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

//go:build (openbsd && amd64) || (openbsd && arm64)

package sqlite3

import (
	"unsafe"

	"modernc.org/libc"
)

const AT_EACCESS = 1

const AT_REMOVEDIR = 8

const AT_SYMLINK_FOLLOW = 4

const AT_SYMLINK_NOFOLLOW = 2

const CLK_TCK = 100

const CLOCK_BOOTTIME = 6

const CLOCK_THREAD_CPUTIME_ID = 4

const DL_GETLIST = 0

const DL_GETLOADADDR = 0

const DL_GETREFCNT = 0

const DL_REFERENCE = 4

const DL_SETBINDLCK = 3

const DL_SETSRCHPATH = 0

const DL_SETTHREADLCK = 2

type Dl_info_t = TDl_info_t

const EBADMSG = 92

const ECANCELED = 88

const EIDRM = 89

const EIPSEC = 82

const ELAST = 95

const EMEDIUMTYPE = 86

const ENDRUNDISC = 9

const ENOATTR = 83

const ENOMEDIUM = 85

const ENOMSG = 90

const ENOTRECOVERABLE = 93

const ENOTSUP = 91

const EOVERFLOW = 87

const EOWNERDEAD = 94

const EPROTO = 95

const FIOGETOWN = 1073768059

const FIOSETOWN = 2147509884

const F_DUPFD_CLOEXEC = 10

const F_DUPFD_CLOFORK = 12

const F_ISATTY = 11

const GID_MAX = 4294967295

const KBIND_BLOCK_MAX = 2

const KBIND_DATA_MAX = 24

const MAP_CONCEAL = 32768

const MAP_FLAGMASK = 65527

const MAP_HASSEMAPHORE = 0

const MAP_INHERIT = 0

const MAP_INHERIT_ZERO = 3

const MAP_NOEXTEND = 0

const MAP_NORESERVE = 0

const MAP_RENAME = 0

const MAP_STACK = 16384

const MAP_TRYFIXED = 0

const MB_LEN_MAX = 4

const MSTSDISC = 8

const MS_INVALIDATE = 4

const MS_SYNC = 2

const NFDBITS = "__NFDBITS"

const NMEADISC = 7

const O_CLOEXEC = 65536

const O_CLOFORK = 262144

const O_DSYNC = 128

const O_RSYNC = 128

const RTLD_NODELETE = 1024

const RTLD_NOLOAD = 2048

const SIOCADDMULTI = 2147510577

const SIOCAIFADDR = 2147510554

const SIOCAIFGROUP = 2147510663

const SIOCATMARK = 1073771271

const SIOCBRDGADD = 2147510588

const SIOCBRDGADDL = 2147510601

const SIOCBRDGADDS = 2147510593

const SIOCBRDGARL = 2147510605

const SIOCBRDGDADDR = 2147510599

const SIOCBRDGDEL = 2147510589

const SIOCBRDGDELS = 2147510594

const SIOCBRDGFLUSH = 2147510600

const SIOCBRDGFRL = 2147510606

const SIOCBRDGGCACHE = 3221252417

const SIOCBRDGGFD = 3221252434

const SIOCBRDGGHT = 3221252433

const SIOCBRDGGIFFLGS = 3221252414

const SIOCBRDGGMA = 3221252435

const SIOCBRDGGPARAM = 3221252440

const SIOCBRDGGPRI = 3221252432

const SIOCBRDGGRL = 3221252431

const SIOCBRDGGTO = 3221252422

const SIOCBRDGIFS = 3221252418

const SIOCBRDGRTS = 3221252419

const SIOCBRDGSADDR = 3221252420

const SIOCBRDGSCACHE = 2147510592

const SIOCBRDGSFD = 2147510610

const SIOCBRDGSHT = 2147510609

const SIOCBRDGSIFCOST = 2147510613

const SIOCBRDGSIFFLGS = 2147510591

const SIOCBRDGSIFPRIO = 2147510612

const SIOCBRDGSIFPROT = 2147510602

const SIOCBRDGSMA = 2147510611

const SIOCBRDGSPRI = 2147510608

const SIOCBRDGSPROTO = 2147510618

const SIOCBRDGSTO = 2147510597

const SIOCBRDGSTXHC = 2147510617

const SIOCDELLABEL = 2147510679

const SIOCDELMULTI = 2147510578

const SIOCDIFADDR = 2147510553

const SIOCDIFGROUP = 2147510665

const SIOCDIFPARENT = 2147510708

const SIOCDIFPHYADDR = 2147510601

const SIOCDPWE3NEIGHBOR = 2147510750

const SIOCDVNETID = 2147510703

const SIOCGETKALIVE = 3221252516

const SIOCGETLABEL = 2147510682

const SIOCGETMPWCFG = 3221252526

const SIOCGETPFLOW = 3221252606

const SIOCGETPFSYNC = 3221252600

const SIOCGETSGCNT = 3221255476

const SIOCGETVIFCNT = 3221255475

const SIOCGETVLAN = 3221252496

const SIOCGIFADDR = 3221252385

const SIOCGIFBRDADDR = 3221252387

const SIOCGIFCONF = 3221252388

const SIOCGIFDATA = 3221252379

const SIOCGIFDESCR = 3221252481

const SIOCGIFDSTADDR = 3221252386

const SIOCGIFFLAGS = 3221252369

const SIOCGIFGATTR = 3221252491

const SIOCGIFGLIST = 3221252493

const SIOCGIFGMEMB = 3221252490

const SIOCGIFGROUP = 3221252488

const SIOCGIFHARDMTU = 3221252517

const SIOCGIFLLPRIO = 3221252534

const SIOCGIFMEDIA = 3221252408

const SIOCGIFMETRIC = 3221252375

const SIOCGIFMTU = 3221252478

const SIOCGIFNETMASK = 3221252389

const SIOCGIFPAIR = 3221252529

const SIOCGIFPARENT = 3221252531

const SIOCGIFPRIORITY = 3221252508

const SIOCGIFRDOMAIN = 3221252512

const SIOCGIFRTLABEL = 3221252483

const SIOCGIFRXR = 2147510698

const SIOCGIFSFFPAGE = 3221252409

const SIOCGIFXFLAGS = 3221252510

const SIOCGLIFPHYADDR = 3221252427

const SIOCGLIFPHYDF = 3221252546

const SIOCGLIFPHYECN = 3221252552

const SIOCGLIFPHYRTABLE = 3221252514

const SIOCGLIFPHYTTL = 3221252521

const SIOCGPGRP = 1073771273

const SIOCGPWE3 = 3221252504

const SIOCGPWE3CTRLWORD = 3221252572

const SIOCGPWE3FAT = 3221252573

const SIOCGPWE3NEIGHBOR = 3221252574

const SIOCGRXHPRIO = 3221252571

const SIOCGSPPPPARAMS = 3221252500

const SIOCGTXHPRIO = 3221252550

const SIOCGUMBINFO = 3221252542

const SIOCGUMBPARAM = 3221252544

const SIOCGVH = 3221252598

const SIOCGVNETFLOWID = 3221252548

const SIOCGVNETID = 3221252519

const SIOCIFAFATTACH = 2147510699

const SIOCIFAFDETACH = 2147510700

const SIOCIFCREATE = 2147510650

const SIOCIFDESTROY = 2147510649

const SIOCIFGCLONERS = 3221252472

const SIOCSETKALIVE = 2147510691

const SIOCSETLABEL = 2147510681

const SIOCSETMPWCFG = 2147510701

const SIOCSETPFLOW = 2147510781

const SIOCSETPFSYNC = 2147510775

const SIOCSETVLAN = 2147510671

const SIOCSIFADDR = 2147510540

const SIOCSIFBRDADDR = 2147510547

const SIOCSIFDESCR = 2147510656

const SIOCSIFDSTADDR = 2147510542

const SIOCSIFFLAGS = 2147510544

const SIOCSIFGATTR = 2147510668

const SIOCSIFLLADDR = 2147510559

const SIOCSIFLLPRIO = 2147510709

const SIOCSIFMEDIA = 3221252407

const SIOCSIFMETRIC = 2147510552

const SIOCSIFMTU = 2147510655

const SIOCSIFNETMASK = 2147510550

const SIOCSIFPAIR = 2147510704

const SIOCSIFPARENT = 2147510706

const SIOCSIFPRIORITY = 2147510683

const SIOCSIFRDOMAIN = 2147510687

const SIOCSIFRTLABEL = 2147510658

const SIOCSIFXFLAGS = 2147510685

const SIOCSLIFPHYADDR = 2147510602

const SIOCSLIFPHYDF = 2147510721

const SIOCSLIFPHYECN = 2147510727

const SIOCSLIFPHYRTABLE = 2147510689

const SIOCSLIFPHYTTL = 2147510696

const SIOCSPGRP = 2147513096

const SIOCSPWE3CTRLWORD = 2147510748

const SIOCSPWE3FAT = 2147510749

const SIOCSPWE3NEIGHBOR = 2147510750

const SIOCSRXHPRIO = 2147510747

const SIOCSSPPPPARAMS = 2147510675

const SIOCSTXHPRIO = 2147510725

const SIOCSUMBPARAM = 2147510719

const SIOCSVH = 3221252597

const SIOCSVNETFLOWID = 2147510723

const SIOCSVNETID = 2147510694

type TDl_info_t = struct {
	Fdli_fname uintptr
	Fdli_fbase uintptr
	Fdli_sname uintptr
	Fdli_saddr uintptr
}

const TIOCCBRK = 536900730

const TIOCCDTR = 536900728

const TIOCCHKVERAUTH = 536900638

const TIOCCLRVERAUTH = 536900637

const TIOCCONS = 2147513442

const TIOCDRAIN = 536900702

const TIOCEXCL = 536900621

const TIOCEXT = 2147513440

const TIOCFLAG_PPS = 16

const TIOCFLUSH = 2147513360

const TIOCGETA = 1073771539

const TIOCGETD = 1073771546

const TIOCGFLAGS = 1073771613

const TIOCGSID = 1073771619

const TIOCGTSTAMP = 1073771611

const TIOCMBIC = 2147513451

const TIOCMBIS = 2147513452

const TIOCMGET = 1073771626

const TIOCMODG = 1073771626

const TIOCMODS = 2147513453

const TIOCMSET = 2147513453

const TIOCNOTTY = 536900721

const TIOCNXCL = 536900622

const TIOCPKT = 2147513456

const TIOCREMOTE = 2147513449

const TIOCSBRK = 536900731

const TIOCSCTTY = 536900705

const TIOCSDTR = 536900729

const TIOCSETA = 2147513364

const TIOCSETAF = 2147513366

const TIOCSETAW = 2147513365

const TIOCSETD = 2147513371

const TIOCSETVERAUTH = 2147513372

const TIOCSFLAGS = 2147513436

const TIOCSIG = 2147513439

const TIOCSTAT = 536900709

const TIOCSTSTAMP = 2147513434

const TIOCUCNTL = 2147513446

const TIOCUCNTL_CBRK = 122

const TIOCUCNTL_SBRK = 123

const TMP_MAX = 2147483647

type Tclockinfo = struct {
	Fhz     int32
	Ftick   int32
	Fstathz int32
	Fprofhz int32
}

type Tdaddr32_t = int32

type Tdl_info = TDl_info_t

type Tfd_set = struct {
	Ffds_bits [32]t__fd_mask
}

type Tpaddr_t = uint64

type Tpsize_t = uint64

type Tstat = struct {
	Fst_mode       Tmode_t
	Fst_dev        Tdev_t
	Fst_ino        Tino_t
	Fst_nlink      Tnlink_t
	Fst_uid        Tuid_t
	Fst_gid        Tgid_t
	Fst_rdev       Tdev_t
	Fst_atim       Ttimespec
	Fst_mtim       Ttimespec
	Fst_ctim       Ttimespec
	Fst_size       Toff_t
	Fst_blocks     Tblkcnt_t
	Fst_blksize    Tblksize_t
	Fst_flags      Tu_int32_t
	Fst_gen        Tu_int32_t
	F__st_birthtim Ttimespec
}

type Ttstamps = struct {
	Fts_set int32
	Fts_clr int32
}

type Tvaddr_t = uint64

type Tvsize_t = uint64

const UID_MAX = 4294967295

const UTIME_NOW = -2

const UTIME_OMIT = -1

// C documentation
//
//	/*
//	** Create an sqlite3_backup process to copy the contents of zSrcDb from
//	** connection handle pSrcDb to zDestDb in pDestDb. If successful, return
//	** a pointer to the new sqlite3_backup object.
//	**
//	** If an error occurs, NULL is returned and an error code and error message
//	** stored in database handle pDestDb.
//	*/
func Xsqlite3_backup_init(tls *libc.TLS, pDestDb uintptr, zDestDb uintptr, pSrcDb uintptr, zSrcDb uintptr) (r uintptr) {
	var nDest int32
	var p, pDest uintptr
	_, _, _ = nDest, p, pDest /* Value to return */
	/* Lock the source database handle. The destination database
	 ** handle is not locked in this routine, but it is locked in
	 ** sqlite3_backup_step(). The user is required to ensure that no
	 ** other thread accesses the destination handle for the duration
	 ** of the backup operation.  Any attempt to use the destination
	 ** database connection while a backup is in progress may cause
	 ** a malfunction or a deadlock.
	 */
	Xsqlite3_mutex_enter(tls, (*Tsqlite3)(unsafe.Pointer(pSrcDb)).Fmutex)
	Xsqlite3_mutex_enter(tls, (*Tsqlite3)(unsafe.Pointer(pDestDb)).Fmutex)
	if pSrcDb == pDestDb {
		_sqlite3ErrorWithMsg(tls, pDestDb, int32(SQLITE_ERROR), __ccgo_ts+5169, 0)
		p = uintptr(0)
	} else {
		nDest = _sqlite3Strlen30(tls, zDestDb)
		/* Allocate space for a new sqlite3_backup object...
		 ** 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(). */
		p = _sqlite3MallocZero(tls, uint64(uint64(80)+libc.Uint64FromInt32(nDest)+uint64(1)))
		if !(p != 0) {
			_sqlite3Error(tls, pDestDb, int32(SQLITE_NOMEM))
		} else {
			(*Tsqlite3_backup)(unsafe.Pointer(p)).FzDestDb = p + 1*80
			libc.Xmemcpy(tls, (*Tsqlite3_backup)(unsafe.Pointer(p)).FzDestDb, zDestDb, libc.Uint64FromInt32(nDest))
		}
	}
	/* If the allocation succeeded, populate the new object. */
	if p != 0 {
		/* Do not store the pointer to the destination b-tree at this point.
		 ** This is because there is nothing preventing it from being detached
		 ** or otherwise freed before the first call to sqlite3_backup_step()
		 ** on this object. The source b-tree does not have this problem, as
		 ** incrementing Btree.nBackup (see below) effectively locks the object. */
		pDest = _findBtree(tls, pDestDb, pDestDb, zDestDb)
		(*Tsqlite3_backup)(unsafe.Pointer(p)).FpSrc = _findBtree(tls, pDestDb, pSrcDb, zSrcDb)
		(*Tsqlite3_backup)(unsafe.Pointer(p)).FpDestDb = pDestDb
		(*Tsqlite3_backup)(unsafe.Pointer(p)).FpSrcDb = pSrcDb
		(*Tsqlite3_backup)(unsafe.Pointer(p)).FiNext = uint32(1)
		(*Tsqlite3_backup)(unsafe.Pointer(p)).FisAttached = 0
		if uintptr(0) == (*Tsqlite3_backup)(unsafe.Pointer(p)).FpSrc || uintptr(0) == pDest || _checkReadTransaction(tls, pDestDb, pDest) != SQLITE_OK {
			/* One (or both) of the named databases did not exist or an OOM
			 ** error was hit. Or there is a transaction open on the destination
			 ** database. The error has already been written into the pDestDb
			 ** handle. All that is left to do here is free the sqlite3_backup
			 ** structure.  */
			Xsqlite3_free(tls, p)
			p = uintptr(0)
		}
	}
	if p != 0 {
		(*TBtree)(unsafe.Pointer((*Tsqlite3_backup)(unsafe.Pointer(p)).FpSrc)).FnBackup = (*TBtree)(unsafe.Pointer((*Tsqlite3_backup)(unsafe.Pointer(p)).FpSrc)).FnBackup + 1
	}
	Xsqlite3_mutex_leave(tls, (*Tsqlite3)(unsafe.Pointer(pDestDb)).Fmutex)
	Xsqlite3_mutex_leave(tls, (*Tsqlite3)(unsafe.Pointer(pSrcDb)).Fmutex)
	return p
}

// C documentation
//
//	/*
//	** Open a blob handle.
//	*/
func Xsqlite3_blob_open(tls *libc.TLS, db uintptr, zDb uintptr, zTable uintptr, zColumn uintptr, iRow Tsqlite_int64, wrFlag int32, ppBlob uintptr) (r int32) {
	bp := tls.Alloc(448)
	defer tls.Free(448)
	var aOp, pBlob, pFKey, pIdx, pTab, v, zFault, v8 uintptr
	var iCol, iDb, j, j1, nAttempt, rc, v1 int32
	var v2 bool
	var _ /* sParse at bp+8 */ TParse
	var _ /* zErr at bp+0 */ uintptr
	_, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _ = aOp, iCol, iDb, j, j1, nAttempt, pBlob, pFKey, pIdx, pTab, rc, v, zFault, v1, v2, v8
	nAttempt = 0 /* Index of zColumn in row-record */
	rc = SQLITE_OK
	**(**uintptr)(__ccgo_up(bp)) = uintptr(0)
	pBlob = uintptr(0)
	**(**uintptr)(__ccgo_up(ppBlob)) = uintptr(0)
	wrFlag = libc.BoolInt32(!!(wrFlag != 0)) /* wrFlag = (wrFlag ? 1 : 0); */
	Xsqlite3_mutex_enter(tls, (*Tsqlite3)(unsafe.Pointer(db)).Fmutex)
	pBlob = _sqlite3DbMallocZero(tls, db, uint64(56))
	for int32(1) != 0 {
		_sqlite3ParseObjectInit(tls, bp+8, db)
		if !(pBlob != 0) {
			goto blob_open_out
		}
		_sqlite3DbFree(tls, db, **(**uintptr)(__ccgo_up(bp)))
		**(**uintptr)(__ccgo_up(bp)) = uintptr(0)
		_sqlite3BtreeEnterAll(tls, db)
		pTab = _sqlite3LocateTable(tls, bp+8, uint32(0), zTable, zDb)
		if pTab != 0 && libc.Int32FromUint8((*TTable)(unsafe.Pointer(pTab)).FeTabType) == int32(TABTYP_VTAB) {
			pTab = uintptr(0)
			_sqlite3ErrorMsg(tls, bp+8, __ccgo_ts+6542, libc.VaList(bp+440, zTable))
		}
		if pTab != 0 && !((*TTable)(unsafe.Pointer(pTab)).FtabFlags&libc.Uint32FromInt32(TF_WithoutRowid) == libc.Uint32FromInt32(0)) {
			pTab = uintptr(0)
			_sqlite3ErrorMsg(tls, bp+8, __ccgo_ts+6572, libc.VaList(bp+440, zTable))
		}
		if pTab != 0 && (*TTable)(unsafe.Pointer(pTab)).FtabFlags&uint32(TF_HasGenerated) != uint32(0) {
			pTab = uintptr(0)
			_sqlite3ErrorMsg(tls, bp+8, __ccgo_ts+6608, libc.VaList(bp+440, zTable))
		}
		if pTab != 0 && libc.Int32FromUint8((*TTable)(unsafe.Pointer(pTab)).FeTabType) == int32(TABTYP_VIEW) {
			pTab = uintptr(0)
			_sqlite3ErrorMsg(tls, bp+8, __ccgo_ts+6653, libc.VaList(bp+440, zTable))
		}
		if v2 = pTab == uintptr(0); !v2 {
			v1 = _sqlite3SchemaToIndex(tls, db, (*TTable)(unsafe.Pointer(pTab)).FpSchema)
			iDb = v1
		}
		if v2 || v1 == int32(1) && _sqlite3OpenTempDatabase(tls, bp+8) != 0 {
			if (**(**TParse)(__ccgo_up(bp + 8))).FzErrMsg != 0 {
				_sqlite3DbFree(tls, db, **(**uintptr)(__ccgo_up(bp)))
				**(**uintptr)(__ccgo_up(bp)) = (**(**TParse)(__ccgo_up(bp + 8))).FzErrMsg
				(**(**TParse)(__ccgo_up(bp + 8))).FzErrMsg = uintptr(0)
			}
			rc = int32(SQLITE_ERROR)
			_sqlite3BtreeLeaveAll(tls, db)
			goto blob_open_out
		}
		(*TIncrblob)(unsafe.Pointer(pBlob)).FpTab = pTab
		(*TIncrblob)(unsafe.Pointer(pBlob)).FzDb = (**(**TDb)(__ccgo_up((*Tsqlite3)(unsafe.Pointer(db)).FaDb + uintptr(iDb)*32))).FzDbSName
		/* Now search pTab for the exact column. */
		iCol = _sqlite3ColumnIndex(tls, pTab, zColumn)
		if iCol < 0 {
			_sqlite3DbFree(tls, db, **(**uintptr)(__ccgo_up(bp)))
			**(**uintptr)(__ccgo_up(bp)) = _sqlite3MPrintf(tls, db, __ccgo_ts+6674, libc.VaList(bp+440, zColumn))
			rc = int32(SQLITE_ERROR)
			_sqlite3BtreeLeaveAll(tls, db)
			goto blob_open_out
		}
		/* If the value is being opened for writing, check that the
		 ** column is not indexed, and that it is not part of a foreign key.
		 */
		if wrFlag != 0 {
			zFault = uintptr(0)
			if (*Tsqlite3)(unsafe.Pointer(db)).Fflags&uint64(SQLITE_ForeignKeys) != 0 {
				pFKey = (*(*struct {
					FaddColOffset int32
					FpFKey        uintptr
					FpDfltList    uintptr
				})(unsafe.Pointer(pTab + 64))).FpFKey
				for {
					if !(pFKey != 0) {
						break
					}
					j = 0
					for {
						if !(j < (*TFKey)(unsafe.Pointer(pFKey)).FnCol) {
							break
						}
						if (*(*TsColMap)(unsafe.Pointer(pFKey + 64 + uintptr(j)*16))).FiFrom == iCol {
							zFault = __ccgo_ts + 6695
						}
						goto _4
					_4:
						;
						j = j + 1
					}
					goto _3
				_3:
					;
					pFKey = (*TFKey)(unsafe.Pointer(pFKey)).FpNextFrom
				}
			}
			pIdx = (*TTable)(unsafe.Pointer(pTab)).FpIndex
			for {
				if !(pIdx != 0) {
					break
				}
				j1 = 0
				for {
					if !(j1 < libc.Int32FromUint16((*TIndex)(unsafe.Pointer(pIdx)).FnKeyCol)) {
						break
					}
					/* FIXME: Be smarter about indexes that use expressions */
					if int32(**(**Ti16)(__ccgo_up((*TIndex)(unsafe.Pointer(pIdx)).FaiColumn + uintptr(j1)*2))) == iCol || int32(**(**Ti16)(__ccgo_up((*TIndex)(unsafe.Pointer(pIdx)).FaiColumn + uintptr(j1)*2))) == -int32(2) {
						zFault = __ccgo_ts + 6707
					}
					goto _6
				_6:
					;
					j1 = j1 + 1
				}
				goto _5
			_5:
				;
				pIdx = (*TIndex)(unsafe.Pointer(pIdx)).FpNext
			}
			if zFault != 0 {
				_sqlite3DbFree(tls, db, **(**uintptr)(__ccgo_up(bp)))
				**(**uintptr)(__ccgo_up(bp)) = _sqlite3MPrintf(tls, db, __ccgo_ts+6715, libc.VaList(bp+440, zFault))
				rc = int32(SQLITE_ERROR)
				_sqlite3BtreeLeaveAll(tls, db)
				goto blob_open_out
			}
		}
		(*TIncrblob)(unsafe.Pointer(pBlob)).FpStmt = _sqlite3VdbeCreate(tls, bp+8)
		if (*TIncrblob)(unsafe.Pointer(pBlob)).FpStmt != 0 {
			v = (*TIncrblob)(unsafe.Pointer(pBlob)).FpStmt
			_sqlite3VdbeAddOp4Int(tls, v, int32(OP_Transaction), iDb, wrFlag, (*TSchema)(unsafe.Pointer((*TTable)(unsafe.Pointer(pTab)).FpSchema)).Fschema_cookie, (*TSchema)(unsafe.Pointer((*TTable)(unsafe.Pointer(pTab)).FpSchema)).FiGeneration)
			_sqlite3VdbeChangeP5(tls, v, uint16(1))
			aOp = _sqlite3VdbeAddOpList(tls, v, libc.Int32FromUint64(libc.Uint64FromInt64(24)/libc.Uint64FromInt64(4)), uintptr(unsafe.Pointer(&_openBlob)), _iLn)
			/* Make sure a mutex is held on the table to be accessed */
			_sqlite3VdbeUsesBtree(tls, v, iDb)
			if libc.Int32FromUint8((*Tsqlite3)(unsafe.Pointer(db)).FmallocFailed) == 0 {
				/* Configure the OP_TableLock instruction */
				(**(**TVdbeOp)(__ccgo_up(aOp))).Fp1 = iDb
				(**(**TVdbeOp)(__ccgo_up(aOp))).Fp2 = libc.Int32FromUint32((*TTable)(unsafe.Pointer(pTab)).Ftnum)
				(**(**TVdbeOp)(__ccgo_up(aOp))).Fp3 = wrFlag
				_sqlite3VdbeChangeP4(tls, v, int32(2), (*TTable)(unsafe.Pointer(pTab)).FzName, P4_TRANSIENT)
			}
			if libc.Int32FromUint8((*Tsqlite3)(unsafe.Pointer(db)).FmallocFailed) == 0 {
				/* Remove either the OP_OpenWrite or OpenRead. Set the P2
				 ** parameter of the other to pTab->tnum.  */
				if wrFlag != 0 {
					(**(**TVdbeOp)(__ccgo_up(aOp + 1*24))).Fopcode = uint8(OP_OpenWrite)
				}
				(**(**TVdbeOp)(__ccgo_up(aOp + 1*24))).Fp2 = libc.Int32FromUint32((*TTable)(unsafe.Pointer(pTab)).Ftnum)
				(**(**TVdbeOp)(__ccgo_up(aOp + 1*24))).Fp3 = iDb
				/* Configure the number of columns. Configure the cursor to
				 ** think that the table has one more column than it really
				 ** does. An OP_Column to retrieve this imaginary column will
				 ** always return an SQL NULL. This is useful because it means
				 ** we can invoke OP_Column to fill in the vdbe cursors type
				 ** and offset cache without causing any IO.
				 */
				(**(**TVdbeOp)(__ccgo_up(aOp + 1*24))).Fp4type = int8(-libc.Int32FromInt32(3))
				*(*int32)(unsafe.Pointer(aOp + 1*24 + 16)) = int32((*TTable)(unsafe.Pointer(pTab)).FnCol) + int32(1)
				(**(**TVdbeOp)(__ccgo_up(aOp + 3*24))).Fp2 = int32((*TTable)(unsafe.Pointer(pTab)).FnCol)
				(**(**TParse)(__ccgo_up(bp + 8))).FnVar = 0
				(**(**TParse)(__ccgo_up(bp + 8))).FnMem = int32(1)
				(**(**TParse)(__ccgo_up(bp + 8))).FnTab = int32(1)
				_sqlite3VdbeMakeReady(tls, v, bp+8)
			}
		}
		(*TIncrblob)(unsafe.Pointer(pBlob)).FiCol = libc.Uint16FromInt32(iCol)
		(*TIncrblob)(unsafe.Pointer(pBlob)).Fdb = db
		_sqlite3BtreeLeaveAll(tls, db)
		if (*Tsqlite3)(unsafe.Pointer(db)).FmallocFailed != 0 {
			goto blob_open_out
		}
		rc = _blobSeekToRow(tls, pBlob, iRow, bp)
		nAttempt = nAttempt + 1
		v1 = nAttempt
		if v1 >= int32(SQLITE_MAX_SCHEMA_RETRY) || rc != int32(SQLITE_SCHEMA) {
			break
		}
		_sqlite3ParseObjectReset(tls, bp+8)
	}
	goto blob_open_out
blob_open_out:
	;
	if rc == SQLITE_OK && libc.Int32FromUint8((*Tsqlite3)(unsafe.Pointer(db)).FmallocFailed) == 0 {
		**(**uintptr)(__ccgo_up(ppBlob)) = pBlob
	} else {
		if pBlob != 0 && (*TIncrblob)(unsafe.Pointer(pBlob)).FpStmt != 0 {
			_sqlite3VdbeFinalize(tls, (*TIncrblob)(unsafe.Pointer(pBlob)).FpStmt)
		}
		_sqlite3DbFree(tls, db, pBlob)
	}
	if **(**uintptr)(__ccgo_up(bp)) != 0 {
		v8 = __ccgo_ts + 3933
	} else {
		v8 = libc.UintptrFromInt32(0)
	}
	_sqlite3ErrorWithMsg(tls, db, rc, v8, libc.VaList(bp+440, **(**uintptr)(__ccgo_up(bp))))
	_sqlite3DbFree(tls, db, **(**uintptr)(__ccgo_up(bp)))
	_sqlite3ParseObjectReset(tls, bp+8)
	rc = _sqlite3ApiExit(tls, db, rc)
	Xsqlite3_mutex_leave(tls, (*Tsqlite3)(unsafe.Pointer(db)).Fmutex)
	return rc
}

// C documentation
//
//	/*
//	** Move an existing blob handle to point to a different row of the same
//	** database table.
//	**
//	** If an error occurs, or if the specified row does not exist or does not
//	** contain a blob or text value, then an error code is returned and the
//	** database handle error code and message set. If this happens, then all
//	** subsequent calls to sqlite3_blob_xxx() functions (except blob_close())
//	** immediately return SQLITE_ABORT.
//	*/
func Xsqlite3_blob_reopen(tls *libc.TLS, pBlob uintptr, iRow Tsqlite3_int64) (r int32) {
	bp := tls.Alloc(32)
	defer tls.Free(32)
	var db, p, v1 uintptr
	var rc int32
	var _ /* zErr at bp+0 */ uintptr
	_, _, _, _ = db, p, rc, v1
	p = pBlob
	if p == uintptr(0) {
		return _sqlite3MisuseError(tls, int32(106500))
	}
	db = (*TIncrblob)(unsafe.Pointer(p)).Fdb
	Xsqlite3_mutex_enter(tls, (*Tsqlite3)(unsafe.Pointer(db)).Fmutex)
	if (*TIncrblob)(unsafe.Pointer(p)).FpStmt == uintptr(0) {
		/* If there is no statement handle, then the blob-handle has
		 ** already been invalidated. Return SQLITE_ABORT in this case.
		 */
		rc = int32(SQLITE_ABORT)
	} else {
		(*TVdbe)(unsafe.Pointer((*TIncrblob)(unsafe.Pointer(p)).FpStmt)).Frc = SQLITE_OK
		rc = _blobSeekToRow(tls, p, iRow, bp)
		if rc != SQLITE_OK {
			if **(**uintptr)(__ccgo_up(bp)) != 0 {
				v1 = __ccgo_ts + 3933
			} else {
				v1 = libc.UintptrFromInt32(0)
			}
			_sqlite3ErrorWithMsg(tls, db, rc, v1, libc.VaList(bp+16, **(**uintptr)(__ccgo_up(bp))))
			_sqlite3DbFree(tls, db, **(**uintptr)(__ccgo_up(bp)))
		}
	}
	rc = _sqlite3ApiExit(tls, db, rc)
	Xsqlite3_mutex_leave(tls, (*Tsqlite3)(unsafe.Pointer(db)).Fmutex)
	return rc
}

/************** End of vdbeblob.c ********************************************/
/************** Begin file vdbesort.c ****************************************/
/*
** 2011-07-09
**
** 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 for the VdbeSorter object, used in concert with
** a VdbeCursor to sort large numbers of keys for CREATE INDEX statements
** or by SELECT statements with ORDER BY clauses that cannot be satisfied
** using indexes and without LIMIT clauses.
**
** The VdbeSorter object implements a multi-threaded external merge sort
** algorithm that is efficient even if the number of elements being sorted
** exceeds the available memory.
**
** Here is the (internal, non-API) interface between this module and the
** rest of the SQLite system:
**
**    sqlite3VdbeSorterInit()       Create a new VdbeSorter object.
**
**    sqlite3VdbeSorterWrite()      Add a single new row to the VdbeSorter
**                                  object.  The row is a binary blob in the
**                                  OP_MakeRecord format that contains both
**                                  the ORDER BY key columns and result columns
**                                  in the case of a SELECT w/ ORDER BY, or
**                                  the complete record for an index entry
**                                  in the case of a CREATE INDEX.
**
**    sqlite3VdbeSorterRewind()     Sort all content previously added.
**                                  Position the read cursor on the
**                                  first sorted element.
**
**    sqlite3VdbeSorterNext()       Advance the read cursor to the next sorted
**                                  element.
**
**    sqlite3VdbeSorterRowkey()     Return the complete binary blob for the
**                                  row currently under the read cursor.
**
**    sqlite3VdbeSorterCompare()    Compare the binary blob for the row
**                                  currently under the read cursor against
**                                  another binary blob X and report if
**                                  X is strictly less than the read cursor.
**                                  Used to enforce uniqueness in a
**                                  CREATE UNIQUE INDEX statement.
**
**    sqlite3VdbeSorterClose()      Close the VdbeSorter object and reclaim
**                                  all resources.
**
**    sqlite3VdbeSorterReset()      Refurbish the VdbeSorter for reuse.  This
**                                  is like Close() followed by Init() only
**                                  much faster.
**
** The interfaces above must be called in a particular order.  Write() can
** only occur in between Init()/Reset() and Rewind().  Next(), Rowkey(), and
** Compare() can only occur in between Rewind() and Close()/Reset(). i.e.
**
**   Init()
**   for each record: Write()
**   Rewind()
**     Rowkey()/Compare()
**   Next()
**   Close()
**
** Algorithm:
**
** Records passed to the sorter via calls to Write() are initially held
** unsorted in main memory. Assuming the amount of memory used never exceeds
** a threshold, when Rewind() is called the set of records is sorted using
** an in-memory merge sort. In this case, no temporary files are required
** and subsequent calls to Rowkey(), Next() and Compare() read records
** directly from main memory.
**
** If the amount of space used to store records in main memory exceeds the
** threshold, then the set of records currently in memory are sorted and
** written to a temporary file in "Packed Memory Array" (PMA) format.
** A PMA created at this point is known as a "level-0 PMA". Higher levels
** of PMAs may be created by merging existing PMAs together - for example
** merging two or more level-0 PMAs together creates a level-1 PMA.
**
** The threshold for the amount of main memory to use before flushing
** records to a PMA is roughly the same as the limit configured for the
** page-cache of the main database. Specifically, the threshold is set to
** the value returned by "PRAGMA main.page_size" multiplied by
** that returned by "PRAGMA main.cache_size", in bytes.
**
** If the sorter is running in single-threaded mode, then all PMAs generated
** are appended to a single temporary file. Or, if the sorter is running in
** multi-threaded mode then up to (N+1) temporary files may be opened, where
** N is the configured number of worker threads. In this case, instead of
** sorting the records and writing the PMA to a temporary file itself, the
** calling thread usually launches a worker thread to do so. Except, if
** there are already N worker threads running, the main thread does the work
** itself.
**
** The sorter is running in multi-threaded mode if (a) the library was built
** with pre-processor symbol SQLITE_MAX_WORKER_THREADS set to a value greater
** than zero, and (b) worker threads have been enabled at runtime by calling
** "PRAGMA threads=N" with some value of N greater than 0.
**
** When Rewind() is called, any data remaining in memory is flushed to a
** final PMA. So at this point the data is stored in some number of sorted
** PMAs within temporary files on disk.
**
** If there are fewer than SORTER_MAX_MERGE_COUNT PMAs in total and the
** sorter is running in single-threaded mode, then these PMAs are merged
** incrementally as keys are retrieved from the sorter by the VDBE.  The
** MergeEngine object, described in further detail below, performs this
** merge.
**
** Or, if running in multi-threaded mode, then a background thread is
** launched to merge the existing PMAs. Once the background thread has
** merged T bytes of data into a single sorted PMA, the main thread
** begins reading keys from that PMA while the background thread proceeds
** with merging the next T bytes of data. And so on.
**
** Parameter T is set to half the value of the memory threshold used
** by Write() above to determine when to create a new PMA.
**
** If there are more than SORTER_MAX_MERGE_COUNT PMAs in total when
** Rewind() is called, then a hierarchy of incremental-merges is used.
** First, T bytes of data from the first SORTER_MAX_MERGE_COUNT PMAs on
** disk are merged together. Then T bytes of data from the second set, and
** so on, such that no operation ever merges more than SORTER_MAX_MERGE_COUNT
** PMAs at a time. This done is to improve locality.
**
** If running in multi-threaded mode and there are more than
** SORTER_MAX_MERGE_COUNT PMAs on disk when Rewind() is called, then more
** than one background thread may be created. Specifically, there may be
** one background thread for each temporary file on disk, and one background
** thread to merge the output of each of the others to a single PMA for
** the main thread to read from.
 */
/* #include "sqliteInt.h" */
/* #include "vdbeInt.h" */

/*
** If SQLITE_DEBUG_SORTER_THREADS is defined, this module outputs various
** messages to stderr that may be helpful in understanding the performance
** characteristics of the sorter in multi-threaded mode.
 */

/*
** Hard-coded maximum amount of data to accumulate in memory before flushing
** to a level 0 PMA. The purpose of this limit is to prevent various integer
** overflows. 512MiB.
 */

// C documentation
//
//	/*
//	** This API allows applications to modify the global configuration of
//	** the SQLite library at run-time.
//	**
//	** This routine should only be called when there are no outstanding
//	** database connections or memory allocations.  This routine is not
//	** threadsafe.  Failure to heed these warnings can lead to unpredictable
//	** behavior.
//	*/
func Xsqlite3_config(tls *libc.TLS, op int32, va uintptr) (r int32) {
	var ap Tva_list
	var bOpenUri, rc int32
	var mxMmap, szMmap Tsqlite3_int64
	var pLogArg, pVal, xLog uintptr
	_, _, _, _, _, _, _, _ = ap, bOpenUri, mxMmap, pLogArg, pVal, rc, szMmap, xLog
	rc = SQLITE_OK
	/* sqlite3_config() normally returns SQLITE_MISUSE if it is invoked while
	 ** the SQLite library is in use.  Except, a few selected opcodes
	 ** are allowed.
	 */
	if libc.AtomicLoadPInt32(uintptr(unsafe.Pointer(&_sqlite3Config))+340) != 0 {
		if op < 0 || op > int32(63) || libc.Uint64FromInt32(1)<<op&_mAnytimeConfigOption == uint64(0) {
			return _sqlite3MisuseError(tls, int32(187803))
		}
	}
	ap = va
	switch op {
	/* Mutex configuration options are only available in a threadsafe
	 ** compile.
	 */
	case int32(SQLITE_CONFIG_SINGLETHREAD):
		/* EVIDENCE-OF: R-02748-19096 This option sets the threading mode to
		 ** Single-thread. */
		_sqlite3Config.FbCoreMutex = uint8(0) /* Disable mutex on core */
		_sqlite3Config.FbFullMutex = uint8(0) /* Disable mutex on connections */
	case int32(SQLITE_CONFIG_MULTITHREAD):
		/* EVIDENCE-OF: R-14374-42468 This option sets the threading mode to
		 ** Multi-thread. */
		_sqlite3Config.FbCoreMutex = uint8(1) /* Enable mutex on core */
		_sqlite3Config.FbFullMutex = uint8(0) /* Disable mutex on connections */
	case int32(SQLITE_CONFIG_SERIALIZED):
		/* EVIDENCE-OF: R-41220-51800 This option sets the threading mode to
		 ** Serialized. */
		_sqlite3Config.FbCoreMutex = uint8(1) /* Enable mutex on core */
		_sqlite3Config.FbFullMutex = uint8(1) /* Enable mutex on connections */
	case int32(SQLITE_CONFIG_MUTEX):
		/* Specify an alternative mutex implementation */
		_sqlite3Config.Fmutex = **(**Tsqlite3_mutex_methods)(__ccgo_up(libc.VaUintptr(&ap)))
	case int32(SQLITE_CONFIG_GETMUTEX):
		/* Retrieve the current mutex implementation */
		**(**Tsqlite3_mutex_methods)(__ccgo_up(libc.VaUintptr(&ap))) = _sqlite3Config.Fmutex
	case int32(SQLITE_CONFIG_MALLOC):
		/* EVIDENCE-OF: R-55594-21030 The SQLITE_CONFIG_MALLOC option takes a
		 ** single argument which is a pointer to an instance of the
		 ** sqlite3_mem_methods structure. The argument specifies alternative
		 ** low-level memory allocation routines to be used in place of the memory
		 ** allocation routines built into SQLite. */
		_sqlite3Config.Fm = **(**Tsqlite3_mem_methods)(__ccgo_up(libc.VaUintptr(&ap)))
	case int32(SQLITE_CONFIG_GETMALLOC):
		/* EVIDENCE-OF: R-51213-46414 The SQLITE_CONFIG_GETMALLOC option takes a
		 ** single argument which is a pointer to an instance of the
		 ** sqlite3_mem_methods structure. The sqlite3_mem_methods structure is
		 ** filled with the currently defined memory allocation routines. */
		if _sqlite3Config.Fm.FxMalloc == uintptr(0) {
			_sqlite3MemSetDefault(tls)
		}
		**(**Tsqlite3_mem_methods)(__ccgo_up(libc.VaUintptr(&ap))) = _sqlite3Config.Fm
	case int32(SQLITE_CONFIG_MEMSTATUS):
		/* Cannot change at runtime */
		/* EVIDENCE-OF: R-61275-35157 The SQLITE_CONFIG_MEMSTATUS option takes
		 ** single argument of type int, interpreted as a boolean, which enables
		 ** or disables the collection of memory allocation statistics. */
		_sqlite3Config.FbMemstat = libc.VaInt32(&ap)
	case int32(SQLITE_CONFIG_SMALL_MALLOC):
		_sqlite3Config.FbSmallMalloc = libc.Uint8FromInt32(libc.VaInt32(&ap))
	case int32(SQLITE_CONFIG_PAGECACHE):
		/* EVIDENCE-OF: R-18761-36601 There are three arguments to
		 ** SQLITE_CONFIG_PAGECACHE: A pointer to 8-byte aligned memory (pMem),
		 ** the size of each page cache line (sz), and the number of cache lines
		 ** (N). */
		_sqlite3Config.FpPage = libc.VaUintptr(&ap)
		_sqlite3Config.FszPage = libc.VaInt32(&ap)
		_sqlite3Config.FnPage = libc.VaInt32(&ap)
	case int32(SQLITE_CONFIG_PCACHE_HDRSZ):
		/* EVIDENCE-OF: R-39100-27317 The SQLITE_CONFIG_PCACHE_HDRSZ option takes
		 ** a single parameter which is a pointer to an integer and writes into
		 ** that integer the number of extra bytes per page required for each page
		 ** in SQLITE_CONFIG_PAGECACHE. */
		**(**int32)(__ccgo_up(libc.VaUintptr(&ap))) = _sqlite3HeaderSizeBtree(tls) + _sqlite3HeaderSizePcache(tls) + _sqlite3HeaderSizePcache1(tls)
	case int32(SQLITE_CONFIG_PCACHE):
		/* no-op */
	case int32(SQLITE_CONFIG_GETPCACHE):
		/* now an error */
		rc = int32(SQLITE_ERROR)
	case int32(SQLITE_CONFIG_PCACHE2):
		/* EVIDENCE-OF: R-63325-48378 The SQLITE_CONFIG_PCACHE2 option takes a
		 ** single argument which is a pointer to an sqlite3_pcache_methods2
		 ** object. This object specifies the interface to a custom page cache
		 ** implementation. */
		_sqlite3Config.Fpcache2 = **(**Tsqlite3_pcache_methods2)(__ccgo_up(libc.VaUintptr(&ap)))
	case int32(SQLITE_CONFIG_GETPCACHE2):
		/* EVIDENCE-OF: R-22035-46182 The SQLITE_CONFIG_GETPCACHE2 option takes a
		 ** single argument which is a pointer to an sqlite3_pcache_methods2
		 ** object. SQLite copies of the current page cache implementation into
		 ** that object. */
		if _sqlite3Config.Fpcache2.FxInit == uintptr(0) {
			_sqlite3PCacheSetDefault(tls)
		}
		**(**Tsqlite3_pcache_methods2)(__ccgo_up(libc.VaUintptr(&ap))) = _sqlite3Config.Fpcache2
		break
		/* EVIDENCE-OF: R-06626-12911 The SQLITE_CONFIG_HEAP option is only
		 ** available if SQLite is compiled with either SQLITE_ENABLE_MEMSYS3 or
		 ** SQLITE_ENABLE_MEMSYS5 and returns SQLITE_ERROR if invoked otherwise. */
		fallthrough
	case int32(SQLITE_CONFIG_LOOKASIDE):
		_sqlite3Config.FszLookaside = libc.VaInt32(&ap)
		_sqlite3Config.FnLookaside = libc.VaInt32(&ap)
		break
		/* Record a pointer to the logger function and its first argument.
		 ** The default is NULL.  Logging is disabled if the function pointer is
		 ** NULL.
		 */
		fallthrough
	case int32(SQLITE_CONFIG_LOG):
		xLog = libc.VaUintptr(&ap)
		pLogArg = libc.VaUintptr(&ap)
		libc.AtomicStoreNUintptr(uintptr(unsafe.Pointer(&_sqlite3Config))+376, xLog, libc.Int32FromInt32(__ATOMIC_RELAXED))
		libc.AtomicStoreNUintptr(uintptr(unsafe.Pointer(&_sqlite3Config))+384, pLogArg, libc.Int32FromInt32(__ATOMIC_RELAXED))
		break
		/* EVIDENCE-OF: R-55548-33817 The compile-time setting for URI filenames
		 ** can be changed at start-time using the
		 ** sqlite3_config(SQLITE_CONFIG_URI,1) or
		 ** sqlite3_config(SQLITE_CONFIG_URI,0) configuration calls.
		 */
		fallthrough
	case int32(SQLITE_CONFIG_URI):
		/* EVIDENCE-OF: R-25451-61125 The SQLITE_CONFIG_URI option takes a single
		 ** argument of type int. If non-zero, then URI handling is globally
		 ** enabled. If the parameter is zero, then URI handling is globally
		 ** disabled. */
		bOpenUri = libc.VaInt32(&ap)
		libc.AtomicStoreNUint8(uintptr(unsafe.Pointer(&_sqlite3Config))+6, libc.Uint8FromInt32(bOpenUri), libc.Int32FromInt32(__ATOMIC_RELAXED))
	case int32(SQLITE_CONFIG_COVERING_INDEX_SCAN):
		/* EVIDENCE-OF: R-36592-02772 The SQLITE_CONFIG_COVERING_INDEX_SCAN
		 ** option takes a single integer argument which is interpreted as a
		 ** boolean in order to enable or disable the use of covering indices for
		 ** full table scans in the query optimizer. */
		_sqlite3Config.FbUseCis = libc.Uint8FromInt32(libc.VaInt32(&ap))
	case int32(SQLITE_CONFIG_MMAP_SIZE):
		/* EVIDENCE-OF: R-58063-38258 SQLITE_CONFIG_MMAP_SIZE takes two 64-bit
		 ** integer (sqlite3_int64) values that are the default mmap size limit
		 ** (the default setting for PRAGMA mmap_size) and the maximum allowed
		 ** mmap size limit. */
		szMmap = libc.VaInt64(&ap)
		mxMmap = libc.VaInt64(&ap)
		/* EVIDENCE-OF: R-53367-43190 If either argument to this option is
		 ** negative, then that argument is changed to its compile-time default.
		 **
		 ** EVIDENCE-OF: R-34993-45031 The maximum allowed mmap size will be
		 ** silently truncated if necessary so that it does not exceed the
		 ** compile-time maximum mmap size set by the SQLITE_MAX_MMAP_SIZE
		 ** compile-time option.
		 */
		if mxMmap < 0 || mxMmap > 0 {
			mxMmap = 0
		}
		if szMmap < 0 {
			szMmap = SQLITE_DEFAULT_MMAP_SIZE
		}
		if szMmap > mxMmap {
			szMmap = mxMmap
		}
		_sqlite3Config.FmxMmap = mxMmap
		_sqlite3Config.FszMmap = szMmap
	case int32(SQLITE_CONFIG_PMASZ):
		_sqlite3Config.FszPma = libc.VaUint32(&ap)
	case int32(SQLITE_CONFIG_STMTJRNL_SPILL):
		_sqlite3Config.FnStmtSpill = libc.VaInt32(&ap)
	case int32(SQLITE_CONFIG_MEMDB_MAXSIZE):
		_sqlite3Config.FmxMemdbSize = libc.VaInt64(&ap)
	case int32(SQLITE_CONFIG_ROWID_IN_VIEW):
		pVal = libc.VaUintptr(&ap)
		**(**int32)(__ccgo_up(pVal)) = 0
	default:
		rc = int32(SQLITE_ERROR)
		break
	}
	_ = ap
	return rc
}

// C documentation
//
//	/*
//	** This function is used to set the schema of a virtual table.  It is only
//	** valid to call this function from within the xCreate() or xConnect() of a
//	** virtual table module.
//	*/
func Xsqlite3_declare_vtab(tls *libc.TLS, db uintptr, zCreateTable uintptr) (r int32) {
	bp := tls.Alloc(448)
	defer tls.Free(448)
	var i, initBusy, rc int32
	var pCtx, pIdx, pNew, pTab, z, v3 uintptr
	var v2 Ti16
	var _ /* sParse at bp+0 */ TParse
	var _ /* tokenType at bp+424 */ int32
	_, _, _, _, _, _, _, _, _, _ = i, initBusy, pCtx, pIdx, pNew, pTab, rc, z, v2, v3
	rc = SQLITE_OK
	/* Verify that the first two keywords in the CREATE TABLE statement
	 ** really are "CREATE" and "TABLE".  If this is not the case, then
	 ** sqlite3_declare_vtab() is being misused.
	 */
	z = zCreateTable
	i = 0
	for {
		if !(_aKeyword1[i] != 0) {
			break
		}
		**(**int32)(__ccgo_up(bp + 424)) = 0
		for cond := true; cond; cond = **(**int32)(__ccgo_up(bp + 424)) == int32(TK_SPACE) || **(**int32)(__ccgo_up(bp + 424)) == int32(TK_COMMENT) {
			z = z + uintptr(_sqlite3GetToken(tls, z, bp+424))
		}
		if **(**int32)(__ccgo_up(bp + 424)) != libc.Int32FromUint8(_aKeyword1[i]) {
			_sqlite3ErrorWithMsg(tls, db, int32(SQLITE_ERROR), __ccgo_ts+23598, 0)
			return int32(SQLITE_ERROR)
		}
		goto _1
	_1:
		;
		i = i + 1
	}
	Xsqlite3_mutex_enter(tls, (*Tsqlite3)(unsafe.Pointer(db)).Fmutex)
	pCtx = (*Tsqlite3)(unsafe.Pointer(db)).FpVtabCtx
	if !(pCtx != 0) || (*TVtabCtx)(unsafe.Pointer(pCtx)).FbDeclared != 0 {
		_sqlite3Error(tls, db, _sqlite3MisuseError(tls, int32(162730)))
		Xsqlite3_mutex_leave(tls, (*Tsqlite3)(unsafe.Pointer(db)).Fmutex)
		return _sqlite3MisuseError(tls, int32(162732))
	}
	pTab = (*TVtabCtx)(unsafe.Pointer(pCtx)).FpTab
	_sqlite3ParseObjectInit(tls, bp, db)
	(**(**TParse)(__ccgo_up(bp))).FeParseMode = uint8(PARSE_MODE_DECLARE_VTAB)
	libc.SetBitFieldPtr16Uint32(bp+40, libc.Uint32FromInt32(1), 0, 0x1)
	/* We should never be able to reach this point while loading the
	 ** schema.  Nevertheless, defend against that (turn off db->init.busy)
	 ** in case a bug arises. */
	initBusy = libc.Int32FromUint8((*Tsqlite3)(unsafe.Pointer(db)).Finit1.Fbusy)
	(*Tsqlite3)(unsafe.Pointer(db)).Finit1.Fbusy = uint8(0)
	(**(**TParse)(__ccgo_up(bp))).FnQueryLoop = int16(1)
	if SQLITE_OK == _sqlite3RunParser(tls, bp, zCreateTable) {
		if !((*TTable)(unsafe.Pointer(pTab)).FaCol != 0) {
			pNew = (**(**TParse)(__ccgo_up(bp))).FpNewTable
			(*TTable)(unsafe.Pointer(pTab)).FaCol = (*TTable)(unsafe.Pointer(pNew)).FaCol
			_sqlite3ExprListDelete(tls, db, (*(*struct {
				FaddColOffset int32
				FpFKey        uintptr
				FpDfltList    uintptr
			})(unsafe.Pointer(pNew + 64))).FpDfltList)
			v2 = (*TTable)(unsafe.Pointer(pNew)).FnCol
			(*TTable)(unsafe.Pointer(pTab)).FnCol = v2
			(*TTable)(unsafe.Pointer(pTab)).FnNVCol = v2
			**(**Tu32)(__ccgo_up(pTab + 48)) |= (*TTable)(unsafe.Pointer(pNew)).FtabFlags & libc.Uint32FromInt32(libc.Int32FromInt32(TF_WithoutRowid)|libc.Int32FromInt32(TF_NoVisibleRowid))
			(*TTable)(unsafe.Pointer(pNew)).FnCol = 0
			(*TTable)(unsafe.Pointer(pNew)).FaCol = uintptr(0)
			if !((*TTable)(unsafe.Pointer(pNew)).FtabFlags&libc.Uint32FromInt32(TF_WithoutRowid) == libc.Uint32FromInt32(0)) && (*Tsqlite3_module)(unsafe.Pointer((*TModule)(unsafe.Pointer((*TVTable)(unsafe.Pointer((*TVtabCtx)(unsafe.Pointer(pCtx)).FpVTable)).FpMod)).FpModule)).FxUpdate != uintptr(0) && libc.Int32FromUint16((*TIndex)(unsafe.Pointer(_sqlite3PrimaryKeyIndex(tls, pNew))).FnKeyCol) != int32(1) {
				/* WITHOUT ROWID virtual tables must either be read-only (xUpdate==0)
				 ** or else must have a single-column PRIMARY KEY */
				rc = int32(SQLITE_ERROR)
			}
			pIdx = (*TTable)(unsafe.Pointer(pNew)).FpIndex
			if pIdx != 0 {
				(*TTable)(unsafe.Pointer(pTab)).FpIndex = pIdx
				(*TTable)(unsafe.Pointer(pNew)).FpIndex = uintptr(0)
				(*TIndex)(unsafe.Pointer(pIdx)).FpTable = pTab
			}
		}
		(*TVtabCtx)(unsafe.Pointer(pCtx)).FbDeclared = int32(1)
	} else {
		if (**(**TParse)(__ccgo_up(bp))).FzErrMsg != 0 {
			v3 = __ccgo_ts + 3933
		} else {
			v3 = uintptr(0)
		}
		_sqlite3ErrorWithMsg(tls, db, int32(SQLITE_ERROR), v3, libc.VaList(bp+440, (**(**TParse)(__ccgo_up(bp))).FzErrMsg))
		_sqlite3DbFree(tls, db, (**(**TParse)(__ccgo_up(bp))).FzErrMsg)
		rc = int32(SQLITE_ERROR)
	}
	(**(**TParse)(__ccgo_up(bp))).FeParseMode = uint8(PARSE_MODE_NORMAL)
	if (**(**TParse)(__ccgo_up(bp))).FpVdbe != 0 {
		_sqlite3VdbeFinalize(tls, (**(**TParse)(__ccgo_up(bp))).FpVdbe)
	}
	_sqlite3DeleteTable(tls, db, (**(**TParse)(__ccgo_up(bp))).FpNewTable)
	_sqlite3ParseObjectReset(tls, bp)
	(*Tsqlite3)(unsafe.Pointer(db)).Finit1.Fbusy = libc.Uint8FromInt32(initBusy)
	rc = _sqlite3ApiExit(tls, db, rc)
	Xsqlite3_mutex_leave(tls, (*Tsqlite3)(unsafe.Pointer(db)).Fmutex)
	return rc
}

// C documentation
//
//	/* Convert zSchema to a MemDB and initialize its content.
//	*/
func Xsqlite3_deserialize(tls *libc.TLS, db uintptr, zSchema uintptr, pData uintptr, szDb Tsqlite3_int64, szBuf Tsqlite3_int64, mFlags uint32) (r int32) {
	bp := tls.Alloc(32)
	defer tls.Free(32)
	var iDb, rc int32
	var p, pStore, zSql uintptr
	var _ /* pStmt at bp+0 */ uintptr
	_, _, _, _, _ = iDb, p, pStore, rc, zSql
	**(**uintptr)(__ccgo_up(bp)) = uintptr(0)
	Xsqlite3_mutex_enter(tls, (*Tsqlite3)(unsafe.Pointer(db)).Fmutex)
	if zSchema == uintptr(0) {
		zSchema = (**(**TDb)(__ccgo_up((*Tsqlite3)(unsafe.Pointer(db)).FaDb))).FzDbSName
	}
	iDb = _sqlite3FindDbName(tls, db, zSchema)
	if iDb < int32(2) && iDb != 0 {
		rc = int32(SQLITE_ERROR)
		goto end_deserialize
	}
	zSql = Xsqlite3_mprintf(tls, __ccgo_ts+4174, libc.VaList(bp+16, zSchema))
	if zSql == uintptr(0) {
		rc = int32(SQLITE_NOMEM)
	} else {
		rc = Xsqlite3_prepare_v2(tls, db, zSql, -int32(1), bp, uintptr(0))
		Xsqlite3_free(tls, zSql)
	}
	if rc != 0 {
		goto end_deserialize
	}
	(*Tsqlite3)(unsafe.Pointer(db)).Finit1.FiDb = libc.Uint8FromInt32(iDb)
	libc.SetBitFieldPtr8Uint32(db+192+8, libc.Uint32FromInt32(1), 3, 0x8)
	Xsqlite3_step(tls, **(**uintptr)(__ccgo_up(bp)))
	libc.SetBitFieldPtr8Uint32(db+192+8, libc.Uint32FromInt32(0), 3, 0x8)
	rc = Xsqlite3_finalize(tls, **(**uintptr)(__ccgo_up(bp)))
	if rc != SQLITE_OK {
		goto end_deserialize
	}
	p = _memdbFromDbSchema(tls, db, zSchema)
	if p == uintptr(0) {
		rc = int32(SQLITE_ERROR)
	} else {
		pStore = (*TMemFile)(unsafe.Pointer(p)).FpStore
		(*TMemStore)(unsafe.Pointer(pStore)).FaData = pData
		pData = uintptr(0)
		(*TMemStore)(unsafe.Pointer(pStore)).Fsz = szDb
		(*TMemStore)(unsafe.Pointer(pStore)).FszAlloc = szBuf
		(*TMemStore)(unsafe.Pointer(pStore)).FszMax = szBuf
		if (*TMemStore)(unsafe.Pointer(pStore)).FszMax < _sqlite3Config.FmxMemdbSize {
			(*TMemStore)(unsafe.Pointer(pStore)).FszMax = _sqlite3Config.FmxMemdbSize
		}
		(*TMemStore)(unsafe.Pointer(pStore)).FmFlags = mFlags
		rc = SQLITE_OK
	}
	goto end_deserialize
end_deserialize:
	;
	if pData != 0 && mFlags&uint32(SQLITE_DESERIALIZE_FREEONCLOSE) != uint32(0) {
		Xsqlite3_free(tls, pData)
	}
	Xsqlite3_mutex_leave(tls, (*Tsqlite3)(unsafe.Pointer(db)).Fmutex)
	return rc
}

// C documentation
//
//	/*
//	** Query the database.  But instead of invoking a callback for each row,
//	** malloc() for space to hold the result and return the entire results
//	** at the conclusion of the call.
//	**
//	** The result that is written to ***pazResult is held in memory obtained
//	** from malloc().  But the caller cannot free this memory directly.
//	** Instead, the entire table should be passed to sqlite3_free_table() when
//	** the calling procedure is finished using it.
//	*/
func Xsqlite3_get_table(tls *libc.TLS, db uintptr, zSql uintptr, pazResult uintptr, pnRow uintptr, pnColumn uintptr, pzErrMsg uintptr) (r int32) {
	bp := tls.Alloc(64)
	defer tls.Free(64)
	var azNew uintptr
	var rc int32
	var _ /* res at bp+0 */ TTabResult
	_, _ = azNew, rc
	**(**uintptr)(__ccgo_up(pazResult)) = uintptr(0)
	if pnColumn != 0 {
		**(**int32)(__ccgo_up(pnColumn)) = 0
	}
	if pnRow != 0 {
		**(**int32)(__ccgo_up(pnRow)) = 0
	}
	if pzErrMsg != 0 {
		**(**uintptr)(__ccgo_up(pzErrMsg)) = uintptr(0)
	}
	(**(**TTabResult)(__ccgo_up(bp))).FzErrMsg = uintptr(0)
	(**(**TTabResult)(__ccgo_up(bp))).FnRow = uint32(0)
	(**(**TTabResult)(__ccgo_up(bp))).FnColumn = uint32(0)
	(**(**TTabResult)(__ccgo_up(bp))).FnData = uint32(1)
	(**(**TTabResult)(__ccgo_up(bp))).FnAlloc = uint32(20)
	(**(**TTabResult)(__ccgo_up(bp))).Frc = SQLITE_OK
	(**(**TTabResult)(__ccgo_up(bp))).FazResult = Xsqlite3_malloc64(tls, uint64(8)*uint64((**(**TTabResult)(__ccgo_up(bp))).FnAlloc))
	if (**(**TTabResult)(__ccgo_up(bp))).FazResult == uintptr(0) {
		(*Tsqlite3)(unsafe.Pointer(db)).FerrCode = int32(SQLITE_NOMEM)
		return int32(SQLITE_NOMEM)
	}
	**(**uintptr)(__ccgo_up((**(**TTabResult)(__ccgo_up(bp))).FazResult)) = uintptr(0)
	rc = Xsqlite3_exec(tls, db, zSql, __ccgo_fp(_sqlite3_get_table_cb), bp, pzErrMsg)
	**(**uintptr)(__ccgo_up((**(**TTabResult)(__ccgo_up(bp))).FazResult)) = uintptr(libc.Int64FromUint32((**(**TTabResult)(__ccgo_up(bp))).FnData))
	if rc&int32(0xff) == int32(SQLITE_ABORT) {
		Xsqlite3_free_table(tls, (**(**TTabResult)(__ccgo_up(bp))).FazResult+1*8)
		if (**(**TTabResult)(__ccgo_up(bp))).FzErrMsg != 0 {
			if pzErrMsg != 0 {
				Xsqlite3_free(tls, **(**uintptr)(__ccgo_up(pzErrMsg)))
				**(**uintptr)(__ccgo_up(pzErrMsg)) = Xsqlite3_mprintf(tls, __ccgo_ts+3933, libc.VaList(bp+48, (**(**TTabResult)(__ccgo_up(bp))).FzErrMsg))
			}
			Xsqlite3_free(tls, (**(**TTabResult)(__ccgo_up(bp))).FzErrMsg)
		}
		(*Tsqlite3)(unsafe.Pointer(db)).FerrCode = (**(**TTabResult)(__ccgo_up(bp))).Frc /* Assume 32-bit assignment is atomic */
		return (**(**TTabResult)(__ccgo_up(bp))).Frc
	}
	Xsqlite3_free(tls, (**(**TTabResult)(__ccgo_up(bp))).FzErrMsg)
	if rc != SQLITE_OK {
		Xsqlite3_free_table(tls, (**(**TTabResult)(__ccgo_up(bp))).FazResult+1*8)
		return rc
	}
	if (**(**TTabResult)(__ccgo_up(bp))).FnAlloc > (**(**TTabResult)(__ccgo_up(bp))).FnData {
		azNew = _sqlite3Realloc(tls, (**(**TTabResult)(__ccgo_up(bp))).FazResult, uint64(8)*uint64((**(**TTabResult)(__ccgo_up(bp))).FnData))
		if azNew == uintptr(0) {
			Xsqlite3_free_table(tls, (**(**TTabResult)(__ccgo_up(bp))).FazResult+1*8)
			(*Tsqlite3)(unsafe.Pointer(db)).FerrCode = int32(SQLITE_NOMEM)
			return int32(SQLITE_NOMEM)
		}
		(**(**TTabResult)(__ccgo_up(bp))).FazResult = azNew
	}
	**(**uintptr)(__ccgo_up(pazResult)) = (**(**TTabResult)(__ccgo_up(bp))).FazResult + 1*8
	if pnColumn != 0 {
		**(**int32)(__ccgo_up(pnColumn)) = libc.Int32FromUint32((**(**TTabResult)(__ccgo_up(bp))).FnColumn)
	}
	if pnRow != 0 {
		**(**int32)(__ccgo_up(pnRow)) = libc.Int32FromUint32((**(**TTabResult)(__ccgo_up(bp))).FnRow)
	}
	return rc
}

// C documentation
//
//	/*
//	** Open a new database handle.
//	*/
func Xsqlite3_open16(tls *libc.TLS, zFilename uintptr, ppDb uintptr) (r int32) {
	var pVal, zFilename8 uintptr
	var rc int32
	var v1 Tu8
	_, _, _, _ = pVal, rc, zFilename8, v1
	**(**uintptr)(__ccgo_up(ppDb)) = uintptr(0)
	rc = Xsqlite3_initialize(tls)
	if rc != 0 {
		return rc
	}
	if zFilename == uintptr(0) {
		zFilename = __ccgo_ts + 26257
	}
	pVal = _sqlite3ValueNew(tls, uintptr(0))
	_sqlite3ValueSetStr(tls, pVal, -int32(1), zFilename, uint8(SQLITE_UTF16LE), libc.UintptrFromInt32(0))
	zFilename8 = _sqlite3ValueText(tls, pVal, uint8(SQLITE_UTF8))
	if zFilename8 != 0 {
		rc = _openDatabase(tls, zFilename8, ppDb, libc.Uint32FromInt32(libc.Int32FromInt32(SQLITE_OPEN_READWRITE)|libc.Int32FromInt32(SQLITE_OPEN_CREATE)), uintptr(0))
		if rc == SQLITE_OK && !(libc.Int32FromUint16((*TSchema)(unsafe.Pointer((**(**TDb)(__ccgo_up((*Tsqlite3)(unsafe.Pointer(**(**uintptr)(__ccgo_up(ppDb)))).FaDb))).FpSchema)).FschemaFlags)&libc.Int32FromInt32(DB_SchemaLoaded) == libc.Int32FromInt32(DB_SchemaLoaded)) {
			v1 = libc.Uint8FromInt32(SQLITE_UTF16LE)
			(*Tsqlite3)(unsafe.Pointer(**(**uintptr)(__ccgo_up(ppDb)))).Fenc = v1
			(*TSchema)(unsafe.Pointer((**(**TDb)(__ccgo_up((*Tsqlite3)(unsafe.Pointer(**(**uintptr)(__ccgo_up(ppDb)))).FaDb))).FpSchema)).Fenc = v1
		}
	} else {
		rc = int32(SQLITE_NOMEM)
	}
	_sqlite3ValueFree(tls, pVal)
	return rc & int32(0xff)
}

// C documentation
//
//	/*
//	** Declare that a function has been overloaded by a virtual table.
//	**
//	** If the function already exists as a regular global function, then
//	** this routine is a no-op.  If the function does not exist, then create
//	** a new one that always throws a run-time error.
//	**
//	** When virtual tables intend to provide an overloaded function, they
//	** should call this routine to make sure the global function exists.
//	** A global function must exist in order for name resolution to work
//	** properly.
//	*/
func Xsqlite3_overload_function(tls *libc.TLS, db uintptr, zName uintptr, nArg int32) (r int32) {
	bp := tls.Alloc(16)
	defer tls.Free(16)
	var rc int32
	var zCopy uintptr
	_, _ = rc, zCopy
	Xsqlite3_mutex_enter(tls, (*Tsqlite3)(unsafe.Pointer(db)).Fmutex)
	rc = libc.BoolInt32(_sqlite3FindFunction(tls, db, zName, nArg, uint8(SQLITE_UTF8), uint8(0)) != uintptr(0))
	Xsqlite3_mutex_leave(tls, (*Tsqlite3)(unsafe.Pointer(db)).Fmutex)
	if rc != 0 {
		return SQLITE_OK
	}
	zCopy = Xsqlite3_mprintf(tls, __ccgo_ts+3933, libc.VaList(bp+8, zName))
	if zCopy == uintptr(0) {
		return int32(SQLITE_NOMEM)
	}
	return Xsqlite3_create_function_v2(tls, db, zName, nArg, int32(SQLITE_UTF8), zCopy, __ccgo_fp(_sqlite3InvalidFunction), uintptr(0), uintptr(0), __ccgo_fp(Xsqlite3_free))
}

// C documentation
//
//	/* Force an SQLITE_TOOBIG error. */
func Xsqlite3_result_error_toobig(tls *libc.TLS, pCtx uintptr) {
	(*Tsqlite3_context)(unsafe.Pointer(pCtx)).FisError = int32(SQLITE_TOOBIG)
	_sqlite3VdbeMemSetStr(tls, (*Tsqlite3_context)(unsafe.Pointer(pCtx)).FpOut, __ccgo_ts+5583, int64(-int32(1)), uint8(SQLITE_UTF8), libc.UintptrFromInt32(0))
}

// C documentation
//
//	/*
//	** Return the serialization of a database
//	*/
func Xsqlite3_serialize(tls *libc.TLS, db uintptr, zSchema uintptr, piSize uintptr, mFlags uint32) (r uintptr) {
	bp := tls.Alloc(32)
	defer tls.Free(32)
	var iDb, nPage, pgno, rc, szPage, v1 int32
	var p, pBt, pOut, pPager, pStore, pTo, zSql uintptr
	var sz Tsqlite3_int64
	var _ /* pPage at bp+8 */ uintptr
	var _ /* pStmt at bp+0 */ uintptr
	_, _, _, _, _, _, _, _, _, _, _, _, _, _ = iDb, nPage, p, pBt, pOut, pPager, pStore, pTo, pgno, rc, sz, szPage, zSql, v1
	szPage = 0
	**(**uintptr)(__ccgo_up(bp)) = uintptr(0)
	pOut = uintptr(0)
	Xsqlite3_mutex_enter(tls, (*Tsqlite3)(unsafe.Pointer(db)).Fmutex)
	if zSchema == uintptr(0) {
		zSchema = (**(**TDb)(__ccgo_up((*Tsqlite3)(unsafe.Pointer(db)).FaDb))).FzDbSName
	}
	p = _memdbFromDbSchema(tls, db, zSchema)
	iDb = _sqlite3FindDbName(tls, db, zSchema)
	if piSize != 0 {
		**(**Tsqlite3_int64)(__ccgo_up(piSize)) = int64(-int32(1))
	}
	if iDb < 0 {
		goto serialize_out
	}
	if p != 0 {
		pStore = (*TMemFile)(unsafe.Pointer(p)).FpStore
		if piSize != 0 {
			**(**Tsqlite3_int64)(__ccgo_up(piSize)) = (*TMemStore)(unsafe.Pointer(pStore)).Fsz
		}
		if mFlags&uint32(SQLITE_SERIALIZE_NOCOPY) != 0 {
			pOut = (*TMemStore)(unsafe.Pointer(pStore)).FaData
		} else {
			pOut = Xsqlite3_malloc64(tls, libc.Uint64FromInt64((*TMemStore)(unsafe.Pointer(pStore)).Fsz))
			if pOut != 0 {
				libc.Xmemcpy(tls, pOut, (*TMemStore)(unsafe.Pointer(pStore)).FaData, libc.Uint64FromInt64((*TMemStore)(unsafe.Pointer(pStore)).Fsz))
			}
		}
		goto serialize_out
	}
	pBt = (**(**TDb)(__ccgo_up((*Tsqlite3)(unsafe.Pointer(db)).FaDb + uintptr(iDb)*32))).FpBt
	if pBt == uintptr(0) {
		goto serialize_out
	}
	szPage = _sqlite3BtreeGetPageSize(tls, pBt)
	zSql = Xsqlite3_mprintf(tls, __ccgo_ts+4126, libc.VaList(bp+24, zSchema))
	if zSql != 0 {
		v1 = Xsqlite3_prepare_v2(tls, db, zSql, -int32(1), bp, uintptr(0))
	} else {
		v1 = int32(SQLITE_NOMEM)
	}
	rc = v1
	Xsqlite3_free(tls, zSql)
	if rc != 0 {
		goto serialize_out
	}
	rc = Xsqlite3_step(tls, **(**uintptr)(__ccgo_up(bp)))
	if rc == int32(SQLITE_ROW) {
		sz = Xsqlite3_column_int64(tls, **(**uintptr)(__ccgo_up(bp)), 0) * int64(szPage)
		if sz == 0 {
			Xsqlite3_reset(tls, **(**uintptr)(__ccgo_up(bp)))
			Xsqlite3_exec(tls, db, __ccgo_ts+4149, uintptr(0), uintptr(0), uintptr(0))
			rc = Xsqlite3_step(tls, **(**uintptr)(__ccgo_up(bp)))
			if rc == int32(SQLITE_ROW) {
				sz = Xsqlite3_column_int64(tls, **(**uintptr)(__ccgo_up(bp)), 0) * int64(szPage)
			}
		}
		if piSize != 0 {
			**(**Tsqlite3_int64)(__ccgo_up(piSize)) = sz
		}
		if mFlags&uint32(SQLITE_SERIALIZE_NOCOPY) != 0 {
			pOut = uintptr(0)
		} else {
			pOut = Xsqlite3_malloc64(tls, libc.Uint64FromInt64(sz))
			if pOut != 0 {
				nPage = Xsqlite3_column_int(tls, **(**uintptr)(__ccgo_up(bp)), 0)
				pPager = _sqlite3BtreePager(tls, pBt)
				pgno = int32(1)
				for {
					if !(pgno <= nPage) {
						break
					}
					**(**uintptr)(__ccgo_up(bp + 8)) = uintptr(0)
					pTo = pOut + uintptr(int64(szPage)*int64(pgno-libc.Int32FromInt32(1)))
					rc = _sqlite3PagerGet(tls, pPager, libc.Uint32FromInt32(pgno), bp+8, 0)
					if rc == SQLITE_OK {
						libc.Xmemcpy(tls, pTo, _sqlite3PagerGetData(tls, **(**uintptr)(__ccgo_up(bp + 8))), libc.Uint64FromInt32(szPage))
					} else {
						libc.Xmemset(tls, pTo, 0, libc.Uint64FromInt32(szPage))
					}
					_sqlite3PagerUnref(tls, **(**uintptr)(__ccgo_up(bp + 8)))
					goto _2
				_2:
					;
					pgno = pgno + 1
				}
			}
		}
	}
	Xsqlite3_finalize(tls, **(**uintptr)(__ccgo_up(bp)))
	goto serialize_out
serialize_out:
	;
	Xsqlite3_mutex_leave(tls, (*Tsqlite3)(unsafe.Pointer(db)).Fmutex)
	return pOut
}

// C documentation
//
//	/*
//	** Set the error code and error message associated with the database handle.
//	**
//	** This routine is intended to be called by outside extensions (ex: the
//	** Session extension). Internal logic should invoke sqlite3Error() or
//	** sqlite3ErrorWithMsg() directly.
//	*/
func Xsqlite3_set_errmsg(tls *libc.TLS, db uintptr, errcode int32, zMsg uintptr) (r int32) {
	bp := tls.Alloc(16)
	defer tls.Free(16)
	var rc int32
	_ = rc
	rc = SQLITE_OK
	if !(_sqlite3SafetyCheckOk(tls, db) != 0) {
		return _sqlite3MisuseError(tls, int32(190121))
	}
	Xsqlite3_mutex_enter(tls, (*Tsqlite3)(unsafe.Pointer(db)).Fmutex)
	if zMsg != 0 {
		_sqlite3ErrorWithMsg(tls, db, errcode, __ccgo_ts+3933, libc.VaList(bp+8, zMsg))
	} else {
		_sqlite3Error(tls, db, errcode)
	}
	rc = _sqlite3ApiExit(tls, db, rc)
	Xsqlite3_mutex_leave(tls, (*Tsqlite3)(unsafe.Pointer(db)).Fmutex)
	return rc
}

// C documentation
//
//	/************** End of stmt.c ************************************************/
//	/* Return the source-id for this library */
func Xsqlite3_sourceid(tls *libc.TLS) (r uintptr) {
	return __ccgo_ts + 42528
}

// C documentation
//
//	/*
//	** Return meta information about a specific column of a database table.
//	** See comment in sqlite3.h (sqlite.h.in) for details.
//	*/
func Xsqlite3_table_column_metadata(tls *libc.TLS, db uintptr, zDbName uintptr, zTableName uintptr, zColumnName uintptr, pzDataType uintptr, pzCollSeq uintptr, pNotNull uintptr, pPrimaryKey uintptr, pAutoinc uintptr) (r int32) {
	bp := tls.Alloc(32)
	defer tls.Free(32)
	var autoinc, iCol, notnull, primarykey, rc int32
	var pCol, pTab, zCollSeq, zDataType, v1 uintptr
	var _ /* zErrMsg at bp+0 */ uintptr
	_, _, _, _, _, _, _, _, _, _ = autoinc, iCol, notnull, pCol, pTab, primarykey, rc, zCollSeq, zDataType, v1
	**(**uintptr)(__ccgo_up(bp)) = uintptr(0)
	pTab = uintptr(0)
	pCol = uintptr(0)
	iCol = 0
	zDataType = uintptr(0)
	zCollSeq = uintptr(0)
	notnull = 0
	primarykey = 0
	autoinc = 0
	/* Ensure the database schema has been loaded */
	Xsqlite3_mutex_enter(tls, (*Tsqlite3)(unsafe.Pointer(db)).Fmutex)
	_sqlite3BtreeEnterAll(tls, db)
	rc = _sqlite3Init(tls, db, bp)
	if SQLITE_OK != rc {
		goto error_out
	}
	/* Locate the table in question */
	pTab = _sqlite3FindTable(tls, db, zTableName, zDbName)
	if !(pTab != 0) || libc.Int32FromUint8((*TTable)(unsafe.Pointer(pTab)).FeTabType) == int32(TABTYP_VIEW) {
		pTab = uintptr(0)
		goto error_out
	}
	/* Find the column for which info is requested */
	if zColumnName == uintptr(0) {
		/* Query for existence of table only */
	} else {
		iCol = _sqlite3ColumnIndex(tls, pTab, zColumnName)
		if iCol >= 0 {
			pCol = (*TTable)(unsafe.Pointer(pTab)).FaCol + uintptr(iCol)*16
		} else {
			if (*TTable)(unsafe.Pointer(pTab)).FtabFlags&uint32(TF_WithoutRowid) == uint32(0) && _sqlite3IsRowid(tls, zColumnName) != 0 {
				iCol = int32((*TTable)(unsafe.Pointer(pTab)).FiPKey)
				if iCol >= 0 {
					v1 = (*TTable)(unsafe.Pointer(pTab)).FaCol + uintptr(iCol)*16
				} else {
					v1 = uintptr(0)
				}
				pCol = v1
			} else {
				pTab = uintptr(0)
				goto error_out
			}
		}
	}
	/* The following block stores the meta information that will be returned
	 ** to the caller in local variables zDataType, zCollSeq, notnull, primarykey
	 ** and autoinc. At this point there are two possibilities:
	 **
	 **     1. The specified column name was rowid", "oid" or "_rowid_"
	 **        and there is no explicitly declared IPK column.
	 **
	 **     2. The table is not a view and the column name identified an
	 **        explicitly declared column. Copy meta information from *pCol.
	 */
	if pCol != 0 {
		zDataType = _sqlite3ColumnType(tls, pCol, uintptr(0))
		zCollSeq = _sqlite3ColumnColl(tls, pCol)
		notnull = libc.BoolInt32(int32(uint32(*(*uint8)(unsafe.Pointer(pCol + 8))&0xf>>0)) != 0)
		primarykey = libc.BoolInt32(libc.Int32FromUint16((*TColumn)(unsafe.Pointer(pCol)).FcolFlags)&int32(COLFLAG_PRIMKEY) != 0)
		autoinc = libc.BoolInt32(int32((*TTable)(unsafe.Pointer(pTab)).FiPKey) == iCol && (*TTable)(unsafe.Pointer(pTab)).FtabFlags&uint32(TF_Autoincrement) != uint32(0))
	} else {
		zDataType = __ccgo_ts + 1167
		primarykey = int32(1)
	}
	if !(zCollSeq != 0) {
		zCollSeq = uintptr(unsafe.Pointer(&_sqlite3StrBINARY))
	}
	goto error_out
error_out:
	;
	_sqlite3BtreeLeaveAll(tls, db)
	/* Whether the function call succeeded or failed, set the output parameters
	 ** to whatever their local counterparts contain. If an error did occur,
	 ** this has the effect of zeroing all output parameters.
	 */
	if pzDataType != 0 {
		**(**uintptr)(__ccgo_up(pzDataType)) = zDataType
	}
	if pzCollSeq != 0 {
		**(**uintptr)(__ccgo_up(pzCollSeq)) = zCollSeq
	}
	if pNotNull != 0 {
		**(**int32)(__ccgo_up(pNotNull)) = notnull
	}
	if pPrimaryKey != 0 {
		**(**int32)(__ccgo_up(pPrimaryKey)) = primarykey
	}
	if pAutoinc != 0 {
		**(**int32)(__ccgo_up(pAutoinc)) = autoinc
	}
	if SQLITE_OK == rc && !(pTab != 0) {
		_sqlite3DbFree(tls, db, **(**uintptr)(__ccgo_up(bp)))
		**(**uintptr)(__ccgo_up(bp)) = _sqlite3MPrintf(tls, db, __ccgo_ts+26329, libc.VaList(bp+16, zTableName, zColumnName))
		rc = int32(SQLITE_ERROR)
	}
	if **(**uintptr)(__ccgo_up(bp)) != 0 {
		v1 = __ccgo_ts + 3933
	} else {
		v1 = uintptr(0)
	}
	_sqlite3ErrorWithMsg(tls, db, rc, v1, libc.VaList(bp+16, **(**uintptr)(__ccgo_up(bp))))
	_sqlite3DbFree(tls, db, **(**uintptr)(__ccgo_up(bp)))
	rc = _sqlite3ApiExit(tls, db, rc)
	Xsqlite3_mutex_leave(tls, (*Tsqlite3)(unsafe.Pointer(db)).Fmutex)
	return rc
}

// C documentation
//
//	/*
//	** Register an unlock-notify callback.
//	**
//	** This is called after connection "db" has attempted some operation
//	** but has received an SQLITE_LOCKED error because another connection
//	** (call it pOther) in the same process was busy using the same shared
//	** cache.  pOther is found by looking at db->pBlockingConnection.
//	**
//	** If there is no blocking connection, the callback is invoked immediately,
//	** before this routine returns.
//	**
//	** If pOther is already blocked on db, then report SQLITE_LOCKED, to indicate
//	** a deadlock.
//	**
//	** Otherwise, make arrangements to invoke xNotify when pOther drops
//	** its locks.
//	**
//	** Each call to this routine overrides any prior callbacks registered
//	** on the same "db".  If xNotify==0 then any prior callbacks are immediately
//	** cancelled.
//	*/
func Xsqlite3_unlock_notify(tls *libc.TLS, db uintptr, __ccgo_fp_xNotify uintptr, _pArg uintptr) (r int32) {
	bp := tls.Alloc(16)
	defer tls.Free(16)
	*(*uintptr)(unsafe.Pointer(bp)) = _pArg
	var p, v2 uintptr
	var rc int32
	_, _, _ = p, rc, v2
	rc = SQLITE_OK
	Xsqlite3_mutex_enter(tls, (*Tsqlite3)(unsafe.Pointer(db)).Fmutex)
	_enterMutex(tls)
	if __ccgo_fp_xNotify == uintptr(0) {
		_removeFromBlockedList(tls, db)
		(*Tsqlite3)(unsafe.Pointer(db)).FpBlockingConnection = uintptr(0)
		(*Tsqlite3)(unsafe.Pointer(db)).FpUnlockConnection = uintptr(0)
		(*Tsqlite3)(unsafe.Pointer(db)).FxUnlockNotify = uintptr(0)
		(*Tsqlite3)(unsafe.Pointer(db)).FpUnlockArg = uintptr(0)
	} else {
		if uintptr(0) == (*Tsqlite3)(unsafe.Pointer(db)).FpBlockingConnection {
			/* The blocking transaction has been concluded. Or there never was a
			 ** blocking transaction. In either case, invoke the notify callback
			 ** immediately.
			 */
			(*(*func(*libc.TLS, uintptr, int32))(unsafe.Pointer(&struct{ uintptr }{__ccgo_fp_xNotify})))(tls, bp, int32(1))
		} else {
			p = (*Tsqlite3)(unsafe.Pointer(db)).FpBlockingConnection
			for {
				if !(p != 0 && p != db) {
					break
				}
				goto _1
			_1:
				;
				p = (*Tsqlite3)(unsafe.Pointer(p)).FpUnlockConnection
			}
			if p != 0 {
				rc = int32(SQLITE_LOCKED) /* Deadlock detected. */
			} else {
				(*Tsqlite3)(unsafe.Pointer(db)).FpUnlockConnection = (*Tsqlite3)(unsafe.Pointer(db)).FpBlockingConnection
				(*Tsqlite3)(unsafe.Pointer(db)).FxUnlockNotify = __ccgo_fp_xNotify
				(*Tsqlite3)(unsafe.Pointer(db)).FpUnlockArg = **(**uintptr)(__ccgo_up(bp))
				_removeFromBlockedList(tls, db)
				_addToBlockedList(tls, db)
			}
		}
	}
	_leaveMutex(tls)
	if rc != 0 {
		v2 = __ccgo_ts + 26365
	} else {
		v2 = uintptr(0)
	}
	_sqlite3ErrorWithMsg(tls, db, rc, v2, 0)
	Xsqlite3_mutex_leave(tls, (*Tsqlite3)(unsafe.Pointer(db)).Fmutex)
	return rc
}

// C documentation
//
//	/*
//	** Begin adding a change to a changegroup object.
//	*/
func Xsqlite3changegroup_change_begin(tls *libc.TLS, pGrp uintptr, eOp int32, zTab uintptr, bIndirect int32, pzErr uintptr) (r int32) {
	bp := tls.Alloc(32)
	defer tls.Free(32)
	var aBuf uintptr
	var nReq, rc, v1 int32
	var _ /* pTab at bp+0 */ uintptr
	_, _, _, _ = aBuf, nReq, rc, v1
	**(**uintptr)(__ccgo_up(bp)) = uintptr(0)
	rc = SQLITE_OK
	if (*Tsqlite3_changegroup)(unsafe.Pointer(pGrp)).Fcd.FpTab != 0 {
		rc = int32(SQLITE_MISUSE)
	} else {
		if eOp != int32(SQLITE_INSERT) && eOp != int32(SQLITE_UPDATE) && eOp != int32(SQLITE_DELETE) {
			rc = int32(SQLITE_ERROR)
		} else {
			rc = _sessionChangesetFindTable(tls, pGrp, zTab, uintptr(0), bp)
		}
	}
	if rc == SQLITE_OK {
		if **(**uintptr)(__ccgo_up(bp)) == uintptr(0) {
			if pzErr != 0 {
				**(**uintptr)(__ccgo_up(pzErr)) = Xsqlite3_mprintf(tls, __ccgo_ts+21332, libc.VaList(bp+16, zTab))
			}
			rc = int32(SQLITE_ERROR)
		} else {
			if eOp == int32(SQLITE_UPDATE) {
				v1 = int32(2)
			} else {
				v1 = int32(1)
			}
			nReq = (*TSessionTable)(unsafe.Pointer(**(**uintptr)(__ccgo_up(bp)))).FnCol * v1
			(*Tsqlite3_changegroup)(unsafe.Pointer(pGrp)).Fcd.FpTab = **(**uintptr)(__ccgo_up(bp))
			(*Tsqlite3_changegroup)(unsafe.Pointer(pGrp)).Fcd.FeOp = eOp
			(*Tsqlite3_changegroup)(unsafe.Pointer(pGrp)).Fcd.FbIndirect = bIndirect
			if (*Tsqlite3_changegroup)(unsafe.Pointer(pGrp)).Fcd.FnBufAlloc < nReq {
				aBuf = Xsqlite3_realloc(tls, (*Tsqlite3_changegroup)(unsafe.Pointer(pGrp)).Fcd.FaBuf, libc.Int32FromUint64(libc.Uint64FromInt32(nReq)*uint64(16)))
				if aBuf == uintptr(0) {
					rc = int32(SQLITE_NOMEM)
				} else {
					libc.Xmemset(tls, aBuf+uintptr((*Tsqlite3_changegroup)(unsafe.Pointer(pGrp)).Fcd.FnBufAlloc)*16, 0, uint64(16)*libc.Uint64FromInt32(nReq-(*Tsqlite3_changegroup)(unsafe.Pointer(pGrp)).Fcd.FnBufAlloc))
					(*Tsqlite3_changegroup)(unsafe.Pointer(pGrp)).Fcd.FaBuf = aBuf
					(*Tsqlite3_changegroup)(unsafe.Pointer(pGrp)).Fcd.FnBufAlloc = nReq
				}
			}
		}
	}
	return rc
}

// C documentation
//
//	/*
//	** Finish any change currently being constructed by the changegroup object.
//	*/
func Xsqlite3changegroup_change_finish(tls *libc.TLS, pGrp uintptr, bDiscard int32, pzErr uintptr) (r int32) {
	bp := tls.Alloc(48)
	defer tls.Free(48)
	var aBuf, p, v2, v3 uintptr
	var eUndef Tu8
	var ii, isPK, nBuf, nZero, v7 int32
	var _ /* rc at bp+0 */ int32
	_, _, _, _, _, _, _, _, _, _ = aBuf, eUndef, ii, isPK, nBuf, nZero, p, v2, v3, v7
	**(**int32)(__ccgo_up(bp)) = SQLITE_OK
	if (*Tsqlite3_changegroup)(unsafe.Pointer(pGrp)).Fcd.FpTab != 0 {
		aBuf = (*Tsqlite3_changegroup)(unsafe.Pointer(pGrp)).Fcd.FaBuf
		if bDiscard == 0 {
			nBuf = (*TSessionTable)(unsafe.Pointer((*Tsqlite3_changegroup)(unsafe.Pointer(pGrp)).Fcd.FpTab)).FnCol
			eUndef = uint8(SQLITE_NULL)
			if (*Tsqlite3_changegroup)(unsafe.Pointer(pGrp)).Fcd.FeOp == int32(SQLITE_UPDATE) {
				ii = 0
				for {
					if !(ii < nBuf) {
						break
					}
					if **(**Tu8)(__ccgo_up((*TSessionTable)(unsafe.Pointer((*Tsqlite3_changegroup)(unsafe.Pointer(pGrp)).Fcd.FpTab)).FabPK + uintptr(ii))) != 0 {
						if (**(**TSessionBuffer)(__ccgo_up(aBuf + uintptr(ii)*16))).FnBuf <= int32(1) {
							if (**(**TSessionBuffer)(__ccgo_up(aBuf + uintptr(ii)*16))).FnBuf == int32(1) {
								v2 = __ccgo_ts + 1679
							} else {
								v2 = __ccgo_ts + 36819
							}
							**(**uintptr)(__ccgo_up(pzErr)) = Xsqlite3_mprintf(tls, __ccgo_ts+36829, libc.VaList(bp+16, v2))
							**(**int32)(__ccgo_up(bp)) = int32(SQLITE_ERROR)
							break
						} else {
							if (**(**TSessionBuffer)(__ccgo_up(aBuf + uintptr(ii+nBuf)*16))).FnBuf > 0 {
								**(**uintptr)(__ccgo_up(pzErr)) = Xsqlite3_mprintf(tls, __ccgo_ts+36876, 0)
								**(**int32)(__ccgo_up(bp)) = int32(SQLITE_ERROR)
								break
							}
						}
					} else {
						if (*Tsqlite3_changegroup)(unsafe.Pointer(pGrp)).FbPatch == 0 && libc.BoolInt32((**(**TSessionBuffer)(__ccgo_up(aBuf + uintptr(ii)*16))).FnBuf > 0) != libc.BoolInt32((**(**TSessionBuffer)(__ccgo_up(aBuf + uintptr(ii+nBuf)*16))).FnBuf > 0) {
							if (**(**TSessionBuffer)(__ccgo_up(aBuf + uintptr(ii)*16))).FnBuf != 0 {
								v2 = __ccgo_ts + 1693
							} else {
								v2 = __ccgo_ts + 36928
							}
							if (**(**TSessionBuffer)(__ccgo_up(aBuf + uintptr(ii+nBuf)*16))).FnBuf != 0 {
								v3 = __ccgo_ts + 1693
							} else {
								v3 = __ccgo_ts + 36928
							}
							**(**uintptr)(__ccgo_up(pzErr)) = Xsqlite3_mprintf(tls, __ccgo_ts+36931, libc.VaList(bp+16, ii, v2, v3))
							**(**int32)(__ccgo_up(bp)) = int32(SQLITE_ERROR)
							break
						}
					}
					goto _1
				_1:
					;
					ii = ii + 1
				}
				eUndef = uint8(0x00)
				if (*Tsqlite3_changegroup)(unsafe.Pointer(pGrp)).FbPatch == 0 {
					nBuf = nBuf * int32(2)
				}
			} else {
				ii = 0
				for {
					if !(ii < nBuf) {
						break
					}
					isPK = libc.Int32FromUint8(**(**Tu8)(__ccgo_up((*TSessionTable)(unsafe.Pointer((*Tsqlite3_changegroup)(unsafe.Pointer(pGrp)).Fcd.FpTab)).FabPK + uintptr(ii))))
					if ((*Tsqlite3_changegroup)(unsafe.Pointer(pGrp)).Fcd.FeOp == int32(SQLITE_INSERT) || (*Tsqlite3_changegroup)(unsafe.Pointer(pGrp)).FbPatch == 0 || isPK != 0) && (**(**TSessionBuffer)(__ccgo_up(aBuf + uintptr(ii)*16))).FnBuf == 0 {
						**(**uintptr)(__ccgo_up(pzErr)) = Xsqlite3_mprintf(tls, __ccgo_ts+37007, libc.VaList(bp+16, ii))
						**(**int32)(__ccgo_up(bp)) = int32(SQLITE_ERROR)
						break
					}
					if (**(**TSessionBuffer)(__ccgo_up(aBuf + uintptr(ii)*16))).FnBuf == int32(1) && isPK != 0 {
						**(**uintptr)(__ccgo_up(pzErr)) = Xsqlite3_mprintf(tls, __ccgo_ts+37046, 0)
						**(**int32)(__ccgo_up(bp)) = int32(SQLITE_ERROR)
						break
					}
					goto _5
				_5:
					;
					ii = ii + 1
				}
			}
			(*Tsqlite3_changegroup)(unsafe.Pointer(pGrp)).Fcd.Frecord.FnBuf = 0
			ii = 0
			for {
				if !(ii < nBuf) {
					break
				}
				p = (*Tsqlite3_changegroup)(unsafe.Pointer(pGrp)).Fcd.FaBuf + uintptr(ii)*16
				if (*Tsqlite3_changegroup)(unsafe.Pointer(pGrp)).FbPatch != 0 {
					if libc.Int32FromUint8(**(**Tu8)(__ccgo_up((*TSessionTable)(unsafe.Pointer((*Tsqlite3_changegroup)(unsafe.Pointer(pGrp)).Fcd.FpTab)).FabPK + uintptr(ii)))) == 0 {
						if (*Tsqlite3_changegroup)(unsafe.Pointer(pGrp)).Fcd.FeOp == int32(SQLITE_UPDATE) {
							p = p + uintptr((*TSessionTable)(unsafe.Pointer((*Tsqlite3_changegroup)(unsafe.Pointer(pGrp)).Fcd.FpTab)).FnCol)*16
						} else {
							if (*Tsqlite3_changegroup)(unsafe.Pointer(pGrp)).Fcd.FeOp == int32(SQLITE_DELETE) {
								goto _6
							}
						}
					}
				}
				if (*TSessionBuffer)(unsafe.Pointer(p)).FnBuf != 0 {
					v7 = (*TSessionBuffer)(unsafe.Pointer(p)).FnBuf
				} else {
					v7 = int32(1)
				}
				if 0 == _sessionBufferGrow(tls, pGrp+48+32, int64(v7), bp) {
					if (*TSessionBuffer)(unsafe.Pointer(p)).FnBuf != 0 {
						libc.Xmemcpy(tls, (*Tsqlite3_changegroup)(unsafe.Pointer(pGrp)).Fcd.Frecord.FaBuf+uintptr((*Tsqlite3_changegroup)(unsafe.Pointer(pGrp)).Fcd.Frecord.FnBuf), (*TSessionBuffer)(unsafe.Pointer(p)).FaBuf, libc.Uint64FromInt32((*TSessionBuffer)(unsafe.Pointer(p)).FnBuf))
						(*Tsqlite3_changegroup)(unsafe.Pointer(pGrp)).Fcd.Frecord.FnBuf += (*TSessionBuffer)(unsafe.Pointer(p)).FnBuf
					} else {
						v2 = pGrp + 48 + 32 + 8
						v7 = *(*int32)(unsafe.Pointer(v2))
						*(*int32)(unsafe.Pointer(v2)) = *(*int32)(unsafe.Pointer(v2)) + 1
						**(**Tu8)(__ccgo_up((*Tsqlite3_changegroup)(unsafe.Pointer(pGrp)).Fcd.Frecord.FaBuf + uintptr(v7))) = eUndef
					}
				}
				goto _6
			_6:
				;
				ii = ii + 1
			}
			if **(**int32)(__ccgo_up(bp)) == SQLITE_OK {
				**(**int32)(__ccgo_up(bp)) = _sessionOneChangeToHash(tls, pGrp, (*Tsqlite3_changegroup)(unsafe.Pointer(pGrp)).Fcd.FpTab, (*Tsqlite3_changegroup)(unsafe.Pointer(pGrp)).Fcd.FeOp, (*Tsqlite3_changegroup)(unsafe.Pointer(pGrp)).Fcd.FbIndirect, (*TSessionTable)(unsafe.Pointer((*Tsqlite3_changegroup)(unsafe.Pointer(pGrp)).Fcd.FpTab)).FnCol, (*Tsqlite3_changegroup)(unsafe.Pointer(pGrp)).Fcd.Frecord.FaBuf, (*Tsqlite3_changegroup)(unsafe.Pointer(pGrp)).Fcd.Frecord.FnBuf, 0)
			}
		}
		/* Reset all aBuf[] entries to "undefined". */
		nZero = (*TSessionTable)(unsafe.Pointer((*Tsqlite3_changegroup)(unsafe.Pointer(pGrp)).Fcd.FpTab)).FnCol
		if (*Tsqlite3_changegroup)(unsafe.Pointer(pGrp)).Fcd.FeOp == int32(SQLITE_UPDATE) {
			nZero = nZero + nZero
		}
		ii = 0
		for {
			if !(ii < nZero) {
				break
			}
			(**(**TSessionBuffer)(__ccgo_up((*Tsqlite3_changegroup)(unsafe.Pointer(pGrp)).Fcd.FaBuf + uintptr(ii)*16))).FnBuf = 0
			goto _10
		_10:
			;
			ii = ii + 1
		}
		(*Tsqlite3_changegroup)(unsafe.Pointer(pGrp)).Fcd.FpTab = uintptr(0)
	}
	return **(**int32)(__ccgo_up(bp))
}

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

/*
** This, the "fts5.c" source file, is a composite file that is itself
** assembled from the following files:
**
**    fts5.h
**    fts5Int.h
**    fts5parse.h          <--- Generated from fts5parse.y by Lemon
**    fts5parse.c          <--- Generated from fts5parse.y by Lemon
**    fts5_aux.c
**    fts5_buffer.c
**    fts5_config.c
**    fts5_expr.c
**    fts5_hash.c
**    fts5_index.c
**    fts5_main.c
**    fts5_storage.c
**    fts5_tokenize.c
**    fts5_unicode2.c
**    fts5_varint.c
**    fts5_vocab.c
 */

/*
** 2014 May 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.
**
******************************************************************************
**
** Interfaces to extend FTS5. Using the interfaces defined in this file,
** FTS5 may be extended with:
**
**     * custom tokenizers, and
**     * custom auxiliary functions.
 */

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

/* #include "fts5.h" */
/* #include "sqlite3ext.h" */

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

/*
** Constants for the largest and smallest possible 32-bit signed integers.
 */

/* Truncate very long tokens to this many bytes. Hard limit is
** (65536-1-1-4-9)==65521 bytes. The limiting factor is the 16-bit offset
** field that occurs at the start of each leaf page (see fts5_index.c). */

/*
** Maximum number of prefix indexes on single FTS5 table. This must be
** less than 32. If it is set to anything large than that, an #error
** directive in fts5_index.c will cause the build to fail.
 */

/*
** Maximum segments permitted in a single index
 */

/* Name of rank and rowid columns */

/*
** The assert_nc() macro is similar to the assert() macro, except that it
** is used for assert() conditions that are true only if it can be
** guranteed that the database is not corrupt.
 */

/*
** A version of memcmp() that does not cause asan errors if one of the pointer
** parameters is NULL and the number of bytes to compare is zero.
 */

/* Mark a function parameter as unused, to suppress nuisance compiler
** warnings. */

// C documentation
//
//	/*
//	** Provide a database schema to the changegroup object.
//	*/
func Xsqlite3changegroup_schema(tls *libc.TLS, pGrp uintptr, db uintptr, zDb uintptr) (r int32) {
	bp := tls.Alloc(16)
	defer tls.Free(16)
	var rc int32
	_ = rc
	rc = SQLITE_OK
	if (*Tsqlite3_changegroup)(unsafe.Pointer(pGrp)).FpList != 0 || (*Tsqlite3_changegroup)(unsafe.Pointer(pGrp)).Fdb != 0 {
		/* Cannot add a schema after one or more calls to sqlite3changegroup_add(),
		 ** or after sqlite3changegroup_schema() has already been called. */
		rc = int32(SQLITE_MISUSE)
	} else {
		(*Tsqlite3_changegroup)(unsafe.Pointer(pGrp)).FzDb = Xsqlite3_mprintf(tls, __ccgo_ts+3933, libc.VaList(bp+8, zDb))
		if (*Tsqlite3_changegroup)(unsafe.Pointer(pGrp)).FzDb == uintptr(0) {
			rc = int32(SQLITE_NOMEM)
		} else {
			(*Tsqlite3_changegroup)(unsafe.Pointer(pGrp)).Fdb = db
		}
	}
	return rc
}

// C documentation
//
//	/*
//	** Close the RBU handle.
//	*/
func Xsqlite3rbu_close(tls *libc.TLS, p uintptr, pzErrmsg uintptr) (r int32) {
	var pDb uintptr
	var rc, rc2 int32
	_, _, _ = pDb, rc, rc2
	if p != 0 {
		/* Commit the transaction to the *-oal file. */
		if (*Tsqlite3rbu)(unsafe.Pointer(p)).Frc == SQLITE_OK && (*Tsqlite3rbu)(unsafe.Pointer(p)).FeStage == int32(RBU_STAGE_OAL) {
			(*Tsqlite3rbu)(unsafe.Pointer(p)).Frc = Xsqlite3_exec(tls, (*Tsqlite3rbu)(unsafe.Pointer(p)).FdbMain, __ccgo_ts+16111, uintptr(0), uintptr(0), p+64)
		}
		/* Sync the db file if currently doing an incremental checkpoint */
		if (*Tsqlite3rbu)(unsafe.Pointer(p)).Frc == SQLITE_OK && (*Tsqlite3rbu)(unsafe.Pointer(p)).FeStage == int32(RBU_STAGE_CKPT) {
			pDb = (*Trbu_file)(unsafe.Pointer((*Tsqlite3rbu)(unsafe.Pointer(p)).FpTargetFd)).FpReal
			(*Tsqlite3rbu)(unsafe.Pointer(p)).Frc = (*(*func(*libc.TLS, uintptr, int32) int32)(unsafe.Pointer(&struct{ uintptr }{(*Tsqlite3_io_methods)(unsafe.Pointer((*Tsqlite3_file)(unsafe.Pointer(pDb)).FpMethods)).FxSync})))(tls, pDb, int32(SQLITE_SYNC_NORMAL))
		}
		_rbuSaveState(tls, p, (*Tsqlite3rbu)(unsafe.Pointer(p)).FeStage)
		if (*Tsqlite3rbu)(unsafe.Pointer(p)).Frc == SQLITE_OK && (*Tsqlite3rbu)(unsafe.Pointer(p)).FeStage == int32(RBU_STAGE_OAL) {
			(*Tsqlite3rbu)(unsafe.Pointer(p)).Frc = Xsqlite3_exec(tls, (*Tsqlite3rbu)(unsafe.Pointer(p)).FdbRbu, __ccgo_ts+16111, uintptr(0), uintptr(0), p+64)
		}
		/* Close any open statement handles. */
		_rbuObjIterFinalize(tls, p+88)
		/* If this is an RBU vacuum handle and the vacuum has either finished
		 ** successfully or encountered an error, delete the contents of the
		 ** state table. This causes the next call to sqlite3rbu_vacuum()
		 ** specifying the current target and state databases to start a new
		 ** vacuum from scratch.  */
		if (*Tsqlite3rbu)(unsafe.Pointer(p)).FzTarget == uintptr(0) && (*Tsqlite3rbu)(unsafe.Pointer(p)).Frc != SQLITE_OK && (*Tsqlite3rbu)(unsafe.Pointer(p)).FdbRbu != 0 {
			rc2 = Xsqlite3_exec(tls, (*Tsqlite3rbu)(unsafe.Pointer(p)).FdbRbu, __ccgo_ts+34673, uintptr(0), uintptr(0), uintptr(0))
			if (*Tsqlite3rbu)(unsafe.Pointer(p)).Frc == int32(SQLITE_DONE) && rc2 != SQLITE_OK {
				(*Tsqlite3rbu)(unsafe.Pointer(p)).Frc = rc2
			}
		}
		/* Close the open database handle and VFS object. */
		Xsqlite3_close(tls, (*Tsqlite3rbu)(unsafe.Pointer(p)).FdbRbu)
		Xsqlite3_close(tls, (*Tsqlite3rbu)(unsafe.Pointer(p)).FdbMain)
		_rbuDeleteVfs(tls, p)
		Xsqlite3_free(tls, (*Tsqlite3rbu)(unsafe.Pointer(p)).FaBuf)
		Xsqlite3_free(tls, (*Tsqlite3rbu)(unsafe.Pointer(p)).FaFrame)
		_rbuEditErrmsg(tls, p)
		rc = (*Tsqlite3rbu)(unsafe.Pointer(p)).Frc
		if pzErrmsg != 0 {
			**(**uintptr)(__ccgo_up(pzErrmsg)) = (*Tsqlite3rbu)(unsafe.Pointer(p)).FzErrmsg
		} else {
			Xsqlite3_free(tls, (*Tsqlite3rbu)(unsafe.Pointer(p)).FzErrmsg)
		}
		Xsqlite3_free(tls, (*Tsqlite3rbu)(unsafe.Pointer(p)).FzState)
		Xsqlite3_free(tls, p)
	} else {
		rc = int32(SQLITE_NOMEM)
		**(**uintptr)(__ccgo_up(pzErrmsg)) = uintptr(0)
	}
	return rc
}

func Xsqlite3rbu_savestate(tls *libc.TLS, p uintptr) (r int32) {
	var pDb, zBegin, v1 uintptr
	var rc int32
	_, _, _, _ = pDb, rc, zBegin, v1
	rc = (*Tsqlite3rbu)(unsafe.Pointer(p)).Frc
	if rc == int32(SQLITE_DONE) {
		return SQLITE_OK
	}
	if (*Tsqlite3rbu)(unsafe.Pointer(p)).FeStage == int32(RBU_STAGE_OAL) {
		if rc == SQLITE_OK {
			rc = Xsqlite3_exec(tls, (*Tsqlite3rbu)(unsafe.Pointer(p)).FdbMain, __ccgo_ts+16111, uintptr(0), uintptr(0), uintptr(0))
		}
	}
	/* Sync the db file */
	if rc == SQLITE_OK && (*Tsqlite3rbu)(unsafe.Pointer(p)).FeStage == int32(RBU_STAGE_CKPT) {
		pDb = (*Trbu_file)(unsafe.Pointer((*Tsqlite3rbu)(unsafe.Pointer(p)).FpTargetFd)).FpReal
		rc = (*(*func(*libc.TLS, uintptr, int32) int32)(unsafe.Pointer(&struct{ uintptr }{(*Tsqlite3_io_methods)(unsafe.Pointer((*Tsqlite3_file)(unsafe.Pointer(pDb)).FpMethods)).FxSync})))(tls, pDb, int32(SQLITE_SYNC_NORMAL))
	}
	(*Tsqlite3rbu)(unsafe.Pointer(p)).Frc = rc
	_rbuSaveState(tls, p, (*Tsqlite3rbu)(unsafe.Pointer(p)).FeStage)
	rc = (*Tsqlite3rbu)(unsafe.Pointer(p)).Frc
	if (*Tsqlite3rbu)(unsafe.Pointer(p)).FeStage == int32(RBU_STAGE_OAL) {
		if rc == SQLITE_OK {
			rc = Xsqlite3_exec(tls, (*Tsqlite3rbu)(unsafe.Pointer(p)).FdbRbu, __ccgo_ts+16111, uintptr(0), uintptr(0), uintptr(0))
		}
		if rc == SQLITE_OK {
			if (*Tsqlite3rbu)(unsafe.Pointer(p)).FzTarget == uintptr(0) {
				v1 = __ccgo_ts + 16096
			} else {
				v1 = __ccgo_ts + 34625
			}
			zBegin = v1
			rc = Xsqlite3_exec(tls, (*Tsqlite3rbu)(unsafe.Pointer(p)).FdbRbu, zBegin, uintptr(0), uintptr(0), uintptr(0))
		}
		if rc == SQLITE_OK {
			rc = Xsqlite3_exec(tls, (*Tsqlite3rbu)(unsafe.Pointer(p)).FdbMain, __ccgo_ts+34625, uintptr(0), uintptr(0), uintptr(0))
		}
	}
	(*Tsqlite3rbu)(unsafe.Pointer(p)).Frc = rc
	return rc
}

// C documentation
//
//	/*
//	** Step the RBU object.
//	*/
func Xsqlite3rbu_step(tls *libc.TLS, p uintptr) (r int32) {
	bp := tls.Alloc(32)
	defer tls.Free(32)
	var iSector Tu32
	var pDb, pFrame, pIter uintptr
	var rc int32
	var _ /* ptr at bp+0 */ uintptr
	_, _, _, _, _ = iSector, pDb, pFrame, pIter, rc
	if p != 0 {
		switch (*Tsqlite3rbu)(unsafe.Pointer(p)).FeStage {
		case int32(RBU_STAGE_OAL):
			pIter = p + 88
			/* If this is an RBU vacuum operation and the state table was empty
			 ** when this handle was opened, create the target database schema. */
			if (*Tsqlite3rbu)(unsafe.Pointer(p)).FzTarget == uintptr(0) && (*Tsqlite3rbu)(unsafe.Pointer(p)).FnProgress == 0 && (*Tsqlite3rbu)(unsafe.Pointer(p)).Frc == SQLITE_OK {
				_rbuCreateTargetSchema(tls, p)
				_rbuCopyPragma(tls, p, __ccgo_ts+18929)
				_rbuCopyPragma(tls, p, __ccgo_ts+18040)
			}
			for (*Tsqlite3rbu)(unsafe.Pointer(p)).Frc == SQLITE_OK && (*TRbuObjIter)(unsafe.Pointer(pIter)).FzTbl != 0 {
				if (*TRbuObjIter)(unsafe.Pointer(pIter)).FbCleanup != 0 {
					/* Clean up the rbu_tmp_xxx table for the previous table. It
					 ** cannot be dropped as there are currently active SQL statements.
					 ** But the contents can be deleted.  */
					if libc.BoolInt32((*Tsqlite3rbu)(unsafe.Pointer(p)).FzTarget == uintptr(0)) == 0 && (*TRbuObjIter)(unsafe.Pointer(pIter)).FabIndexed != 0 {
						_rbuMPrintfExec(tls, p, (*Tsqlite3rbu)(unsafe.Pointer(p)).FdbRbu, __ccgo_ts+34266, libc.VaList(bp+16, p+48, (*TRbuObjIter)(unsafe.Pointer(pIter)).FzDataTbl))
					}
				} else {
					_rbuObjIterPrepareAll(tls, p, pIter, 0)
					/* Advance to the next row to process. */
					if (*Tsqlite3rbu)(unsafe.Pointer(p)).Frc == SQLITE_OK {
						rc = Xsqlite3_step(tls, (*TRbuObjIter)(unsafe.Pointer(pIter)).FpSelect)
						if rc == int32(SQLITE_ROW) {
							(*Tsqlite3rbu)(unsafe.Pointer(p)).FnProgress = (*Tsqlite3rbu)(unsafe.Pointer(p)).FnProgress + 1
							(*Tsqlite3rbu)(unsafe.Pointer(p)).FnStep = (*Tsqlite3rbu)(unsafe.Pointer(p)).FnStep + 1
							return _rbuStep(tls, p)
						}
						(*Tsqlite3rbu)(unsafe.Pointer(p)).Frc = Xsqlite3_reset(tls, (*TRbuObjIter)(unsafe.Pointer(pIter)).FpSelect)
						(*Tsqlite3rbu)(unsafe.Pointer(p)).FnStep = 0
					}
				}
				_rbuObjIterNext(tls, p, pIter)
			}
			if (*Tsqlite3rbu)(unsafe.Pointer(p)).Frc == SQLITE_OK {
				_rbuSaveState(tls, p, int32(RBU_STAGE_MOVE))
				_rbuIncrSchemaCookie(tls, p)
				if (*Tsqlite3rbu)(unsafe.Pointer(p)).Frc == SQLITE_OK {
					(*Tsqlite3rbu)(unsafe.Pointer(p)).Frc = Xsqlite3_exec(tls, (*Tsqlite3rbu)(unsafe.Pointer(p)).FdbMain, __ccgo_ts+16111, uintptr(0), uintptr(0), p+64)
				}
				if (*Tsqlite3rbu)(unsafe.Pointer(p)).Frc == SQLITE_OK {
					(*Tsqlite3rbu)(unsafe.Pointer(p)).Frc = Xsqlite3_exec(tls, (*Tsqlite3rbu)(unsafe.Pointer(p)).FdbRbu, __ccgo_ts+16111, uintptr(0), uintptr(0), p+64)
				}
				(*Tsqlite3rbu)(unsafe.Pointer(p)).FeStage = int32(RBU_STAGE_MOVE)
			}
		case int32(RBU_STAGE_MOVE):
			if (*Tsqlite3rbu)(unsafe.Pointer(p)).Frc == SQLITE_OK {
				_rbuMoveOalFile(tls, p)
				(*Tsqlite3rbu)(unsafe.Pointer(p)).FnProgress = (*Tsqlite3rbu)(unsafe.Pointer(p)).FnProgress + 1
			}
		case int32(RBU_STAGE_CKPT):
			if (*Tsqlite3rbu)(unsafe.Pointer(p)).Frc == SQLITE_OK {
				if (*Tsqlite3rbu)(unsafe.Pointer(p)).FnStep >= (*Tsqlite3rbu)(unsafe.Pointer(p)).FnFrame {
					pDb = (*Trbu_file)(unsafe.Pointer((*Tsqlite3rbu)(unsafe.Pointer(p)).FpTargetFd)).FpReal
					/* Sync the db file */
					(*Tsqlite3rbu)(unsafe.Pointer(p)).Frc = (*(*func(*libc.TLS, uintptr, int32) int32)(unsafe.Pointer(&struct{ uintptr }{(*Tsqlite3_io_methods)(unsafe.Pointer((*Tsqlite3_file)(unsafe.Pointer(pDb)).FpMethods)).FxSync})))(tls, pDb, int32(SQLITE_SYNC_NORMAL))
					/* Update nBackfill */
					if (*Tsqlite3rbu)(unsafe.Pointer(p)).Frc == SQLITE_OK {
						(*Tsqlite3rbu)(unsafe.Pointer(p)).Frc = (*(*func(*libc.TLS, uintptr, int32, int32, int32, uintptr) int32)(unsafe.Pointer(&struct{ uintptr }{(*Tsqlite3_io_methods)(unsafe.Pointer((*Tsqlite3_file)(unsafe.Pointer(pDb)).FpMethods)).FxShmMap})))(tls, pDb, 0, libc.Int32FromInt32(32)*libc.Int32FromInt32(1024), 0, bp)
						if (*Tsqlite3rbu)(unsafe.Pointer(p)).Frc == SQLITE_OK {
							**(**Tu32)(__ccgo_up(**(**uintptr)(__ccgo_up(bp)) + 24*4)) = (*Tsqlite3rbu)(unsafe.Pointer(p)).FiMaxFrame
						}
					}
					if (*Tsqlite3rbu)(unsafe.Pointer(p)).Frc == SQLITE_OK {
						(*Tsqlite3rbu)(unsafe.Pointer(p)).FeStage = int32(RBU_STAGE_DONE)
						(*Tsqlite3rbu)(unsafe.Pointer(p)).Frc = int32(SQLITE_DONE)
					}
				} else {
					for cond := true; cond; cond = (*Tsqlite3rbu)(unsafe.Pointer(p)).FnStep < (*Tsqlite3rbu)(unsafe.Pointer(p)).FnFrame && iSector == ((**(**TRbuFrame)(__ccgo_up((*Tsqlite3rbu)(unsafe.Pointer(p)).FaFrame + uintptr((*Tsqlite3rbu)(unsafe.Pointer(p)).FnStep)*8))).FiDbPage-uint32(1))/libc.Uint32FromInt32((*Tsqlite3rbu)(unsafe.Pointer(p)).FnPagePerSector) && (*Tsqlite3rbu)(unsafe.Pointer(p)).Frc == SQLITE_OK {
						pFrame = (*Tsqlite3rbu)(unsafe.Pointer(p)).FaFrame + uintptr((*Tsqlite3rbu)(unsafe.Pointer(p)).FnStep)*8
						iSector = ((*TRbuFrame)(unsafe.Pointer(pFrame)).FiDbPage - uint32(1)) / libc.Uint32FromInt32((*Tsqlite3rbu)(unsafe.Pointer(p)).FnPagePerSector)
						_rbuCheckpointFrame(tls, p, pFrame)
						(*Tsqlite3rbu)(unsafe.Pointer(p)).FnStep = (*Tsqlite3rbu)(unsafe.Pointer(p)).FnStep + 1
					}
				}
				(*Tsqlite3rbu)(unsafe.Pointer(p)).FnProgress = (*Tsqlite3rbu)(unsafe.Pointer(p)).FnProgress + 1
			}
		default:
			break
		}
		return (*Tsqlite3rbu)(unsafe.Pointer(p)).Frc
	} else {
		return int32(SQLITE_NOMEM)
	}
	return r
}

// C documentation
//
//	/*
//	** Open a handle to begin or resume an RBU VACUUM operation.
//	*/
func Xsqlite3rbu_vacuum(tls *libc.TLS, zTarget uintptr, zState uintptr) (r uintptr) {
	var n Tsize_t
	_ = n
	if zTarget == uintptr(0) {
		return _rbuMisuseError(tls)
	}
	if zState != 0 {
		n = libc.Xstrlen(tls, zState)
		if n >= uint64(7) && 0 == libc.Xmemcmp(tls, __ccgo_ts+34665, zState+uintptr(n-uint64(7)), uint64(7)) {
			return _rbuMisuseError(tls)
		}
	}
	/* TODO: Check that both arguments are non-NULL */
	return _openRbuHandle(tls, uintptr(0), zTarget, zState)
}

func Xsqlite3session_diff(tls *libc.TLS, pSession uintptr, zFrom uintptr, zTbl uintptr, pzErrMsg uintptr) (r int32) {
	bp := tls.Alloc(80)
	defer tls.Free(80)
	var bHasPk, bMismatch, i, rc int32
	var db, zDb, zDbExists, zExpr, v1 uintptr
	var _ /* abPK at bp+32 */ uintptr
	var _ /* azCol at bp+40 */ uintptr
	var _ /* bRowid at bp+28 */ int32
	var _ /* d at bp+0 */ TSessionDiffCtx
	var _ /* nCol at bp+24 */ int32
	var _ /* pDbExists at bp+48 */ uintptr
	var _ /* pTo at bp+16 */ uintptr
	_, _, _, _, _, _, _, _, _ = bHasPk, bMismatch, db, i, rc, zDb, zDbExists, zExpr, v1
	zDb = (*Tsqlite3_session)(unsafe.Pointer(pSession)).FzDb
	rc = (*Tsqlite3_session)(unsafe.Pointer(pSession)).Frc
	libc.Xmemset(tls, bp, 0, uint64(16))
	_sessionDiffHooks(tls, pSession, bp)
	Xsqlite3_mutex_enter(tls, Xsqlite3_db_mutex(tls, (*Tsqlite3_session)(unsafe.Pointer(pSession)).Fdb))
	if pzErrMsg != 0 {
		**(**uintptr)(__ccgo_up(pzErrMsg)) = uintptr(0)
	}
	if rc == SQLITE_OK {
		zExpr = uintptr(0)
		db = (*Tsqlite3_session)(unsafe.Pointer(pSession)).Fdb /* Table zTbl */
		/* Locate and if necessary initialize the target table object */
		(*Tsqlite3_session)(unsafe.Pointer(pSession)).FbAutoAttach = (*Tsqlite3_session)(unsafe.Pointer(pSession)).FbAutoAttach + 1
		rc = _sessionFindTable(tls, pSession, zTbl, bp+16)
		(*Tsqlite3_session)(unsafe.Pointer(pSession)).FbAutoAttach = (*Tsqlite3_session)(unsafe.Pointer(pSession)).FbAutoAttach - 1
		if **(**uintptr)(__ccgo_up(bp + 16)) == uintptr(0) {
			goto diff_out
		}
		if _sessionInitTable(tls, pSession, **(**uintptr)(__ccgo_up(bp + 16)), (*Tsqlite3_session)(unsafe.Pointer(pSession)).Fdb, (*Tsqlite3_session)(unsafe.Pointer(pSession)).FzDb) != 0 {
			rc = (*Tsqlite3_session)(unsafe.Pointer(pSession)).Frc
			goto diff_out
		}
		/* Check the table schemas match */
		if rc == SQLITE_OK {
			bHasPk = 0
			bMismatch = 0
			**(**int32)(__ccgo_up(bp + 24)) = 0 /* Columns in zFrom.zTbl */
			**(**int32)(__ccgo_up(bp + 28)) = 0
			**(**uintptr)(__ccgo_up(bp + 32)) = uintptr(0)
			**(**uintptr)(__ccgo_up(bp + 40)) = uintptr(0)
			zDbExists = uintptr(0)
			/* Check that database zFrom is attached.  */
			zDbExists = Xsqlite3_mprintf(tls, __ccgo_ts+35596, libc.VaList(bp+64, zFrom))
			if zDbExists == uintptr(0) {
				rc = int32(SQLITE_NOMEM)
			} else {
				**(**uintptr)(__ccgo_up(bp + 48)) = uintptr(0)
				rc = Xsqlite3_prepare_v2(tls, db, zDbExists, -int32(1), bp+48, uintptr(0))
				if rc == int32(SQLITE_ERROR) {
					rc = SQLITE_OK
					**(**int32)(__ccgo_up(bp + 24)) = -int32(1)
				}
				Xsqlite3_finalize(tls, **(**uintptr)(__ccgo_up(bp + 48)))
				Xsqlite3_free(tls, zDbExists)
			}
			if rc == SQLITE_OK && **(**int32)(__ccgo_up(bp + 24)) == 0 {
				if (*Tsqlite3_session)(unsafe.Pointer(pSession)).FbImplicitPK != 0 {
					v1 = bp + 28
				} else {
					v1 = uintptr(0)
				}
				rc = _sessionTableInfo(tls, uintptr(0), db, zFrom, zTbl, bp+24, uintptr(0), uintptr(0), bp+40, uintptr(0), uintptr(0), bp+32, v1)
			}
			if rc == SQLITE_OK {
				if (*TSessionTable)(unsafe.Pointer(**(**uintptr)(__ccgo_up(bp + 16)))).FnCol != **(**int32)(__ccgo_up(bp + 24)) {
					if **(**int32)(__ccgo_up(bp + 24)) <= 0 {
						rc = int32(SQLITE_SCHEMA)
						if pzErrMsg != 0 {
							**(**uintptr)(__ccgo_up(pzErrMsg)) = Xsqlite3_mprintf(tls, __ccgo_ts+35627, libc.VaList(bp+64, zFrom, zTbl))
						}
					} else {
						bMismatch = int32(1)
					}
				} else {
					i = 0
					for {
						if !(i < **(**int32)(__ccgo_up(bp + 24))) {
							break
						}
						if libc.Int32FromUint8(**(**Tu8)(__ccgo_up((*TSessionTable)(unsafe.Pointer(**(**uintptr)(__ccgo_up(bp + 16)))).FabPK + uintptr(i)))) != libc.Int32FromUint8(**(**Tu8)(__ccgo_up(**(**uintptr)(__ccgo_up(bp + 32)) + uintptr(i)))) {
							bMismatch = int32(1)
						}
						if Xsqlite3_stricmp(tls, **(**uintptr)(__ccgo_up(**(**uintptr)(__ccgo_up(bp + 40)) + uintptr(i)*8)), **(**uintptr)(__ccgo_up((*TSessionTable)(unsafe.Pointer(**(**uintptr)(__ccgo_up(bp + 16)))).FazCol + uintptr(i)*8))) != 0 {
							bMismatch = int32(1)
						}
						if **(**Tu8)(__ccgo_up(**(**uintptr)(__ccgo_up(bp + 32)) + uintptr(i))) != 0 {
							bHasPk = int32(1)
						}
						goto _2
					_2:
						;
						i = i + 1
					}
				}
			}
			Xsqlite3_free(tls, **(**uintptr)(__ccgo_up(bp + 40)))
			if bMismatch != 0 {
				if pzErrMsg != 0 {
					**(**uintptr)(__ccgo_up(pzErrMsg)) = Xsqlite3_mprintf(tls, __ccgo_ts+35648, 0)
				}
				rc = int32(SQLITE_SCHEMA)
			}
			if bHasPk == 0 {
				/* Ignore tables with no primary keys */
				goto diff_out
			}
		}
		if rc == SQLITE_OK {
			zExpr = _sessionExprComparePK(tls, (*TSessionTable)(unsafe.Pointer(**(**uintptr)(__ccgo_up(bp + 16)))).FnCol, zDb, zFrom, (*TSessionTable)(unsafe.Pointer(**(**uintptr)(__ccgo_up(bp + 16)))).FzName, (*TSessionTable)(unsafe.Pointer(**(**uintptr)(__ccgo_up(bp + 16)))).FazCol, (*TSessionTable)(unsafe.Pointer(**(**uintptr)(__ccgo_up(bp + 16)))).FabPK)
		}
		/* Find new rows */
		if rc == SQLITE_OK {
			rc = _sessionDiffFindNew(tls, int32(SQLITE_INSERT), pSession, **(**uintptr)(__ccgo_up(bp + 16)), zDb, zFrom, zExpr)
		}
		/* Find old rows */
		if rc == SQLITE_OK {
			rc = _sessionDiffFindNew(tls, int32(SQLITE_DELETE), pSession, **(**uintptr)(__ccgo_up(bp + 16)), zFrom, zDb, zExpr)
		}
		/* Find modified rows */
		if rc == SQLITE_OK {
			rc = _sessionDiffFindModified(tls, pSession, **(**uintptr)(__ccgo_up(bp + 16)), zFrom, zExpr)
		}
		Xsqlite3_free(tls, zExpr)
	}
	goto diff_out
diff_out:
	;
	_sessionPreupdateHooks(tls, pSession)
	Xsqlite3_mutex_leave(tls, Xsqlite3_db_mutex(tls, (*Tsqlite3_session)(unsafe.Pointer(pSession)).Fdb))
	return rc
}

const _ALIGNBYTES = -1

const _CS_POSIX_V7_ILP32_OFF32_CFLAGS = 16

const _CS_POSIX_V7_ILP32_OFF32_LDFLAGS = 17

const _CS_POSIX_V7_ILP32_OFF32_LIBS = 18

const _CS_POSIX_V7_ILP32_OFFBIG_CFLAGS = 19

const _CS_POSIX_V7_ILP32_OFFBIG_LDFLAGS = 20

const _CS_POSIX_V7_ILP32_OFFBIG_LIBS = 21

const _CS_POSIX_V7_LP64_OFF64_CFLAGS = 22

const _CS_POSIX_V7_LP64_OFF64_LDFLAGS = 23

const _CS_POSIX_V7_LP64_OFF64_LIBS = 24

const _CS_POSIX_V7_LPBIG_OFFBIG_CFLAGS = 25

const _CS_POSIX_V7_LPBIG_OFFBIG_LDFLAGS = 26

const _CS_POSIX_V7_LPBIG_OFFBIG_LIBS = 27

const _CS_POSIX_V7_THREADS_CFLAGS = 28

const _CS_POSIX_V7_THREADS_LDFLAGS = 29

const _CS_POSIX_V7_WIDTH_RESTRICTED_ENVS = 30

const _CS_V6_ENV = 15

const _CS_V7_ENV = 31

const _CTYPE_B = 128

const _CTYPE_C = 32

const _CTYPE_L = 2

const _CTYPE_N = 4

const _CTYPE_P = 16

const _CTYPE_S = 8

const _CTYPE_U = 1

const _CTYPE_X = 64

const _MAX_PAGE_SHIFT = 12

const _PC_2_SYMLINKS = 10

const _PC_ALLOC_SIZE_MIN = 11

const _PC_ASYNC_IO = 12

const _PC_PRIO_IO = 14

const _PC_REC_INCR_XFER_SIZE = 15

const _PC_REC_MAX_XFER_SIZE = 16

const _PC_REC_MIN_XFER_SIZE = 17

const _PC_REC_XFER_ALIGN = 18

const _PC_SYNC_IO = 20

const _PC_TIMESTAMP_RESOLUTION = 21

const _POSIX2_FORT_RUN = -1

const _POSIX_ASYNC_IO = -1

const _POSIX_MEMLOCK = 200112

const _POSIX_PRIO_IO = -1

const _POSIX_SYNC_IO = -1

const _POSIX_THREAD_PROCESS_SHARED = -1

const _POSIX_THREAD_ROBUST_PRIO_INHERIT = -1

const _POSIX_THREAD_ROBUST_PRIO_PROTECT = -1

const _POSIX_V6_ILP32_OFFBIG = 0

const _POSIX_V6_LP64_OFF64 = 0

const _POSIX_V6_LPBIG_OFFBIG = 0

const _POSIX_V7_ILP32_OFFBIG = 0

const _POSIX_V7_LP64_OFF64 = 0

const _POSIX_V7_LPBIG_OFFBIG = 0

const _RET_PROTECTOR = 1

const _SC_2_PBS = 35

const _SC_2_PBS_ACCOUNTING = 36

const _SC_2_PBS_CHECKPOINT = 37

const _SC_2_PBS_LOCATE = 38

const _SC_2_PBS_MESSAGE = 39

const _SC_2_PBS_TRACK = 40

const _SC_ADVISORY_INFO = 41

const _SC_ASYNCHRONOUS_IO = 45

const _SC_ATEXIT_MAX = 46

const _SC_AVPHYS_PAGES = 501

const _SC_BARRIERS = 47

const _SC_CLOCK_SELECTION = 48

const _SC_CPUTIME = 49

const _SC_DELAYTIMER_MAX = 50

const _SC_GETGR_R_SIZE_MAX = 100

const _SC_GETPW_R_SIZE_MAX = 101

const _SC_HOST_NAME_MAX = 33

const _SC_IOV_MAX = 51

const _SC_IPV6 = 52

const _SC_LOGIN_NAME_MAX = 102

const _SC_MAPPED_FILES = 53

const _SC_MEMLOCK = 54

const _SC_MEMLOCK_RANGE = 55

const _SC_MEMORY_PROTECTION = 56

const _SC_MESSAGE_PASSING = 57

const _SC_MONOTONIC_CLOCK = 34

const _SC_MQ_OPEN_MAX = 58

const _SC_MQ_PRIO_MAX = 59

const _SC_NPROCESSORS_CONF = 502

const _SC_NPROCESSORS_ONLN = 503

const _SC_PHYS_PAGES = 500

const _SC_PRIORITIZED_IO = 60

const _SC_PRIORITY_SCHEDULING = 61

const _SC_RAW_SOCKETS = 62

const _SC_READER_WRITER_LOCKS = 63

const _SC_REALTIME_SIGNALS = 64

const _SC_REGEXP = 65

const _SC_RTSIG_MAX = 66

const _SC_SEMAPHORES = 67

const _SC_SEM_NSEMS_MAX = 31

const _SC_SEM_VALUE_MAX = 32

const _SC_SHARED_MEMORY_OBJECTS = 68

const _SC_SHELL = 69

const _SC_SIGQUEUE_MAX = 70

const _SC_SPAWN = 71

const _SC_SPIN_LOCKS = 72

const _SC_SPORADIC_SERVER = 73

const _SC_SS_REPL_MAX = 74

const _SC_SYMLOOP_MAX = 76

const _SC_SYNCHRONIZED_IO = 75

const _SC_THREADS = 91

const _SC_THREAD_CPUTIME = 79

const _SC_THREAD_DESTRUCTOR_ITERATIONS = 80

const _SC_THREAD_KEYS_MAX = 81

const _SC_THREAD_PRIORITY_SCHEDULING = 84

const _SC_THREAD_PRIO_INHERIT = 82

const _SC_THREAD_PRIO_PROTECT = 83

const _SC_THREAD_PROCESS_SHARED = 85

const _SC_THREAD_ROBUST_PRIO_INHERIT = 86

const _SC_THREAD_ROBUST_PRIO_PROTECT = 87

const _SC_THREAD_SAFE_FUNCTIONS = 103

const _SC_THREAD_SPORADIC_SERVER = 88

const _SC_THREAD_STACK_MIN = 89

const _SC_THREAD_THREADS_MAX = 90

const _SC_TIMEOUTS = 92

const _SC_TIMERS = 94

const _SC_TIMER_MAX = 93

const _SC_TRACE = 95

const _SC_TRACE_EVENT_FILTER = 96

const _SC_TRACE_EVENT_NAME_MAX = 97

const _SC_TRACE_INHERIT = 98

const _SC_TRACE_LOG = 99

const _SC_TRACE_NAME_MAX = 104

const _SC_TRACE_SYS_MAX = 105

const _SC_TRACE_USER_EVENT_MAX = 106

const _SC_TTY_NAME_MAX = 107

const _SC_TYPED_MEMORY_OBJECTS = 108

const _SC_V6_ILP32_OFF32 = 109

const _SC_V6_ILP32_OFFBIG = 110

const _SC_V6_LP64_OFF64 = 111

const _SC_V6_LPBIG_OFFBIG = 112

const _SC_V7_ILP32_OFF32 = 113

const _SC_V7_ILP32_OFFBIG = 114

const _SC_V7_LP64_OFF64 = 115

const _SC_V7_LPBIG_OFFBIG = 116

const _SC_XOPEN_CRYPT = 117

const _SC_XOPEN_ENH_I18N = 118

const _SC_XOPEN_LEGACY = 119

const _SC_XOPEN_REALTIME = 120

const _SC_XOPEN_REALTIME_THREADS = 121

const _SC_XOPEN_STREAMS = 122

const _SC_XOPEN_UNIX = 123

const _SC_XOPEN_UUCP = 124

const _SC_XOPEN_VERSION = 125

const _STACKALIGNBYTES = 15

const _XOPEN_UUCP = -1

const __INT_FAST16_MAX = 2147483647

const __INT_FAST16_MIN = -2147483648

const __INT_FAST32_MAX = 2147483647

const __INT_FAST32_MIN = -2147483648

const __INT_FAST64_MAX = 9223372036854775807

const __INT_FAST64_MIN = -9223372036854775808

const __INT_FAST8_MAX = 2147483647

const __INT_FAST8_MIN = -2147483648

const __MAP_NOFAULT = 8192

const __MAP_NOREPLACE = 2048

const __NBBY = 8

const __OpenBSD__ = 1

const __PIE__ = 1

const __UINT_FAST16_MAX = 4294967295

const __UINT_FAST32_MAX = 4294967295

const __UINT_FAST64_MAX = 18446744073709551615

const __UINT_FAST8_MAX = 4294967295

const __VERSION__ = "OpenBSD Clang 19.1.7"

const __XPG_VISIBLE = 800

var __ccgo_ts1 = "ATOMIC_INTRINSICS=1\x00COMPILER=clang-19.1.7\x00DEFAULT_AUTOVACUUM\x00DEFAULT_CACHE_SIZE=-2000\x00DEFAULT_FILE_FORMAT=4\x00DEFAULT_JOURNAL_SIZE_LIMIT=-1\x00DEFAULT_MEMSTATUS=0\x00DEFAULT_MMAP_SIZE=0\x00DEFAULT_PAGE_SIZE=4096\x00DEFAULT_PCACHE_INITSZ=20\x00DEFAULT_RECURSIVE_TRIGGERS\x00DEFAULT_SECTOR_SIZE=4096\x00DEFAULT_SYNCHRONOUS=2\x00DEFAULT_WAL_AUTOCHECKPOINT=1000\x00DEFAULT_WAL_SYNCHRONOUS=2\x00DEFAULT_WORKER_THREADS=0\x00DIRECT_OVERFLOW_READ\x00DISABLE_INTRINSIC\x00ENABLE_COLUMN_METADATA\x00ENABLE_DBPAGE_VTAB\x00ENABLE_DBSTAT_VTAB\x00ENABLE_FTS5\x00ENABLE_GEOPOLY\x00ENABLE_MATH_FUNCTIONS\x00ENABLE_MEMORY_MANAGEMENT\x00ENABLE_OFFSET_SQL_FUNC\x00ENABLE_PREUPDATE_HOOK\x00ENABLE_RBU\x00ENABLE_RTREE\x00ENABLE_SESSION\x00ENABLE_SNAPSHOT\x00ENABLE_STAT4\x00ENABLE_UNLOCK_NOTIFY\x00LIKE_DOESNT_MATCH_BLOBS\x00MALLOC_SOFT_LIMIT=1024\x00MAX_ATTACHED=10\x00MAX_COLUMN=2000\x00MAX_COMPOUND_SELECT=500\x00MAX_DEFAULT_PAGE_SIZE=8192\x00MAX_EXPR_DEPTH=1000\x00MAX_FUNCTION_ARG=1000\x00MAX_LENGTH=1000000000\x00MAX_LIKE_PATTERN_LENGTH=50000\x00MAX_MMAP_SIZE=0\x00MAX_PAGE_COUNT=0xfffffffe\x00MAX_PAGE_SIZE=65536\x00MAX_SQL_LENGTH=1000000000\x00MAX_TRIGGER_DEPTH=1000\x00MAX_VARIABLE_NUMBER=32766\x00MAX_VDBE_OP=250000000\x00MAX_WORKER_THREADS=8\x00MUTEX_NOOP\x00SOUNDEX\x00SYSTEM_MALLOC\x00TEMP_STORE=1\x00THREADSAFE=1\x00ANY\x00BLOB\x00INT\x00INTEGER\x00REAL\x00TEXT\x0020b:20e\x0020c:20e\x0020e\x0040f-21a-21d\x00now\x00subsec\x00subsecond\x00local time unavailable\x00auto\x00ceiling\x00floor\x00julianday\x00localtime\x00unixepoch\x00utc\x00weekday \x00start of \x00month\x00year\x00day\x0040f\x0050f\x0040f-20a-20d\x0050f-20a-20d\x00%02d\x00%2d\x00%06.3f\x00%04d-%02d-%02d\x00%04d\x00%03d\x00%.16g\x00PM\x00pm\x00AM\x00am\x00%02d:%02d\x00%.3f\x00%lld\x00%02d:%02d:%02d\x00%c%04d-%02d-%02d %02d:%02d:%06.3f\x00date\x00time\x00datetime\x00strftime\x00timediff\x00current_time\x00current_timestamp\x00current_date\x00failed to allocate %u bytes of memory\x00failed memory resize %u to %u bytes\x00out of memory\x00%\x00null\x00NaN\x00-Inf\x00\x00NULL\x00(NULL)\x00unistr('\x000123456789abcdef\x00.\x00(join-%u)\x00%u-ROW VALUES CLAUSE\x00(subquery-%u)\x00unrecognized token: \"%s\"\x00922337203685477580\x00+- \n\t0123456789\x000\x00API call with %s database connection pointer\x00unopened\x00invalid\x00Savepoint\x00AutoCommit\x00Transaction\x00Checkpoint\x00JournalMode\x00Vacuum\x00VFilter\x00VUpdate\x00Init\x00Goto\x00Gosub\x00InitCoroutine\x00Yield\x00MustBeInt\x00Jump\x00Once\x00If\x00IfNot\x00IsType\x00Not\x00IfNullRow\x00SeekLT\x00SeekLE\x00SeekGE\x00SeekGT\x00IfNotOpen\x00IfNoHope\x00NoConflict\x00NotFound\x00Found\x00SeekRowid\x00NotExists\x00Last\x00IfSizeBetween\x00SorterSort\x00Sort\x00Rewind\x00IfEmpty\x00SorterNext\x00Prev\x00Next\x00IdxLE\x00IdxGT\x00Or\x00And\x00IdxLT\x00IdxGE\x00IFindKey\x00RowSetRead\x00RowSetTest\x00Program\x00IsNull\x00NotNull\x00Ne\x00Eq\x00Gt\x00Le\x00Lt\x00Ge\x00ElseEq\x00FkIfZero\x00IfPos\x00IfNotZero\x00DecrJumpZero\x00IncrVacuum\x00VNext\x00Filter\x00PureFunc\x00Function\x00Return\x00EndCoroutine\x00HaltIfNull\x00Halt\x00Integer\x00Int64\x00String\x00BeginSubrtn\x00Null\x00SoftNull\x00Blob\x00Variable\x00Move\x00Copy\x00SCopy\x00IntCopy\x00FkCheck\x00ResultRow\x00CollSeq\x00AddImm\x00RealAffinity\x00Cast\x00Permutation\x00Compare\x00IsTrue\x00ZeroOrNull\x00Offset\x00Column\x00TypeCheck\x00Affinity\x00MakeRecord\x00Count\x00ReadCookie\x00SetCookie\x00BitAnd\x00BitOr\x00ShiftLeft\x00ShiftRight\x00Add\x00Subtract\x00Multiply\x00Divide\x00Remainder\x00Concat\x00ReopenIdx\x00OpenRead\x00BitNot\x00OpenWrite\x00OpenDup\x00String8\x00OpenAutoindex\x00OpenEphemeral\x00SorterOpen\x00SequenceTest\x00OpenPseudo\x00Close\x00ColumnsUsed\x00SeekScan\x00SeekHit\x00Sequence\x00NewRowid\x00Insert\x00RowCell\x00Delete\x00ResetCount\x00SorterCompare\x00SorterData\x00RowData\x00Rowid\x00NullRow\x00SeekEnd\x00IdxInsert\x00SorterInsert\x00IdxDelete\x00DeferredSeek\x00IdxRowid\x00FinishSeek\x00Destroy\x00Clear\x00ResetSorter\x00CreateBtree\x00SqlExec\x00ParseSchema\x00LoadAnalysis\x00DropTable\x00Real\x00DropIndex\x00DropTrigger\x00IntegrityCk\x00RowSetAdd\x00Param\x00FkCounter\x00MemMax\x00OffsetLimit\x00AggInverse\x00AggStep\x00AggStep1\x00AggValue\x00AggFinal\x00Expire\x00CursorLock\x00CursorUnlock\x00TableLock\x00VBegin\x00VCreate\x00VDestroy\x00VOpen\x00VCheck\x00VInitIn\x00VColumn\x00VRename\x00Pagecount\x00MaxPgcnt\x00ClrSubtype\x00GetSubtype\x00SetSubtype\x00FilterAdd\x00Trace\x00CursorHint\x00ReleaseReg\x00Noop\x00Explain\x00Abortable\x00open\x00close\x00access\x00getcwd\x00stat\x00fstat\x00ftruncate\x00fcntl\x00read\x00pread\x00pread64\x00write\x00pwrite\x00pwrite64\x00fchmod\x00fallocate\x00unlink\x00openDirectory\x00mkdir\x00rmdir\x00fchown\x00geteuid\x00mmap\x00munmap\x00mremap\x00getpagesize\x00readlink\x00lstat\x00ioctl\x00attempt to open \"%s\" as file descriptor %d\x00/dev/null\x00os_unix.c:%d: (%d) %s(%s) - %s\x00cannot fstat db file %s\x00file unlinked while open: %s\x00multiple links to file: %s\x00file renamed while open: %s\x00%s\x00full_fsync\x00%s-shm\x00readonly_shm\x00psow\x00unix-excl\x00%s.lock\x00/var/tmp\x00/usr/tmp\x00/tmp\x00SQLITE_TMPDIR\x00TMPDIR\x00%s/etilqs_%llx%c\x00modeof\x00fsync\x00/dev/urandom\x00unix\x00unix-none\x00unix-dotfile\x00memdb\x00memdb(%p,%lld)\x00PRAGMA \"%w\".page_count\x00BEGIN IMMEDIATE; COMMIT;\x00ATTACH x AS %Q\x00-mj\x00recovered %d pages from %s\x00-journal\x00-wal\x00nolock\x00immutable\x00PRAGMA table_list\x00recovered %d frames from WAL file %s\x00cannot limit WAL size: %s\x00:memory:\x00@  \x00\n\x00invalid page number %u\x002nd reference to page %u\x00Failed to read ptrmap key=%u\x00Bad ptr map entry key=%u expected=(%u,%u) got=(%u,%u)\x00failed to get page %u\x00freelist leaf count too big on page %u\x00size\x00overflow list length\x00%s is %u but should be %u\x00Tree %u page %u: \x00unable to get the page. error code=%d\x00btreeInitPage() returns error code %d\x00free space corruption\x00Tree %u page %u cell %u: \x00Tree %u page %u right child: \x00Offset %u out of range %u..%u\x00Extends off end of page\x00Rowid %lld out of order\x00Child page depth differs\x00Multiple uses for byte %u of page %u\x00Fragmentation of %u bytes reported as %u on page %u\x00Freelist: \x00max rootpage (%u) disagrees with header (%u)\x00incremental_vacuum enabled with a max rootpage of zero\x00Page %u: never used\x00Page %u: pointer map referenced\x00unknown database %s\x00destination database is in use\x00source and destination must be distinct\x00.0\x00%!.*g\x00-\x00%s%s\x00k(%d\x00BINARY\x00B\x00N.\x00,%s%s%s\x00)\x00?\x008\x0016LE\x0016BE\x00%.18s-%s\x00%s(%d)\x00%d\x00(blob)\x00vtab:%p\x00%c%u\x00]\x00program\x00subrtnsig:%d,%s\x00%.4c%s%.16c\x00MJ delete: %s\x00MJ collide: %s\x00-mj%06X9%02X\x00FOREIGN KEY constraint failed\x00a CHECK constraint\x00a generated column\x00an index\x00non-deterministic use of %s() in %s\x00API called with finalized prepared statement\x00API called with NULL prepared statement\x00string or blob too big\x00addr\x00opcode\x00p1\x00p2\x00p3\x00p4\x00p5\x00comment\x00id\x00parent\x00notused\x00detail\x00bind on a busy prepared statement: [%s]\x00-- \x00%!.15g\x00'%.*q'\x00zeroblob(%d)\x00x'\x00%02x\x00'\x00/* %s */ \x00/* unknown trigger */ \x00statement aborts at %d: %s; [%s%s]\x00NOT NULL\x00UNIQUE\x00CHECK\x00FOREIGN KEY\x00%s constraint failed\x00%z: %s\x00cannot store %s value in %s column %s.%s\x00cannot open savepoint - SQL statements in progress\x00no such savepoint: %s\x00cannot release savepoint - SQL statements in progress\x00cannot commit transaction - SQL statements in progress\x00cannot start a transaction within a transaction\x00cannot rollback - no transaction is active\x00cannot commit - no transaction is active\x00database schema has changed\x00index corruption\x00sqlite_master\x00SELECT*FROM\"%w\".%s WHERE %s ORDER BY rowid\x00too many levels of trigger recursion\x00into\x00out of\x00cannot change %s wal mode from within a transaction\x00database table is locked: %s\x00ValueList\x00-- %s\x00real\x00integer\x00cannot open value of type %s\x00no such rowid: %lld\x00cannot open virtual table: %s\x00cannot open table without rowid: %s\x00cannot open table with generated columns: %s\x00cannot open view: %s\x00no such column: \"%s\"\x00foreign key\x00indexed\x00cannot open %s column for writing\x00sqlite_\x00sqlite_temp_master\x00sqlite_temp_schema\x00sqlite_schema\x00main\x00*\x00new\x00old\x00excluded\x00misuse of aliased aggregate %s\x00misuse of aliased window function %s\x00row value misused\x00double-quoted string literal: \"%w\"\x00coalesce\x00no such column\x00ambiguous column name\x00%s: %s.%s.%s\x00%s: %s.%s\x00%s: \"%s\" - should this be a string literal in single-quotes?\x00%s: %s\x00partial index WHERE clauses\x00index expressions\x00CHECK constraints\x00generated columns\x00%s prohibited in %s\x00the \".\" operator\x00second argument to %#T() must be a constant between 0.0 and 1.0\x00not authorized to use function: %#T\x00non-deterministic functions\x00%#T() may not be used as a window function\x00window\x00aggregate\x00misuse of %s function %#T()\x00no such function: %#T\x00wrong number of arguments to function %#T()\x00FILTER may not be used with non-aggregate %#T()\x00subqueries\x00parameters\x00%r %s BY term out of range - should be between 1 and %d\x00too many terms in ORDER BY clause\x00ORDER\x00%r ORDER BY term does not match any column in the result set\x00too many terms in %s BY clause\x00HAVING clause on a non-aggregate query\x00GROUP\x00aggregate functions are not allowed in the GROUP BY clause\x00Expression tree is too large (maximum depth %d)\x00s\x00IN(...) element has %d term%s - expected %d\x00too many arguments on function %T\x00ORDER BY may not be used with non-aggregate %#T()\x00unsafe use of %#T()\x00variable number must be between ?1 and ?%d\x00too many SQL variables\x00%d columns assigned %d values\x00too many columns in %s\x00true\x00false\x00_ROWID_\x00ROWID\x00OID\x00USING ROWID SEARCH ON TABLE %s FOR IN-OPERATOR\x00USING INDEX %s FOR IN-OPERATOR\x00sub-select returns %d columns - expected %d\x00REUSE LIST SUBQUERY %d\x00CORRELATED \x00%sLIST SUBQUERY %d\x00REUSE SUBQUERY %d\x00%sSCALAR SUBQUERY %d\x000x\x00hex literal too big: %s%#T\x00generated column loop on \"%s\"\x00blob\x00text\x00numeric\x00flexnum\x00none\x00misuse of aggregate: %#T()\x00unknown function: %#T()\x00RAISE() may only be used within a trigger-program\x00more than %d aggregate terms\x00table %s may not be altered\x00SELECT 1 FROM \"%w\".sqlite_master WHERE name NOT LIKE 'sqliteX_%%' ESCAPE 'X' AND sql NOT LIKE 'create virtual%%' AND sqlite_rename_test(%Q, sql, type, name, %d, %Q, %d)=NULL \x00SELECT 1 FROM temp.sqlite_master WHERE name NOT LIKE 'sqliteX_%%' ESCAPE 'X' AND sql NOT LIKE 'create virtual%%' AND sqlite_rename_test(%Q, sql, type, name, 1, %Q, %d)=NULL \x00UPDATE \"%w\".sqlite_master SET sql = sqlite_rename_quotefix(%Q, sql)WHERE name NOT LIKE 'sqliteX_%%' ESCAPE 'X' AND sql NOT LIKE 'create virtual%%'\x00UPDATE temp.sqlite_master SET sql = sqlite_rename_quotefix('temp', sql)WHERE name NOT LIKE 'sqliteX_%%' ESCAPE 'X' AND sql NOT LIKE 'create virtual%%'\x00there is already another table or index with this name: %s\x00table\x00view %s may not be altered\x00UPDATE \"%w\".sqlite_master SET sql = sqlite_rename_table(%Q, type, name, sql, %Q, %Q, %d) WHERE (type!='index' OR tbl_name=%Q COLLATE nocase)AND   name NOT LIKE 'sqliteX_%%' ESCAPE 'X'\x00UPDATE %Q.sqlite_master SET tbl_name = %Q, name = CASE WHEN type='table' THEN %Q WHEN name LIKE 'sqliteX_autoindex%%' ESCAPE 'X'      AND type='index' THEN 'sqlite_autoindex_' || %Q || substr(name,%d+18) ELSE name END WHERE tbl_name=%Q COLLATE nocase AND (type='table' OR type='index' OR type='trigger');\x00sqlite_sequence\x00UPDATE \"%w\".sqlite_sequence set name = %Q WHERE name = %Q\x00UPDATE sqlite_temp_schema SET sql = sqlite_rename_table(%Q, type, name, sql, %Q, %Q, 1), tbl_name = CASE WHEN tbl_name=%Q COLLATE nocase AND   sqlite_rename_test(%Q, sql, type, name, 1, 'after rename', 0) THEN %Q ELSE tbl_name END WHERE type IN ('view', 'trigger')\x00after rename\x00SELECT raise(ABORT,%Q) FROM \"%w\".\"%w\"\x00Cannot add a PRIMARY KEY column\x00Cannot add a UNIQUE column\x00Cannot add a REFERENCES column with non-NULL default value\x00Cannot add a NOT NULL column with default value NULL\x00Cannot add a column with non-constant default\x00cannot add a STORED column\x00UPDATE \"%w\".sqlite_master SET sql = printf('%%.%ds, ',sql) || %Q || substr(sql,1+length(printf('%%.%ds',sql))) WHERE type = 'table' AND name = %Q\x00SELECT CASE WHEN quick_check GLOB 'CHECK*' THEN raise(ABORT,'CHECK constraint failed') WHEN quick_check GLOB 'non-* value in*' THEN raise(ABORT,'type mismatch on DEFAULT') ELSE raise(ABORT,'NOT NULL constraint failed') END  FROM pragma_quick_check(%Q,%Q) WHERE quick_check GLOB 'CHECK*' OR quick_check GLOB 'NULL*' OR quick_check GLOB 'non-* value in*'\x00virtual tables may not be altered\x00Cannot add a column to a view\x00sqlite_altertab_%s\x00view\x00virtual table\x00rename columns of\x00drop column from\x00edit constraints of\x00cannot %s %s \"%s\"\x00no such column: \"%T\"\x00UPDATE \"%w\".sqlite_master SET sql = sqlite_rename_column(sql, type, name, %Q, %Q, %d, %Q, %d, %d) WHERE name NOT LIKE 'sqliteX_%%' ESCAPE 'X'  AND (type != 'index' OR tbl_name = %Q)\x00UPDATE temp.sqlite_master SET sql = sqlite_rename_column(sql, type, name, %Q, %Q, %d, %Q, %d, 1) WHERE type IN ('trigger', 'view')\x00 \x00error in %s %s%s%s: %s\x00CREATE \x00\"%w\" \x00%Q%s\x00%.*s%s\x00PRIMARY KEY\x00cannot drop %s column: \"%s\"\x00cannot drop column \"%s\": no other columns exist\x00UPDATE \"%w\".sqlite_master SET sql = sqlite_drop_column(%d, sql, %d) WHERE (type=='table' AND tbl_name=%Q COLLATE nocase)\x00after drop column\x00constraint may not be dropped: %s\x00no such constraint: %s\x00%.*s%s%s\x00%.*s, %s%s\x00%.*s %s%s\x00no such column: %s\x00%Q\x00UPDATE \"%w\".sqlite_master SET sql = sqlite_drop_constraint(sql, %s) WHERE type='table' AND tbl_name=%Q COLLATE nocase\x00%.*s\x00SELECT sqlite_fail('constraint failed', %d) FROM %Q.%Q AS x WHERE x.%.*s IS NULL\x00UPDATE \"%w\".sqlite_master SET sql = sqlite_add_constraint(sqlite_drop_constraint(sql, %d), %.*Q, %d) WHERE type='table' AND tbl_name=%Q COLLATE nocase\x00SELECT sqlite_fail('constraint %q already exists', %d) FROM \"%w\".sqlite_master WHERE type='table' AND tbl_name=%Q COLLATE nocase AND sqlite_find_constraint(sql, %Q)\x00SELECT sqlite_fail('constraint failed', %d) FROM %Q.%Q WHERE (%.*s) IS NOT TRUE\x00UPDATE \"%w\".sqlite_master SET sql = sqlite_add_constraint(sql, %.*Q, -1) WHERE type='table' AND tbl_name=%Q COLLATE nocase\x00sqlite_rename_column\x00sqlite_rename_table\x00sqlite_rename_test\x00sqlite_drop_column\x00sqlite_rename_quotefix\x00sqlite_drop_constraint\x00sqlite_fail\x00sqlite_add_constraint\x00sqlite_find_constraint\x00sqlite_stat1\x00tbl,idx,stat\x00sqlite_stat4\x00tbl,idx,neq,nlt,ndlt,sample\x00sqlite_stat3\x00CREATE TABLE %Q.%s(%s)\x00DELETE FROM %Q.%s WHERE %s=%Q\x00DELETE FROM %Q.%s\x00stat_init\x00stat_push\x00%llu\x00 %llu\x00%llu \x00stat_get\x00sqlite\\_%\x00BBB\x00idx\x00tbl\x00unordered*\x00sz=[0-9]*\x00noskipscan*\x00SELECT idx,count(*) FROM %Q.sqlite_stat4 GROUP BY idx COLLATE nocase\x00SELECT idx,neq,nlt,ndlt,sample FROM %Q.sqlite_stat4\x00SELECT tbl,idx,stat FROM %Q.sqlite_stat1\x00x\x00\x00too many attached databases - max %d\x00database %s is already in use\x00database is already attached\x00attached databases must use the same text encoding as main database\x00unable to open database: %s\x00no such database: %s\x00cannot detach database %s\x00database %s is locked\x00sqlite_detach\x00sqlite_attach\x00%s cannot use variables\x00%s %T cannot reference objects in database %s\x00authorizer malfunction\x00%s.%s\x00%s.%z\x00access to %z is prohibited\x00not authorized\x00pragma_\x00json\x00no such view\x00no such table\x00corrupt database\x00unknown database %T\x00object name reserved for internal use: %s\x00temporary table name must be unqualified\x00%s %T already exists\x00there is already an index named %s\x00cannot use RETURNING in a trigger\x00sqlite_returning_%p\x00too many columns on %s\x00always\x00generated\x00duplicate column name: %s\x00default value of column [%s] is not constant\x00cannot use DEFAULT on a generated column\x00generated columns cannot be part of the PRIMARY KEY\x00table \"%s\" has more than one primary key\x00AUTOINCREMENT is only allowed on an INTEGER PRIMARY KEY\x00virtual tables cannot use computed columns\x00virtual\x00stored\x00error in generated column \"%s\"\x00,\x00\n  \x00,\n  \x00\n)\x00CREATE TABLE \x00 TEXT\x00 NUM\x00 INT\x00 REAL\x00unknown datatype for %s.%s: \"%s\"\x00missing datatype for %s.%s\x00AUTOINCREMENT not allowed on WITHOUT ROWID tables\x00PRIMARY KEY missing on table %s\x00must have at least one non-generated column\x00TABLE\x00VIEW\x00CREATE %s %.*s\x00UPDATE %Q.sqlite_master SET type='%s', name=%Q, tbl_name=%Q, rootpage=#%d, sql=%Q WHERE rowid=#%d\x00CREATE TABLE %Q.sqlite_sequence(name,seq)\x00tbl_name='%q' AND type!='trigger'\x00SELECT*FROM\"%w\".\"%w\"\x00parameters are not allowed in views\x00view %s is circularly defined\x00corrupt schema\x00UPDATE %Q.sqlite_master SET rootpage=%d WHERE #%d AND rootpage=#%d\x00sqlite_stat%d\x00DELETE FROM %Q.sqlite_sequence WHERE name=%Q\x00DELETE FROM %Q.sqlite_master WHERE tbl_name=%Q and type!='trigger'\x00table %s may not be dropped\x00use DROP TABLE to delete table %s\x00use DROP VIEW to delete view %s\x00foreign key on %s should reference only one column of table %T\x00number of columns in foreign key does not match the number of columns in the referenced table\x00unknown column \"%s\" in foreign key definition\x00FIRST\x00LAST\x00unsupported use of NULLS %s\x00index\x00cannot create a TEMP index on non-TEMP table \"%s\"\x00table %s may not be indexed\x00views may not be indexed\x00virtual tables may not be indexed\x00there is already a table named %s\x00index %s already exists\x00sqlite_autoindex_%s_%d\x00expressions prohibited in PRIMARY KEY and UNIQUE constraints\x00conflicting ON CONFLICT clauses specified\x00invalid rootpage\x00 UNIQUE\x00CREATE%s INDEX %.*s\x00INSERT INTO %Q.sqlite_master VALUES('index',%Q,%Q,#%d,%Q);\x00name='%q' AND type='index'\x00no such index: %S\x00index associated with UNIQUE or PRIMARY KEY constraint cannot be dropped\x00DELETE FROM %Q.sqlite_master WHERE name=%Q AND type='index'\x00too many FROM clause terms, max: %d\x00ON\x00USING\x00a JOIN clause is required before %s\x00BEGIN\x00ROLLBACK\x00COMMIT\x00RELEASE\x00unable to open a temporary database file for storing temporary tables\x00index '%q'\x00, \x00%s.rowid\x00expressions\x00unable to identify the object to be reindexed\x00duplicate WITH table name: %s\x00no such collation sequence: %s\x00unsafe use of virtual table \"%s\"\x00table %s may not be modified\x00cannot modify %s because it is a view\x00rows deleted\x00integer overflow\x00%!.*f\x00LIKE or GLOB pattern too complex\x00ESCAPE expression must be a single character\x00%!0.17g\x00%#Q\x00invalid Unicode escape\x00?000\x00MATCH\x00like\x00implies_nonnull_row\x00expr_compare\x00expr_implies_expr\x00affinity\x00soundex\x00load_extension\x00sqlite_compileoption_used\x00sqlite_compileoption_get\x00unlikely\x00likelihood\x00likely\x00sqlite_offset\x00ltrim\x00rtrim\x00trim\x00min\x00max\x00typeof\x00subtype\x00length\x00octet_length\x00instr\x00printf\x00format\x00unicode\x00char\x00abs\x00round\x00upper\x00lower\x00hex\x00unhex\x00concat\x00concat_ws\x00ifnull\x00random\x00randomblob\x00nullif\x00sqlite_version\x00sqlite_source_id\x00sqlite_log\x00unistr\x00quote\x00unistr_quote\x00last_insert_rowid\x00changes\x00total_changes\x00replace\x00zeroblob\x00substr\x00substring\x00sum\x00total\x00avg\x00count\x00group_concat\x00string_agg\x00glob\x00ceil\x00trunc\x00ln\x00log\x00log10\x00log2\x00exp\x00pow\x00power\x00mod\x00acos\x00asin\x00atan\x00atan2\x00cos\x00sin\x00tan\x00cosh\x00sinh\x00tanh\x00acosh\x00asinh\x00atanh\x00sqrt\x00radians\x00degrees\x00pi\x00sign\x00iif\x00if\x00foreign key mismatch - \"%w\" referencing \"%w\"\x00cannot INSERT into generated column \"%s\"\x00table %S has no column named %s\x00SCAN %S\x00table %S has %d columns but %d values were supplied\x00%d values for %d columns\x00UPSERT not implemented for virtual table \"%s\"\x00cannot UPSERT a view\x00rows inserted\x00so\x00sqlite3_extension_init\x00sqlite3_\x00lib\x00_init\x00no entry point [%s] in shared library [%s]\x00error during initialization: %s\x00unable to open shared library [%.*s]\x00automatic extension loading failed: %s\x00seq\x00from\x00to\x00on_update\x00on_delete\x00match\x00cid\x00name\x00type\x00notnull\x00dflt_value\x00pk\x00hidden\x00builtin\x00enc\x00narg\x00flags\x00schema\x00ncol\x00wr\x00strict\x00seqno\x00desc\x00coll\x00key\x00unique\x00origin\x00partial\x00wdth\x00hght\x00flgs\x00rowid\x00fkid\x00busy\x00checkpointed\x00file\x00database\x00status\x00cache_size\x00timeout\x00analysis_limit\x00application_id\x00auto_vacuum\x00automatic_index\x00busy_timeout\x00cache_spill\x00case_sensitive_like\x00cell_size_check\x00checkpoint_fullfsync\x00collation_list\x00compile_options\x00count_changes\x00data_version\x00database_list\x00default_cache_size\x00defer_foreign_keys\x00empty_result_callbacks\x00encoding\x00foreign_key_check\x00foreign_key_list\x00foreign_keys\x00freelist_count\x00full_column_names\x00fullfsync\x00function_list\x00hard_heap_limit\x00ignore_check_constraints\x00incremental_vacuum\x00index_info\x00index_list\x00index_xinfo\x00integrity_check\x00journal_mode\x00journal_size_limit\x00legacy_alter_table\x00locking_mode\x00max_page_count\x00mmap_size\x00module_list\x00optimize\x00page_count\x00page_size\x00pragma_list\x00query_only\x00quick_check\x00read_uncommitted\x00recursive_triggers\x00reverse_unordered_selects\x00schema_version\x00secure_delete\x00short_column_names\x00shrink_memory\x00soft_heap_limit\x00synchronous\x00table_info\x00table_list\x00table_xinfo\x00temp_store\x00temp_store_directory\x00threads\x00trusted_schema\x00user_version\x00wal_autocheckpoint\x00wal_checkpoint\x00writable_schema\x00exclusive\x00normal\x00full\x00incremental\x00memory\x00temporary storage cannot be changed from within a transaction\x00SET NULL\x00SET DEFAULT\x00CASCADE\x00RESTRICT\x00NO ACTION\x00delete\x00persist\x00off\x00truncate\x00wal\x00utf8\x00utf16le\x00utf16be\x00w\x00a\x00sissii\x00-%T\x00fast\x00not a writable directory\x00Safety level may not be changed inside a transaction\x00reset\x00issisii\x00issisi\x00SELECT*FROM\"%w\"\x00shadow\x00sssiii\x00iisX\x00isiX\x00c\x00u\x00isisi\x00iss\x00is\x00iissssss\x00NONE\x00siX\x00*** in database %s ***\n\x00wrong # of entries in index \x00row not in PRIMARY KEY order for %s\x00NULL value in %s.%s\x00non-%s value in %s.%s\x00NUMERIC value in %s.%s\x00C\x00TEXT value in %s.%s\x00CHECK constraint failed in %s\x00index %s stores an imprecise floating-point value for row \x00row \x00 missing from index \x00rowid not at end-of-record for row \x00 of index \x00 values differ from index \x00non-unique entry in index \x00ok\x00UTF8\x00UTF-8\x00UTF-16le\x00UTF-16be\x00UTF16le\x00UTF16be\x00UTF-16\x00UTF16\x00unsupported encoding: %s\x00restart\x00noop\x00ANALYZE \"%w\".\"%w\"\x00CREATE TABLE x\x00%c\"%s\"\x00(\"%s\"\x00,arg HIDDEN\x00,schema HIDDEN\x00PRAGMA \x00%Q.\x00=%Q\x00rename\x00drop column\x00add column\x00drop constraint\x00error in %s %s after %s: %s\x00malformed database schema (%s)\x00%z - %s\x00orphan index\x001\x00CREATE TABLE x(type text,name text,tbl_name text,rootpage int,sql text)\x00unsupported file format\x00SELECT*FROM\"%w\".%s ORDER BY rowid\x00database schema is locked: %s\x00statement too long\x00unknown join type: %T%s%T%s%T\x00a NATURAL join may not have an ON or USING clause\x00cannot join using column %s - column not present in both tables\x00ambiguous reference to %s in USING()\x00CREATE BLOOM FILTER\x00UNION ALL\x00INTERSECT\x00EXCEPT\x00UNION\x00USE TEMP B-TREE FOR %s\x00LAST TERM OF \x00USE TEMP B-TREE FOR %sORDER BY\x00USE TEMP B-TREE FOR LAST %d TERMS OF ORDER BY\x00column%d\x00%.*z:%u\x00NUM\x00VIEWs and/or subqueries nested too deep\x00cannot use window functions in recursive queries\x00recursive aggregate queries not supported\x00SETUP\x00RECURSIVE STEP\x00S\x00SCAN %d CONSTANT ROW%s\x00COMPOUND QUERY\x00LEFT-MOST SUBQUERY\x00all VALUES must have the same number of terms\x00SELECTs to the left and right of %s do not have the same number of result columns\x00MERGE (%s)\x00LEFT\x00RIGHT\x00no such index: %s\x00'%s' is not a function\x00no such index: \"%s\"\x00multiple references to recursive table: %s\x00circular reference: %s\x00table %s has %d values for %d columns\x00multiple recursive references: %s\x00recursive reference in a subquery: %s\x00%!S\x00too many references to \"%s\": max 65535\x00access to view \"%s\" prohibited\x00..%s\x00%s.%s.%s\x00no such table: %s\x00no tables specified\x00too many columns in result set\x00DISTINCT aggregates must have exactly one argument\x00USE TEMP B-TREE FOR %s(DISTINCT)\x00USE TEMP B-TREE FOR %s(ORDER BY)\x00 USING COVERING INDEX \x00SCAN %s%s%s\x00table-function argument\x00ON clause\x00%s references tables to its right\x00target object/alias may not appear in FROM clause: %s\x00expected %d columns for '%s' but got %d\x00CO-ROUTINE %!S\x00MATERIALIZE %!S\x00DISTINCT\x00GROUP BY\x00sqlite3_get_table() called with two or more incompatible queries\x00temporary trigger may not have qualified name\x00trigger\x00cannot create triggers on virtual tables\x00cannot create triggers on shadow tables\x00trigger %T already exists\x00cannot create trigger on system table\x00BEFORE\x00AFTER\x00cannot create %s trigger on view: %S\x00cannot create INSTEAD OF trigger on table: %S\x00trigger \"%s\" may not write to shadow table \"%s\"\x00INSERT INTO %Q.sqlite_master VALUES('trigger',%Q,%Q,0,'CREATE TRIGGER %q')\x00type='trigger' AND name='%q'\x00qualified table names are not allowed on INSERT, UPDATE, and DELETE statements within triggers\x00no such trigger: %S\x00DELETE FROM %Q.sqlite_master WHERE name=%Q AND type='trigger'\x00DELETE\x00UPDATE\x00%s RETURNING is not available on virtual tables\x00RETURNING may not use \"TABLE.*\" wildcards\x00triggers nested too deep\x00-- TRIGGER %s\x00cannot UPDATE generated column \"%s\"\x00rows updated\x00%r \x00%sON CONFLICT clause does not match any PRIMARY KEY or UNIQUE constraint\x00CRE\x00INS\x00cannot VACUUM from within a transaction\x00cannot VACUUM - SQL statements in progress\x00non-text filename\x00vacuum_%016llx\x00ATTACH %Q AS %s\x00output file already exists\x00reserve\x00SELECT sql FROM \"%w\".sqlite_schema WHERE type='table'AND name<>'sqlite_sequence' AND coalesce(rootpage,1)>0\x00SELECT sql FROM \"%w\".sqlite_schema WHERE type='index'\x00SELECT'INSERT INTO %s.'||quote(name)||' SELECT*FROM\"%w\".'||quote(name)FROM %s.sqlite_schema WHERE type='table'AND coalesce(rootpage,1)>0\x00INSERT INTO %s.sqlite_schema SELECT*FROM \"%w\".sqlite_schema WHERE type IN('view','trigger') OR(type='table'AND rootpage=0)\x00CREATE VIRTUAL TABLE %T\x00UPDATE %Q.sqlite_master SET type='table', name=%Q, tbl_name=%Q, rootpage=0, sql=%Q WHERE rowid=#%d\x00name=%Q AND sql=%Q\x00vtable constructor called recursively: %s\x00vtable constructor failed: %s\x00vtable constructor did not declare schema: %s\x00no such module: %s\x00syntax error\x00<expr>\x00 AND \x00(\x00 (\x00%s=?\x00ANY(%s)\x00>\x00<\x00SEARCH\x00SCAN\x00 EXISTS\x00%s %S%s\x00AUTOMATIC PARTIAL COVERING INDEX\x00AUTOMATIC COVERING INDEX\x00COVERING INDEX %s\x00INDEX %s\x00 USING \x00 USING INTEGER PRIMARY KEY (%s\x00>? AND %s\x00%c?)\x00 VIRTUAL TABLE INDEX \x000x%x:%s\x00%d:%s\x00 LEFT-JOIN\x00BLOOM FILTER ON %S (\x00rowid=?\x00MULTI-INDEX OR\x00INDEX %d\x00RIGHT-JOIN %s\x00regexp\x00NOCASE\x00too many arguments on %s() - max %d\x00automatic index on %s(%s)\x00auto-index\x00%s.xBestIndex malfunction\x00abbreviated query algorithm search\x00no query solution\x00at most %d tables in a join\x00SCAN CONSTANT ROW\x00internal query planner error\x00second argument to nth_value must be a positive integer\x00argument of ntile must be a positive integer\x00no such window: %s\x00RANGE with offset PRECEDING/FOLLOWING requires one ORDER BY expression\x00FILTER clause may only be used with aggregate window functions\x00misuse of aggregate: %s()\x00unsupported frame specification\x00PARTITION clause\x00ORDER BY clause\x00frame specification\x00cannot override %s of window: %s\x00DISTINCT is not supported for window functions\x00frame starting offset must be a non-negative integer\x00frame ending offset must be a non-negative integer\x00frame starting offset must be a non-negative number\x00frame ending offset must be a non-negative number\x00near \"%T\": syntax error\x00ORDER BY\x00LIMIT\x00%s clause should come after %s not before\x00too many terms in compound SELECT\x00syntax error after column name \"%.*s\"\x00Recursion limit\x00unknown table option: %.*s\x00set list\x00the INDEXED BY clause is not allowed on UPDATE or DELETE statements within triggers\x00the NOT INDEXED clause is not allowed on UPDATE or DELETE statements within triggers\x00incomplete input\x00unrecognized token: \"%T\"\x00%s in \"%s\"\x00create\x00temp\x00temporary\x00end\x00explain\x00unable to close due to unfinalized statements or unfinished backups\x00not an error\x00SQL logic error\x00access permission denied\x00query aborted\x00database is locked\x00database table is locked\x00attempt to write a readonly database\x00interrupted\x00disk I/O error\x00database disk image is malformed\x00unknown operation\x00database or disk is full\x00unable to open database file\x00locking protocol\x00constraint failed\x00datatype mismatch\x00bad parameter or other API misuse\x00authorization denied\x00column index out of range\x00file is not a database\x00notification message\x00warning message\x00unknown error\x00abort due to ROLLBACK\x00another row available\x00no more rows available\x00unable to delete/modify user-function due to active statements\x00unable to use function %s in the requested context\x00unknown database: %s\x00unable to delete/modify collation sequence due to active statements\x00file:\x00localhost\x00invalid uri authority: %.*s\x00vfs\x00cache\x00shared\x00private\x00mode\x00ro\x00rw\x00rwc\x00no such %s mode: %s\x00%s mode not allowed: %s\x00no such vfs: %s\x00RTRIM\x00\x00\x00\x00%s at line %d of [%.10s]\x00database corruption\x00misuse\x00cannot open file\x00no such table column: %s.%s\x00SQLITE_\x00database is deadlocked\x00array\x00object\x00JSON nested too deep\x00JSON cannot hold BLOB values\x00malformed JSON\x00inf\x009.0e999\x00infinity\x00QNaN\x00SNaN\x00json_%s() needs an odd number of arguments\x00\"\\/bfnrt\x00-9e999\x009e999\x00inity\x00\\\"\x00\\u000b\x00\\u00\x00\\u0000\x00,\n\x00: \x00*]\x00not an array element: %Q\x00JSON path too deep\x00bad JSON path: %Q\x00@\x00[\x00#\x00.\"\x00\"\x00json_object() requires an even number of arguments\x00json_object() labels must be TEXT\x00insert\x00set\x00array_insert\x00    \x00FLAGS parameter to json_valid() must be between 1 and 15\x00[]\x00}\x00{}\x00CREATE TABLE x(key,value,type,atom,id,parent,fullkey,path,json HIDDEN,root HIDDEN)\x00[%lld]\x00.\"%.*s\"\x00.%.*s\x00$\x00jsonb\x00json_array\x00jsonb_array\x00json_array_insert\x00jsonb_array_insert\x00json_array_length\x00json_error_position\x00json_extract\x00jsonb_extract\x00->\x00->>\x00json_insert\x00jsonb_insert\x00json_object\x00jsonb_object\x00json_patch\x00jsonb_patch\x00json_pretty\x00json_quote\x00json_remove\x00jsonb_remove\x00json_replace\x00jsonb_replace\x00json_set\x00jsonb_set\x00json_type\x00json_valid\x00json_group_array\x00jsonb_group_array\x00json_group_object\x00jsonb_group_object\x00json_each\x00json_tree\x00jsonb_each\x00jsonb_tree\x00data\x00DROP TABLE '%q'.'%q_node';DROP TABLE '%q'.'%q_rowid';DROP TABLE '%q'.'%q_parent';\x00RtreeMatchArg\x00SELECT * FROM %Q.%Q\x00UNIQUE constraint failed: %s.%s\x00rtree constraint failed: %s.(%s<=%s)\x00ALTER TABLE %Q.'%q_node'   RENAME TO \"%w_node\";ALTER TABLE %Q.'%q_parent' RENAME TO \"%w_parent\";ALTER TABLE %Q.'%q_rowid'  RENAME TO \"%w_rowid\";\x00SELECT stat FROM %Q.sqlite_stat1 WHERE tbl = '%q_rowid'\x00node\x00INSERT OR REPLACE INTO '%q'.'%q_node' VALUES(?1, ?2)\x00DELETE FROM '%q'.'%q_node' WHERE nodeno = ?1\x00SELECT nodeno FROM '%q'.'%q_rowid' WHERE rowid = ?1\x00INSERT OR REPLACE INTO '%q'.'%q_rowid' VALUES(?1, ?2)\x00DELETE FROM '%q'.'%q_rowid' WHERE rowid = ?1\x00SELECT parentnode FROM '%q'.'%q_parent' WHERE nodeno = ?1\x00INSERT OR REPLACE INTO '%q'.'%q_parent' VALUES(?1, ?2)\x00DELETE FROM '%q'.'%q_parent' WHERE nodeno = ?1\x00CREATE TABLE \"%w\".\"%w_rowid\"(rowid INTEGER PRIMARY KEY,nodeno\x00,a%d\x00);CREATE TABLE \"%w\".\"%w_node\"(nodeno INTEGER PRIMARY KEY,data);\x00CREATE TABLE \"%w\".\"%w_parent\"(nodeno INTEGER PRIMARY KEY,parentnode);\x00INSERT INTO \"%w\".\"%w_node\"VALUES(1,zeroblob(%d))\x00INSERT INTO\"%w\".\"%w_rowid\"(rowid,nodeno)VALUES(?1,?2)ON CONFLICT(rowid)DO UPDATE SET nodeno=excluded.nodeno\x00SELECT * FROM \"%w\".\"%w_rowid\" WHERE rowid=?1\x00UPDATE \"%w\".\"%w_rowid\"SET \x00a%d=coalesce(?%d,a%d)\x00a%d=?%d\x00 WHERE rowid=?1\x00PRAGMA %Q.page_size\x00SELECT length(data) FROM '%q'.'%q_node' WHERE nodeno = 1\x00undersize RTree blobs in \"%q_node\"\x00Wrong number of columns for an rtree table\x00Too few columns for an rtree table\x00Too many columns for an rtree table\x00Auxiliary rtree columns must be last\x00_node\x00CREATE TABLE x(%.*s INT\x00,%.*s\x00,%.*s REAL\x00,%.*s INT\x00);\x00{%lld\x00 %g\x00Invalid argument to rtreedepth()\x00%z%s%z\x00SELECT data FROM %Q.'%q_node' WHERE nodeno=?\x00Node %lld missing from database\x00SELECT parentnode FROM %Q.'%q_parent' WHERE nodeno=?1\x00SELECT nodeno FROM %Q.'%q_rowid' WHERE rowid=?1\x00%_rowid\x00%_parent\x00Mapping (%lld -> %lld) missing from %s table\x00Found (%lld -> %lld) in %s table, expected (%lld -> %lld)\x00Dimension %d of cell %d on node %lld is corrupt\x00Dimension %d of cell %d on node %lld is corrupt relative to parent\x00Node %lld is too small (%d bytes)\x00Rtree depth out of range (%d)\x00Node %lld is too small for cell count of %d (%d bytes)\x00SELECT count(*) FROM %Q.'%q%s'\x00Wrong number of entries in %%%s table - expected %lld, actual %lld\x00SELECT * FROM %Q.'%q_rowid'\x00Schema corrupt or not an rtree\x00_rowid\x00_parent\x00In RTree %s.%s:\n%z\x00wrong number of arguments to function rtreecheck()\x00[%!g,%!g],\x00[%!g,%!g]]\x00<polyline points=\x00%c%g,%g\x00 %g,%g'\x00 %s\x00></polyline>\x00Too many columns for a geopoly table\x00CREATE TABLE x(_shape\x00,%s\x00rtree\x00fullscan\x00_shape does not contain a valid polygon\x00geopoly_overlap\x00geopoly_within\x00geopoly_area\x00geopoly_blob\x00geopoly_json\x00geopoly_svg\x00geopoly_contains_point\x00geopoly_debug\x00geopoly_bbox\x00geopoly_xform\x00geopoly_regular\x00geopoly_ccw\x00geopoly_group_bbox\x00geopoly\x00rtreenode\x00rtreedepth\x00rtreecheck\x00rtree_i32\x00corrupt fossil delta\x00DROP TRIGGER IF EXISTS temp.rbu_insert_tr;DROP TRIGGER IF EXISTS temp.rbu_update1_tr;DROP TRIGGER IF EXISTS temp.rbu_update2_tr;DROP TRIGGER IF EXISTS temp.rbu_delete_tr;\x00AND rootpage!=0 AND rootpage IS NOT NULL\x00SELECT rbu_target_name(name, type='view') AS target, name FROM sqlite_schema WHERE type IN ('table', 'view') AND target IS NOT NULL  %s ORDER BY name\x00SELECT name, rootpage, sql IS NULL OR substr(8, 6)=='UNIQUE'   FROM main.sqlite_schema   WHERE type='index' AND tbl_name = ?\x00SELECT  (sql COLLATE nocase BETWEEN 'CREATE VIRTUAL' AND 'CREATE VIRTUAM'), rootpage  FROM sqlite_schema WHERE name=%Q\x00PRAGMA index_list=%Q\x00SELECT rootpage FROM sqlite_schema WHERE name = %Q\x00PRAGMA table_info=%Q\x00PRAGMA main.index_list = %Q\x00PRAGMA main.index_xinfo = %Q\x00SELECT * FROM '%q'\x00rbu_\x00rbu_rowid\x00may not have\x00requires\x00table %q %s rbu_rowid column\x00PRAGMA table_info(%Q)\x00column missing from %q: %s\x00%z%s\"%w\"\x00%z%s%s\"%w\"%s\x00SELECT max(_rowid_) FROM \"%s%w\"\x00 WHERE _rowid_ > %lld \x00 DESC\x00quote(\x00||','||\x00SELECT %s FROM \"%s%w\" ORDER BY %s LIMIT 1\x00 WHERE (%s) > (%s) \x00_rowid_\x00%z%s \"%w\" COLLATE %Q\x00%z%s \"rbu_imp_%d%w\" COLLATE %Q DESC\x00%z%s quote(\"rbu_imp_%d%w\")\x00SELECT %s FROM \"rbu_imp_%w\" ORDER BY %s LIMIT 1\x00%z%s%s\x00(%s) > (%s)\x00%z%s(%.*s) COLLATE %Q\x00%z%s\"%w\" COLLATE %Q\x00%z%s\"rbu_imp_%d%w\"%s\x00%z%s\"rbu_imp_%d%w\" %s COLLATE %Q\x00%z%s\"rbu_imp_%d%w\" IS ?\x00%z%s%s.\"%w\"\x00%z%sNULL\x00%z, %s._rowid_\x00_rowid_ = ?%d\x00%z%sc%d=?%d\x00_rowid_ = (SELECT id FROM rbu_imposter2 WHERE %z)\x00%z%s\"%w\"=?%d\x00invalid rbu_control value\x00%z%s\"%w\"=rbu_delta(\"%w\", ?%d)\x00%z%s\"%w\"=rbu_fossil_delta(\"%w\", ?%d)\x00PRIMARY KEY(\x00%z%s\"%w\"%s\x00%z)\x00SELECT name FROM sqlite_schema WHERE rootpage = ?\x00%z%sc%d %s COLLATE %Q\x00%z%sc%d%s\x00%z, id INTEGER\x00CREATE TABLE rbu_imposter2(%z, PRIMARY KEY(%z)) WITHOUT ROWID\x00PRIMARY KEY \x00 NOT NULL\x00%z%s\"%w\" %s %sCOLLATE %Q%s\x00%z, %z\x00 WITHOUT ROWID\x00CREATE TABLE \"rbu_imp_%w\"(%z)%s\x00INSERT INTO %s.'rbu_tmp_%q'(rbu_control,%s%s) VALUES(%z)\x00SELECT trim(sql) FROM sqlite_schema WHERE type='index' AND name=?\x00 LIMIT -1 OFFSET %d\x00CREATE TABLE \"rbu_imp_%w\"( %s, PRIMARY KEY( %s ) ) WITHOUT ROWID\x00INSERT INTO \"rbu_imp_%w\" VALUES(%s)\x00DELETE FROM \"rbu_imp_%w\" WHERE %s\x00AND\x00WHERE\x00SELECT %s, 0 AS rbu_control FROM '%q' %s %s %s ORDER BY %s%s\x00SELECT %s, rbu_control FROM %s.'rbu_tmp_%q' %s ORDER BY %s%s\x00SELECT %s, rbu_control FROM %s.'rbu_tmp_%q' %s UNION ALL SELECT %s, rbu_control FROM '%q' %s %s typeof(rbu_control)='integer' AND rbu_control!=1 ORDER BY %s%s\x00rbu_imp_\x00, _rowid_\x00INSERT INTO \"%s%w\"(%s%s) VALUES(%s)\x00DELETE FROM \"%s%w\" WHERE %s\x00, rbu_rowid\x00, 0 AS rbu_rowid\x00CREATE TABLE IF NOT EXISTS %s.'rbu_tmp_%q' AS SELECT *%s FROM '%q' WHERE 0;\x00CREATE TEMP TRIGGER rbu_delete_tr BEFORE DELETE ON \"%s%w\" BEGIN   SELECT rbu_tmp_insert(3, %s);END;CREATE TEMP TRIGGER rbu_update1_tr BEFORE UPDATE ON \"%s%w\" BEGIN   SELECT rbu_tmp_insert(3, %s);END;CREATE TEMP TRIGGER rbu_update2_tr AFTER UPDATE ON \"%s%w\" BEGIN   SELECT rbu_tmp_insert(4, %s);END;\x00CREATE TEMP TRIGGER rbu_insert_tr AFTER INSERT ON \"%s%w\" BEGIN   SELECT rbu_tmp_insert(0, %s);END;\x00,_rowid_ \x00,rbu_rowid\x000 AS \x00SELECT %s,%s rbu_control%s FROM '%q'%s %s %s %s\x00UPDATE \"%s%w\" SET %s WHERE %s\x00SELECT k, v FROM %s.rbu_state\x00file:///%s-vacuum?modeof=%s\x00ATTACH %Q AS stat\x00CREATE TABLE IF NOT EXISTS %s.rbu_state(k INTEGER PRIMARY KEY, v)\x00cannot vacuum wal mode database\x00&\x00file:%s-vactmp?rbu_memory=1%s%s\x00rbu_tmp_insert\x00rbu_fossil_delta\x00rbu_target_name\x00SELECT * FROM sqlite_schema\x00rbu vfs not found\x00PRAGMA main.wal_checkpoint=restart\x00rbu_exclusive_checkpoint\x00%s-oal\x00%s-wal\x00PRAGMA schema_version\x00PRAGMA schema_version = %d\x00INSERT OR REPLACE INTO %s.rbu_state(k, v) VALUES (%d, %d), (%d, %Q), (%d, %Q), (%d, %d), (%d, %lld), (%d, %lld), (%d, %lld), (%d, %lld), (%d, %lld), (%d, %Q)  \x00PRAGMA main.%s\x00PRAGMA main.%s = %d\x00PRAGMA writable_schema=1\x00SELECT sql FROM sqlite_schema WHERE sql!='' AND rootpage!=0 AND name!='sqlite_sequence'  ORDER BY type DESC\x00SELECT * FROM sqlite_schema WHERE rootpage=0 OR rootpage IS NULL\x00INSERT INTO sqlite_schema VALUES(?,?,?,?,?)\x00PRAGMA writable_schema=0\x00DELETE FROM %s.'rbu_tmp_%q'\x00rbu_state mismatch error\x00rbu_vfs_%d\x00SELECT count(*) FROM sqlite_schema WHERE type='index' AND tbl_name = %Q\x00rbu_index_cnt\x00SELECT 1 FROM sqlite_schema WHERE tbl_name = 'rbu_count'\x00SELECT sum(cnt * (1 + rbu_index_cnt(rbu_target_name(tbl))))FROM rbu_count\x00cannot update wal mode database\x00vacuum\x00update\x00database modified during rbu %s\x00BEGIN IMMEDIATE\x00PRAGMA journal_mode=off\x00-vactmp\x00DELETE FROM stat.rbu_state\x00rbu/zipvfs setup error\x00rbu(%s)/%z\x00rbu_memory\x00/\x00overflow\x00%s%.3x+%.6x\x00%s%.3x/\x00internal\x00leaf\x00corrupted\x00SELECT * FROM (SELECT 'sqlite_schema' AS name,1 AS rootpage,'table' AS type UNION ALL SELECT name,rootpage,type FROM \"%w\".sqlite_schema WHERE rootpage!=0)\x00WHERE name=%Q\x00 ORDER BY name\x00dbstat\x00CREATE TABLE x(pgno INTEGER PRIMARY KEY, data BLOB, schema HIDDEN)\x00read-only\x00cannot delete\x00cannot insert\x00no such schema\x00bad page number\x00bad page value\x00failed to open transaction\x00sqlite_dbpage\x00SELECT 0, 'tbl',  '', 0, '', 1, 0     UNION ALL SELECT 1, 'idx',  '', 0, '', 2, 0     UNION ALL SELECT 2, 'stat', '', 0, '', 0, 0\x00PRAGMA '%q'.table_xinfo('%q')\x00SELECT\x00%z%s\"%w\".\"%w\".\"%w\"=\"%w\".\"%w\".\"%w\"\x00%z%s\"%w\".\"%w\".\"%w\" IS NOT \"%w\".\"%w\".\"%w\"\x00 OR \x00_rowid_, *\x00SELECT %s FROM \"%w\".\"%w\" WHERE NOT EXISTS (  SELECT 1 FROM \"%w\".\"%w\" WHERE %s)\x00%z%s\"%w\".\"%w\".\"%w\"\x00SELECT %s,%s FROM \"%w\".\"%w\", \"%w\".\"%w\" WHERE %s AND (%z)\x00SELECT * FROM %Q.sqlite_schema\x00no such table: %s.%s\x00table schemas do not match\x00, 1\x00 AND (?6 OR ?3 IS stat)\x00tbl, idx\x00?1, (CASE WHEN ?2=X'' THEN NULL ELSE ?2 END)\x00tbl, ?2, stat\x00?%d\x00 AND (?%d OR ?%d IS %w.%w)\x00SELECT %s%s FROM %Q.%Q WHERE (%s) IS (%s)\x00SAVEPOINT changeset\x00RELEASE changeset\x00UPDATE main.\x00 SET \x00 = ?\x00 WHERE \x00idx IS CASE WHEN length(?4)=0 AND typeof(?4)='blob' THEN NULL ELSE ?4 END \x00 IS ?\x00DELETE FROM main.\x00 AND (?\x00AND \x00INSERT INTO main.\x00) VALUES(?\x00, ?\x00INSERT INTO main.sqlite_stat1 VALUES(?1, CASE WHEN length(?2)=0 AND typeof(?2)='blob' THEN NULL ELSE ?2 END, ?3)\x00DELETE FROM main.sqlite_stat1 WHERE tbl=?1 AND idx IS CASE WHEN length(?2)=0 AND typeof(?2)='blob' THEN NULL ELSE ?2 END AND (?4 OR stat IS ?3)\x00SAVEPOINT replace_op\x00RELEASE replace_op\x00PRAGMA table_list = %Q\x00SELECT %s FROM %Q WHERE (%s) IS (%s)\x00INSERT INTO %Q(%s) VALUES(%s)\x00SAVEPOINT update_op\x00ROLLBACK TO update_op\x00RELEASE update_op\x00SAVEPOINT changeset_apply\x00PRAGMA defer_foreign_keys = 1\x00sqlite3changeset_apply(): no such table: %s\x00sqlite3changeset_apply(): table %s has %d columns, expected %d or more\x00sqlite3changeset_apply(): primary key mismatch for table %s\x00PRAGMA defer_foreign_keys = 0\x00RELEASE changeset_apply\x00ROLLBACK TO changeset_apply\x00undefined\x00invalid change: %s value in PK of old.* record\x00invalid change: defined value in PK of new.* record\x00un\x00invalid change: column %d - old.* value is %sdefined but new.* is %sdefined\x00invalid change: column %d is undefined\x00invalid change: null value in PK\x00fts5: parser stack overflow\x00fts5: syntax error near \"%.*s\"\x00%z%.*s\x00wrong number of arguments to function highlight()\x00wrong number of arguments to function snippet()\x00wrong number of arguments to function fts5_get_locale()\x00non-integer argument passed to function fts5_get_locale()\x00snippet\x00highlight\x00bm25\x00fts5_get_locale\x00prefix\x00malformed prefix=... directive\x00too many prefix indexes (max %d)\x00prefix length out of range (max 999)\x00tokenize\x00multiple tokenize=... directives\x00parse error in tokenize directive\x00content\x00multiple content=... directives\x00%Q.%Q\x00contentless_delete\x00malformed contentless_delete=... directive\x00contentless_unindexed\x00content_rowid\x00multiple content_rowid=... directives\x00columnsize\x00malformed columnsize=... directive\x00locale\x00malformed locale=... directive\x00columns\x00malformed detail=... directive\x00tokendata\x00malformed tokendata=... directive\x00unrecognized option: \"%.*s\"\x00rank\x00reserved fts5 column name: %s\x00unindexed\x00unrecognized column option: %s\x00T.%Q\x00, T.%Q\x00, T.c%d\x00, NULL\x00, T.l%d\x00reserved fts5 table name: %s\x00parse error in \"%s\"\x00contentless_delete=1 requires a contentless table\x00contentless_delete=1 is incompatible with columnsize=0\x00contentless_unindexed=1 requires a contentless table\x00docsize\x00%Q.'%q_%s'\x00CREATE TABLE x(\x00%z%s%Q\x00%z, %Q HIDDEN, %s HIDDEN)\x00pgsz\x00hashsize\x00automerge\x00usermerge\x00crisismerge\x00deletemerge\x00secure-delete\x00insttoken\x00SELECT k, v FROM %Q.'%q_config'\x00version\x00invalid fts5 file format (found %d, expected %d or %d) - run 'rebuild'\x00unterminated string\x00fts5: syntax error near \"%.1s\"\x00OR\x00NOT\x00NEAR\x00expected integer, got \"%.*s\"\x00fts5: column queries are not supported (detail=none)\x00phrase\x00fts5: %s queries are not supported (detail!=full)\x00fts5 expression tree is too large (maximum depth %d)\x00fts5: corruption found reading blob %lld from table \"%s\"\x00fts5: corruption on page %d, segment %d, table \"%s\"\x00fts5: corruption in table \"%s\"\x00block\x00REPLACE INTO '%q'.'%q_data'(id, block) VALUES(?,?)\x00DELETE FROM '%q'.'%q_data' WHERE id>=? AND id<=?\x00DELETE FROM '%q'.'%q_idx' WHERE segid=?\x00\xff\x00\x00\x01\x00fts5: corrupt structure record for table \"%s\"\x00PRAGMA %Q.data_version\x00SELECT pgno FROM '%q'.'%q_idx' WHERE segid=? AND term<=? ORDER BY term DESC LIMIT 1\x00SELECT pgno FROM '%q'.'%q_idx' WHERE segid=? AND term>? ORDER BY term ASC LIMIT 1\x00INSERT INTO '%q'.'%q_idx'(segid,term,pgno) VALUES(?,?,?)\x00DELETE FROM '%q'.'%q_idx' WHERE (segid, (pgno/2)) = (?1, ?2)\x00REPLACE INTO %Q.'%q_config' VALUES ('version', %d)\x00%s_data\x00id INTEGER PRIMARY KEY, block BLOB\x00segid, term, pgno, PRIMARY KEY(segid, term)\x00\x00\x00SELECT segid, term, (pgno>>1), (pgno&1) FROM %Q.'%q_idx' WHERE segid=%d ORDER BY 1, 2\x00\x00\x00\x00\x00\x00fts5: checksum mismatch for table \"%s\"\x00recursively defined fts5 content table\x00DESC\x00ASC\x00SELECT rowid, rank FROM %Q.%Q ORDER BY %s(\"%w\"%s%s) %s\x00reads\x00unknown special query: %.*s\x00SELECT %s\x00no such function: %s\x00parse error in rank function: %s\x00%s: table does not support scanning\x00fts5: missing row %lld from content table %s\x00delete-all\x00'delete-all' may only be used with a contentless or external content fts5 table\x00rebuild\x00'rebuild' may not be used with a contentless fts5 table\x00merge\x00integrity-check\x00flush\x00%s a subset of columns on fts5 contentless-delete table: %s\x00%s contentless fts5 table: %s\x00cannot UPDATE\x00'delete' may not be used with a contentless_delete=1 table\x00cannot DELETE from contentless fts5 table: %s\x00fts5_locale() requires locale=1\x00no such cursor: %lld\x00no such tokenizer: %s\x00error in tokenizer constructor\x00fts5_api_ptr\x00fts5: 2026-06-26 20:14:12 d4c0e51e4aeb96955b99185ab9cde75c339e2c29c3f3f12428d364a10d782c62\x00config\x00malformed inverted index for FTS5 table %s.%s\x00unable to validate the inverted index for FTS5 table %s.%s: %s\x00fts5\x00fts5_source_id\x00fts5_locale\x00fts5_insttoken\x00SELECT %s FROM %s T WHERE T.%Q >= ? AND T.%Q <= ? ORDER BY T.%Q ASC\x00SELECT %s FROM %s T WHERE T.%Q <= ? AND T.%Q >= ? ORDER BY T.%Q DESC\x00SELECT %s FROM %s T WHERE T.%Q=?\x00INSERT INTO %Q.'%q_content' VALUES(%s)\x00REPLACE INTO %Q.'%q_content' VALUES(%s)\x00DELETE FROM %Q.'%q_content' WHERE id=?\x00REPLACE INTO %Q.'%q_docsize' VALUES(?,?%s)\x00DELETE FROM %Q.'%q_docsize' WHERE id=?\x00SELECT sz%s FROM %Q.'%q_docsize' WHERE id=?\x00REPLACE INTO %Q.'%q_config' VALUES(?,?)\x00SELECT %s FROM %s AS T\x00%z%s?%d\x00%z,?%d\x00,?\x00,origin\x00DROP TABLE IF EXISTS %Q.'%q_data';DROP TABLE IF EXISTS %Q.'%q_idx';DROP TABLE IF EXISTS %Q.'%q_config';\x00DROP TABLE IF EXISTS %Q.'%q_docsize';\x00DROP TABLE IF EXISTS %Q.'%q_content';\x00ALTER TABLE %Q.'%q_%s' RENAME TO '%q_%s';\x00CREATE TABLE %Q.'%q_%q'(%s)%s\x00fts5: error creating shadow table %q_%s: %s\x00id INTEGER PRIMARY KEY\x00, c%d\x00, l%d\x00id INTEGER PRIMARY KEY, sz BLOB\x00id INTEGER PRIMARY KEY, sz BLOB, origin INTEGER\x00k PRIMARY KEY, v\x00DELETE FROM %Q.'%q_data';DELETE FROM %Q.'%q_idx';\x00DELETE FROM %Q.'%q_docsize';\x00DELETE FROM %Q.'%q_content';\x00SELECT count(*) FROM %Q.'%q_%s'\x00tokenchars\x00separators\x00L* N* Co\x00categories\x00remove_diacritics\x00unicode61\x00porter\x00al\x00ance\x00ence\x00er\x00ic\x00able\x00ible\x00ant\x00ement\x00ment\x00ent\x00ion\x00ou\x00ism\x00ate\x00iti\x00ous\x00ive\x00ize\x00at\x00bl\x00ble\x00iz\x00ational\x00tional\x00tion\x00enci\x00anci\x00izer\x00logi\x00bli\x00alli\x00entli\x00eli\x00e\x00ousli\x00ization\x00ation\x00ator\x00alism\x00iveness\x00fulness\x00ful\x00ousness\x00aliti\x00iviti\x00biliti\x00ical\x00ness\x00icate\x00iciti\x00ative\x00alize\x00eed\x00ee\x00ed\x00ing\x00case_sensitive\x00trigram\x00ascii\x00col\x00row\x00instance\x00fts5vocab: unknown table type: %Q\x00CREATE TABlE vocab(term, col, doc, cnt)\x00CREATE TABlE vocab(term, doc, cnt)\x00CREATE TABlE vocab(term, doc, col, offset)\x00wrong number of vtable arguments\x00recursive definition for %s.%s\x00SELECT t.%Q FROM %Q.%Q AS t WHERE t.%Q MATCH '*id'\x00no such fts5 table: %s.%s\x00fts5vocab\x002026-06-26 20:14:12 d4c0e51e4aeb96955b99185ab9cde75c339e2c29c3f3f12428d364a10d782c62\x00"

const __clang_version__ = "19.1.7 "

const __htobe16 = 0

const __htobe32 = 0

const __htobe64 = 0

const __pie__ = 1

const __st_birthtimespec = 0

var _aAgg = [1]struct {
	FxStep  uintptr
	FxFinal uintptr
	FzName  uintptr
}{
	0: {
		FzName: __ccgo_ts + 30191,
	},
}

var _aAlterTableFuncs = [9]TFuncDef{
	0: {
		FnArg:      int16(9),
		FfuncFlags: libc.Uint32FromInt32(libc.Int32FromInt32(SQLITE_FUNC_BUILTIN) | libc.Int32FromInt32(SQLITE_FUNC_INTERNAL) | libc.Int32FromInt32(SQLITE_UTF8) | libc.Int32FromInt32(SQLITE_FUNC_CONSTANT)),
		FzName:     __ccgo_ts + 12644,
	},
	1: {
		FnArg:      int16(7),
		FfuncFlags: libc.Uint32FromInt32(libc.Int32FromInt32(SQLITE_FUNC_BUILTIN) | libc.Int32FromInt32(SQLITE_FUNC_INTERNAL) | libc.Int32FromInt32(SQLITE_UTF8) | libc.Int32FromInt32(SQLITE_FUNC_CONSTANT)),
		FzName:     __ccgo_ts + 12665,
	},
	2: {
		FnArg:      int16(7),
		FfuncFlags: libc.Uint32FromInt32(libc.Int32FromInt32(SQLITE_FUNC_BUILTIN) | libc.Int32FromInt32(SQLITE_FUNC_INTERNAL) | libc.Int32FromInt32(SQLITE_UTF8) | libc.Int32FromInt32(SQLITE_FUNC_CONSTANT)),
		FzName:     __ccgo_ts + 12685,
	},
	3: {
		FnArg:      int16(3),
		FfuncFlags: libc.Uint32FromInt32(libc.Int32FromInt32(SQLITE_FUNC_BUILTIN) | libc.Int32FromInt32(SQLITE_FUNC_INTERNAL) | libc.Int32FromInt32(SQLITE_UTF8) | libc.Int32FromInt32(SQLITE_FUNC_CONSTANT)),
		FzName:     __ccgo_ts + 12704,
	},
	4: {
		FnArg:      int16(2),
		FfuncFlags: libc.Uint32FromInt32(libc.Int32FromInt32(SQLITE_FUNC_BUILTIN) | libc.Int32FromInt32(SQLITE_FUNC_INTERNAL) | libc.Int32FromInt32(SQLITE_UTF8) | libc.Int32FromInt32(SQLITE_FUNC_CONSTANT)),
		FzName:     __ccgo_ts + 12723,
	},
	5: {
		FnArg:      int16(2),
		FfuncFlags: libc.Uint32FromInt32(libc.Int32FromInt32(SQLITE_FUNC_BUILTIN) | libc.Int32FromInt32(SQLITE_FUNC_INTERNAL) | libc.Int32FromInt32(SQLITE_UTF8) | libc.Int32FromInt32(SQLITE_FUNC_CONSTANT)),
		FzName:     __ccgo_ts + 12746,
	},
	6: {
		FnArg:      int16(2),
		FfuncFlags: libc.Uint32FromInt32(libc.Int32FromInt32(SQLITE_FUNC_BUILTIN) | libc.Int32FromInt32(SQLITE_FUNC_INTERNAL) | libc.Int32FromInt32(SQLITE_UTF8) | libc.Int32FromInt32(SQLITE_FUNC_CONSTANT)),
		FzName:     __ccgo_ts + 12769,
	},
	7: {
		FnArg:      int16(3),
		FfuncFlags: libc.Uint32FromInt32(libc.Int32FromInt32(SQLITE_FUNC_BUILTIN) | libc.Int32FromInt32(SQLITE_FUNC_INTERNAL) | libc.Int32FromInt32(SQLITE_UTF8) | libc.Int32FromInt32(SQLITE_FUNC_CONSTANT)),
		FzName:     __ccgo_ts + 12781,
	},
	8: {
		FnArg:      int16(2),
		FfuncFlags: libc.Uint32FromInt32(libc.Int32FromInt32(SQLITE_FUNC_BUILTIN) | libc.Int32FromInt32(SQLITE_FUNC_INTERNAL) | libc.Int32FromInt32(SQLITE_UTF8) | libc.Int32FromInt32(SQLITE_FUNC_CONSTANT)),
		FzName:     __ccgo_ts + 12803,
	},
}

/*
 ** The following array holds FuncDef structures for all of the functions
 ** defined in this file.
 **
 ** The array cannot be constant since changes are made to the
 ** FuncDef.pHash elements at start-time.  The elements of this array
 ** are read-only after initialization is complete.
 **
 ** For peak efficiency, put the most frequently used function last.
 */
var _aBuiltinFunc = [106]TFuncDef{
	0: {
		FnArg:      int16(2),
		FfuncFlags: libc.Uint32FromInt32(libc.Int32FromInt32(SQLITE_FUNC_BUILTIN) | libc.Int32FromInt32(SQLITE_UTF8) | libc.Int32FromInt32(SQLITE_FUNC_INTERNAL) | libc.Int32FromInt32(SQLITE_FUNC_TEST) | libc.Int32FromInt32(SQLITE_FUNC_INLINE) | libc.Int32FromInt32(SQLITE_FUNC_CONSTANT) | libc.Int32FromInt32(0)),
		FpUserData: uintptr(int64(libc.Int32FromInt32(INLINEFUNC_implies_nonnull_row))),
		FzName:     __ccgo_ts + 16603,
	},
	1: {
		FnArg:      int16(2),
		FfuncFlags: libc.Uint32FromInt32(libc.Int32FromInt32(SQLITE_FUNC_BUILTIN) | libc.Int32FromInt32(SQLITE_UTF8) | libc.Int32FromInt32(SQLITE_FUNC_INTERNAL) | libc.Int32FromInt32(SQLITE_FUNC_TEST) | libc.Int32FromInt32(SQLITE_FUNC_INLINE) | libc.Int32FromInt32(SQLITE_FUNC_CONSTANT) | libc.Int32FromInt32(0)),
		FpUserData: uintptr(int64(libc.Int32FromInt32(INLINEFUNC_expr_compare))),
		FzName:     __ccgo_ts + 16623,
	},
	2: {
		FnArg:      int16(2),
		FfuncFlags: libc.Uint32FromInt32(libc.Int32FromInt32(SQLITE_FUNC_BUILTIN) | libc.Int32FromInt32(SQLITE_UTF8) | libc.Int32FromInt32(SQLITE_FUNC_INTERNAL) | libc.Int32FromInt32(SQLITE_FUNC_TEST) | libc.Int32FromInt32(SQLITE_FUNC_INLINE) | libc.Int32FromInt32(SQLITE_FUNC_CONSTANT) | libc.Int32FromInt32(0)),
		FpUserData: uintptr(int64(libc.Int32FromInt32(INLINEFUNC_expr_implies_expr))),
		FzName:     __ccgo_ts + 16636,
	},
	3: {
		FnArg:      int16(1),
		FfuncFlags: libc.Uint32FromInt32(libc.Int32FromInt32(SQLITE_FUNC_BUILTIN) | libc.Int32FromInt32(SQLITE_UTF8) | libc.Int32FromInt32(SQLITE_FUNC_INTERNAL) | libc.Int32FromInt32(SQLITE_FUNC_TEST) | libc.Int32FromInt32(SQLITE_FUNC_INLINE) | libc.Int32FromInt32(SQLITE_FUNC_CONSTANT) | libc.Int32FromInt32(0)),
		FpUserData: uintptr(int64(libc.Int32FromInt32(INLINEFUNC_affinity))),
		FzName:     __ccgo_ts + 16654,
	},
	4: {
		FnArg:      int16(1),
		FfuncFlags: libc.Uint32FromInt32(libc.Int32FromInt32(SQLITE_FUNC_BUILTIN) | libc.Int32FromInt32(SQLITE_FUNC_CONSTANT) | libc.Int32FromInt32(SQLITE_UTF8) | libc.Int32FromInt32(0)*libc.Int32FromInt32(SQLITE_FUNC_NEEDCOLL)),
		FzName:     __ccgo_ts + 16663,
	},
	5: {
		FnArg:      int16(1),
		FfuncFlags: libc.Uint32FromInt32(libc.Int32FromInt32(SQLITE_FUNC_BUILTIN) | libc.Int32FromInt32(SQLITE_UTF8) | libc.Int32FromInt32(SQLITE_DIRECTONLY) | libc.Int32FromInt32(SQLITE_FUNC_UNSAFE)),
		FzName:     __ccgo_ts + 16671,
	},
	6: {
		FnArg:      int16(2),
		FfuncFlags: libc.Uint32FromInt32(libc.Int32FromInt32(SQLITE_FUNC_BUILTIN) | libc.Int32FromInt32(SQLITE_UTF8) | libc.Int32FromInt32(SQLITE_DIRECTONLY) | libc.Int32FromInt32(SQLITE_FUNC_UNSAFE)),
		FzName:     __ccgo_ts + 16671,
	},
	7: {
		FnArg:      int16(1),
		FfuncFlags: libc.Uint32FromInt32(libc.Int32FromInt32(SQLITE_FUNC_BUILTIN) | libc.Int32FromInt32(SQLITE_FUNC_SLOCHNG) | libc.Int32FromInt32(SQLITE_UTF8)),
		FzName:     __ccgo_ts + 16686,
	},
	8: {
		FnArg:      int16(1),
		FfuncFlags: libc.Uint32FromInt32(libc.Int32FromInt32(SQLITE_FUNC_BUILTIN) | libc.Int32FromInt32(SQLITE_FUNC_SLOCHNG) | libc.Int32FromInt32(SQLITE_UTF8)),
		FzName:     __ccgo_ts + 16712,
	},
	9: {
		FnArg:      int16(1),
		FfuncFlags: libc.Uint32FromInt32(libc.Int32FromInt32(SQLITE_FUNC_BUILTIN) | libc.Int32FromInt32(SQLITE_UTF8) | libc.Int32FromInt32(SQLITE_FUNC_INLINE) | libc.Int32FromInt32(SQLITE_FUNC_CONSTANT) | libc.Int32FromInt32(SQLITE_FUNC_UNLIKELY)),
		FpUserData: uintptr(int64(libc.Int32FromInt32(INLINEFUNC_unlikely))),
		FzName:     __ccgo_ts + 16737,
	},
	10: {
		FnArg:      int16(2),
		FfuncFlags: libc.Uint32FromInt32(libc.Int32FromInt32(SQLITE_FUNC_BUILTIN) | libc.Int32FromInt32(SQLITE_UTF8) | libc.Int32FromInt32(SQLITE_FUNC_INLINE) | libc.Int32FromInt32(SQLITE_FUNC_CONSTANT) | libc.Int32FromInt32(SQLITE_FUNC_UNLIKELY)),
		FpUserData: uintptr(int64(libc.Int32FromInt32(INLINEFUNC_unlikely))),
		FzName:     __ccgo_ts + 16746,
	},
	11: {
		FnArg:      int16(1),
		FfuncFlags: libc.Uint32FromInt32(libc.Int32FromInt32(SQLITE_FUNC_BUILTIN) | libc.Int32FromInt32(SQLITE_UTF8) | libc.Int32FromInt32(SQLITE_FUNC_INLINE) | libc.Int32FromInt32(SQLITE_FUNC_CONSTANT) | libc.Int32FromInt32(SQLITE_FUNC_UNLIKELY)),
		FpUserData: uintptr(int64(libc.Int32FromInt32(INLINEFUNC_unlikely))),
		FzName:     __ccgo_ts + 16757,
	},
	12: {
		FnArg:      int16(1),
		FfuncFlags: libc.Uint32FromInt32(libc.Int32FromInt32(SQLITE_FUNC_BUILTIN) | libc.Int32FromInt32(SQLITE_UTF8) | libc.Int32FromInt32(SQLITE_FUNC_INLINE) | libc.Int32FromInt32(SQLITE_FUNC_CONSTANT) | libc.Int32FromInt32(0)),
		FpUserData: uintptr(int64(libc.Int32FromInt32(INLINEFUNC_sqlite_offset))),
		FzName:     __ccgo_ts + 16764,
	},
	13: {
		FnArg:      int16(1),
		FfuncFlags: libc.Uint32FromInt32(libc.Int32FromInt32(SQLITE_FUNC_BUILTIN) | libc.Int32FromInt32(SQLITE_FUNC_CONSTANT) | libc.Int32FromInt32(SQLITE_UTF8) | libc.Int32FromInt32(0)*libc.Int32FromInt32(SQLITE_FUNC_NEEDCOLL)),
		FpUserData: uintptr(int64(libc.Int32FromInt32(1))),
		FzName:     __ccgo_ts + 16778,
	},
	14: {
		FnArg:      int16(2),
		FfuncFlags: libc.Uint32FromInt32(libc.Int32FromInt32(SQLITE_FUNC_BUILTIN) | libc.Int32FromInt32(SQLITE_FUNC_CONSTANT) | libc.Int32FromInt32(SQLITE_UTF8) | libc.Int32FromInt32(0)*libc.Int32FromInt32(SQLITE_FUNC_NEEDCOLL)),
		FpUserData: uintptr(int64(libc.Int32FromInt32(1))),
		FzName:     __ccgo_ts + 16778,
	},
	15: {
		FnArg:      int16(1),
		FfuncFlags: libc.Uint32FromInt32(libc.Int32FromInt32(SQLITE_FUNC_BUILTIN) | libc.Int32FromInt32(SQLITE_FUNC_CONSTANT) | libc.Int32FromInt32(SQLITE_UTF8) | libc.Int32FromInt32(0)*libc.Int32FromInt32(SQLITE_FUNC_NEEDCOLL)),
		FpUserData: uintptr(int64(libc.Int32FromInt32(2))),
		FzName:     __ccgo_ts + 16784,
	},
	16: {
		FnArg:      int16(2),
		FfuncFlags: libc.Uint32FromInt32(libc.Int32FromInt32(SQLITE_FUNC_BUILTIN) | libc.Int32FromInt32(SQLITE_FUNC_CONSTANT) | libc.Int32FromInt32(SQLITE_UTF8) | libc.Int32FromInt32(0)*libc.Int32FromInt32(SQLITE_FUNC_NEEDCOLL)),
		FpUserData: uintptr(int64(libc.Int32FromInt32(2))),
		FzName:     __ccgo_ts + 16784,
	},
	17: {
		FnArg:      int16(1),
		FfuncFlags: libc.Uint32FromInt32(libc.Int32FromInt32(SQLITE_FUNC_BUILTIN) | libc.Int32FromInt32(SQLITE_FUNC_CONSTANT) | libc.Int32FromInt32(SQLITE_UTF8) | libc.Int32FromInt32(0)*libc.Int32FromInt32(SQLITE_FUNC_NEEDCOLL)),
		FpUserData: uintptr(int64(libc.Int32FromInt32(3))),
		FzName:     __ccgo_ts + 16790,
	},
	18: {
		FnArg:      int16(2),
		FfuncFlags: libc.Uint32FromInt32(libc.Int32FromInt32(SQLITE_FUNC_BUILTIN) | libc.Int32FromInt32(SQLITE_FUNC_CONSTANT) | libc.Int32FromInt32(SQLITE_UTF8) | libc.Int32FromInt32(0)*libc.Int32FromInt32(SQLITE_FUNC_NEEDCOLL)),
		FpUserData: uintptr(int64(libc.Int32FromInt32(3))),
		FzName:     __ccgo_ts + 16790,
	},
	19: {
		FnArg:      int16(-int32(3)),
		FfuncFlags: libc.Uint32FromInt32(libc.Int32FromInt32(SQLITE_FUNC_BUILTIN) | libc.Int32FromInt32(SQLITE_FUNC_CONSTANT) | libc.Int32FromInt32(SQLITE_UTF8) | libc.Int32FromInt32(1)*libc.Int32FromInt32(SQLITE_FUNC_NEEDCOLL)),
		FzName:     __ccgo_ts + 16795,
	},
	20: {
		FnArg:      int16(1),
		FfuncFlags: libc.Uint32FromInt32(libc.Int32FromInt32(SQLITE_FUNC_BUILTIN) | libc.Int32FromInt32(SQLITE_UTF8) | libc.Int32FromInt32(1)*libc.Int32FromInt32(SQLITE_FUNC_NEEDCOLL) | libc.Int32FromInt32(SQLITE_FUNC_MINMAX) | libc.Int32FromInt32(SQLITE_FUNC_ANYORDER)),
		FzName:     __ccgo_ts + 16795,
	},
	21: {
		FnArg:      int16(-int32(3)),
		FfuncFlags: libc.Uint32FromInt32(libc.Int32FromInt32(SQLITE_FUNC_BUILTIN) | libc.Int32FromInt32(SQLITE_FUNC_CONSTANT) | libc.Int32FromInt32(SQLITE_UTF8) | libc.Int32FromInt32(1)*libc.Int32FromInt32(SQLITE_FUNC_NEEDCOLL)),
		FpUserData: uintptr(int64(libc.Int32FromInt32(1))),
		FzName:     __ccgo_ts + 16799,
	},
	22: {
		FnArg:      int16(1),
		FfuncFlags: libc.Uint32FromInt32(libc.Int32FromInt32(SQLITE_FUNC_BUILTIN) | libc.Int32FromInt32(SQLITE_UTF8) | libc.Int32FromInt32(1)*libc.Int32FromInt32(SQLITE_FUNC_NEEDCOLL) | libc.Int32FromInt32(SQLITE_FUNC_MINMAX) | libc.Int32FromInt32(SQLITE_FUNC_ANYORDER)),
		FpUserData: uintptr(int64(libc.Int32FromInt32(1))),
		FzName:     __ccgo_ts + 16799,
	},
	23: {
		FnArg:      int16(1),
		FfuncFlags: libc.Uint32FromInt32(libc.Int32FromInt32(SQLITE_FUNC_BUILTIN) | libc.Int32FromInt32(SQLITE_FUNC_CONSTANT) | libc.Int32FromInt32(SQLITE_UTF8) | libc.Int32FromInt32(0)*libc.Int32FromInt32(SQLITE_FUNC_NEEDCOLL) | libc.Int32FromInt32(SQLITE_FUNC_TYPEOF)),
		FzName:     __ccgo_ts + 16803,
	},
	24: {
		FnArg:      int16(1),
		FfuncFlags: libc.Uint32FromInt32(libc.Int32FromInt32(SQLITE_FUNC_BUILTIN) | libc.Int32FromInt32(SQLITE_FUNC_CONSTANT) | libc.Int32FromInt32(SQLITE_UTF8) | libc.Int32FromInt32(0)*libc.Int32FromInt32(SQLITE_FUNC_NEEDCOLL) | libc.Int32FromInt32(SQLITE_FUNC_TYPEOF) | libc.Int32FromInt32(SQLITE_SUBTYPE)),
		FzName:     __ccgo_ts + 16810,
	},
	25: {
		FnArg:      int16(1),
		FfuncFlags: libc.Uint32FromInt32(libc.Int32FromInt32(SQLITE_FUNC_BUILTIN) | libc.Int32FromInt32(SQLITE_FUNC_CONSTANT) | libc.Int32FromInt32(SQLITE_UTF8) | libc.Int32FromInt32(0)*libc.Int32FromInt32(SQLITE_FUNC_NEEDCOLL) | libc.Int32FromInt32(SQLITE_FUNC_LENGTH)),
		FzName:     __ccgo_ts + 16818,
	},
	26: {
		FnArg:      int16(1),
		FfuncFlags: libc.Uint32FromInt32(libc.Int32FromInt32(SQLITE_FUNC_BUILTIN) | libc.Int32FromInt32(SQLITE_FUNC_CONSTANT) | libc.Int32FromInt32(SQLITE_UTF8) | libc.Int32FromInt32(0)*libc.Int32FromInt32(SQLITE_FUNC_NEEDCOLL) | libc.Int32FromInt32(SQLITE_FUNC_BYTELEN)),
		FzName:     __ccgo_ts + 16825,
	},
	27: {
		FnArg:      int16(2),
		FfuncFlags: libc.Uint32FromInt32(libc.Int32FromInt32(SQLITE_FUNC_BUILTIN) | libc.Int32FromInt32(SQLITE_FUNC_CONSTANT) | libc.Int32FromInt32(SQLITE_UTF8) | libc.Int32FromInt32(0)*libc.Int32FromInt32(SQLITE_FUNC_NEEDCOLL)),
		FzName:     __ccgo_ts + 16838,
	},
	28: {
		FnArg:      int16(-int32(1)),
		FfuncFlags: libc.Uint32FromInt32(libc.Int32FromInt32(SQLITE_FUNC_BUILTIN) | libc.Int32FromInt32(SQLITE_FUNC_CONSTANT) | libc.Int32FromInt32(SQLITE_UTF8) | libc.Int32FromInt32(0)*libc.Int32FromInt32(SQLITE_FUNC_NEEDCOLL)),
		FzName:     __ccgo_ts + 16844,
	},
	29: {
		FnArg:      int16(-int32(1)),
		FfuncFlags: libc.Uint32FromInt32(libc.Int32FromInt32(SQLITE_FUNC_BUILTIN) | libc.Int32FromInt32(SQLITE_FUNC_CONSTANT) | libc.Int32FromInt32(SQLITE_UTF8) | libc.Int32FromInt32(0)*libc.Int32FromInt32(SQLITE_FUNC_NEEDCOLL)),
		FzName:     __ccgo_ts + 16851,
	},
	30: {
		FnArg:      int16(1),
		FfuncFlags: libc.Uint32FromInt32(libc.Int32FromInt32(SQLITE_FUNC_BUILTIN) | libc.Int32FromInt32(SQLITE_FUNC_CONSTANT) | libc.Int32FromInt32(SQLITE_UTF8) | libc.Int32FromInt32(0)*libc.Int32FromInt32(SQLITE_FUNC_NEEDCOLL)),
		FzName:     __ccgo_ts + 16858,
	},
	31: {
		FnArg:      int16(-int32(1)),
		FfuncFlags: libc.Uint32FromInt32(libc.Int32FromInt32(SQLITE_FUNC_BUILTIN) | libc.Int32FromInt32(SQLITE_FUNC_CONSTANT) | libc.Int32FromInt32(SQLITE_UTF8) | libc.Int32FromInt32(0)*libc.Int32FromInt32(SQLITE_FUNC_NEEDCOLL)),
		FzName:     __ccgo_ts + 16866,
	},
	32: {
		FnArg:      int16(1),
		FfuncFlags: libc.Uint32FromInt32(libc.Int32FromInt32(SQLITE_FUNC_BUILTIN) | libc.Int32FromInt32(SQLITE_FUNC_CONSTANT) | libc.Int32FromInt32(SQLITE_UTF8) | libc.Int32FromInt32(0)*libc.Int32FromInt32(SQLITE_FUNC_NEEDCOLL)),
		FzName:     __ccgo_ts + 16871,
	},
	33: {
		FnArg:      int16(1),
		FfuncFlags: libc.Uint32FromInt32(libc.Int32FromInt32(SQLITE_FUNC_BUILTIN) | libc.Int32FromInt32(SQLITE_FUNC_CONSTANT) | libc.Int32FromInt32(SQLITE_UTF8) | libc.Int32FromInt32(0)*libc.Int32FromInt32(SQLITE_FUNC_NEEDCOLL)),
		FzName:     __ccgo_ts + 16875,
	},
	34: {
		FnArg:      int16(2),
		FfuncFlags: libc.Uint32FromInt32(libc.Int32FromInt32(SQLITE_FUNC_BUILTIN) | libc.Int32FromInt32(SQLITE_FUNC_CONSTANT) | libc.Int32FromInt32(SQLITE_UTF8) | libc.Int32FromInt32(0)*libc.Int32FromInt32(SQLITE_FUNC_NEEDCOLL)),
		FzName:     __ccgo_ts + 16875,
	},
	35: {
		FnArg:      int16(1),
		FfuncFlags: libc.Uint32FromInt32(libc.Int32FromInt32(SQLITE_FUNC_BUILTIN) | libc.Int32FromInt32(SQLITE_FUNC_CONSTANT) | libc.Int32FromInt32(SQLITE_UTF8) | libc.Int32FromInt32(0)*libc.Int32FromInt32(SQLITE_FUNC_NEEDCOLL)),
		FzName:     __ccgo_ts + 16881,
	},
	36: {
		FnArg:      int16(1),
		FfuncFlags: libc.Uint32FromInt32(libc.Int32FromInt32(SQLITE_FUNC_BUILTIN) | libc.Int32FromInt32(SQLITE_FUNC_CONSTANT) | libc.Int32FromInt32(SQLITE_UTF8) | libc.Int32FromInt32(0)*libc.Int32FromInt32(SQLITE_FUNC_NEEDCOLL)),
		FzName:     __ccgo_ts + 16887,
	},
	37: {
		FnArg:      int16(1),
		FfuncFlags: libc.Uint32FromInt32(libc.Int32FromInt32(SQLITE_FUNC_BUILTIN) | libc.Int32FromInt32(SQLITE_FUNC_CONSTANT) | libc.Int32FromInt32(SQLITE_UTF8) | libc.Int32FromInt32(0)*libc.Int32FromInt32(SQLITE_FUNC_NEEDCOLL)),
		FzName:     __ccgo_ts + 16893,
	},
	38: {
		FnArg:      int16(1),
		FfuncFlags: libc.Uint32FromInt32(libc.Int32FromInt32(SQLITE_FUNC_BUILTIN) | libc.Int32FromInt32(SQLITE_FUNC_CONSTANT) | libc.Int32FromInt32(SQLITE_UTF8) | libc.Int32FromInt32(0)*libc.Int32FromInt32(SQLITE_FUNC_NEEDCOLL)),
		FzName:     __ccgo_ts + 16897,
	},
	39: {
		FnArg:      int16(2),
		FfuncFlags: libc.Uint32FromInt32(libc.Int32FromInt32(SQLITE_FUNC_BUILTIN) | libc.Int32FromInt32(SQLITE_FUNC_CONSTANT) | libc.Int32FromInt32(SQLITE_UTF8) | libc.Int32FromInt32(0)*libc.Int32FromInt32(SQLITE_FUNC_NEEDCOLL)),
		FzName:     __ccgo_ts + 16897,
	},
	40: {
		FnArg:      int16(-int32(3)),
		FfuncFlags: libc.Uint32FromInt32(libc.Int32FromInt32(SQLITE_FUNC_BUILTIN) | libc.Int32FromInt32(SQLITE_FUNC_CONSTANT) | libc.Int32FromInt32(SQLITE_UTF8) | libc.Int32FromInt32(0)*libc.Int32FromInt32(SQLITE_FUNC_NEEDCOLL)),
		FzName:     __ccgo_ts + 16903,
	},
	41: {
		FnArg:      int16(-int32(4)),
		FfuncFlags: libc.Uint32FromInt32(libc.Int32FromInt32(SQLITE_FUNC_BUILTIN) | libc.Int32FromInt32(SQLITE_FUNC_CONSTANT) | libc.Int32FromInt32(SQLITE_UTF8) | libc.Int32FromInt32(0)*libc.Int32FromInt32(SQLITE_FUNC_NEEDCOLL)),
		FzName:     __ccgo_ts + 16910,
	},
	42: {
		FnArg:      int16(2),
		FfuncFlags: libc.Uint32FromInt32(libc.Int32FromInt32(SQLITE_FUNC_BUILTIN) | libc.Int32FromInt32(SQLITE_UTF8) | libc.Int32FromInt32(SQLITE_FUNC_INLINE) | libc.Int32FromInt32(SQLITE_FUNC_CONSTANT) | libc.Int32FromInt32(0)),
		FzName:     __ccgo_ts + 16920,
	},
	43: {
		FfuncFlags: libc.Uint32FromInt32(libc.Int32FromInt32(SQLITE_FUNC_BUILTIN) | libc.Int32FromInt32(SQLITE_UTF8) | libc.Int32FromInt32(0)*libc.Int32FromInt32(SQLITE_FUNC_NEEDCOLL)),
		FzName:     __ccgo_ts + 16927,
	},
	44: {
		FnArg:      int16(1),
		FfuncFlags: libc.Uint32FromInt32(libc.Int32FromInt32(SQLITE_FUNC_BUILTIN) | libc.Int32FromInt32(SQLITE_UTF8) | libc.Int32FromInt32(0)*libc.Int32FromInt32(SQLITE_FUNC_NEEDCOLL)),
		FzName:     __ccgo_ts + 16934,
	},
	45: {
		FnArg:      int16(2),
		FfuncFlags: libc.Uint32FromInt32(libc.Int32FromInt32(SQLITE_FUNC_BUILTIN) | libc.Int32FromInt32(SQLITE_FUNC_CONSTANT) | libc.Int32FromInt32(SQLITE_UTF8) | libc.Int32FromInt32(1)*libc.Int32FromInt32(SQLITE_FUNC_NEEDCOLL)),
		FzName:     __ccgo_ts + 16945,
	},
	46: {
		FfuncFlags: libc.Uint32FromInt32(libc.Int32FromInt32(SQLITE_FUNC_BUILTIN) | libc.Int32FromInt32(SQLITE_FUNC_SLOCHNG) | libc.Int32FromInt32(SQLITE_UTF8)),
		FzName:     __ccgo_ts + 16952,
	},
	47: {
		FfuncFlags: libc.Uint32FromInt32(libc.Int32FromInt32(SQLITE_FUNC_BUILTIN) | libc.Int32FromInt32(SQLITE_FUNC_SLOCHNG) | libc.Int32FromInt32(SQLITE_UTF8)),
		FzName:     __ccgo_ts + 16967,
	},
	48: {
		FnArg:      int16(2),
		FfuncFlags: libc.Uint32FromInt32(libc.Int32FromInt32(SQLITE_FUNC_BUILTIN) | libc.Int32FromInt32(SQLITE_FUNC_CONSTANT) | libc.Int32FromInt32(SQLITE_UTF8) | libc.Int32FromInt32(0)*libc.Int32FromInt32(SQLITE_FUNC_NEEDCOLL)),
		FzName:     __ccgo_ts + 16984,
	},
	49: {
		FnArg:      int16(1),
		FfuncFlags: libc.Uint32FromInt32(libc.Int32FromInt32(SQLITE_FUNC_BUILTIN) | libc.Int32FromInt32(SQLITE_FUNC_CONSTANT) | libc.Int32FromInt32(SQLITE_UTF8) | libc.Int32FromInt32(0)*libc.Int32FromInt32(SQLITE_FUNC_NEEDCOLL)),
		FzName:     __ccgo_ts + 16995,
	},
	50: {
		FnArg:      int16(1),
		FfuncFlags: libc.Uint32FromInt32(libc.Int32FromInt32(SQLITE_FUNC_BUILTIN) | libc.Int32FromInt32(SQLITE_FUNC_CONSTANT) | libc.Int32FromInt32(SQLITE_UTF8) | libc.Int32FromInt32(0)*libc.Int32FromInt32(SQLITE_FUNC_NEEDCOLL)),
		FzName:     __ccgo_ts + 17002,
	},
	51: {
		FnArg:      int16(1),
		FfuncFlags: libc.Uint32FromInt32(libc.Int32FromInt32(SQLITE_FUNC_BUILTIN) | libc.Int32FromInt32(SQLITE_FUNC_CONSTANT) | libc.Int32FromInt32(SQLITE_UTF8) | libc.Int32FromInt32(0)*libc.Int32FromInt32(SQLITE_FUNC_NEEDCOLL)),
		FpUserData: uintptr(int64(libc.Int32FromInt32(1))),
		FzName:     __ccgo_ts + 17008,
	},
	52: {
		FfuncFlags: libc.Uint32FromInt32(libc.Int32FromInt32(SQLITE_FUNC_BUILTIN) | libc.Int32FromInt32(SQLITE_UTF8) | libc.Int32FromInt32(0)*libc.Int32FromInt32(SQLITE_FUNC_NEEDCOLL)),
		FzName:     __ccgo_ts + 17021,
	},
	53: {
		FfuncFlags: libc.Uint32FromInt32(libc.Int32FromInt32(SQLITE_FUNC_BUILTIN) | libc.Int32FromInt32(SQLITE_UTF8) | libc.Int32FromInt32(0)*libc.Int32FromInt32(SQLITE_FUNC_NEEDCOLL)),
		FzName:     __ccgo_ts + 17039,
	},
	54: {
		FfuncFlags: libc.Uint32FromInt32(libc.Int32FromInt32(SQLITE_FUNC_BUILTIN) | libc.Int32FromInt32(SQLITE_UTF8) | libc.Int32FromInt32(0)*libc.Int32FromInt32(SQLITE_FUNC_NEEDCOLL)),
		FzName:     __ccgo_ts + 17047,
	},
	55: {
		FnArg:      int16(3),
		FfuncFlags: libc.Uint32FromInt32(libc.Int32FromInt32(SQLITE_FUNC_BUILTIN) | libc.Int32FromInt32(SQLITE_FUNC_CONSTANT) | libc.Int32FromInt32(SQLITE_UTF8) | libc.Int32FromInt32(0)*libc.Int32FromInt32(SQLITE_FUNC_NEEDCOLL)),
		FzName:     __ccgo_ts + 17061,
	},
	56: {
		FnArg:      int16(1),
		FfuncFlags: libc.Uint32FromInt32(libc.Int32FromInt32(SQLITE_FUNC_BUILTIN) | libc.Int32FromInt32(SQLITE_FUNC_CONSTANT) | libc.Int32FromInt32(SQLITE_UTF8) | libc.Int32FromInt32(0)*libc.Int32FromInt32(SQLITE_FUNC_NEEDCOLL)),
		FzName:     __ccgo_ts + 17069,
	},
	57: {
		FnArg:      int16(2),
		FfuncFlags: libc.Uint32FromInt32(libc.Int32FromInt32(SQLITE_FUNC_BUILTIN) | libc.Int32FromInt32(SQLITE_FUNC_CONSTANT) | libc.Int32FromInt32(SQLITE_UTF8) | libc.Int32FromInt32(0)*libc.Int32FromInt32(SQLITE_FUNC_NEEDCOLL)),
		FzName:     __ccgo_ts + 17078,
	},
	58: {
		FnArg:      int16(3),
		FfuncFlags: libc.Uint32FromInt32(libc.Int32FromInt32(SQLITE_FUNC_BUILTIN) | libc.Int32FromInt32(SQLITE_FUNC_CONSTANT) | libc.Int32FromInt32(SQLITE_UTF8) | libc.Int32FromInt32(0)*libc.Int32FromInt32(SQLITE_FUNC_NEEDCOLL)),
		FzName:     __ccgo_ts + 17078,
	},
	59: {
		FnArg:      int16(2),
		FfuncFlags: libc.Uint32FromInt32(libc.Int32FromInt32(SQLITE_FUNC_BUILTIN) | libc.Int32FromInt32(SQLITE_FUNC_CONSTANT) | libc.Int32FromInt32(SQLITE_UTF8) | libc.Int32FromInt32(0)*libc.Int32FromInt32(SQLITE_FUNC_NEEDCOLL)),
		FzName:     __ccgo_ts + 17085,
	},
	60: {
		FnArg:      int16(3),
		FfuncFlags: libc.Uint32FromInt32(libc.Int32FromInt32(SQLITE_FUNC_BUILTIN) | libc.Int32FromInt32(SQLITE_FUNC_CONSTANT) | libc.Int32FromInt32(SQLITE_UTF8) | libc.Int32FromInt32(0)*libc.Int32FromInt32(SQLITE_FUNC_NEEDCOLL)),
		FzName:     __ccgo_ts + 17085,
	},
	61: {
		FnArg:      int16(1),
		FfuncFlags: libc.Uint32FromInt32(libc.Int32FromInt32(SQLITE_FUNC_BUILTIN) | libc.Int32FromInt32(SQLITE_UTF8) | libc.Int32FromInt32(0)*libc.Int32FromInt32(SQLITE_FUNC_NEEDCOLL) | libc.Int32FromInt32(0)),
		FzName:     __ccgo_ts + 17095,
	},
	62: {
		FnArg:      int16(1),
		FfuncFlags: libc.Uint32FromInt32(libc.Int32FromInt32(SQLITE_FUNC_BUILTIN) | libc.Int32FromInt32(SQLITE_UTF8) | libc.Int32FromInt32(0)*libc.Int32FromInt32(SQLITE_FUNC_NEEDCOLL) | libc.Int32FromInt32(0)),
		FzName:     __ccgo_ts + 17099,
	},
	63: {
		FnArg:      int16(1),
		FfuncFlags: libc.Uint32FromInt32(libc.Int32FromInt32(SQLITE_FUNC_BUILTIN) | libc.Int32FromInt32(SQLITE_UTF8) | libc.Int32FromInt32(0)*libc.Int32FromInt32(SQLITE_FUNC_NEEDCOLL) | libc.Int32FromInt32(0)),
		FzName:     __ccgo_ts + 17105,
	},
	64: {
		FfuncFlags: libc.Uint32FromInt32(libc.Int32FromInt32(SQLITE_FUNC_BUILTIN) | libc.Int32FromInt32(SQLITE_UTF8) | libc.Int32FromInt32(0)*libc.Int32FromInt32(SQLITE_FUNC_NEEDCOLL) | libc.Int32FromInt32(SQLITE_FUNC_COUNT) | libc.Int32FromInt32(SQLITE_FUNC_ANYORDER)),
		FzName:     __ccgo_ts + 17109,
	},
	65: {
		FnArg:      int16(1),
		FfuncFlags: libc.Uint32FromInt32(libc.Int32FromInt32(SQLITE_FUNC_BUILTIN) | libc.Int32FromInt32(SQLITE_UTF8) | libc.Int32FromInt32(0)*libc.Int32FromInt32(SQLITE_FUNC_NEEDCOLL) | libc.Int32FromInt32(SQLITE_FUNC_ANYORDER)),
		FzName:     __ccgo_ts + 17109,
	},
	66: {
		FnArg:      int16(1),
		FfuncFlags: libc.Uint32FromInt32(libc.Int32FromInt32(SQLITE_FUNC_BUILTIN) | libc.Int32FromInt32(SQLITE_UTF8) | libc.Int32FromInt32(0)*libc.Int32FromInt32(SQLITE_FUNC_NEEDCOLL) | libc.Int32FromInt32(0)),
		FzName:     __ccgo_ts + 17115,
	},
	67: {
		FnArg:      int16(2),
		FfuncFlags: libc.Uint32FromInt32(libc.Int32FromInt32(SQLITE_FUNC_BUILTIN) | libc.Int32FromInt32(SQLITE_UTF8) | libc.Int32FromInt32(0)*libc.Int32FromInt32(SQLITE_FUNC_NEEDCOLL) | libc.Int32FromInt32(0)),
		FzName:     __ccgo_ts + 17115,
	},
	68: {
		FnArg:      int16(2),
		FfuncFlags: libc.Uint32FromInt32(libc.Int32FromInt32(SQLITE_FUNC_BUILTIN) | libc.Int32FromInt32(SQLITE_UTF8) | libc.Int32FromInt32(0)*libc.Int32FromInt32(SQLITE_FUNC_NEEDCOLL) | libc.Int32FromInt32(0)),
		FzName:     __ccgo_ts + 17128,
	},
	69: {
		FnArg:      int16(2),
		FfuncFlags: libc.Uint32FromInt32(libc.Int32FromInt32(SQLITE_FUNC_BUILTIN) | libc.Int32FromInt32(SQLITE_FUNC_CONSTANT) | libc.Int32FromInt32(SQLITE_UTF8) | libc.Int32FromInt32(SQLITE_FUNC_LIKE) | libc.Int32FromInt32(SQLITE_FUNC_CASE)),
		FpUserData: uintptr(unsafe.Pointer(&_globInfo)),
		FzName:     __ccgo_ts + 17139,
	},
	70: {
		FnArg:      int16(2),
		FfuncFlags: libc.Uint32FromInt32(libc.Int32FromInt32(SQLITE_FUNC_BUILTIN) | libc.Int32FromInt32(SQLITE_FUNC_CONSTANT) | libc.Int32FromInt32(SQLITE_UTF8) | libc.Int32FromInt32(SQLITE_FUNC_LIKE)),
		FpUserData: uintptr(unsafe.Pointer(&_likeInfoNorm)),
		FzName:     __ccgo_ts + 16598,
	},
	71: {
		FnArg:      int16(3),
		FfuncFlags: libc.Uint32FromInt32(libc.Int32FromInt32(SQLITE_FUNC_BUILTIN) | libc.Int32FromInt32(SQLITE_FUNC_CONSTANT) | libc.Int32FromInt32(SQLITE_UTF8) | libc.Int32FromInt32(SQLITE_FUNC_LIKE)),
		FpUserData: uintptr(unsafe.Pointer(&_likeInfoNorm)),
		FzName:     __ccgo_ts + 16598,
	},
	72: {
		FnArg:      int16(1),
		FfuncFlags: libc.Uint32FromInt32(libc.Int32FromInt32(SQLITE_FUNC_BUILTIN) | libc.Int32FromInt32(SQLITE_FUNC_CONSTANT) | libc.Int32FromInt32(SQLITE_UTF8)),
		FzName:     __ccgo_ts + 17144,
	},
	73: {
		FnArg:      int16(1),
		FfuncFlags: libc.Uint32FromInt32(libc.Int32FromInt32(SQLITE_FUNC_BUILTIN) | libc.Int32FromInt32(SQLITE_FUNC_CONSTANT) | libc.Int32FromInt32(SQLITE_UTF8)),
		FzName:     __ccgo_ts + 1266,
	},
	74: {
		FnArg:      int16(1),
		FfuncFlags: libc.Uint32FromInt32(libc.Int32FromInt32(SQLITE_FUNC_BUILTIN) | libc.Int32FromInt32(SQLITE_FUNC_CONSTANT) | libc.Int32FromInt32(SQLITE_UTF8)),
		FzName:     __ccgo_ts + 1274,
	},
	75: {
		FnArg:      int16(1),
		FfuncFlags: libc.Uint32FromInt32(libc.Int32FromInt32(SQLITE_FUNC_BUILTIN) | libc.Int32FromInt32(SQLITE_FUNC_CONSTANT) | libc.Int32FromInt32(SQLITE_UTF8)),
		FzName:     __ccgo_ts + 17149,
	},
	76: {
		FnArg:      int16(1),
		FfuncFlags: libc.Uint32FromInt32(libc.Int32FromInt32(SQLITE_FUNC_BUILTIN) | libc.Int32FromInt32(SQLITE_FUNC_CONSTANT) | libc.Int32FromInt32(SQLITE_UTF8) | libc.Int32FromInt32(0)*libc.Int32FromInt32(SQLITE_FUNC_NEEDCOLL)),
		FzName:     __ccgo_ts + 17155,
	},
	77: {
		FnArg:      int16(1),
		FfuncFlags: libc.Uint32FromInt32(libc.Int32FromInt32(SQLITE_FUNC_BUILTIN) | libc.Int32FromInt32(SQLITE_FUNC_CONSTANT) | libc.Int32FromInt32(SQLITE_UTF8) | libc.Int32FromInt32(0)*libc.Int32FromInt32(SQLITE_FUNC_NEEDCOLL)),
		FpUserData: uintptr(int64(libc.Int32FromInt32(1))),
		FzName:     __ccgo_ts + 17158,
	},
	78: {
		FnArg:      int16(1),
		FfuncFlags: libc.Uint32FromInt32(libc.Int32FromInt32(SQLITE_FUNC_BUILTIN) | libc.Int32FromInt32(SQLITE_FUNC_CONSTANT) | libc.Int32FromInt32(SQLITE_UTF8) | libc.Int32FromInt32(0)*libc.Int32FromInt32(SQLITE_FUNC_NEEDCOLL)),
		FpUserData: uintptr(int64(libc.Int32FromInt32(1))),
		FzName:     __ccgo_ts + 17162,
	},
	79: {
		FnArg:      int16(1),
		FfuncFlags: libc.Uint32FromInt32(libc.Int32FromInt32(SQLITE_FUNC_BUILTIN) | libc.Int32FromInt32(SQLITE_FUNC_CONSTANT) | libc.Int32FromInt32(SQLITE_UTF8) | libc.Int32FromInt32(0)*libc.Int32FromInt32(SQLITE_FUNC_NEEDCOLL)),
		FpUserData: uintptr(int64(libc.Int32FromInt32(2))),
		FzName:     __ccgo_ts + 17168,
	},
	80: {
		FnArg:      int16(2),
		FfuncFlags: libc.Uint32FromInt32(libc.Int32FromInt32(SQLITE_FUNC_BUILTIN) | libc.Int32FromInt32(SQLITE_FUNC_CONSTANT) | libc.Int32FromInt32(SQLITE_UTF8) | libc.Int32FromInt32(0)*libc.Int32FromInt32(SQLITE_FUNC_NEEDCOLL)),
		FzName:     __ccgo_ts + 17158,
	},
	81: {
		FnArg:      int16(1),
		FfuncFlags: libc.Uint32FromInt32(libc.Int32FromInt32(SQLITE_FUNC_BUILTIN) | libc.Int32FromInt32(SQLITE_FUNC_CONSTANT) | libc.Int32FromInt32(SQLITE_UTF8)),
		FzName:     __ccgo_ts + 17173,
	},
	82: {
		FnArg:      int16(2),
		FfuncFlags: libc.Uint32FromInt32(libc.Int32FromInt32(SQLITE_FUNC_BUILTIN) | libc.Int32FromInt32(SQLITE_FUNC_CONSTANT) | libc.Int32FromInt32(SQLITE_UTF8)),
		FzName:     __ccgo_ts + 17177,
	},
	83: {
		FnArg:      int16(2),
		FfuncFlags: libc.Uint32FromInt32(libc.Int32FromInt32(SQLITE_FUNC_BUILTIN) | libc.Int32FromInt32(SQLITE_FUNC_CONSTANT) | libc.Int32FromInt32(SQLITE_UTF8)),
		FzName:     __ccgo_ts + 17181,
	},
	84: {
		FnArg:      int16(2),
		FfuncFlags: libc.Uint32FromInt32(libc.Int32FromInt32(SQLITE_FUNC_BUILTIN) | libc.Int32FromInt32(SQLITE_FUNC_CONSTANT) | libc.Int32FromInt32(SQLITE_UTF8)),
		FzName:     __ccgo_ts + 17187,
	},
	85: {
		FnArg:      int16(1),
		FfuncFlags: libc.Uint32FromInt32(libc.Int32FromInt32(SQLITE_FUNC_BUILTIN) | libc.Int32FromInt32(SQLITE_FUNC_CONSTANT) | libc.Int32FromInt32(SQLITE_UTF8)),
		FzName:     __ccgo_ts + 17191,
	},
	86: {
		FnArg:      int16(1),
		FfuncFlags: libc.Uint32FromInt32(libc.Int32FromInt32(SQLITE_FUNC_BUILTIN) | libc.Int32FromInt32(SQLITE_FUNC_CONSTANT) | libc.Int32FromInt32(SQLITE_UTF8)),
		FzName:     __ccgo_ts + 17196,
	},
	87: {
		FnArg:      int16(1),
		FfuncFlags: libc.Uint32FromInt32(libc.Int32FromInt32(SQLITE_FUNC_BUILTIN) | libc.Int32FromInt32(SQLITE_FUNC_CONSTANT) | libc.Int32FromInt32(SQLITE_UTF8)),
		FzName:     __ccgo_ts + 17201,
	},
	88: {
		FnArg:      int16(2),
		FfuncFlags: libc.Uint32FromInt32(libc.Int32FromInt32(SQLITE_FUNC_BUILTIN) | libc.Int32FromInt32(SQLITE_FUNC_CONSTANT) | libc.Int32FromInt32(SQLITE_UTF8)),
		FzName:     __ccgo_ts + 17206,
	},
	89: {
		FnArg:      int16(1),
		FfuncFlags: libc.Uint32FromInt32(libc.Int32FromInt32(SQLITE_FUNC_BUILTIN) | libc.Int32FromInt32(SQLITE_FUNC_CONSTANT) | libc.Int32FromInt32(SQLITE_UTF8)),
		FzName:     __ccgo_ts + 17212,
	},
	90: {
		FnArg:      int16(1),
		FfuncFlags: libc.Uint32FromInt32(libc.Int32FromInt32(SQLITE_FUNC_BUILTIN) | libc.Int32FromInt32(SQLITE_FUNC_CONSTANT) | libc.Int32FromInt32(SQLITE_UTF8)),
		FzName:     __ccgo_ts + 17216,
	},
	91: {
		FnArg:      int16(1),
		FfuncFlags: libc.Uint32FromInt32(libc.Int32FromInt32(SQLITE_FUNC_BUILTIN) | libc.Int32FromInt32(SQLITE_FUNC_CONSTANT) | libc.Int32FromInt32(SQLITE_UTF8)),
		FzName:     __ccgo_ts + 17220,
	},
	92: {
		FnArg:      int16(1),
		FfuncFlags: libc.Uint32FromInt32(libc.Int32FromInt32(SQLITE_FUNC_BUILTIN) | libc.Int32FromInt32(SQLITE_FUNC_CONSTANT) | libc.Int32FromInt32(SQLITE_UTF8)),
		FzName:     __ccgo_ts + 17224,
	},
	93: {
		FnArg:      int16(1),
		FfuncFlags: libc.Uint32FromInt32(libc.Int32FromInt32(SQLITE_FUNC_BUILTIN) | libc.Int32FromInt32(SQLITE_FUNC_CONSTANT) | libc.Int32FromInt32(SQLITE_UTF8)),
		FzName:     __ccgo_ts + 17229,
	},
	94: {
		FnArg:      int16(1),
		FfuncFlags: libc.Uint32FromInt32(libc.Int32FromInt32(SQLITE_FUNC_BUILTIN) | libc.Int32FromInt32(SQLITE_FUNC_CONSTANT) | libc.Int32FromInt32(SQLITE_UTF8)),
		FzName:     __ccgo_ts + 17234,
	},
	95: {
		FnArg:      int16(1),
		FfuncFlags: libc.Uint32FromInt32(libc.Int32FromInt32(SQLITE_FUNC_BUILTIN) | libc.Int32FromInt32(SQLITE_FUNC_CONSTANT) | libc.Int32FromInt32(SQLITE_UTF8)),
		FzName:     __ccgo_ts + 17239,
	},
	96: {
		FnArg:      int16(1),
		FfuncFlags: libc.Uint32FromInt32(libc.Int32FromInt32(SQLITE_FUNC_BUILTIN) | libc.Int32FromInt32(SQLITE_FUNC_CONSTANT) | libc.Int32FromInt32(SQLITE_UTF8)),
		FzName:     __ccgo_ts + 17245,
	},
	97: {
		FnArg:      int16(1),
		FfuncFlags: libc.Uint32FromInt32(libc.Int32FromInt32(SQLITE_FUNC_BUILTIN) | libc.Int32FromInt32(SQLITE_FUNC_CONSTANT) | libc.Int32FromInt32(SQLITE_UTF8)),
		FzName:     __ccgo_ts + 17251,
	},
	98: {
		FnArg:      int16(1),
		FfuncFlags: libc.Uint32FromInt32(libc.Int32FromInt32(SQLITE_FUNC_BUILTIN) | libc.Int32FromInt32(SQLITE_FUNC_CONSTANT) | libc.Int32FromInt32(SQLITE_UTF8)),
		FzName:     __ccgo_ts + 17257,
	},
	99: {
		FnArg:      int16(1),
		FfuncFlags: libc.Uint32FromInt32(libc.Int32FromInt32(SQLITE_FUNC_BUILTIN) | libc.Int32FromInt32(SQLITE_FUNC_CONSTANT) | libc.Int32FromInt32(SQLITE_UTF8)),
		FzName:     __ccgo_ts + 17262,
	},
	100: {
		FnArg:      int16(1),
		FfuncFlags: libc.Uint32FromInt32(libc.Int32FromInt32(SQLITE_FUNC_BUILTIN) | libc.Int32FromInt32(SQLITE_FUNC_CONSTANT) | libc.Int32FromInt32(SQLITE_UTF8)),
		FzName:     __ccgo_ts + 17270,
	},
	101: {
		FfuncFlags: libc.Uint32FromInt32(libc.Int32FromInt32(SQLITE_FUNC_BUILTIN) | libc.Int32FromInt32(SQLITE_FUNC_CONSTANT) | libc.Int32FromInt32(SQLITE_UTF8)),
		FzName:     __ccgo_ts + 17278,
	},
	102: {
		FnArg:      int16(1),
		FfuncFlags: libc.Uint32FromInt32(libc.Int32FromInt32(SQLITE_FUNC_BUILTIN) | libc.Int32FromInt32(SQLITE_FUNC_CONSTANT) | libc.Int32FromInt32(SQLITE_UTF8) | libc.Int32FromInt32(0)*libc.Int32FromInt32(SQLITE_FUNC_NEEDCOLL)),
		FzName:     __ccgo_ts + 17281,
	},
	103: {
		FnArg:      int16(-int32(4)),
		FfuncFlags: libc.Uint32FromInt32(libc.Int32FromInt32(SQLITE_FUNC_BUILTIN) | libc.Int32FromInt32(SQLITE_UTF8) | libc.Int32FromInt32(SQLITE_FUNC_INLINE) | libc.Int32FromInt32(SQLITE_FUNC_CONSTANT) | libc.Int32FromInt32(0)),
		FzName:     __ccgo_ts + 6954,
	},
	104: {
		FnArg:      int16(-int32(4)),
		FfuncFlags: libc.Uint32FromInt32(libc.Int32FromInt32(SQLITE_FUNC_BUILTIN) | libc.Int32FromInt32(SQLITE_UTF8) | libc.Int32FromInt32(SQLITE_FUNC_INLINE) | libc.Int32FromInt32(SQLITE_FUNC_CONSTANT) | libc.Int32FromInt32(0)),
		FpUserData: uintptr(int64(libc.Int32FromInt32(INLINEFUNC_iif))),
		FzName:     __ccgo_ts + 17286,
	},
	105: {
		FnArg:      int16(-int32(4)),
		FfuncFlags: libc.Uint32FromInt32(libc.Int32FromInt32(SQLITE_FUNC_BUILTIN) | libc.Int32FromInt32(SQLITE_UTF8) | libc.Int32FromInt32(SQLITE_FUNC_INLINE) | libc.Int32FromInt32(SQLITE_FUNC_CONSTANT) | libc.Int32FromInt32(0)),
		FpUserData: uintptr(int64(libc.Int32FromInt32(INLINEFUNC_iif))),
		FzName:     __ccgo_ts + 17290,
	},
}

var _aCacheMode = [3]struct {
	Fz    uintptr
	Fmode int32
}{
	0: {
		Fz:    __ccgo_ts + 26161,
		Fmode: int32(SQLITE_OPEN_SHAREDCACHE),
	},
	1: {
		Fz:    __ccgo_ts + 26168,
		Fmode: int32(SQLITE_OPEN_PRIVATECACHE),
	},
	2: {},
}

var _aDateTimeFuncs = [10]TFuncDef{
	0: {
		FnArg:      int16(-int32(1)),
		FfuncFlags: libc.Uint32FromInt32(libc.Int32FromInt32(SQLITE_FUNC_BUILTIN) | libc.Int32FromInt32(SQLITE_FUNC_SLOCHNG) | libc.Int32FromInt32(SQLITE_UTF8) | libc.Int32FromInt32(SQLITE_FUNC_CONSTANT)),
		FpUserData: uintptr(unsafe.Pointer(&_sqlite3Config)),
		FzName:     __ccgo_ts + 1280,
	},
	1: {
		FnArg:      int16(-int32(1)),
		FfuncFlags: libc.Uint32FromInt32(libc.Int32FromInt32(SQLITE_FUNC_BUILTIN) | libc.Int32FromInt32(SQLITE_FUNC_SLOCHNG) | libc.Int32FromInt32(SQLITE_UTF8) | libc.Int32FromInt32(SQLITE_FUNC_CONSTANT)),
		FpUserData: uintptr(unsafe.Pointer(&_sqlite3Config)),
		FzName:     __ccgo_ts + 1300,
	},
	2: {
		FnArg:      int16(-int32(1)),
		FfuncFlags: libc.Uint32FromInt32(libc.Int32FromInt32(SQLITE_FUNC_BUILTIN) | libc.Int32FromInt32(SQLITE_FUNC_SLOCHNG) | libc.Int32FromInt32(SQLITE_UTF8) | libc.Int32FromInt32(SQLITE_FUNC_CONSTANT)),
		FpUserData: uintptr(unsafe.Pointer(&_sqlite3Config)),
		FzName:     __ccgo_ts + 1508,
	},
	3: {
		FnArg:      int16(-int32(1)),
		FfuncFlags: libc.Uint32FromInt32(libc.Int32FromInt32(SQLITE_FUNC_BUILTIN) | libc.Int32FromInt32(SQLITE_FUNC_SLOCHNG) | libc.Int32FromInt32(SQLITE_UTF8) | libc.Int32FromInt32(SQLITE_FUNC_CONSTANT)),
		FpUserData: uintptr(unsafe.Pointer(&_sqlite3Config)),
		FzName:     __ccgo_ts + 1513,
	},
	4: {
		FnArg:      int16(-int32(1)),
		FfuncFlags: libc.Uint32FromInt32(libc.Int32FromInt32(SQLITE_FUNC_BUILTIN) | libc.Int32FromInt32(SQLITE_FUNC_SLOCHNG) | libc.Int32FromInt32(SQLITE_UTF8) | libc.Int32FromInt32(SQLITE_FUNC_CONSTANT)),
		FpUserData: uintptr(unsafe.Pointer(&_sqlite3Config)),
		FzName:     __ccgo_ts + 1518,
	},
	5: {
		FnArg:      int16(-int32(1)),
		FfuncFlags: libc.Uint32FromInt32(libc.Int32FromInt32(SQLITE_FUNC_BUILTIN) | libc.Int32FromInt32(SQLITE_FUNC_SLOCHNG) | libc.Int32FromInt32(SQLITE_UTF8) | libc.Int32FromInt32(SQLITE_FUNC_CONSTANT)),
		FpUserData: uintptr(unsafe.Pointer(&_sqlite3Config)),
		FzName:     __ccgo_ts + 1527,
	},
	6: {
		FnArg:      int16(2),
		FfuncFlags: libc.Uint32FromInt32(libc.Int32FromInt32(SQLITE_FUNC_BUILTIN) | libc.Int32FromInt32(SQLITE_FUNC_SLOCHNG) | libc.Int32FromInt32(SQLITE_UTF8) | libc.Int32FromInt32(SQLITE_FUNC_CONSTANT)),
		FpUserData: uintptr(unsafe.Pointer(&_sqlite3Config)),
		FzName:     __ccgo_ts + 1536,
	},
	7: {
		FfuncFlags: libc.Uint32FromInt32(libc.Int32FromInt32(SQLITE_FUNC_BUILTIN) | libc.Int32FromInt32(SQLITE_FUNC_SLOCHNG) | libc.Int32FromInt32(SQLITE_UTF8)),
		FzName:     __ccgo_ts + 1545,
	},
	8: {
		FfuncFlags: libc.Uint32FromInt32(libc.Int32FromInt32(SQLITE_FUNC_BUILTIN) | libc.Int32FromInt32(SQLITE_FUNC_SLOCHNG) | libc.Int32FromInt32(SQLITE_UTF8)),
		FzName:     __ccgo_ts + 1558,
	},
	9: {
		FfuncFlags: libc.Uint32FromInt32(libc.Int32FromInt32(SQLITE_FUNC_BUILTIN) | libc.Int32FromInt32(SQLITE_FUNC_SLOCHNG) | libc.Int32FromInt32(SQLITE_UTF8)),
		FzName:     __ccgo_ts + 1576,
	},
}

var _aFunc = [12]struct {
	FxFunc uintptr
	FnArg  int8
	FbPure uint8
	FzName uintptr
}{
	0: {
		FnArg:  int8(1),
		FbPure: uint8(1),
		FzName: __ccgo_ts + 30048,
	},
	1: {
		FnArg:  int8(1),
		FbPure: uint8(1),
		FzName: __ccgo_ts + 30061,
	},
	2: {
		FnArg:  int8(1),
		FbPure: uint8(1),
		FzName: __ccgo_ts + 30074,
	},
	3: {
		FnArg:  int8(-int32(1)),
		FbPure: uint8(1),
		FzName: __ccgo_ts + 30087,
	},
	4: {
		FnArg:  int8(2),
		FbPure: uint8(1),
		FzName: __ccgo_ts + 30033,
	},
	5: {
		FnArg:  int8(3),
		FbPure: uint8(1),
		FzName: __ccgo_ts + 30099,
	},
	6: {
		FnArg:  int8(2),
		FbPure: uint8(1),
		FzName: __ccgo_ts + 30017,
	},
	7: {
		FnArg:  int8(1),
		FzName: __ccgo_ts + 30122,
	},
	8: {
		FnArg:  int8(1),
		FbPure: uint8(1),
		FzName: __ccgo_ts + 30136,
	},
	9: {
		FnArg:  int8(7),
		FbPure: uint8(1),
		FzName: __ccgo_ts + 30149,
	},
	10: {
		FnArg:  int8(4),
		FbPure: uint8(1),
		FzName: __ccgo_ts + 30163,
	},
	11: {
		FnArg:  int8(1),
		FbPure: uint8(1),
		FzName: __ccgo_ts + 30179,
	},
}

var _aJsonFunc = [36]TFuncDef{
	0: {
		FnArg:      int16(1),
		FfuncFlags: libc.Uint32FromInt32(libc.Int32FromInt32(SQLITE_FUNC_BUILTIN) | libc.Int32FromInt32(SQLITE_DETERMINISTIC) | libc.Int32FromInt32(SQLITE_FUNC_CONSTANT) | libc.Int32FromInt32(SQLITE_UTF8) | libc.Int32FromInt32(1)*libc.Int32FromInt32(SQLITE_FUNC_RUNONLY) | libc.Int32FromInt32(0)*libc.Int32FromInt32(SQLITE_SUBTYPE) | libc.Int32FromInt32(1)*libc.Int32FromInt32(SQLITE_RESULT_SUBTYPE)),
		FzName:     __ccgo_ts + 13687,
	},
	1: {
		FnArg:      int16(1),
		FfuncFlags: libc.Uint32FromInt32(libc.Int32FromInt32(SQLITE_FUNC_BUILTIN) | libc.Int32FromInt32(SQLITE_DETERMINISTIC) | libc.Int32FromInt32(SQLITE_FUNC_CONSTANT) | libc.Int32FromInt32(SQLITE_UTF8) | libc.Int32FromInt32(1)*libc.Int32FromInt32(SQLITE_FUNC_RUNONLY) | libc.Int32FromInt32(0)*libc.Int32FromInt32(SQLITE_SUBTYPE) | libc.Int32FromInt32(0)*libc.Int32FromInt32(SQLITE_RESULT_SUBTYPE)),
		FpUserData: uintptr(int64(libc.Int32FromInt32(0) | libc.Int32FromInt32(1)*libc.Int32FromInt32(JSON_BLOB))),
		FzName:     __ccgo_ts + 26957,
	},
	2: {
		FnArg:      int16(-int32(1)),
		FfuncFlags: libc.Uint32FromInt32(libc.Int32FromInt32(SQLITE_FUNC_BUILTIN) | libc.Int32FromInt32(SQLITE_DETERMINISTIC) | libc.Int32FromInt32(SQLITE_FUNC_CONSTANT) | libc.Int32FromInt32(SQLITE_UTF8) | libc.Int32FromInt32(0)*libc.Int32FromInt32(SQLITE_FUNC_RUNONLY) | libc.Int32FromInt32(1)*libc.Int32FromInt32(SQLITE_SUBTYPE) | libc.Int32FromInt32(1)*libc.Int32FromInt32(SQLITE_RESULT_SUBTYPE)),
		FzName:     __ccgo_ts + 26963,
	},
	3: {
		FnArg:      int16(-int32(1)),
		FfuncFlags: libc.Uint32FromInt32(libc.Int32FromInt32(SQLITE_FUNC_BUILTIN) | libc.Int32FromInt32(SQLITE_DETERMINISTIC) | libc.Int32FromInt32(SQLITE_FUNC_CONSTANT) | libc.Int32FromInt32(SQLITE_UTF8) | libc.Int32FromInt32(0)*libc.Int32FromInt32(SQLITE_FUNC_RUNONLY) | libc.Int32FromInt32(1)*libc.Int32FromInt32(SQLITE_SUBTYPE) | libc.Int32FromInt32(1)*libc.Int32FromInt32(SQLITE_RESULT_SUBTYPE)),
		FpUserData: uintptr(int64(libc.Int32FromInt32(0) | libc.Int32FromInt32(1)*libc.Int32FromInt32(JSON_BLOB))),
		FzName:     __ccgo_ts + 26974,
	},
	4: {
		FnArg:      int16(-int32(1)),
		FfuncFlags: libc.Uint32FromInt32(libc.Int32FromInt32(SQLITE_FUNC_BUILTIN) | libc.Int32FromInt32(SQLITE_DETERMINISTIC) | libc.Int32FromInt32(SQLITE_FUNC_CONSTANT) | libc.Int32FromInt32(SQLITE_UTF8) | libc.Int32FromInt32(1)*libc.Int32FromInt32(SQLITE_FUNC_RUNONLY) | libc.Int32FromInt32(1)*libc.Int32FromInt32(SQLITE_SUBTYPE) | libc.Int32FromInt32(1)*libc.Int32FromInt32(SQLITE_RESULT_SUBTYPE)),
		FpUserData: uintptr(int64(libc.Int32FromInt32(JSON_AINS) | libc.Int32FromInt32(0)*libc.Int32FromInt32(JSON_BLOB))),
		FzName:     __ccgo_ts + 26986,
	},
	5: {
		FnArg:      int16(-int32(1)),
		FfuncFlags: libc.Uint32FromInt32(libc.Int32FromInt32(SQLITE_FUNC_BUILTIN) | libc.Int32FromInt32(SQLITE_DETERMINISTIC) | libc.Int32FromInt32(SQLITE_FUNC_CONSTANT) | libc.Int32FromInt32(SQLITE_UTF8) | libc.Int32FromInt32(1)*libc.Int32FromInt32(SQLITE_FUNC_RUNONLY) | libc.Int32FromInt32(1)*libc.Int32FromInt32(SQLITE_SUBTYPE) | libc.Int32FromInt32(0)*libc.Int32FromInt32(SQLITE_RESULT_SUBTYPE)),
		FpUserData: uintptr(int64(libc.Int32FromInt32(JSON_AINS) | libc.Int32FromInt32(1)*libc.Int32FromInt32(JSON_BLOB))),
		FzName:     __ccgo_ts + 27004,
	},
	6: {
		FnArg:      int16(1),
		FfuncFlags: libc.Uint32FromInt32(libc.Int32FromInt32(SQLITE_FUNC_BUILTIN) | libc.Int32FromInt32(SQLITE_DETERMINISTIC) | libc.Int32FromInt32(SQLITE_FUNC_CONSTANT) | libc.Int32FromInt32(SQLITE_UTF8) | libc.Int32FromInt32(1)*libc.Int32FromInt32(SQLITE_FUNC_RUNONLY) | libc.Int32FromInt32(0)*libc.Int32FromInt32(SQLITE_SUBTYPE) | libc.Int32FromInt32(0)*libc.Int32FromInt32(SQLITE_RESULT_SUBTYPE)),
		FzName:     __ccgo_ts + 27023,
	},
	7: {
		FnArg:      int16(2),
		FfuncFlags: libc.Uint32FromInt32(libc.Int32FromInt32(SQLITE_FUNC_BUILTIN) | libc.Int32FromInt32(SQLITE_DETERMINISTIC) | libc.Int32FromInt32(SQLITE_FUNC_CONSTANT) | libc.Int32FromInt32(SQLITE_UTF8) | libc.Int32FromInt32(1)*libc.Int32FromInt32(SQLITE_FUNC_RUNONLY) | libc.Int32FromInt32(0)*libc.Int32FromInt32(SQLITE_SUBTYPE) | libc.Int32FromInt32(0)*libc.Int32FromInt32(SQLITE_RESULT_SUBTYPE)),
		FzName:     __ccgo_ts + 27023,
	},
	8: {
		FnArg:      int16(1),
		FfuncFlags: libc.Uint32FromInt32(libc.Int32FromInt32(SQLITE_FUNC_BUILTIN) | libc.Int32FromInt32(SQLITE_DETERMINISTIC) | libc.Int32FromInt32(SQLITE_FUNC_CONSTANT) | libc.Int32FromInt32(SQLITE_UTF8) | libc.Int32FromInt32(1)*libc.Int32FromInt32(SQLITE_FUNC_RUNONLY) | libc.Int32FromInt32(0)*libc.Int32FromInt32(SQLITE_SUBTYPE) | libc.Int32FromInt32(0)*libc.Int32FromInt32(SQLITE_RESULT_SUBTYPE)),
		FzName:     __ccgo_ts + 27041,
	},
	9: {
		FnArg:      int16(-int32(1)),
		FfuncFlags: libc.Uint32FromInt32(libc.Int32FromInt32(SQLITE_FUNC_BUILTIN) | libc.Int32FromInt32(SQLITE_DETERMINISTIC) | libc.Int32FromInt32(SQLITE_FUNC_CONSTANT) | libc.Int32FromInt32(SQLITE_UTF8) | libc.Int32FromInt32(1)*libc.Int32FromInt32(SQLITE_FUNC_RUNONLY) | libc.Int32FromInt32(0)*libc.Int32FromInt32(SQLITE_SUBTYPE) | libc.Int32FromInt32(1)*libc.Int32FromInt32(SQLITE_RESULT_SUBTYPE)),
		FzName:     __ccgo_ts + 27061,
	},
	10: {
		FnArg:      int16(-int32(1)),
		FfuncFlags: libc.Uint32FromInt32(libc.Int32FromInt32(SQLITE_FUNC_BUILTIN) | libc.Int32FromInt32(SQLITE_DETERMINISTIC) | libc.Int32FromInt32(SQLITE_FUNC_CONSTANT) | libc.Int32FromInt32(SQLITE_UTF8) | libc.Int32FromInt32(1)*libc.Int32FromInt32(SQLITE_FUNC_RUNONLY) | libc.Int32FromInt32(0)*libc.Int32FromInt32(SQLITE_SUBTYPE) | libc.Int32FromInt32(0)*libc.Int32FromInt32(SQLITE_RESULT_SUBTYPE)),
		FpUserData: uintptr(int64(libc.Int32FromInt32(0) | libc.Int32FromInt32(1)*libc.Int32FromInt32(JSON_BLOB))),
		FzName:     __ccgo_ts + 27074,
	},
	11: {
		FnArg:      int16(2),
		FfuncFlags: libc.Uint32FromInt32(libc.Int32FromInt32(SQLITE_FUNC_BUILTIN) | libc.Int32FromInt32(SQLITE_DETERMINISTIC) | libc.Int32FromInt32(SQLITE_FUNC_CONSTANT) | libc.Int32FromInt32(SQLITE_UTF8) | libc.Int32FromInt32(1)*libc.Int32FromInt32(SQLITE_FUNC_RUNONLY) | libc.Int32FromInt32(0)*libc.Int32FromInt32(SQLITE_SUBTYPE) | libc.Int32FromInt32(1)*libc.Int32FromInt32(SQLITE_RESULT_SUBTYPE)),
		FpUserData: uintptr(int64(libc.Int32FromInt32(JSON_JSON) | libc.Int32FromInt32(0)*libc.Int32FromInt32(JSON_BLOB))),
		FzName:     __ccgo_ts + 27088,
	},
	12: {
		FnArg:      int16(2),
		FfuncFlags: libc.Uint32FromInt32(libc.Int32FromInt32(SQLITE_FUNC_BUILTIN) | libc.Int32FromInt32(SQLITE_DETERMINISTIC) | libc.Int32FromInt32(SQLITE_FUNC_CONSTANT) | libc.Int32FromInt32(SQLITE_UTF8) | libc.Int32FromInt32(1)*libc.Int32FromInt32(SQLITE_FUNC_RUNONLY) | libc.Int32FromInt32(0)*libc.Int32FromInt32(SQLITE_SUBTYPE) | libc.Int32FromInt32(0)*libc.Int32FromInt32(SQLITE_RESULT_SUBTYPE)),
		FpUserData: uintptr(int64(libc.Int32FromInt32(JSON_SQL) | libc.Int32FromInt32(0)*libc.Int32FromInt32(JSON_BLOB))),
		FzName:     __ccgo_ts + 27091,
	},
	13: {
		FnArg:      int16(-int32(1)),
		FfuncFlags: libc.Uint32FromInt32(libc.Int32FromInt32(SQLITE_FUNC_BUILTIN) | libc.Int32FromInt32(SQLITE_DETERMINISTIC) | libc.Int32FromInt32(SQLITE_FUNC_CONSTANT) | libc.Int32FromInt32(SQLITE_UTF8) | libc.Int32FromInt32(1)*libc.Int32FromInt32(SQLITE_FUNC_RUNONLY) | libc.Int32FromInt32(1)*libc.Int32FromInt32(SQLITE_SUBTYPE) | libc.Int32FromInt32(1)*libc.Int32FromInt32(SQLITE_RESULT_SUBTYPE)),
		FzName:     __ccgo_ts + 27095,
	},
	14: {
		FnArg:      int16(-int32(1)),
		FfuncFlags: libc.Uint32FromInt32(libc.Int32FromInt32(SQLITE_FUNC_BUILTIN) | libc.Int32FromInt32(SQLITE_DETERMINISTIC) | libc.Int32FromInt32(SQLITE_FUNC_CONSTANT) | libc.Int32FromInt32(SQLITE_UTF8) | libc.Int32FromInt32(1)*libc.Int32FromInt32(SQLITE_FUNC_RUNONLY) | libc.Int32FromInt32(1)*libc.Int32FromInt32(SQLITE_SUBTYPE) | libc.Int32FromInt32(0)*libc.Int32FromInt32(SQLITE_RESULT_SUBTYPE)),
		FpUserData: uintptr(int64(libc.Int32FromInt32(0) | libc.Int32FromInt32(1)*libc.Int32FromInt32(JSON_BLOB))),
		FzName:     __ccgo_ts + 27107,
	},
	15: {
		FnArg:      int16(-int32(1)),
		FfuncFlags: libc.Uint32FromInt32(libc.Int32FromInt32(SQLITE_FUNC_BUILTIN) | libc.Int32FromInt32(SQLITE_DETERMINISTIC) | libc.Int32FromInt32(SQLITE_FUNC_CONSTANT) | libc.Int32FromInt32(SQLITE_UTF8) | libc.Int32FromInt32(0)*libc.Int32FromInt32(SQLITE_FUNC_RUNONLY) | libc.Int32FromInt32(1)*libc.Int32FromInt32(SQLITE_SUBTYPE) | libc.Int32FromInt32(1)*libc.Int32FromInt32(SQLITE_RESULT_SUBTYPE)),
		FzName:     __ccgo_ts + 27120,
	},
	16: {
		FnArg:      int16(-int32(1)),
		FfuncFlags: libc.Uint32FromInt32(libc.Int32FromInt32(SQLITE_FUNC_BUILTIN) | libc.Int32FromInt32(SQLITE_DETERMINISTIC) | libc.Int32FromInt32(SQLITE_FUNC_CONSTANT) | libc.Int32FromInt32(SQLITE_UTF8) | libc.Int32FromInt32(0)*libc.Int32FromInt32(SQLITE_FUNC_RUNONLY) | libc.Int32FromInt32(1)*libc.Int32FromInt32(SQLITE_SUBTYPE) | libc.Int32FromInt32(1)*libc.Int32FromInt32(SQLITE_RESULT_SUBTYPE)),
		FpUserData: uintptr(int64(libc.Int32FromInt32(0) | libc.Int32FromInt32(1)*libc.Int32FromInt32(JSON_BLOB))),
		FzName:     __ccgo_ts + 27132,
	},
	17: {
		FnArg:      int16(2),
		FfuncFlags: libc.Uint32FromInt32(libc.Int32FromInt32(SQLITE_FUNC_BUILTIN) | libc.Int32FromInt32(SQLITE_DETERMINISTIC) | libc.Int32FromInt32(SQLITE_FUNC_CONSTANT) | libc.Int32FromInt32(SQLITE_UTF8) | libc.Int32FromInt32(1)*libc.Int32FromInt32(SQLITE_FUNC_RUNONLY) | libc.Int32FromInt32(0)*libc.Int32FromInt32(SQLITE_SUBTYPE) | libc.Int32FromInt32(1)*libc.Int32FromInt32(SQLITE_RESULT_SUBTYPE)),
		FzName:     __ccgo_ts + 27145,
	},
	18: {
		FnArg:      int16(2),
		FfuncFlags: libc.Uint32FromInt32(libc.Int32FromInt32(SQLITE_FUNC_BUILTIN) | libc.Int32FromInt32(SQLITE_DETERMINISTIC) | libc.Int32FromInt32(SQLITE_FUNC_CONSTANT) | libc.Int32FromInt32(SQLITE_UTF8) | libc.Int32FromInt32(1)*libc.Int32FromInt32(SQLITE_FUNC_RUNONLY) | libc.Int32FromInt32(0)*libc.Int32FromInt32(SQLITE_SUBTYPE) | libc.Int32FromInt32(0)*libc.Int32FromInt32(SQLITE_RESULT_SUBTYPE)),
		FpUserData: uintptr(int64(libc.Int32FromInt32(0) | libc.Int32FromInt32(1)*libc.Int32FromInt32(JSON_BLOB))),
		FzName:     __ccgo_ts + 27156,
	},
	19: {
		FnArg:      int16(1),
		FfuncFlags: libc.Uint32FromInt32(libc.Int32FromInt32(SQLITE_FUNC_BUILTIN) | libc.Int32FromInt32(SQLITE_DETERMINISTIC) | libc.Int32FromInt32(SQLITE_FUNC_CONSTANT) | libc.Int32FromInt32(SQLITE_UTF8) | libc.Int32FromInt32(1)*libc.Int32FromInt32(SQLITE_FUNC_RUNONLY) | libc.Int32FromInt32(0)*libc.Int32FromInt32(SQLITE_SUBTYPE) | libc.Int32FromInt32(0)*libc.Int32FromInt32(SQLITE_RESULT_SUBTYPE)),
		FzName:     __ccgo_ts + 27168,
	},
	20: {
		FnArg:      int16(2),
		FfuncFlags: libc.Uint32FromInt32(libc.Int32FromInt32(SQLITE_FUNC_BUILTIN) | libc.Int32FromInt32(SQLITE_DETERMINISTIC) | libc.Int32FromInt32(SQLITE_FUNC_CONSTANT) | libc.Int32FromInt32(SQLITE_UTF8) | libc.Int32FromInt32(1)*libc.Int32FromInt32(SQLITE_FUNC_RUNONLY) | libc.Int32FromInt32(0)*libc.Int32FromInt32(SQLITE_SUBTYPE) | libc.Int32FromInt32(0)*libc.Int32FromInt32(SQLITE_RESULT_SUBTYPE)),
		FzName:     __ccgo_ts + 27168,
	},
	21: {
		FnArg:      int16(1),
		FfuncFlags: libc.Uint32FromInt32(libc.Int32FromInt32(SQLITE_FUNC_BUILTIN) | libc.Int32FromInt32(SQLITE_DETERMINISTIC) | libc.Int32FromInt32(SQLITE_FUNC_CONSTANT) | libc.Int32FromInt32(SQLITE_UTF8) | libc.Int32FromInt32(0)*libc.Int32FromInt32(SQLITE_FUNC_RUNONLY) | libc.Int32FromInt32(1)*libc.Int32FromInt32(SQLITE_SUBTYPE) | libc.Int32FromInt32(1)*libc.Int32FromInt32(SQLITE_RESULT_SUBTYPE)),
		FzName:     __ccgo_ts + 27180,
	},
	22: {
		FnArg:      int16(-int32(1)),
		FfuncFlags: libc.Uint32FromInt32(libc.Int32FromInt32(SQLITE_FUNC_BUILTIN) | libc.Int32FromInt32(SQLITE_DETERMINISTIC) | libc.Int32FromInt32(SQLITE_FUNC_CONSTANT) | libc.Int32FromInt32(SQLITE_UTF8) | libc.Int32FromInt32(1)*libc.Int32FromInt32(SQLITE_FUNC_RUNONLY) | libc.Int32FromInt32(0)*libc.Int32FromInt32(SQLITE_SUBTYPE) | libc.Int32FromInt32(1)*libc.Int32FromInt32(SQLITE_RESULT_SUBTYPE)),
		FzName:     __ccgo_ts + 27191,
	},
	23: {
		FnArg:      int16(-int32(1)),
		FfuncFlags: libc.Uint32FromInt32(libc.Int32FromInt32(SQLITE_FUNC_BUILTIN) | libc.Int32FromInt32(SQLITE_DETERMINISTIC) | libc.Int32FromInt32(SQLITE_FUNC_CONSTANT) | libc.Int32FromInt32(SQLITE_UTF8) | libc.Int32FromInt32(1)*libc.Int32FromInt32(SQLITE_FUNC_RUNONLY) | libc.Int32FromInt32(0)*libc.Int32FromInt32(SQLITE_SUBTYPE) | libc.Int32FromInt32(0)*libc.Int32FromInt32(SQLITE_RESULT_SUBTYPE)),
		FpUserData: uintptr(int64(libc.Int32FromInt32(0) | libc.Int32FromInt32(1)*libc.Int32FromInt32(JSON_BLOB))),
		FzName:     __ccgo_ts + 27203,
	},
	24: {
		FnArg:      int16(-int32(1)),
		FfuncFlags: libc.Uint32FromInt32(libc.Int32FromInt32(SQLITE_FUNC_BUILTIN) | libc.Int32FromInt32(SQLITE_DETERMINISTIC) | libc.Int32FromInt32(SQLITE_FUNC_CONSTANT) | libc.Int32FromInt32(SQLITE_UTF8) | libc.Int32FromInt32(1)*libc.Int32FromInt32(SQLITE_FUNC_RUNONLY) | libc.Int32FromInt32(1)*libc.Int32FromInt32(SQLITE_SUBTYPE) | libc.Int32FromInt32(1)*libc.Int32FromInt32(SQLITE_RESULT_SUBTYPE)),
		FzName:     __ccgo_ts + 27216,
	},
	25: {
		FnArg:      int16(-int32(1)),
		FfuncFlags: libc.Uint32FromInt32(libc.Int32FromInt32(SQLITE_FUNC_BUILTIN) | libc.Int32FromInt32(SQLITE_DETERMINISTIC) | libc.Int32FromInt32(SQLITE_FUNC_CONSTANT) | libc.Int32FromInt32(SQLITE_UTF8) | libc.Int32FromInt32(1)*libc.Int32FromInt32(SQLITE_FUNC_RUNONLY) | libc.Int32FromInt32(1)*libc.Int32FromInt32(SQLITE_SUBTYPE) | libc.Int32FromInt32(0)*libc.Int32FromInt32(SQLITE_RESULT_SUBTYPE)),
		FpUserData: uintptr(int64(libc.Int32FromInt32(0) | libc.Int32FromInt32(1)*libc.Int32FromInt32(JSON_BLOB))),
		FzName:     __ccgo_ts + 27229,
	},
	26: {
		FnArg:      int16(-int32(1)),
		FfuncFlags: libc.Uint32FromInt32(libc.Int32FromInt32(SQLITE_FUNC_BUILTIN) | libc.Int32FromInt32(SQLITE_DETERMINISTIC) | libc.Int32FromInt32(SQLITE_FUNC_CONSTANT) | libc.Int32FromInt32(SQLITE_UTF8) | libc.Int32FromInt32(1)*libc.Int32FromInt32(SQLITE_FUNC_RUNONLY) | libc.Int32FromInt32(1)*libc.Int32FromInt32(SQLITE_SUBTYPE) | libc.Int32FromInt32(1)*libc.Int32FromInt32(SQLITE_RESULT_SUBTYPE)),
		FpUserData: uintptr(int64(libc.Int32FromInt32(JSON_ISSET) | libc.Int32FromInt32(0)*libc.Int32FromInt32(JSON_BLOB))),
		FzName:     __ccgo_ts + 27243,
	},
	27: {
		FnArg:      int16(-int32(1)),
		FfuncFlags: libc.Uint32FromInt32(libc.Int32FromInt32(SQLITE_FUNC_BUILTIN) | libc.Int32FromInt32(SQLITE_DETERMINISTIC) | libc.Int32FromInt32(SQLITE_FUNC_CONSTANT) | libc.Int32FromInt32(SQLITE_UTF8) | libc.Int32FromInt32(1)*libc.Int32FromInt32(SQLITE_FUNC_RUNONLY) | libc.Int32FromInt32(1)*libc.Int32FromInt32(SQLITE_SUBTYPE) | libc.Int32FromInt32(0)*libc.Int32FromInt32(SQLITE_RESULT_SUBTYPE)),
		FpUserData: uintptr(int64(libc.Int32FromInt32(JSON_ISSET) | libc.Int32FromInt32(1)*libc.Int32FromInt32(JSON_BLOB))),
		FzName:     __ccgo_ts + 27252,
	},
	28: {
		FnArg:      int16(1),
		FfuncFlags: libc.Uint32FromInt32(libc.Int32FromInt32(SQLITE_FUNC_BUILTIN) | libc.Int32FromInt32(SQLITE_DETERMINISTIC) | libc.Int32FromInt32(SQLITE_FUNC_CONSTANT) | libc.Int32FromInt32(SQLITE_UTF8) | libc.Int32FromInt32(1)*libc.Int32FromInt32(SQLITE_FUNC_RUNONLY) | libc.Int32FromInt32(0)*libc.Int32FromInt32(SQLITE_SUBTYPE) | libc.Int32FromInt32(0)*libc.Int32FromInt32(SQLITE_RESULT_SUBTYPE)),
		FzName:     __ccgo_ts + 27262,
	},
	29: {
		FnArg:      int16(2),
		FfuncFlags: libc.Uint32FromInt32(libc.Int32FromInt32(SQLITE_FUNC_BUILTIN) | libc.Int32FromInt32(SQLITE_DETERMINISTIC) | libc.Int32FromInt32(SQLITE_FUNC_CONSTANT) | libc.Int32FromInt32(SQLITE_UTF8) | libc.Int32FromInt32(1)*libc.Int32FromInt32(SQLITE_FUNC_RUNONLY) | libc.Int32FromInt32(0)*libc.Int32FromInt32(SQLITE_SUBTYPE) | libc.Int32FromInt32(0)*libc.Int32FromInt32(SQLITE_RESULT_SUBTYPE)),
		FzName:     __ccgo_ts + 27262,
	},
	30: {
		FnArg:      int16(1),
		FfuncFlags: libc.Uint32FromInt32(libc.Int32FromInt32(SQLITE_FUNC_BUILTIN) | libc.Int32FromInt32(SQLITE_DETERMINISTIC) | libc.Int32FromInt32(SQLITE_FUNC_CONSTANT) | libc.Int32FromInt32(SQLITE_UTF8) | libc.Int32FromInt32(1)*libc.Int32FromInt32(SQLITE_FUNC_RUNONLY) | libc.Int32FromInt32(0)*libc.Int32FromInt32(SQLITE_SUBTYPE) | libc.Int32FromInt32(0)*libc.Int32FromInt32(SQLITE_RESULT_SUBTYPE)),
		FzName:     __ccgo_ts + 27272,
	},
	31: {
		FnArg:      int16(2),
		FfuncFlags: libc.Uint32FromInt32(libc.Int32FromInt32(SQLITE_FUNC_BUILTIN) | libc.Int32FromInt32(SQLITE_DETERMINISTIC) | libc.Int32FromInt32(SQLITE_FUNC_CONSTANT) | libc.Int32FromInt32(SQLITE_UTF8) | libc.Int32FromInt32(1)*libc.Int32FromInt32(SQLITE_FUNC_RUNONLY) | libc.Int32FromInt32(0)*libc.Int32FromInt32(SQLITE_SUBTYPE) | libc.Int32FromInt32(0)*libc.Int32FromInt32(SQLITE_RESULT_SUBTYPE)),
		FzName:     __ccgo_ts + 27272,
	},
	32: {
		FnArg:      int16(1),
		FfuncFlags: libc.Uint32FromInt32(libc.Int32FromInt32(SQLITE_FUNC_BUILTIN) | libc.Int32FromInt32(SQLITE_UTF8) | libc.Int32FromInt32(0)*libc.Int32FromInt32(SQLITE_FUNC_NEEDCOLL) | libc.Int32FromInt32(SQLITE_SUBTYPE) | libc.Int32FromInt32(SQLITE_RESULT_SUBTYPE) | libc.Int32FromInt32(SQLITE_UTF8) | libc.Int32FromInt32(SQLITE_DETERMINISTIC)),
		FzName:     __ccgo_ts + 27283,
	},
	33: {
		FnArg:      int16(1),
		FfuncFlags: libc.Uint32FromInt32(libc.Int32FromInt32(SQLITE_FUNC_BUILTIN) | libc.Int32FromInt32(SQLITE_UTF8) | libc.Int32FromInt32(0)*libc.Int32FromInt32(SQLITE_FUNC_NEEDCOLL) | libc.Int32FromInt32(SQLITE_SUBTYPE) | libc.Int32FromInt32(SQLITE_RESULT_SUBTYPE) | libc.Int32FromInt32(SQLITE_UTF8) | libc.Int32FromInt32(SQLITE_DETERMINISTIC)),
		FpUserData: uintptr(int64(libc.Int32FromInt32(JSON_BLOB))),
		FzName:     __ccgo_ts + 27300,
	},
	34: {
		FnArg:      int16(2),
		FfuncFlags: libc.Uint32FromInt32(libc.Int32FromInt32(SQLITE_FUNC_BUILTIN) | libc.Int32FromInt32(SQLITE_UTF8) | libc.Int32FromInt32(0)*libc.Int32FromInt32(SQLITE_FUNC_NEEDCOLL) | libc.Int32FromInt32(SQLITE_SUBTYPE) | libc.Int32FromInt32(SQLITE_RESULT_SUBTYPE) | libc.Int32FromInt32(SQLITE_UTF8) | libc.Int32FromInt32(SQLITE_DETERMINISTIC)),
		FzName:     __ccgo_ts + 27318,
	},
	35: {
		FnArg:      int16(2),
		FfuncFlags: libc.Uint32FromInt32(libc.Int32FromInt32(SQLITE_FUNC_BUILTIN) | libc.Int32FromInt32(SQLITE_UTF8) | libc.Int32FromInt32(0)*libc.Int32FromInt32(SQLITE_FUNC_NEEDCOLL) | libc.Int32FromInt32(SQLITE_SUBTYPE) | libc.Int32FromInt32(SQLITE_RESULT_SUBTYPE) | libc.Int32FromInt32(SQLITE_UTF8) | libc.Int32FromInt32(SQLITE_DETERMINISTIC)),
		FpUserData: uintptr(int64(libc.Int32FromInt32(JSON_BLOB))),
		FzName:     __ccgo_ts + 27336,
	},
}

var _aMsg = [29]uintptr{
	0:  __ccgo_ts + 25348,
	1:  __ccgo_ts + 25361,
	3:  __ccgo_ts + 25377,
	4:  __ccgo_ts + 25402,
	5:  __ccgo_ts + 25416,
	6:  __ccgo_ts + 25435,
	7:  __ccgo_ts + 1663,
	8:  __ccgo_ts + 25460,
	9:  __ccgo_ts + 25497,
	10: __ccgo_ts + 25509,
	11: __ccgo_ts + 25524,
	12: __ccgo_ts + 25557,
	13: __ccgo_ts + 25575,
	14: __ccgo_ts + 25600,
	15: __ccgo_ts + 25629,
	17: __ccgo_ts + 6232,
	18: __ccgo_ts + 5583,
	19: __ccgo_ts + 25646,
	20: __ccgo_ts + 25664,
	21: __ccgo_ts + 25682,
	23: __ccgo_ts + 25716,
	25: __ccgo_ts + 25737,
	26: __ccgo_ts + 25763,
	27: __ccgo_ts + 25786,
	28: __ccgo_ts + 25807,
}

var _aOp = [4]struct {
	FzOp uintptr
	FeOp uint8
}{
	0: {
		FzOp: __ccgo_ts + 17805,
		FeOp: uint8(SQLITE_INDEX_CONSTRAINT_MATCH),
	},
	1: {
		FzOp: __ccgo_ts + 17139,
		FeOp: uint8(SQLITE_INDEX_CONSTRAINT_GLOB),
	},
	2: {
		FzOp: __ccgo_ts + 16598,
		FeOp: uint8(SQLITE_INDEX_CONSTRAINT_LIKE),
	},
	3: {
		FzOp: __ccgo_ts + 23927,
		FeOp: uint8(SQLITE_INDEX_CONSTRAINT_REGEXP),
	},
}

var _aOpenMode = [5]struct {
	Fz    uintptr
	Fmode int32
}{
	0: {
		Fz:    __ccgo_ts + 26181,
		Fmode: int32(SQLITE_OPEN_READONLY),
	},
	1: {
		Fz:    __ccgo_ts + 26184,
		Fmode: int32(SQLITE_OPEN_READWRITE),
	},
	2: {
		Fz:    __ccgo_ts + 26187,
		Fmode: libc.Int32FromInt32(SQLITE_OPEN_READWRITE) | libc.Int32FromInt32(SQLITE_OPEN_CREATE),
	},
	3: {
		Fz:    __ccgo_ts + 19026,
		Fmode: int32(SQLITE_OPEN_MEMORY),
	},
	4: {},
}

var _aPragmaName = [66]TPragmaName{
	0: {
		FzName:    __ccgo_ts + 18025,
		FePragTyp: uint8(PragTyp_ANALYSIS_LIMIT),
		FmPragFlg: uint8(PragFlg_Result0),
	},
	1: {
		FzName:    __ccgo_ts + 18040,
		FePragTyp: uint8(PragTyp_HEADER_VALUE),
		FmPragFlg: libc.Uint8FromInt32(libc.Int32FromInt32(PragFlg_NoColumns1) | libc.Int32FromInt32(PragFlg_Result0)),
		FiArg:     uint64(BTREE_APPLICATION_ID),
	},
	2: {
		FzName:    __ccgo_ts + 18055,
		FePragTyp: uint8(PragTyp_AUTO_VACUUM),
		FmPragFlg: libc.Uint8FromInt32(libc.Int32FromInt32(PragFlg_NeedSchema) | libc.Int32FromInt32(PragFlg_Result0) | libc.Int32FromInt32(PragFlg_SchemaReq) | libc.Int32FromInt32(PragFlg_NoColumns1)),
	},
	3: {
		FzName:    __ccgo_ts + 18067,
		FePragTyp: uint8(PragTyp_FLAG),
		FmPragFlg: libc.Uint8FromInt32(libc.Int32FromInt32(PragFlg_Result0) | libc.Int32FromInt32(PragFlg_NoColumns1)),
		FiArg:     uint64(SQLITE_AutoIndex),
	},
	4: {
		FzName:      __ccgo_ts + 18083,
		FePragTyp:   uint8(PragTyp_BUSY_TIMEOUT),
		FmPragFlg:   uint8(PragFlg_Result0),
		FiPragCName: uint8(56),
		FnPragCName: uint8(1),
	},
	5: {
		FzName:    __ccgo_ts + 18006,
		FePragTyp: uint8(PragTyp_CACHE_SIZE),
		FmPragFlg: libc.Uint8FromInt32(libc.Int32FromInt32(PragFlg_NeedSchema) | libc.Int32FromInt32(PragFlg_Result0) | libc.Int32FromInt32(PragFlg_SchemaReq) | libc.Int32FromInt32(PragFlg_NoColumns1)),
	},
	6: {
		FzName:    __ccgo_ts + 18096,
		FePragTyp: uint8(PragTyp_CACHE_SPILL),
		FmPragFlg: libc.Uint8FromInt32(libc.Int32FromInt32(PragFlg_Result0) | libc.Int32FromInt32(PragFlg_SchemaReq) | libc.Int32FromInt32(PragFlg_NoColumns1)),
	},
	7: {
		FzName:    __ccgo_ts + 18108,
		FePragTyp: uint8(PragTyp_CASE_SENSITIVE_LIKE),
		FmPragFlg: uint8(PragFlg_NoColumns),
	},
	8: {
		FzName:    __ccgo_ts + 18128,
		FePragTyp: uint8(PragTyp_FLAG),
		FmPragFlg: libc.Uint8FromInt32(libc.Int32FromInt32(PragFlg_Result0) | libc.Int32FromInt32(PragFlg_NoColumns1)),
		FiArg:     uint64(SQLITE_CellSizeCk),
	},
	9: {
		FzName:    __ccgo_ts + 18144,
		FePragTyp: uint8(PragTyp_FLAG),
		FmPragFlg: libc.Uint8FromInt32(libc.Int32FromInt32(PragFlg_Result0) | libc.Int32FromInt32(PragFlg_NoColumns1)),
		FiArg:     uint64(SQLITE_CkptFullFSync),
	},
	10: {
		FzName:      __ccgo_ts + 18165,
		FePragTyp:   uint8(PragTyp_COLLATION_LIST),
		FmPragFlg:   uint8(PragFlg_Result0),
		FiPragCName: uint8(33),
		FnPragCName: uint8(2),
	},
	11: {
		FzName:    __ccgo_ts + 18180,
		FePragTyp: uint8(PragTyp_COMPILE_OPTIONS),
		FmPragFlg: uint8(PragFlg_Result0),
	},
	12: {
		FzName:    __ccgo_ts + 18196,
		FePragTyp: uint8(PragTyp_FLAG),
		FmPragFlg: libc.Uint8FromInt32(libc.Int32FromInt32(PragFlg_Result0) | libc.Int32FromInt32(PragFlg_NoColumns1)),
		FiArg:     libc.Uint64FromInt32(libc.Int32FromInt32(0x00001)) << libc.Int32FromInt32(32),
	},
	13: {
		FzName:    __ccgo_ts + 18210,
		FePragTyp: uint8(PragTyp_HEADER_VALUE),
		FmPragFlg: libc.Uint8FromInt32(libc.Int32FromInt32(PragFlg_ReadOnly) | libc.Int32FromInt32(PragFlg_Result0)),
		FiArg:     uint64(BTREE_DATA_VERSION),
	},
	14: {
		FzName:      __ccgo_ts + 18223,
		FePragTyp:   uint8(PragTyp_DATABASE_LIST),
		FmPragFlg:   uint8(PragFlg_Result0),
		FiPragCName: uint8(50),
		FnPragCName: uint8(3),
	},
	15: {
		FzName:      __ccgo_ts + 18237,
		FePragTyp:   uint8(PragTyp_DEFAULT_CACHE_SIZE),
		FmPragFlg:   libc.Uint8FromInt32(libc.Int32FromInt32(PragFlg_NeedSchema) | libc.Int32FromInt32(PragFlg_Result0) | libc.Int32FromInt32(PragFlg_SchemaReq) | libc.Int32FromInt32(PragFlg_NoColumns1)),
		FiPragCName: uint8(55),
		FnPragCName: uint8(1),
	},
	16: {
		FzName:    __ccgo_ts + 18256,
		FePragTyp: uint8(PragTyp_FLAG),
		FmPragFlg: libc.Uint8FromInt32(libc.Int32FromInt32(PragFlg_Result0) | libc.Int32FromInt32(PragFlg_NoColumns1)),
		FiArg:     uint64(SQLITE_DeferFKs),
	},
	17: {
		FzName:    __ccgo_ts + 18275,
		FePragTyp: uint8(PragTyp_FLAG),
		FmPragFlg: libc.Uint8FromInt32(libc.Int32FromInt32(PragFlg_Result0) | libc.Int32FromInt32(PragFlg_NoColumns1)),
		FiArg:     uint64(SQLITE_NullCallback),
	},
	18: {
		FzName:    __ccgo_ts + 18298,
		FePragTyp: uint8(PragTyp_ENCODING),
		FmPragFlg: libc.Uint8FromInt32(libc.Int32FromInt32(PragFlg_Result0) | libc.Int32FromInt32(PragFlg_NoColumns1)),
	},
	19: {
		FzName:      __ccgo_ts + 18307,
		FePragTyp:   uint8(PragTyp_FOREIGN_KEY_CHECK),
		FmPragFlg:   libc.Uint8FromInt32(libc.Int32FromInt32(PragFlg_NeedSchema) | libc.Int32FromInt32(PragFlg_Result0) | libc.Int32FromInt32(PragFlg_Result1) | libc.Int32FromInt32(PragFlg_SchemaOpt)),
		FiPragCName: uint8(43),
		FnPragCName: uint8(4),
	},
	20: {
		FzName:      __ccgo_ts + 18325,
		FePragTyp:   uint8(PragTyp_FOREIGN_KEY_LIST),
		FmPragFlg:   libc.Uint8FromInt32(libc.Int32FromInt32(PragFlg_NeedSchema) | libc.Int32FromInt32(PragFlg_Result1) | libc.Int32FromInt32(PragFlg_SchemaOpt)),
		FnPragCName: uint8(8),
	},
	21: {
		FzName:    __ccgo_ts + 18342,
		FePragTyp: uint8(PragTyp_FLAG),
		FmPragFlg: libc.Uint8FromInt32(libc.Int32FromInt32(PragFlg_Result0) | libc.Int32FromInt32(PragFlg_NoColumns1)),
		FiArg:     uint64(SQLITE_ForeignKeys),
	},
	22: {
		FzName:    __ccgo_ts + 18355,
		FePragTyp: uint8(PragTyp_HEADER_VALUE),
		FmPragFlg: libc.Uint8FromInt32(libc.Int32FromInt32(PragFlg_ReadOnly) | libc.Int32FromInt32(PragFlg_Result0)),
	},
	23: {
		FzName:    __ccgo_ts + 18370,
		FePragTyp: uint8(PragTyp_FLAG),
		FmPragFlg: libc.Uint8FromInt32(libc.Int32FromInt32(PragFlg_Result0) | libc.Int32FromInt32(PragFlg_NoColumns1)),
		FiArg:     uint64(SQLITE_FullColNames),
	},
	24: {
		FzName:    __ccgo_ts + 18388,
		FePragTyp: uint8(PragTyp_FLAG),
		FmPragFlg: libc.Uint8FromInt32(libc.Int32FromInt32(PragFlg_Result0) | libc.Int32FromInt32(PragFlg_NoColumns1)),
		FiArg:     uint64(SQLITE_FullFSync),
	},
	25: {
		FzName:      __ccgo_ts + 18398,
		FePragTyp:   uint8(PragTyp_FUNCTION_LIST),
		FmPragFlg:   uint8(PragFlg_Result0),
		FiPragCName: uint8(15),
		FnPragCName: uint8(6),
	},
	26: {
		FzName:    __ccgo_ts + 18412,
		FePragTyp: uint8(PragTyp_HARD_HEAP_LIMIT),
		FmPragFlg: uint8(PragFlg_Result0),
	},
	27: {
		FzName:    __ccgo_ts + 18428,
		FePragTyp: uint8(PragTyp_FLAG),
		FmPragFlg: libc.Uint8FromInt32(libc.Int32FromInt32(PragFlg_Result0) | libc.Int32FromInt32(PragFlg_NoColumns1)),
		FiArg:     uint64(SQLITE_IgnoreChecks),
	},
	28: {
		FzName:    __ccgo_ts + 18453,
		FePragTyp: uint8(PragTyp_INCREMENTAL_VACUUM),
		FmPragFlg: libc.Uint8FromInt32(libc.Int32FromInt32(PragFlg_NeedSchema) | libc.Int32FromInt32(PragFlg_NoColumns)),
	},
	29: {
		FzName:      __ccgo_ts + 18472,
		FePragTyp:   uint8(PragTyp_INDEX_INFO),
		FmPragFlg:   libc.Uint8FromInt32(libc.Int32FromInt32(PragFlg_NeedSchema) | libc.Int32FromInt32(PragFlg_Result1) | libc.Int32FromInt32(PragFlg_SchemaOpt)),
		FiPragCName: uint8(27),
		FnPragCName: uint8(3),
	},
	30: {
		FzName:      __ccgo_ts + 18483,
		FePragTyp:   uint8(PragTyp_INDEX_LIST),
		FmPragFlg:   libc.Uint8FromInt32(libc.Int32FromInt32(PragFlg_NeedSchema) | libc.Int32FromInt32(PragFlg_Result1) | libc.Int32FromInt32(PragFlg_SchemaOpt)),
		FiPragCName: uint8(33),
		FnPragCName: uint8(5),
	},
	31: {
		FzName:      __ccgo_ts + 18494,
		FePragTyp:   uint8(PragTyp_INDEX_INFO),
		FmPragFlg:   libc.Uint8FromInt32(libc.Int32FromInt32(PragFlg_NeedSchema) | libc.Int32FromInt32(PragFlg_Result1) | libc.Int32FromInt32(PragFlg_SchemaOpt)),
		FiPragCName: uint8(27),
		FnPragCName: uint8(6),
		FiArg:       uint64(1),
	},
	32: {
		FzName:    __ccgo_ts + 18506,
		FePragTyp: uint8(PragTyp_INTEGRITY_CHECK),
		FmPragFlg: libc.Uint8FromInt32(libc.Int32FromInt32(PragFlg_NeedSchema) | libc.Int32FromInt32(PragFlg_Result0) | libc.Int32FromInt32(PragFlg_Result1) | libc.Int32FromInt32(PragFlg_SchemaOpt)),
	},
	33: {
		FzName:    __ccgo_ts + 18522,
		FePragTyp: uint8(PragTyp_JOURNAL_MODE),
		FmPragFlg: libc.Uint8FromInt32(libc.Int32FromInt32(PragFlg_NeedSchema) | libc.Int32FromInt32(PragFlg_Result0) | libc.Int32FromInt32(PragFlg_SchemaReq)),
	},
	34: {
		FzName:    __ccgo_ts + 18535,
		FePragTyp: uint8(PragTyp_JOURNAL_SIZE_LIMIT),
		FmPragFlg: libc.Uint8FromInt32(libc.Int32FromInt32(PragFlg_Result0) | libc.Int32FromInt32(PragFlg_SchemaReq)),
	},
	35: {
		FzName:    __ccgo_ts + 18554,
		FePragTyp: uint8(PragTyp_FLAG),
		FmPragFlg: libc.Uint8FromInt32(libc.Int32FromInt32(PragFlg_Result0) | libc.Int32FromInt32(PragFlg_NoColumns1)),
		FiArg:     uint64(SQLITE_LegacyAlter),
	},
	36: {
		FzName:    __ccgo_ts + 18573,
		FePragTyp: uint8(PragTyp_LOCKING_MODE),
		FmPragFlg: libc.Uint8FromInt32(libc.Int32FromInt32(PragFlg_Result0) | libc.Int32FromInt32(PragFlg_SchemaReq)),
	},
	37: {
		FzName:    __ccgo_ts + 18586,
		FePragTyp: uint8(PragTyp_PAGE_COUNT),
		FmPragFlg: libc.Uint8FromInt32(libc.Int32FromInt32(PragFlg_NeedSchema) | libc.Int32FromInt32(PragFlg_Result0) | libc.Int32FromInt32(PragFlg_SchemaReq)),
	},
	38: {
		FzName:    __ccgo_ts + 18601,
		FePragTyp: uint8(PragTyp_MMAP_SIZE),
	},
	39: {
		FzName:      __ccgo_ts + 18611,
		FePragTyp:   uint8(PragTyp_MODULE_LIST),
		FmPragFlg:   uint8(PragFlg_Result0),
		FiPragCName: uint8(9),
		FnPragCName: uint8(1),
	},
	40: {
		FzName:    __ccgo_ts + 18623,
		FePragTyp: uint8(PragTyp_OPTIMIZE),
		FmPragFlg: libc.Uint8FromInt32(libc.Int32FromInt32(PragFlg_Result1) | libc.Int32FromInt32(PragFlg_NeedSchema)),
	},
	41: {
		FzName:    __ccgo_ts + 18632,
		FePragTyp: uint8(PragTyp_PAGE_COUNT),
		FmPragFlg: libc.Uint8FromInt32(libc.Int32FromInt32(PragFlg_NeedSchema) | libc.Int32FromInt32(PragFlg_Result0) | libc.Int32FromInt32(PragFlg_SchemaReq)),
	},
	42: {
		FzName:    __ccgo_ts + 18643,
		FePragTyp: uint8(PragTyp_PAGE_SIZE),
		FmPragFlg: libc.Uint8FromInt32(libc.Int32FromInt32(PragFlg_Result0) | libc.Int32FromInt32(PragFlg_SchemaReq) | libc.Int32FromInt32(PragFlg_NoColumns1)),
	},
	43: {
		FzName:      __ccgo_ts + 18653,
		FePragTyp:   uint8(PragTyp_PRAGMA_LIST),
		FmPragFlg:   uint8(PragFlg_Result0),
		FiPragCName: uint8(9),
		FnPragCName: uint8(1),
	},
	44: {
		FzName:    __ccgo_ts + 18665,
		FePragTyp: uint8(PragTyp_FLAG),
		FmPragFlg: libc.Uint8FromInt32(libc.Int32FromInt32(PragFlg_Result0) | libc.Int32FromInt32(PragFlg_NoColumns1)),
		FiArg:     uint64(SQLITE_QueryOnly),
	},
	45: {
		FzName:    __ccgo_ts + 18676,
		FePragTyp: uint8(PragTyp_INTEGRITY_CHECK),
		FmPragFlg: libc.Uint8FromInt32(libc.Int32FromInt32(PragFlg_NeedSchema) | libc.Int32FromInt32(PragFlg_Result0) | libc.Int32FromInt32(PragFlg_Result1) | libc.Int32FromInt32(PragFlg_SchemaOpt)),
	},
	46: {
		FzName:    __ccgo_ts + 18688,
		FePragTyp: uint8(PragTyp_FLAG),
		FmPragFlg: libc.Uint8FromInt32(libc.Int32FromInt32(PragFlg_Result0) | libc.Int32FromInt32(PragFlg_NoColumns1)),
		FiArg:     libc.Uint64FromInt32(libc.Int32FromInt32(0x00004)) << libc.Int32FromInt32(32),
	},
	47: {
		FzName:    __ccgo_ts + 18705,
		FePragTyp: uint8(PragTyp_FLAG),
		FmPragFlg: libc.Uint8FromInt32(libc.Int32FromInt32(PragFlg_Result0) | libc.Int32FromInt32(PragFlg_NoColumns1)),
		FiArg:     uint64(SQLITE_RecTriggers),
	},
	48: {
		FzName:    __ccgo_ts + 18724,
		FePragTyp: uint8(PragTyp_FLAG),
		FmPragFlg: libc.Uint8FromInt32(libc.Int32FromInt32(PragFlg_Result0) | libc.Int32FromInt32(PragFlg_NoColumns1)),
		FiArg:     uint64(SQLITE_ReverseOrder),
	},
	49: {
		FzName:    __ccgo_ts + 18750,
		FePragTyp: uint8(PragTyp_HEADER_VALUE),
		FmPragFlg: libc.Uint8FromInt32(libc.Int32FromInt32(PragFlg_NoColumns1) | libc.Int32FromInt32(PragFlg_Result0)),
		FiArg:     uint64(BTREE_SCHEMA_VERSION),
	},
	50: {
		FzName:    __ccgo_ts + 18765,
		FePragTyp: uint8(PragTyp_SECURE_DELETE),
		FmPragFlg: uint8(PragFlg_Result0),
	},
	51: {
		FzName:    __ccgo_ts + 18779,
		FePragTyp: uint8(PragTyp_FLAG),
		FmPragFlg: libc.Uint8FromInt32(libc.Int32FromInt32(PragFlg_Result0) | libc.Int32FromInt32(PragFlg_NoColumns1)),
		FiArg:     uint64(SQLITE_ShortColNames),
	},
	52: {
		FzName:    __ccgo_ts + 18798,
		FePragTyp: uint8(PragTyp_SHRINK_MEMORY),
		FmPragFlg: uint8(PragFlg_NoColumns),
	},
	53: {
		FzName:    __ccgo_ts + 18812,
		FePragTyp: uint8(PragTyp_SOFT_HEAP_LIMIT),
		FmPragFlg: uint8(PragFlg_Result0),
	},
	54: {
		FzName:    __ccgo_ts + 18828,
		FePragTyp: uint8(PragTyp_SYNCHRONOUS),
		FmPragFlg: libc.Uint8FromInt32(libc.Int32FromInt32(PragFlg_NeedSchema) | libc.Int32FromInt32(PragFlg_Result0) | libc.Int32FromInt32(PragFlg_SchemaReq) | libc.Int32FromInt32(PragFlg_NoColumns1)),
	},
	55: {
		FzName:      __ccgo_ts + 18840,
		FePragTyp:   uint8(PragTyp_TABLE_INFO),
		FmPragFlg:   libc.Uint8FromInt32(libc.Int32FromInt32(PragFlg_NeedSchema) | libc.Int32FromInt32(PragFlg_Result1) | libc.Int32FromInt32(PragFlg_SchemaOpt)),
		FiPragCName: uint8(8),
		FnPragCName: uint8(6),
	},
	56: {
		FzName:      __ccgo_ts + 18851,
		FePragTyp:   uint8(PragTyp_TABLE_LIST),
		FmPragFlg:   libc.Uint8FromInt32(libc.Int32FromInt32(PragFlg_NeedSchema) | libc.Int32FromInt32(PragFlg_Result1)),
		FiPragCName: uint8(21),
		FnPragCName: uint8(6),
	},
	57: {
		FzName:      __ccgo_ts + 18862,
		FePragTyp:   uint8(PragTyp_TABLE_INFO),
		FmPragFlg:   libc.Uint8FromInt32(libc.Int32FromInt32(PragFlg_NeedSchema) | libc.Int32FromInt32(PragFlg_Result1) | libc.Int32FromInt32(PragFlg_SchemaOpt)),
		FiPragCName: uint8(8),
		FnPragCName: uint8(7),
		FiArg:       uint64(1),
	},
	58: {
		FzName:    __ccgo_ts + 18874,
		FePragTyp: uint8(PragTyp_TEMP_STORE),
		FmPragFlg: libc.Uint8FromInt32(libc.Int32FromInt32(PragFlg_Result0) | libc.Int32FromInt32(PragFlg_NoColumns1)),
	},
	59: {
		FzName:    __ccgo_ts + 18885,
		FePragTyp: uint8(PragTyp_TEMP_STORE_DIRECTORY),
		FmPragFlg: uint8(PragFlg_NoColumns1),
	},
	60: {
		FzName:    __ccgo_ts + 18906,
		FePragTyp: uint8(PragTyp_THREADS),
		FmPragFlg: uint8(PragFlg_Result0),
	},
	61: {
		FzName:    __ccgo_ts + 18914,
		FePragTyp: uint8(PragTyp_FLAG),
		FmPragFlg: libc.Uint8FromInt32(libc.Int32FromInt32(PragFlg_Result0) | libc.Int32FromInt32(PragFlg_NoColumns1)),
		FiArg:     uint64(SQLITE_TrustedSchema),
	},
	62: {
		FzName:    __ccgo_ts + 18929,
		FePragTyp: uint8(PragTyp_HEADER_VALUE),
		FmPragFlg: libc.Uint8FromInt32(libc.Int32FromInt32(PragFlg_NoColumns1) | libc.Int32FromInt32(PragFlg_Result0)),
		FiArg:     uint64(BTREE_USER_VERSION),
	},
	63: {
		FzName:    __ccgo_ts + 18942,
		FePragTyp: uint8(PragTyp_WAL_AUTOCHECKPOINT),
	},
	64: {
		FzName:      __ccgo_ts + 18961,
		FePragTyp:   uint8(PragTyp_WAL_CHECKPOINT),
		FmPragFlg:   uint8(PragFlg_NeedSchema),
		FiPragCName: uint8(47),
		FnPragCName: uint8(3),
	},
	65: {
		FzName:    __ccgo_ts + 18976,
		FePragTyp: uint8(PragTyp_FLAG),
		FmPragFlg: libc.Uint8FromInt32(libc.Int32FromInt32(PragFlg_Result0) | libc.Int32FromInt32(PragFlg_NoColumns1)),
		FiArg:     libc.Uint64FromInt32(libc.Int32FromInt32(SQLITE_WriteSchema) | libc.Int32FromInt32(SQLITE_NoSchemaError)),
	},
}

/* Number of pragmas: 68 on by default, 78 total. */

/************** End of pragma.h **********************************************/
/************** Continuing where we left off in pragma.c *********************/

/*
** When the 0x10 bit of PRAGMA optimize is set, any ANALYZE commands
** will be run with an analysis_limit set to the lessor of the value of
** the following macro or to the actual analysis_limit if it is non-zero,
** in order to prevent PRAGMA optimize from running for too long.
**
** The value of 2000 is chosen empirically so that the worst-case run-time
** for PRAGMA optimize does not exceed 100 milliseconds against a variety
** of test databases on a RaspberryPI-4 compiled using -Os and without
** -DSQLITE_DEBUG.  Of course, your mileage may vary.  For the purpose of
** this paragraph, "worst-case" means that ANALYZE ends up being
** run on every table in the database.  The worst case typically only
** happens if PRAGMA optimize is run on a database file for which ANALYZE
** has not been previously run and the 0x10000 flag is included so that
** all tables are analyzed.  The usual case for PRAGMA optimize is that
** no ANALYZE commands will be run at all, or if any ANALYZE happens it
** will be against a single table, so that expected timing for PRAGMA
** optimize on a PI-4 is more like 1 millisecond or less with the 0x10000
** flag or less than 100 microseconds without the 0x10000 flag.
**
** An analysis limit of 2000 is almost always sufficient for the query
** planner to fully characterize an index.  The additional accuracy from
** a larger analysis is not usually helpful.
 */

// C documentation
//
//	/*
//	** Many system calls are accessed through pointer-to-functions so that
//	** they may be overridden at runtime to facilitate fault injection during
//	** testing and sandboxing.  The following array holds the names and pointers
//	** to all overrideable system calls.
//	*/
var _aSyscall = [29]Tunix_syscall{
	0: {
		FzName: __ccgo_ts + 3531,
	},
	1: {
		FzName: __ccgo_ts + 3536,
	},
	2: {
		FzName: __ccgo_ts + 3542,
	},
	3: {
		FzName: __ccgo_ts + 3549,
	},
	4: {
		FzName: __ccgo_ts + 3556,
	},
	5: {
		FzName: __ccgo_ts + 3561,
	},
	6: {
		FzName: __ccgo_ts + 3567,
	},
	7: {
		FzName: __ccgo_ts + 3577,
	},
	8: {
		FzName: __ccgo_ts + 3583,
	},
	9: {
		FzName: __ccgo_ts + 3588,
	},
	10: {
		FzName: __ccgo_ts + 3594,
	},
	11: {
		FzName: __ccgo_ts + 3602,
	},
	12: {
		FzName: __ccgo_ts + 3608,
	},
	13: {
		FzName: __ccgo_ts + 3615,
	},
	14: {
		FzName: __ccgo_ts + 3624,
	},
	15: {
		FzName: __ccgo_ts + 3631,
	},
	16: {
		FzName: __ccgo_ts + 3641,
	},
	17: {
		FzName: __ccgo_ts + 3648,
	},
	18: {
		FzName: __ccgo_ts + 3662,
	},
	19: {
		FzName: __ccgo_ts + 3668,
	},
	20: {
		FzName: __ccgo_ts + 3674,
	},
	21: {
		FzName: __ccgo_ts + 3681,
	},
	22: {
		FzName: __ccgo_ts + 3689,
	},
	23: {
		FzName: __ccgo_ts + 3694,
	},
	24: {
		FzName: __ccgo_ts + 3701,
	},
	25: {
		FzName: __ccgo_ts + 3708,
	},
	26: {
		FzName: __ccgo_ts + 3720,
	},
	27: {
		FzName: __ccgo_ts + 3729,
	},
	28: {
		FzName: __ccgo_ts + 3735,
	},
}

var _aTable = [3]struct {
	FzName uintptr
	FzCols uintptr
}{
	0: {
		FzName: __ccgo_ts + 12826,
		FzCols: __ccgo_ts + 12839,
	},
	1: {
		FzName: __ccgo_ts + 12852,
		FzCols: __ccgo_ts + 12865,
	},
	2: {
		FzName: __ccgo_ts + 12893,
	},
}

/*
** Recommended number of samples for sqlite_stat4
 */

/*
 ** All default VFSes for unix are contained in the following array.
 **
 ** Note that the sqlite3_vfs.pNext field of the VFS object is modified
 ** by the SQLite core when the VFS is registered.  So the following
 ** array cannot be const.
 */
var _aVfs = [4]Tsqlite3_vfs{
	0: {
		FiVersion:   int32(3),
		FszOsFile:   int32(88),
		FmxPathname: int32(MAX_PATHNAME),
		FzName:      __ccgo_ts + 4077,
	},
	1: {
		FiVersion:   int32(3),
		FszOsFile:   int32(88),
		FmxPathname: int32(MAX_PATHNAME),
		FzName:      __ccgo_ts + 4082,
	},
	2: {
		FiVersion:   int32(3),
		FszOsFile:   int32(88),
		FmxPathname: int32(MAX_PATHNAME),
		FzName:      __ccgo_ts + 4092,
	},
	3: {
		FiVersion:   int32(3),
		FszOsFile:   int32(88),
		FmxPathname: int32(MAX_PATHNAME),
		FzName:      __ccgo_ts + 3972,
	},
}

// C documentation
//
//	/*
//	** Implementation of the abs() function.
//	**
//	** IMP: R-23979-26855 The abs(X) function returns the absolute value of
//	** the numeric argument X.
//	*/
func _absFunc(tls *libc.TLS, context uintptr, argc int32, argv uintptr) {
	var iVal Ti64
	var rVal float64
	_, _ = iVal, rVal
	_ = argc
	switch Xsqlite3_value_type(tls, **(**uintptr)(__ccgo_up(argv))) {
	case int32(SQLITE_INTEGER):
		iVal = Xsqlite3_value_int64(tls, **(**uintptr)(__ccgo_up(argv)))
		if iVal < 0 {
			if iVal == int64(-libc.Int32FromInt32(1))-(libc.Int64FromUint32(0xffffffff)|libc.Int64FromInt32(0x7fffffff)<<libc.Int32FromInt32(32)) {
				/* IMP: R-31676-45509 If X is the integer -9223372036854775808
				 ** then abs(X) throws an integer overflow error since there is no
				 ** equivalent positive 64-bit two complement value. */
				Xsqlite3_result_error(tls, context, __ccgo_ts+16451, -int32(1))
				return
			}
			iVal = -iVal
		}
		Xsqlite3_result_int64(tls, context, iVal)
	case int32(SQLITE_NULL):
		/* IMP: R-37434-19929 Abs(X) returns NULL if X is NULL. */
		Xsqlite3_result_null(tls, context)
	default:
		/* Because sqlite3_value_double() returns 0.0 if the argument is not
		 ** something that can be converted into a number, we have:
		 ** IMP: R-01992-00519 Abs(X) returns 0.0 if X is a string or blob
		 ** that cannot be converted to a numeric value.
		 */
		rVal = Xsqlite3_value_double(tls, **(**uintptr)(__ccgo_up(argv)))
		if rVal < libc.Float64FromInt32(0) {
			rVal = -rVal
		}
		Xsqlite3_result_double(tls, context, rVal)
		break
	}
}

// C documentation
//
//	/*
//	** Return a human-readable name for a constraint resolution action.
//	*/
func _actionName(tls *libc.TLS, action Tu8) (r uintptr) {
	var zName uintptr
	_ = zName
	switch libc.Int32FromUint8(action) {
	case int32(OE_SetNull):
		zName = __ccgo_ts + 19095
	case int32(OE_SetDflt):
		zName = __ccgo_ts + 19104
	case int32(OE_Cascade):
		zName = __ccgo_ts + 19116
	case int32(OE_Restrict):
		zName = __ccgo_ts + 19124
	default:
		zName = __ccgo_ts + 19133
		break
	}
	return zName
}

// C documentation
//
//	/*
//	** Internal SQL function:
//	**
//	**     sqlite_add_constraint(SQL, CONSTRAINT-TEXT, ICOL)
//	**
//	** SQL is a CREATE TABLE statement.  Return a modified version of
//	** SQL that adds CONSTRAINT-TEXT at the end of the ICOL-th column
//	** definition.  (The left-most column defintion is 0.)
//	*/
func _addConstraintFunc(tls *libc.TLS, ctx uintptr, NotUsed int32, argv uintptr) {
	bp := tls.Alloc(48)
	defer tls.Free(48)
	var db, zCons, zNew, zSql uintptr
	var iCol, ii, nTok int32
	var _ /* iOff at bp+0 */ int32
	var _ /* t at bp+4 */ int32
	_, _, _, _, _, _, _ = db, iCol, ii, nTok, zCons, zNew, zSql
	zSql = Xsqlite3_value_text(tls, **(**uintptr)(__ccgo_up(argv)))
	zCons = Xsqlite3_value_text(tls, **(**uintptr)(__ccgo_up(argv + 1*8)))
	iCol = Xsqlite3_value_int(tls, **(**uintptr)(__ccgo_up(argv + 2*8)))
	**(**int32)(__ccgo_up(bp)) = 0
	zNew = uintptr(0)
	**(**int32)(__ccgo_up(bp + 4)) = 0
	_ = NotUsed
	if _skipCreateTable(tls, ctx, zSql, bp) != 0 {
		return
	}
	ii = 0
	for {
		if !(ii <= iCol || iCol < 0 && **(**int32)(__ccgo_up(bp + 4)) != int32(TK_RP)) {
			break
		}
		**(**int32)(__ccgo_up(bp)) = **(**int32)(__ccgo_up(bp)) + _getConstraintToken(tls, zSql+uintptr(**(**int32)(__ccgo_up(bp))), bp+4)
		for int32(1) != 0 {
			nTok = _getConstraintToken(tls, zSql+uintptr(**(**int32)(__ccgo_up(bp))), bp+4)
			if **(**int32)(__ccgo_up(bp + 4)) == int32(TK_COMMA) || **(**int32)(__ccgo_up(bp + 4)) == int32(TK_RP) {
				break
			}
			if **(**int32)(__ccgo_up(bp + 4)) == int32(TK_ILLEGAL) {
				Xsqlite3_result_error_code(tls, ctx, _sqlite3CorruptError(tls, int32(123226)))
				return
			}
			**(**int32)(__ccgo_up(bp)) = **(**int32)(__ccgo_up(bp)) + nTok
		}
		goto _1
	_1:
		;
		ii = ii + 1
	}
	**(**int32)(__ccgo_up(bp)) = **(**int32)(__ccgo_up(bp)) + _getWhitespace(tls, zSql+uintptr(**(**int32)(__ccgo_up(bp))))
	db = Xsqlite3_context_db_handle(tls, ctx)
	if iCol < 0 {
		zNew = _sqlite3MPrintf(tls, db, __ccgo_ts+11878, libc.VaList(bp+16, **(**int32)(__ccgo_up(bp)), zSql, zCons, zSql+uintptr(**(**int32)(__ccgo_up(bp)))))
	} else {
		zNew = _sqlite3MPrintf(tls, db, __ccgo_ts+11889, libc.VaList(bp+16, **(**int32)(__ccgo_up(bp)), zSql, zCons, zSql+uintptr(**(**int32)(__ccgo_up(bp)))))
	}
	Xsqlite3_result_text(tls, ctx, zNew, -int32(1), __ccgo_fp(_sqlite3RowSetClear))
}

// C documentation
//
//	/*
//	** Add a new module argument to pTable->u.vtab.azArg[].
//	** The string is not copied - the pointer is stored.  The
//	** string will be freed automatically when the table is
//	** deleted.
//	*/
func _addModuleArgument(tls *libc.TLS, pParse uintptr, pTable uintptr, zArg uintptr) {
	bp := tls.Alloc(16)
	defer tls.Free(16)
	var azModuleArg, db, v2 uintptr
	var i, v1 int32
	var nBytes Tsqlite3_int64
	_, _, _, _, _, _ = azModuleArg, db, i, nBytes, v1, v2
	db = (*TParse)(unsafe.Pointer(pParse)).Fdb
	nBytes = libc.Int64FromUint64(uint64(8) * libc.Uint64FromInt32(libc.Int32FromInt32(2)+(*(*struct {
		FnArg  int32
		FazArg uintptr
		Fp     uintptr
	})(unsafe.Pointer(pTable + 64))).FnArg))
	if (*(*struct {
		FnArg  int32
		FazArg uintptr
		Fp     uintptr
	})(unsafe.Pointer(pTable + 64))).FnArg+int32(3) >= **(**int32)(__ccgo_up(db + 136 + 2*4)) {
		_sqlite3ErrorMsg(tls, pParse, __ccgo_ts+13949, libc.VaList(bp+8, (*TTable)(unsafe.Pointer(pTable)).FzName))
	}
	azModuleArg = _sqlite3DbRealloc(tls, db, (*(*struct {
		FnArg  int32
		FazArg uintptr
		Fp     uintptr
	})(unsafe.Pointer(pTable + 64))).FazArg, libc.Uint64FromInt64(nBytes))
	if azModuleArg == uintptr(0) {
		_sqlite3DbFree(tls, db, zArg)
	} else {
		v2 = pTable + 64
		v1 = *(*int32)(unsafe.Pointer(v2))
		*(*int32)(unsafe.Pointer(v2)) = *(*int32)(unsafe.Pointer(v2)) + 1
		i = v1
		**(**uintptr)(__ccgo_up(azModuleArg + uintptr(i)*8)) = zArg
		**(**uintptr)(__ccgo_up(azModuleArg + uintptr(i+int32(1))*8)) = uintptr(0)
		(*(*struct {
			FnArg  int32
			FazArg uintptr
			Fp     uintptr
		})(unsafe.Pointer(pTable + 64))).FazArg = azModuleArg
	}
}

// C documentation
//
//	/*
//	** Allocate and populate an sqlite3_index_info structure. It is the
//	** responsibility of the caller to eventually release the structure
//	** by passing the pointer returned by this function to freeIndexInfo().
//	*/
func _allocateIndexInfo(tls *libc.TLS, pWInfo uintptr, pWC uintptr, mUnusable TBitmask, pSrc uintptr, pmNoOmit uintptr) (r uintptr) {
	var bSortByGroup, eDistinct, i, iCol, j, n, nLast, nOrderBy, nTerm, v10 int32
	var mNoOmit, op Tu16
	var p, pE2, pExpr, pExpr1, pHidden, pIdxCons, pIdxInfo, pIdxOrderBy, pOrderBy, pParse, pPk, pTab, pTerm, pUsage, zColl, v3 uintptr
	var v12 uint32
	var v7 bool
	_, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _ = bSortByGroup, eDistinct, i, iCol, j, mNoOmit, n, nLast, nOrderBy, nTerm, op, p, pE2, pExpr, pExpr1, pHidden, pIdxCons, pIdxInfo, pIdxOrderBy, pOrderBy, pParse, pPk, pTab, pTerm, pUsage, zColl, v10, v12, v3, v7
	pParse = (*TWhereInfo)(unsafe.Pointer(pWInfo)).FpParse
	mNoOmit = uint16(0)
	eDistinct = 0
	pOrderBy = (*TWhereInfo)(unsafe.Pointer(pWInfo)).FpOrderBy
	pTab = (*TSrcItem)(unsafe.Pointer(pSrc)).FpSTab
	/* Find all WHERE clause constraints referring to this virtual table.
	 ** Mark each term with the TERM_OK flag.  Set nTerm to the number of
	 ** terms found.
	 */
	p = pWC
	nTerm = libc.Int32FromInt32(0)
	for {
		if !(p != 0) {
			break
		}
		i = 0
		pTerm = (*TWhereClause)(unsafe.Pointer(p)).Fa
		for {
			if !(i < (*TWhereClause)(unsafe.Pointer(p)).FnTerm) {
				break
			}
			v3 = pTerm + 18
			*(*Tu16)(unsafe.Pointer(v3)) = Tu16(int32(*(*Tu16)(unsafe.Pointer(v3))) & ^libc.Int32FromInt32(TERM_OK))
			if (*TWhereTerm)(unsafe.Pointer(pTerm)).FleftCursor != (*TSrcItem)(unsafe.Pointer(pSrc)).FiCursor {
				goto _2
			}
			if (*TWhereTerm)(unsafe.Pointer(pTerm)).FprereqRight&mUnusable != 0 {
				goto _2
			}
			if libc.Int32FromUint16((*TWhereTerm)(unsafe.Pointer(pTerm)).FeOperator) & ^libc.Int32FromInt32(WO_EQUIV) == 0 {
				goto _2
			}
			if libc.Int32FromUint16((*TWhereTerm)(unsafe.Pointer(pTerm)).FwtFlags)&int32(TERM_VNULL) != 0 {
				goto _2
			}
			if libc.Int32FromUint8((*TSrcItem)(unsafe.Pointer(pSrc)).Ffg.Fjointype)&(libc.Int32FromInt32(JT_LEFT)|libc.Int32FromInt32(JT_LTORJ)|libc.Int32FromInt32(JT_RIGHT)) != 0 && !(_constraintCompatibleWithOuterJoin(tls, pTerm, pSrc) != 0) {
				goto _2
			}
			nTerm = nTerm + 1
			v3 = pTerm + 18
			*(*Tu16)(unsafe.Pointer(v3)) = Tu16(int32(*(*Tu16)(unsafe.Pointer(v3))) | libc.Int32FromInt32(TERM_OK))
			goto _2
		_2:
			;
			i = i + 1
			pTerm += 56
		}
		goto _1
	_1:
		;
		p = (*TWhereClause)(unsafe.Pointer(p)).FpOuter
	}
	/* If the ORDER BY clause contains only columns in the current
	 ** virtual table then allocate space for the aOrderBy part of
	 ** the sqlite3_index_info structure.
	 */
	nOrderBy = 0
	if pOrderBy != 0 {
		n = (*TExprList)(unsafe.Pointer(pOrderBy)).FnExpr
		i = 0
		for {
			if !(i < n) {
				break
			}
			pExpr = (*(*TExprList_item)(unsafe.Pointer(pOrderBy + 8 + uintptr(i)*32))).FpExpr
			/* Skip over constant terms in the ORDER BY clause */
			if _sqlite3ExprIsConstant(tls, uintptr(0), pExpr) != 0 {
				goto _5
			}
			/* Virtual tables are unable to deal with NULLS FIRST */
			if libc.Int32FromUint8((*(*TExprList_item)(unsafe.Pointer(pOrderBy + 8 + uintptr(i)*32))).Ffg.FsortFlags)&int32(KEYINFO_ORDER_BIGNULL) != 0 {
				break
			}
			/* First case - a direct column references without a COLLATE operator */
			if libc.Int32FromUint8((*TExpr)(unsafe.Pointer(pExpr)).Fop) == int32(TK_COLUMN) && (*TExpr)(unsafe.Pointer(pExpr)).FiTable == (*TSrcItem)(unsafe.Pointer(pSrc)).FiCursor {
				goto _5
			}
			/* 2nd case - a column reference with a COLLATE operator.  Only match
			 ** of the COLLATE operator matches the collation of the column. */
			if v7 = libc.Int32FromUint8((*TExpr)(unsafe.Pointer(pExpr)).Fop) == int32(TK_COLLATE); v7 {
				v3 = (*TExpr)(unsafe.Pointer(pExpr)).FpLeft
				pE2 = v3
			}
			if v7 && libc.Int32FromUint8((*TExpr)(unsafe.Pointer(v3)).Fop) == int32(TK_COLUMN) && (*TExpr)(unsafe.Pointer(pE2)).FiTable == (*TSrcItem)(unsafe.Pointer(pSrc)).FiCursor { /* The collating sequence name */
				(*TExpr)(unsafe.Pointer(pExpr)).FiColumn = (*TExpr)(unsafe.Pointer(pE2)).FiColumn
				if int32((*TExpr)(unsafe.Pointer(pE2)).FiColumn) < 0 {
					goto _5
				} /* Collseq does not matter for rowid */
				zColl = _sqlite3ColumnColl(tls, (*TTable)(unsafe.Pointer(pTab)).FaCol+uintptr((*TExpr)(unsafe.Pointer(pE2)).FiColumn)*16)
				if zColl == uintptr(0) {
					zColl = uintptr(unsafe.Pointer(&_sqlite3StrBINARY))
				}
				if Xsqlite3_stricmp(tls, *(*uintptr)(unsafe.Pointer(pExpr + 8)), zColl) == 0 {
					goto _5
				}
			}
			/* No matches cause a break out of the loop */
			break
			goto _5
		_5:
			;
			i = i + 1
		}
		if i == n {
			bSortByGroup = libc.BoolInt32(libc.Int32FromUint16((*TWhereInfo)(unsafe.Pointer(pWInfo)).FwctrlFlags)&int32(WHERE_SORTBYGROUP) != 0)
			nOrderBy = n
			if libc.Int32FromUint16((*TWhereInfo)(unsafe.Pointer(pWInfo)).FwctrlFlags)&int32(WHERE_DISTINCTBY) != 0 && !(int32(*(*uint32)(unsafe.Pointer(pSrc + 24 + 4))&0x8000>>15) != 0) {
				eDistinct = int32(2) + bSortByGroup
			} else {
				if libc.Int32FromUint16((*TWhereInfo)(unsafe.Pointer(pWInfo)).FwctrlFlags)&int32(WHERE_GROUPBY) != 0 {
					eDistinct = int32(1) - bSortByGroup
				} else {
					if libc.Int32FromUint16((*TWhereInfo)(unsafe.Pointer(pWInfo)).FwctrlFlags)&int32(WHERE_WANT_DISTINCT) != 0 {
						eDistinct = int32(3)
					}
				}
			}
		}
	}
	/* Allocate the sqlite3_index_info structure
	 */
	pIdxInfo = _sqlite3DbMallocZero(tls, (*TParse)(unsafe.Pointer(pParse)).Fdb, uint64(uint64(96)+(libc.Uint64FromInt64(12)+libc.Uint64FromInt64(8))*libc.Uint64FromInt32(nTerm)+uint64(8)*libc.Uint64FromInt32(nOrderBy)+(uint64(libc.UintptrFromInt32(0)+32)+libc.Uint64FromInt32(nTerm)*uint64(8))))
	if pIdxInfo == uintptr(0) {
		_sqlite3ErrorMsg(tls, pParse, __ccgo_ts+1663, 0)
		return uintptr(0)
	}
	pHidden = pIdxInfo + 1*96
	pIdxCons = pHidden + 32 + uintptr(nTerm)*8
	pIdxOrderBy = pIdxCons + uintptr(nTerm)*12
	pUsage = pIdxOrderBy + uintptr(nOrderBy)*8
	(*Tsqlite3_index_info)(unsafe.Pointer(pIdxInfo)).FaConstraint = pIdxCons
	(*Tsqlite3_index_info)(unsafe.Pointer(pIdxInfo)).FaOrderBy = pIdxOrderBy
	(*Tsqlite3_index_info)(unsafe.Pointer(pIdxInfo)).FaConstraintUsage = pUsage
	(*Tsqlite3_index_info)(unsafe.Pointer(pIdxInfo)).FcolUsed = libc.Uint64FromInt64(libc.Int64FromUint64((*TSrcItem)(unsafe.Pointer(pSrc)).FcolUsed))
	if libc.BoolInt32((*TTable)(unsafe.Pointer(pTab)).FtabFlags&uint32(TF_WithoutRowid) == uint32(0)) == 0 {
		/* Ensure that all bits associated with PK columns are set. This is to
		 ** ensure they are available for cases like RIGHT joins or OR loops. */
		pPk = _sqlite3PrimaryKeyIndex(tls, pTab)
		i = 0
		for {
			if !(i < libc.Int32FromUint16((*TIndex)(unsafe.Pointer(pPk)).FnKeyCol)) {
				break
			}
			iCol = int32(**(**Ti16)(__ccgo_up((*TIndex)(unsafe.Pointer(pPk)).FaiColumn + uintptr(i)*2)))
			if iCol >= libc.Int32FromUint64(libc.Uint64FromInt64(8)*libc.Uint64FromInt32(8))-libc.Int32FromInt32(1) {
				iCol = libc.Int32FromUint64(libc.Uint64FromInt64(8)*libc.Uint64FromInt32(8)) - libc.Int32FromInt32(1)
			}
			**(**Tsqlite3_uint64)(__ccgo_up(pIdxInfo + 88)) |= libc.Uint64FromInt32(1) << iCol
			goto _8
		_8:
			;
			i = i + 1
		}
	}
	(*THiddenIndexInfo)(unsafe.Pointer(pHidden)).FpWC = pWC
	(*THiddenIndexInfo)(unsafe.Pointer(pHidden)).FpParse = pParse
	(*THiddenIndexInfo)(unsafe.Pointer(pHidden)).FeDistinct = eDistinct
	(*THiddenIndexInfo)(unsafe.Pointer(pHidden)).FmIn = uint32(0)
	p = pWC
	v10 = libc.Int32FromInt32(0)
	j = v10
	i = v10
	for {
		if !(p != 0) {
			break
		}
		nLast = i + (*TWhereClause)(unsafe.Pointer(p)).FnTerm
		pTerm = (*TWhereClause)(unsafe.Pointer(p)).Fa
		for {
			if !(i < nLast) {
				break
			}
			if libc.Int32FromUint16((*TWhereTerm)(unsafe.Pointer(pTerm)).FwtFlags)&int32(TERM_OK) == 0 {
				goto _11
			}
			(**(**Tsqlite3_index_constraint)(__ccgo_up(pIdxCons + uintptr(j)*12))).FiColumn = (*(*struct {
				FleftColumn int32
				FiField     int32
			})(unsafe.Pointer(pTerm + 32))).FleftColumn
			(**(**Tsqlite3_index_constraint)(__ccgo_up(pIdxCons + uintptr(j)*12))).FiTermOffset = i
			op = libc.Uint16FromInt32(libc.Int32FromUint16((*TWhereTerm)(unsafe.Pointer(pTerm)).FeOperator) & int32(WO_ALL))
			if libc.Int32FromUint16(op) == int32(WO_IN) {
				if libc.Int32FromUint16((*TWhereTerm)(unsafe.Pointer(pTerm)).FwtFlags)&int32(TERM_SLICE) == 0 {
					if j <= int32(31) {
						v12 = libc.Uint32FromInt32(1) << j
					} else {
						v12 = uint32(0)
					}
					**(**Tu32)(__ccgo_up(pHidden + 20)) |= v12
				}
				op = uint16(WO_EQ)
			}
			if libc.Int32FromUint16(op) == int32(WO_AUX) {
				(**(**Tsqlite3_index_constraint)(__ccgo_up(pIdxCons + uintptr(j)*12))).Fop = (*TWhereTerm)(unsafe.Pointer(pTerm)).FeMatchOp
			} else {
				if libc.Int32FromUint16(op)&(libc.Int32FromInt32(WO_ISNULL)|libc.Int32FromInt32(WO_IS)) != 0 {
					if libc.Int32FromUint16(op) == int32(WO_ISNULL) {
						(**(**Tsqlite3_index_constraint)(__ccgo_up(pIdxCons + uintptr(j)*12))).Fop = uint8(SQLITE_INDEX_CONSTRAINT_ISNULL)
					} else {
						(**(**Tsqlite3_index_constraint)(__ccgo_up(pIdxCons + uintptr(j)*12))).Fop = uint8(SQLITE_INDEX_CONSTRAINT_IS)
					}
				} else {
					(**(**Tsqlite3_index_constraint)(__ccgo_up(pIdxCons + uintptr(j)*12))).Fop = uint8(op)
					/* The direct assignment in the previous line is possible only because
					 ** the WO_ and SQLITE_INDEX_CONSTRAINT_ codes are identical.  The
					 ** following asserts verify this fact. */
					if libc.Int32FromUint16(op)&(libc.Int32FromInt32(WO_EQ)<<(libc.Int32FromInt32(TK_LT)-libc.Int32FromInt32(TK_EQ))|libc.Int32FromInt32(WO_EQ)<<(libc.Int32FromInt32(TK_LE)-libc.Int32FromInt32(TK_EQ))|libc.Int32FromInt32(WO_EQ)<<(libc.Int32FromInt32(TK_GT)-libc.Int32FromInt32(TK_EQ))|libc.Int32FromInt32(WO_EQ)<<(libc.Int32FromInt32(TK_GE)-libc.Int32FromInt32(TK_EQ))) != 0 && _sqlite3ExprIsVector(tls, (*TExpr)(unsafe.Pointer((*TWhereTerm)(unsafe.Pointer(pTerm)).FpExpr)).FpRight) != 0 {
						if j < int32(16) {
							mNoOmit = libc.Uint16FromInt32(int32(mNoOmit) | libc.Int32FromInt32(1)<<j)
						}
						if libc.Int32FromUint16(op) == libc.Int32FromInt32(WO_EQ)<<(libc.Int32FromInt32(TK_LT)-libc.Int32FromInt32(TK_EQ)) {
							(**(**Tsqlite3_index_constraint)(__ccgo_up(pIdxCons + uintptr(j)*12))).Fop = libc.Uint8FromInt32(libc.Int32FromInt32(WO_EQ) << (libc.Int32FromInt32(TK_LE) - libc.Int32FromInt32(TK_EQ)))
						}
						if libc.Int32FromUint16(op) == libc.Int32FromInt32(WO_EQ)<<(libc.Int32FromInt32(TK_GT)-libc.Int32FromInt32(TK_EQ)) {
							(**(**Tsqlite3_index_constraint)(__ccgo_up(pIdxCons + uintptr(j)*12))).Fop = libc.Uint8FromInt32(libc.Int32FromInt32(WO_EQ) << (libc.Int32FromInt32(TK_GE) - libc.Int32FromInt32(TK_EQ)))
						}
					}
				}
			}
			j = j + 1
			goto _11
		_11:
			;
			i = i + 1
			pTerm += 56
		}
		goto _9
	_9:
		;
		p = (*TWhereClause)(unsafe.Pointer(p)).FpOuter
	}
	(*Tsqlite3_index_info)(unsafe.Pointer(pIdxInfo)).FnConstraint = j
	v10 = libc.Int32FromInt32(0)
	j = v10
	i = v10
	for {
		if !(i < nOrderBy) {
			break
		}
		pExpr1 = (*(*TExprList_item)(unsafe.Pointer(pOrderBy + 8 + uintptr(i)*32))).FpExpr
		if _sqlite3ExprIsConstant(tls, uintptr(0), pExpr1) != 0 {
			goto _13
		}
		(**(**Tsqlite3_index_orderby)(__ccgo_up(pIdxOrderBy + uintptr(j)*8))).FiColumn = int32((*TExpr)(unsafe.Pointer(pExpr1)).FiColumn)
		(**(**Tsqlite3_index_orderby)(__ccgo_up(pIdxOrderBy + uintptr(j)*8))).Fdesc = libc.Uint8FromInt32(libc.Int32FromUint8((*(*TExprList_item)(unsafe.Pointer(pOrderBy + 8 + uintptr(i)*32))).Ffg.FsortFlags) & int32(KEYINFO_ORDER_DESC))
		j = j + 1
		goto _13
	_13:
		;
		i = i + 1
	}
	(*Tsqlite3_index_info)(unsafe.Pointer(pIdxInfo)).FnOrderBy = j
	**(**Tu16)(__ccgo_up(pmNoOmit)) = mNoOmit
	return pIdxInfo
}

// C documentation
//
//	/*
//	** Find a column named pCol in table pTab. If successful, set output
//	** parameter *piCol to the index of the column in the table and return
//	** SQLITE_OK. Otherwise, set *piCol to -1 and return an SQLite error
//	** code.
//	*/
func _alterFindCol(tls *libc.TLS, pParse uintptr, pTab uintptr, pCol uintptr, piCol uintptr) (r int32) {
	bp := tls.Alloc(16)
	defer tls.Free(16)
	var db, zCol, zDb, zName uintptr
	var iCol, rc int32
	_, _, _, _, _, _ = db, iCol, rc, zCol, zDb, zName
	db = (*TParse)(unsafe.Pointer(pParse)).Fdb
	zName = _sqlite3NameFromToken(tls, db, pCol)
	rc = int32(SQLITE_NOMEM)
	iCol = -int32(1)
	if zName != 0 {
		iCol = _sqlite3ColumnIndex(tls, pTab, zName)
		if iCol < 0 {
			_sqlite3ErrorMsg(tls, pParse, __ccgo_ts+11899, libc.VaList(bp+8, zName))
			rc = int32(SQLITE_ERROR)
		} else {
			rc = SQLITE_OK
		}
	}
	if rc == SQLITE_OK {
		zDb = (**(**TDb)(__ccgo_up((*Tsqlite3)(unsafe.Pointer(db)).FaDb + uintptr(_sqlite3SchemaToIndex(tls, db, (*TTable)(unsafe.Pointer(pTab)).FpSchema))*32))).FzDbSName
		zCol = (**(**TColumn)(__ccgo_up((*TTable)(unsafe.Pointer(pTab)).FaCol + uintptr(iCol)*16))).FzCnName
		if _sqlite3AuthCheck(tls, pParse, int32(SQLITE_ALTER_TABLE), zDb, (*TTable)(unsafe.Pointer(pTab)).FzName, zCol) != 0 {
			pTab = uintptr(0)
		}
	}
	_sqlite3DbFree(tls, db, zName)
	**(**int32)(__ccgo_up(piCol)) = iCol
	return rc
}

// C documentation
//
//	/*
//	** Buffer pCons, which is nCons bytes in size, contains the text of a
//	** NOT NULL or CHECK constraint that will be inserted into a CREATE TABLE
//	** statement. If successful, this function returns the size of the buffer in
//	** bytes not including any trailing whitespace or "--" style comments. Or,
//	** if an OOM occurs, it returns 0 and sets db->mallocFailed to true.
//	**
//	** C-style comments at the end are preserved.  "--" style comments are
//	** removed because the comment terminator might be \000, and we are about
//	** to insert the pCons[] text into the middle of a larger string, and that
//	** will have the effect of removing the comment terminator and messing up
//	** the syntax.
//	*/
func _alterRtrimConstraint(tls *libc.TLS, db uintptr, pCons uintptr, nCons int32) (r int32) {
	bp := tls.Alloc(32)
	defer tls.Free(32)
	var iEnd, iOff, nToken int32
	var zTmp uintptr
	var _ /* t at bp+0 */ int32
	_, _, _, _ = iEnd, iOff, nToken, zTmp
	zTmp = _sqlite3MPrintf(tls, db, __ccgo_ts+12039, libc.VaList(bp+16, nCons, pCons))
	iOff = 0
	iEnd = 0
	if zTmp == uintptr(0) {
		return 0
	}
	for int32(1) != 0 {
		**(**int32)(__ccgo_up(bp)) = 0
		nToken = int32(_sqlite3GetToken(tls, zTmp+uintptr(iOff), bp))
		if **(**int32)(__ccgo_up(bp)) == int32(TK_ILLEGAL) {
			break
		}
		if **(**int32)(__ccgo_up(bp)) != int32(TK_SPACE) && (**(**int32)(__ccgo_up(bp)) != int32(TK_COMMENT) || libc.Int32FromUint8(**(**Tu8)(__ccgo_up(zTmp + uintptr(iOff)))) != int32('-')) {
			iEnd = iOff + nToken
		}
		iOff = iOff + nToken
	}
	_sqlite3DbFree(tls, db, zTmp)
	return iEnd
}

// C documentation
//
//	/*
//	** This is the xExprCallback for a tree walker.  It is used to
//	** implement sqlite3ExprAnalyzeAggregates().  See sqlite3ExprAnalyzeAggregates
//	** for additional information.
//	*/
func _analyzeAggregate(tls *libc.TLS, pWalker uintptr, pExpr uintptr) (r int32) {
	bp := tls.Alloc(96)
	defer tls.Free(96)
	var enc Tu8
	var i, iDataCur, mxTerm, nArg, v5 int32
	var pAggInfo, pIEpr, pItem, pItem1, pNC, pOBList, pParse, pSrcList, v7 uintptr
	var _ /* tmp at bp+0 */ TExpr
	_, _, _, _, _, _, _, _, _, _, _, _, _, _, _ = enc, i, iDataCur, mxTerm, nArg, pAggInfo, pIEpr, pItem, pItem1, pNC, pOBList, pParse, pSrcList, v5, v7
	pNC = *(*uintptr)(unsafe.Pointer(pWalker + 40))
	pParse = (*TNameContext)(unsafe.Pointer(pNC)).FpParse
	pSrcList = (*TNameContext)(unsafe.Pointer(pNC)).FpSrcList
	pAggInfo = *(*uintptr)(unsafe.Pointer(pNC + 16))
	switch libc.Int32FromUint8((*TExpr)(unsafe.Pointer(pExpr)).Fop) {
	default:
		if (*TNameContext)(unsafe.Pointer(pNC)).FncFlags&int32(NC_InAggFunc) == 0 {
			break
		}
		if (*TParse)(unsafe.Pointer(pParse)).FpIdxEpr == uintptr(0) {
			break
		}
		pIEpr = (*TParse)(unsafe.Pointer(pParse)).FpIdxEpr
		for {
			if !(pIEpr != 0) {
				break
			}
			iDataCur = (*TIndexedExpr)(unsafe.Pointer(pIEpr)).FiDataCur
			if iDataCur < 0 {
				goto _1
			}
			if _sqlite3ExprCompare(tls, uintptr(0), pExpr, (*TIndexedExpr)(unsafe.Pointer(pIEpr)).FpExpr, iDataCur) == 0 {
				break
			}
			goto _1
		_1:
			;
			pIEpr = (*TIndexedExpr)(unsafe.Pointer(pIEpr)).FpIENext
		}
		if pIEpr == uintptr(0) {
			break
		}
		if !((*TExpr)(unsafe.Pointer(pExpr)).Fflags&libc.Uint32FromInt32(libc.Int32FromInt32(EP_WinFunc)|libc.Int32FromInt32(EP_Subrtn)) == libc.Uint32FromInt32(0)) {
			break
		}
		i = 0
		for {
			if !(i < (*TSrcList)(unsafe.Pointer(pSrcList)).FnSrc) {
				break
			}
			if (*(*TSrcItem)(unsafe.Pointer(pSrcList + 8 + uintptr(i)*80))).FiCursor == (*TIndexedExpr)(unsafe.Pointer(pIEpr)).FiDataCur {
				break
			}
			goto _2
		_2:
			;
			i = i + 1
		}
		if i >= (*TSrcList)(unsafe.Pointer(pSrcList)).FnSrc {
			break
		}
		if (*TExpr)(unsafe.Pointer(pExpr)).FpAggInfo != uintptr(0) {
			break
		} /* Resolved by outer context */
		if (*TParse)(unsafe.Pointer(pParse)).FnErr != 0 {
			return int32(WRC_Abort)
		}
		/* If we reach this point, it means that expression pExpr can be
		 ** translated into a reference to an index column as described by
		 ** pIEpr.
		 */
		libc.Xmemset(tls, bp, 0, uint64(72))
		(**(**TExpr)(__ccgo_up(bp))).Fop = uint8(TK_AGG_COLUMN)
		(**(**TExpr)(__ccgo_up(bp))).FiTable = (*TIndexedExpr)(unsafe.Pointer(pIEpr)).FiIdxCur
		(**(**TExpr)(__ccgo_up(bp))).FiColumn = int16((*TIndexedExpr)(unsafe.Pointer(pIEpr)).FiIdxCol)
		_findOrCreateAggInfoColumn(tls, pParse, pAggInfo, bp)
		if (*TParse)(unsafe.Pointer(pParse)).FnErr != 0 {
			return int32(WRC_Abort)
		}
		(**(**TAggInfo_col)(__ccgo_up((*TAggInfo)(unsafe.Pointer(pAggInfo)).FaCol + uintptr((**(**TExpr)(__ccgo_up(bp))).FiAgg)*32))).FpCExpr = pExpr
		(*TExpr)(unsafe.Pointer(pExpr)).FpAggInfo = pAggInfo
		(*TExpr)(unsafe.Pointer(pExpr)).FiAgg = (**(**TExpr)(__ccgo_up(bp))).FiAgg
		return int32(WRC_Prune)
	case int32(TK_IF_NULL_ROW):
		fallthrough
	case int32(TK_AGG_COLUMN):
		fallthrough
	case int32(TK_COLUMN):
		/* Check to see if the column is in one of the tables in the FROM
		 ** clause of the aggregate query */
		if pSrcList != uintptr(0) {
			pItem = pSrcList + 8
			i = 0
			for {
				if !(i < (*TSrcList)(unsafe.Pointer(pSrcList)).FnSrc) {
					break
				}
				if (*TExpr)(unsafe.Pointer(pExpr)).FiTable == (*TSrcItem)(unsafe.Pointer(pItem)).FiCursor {
					_findOrCreateAggInfoColumn(tls, pParse, pAggInfo, pExpr)
					break
				} /* endif pExpr->iTable==pItem->iCursor */
				goto _3
			_3:
				;
				i = i + 1
				pItem += 80
			} /* end loop over pSrcList */
		}
		return WRC_Continue
	case int32(TK_AGG_FUNCTION):
		if (*TNameContext)(unsafe.Pointer(pNC)).FncFlags&int32(NC_InAggFunc) == 0 && (*TWalker)(unsafe.Pointer(pWalker)).FwalkerDepth == libc.Int32FromUint8((*TExpr)(unsafe.Pointer(pExpr)).Fop2) && (*TExpr)(unsafe.Pointer(pExpr)).FpAggInfo == uintptr(0) {
			/* Check to see if pExpr is a duplicate of another aggregate
			 ** function that is already in the pAggInfo structure
			 */
			pItem1 = (*TAggInfo)(unsafe.Pointer(pAggInfo)).FaFunc
			mxTerm = **(**int32)(__ccgo_up((*TParse)(unsafe.Pointer(pParse)).Fdb + 136 + 2*4))
			i = 0
			for {
				if !(i < (*TAggInfo)(unsafe.Pointer(pAggInfo)).FnFunc) {
					break
				}
				if (*TAggInfo_func)(unsafe.Pointer(pItem1)).FpFExpr == pExpr {
					break
				}
				if _sqlite3ExprCompare(tls, uintptr(0), (*TAggInfo_func)(unsafe.Pointer(pItem1)).FpFExpr, pExpr, -int32(1)) == 0 {
					break
				}
				goto _4
			_4:
				;
				i = i + 1
				pItem1 += 32
			}
			if i > mxTerm {
				_sqlite3ErrorMsg(tls, pParse, __ccgo_ts+8607, libc.VaList(bp+80, mxTerm))
				i = mxTerm
			} else {
				if i >= (*TAggInfo)(unsafe.Pointer(pAggInfo)).FnFunc {
					/* pExpr is original.  Make a new entry in pAggInfo->aFunc[]
					 */
					enc = (*Tsqlite3)(unsafe.Pointer((*TParse)(unsafe.Pointer(pParse)).Fdb)).Fenc
					i = _addAggInfoFunc(tls, (*TParse)(unsafe.Pointer(pParse)).Fdb, pAggInfo)
					if i >= 0 {
						pItem1 = (*TAggInfo)(unsafe.Pointer(pAggInfo)).FaFunc + uintptr(i)*32
						(*TAggInfo_func)(unsafe.Pointer(pItem1)).FpFExpr = pExpr
						if *(*uintptr)(unsafe.Pointer(pExpr + 32)) != 0 {
							v5 = (*TExprList)(unsafe.Pointer(*(*uintptr)(unsafe.Pointer(pExpr + 32)))).FnExpr
						} else {
							v5 = 0
						}
						nArg = v5
						(*TAggInfo_func)(unsafe.Pointer(pItem1)).FpFunc = _sqlite3FindFunction(tls, (*TParse)(unsafe.Pointer(pParse)).Fdb, *(*uintptr)(unsafe.Pointer(pExpr + 8)), nArg, enc, uint8(0))
						if (*TExpr)(unsafe.Pointer(pExpr)).FpLeft != 0 && (*TFuncDef)(unsafe.Pointer((*TAggInfo_func)(unsafe.Pointer(pItem1)).FpFunc)).FfuncFlags&uint32(SQLITE_FUNC_NEEDCOLL) == uint32(0) {
							v7 = pParse + 56
							v5 = *(*int32)(unsafe.Pointer(v7))
							*(*int32)(unsafe.Pointer(v7)) = *(*int32)(unsafe.Pointer(v7)) + 1
							(*TAggInfo_func)(unsafe.Pointer(pItem1)).FiOBTab = v5
							pOBList = *(*uintptr)(unsafe.Pointer((*TExpr)(unsafe.Pointer(pExpr)).FpLeft + 32))
							if (*TExprList)(unsafe.Pointer(pOBList)).FnExpr == int32(1) && nArg == int32(1) && _sqlite3ExprCompare(tls, uintptr(0), (*(*TExprList_item)(unsafe.Pointer(pOBList + 8))).FpExpr, (*(*TExprList_item)(unsafe.Pointer(*(*uintptr)(unsafe.Pointer(pExpr + 32)) + 8))).FpExpr, 0) == 0 {
								(*TAggInfo_func)(unsafe.Pointer(pItem1)).FbOBPayload = uint8(0)
								(*TAggInfo_func)(unsafe.Pointer(pItem1)).FbOBUnique = libc.BoolUint8((*TExpr)(unsafe.Pointer(pExpr)).Fflags&libc.Uint32FromInt32(libc.Int32FromInt32(EP_Distinct)) != libc.Uint32FromInt32(0))
							} else {
								(*TAggInfo_func)(unsafe.Pointer(pItem1)).FbOBPayload = uint8(1)
							}
							(*TAggInfo_func)(unsafe.Pointer(pItem1)).FbUseSubtype = libc.BoolUint8((*TFuncDef)(unsafe.Pointer((*TAggInfo_func)(unsafe.Pointer(pItem1)).FpFunc)).FfuncFlags&uint32(SQLITE_SUBTYPE) != uint32(0))
						} else {
							(*TAggInfo_func)(unsafe.Pointer(pItem1)).FiOBTab = -int32(1)
						}
						if (*TExpr)(unsafe.Pointer(pExpr)).Fflags&libc.Uint32FromInt32(libc.Int32FromInt32(EP_Distinct)) != uint32(0) && !((*TAggInfo_func)(unsafe.Pointer(pItem1)).FbOBUnique != 0) {
							v7 = pParse + 56
							v5 = *(*int32)(unsafe.Pointer(v7))
							*(*int32)(unsafe.Pointer(v7)) = *(*int32)(unsafe.Pointer(v7)) + 1
							(*TAggInfo_func)(unsafe.Pointer(pItem1)).FiDistinct = v5
						} else {
							(*TAggInfo_func)(unsafe.Pointer(pItem1)).FiDistinct = -int32(1)
						}
					}
				}
			}
			/* Make pExpr point to the appropriate pAggInfo->aFunc[] entry
			 */
			(*TExpr)(unsafe.Pointer(pExpr)).FiAgg = int16(i)
			(*TExpr)(unsafe.Pointer(pExpr)).FpAggInfo = pAggInfo
			return int32(WRC_Prune)
		} else {
			return WRC_Continue
		}
	}
	return WRC_Continue
}

// C documentation
//
//	/*
//	** Generate code to do an analysis of all indices associated with
//	** a single table.
//	*/
func _analyzeOneTable(tls *libc.TLS, pParse uintptr, pTab uintptr, pOnlyIdx uintptr, iStatCur int32, iMem int32, iTab int32) {
	var aGotoChng, db, pColl, pIdx, pPk, pStat1, pX, v, zIdxName uintptr
	var addrGotoEnd, addrIsNull, addrNext, addrNextRow, doOnce, endDistinctTest, i, iDb, iIdxCur, iTabCur, j, j1, j2, j3, jZeroRows, k, mxCol, nCol, nColTest, nColX, regChng, regCol, regDLt, regEq, regIdxname, regKey, regLt, regNewRowid, regPrev, regRowid, regSample, regSampleRowid, regStat, regStat1, regTabname, regTemp, regTemp2, v1, v2, v3, v4, v5, v6, v7, v8, v9 int32
	var needTableCnt, seekOp Tu8
	_, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _ = aGotoChng, addrGotoEnd, addrIsNull, addrNext, addrNextRow, db, doOnce, endDistinctTest, i, iDb, iIdxCur, iTabCur, j, j1, j2, j3, jZeroRows, k, mxCol, nCol, nColTest, nColX, needTableCnt, pColl, pIdx, pPk, pStat1, pX, regChng, regCol, regDLt, regEq, regIdxname, regKey, regLt, regNewRowid, regPrev, regRowid, regSample, regSampleRowid, regStat, regStat1, regTabname, regTemp, regTemp2, seekOp, v, zIdxName, v1, v2, v3, v4, v5, v6, v7, v8, v9
	db = (*TParse)(unsafe.Pointer(pParse)).Fdb /* Loop counter */
	jZeroRows = -int32(1)                      /* Index of database containing pTab */
	needTableCnt = uint8(1)
	v1 = iMem
	iMem = iMem + 1 /* True to count the table */
	regNewRowid = v1
	v2 = iMem
	iMem = iMem + 1 /* Rowid for the inserted record */
	regStat = v2
	v3 = iMem
	iMem = iMem + 1 /* Register to hold StatAccum object */
	regChng = v3
	v4 = iMem
	iMem = iMem + 1 /* Index of changed index field */
	regRowid = v4
	v5 = iMem
	iMem = iMem + 1 /* Rowid argument passed to stat_push() */
	regTemp = v5
	v6 = iMem
	iMem = iMem + 1 /* Temporary use register */
	regTemp2 = v6
	v7 = iMem
	iMem = iMem + 1 /* Second temporary use register */
	regTabname = v7
	v8 = iMem
	iMem = iMem + 1 /* Register containing table name */
	regIdxname = v8
	v9 = iMem
	iMem = iMem + 1   /* Register containing index name */
	regStat1 = v9     /* Value for the stat column of sqlite_stat1 */
	regPrev = iMem    /* MUST BE LAST (see below) */
	doOnce = int32(1) /* Flag for a one-time computation */
	pStat1 = uintptr(0)
	_sqlite3TouchRegister(tls, pParse, iMem)
	v = _sqlite3GetVdbe(tls, pParse)
	if v == uintptr(0) || pTab == uintptr(0) {
		return
	}
	if !(libc.Int32FromUint8((*TTable)(unsafe.Pointer(pTab)).FeTabType) == libc.Int32FromInt32(TABTYP_NORM)) {
		/* Do not gather statistics on views or virtual tables */
		return
	}
	if Xsqlite3_strlike(tls, __ccgo_ts+13023, (*TTable)(unsafe.Pointer(pTab)).FzName, uint32('\\')) == 0 {
		/* Do not gather statistics on system tables */
		return
	}
	iDb = _sqlite3SchemaToIndex(tls, db, (*TTable)(unsafe.Pointer(pTab)).FpSchema)
	if _sqlite3AuthCheck(tls, pParse, int32(SQLITE_ANALYZE), (*TTable)(unsafe.Pointer(pTab)).FzName, uintptr(0), (**(**TDb)(__ccgo_up((*Tsqlite3)(unsafe.Pointer(db)).FaDb + uintptr(iDb)*32))).FzDbSName) != 0 {
		return
	}
	if (*Tsqlite3)(unsafe.Pointer(db)).FxPreUpdateCallback != 0 {
		pStat1 = _sqlite3DbMallocZero(tls, db, uint64(libc.Uint64FromInt64(120)+libc.Uint64FromInt32(13)))
		if pStat1 == uintptr(0) {
			return
		}
		(*TTable)(unsafe.Pointer(pStat1)).FzName = pStat1 + 1*120
		libc.Xmemcpy(tls, (*TTable)(unsafe.Pointer(pStat1)).FzName, __ccgo_ts+12826, uint64(13))
		(*TTable)(unsafe.Pointer(pStat1)).FnCol = int16(3)
		(*TTable)(unsafe.Pointer(pStat1)).FiPKey = int16(-int32(1))
		_sqlite3VdbeAddOp4(tls, (*TParse)(unsafe.Pointer(pParse)).FpVdbe, int32(OP_Noop), 0, 0, 0, pStat1, -int32(7))
	}
	/* Establish a read-lock on the table at the shared-cache level.
	 ** Open a read-only cursor on the table. Also allocate a cursor number
	 ** to use for scanning indexes (iIdxCur). No index cursor is opened at
	 ** this time though.  */
	_sqlite3TableLock(tls, pParse, iDb, (*TTable)(unsafe.Pointer(pTab)).Ftnum, uint8(0), (*TTable)(unsafe.Pointer(pTab)).FzName)
	v1 = iTab
	iTab = iTab + 1
	iTabCur = v1
	v1 = iTab
	iTab = iTab + 1
	iIdxCur = v1
	if (*TParse)(unsafe.Pointer(pParse)).FnTab > iTab {
		v1 = (*TParse)(unsafe.Pointer(pParse)).FnTab
	} else {
		v1 = iTab
	}
	(*TParse)(unsafe.Pointer(pParse)).FnTab = v1
	_sqlite3OpenTable(tls, pParse, iTabCur, iDb, pTab, int32(OP_OpenRead))
	_sqlite3VdbeLoadString(tls, v, regTabname, (*TTable)(unsafe.Pointer(pTab)).FzName)
	pIdx = (*TTable)(unsafe.Pointer(pTab)).FpIndex
	for {
		if !(pIdx != 0) {
			break
		} /* Number of columns to test for changes */
		if pOnlyIdx != 0 && pOnlyIdx != pIdx {
			goto _13
		}
		if (*TIndex)(unsafe.Pointer(pIdx)).FpPartIdxWhere == uintptr(0) {
			needTableCnt = uint8(0)
		}
		if !((*TTable)(unsafe.Pointer(pTab)).FtabFlags&libc.Uint32FromInt32(TF_WithoutRowid) == libc.Uint32FromInt32(0)) && int32(uint32(*(*uint16)(unsafe.Pointer(pIdx + 100))&0x3>>0)) == int32(SQLITE_IDXTYPE_PRIMARYKEY) {
			nCol = libc.Int32FromUint16((*TIndex)(unsafe.Pointer(pIdx)).FnKeyCol)
			zIdxName = (*TTable)(unsafe.Pointer(pTab)).FzName
			nColTest = nCol - int32(1)
		} else {
			nCol = libc.Int32FromUint16((*TIndex)(unsafe.Pointer(pIdx)).FnColumn)
			zIdxName = (*TIndex)(unsafe.Pointer(pIdx)).FzName
			if int32(uint32(*(*uint16)(unsafe.Pointer(pIdx + 100))&0x8>>3)) != 0 {
				v1 = libc.Int32FromUint16((*TIndex)(unsafe.Pointer(pIdx)).FnKeyCol) - int32(1)
			} else {
				v1 = nCol - int32(1)
			}
			nColTest = v1
		}
		/* Populate the register containing the index name. */
		_sqlite3VdbeLoadString(tls, v, regIdxname, zIdxName)
		/*
		 ** Pseudo-code for loop that calls stat_push():
		 **
		 **   regChng = 0
		 **   Rewind csr
		 **   if eof(csr){
		 **      stat_init() with count = 0;
		 **      goto end_of_scan;
		 **   }
		 **   count()
		 **   stat_init()
		 **   goto chng_addr_0;
		 **
		 **  next_row:
		 **   regChng = 0
		 **   if( idx(0) != regPrev(0) ) goto chng_addr_0
		 **   regChng = 1
		 **   if( idx(1) != regPrev(1) ) goto chng_addr_1
		 **   ...
		 **   regChng = N
		 **   goto chng_addr_N
		 **
		 **  chng_addr_0:
		 **   regPrev(0) = idx(0)
		 **  chng_addr_1:
		 **   regPrev(1) = idx(1)
		 **  ...
		 **
		 **  endDistinctTest:
		 **   regRowid = idx(rowid)
		 **   stat_push(P, regChng, regRowid)
		 **   Next csr
		 **   if !eof(csr) goto next_row;
		 **
		 **  end_of_scan:
		 */
		/* Make sure there are enough memory cells allocated to accommodate
		 ** the regPrev array and a trailing rowid (the rowid slot is required
		 ** when building a record to insert into the sample column of
		 ** the sqlite_stat4 table.  */
		_sqlite3TouchRegister(tls, pParse, regPrev+nColTest)
		/* Open a read-only cursor on the index being analyzed. */
		_sqlite3VdbeAddOp3(tls, v, int32(OP_OpenRead), iIdxCur, libc.Int32FromUint32((*TIndex)(unsafe.Pointer(pIdx)).Ftnum), iDb)
		_sqlite3VdbeSetP4KeyInfo(tls, pParse, pIdx)
		/* Implementation of the following:
		 **
		 **   regChng = 0
		 **   Rewind csr
		 **   if eof(csr){
		 **      stat_init() with count = 0;
		 **      goto end_of_scan;
		 **   }
		 **   count()
		 **   stat_init()
		 **   goto chng_addr_0;
		 */
		_sqlite3VdbeAddOp2(tls, v, int32(OP_Integer), (*Tsqlite3)(unsafe.Pointer(db)).FnAnalysisLimit, regTemp2)
		/* Arguments to stat_init():
		 **    (1) the number of columns in the index including the rowid
		 **        (or for a WITHOUT ROWID table, the number of PK columns),
		 **    (2) the number of columns in the key without the rowid/pk
		 **    (3) estimated number of rows in the index. */
		_sqlite3VdbeAddOp2(tls, v, int32(OP_Integer), nCol, regStat+int32(1))
		_sqlite3VdbeAddOp2(tls, v, int32(OP_Integer), libc.Int32FromUint16((*TIndex)(unsafe.Pointer(pIdx)).FnKeyCol), regRowid)
		_sqlite3VdbeAddOp3(tls, v, int32(OP_Count), iIdxCur, regTemp, libc.BoolInt32((*Tsqlite3)(unsafe.Pointer(db)).FdbOptFlags&libc.Uint32FromInt32(libc.Int32FromInt32(SQLITE_Stat4)) != uint32(0)))
		_sqlite3VdbeAddFunctionCall(tls, pParse, 0, regStat+int32(1), regStat, int32(4), uintptr(unsafe.Pointer(&_statInitFuncdef)), 0)
		addrGotoEnd = _sqlite3VdbeAddOp1(tls, v, int32(OP_Rewind), iIdxCur)
		_sqlite3VdbeAddOp2(tls, v, int32(OP_Integer), 0, regChng)
		addrNextRow = _sqlite3VdbeCurrentAddr(tls, v)
		if nColTest > 0 {
			endDistinctTest = _sqlite3VdbeMakeLabel(tls, pParse) /* Array of jump instruction addresses */
			aGotoChng = _sqlite3DbMallocRawNN(tls, db, uint64(uint64(4)*libc.Uint64FromInt32(nColTest)))
			if aGotoChng == uintptr(0) {
				goto _13
			}
			/*
			 **  next_row:
			 **   regChng = 0
			 **   if( idx(0) != regPrev(0) ) goto chng_addr_0
			 **   regChng = 1
			 **   if( idx(1) != regPrev(1) ) goto chng_addr_1
			 **   ...
			 **   regChng = N
			 **   goto endDistinctTest
			 */
			_sqlite3VdbeAddOp0(tls, v, int32(OP_Goto))
			addrNextRow = _sqlite3VdbeCurrentAddr(tls, v)
			if nColTest == int32(1) && libc.Int32FromUint16((*TIndex)(unsafe.Pointer(pIdx)).FnKeyCol) == int32(1) && libc.Int32FromUint8((*TIndex)(unsafe.Pointer(pIdx)).FonError) != OE_None {
				/* For a single-column UNIQUE index, once we have found a non-NULL
				 ** row, we know that all the rest will be distinct, so skip
				 ** subsequent distinctness tests. */
				_sqlite3VdbeAddOp2(tls, v, int32(OP_NotNull), regPrev, endDistinctTest)
			}
			i = 0
			for {
				if !(i < nColTest) {
					break
				}
				pColl = _sqlite3LocateCollSeq(tls, pParse, **(**uintptr)(__ccgo_up((*TIndex)(unsafe.Pointer(pIdx)).FazColl + uintptr(i)*8)))
				_sqlite3VdbeAddOp2(tls, v, int32(OP_Integer), i, regChng)
				_sqlite3VdbeAddOp3(tls, v, int32(OP_Column), iIdxCur, i, regTemp)
				**(**int32)(__ccgo_up(aGotoChng + uintptr(i)*4)) = _sqlite3VdbeAddOp4(tls, v, int32(OP_Ne), regTemp, 0, regPrev+i, pColl, -int32(2))
				_sqlite3VdbeChangeP5(tls, v, uint16(SQLITE_NULLEQ))
				goto _15
			_15:
				;
				i = i + 1
			}
			_sqlite3VdbeAddOp2(tls, v, int32(OP_Integer), nColTest, regChng)
			_sqlite3VdbeGoto(tls, v, endDistinctTest)
			/*
			 **  chng_addr_0:
			 **   regPrev(0) = idx(0)
			 **  chng_addr_1:
			 **   regPrev(1) = idx(1)
			 **  ...
			 */
			_sqlite3VdbeJumpHere(tls, v, addrNextRow-int32(1))
			i = 0
			for {
				if !(i < nColTest) {
					break
				}
				_sqlite3VdbeJumpHere(tls, v, **(**int32)(__ccgo_up(aGotoChng + uintptr(i)*4)))
				_sqlite3VdbeAddOp3(tls, v, int32(OP_Column), iIdxCur, i, regPrev+i)
				goto _16
			_16:
				;
				i = i + 1
			}
			_sqlite3VdbeResolveLabel(tls, v, endDistinctTest)
			_sqlite3DbFree(tls, db, aGotoChng)
		}
		/*
		 **  chng_addr_N:
		 **   regRowid = idx(rowid)            // STAT4 only
		 **   stat_push(P, regChng, regRowid)  // 3rd parameter STAT4 only
		 **   Next csr
		 **   if !eof(csr) goto next_row;
		 */
		if (*Tsqlite3)(unsafe.Pointer(db)).FdbOptFlags&libc.Uint32FromInt32(libc.Int32FromInt32(SQLITE_Stat4)) == uint32(0) {
			if (*TTable)(unsafe.Pointer(pTab)).FtabFlags&uint32(TF_WithoutRowid) == uint32(0) {
				_sqlite3VdbeAddOp2(tls, v, int32(OP_IdxRowid), iIdxCur, regRowid)
			} else {
				pPk = _sqlite3PrimaryKeyIndex(tls, (*TIndex)(unsafe.Pointer(pIdx)).FpTable)
				regKey = _sqlite3GetTempRange(tls, pParse, libc.Int32FromUint16((*TIndex)(unsafe.Pointer(pPk)).FnKeyCol))
				j = 0
				for {
					if !(j < libc.Int32FromUint16((*TIndex)(unsafe.Pointer(pPk)).FnKeyCol)) {
						break
					}
					k = _sqlite3TableColumnToIndex(tls, pIdx, int32(**(**Ti16)(__ccgo_up((*TIndex)(unsafe.Pointer(pPk)).FaiColumn + uintptr(j)*2))))
					_sqlite3VdbeAddOp3(tls, v, int32(OP_Column), iIdxCur, k, regKey+j)
					goto _17
				_17:
					;
					j = j + 1
				}
				_sqlite3VdbeAddOp3(tls, v, int32(OP_MakeRecord), regKey, libc.Int32FromUint16((*TIndex)(unsafe.Pointer(pPk)).FnKeyCol), regRowid)
				_sqlite3ReleaseTempRange(tls, pParse, regKey, libc.Int32FromUint16((*TIndex)(unsafe.Pointer(pPk)).FnKeyCol))
			}
		}
		_sqlite3VdbeAddFunctionCall(tls, pParse, int32(1), regStat, regTemp, libc.Int32FromInt32(2)+libc.Int32FromInt32(IsStat4), uintptr(unsafe.Pointer(&_statPushFuncdef)), 0)
		if (*Tsqlite3)(unsafe.Pointer(db)).FnAnalysisLimit != 0 {
			j1 = _sqlite3VdbeAddOp1(tls, v, int32(OP_IsNull), regTemp)
			j2 = _sqlite3VdbeAddOp1(tls, v, int32(OP_If), regTemp)
			j3 = _sqlite3VdbeAddOp4Int(tls, v, int32(OP_SeekGT), iIdxCur, 0, regPrev, int32(1))
			_sqlite3VdbeJumpHere(tls, v, j1)
			_sqlite3VdbeAddOp2(tls, v, int32(OP_Next), iIdxCur, addrNextRow)
			_sqlite3VdbeJumpHere(tls, v, j2)
			_sqlite3VdbeJumpHere(tls, v, j3)
		} else {
			_sqlite3VdbeAddOp2(tls, v, int32(OP_Next), iIdxCur, addrNextRow)
		}
		/* Add the entry to the stat1 table. */
		if (*TIndex)(unsafe.Pointer(pIdx)).FpPartIdxWhere != 0 {
			/* Partial indexes might get a zero-entry in sqlite_stat1.  But
			 ** an empty table is omitted from sqlite_stat1. */
			_sqlite3VdbeJumpHere(tls, v, addrGotoEnd)
			addrGotoEnd = 0
		}
		_callStatGet(tls, pParse, regStat, STAT_GET_STAT1, regStat1)
		_sqlite3VdbeAddOp4(tls, v, int32(OP_MakeRecord), regTabname, int32(3), regTemp, __ccgo_ts+13033, 0)
		_sqlite3VdbeAddOp2(tls, v, int32(OP_NewRowid), iStatCur, regNewRowid)
		_sqlite3VdbeAddOp3(tls, v, int32(OP_Insert), iStatCur, regTemp, regNewRowid)
		_sqlite3VdbeChangeP4(tls, v, -int32(1), pStat1, -int32(5))
		_sqlite3VdbeChangeP5(tls, v, uint16(OPFLAG_APPEND))
		/* Add the entries to the stat4 table. */
		if (*Tsqlite3)(unsafe.Pointer(db)).FdbOptFlags&libc.Uint32FromInt32(libc.Int32FromInt32(SQLITE_Stat4)) == uint32(0) && (*Tsqlite3)(unsafe.Pointer(db)).FnAnalysisLimit == 0 {
			regEq = regStat1
			regLt = regStat1 + int32(1)
			regDLt = regStat1 + int32(2)
			regSample = regStat1 + int32(3)
			regCol = regStat1 + int32(4)
			regSampleRowid = regCol + nCol
			if (*TTable)(unsafe.Pointer(pTab)).FtabFlags&uint32(TF_WithoutRowid) == uint32(0) {
				v1 = int32(OP_NotExists)
			} else {
				v1 = int32(OP_NotFound)
			}
			seekOp = libc.Uint8FromInt32(v1)
			/* No STAT4 data is generated if the number of rows is zero */
			if addrGotoEnd == 0 {
				_sqlite3VdbeAddOp2(tls, v, int32(OP_Cast), regStat1, int32(SQLITE_AFF_INTEGER))
				addrGotoEnd = _sqlite3VdbeAddOp1(tls, v, int32(OP_IfNot), regStat1)
			}
			if doOnce != 0 {
				mxCol = nCol
				/* Compute the maximum number of columns in any index */
				pX = (*TTable)(unsafe.Pointer(pTab)).FpIndex
				for {
					if !(pX != 0) {
						break
					} /* Number of columns in pX */
					if !((*TTable)(unsafe.Pointer(pTab)).FtabFlags&libc.Uint32FromInt32(TF_WithoutRowid) == libc.Uint32FromInt32(0)) && int32(uint32(*(*uint16)(unsafe.Pointer(pX + 100))&0x3>>0)) == int32(SQLITE_IDXTYPE_PRIMARYKEY) {
						nColX = libc.Int32FromUint16((*TIndex)(unsafe.Pointer(pX)).FnKeyCol)
					} else {
						nColX = libc.Int32FromUint16((*TIndex)(unsafe.Pointer(pX)).FnColumn)
					}
					if nColX > mxCol {
						mxCol = nColX
					}
					goto _19
				_19:
					;
					pX = (*TIndex)(unsafe.Pointer(pX)).FpNext
				}
				/* Allocate space to compute results for the largest index */
				_sqlite3TouchRegister(tls, pParse, regCol+mxCol)
				doOnce = 0
				_sqlite3ClearTempRegCache(tls, pParse) /* tag-20230325-1 */
			}
			addrNext = _sqlite3VdbeCurrentAddr(tls, v)
			_callStatGet(tls, pParse, regStat, int32(STAT_GET_ROWID), regSampleRowid)
			addrIsNull = _sqlite3VdbeAddOp1(tls, v, int32(OP_IsNull), regSampleRowid)
			_callStatGet(tls, pParse, regStat, int32(STAT_GET_NEQ), regEq)
			_callStatGet(tls, pParse, regStat, int32(STAT_GET_NLT), regLt)
			_callStatGet(tls, pParse, regStat, int32(STAT_GET_NDLT), regDLt)
			_sqlite3VdbeAddOp4Int(tls, v, libc.Int32FromUint8(seekOp), iTabCur, addrNext, regSampleRowid, 0)
			i = 0
			for {
				if !(i < nCol) {
					break
				}
				_sqlite3ExprCodeLoadIndexColumn(tls, pParse, pIdx, iTabCur, i, regCol+i)
				goto _20
			_20:
				;
				i = i + 1
			}
			_sqlite3VdbeAddOp3(tls, v, int32(OP_MakeRecord), regCol, nCol, regSample)
			_sqlite3VdbeAddOp3(tls, v, int32(OP_MakeRecord), regTabname, int32(6), regTemp)
			_sqlite3VdbeAddOp2(tls, v, int32(OP_NewRowid), iStatCur+int32(1), regNewRowid)
			_sqlite3VdbeAddOp3(tls, v, int32(OP_Insert), iStatCur+int32(1), regTemp, regNewRowid)
			_sqlite3VdbeAddOp2(tls, v, int32(OP_Goto), int32(1), addrNext) /* P1==1 for end-of-loop */
			_sqlite3VdbeJumpHere(tls, v, addrIsNull)
		}
		/* End of analysis */
		if addrGotoEnd != 0 {
			_sqlite3VdbeJumpHere(tls, v, addrGotoEnd)
		}
		goto _13
	_13:
		;
		pIdx = (*TIndex)(unsafe.Pointer(pIdx)).FpNext
	}
	/* Create a single sqlite_stat1 entry containing NULL as the index
	 ** name and the row count as the content.
	 */
	if pOnlyIdx == uintptr(0) && needTableCnt != 0 {
		_sqlite3VdbeAddOp2(tls, v, int32(OP_Count), iTabCur, regStat1)
		jZeroRows = _sqlite3VdbeAddOp1(tls, v, int32(OP_IfNot), regStat1)
		_sqlite3VdbeAddOp2(tls, v, int32(OP_Null), 0, regIdxname)
		_sqlite3VdbeAddOp4(tls, v, int32(OP_MakeRecord), regTabname, int32(3), regTemp, __ccgo_ts+13033, 0)
		_sqlite3VdbeAddOp2(tls, v, int32(OP_NewRowid), iStatCur, regNewRowid)
		_sqlite3VdbeAddOp3(tls, v, int32(OP_Insert), iStatCur, regTemp, regNewRowid)
		_sqlite3VdbeChangeP5(tls, v, uint16(OPFLAG_APPEND))
		_sqlite3VdbeChangeP4(tls, v, -int32(1), pStat1, -int32(5))
		_sqlite3VdbeJumpHere(tls, v, jZeroRows)
	}
}

// C documentation
//
//	/*
//	** Generate code that will do an analysis of a single table in
//	** a database.  If pOnlyIdx is not NULL then it is a single index
//	** in pTab that should be analyzed.
//	*/
func _analyzeTable(tls *libc.TLS, pParse uintptr, pTab uintptr, pOnlyIdx uintptr) {
	var iDb, iStatCur int32
	_, _ = iDb, iStatCur
	iDb = _sqlite3SchemaToIndex(tls, (*TParse)(unsafe.Pointer(pParse)).Fdb, (*TTable)(unsafe.Pointer(pTab)).FpSchema)
	_sqlite3BeginWriteOperation(tls, pParse, 0, iDb)
	iStatCur = (*TParse)(unsafe.Pointer(pParse)).FnTab
	**(**int32)(__ccgo_up(pParse + 56)) += int32(3)
	if pOnlyIdx != 0 {
		_openStatTable(tls, pParse, iDb, iStatCur, (*TIndex)(unsafe.Pointer(pOnlyIdx)).FzName, __ccgo_ts+13037)
	} else {
		_openStatTable(tls, pParse, iDb, iStatCur, (*TTable)(unsafe.Pointer(pTab)).FzName, __ccgo_ts+13041)
	}
	_analyzeOneTable(tls, pParse, pTab, pOnlyIdx, iStatCur, (*TParse)(unsafe.Pointer(pParse)).FnMem+int32(1), (*TParse)(unsafe.Pointer(pParse)).FnTab)
	_loadAnalysis(tls, pParse, iDb)
}

// C documentation
//
//	/*
//	** An SQL user-function registered to do the work of an ATTACH statement. The
//	** three arguments to the function come directly from an attach statement:
//	**
//	**     ATTACH DATABASE x AS y KEY z
//	**
//	**     SELECT sqlite_attach(x, y, z)
//	**
//	** If the optional "KEY z" syntax is omitted, an SQL NULL is passed as the
//	** third argument.
//	**
//	** If the db->init.reopenMemdb flags is set, then instead of attaching a
//	** new database, close the database on db->init.iDb and reopen it as an
//	** empty MemDB.
//	*/
func _attachFunc(tls *libc.TLS, context uintptr, NotUsed int32, argv uintptr) {
	bp := tls.Alloc(64)
	defer tls.Free(64)
	var aNew, db, pNew, pNewSchema, pPager, zFile, zName uintptr
	var i, iDb, rc int32
	var _ /* flags at bp+16 */ uint32
	var _ /* pNewBt at bp+40 */ uintptr
	var _ /* pVfs at bp+32 */ uintptr
	var _ /* zErr at bp+8 */ uintptr
	var _ /* zErrDyn at bp+24 */ uintptr
	var _ /* zPath at bp+0 */ uintptr
	_, _, _, _, _, _, _, _, _, _ = aNew, db, i, iDb, pNew, pNewSchema, pPager, rc, zFile, zName
	rc = 0
	db = Xsqlite3_context_db_handle(tls, context)
	**(**uintptr)(__ccgo_up(bp)) = uintptr(0)
	**(**uintptr)(__ccgo_up(bp + 8)) = uintptr(0) /* New array of Db pointers */
	pNew = uintptr(0)                             /* Db object for the newly attached database */
	**(**uintptr)(__ccgo_up(bp + 24)) = uintptr(0)
	_ = NotUsed
	zFile = Xsqlite3_value_text(tls, **(**uintptr)(__ccgo_up(argv)))
	zName = Xsqlite3_value_text(tls, **(**uintptr)(__ccgo_up(argv + 1*8)))
	if zFile == uintptr(0) {
		zFile = __ccgo_ts + 1693
	}
	if zName == uintptr(0) {
		zName = __ccgo_ts + 1693
	}
	if int32(uint32(*(*uint8)(unsafe.Pointer(db + 192 + 8))&0x8>>3)) != 0 {
		/* This is not a real ATTACH.  Instead, this routine is being called
		 ** from sqlite3_deserialize() to close database db->init.iDb and
		 ** reopen it as a MemDB */
		**(**uintptr)(__ccgo_up(bp + 40)) = uintptr(0)
		pNew = (*Tsqlite3)(unsafe.Pointer(db)).FaDb + uintptr((*Tsqlite3)(unsafe.Pointer(db)).Finit1.FiDb)*32
		if _sqlite3BtreeTxnState(tls, (*TDb)(unsafe.Pointer(pNew)).FpBt) != SQLITE_TXN_NONE || _sqlite3BtreeIsInBackup(tls, (*TDb)(unsafe.Pointer(pNew)).FpBt) != 0 {
			rc = int32(SQLITE_BUSY)
			goto attach_error
		}
		**(**uintptr)(__ccgo_up(bp + 32)) = Xsqlite3_vfs_find(tls, __ccgo_ts+4105)
		if **(**uintptr)(__ccgo_up(bp + 32)) == uintptr(0) {
			return
		}
		rc = _sqlite3BtreeOpen(tls, **(**uintptr)(__ccgo_up(bp + 32)), __ccgo_ts+13240, db, bp+40, 0, int32(SQLITE_OPEN_MAIN_DB))
		if rc == SQLITE_OK {
			pNewSchema = _sqlite3SchemaGet(tls, db, **(**uintptr)(__ccgo_up(bp + 40)))
			if pNewSchema != 0 {
				/* Both the Btree and the new Schema were allocated successfully.
				 ** Close the old db and update the aDb[] slot with the new memdb
				 ** values.  */
				_sqlite3BtreeClose(tls, (*TDb)(unsafe.Pointer(pNew)).FpBt)
				(*TDb)(unsafe.Pointer(pNew)).FpBt = **(**uintptr)(__ccgo_up(bp + 40))
				(*TDb)(unsafe.Pointer(pNew)).FpSchema = pNewSchema
			} else {
				_sqlite3BtreeClose(tls, **(**uintptr)(__ccgo_up(bp + 40)))
				rc = int32(SQLITE_NOMEM)
			}
		}
		if rc != 0 {
			goto attach_error
		}
	} else {
		/* This is a real ATTACH
		 **
		 ** Check for the following errors:
		 **
		 **     * Too many attached databases,
		 **     * Transaction currently open
		 **     * Specified database name already being used.
		 */
		if (*Tsqlite3)(unsafe.Pointer(db)).FnDb >= **(**int32)(__ccgo_up(db + 136 + 7*4))+int32(2) {
			**(**uintptr)(__ccgo_up(bp + 24)) = _sqlite3MPrintf(tls, db, __ccgo_ts+13243, libc.VaList(bp+56, **(**int32)(__ccgo_up(db + 136 + 7*4))))
			goto attach_error
		}
		i = 0
		for {
			if !(i < (*Tsqlite3)(unsafe.Pointer(db)).FnDb) {
				break
			}
			if _sqlite3DbIsNamed(tls, db, i, zName) != 0 {
				**(**uintptr)(__ccgo_up(bp + 24)) = _sqlite3MPrintf(tls, db, __ccgo_ts+13280, libc.VaList(bp+56, zName))
				goto attach_error
			}
			goto _1
		_1:
			;
			i = i + 1
		}
		/* Allocate the new entry in the db->aDb[] array and initialize the schema
		 ** hash tables.
		 */
		if (*Tsqlite3)(unsafe.Pointer(db)).FaDb == db+696 {
			aNew = _sqlite3DbMallocRawNN(tls, db, uint64(libc.Uint64FromInt64(32)*libc.Uint64FromInt32(3)))
			if aNew == uintptr(0) {
				return
			}
			libc.Xmemcpy(tls, aNew, (*Tsqlite3)(unsafe.Pointer(db)).FaDb, libc.Uint64FromInt64(32)*libc.Uint64FromInt32(2))
		} else {
			aNew = _sqlite3DbRealloc(tls, db, (*Tsqlite3)(unsafe.Pointer(db)).FaDb, uint64(32)*libc.Uint64FromInt64(libc.Int64FromInt32(1)+int64((*Tsqlite3)(unsafe.Pointer(db)).FnDb)))
			if aNew == uintptr(0) {
				return
			}
		}
		(*Tsqlite3)(unsafe.Pointer(db)).FaDb = aNew
		pNew = (*Tsqlite3)(unsafe.Pointer(db)).FaDb + uintptr((*Tsqlite3)(unsafe.Pointer(db)).FnDb)*32
		libc.Xmemset(tls, pNew, 0, uint64(32))
		/* Open the database file. If the btree is successfully opened, use
		 ** it to obtain the database schema. At this point the schema may
		 ** or may not be initialized.
		 */
		**(**uint32)(__ccgo_up(bp + 16)) = (*Tsqlite3)(unsafe.Pointer(db)).FopenFlags
		rc = _sqlite3ParseUri(tls, (*Tsqlite3_vfs)(unsafe.Pointer((*Tsqlite3)(unsafe.Pointer(db)).FpVfs)).FzName, zFile, bp+16, bp+32, bp, bp+8)
		if rc != SQLITE_OK {
			if rc == int32(SQLITE_NOMEM) {
				_sqlite3OomFault(tls, db)
			}
			Xsqlite3_result_error(tls, context, **(**uintptr)(__ccgo_up(bp + 8)), -int32(1))
			Xsqlite3_free(tls, **(**uintptr)(__ccgo_up(bp + 8)))
			return
		}
		if (*Tsqlite3)(unsafe.Pointer(db)).Fflags&(libc.Uint64FromInt32(libc.Int32FromInt32(0x00020))<<libc.Int32FromInt32(32)) == uint64(0) {
			**(**uint32)(__ccgo_up(bp + 16)) = **(**uint32)(__ccgo_up(bp + 16)) & libc.Uint32FromInt32(^(libc.Int32FromInt32(SQLITE_OPEN_CREATE) | libc.Int32FromInt32(SQLITE_OPEN_READWRITE)))
			**(**uint32)(__ccgo_up(bp + 16)) = **(**uint32)(__ccgo_up(bp + 16)) | uint32(SQLITE_OPEN_READONLY)
		} else {
			if (*Tsqlite3)(unsafe.Pointer(db)).Fflags&(libc.Uint64FromInt32(libc.Int32FromInt32(0x00010))<<libc.Int32FromInt32(32)) == uint64(0) {
				**(**uint32)(__ccgo_up(bp + 16)) = **(**uint32)(__ccgo_up(bp + 16)) & libc.Uint32FromInt32(^libc.Int32FromInt32(SQLITE_OPEN_CREATE))
			}
		}
		**(**uint32)(__ccgo_up(bp + 16)) = **(**uint32)(__ccgo_up(bp + 16)) | uint32(SQLITE_OPEN_MAIN_DB)
		rc = _sqlite3BtreeOpen(tls, **(**uintptr)(__ccgo_up(bp + 32)), **(**uintptr)(__ccgo_up(bp)), db, pNew+8, 0, libc.Int32FromUint32(**(**uint32)(__ccgo_up(bp + 16))))
		(*Tsqlite3)(unsafe.Pointer(db)).FnDb = (*Tsqlite3)(unsafe.Pointer(db)).FnDb + 1
		(*TDb)(unsafe.Pointer(pNew)).FzDbSName = _sqlite3DbStrDup(tls, db, zName)
	}
	(*Tsqlite3)(unsafe.Pointer(db)).FnoSharedCache = uint8(0)
	if rc == int32(SQLITE_CONSTRAINT) {
		rc = int32(SQLITE_ERROR)
		**(**uintptr)(__ccgo_up(bp + 24)) = _sqlite3MPrintf(tls, db, __ccgo_ts+13310, 0)
	} else {
		if rc == SQLITE_OK {
			(*TDb)(unsafe.Pointer(pNew)).FpSchema = _sqlite3SchemaGet(tls, db, (*TDb)(unsafe.Pointer(pNew)).FpBt)
			if !((*TDb)(unsafe.Pointer(pNew)).FpSchema != 0) {
				rc = int32(SQLITE_NOMEM)
			} else {
				if (*TSchema)(unsafe.Pointer((*TDb)(unsafe.Pointer(pNew)).FpSchema)).Ffile_format != 0 && libc.Int32FromUint8((*TSchema)(unsafe.Pointer((*TDb)(unsafe.Pointer(pNew)).FpSchema)).Fenc) != libc.Int32FromUint8((*Tsqlite3)(unsafe.Pointer(db)).Fenc) {
					**(**uintptr)(__ccgo_up(bp + 24)) = _sqlite3MPrintf(tls, db, __ccgo_ts+13339, 0)
					rc = int32(SQLITE_ERROR)
				}
			}
			_sqlite3BtreeEnter(tls, (*TDb)(unsafe.Pointer(pNew)).FpBt)
			pPager = _sqlite3BtreePager(tls, (*TDb)(unsafe.Pointer(pNew)).FpBt)
			_sqlite3PagerLockingMode(tls, pPager, libc.Int32FromUint8((*Tsqlite3)(unsafe.Pointer(db)).FdfltLockMode))
			_sqlite3BtreeSecureDelete(tls, (*TDb)(unsafe.Pointer(pNew)).FpBt, _sqlite3BtreeSecureDelete(tls, (**(**TDb)(__ccgo_up((*Tsqlite3)(unsafe.Pointer(db)).FaDb))).FpBt, -int32(1)))
			_sqlite3BtreeSetPagerFlags(tls, (*TDb)(unsafe.Pointer(pNew)).FpBt, uint32(uint64(PAGER_SYNCHRONOUS_FULL)|(*Tsqlite3)(unsafe.Pointer(db)).Fflags&uint64(PAGER_FLAGS_MASK)))
			_sqlite3BtreeLeave(tls, (*TDb)(unsafe.Pointer(pNew)).FpBt)
		}
	}
	(*TDb)(unsafe.Pointer(pNew)).Fsafety_level = libc.Uint8FromInt32(libc.Int32FromInt32(SQLITE_DEFAULT_SYNCHRONOUS) + libc.Int32FromInt32(1))
	if rc == SQLITE_OK && (*TDb)(unsafe.Pointer(pNew)).FzDbSName == uintptr(0) {
		rc = int32(SQLITE_NOMEM)
	}
	Xsqlite3_free_filename(tls, **(**uintptr)(__ccgo_up(bp)))
	/* If the file was opened successfully, read the schema for the new database.
	 ** If this fails, or if opening the file failed, then close the file and
	 ** remove the entry from the db->aDb[] array. i.e. put everything back the
	 ** way we found it.
	 */
	if rc == SQLITE_OK {
		_sqlite3BtreeEnterAll(tls, db)
		(*Tsqlite3)(unsafe.Pointer(db)).Finit1.FiDb = uint8(0)
		**(**Tu32)(__ccgo_up(db + 44)) &= libc.Uint32FromInt32(^libc.Int32FromInt32(DBFLAG_SchemaKnownOk))
		if !(int32(uint32(*(*uint8)(unsafe.Pointer(db + 192 + 8))&0x8>>3)) != 0) {
			rc = _sqlite3Init(tls, db, bp+24)
		}
		_sqlite3BtreeLeaveAll(tls, db)
	}
	if rc != 0 {
		if !(int32(uint32(*(*uint8)(unsafe.Pointer(db + 192 + 8))&0x8>>3)) != 0) {
			iDb = (*Tsqlite3)(unsafe.Pointer(db)).FnDb - int32(1)
			if (**(**TDb)(__ccgo_up((*Tsqlite3)(unsafe.Pointer(db)).FaDb + uintptr(iDb)*32))).FpBt != 0 {
				_sqlite3BtreeClose(tls, (**(**TDb)(__ccgo_up((*Tsqlite3)(unsafe.Pointer(db)).FaDb + uintptr(iDb)*32))).FpBt)
				(**(**TDb)(__ccgo_up((*Tsqlite3)(unsafe.Pointer(db)).FaDb + uintptr(iDb)*32))).FpBt = uintptr(0)
				(**(**TDb)(__ccgo_up((*Tsqlite3)(unsafe.Pointer(db)).FaDb + uintptr(iDb)*32))).FpSchema = uintptr(0)
			}
			_sqlite3ResetAllSchemasOfConnection(tls, db)
			(*Tsqlite3)(unsafe.Pointer(db)).FnDb = iDb
			if rc == int32(SQLITE_NOMEM) || rc == libc.Int32FromInt32(SQLITE_IOERR)|libc.Int32FromInt32(12)<<libc.Int32FromInt32(8) {
				_sqlite3OomFault(tls, db)
				_sqlite3DbFree(tls, db, **(**uintptr)(__ccgo_up(bp + 24)))
				**(**uintptr)(__ccgo_up(bp + 24)) = _sqlite3MPrintf(tls, db, __ccgo_ts+1663, 0)
			} else {
				if **(**uintptr)(__ccgo_up(bp + 24)) == uintptr(0) {
					**(**uintptr)(__ccgo_up(bp + 24)) = _sqlite3MPrintf(tls, db, __ccgo_ts+13407, libc.VaList(bp+56, zFile))
				}
			}
		}
		goto attach_error
	}
	return
	goto attach_error
attach_error:
	;
	/* Return an error if we get here */
	if **(**uintptr)(__ccgo_up(bp + 24)) != 0 {
		Xsqlite3_result_error(tls, context, **(**uintptr)(__ccgo_up(bp + 24)), -int32(1))
		_sqlite3DbFree(tls, db, **(**uintptr)(__ccgo_up(bp + 24)))
	}
	if rc != 0 {
		Xsqlite3_result_error_code(tls, context, rc)
	}
}

var _attach_func = TFuncDef{
	FnArg:      int16(3),
	FfuncFlags: uint32(SQLITE_UTF8),
	FzName:     __ccgo_ts + 13518,
}

var _az = [3]uintptr{
	0: __ccgo_ts + 16096,
	1: __ccgo_ts + 16118,
	2: __ccgo_ts + 16102,
}

var _azAlterType = [4]uintptr{
	0: __ccgo_ts + 19970,
	1: __ccgo_ts + 19977,
	2: __ccgo_ts + 19989,
	3: __ccgo_ts + 20000,
}

var _azEnc = [4]uintptr{
	1: __ccgo_ts + 19175,
	2: __ccgo_ts + 19180,
	3: __ccgo_ts + 19188,
}

/* Shared library endings to try if zFile cannot be loaded as written */
var _azEndings = [1]uintptr{
	0: __ccgo_ts + 17577,
}

var _azErr = [5]uintptr{
	0: __ccgo_ts + 24613,
	1: __ccgo_ts + 24666,
	2: __ccgo_ts + 24168,
	3: __ccgo_ts + 24717,
	4: __ccgo_ts + 24769,
}

// C documentation
//
//	/*
//	** Column names appropriate for EXPLAIN or EXPLAIN QUERY PLAN.
//	*/
var _azExplainColNames8 = [12]uintptr{
	0:  __ccgo_ts + 5606,
	1:  __ccgo_ts + 5611,
	2:  __ccgo_ts + 5618,
	3:  __ccgo_ts + 5621,
	4:  __ccgo_ts + 5624,
	5:  __ccgo_ts + 5627,
	6:  __ccgo_ts + 5630,
	7:  __ccgo_ts + 5633,
	8:  __ccgo_ts + 5641,
	9:  __ccgo_ts + 5644,
	10: __ccgo_ts + 5651,
	11: __ccgo_ts + 5659,
}

var _azFormat = [2]uintptr{
	0: __ccgo_ts + 28977,
	1: __ccgo_ts + 28988,
}

var _azInsType = [3]uintptr{
	0: __ccgo_ts + 26757,
	1: __ccgo_ts + 26764,
	2: __ccgo_ts + 26768,
}

var _azModeName = [6]uintptr{
	0: __ccgo_ts + 19143,
	1: __ccgo_ts + 19150,
	2: __ccgo_ts + 19158,
	3: __ccgo_ts + 19162,
	4: __ccgo_ts + 19026,
	5: __ccgo_ts + 19171,
}

var _azModule = [4]uintptr{
	0: __ccgo_ts + 27355,
	1: __ccgo_ts + 27365,
	2: __ccgo_ts + 27375,
	3: __ccgo_ts + 27386,
}

/* In SQLite core */

/* #include <stddef.h> */

/*
** If building separately, we will need some setup that is normally
** found in sqliteInt.h
 */

/* Macro to check for 4-byte alignment.  Only used inside of assert() */

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

/*  The following macro is used to suppress compiler warnings.
 */

var _azName = [192]uintptr{
	0:   __ccgo_ts + 1903,
	1:   __ccgo_ts + 1913,
	2:   __ccgo_ts + 1924,
	3:   __ccgo_ts + 1936,
	4:   __ccgo_ts + 1947,
	5:   __ccgo_ts + 1959,
	6:   __ccgo_ts + 1966,
	7:   __ccgo_ts + 1974,
	8:   __ccgo_ts + 1982,
	9:   __ccgo_ts + 1987,
	10:  __ccgo_ts + 1992,
	11:  __ccgo_ts + 1998,
	12:  __ccgo_ts + 2012,
	13:  __ccgo_ts + 2018,
	14:  __ccgo_ts + 2028,
	15:  __ccgo_ts + 2033,
	16:  __ccgo_ts + 2038,
	17:  __ccgo_ts + 2041,
	18:  __ccgo_ts + 2047,
	19:  __ccgo_ts + 2054,
	20:  __ccgo_ts + 2058,
	21:  __ccgo_ts + 2068,
	22:  __ccgo_ts + 2075,
	23:  __ccgo_ts + 2082,
	24:  __ccgo_ts + 2089,
	25:  __ccgo_ts + 2096,
	26:  __ccgo_ts + 2106,
	27:  __ccgo_ts + 2115,
	28:  __ccgo_ts + 2126,
	29:  __ccgo_ts + 2135,
	30:  __ccgo_ts + 2141,
	31:  __ccgo_ts + 2151,
	32:  __ccgo_ts + 2161,
	33:  __ccgo_ts + 2166,
	34:  __ccgo_ts + 2180,
	35:  __ccgo_ts + 2191,
	36:  __ccgo_ts + 2196,
	37:  __ccgo_ts + 2203,
	38:  __ccgo_ts + 2211,
	39:  __ccgo_ts + 2222,
	40:  __ccgo_ts + 2227,
	41:  __ccgo_ts + 2232,
	42:  __ccgo_ts + 2238,
	43:  __ccgo_ts + 2244,
	44:  __ccgo_ts + 2247,
	45:  __ccgo_ts + 2251,
	46:  __ccgo_ts + 2257,
	47:  __ccgo_ts + 2263,
	48:  __ccgo_ts + 2272,
	49:  __ccgo_ts + 2283,
	50:  __ccgo_ts + 2294,
	51:  __ccgo_ts + 2302,
	52:  __ccgo_ts + 2309,
	53:  __ccgo_ts + 2317,
	54:  __ccgo_ts + 2320,
	55:  __ccgo_ts + 2323,
	56:  __ccgo_ts + 2326,
	57:  __ccgo_ts + 2329,
	58:  __ccgo_ts + 2332,
	59:  __ccgo_ts + 2335,
	60:  __ccgo_ts + 2342,
	61:  __ccgo_ts + 2351,
	62:  __ccgo_ts + 2357,
	63:  __ccgo_ts + 2367,
	64:  __ccgo_ts + 2380,
	65:  __ccgo_ts + 2391,
	66:  __ccgo_ts + 2397,
	67:  __ccgo_ts + 2404,
	68:  __ccgo_ts + 2413,
	69:  __ccgo_ts + 2422,
	70:  __ccgo_ts + 2429,
	71:  __ccgo_ts + 2442,
	72:  __ccgo_ts + 2453,
	73:  __ccgo_ts + 2458,
	74:  __ccgo_ts + 2466,
	75:  __ccgo_ts + 2472,
	76:  __ccgo_ts + 2479,
	77:  __ccgo_ts + 2491,
	78:  __ccgo_ts + 2496,
	79:  __ccgo_ts + 2505,
	80:  __ccgo_ts + 2510,
	81:  __ccgo_ts + 2519,
	82:  __ccgo_ts + 2524,
	83:  __ccgo_ts + 2529,
	84:  __ccgo_ts + 2535,
	85:  __ccgo_ts + 2543,
	86:  __ccgo_ts + 2551,
	87:  __ccgo_ts + 2561,
	88:  __ccgo_ts + 2569,
	89:  __ccgo_ts + 2576,
	90:  __ccgo_ts + 2589,
	91:  __ccgo_ts + 2594,
	92:  __ccgo_ts + 2606,
	93:  __ccgo_ts + 2614,
	94:  __ccgo_ts + 2621,
	95:  __ccgo_ts + 2632,
	96:  __ccgo_ts + 2639,
	97:  __ccgo_ts + 2646,
	98:  __ccgo_ts + 2656,
	99:  __ccgo_ts + 2665,
	100: __ccgo_ts + 2676,
	101: __ccgo_ts + 2682,
	102: __ccgo_ts + 2693,
	103: __ccgo_ts + 2703,
	104: __ccgo_ts + 2710,
	105: __ccgo_ts + 2716,
	106: __ccgo_ts + 2726,
	107: __ccgo_ts + 2737,
	108: __ccgo_ts + 2741,
	109: __ccgo_ts + 2750,
	110: __ccgo_ts + 2759,
	111: __ccgo_ts + 2766,
	112: __ccgo_ts + 2776,
	113: __ccgo_ts + 2783,
	114: __ccgo_ts + 2793,
	115: __ccgo_ts + 2802,
	116: __ccgo_ts + 2809,
	117: __ccgo_ts + 2819,
	118: __ccgo_ts + 2827,
	119: __ccgo_ts + 2835,
	120: __ccgo_ts + 2849,
	121: __ccgo_ts + 2863,
	122: __ccgo_ts + 2874,
	123: __ccgo_ts + 2887,
	124: __ccgo_ts + 2898,
	125: __ccgo_ts + 2904,
	126: __ccgo_ts + 2916,
	127: __ccgo_ts + 2925,
	128: __ccgo_ts + 2933,
	129: __ccgo_ts + 2942,
	130: __ccgo_ts + 2951,
	131: __ccgo_ts + 2958,
	132: __ccgo_ts + 2966,
	133: __ccgo_ts + 2973,
	134: __ccgo_ts + 2984,
	135: __ccgo_ts + 2998,
	136: __ccgo_ts + 3009,
	137: __ccgo_ts + 3017,
	138: __ccgo_ts + 3023,
	139: __ccgo_ts + 3031,
	140: __ccgo_ts + 3039,
	141: __ccgo_ts + 3049,
	142: __ccgo_ts + 3062,
	143: __ccgo_ts + 3072,
	144: __ccgo_ts + 3085,
	145: __ccgo_ts + 3094,
	146: __ccgo_ts + 3105,
	147: __ccgo_ts + 3113,
	148: __ccgo_ts + 3119,
	149: __ccgo_ts + 3131,
	150: __ccgo_ts + 3143,
	151: __ccgo_ts + 3151,
	152: __ccgo_ts + 3163,
	153: __ccgo_ts + 3176,
	154: __ccgo_ts + 3186,
	155: __ccgo_ts + 3191,
	156: __ccgo_ts + 3201,
	157: __ccgo_ts + 3213,
	158: __ccgo_ts + 3225,
	159: __ccgo_ts + 3235,
	160: __ccgo_ts + 3241,
	161: __ccgo_ts + 3251,
	162: __ccgo_ts + 3258,
	163: __ccgo_ts + 3270,
	164: __ccgo_ts + 3281,
	165: __ccgo_ts + 3289,
	166: __ccgo_ts + 3298,
	167: __ccgo_ts + 3307,
	168: __ccgo_ts + 3316,
	169: __ccgo_ts + 3323,
	170: __ccgo_ts + 3334,
	171: __ccgo_ts + 3347,
	172: __ccgo_ts + 3357,
	173: __ccgo_ts + 3364,
	174: __ccgo_ts + 3372,
	175: __ccgo_ts + 3381,
	176: __ccgo_ts + 3387,
	177: __ccgo_ts + 3394,
	178: __ccgo_ts + 3402,
	179: __ccgo_ts + 3410,
	180: __ccgo_ts + 3418,
	181: __ccgo_ts + 3428,
	182: __ccgo_ts + 3437,
	183: __ccgo_ts + 3448,
	184: __ccgo_ts + 3459,
	185: __ccgo_ts + 3470,
	186: __ccgo_ts + 3480,
	187: __ccgo_ts + 3486,
	188: __ccgo_ts + 3497,
	189: __ccgo_ts + 3508,
	190: __ccgo_ts + 3513,
	191: __ccgo_ts + 3521,
}

var _azName1 = [3]uintptr{
	0: __ccgo_ts + 27788,
	1: __ccgo_ts + 5644,
	2: __ccgo_ts + 17956,
}

var _azName2 = [5]uintptr{
	0: __ccgo_ts + 40589,
	1: __ccgo_ts + 37580,
	2: __ccgo_ts + 27397,
	3: __ccgo_ts + 38275,
	4: __ccgo_ts + 13037,
}

var _azOne = [1]uintptr{
	0: __ccgo_ts + 11534,
}

var _azSql = [8]uintptr{
	0: __ccgo_ts + 27793,
	1: __ccgo_ts + 27846,
	2: __ccgo_ts + 27891,
	3: __ccgo_ts + 27943,
	4: __ccgo_ts + 27997,
	5: __ccgo_ts + 28042,
	6: __ccgo_ts + 28100,
	7: __ccgo_ts + 28155,
}

// C documentation
//
//	/*
//	** Directories to consider for temp files.
//	*/
var _azTempDirs = [6]uintptr{
	2: __ccgo_ts + 3990,
	3: __ccgo_ts + 3999,
	4: __ccgo_ts + 4008,
	5: __ccgo_ts + 1732,
}

var _azType = [4]uintptr{
	0: __ccgo_ts + 5815,
	1: __ccgo_ts + 5824,
	2: __ccgo_ts + 5831,
	3: __ccgo_ts + 5837,
}

var _azType1 = [6]uintptr{
	0: __ccgo_ts + 1693,
	1: __ccgo_ts + 14367,
	2: __ccgo_ts + 14373,
	3: __ccgo_ts + 14378,
	4: __ccgo_ts + 14383,
	5: __ccgo_ts + 14373,
}

var _azType2 = [5]uintptr{
	0: __ccgo_ts + 6485,
	1: __ccgo_ts + 6480,
	2: __ccgo_ts + 8480,
	3: __ccgo_ts + 8475,
	4: __ccgo_ts + 1679,
}

var _azTypes = [5]uintptr{
	0: __ccgo_ts + 1163,
	1: __ccgo_ts + 1175,
	2: __ccgo_ts + 1180,
	3: __ccgo_ts + 1158,
	4: __ccgo_ts + 1694,
}

// C documentation
//
//	/*
//	** This function is used by both blob_open() and blob_reopen(). It seeks
//	** the b-tree cursor associated with blob handle p to point to row iRow.
//	** If successful, SQLITE_OK is returned and subsequent calls to
//	** sqlite3_blob_read() or sqlite3_blob_write() access the specified row.
//	**
//	** If an error occurs, or if the specified row does not exist or does not
//	** contain a value of type TEXT or BLOB in the column nominated when the
//	** blob handle was opened, then an error code is returned and *pzErr may
//	** be set to point to a buffer containing an error message. It is the
//	** responsibility of the caller to free the error message buffer using
//	** sqlite3DbFree().
//	**
//	** If an error does occur, then the b-tree cursor is closed. All subsequent
//	** calls to sqlite3_blob_read(), blob_write() or blob_reopen() will
//	** immediately return SQLITE_ABORT.
//	*/
func _blobSeekToRow(tls *libc.TLS, p uintptr, iRow Tsqlite3_int64, pzErr uintptr) (r int32) {
	bp := tls.Alloc(16)
	defer tls.Free(16)
	var pC, v, zErr, v2, v3 uintptr
	var rc int32
	var type1 Tu32
	var v1 uint32
	_, _, _, _, _, _, _, _ = pC, rc, type1, v, zErr, v1, v2, v3 /* Error code */
	zErr = uintptr(0)                                           /* Error message */
	v = (*TIncrblob)(unsafe.Pointer(p)).FpStmt
	/* Set the value of register r[1] in the SQL statement to integer iRow.
	 ** This is done directly as a performance optimization
	 */
	_sqlite3VdbeMemSetInt64(tls, (*TVdbe)(unsafe.Pointer(v)).FaMem+1*56, iRow)
	/* If the statement has been run before (and is paused at the OP_ResultRow)
	 ** then back it up to the point where it does the OP_NotExists.  This could
	 ** have been down with an extra OP_Goto, but simply setting the program
	 ** counter is faster. */
	if (*TVdbe)(unsafe.Pointer(v)).Fpc > int32(4) {
		(*TVdbe)(unsafe.Pointer(v)).Fpc = int32(4)
		rc = _sqlite3VdbeExec(tls, v)
	} else {
		rc = Xsqlite3_step(tls, (*TIncrblob)(unsafe.Pointer(p)).FpStmt)
	}
	if rc == int32(SQLITE_ROW) {
		pC = **(**uintptr)(__ccgo_up((*TVdbe)(unsafe.Pointer(v)).FapCsr))
		if libc.Int32FromUint16((*TVdbeCursor)(unsafe.Pointer(pC)).FnHdrParsed) > libc.Int32FromUint16((*TIncrblob)(unsafe.Pointer(p)).FiCol) {
			v1 = *(*Tu32)(unsafe.Pointer(pC + 120 + uintptr((*TIncrblob)(unsafe.Pointer(p)).FiCol)*4))
		} else {
			v1 = uint32(0)
		}
		type1 = v1
		if type1 < uint32(12) {
			if type1 == uint32(0) {
				v2 = __ccgo_ts + 1679
			} else {
				if type1 == uint32(7) {
					v3 = __ccgo_ts + 6480
				} else {
					v3 = __ccgo_ts + 6485
				}
				v2 = v3
			}
			zErr = _sqlite3MPrintf(tls, (*TIncrblob)(unsafe.Pointer(p)).Fdb, __ccgo_ts+6493, libc.VaList(bp+8, v2))
			rc = int32(SQLITE_ERROR)
			Xsqlite3_finalize(tls, (*TIncrblob)(unsafe.Pointer(p)).FpStmt)
			(*TIncrblob)(unsafe.Pointer(p)).FpStmt = uintptr(0)
		} else {
			(*TIncrblob)(unsafe.Pointer(p)).FiOffset = libc.Int32FromUint32(*(*Tu32)(unsafe.Pointer(pC + 120 + uintptr(libc.Int32FromUint16((*TIncrblob)(unsafe.Pointer(p)).FiCol)+int32((*TVdbeCursor)(unsafe.Pointer(pC)).FnField))*4)))
			(*TIncrblob)(unsafe.Pointer(p)).FnByte = libc.Int32FromUint32(_sqlite3VdbeSerialTypeLen(tls, type1))
			(*TIncrblob)(unsafe.Pointer(p)).FpCsr = *(*uintptr)(unsafe.Pointer(pC + 48))
			_sqlite3BtreeIncrblobCursor(tls, (*TIncrblob)(unsafe.Pointer(p)).FpCsr)
		}
	}
	if rc == int32(SQLITE_ROW) {
		rc = SQLITE_OK
	} else {
		if (*TIncrblob)(unsafe.Pointer(p)).FpStmt != 0 {
			rc = Xsqlite3_finalize(tls, (*TIncrblob)(unsafe.Pointer(p)).FpStmt)
			(*TIncrblob)(unsafe.Pointer(p)).FpStmt = uintptr(0)
			if rc == SQLITE_OK {
				zErr = _sqlite3MPrintf(tls, (*TIncrblob)(unsafe.Pointer(p)).Fdb, __ccgo_ts+6522, libc.VaList(bp+8, iRow))
				rc = int32(SQLITE_ERROR)
			} else {
				zErr = _sqlite3MPrintf(tls, (*TIncrblob)(unsafe.Pointer(p)).Fdb, __ccgo_ts+3933, libc.VaList(bp+8, Xsqlite3_errmsg(tls, (*TIncrblob)(unsafe.Pointer(p)).Fdb)))
			}
		}
	}
	**(**uintptr)(__ccgo_up(pzErr)) = zErr
	return rc
}

// C documentation
//
//	/*
//	** Check to see if the FROM clause term pFrom has table-valued function
//	** arguments.  If it does, leave an error message in pParse and return
//	** non-zero, since pFrom is not allowed to be a table-valued function.
//	*/
func _cannotBeFunction(tls *libc.TLS, pParse uintptr, pFrom uintptr) (r int32) {
	bp := tls.Alloc(16)
	defer tls.Free(16)
	if int32(*(*uint32)(unsafe.Pointer(pFrom + 24 + 4))&0x8>>3) != 0 {
		_sqlite3ErrorMsg(tls, pParse, __ccgo_ts+21025, libc.VaList(bp+8, (*TSrcItem)(unsafe.Pointer(pFrom)).FzName))
		return int32(1)
	}
	return 0
}

// C documentation
//
//	/*
//	** Append a message to the error message string.
//	*/
func _checkAppendMsg(tls *libc.TLS, pCheck uintptr, zFormat uintptr, va uintptr) {
	bp := tls.Alloc(32)
	defer tls.Free(32)
	var ap Tva_list
	_ = ap
	_checkProgress(tls, pCheck)
	if !((*TIntegrityCk)(unsafe.Pointer(pCheck)).FmxErr != 0) {
		return
	}
	(*TIntegrityCk)(unsafe.Pointer(pCheck)).FmxErr = (*TIntegrityCk)(unsafe.Pointer(pCheck)).FmxErr - 1
	(*TIntegrityCk)(unsafe.Pointer(pCheck)).FnErr = (*TIntegrityCk)(unsafe.Pointer(pCheck)).FnErr + 1
	ap = va
	if (*TIntegrityCk)(unsafe.Pointer(pCheck)).FerrMsg.FnChar != 0 {
		Xsqlite3_str_append(tls, pCheck+72, __ccgo_ts+4345, int32(1))
	}
	if (*TIntegrityCk)(unsafe.Pointer(pCheck)).FzPfx != 0 {
		Xsqlite3_str_appendf(tls, pCheck+72, (*TIntegrityCk)(unsafe.Pointer(pCheck)).FzPfx, libc.VaList(bp+8, (*TIntegrityCk)(unsafe.Pointer(pCheck)).Fv0, (*TIntegrityCk)(unsafe.Pointer(pCheck)).Fv1, (*TIntegrityCk)(unsafe.Pointer(pCheck)).Fv2))
	}
	Xsqlite3_str_vappendf(tls, pCheck+72, zFormat, ap)
	_ = ap
	if libc.Int32FromUint8((*TIntegrityCk)(unsafe.Pointer(pCheck)).FerrMsg.FaccError) == int32(SQLITE_NOMEM) {
		_checkOom(tls, pCheck)
	}
}

// C documentation
//
//	/*
//	** Check the integrity of the freelist or of an overflow page list.
//	** Verify that the number of pages on the list is N.
//	*/
func _checkList(tls *libc.TLS, pCheck uintptr, isFreeList int32, iPage TPgno, N Tu32) {
	bp := tls.Alloc(48)
	defer tls.Free(48)
	var expected, n Tu32
	var i, nErrAtStart int32
	var iFreePage TPgno
	var pOvflData, v2 uintptr
	var _ /* pOvflPage at bp+0 */ uintptr
	_, _, _, _, _, _, _ = expected, i, iFreePage, n, nErrAtStart, pOvflData, v2
	expected = N
	nErrAtStart = (*TIntegrityCk)(unsafe.Pointer(pCheck)).FnErr
	for iPage != uint32(0) && (*TIntegrityCk)(unsafe.Pointer(pCheck)).FmxErr != 0 {
		if _checkRef(tls, pCheck, iPage) != 0 {
			break
		}
		N = N - 1
		if _sqlite3PagerGet(tls, (*TIntegrityCk)(unsafe.Pointer(pCheck)).FpPager, iPage, bp, 0) != 0 {
			_checkAppendMsg(tls, pCheck, __ccgo_ts+4478, libc.VaList(bp+16, iPage))
			break
		}
		pOvflData = _sqlite3PagerGetData(tls, **(**uintptr)(__ccgo_up(bp)))
		if isFreeList != 0 {
			n = _sqlite3Get4byte(tls, pOvflData+4)
			if (*TBtShared)(unsafe.Pointer((*TIntegrityCk)(unsafe.Pointer(pCheck)).FpBt)).FautoVacuum != 0 {
				_checkPtrmap(tls, pCheck, iPage, uint8(PTRMAP_FREEPAGE), uint32(0))
			}
			if n > (*TBtShared)(unsafe.Pointer((*TIntegrityCk)(unsafe.Pointer(pCheck)).FpBt)).FusableSize/uint32(4)-uint32(2) {
				_checkAppendMsg(tls, pCheck, __ccgo_ts+4500, libc.VaList(bp+16, iPage))
				N = N - 1
			} else {
				i = 0
				for {
					if !(i < libc.Int32FromUint32(n)) {
						break
					}
					iFreePage = _sqlite3Get4byte(tls, pOvflData+uintptr(int32(8)+i*int32(4)))
					if (*TBtShared)(unsafe.Pointer((*TIntegrityCk)(unsafe.Pointer(pCheck)).FpBt)).FautoVacuum != 0 {
						_checkPtrmap(tls, pCheck, iFreePage, uint8(PTRMAP_FREEPAGE), uint32(0))
					}
					_checkRef(tls, pCheck, iFreePage)
					goto _1
				_1:
					;
					i = i + 1
				}
				N = N - n
			}
		} else {
			/* If this database supports auto-vacuum and iPage is not the last
			 ** page in this overflow list, check that the pointer-map entry for
			 ** the following page matches iPage.
			 */
			if (*TBtShared)(unsafe.Pointer((*TIntegrityCk)(unsafe.Pointer(pCheck)).FpBt)).FautoVacuum != 0 && N > uint32(0) {
				i = libc.Int32FromUint32(_sqlite3Get4byte(tls, pOvflData))
				_checkPtrmap(tls, pCheck, libc.Uint32FromInt32(i), uint8(PTRMAP_OVERFLOW2), iPage)
			}
		}
		iPage = _sqlite3Get4byte(tls, pOvflData)
		_sqlite3PagerUnref(tls, **(**uintptr)(__ccgo_up(bp)))
	}
	if N != 0 && nErrAtStart == (*TIntegrityCk)(unsafe.Pointer(pCheck)).FnErr {
		if isFreeList != 0 {
			v2 = __ccgo_ts + 4539
		} else {
			v2 = __ccgo_ts + 4544
		}
		_checkAppendMsg(tls, pCheck, __ccgo_ts+4565, libc.VaList(bp+16, v2, expected-N, expected))
	}
}

// C documentation
//
//	/*
//	** Check that the entry in the pointer-map for page iChild maps to
//	** page iParent, pointer type ptrType. If not, append an error message
//	** to pCheck.
//	*/
func _checkPtrmap(tls *libc.TLS, pCheck uintptr, iChild TPgno, eType Tu8, iParent TPgno) {
	bp := tls.Alloc(64)
	defer tls.Free(64)
	var rc int32
	var _ /* ePtrmapType at bp+0 */ Tu8
	var _ /* iPtrmapParent at bp+4 */ TPgno
	_ = rc
	rc = _ptrmapGet(tls, (*TIntegrityCk)(unsafe.Pointer(pCheck)).FpBt, iChild, bp, bp+4)
	if rc != SQLITE_OK {
		if rc == int32(SQLITE_NOMEM) || rc == libc.Int32FromInt32(SQLITE_IOERR)|libc.Int32FromInt32(12)<<libc.Int32FromInt32(8) {
			_checkOom(tls, pCheck)
		}
		_checkAppendMsg(tls, pCheck, __ccgo_ts+4395, libc.VaList(bp+16, iChild))
		return
	}
	if libc.Int32FromUint8(**(**Tu8)(__ccgo_up(bp))) != libc.Int32FromUint8(eType) || **(**TPgno)(__ccgo_up(bp + 4)) != iParent {
		_checkAppendMsg(tls, pCheck, __ccgo_ts+4424, libc.VaList(bp+16, iChild, libc.Int32FromUint8(eType), iParent, libc.Int32FromUint8(**(**Tu8)(__ccgo_up(bp))), **(**TPgno)(__ccgo_up(bp + 4))))
	}
}

// C documentation
//
//	/*
//	** Check that there is no open read-transaction on the b-tree passed as the
//	** second argument. If there is not, return SQLITE_OK. Otherwise, if there
//	** is an open read-transaction, return SQLITE_ERROR and leave an error
//	** message in database handle db.
//	*/
func _checkReadTransaction(tls *libc.TLS, db uintptr, p uintptr) (r int32) {
	if _sqlite3BtreeTxnState(tls, p) != SQLITE_TXN_NONE {
		_sqlite3ErrorWithMsg(tls, db, int32(SQLITE_ERROR), __ccgo_ts+5138, 0)
		return int32(SQLITE_ERROR)
	}
	return SQLITE_OK
}

// C documentation
//
//	/*
//	** Add 1 to the reference count for page iPage.  If this is the second
//	** reference to the page, add an error message to pCheck->zErrMsg.
//	** Return 1 if there are 2 or more references to the page and 0 if
//	** if this is the first reference to the page.
//	**
//	** Also check that the page number is in bounds.
//	*/
func _checkRef(tls *libc.TLS, pCheck uintptr, iPage TPgno) (r int32) {
	bp := tls.Alloc(16)
	defer tls.Free(16)
	if iPage > (*TIntegrityCk)(unsafe.Pointer(pCheck)).FnCkPage || iPage == uint32(0) {
		_checkAppendMsg(tls, pCheck, __ccgo_ts+4347, libc.VaList(bp+8, iPage))
		return int32(1)
	}
	if _getPageReferenced(tls, pCheck, iPage) != 0 {
		_checkAppendMsg(tls, pCheck, __ccgo_ts+4370, libc.VaList(bp+8, iPage))
		return int32(1)
	}
	_setPageReferenced(tls, pCheck, iPage)
	return 0
}

// C documentation
//
//	/*
//	** Do various sanity checks on a single page of a tree.  Return
//	** the tree depth.  Root pages return 0.  Parents of root pages
//	** return 1, and so forth.
//	**
//	** These checks are done:
//	**
//	**      1.  Make sure that cells and freeblocks do not overlap
//	**          but combine to completely cover the page.
//	**      2.  Make sure integer cell keys are in order.
//	**      3.  Check the integrity of overflow pages.
//	**      4.  Recursively call checkTreePage on all children.
//	**      5.  Verify that the depth of all children is the same.
//	*/
func _checkTreePage(tls *libc.TLS, pCheck uintptr, iPage TPgno, piMinKey uintptr, _maxKey Ti64) (r int32) {
	bp := tls.Alloc(80)
	defer tls.Free(80)
	*(*Ti64)(unsafe.Pointer(bp)) = _maxKey
	var cellStart, d2, depth, doCoverageCheck, hdr, i, j, keyCanBeEqual, nCell, nFrag, pgno, rc, saved_v1, saved_v2, size1, v1 int32
	var contentOffset, nPage, pc, prev, size, usableSize Tu32
	var data, heap, pBt, pCell, pCellIdx, saved_zPfx uintptr
	var pgnoOvfl TPgno
	var savedIsInit Tu8
	var _ /* info at bp+24 */ TCellInfo
	var _ /* pPage at bp+8 */ uintptr
	var _ /* x at bp+16 */ Tu32
	_, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _ = cellStart, contentOffset, d2, data, depth, doCoverageCheck, hdr, heap, i, j, keyCanBeEqual, nCell, nFrag, nPage, pBt, pCell, pCellIdx, pc, pgno, pgnoOvfl, prev, rc, savedIsInit, saved_v1, saved_v2, saved_zPfx, size, size1, usableSize, v1
	**(**uintptr)(__ccgo_up(bp + 8)) = uintptr(0) /* Result code from subroutine call */
	depth = -int32(1)                             /* Number of cells */
	doCoverageCheck = int32(1)                    /* True if cell coverage checking should be done */
	keyCanBeEqual = int32(1)                      /* Offset to the start of the cell content area */
	heap = uintptr(0)
	prev = uint32(0) /* Next and previous entry on the min-heap */
	saved_zPfx = (*TIntegrityCk)(unsafe.Pointer(pCheck)).FzPfx
	saved_v1 = libc.Int32FromUint32((*TIntegrityCk)(unsafe.Pointer(pCheck)).Fv1)
	saved_v2 = (*TIntegrityCk)(unsafe.Pointer(pCheck)).Fv2
	savedIsInit = uint8(0)
	/* Check that the page exists
	 */
	_checkProgress(tls, pCheck)
	if (*TIntegrityCk)(unsafe.Pointer(pCheck)).FmxErr == 0 {
		goto end_of_check
	}
	pBt = (*TIntegrityCk)(unsafe.Pointer(pCheck)).FpBt
	usableSize = (*TBtShared)(unsafe.Pointer(pBt)).FusableSize
	if iPage == uint32(0) {
		return 0
	}
	if _checkRef(tls, pCheck, iPage) != 0 {
		return 0
	}
	(*TIntegrityCk)(unsafe.Pointer(pCheck)).FzPfx = __ccgo_ts + 4591
	(*TIntegrityCk)(unsafe.Pointer(pCheck)).Fv1 = iPage
	v1 = _btreeGetPage(tls, pBt, iPage, bp+8, 0)
	rc = v1
	if v1 != 0 {
		_checkAppendMsg(tls, pCheck, __ccgo_ts+4609, libc.VaList(bp+56, rc))
		if rc == libc.Int32FromInt32(SQLITE_IOERR)|libc.Int32FromInt32(12)<<libc.Int32FromInt32(8) {
			(*TIntegrityCk)(unsafe.Pointer(pCheck)).Frc = int32(SQLITE_NOMEM)
		}
		goto end_of_check
	}
	/* Clear MemPage.isInit to make sure the corruption detection code in
	 ** btreeInitPage() is executed.  */
	savedIsInit = (*TMemPage)(unsafe.Pointer(**(**uintptr)(__ccgo_up(bp + 8)))).FisInit
	(*TMemPage)(unsafe.Pointer(**(**uintptr)(__ccgo_up(bp + 8)))).FisInit = uint8(0)
	v1 = _btreeInitPage(tls, **(**uintptr)(__ccgo_up(bp + 8)))
	rc = v1
	if v1 != 0 {
		/* The only possible error from InitPage */
		_checkAppendMsg(tls, pCheck, __ccgo_ts+4647, libc.VaList(bp+56, rc))
		goto end_of_check
	}
	v1 = _btreeComputeFreeSpace(tls, **(**uintptr)(__ccgo_up(bp + 8)))
	rc = v1
	if v1 != 0 {
		_checkAppendMsg(tls, pCheck, __ccgo_ts+4685, libc.VaList(bp+56, rc))
		goto end_of_check
	}
	data = (*TMemPage)(unsafe.Pointer(**(**uintptr)(__ccgo_up(bp + 8)))).FaData
	hdr = libc.Int32FromUint8((*TMemPage)(unsafe.Pointer(**(**uintptr)(__ccgo_up(bp + 8)))).FhdrOffset)
	/* Set up for cell analysis */
	(*TIntegrityCk)(unsafe.Pointer(pCheck)).FzPfx = __ccgo_ts + 4707
	contentOffset = libc.Uint32FromInt32((libc.Int32FromUint8(**(**Tu8)(__ccgo_up(data + uintptr(hdr+int32(5)))))<<libc.Int32FromInt32(8)|libc.Int32FromUint8(**(**Tu8)(__ccgo_up(data + uintptr(hdr+int32(5)) + 1)))-libc.Int32FromInt32(1))&libc.Int32FromInt32(0xffff) + libc.Int32FromInt32(1))
	/* Enforced by btreeInitPage() */
	/* EVIDENCE-OF: R-37002-32774 The two-byte integer at offset 3 gives the
	 ** number of cells on the page. */
	nCell = libc.Int32FromUint8(**(**Tu8)(__ccgo_up(data + uintptr(hdr+int32(3)))))<<int32(8) | libc.Int32FromUint8(**(**Tu8)(__ccgo_up(data + uintptr(hdr+int32(3)) + 1)))
	if (*TMemPage)(unsafe.Pointer(**(**uintptr)(__ccgo_up(bp + 8)))).Fleaf != 0 || libc.Int32FromUint8((*TMemPage)(unsafe.Pointer(**(**uintptr)(__ccgo_up(bp + 8)))).FintKey) == 0 {
		**(**Ti64)(__ccgo_up(pCheck + 120)) += int64(nCell)
	}
	/* EVIDENCE-OF: R-23882-45353 The cell pointer array of a b-tree page
	 ** immediately follows the b-tree page header. */
	cellStart = hdr + int32(12) - int32(4)*libc.Int32FromUint8((*TMemPage)(unsafe.Pointer(**(**uintptr)(__ccgo_up(bp + 8)))).Fleaf)
	pCellIdx = data + uintptr(cellStart+int32(2)*(nCell-int32(1)))
	if !((*TMemPage)(unsafe.Pointer(**(**uintptr)(__ccgo_up(bp + 8)))).Fleaf != 0) {
		/* Analyze the right-child page of internal pages */
		pgno = libc.Int32FromUint32(_sqlite3Get4byte(tls, data+uintptr(hdr+int32(8))))
		if (*TBtShared)(unsafe.Pointer(pBt)).FautoVacuum != 0 {
			(*TIntegrityCk)(unsafe.Pointer(pCheck)).FzPfx = __ccgo_ts + 4733
			_checkPtrmap(tls, pCheck, libc.Uint32FromInt32(pgno), uint8(PTRMAP_BTREE), iPage)
		}
		depth = _checkTreePage(tls, pCheck, libc.Uint32FromInt32(pgno), bp, **(**Ti64)(__ccgo_up(bp)))
		keyCanBeEqual = 0
	} else {
		/* For leaf pages, the coverage check will occur in the same loop
		 ** as the other cell checks, so initialize the heap.  */
		heap = (*TIntegrityCk)(unsafe.Pointer(pCheck)).Fheap
		**(**Tu32)(__ccgo_up(heap)) = uint32(0)
	}
	/* EVIDENCE-OF: R-02776-14802 The cell pointer array consists of K 2-byte
	 ** integer offsets to the cell contents. */
	i = nCell - int32(1)
	for {
		if !(i >= 0 && (*TIntegrityCk)(unsafe.Pointer(pCheck)).FmxErr != 0) {
			break
		}
		/* Check cell size */
		(*TIntegrityCk)(unsafe.Pointer(pCheck)).Fv2 = i
		pc = libc.Uint32FromInt32(libc.Int32FromUint8(**(**Tu8)(__ccgo_up(pCellIdx)))<<libc.Int32FromInt32(8) | libc.Int32FromUint8(**(**Tu8)(__ccgo_up(pCellIdx + 1))))
		pCellIdx = pCellIdx - uintptr(2)
		if pc < contentOffset || pc > usableSize-uint32(4) {
			_checkAppendMsg(tls, pCheck, __ccgo_ts+4763, libc.VaList(bp+56, pc, contentOffset, usableSize-uint32(4)))
			doCoverageCheck = 0
			goto _4
		}
		pCell = data + uintptr(pc)
		(*(*func(*libc.TLS, uintptr, uintptr, uintptr))(unsafe.Pointer(&struct{ uintptr }{(*TMemPage)(unsafe.Pointer(**(**uintptr)(__ccgo_up(bp + 8)))).FxParseCell})))(tls, **(**uintptr)(__ccgo_up(bp + 8)), pCell, bp+24)
		if pc+uint32((**(**TCellInfo)(__ccgo_up(bp + 24))).FnSize) > usableSize {
			_checkAppendMsg(tls, pCheck, __ccgo_ts+4793, 0)
			doCoverageCheck = 0
			goto _4
		}
		/* Check for integer primary key out of range */
		if (*TMemPage)(unsafe.Pointer(**(**uintptr)(__ccgo_up(bp + 8)))).FintKey != 0 {
			if keyCanBeEqual != 0 {
				v1 = libc.BoolInt32((**(**TCellInfo)(__ccgo_up(bp + 24))).FnKey > **(**Ti64)(__ccgo_up(bp)))
			} else {
				v1 = libc.BoolInt32((**(**TCellInfo)(__ccgo_up(bp + 24))).FnKey >= **(**Ti64)(__ccgo_up(bp)))
			}
			if v1 != 0 {
				_checkAppendMsg(tls, pCheck, __ccgo_ts+4817, libc.VaList(bp+56, (**(**TCellInfo)(__ccgo_up(bp + 24))).FnKey))
			}
			**(**Ti64)(__ccgo_up(bp)) = (**(**TCellInfo)(__ccgo_up(bp + 24))).FnKey
			keyCanBeEqual = 0 /* Only the first key on the page may ==maxKey */
		}
		/* Check the content overflow list */
		if (**(**TCellInfo)(__ccgo_up(bp + 24))).FnPayload > uint32((**(**TCellInfo)(__ccgo_up(bp + 24))).FnLocal) { /* First page of the overflow chain */
			nPage = ((**(**TCellInfo)(__ccgo_up(bp + 24))).FnPayload - uint32((**(**TCellInfo)(__ccgo_up(bp + 24))).FnLocal) + usableSize - uint32(5)) / (usableSize - uint32(4))
			pgnoOvfl = _sqlite3Get4byte(tls, pCell+uintptr(libc.Int32FromUint16((**(**TCellInfo)(__ccgo_up(bp + 24))).FnSize)-int32(4)))
			if (*TBtShared)(unsafe.Pointer(pBt)).FautoVacuum != 0 {
				_checkPtrmap(tls, pCheck, pgnoOvfl, uint8(PTRMAP_OVERFLOW1), iPage)
			}
			_checkList(tls, pCheck, 0, pgnoOvfl, nPage)
		}
		if !((*TMemPage)(unsafe.Pointer(**(**uintptr)(__ccgo_up(bp + 8)))).Fleaf != 0) {
			/* Check sanity of left child page for internal pages */
			pgno = libc.Int32FromUint32(_sqlite3Get4byte(tls, pCell))
			if (*TBtShared)(unsafe.Pointer(pBt)).FautoVacuum != 0 {
				_checkPtrmap(tls, pCheck, libc.Uint32FromInt32(pgno), uint8(PTRMAP_BTREE), iPage)
			}
			d2 = _checkTreePage(tls, pCheck, libc.Uint32FromInt32(pgno), bp, **(**Ti64)(__ccgo_up(bp)))
			keyCanBeEqual = 0
			if d2 != depth {
				_checkAppendMsg(tls, pCheck, __ccgo_ts+4841, 0)
				depth = d2
			}
		} else {
			/* Populate the coverage-checking heap for leaf pages */
			_btreeHeapInsert(tls, heap, pc<<libc.Int32FromInt32(16)|(pc+uint32((**(**TCellInfo)(__ccgo_up(bp + 24))).FnSize)-uint32(1)))
		}
		goto _4
	_4:
		;
		i = i - 1
	}
	**(**Ti64)(__ccgo_up(piMinKey)) = **(**Ti64)(__ccgo_up(bp))
	/* Check for complete coverage of the page
	 */
	(*TIntegrityCk)(unsafe.Pointer(pCheck)).FzPfx = uintptr(0)
	if doCoverageCheck != 0 && (*TIntegrityCk)(unsafe.Pointer(pCheck)).FmxErr > 0 {
		/* For leaf pages, the min-heap has already been initialized and the
		 ** cells have already been inserted.  But for internal pages, that has
		 ** not yet been done, so do it now */
		if !((*TMemPage)(unsafe.Pointer(**(**uintptr)(__ccgo_up(bp + 8)))).Fleaf != 0) {
			heap = (*TIntegrityCk)(unsafe.Pointer(pCheck)).Fheap
			**(**Tu32)(__ccgo_up(heap)) = uint32(0)
			i = nCell - int32(1)
			for {
				if !(i >= 0) {
					break
				}
				pc = libc.Uint32FromInt32(libc.Int32FromUint8(**(**Tu8)(__ccgo_up(data + uintptr(cellStart+i*int32(2)))))<<libc.Int32FromInt32(8) | libc.Int32FromUint8(**(**Tu8)(__ccgo_up(data + uintptr(cellStart+i*int32(2)) + 1))))
				size = uint32((*(*func(*libc.TLS, uintptr, uintptr) Tu16)(unsafe.Pointer(&struct{ uintptr }{(*TMemPage)(unsafe.Pointer(**(**uintptr)(__ccgo_up(bp + 8)))).FxCellSize})))(tls, **(**uintptr)(__ccgo_up(bp + 8)), data+uintptr(pc)))
				_btreeHeapInsert(tls, heap, pc<<libc.Int32FromInt32(16)|(pc+size-uint32(1)))
				goto _6
			_6:
				;
				i = i - 1
			}
		}
		/* Add the freeblocks to the min-heap
		 **
		 ** EVIDENCE-OF: R-20690-50594 The second field of the b-tree page header
		 ** is the offset of the first freeblock, or zero if there are no
		 ** freeblocks on the page.
		 */
		i = libc.Int32FromUint8(**(**Tu8)(__ccgo_up(data + uintptr(hdr+int32(1)))))<<int32(8) | libc.Int32FromUint8(**(**Tu8)(__ccgo_up(data + uintptr(hdr+int32(1)) + 1)))
		for i > 0 {
			/* Enforced by btreeComputeFreeSpace() */
			size1 = libc.Int32FromUint8(**(**Tu8)(__ccgo_up(data + uintptr(i+int32(2)))))<<int32(8) | libc.Int32FromUint8(**(**Tu8)(__ccgo_up(data + uintptr(i+int32(2)) + 1)))
			/* due to btreeComputeFreeSpace() */
			_btreeHeapInsert(tls, heap, libc.Uint32FromInt32(i)<<libc.Int32FromInt32(16)|libc.Uint32FromInt32(i+size1-libc.Int32FromInt32(1)))
			/* EVIDENCE-OF: R-58208-19414 The first 2 bytes of a freeblock are a
			 ** big-endian integer which is the offset in the b-tree page of the next
			 ** freeblock in the chain, or zero if the freeblock is the last on the
			 ** chain. */
			j = libc.Int32FromUint8(**(**Tu8)(__ccgo_up(data + uintptr(i))))<<int32(8) | libc.Int32FromUint8(**(**Tu8)(__ccgo_up(data + uintptr(i) + 1)))
			/* EVIDENCE-OF: R-06866-39125 Freeblocks are always connected in order of
			 ** increasing offset. */
			/* Enforced by btreeComputeFreeSpace() */
			/* Enforced by btreeComputeFreeSpace() */
			i = j
		}
		/* Analyze the min-heap looking for overlap between cells and/or
		 ** freeblocks, and counting the number of untracked bytes in nFrag.
		 **
		 ** Each min-heap entry is of the form:    (start_address<<16)|end_address.
		 ** There is an implied first entry the covers the page header, the cell
		 ** pointer index, and the gap between the cell pointer index and the start
		 ** of cell content.
		 **
		 ** The loop below pulls entries from the min-heap in order and compares
		 ** the start_address against the previous end_address.  If there is an
		 ** overlap, that means bytes are used multiple times.  If there is a gap,
		 ** that gap is added to the fragmentation count.
		 */
		nFrag = 0
		prev = contentOffset - uint32(1) /* Implied first min-heap entry */
		for _btreeHeapPull(tls, heap, bp+16) != 0 {
			if prev&uint32(0xffff) >= **(**Tu32)(__ccgo_up(bp + 16))>>libc.Int32FromInt32(16) {
				_checkAppendMsg(tls, pCheck, __ccgo_ts+4866, libc.VaList(bp+56, **(**Tu32)(__ccgo_up(bp + 16))>>int32(16), iPage))
				break
			} else {
				nFrag = libc.Int32FromUint32(uint32(nFrag) + (**(**Tu32)(__ccgo_up(bp + 16))>>libc.Int32FromInt32(16) - prev&libc.Uint32FromInt32(0xffff) - libc.Uint32FromInt32(1)))
				prev = **(**Tu32)(__ccgo_up(bp + 16))
			}
		}
		nFrag = libc.Int32FromUint32(uint32(nFrag) + (usableSize - prev&libc.Uint32FromInt32(0xffff) - libc.Uint32FromInt32(1)))
		/* EVIDENCE-OF: R-43263-13491 The total number of bytes in all fragments
		 ** is stored in the fifth field of the b-tree page header.
		 ** EVIDENCE-OF: R-07161-27322 The one-byte integer at offset 7 gives the
		 ** number of fragmented free bytes within the cell content area.
		 */
		if **(**Tu32)(__ccgo_up(heap)) == uint32(0) && nFrag != libc.Int32FromUint8(**(**Tu8)(__ccgo_up(data + uintptr(hdr+int32(7))))) {
			_checkAppendMsg(tls, pCheck, __ccgo_ts+4903, libc.VaList(bp+56, nFrag, libc.Int32FromUint8(**(**Tu8)(__ccgo_up(data + uintptr(hdr+int32(7))))), iPage))
		}
	}
	goto end_of_check
end_of_check:
	;
	if !(doCoverageCheck != 0) {
		(*TMemPage)(unsafe.Pointer(**(**uintptr)(__ccgo_up(bp + 8)))).FisInit = savedIsInit
	}
	_releasePage(tls, **(**uintptr)(__ccgo_up(bp + 8)))
	(*TIntegrityCk)(unsafe.Pointer(pCheck)).FzPfx = saved_zPfx
	(*TIntegrityCk)(unsafe.Pointer(pCheck)).Fv1 = libc.Uint32FromInt32(saved_v1)
	(*TIntegrityCk)(unsafe.Pointer(pCheck)).Fv2 = saved_v2
	return depth + int32(1)
}

// C documentation
//
//	/*
//	** Generate an instruction that will put the integer describe by
//	** text z[0..n-1] into register iMem.
//	**
//	** Expr.u.zToken is always UTF8 and zero-terminated.
//	*/
func _codeInteger(tls *libc.TLS, pParse uintptr, pExpr uintptr, negFlag int32, iMem int32) {
	bp := tls.Alloc(32)
	defer tls.Free(32)
	var c, i int32
	var v, z, v1 uintptr
	var v2 int64
	var _ /* value at bp+0 */ Ti64
	_, _, _, _, _, _ = c, i, v, z, v1, v2
	v = (*TParse)(unsafe.Pointer(pParse)).FpVdbe
	if (*TExpr)(unsafe.Pointer(pExpr)).Fflags&uint32(EP_IntValue) != 0 {
		i = *(*int32)(unsafe.Pointer(&(*TExpr)(unsafe.Pointer(pExpr)).Fu))
		if negFlag != 0 {
			i = -i
		}
		_sqlite3VdbeAddOp2(tls, v, int32(OP_Integer), i, iMem)
	} else {
		z = *(*uintptr)(unsafe.Pointer(pExpr + 8))
		c = _sqlite3DecOrHexToI64(tls, z, bp)
		if c == int32(3) && !(negFlag != 0) || c == int32(2) || negFlag != 0 && **(**Ti64)(__ccgo_up(bp)) == int64(-libc.Int32FromInt32(1))-(libc.Int64FromUint32(0xffffffff)|libc.Int64FromInt32(0x7fffffff)<<libc.Int32FromInt32(32)) {
			if Xsqlite3_strnicmp(tls, z, __ccgo_ts+8415, int32(2)) == 0 {
				if negFlag != 0 {
					v1 = __ccgo_ts + 5218
				} else {
					v1 = __ccgo_ts + 1693
				}
				_sqlite3ErrorMsg(tls, pParse, __ccgo_ts+8418, libc.VaList(bp+16, v1, pExpr))
			} else {
				_codeReal(tls, v, z, negFlag, iMem)
			}
		} else {
			if negFlag != 0 {
				if c == int32(3) {
					v2 = int64(-libc.Int32FromInt32(1)) - (libc.Int64FromUint32(0xffffffff) | libc.Int64FromInt32(0x7fffffff)<<libc.Int32FromInt32(32))
				} else {
					v2 = -**(**Ti64)(__ccgo_up(bp))
				}
				**(**Ti64)(__ccgo_up(bp)) = v2
			}
			_sqlite3VdbeAddOp4Dup8(tls, v, int32(OP_Int64), 0, iMem, 0, bp, -int32(14))
		}
	}
}

// C documentation
//
//	/*
//	** Create and populate a new TriggerPrg object with a sub-program
//	** implementing trigger pTrigger with ON CONFLICT policy orconf.
//	*/
func _codeRowTrigger(tls *libc.TLS, pParse uintptr, pTrigger uintptr, pTab uintptr, orconf int32) (r uintptr) {
	bp := tls.Alloc(496)
	defer tls.Free(496)
	var db, pPrg, pProgram, pTop, pWhen, v, v2 uintptr
	var iEndTrigger, nDepth int32
	var _ /* sNC at bp+0 */ TNameContext
	var _ /* sSubParse at bp+56 */ TParse
	_, _, _, _, _, _, _, _, _ = db, iEndTrigger, nDepth, pPrg, pProgram, pTop, pWhen, v, v2 /* Top level Parse object */
	db = (*TParse)(unsafe.Pointer(pParse)).Fdb                                              /* Value to return */
	pWhen = uintptr(0)                                                                      /* Name context for sub-vdbe */
	pProgram = uintptr(0)                                                                   /* Sub-vdbe for trigger program */
	iEndTrigger = 0                                                                         /* Trigger depth */
	/* Ensure that triggers are not chained too deep.  This test is linear
	 ** in the chaining depth, but sensible code ought not be chaining
	 ** triggers excessively, so that shouldn't be a problem.
	 */
	pTop = pParse
	nDepth = 0
	for {
		if !((*TParse)(unsafe.Pointer(pTop)).FpOuterParse != 0) {
			break
		}
		goto _1
	_1:
		;
		pTop = (*TParse)(unsafe.Pointer(pTop)).FpOuterParse
		nDepth = nDepth + 1
	}
	if nDepth >= **(**int32)(__ccgo_up(db + 136 + 10*4)) {
		_sqlite3ErrorMsg(tls, pParse, __ccgo_ts+22557, 0)
		return uintptr(0)
	}
	if (*TParse)(unsafe.Pointer(pParse)).FpToplevel != 0 {
		v2 = (*TParse)(unsafe.Pointer(pParse)).FpToplevel
	} else {
		v2 = pParse
	}
	pTop = v2
	/* Allocate the TriggerPrg and SubProgram objects. To ensure that they
	 ** are freed if an error occurs, link them into the Parse.pTriggerPrg
	 ** list of the top-level Parse object sooner rather than later.  */
	pPrg = _sqlite3DbMallocZero(tls, db, uint64(40))
	if !(pPrg != 0) {
		return uintptr(0)
	}
	(*TTriggerPrg)(unsafe.Pointer(pPrg)).FpNext = (*TParse)(unsafe.Pointer(pTop)).FpTriggerPrg
	(*TParse)(unsafe.Pointer(pTop)).FpTriggerPrg = pPrg
	v2 = _sqlite3DbMallocZero(tls, db, uint64(48))
	pProgram = v2
	(*TTriggerPrg)(unsafe.Pointer(pPrg)).FpProgram = v2
	if !(pProgram != 0) {
		return uintptr(0)
	}
	_sqlite3VdbeLinkSubProgram(tls, (*TParse)(unsafe.Pointer(pTop)).FpVdbe, pProgram)
	(*TTriggerPrg)(unsafe.Pointer(pPrg)).FpTrigger = pTrigger
	(*TTriggerPrg)(unsafe.Pointer(pPrg)).Forconf = orconf
	**(**Tu32)(__ccgo_up(pPrg + 28)) = uint32(0xffffffff)
	**(**Tu32)(__ccgo_up(pPrg + 28 + 1*4)) = uint32(0xffffffff)
	/* Allocate and populate a new Parse context to use for coding the
	 ** trigger sub-program.  */
	_sqlite3ParseObjectInit(tls, bp+56, db)
	libc.Xmemset(tls, bp, 0, uint64(56))
	(**(**TNameContext)(__ccgo_up(bp))).FpParse = bp + 56
	(**(**TParse)(__ccgo_up(bp + 56))).FpTriggerTab = pTab
	(**(**TParse)(__ccgo_up(bp + 56))).FpToplevel = pTop
	(**(**TParse)(__ccgo_up(bp + 56))).FzAuthContext = (*TTrigger)(unsafe.Pointer(pTrigger)).FzName
	(**(**TParse)(__ccgo_up(bp + 56))).FeTriggerOp = (*TTrigger)(unsafe.Pointer(pTrigger)).Fop
	(**(**TParse)(__ccgo_up(bp + 56))).FnQueryLoop = (*TParse)(unsafe.Pointer(pParse)).FnQueryLoop
	(**(**TParse)(__ccgo_up(bp + 56))).FprepFlags = (*TParse)(unsafe.Pointer(pParse)).FprepFlags
	(**(**TParse)(__ccgo_up(bp + 56))).Foldmask = uint32(0)
	(**(**TParse)(__ccgo_up(bp + 56))).Fnewmask = uint32(0)
	v = _sqlite3GetVdbe(tls, bp+56)
	if v != 0 {
		if (*TTrigger)(unsafe.Pointer(pTrigger)).FzName != 0 {
			_sqlite3VdbeChangeP4(tls, v, -int32(1), _sqlite3MPrintf(tls, db, __ccgo_ts+22582, libc.VaList(bp+488, (*TTrigger)(unsafe.Pointer(pTrigger)).FzName)), -int32(7))
		}
		/* If one was specified, code the WHEN clause. If it evaluates to false
		 ** (or NULL) the sub-vdbe is immediately halted by jumping to the
		 ** OP_Halt inserted at the end of the program.  */
		if (*TTrigger)(unsafe.Pointer(pTrigger)).FpWhen != 0 {
			pWhen = _sqlite3ExprDup(tls, db, (*TTrigger)(unsafe.Pointer(pTrigger)).FpWhen, 0)
			if libc.Int32FromUint8((*Tsqlite3)(unsafe.Pointer(db)).FmallocFailed) == 0 && SQLITE_OK == _sqlite3ResolveExprNames(tls, bp, pWhen) {
				iEndTrigger = _sqlite3VdbeMakeLabel(tls, bp+56)
				_sqlite3ExprIfFalse(tls, bp+56, pWhen, iEndTrigger, int32(SQLITE_JUMPIFNULL))
			}
			_sqlite3ExprDelete(tls, db, pWhen)
		}
		/* Code the trigger program into the sub-vdbe. */
		_codeTriggerProgram(tls, bp+56, (*TTrigger)(unsafe.Pointer(pTrigger)).Fstep_list, orconf)
		/* Insert an OP_Halt at the end of the sub-program. */
		if iEndTrigger != 0 {
			_sqlite3VdbeResolveLabel(tls, v, iEndTrigger)
		}
		_sqlite3VdbeAddOp0(tls, v, int32(OP_Halt))
		_transferParseError(tls, pParse, bp+56)
		if (*TParse)(unsafe.Pointer(pParse)).FnErr == 0 {
			(*TSubProgram)(unsafe.Pointer(pProgram)).FaOp = _sqlite3VdbeTakeOpArray(tls, v, pProgram+8, pTop+128)
		}
		(*TSubProgram)(unsafe.Pointer(pProgram)).FnMem = (**(**TParse)(__ccgo_up(bp + 56))).FnMem
		(*TSubProgram)(unsafe.Pointer(pProgram)).FnCsr = (**(**TParse)(__ccgo_up(bp + 56))).FnTab
		(*TSubProgram)(unsafe.Pointer(pProgram)).Ftoken = pTrigger
		**(**Tu32)(__ccgo_up(pPrg + 28)) = (**(**TParse)(__ccgo_up(bp + 56))).Foldmask
		**(**Tu32)(__ccgo_up(pPrg + 28 + 1*4)) = (**(**TParse)(__ccgo_up(bp + 56))).Fnewmask
		_sqlite3VdbeDelete(tls, v)
	} else {
		_transferParseError(tls, pParse, bp+56)
	}
	_sqlite3ParseObjectReset(tls, bp+56)
	return pPrg
}

// C documentation
//
//	/*
//	** Generate VDBE code for the statements inside the body of a single
//	** trigger.
//	*/
func _codeTriggerProgram(tls *libc.TLS, pParse uintptr, pStepList uintptr, orconf int32) (r int32) {
	bp := tls.Alloc(64)
	defer tls.Free(64)
	var db, pSelect, pStep, v uintptr
	var v2 int32
	var _ /* sDest at bp+0 */ TSelectDest
	_, _, _, _, _ = db, pSelect, pStep, v, v2
	v = (*TParse)(unsafe.Pointer(pParse)).FpVdbe
	db = (*TParse)(unsafe.Pointer(pParse)).Fdb
	pStep = pStepList
	for {
		if !(pStep != 0) {
			break
		}
		/* Figure out the ON CONFLICT policy that will be used for this step
		 ** of the trigger program. If the statement that caused this trigger
		 ** to fire had an explicit ON CONFLICT, then use it. Otherwise, use
		 ** the ON CONFLICT policy that was specified as part of the trigger
		 ** step statement. Example:
		 **
		 **   CREATE TRIGGER AFTER INSERT ON t1 BEGIN;
		 **     INSERT OR REPLACE INTO t2 VALUES(new.a, new.b);
		 **   END;
		 **
		 **   INSERT INTO t1 ... ;            -- insert into t2 uses REPLACE policy
		 **   INSERT OR IGNORE INTO t1 ... ;  -- insert into t2 uses IGNORE policy
		 */
		if orconf == int32(OE_Default) {
			v2 = libc.Int32FromUint8((*TTriggerStep)(unsafe.Pointer(pStep)).Forconf)
		} else {
			v2 = libc.Int32FromUint8(libc.Uint8FromInt32(orconf))
		}
		(*TParse)(unsafe.Pointer(pParse)).FeOrconf = libc.Uint8FromInt32(v2)
		if (*TTriggerStep)(unsafe.Pointer(pStep)).FzSpan != 0 {
			_sqlite3VdbeAddOp4(tls, v, int32(OP_Trace), int32(0x7fffffff), int32(1), 0, _sqlite3MPrintf(tls, db, __ccgo_ts+6474, libc.VaList(bp+48, (*TTriggerStep)(unsafe.Pointer(pStep)).FzSpan)), -int32(7))
		}
		switch libc.Int32FromUint8((*TTriggerStep)(unsafe.Pointer(pStep)).Fop) {
		case int32(TK_UPDATE):
			_sqlite3Update(tls, pParse, _sqlite3SrcListDup(tls, db, (*TTriggerStep)(unsafe.Pointer(pStep)).FpSrc, 0), _sqlite3ExprListDup(tls, db, (*TTriggerStep)(unsafe.Pointer(pStep)).FpExprList, 0), _sqlite3ExprDup(tls, db, (*TTriggerStep)(unsafe.Pointer(pStep)).FpWhere, 0), libc.Int32FromUint8((*TParse)(unsafe.Pointer(pParse)).FeOrconf), uintptr(0), uintptr(0), uintptr(0))
			_sqlite3VdbeAddOp0(tls, v, int32(OP_ResetCount))
		case int32(TK_INSERT):
			_sqlite3Insert(tls, pParse, _sqlite3SrcListDup(tls, db, (*TTriggerStep)(unsafe.Pointer(pStep)).FpSrc, 0), _sqlite3SelectDup(tls, db, (*TTriggerStep)(unsafe.Pointer(pStep)).FpSelect, 0), _sqlite3IdListDup(tls, db, (*TTriggerStep)(unsafe.Pointer(pStep)).FpIdList), libc.Int32FromUint8((*TParse)(unsafe.Pointer(pParse)).FeOrconf), _sqlite3UpsertDup(tls, db, (*TTriggerStep)(unsafe.Pointer(pStep)).FpUpsert))
			_sqlite3VdbeAddOp0(tls, v, int32(OP_ResetCount))
		case int32(TK_DELETE):
			_sqlite3DeleteFrom(tls, pParse, _sqlite3SrcListDup(tls, db, (*TTriggerStep)(unsafe.Pointer(pStep)).FpSrc, 0), _sqlite3ExprDup(tls, db, (*TTriggerStep)(unsafe.Pointer(pStep)).FpWhere, 0), uintptr(0), uintptr(0))
			_sqlite3VdbeAddOp0(tls, v, int32(OP_ResetCount))
		default:
			pSelect = _sqlite3SelectDup(tls, db, (*TTriggerStep)(unsafe.Pointer(pStep)).FpSelect, 0)
			_sqlite3SelectDestInit(tls, bp, int32(SRT_Discard), 0)
			_sqlite3Select(tls, pParse, pSelect, bp)
			_sqlite3SelectDelete(tls, db, pSelect)
			break
		}
		goto _1
	_1:
		;
		pStep = (*TTriggerStep)(unsafe.Pointer(pStep)).FpNext
	}
	return 0
}

// C documentation
//
//	/*
//	** Expression pExpr is a comparison between two vector values. Compute
//	** the result of the comparison (1, 0, or NULL) and write that
//	** result into register dest.
//	**
//	** The caller must satisfy the following preconditions:
//	**
//	**    if pExpr->op==TK_IS:      op==TK_EQ and p5==SQLITE_NULLEQ
//	**    if pExpr->op==TK_ISNOT:   op==TK_NE and p5==SQLITE_NULLEQ
//	**    otherwise:                op==pExpr->op and p5==0
//	*/
func _codeVectorCompare(tls *libc.TLS, pParse uintptr, pExpr uintptr, dest int32, op Tu8, p5 Tu8) {
	bp := tls.Alloc(32)
	defer tls.Free(32)
	var addrCmp, addrDone, i, isCommuted, nLeft, r1, r2, regLeft, regRight int32
	var opx Tu8
	var pLeft, pRight, v uintptr
	var _ /* pL at bp+8 */ uintptr
	var _ /* pR at bp+16 */ uintptr
	var _ /* regFree1 at bp+0 */ int32
	var _ /* regFree2 at bp+4 */ int32
	_, _, _, _, _, _, _, _, _, _, _, _, _ = addrCmp, addrDone, i, isCommuted, nLeft, opx, pLeft, pRight, r1, r2, regLeft, regRight, v
	v = (*TParse)(unsafe.Pointer(pParse)).FpVdbe
	pLeft = (*TExpr)(unsafe.Pointer(pExpr)).FpLeft
	pRight = (*TExpr)(unsafe.Pointer(pExpr)).FpRight
	nLeft = _sqlite3ExprVectorSize(tls, pLeft)
	regLeft = 0
	regRight = 0
	opx = op
	addrCmp = 0
	addrDone = _sqlite3VdbeMakeLabel(tls, pParse)
	isCommuted = libc.BoolInt32((*TExpr)(unsafe.Pointer(pExpr)).Fflags&libc.Uint32FromInt32(libc.Int32FromInt32(EP_Commuted)) != uint32(0))
	if (*TParse)(unsafe.Pointer(pParse)).FnErr != 0 {
		return
	}
	if nLeft != _sqlite3ExprVectorSize(tls, pRight) {
		_sqlite3ErrorMsg(tls, pParse, __ccgo_ts+6901, 0)
		return
	}
	if libc.Int32FromUint8(op) == int32(TK_LE) {
		opx = uint8(TK_LT)
	}
	if libc.Int32FromUint8(op) == int32(TK_GE) {
		opx = uint8(TK_GT)
	}
	if libc.Int32FromUint8(op) == int32(TK_NE) {
		opx = uint8(TK_EQ)
	}
	regLeft = _exprCodeSubselect(tls, pParse, pLeft)
	regRight = _exprCodeSubselect(tls, pParse, pRight)
	_sqlite3VdbeAddOp2(tls, v, int32(OP_Integer), int32(1), dest)
	i = 0
	for {
		if !(int32(1) != 0) {
			break
		}
		**(**int32)(__ccgo_up(bp)) = 0
		**(**int32)(__ccgo_up(bp + 4)) = 0
		**(**uintptr)(__ccgo_up(bp + 8)) = uintptr(0)
		**(**uintptr)(__ccgo_up(bp + 16)) = uintptr(0)
		if addrCmp != 0 {
			_sqlite3VdbeJumpHere(tls, v, addrCmp)
		}
		r1 = _exprVectorRegister(tls, pParse, pLeft, i, regLeft, bp+8, bp)
		r2 = _exprVectorRegister(tls, pParse, pRight, i, regRight, bp+16, bp+4)
		addrCmp = _sqlite3VdbeCurrentAddr(tls, v)
		_codeCompare(tls, pParse, **(**uintptr)(__ccgo_up(bp + 8)), **(**uintptr)(__ccgo_up(bp + 16)), libc.Int32FromUint8(opx), r1, r2, addrDone, libc.Int32FromUint8(p5), isCommuted)
		_sqlite3ReleaseTempReg(tls, pParse, **(**int32)(__ccgo_up(bp)))
		_sqlite3ReleaseTempReg(tls, pParse, **(**int32)(__ccgo_up(bp + 4)))
		if (libc.Int32FromUint8(opx) == int32(TK_LT) || libc.Int32FromUint8(opx) == int32(TK_GT)) && i < nLeft-int32(1) {
			addrCmp = _sqlite3VdbeAddOp0(tls, v, int32(OP_ElseEq))
		}
		if libc.Int32FromUint8(p5) == int32(SQLITE_NULLEQ) {
			_sqlite3VdbeAddOp2(tls, v, int32(OP_Integer), 0, dest)
		} else {
			_sqlite3VdbeAddOp3(tls, v, int32(OP_ZeroOrNull), r1, dest, r2)
		}
		if i == nLeft-int32(1) {
			break
		}
		if libc.Int32FromUint8(opx) == int32(TK_EQ) {
			_sqlite3VdbeAddOp2(tls, v, int32(OP_NotNull), dest, addrDone)
		} else {
			_sqlite3VdbeAddOp2(tls, v, int32(OP_Goto), 0, addrDone)
			if i == nLeft-int32(2) {
				opx = op
			}
		}
		goto _1
	_1:
		;
		i = i + 1
	}
	_sqlite3VdbeJumpHere(tls, v, addrCmp)
	_sqlite3VdbeResolveLabel(tls, v, addrDone)
	if libc.Int32FromUint8(op) == int32(TK_NE) {
		_sqlite3VdbeAddOp2(tls, v, int32(OP_Not), dest, dest)
	}
}

// C documentation
//
//	/*
//	** Return a pointer to a string containing the 'declaration type' of the
//	** expression pExpr. The string may be treated as static by the caller.
//	**
//	** The declaration type is the exact datatype definition extracted from the
//	** original CREATE TABLE statement if the expression is a column. The
//	** declaration type for a ROWID field is INTEGER. Exactly when an expression
//	** is considered a column can be complex in the presence of subqueries. The
//	** result-set expression in all of the following SELECT statements is
//	** considered a column by this function.
//	**
//	**   SELECT col FROM tbl;
//	**   SELECT (SELECT col FROM tbl;
//	**   SELECT (SELECT col FROM tbl);
//	**   SELECT abc FROM (SELECT col AS abc FROM tbl);
//	**
//	** The declaration type for any expression other than a column is NULL.
//	**
//	** This routine has either 3 or 6 parameters depending on whether or not
//	** the SQLITE_ENABLE_COLUMN_METADATA compile-time option is used.
//	*/
func _columnTypeImpl(tls *libc.TLS, pNC uintptr, pExpr uintptr, pzOrigDb uintptr, pzOrigTab uintptr, pzOrigCol uintptr) (r uintptr) {
	bp := tls.Alloc(144)
	defer tls.Free(144)
	var iCol, iDb, j int32
	var p, p1, pS, pS1, pTab, pTabList, zType uintptr
	var _ /* sNC at bp+24 */ TNameContext
	var _ /* sNC at bp+80 */ TNameContext
	var _ /* zOrigCol at bp+16 */ uintptr
	var _ /* zOrigDb at bp+0 */ uintptr
	var _ /* zOrigTab at bp+8 */ uintptr
	_, _, _, _, _, _, _, _, _, _ = iCol, iDb, j, p, p1, pS, pS1, pTab, pTabList, zType
	zType = uintptr(0)
	**(**uintptr)(__ccgo_up(bp)) = uintptr(0)
	**(**uintptr)(__ccgo_up(bp + 8)) = uintptr(0)
	**(**uintptr)(__ccgo_up(bp + 16)) = uintptr(0)
	switch libc.Int32FromUint8((*TExpr)(unsafe.Pointer(pExpr)).Fop) {
	case int32(TK_COLUMN):
		/* The expression is a column. Locate the table the column is being
		 ** extracted from in NameContext.pSrcList. This table may be real
		 ** database table or a subquery.
		 */
		pTab = uintptr(0)                                      /* Table structure column is extracted from */
		pS = uintptr(0)                                        /* Select the column is extracted from */
		iCol = int32((*TExpr)(unsafe.Pointer(pExpr)).FiColumn) /* Index of column in pTab */
		for pNC != 0 && !(pTab != 0) {
			pTabList = (*TNameContext)(unsafe.Pointer(pNC)).FpSrcList
			j = 0
			for {
				if !(j < (*TSrcList)(unsafe.Pointer(pTabList)).FnSrc && (*(*TSrcItem)(unsafe.Pointer(pTabList + 8 + uintptr(j)*80))).FiCursor != (*TExpr)(unsafe.Pointer(pExpr)).FiTable) {
					break
				}
				goto _1
			_1:
				;
				j = j + 1
			}
			if j < (*TSrcList)(unsafe.Pointer(pTabList)).FnSrc {
				pTab = (*(*TSrcItem)(unsafe.Pointer(pTabList + 8 + uintptr(j)*80))).FpSTab
				if int32(*(*uint32)(unsafe.Pointer(pTabList + 8 + uintptr(j)*80 + 24 + 4))&0x4>>2) != 0 {
					pS = (*TSubquery)(unsafe.Pointer(*(*uintptr)(unsafe.Pointer(pTabList + 8 + uintptr(j)*80 + 72)))).FpSelect
				} else {
					pS = uintptr(0)
				}
			} else {
				pNC = (*TNameContext)(unsafe.Pointer(pNC)).FpNext
			}
		}
		if pTab == uintptr(0) {
			/* At one time, code such as "SELECT new.x" within a trigger would
			 ** cause this condition to run.  Since then, we have restructured how
			 ** trigger code is generated and so this condition is no longer
			 ** possible. However, it can still be true for statements like
			 ** the following:
			 **
			 **   CREATE TABLE t1(col INTEGER);
			 **   SELECT (SELECT t1.col) FROM FROM t1;
			 **
			 ** when columnType() is called on the expression "t1.col" in the
			 ** sub-select. In this case, set the column type to NULL, even
			 ** though it should really be "INTEGER".
			 **
			 ** This is not a problem, as the column type of "t1.col" is never
			 ** used. When columnType() is called on the expression
			 ** "(SELECT t1.col)", the correct type is returned (see the TK_SELECT
			 ** branch below.  */
			break
		}
		if pS != 0 {
			/* The "table" is actually a sub-select or a view in the FROM clause
			 ** of the SELECT statement. Return the declaration type and origin
			 ** data for the result-set column of the sub-select.
			 */
			if iCol < (*TExprList)(unsafe.Pointer((*TSelect)(unsafe.Pointer(pS)).FpEList)).FnExpr && libc.Bool(libc.Bool(!(libc.Int32FromInt32(ViewCanHaveRowid) != 0)) || iCol >= 0) {
				p = (*(*TExprList_item)(unsafe.Pointer((*TSelect)(unsafe.Pointer(pS)).FpEList + 8 + uintptr(iCol)*32))).FpExpr
				(**(**TNameContext)(__ccgo_up(bp + 24))).FpSrcList = (*TSelect)(unsafe.Pointer(pS)).FpSrc
				(**(**TNameContext)(__ccgo_up(bp + 24))).FpNext = pNC
				(**(**TNameContext)(__ccgo_up(bp + 24))).FpParse = (*TNameContext)(unsafe.Pointer(pNC)).FpParse
				zType = _columnTypeImpl(tls, bp+24, p, bp, bp+8, bp+16)
			}
		} else {
			/* A real table or a CTE table */
			if iCol < 0 {
				iCol = int32((*TTable)(unsafe.Pointer(pTab)).FiPKey)
			}
			if iCol < 0 {
				zType = __ccgo_ts + 1167
				**(**uintptr)(__ccgo_up(bp + 16)) = __ccgo_ts + 17956
			} else {
				**(**uintptr)(__ccgo_up(bp + 16)) = (**(**TColumn)(__ccgo_up((*TTable)(unsafe.Pointer(pTab)).FaCol + uintptr(iCol)*16))).FzCnName
				zType = _sqlite3ColumnType(tls, (*TTable)(unsafe.Pointer(pTab)).FaCol+uintptr(iCol)*16, uintptr(0))
			}
			**(**uintptr)(__ccgo_up(bp + 8)) = (*TTable)(unsafe.Pointer(pTab)).FzName
			if (*TNameContext)(unsafe.Pointer(pNC)).FpParse != 0 && (*TTable)(unsafe.Pointer(pTab)).FpSchema != 0 {
				iDb = _sqlite3SchemaToIndex(tls, (*TParse)(unsafe.Pointer((*TNameContext)(unsafe.Pointer(pNC)).FpParse)).Fdb, (*TTable)(unsafe.Pointer(pTab)).FpSchema)
				**(**uintptr)(__ccgo_up(bp)) = (**(**TDb)(__ccgo_up((*Tsqlite3)(unsafe.Pointer((*TParse)(unsafe.Pointer((*TNameContext)(unsafe.Pointer(pNC)).FpParse)).Fdb)).FaDb + uintptr(iDb)*32))).FzDbSName
			}
		}
	case int32(TK_SELECT):
		pS1 = *(*uintptr)(unsafe.Pointer(pExpr + 32))
		p1 = (*(*TExprList_item)(unsafe.Pointer((*TSelect)(unsafe.Pointer(pS1)).FpEList + 8))).FpExpr
		(**(**TNameContext)(__ccgo_up(bp + 80))).FpSrcList = (*TSelect)(unsafe.Pointer(pS1)).FpSrc
		(**(**TNameContext)(__ccgo_up(bp + 80))).FpNext = pNC
		(**(**TNameContext)(__ccgo_up(bp + 80))).FpParse = (*TNameContext)(unsafe.Pointer(pNC)).FpParse
		zType = _columnTypeImpl(tls, bp+80, p1, bp, bp+8, bp+16)
		break
	}
	if pzOrigDb != 0 {
		**(**uintptr)(__ccgo_up(pzOrigDb)) = **(**uintptr)(__ccgo_up(bp))
		**(**uintptr)(__ccgo_up(pzOrigTab)) = **(**uintptr)(__ccgo_up(bp + 8))
		**(**uintptr)(__ccgo_up(pzOrigCol)) = **(**uintptr)(__ccgo_up(bp + 16))
	}
	return zType
}

// C documentation
//
//	/*
//	** The CONCAT(...) function.  Generate a string result that is the
//	** concatentation of all non-null arguments.
//	*/
func _concatFunc(tls *libc.TLS, context uintptr, argc int32, argv uintptr) {
	_concatFuncCore(tls, context, argc, argv, 0, __ccgo_ts+1693)
}

// C documentation
//
//	/*
//	** Attempt to transform a query of the form
//	**
//	**    SELECT count(*) FROM (SELECT x FROM t1 UNION ALL SELECT y FROM t2)
//	**
//	** Into this:
//	**
//	**    SELECT (SELECT count(*) FROM t1)+(SELECT count(*) FROM t2)
//	**
//	** The transformation only works if all of the following are true:
//	**
//	**   *  The subquery is a UNION ALL of two or more terms
//	**   *  The subquery does not have a LIMIT clause
//	**   *  There is no WHERE or GROUP BY or HAVING clauses on the subqueries
//	**   *  The outer query is a simple count(*) with no WHERE clause or other
//	**      extraneous syntax.
//	**   *  None of the subqueries are DISTINCT (forumpost/a860f5fb2e 2025-03-10)
//	**
//	** Return TRUE if the optimization is undertaken.
//	*/
func _countOfViewOptimization(tls *libc.TLS, pParse uintptr, p uintptr) (r int32) {
	var db, pCount, pExpr, pFrom, pPrior, pSub, pTerm, v1 uintptr
	_, _, _, _, _, _, _, _ = db, pCount, pExpr, pFrom, pPrior, pSub, pTerm, v1
	if (*TSelect)(unsafe.Pointer(p)).FselFlags&uint32(SF_Aggregate) == uint32(0) {
		return 0
	} /* This is an aggregate */
	if (*TExprList)(unsafe.Pointer((*TSelect)(unsafe.Pointer(p)).FpEList)).FnExpr != int32(1) {
		return 0
	} /* Single result column */
	if (*TSelect)(unsafe.Pointer(p)).FpWhere != 0 {
		return 0
	}
	if (*TSelect)(unsafe.Pointer(p)).FpHaving != 0 {
		return 0
	}
	if (*TSelect)(unsafe.Pointer(p)).FpGroupBy != 0 {
		return 0
	}
	if (*TSelect)(unsafe.Pointer(p)).FpOrderBy != 0 {
		return 0
	}
	pExpr = (*(*TExprList_item)(unsafe.Pointer((*TSelect)(unsafe.Pointer(p)).FpEList + 8))).FpExpr
	if libc.Int32FromUint8((*TExpr)(unsafe.Pointer(pExpr)).Fop) != int32(TK_AGG_FUNCTION) {
		return 0
	} /* Result is an aggregate */
	if Xsqlite3_stricmp(tls, *(*uintptr)(unsafe.Pointer(pExpr + 8)), __ccgo_ts+17109) != 0 {
		return 0
	} /* Is count() */
	if *(*uintptr)(unsafe.Pointer(pExpr + 32)) != uintptr(0) {
		return 0
	} /* Must be count(*) */
	if (*TSrcList)(unsafe.Pointer((*TSelect)(unsafe.Pointer(p)).FpSrc)).FnSrc != int32(1) {
		return 0
	} /* One table in FROM  */
	if (*TExpr)(unsafe.Pointer(pExpr)).Fflags&libc.Uint32FromInt32(libc.Int32FromInt32(EP_WinFunc)) != uint32(0) {
		return 0
	} /* Not a window function */
	pFrom = (*TSelect)(unsafe.Pointer(p)).FpSrc + 8
	if int32(*(*uint32)(unsafe.Pointer(pFrom + 24 + 4))&0x4>>2) == 0 {
		return 0
	} /* FROM is a subquery */
	pSub = (*TSubquery)(unsafe.Pointer(*(*uintptr)(unsafe.Pointer(pFrom + 72)))).FpSelect
	if (*TSelect)(unsafe.Pointer(pSub)).FpPrior == uintptr(0) {
		return 0
	} /* Must be a compound */
	if (*TSelect)(unsafe.Pointer(pSub)).FselFlags&uint32(SF_CopyCte) != 0 {
		return 0
	} /* Not a CTE */
	for cond := true; cond; cond = pSub != 0 {
		if libc.Int32FromUint8((*TSelect)(unsafe.Pointer(pSub)).Fop) != int32(TK_ALL) && (*TSelect)(unsafe.Pointer(pSub)).FpPrior != 0 {
			return 0
		} /* Must be UNION ALL */
		if (*TSelect)(unsafe.Pointer(pSub)).FpWhere != 0 {
			return 0
		} /* No WHERE clause */
		if (*TSelect)(unsafe.Pointer(pSub)).FpLimit != 0 {
			return 0
		} /* No LIMIT clause */
		if (*TSelect)(unsafe.Pointer(pSub)).FselFlags&libc.Uint32FromInt32(libc.Int32FromInt32(SF_Aggregate)|libc.Int32FromInt32(SF_Distinct)) != 0 {
			return 0 /* Not an aggregate nor DISTINCT */
		}
		/* Due to the previous */
		pSub = (*TSelect)(unsafe.Pointer(pSub)).FpPrior /* Repeat over compound */
	}
	/* If we reach this point then it is OK to perform the transformation */
	db = (*TParse)(unsafe.Pointer(pParse)).Fdb
	pCount = pExpr
	pExpr = uintptr(0)
	pSub = _sqlite3SubqueryDetach(tls, db, pFrom)
	_sqlite3SrcListDelete(tls, db, (*TSelect)(unsafe.Pointer(p)).FpSrc)
	(*TSelect)(unsafe.Pointer(p)).FpSrc = _sqlite3DbMallocZero(tls, (*TParse)(unsafe.Pointer(pParse)).Fdb, uint64(uint64(libc.UintptrFromInt32(0)+8)+libc.Uint64FromInt64(80)))
	for pSub != 0 {
		pPrior = (*TSelect)(unsafe.Pointer(pSub)).FpPrior
		(*TSelect)(unsafe.Pointer(pSub)).FpPrior = uintptr(0)
		(*TSelect)(unsafe.Pointer(pSub)).FpNext = uintptr(0)
		**(**Tu32)(__ccgo_up(pSub + 4)) |= uint32(SF_Aggregate)
		**(**Tu32)(__ccgo_up(pSub + 4)) &= ^libc.Uint32FromInt32(SF_Compound)
		(*TSelect)(unsafe.Pointer(pSub)).FnSelectRow = 0
		_sqlite3ParserAddCleanup(tls, pParse, __ccgo_fp(_sqlite3ExprListDeleteGeneric), (*TSelect)(unsafe.Pointer(pSub)).FpEList)
		if pPrior != 0 {
			v1 = _sqlite3ExprDup(tls, db, pCount, 0)
		} else {
			v1 = pCount
		}
		pTerm = v1
		(*TSelect)(unsafe.Pointer(pSub)).FpEList = _sqlite3ExprListAppend(tls, pParse, uintptr(0), pTerm)
		pTerm = _sqlite3PExpr(tls, pParse, int32(TK_SELECT), uintptr(0), uintptr(0))
		_sqlite3PExprAddSelect(tls, pParse, pTerm, pSub)
		if pExpr == uintptr(0) {
			pExpr = pTerm
		} else {
			pExpr = _sqlite3PExpr(tls, pParse, int32(TK_PLUS), pTerm, pExpr)
		}
		pSub = pPrior
	}
	(*(*TExprList_item)(unsafe.Pointer((*TSelect)(unsafe.Pointer(p)).FpEList + 8))).FpExpr = pExpr
	**(**Tu32)(__ccgo_up(p + 4)) &= ^libc.Uint32FromInt32(SF_Aggregate)
	return int32(1)
}

// C documentation
//
//	/*
//	** Create a new collating function for database "db".  The name is zName
//	** and the encoding is enc.
//	*/
func _createCollation(tls *libc.TLS, db uintptr, zName uintptr, enc Tu8, pCtx uintptr, __ccgo_fp_xCompare uintptr, __ccgo_fp_xDel uintptr) (r int32) {
	var aColl, p, pColl uintptr
	var enc2, j int32
	_, _, _, _, _ = aColl, enc2, j, p, pColl
	/* If SQLITE_UTF16 is specified as the encoding type, transform this
	 ** to one of SQLITE_UTF16LE or SQLITE_UTF16BE using the
	 ** SQLITE_UTF16NATIVE macro. SQLITE_UTF16 is not used internally.
	 */
	enc2 = libc.Int32FromUint8(enc)
	if enc2 == int32(SQLITE_UTF16) || enc2 == int32(SQLITE_UTF16_ALIGNED) {
		enc2 = int32(SQLITE_UTF16LE)
	}
	if enc2 < int32(SQLITE_UTF8) || enc2 > int32(SQLITE_UTF16BE) {
		return _sqlite3MisuseError(tls, int32(190273))
	}
	/* Check if this call is removing or replacing an existing collation
	 ** sequence. If so, and there are active VMs, return busy. If there
	 ** are no active VMs, invalidate any pre-compiled statements.
	 */
	pColl = _sqlite3FindCollSeq(tls, db, libc.Uint8FromInt32(enc2), zName, 0)
	if pColl != 0 && (*TCollSeq)(unsafe.Pointer(pColl)).FxCmp != 0 {
		if (*Tsqlite3)(unsafe.Pointer(db)).FnVdbeActive != 0 {
			_sqlite3ErrorWithMsg(tls, db, int32(SQLITE_BUSY), __ccgo_ts+26039, 0)
			return int32(SQLITE_BUSY)
		}
		_sqlite3ExpirePreparedStatements(tls, db, 0)
		/* If collation sequence pColl was created directly by a call to
		 ** sqlite3_create_collation, and not generated by synthCollSeq(),
		 ** then any copies made by synthCollSeq() need to be invalidated.
		 ** Also, collation destructor - CollSeq.xDel() - function may need
		 ** to be called.
		 */
		if libc.Int32FromUint8((*TCollSeq)(unsafe.Pointer(pColl)).Fenc) & ^libc.Int32FromInt32(SQLITE_UTF16_ALIGNED) == enc2 {
			aColl = _sqlite3HashFind(tls, db+648, zName)
			j = 0
			for {
				if !(j < int32(3)) {
					break
				}
				p = aColl + uintptr(j)*40
				if libc.Int32FromUint8((*TCollSeq)(unsafe.Pointer(p)).Fenc) == libc.Int32FromUint8((*TCollSeq)(unsafe.Pointer(pColl)).Fenc) {
					if (*TCollSeq)(unsafe.Pointer(p)).FxDel != 0 {
						(*(*func(*libc.TLS, uintptr))(unsafe.Pointer(&struct{ uintptr }{(*TCollSeq)(unsafe.Pointer(p)).FxDel})))(tls, (*TCollSeq)(unsafe.Pointer(p)).FpUser)
					}
					(*TCollSeq)(unsafe.Pointer(p)).FxCmp = uintptr(0)
				}
				goto _1
			_1:
				;
				j = j + 1
			}
		}
	}
	pColl = _sqlite3FindCollSeq(tls, db, libc.Uint8FromInt32(enc2), zName, int32(1))
	if pColl == uintptr(0) {
		return int32(SQLITE_NOMEM)
	}
	(*TCollSeq)(unsafe.Pointer(pColl)).FxCmp = __ccgo_fp_xCompare
	(*TCollSeq)(unsafe.Pointer(pColl)).FpUser = pCtx
	(*TCollSeq)(unsafe.Pointer(pColl)).FxDel = __ccgo_fp_xDel
	(*TCollSeq)(unsafe.Pointer(pColl)).Fenc = libc.Uint8FromInt32(enc2 | libc.Int32FromUint8(enc)&libc.Int32FromInt32(SQLITE_UTF16_ALIGNED))
	_sqlite3Error(tls, db, SQLITE_OK)
	return SQLITE_OK
}

// C documentation
//
//	/*
//	** Connect to or create a dbpagevfs virtual table.
//	*/
func _dbpageConnect(tls *libc.TLS, db uintptr, pAux uintptr, argc int32, argv uintptr, ppVtab uintptr, pzErr uintptr) (r int32) {
	var pTab uintptr
	var rc int32
	_, _ = pTab, rc
	pTab = uintptr(0)
	rc = SQLITE_OK
	_ = pAux
	_ = argc
	_ = argv
	_ = pzErr
	Xsqlite3_vtab_config(tls, db, int32(SQLITE_VTAB_DIRECTONLY), 0)
	Xsqlite3_vtab_config(tls, db, int32(SQLITE_VTAB_USES_ALL_SCHEMAS), 0)
	rc = Xsqlite3_declare_vtab(tls, db, __ccgo_ts+34991)
	if rc == SQLITE_OK {
		pTab = Xsqlite3_malloc64(tls, uint64(40))
		if pTab == uintptr(0) {
			rc = int32(SQLITE_NOMEM)
		}
	}
	if rc == SQLITE_OK {
		libc.Xmemset(tls, pTab, 0, uint64(40))
		(*TDbpageTable)(unsafe.Pointer(pTab)).Fdb = db
	}
	**(**uintptr)(__ccgo_up(ppVtab)) = pTab
	return rc
}

func _dbpageUpdate(tls *libc.TLS, pVtab uintptr, argc int32, argv uintptr, pRowid uintptr) (r int32) {
	bp := tls.Alloc(32)
	defer tls.Free(32)
	var aPage, pBt, pData, pPager, pTab, zErr, zSchema uintptr
	var iDb, isInsert, rc, szPage, v1 int32
	var pgno TPgno
	var _ /* pDbPage at bp+0 */ uintptr
	_, _, _, _, _, _, _, _, _, _, _, _, _ = aPage, iDb, isInsert, pBt, pData, pPager, pTab, pgno, rc, szPage, zErr, zSchema, v1
	pTab = pVtab
	**(**uintptr)(__ccgo_up(bp)) = uintptr(0)
	rc = SQLITE_OK
	zErr = uintptr(0)
	_ = pRowid
	if (*Tsqlite3)(unsafe.Pointer((*TDbpageTable)(unsafe.Pointer(pTab)).Fdb)).Fflags&uint64(SQLITE_Defensive) != 0 {
		zErr = __ccgo_ts + 35058
		goto update_fail
	}
	if argc == int32(1) {
		zErr = __ccgo_ts + 35068
		goto update_fail
	}
	if Xsqlite3_value_type(tls, **(**uintptr)(__ccgo_up(argv))) == int32(SQLITE_NULL) {
		pgno = libc.Uint32FromInt64(Xsqlite3_value_int64(tls, **(**uintptr)(__ccgo_up(argv + 2*8))))
		isInsert = int32(1)
	} else {
		pgno = libc.Uint32FromInt64(Xsqlite3_value_int64(tls, **(**uintptr)(__ccgo_up(argv))))
		if libc.Uint32FromInt32(Xsqlite3_value_int(tls, **(**uintptr)(__ccgo_up(argv + 1*8)))) != pgno {
			zErr = __ccgo_ts + 35082
			goto update_fail
		}
		isInsert = 0
	}
	if Xsqlite3_value_type(tls, **(**uintptr)(__ccgo_up(argv + 4*8))) == int32(SQLITE_NULL) {
		iDb = 0
	} else {
		zSchema = Xsqlite3_value_text(tls, **(**uintptr)(__ccgo_up(argv + 4*8)))
		iDb = _sqlite3FindDbName(tls, (*TDbpageTable)(unsafe.Pointer(pTab)).Fdb, zSchema)
		if iDb < 0 {
			zErr = __ccgo_ts + 35096
			goto update_fail
		}
	}
	pBt = (**(**TDb)(__ccgo_up((*Tsqlite3)(unsafe.Pointer((*TDbpageTable)(unsafe.Pointer(pTab)).Fdb)).FaDb + uintptr(iDb)*32))).FpBt
	if pgno < uint32(1) || pBt == uintptr(0) {
		zErr = __ccgo_ts + 35111
		goto update_fail
	}
	szPage = _sqlite3BtreeGetPageSize(tls, pBt)
	if Xsqlite3_value_type(tls, **(**uintptr)(__ccgo_up(argv + 3*8))) != int32(SQLITE_BLOB) || Xsqlite3_value_bytes(tls, **(**uintptr)(__ccgo_up(argv + 3*8))) != szPage {
		if Xsqlite3_value_type(tls, **(**uintptr)(__ccgo_up(argv + 3*8))) == int32(SQLITE_NULL) && isInsert != 0 && pgno > uint32(1) {
			/* "INSERT INTO dbpage($PGNO,NULL)" causes page number $PGNO and
			 ** all subsequent pages to be deleted. */
			(*TDbpageTable)(unsafe.Pointer(pTab)).FiDbTrunc = iDb
			(*TDbpageTable)(unsafe.Pointer(pTab)).FpgnoTrunc = pgno - uint32(1)
			pgno = uint32(1)
		} else {
			zErr = __ccgo_ts + 35127
			goto update_fail
		}
	}
	if _dbpageBeginTrans(tls, pTab) != SQLITE_OK {
		zErr = __ccgo_ts + 35142
		goto update_fail
	}
	pPager = _sqlite3BtreePager(tls, pBt)
	rc = _sqlite3PagerGet(tls, pPager, pgno, bp, 0)
	if rc == SQLITE_OK {
		pData = Xsqlite3_value_blob(tls, **(**uintptr)(__ccgo_up(argv + 3*8)))
		v1 = _sqlite3PagerWrite(tls, **(**uintptr)(__ccgo_up(bp)))
		rc = v1
		if v1 == SQLITE_OK && pData != 0 {
			aPage = _sqlite3PagerGetData(tls, **(**uintptr)(__ccgo_up(bp)))
			libc.Xmemcpy(tls, aPage, pData, libc.Uint64FromInt32(szPage))
			(*TDbpageTable)(unsafe.Pointer(pTab)).FpgnoTrunc = uint32(0)
		}
	}
	if rc != SQLITE_OK {
		(*TDbpageTable)(unsafe.Pointer(pTab)).FpgnoTrunc = uint32(0)
	}
	_sqlite3PagerUnref(tls, **(**uintptr)(__ccgo_up(bp)))
	return rc
	goto update_fail
update_fail:
	;
	(*TDbpageTable)(unsafe.Pointer(pTab)).FpgnoTrunc = uint32(0)
	Xsqlite3_free(tls, (*Tsqlite3_vtab)(unsafe.Pointer(pVtab)).FzErrMsg)
	(*Tsqlite3_vtab)(unsafe.Pointer(pVtab)).FzErrMsg = Xsqlite3_mprintf(tls, __ccgo_ts+3933, libc.VaList(bp+16, zErr))
	return int32(SQLITE_ERROR)
}

// C documentation
//
//	/*
//	** This function is called to configure the RtreeConstraint object passed
//	** as the second argument for a MATCH constraint. The value passed as the
//	** first argument to this function is the right-hand operand to the MATCH
//	** operator.
//	*/
func _deserializeGeometry(tls *libc.TLS, pValue uintptr, pCons uintptr) (r int32) {
	var pBlob, pInfo, pSrc uintptr
	_, _, _ = pBlob, pInfo, pSrc /* Callback information */
	pSrc = Xsqlite3_value_pointer(tls, pValue, __ccgo_ts+27484)
	if pSrc == uintptr(0) {
		return int32(SQLITE_ERROR)
	}
	pInfo = Xsqlite3_malloc64(tls, uint64(112)+uint64((*TRtreeMatchArg)(unsafe.Pointer(pSrc)).FiSize))
	if !(pInfo != 0) {
		return int32(SQLITE_NOMEM)
	}
	libc.Xmemset(tls, pInfo, 0, uint64(112))
	pBlob = pInfo + 1*112
	libc.Xmemcpy(tls, pBlob, pSrc, uint64((*TRtreeMatchArg)(unsafe.Pointer(pSrc)).FiSize))
	(*Tsqlite3_rtree_query_info)(unsafe.Pointer(pInfo)).FpContext = (*TRtreeMatchArg)(unsafe.Pointer(pBlob)).Fcb.FpContext
	(*Tsqlite3_rtree_query_info)(unsafe.Pointer(pInfo)).FnParam = (*TRtreeMatchArg)(unsafe.Pointer(pBlob)).FnParam
	(*Tsqlite3_rtree_query_info)(unsafe.Pointer(pInfo)).FaParam = pBlob + 56
	(*Tsqlite3_rtree_query_info)(unsafe.Pointer(pInfo)).FapSqlParam = (*TRtreeMatchArg)(unsafe.Pointer(pBlob)).FapSqlParam
	if (*TRtreeMatchArg)(unsafe.Pointer(pBlob)).Fcb.FxGeom != 0 {
		*(*uintptr)(unsafe.Pointer(pCons + 8)) = (*TRtreeMatchArg)(unsafe.Pointer(pBlob)).Fcb.FxGeom
	} else {
		(*TRtreeConstraint)(unsafe.Pointer(pCons)).Fop = int32(RTREE_QUERY)
		*(*uintptr)(unsafe.Pointer(pCons + 8)) = (*TRtreeMatchArg)(unsafe.Pointer(pBlob)).Fcb.FxQueryFunc
	}
	(*TRtreeConstraint)(unsafe.Pointer(pCons)).FpInfo = pInfo
	return SQLITE_OK
}

// C documentation
//
//	/*
//	** Write code to erase the table with root-page iTable from database iDb.
//	** Also write code to modify the sqlite_schema table and internal schema
//	** if a root-page of another table is moved by the btree-layer whilst
//	** erasing iTable (this can happen with an auto-vacuum database).
//	*/
func _destroyRootPage(tls *libc.TLS, pParse uintptr, iTable int32, iDb int32) {
	bp := tls.Alloc(48)
	defer tls.Free(48)
	var r1 int32
	var v uintptr
	_, _ = r1, v
	v = _sqlite3GetVdbe(tls, pParse)
	r1 = _sqlite3GetTempReg(tls, pParse)
	if iTable < int32(2) {
		_sqlite3ErrorMsg(tls, pParse, __ccgo_ts+14862, 0)
	}
	_sqlite3VdbeAddOp3(tls, v, int32(OP_Destroy), iTable, r1, iDb)
	_sqlite3MayAbort(tls, pParse)
	/* OP_Destroy stores an in integer r1. If this integer
	 ** is non-zero, then it is the root page number of a table moved to
	 ** location iTable. The following code modifies the sqlite_schema table to
	 ** reflect this.
	 **
	 ** The "#NNN" in the SQL is a special constant that means whatever value
	 ** is in register NNN.  See grammar rules associated with the TK_REGISTER
	 ** token for additional information.
	 */
	_sqlite3NestedParse(tls, pParse, __ccgo_ts+14877, libc.VaList(bp+8, (**(**TDb)(__ccgo_up((*Tsqlite3)(unsafe.Pointer((*TParse)(unsafe.Pointer(pParse)).Fdb)).FaDb + uintptr(iDb)*32))).FzDbSName, iTable, r1, r1))
	_sqlite3ReleaseTempReg(tls, pParse, r1)
}

var _detach_func = TFuncDef{
	FnArg:      int16(1),
	FfuncFlags: uint32(SQLITE_UTF8),
	FzName:     __ccgo_ts + 13504,
}

func _disallowAggregatesInOrderByCb(tls *libc.TLS, pWalker uintptr, pExpr uintptr) (r int32) {
	bp := tls.Alloc(16)
	defer tls.Free(16)
	if libc.Int32FromUint8((*TExpr)(unsafe.Pointer(pExpr)).Fop) == int32(TK_AGG_FUNCTION) && (*TExpr)(unsafe.Pointer(pExpr)).FpAggInfo == uintptr(0) {
		_sqlite3ErrorMsg(tls, (*TWalker)(unsafe.Pointer(pWalker)).FpParse, __ccgo_ts+24422, libc.VaList(bp+8, *(*uintptr)(unsafe.Pointer(pExpr + 8))))
	}
	return WRC_Continue
}

// C documentation
//
//	/*
//	** Lock the file with the lock specified by parameter eFileLock - one
//	** of the following:
//	**
//	**     (1) SHARED_LOCK
//	**     (2) RESERVED_LOCK
//	**     (3) PENDING_LOCK
//	**     (4) EXCLUSIVE_LOCK
//	**
//	** Sometimes when requesting one lock state, additional lock states
//	** are inserted in between.  The locking might fail on one of the later
//	** transitions leaving the lock state different from what it started but
//	** still short of its goal.  The following chart shows the allowed
//	** transitions and the inserted intermediate states:
//	**
//	**    UNLOCKED -> SHARED
//	**    SHARED -> RESERVED
//	**    SHARED -> (PENDING) -> EXCLUSIVE
//	**    RESERVED -> (PENDING) -> EXCLUSIVE
//	**    PENDING -> EXCLUSIVE
//	**
//	** This routine will only increase a lock.  Use the sqlite3OsUnlock()
//	** routine to lower a locking level.
//	**
//	** With dotfile locking, we really only support state (4): EXCLUSIVE.
//	** But we track the other locking levels internally.
//	*/
func _dotlockLock(tls *libc.TLS, id uintptr, eFileLock int32) (r int32) {
	var pFile, zLockFile uintptr
	var rc, tErrno int32
	_, _, _, _ = pFile, rc, tErrno, zLockFile
	pFile = id
	zLockFile = (*TunixFile)(unsafe.Pointer(pFile)).FlockingContext
	rc = SQLITE_OK
	/* If we have any lock, then the lock file already exists.  All we have
	 ** to do is adjust our internal record of the lock level.
	 */
	if libc.Int32FromUint8((*TunixFile)(unsafe.Pointer(pFile)).FeFileLock) > NO_LOCK {
		(*TunixFile)(unsafe.Pointer(pFile)).FeFileLock = libc.Uint8FromInt32(eFileLock)
		/* Always update the timestamp on the old file */
		libc.Xutimes(tls, zLockFile, libc.UintptrFromInt32(0))
		return SQLITE_OK
	}
	/* grab an exclusive lock */
	rc = (*(*func(*libc.TLS, uintptr, Tmode_t) int32)(unsafe.Pointer(&struct{ uintptr }{_aSyscall[int32(18)].FpCurrent})))(tls, zLockFile, uint32(0777))
	if rc < 0 {
		/* failed to open/create the lock directory */
		tErrno = **(**int32)(__ccgo_up(libc.X__errno(tls)))
		if int32(EEXIST) == tErrno {
			rc = int32(SQLITE_BUSY)
		} else {
			rc = _sqliteErrorFromPosixError(tls, tErrno, libc.Int32FromInt32(SQLITE_IOERR)|libc.Int32FromInt32(15)<<libc.Int32FromInt32(8))
			if rc != int32(SQLITE_BUSY) {
				_storeLastErrno(tls, pFile, tErrno)
			}
		}
		return rc
	}
	/* got it, set the type and return ok */
	(*TunixFile)(unsafe.Pointer(pFile)).FeFileLock = libc.Uint8FromInt32(eFileLock)
	return rc
}

// C documentation
//
//	/*
//	** The implementation of internal UDF sqlite_drop_column().
//	**
//	** Arguments:
//	**
//	**  argv[0]: An integer - the index of the schema containing the table
//	**  argv[1]: CREATE TABLE statement to modify.
//	**  argv[2]: An integer - the index of the column to remove.
//	**
//	** The value returned is a string containing the CREATE TABLE statement
//	** with column argv[2] removed.
//	*/
func _dropColumnFunc(tls *libc.TLS, context uintptr, NotUsed int32, argv uintptr) {
	bp := tls.Alloc(464)
	defer tls.Free(464)
	var db, pCol, pEnd, pTab, zDb, zEnd, zNew, zSql uintptr
	var iCol, iSchema, rc int32
	var xAuth Tsqlite3_xauth
	var _ /* eTok at bp+424 */ int32
	var _ /* sParse at bp+0 */ TParse
	_, _, _, _, _, _, _, _, _, _, _, _ = db, iCol, iSchema, pCol, pEnd, pTab, rc, xAuth, zDb, zEnd, zNew, zSql
	db = Xsqlite3_context_db_handle(tls, context)
	iSchema = Xsqlite3_value_int(tls, **(**uintptr)(__ccgo_up(argv)))
	zSql = Xsqlite3_value_text(tls, **(**uintptr)(__ccgo_up(argv + 1*8)))
	iCol = Xsqlite3_value_int(tls, **(**uintptr)(__ccgo_up(argv + 2*8)))
	zDb = (**(**TDb)(__ccgo_up((*Tsqlite3)(unsafe.Pointer(db)).FaDb + uintptr(iSchema)*32))).FzDbSName
	zNew = uintptr(0)
	xAuth = (*Tsqlite3)(unsafe.Pointer(db)).FxAuth
	(*Tsqlite3)(unsafe.Pointer(db)).FxAuth = uintptr(0)
	_ = NotUsed
	rc = _renameParseSql(tls, bp, zDb, db, zSql, libc.BoolInt32(iSchema == int32(1)))
	if rc != SQLITE_OK {
		goto drop_column_done
	}
	pTab = (**(**TParse)(__ccgo_up(bp))).FpNewTable
	if pTab == uintptr(0) || int32((*TTable)(unsafe.Pointer(pTab)).FnCol) == int32(1) || iCol >= int32((*TTable)(unsafe.Pointer(pTab)).FnCol) {
		/* This can happen if the sqlite_schema table is corrupt */
		rc = _sqlite3CorruptError(tls, int32(122753))
		goto drop_column_done
	}
	if iCol < int32((*TTable)(unsafe.Pointer(pTab)).FnCol)-int32(1) {
		pCol = _renameTokenFind(tls, bp, uintptr(0), (**(**TColumn)(__ccgo_up((*TTable)(unsafe.Pointer(pTab)).FaCol + uintptr(iCol)*16))).FzCnName)
		pEnd = _renameTokenFind(tls, bp, uintptr(0), (**(**TColumn)(__ccgo_up((*TTable)(unsafe.Pointer(pTab)).FaCol + uintptr(iCol+int32(1))*16))).FzCnName)
		zEnd = (*TRenameToken)(unsafe.Pointer(pEnd)).Ft.Fz
	} else {
		/* Point pCol->t.z at the "," immediately preceding the definition of
		 ** the column being dropped. To do this, start at the name of the
		 ** previous column, and tokenize until the next ",".  */
		pCol = _renameTokenFind(tls, bp, uintptr(0), (**(**TColumn)(__ccgo_up((*TTable)(unsafe.Pointer(pTab)).FaCol + uintptr(iCol-int32(1))*16))).FzCnName)
		for cond := true; cond; cond = **(**int32)(__ccgo_up(bp + 424)) != int32(TK_COMMA) {
			(*TRenameToken)(unsafe.Pointer(pCol)).Ft.Fz += uintptr(_getConstraintToken(tls, (*TRenameToken)(unsafe.Pointer(pCol)).Ft.Fz, bp+424))
		}
		(*TRenameToken)(unsafe.Pointer(pCol)).Ft.Fz = (*TRenameToken)(unsafe.Pointer(pCol)).Ft.Fz - 1
		zEnd = zSql + uintptr((*(*struct {
			FaddColOffset int32
			FpFKey        uintptr
			FpDfltList    uintptr
		})(unsafe.Pointer(pTab + 64))).FaddColOffset)
	}
	zNew = _sqlite3MPrintf(tls, db, __ccgo_ts+11578, libc.VaList(bp+440, int64((*TRenameToken)(unsafe.Pointer(pCol)).Ft.Fz)-int64(zSql), zSql, zEnd))
	Xsqlite3_result_text(tls, context, zNew, -int32(1), uintptr(-libc.Int32FromInt32(1)))
	Xsqlite3_free(tls, zNew)
	goto drop_column_done
drop_column_done:
	;
	_renameParseCleanup(tls, bp)
	(*Tsqlite3)(unsafe.Pointer(db)).FxAuth = xAuth
	if rc != SQLITE_OK {
		Xsqlite3_result_error_code(tls, context, rc)
	}
}

// C documentation
//
//	/*
//	** Internal SQL function sqlite3_drop_constraint():  Given an input
//	** CREATE TABLE statement, return a revised CREATE TABLE statement
//	** with a constraint removed.  Two forms, depending on the datatype
//	** of argv[2]:
//	**
//	**   sqlite_drop_constraint(SQL, INT)  -- Omit NOT NULL from the INT-th column
//	**   sqlite_drop_constraint(SQL, TEXT) -- OMIT constraint with name TEXT
//	**
//	** In the first case, the left-most column is 0.
//	*/
func _dropConstraintFunc(tls *libc.TLS, ctx uintptr, NotUsed int32, argv uintptr) {
	bp := tls.Alloc(64)
	defer tls.Free(64)
	var db, zCons, zNew, zSpace, zSql uintptr
	var iEnd, iNotNull, iStart, ii, nTok int32
	var _ /* cmp at bp+8 */ int32
	var _ /* iOff at bp+0 */ int32
	var _ /* t at bp+4 */ int32
	_, _, _, _, _, _, _, _, _, _ = db, iEnd, iNotNull, iStart, ii, nTok, zCons, zNew, zSpace, zSql
	zSql = Xsqlite3_value_text(tls, **(**uintptr)(__ccgo_up(argv)))
	zCons = uintptr(0)
	iNotNull = -int32(1)
	**(**int32)(__ccgo_up(bp)) = 0
	iStart = 0
	iEnd = 0
	zNew = uintptr(0)
	**(**int32)(__ccgo_up(bp + 4)) = 0
	_ = NotUsed
	if zSql == uintptr(0) {
		return
	}
	/* Jump past the "CREATE TABLE" bit. */
	if _skipCreateTable(tls, ctx, zSql, bp) != 0 {
		return
	}
	if Xsqlite3_value_type(tls, **(**uintptr)(__ccgo_up(argv + 1*8))) == int32(SQLITE_INTEGER) {
		iNotNull = Xsqlite3_value_int(tls, **(**uintptr)(__ccgo_up(argv + 1*8)))
	} else {
		zCons = Xsqlite3_value_text(tls, **(**uintptr)(__ccgo_up(argv + 1*8)))
	}
	/* Search for the named constraint within column definitions. */
	ii = 0
	for {
		if !(iEnd == 0) {
			break
		}
		/* Now parse the column or table constraint definition. Search
		 ** for the token CONSTRAINT if this is a DROP CONSTRAINT command, or
		 ** NOT in the right column if this is a DROP NOT NULL. */
		for int32(1) != 0 {
			iStart = **(**int32)(__ccgo_up(bp))
			**(**int32)(__ccgo_up(bp)) = **(**int32)(__ccgo_up(bp)) + _getConstraintToken(tls, zSql+uintptr(**(**int32)(__ccgo_up(bp))), bp+4)
			if **(**int32)(__ccgo_up(bp + 4)) == int32(TK_CONSTRAINT) && (zCons != 0 || iNotNull == ii) {
				/* Check if this is the constraint we are searching for. */
				nTok = 0
				**(**int32)(__ccgo_up(bp + 8)) = int32(1)
				/* Skip past any whitespace. */
				**(**int32)(__ccgo_up(bp)) = **(**int32)(__ccgo_up(bp)) + _getWhitespace(tls, zSql+uintptr(**(**int32)(__ccgo_up(bp))))
				/* Compare the next token - which may be quoted - with the name of
				 ** the constraint being dropped.  */
				nTok = _getConstraintToken(tls, zSql+uintptr(**(**int32)(__ccgo_up(bp))), bp+4)
				if zCons != 0 {
					if _quotedCompare(tls, ctx, **(**int32)(__ccgo_up(bp + 4)), zSql+uintptr(**(**int32)(__ccgo_up(bp))), nTok, zCons, bp+8) != 0 {
						return
					}
				}
				**(**int32)(__ccgo_up(bp)) = **(**int32)(__ccgo_up(bp)) + nTok
				/* The next token is usually the first token of the constraint
				 ** definition. This is enough to tell the type of the constraint -
				 ** TK_NOT means it is a NOT NULL, TK_CHECK a CHECK constraint etc.
				 **
				 ** There is also the chance that the next token is TK_CONSTRAINT
				 ** (or TK_DEFAULT or TK_COLLATE), for example if a table has been
				 ** created as follows:
				 **
				 **    CREATE TABLE t1(cols, CONSTRAINT one CONSTRAINT two NOT NULL);
				 **
				 ** In this case, allow the "CONSTRAINT one" bit to be dropped by
				 ** this command if that is what is requested, or to advance to
				 ** the next iteration of the loop with &zSql[iOff] still pointing
				 ** to the CONSTRAINT keyword.  */
				nTok = _getConstraintToken(tls, zSql+uintptr(**(**int32)(__ccgo_up(bp))), bp+4)
				if **(**int32)(__ccgo_up(bp + 4)) == int32(TK_CONSTRAINT) || **(**int32)(__ccgo_up(bp + 4)) == int32(TK_DEFAULT) || **(**int32)(__ccgo_up(bp + 4)) == int32(TK_COLLATE) || **(**int32)(__ccgo_up(bp + 4)) == int32(TK_COMMA) || **(**int32)(__ccgo_up(bp + 4)) == int32(TK_RP) || **(**int32)(__ccgo_up(bp + 4)) == int32(TK_GENERATED) || **(**int32)(__ccgo_up(bp + 4)) == int32(TK_AS) {
					**(**int32)(__ccgo_up(bp + 4)) = int32(TK_CHECK)
				} else {
					**(**int32)(__ccgo_up(bp)) = **(**int32)(__ccgo_up(bp)) + nTok
					**(**int32)(__ccgo_up(bp)) = **(**int32)(__ccgo_up(bp)) + _getConstraint(tls, zSql+uintptr(**(**int32)(__ccgo_up(bp))))
				}
				if **(**int32)(__ccgo_up(bp + 8)) == 0 || iNotNull >= 0 && **(**int32)(__ccgo_up(bp + 4)) == int32(TK_NOT) {
					if **(**int32)(__ccgo_up(bp + 4)) != int32(TK_NOT) && **(**int32)(__ccgo_up(bp + 4)) != int32(TK_CHECK) {
						_errorMPrintf(tls, ctx, __ccgo_ts+11812, libc.VaList(bp+24, zCons))
						return
					}
					iEnd = **(**int32)(__ccgo_up(bp))
					break
				}
			} else {
				if **(**int32)(__ccgo_up(bp + 4)) == int32(TK_NOT) && iNotNull == ii {
					iEnd = **(**int32)(__ccgo_up(bp)) + _getConstraint(tls, zSql+uintptr(**(**int32)(__ccgo_up(bp))))
					break
				} else {
					if **(**int32)(__ccgo_up(bp + 4)) == int32(TK_RP) || **(**int32)(__ccgo_up(bp + 4)) == int32(TK_ILLEGAL) {
						iEnd = -int32(1)
						break
					} else {
						if **(**int32)(__ccgo_up(bp + 4)) == int32(TK_COMMA) {
							break
						}
					}
				}
			}
		}
		goto _1
	_1:
		;
		ii = ii + 1
	}
	/* If the constraint has not been found it is an error. */
	if iEnd <= 0 {
		if zCons != 0 {
			_errorMPrintf(tls, ctx, __ccgo_ts+11846, libc.VaList(bp+24, zCons))
		} else {
			/* SQLite follows postgres in that a DROP NOT NULL on a column that is
			 ** not NOT NULL is not an error. So just return the original SQL here. */
			Xsqlite3_result_text(tls, ctx, zSql, -int32(1), uintptr(-libc.Int32FromInt32(1)))
		}
	} else {
		/* Figure out if an extra space should be inserted after the constraint
		 ** is removed. And if an additional comma preceding the constraint
		 ** should be removed. */
		zSpace = __ccgo_ts + 11534
		iEnd = iEnd + _getWhitespace(tls, zSql+uintptr(iEnd))
		_sqlite3GetToken(tls, zSql+uintptr(iEnd), bp+4)
		if **(**int32)(__ccgo_up(bp + 4)) == int32(TK_RP) || **(**int32)(__ccgo_up(bp + 4)) == int32(TK_COMMA) {
			zSpace = __ccgo_ts + 1693
			if libc.Int32FromUint8(**(**Tu8)(__ccgo_up(zSql + uintptr(iStart-int32(1))))) == int32(',') {
				iStart = iStart - 1
			}
		}
		db = Xsqlite3_context_db_handle(tls, ctx)
		zNew = _sqlite3MPrintf(tls, db, __ccgo_ts+11869, libc.VaList(bp+24, iStart, zSql, zSpace, zSql+uintptr(iEnd)))
		Xsqlite3_result_text(tls, ctx, zNew, -int32(1), __ccgo_fp(_sqlite3RowSetClear))
	}
}

var _encnames = [4]uintptr{
	0: __ccgo_ts + 5252,
	1: __ccgo_ts + 5254,
	2: __ccgo_ts + 5256,
	3: __ccgo_ts + 5261,
}

var _encnames1 = [9]struct {
	FzName uintptr
	Fenc   Tu8
}{
	0: {
		FzName: __ccgo_ts + 19785,
		Fenc:   uint8(SQLITE_UTF8),
	},
	1: {
		FzName: __ccgo_ts + 19790,
		Fenc:   uint8(SQLITE_UTF8),
	},
	2: {
		FzName: __ccgo_ts + 19796,
		Fenc:   uint8(SQLITE_UTF16LE),
	},
	3: {
		FzName: __ccgo_ts + 19805,
		Fenc:   uint8(SQLITE_UTF16BE),
	},
	4: {
		FzName: __ccgo_ts + 19814,
		Fenc:   uint8(SQLITE_UTF16LE),
	},
	5: {
		FzName: __ccgo_ts + 19822,
		Fenc:   uint8(SQLITE_UTF16BE),
	},
	6: {
		FzName: __ccgo_ts + 19830,
	},
	7: {
		FzName: __ccgo_ts + 19837,
	},
	8: {},
}

// C documentation
//
//	/*
//	** Implementation of the sqlite_log() function.  This is a wrapper around
//	** sqlite3_log().  The return value is NULL.  The function exists purely for
//	** its side-effects.
//	*/
func _errlogFunc(tls *libc.TLS, context uintptr, argc int32, argv uintptr) {
	bp := tls.Alloc(16)
	defer tls.Free(16)
	_ = argc
	_ = context
	Xsqlite3_log(tls, Xsqlite3_value_int(tls, **(**uintptr)(__ccgo_up(argv))), __ccgo_ts+3933, libc.VaList(bp+8, Xsqlite3_value_text(tls, **(**uintptr)(__ccgo_up(argv + 1*8)))))
}

// C documentation
//
//	/*
//	** Execute zSql on database db.
//	**
//	** If zSql returns rows, then each row will have exactly one
//	** column.  (This will only happen if zSql begins with "SELECT".)
//	** Take each row of result and call execSql() again recursively.
//	**
//	** The execSqlF() routine does the same thing, except it accepts
//	** a format string as its third argument
//	*/
func _execSql(tls *libc.TLS, db uintptr, pzErrMsg uintptr, zSql uintptr) (r int32) {
	bp := tls.Alloc(16)
	defer tls.Free(16)
	var rc, v1 int32
	var zSubSql uintptr
	var _ /* pStmt at bp+0 */ uintptr
	_, _, _ = rc, zSubSql, v1
	/* printf("SQL: [%s]\n", zSql); fflush(stdout); */
	rc = Xsqlite3_prepare_v2(tls, db, zSql, -int32(1), bp, uintptr(0))
	if rc != SQLITE_OK {
		return rc
	}
	for {
		v1 = Xsqlite3_step(tls, **(**uintptr)(__ccgo_up(bp)))
		rc = v1
		if !(int32(SQLITE_ROW) == v1) {
			break
		}
		zSubSql = Xsqlite3_column_text(tls, **(**uintptr)(__ccgo_up(bp)), 0)
		/* The secondary SQL must be one of CREATE TABLE, CREATE INDEX,
		 ** or INSERT.  Historically there have been attacks that first
		 ** corrupt the sqlite_schema.sql field with other kinds of statements
		 ** then run VACUUM to get those statements to execute at inappropriate
		 ** times. */
		if zSubSql != 0 && (libc.Xstrncmp(tls, zSubSql, __ccgo_ts+22722, uint64(3)) == 0 || libc.Xstrncmp(tls, zSubSql, __ccgo_ts+22726, uint64(3)) == 0) {
			rc = _execSql(tls, db, pzErrMsg, zSubSql)
			if rc != SQLITE_OK {
				break
			}
		}
	}
	if rc == int32(SQLITE_DONE) {
		rc = SQLITE_OK
	}
	if rc != 0 {
		_sqlite3SetString(tls, pzErrMsg, db, Xsqlite3_errmsg(tls, db))
	}
	Xsqlite3_finalize(tls, **(**uintptr)(__ccgo_up(bp)))
	return rc
}

// C documentation
//
//	/*
//	** This routine is a helper for explainIndexRange() below
//	**
//	** pStr holds the text of an expression that we are building up one term
//	** at a time.  This routine adds a new term to the end of the expression.
//	** Terms are separated by AND so add the "AND" text for second and subsequent
//	** terms only.
//	*/
func _explainAppendTerm(tls *libc.TLS, pStr uintptr, pIdx uintptr, nTerm int32, iTerm int32, bAnd int32, zOp uintptr) {
	var i int32
	_ = i
	if bAnd != 0 {
		Xsqlite3_str_append(tls, pStr, __ccgo_ts+23618, int32(5))
	}
	if nTerm > int32(1) {
		Xsqlite3_str_append(tls, pStr, __ccgo_ts+23624, int32(1))
	}
	i = 0
	for {
		if !(i < nTerm) {
			break
		}
		if i != 0 {
			Xsqlite3_str_append(tls, pStr, __ccgo_ts+14339, int32(1))
		}
		Xsqlite3_str_appendall(tls, pStr, _explainIndexColumnName(tls, pIdx, iTerm+i))
		goto _1
	_1:
		;
		i = i + 1
	}
	if nTerm > int32(1) {
		Xsqlite3_str_append(tls, pStr, __ccgo_ts+5250, int32(1))
	}
	Xsqlite3_str_append(tls, pStr, zOp, int32(1))
	if nTerm > int32(1) {
		Xsqlite3_str_append(tls, pStr, __ccgo_ts+23624, int32(1))
	}
	i = 0
	for {
		if !(i < nTerm) {
			break
		}
		if i != 0 {
			Xsqlite3_str_append(tls, pStr, __ccgo_ts+14339, int32(1))
		}
		Xsqlite3_str_append(tls, pStr, __ccgo_ts+5252, int32(1))
		goto _2
	_2:
		;
		i = i + 1
	}
	if nTerm > int32(1) {
		Xsqlite3_str_append(tls, pStr, __ccgo_ts+5250, int32(1))
	}
}

// C documentation
//
//	/*
//	** Return the name of the i-th column of the pIdx index.
//	*/
func _explainIndexColumnName(tls *libc.TLS, pIdx uintptr, i int32) (r uintptr) {
	i = int32(**(**Ti16)(__ccgo_up((*TIndex)(unsafe.Pointer(pIdx)).FaiColumn + uintptr(i)*2)))
	if i == -int32(2) {
		return __ccgo_ts + 23611
	}
	if i == -int32(1) {
		return __ccgo_ts + 17956
	}
	return (**(**TColumn)(__ccgo_up((*TTable)(unsafe.Pointer((*TIndex)(unsafe.Pointer(pIdx)).FpTable)).FaCol + uintptr(i)*16))).FzCnName
}

// C documentation
//
//	/*
//	** Argument pLevel describes a strategy for scanning table pTab. This
//	** function appends text to pStr that describes the subset of table
//	** rows scanned by the strategy in the form of an SQL expression.
//	**
//	** For example, if the query:
//	**
//	**   SELECT * FROM t1 WHERE a=1 AND b>2;
//	**
//	** is run and there is an index on (a, b), then this function returns a
//	** string similar to:
//	**
//	**   "a=? AND b>?"
//	*/
func _explainIndexRange(tls *libc.TLS, pStr uintptr, pLoop uintptr) {
	bp := tls.Alloc(16)
	defer tls.Free(16)
	var i, j int32
	var nEq, nSkip Tu16
	var pIndex, z, v2 uintptr
	_, _, _, _, _, _, _ = i, j, nEq, nSkip, pIndex, z, v2
	pIndex = (*(*struct {
		FnEq          Tu16
		FnBtm         Tu16
		FnTop         Tu16
		FnDistinctCol Tu16
		FpIndex       uintptr
		FpOrderBy     uintptr
	})(unsafe.Pointer(pLoop + 24))).FpIndex
	nEq = (*(*struct {
		FnEq          Tu16
		FnBtm         Tu16
		FnTop         Tu16
		FnDistinctCol Tu16
		FpIndex       uintptr
		FpOrderBy     uintptr
	})(unsafe.Pointer(pLoop + 24))).FnEq
	nSkip = (*TWhereLoop)(unsafe.Pointer(pLoop)).FnSkip
	if libc.Int32FromUint16(nEq) == 0 && (*TWhereLoop)(unsafe.Pointer(pLoop)).FwsFlags&libc.Uint32FromInt32(libc.Int32FromInt32(WHERE_BTM_LIMIT)|libc.Int32FromInt32(WHERE_TOP_LIMIT)) == uint32(0) {
		return
	}
	Xsqlite3_str_append(tls, pStr, __ccgo_ts+23626, int32(2))
	i = 0
	for {
		if !(i < libc.Int32FromUint16(nEq)) {
			break
		}
		z = _explainIndexColumnName(tls, pIndex, i)
		if i != 0 {
			Xsqlite3_str_append(tls, pStr, __ccgo_ts+23618, int32(5))
		}
		if i >= libc.Int32FromUint16(nSkip) {
			v2 = __ccgo_ts + 23629
		} else {
			v2 = __ccgo_ts + 23634
		}
		Xsqlite3_str_appendf(tls, pStr, v2, libc.VaList(bp+8, z))
		goto _1
	_1:
		;
		i = i + 1
	}
	j = i
	if (*TWhereLoop)(unsafe.Pointer(pLoop)).FwsFlags&uint32(WHERE_BTM_LIMIT) != 0 {
		_explainAppendTerm(tls, pStr, pIndex, libc.Int32FromUint16((*(*struct {
			FnEq          Tu16
			FnBtm         Tu16
			FnTop         Tu16
			FnDistinctCol Tu16
			FpIndex       uintptr
			FpOrderBy     uintptr
		})(unsafe.Pointer(pLoop + 24))).FnBtm), j, i, __ccgo_ts+23642)
		i = int32(1)
	}
	if (*TWhereLoop)(unsafe.Pointer(pLoop)).FwsFlags&uint32(WHERE_TOP_LIMIT) != 0 {
		_explainAppendTerm(tls, pStr, pIndex, libc.Int32FromUint16((*(*struct {
			FnEq          Tu16
			FnBtm         Tu16
			FnTop         Tu16
			FnDistinctCol Tu16
			FpIndex       uintptr
			FpOrderBy     uintptr
		})(unsafe.Pointer(pLoop + 24))).FnTop), j, i, __ccgo_ts+23644)
	}
	Xsqlite3_str_append(tls, pStr, __ccgo_ts+5250, int32(1))
}

// C documentation
//
//	/*
//	** Add a single OP_Explain instruction to the VDBE to explain a simple
//	** count(*) query ("SELECT count(*) FROM pTab").
//	*/
func _explainSimpleCount(tls *libc.TLS, pParse uintptr, pTab uintptr, pIdx uintptr) {
	bp := tls.Alloc(32)
	defer tls.Free(32)
	var bCover int32
	var v1, v2 uintptr
	_, _, _ = bCover, v1, v2
	if libc.Int32FromUint8((*TParse)(unsafe.Pointer(pParse)).Fexplain) == int32(2) {
		bCover = libc.BoolInt32(pIdx != uintptr(0) && ((*TTable)(unsafe.Pointer(pTab)).FtabFlags&uint32(TF_WithoutRowid) == uint32(0) || !(int32(uint32(*(*uint16)(unsafe.Pointer(pIdx + 100))&0x3>>0)) == libc.Int32FromInt32(SQLITE_IDXTYPE_PRIMARYKEY))))
		if bCover != 0 {
			v1 = __ccgo_ts + 21518
		} else {
			v1 = __ccgo_ts + 1693
		}
		if bCover != 0 {
			v2 = (*TIndex)(unsafe.Pointer(pIdx)).FzName
		} else {
			v2 = __ccgo_ts + 1693
		}
		_sqlite3VdbeExplain(tls, pParse, uint8(0), __ccgo_ts+21541, libc.VaList(bp+8, (*TTable)(unsafe.Pointer(pTab)).FzName, v1, v2))
	}
}

// C documentation
//
//	/*
//	** Unless an "EXPLAIN QUERY PLAN" command is being processed, this function
//	** is a no-op. Otherwise, it adds a single row of output to the EQP result,
//	** where the caption is of the form:
//	**
//	**   "USE TEMP B-TREE FOR xxx"
//	**
//	** where xxx is one of "DISTINCT", "ORDER BY" or "GROUP BY". Exactly which
//	** is determined by the zUsage argument.
//	*/
func _explainTempTable(tls *libc.TLS, pParse uintptr, zUsage uintptr) {
	bp := tls.Alloc(16)
	defer tls.Free(16)
	_sqlite3VdbeExplain(tls, pParse, uint8(0), __ccgo_ts+20511, libc.VaList(bp+8, zUsage))
}

/*
** Assign expression b to lvalue a. A second, no-op, version of this macro
** is provided when SQLITE_OMIT_EXPLAIN is defined. This allows the code
** in sqlite3Select() to assign values to structure member variables that
** only exist if SQLITE_OMIT_EXPLAIN is not defined without polluting the
** code with #ifndef directives.
 */

// C documentation
//
//	/*
//	** This function is called to handle the SQLITE_FCNTL_SIZE_HINT
//	** file-control operation.  Enlarge the database to nBytes in size
//	** (rounded up to the next chunk-size).  If the database is already
//	** nBytes or larger, this routine is a no-op.
//	*/
func _fcntlSizeHint(tls *libc.TLS, pFile uintptr, nByte Ti64) (r int32) {
	bp := tls.Alloc(128)
	defer tls.Free(128)
	var iWrite, nSize Ti64
	var nBlk, nWrite int32
	var _ /* buf at bp+0 */ Tstat
	_, _, _, _ = iWrite, nBlk, nSize, nWrite
	if (*TunixFile)(unsafe.Pointer(pFile)).FszChunk > 0 { /* Used to hold return values of fstat() */
		if (*(*func(*libc.TLS, int32, uintptr) int32)(unsafe.Pointer(&struct{ uintptr }{_aSyscall[int32(5)].FpCurrent})))(tls, (*TunixFile)(unsafe.Pointer(pFile)).Fh, bp) != 0 {
			return libc.Int32FromInt32(SQLITE_IOERR) | libc.Int32FromInt32(7)<<libc.Int32FromInt32(8)
		}
		nSize = (nByte + int64((*TunixFile)(unsafe.Pointer(pFile)).FszChunk) - int64(1)) / int64((*TunixFile)(unsafe.Pointer(pFile)).FszChunk) * int64((*TunixFile)(unsafe.Pointer(pFile)).FszChunk)
		if nSize > (**(**Tstat)(__ccgo_up(bp))).Fst_size {
			/* If the OS does not have posix_fallocate(), fake it. Write a
			 ** single byte to the last byte in each block that falls entirely
			 ** within the extended region. Then, if required, a single byte
			 ** at offset (nSize-1), to set the size of the file correctly.
			 ** This is a similar technique to that used by glibc on systems
			 ** that do not have a real fallocate() call.
			 */
			nBlk = (**(**Tstat)(__ccgo_up(bp))).Fst_blksize /* File-system block size */
			nWrite = 0                                      /* Next offset to write to */
			iWrite = (**(**Tstat)(__ccgo_up(bp))).Fst_size/int64(nBlk)*int64(nBlk) + int64(nBlk) - int64(1)
			for {
				if !(iWrite < nSize+int64(nBlk)-int64(1)) {
					break
				}
				if iWrite >= nSize {
					iWrite = nSize - int64(1)
				}
				nWrite = _seekAndWrite(tls, pFile, iWrite, __ccgo_ts+1693, int32(1))
				if nWrite != int32(1) {
					return libc.Int32FromInt32(SQLITE_IOERR) | libc.Int32FromInt32(3)<<libc.Int32FromInt32(8)
				}
				goto _1
			_1:
				;
				iWrite = iWrite + int64(nBlk)
			}
		}
	}
	return SQLITE_OK
}

// C documentation
//
//	/*
//	** Return TRUE if pFile has been renamed or unlinked since it was first opened.
//	*/
func _fileHasMoved(tls *libc.TLS, pFile uintptr) (r int32) {
	bp := tls.Alloc(128)
	defer tls.Free(128)
	var _ /* buf at bp+0 */ Tstat
	return libc.BoolInt32((*TunixFile)(unsafe.Pointer(pFile)).FpInode != uintptr(0) && ((*(*func(*libc.TLS, uintptr, uintptr) int32)(unsafe.Pointer(&struct{ uintptr }{_aSyscall[int32(4)].FpCurrent})))(tls, (*TunixFile)(unsafe.Pointer(pFile)).FzPath, bp) != 0 || (**(**Tstat)(__ccgo_up(bp))).Fst_ino != (*TunixInodeInfo)(unsafe.Pointer((*TunixFile)(unsafe.Pointer(pFile)).FpInode)).FfileId.Fino))
}

// C documentation
//
//	/*
//	** Initialize the contents of the unixFile structure pointed to by pId.
//	*/
func _fillInUnixFile(tls *libc.TLS, pVfs uintptr, h int32, pId uintptr, zFilename uintptr, ctrlFlags int32) (r int32) {
	bp := tls.Alloc(16)
	defer tls.Free(16)
	var nFilename, rc int32
	var pLockingStyle, pNew, zLockFile, v1, v2 uintptr
	_, _, _, _, _, _, _ = nFilename, pLockingStyle, pNew, rc, zLockFile, v1, v2
	pNew = pId
	rc = SQLITE_OK
	/* No locking occurs in temporary files */
	(*TunixFile)(unsafe.Pointer(pNew)).Fh = h
	(*TunixFile)(unsafe.Pointer(pNew)).FpVfs = pVfs
	(*TunixFile)(unsafe.Pointer(pNew)).FzPath = zFilename
	(*TunixFile)(unsafe.Pointer(pNew)).FctrlFlags = uint16(libc.Uint8FromInt32(ctrlFlags))
	if ctrlFlags&int32(UNIXFILE_URI) != 0 {
		v1 = zFilename
	} else {
		v1 = uintptr(0)
	}
	if Xsqlite3_uri_boolean(tls, v1, __ccgo_ts+3967, int32(SQLITE_POWERSAFE_OVERWRITE)) != 0 {
		v2 = pNew + 30
		*(*uint16)(unsafe.Pointer(v2)) = uint16(int32(*(*uint16)(unsafe.Pointer(v2))) | libc.Int32FromInt32(UNIXFILE_PSOW))
	}
	if libc.Xstrcmp(tls, (*Tsqlite3_vfs)(unsafe.Pointer(pVfs)).FzName, __ccgo_ts+3972) == 0 {
		v1 = pNew + 30
		*(*uint16)(unsafe.Pointer(v1)) = uint16(int32(*(*uint16)(unsafe.Pointer(v1))) | libc.Int32FromInt32(UNIXFILE_EXCL))
	}
	if ctrlFlags&int32(UNIXFILE_NOLOCK) != 0 {
		pLockingStyle = uintptr(unsafe.Pointer(&_nolockIoMethods))
	} else {
		pLockingStyle = (*(*func(*libc.TLS, uintptr, uintptr) uintptr)(unsafe.Pointer(&struct{ uintptr }{*(*uintptr)(unsafe.Pointer((*Tsqlite3_vfs)(unsafe.Pointer(pVfs)).FpAppData))})))(tls, zFilename, pNew)
	}
	if pLockingStyle == uintptr(unsafe.Pointer(&_posixIoMethods)) {
		_unixEnterMutex(tls)
		rc = _findInodeInfo(tls, pNew, pNew+16)
		if rc != SQLITE_OK {
			/* If an error occurred in findInodeInfo(), close the file descriptor
			 ** immediately, before releasing the mutex. findInodeInfo() may fail
			 ** in two scenarios:
			 **
			 **   (a) A call to fstat() failed.
			 **   (b) A malloc failed.
			 **
			 ** Scenario (b) may only occur if the process is holding no other
			 ** file descriptors open on the same file. If there were other file
			 ** descriptors on this file, then no malloc would be required by
			 ** findInodeInfo(). If this is the case, it is quite safe to close
			 ** handle h - as it is guaranteed that no posix locks will be released
			 ** by doing so.
			 **
			 ** If scenario (a) caused the error then things are not so safe. The
			 ** implicit assumption here is that if fstat() fails, things are in
			 ** such bad shape that dropping a lock or two doesn't matter much.
			 */
			_robust_close(tls, pNew, h, int32(46355))
			h = -int32(1)
		}
		_unixLeaveMutex(tls)
	} else {
		if pLockingStyle == uintptr(unsafe.Pointer(&_dotlockIoMethods)) {
			nFilename = libc.Int32FromUint64(libc.Xstrlen(tls, zFilename)) + int32(6)
			zLockFile = Xsqlite3_malloc64(tls, libc.Uint64FromInt32(nFilename))
			if zLockFile == uintptr(0) {
				rc = int32(SQLITE_NOMEM)
			} else {
				Xsqlite3_snprintf(tls, nFilename, zLockFile, __ccgo_ts+3982, libc.VaList(bp+8, zFilename))
			}
			(*TunixFile)(unsafe.Pointer(pNew)).FlockingContext = zLockFile
		}
	}
	_storeLastErrno(tls, pNew, 0)
	if rc != SQLITE_OK {
		if h >= 0 {
			_robust_close(tls, pNew, h, int32(46447))
		}
	} else {
		(*Tsqlite3_file)(unsafe.Pointer(pId)).FpMethods = pLockingStyle
		_verifyDbFile(tls, pNew)
	}
	return rc
}

// C documentation
//
//	/*
//	** Return a pointer corresponding to database zDb (i.e. "main", "temp")
//	** in connection handle pDb. If such a database cannot be found, return
//	** a NULL pointer and write an error message to pErrorDb.
//	**
//	** If the "temp" database is requested, it may need to be opened by this
//	** function. If an error occurs while doing so, return 0 and write an
//	** error message to pErrorDb.
//	*/
func _findBtree(tls *libc.TLS, pErrorDb uintptr, pDb uintptr, zDb uintptr) (r uintptr) {
	bp := tls.Alloc(448)
	defer tls.Free(448)
	var i, rc int32
	var _ /* sParse at bp+0 */ TParse
	_, _ = i, rc
	i = _sqlite3FindDbName(tls, pDb, zDb)
	if i == int32(1) {
		rc = 0
		_sqlite3ParseObjectInit(tls, bp, pDb)
		if _sqlite3OpenTempDatabase(tls, bp) != 0 {
			_sqlite3ErrorWithMsg(tls, pErrorDb, (**(**TParse)(__ccgo_up(bp))).Frc, __ccgo_ts+3933, libc.VaList(bp+432, (**(**TParse)(__ccgo_up(bp))).FzErrMsg))
			rc = int32(SQLITE_ERROR)
		}
		_sqlite3DbFree(tls, pErrorDb, (**(**TParse)(__ccgo_up(bp))).FzErrMsg)
		_sqlite3ParseObjectReset(tls, bp)
		if rc != 0 {
			return uintptr(0)
		}
	}
	if i < 0 {
		_sqlite3ErrorWithMsg(tls, pErrorDb, int32(SQLITE_ERROR), __ccgo_ts+5118, libc.VaList(bp+432, zDb))
		return uintptr(0)
	}
	return (**(**TDb)(__ccgo_up((*Tsqlite3)(unsafe.Pointer(pDb)).FaDb + uintptr(i)*32))).FpBt
}

// C documentation
//
//	/*
//	** Given a file descriptor, locate the unixInodeInfo object that
//	** describes that file descriptor.  Create a new one if necessary.  The
//	** return value might be uninitialized if an error occurs.
//	**
//	** The global mutex must held when calling this routine.
//	**
//	** Return an appropriate error code.
//	*/
func _findInodeInfo(tls *libc.TLS, pFile uintptr, ppInode uintptr) (r int32) {
	bp := tls.Alloc(144)
	defer tls.Free(144)
	var fd, rc int32
	var pInode uintptr
	var _ /* fileId at bp+0 */ TunixFileId
	var _ /* statbuf at bp+16 */ Tstat
	_, _, _ = fd, pInode, rc /* Low-level file information */
	pInode = uintptr(0)      /* Candidate unixInodeInfo object */
	/* Get low-level information about the file that we can used to
	 ** create a unique name for the file.
	 */
	fd = (*TunixFile)(unsafe.Pointer(pFile)).Fh
	rc = (*(*func(*libc.TLS, int32, uintptr) int32)(unsafe.Pointer(&struct{ uintptr }{_aSyscall[int32(5)].FpCurrent})))(tls, fd, bp+16)
	if rc != 0 {
		_storeLastErrno(tls, pFile, **(**int32)(__ccgo_up(libc.X__errno(tls))))
		return int32(SQLITE_IOERR)
	}
	libc.Xmemset(tls, bp, 0, uint64(16))
	(**(**TunixFileId)(__ccgo_up(bp))).Fdev = (**(**Tstat)(__ccgo_up(bp + 16))).Fst_dev
	(**(**TunixFileId)(__ccgo_up(bp))).Fino = (**(**Tstat)(__ccgo_up(bp + 16))).Fst_ino
	pInode = _inodeList
	for pInode != 0 && libc.Xmemcmp(tls, bp, pInode, uint64(16)) != 0 {
		pInode = (*TunixInodeInfo)(unsafe.Pointer(pInode)).FpNext
	}
	if pInode == uintptr(0) {
		pInode = Xsqlite3_malloc64(tls, uint64(80))
		if pInode == uintptr(0) {
			return int32(SQLITE_NOMEM)
		}
		libc.Xmemset(tls, pInode, 0, uint64(80))
		libc.Xmemcpy(tls, pInode, bp, uint64(16))
		if _sqlite3Config.FbCoreMutex != 0 {
			(*TunixInodeInfo)(unsafe.Pointer(pInode)).FpLockMutex = Xsqlite3_mutex_alloc(tls, SQLITE_MUTEX_FAST)
			if (*TunixInodeInfo)(unsafe.Pointer(pInode)).FpLockMutex == uintptr(0) {
				Xsqlite3_free(tls, pInode)
				return int32(SQLITE_NOMEM)
			}
		}
		(*TunixInodeInfo)(unsafe.Pointer(pInode)).FnRef = int32(1)
		(*TunixInodeInfo)(unsafe.Pointer(pInode)).FpNext = _inodeList
		(*TunixInodeInfo)(unsafe.Pointer(pInode)).FpPrev = uintptr(0)
		if _inodeList != 0 {
			(*TunixInodeInfo)(unsafe.Pointer(_inodeList)).FpPrev = pInode
		}
		_inodeList = pInode
	} else {
		(*TunixInodeInfo)(unsafe.Pointer(pInode)).FnRef = (*TunixInodeInfo)(unsafe.Pointer(pInode)).FnRef + 1
	}
	**(**uintptr)(__ccgo_up(ppInode)) = pInode
	return SQLITE_OK
}

// C documentation
//
//	/*
//	** Search the AggInfo object for an aCol[] entry that has iTable and iColumn.
//	** Return the index in aCol[] of the entry that describes that column.
//	**
//	** If no prior entry is found, create a new one and return -1.  The
//	** new column will have an index of pAggInfo->nColumn-1.
//	*/
func _findOrCreateAggInfoColumn(tls *libc.TLS, pParse uintptr, pAggInfo uintptr, pExpr uintptr) {
	bp := tls.Alloc(16)
	defer tls.Free(16)
	var j, k, mxTerm, n int32
	var pCol, pE, pGB, pTerm, v4 uintptr
	var v3 Tu32
	_, _, _, _, _, _, _, _, _, _ = j, k, mxTerm, n, pCol, pE, pGB, pTerm, v3, v4
	mxTerm = **(**int32)(__ccgo_up((*TParse)(unsafe.Pointer(pParse)).Fdb + 136 + 2*4))
	pCol = (*TAggInfo)(unsafe.Pointer(pAggInfo)).FaCol
	k = 0
	for {
		if !(k < (*TAggInfo)(unsafe.Pointer(pAggInfo)).FnColumn) {
			break
		}
		if (*TAggInfo_col)(unsafe.Pointer(pCol)).FpCExpr == pExpr {
			return
		}
		if (*TAggInfo_col)(unsafe.Pointer(pCol)).FiTable == (*TExpr)(unsafe.Pointer(pExpr)).FiTable && (*TAggInfo_col)(unsafe.Pointer(pCol)).FiColumn == int32((*TExpr)(unsafe.Pointer(pExpr)).FiColumn) && libc.Int32FromUint8((*TExpr)(unsafe.Pointer(pExpr)).Fop) != int32(TK_IF_NULL_ROW) {
			goto fix_up_expr
		}
		goto _1
	_1:
		;
		k = k + 1
		pCol += 32
	}
	k = _addAggInfoColumn(tls, (*TParse)(unsafe.Pointer(pParse)).Fdb, pAggInfo)
	if k < 0 {
		/* OOM on resize */
		return
	}
	if k > mxTerm {
		_sqlite3ErrorMsg(tls, pParse, __ccgo_ts+8607, libc.VaList(bp+8, mxTerm))
		k = mxTerm
	}
	pCol = (*TAggInfo)(unsafe.Pointer(pAggInfo)).FaCol + uintptr(k)*32
	(*TAggInfo_col)(unsafe.Pointer(pCol)).FpTab = *(*uintptr)(unsafe.Pointer(pExpr + 64))
	(*TAggInfo_col)(unsafe.Pointer(pCol)).FiTable = (*TExpr)(unsafe.Pointer(pExpr)).FiTable
	(*TAggInfo_col)(unsafe.Pointer(pCol)).FiColumn = int32((*TExpr)(unsafe.Pointer(pExpr)).FiColumn)
	(*TAggInfo_col)(unsafe.Pointer(pCol)).FiSorterColumn = -int32(1)
	(*TAggInfo_col)(unsafe.Pointer(pCol)).FpCExpr = pExpr
	if (*TAggInfo)(unsafe.Pointer(pAggInfo)).FpGroupBy != 0 && libc.Int32FromUint8((*TExpr)(unsafe.Pointer(pExpr)).Fop) != int32(TK_IF_NULL_ROW) {
		pGB = (*TAggInfo)(unsafe.Pointer(pAggInfo)).FpGroupBy
		pTerm = pGB + 8
		n = (*TExprList)(unsafe.Pointer(pGB)).FnExpr
		j = 0
		for {
			if !(j < n) {
				break
			}
			pE = (*TExprList_item)(unsafe.Pointer(pTerm)).FpExpr
			if libc.Int32FromUint8((*TExpr)(unsafe.Pointer(pE)).Fop) == int32(TK_COLUMN) && (*TExpr)(unsafe.Pointer(pE)).FiTable == (*TExpr)(unsafe.Pointer(pExpr)).FiTable && int32((*TExpr)(unsafe.Pointer(pE)).FiColumn) == int32((*TExpr)(unsafe.Pointer(pExpr)).FiColumn) {
				(*TAggInfo_col)(unsafe.Pointer(pCol)).FiSorterColumn = j
				break
			}
			goto _2
		_2:
			;
			j = j + 1
			pTerm += 32
		}
	}
	if (*TAggInfo_col)(unsafe.Pointer(pCol)).FiSorterColumn < 0 {
		v4 = pAggInfo + 4
		v3 = *(*Tu32)(unsafe.Pointer(v4))
		*(*Tu32)(unsafe.Pointer(v4)) = *(*Tu32)(unsafe.Pointer(v4)) + 1
		(*TAggInfo_col)(unsafe.Pointer(pCol)).FiSorterColumn = libc.Int32FromUint32(v3)
	}
	goto fix_up_expr
fix_up_expr:
	;
	(*TExpr)(unsafe.Pointer(pExpr)).FpAggInfo = pAggInfo
	if libc.Int32FromUint8((*TExpr)(unsafe.Pointer(pExpr)).Fop) == int32(TK_COLUMN) {
		(*TExpr)(unsafe.Pointer(pExpr)).Fop = uint8(TK_AGG_COLUMN)
	}
	(*TExpr)(unsafe.Pointer(pExpr)).FiAgg = int16(k)
}

// C documentation
//
//	/*
//	** Search for an unused file descriptor that was opened on the database
//	** file (not a journal or super-journal file) identified by pathname
//	** zPath with SQLITE_OPEN_XXX flags matching those passed as the second
//	** argument to this function.
//	**
//	** Such a file descriptor may exist if a database connection was closed
//	** but the associated file descriptor could not be closed because some
//	** other file descriptor open on the same file is holding a file-lock.
//	** Refer to comments in the unixClose() function and the lengthy comment
//	** describing "Posix Advisory Locking" at the start of this file for
//	** further details. Also, ticket #4018.
//	**
//	** If a suitable file descriptor is found, then it is returned. If no
//	** such file descriptor is located, -1 is returned.
//	*/
func _findReusableFd(tls *libc.TLS, zPath uintptr, flags int32) (r uintptr) {
	bp := tls.Alloc(128)
	defer tls.Free(128)
	var pInode, pUnused, pp uintptr
	var _ /* sStat at bp+0 */ Tstat
	_, _, _ = pInode, pUnused, pp
	pUnused = uintptr(0) /* Results of stat() call */
	_unixEnterMutex(tls)
	/* A stat() call may fail for various reasons. If this happens, it is
	 ** almost certain that an open() call on the same path will also fail.
	 ** For this reason, if an error occurs in the stat() call here, it is
	 ** ignored and -1 is returned. The caller will try to open a new file
	 ** descriptor on the same path, fail, and return an error to SQLite.
	 **
	 ** Even if a subsequent open() call does succeed, the consequences of
	 ** not searching for a reusable file descriptor are not dire.  */
	if _inodeList != uintptr(0) && 0 == (*(*func(*libc.TLS, uintptr, uintptr) int32)(unsafe.Pointer(&struct{ uintptr }{_aSyscall[int32(4)].FpCurrent})))(tls, zPath, bp) {
		pInode = _inodeList
		for pInode != 0 && ((*TunixInodeInfo)(unsafe.Pointer(pInode)).FfileId.Fdev != (**(**Tstat)(__ccgo_up(bp))).Fst_dev || (*TunixInodeInfo)(unsafe.Pointer(pInode)).FfileId.Fino != (**(**Tstat)(__ccgo_up(bp))).Fst_ino) {
			pInode = (*TunixInodeInfo)(unsafe.Pointer(pInode)).FpNext
		}
		if pInode != 0 {
			Xsqlite3_mutex_enter(tls, (*TunixInodeInfo)(unsafe.Pointer(pInode)).FpLockMutex)
			flags = flags & (libc.Int32FromInt32(SQLITE_OPEN_READONLY) | libc.Int32FromInt32(SQLITE_OPEN_READWRITE))
			pp = pInode + 40
			for {
				if !(**(**uintptr)(__ccgo_up(pp)) != 0 && (*TUnixUnusedFd)(unsafe.Pointer(**(**uintptr)(__ccgo_up(pp)))).Fflags != flags) {
					break
				}
				goto _1
			_1:
				;
				pp = **(**uintptr)(__ccgo_up(pp)) + 8
			}
			pUnused = **(**uintptr)(__ccgo_up(pp))
			if pUnused != 0 {
				**(**uintptr)(__ccgo_up(pp)) = (*TUnixUnusedFd)(unsafe.Pointer(pUnused)).FpNext
			}
			Xsqlite3_mutex_leave(tls, (*TunixInodeInfo)(unsafe.Pointer(pInode)).FpLockMutex)
		}
	}
	_unixLeaveMutex(tls)
	return pUnused
}

// C documentation
//
//	/*
//	** Expression callback used by sqlite3FixAAAA() routines.
//	*/
func _fixExprCb(tls *libc.TLS, p uintptr, pExpr uintptr) (r int32) {
	bp := tls.Alloc(16)
	defer tls.Free(16)
	var pFix uintptr
	_ = pFix
	pFix = *(*uintptr)(unsafe.Pointer(p + 40))
	if !((*TDbFixer)(unsafe.Pointer(pFix)).FbTemp != 0) {
		**(**Tu32)(__ccgo_up(pExpr + 4)) |= libc.Uint32FromInt32(libc.Int32FromInt32(EP_FromDDL))
	}
	if libc.Int32FromUint8((*TExpr)(unsafe.Pointer(pExpr)).Fop) == int32(TK_VARIABLE) {
		if (*Tsqlite3)(unsafe.Pointer((*TParse)(unsafe.Pointer((*TDbFixer)(unsafe.Pointer(pFix)).FpParse)).Fdb)).Finit1.Fbusy != 0 {
			(*TExpr)(unsafe.Pointer(pExpr)).Fop = uint8(TK_NULL)
		} else {
			_sqlite3ErrorMsg(tls, (*TDbFixer)(unsafe.Pointer(pFix)).FpParse, __ccgo_ts+13532, libc.VaList(bp+8, (*TDbFixer)(unsafe.Pointer(pFix)).FzType))
			return int32(WRC_Abort)
		}
	}
	return WRC_Continue
}

// C documentation
//
//	/*
//	** Select callback used by sqlite3FixAAAA() routines.
//	*/
func _fixSelectCb(tls *libc.TLS, p uintptr, pSelect uintptr) (r int32) {
	bp := tls.Alloc(32)
	defer tls.Free(32)
	var db, pFix, pItem, pList uintptr
	var i, iDb int32
	_, _, _, _, _, _ = db, i, iDb, pFix, pItem, pList
	pFix = *(*uintptr)(unsafe.Pointer(p + 40))
	db = (*TParse)(unsafe.Pointer((*TDbFixer)(unsafe.Pointer(pFix)).FpParse)).Fdb
	iDb = _sqlite3FindDbName(tls, db, (*TDbFixer)(unsafe.Pointer(pFix)).FzDb)
	pList = (*TSelect)(unsafe.Pointer(pSelect)).FpSrc
	if pList == uintptr(0) {
		return WRC_Continue
	}
	i = 0
	pItem = pList + 8
	for {
		if !(i < (*TSrcList)(unsafe.Pointer(pList)).FnSrc) {
			break
		}
		if libc.Int32FromUint8((*TDbFixer)(unsafe.Pointer(pFix)).FbTemp) == 0 && int32(*(*uint32)(unsafe.Pointer(pItem + 24 + 4))&0x4>>2) == 0 {
			if int32(*(*uint32)(unsafe.Pointer(pItem + 24 + 4))&0x10000>>16) == 0 && *(*uintptr)(unsafe.Pointer(pItem + 72)) != uintptr(0) {
				if iDb != _sqlite3FindDbName(tls, db, *(*uintptr)(unsafe.Pointer(pItem + 72))) {
					_sqlite3ErrorMsg(tls, (*TDbFixer)(unsafe.Pointer(pFix)).FpParse, __ccgo_ts+13556, libc.VaList(bp+8, (*TDbFixer)(unsafe.Pointer(pFix)).FzType, (*TDbFixer)(unsafe.Pointer(pFix)).FpName, *(*uintptr)(unsafe.Pointer(pItem + 72))))
					return int32(WRC_Abort)
				}
				_sqlite3DbFree(tls, db, *(*uintptr)(unsafe.Pointer(pItem + 72)))
				libc.SetBitFieldPtr32Uint32(pItem+24+4, libc.Uint32FromInt32(1), 10, 0x400)
				libc.SetBitFieldPtr32Uint32(pItem+24+4, libc.Uint32FromInt32(1), 17, 0x20000)
			}
			*(*uintptr)(unsafe.Pointer(pItem + 72)) = (*TDbFixer)(unsafe.Pointer(pFix)).FpSchema
			libc.SetBitFieldPtr32Uint32(pItem+24+4, libc.Uint32FromInt32(1), 8, 0x100)
			libc.SetBitFieldPtr32Uint32(pItem+24+4, libc.Uint32FromInt32(1), 16, 0x10000)
		}
		if int32(*(*uint32)(unsafe.Pointer(pList + 8 + uintptr(i)*80 + 24 + 4))&0x800>>11) == 0 && _sqlite3WalkExpr(tls, pFix+8, *(*uintptr)(unsafe.Pointer(pList + 8 + uintptr(i)*80 + 64))) != 0 {
			return int32(WRC_Abort)
		}
		goto _1
	_1:
		;
		i = i + 1
		pItem += 80
	}
	if (*TSelect)(unsafe.Pointer(pSelect)).FpWith != 0 {
		i = 0
		for {
			if !(i < (*TWith)(unsafe.Pointer((*TSelect)(unsafe.Pointer(pSelect)).FpWith)).FnCte) {
				break
			}
			if _sqlite3WalkSelect(tls, p, (*(*TCte)(unsafe.Pointer((*TSelect)(unsafe.Pointer(pSelect)).FpWith + 16 + uintptr(i)*48))).FpSelect) != 0 {
				return int32(WRC_Abort)
			}
			goto _2
		_2:
			;
			i = i + 1
		}
	}
	return WRC_Continue
}

func _fts5ApiCallback(tls *libc.TLS, context uintptr, argc int32, argv uintptr) {
	bp := tls.Alloc(16)
	defer tls.Free(16)
	var iCsrId Ti64
	var pAux, pCsr, pTab uintptr
	_, _, _, _ = iCsrId, pAux, pCsr, pTab
	pAux = Xsqlite3_user_data(tls, context)
	iCsrId = Xsqlite3_value_int64(tls, **(**uintptr)(__ccgo_up(argv)))
	pCsr = _fts5CursorFromCsrid(tls, (*TFts5Auxiliary)(unsafe.Pointer(pAux)).FpGlobal, iCsrId)
	if pCsr == uintptr(0) || ((*TFts5Cursor)(unsafe.Pointer(pCsr)).FePlan == 0 || (*TFts5Cursor)(unsafe.Pointer(pCsr)).FePlan == int32(FTS5_PLAN_SPECIAL)) {
		_fts5ResultError(tls, context, __ccgo_ts+40411, libc.VaList(bp+8, iCsrId))
	} else {
		pTab = (*TFts5Cursor)(unsafe.Pointer(pCsr)).Fbase.FpVtab
		_fts5ApiInvoke(tls, pAux, pCsr, context, argc-int32(1), argv+1*8)
		Xsqlite3_free(tls, (*Tsqlite3_vtab)(unsafe.Pointer(pTab)).FzErrMsg)
		(*Tsqlite3_vtab)(unsafe.Pointer(pTab)).FzErrMsg = uintptr(0)
	}
}

// C documentation
//
//	/*
//	** Create an "ascii" tokenizer.
//	*/
func _fts5AsciiCreate(tls *libc.TLS, pUnused uintptr, azArg uintptr, nArg int32, ppOut uintptr) (r int32) {
	var i, rc int32
	var p, zArg uintptr
	_, _, _, _ = i, p, rc, zArg
	rc = SQLITE_OK
	p = uintptr(0)
	_ = pUnused
	if nArg%int32(2) != 0 {
		rc = int32(SQLITE_ERROR)
	} else {
		p = Xsqlite3_malloc64(tls, uint64(128))
		if p == uintptr(0) {
			rc = int32(SQLITE_NOMEM)
		} else {
			libc.Xmemset(tls, p, 0, uint64(128))
			libc.Xmemcpy(tls, p, uintptr(unsafe.Pointer(&_aAsciiTokenChar)), uint64(128))
			i = 0
			for {
				if !(rc == SQLITE_OK && i < nArg) {
					break
				}
				zArg = **(**uintptr)(__ccgo_up(azArg + uintptr(i+int32(1))*8))
				if 0 == Xsqlite3_stricmp(tls, **(**uintptr)(__ccgo_up(azArg + uintptr(i)*8)), __ccgo_ts+41823) {
					_fts5AsciiAddExceptions(tls, p, zArg, int32(1))
				} else {
					if 0 == Xsqlite3_stricmp(tls, **(**uintptr)(__ccgo_up(azArg + uintptr(i)*8)), __ccgo_ts+41834) {
						_fts5AsciiAddExceptions(tls, p, zArg, 0)
					} else {
						rc = int32(SQLITE_ERROR)
					}
				}
				goto _1
			_1:
				;
				i = i + int32(2)
			}
			if rc != SQLITE_OK {
				_fts5AsciiDelete(tls, p)
				p = uintptr(0)
			}
		}
	}
	**(**uintptr)(__ccgo_up(ppOut)) = p
	return rc
}

// C documentation
//
//	/*
//	** Populate the Fts5Config.zContentExprlist string.
//	*/
func _fts5ConfigMakeExprlist(tls *libc.TLS, p uintptr) (r int32) {
	bp := tls.Alloc(48)
	defer tls.Free(48)
	var i int32
	var _ /* buf at bp+8 */ TFts5Buffer
	var _ /* rc at bp+0 */ int32
	_ = i
	**(**int32)(__ccgo_up(bp)) = SQLITE_OK
	**(**TFts5Buffer)(__ccgo_up(bp + 8)) = TFts5Buffer{}
	_sqlite3Fts5BufferAppendPrintf(tls, bp, bp+8, __ccgo_ts+38033, libc.VaList(bp+32, (*TFts5Config)(unsafe.Pointer(p)).FzContentRowid))
	if (*TFts5Config)(unsafe.Pointer(p)).FeContent != int32(FTS5_CONTENT_NONE) {
		i = 0
		for {
			if !(i < (*TFts5Config)(unsafe.Pointer(p)).FnCol) {
				break
			}
			if (*TFts5Config)(unsafe.Pointer(p)).FeContent == int32(FTS5_CONTENT_EXTERNAL) {
				_sqlite3Fts5BufferAppendPrintf(tls, bp, bp+8, __ccgo_ts+38038, libc.VaList(bp+32, **(**uintptr)(__ccgo_up((*TFts5Config)(unsafe.Pointer(p)).FazCol + uintptr(i)*8))))
			} else {
				if (*TFts5Config)(unsafe.Pointer(p)).FeContent == FTS5_CONTENT_NORMAL || **(**Tu8)(__ccgo_up((*TFts5Config)(unsafe.Pointer(p)).FabUnindexed + uintptr(i))) != 0 {
					_sqlite3Fts5BufferAppendPrintf(tls, bp, bp+8, __ccgo_ts+38045, libc.VaList(bp+32, i))
				} else {
					_sqlite3Fts5BufferAppendPrintf(tls, bp, bp+8, __ccgo_ts+38053, 0)
				}
			}
			goto _1
		_1:
			;
			i = i + 1
		}
	}
	if (*TFts5Config)(unsafe.Pointer(p)).FeContent == FTS5_CONTENT_NORMAL && (*TFts5Config)(unsafe.Pointer(p)).FbLocale != 0 {
		i = 0
		for {
			if !(i < (*TFts5Config)(unsafe.Pointer(p)).FnCol) {
				break
			}
			if libc.Int32FromUint8(**(**Tu8)(__ccgo_up((*TFts5Config)(unsafe.Pointer(p)).FabUnindexed + uintptr(i)))) == 0 {
				_sqlite3Fts5BufferAppendPrintf(tls, bp, bp+8, __ccgo_ts+38060, libc.VaList(bp+32, i))
			} else {
				_sqlite3Fts5BufferAppendPrintf(tls, bp, bp+8, __ccgo_ts+38053, 0)
			}
			goto _2
		_2:
			;
			i = i + 1
		}
	}
	(*TFts5Config)(unsafe.Pointer(p)).FzContentExprlist = (**(**TFts5Buffer)(__ccgo_up(bp + 8))).Fp
	return **(**int32)(__ccgo_up(bp))
}

func _fts5ConfigParseColumn(tls *libc.TLS, p uintptr, zCol uintptr, zArg uintptr, pzErr uintptr, pbUnindexed uintptr) (r int32) {
	bp := tls.Alloc(16)
	defer tls.Free(16)
	var rc, v1 int32
	var v2 uintptr
	_, _, _ = rc, v1, v2
	rc = SQLITE_OK
	if 0 == Xsqlite3_stricmp(tls, zCol, __ccgo_ts+37957) || 0 == Xsqlite3_stricmp(tls, zCol, __ccgo_ts+17956) {
		**(**uintptr)(__ccgo_up(pzErr)) = Xsqlite3_mprintf(tls, __ccgo_ts+37962, libc.VaList(bp+8, zCol))
		rc = int32(SQLITE_ERROR)
	} else {
		if zArg != 0 {
			if 0 == Xsqlite3_stricmp(tls, zArg, __ccgo_ts+37992) {
				**(**Tu8)(__ccgo_up((*TFts5Config)(unsafe.Pointer(p)).FabUnindexed + uintptr((*TFts5Config)(unsafe.Pointer(p)).FnCol))) = uint8(1)
				**(**int32)(__ccgo_up(pbUnindexed)) = int32(1)
			} else {
				**(**uintptr)(__ccgo_up(pzErr)) = Xsqlite3_mprintf(tls, __ccgo_ts+38002, libc.VaList(bp+8, zArg))
				rc = int32(SQLITE_ERROR)
			}
		}
	}
	v2 = p + 32
	v1 = *(*int32)(unsafe.Pointer(v2))
	*(*int32)(unsafe.Pointer(v2)) = *(*int32)(unsafe.Pointer(v2)) + 1
	**(**uintptr)(__ccgo_up((*TFts5Config)(unsafe.Pointer(p)).FazCol + uintptr(v1)*8)) = zCol
	return rc
}

// C documentation
//
//	/*
//	**
//	** This function is called when the user attempts an UPDATE on a contentless
//	** table. Parameter bRowidModified is true if the UPDATE statement modifies
//	** the rowid value. Parameter apVal[] contains the new values for each user
//	** defined column of the fts5 table. pConfig is the configuration object of the
//	** table being updated (guaranteed to be contentless). The contentless_delete=1
//	** and contentless_unindexed=1 options may or may not be set.
//	**
//	** This function returns SQLITE_OK if the UPDATE can go ahead, or an SQLite
//	** error code if it cannot. In this case an error message is also loaded into
//	** pConfig. Output parameter (*pbContent) is set to true if the caller should
//	** update the %_content table only - not the FTS index or any other shadow
//	** table. This occurs when an UPDATE modifies only UNINDEXED columns of the
//	** table.
//	**
//	** An UPDATE may proceed if:
//	**
//	**   * The only columns modified are UNINDEXED columns, or
//	**
//	**   * The contentless_delete=1 option was specified and all of the indexed
//	**     columns (not a subset) have been modified.
//	*/
func _fts5ContentlessUpdate(tls *libc.TLS, pConfig uintptr, apVal uintptr, bRowidModified int32, pbContent uintptr) (r int32) {
	bp := tls.Alloc(32)
	defer tls.Free(32)
	var bSeenIndex, bSeenIndexNC, ii, rc int32
	var v2 uintptr
	_, _, _, _, _ = bSeenIndex, bSeenIndexNC, ii, rc, v2
	bSeenIndex = 0   /* Have seen modified indexed column */
	bSeenIndexNC = 0 /* Have seen unmodified indexed column */
	rc = SQLITE_OK
	ii = 0
	for {
		if !(ii < (*TFts5Config)(unsafe.Pointer(pConfig)).FnCol) {
			break
		}
		if libc.Int32FromUint8(**(**Tu8)(__ccgo_up((*TFts5Config)(unsafe.Pointer(pConfig)).FabUnindexed + uintptr(ii)))) == 0 {
			if Xsqlite3_value_nochange(tls, **(**uintptr)(__ccgo_up(apVal + uintptr(ii)*8))) != 0 {
				bSeenIndexNC = bSeenIndexNC + 1
			} else {
				bSeenIndex = bSeenIndex + 1
			}
		}
		goto _1
	_1:
		;
		ii = ii + 1
	}
	if bSeenIndex == 0 && bRowidModified == 0 {
		**(**int32)(__ccgo_up(pbContent)) = int32(1)
	} else {
		if bSeenIndexNC != 0 || (*TFts5Config)(unsafe.Pointer(pConfig)).FbContentlessDelete == 0 {
			rc = int32(SQLITE_ERROR)
			if (*TFts5Config)(unsafe.Pointer(pConfig)).FbContentlessDelete != 0 {
				v2 = __ccgo_ts + 40170
			} else {
				v2 = __ccgo_ts + 40230
			}
			_sqlite3Fts5ConfigErrmsg(tls, pConfig, v2, libc.VaList(bp+8, __ccgo_ts+40260, (*TFts5Config)(unsafe.Pointer(pConfig)).FzName))
		}
	}
	return rc
}

func _fts5CursorFirstSorted(tls *libc.TLS, pTab uintptr, pCsr uintptr, bDesc int32) (r int32) {
	bp := tls.Alloc(64)
	defer tls.Free(64)
	var nByte Tsqlite3_int64
	var nPhrase, rc int32
	var pConfig, pSorter, zRank, zRankArgs, v1, v2, v3 uintptr
	_, _, _, _, _, _, _, _, _, _ = nByte, nPhrase, pConfig, pSorter, rc, zRank, zRankArgs, v1, v2, v3
	pConfig = (*TFts5FullTable)(unsafe.Pointer(pTab)).Fp.FpConfig
	zRank = (*TFts5Cursor)(unsafe.Pointer(pCsr)).FzRank
	zRankArgs = (*TFts5Cursor)(unsafe.Pointer(pCsr)).FzRankArgs
	nPhrase = _sqlite3Fts5ExprPhraseCount(tls, (*TFts5Cursor)(unsafe.Pointer(pCsr)).FpExpr)
	nByte = libc.Int64FromUint64(uint64(libc.UintptrFromInt32(0)+24) + libc.Uint64FromInt32((nPhrase+libc.Int32FromInt32(2))/libc.Int32FromInt32(2))*libc.Uint64FromInt64(8))
	pSorter = Xsqlite3_malloc64(tls, libc.Uint64FromInt64(nByte))
	if pSorter == uintptr(0) {
		return int32(SQLITE_NOMEM)
	}
	libc.Xmemset(tls, pSorter, 0, libc.Uint64FromInt64(nByte))
	(*TFts5Sorter)(unsafe.Pointer(pSorter)).FnIdx = nPhrase
	/* TODO: It would be better to have some system for reusing statement
	 ** handles here, rather than preparing a new one for each query. But that
	 ** is not possible as SQLite reference counts the virtual table objects.
	 ** And since the statement required here reads from this very virtual
	 ** table, saving it creates a circular reference.
	 **
	 ** If SQLite a built-in statement cache, this wouldn't be a problem. */
	if zRankArgs != 0 {
		v1 = __ccgo_ts + 16207
	} else {
		v1 = __ccgo_ts + 1693
	}
	if zRankArgs != 0 {
		v2 = zRankArgs
	} else {
		v2 = __ccgo_ts + 1693
	}
	if bDesc != 0 {
		v3 = __ccgo_ts + 39744
	} else {
		v3 = __ccgo_ts + 39749
	}
	rc = _fts5PrepareStatement(tls, pSorter, pConfig, __ccgo_ts+39753, libc.VaList(bp+8, (*TFts5Config)(unsafe.Pointer(pConfig)).FzDb, (*TFts5Config)(unsafe.Pointer(pConfig)).FzName, zRank, (*TFts5Config)(unsafe.Pointer(pConfig)).FzName, v1, v2, v3))
	(*TFts5Cursor)(unsafe.Pointer(pCsr)).FpSorter = pSorter
	if rc == SQLITE_OK {
		(*TFts5FullTable)(unsafe.Pointer(pTab)).FpSortCsr = pCsr
		rc = _fts5SorterNext(tls, pCsr)
		(*TFts5FullTable)(unsafe.Pointer(pTab)).FpSortCsr = uintptr(0)
	}
	if rc != SQLITE_OK {
		Xsqlite3_finalize(tls, (*TFts5Sorter)(unsafe.Pointer(pSorter)).FpStmt)
		Xsqlite3_free(tls, pSorter)
		(*TFts5Cursor)(unsafe.Pointer(pCsr)).FpSorter = uintptr(0)
	}
	return rc
}

func _fts5CursorParseRank(tls *libc.TLS, pConfig uintptr, pCsr uintptr, pRank uintptr) (r int32) {
	bp := tls.Alloc(32)
	defer tls.Free(32)
	var rc int32
	var z uintptr
	var _ /* zRank at bp+0 */ uintptr
	var _ /* zRankArgs at bp+8 */ uintptr
	_, _ = rc, z
	rc = SQLITE_OK
	if pRank != 0 {
		z = Xsqlite3_value_text(tls, pRank)
		**(**uintptr)(__ccgo_up(bp)) = uintptr(0)
		**(**uintptr)(__ccgo_up(bp + 8)) = uintptr(0)
		if z == uintptr(0) {
			if Xsqlite3_value_type(tls, pRank) == int32(SQLITE_NULL) {
				rc = int32(SQLITE_ERROR)
			}
		} else {
			rc = _sqlite3Fts5ConfigParseRank(tls, z, bp, bp+8)
		}
		if rc == SQLITE_OK {
			(*TFts5Cursor)(unsafe.Pointer(pCsr)).FzRank = **(**uintptr)(__ccgo_up(bp))
			(*TFts5Cursor)(unsafe.Pointer(pCsr)).FzRankArgs = **(**uintptr)(__ccgo_up(bp + 8))
			**(**int32)(__ccgo_up(pCsr + 80)) |= int32(FTS5CSR_FREE_ZRANK)
		} else {
			if rc == int32(SQLITE_ERROR) {
				(*Tsqlite3_vtab)(unsafe.Pointer((*TFts5Cursor)(unsafe.Pointer(pCsr)).Fbase.FpVtab)).FzErrMsg = Xsqlite3_mprintf(tls, __ccgo_ts+39873, libc.VaList(bp+24, z))
			}
		}
	} else {
		if (*TFts5Config)(unsafe.Pointer(pConfig)).FzRank != 0 {
			(*TFts5Cursor)(unsafe.Pointer(pCsr)).FzRank = (*TFts5Config)(unsafe.Pointer(pConfig)).FzRank
			(*TFts5Cursor)(unsafe.Pointer(pCsr)).FzRankArgs = (*TFts5Config)(unsafe.Pointer(pConfig)).FzRankArgs
		} else {
			(*TFts5Cursor)(unsafe.Pointer(pCsr)).FzRank = __ccgo_ts + 37375
			(*TFts5Cursor)(unsafe.Pointer(pCsr)).FzRankArgs = uintptr(0)
		}
	}
	return rc
}

// C documentation
//
//	/*
//	** Execute the following SQL:
//	**
//	**     DELETE FROM %_data WHERE id BETWEEN $iFirst AND $iLast
//	*/
func _fts5DataDelete(tls *libc.TLS, p uintptr, iFirst Ti64, iLast Ti64) {
	bp := tls.Alloc(32)
	defer tls.Free(32)
	var pConfig, zSql uintptr
	_, _ = pConfig, zSql
	if (*TFts5Index)(unsafe.Pointer(p)).Frc != SQLITE_OK {
		return
	}
	if (*TFts5Index)(unsafe.Pointer(p)).FpDeleter == uintptr(0) {
		pConfig = (*TFts5Index)(unsafe.Pointer(p)).FpConfig
		zSql = Xsqlite3_mprintf(tls, __ccgo_ts+38988, libc.VaList(bp+8, (*TFts5Config)(unsafe.Pointer(pConfig)).FzDb, (*TFts5Config)(unsafe.Pointer(pConfig)).FzName))
		if _fts5IndexPrepareStmt(tls, p, p+88, zSql) != 0 {
			return
		}
	}
	Xsqlite3_bind_int64(tls, (*TFts5Index)(unsafe.Pointer(p)).FpDeleter, int32(1), iFirst)
	Xsqlite3_bind_int64(tls, (*TFts5Index)(unsafe.Pointer(p)).FpDeleter, int32(2), iLast)
	Xsqlite3_step(tls, (*TFts5Index)(unsafe.Pointer(p)).FpDeleter)
	(*TFts5Index)(unsafe.Pointer(p)).Frc = Xsqlite3_reset(tls, (*TFts5Index)(unsafe.Pointer(p)).FpDeleter)
}

// C documentation
//
//	/*
//	** Retrieve a record from the %_data table.
//	**
//	** If an error occurs, NULL is returned and an error left in the
//	** Fts5Index object.
//	*/
func _fts5DataRead(tls *libc.TLS, p uintptr, iRowid Ti64) (r uintptr) {
	var aOut, pBlob, pConfig, pRet, v1 uintptr
	var nAlloc, nByte, szData Ti64
	var rc int32
	_, _, _, _, _, _, _, _, _ = aOut, nAlloc, nByte, pBlob, pConfig, pRet, rc, szData, v1
	pRet = uintptr(0)
	if (*TFts5Index)(unsafe.Pointer(p)).Frc == SQLITE_OK {
		rc = SQLITE_OK
		if (*TFts5Index)(unsafe.Pointer(p)).FpReader != 0 {
			/* This call may return SQLITE_ABORT if there has been a savepoint
			 ** rollback since it was last used. In this case a new blob handle
			 ** is required.  */
			pBlob = (*TFts5Index)(unsafe.Pointer(p)).FpReader
			(*TFts5Index)(unsafe.Pointer(p)).FpReader = uintptr(0)
			rc = Xsqlite3_blob_reopen(tls, pBlob, iRowid)
			(*TFts5Index)(unsafe.Pointer(p)).FpReader = pBlob
			if rc != SQLITE_OK {
				_fts5IndexCloseReader(tls, p)
			}
			if rc == int32(SQLITE_ABORT) {
				rc = SQLITE_OK
			}
		}
		/* If the blob handle is not open at this point, open it and seek
		 ** to the requested entry.  */
		if (*TFts5Index)(unsafe.Pointer(p)).FpReader == uintptr(0) && rc == SQLITE_OK {
			pConfig = (*TFts5Index)(unsafe.Pointer(p)).FpConfig
			rc = Xsqlite3_blob_open(tls, (*TFts5Config)(unsafe.Pointer(pConfig)).Fdb, (*TFts5Config)(unsafe.Pointer(pConfig)).FzDb, (*TFts5Index)(unsafe.Pointer(p)).FzDataTbl, __ccgo_ts+38931, iRowid, 0, p+72)
		}
		/* If either of the sqlite3_blob_open() or sqlite3_blob_reopen() calls
		 ** above returned SQLITE_ERROR, return SQLITE_CORRUPT_VTAB instead.
		 ** All the reasons those functions might return SQLITE_ERROR - missing
		 ** table, missing row, non-blob/text in block column - indicate
		 ** backing store corruption.  */
		if rc == int32(SQLITE_ERROR) {
			rc = _fts5IndexCorruptRowid(tls, p, iRowid)
		}
		if rc == SQLITE_OK {
			aOut = uintptr(0) /* Read blob data into this buffer */
			nByte = int64(Xsqlite3_blob_bytes(tls, (*TFts5Index)(unsafe.Pointer(p)).FpReader))
			szData = libc.Int64FromUint64((libc.Uint64FromInt64(16) + libc.Uint64FromInt32(7)) & libc.Uint64FromInt32(^libc.Int32FromInt32(7)))
			nAlloc = szData + nByte + int64(FTS5_DATA_PADDING)
			pRet = Xsqlite3_malloc64(tls, libc.Uint64FromInt64(nAlloc))
			if pRet != 0 {
				(*TFts5Data)(unsafe.Pointer(pRet)).Fnn = int32(nByte)
				v1 = pRet + uintptr(szData)
				(*TFts5Data)(unsafe.Pointer(pRet)).Fp = v1
				aOut = v1
			} else {
				rc = int32(SQLITE_NOMEM)
			}
			if rc == SQLITE_OK {
				rc = Xsqlite3_blob_read(tls, (*TFts5Index)(unsafe.Pointer(p)).FpReader, aOut, int32(nByte), 0)
			}
			if rc != SQLITE_OK {
				Xsqlite3_free(tls, pRet)
				pRet = uintptr(0)
			} else {
				/* TODO1: Fix this */
				**(**Tu8)(__ccgo_up((*TFts5Data)(unsafe.Pointer(pRet)).Fp + uintptr(nByte))) = uint8(0x00)
				**(**Tu8)(__ccgo_up((*TFts5Data)(unsafe.Pointer(pRet)).Fp + uintptr(nByte+int64(1)))) = uint8(0x00)
				(*TFts5Data)(unsafe.Pointer(pRet)).FszLeaf = libc.Int32FromUint16(_fts5GetU16(tls, (*TFts5Data)(unsafe.Pointer(pRet)).Fp+2))
			}
		}
		(*TFts5Index)(unsafe.Pointer(p)).Frc = rc
		(*TFts5Index)(unsafe.Pointer(p)).FnRead = (*TFts5Index)(unsafe.Pointer(p)).FnRead + 1
	}
	return pRet
}

// C documentation
//
//	/*
//	** Remove all records associated with segment iSegid.
//	*/
func _fts5DataRemoveSegment(tls *libc.TLS, p uintptr, pSeg uintptr) {
	bp := tls.Alloc(32)
	defer tls.Free(32)
	var iFirst, iLast, iTomb1, iTomb2 Ti64
	var iSegid int32
	var pConfig uintptr
	_, _, _, _, _, _ = iFirst, iLast, iSegid, iTomb1, iTomb2, pConfig
	iSegid = (*TFts5StructureSegment)(unsafe.Pointer(pSeg)).FiSegid
	iFirst = int64(iSegid)<<(libc.Int32FromInt32(FTS5_DATA_PAGE_B)+libc.Int32FromInt32(FTS5_DATA_HEIGHT_B)+libc.Int32FromInt32(FTS5_DATA_DLI_B)) + int64(libc.Int32FromInt32(0))<<(libc.Int32FromInt32(FTS5_DATA_PAGE_B)+libc.Int32FromInt32(FTS5_DATA_HEIGHT_B)) + int64(libc.Int32FromInt32(0))<<libc.Int32FromInt32(FTS5_DATA_PAGE_B) + int64(libc.Int32FromInt32(0))
	iLast = int64(iSegid+libc.Int32FromInt32(1))<<(libc.Int32FromInt32(FTS5_DATA_PAGE_B)+libc.Int32FromInt32(FTS5_DATA_HEIGHT_B)+libc.Int32FromInt32(FTS5_DATA_DLI_B)) + int64(libc.Int32FromInt32(0))<<(libc.Int32FromInt32(FTS5_DATA_PAGE_B)+libc.Int32FromInt32(FTS5_DATA_HEIGHT_B)) + int64(libc.Int32FromInt32(0))<<libc.Int32FromInt32(FTS5_DATA_PAGE_B) + int64(libc.Int32FromInt32(0)) - int64(1)
	_fts5DataDelete(tls, p, iFirst, iLast)
	if (*TFts5StructureSegment)(unsafe.Pointer(pSeg)).FnPgTombstone != 0 {
		iTomb1 = int64(iSegid+libc.Int32FromInt32(1)<<libc.Int32FromInt32(16))<<(libc.Int32FromInt32(FTS5_DATA_PAGE_B)+libc.Int32FromInt32(FTS5_DATA_HEIGHT_B)+libc.Int32FromInt32(FTS5_DATA_DLI_B)) + int64(libc.Int32FromInt32(0))<<(libc.Int32FromInt32(FTS5_DATA_PAGE_B)+libc.Int32FromInt32(FTS5_DATA_HEIGHT_B)) + int64(libc.Int32FromInt32(0))<<libc.Int32FromInt32(FTS5_DATA_PAGE_B) + int64(libc.Int32FromInt32(0))
		iTomb2 = int64(iSegid+libc.Int32FromInt32(1)<<libc.Int32FromInt32(16))<<(libc.Int32FromInt32(FTS5_DATA_PAGE_B)+libc.Int32FromInt32(FTS5_DATA_HEIGHT_B)+libc.Int32FromInt32(FTS5_DATA_DLI_B)) + int64(libc.Int32FromInt32(0))<<(libc.Int32FromInt32(FTS5_DATA_PAGE_B)+libc.Int32FromInt32(FTS5_DATA_HEIGHT_B)) + int64(libc.Int32FromInt32(0))<<libc.Int32FromInt32(FTS5_DATA_PAGE_B) + int64((*TFts5StructureSegment)(unsafe.Pointer(pSeg)).FnPgTombstone-libc.Int32FromInt32(1))
		_fts5DataDelete(tls, p, iTomb1, iTomb2)
	}
	if (*TFts5Index)(unsafe.Pointer(p)).FpIdxDeleter == uintptr(0) {
		pConfig = (*TFts5Index)(unsafe.Pointer(p)).FpConfig
		_fts5IndexPrepareStmt(tls, p, p+104, Xsqlite3_mprintf(tls, __ccgo_ts+39037, libc.VaList(bp+8, (*TFts5Config)(unsafe.Pointer(pConfig)).FzDb, (*TFts5Config)(unsafe.Pointer(pConfig)).FzName)))
	}
	if (*TFts5Index)(unsafe.Pointer(p)).Frc == SQLITE_OK {
		Xsqlite3_bind_int(tls, (*TFts5Index)(unsafe.Pointer(p)).FpIdxDeleter, int32(1), iSegid)
		Xsqlite3_step(tls, (*TFts5Index)(unsafe.Pointer(p)).FpIdxDeleter)
		(*TFts5Index)(unsafe.Pointer(p)).Frc = Xsqlite3_reset(tls, (*TFts5Index)(unsafe.Pointer(p)).FpIdxDeleter)
	}
}

// C documentation
//
//	/*
//	** INSERT OR REPLACE a record into the %_data table.
//	*/
func _fts5DataWrite(tls *libc.TLS, p uintptr, iRowid Ti64, pData uintptr, nData int32) {
	bp := tls.Alloc(32)
	defer tls.Free(32)
	var pConfig uintptr
	_ = pConfig
	if (*TFts5Index)(unsafe.Pointer(p)).Frc != SQLITE_OK {
		return
	}
	if (*TFts5Index)(unsafe.Pointer(p)).FpWriter == uintptr(0) {
		pConfig = (*TFts5Index)(unsafe.Pointer(p)).FpConfig
		_fts5IndexPrepareStmt(tls, p, p+80, Xsqlite3_mprintf(tls, __ccgo_ts+38937, libc.VaList(bp+8, (*TFts5Config)(unsafe.Pointer(pConfig)).FzDb, (*TFts5Config)(unsafe.Pointer(pConfig)).FzName)))
		if (*TFts5Index)(unsafe.Pointer(p)).Frc != 0 {
			return
		}
	}
	Xsqlite3_bind_int64(tls, (*TFts5Index)(unsafe.Pointer(p)).FpWriter, int32(1), iRowid)
	Xsqlite3_bind_blob(tls, (*TFts5Index)(unsafe.Pointer(p)).FpWriter, int32(2), pData, nData, libc.UintptrFromInt32(0))
	Xsqlite3_step(tls, (*TFts5Index)(unsafe.Pointer(p)).FpWriter)
	(*TFts5Index)(unsafe.Pointer(p)).Frc = Xsqlite3_reset(tls, (*TFts5Index)(unsafe.Pointer(p)).FpWriter)
	Xsqlite3_bind_null(tls, (*TFts5Index)(unsafe.Pointer(p)).FpWriter, int32(2))
}

// C documentation
//
//	/*
//	** Argument pVal is the text of a full-text search expression. It may or
//	** may not have been wrapped by fts5_locale(). This function extracts
//	** the text of the expression, and sets output variable (*pzText) to
//	** point to a nul-terminated buffer containing the expression.
//	**
//	** If pVal was an fts5_locale() value, then sqlite3Fts5SetLocale() is called
//	** to set the tokenizer to use the specified locale.
//	**
//	** If output variable (*pbFreeAndReset) is set to true, then the caller
//	** is required to (a) call sqlite3Fts5ClearLocale() to reset the tokenizer
//	** locale, and (b) call sqlite3_free() to free (*pzText).
//	*/
func _fts5ExtractExprText(tls *libc.TLS, pConfig uintptr, pVal uintptr, pzText uintptr, pbFreeAndReset uintptr) (r int32) {
	bp := tls.Alloc(64)
	defer tls.Free(64)
	var _ /* nLoc at bp+32 */ int32
	var _ /* nText at bp+16 */ int32
	var _ /* pLoc at bp+24 */ uintptr
	var _ /* pText at bp+8 */ uintptr
	var _ /* rc at bp+0 */ int32
	**(**int32)(__ccgo_up(bp)) = SQLITE_OK
	if _sqlite3Fts5IsLocaleValue(tls, pConfig, pVal) != 0 {
		**(**uintptr)(__ccgo_up(bp + 8)) = uintptr(0)
		**(**int32)(__ccgo_up(bp + 16)) = 0
		**(**uintptr)(__ccgo_up(bp + 24)) = uintptr(0)
		**(**int32)(__ccgo_up(bp + 32)) = 0
		**(**int32)(__ccgo_up(bp)) = _sqlite3Fts5DecodeLocaleValue(tls, pVal, bp+8, bp+16, bp+24, bp+32)
		**(**uintptr)(__ccgo_up(pzText)) = _sqlite3Fts5Mprintf(tls, bp, __ccgo_ts+12039, libc.VaList(bp+48, **(**int32)(__ccgo_up(bp + 16)), **(**uintptr)(__ccgo_up(bp + 8))))
		if **(**int32)(__ccgo_up(bp)) == SQLITE_OK {
			_sqlite3Fts5SetLocale(tls, pConfig, **(**uintptr)(__ccgo_up(bp + 24)), **(**int32)(__ccgo_up(bp + 32)))
		}
		**(**int32)(__ccgo_up(pbFreeAndReset)) = int32(1)
	} else {
		**(**uintptr)(__ccgo_up(pzText)) = Xsqlite3_value_text(tls, pVal)
		**(**int32)(__ccgo_up(pbFreeAndReset)) = 0
	}
	return **(**int32)(__ccgo_up(bp))
}

func _fts5FindRankFunction(tls *libc.TLS, pCsr uintptr) (r int32) {
	bp := tls.Alloc(32)
	defer tls.Free(32)
	var i int32
	var nByte Tsqlite3_int64
	var pAux, pConfig, pTab, zRank, zRankArgs, zSql uintptr
	var _ /* pStmt at bp+8 */ uintptr
	var _ /* rc at bp+0 */ int32
	_, _, _, _, _, _, _, _ = i, nByte, pAux, pConfig, pTab, zRank, zRankArgs, zSql
	pTab = (*TFts5Cursor)(unsafe.Pointer(pCsr)).Fbase.FpVtab
	pConfig = (*TFts5FullTable)(unsafe.Pointer(pTab)).Fp.FpConfig
	**(**int32)(__ccgo_up(bp)) = SQLITE_OK
	pAux = uintptr(0)
	zRank = (*TFts5Cursor)(unsafe.Pointer(pCsr)).FzRank
	zRankArgs = (*TFts5Cursor)(unsafe.Pointer(pCsr)).FzRankArgs
	if zRankArgs != 0 {
		zSql = _sqlite3Fts5Mprintf(tls, bp, __ccgo_ts+39842, libc.VaList(bp+24, zRankArgs))
		if zSql != 0 {
			**(**uintptr)(__ccgo_up(bp + 8)) = uintptr(0)
			**(**int32)(__ccgo_up(bp)) = Xsqlite3_prepare_v3(tls, (*TFts5Config)(unsafe.Pointer(pConfig)).Fdb, zSql, -int32(1), uint32(SQLITE_PREPARE_PERSISTENT), bp+8, uintptr(0))
			Xsqlite3_free(tls, zSql)
			if **(**int32)(__ccgo_up(bp)) == SQLITE_OK {
				if int32(SQLITE_ROW) == Xsqlite3_step(tls, **(**uintptr)(__ccgo_up(bp + 8))) {
					(*TFts5Cursor)(unsafe.Pointer(pCsr)).FnRankArg = Xsqlite3_column_count(tls, **(**uintptr)(__ccgo_up(bp + 8)))
					nByte = libc.Int64FromUint64(uint64(8) * libc.Uint64FromInt32((*TFts5Cursor)(unsafe.Pointer(pCsr)).FnRankArg))
					(*TFts5Cursor)(unsafe.Pointer(pCsr)).FapRankArg = _sqlite3Fts5MallocZero(tls, bp, nByte)
					if **(**int32)(__ccgo_up(bp)) == SQLITE_OK {
						i = 0
						for {
							if !(i < (*TFts5Cursor)(unsafe.Pointer(pCsr)).FnRankArg) {
								break
							}
							**(**uintptr)(__ccgo_up((*TFts5Cursor)(unsafe.Pointer(pCsr)).FapRankArg + uintptr(i)*8)) = Xsqlite3_column_value(tls, **(**uintptr)(__ccgo_up(bp + 8)), i)
							goto _1
						_1:
							;
							i = i + 1
						}
					}
					(*TFts5Cursor)(unsafe.Pointer(pCsr)).FpRankArgStmt = **(**uintptr)(__ccgo_up(bp + 8))
				} else {
					**(**int32)(__ccgo_up(bp)) = Xsqlite3_finalize(tls, **(**uintptr)(__ccgo_up(bp + 8)))
				}
			}
		}
	}
	if **(**int32)(__ccgo_up(bp)) == SQLITE_OK {
		pAux = _fts5FindAuxiliary(tls, pTab, zRank)
		if pAux == uintptr(0) {
			(*TFts5FullTable)(unsafe.Pointer(pTab)).Fp.Fbase.FzErrMsg = Xsqlite3_mprintf(tls, __ccgo_ts+39852, libc.VaList(bp+24, zRank))
			**(**int32)(__ccgo_up(bp)) = int32(SQLITE_ERROR)
		}
	}
	(*TFts5Cursor)(unsafe.Pointer(pCsr)).FpRank = pAux
	return **(**int32)(__ccgo_up(bp))
}

// C documentation
//
//	/*
//	** This is called as part of flushing a delete to disk in 'secure-delete'
//	** mode. It edits the segments within the database described by argument
//	** pStruct to remove the entries for term zTerm, rowid iRowid.
//	**
//	** Return SQLITE_OK if successful, or an SQLite error code if an error
//	** has occurred. Any error code is also stored in the Fts5Index handle.
//	*/
func _fts5FlushSecureDelete(tls *libc.TLS, p uintptr, pStruct uintptr, zTerm uintptr, nTerm int32, iRowid Ti64) (r int32) {
	bp := tls.Alloc(48)
	defer tls.Free(48)
	var f, rc int32
	var iThis Ti64
	var pConfig, pSeg uintptr
	var _ /* pIter at bp+0 */ uintptr
	var _ /* pStmt at bp+8 */ uintptr
	_, _, _, _, _ = f, iThis, pConfig, pSeg, rc
	f = int32(FTS5INDEX_QUERY_SKIPHASH)
	**(**uintptr)(__ccgo_up(bp)) = uintptr(0) /* Used to find term instance */
	/* If the version number has not been set to SECUREDELETE, do so now. */
	if (*TFts5Config)(unsafe.Pointer((*TFts5Index)(unsafe.Pointer(p)).FpConfig)).FiVersion != int32(FTS5_CURRENT_VERSION_SECUREDELETE) {
		pConfig = (*TFts5Index)(unsafe.Pointer(p)).FpConfig
		**(**uintptr)(__ccgo_up(bp + 8)) = uintptr(0)
		_fts5IndexPrepareStmt(tls, p, bp+8, Xsqlite3_mprintf(tls, __ccgo_ts+39435, libc.VaList(bp+24, (*TFts5Config)(unsafe.Pointer(pConfig)).FzDb, (*TFts5Config)(unsafe.Pointer(pConfig)).FzName, int32(FTS5_CURRENT_VERSION_SECUREDELETE))))
		if (*TFts5Index)(unsafe.Pointer(p)).Frc == SQLITE_OK {
			Xsqlite3_step(tls, **(**uintptr)(__ccgo_up(bp + 8)))
			rc = Xsqlite3_finalize(tls, **(**uintptr)(__ccgo_up(bp + 8)))
			if (*TFts5Index)(unsafe.Pointer(p)).Frc == SQLITE_OK {
				(*TFts5Index)(unsafe.Pointer(p)).Frc = rc
			}
			(*TFts5Config)(unsafe.Pointer(pConfig)).FiCookie = (*TFts5Config)(unsafe.Pointer(pConfig)).FiCookie + 1
			(*TFts5Config)(unsafe.Pointer(pConfig)).FiVersion = int32(FTS5_CURRENT_VERSION_SECUREDELETE)
		}
	}
	_fts5MultiIterNew(tls, p, pStruct, f, uintptr(0), zTerm, nTerm, -int32(1), 0, bp)
	if _fts5MultiIterEof(tls, p, **(**uintptr)(__ccgo_up(bp))) == 0 {
		iThis = _fts5MultiIterRowid(tls, **(**uintptr)(__ccgo_up(bp)))
		if iThis < iRowid {
			_fts5MultiIterNextFrom(tls, p, **(**uintptr)(__ccgo_up(bp)), iRowid)
		}
		if (*TFts5Index)(unsafe.Pointer(p)).Frc == SQLITE_OK && _fts5MultiIterEof(tls, p, **(**uintptr)(__ccgo_up(bp))) == 0 && iRowid == _fts5MultiIterRowid(tls, **(**uintptr)(__ccgo_up(bp))) {
			pSeg = **(**uintptr)(__ccgo_up(bp)) + 104 + uintptr((**(**TFts5CResult)(__ccgo_up((*TFts5Iter)(unsafe.Pointer(**(**uintptr)(__ccgo_up(bp)))).FaFirst + 1*4))).FiFirst)*128
			_fts5DoSecureDelete(tls, p, pSeg)
		}
	}
	_fts5MultiIterFree(tls, **(**uintptr)(__ccgo_up(bp)))
	return (*TFts5Index)(unsafe.Pointer(p)).Frc
}

// C documentation
//
//	/*
//	** Implementation of the fts5() function used by clients to obtain the
//	** API pointer.
//	*/
func _fts5Fts5Func(tls *libc.TLS, pCtx uintptr, nArg int32, apArg uintptr) {
	var pGlobal, ppApi uintptr
	_, _ = pGlobal, ppApi
	pGlobal = Xsqlite3_user_data(tls, pCtx)
	_ = nArg
	ppApi = Xsqlite3_value_pointer(tls, **(**uintptr)(__ccgo_up(apArg)), __ccgo_ts+40485)
	if ppApi != 0 {
		**(**uintptr)(__ccgo_up(ppApi)) = pGlobal
	}
}

// C documentation
//
//	/*
//	** Implementation of fts5_get_locale() function.
//	*/
func _fts5GetLocaleFunction(tls *libc.TLS, pApi uintptr, pFts uintptr, pCtx uintptr, nVal int32, apVal uintptr) {
	bp := tls.Alloc(16)
	defer tls.Free(16)
	var eType, iCol, rc int32
	var z, z1 uintptr
	var _ /* nLocale at bp+8 */ int32
	var _ /* zLocale at bp+0 */ uintptr
	_, _, _, _, _ = eType, iCol, rc, z, z1
	iCol = 0
	eType = 0
	rc = SQLITE_OK
	**(**uintptr)(__ccgo_up(bp)) = uintptr(0)
	**(**int32)(__ccgo_up(bp + 8)) = 0
	/* xColumnLocale() must be available */
	if nVal != int32(1) {
		z = __ccgo_ts + 37243
		Xsqlite3_result_error(tls, pCtx, z, -int32(1))
		return
	}
	eType = Xsqlite3_value_numeric_type(tls, **(**uintptr)(__ccgo_up(apVal)))
	if eType != int32(SQLITE_INTEGER) {
		z1 = __ccgo_ts + 37299
		Xsqlite3_result_error(tls, pCtx, z1, -int32(1))
		return
	}
	iCol = Xsqlite3_value_int(tls, **(**uintptr)(__ccgo_up(apVal)))
	if iCol < 0 || iCol >= (*(*func(*libc.TLS, uintptr) int32)(unsafe.Pointer(&struct{ uintptr }{(*TFts5ExtensionApi)(unsafe.Pointer(pApi)).FxColumnCount})))(tls, pFts) {
		Xsqlite3_result_error_code(tls, pCtx, int32(SQLITE_RANGE))
		return
	}
	rc = (*(*func(*libc.TLS, uintptr, int32, uintptr, uintptr) int32)(unsafe.Pointer(&struct{ uintptr }{(*TFts5ExtensionApi)(unsafe.Pointer(pApi)).FxColumnLocale})))(tls, pFts, iCol, bp, bp+8)
	if rc != SQLITE_OK {
		Xsqlite3_result_error_code(tls, pCtx, rc)
		return
	}
	Xsqlite3_result_text(tls, pCtx, **(**uintptr)(__ccgo_up(bp)), **(**int32)(__ccgo_up(bp + 8)), uintptr(-libc.Int32FromInt32(1)))
}

// C documentation
//
//	/*
//	** Append text to the HighlightContext output string - p->zOut. Argument
//	** z points to a buffer containing n bytes of text to append. If n is
//	** negative, everything up until the first '\0' is appended to the output.
//	**
//	** If *pRc is set to any value other than SQLITE_OK when this function is
//	** called, it is a no-op. If an error (i.e. an OOM condition) is encountered,
//	** *pRc is set to an error code before returning.
//	*/
func _fts5HighlightAppend(tls *libc.TLS, pRc uintptr, p uintptr, z uintptr, n int32) {
	bp := tls.Alloc(32)
	defer tls.Free(32)
	if **(**int32)(__ccgo_up(pRc)) == SQLITE_OK && z != 0 {
		if n < 0 {
			n = libc.Int32FromUint64(libc.Xstrlen(tls, z))
		}
		(*THighlightContext)(unsafe.Pointer(p)).FzOut = Xsqlite3_mprintf(tls, __ccgo_ts+37138, libc.VaList(bp+8, (*THighlightContext)(unsafe.Pointer(p)).FzOut, n, z))
		if (*THighlightContext)(unsafe.Pointer(p)).FzOut == uintptr(0) {
			**(**int32)(__ccgo_up(pRc)) = int32(SQLITE_NOMEM)
		}
	}
}

// C documentation
//
//	/*
//	** Implementation of highlight() function.
//	*/
func _fts5HighlightFunction(tls *libc.TLS, pApi uintptr, pFts uintptr, pCtx uintptr, nVal int32, apVal uintptr) {
	bp := tls.Alloc(128)
	defer tls.Free(128)
	var iCol int32
	var zErr uintptr
	var _ /* ctx at bp+0 */ THighlightContext
	var _ /* nLoc at bp+120 */ int32
	var _ /* pLoc at bp+112 */ uintptr
	var _ /* rc at bp+104 */ int32
	_, _ = iCol, zErr
	if nVal != int32(3) {
		zErr = __ccgo_ts + 37145
		Xsqlite3_result_error(tls, pCtx, zErr, -int32(1))
		return
	}
	iCol = Xsqlite3_value_int(tls, **(**uintptr)(__ccgo_up(apVal)))
	libc.Xmemset(tls, bp, 0, uint64(104))
	(**(**THighlightContext)(__ccgo_up(bp))).FzOpen = Xsqlite3_value_text(tls, **(**uintptr)(__ccgo_up(apVal + 1*8)))
	(**(**THighlightContext)(__ccgo_up(bp))).FzClose = Xsqlite3_value_text(tls, **(**uintptr)(__ccgo_up(apVal + 2*8)))
	(**(**THighlightContext)(__ccgo_up(bp))).FiRangeEnd = -int32(1)
	**(**int32)(__ccgo_up(bp + 104)) = (*(*func(*libc.TLS, uintptr, int32, uintptr, uintptr) int32)(unsafe.Pointer(&struct{ uintptr }{(*TFts5ExtensionApi)(unsafe.Pointer(pApi)).FxColumnText})))(tls, pFts, iCol, bp+24, bp+32)
	if **(**int32)(__ccgo_up(bp + 104)) == int32(SQLITE_RANGE) {
		Xsqlite3_result_text(tls, pCtx, __ccgo_ts+1693, -int32(1), libc.UintptrFromInt32(0))
		**(**int32)(__ccgo_up(bp + 104)) = SQLITE_OK
	} else {
		if (**(**THighlightContext)(__ccgo_up(bp))).FzIn != 0 {
			**(**uintptr)(__ccgo_up(bp + 112)) = uintptr(0) /* Locale of column iCol */
			**(**int32)(__ccgo_up(bp + 120)) = 0            /* Size of pLoc in bytes */
			if **(**int32)(__ccgo_up(bp + 104)) == SQLITE_OK {
				**(**int32)(__ccgo_up(bp + 104)) = _fts5CInstIterInit(tls, pApi, pFts, iCol, bp+40)
			}
			if **(**int32)(__ccgo_up(bp + 104)) == SQLITE_OK {
				**(**int32)(__ccgo_up(bp + 104)) = (*(*func(*libc.TLS, uintptr, int32, uintptr, uintptr) int32)(unsafe.Pointer(&struct{ uintptr }{(*TFts5ExtensionApi)(unsafe.Pointer(pApi)).FxColumnLocale})))(tls, pFts, iCol, bp+112, bp+120)
			}
			if **(**int32)(__ccgo_up(bp + 104)) == SQLITE_OK {
				**(**int32)(__ccgo_up(bp + 104)) = (*(*func(*libc.TLS, uintptr, uintptr, int32, uintptr, int32, uintptr, uintptr) int32)(unsafe.Pointer(&struct{ uintptr }{(*TFts5ExtensionApi)(unsafe.Pointer(pApi)).FxTokenize_v2})))(tls, pFts, (**(**THighlightContext)(__ccgo_up(bp))).FzIn, (**(**THighlightContext)(__ccgo_up(bp))).FnIn, **(**uintptr)(__ccgo_up(bp + 112)), **(**int32)(__ccgo_up(bp + 120)), bp, __ccgo_fp(_fts5HighlightCb))
			}
			if (**(**THighlightContext)(__ccgo_up(bp))).FbOpen != 0 {
				_fts5HighlightAppend(tls, bp+104, bp, (**(**THighlightContext)(__ccgo_up(bp))).FzClose, -int32(1))
			}
			_fts5HighlightAppend(tls, bp+104, bp, (**(**THighlightContext)(__ccgo_up(bp))).FzIn+uintptr((**(**THighlightContext)(__ccgo_up(bp))).FiOff), (**(**THighlightContext)(__ccgo_up(bp))).FnIn-(**(**THighlightContext)(__ccgo_up(bp))).FiOff)
			if **(**int32)(__ccgo_up(bp + 104)) == SQLITE_OK {
				Xsqlite3_result_text(tls, pCtx, (**(**THighlightContext)(__ccgo_up(bp))).FzOut, -int32(1), uintptr(-libc.Int32FromInt32(1)))
			}
			Xsqlite3_free(tls, (**(**THighlightContext)(__ccgo_up(bp))).FzOut)
		}
	}
	if **(**int32)(__ccgo_up(bp + 104)) != SQLITE_OK {
		Xsqlite3_result_error_code(tls, pCtx, **(**int32)(__ccgo_up(bp + 104)))
	}
}

/*
** End of highlight() implementation.
**************************************************************************/

// C documentation
//
//	/*
//	** SQL used by fts5SegIterNextInit() to find the page to open.
//	*/
func _fts5IdxNextStmt(tls *libc.TLS, p uintptr) (r uintptr) {
	bp := tls.Alloc(32)
	defer tls.Free(32)
	var pConfig uintptr
	_ = pConfig
	if (*TFts5Index)(unsafe.Pointer(p)).FpIdxNextSelect == uintptr(0) {
		pConfig = (*TFts5Index)(unsafe.Pointer(p)).FpConfig
		_fts5IndexPrepareStmt(tls, p, p+120, Xsqlite3_mprintf(tls, __ccgo_ts+39235, libc.VaList(bp+8, (*TFts5Config)(unsafe.Pointer(pConfig)).FzDb, (*TFts5Config)(unsafe.Pointer(pConfig)).FzName)))
	}
	return (*TFts5Index)(unsafe.Pointer(p)).FpIdxNextSelect
}

func _fts5IdxSelectStmt(tls *libc.TLS, p uintptr) (r uintptr) {
	bp := tls.Alloc(32)
	defer tls.Free(32)
	var pConfig uintptr
	_ = pConfig
	if (*TFts5Index)(unsafe.Pointer(p)).FpIdxSelect == uintptr(0) {
		pConfig = (*TFts5Index)(unsafe.Pointer(p)).FpConfig
		_fts5IndexPrepareStmt(tls, p, p+112, Xsqlite3_mprintf(tls, __ccgo_ts+39151, libc.VaList(bp+8, (*TFts5Config)(unsafe.Pointer(pConfig)).FzDb, (*TFts5Config)(unsafe.Pointer(pConfig)).FzName)))
	}
	return (*TFts5Index)(unsafe.Pointer(p)).FpIdxSelect
}

func _fts5IndexCorruptIdx(tls *libc.TLS, pIdx uintptr) (r int32) {
	bp := tls.Alloc(16)
	defer tls.Free(16)
	(*TFts5Index)(unsafe.Pointer(pIdx)).Frc = libc.Int32FromInt32(SQLITE_CORRUPT) | libc.Int32FromInt32(1)<<libc.Int32FromInt32(8)
	_sqlite3Fts5ConfigErrmsg(tls, (*TFts5Index)(unsafe.Pointer(pIdx)).FpConfig, __ccgo_ts+38900, libc.VaList(bp+8, (*TFts5Config)(unsafe.Pointer((*TFts5Index)(unsafe.Pointer(pIdx)).FpConfig)).FzName))
	return libc.Int32FromInt32(SQLITE_CORRUPT) | libc.Int32FromInt32(1)<<libc.Int32FromInt32(8)
}

/* Size (in bytes) of an Fts5DlidxIter object with up to N levels */

func _fts5IndexCorruptIter(tls *libc.TLS, pIdx uintptr, pIter uintptr) (r int32) {
	bp := tls.Alloc(32)
	defer tls.Free(32)
	(*TFts5Index)(unsafe.Pointer(pIdx)).Frc = libc.Int32FromInt32(SQLITE_CORRUPT) | libc.Int32FromInt32(1)<<libc.Int32FromInt32(8)
	_sqlite3Fts5ConfigErrmsg(tls, (*TFts5Index)(unsafe.Pointer(pIdx)).FpConfig, __ccgo_ts+38848, libc.VaList(bp+8, (*TFts5SegIter)(unsafe.Pointer(pIter)).FiLeafPgno, (*TFts5StructureSegment)(unsafe.Pointer((*TFts5SegIter)(unsafe.Pointer(pIter)).FpSeg)).FiSegid, (*TFts5Config)(unsafe.Pointer((*TFts5Index)(unsafe.Pointer(pIdx)).FpConfig)).FzName))
	return libc.Int32FromInt32(SQLITE_CORRUPT) | libc.Int32FromInt32(1)<<libc.Int32FromInt32(8)
}

func _fts5IndexCorruptRowid(tls *libc.TLS, pIdx uintptr, iRowid Ti64) (r int32) {
	bp := tls.Alloc(32)
	defer tls.Free(32)
	(*TFts5Index)(unsafe.Pointer(pIdx)).Frc = libc.Int32FromInt32(SQLITE_CORRUPT) | libc.Int32FromInt32(1)<<libc.Int32FromInt32(8)
	_sqlite3Fts5ConfigErrmsg(tls, (*TFts5Index)(unsafe.Pointer(pIdx)).FpConfig, __ccgo_ts+38791, libc.VaList(bp+8, iRowid, (*TFts5Config)(unsafe.Pointer((*TFts5Index)(unsafe.Pointer(pIdx)).FpConfig)).FzName))
	return libc.Int32FromInt32(SQLITE_CORRUPT) | libc.Int32FromInt32(1)<<libc.Int32FromInt32(8)
}

func _fts5IndexDataVersion(tls *libc.TLS, p uintptr) (r Ti64) {
	bp := tls.Alloc(16)
	defer tls.Free(16)
	var iVersion Ti64
	_ = iVersion
	iVersion = 0
	if (*TFts5Index)(unsafe.Pointer(p)).Frc == SQLITE_OK {
		if (*TFts5Index)(unsafe.Pointer(p)).FpDataVersion == uintptr(0) {
			(*TFts5Index)(unsafe.Pointer(p)).Frc = _fts5IndexPrepareStmt(tls, p, p+144, Xsqlite3_mprintf(tls, __ccgo_ts+39128, libc.VaList(bp+8, (*TFts5Config)(unsafe.Pointer((*TFts5Index)(unsafe.Pointer(p)).FpConfig)).FzDb)))
			if (*TFts5Index)(unsafe.Pointer(p)).Frc != 0 {
				return 0
			}
		}
		if int32(SQLITE_ROW) == Xsqlite3_step(tls, (*TFts5Index)(unsafe.Pointer(p)).FpDataVersion) {
			iVersion = Xsqlite3_column_int64(tls, (*TFts5Index)(unsafe.Pointer(p)).FpDataVersion, 0)
		}
		(*TFts5Index)(unsafe.Pointer(p)).Frc = Xsqlite3_reset(tls, (*TFts5Index)(unsafe.Pointer(p)).FpDataVersion)
	}
	return iVersion
}

func _fts5IndexIntegrityCheckSegment(tls *libc.TLS, p uintptr, pSeg uintptr) {
	bp := tls.Alloc(64)
	defer tls.Free(64)
	var bIdxDlidx, bSecureDelete, iDlidxPrevLeaf, iIdxLeaf, iIdxPrevLeaf, iOff, iPg, iPrevLeaf, iRowidOff, iRowidOff1, iSegid, nIdxTerm, rc2, res, v1, v2, v3 int32
	var iDlRowid, iKey, iRow Ti64
	var pConfig, pDlidx, pLeaf, zIdxTerm uintptr
	var _ /* iRowid at bp+16 */ Ti64
	var _ /* nTerm at bp+8 */ int32
	var _ /* pStmt at bp+0 */ uintptr
	_, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _ = bIdxDlidx, bSecureDelete, iDlRowid, iDlidxPrevLeaf, iIdxLeaf, iIdxPrevLeaf, iKey, iOff, iPg, iPrevLeaf, iRow, iRowidOff, iRowidOff1, iSegid, nIdxTerm, pConfig, pDlidx, pLeaf, rc2, res, zIdxTerm, v1, v2, v3
	pConfig = (*TFts5Index)(unsafe.Pointer(p)).FpConfig
	bSecureDelete = libc.BoolInt32((*TFts5Config)(unsafe.Pointer(pConfig)).FiVersion == int32(FTS5_CURRENT_VERSION_SECUREDELETE))
	**(**uintptr)(__ccgo_up(bp)) = uintptr(0)
	iIdxPrevLeaf = (*TFts5StructureSegment)(unsafe.Pointer(pSeg)).FpgnoFirst - int32(1)
	iDlidxPrevLeaf = (*TFts5StructureSegment)(unsafe.Pointer(pSeg)).FpgnoLast
	if (*TFts5StructureSegment)(unsafe.Pointer(pSeg)).FpgnoFirst == 0 {
		return
	}
	_fts5IndexPrepareStmt(tls, p, bp, Xsqlite3_mprintf(tls, __ccgo_ts+39575, libc.VaList(bp+32, (*TFts5Config)(unsafe.Pointer(pConfig)).FzDb, (*TFts5Config)(unsafe.Pointer(pConfig)).FzName, (*TFts5StructureSegment)(unsafe.Pointer(pSeg)).FiSegid)))
	/* Iterate through the b-tree hierarchy.  */
	for (*TFts5Index)(unsafe.Pointer(p)).Frc == SQLITE_OK && int32(SQLITE_ROW) == Xsqlite3_step(tls, **(**uintptr)(__ccgo_up(bp))) { /* Data for this leaf */
		zIdxTerm = Xsqlite3_column_blob(tls, **(**uintptr)(__ccgo_up(bp)), int32(1))
		nIdxTerm = Xsqlite3_column_bytes(tls, **(**uintptr)(__ccgo_up(bp)), int32(1))
		iIdxLeaf = Xsqlite3_column_int(tls, **(**uintptr)(__ccgo_up(bp)), int32(2))
		bIdxDlidx = Xsqlite3_column_int(tls, **(**uintptr)(__ccgo_up(bp)), int32(3))
		/* If the leaf in question has already been trimmed from the segment,
		 ** ignore this b-tree entry. Otherwise, load it into memory. */
		if iIdxLeaf < (*TFts5StructureSegment)(unsafe.Pointer(pSeg)).FpgnoFirst {
			continue
		}
		iRow = int64((*TFts5StructureSegment)(unsafe.Pointer(pSeg)).FiSegid)<<(libc.Int32FromInt32(FTS5_DATA_PAGE_B)+libc.Int32FromInt32(FTS5_DATA_HEIGHT_B)+libc.Int32FromInt32(FTS5_DATA_DLI_B)) + int64(libc.Int32FromInt32(0))<<(libc.Int32FromInt32(FTS5_DATA_PAGE_B)+libc.Int32FromInt32(FTS5_DATA_HEIGHT_B)) + int64(libc.Int32FromInt32(0))<<libc.Int32FromInt32(FTS5_DATA_PAGE_B) + int64(iIdxLeaf)
		pLeaf = _fts5LeafRead(tls, p, iRow)
		if pLeaf == uintptr(0) {
			break
		}
		/* Check that the leaf contains at least one term, and that it is equal
		 ** to or larger than the split-key in zIdxTerm.  Also check that if there
		 ** is also a rowid pointer within the leaf page header, it points to a
		 ** location before the term.  */
		if (*TFts5Data)(unsafe.Pointer(pLeaf)).Fnn <= (*TFts5Data)(unsafe.Pointer(pLeaf)).FszLeaf {
			if nIdxTerm == 0 && (*TFts5Config)(unsafe.Pointer(pConfig)).FiVersion == int32(FTS5_CURRENT_VERSION_SECUREDELETE) && (*TFts5Data)(unsafe.Pointer(pLeaf)).Fnn == (*TFts5Data)(unsafe.Pointer(pLeaf)).FszLeaf && (*TFts5Data)(unsafe.Pointer(pLeaf)).Fnn == int32(4) {
				/* special case - the very first page in a segment keeps its %_idx
				 ** entry even if all the terms are removed from it by secure-delete
				 ** operations. */
			} else {
				_fts5IndexCorruptRowid(tls, p, iRow)
			}
		} else { /* Comparison of term and split-key */
			iOff = _fts5LeafFirstTermOff(tls, pLeaf)
			iRowidOff = libc.Int32FromUint16(_fts5GetU16(tls, (*TFts5Data)(unsafe.Pointer(pLeaf)).Fp))
			if iRowidOff >= iOff || iOff >= (*TFts5Data)(unsafe.Pointer(pLeaf)).FszLeaf {
				_fts5IndexCorruptRowid(tls, p, iRow)
			} else {
				iOff = iOff + _sqlite3Fts5GetVarint32(tls, (*TFts5Data)(unsafe.Pointer(pLeaf)).Fp+uintptr(iOff), bp+8)
				if iOff+**(**int32)(__ccgo_up(bp + 8)) > (*TFts5Data)(unsafe.Pointer(pLeaf)).FszLeaf {
					_fts5IndexCorruptRowid(tls, p, iRow)
				} else {
					if **(**int32)(__ccgo_up(bp + 8)) < nIdxTerm {
						v2 = **(**int32)(__ccgo_up(bp + 8))
					} else {
						v2 = nIdxTerm
					}
					if v2 <= 0 {
						v1 = 0
					} else {
						if **(**int32)(__ccgo_up(bp + 8)) < nIdxTerm {
							v3 = **(**int32)(__ccgo_up(bp + 8))
						} else {
							v3 = nIdxTerm
						}
						v1 = libc.Xmemcmp(tls, (*TFts5Data)(unsafe.Pointer(pLeaf)).Fp+uintptr(iOff), zIdxTerm, libc.Uint64FromInt32(v3))
					}
					res = v1
					if res == 0 {
						res = **(**int32)(__ccgo_up(bp + 8)) - nIdxTerm
					}
					if res < 0 {
						_fts5IndexCorruptRowid(tls, p, iRow)
					}
				}
			}
			_fts5IntegrityCheckPgidx(tls, p, iRow, pLeaf)
		}
		_fts5DataRelease(tls, pLeaf)
		if (*TFts5Index)(unsafe.Pointer(p)).Frc != 0 {
			break
		}
		/* Now check that the iter.nEmpty leaves following the current leaf
		 ** (a) exist and (b) contain no terms. */
		_fts5IndexIntegrityCheckEmpty(tls, p, pSeg, iIdxPrevLeaf+int32(1), iDlidxPrevLeaf+int32(1), iIdxLeaf-int32(1))
		if (*TFts5Index)(unsafe.Pointer(p)).Frc != 0 {
			break
		}
		/* If there is a doclist-index, check that it looks right. */
		if bIdxDlidx != 0 {
			pDlidx = uintptr(0) /* For iterating through doclist index */
			iPrevLeaf = iIdxLeaf
			iSegid = (*TFts5StructureSegment)(unsafe.Pointer(pSeg)).FiSegid
			iPg = 0
			pDlidx = _fts5DlidxIterInit(tls, p, 0, iSegid, iIdxLeaf)
			for {
				if !(_fts5DlidxIterEof(tls, p, pDlidx) == 0) {
					break
				}
				/* Check any rowid-less pages that occur before the current leaf. */
				iPg = iPrevLeaf + int32(1)
				for {
					if !(iPg < _fts5DlidxIterPgno(tls, pDlidx)) {
						break
					}
					iKey = int64(iSegid)<<(libc.Int32FromInt32(FTS5_DATA_PAGE_B)+libc.Int32FromInt32(FTS5_DATA_HEIGHT_B)+libc.Int32FromInt32(FTS5_DATA_DLI_B)) + int64(libc.Int32FromInt32(0))<<(libc.Int32FromInt32(FTS5_DATA_PAGE_B)+libc.Int32FromInt32(FTS5_DATA_HEIGHT_B)) + int64(libc.Int32FromInt32(0))<<libc.Int32FromInt32(FTS5_DATA_PAGE_B) + int64(iPg)
					pLeaf = _fts5LeafRead(tls, p, iKey)
					if pLeaf != 0 {
						if libc.Int32FromUint16(_fts5GetU16(tls, (*TFts5Data)(unsafe.Pointer(pLeaf)).Fp)) != 0 {
							_fts5IndexCorruptRowid(tls, p, iKey)
						}
						_fts5DataRelease(tls, pLeaf)
					}
					goto _5
				_5:
					;
					iPg = iPg + 1
				}
				iPrevLeaf = _fts5DlidxIterPgno(tls, pDlidx)
				/* Check that the leaf page indicated by the iterator really does
				 ** contain the rowid suggested by the same. */
				iKey = int64(iSegid)<<(libc.Int32FromInt32(FTS5_DATA_PAGE_B)+libc.Int32FromInt32(FTS5_DATA_HEIGHT_B)+libc.Int32FromInt32(FTS5_DATA_DLI_B)) + int64(libc.Int32FromInt32(0))<<(libc.Int32FromInt32(FTS5_DATA_PAGE_B)+libc.Int32FromInt32(FTS5_DATA_HEIGHT_B)) + int64(libc.Int32FromInt32(0))<<libc.Int32FromInt32(FTS5_DATA_PAGE_B) + int64(iPrevLeaf)
				pLeaf = _fts5LeafRead(tls, p, iKey)
				if pLeaf != 0 {
					iRowidOff1 = libc.Int32FromUint16(_fts5GetU16(tls, (*TFts5Data)(unsafe.Pointer(pLeaf)).Fp))
					if iRowidOff1 >= (*TFts5Data)(unsafe.Pointer(pLeaf)).FszLeaf {
						_fts5IndexCorruptRowid(tls, p, iKey)
					} else {
						if bSecureDelete == 0 || iRowidOff1 > 0 {
							iDlRowid = _fts5DlidxIterRowid(tls, pDlidx)
							_sqlite3Fts5GetVarint(tls, (*TFts5Data)(unsafe.Pointer(pLeaf)).Fp+uintptr(iRowidOff1), bp+16)
							if **(**Ti64)(__ccgo_up(bp + 16)) < iDlRowid || bSecureDelete == 0 && **(**Ti64)(__ccgo_up(bp + 16)) != iDlRowid {
								_fts5IndexCorruptRowid(tls, p, iKey)
							}
						}
					}
					_fts5DataRelease(tls, pLeaf)
				}
				goto _4
			_4:
				;
				_fts5DlidxIterNext(tls, p, pDlidx)
			}
			iDlidxPrevLeaf = iPg
			_fts5DlidxIterFree(tls, pDlidx)
		} else {
			iDlidxPrevLeaf = (*TFts5StructureSegment)(unsafe.Pointer(pSeg)).FpgnoLast
			/* TODO: Check there is no doclist index */
		}
		iIdxPrevLeaf = iIdxLeaf
	}
	rc2 = Xsqlite3_finalize(tls, **(**uintptr)(__ccgo_up(bp)))
	if (*TFts5Index)(unsafe.Pointer(p)).Frc == SQLITE_OK {
		(*TFts5Index)(unsafe.Pointer(p)).Frc = rc2
	}
	/* Page iter.iLeaf must now be the rightmost leaf-page in the segment */
}

func _fts5Init(tls *libc.TLS, db uintptr) (r int32) {
	var p, pGlobal uintptr
	var rc int32
	_, _, _ = p, pGlobal, rc
	pGlobal = uintptr(0)
	pGlobal = Xsqlite3_malloc64(tls, uint64(112))
	if pGlobal == uintptr(0) {
		rc = int32(SQLITE_NOMEM)
	} else {
		p = pGlobal
		libc.Xmemset(tls, pGlobal, 0, uint64(112))
		(*TFts5Global)(unsafe.Pointer(pGlobal)).Fdb = db
		(*TFts5Global)(unsafe.Pointer(pGlobal)).Fapi.FiVersion = int32(3)
		(*TFts5Global)(unsafe.Pointer(pGlobal)).Fapi.FxCreateFunction = __ccgo_fp(_fts5CreateAux)
		(*TFts5Global)(unsafe.Pointer(pGlobal)).Fapi.FxCreateTokenizer = __ccgo_fp(_fts5CreateTokenizer)
		(*TFts5Global)(unsafe.Pointer(pGlobal)).Fapi.FxFindTokenizer = __ccgo_fp(_fts5FindTokenizer)
		(*TFts5Global)(unsafe.Pointer(pGlobal)).Fapi.FxCreateTokenizer_v2 = __ccgo_fp(_fts5CreateTokenizer_v2)
		(*TFts5Global)(unsafe.Pointer(pGlobal)).Fapi.FxFindTokenizer_v2 = __ccgo_fp(_fts5FindTokenizer_v2)
		/* Initialize pGlobal->aLocaleHdr[] to a 128-bit pseudo-random vector.
		 ** The constants below were generated randomly.  */
		Xsqlite3_randomness(tls, int32(16), pGlobal+96)
		**(**Tu32)(__ccgo_up(pGlobal + 96)) ^= uint32(0xF924976D)
		**(**Tu32)(__ccgo_up(pGlobal + 96 + 1*4)) ^= uint32(0x16596E13)
		**(**Tu32)(__ccgo_up(pGlobal + 96 + 2*4)) ^= uint32(0x7C80BEAA)
		**(**Tu32)(__ccgo_up(pGlobal + 96 + 3*4)) ^= uint32(0x9B03A67F)
		rc = Xsqlite3_create_module_v2(tls, db, __ccgo_ts+40705, uintptr(unsafe.Pointer(&_fts5Mod)), p, __ccgo_fp(_fts5ModuleDestroy))
		if rc == SQLITE_OK {
			rc = _sqlite3Fts5IndexInit(tls, db)
		}
		if rc == SQLITE_OK {
			rc = _sqlite3Fts5ExprInit(tls, pGlobal, db)
		}
		if rc == SQLITE_OK {
			rc = _sqlite3Fts5AuxInit(tls, pGlobal)
		}
		if rc == SQLITE_OK {
			rc = _sqlite3Fts5TokenizerInit(tls, pGlobal)
		}
		if rc == SQLITE_OK {
			rc = _sqlite3Fts5VocabInit(tls, pGlobal, db)
		}
		if rc == SQLITE_OK {
			rc = Xsqlite3_create_function(tls, db, __ccgo_ts+40705, int32(1), int32(SQLITE_UTF8), p, __ccgo_fp(_fts5Fts5Func), uintptr(0), uintptr(0))
		}
		if rc == SQLITE_OK {
			rc = Xsqlite3_create_function(tls, db, __ccgo_ts+40710, 0, libc.Int32FromInt32(SQLITE_UTF8)|libc.Int32FromInt32(SQLITE_DETERMINISTIC)|libc.Int32FromInt32(SQLITE_INNOCUOUS), p, __ccgo_fp(_fts5SourceIdFunc), uintptr(0), uintptr(0))
		}
		if rc == SQLITE_OK {
			rc = Xsqlite3_create_function(tls, db, __ccgo_ts+40725, int32(2), libc.Int32FromInt32(SQLITE_UTF8)|libc.Int32FromInt32(SQLITE_INNOCUOUS)|libc.Int32FromInt32(SQLITE_RESULT_SUBTYPE)|libc.Int32FromInt32(SQLITE_SUBTYPE), p, __ccgo_fp(_fts5LocaleFunc), uintptr(0), uintptr(0))
		}
		if rc == SQLITE_OK {
			rc = Xsqlite3_create_function(tls, db, __ccgo_ts+40737, int32(1), libc.Int32FromInt32(SQLITE_UTF8)|libc.Int32FromInt32(SQLITE_INNOCUOUS)|libc.Int32FromInt32(SQLITE_RESULT_SUBTYPE), p, __ccgo_fp(_fts5InsttokenFunc), uintptr(0), uintptr(0))
		}
	}
	/* If SQLITE_FTS5_ENABLE_TEST_MI is defined, assume that the file
	 ** fts5_test_mi.c is compiled and linked into the executable. And call
	 ** its entry point to enable the matchinfo() demo.  */
	return rc
}

// C documentation
//
//	/*
//	** Run an integrity check on the FTS5 data structures.  Return a string
//	** if anything is found amiss.  Return a NULL pointer if everything is
//	** OK.
//	*/
func _fts5IntegrityMethod(tls *libc.TLS, pVtab uintptr, zSchema uintptr, zTabname uintptr, isQuick int32, pzErr uintptr) (r int32) {
	bp := tls.Alloc(32)
	defer tls.Free(32)
	var pTab uintptr
	var rc, v1 int32
	_, _, _ = pTab, rc, v1
	pTab = pVtab
	_ = isQuick
	(*TFts5Config)(unsafe.Pointer((*TFts5FullTable)(unsafe.Pointer(pTab)).Fp.FpConfig)).FpzErrmsg = pzErr
	rc = _sqlite3Fts5StorageIntegrity(tls, (*TFts5FullTable)(unsafe.Pointer(pTab)).FpStorage, 0)
	if **(**uintptr)(__ccgo_up(pzErr)) == uintptr(0) && rc != SQLITE_OK {
		if rc&int32(0xff) == int32(SQLITE_CORRUPT) {
			**(**uintptr)(__ccgo_up(pzErr)) = Xsqlite3_mprintf(tls, __ccgo_ts+40596, libc.VaList(bp+8, zSchema, zTabname))
			if **(**uintptr)(__ccgo_up(pzErr)) != 0 {
				v1 = SQLITE_OK
			} else {
				v1 = int32(SQLITE_NOMEM)
			}
			rc = v1
		} else {
			**(**uintptr)(__ccgo_up(pzErr)) = Xsqlite3_mprintf(tls, __ccgo_ts+40642, libc.VaList(bp+8, zSchema, zTabname, Xsqlite3_errstr(tls, rc)))
		}
	} else {
		if rc&int32(0xff) == int32(SQLITE_CORRUPT) {
			rc = SQLITE_OK
		}
	}
	_sqlite3Fts5IndexCloseReader(tls, (*TFts5FullTable)(unsafe.Pointer(pTab)).Fp.FpIndex)
	(*TFts5Config)(unsafe.Pointer((*TFts5FullTable)(unsafe.Pointer(pTab)).Fp.FpConfig)).FpzErrmsg = uintptr(0)
	return rc
}

// C documentation
//
//	/*
//	** Advance the cursor to the next row in the table that matches the
//	** search criteria.
//	**
//	** Return SQLITE_OK if nothing goes wrong.  SQLITE_OK is returned
//	** even if we reach end-of-file.  The fts5EofMethod() will be called
//	** subsequently to determine whether or not an EOF was hit.
//	*/
func _fts5NextMethod(tls *libc.TLS, pCursor uintptr) (r int32) {
	bp := tls.Alloc(32)
	defer tls.Free(32)
	var pConfig, pCsr uintptr
	var rc, v1 int32
	var _ /* bSkip at bp+0 */ int32
	_, _, _, _ = pConfig, pCsr, rc, v1
	pCsr = pCursor
	/* If this cursor uses FTS5_PLAN_MATCH and this is a tokendata=1 table,
	 ** clear any token mappings accumulated at the fts5_index.c level. In
	 ** other cases, specifically FTS5_PLAN_SOURCE and FTS5_PLAN_SORTED_MATCH,
	 ** we need to retain the mappings for the entire query.  */
	if (*TFts5Cursor)(unsafe.Pointer(pCsr)).FePlan == int32(FTS5_PLAN_MATCH) && (*TFts5Config)(unsafe.Pointer((*TFts5Table)(unsafe.Pointer((*Tsqlite3_vtab_cursor)(unsafe.Pointer(pCursor)).FpVtab)).FpConfig)).FbTokendata != 0 {
		_sqlite3Fts5ExprClearTokens(tls, (*TFts5Cursor)(unsafe.Pointer(pCsr)).FpExpr)
	}
	if (*TFts5Cursor)(unsafe.Pointer(pCsr)).FePlan < int32(3) {
		**(**int32)(__ccgo_up(bp)) = 0
		v1 = _fts5CursorReseek(tls, pCsr, bp)
		rc = v1
		if v1 != 0 || **(**int32)(__ccgo_up(bp)) != 0 {
			return rc
		}
		rc = _sqlite3Fts5ExprNext(tls, (*TFts5Cursor)(unsafe.Pointer(pCsr)).FpExpr, (*TFts5Cursor)(unsafe.Pointer(pCsr)).FiLastRowid)
		**(**int32)(__ccgo_up(pCsr + 80)) |= _sqlite3Fts5ExprEof(tls, (*TFts5Cursor)(unsafe.Pointer(pCsr)).FpExpr)
		_fts5CsrNewrow(tls, pCsr)
	} else {
		switch (*TFts5Cursor)(unsafe.Pointer(pCsr)).FePlan {
		case int32(FTS5_PLAN_SPECIAL):
			**(**int32)(__ccgo_up(pCsr + 80)) |= int32(FTS5CSR_EOF)
			rc = SQLITE_OK
		case int32(FTS5_PLAN_SORTED_MATCH):
			rc = _fts5SorterNext(tls, pCsr)
		default:
			pConfig = (*TFts5Table)(unsafe.Pointer((*Tsqlite3_vtab_cursor)(unsafe.Pointer(pCursor)).FpVtab)).FpConfig
			(*TFts5Config)(unsafe.Pointer(pConfig)).FbLock = (*TFts5Config)(unsafe.Pointer(pConfig)).FbLock + 1
			rc = Xsqlite3_step(tls, (*TFts5Cursor)(unsafe.Pointer(pCsr)).FpStmt)
			(*TFts5Config)(unsafe.Pointer(pConfig)).FbLock = (*TFts5Config)(unsafe.Pointer(pConfig)).FbLock - 1
			if rc != int32(SQLITE_ROW) {
				**(**int32)(__ccgo_up(pCsr + 80)) |= int32(FTS5CSR_EOF)
				rc = Xsqlite3_reset(tls, (*TFts5Cursor)(unsafe.Pointer(pCsr)).FpStmt)
				if rc != SQLITE_OK {
					(*Tsqlite3_vtab)(unsafe.Pointer((*Tsqlite3_vtab_cursor)(unsafe.Pointer(pCursor)).FpVtab)).FzErrMsg = Xsqlite3_mprintf(tls, __ccgo_ts+3933, libc.VaList(bp+16, Xsqlite3_errmsg(tls, (*TFts5Config)(unsafe.Pointer(pConfig)).Fdb)))
				}
			} else {
				rc = SQLITE_OK
				**(**int32)(__ccgo_up(pCsr + 80)) |= int32(FTS5CSR_REQUIRE_DOCSIZE)
			}
			break
		}
	}
	return rc
}

// C documentation
//
//	/*
//	** Create a "porter" tokenizer.
//	*/
func _fts5PorterCreate(tls *libc.TLS, pCtx uintptr, azArg uintptr, nArg int32, ppOut uintptr) (r int32) {
	bp := tls.Alloc(16)
	defer tls.Free(16)
	var az2, pApi, pRet, zBase, v2 uintptr
	var nArg2, rc, v1 int32
	var _ /* pUserdata at bp+0 */ uintptr
	var _ /* pV2 at bp+8 */ uintptr
	_, _, _, _, _, _, _, _ = az2, nArg2, pApi, pRet, rc, zBase, v1, v2
	pApi = pCtx
	rc = SQLITE_OK
	**(**uintptr)(__ccgo_up(bp)) = uintptr(0)
	zBase = __ccgo_ts + 41883
	**(**uintptr)(__ccgo_up(bp + 8)) = uintptr(0)
	for nArg > 0 {
		if Xsqlite3_stricmp(tls, **(**uintptr)(__ccgo_up(azArg)), __ccgo_ts+41893) == 0 {
			nArg = nArg - 1
			azArg += 8
		} else {
			zBase = **(**uintptr)(__ccgo_up(azArg))
			break
		}
	}
	pRet = Xsqlite3_malloc64(tls, uint64(168))
	if pRet != 0 {
		libc.Xmemset(tls, pRet, 0, uint64(168))
		rc = (*(*func(*libc.TLS, uintptr, uintptr, uintptr, uintptr) int32)(unsafe.Pointer(&struct{ uintptr }{(*Tfts5_api)(unsafe.Pointer(pApi)).FxFindTokenizer_v2})))(tls, pApi, zBase, bp, bp+8)
	} else {
		rc = int32(SQLITE_NOMEM)
	}
	if rc == SQLITE_OK {
		if nArg > 0 {
			v1 = nArg - int32(1)
		} else {
			v1 = 0
		}
		nArg2 = v1
		if nArg2 != 0 {
			v2 = azArg + 1*8
		} else {
			v2 = uintptr(0)
		}
		az2 = v2
		libc.Xmemcpy(tls, pRet, **(**uintptr)(__ccgo_up(bp + 8)), uint64(32))
		rc = (*(*func(*libc.TLS, uintptr, uintptr, int32, uintptr) int32)(unsafe.Pointer(&struct{ uintptr }{(*TPorterTokenizer)(unsafe.Pointer(pRet)).Ftokenizer_v2.FxCreate})))(tls, **(**uintptr)(__ccgo_up(bp)), az2, nArg2, pRet+32)
	}
	if rc != SQLITE_OK {
		_fts5PorterDelete(tls, pRet)
		pRet = uintptr(0)
	}
	**(**uintptr)(__ccgo_up(ppOut)) = pRet
	return rc
}

func _fts5PrepareStatement(tls *libc.TLS, ppStmt uintptr, pConfig uintptr, zFmt uintptr, va uintptr) (r int32) {
	bp := tls.Alloc(32)
	defer tls.Free(32)
	var ap Tva_list
	var rc int32
	var zSql uintptr
	var _ /* pRet at bp+0 */ uintptr
	_, _, _ = ap, rc, zSql
	**(**uintptr)(__ccgo_up(bp)) = uintptr(0)
	ap = va
	zSql = Xsqlite3_vmprintf(tls, zFmt, ap)
	if zSql == uintptr(0) {
		rc = int32(SQLITE_NOMEM)
	} else {
		rc = Xsqlite3_prepare_v3(tls, (*TFts5Config)(unsafe.Pointer(pConfig)).Fdb, zSql, -int32(1), uint32(SQLITE_PREPARE_PERSISTENT), bp, uintptr(0))
		if rc != SQLITE_OK {
			_sqlite3Fts5ConfigErrmsg(tls, pConfig, __ccgo_ts+3933, libc.VaList(bp+16, Xsqlite3_errmsg(tls, (*TFts5Config)(unsafe.Pointer(pConfig)).Fdb)))
		}
		Xsqlite3_free(tls, zSql)
	}
	_ = ap
	**(**uintptr)(__ccgo_up(ppStmt)) = **(**uintptr)(__ccgo_up(bp))
	return rc
}

// C documentation
//
//	/*
//	** Execute the SQL statement:
//	**
//	**    DELETE FROM %_idx WHERE (segid, (pgno/2)) = ($iSegid, $iPgno);
//	**
//	** This is used when a secure-delete operation removes the last term
//	** from a segment leaf page. In that case the %_idx entry is removed
//	** too. This is done to ensure that if all instances of a token are
//	** removed from an fts5 database in secure-delete mode, no trace of
//	** the token itself remains in the database.
//	*/
func _fts5SecureDeleteIdxEntry(tls *libc.TLS, p uintptr, iSegid int32, iPgno int32) {
	bp := tls.Alloc(32)
	defer tls.Free(32)
	if iPgno != int32(1) {
		if (*TFts5Index)(unsafe.Pointer(p)).FpDeleteFromIdx == uintptr(0) {
			_fts5IndexPrepareStmt(tls, p, p+136, Xsqlite3_mprintf(tls, __ccgo_ts+39374, libc.VaList(bp+8, (*TFts5Config)(unsafe.Pointer((*TFts5Index)(unsafe.Pointer(p)).FpConfig)).FzDb, (*TFts5Config)(unsafe.Pointer((*TFts5Index)(unsafe.Pointer(p)).FpConfig)).FzName)))
		}
		if (*TFts5Index)(unsafe.Pointer(p)).Frc == SQLITE_OK {
			Xsqlite3_bind_int(tls, (*TFts5Index)(unsafe.Pointer(p)).FpDeleteFromIdx, int32(1), iSegid)
			Xsqlite3_bind_int(tls, (*TFts5Index)(unsafe.Pointer(p)).FpDeleteFromIdx, int32(2), iPgno)
			Xsqlite3_step(tls, (*TFts5Index)(unsafe.Pointer(p)).FpDeleteFromIdx)
			(*TFts5Index)(unsafe.Pointer(p)).Frc = Xsqlite3_reset(tls, (*TFts5Index)(unsafe.Pointer(p)).FpDeleteFromIdx)
		}
	}
}

// C documentation
//
//	/*
//	** If the cursor requires seeking (bSeekRequired flag is set), seek it.
//	** Return SQLITE_OK if no error occurs, or an SQLite error code otherwise.
//	**
//	** If argument bErrormsg is true and an error occurs, an error message may
//	** be left in sqlite3_vtab.zErrMsg.
//	*/
func _fts5SeekCursor(tls *libc.TLS, pCsr uintptr, bErrormsg int32) (r int32) {
	bp := tls.Alloc(32)
	defer tls.Free(32)
	var eStmt, rc int32
	var pTab, pTab1, v1 uintptr
	_, _, _, _, _ = eStmt, pTab, pTab1, rc, v1
	rc = SQLITE_OK
	/* If the cursor does not yet have a statement handle, obtain one now. */
	if (*TFts5Cursor)(unsafe.Pointer(pCsr)).FpStmt == uintptr(0) {
		pTab = (*TFts5Cursor)(unsafe.Pointer(pCsr)).Fbase.FpVtab
		eStmt = _fts5StmtType(tls, pCsr)
		if bErrormsg != 0 {
			v1 = pTab + 16
		} else {
			v1 = uintptr(0)
		}
		rc = _sqlite3Fts5StorageStmt(tls, (*TFts5FullTable)(unsafe.Pointer(pTab)).FpStorage, eStmt, pCsr+56, v1)
	}
	if rc == SQLITE_OK && (*TFts5Cursor)(unsafe.Pointer(pCsr)).Fcsrflags&int32(FTS5CSR_REQUIRE_CONTENT) != 0 {
		pTab1 = (*TFts5Cursor)(unsafe.Pointer(pCsr)).Fbase.FpVtab
		Xsqlite3_reset(tls, (*TFts5Cursor)(unsafe.Pointer(pCsr)).FpStmt)
		Xsqlite3_bind_int64(tls, (*TFts5Cursor)(unsafe.Pointer(pCsr)).FpStmt, int32(1), _fts5CursorRowid(tls, pCsr))
		(*TFts5Config)(unsafe.Pointer((*TFts5Table)(unsafe.Pointer(pTab1)).FpConfig)).FbLock = (*TFts5Config)(unsafe.Pointer((*TFts5Table)(unsafe.Pointer(pTab1)).FpConfig)).FbLock + 1
		rc = Xsqlite3_step(tls, (*TFts5Cursor)(unsafe.Pointer(pCsr)).FpStmt)
		(*TFts5Config)(unsafe.Pointer((*TFts5Table)(unsafe.Pointer(pTab1)).FpConfig)).FbLock = (*TFts5Config)(unsafe.Pointer((*TFts5Table)(unsafe.Pointer(pTab1)).FpConfig)).FbLock - 1
		if rc == int32(SQLITE_ROW) {
			rc = SQLITE_OK
			**(**int32)(__ccgo_up(pCsr + 80)) &= ^libc.Int32FromInt32(FTS5CSR_REQUIRE_CONTENT)
		} else {
			rc = Xsqlite3_reset(tls, (*TFts5Cursor)(unsafe.Pointer(pCsr)).FpStmt)
			if rc == SQLITE_OK {
				rc = libc.Int32FromInt32(SQLITE_CORRUPT) | libc.Int32FromInt32(1)<<libc.Int32FromInt32(8)
				_fts5SetVtabError(tls, pTab1, __ccgo_ts+39942, libc.VaList(bp+8, _fts5CursorRowid(tls, pCsr), (*TFts5Config)(unsafe.Pointer((*TFts5Table)(unsafe.Pointer(pTab1)).FpConfig)).FzContent))
			} else {
				if (*TFts5Config)(unsafe.Pointer((*TFts5Table)(unsafe.Pointer(pTab1)).FpConfig)).FpzErrmsg != 0 {
					_fts5SetVtabError(tls, pTab1, __ccgo_ts+3933, libc.VaList(bp+8, Xsqlite3_errmsg(tls, (*TFts5Config)(unsafe.Pointer((*TFts5Table)(unsafe.Pointer(pTab1)).FpConfig)).Fdb)))
				}
			}
		}
	}
	return rc
}

// C documentation
//
//	/*
//	** This function sets up an iterator to use for a non-prefix query on a
//	** tokendata=1 table.
//	*/
func _fts5SetupTokendataIter(tls *libc.TLS, p uintptr, pToken uintptr, nToken int32, pColset uintptr) (r uintptr) {
	bp := tls.Alloc(16)
	defer tls.Free(16)
	var bDone, flags, iLvl, iSeg, iSeg1, ii, ii1 int32
	var pII, pIter, pNew, pNewIter, pPrev, pPrevIter, pRet, pSeg, pSet, pSmall, pStruct, v1 uintptr
	var _ /* bSeek at bp+0 */ TFts5Buffer
	_, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _ = bDone, flags, iLvl, iSeg, iSeg1, ii, ii1, pII, pIter, pNew, pNewIter, pPrev, pPrevIter, pRet, pSeg, pSet, pSmall, pStruct, v1
	pRet = uintptr(0)
	pSet = uintptr(0)
	pStruct = uintptr(0)
	flags = libc.Int32FromInt32(FTS5INDEX_QUERY_SCANONETERM) | libc.Int32FromInt32(FTS5INDEX_QUERY_SCAN)
	**(**TFts5Buffer)(__ccgo_up(bp)) = TFts5Buffer{}
	pSmall = uintptr(0)
	_fts5IndexFlush(tls, p)
	pStruct = _fts5StructureRead(tls, p)
	for (*TFts5Index)(unsafe.Pointer(p)).Frc == SQLITE_OK {
		if pSet != 0 {
			v1 = *(*uintptr)(unsafe.Pointer(pSet + 72 + uintptr((*TFts5TokenDataIter)(unsafe.Pointer(pSet)).FnIter-int64(1))*8))
		} else {
			v1 = uintptr(0)
		}
		pPrev = v1
		pNew = uintptr(0)
		pNewIter = uintptr(0)
		pPrevIter = uintptr(0)
		pNew = _fts5MultiIterAlloc(tls, p, (*TFts5Structure)(unsafe.Pointer(pStruct)).FnSegment)
		if pSmall != 0 {
			_sqlite3Fts5BufferSet(tls, p+60, bp, (*TFts5Buffer)(unsafe.Pointer(pSmall)).Fn, (*TFts5Buffer)(unsafe.Pointer(pSmall)).Fp)
			_sqlite3Fts5BufferAppendBlob(tls, p+60, bp, uint32(1), __ccgo_ts+39573)
		} else {
			_sqlite3Fts5BufferSet(tls, p+60, bp, nToken, pToken)
		}
		if (*TFts5Index)(unsafe.Pointer(p)).Frc != 0 {
			_fts5IterClose(tls, pNew)
			break
		}
		pNewIter = pNew + 104
		if pPrev != 0 {
			v1 = pPrev + 104
		} else {
			v1 = uintptr(0)
		}
		pPrevIter = v1
		iLvl = 0
		for {
			if !(iLvl < (*TFts5Structure)(unsafe.Pointer(pStruct)).FnLevel) {
				break
			}
			iSeg = (*(*TFts5StructureLevel)(unsafe.Pointer(pStruct + 32 + uintptr(iLvl)*16))).FnSeg - int32(1)
			for {
				if !(iSeg >= 0) {
					break
				}
				pSeg = (*(*TFts5StructureLevel)(unsafe.Pointer(pStruct + 32 + uintptr(iLvl)*16))).FaSeg + uintptr(iSeg)*56
				bDone = 0
				if pPrevIter != 0 {
					if _fts5BufferCompare(tls, pSmall, pPrevIter+96) != 0 {
						libc.Xmemcpy(tls, pNewIter, pPrevIter, uint64(128))
						libc.Xmemset(tls, pPrevIter, 0, uint64(128))
						bDone = int32(1)
					} else {
						if (*TFts5SegIter)(unsafe.Pointer(pPrevIter)).FiEndofDoclist > (*TFts5Data)(unsafe.Pointer((*TFts5SegIter)(unsafe.Pointer(pPrevIter)).FpLeaf)).FszLeaf {
							_fts5SegIterNextInit(tls, p, (**(**TFts5Buffer)(__ccgo_up(bp))).Fp, (**(**TFts5Buffer)(__ccgo_up(bp))).Fn-int32(1), pSeg, pNewIter)
							bDone = int32(1)
						}
					}
				}
				if bDone == 0 {
					_fts5SegIterSeekInit(tls, p, (**(**TFts5Buffer)(__ccgo_up(bp))).Fp, (**(**TFts5Buffer)(__ccgo_up(bp))).Fn, flags, pSeg, pNewIter)
				}
				if pPrevIter != 0 {
					if (*TFts5SegIter)(unsafe.Pointer(pPrevIter)).FpTombArray != 0 {
						(*TFts5SegIter)(unsafe.Pointer(pNewIter)).FpTombArray = (*TFts5SegIter)(unsafe.Pointer(pPrevIter)).FpTombArray
						(*TFts5TombstoneArray)(unsafe.Pointer((*TFts5SegIter)(unsafe.Pointer(pNewIter)).FpTombArray)).FnRef = (*TFts5TombstoneArray)(unsafe.Pointer((*TFts5SegIter)(unsafe.Pointer(pNewIter)).FpTombArray)).FnRef + 1
					}
				} else {
					_fts5SegIterAllocTombstone(tls, p, pNewIter)
				}
				pNewIter += 128
				if pPrevIter != 0 {
					pPrevIter += 128
				}
				if (*TFts5Index)(unsafe.Pointer(p)).Frc != 0 {
					break
				}
				goto _4
			_4:
				;
				iSeg = iSeg - 1
			}
			goto _3
		_3:
			;
			iLvl = iLvl + 1
		}
		_fts5TokendataSetTermIfEof(tls, pPrev, pSmall)
		(*TFts5Iter)(unsafe.Pointer(pNew)).FbSkipEmpty = uint8(1)
		(*TFts5Iter)(unsafe.Pointer(pNew)).FpColset = pColset
		_fts5IterSetOutputCb(tls, p+60, pNew)
		/* Loop through all segments in the new iterator. Find the smallest
		 ** term that any segment-iterator points to. Iterator pNew will be
		 ** used for this term. Also, set any iterator that points to a term that
		 ** does not match pToken/nToken to point to EOF */
		pSmall = uintptr(0)
		ii = 0
		for {
			if !(ii < (*TFts5Iter)(unsafe.Pointer(pNew)).FnSeg) {
				break
			}
			pII = pNew + 104 + uintptr(ii)*128
			if 0 == _fts5IsTokendataPrefix(tls, pII+96, pToken, nToken) {
				_fts5SegIterSetEOF(tls, pII)
			}
			if (*TFts5SegIter)(unsafe.Pointer(pII)).FpLeaf != 0 && (!(pSmall != 0) || _fts5BufferCompare(tls, pSmall, pII+96) > 0) {
				pSmall = pII + 96
			}
			goto _5
		_5:
			;
			ii = ii + 1
		}
		/* If pSmall is still NULL at this point, then the new iterator does
		 ** not point to any terms that match the query. So delete it and break
		 ** out of the loop - all required iterators have been collected.  */
		if pSmall == uintptr(0) {
			_fts5IterClose(tls, pNew)
			break
		}
		/* Append this iterator to the set and continue. */
		pSet = _fts5AppendTokendataIter(tls, p, pSet, pNew)
	}
	if (*TFts5Index)(unsafe.Pointer(p)).Frc == SQLITE_OK && pSet != 0 {
		ii1 = 0
		for {
			if !(int64(ii1) < (*TFts5TokenDataIter)(unsafe.Pointer(pSet)).FnIter) {
				break
			}
			pIter = *(*uintptr)(unsafe.Pointer(pSet + 72 + uintptr(ii1)*8))
			iSeg1 = 0
			for {
				if !(iSeg1 < (*TFts5Iter)(unsafe.Pointer(pIter)).FnSeg) {
					break
				}
				(*(*TFts5SegIter)(unsafe.Pointer(pIter + 104 + uintptr(iSeg1)*128))).Fflags |= int32(FTS5_SEGITER_ONETERM)
				goto _7
			_7:
				;
				iSeg1 = iSeg1 + 1
			}
			_fts5MultiIterFinishSetup(tls, p, pIter)
			goto _6
		_6:
			;
			ii1 = ii1 + 1
		}
	}
	if (*TFts5Index)(unsafe.Pointer(p)).Frc == SQLITE_OK {
		pRet = _fts5MultiIterAlloc(tls, p, 0)
	}
	if pRet != 0 {
		(*TFts5Iter)(unsafe.Pointer(pRet)).FnSeg = 0
		(*TFts5Iter)(unsafe.Pointer(pRet)).FpTokenDataIter = pSet
		if pSet != 0 {
			_fts5IterSetOutputsTokendata(tls, pRet)
		} else {
			(*TFts5Iter)(unsafe.Pointer(pRet)).Fbase.FbEof = uint8(1)
		}
	} else {
		_fts5TokendataIterDelete(tls, pSet)
	}
	_fts5StructureRelease(tls, pStruct)
	_sqlite3Fts5BufferFree(tls, bp)
	return pRet
}

// C documentation
//
//	/*
//	** Implementation of snippet() function.
//	*/
func _fts5SnippetFunction(tls *libc.TLS, pApi uintptr, pFts uintptr, pCtx uintptr, nVal int32, apVal uintptr) {
	bp := tls.Alloc(208)
	defer tls.Free(208)
	var aSeen, zEllips, zErr uintptr
	var i, iBestCol, iBestStart, iCol, ii, jj, nBestScore, nCol, nPhrase, v4 int32
	var nToken Ti64
	var v1, v2, v3 int64
	var _ /* ctx at bp+0 */ THighlightContext
	var _ /* iAdj at bp+184 */ int32
	var _ /* ic at bp+176 */ int32
	var _ /* io at bp+180 */ int32
	var _ /* ip at bp+172 */ int32
	var _ /* nColSize at bp+112 */ int32
	var _ /* nDoc at bp+164 */ int32
	var _ /* nDocsize at bp+168 */ int32
	var _ /* nInst at bp+108 */ int32
	var _ /* nLoc at bp+160 */ int32
	var _ /* nLoc at bp+200 */ int32
	var _ /* nScore at bp+188 */ int32
	var _ /* pLoc at bp+152 */ uintptr
	var _ /* pLoc at bp+192 */ uintptr
	var _ /* rc at bp+104 */ int32
	var _ /* sFinder at bp+120 */ TFts5SFinder
	_, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _ = aSeen, i, iBestCol, iBestStart, iCol, ii, jj, nBestScore, nCol, nPhrase, nToken, zEllips, zErr, v1, v2, v3, v4
	**(**int32)(__ccgo_up(bp + 104)) = SQLITE_OK /* 5th argument to snippet() */
	**(**int32)(__ccgo_up(bp + 108)) = 0         /* Column containing best snippet */
	iBestStart = 0                               /* First token of best snippet */
	nBestScore = 0                               /* Score of best snippet */
	**(**int32)(__ccgo_up(bp + 112)) = 0
	if nVal != int32(5) {
		zErr = __ccgo_ts + 37195
		Xsqlite3_result_error(tls, pCtx, zErr, -int32(1))
		return
	}
	nCol = (*(*func(*libc.TLS, uintptr) int32)(unsafe.Pointer(&struct{ uintptr }{(*TFts5ExtensionApi)(unsafe.Pointer(pApi)).FxColumnCount})))(tls, pFts)
	libc.Xmemset(tls, bp, 0, uint64(104))
	iCol = Xsqlite3_value_int(tls, **(**uintptr)(__ccgo_up(apVal)))
	(**(**THighlightContext)(__ccgo_up(bp))).FzOpen = _fts5ValueToText(tls, **(**uintptr)(__ccgo_up(apVal + 1*8)))
	(**(**THighlightContext)(__ccgo_up(bp))).FzClose = _fts5ValueToText(tls, **(**uintptr)(__ccgo_up(apVal + 2*8)))
	(**(**THighlightContext)(__ccgo_up(bp))).FiRangeEnd = -int32(1)
	zEllips = _fts5ValueToText(tls, **(**uintptr)(__ccgo_up(apVal + 3*8)))
	if Xsqlite3_value_int64(tls, **(**uintptr)(__ccgo_up(apVal + 4*8))) > int64(libc.Int32FromInt32(0)) {
		v2 = Xsqlite3_value_int64(tls, **(**uintptr)(__ccgo_up(apVal + 4*8)))
	} else {
		v2 = int64(libc.Int32FromInt32(0))
	}
	if v2 < int64(libc.Int32FromInt32(64)) {
		if Xsqlite3_value_int64(tls, **(**uintptr)(__ccgo_up(apVal + 4*8))) > int64(libc.Int32FromInt32(0)) {
			v3 = Xsqlite3_value_int64(tls, **(**uintptr)(__ccgo_up(apVal + 4*8)))
		} else {
			v3 = int64(libc.Int32FromInt32(0))
		}
		v1 = v3
	} else {
		v1 = int64(libc.Int32FromInt32(64))
	}
	nToken = int64(int32(v1))
	if iCol >= 0 {
		v4 = iCol
	} else {
		v4 = 0
	}
	iBestCol = v4
	nPhrase = (*(*func(*libc.TLS, uintptr) int32)(unsafe.Pointer(&struct{ uintptr }{(*TFts5ExtensionApi)(unsafe.Pointer(pApi)).FxPhraseCount})))(tls, pFts)
	aSeen = Xsqlite3_malloc64(tls, libc.Uint64FromInt32(nPhrase))
	if aSeen == uintptr(0) {
		**(**int32)(__ccgo_up(bp + 104)) = int32(SQLITE_NOMEM)
	}
	if **(**int32)(__ccgo_up(bp + 104)) == SQLITE_OK {
		**(**int32)(__ccgo_up(bp + 104)) = (*(*func(*libc.TLS, uintptr, uintptr) int32)(unsafe.Pointer(&struct{ uintptr }{(*TFts5ExtensionApi)(unsafe.Pointer(pApi)).FxInstCount})))(tls, pFts, bp+108)
	}
	libc.Xmemset(tls, bp+120, 0, uint64(32))
	i = 0
	for {
		if !(i < nCol) {
			break
		}
		if iCol < 0 || iCol == i {
			**(**uintptr)(__ccgo_up(bp + 152)) = uintptr(0) /* Locale of column iCol */
			**(**int32)(__ccgo_up(bp + 160)) = 0
			(**(**TFts5SFinder)(__ccgo_up(bp + 120))).FiPos = 0
			(**(**TFts5SFinder)(__ccgo_up(bp + 120))).FnFirst = 0
			**(**int32)(__ccgo_up(bp + 104)) = (*(*func(*libc.TLS, uintptr, int32, uintptr, uintptr) int32)(unsafe.Pointer(&struct{ uintptr }{(*TFts5ExtensionApi)(unsafe.Pointer(pApi)).FxColumnText})))(tls, pFts, i, bp+120+24, bp+164)
			if **(**int32)(__ccgo_up(bp + 104)) != SQLITE_OK {
				break
			}
			**(**int32)(__ccgo_up(bp + 104)) = (*(*func(*libc.TLS, uintptr, int32, uintptr, uintptr) int32)(unsafe.Pointer(&struct{ uintptr }{(*TFts5ExtensionApi)(unsafe.Pointer(pApi)).FxColumnLocale})))(tls, pFts, i, bp+152, bp+160)
			if **(**int32)(__ccgo_up(bp + 104)) != SQLITE_OK {
				break
			}
			**(**int32)(__ccgo_up(bp + 104)) = (*(*func(*libc.TLS, uintptr, uintptr, int32, uintptr, int32, uintptr, uintptr) int32)(unsafe.Pointer(&struct{ uintptr }{(*TFts5ExtensionApi)(unsafe.Pointer(pApi)).FxTokenize_v2})))(tls, pFts, (**(**TFts5SFinder)(__ccgo_up(bp + 120))).FzDoc, **(**int32)(__ccgo_up(bp + 164)), **(**uintptr)(__ccgo_up(bp + 152)), **(**int32)(__ccgo_up(bp + 160)), bp+120, __ccgo_fp(_fts5SentenceFinderCb))
			if **(**int32)(__ccgo_up(bp + 104)) != SQLITE_OK {
				break
			}
			**(**int32)(__ccgo_up(bp + 104)) = (*(*func(*libc.TLS, uintptr, int32, uintptr) int32)(unsafe.Pointer(&struct{ uintptr }{(*TFts5ExtensionApi)(unsafe.Pointer(pApi)).FxColumnSize})))(tls, pFts, i, bp+168)
			if **(**int32)(__ccgo_up(bp + 104)) != SQLITE_OK {
				break
			}
			ii = 0
			for {
				if !(**(**int32)(__ccgo_up(bp + 104)) == SQLITE_OK && ii < **(**int32)(__ccgo_up(bp + 108))) {
					break
				}
				**(**int32)(__ccgo_up(bp + 104)) = (*(*func(*libc.TLS, uintptr, int32, uintptr, uintptr, uintptr) int32)(unsafe.Pointer(&struct{ uintptr }{(*TFts5ExtensionApi)(unsafe.Pointer(pApi)).FxInst})))(tls, pFts, ii, bp+172, bp+176, bp+180)
				if **(**int32)(__ccgo_up(bp + 176)) != i {
					goto _6
				}
				if **(**int32)(__ccgo_up(bp + 180)) > **(**int32)(__ccgo_up(bp + 168)) {
					**(**int32)(__ccgo_up(bp + 104)) = libc.Int32FromInt32(SQLITE_CORRUPT) | libc.Int32FromInt32(1)<<libc.Int32FromInt32(8)
				}
				if **(**int32)(__ccgo_up(bp + 104)) != SQLITE_OK {
					goto _6
				}
				libc.Xmemset(tls, aSeen, 0, libc.Uint64FromInt32(nPhrase))
				**(**int32)(__ccgo_up(bp + 104)) = _fts5SnippetScore(tls, pApi, pFts, **(**int32)(__ccgo_up(bp + 168)), aSeen, i, **(**int32)(__ccgo_up(bp + 180)), int32(nToken), bp+188, bp+184)
				if **(**int32)(__ccgo_up(bp + 104)) == SQLITE_OK && **(**int32)(__ccgo_up(bp + 188)) > nBestScore {
					nBestScore = **(**int32)(__ccgo_up(bp + 188))
					iBestCol = i
					iBestStart = **(**int32)(__ccgo_up(bp + 184))
					**(**int32)(__ccgo_up(bp + 112)) = **(**int32)(__ccgo_up(bp + 168))
				}
				if **(**int32)(__ccgo_up(bp + 104)) == SQLITE_OK && (**(**TFts5SFinder)(__ccgo_up(bp + 120))).FnFirst != 0 && int64(**(**int32)(__ccgo_up(bp + 168))) > nToken {
					jj = 0
					for {
						if !(jj < (**(**TFts5SFinder)(__ccgo_up(bp + 120))).FnFirst-int32(1)) {
							break
						}
						if **(**int32)(__ccgo_up((**(**TFts5SFinder)(__ccgo_up(bp + 120))).FaFirst + uintptr(jj+int32(1))*4)) > **(**int32)(__ccgo_up(bp + 180)) {
							break
						}
						goto _7
					_7:
						;
						jj = jj + 1
					}
					if **(**int32)(__ccgo_up((**(**TFts5SFinder)(__ccgo_up(bp + 120))).FaFirst + uintptr(jj)*4)) < **(**int32)(__ccgo_up(bp + 180)) {
						libc.Xmemset(tls, aSeen, 0, libc.Uint64FromInt32(nPhrase))
						**(**int32)(__ccgo_up(bp + 104)) = _fts5SnippetScore(tls, pApi, pFts, **(**int32)(__ccgo_up(bp + 168)), aSeen, i, **(**int32)(__ccgo_up((**(**TFts5SFinder)(__ccgo_up(bp + 120))).FaFirst + uintptr(jj)*4)), int32(nToken), bp+188, uintptr(0))
						if **(**int32)(__ccgo_up((**(**TFts5SFinder)(__ccgo_up(bp + 120))).FaFirst + uintptr(jj)*4)) == 0 {
							v4 = int32(120)
						} else {
							v4 = int32(100)
						}
						**(**int32)(__ccgo_up(bp + 188)) = **(**int32)(__ccgo_up(bp + 188)) + v4
						if **(**int32)(__ccgo_up(bp + 104)) == SQLITE_OK && **(**int32)(__ccgo_up(bp + 188)) > nBestScore {
							nBestScore = **(**int32)(__ccgo_up(bp + 188))
							iBestCol = i
							iBestStart = **(**int32)(__ccgo_up((**(**TFts5SFinder)(__ccgo_up(bp + 120))).FaFirst + uintptr(jj)*4))
							**(**int32)(__ccgo_up(bp + 112)) = **(**int32)(__ccgo_up(bp + 168))
						}
					}
				}
				goto _6
			_6:
				;
				ii = ii + 1
			}
		}
		goto _5
	_5:
		;
		i = i + 1
	}
	if **(**int32)(__ccgo_up(bp + 104)) == SQLITE_OK {
		**(**int32)(__ccgo_up(bp + 104)) = (*(*func(*libc.TLS, uintptr, int32, uintptr, uintptr) int32)(unsafe.Pointer(&struct{ uintptr }{(*TFts5ExtensionApi)(unsafe.Pointer(pApi)).FxColumnText})))(tls, pFts, iBestCol, bp+24, bp+32)
	}
	if **(**int32)(__ccgo_up(bp + 104)) == SQLITE_OK && **(**int32)(__ccgo_up(bp + 112)) == 0 {
		**(**int32)(__ccgo_up(bp + 104)) = (*(*func(*libc.TLS, uintptr, int32, uintptr) int32)(unsafe.Pointer(&struct{ uintptr }{(*TFts5ExtensionApi)(unsafe.Pointer(pApi)).FxColumnSize})))(tls, pFts, iBestCol, bp+112)
	}
	if (**(**THighlightContext)(__ccgo_up(bp))).FzIn != 0 {
		**(**uintptr)(__ccgo_up(bp + 192)) = uintptr(0) /* Locale of column iBestCol */
		**(**int32)(__ccgo_up(bp + 200)) = 0            /* Bytes in pLoc */
		if **(**int32)(__ccgo_up(bp + 104)) == SQLITE_OK {
			**(**int32)(__ccgo_up(bp + 104)) = _fts5CInstIterInit(tls, pApi, pFts, iBestCol, bp+40)
		}
		(**(**THighlightContext)(__ccgo_up(bp))).FiRangeStart = iBestStart
		(**(**THighlightContext)(__ccgo_up(bp))).FiRangeEnd = int32(int64(iBestStart) + nToken - int64(1))
		if iBestStart > 0 {
			_fts5HighlightAppend(tls, bp+104, bp, zEllips, -int32(1))
		}
		/* Advance iterator ctx.iter so that it points to the first coalesced
		 ** phrase instance at or following position iBestStart. */
		for (**(**THighlightContext)(__ccgo_up(bp))).Fiter.FiStart >= 0 && (**(**THighlightContext)(__ccgo_up(bp))).Fiter.FiStart < iBestStart && **(**int32)(__ccgo_up(bp + 104)) == SQLITE_OK {
			**(**int32)(__ccgo_up(bp + 104)) = _fts5CInstIterNext(tls, bp+40)
		}
		if **(**int32)(__ccgo_up(bp + 104)) == SQLITE_OK {
			**(**int32)(__ccgo_up(bp + 104)) = (*(*func(*libc.TLS, uintptr, int32, uintptr, uintptr) int32)(unsafe.Pointer(&struct{ uintptr }{(*TFts5ExtensionApi)(unsafe.Pointer(pApi)).FxColumnLocale})))(tls, pFts, iBestCol, bp+192, bp+200)
		}
		if **(**int32)(__ccgo_up(bp + 104)) == SQLITE_OK {
			**(**int32)(__ccgo_up(bp + 104)) = (*(*func(*libc.TLS, uintptr, uintptr, int32, uintptr, int32, uintptr, uintptr) int32)(unsafe.Pointer(&struct{ uintptr }{(*TFts5ExtensionApi)(unsafe.Pointer(pApi)).FxTokenize_v2})))(tls, pFts, (**(**THighlightContext)(__ccgo_up(bp))).FzIn, (**(**THighlightContext)(__ccgo_up(bp))).FnIn, **(**uintptr)(__ccgo_up(bp + 192)), **(**int32)(__ccgo_up(bp + 200)), bp, __ccgo_fp(_fts5HighlightCb))
		}
		if (**(**THighlightContext)(__ccgo_up(bp))).FbOpen != 0 {
			_fts5HighlightAppend(tls, bp+104, bp, (**(**THighlightContext)(__ccgo_up(bp))).FzClose, -int32(1))
		}
		if (**(**THighlightContext)(__ccgo_up(bp))).FiRangeEnd >= **(**int32)(__ccgo_up(bp + 112))-int32(1) {
			_fts5HighlightAppend(tls, bp+104, bp, (**(**THighlightContext)(__ccgo_up(bp))).FzIn+uintptr((**(**THighlightContext)(__ccgo_up(bp))).FiOff), (**(**THighlightContext)(__ccgo_up(bp))).FnIn-(**(**THighlightContext)(__ccgo_up(bp))).FiOff)
		} else {
			_fts5HighlightAppend(tls, bp+104, bp, zEllips, -int32(1))
		}
	}
	if **(**int32)(__ccgo_up(bp + 104)) == SQLITE_OK {
		Xsqlite3_result_text(tls, pCtx, (**(**THighlightContext)(__ccgo_up(bp))).FzOut, -int32(1), uintptr(-libc.Int32FromInt32(1)))
	} else {
		Xsqlite3_result_error_code(tls, pCtx, **(**int32)(__ccgo_up(bp + 104)))
	}
	Xsqlite3_free(tls, (**(**THighlightContext)(__ccgo_up(bp))).FzOut)
	Xsqlite3_free(tls, aSeen)
	Xsqlite3_free(tls, (**(**TFts5SFinder)(__ccgo_up(bp + 120))).FaFirst)
}

/************************************************************************/

// C documentation
//
//	/*
//	** Implementation of fts5_source_id() function.
//	*/
func _fts5SourceIdFunc(tls *libc.TLS, pCtx uintptr, nArg int32, apUnused uintptr) {
	_ = nArg
	_ = apUnused
	Xsqlite3_result_text(tls, pCtx, __ccgo_ts+40498, -int32(1), uintptr(-libc.Int32FromInt32(1)))
}

// C documentation
//
//	/*
//	** This function is called to handle an FTS INSERT command. In other words,
//	** an INSERT statement of the form:
//	**
//	**     INSERT INTO fts(fts) VALUES($pCmd)
//	**     INSERT INTO fts(fts, rank) VALUES($pCmd, $pVal)
//	**
//	** Argument pVal is the value assigned to column "fts" by the INSERT
//	** statement. This function returns SQLITE_OK if successful, or an SQLite
//	** error code if an error occurs.
//	**
//	** The commands implemented by this function are documented in the "Special
//	** INSERT Directives" section of the documentation. It should be updated if
//	** more commands are added to this function.
//	*/
func _fts5SpecialInsert(tls *libc.TLS, pTab uintptr, zCmd uintptr, pVal uintptr) (r int32) {
	bp := tls.Alloc(16)
	defer tls.Free(16)
	var bLoadConfig, iArg, nMerge, rc int32
	var pConfig uintptr
	var _ /* bError at bp+0 */ int32
	_, _, _, _, _ = bLoadConfig, iArg, nMerge, pConfig, rc
	pConfig = (*TFts5FullTable)(unsafe.Pointer(pTab)).Fp.FpConfig
	rc = SQLITE_OK
	**(**int32)(__ccgo_up(bp)) = 0
	bLoadConfig = 0
	if 0 == Xsqlite3_stricmp(tls, __ccgo_ts+39987, zCmd) {
		if (*TFts5Config)(unsafe.Pointer(pConfig)).FeContent == FTS5_CONTENT_NORMAL {
			_fts5SetVtabError(tls, pTab, __ccgo_ts+39998, 0)
			rc = int32(SQLITE_ERROR)
		} else {
			rc = _sqlite3Fts5StorageDeleteAll(tls, (*TFts5FullTable)(unsafe.Pointer(pTab)).FpStorage)
		}
		bLoadConfig = int32(1)
	} else {
		if 0 == Xsqlite3_stricmp(tls, __ccgo_ts+40078, zCmd) {
			if _fts5IsContentless(tls, pTab, int32(1)) != 0 {
				_fts5SetVtabError(tls, pTab, __ccgo_ts+40086, 0)
				rc = int32(SQLITE_ERROR)
			} else {
				rc = _sqlite3Fts5StorageRebuild(tls, (*TFts5FullTable)(unsafe.Pointer(pTab)).FpStorage)
			}
			bLoadConfig = int32(1)
		} else {
			if 0 == Xsqlite3_stricmp(tls, __ccgo_ts+18623, zCmd) {
				rc = _sqlite3Fts5StorageOptimize(tls, (*TFts5FullTable)(unsafe.Pointer(pTab)).FpStorage)
			} else {
				if 0 == Xsqlite3_stricmp(tls, __ccgo_ts+40142, zCmd) {
					nMerge = Xsqlite3_value_int(tls, pVal)
					rc = _sqlite3Fts5StorageMerge(tls, (*TFts5FullTable)(unsafe.Pointer(pTab)).FpStorage, nMerge)
				} else {
					if 0 == Xsqlite3_stricmp(tls, __ccgo_ts+40148, zCmd) {
						iArg = Xsqlite3_value_int(tls, pVal)
						rc = _sqlite3Fts5StorageIntegrity(tls, (*TFts5FullTable)(unsafe.Pointer(pTab)).FpStorage, iArg)
					} else {
						if 0 == Xsqlite3_stricmp(tls, __ccgo_ts+40164, zCmd) {
							rc = _sqlite3Fts5FlushToDisk(tls, pTab)
						} else {
							rc = _sqlite3Fts5FlushToDisk(tls, pTab)
							if rc == SQLITE_OK {
								rc = _sqlite3Fts5IndexLoadConfig(tls, (*TFts5FullTable)(unsafe.Pointer(pTab)).Fp.FpIndex)
							}
							if rc == SQLITE_OK {
								rc = _sqlite3Fts5ConfigSetValue(tls, (*TFts5FullTable)(unsafe.Pointer(pTab)).Fp.FpConfig, zCmd, pVal, bp)
							}
							if rc == SQLITE_OK {
								if **(**int32)(__ccgo_up(bp)) != 0 {
									rc = int32(SQLITE_ERROR)
								} else {
									rc = _sqlite3Fts5StorageConfigValue(tls, (*TFts5FullTable)(unsafe.Pointer(pTab)).FpStorage, zCmd, pVal, 0)
								}
							}
						}
					}
				}
			}
		}
	}
	if rc == SQLITE_OK && bLoadConfig != 0 {
		(*TFts5Config)(unsafe.Pointer((*TFts5FullTable)(unsafe.Pointer(pTab)).Fp.FpConfig)).FiCookie = (*TFts5Config)(unsafe.Pointer((*TFts5FullTable)(unsafe.Pointer(pTab)).Fp.FpConfig)).FiCookie - 1
		rc = _sqlite3Fts5IndexLoadConfig(tls, (*TFts5FullTable)(unsafe.Pointer(pTab)).Fp.FpIndex)
	}
	return rc
}

func _fts5StorageCount(tls *libc.TLS, p uintptr, zSuffix uintptr, pnRow uintptr) (r int32) {
	bp := tls.Alloc(48)
	defer tls.Free(48)
	var pConfig, zSql uintptr
	var rc int32
	var _ /* pCnt at bp+0 */ uintptr
	_, _, _ = pConfig, rc, zSql
	pConfig = (*TFts5Storage)(unsafe.Pointer(p)).FpConfig
	zSql = Xsqlite3_mprintf(tls, __ccgo_ts+41791, libc.VaList(bp+16, (*TFts5Config)(unsafe.Pointer(pConfig)).FzDb, (*TFts5Config)(unsafe.Pointer(pConfig)).FzName, zSuffix))
	if zSql == uintptr(0) {
		rc = int32(SQLITE_NOMEM)
	} else {
		**(**uintptr)(__ccgo_up(bp)) = uintptr(0)
		rc = Xsqlite3_prepare_v2(tls, (*TFts5Config)(unsafe.Pointer(pConfig)).Fdb, zSql, -int32(1), bp, uintptr(0))
		if rc == SQLITE_OK {
			if int32(SQLITE_ROW) == Xsqlite3_step(tls, **(**uintptr)(__ccgo_up(bp))) {
				**(**Ti64)(__ccgo_up(pnRow)) = Xsqlite3_column_int64(tls, **(**uintptr)(__ccgo_up(bp)), 0)
			}
			rc = Xsqlite3_finalize(tls, **(**uintptr)(__ccgo_up(bp)))
		}
	}
	Xsqlite3_free(tls, zSql)
	return rc
}

// C documentation
//
//	/*
//	** Prepare the two insert statements - Fts5Storage.pInsertContent and
//	** Fts5Storage.pInsertDocsize - if they have not already been prepared.
//	** Return SQLITE_OK if successful, or an SQLite error code if an error
//	** occurs.
//	*/
func _fts5StorageGetStmt(tls *libc.TLS, p uintptr, eStmt int32, ppStmt uintptr, pzErrMsg uintptr) (r int32) {
	bp := tls.Alloc(64)
	defer tls.Free(64)
	var azStmt [12]uintptr
	var f, i int32
	var pC, zBind, zSql, v2 uintptr
	var _ /* rc at bp+0 */ int32
	_, _, _, _, _, _, _ = azStmt, f, i, pC, zBind, zSql, v2
	**(**int32)(__ccgo_up(bp)) = SQLITE_OK
	/* If there is no %_docsize table, there should be no requests for
	 ** statements to operate on it.  */
	if **(**uintptr)(__ccgo_up(p + 48 + uintptr(eStmt)*8)) == uintptr(0) {
		azStmt = [12]uintptr{
			0:  __ccgo_ts + 40752,
			1:  __ccgo_ts + 40820,
			2:  __ccgo_ts + 40889,
			3:  __ccgo_ts + 40889,
			4:  __ccgo_ts + 40922,
			5:  __ccgo_ts + 40961,
			6:  __ccgo_ts + 41001,
			7:  __ccgo_ts + 41040,
			8:  __ccgo_ts + 41083,
			9:  __ccgo_ts + 41122,
			10: __ccgo_ts + 41166,
			11: __ccgo_ts + 41206,
		}
		pC = (*TFts5Storage)(unsafe.Pointer(p)).FpConfig
		zSql = uintptr(0)
		switch eStmt {
		case int32(FTS5_STMT_SCAN):
			zSql = Xsqlite3_mprintf(tls, azStmt[eStmt], libc.VaList(bp+16, (*TFts5Config)(unsafe.Pointer(pC)).FzContentExprlist, (*TFts5Config)(unsafe.Pointer(pC)).FzContent))
		case FTS5_STMT_SCAN_ASC:
			fallthrough
		case int32(FTS5_STMT_SCAN_DESC):
			zSql = Xsqlite3_mprintf(tls, azStmt[eStmt], libc.VaList(bp+16, (*TFts5Config)(unsafe.Pointer(pC)).FzContentExprlist, (*TFts5Config)(unsafe.Pointer(pC)).FzContent, (*TFts5Config)(unsafe.Pointer(pC)).FzContentRowid, (*TFts5Config)(unsafe.Pointer(pC)).FzContentRowid, (*TFts5Config)(unsafe.Pointer(pC)).FzContentRowid))
		case int32(FTS5_STMT_LOOKUP):
			fallthrough
		case int32(FTS5_STMT_LOOKUP2):
			zSql = Xsqlite3_mprintf(tls, azStmt[eStmt], libc.VaList(bp+16, (*TFts5Config)(unsafe.Pointer(pC)).FzContentExprlist, (*TFts5Config)(unsafe.Pointer(pC)).FzContent, (*TFts5Config)(unsafe.Pointer(pC)).FzContentRowid))
		case int32(FTS5_STMT_INSERT_CONTENT):
			fallthrough
		case int32(FTS5_STMT_REPLACE_CONTENT):
			zBind = uintptr(0)
			/* Add bindings for the "c*" columns - those that store the actual
			 ** table content. If eContent==NORMAL, then there is one binding
			 ** for each column. Or, if eContent==UNINDEXED, then there are only
			 ** bindings for the UNINDEXED columns. */
			i = 0
			for {
				if !(**(**int32)(__ccgo_up(bp)) == SQLITE_OK && i < (*TFts5Config)(unsafe.Pointer(pC)).FnCol+int32(1)) {
					break
				}
				if !(i != 0) || (*TFts5Config)(unsafe.Pointer(pC)).FeContent == FTS5_CONTENT_NORMAL || **(**Tu8)(__ccgo_up((*TFts5Config)(unsafe.Pointer(pC)).FabUnindexed + uintptr(i-int32(1)))) != 0 {
					if zBind != 0 {
						v2 = __ccgo_ts + 14339
					} else {
						v2 = __ccgo_ts + 1693
					}
					zBind = _sqlite3Fts5Mprintf(tls, bp, __ccgo_ts+41229, libc.VaList(bp+16, zBind, v2, i+int32(1)))
				}
				goto _1
			_1:
				;
				i = i + 1
			}
			/* Add bindings for any "l*" columns. Only non-UNINDEXED columns
			 ** require these.  */
			if (*TFts5Config)(unsafe.Pointer(pC)).FbLocale != 0 && (*TFts5Config)(unsafe.Pointer(pC)).FeContent == FTS5_CONTENT_NORMAL {
				i = 0
				for {
					if !(**(**int32)(__ccgo_up(bp)) == SQLITE_OK && i < (*TFts5Config)(unsafe.Pointer(pC)).FnCol) {
						break
					}
					if libc.Int32FromUint8(**(**Tu8)(__ccgo_up((*TFts5Config)(unsafe.Pointer(pC)).FabUnindexed + uintptr(i)))) == 0 {
						zBind = _sqlite3Fts5Mprintf(tls, bp, __ccgo_ts+41237, libc.VaList(bp+16, zBind, (*TFts5Config)(unsafe.Pointer(pC)).FnCol+i+int32(2)))
					}
					goto _3
				_3:
					;
					i = i + 1
				}
			}
			zSql = _sqlite3Fts5Mprintf(tls, bp, azStmt[eStmt], libc.VaList(bp+16, (*TFts5Config)(unsafe.Pointer(pC)).FzDb, (*TFts5Config)(unsafe.Pointer(pC)).FzName, zBind))
			Xsqlite3_free(tls, zBind)
		case int32(FTS5_STMT_REPLACE_DOCSIZE):
			if (*TFts5Config)(unsafe.Pointer(pC)).FbContentlessDelete != 0 {
				v2 = __ccgo_ts + 41244
			} else {
				v2 = __ccgo_ts + 1693
			}
			zSql = Xsqlite3_mprintf(tls, azStmt[eStmt], libc.VaList(bp+16, (*TFts5Config)(unsafe.Pointer(pC)).FzDb, (*TFts5Config)(unsafe.Pointer(pC)).FzName, v2))
		case int32(FTS5_STMT_LOOKUP_DOCSIZE):
			if (*TFts5Config)(unsafe.Pointer(pC)).FbContentlessDelete != 0 {
				v2 = __ccgo_ts + 41247
			} else {
				v2 = __ccgo_ts + 1693
			}
			zSql = Xsqlite3_mprintf(tls, azStmt[eStmt], libc.VaList(bp+16, v2, (*TFts5Config)(unsafe.Pointer(pC)).FzDb, (*TFts5Config)(unsafe.Pointer(pC)).FzName))
		default:
			zSql = Xsqlite3_mprintf(tls, azStmt[eStmt], libc.VaList(bp+16, (*TFts5Config)(unsafe.Pointer(pC)).FzDb, (*TFts5Config)(unsafe.Pointer(pC)).FzName))
			break
		}
		if zSql == uintptr(0) {
			**(**int32)(__ccgo_up(bp)) = int32(SQLITE_NOMEM)
		} else {
			f = int32(SQLITE_PREPARE_PERSISTENT)
			if eStmt > int32(FTS5_STMT_LOOKUP2) {
				f = f | int32(SQLITE_PREPARE_NO_VTAB)
			}
			(*TFts5Config)(unsafe.Pointer((*TFts5Storage)(unsafe.Pointer(p)).FpConfig)).FbLock = (*TFts5Config)(unsafe.Pointer((*TFts5Storage)(unsafe.Pointer(p)).FpConfig)).FbLock + 1
			**(**int32)(__ccgo_up(bp)) = Xsqlite3_prepare_v3(tls, (*TFts5Config)(unsafe.Pointer(pC)).Fdb, zSql, -int32(1), libc.Uint32FromInt32(f), p+48+uintptr(eStmt)*8, uintptr(0))
			(*TFts5Config)(unsafe.Pointer((*TFts5Storage)(unsafe.Pointer(p)).FpConfig)).FbLock = (*TFts5Config)(unsafe.Pointer((*TFts5Storage)(unsafe.Pointer(p)).FpConfig)).FbLock - 1
			Xsqlite3_free(tls, zSql)
			if **(**int32)(__ccgo_up(bp)) != SQLITE_OK && pzErrMsg != 0 {
				**(**uintptr)(__ccgo_up(pzErrMsg)) = Xsqlite3_mprintf(tls, __ccgo_ts+3933, libc.VaList(bp+16, Xsqlite3_errmsg(tls, (*TFts5Config)(unsafe.Pointer(pC)).Fdb)))
			}
			if **(**int32)(__ccgo_up(bp)) == int32(SQLITE_ERROR) && eStmt > int32(FTS5_STMT_LOOKUP2) && eStmt < int32(FTS5_STMT_SCAN) {
				/* One of the internal tables - not the %_content table - is missing.
				 ** This counts as a corrupted table.  */
				**(**int32)(__ccgo_up(bp)) = int32(SQLITE_CORRUPT)
			}
		}
	}
	**(**uintptr)(__ccgo_up(ppStmt)) = **(**uintptr)(__ccgo_up(p + 48 + uintptr(eStmt)*8))
	Xsqlite3_reset(tls, **(**uintptr)(__ccgo_up(ppStmt)))
	return **(**int32)(__ccgo_up(bp))
}

func _fts5StorageRenameOne(tls *libc.TLS, pConfig uintptr, pRc uintptr, zTail uintptr, zName uintptr) {
	bp := tls.Alloc(48)
	defer tls.Free(48)
	if **(**int32)(__ccgo_up(pRc)) == SQLITE_OK {
		**(**int32)(__ccgo_up(pRc)) = _fts5ExecPrintf(tls, (*TFts5Config)(unsafe.Pointer(pConfig)).Fdb, uintptr(0), __ccgo_ts+41435, libc.VaList(bp+8, (*TFts5Config)(unsafe.Pointer(pConfig)).FzDb, (*TFts5Config)(unsafe.Pointer(pConfig)).FzName, zTail, zName, zTail))
	}
}

// C documentation
//
//	/*
//	** Deserialize and return the structure record currently stored in serialized
//	** form within buffer pData/nData.
//	**
//	** The Fts5Structure.aLevel[] and each Fts5StructureLevel.aSeg[] array
//	** are over-allocated by one slot. This allows the structure contents
//	** to be more easily edited.
//	**
//	** If an error occurs, *ppOut is set to NULL and an SQLite error code
//	** returned. Otherwise, *ppOut is set to point to the new object and
//	** SQLITE_OK returned.
//	*/
func _fts5StructureDecode(tls *libc.TLS, pData uintptr, nData int32, piCookie uintptr, ppOut uintptr) (r int32) {
	bp := tls.Alloc(16)
	defer tls.Free(16)
	var bStructureV2, i, iLvl, iSeg int32
	var nByte Tsqlite3_int64
	var nOriginCntr Tu64
	var pLvl, pRet, pSeg uintptr
	var v3 uint64
	var _ /* nLevel at bp+4 */ int32
	var _ /* nSegment at bp+8 */ int32
	var _ /* nTotal at bp+12 */ int32
	var _ /* rc at bp+0 */ int32
	_, _, _, _, _, _, _, _, _, _ = bStructureV2, i, iLvl, iSeg, nByte, nOriginCntr, pLvl, pRet, pSeg, v3
	**(**int32)(__ccgo_up(bp)) = SQLITE_OK
	i = 0
	**(**int32)(__ccgo_up(bp + 4)) = 0
	**(**int32)(__ccgo_up(bp + 8)) = 0 /* Bytes of space to allocate at pRet */
	pRet = uintptr(0)                  /* Structure object to return */
	bStructureV2 = 0                   /* True for FTS5_STRUCTURE_V2 */
	nOriginCntr = uint64(0)            /* Largest origin value seen so far */
	/* Grab the cookie value */
	if piCookie != 0 {
		**(**int32)(__ccgo_up(piCookie)) = _sqlite3Fts5Get32(tls, pData)
	}
	i = int32(4)
	/* Check if this is a V2 structure record. Set bStructureV2 if it is. */
	if 0 == libc.Xmemcmp(tls, pData+uintptr(i), __ccgo_ts+39077, uint64(4)) {
		i = i + int32(4)
		bStructureV2 = int32(1)
	}
	/* Read the total number of levels and segments from the start of the
	 ** structure record.  */
	i = i + _sqlite3Fts5GetVarint32(tls, pData+uintptr(i), bp+4)
	i = i + _sqlite3Fts5GetVarint32(tls, pData+uintptr(i), bp+8)
	if **(**int32)(__ccgo_up(bp + 4)) > int32(FTS5_MAX_SEGMENT) || **(**int32)(__ccgo_up(bp + 4)) < 0 || **(**int32)(__ccgo_up(bp + 8)) > int32(FTS5_MAX_SEGMENT) || **(**int32)(__ccgo_up(bp + 8)) < 0 {
		return libc.Int32FromInt32(SQLITE_CORRUPT) | libc.Int32FromInt32(1)<<libc.Int32FromInt32(8)
	}
	nByte = libc.Int64FromUint64(uint64(libc.UintptrFromInt32(0)+32) + libc.Uint64FromInt32(**(**int32)(__ccgo_up(bp + 4)))*libc.Uint64FromInt64(16))
	pRet = _sqlite3Fts5MallocZero(tls, bp, nByte)
	if pRet != 0 {
		(*TFts5Structure)(unsafe.Pointer(pRet)).FnRef = int32(1)
		(*TFts5Structure)(unsafe.Pointer(pRet)).FnLevel = **(**int32)(__ccgo_up(bp + 4))
		(*TFts5Structure)(unsafe.Pointer(pRet)).FnSegment = **(**int32)(__ccgo_up(bp + 8))
		i = i + libc.Int32FromUint8(_sqlite3Fts5GetVarint(tls, pData+uintptr(i), pRet+8))
		iLvl = 0
		for {
			if !(**(**int32)(__ccgo_up(bp)) == SQLITE_OK && iLvl < **(**int32)(__ccgo_up(bp + 4))) {
				break
			}
			pLvl = pRet + 32 + uintptr(iLvl)*16
			**(**int32)(__ccgo_up(bp + 12)) = 0
			if i >= nData {
				**(**int32)(__ccgo_up(bp)) = libc.Int32FromInt32(SQLITE_CORRUPT) | libc.Int32FromInt32(1)<<libc.Int32FromInt32(8)
			} else {
				i = i + _sqlite3Fts5GetVarint32(tls, pData+uintptr(i), pLvl)
				i = i + _sqlite3Fts5GetVarint32(tls, pData+uintptr(i), bp+12)
				if **(**int32)(__ccgo_up(bp + 12)) < (*TFts5StructureLevel)(unsafe.Pointer(pLvl)).FnMerge {
					**(**int32)(__ccgo_up(bp)) = libc.Int32FromInt32(SQLITE_CORRUPT) | libc.Int32FromInt32(1)<<libc.Int32FromInt32(8)
				}
				(*TFts5StructureLevel)(unsafe.Pointer(pLvl)).FaSeg = _sqlite3Fts5MallocZero(tls, bp, libc.Int64FromUint64(libc.Uint64FromInt64(int64(**(**int32)(__ccgo_up(bp + 12))))*uint64(56)))
				**(**int32)(__ccgo_up(bp + 8)) = **(**int32)(__ccgo_up(bp + 8)) - **(**int32)(__ccgo_up(bp + 12))
			}
			if **(**int32)(__ccgo_up(bp)) == SQLITE_OK {
				(*TFts5StructureLevel)(unsafe.Pointer(pLvl)).FnSeg = **(**int32)(__ccgo_up(bp + 12))
				iSeg = 0
				for {
					if !(iSeg < **(**int32)(__ccgo_up(bp + 12))) {
						break
					}
					pSeg = (*TFts5StructureLevel)(unsafe.Pointer(pLvl)).FaSeg + uintptr(iSeg)*56
					if i >= nData {
						**(**int32)(__ccgo_up(bp)) = libc.Int32FromInt32(SQLITE_CORRUPT) | libc.Int32FromInt32(1)<<libc.Int32FromInt32(8)
						break
					}
					i = i + _sqlite3Fts5GetVarint32(tls, pData+uintptr(i), pSeg)
					i = i + _sqlite3Fts5GetVarint32(tls, pData+uintptr(i), pSeg+4)
					i = i + _sqlite3Fts5GetVarint32(tls, pData+uintptr(i), pSeg+8)
					if bStructureV2 != 0 {
						i = i + libc.Int32FromUint8(_sqlite3Fts5GetVarint(tls, pData+uintptr(i), pSeg+16))
						i = i + libc.Int32FromUint8(_sqlite3Fts5GetVarint(tls, pData+uintptr(i), pSeg+24))
						i = i + _sqlite3Fts5GetVarint32(tls, pData+uintptr(i), pSeg+32)
						i = i + libc.Int32FromUint8(_sqlite3Fts5GetVarint(tls, pData+uintptr(i), pSeg+40))
						i = i + libc.Int32FromUint8(_sqlite3Fts5GetVarint(tls, pData+uintptr(i), pSeg+48))
						if nOriginCntr > (*TFts5StructureSegment)(unsafe.Pointer(pSeg)).FiOrigin2 {
							v3 = nOriginCntr
						} else {
							v3 = (*TFts5StructureSegment)(unsafe.Pointer(pSeg)).FiOrigin2
						}
						nOriginCntr = v3
					}
					if (*TFts5StructureSegment)(unsafe.Pointer(pSeg)).FpgnoLast < (*TFts5StructureSegment)(unsafe.Pointer(pSeg)).FpgnoFirst {
						**(**int32)(__ccgo_up(bp)) = libc.Int32FromInt32(SQLITE_CORRUPT) | libc.Int32FromInt32(1)<<libc.Int32FromInt32(8)
						break
					}
					goto _2
				_2:
					;
					iSeg = iSeg + 1
				}
				if iLvl > 0 && (**(**TFts5StructureLevel)(__ccgo_up(pLvl + uintptr(-libc.Int32FromInt32(1))*16))).FnMerge != 0 && **(**int32)(__ccgo_up(bp + 12)) == 0 {
					**(**int32)(__ccgo_up(bp)) = libc.Int32FromInt32(SQLITE_CORRUPT) | libc.Int32FromInt32(1)<<libc.Int32FromInt32(8)
				}
				if iLvl == **(**int32)(__ccgo_up(bp + 4))-int32(1) && (*TFts5StructureLevel)(unsafe.Pointer(pLvl)).FnMerge != 0 {
					**(**int32)(__ccgo_up(bp)) = libc.Int32FromInt32(SQLITE_CORRUPT) | libc.Int32FromInt32(1)<<libc.Int32FromInt32(8)
				}
			}
			goto _1
		_1:
			;
			iLvl = iLvl + 1
		}
		if **(**int32)(__ccgo_up(bp + 8)) != 0 && **(**int32)(__ccgo_up(bp)) == SQLITE_OK {
			**(**int32)(__ccgo_up(bp)) = libc.Int32FromInt32(SQLITE_CORRUPT) | libc.Int32FromInt32(1)<<libc.Int32FromInt32(8)
		}
		if bStructureV2 != 0 {
			(*TFts5Structure)(unsafe.Pointer(pRet)).FnOriginCntr = nOriginCntr + uint64(1)
		}
		if **(**int32)(__ccgo_up(bp)) != SQLITE_OK {
			_fts5StructureRelease(tls, pRet)
			pRet = uintptr(0)
		}
	}
	**(**uintptr)(__ccgo_up(ppOut)) = pRet
	return **(**int32)(__ccgo_up(bp))
}

func _fts5StructureReadUncached(tls *libc.TLS, p uintptr) (r uintptr) {
	bp := tls.Alloc(32)
	defer tls.Free(32)
	var pConfig, pData uintptr
	var _ /* iCookie at bp+8 */ int32
	var _ /* pRet at bp+0 */ uintptr
	_, _ = pConfig, pData
	**(**uintptr)(__ccgo_up(bp)) = uintptr(0)
	pConfig = (*TFts5Index)(unsafe.Pointer(p)).FpConfig
	pData = _fts5DataRead(tls, p, int64(FTS5_STRUCTURE_ROWID))
	if (*TFts5Index)(unsafe.Pointer(p)).Frc == SQLITE_OK {
		/* TODO: Do we need this if the leaf-index is appended? Probably... */
		libc.Xmemset(tls, (*TFts5Data)(unsafe.Pointer(pData)).Fp+uintptr((*TFts5Data)(unsafe.Pointer(pData)).Fnn), 0, uint64(FTS5_DATA_PADDING))
		(*TFts5Index)(unsafe.Pointer(p)).Frc = _fts5StructureDecode(tls, (*TFts5Data)(unsafe.Pointer(pData)).Fp, (*TFts5Data)(unsafe.Pointer(pData)).Fnn, bp+8, bp)
		if (*TFts5Index)(unsafe.Pointer(p)).Frc == SQLITE_OK {
			if (*TFts5Config)(unsafe.Pointer(pConfig)).Fpgsz == 0 || (*TFts5Config)(unsafe.Pointer(pConfig)).FiCookie != **(**int32)(__ccgo_up(bp + 8)) {
				(*TFts5Index)(unsafe.Pointer(p)).Frc = _sqlite3Fts5ConfigLoad(tls, pConfig, **(**int32)(__ccgo_up(bp + 8)))
			}
		} else {
			if (*TFts5Index)(unsafe.Pointer(p)).Frc == libc.Int32FromInt32(SQLITE_CORRUPT)|libc.Int32FromInt32(1)<<libc.Int32FromInt32(8) {
				_sqlite3Fts5ConfigErrmsg(tls, (*TFts5Index)(unsafe.Pointer(p)).FpConfig, __ccgo_ts+39082, libc.VaList(bp+24, (*TFts5Config)(unsafe.Pointer((*TFts5Index)(unsafe.Pointer(p)).FpConfig)).FzName))
			}
		}
		_fts5DataRelease(tls, pData)
		if (*TFts5Index)(unsafe.Pointer(p)).Frc != SQLITE_OK {
			_fts5StructureRelease(tls, **(**uintptr)(__ccgo_up(bp)))
			**(**uintptr)(__ccgo_up(bp)) = uintptr(0)
		}
	}
	return **(**uintptr)(__ccgo_up(bp))
}

// C documentation
//
//	/*
//	** Serialize and store the "structure" record.
//	**
//	** If an error occurs, leave an error code in the Fts5Index object. If an
//	** error has already occurred, this function is a no-op.
//	*/
func _fts5StructureWrite(tls *libc.TLS, p uintptr, pStruct uintptr) {
	bp := tls.Alloc(16)
	defer tls.Free(16)
	var iCookie, iLvl, iSeg, nHdr, v1 int32
	var pLvl, pSeg uintptr
	var _ /* buf at bp+0 */ TFts5Buffer
	_, _, _, _, _, _, _ = iCookie, iLvl, iSeg, nHdr, pLvl, pSeg, v1
	if (*TFts5Index)(unsafe.Pointer(p)).Frc == SQLITE_OK {
		if (*TFts5Structure)(unsafe.Pointer(pStruct)).FnOriginCntr > uint64(0) {
			v1 = libc.Int32FromInt32(4) + libc.Int32FromInt32(4) + libc.Int32FromInt32(9) + libc.Int32FromInt32(9) + libc.Int32FromInt32(9)
		} else {
			v1 = libc.Int32FromInt32(4) + libc.Int32FromInt32(9) + libc.Int32FromInt32(9)
		} /* Cookie value to store */
		nHdr = v1
		libc.Xmemset(tls, bp, 0, uint64(16))
		/* Append the current configuration cookie */
		iCookie = (*TFts5Config)(unsafe.Pointer((*TFts5Index)(unsafe.Pointer(p)).FpConfig)).FiCookie
		if iCookie < 0 {
			iCookie = 0
		}
		if 0 == _sqlite3Fts5BufferSize(tls, p+60, bp, libc.Uint32FromInt32(nHdr)) {
			_sqlite3Fts5Put32(tls, (**(**TFts5Buffer)(__ccgo_up(bp))).Fp, iCookie)
			(**(**TFts5Buffer)(__ccgo_up(bp))).Fn = int32(4)
			if (*TFts5Structure)(unsafe.Pointer(pStruct)).FnOriginCntr > uint64(0) {
				libc.Xmemcpy(tls, (*TFts5Buffer)(unsafe.Pointer(bp)).Fp+uintptr((*TFts5Buffer)(unsafe.Pointer(bp)).Fn), __ccgo_ts+39077, uint64(4))
				**(**int32)(__ccgo_up(bp + 8)) += int32(4)
			}
			**(**int32)(__ccgo_up(bp + 8)) += _sqlite3Fts5PutVarint(tls, (*TFts5Buffer)(unsafe.Pointer(bp)).Fp+uintptr((*TFts5Buffer)(unsafe.Pointer(bp)).Fn), libc.Uint64FromInt32((*TFts5Structure)(unsafe.Pointer(pStruct)).FnLevel))
			**(**int32)(__ccgo_up(bp + 8)) += _sqlite3Fts5PutVarint(tls, (*TFts5Buffer)(unsafe.Pointer(bp)).Fp+uintptr((*TFts5Buffer)(unsafe.Pointer(bp)).Fn), libc.Uint64FromInt32((*TFts5Structure)(unsafe.Pointer(pStruct)).FnSegment))
			**(**int32)(__ccgo_up(bp + 8)) += _sqlite3Fts5PutVarint(tls, (*TFts5Buffer)(unsafe.Pointer(bp)).Fp+uintptr((*TFts5Buffer)(unsafe.Pointer(bp)).Fn), libc.Uint64FromInt64(libc.Int64FromUint64((*TFts5Structure)(unsafe.Pointer(pStruct)).FnWriteCounter)))
		}
		iLvl = 0
		for {
			if !(iLvl < (*TFts5Structure)(unsafe.Pointer(pStruct)).FnLevel) {
				break
			} /* Used to iterate through segments */
			pLvl = pStruct + 32 + uintptr(iLvl)*16
			_sqlite3Fts5BufferAppendVarint(tls, p+60, bp, int64((*TFts5StructureLevel)(unsafe.Pointer(pLvl)).FnMerge))
			_sqlite3Fts5BufferAppendVarint(tls, p+60, bp, int64((*TFts5StructureLevel)(unsafe.Pointer(pLvl)).FnSeg))
			iSeg = 0
			for {
				if !(iSeg < (*TFts5StructureLevel)(unsafe.Pointer(pLvl)).FnSeg) {
					break
				}
				pSeg = (*TFts5StructureLevel)(unsafe.Pointer(pLvl)).FaSeg + uintptr(iSeg)*56
				_sqlite3Fts5BufferAppendVarint(tls, p+60, bp, int64((*TFts5StructureSegment)(unsafe.Pointer(pSeg)).FiSegid))
				_sqlite3Fts5BufferAppendVarint(tls, p+60, bp, int64((*TFts5StructureSegment)(unsafe.Pointer(pSeg)).FpgnoFirst))
				_sqlite3Fts5BufferAppendVarint(tls, p+60, bp, int64((*TFts5StructureSegment)(unsafe.Pointer(pSeg)).FpgnoLast))
				if (*TFts5Structure)(unsafe.Pointer(pStruct)).FnOriginCntr > uint64(0) {
					_sqlite3Fts5BufferAppendVarint(tls, p+60, bp, libc.Int64FromUint64((*TFts5StructureSegment)(unsafe.Pointer(pSeg)).FiOrigin1))
					_sqlite3Fts5BufferAppendVarint(tls, p+60, bp, libc.Int64FromUint64((*TFts5StructureSegment)(unsafe.Pointer(pSeg)).FiOrigin2))
					_sqlite3Fts5BufferAppendVarint(tls, p+60, bp, int64((*TFts5StructureSegment)(unsafe.Pointer(pSeg)).FnPgTombstone))
					_sqlite3Fts5BufferAppendVarint(tls, p+60, bp, libc.Int64FromUint64((*TFts5StructureSegment)(unsafe.Pointer(pSeg)).FnEntryTombstone))
					_sqlite3Fts5BufferAppendVarint(tls, p+60, bp, libc.Int64FromUint64((*TFts5StructureSegment)(unsafe.Pointer(pSeg)).FnEntry))
				}
				goto _3
			_3:
				;
				iSeg = iSeg + 1
			}
			goto _2
		_2:
			;
			iLvl = iLvl + 1
		}
		_fts5DataWrite(tls, p, int64(FTS5_STRUCTURE_ROWID), (**(**TFts5Buffer)(__ccgo_up(bp))).Fp, (**(**TFts5Buffer)(__ccgo_up(bp))).Fn)
		_sqlite3Fts5BufferFree(tls, bp)
	}
}

// C documentation
//
//	/*
//	** This function is the implementation of the xUpdate callback used by
//	** FTS3 virtual tables. It is invoked by SQLite each time a row is to be
//	** inserted, updated or deleted.
//	**
//	** A delete specifies a single argument - the rowid of the row to remove.
//	**
//	** Update and insert operations pass:
//	**
//	**   1. The "old" rowid, or NULL.
//	**   2. The "new" rowid.
//	**   3. Values for each of the nCol matchable columns.
//	**   4. Values for the two hidden columns (<tablename> and "rank").
//	*/
func _fts5UpdateMethod(tls *libc.TLS, pVtab uintptr, nArg int32, apVal uintptr, pRowid uintptr) (r int32) {
	bp := tls.Alloc(32)
	defer tls.Free(32)
	var eConflict, eType0, eType1, ii int32
	var iDel, iNew, iNew1, iOld Ti64
	var pConfig, pStorage, pTab, pVal, z uintptr
	var _ /* bContent at bp+4 */ int32
	var _ /* rc at bp+0 */ int32
	_, _, _, _, _, _, _, _, _, _, _, _, _ = eConflict, eType0, eType1, iDel, iNew, iNew1, iOld, ii, pConfig, pStorage, pTab, pVal, z
	pTab = pVtab
	pConfig = (*TFts5FullTable)(unsafe.Pointer(pTab)).Fp.FpConfig /* value_type() of apVal[0] */
	**(**int32)(__ccgo_up(bp)) = SQLITE_OK                        /* Return code */
	/* A transaction must be open when this is called. */
	if (*TFts5Config)(unsafe.Pointer(pConfig)).Fpgsz == 0 {
		**(**int32)(__ccgo_up(bp)) = _sqlite3Fts5ConfigLoad(tls, (*TFts5FullTable)(unsafe.Pointer(pTab)).Fp.FpConfig, (*TFts5Config)(unsafe.Pointer((*TFts5FullTable)(unsafe.Pointer(pTab)).Fp.FpConfig)).FiCookie)
		if **(**int32)(__ccgo_up(bp)) != SQLITE_OK {
			return **(**int32)(__ccgo_up(bp))
		}
	}
	(*TFts5Config)(unsafe.Pointer((*TFts5FullTable)(unsafe.Pointer(pTab)).Fp.FpConfig)).FpzErrmsg = pTab + 16
	/* Put any active cursors into REQUIRE_SEEK state. */
	_fts5TripCursors(tls, pTab)
	eType0 = Xsqlite3_value_type(tls, **(**uintptr)(__ccgo_up(apVal)))
	if eType0 == int32(SQLITE_NULL) && Xsqlite3_value_type(tls, **(**uintptr)(__ccgo_up(apVal + uintptr(int32(2)+(*TFts5Config)(unsafe.Pointer(pConfig)).FnCol)*8))) != int32(SQLITE_NULL) {
		/* A "special" INSERT op. These are handled separately. */
		z = Xsqlite3_value_text(tls, **(**uintptr)(__ccgo_up(apVal + uintptr(int32(2)+(*TFts5Config)(unsafe.Pointer(pConfig)).FnCol)*8)))
		if (*TFts5Config)(unsafe.Pointer(pConfig)).FeContent != FTS5_CONTENT_NORMAL && 0 == Xsqlite3_stricmp(tls, __ccgo_ts+19143, z) {
			if (*TFts5Config)(unsafe.Pointer(pConfig)).FbContentlessDelete != 0 {
				_fts5SetVtabError(tls, pTab, __ccgo_ts+40274, 0)
				**(**int32)(__ccgo_up(bp)) = int32(SQLITE_ERROR)
			} else {
				**(**int32)(__ccgo_up(bp)) = _fts5SpecialDelete(tls, pTab, apVal)
			}
		} else {
			**(**int32)(__ccgo_up(bp)) = _fts5SpecialInsert(tls, pTab, z, **(**uintptr)(__ccgo_up(apVal + uintptr(int32(2)+(*TFts5Config)(unsafe.Pointer(pConfig)).FnCol+int32(1))*8)))
		}
	} else {
		/* A regular INSERT, UPDATE or DELETE statement. The trick here is that
		 ** any conflict on the rowid value must be detected before any
		 ** modifications are made to the database file. There are 4 cases:
		 **
		 **   1) DELETE
		 **   2) UPDATE (rowid not modified)
		 **   3) UPDATE (rowid modified)
		 **   4) INSERT
		 **
		 ** Cases 3 and 4 may violate the rowid constraint.
		 */
		eConflict = int32(SQLITE_ABORT)
		if (*TFts5Config)(unsafe.Pointer(pConfig)).FeContent == FTS5_CONTENT_NORMAL || (*TFts5Config)(unsafe.Pointer(pConfig)).FbContentlessDelete != 0 {
			eConflict = Xsqlite3_vtab_on_conflict(tls, (*TFts5Config)(unsafe.Pointer(pConfig)).Fdb)
		}
		/* DELETE */
		if nArg == int32(1) {
			/* It is only possible to DELETE from a contentless table if the
			 ** contentless_delete=1 flag is set. */
			if _fts5IsContentless(tls, pTab, int32(1)) != 0 && (*TFts5Config)(unsafe.Pointer(pConfig)).FbContentlessDelete == 0 {
				_fts5SetVtabError(tls, pTab, __ccgo_ts+40333, libc.VaList(bp+16, (*TFts5Config)(unsafe.Pointer(pConfig)).FzName))
				**(**int32)(__ccgo_up(bp)) = int32(SQLITE_ERROR)
			} else {
				iDel = Xsqlite3_value_int64(tls, **(**uintptr)(__ccgo_up(apVal))) /* Rowid to delete */
				**(**int32)(__ccgo_up(bp)) = _sqlite3Fts5StorageDelete(tls, (*TFts5FullTable)(unsafe.Pointer(pTab)).FpStorage, iDel, uintptr(0), 0)
			}
		} else {
			eType1 = Xsqlite3_value_numeric_type(tls, **(**uintptr)(__ccgo_up(apVal + 1*8)))
			/* It is an error to write an fts5_locale() value to a table without
			 ** the locale=1 option. */
			if (*TFts5Config)(unsafe.Pointer(pConfig)).FbLocale == 0 {
				ii = 0
				for {
					if !(ii < (*TFts5Config)(unsafe.Pointer(pConfig)).FnCol) {
						break
					}
					pVal = **(**uintptr)(__ccgo_up(apVal + uintptr(ii+int32(2))*8))
					if _sqlite3Fts5IsLocaleValue(tls, pConfig, pVal) != 0 {
						_fts5SetVtabError(tls, pTab, __ccgo_ts+40379, 0)
						**(**int32)(__ccgo_up(bp)) = int32(SQLITE_MISMATCH)
						goto update_out
					}
					goto _1
				_1:
					;
					ii = ii + 1
				}
			}
			if eType0 != int32(SQLITE_INTEGER) {
				/* An INSERT statement. If the conflict-mode is REPLACE, first remove
				 ** the current entry (if any). */
				if eConflict == int32(SQLITE_REPLACE) && eType1 == int32(SQLITE_INTEGER) {
					iNew = Xsqlite3_value_int64(tls, **(**uintptr)(__ccgo_up(apVal + 1*8))) /* Rowid to delete */
					**(**int32)(__ccgo_up(bp)) = _sqlite3Fts5StorageDelete(tls, (*TFts5FullTable)(unsafe.Pointer(pTab)).FpStorage, iNew, uintptr(0), 0)
				}
				_fts5StorageInsert(tls, bp, pTab, apVal, pRowid)
			} else {
				pStorage = (*TFts5FullTable)(unsafe.Pointer(pTab)).FpStorage
				iOld = Xsqlite3_value_int64(tls, **(**uintptr)(__ccgo_up(apVal)))        /* Old rowid */
				iNew1 = Xsqlite3_value_int64(tls, **(**uintptr)(__ccgo_up(apVal + 1*8))) /* New rowid */
				**(**int32)(__ccgo_up(bp + 4)) = 0                                       /* Content only update */
				/* If this is a contentless table (including contentless_unindexed=1
				 ** tables), check if the UPDATE may proceed.  */
				if _fts5IsContentless(tls, pTab, int32(1)) != 0 {
					**(**int32)(__ccgo_up(bp)) = _fts5ContentlessUpdate(tls, pConfig, apVal+2*8, libc.BoolInt32(iOld != iNew1), bp+4)
					if **(**int32)(__ccgo_up(bp)) != SQLITE_OK {
						goto update_out
					}
				}
				if eType1 != int32(SQLITE_INTEGER) {
					**(**int32)(__ccgo_up(bp)) = int32(SQLITE_MISMATCH)
				} else {
					if iOld != iNew1 {
						if eConflict == int32(SQLITE_REPLACE) {
							**(**int32)(__ccgo_up(bp)) = _sqlite3Fts5StorageDelete(tls, pStorage, iOld, uintptr(0), int32(1))
							if **(**int32)(__ccgo_up(bp)) == SQLITE_OK {
								**(**int32)(__ccgo_up(bp)) = _sqlite3Fts5StorageDelete(tls, pStorage, iNew1, uintptr(0), 0)
							}
							_fts5StorageInsert(tls, bp, pTab, apVal, pRowid)
						} else {
							**(**int32)(__ccgo_up(bp)) = _sqlite3Fts5StorageFindDeleteRow(tls, pStorage, iOld)
							if **(**int32)(__ccgo_up(bp)) == SQLITE_OK {
								**(**int32)(__ccgo_up(bp)) = _sqlite3Fts5StorageContentInsert(tls, pStorage, 0, apVal, pRowid)
							}
							if **(**int32)(__ccgo_up(bp)) == SQLITE_OK {
								**(**int32)(__ccgo_up(bp)) = _sqlite3Fts5StorageDelete(tls, pStorage, iOld, uintptr(0), 0)
							}
							if **(**int32)(__ccgo_up(bp)) == SQLITE_OK {
								**(**int32)(__ccgo_up(bp)) = _sqlite3Fts5StorageIndexInsert(tls, pStorage, apVal, **(**Tsqlite_int64)(__ccgo_up(pRowid)))
							}
						}
					} else {
						if **(**int32)(__ccgo_up(bp + 4)) != 0 {
							/* This occurs when an UPDATE on a contentless table affects *only*
							 ** UNINDEXED columns. This is a no-op for contentless_unindexed=0
							 ** tables, or a write to the %_content table only for =1 tables.  */
							**(**int32)(__ccgo_up(bp)) = _sqlite3Fts5StorageFindDeleteRow(tls, pStorage, iOld)
							if **(**int32)(__ccgo_up(bp)) == SQLITE_OK {
								**(**int32)(__ccgo_up(bp)) = _sqlite3Fts5StorageContentInsert(tls, pStorage, int32(1), apVal, pRowid)
							}
						} else {
							**(**int32)(__ccgo_up(bp)) = _sqlite3Fts5StorageDelete(tls, pStorage, iOld, uintptr(0), int32(1))
							_fts5StorageInsert(tls, bp, pTab, apVal, pRowid)
						}
					}
				}
				_sqlite3Fts5StorageReleaseDeleteRow(tls, pStorage)
			}
		}
	}
	goto update_out
update_out:
	;
	_sqlite3Fts5IndexCloseReader(tls, (*TFts5FullTable)(unsafe.Pointer(pTab)).Fp.FpIndex)
	(*TFts5Config)(unsafe.Pointer((*TFts5FullTable)(unsafe.Pointer(pTab)).Fp.FpConfig)).FpzErrmsg = uintptr(0)
	return **(**int32)(__ccgo_up(bp))
}

// C documentation
//
//	/*
//	** Return the value in pVal interpreted as utf-8 text. Except, if pVal
//	** contains a NULL value, return a pointer to a static string zero
//	** bytes in length instead of a NULL pointer.
//	*/
func _fts5ValueToText(tls *libc.TLS, pVal uintptr) (r uintptr) {
	var zRet, v1 uintptr
	_, _ = zRet, v1
	zRet = Xsqlite3_value_text(tls, pVal)
	if zRet != 0 {
		v1 = zRet
	} else {
		v1 = __ccgo_ts + 1693
	}
	return v1
}

// C documentation
//
//	/*
//	** This is the xFilter implementation for the virtual table.
//	*/
func _fts5VocabFilterMethod(tls *libc.TLS, pCursor uintptr, idxNum int32, zUnused uintptr, nUnused int32, apVal uintptr) (r int32) {
	var eType, f, iVal, nTerm, rc, v1 int32
	var pCsr, pEq, pGe, pIndex, pLe, pTab, zCopy, zTerm uintptr
	_, _, _, _, _, _, _, _, _, _, _, _, _, _ = eType, f, iVal, nTerm, pCsr, pEq, pGe, pIndex, pLe, pTab, rc, zCopy, zTerm, v1
	pTab = (*Tsqlite3_vtab_cursor)(unsafe.Pointer(pCursor)).FpVtab
	pCsr = pCursor
	eType = (*TFts5VocabTable)(unsafe.Pointer(pTab)).FeType
	rc = SQLITE_OK
	iVal = 0
	f = int32(FTS5INDEX_QUERY_SCAN)
	zTerm = uintptr(0)
	nTerm = 0
	pEq = uintptr(0)
	pGe = uintptr(0)
	pLe = uintptr(0)
	_ = zUnused
	_ = nUnused
	_fts5VocabResetCursor(tls, pCsr)
	if idxNum&int32(FTS5_VOCAB_TERM_EQ) != 0 {
		v1 = iVal
		iVal = iVal + 1
		pEq = **(**uintptr)(__ccgo_up(apVal + uintptr(v1)*8))
	}
	if idxNum&int32(FTS5_VOCAB_TERM_GE) != 0 {
		v1 = iVal
		iVal = iVal + 1
		pGe = **(**uintptr)(__ccgo_up(apVal + uintptr(v1)*8))
	}
	if idxNum&int32(FTS5_VOCAB_TERM_LE) != 0 {
		v1 = iVal
		iVal = iVal + 1
		pLe = **(**uintptr)(__ccgo_up(apVal + uintptr(v1)*8))
	}
	(*TFts5VocabCursor)(unsafe.Pointer(pCsr)).FcolUsed = idxNum & int32(FTS5_VOCAB_COLUSED_MASK)
	if pEq != 0 {
		zTerm = Xsqlite3_value_text(tls, pEq)
		nTerm = Xsqlite3_value_bytes(tls, pEq)
		f = int32(FTS5INDEX_QUERY_NOTOKENDATA)
	} else {
		if pGe != 0 {
			zTerm = Xsqlite3_value_text(tls, pGe)
			nTerm = Xsqlite3_value_bytes(tls, pGe)
		}
		if pLe != 0 {
			zCopy = Xsqlite3_value_text(tls, pLe)
			if zCopy == uintptr(0) {
				zCopy = __ccgo_ts + 1693
			}
			(*TFts5VocabCursor)(unsafe.Pointer(pCsr)).FnLeTerm = Xsqlite3_value_bytes(tls, pLe)
			(*TFts5VocabCursor)(unsafe.Pointer(pCsr)).FzLeTerm = Xsqlite3_malloc64(tls, libc.Uint64FromInt64(int64((*TFts5VocabCursor)(unsafe.Pointer(pCsr)).FnLeTerm)+int64(1)))
			if (*TFts5VocabCursor)(unsafe.Pointer(pCsr)).FzLeTerm == uintptr(0) {
				rc = int32(SQLITE_NOMEM)
			} else {
				libc.Xmemcpy(tls, (*TFts5VocabCursor)(unsafe.Pointer(pCsr)).FzLeTerm, zCopy, libc.Uint64FromInt32((*TFts5VocabCursor)(unsafe.Pointer(pCsr)).FnLeTerm+int32(1)))
			}
		}
	}
	if rc == SQLITE_OK {
		pIndex = (*TFts5Table)(unsafe.Pointer((*TFts5VocabCursor)(unsafe.Pointer(pCsr)).FpFts5)).FpIndex
		rc = _sqlite3Fts5IndexQuery(tls, pIndex, zTerm, nTerm, f, uintptr(0), pCsr+32)
		if rc == SQLITE_OK {
			(*TFts5VocabCursor)(unsafe.Pointer(pCsr)).FpStruct = _sqlite3Fts5StructureRef(tls, pIndex)
		}
	}
	if rc == SQLITE_OK && eType == int32(FTS5_VOCAB_INSTANCE) {
		rc = _fts5VocabInstanceNewTerm(tls, pCsr)
	}
	if rc == SQLITE_OK && !((*TFts5VocabCursor)(unsafe.Pointer(pCsr)).FbEof != 0) && (eType != int32(FTS5_VOCAB_INSTANCE) || (*TFts5Config)(unsafe.Pointer((*TFts5Table)(unsafe.Pointer((*TFts5VocabCursor)(unsafe.Pointer(pCsr)).FpFts5)).FpConfig)).FeDetail != int32(FTS5_DETAIL_NONE)) {
		rc = _fts5VocabNextMethod(tls, pCursor)
	}
	return rc
}

// 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  ("fts5vocab")
//	**   argv[1]   -> database name
//	**   argv[2]   -> table name
//	**
//	** then:
//	**
//	**   argv[3]   -> name of fts5 table
//	**   argv[4]   -> type of fts5vocab table
//	**
//	** or, for tables in the TEMP schema only.
//	**
//	**   argv[3]   -> name of fts5 tables database
//	**   argv[4]   -> name of fts5 table
//	**   argv[5]   -> type of fts5vocab table
//	*/
func _fts5VocabInitVtab(tls *libc.TLS, db uintptr, pAux uintptr, argc int32, argv uintptr, ppVTab uintptr, pzErr uintptr) (r int32) {
	bp := tls.Alloc(16)
	defer tls.Free(16)
	var azSchema [3]uintptr
	var bDb int32
	var nByte, nDb, nTab Ti64
	var pRet, zDb, zTab, zType, v1, v2, v3 uintptr
	var _ /* eType at bp+4 */ int32
	var _ /* rc at bp+0 */ int32
	_, _, _, _, _, _, _, _, _, _, _, _ = azSchema, bDb, nByte, nDb, nTab, pRet, zDb, zTab, zType, v1, v2, v3
	azSchema = [3]uintptr{
		0: __ccgo_ts + 42259,
		1: __ccgo_ts + 42299,
		2: __ccgo_ts + 42334,
	}
	pRet = uintptr(0)
	**(**int32)(__ccgo_up(bp)) = SQLITE_OK
	bDb = libc.BoolInt32(argc == int32(6) && libc.Xstrlen(tls, **(**uintptr)(__ccgo_up(argv + 1*8))) == uint64(4) && libc.Xmemcmp(tls, __ccgo_ts+25253, **(**uintptr)(__ccgo_up(argv + 1*8)), uint64(4)) == 0)
	if argc != int32(5) && bDb == 0 {
		**(**uintptr)(__ccgo_up(pzErr)) = Xsqlite3_mprintf(tls, __ccgo_ts+42377, 0)
		**(**int32)(__ccgo_up(bp)) = int32(SQLITE_ERROR)
	} else {
		if bDb != 0 {
			v1 = **(**uintptr)(__ccgo_up(argv + 3*8))
		} else {
			v1 = **(**uintptr)(__ccgo_up(argv + 1*8))
		} /* Bytes of space to allocate */
		zDb = v1
		if bDb != 0 {
			v2 = **(**uintptr)(__ccgo_up(argv + 4*8))
		} else {
			v2 = **(**uintptr)(__ccgo_up(argv + 3*8))
		}
		zTab = v2
		if bDb != 0 {
			v3 = **(**uintptr)(__ccgo_up(argv + 5*8))
		} else {
			v3 = **(**uintptr)(__ccgo_up(argv + 4*8))
		}
		zType = v3
		nDb = libc.Int64FromUint64(libc.Xstrlen(tls, zDb) + uint64(1))
		nTab = libc.Int64FromUint64(libc.Xstrlen(tls, zTab) + uint64(1))
		**(**int32)(__ccgo_up(bp + 4)) = 0
		**(**int32)(__ccgo_up(bp)) = _fts5VocabTableType(tls, zType, pzErr, bp+4)
		if **(**int32)(__ccgo_up(bp)) == SQLITE_OK {
			**(**int32)(__ccgo_up(bp)) = Xsqlite3_declare_vtab(tls, db, azSchema[**(**int32)(__ccgo_up(bp + 4))])
		}
		nByte = libc.Int64FromUint64(uint64(64) + libc.Uint64FromInt64(nDb) + libc.Uint64FromInt64(nTab))
		pRet = _sqlite3Fts5MallocZero(tls, bp, nByte)
		if pRet != 0 {
			(*TFts5VocabTable)(unsafe.Pointer(pRet)).FpGlobal = pAux
			(*TFts5VocabTable)(unsafe.Pointer(pRet)).FeType = **(**int32)(__ccgo_up(bp + 4))
			(*TFts5VocabTable)(unsafe.Pointer(pRet)).Fdb = db
			(*TFts5VocabTable)(unsafe.Pointer(pRet)).FzFts5Tbl = pRet + 1*64
			(*TFts5VocabTable)(unsafe.Pointer(pRet)).FzFts5Db = (*TFts5VocabTable)(unsafe.Pointer(pRet)).FzFts5Tbl + uintptr(nTab)
			libc.Xmemcpy(tls, (*TFts5VocabTable)(unsafe.Pointer(pRet)).FzFts5Tbl, zTab, libc.Uint64FromInt64(nTab))
			libc.Xmemcpy(tls, (*TFts5VocabTable)(unsafe.Pointer(pRet)).FzFts5Db, zDb, libc.Uint64FromInt64(nDb))
			_sqlite3Fts5Dequote(tls, (*TFts5VocabTable)(unsafe.Pointer(pRet)).FzFts5Tbl)
			_sqlite3Fts5Dequote(tls, (*TFts5VocabTable)(unsafe.Pointer(pRet)).FzFts5Db)
		}
	}
	**(**uintptr)(__ccgo_up(ppVTab)) = pRet
	return **(**int32)(__ccgo_up(bp))
}

// C documentation
//
//	/*
//	** Implementation of xOpen method.
//	*/
func _fts5VocabOpenMethod(tls *libc.TLS, pVTab uintptr, ppCsr uintptr) (r int32) {
	bp := tls.Alloc(64)
	defer tls.Free(64)
	var iId, nByte Ti64
	var pCsr, pFts5, pTab, zSql uintptr
	var _ /* pStmt at bp+8 */ uintptr
	var _ /* rc at bp+0 */ int32
	_, _, _, _, _, _ = iId, nByte, pCsr, pFts5, pTab, zSql
	pTab = pVTab
	pFts5 = uintptr(0)
	pCsr = uintptr(0)
	**(**int32)(__ccgo_up(bp)) = SQLITE_OK
	**(**uintptr)(__ccgo_up(bp + 8)) = uintptr(0)
	zSql = uintptr(0)
	if (*TFts5VocabTable)(unsafe.Pointer(pTab)).FbBusy != 0 {
		(*Tsqlite3_vtab)(unsafe.Pointer(pVTab)).FzErrMsg = Xsqlite3_mprintf(tls, __ccgo_ts+42410, libc.VaList(bp+24, (*TFts5VocabTable)(unsafe.Pointer(pTab)).FzFts5Db, (*TFts5VocabTable)(unsafe.Pointer(pTab)).FzFts5Tbl))
		return int32(SQLITE_ERROR)
	}
	zSql = _sqlite3Fts5Mprintf(tls, bp, __ccgo_ts+42441, libc.VaList(bp+24, (*TFts5VocabTable)(unsafe.Pointer(pTab)).FzFts5Tbl, (*TFts5VocabTable)(unsafe.Pointer(pTab)).FzFts5Db, (*TFts5VocabTable)(unsafe.Pointer(pTab)).FzFts5Tbl, (*TFts5VocabTable)(unsafe.Pointer(pTab)).FzFts5Tbl))
	if zSql != 0 {
		**(**int32)(__ccgo_up(bp)) = Xsqlite3_prepare_v2(tls, (*TFts5VocabTable)(unsafe.Pointer(pTab)).Fdb, zSql, -int32(1), bp+8, uintptr(0))
	}
	Xsqlite3_free(tls, zSql)
	if **(**int32)(__ccgo_up(bp)) == int32(SQLITE_ERROR) {
		**(**int32)(__ccgo_up(bp)) = SQLITE_OK
	}
	(*TFts5VocabTable)(unsafe.Pointer(pTab)).FbBusy = uint32(1)
	if **(**uintptr)(__ccgo_up(bp + 8)) != 0 && Xsqlite3_step(tls, **(**uintptr)(__ccgo_up(bp + 8))) == int32(SQLITE_ROW) {
		iId = Xsqlite3_column_int64(tls, **(**uintptr)(__ccgo_up(bp + 8)), 0)
		pFts5 = _sqlite3Fts5TableFromCsrid(tls, (*TFts5VocabTable)(unsafe.Pointer(pTab)).FpGlobal, iId)
	}
	(*TFts5VocabTable)(unsafe.Pointer(pTab)).FbBusy = uint32(0)
	if **(**int32)(__ccgo_up(bp)) == SQLITE_OK {
		if pFts5 == uintptr(0) {
			**(**int32)(__ccgo_up(bp)) = Xsqlite3_finalize(tls, **(**uintptr)(__ccgo_up(bp + 8)))
			**(**uintptr)(__ccgo_up(bp + 8)) = uintptr(0)
			if **(**int32)(__ccgo_up(bp)) == SQLITE_OK {
				(*Tsqlite3_vtab)(unsafe.Pointer(pVTab)).FzErrMsg = Xsqlite3_mprintf(tls, __ccgo_ts+42492, libc.VaList(bp+24, (*TFts5VocabTable)(unsafe.Pointer(pTab)).FzFts5Db, (*TFts5VocabTable)(unsafe.Pointer(pTab)).FzFts5Tbl))
				**(**int32)(__ccgo_up(bp)) = int32(SQLITE_ERROR)
			}
		} else {
			**(**int32)(__ccgo_up(bp)) = _sqlite3Fts5FlushToDisk(tls, pFts5)
		}
	}
	if **(**int32)(__ccgo_up(bp)) == SQLITE_OK {
		nByte = libc.Int64FromUint64(libc.Uint64FromInt32((*TFts5Config)(unsafe.Pointer((*TFts5Table)(unsafe.Pointer(pFts5)).FpConfig)).FnCol)*uint64(8)*uint64(2) + uint64(128))
		pCsr = _sqlite3Fts5MallocZero(tls, bp, nByte)
	}
	if pCsr != 0 {
		(*TFts5VocabCursor)(unsafe.Pointer(pCsr)).FpFts5 = pFts5
		(*TFts5VocabCursor)(unsafe.Pointer(pCsr)).FpStmt = **(**uintptr)(__ccgo_up(bp + 8))
		(*TFts5VocabCursor)(unsafe.Pointer(pCsr)).FaCnt = pCsr + 1*128
		(*TFts5VocabCursor)(unsafe.Pointer(pCsr)).FaDoc = (*TFts5VocabCursor)(unsafe.Pointer(pCsr)).FaCnt + uintptr((*TFts5Config)(unsafe.Pointer((*TFts5Table)(unsafe.Pointer(pFts5)).FpConfig)).FnCol)*8
	} else {
		Xsqlite3_finalize(tls, **(**uintptr)(__ccgo_up(bp + 8)))
	}
	**(**uintptr)(__ccgo_up(ppCsr)) = pCsr
	return **(**int32)(__ccgo_up(bp))
}

// C documentation
//
//	/*
//	** Translate a string containing an fts5vocab table type to an
//	** FTS5_VOCAB_XXX constant. If successful, set *peType to the output
//	** value and return SQLITE_OK. Otherwise, set *pzErr to an error message
//	** and return SQLITE_ERROR.
//	*/
func _fts5VocabTableType(tls *libc.TLS, zType uintptr, pzErr uintptr, peType uintptr) (r int32) {
	bp := tls.Alloc(32)
	defer tls.Free(32)
	var zCopy uintptr
	var _ /* rc at bp+0 */ int32
	_ = zCopy
	**(**int32)(__ccgo_up(bp)) = SQLITE_OK
	zCopy = _sqlite3Fts5Strndup(tls, bp, zType, -int32(1))
	if **(**int32)(__ccgo_up(bp)) == SQLITE_OK {
		_sqlite3Fts5Dequote(tls, zCopy)
		if Xsqlite3_stricmp(tls, zCopy, __ccgo_ts+42208) == 0 {
			**(**int32)(__ccgo_up(peType)) = FTS5_VOCAB_COL
		} else {
			if Xsqlite3_stricmp(tls, zCopy, __ccgo_ts+42212) == 0 {
				**(**int32)(__ccgo_up(peType)) = int32(FTS5_VOCAB_ROW)
			} else {
				if Xsqlite3_stricmp(tls, zCopy, __ccgo_ts+42216) == 0 {
					**(**int32)(__ccgo_up(peType)) = int32(FTS5_VOCAB_INSTANCE)
				} else {
					**(**uintptr)(__ccgo_up(pzErr)) = Xsqlite3_mprintf(tls, __ccgo_ts+42225, libc.VaList(bp+16, zCopy))
					**(**int32)(__ccgo_up(bp)) = int32(SQLITE_ERROR)
				}
			}
		}
		Xsqlite3_free(tls, zCopy)
	}
	return **(**int32)(__ccgo_up(bp))
}

// C documentation
//
//	/*
//	** This function is called whenever processing of the doclist for the
//	** last term on leaf page (pWriter->iBtPage) is completed.
//	**
//	** The doclist-index for that term is currently stored in-memory within the
//	** Fts5SegWriter.aDlidx[] array. If it is large enough, this function
//	** writes it out to disk. Or, if it is too small to bother with, discards
//	** it.
//	**
//	** Fts5SegWriter.btterm currently contains the first term on page iBtPage.
//	*/
func _fts5WriteFlushBtree(tls *libc.TLS, p uintptr, pWriter uintptr) {
	var bFlag int32
	var z, v1 uintptr
	_, _, _ = bFlag, z, v1
	if (*TFts5SegWriter)(unsafe.Pointer(pWriter)).FiBtPage == 0 {
		return
	}
	bFlag = _fts5WriteFlushDlidx(tls, p, pWriter)
	if (*TFts5Index)(unsafe.Pointer(p)).Frc == SQLITE_OK {
		if (*TFts5SegWriter)(unsafe.Pointer(pWriter)).Fbtterm.Fn > 0 {
			v1 = (*TFts5SegWriter)(unsafe.Pointer(pWriter)).Fbtterm.Fp
		} else {
			v1 = __ccgo_ts + 1693
		}
		z = v1
		/* The following was already done in fts5WriteInit(): */
		/* sqlite3_bind_int(p->pIdxWriter, 1, pWriter->iSegid); */
		Xsqlite3_bind_blob(tls, (*TFts5Index)(unsafe.Pointer(p)).FpIdxWriter, int32(2), z, (*TFts5SegWriter)(unsafe.Pointer(pWriter)).Fbtterm.Fn, libc.UintptrFromInt32(0))
		Xsqlite3_bind_int64(tls, (*TFts5Index)(unsafe.Pointer(p)).FpIdxWriter, int32(3), int64(bFlag)+int64((*TFts5SegWriter)(unsafe.Pointer(pWriter)).FiBtPage)<<libc.Int32FromInt32(1))
		Xsqlite3_step(tls, (*TFts5Index)(unsafe.Pointer(p)).FpIdxWriter)
		(*TFts5Index)(unsafe.Pointer(p)).Frc = Xsqlite3_reset(tls, (*TFts5Index)(unsafe.Pointer(p)).FpIdxWriter)
		Xsqlite3_bind_null(tls, (*TFts5Index)(unsafe.Pointer(p)).FpIdxWriter, int32(2))
	}
	(*TFts5SegWriter)(unsafe.Pointer(pWriter)).FiBtPage = 0
}

func _fts5WriteInit(tls *libc.TLS, p uintptr, pWriter uintptr, iSegid int32) {
	bp := tls.Alloc(32)
	defer tls.Free(32)
	var nBuffer int32
	var pConfig uintptr
	_, _ = nBuffer, pConfig
	nBuffer = (*TFts5Config)(unsafe.Pointer((*TFts5Index)(unsafe.Pointer(p)).FpConfig)).Fpgsz + int32(FTS5_DATA_PADDING)
	libc.Xmemset(tls, pWriter, 0, uint64(120))
	(*TFts5SegWriter)(unsafe.Pointer(pWriter)).FiSegid = iSegid
	_fts5WriteDlidxGrow(tls, p, pWriter, int32(1))
	(*TFts5SegWriter)(unsafe.Pointer(pWriter)).Fwriter.Fpgno = int32(1)
	(*TFts5SegWriter)(unsafe.Pointer(pWriter)).FbFirstTermInPage = uint8(1)
	(*TFts5SegWriter)(unsafe.Pointer(pWriter)).FiBtPage = int32(1)
	/* Grow the two buffers to pgsz + padding bytes in size. */
	_sqlite3Fts5BufferSize(tls, p+60, pWriter+8+24, libc.Uint32FromInt32(nBuffer))
	_sqlite3Fts5BufferSize(tls, p+60, pWriter+8+8, libc.Uint32FromInt32(nBuffer))
	if (*TFts5Index)(unsafe.Pointer(p)).FpIdxWriter == uintptr(0) {
		pConfig = (*TFts5Index)(unsafe.Pointer(p)).FpConfig
		_fts5IndexPrepareStmt(tls, p, p+96, Xsqlite3_mprintf(tls, __ccgo_ts+39317, libc.VaList(bp+8, (*TFts5Config)(unsafe.Pointer(pConfig)).FzDb, (*TFts5Config)(unsafe.Pointer(pConfig)).FzName)))
	}
	if (*TFts5Index)(unsafe.Pointer(p)).Frc == SQLITE_OK {
		/* Initialize the 4-byte leaf-page header to 0x00. */
		libc.Xmemset(tls, (*TFts5SegWriter)(unsafe.Pointer(pWriter)).Fwriter.Fbuf.Fp, 0, uint64(4))
		(*TFts5SegWriter)(unsafe.Pointer(pWriter)).Fwriter.Fbuf.Fn = int32(4)
		/* Bind the current output segment id to the index-writer. This is an
		 ** optimization over binding the same value over and over as rows are
		 ** inserted into %_idx by the current writer.  */
		Xsqlite3_bind_int(tls, (*TFts5Index)(unsafe.Pointer(p)).FpIdxWriter, int32(1), (*TFts5SegWriter)(unsafe.Pointer(pWriter)).FiSegid)
	}
}

// C documentation
//
//	/*
//	** The following routine is called if the stack overflows.
//	*/
func _fts5yyStackOverflow(tls *libc.TLS, fts5yypParser uintptr) {
	var pParse uintptr
	_ = pParse
	pParse = (*Tfts5yyParser)(unsafe.Pointer(fts5yypParser)).FpParse
	for (*Tfts5yyParser)(unsafe.Pointer(fts5yypParser)).Ffts5yytos > (*Tfts5yyParser)(unsafe.Pointer(fts5yypParser)).Ffts5yystack {
		_fts5yy_pop_parser_stack(tls, fts5yypParser)
	}
	/* Here code is inserted which will execute if the parser
	 ** stack every overflows */
	/******** Begin %stack_overflow code ******************************************/
	_sqlite3Fts5ParseError(tls, pParse, __ccgo_ts+37079, 0)
	/******** End %stack_overflow code ********************************************/
	(*Tfts5yyParser)(unsafe.Pointer(fts5yypParser)).FpParse = pParse /* Suppress warning about unused %extra_argument var */
}

/*
** Print tracing information for a SHIFT action
 */

// C documentation
//
//	/*
//	** The following code executes when a syntax error first occurs.
//	*/
func _fts5yy_syntax_error(tls *libc.TLS, fts5yypParser uintptr, fts5yymajor int32, fts5yyminor TFts5Token) {
	bp := tls.Alloc(32)
	defer tls.Free(32)
	var pParse uintptr
	_ = pParse
	pParse = (*Tfts5yyParser)(unsafe.Pointer(fts5yypParser)).FpParse
	/************ Begin %syntax_error code ****************************************/
	_ = fts5yymajor /* Silence a compiler warning */
	_sqlite3Fts5ParseError(tls, pParse, __ccgo_ts+37107, libc.VaList(bp+8, fts5yyminor.Fn, fts5yyminor.Fp))
	/************ End %syntax_error code ******************************************/
	(*Tfts5yyParser)(unsafe.Pointer(fts5yypParser)).FpParse = pParse /* Suppress warning about unused %extra_argument variable */
}

// C documentation
//
//	/*
//	** Code an output subroutine for a coroutine implementation of a
//	** SELECT statement.
//	**
//	** The data to be output is contained in an array of pIn->nSdst registers
//	** starting at register pIn->iSdst.  pDest is where the output should
//	** be sent.
//	**
//	** regReturn is the number of the register holding the subroutine
//	** return address.
//	**
//	** If regPrev>0 then it is the first register in a vector that
//	** records the previous output.  mem[regPrev] is a flag that is false
//	** if there has been no previous output.  If regPrev>0 then code is
//	** generated to suppress duplicates.  pKeyInfo is used for comparing
//	** keys.
//	**
//	** If the LIMIT found in p->iLimit is reached, jump immediately to
//	** iBreak.
//	*/
func _generateOutputSubroutine(tls *libc.TLS, pParse uintptr, p uintptr, pIn uintptr, pDest uintptr, regReturn int32, regPrev int32, pKeyInfo uintptr, iBreak int32) (r int32) {
	var addr, addr1, addr2, iContinue, iParm, iParm1, ii, nKey, r1, r11, r12, r2, r21, r3 int32
	var pSO, v uintptr
	_, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _ = addr, addr1, addr2, iContinue, iParm, iParm1, ii, nKey, pSO, r1, r11, r12, r2, r21, r3, v
	v = (*TParse)(unsafe.Pointer(pParse)).FpVdbe
	addr = _sqlite3VdbeCurrentAddr(tls, v)
	iContinue = _sqlite3VdbeMakeLabel(tls, pParse)
	/* Suppress duplicates for UNION, EXCEPT, and INTERSECT
	 */
	if regPrev != 0 {
		addr1 = _sqlite3VdbeAddOp1(tls, v, int32(OP_IfNot), regPrev)
		addr2 = _sqlite3VdbeAddOp4(tls, v, int32(OP_Compare), (*TSelectDest)(unsafe.Pointer(pIn)).FiSdst, regPrev+int32(1), (*TSelectDest)(unsafe.Pointer(pIn)).FnSdst, _sqlite3KeyInfoRef(tls, pKeyInfo), -int32(9))
		_sqlite3VdbeAddOp3(tls, v, int32(OP_Jump), addr2+int32(2), iContinue, addr2+int32(2))
		_sqlite3VdbeJumpHere(tls, v, addr1)
		_sqlite3VdbeAddOp3(tls, v, int32(OP_Copy), (*TSelectDest)(unsafe.Pointer(pIn)).FiSdst, regPrev+int32(1), (*TSelectDest)(unsafe.Pointer(pIn)).FnSdst-int32(1))
		_sqlite3VdbeAddOp2(tls, v, int32(OP_Integer), int32(1), regPrev)
	}
	if (*Tsqlite3)(unsafe.Pointer((*TParse)(unsafe.Pointer(pParse)).Fdb)).FmallocFailed != 0 {
		return 0
	}
	/* Suppress the first OFFSET entries if there is an OFFSET clause
	 */
	_codeOffset(tls, v, (*TSelect)(unsafe.Pointer(p)).FiOffset, iContinue)
	switch libc.Int32FromUint8((*TSelectDest)(unsafe.Pointer(pDest)).FeDest) {
	/* Store the result as data using a unique key.
	 */
	case int32(SRT_Fifo):
		fallthrough
	case int32(SRT_DistFifo):
		fallthrough
	case int32(SRT_Table):
		fallthrough
	case int32(SRT_EphemTab):
		r1 = _sqlite3GetTempReg(tls, pParse)
		r2 = _sqlite3GetTempReg(tls, pParse)
		iParm = (*TSelectDest)(unsafe.Pointer(pDest)).FiSDParm
		_sqlite3VdbeAddOp3(tls, v, int32(OP_MakeRecord), (*TSelectDest)(unsafe.Pointer(pIn)).FiSdst, (*TSelectDest)(unsafe.Pointer(pIn)).FnSdst, r1)
		if libc.Int32FromUint8((*TSelectDest)(unsafe.Pointer(pDest)).FeDest) == int32(SRT_DistFifo) {
			/* If the destination is DistFifo, then cursor (iParm+1) is open
			 ** on an ephemeral index that is used to enforce uniqueness on the
			 ** total result.  At this point, we are processing the setup portion
			 ** of the recursive CTE using the merge algorithm, so the results are
			 ** guaranteed to be unique anyhow.  But we still need to populate the
			 ** (iParm+1) cursor for use by the subsequent recursive phase.
			 */
			_sqlite3VdbeAddOp4Int(tls, v, int32(OP_IdxInsert), iParm+int32(1), r1, (*TSelectDest)(unsafe.Pointer(pIn)).FiSdst, (*TSelectDest)(unsafe.Pointer(pIn)).FnSdst)
		}
		_sqlite3VdbeAddOp2(tls, v, int32(OP_NewRowid), iParm, r2)
		_sqlite3VdbeAddOp3(tls, v, int32(OP_Insert), iParm, r1, r2)
		_sqlite3VdbeChangeP5(tls, v, uint16(OPFLAG_APPEND))
		_sqlite3ReleaseTempReg(tls, pParse, r2)
		_sqlite3ReleaseTempReg(tls, pParse, r1)
		break
		/* If any row exist in the result set, record that fact and abort.
		 */
		fallthrough
	case int32(SRT_Exists):
		_sqlite3VdbeAddOp2(tls, v, int32(OP_Integer), int32(1), (*TSelectDest)(unsafe.Pointer(pDest)).FiSDParm)
		/* The LIMIT clause will terminate the loop for us */
		break
		/* If we are creating a set for an "expr IN (SELECT ...)".
		 */
		fallthrough
	case int32(SRT_Set):
		r11 = _sqlite3GetTempReg(tls, pParse)
		_sqlite3VdbeAddOp4(tls, v, int32(OP_MakeRecord), (*TSelectDest)(unsafe.Pointer(pIn)).FiSdst, (*TSelectDest)(unsafe.Pointer(pIn)).FnSdst, r11, (*TSelectDest)(unsafe.Pointer(pDest)).FzAffSdst, (*TSelectDest)(unsafe.Pointer(pIn)).FnSdst)
		_sqlite3VdbeAddOp4Int(tls, v, int32(OP_IdxInsert), (*TSelectDest)(unsafe.Pointer(pDest)).FiSDParm, r11, (*TSelectDest)(unsafe.Pointer(pIn)).FiSdst, (*TSelectDest)(unsafe.Pointer(pIn)).FnSdst)
		if (*TSelectDest)(unsafe.Pointer(pDest)).FiSDParm2 > 0 {
			_sqlite3VdbeAddOp4Int(tls, v, int32(OP_FilterAdd), (*TSelectDest)(unsafe.Pointer(pDest)).FiSDParm2, 0, (*TSelectDest)(unsafe.Pointer(pIn)).FiSdst, (*TSelectDest)(unsafe.Pointer(pIn)).FnSdst)
			_sqlite3VdbeExplain(tls, pParse, uint8(0), __ccgo_ts+20458, 0)
		}
		_sqlite3ReleaseTempReg(tls, pParse, r11)
		break
		/* If this is a scalar select that is part of an expression, then
		 ** store the results in the appropriate memory cell and break out
		 ** of the scan loop.  Note that the select might return multiple columns
		 ** if it is the RHS of a row-value IN operator.
		 */
		fallthrough
	case int32(SRT_Mem):
		_sqlite3ExprCodeMove(tls, pParse, (*TSelectDest)(unsafe.Pointer(pIn)).FiSdst, (*TSelectDest)(unsafe.Pointer(pDest)).FiSDParm, (*TSelectDest)(unsafe.Pointer(pIn)).FnSdst)
		/* The LIMIT clause will jump out of the loop for us */
		break
		/* The results are stored in a sequence of registers
		 ** starting at pDest->iSdst.  Then the co-routine yields.
		 */
		fallthrough
	case int32(SRT_Coroutine):
		if (*TSelectDest)(unsafe.Pointer(pDest)).FiSdst == 0 {
			(*TSelectDest)(unsafe.Pointer(pDest)).FiSdst = _sqlite3GetTempRange(tls, pParse, (*TSelectDest)(unsafe.Pointer(pIn)).FnSdst)
			(*TSelectDest)(unsafe.Pointer(pDest)).FnSdst = (*TSelectDest)(unsafe.Pointer(pIn)).FnSdst
		}
		_sqlite3ExprCodeMove(tls, pParse, (*TSelectDest)(unsafe.Pointer(pIn)).FiSdst, (*TSelectDest)(unsafe.Pointer(pDest)).FiSdst, (*TSelectDest)(unsafe.Pointer(pIn)).FnSdst)
		_sqlite3VdbeAddOp1(tls, v, int32(OP_Yield), (*TSelectDest)(unsafe.Pointer(pDest)).FiSDParm)
		break
		/* Write the results into a priority queue that is order according to
		 ** pDest->pOrderBy (in pSO).  pDest->iSDParm (in iParm) is the cursor for an
		 ** index with pSO->nExpr+2 columns.  Build a key using pSO for the first
		 ** pSO->nExpr columns, then make sure all keys are unique by adding a
		 ** final OP_Sequence column.  The last column is the record as a blob.
		 */
		fallthrough
	case int32(SRT_DistQueue):
		fallthrough
	case int32(SRT_Queue):
		iParm1 = (*TSelectDest)(unsafe.Pointer(pDest)).FiSDParm
		pSO = (*TSelectDest)(unsafe.Pointer(pDest)).FpOrderBy
		nKey = (*TExprList)(unsafe.Pointer(pSO)).FnExpr
		r12 = _sqlite3GetTempReg(tls, pParse)
		r21 = _sqlite3GetTempRange(tls, pParse, nKey+int32(2))
		r3 = r21 + nKey + int32(1)
		_sqlite3VdbeAddOp3(tls, v, int32(OP_MakeRecord), (*TSelectDest)(unsafe.Pointer(pIn)).FiSdst, (*TSelectDest)(unsafe.Pointer(pIn)).FnSdst, r3)
		if libc.Int32FromUint8((*TSelectDest)(unsafe.Pointer(pDest)).FeDest) == int32(SRT_DistQueue) {
			_sqlite3VdbeAddOp2(tls, v, int32(OP_IdxInsert), iParm1+int32(1), r3)
		}
		ii = 0
		for {
			if !(ii < nKey) {
				break
			}
			_sqlite3VdbeAddOp2(tls, v, int32(OP_SCopy), (*TSelectDest)(unsafe.Pointer(pIn)).FiSdst+libc.Int32FromUint16(*(*Tu16)(unsafe.Pointer(pSO + 8 + uintptr(ii)*32 + 24)))-int32(1), r21+ii)
			goto _1
		_1:
			;
			ii = ii + 1
		}
		_sqlite3VdbeAddOp2(tls, v, int32(OP_Sequence), iParm1, r21+nKey)
		_sqlite3VdbeAddOp3(tls, v, int32(OP_MakeRecord), r21, nKey+int32(2), r12)
		_sqlite3VdbeAddOp4Int(tls, v, int32(OP_IdxInsert), iParm1, r12, r21, nKey+int32(2))
		_sqlite3ReleaseTempReg(tls, pParse, r12)
		_sqlite3ReleaseTempRange(tls, pParse, r21, nKey+int32(2))
		break
		/* Ignore the output */
		fallthrough
	case int32(SRT_Discard):
		break
		/* If none of the above, then the result destination must be
		 ** SRT_Output.
		 **
		 ** For SRT_Output, results are stored in a sequence of registers.
		 ** Then the OP_ResultRow opcode is used to cause sqlite3_step() to
		 ** return the next row of result.
		 */
		fallthrough
	default:
		_sqlite3VdbeAddOp2(tls, v, int32(OP_ResultRow), (*TSelectDest)(unsafe.Pointer(pIn)).FiSdst, (*TSelectDest)(unsafe.Pointer(pIn)).FnSdst)
		break
	}
	/* Jump to the end of the loop if the LIMIT is reached.
	 */
	if (*TSelect)(unsafe.Pointer(p)).FiLimit != 0 {
		_sqlite3VdbeAddOp2(tls, v, int32(OP_DecrJumpZero), (*TSelect)(unsafe.Pointer(p)).FiLimit, iBreak)
	}
	/* Generate the subroutine return
	 */
	_sqlite3VdbeResolveLabel(tls, v, iContinue)
	_sqlite3VdbeAddOp1(tls, v, int32(OP_Return), regReturn)
	return addr
}

// C documentation
//
//	/*
//	** If the inner loop was generated using a non-null pOrderBy argument,
//	** then the results were placed in a sorter.  After the loop is terminated
//	** we need to run the sorter and output the results.  The following
//	** routine generates the code needed to do that.
//	*/
func _generateSortTail(tls *libc.TLS, pParse uintptr, p uintptr, pSort uintptr, nColumn int32, pDest uintptr) {
	bp := tls.Alloc(16)
	defer tls.Free(16)
	var aOutEx, pOrderBy, v, v1, v3 uintptr
	var addr, addrBreak, addrContinue, addrOnce, bSeq, eDest, i, i2, iCol, iParm, iRead, iSortTab, iTab, nKey, nRefKey, r1, regRow, regRowid, regSortOut, v2, v4 int32
	_, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _ = aOutEx, addr, addrBreak, addrContinue, addrOnce, bSeq, eDest, i, i2, iCol, iParm, iRead, iSortTab, iTab, nKey, nRefKey, pOrderBy, r1, regRow, regRowid, regSortOut, v, v1, v2, v3, v4
	v = (*TParse)(unsafe.Pointer(pParse)).FpVdbe              /* The prepared statement */
	addrBreak = (*TSortCtx)(unsafe.Pointer(pSort)).FlabelDone /* Jump here to exit loop */
	addrContinue = _sqlite3VdbeMakeLabel(tls, pParse)         /* Top of output loop. Jump for Next. */
	addrOnce = 0
	pOrderBy = (*TSortCtx)(unsafe.Pointer(pSort)).FpOrderBy
	eDest = libc.Int32FromUint8((*TSelectDest)(unsafe.Pointer(pDest)).FeDest)
	iParm = (*TSelectDest)(unsafe.Pointer(pDest)).FiSDParm /* True if sorter record includes seq. no. */
	nRefKey = 0
	aOutEx = (*TSelect)(unsafe.Pointer(p)).FpEList + 8
	nKey = (*TExprList)(unsafe.Pointer(pOrderBy)).FnExpr - (*TSortCtx)(unsafe.Pointer(pSort)).FnOBSat
	if (*TSortCtx)(unsafe.Pointer(pSort)).FnOBSat == 0 || nKey == int32(1) {
		if (*TSortCtx)(unsafe.Pointer(pSort)).FnOBSat != 0 {
			v1 = __ccgo_ts + 20534
		} else {
			v1 = __ccgo_ts + 1693
		}
		_sqlite3VdbeExplain(tls, pParse, uint8(0), __ccgo_ts+20548, libc.VaList(bp+8, v1))
	} else {
		_sqlite3VdbeExplain(tls, pParse, uint8(0), __ccgo_ts+20579, libc.VaList(bp+8, nKey))
	}
	if (*TSortCtx)(unsafe.Pointer(pSort)).FlabelBkOut != 0 {
		_sqlite3VdbeAddOp2(tls, v, int32(OP_Gosub), (*TSortCtx)(unsafe.Pointer(pSort)).FregReturn, (*TSortCtx)(unsafe.Pointer(pSort)).FlabelBkOut)
		_sqlite3VdbeGoto(tls, v, addrBreak)
		_sqlite3VdbeResolveLabel(tls, v, (*TSortCtx)(unsafe.Pointer(pSort)).FlabelBkOut)
	}
	iTab = (*TSortCtx)(unsafe.Pointer(pSort)).FiECursor
	if eDest == int32(SRT_Output) || eDest == int32(SRT_Coroutine) || eDest == int32(SRT_Mem) {
		if eDest == int32(SRT_Mem) && (*TSelect)(unsafe.Pointer(p)).FiOffset != 0 {
			_sqlite3VdbeAddOp2(tls, v, int32(OP_Null), 0, (*TSelectDest)(unsafe.Pointer(pDest)).FiSdst)
		}
		regRowid = 0
		regRow = (*TSelectDest)(unsafe.Pointer(pDest)).FiSdst
	} else {
		regRowid = _sqlite3GetTempReg(tls, pParse)
		if eDest == int32(SRT_EphemTab) || eDest == int32(SRT_Table) {
			regRow = _sqlite3GetTempReg(tls, pParse)
			nColumn = 0
		} else {
			regRow = _sqlite3GetTempRange(tls, pParse, nColumn)
		}
	}
	if libc.Int32FromUint8((*TSortCtx)(unsafe.Pointer(pSort)).FsortFlags)&int32(SORTFLAG_UseSorter) != 0 {
		v1 = pParse + 60
		*(*int32)(unsafe.Pointer(v1)) = *(*int32)(unsafe.Pointer(v1)) + 1
		v2 = *(*int32)(unsafe.Pointer(v1))
		regSortOut = v2
		v3 = pParse + 56
		v4 = *(*int32)(unsafe.Pointer(v3))
		*(*int32)(unsafe.Pointer(v3)) = *(*int32)(unsafe.Pointer(v3)) + 1
		iSortTab = v4
		if (*TSortCtx)(unsafe.Pointer(pSort)).FlabelBkOut != 0 {
			addrOnce = _sqlite3VdbeAddOp0(tls, v, int32(OP_Once))
		}
		_sqlite3VdbeAddOp3(tls, v, int32(OP_OpenPseudo), iSortTab, regSortOut, nKey+int32(1)+nColumn+nRefKey)
		if addrOnce != 0 {
			_sqlite3VdbeJumpHere(tls, v, addrOnce)
		}
		addr = int32(1) + _sqlite3VdbeAddOp2(tls, v, int32(OP_SorterSort), iTab, addrBreak)
		_sqlite3VdbeAddOp3(tls, v, int32(OP_SorterData), iTab, regSortOut, iSortTab)
		bSeq = 0
	} else {
		addr = int32(1) + _sqlite3VdbeAddOp2(tls, v, int32(OP_Sort), iTab, addrBreak)
		_codeOffset(tls, v, (*TSelect)(unsafe.Pointer(p)).FiOffset, addrContinue)
		iSortTab = iTab
		bSeq = int32(1)
		if (*TSelect)(unsafe.Pointer(p)).FiOffset > 0 {
			_sqlite3VdbeAddOp2(tls, v, int32(OP_AddImm), (*TSelect)(unsafe.Pointer(p)).FiLimit, -int32(1))
		}
	}
	i = 0
	iCol = nKey + bSeq - libc.Int32FromInt32(1)
	for {
		if !(i < nColumn) {
			break
		}
		if libc.Int32FromUint16(*(*Tu16)(unsafe.Pointer(aOutEx + uintptr(i)*32 + 24))) == 0 {
			iCol = iCol + 1
		}
		goto _6
	_6:
		;
		i = i + 1
	}
	i = nColumn - int32(1)
	for {
		if !(i >= 0) {
			break
		}
		if *(*Tu16)(unsafe.Pointer(aOutEx + uintptr(i)*32 + 24)) != 0 {
			iRead = libc.Int32FromUint16(*(*Tu16)(unsafe.Pointer(aOutEx + uintptr(i)*32 + 24))) - int32(1)
		} else {
			v2 = iCol
			iCol = iCol - 1
			iRead = v2
		}
		_sqlite3VdbeAddOp3(tls, v, int32(OP_Column), iSortTab, iRead, regRow+i)
		goto _7
	_7:
		;
		i = i - 1
	}
	switch eDest {
	case int32(SRT_Table):
		fallthrough
	case int32(SRT_EphemTab):
		_sqlite3VdbeAddOp3(tls, v, int32(OP_Column), iSortTab, nKey+bSeq, regRow)
		_sqlite3VdbeAddOp2(tls, v, int32(OP_NewRowid), iParm, regRowid)
		_sqlite3VdbeAddOp3(tls, v, int32(OP_Insert), iParm, regRow, regRowid)
		_sqlite3VdbeChangeP5(tls, v, uint16(OPFLAG_APPEND))
	case int32(SRT_Set):
		_sqlite3VdbeAddOp4(tls, v, int32(OP_MakeRecord), regRow, nColumn, regRowid, (*TSelectDest)(unsafe.Pointer(pDest)).FzAffSdst, nColumn)
		_sqlite3VdbeAddOp4Int(tls, v, int32(OP_IdxInsert), iParm, regRowid, regRow, nColumn)
	case int32(SRT_Mem):
		/* The LIMIT clause will terminate the loop for us */
	case int32(SRT_Upfrom):
		i2 = (*TSelectDest)(unsafe.Pointer(pDest)).FiSDParm2
		r1 = _sqlite3GetTempReg(tls, pParse)
		_sqlite3VdbeAddOp3(tls, v, int32(OP_MakeRecord), regRow+libc.BoolInt32(i2 < 0), nColumn-libc.BoolInt32(i2 < 0), r1)
		if i2 < 0 {
			_sqlite3VdbeAddOp3(tls, v, int32(OP_Insert), iParm, r1, regRow)
		} else {
			_sqlite3VdbeAddOp4Int(tls, v, int32(OP_IdxInsert), iParm, r1, regRow, i2)
		}
	default:
		if eDest == int32(SRT_Output) {
			_sqlite3VdbeAddOp2(tls, v, int32(OP_ResultRow), (*TSelectDest)(unsafe.Pointer(pDest)).FiSdst, nColumn)
		} else {
			_sqlite3VdbeAddOp1(tls, v, int32(OP_Yield), (*TSelectDest)(unsafe.Pointer(pDest)).FiSDParm)
		}
		break
	}
	if regRowid != 0 {
		if eDest == int32(SRT_Set) {
			_sqlite3ReleaseTempRange(tls, pParse, regRow, nColumn)
		} else {
			_sqlite3ReleaseTempReg(tls, pParse, regRow)
		}
		_sqlite3ReleaseTempReg(tls, pParse, regRowid)
	}
	/* The bottom of the loop
	 */
	_sqlite3VdbeResolveLabel(tls, v, addrContinue)
	if libc.Int32FromUint8((*TSortCtx)(unsafe.Pointer(pSort)).FsortFlags)&int32(SORTFLAG_UseSorter) != 0 {
		_sqlite3VdbeAddOp2(tls, v, int32(OP_SorterNext), iTab, addr)
	} else {
		_sqlite3VdbeAddOp2(tls, v, int32(OP_Next), iTab, addr)
	}
	if (*TSortCtx)(unsafe.Pointer(pSort)).FregReturn != 0 {
		_sqlite3VdbeAddOp1(tls, v, int32(OP_Return), (*TSortCtx)(unsafe.Pointer(pSort)).FregReturn)
	}
	_sqlite3VdbeResolveLabel(tls, v, addrBreak)
}

// C documentation
//
//	/*
//	** This routine generates VDBE code to compute the content of a WITH RECURSIVE
//	** query of the form:
//	**
//	**   <recursive-table> AS (<setup-query> UNION [ALL] <recursive-query>)
//	**                         \___________/             \_______________/
//	**                           p->pPrior                      p
//	**
//	**
//	** There is exactly one reference to the recursive-table in the FROM clause
//	** of recursive-query, marked with the SrcList->a[].fg.isRecursive flag.
//	**
//	** The setup-query runs once to generate an initial set of rows that go
//	** into a Queue table.  Rows are extracted from the Queue table one by
//	** one.  Each row extracted from Queue is output to pDest.  Then the single
//	** extracted row (now in the iCurrent table) becomes the content of the
//	** recursive-table for a recursive-query run.  The output of the recursive-query
//	** is added back into the Queue table.  Then another row is extracted from Queue
//	** and the iteration continues until the Queue table is empty.
//	**
//	** If the compound query operator is UNION then no duplicate rows are ever
//	** inserted into the Queue table.  The iDistinct table keeps a copy of all rows
//	** that have ever been inserted into Queue and causes duplicates to be
//	** discarded.  If the operator is UNION ALL, then duplicates are allowed.
//	**
//	** If the query has an ORDER BY, then entries in the Queue table are kept in
//	** ORDER BY order and the first entry is extracted for each cycle.  Without
//	** an ORDER BY, the Queue table is just a FIFO.
//	**
//	** If a LIMIT clause is provided, then the iteration stops after LIMIT rows
//	** have been output to pDest.  A LIMIT of zero means to output no rows and a
//	** negative LIMIT means to output all rows.  If there is also an OFFSET clause
//	** with a positive value, then the first OFFSET outputs are discarded rather
//	** than being sent to pDest.  The LIMIT count does not begin until after OFFSET
//	** rows have been skipped.
//	*/
func _generateWithRecursiveQuery(tls *libc.TLS, pParse uintptr, p uintptr, pDest uintptr) {
	bp := tls.Alloc(48)
	defer tls.Free(48)
	var addrBreak, addrCont, addrTop, eDest, i, iCurrent, iDistinct, iQueue, nCol, rc, regCurrent, regLimit, regOffset, v1 int32
	var apColl, pFirstRec, pKeyInfo, pKeyInfo1, pLimit, pOrderBy, pSetup, pSrc, v, v4 uintptr
	var _ /* destQueue at bp+0 */ TSelectDest
	_, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _ = addrBreak, addrCont, addrTop, apColl, eDest, i, iCurrent, iDistinct, iQueue, nCol, pFirstRec, pKeyInfo, pKeyInfo1, pLimit, pOrderBy, pSetup, pSrc, rc, regCurrent, regLimit, regOffset, v, v1, v4
	pSrc = (*TSelect)(unsafe.Pointer(p)).FpSrc                                        /* The FROM clause of the recursive query */
	nCol = (*TExprList)(unsafe.Pointer((*TSelect)(unsafe.Pointer(p)).FpEList)).FnExpr /* Number of columns in the recursive table */
	v = (*TParse)(unsafe.Pointer(pParse)).FpVdbe                                      /* CONTINUE and BREAK addresses */
	iCurrent = 0                                                                      /* The Queue table */
	iDistinct = 0                                                                     /* To ensure unique results if UNION */
	eDest = int32(SRT_Fifo)                                                           /* Registers used by LIMIT and OFFSET */
	if (*TSelect)(unsafe.Pointer(p)).FpWin != 0 {
		_sqlite3ErrorMsg(tls, pParse, __ccgo_ts+20686, 0)
		return
	}
	/* Obtain authorization to do a recursive query */
	if _sqlite3AuthCheck(tls, pParse, int32(SQLITE_RECURSIVE), uintptr(0), uintptr(0), uintptr(0)) != 0 {
		return
	}
	/* Process the LIMIT and OFFSET clauses, if they exist */
	addrBreak = _sqlite3VdbeMakeLabel(tls, pParse)
	(*TSelect)(unsafe.Pointer(p)).FnSelectRow = int16(320) /* 4 billion rows */
	_computeLimitRegisters(tls, pParse, p, addrBreak)
	pLimit = (*TSelect)(unsafe.Pointer(p)).FpLimit
	regLimit = (*TSelect)(unsafe.Pointer(p)).FiLimit
	regOffset = (*TSelect)(unsafe.Pointer(p)).FiOffset
	(*TSelect)(unsafe.Pointer(p)).FpLimit = uintptr(0)
	v1 = libc.Int32FromInt32(0)
	(*TSelect)(unsafe.Pointer(p)).FiOffset = v1
	(*TSelect)(unsafe.Pointer(p)).FiLimit = v1
	pOrderBy = (*TSelect)(unsafe.Pointer(p)).FpOrderBy
	/* Locate the cursor number of the Current table */
	i = 0
	for {
		if !(i < (*TSrcList)(unsafe.Pointer(pSrc)).FnSrc) {
			break
		}
		if int32(*(*uint32)(unsafe.Pointer(pSrc + 8 + uintptr(i)*80 + 24 + 4))&0x80>>7) != 0 {
			iCurrent = (*(*TSrcItem)(unsafe.Pointer(pSrc + 8 + uintptr(i)*80))).FiCursor
			break
		}
		goto _2
	_2:
		;
		i = i + 1
	}
	/* Allocate cursors numbers for Queue and Distinct.  The cursor number for
	 ** the Distinct table must be exactly one greater than Queue in order
	 ** for the SRT_DistFifo and SRT_DistQueue destinations to work. */
	v4 = pParse + 56
	v1 = *(*int32)(unsafe.Pointer(v4))
	*(*int32)(unsafe.Pointer(v4)) = *(*int32)(unsafe.Pointer(v4)) + 1
	iQueue = v1
	if libc.Int32FromUint8((*TSelect)(unsafe.Pointer(p)).Fop) == int32(TK_UNION) {
		if pOrderBy != 0 {
			v1 = int32(SRT_DistQueue)
		} else {
			v1 = int32(SRT_DistFifo)
		}
		eDest = v1
		v4 = pParse + 56
		v1 = *(*int32)(unsafe.Pointer(v4))
		*(*int32)(unsafe.Pointer(v4)) = *(*int32)(unsafe.Pointer(v4)) + 1
		iDistinct = v1
	} else {
		if pOrderBy != 0 {
			v1 = int32(SRT_Queue)
		} else {
			v1 = int32(SRT_Fifo)
		}
		eDest = v1
	}
	_sqlite3SelectDestInit(tls, bp, eDest, iQueue)
	/* Allocate cursors for Current, Queue, and Distinct. */
	v4 = pParse + 60
	*(*int32)(unsafe.Pointer(v4)) = *(*int32)(unsafe.Pointer(v4)) + 1
	v1 = *(*int32)(unsafe.Pointer(v4))
	regCurrent = v1
	_sqlite3VdbeAddOp3(tls, v, int32(OP_OpenPseudo), iCurrent, regCurrent, nCol)
	if pOrderBy != 0 {
		pKeyInfo = _multiSelectByMergeKeyInfo(tls, pParse, p, int32(1))
		_sqlite3VdbeAddOp4(tls, v, int32(OP_OpenEphemeral), iQueue, (*TExprList)(unsafe.Pointer(pOrderBy)).FnExpr+int32(2), 0, pKeyInfo, -int32(9))
		(**(**TSelectDest)(__ccgo_up(bp))).FpOrderBy = pOrderBy
	} else {
		_sqlite3VdbeAddOp2(tls, v, int32(OP_OpenEphemeral), iQueue, nCol)
	}
	if iDistinct != 0 { /* For looping through pKeyInfo->aColl[] */
		nCol = (*TExprList)(unsafe.Pointer((*TSelect)(unsafe.Pointer(p)).FpEList)).FnExpr
		pKeyInfo1 = _sqlite3KeyInfoAlloc(tls, (*TParse)(unsafe.Pointer(pParse)).Fdb, nCol, int32(1))
		if pKeyInfo1 != 0 {
			i = 0
			apColl = pKeyInfo1 + 32
			for {
				if !(i < nCol) {
					break
				}
				**(**uintptr)(__ccgo_up(apColl)) = _multiSelectCollSeq(tls, pParse, p, i)
				if uintptr(0) == **(**uintptr)(__ccgo_up(apColl)) {
					**(**uintptr)(__ccgo_up(apColl)) = (*Tsqlite3)(unsafe.Pointer((*TParse)(unsafe.Pointer(pParse)).Fdb)).FpDfltColl
				}
				goto _11
			_11:
				;
				i = i + 1
				apColl += 8
			}
			_sqlite3VdbeAddOp4(tls, v, int32(OP_OpenEphemeral), iDistinct, nCol, 0, pKeyInfo1, -int32(9))
		} else {
		}
	}
	/* Detach the ORDER BY clause from the compound SELECT */
	(*TSelect)(unsafe.Pointer(p)).FpOrderBy = uintptr(0)
	/* Figure out how many elements of the compound SELECT are part of the
	 ** recursive query.  Make sure no recursive elements use aggregate
	 ** functions.  Mark the recursive elements as UNION ALL even if they
	 ** are really UNION because the distinctness will be enforced by the
	 ** iDistinct table.  pFirstRec is left pointing to the left-most
	 ** recursive term of the CTE.
	 */
	pFirstRec = p
	for {
		if !(pFirstRec != uintptr(0)) {
			break
		}
		if (*TSelect)(unsafe.Pointer(pFirstRec)).FselFlags&uint32(SF_Aggregate) != 0 {
			_sqlite3ErrorMsg(tls, pParse, __ccgo_ts+20735, 0)
			goto end_of_recursive_query
		}
		(*TSelect)(unsafe.Pointer(pFirstRec)).Fop = uint8(TK_ALL)
		if (*TSelect)(unsafe.Pointer((*TSelect)(unsafe.Pointer(pFirstRec)).FpPrior)).FselFlags&uint32(SF_Recursive) == uint32(0) {
			break
		}
		goto _12
	_12:
		;
		pFirstRec = (*TSelect)(unsafe.Pointer(pFirstRec)).FpPrior
	}
	/* Store the results of the setup-query in Queue. */
	pSetup = (*TSelect)(unsafe.Pointer(pFirstRec)).FpPrior
	(*TSelect)(unsafe.Pointer(pSetup)).FpNext = uintptr(0)
	_sqlite3VdbeExplain(tls, pParse, uint8(1), __ccgo_ts+20777, 0)
	rc = _sqlite3Select(tls, pParse, pSetup, bp)
	(*TSelect)(unsafe.Pointer(pSetup)).FpNext = p
	if rc != 0 {
		goto end_of_recursive_query
	}
	/* Find the next row in the Queue and output that row */
	addrTop = _sqlite3VdbeAddOp2(tls, v, int32(OP_Rewind), iQueue, addrBreak)
	/* Transfer the next row in Queue over to Current */
	_sqlite3VdbeAddOp1(tls, v, int32(OP_NullRow), iCurrent) /* To reset column cache */
	if pOrderBy != 0 {
		_sqlite3VdbeAddOp3(tls, v, int32(OP_Column), iQueue, (*TExprList)(unsafe.Pointer(pOrderBy)).FnExpr+int32(1), regCurrent)
	} else {
		_sqlite3VdbeAddOp2(tls, v, int32(OP_RowData), iQueue, regCurrent)
	}
	_sqlite3VdbeAddOp1(tls, v, int32(OP_Delete), iQueue)
	/* Output the single row in Current */
	addrCont = _sqlite3VdbeMakeLabel(tls, pParse)
	_codeOffset(tls, v, regOffset, addrCont)
	_selectInnerLoop(tls, pParse, p, iCurrent, uintptr(0), uintptr(0), pDest, addrCont, addrBreak)
	if regLimit != 0 {
		_sqlite3VdbeAddOp2(tls, v, int32(OP_DecrJumpZero), regLimit, addrBreak)
	}
	_sqlite3VdbeResolveLabel(tls, v, addrCont)
	/* Execute the recursive SELECT taking the single row in Current as
	 ** the value for the recursive-table. Store the results in the Queue.
	 */
	(*TSelect)(unsafe.Pointer(pFirstRec)).FpPrior = uintptr(0)
	_sqlite3VdbeExplain(tls, pParse, uint8(1), __ccgo_ts+20783, 0)
	_sqlite3Select(tls, pParse, p, bp)
	(*TSelect)(unsafe.Pointer(pFirstRec)).FpPrior = pSetup
	/* Keep running the loop until the Queue is empty */
	_sqlite3VdbeGoto(tls, v, addrTop)
	_sqlite3VdbeResolveLabel(tls, v, addrBreak)
	goto end_of_recursive_query
end_of_recursive_query:
	;
	_sqlite3ExprListDelete(tls, (*TParse)(unsafe.Pointer(pParse)).Fdb, (*TSelect)(unsafe.Pointer(p)).FpOrderBy)
	(*TSelect)(unsafe.Pointer(p)).FpOrderBy = pOrderBy
	(*TSelect)(unsafe.Pointer(p)).FpLimit = pLimit
	return
}

// C documentation
//
//	/*
//	** Each call to sqlite3_rtree_geometry_callback() or
//	** sqlite3_rtree_query_callback() creates an ordinary SQLite
//	** scalar function that is implemented by this routine.
//	**
//	** All this function does is construct an RtreeMatchArg object that
//	** contains the geometry-checking callback routines and a list of
//	** parameters to this function, then return that RtreeMatchArg object
//	** as a BLOB.
//	**
//	** The R-Tree MATCH operator will read the returned BLOB, deserialize
//	** the RtreeMatchArg object, and use the RtreeMatchArg object to figure
//	** out which elements of the R-Tree should be returned by the query.
//	*/
func _geomCallback(tls *libc.TLS, ctx uintptr, nArg int32, aArg uintptr) {
	var i, memErr int32
	var nBlob Tsqlite3_int64
	var pBlob, pGeomCtx uintptr
	_, _, _, _, _ = i, memErr, nBlob, pBlob, pGeomCtx
	pGeomCtx = Xsqlite3_user_data(tls, ctx)
	memErr = 0
	nBlob = libc.Int64FromUint64(uint64(libc.UintptrFromInt32(0)+56) + libc.Uint64FromInt32(nArg)*uint64(8) + libc.Uint64FromInt32(nArg)*uint64(8))
	pBlob = Xsqlite3_malloc64(tls, libc.Uint64FromInt64(nBlob))
	if !(pBlob != 0) {
		Xsqlite3_result_error_nomem(tls, ctx)
	} else {
		(*TRtreeMatchArg)(unsafe.Pointer(pBlob)).FiSize = libc.Uint32FromInt64(nBlob)
		(*TRtreeMatchArg)(unsafe.Pointer(pBlob)).Fcb = **(**TRtreeGeomCallback)(__ccgo_up(pGeomCtx))
		(*TRtreeMatchArg)(unsafe.Pointer(pBlob)).FapSqlParam = pBlob + 56 + uintptr(nArg)*8
		(*TRtreeMatchArg)(unsafe.Pointer(pBlob)).FnParam = nArg
		i = 0
		for {
			if !(i < nArg) {
				break
			}
			**(**uintptr)(__ccgo_up((*TRtreeMatchArg)(unsafe.Pointer(pBlob)).FapSqlParam + uintptr(i)*8)) = Xsqlite3_value_dup(tls, **(**uintptr)(__ccgo_up(aArg + uintptr(i)*8)))
			if **(**uintptr)(__ccgo_up((*TRtreeMatchArg)(unsafe.Pointer(pBlob)).FapSqlParam + uintptr(i)*8)) == uintptr(0) {
				memErr = int32(1)
			}
			*(*TRtreeDValue)(unsafe.Pointer(pBlob + 56 + uintptr(i)*8)) = Xsqlite3_value_double(tls, **(**uintptr)(__ccgo_up(aArg + uintptr(i)*8)))
			goto _1
		_1:
			;
			i = i + 1
		}
		if memErr != 0 {
			Xsqlite3_result_error_nomem(tls, ctx)
			_rtreeMatchArgFree(tls, pBlob)
		} else {
			Xsqlite3_result_pointer(tls, ctx, pBlob, __ccgo_ts+27484, __ccgo_fp(_rtreeMatchArgFree))
		}
	}
}

// C documentation
//
//	/*
//	** Rtree virtual table module xBestIndex method. There are three
//	** table scan strategies to choose from (in order from most to
//	** least desirable):
//	**
//	**   idxNum     idxStr        Strategy
//	**   ------------------------------------------------
//	**     1        "rowid"       Direct lookup by rowid.
//	**     2        "rtree"       R-tree overlap query using geopoly_overlap()
//	**     3        "rtree"       R-tree within query using geopoly_within()
//	**     4        "fullscan"    full-table scan.
//	**   ------------------------------------------------
//	*/
func _geopolyBestIndex(tls *libc.TLS, tab uintptr, pIdxInfo uintptr) (r int32) {
	var iFuncTerm, iRowidTerm, idxNum, ii int32
	var p uintptr
	_, _, _, _, _ = iFuncTerm, iRowidTerm, idxNum, ii, p
	iRowidTerm = -int32(1)
	iFuncTerm = -int32(1)
	idxNum = 0
	_ = tab
	ii = 0
	for {
		if !(ii < (*Tsqlite3_index_info)(unsafe.Pointer(pIdxInfo)).FnConstraint) {
			break
		}
		p = (*Tsqlite3_index_info)(unsafe.Pointer(pIdxInfo)).FaConstraint + uintptr(ii)*12
		if !((*Tsqlite3_index_constraint)(unsafe.Pointer(p)).Fusable != 0) {
			goto _1
		}
		if (*Tsqlite3_index_constraint)(unsafe.Pointer(p)).FiColumn < 0 && libc.Int32FromUint8((*Tsqlite3_index_constraint)(unsafe.Pointer(p)).Fop) == int32(SQLITE_INDEX_CONSTRAINT_EQ) {
			iRowidTerm = ii
			break
		}
		if (*Tsqlite3_index_constraint)(unsafe.Pointer(p)).FiColumn == 0 && libc.Int32FromUint8((*Tsqlite3_index_constraint)(unsafe.Pointer(p)).Fop) >= int32(SQLITE_INDEX_CONSTRAINT_FUNCTION) {
			/* p->op==SQLITE_INDEX_CONSTRAINT_FUNCTION for geopoly_overlap()
			 ** p->op==(SQLITE_INDEX_CONTRAINT_FUNCTION+1) for geopoly_within().
			 ** See geopolyFindFunction() */
			iFuncTerm = ii
			idxNum = libc.Int32FromUint8((*Tsqlite3_index_constraint)(unsafe.Pointer(p)).Fop) - int32(SQLITE_INDEX_CONSTRAINT_FUNCTION) + int32(2)
		}
		goto _1
	_1:
		;
		ii = ii + 1
	}
	if iRowidTerm >= 0 {
		(*Tsqlite3_index_info)(unsafe.Pointer(pIdxInfo)).FidxNum = int32(1)
		(*Tsqlite3_index_info)(unsafe.Pointer(pIdxInfo)).FidxStr = __ccgo_ts + 17956
		(**(**Tsqlite3_index_constraint_usage)(__ccgo_up((*Tsqlite3_index_info)(unsafe.Pointer(pIdxInfo)).FaConstraintUsage + uintptr(iRowidTerm)*8))).FargvIndex = int32(1)
		(**(**Tsqlite3_index_constraint_usage)(__ccgo_up((*Tsqlite3_index_info)(unsafe.Pointer(pIdxInfo)).FaConstraintUsage + uintptr(iRowidTerm)*8))).Fomit = uint8(1)
		(*Tsqlite3_index_info)(unsafe.Pointer(pIdxInfo)).FestimatedCost = float64(30)
		(*Tsqlite3_index_info)(unsafe.Pointer(pIdxInfo)).FestimatedRows = int64(1)
		(*Tsqlite3_index_info)(unsafe.Pointer(pIdxInfo)).FidxFlags = int32(SQLITE_INDEX_SCAN_UNIQUE)
		return SQLITE_OK
	}
	if iFuncTerm >= 0 {
		(*Tsqlite3_index_info)(unsafe.Pointer(pIdxInfo)).FidxNum = idxNum
		(*Tsqlite3_index_info)(unsafe.Pointer(pIdxInfo)).FidxStr = __ccgo_ts + 29962
		(**(**Tsqlite3_index_constraint_usage)(__ccgo_up((*Tsqlite3_index_info)(unsafe.Pointer(pIdxInfo)).FaConstraintUsage + uintptr(iFuncTerm)*8))).FargvIndex = int32(1)
		(**(**Tsqlite3_index_constraint_usage)(__ccgo_up((*Tsqlite3_index_info)(unsafe.Pointer(pIdxInfo)).FaConstraintUsage + uintptr(iFuncTerm)*8))).Fomit = uint8(0)
		(*Tsqlite3_index_info)(unsafe.Pointer(pIdxInfo)).FestimatedCost = float64(300)
		(*Tsqlite3_index_info)(unsafe.Pointer(pIdxInfo)).FestimatedRows = int64(10)
		return SQLITE_OK
	}
	(*Tsqlite3_index_info)(unsafe.Pointer(pIdxInfo)).FidxNum = int32(4)
	(*Tsqlite3_index_info)(unsafe.Pointer(pIdxInfo)).FidxStr = __ccgo_ts + 29968
	(*Tsqlite3_index_info)(unsafe.Pointer(pIdxInfo)).FestimatedCost = float64(3e+06)
	(*Tsqlite3_index_info)(unsafe.Pointer(pIdxInfo)).FestimatedRows = int64(100000)
	return SQLITE_OK
}

// C documentation
//
//	/*
//	** Report that geopoly_overlap() is an overloaded function suitable
//	** for use in xBestIndex.
//	*/
func _geopolyFindFunction(tls *libc.TLS, pVtab uintptr, nArg int32, zName uintptr, __ccgo_fp_pxFunc uintptr, ppArg uintptr) (r int32) {
	_ = pVtab
	_ = nArg
	if Xsqlite3_stricmp(tls, zName, __ccgo_ts+30017) == 0 {
		**(**uintptr)(__ccgo_up(__ccgo_fp_pxFunc)) = __ccgo_fp(_geopolyOverlapFunc)
		**(**uintptr)(__ccgo_up(ppArg)) = uintptr(0)
		return int32(SQLITE_INDEX_CONSTRAINT_FUNCTION)
	}
	if Xsqlite3_stricmp(tls, zName, __ccgo_ts+30033) == 0 {
		**(**uintptr)(__ccgo_up(__ccgo_fp_pxFunc)) = __ccgo_fp(_geopolyWithinFunc)
		**(**uintptr)(__ccgo_up(ppArg)) = uintptr(0)
		return libc.Int32FromInt32(SQLITE_INDEX_CONSTRAINT_FUNCTION) + libc.Int32FromInt32(1)
	}
	return 0
}

// C documentation
//
//	/*
//	** This function is the implementation of both the xConnect and xCreate
//	** methods of the geopoly virtual table.
//	**
//	**   argv[0]   -> module name
//	**   argv[1]   -> database name
//	**   argv[2]   -> table name
//	**   argv[...] -> column names...
//	*/
func _geopolyInit(tls *libc.TLS, db uintptr, pAux uintptr, argc int32, argv uintptr, ppVtab uintptr, pzErr uintptr, isCreate int32) (r int32) {
	bp := tls.Alloc(16)
	defer tls.Free(16)
	var ii, rc, v2 int32
	var nDb, nName Tsqlite3_int64
	var pRtree, pSql, zSql uintptr
	_, _, _, _, _, _, _, _ = ii, nDb, nName, pRtree, pSql, rc, zSql, v2
	rc = SQLITE_OK
	_ = pAux
	if argc >= libc.Int32FromInt32(RTREE_MAX_AUX_COLUMN)+libc.Int32FromInt32(4) {
		**(**uintptr)(__ccgo_up(pzErr)) = Xsqlite3_mprintf(tls, __ccgo_ts+29899, 0)
		return int32(SQLITE_ERROR)
	}
	Xsqlite3_vtab_config(tls, db, int32(SQLITE_VTAB_CONSTRAINT_SUPPORT), libc.VaList(bp+8, int32(1)))
	Xsqlite3_vtab_config(tls, db, int32(SQLITE_VTAB_INNOCUOUS), 0)
	/* Allocate the sqlite3_vtab structure */
	nDb = libc.Int64FromUint64(libc.Xstrlen(tls, **(**uintptr)(__ccgo_up(argv + 1*8))))
	nName = libc.Int64FromUint64(libc.Xstrlen(tls, **(**uintptr)(__ccgo_up(argv + 2*8))))
	pRtree = Xsqlite3_malloc64(tls, uint64(976)+libc.Uint64FromInt64(nDb)+libc.Uint64FromInt64(nName*int64(2))+uint64(8))
	if !(pRtree != 0) {
		return int32(SQLITE_NOMEM)
	}
	libc.Xmemset(tls, pRtree, 0, uint64(uint64(976)+libc.Uint64FromInt64(nDb)+libc.Uint64FromInt64(nName*int64(2))+uint64(8)))
	(*TRtree)(unsafe.Pointer(pRtree)).FnBusy = uint32(1)
	(*TRtree)(unsafe.Pointer(pRtree)).Fbase.FpModule = uintptr(unsafe.Pointer(&_rtreeModule))
	(*TRtree)(unsafe.Pointer(pRtree)).FzDb = pRtree + 1*976
	(*TRtree)(unsafe.Pointer(pRtree)).FzName = (*TRtree)(unsafe.Pointer(pRtree)).FzDb + uintptr(nDb+int64(1))
	(*TRtree)(unsafe.Pointer(pRtree)).FzNodeName = (*TRtree)(unsafe.Pointer(pRtree)).FzName + uintptr(nName+int64(1))
	(*TRtree)(unsafe.Pointer(pRtree)).FeCoordType = uint8(RTREE_COORD_REAL32)
	(*TRtree)(unsafe.Pointer(pRtree)).FnDim = uint8(2)
	(*TRtree)(unsafe.Pointer(pRtree)).FnDim2 = uint8(4)
	libc.Xmemcpy(tls, (*TRtree)(unsafe.Pointer(pRtree)).FzDb, **(**uintptr)(__ccgo_up(argv + 1*8)), libc.Uint64FromInt64(nDb))
	libc.Xmemcpy(tls, (*TRtree)(unsafe.Pointer(pRtree)).FzName, **(**uintptr)(__ccgo_up(argv + 2*8)), libc.Uint64FromInt64(nName))
	libc.Xmemcpy(tls, (*TRtree)(unsafe.Pointer(pRtree)).FzNodeName, **(**uintptr)(__ccgo_up(argv + 2*8)), libc.Uint64FromInt64(nName))
	libc.Xmemcpy(tls, (*TRtree)(unsafe.Pointer(pRtree)).FzNodeName+uintptr(nName), __ccgo_ts+28941, uint64(6))
	/* Create/Connect to the underlying relational database schema. If
	 ** that is successful, call sqlite3_declare_vtab() to configure
	 ** the r-tree table schema.
	 */
	pSql = Xsqlite3_str_new(tls, db)
	Xsqlite3_str_appendf(tls, pSql, __ccgo_ts+29936, 0)
	(*TRtree)(unsafe.Pointer(pRtree)).FnAux = uint16(1)       /* Add one for _shape */
	(*TRtree)(unsafe.Pointer(pRtree)).FnAuxNotNull = uint8(1) /* The _shape column is always not-null */
	ii = int32(3)
	for {
		if !(ii < argc) {
			break
		}
		(*TRtree)(unsafe.Pointer(pRtree)).FnAux = (*TRtree)(unsafe.Pointer(pRtree)).FnAux + 1
		Xsqlite3_str_appendf(tls, pSql, __ccgo_ts+29958, libc.VaList(bp+8, **(**uintptr)(__ccgo_up(argv + uintptr(ii)*8))))
		goto _1
	_1:
		;
		ii = ii + 1
	}
	Xsqlite3_str_appendf(tls, pSql, __ccgo_ts+28998, 0)
	zSql = Xsqlite3_str_finish(tls, pSql)
	if !(zSql != 0) {
		rc = int32(SQLITE_NOMEM)
	} else {
		v2 = Xsqlite3_declare_vtab(tls, db, zSql)
		rc = v2
		if SQLITE_OK != v2 {
			**(**uintptr)(__ccgo_up(pzErr)) = Xsqlite3_mprintf(tls, __ccgo_ts+3933, libc.VaList(bp+8, Xsqlite3_errmsg(tls, db)))
		}
	}
	Xsqlite3_free(tls, zSql)
	if rc != 0 {
		goto geopolyInit_fail
	}
	(*TRtree)(unsafe.Pointer(pRtree)).FnBytesPerCell = libc.Uint8FromInt32(int32(8) + libc.Int32FromUint8((*TRtree)(unsafe.Pointer(pRtree)).FnDim2)*int32(4))
	/* Figure out the node size to use. */
	rc = _getNodeSize(tls, db, pRtree, isCreate, pzErr)
	if rc != 0 {
		goto geopolyInit_fail
	}
	rc = _rtreeSqlInit(tls, pRtree, db, **(**uintptr)(__ccgo_up(argv + 1*8)), **(**uintptr)(__ccgo_up(argv + 2*8)), isCreate)
	if rc != 0 {
		**(**uintptr)(__ccgo_up(pzErr)) = Xsqlite3_mprintf(tls, __ccgo_ts+3933, libc.VaList(bp+8, Xsqlite3_errmsg(tls, db)))
		goto geopolyInit_fail
	}
	**(**uintptr)(__ccgo_up(ppVtab)) = pRtree
	return SQLITE_OK
	goto geopolyInit_fail
geopolyInit_fail:
	;
	if rc == SQLITE_OK {
		rc = int32(SQLITE_ERROR)
	}
	_rtreeRelease(tls, pRtree)
	return rc
}

// C documentation
//
//	/*
//	** SQL function:     geopoly_json(X)
//	**
//	** Interpret X as a polygon and render it as a JSON array
//	** of coordinates.  Or, if X is not a valid polygon, return NULL.
//	*/
func _geopolyJsonFunc(tls *libc.TLS, context uintptr, argc int32, argv uintptr) {
	bp := tls.Alloc(32)
	defer tls.Free(32)
	var db, p, x uintptr
	var i int32
	_, _, _, _ = db, i, p, x
	p = _geopolyFuncParam(tls, context, **(**uintptr)(__ccgo_up(argv)), uintptr(0))
	_ = argc
	if p != 0 {
		db = Xsqlite3_context_db_handle(tls, context)
		x = Xsqlite3_str_new(tls, db)
		Xsqlite3_str_append(tls, x, __ccgo_ts+26663, int32(1))
		i = 0
		for {
			if !(i < (*TGeoPoly)(unsafe.Pointer(p)).FnVertex) {
				break
			}
			Xsqlite3_str_appendf(tls, x, __ccgo_ts+29826, libc.VaList(bp+8, float64(**(**TGeoCoord)(__ccgo_up(p + 8 + uintptr(i*int32(2))*4))), float64(**(**TGeoCoord)(__ccgo_up(p + 8 + uintptr(i*int32(2)+int32(1))*4)))))
			goto _1
		_1:
			;
			i = i + 1
		}
		Xsqlite3_str_appendf(tls, x, __ccgo_ts+29837, libc.VaList(bp+8, float64(**(**TGeoCoord)(__ccgo_up(p + 8 + uintptr(libc.Int32FromInt32(0)*libc.Int32FromInt32(2))*4))), float64(**(**TGeoCoord)(__ccgo_up(p + 8 + uintptr(libc.Int32FromInt32(0)*libc.Int32FromInt32(2)+libc.Int32FromInt32(1))*4)))))
		Xsqlite3_result_text(tls, context, Xsqlite3_str_finish(tls, x), -int32(1), __ccgo_fp(Xsqlite3_free))
		Xsqlite3_free(tls, p)
	}
}

// C documentation
//
//	/*
//	** The xUpdate method for GEOPOLY module virtual tables.
//	**
//	** For DELETE:
//	**
//	**     argv[0] = the rowid to be deleted
//	**
//	** For INSERT:
//	**
//	**     argv[0] = SQL NULL
//	**     argv[1] = rowid to insert, or an SQL NULL to select automatically
//	**     argv[2] = _shape column
//	**     argv[3] = first application-defined column....
//	**
//	** For UPDATE:
//	**
//	**     argv[0] = rowid to modify.  Never NULL
//	**     argv[1] = rowid after the change.  Never NULL
//	**     argv[2] = new value for _shape
//	**     argv[3] = new value for first application-defined column....
//	*/
func _geopolyUpdate(tls *libc.TLS, pVtab uintptr, nData int32, aData uintptr, pRowid uintptr) (r int32) {
	bp := tls.Alloc(64)
	defer tls.Free(64)
	var coordChange, jj, nChange, newRowidValid, oldRowidValid, rc2, steprc int32
	var newRowid, oldRowid Ti64
	var p, pRtree, pUp, v3 uintptr
	var v1 int64
	var v4 bool
	var _ /* cell at bp+8 */ TRtreeCell
	var _ /* pLeaf at bp+56 */ uintptr
	var _ /* rc at bp+0 */ int32
	_, _, _, _, _, _, _, _, _, _, _, _, _, _, _ = coordChange, jj, nChange, newRowid, newRowidValid, oldRowid, oldRowidValid, p, pRtree, pUp, rc2, steprc, v1, v3, v4
	pRtree = pVtab
	**(**int32)(__ccgo_up(bp)) = SQLITE_OK /* True if newRowid is valid */
	coordChange = 0                        /* Change in coordinates */
	if (*TRtree)(unsafe.Pointer(pRtree)).FnNodeRef != 0 {
		/* Unable to write to the btree while another cursor is reading from it,
		 ** since the write might do a rebalance which would disrupt the read
		 ** cursor. */
		return libc.Int32FromInt32(SQLITE_LOCKED) | libc.Int32FromInt32(2)<<libc.Int32FromInt32(8)
	}
	_rtreeReference(tls, pRtree)
	oldRowidValid = libc.BoolInt32(Xsqlite3_value_type(tls, **(**uintptr)(__ccgo_up(aData))) != int32(SQLITE_NULL))
	if oldRowidValid != 0 {
		v1 = Xsqlite3_value_int64(tls, **(**uintptr)(__ccgo_up(aData)))
	} else {
		v1 = 0
	}
	oldRowid = v1
	newRowidValid = libc.BoolInt32(nData > int32(1) && Xsqlite3_value_type(tls, **(**uintptr)(__ccgo_up(aData + 1*8))) != int32(SQLITE_NULL))
	if newRowidValid != 0 {
		v1 = Xsqlite3_value_int64(tls, **(**uintptr)(__ccgo_up(aData + 1*8)))
	} else {
		v1 = 0
	}
	newRowid = v1
	(**(**TRtreeCell)(__ccgo_up(bp + 8))).FiRowid = newRowid
	if nData > int32(1) && (!(oldRowidValid != 0) || !(Xsqlite3_value_nochange(tls, **(**uintptr)(__ccgo_up(aData + 2*8))) != 0) || oldRowid != newRowid) {
		_geopolyBBox(tls, uintptr(0), **(**uintptr)(__ccgo_up(aData + 2*8)), bp+8+8, bp)
		if **(**int32)(__ccgo_up(bp)) != 0 {
			if **(**int32)(__ccgo_up(bp)) == int32(SQLITE_ERROR) {
				(*Tsqlite3_vtab)(unsafe.Pointer(pVtab)).FzErrMsg = Xsqlite3_mprintf(tls, __ccgo_ts+29977, 0)
			}
			goto geopoly_update_end
		}
		coordChange = int32(1)
		/* If a rowid value was supplied, check if it is already present in
		 ** the table. If so, the constraint has failed. */
		if newRowidValid != 0 && (!(oldRowidValid != 0) || oldRowid != newRowid) {
			Xsqlite3_bind_int64(tls, (*TRtree)(unsafe.Pointer(pRtree)).FpReadRowid, int32(1), (**(**TRtreeCell)(__ccgo_up(bp + 8))).FiRowid)
			steprc = Xsqlite3_step(tls, (*TRtree)(unsafe.Pointer(pRtree)).FpReadRowid)
			**(**int32)(__ccgo_up(bp)) = Xsqlite3_reset(tls, (*TRtree)(unsafe.Pointer(pRtree)).FpReadRowid)
			if int32(SQLITE_ROW) == steprc {
				if Xsqlite3_vtab_on_conflict(tls, (*TRtree)(unsafe.Pointer(pRtree)).Fdb) == int32(SQLITE_REPLACE) {
					**(**int32)(__ccgo_up(bp)) = _rtreeDeleteRowid(tls, pRtree, (**(**TRtreeCell)(__ccgo_up(bp + 8))).FiRowid)
				} else {
					**(**int32)(__ccgo_up(bp)) = _rtreeConstraintError(tls, pRtree, 0)
				}
			}
		}
	}
	/* If aData[0] is not an SQL NULL value, it is the rowid of a
	 ** record to delete from the r-tree table. The following block does
	 ** just that.
	 */
	if **(**int32)(__ccgo_up(bp)) == SQLITE_OK && (nData == int32(1) || coordChange != 0 && oldRowidValid != 0) {
		**(**int32)(__ccgo_up(bp)) = _rtreeDeleteRowid(tls, pRtree, oldRowid)
	}
	/* If the aData[] array contains more than one element, elements
	 ** (aData[2]..aData[argc-1]) contain a new record to insert into
	 ** the r-tree structure.
	 */
	if **(**int32)(__ccgo_up(bp)) == SQLITE_OK && nData > int32(1) && coordChange != 0 {
		/* Insert the new record into the r-tree */
		**(**uintptr)(__ccgo_up(bp + 56)) = uintptr(0)
		if !(newRowidValid != 0) {
			**(**int32)(__ccgo_up(bp)) = _rtreeNewRowid(tls, pRtree, bp+8)
		}
		**(**Tsqlite_int64)(__ccgo_up(pRowid)) = (**(**TRtreeCell)(__ccgo_up(bp + 8))).FiRowid
		if **(**int32)(__ccgo_up(bp)) == SQLITE_OK {
			**(**int32)(__ccgo_up(bp)) = _ChooseLeaf(tls, pRtree, bp+8, 0, bp+56)
		}
		if **(**int32)(__ccgo_up(bp)) == SQLITE_OK {
			**(**int32)(__ccgo_up(bp)) = _rtreeInsertCell(tls, pRtree, **(**uintptr)(__ccgo_up(bp + 56)), bp+8, 0)
			rc2 = _nodeRelease(tls, pRtree, **(**uintptr)(__ccgo_up(bp + 56)))
			if **(**int32)(__ccgo_up(bp)) == SQLITE_OK {
				**(**int32)(__ccgo_up(bp)) = rc2
			}
		}
	}
	/* Change the data */
	if **(**int32)(__ccgo_up(bp)) == SQLITE_OK && nData > int32(1) {
		pUp = (*TRtree)(unsafe.Pointer(pRtree)).FpWriteAux
		nChange = 0
		Xsqlite3_bind_int64(tls, pUp, int32(1), (**(**TRtreeCell)(__ccgo_up(bp + 8))).FiRowid)
		if Xsqlite3_value_nochange(tls, **(**uintptr)(__ccgo_up(aData + 2*8))) != 0 {
			Xsqlite3_bind_null(tls, pUp, int32(2))
		} else {
			p = uintptr(0)
			if v4 = Xsqlite3_value_type(tls, **(**uintptr)(__ccgo_up(aData + 2*8))) == int32(SQLITE_TEXT); v4 {
				v3 = _geopolyFuncParam(tls, uintptr(0), **(**uintptr)(__ccgo_up(aData + 2*8)), bp)
				p = v3
			}
			if v4 && v3 != uintptr(0) && **(**int32)(__ccgo_up(bp)) == SQLITE_OK {
				Xsqlite3_bind_blob(tls, pUp, int32(2), p+4, int32(4)+int32(8)*(*TGeoPoly)(unsafe.Pointer(p)).FnVertex, uintptr(-libc.Int32FromInt32(1)))
			} else {
				Xsqlite3_bind_value(tls, pUp, int32(2), **(**uintptr)(__ccgo_up(aData + 2*8)))
			}
			Xsqlite3_free(tls, p)
			nChange = int32(1)
		}
		jj = int32(1)
		for {
			if !(jj < nData-int32(2)) {
				break
			}
			nChange = nChange + 1
			Xsqlite3_bind_value(tls, pUp, jj+int32(2), **(**uintptr)(__ccgo_up(aData + uintptr(jj+int32(2))*8)))
			goto _5
		_5:
			;
			jj = jj + 1
		}
		if nChange != 0 {
			Xsqlite3_step(tls, pUp)
			**(**int32)(__ccgo_up(bp)) = Xsqlite3_reset(tls, pUp)
		}
	}
	goto geopoly_update_end
geopoly_update_end:
	;
	_rtreeRelease(tls, pRtree)
	return **(**int32)(__ccgo_up(bp))
}

// C documentation
//
//	/*
//	** Interpret the given string as an auto-vacuum mode value.
//	**
//	** The following strings, "none", "full" and "incremental" are
//	** acceptable, as are their numeric equivalents: 0, 1 and 2 respectively.
//	*/
func _getAutoVacuum(tls *libc.TLS, z uintptr) (r int32) {
	var i, v1 int32
	_, _ = i, v1
	if 0 == _sqlite3StrICmp(tls, z, __ccgo_ts+8501) {
		return BTREE_AUTOVACUUM_NONE
	}
	if 0 == _sqlite3StrICmp(tls, z, __ccgo_ts+19009) {
		return int32(BTREE_AUTOVACUUM_FULL)
	}
	if 0 == _sqlite3StrICmp(tls, z, __ccgo_ts+19014) {
		return int32(BTREE_AUTOVACUUM_INCR)
	}
	i = _sqlite3Atoi(tls, z)
	if i >= 0 && i <= int32(2) {
		v1 = i
	} else {
		v1 = 0
	}
	return libc.Int32FromUint8(libc.Uint8FromInt32(v1))
}

// C documentation
//
//	/*
//	** Interpret the given string as a locking mode value.
//	*/
func _getLockingMode(tls *libc.TLS, z uintptr) (r int32) {
	if z != 0 {
		if 0 == _sqlite3StrICmp(tls, z, __ccgo_ts+18992) {
			return int32(PAGER_LOCKINGMODE_EXCLUSIVE)
		}
		if 0 == _sqlite3StrICmp(tls, z, __ccgo_ts+19002) {
			return PAGER_LOCKINGMODE_NORMAL
		}
	}
	return -int32(1)
}

// C documentation
//
//	/*
//	** This function is called from within the xConnect() or xCreate() method to
//	** determine the node-size used by the rtree table being created or connected
//	** to. If successful, pRtree->iNodeSize is populated and SQLITE_OK returned.
//	** Otherwise, an SQLite error code is returned.
//	**
//	** If this function is being called as part of an xConnect(), then the rtree
//	** table already exists. In this case the node-size is determined by inspecting
//	** the root node of the tree.
//	**
//	** Otherwise, for an xCreate(), use 64 bytes less than the database page-size.
//	** This ensures that each node is stored on a single database page. If the
//	** database page-size is so large that more than RTREE_MAXCELLS entries
//	** would fit in a single node, use a smaller node-size.
//	*/
func _getNodeSize(tls *libc.TLS, db uintptr, pRtree uintptr, isCreate int32, pzErr uintptr) (r int32) {
	bp := tls.Alloc(32)
	defer tls.Free(32)
	var rc int32
	var zSql uintptr
	var _ /* iPageSize at bp+0 */ int32
	_, _ = rc, zSql
	if isCreate != 0 {
		**(**int32)(__ccgo_up(bp)) = 0
		zSql = Xsqlite3_mprintf(tls, __ccgo_ts+28678, libc.VaList(bp+16, (*TRtree)(unsafe.Pointer(pRtree)).FzDb))
		rc = _getIntFromStmt(tls, db, zSql, bp)
		if rc == SQLITE_OK {
			(*TRtree)(unsafe.Pointer(pRtree)).FiNodeSize = **(**int32)(__ccgo_up(bp)) - int32(64)
			if int32(4)+libc.Int32FromUint8((*TRtree)(unsafe.Pointer(pRtree)).FnBytesPerCell)*int32(RTREE_MAXCELLS) < (*TRtree)(unsafe.Pointer(pRtree)).FiNodeSize {
				(*TRtree)(unsafe.Pointer(pRtree)).FiNodeSize = int32(4) + libc.Int32FromUint8((*TRtree)(unsafe.Pointer(pRtree)).FnBytesPerCell)*int32(RTREE_MAXCELLS)
			}
		} else {
			**(**uintptr)(__ccgo_up(pzErr)) = Xsqlite3_mprintf(tls, __ccgo_ts+3933, libc.VaList(bp+16, Xsqlite3_errmsg(tls, db)))
		}
	} else {
		zSql = Xsqlite3_mprintf(tls, __ccgo_ts+28698, libc.VaList(bp+16, (*TRtree)(unsafe.Pointer(pRtree)).FzDb, (*TRtree)(unsafe.Pointer(pRtree)).FzName))
		rc = _getIntFromStmt(tls, db, zSql, pRtree+32)
		if rc != SQLITE_OK {
			**(**uintptr)(__ccgo_up(pzErr)) = Xsqlite3_mprintf(tls, __ccgo_ts+3933, libc.VaList(bp+16, Xsqlite3_errmsg(tls, db)))
		} else {
			if (*TRtree)(unsafe.Pointer(pRtree)).FiNodeSize < libc.Int32FromInt32(512)-libc.Int32FromInt32(64) {
				rc = libc.Int32FromInt32(SQLITE_CORRUPT) | libc.Int32FromInt32(1)<<libc.Int32FromInt32(8)
				**(**uintptr)(__ccgo_up(pzErr)) = Xsqlite3_mprintf(tls, __ccgo_ts+28755, libc.VaList(bp+16, (*TRtree)(unsafe.Pointer(pRtree)).FzName))
			}
		}
	}
	Xsqlite3_free(tls, zSql)
	return rc
}

func _groupConcatValue(tls *libc.TLS, context uintptr) {
	var pAccum, pGCC, zText uintptr
	_, _, _ = pAccum, pGCC, zText
	pGCC = Xsqlite3_aggregate_context(tls, context, 0)
	if pGCC != 0 {
		pAccum = pGCC
		if libc.Int32FromUint8((*TStrAccum)(unsafe.Pointer(pAccum)).FaccError) == int32(SQLITE_TOOBIG) {
			Xsqlite3_result_error_toobig(tls, context)
		} else {
			if libc.Int32FromUint8((*TStrAccum)(unsafe.Pointer(pAccum)).FaccError) == int32(SQLITE_NOMEM) {
				Xsqlite3_result_error_nomem(tls, context)
			} else {
				if (*TGroupConcatCtx)(unsafe.Pointer(pGCC)).FnAccum > 0 && (*TStrAccum)(unsafe.Pointer(pAccum)).FnChar == uint32(0) {
					Xsqlite3_result_text(tls, context, __ccgo_ts+1693, int32(1), libc.UintptrFromInt32(0))
				} else {
					zText = Xsqlite3_str_value(tls, pAccum)
					Xsqlite3_result_text(tls, context, zText, libc.Int32FromUint32((*TStrAccum)(unsafe.Pointer(pAccum)).FnChar), uintptr(-libc.Int32FromInt32(1)))
				}
			}
		}
	}
}

// C documentation
//
//	/*
//	** Invalidate temp storage, either when the temp storage is changed
//	** from default, or when 'file' and the temp_store_directory has changed
//	*/
func _invalidateTempStorage(tls *libc.TLS, pParse uintptr) (r int32) {
	var db uintptr
	_ = db
	db = (*TParse)(unsafe.Pointer(pParse)).Fdb
	if (**(**TDb)(__ccgo_up((*Tsqlite3)(unsafe.Pointer(db)).FaDb + 1*32))).FpBt != uintptr(0) {
		if !((*Tsqlite3)(unsafe.Pointer(db)).FautoCommit != 0) || _sqlite3BtreeTxnState(tls, (**(**TDb)(__ccgo_up((*Tsqlite3)(unsafe.Pointer(db)).FaDb + 1*32))).FpBt) != SQLITE_TXN_NONE {
			_sqlite3ErrorMsg(tls, pParse, __ccgo_ts+19033, 0)
			return int32(SQLITE_ERROR)
		}
		_sqlite3BtreeClose(tls, (**(**TDb)(__ccgo_up((*Tsqlite3)(unsafe.Pointer(db)).FaDb + 1*32))).FpBt)
		(**(**TDb)(__ccgo_up((*Tsqlite3)(unsafe.Pointer(db)).FaDb + 1*32))).FpBt = uintptr(0)
		_sqlite3ResetAllSchemasOfConnection(tls, db)
	}
	return SQLITE_OK
}

// C documentation
//
//	/*
//	** Parameter zName is the name of a table that is about to be altered
//	** (either with ALTER TABLE ... RENAME TO or ALTER TABLE ... ADD COLUMN).
//	** If the table is a system table, this function leaves an error message
//	** in pParse->zErr (system tables may not be altered) and returns non-zero.
//	**
//	** Or, if zName is not a system table, zero is returned.
//	*/
func _isAlterableTable(tls *libc.TLS, pParse uintptr, pTab uintptr) (r int32) {
	bp := tls.Alloc(16)
	defer tls.Free(16)
	if 0 == Xsqlite3_strnicmp(tls, (*TTable)(unsafe.Pointer(pTab)).FzName, __ccgo_ts+6749, int32(7)) || (*TTable)(unsafe.Pointer(pTab)).FtabFlags&uint32(TF_Eponymous) != uint32(0) || (*TTable)(unsafe.Pointer(pTab)).FtabFlags&uint32(TF_Shadow) != uint32(0) && _sqlite3ReadOnlyShadowTables(tls, (*TParse)(unsafe.Pointer(pParse)).Fdb) != 0 {
		_sqlite3ErrorMsg(tls, pParse, __ccgo_ts+8636, libc.VaList(bp+8, (*TTable)(unsafe.Pointer(pTab)).FzName))
		return int32(1)
	}
	return 0
}

// C documentation
//
//	/*
//	** Return true if the pExpr term from the RETURNING clause argument
//	** list is of the form "*".  Raise an error if the terms if of the
//	** form "table.*".
//	*/
func _isAsteriskTerm(tls *libc.TLS, pParse uintptr, pTerm uintptr) (r int32) {
	if libc.Int32FromUint8((*TExpr)(unsafe.Pointer(pTerm)).Fop) == int32(TK_ASTERISK) {
		return int32(1)
	}
	if libc.Int32FromUint8((*TExpr)(unsafe.Pointer(pTerm)).Fop) != int32(TK_DOT) {
		return 0
	}
	if libc.Int32FromUint8((*TExpr)(unsafe.Pointer((*TExpr)(unsafe.Pointer(pTerm)).FpRight)).Fop) != int32(TK_ASTERISK) {
		return 0
	}
	_sqlite3ErrorMsg(tls, pParse, __ccgo_ts+22515, 0)
	return int32(1)
}

// C documentation
//
//	/*
//	** Parameter pTab is the subject of an ALTER TABLE ... RENAME COLUMN
//	** command. This function checks if the table is a view or virtual
//	** table (columns of views or virtual tables may not be renamed). If so,
//	** it loads an error message into pParse and returns non-zero.
//	**
//	** Or, if pTab is not a view or virtual table, zero is returned.
//	*/
func _isRealTable(tls *libc.TLS, pParse uintptr, pTab uintptr, iOp int32) (r int32) {
	bp := tls.Alloc(32)
	defer tls.Free(32)
	var azMsg [3]uintptr
	var zType uintptr
	_, _ = azMsg, zType
	zType = uintptr(0)
	if libc.Int32FromUint8((*TTable)(unsafe.Pointer(pTab)).FeTabType) == int32(TABTYP_VIEW) {
		zType = __ccgo_ts + 11108
	}
	if libc.Int32FromUint8((*TTable)(unsafe.Pointer(pTab)).FeTabType) == int32(TABTYP_VTAB) {
		zType = __ccgo_ts + 11113
	}
	if zType != 0 {
		azMsg = [3]uintptr{
			0: __ccgo_ts + 11127,
			1: __ccgo_ts + 11145,
			2: __ccgo_ts + 11162,
		}
		_sqlite3ErrorMsg(tls, pParse, __ccgo_ts+11182, libc.VaList(bp+8, azMsg[iOp], zType, (*TTable)(unsafe.Pointer(pTab)).FzName))
		return int32(1)
	}
	return 0
}

// C documentation
//
//	/*
//	** Return TRUE (non-zero) if zTab is a valid name for the schema table pTab.
//	*/
func _isValidSchemaTableName(tls *libc.TLS, zTab uintptr, pTab uintptr, zDb uintptr) (r int32) {
	var zLegacy uintptr
	_ = zLegacy
	if Xsqlite3_strnicmp(tls, zTab, __ccgo_ts+6749, int32(7)) != 0 {
		return 0
	}
	zLegacy = (*TTable)(unsafe.Pointer(pTab)).FzName
	if libc.Xstrcmp(tls, zLegacy+uintptr(7), __ccgo_ts+6757+7) == 0 {
		if _sqlite3StrICmp(tls, zTab+uintptr(7), __ccgo_ts+6776+7) == 0 {
			return int32(1)
		}
		if zDb == uintptr(0) {
			return 0
		}
		if _sqlite3StrICmp(tls, zTab+uintptr(7), __ccgo_ts+6277+7) == 0 {
			return int32(1)
		}
		if _sqlite3StrICmp(tls, zTab+uintptr(7), __ccgo_ts+6795+7) == 0 {
			return int32(1)
		}
	} else {
		if _sqlite3StrICmp(tls, zTab+uintptr(7), __ccgo_ts+6795+7) == 0 {
			return int32(1)
		}
	}
	return 0
}

// C documentation
//
//	/*
//	** Append an sqlite3_value (such as a function parameter) to the JSON
//	** string under construction in p.
//	*/
func _jsonAppendSqlValue(tls *libc.TLS, p uintptr, pValue uintptr) {
	bp := tls.Alloc(96)
	defer tls.Free(96)
	var n, n1 Tu32
	var z, z1 uintptr
	var _ /* px at bp+0 */ TJsonParse
	_, _, _, _ = n, n1, z, z1
	switch Xsqlite3_value_type(tls, pValue) {
	case int32(SQLITE_NULL):
		_jsonAppendRawNZ(tls, p, __ccgo_ts+1679, uint32(4))
	case int32(SQLITE_FLOAT):
		_jsonPrintf(tls, int32(100), p, __ccgo_ts+16552, libc.VaList(bp+80, Xsqlite3_value_double(tls, pValue)))
	case int32(SQLITE_INTEGER):
		z = Xsqlite3_value_text(tls, pValue)
		n = libc.Uint32FromInt32(Xsqlite3_value_bytes(tls, pValue))
		_jsonAppendRaw(tls, p, z, n)
	case int32(SQLITE_TEXT):
		z1 = Xsqlite3_value_text(tls, pValue)
		n1 = libc.Uint32FromInt32(Xsqlite3_value_bytes(tls, pValue))
		if Xsqlite3_value_subtype(tls, pValue) == uint32(JSON_SUBTYPE) {
			_jsonAppendRaw(tls, p, z1, n1)
		} else {
			_jsonAppendString(tls, p, z1, n1)
		}
	default:
		libc.Xmemset(tls, bp, 0, uint64(72))
		if _jsonArgIsJsonb(tls, pValue, bp) != 0 {
			_jsonTranslateBlobToText(tls, bp, uint32(0), p)
		} else {
			if libc.Int32FromUint8((*TJsonString)(unsafe.Pointer(p)).FeErr) == 0 {
				Xsqlite3_result_error(tls, (*TJsonString)(unsafe.Pointer(p)).FpCtx, __ccgo_ts+26422, -int32(1))
				(*TJsonString)(unsafe.Pointer(p)).FeErr = uint8(JSTRING_ERR)
				_jsonStringReset(tls, p)
			}
		}
		break
	}
}

func _jsonArrayCompute(tls *libc.TLS, ctx uintptr, isFinal int32) {
	var flags int32
	var pStr uintptr
	var v1 Tsqlite3_destructor_type
	_, _, _ = flags, pStr, v1
	flags = int32(int64(Xsqlite3_user_data(tls, ctx)))
	pStr = Xsqlite3_aggregate_context(tls, ctx, 0)
	if pStr != 0 {
		(*TJsonString)(unsafe.Pointer(pStr)).FpCtx = ctx
		_jsonAppendRawNZ(tls, pStr, __ccgo_ts+5305, uint32(2))
		_jsonStringTrimOneChar(tls, pStr)
		if (*TJsonString)(unsafe.Pointer(pStr)).FeErr != 0 {
			_jsonReturnString(tls, pStr, uintptr(0), uintptr(0))
			return
		} else {
			if flags&int32(JSON_BLOB) != 0 {
				_jsonReturnStringAsBlob(tls, pStr)
				if isFinal != 0 {
					if !((*TJsonString)(unsafe.Pointer(pStr)).FbStatic != 0) {
						_sqlite3RCStrUnref(tls, (*TJsonString)(unsafe.Pointer(pStr)).FzBuf)
					}
				} else {
					_jsonStringTrimOneChar(tls, pStr)
				}
				return
			} else {
				if isFinal != 0 {
					if (*TJsonString)(unsafe.Pointer(pStr)).FbStatic != 0 {
						v1 = uintptr(-libc.Int32FromInt32(1))
					} else {
						v1 = __ccgo_fp(_sqlite3RCStrUnref)
					}
					Xsqlite3_result_text(tls, ctx, (*TJsonString)(unsafe.Pointer(pStr)).FzBuf, libc.Int32FromUint64((*TJsonString)(unsafe.Pointer(pStr)).FnUsed), v1)
					(*TJsonString)(unsafe.Pointer(pStr)).FbStatic = uint8(1)
				} else {
					Xsqlite3_result_text(tls, ctx, (*TJsonString)(unsafe.Pointer(pStr)).FzBuf, libc.Int32FromUint64((*TJsonString)(unsafe.Pointer(pStr)).FnUsed), uintptr(-libc.Int32FromInt32(1)))
					_jsonStringTrimOneChar(tls, pStr)
				}
			}
		}
	} else {
		if flags&int32(JSON_BLOB) != 0 {
			Xsqlite3_result_blob(tls, ctx, uintptr(unsafe.Pointer(&_emptyArray)), int32(1), libc.UintptrFromInt32(0))
		} else {
			Xsqlite3_result_text(tls, ctx, __ccgo_ts+26843, int32(2), libc.UintptrFromInt32(0))
		}
	}
	Xsqlite3_result_subtype(tls, ctx, uint32(JSON_SUBTYPE))
}

// C documentation
//
//	/*
//	** Generate a path error.
//	**
//	** The specifics of the error are determined by the rc argument.
//	**
//	**          rc                        error
//	**  -----------------       ----------------------
//	**  JSON_LOOKUP_ARRAY       "not an array"
//	**  JSON_LOOKUP_TOODEEP     "JSON nested too deep"
//	**  JSON_LOOKUP_ERROR       "malformed JSON"
//	**  otherwise...            "bad JSON path"
//	**
//	** If ctx is not NULL then push the error message into ctx and return NULL.
//	** If ctx is NULL, then return the text of the error message.
//	*/
func _jsonBadPathError(tls *libc.TLS, ctx uintptr, zPath uintptr, rc int32) (r uintptr) {
	bp := tls.Alloc(16)
	defer tls.Free(16)
	var zMsg uintptr
	_ = zMsg
	if rc == libc.Int32FromUint32(JSON_LOOKUP_NOTARRAY) {
		zMsg = Xsqlite3_mprintf(tls, __ccgo_ts+26599, libc.VaList(bp+8, zPath))
	} else {
		if rc == libc.Int32FromUint32(JSON_LOOKUP_ERROR) {
			zMsg = Xsqlite3_mprintf(tls, __ccgo_ts+26451, 0)
		} else {
			if rc == libc.Int32FromUint32(JSON_LOOKUP_TOODEEP) {
				zMsg = Xsqlite3_mprintf(tls, __ccgo_ts+26624, 0)
			} else {
				zMsg = Xsqlite3_mprintf(tls, __ccgo_ts+26643, libc.VaList(bp+8, zPath))
			}
		}
	}
	if ctx == uintptr(0) {
		return zMsg
	}
	if zMsg != 0 {
		Xsqlite3_result_error(tls, ctx, zMsg, -int32(1))
		Xsqlite3_free(tls, zMsg)
	} else {
		Xsqlite3_result_error_nomem(tls, ctx)
	}
	return uintptr(0)
}

// C documentation
//
//	/*
//	** Implementation of the json_mergepatch(JSON1,JSON2) function.  Return a JSON
//	** object that is the result of running the RFC 7396 MergePatch() algorithm
//	** on the two arguments.
//	*/
func _jsonPatchFunc(tls *libc.TLS, ctx uintptr, argc int32, argv uintptr) {
	var pPatch, pTarget uintptr
	var rc int32
	_, _, _ = pPatch, pTarget, rc /* Result code */
	_ = argc
	pTarget = _jsonParseFuncArg(tls, ctx, **(**uintptr)(__ccgo_up(argv)), uint32(JSON_EDITABLE))
	if pTarget == uintptr(0) {
		return
	}
	pPatch = _jsonParseFuncArg(tls, ctx, **(**uintptr)(__ccgo_up(argv + 1*8)), uint32(0))
	if pPatch != 0 {
		rc = _jsonMergePatch(tls, pTarget, uint32(0), pPatch, uint32(0), uint32(0))
		if rc == JSON_MERGE_OK {
			_jsonReturnParse(tls, ctx, pTarget)
		} else {
			if rc == int32(JSON_MERGE_OOM) {
				Xsqlite3_result_error_nomem(tls, ctx)
			} else {
				if rc == int32(JSON_MERGE_TOODEEP) {
					Xsqlite3_result_error(tls, ctx, __ccgo_ts+26401, -int32(1))
				} else {
					Xsqlite3_result_error(tls, ctx, __ccgo_ts+26451, -int32(1))
				}
			}
		}
		_jsonParseFree(tls, pPatch)
	}
	_jsonParseFree(tls, pTarget)
}

// C documentation
//
//	/*
//	** json_pretty(JSON)
//	** json_pretty(JSON, INDENT)
//	**
//	** Return text that is a pretty-printed rendering of the input JSON.
//	** If the argument is not valid JSON, return NULL.
//	**
//	** The INDENT argument is text that is used for indentation.  If omitted,
//	** it defaults to four spaces (the same as PostgreSQL).
//	*/
func _jsonPrettyFunc(tls *libc.TLS, ctx uintptr, argc int32, argv uintptr) {
	bp := tls.Alloc(176)
	defer tls.Free(176)
	var v1 uintptr
	var v2 bool
	var _ /* s at bp+0 */ TJsonString
	var _ /* x at bp+136 */ TJsonPretty
	_, _ = v1, v2 /* Pretty printing context */
	libc.Xmemset(tls, bp+136, 0, uint64(32))
	(**(**TJsonPretty)(__ccgo_up(bp + 136))).FpParse = _jsonParseFuncArg(tls, ctx, **(**uintptr)(__ccgo_up(argv)), uint32(0))
	if (**(**TJsonPretty)(__ccgo_up(bp + 136))).FpParse == uintptr(0) {
		return
	}
	(**(**TJsonPretty)(__ccgo_up(bp + 136))).FpOut = bp
	_jsonStringInit(tls, bp, ctx)
	if v2 = argc == int32(1); !v2 {
		v1 = Xsqlite3_value_text(tls, **(**uintptr)(__ccgo_up(argv + 1*8)))
		(**(**TJsonPretty)(__ccgo_up(bp + 136))).FzIndent = v1
	}
	if v2 || v1 == uintptr(0) {
		(**(**TJsonPretty)(__ccgo_up(bp + 136))).FzIndent = __ccgo_ts + 26781
		(**(**TJsonPretty)(__ccgo_up(bp + 136))).FszIndent = uint32(4)
	} else {
		(**(**TJsonPretty)(__ccgo_up(bp + 136))).FszIndent = uint32(libc.Xstrlen(tls, (**(**TJsonPretty)(__ccgo_up(bp + 136))).FzIndent))
	}
	_jsonTranslateBlobToPrettyText(tls, bp+136, uint32(0))
	_jsonReturnString(tls, bp, uintptr(0), uintptr(0))
	_jsonParseFree(tls, (**(**TJsonPretty)(__ccgo_up(bp + 136))).FpParse)
}

// C documentation
//
//	/*
//	** json_replace(JSON, PATH, VALUE, ...)
//	**
//	** Replace the value at PATH with VALUE.  If PATH does not already exist,
//	** this routine is a no-op.  If JSON or PATH is malformed, throw an error.
//	*/
func _jsonReplaceFunc(tls *libc.TLS, ctx uintptr, argc int32, argv uintptr) {
	if argc < int32(1) {
		return
	}
	if argc&int32(1) == 0 {
		_jsonWrongNumArgs(tls, ctx, __ccgo_ts+17061)
		return
	}
	_jsonInsertIntoBlob(tls, ctx, argc, argv, int32(JEDIT_REPL))
}

// C documentation
//
//	/* Make the text in p (which is probably a generated JSON text string)
//	** the result of the SQL function.
//	**
//	** The JsonString is reset.
//	**
//	** If pParse and ctx are both non-NULL, then the SQL string in p is
//	** loaded into the zJson field of the pParse object as a RCStr and the
//	** pParse is added to the cache.
//	*/
func _jsonReturnString(tls *libc.TLS, p uintptr, pParse uintptr, ctx uintptr) {
	var flags, rc int32
	_, _ = flags, rc
	_jsonStringTerminate(tls, p)
	if libc.Int32FromUint8((*TJsonString)(unsafe.Pointer(p)).FeErr) == 0 {
		flags = int32(int64(Xsqlite3_user_data(tls, (*TJsonString)(unsafe.Pointer(p)).FpCtx)))
		if flags&int32(JSON_BLOB) != 0 {
			_jsonReturnStringAsBlob(tls, p)
		} else {
			if (*TJsonString)(unsafe.Pointer(p)).FbStatic != 0 {
				Xsqlite3_result_text64(tls, (*TJsonString)(unsafe.Pointer(p)).FpCtx, (*TJsonString)(unsafe.Pointer(p)).FzBuf, (*TJsonString)(unsafe.Pointer(p)).FnUsed, uintptr(-libc.Int32FromInt32(1)), uint8(SQLITE_UTF8))
			} else {
				if pParse != 0 && libc.Int32FromUint8((*TJsonParse)(unsafe.Pointer(pParse)).FbJsonIsRCStr) == 0 && (*TJsonParse)(unsafe.Pointer(pParse)).FnBlobAlloc > uint32(0) {
					(*TJsonParse)(unsafe.Pointer(pParse)).FzJson = _sqlite3RCStrRef(tls, (*TJsonString)(unsafe.Pointer(p)).FzBuf)
					(*TJsonParse)(unsafe.Pointer(pParse)).FnJson = libc.Int32FromUint64((*TJsonString)(unsafe.Pointer(p)).FnUsed)
					(*TJsonParse)(unsafe.Pointer(pParse)).FbJsonIsRCStr = uint8(1)
					rc = _jsonCacheInsert(tls, ctx, pParse)
					if rc == int32(SQLITE_NOMEM) {
						Xsqlite3_result_error_nomem(tls, ctx)
						_jsonStringReset(tls, p)
						return
					}
				}
				Xsqlite3_result_text64(tls, (*TJsonString)(unsafe.Pointer(p)).FpCtx, _sqlite3RCStrRef(tls, (*TJsonString)(unsafe.Pointer(p)).FzBuf), (*TJsonString)(unsafe.Pointer(p)).FnUsed, __ccgo_fp(_sqlite3RCStrUnref), uint8(SQLITE_UTF8))
			}
		}
	} else {
		if libc.Int32FromUint8((*TJsonString)(unsafe.Pointer(p)).FeErr)&int32(JSTRING_OOM) != 0 {
			Xsqlite3_result_error_nomem(tls, (*TJsonString)(unsafe.Pointer(p)).FpCtx)
		} else {
			if libc.Int32FromUint8((*TJsonString)(unsafe.Pointer(p)).FeErr)&int32(JSTRING_TOODEEP) != 0 {
				/* error already in p->pCtx */
			} else {
				if libc.Int32FromUint8((*TJsonString)(unsafe.Pointer(p)).FeErr)&int32(JSTRING_MALFORMED) != 0 {
					Xsqlite3_result_error(tls, (*TJsonString)(unsafe.Pointer(p)).FpCtx, __ccgo_ts+26451, -int32(1))
				}
			}
		}
	}
	_jsonStringReset(tls, p)
}

/**************************************************************************
** Utility routines for dealing with JsonParse objects
**************************************************************************/

// C documentation
//
//	/* Report JSON nested too deep
//	*/
func _jsonStringTooDeep(tls *libc.TLS, p uintptr) {
	var v1 uintptr
	_ = v1
	v1 = p + 33
	*(*Tu8)(unsafe.Pointer(v1)) = Tu8(int32(*(*Tu8)(unsafe.Pointer(v1))) | libc.Int32FromInt32(JSTRING_TOODEEP))
	Xsqlite3_result_error(tls, (*TJsonString)(unsafe.Pointer(p)).FpCtx, __ccgo_ts+26401, -int32(1))
	_jsonStringReset(tls, p)
}

// C documentation
//
//	/*
//	** json_valid(JSON)
//	** json_valid(JSON, FLAGS)
//	**
//	** Check the JSON argument to see if it is well-formed.  The FLAGS argument
//	** encodes the various constraints on what is meant by "well-formed":
//	**
//	**     0x01      Canonical RFC-8259 JSON text
//	**     0x02      JSON text with optional JSON-5 extensions
//	**     0x04      Superficially appears to be JSONB
//	**     0x08      Strictly well-formed JSONB
//	**
//	** If the FLAGS argument is omitted, it defaults to 1.  Useful values for
//	** FLAGS include:
//	**
//	**    1          Strict canonical JSON text
//	**    2          JSON text perhaps with JSON-5 extensions
//	**    4          Superficially appears to be JSONB
//	**    5          Canonical JSON text or superficial JSONB
//	**    6          JSON-5 text or superficial JSONB
//	**    8          Strict JSONB
//	**    9          Canonical JSON text or strict JSONB
//	**    10         JSON-5 text or strict JSONB
//	**
//	** Other flag combinations are redundant.  For example, every canonical
//	** JSON text is also well-formed JSON-5 text, so FLAG values 2 and 3
//	** are the same.  Similarly, any input that passes a strict JSONB validation
//	** will also pass the superficial validation so 12 through 15 are the same
//	** as 8 through 11 respectively.
//	**
//	** This routine runs in linear time to validate text and when doing strict
//	** JSONB validation.  Superficial JSONB validation is constant time,
//	** assuming the BLOB is already in memory.  The performance advantage
//	** of superficial JSONB validation is why that option is provided.
//	** Application developers can choose to do fast superficial validation or
//	** slower strict validation, according to their specific needs.
//	**
//	** Only the lower four bits of the FLAGS argument are currently used.
//	** Higher bits are reserved for future expansion.   To facilitate
//	** compatibility, the current implementation raises an error if any bit
//	** in FLAGS is set other than the lower four bits.
//	**
//	** The original circa 2015 implementation of the JSON routines in
//	** SQLite only supported canonical RFC-8259 JSON text and the json_valid()
//	** function only accepted one argument.  That is why the default value
//	** for the FLAGS argument is 1, since FLAGS=1 causes this routine to only
//	** recognize canonical RFC-8259 JSON text as valid.  The extra FLAGS
//	** argument was added when the JSON routines were extended to support
//	** JSON5-like extensions and binary JSONB stored in BLOBs.
//	**
//	** Return Values:
//	**
//	**   *   Raise an error if FLAGS is outside the range of 1 to 15.
//	**   *   Return NULL if the input is NULL
//	**   *   Return 1 if the input is well-formed.
//	**   *   Return 0 if the input is not well-formed.
//	*/
func _jsonValidFunc(tls *libc.TLS, ctx uintptr, argc int32, argv uintptr) {
	bp := tls.Alloc(144)
	defer tls.Free(144)
	var f Ti64
	var flags, res Tu8
	var p uintptr
	var _ /* px at bp+72 */ TJsonParse
	var _ /* py at bp+0 */ TJsonParse
	_, _, _, _ = f, flags, p, res /* The parse */
	flags = uint8(1)
	res = uint8(0)
	if argc == int32(2) {
		f = Xsqlite3_value_int64(tls, **(**uintptr)(__ccgo_up(argv + 1*8)))
		if f < int64(1) || f > int64(15) {
			Xsqlite3_result_error(tls, ctx, __ccgo_ts+26786, -int32(1))
			return
		}
		flags = libc.Uint8FromInt64(f & int64(0x0f))
	}
	switch Xsqlite3_value_type(tls, **(**uintptr)(__ccgo_up(argv))) {
	case int32(SQLITE_NULL):
		return
	case int32(SQLITE_BLOB):
		libc.Xmemset(tls, bp, 0, uint64(72))
		if _jsonArgIsJsonb(tls, **(**uintptr)(__ccgo_up(argv)), bp) != 0 {
			if libc.Int32FromUint8(flags)&int32(0x04) != 0 {
				/* Superficial checking only - accomplished by the
				 ** jsonArgIsJsonb() call above. */
				res = uint8(1)
			} else {
				if libc.Int32FromUint8(flags)&int32(0x08) != 0 {
					/* Strict checking.  Check by translating BLOB->TEXT->BLOB.  If
					 ** no errors occur, call that a "strict check". */
					res = libc.BoolUint8(uint32(0) == _jsonbValidityCheck(tls, bp, uint32(0), (**(**TJsonParse)(__ccgo_up(bp))).FnBlob, uint32(1)))
				}
			}
			break
		}
		/* Fall through into interpreting the input as text.  See note
		 ** above at tag-20240123-a. */
		fallthrough
	default:
		if libc.Int32FromUint8(flags)&int32(0x3) == 0 {
			break
		}
		libc.Xmemset(tls, bp+72, 0, uint64(72))
		p = _jsonParseFuncArg(tls, ctx, **(**uintptr)(__ccgo_up(argv)), uint32(JSON_KEEPERROR))
		if p != 0 {
			if (*TJsonParse)(unsafe.Pointer(p)).Foom != 0 {
				Xsqlite3_result_error_nomem(tls, ctx)
			} else {
				if (*TJsonParse)(unsafe.Pointer(p)).FnErr != 0 {
					/* no-op */
				} else {
					if libc.Int32FromUint8(flags)&int32(0x02) != 0 || libc.Int32FromUint8((*TJsonParse)(unsafe.Pointer(p)).FhasNonstd) == 0 {
						res = uint8(1)
					}
				}
			}
			_jsonParseFree(tls, p)
		} else {
			Xsqlite3_result_error_nomem(tls, ctx)
		}
		break
	}
	Xsqlite3_result_int(tls, ctx, libc.Int32FromUint8(res))
}

// C documentation
//
//	/*
//	** Report the wrong number of arguments for json_insert(), json_replace()
//	** or json_set().
//	*/
func _jsonWrongNumArgs(tls *libc.TLS, pCtx uintptr, zFuncName uintptr) {
	bp := tls.Alloc(16)
	defer tls.Free(16)
	var zMsg uintptr
	_ = zMsg
	zMsg = Xsqlite3_mprintf(tls, __ccgo_ts+26497, libc.VaList(bp+8, zFuncName))
	Xsqlite3_result_error(tls, pCtx, zMsg, -int32(1))
	Xsqlite3_free(tls, zMsg)
}

/****************************************************************************
** Utility routines for dealing with the binary BLOB representation of JSON
****************************************************************************/

// C documentation
//
//	/* Human-readable names for the JSONB values.  The index for each
//	** string must correspond to the JSONB_* integer above.
//	*/
var _jsonbType = [17]uintptr{
	0:  __ccgo_ts + 1679,
	1:  __ccgo_ts + 8171,
	2:  __ccgo_ts + 8176,
	3:  __ccgo_ts + 6485,
	4:  __ccgo_ts + 6485,
	5:  __ccgo_ts + 6480,
	6:  __ccgo_ts + 6480,
	7:  __ccgo_ts + 8480,
	8:  __ccgo_ts + 8480,
	9:  __ccgo_ts + 8480,
	10: __ccgo_ts + 8480,
	11: __ccgo_ts + 26388,
	12: __ccgo_ts + 26394,
	13: __ccgo_ts + 1693,
	14: __ccgo_ts + 1693,
	15: __ccgo_ts + 1693,
	16: __ccgo_ts + 1693,
}

// C documentation
//
//	/*
//	** Check a single element of the JSONB in pParse for validity.
//	**
//	** The element to be checked starts at offset i and must end at on the
//	** last byte before iEnd.
//	**
//	** Return 0 if everything is correct.  Return the 1-based byte offset of the
//	** error if a problem is detected.  (In other words, if the error is at offset
//	** 0, return 1).
//	*/
func _jsonbValidityCheck(tls *libc.TLS, pParse uintptr, i Tu32, iEnd Tu32, iDepth Tu32) (r Tu32) {
	bp := tls.Alloc(16)
	defer tls.Free(16)
	var cnt, j, k, n, sub, sub1, szC Tu32
	var seen, x Tu8
	var z uintptr
	var v1 uint32
	var _ /* c at bp+4 */ Tu32
	var _ /* sz at bp+0 */ Tu32
	_, _, _, _, _, _, _, _, _, _, _ = cnt, j, k, n, seen, sub, sub1, szC, x, z, v1
	if iDepth > uint32(JSON_MAX_DEPTH) {
		return i + uint32(1)
	}
	**(**Tu32)(__ccgo_up(bp)) = uint32(0)
	n = _jsonbPayloadSize(tls, pParse, i, bp)
	if n == uint32(0) {
		return i + uint32(1)
	} /* Checked by caller */
	if i+n+**(**Tu32)(__ccgo_up(bp)) != iEnd {
		return i + uint32(1)
	} /* Checked by caller */
	z = (*TJsonParse)(unsafe.Pointer(pParse)).FaBlob
	x = libc.Uint8FromInt32(libc.Int32FromUint8(**(**Tu8)(__ccgo_up(z + uintptr(i)))) & int32(0x0f))
	switch libc.Int32FromUint8(x) {
	case JSONB_NULL:
		fallthrough
	case int32(JSONB_TRUE):
		fallthrough
	case int32(JSONB_FALSE):
		if n+**(**Tu32)(__ccgo_up(bp)) == uint32(1) {
			v1 = uint32(0)
		} else {
			v1 = i + uint32(1)
		}
		return v1
	case int32(JSONB_INT):
		if **(**Tu32)(__ccgo_up(bp)) < uint32(1) {
			return i + uint32(1)
		}
		j = i + n
		if libc.Int32FromUint8(**(**Tu8)(__ccgo_up(z + uintptr(j)))) == int32('-') {
			j = j + 1
			if **(**Tu32)(__ccgo_up(bp)) < uint32(2) {
				return i + uint32(1)
			}
		}
		k = i + n + **(**Tu32)(__ccgo_up(bp))
		for j < k {
			if libc.Int32FromUint8(_sqlite3CtypeMap[**(**Tu8)(__ccgo_up(z + uintptr(j)))])&int32(0x04) != 0 {
				j = j + 1
			} else {
				return j + uint32(1)
			}
		}
		return uint32(0)
	case int32(JSONB_INT5):
		if **(**Tu32)(__ccgo_up(bp)) < uint32(3) {
			return i + uint32(1)
		}
		j = i + n
		if libc.Int32FromUint8(**(**Tu8)(__ccgo_up(z + uintptr(j)))) == int32('-') {
			if **(**Tu32)(__ccgo_up(bp)) < uint32(4) {
				return i + uint32(1)
			}
			j = j + 1
		}
		if libc.Int32FromUint8(**(**Tu8)(__ccgo_up(z + uintptr(j)))) != int32('0') {
			return i + uint32(1)
		}
		if libc.Int32FromUint8(**(**Tu8)(__ccgo_up(z + uintptr(j+uint32(1))))) != int32('x') && libc.Int32FromUint8(**(**Tu8)(__ccgo_up(z + uintptr(j+uint32(1))))) != int32('X') {
			return j + uint32(2)
		}
		j = j + uint32(2)
		k = i + n + **(**Tu32)(__ccgo_up(bp))
		for j < k {
			if libc.Int32FromUint8(_sqlite3CtypeMap[**(**Tu8)(__ccgo_up(z + uintptr(j)))])&int32(0x08) != 0 {
				j = j + 1
			} else {
				return j + uint32(1)
			}
		}
		return uint32(0)
	case int32(JSONB_FLOAT):
		fallthrough
	case int32(JSONB_FLOAT5):
		seen = uint8(0) /* 0: initial.  1: '.' seen  2: 'e' seen */
		if **(**Tu32)(__ccgo_up(bp)) < uint32(2) {
			return i + uint32(1)
		}
		j = i + n
		k = j + **(**Tu32)(__ccgo_up(bp))
		if libc.Int32FromUint8(**(**Tu8)(__ccgo_up(z + uintptr(j)))) == int32('-') {
			j = j + 1
			if **(**Tu32)(__ccgo_up(bp)) < uint32(3) {
				return i + uint32(1)
			}
		}
		if libc.Int32FromUint8(**(**Tu8)(__ccgo_up(z + uintptr(j)))) == int32('.') {
			if libc.Int32FromUint8(x) == int32(JSONB_FLOAT) {
				return j + uint32(1)
			}
			if !(libc.Int32FromUint8(_sqlite3CtypeMap[**(**Tu8)(__ccgo_up(z + uintptr(j+uint32(1))))])&libc.Int32FromInt32(0x04) != 0) {
				return j + uint32(1)
			}
			j = j + uint32(2)
			seen = uint8(1)
		} else {
			if libc.Int32FromUint8(**(**Tu8)(__ccgo_up(z + uintptr(j)))) == int32('0') && libc.Int32FromUint8(x) == int32(JSONB_FLOAT) {
				if j+uint32(3) > k {
					return j + uint32(1)
				}
				if libc.Int32FromUint8(**(**Tu8)(__ccgo_up(z + uintptr(j+uint32(1))))) != int32('.') && libc.Int32FromUint8(**(**Tu8)(__ccgo_up(z + uintptr(j+uint32(1))))) != int32('e') && libc.Int32FromUint8(**(**Tu8)(__ccgo_up(z + uintptr(j+uint32(1))))) != int32('E') {
					return j + uint32(1)
				}
				j = j + 1
			}
		}
		for {
			if !(j < k) {
				break
			}
			if libc.Int32FromUint8(_sqlite3CtypeMap[**(**Tu8)(__ccgo_up(z + uintptr(j)))])&int32(0x04) != 0 {
				goto _2
			}
			if libc.Int32FromUint8(**(**Tu8)(__ccgo_up(z + uintptr(j)))) == int32('.') {
				if libc.Int32FromUint8(seen) > 0 {
					return j + uint32(1)
				}
				if libc.Int32FromUint8(x) == int32(JSONB_FLOAT) && (j == k-uint32(1) || !(libc.Int32FromUint8(_sqlite3CtypeMap[**(**Tu8)(__ccgo_up(z + uintptr(j+uint32(1))))])&libc.Int32FromInt32(0x04) != 0)) {
					return j + uint32(1)
				}
				seen = uint8(1)
				goto _2
			}
			if libc.Int32FromUint8(**(**Tu8)(__ccgo_up(z + uintptr(j)))) == int32('e') || libc.Int32FromUint8(**(**Tu8)(__ccgo_up(z + uintptr(j)))) == int32('E') {
				if libc.Int32FromUint8(seen) == int32(2) {
					return j + uint32(1)
				}
				if j == k-uint32(1) {
					return j + uint32(1)
				}
				if libc.Int32FromUint8(**(**Tu8)(__ccgo_up(z + uintptr(j+uint32(1))))) == int32('+') || libc.Int32FromUint8(**(**Tu8)(__ccgo_up(z + uintptr(j+uint32(1))))) == int32('-') {
					j = j + 1
					if j == k-uint32(1) {
						return j + uint32(1)
					}
				}
				seen = uint8(2)
				goto _2
			}
			return j + uint32(1)
			goto _2
		_2:
			;
			j = j + 1
		}
		if libc.Int32FromUint8(seen) == 0 {
			return i + uint32(1)
		}
		return uint32(0)
	case int32(JSONB_TEXT):
		j = i + n
		k = j + **(**Tu32)(__ccgo_up(bp))
		for j < k {
			if !(_jsonIsOk[**(**Tu8)(__ccgo_up(z + uintptr(j)))] != 0) && libc.Int32FromUint8(**(**Tu8)(__ccgo_up(z + uintptr(j)))) != int32('\'') {
				return j + uint32(1)
			}
			j = j + 1
		}
		return uint32(0)
	case int32(JSONB_TEXTJ):
		fallthrough
	case int32(JSONB_TEXT5):
		j = i + n
		k = j + **(**Tu32)(__ccgo_up(bp))
		for j < k {
			if !(_jsonIsOk[**(**Tu8)(__ccgo_up(z + uintptr(j)))] != 0) && libc.Int32FromUint8(**(**Tu8)(__ccgo_up(z + uintptr(j)))) != int32('\'') {
				if libc.Int32FromUint8(**(**Tu8)(__ccgo_up(z + uintptr(j)))) == int32('"') {
					if libc.Int32FromUint8(x) == int32(JSONB_TEXTJ) {
						return j + uint32(1)
					}
				} else {
					if libc.Int32FromUint8(**(**Tu8)(__ccgo_up(z + uintptr(j)))) <= int32(0x1f) {
						/* Control characters in JSON5 string literals are ok */
						if libc.Int32FromUint8(x) == int32(JSONB_TEXTJ) {
							return j + uint32(1)
						}
					} else {
						if libc.Int32FromUint8(**(**Tu8)(__ccgo_up(z + uintptr(j)))) != int32('\\') || j+uint32(1) >= k {
							return j + uint32(1)
						} else {
							if libc.Xstrchr(tls, __ccgo_ts+26540, libc.Int32FromUint8(**(**Tu8)(__ccgo_up(z + uintptr(j+uint32(1)))))) != uintptr(0) {
								j = j + 1
							} else {
								if libc.Int32FromUint8(**(**Tu8)(__ccgo_up(z + uintptr(j+uint32(1))))) == int32('u') {
									if j+uint32(5) >= k {
										return j + uint32(1)
									}
									if !(_jsonIs4Hex(tls, z+uintptr(j+uint32(2))) != 0) {
										return j + uint32(1)
									}
									j = j + 1
								} else {
									if libc.Int32FromUint8(x) != int32(JSONB_TEXT5) {
										return j + uint32(1)
									} else {
										**(**Tu32)(__ccgo_up(bp + 4)) = uint32(0)
										szC = _jsonUnescapeOneChar(tls, z+uintptr(j), k-j, bp+4)
										if **(**Tu32)(__ccgo_up(bp + 4)) == uint32(JSON_INVALID_CHAR) {
											return j + uint32(1)
										}
										j = j + (szC - uint32(1))
									}
								}
							}
						}
					}
				}
			}
			j = j + 1
		}
		return uint32(0)
	case int32(JSONB_TEXTRAW):
		return uint32(0)
	case int32(JSONB_ARRAY):
		j = i + n
		k = j + **(**Tu32)(__ccgo_up(bp))
		for j < k {
			**(**Tu32)(__ccgo_up(bp)) = uint32(0)
			n = _jsonbPayloadSize(tls, pParse, j, bp)
			if n == uint32(0) {
				return j + uint32(1)
			}
			if j+n+**(**Tu32)(__ccgo_up(bp)) > k {
				return j + uint32(1)
			}
			sub = _jsonbValidityCheck(tls, pParse, j, j+n+**(**Tu32)(__ccgo_up(bp)), iDepth+uint32(1))
			if sub != 0 {
				return sub
			}
			j = j + (n + **(**Tu32)(__ccgo_up(bp)))
		}
		return uint32(0)
	case int32(JSONB_OBJECT):
		cnt = uint32(0)
		j = i + n
		k = j + **(**Tu32)(__ccgo_up(bp))
		for j < k {
			**(**Tu32)(__ccgo_up(bp)) = uint32(0)
			n = _jsonbPayloadSize(tls, pParse, j, bp)
			if n == uint32(0) {
				return j + uint32(1)
			}
			if j+n+**(**Tu32)(__ccgo_up(bp)) > k {
				return j + uint32(1)
			}
			if cnt&uint32(1) == uint32(0) {
				x = libc.Uint8FromInt32(libc.Int32FromUint8(**(**Tu8)(__ccgo_up(z + uintptr(j)))) & int32(0x0f))
				if libc.Int32FromUint8(x) < int32(JSONB_TEXT) || libc.Int32FromUint8(x) > int32(JSONB_TEXTRAW) {
					return j + uint32(1)
				}
			}
			sub1 = _jsonbValidityCheck(tls, pParse, j, j+n+**(**Tu32)(__ccgo_up(bp)), iDepth+uint32(1))
			if sub1 != 0 {
				return sub1
			}
			cnt = cnt + 1
			j = j + (n + **(**Tu32)(__ccgo_up(bp)))
		}
		if cnt&uint32(1) != uint32(0) {
			return j + uint32(1)
		}
		return uint32(0)
	default:
		return i + uint32(1)
	}
	return r
}

// C documentation
//
//	/*
//	** Implementation of the like() SQL function.  This function implements
//	** the built-in LIKE operator.  The first argument to the function is the
//	** pattern and the second argument is the string.  So, the SQL statements:
//	**
//	**       A LIKE B
//	**
//	** is implemented as like(B,A).
//	**
//	** This same function (with a different compareInfo structure) computes
//	** the GLOB operator.
//	*/
func _likeFunc(tls *libc.TLS, context uintptr, argc int32, argv uintptr) {
	bp := tls.Alloc(16)
	defer tls.Free(16)
	var db, pInfo, zA, zB uintptr
	var escape Tu32
	var nPat int32
	var _ /* backupInfo at bp+0 */ TcompareInfo
	var _ /* zEsc at bp+8 */ uintptr
	_, _, _, _, _, _ = db, escape, nPat, pInfo, zA, zB
	db = Xsqlite3_context_db_handle(tls, context)
	pInfo = Xsqlite3_user_data(tls, context)
	if Xsqlite3_value_type(tls, **(**uintptr)(__ccgo_up(argv))) == int32(SQLITE_BLOB) || Xsqlite3_value_type(tls, **(**uintptr)(__ccgo_up(argv + 1*8))) == int32(SQLITE_BLOB) {
		Xsqlite3_result_int(tls, context, 0)
		return
	}
	/* Limit the length of the LIKE or GLOB pattern to avoid problems
	 ** of deep recursion and N*N behavior in patternCompare().
	 */
	nPat = Xsqlite3_value_bytes(tls, **(**uintptr)(__ccgo_up(argv)))
	if nPat > **(**int32)(__ccgo_up(db + 136 + 8*4)) {
		Xsqlite3_result_error(tls, context, __ccgo_ts+16474, -int32(1))
		return
	}
	if argc == int32(3) {
		/* The escape character string must consist of a single UTF-8 character.
		 ** Otherwise, return an error.
		 */
		**(**uintptr)(__ccgo_up(bp + 8)) = Xsqlite3_value_text(tls, **(**uintptr)(__ccgo_up(argv + 2*8)))
		if **(**uintptr)(__ccgo_up(bp + 8)) == uintptr(0) {
			return
		}
		if _sqlite3Utf8CharLen(tls, **(**uintptr)(__ccgo_up(bp + 8)), -int32(1)) != int32(1) {
			Xsqlite3_result_error(tls, context, __ccgo_ts+16507, -int32(1))
			return
		}
		escape = _sqlite3Utf8Read(tls, bp+8)
		if escape == uint32((*TcompareInfo)(unsafe.Pointer(pInfo)).FmatchAll) || escape == uint32((*TcompareInfo)(unsafe.Pointer(pInfo)).FmatchOne) {
			libc.Xmemcpy(tls, bp, pInfo, uint64(4))
			pInfo = bp
			if escape == uint32((*TcompareInfo)(unsafe.Pointer(pInfo)).FmatchAll) {
				(*TcompareInfo)(unsafe.Pointer(pInfo)).FmatchAll = uint8(0)
			}
			if escape == uint32((*TcompareInfo)(unsafe.Pointer(pInfo)).FmatchOne) {
				(*TcompareInfo)(unsafe.Pointer(pInfo)).FmatchOne = uint8(0)
			}
		}
	} else {
		escape = uint32((*TcompareInfo)(unsafe.Pointer(pInfo)).FmatchSet)
	}
	zB = Xsqlite3_value_text(tls, **(**uintptr)(__ccgo_up(argv)))
	zA = Xsqlite3_value_text(tls, **(**uintptr)(__ccgo_up(argv + 1*8)))
	if zA != 0 && zB != 0 {
		Xsqlite3_result_int(tls, context, libc.BoolInt32(_patternCompare(tls, zB, zA, pInfo, escape) == SQLITE_MATCH))
	}
}

// C documentation
//
//	/*
//	** A function that loads a shared-library extension then returns NULL.
//	*/
func _loadExt(tls *libc.TLS, context uintptr, argc int32, argv uintptr) {
	bp := tls.Alloc(16)
	defer tls.Free(16)
	var db, zFile, zProc uintptr
	var _ /* zErrMsg at bp+0 */ uintptr
	_, _, _ = db, zFile, zProc
	zFile = Xsqlite3_value_text(tls, **(**uintptr)(__ccgo_up(argv)))
	db = Xsqlite3_context_db_handle(tls, context)
	**(**uintptr)(__ccgo_up(bp)) = uintptr(0)
	/* Disallow the load_extension() SQL function unless the SQLITE_LoadExtFunc
	 ** flag is set.  See the sqlite3_enable_load_extension() API.
	 */
	if (*Tsqlite3)(unsafe.Pointer(db)).Fflags&uint64(SQLITE_LoadExtFunc) == uint64(0) {
		Xsqlite3_result_error(tls, context, __ccgo_ts+13664, -int32(1))
		return
	}
	if argc == int32(2) {
		zProc = Xsqlite3_value_text(tls, **(**uintptr)(__ccgo_up(argv + 1*8)))
	} else {
		zProc = uintptr(0)
	}
	if zFile != 0 && Xsqlite3_load_extension(tls, db, zFile, zProc, bp) != 0 {
		Xsqlite3_result_error(tls, context, **(**uintptr)(__ccgo_up(bp)), -int32(1))
		Xsqlite3_free(tls, **(**uintptr)(__ccgo_up(bp)))
	}
}

// C documentation
//
//	/*
//	** Load content from the sqlite_stat4 table into
//	** the Index.aSample[] arrays of all indices.
//	*/
func _loadStat4(tls *libc.TLS, db uintptr, zDb uintptr) (r int32) {
	var pStat4, v1 uintptr
	var rc int32
	var v2 bool
	_, _, _, _ = pStat4, rc, v1, v2
	rc = SQLITE_OK
	if v2 = (*Tsqlite3)(unsafe.Pointer(db)).FdbOptFlags&libc.Uint32FromInt32(libc.Int32FromInt32(SQLITE_Stat4)) == uint32(0); v2 {
		v1 = _sqlite3FindTable(tls, db, __ccgo_ts+12852, zDb)
		pStat4 = v1
	}
	if v2 && v1 != uintptr(0) && libc.Int32FromUint8((*TTable)(unsafe.Pointer(pStat4)).FeTabType) == TABTYP_NORM {
		rc = _loadStatTbl(tls, db, __ccgo_ts+13078, __ccgo_ts+13147, zDb)
	}
	return rc
}

// C documentation
//
//	/*
//	** Get a reference to pPage1 of the database file.  This will
//	** also acquire a readlock on that file.
//	**
//	** SQLITE_OK is returned on success.  If the file is not a
//	** well-formed database file, then SQLITE_CORRUPT is returned.
//	** SQLITE_BUSY is returned if the database is locked.  SQLITE_NOMEM
//	** is returned if we run out of memory.
//	*/
func _lockBtree(tls *libc.TLS, pBt uintptr) (r int32) {
	bp := tls.Alloc(16)
	defer tls.Free(16)
	var nPage, pageSize, usableSize Tu32
	var page1, v1 uintptr
	var rc, v4 int32
	var _ /* isOpen at bp+12 */ int32
	var _ /* nPageFile at bp+8 */ Tu32
	var _ /* pPage1 at bp+0 */ uintptr
	_, _, _, _, _, _, _ = nPage, page1, pageSize, rc, usableSize, v1, v4 /* Number of pages in the database */
	**(**Tu32)(__ccgo_up(bp + 8)) = uint32(0)                            /* Number of pages in the database file */
	rc = _sqlite3PagerSharedLock(tls, (*TBtShared)(unsafe.Pointer(pBt)).FpPager)
	if rc != SQLITE_OK {
		return rc
	}
	rc = _btreeGetPage(tls, pBt, uint32(1), bp, 0)
	if rc != SQLITE_OK {
		return rc
	}
	/* Do some checking to help insure the file we opened really is
	 ** a valid database file.
	 */
	nPage = _sqlite3Get4byte(tls, uintptr(28)+(*TMemPage)(unsafe.Pointer(**(**uintptr)(__ccgo_up(bp)))).FaData)
	_sqlite3PagerPagecount(tls, (*TBtShared)(unsafe.Pointer(pBt)).FpPager, bp+8)
	if nPage == uint32(0) || libc.Xmemcmp(tls, uintptr(24)+(*TMemPage)(unsafe.Pointer(**(**uintptr)(__ccgo_up(bp)))).FaData, uintptr(92)+(*TMemPage)(unsafe.Pointer(**(**uintptr)(__ccgo_up(bp)))).FaData, uint64(4)) != 0 {
		nPage = **(**Tu32)(__ccgo_up(bp + 8))
	}
	if (*Tsqlite3)(unsafe.Pointer((*TBtShared)(unsafe.Pointer(pBt)).Fdb)).Fflags&uint64(SQLITE_ResetDatabase) != uint64(0) {
		nPage = uint32(0)
	}
	if nPage > uint32(0) {
		page1 = (*TMemPage)(unsafe.Pointer(**(**uintptr)(__ccgo_up(bp)))).FaData
		rc = int32(SQLITE_NOTADB)
		/* EVIDENCE-OF: R-43737-39999 Every valid SQLite database file begins
		 ** with the following 16 bytes (in hex): 53 51 4c 69 74 65 20 66 6f 72 6d
		 ** 61 74 20 33 00. */
		if libc.Xmemcmp(tls, page1, uintptr(unsafe.Pointer(&_zMagicHeader)), uint64(16)) != 0 {
			goto page1_init_failed
		}
		if libc.Int32FromUint8(**(**Tu8)(__ccgo_up(page1 + 18))) > int32(2) {
			v1 = pBt + 40
			*(*Tu16)(unsafe.Pointer(v1)) = Tu16(int32(*(*Tu16)(unsafe.Pointer(v1))) | libc.Int32FromInt32(BTS_READ_ONLY))
		}
		if libc.Int32FromUint8(**(**Tu8)(__ccgo_up(page1 + 19))) > int32(2) {
			goto page1_init_failed
		}
		/* If the read version is set to 2, this database should be accessed
		 ** in WAL mode. If the log is not already open, open it now. Then
		 ** return SQLITE_OK and return without populating BtShared.pPage1.
		 ** The caller detects this and calls this function again. This is
		 ** required as the version of page 1 currently in the page1 buffer
		 ** may not be the latest version - there may be a newer one in the log
		 ** file.
		 */
		if libc.Int32FromUint8(**(**Tu8)(__ccgo_up(page1 + 19))) == int32(2) && libc.Int32FromUint16((*TBtShared)(unsafe.Pointer(pBt)).FbtsFlags)&int32(BTS_NO_WAL) == 0 {
			**(**int32)(__ccgo_up(bp + 12)) = 0
			rc = _sqlite3PagerOpenWal(tls, (*TBtShared)(unsafe.Pointer(pBt)).FpPager, bp+12)
			if rc != SQLITE_OK {
				goto page1_init_failed
			} else {
				if **(**int32)(__ccgo_up(bp + 12)) == 0 {
					_releasePageOne(tls, **(**uintptr)(__ccgo_up(bp)))
					return SQLITE_OK
				}
			}
			rc = int32(SQLITE_NOTADB)
		} else {
		}
		/* EVIDENCE-OF: R-15465-20813 The maximum and minimum embedded payload
		 ** fractions and the leaf payload fraction values must be 64, 32, and 32.
		 **
		 ** The original design allowed these amounts to vary, but as of
		 ** version 3.6.0, we require them to be fixed.
		 */
		if libc.Xmemcmp(tls, page1+21, __ccgo_ts+4341, uint64(3)) != 0 {
			goto page1_init_failed
		}
		/* EVIDENCE-OF: R-51873-39618 The page size for a database file is
		 ** determined by the 2-byte integer located at an offset of 16 bytes from
		 ** the beginning of the database file. */
		pageSize = libc.Uint32FromInt32(libc.Int32FromUint8(**(**Tu8)(__ccgo_up(page1 + 16)))<<int32(8) | libc.Int32FromUint8(**(**Tu8)(__ccgo_up(page1 + 17)))<<int32(16))
		/* EVIDENCE-OF: R-25008-21688 The size of a page is a power of two
		 ** between 512 and 65536 inclusive. */
		if (pageSize-uint32(1))&pageSize != uint32(0) || pageSize > uint32(SQLITE_MAX_PAGE_SIZE) || pageSize <= uint32(256) {
			goto page1_init_failed
		}
		/* EVIDENCE-OF: R-59310-51205 The "reserved space" size in the 1-byte
		 ** integer at offset 20 is the number of bytes of space at the end of
		 ** each page to reserve for extensions.
		 **
		 ** EVIDENCE-OF: R-37497-42412 The size of the reserved region is
		 ** determined by the one-byte unsigned integer found at an offset of 20
		 ** into the database file header. */
		usableSize = pageSize - uint32(**(**Tu8)(__ccgo_up(page1 + 20)))
		if pageSize != (*TBtShared)(unsafe.Pointer(pBt)).FpageSize {
			/* After reading the first page of the database assuming a page size
			 ** of BtShared.pageSize, we have discovered that the page-size is
			 ** actually pageSize. Unlock the database, leave pBt->pPage1 at
			 ** zero and return SQLITE_OK. The caller will call this function
			 ** again with the correct page-size.
			 */
			_releasePageOne(tls, **(**uintptr)(__ccgo_up(bp)))
			(*TBtShared)(unsafe.Pointer(pBt)).FusableSize = usableSize
			(*TBtShared)(unsafe.Pointer(pBt)).FpageSize = pageSize
			v1 = pBt + 40
			*(*Tu16)(unsafe.Pointer(v1)) = Tu16(int32(*(*Tu16)(unsafe.Pointer(v1))) | libc.Int32FromInt32(BTS_PAGESIZE_FIXED))
			_freeTempSpace(tls, pBt)
			rc = _sqlite3PagerSetPagesize(tls, (*TBtShared)(unsafe.Pointer(pBt)).FpPager, pBt+52, libc.Int32FromUint32(pageSize-usableSize))
			return rc
		}
		if nPage > **(**Tu32)(__ccgo_up(bp + 8)) {
			if _sqlite3WritableSchema(tls, (*TBtShared)(unsafe.Pointer(pBt)).Fdb) == 0 {
				rc = _sqlite3CorruptError(tls, int32(76633))
				goto page1_init_failed
			} else {
				nPage = **(**Tu32)(__ccgo_up(bp + 8))
			}
		}
		/* EVIDENCE-OF: R-28312-64704 However, the usable size is not allowed to
		 ** be less than 480. In other words, if the page size is 512, then the
		 ** reserved space size cannot exceed 32. */
		if usableSize < uint32(480) {
			goto page1_init_failed
		}
		v1 = pBt + 40
		*(*Tu16)(unsafe.Pointer(v1)) = Tu16(int32(*(*Tu16)(unsafe.Pointer(v1))) | libc.Int32FromInt32(BTS_PAGESIZE_FIXED))
		(*TBtShared)(unsafe.Pointer(pBt)).FpageSize = pageSize
		(*TBtShared)(unsafe.Pointer(pBt)).FusableSize = usableSize
		if _sqlite3Get4byte(tls, page1+uintptr(libc.Int32FromInt32(36)+libc.Int32FromInt32(4)*libc.Int32FromInt32(4))) != 0 {
			v4 = int32(1)
		} else {
			v4 = 0
		}
		(*TBtShared)(unsafe.Pointer(pBt)).FautoVacuum = libc.Uint8FromInt32(v4)
		if _sqlite3Get4byte(tls, page1+uintptr(libc.Int32FromInt32(36)+libc.Int32FromInt32(7)*libc.Int32FromInt32(4))) != 0 {
			v4 = int32(1)
		} else {
			v4 = 0
		}
		(*TBtShared)(unsafe.Pointer(pBt)).FincrVacuum = libc.Uint8FromInt32(v4)
	}
	/* maxLocal is the maximum amount of payload to store locally for
	 ** a cell.  Make sure it is small enough so that at least minFanout
	 ** cells can will fit on one page.  We assume a 10-byte page header.
	 ** Besides the payload, the cell must store:
	 **     2-byte pointer to the cell
	 **     4-byte child pointer
	 **     9-byte nKey value
	 **     4-byte nData value
	 **     4-byte overflow page pointer
	 ** So a cell consists of a 2-byte pointer, a header which is as much as
	 ** 17 bytes long, 0 to N bytes of payload, and an optional 4 byte overflow
	 ** page pointer.
	 */
	(*TBtShared)(unsafe.Pointer(pBt)).FmaxLocal = uint16(((*TBtShared)(unsafe.Pointer(pBt)).FusableSize-libc.Uint32FromInt32(12))*libc.Uint32FromInt32(64)/libc.Uint32FromInt32(255) - libc.Uint32FromInt32(23))
	(*TBtShared)(unsafe.Pointer(pBt)).FminLocal = uint16(((*TBtShared)(unsafe.Pointer(pBt)).FusableSize-libc.Uint32FromInt32(12))*libc.Uint32FromInt32(32)/libc.Uint32FromInt32(255) - libc.Uint32FromInt32(23))
	(*TBtShared)(unsafe.Pointer(pBt)).FmaxLeaf = uint16((*TBtShared)(unsafe.Pointer(pBt)).FusableSize - libc.Uint32FromInt32(35))
	(*TBtShared)(unsafe.Pointer(pBt)).FminLeaf = uint16(((*TBtShared)(unsafe.Pointer(pBt)).FusableSize-libc.Uint32FromInt32(12))*libc.Uint32FromInt32(32)/libc.Uint32FromInt32(255) - libc.Uint32FromInt32(23))
	if libc.Int32FromUint16((*TBtShared)(unsafe.Pointer(pBt)).FmaxLocal) > int32(127) {
		(*TBtShared)(unsafe.Pointer(pBt)).Fmax1bytePayload = uint8(127)
	} else {
		(*TBtShared)(unsafe.Pointer(pBt)).Fmax1bytePayload = uint8((*TBtShared)(unsafe.Pointer(pBt)).FmaxLocal)
	}
	(*TBtShared)(unsafe.Pointer(pBt)).FpPage1 = **(**uintptr)(__ccgo_up(bp))
	(*TBtShared)(unsafe.Pointer(pBt)).FnPage = nPage
	return SQLITE_OK
	goto page1_init_failed
page1_init_failed:
	;
	_releasePageOne(tls, **(**uintptr)(__ccgo_up(bp)))
	(*TBtShared)(unsafe.Pointer(pBt)).FpPage1 = uintptr(0)
	return rc
}

// C documentation
//
//	/*
//	** Log an error that is an API call on a connection pointer that should
//	** not have been used.  The "type" of connection pointer is given as the
//	** argument.  The zType is a word like "NULL" or "closed" or "invalid".
//	*/
func _logBadConnection(tls *libc.TLS, zType uintptr) {
	bp := tls.Alloc(16)
	defer tls.Free(16)
	Xsqlite3_log(tls, int32(SQLITE_MISUSE), __ccgo_ts+1841, libc.VaList(bp+8, zType))
}

// C documentation
//
//	/*
//	** Tag the given column as being part of the PRIMARY KEY
//	*/
func _makeColumnPartOfPrimaryKey(tls *libc.TLS, pParse uintptr, pCol uintptr) {
	var v1 uintptr
	_ = v1
	v1 = pCol + 14
	*(*Tu16)(unsafe.Pointer(v1)) = Tu16(int32(*(*Tu16)(unsafe.Pointer(v1))) | libc.Int32FromInt32(COLFLAG_PRIMKEY))
	if libc.Int32FromUint16((*TColumn)(unsafe.Pointer(pCol)).FcolFlags)&int32(COLFLAG_GENERATED) != 0 {
		_sqlite3ErrorMsg(tls, pParse, __ccgo_ts+14101, 0)
	}
}

// C documentation
//
//	/*
//	** File control method. For custom operations on an memdb-file.
//	*/
func _memdbFileControl(tls *libc.TLS, pFile uintptr, op int32, pArg uintptr) (r int32) {
	bp := tls.Alloc(32)
	defer tls.Free(32)
	var iLimit Tsqlite3_int64
	var p uintptr
	var rc int32
	_, _, _ = iLimit, p, rc
	p = (*TMemFile)(unsafe.Pointer(pFile)).FpStore
	rc = int32(SQLITE_NOTFOUND)
	_memdbEnter(tls, p)
	if op == int32(SQLITE_FCNTL_VFSNAME) {
		**(**uintptr)(__ccgo_up(pArg)) = Xsqlite3_mprintf(tls, __ccgo_ts+4111, libc.VaList(bp+8, (*TMemStore)(unsafe.Pointer(p)).FaData, (*TMemStore)(unsafe.Pointer(p)).Fsz))
		rc = SQLITE_OK
	}
	if op == int32(SQLITE_FCNTL_SIZE_LIMIT) {
		iLimit = **(**Tsqlite3_int64)(__ccgo_up(pArg))
		if iLimit < (*TMemStore)(unsafe.Pointer(p)).Fsz {
			if iLimit < 0 {
				iLimit = (*TMemStore)(unsafe.Pointer(p)).FszMax
			} else {
				iLimit = (*TMemStore)(unsafe.Pointer(p)).Fsz
			}
		}
		(*TMemStore)(unsafe.Pointer(p)).FszMax = iLimit
		**(**Tsqlite3_int64)(__ccgo_up(pArg)) = iLimit
		rc = SQLITE_OK
	}
	_memdbLeave(tls, p)
	return rc
}

// C documentation
//
//	/*
//	** Populate buffer zOut with the full canonical pathname corresponding
//	** to the pathname in zPath. zOut is guaranteed to point to a buffer
//	** of at least (INST_MAX_PATHNAME+1) bytes.
//	*/
func _memdbFullPathname(tls *libc.TLS, pVfs uintptr, zPath uintptr, nOut int32, zOut uintptr) (r int32) {
	bp := tls.Alloc(16)
	defer tls.Free(16)
	_ = pVfs
	Xsqlite3_snprintf(tls, nOut, zOut, __ccgo_ts+3933, libc.VaList(bp+8, zPath))
	return SQLITE_OK
}

var _memdb_vfs = Tsqlite3_vfs{
	FiVersion:   int32(2),
	FmxPathname: int32(1024),
	FzName:      __ccgo_ts + 4105,
}

// C documentation
//
//	/*
//	** The pFunc is the only aggregate function in the query.  Check to see
//	** if the query is a candidate for the min/max optimization.
//	**
//	** If the query is a candidate for the min/max optimization, then set
//	** *ppMinMax to be an ORDER BY clause to be used for the optimization
//	** and return either WHERE_ORDERBY_MIN or WHERE_ORDERBY_MAX depending on
//	** whether pFunc is a min() or max() function.
//	**
//	** If the query is not a candidate for the min/max optimization, return
//	** WHERE_ORDERBY_NORMAL (which must be zero).
//	**
//	** This routine must be called after aggregate functions have been
//	** located but before their arguments have been subjected to aggregate
//	** analysis.
//	*/
func _minMaxQuery(tls *libc.TLS, db uintptr, pFunc uintptr, ppMinMax uintptr) (r Tu8) {
	var eRet int32
	var pEList, pOrderBy, zFunc, v1 uintptr
	var sortFlags Tu8
	_, _, _, _, _, _ = eRet, pEList, pOrderBy, sortFlags, zFunc, v1
	eRet = WHERE_ORDERBY_NORMAL
	sortFlags = uint8(0)
	pEList = *(*uintptr)(unsafe.Pointer(pFunc + 32))
	if pEList == uintptr(0) || (*TExprList)(unsafe.Pointer(pEList)).FnExpr != int32(1) || (*TExpr)(unsafe.Pointer(pFunc)).Fflags&libc.Uint32FromInt32(libc.Int32FromInt32(EP_WinFunc)) != uint32(0) || (*Tsqlite3)(unsafe.Pointer(db)).FdbOptFlags&libc.Uint32FromInt32(libc.Int32FromInt32(SQLITE_MinMaxOpt)) != uint32(0) {
		return libc.Uint8FromInt32(eRet)
	}
	zFunc = *(*uintptr)(unsafe.Pointer(pFunc + 8))
	if _sqlite3StrICmp(tls, zFunc, __ccgo_ts+16795) == 0 {
		eRet = int32(WHERE_ORDERBY_MIN)
		if _sqlite3ExprCanBeNull(tls, (*(*TExprList_item)(unsafe.Pointer(pEList + 8))).FpExpr) != 0 {
			sortFlags = uint8(KEYINFO_ORDER_BIGNULL)
		}
	} else {
		if _sqlite3StrICmp(tls, zFunc, __ccgo_ts+16799) == 0 {
			eRet = int32(WHERE_ORDERBY_MAX)
			sortFlags = uint8(KEYINFO_ORDER_DESC)
		} else {
			return libc.Uint8FromInt32(eRet)
		}
	}
	v1 = _sqlite3ExprListDup(tls, db, pEList, 0)
	pOrderBy = v1
	**(**uintptr)(__ccgo_up(ppMinMax)) = v1
	if pOrderBy != 0 {
		(*(*TExprList_item)(unsafe.Pointer(pOrderBy + 8))).Ffg.FsortFlags = sortFlags
	}
	return libc.Uint8FromInt32(eRet)
}

// C documentation
//
//	/*
//	** This routine is called to process a compound query form from
//	** two or more separate queries using UNION, UNION ALL, EXCEPT, or
//	** INTERSECT
//	**
//	** "p" points to the right-most of the two queries.  the query on the
//	** left is p->pPrior.  The left query could also be a compound query
//	** in which case this routine will be called recursively.
//	**
//	** The results of the total query are to be written into a destination
//	** of type eDest with parameter iParm.
//	**
//	** Example 1:  Consider a three-way compound SQL statement.
//	**
//	**     SELECT a FROM t1 UNION SELECT b FROM t2 UNION SELECT c FROM t3
//	**
//	** This statement is parsed up as follows:
//	**
//	**     SELECT c FROM t3
//	**      |
//	**      `----->  SELECT b FROM t2
//	**                |
//	**                `------>  SELECT a FROM t1
//	**
//	** The arrows in the diagram above represent the Select.pPrior pointer.
//	** So if this routine is called with p equal to the t3 query, then
//	** pPrior will be the t2 query.  p->op will be TK_UNION in this case.
//	**
//	** Notice that because of the way SQLite parses compound SELECTs, the
//	** individual selects always group from left to right.
//	*/
func _multiSelect(tls *libc.TLS, pParse uintptr, p uintptr, pDest uintptr) (r int32) {
	bp := tls.Alloc(48)
	defer tls.Free(48)
	var addr, rc int32
	var db, pDelete, pOne, pPrior, v uintptr
	var _ /* dest at bp+0 */ TSelectDest
	var _ /* nLimit at bp+40 */ int32
	_, _, _, _, _, _, _ = addr, db, pDelete, pOne, pPrior, rc, v
	rc = SQLITE_OK       /* Alternative data destination */
	pDelete = uintptr(0) /* Database connection */
	/* Make sure there is no ORDER BY or LIMIT clause on prior SELECTs.  Only
	 ** the last (right-most) SELECT in the series may have an ORDER BY or LIMIT.
	 */
	/* Calling function guarantees this much */
	db = (*TParse)(unsafe.Pointer(pParse)).Fdb
	pPrior = (*TSelect)(unsafe.Pointer(p)).FpPrior
	**(**TSelectDest)(__ccgo_up(bp)) = **(**TSelectDest)(__ccgo_up(pDest))
	v = _sqlite3GetVdbe(tls, pParse)
	/* The VDBE already created by calling function */
	/* Create the destination temporary table if necessary
	 */
	if libc.Int32FromUint8((**(**TSelectDest)(__ccgo_up(bp))).FeDest) == int32(SRT_EphemTab) {
		_sqlite3VdbeAddOp2(tls, v, int32(OP_OpenEphemeral), (**(**TSelectDest)(__ccgo_up(bp))).FiSDParm, (*TExprList)(unsafe.Pointer((*TSelect)(unsafe.Pointer(p)).FpEList)).FnExpr)
		(**(**TSelectDest)(__ccgo_up(bp))).FeDest = uint8(SRT_Table)
	}
	/* Special handling for a compound-select that originates as a VALUES clause.
	 */
	if (*TSelect)(unsafe.Pointer(p)).FselFlags&uint32(SF_MultiValue) != 0 {
		rc = _multiSelectValues(tls, pParse, p, bp)
		if rc >= 0 {
			goto multi_select_end
		}
		rc = SQLITE_OK
	}
	/* Make sure all SELECTs in the statement have the same number of elements
	 ** in their result sets.
	 */
	if (*TSelect)(unsafe.Pointer(p)).FselFlags&uint32(SF_Recursive) != uint32(0) && _hasAnchor(tls, p) != 0 {
		_generateWithRecursiveQuery(tls, pParse, p, bp)
	} else {
		if (*TSelect)(unsafe.Pointer(p)).FpOrderBy != 0 {
			/* If the compound has an ORDER BY clause, then always use the merge
			 ** algorithm. */
			return _multiSelectByMerge(tls, pParse, p, pDest)
		} else {
			if libc.Int32FromUint8((*TSelect)(unsafe.Pointer(p)).Fop) != int32(TK_ALL) {
				/* If the compound is EXCEPT, INTERSECT, or UNION (anything other than
				 ** UNION ALL) then also always use the merge algorithm.  However, the
				 ** multiSelectByMerge() routine requires that the compound have an
				 ** ORDER BY clause, and it doesn't right now.  So invent one first. */
				pOne = _sqlite3ExprInt32(tls, db, int32(1))
				(*TSelect)(unsafe.Pointer(p)).FpOrderBy = _sqlite3ExprListAppend(tls, pParse, uintptr(0), pOne)
				if (*TParse)(unsafe.Pointer(pParse)).FnErr != 0 {
					goto multi_select_end
				}
				*(*Tu16)(unsafe.Pointer((*TSelect)(unsafe.Pointer(p)).FpOrderBy + 8 + 24)) = uint16(1)
				return _multiSelectByMerge(tls, pParse, p, pDest)
			} else {
				/* For a UNION ALL compound without ORDER BY, simply run the left
				 ** query, then run the right query */
				addr = 0
				**(**int32)(__ccgo_up(bp + 40)) = 0 /* Initialize to suppress harmless compiler warning */
				if (*TSelect)(unsafe.Pointer(pPrior)).FpPrior == uintptr(0) {
					_sqlite3VdbeExplain(tls, pParse, uint8(1), __ccgo_ts+20823, 0)
					_sqlite3VdbeExplain(tls, pParse, uint8(1), __ccgo_ts+20838, 0)
				}
				(*TSelect)(unsafe.Pointer(pPrior)).FiLimit = (*TSelect)(unsafe.Pointer(p)).FiLimit
				(*TSelect)(unsafe.Pointer(pPrior)).FiOffset = (*TSelect)(unsafe.Pointer(p)).FiOffset
				(*TSelect)(unsafe.Pointer(pPrior)).FpLimit = _sqlite3ExprDup(tls, db, (*TSelect)(unsafe.Pointer(p)).FpLimit, 0)
				rc = _sqlite3Select(tls, pParse, pPrior, bp)
				_sqlite3ExprDelete(tls, db, (*TSelect)(unsafe.Pointer(pPrior)).FpLimit)
				(*TSelect)(unsafe.Pointer(pPrior)).FpLimit = uintptr(0)
				if rc != 0 {
					goto multi_select_end
				}
				(*TSelect)(unsafe.Pointer(p)).FpPrior = uintptr(0)
				(*TSelect)(unsafe.Pointer(p)).FiLimit = (*TSelect)(unsafe.Pointer(pPrior)).FiLimit
				(*TSelect)(unsafe.Pointer(p)).FiOffset = (*TSelect)(unsafe.Pointer(pPrior)).FiOffset
				if (*TSelect)(unsafe.Pointer(p)).FiLimit != 0 {
					addr = _sqlite3VdbeAddOp1(tls, v, int32(OP_IfNot), (*TSelect)(unsafe.Pointer(p)).FiLimit)
					if (*TSelect)(unsafe.Pointer(p)).FiOffset != 0 {
						_sqlite3VdbeAddOp3(tls, v, int32(OP_OffsetLimit), (*TSelect)(unsafe.Pointer(p)).FiLimit, (*TSelect)(unsafe.Pointer(p)).FiOffset+int32(1), (*TSelect)(unsafe.Pointer(p)).FiOffset)
					}
				}
				_sqlite3VdbeExplain(tls, pParse, uint8(1), __ccgo_ts+20478, 0)
				rc = _sqlite3Select(tls, pParse, p, bp)
				pDelete = (*TSelect)(unsafe.Pointer(p)).FpPrior
				(*TSelect)(unsafe.Pointer(p)).FpPrior = pPrior
				(*TSelect)(unsafe.Pointer(p)).FnSelectRow = _sqlite3LogEstAdd(tls, (*TSelect)(unsafe.Pointer(p)).FnSelectRow, (*TSelect)(unsafe.Pointer(pPrior)).FnSelectRow)
				if (*TSelect)(unsafe.Pointer(p)).FpLimit != 0 && _sqlite3ExprIsInteger(tls, (*TExpr)(unsafe.Pointer((*TSelect)(unsafe.Pointer(p)).FpLimit)).FpLeft, bp+40, pParse) != 0 && **(**int32)(__ccgo_up(bp + 40)) > 0 && int32((*TSelect)(unsafe.Pointer(p)).FnSelectRow) > int32(_sqlite3LogEst(tls, libc.Uint64FromInt32(**(**int32)(__ccgo_up(bp + 40))))) {
					(*TSelect)(unsafe.Pointer(p)).FnSelectRow = _sqlite3LogEst(tls, libc.Uint64FromInt32(**(**int32)(__ccgo_up(bp + 40))))
				}
				if addr != 0 {
					_sqlite3VdbeJumpHere(tls, v, addr)
				}
				if (*TSelect)(unsafe.Pointer(p)).FpNext == uintptr(0) {
					_sqlite3VdbeExplainPop(tls, pParse)
				}
			}
		}
	}
	goto multi_select_end
multi_select_end:
	;
	(*TSelectDest)(unsafe.Pointer(pDest)).FiSdst = (**(**TSelectDest)(__ccgo_up(bp))).FiSdst
	(*TSelectDest)(unsafe.Pointer(pDest)).FnSdst = (**(**TSelectDest)(__ccgo_up(bp))).FnSdst
	(*TSelectDest)(unsafe.Pointer(pDest)).FiSDParm2 = (**(**TSelectDest)(__ccgo_up(bp))).FiSDParm2
	if pDelete != 0 {
		_sqlite3ParserAddCleanup(tls, pParse, __ccgo_fp(_sqlite3SelectDeleteGeneric), pDelete)
	}
	return rc
}

// C documentation
//
//	/*
//	** Generate code for a compound SELECT statement using a merge
//	** algorithm.  The compound must have an ORDER BY clause for this
//	** to work.
//	**
//	** We assume a query of the following form:
//	**
//	**      <selectA>  <operator>  <selectB>  ORDER BY <orderbylist>
//	**
//	** <operator> is one of UNION ALL, UNION, EXCEPT, or INTERSECT.  The idea
//	** is to code both <selectA> and <selectB> with the ORDER BY clause as
//	** co-routines.  Then run the co-routines in parallel and merge the results
//	** into the output.  In addition to the two coroutines (called selectA and
//	** selectB) there are 7 subroutines:
//	**
//	**    outA:    Move the output of the selectA coroutine into the output
//	**             of the compound query.
//	**
//	**    outB:    Move the output of the selectB coroutine into the output
//	**             of the compound query.  (Only generated for UNION and
//	**             UNION ALL.  EXCEPT and INTERSECT never output a row that
//	**             appears only in B.)
//	**
//	**    AltB:    Called when there is data from both coroutines and A<B.
//	**
//	**    AeqB:    Called when there is data from both coroutines and A==B.
//	**
//	**    AgtB:    Called when there is data from both coroutines and A>B.
//	**
//	**    EofA:    Called when data is exhausted from selectA.
//	**
//	**    EofB:    Called when data is exhausted from selectB.
//	**
//	** The implementation of the latter five subroutines depend on which
//	** <operator> is used:
//	**
//	**
//	**             UNION ALL         UNION            EXCEPT          INTERSECT
//	**          -------------  -----------------  --------------  -----------------
//	**   AltB:   outA, nextA      outA, nextA       outA, nextA         nextA
//	**
//	**   AeqB:   outA, nextA         nextA             nextA         outA, nextA
//	**
//	**   AgtB:   outB, nextB      outB, nextB          nextB            nextB
//	**
//	**   EofA:   outB, nextB      outB, nextB          halt             halt
//	**
//	**   EofB:   outA, nextA      outA, nextA       outA, nextA         halt
//	**
//	** In the AltB, AeqB, and AgtB subroutines, an EOF on A following nextA
//	** causes an immediate jump to EofA and an EOF on B following nextB causes
//	** an immediate jump to EofB.  Within EofA and EofB, and EOF on entry or
//	** following nextX causes a jump to the end of the select processing.
//	**
//	** Duplicate removal in the UNION, EXCEPT, and INTERSECT cases is handled
//	** within the output subroutine.  The regPrev register set holds the previously
//	** output value.  A comparison is made against this value and the output
//	** is skipped if the next results would be the same as the previous.
//	**
//	** The implementation plan is to implement the two coroutines and seven
//	** subroutines first, then put the control logic at the bottom.  Like this:
//	**
//	**          goto Init
//	**     coA: coroutine for left query (A)
//	**     coB: coroutine for right query (B)
//	**    outA: output one row of A
//	**    outB: output one row of B (UNION and UNION ALL only)
//	**    EofA: ...
//	**    EofB: ...
//	**    AltB: ...
//	**    AeqB: ...
//	**    AgtB: ...
//	**    Init: initialize coroutine registers
//	**          yield coA, on eof goto EofA
//	**          yield coB, on eof goto EofB
//	**    Cmpr: Compare A, B
//	**          Jump AltB, AeqB, AgtB
//	**     End: ...
//	**
//	** We call AltB, AeqB, AgtB, EofA, and EofB "subroutines" but they are not
//	** actually called using Gosub and they do not Return.  EofA and EofB loop
//	** until all data is exhausted then jump to the "end" label.  AltB, AeqB,
//	** and AgtB jump to either Cmpr or to one of EofA or EofB.
//	*/
func _multiSelectByMerge(tls *libc.TLS, pParse uintptr, p uintptr, pDest uintptr) (r int32) {
	bp := tls.Alloc(96)
	defer tls.Free(96)
	var aPermute, db, pItem, pItem1, pKeyDup, pKeyMerge, pNew, pOrderBy, pPrior, pSplit, v, v3 uintptr
	var addr1, addrAeqB, addrAgtB, addrAltB, addrEofA, addrEofA_noB, addrEofB, addrOutA, addrOutB, addrSelectA, addrSelectB, bKeep, i, j, labelCmpr, labelEnd, nExpr, nOrderBy, nSelect, op, regAddrA, regAddrB, regLimitA, regLimitB, regOutA, regOutB, regPrev, savedLimit, savedOffset, v4 int32
	var _ /* destA at bp+0 */ TSelectDest
	var _ /* destB at bp+40 */ TSelectDest
	_, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _ = aPermute, addr1, addrAeqB, addrAgtB, addrAltB, addrEofA, addrEofA_noB, addrEofB, addrOutA, addrOutB, addrSelectA, addrSelectB, bKeep, db, i, j, labelCmpr, labelEnd, nExpr, nOrderBy, nSelect, op, pItem, pItem1, pKeyDup, pKeyMerge, pNew, pOrderBy, pPrior, pSplit, regAddrA, regAddrB, regLimitA, regLimitB, regOutA, regOutB, regPrev, savedLimit, savedOffset, v, v3, v4 /* Address of the output-A subroutine */
	addrOutB = 0                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                 /* One of TK_ALL, TK_UNION, TK_EXCEPT, TK_INTERSECT */
	pKeyDup = uintptr(0)                                                                                                                                                                                                                                                                                                                                                                                                                                                                                         /* Mapping from ORDER BY terms to result set columns */
	/* "Managed" code needs this.  Ticket #3382. */
	db = (*TParse)(unsafe.Pointer(pParse)).Fdb
	v = (*TParse)(unsafe.Pointer(pParse)).FpVdbe
	/* Already thrown the error if VDBE alloc failed */
	labelEnd = _sqlite3VdbeMakeLabel(tls, pParse)
	labelCmpr = _sqlite3VdbeMakeLabel(tls, pParse)
	/* Patch up the ORDER BY clause
	 */
	op = libc.Int32FromUint8((*TSelect)(unsafe.Pointer(p)).Fop)
	pOrderBy = (*TSelect)(unsafe.Pointer(p)).FpOrderBy
	nOrderBy = (*TExprList)(unsafe.Pointer(pOrderBy)).FnExpr
	/* For operators other than UNION ALL we have to make sure that
	 ** the ORDER BY clause covers every term of the result set.  Add
	 ** terms to the ORDER BY clause as necessary.
	 */
	if op != int32(TK_ALL) {
		i = int32(1)
		for {
			if !(libc.Int32FromUint8((*Tsqlite3)(unsafe.Pointer(db)).FmallocFailed) == 0 && i <= (*TExprList)(unsafe.Pointer((*TSelect)(unsafe.Pointer(p)).FpEList)).FnExpr) {
				break
			}
			j = 0
			pItem = pOrderBy + 8
			for {
				if !(j < nOrderBy) {
					break
				}
				if libc.Int32FromUint16((*(*struct {
					FiOrderByCol Tu16
					FiAlias      Tu16
				})(unsafe.Pointer(pItem + 24))).FiOrderByCol) == i {
					break
				}
				goto _2
			_2:
				;
				j = j + 1
				pItem += 32
			}
			if j == nOrderBy {
				pNew = _sqlite3ExprInt32(tls, db, i)
				if pNew == uintptr(0) {
					return int32(SQLITE_NOMEM)
				}
				v3 = _sqlite3ExprListAppend(tls, pParse, pOrderBy, pNew)
				pOrderBy = v3
				(*TSelect)(unsafe.Pointer(p)).FpOrderBy = v3
				if pOrderBy != 0 {
					v4 = nOrderBy
					nOrderBy = nOrderBy + 1
					*(*Tu16)(unsafe.Pointer(pOrderBy + 8 + uintptr(v4)*32 + 24)) = libc.Uint16FromInt32(i)
				}
			}
			goto _1
		_1:
			;
			i = i + 1
		}
	}
	/* Compute the comparison permutation and keyinfo that is used with
	 ** the permutation to determine if the next row of results comes
	 ** from selectA or selectB.  Also add literal collations to the
	 ** ORDER BY clause terms so that when selectA and selectB are
	 ** evaluated, they use the correct collation.
	 */
	aPermute = _sqlite3DbMallocRawNN(tls, db, uint64(uint64(4)*libc.Uint64FromInt32(nOrderBy+libc.Int32FromInt32(1))))
	if aPermute != 0 {
		bKeep = 0
		**(**Tu32)(__ccgo_up(aPermute)) = libc.Uint32FromInt32(nOrderBy)
		i = int32(1)
		pItem1 = pOrderBy + 8
		for {
			if !(i <= nOrderBy) {
				break
			}
			**(**Tu32)(__ccgo_up(aPermute + uintptr(i)*4)) = libc.Uint32FromInt32(libc.Int32FromUint16((*(*struct {
				FiOrderByCol Tu16
				FiAlias      Tu16
			})(unsafe.Pointer(pItem1 + 24))).FiOrderByCol) - int32(1))
			if **(**Tu32)(__ccgo_up(aPermute + uintptr(i)*4)) != libc.Uint32FromInt32(i)-uint32(1) {
				bKeep = int32(1)
			}
			goto _5
		_5:
			;
			i = i + 1
			pItem1 += 32
		}
		if bKeep == 0 {
			_sqlite3DbFreeNN(tls, db, aPermute)
			aPermute = uintptr(0)
		}
	}
	pKeyMerge = _multiSelectByMergeKeyInfo(tls, pParse, p, int32(1))
	/* Allocate a range of temporary registers and the KeyInfo needed
	 ** for the logic that removes duplicate result rows when the
	 ** operator is UNION, EXCEPT, or INTERSECT (but not UNION ALL).
	 */
	if op == int32(TK_ALL) {
		regPrev = 0
	} else {
		nExpr = (*TExprList)(unsafe.Pointer((*TSelect)(unsafe.Pointer(p)).FpEList)).FnExpr
		regPrev = (*TParse)(unsafe.Pointer(pParse)).FnMem + int32(1)
		**(**int32)(__ccgo_up(pParse + 60)) += nExpr + int32(1)
		_sqlite3VdbeAddOp2(tls, v, int32(OP_Integer), 0, regPrev)
		pKeyDup = _sqlite3KeyInfoAlloc(tls, db, nExpr, int32(1))
		if pKeyDup != 0 {
			i = 0
			for {
				if !(i < nExpr) {
					break
				}
				*(*uintptr)(unsafe.Pointer(pKeyDup + 32 + uintptr(i)*8)) = _multiSelectCollSeq(tls, pParse, p, i)
				**(**Tu8)(__ccgo_up((*TKeyInfo)(unsafe.Pointer(pKeyDup)).FaSortFlags + uintptr(i))) = uint8(0)
				goto _6
			_6:
				;
				i = i + 1
			}
		}
	}
	/* Separate the left and the right query from one another
	 */
	nSelect = int32(1)
	if (op == int32(TK_ALL) || op == int32(TK_UNION)) && (*Tsqlite3)(unsafe.Pointer(db)).FdbOptFlags&libc.Uint32FromInt32(libc.Int32FromInt32(SQLITE_BalancedMerge)) == uint32(0) {
		pSplit = p
		for {
			if !((*TSelect)(unsafe.Pointer(pSplit)).FpPrior != uintptr(0) && libc.Int32FromUint8((*TSelect)(unsafe.Pointer(pSplit)).Fop) == op) {
				break
			}
			nSelect = nSelect + 1
			goto _7
		_7:
			;
			pSplit = (*TSelect)(unsafe.Pointer(pSplit)).FpPrior
		}
	}
	if nSelect <= int32(3) {
		pSplit = p
	} else {
		pSplit = p
		i = int32(2)
		for {
			if !(i < nSelect) {
				break
			}
			pSplit = (*TSelect)(unsafe.Pointer(pSplit)).FpPrior
			goto _8
		_8:
			;
			i = i + int32(2)
		}
	}
	pPrior = (*TSelect)(unsafe.Pointer(pSplit)).FpPrior
	(*TSelect)(unsafe.Pointer(pSplit)).FpPrior = uintptr(0)
	(*TSelect)(unsafe.Pointer(pPrior)).FpNext = uintptr(0)
	(*TSelect)(unsafe.Pointer(pPrior)).FpOrderBy = _sqlite3ExprListDup(tls, (*TParse)(unsafe.Pointer(pParse)).Fdb, pOrderBy, 0)
	_sqlite3ResolveOrderGroupBy(tls, pParse, p, (*TSelect)(unsafe.Pointer(p)).FpOrderBy, __ccgo_ts+7652)
	_sqlite3ResolveOrderGroupBy(tls, pParse, pPrior, (*TSelect)(unsafe.Pointer(pPrior)).FpOrderBy, __ccgo_ts+7652)
	/* Compute the limit registers */
	_computeLimitRegisters(tls, pParse, p, labelEnd)
	if (*TSelect)(unsafe.Pointer(p)).FiLimit != 0 && op == int32(TK_ALL) {
		v3 = pParse + 60
		*(*int32)(unsafe.Pointer(v3)) = *(*int32)(unsafe.Pointer(v3)) + 1
		v4 = *(*int32)(unsafe.Pointer(v3))
		regLimitA = v4
		v3 = pParse + 60
		*(*int32)(unsafe.Pointer(v3)) = *(*int32)(unsafe.Pointer(v3)) + 1
		v4 = *(*int32)(unsafe.Pointer(v3))
		regLimitB = v4
		if (*TSelect)(unsafe.Pointer(p)).FiOffset != 0 {
			v4 = (*TSelect)(unsafe.Pointer(p)).FiOffset + int32(1)
		} else {
			v4 = (*TSelect)(unsafe.Pointer(p)).FiLimit
		}
		_sqlite3VdbeAddOp2(tls, v, int32(OP_Copy), v4, regLimitA)
		_sqlite3VdbeAddOp2(tls, v, int32(OP_Copy), regLimitA, regLimitB)
	} else {
		v4 = libc.Int32FromInt32(0)
		regLimitB = v4
		regLimitA = v4
	}
	_sqlite3ExprDelete(tls, db, (*TSelect)(unsafe.Pointer(p)).FpLimit)
	(*TSelect)(unsafe.Pointer(p)).FpLimit = uintptr(0)
	v3 = pParse + 60
	*(*int32)(unsafe.Pointer(v3)) = *(*int32)(unsafe.Pointer(v3)) + 1
	v4 = *(*int32)(unsafe.Pointer(v3))
	regAddrA = v4
	v3 = pParse + 60
	*(*int32)(unsafe.Pointer(v3)) = *(*int32)(unsafe.Pointer(v3)) + 1
	v4 = *(*int32)(unsafe.Pointer(v3))
	regAddrB = v4
	v3 = pParse + 60
	*(*int32)(unsafe.Pointer(v3)) = *(*int32)(unsafe.Pointer(v3)) + 1
	v4 = *(*int32)(unsafe.Pointer(v3))
	regOutA = v4
	v3 = pParse + 60
	*(*int32)(unsafe.Pointer(v3)) = *(*int32)(unsafe.Pointer(v3)) + 1
	v4 = *(*int32)(unsafe.Pointer(v3))
	regOutB = v4
	_sqlite3SelectDestInit(tls, bp, int32(SRT_Coroutine), regAddrA)
	_sqlite3SelectDestInit(tls, bp+40, int32(SRT_Coroutine), regAddrB)
	_sqlite3VdbeExplain(tls, pParse, uint8(1), __ccgo_ts+20985, libc.VaList(bp+88, _sqlite3SelectOpName(tls, libc.Int32FromUint8((*TSelect)(unsafe.Pointer(p)).Fop))))
	/* Generate a coroutine to evaluate the SELECT statement to the
	 ** left of the compound operator - the "A" select.
	 */
	addrSelectA = _sqlite3VdbeCurrentAddr(tls, v) + int32(1)
	addr1 = _sqlite3VdbeAddOp3(tls, v, int32(OP_InitCoroutine), regAddrA, 0, addrSelectA)
	(*TSelect)(unsafe.Pointer(pPrior)).FiLimit = regLimitA
	_sqlite3VdbeExplain(tls, pParse, uint8(1), __ccgo_ts+20996, 0)
	_sqlite3Select(tls, pParse, pPrior, bp)
	_sqlite3VdbeEndCoroutine(tls, v, regAddrA)
	_sqlite3VdbeJumpHere(tls, v, addr1)
	/* Generate a coroutine to evaluate the SELECT statement on
	 ** the right - the "B" select
	 */
	addrSelectB = _sqlite3VdbeCurrentAddr(tls, v) + int32(1)
	addr1 = _sqlite3VdbeAddOp3(tls, v, int32(OP_InitCoroutine), regAddrB, 0, addrSelectB)
	savedLimit = (*TSelect)(unsafe.Pointer(p)).FiLimit
	savedOffset = (*TSelect)(unsafe.Pointer(p)).FiOffset
	(*TSelect)(unsafe.Pointer(p)).FiLimit = regLimitB
	(*TSelect)(unsafe.Pointer(p)).FiOffset = 0
	_sqlite3VdbeExplain(tls, pParse, uint8(1), __ccgo_ts+21001, 0)
	_sqlite3Select(tls, pParse, p, bp+40)
	(*TSelect)(unsafe.Pointer(p)).FiLimit = savedLimit
	(*TSelect)(unsafe.Pointer(p)).FiOffset = savedOffset
	_sqlite3VdbeEndCoroutine(tls, v, regAddrB)
	/* Generate a subroutine that outputs the current row of the A
	 ** select as the next output row of the compound select.
	 */
	addrOutA = _generateOutputSubroutine(tls, pParse, p, bp, pDest, regOutA, regPrev, pKeyDup, labelEnd)
	/* Generate a subroutine that outputs the current row of the B
	 ** select as the next output row of the compound select.
	 */
	if op == int32(TK_ALL) || op == int32(TK_UNION) {
		addrOutB = _generateOutputSubroutine(tls, pParse, p, bp+40, pDest, regOutB, regPrev, pKeyDup, labelEnd)
	}
	_sqlite3KeyInfoUnref(tls, pKeyDup)
	/* Generate a subroutine to run when the results from select A
	 ** are exhausted and only data in select B remains.
	 */
	if op == int32(TK_EXCEPT) || op == int32(TK_INTERSECT) {
		v4 = labelEnd
		addrEofA = v4
		addrEofA_noB = v4
	} else {
		addrEofA = _sqlite3VdbeAddOp2(tls, v, int32(OP_Gosub), regOutB, addrOutB)
		addrEofA_noB = _sqlite3VdbeAddOp2(tls, v, int32(OP_Yield), regAddrB, labelEnd)
		_sqlite3VdbeGoto(tls, v, addrEofA)
		(*TSelect)(unsafe.Pointer(p)).FnSelectRow = _sqlite3LogEstAdd(tls, (*TSelect)(unsafe.Pointer(p)).FnSelectRow, (*TSelect)(unsafe.Pointer(pPrior)).FnSelectRow)
	}
	/* Generate a subroutine to run when the results from select B
	 ** are exhausted and only data in select A remains.
	 */
	if op == int32(TK_INTERSECT) {
		addrEofB = addrEofA
		if int32((*TSelect)(unsafe.Pointer(p)).FnSelectRow) > int32((*TSelect)(unsafe.Pointer(pPrior)).FnSelectRow) {
			(*TSelect)(unsafe.Pointer(p)).FnSelectRow = (*TSelect)(unsafe.Pointer(pPrior)).FnSelectRow
		}
	} else {
		addrEofB = _sqlite3VdbeAddOp2(tls, v, int32(OP_Gosub), regOutA, addrOutA)
		_sqlite3VdbeAddOp2(tls, v, int32(OP_Yield), regAddrA, labelEnd)
		_sqlite3VdbeGoto(tls, v, addrEofB)
	}
	/* Generate code to handle the case of A<B
	 */
	addrAltB = _sqlite3VdbeAddOp2(tls, v, int32(OP_Gosub), regOutA, addrOutA)
	_sqlite3VdbeAddOp2(tls, v, int32(OP_Yield), regAddrA, addrEofA)
	_sqlite3VdbeGoto(tls, v, labelCmpr)
	/* Generate code to handle the case of A==B
	 */
	if op == int32(TK_ALL) {
		addrAeqB = addrAltB
	} else {
		if op == int32(TK_INTERSECT) {
			addrAeqB = addrAltB
			addrAltB = addrAltB + 1
		} else {
			addrAeqB = addrAltB + int32(1)
		}
	}
	/* Generate code to handle the case of A>B
	 */
	addrAgtB = _sqlite3VdbeCurrentAddr(tls, v)
	if op == int32(TK_ALL) || op == int32(TK_UNION) {
		_sqlite3VdbeAddOp2(tls, v, int32(OP_Gosub), regOutB, addrOutB)
		_sqlite3VdbeAddOp2(tls, v, int32(OP_Yield), regAddrB, addrEofB)
		_sqlite3VdbeGoto(tls, v, labelCmpr)
	} else {
		addrAgtB = addrAgtB + 1 /* Just do next-B.  Might as well use the next-B call
		 ** in the next code block */
	}
	/* This code runs once to initialize everything.
	 */
	_sqlite3VdbeJumpHere(tls, v, addr1)
	_sqlite3VdbeAddOp2(tls, v, int32(OP_Yield), regAddrA, addrEofA_noB)
	/* v---  Also the A>B case for EXCEPT and INTERSECT */
	_sqlite3VdbeAddOp2(tls, v, int32(OP_Yield), regAddrB, addrEofB)
	/* Implement the main merge loop
	 */
	if aPermute != uintptr(0) {
		_sqlite3VdbeAddOp4(tls, v, int32(OP_Permutation), 0, 0, 0, aPermute, -int32(15))
	}
	_sqlite3VdbeResolveLabel(tls, v, labelCmpr)
	_sqlite3VdbeAddOp4(tls, v, int32(OP_Compare), (**(**TSelectDest)(__ccgo_up(bp))).FiSdst, (**(**TSelectDest)(__ccgo_up(bp + 40))).FiSdst, nOrderBy, pKeyMerge, -int32(9))
	if aPermute != uintptr(0) {
		_sqlite3VdbeChangeP5(tls, v, uint16(OPFLAG_PERMUTE))
	}
	_sqlite3VdbeAddOp3(tls, v, int32(OP_Jump), addrAltB, addrAeqB, addrAgtB)
	/* Jump to the this point in order to terminate the query.
	 */
	_sqlite3VdbeResolveLabel(tls, v, labelEnd)
	/* Make arrangements to free the 2nd and subsequent arms of the compound
	 ** after the parse has finished */
	if (*TSelect)(unsafe.Pointer(pSplit)).FpPrior != 0 {
		_sqlite3ParserAddCleanup(tls, pParse, __ccgo_fp(_sqlite3SelectDeleteGeneric), (*TSelect)(unsafe.Pointer(pSplit)).FpPrior)
	}
	(*TSelect)(unsafe.Pointer(pSplit)).FpPrior = pPrior
	(*TSelect)(unsafe.Pointer(pPrior)).FpNext = pSplit
	_sqlite3ExprListDelete(tls, db, (*TSelect)(unsafe.Pointer(pPrior)).FpOrderBy)
	(*TSelect)(unsafe.Pointer(pPrior)).FpOrderBy = uintptr(0)
	/*** TBD:  Insert subroutine calls to close cursors on incomplete
	 **** subqueries ****/
	_sqlite3VdbeExplainPop(tls, pParse)
	return libc.BoolInt32((*TParse)(unsafe.Pointer(pParse)).FnErr != 0)
}

// C documentation
//
//	/*
//	** Handle the special case of a compound-select that originates from a
//	** VALUES clause.  By handling this as a special case, we avoid deep
//	** recursion, and thus do not need to enforce the SQLITE_LIMIT_COMPOUND_SELECT
//	** on a VALUES clause.
//	**
//	** Because the Select object originates from a VALUES clause:
//	**   (1) There is no LIMIT or OFFSET or else there is a LIMIT of exactly 1
//	**   (2) All terms are UNION ALL
//	**   (3) There is no ORDER BY clause
//	**
//	** The "LIMIT of exactly 1" case of condition (1) comes about when a VALUES
//	** clause occurs within scalar expression (ex: "SELECT (VALUES(1),(2),(3))").
//	** The sqlite3CodeSubselect will have added the LIMIT 1 clause in tht case.
//	** Since the limit is exactly 1, we only need to evaluate the left-most VALUES.
//	*/
func _multiSelectValues(tls *libc.TLS, pParse uintptr, p uintptr, pDest uintptr) (r int32) {
	bp := tls.Alloc(32)
	defer tls.Free(32)
	var bShowAll, nRow, rc int32
	var v1 uintptr
	_, _, _, _ = bShowAll, nRow, rc, v1
	nRow = int32(1)
	rc = 0
	bShowAll = libc.BoolInt32((*TSelect)(unsafe.Pointer(p)).FpLimit == uintptr(0))
	for cond := true; cond; cond = int32(1) != 0 {
		if (*TSelect)(unsafe.Pointer(p)).FpWin != 0 {
			return -int32(1)
		}
		if (*TSelect)(unsafe.Pointer(p)).FpPrior == uintptr(0) {
			break
		}
		p = (*TSelect)(unsafe.Pointer(p)).FpPrior
		nRow = nRow + bShowAll
	}
	if nRow == int32(1) {
		v1 = __ccgo_ts + 1693
	} else {
		v1 = __ccgo_ts + 20798
	}
	_sqlite3VdbeExplain(tls, pParse, uint8(0), __ccgo_ts+20800, libc.VaList(bp+8, nRow, v1))
	for p != 0 {
		_selectInnerLoop(tls, pParse, p, -int32(1), uintptr(0), uintptr(0), pDest, int32(1), int32(1))
		if !(bShowAll != 0) {
			break
		}
		(*TSelect)(unsafe.Pointer(p)).FnSelectRow = int16(nRow)
		p = (*TSelect)(unsafe.Pointer(p)).FpNext
	}
	return rc
}

// C documentation
//
//	/*
//	** Obtain a reference to an r-tree node.
//	*/
func _nodeAcquire(tls *libc.TLS, pRtree uintptr, iNode Ti64, pParent uintptr, ppNode uintptr) (r int32) {
	var pBlob, pNode, v1 uintptr
	var rc int32
	_, _, _, _ = pBlob, pNode, rc, v1
	rc = SQLITE_OK
	pNode = uintptr(0)
	/* Check if the requested node is already in the hash table. If so,
	 ** increase its reference count and return it.
	 */
	v1 = _nodeHashLookup(tls, pRtree, iNode)
	pNode = v1
	if v1 != uintptr(0) {
		if pParent != 0 && pParent != (*TRtreeNode)(unsafe.Pointer(pNode)).FpParent {
			return libc.Int32FromInt32(SQLITE_CORRUPT) | libc.Int32FromInt32(1)<<libc.Int32FromInt32(8)
		}
		(*TRtreeNode)(unsafe.Pointer(pNode)).FnRef = (*TRtreeNode)(unsafe.Pointer(pNode)).FnRef + 1
		**(**uintptr)(__ccgo_up(ppNode)) = pNode
		return SQLITE_OK
	}
	if (*TRtree)(unsafe.Pointer(pRtree)).FpNodeBlob != 0 {
		pBlob = (*TRtree)(unsafe.Pointer(pRtree)).FpNodeBlob
		(*TRtree)(unsafe.Pointer(pRtree)).FpNodeBlob = uintptr(0)
		rc = Xsqlite3_blob_reopen(tls, pBlob, iNode)
		(*TRtree)(unsafe.Pointer(pRtree)).FpNodeBlob = pBlob
		if rc != 0 {
			_nodeBlobReset(tls, pRtree)
			if rc == int32(SQLITE_NOMEM) {
				return int32(SQLITE_NOMEM)
			}
		}
	}
	if (*TRtree)(unsafe.Pointer(pRtree)).FpNodeBlob == uintptr(0) {
		rc = Xsqlite3_blob_open(tls, (*TRtree)(unsafe.Pointer(pRtree)).Fdb, (*TRtree)(unsafe.Pointer(pRtree)).FzDb, (*TRtree)(unsafe.Pointer(pRtree)).FzNodeName, __ccgo_ts+27397, iNode, 0, pRtree+120)
	}
	if rc != 0 {
		**(**uintptr)(__ccgo_up(ppNode)) = uintptr(0)
		/* If unable to open an sqlite3_blob on the desired row, that can only
		 ** be because the shadow tables hold erroneous data. */
		if rc == int32(SQLITE_ERROR) {
			rc = libc.Int32FromInt32(SQLITE_CORRUPT) | libc.Int32FromInt32(1)<<libc.Int32FromInt32(8)
		}
	} else {
		if iNode <= 0 {
			rc = libc.Int32FromInt32(SQLITE_CORRUPT) | libc.Int32FromInt32(1)<<libc.Int32FromInt32(8)
		} else {
			if (*TRtree)(unsafe.Pointer(pRtree)).FiNodeSize == Xsqlite3_blob_bytes(tls, (*TRtree)(unsafe.Pointer(pRtree)).FpNodeBlob) {
				pNode = Xsqlite3_malloc64(tls, uint64(uint64(40)+libc.Uint64FromInt32((*TRtree)(unsafe.Pointer(pRtree)).FiNodeSize)))
				if !(pNode != 0) {
					rc = int32(SQLITE_NOMEM)
				} else {
					(*TRtreeNode)(unsafe.Pointer(pNode)).FpParent = pParent
					(*TRtreeNode)(unsafe.Pointer(pNode)).FzData = pNode + 1*40
					(*TRtreeNode)(unsafe.Pointer(pNode)).FnRef = int32(1)
					(*TRtree)(unsafe.Pointer(pRtree)).FnNodeRef = (*TRtree)(unsafe.Pointer(pRtree)).FnNodeRef + 1
					(*TRtreeNode)(unsafe.Pointer(pNode)).FiNode = iNode
					(*TRtreeNode)(unsafe.Pointer(pNode)).FisDirty = 0
					(*TRtreeNode)(unsafe.Pointer(pNode)).FpNext = uintptr(0)
					rc = Xsqlite3_blob_read(tls, (*TRtree)(unsafe.Pointer(pRtree)).FpNodeBlob, (*TRtreeNode)(unsafe.Pointer(pNode)).FzData, (*TRtree)(unsafe.Pointer(pRtree)).FiNodeSize, 0)
				}
			}
		}
	}
	/* If the root node was just loaded, set pRtree->iDepth to the height
	 ** of the r-tree structure. A height of zero means all data is stored on
	 ** the root node. A height of one means the children of the root node
	 ** are the leaves, and so on. If the depth as specified on the root node
	 ** is greater than RTREE_MAX_DEPTH, the r-tree structure must be corrupt.
	 */
	if rc == SQLITE_OK && pNode != 0 && iNode == int64(1) {
		(*TRtree)(unsafe.Pointer(pRtree)).FiDepth = _readInt16(tls, (*TRtreeNode)(unsafe.Pointer(pNode)).FzData)
		if (*TRtree)(unsafe.Pointer(pRtree)).FiDepth >= int32(RTREE_MAX_DEPTH) {
			rc = libc.Int32FromInt32(SQLITE_CORRUPT) | libc.Int32FromInt32(1)<<libc.Int32FromInt32(8)
		}
	}
	/* If no error has occurred so far, check if the "number of entries"
	 ** field on the node is too large. If so, set the return code to
	 ** SQLITE_CORRUPT_VTAB.
	 */
	if pNode != 0 && rc == SQLITE_OK {
		if _readInt16(tls, (*TRtreeNode)(unsafe.Pointer(pNode)).FzData+2) > ((*TRtree)(unsafe.Pointer(pRtree)).FiNodeSize-int32(4))/libc.Int32FromUint8((*TRtree)(unsafe.Pointer(pRtree)).FnBytesPerCell) {
			rc = libc.Int32FromInt32(SQLITE_CORRUPT) | libc.Int32FromInt32(1)<<libc.Int32FromInt32(8)
		}
	}
	if rc == SQLITE_OK {
		if pNode != uintptr(0) {
			_nodeReference(tls, pParent)
			_nodeHashInsert(tls, pRtree, pNode)
		} else {
			rc = libc.Int32FromInt32(SQLITE_CORRUPT) | libc.Int32FromInt32(1)<<libc.Int32FromInt32(8)
		}
		**(**uintptr)(__ccgo_up(ppNode)) = pNode
	} else {
		_nodeBlobReset(tls, pRtree)
		if pNode != 0 {
			(*TRtree)(unsafe.Pointer(pRtree)).FnNodeRef = (*TRtree)(unsafe.Pointer(pRtree)).FnNodeRef - 1
			Xsqlite3_free(tls, pNode)
		}
		**(**uintptr)(__ccgo_up(ppNode)) = uintptr(0)
	}
	return rc
}

// C documentation
//
//	/*
//	** Report an error that an expression is not valid for some set of
//	** pNC->ncFlags values determined by validMask.
//	**
//	** static void notValid(
//	**   Parse *pParse,       // Leave error message here
//	**   NameContext *pNC,    // The name context
//	**   const char *zMsg,    // Type of error
//	**   int validMask,       // Set of contexts for which prohibited
//	**   Expr *pExpr          // Invalidate this expression on error
//	** ){...}
//	**
//	** As an optimization, since the conditional is almost always false
//	** (because errors are rare), the conditional is moved outside of the
//	** function call using a macro.
//	*/
func _notValidImpl(tls *libc.TLS, pParse uintptr, pNC uintptr, zMsg uintptr, pExpr uintptr, pError uintptr) {
	bp := tls.Alloc(32)
	defer tls.Free(32)
	var zIn uintptr
	_ = zIn
	zIn = __ccgo_ts + 7091
	if (*TNameContext)(unsafe.Pointer(pNC)).FncFlags&int32(NC_IdxExpr) != 0 {
		zIn = __ccgo_ts + 7119
	} else {
		if (*TNameContext)(unsafe.Pointer(pNC)).FncFlags&int32(NC_IsCheck) != 0 {
			zIn = __ccgo_ts + 7137
		} else {
			if (*TNameContext)(unsafe.Pointer(pNC)).FncFlags&int32(NC_GenCol) != 0 {
				zIn = __ccgo_ts + 7155
			}
		}
	}
	_sqlite3ErrorMsg(tls, pParse, __ccgo_ts+7173, libc.VaList(bp+8, zMsg, zIn))
	if pExpr != 0 {
		(*TExpr)(unsafe.Pointer(pExpr)).Fop = uint8(TK_NULL)
	}
	_sqlite3RecordErrorOffsetOfExpr(tls, (*TParse)(unsafe.Pointer(pParse)).Fdb, pError)
}

func _nth_valueStepFunc(tls *libc.TLS, pCtx uintptr, nArg int32, apArg uintptr) {
	var fVal float64
	var iVal Ti64
	var p uintptr
	_, _, _ = fVal, iVal, p
	p = Xsqlite3_aggregate_context(tls, pCtx, int32(16))
	if p != 0 {
		switch Xsqlite3_value_numeric_type(tls, **(**uintptr)(__ccgo_up(apArg + 1*8))) {
		case int32(SQLITE_INTEGER):
			iVal = Xsqlite3_value_int64(tls, **(**uintptr)(__ccgo_up(apArg + 1*8)))
		case int32(SQLITE_FLOAT):
			fVal = Xsqlite3_value_double(tls, **(**uintptr)(__ccgo_up(apArg + 1*8)))
			if float64(int64(fVal)) != fVal {
				goto error_out
			}
			iVal = int64(fVal)
		default:
			goto error_out
		}
		if iVal <= 0 {
			goto error_out
		}
		(*TNthValueCtx)(unsafe.Pointer(p)).FnStep = (*TNthValueCtx)(unsafe.Pointer(p)).FnStep + 1
		if iVal == (*TNthValueCtx)(unsafe.Pointer(p)).FnStep {
			(*TNthValueCtx)(unsafe.Pointer(p)).FpValue = Xsqlite3_value_dup(tls, **(**uintptr)(__ccgo_up(apArg)))
			if !((*TNthValueCtx)(unsafe.Pointer(p)).FpValue != 0) {
				Xsqlite3_result_error_nomem(tls, pCtx)
			}
		}
	}
	_ = nArg
	_ = apArg
	return
	goto error_out
error_out:
	;
	Xsqlite3_result_error(tls, pCtx, __ccgo_ts+24168, -int32(1))
}

// C documentation
//
//	/*
//	** Implementation of ntile(). This assumes that the window frame has
//	** been coerced to:
//	**
//	**   ROWS CURRENT ROW AND UNBOUNDED FOLLOWING
//	*/
func _ntileStepFunc(tls *libc.TLS, pCtx uintptr, nArg int32, apArg uintptr) {
	var p uintptr
	_ = p
	_ = nArg
	p = Xsqlite3_aggregate_context(tls, pCtx, int32(24))
	if p != 0 {
		if (*TNtileCtx)(unsafe.Pointer(p)).FnTotal == 0 {
			(*TNtileCtx)(unsafe.Pointer(p)).FnParam = Xsqlite3_value_int64(tls, **(**uintptr)(__ccgo_up(apArg)))
			if (*TNtileCtx)(unsafe.Pointer(p)).FnParam <= 0 {
				Xsqlite3_result_error(tls, pCtx, __ccgo_ts+24224, -int32(1))
			}
		}
		(*TNtileCtx)(unsafe.Pointer(p)).FnTotal = (*TNtileCtx)(unsafe.Pointer(p)).FnTotal + 1
	}
}

// C documentation
//
//	/*
//	** This routine does the work of opening a database on behalf of
//	** sqlite3_open() and sqlite3_open16(). The database filename "zFilename"
//	** is UTF-8 encoded.
//	*/
func _openDatabase(tls *libc.TLS, zFilename uintptr, ppDb uintptr, _flags uint32, zVfs uintptr) (r int32) {
	bp := tls.Alloc(48)
	defer tls.Free(48)
	*(*uint32)(unsafe.Pointer(bp)) = _flags
	var db, v2 uintptr
	var i, isThreadsafe, rc int32
	var v1 uint32
	var _ /* zErrMsg at bp+16 */ uintptr
	var _ /* zOpen at bp+8 */ uintptr
	_, _, _, _, _, _ = db, i, isThreadsafe, rc, v1, v2 /* True for threadsafe connections */
	**(**uintptr)(__ccgo_up(bp + 8)) = uintptr(0)      /* Filename argument to pass to BtreeOpen() */
	**(**uintptr)(__ccgo_up(bp + 16)) = uintptr(0)     /* Loop counter */
	**(**uintptr)(__ccgo_up(ppDb)) = uintptr(0)
	rc = Xsqlite3_initialize(tls)
	if rc != 0 {
		return rc
	}
	if libc.Int32FromUint8(_sqlite3Config.FbCoreMutex) == 0 {
		isThreadsafe = 0
	} else {
		if **(**uint32)(__ccgo_up(bp))&uint32(SQLITE_OPEN_NOMUTEX) != 0 {
			isThreadsafe = 0
		} else {
			if **(**uint32)(__ccgo_up(bp))&uint32(SQLITE_OPEN_FULLMUTEX) != 0 {
				isThreadsafe = int32(1)
			} else {
				isThreadsafe = libc.Int32FromUint8(_sqlite3Config.FbFullMutex)
			}
		}
	}
	if **(**uint32)(__ccgo_up(bp))&uint32(SQLITE_OPEN_PRIVATECACHE) != 0 {
		**(**uint32)(__ccgo_up(bp)) = **(**uint32)(__ccgo_up(bp)) & libc.Uint32FromInt32(^libc.Int32FromInt32(SQLITE_OPEN_SHAREDCACHE))
	} else {
		if _sqlite3Config.FsharedCacheEnabled != 0 {
			**(**uint32)(__ccgo_up(bp)) = **(**uint32)(__ccgo_up(bp)) | uint32(SQLITE_OPEN_SHAREDCACHE)
		}
	}
	/* Remove harmful bits from the flags parameter
	 **
	 ** The SQLITE_OPEN_NOMUTEX and SQLITE_OPEN_FULLMUTEX flags were
	 ** dealt with in the previous code block.  Besides these, the only
	 ** valid input flags for sqlite3_open_v2() are SQLITE_OPEN_READONLY,
	 ** SQLITE_OPEN_READWRITE, SQLITE_OPEN_CREATE, SQLITE_OPEN_SHAREDCACHE,
	 ** SQLITE_OPEN_PRIVATECACHE, SQLITE_OPEN_EXRESCODE, and some reserved
	 ** bits.  Silently mask off all other flags.
	 */
	**(**uint32)(__ccgo_up(bp)) = **(**uint32)(__ccgo_up(bp)) & libc.Uint32FromInt32(^(libc.Int32FromInt32(SQLITE_OPEN_DELETEONCLOSE) | libc.Int32FromInt32(SQLITE_OPEN_EXCLUSIVE) | libc.Int32FromInt32(SQLITE_OPEN_MAIN_DB) | libc.Int32FromInt32(SQLITE_OPEN_TEMP_DB) | libc.Int32FromInt32(SQLITE_OPEN_TRANSIENT_DB) | libc.Int32FromInt32(SQLITE_OPEN_MAIN_JOURNAL) | libc.Int32FromInt32(SQLITE_OPEN_TEMP_JOURNAL) | libc.Int32FromInt32(SQLITE_OPEN_SUBJOURNAL) | libc.Int32FromInt32(SQLITE_OPEN_SUPER_JOURNAL) | libc.Int32FromInt32(SQLITE_OPEN_NOMUTEX) | libc.Int32FromInt32(SQLITE_OPEN_FULLMUTEX) | libc.Int32FromInt32(SQLITE_OPEN_WAL)))
	/* Allocate the sqlite data structure */
	db = _sqlite3MallocZero(tls, uint64(864))
	if db == uintptr(0) {
		goto opendb_out
	}
	if isThreadsafe != 0 {
		(*Tsqlite3)(unsafe.Pointer(db)).Fmutex = _sqlite3MutexAlloc(tls, int32(SQLITE_MUTEX_RECURSIVE))
		if (*Tsqlite3)(unsafe.Pointer(db)).Fmutex == uintptr(0) {
			Xsqlite3_free(tls, db)
			db = uintptr(0)
			goto opendb_out
		}
		if isThreadsafe == 0 {
		}
	}
	Xsqlite3_mutex_enter(tls, (*Tsqlite3)(unsafe.Pointer(db)).Fmutex)
	if **(**uint32)(__ccgo_up(bp))&uint32(SQLITE_OPEN_EXRESCODE) != uint32(0) {
		v1 = uint32(0xffffffff)
	} else {
		v1 = uint32(0xff)
	}
	(*Tsqlite3)(unsafe.Pointer(db)).FerrMask = libc.Int32FromUint32(v1)
	(*Tsqlite3)(unsafe.Pointer(db)).FnDb = int32(2)
	(*Tsqlite3)(unsafe.Pointer(db)).FeOpenState = uint8(SQLITE_STATE_BUSY)
	(*Tsqlite3)(unsafe.Pointer(db)).FaDb = db + 696
	(*Tsqlite3)(unsafe.Pointer(db)).Flookaside.FbDisable = uint32(1)
	(*Tsqlite3)(unsafe.Pointer(db)).Flookaside.Fsz = uint16(0)
	(*Tsqlite3)(unsafe.Pointer(db)).FnFpDigit = uint8(17)
	libc.Xmemcpy(tls, db+136, uintptr(unsafe.Pointer(&_aHardLimit)), uint64(52))
	**(**int32)(__ccgo_up(db + 136 + 11*4)) = SQLITE_DEFAULT_WORKER_THREADS
	(*Tsqlite3)(unsafe.Pointer(db)).FautoCommit = uint8(1)
	(*Tsqlite3)(unsafe.Pointer(db)).FnextAutovac = int8(-int32(1))
	(*Tsqlite3)(unsafe.Pointer(db)).FszMmap = _sqlite3Config.FszMmap
	(*Tsqlite3)(unsafe.Pointer(db)).FnextPagesize = 0
	(*Tsqlite3)(unsafe.Pointer(db)).Finit1.FazInit = uintptr(unsafe.Pointer(&_sqlite3StdType)) /* Any array of string ptrs will do */
	**(**Tu64)(__ccgo_up(db + 48)) |= uint64(libc.Uint32FromInt32(libc.Int32FromInt32(SQLITE_ShortColNames)|libc.Int32FromInt32(SQLITE_EnableTrigger))|libc.Uint32FromUint32(SQLITE_EnableView)|libc.Uint32FromInt32(SQLITE_CacheSpill)) | libc.Uint64FromInt32(libc.Int32FromInt32(0x00010))<<libc.Int32FromInt32(32) | libc.Uint64FromInt32(libc.Int32FromInt32(0x00020))<<libc.Int32FromInt32(32) | libc.Uint64FromInt32(libc.Int32FromInt32(0x00040))<<libc.Int32FromInt32(32) | libc.Uint64FromInt32(SQLITE_TrustedSchema) | libc.Uint64FromInt32(SQLITE_DqsDML) | libc.Uint64FromInt32(SQLITE_DqsDDL) | libc.Uint64FromInt32(SQLITE_AutoIndex)
	_sqlite3HashInit(tls, db+648)
	_sqlite3HashInit(tls, db+576)
	/* Add the default collation sequence BINARY. BINARY works for both UTF-8
	 ** and UTF-16, so add a version for each to avoid any unnecessary
	 ** conversions. The only error that can occur here is a malloc() failure.
	 **
	 ** EVIDENCE-OF: R-52786-44878 SQLite defines three built-in collating
	 ** functions:
	 */
	_createCollation(tls, db, uintptr(unsafe.Pointer(&_sqlite3StrBINARY)), uint8(SQLITE_UTF8), uintptr(0), __ccgo_fp(_binCollFunc), uintptr(0))
	_createCollation(tls, db, uintptr(unsafe.Pointer(&_sqlite3StrBINARY)), uint8(SQLITE_UTF16BE), uintptr(0), __ccgo_fp(_binCollFunc), uintptr(0))
	_createCollation(tls, db, uintptr(unsafe.Pointer(&_sqlite3StrBINARY)), uint8(SQLITE_UTF16LE), uintptr(0), __ccgo_fp(_binCollFunc), uintptr(0))
	_createCollation(tls, db, __ccgo_ts+23934, uint8(SQLITE_UTF8), uintptr(0), __ccgo_fp(_nocaseCollatingFunc), uintptr(0))
	_createCollation(tls, db, __ccgo_ts+26251, uint8(SQLITE_UTF8), uintptr(0), __ccgo_fp(_rtrimCollFunc), uintptr(0))
	if (*Tsqlite3)(unsafe.Pointer(db)).FmallocFailed != 0 {
		goto opendb_out
	}
	/* Parse the filename/URI argument
	 **
	 ** Only allow sensible combinations of bits in the flags argument.
	 ** Throw an error if any non-sense combination is used.  If we
	 ** do not block illegal combinations here, it could trigger
	 ** assert() statements in deeper layers.  Sensible combinations
	 ** are:
	 **
	 **  1:  SQLITE_OPEN_READONLY
	 **  2:  SQLITE_OPEN_READWRITE
	 **  6:  SQLITE_OPEN_READWRITE | SQLITE_OPEN_CREATE
	 */
	(*Tsqlite3)(unsafe.Pointer(db)).FopenFlags = **(**uint32)(__ccgo_up(bp))
	/* READONLY */
	/* READWRITE */
	/* READWRITE | CREATE */
	if int32(1)<<(**(**uint32)(__ccgo_up(bp))&uint32(7))&int32(0x46) == 0 {
		rc = _sqlite3MisuseError(tls, int32(190956)) /* IMP: R-18321-05872 */
	} else {
		if zFilename == uintptr(0) {
			zFilename = __ccgo_ts + 4332
		}
		rc = _sqlite3ParseUri(tls, zVfs, zFilename, bp, db, bp+8, bp+16)
	}
	if rc != SQLITE_OK {
		if rc == int32(SQLITE_NOMEM) {
			_sqlite3OomFault(tls, db)
		}
		if **(**uintptr)(__ccgo_up(bp + 16)) != 0 {
			v2 = __ccgo_ts + 3933
		} else {
			v2 = uintptr(0)
		}
		_sqlite3ErrorWithMsg(tls, db, rc, v2, libc.VaList(bp+32, **(**uintptr)(__ccgo_up(bp + 16))))
		Xsqlite3_free(tls, **(**uintptr)(__ccgo_up(bp + 16)))
		goto opendb_out
	}
	/* Open the backend database driver */
	rc = _sqlite3BtreeOpen(tls, (*Tsqlite3)(unsafe.Pointer(db)).FpVfs, **(**uintptr)(__ccgo_up(bp + 8)), db, (*Tsqlite3)(unsafe.Pointer(db)).FaDb+8, 0, libc.Int32FromUint32(**(**uint32)(__ccgo_up(bp))|uint32(SQLITE_OPEN_MAIN_DB)))
	if rc != SQLITE_OK {
		if rc == libc.Int32FromInt32(SQLITE_IOERR)|libc.Int32FromInt32(12)<<libc.Int32FromInt32(8) {
			rc = int32(SQLITE_NOMEM)
		}
		_sqlite3Error(tls, db, rc)
		goto opendb_out
	}
	_sqlite3BtreeEnter(tls, (**(**TDb)(__ccgo_up((*Tsqlite3)(unsafe.Pointer(db)).FaDb))).FpBt)
	(**(**TDb)(__ccgo_up((*Tsqlite3)(unsafe.Pointer(db)).FaDb))).FpSchema = _sqlite3SchemaGet(tls, db, (**(**TDb)(__ccgo_up((*Tsqlite3)(unsafe.Pointer(db)).FaDb))).FpBt)
	if !((*Tsqlite3)(unsafe.Pointer(db)).FmallocFailed != 0) {
		_sqlite3SetTextEncoding(tls, db, (*TSchema)(unsafe.Pointer((**(**TDb)(__ccgo_up((*Tsqlite3)(unsafe.Pointer(db)).FaDb))).FpSchema)).Fenc)
	}
	_sqlite3BtreeLeave(tls, (**(**TDb)(__ccgo_up((*Tsqlite3)(unsafe.Pointer(db)).FaDb))).FpBt)
	(**(**TDb)(__ccgo_up((*Tsqlite3)(unsafe.Pointer(db)).FaDb + 1*32))).FpSchema = _sqlite3SchemaGet(tls, db, uintptr(0))
	/* The default safety_level for the main database is FULL; for the temp
	 ** database it is OFF. This matches the pager layer defaults.
	 */
	(**(**TDb)(__ccgo_up((*Tsqlite3)(unsafe.Pointer(db)).FaDb))).FzDbSName = __ccgo_ts + 6809
	(**(**TDb)(__ccgo_up((*Tsqlite3)(unsafe.Pointer(db)).FaDb))).Fsafety_level = libc.Uint8FromInt32(libc.Int32FromInt32(SQLITE_DEFAULT_SYNCHRONOUS) + libc.Int32FromInt32(1))
	(**(**TDb)(__ccgo_up((*Tsqlite3)(unsafe.Pointer(db)).FaDb + 1*32))).FzDbSName = __ccgo_ts + 25253
	(**(**TDb)(__ccgo_up((*Tsqlite3)(unsafe.Pointer(db)).FaDb + 1*32))).Fsafety_level = uint8(PAGER_SYNCHRONOUS_OFF)
	(*Tsqlite3)(unsafe.Pointer(db)).FeOpenState = uint8(SQLITE_STATE_OPEN)
	if (*Tsqlite3)(unsafe.Pointer(db)).FmallocFailed != 0 {
		goto opendb_out
	}
	/* Register all built-in functions, but do not attempt to read the
	 ** database schema yet. This is delayed until the first time the database
	 ** is accessed.
	 */
	_sqlite3Error(tls, db, SQLITE_OK)
	_sqlite3RegisterPerConnectionBuiltinFunctions(tls, db)
	rc = Xsqlite3_errcode(tls, db)
	/* Load compiled-in extensions */
	i = 0
	for {
		if !(rc == SQLITE_OK && i < libc.Int32FromUint64(libc.Uint64FromInt64(40)/libc.Uint64FromInt64(8))) {
			break
		}
		rc = (*(*func(*libc.TLS, uintptr) int32)(unsafe.Pointer(&struct{ uintptr }{_sqlite3BuiltinExtensions[i]})))(tls, db)
		goto _3
	_3:
		;
		i = i + 1
	}
	/* Load automatic extensions - extensions that have been registered
	 ** using the sqlite3_automatic_extension() API.
	 */
	if rc == SQLITE_OK {
		_sqlite3AutoLoadExtensions(tls, db)
		rc = Xsqlite3_errcode(tls, db)
		if rc != SQLITE_OK {
			goto opendb_out
		}
	}
	/* -DSQLITE_DEFAULT_LOCKING_MODE=1 makes EXCLUSIVE the default locking
	 ** mode.  -DSQLITE_DEFAULT_LOCKING_MODE=0 make NORMAL the default locking
	 ** mode.  Doing nothing at all also makes NORMAL the default.
	 */
	if rc != 0 {
		_sqlite3Error(tls, db, rc)
	}
	/* Enable the lookaside-malloc subsystem */
	_setupLookaside(tls, db, uintptr(0), _sqlite3Config.FszLookaside, _sqlite3Config.FnLookaside)
	Xsqlite3_wal_autocheckpoint(tls, db, int32(SQLITE_DEFAULT_WAL_AUTOCHECKPOINT))
	goto opendb_out
opendb_out:
	;
	if db != 0 {
		Xsqlite3_mutex_leave(tls, (*Tsqlite3)(unsafe.Pointer(db)).Fmutex)
	}
	rc = Xsqlite3_errcode(tls, db)
	if rc&int32(0xff) == int32(SQLITE_NOMEM) {
		Xsqlite3_close(tls, db)
		db = uintptr(0)
	} else {
		if rc != SQLITE_OK {
			(*Tsqlite3)(unsafe.Pointer(db)).FeOpenState = uint8(SQLITE_STATE_SICK)
		}
	}
	**(**uintptr)(__ccgo_up(ppDb)) = db
	Xsqlite3_free_filename(tls, **(**uintptr)(__ccgo_up(bp + 8)))
	return rc
}

func _openRbuHandle(tls *libc.TLS, zTarget uintptr, zRbu uintptr, zState uintptr) (r uintptr) {
	bp := tls.Alloc(32)
	defer tls.Free(32)
	var db, p, pCsr, pFd, pState, v2 uintptr
	var frc int32
	var nByte, nRbu, nTarget Tsize_t
	var v1 uint64
	var _ /* bRetry at bp+0 */ int32
	_, _, _, _, _, _, _, _, _, _, _ = db, frc, nByte, nRbu, nTarget, p, pCsr, pFd, pState, v1, v2
	if zTarget != 0 {
		v1 = libc.Xstrlen(tls, zTarget)
	} else {
		v1 = uint64(0)
	}
	nTarget = v1
	nRbu = libc.Xstrlen(tls, zRbu)
	nByte = uint64(416) + nTarget + uint64(1) + nRbu + uint64(1)
	p = Xsqlite3_malloc64(tls, nByte)
	if p != 0 {
		pState = uintptr(0)
		/* Create the custom VFS. */
		libc.Xmemset(tls, p, 0, uint64(416))
		Xsqlite3rbu_rename_handler(tls, p, uintptr(0), uintptr(0))
		_rbuCreateVfs(tls, p)
		/* Open the target, RBU and state databases */
		if (*Tsqlite3rbu)(unsafe.Pointer(p)).Frc == SQLITE_OK {
			pCsr = p + 1*416
			**(**int32)(__ccgo_up(bp)) = 0
			if zTarget != 0 {
				(*Tsqlite3rbu)(unsafe.Pointer(p)).FzTarget = pCsr
				libc.Xmemcpy(tls, (*Tsqlite3rbu)(unsafe.Pointer(p)).FzTarget, zTarget, nTarget+uint64(1))
				pCsr = pCsr + uintptr(nTarget+uint64(1))
			}
			(*Tsqlite3rbu)(unsafe.Pointer(p)).FzRbu = pCsr
			libc.Xmemcpy(tls, (*Tsqlite3rbu)(unsafe.Pointer(p)).FzRbu, zRbu, nRbu+uint64(1))
			pCsr = pCsr + uintptr(nRbu+uint64(1))
			if zState != 0 {
				(*Tsqlite3rbu)(unsafe.Pointer(p)).FzState = _rbuMPrintf(tls, p, __ccgo_ts+3933, libc.VaList(bp+16, zState))
			}
			/* If the first attempt to open the database file fails and the bRetry
			 ** flag it set, this means that the db was not opened because it seemed
			 ** to be a wal-mode db. But, this may have happened due to an earlier
			 ** RBU vacuum operation leaving an old wal file in the directory.
			 ** If this is the case, it will have been checkpointed and deleted
			 ** when the handle was closed and a second attempt to open the
			 ** database may succeed.  */
			_rbuOpenDatabase(tls, p, uintptr(0), bp)
			if **(**int32)(__ccgo_up(bp)) != 0 {
				_rbuOpenDatabase(tls, p, uintptr(0), uintptr(0))
			}
		}
		if (*Tsqlite3rbu)(unsafe.Pointer(p)).Frc == SQLITE_OK {
			pState = _rbuLoadState(tls, p)
			if (*Tsqlite3rbu)(unsafe.Pointer(p)).Frc == SQLITE_OK {
				if (*TRbuState)(unsafe.Pointer(pState)).FeStage == 0 {
					_rbuDeleteOalFile(tls, p)
					_rbuInitPhaseOneSteps(tls, p)
					(*Tsqlite3rbu)(unsafe.Pointer(p)).FeStage = int32(RBU_STAGE_OAL)
				} else {
					(*Tsqlite3rbu)(unsafe.Pointer(p)).FeStage = (*TRbuState)(unsafe.Pointer(pState)).FeStage
					(*Tsqlite3rbu)(unsafe.Pointer(p)).FnPhaseOneStep = (*TRbuState)(unsafe.Pointer(pState)).FnPhaseOneStep
				}
				(*Tsqlite3rbu)(unsafe.Pointer(p)).FnProgress = (*TRbuState)(unsafe.Pointer(pState)).FnProgress
				(*Tsqlite3rbu)(unsafe.Pointer(p)).FiOalSz = (*TRbuState)(unsafe.Pointer(pState)).FiOalSz
			}
		}
		if (*Tsqlite3rbu)(unsafe.Pointer(p)).Frc == SQLITE_OK && (*Trbu_file)(unsafe.Pointer((*Tsqlite3rbu)(unsafe.Pointer(p)).FpTargetFd)).FpWalFd != 0 {
			if (*Tsqlite3rbu)(unsafe.Pointer(p)).FeStage == int32(RBU_STAGE_OAL) {
				(*Tsqlite3rbu)(unsafe.Pointer(p)).Frc = int32(SQLITE_ERROR)
				(*Tsqlite3rbu)(unsafe.Pointer(p)).FzErrmsg = Xsqlite3_mprintf(tls, __ccgo_ts+34547, 0)
			} else {
				if (*Tsqlite3rbu)(unsafe.Pointer(p)).FeStage == int32(RBU_STAGE_MOVE) {
					(*Tsqlite3rbu)(unsafe.Pointer(p)).FeStage = int32(RBU_STAGE_CKPT)
					(*Tsqlite3rbu)(unsafe.Pointer(p)).FnStep = 0
				}
			}
		}
		if (*Tsqlite3rbu)(unsafe.Pointer(p)).Frc == SQLITE_OK && ((*Tsqlite3rbu)(unsafe.Pointer(p)).FeStage == int32(RBU_STAGE_OAL) || (*Tsqlite3rbu)(unsafe.Pointer(p)).FeStage == int32(RBU_STAGE_MOVE)) && (*TRbuState)(unsafe.Pointer(pState)).FeStage != 0 {
			if (*Tsqlite3rbu)(unsafe.Pointer(p)).FzTarget == uintptr(0) {
				v2 = (*Tsqlite3rbu)(unsafe.Pointer(p)).FpRbuFd
			} else {
				v2 = (*Tsqlite3rbu)(unsafe.Pointer(p)).FpTargetFd
			}
			pFd = v2
			if (*Trbu_file)(unsafe.Pointer(pFd)).FiCookie != (*TRbuState)(unsafe.Pointer(pState)).FiCookie {
				/* At this point (pTargetFd->iCookie) contains the value of the
				 ** change-counter cookie (the thing that gets incremented when a
				 ** transaction is committed in rollback mode) currently stored on
				 ** page 1 of the database file. */
				(*Tsqlite3rbu)(unsafe.Pointer(p)).Frc = int32(SQLITE_BUSY)
				if (*Tsqlite3rbu)(unsafe.Pointer(p)).FzTarget == uintptr(0) {
					v2 = __ccgo_ts + 34579
				} else {
					v2 = __ccgo_ts + 34586
				}
				(*Tsqlite3rbu)(unsafe.Pointer(p)).FzErrmsg = Xsqlite3_mprintf(tls, __ccgo_ts+34593, libc.VaList(bp+16, v2))
			}
		}
		if (*Tsqlite3rbu)(unsafe.Pointer(p)).Frc == SQLITE_OK {
			if (*Tsqlite3rbu)(unsafe.Pointer(p)).FeStage == int32(RBU_STAGE_OAL) {
				db = (*Tsqlite3rbu)(unsafe.Pointer(p)).FdbMain
				(*Tsqlite3rbu)(unsafe.Pointer(p)).Frc = Xsqlite3_exec(tls, (*Tsqlite3rbu)(unsafe.Pointer(p)).FdbRbu, __ccgo_ts+16096, uintptr(0), uintptr(0), p+64)
				/* Point the object iterator at the first object */
				if (*Tsqlite3rbu)(unsafe.Pointer(p)).Frc == SQLITE_OK {
					(*Tsqlite3rbu)(unsafe.Pointer(p)).Frc = _rbuObjIterFirst(tls, p, p+88)
				}
				/* If the RBU database contains no data_xxx tables, declare the RBU
				 ** update finished.  */
				if (*Tsqlite3rbu)(unsafe.Pointer(p)).Frc == SQLITE_OK && (*Tsqlite3rbu)(unsafe.Pointer(p)).Fobjiter.FzTbl == uintptr(0) {
					(*Tsqlite3rbu)(unsafe.Pointer(p)).Frc = int32(SQLITE_DONE)
					(*Tsqlite3rbu)(unsafe.Pointer(p)).FeStage = int32(RBU_STAGE_DONE)
				} else {
					if (*Tsqlite3rbu)(unsafe.Pointer(p)).Frc == SQLITE_OK && (*TRbuState)(unsafe.Pointer(pState)).FeStage == 0 && (*Tsqlite3rbu)(unsafe.Pointer(p)).FzTarget == uintptr(0) {
						_rbuCopyPragma(tls, p, __ccgo_ts+18643)
						_rbuCopyPragma(tls, p, __ccgo_ts+18055)
					}
					/* Open transactions both databases. The *-oal file is opened or
					 ** created at this point. */
					if (*Tsqlite3rbu)(unsafe.Pointer(p)).Frc == SQLITE_OK {
						(*Tsqlite3rbu)(unsafe.Pointer(p)).Frc = Xsqlite3_exec(tls, db, __ccgo_ts+34625, uintptr(0), uintptr(0), p+64)
					}
					/* Check if the main database is a zipvfs db. If it is, set the upper
					 ** level pager to use "journal_mode=off". This prevents it from
					 ** generating a large journal using a temp file.  */
					if (*Tsqlite3rbu)(unsafe.Pointer(p)).Frc == SQLITE_OK {
						frc = Xsqlite3_file_control(tls, db, __ccgo_ts+6809, int32(SQLITE_FCNTL_ZIPVFS), uintptr(0))
						if frc == SQLITE_OK {
							(*Tsqlite3rbu)(unsafe.Pointer(p)).Frc = Xsqlite3_exec(tls, db, __ccgo_ts+34641, uintptr(0), uintptr(0), p+64)
						}
					}
					if (*Tsqlite3rbu)(unsafe.Pointer(p)).Frc == SQLITE_OK {
						_rbuSetupOal(tls, p, pState)
					}
				}
			} else {
				if (*Tsqlite3rbu)(unsafe.Pointer(p)).FeStage == int32(RBU_STAGE_MOVE) {
					/* no-op */
				} else {
					if (*Tsqlite3rbu)(unsafe.Pointer(p)).FeStage == int32(RBU_STAGE_CKPT) {
						if !((*Tsqlite3rbu)(unsafe.Pointer(p)).FzTarget == libc.UintptrFromInt32(0)) && _rbuExclusiveCheckpoint(tls, (*Tsqlite3rbu)(unsafe.Pointer(p)).FdbMain) != 0 {
							/* If the rbu_exclusive_checkpoint=1 URI parameter was specified
							 ** and an incremental checkpoint is being resumed, attempt an
							 ** exclusive lock on the db file. If this fails, so be it.  */
							(*Tsqlite3rbu)(unsafe.Pointer(p)).FeStage = int32(RBU_STAGE_DONE)
							_rbuLockDatabase(tls, (*Tsqlite3rbu)(unsafe.Pointer(p)).FdbMain)
							(*Tsqlite3rbu)(unsafe.Pointer(p)).FeStage = int32(RBU_STAGE_CKPT)
						}
						_rbuSetupCheckpoint(tls, p, pState)
					} else {
						if (*Tsqlite3rbu)(unsafe.Pointer(p)).FeStage == int32(RBU_STAGE_DONE) {
							(*Tsqlite3rbu)(unsafe.Pointer(p)).Frc = int32(SQLITE_DONE)
						} else {
							(*Tsqlite3rbu)(unsafe.Pointer(p)).Frc = int32(SQLITE_CORRUPT)
						}
					}
				}
			}
		}
		_rbuFreeState(tls, pState)
	}
	return p
}

// C documentation
//
//	/*
//	** This routine generates code that opens the sqlite_statN tables.
//	** The sqlite_stat1 table is always relevant.  sqlite_stat2 is now
//	** obsolete.  sqlite_stat3 and sqlite_stat4 are only opened when
//	** appropriate compile-time options are provided.
//	**
//	** If the sqlite_statN tables do not previously exist, it is created.
//	**
//	** Argument zWhere may be a pointer to a buffer containing a table name,
//	** or it may be a NULL pointer. If it is not NULL, then all entries in
//	** the sqlite_statN tables associated with the named table are deleted.
//	** If zWhere==0, then code is generated to delete all stat table entries.
//	*/
func _openStatTable(tls *libc.TLS, pParse uintptr, iDb int32, iStatCur int32, zWhere uintptr, zWhereType uintptr) {
	bp := tls.Alloc(48)
	defer tls.Free(48)
	var aCreateTbl [3]Tu8
	var aRoot [3]Tu32
	var db, pDb, pStat, v, zTab, v3 uintptr
	var i, nToOpen, v1 int32
	_, _, _, _, _, _, _, _, _, _, _ = aCreateTbl, aRoot, db, i, nToOpen, pDb, pStat, v, zTab, v1, v3
	db = (*TParse)(unsafe.Pointer(pParse)).Fdb
	v = _sqlite3GetVdbe(tls, pParse)
	if (*Tsqlite3)(unsafe.Pointer(db)).FdbOptFlags&libc.Uint32FromInt32(libc.Int32FromInt32(SQLITE_Stat4)) == uint32(0) {
		v1 = int32(2)
	} else {
		v1 = int32(1)
	}
	nToOpen = v1
	if v == uintptr(0) {
		return
	}
	pDb = (*Tsqlite3)(unsafe.Pointer(db)).FaDb + uintptr(iDb)*32
	/* Create new statistic tables if they do not exist, or clear them
	 ** if they do already exist.
	 */
	i = 0
	for {
		if !(i < libc.Int32FromUint64(libc.Uint64FromInt64(48)/libc.Uint64FromInt64(16))) {
			break
		}
		zTab = _aTable[i].FzName
		aCreateTbl[i] = uint8(0)
		v3 = _sqlite3FindTable(tls, db, zTab, (*TDb)(unsafe.Pointer(pDb)).FzDbSName)
		pStat = v3
		if v3 == uintptr(0) {
			if i < nToOpen {
				/* The sqlite_statN table does not exist. Create it. Note that a
				 ** side-effect of the CREATE TABLE statement is to leave the rootpage
				 ** of the new table in register pParse->regRoot. This is important
				 ** because the OpenWrite opcode below will be needing it. */
				_sqlite3NestedParse(tls, pParse, __ccgo_ts+12906, libc.VaList(bp+8, (*TDb)(unsafe.Pointer(pDb)).FzDbSName, zTab, _aTable[i].FzCols))
				aRoot[i] = libc.Uint32FromInt32((*(*struct {
					FaddrCrTab      int32
					FregRowid       int32
					FregRoot        int32
					FconstraintName TToken
				})(unsafe.Pointer(pParse + 256))).FregRoot)
				aCreateTbl[i] = uint8(OPFLAG_P2ISREG)
			}
		} else {
			/* The table already exists. If zWhere is not NULL, delete all entries
			 ** associated with the table zWhere. If zWhere is NULL, delete the
			 ** entire contents of the table. */
			aRoot[i] = (*TTable)(unsafe.Pointer(pStat)).Ftnum
			_sqlite3TableLock(tls, pParse, iDb, aRoot[i], uint8(1), zTab)
			if zWhere != 0 {
				_sqlite3NestedParse(tls, pParse, __ccgo_ts+12929, libc.VaList(bp+8, (*TDb)(unsafe.Pointer(pDb)).FzDbSName, zTab, zWhereType, zWhere))
			} else {
				if (*Tsqlite3)(unsafe.Pointer(db)).FxPreUpdateCallback != 0 {
					_sqlite3NestedParse(tls, pParse, __ccgo_ts+12959, libc.VaList(bp+8, (*TDb)(unsafe.Pointer(pDb)).FzDbSName, zTab))
				} else {
					/* The sqlite_stat[134] table already exists.  Delete all rows. */
					_sqlite3VdbeAddOp2(tls, v, int32(OP_Clear), libc.Int32FromUint32(aRoot[i]), iDb)
				}
			}
		}
		goto _2
	_2:
		;
		i = i + 1
	}
	/* Open the sqlite_stat[134] tables for writing. */
	i = 0
	for {
		if !(i < nToOpen) {
			break
		}
		_sqlite3VdbeAddOp4Int(tls, v, int32(OP_OpenWrite), iStatCur+i, libc.Int32FromUint32(aRoot[i]), iDb, int32(3))
		_sqlite3VdbeChangeP5(tls, v, uint16(aCreateTbl[i]))
		goto _4
	_4:
		;
		i = i + 1
	}
}

// C documentation
//
//	/*
//	** Playback the journal and thus restore the database file to
//	** the state it was in before we started making changes.
//	**
//	** The journal file format is as follows:
//	**
//	**  (1)  8 byte prefix.  A copy of aJournalMagic[].
//	**  (2)  4 byte big-endian integer which is the number of valid page records
//	**       in the journal.  If this value is 0xffffffff, then compute the
//	**       number of page records from the journal size.
//	**  (3)  4 byte big-endian integer which is the initial value for the
//	**       sanity checksum.
//	**  (4)  4 byte integer which is the number of pages to truncate the
//	**       database to during a rollback.
//	**  (5)  4 byte big-endian integer which is the sector size.  The header
//	**       is this many bytes in size.
//	**  (6)  4 byte big-endian integer which is the page size.
//	**  (7)  zero padding out to the next sector size.
//	**  (8)  Zero or more pages instances, each as follows:
//	**        +  4 byte page number.
//	**        +  pPager->pageSize bytes of data.
//	**        +  4 byte checksum
//	**
//	** When we speak of the journal header, we mean the first 7 items above.
//	** Each entry in the journal is an instance of the 8th item.
//	**
//	** Call the value from the second bullet "nRec".  nRec is the number of
//	** valid page entries in the journal.  In most cases, you can compute the
//	** value of nRec from the size of the journal file.  But if a power
//	** failure occurred while the journal was being written, it could be the
//	** case that the size of the journal file had already been increased but
//	** the extra entries had not yet made it safely to disk.  In such a case,
//	** the value of nRec computed from the file size would be too large.  For
//	** that reason, we always use the nRec value in the header.
//	**
//	** If the nRec value is 0xffffffff it means that nRec should be computed
//	** from the file size.  This value is used when the user selects the
//	** no-sync option for the journal.  A power failure could lead to corruption
//	** in this case.  But for things like temporary table (which will be
//	** deleted when the power is restored) we don't care.
//	**
//	** If the file opened as the journal file is not a well-formed
//	** journal file then all pages up to the first corrupted page are rolled
//	** back (or no pages if the journal header is corrupted). The journal file
//	** is then deleted and SQLITE_OK returned, just as if no corruption had
//	** been encountered.
//	**
//	** If an I/O or malloc() error occurs, the journal-file is not deleted
//	** and an error code is returned.
//	**
//	** The isHot parameter indicates that we are trying to rollback a journal
//	** that might be a hot journal.  Or, it could be that the journal is
//	** preserved because of JOURNALMODE_PERSIST or JOURNALMODE_TRUNCATE.
//	** If the journal really is hot, reset the pager cache prior rolling
//	** back any content.  If the journal is merely persistent, no reset is
//	** needed.
//	*/
func _pager_playback(tls *libc.TLS, pPager uintptr, isHot int32) (r int32) {
	bp := tls.Alloc(64)
	defer tls.Free(64)
	var nPlayback, needPagerReset, rc int32
	var pVfs uintptr
	var u Tu32
	var _ /* mxPg at bp+12 */ TPgno
	var _ /* nRec at bp+8 */ Tu32
	var _ /* res at bp+16 */ int32
	var _ /* savedPageSize at bp+32 */ Tu32
	var _ /* szJ at bp+0 */ Ti64
	var _ /* zSuper at bp+24 */ uintptr
	_, _, _, _, _ = nPlayback, needPagerReset, pVfs, rc, u
	pVfs = (*TPager)(unsafe.Pointer(pPager)).FpVfs /* Unsigned loop counter */
	**(**TPgno)(__ccgo_up(bp + 12)) = uint32(0)    /* Result code of a subroutine */
	**(**int32)(__ccgo_up(bp + 16)) = int32(1)     /* Value returned by sqlite3OsAccess() */
	**(**uintptr)(__ccgo_up(bp + 24)) = uintptr(0) /* True to reset page prior to first page rollback */
	nPlayback = 0                                  /* Total number of pages restored from journal */
	**(**Tu32)(__ccgo_up(bp + 32)) = libc.Uint32FromInt64((*TPager)(unsafe.Pointer(pPager)).FpageSize)
	/* Figure out how many records are in the journal.  Abort early if
	 ** the journal is empty.
	 */
	rc = _sqlite3OsFileSize(tls, (*TPager)(unsafe.Pointer(pPager)).Fjfd, bp)
	if rc != SQLITE_OK {
		goto end_playback
	}
	/* Read the super-journal name from the journal, if it is present.
	 ** If a super-journal file name is specified, but the file is not
	 ** present on disk, then the journal is not hot and does not need to be
	 ** played back.
	 */
	rc = _readSuperJournal(tls, (*TPager)(unsafe.Pointer(pPager)).Fjfd, libc.Uint64FromInt64(int64(1)+int64((*Tsqlite3_vfs)(unsafe.Pointer((*TPager)(unsafe.Pointer(pPager)).FpVfs)).FmxPathname)), bp+24)
	if rc == SQLITE_OK && **(**uintptr)(__ccgo_up(bp + 24)) != 0 {
		rc = _sqlite3OsAccess(tls, pVfs, **(**uintptr)(__ccgo_up(bp + 24)), SQLITE_ACCESS_EXISTS, bp+16)
	}
	if rc != SQLITE_OK || !(**(**int32)(__ccgo_up(bp + 16)) != 0) {
		goto end_playback
	}
	(*TPager)(unsafe.Pointer(pPager)).FjournalOff = 0
	needPagerReset = isHot
	/* This loop terminates either when a readJournalHdr() or
	 ** pager_playback_one_page() call returns SQLITE_DONE or an IO error
	 ** occurs.
	 */
	for int32(1) != 0 {
		/* Read the next journal header from the journal file.  If there are
		 ** not enough bytes left in the journal file for a complete header, or
		 ** it is corrupted, then a process must have failed while writing it.
		 ** This indicates nothing more needs to be rolled back.
		 */
		rc = _readJournalHdr(tls, pPager, isHot, **(**Ti64)(__ccgo_up(bp)), bp+8, bp+12)
		if rc != SQLITE_OK {
			if rc == int32(SQLITE_DONE) {
				rc = SQLITE_OK
			}
			goto end_playback
		}
		/* If nRec is 0xffffffff, then this journal was created by a process
		 ** working in no-sync mode. This means that the rest of the journal
		 ** file consists of pages, there are no more journal headers. Compute
		 ** the value of nRec based on this assumption.
		 */
		if **(**Tu32)(__ccgo_up(bp + 8)) == uint32(0xffffffff) {
			**(**Tu32)(__ccgo_up(bp + 8)) = libc.Uint32FromInt32(int32((**(**Ti64)(__ccgo_up(bp)) - libc.Int64FromUint32((*TPager)(unsafe.Pointer(pPager)).FsectorSize)) / ((*TPager)(unsafe.Pointer(pPager)).FpageSize + libc.Int64FromInt32(8))))
		}
		/* If nRec is 0 and this rollback is of a transaction created by this
		 ** process and if this is the final header in the journal, then it means
		 ** that this part of the journal was being filled but has not yet been
		 ** synced to disk.  Compute the number of pages based on the remaining
		 ** size of the file.
		 **
		 ** The third term of the test was added to fix ticket #2565.
		 ** When rolling back a hot journal, nRec==0 always means that the next
		 ** chunk of the journal contains zero pages to be rolled back.  But
		 ** when doing a ROLLBACK and the nRec==0 chunk is the last chunk in
		 ** the journal, it means that the journal might contain additional
		 ** pages that need to be rolled back and that the number of pages
		 ** should be computed based on the journal file size.
		 */
		if **(**Tu32)(__ccgo_up(bp + 8)) == uint32(0) && !(isHot != 0) && (*TPager)(unsafe.Pointer(pPager)).FjournalHdr+libc.Int64FromUint32((*TPager)(unsafe.Pointer(pPager)).FsectorSize) == (*TPager)(unsafe.Pointer(pPager)).FjournalOff {
			**(**Tu32)(__ccgo_up(bp + 8)) = libc.Uint32FromInt32(int32((**(**Ti64)(__ccgo_up(bp)) - (*TPager)(unsafe.Pointer(pPager)).FjournalOff) / ((*TPager)(unsafe.Pointer(pPager)).FpageSize + libc.Int64FromInt32(8))))
		}
		/* If this is the first header read from the journal, truncate the
		 ** database file back to its original size.
		 */
		if (*TPager)(unsafe.Pointer(pPager)).FjournalOff == libc.Int64FromUint32((*TPager)(unsafe.Pointer(pPager)).FsectorSize) {
			rc = _pager_truncate(tls, pPager, **(**TPgno)(__ccgo_up(bp + 12)))
			if rc != SQLITE_OK {
				goto end_playback
			}
			(*TPager)(unsafe.Pointer(pPager)).FdbSize = **(**TPgno)(__ccgo_up(bp + 12))
			if (*TPager)(unsafe.Pointer(pPager)).FmxPgno < **(**TPgno)(__ccgo_up(bp + 12)) {
				(*TPager)(unsafe.Pointer(pPager)).FmxPgno = **(**TPgno)(__ccgo_up(bp + 12))
			}
		}
		/* Copy original pages out of the journal and back into the
		 ** database file and/or page cache.
		 */
		u = uint32(0)
		for {
			if !(u < **(**Tu32)(__ccgo_up(bp + 8))) {
				break
			}
			if needPagerReset != 0 {
				_pager_reset(tls, pPager)
				needPagerReset = 0
			}
			rc = _pager_playback_one_page(tls, pPager, pPager+96, uintptr(0), int32(1), 0)
			if rc == SQLITE_OK {
				nPlayback = nPlayback + 1
			} else {
				if rc == int32(SQLITE_DONE) {
					(*TPager)(unsafe.Pointer(pPager)).FjournalOff = **(**Ti64)(__ccgo_up(bp))
					break
				} else {
					if rc == libc.Int32FromInt32(SQLITE_IOERR)|libc.Int32FromInt32(2)<<libc.Int32FromInt32(8) {
						/* If the journal has been truncated, simply stop reading and
						 ** processing the journal. This might happen if the journal was
						 ** not completely written and synced prior to a crash.  In that
						 ** case, the database should have never been written in the
						 ** first place so it is OK to simply abandon the rollback. */
						rc = SQLITE_OK
						goto end_playback
					} else {
						/* If we are unable to rollback, quit and return the error
						 ** code.  This will cause the pager to enter the error state
						 ** so that no further harm will be done.  Perhaps the next
						 ** process to come along will be able to rollback the database.
						 */
						goto end_playback
					}
				}
			}
			goto _1
		_1:
			;
			u = u + 1
		}
	}
	/*NOTREACHED*/
	goto end_playback
end_playback:
	;
	if rc == SQLITE_OK {
		rc = _sqlite3PagerSetPagesize(tls, pPager, bp+32, -int32(1))
	}
	/* Following a rollback, the database file should be back in its original
	 ** state prior to the start of the transaction, so invoke the
	 ** SQLITE_FCNTL_DB_UNCHANGED file-control method to disable the
	 ** assertion that the transaction counter was modified.
	 */
	/* If this playback is happening automatically as a result of an IO or
	 ** malloc error that occurred after the change-counter was updated but
	 ** before the transaction was committed, then the change-counter
	 ** modification may just have been reverted. If this happens in exclusive
	 ** mode, then subsequent transactions performed by the connection will not
	 ** update the change-counter at all. This may lead to cache inconsistency
	 ** problems for other processes at some point in the future. So, just
	 ** in case this has happened, clear the changeCountDone flag now.
	 */
	(*TPager)(unsafe.Pointer(pPager)).FchangeCountDone = (*TPager)(unsafe.Pointer(pPager)).FtempFile
	if rc == SQLITE_OK && (libc.Int32FromUint8((*TPager)(unsafe.Pointer(pPager)).FeState) >= int32(PAGER_WRITER_DBMOD) || libc.Int32FromUint8((*TPager)(unsafe.Pointer(pPager)).FeState) == PAGER_OPEN) {
		rc = _sqlite3PagerSync(tls, pPager, uintptr(0))
	}
	if rc == SQLITE_OK {
		rc = _pager_end_transaction(tls, pPager, libc.BoolInt32(**(**uintptr)(__ccgo_up(bp + 24)) != uintptr(0)), 0)
	}
	if rc == SQLITE_OK && **(**uintptr)(__ccgo_up(bp + 24)) != 0 && **(**int32)(__ccgo_up(bp + 16)) != 0 {
		/* If there was a super-journal and this routine will return success,
		 ** see if it is possible to delete the super-journal.
		 */
		rc = _pager_delsuper(tls, pPager, **(**uintptr)(__ccgo_up(bp + 24)))
	}
	if isHot != 0 && nPlayback != 0 {
		Xsqlite3_log(tls, libc.Int32FromInt32(SQLITE_NOTICE)|libc.Int32FromInt32(2)<<libc.Int32FromInt32(8), __ccgo_ts+4193, libc.VaList(bp+48, nPlayback, (*TPager)(unsafe.Pointer(pPager)).FzJournal))
	}
	/* The Pager.sectorSize variable may have been updated while rolling
	 ** back a journal created by a process with a different sector size
	 ** value. Reset it to the correct value for this process.
	 */
	_freeSuperJournal(tls, **(**uintptr)(__ccgo_up(bp + 24)))
	_setSectorSize(tls, pPager)
	return rc
}

// C documentation
//
//	/*
//	** Attempt to parse the given string into a julian day number.  Return
//	** the number of errors.
//	**
//	** The following are acceptable forms for the input string:
//	**
//	**      YYYY-MM-DD HH:MM:SS.FFF  +/-HH:MM
//	**      DDDD.DD
//	**      now
//	**
//	** In the first form, the +/-HH:MM is always optional.  The fractional
//	** seconds extension (the ".FFF") is optional.  The seconds portion
//	** (":SS.FFF") is option.  The year and date can be omitted as long
//	** as there is a time string.  The time string can be omitted as long
//	** as there is a year and date.
//	*/
func _parseDateOrTime(tls *libc.TLS, context uintptr, zDate uintptr, p uintptr) (r int32) {
	bp := tls.Alloc(16)
	defer tls.Free(16)
	var _ /* r at bp+0 */ float64
	if _parseYyyyMmDd(tls, zDate, p) == 0 {
		return 0
	} else {
		if _parseHhMmSs(tls, zDate, p) == 0 {
			return 0
		} else {
			if _sqlite3StrICmp(tls, zDate, __ccgo_ts+1217) == 0 && _sqlite3NotPureFunc(tls, context) != 0 {
				return _setDateTimeToCurrent(tls, context, p)
			} else {
				if _sqlite3AtoF(tls, zDate, bp) > 0 {
					_setRawDateNumber(tls, p, **(**float64)(__ccgo_up(bp)))
					return 0
				} else {
					if (_sqlite3StrICmp(tls, zDate, __ccgo_ts+1221) == 0 || _sqlite3StrICmp(tls, zDate, __ccgo_ts+1228) == 0) && _sqlite3NotPureFunc(tls, context) != 0 {
						libc.SetBitFieldPtr8Uint32(p+44, libc.Uint32FromInt32(1), 2, 0x4)
						return _setDateTimeToCurrent(tls, context, p)
					}
				}
			}
		}
	}
	return int32(1)
}

/* The julian day number for 9999-12-31 23:59:59.999 is 5373484.4999999.
** Multiplying this by 86400000 gives 464269060799999 as the maximum value
** for DateTime.iJD.
**
** But some older compilers (ex: gcc 4.2.1 on older Macs) cannot deal with
** such a large integer literal, so we have to encode it.
 */

// C documentation
//
//	/* Add a single new term to an ExprList that is used to store a
//	  ** list of identifiers.  Report an error if the ID list contains
//	  ** a COLLATE clause or an ASC or DESC keyword, except ignore the
//	  ** error while parsing a legacy schema.
//	  */
func _parserAddExprIdListTerm(tls *libc.TLS, pParse uintptr, pPrior uintptr, pIdToken uintptr, hasCollate int32, sortOrder int32) (r uintptr) {
	bp := tls.Alloc(32)
	defer tls.Free(32)
	var p uintptr
	_ = p
	p = _sqlite3ExprListAppend(tls, pParse, pPrior, uintptr(0))
	if (hasCollate != 0 || sortOrder != -int32(1)) && libc.Int32FromUint8((*Tsqlite3)(unsafe.Pointer((*TParse)(unsafe.Pointer(pParse)).Fdb)).Finit1.Fbusy) == 0 {
		_sqlite3ErrorMsg(tls, pParse, __ccgo_ts+24934, libc.VaList(bp+8, (*TToken)(unsafe.Pointer(pIdToken)).Fn, (*TToken)(unsafe.Pointer(pIdToken)).Fz))
	}
	_sqlite3ExprListSetName(tls, pParse, p, pIdToken, int32(1))
	return p
}

/**************** End of %include directives **********************************/
/* These constants specify the various numeric values for terminal symbols.
***************** Begin token definitions *************************************/
/**************** End token definitions ***************************************/

// C documentation
//
//	/*
//	  ** For a compound SELECT statement, make sure p->pPrior->pNext==p for
//	  ** all elements in the list.  And make sure list length does not exceed
//	  ** SQLITE_LIMIT_COMPOUND_SELECT.
//	  */
func _parserDoubleLinkSelect(tls *libc.TLS, pParse uintptr, p uintptr) {
	bp := tls.Alloc(32)
	defer tls.Free(32)
	var cnt, mxSelect, v2 int32
	var pLoop, pNext, v1 uintptr
	var v3 bool
	_, _, _, _, _, _, _ = cnt, mxSelect, pLoop, pNext, v1, v2, v3
	if (*TSelect)(unsafe.Pointer(p)).FpPrior != 0 {
		pNext = uintptr(0)
		pLoop = p
		cnt = int32(1)
		for int32(1) != 0 {
			(*TSelect)(unsafe.Pointer(pLoop)).FpNext = pNext
			**(**Tu32)(__ccgo_up(pLoop + 4)) |= uint32(SF_Compound)
			pNext = pLoop
			pLoop = (*TSelect)(unsafe.Pointer(pLoop)).FpPrior
			if pLoop == uintptr(0) {
				break
			}
			cnt = cnt + 1
			if (*TSelect)(unsafe.Pointer(pLoop)).FpOrderBy != 0 || (*TSelect)(unsafe.Pointer(pLoop)).FpLimit != 0 {
				if (*TSelect)(unsafe.Pointer(pLoop)).FpOrderBy != uintptr(0) {
					v1 = __ccgo_ts + 24843
				} else {
					v1 = __ccgo_ts + 24852
				}
				_sqlite3ErrorMsg(tls, pParse, __ccgo_ts+24858, libc.VaList(bp+8, v1, _sqlite3SelectOpName(tls, libc.Int32FromUint8((*TSelect)(unsafe.Pointer(pNext)).Fop))))
				break
			}
		}
		if v3 = (*TSelect)(unsafe.Pointer(p)).FselFlags&libc.Uint32FromInt32(libc.Int32FromInt32(SF_MultiValue)|libc.Int32FromInt32(SF_Values)) == uint32(0); v3 {
			v2 = **(**int32)(__ccgo_up((*TParse)(unsafe.Pointer(pParse)).Fdb + 136 + 4*4))
			mxSelect = v2
		}
		if v3 && v2 > 0 && cnt > mxSelect {
			_sqlite3ErrorMsg(tls, pParse, __ccgo_ts+24900, 0)
		}
	}
}

// C documentation
//
//	/*
//	** Generate a syntax error
//	*/
func _parserSyntaxError(tls *libc.TLS, pParse uintptr, p uintptr) {
	bp := tls.Alloc(16)
	defer tls.Free(16)
	_sqlite3ErrorMsg(tls, pParse, __ccgo_ts+24819, libc.VaList(bp+8, p))
}

// C documentation
//
//	/*
//	** Implementation of 0-argument pi() function.
//	*/
func _piFunc(tls *libc.TLS, context uintptr, argc int32, argv uintptr) {
	_ = argv
	Xsqlite3_result_double(tls, context, libc.Float64FromFloat64(3.141592653589793))
}

// C documentation
//
//	/*
//	** Lower the locking level on file descriptor pFile to eFileLock.  eFileLock
//	** must be either NO_LOCK or SHARED_LOCK.
//	**
//	** If the locking level of the file descriptor is already at or below
//	** the requested locking level, this routine is a no-op.
//	**
//	** If handleNFSUnlock is true, then on downgrading an EXCLUSIVE_LOCK to SHARED
//	** the byte range is divided into 2 parts and the first part is unlocked then
//	** set to a read lock, then the other part is simply unlocked.  This works
//	** around a bug in BSD NFS lockd (also seen on MacOSX 10.3+) that fails to
//	** remove the write lock on a region when a read lock is set.
//	*/
func _posixUnlock(tls *libc.TLS, id uintptr, eFileLock int32, handleNFSUnlock int32) (r int32) {
	bp := tls.Alloc(32)
	defer tls.Free(32)
	var pFile, pInode uintptr
	var rc int32
	var v1 Toff_t
	var _ /* lock at bp+0 */ Tflock
	_, _, _, _ = pFile, pInode, rc, v1
	pFile = id
	rc = SQLITE_OK
	if libc.Int32FromUint8((*TunixFile)(unsafe.Pointer(pFile)).FeFileLock) <= eFileLock {
		return SQLITE_OK
	}
	pInode = (*TunixFile)(unsafe.Pointer(pFile)).FpInode
	Xsqlite3_mutex_enter(tls, (*TunixInodeInfo)(unsafe.Pointer(pInode)).FpLockMutex)
	if libc.Int32FromUint8((*TunixFile)(unsafe.Pointer(pFile)).FeFileLock) > int32(SHARED_LOCK) {
		/* downgrading to a shared lock on NFS involves clearing the write lock
		 ** before establishing the readlock - to avoid a race condition we downgrade
		 ** the lock in 2 blocks, so that part of the range will be covered by a
		 ** write lock until the rest is covered by a read lock:
		 **  1:   [WWWWW]
		 **  2:   [....W]
		 **  3:   [RRRRW]
		 **  4:   [RRRR.]
		 */
		if eFileLock == int32(SHARED_LOCK) {
			_ = handleNFSUnlock
			(**(**Tflock)(__ccgo_up(bp))).Fl_type = int16(F_RDLCK)
			(**(**Tflock)(__ccgo_up(bp))).Fl_whence = SEEK_SET
			(**(**Tflock)(__ccgo_up(bp))).Fl_start = int64(_sqlite3PendingByte + libc.Int32FromInt32(2))
			(**(**Tflock)(__ccgo_up(bp))).Fl_len = int64(SHARED_SIZE)
			if _unixFileLock(tls, pFile, bp) != 0 {
				/* In theory, the call to unixFileLock() cannot fail because another
				 ** process is holding an incompatible lock. If it does, this
				 ** indicates that the other process is not following the locking
				 ** protocol. If this happens, return SQLITE_IOERR_RDLOCK. Returning
				 ** SQLITE_BUSY would confuse the upper layer (in practice it causes
				 ** an assert to fail). */
				rc = libc.Int32FromInt32(SQLITE_IOERR) | libc.Int32FromInt32(9)<<libc.Int32FromInt32(8)
				_storeLastErrno(tls, pFile, **(**int32)(__ccgo_up(libc.X__errno(tls))))
				goto end_unlock
			}
		}
		(**(**Tflock)(__ccgo_up(bp))).Fl_type = int16(F_UNLCK)
		(**(**Tflock)(__ccgo_up(bp))).Fl_whence = SEEK_SET
		(**(**Tflock)(__ccgo_up(bp))).Fl_start = int64(_sqlite3PendingByte)
		(**(**Tflock)(__ccgo_up(bp))).Fl_len = int64(2)
		if _unixFileLock(tls, pFile, bp) == 0 {
			(*TunixInodeInfo)(unsafe.Pointer(pInode)).FeFileLock = uint8(SHARED_LOCK)
		} else {
			rc = libc.Int32FromInt32(SQLITE_IOERR) | libc.Int32FromInt32(8)<<libc.Int32FromInt32(8)
			_storeLastErrno(tls, pFile, **(**int32)(__ccgo_up(libc.X__errno(tls))))
			goto end_unlock
		}
	}
	if eFileLock == NO_LOCK {
		/* Decrement the shared lock counter.  Release the lock using an
		 ** OS call only when all threads in this same process have released
		 ** the lock.
		 */
		(*TunixInodeInfo)(unsafe.Pointer(pInode)).FnShared = (*TunixInodeInfo)(unsafe.Pointer(pInode)).FnShared - 1
		if (*TunixInodeInfo)(unsafe.Pointer(pInode)).FnShared == 0 {
			(**(**Tflock)(__ccgo_up(bp))).Fl_type = int16(F_UNLCK)
			(**(**Tflock)(__ccgo_up(bp))).Fl_whence = SEEK_SET
			v1 = libc.Int64FromInt64(0)
			(**(**Tflock)(__ccgo_up(bp))).Fl_len = v1
			(**(**Tflock)(__ccgo_up(bp))).Fl_start = v1
			if _unixFileLock(tls, pFile, bp) == 0 {
				(*TunixInodeInfo)(unsafe.Pointer(pInode)).FeFileLock = uint8(NO_LOCK)
			} else {
				rc = libc.Int32FromInt32(SQLITE_IOERR) | libc.Int32FromInt32(8)<<libc.Int32FromInt32(8)
				_storeLastErrno(tls, pFile, **(**int32)(__ccgo_up(libc.X__errno(tls))))
				(*TunixInodeInfo)(unsafe.Pointer(pInode)).FeFileLock = uint8(NO_LOCK)
				(*TunixFile)(unsafe.Pointer(pFile)).FeFileLock = uint8(NO_LOCK)
			}
		}
		/* Decrement the count of locks against this same file.  When the
		 ** count reaches zero, close any other file descriptors whose close
		 ** was deferred because of outstanding locks.
		 */
		(*TunixInodeInfo)(unsafe.Pointer(pInode)).FnLock = (*TunixInodeInfo)(unsafe.Pointer(pInode)).FnLock - 1
		if (*TunixInodeInfo)(unsafe.Pointer(pInode)).FnLock == 0 {
			_closePendingFds(tls, pFile)
		}
	}
	goto end_unlock
end_unlock:
	;
	Xsqlite3_mutex_leave(tls, (*TunixInodeInfo)(unsafe.Pointer(pInode)).FpLockMutex)
	if rc == SQLITE_OK {
		(*TunixFile)(unsafe.Pointer(pFile)).FeFileLock = libc.Uint8FromInt32(eFileLock)
	}
	return rc
}

// C documentation
//
//	/* Names of columns for pragmas that return multi-column result
//	** or that return single-column results where the name of the
//	** result column is different from the name of the pragma
//	*/
var _pragCName = [57]uintptr{
	0:  __ccgo_ts + 5641,
	1:  __ccgo_ts + 17773,
	2:  __ccgo_ts + 9370,
	3:  __ccgo_ts + 17777,
	4:  __ccgo_ts + 17782,
	5:  __ccgo_ts + 17785,
	6:  __ccgo_ts + 17795,
	7:  __ccgo_ts + 17805,
	8:  __ccgo_ts + 17811,
	9:  __ccgo_ts + 17815,
	10: __ccgo_ts + 17820,
	11: __ccgo_ts + 17825,
	12: __ccgo_ts + 17833,
	13: __ccgo_ts + 17844,
	14: __ccgo_ts + 17847,
	15: __ccgo_ts + 17815,
	16: __ccgo_ts + 17854,
	17: __ccgo_ts + 17820,
	18: __ccgo_ts + 17862,
	19: __ccgo_ts + 17866,
	20: __ccgo_ts + 17871,
	21: __ccgo_ts + 17877,
	22: __ccgo_ts + 17815,
	23: __ccgo_ts + 17820,
	24: __ccgo_ts + 17884,
	25: __ccgo_ts + 17889,
	26: __ccgo_ts + 17892,
	27: __ccgo_ts + 17899,
	28: __ccgo_ts + 17811,
	29: __ccgo_ts + 17815,
	30: __ccgo_ts + 17905,
	31: __ccgo_ts + 17910,
	32: __ccgo_ts + 17915,
	33: __ccgo_ts + 17773,
	34: __ccgo_ts + 17815,
	35: __ccgo_ts + 17919,
	36: __ccgo_ts + 17926,
	37: __ccgo_ts + 17933,
	38: __ccgo_ts + 13041,
	39: __ccgo_ts + 13037,
	40: __ccgo_ts + 17941,
	41: __ccgo_ts + 17946,
	42: __ccgo_ts + 17951,
	43: __ccgo_ts + 9370,
	44: __ccgo_ts + 17956,
	45: __ccgo_ts + 5644,
	46: __ccgo_ts + 17962,
	47: __ccgo_ts + 17967,
	48: __ccgo_ts + 17158,
	49: __ccgo_ts + 17972,
	50: __ccgo_ts + 17773,
	51: __ccgo_ts + 17815,
	52: __ccgo_ts + 17985,
	53: __ccgo_ts + 17990,
	54: __ccgo_ts + 17999,
	55: __ccgo_ts + 18006,
	56: __ccgo_ts + 18017,
}

// C documentation
//
//	/*
//	** Create zero or more entries in the output for the SQL functions
//	** defined by FuncDef p.
//	*/
func _pragmaFunclistLine(tls *libc.TLS, v uintptr, p uintptr, isBuiltin int32, showInternFuncs int32) {
	bp := tls.Alloc(64)
	defer tls.Free(64)
	var mask Tu32
	var zType uintptr
	_, _ = mask, zType
	mask = libc.Uint32FromInt32(libc.Int32FromInt32(SQLITE_DETERMINISTIC) | libc.Int32FromInt32(SQLITE_DIRECTONLY) | libc.Int32FromInt32(SQLITE_SUBTYPE) | libc.Int32FromInt32(SQLITE_INNOCUOUS) | libc.Int32FromInt32(SQLITE_FUNC_INTERNAL))
	if showInternFuncs != 0 {
		mask = uint32(0xffffffff)
	}
	for {
		if !(p != 0) {
			break
		}
		if (*TFuncDef)(unsafe.Pointer(p)).FxSFunc == uintptr(0) {
			goto _1
		}
		if (*TFuncDef)(unsafe.Pointer(p)).FfuncFlags&uint32(SQLITE_FUNC_INTERNAL) != uint32(0) && showInternFuncs == 0 {
			goto _1
		}
		if (*TFuncDef)(unsafe.Pointer(p)).FxValue != uintptr(0) {
			zType = __ccgo_ts + 19196
		} else {
			if (*TFuncDef)(unsafe.Pointer(p)).FxFinalize != uintptr(0) {
				zType = __ccgo_ts + 19198
			} else {
				zType = __ccgo_ts + 7902
			}
		}
		_sqlite3VdbeMultiLoad(tls, v, int32(1), __ccgo_ts+19200, libc.VaList(bp+8, (*TFuncDef)(unsafe.Pointer(p)).FzName, isBuiltin, zType, _azEnc[(*TFuncDef)(unsafe.Pointer(p)).FfuncFlags&uint32(SQLITE_FUNC_ENCMASK)], int32((*TFuncDef)(unsafe.Pointer(p)).FnArg), (*TFuncDef)(unsafe.Pointer(p)).FfuncFlags&mask^uint32(SQLITE_INNOCUOUS)))
		goto _1
	_1:
		;
		p = (*TFuncDef)(unsafe.Pointer(p)).FpNext
	}
}

// C documentation
//
//	/*
//	** Pragma virtual table module xFilter method.
//	*/
func _pragmaVtabFilter(tls *libc.TLS, pVtabCursor uintptr, idxNum int32, idxStr uintptr, argc int32, argv uintptr) (r int32) {
	bp := tls.Alloc(48)
	defer tls.Free(48)
	var i, j, rc, v1 int32
	var pCsr, pTab, zSql, zText uintptr
	var _ /* acc at bp+0 */ TStrAccum
	_, _, _, _, _, _, _, _ = i, j, pCsr, pTab, rc, zSql, zText, v1
	pCsr = pVtabCursor
	pTab = (*Tsqlite3_vtab_cursor)(unsafe.Pointer(pVtabCursor)).FpVtab
	_ = idxNum
	_ = idxStr
	_pragmaVtabCursorClear(tls, pCsr)
	if libc.Int32FromUint8((*TPragmaName)(unsafe.Pointer((*TPragmaVtab)(unsafe.Pointer(pTab)).FpName)).FmPragFlg)&int32(PragFlg_Result1) != 0 {
		v1 = 0
	} else {
		v1 = int32(1)
	}
	j = v1
	i = 0
	for {
		if !(i < argc) {
			break
		}
		zText = Xsqlite3_value_text(tls, **(**uintptr)(__ccgo_up(argv + uintptr(i)*8)))
		if zText != 0 {
			**(**uintptr)(__ccgo_up(pCsr + 24 + uintptr(j)*8)) = Xsqlite3_mprintf(tls, __ccgo_ts+3933, libc.VaList(bp+40, zText))
			if **(**uintptr)(__ccgo_up(pCsr + 24 + uintptr(j)*8)) == uintptr(0) {
				return int32(SQLITE_NOMEM)
			}
		}
		goto _2
	_2:
		;
		i = i + 1
		j = j + 1
	}
	_sqlite3StrAccumInit(tls, bp, uintptr(0), uintptr(0), 0, **(**int32)(__ccgo_up((*TPragmaVtab)(unsafe.Pointer(pTab)).Fdb + 136 + 1*4)))
	Xsqlite3_str_appendall(tls, bp, __ccgo_ts+19954)
	if **(**uintptr)(__ccgo_up(pCsr + 24 + 1*8)) != 0 {
		Xsqlite3_str_appendf(tls, bp, __ccgo_ts+19962, libc.VaList(bp+40, **(**uintptr)(__ccgo_up(pCsr + 24 + 1*8))))
	}
	Xsqlite3_str_appendall(tls, bp, (*TPragmaName)(unsafe.Pointer((*TPragmaVtab)(unsafe.Pointer(pTab)).FpName)).FzName)
	if **(**uintptr)(__ccgo_up(pCsr + 24)) != 0 {
		Xsqlite3_str_appendf(tls, bp, __ccgo_ts+19966, libc.VaList(bp+40, **(**uintptr)(__ccgo_up(pCsr + 24))))
	}
	zSql = _sqlite3StrAccumFinish(tls, bp)
	if zSql == uintptr(0) {
		return int32(SQLITE_NOMEM)
	}
	rc = Xsqlite3_prepare_v2(tls, (*TPragmaVtab)(unsafe.Pointer(pTab)).Fdb, zSql, -int32(1), pCsr+8, uintptr(0))
	Xsqlite3_free(tls, zSql)
	if rc != SQLITE_OK {
		(*TPragmaVtab)(unsafe.Pointer(pTab)).Fbase.FzErrMsg = Xsqlite3_mprintf(tls, __ccgo_ts+3933, libc.VaList(bp+40, Xsqlite3_errmsg(tls, (*TPragmaVtab)(unsafe.Pointer(pTab)).Fdb)))
		return rc
	}
	return _pragmaVtabNext(tls, pVtabCursor)
}

// C documentation
//
//	/*
//	** Prepare the SQL statement in buffer zSql against database handle db.
//	** If successful, set *ppStmt to point to the new statement and return
//	** SQLITE_OK.
//	**
//	** Otherwise, if an error does occur, set *ppStmt to NULL and return
//	** an SQLite error code. Additionally, set output variable *pzErrmsg to
//	** point to a buffer containing an error message. It is the responsibility
//	** of the caller to (eventually) free this buffer using sqlite3_free().
//	*/
func _prepareAndCollectError(tls *libc.TLS, db uintptr, ppStmt uintptr, pzErrmsg uintptr, zSql uintptr) (r int32) {
	bp := tls.Alloc(16)
	defer tls.Free(16)
	var rc int32
	_ = rc
	rc = Xsqlite3_prepare_v2(tls, db, zSql, -int32(1), ppStmt, uintptr(0))
	if rc != SQLITE_OK {
		**(**uintptr)(__ccgo_up(pzErrmsg)) = Xsqlite3_mprintf(tls, __ccgo_ts+3933, libc.VaList(bp+8, Xsqlite3_errmsg(tls, db)))
		**(**uintptr)(__ccgo_up(ppStmt)) = uintptr(0)
	}
	return rc
}

// C documentation
//
//	/*
//	** The SELECT statement iterating through the keys for the current object
//	** (p->objiter.pSelect) currently points to a valid row. However, there
//	** is something wrong with the rbu_control value in the rbu_control value
//	** stored in the (p->nCol+1)'th column. Set the error code and error message
//	** of the RBU handle to something reflecting this.
//	*/
func _rbuBadControlError(tls *libc.TLS, p uintptr) {
	(*Tsqlite3rbu)(unsafe.Pointer(p)).Frc = int32(SQLITE_ERROR)
	(*Tsqlite3rbu)(unsafe.Pointer(p)).FzErrmsg = Xsqlite3_mprintf(tls, __ccgo_ts+31735, 0)
}

// C documentation
//
//	/*
//	** The second argument passed to this function is the name of a PRAGMA
//	** setting - "page_size", "auto_vacuum", "user_version" or "application_id".
//	** This function executes the following on sqlite3rbu.dbRbu:
//	**
//	**   "PRAGMA main.$zPragma"
//	**
//	** where $zPragma is the string passed as the second argument, then
//	** on sqlite3rbu.dbMain:
//	**
//	**   "PRAGMA main.$zPragma = $val"
//	**
//	** where $val is the value returned by the first PRAGMA invocation.
//	**
//	** In short, it copies the value  of the specified PRAGMA setting from
//	** dbRbu to dbMain.
//	*/
func _rbuCopyPragma(tls *libc.TLS, p uintptr, zPragma uintptr) {
	bp := tls.Alloc(32)
	defer tls.Free(32)
	var _ /* pPragma at bp+0 */ uintptr
	if (*Tsqlite3rbu)(unsafe.Pointer(p)).Frc == SQLITE_OK {
		**(**uintptr)(__ccgo_up(bp)) = uintptr(0)
		(*Tsqlite3rbu)(unsafe.Pointer(p)).Frc = _prepareFreeAndCollectError(tls, (*Tsqlite3rbu)(unsafe.Pointer(p)).FdbRbu, bp, p+64, Xsqlite3_mprintf(tls, __ccgo_ts+33964, libc.VaList(bp+16, zPragma)))
		if (*Tsqlite3rbu)(unsafe.Pointer(p)).Frc == SQLITE_OK && int32(SQLITE_ROW) == Xsqlite3_step(tls, **(**uintptr)(__ccgo_up(bp))) {
			(*Tsqlite3rbu)(unsafe.Pointer(p)).Frc = _rbuMPrintfExec(tls, p, (*Tsqlite3rbu)(unsafe.Pointer(p)).FdbMain, __ccgo_ts+33979, libc.VaList(bp+16, zPragma, Xsqlite3_column_int(tls, **(**uintptr)(__ccgo_up(bp)), 0)))
		}
		_rbuFinalize(tls, p, **(**uintptr)(__ccgo_up(bp)))
	}
}

// C documentation
//
//	/*
//	** If an error has already occurred when this function is called, it
//	** immediately returns zero (without doing any work). Or, if an error
//	** occurs during the execution of this function, it sets the error code
//	** in the sqlite3rbu object indicated by the first argument and returns
//	** zero.
//	**
//	** The iterator passed as the second argument is guaranteed to point to
//	** a table (not an index) when this function is called. This function
//	** attempts to create any imposter table required to write to the main
//	** table b-tree of the table before returning. Non-zero is returned if
//	** an imposter table are created, or zero otherwise.
//	**
//	** An imposter table is required in all cases except RBU_PK_VTAB. Only
//	** virtual tables are written to directly. The imposter table has the
//	** same schema as the actual target table (less any UNIQUE constraints).
//	** More precisely, the "same schema" means the same columns, types,
//	** collation sequences. For tables that do not have an external PRIMARY
//	** KEY, it also means the same PRIMARY KEY declaration.
//	*/
func _rbuCreateImposterTable(tls *libc.TLS, p uintptr, pIter uintptr) {
	bp := tls.Alloc(80)
	defer tls.Free(80)
	var iCol, tnum int32
	var zCol, zComma, zPk, zPk1, zSql, v2 uintptr
	var _ /* zColl at bp+0 */ uintptr
	_, _, _, _, _, _, _, _ = iCol, tnum, zCol, zComma, zPk, zPk1, zSql, v2
	if (*Tsqlite3rbu)(unsafe.Pointer(p)).Frc == SQLITE_OK && (*TRbuObjIter)(unsafe.Pointer(pIter)).FeType != int32(RBU_PK_VTAB) {
		tnum = (*TRbuObjIter)(unsafe.Pointer(pIter)).FiTnum
		zComma = __ccgo_ts + 1693
		zSql = uintptr(0)
		Xsqlite3_test_control(tls, int32(SQLITE_TESTCTRL_IMPOSTER), libc.VaList(bp+16, (*Tsqlite3rbu)(unsafe.Pointer(p)).FdbMain, __ccgo_ts+6809, 0, int32(1)))
		iCol = 0
		for {
			if !((*Tsqlite3rbu)(unsafe.Pointer(p)).Frc == SQLITE_OK && iCol < (*TRbuObjIter)(unsafe.Pointer(pIter)).FnTblCol) {
				break
			}
			zPk = __ccgo_ts + 1693
			zCol = **(**uintptr)(__ccgo_up((*TRbuObjIter)(unsafe.Pointer(pIter)).FazTblCol + uintptr(iCol)*8))
			**(**uintptr)(__ccgo_up(bp)) = uintptr(0)
			(*Tsqlite3rbu)(unsafe.Pointer(p)).Frc = Xsqlite3_table_column_metadata(tls, (*Tsqlite3rbu)(unsafe.Pointer(p)).FdbMain, __ccgo_ts+6809, (*TRbuObjIter)(unsafe.Pointer(pIter)).FzTbl, zCol, uintptr(0), bp, uintptr(0), uintptr(0), uintptr(0))
			if (*TRbuObjIter)(unsafe.Pointer(pIter)).FeType == int32(RBU_PK_IPK) && **(**Tu8)(__ccgo_up((*TRbuObjIter)(unsafe.Pointer(pIter)).FabTblPk + uintptr(iCol))) != 0 {
				/* If the target table column is an "INTEGER PRIMARY KEY", add
				 ** "PRIMARY KEY" to the imposter table column declaration. */
				zPk = __ccgo_ts + 32015
			}
			if **(**Tu8)(__ccgo_up((*TRbuObjIter)(unsafe.Pointer(pIter)).FabNotNull + uintptr(iCol))) != 0 {
				v2 = __ccgo_ts + 32028
			} else {
				v2 = __ccgo_ts + 1693
			}
			zSql = _rbuMPrintf(tls, p, __ccgo_ts+32038, libc.VaList(bp+16, zSql, zComma, zCol, **(**uintptr)(__ccgo_up((*TRbuObjIter)(unsafe.Pointer(pIter)).FazTblType + uintptr(iCol)*8)), zPk, **(**uintptr)(__ccgo_up(bp)), v2))
			zComma = __ccgo_ts + 16207
			goto _1
		_1:
			;
			iCol = iCol + 1
		}
		if (*TRbuObjIter)(unsafe.Pointer(pIter)).FeType == int32(RBU_PK_WITHOUT_ROWID) {
			zPk1 = _rbuWithoutRowidPK(tls, p, pIter)
			if zPk1 != 0 {
				zSql = _rbuMPrintf(tls, p, __ccgo_ts+32065, libc.VaList(bp+16, zSql, zPk1))
			}
		}
		Xsqlite3_test_control(tls, int32(SQLITE_TESTCTRL_IMPOSTER), libc.VaList(bp+16, (*Tsqlite3rbu)(unsafe.Pointer(p)).FdbMain, __ccgo_ts+6809, int32(1), tnum))
		if (*TRbuObjIter)(unsafe.Pointer(pIter)).FeType == int32(RBU_PK_WITHOUT_ROWID) {
			v2 = __ccgo_ts + 32072
		} else {
			v2 = __ccgo_ts + 1693
		}
		_rbuMPrintfExec(tls, p, (*Tsqlite3rbu)(unsafe.Pointer(p)).FdbMain, __ccgo_ts+32087, libc.VaList(bp+16, (*TRbuObjIter)(unsafe.Pointer(pIter)).FzTbl, zSql, v2))
		Xsqlite3_test_control(tls, int32(SQLITE_TESTCTRL_IMPOSTER), libc.VaList(bp+16, (*Tsqlite3rbu)(unsafe.Pointer(p)).FdbMain, __ccgo_ts+6809, 0, 0))
	}
}

// C documentation
//
//	/*
//	** This function creates the second imposter table used when writing to
//	** a table b-tree where the table has an external primary key. If the
//	** iterator passed as the second argument does not currently point to
//	** a table (not index) with an external primary key, this function is a
//	** no-op.
//	**
//	** Assuming the iterator does point to a table with an external PK, this
//	** function creates a WITHOUT ROWID imposter table named "rbu_imposter2"
//	** used to access that PK index. For example, if the target table is
//	** declared as follows:
//	**
//	**   CREATE TABLE t1(a, b TEXT, c REAL, PRIMARY KEY(b, c));
//	**
//	** then the imposter table schema is:
//	**
//	**   CREATE TABLE rbu_imposter2(c1 TEXT, c2 REAL, id INTEGER) WITHOUT ROWID;
//	**
//	*/
func _rbuCreateImposterTable2(tls *libc.TLS, p uintptr, pIter uintptr) {
	bp := tls.Alloc(64)
	defer tls.Free(64)
	var bDesc, bKey, iCid, tnum int32
	var zCollate, zCols, zComma, zIdx, zPk, v1 uintptr
	var _ /* pQuery at bp+0 */ uintptr
	var _ /* pXInfo at bp+8 */ uintptr
	_, _, _, _, _, _, _, _, _, _ = bDesc, bKey, iCid, tnum, zCollate, zCols, zComma, zIdx, zPk, v1
	if (*Tsqlite3rbu)(unsafe.Pointer(p)).Frc == SQLITE_OK && (*TRbuObjIter)(unsafe.Pointer(pIter)).FeType == int32(RBU_PK_EXTERNAL) {
		tnum = (*TRbuObjIter)(unsafe.Pointer(pIter)).FiPkTnum /* Root page of PK index */
		**(**uintptr)(__ccgo_up(bp)) = uintptr(0)             /* SELECT name ... WHERE rootpage = $tnum */
		zIdx = uintptr(0)                                     /* Name of PK index */
		**(**uintptr)(__ccgo_up(bp + 8)) = uintptr(0)         /* PRAGMA main.index_xinfo = $zIdx */
		zComma = __ccgo_ts + 1693
		zCols = uintptr(0) /* Used to build up list of table cols */
		zPk = uintptr(0)   /* Used to build up table PK declaration */
		/* Figure out the name of the primary key index for the current table.
		 ** This is needed for the argument to "PRAGMA index_xinfo". Set
		 ** zIdx to point to a nul-terminated string containing this name. */
		(*Tsqlite3rbu)(unsafe.Pointer(p)).Frc = _prepareAndCollectError(tls, (*Tsqlite3rbu)(unsafe.Pointer(p)).FdbMain, bp, p+64, __ccgo_ts+31856)
		if (*Tsqlite3rbu)(unsafe.Pointer(p)).Frc == SQLITE_OK {
			Xsqlite3_bind_int(tls, **(**uintptr)(__ccgo_up(bp)), int32(1), tnum)
			if int32(SQLITE_ROW) == Xsqlite3_step(tls, **(**uintptr)(__ccgo_up(bp))) {
				zIdx = Xsqlite3_column_text(tls, **(**uintptr)(__ccgo_up(bp)), 0)
			}
		}
		if zIdx != 0 {
			(*Tsqlite3rbu)(unsafe.Pointer(p)).Frc = _prepareFreeAndCollectError(tls, (*Tsqlite3rbu)(unsafe.Pointer(p)).FdbMain, bp+8, p+64, Xsqlite3_mprintf(tls, __ccgo_ts+31008, libc.VaList(bp+24, zIdx)))
		}
		_rbuFinalize(tls, p, **(**uintptr)(__ccgo_up(bp)))
		for (*Tsqlite3rbu)(unsafe.Pointer(p)).Frc == SQLITE_OK && int32(SQLITE_ROW) == Xsqlite3_step(tls, **(**uintptr)(__ccgo_up(bp + 8))) {
			bKey = Xsqlite3_column_int(tls, **(**uintptr)(__ccgo_up(bp + 8)), int32(5))
			if bKey != 0 {
				iCid = Xsqlite3_column_int(tls, **(**uintptr)(__ccgo_up(bp + 8)), int32(1))
				bDesc = Xsqlite3_column_int(tls, **(**uintptr)(__ccgo_up(bp + 8)), int32(3))
				zCollate = Xsqlite3_column_text(tls, **(**uintptr)(__ccgo_up(bp + 8)), int32(4))
				zCols = _rbuMPrintf(tls, p, __ccgo_ts+31906, libc.VaList(bp+24, zCols, zComma, iCid, **(**uintptr)(__ccgo_up((*TRbuObjIter)(unsafe.Pointer(pIter)).FazTblType + uintptr(iCid)*8)), zCollate))
				if bDesc != 0 {
					v1 = __ccgo_ts + 31248
				} else {
					v1 = __ccgo_ts + 1693
				}
				zPk = _rbuMPrintf(tls, p, __ccgo_ts+31928, libc.VaList(bp+24, zPk, zComma, iCid, v1))
				zComma = __ccgo_ts + 16207
			}
		}
		zCols = _rbuMPrintf(tls, p, __ccgo_ts+31938, libc.VaList(bp+24, zCols))
		_rbuFinalize(tls, p, **(**uintptr)(__ccgo_up(bp + 8)))
		Xsqlite3_test_control(tls, int32(SQLITE_TESTCTRL_IMPOSTER), libc.VaList(bp+24, (*Tsqlite3rbu)(unsafe.Pointer(p)).FdbMain, __ccgo_ts+6809, int32(1), tnum))
		_rbuMPrintfExec(tls, p, (*Tsqlite3rbu)(unsafe.Pointer(p)).FdbMain, __ccgo_ts+31953, libc.VaList(bp+24, zCols, zPk))
		Xsqlite3_test_control(tls, int32(SQLITE_TESTCTRL_IMPOSTER), libc.VaList(bp+24, (*Tsqlite3rbu)(unsafe.Pointer(p)).FdbMain, __ccgo_ts+6809, 0, 0))
	}
}

// C documentation
//
//	/*
//	** The RBU handle passed as the only argument has just been opened and
//	** the state database is empty. If this RBU handle was opened for an
//	** RBU vacuum operation, create the schema in the target db.
//	*/
func _rbuCreateTargetSchema(tls *libc.TLS, p uintptr) {
	bp := tls.Alloc(16)
	defer tls.Free(16)
	var i int32
	var zSql uintptr
	var _ /* pInsert at bp+8 */ uintptr
	var _ /* pSql at bp+0 */ uintptr
	_, _ = i, zSql
	**(**uintptr)(__ccgo_up(bp)) = uintptr(0)
	**(**uintptr)(__ccgo_up(bp + 8)) = uintptr(0)
	(*Tsqlite3rbu)(unsafe.Pointer(p)).Frc = Xsqlite3_exec(tls, (*Tsqlite3rbu)(unsafe.Pointer(p)).FdbMain, __ccgo_ts+33999, uintptr(0), uintptr(0), p+64)
	if (*Tsqlite3rbu)(unsafe.Pointer(p)).Frc == SQLITE_OK {
		(*Tsqlite3rbu)(unsafe.Pointer(p)).Frc = _prepareAndCollectError(tls, (*Tsqlite3rbu)(unsafe.Pointer(p)).FdbRbu, bp, p+64, __ccgo_ts+34024)
	}
	for (*Tsqlite3rbu)(unsafe.Pointer(p)).Frc == SQLITE_OK && Xsqlite3_step(tls, **(**uintptr)(__ccgo_up(bp))) == int32(SQLITE_ROW) {
		zSql = Xsqlite3_column_text(tls, **(**uintptr)(__ccgo_up(bp)), 0)
		(*Tsqlite3rbu)(unsafe.Pointer(p)).Frc = Xsqlite3_exec(tls, (*Tsqlite3rbu)(unsafe.Pointer(p)).FdbMain, zSql, uintptr(0), uintptr(0), p+64)
	}
	_rbuFinalize(tls, p, **(**uintptr)(__ccgo_up(bp)))
	if (*Tsqlite3rbu)(unsafe.Pointer(p)).Frc != SQLITE_OK {
		return
	}
	if (*Tsqlite3rbu)(unsafe.Pointer(p)).Frc == SQLITE_OK {
		(*Tsqlite3rbu)(unsafe.Pointer(p)).Frc = _prepareAndCollectError(tls, (*Tsqlite3rbu)(unsafe.Pointer(p)).FdbRbu, bp, p+64, __ccgo_ts+34132)
	}
	if (*Tsqlite3rbu)(unsafe.Pointer(p)).Frc == SQLITE_OK {
		(*Tsqlite3rbu)(unsafe.Pointer(p)).Frc = _prepareAndCollectError(tls, (*Tsqlite3rbu)(unsafe.Pointer(p)).FdbMain, bp+8, p+64, __ccgo_ts+34197)
	}
	for (*Tsqlite3rbu)(unsafe.Pointer(p)).Frc == SQLITE_OK && Xsqlite3_step(tls, **(**uintptr)(__ccgo_up(bp))) == int32(SQLITE_ROW) {
		i = 0
		for {
			if !(i < int32(5)) {
				break
			}
			Xsqlite3_bind_value(tls, **(**uintptr)(__ccgo_up(bp + 8)), i+int32(1), Xsqlite3_column_value(tls, **(**uintptr)(__ccgo_up(bp)), i))
			goto _1
		_1:
			;
			i = i + 1
		}
		Xsqlite3_step(tls, **(**uintptr)(__ccgo_up(bp + 8)))
		(*Tsqlite3rbu)(unsafe.Pointer(p)).Frc = Xsqlite3_reset(tls, **(**uintptr)(__ccgo_up(bp + 8)))
	}
	if (*Tsqlite3rbu)(unsafe.Pointer(p)).Frc == SQLITE_OK {
		(*Tsqlite3rbu)(unsafe.Pointer(p)).Frc = Xsqlite3_exec(tls, (*Tsqlite3rbu)(unsafe.Pointer(p)).FdbMain, __ccgo_ts+34241, uintptr(0), uintptr(0), p+64)
	}
	_rbuFinalize(tls, p, **(**uintptr)(__ccgo_up(bp)))
	_rbuFinalize(tls, p, **(**uintptr)(__ccgo_up(bp + 8)))
}

// C documentation
//
//	/*
//	** If there is a "*-oal" file in the file-system corresponding to the
//	** target database in the file-system, delete it. If an error occurs,
//	** leave an error code and error message in the rbu handle.
//	*/
func _rbuDeleteOalFile(tls *libc.TLS, p uintptr) {
	bp := tls.Alloc(32)
	defer tls.Free(32)
	var zOal uintptr
	var _ /* pVfs at bp+0 */ uintptr
	_ = zOal
	zOal = _rbuMPrintf(tls, p, __ccgo_ts+33741, libc.VaList(bp+16, (*Tsqlite3rbu)(unsafe.Pointer(p)).FzTarget))
	if zOal != 0 {
		**(**uintptr)(__ccgo_up(bp)) = uintptr(0)
		Xsqlite3_file_control(tls, (*Tsqlite3rbu)(unsafe.Pointer(p)).FdbMain, __ccgo_ts+6809, int32(SQLITE_FCNTL_VFS_POINTER), bp)
		(*(*func(*libc.TLS, uintptr, uintptr, int32) int32)(unsafe.Pointer(&struct{ uintptr }{(*Tsqlite3_vfs)(unsafe.Pointer(**(**uintptr)(__ccgo_up(bp)))).FxDelete})))(tls, **(**uintptr)(__ccgo_up(bp)), zOal, 0)
		Xsqlite3_free(tls, zOal)
	}
}

// C documentation
//
//	/*
//	** Return true if the database handle passed as the only argument
//	** was opened with the rbu_exclusive_checkpoint=1 URI parameter
//	** specified. Or false otherwise.
//	*/
func _rbuExclusiveCheckpoint(tls *libc.TLS, db uintptr) (r int32) {
	var zUri uintptr
	_ = zUri
	zUri = Xsqlite3_db_filename(tls, db, uintptr(0))
	return Xsqlite3_uri_boolean(tls, zUri, __ccgo_ts+33716, 0)
}

// C documentation
//
//	/*
//	** Finalize the statement passed as the second argument.
//	**
//	** If the sqlite3_finalize() call indicates that an error occurs, and the
//	** rbu handle error code is not already set, set the error code and error
//	** message accordingly.
//	*/
func _rbuFinalize(tls *libc.TLS, p uintptr, pStmt uintptr) {
	bp := tls.Alloc(16)
	defer tls.Free(16)
	var db uintptr
	var rc int32
	_, _ = db, rc
	db = Xsqlite3_db_handle(tls, pStmt)
	rc = Xsqlite3_finalize(tls, pStmt)
	if (*Tsqlite3rbu)(unsafe.Pointer(p)).Frc == SQLITE_OK && rc != SQLITE_OK {
		(*Tsqlite3rbu)(unsafe.Pointer(p)).Frc = rc
		(*Tsqlite3rbu)(unsafe.Pointer(p)).FzErrmsg = Xsqlite3_mprintf(tls, __ccgo_ts+3933, libc.VaList(bp+8, Xsqlite3_errmsg(tls, db)))
	}
}

// C documentation
//
//	/*
//	** Implementation of SQL scalar function rbu_fossil_delta().
//	**
//	** This function applies a fossil delta patch to a blob. Exactly two
//	** arguments must be passed to this function. The first is the blob to
//	** patch and the second the patch to apply. If no error occurs, this
//	** function returns the patched blob.
//	*/
func _rbuFossilDeltaFunc(tls *libc.TLS, context uintptr, argc int32, argv uintptr) {
	var aDelta, aOrig, aOut uintptr
	var nDelta, nOrig, nOut, nOut2 int32
	_, _, _, _, _, _, _ = aDelta, aOrig, aOut, nDelta, nOrig, nOut, nOut2
	_ = argc
	nOrig = Xsqlite3_value_bytes(tls, **(**uintptr)(__ccgo_up(argv)))
	aOrig = Xsqlite3_value_blob(tls, **(**uintptr)(__ccgo_up(argv)))
	nDelta = Xsqlite3_value_bytes(tls, **(**uintptr)(__ccgo_up(argv + 1*8)))
	aDelta = Xsqlite3_value_blob(tls, **(**uintptr)(__ccgo_up(argv + 1*8)))
	/* Figure out the size of the output */
	nOut = _rbuDeltaOutputSize(tls, aDelta, nDelta)
	if nOut < 0 {
		Xsqlite3_result_error(tls, context, __ccgo_ts+30260, -int32(1))
		return
	}
	aOut = Xsqlite3_malloc64(tls, libc.Uint64FromInt64(int64(nOut)+int64(1)))
	if aOut == uintptr(0) {
		Xsqlite3_result_error_nomem(tls, context)
	} else {
		nOut2 = _rbuDeltaApply(tls, aOrig, nOrig, aDelta, nDelta, aOut)
		if nOut2 != nOut {
			Xsqlite3_free(tls, aOut)
			Xsqlite3_result_error(tls, context, __ccgo_ts+30260, -int32(1))
		} else {
			Xsqlite3_result_blob(tls, context, aOut, nOut, __ccgo_fp(Xsqlite3_free))
		}
	}
}

// C documentation
//
//	/*
//	** Set output variable *ppStmt to point to an UPDATE statement that may
//	** be used to update the imposter table for the main table b-tree of the
//	** table object that pIter currently points to, assuming that the
//	** rbu_control column of the data_xyz table contains zMask.
//	**
//	** If the zMask string does not specify any columns to update, then this
//	** is not an error. Output variable *ppStmt is set to NULL in this case.
//	*/
func _rbuGetUpdateStmt(tls *libc.TLS, p uintptr, pIter uintptr, zMask uintptr, ppStmt uintptr) (r int32) {
	bp := tls.Alloc(48)
	defer tls.Free(48)
	var nUp int32
	var pUp, pp, zPrefix, zSet, zUpdate, zWhere uintptr
	_, _, _, _, _, _, _ = nUp, pUp, pp, zPrefix, zSet, zUpdate, zWhere
	pUp = uintptr(0)
	nUp = 0
	/* In case an error occurs */
	**(**uintptr)(__ccgo_up(ppStmt)) = uintptr(0)
	/* Search for an existing statement. If one is found, shift it to the front
	 ** of the LRU queue and return immediately. Otherwise, leave nUp pointing
	 ** to the number of statements currently in the cache and pUp to the
	 ** last object in the list.  */
	pp = pIter + 184
	for {
		if !(**(**uintptr)(__ccgo_up(pp)) != 0) {
			break
		}
		pUp = **(**uintptr)(__ccgo_up(pp))
		if libc.Xstrcmp(tls, (*TRbuUpdateStmt)(unsafe.Pointer(pUp)).FzMask, zMask) == 0 {
			**(**uintptr)(__ccgo_up(pp)) = (*TRbuUpdateStmt)(unsafe.Pointer(pUp)).FpNext
			(*TRbuUpdateStmt)(unsafe.Pointer(pUp)).FpNext = (*TRbuObjIter)(unsafe.Pointer(pIter)).FpRbuUpdate
			(*TRbuObjIter)(unsafe.Pointer(pIter)).FpRbuUpdate = pUp
			**(**uintptr)(__ccgo_up(ppStmt)) = (*TRbuUpdateStmt)(unsafe.Pointer(pUp)).FpUpdate
			return SQLITE_OK
		}
		nUp = nUp + 1
		goto _1
	_1:
		;
		pp = **(**uintptr)(__ccgo_up(pp)) + 16
	}
	if nUp >= int32(SQLITE_RBU_UPDATE_CACHESIZE) {
		pp = pIter + 184
		for {
			if !(**(**uintptr)(__ccgo_up(pp)) != pUp) {
				break
			}
			goto _2
		_2:
			;
			pp = **(**uintptr)(__ccgo_up(pp)) + 16
		}
		**(**uintptr)(__ccgo_up(pp)) = uintptr(0)
		Xsqlite3_finalize(tls, (*TRbuUpdateStmt)(unsafe.Pointer(pUp)).FpUpdate)
		(*TRbuUpdateStmt)(unsafe.Pointer(pUp)).FpUpdate = uintptr(0)
	} else {
		pUp = _rbuMalloc(tls, p, libc.Int64FromUint64(uint64(24)+libc.Uint64FromInt32((*TRbuObjIter)(unsafe.Pointer(pIter)).FnTblCol)+uint64(1)))
	}
	if pUp != 0 {
		zWhere = _rbuObjIterGetWhere(tls, p, pIter)
		zSet = _rbuObjIterGetSetlist(tls, p, pIter, zMask)
		zUpdate = uintptr(0)
		(*TRbuUpdateStmt)(unsafe.Pointer(pUp)).FzMask = pUp + 1*24
		libc.Xmemcpy(tls, (*TRbuUpdateStmt)(unsafe.Pointer(pUp)).FzMask, zMask, libc.Uint64FromInt32((*TRbuObjIter)(unsafe.Pointer(pIter)).FnTblCol))
		(*TRbuUpdateStmt)(unsafe.Pointer(pUp)).FpNext = (*TRbuObjIter)(unsafe.Pointer(pIter)).FpRbuUpdate
		(*TRbuObjIter)(unsafe.Pointer(pIter)).FpRbuUpdate = pUp
		if zSet != 0 {
			zPrefix = __ccgo_ts + 1693
			if (*TRbuObjIter)(unsafe.Pointer(pIter)).FeType != int32(RBU_PK_VTAB) {
				zPrefix = __ccgo_ts + 32688
			}
			zUpdate = Xsqlite3_mprintf(tls, __ccgo_ts+33349, libc.VaList(bp+8, zPrefix, (*TRbuObjIter)(unsafe.Pointer(pIter)).FzTbl, zSet, zWhere))
			(*Tsqlite3rbu)(unsafe.Pointer(p)).Frc = _prepareFreeAndCollectError(tls, (*Tsqlite3rbu)(unsafe.Pointer(p)).FdbMain, pUp+8, p+64, zUpdate)
			**(**uintptr)(__ccgo_up(ppStmt)) = (*TRbuUpdateStmt)(unsafe.Pointer(pUp)).FpUpdate
		}
		Xsqlite3_free(tls, zWhere)
		Xsqlite3_free(tls, zSet)
	}
	return (*Tsqlite3rbu)(unsafe.Pointer(p)).Frc
}

// C documentation
//
//	/*
//	** Increment the schema cookie of the main database opened by p->dbMain.
//	**
//	** Or, if this is an RBU vacuum, set the schema cookie of the main db
//	** opened by p->dbMain to one more than the schema cookie of the main
//	** db opened by p->dbRbu.
//	*/
func _rbuIncrSchemaCookie(tls *libc.TLS, p uintptr) {
	bp := tls.Alloc(32)
	defer tls.Free(32)
	var dbread, v1 uintptr
	var iCookie int32
	var _ /* pStmt at bp+0 */ uintptr
	_, _, _ = dbread, iCookie, v1
	if (*Tsqlite3rbu)(unsafe.Pointer(p)).Frc == SQLITE_OK {
		if (*Tsqlite3rbu)(unsafe.Pointer(p)).FzTarget == uintptr(0) {
			v1 = (*Tsqlite3rbu)(unsafe.Pointer(p)).FdbRbu
		} else {
			v1 = (*Tsqlite3rbu)(unsafe.Pointer(p)).FdbMain
		}
		dbread = v1
		iCookie = int32(1000000)
		(*Tsqlite3rbu)(unsafe.Pointer(p)).Frc = _prepareAndCollectError(tls, dbread, bp, p+64, __ccgo_ts+33755)
		if (*Tsqlite3rbu)(unsafe.Pointer(p)).Frc == SQLITE_OK {
			/* Coverage: it may be that this sqlite3_step() cannot fail. There
			 ** is already a transaction open, so the prepared statement cannot
			 ** throw an SQLITE_SCHEMA exception. The only database page the
			 ** statement reads is page 1, which is guaranteed to be in the cache.
			 ** And no memory allocations are required.  */
			if int32(SQLITE_ROW) == Xsqlite3_step(tls, **(**uintptr)(__ccgo_up(bp))) {
				iCookie = Xsqlite3_column_int(tls, **(**uintptr)(__ccgo_up(bp)), 0)
			}
			_rbuFinalize(tls, p, **(**uintptr)(__ccgo_up(bp)))
		}
		if (*Tsqlite3rbu)(unsafe.Pointer(p)).Frc == SQLITE_OK {
			_rbuMPrintfExec(tls, p, (*Tsqlite3rbu)(unsafe.Pointer(p)).FdbMain, __ccgo_ts+33777, libc.VaList(bp+16, iCookie+int32(1)))
		}
	}
}

// C documentation
//
//	/*
//	** This user-defined SQL function is invoked with a single argument - the
//	** name of a table expected to appear in the target database. It returns
//	** the number of auxilliary indexes on the table.
//	*/
func _rbuIndexCntFunc(tls *libc.TLS, pCtx uintptr, nVal int32, apVal uintptr) {
	bp := tls.Alloc(32)
	defer tls.Free(32)
	var db, p, v1 uintptr
	var nIndex, rc int32
	var _ /* pStmt at bp+0 */ uintptr
	var _ /* zErrmsg at bp+8 */ uintptr
	_, _, _, _, _ = db, nIndex, p, rc, v1
	p = Xsqlite3_user_data(tls, pCtx)
	**(**uintptr)(__ccgo_up(bp)) = uintptr(0)
	**(**uintptr)(__ccgo_up(bp + 8)) = uintptr(0)
	if (*Tsqlite3rbu)(unsafe.Pointer(p)).FzTarget == uintptr(0) {
		v1 = (*Tsqlite3rbu)(unsafe.Pointer(p)).FdbRbu
	} else {
		v1 = (*Tsqlite3rbu)(unsafe.Pointer(p)).FdbMain
	}
	db = v1
	_ = nVal
	rc = _prepareFreeAndCollectError(tls, db, bp, bp+8, Xsqlite3_mprintf(tls, __ccgo_ts+34330, libc.VaList(bp+24, Xsqlite3_value_text(tls, **(**uintptr)(__ccgo_up(apVal))))))
	if rc != SQLITE_OK {
		Xsqlite3_result_error(tls, pCtx, **(**uintptr)(__ccgo_up(bp + 8)), -int32(1))
	} else {
		nIndex = 0
		if int32(SQLITE_ROW) == Xsqlite3_step(tls, **(**uintptr)(__ccgo_up(bp))) {
			nIndex = Xsqlite3_column_int(tls, **(**uintptr)(__ccgo_up(bp)), 0)
		}
		rc = Xsqlite3_finalize(tls, **(**uintptr)(__ccgo_up(bp)))
		if rc == SQLITE_OK {
			Xsqlite3_result_int(tls, pCtx, nIndex)
		} else {
			Xsqlite3_result_error(tls, pCtx, Xsqlite3_errmsg(tls, db), -int32(1))
		}
	}
	Xsqlite3_free(tls, **(**uintptr)(__ccgo_up(bp + 8)))
}

// C documentation
//
//	/*
//	** If the RBU database contains the rbu_count table, use it to initialize
//	** the sqlite3rbu.nPhaseOneStep variable. The schema of the rbu_count table
//	** is assumed to contain the same columns as:
//	**
//	**   CREATE TABLE rbu_count(tbl TEXT PRIMARY KEY, cnt INTEGER) WITHOUT ROWID;
//	**
//	** There should be one row in the table for each data_xxx table in the
//	** database. The 'tbl' column should contain the name of a data_xxx table,
//	** and the cnt column the number of rows it contains.
//	**
//	** sqlite3rbu.nPhaseOneStep is initialized to the sum of (1 + nIndex) * cnt
//	** for all rows in the rbu_count table, where nIndex is the number of
//	** indexes on the corresponding target database table.
//	*/
func _rbuInitPhaseOneSteps(tls *libc.TLS, p uintptr) {
	bp := tls.Alloc(16)
	defer tls.Free(16)
	var bExists int32
	var _ /* pStmt at bp+0 */ uintptr
	_ = bExists
	if (*Tsqlite3rbu)(unsafe.Pointer(p)).Frc == SQLITE_OK {
		**(**uintptr)(__ccgo_up(bp)) = uintptr(0)
		bExists = 0 /* True if rbu_count exists */
		(*Tsqlite3rbu)(unsafe.Pointer(p)).FnPhaseOneStep = int64(-int32(1))
		(*Tsqlite3rbu)(unsafe.Pointer(p)).Frc = Xsqlite3_create_function(tls, (*Tsqlite3rbu)(unsafe.Pointer(p)).FdbRbu, __ccgo_ts+34402, int32(1), int32(SQLITE_UTF8), p, __ccgo_fp(_rbuIndexCntFunc), uintptr(0), uintptr(0))
		/* Check for the rbu_count table. If it does not exist, or if an error
		 ** occurs, nPhaseOneStep will be left set to -1. */
		if (*Tsqlite3rbu)(unsafe.Pointer(p)).Frc == SQLITE_OK {
			(*Tsqlite3rbu)(unsafe.Pointer(p)).Frc = _prepareAndCollectError(tls, (*Tsqlite3rbu)(unsafe.Pointer(p)).FdbRbu, bp, p+64, __ccgo_ts+34416)
		}
		if (*Tsqlite3rbu)(unsafe.Pointer(p)).Frc == SQLITE_OK {
			if int32(SQLITE_ROW) == Xsqlite3_step(tls, **(**uintptr)(__ccgo_up(bp))) {
				bExists = int32(1)
			}
			(*Tsqlite3rbu)(unsafe.Pointer(p)).Frc = Xsqlite3_finalize(tls, **(**uintptr)(__ccgo_up(bp)))
		}
		if (*Tsqlite3rbu)(unsafe.Pointer(p)).Frc == SQLITE_OK && bExists != 0 {
			(*Tsqlite3rbu)(unsafe.Pointer(p)).Frc = _prepareAndCollectError(tls, (*Tsqlite3rbu)(unsafe.Pointer(p)).FdbRbu, bp, p+64, __ccgo_ts+34473)
			if (*Tsqlite3rbu)(unsafe.Pointer(p)).Frc == SQLITE_OK {
				if int32(SQLITE_ROW) == Xsqlite3_step(tls, **(**uintptr)(__ccgo_up(bp))) {
					(*Tsqlite3rbu)(unsafe.Pointer(p)).FnPhaseOneStep = Xsqlite3_column_int64(tls, **(**uintptr)(__ccgo_up(bp)), 0)
				}
				(*Tsqlite3rbu)(unsafe.Pointer(p)).Frc = Xsqlite3_finalize(tls, **(**uintptr)(__ccgo_up(bp)))
			}
		}
	}
}

// C documentation
//
//	/*
//	** Allocate an RbuState object and load the contents of the rbu_state
//	** table into it. Return a pointer to the new object. It is the
//	** responsibility of the caller to eventually free the object using
//	** sqlite3_free().
//	**
//	** If an error occurs, leave an error code and message in the rbu handle
//	** and return NULL.
//	*/
func _rbuLoadState(tls *libc.TLS, p uintptr) (r uintptr) {
	bp := tls.Alloc(32)
	defer tls.Free(32)
	var pRet uintptr
	var rc2 int32
	var _ /* pStmt at bp+0 */ uintptr
	var _ /* rc at bp+8 */ int32
	_, _ = pRet, rc2
	pRet = uintptr(0)
	**(**uintptr)(__ccgo_up(bp)) = uintptr(0)
	pRet = _rbuMalloc(tls, p, int64(80))
	if pRet == uintptr(0) {
		return uintptr(0)
	}
	**(**int32)(__ccgo_up(bp + 8)) = _prepareFreeAndCollectError(tls, (*Tsqlite3rbu)(unsafe.Pointer(p)).FdbRbu, bp, p+64, Xsqlite3_mprintf(tls, __ccgo_ts+33379, libc.VaList(bp+24, p+48)))
	for **(**int32)(__ccgo_up(bp + 8)) == SQLITE_OK && int32(SQLITE_ROW) == Xsqlite3_step(tls, **(**uintptr)(__ccgo_up(bp))) {
		switch Xsqlite3_column_int(tls, **(**uintptr)(__ccgo_up(bp)), 0) {
		case int32(RBU_STATE_STAGE):
			(*TRbuState)(unsafe.Pointer(pRet)).FeStage = Xsqlite3_column_int(tls, **(**uintptr)(__ccgo_up(bp)), int32(1))
			if (*TRbuState)(unsafe.Pointer(pRet)).FeStage != int32(RBU_STAGE_OAL) && (*TRbuState)(unsafe.Pointer(pRet)).FeStage != int32(RBU_STAGE_MOVE) && (*TRbuState)(unsafe.Pointer(pRet)).FeStage != int32(RBU_STAGE_CKPT) {
				(*Tsqlite3rbu)(unsafe.Pointer(p)).Frc = int32(SQLITE_CORRUPT)
			}
		case int32(RBU_STATE_TBL):
			(*TRbuState)(unsafe.Pointer(pRet)).FzTbl = _rbuStrndup(tls, Xsqlite3_column_text(tls, **(**uintptr)(__ccgo_up(bp)), int32(1)), bp+8)
		case int32(RBU_STATE_IDX):
			(*TRbuState)(unsafe.Pointer(pRet)).FzIdx = _rbuStrndup(tls, Xsqlite3_column_text(tls, **(**uintptr)(__ccgo_up(bp)), int32(1)), bp+8)
		case int32(RBU_STATE_ROW):
			(*TRbuState)(unsafe.Pointer(pRet)).FnRow = Xsqlite3_column_int(tls, **(**uintptr)(__ccgo_up(bp)), int32(1))
		case int32(RBU_STATE_PROGRESS):
			(*TRbuState)(unsafe.Pointer(pRet)).FnProgress = Xsqlite3_column_int64(tls, **(**uintptr)(__ccgo_up(bp)), int32(1))
		case int32(RBU_STATE_CKPT):
			(*TRbuState)(unsafe.Pointer(pRet)).FiWalCksum = Xsqlite3_column_int64(tls, **(**uintptr)(__ccgo_up(bp)), int32(1))
		case int32(RBU_STATE_COOKIE):
			(*TRbuState)(unsafe.Pointer(pRet)).FiCookie = libc.Uint32FromInt64(Xsqlite3_column_int64(tls, **(**uintptr)(__ccgo_up(bp)), int32(1)))
		case int32(RBU_STATE_OALSZ):
			(*TRbuState)(unsafe.Pointer(pRet)).FiOalSz = Xsqlite3_column_int64(tls, **(**uintptr)(__ccgo_up(bp)), int32(1))
		case int32(RBU_STATE_PHASEONESTEP):
			(*TRbuState)(unsafe.Pointer(pRet)).FnPhaseOneStep = Xsqlite3_column_int64(tls, **(**uintptr)(__ccgo_up(bp)), int32(1))
		case int32(RBU_STATE_DATATBL):
			(*TRbuState)(unsafe.Pointer(pRet)).FzDataTbl = _rbuStrndup(tls, Xsqlite3_column_text(tls, **(**uintptr)(__ccgo_up(bp)), int32(1)), bp+8)
		default:
			**(**int32)(__ccgo_up(bp + 8)) = int32(SQLITE_CORRUPT)
			break
		}
	}
	rc2 = Xsqlite3_finalize(tls, **(**uintptr)(__ccgo_up(bp)))
	if **(**int32)(__ccgo_up(bp + 8)) == SQLITE_OK {
		**(**int32)(__ccgo_up(bp + 8)) = rc2
	}
	(*Tsqlite3rbu)(unsafe.Pointer(p)).Frc = **(**int32)(__ccgo_up(bp + 8))
	return pRet
}

// C documentation
//
//	/*
//	** Take an EXCLUSIVE lock on the database file. Return SQLITE_OK if
//	** successful, or an SQLite error code otherwise.
//	*/
func _rbuLockDatabase(tls *libc.TLS, db uintptr) (r int32) {
	bp := tls.Alloc(16)
	defer tls.Free(16)
	var rc int32
	var _ /* fd at bp+0 */ uintptr
	_ = rc
	rc = SQLITE_OK
	**(**uintptr)(__ccgo_up(bp)) = uintptr(0)
	Xsqlite3_file_control(tls, db, __ccgo_ts+6809, int32(RBU_ZIPVFS_CTRL_FILE_POINTER), bp)
	if **(**uintptr)(__ccgo_up(bp)) != 0 {
		Xsqlite3_file_control(tls, db, __ccgo_ts+6809, int32(SQLITE_FCNTL_FILE_POINTER), bp)
		rc = (*(*func(*libc.TLS, uintptr, int32) int32)(unsafe.Pointer(&struct{ uintptr }{(*Tsqlite3_io_methods)(unsafe.Pointer((*Tsqlite3_file)(unsafe.Pointer(**(**uintptr)(__ccgo_up(bp)))).FpMethods)).FxLock})))(tls, **(**uintptr)(__ccgo_up(bp)), int32(SQLITE_LOCK_SHARED))
		if rc == SQLITE_OK {
			rc = (*(*func(*libc.TLS, uintptr, int32) int32)(unsafe.Pointer(&struct{ uintptr }{(*Tsqlite3_io_methods)(unsafe.Pointer((*Tsqlite3_file)(unsafe.Pointer(**(**uintptr)(__ccgo_up(bp)))).FpMethods)).FxUnlock})))(tls, **(**uintptr)(__ccgo_up(bp)), SQLITE_LOCK_NONE)
		}
		Xsqlite3_file_control(tls, db, __ccgo_ts+6809, int32(RBU_ZIPVFS_CTRL_FILE_POINTER), bp)
	} else {
		Xsqlite3_file_control(tls, db, __ccgo_ts+6809, int32(SQLITE_FCNTL_FILE_POINTER), bp)
	}
	if rc == SQLITE_OK && (*Tsqlite3_file)(unsafe.Pointer(**(**uintptr)(__ccgo_up(bp)))).FpMethods != 0 {
		rc = (*(*func(*libc.TLS, uintptr, int32) int32)(unsafe.Pointer(&struct{ uintptr }{(*Tsqlite3_io_methods)(unsafe.Pointer((*Tsqlite3_file)(unsafe.Pointer(**(**uintptr)(__ccgo_up(bp)))).FpMethods)).FxLock})))(tls, **(**uintptr)(__ccgo_up(bp)), int32(SQLITE_LOCK_SHARED))
		if rc == SQLITE_OK {
			rc = (*(*func(*libc.TLS, uintptr, int32) int32)(unsafe.Pointer(&struct{ uintptr }{(*Tsqlite3_io_methods)(unsafe.Pointer((*Tsqlite3_file)(unsafe.Pointer(**(**uintptr)(__ccgo_up(bp)))).FpMethods)).FxLock})))(tls, **(**uintptr)(__ccgo_up(bp)), int32(SQLITE_LOCK_EXCLUSIVE))
		}
	}
	return rc
}

// C documentation
//
//	/*
//	** The RBU handle is currently in RBU_STAGE_OAL state, with a SHARED lock
//	** on the database file. This proc moves the *-oal file to the *-wal path,
//	** then reopens the database file (this time in vanilla, non-oal, WAL mode).
//	** If an error occurs, leave an error code and error message in the rbu
//	** handle.
//	*/
func _rbuMoveOalFile(tls *libc.TLS, p uintptr) {
	bp := tls.Alloc(16)
	defer tls.Free(16)
	var dbMain, zBase, zMove, zOal, zWal uintptr
	_, _, _, _, _ = dbMain, zBase, zMove, zOal, zWal
	zBase = Xsqlite3_db_filename(tls, (*Tsqlite3rbu)(unsafe.Pointer(p)).FdbMain, __ccgo_ts+6809)
	zMove = zBase
	if (*Tsqlite3rbu)(unsafe.Pointer(p)).FzTarget == uintptr(0) {
		zMove = Xsqlite3_db_filename(tls, (*Tsqlite3rbu)(unsafe.Pointer(p)).FdbRbu, __ccgo_ts+6809)
	}
	zOal = Xsqlite3_mprintf(tls, __ccgo_ts+33741, libc.VaList(bp+8, zMove))
	zWal = Xsqlite3_mprintf(tls, __ccgo_ts+33748, libc.VaList(bp+8, zMove))
	if zWal == uintptr(0) || zOal == uintptr(0) {
		(*Tsqlite3rbu)(unsafe.Pointer(p)).Frc = int32(SQLITE_NOMEM)
	} else {
		/* Move the *-oal file to *-wal. At this point connection p->db is
		 ** holding a SHARED lock on the target database file (because it is
		 ** in WAL mode). So no other connection may be writing the db.
		 **
		 ** In order to ensure that there are no database readers, an EXCLUSIVE
		 ** lock is obtained here before the *-oal is moved to *-wal.
		 */
		dbMain = uintptr(0)
		_rbuFileSuffix3(tls, zBase, zWal)
		_rbuFileSuffix3(tls, zBase, zOal)
		/* Re-open the databases. */
		_rbuObjIterFinalize(tls, p+88)
		Xsqlite3_close(tls, (*Tsqlite3rbu)(unsafe.Pointer(p)).FdbRbu)
		Xsqlite3_close(tls, (*Tsqlite3rbu)(unsafe.Pointer(p)).FdbMain)
		(*Tsqlite3rbu)(unsafe.Pointer(p)).FdbMain = uintptr(0)
		(*Tsqlite3rbu)(unsafe.Pointer(p)).FdbRbu = uintptr(0)
		dbMain = _rbuOpenDbhandle(tls, p, (*Tsqlite3rbu)(unsafe.Pointer(p)).FzTarget, int32(1))
		if dbMain != 0 {
			(*Tsqlite3rbu)(unsafe.Pointer(p)).Frc = _rbuLockDatabase(tls, dbMain)
		}
		if (*Tsqlite3rbu)(unsafe.Pointer(p)).Frc == SQLITE_OK {
			(*Tsqlite3rbu)(unsafe.Pointer(p)).Frc = (*(*func(*libc.TLS, uintptr, uintptr, uintptr) int32)(unsafe.Pointer(&struct{ uintptr }{(*Tsqlite3rbu)(unsafe.Pointer(p)).FxRename})))(tls, (*Tsqlite3rbu)(unsafe.Pointer(p)).FpRenameArg, zOal, zWal)
		}
		if (*Tsqlite3rbu)(unsafe.Pointer(p)).Frc != SQLITE_OK || (*Tsqlite3rbu)(unsafe.Pointer(p)).FzTarget == uintptr(0) || _rbuExclusiveCheckpoint(tls, dbMain) == 0 {
			Xsqlite3_close(tls, dbMain)
			dbMain = uintptr(0)
		}
		if (*Tsqlite3rbu)(unsafe.Pointer(p)).Frc == SQLITE_OK {
			_rbuOpenDatabase(tls, p, dbMain, uintptr(0))
			_rbuSetupCheckpoint(tls, p, uintptr(0))
		}
	}
	Xsqlite3_free(tls, zWal)
	Xsqlite3_free(tls, zOal)
}

// C documentation
//
//	/*
//	** This is a helper function for rbuObjIterCacheTableInfo(). It populates
//	** the pIter->abIndexed[] array.
//	*/
func _rbuObjIterCacheIndexedCols(tls *libc.TLS, p uintptr, pIter uintptr) {
	bp := tls.Alloc(32)
	defer tls.Free(32)
	var bIndex, bPartial, iCid int32
	var zIdx uintptr
	var _ /* pList at bp+0 */ uintptr
	var _ /* pXInfo at bp+8 */ uintptr
	_, _, _, _ = bIndex, bPartial, iCid, zIdx
	**(**uintptr)(__ccgo_up(bp)) = uintptr(0)
	bIndex = 0
	if (*Tsqlite3rbu)(unsafe.Pointer(p)).Frc == SQLITE_OK {
		libc.Xmemcpy(tls, (*TRbuObjIter)(unsafe.Pointer(pIter)).FabIndexed, (*TRbuObjIter)(unsafe.Pointer(pIter)).FabTblPk, uint64(1)*libc.Uint64FromInt32((*TRbuObjIter)(unsafe.Pointer(pIter)).FnTblCol))
		(*Tsqlite3rbu)(unsafe.Pointer(p)).Frc = _prepareFreeAndCollectError(tls, (*Tsqlite3rbu)(unsafe.Pointer(p)).FdbMain, bp, p+64, Xsqlite3_mprintf(tls, __ccgo_ts+30980, libc.VaList(bp+24, (*TRbuObjIter)(unsafe.Pointer(pIter)).FzTbl)))
	}
	(*TRbuObjIter)(unsafe.Pointer(pIter)).FnIndex = 0
	for (*Tsqlite3rbu)(unsafe.Pointer(p)).Frc == SQLITE_OK && int32(SQLITE_ROW) == Xsqlite3_step(tls, **(**uintptr)(__ccgo_up(bp))) {
		zIdx = Xsqlite3_column_text(tls, **(**uintptr)(__ccgo_up(bp)), int32(1))
		bPartial = Xsqlite3_column_int(tls, **(**uintptr)(__ccgo_up(bp)), int32(4))
		**(**uintptr)(__ccgo_up(bp + 8)) = uintptr(0)
		if zIdx == uintptr(0) {
			break
		}
		if bPartial != 0 {
			libc.Xmemset(tls, (*TRbuObjIter)(unsafe.Pointer(pIter)).FabIndexed, int32(0x01), uint64(1)*libc.Uint64FromInt32((*TRbuObjIter)(unsafe.Pointer(pIter)).FnTblCol))
		}
		(*Tsqlite3rbu)(unsafe.Pointer(p)).Frc = _prepareFreeAndCollectError(tls, (*Tsqlite3rbu)(unsafe.Pointer(p)).FdbMain, bp+8, p+64, Xsqlite3_mprintf(tls, __ccgo_ts+31008, libc.VaList(bp+24, zIdx)))
		for (*Tsqlite3rbu)(unsafe.Pointer(p)).Frc == SQLITE_OK && int32(SQLITE_ROW) == Xsqlite3_step(tls, **(**uintptr)(__ccgo_up(bp + 8))) {
			iCid = Xsqlite3_column_int(tls, **(**uintptr)(__ccgo_up(bp + 8)), int32(1))
			if iCid >= 0 {
				**(**Tu8)(__ccgo_up((*TRbuObjIter)(unsafe.Pointer(pIter)).FabIndexed + uintptr(iCid))) = uint8(1)
			}
			if iCid == -int32(2) {
				libc.Xmemset(tls, (*TRbuObjIter)(unsafe.Pointer(pIter)).FabIndexed, int32(0x01), uint64(1)*libc.Uint64FromInt32((*TRbuObjIter)(unsafe.Pointer(pIter)).FnTblCol))
			}
		}
		_rbuFinalize(tls, p, **(**uintptr)(__ccgo_up(bp + 8)))
		bIndex = int32(1)
		(*TRbuObjIter)(unsafe.Pointer(pIter)).FnIndex = (*TRbuObjIter)(unsafe.Pointer(pIter)).FnIndex + 1
	}
	if (*TRbuObjIter)(unsafe.Pointer(pIter)).FeType == int32(RBU_PK_WITHOUT_ROWID) {
		/* "PRAGMA index_list" includes the main PK b-tree */
		(*TRbuObjIter)(unsafe.Pointer(pIter)).FnIndex = (*TRbuObjIter)(unsafe.Pointer(pIter)).FnIndex - 1
	}
	_rbuFinalize(tls, p, **(**uintptr)(__ccgo_up(bp)))
	if bIndex == 0 {
		(*TRbuObjIter)(unsafe.Pointer(pIter)).FabIndexed = uintptr(0)
	}
}

// C documentation
//
//	/*
//	** If they are not already populated, populate the pIter->azTblCol[],
//	** pIter->abTblPk[], pIter->nTblCol and pIter->bRowid variables according to
//	** the table (not index) that the iterator currently points to.
//	**
//	** Return SQLITE_OK if successful, or an SQLite error code otherwise. If
//	** an error does occur, an error code and error message are also left in
//	** the RBU handle.
//	*/
func _rbuObjIterCacheTableInfo(tls *libc.TLS, p uintptr, pIter uintptr) (r int32) {
	bp := tls.Alloc(48)
	defer tls.Free(48)
	var bNotNull, bRbuRowid, i, iOrder, iPk, nCol, t, v2 int32
	var t1, zCopy, zName, zName1, zType, v3 uintptr
	var _ /* iTnum at bp+8 */ int32
	var _ /* pStmt at bp+0 */ uintptr
	_, _, _, _, _, _, _, _, _, _, _, _, _, _ = bNotNull, bRbuRowid, i, iOrder, iPk, nCol, t, t1, zCopy, zName, zName1, zType, v2, v3
	if (*TRbuObjIter)(unsafe.Pointer(pIter)).FazTblCol == uintptr(0) {
		**(**uintptr)(__ccgo_up(bp)) = uintptr(0)
		nCol = 0      /* for() loop iterator variable */
		bRbuRowid = 0 /* If input table has column "rbu_rowid" */
		iOrder = 0
		**(**int32)(__ccgo_up(bp + 8)) = 0
		/* Figure out the type of table this step will deal with. */
		_rbuTableType(tls, p, (*TRbuObjIter)(unsafe.Pointer(pIter)).FzTbl, pIter+72, bp+8, pIter+108)
		if (*Tsqlite3rbu)(unsafe.Pointer(p)).Frc == SQLITE_OK && (*TRbuObjIter)(unsafe.Pointer(pIter)).FeType == RBU_PK_NOTABLE {
			(*Tsqlite3rbu)(unsafe.Pointer(p)).Frc = int32(SQLITE_ERROR)
			(*Tsqlite3rbu)(unsafe.Pointer(p)).FzErrmsg = Xsqlite3_mprintf(tls, __ccgo_ts+21332, libc.VaList(bp+24, (*TRbuObjIter)(unsafe.Pointer(pIter)).FzTbl))
		}
		if (*Tsqlite3rbu)(unsafe.Pointer(p)).Frc != 0 {
			return (*Tsqlite3rbu)(unsafe.Pointer(p)).Frc
		}
		if (*TRbuObjIter)(unsafe.Pointer(pIter)).FzIdx == uintptr(0) {
			(*TRbuObjIter)(unsafe.Pointer(pIter)).FiTnum = **(**int32)(__ccgo_up(bp + 8))
		}
		/* Populate the azTblCol[] and nTblCol variables based on the columns
		 ** of the input table. Ignore any input table columns that begin with
		 ** "rbu_".  */
		(*Tsqlite3rbu)(unsafe.Pointer(p)).Frc = _prepareFreeAndCollectError(tls, (*Tsqlite3rbu)(unsafe.Pointer(p)).FdbRbu, bp, p+64, Xsqlite3_mprintf(tls, __ccgo_ts+31037, libc.VaList(bp+24, (*TRbuObjIter)(unsafe.Pointer(pIter)).FzDataTbl)))
		if (*Tsqlite3rbu)(unsafe.Pointer(p)).Frc == SQLITE_OK {
			nCol = Xsqlite3_column_count(tls, **(**uintptr)(__ccgo_up(bp)))
			_rbuAllocateIterArrays(tls, p, pIter, nCol)
		}
		i = 0
		for {
			if !((*Tsqlite3rbu)(unsafe.Pointer(p)).Frc == SQLITE_OK && i < nCol) {
				break
			}
			zName = Xsqlite3_column_name(tls, **(**uintptr)(__ccgo_up(bp)), i)
			if Xsqlite3_strnicmp(tls, __ccgo_ts+31056, zName, int32(4)) != 0 {
				zCopy = _rbuStrndup(tls, zName, p+56)
				**(**int32)(__ccgo_up((*TRbuObjIter)(unsafe.Pointer(pIter)).FaiSrcOrder + uintptr((*TRbuObjIter)(unsafe.Pointer(pIter)).FnTblCol)*4)) = (*TRbuObjIter)(unsafe.Pointer(pIter)).FnTblCol
				v3 = pIter + 16
				v2 = *(*int32)(unsafe.Pointer(v3))
				*(*int32)(unsafe.Pointer(v3)) = *(*int32)(unsafe.Pointer(v3)) + 1
				**(**uintptr)(__ccgo_up((*TRbuObjIter)(unsafe.Pointer(pIter)).FazTblCol + uintptr(v2)*8)) = zCopy
			} else {
				if 0 == Xsqlite3_stricmp(tls, __ccgo_ts+31061, zName) {
					bRbuRowid = int32(1)
				}
			}
			goto _1
		_1:
			;
			i = i + 1
		}
		Xsqlite3_finalize(tls, **(**uintptr)(__ccgo_up(bp)))
		**(**uintptr)(__ccgo_up(bp)) = uintptr(0)
		if (*Tsqlite3rbu)(unsafe.Pointer(p)).Frc == SQLITE_OK && libc.BoolInt32((*Tsqlite3rbu)(unsafe.Pointer(p)).FzTarget == uintptr(0)) == 0 && bRbuRowid != libc.BoolInt32((*TRbuObjIter)(unsafe.Pointer(pIter)).FeType == int32(RBU_PK_VTAB) || (*TRbuObjIter)(unsafe.Pointer(pIter)).FeType == int32(RBU_PK_NONE)) {
			(*Tsqlite3rbu)(unsafe.Pointer(p)).Frc = int32(SQLITE_ERROR)
			if bRbuRowid != 0 {
				v3 = __ccgo_ts + 31071
			} else {
				v3 = __ccgo_ts + 31084
			}
			(*Tsqlite3rbu)(unsafe.Pointer(p)).FzErrmsg = Xsqlite3_mprintf(tls, __ccgo_ts+31093, libc.VaList(bp+24, (*TRbuObjIter)(unsafe.Pointer(pIter)).FzDataTbl, v3))
		}
		/* Check that all non-HIDDEN columns in the destination table are also
		 ** present in the input table. Populate the abTblPk[], azTblType[] and
		 ** aiTblOrder[] arrays at the same time.  */
		if (*Tsqlite3rbu)(unsafe.Pointer(p)).Frc == SQLITE_OK {
			(*Tsqlite3rbu)(unsafe.Pointer(p)).Frc = _prepareFreeAndCollectError(tls, (*Tsqlite3rbu)(unsafe.Pointer(p)).FdbMain, bp, p+64, Xsqlite3_mprintf(tls, __ccgo_ts+31122, libc.VaList(bp+24, (*TRbuObjIter)(unsafe.Pointer(pIter)).FzTbl)))
		}
		for (*Tsqlite3rbu)(unsafe.Pointer(p)).Frc == SQLITE_OK && int32(SQLITE_ROW) == Xsqlite3_step(tls, **(**uintptr)(__ccgo_up(bp))) {
			zName1 = Xsqlite3_column_text(tls, **(**uintptr)(__ccgo_up(bp)), int32(1))
			if zName1 == uintptr(0) {
				break
			} /* An OOM - finalize() below returns S_NOMEM */
			i = iOrder
			for {
				if !(i < (*TRbuObjIter)(unsafe.Pointer(pIter)).FnTblCol) {
					break
				}
				if 0 == libc.Xstrcmp(tls, zName1, **(**uintptr)(__ccgo_up((*TRbuObjIter)(unsafe.Pointer(pIter)).FazTblCol + uintptr(i)*8))) {
					break
				}
				goto _5
			_5:
				;
				i = i + 1
			}
			if i == (*TRbuObjIter)(unsafe.Pointer(pIter)).FnTblCol {
				(*Tsqlite3rbu)(unsafe.Pointer(p)).Frc = int32(SQLITE_ERROR)
				(*Tsqlite3rbu)(unsafe.Pointer(p)).FzErrmsg = Xsqlite3_mprintf(tls, __ccgo_ts+31144, libc.VaList(bp+24, (*TRbuObjIter)(unsafe.Pointer(pIter)).FzDataTbl, zName1))
			} else {
				iPk = Xsqlite3_column_int(tls, **(**uintptr)(__ccgo_up(bp)), int32(5))
				bNotNull = Xsqlite3_column_int(tls, **(**uintptr)(__ccgo_up(bp)), int32(3))
				zType = Xsqlite3_column_text(tls, **(**uintptr)(__ccgo_up(bp)), int32(2))
				if i != iOrder {
					t = **(**int32)(__ccgo_up((*TRbuObjIter)(unsafe.Pointer(pIter)).FaiSrcOrder + uintptr(i)*4))
					**(**int32)(__ccgo_up((*TRbuObjIter)(unsafe.Pointer(pIter)).FaiSrcOrder + uintptr(i)*4)) = **(**int32)(__ccgo_up((*TRbuObjIter)(unsafe.Pointer(pIter)).FaiSrcOrder + uintptr(iOrder)*4))
					**(**int32)(__ccgo_up((*TRbuObjIter)(unsafe.Pointer(pIter)).FaiSrcOrder + uintptr(iOrder)*4)) = t
					t1 = **(**uintptr)(__ccgo_up((*TRbuObjIter)(unsafe.Pointer(pIter)).FazTblCol + uintptr(i)*8))
					**(**uintptr)(__ccgo_up((*TRbuObjIter)(unsafe.Pointer(pIter)).FazTblCol + uintptr(i)*8)) = **(**uintptr)(__ccgo_up((*TRbuObjIter)(unsafe.Pointer(pIter)).FazTblCol + uintptr(iOrder)*8))
					**(**uintptr)(__ccgo_up((*TRbuObjIter)(unsafe.Pointer(pIter)).FazTblCol + uintptr(iOrder)*8)) = t1
				}
				**(**uintptr)(__ccgo_up((*TRbuObjIter)(unsafe.Pointer(pIter)).FazTblType + uintptr(iOrder)*8)) = _rbuStrndup(tls, zType, p+56)
				**(**Tu8)(__ccgo_up((*TRbuObjIter)(unsafe.Pointer(pIter)).FabTblPk + uintptr(iOrder))) = libc.Uint8FromInt32(iPk)
				**(**Tu8)(__ccgo_up((*TRbuObjIter)(unsafe.Pointer(pIter)).FabNotNull + uintptr(iOrder))) = libc.BoolUint8(libc.Uint8FromInt32(bNotNull) != 0 || iPk != 0)
				iOrder = iOrder + 1
			}
		}
		_rbuFinalize(tls, p, **(**uintptr)(__ccgo_up(bp)))
		_rbuObjIterCacheIndexedCols(tls, p, pIter)
	}
	return (*Tsqlite3rbu)(unsafe.Pointer(p)).Frc
}

// C documentation
//
//	/*
//	** Initialize the iterator structure passed as the second argument.
//	**
//	** If no error occurs, SQLITE_OK is returned and the iterator is left
//	** pointing to the first entry. Otherwise, an error code and message is
//	** left in the RBU handle passed as the first argument. A copy of the
//	** error code is returned.
//	*/
func _rbuObjIterFirst(tls *libc.TLS, p uintptr, pIter uintptr) (r int32) {
	bp := tls.Alloc(16)
	defer tls.Free(16)
	var rc int32
	var v1 uintptr
	_, _ = rc, v1
	libc.Xmemset(tls, pIter, 0, uint64(192))
	if (*Tsqlite3rbu)(unsafe.Pointer(p)).FzTarget == uintptr(0) {
		v1 = __ccgo_ts + 30452
	} else {
		v1 = __ccgo_ts + 1693
	}
	rc = _prepareFreeAndCollectError(tls, (*Tsqlite3rbu)(unsafe.Pointer(p)).FdbRbu, pIter, p+64, Xsqlite3_mprintf(tls, __ccgo_ts+30493, libc.VaList(bp+8, v1)))
	if rc == SQLITE_OK {
		rc = _prepareAndCollectError(tls, (*Tsqlite3rbu)(unsafe.Pointer(p)).FdbMain, pIter+8, p+64, __ccgo_ts+30643)
	}
	(*TRbuObjIter)(unsafe.Pointer(pIter)).FbCleanup = int32(1)
	(*Tsqlite3rbu)(unsafe.Pointer(p)).Frc = rc
	return _rbuObjIterNext(tls, p, pIter)
}

// C documentation
//
//	/*
//	** This function constructs and returns a pointer to a nul-terminated
//	** string containing some SQL clause or list based on one or more of the
//	** column names currently stored in the pIter->azTblCol[] array.
//	*/
func _rbuObjIterGetCollist(tls *libc.TLS, p uintptr, pIter uintptr) (r uintptr) {
	bp := tls.Alloc(32)
	defer tls.Free(32)
	var i int32
	var z, zList, zSep uintptr
	_, _, _, _ = i, z, zList, zSep
	zList = uintptr(0)
	zSep = __ccgo_ts + 1693
	i = 0
	for {
		if !(i < (*TRbuObjIter)(unsafe.Pointer(pIter)).FnTblCol) {
			break
		}
		z = **(**uintptr)(__ccgo_up((*TRbuObjIter)(unsafe.Pointer(pIter)).FazTblCol + uintptr(i)*8))
		zList = _rbuMPrintf(tls, p, __ccgo_ts+31171, libc.VaList(bp+8, zList, zSep, z))
		zSep = __ccgo_ts + 16207
		goto _1
	_1:
		;
		i = i + 1
	}
	return zList
}

// C documentation
//
//	/*
//	** This function is used to create a SELECT list (the list of SQL
//	** expressions that follows a SELECT keyword) for a SELECT statement
//	** used to read from an data_xxx or rbu_tmp_xxx table while updating the
//	** index object currently indicated by the iterator object passed as the
//	** second argument. A "PRAGMA index_xinfo = <idxname>" statement is used
//	** to obtain the required information.
//	**
//	** If the index is of the following form:
//	**
//	**   CREATE INDEX i1 ON t1(c, b COLLATE nocase);
//	**
//	** and "t1" is a table with an explicit INTEGER PRIMARY KEY column
//	** "ipk", the returned string is:
//	**
//	**   "`c` COLLATE 'BINARY', `b` COLLATE 'NOCASE', `ipk` COLLATE 'BINARY'"
//	**
//	** As well as the returned string, three other malloc'd strings are
//	** returned via output parameters. As follows:
//	**
//	**   pzImposterCols: ...
//	**   pzImposterPk: ...
//	**   pzWhere: ...
//	*/
func _rbuObjIterGetIndexCols(tls *libc.TLS, p uintptr, pIter uintptr, pzImposterCols uintptr, pzImposterPk uintptr, pzWhere uintptr, pnBind uintptr) (r uintptr) {
	bp := tls.Alloc(64)
	defer tls.Free(64)
	var bDesc, i, iCid, iSeq, nBind, rc, rc2 int32
	var zAnd, zCol, zCollate, zCom, zImpCols, zImpPK, zOrder, zRet, zType, zWhere, v2 uintptr
	var _ /* pXInfo at bp+0 */ uintptr
	_, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _ = bDesc, i, iCid, iSeq, nBind, rc, rc2, zAnd, zCol, zCollate, zCom, zImpCols, zImpPK, zOrder, zRet, zType, zWhere, v2
	rc = (*Tsqlite3rbu)(unsafe.Pointer(p)).Frc /* sqlite3_finalize() return code */
	zRet = uintptr(0)                          /* String to return */
	zImpCols = uintptr(0)                      /* String to return via *pzImposterCols */
	zImpPK = uintptr(0)                        /* String to return via *pzImposterPK */
	zWhere = uintptr(0)                        /* String to return via *pzWhere */
	nBind = 0                                  /* Value to return via *pnBind */
	zCom = __ccgo_ts + 1693                    /* Set to ", " later on */
	zAnd = __ccgo_ts + 1693                    /* Set to " AND " later on */
	**(**uintptr)(__ccgo_up(bp)) = uintptr(0)  /* PRAGMA index_xinfo = ? */
	if rc == SQLITE_OK {
		rc = _prepareFreeAndCollectError(tls, (*Tsqlite3rbu)(unsafe.Pointer(p)).FdbMain, bp, p+64, Xsqlite3_mprintf(tls, __ccgo_ts+31008, libc.VaList(bp+16, (*TRbuObjIter)(unsafe.Pointer(pIter)).FzIdx)))
	}
	for rc == SQLITE_OK && int32(SQLITE_ROW) == Xsqlite3_step(tls, **(**uintptr)(__ccgo_up(bp))) {
		iCid = Xsqlite3_column_int(tls, **(**uintptr)(__ccgo_up(bp)), int32(1))
		bDesc = Xsqlite3_column_int(tls, **(**uintptr)(__ccgo_up(bp)), int32(3))
		zCollate = Xsqlite3_column_text(tls, **(**uintptr)(__ccgo_up(bp)), int32(4))
		zCol = uintptr(0)
		if iCid == -int32(2) {
			iSeq = Xsqlite3_column_int(tls, **(**uintptr)(__ccgo_up(bp)), 0)
			zRet = Xsqlite3_mprintf(tls, __ccgo_ts+31490, libc.VaList(bp+16, zRet, zCom, (**(**TRbuSpan)(__ccgo_up((*TRbuObjIter)(unsafe.Pointer(pIter)).FaIdxCol + uintptr(iSeq)*16))).FnSpan, (**(**TRbuSpan)(__ccgo_up((*TRbuObjIter)(unsafe.Pointer(pIter)).FaIdxCol + uintptr(iSeq)*16))).FzSpan, zCollate))
			zType = __ccgo_ts + 1693
		} else {
			if iCid < 0 {
				/* An integer primary key. If the table has an explicit IPK, use
				 ** its name. Otherwise, use "rbu_rowid".  */
				if (*TRbuObjIter)(unsafe.Pointer(pIter)).FeType == int32(RBU_PK_IPK) {
					i = 0
					for {
						if !(libc.Int32FromUint8(**(**Tu8)(__ccgo_up((*TRbuObjIter)(unsafe.Pointer(pIter)).FabTblPk + uintptr(i)))) == 0) {
							break
						}
						goto _1
					_1:
						;
						i = i + 1
					}
					zCol = **(**uintptr)(__ccgo_up((*TRbuObjIter)(unsafe.Pointer(pIter)).FazTblCol + uintptr(i)*8))
				} else {
					if (*Tsqlite3rbu)(unsafe.Pointer(p)).FzTarget == uintptr(0) {
						zCol = __ccgo_ts + 31331
					} else {
						zCol = __ccgo_ts + 31061
					}
				}
				zType = __ccgo_ts + 1167
			} else {
				zCol = **(**uintptr)(__ccgo_up((*TRbuObjIter)(unsafe.Pointer(pIter)).FazTblCol + uintptr(iCid)*8))
				zType = **(**uintptr)(__ccgo_up((*TRbuObjIter)(unsafe.Pointer(pIter)).FazTblType + uintptr(iCid)*8))
			}
			zRet = Xsqlite3_mprintf(tls, __ccgo_ts+31512, libc.VaList(bp+16, zRet, zCom, zCol, zCollate))
		}
		if (*TRbuObjIter)(unsafe.Pointer(pIter)).FbUnique == 0 || Xsqlite3_column_int(tls, **(**uintptr)(__ccgo_up(bp)), int32(5)) != 0 {
			if bDesc != 0 {
				v2 = __ccgo_ts + 31248
			} else {
				v2 = __ccgo_ts + 1693
			}
			zOrder = v2
			zImpPK = Xsqlite3_mprintf(tls, __ccgo_ts+31532, libc.VaList(bp+16, zImpPK, zCom, nBind, zCol, zOrder))
		}
		zImpCols = Xsqlite3_mprintf(tls, __ccgo_ts+31553, libc.VaList(bp+16, zImpCols, zCom, nBind, zCol, zType, zCollate))
		zWhere = Xsqlite3_mprintf(tls, __ccgo_ts+31586, libc.VaList(bp+16, zWhere, zAnd, nBind, zCol))
		if zRet == uintptr(0) || zImpPK == uintptr(0) || zImpCols == uintptr(0) || zWhere == uintptr(0) {
			rc = int32(SQLITE_NOMEM)
		}
		zCom = __ccgo_ts + 16207
		zAnd = __ccgo_ts + 23618
		nBind = nBind + 1
	}
	rc2 = Xsqlite3_finalize(tls, **(**uintptr)(__ccgo_up(bp)))
	if rc == SQLITE_OK {
		rc = rc2
	}
	if rc != SQLITE_OK {
		Xsqlite3_free(tls, zRet)
		Xsqlite3_free(tls, zImpCols)
		Xsqlite3_free(tls, zImpPK)
		Xsqlite3_free(tls, zWhere)
		zRet = uintptr(0)
		zImpCols = uintptr(0)
		zImpPK = uintptr(0)
		zWhere = uintptr(0)
		(*Tsqlite3rbu)(unsafe.Pointer(p)).Frc = rc
	}
	**(**uintptr)(__ccgo_up(pzImposterCols)) = zImpCols
	**(**uintptr)(__ccgo_up(pzImposterPk)) = zImpPK
	**(**uintptr)(__ccgo_up(pzWhere)) = zWhere
	**(**int32)(__ccgo_up(pnBind)) = nBind
	return zRet
}

// C documentation
//
//	/*
//	** Assuming the current table columns are "a", "b" and "c", and the zObj
//	** paramter is passed "old", return a string of the form:
//	**
//	**     "old.a, old.b, old.b"
//	**
//	** With the column names escaped.
//	**
//	** For tables with implicit rowids - RBU_PK_EXTERNAL and RBU_PK_NONE, append
//	** the text ", old._rowid_" to the returned value.
//	*/
func _rbuObjIterGetOldlist(tls *libc.TLS, p uintptr, pIter uintptr, zObj uintptr) (r uintptr) {
	bp := tls.Alloc(48)
	defer tls.Free(48)
	var i int32
	var zCol, zList, zS uintptr
	_, _, _, _ = i, zCol, zList, zS
	zList = uintptr(0)
	if (*Tsqlite3rbu)(unsafe.Pointer(p)).Frc == SQLITE_OK && (*TRbuObjIter)(unsafe.Pointer(pIter)).FabIndexed != 0 {
		zS = __ccgo_ts + 1693
		i = 0
		for {
			if !(i < (*TRbuObjIter)(unsafe.Pointer(pIter)).FnTblCol) {
				break
			}
			if **(**Tu8)(__ccgo_up((*TRbuObjIter)(unsafe.Pointer(pIter)).FabIndexed + uintptr(i))) != 0 {
				zCol = **(**uintptr)(__ccgo_up((*TRbuObjIter)(unsafe.Pointer(pIter)).FazTblCol + uintptr(i)*8))
				zList = Xsqlite3_mprintf(tls, __ccgo_ts+31610, libc.VaList(bp+8, zList, zS, zObj, zCol))
			} else {
				zList = Xsqlite3_mprintf(tls, __ccgo_ts+31622, libc.VaList(bp+8, zList, zS))
			}
			zS = __ccgo_ts + 16207
			if zList == uintptr(0) {
				(*Tsqlite3rbu)(unsafe.Pointer(p)).Frc = int32(SQLITE_NOMEM)
				break
			}
			goto _1
		_1:
			;
			i = i + 1
		}
		/* For a table with implicit rowids, append "old._rowid_" to the list. */
		if (*TRbuObjIter)(unsafe.Pointer(pIter)).FeType == int32(RBU_PK_EXTERNAL) || (*TRbuObjIter)(unsafe.Pointer(pIter)).FeType == int32(RBU_PK_NONE) {
			zList = _rbuMPrintf(tls, p, __ccgo_ts+31631, libc.VaList(bp+8, zList, zObj))
		}
	}
	return zList
}

// C documentation
//
//	/*
//	** Return a comma separated list of the quoted PRIMARY KEY column names,
//	** in order, for the current table. Before each column name, add the text
//	** zPre. After each column name, add the zPost text. Use zSeparator as
//	** the separator text (usually ", ").
//	*/
func _rbuObjIterGetPkList(tls *libc.TLS, p uintptr, pIter uintptr, zPre uintptr, zSeparator uintptr, zPost uintptr) (r uintptr) {
	bp := tls.Alloc(48)
	defer tls.Free(48)
	var i, iPk int32
	var zCol, zRet, zSep uintptr
	_, _, _, _, _ = i, iPk, zCol, zRet, zSep
	iPk = int32(1)
	zRet = uintptr(0)
	zSep = __ccgo_ts + 1693
	for int32(1) != 0 {
		i = 0
		for {
			if !(i < (*TRbuObjIter)(unsafe.Pointer(pIter)).FnTblCol) {
				break
			}
			if libc.Int32FromUint8(**(**Tu8)(__ccgo_up((*TRbuObjIter)(unsafe.Pointer(pIter)).FabTblPk + uintptr(i)))) == iPk {
				zCol = **(**uintptr)(__ccgo_up((*TRbuObjIter)(unsafe.Pointer(pIter)).FazTblCol + uintptr(i)*8))
				zRet = _rbuMPrintf(tls, p, __ccgo_ts+31180, libc.VaList(bp+8, zRet, zSep, zPre, zCol, zPost))
				zSep = zSeparator
				break
			}
			goto _1
		_1:
			;
			i = i + 1
		}
		if i == (*TRbuObjIter)(unsafe.Pointer(pIter)).FnTblCol {
			break
		}
		iPk = iPk + 1
	}
	return zRet
}

// C documentation
//
//	/*
//	** Return an expression that can be used in a WHERE clause to match the
//	** primary key of the current table. For example, if the table is:
//	**
//	**   CREATE TABLE t1(a, b, c, PRIMARY KEY(b, c));
//	**
//	** Return the string:
//	**
//	**   "b = ?1 AND c = ?2"
//	*/
func _rbuObjIterGetWhere(tls *libc.TLS, p uintptr, pIter uintptr) (r uintptr) {
	bp := tls.Alloc(48)
	defer tls.Free(48)
	var i, i1 int32
	var zCol, zList, zSep, zSep1 uintptr
	_, _, _, _, _, _ = i, i1, zCol, zList, zSep, zSep1
	zList = uintptr(0)
	if (*TRbuObjIter)(unsafe.Pointer(pIter)).FeType == int32(RBU_PK_VTAB) || (*TRbuObjIter)(unsafe.Pointer(pIter)).FeType == int32(RBU_PK_NONE) {
		zList = _rbuMPrintf(tls, p, __ccgo_ts+31646, libc.VaList(bp+8, (*TRbuObjIter)(unsafe.Pointer(pIter)).FnTblCol+int32(1)))
	} else {
		if (*TRbuObjIter)(unsafe.Pointer(pIter)).FeType == int32(RBU_PK_EXTERNAL) {
			zSep = __ccgo_ts + 1693
			i = 0
			for {
				if !(i < (*TRbuObjIter)(unsafe.Pointer(pIter)).FnTblCol) {
					break
				}
				if **(**Tu8)(__ccgo_up((*TRbuObjIter)(unsafe.Pointer(pIter)).FabTblPk + uintptr(i))) != 0 {
					zList = _rbuMPrintf(tls, p, __ccgo_ts+31660, libc.VaList(bp+8, zList, zSep, i, i+int32(1)))
					zSep = __ccgo_ts + 23618
				}
				goto _1
			_1:
				;
				i = i + 1
			}
			zList = _rbuMPrintf(tls, p, __ccgo_ts+31672, libc.VaList(bp+8, zList))
		} else {
			zSep1 = __ccgo_ts + 1693
			i1 = 0
			for {
				if !(i1 < (*TRbuObjIter)(unsafe.Pointer(pIter)).FnTblCol) {
					break
				}
				if **(**Tu8)(__ccgo_up((*TRbuObjIter)(unsafe.Pointer(pIter)).FabTblPk + uintptr(i1))) != 0 {
					zCol = **(**uintptr)(__ccgo_up((*TRbuObjIter)(unsafe.Pointer(pIter)).FazTblCol + uintptr(i1)*8))
					zList = _rbuMPrintf(tls, p, __ccgo_ts+31722, libc.VaList(bp+8, zList, zSep1, zCol, i1+int32(1)))
					zSep1 = __ccgo_ts + 23618
				}
				goto _2
			_2:
				;
				i1 = i1 + 1
			}
		}
	}
	return zList
}

// C documentation
//
//	/*
//	** Advance the iterator to the next position.
//	**
//	** If no error occurs, SQLITE_OK is returned and the iterator is left
//	** pointing to the next entry. Otherwise, an error code and message is
//	** left in the RBU handle passed as the first argument. A copy of the
//	** error code is returned.
//	*/
func _rbuObjIterNext(tls *libc.TLS, p uintptr, pIter uintptr) (r int32) {
	var pIdx uintptr
	var rc, v1 int32
	_, _, _ = pIdx, rc, v1
	rc = (*Tsqlite3rbu)(unsafe.Pointer(p)).Frc
	if rc == SQLITE_OK {
		/* Free any SQLite statements used while processing the previous object */
		_rbuObjIterClearStatements(tls, pIter)
		if (*TRbuObjIter)(unsafe.Pointer(pIter)).FzIdx == uintptr(0) {
			rc = Xsqlite3_exec(tls, (*Tsqlite3rbu)(unsafe.Pointer(p)).FdbMain, __ccgo_ts+30281, uintptr(0), uintptr(0), p+64)
		}
		if rc == SQLITE_OK {
			if (*TRbuObjIter)(unsafe.Pointer(pIter)).FbCleanup != 0 {
				_rbuObjIterFreeCols(tls, pIter)
				(*TRbuObjIter)(unsafe.Pointer(pIter)).FbCleanup = 0
				rc = Xsqlite3_step(tls, (*TRbuObjIter)(unsafe.Pointer(pIter)).FpTblIter)
				if rc != int32(SQLITE_ROW) {
					rc = _resetAndCollectError(tls, (*TRbuObjIter)(unsafe.Pointer(pIter)).FpTblIter, p+64)
					(*TRbuObjIter)(unsafe.Pointer(pIter)).FzTbl = uintptr(0)
					(*TRbuObjIter)(unsafe.Pointer(pIter)).FzDataTbl = uintptr(0)
				} else {
					(*TRbuObjIter)(unsafe.Pointer(pIter)).FzTbl = Xsqlite3_column_text(tls, (*TRbuObjIter)(unsafe.Pointer(pIter)).FpTblIter, 0)
					(*TRbuObjIter)(unsafe.Pointer(pIter)).FzDataTbl = Xsqlite3_column_text(tls, (*TRbuObjIter)(unsafe.Pointer(pIter)).FpTblIter, int32(1))
					if (*TRbuObjIter)(unsafe.Pointer(pIter)).FzDataTbl != 0 && (*TRbuObjIter)(unsafe.Pointer(pIter)).FzTbl != 0 {
						v1 = SQLITE_OK
					} else {
						v1 = int32(SQLITE_NOMEM)
					}
					rc = v1
				}
			} else {
				if (*TRbuObjIter)(unsafe.Pointer(pIter)).FzIdx == uintptr(0) {
					pIdx = (*TRbuObjIter)(unsafe.Pointer(pIter)).FpIdxIter
					rc = Xsqlite3_bind_text(tls, pIdx, int32(1), (*TRbuObjIter)(unsafe.Pointer(pIter)).FzTbl, -int32(1), libc.UintptrFromInt32(0))
				}
				if rc == SQLITE_OK {
					rc = Xsqlite3_step(tls, (*TRbuObjIter)(unsafe.Pointer(pIter)).FpIdxIter)
					if rc != int32(SQLITE_ROW) {
						rc = _resetAndCollectError(tls, (*TRbuObjIter)(unsafe.Pointer(pIter)).FpIdxIter, p+64)
						(*TRbuObjIter)(unsafe.Pointer(pIter)).FbCleanup = int32(1)
						(*TRbuObjIter)(unsafe.Pointer(pIter)).FzIdx = uintptr(0)
					} else {
						(*TRbuObjIter)(unsafe.Pointer(pIter)).FzIdx = Xsqlite3_column_text(tls, (*TRbuObjIter)(unsafe.Pointer(pIter)).FpIdxIter, 0)
						(*TRbuObjIter)(unsafe.Pointer(pIter)).FiTnum = Xsqlite3_column_int(tls, (*TRbuObjIter)(unsafe.Pointer(pIter)).FpIdxIter, int32(1))
						(*TRbuObjIter)(unsafe.Pointer(pIter)).FbUnique = Xsqlite3_column_int(tls, (*TRbuObjIter)(unsafe.Pointer(pIter)).FpIdxIter, int32(2))
						if (*TRbuObjIter)(unsafe.Pointer(pIter)).FzIdx != 0 {
							v1 = SQLITE_OK
						} else {
							v1 = int32(SQLITE_NOMEM)
						}
						rc = v1
					}
				}
			}
		}
	}
	if rc != SQLITE_OK {
		_rbuObjIterFinalize(tls, pIter)
		(*Tsqlite3rbu)(unsafe.Pointer(p)).Frc = rc
	}
	return rc
}

// C documentation
//
//	/*
//	** Ensure that the SQLite statement handles required to update the
//	** target database object currently indicated by the iterator passed
//	** as the second argument are available.
//	*/
func _rbuObjIterPrepareAll(tls *libc.TLS, p uintptr, pIter uintptr, nOffset int32) (r int32) {
	bp := tls.Alloc(128)
	defer tls.Free(128)
	var bRbuRowid, tnum int32
	var pz, zBind, zBindings, zCollist, zIdx, zLimit, zNewlist, zOldlist, zOrder, zPart, zRbuRowid, zRbuRowid1, zSql, zStart, zStart1, zTbl, zTbl1, zWhere1, zWrite, v1, v2, v3 uintptr
	var _ /* nBind at bp+24 */ int32
	var _ /* zImposterCols at bp+0 */ uintptr
	var _ /* zImposterPK at bp+8 */ uintptr
	var _ /* zWhere at bp+16 */ uintptr
	_, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _ = bRbuRowid, pz, tnum, zBind, zBindings, zCollist, zIdx, zLimit, zNewlist, zOldlist, zOrder, zPart, zRbuRowid, zRbuRowid1, zSql, zStart, zStart1, zTbl, zTbl1, zWhere1, zWrite, v1, v2, v3
	if (*TRbuObjIter)(unsafe.Pointer(pIter)).FpSelect == uintptr(0) && _rbuObjIterCacheTableInfo(tls, p, pIter) == SQLITE_OK {
		tnum = (*TRbuObjIter)(unsafe.Pointer(pIter)).FiTnum
		zCollist = uintptr(0) /* List of indexed columns */
		pz = p + 64
		zIdx = (*TRbuObjIter)(unsafe.Pointer(pIter)).FzIdx
		zLimit = uintptr(0)
		if nOffset != 0 {
			zLimit = Xsqlite3_mprintf(tls, __ccgo_ts+32242, libc.VaList(bp+40, nOffset))
			if !(zLimit != 0) {
				(*Tsqlite3rbu)(unsafe.Pointer(p)).Frc = int32(SQLITE_NOMEM)
			}
		}
		if zIdx != 0 {
			zTbl = (*TRbuObjIter)(unsafe.Pointer(pIter)).FzTbl
			**(**uintptr)(__ccgo_up(bp)) = uintptr(0)      /* Columns for imposter table */
			**(**uintptr)(__ccgo_up(bp + 8)) = uintptr(0)  /* Primary key declaration for imposter */
			**(**uintptr)(__ccgo_up(bp + 16)) = uintptr(0) /* WHERE clause on PK columns */
			zBind = uintptr(0)
			zPart = uintptr(0)
			**(**int32)(__ccgo_up(bp + 24)) = 0
			zPart = _rbuObjIterGetIndexWhere(tls, p, pIter)
			zCollist = _rbuObjIterGetIndexCols(tls, p, pIter, bp, bp+8, bp+16, bp+24)
			zBind = _rbuObjIterGetBindlist(tls, p, **(**int32)(__ccgo_up(bp + 24)))
			/* Create the imposter table used to write to this index. */
			Xsqlite3_test_control(tls, int32(SQLITE_TESTCTRL_IMPOSTER), libc.VaList(bp+40, (*Tsqlite3rbu)(unsafe.Pointer(p)).FdbMain, __ccgo_ts+6809, 0, int32(1)))
			Xsqlite3_test_control(tls, int32(SQLITE_TESTCTRL_IMPOSTER), libc.VaList(bp+40, (*Tsqlite3rbu)(unsafe.Pointer(p)).FdbMain, __ccgo_ts+6809, int32(1), tnum))
			_rbuMPrintfExec(tls, p, (*Tsqlite3rbu)(unsafe.Pointer(p)).FdbMain, __ccgo_ts+32262, libc.VaList(bp+40, zTbl, **(**uintptr)(__ccgo_up(bp)), **(**uintptr)(__ccgo_up(bp + 8))))
			Xsqlite3_test_control(tls, int32(SQLITE_TESTCTRL_IMPOSTER), libc.VaList(bp+40, (*Tsqlite3rbu)(unsafe.Pointer(p)).FdbMain, __ccgo_ts+6809, 0, 0))
			/* Create the statement to insert index entries */
			(*TRbuObjIter)(unsafe.Pointer(pIter)).FnCol = **(**int32)(__ccgo_up(bp + 24))
			if (*Tsqlite3rbu)(unsafe.Pointer(p)).Frc == SQLITE_OK {
				(*Tsqlite3rbu)(unsafe.Pointer(p)).Frc = _prepareFreeAndCollectError(tls, (*Tsqlite3rbu)(unsafe.Pointer(p)).FdbMain, pIter+136, p+64, Xsqlite3_mprintf(tls, __ccgo_ts+32327, libc.VaList(bp+40, zTbl, zBind)))
			}
			/* And to delete index entries */
			if libc.BoolInt32((*Tsqlite3rbu)(unsafe.Pointer(p)).FzTarget == uintptr(0)) == 0 && (*Tsqlite3rbu)(unsafe.Pointer(p)).Frc == SQLITE_OK {
				(*Tsqlite3rbu)(unsafe.Pointer(p)).Frc = _prepareFreeAndCollectError(tls, (*Tsqlite3rbu)(unsafe.Pointer(p)).FdbMain, pIter+144, p+64, Xsqlite3_mprintf(tls, __ccgo_ts+32363, libc.VaList(bp+40, zTbl, **(**uintptr)(__ccgo_up(bp + 16)))))
			}
			/* Create the SELECT statement to read keys in sorted order */
			if (*Tsqlite3rbu)(unsafe.Pointer(p)).Frc == SQLITE_OK {
				if (*Tsqlite3rbu)(unsafe.Pointer(p)).FzTarget == uintptr(0) {
					zStart = uintptr(0)
					if nOffset != 0 {
						zStart = _rbuVacuumIndexStart(tls, p, pIter)
						if zStart != 0 {
							Xsqlite3_free(tls, zLimit)
							zLimit = uintptr(0)
						}
					}
					if zStart != 0 {
						if zPart != 0 {
							v2 = __ccgo_ts + 32397
						} else {
							v2 = __ccgo_ts + 32401
						}
						v1 = v2
					} else {
						v1 = __ccgo_ts + 1693
					}
					zSql = Xsqlite3_mprintf(tls, __ccgo_ts+32407, libc.VaList(bp+40, zCollist, (*TRbuObjIter)(unsafe.Pointer(pIter)).FzDataTbl, zPart, v1, zStart, zCollist, zLimit))
					Xsqlite3_free(tls, zStart)
				} else {
					if (*TRbuObjIter)(unsafe.Pointer(pIter)).FeType == int32(RBU_PK_EXTERNAL) || (*TRbuObjIter)(unsafe.Pointer(pIter)).FeType == int32(RBU_PK_NONE) {
						zSql = Xsqlite3_mprintf(tls, __ccgo_ts+32468, libc.VaList(bp+40, zCollist, p+48, (*TRbuObjIter)(unsafe.Pointer(pIter)).FzDataTbl, zPart, zCollist, zLimit))
					} else {
						if zPart != 0 {
							v1 = __ccgo_ts + 32397
						} else {
							v1 = __ccgo_ts + 32401
						}
						zSql = Xsqlite3_mprintf(tls, __ccgo_ts+32529, libc.VaList(bp+40, zCollist, p+48, (*TRbuObjIter)(unsafe.Pointer(pIter)).FzDataTbl, zPart, zCollist, (*TRbuObjIter)(unsafe.Pointer(pIter)).FzDataTbl, zPart, v1, zCollist, zLimit))
					}
				}
				if (*Tsqlite3rbu)(unsafe.Pointer(p)).Frc == SQLITE_OK {
					(*Tsqlite3rbu)(unsafe.Pointer(p)).Frc = _prepareFreeAndCollectError(tls, (*Tsqlite3rbu)(unsafe.Pointer(p)).FdbRbu, pIter+128, pz, zSql)
				} else {
					Xsqlite3_free(tls, zSql)
				}
			}
			Xsqlite3_free(tls, **(**uintptr)(__ccgo_up(bp)))
			Xsqlite3_free(tls, **(**uintptr)(__ccgo_up(bp + 8)))
			Xsqlite3_free(tls, **(**uintptr)(__ccgo_up(bp + 16)))
			Xsqlite3_free(tls, zBind)
			Xsqlite3_free(tls, zPart)
		} else {
			bRbuRowid = libc.BoolInt32((*TRbuObjIter)(unsafe.Pointer(pIter)).FeType == int32(RBU_PK_VTAB) || (*TRbuObjIter)(unsafe.Pointer(pIter)).FeType == int32(RBU_PK_NONE) || (*TRbuObjIter)(unsafe.Pointer(pIter)).FeType == int32(RBU_PK_EXTERNAL) && (*Tsqlite3rbu)(unsafe.Pointer(p)).FzTarget == uintptr(0))
			zTbl1 = (*TRbuObjIter)(unsafe.Pointer(pIter)).FzTbl /* Imposter table name */
			zBindings = _rbuObjIterGetBindlist(tls, p, (*TRbuObjIter)(unsafe.Pointer(pIter)).FnTblCol+bRbuRowid)
			zWhere1 = _rbuObjIterGetWhere(tls, p, pIter)
			zOldlist = _rbuObjIterGetOldlist(tls, p, pIter, __ccgo_ts+6820)
			zNewlist = _rbuObjIterGetOldlist(tls, p, pIter, __ccgo_ts+6816)
			zCollist = _rbuObjIterGetCollist(tls, p, pIter)
			(*TRbuObjIter)(unsafe.Pointer(pIter)).FnCol = (*TRbuObjIter)(unsafe.Pointer(pIter)).FnTblCol
			/* Create the imposter table or tables (if required). */
			_rbuCreateImposterTable(tls, p, pIter)
			_rbuCreateImposterTable2(tls, p, pIter)
			if (*TRbuObjIter)(unsafe.Pointer(pIter)).FeType == int32(RBU_PK_VTAB) {
				v1 = __ccgo_ts + 1693
			} else {
				v1 = __ccgo_ts + 32688
			}
			zWrite = v1
			/* Create the INSERT statement to write to the target PK b-tree */
			if (*Tsqlite3rbu)(unsafe.Pointer(p)).Frc == SQLITE_OK {
				if bRbuRowid != 0 {
					v1 = __ccgo_ts + 32697
				} else {
					v1 = __ccgo_ts + 1693
				}
				(*Tsqlite3rbu)(unsafe.Pointer(p)).Frc = _prepareFreeAndCollectError(tls, (*Tsqlite3rbu)(unsafe.Pointer(p)).FdbMain, pIter+136, pz, Xsqlite3_mprintf(tls, __ccgo_ts+32707, libc.VaList(bp+40, zWrite, zTbl1, zCollist, v1, zBindings)))
			}
			/* Create the DELETE statement to write to the target PK b-tree.
			 ** Because it only performs INSERT operations, this is not required for
			 ** an rbu vacuum handle.  */
			if libc.BoolInt32((*Tsqlite3rbu)(unsafe.Pointer(p)).FzTarget == uintptr(0)) == 0 && (*Tsqlite3rbu)(unsafe.Pointer(p)).Frc == SQLITE_OK {
				(*Tsqlite3rbu)(unsafe.Pointer(p)).Frc = _prepareFreeAndCollectError(tls, (*Tsqlite3rbu)(unsafe.Pointer(p)).FdbMain, pIter+144, pz, Xsqlite3_mprintf(tls, __ccgo_ts+32743, libc.VaList(bp+40, zWrite, zTbl1, zWhere1)))
			}
			if libc.BoolInt32((*Tsqlite3rbu)(unsafe.Pointer(p)).FzTarget == uintptr(0)) == 0 && (*TRbuObjIter)(unsafe.Pointer(pIter)).FabIndexed != 0 {
				zRbuRowid = __ccgo_ts + 1693
				if (*TRbuObjIter)(unsafe.Pointer(pIter)).FeType == int32(RBU_PK_EXTERNAL) || (*TRbuObjIter)(unsafe.Pointer(pIter)).FeType == int32(RBU_PK_NONE) {
					zRbuRowid = __ccgo_ts + 32771
				}
				/* Create the rbu_tmp_xxx table and the triggers to populate it. */
				if (*TRbuObjIter)(unsafe.Pointer(pIter)).FeType == int32(RBU_PK_EXTERNAL) {
					v1 = __ccgo_ts + 32783
				} else {
					v1 = __ccgo_ts + 1693
				}
				_rbuMPrintfExec(tls, p, (*Tsqlite3rbu)(unsafe.Pointer(p)).FdbRbu, __ccgo_ts+32800, libc.VaList(bp+40, p+48, (*TRbuObjIter)(unsafe.Pointer(pIter)).FzDataTbl, v1, (*TRbuObjIter)(unsafe.Pointer(pIter)).FzDataTbl))
				_rbuMPrintfExec(tls, p, (*Tsqlite3rbu)(unsafe.Pointer(p)).FdbMain, __ccgo_ts+32876, libc.VaList(bp+40, zWrite, zTbl1, zOldlist, zWrite, zTbl1, zOldlist, zWrite, zTbl1, zNewlist))
				if (*TRbuObjIter)(unsafe.Pointer(pIter)).FeType == int32(RBU_PK_EXTERNAL) || (*TRbuObjIter)(unsafe.Pointer(pIter)).FeType == int32(RBU_PK_NONE) {
					_rbuMPrintfExec(tls, p, (*Tsqlite3rbu)(unsafe.Pointer(p)).FdbMain, __ccgo_ts+33175, libc.VaList(bp+40, zWrite, zTbl1, zNewlist))
				}
				_rbuObjIterPrepareTmpInsert(tls, p, pIter, zCollist, zRbuRowid)
			}
			/* Create the SELECT statement to read keys from data_xxx */
			if (*Tsqlite3rbu)(unsafe.Pointer(p)).Frc == SQLITE_OK {
				zRbuRowid1 = __ccgo_ts + 1693
				zStart1 = uintptr(0)
				zOrder = uintptr(0)
				if bRbuRowid != 0 {
					if (*Tsqlite3rbu)(unsafe.Pointer(p)).FzTarget == uintptr(0) {
						v1 = __ccgo_ts + 33274
					} else {
						v1 = __ccgo_ts + 33284
					}
					zRbuRowid1 = v1
				}
				if (*Tsqlite3rbu)(unsafe.Pointer(p)).FzTarget == uintptr(0) {
					if nOffset != 0 {
						zStart1 = _rbuVacuumTableStart(tls, p, pIter, bRbuRowid, zWrite)
						if zStart1 != 0 {
							Xsqlite3_free(tls, zLimit)
							zLimit = uintptr(0)
						}
					}
					if bRbuRowid != 0 {
						zOrder = _rbuMPrintf(tls, p, __ccgo_ts+31331, 0)
					} else {
						zOrder = _rbuObjIterGetPkList(tls, p, pIter, __ccgo_ts+1693, __ccgo_ts+16207, __ccgo_ts+1693)
					}
				}
				if (*Tsqlite3rbu)(unsafe.Pointer(p)).Frc == SQLITE_OK {
					if (*Tsqlite3rbu)(unsafe.Pointer(p)).FzTarget == uintptr(0) {
						v1 = __ccgo_ts + 33295
					} else {
						v1 = __ccgo_ts + 1693
					}
					if zStart1 != 0 {
						v2 = zStart1
					} else {
						v2 = __ccgo_ts + 1693
					}
					if zOrder != 0 {
						v3 = __ccgo_ts + 24843
					} else {
						v3 = __ccgo_ts + 1693
					}
					(*Tsqlite3rbu)(unsafe.Pointer(p)).Frc = _prepareFreeAndCollectError(tls, (*Tsqlite3rbu)(unsafe.Pointer(p)).FdbRbu, pIter+128, pz, Xsqlite3_mprintf(tls, __ccgo_ts+33301, libc.VaList(bp+40, zCollist, v1, zRbuRowid1, (*TRbuObjIter)(unsafe.Pointer(pIter)).FzDataTbl, v2, v3, zOrder, zLimit)))
				}
				Xsqlite3_free(tls, zStart1)
				Xsqlite3_free(tls, zOrder)
			}
			Xsqlite3_free(tls, zWhere1)
			Xsqlite3_free(tls, zOldlist)
			Xsqlite3_free(tls, zNewlist)
			Xsqlite3_free(tls, zBindings)
		}
		Xsqlite3_free(tls, zCollist)
		Xsqlite3_free(tls, zLimit)
	}
	return (*Tsqlite3rbu)(unsafe.Pointer(p)).Frc
}

// C documentation
//
//	/*
//	** Prepare a statement used to insert rows into the "rbu_tmp_xxx" table.
//	** Specifically a statement of the form:
//	**
//	**     INSERT INTO rbu_tmp_xxx VALUES(?, ?, ? ...);
//	**
//	** The number of bound variables is equal to the number of columns in
//	** the target table, plus one (for the rbu_control column), plus one more
//	** (for the rbu_rowid column) if the target table is an implicit IPK or
//	** virtual table.
//	*/
func _rbuObjIterPrepareTmpInsert(tls *libc.TLS, p uintptr, pIter uintptr, zCollist uintptr, zRbuRowid uintptr) {
	bp := tls.Alloc(48)
	defer tls.Free(48)
	var bRbuRowid int32
	var zBind uintptr
	_, _ = bRbuRowid, zBind
	bRbuRowid = libc.BoolInt32((*TRbuObjIter)(unsafe.Pointer(pIter)).FeType == int32(RBU_PK_EXTERNAL) || (*TRbuObjIter)(unsafe.Pointer(pIter)).FeType == int32(RBU_PK_NONE))
	zBind = _rbuObjIterGetBindlist(tls, p, (*TRbuObjIter)(unsafe.Pointer(pIter)).FnTblCol+int32(1)+bRbuRowid)
	if zBind != 0 {
		(*Tsqlite3rbu)(unsafe.Pointer(p)).Frc = _prepareFreeAndCollectError(tls, (*Tsqlite3rbu)(unsafe.Pointer(p)).FdbRbu, pIter+152, p+64, Xsqlite3_mprintf(tls, __ccgo_ts+32119, libc.VaList(bp+8, p+48, (*TRbuObjIter)(unsafe.Pointer(pIter)).FzDataTbl, zCollist, zRbuRowid, zBind)))
	}
}

func _rbuOpenDbhandle(tls *libc.TLS, p uintptr, zName uintptr, bUseVfs int32) (r uintptr) {
	bp := tls.Alloc(32)
	defer tls.Free(32)
	var flags int32
	var v1 uintptr
	var _ /* db at bp+0 */ uintptr
	_, _ = flags, v1
	**(**uintptr)(__ccgo_up(bp)) = uintptr(0)
	if (*Tsqlite3rbu)(unsafe.Pointer(p)).Frc == SQLITE_OK {
		flags = libc.Int32FromInt32(SQLITE_OPEN_READWRITE) | libc.Int32FromInt32(SQLITE_OPEN_CREATE) | libc.Int32FromInt32(SQLITE_OPEN_URI)
		if bUseVfs != 0 {
			v1 = (*Tsqlite3rbu)(unsafe.Pointer(p)).FzVfsName
		} else {
			v1 = uintptr(0)
		}
		(*Tsqlite3rbu)(unsafe.Pointer(p)).Frc = Xsqlite3_open_v2(tls, zName, bp, flags, v1)
		if (*Tsqlite3rbu)(unsafe.Pointer(p)).Frc != 0 {
			(*Tsqlite3rbu)(unsafe.Pointer(p)).FzErrmsg = Xsqlite3_mprintf(tls, __ccgo_ts+3933, libc.VaList(bp+16, Xsqlite3_errmsg(tls, **(**uintptr)(__ccgo_up(bp)))))
			Xsqlite3_close(tls, **(**uintptr)(__ccgo_up(bp)))
			**(**uintptr)(__ccgo_up(bp)) = uintptr(0)
		}
	}
	return **(**uintptr)(__ccgo_up(bp))
}

// C documentation
//
//	/*
//	** Update the contents of the rbu_state table within the rbu database. The
//	** value stored in the RBU_STATE_STAGE column is eStage. All other values
//	** are determined by inspecting the rbu handle passed as the first argument.
//	*/
func _rbuSaveState(tls *libc.TLS, p uintptr, eStage int32) {
	bp := tls.Alloc(192)
	defer tls.Free(192)
	var pFd, v1 uintptr
	var rc int32
	var _ /* pInsert at bp+0 */ uintptr
	_, _, _ = pFd, rc, v1
	if (*Tsqlite3rbu)(unsafe.Pointer(p)).Frc == SQLITE_OK || (*Tsqlite3rbu)(unsafe.Pointer(p)).Frc == int32(SQLITE_DONE) {
		**(**uintptr)(__ccgo_up(bp)) = uintptr(0)
		if (*Tsqlite3rbu)(unsafe.Pointer(p)).FzTarget == uintptr(0) {
			v1 = (*Tsqlite3rbu)(unsafe.Pointer(p)).FpRbuFd
		} else {
			v1 = (*Tsqlite3rbu)(unsafe.Pointer(p)).FpTargetFd
		}
		pFd = v1
		rc = _prepareFreeAndCollectError(tls, (*Tsqlite3rbu)(unsafe.Pointer(p)).FdbRbu, bp, p+64, Xsqlite3_mprintf(tls, __ccgo_ts+33804, libc.VaList(bp+16, p+48, int32(RBU_STATE_STAGE), eStage, int32(RBU_STATE_TBL), (*Tsqlite3rbu)(unsafe.Pointer(p)).Fobjiter.FzTbl, int32(RBU_STATE_IDX), (*Tsqlite3rbu)(unsafe.Pointer(p)).Fobjiter.FzIdx, int32(RBU_STATE_ROW), (*Tsqlite3rbu)(unsafe.Pointer(p)).FnStep, int32(RBU_STATE_PROGRESS), (*Tsqlite3rbu)(unsafe.Pointer(p)).FnProgress, int32(RBU_STATE_CKPT), (*Tsqlite3rbu)(unsafe.Pointer(p)).FiWalCksum, int32(RBU_STATE_COOKIE), libc.Int64FromUint32((*Trbu_file)(unsafe.Pointer(pFd)).FiCookie), int32(RBU_STATE_OALSZ), (*Tsqlite3rbu)(unsafe.Pointer(p)).FiOalSz, int32(RBU_STATE_PHASEONESTEP), (*Tsqlite3rbu)(unsafe.Pointer(p)).FnPhaseOneStep, int32(RBU_STATE_DATATBL), (*Tsqlite3rbu)(unsafe.Pointer(p)).Fobjiter.FzDataTbl)))
		if rc == SQLITE_OK {
			Xsqlite3_step(tls, **(**uintptr)(__ccgo_up(bp)))
			rc = Xsqlite3_finalize(tls, **(**uintptr)(__ccgo_up(bp)))
		}
		if rc != SQLITE_OK {
			(*Tsqlite3rbu)(unsafe.Pointer(p)).Frc = rc
		}
	}
}

// C documentation
//
//	/*
//	** This function is called as part of initializing or reinitializing an
//	** incremental checkpoint.
//	**
//	** It populates the sqlite3rbu.aFrame[] array with the set of
//	** (wal frame -> db page) copy operations required to checkpoint the
//	** current wal file, and obtains the set of shm locks required to safely
//	** perform the copy operations directly on the file-system.
//	**
//	** If argument pState is not NULL, then the incremental checkpoint is
//	** being resumed. In this case, if the checksum of the wal-index-header
//	** following recovery is not the same as the checksum saved in the RbuState
//	** object, then the rbu handle is set to DONE state. This occurs if some
//	** other client appends a transaction to the wal file in the middle of
//	** an incremental checkpoint.
//	*/
func _rbuSetupCheckpoint(tls *libc.TLS, p uintptr, pState uintptr) {
	var nSectorSize, rc2, v1 int32
	var pDb, pWal uintptr
	_, _, _, _, _ = nSectorSize, pDb, pWal, rc2, v1
	/* If pState is NULL, then the wal file may not have been opened and
	 ** recovered. Running a read-statement here to ensure that doing so
	 ** does not interfere with the "capture" process below.  */
	if pState == uintptr(0) {
		(*Tsqlite3rbu)(unsafe.Pointer(p)).FeStage = 0
		if (*Tsqlite3rbu)(unsafe.Pointer(p)).Frc == SQLITE_OK {
			(*Tsqlite3rbu)(unsafe.Pointer(p)).Frc = Xsqlite3_exec(tls, (*Tsqlite3rbu)(unsafe.Pointer(p)).FdbMain, __ccgo_ts+33635, uintptr(0), uintptr(0), uintptr(0))
		}
	}
	/* Assuming no error has occurred, run a "restart" checkpoint with the
	 ** sqlite3rbu.eStage variable set to CAPTURE. This turns on the following
	 ** special behaviour in the rbu VFS:
	 **
	 **   * If the exclusive shm WRITER or READ0 lock cannot be obtained,
	 **     the checkpoint fails with SQLITE_BUSY (normally SQLite would
	 **     proceed with running a passive checkpoint instead of failing).
	 **
	 **   * Attempts to read from the *-wal file or write to the database file
	 **     do not perform any IO. Instead, the frame/page combinations that
	 **     would be read/written are recorded in the sqlite3rbu.aFrame[]
	 **     array.
	 **
	 **   * Calls to xShmLock(UNLOCK) to release the exclusive shm WRITER,
	 **     READ0 and CHECKPOINT locks taken as part of the checkpoint are
	 **     no-ops. These locks will not be released until the connection
	 **     is closed.
	 **
	 **   * Attempting to xSync() the database file causes an SQLITE_NOTICE
	 **     error.
	 **
	 ** As a result, unless an error (i.e. OOM or SQLITE_BUSY) occurs, the
	 ** checkpoint below fails with SQLITE_NOTICE, and leaves the aFrame[]
	 ** array populated with a set of (frame -> page) mappings. Because the
	 ** WRITER, CHECKPOINT and READ0 locks are still held, it is safe to copy
	 ** data from the wal file into the database file according to the
	 ** contents of aFrame[].
	 */
	if (*Tsqlite3rbu)(unsafe.Pointer(p)).Frc == SQLITE_OK {
		(*Tsqlite3rbu)(unsafe.Pointer(p)).FeStage = int32(RBU_STAGE_CAPTURE)
		rc2 = Xsqlite3_exec(tls, (*Tsqlite3rbu)(unsafe.Pointer(p)).FdbMain, __ccgo_ts+33681, uintptr(0), uintptr(0), uintptr(0))
		if rc2 != int32(SQLITE_NOTICE) {
			(*Tsqlite3rbu)(unsafe.Pointer(p)).Frc = rc2
		}
	}
	if (*Tsqlite3rbu)(unsafe.Pointer(p)).Frc == SQLITE_OK && (*Tsqlite3rbu)(unsafe.Pointer(p)).FnFrame > 0 {
		(*Tsqlite3rbu)(unsafe.Pointer(p)).FeStage = int32(RBU_STAGE_CKPT)
		if pState != 0 {
			v1 = (*TRbuState)(unsafe.Pointer(pState)).FnRow
		} else {
			v1 = 0
		}
		(*Tsqlite3rbu)(unsafe.Pointer(p)).FnStep = v1
		(*Tsqlite3rbu)(unsafe.Pointer(p)).FaBuf = _rbuMalloc(tls, p, int64((*Tsqlite3rbu)(unsafe.Pointer(p)).Fpgsz))
		(*Tsqlite3rbu)(unsafe.Pointer(p)).FiWalCksum = _rbuShmChecksum(tls, p)
	}
	if (*Tsqlite3rbu)(unsafe.Pointer(p)).Frc == SQLITE_OK {
		if (*Tsqlite3rbu)(unsafe.Pointer(p)).FnFrame == 0 || pState != 0 && (*TRbuState)(unsafe.Pointer(pState)).FiWalCksum != (*Tsqlite3rbu)(unsafe.Pointer(p)).FiWalCksum {
			(*Tsqlite3rbu)(unsafe.Pointer(p)).Frc = int32(SQLITE_DONE)
			(*Tsqlite3rbu)(unsafe.Pointer(p)).FeStage = int32(RBU_STAGE_DONE)
		} else {
			pDb = (*Trbu_file)(unsafe.Pointer((*Tsqlite3rbu)(unsafe.Pointer(p)).FpTargetFd)).FpReal
			pWal = (*Trbu_file)(unsafe.Pointer((*Trbu_file)(unsafe.Pointer((*Tsqlite3rbu)(unsafe.Pointer(p)).FpTargetFd)).FpWalFd)).FpReal
			nSectorSize = (*(*func(*libc.TLS, uintptr) int32)(unsafe.Pointer(&struct{ uintptr }{(*Tsqlite3_io_methods)(unsafe.Pointer((*Tsqlite3_file)(unsafe.Pointer(pDb)).FpMethods)).FxSectorSize})))(tls, pDb)
			if nSectorSize > (*Tsqlite3rbu)(unsafe.Pointer(p)).Fpgsz {
				(*Tsqlite3rbu)(unsafe.Pointer(p)).FnPagePerSector = nSectorSize / (*Tsqlite3rbu)(unsafe.Pointer(p)).Fpgsz
			} else {
				(*Tsqlite3rbu)(unsafe.Pointer(p)).FnPagePerSector = int32(1)
			}
			/* Call xSync() on the wal file. This causes SQLite to sync the
			 ** directory in which the target database and the wal file reside, in
			 ** case it has not been synced since the rename() call in
			 ** rbuMoveOalFile(). */
			(*Tsqlite3rbu)(unsafe.Pointer(p)).Frc = (*(*func(*libc.TLS, uintptr, int32) int32)(unsafe.Pointer(&struct{ uintptr }{(*Tsqlite3_io_methods)(unsafe.Pointer((*Tsqlite3_file)(unsafe.Pointer(pWal)).FpMethods)).FxSync})))(tls, pWal, int32(SQLITE_SYNC_NORMAL))
		}
	}
}

// C documentation
//
//	/*
//	** This function is called as part of sqlite3rbu_open() when initializing
//	** an rbu handle in OAL stage. If the rbu update has not started (i.e.
//	** the rbu_state table was empty) it is a no-op. Otherwise, it arranges
//	** things so that the next call to sqlite3rbu_step() continues on from
//	** where the previous rbu handle left off.
//	**
//	** If an error occurs, an error code and error message are left in the
//	** rbu handle passed as the first argument.
//	*/
func _rbuSetupOal(tls *libc.TLS, p uintptr, pState uintptr) {
	var pIter uintptr
	var rc int32
	_, _ = pIter, rc
	if (*TRbuState)(unsafe.Pointer(pState)).FzTbl != 0 {
		pIter = p + 88
		rc = SQLITE_OK
		for rc == SQLITE_OK && (*TRbuObjIter)(unsafe.Pointer(pIter)).FzTbl != 0 && ((*TRbuObjIter)(unsafe.Pointer(pIter)).FbCleanup != 0 || _rbuStrCompare(tls, (*TRbuObjIter)(unsafe.Pointer(pIter)).FzIdx, (*TRbuState)(unsafe.Pointer(pState)).FzIdx) != 0 || (*TRbuState)(unsafe.Pointer(pState)).FzDataTbl == uintptr(0) && _rbuStrCompare(tls, (*TRbuObjIter)(unsafe.Pointer(pIter)).FzTbl, (*TRbuState)(unsafe.Pointer(pState)).FzTbl) != 0 || (*TRbuState)(unsafe.Pointer(pState)).FzDataTbl != 0 && _rbuStrCompare(tls, (*TRbuObjIter)(unsafe.Pointer(pIter)).FzDataTbl, (*TRbuState)(unsafe.Pointer(pState)).FzDataTbl) != 0) {
			rc = _rbuObjIterNext(tls, p, pIter)
		}
		if rc == SQLITE_OK && !((*TRbuObjIter)(unsafe.Pointer(pIter)).FzTbl != 0) {
			rc = int32(SQLITE_ERROR)
			(*Tsqlite3rbu)(unsafe.Pointer(p)).FzErrmsg = Xsqlite3_mprintf(tls, __ccgo_ts+34294, 0)
		}
		if rc == SQLITE_OK {
			(*Tsqlite3rbu)(unsafe.Pointer(p)).FnStep = (*TRbuState)(unsafe.Pointer(pState)).FnRow
			rc = _rbuObjIterPrepareAll(tls, p, p+88, (*Tsqlite3rbu)(unsafe.Pointer(p)).FnStep)
		}
		(*Tsqlite3rbu)(unsafe.Pointer(p)).Frc = rc
	}
}

// C documentation
//
//	/*
//	** Argument eType must be one of RBU_INSERT, RBU_DELETE, RBU_IDX_INSERT or
//	** RBU_IDX_DELETE. This function performs the work of a single
//	** sqlite3rbu_step() call for the type of operation specified by eType.
//	*/
func _rbuStepOneOp(tls *libc.TLS, p uintptr, eType int32) {
	var i int32
	var pIter, pVal, pWriter uintptr
	_, _, _, _ = i, pIter, pVal, pWriter
	pIter = p + 88
	/* If this is a delete, decrement nPhaseOneStep by nIndex. If the DELETE
	 ** statement below does actually delete a row, nPhaseOneStep will be
	 ** incremented by the same amount when SQL function rbu_tmp_insert()
	 ** is invoked by the trigger.  */
	if eType == int32(RBU_DELETE) {
		**(**Ti64)(__ccgo_up(p + 312)) -= int64((*Tsqlite3rbu)(unsafe.Pointer(p)).Fobjiter.FnIndex)
	}
	if eType == int32(RBU_IDX_DELETE) || eType == int32(RBU_DELETE) {
		pWriter = (*TRbuObjIter)(unsafe.Pointer(pIter)).FpDelete
	} else {
		pWriter = (*TRbuObjIter)(unsafe.Pointer(pIter)).FpInsert
	}
	i = 0
	for {
		if !(i < (*TRbuObjIter)(unsafe.Pointer(pIter)).FnCol) {
			break
		}
		/* If this is an INSERT into a table b-tree and the table has an
		 ** explicit INTEGER PRIMARY KEY, check that this is not an attempt
		 ** to write a NULL into the IPK column. That is not permitted.  */
		if eType == int32(RBU_INSERT) && (*TRbuObjIter)(unsafe.Pointer(pIter)).FzIdx == uintptr(0) && (*TRbuObjIter)(unsafe.Pointer(pIter)).FeType == int32(RBU_PK_IPK) && **(**Tu8)(__ccgo_up((*TRbuObjIter)(unsafe.Pointer(pIter)).FabTblPk + uintptr(i))) != 0 && Xsqlite3_column_type(tls, (*TRbuObjIter)(unsafe.Pointer(pIter)).FpSelect, i) == int32(SQLITE_NULL) {
			(*Tsqlite3rbu)(unsafe.Pointer(p)).Frc = int32(SQLITE_MISMATCH)
			(*Tsqlite3rbu)(unsafe.Pointer(p)).FzErrmsg = Xsqlite3_mprintf(tls, __ccgo_ts+25664, 0)
			return
		}
		if eType == int32(RBU_DELETE) && libc.Int32FromUint8(**(**Tu8)(__ccgo_up((*TRbuObjIter)(unsafe.Pointer(pIter)).FabTblPk + uintptr(i)))) == 0 {
			goto _1
		}
		pVal = Xsqlite3_column_value(tls, (*TRbuObjIter)(unsafe.Pointer(pIter)).FpSelect, i)
		(*Tsqlite3rbu)(unsafe.Pointer(p)).Frc = Xsqlite3_bind_value(tls, pWriter, i+int32(1), pVal)
		if (*Tsqlite3rbu)(unsafe.Pointer(p)).Frc != 0 {
			return
		}
		goto _1
	_1:
		;
		i = i + 1
	}
	if (*TRbuObjIter)(unsafe.Pointer(pIter)).FzIdx == uintptr(0) {
		if (*TRbuObjIter)(unsafe.Pointer(pIter)).FeType == int32(RBU_PK_VTAB) || (*TRbuObjIter)(unsafe.Pointer(pIter)).FeType == int32(RBU_PK_NONE) || (*TRbuObjIter)(unsafe.Pointer(pIter)).FeType == int32(RBU_PK_EXTERNAL) && (*Tsqlite3rbu)(unsafe.Pointer(p)).FzTarget == uintptr(0) {
			/* For a virtual table, or a table with no primary key, the
			 ** SELECT statement is:
			 **
			 **   SELECT <cols>, rbu_control, rbu_rowid FROM ....
			 **
			 ** Hence column_value(pIter->nCol+1).
			 */
			pVal = Xsqlite3_column_value(tls, (*TRbuObjIter)(unsafe.Pointer(pIter)).FpSelect, (*TRbuObjIter)(unsafe.Pointer(pIter)).FnCol+int32(1))
			(*Tsqlite3rbu)(unsafe.Pointer(p)).Frc = Xsqlite3_bind_value(tls, pWriter, (*TRbuObjIter)(unsafe.Pointer(pIter)).FnCol+int32(1), pVal)
		}
	}
	if (*Tsqlite3rbu)(unsafe.Pointer(p)).Frc == SQLITE_OK {
		Xsqlite3_step(tls, pWriter)
		(*Tsqlite3rbu)(unsafe.Pointer(p)).Frc = _resetAndCollectError(tls, pWriter, p+64)
	}
}

// C documentation
//
//	/* Determine the type of a table.
//	**
//	**   peType is of type (int*), a pointer to an output parameter of type
//	**   (int). This call sets the output parameter as follows, depending
//	**   on the type of the table specified by parameters dbName and zTbl.
//	**
//	**     RBU_PK_NOTABLE:       No such table.
//	**     RBU_PK_NONE:          Table has an implicit rowid.
//	**     RBU_PK_IPK:           Table has an explicit IPK column.
//	**     RBU_PK_EXTERNAL:      Table has an external PK index.
//	**     RBU_PK_WITHOUT_ROWID: Table is WITHOUT ROWID.
//	**     RBU_PK_VTAB:          Table is a virtual table.
//	**
//	**   Argument *piPk is also of type (int*), and also points to an output
//	**   parameter. Unless the table has an external primary key index
//	**   (i.e. unless *peType is set to 3), then *piPk is set to zero. Or,
//	**   if the table does have an external primary key index, then *piPk
//	**   is set to the root page number of the primary key index before
//	**   returning.
//	**
//	** ALGORITHM:
//	**
//	**   if( no entry exists in sqlite_schema ){
//	**     return RBU_PK_NOTABLE
//	**   }else if( sql for the entry starts with "CREATE VIRTUAL" ){
//	**     return RBU_PK_VTAB
//	**   }else if( "PRAGMA index_list()" for the table contains a "pk" index ){
//	**     if( the index that is the pk exists in sqlite_schema ){
//	**       *piPK = rootpage of that index.
//	**       return RBU_PK_EXTERNAL
//	**     }else{
//	**       return RBU_PK_WITHOUT_ROWID
//	**     }
//	**   }else if( "PRAGMA table_info()" lists one or more "pk" columns ){
//	**     return RBU_PK_IPK
//	**   }else{
//	**     return RBU_PK_NONE
//	**   }
//	*/
func _rbuTableType(tls *libc.TLS, p uintptr, zTab uintptr, peType uintptr, piTnum uintptr, piPk uintptr) {
	bp := tls.Alloc(48)
	defer tls.Free(48)
	var i uint32
	var zIdx, zOrig uintptr
	var _ /* aStmt at bp+0 */ [4]uintptr
	_, _, _ = i, zIdx, zOrig
	/*
	 ** 0) SELECT count(*) FROM sqlite_schema where name=%Q AND IsVirtual(%Q)
	 ** 1) PRAGMA index_list = ?
	 ** 2) SELECT count(*) FROM sqlite_schema where name=%Q
	 ** 3) PRAGMA table_info = ?
	 */
	**(**[4]uintptr)(__ccgo_up(bp)) = [4]uintptr{}
	**(**int32)(__ccgo_up(peType)) = RBU_PK_NOTABLE
	**(**int32)(__ccgo_up(piPk)) = 0
	(*Tsqlite3rbu)(unsafe.Pointer(p)).Frc = _prepareFreeAndCollectError(tls, (*Tsqlite3rbu)(unsafe.Pointer(p)).FdbMain, bp, p+64, Xsqlite3_mprintf(tls, __ccgo_ts+30768, libc.VaList(bp+40, zTab)))
	if (*Tsqlite3rbu)(unsafe.Pointer(p)).Frc != SQLITE_OK || Xsqlite3_step(tls, (**(**[4]uintptr)(__ccgo_up(bp)))[0]) != int32(SQLITE_ROW) {
		/* Either an error, or no such table. */
		goto rbuTableType_end
	}
	if Xsqlite3_column_int(tls, (**(**[4]uintptr)(__ccgo_up(bp)))[0], 0) != 0 {
		**(**int32)(__ccgo_up(peType)) = int32(RBU_PK_VTAB) /* virtual table */
		goto rbuTableType_end
	}
	**(**int32)(__ccgo_up(piTnum)) = Xsqlite3_column_int(tls, (**(**[4]uintptr)(__ccgo_up(bp)))[0], int32(1))
	(*Tsqlite3rbu)(unsafe.Pointer(p)).Frc = _prepareFreeAndCollectError(tls, (*Tsqlite3rbu)(unsafe.Pointer(p)).FdbMain, bp+1*8, p+64, Xsqlite3_mprintf(tls, __ccgo_ts+30887, libc.VaList(bp+40, zTab)))
	if (*Tsqlite3rbu)(unsafe.Pointer(p)).Frc != 0 {
		goto rbuTableType_end
	}
	for Xsqlite3_step(tls, (**(**[4]uintptr)(__ccgo_up(bp)))[int32(1)]) == int32(SQLITE_ROW) {
		zOrig = Xsqlite3_column_text(tls, (**(**[4]uintptr)(__ccgo_up(bp)))[int32(1)], int32(3))
		zIdx = Xsqlite3_column_text(tls, (**(**[4]uintptr)(__ccgo_up(bp)))[int32(1)], int32(1))
		if zOrig != 0 && zIdx != 0 && libc.Int32FromUint8(**(**Tu8)(__ccgo_up(zOrig))) == int32('p') {
			(*Tsqlite3rbu)(unsafe.Pointer(p)).Frc = _prepareFreeAndCollectError(tls, (*Tsqlite3rbu)(unsafe.Pointer(p)).FdbMain, bp+2*8, p+64, Xsqlite3_mprintf(tls, __ccgo_ts+30908, libc.VaList(bp+40, zIdx)))
			if (*Tsqlite3rbu)(unsafe.Pointer(p)).Frc == SQLITE_OK {
				if Xsqlite3_step(tls, (**(**[4]uintptr)(__ccgo_up(bp)))[int32(2)]) == int32(SQLITE_ROW) {
					**(**int32)(__ccgo_up(piPk)) = Xsqlite3_column_int(tls, (**(**[4]uintptr)(__ccgo_up(bp)))[int32(2)], 0)
					**(**int32)(__ccgo_up(peType)) = int32(RBU_PK_EXTERNAL)
				} else {
					**(**int32)(__ccgo_up(peType)) = int32(RBU_PK_WITHOUT_ROWID)
				}
			}
			goto rbuTableType_end
		}
	}
	(*Tsqlite3rbu)(unsafe.Pointer(p)).Frc = _prepareFreeAndCollectError(tls, (*Tsqlite3rbu)(unsafe.Pointer(p)).FdbMain, bp+3*8, p+64, Xsqlite3_mprintf(tls, __ccgo_ts+30959, libc.VaList(bp+40, zTab)))
	if (*Tsqlite3rbu)(unsafe.Pointer(p)).Frc == SQLITE_OK {
		for Xsqlite3_step(tls, (**(**[4]uintptr)(__ccgo_up(bp)))[int32(3)]) == int32(SQLITE_ROW) {
			if Xsqlite3_column_int(tls, (**(**[4]uintptr)(__ccgo_up(bp)))[int32(3)], int32(5)) > 0 {
				**(**int32)(__ccgo_up(peType)) = int32(RBU_PK_IPK) /* explicit IPK column */
				goto rbuTableType_end
			}
		}
		**(**int32)(__ccgo_up(peType)) = int32(RBU_PK_NONE)
	}
	goto rbuTableType_end
rbuTableType_end:
	;
	i = uint32(0)
	for {
		if !(uint64(i) < libc.Uint64FromInt64(32)/libc.Uint64FromInt64(8)) {
			break
		}
		_rbuFinalize(tls, p, (**(**[4]uintptr)(__ccgo_up(bp)))[i])
		goto _1
	_1:
		;
		i = i + 1
	}
}

// C documentation
//
//	/*
//	** This function is called as part of restarting an RBU vacuum within
//	** stage 1 of the process (while the *-oal file is being built) while
//	** updating a table (not an index). The table may be a rowid table or
//	** a WITHOUT ROWID table. It queries the target database to find the
//	** largest key that has already been written to the target table and
//	** constructs a WHERE clause that can be used to extract the remaining
//	** rows from the source table. For a rowid table, the WHERE clause
//	** is of the form:
//	**
//	**     "WHERE _rowid_ > ?"
//	**
//	** and for WITHOUT ROWID tables:
//	**
//	**     "WHERE (key1, key2) > (?, ?)"
//	**
//	** Instead of "?" placeholders, the actual WHERE clauses created by
//	** this function contain literal SQL values.
//	*/
func _rbuVacuumTableStart(tls *libc.TLS, p uintptr, pIter uintptr, bRowid int32, zWrite uintptr) (r uintptr) {
	bp := tls.Alloc(48)
	defer tls.Free(48)
	var iMax Tsqlite3_int64
	var zList, zOrder, zRet, zSelect, zVal uintptr
	var _ /* pMax at bp+0 */ uintptr
	_, _, _, _, _, _ = iMax, zList, zOrder, zRet, zSelect, zVal
	**(**uintptr)(__ccgo_up(bp)) = uintptr(0)
	zRet = uintptr(0)
	if bRowid != 0 {
		(*Tsqlite3rbu)(unsafe.Pointer(p)).Frc = _prepareFreeAndCollectError(tls, (*Tsqlite3rbu)(unsafe.Pointer(p)).FdbMain, bp, p+64, Xsqlite3_mprintf(tls, __ccgo_ts+31193, libc.VaList(bp+16, zWrite, (*TRbuObjIter)(unsafe.Pointer(pIter)).FzTbl)))
		if (*Tsqlite3rbu)(unsafe.Pointer(p)).Frc == SQLITE_OK && int32(SQLITE_ROW) == Xsqlite3_step(tls, **(**uintptr)(__ccgo_up(bp))) {
			iMax = Xsqlite3_column_int64(tls, **(**uintptr)(__ccgo_up(bp)), 0)
			zRet = _rbuMPrintf(tls, p, __ccgo_ts+31225, libc.VaList(bp+16, iMax))
		}
		_rbuFinalize(tls, p, **(**uintptr)(__ccgo_up(bp)))
	} else {
		zOrder = _rbuObjIterGetPkList(tls, p, pIter, __ccgo_ts+1693, __ccgo_ts+16207, __ccgo_ts+31248)
		zSelect = _rbuObjIterGetPkList(tls, p, pIter, __ccgo_ts+31254, __ccgo_ts+31261, __ccgo_ts+5250)
		zList = _rbuObjIterGetPkList(tls, p, pIter, __ccgo_ts+1693, __ccgo_ts+16207, __ccgo_ts+1693)
		if (*Tsqlite3rbu)(unsafe.Pointer(p)).Frc == SQLITE_OK {
			(*Tsqlite3rbu)(unsafe.Pointer(p)).Frc = _prepareFreeAndCollectError(tls, (*Tsqlite3rbu)(unsafe.Pointer(p)).FdbMain, bp, p+64, Xsqlite3_mprintf(tls, __ccgo_ts+31269, libc.VaList(bp+16, zSelect, zWrite, (*TRbuObjIter)(unsafe.Pointer(pIter)).FzTbl, zOrder)))
			if (*Tsqlite3rbu)(unsafe.Pointer(p)).Frc == SQLITE_OK && int32(SQLITE_ROW) == Xsqlite3_step(tls, **(**uintptr)(__ccgo_up(bp))) {
				zVal = Xsqlite3_column_text(tls, **(**uintptr)(__ccgo_up(bp)), 0)
				zRet = _rbuMPrintf(tls, p, __ccgo_ts+31311, libc.VaList(bp+16, zList, zVal))
			}
			_rbuFinalize(tls, p, **(**uintptr)(__ccgo_up(bp)))
		}
		Xsqlite3_free(tls, zOrder)
		Xsqlite3_free(tls, zSelect)
		Xsqlite3_free(tls, zList)
	}
	return zRet
}

// C documentation
//
//	/*
//	** File control method. For custom operations on an rbuVfs-file.
//	*/
func _rbuVfsFileControl(tls *libc.TLS, pFile uintptr, op int32, pArg uintptr) (r int32) {
	bp := tls.Alloc(32)
	defer tls.Free(32)
	var p, pRbu, pRbu1, pRbuVfs, xControl, zIn, zOut uintptr
	var rc int32
	var _ /* dummy at bp+0 */ uintptr
	_, _, _, _, _, _, _, _ = p, pRbu, pRbu1, pRbuVfs, rc, xControl, zIn, zOut
	p = pFile
	xControl = (*Tsqlite3_io_methods)(unsafe.Pointer((*Tsqlite3_file)(unsafe.Pointer((*Trbu_file)(unsafe.Pointer(p)).FpReal)).FpMethods)).FxFileControl
	if op == int32(SQLITE_FCNTL_RBU) {
		pRbu = pArg
		/* First try to find another RBU vfs lower down in the vfs stack. If
		 ** one is found, this vfs will operate in pass-through mode. The lower
		 ** level vfs will do the special RBU handling.  */
		rc = (*(*func(*libc.TLS, uintptr, int32, uintptr) int32)(unsafe.Pointer(&struct{ uintptr }{xControl})))(tls, (*Trbu_file)(unsafe.Pointer(p)).FpReal, op, pArg)
		if rc == int32(SQLITE_NOTFOUND) {
			/* Now search for a zipvfs instance lower down in the VFS stack. If
			 ** one is found, this is an error.  */
			**(**uintptr)(__ccgo_up(bp)) = uintptr(0)
			rc = (*(*func(*libc.TLS, uintptr, int32, uintptr) int32)(unsafe.Pointer(&struct{ uintptr }{xControl})))(tls, (*Trbu_file)(unsafe.Pointer(p)).FpReal, int32(SQLITE_FCNTL_ZIPVFS), bp)
			if rc == SQLITE_OK {
				rc = int32(SQLITE_ERROR)
				(*Tsqlite3rbu)(unsafe.Pointer(pRbu)).FzErrmsg = Xsqlite3_mprintf(tls, __ccgo_ts+34700, 0)
			} else {
				if rc == int32(SQLITE_NOTFOUND) {
					(*Tsqlite3rbu)(unsafe.Pointer(pRbu)).FpTargetFd = p
					(*Trbu_file)(unsafe.Pointer(p)).FpRbu = pRbu
					_rbuMainlistAdd(tls, p)
					if (*Trbu_file)(unsafe.Pointer(p)).FpWalFd != 0 {
						(*Trbu_file)(unsafe.Pointer((*Trbu_file)(unsafe.Pointer(p)).FpWalFd)).FpRbu = pRbu
					}
					rc = SQLITE_OK
				}
			}
		}
		return rc
	} else {
		if op == int32(SQLITE_FCNTL_RBUCNT) {
			pRbu1 = pArg
			(*Tsqlite3rbu)(unsafe.Pointer(pRbu1)).FnRbu = (*Tsqlite3rbu)(unsafe.Pointer(pRbu1)).FnRbu + 1
			(*Tsqlite3rbu)(unsafe.Pointer(pRbu1)).FpRbuFd = p
			(*Trbu_file)(unsafe.Pointer(p)).FbNolock = uint8(1)
		}
	}
	rc = (*(*func(*libc.TLS, uintptr, int32, uintptr) int32)(unsafe.Pointer(&struct{ uintptr }{xControl})))(tls, (*Trbu_file)(unsafe.Pointer(p)).FpReal, op, pArg)
	if rc == SQLITE_OK && op == int32(SQLITE_FCNTL_VFSNAME) {
		pRbuVfs = (*Trbu_file)(unsafe.Pointer(p)).FpRbuVfs
		zIn = **(**uintptr)(__ccgo_up(pArg))
		zOut = Xsqlite3_mprintf(tls, __ccgo_ts+34723, libc.VaList(bp+16, (*Trbu_vfs)(unsafe.Pointer(pRbuVfs)).Fbase.FzName, zIn))
		**(**uintptr)(__ccgo_up(pArg)) = zOut
		if zOut == uintptr(0) {
			rc = int32(SQLITE_NOMEM)
		}
	}
	return rc
}

// C documentation
//
//	/*
//	** The iterator currently points to a table (not index) of type
//	** RBU_PK_WITHOUT_ROWID. This function creates the PRIMARY KEY
//	** declaration for the corresponding imposter table. For example,
//	** if the iterator points to a table created as:
//	**
//	**   CREATE TABLE t1(a, b, c, PRIMARY KEY(b, a DESC)) WITHOUT ROWID
//	**
//	** this function returns:
//	**
//	**   PRIMARY KEY("b", "a" DESC)
//	*/
func _rbuWithoutRowidPK(tls *libc.TLS, p uintptr, pIter uintptr) (r uintptr) {
	bp := tls.Alloc(64)
	defer tls.Free(64)
	var z, zCol, zDesc, zIdx, zOrig, zSep, v1 uintptr
	var _ /* pXInfo at bp+8 */ uintptr
	var _ /* pXList at bp+0 */ uintptr
	_, _, _, _, _, _, _ = z, zCol, zDesc, zIdx, zOrig, zSep, v1
	z = uintptr(0)
	if (*Tsqlite3rbu)(unsafe.Pointer(p)).Frc == SQLITE_OK {
		zSep = __ccgo_ts + 31828
		**(**uintptr)(__ccgo_up(bp)) = uintptr(0)     /* PRAGMA index_list = (pIter->zTbl) */
		**(**uintptr)(__ccgo_up(bp + 8)) = uintptr(0) /* PRAGMA index_xinfo = <pk-index> */
		(*Tsqlite3rbu)(unsafe.Pointer(p)).Frc = _prepareFreeAndCollectError(tls, (*Tsqlite3rbu)(unsafe.Pointer(p)).FdbMain, bp, p+64, Xsqlite3_mprintf(tls, __ccgo_ts+30980, libc.VaList(bp+24, (*TRbuObjIter)(unsafe.Pointer(pIter)).FzTbl)))
		for (*Tsqlite3rbu)(unsafe.Pointer(p)).Frc == SQLITE_OK && int32(SQLITE_ROW) == Xsqlite3_step(tls, **(**uintptr)(__ccgo_up(bp))) {
			zOrig = Xsqlite3_column_text(tls, **(**uintptr)(__ccgo_up(bp)), int32(3))
			if zOrig != 0 && libc.Xstrcmp(tls, zOrig, __ccgo_ts+17844) == 0 {
				zIdx = Xsqlite3_column_text(tls, **(**uintptr)(__ccgo_up(bp)), int32(1))
				if zIdx != 0 {
					(*Tsqlite3rbu)(unsafe.Pointer(p)).Frc = _prepareFreeAndCollectError(tls, (*Tsqlite3rbu)(unsafe.Pointer(p)).FdbMain, bp+8, p+64, Xsqlite3_mprintf(tls, __ccgo_ts+31008, libc.VaList(bp+24, zIdx)))
				}
				break
			}
		}
		_rbuFinalize(tls, p, **(**uintptr)(__ccgo_up(bp)))
		for (*Tsqlite3rbu)(unsafe.Pointer(p)).Frc == SQLITE_OK && int32(SQLITE_ROW) == Xsqlite3_step(tls, **(**uintptr)(__ccgo_up(bp + 8))) {
			if Xsqlite3_column_int(tls, **(**uintptr)(__ccgo_up(bp + 8)), int32(5)) != 0 {
				/* int iCid = sqlite3_column_int(pXInfo, 0); */
				zCol = Xsqlite3_column_text(tls, **(**uintptr)(__ccgo_up(bp + 8)), int32(2))
				if Xsqlite3_column_int(tls, **(**uintptr)(__ccgo_up(bp + 8)), int32(3)) != 0 {
					v1 = __ccgo_ts + 31248
				} else {
					v1 = __ccgo_ts + 1693
				}
				zDesc = v1
				z = _rbuMPrintf(tls, p, __ccgo_ts+31841, libc.VaList(bp+24, z, zSep, zCol, zDesc))
				zSep = __ccgo_ts + 16207
			}
		}
		z = _rbuMPrintf(tls, p, __ccgo_ts+31852, libc.VaList(bp+24, z))
		_rbuFinalize(tls, p, **(**uintptr)(__ccgo_up(bp + 8)))
	}
	return z
}

// C documentation
//
//	/*
//	** SQL function:
//	**
//	**     sqlite_rename_column(SQL,TYPE,OBJ,DB,TABLE,COL,NEWNAME,QUOTE,TEMP)
//	**
//	**   0. zSql:     SQL statement to rewrite
//	**   1. type:     Type of object ("table", "view" etc.)
//	**   2. object:   Name of object
//	**   3. Database: Database name (e.g. "main")
//	**   4. Table:    Table name
//	**   5. iCol:     Index of column to rename
//	**   6. zNew:     New column name
//	**   7. bQuote:   Non-zero if the new column name should be quoted.
//	**   8. bTemp:    True if zSql comes from temp schema
//	**
//	** Do a column rename operation on the CREATE statement given in zSql.
//	** The iCol-th column (left-most is 0) of table zTable is renamed from zCol
//	** into zNew.  The name should be quoted if bQuote is true.
//	**
//	** This function is used internally by the ALTER TABLE RENAME COLUMN command.
//	** It is only accessible to SQL created using sqlite3NestedParse().  It is
//	** not reachable from ordinary SQL passed into sqlite3_prepare() unless the
//	** SQLITE_TESTCTRL_INTERNAL_FUNCTIONS test setting is enabled.
//	*/
func _renameColumnFunc(tls *libc.TLS, context uintptr, NotUsed int32, argv uintptr) {
	bp := tls.Alloc(512)
	defer tls.Free(512)
	var bFKOnly, bQuote, bTemp, i, iCol, rc, v1 int32
	var db, pExpr, pFKey, pIdx, pSelect, pStep, pTab, pTarget, pUpsertSet, zDb, zNew, zOld, zSql, zTable uintptr
	var xAuth Tsqlite3_xauth
	var _ /* sCtx at bp+0 */ TRenameCtx
	var _ /* sParse at bp+32 */ TParse
	var _ /* sWalker at bp+456 */ TWalker
	_, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _ = bFKOnly, bQuote, bTemp, db, i, iCol, pExpr, pFKey, pIdx, pSelect, pStep, pTab, pTarget, pUpsertSet, rc, xAuth, zDb, zNew, zOld, zSql, zTable, v1
	db = Xsqlite3_context_db_handle(tls, context)
	zSql = Xsqlite3_value_text(tls, **(**uintptr)(__ccgo_up(argv)))
	zDb = Xsqlite3_value_text(tls, **(**uintptr)(__ccgo_up(argv + 3*8)))
	zTable = Xsqlite3_value_text(tls, **(**uintptr)(__ccgo_up(argv + 4*8)))
	iCol = Xsqlite3_value_int(tls, **(**uintptr)(__ccgo_up(argv + 5*8)))
	zNew = Xsqlite3_value_text(tls, **(**uintptr)(__ccgo_up(argv + 6*8)))
	bQuote = Xsqlite3_value_int(tls, **(**uintptr)(__ccgo_up(argv + 7*8)))
	bTemp = Xsqlite3_value_int(tls, **(**uintptr)(__ccgo_up(argv + 8*8)))
	xAuth = (*Tsqlite3)(unsafe.Pointer(db)).FxAuth
	_ = NotUsed
	if zSql == uintptr(0) {
		return
	}
	if zTable == uintptr(0) {
		return
	}
	if zNew == uintptr(0) {
		return
	}
	if iCol < 0 {
		return
	}
	_sqlite3BtreeEnterAll(tls, db)
	pTab = _sqlite3FindTable(tls, db, zTable, zDb)
	if pTab == uintptr(0) || iCol >= int32((*TTable)(unsafe.Pointer(pTab)).FnCol) {
		_sqlite3BtreeLeaveAll(tls, db)
		return
	}
	zOld = (**(**TColumn)(__ccgo_up((*TTable)(unsafe.Pointer(pTab)).FaCol + uintptr(iCol)*16))).FzCnName
	libc.Xmemset(tls, bp, 0, uint64(32))
	if iCol == int32((*TTable)(unsafe.Pointer(pTab)).FiPKey) {
		v1 = -int32(1)
	} else {
		v1 = iCol
	}
	(**(**TRenameCtx)(__ccgo_up(bp))).FiCol = v1
	(*Tsqlite3)(unsafe.Pointer(db)).FxAuth = uintptr(0)
	rc = _renameParseSql(tls, bp+32, zDb, db, zSql, bTemp)
	/* Find tokens that need to be replaced. */
	libc.Xmemset(tls, bp+456, 0, uint64(48))
	(**(**TWalker)(__ccgo_up(bp + 456))).FpParse = bp + 32
	(**(**TWalker)(__ccgo_up(bp + 456))).FxExprCallback = __ccgo_fp(_renameColumnExprCb)
	(**(**TWalker)(__ccgo_up(bp + 456))).FxSelectCallback = __ccgo_fp(_renameColumnSelectCb)
	*(*uintptr)(unsafe.Pointer(bp + 456 + 40)) = bp
	(**(**TRenameCtx)(__ccgo_up(bp))).FpTab = pTab
	if rc != SQLITE_OK {
		goto renameColumnFunc_done
	}
	if (**(**TParse)(__ccgo_up(bp + 32))).FpNewTable != 0 {
		if libc.Int32FromUint8((*TTable)(unsafe.Pointer((**(**TParse)(__ccgo_up(bp + 32))).FpNewTable)).FeTabType) == int32(TABTYP_VIEW) {
			pSelect = (*(*struct {
				FpSelect uintptr
			})(unsafe.Pointer(&(*TTable)(unsafe.Pointer((**(**TParse)(__ccgo_up(bp + 32))).FpNewTable)).Fu))).FpSelect
			**(**Tu32)(__ccgo_up(pSelect + 4)) &= ^libc.Uint32FromInt32(SF_View)
			(**(**TParse)(__ccgo_up(bp + 32))).Frc = SQLITE_OK
			_sqlite3SelectPrep(tls, bp+32, pSelect, uintptr(0))
			if (*Tsqlite3)(unsafe.Pointer(db)).FmallocFailed != 0 {
				v1 = int32(SQLITE_NOMEM)
			} else {
				v1 = (**(**TParse)(__ccgo_up(bp + 32))).Frc
			}
			rc = v1
			if rc == SQLITE_OK {
				_sqlite3WalkSelect(tls, bp+456, pSelect)
			}
			if rc != SQLITE_OK {
				goto renameColumnFunc_done
			}
		} else {
			if libc.Int32FromUint8((*TTable)(unsafe.Pointer((**(**TParse)(__ccgo_up(bp + 32))).FpNewTable)).FeTabType) == TABTYP_NORM {
				/* A regular table */
				bFKOnly = Xsqlite3_stricmp(tls, zTable, (*TTable)(unsafe.Pointer((**(**TParse)(__ccgo_up(bp + 32))).FpNewTable)).FzName)
				(**(**TRenameCtx)(__ccgo_up(bp))).FpTab = (**(**TParse)(__ccgo_up(bp + 32))).FpNewTable
				if bFKOnly == 0 {
					if iCol < int32((*TTable)(unsafe.Pointer((**(**TParse)(__ccgo_up(bp + 32))).FpNewTable)).FnCol) {
						_renameTokenFind(tls, bp+32, bp, (**(**TColumn)(__ccgo_up((*TTable)(unsafe.Pointer((**(**TParse)(__ccgo_up(bp + 32))).FpNewTable)).FaCol + uintptr(iCol)*16))).FzCnName)
					}
					if (**(**TRenameCtx)(__ccgo_up(bp))).FiCol < 0 {
						_renameTokenFind(tls, bp+32, bp, (**(**TParse)(__ccgo_up(bp + 32))).FpNewTable+52)
					}
					_sqlite3WalkExprList(tls, bp+456, (*TTable)(unsafe.Pointer((**(**TParse)(__ccgo_up(bp + 32))).FpNewTable)).FpCheck)
					pIdx = (*TTable)(unsafe.Pointer((**(**TParse)(__ccgo_up(bp + 32))).FpNewTable)).FpIndex
					for {
						if !(pIdx != 0) {
							break
						}
						_sqlite3WalkExprList(tls, bp+456, (*TIndex)(unsafe.Pointer(pIdx)).FaColExpr)
						goto _3
					_3:
						;
						pIdx = (*TIndex)(unsafe.Pointer(pIdx)).FpNext
					}
					pIdx = (**(**TParse)(__ccgo_up(bp + 32))).FpNewIndex
					for {
						if !(pIdx != 0) {
							break
						}
						_sqlite3WalkExprList(tls, bp+456, (*TIndex)(unsafe.Pointer(pIdx)).FaColExpr)
						goto _4
					_4:
						;
						pIdx = (*TIndex)(unsafe.Pointer(pIdx)).FpNext
					}
					i = 0
					for {
						if !(i < int32((*TTable)(unsafe.Pointer((**(**TParse)(__ccgo_up(bp + 32))).FpNewTable)).FnCol)) {
							break
						}
						pExpr = _sqlite3ColumnExpr(tls, (**(**TParse)(__ccgo_up(bp + 32))).FpNewTable, (*TTable)(unsafe.Pointer((**(**TParse)(__ccgo_up(bp + 32))).FpNewTable)).FaCol+uintptr(i)*16)
						_sqlite3WalkExpr(tls, bp+456, pExpr)
						goto _5
					_5:
						;
						i = i + 1
					}
				}
				pFKey = (*(*struct {
					FaddColOffset int32
					FpFKey        uintptr
					FpDfltList    uintptr
				})(unsafe.Pointer((**(**TParse)(__ccgo_up(bp + 32))).FpNewTable + 64))).FpFKey
				for {
					if !(pFKey != 0) {
						break
					}
					i = 0
					for {
						if !(i < (*TFKey)(unsafe.Pointer(pFKey)).FnCol) {
							break
						}
						if bFKOnly == 0 && (*(*TsColMap)(unsafe.Pointer(pFKey + 64 + uintptr(i)*16))).FiFrom == iCol {
							_renameTokenFind(tls, bp+32, bp, pFKey+64+uintptr(i)*16)
						}
						if 0 == Xsqlite3_stricmp(tls, (*TFKey)(unsafe.Pointer(pFKey)).FzTo, zTable) && 0 == Xsqlite3_stricmp(tls, (*(*TsColMap)(unsafe.Pointer(pFKey + 64 + uintptr(i)*16))).FzCol, zOld) {
							_renameTokenFind(tls, bp+32, bp, (*(*TsColMap)(unsafe.Pointer(pFKey + 64 + uintptr(i)*16))).FzCol)
						}
						goto _7
					_7:
						;
						i = i + 1
					}
					goto _6
				_6:
					;
					pFKey = (*TFKey)(unsafe.Pointer(pFKey)).FpNextFrom
				}
			}
		}
	} else {
		if (**(**TParse)(__ccgo_up(bp + 32))).FpNewIndex != 0 {
			_sqlite3WalkExprList(tls, bp+456, (*TIndex)(unsafe.Pointer((**(**TParse)(__ccgo_up(bp + 32))).FpNewIndex)).FaColExpr)
			_sqlite3WalkExpr(tls, bp+456, (*TIndex)(unsafe.Pointer((**(**TParse)(__ccgo_up(bp + 32))).FpNewIndex)).FpPartIdxWhere)
		} else {
			rc = _renameResolveTrigger(tls, bp+32)
			if rc != SQLITE_OK {
				goto renameColumnFunc_done
			}
			pStep = (*TTrigger)(unsafe.Pointer((**(**TParse)(__ccgo_up(bp + 32))).FpNewTrigger)).Fstep_list
			for {
				if !(pStep != 0) {
					break
				}
				if (*TTriggerStep)(unsafe.Pointer(pStep)).FpSrc != 0 {
					pTarget = _sqlite3LocateTableItem(tls, bp+32, uint32(0), (*TTriggerStep)(unsafe.Pointer(pStep)).FpSrc+8)
					if pTarget == pTab {
						if (*TTriggerStep)(unsafe.Pointer(pStep)).FpUpsert != 0 {
							pUpsertSet = (*TUpsert)(unsafe.Pointer((*TTriggerStep)(unsafe.Pointer(pStep)).FpUpsert)).FpUpsertSet
							_renameColumnElistNames(tls, bp+32, bp, pUpsertSet, zOld)
						}
						_renameColumnIdlistNames(tls, bp+32, bp, (*TTriggerStep)(unsafe.Pointer(pStep)).FpIdList, zOld)
						_renameColumnElistNames(tls, bp+32, bp, (*TTriggerStep)(unsafe.Pointer(pStep)).FpExprList, zOld)
					}
				}
				goto _8
			_8:
				;
				pStep = (*TTriggerStep)(unsafe.Pointer(pStep)).FpNext
			}
			/* Find tokens to edit in UPDATE OF clause */
			if (**(**TParse)(__ccgo_up(bp + 32))).FpTriggerTab == pTab {
				_renameColumnIdlistNames(tls, bp+32, bp, (*TTrigger)(unsafe.Pointer((**(**TParse)(__ccgo_up(bp + 32))).FpNewTrigger)).FpColumns, zOld)
			}
			/* Find tokens to edit in various expressions and selects */
			_renameWalkTrigger(tls, bp+456, (**(**TParse)(__ccgo_up(bp + 32))).FpNewTrigger)
		}
	}
	rc = _renameEditSql(tls, context, bp, zSql, zNew, bQuote)
	goto renameColumnFunc_done
renameColumnFunc_done:
	;
	if rc != SQLITE_OK {
		if rc == int32(SQLITE_ERROR) && _sqlite3WritableSchema(tls, db) != 0 {
			Xsqlite3_result_value(tls, context, **(**uintptr)(__ccgo_up(argv)))
		} else {
			if (**(**TParse)(__ccgo_up(bp + 32))).FzErrMsg != 0 {
				_renameColumnParseError(tls, context, __ccgo_ts+1693, **(**uintptr)(__ccgo_up(argv + 1*8)), **(**uintptr)(__ccgo_up(argv + 2*8)), bp+32)
			} else {
				Xsqlite3_result_error_code(tls, context, rc)
			}
		}
	}
	_renameParseCleanup(tls, bp+32)
	_renameTokenFree(tls, db, (**(**TRenameCtx)(__ccgo_up(bp))).FpList)
	(*Tsqlite3)(unsafe.Pointer(db)).FxAuth = xAuth
	_sqlite3BtreeLeaveAll(tls, db)
}

// C documentation
//
//	/*
//	** Generate VM code to replace any double-quoted strings (but not double-quoted
//	** identifiers) within the "sql" column of the sqlite_schema table in
//	** database zDb with their single-quoted equivalents. If argument bTemp is
//	** not true, similarly update all SQL statements in the sqlite_schema table
//	** of the temp db.
//	*/
func _renameFixQuotes(tls *libc.TLS, pParse uintptr, zDb uintptr, bTemp int32) {
	bp := tls.Alloc(32)
	defer tls.Free(32)
	_sqlite3NestedParse(tls, pParse, __ccgo_ts+9013, libc.VaList(bp+8, zDb, zDb))
	if bTemp == 0 {
		_sqlite3NestedParse(tls, pParse, __ccgo_ts+9160, 0)
	}
}

// C documentation
//
//	/*
//	** Parse the SQL statement zSql using Parse object (*p). The Parse object
//	** is initialized by this function before it is used.
//	*/
func _renameParseSql(tls *libc.TLS, p uintptr, zDb uintptr, db uintptr, zSql uintptr, bTemp int32) (r int32) {
	var flags Tu64
	var iDb, rc int32
	_, _, _ = flags, iDb, rc
	_sqlite3ParseObjectInit(tls, p, db)
	if zSql == uintptr(0) {
		return int32(SQLITE_NOMEM)
	}
	if Xsqlite3_strnicmp(tls, zSql, __ccgo_ts+11559, int32(7)) != 0 {
		return _sqlite3CorruptError(tls, int32(121717))
	}
	if bTemp != 0 {
		(*Tsqlite3)(unsafe.Pointer(db)).Finit1.FiDb = uint8(1)
	} else {
		iDb = _sqlite3FindDbName(tls, db, zDb)
		(*Tsqlite3)(unsafe.Pointer(db)).Finit1.FiDb = libc.Uint8FromInt32(iDb)
	}
	(*TParse)(unsafe.Pointer(p)).FeParseMode = uint8(PARSE_MODE_RENAME)
	(*TParse)(unsafe.Pointer(p)).Fdb = db
	(*TParse)(unsafe.Pointer(p)).FnQueryLoop = int16(1)
	flags = (*Tsqlite3)(unsafe.Pointer(db)).Fflags
	**(**Tu64)(__ccgo_up(db + 48)) |= libc.Uint64FromInt32(libc.Int32FromInt32(0x00040)) << libc.Int32FromInt32(32)
	rc = _sqlite3RunParser(tls, p, zSql)
	(*Tsqlite3)(unsafe.Pointer(db)).Fflags = flags
	if (*Tsqlite3)(unsafe.Pointer(db)).FmallocFailed != 0 {
		rc = int32(SQLITE_NOMEM)
	}
	if rc == SQLITE_OK && ((*TParse)(unsafe.Pointer(p)).FpNewTable == uintptr(0) && (*TParse)(unsafe.Pointer(p)).FpNewIndex == uintptr(0) && (*TParse)(unsafe.Pointer(p)).FpNewTrigger == uintptr(0)) {
		rc = _sqlite3CorruptError(tls, int32(121738))
	}
	(*Tsqlite3)(unsafe.Pointer(db)).Finit1.FiDb = uint8(0)
	return rc
}

// C documentation
//
//	/*
//	** This C function implements an SQL user function that is used by SQL code
//	** generated by the ALTER TABLE ... RENAME command to modify the definition
//	** of any foreign key constraints that use the table being renamed as the
//	** parent table. It is passed three arguments:
//	**
//	**   0: The database containing the table being renamed.
//	**   1. type:     Type of object ("table", "view" etc.)
//	**   2. object:   Name of object
//	**   3: The complete text of the schema statement being modified,
//	**   4: The old name of the table being renamed, and
//	**   5: The new name of the table being renamed.
//	**   6: True if the schema statement comes from the temp db.
//	**
//	** It returns the new schema statement. For example:
//	**
//	** sqlite_rename_table('main', 'CREATE TABLE t1(a REFERENCES t2)','t2','t3',0)
//	**       -> 'CREATE TABLE t1(a REFERENCES t3)'
//	*/
func _renameTableFunc(tls *libc.TLS, context uintptr, NotUsed int32, argv uintptr) {
	bp := tls.Alloc(560)
	defer tls.Free(560)
	var bQuote, bTemp, i, isLegacy, rc int32
	var db, pFKey, pItem, pSelect, pStep, pTab, pTrigger, zDb, zInput, zNew, zOld uintptr
	var xAuth Tsqlite3_xauth
	var _ /* sCtx at bp+424 */ TRenameCtx
	var _ /* sNC at bp+504 */ TNameContext
	var _ /* sParse at bp+0 */ TParse
	var _ /* sWalker at bp+456 */ TWalker
	_, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _ = bQuote, bTemp, db, i, isLegacy, pFKey, pItem, pSelect, pStep, pTab, pTrigger, rc, xAuth, zDb, zInput, zNew, zOld
	db = Xsqlite3_context_db_handle(tls, context)
	zDb = Xsqlite3_value_text(tls, **(**uintptr)(__ccgo_up(argv)))
	zInput = Xsqlite3_value_text(tls, **(**uintptr)(__ccgo_up(argv + 3*8)))
	zOld = Xsqlite3_value_text(tls, **(**uintptr)(__ccgo_up(argv + 4*8)))
	zNew = Xsqlite3_value_text(tls, **(**uintptr)(__ccgo_up(argv + 5*8)))
	bTemp = Xsqlite3_value_int(tls, **(**uintptr)(__ccgo_up(argv + 6*8)))
	_ = NotUsed
	if zInput != 0 && zOld != 0 && zNew != 0 {
		bQuote = int32(1)
		xAuth = (*Tsqlite3)(unsafe.Pointer(db)).FxAuth
		(*Tsqlite3)(unsafe.Pointer(db)).FxAuth = uintptr(0)
		_sqlite3BtreeEnterAll(tls, db)
		libc.Xmemset(tls, bp+424, 0, uint64(32))
		(**(**TRenameCtx)(__ccgo_up(bp + 424))).FpTab = _sqlite3FindTable(tls, db, zOld, zDb)
		libc.Xmemset(tls, bp+456, 0, uint64(48))
		(**(**TWalker)(__ccgo_up(bp + 456))).FpParse = bp
		(**(**TWalker)(__ccgo_up(bp + 456))).FxExprCallback = __ccgo_fp(_renameTableExprCb)
		(**(**TWalker)(__ccgo_up(bp + 456))).FxSelectCallback = __ccgo_fp(_renameTableSelectCb)
		*(*uintptr)(unsafe.Pointer(bp + 456 + 40)) = bp + 424
		rc = _renameParseSql(tls, bp, zDb, db, zInput, bTemp)
		if rc == SQLITE_OK {
			isLegacy = libc.Int32FromUint64((*Tsqlite3)(unsafe.Pointer(db)).Fflags & libc.Uint64FromInt32(SQLITE_LegacyAlter))
			if (**(**TParse)(__ccgo_up(bp))).FpNewTable != 0 {
				pTab = (**(**TParse)(__ccgo_up(bp))).FpNewTable
				if libc.Int32FromUint8((*TTable)(unsafe.Pointer(pTab)).FeTabType) == int32(TABTYP_VIEW) {
					if isLegacy == 0 {
						pSelect = (*(*struct {
							FpSelect uintptr
						})(unsafe.Pointer(&(*TTable)(unsafe.Pointer(pTab)).Fu))).FpSelect
						libc.Xmemset(tls, bp+504, 0, uint64(56))
						(**(**TNameContext)(__ccgo_up(bp + 504))).FpParse = bp
						**(**Tu32)(__ccgo_up(pSelect + 4)) &= ^libc.Uint32FromInt32(SF_View)
						_sqlite3SelectPrep(tls, bp, (*(*struct {
							FpSelect uintptr
						})(unsafe.Pointer(&(*TTable)(unsafe.Pointer(pTab)).Fu))).FpSelect, bp+504)
						if (**(**TParse)(__ccgo_up(bp))).FnErr != 0 {
							rc = (**(**TParse)(__ccgo_up(bp))).Frc
						} else {
							_sqlite3WalkSelect(tls, bp+456, (*(*struct {
								FpSelect uintptr
							})(unsafe.Pointer(&(*TTable)(unsafe.Pointer(pTab)).Fu))).FpSelect)
						}
					}
				} else {
					/* Modify any FK definitions to point to the new table. */
					if (isLegacy == 0 || (*Tsqlite3)(unsafe.Pointer(db)).Fflags&uint64(SQLITE_ForeignKeys) != 0) && !(libc.Int32FromUint8((*TTable)(unsafe.Pointer(pTab)).FeTabType) == libc.Int32FromInt32(TABTYP_VTAB)) {
						pFKey = (*(*struct {
							FaddColOffset int32
							FpFKey        uintptr
							FpDfltList    uintptr
						})(unsafe.Pointer(pTab + 64))).FpFKey
						for {
							if !(pFKey != 0) {
								break
							}
							if Xsqlite3_stricmp(tls, (*TFKey)(unsafe.Pointer(pFKey)).FzTo, zOld) == 0 {
								_renameTokenFind(tls, bp, bp+424, (*TFKey)(unsafe.Pointer(pFKey)).FzTo)
							}
							goto _1
						_1:
							;
							pFKey = (*TFKey)(unsafe.Pointer(pFKey)).FpNextFrom
						}
					}
					/* If this is the table being altered, fix any table refs in CHECK
					 ** expressions. Also update the name that appears right after the
					 ** "CREATE [VIRTUAL] TABLE" bit. */
					if Xsqlite3_stricmp(tls, zOld, (*TTable)(unsafe.Pointer(pTab)).FzName) == 0 {
						(**(**TRenameCtx)(__ccgo_up(bp + 424))).FpTab = pTab
						if isLegacy == 0 {
							_sqlite3WalkExprList(tls, bp+456, (*TTable)(unsafe.Pointer(pTab)).FpCheck)
						}
						_renameTokenFind(tls, bp, bp+424, (*TTable)(unsafe.Pointer(pTab)).FzName)
					}
				}
			} else {
				if (**(**TParse)(__ccgo_up(bp))).FpNewIndex != 0 {
					_renameTokenFind(tls, bp, bp+424, (*TIndex)(unsafe.Pointer((**(**TParse)(__ccgo_up(bp))).FpNewIndex)).FzName)
					if isLegacy == 0 {
						_sqlite3WalkExpr(tls, bp+456, (*TIndex)(unsafe.Pointer((**(**TParse)(__ccgo_up(bp))).FpNewIndex)).FpPartIdxWhere)
					}
				} else {
					pTrigger = (**(**TParse)(__ccgo_up(bp))).FpNewTrigger
					if 0 == Xsqlite3_stricmp(tls, (*TTrigger)(unsafe.Pointer((**(**TParse)(__ccgo_up(bp))).FpNewTrigger)).Ftable, zOld) && (*TTable)(unsafe.Pointer((**(**TRenameCtx)(__ccgo_up(bp + 424))).FpTab)).FpSchema == (*TTrigger)(unsafe.Pointer(pTrigger)).FpTabSchema {
						_renameTokenFind(tls, bp, bp+424, (*TTrigger)(unsafe.Pointer((**(**TParse)(__ccgo_up(bp))).FpNewTrigger)).Ftable)
					}
					if isLegacy == 0 {
						rc = _renameResolveTrigger(tls, bp)
						if rc == SQLITE_OK {
							_renameWalkTrigger(tls, bp+456, pTrigger)
							pStep = (*TTrigger)(unsafe.Pointer(pTrigger)).Fstep_list
							for {
								if !(pStep != 0) {
									break
								}
								if (*TTriggerStep)(unsafe.Pointer(pStep)).FpSrc != 0 {
									i = 0
									for {
										if !(i < (*TSrcList)(unsafe.Pointer((*TTriggerStep)(unsafe.Pointer(pStep)).FpSrc)).FnSrc) {
											break
										}
										pItem = (*TTriggerStep)(unsafe.Pointer(pStep)).FpSrc + 8 + uintptr(i)*80
										if 0 == Xsqlite3_stricmp(tls, (*TSrcItem)(unsafe.Pointer(pItem)).FzName, zOld) {
											_renameTokenFind(tls, bp, bp+424, (*TSrcItem)(unsafe.Pointer(pItem)).FzName)
										}
										goto _3
									_3:
										;
										i = i + 1
									}
								}
								goto _2
							_2:
								;
								pStep = (*TTriggerStep)(unsafe.Pointer(pStep)).FpNext
							}
						}
					}
				}
			}
		}
		if rc == SQLITE_OK {
			rc = _renameEditSql(tls, context, bp+424, zInput, zNew, bQuote)
		}
		if rc != SQLITE_OK {
			if rc == int32(SQLITE_ERROR) && _sqlite3WritableSchema(tls, db) != 0 {
				Xsqlite3_result_value(tls, context, **(**uintptr)(__ccgo_up(argv + 3*8)))
			} else {
				if (**(**TParse)(__ccgo_up(bp))).FzErrMsg != 0 {
					_renameColumnParseError(tls, context, __ccgo_ts+1693, **(**uintptr)(__ccgo_up(argv + 1*8)), **(**uintptr)(__ccgo_up(argv + 2*8)), bp)
				} else {
					Xsqlite3_result_error_code(tls, context, rc)
				}
			}
		}
		_renameParseCleanup(tls, bp)
		_renameTokenFree(tls, db, (**(**TRenameCtx)(__ccgo_up(bp + 424))).FpList)
		_sqlite3BtreeLeaveAll(tls, db)
		(*Tsqlite3)(unsafe.Pointer(db)).FxAuth = xAuth
	}
	return
}

// C documentation
//
//	/*
//	** Generate code to verify that the schemas of database zDb and, if
//	** bTemp is not true, database "temp", can still be parsed. This is
//	** called at the end of the generation of an ALTER TABLE ... RENAME ...
//	** statement to ensure that the operation has not rendered any schema
//	** objects unusable.
//	*/
func _renameTestSchema(tls *libc.TLS, pParse uintptr, zDb uintptr, bTemp int32, zWhen uintptr, bNoDQS int32) {
	bp := tls.Alloc(48)
	defer tls.Free(48)
	libc.SetBitFieldPtr16Uint32(pParse+40, libc.Uint32FromInt32(1), 5, 0x20)
	_sqlite3NestedParse(tls, pParse, __ccgo_ts+8664, libc.VaList(bp+8, zDb, zDb, bTemp, zWhen, bNoDQS))
	if bTemp == 0 {
		_sqlite3NestedParse(tls, pParse, __ccgo_ts+8839, libc.VaList(bp+8, zDb, zWhen, bNoDQS))
	}
}

// C documentation
//
//	/*
//	** Reset the aggregate accumulator.
//	**
//	** The aggregate accumulator is a set of memory cells that hold
//	** intermediate results while calculating an aggregate.  This
//	** routine generates code that stores NULLs in all of those memory
//	** cells.
//	*/
func _resetAccumulator(tls *libc.TLS, pParse uintptr, pAggInfo uintptr) {
	bp := tls.Alloc(16)
	defer tls.Free(16)
	var i, nExtra, nReg int32
	var pE, pFunc, pKeyInfo, pKeyInfo1, pOBList, v uintptr
	_, _, _, _, _, _, _, _, _ = i, nExtra, nReg, pE, pFunc, pKeyInfo, pKeyInfo1, pOBList, v
	v = (*TParse)(unsafe.Pointer(pParse)).FpVdbe
	nReg = (*TAggInfo)(unsafe.Pointer(pAggInfo)).FnFunc + (*TAggInfo)(unsafe.Pointer(pAggInfo)).FnColumn
	if nReg == 0 {
		return
	}
	if (*TParse)(unsafe.Pointer(pParse)).FnErr != 0 {
		return
	}
	_sqlite3VdbeAddOp3(tls, v, int32(OP_Null), 0, (*TAggInfo)(unsafe.Pointer(pAggInfo)).FiFirstReg, (*TAggInfo)(unsafe.Pointer(pAggInfo)).FiFirstReg+nReg-int32(1))
	pFunc = (*TAggInfo)(unsafe.Pointer(pAggInfo)).FaFunc
	i = libc.Int32FromInt32(0)
	for {
		if !(i < (*TAggInfo)(unsafe.Pointer(pAggInfo)).FnFunc) {
			break
		}
		if (*TAggInfo_func)(unsafe.Pointer(pFunc)).FiDistinct >= 0 {
			pE = (*TAggInfo_func)(unsafe.Pointer(pFunc)).FpFExpr
			if *(*uintptr)(unsafe.Pointer(pE + 32)) == uintptr(0) || (*TExprList)(unsafe.Pointer(*(*uintptr)(unsafe.Pointer(pE + 32)))).FnExpr != int32(1) {
				_sqlite3ErrorMsg(tls, pParse, __ccgo_ts+21401, 0)
				(*TAggInfo_func)(unsafe.Pointer(pFunc)).FiDistinct = -int32(1)
			} else {
				pKeyInfo = _sqlite3KeyInfoFromExprList(tls, pParse, *(*uintptr)(unsafe.Pointer(pE + 32)), 0, 0)
				(*TAggInfo_func)(unsafe.Pointer(pFunc)).FiDistAddr = _sqlite3VdbeAddOp4(tls, v, int32(OP_OpenEphemeral), (*TAggInfo_func)(unsafe.Pointer(pFunc)).FiDistinct, 0, 0, pKeyInfo, -int32(9))
				_sqlite3VdbeExplain(tls, pParse, uint8(0), __ccgo_ts+21452, libc.VaList(bp+8, (*TFuncDef)(unsafe.Pointer((*TAggInfo_func)(unsafe.Pointer(pFunc)).FpFunc)).FzName))
			}
		}
		if (*TAggInfo_func)(unsafe.Pointer(pFunc)).FiOBTab >= 0 {
			nExtra = 0
			pOBList = *(*uintptr)(unsafe.Pointer((*TExpr)(unsafe.Pointer((*TAggInfo_func)(unsafe.Pointer(pFunc)).FpFExpr)).FpLeft + 32))
			if !((*TAggInfo_func)(unsafe.Pointer(pFunc)).FbOBUnique != 0) {
				nExtra = nExtra + 1 /* One extra column for the OP_Sequence */
			}
			if (*TAggInfo_func)(unsafe.Pointer(pFunc)).FbOBPayload != 0 {
				/* extra columns for the function arguments */
				nExtra = nExtra + (*TExprList)(unsafe.Pointer(*(*uintptr)(unsafe.Pointer((*TAggInfo_func)(unsafe.Pointer(pFunc)).FpFExpr + 32)))).FnExpr
			}
			if (*TAggInfo_func)(unsafe.Pointer(pFunc)).FbUseSubtype != 0 {
				nExtra = nExtra + (*TExprList)(unsafe.Pointer(*(*uintptr)(unsafe.Pointer((*TAggInfo_func)(unsafe.Pointer(pFunc)).FpFExpr + 32)))).FnExpr
			}
			pKeyInfo1 = _sqlite3KeyInfoFromExprList(tls, pParse, pOBList, 0, nExtra)
			if !((*TAggInfo_func)(unsafe.Pointer(pFunc)).FbOBUnique != 0) && (*TParse)(unsafe.Pointer(pParse)).FnErr == 0 {
				(*TKeyInfo)(unsafe.Pointer(pKeyInfo1)).FnKeyField = (*TKeyInfo)(unsafe.Pointer(pKeyInfo1)).FnKeyField + 1
			}
			_sqlite3VdbeAddOp4(tls, v, int32(OP_OpenEphemeral), (*TAggInfo_func)(unsafe.Pointer(pFunc)).FiOBTab, (*TExprList)(unsafe.Pointer(pOBList)).FnExpr+nExtra, 0, pKeyInfo1, -int32(9))
			_sqlite3VdbeExplain(tls, pParse, uint8(0), __ccgo_ts+21485, libc.VaList(bp+8, (*TFuncDef)(unsafe.Pointer((*TAggInfo_func)(unsafe.Pointer(pFunc)).FpFunc)).FzName))
		}
		goto _1
	_1:
		;
		i = i + 1
		pFunc += 32
	}
}

// C documentation
//
//	/*
//	** Reset the SQL statement passed as the first argument. Return a copy
//	** of the value returned by sqlite3_reset().
//	**
//	** If an error has occurred, then set *pzErrmsg to point to a buffer
//	** containing an error message. It is the responsibility of the caller
//	** to eventually free this buffer using sqlite3_free().
//	*/
func _resetAndCollectError(tls *libc.TLS, pStmt uintptr, pzErrmsg uintptr) (r int32) {
	bp := tls.Alloc(16)
	defer tls.Free(16)
	var rc int32
	_ = rc
	rc = Xsqlite3_reset(tls, pStmt)
	if rc != SQLITE_OK {
		**(**uintptr)(__ccgo_up(pzErrmsg)) = Xsqlite3_mprintf(tls, __ccgo_ts+3933, libc.VaList(bp+8, Xsqlite3_errmsg(tls, Xsqlite3_db_handle(tls, pStmt))))
	}
	return rc
}

// C documentation
//
//	/*
//	** Analyze the ORDER BY clause in a compound SELECT statement.   Modify
//	** each term of the ORDER BY clause is a constant integer between 1
//	** and N where N is the number of columns in the compound SELECT.
//	**
//	** ORDER BY terms that are already an integer between 1 and N are
//	** unmodified.  ORDER BY terms that are integers outside the range of
//	** 1 through N generate an error.  ORDER BY terms that are expressions
//	** are matched against result set expressions of compound SELECT
//	** beginning with the left-most SELECT and working toward the right.
//	** At the first match, the ORDER BY expression is transformed into
//	** the integer column number.
//	**
//	** Return the number of errors seen.
//	*/
func _resolveCompoundOrderBy(tls *libc.TLS, pParse uintptr, pSelect uintptr) (r int32) {
	bp := tls.Alloc(32)
	defer tls.Free(32)
	var db, pDup, pE, pEList, pItem, pNew, pOrderBy, pParent uintptr
	var i, moreToDo int32
	var _ /* iCol at bp+0 */ int32
	_, _, _, _, _, _, _, _, _, _ = db, i, moreToDo, pDup, pE, pEList, pItem, pNew, pOrderBy, pParent
	moreToDo = int32(1)
	pOrderBy = (*TSelect)(unsafe.Pointer(pSelect)).FpOrderBy
	if pOrderBy == uintptr(0) {
		return 0
	}
	db = (*TParse)(unsafe.Pointer(pParse)).Fdb
	if (*TExprList)(unsafe.Pointer(pOrderBy)).FnExpr > **(**int32)(__ccgo_up(db + 136 + 2*4)) {
		_sqlite3ErrorMsg(tls, pParse, __ccgo_ts+7618, 0)
		return int32(1)
	}
	i = 0
	for {
		if !(i < (*TExprList)(unsafe.Pointer(pOrderBy)).FnExpr) {
			break
		}
		libc.SetBitFieldPtr16Uint32(pOrderBy+8+uintptr(i)*32+16+4, libc.Uint32FromInt32(0), 2, 0x4)
		goto _1
	_1:
		;
		i = i + 1
	}
	(*TSelect)(unsafe.Pointer(pSelect)).FpNext = uintptr(0)
	for (*TSelect)(unsafe.Pointer(pSelect)).FpPrior != 0 {
		(*TSelect)(unsafe.Pointer((*TSelect)(unsafe.Pointer(pSelect)).FpPrior)).FpNext = pSelect
		pSelect = (*TSelect)(unsafe.Pointer(pSelect)).FpPrior
	}
	for pSelect != 0 && moreToDo != 0 {
		moreToDo = 0
		pEList = (*TSelect)(unsafe.Pointer(pSelect)).FpEList
		i = 0
		pItem = pOrderBy + 8
		for {
			if !(i < (*TExprList)(unsafe.Pointer(pOrderBy)).FnExpr) {
				break
			}
			**(**int32)(__ccgo_up(bp)) = -int32(1)
			if int32(uint32(*(*uint16)(unsafe.Pointer(pItem + 16 + 4))&0x4>>2)) != 0 {
				goto _2
			}
			pE = _sqlite3ExprSkipCollateAndLikely(tls, (*TExprList_item)(unsafe.Pointer(pItem)).FpExpr)
			if pE == uintptr(0) {
				goto _2
			}
			if _sqlite3ExprIsInteger(tls, pE, bp, uintptr(0)) != 0 {
				if **(**int32)(__ccgo_up(bp)) <= 0 || **(**int32)(__ccgo_up(bp)) > (*TExprList)(unsafe.Pointer(pEList)).FnExpr {
					_resolveOutOfRangeError(tls, pParse, __ccgo_ts+7652, i+int32(1), (*TExprList)(unsafe.Pointer(pEList)).FnExpr, pE)
					return int32(1)
				}
			} else {
				**(**int32)(__ccgo_up(bp)) = _resolveAsName(tls, pParse, pEList, pE)
				if **(**int32)(__ccgo_up(bp)) == 0 {
					/* Now test if expression pE matches one of the values returned
					 ** by pSelect. In the usual case this is done by duplicating the
					 ** expression, resolving any symbols in it, and then comparing
					 ** it against each expression returned by the SELECT statement.
					 ** Once the comparisons are finished, the duplicate expression
					 ** is deleted.
					 **
					 ** If this is running as part of an ALTER TABLE operation and
					 ** the symbols resolve successfully, also resolve the symbols in the
					 ** actual expression. This allows the code in alter.c to modify
					 ** column references within the ORDER BY expression as required.  */
					pDup = _sqlite3ExprDup(tls, db, pE, 0)
					if !((*Tsqlite3)(unsafe.Pointer(db)).FmallocFailed != 0) {
						**(**int32)(__ccgo_up(bp)) = _resolveOrderByTermToExprList(tls, pParse, pSelect, pDup)
						if libc.Int32FromUint8((*TParse)(unsafe.Pointer(pParse)).FeParseMode) >= int32(PARSE_MODE_RENAME) && **(**int32)(__ccgo_up(bp)) > 0 {
							_resolveOrderByTermToExprList(tls, pParse, pSelect, pE)
						}
					}
					_sqlite3ExprDelete(tls, db, pDup)
				}
			}
			if **(**int32)(__ccgo_up(bp)) > 0 {
				/* Convert the ORDER BY term into an integer column number iCol,
				 ** taking care to preserve the COLLATE clause if it exists. */
				if !(libc.Int32FromUint8((*TParse)(unsafe.Pointer(pParse)).FeParseMode) >= libc.Int32FromInt32(PARSE_MODE_RENAME)) {
					pNew = _sqlite3ExprInt32(tls, db, **(**int32)(__ccgo_up(bp)))
					if pNew == uintptr(0) {
						return int32(1)
					}
					if (*TExprList_item)(unsafe.Pointer(pItem)).FpExpr == pE {
						(*TExprList_item)(unsafe.Pointer(pItem)).FpExpr = pNew
					} else {
						pParent = (*TExprList_item)(unsafe.Pointer(pItem)).FpExpr
						for libc.Int32FromUint8((*TExpr)(unsafe.Pointer((*TExpr)(unsafe.Pointer(pParent)).FpLeft)).Fop) == int32(TK_COLLATE) {
							pParent = (*TExpr)(unsafe.Pointer(pParent)).FpLeft
						}
						(*TExpr)(unsafe.Pointer(pParent)).FpLeft = pNew
					}
					_sqlite3ExprDelete(tls, db, pE)
					(*(*struct {
						FiOrderByCol Tu16
						FiAlias      Tu16
					})(unsafe.Pointer(pItem + 24))).FiOrderByCol = libc.Uint16FromInt32(**(**int32)(__ccgo_up(bp)))
				}
				libc.SetBitFieldPtr16Uint32(pItem+16+4, libc.Uint32FromInt32(1), 2, 0x4)
			} else {
				moreToDo = int32(1)
			}
			goto _2
		_2:
			;
			i = i + 1
			pItem += 32
		}
		pSelect = (*TSelect)(unsafe.Pointer(pSelect)).FpNext
	}
	i = 0
	for {
		if !(i < (*TExprList)(unsafe.Pointer(pOrderBy)).FnExpr) {
			break
		}
		if int32(uint32(*(*uint16)(unsafe.Pointer(pOrderBy + 8 + uintptr(i)*32 + 16 + 4))&0x4>>2)) == 0 {
			_sqlite3ErrorMsg(tls, pParse, __ccgo_ts+7658, libc.VaList(bp+16, i+int32(1)))
			return int32(1)
		}
		goto _3
	_3:
		;
		i = i + 1
	}
	return 0
}

// C documentation
//
//	/*
//	** This function checks if argument pFrom refers to a CTE declared by
//	** a WITH clause on the stack currently maintained by the parser (on the
//	** pParse->pWith linked list).  And if currently processing a CTE
//	** CTE expression, through routine checks to see if the reference is
//	** a recursive reference to the CTE.
//	**
//	** If pFrom matches a CTE according to either of these two above, pFrom->pSTab
//	** and other fields are populated accordingly.
//	**
//	** Return 0 if no match is found.
//	** Return 1 if a match is found.
//	** Return 2 if an error condition is detected.
//	*/
func _resolveFromTermToCte(tls *libc.TLS, pParse uintptr, pWalker uintptr, pFrom uintptr) (r int32) {
	bp := tls.Alloc(48)
	defer tls.Free(48)
	var bMayRecursive, i, iRecTab, rc, v3 int32
	var db, pCte, pCteUse, pEList, pItem, pLeft, pRecTerm, pSavedWith, pSel, pSrc, pTab, v1 uintptr
	var _ /* pWith at bp+0 */ uintptr
	_, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _ = bMayRecursive, db, i, iRecTab, pCte, pCteUse, pEList, pItem, pLeft, pRecTerm, pSavedWith, pSel, pSrc, pTab, rc, v1, v3 /* The matching WITH */
	if (*TParse)(unsafe.Pointer(pParse)).FpWith == uintptr(0) {
		/* There are no WITH clauses in the stack.  No match is possible */
		return 0
	}
	if (*TParse)(unsafe.Pointer(pParse)).FnErr != 0 {
		/* Prior errors might have left pParse->pWith in a goofy state, so
		 ** go no further. */
		return 0
	}
	if int32(*(*uint32)(unsafe.Pointer(pFrom + 24 + 4))&0x10000>>16) == 0 && *(*uintptr)(unsafe.Pointer(pFrom + 72)) != uintptr(0) {
		/* The FROM term contains a schema qualifier (ex: main.t1) and so
		 ** it cannot possibly be a CTE reference. */
		return 0
	}
	if int32(*(*uint32)(unsafe.Pointer(pFrom + 24 + 4))&0x400>>10) != 0 {
		/* The FROM term is specifically excluded from matching a CTE.
		 **   (1)  It is part of a trigger that used to have zDatabase but had
		 **        zDatabase removed by sqlite3FixTriggerStep().
		 **   (2)  This is the first term in the FROM clause of an UPDATE.
		 */
		return 0
	}
	pCte = _searchWith(tls, (*TParse)(unsafe.Pointer(pParse)).FpWith, pFrom, bp)
	if pCte != 0 {
		db = (*TParse)(unsafe.Pointer(pParse)).Fdb /* Initial value of pParse->pWith */
		iRecTab = -int32(1)
		/* If pCte->zCteErr is non-NULL at this point, then this is an illegal
		 ** recursive reference to CTE pCte. Leave an error in pParse and return
		 ** early. If pCte->zCteErr is NULL, then this is not a recursive reference.
		 ** In this case, proceed.  */
		if (*TCte)(unsafe.Pointer(pCte)).FzCteErr != 0 {
			_sqlite3ErrorMsg(tls, pParse, (*TCte)(unsafe.Pointer(pCte)).FzCteErr, libc.VaList(bp+16, (*TCte)(unsafe.Pointer(pCte)).FzName))
			return int32(2)
		}
		if _cannotBeFunction(tls, pParse, pFrom) != 0 {
			return int32(2)
		}
		pTab = _sqlite3DbMallocZero(tls, db, uint64(120))
		if pTab == uintptr(0) {
			return int32(2)
		}
		pCteUse = (*TCte)(unsafe.Pointer(pCte)).FpUse
		if pCteUse == uintptr(0) {
			v1 = _sqlite3DbMallocZero(tls, db, uint64(20))
			pCteUse = v1
			(*TCte)(unsafe.Pointer(pCte)).FpUse = v1
			if pCteUse == uintptr(0) || _sqlite3ParserAddCleanup(tls, pParse, __ccgo_fp(_sqlite3DbFree), pCteUse) == uintptr(0) {
				_sqlite3DbFree(tls, db, pTab)
				return int32(2)
			}
			(*TCteUse)(unsafe.Pointer(pCteUse)).FeM10d = (*TCte)(unsafe.Pointer(pCte)).FeM10d
		}
		(*TSrcItem)(unsafe.Pointer(pFrom)).FpSTab = pTab
		(*TTable)(unsafe.Pointer(pTab)).FnTabRef = uint32(1)
		(*TTable)(unsafe.Pointer(pTab)).FzName = _sqlite3DbStrDup(tls, db, (*TCte)(unsafe.Pointer(pCte)).FzName)
		(*TTable)(unsafe.Pointer(pTab)).FiPKey = int16(-int32(1))
		(*TTable)(unsafe.Pointer(pTab)).FnRowLogEst = int16(200)
		**(**Tu32)(__ccgo_up(pTab + 48)) |= libc.Uint32FromInt32(libc.Int32FromInt32(TF_Ephemeral) | libc.Int32FromInt32(TF_NoVisibleRowid))
		_sqlite3SrcItemAttachSubquery(tls, pParse, pFrom, (*TCte)(unsafe.Pointer(pCte)).FpSelect, int32(1))
		if (*Tsqlite3)(unsafe.Pointer(db)).FmallocFailed != 0 {
			return int32(2)
		}
		pSel = (*TSubquery)(unsafe.Pointer(*(*uintptr)(unsafe.Pointer(pFrom + 72)))).FpSelect
		**(**Tu32)(__ccgo_up(pSel + 4)) |= uint32(SF_CopyCte)
		if int32(*(*uint32)(unsafe.Pointer(pFrom + 24 + 4))&0x2>>1) != 0 {
			_sqlite3ErrorMsg(tls, pParse, __ccgo_ts+21048, libc.VaList(bp+16, *(*uintptr)(unsafe.Pointer(pFrom + 48))))
			return int32(2)
		}
		libc.SetBitFieldPtr32Uint32(pFrom+24+4, libc.Uint32FromInt32(1), 9, 0x200)
		*(*uintptr)(unsafe.Pointer(pFrom + 56)) = pCteUse
		(*TCteUse)(unsafe.Pointer(pCteUse)).FnUse = (*TCteUse)(unsafe.Pointer(pCteUse)).FnUse + 1
		/* Check if this is a recursive CTE. */
		pRecTerm = pSel
		bMayRecursive = libc.BoolInt32(libc.Int32FromUint8((*TSelect)(unsafe.Pointer(pSel)).Fop) == int32(TK_ALL) || libc.Int32FromUint8((*TSelect)(unsafe.Pointer(pSel)).Fop) == int32(TK_UNION))
		for bMayRecursive != 0 && libc.Int32FromUint8((*TSelect)(unsafe.Pointer(pRecTerm)).Fop) == libc.Int32FromUint8((*TSelect)(unsafe.Pointer(pSel)).Fop) {
			pSrc = (*TSelect)(unsafe.Pointer(pRecTerm)).FpSrc
			i = 0
			for {
				if !(i < (*TSrcList)(unsafe.Pointer(pSrc)).FnSrc) {
					break
				}
				pItem = pSrc + 8 + uintptr(i)*80
				if (*TSrcItem)(unsafe.Pointer(pItem)).FzName != uintptr(0) && !(int32(*(*uint32)(unsafe.Pointer(pItem + 24 + 4))&0x20000>>17) != 0) && !(int32(*(*uint32)(unsafe.Pointer(pItem + 24 + 4))&0x4>>2) != 0) && (int32(*(*uint32)(unsafe.Pointer(pItem + 24 + 4))&0x10000>>16) != 0 || *(*uintptr)(unsafe.Pointer(pItem + 72)) == uintptr(0)) && 0 == _sqlite3StrICmp(tls, (*TSrcItem)(unsafe.Pointer(pItem)).FzName, (*TCte)(unsafe.Pointer(pCte)).FzName) {
					(*TSrcItem)(unsafe.Pointer(pItem)).FpSTab = pTab
					(*TTable)(unsafe.Pointer(pTab)).FnTabRef = (*TTable)(unsafe.Pointer(pTab)).FnTabRef + 1
					libc.SetBitFieldPtr32Uint32(pItem+24+4, libc.Uint32FromInt32(1), 7, 0x80)
					if (*TSelect)(unsafe.Pointer(pRecTerm)).FselFlags&uint32(SF_Recursive) != 0 {
						_sqlite3ErrorMsg(tls, pParse, __ccgo_ts+21068, libc.VaList(bp+16, (*TCte)(unsafe.Pointer(pCte)).FzName))
						return int32(2)
					}
					**(**Tu32)(__ccgo_up(pRecTerm + 4)) |= uint32(SF_Recursive)
					if iRecTab < 0 {
						v1 = pParse + 56
						v3 = *(*int32)(unsafe.Pointer(v1))
						*(*int32)(unsafe.Pointer(v1)) = *(*int32)(unsafe.Pointer(v1)) + 1
						iRecTab = v3
					}
					(*TSrcItem)(unsafe.Pointer(pItem)).FiCursor = iRecTab
				}
				goto _2
			_2:
				;
				i = i + 1
			}
			if (*TSelect)(unsafe.Pointer(pRecTerm)).FselFlags&uint32(SF_Recursive) == uint32(0) {
				break
			}
			pRecTerm = (*TSelect)(unsafe.Pointer(pRecTerm)).FpPrior
		}
		(*TCte)(unsafe.Pointer(pCte)).FzCteErr = __ccgo_ts + 21111
		pSavedWith = (*TParse)(unsafe.Pointer(pParse)).FpWith
		(*TParse)(unsafe.Pointer(pParse)).FpWith = **(**uintptr)(__ccgo_up(bp))
		if (*TSelect)(unsafe.Pointer(pSel)).FselFlags&uint32(SF_Recursive) != 0 {
			(*TSelect)(unsafe.Pointer(pRecTerm)).FpWith = (*TSelect)(unsafe.Pointer(pSel)).FpWith
			rc = _sqlite3WalkSelect(tls, pWalker, pRecTerm)
			(*TSelect)(unsafe.Pointer(pRecTerm)).FpWith = uintptr(0)
			if rc != 0 {
				(*TParse)(unsafe.Pointer(pParse)).FpWith = pSavedWith
				return int32(2)
			}
		} else {
			if _sqlite3WalkSelect(tls, pWalker, pSel) != 0 {
				(*TParse)(unsafe.Pointer(pParse)).FpWith = pSavedWith
				return int32(2)
			}
		}
		(*TParse)(unsafe.Pointer(pParse)).FpWith = **(**uintptr)(__ccgo_up(bp))
		pLeft = pSel
		for {
			if !((*TSelect)(unsafe.Pointer(pLeft)).FpPrior != 0) {
				break
			}
			goto _5
		_5:
			;
			pLeft = (*TSelect)(unsafe.Pointer(pLeft)).FpPrior
		}
		pEList = (*TSelect)(unsafe.Pointer(pLeft)).FpEList
		if (*TCte)(unsafe.Pointer(pCte)).FpCols != 0 {
			if pEList != 0 && (*TExprList)(unsafe.Pointer(pEList)).FnExpr != (*TExprList)(unsafe.Pointer((*TCte)(unsafe.Pointer(pCte)).FpCols)).FnExpr {
				_sqlite3ErrorMsg(tls, pParse, __ccgo_ts+21134, libc.VaList(bp+16, (*TCte)(unsafe.Pointer(pCte)).FzName, (*TExprList)(unsafe.Pointer(pEList)).FnExpr, (*TExprList)(unsafe.Pointer((*TCte)(unsafe.Pointer(pCte)).FpCols)).FnExpr))
				(*TParse)(unsafe.Pointer(pParse)).FpWith = pSavedWith
				return int32(2)
			}
			pEList = (*TCte)(unsafe.Pointer(pCte)).FpCols
		}
		_sqlite3ColumnsFromExprList(tls, pParse, pEList, pTab+54, pTab+8)
		if bMayRecursive != 0 {
			if (*TSelect)(unsafe.Pointer(pSel)).FselFlags&uint32(SF_Recursive) != 0 {
				(*TCte)(unsafe.Pointer(pCte)).FzCteErr = __ccgo_ts + 21172
			} else {
				(*TCte)(unsafe.Pointer(pCte)).FzCteErr = __ccgo_ts + 21206
			}
			_sqlite3WalkSelect(tls, pWalker, pSel)
		}
		(*TCte)(unsafe.Pointer(pCte)).FzCteErr = uintptr(0)
		(*TParse)(unsafe.Pointer(pParse)).FpWith = pSavedWith
		return int32(1) /* Success */
	}
	return 0 /* No match */
}

// C documentation
//
//	/*
//	** Generate an ORDER BY or GROUP BY term out-of-range error.
//	*/
func _resolveOutOfRangeError(tls *libc.TLS, pParse uintptr, zType uintptr, i int32, mx int32, pError uintptr) {
	bp := tls.Alloc(32)
	defer tls.Free(32)
	_sqlite3ErrorMsg(tls, pParse, __ccgo_ts+7562, libc.VaList(bp+8, i, zType, mx))
	_sqlite3RecordErrorOffsetOfExpr(tls, (*TParse)(unsafe.Pointer(pParse)).Fdb, pError)
}

// C documentation
//
//	/*
//	** Resolve names in the SELECT statement p and all of its descendants.
//	*/
func _resolveSelectStep(tls *libc.TLS, pWalker uintptr, p uintptr) (r int32) {
	bp := tls.Alloc(64)
	defer tls.Free(64)
	var db, pGroupBy, pItem, pItem1, pItem2, pLeftmost, pOuterNC, pParse, pSub, pSub1, pWin, zSavedContext uintptr
	var i, isCompound, nCompound, nRef, v1 int32
	var _ /* sNC at bp+0 */ TNameContext
	_, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _ = db, i, isCompound, nCompound, nRef, pGroupBy, pItem, pItem1, pItem2, pLeftmost, pOuterNC, pParse, pSub, pSub1, pWin, zSavedContext, v1 /* Database connection */
	if (*TSelect)(unsafe.Pointer(p)).FselFlags&uint32(SF_Resolved) != 0 {
		return int32(WRC_Prune)
	}
	pOuterNC = *(*uintptr)(unsafe.Pointer(pWalker + 40))
	pParse = (*TWalker)(unsafe.Pointer(pWalker)).FpParse
	db = (*TParse)(unsafe.Pointer(pParse)).Fdb
	/* Normally sqlite3SelectExpand() will be called first and will have
	 ** already expanded this SELECT.  However, if this is a subquery within
	 ** an expression, sqlite3ResolveExprNames() will be called without a
	 ** prior call to sqlite3SelectExpand().  When that happens, let
	 ** sqlite3SelectPrep() do all of the processing for this SELECT.
	 ** sqlite3SelectPrep() will invoke both sqlite3SelectExpand() and
	 ** this routine in the correct order.
	 */
	if (*TSelect)(unsafe.Pointer(p)).FselFlags&uint32(SF_Expanded) == uint32(0) {
		_sqlite3SelectPrep(tls, pParse, p, pOuterNC)
		if (*TParse)(unsafe.Pointer(pParse)).FnErr != 0 {
			v1 = int32(WRC_Abort)
		} else {
			v1 = int32(WRC_Prune)
		}
		return v1
	}
	isCompound = libc.BoolInt32((*TSelect)(unsafe.Pointer(p)).FpPrior != uintptr(0))
	nCompound = 0
	pLeftmost = p
	for p != 0 {
		**(**Tu32)(__ccgo_up(p + 4)) |= uint32(SF_Resolved)
		/* Resolve the expressions in the LIMIT and OFFSET clauses. These
		 ** are not allowed to refer to any names, so pass an empty NameContext.
		 */
		libc.Xmemset(tls, bp, 0, uint64(56))
		(**(**TNameContext)(__ccgo_up(bp))).FpParse = pParse
		(**(**TNameContext)(__ccgo_up(bp))).FpWinSelect = p
		if _sqlite3ResolveExprNames(tls, bp, (*TSelect)(unsafe.Pointer(p)).FpLimit) != 0 {
			return int32(WRC_Abort)
		}
		/* If the SF_Converted flags is set, then this Select object was
		 ** was created by the convertCompoundSelectToSubquery() function.
		 ** In this case the ORDER BY clause (p->pOrderBy) should be resolved
		 ** as if it were part of the sub-query, not the parent. This block
		 ** moves the pOrderBy down to the sub-query. It will be moved back
		 ** after the names have been resolved.  */
		if (*TSelect)(unsafe.Pointer(p)).FselFlags&uint32(SF_Converted) != 0 {
			pSub = (*TSubquery)(unsafe.Pointer(*(*uintptr)(unsafe.Pointer((*TSelect)(unsafe.Pointer(p)).FpSrc + 8 + 72)))).FpSelect
			(*TSelect)(unsafe.Pointer(pSub)).FpOrderBy = (*TSelect)(unsafe.Pointer(p)).FpOrderBy
			(*TSelect)(unsafe.Pointer(p)).FpOrderBy = uintptr(0)
		}
		/* Recursively resolve names in all subqueries in the FROM clause
		 */
		if pOuterNC != 0 {
			(*TNameContext)(unsafe.Pointer(pOuterNC)).FnNestedSelect = (*TNameContext)(unsafe.Pointer(pOuterNC)).FnNestedSelect + 1
		}
		i = 0
		for {
			if !(i < (*TSrcList)(unsafe.Pointer((*TSelect)(unsafe.Pointer(p)).FpSrc)).FnSrc) {
				break
			}
			pItem = (*TSelect)(unsafe.Pointer(p)).FpSrc + 8 + uintptr(i)*80
			/* Test of tag-20240424-1*/
			if int32(*(*uint32)(unsafe.Pointer(pItem + 24 + 4))&0x4>>2) != 0 && (*TSelect)(unsafe.Pointer((*TSubquery)(unsafe.Pointer(*(*uintptr)(unsafe.Pointer(pItem + 72)))).FpSelect)).FselFlags&uint32(SF_Resolved) == uint32(0) {
				if pOuterNC != 0 {
					v1 = (*TNameContext)(unsafe.Pointer(pOuterNC)).FnRef
				} else {
					v1 = 0
				}
				nRef = v1
				zSavedContext = (*TParse)(unsafe.Pointer(pParse)).FzAuthContext
				if (*TSrcItem)(unsafe.Pointer(pItem)).FzName != 0 {
					(*TParse)(unsafe.Pointer(pParse)).FzAuthContext = (*TSrcItem)(unsafe.Pointer(pItem)).FzName
				}
				_sqlite3ResolveSelectNames(tls, pParse, (*TSubquery)(unsafe.Pointer(*(*uintptr)(unsafe.Pointer(pItem + 72)))).FpSelect, pOuterNC)
				(*TParse)(unsafe.Pointer(pParse)).FzAuthContext = zSavedContext
				if (*TParse)(unsafe.Pointer(pParse)).FnErr != 0 {
					return int32(WRC_Abort)
				}
				/* If the number of references to the outer context changed when
				 ** expressions in the sub-select were resolved, the sub-select
				 ** is correlated. It is not required to check the refcount on any
				 ** but the innermost outer context object, as lookupName() increments
				 ** the refcount on all contexts between the current one and the
				 ** context containing the column when it resolves a name. */
				if pOuterNC != 0 {
					libc.SetBitFieldPtr32Uint32(pItem+24+4, libc.BoolUint32((*TNameContext)(unsafe.Pointer(pOuterNC)).FnRef > nRef), 4, 0x10)
				}
			}
			goto _2
		_2:
			;
			i = i + 1
		}
		if pOuterNC != 0 && (*TNameContext)(unsafe.Pointer(pOuterNC)).FnNestedSelect > uint32(0) {
			(*TNameContext)(unsafe.Pointer(pOuterNC)).FnNestedSelect = (*TNameContext)(unsafe.Pointer(pOuterNC)).FnNestedSelect - 1
		}
		/* Set up the local name-context to pass to sqlite3ResolveExprNames() to
		 ** resolve the result-set expression list.
		 */
		(**(**TNameContext)(__ccgo_up(bp))).FncFlags = libc.Int32FromInt32(NC_AllowAgg) | libc.Int32FromInt32(NC_AllowWin)
		(**(**TNameContext)(__ccgo_up(bp))).FpSrcList = (*TSelect)(unsafe.Pointer(p)).FpSrc
		(**(**TNameContext)(__ccgo_up(bp))).FpNext = pOuterNC
		/* Resolve names in the result set. */
		if _sqlite3ResolveExprListNames(tls, bp, (*TSelect)(unsafe.Pointer(p)).FpEList) != 0 {
			return int32(WRC_Abort)
		}
		(**(**TNameContext)(__ccgo_up(bp))).FncFlags &= ^libc.Int32FromInt32(NC_AllowWin)
		/* If there are no aggregate functions in the result-set, and no GROUP BY
		 ** expression, do not allow aggregates in any of the other expressions.
		 */
		pGroupBy = (*TSelect)(unsafe.Pointer(p)).FpGroupBy
		if pGroupBy != 0 || (**(**TNameContext)(__ccgo_up(bp))).FncFlags&int32(NC_HasAgg) != 0 {
			**(**Tu32)(__ccgo_up(p + 4)) |= libc.Uint32FromInt32(int32(SF_Aggregate) | (**(**TNameContext)(__ccgo_up(bp))).FncFlags&(libc.Int32FromInt32(NC_MinMaxAgg)|libc.Int32FromInt32(NC_OrderAgg)))
		} else {
			(**(**TNameContext)(__ccgo_up(bp))).FncFlags &= ^libc.Int32FromInt32(NC_AllowAgg)
		}
		/* Add the output column list to the name-context before parsing the
		 ** other expressions in the SELECT statement. This is so that
		 ** expressions in the WHERE clause (etc.) can refer to expressions by
		 ** aliases in the result set.
		 **
		 ** Minor point: If this is the case, then the expression will be
		 ** re-evaluated for each reference to it.
		 */
		*(*uintptr)(unsafe.Pointer(bp + 16)) = (*TSelect)(unsafe.Pointer(p)).FpEList
		(**(**TNameContext)(__ccgo_up(bp))).FncFlags |= int32(NC_UEList)
		if (*TSelect)(unsafe.Pointer(p)).FpHaving != 0 {
			if (*TSelect)(unsafe.Pointer(p)).FselFlags&uint32(SF_Aggregate) == uint32(0) {
				_sqlite3ErrorMsg(tls, pParse, __ccgo_ts+7750, 0)
				return int32(WRC_Abort)
			}
			if _sqlite3ResolveExprNames(tls, bp, (*TSelect)(unsafe.Pointer(p)).FpHaving) != 0 {
				return int32(WRC_Abort)
			}
		}
		(**(**TNameContext)(__ccgo_up(bp))).FncFlags |= int32(NC_Where)
		if _sqlite3ResolveExprNames(tls, bp, (*TSelect)(unsafe.Pointer(p)).FpWhere) != 0 {
			return int32(WRC_Abort)
		}
		(**(**TNameContext)(__ccgo_up(bp))).FncFlags &= ^libc.Int32FromInt32(NC_Where)
		/* Resolve names in table-valued-function arguments */
		i = 0
		for {
			if !(i < (*TSrcList)(unsafe.Pointer((*TSelect)(unsafe.Pointer(p)).FpSrc)).FnSrc) {
				break
			}
			pItem1 = (*TSelect)(unsafe.Pointer(p)).FpSrc + 8 + uintptr(i)*80
			if int32(*(*uint32)(unsafe.Pointer(pItem1 + 24 + 4))&0x8>>3) != 0 && _sqlite3ResolveExprListNames(tls, bp, *(*uintptr)(unsafe.Pointer(pItem1 + 48))) != 0 {
				return int32(WRC_Abort)
			}
			goto _4
		_4:
			;
			i = i + 1
		}
		if libc.Int32FromUint8((*TParse)(unsafe.Pointer(pParse)).FeParseMode) >= int32(PARSE_MODE_RENAME) {
			pWin = (*TSelect)(unsafe.Pointer(p)).FpWinDefn
			for {
				if !(pWin != 0) {
					break
				}
				if _sqlite3ResolveExprListNames(tls, bp, (*TWindow)(unsafe.Pointer(pWin)).FpOrderBy) != 0 || _sqlite3ResolveExprListNames(tls, bp, (*TWindow)(unsafe.Pointer(pWin)).FpPartition) != 0 {
					return int32(WRC_Abort)
				}
				goto _5
			_5:
				;
				pWin = (*TWindow)(unsafe.Pointer(pWin)).FpNextWin
			}
		}
		(**(**TNameContext)(__ccgo_up(bp))).FncFlags |= libc.Int32FromInt32(NC_AllowAgg) | libc.Int32FromInt32(NC_AllowWin)
		/* If this is a converted compound query, move the ORDER BY clause from
		 ** the sub-query back to the parent query. At this point each term
		 ** within the ORDER BY clause has been transformed to an integer value.
		 ** These integers will be replaced by copies of the corresponding result
		 ** set expressions by the call to resolveOrderGroupBy() below.  */
		if (*TSelect)(unsafe.Pointer(p)).FselFlags&uint32(SF_Converted) != 0 {
			pSub1 = (*TSubquery)(unsafe.Pointer(*(*uintptr)(unsafe.Pointer((*TSelect)(unsafe.Pointer(p)).FpSrc + 8 + 72)))).FpSelect
			(*TSelect)(unsafe.Pointer(p)).FpOrderBy = (*TSelect)(unsafe.Pointer(pSub1)).FpOrderBy
			(*TSelect)(unsafe.Pointer(pSub1)).FpOrderBy = uintptr(0)
		}
		/* Process the ORDER BY clause for singleton SELECT statements.
		 ** The ORDER BY clause for compounds SELECT statements is handled
		 ** below, after all of the result-sets for all of the elements of
		 ** the compound have been resolved.
		 **
		 ** If there is an ORDER BY clause on a term of a compound-select other
		 ** than the right-most term, then that is a syntax error.  But the error
		 ** is not detected until much later, and so we need to go ahead and
		 ** resolve those symbols on the incorrect ORDER BY for consistency.
		 */
		if (*TSelect)(unsafe.Pointer(p)).FpOrderBy != uintptr(0) && isCompound <= nCompound && _resolveOrderGroupBy(tls, bp, p, (*TSelect)(unsafe.Pointer(p)).FpOrderBy, __ccgo_ts+7652) != 0 {
			return int32(WRC_Abort)
		}
		if (*Tsqlite3)(unsafe.Pointer(db)).FmallocFailed != 0 {
			return int32(WRC_Abort)
		}
		(**(**TNameContext)(__ccgo_up(bp))).FncFlags &= ^libc.Int32FromInt32(NC_AllowWin)
		/* Resolve the GROUP BY clause.  At the same time, make sure
		 ** the GROUP BY clause does not contain aggregate functions.
		 */
		if pGroupBy != 0 {
			if _resolveOrderGroupBy(tls, bp, p, pGroupBy, __ccgo_ts+7789) != 0 || (*Tsqlite3)(unsafe.Pointer(db)).FmallocFailed != 0 {
				return int32(WRC_Abort)
			}
			i = 0
			pItem2 = pGroupBy + 8
			for {
				if !(i < (*TExprList)(unsafe.Pointer(pGroupBy)).FnExpr) {
					break
				}
				if (*TExpr)(unsafe.Pointer((*TExprList_item)(unsafe.Pointer(pItem2)).FpExpr)).Fflags&libc.Uint32FromInt32(libc.Int32FromInt32(EP_Agg)) != uint32(0) {
					_sqlite3ErrorMsg(tls, pParse, __ccgo_ts+7795, 0)
					return int32(WRC_Abort)
				}
				goto _6
			_6:
				;
				i = i + 1
				pItem2 += 32
			}
		}
		/* If this is part of a compound SELECT, check that it has the right
		 ** number of expressions in the select list. */
		if (*TSelect)(unsafe.Pointer(p)).FpNext != 0 && (*TExprList)(unsafe.Pointer((*TSelect)(unsafe.Pointer(p)).FpEList)).FnExpr != (*TExprList)(unsafe.Pointer((*TSelect)(unsafe.Pointer((*TSelect)(unsafe.Pointer(p)).FpNext)).FpEList)).FnExpr {
			_sqlite3SelectWrongNumTermsError(tls, pParse, (*TSelect)(unsafe.Pointer(p)).FpNext)
			return int32(WRC_Abort)
		}
		/* If the SELECT statement contains ON clauses that were moved into
		 ** the WHERE clause, go through and verify that none of the terms
		 ** in the ON clauses reference tables to the right of the ON clause. */
		if (*TSelect)(unsafe.Pointer(p)).FselFlags&uint32(SF_OnToWhere) != 0 {
			_sqlite3SelectCheckOnClauses(tls, pParse, p)
			if (*TParse)(unsafe.Pointer(pParse)).FnErr != 0 {
				return int32(WRC_Abort)
			}
		}
		/* Advance to the next term of the compound
		 */
		p = (*TSelect)(unsafe.Pointer(p)).FpPrior
		nCompound = nCompound + 1
	}
	/* Resolve the ORDER BY on a compound SELECT after all terms of
	 ** the compound have been resolved.
	 */
	if isCompound != 0 && _resolveCompoundOrderBy(tls, pParse, pLeftmost) != 0 {
		return int32(WRC_Abort)
	}
	return int32(WRC_Prune)
}

// C documentation
//
//	/*
//	** Close a file descriptor.
//	**
//	** We assume that close() almost always works, since it is only in a
//	** very sick application or on a very sick platform that it might fail.
//	** If it does fail, simply leak the file descriptor, but do log the
//	** error.
//	**
//	** Note that it is not safe to retry close() after EINTR since the
//	** file descriptor might have already been reused by another thread.
//	** So we don't even try to recover from an EINTR.  Just log the error
//	** and move on.
//	*/
func _robust_close(tls *libc.TLS, pFile uintptr, h int32, lineno int32) {
	var v1 uintptr
	_ = v1
	if (*(*func(*libc.TLS, int32) int32)(unsafe.Pointer(&struct{ uintptr }{_aSyscall[int32(1)].FpCurrent})))(tls, h) != 0 {
		if pFile != 0 {
			v1 = (*TunixFile)(unsafe.Pointer(pFile)).FzPath
		} else {
			v1 = uintptr(0)
		}
		_unixLogErrorAtLine(tls, libc.Int32FromInt32(SQLITE_IOERR)|libc.Int32FromInt32(16)<<libc.Int32FromInt32(8), __ccgo_ts+3536, v1, lineno)
	}
}

// C documentation
//
//	/*
//	** Retry ftruncate() calls that fail due to EINTR
//	**
//	** All calls to ftruncate() within this file should be made through
//	** this wrapper.  On the Android platform, bypassing the logic below
//	** could lead to a corrupt database.
//	*/
func _robust_ftruncate(tls *libc.TLS, h int32, sz Tsqlite3_int64) (r int32) {
	var rc int32
	_ = rc
	for cond := true; cond; cond = rc < 0 && **(**int32)(__ccgo_up(libc.X__errno(tls))) == int32(EINTR) {
		rc = (*(*func(*libc.TLS, int32, Toff_t) int32)(unsafe.Pointer(&struct{ uintptr }{_aSyscall[int32(6)].FpCurrent})))(tls, h, sz)
	}
	return rc
}

// C documentation
//
//	/*
//	** Invoke open().  Do so multiple times, until it either succeeds or
//	** fails for some reason other than EINTR.
//	**
//	** If the file creation mode "m" is 0 then set it to the default for
//	** SQLite.  The default is SQLITE_DEFAULT_FILE_PERMISSIONS (normally
//	** 0644) as modified by the system umask.  If m is not 0, then
//	** make the file creation mode be exactly m ignoring the umask.
//	**
//	** The m parameter will be non-zero only when creating -wal, -journal,
//	** and -shm files.  We want those files to have *exactly* the same
//	** permissions as their original database, unadulterated by the umask.
//	** In that way, if a database file is -rw-rw-rw or -rw-rw-r-, and a
//	** transaction crashes and leaves behind hot journals, then any
//	** process that is able to write to the database will also be able to
//	** recover the hot journals.
//	*/
func _robust_open(tls *libc.TLS, z uintptr, f int32, m Tmode_t) (r int32) {
	bp := tls.Alloc(160)
	defer tls.Free(160)
	var fd int32
	var m2 Tmode_t
	var v1 uint32
	var _ /* statbuf at bp+0 */ Tstat
	_, _, _ = fd, m2, v1
	if m != 0 {
		v1 = m
	} else {
		v1 = uint32(SQLITE_DEFAULT_FILE_PERMISSIONS)
	}
	m2 = v1
	for int32(1) != 0 {
		fd = (*(*func(*libc.TLS, uintptr, int32, int32) int32)(unsafe.Pointer(&struct{ uintptr }{_aSyscall[0].FpCurrent})))(tls, z, f|int32(O_CLOEXEC), libc.Int32FromUint32(m2))
		if fd < 0 {
			if **(**int32)(__ccgo_up(libc.X__errno(tls))) == int32(EINTR) {
				continue
			}
			break
		}
		if fd >= int32(SQLITE_MINIMUM_FILE_DESCRIPTOR) {
			break
		}
		if f&(libc.Int32FromInt32(O_EXCL)|libc.Int32FromInt32(O_CREAT)) == libc.Int32FromInt32(O_EXCL)|libc.Int32FromInt32(O_CREAT) {
			(*(*func(*libc.TLS, uintptr) int32)(unsafe.Pointer(&struct{ uintptr }{_aSyscall[int32(16)].FpCurrent})))(tls, z)
		}
		(*(*func(*libc.TLS, int32) int32)(unsafe.Pointer(&struct{ uintptr }{_aSyscall[int32(1)].FpCurrent})))(tls, fd)
		Xsqlite3_log(tls, int32(SQLITE_WARNING), __ccgo_ts+3741, libc.VaList(bp+136, z, fd))
		fd = -int32(1)
		if (*(*func(*libc.TLS, uintptr, int32, int32) int32)(unsafe.Pointer(&struct{ uintptr }{_aSyscall[0].FpCurrent})))(tls, __ccgo_ts+3784, O_RDONLY, libc.Int32FromUint32(m)) < 0 {
			break
		}
	}
	if fd >= 0 {
		if m != uint32(0) {
			if (*(*func(*libc.TLS, int32, uintptr) int32)(unsafe.Pointer(&struct{ uintptr }{_aSyscall[int32(5)].FpCurrent})))(tls, fd, bp) == 0 && (**(**Tstat)(__ccgo_up(bp))).Fst_size == 0 && (**(**Tstat)(__ccgo_up(bp))).Fst_mode&uint32(0777) != m {
				(*(*func(*libc.TLS, int32, Tmode_t) int32)(unsafe.Pointer(&struct{ uintptr }{_aSyscall[int32(14)].FpCurrent})))(tls, fd, m)
			}
		}
	}
	return fd
}

// C documentation
//
//	/*
//	** Implementation of the round() function
//	*/
func _roundFunc(tls *libc.TLS, context uintptr, argc int32, argv uintptr) {
	bp := tls.Alloc(32)
	defer tls.Free(32)
	var n Ti64
	var zBuf uintptr
	var v1 float64
	var _ /* r at bp+0 */ float64
	_, _, _ = n, zBuf, v1
	n = 0
	if argc == int32(2) {
		if int32(SQLITE_NULL) == Xsqlite3_value_type(tls, **(**uintptr)(__ccgo_up(argv + 1*8))) {
			return
		}
		n = Xsqlite3_value_int64(tls, **(**uintptr)(__ccgo_up(argv + 1*8)))
		if n > int64(30) {
			n = int64(30)
		}
		if n < 0 {
			n = 0
		}
	}
	if Xsqlite3_value_type(tls, **(**uintptr)(__ccgo_up(argv))) == int32(SQLITE_NULL) {
		return
	}
	**(**float64)(__ccgo_up(bp)) = Xsqlite3_value_double(tls, **(**uintptr)(__ccgo_up(argv)))
	/* If Y==0 and X will fit in a 64-bit int,
	 ** handle the rounding directly,
	 ** otherwise use printf.
	 */
	if **(**float64)(__ccgo_up(bp)) < -libc.Float64FromFloat64(4.503599627370496e+15) || **(**float64)(__ccgo_up(bp)) > +libc.Float64FromFloat64(4.503599627370496e+15) {
		/* The value has no fractional part so there is nothing to round */
	} else {
		if n == 0 {
			if **(**float64)(__ccgo_up(bp)) < libc.Float64FromInt32(0) {
				v1 = -libc.Float64FromFloat64(0.5)
			} else {
				v1 = +libc.Float64FromFloat64(0.5)
			}
			**(**float64)(__ccgo_up(bp)) = float64(int64(**(**float64)(__ccgo_up(bp)) + v1))
		} else {
			zBuf = Xsqlite3_mprintf(tls, __ccgo_ts+16468, libc.VaList(bp+16, int32(n), **(**float64)(__ccgo_up(bp))))
			if zBuf == uintptr(0) {
				Xsqlite3_result_error_nomem(tls, context)
				return
			}
			_sqlite3AtoF(tls, zBuf, bp)
			Xsqlite3_free(tls, zBuf)
		}
	}
	Xsqlite3_result_double(tls, context, **(**float64)(__ccgo_up(bp)))
}

// C documentation
//
//	/*
//	** The second and subsequent arguments to this function are a printf()
//	** style format string and arguments. This function formats the string and
//	** appends it to the report being accumulated in pCheck.
//	*/
func _rtreeCheckAppendMsg(tls *libc.TLS, pCheck uintptr, zFmt uintptr, va uintptr) {
	bp := tls.Alloc(32)
	defer tls.Free(32)
	var ap Tva_list
	var z, v1 uintptr
	_, _, _ = ap, z, v1
	ap = va
	if (*TRtreeCheck)(unsafe.Pointer(pCheck)).Frc == SQLITE_OK && (*TRtreeCheck)(unsafe.Pointer(pCheck)).FnErr < int32(RTREE_CHECK_MAX_ERROR) {
		z = Xsqlite3_vmprintf(tls, zFmt, ap)
		if z == uintptr(0) {
			(*TRtreeCheck)(unsafe.Pointer(pCheck)).Frc = int32(SQLITE_NOMEM)
		} else {
			if (*TRtreeCheck)(unsafe.Pointer(pCheck)).FzReport != 0 {
				v1 = __ccgo_ts + 4345
			} else {
				v1 = __ccgo_ts + 1693
			}
			(*TRtreeCheck)(unsafe.Pointer(pCheck)).FzReport = Xsqlite3_mprintf(tls, __ccgo_ts+29044, libc.VaList(bp+8, (*TRtreeCheck)(unsafe.Pointer(pCheck)).FzReport, v1, z))
			if (*TRtreeCheck)(unsafe.Pointer(pCheck)).FzReport == uintptr(0) {
				(*TRtreeCheck)(unsafe.Pointer(pCheck)).Frc = int32(SQLITE_NOMEM)
			}
		}
		(*TRtreeCheck)(unsafe.Pointer(pCheck)).FnErr = (*TRtreeCheck)(unsafe.Pointer(pCheck)).FnErr + 1
	}
	_ = ap
}

// C documentation
//
//	/*
//	** Argument pCell points to an array of coordinates stored on an rtree page.
//	** This function checks that the coordinates are internally consistent (no
//	** x1>x2 conditions) and adds an error message to the RtreeCheck object
//	** if they are not.
//	**
//	** Additionally, if pParent is not NULL, then it is assumed to point to
//	** the array of coordinates on the parent page that bound the page
//	** containing pCell. In this case it is also verified that the two
//	** sets of coordinates are mutually consistent and an error message added
//	** to the RtreeCheck object if they are not.
//	*/
func _rtreeCheckCellCoord(tls *libc.TLS, pCheck uintptr, iNode Ti64, iCell int32, pCell uintptr, pParent uintptr) {
	bp := tls.Alloc(48)
	defer tls.Free(48)
	var i, v2, v3 int32
	var v5 bool
	var _ /* c1 at bp+0 */ TRtreeCoord
	var _ /* c2 at bp+4 */ TRtreeCoord
	var _ /* p1 at bp+8 */ TRtreeCoord
	var _ /* p2 at bp+12 */ TRtreeCoord
	_, _, _, _ = i, v2, v3, v5
	i = 0
	for {
		if !(i < (*TRtreeCheck)(unsafe.Pointer(pCheck)).FnDim) {
			break
		}
		_readCoord(tls, pCell+uintptr(libc.Int32FromInt32(4)*libc.Int32FromInt32(2)*i), bp)
		_readCoord(tls, pCell+uintptr(int32(4)*(int32(2)*i+int32(1))), bp+4)
		/* printf("%e, %e\n", c1.u.f, c2.u.f); */
		if (*TRtreeCheck)(unsafe.Pointer(pCheck)).FbInt != 0 {
			v2 = libc.BoolInt32(*(*int32)(unsafe.Pointer(bp)) > *(*int32)(unsafe.Pointer(bp + 4)))
		} else {
			v2 = libc.BoolInt32(*(*TRtreeValue)(unsafe.Pointer(bp)) > *(*TRtreeValue)(unsafe.Pointer(bp + 4)))
		}
		if v2 != 0 {
			_rtreeCheckAppendMsg(tls, pCheck, __ccgo_ts+29350, libc.VaList(bp+24, i, iCell, iNode))
		}
		if pParent != 0 {
			_readCoord(tls, pParent+uintptr(libc.Int32FromInt32(4)*libc.Int32FromInt32(2)*i), bp+8)
			_readCoord(tls, pParent+uintptr(int32(4)*(int32(2)*i+int32(1))), bp+12)
			if (*TRtreeCheck)(unsafe.Pointer(pCheck)).FbInt != 0 {
				v2 = libc.BoolInt32(*(*int32)(unsafe.Pointer(bp)) < *(*int32)(unsafe.Pointer(bp + 8)))
			} else {
				v2 = libc.BoolInt32(*(*TRtreeValue)(unsafe.Pointer(bp)) < *(*TRtreeValue)(unsafe.Pointer(bp + 8)))
			}
			if v5 = v2 != 0; !v5 {
				if (*TRtreeCheck)(unsafe.Pointer(pCheck)).FbInt != 0 {
					v3 = libc.BoolInt32(*(*int32)(unsafe.Pointer(bp + 4)) > *(*int32)(unsafe.Pointer(bp + 12)))
				} else {
					v3 = libc.BoolInt32(*(*TRtreeValue)(unsafe.Pointer(bp + 4)) > *(*TRtreeValue)(unsafe.Pointer(bp + 12)))
				}
			}
			if v5 || v3 != 0 {
				_rtreeCheckAppendMsg(tls, pCheck, __ccgo_ts+29398, libc.VaList(bp+24, i, iCell, iNode))
			}
		}
		goto _1
	_1:
		;
		i = i + 1
	}
}

// C documentation
//
//	/*
//	** The second argument to this function must be either "_rowid" or
//	** "_parent". This function checks that the number of entries in the
//	** %_rowid or %_parent table is exactly nExpect. If not, it adds
//	** an error message to the report in the RtreeCheck object indicated
//	** by the first argument.
//	*/
func _rtreeCheckCount(tls *libc.TLS, pCheck uintptr, zTbl uintptr, nExpect Ti64) {
	bp := tls.Alloc(32)
	defer tls.Free(32)
	var nActual Ti64
	var pCount uintptr
	_, _ = nActual, pCount
	if (*TRtreeCheck)(unsafe.Pointer(pCheck)).Frc == SQLITE_OK {
		pCount = _rtreeCheckPrepare(tls, pCheck, __ccgo_ts+29584, libc.VaList(bp+8, (*TRtreeCheck)(unsafe.Pointer(pCheck)).FzDb, (*TRtreeCheck)(unsafe.Pointer(pCheck)).FzTab, zTbl))
		if pCount != 0 {
			if Xsqlite3_step(tls, pCount) == int32(SQLITE_ROW) {
				nActual = Xsqlite3_column_int64(tls, pCount, 0)
				if nActual != nExpect {
					_rtreeCheckAppendMsg(tls, pCheck, __ccgo_ts+29615, libc.VaList(bp+8, zTbl, nExpect, nActual))
				}
			}
			(*TRtreeCheck)(unsafe.Pointer(pCheck)).Frc = Xsqlite3_finalize(tls, pCount)
		}
	}
}

// C documentation
//
//	/*
//	** This function is a no-op if there is already an error code stored
//	** in the RtreeCheck object indicated by the first argument. NULL is
//	** returned in this case.
//	**
//	** Otherwise, the contents of rtree table node iNode are loaded from
//	** the database and copied into a buffer obtained from sqlite3_malloc().
//	** If no error occurs, a pointer to the buffer is returned and (*pnNode)
//	** is set to the size of the buffer in bytes.
//	**
//	** Or, if an error does occur, NULL is returned and an error code left
//	** in the RtreeCheck object. The final value of *pnNode is undefined in
//	** this case.
//	*/
func _rtreeCheckGetNode(tls *libc.TLS, pCheck uintptr, iNode Ti64, pnNode uintptr) (r uintptr) {
	bp := tls.Alloc(32)
	defer tls.Free(32)
	var nNode int32
	var pNode, pRet uintptr
	_, _, _ = nNode, pNode, pRet
	pRet = uintptr(0) /* Return value */
	if (*TRtreeCheck)(unsafe.Pointer(pCheck)).Frc == SQLITE_OK && (*TRtreeCheck)(unsafe.Pointer(pCheck)).FpGetNode == uintptr(0) {
		(*TRtreeCheck)(unsafe.Pointer(pCheck)).FpGetNode = _rtreeCheckPrepare(tls, pCheck, __ccgo_ts+29051, libc.VaList(bp+8, (*TRtreeCheck)(unsafe.Pointer(pCheck)).FzDb, (*TRtreeCheck)(unsafe.Pointer(pCheck)).FzTab))
	}
	if (*TRtreeCheck)(unsafe.Pointer(pCheck)).Frc == SQLITE_OK {
		Xsqlite3_bind_int64(tls, (*TRtreeCheck)(unsafe.Pointer(pCheck)).FpGetNode, int32(1), iNode)
		if Xsqlite3_step(tls, (*TRtreeCheck)(unsafe.Pointer(pCheck)).FpGetNode) == int32(SQLITE_ROW) {
			nNode = Xsqlite3_column_bytes(tls, (*TRtreeCheck)(unsafe.Pointer(pCheck)).FpGetNode, 0)
			pNode = Xsqlite3_column_blob(tls, (*TRtreeCheck)(unsafe.Pointer(pCheck)).FpGetNode, 0)
			pRet = Xsqlite3_malloc64(tls, libc.Uint64FromInt32(nNode))
			if pRet == uintptr(0) {
				(*TRtreeCheck)(unsafe.Pointer(pCheck)).Frc = int32(SQLITE_NOMEM)
			} else {
				libc.Xmemcpy(tls, pRet, pNode, libc.Uint64FromInt32(nNode))
				**(**int32)(__ccgo_up(pnNode)) = nNode
			}
		}
		_rtreeCheckReset(tls, pCheck, (*TRtreeCheck)(unsafe.Pointer(pCheck)).FpGetNode)
		if (*TRtreeCheck)(unsafe.Pointer(pCheck)).Frc == SQLITE_OK && pRet == uintptr(0) {
			_rtreeCheckAppendMsg(tls, pCheck, __ccgo_ts+29096, libc.VaList(bp+8, iNode))
		}
	}
	return pRet
}

// C documentation
//
//	/*
//	** This function is used to check that the %_parent (if bLeaf==0) or %_rowid
//	** (if bLeaf==1) table contains a specified entry. The schemas of the
//	** two tables are:
//	**
//	**   CREATE TABLE %_parent(nodeno INTEGER PRIMARY KEY, parentnode INTEGER)
//	**   CREATE TABLE %_rowid(rowid INTEGER PRIMARY KEY, nodeno INTEGER, ...)
//	**
//	** In both cases, this function checks that there exists an entry with
//	** IPK value iKey and the second column set to iVal.
//	**
//	*/
func _rtreeCheckMapping(tls *libc.TLS, pCheck uintptr, bLeaf int32, iKey Ti64, iVal Ti64) {
	bp := tls.Alloc(48)
	defer tls.Free(48)
	var azSql [2]uintptr
	var ii Ti64
	var pStmt, v1 uintptr
	var rc int32
	_, _, _, _, _ = azSql, ii, pStmt, rc, v1
	azSql = [2]uintptr{
		0: __ccgo_ts + 29128,
		1: __ccgo_ts + 29182,
	}
	if **(**uintptr)(__ccgo_up(pCheck + 40 + uintptr(bLeaf)*8)) == uintptr(0) {
		**(**uintptr)(__ccgo_up(pCheck + 40 + uintptr(bLeaf)*8)) = _rtreeCheckPrepare(tls, pCheck, azSql[bLeaf], libc.VaList(bp+8, (*TRtreeCheck)(unsafe.Pointer(pCheck)).FzDb, (*TRtreeCheck)(unsafe.Pointer(pCheck)).FzTab))
	}
	if (*TRtreeCheck)(unsafe.Pointer(pCheck)).Frc != SQLITE_OK {
		return
	}
	pStmt = **(**uintptr)(__ccgo_up(pCheck + 40 + uintptr(bLeaf)*8))
	Xsqlite3_bind_int64(tls, pStmt, int32(1), iKey)
	rc = Xsqlite3_step(tls, pStmt)
	if rc == int32(SQLITE_DONE) {
		if bLeaf != 0 {
			v1 = __ccgo_ts + 29230
		} else {
			v1 = __ccgo_ts + 29238
		}
		_rtreeCheckAppendMsg(tls, pCheck, __ccgo_ts+29247, libc.VaList(bp+8, iKey, iVal, v1))
	} else {
		if rc == int32(SQLITE_ROW) {
			ii = Xsqlite3_column_int64(tls, pStmt, 0)
			if ii != iVal {
				if bLeaf != 0 {
					v1 = __ccgo_ts + 29230
				} else {
					v1 = __ccgo_ts + 29238
				}
				_rtreeCheckAppendMsg(tls, pCheck, __ccgo_ts+29292, libc.VaList(bp+8, iKey, ii, v1, iKey, iVal))
			}
		}
	}
	_rtreeCheckReset(tls, pCheck, pStmt)
}

// C documentation
//
//	/*
//	** Run rtreecheck() checks on node iNode, which is at depth iDepth within
//	** the r-tree structure. Argument aParent points to the array of coordinates
//	** that bound node iNode on the parent node.
//	**
//	** If any problems are discovered, an error message is appended to the
//	** report accumulated in the RtreeCheck object.
//	*/
func _rtreeCheckNode(tls *libc.TLS, pCheck uintptr, iDepth int32, aParent uintptr, iNode Ti64) {
	bp := tls.Alloc(48)
	defer tls.Free(48)
	var aNode, pCell uintptr
	var i, nCell int32
	var iVal Ti64
	var _ /* nNode at bp+0 */ int32
	_, _, _, _, _ = aNode, i, iVal, nCell, pCell
	aNode = uintptr(0)
	**(**int32)(__ccgo_up(bp)) = 0
	aNode = _rtreeCheckGetNode(tls, pCheck, iNode, bp)
	if aNode != 0 {
		if **(**int32)(__ccgo_up(bp)) < int32(4) {
			_rtreeCheckAppendMsg(tls, pCheck, __ccgo_ts+29465, libc.VaList(bp+16, iNode, **(**int32)(__ccgo_up(bp))))
		} else { /* Used to iterate through cells */
			if aParent == uintptr(0) {
				iDepth = _readInt16(tls, aNode)
				if iDepth > int32(RTREE_MAX_DEPTH) {
					_rtreeCheckAppendMsg(tls, pCheck, __ccgo_ts+29499, libc.VaList(bp+16, iDepth))
					Xsqlite3_free(tls, aNode)
					return
				}
			}
			nCell = _readInt16(tls, aNode+2)
			if int32(4)+nCell*(int32(8)+(*TRtreeCheck)(unsafe.Pointer(pCheck)).FnDim*int32(2)*int32(4)) > **(**int32)(__ccgo_up(bp)) {
				_rtreeCheckAppendMsg(tls, pCheck, __ccgo_ts+29529, libc.VaList(bp+16, iNode, nCell, **(**int32)(__ccgo_up(bp))))
			} else {
				i = 0
				for {
					if !(i < nCell) {
						break
					}
					pCell = aNode + uintptr(int32(4)+i*(int32(8)+(*TRtreeCheck)(unsafe.Pointer(pCheck)).FnDim*int32(2)*int32(4)))
					iVal = _readInt64(tls, pCell)
					_rtreeCheckCellCoord(tls, pCheck, iNode, i, pCell+8, aParent)
					if iDepth > 0 {
						_rtreeCheckMapping(tls, pCheck, 0, iVal, iNode)
						_rtreeCheckNode(tls, pCheck, iDepth-int32(1), pCell+8, iVal)
						(*TRtreeCheck)(unsafe.Pointer(pCheck)).FnNonLeaf = (*TRtreeCheck)(unsafe.Pointer(pCheck)).FnNonLeaf + 1
					} else {
						_rtreeCheckMapping(tls, pCheck, int32(1), iVal, iNode)
						(*TRtreeCheck)(unsafe.Pointer(pCheck)).FnLeaf = (*TRtreeCheck)(unsafe.Pointer(pCheck)).FnLeaf + 1
					}
					goto _1
				_1:
					;
					i = i + 1
				}
			}
		}
		Xsqlite3_free(tls, aNode)
	}
}

// C documentation
//
//	/*
//	** This function does the bulk of the work for the rtree integrity-check.
//	** It is called by rtreecheck(), which is the SQL function implementation.
//	*/
func _rtreeCheckTable(tls *libc.TLS, db uintptr, zDb uintptr, zTab uintptr, pzReport uintptr) (r int32) {
	bp := tls.Alloc(112)
	defer tls.Free(112)
	var nAux, rc int32
	var pStmt uintptr
	var _ /* check at bp+0 */ TRtreeCheck
	_, _, _ = nAux, pStmt, rc /* Common context for various routines */
	pStmt = uintptr(0)        /* Used to find column count of rtree table */
	nAux = 0                  /* Number of extra columns. */
	/* Initialize the context object */
	libc.Xmemset(tls, bp, 0, uint64(88))
	(**(**TRtreeCheck)(__ccgo_up(bp))).Fdb = db
	(**(**TRtreeCheck)(__ccgo_up(bp))).FzDb = zDb
	(**(**TRtreeCheck)(__ccgo_up(bp))).FzTab = zTab
	/* Find the number of auxiliary columns */
	pStmt = _rtreeCheckPrepare(tls, bp, __ccgo_ts+29682, libc.VaList(bp+96, zDb, zTab))
	if pStmt != 0 {
		nAux = Xsqlite3_column_count(tls, pStmt) - int32(2)
		Xsqlite3_finalize(tls, pStmt)
	} else {
		if (**(**TRtreeCheck)(__ccgo_up(bp))).Frc != int32(SQLITE_NOMEM) {
			(**(**TRtreeCheck)(__ccgo_up(bp))).Frc = SQLITE_OK
		}
	}
	/* Find number of dimensions in the rtree table. */
	pStmt = _rtreeCheckPrepare(tls, bp, __ccgo_ts+27498, libc.VaList(bp+96, zDb, zTab))
	if pStmt != 0 {
		(**(**TRtreeCheck)(__ccgo_up(bp))).FnDim = (Xsqlite3_column_count(tls, pStmt) - int32(1) - nAux) / int32(2)
		if (**(**TRtreeCheck)(__ccgo_up(bp))).FnDim < int32(1) {
			_rtreeCheckAppendMsg(tls, bp, __ccgo_ts+29710, 0)
		} else {
			if int32(SQLITE_ROW) == Xsqlite3_step(tls, pStmt) {
				(**(**TRtreeCheck)(__ccgo_up(bp))).FbInt = libc.BoolInt32(Xsqlite3_column_type(tls, pStmt, int32(1)) == int32(SQLITE_INTEGER))
			}
		}
		rc = Xsqlite3_finalize(tls, pStmt)
		if rc != int32(SQLITE_CORRUPT) {
			(**(**TRtreeCheck)(__ccgo_up(bp))).Frc = rc
		}
	}
	/* Do the actual integrity-check */
	if (**(**TRtreeCheck)(__ccgo_up(bp))).FnDim >= int32(1) {
		if (**(**TRtreeCheck)(__ccgo_up(bp))).Frc == SQLITE_OK {
			_rtreeCheckNode(tls, bp, 0, uintptr(0), int64(1))
		}
		_rtreeCheckCount(tls, bp, __ccgo_ts+29741, int64((**(**TRtreeCheck)(__ccgo_up(bp))).FnLeaf))
		_rtreeCheckCount(tls, bp, __ccgo_ts+29748, int64((**(**TRtreeCheck)(__ccgo_up(bp))).FnNonLeaf))
	}
	/* Finalize SQL statements used by the integrity-check */
	Xsqlite3_finalize(tls, (**(**TRtreeCheck)(__ccgo_up(bp))).FpGetNode)
	Xsqlite3_finalize(tls, **(**uintptr)(__ccgo_up(bp + 40)))
	Xsqlite3_finalize(tls, **(**uintptr)(__ccgo_up(bp + 40 + 1*8)))
	**(**uintptr)(__ccgo_up(pzReport)) = (**(**TRtreeCheck)(__ccgo_up(bp))).FzReport
	return (**(**TRtreeCheck)(__ccgo_up(bp))).Frc
}

// C documentation
//
//	/*
//	** A constraint has failed while inserting a row into an rtree table.
//	** Assuming no OOM error occurs, this function sets the error message
//	** (at pRtree->base.zErrMsg) to an appropriate value and returns
//	** SQLITE_CONSTRAINT.
//	**
//	** Parameter iCol is the index of the leftmost column involved in the
//	** constraint failure. If it is 0, then the constraint that failed is
//	** the unique constraint on the id column. Otherwise, it is the rtree
//	** (c1<=c2) constraint on columns iCol and iCol+1 that has failed.
//	**
//	** If an OOM occurs, SQLITE_NOMEM is returned instead of SQLITE_CONSTRAINT.
//	*/
func _rtreeConstraintError(tls *libc.TLS, pRtree uintptr, iCol int32) (r int32) {
	bp := tls.Alloc(48)
	defer tls.Free(48)
	var rc, v1 int32
	var zCol, zCol1, zCol2, zSql uintptr
	var _ /* pStmt at bp+0 */ uintptr
	_, _, _, _, _, _ = rc, zCol, zCol1, zCol2, zSql, v1
	**(**uintptr)(__ccgo_up(bp)) = uintptr(0)
	zSql = Xsqlite3_mprintf(tls, __ccgo_ts+27498, libc.VaList(bp+16, (*TRtree)(unsafe.Pointer(pRtree)).FzDb, (*TRtree)(unsafe.Pointer(pRtree)).FzName))
	if zSql != 0 {
		rc = Xsqlite3_prepare_v2(tls, (*TRtree)(unsafe.Pointer(pRtree)).Fdb, zSql, -int32(1), bp, uintptr(0))
	} else {
		rc = int32(SQLITE_NOMEM)
	}
	Xsqlite3_free(tls, zSql)
	if rc == SQLITE_OK {
		if iCol == 0 {
			zCol = Xsqlite3_column_name(tls, **(**uintptr)(__ccgo_up(bp)), 0)
			(*TRtree)(unsafe.Pointer(pRtree)).Fbase.FzErrMsg = Xsqlite3_mprintf(tls, __ccgo_ts+27518, libc.VaList(bp+16, (*TRtree)(unsafe.Pointer(pRtree)).FzName, zCol))
		} else {
			zCol1 = Xsqlite3_column_name(tls, **(**uintptr)(__ccgo_up(bp)), iCol)
			zCol2 = Xsqlite3_column_name(tls, **(**uintptr)(__ccgo_up(bp)), iCol+int32(1))
			(*TRtree)(unsafe.Pointer(pRtree)).Fbase.FzErrMsg = Xsqlite3_mprintf(tls, __ccgo_ts+27550, libc.VaList(bp+16, (*TRtree)(unsafe.Pointer(pRtree)).FzName, zCol1, zCol2))
		}
	}
	Xsqlite3_finalize(tls, **(**uintptr)(__ccgo_up(bp)))
	if rc == SQLITE_OK {
		v1 = int32(SQLITE_CONSTRAINT)
	} else {
		v1 = rc
	}
	return v1
}

// C documentation
//
//	/*
//	** Rtree virtual table module xDestroy method.
//	*/
func _rtreeDestroy(tls *libc.TLS, pVtab uintptr) (r int32) {
	bp := tls.Alloc(64)
	defer tls.Free(64)
	var pRtree, zCreate uintptr
	var rc int32
	_, _, _ = pRtree, rc, zCreate
	pRtree = pVtab
	zCreate = Xsqlite3_mprintf(tls, __ccgo_ts+27402, libc.VaList(bp+8, (*TRtree)(unsafe.Pointer(pRtree)).FzDb, (*TRtree)(unsafe.Pointer(pRtree)).FzName, (*TRtree)(unsafe.Pointer(pRtree)).FzDb, (*TRtree)(unsafe.Pointer(pRtree)).FzName, (*TRtree)(unsafe.Pointer(pRtree)).FzDb, (*TRtree)(unsafe.Pointer(pRtree)).FzName))
	if !(zCreate != 0) {
		rc = int32(SQLITE_NOMEM)
	} else {
		_nodeBlobReset(tls, pRtree)
		rc = Xsqlite3_exec(tls, (*TRtree)(unsafe.Pointer(pRtree)).Fdb, zCreate, uintptr(0), uintptr(0), uintptr(0))
		Xsqlite3_free(tls, zCreate)
	}
	if rc == SQLITE_OK {
		_rtreeRelease(tls, pRtree)
	}
	return rc
}

// C documentation
//
//	/*
//	** Implementation of the xIntegrity method for Rtree.
//	*/
func _rtreeIntegrity(tls *libc.TLS, pVtab uintptr, zSchema uintptr, zName uintptr, isQuick int32, pzErr uintptr) (r int32) {
	bp := tls.Alloc(32)
	defer tls.Free(32)
	var pRtree uintptr
	var rc int32
	_, _ = pRtree, rc
	pRtree = pVtab
	_ = zSchema
	_ = zName
	_ = isQuick
	rc = _rtreeCheckTable(tls, (*TRtree)(unsafe.Pointer(pRtree)).Fdb, (*TRtree)(unsafe.Pointer(pRtree)).FzDb, (*TRtree)(unsafe.Pointer(pRtree)).FzName, pzErr)
	if rc == SQLITE_OK && **(**uintptr)(__ccgo_up(pzErr)) != 0 {
		**(**uintptr)(__ccgo_up(pzErr)) = Xsqlite3_mprintf(tls, __ccgo_ts+29756, libc.VaList(bp+8, (*TRtree)(unsafe.Pointer(pRtree)).FzDb, (*TRtree)(unsafe.Pointer(pRtree)).FzName, **(**uintptr)(__ccgo_up(pzErr))))
		if **(**uintptr)(__ccgo_up(pzErr)) == uintptr(0) {
			rc = int32(SQLITE_NOMEM)
		}
	}
	return rc
}

// C documentation
//
//	/*
//	** This function populates the pRtree->nRowEst variable with an estimate
//	** of the number of rows in the virtual table. If possible, this is based
//	** on sqlite_stat1 data. Otherwise, use RTREE_DEFAULT_ROWEST.
//	*/
func _rtreeQueryStat1(tls *libc.TLS, db uintptr, pRtree uintptr) (r int32) {
	bp := tls.Alloc(32)
	defer tls.Free(32)
	var nRow Ti64
	var rc, v1 int32
	var zFmt, zSql uintptr
	var v2 int64
	var _ /* p at bp+0 */ uintptr
	_, _, _, _, _, _ = nRow, rc, zFmt, zSql, v1, v2
	zFmt = __ccgo_ts + 27732
	nRow = int64(RTREE_MIN_ROWEST)
	rc = Xsqlite3_table_column_metadata(tls, db, (*TRtree)(unsafe.Pointer(pRtree)).FzDb, __ccgo_ts+12826, uintptr(0), uintptr(0), uintptr(0), uintptr(0), uintptr(0), uintptr(0))
	if rc != SQLITE_OK {
		(*TRtree)(unsafe.Pointer(pRtree)).FnRowEst = int64(RTREE_DEFAULT_ROWEST)
		if rc == int32(SQLITE_ERROR) {
			v1 = SQLITE_OK
		} else {
			v1 = rc
		}
		return v1
	}
	zSql = Xsqlite3_mprintf(tls, zFmt, libc.VaList(bp+16, (*TRtree)(unsafe.Pointer(pRtree)).FzDb, (*TRtree)(unsafe.Pointer(pRtree)).FzName))
	if zSql == uintptr(0) {
		rc = int32(SQLITE_NOMEM)
	} else {
		rc = Xsqlite3_prepare_v2(tls, db, zSql, -int32(1), bp, uintptr(0))
		if rc == SQLITE_OK {
			if Xsqlite3_step(tls, **(**uintptr)(__ccgo_up(bp))) == int32(SQLITE_ROW) {
				nRow = Xsqlite3_column_int64(tls, **(**uintptr)(__ccgo_up(bp)), 0)
			}
			rc = Xsqlite3_finalize(tls, **(**uintptr)(__ccgo_up(bp)))
		}
		Xsqlite3_free(tls, zSql)
	}
	if nRow > int64(libc.Int32FromInt32(RTREE_MIN_ROWEST)) {
		v2 = nRow
	} else {
		v2 = int64(libc.Int32FromInt32(RTREE_MIN_ROWEST))
	}
	(*TRtree)(unsafe.Pointer(pRtree)).FnRowEst = v2
	return rc
}

// C documentation
//
//	/*
//	** The xRename method for rtree module virtual tables.
//	*/
func _rtreeRename(tls *libc.TLS, pVtab uintptr, zNewName uintptr) (r int32) {
	bp := tls.Alloc(80)
	defer tls.Free(80)
	var pRtree, zSql uintptr
	var rc int32
	_, _, _ = pRtree, rc, zSql
	pRtree = pVtab
	rc = int32(SQLITE_NOMEM)
	zSql = Xsqlite3_mprintf(tls, __ccgo_ts+27587, libc.VaList(bp+8, (*TRtree)(unsafe.Pointer(pRtree)).FzDb, (*TRtree)(unsafe.Pointer(pRtree)).FzName, zNewName, (*TRtree)(unsafe.Pointer(pRtree)).FzDb, (*TRtree)(unsafe.Pointer(pRtree)).FzName, zNewName, (*TRtree)(unsafe.Pointer(pRtree)).FzDb, (*TRtree)(unsafe.Pointer(pRtree)).FzName, zNewName))
	if zSql != 0 {
		_nodeBlobReset(tls, pRtree)
		rc = Xsqlite3_exec(tls, (*TRtree)(unsafe.Pointer(pRtree)).Fdb, zSql, uintptr(0), uintptr(0), uintptr(0))
		Xsqlite3_free(tls, zSql)
	}
	return rc
}

func _rtreeSqlInit(tls *libc.TLS, pRtree uintptr, db uintptr, zDb uintptr, zPrefix uintptr, isCreate int32) (r int32) {
	bp := tls.Alloc(32)
	defer tls.Free(32)
	var appStmt [8]uintptr
	var f, i, ii, ii1, rc int32
	var p, p1, zCreate, zFormat, zSql, zSql1 uintptr
	_, _, _, _, _, _, _, _, _, _, _, _ = appStmt, f, i, ii, ii1, p, p1, rc, zCreate, zFormat, zSql, zSql1
	rc = SQLITE_OK
	f = libc.Int32FromInt32(SQLITE_PREPARE_PERSISTENT) | libc.Int32FromInt32(SQLITE_PREPARE_NO_VTAB)
	(*TRtree)(unsafe.Pointer(pRtree)).Fdb = db
	if isCreate != 0 {
		p = Xsqlite3_str_new(tls, db)
		Xsqlite3_str_appendf(tls, p, __ccgo_ts+28202, libc.VaList(bp+8, zDb, zPrefix))
		ii = 0
		for {
			if !(ii < libc.Int32FromUint16((*TRtree)(unsafe.Pointer(pRtree)).FnAux)) {
				break
			}
			Xsqlite3_str_appendf(tls, p, __ccgo_ts+28264, libc.VaList(bp+8, ii))
			goto _1
		_1:
			;
			ii = ii + 1
		}
		Xsqlite3_str_appendf(tls, p, __ccgo_ts+28269, libc.VaList(bp+8, zDb, zPrefix))
		Xsqlite3_str_appendf(tls, p, __ccgo_ts+28333, libc.VaList(bp+8, zDb, zPrefix))
		Xsqlite3_str_appendf(tls, p, __ccgo_ts+28403, libc.VaList(bp+8, zDb, zPrefix, (*TRtree)(unsafe.Pointer(pRtree)).FiNodeSize))
		zCreate = Xsqlite3_str_finish(tls, p)
		if !(zCreate != 0) {
			return int32(SQLITE_NOMEM)
		}
		rc = Xsqlite3_exec(tls, db, zCreate, uintptr(0), uintptr(0), uintptr(0))
		Xsqlite3_free(tls, zCreate)
		if rc != SQLITE_OK {
			return rc
		}
	}
	appStmt[0] = pRtree + 128
	appStmt[int32(1)] = pRtree + 136
	appStmt[int32(2)] = pRtree + 144
	appStmt[int32(3)] = pRtree + 152
	appStmt[int32(4)] = pRtree + 160
	appStmt[int32(5)] = pRtree + 168
	appStmt[int32(6)] = pRtree + 176
	appStmt[int32(7)] = pRtree + 184
	rc = _rtreeQueryStat1(tls, db, pRtree)
	i = 0
	for {
		if !(i < int32(N_STATEMENT) && rc == SQLITE_OK) {
			break
		}
		if i != int32(3) || libc.Int32FromUint16((*TRtree)(unsafe.Pointer(pRtree)).FnAux) == 0 {
			zFormat = _azSql[i]
		} else {
			/* An UPSERT is very slightly slower than REPLACE, but it is needed
			 ** if there are auxiliary columns */
			zFormat = __ccgo_ts + 28452
		}
		zSql = Xsqlite3_mprintf(tls, zFormat, libc.VaList(bp+8, zDb, zPrefix))
		if zSql != 0 {
			rc = Xsqlite3_prepare_v3(tls, db, zSql, -int32(1), libc.Uint32FromInt32(f), appStmt[i], uintptr(0))
		} else {
			rc = int32(SQLITE_NOMEM)
		}
		Xsqlite3_free(tls, zSql)
		goto _2
	_2:
		;
		i = i + 1
	}
	if (*TRtree)(unsafe.Pointer(pRtree)).FnAux != 0 && rc != int32(SQLITE_NOMEM) {
		(*TRtree)(unsafe.Pointer(pRtree)).FzReadAuxSql = Xsqlite3_mprintf(tls, __ccgo_ts+28560, libc.VaList(bp+8, zDb, zPrefix))
		if (*TRtree)(unsafe.Pointer(pRtree)).FzReadAuxSql == uintptr(0) {
			rc = int32(SQLITE_NOMEM)
		} else {
			p1 = Xsqlite3_str_new(tls, db)
			Xsqlite3_str_appendf(tls, p1, __ccgo_ts+28605, libc.VaList(bp+8, zDb, zPrefix))
			ii1 = 0
			for {
				if !(ii1 < libc.Int32FromUint16((*TRtree)(unsafe.Pointer(pRtree)).FnAux)) {
					break
				}
				if ii1 != 0 {
					Xsqlite3_str_append(tls, p1, __ccgo_ts+14339, int32(1))
				}
				if ii1 < libc.Int32FromUint8((*TRtree)(unsafe.Pointer(pRtree)).FnAuxNotNull) {
					Xsqlite3_str_appendf(tls, p1, __ccgo_ts+28632, libc.VaList(bp+8, ii1, ii1+int32(2), ii1))
				} else {
					Xsqlite3_str_appendf(tls, p1, __ccgo_ts+28654, libc.VaList(bp+8, ii1, ii1+int32(2)))
				}
				goto _3
			_3:
				;
				ii1 = ii1 + 1
			}
			Xsqlite3_str_appendf(tls, p1, __ccgo_ts+28662, 0)
			zSql1 = Xsqlite3_str_finish(tls, p1)
			if zSql1 == uintptr(0) {
				rc = int32(SQLITE_NOMEM)
			} else {
				rc = Xsqlite3_prepare_v3(tls, db, zSql1, -int32(1), libc.Uint32FromInt32(f), pRtree+192, uintptr(0))
				Xsqlite3_free(tls, zSql1)
			}
		}
	}
	return rc
}

// C documentation
//
//	/*
//	** Usage:
//	**
//	**   rtreecheck(<rtree-table>);
//	**   rtreecheck(<database>, <rtree-table>);
//	**
//	** Invoking this SQL function runs an integrity-check on the named rtree
//	** table. The integrity-check verifies the following:
//	**
//	**   1. For each cell in the r-tree structure (%_node table), that:
//	**
//	**       a) for each dimension, (coord1 <= coord2).
//	**
//	**       b) unless the cell is on the root node, that the cell is bounded
//	**          by the parent cell on the parent node.
//	**
//	**       c) for leaf nodes, that there is an entry in the %_rowid
//	**          table corresponding to the cell's rowid value that
//	**          points to the correct node.
//	**
//	**       d) for cells on non-leaf nodes, that there is an entry in the
//	**          %_parent table mapping from the cell's child node to the
//	**          node that it resides on.
//	**
//	**   2. That there are the same number of entries in the %_rowid table
//	**      as there are leaf cells in the r-tree structure, and that there
//	**      is a leaf cell that corresponds to each entry in the %_rowid table.
//	**
//	**   3. That there are the same number of entries in the %_parent table
//	**      as there are non-leaf cells in the r-tree structure, and that
//	**      there is a non-leaf cell that corresponds to each entry in the
//	**      %_parent table.
//	*/
func _rtreecheck(tls *libc.TLS, ctx uintptr, nArg int32, apArg uintptr) {
	bp := tls.Alloc(16)
	defer tls.Free(16)
	var rc int32
	var zDb, zTab, v1 uintptr
	var _ /* zReport at bp+0 */ uintptr
	_, _, _, _ = rc, zDb, zTab, v1
	if nArg != int32(1) && nArg != int32(2) {
		Xsqlite3_result_error(tls, ctx, __ccgo_ts+29775, -int32(1))
	} else {
		**(**uintptr)(__ccgo_up(bp)) = uintptr(0)
		zDb = Xsqlite3_value_text(tls, **(**uintptr)(__ccgo_up(apArg)))
		if nArg == int32(1) {
			zTab = zDb
			zDb = __ccgo_ts + 6809
		} else {
			zTab = Xsqlite3_value_text(tls, **(**uintptr)(__ccgo_up(apArg + 1*8)))
		}
		rc = _rtreeCheckTable(tls, Xsqlite3_context_db_handle(tls, ctx), zDb, zTab, bp)
		if rc == SQLITE_OK {
			if **(**uintptr)(__ccgo_up(bp)) != 0 {
				v1 = **(**uintptr)(__ccgo_up(bp))
			} else {
				v1 = __ccgo_ts + 19782
			}
			Xsqlite3_result_text(tls, ctx, v1, -int32(1), uintptr(-libc.Int32FromInt32(1)))
		} else {
			Xsqlite3_result_error_code(tls, ctx, rc)
		}
		Xsqlite3_free(tls, **(**uintptr)(__ccgo_up(bp)))
	}
}

/* Conditionally include the geopoly code */
/************** Include geopoly.c in the middle of rtree.c *******************/
/************** Begin file geopoly.c *****************************************/
/*
** 2018-05-25
**
** 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 an alternative R-Tree virtual table that
** uses polygons to express the boundaries of 2-dimensional objects.
**
** This file is #include-ed onto the end of "rtree.c" so that it has
** access to all of the R-Tree internals.
 */
/* #include <stdlib.h> */

/* Enable -DGEOPOLY_ENABLE_DEBUG for debugging facilities */

/* Character class routines */
/* Use the SQLite core versions if this routine is part of the
 ** SQLite amalgamation */

// C documentation
//
//	/* This routine implements an SQL function that returns the "depth" parameter
//	** from the front of a blob that is an r-tree node.  For example:
//	**
//	**     SELECT rtreedepth(data) FROM rt_node WHERE nodeno=1;
//	**
//	** The depth value is 0 for all nodes other than the root node, and the root
//	** node always has nodeno=1, so the example above is the primary use for this
//	** routine.  This routine is intended for testing and analysis only.
//	*/
func _rtreedepth(tls *libc.TLS, ctx uintptr, nArg int32, apArg uintptr) {
	var zBlob uintptr
	_ = zBlob
	_ = nArg
	if Xsqlite3_value_type(tls, **(**uintptr)(__ccgo_up(apArg))) != int32(SQLITE_BLOB) || Xsqlite3_value_bytes(tls, **(**uintptr)(__ccgo_up(apArg))) < int32(2) {
		Xsqlite3_result_error(tls, ctx, __ccgo_ts+29011, -int32(1))
	} else {
		zBlob = Xsqlite3_value_blob(tls, **(**uintptr)(__ccgo_up(apArg)))
		if zBlob != 0 {
			Xsqlite3_result_int(tls, ctx, _readInt16(tls, zBlob))
		} else {
			Xsqlite3_result_error_nomem(tls, ctx)
		}
	}
}

// C documentation
//
//	/*
//	** Implementation of a scalar function that decodes r-tree nodes to
//	** human readable strings. This can be used for debugging and analysis.
//	**
//	** The scalar function takes two arguments: (1) the number of dimensions
//	** to the rtree (between 1 and 5, inclusive) and (2) a blob of data containing
//	** an r-tree node.  For a two-dimensional r-tree structure called "rt", to
//	** deserialize all nodes, a statement like:
//	**
//	**   SELECT rtreenode(2, data) FROM rt_node;
//	**
//	** The human readable string takes the form of a Tcl list with one
//	** entry for each cell in the r-tree node. Each entry is itself a
//	** list, containing the 8-byte rowid/pageno followed by the
//	** <num-dimension>*2 coordinates.
//	*/
func _rtreenode(tls *libc.TLS, ctx uintptr, nArg int32, apArg uintptr) {
	bp := tls.Alloc(1088)
	defer tls.Free(1088)
	var errCode, ii, jj, nData int32
	var pOut uintptr
	var _ /* cell at bp+1016 */ TRtreeCell
	var _ /* node at bp+0 */ TRtreeNode
	var _ /* tree at bp+40 */ TRtree
	_, _, _, _, _ = errCode, ii, jj, nData, pOut
	_ = nArg
	libc.Xmemset(tls, bp, 0, uint64(40))
	libc.Xmemset(tls, bp+40, 0, uint64(976))
	(**(**TRtree)(__ccgo_up(bp + 40))).FnDim = libc.Uint8FromInt32(Xsqlite3_value_int(tls, **(**uintptr)(__ccgo_up(apArg))))
	if libc.Int32FromUint8((**(**TRtree)(__ccgo_up(bp + 40))).FnDim) < int32(1) || libc.Int32FromUint8((**(**TRtree)(__ccgo_up(bp + 40))).FnDim) > int32(5) {
		return
	}
	(**(**TRtree)(__ccgo_up(bp + 40))).FnDim2 = libc.Uint8FromInt32(libc.Int32FromUint8((**(**TRtree)(__ccgo_up(bp + 40))).FnDim) * int32(2))
	(**(**TRtree)(__ccgo_up(bp + 40))).FnBytesPerCell = libc.Uint8FromInt32(int32(8) + int32(8)*libc.Int32FromUint8((**(**TRtree)(__ccgo_up(bp + 40))).FnDim))
	(**(**TRtreeNode)(__ccgo_up(bp))).FzData = Xsqlite3_value_blob(tls, **(**uintptr)(__ccgo_up(apArg + 1*8)))
	if (**(**TRtreeNode)(__ccgo_up(bp))).FzData == uintptr(0) {
		return
	}
	nData = Xsqlite3_value_bytes(tls, **(**uintptr)(__ccgo_up(apArg + 1*8)))
	if nData < int32(4) {
		return
	}
	if nData < int32(4)+_readInt16(tls, (*TRtreeNode)(unsafe.Pointer(bp)).FzData+2)*libc.Int32FromUint8((**(**TRtree)(__ccgo_up(bp + 40))).FnBytesPerCell) {
		return
	}
	pOut = Xsqlite3_str_new(tls, uintptr(0))
	ii = 0
	for {
		if !(ii < _readInt16(tls, (*TRtreeNode)(unsafe.Pointer(bp)).FzData+2)) {
			break
		}
		_nodeGetCell(tls, bp+40, bp, ii, bp+1016)
		if ii > 0 {
			Xsqlite3_str_append(tls, pOut, __ccgo_ts+11534, int32(1))
		}
		Xsqlite3_str_appendf(tls, pOut, __ccgo_ts+29001, libc.VaList(bp+1072, (**(**TRtreeCell)(__ccgo_up(bp + 1016))).FiRowid))
		jj = 0
		for {
			if !(jj < libc.Int32FromUint8((**(**TRtree)(__ccgo_up(bp + 40))).FnDim2)) {
				break
			}
			Xsqlite3_str_appendf(tls, pOut, __ccgo_ts+29007, libc.VaList(bp+1072, float64(*(*TRtreeValue)(unsafe.Pointer(bp + 1016 + 8 + uintptr(jj)*4)))))
			goto _2
		_2:
			;
			jj = jj + 1
		}
		Xsqlite3_str_append(tls, pOut, __ccgo_ts+26846, int32(1))
		goto _1
	_1:
		;
		ii = ii + 1
	}
	errCode = Xsqlite3_str_errcode(tls, pOut)
	Xsqlite3_result_error_code(tls, ctx, errCode)
	Xsqlite3_result_text(tls, ctx, Xsqlite3_str_finish(tls, pOut), -int32(1), __ccgo_fp(Xsqlite3_free))
}

// C documentation
//
//	/*
//	** Seek to the offset passed as the second argument, then read cnt
//	** bytes into pBuf. Return the number of bytes actually read.
//	**
//	** To avoid stomping the errno value on a failed read the lastErrno value
//	** is set before returning.
//	*/
func _seekAndRead(tls *libc.TLS, id uintptr, offset Tsqlite3_int64, pBuf uintptr, cnt int32) (r int32) {
	var got, prior int32
	var newOffset Ti64
	_, _, _ = got, newOffset, prior
	prior = 0
	for cond := true; cond; cond = got > 0 {
		newOffset = libc.Xlseek(tls, (*TunixFile)(unsafe.Pointer(id)).Fh, offset, SEEK_SET)
		if newOffset < 0 {
			_storeLastErrno(tls, id, **(**int32)(__ccgo_up(libc.X__errno(tls))))
			return -int32(1)
		}
		got = int32((*(*func(*libc.TLS, int32, uintptr, Tsize_t) Tssize_t)(unsafe.Pointer(&struct{ uintptr }{_aSyscall[int32(8)].FpCurrent})))(tls, (*TunixFile)(unsafe.Pointer(id)).Fh, pBuf, libc.Uint64FromInt32(cnt)))
		if got == cnt {
			break
		}
		if got < 0 {
			if **(**int32)(__ccgo_up(libc.X__errno(tls))) == int32(EINTR) {
				got = int32(1)
				continue
			}
			prior = 0
			_storeLastErrno(tls, id, **(**int32)(__ccgo_up(libc.X__errno(tls))))
			break
		} else {
			if got > 0 {
				cnt = cnt - got
				offset = offset + int64(got)
				prior = prior + got
				pBuf = uintptr(got) + pBuf
			}
		}
	}
	return got + prior
}

// C documentation
//
//	/*
//	** Attempt to seek the file-descriptor passed as the first argument to
//	** absolute offset iOff, then attempt to write nBuf bytes of data from
//	** pBuf to it. If an error occurs, return -1 and set *piErrno. Otherwise,
//	** return the actual number of bytes written (which may be less than
//	** nBuf).
//	*/
func _seekAndWriteFd(tls *libc.TLS, fd int32, iOff Ti64, pBuf uintptr, nBuf int32, piErrno uintptr) (r int32) {
	var iSeek Ti64
	var rc int32
	_, _ = iSeek, rc
	rc = 0 /* Value returned by system call */
	nBuf = nBuf & int32(0x1ffff)
	for cond := true; cond; cond = rc < 0 && **(**int32)(__ccgo_up(libc.X__errno(tls))) == int32(EINTR) {
		iSeek = libc.Xlseek(tls, fd, iOff, SEEK_SET)
		if iSeek < 0 {
			rc = -int32(1)
			break
		}
		rc = int32((*(*func(*libc.TLS, int32, uintptr, Tsize_t) Tssize_t)(unsafe.Pointer(&struct{ uintptr }{_aSyscall[int32(11)].FpCurrent})))(tls, fd, pBuf, libc.Uint64FromInt32(nBuf)))
	}
	if rc < 0 {
		**(**int32)(__ccgo_up(piErrno)) = **(**int32)(__ccgo_up(libc.X__errno(tls)))
	}
	return rc
}

// C documentation
//
//	/*
//	** The xExpr callback for the search of invalid ON clause terms.
//	*/
func _selectCheckOnClausesExpr(tls *libc.TLS, pWalker uintptr, pExpr uintptr) (r int32) {
	bp := tls.Alloc(16)
	defer tls.Free(16)
	var iTab, ii, nSrc int32
	var pCtx, pSrc, v2 uintptr
	_, _, _, _, _, _ = iTab, ii, nSrc, pCtx, pSrc, v2
	pCtx = *(*uintptr)(unsafe.Pointer(pWalker + 40))
	/* Check if pExpr is root or near-root of an ON clause constraint that needs
	 ** to be checked to ensure that it does not refer to tables in its FROM
	 ** clause to the right of itself. i.e. it is either:
	 **
	 **   + an ON clause on an OUTER join, or
	 **   + an ON clause on an INNER join within a FROM that features at
	 **     least one RIGHT or FULL join.
	 */
	if (*TExpr)(unsafe.Pointer(pExpr)).Fflags&libc.Uint32FromInt32(libc.Int32FromInt32(EP_OuterON)) != uint32(0) || (*TExpr)(unsafe.Pointer(pExpr)).Fflags&libc.Uint32FromInt32(libc.Int32FromInt32(EP_InnerON)) != uint32(0) && libc.Int32FromUint8((*(*TSrcItem)(unsafe.Pointer((*TCheckOnCtx)(unsafe.Pointer(pCtx)).FpSrc + 8))).Ffg.Fjointype)&int32(JT_LTORJ) != 0 {
		/* If CheckOnCtx.iJoin is already set, then fall through and process
		 ** this expression node as normal. Or, if CheckOnCtx.iJoin is still 0,
		 ** set it to the cursor number of the RHS of the join to which this
		 ** ON expression was attached and then iterate through the entire
		 ** expression.  */
		if (*TCheckOnCtx)(unsafe.Pointer(pCtx)).FiJoin == 0 {
			(*TCheckOnCtx)(unsafe.Pointer(pCtx)).FiJoin = *(*int32)(unsafe.Pointer(pExpr + 52))
			_sqlite3WalkExprNN(tls, pWalker, pExpr)
			(*TCheckOnCtx)(unsafe.Pointer(pCtx)).FiJoin = 0
			return int32(WRC_Prune)
		}
	}
	if libc.Int32FromUint8((*TExpr)(unsafe.Pointer(pExpr)).Fop) == int32(TK_COLUMN) {
		/* A column expression. Find the SrcList (if any) to which it refers.
		 ** Then, if CheckOnCtx.iJoin indicates that this expression is part of an
		 ** ON clause from that SrcList (i.e. if iJoin is non-zero), check that it
		 ** does not refer to a table to the right of CheckOnCtx.iJoin. */
		for cond := true; cond; cond = pCtx != 0 {
			pSrc = (*TCheckOnCtx)(unsafe.Pointer(pCtx)).FpSrc
			nSrc = (*TSrcList)(unsafe.Pointer(pSrc)).FnSrc
			iTab = (*TExpr)(unsafe.Pointer(pExpr)).FiTable
			ii = 0
			for {
				if !(ii < nSrc && (*(*TSrcItem)(unsafe.Pointer(pSrc + 8 + uintptr(ii)*80))).FiCursor != iTab) {
					break
				}
				goto _1
			_1:
				;
				ii = ii + 1
			}
			if ii < nSrc {
				if (*TCheckOnCtx)(unsafe.Pointer(pCtx)).FiJoin != 0 && iTab > (*TCheckOnCtx)(unsafe.Pointer(pCtx)).FiJoin {
					if (*TCheckOnCtx)(unsafe.Pointer(pCtx)).FbFuncArg != 0 {
						v2 = __ccgo_ts + 21553
					} else {
						v2 = __ccgo_ts + 21577
					}
					_sqlite3ErrorMsg(tls, (*TWalker)(unsafe.Pointer(pWalker)).FpParse, __ccgo_ts+21587, libc.VaList(bp+8, v2))
					return int32(WRC_Abort)
				}
				break
			}
			pCtx = (*TCheckOnCtx)(unsafe.Pointer(pCtx)).FpParent
		}
	}
	return WRC_Continue
}

// C documentation
//
//	/*
//	** This routine is a Walker callback for "expanding" a SELECT statement.
//	** "Expanding" means to do the following:
//	**
//	**    (1)  Make sure VDBE cursor numbers have been assigned to every
//	**         element of the FROM clause.
//	**
//	**    (2)  Fill in the pTabList->a[].pTab fields in the SrcList that
//	**         defines FROM clause.  When views appear in the FROM clause,
//	**         fill pTabList->a[].pSelect with a copy of the SELECT statement
//	**         that implements the view.  A copy is made of the view's SELECT
//	**         statement so that we can freely modify or delete that statement
//	**         without worrying about messing up the persistent representation
//	**         of the view.
//	**
//	**    (3)  Add terms to the WHERE clause to accommodate the NATURAL keyword
//	**         on joins and the ON and USING clause of joins.
//	**
//	**    (4)  Scan the list of columns in the result set (pEList) looking
//	**         for instances of the "*" operator or the TABLE.* operator.
//	**         If found, expand each "*" to be every column in every table
//	**         and TABLE.* to be every column in TABLE.
//	**
//	*/
func _selectExpander(tls *libc.TLS, pWalker uintptr, p uintptr) (r int32) {
	bp := tls.Alloc(32)
	defer tls.Free(32)
	var a, db, pE, pEList, pExpr, pFrom, pLeft, pNestedFrom, pNew, pParse, pRight, pSel, pTab, pTab1, pTabList, pUsing, pX, pX1, zName, zSchemaName, zTName, zTabName, zUName, v2 uintptr
	var eCodeOrig Tu8
	var elistFlags Tu32
	var flags, i, iDb, iErrOfst, ii, j, k, longNames, nAdd, rc, tableSeen, v1 int32
	var nCol Ti16
	var selFlags Tu16
	_, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _ = a, db, eCodeOrig, elistFlags, flags, i, iDb, iErrOfst, ii, j, k, longNames, nAdd, nCol, pE, pEList, pExpr, pFrom, pLeft, pNestedFrom, pNew, pParse, pRight, pSel, pTab, pTab1, pTabList, pUsing, pX, pX1, rc, selFlags, tableSeen, zName, zSchemaName, zTName, zTabName, zUName, v1, v2
	pParse = (*TWalker)(unsafe.Pointer(pWalker)).FpParse
	db = (*TParse)(unsafe.Pointer(pParse)).Fdb
	selFlags = uint16((*TSelect)(unsafe.Pointer(p)).FselFlags)
	elistFlags = uint32(0)
	**(**Tu32)(__ccgo_up(p + 4)) |= uint32(SF_Expanded)
	if (*Tsqlite3)(unsafe.Pointer(db)).FmallocFailed != 0 {
		return int32(WRC_Abort)
	}
	if libc.Int32FromUint16(selFlags)&int32(SF_Expanded) != 0 {
		return int32(WRC_Prune)
	}
	if (*TWalker)(unsafe.Pointer(pWalker)).FeCode != 0 {
		/* Renumber selId because it has been copied from a view */
		v2 = pParse + 132
		*(*int32)(unsafe.Pointer(v2)) = *(*int32)(unsafe.Pointer(v2)) + 1
		v1 = *(*int32)(unsafe.Pointer(v2))
		(*TSelect)(unsafe.Pointer(p)).FselId = libc.Uint32FromInt32(v1)
	}
	pTabList = (*TSelect)(unsafe.Pointer(p)).FpSrc
	pEList = (*TSelect)(unsafe.Pointer(p)).FpEList
	if (*TParse)(unsafe.Pointer(pParse)).FpWith != 0 && (*TSelect)(unsafe.Pointer(p)).FselFlags&uint32(SF_View) != 0 {
		if (*TSelect)(unsafe.Pointer(p)).FpWith == uintptr(0) {
			(*TSelect)(unsafe.Pointer(p)).FpWith = _sqlite3DbMallocZero(tls, db, uint64(uint64(libc.UintptrFromInt32(0)+16)+libc.Uint64FromInt32(libc.Int32FromInt32(1))*libc.Uint64FromInt64(48)))
			if (*TSelect)(unsafe.Pointer(p)).FpWith == uintptr(0) {
				return int32(WRC_Abort)
			}
		}
		(*TWith)(unsafe.Pointer((*TSelect)(unsafe.Pointer(p)).FpWith)).FbView = int32(1)
	}
	_sqlite3WithPush(tls, pParse, (*TSelect)(unsafe.Pointer(p)).FpWith, uint8(0))
	/* Make sure cursor numbers have been assigned to all entries in
	 ** the FROM clause of the SELECT statement.
	 */
	_sqlite3SrcListAssignCursors(tls, pParse, pTabList)
	/* Look up every table named in the FROM clause of the select.  If
	 ** an entry of the FROM clause is a subquery instead of a table or view,
	 ** then create a transient table structure to describe the subquery.
	 */
	i = 0
	pFrom = pTabList + 8
	for {
		if !(i < (*TSrcList)(unsafe.Pointer(pTabList)).FnSrc) {
			break
		}
		if (*TSrcItem)(unsafe.Pointer(pFrom)).FpSTab != 0 {
			goto _3
		}
		if (*TSrcItem)(unsafe.Pointer(pFrom)).FzName == uintptr(0) {
			pSel = (*TSubquery)(unsafe.Pointer(*(*uintptr)(unsafe.Pointer(pFrom + 72)))).FpSelect
			/* A sub-query in the FROM clause of a SELECT */
			if _sqlite3WalkSelect(tls, pWalker, pSel) != 0 {
				return int32(WRC_Abort)
			}
			if _sqlite3ExpandSubquery(tls, pParse, pFrom) != 0 {
				return int32(WRC_Abort)
			}
		} else {
			v1 = _resolveFromTermToCte(tls, pParse, pWalker, pFrom)
			rc = v1
			if v1 != 0 {
				if rc > int32(1) {
					return int32(WRC_Abort)
				}
				pTab = (*TSrcItem)(unsafe.Pointer(pFrom)).FpSTab
			} else {
				/* An ordinary table or view name in the FROM clause */
				v2 = _sqlite3LocateTableItem(tls, pParse, uint32(0), pFrom)
				pTab = v2
				(*TSrcItem)(unsafe.Pointer(pFrom)).FpSTab = v2
				if pTab == uintptr(0) {
					return int32(WRC_Abort)
				}
				if (*TTable)(unsafe.Pointer(pTab)).FnTabRef >= uint32(0xffff) {
					_sqlite3ErrorMsg(tls, pParse, __ccgo_ts+21248, libc.VaList(bp+8, (*TTable)(unsafe.Pointer(pTab)).FzName))
					(*TSrcItem)(unsafe.Pointer(pFrom)).FpSTab = uintptr(0)
					return int32(WRC_Abort)
				}
				(*TTable)(unsafe.Pointer(pTab)).FnTabRef = (*TTable)(unsafe.Pointer(pTab)).FnTabRef + 1
				if !(libc.Int32FromUint8((*TTable)(unsafe.Pointer(pTab)).FeTabType) == libc.Int32FromInt32(TABTYP_VTAB)) && _cannotBeFunction(tls, pParse, pFrom) != 0 {
					return int32(WRC_Abort)
				}
				if !(libc.Int32FromUint8((*TTable)(unsafe.Pointer(pTab)).FeTabType) == libc.Int32FromInt32(TABTYP_NORM)) {
					eCodeOrig = uint8((*TWalker)(unsafe.Pointer(pWalker)).FeCode)
					if _sqlite3ViewGetColumnNames(tls, pParse, pTab) != 0 {
						return int32(WRC_Abort)
					}
					if libc.Int32FromUint8((*TTable)(unsafe.Pointer(pTab)).FeTabType) == int32(TABTYP_VIEW) {
						if (*Tsqlite3)(unsafe.Pointer(db)).Fflags&uint64(SQLITE_EnableView) == uint64(0) && (*TTable)(unsafe.Pointer(pTab)).FpSchema != (**(**TDb)(__ccgo_up((*Tsqlite3)(unsafe.Pointer(db)).FaDb + 1*32))).FpSchema {
							_sqlite3ErrorMsg(tls, pParse, __ccgo_ts+21287, libc.VaList(bp+8, (*TTable)(unsafe.Pointer(pTab)).FzName))
						}
						_sqlite3SrcItemAttachSubquery(tls, pParse, pFrom, (*(*struct {
							FpSelect uintptr
						})(unsafe.Pointer(&(*TTable)(unsafe.Pointer(pTab)).Fu))).FpSelect, int32(1))
					} else {
						if libc.Int32FromUint8((*TTable)(unsafe.Pointer(pTab)).FeTabType) == int32(TABTYP_VTAB) && (int32(*(*uint32)(unsafe.Pointer(pFrom + 24 + 4))&0x100>>8) != 0 || libc.Int32FromUint8((*TParse)(unsafe.Pointer(pParse)).FprepFlags)&int32(SQLITE_PREPARE_FROM_DDL) != 0) && (*(*struct {
							FnArg  int32
							FazArg uintptr
							Fp     uintptr
						})(unsafe.Pointer(pTab + 64))).Fp != uintptr(0) && libc.Int32FromUint8((*TVTable)(unsafe.Pointer((*(*struct {
							FnArg  int32
							FazArg uintptr
							Fp     uintptr
						})(unsafe.Pointer(pTab + 64))).Fp)).FeVtabRisk) > libc.BoolInt32((*Tsqlite3)(unsafe.Pointer(db)).Fflags&uint64(SQLITE_TrustedSchema) != uint64(0)) {
							_sqlite3ErrorMsg(tls, pParse, __ccgo_ts+16338, libc.VaList(bp+8, (*TTable)(unsafe.Pointer(pTab)).FzName))
						}
					}
					nCol = (*TTable)(unsafe.Pointer(pTab)).FnCol
					(*TTable)(unsafe.Pointer(pTab)).FnCol = int16(-int32(1))
					(*TWalker)(unsafe.Pointer(pWalker)).FeCode = uint16(1) /* Turn on Select.selId renumbering */
					if int32(*(*uint32)(unsafe.Pointer(pFrom + 24 + 4))&0x4>>2) != 0 {
						_sqlite3WalkSelect(tls, pWalker, (*TSubquery)(unsafe.Pointer(*(*uintptr)(unsafe.Pointer(pFrom + 72)))).FpSelect)
					}
					(*TWalker)(unsafe.Pointer(pWalker)).FeCode = uint16(eCodeOrig)
					(*TTable)(unsafe.Pointer(pTab)).FnCol = nCol
				}
			}
		}
		/* Locate the index named by the INDEXED BY clause, if any. */
		if int32(*(*uint32)(unsafe.Pointer(pFrom + 24 + 4))&0x2>>1) != 0 && _sqlite3IndexedByLookup(tls, pParse, pFrom) != 0 {
			return int32(WRC_Abort)
		}
		goto _3
	_3:
		;
		i = i + 1
		pFrom += 80
	}
	/* Process NATURAL keywords, and ON and USING clauses of joins.
	 */
	if (*TParse)(unsafe.Pointer(pParse)).FnErr != 0 || _sqlite3ProcessJoin(tls, pParse, p) != 0 {
		return int32(WRC_Abort)
	}
	/* For every "*" that occurs in the column list, insert the names of
	 ** all columns in all tables.  And for every TABLE.* insert the names
	 ** of all columns in TABLE.  The parser inserted a special expression
	 ** with the TK_ASTERISK operator for each "*" that it found in the column
	 ** list.  The following code just has to locate the TK_ASTERISK
	 ** expressions and expand each one to the list of all columns in
	 ** all tables.
	 **
	 ** The first loop just checks to see if there are any "*" operators
	 ** that need expanding.
	 */
	k = 0
	for {
		if !(k < (*TExprList)(unsafe.Pointer(pEList)).FnExpr) {
			break
		}
		pE = (*(*TExprList_item)(unsafe.Pointer(pEList + 8 + uintptr(k)*32))).FpExpr
		if libc.Int32FromUint8((*TExpr)(unsafe.Pointer(pE)).Fop) == int32(TK_ASTERISK) {
			break
		}
		if libc.Int32FromUint8((*TExpr)(unsafe.Pointer(pE)).Fop) == int32(TK_DOT) && libc.Int32FromUint8((*TExpr)(unsafe.Pointer((*TExpr)(unsafe.Pointer(pE)).FpRight)).Fop) == int32(TK_ASTERISK) {
			break
		}
		elistFlags = elistFlags | (*TExpr)(unsafe.Pointer(pE)).Fflags
		goto _6
	_6:
		;
		k = k + 1
	}
	if k < (*TExprList)(unsafe.Pointer(pEList)).FnExpr {
		/*
		 ** If we get here it means the result set contains one or more "*"
		 ** operators that need to be expanded.  Loop through each expression
		 ** in the result set and expand them one by one.
		 */
		a = pEList + 8
		pNew = uintptr(0)
		flags = libc.Int32FromUint64((*Tsqlite3)(unsafe.Pointer((*TParse)(unsafe.Pointer(pParse)).Fdb)).Fflags)
		longNames = libc.BoolInt32(flags&int32(SQLITE_FullColNames) != 0 && flags&int32(SQLITE_ShortColNames) == 0)
		k = 0
		for {
			if !(k < (*TExprList)(unsafe.Pointer(pEList)).FnExpr) {
				break
			}
			pE = (**(**TExprList_item)(__ccgo_up(a + uintptr(k)*32))).FpExpr
			elistFlags = elistFlags | (*TExpr)(unsafe.Pointer(pE)).Fflags
			pRight = (*TExpr)(unsafe.Pointer(pE)).FpRight
			if libc.Int32FromUint8((*TExpr)(unsafe.Pointer(pE)).Fop) != int32(TK_ASTERISK) && (libc.Int32FromUint8((*TExpr)(unsafe.Pointer(pE)).Fop) != int32(TK_DOT) || libc.Int32FromUint8((*TExpr)(unsafe.Pointer(pRight)).Fop) != int32(TK_ASTERISK)) {
				/* This particular expression does not need to be expanded.
				 */
				pNew = _sqlite3ExprListAppend(tls, pParse, pNew, (**(**TExprList_item)(__ccgo_up(a + uintptr(k)*32))).FpExpr)
				if pNew != 0 {
					(*(*TExprList_item)(unsafe.Pointer(pNew + 8 + uintptr((*TExprList)(unsafe.Pointer(pNew)).FnExpr-int32(1))*32))).FzEName = (**(**TExprList_item)(__ccgo_up(a + uintptr(k)*32))).FzEName
					libc.SetBitFieldPtr16Uint32(pNew+8+uintptr((*TExprList)(unsafe.Pointer(pNew)).FnExpr-int32(1))*32+16+4, libc.Uint32FromInt32(int32(uint32(*(*uint16)(unsafe.Pointer(a + uintptr(k)*32 + 16 + 4))&0x3>>0))), 0, 0x3)
					(**(**TExprList_item)(__ccgo_up(a + uintptr(k)*32))).FzEName = uintptr(0)
				}
				(**(**TExprList_item)(__ccgo_up(a + uintptr(k)*32))).FpExpr = uintptr(0)
			} else {
				/* This expression is a "*" or a "TABLE.*" and needs to be
				 ** expanded. */
				tableSeen = 0 /* Set to 1 when TABLE matches */
				zTName = uintptr(0)
				if libc.Int32FromUint8((*TExpr)(unsafe.Pointer(pE)).Fop) == int32(TK_DOT) {
					zTName = *(*uintptr)(unsafe.Pointer((*TExpr)(unsafe.Pointer(pE)).FpLeft + 8))
					iErrOfst = *(*int32)(unsafe.Pointer((*TExpr)(unsafe.Pointer(pE)).FpRight + 52))
				} else {
					iErrOfst = *(*int32)(unsafe.Pointer(pE + 52))
				}
				i = 0
				pFrom = pTabList + 8
				for {
					if !(i < (*TSrcList)(unsafe.Pointer(pTabList)).FnSrc) {
						break
					} /* Number of cols including rowid */
					pTab1 = (*TSrcItem)(unsafe.Pointer(pFrom)).FpSTab /* AS name for this data source */
					zSchemaName = uintptr(0)                          /* USING clause for pFrom[1] */
					v2 = (*TSrcItem)(unsafe.Pointer(pFrom)).FzAlias
					zTabName = v2
					if v2 == uintptr(0) {
						zTabName = (*TTable)(unsafe.Pointer(pTab1)).FzName
					}
					if (*Tsqlite3)(unsafe.Pointer(db)).FmallocFailed != 0 {
						break
					}
					if int32(*(*uint32)(unsafe.Pointer(pFrom + 24 + 4))&0x4000>>14) != 0 {
						pNestedFrom = (*TSelect)(unsafe.Pointer((*TSubquery)(unsafe.Pointer(*(*uintptr)(unsafe.Pointer(pFrom + 72)))).FpSelect)).FpEList
					} else {
						if zTName != 0 && _sqlite3StrICmp(tls, zTName, zTabName) != 0 {
							goto _8
						}
						pNestedFrom = uintptr(0)
						iDb = _sqlite3SchemaToIndex(tls, db, (*TTable)(unsafe.Pointer(pTab1)).FpSchema)
						if iDb >= 0 {
							v2 = (**(**TDb)(__ccgo_up((*Tsqlite3)(unsafe.Pointer(db)).FaDb + uintptr(iDb)*32))).FzDbSName
						} else {
							v2 = __ccgo_ts + 6814
						}
						zSchemaName = v2
					}
					if i+int32(1) < (*TSrcList)(unsafe.Pointer(pTabList)).FnSrc && int32(*(*uint32)(unsafe.Pointer(pFrom + 1*80 + 24 + 4))&0x800>>11) != 0 && libc.Int32FromUint16(selFlags)&int32(SF_NestedFrom) != 0 {
						pUsing = *(*uintptr)(unsafe.Pointer(pFrom + 1*80 + 64))
						ii = 0
						for {
							if !(ii < (*TIdList)(unsafe.Pointer(pUsing)).FnId) {
								break
							}
							zUName = (*(*TIdList_item)(unsafe.Pointer(pUsing + 8 + uintptr(ii)*8))).FzName
							pRight = _sqlite3Expr(tls, db, int32(TK_ID), zUName)
							_sqlite3ExprSetErrorOffset(tls, pRight, iErrOfst)
							pNew = _sqlite3ExprListAppend(tls, pParse, pNew, pRight)
							if pNew != 0 {
								pX = pNew + 8 + uintptr((*TExprList)(unsafe.Pointer(pNew)).FnExpr-int32(1))*32
								(*TExprList_item)(unsafe.Pointer(pX)).FzEName = _sqlite3MPrintf(tls, db, __ccgo_ts+21318, libc.VaList(bp+8, zUName))
								libc.SetBitFieldPtr16Uint32(pX+16+4, libc.Uint32FromInt32(ENAME_TAB), 0, 0x3)
								libc.SetBitFieldPtr16Uint32(pX+16+4, libc.Uint32FromInt32(1), 7, 0x80)
							}
							goto _11
						_11:
							;
							ii = ii + 1
						}
					} else {
						pUsing = uintptr(0)
					}
					nAdd = int32((*TTable)(unsafe.Pointer(pTab1)).FnCol)
					if (*TTable)(unsafe.Pointer(pTab1)).FtabFlags&uint32(TF_NoVisibleRowid) == uint32(0) && libc.Int32FromUint16(selFlags)&int32(SF_NestedFrom) != 0 {
						nAdd = nAdd + 1
					}
					j = 0
					for {
						if !(j < nAdd) {
							break
						} /* Newly added ExprList term */
						if j == int32((*TTable)(unsafe.Pointer(pTab1)).FnCol) {
							zName = _sqlite3RowidAlias(tls, pTab1)
							if zName == uintptr(0) {
								goto _12
							}
						} else {
							zName = (**(**TColumn)(__ccgo_up((*TTable)(unsafe.Pointer(pTab1)).FaCol + uintptr(j)*16))).FzCnName
							/* If pTab is actually an SF_NestedFrom sub-select, do not
							 ** expand any ENAME_ROWID columns.  */
							if pNestedFrom != 0 && int32(uint32(*(*uint16)(unsafe.Pointer(pNestedFrom + 8 + uintptr(j)*32 + 16 + 4))&0x3>>0)) == int32(ENAME_ROWID) {
								goto _12
							}
							if zTName != 0 && pNestedFrom != 0 && _sqlite3MatchEName(tls, pNestedFrom+8+uintptr(j)*32, uintptr(0), zTName, uintptr(0), uintptr(0)) == 0 {
								goto _12
							}
							/* If a column is marked as 'hidden', omit it from the expanded
							 ** result-set list unless the SELECT has the SF_IncludeHidden
							 ** bit set.
							 */
							if (*TSelect)(unsafe.Pointer(p)).FselFlags&uint32(SF_IncludeHidden) == uint32(0) && libc.Int32FromUint16((*TColumn)(unsafe.Pointer((*TTable)(unsafe.Pointer(pTab1)).FaCol+uintptr(j)*16)).FcolFlags)&int32(COLFLAG_HIDDEN) != 0 {
								goto _12
							}
							if libc.Int32FromUint16((**(**TColumn)(__ccgo_up((*TTable)(unsafe.Pointer(pTab1)).FaCol + uintptr(j)*16))).FcolFlags)&int32(COLFLAG_NOEXPAND) != 0 && zTName == uintptr(0) && libc.Int32FromUint16(selFlags)&int32(SF_NestedFrom) == 0 {
								goto _12
							}
						}
						tableSeen = int32(1)
						if i > 0 && zTName == uintptr(0) && libc.Int32FromUint16(selFlags)&int32(SF_NestedFrom) == 0 {
							if int32(*(*uint32)(unsafe.Pointer(pFrom + 24 + 4))&0x800>>11) != 0 && _sqlite3IdListIndex(tls, *(*uintptr)(unsafe.Pointer(pFrom + 64)), zName) >= 0 {
								/* In a join with a USING clause, omit columns in the
								 ** using clause from the table on the right. */
								goto _12
							}
						}
						pRight = _sqlite3Expr(tls, db, int32(TK_ID), zName)
						if (*TSrcList)(unsafe.Pointer(pTabList)).FnSrc > int32(1) && (libc.Int32FromUint8((*TSrcItem)(unsafe.Pointer(pFrom)).Ffg.Fjointype)&int32(JT_LTORJ) == 0 || libc.Int32FromUint16(selFlags)&int32(SF_NestedFrom) != 0 || !(_inAnyUsingClause(tls, zName, pFrom, (*TSrcList)(unsafe.Pointer(pTabList)).FnSrc-i-int32(1)) != 0)) || libc.Int32FromUint8((*TParse)(unsafe.Pointer(pParse)).FeParseMode) >= int32(PARSE_MODE_RENAME) {
							pLeft = _sqlite3Expr(tls, db, int32(TK_ID), zTabName)
							pExpr = _sqlite3PExpr(tls, pParse, int32(TK_DOT), pLeft, pRight)
							if libc.Int32FromUint8((*TParse)(unsafe.Pointer(pParse)).FeParseMode) >= int32(PARSE_MODE_RENAME) && (*TExpr)(unsafe.Pointer(pE)).FpLeft != 0 {
								_sqlite3RenameTokenRemap(tls, pParse, pLeft, (*TExpr)(unsafe.Pointer(pE)).FpLeft)
							}
							if zSchemaName != 0 {
								pLeft = _sqlite3Expr(tls, db, int32(TK_ID), zSchemaName)
								pExpr = _sqlite3PExpr(tls, pParse, int32(TK_DOT), pLeft, pExpr)
							}
						} else {
							pExpr = pRight
						}
						_sqlite3ExprSetErrorOffset(tls, pExpr, iErrOfst)
						pNew = _sqlite3ExprListAppend(tls, pParse, pNew, pExpr)
						if pNew == uintptr(0) {
							break /* OOM */
						}
						pX1 = pNew + 8 + uintptr((*TExprList)(unsafe.Pointer(pNew)).FnExpr-int32(1))*32
						if libc.Int32FromUint16(selFlags)&int32(SF_NestedFrom) != 0 && !(libc.Int32FromUint8((*TParse)(unsafe.Pointer(pParse)).FeParseMode) >= libc.Int32FromInt32(PARSE_MODE_RENAME)) {
							if pNestedFrom != 0 && libc.Bool(libc.Bool(!(libc.Int32FromInt32(ViewCanHaveRowid) != 0)) || j < (*TExprList)(unsafe.Pointer(pNestedFrom)).FnExpr) {
								(*TExprList_item)(unsafe.Pointer(pX1)).FzEName = _sqlite3DbStrDup(tls, db, (*(*TExprList_item)(unsafe.Pointer(pNestedFrom + 8 + uintptr(j)*32))).FzEName)
							} else {
								(*TExprList_item)(unsafe.Pointer(pX1)).FzEName = _sqlite3MPrintf(tls, db, __ccgo_ts+21323, libc.VaList(bp+8, zSchemaName, zTabName, zName))
							}
							if j == int32((*TTable)(unsafe.Pointer(pTab1)).FnCol) {
								v1 = int32(ENAME_ROWID)
							} else {
								v1 = int32(ENAME_TAB)
							}
							libc.SetBitFieldPtr16Uint32(pX1+16+4, libc.Uint32FromInt32(v1), 0, 0x3)
							if int32(*(*uint32)(unsafe.Pointer(pFrom + 24 + 4))&0x800>>11) != 0 && _sqlite3IdListIndex(tls, *(*uintptr)(unsafe.Pointer(pFrom + 64)), zName) >= 0 || pUsing != 0 && _sqlite3IdListIndex(tls, pUsing, zName) >= 0 || j < int32((*TTable)(unsafe.Pointer(pTab1)).FnCol) && libc.Int32FromUint16((**(**TColumn)(__ccgo_up((*TTable)(unsafe.Pointer(pTab1)).FaCol + uintptr(j)*16))).FcolFlags)&int32(COLFLAG_NOEXPAND) != 0 {
								libc.SetBitFieldPtr16Uint32(pX1+16+4, libc.Uint32FromInt32(1), 8, 0x100)
							}
						} else {
							if longNames != 0 {
								(*TExprList_item)(unsafe.Pointer(pX1)).FzEName = _sqlite3MPrintf(tls, db, __ccgo_ts+13625, libc.VaList(bp+8, zTabName, zName))
								libc.SetBitFieldPtr16Uint32(pX1+16+4, libc.Uint32FromInt32(ENAME_NAME), 0, 0x3)
							} else {
								(*TExprList_item)(unsafe.Pointer(pX1)).FzEName = _sqlite3DbStrDup(tls, db, zName)
								libc.SetBitFieldPtr16Uint32(pX1+16+4, libc.Uint32FromInt32(ENAME_NAME), 0, 0x3)
							}
						}
						goto _12
					_12:
						;
						j = j + 1
					}
					goto _8
				_8:
					;
					i = i + 1
					pFrom += 80
				}
				if !(tableSeen != 0) {
					if zTName != 0 {
						_sqlite3ErrorMsg(tls, pParse, __ccgo_ts+21332, libc.VaList(bp+8, zTName))
					} else {
						_sqlite3ErrorMsg(tls, pParse, __ccgo_ts+21350, 0)
					}
				}
			}
			goto _7
		_7:
			;
			k = k + 1
		}
		_sqlite3ExprListDelete(tls, db, pEList)
		(*TSelect)(unsafe.Pointer(p)).FpEList = pNew
	}
	if (*TSelect)(unsafe.Pointer(p)).FpEList != 0 {
		if (*TExprList)(unsafe.Pointer((*TSelect)(unsafe.Pointer(p)).FpEList)).FnExpr > **(**int32)(__ccgo_up(db + 136 + 2*4)) {
			_sqlite3ErrorMsg(tls, pParse, __ccgo_ts+21370, 0)
			return int32(WRC_Abort)
		}
		if elistFlags&libc.Uint32FromInt32(libc.Int32FromInt32(EP_HasFunc)|libc.Int32FromInt32(EP_Subquery)) != uint32(0) {
			**(**Tu32)(__ccgo_up(p + 4)) |= uint32(SF_ComplexResult)
		}
	}
	return WRC_Continue
}

// C documentation
//
//	/*
//	** This routine generates the code for the inside of the inner loop
//	** of a SELECT.
//	**
//	** If srcTab is negative, then the p->pEList expressions
//	** are evaluated in order to get the data for this row.  If srcTab is
//	** zero or more, then data is pulled from srcTab and p->pEList is used only
//	** to get the number of columns and the collation sequence for each column.
//	*/
func _selectInnerLoop(tls *libc.TLS, pParse uintptr, p uintptr, srcTab int32, pSort uintptr, pDistinct uintptr, pDest uintptr, iContinue int32, iBreak int32) {
	bp := tls.Alloc(16)
	defer tls.Free(16)
	var addr, addrTest, eDest, eType, hasDistinct, i, i2, iParm, iTab, j, nKey, nPrefixReg, nResultCol, r1, r11, r12, r13, r2, r21, r3, regOrig, regResult, v1 int32
	var ecelFlags Tu8
	var pEList, pSO, v uintptr
	var _ /* sRowLoadInfo at bp+0 */ TRowLoadInfo
	_, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _ = addr, addrTest, eDest, eType, ecelFlags, hasDistinct, i, i2, iParm, iTab, j, nKey, nPrefixReg, nResultCol, pEList, pSO, r1, r11, r12, r13, r2, r21, r3, regOrig, regResult, v, v1
	v = (*TParse)(unsafe.Pointer(pParse)).FpVdbe                              /* True if the DISTINCT keyword is present */
	eDest = libc.Int32FromUint8((*TSelectDest)(unsafe.Pointer(pDest)).FeDest) /* How to dispose of results */
	iParm = (*TSelectDest)(unsafe.Pointer(pDest)).FiSDParm                    /* Number of result columns */
	nPrefixReg = 0                                                            /* Start of memory holding full result (or 0) */
	if pDistinct != 0 {
		v1 = libc.Int32FromUint8((*TDistinctCtx)(unsafe.Pointer(pDistinct)).FeTnctType)
	} else {
		v1 = WHERE_DISTINCT_NOOP
	}
	hasDistinct = v1
	if pSort != 0 && (*TSortCtx)(unsafe.Pointer(pSort)).FpOrderBy == uintptr(0) {
		pSort = uintptr(0)
	}
	if pSort == uintptr(0) && !(hasDistinct != 0) {
		_codeOffset(tls, v, (*TSelect)(unsafe.Pointer(p)).FiOffset, iContinue)
	}
	/* Pull the requested columns.
	 */
	nResultCol = (*TExprList)(unsafe.Pointer((*TSelect)(unsafe.Pointer(p)).FpEList)).FnExpr
	if (*TSelectDest)(unsafe.Pointer(pDest)).FiSdst == 0 {
		if pSort != 0 {
			nPrefixReg = (*TExprList)(unsafe.Pointer((*TSortCtx)(unsafe.Pointer(pSort)).FpOrderBy)).FnExpr
			if !(libc.Int32FromUint8((*TSortCtx)(unsafe.Pointer(pSort)).FsortFlags)&libc.Int32FromInt32(SORTFLAG_UseSorter) != 0) {
				nPrefixReg = nPrefixReg + 1
			}
			**(**int32)(__ccgo_up(pParse + 60)) += nPrefixReg
		}
		(*TSelectDest)(unsafe.Pointer(pDest)).FiSdst = (*TParse)(unsafe.Pointer(pParse)).FnMem + int32(1)
		**(**int32)(__ccgo_up(pParse + 60)) += nResultCol
	} else {
		if (*TSelectDest)(unsafe.Pointer(pDest)).FiSdst+nResultCol > (*TParse)(unsafe.Pointer(pParse)).FnMem {
			/* This is an error condition that can result, for example, when a SELECT
			 ** on the right-hand side of an INSERT contains more result columns than
			 ** there are columns in the table on the left.  The error will be caught
			 ** and reported later.  But we need to make sure enough memory is allocated
			 ** to avoid other spurious errors in the meantime. */
			**(**int32)(__ccgo_up(pParse + 60)) += nResultCol
		}
	}
	(*TSelectDest)(unsafe.Pointer(pDest)).FnSdst = nResultCol
	v1 = (*TSelectDest)(unsafe.Pointer(pDest)).FiSdst
	regResult = v1
	regOrig = v1
	if srcTab >= 0 {
		i = 0
		for {
			if !(i < nResultCol) {
				break
			}
			_sqlite3VdbeAddOp3(tls, v, int32(OP_Column), srcTab, i, regResult+i)
			goto _3
		_3:
			;
			i = i + 1
		}
	} else {
		if eDest != int32(SRT_Exists) {
			if eDest == int32(SRT_Mem) || eDest == int32(SRT_Output) || eDest == int32(SRT_Coroutine) {
				ecelFlags = uint8(SQLITE_ECEL_DUP)
			} else {
				ecelFlags = uint8(0)
			}
			if pSort != 0 && hasDistinct == 0 && eDest != int32(SRT_EphemTab) && eDest != int32(SRT_Table) {
				/* For each expression in p->pEList that is a copy of an expression in
				 ** the ORDER BY clause (pSort->pOrderBy), set the associated
				 ** iOrderByCol value to one more than the index of the ORDER BY
				 ** expression within the sort-key that pushOntoSorter() will generate.
				 ** This allows the p->pEList field to be omitted from the sorted record,
				 ** saving space and CPU cycles.  */
				ecelFlags = libc.Uint8FromInt32(int32(ecelFlags) | (libc.Int32FromInt32(SQLITE_ECEL_OMITREF) | libc.Int32FromInt32(SQLITE_ECEL_REF)))
				i = (*TSortCtx)(unsafe.Pointer(pSort)).FnOBSat
				for {
					if !(i < (*TExprList)(unsafe.Pointer((*TSortCtx)(unsafe.Pointer(pSort)).FpOrderBy)).FnExpr) {
						break
					}
					v1 = libc.Int32FromUint16(*(*Tu16)(unsafe.Pointer((*TSortCtx)(unsafe.Pointer(pSort)).FpOrderBy + 8 + uintptr(i)*32 + 24)))
					j = v1
					if v1 > 0 {
						*(*Tu16)(unsafe.Pointer((*TSelect)(unsafe.Pointer(p)).FpEList + 8 + uintptr(j-int32(1))*32 + 24)) = libc.Uint16FromInt32(i + int32(1) - (*TSortCtx)(unsafe.Pointer(pSort)).FnOBSat)
					}
					goto _4
				_4:
					;
					i = i + 1
				}
				/* Adjust nResultCol to account for columns that are omitted
				 ** from the sorter by the optimizations in this branch */
				pEList = (*TSelect)(unsafe.Pointer(p)).FpEList
				i = 0
				for {
					if !(i < (*TExprList)(unsafe.Pointer(pEList)).FnExpr) {
						break
					}
					if libc.Int32FromUint16(*(*Tu16)(unsafe.Pointer(pEList + 8 + uintptr(i)*32 + 24))) > 0 {
						nResultCol = nResultCol - 1
						regOrig = 0
					}
					goto _6
				_6:
					;
					i = i + 1
				}
			}
			(**(**TRowLoadInfo)(__ccgo_up(bp))).FregResult = regResult
			(**(**TRowLoadInfo)(__ccgo_up(bp))).FecelFlags = ecelFlags
			if (*TSelect)(unsafe.Pointer(p)).FiLimit != 0 && libc.Int32FromUint8(ecelFlags)&int32(SQLITE_ECEL_OMITREF) != 0 && nPrefixReg > 0 {
				(*TSortCtx)(unsafe.Pointer(pSort)).FpDeferredRowLoad = bp
				regOrig = 0
			} else {
				_innerLoopLoadRow(tls, pParse, p, bp)
			}
		}
	}
	/* If the DISTINCT keyword was present on the SELECT statement
	 ** and this row has been seen before, then do not make this row
	 ** part of the result.
	 */
	if hasDistinct != 0 {
		eType = libc.Int32FromUint8((*TDistinctCtx)(unsafe.Pointer(pDistinct)).FeTnctType)
		iTab = (*TDistinctCtx)(unsafe.Pointer(pDistinct)).FtabTnct
		iTab = _codeDistinct(tls, pParse, eType, iTab, iContinue, (*TSelect)(unsafe.Pointer(p)).FpEList, regResult)
		_fixDistinctOpenEph(tls, pParse, eType, iTab, (*TDistinctCtx)(unsafe.Pointer(pDistinct)).FaddrTnct)
		if pSort == uintptr(0) {
			_codeOffset(tls, v, (*TSelect)(unsafe.Pointer(p)).FiOffset, iContinue)
		}
	}
	switch eDest {
	/* Store the result as data using a unique key.
	 */
	case int32(SRT_Fifo):
		fallthrough
	case int32(SRT_DistFifo):
		fallthrough
	case int32(SRT_Table):
		fallthrough
	case int32(SRT_EphemTab):
		r1 = _sqlite3GetTempRange(tls, pParse, nPrefixReg+int32(1))
		_sqlite3VdbeAddOp3(tls, v, int32(OP_MakeRecord), regResult, nResultCol, r1+nPrefixReg)
		if eDest == int32(SRT_DistFifo) {
			/* If the destination is DistFifo, then cursor (iParm+1) is open
			 ** on an ephemeral index. If the current row is already present
			 ** in the index, do not write it to the output. If not, add the
			 ** current row to the index and proceed with writing it to the
			 ** output table as well.  */
			addr = _sqlite3VdbeCurrentAddr(tls, v) + int32(4)
			_sqlite3VdbeAddOp4Int(tls, v, int32(OP_Found), iParm+int32(1), addr, r1, 0)
			_sqlite3VdbeAddOp4Int(tls, v, int32(OP_IdxInsert), iParm+int32(1), r1, regResult, nResultCol)
		}
		if pSort != 0 {
			_pushOntoSorter(tls, pParse, pSort, p, r1+nPrefixReg, regOrig, int32(1), nPrefixReg)
		} else {
			r2 = _sqlite3GetTempReg(tls, pParse)
			_sqlite3VdbeAddOp2(tls, v, int32(OP_NewRowid), iParm, r2)
			_sqlite3VdbeAddOp3(tls, v, int32(OP_Insert), iParm, r1, r2)
			_sqlite3VdbeChangeP5(tls, v, uint16(OPFLAG_APPEND))
			_sqlite3ReleaseTempReg(tls, pParse, r2)
		}
		_sqlite3ReleaseTempRange(tls, pParse, r1, nPrefixReg+int32(1))
	case int32(SRT_Upfrom):
		if pSort != 0 {
			_pushOntoSorter(tls, pParse, pSort, p, regResult, regOrig, nResultCol, nPrefixReg)
		} else {
			i2 = (*TSelectDest)(unsafe.Pointer(pDest)).FiSDParm2
			r11 = _sqlite3GetTempReg(tls, pParse)
			/* If the UPDATE FROM join is an aggregate that matches no rows, it
			 ** might still be trying to return one row, because that is what
			 ** aggregates do.  Don't record that empty row in the output table. */
			_sqlite3VdbeAddOp2(tls, v, int32(OP_IsNull), regResult, iBreak)
			_sqlite3VdbeAddOp3(tls, v, int32(OP_MakeRecord), regResult+libc.BoolInt32(i2 < 0), nResultCol-libc.BoolInt32(i2 < 0), r11)
			if i2 < 0 {
				_sqlite3VdbeAddOp3(tls, v, int32(OP_Insert), iParm, r11, regResult)
			} else {
				_sqlite3VdbeAddOp4Int(tls, v, int32(OP_IdxInsert), iParm, r11, regResult, i2)
			}
		}
		break
		/* If we are creating a set for an "expr IN (SELECT ...)" construct,
		 ** then there should be a single item on the stack.  Write this
		 ** item into the set table with bogus data.
		 */
		fallthrough
	case int32(SRT_Set):
		if pSort != 0 {
			/* At first glance you would think we could optimize out the
			 ** ORDER BY in this case since the order of entries in the set
			 ** does not matter.  But there might be a LIMIT clause, in which
			 ** case the order does matter */
			_pushOntoSorter(tls, pParse, pSort, p, regResult, regOrig, nResultCol, nPrefixReg)
			(*TSelectDest)(unsafe.Pointer(pDest)).FiSDParm2 = 0 /* Signal that any Bloom filter is unpopulated */
		} else {
			r12 = _sqlite3GetTempReg(tls, pParse)
			_sqlite3VdbeAddOp4(tls, v, int32(OP_MakeRecord), regResult, nResultCol, r12, (*TSelectDest)(unsafe.Pointer(pDest)).FzAffSdst, nResultCol)
			_sqlite3VdbeAddOp4Int(tls, v, int32(OP_IdxInsert), iParm, r12, regResult, nResultCol)
			if (*TSelectDest)(unsafe.Pointer(pDest)).FiSDParm2 != 0 {
				_sqlite3VdbeAddOp4Int(tls, v, int32(OP_FilterAdd), (*TSelectDest)(unsafe.Pointer(pDest)).FiSDParm2, 0, regResult, nResultCol)
				_sqlite3VdbeExplain(tls, pParse, uint8(0), __ccgo_ts+20458, 0)
			}
			_sqlite3ReleaseTempReg(tls, pParse, r12)
		}
		break
		/* If any row exist in the result set, record that fact and abort.
		 */
		fallthrough
	case int32(SRT_Exists):
		_sqlite3VdbeAddOp2(tls, v, int32(OP_Integer), int32(1), iParm)
		/* The LIMIT clause will terminate the loop for us */
		break
		/* If this is a scalar select that is part of an expression, then
		 ** store the results in the appropriate memory cell or array of
		 ** memory cells and break out of the scan loop.
		 */
		fallthrough
	case int32(SRT_Mem):
		if pSort != 0 {
			_pushOntoSorter(tls, pParse, pSort, p, regResult, regOrig, nResultCol, nPrefixReg)
			(*TSelectDest)(unsafe.Pointer(pDest)).FiSDParm = regResult
		} else {
			if regResult != iParm {
				/* This occurs in cases where the SELECT had both a DISTINCT and
				 ** an OFFSET clause.  */
				_sqlite3VdbeAddOp3(tls, v, int32(OP_Copy), regResult, iParm, nResultCol-int32(1))
			}
			/* The LIMIT clause will jump out of the loop for us */
		}
	case int32(SRT_Coroutine): /* Send data to a co-routine */
		fallthrough
	case int32(SRT_Output): /* Return the results */
		if pSort != 0 {
			_pushOntoSorter(tls, pParse, pSort, p, regResult, regOrig, nResultCol, nPrefixReg)
		} else {
			if eDest == int32(SRT_Coroutine) {
				_sqlite3VdbeAddOp1(tls, v, int32(OP_Yield), (*TSelectDest)(unsafe.Pointer(pDest)).FiSDParm)
			} else {
				_sqlite3VdbeAddOp2(tls, v, int32(OP_ResultRow), regResult, nResultCol)
			}
		}
		break
		/* Write the results into a priority queue that is order according to
		 ** pDest->pOrderBy (in pSO).  pDest->iSDParm (in iParm) is the cursor for an
		 ** index with pSO->nExpr+2 columns.  Build a key using pSO for the first
		 ** pSO->nExpr columns, then make sure all keys are unique by adding a
		 ** final OP_Sequence column.  The last column is the record as a blob.
		 */
		fallthrough
	case int32(SRT_DistQueue):
		fallthrough
	case int32(SRT_Queue):
		addrTest = 0
		pSO = (*TSelectDest)(unsafe.Pointer(pDest)).FpOrderBy
		nKey = (*TExprList)(unsafe.Pointer(pSO)).FnExpr
		r13 = _sqlite3GetTempReg(tls, pParse)
		r21 = _sqlite3GetTempRange(tls, pParse, nKey+int32(2))
		r3 = r21 + nKey + int32(1)
		if eDest == int32(SRT_DistQueue) {
			/* If the destination is DistQueue, then cursor (iParm+1) is open
			 ** on a second ephemeral index that holds all values every previously
			 ** added to the queue. */
			addrTest = _sqlite3VdbeAddOp4Int(tls, v, int32(OP_Found), iParm+int32(1), 0, regResult, nResultCol)
		}
		_sqlite3VdbeAddOp3(tls, v, int32(OP_MakeRecord), regResult, nResultCol, r3)
		if eDest == int32(SRT_DistQueue) {
			_sqlite3VdbeAddOp2(tls, v, int32(OP_IdxInsert), iParm+int32(1), r3)
			_sqlite3VdbeChangeP5(tls, v, uint16(OPFLAG_USESEEKRESULT))
		}
		i = 0
		for {
			if !(i < nKey) {
				break
			}
			_sqlite3VdbeAddOp2(tls, v, int32(OP_SCopy), regResult+libc.Int32FromUint16(*(*Tu16)(unsafe.Pointer(pSO + 8 + uintptr(i)*32 + 24)))-int32(1), r21+i)
			goto _7
		_7:
			;
			i = i + 1
		}
		_sqlite3VdbeAddOp2(tls, v, int32(OP_Sequence), iParm, r21+nKey)
		_sqlite3VdbeAddOp3(tls, v, int32(OP_MakeRecord), r21, nKey+int32(2), r13)
		_sqlite3VdbeAddOp4Int(tls, v, int32(OP_IdxInsert), iParm, r13, r21, nKey+int32(2))
		if addrTest != 0 {
			_sqlite3VdbeJumpHere(tls, v, addrTest)
		}
		_sqlite3ReleaseTempReg(tls, pParse, r13)
		_sqlite3ReleaseTempRange(tls, pParse, r21, nKey+int32(2))
		break
		/* Discard the results.  This is used for SELECT statements inside
		 ** the body of a TRIGGER.  The purpose of such selects is to call
		 ** user-defined functions that have side effects.  We do not care
		 ** about the actual results of the select.
		 */
		fallthrough
	default:
		break
	}
	/* Jump to the end of the loop if the LIMIT is reached.  Except, if
	 ** there is a sorter, in which case the sorter has already limited
	 ** the output for us.
	 */
	if pSort == uintptr(0) && (*TSelect)(unsafe.Pointer(p)).FiLimit != 0 {
		_sqlite3VdbeAddOp2(tls, v, int32(OP_DecrJumpZero), (*TSelect)(unsafe.Pointer(p)).FiLimit, iBreak)
	}
}

// C documentation
//
//	/*
//	** Return a comma-separated list of the fully-qualified (with both database
//	** and table name) column names from table pTab. e.g.
//	**
//	**    "main"."t1"."a", "main"."t1"."b", "main"."t1"."c"
//	*/
func _sessionAllCols(tls *libc.TLS, zDb uintptr, pTab uintptr) (r uintptr) {
	bp := tls.Alloc(48)
	defer tls.Free(48)
	var ii int32
	var zRet, v2 uintptr
	_, _, _ = ii, zRet, v2
	zRet = uintptr(0)
	ii = 0
	for {
		if !(ii < (*TSessionTable)(unsafe.Pointer(pTab)).FnCol) {
			break
		}
		if zRet != 0 {
			v2 = __ccgo_ts + 16207
		} else {
			v2 = __ccgo_ts + 1693
		}
		zRet = Xsqlite3_mprintf(tls, __ccgo_ts+35520, libc.VaList(bp+8, zRet, v2, zDb, (*TSessionTable)(unsafe.Pointer(pTab)).FzName, **(**uintptr)(__ccgo_up((*TSessionTable)(unsafe.Pointer(pTab)).FazCol + uintptr(ii)*8))))
		if !(zRet != 0) {
			break
		}
		goto _1
	_1:
		;
		ii = ii + 1
	}
	return zRet
}

// 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.
//	**
//	** The difference between this function and sessionApplyOne() is that this
//	** function handles the case where the conflict-handler is invoked and
//	** returns SQLITE_CHANGESET_REPLACE - indicating that the change should be
//	** retried in some manner.
//	*/
func _sessionApplyOneWithRetry(tls *libc.TLS, db uintptr, pIter uintptr, pApply uintptr, __ccgo_fp_xConflict uintptr, pCtx uintptr) (r int32) {
	bp := tls.Alloc(16)
	defer tls.Free(16)
	var rc int32
	var _ /* bReplace at bp+0 */ int32
	var _ /* bRetry at bp+4 */ int32
	_ = rc
	**(**int32)(__ccgo_up(bp)) = 0
	**(**int32)(__ccgo_up(bp + 4)) = 0
	rc = _sessionApplyOneOp(tls, pIter, pApply, __ccgo_fp_xConflict, pCtx, bp, bp+4)
	if rc == SQLITE_OK {
		/* If the bRetry flag is set, the change has not been applied due to an
		 ** SQLITE_CHANGESET_DATA problem (i.e. this is an UPDATE or DELETE and
		 ** a row with the correct PK is present in the db, but one or more other
		 ** fields do not contain the expected values) and the conflict handler
		 ** returned SQLITE_CHANGESET_REPLACE. In this case retry the operation,
		 ** but pass NULL as the final argument so that sessionApplyOneOp() ignores
		 ** the SQLITE_CHANGESET_DATA problem.  */
		if **(**int32)(__ccgo_up(bp + 4)) != 0 {
			rc = _sessionApplyOneOp(tls, pIter, pApply, __ccgo_fp_xConflict, pCtx, uintptr(0), uintptr(0))
		} else {
			if **(**int32)(__ccgo_up(bp)) != 0 {
				rc = Xsqlite3_exec(tls, db, __ccgo_ts+36316, uintptr(0), uintptr(0), uintptr(0))
				if rc == SQLITE_OK {
					rc = _sessionBindRow(tls, pIter, __ccgo_fp(Xsqlite3changeset_new), (*TSessionApplyCtx)(unsafe.Pointer(pApply)).FnCol, (*TSessionApplyCtx)(unsafe.Pointer(pApply)).FabPK, (*TSessionApplyCtx)(unsafe.Pointer(pApply)).FpDelete)
					Xsqlite3_bind_int(tls, (*TSessionApplyCtx)(unsafe.Pointer(pApply)).FpDelete, (*TSessionApplyCtx)(unsafe.Pointer(pApply)).FnCol+int32(1), int32(1))
				}
				if rc == SQLITE_OK {
					Xsqlite3_step(tls, (*TSessionApplyCtx)(unsafe.Pointer(pApply)).FpDelete)
					rc = Xsqlite3_reset(tls, (*TSessionApplyCtx)(unsafe.Pointer(pApply)).FpDelete)
				}
				if rc == SQLITE_OK {
					rc = _sessionApplyOneOp(tls, pIter, pApply, __ccgo_fp_xConflict, pCtx, uintptr(0), uintptr(0))
				}
				if rc == SQLITE_OK {
					rc = Xsqlite3_exec(tls, db, __ccgo_ts+36337, uintptr(0), uintptr(0), uintptr(0))
				}
			}
		}
	}
	return rc
}

// C documentation
//
//	/*
//	** Argument pIter is a changeset iterator that has been initialized, but
//	** not yet passed to sqlite3changeset_next(). This function applies the
//	** changeset to the main database attached to handle "db". The supplied
//	** conflict handler callback is invoked to resolve any conflicts encountered
//	** while applying the change.
//	*/
func _sessionChangesetApply(tls *libc.TLS, db uintptr, pIter uintptr, __ccgo_fp_xFilter uintptr, __ccgo_fp_xFilterIter uintptr, __ccgo_fp_xConflict uintptr, pCtx uintptr, ppRebase uintptr, pnRebase uintptr, flags int32) (r int32) {
	bp := tls.Alloc(368)
	defer tls.Free(368)
	var bPatchset, i, nMinCol, nTab, rc, rc2, res, schemaMismatch, v2, v3, v4 int32
	var savedFlag Tu64
	var v5, v7 bool
	var _ /* abPK at bp+160 */ uintptr
	var _ /* nCol at bp+144 */ int32
	var _ /* nFk at bp+168 */ int32
	var _ /* notUsed at bp+172 */ int32
	var _ /* op at bp+148 */ int32
	var _ /* sApply at bp+8 */ TSessionApplyCtx
	var _ /* sIter at bp+176 */ Tsqlite3_changeset_iter
	var _ /* zNew at bp+152 */ uintptr
	var _ /* zTab at bp+0 */ uintptr
	_, _, _, _, _, _, _, _, _, _, _, _, _, _ = bPatchset, i, nMinCol, nTab, rc, rc2, res, savedFlag, schemaMismatch, v2, v3, v4, v5, v7
	schemaMismatch = 0
	rc = SQLITE_OK                            /* Return code */
	**(**uintptr)(__ccgo_up(bp)) = uintptr(0) /* Name of current table */
	nTab = 0
	savedFlag = (*Tsqlite3)(unsafe.Pointer(db)).Fflags & (libc.Uint64FromInt32(libc.Int32FromInt32(0x00008)) << libc.Int32FromInt32(32))
	Xsqlite3_mutex_enter(tls, Xsqlite3_db_mutex(tls, db))
	if flags&int32(SQLITE_CHANGESETAPPLY_FKNOACTION) != 0 {
		**(**Tu64)(__ccgo_up(db + 48)) |= libc.Uint64FromInt32(libc.Int32FromInt32(0x00008)) << libc.Int32FromInt32(32)
		**(**int32)(__ccgo_up((**(**TDb)(__ccgo_up((*Tsqlite3)(unsafe.Pointer(db)).FaDb))).FpSchema)) -= int32(32)
	}
	(*Tsqlite3_changeset_iter)(unsafe.Pointer(pIter)).Fin.FbNoDiscard = int32(1)
	libc.Xmemset(tls, bp+8, 0, uint64(136))
	(**(**TSessionApplyCtx)(__ccgo_up(bp + 8))).FbRebase = libc.BoolUint8(ppRebase != 0 && pnRebase != 0)
	(**(**TSessionApplyCtx)(__ccgo_up(bp + 8))).FbInvertConstraints = libc.BoolInt32(!!(flags&libc.Int32FromInt32(SQLITE_CHANGESETAPPLY_INVERT) != 0))
	(**(**TSessionApplyCtx)(__ccgo_up(bp + 8))).FbIgnoreNoop = libc.BoolUint8(!!(flags&libc.Int32FromInt32(SQLITE_CHANGESETAPPLY_IGNORENOOP) != 0))
	(**(**TSessionApplyCtx)(__ccgo_up(bp + 8))).FbNoUpdateLoop = libc.BoolUint8(!!(flags&libc.Int32FromInt32(SQLITE_CHANGESETAPPLY_NOUPDATELOOP) != 0))
	if flags&int32(SQLITE_CHANGESETAPPLY_NOSAVEPOINT) == 0 {
		rc = Xsqlite3_exec(tls, db, __ccgo_ts+36506, uintptr(0), uintptr(0), uintptr(0))
	}
	if rc == SQLITE_OK {
		rc = Xsqlite3_exec(tls, db, __ccgo_ts+36532, uintptr(0), uintptr(0), uintptr(0))
	}
	for rc == SQLITE_OK && int32(SQLITE_ROW) == Xsqlite3changeset_next(tls, pIter) {
		Xsqlite3changeset_op(tls, pIter, bp+152, bp+144, bp+148, uintptr(0))
		if **(**uintptr)(__ccgo_up(bp)) == uintptr(0) || Xsqlite3_strnicmp(tls, **(**uintptr)(__ccgo_up(bp + 152)), **(**uintptr)(__ccgo_up(bp)), nTab+int32(1)) != 0 {
			rc = _sessionRetryConstraints(tls, db, (*Tsqlite3_changeset_iter)(unsafe.Pointer(pIter)).FbPatchset, **(**uintptr)(__ccgo_up(bp)), bp+8, __ccgo_fp_xConflict, pCtx)
			if rc != SQLITE_OK {
				break
			}
			_sessionUpdateFree(tls, bp+8)
			Xsqlite3_free(tls, (**(**TSessionApplyCtx)(__ccgo_up(bp + 8))).FazCol) /* cast works around VC++ bug */
			Xsqlite3_finalize(tls, (**(**TSessionApplyCtx)(__ccgo_up(bp + 8))).FpDelete)
			Xsqlite3_finalize(tls, (**(**TSessionApplyCtx)(__ccgo_up(bp + 8))).FpInsert)
			Xsqlite3_finalize(tls, (**(**TSessionApplyCtx)(__ccgo_up(bp + 8))).FpSelect)
			(**(**TSessionApplyCtx)(__ccgo_up(bp + 8))).Fdb = db
			(**(**TSessionApplyCtx)(__ccgo_up(bp + 8))).FpDelete = uintptr(0)
			(**(**TSessionApplyCtx)(__ccgo_up(bp + 8))).FpInsert = uintptr(0)
			(**(**TSessionApplyCtx)(__ccgo_up(bp + 8))).FpSelect = uintptr(0)
			(**(**TSessionApplyCtx)(__ccgo_up(bp + 8))).FnCol = 0
			(**(**TSessionApplyCtx)(__ccgo_up(bp + 8))).FazCol = uintptr(0)
			(**(**TSessionApplyCtx)(__ccgo_up(bp + 8))).FabPK = uintptr(0)
			(**(**TSessionApplyCtx)(__ccgo_up(bp + 8))).FbStat1 = 0
			(**(**TSessionApplyCtx)(__ccgo_up(bp + 8))).FbDeferConstraints = int32(1)
			(**(**TSessionApplyCtx)(__ccgo_up(bp + 8))).FbRebaseStarted = uint8(0)
			(**(**TSessionApplyCtx)(__ccgo_up(bp + 8))).FbRowid = 0
			libc.Xmemset(tls, bp+8+88, 0, uint64(16))
			/* If an xFilter() callback was specified, invoke it now. If the
			 ** xFilter callback returns zero, skip this table. If it returns
			 ** non-zero, proceed. */
			schemaMismatch = libc.BoolInt32(__ccgo_fp_xFilter != 0 && 0 == (*(*func(*libc.TLS, uintptr, uintptr) int32)(unsafe.Pointer(&struct{ uintptr }{__ccgo_fp_xFilter})))(tls, pCtx, **(**uintptr)(__ccgo_up(bp + 152))))
			if schemaMismatch != 0 {
				**(**uintptr)(__ccgo_up(bp)) = Xsqlite3_mprintf(tls, __ccgo_ts+3933, libc.VaList(bp+336, **(**uintptr)(__ccgo_up(bp + 152))))
				if **(**uintptr)(__ccgo_up(bp)) == uintptr(0) {
					rc = int32(SQLITE_NOMEM)
					break
				}
				nTab = libc.Int32FromUint64(libc.Xstrlen(tls, **(**uintptr)(__ccgo_up(bp))))
				(**(**TSessionApplyCtx)(__ccgo_up(bp + 8))).FazCol = **(**uintptr)(__ccgo_up(bp))
			} else {
				nMinCol = 0
				Xsqlite3changeset_pk(tls, pIter, bp+160, uintptr(0))
				rc = _sessionTableInfo(tls, uintptr(0), db, __ccgo_ts+6809, **(**uintptr)(__ccgo_up(bp + 152)), bp+8+32, uintptr(0), bp, bp+8+40, uintptr(0), uintptr(0), bp+8+48, bp+8+124)
				if rc != SQLITE_OK {
					break
				}
				i = 0
				for {
					if !(i < (**(**TSessionApplyCtx)(__ccgo_up(bp + 8))).FnCol) {
						break
					}
					if **(**Tu8)(__ccgo_up((**(**TSessionApplyCtx)(__ccgo_up(bp + 8))).FabPK + uintptr(i))) != 0 {
						nMinCol = i + int32(1)
					}
					goto _1
				_1:
					;
					i = i + 1
				}
				if (**(**TSessionApplyCtx)(__ccgo_up(bp + 8))).FnCol == 0 {
					schemaMismatch = int32(1)
					Xsqlite3_log(tls, int32(SQLITE_SCHEMA), __ccgo_ts+36562, libc.VaList(bp+336, **(**uintptr)(__ccgo_up(bp))))
				} else {
					if (**(**TSessionApplyCtx)(__ccgo_up(bp + 8))).FnCol < **(**int32)(__ccgo_up(bp + 144)) {
						schemaMismatch = int32(1)
						Xsqlite3_log(tls, int32(SQLITE_SCHEMA), __ccgo_ts+36606, libc.VaList(bp+336, **(**uintptr)(__ccgo_up(bp)), (**(**TSessionApplyCtx)(__ccgo_up(bp + 8))).FnCol, **(**int32)(__ccgo_up(bp + 144))))
					} else {
						if **(**int32)(__ccgo_up(bp + 144)) < nMinCol || libc.Xmemcmp(tls, (**(**TSessionApplyCtx)(__ccgo_up(bp + 8))).FabPK, **(**uintptr)(__ccgo_up(bp + 160)), libc.Uint64FromInt32(**(**int32)(__ccgo_up(bp + 144)))) != 0 {
							schemaMismatch = int32(1)
							Xsqlite3_log(tls, int32(SQLITE_SCHEMA), __ccgo_ts+36677, libc.VaList(bp+336, **(**uintptr)(__ccgo_up(bp))))
						} else {
							(**(**TSessionApplyCtx)(__ccgo_up(bp + 8))).FnCol = **(**int32)(__ccgo_up(bp + 144))
							if 0 == Xsqlite3_stricmp(tls, **(**uintptr)(__ccgo_up(bp)), __ccgo_ts+12826) {
								v2 = _sessionStat1Sql(tls, db, bp+8)
								rc = v2
								if v2 != 0 {
									break
								}
								(**(**TSessionApplyCtx)(__ccgo_up(bp + 8))).FbStat1 = int32(1)
							} else {
								v2 = _sessionSelectRow(tls, db, **(**uintptr)(__ccgo_up(bp)), bp+8)
								rc = v2
								if v5 = v2 != 0; !v5 {
									v3 = _sessionDeleteRow(tls, db, **(**uintptr)(__ccgo_up(bp)), bp+8)
									rc = v3
								}
								if v7 = v5 || v3 != 0; !v7 {
									v4 = _sessionInsertRow(tls, db, **(**uintptr)(__ccgo_up(bp)), bp+8)
									rc = v4
								}
								if v7 || v4 != 0 {
									break
								}
								(**(**TSessionApplyCtx)(__ccgo_up(bp + 8))).FbStat1 = 0
							}
						}
					}
				}
				nTab = _sqlite3Strlen30(tls, **(**uintptr)(__ccgo_up(bp)))
			}
		}
		/* If there is a schema mismatch on the current table, proceed to the
		 ** next change. A log message has already been issued. */
		if schemaMismatch != 0 {
			continue
		}
		/* If this is a call to apply_v3(), invoke xFilterIter here. */
		if __ccgo_fp_xFilterIter != 0 && 0 == (*(*func(*libc.TLS, uintptr, uintptr) int32)(unsafe.Pointer(&struct{ uintptr }{__ccgo_fp_xFilterIter})))(tls, pCtx, pIter) {
			continue
		}
		rc = _sessionApplyOneWithRetry(tls, db, pIter, bp+8, __ccgo_fp_xConflict, pCtx)
	}
	bPatchset = (*Tsqlite3_changeset_iter)(unsafe.Pointer(pIter)).FbPatchset
	if rc == SQLITE_OK {
		rc = Xsqlite3changeset_finalize(tls, pIter)
	} else {
		Xsqlite3changeset_finalize(tls, pIter)
	}
	if rc == SQLITE_OK {
		rc = _sessionRetryConstraints(tls, db, bPatchset, **(**uintptr)(__ccgo_up(bp)), bp+8, __ccgo_fp_xConflict, pCtx)
	}
	if rc == SQLITE_OK {
		Xsqlite3_db_status(tls, db, int32(SQLITE_DBSTATUS_DEFERRED_FKS), bp+168, bp+172, 0)
		if **(**int32)(__ccgo_up(bp + 168)) != 0 {
			res = int32(SQLITE_CHANGESET_ABORT)
			libc.Xmemset(tls, bp+176, 0, uint64(152))
			(**(**Tsqlite3_changeset_iter)(__ccgo_up(bp + 176))).FnCol = **(**int32)(__ccgo_up(bp + 168))
			res = (*(*func(*libc.TLS, uintptr, int32, uintptr) int32)(unsafe.Pointer(&struct{ uintptr }{__ccgo_fp_xConflict})))(tls, pCtx, int32(SQLITE_CHANGESET_FOREIGN_KEY), bp+176)
			if res != SQLITE_CHANGESET_OMIT {
				rc = int32(SQLITE_CONSTRAINT)
			}
		}
	}
	rc2 = Xsqlite3_exec(tls, db, __ccgo_ts+36737, uintptr(0), uintptr(0), uintptr(0))
	if rc == SQLITE_OK {
		rc = rc2
	}
	if flags&int32(SQLITE_CHANGESETAPPLY_NOSAVEPOINT) == 0 {
		if rc == SQLITE_OK {
			rc = Xsqlite3_exec(tls, db, __ccgo_ts+36767, uintptr(0), uintptr(0), uintptr(0))
		}
		if rc != SQLITE_OK {
			Xsqlite3_exec(tls, db, __ccgo_ts+36791, uintptr(0), uintptr(0), uintptr(0))
			Xsqlite3_exec(tls, db, __ccgo_ts+36767, uintptr(0), uintptr(0), uintptr(0))
		}
	}
	if rc == SQLITE_OK && bPatchset == 0 && (**(**TSessionApplyCtx)(__ccgo_up(bp + 8))).FbRebase != 0 {
		**(**uintptr)(__ccgo_up(ppRebase)) = (**(**TSessionApplyCtx)(__ccgo_up(bp + 8))).Frebase.FaBuf
		**(**int32)(__ccgo_up(pnRebase)) = (**(**TSessionApplyCtx)(__ccgo_up(bp + 8))).Frebase.FnBuf
		(**(**TSessionApplyCtx)(__ccgo_up(bp + 8))).Frebase.FaBuf = uintptr(0)
	}
	_sessionUpdateFree(tls, bp+8)
	Xsqlite3_finalize(tls, (**(**TSessionApplyCtx)(__ccgo_up(bp + 8))).FpInsert)
	Xsqlite3_finalize(tls, (**(**TSessionApplyCtx)(__ccgo_up(bp + 8))).FpDelete)
	Xsqlite3_finalize(tls, (**(**TSessionApplyCtx)(__ccgo_up(bp + 8))).FpSelect)
	Xsqlite3_free(tls, (**(**TSessionApplyCtx)(__ccgo_up(bp + 8))).FazCol) /* cast works around VC++ bug */
	Xsqlite3_free(tls, (**(**TSessionApplyCtx)(__ccgo_up(bp + 8))).Fconstraints.FaBuf)
	Xsqlite3_free(tls, (**(**TSessionApplyCtx)(__ccgo_up(bp + 8))).Frebase.FaBuf)
	if flags&int32(SQLITE_CHANGESETAPPLY_FKNOACTION) != 0 && savedFlag == uint64(0) {
		**(**Tu64)(__ccgo_up(db + 48)) &= ^(libc.Uint64FromInt32(libc.Int32FromInt32(0x00008)) << libc.Int32FromInt32(32))
		**(**int32)(__ccgo_up((**(**TDb)(__ccgo_up((*Tsqlite3)(unsafe.Pointer(db)).FaDb))).FpSchema)) -= int32(32)
	}
	Xsqlite3_set_errmsg(tls, db, rc, (**(**TSessionApplyCtx)(__ccgo_up(bp + 8))).FzErr)
	Xsqlite3_free(tls, (**(**TSessionApplyCtx)(__ccgo_up(bp + 8))).FzErr)
	Xsqlite3_mutex_leave(tls, Xsqlite3_db_mutex(tls, db))
	return rc
}

// C documentation
//
//	/*
//	** Formulate a statement to DELETE a row from database db. Assuming a table
//	** structure like this:
//	**
//	**     CREATE TABLE x(a, b, c, d, PRIMARY KEY(a, c));
//	**
//	** The DELETE statement looks like this:
//	**
//	**     DELETE FROM x WHERE a = :1 AND c = :3 AND (:5 OR b IS :2 AND d IS :4)
//	**
//	** Variable :5 (nCol+1) is a boolean. It should be set to 0 if we require
//	** matching b and d values, or 1 otherwise. The second case comes up if the
//	** conflict handler is invoked with NOTFOUND and returns CHANGESET_REPLACE.
//	**
//	** If successful, SQLITE_OK is returned and SessionApplyCtx.pDelete is left
//	** pointing to the prepared version of the SQL statement.
//	*/
func _sessionDeleteRow(tls *libc.TLS, db uintptr, zTab uintptr, p uintptr) (r int32) {
	bp := tls.Alloc(32)
	defer tls.Free(32)
	var i, nPk int32
	var zSep uintptr
	var _ /* buf at bp+8 */ TSessionBuffer
	var _ /* rc at bp+0 */ int32
	_, _, _ = i, nPk, zSep
	zSep = __ccgo_ts + 1693
	**(**int32)(__ccgo_up(bp)) = SQLITE_OK
	**(**TSessionBuffer)(__ccgo_up(bp + 8)) = TSessionBuffer{}
	nPk = 0
	_sessionAppendStr(tls, bp+8, __ccgo_ts+35995, bp)
	_sessionAppendIdent(tls, bp+8, zTab, bp)
	_sessionAppendStr(tls, bp+8, __ccgo_ts+35906, bp)
	i = 0
	for {
		if !(i < (*TSessionApplyCtx)(unsafe.Pointer(p)).FnCol) {
			break
		}
		if **(**Tu8)(__ccgo_up((*TSessionApplyCtx)(unsafe.Pointer(p)).FabPK + uintptr(i))) != 0 {
			nPk = nPk + 1
			_sessionAppendStr(tls, bp+8, zSep, bp)
			_sessionAppendIdent(tls, bp+8, **(**uintptr)(__ccgo_up((*TSessionApplyCtx)(unsafe.Pointer(p)).FazCol + uintptr(i)*8)), bp)
			_sessionAppendStr(tls, bp+8, __ccgo_ts+35901, bp)
			_sessionAppendInteger(tls, bp+8, i+int32(1), bp)
			zSep = __ccgo_ts + 23618
		}
		goto _1
	_1:
		;
		i = i + 1
	}
	if nPk < (*TSessionApplyCtx)(unsafe.Pointer(p)).FnCol {
		_sessionAppendStr(tls, bp+8, __ccgo_ts+36013, bp)
		_sessionAppendInteger(tls, bp+8, (*TSessionApplyCtx)(unsafe.Pointer(p)).FnCol+int32(1), bp)
		_sessionAppendStr(tls, bp+8, __ccgo_ts+35425, bp)
		zSep = __ccgo_ts + 1693
		i = 0
		for {
			if !(i < (*TSessionApplyCtx)(unsafe.Pointer(p)).FnCol) {
				break
			}
			if !(**(**Tu8)(__ccgo_up((*TSessionApplyCtx)(unsafe.Pointer(p)).FabPK + uintptr(i))) != 0) {
				_sessionAppendStr(tls, bp+8, zSep, bp)
				_sessionAppendIdent(tls, bp+8, **(**uintptr)(__ccgo_up((*TSessionApplyCtx)(unsafe.Pointer(p)).FazCol + uintptr(i)*8)), bp)
				_sessionAppendStr(tls, bp+8, __ccgo_ts+35989, bp)
				_sessionAppendInteger(tls, bp+8, i+int32(1), bp)
				zSep = __ccgo_ts + 36021
			}
			goto _2
		_2:
			;
			i = i + 1
		}
		_sessionAppendStr(tls, bp+8, __ccgo_ts+5250, bp)
	}
	if **(**int32)(__ccgo_up(bp)) == SQLITE_OK {
		**(**int32)(__ccgo_up(bp)) = _sessionPrepare(tls, db, p+8, p+128, (**(**TSessionBuffer)(__ccgo_up(bp + 8))).FaBuf)
	}
	Xsqlite3_free(tls, (**(**TSessionBuffer)(__ccgo_up(bp + 8))).FaBuf)
	return **(**int32)(__ccgo_up(bp))
}

func _sessionDiffFindModified(tls *libc.TLS, pSession uintptr, pTab uintptr, zFrom uintptr, zExpr uintptr) (r int32) {
	bp := tls.Alloc(80)
	defer tls.Free(80)
	var iRowid Ti64
	var pDiffCtx, z1, z2, zExpr2, zStmt uintptr
	var rc int32
	var v1 int64
	var _ /* pStmt at bp+0 */ uintptr
	_, _, _, _, _, _, _, _ = iRowid, pDiffCtx, rc, z1, z2, zExpr2, zStmt, v1
	rc = SQLITE_OK
	zExpr2 = _sessionExprCompareOther(tls, (*TSessionTable)(unsafe.Pointer(pTab)).FnCol, (*Tsqlite3_session)(unsafe.Pointer(pSession)).FzDb, zFrom, (*TSessionTable)(unsafe.Pointer(pTab)).FzName, (*TSessionTable)(unsafe.Pointer(pTab)).FazCol, (*TSessionTable)(unsafe.Pointer(pTab)).FabPK)
	if zExpr2 == uintptr(0) {
		rc = int32(SQLITE_NOMEM)
	} else {
		z1 = _sessionAllCols(tls, (*Tsqlite3_session)(unsafe.Pointer(pSession)).FzDb, pTab)
		z2 = _sessionAllCols(tls, zFrom, pTab)
		zStmt = Xsqlite3_mprintf(tls, __ccgo_ts+35539, libc.VaList(bp+16, z1, z2, (*Tsqlite3_session)(unsafe.Pointer(pSession)).FzDb, (*TSessionTable)(unsafe.Pointer(pTab)).FzName, zFrom, (*TSessionTable)(unsafe.Pointer(pTab)).FzName, zExpr, zExpr2))
		if zStmt == uintptr(0) || z1 == uintptr(0) || z2 == uintptr(0) {
			rc = int32(SQLITE_NOMEM)
		} else {
			rc = Xsqlite3_prepare_v2(tls, (*Tsqlite3_session)(unsafe.Pointer(pSession)).Fdb, zStmt, -int32(1), bp, uintptr(0))
			if rc == SQLITE_OK {
				pDiffCtx = (*Tsqlite3_session)(unsafe.Pointer(pSession)).Fhook.FpCtx
				(*TSessionDiffCtx)(unsafe.Pointer(pDiffCtx)).FpStmt = **(**uintptr)(__ccgo_up(bp))
				(*TSessionDiffCtx)(unsafe.Pointer(pDiffCtx)).FnOldOff = (*TSessionTable)(unsafe.Pointer(pTab)).FnCol
				for int32(SQLITE_ROW) == Xsqlite3_step(tls, **(**uintptr)(__ccgo_up(bp))) {
					if (*TSessionTable)(unsafe.Pointer(pTab)).FbRowid != 0 {
						v1 = Xsqlite3_column_int64(tls, **(**uintptr)(__ccgo_up(bp)), 0)
					} else {
						v1 = 0
					}
					iRowid = v1
					_sessionPreupdateOneChange(tls, int32(SQLITE_UPDATE), iRowid, pSession, pTab)
				}
				rc = Xsqlite3_finalize(tls, **(**uintptr)(__ccgo_up(bp)))
			}
		}
		Xsqlite3_free(tls, zStmt)
		Xsqlite3_free(tls, z1)
		Xsqlite3_free(tls, z2)
	}
	return rc
}

func _sessionExprCompareOther(tls *libc.TLS, nCol int32, zDb1 uintptr, zDb2 uintptr, zTab uintptr, azCol uintptr, abPK uintptr) (r uintptr) {
	bp := tls.Alloc(80)
	defer tls.Free(80)
	var bHave, i int32
	var zRet, zSep uintptr
	_, _, _, _ = bHave, i, zRet, zSep
	zSep = __ccgo_ts + 1693
	zRet = uintptr(0)
	bHave = 0
	i = 0
	for {
		if !(i < nCol) {
			break
		}
		if libc.Int32FromUint8(**(**Tu8)(__ccgo_up(abPK + uintptr(i)))) == 0 {
			bHave = int32(1)
			zRet = Xsqlite3_mprintf(tls, __ccgo_ts+35384, libc.VaList(bp+8, zRet, zSep, zDb1, zTab, **(**uintptr)(__ccgo_up(azCol + uintptr(i)*8)), zDb2, zTab, **(**uintptr)(__ccgo_up(azCol + uintptr(i)*8))))
			zSep = __ccgo_ts + 35425
			if zRet == uintptr(0) {
				break
			}
		}
		goto _1
	_1:
		;
		i = i + 1
	}
	if bHave == 0 {
		zRet = Xsqlite3_mprintf(tls, __ccgo_ts+1839, 0)
	}
	return zRet
}

func _sessionExprComparePK(tls *libc.TLS, nCol int32, zDb1 uintptr, zDb2 uintptr, zTab uintptr, azCol uintptr, abPK uintptr) (r uintptr) {
	bp := tls.Alloc(80)
	defer tls.Free(80)
	var i int32
	var zRet, zSep uintptr
	_, _, _ = i, zRet, zSep
	zSep = __ccgo_ts + 1693
	zRet = uintptr(0)
	i = 0
	for {
		if !(i < nCol) {
			break
		}
		if **(**Tu8)(__ccgo_up(abPK + uintptr(i))) != 0 {
			zRet = Xsqlite3_mprintf(tls, __ccgo_ts+35350, libc.VaList(bp+8, zRet, zSep, zDb1, zTab, **(**uintptr)(__ccgo_up(azCol + uintptr(i)*8)), zDb2, zTab, **(**uintptr)(__ccgo_up(azCol + uintptr(i)*8))))
			zSep = __ccgo_ts + 23618
			if zRet == uintptr(0) {
				break
			}
		}
		goto _1
	_1:
		;
		i = i + 1
	}
	return zRet
}

// C documentation
//
//	/*
//	** Generate either a changeset (if argument bPatchset is zero) or a patchset
//	** (if it is non-zero) based on the current contents of the session object
//	** passed as the first argument.
//	**
//	** If no error occurs, SQLITE_OK is returned and the new changeset/patchset
//	** stored in output variables *pnChangeset and *ppChangeset. Or, if an error
//	** occurs, an SQLite error code is returned and both output variables set
//	** to 0.
//	*/
func _sessionGenerateChangeset(tls *libc.TLS, pSession uintptr, bPatchset int32, __ccgo_fp_xOutput uintptr, pOut uintptr, pnChangeset uintptr, ppChangeset uintptr) (r int32) {
	bp := tls.Alloc(32)
	defer tls.Free(32)
	var db, p, pTab, zName uintptr
	var i, iCol, nNoop, nOldCol, nRewind int32
	var _ /* buf at bp+0 */ TSessionBuffer
	var _ /* pSel at bp+24 */ uintptr
	var _ /* rc at bp+16 */ int32
	_, _, _, _, _, _, _, _, _ = db, i, iCol, nNoop, nOldCol, nRewind, p, pTab, zName
	db = (*Tsqlite3_session)(unsafe.Pointer(pSession)).Fdb /* Used to iterate through attached tables */
	**(**TSessionBuffer)(__ccgo_up(bp)) = TSessionBuffer{} /* Return code */
	/* Zero the output variables in case an error occurs. If this session
	 ** object is already in the error state (sqlite3_session.rc != SQLITE_OK),
	 ** this call will be a no-op.  */
	if __ccgo_fp_xOutput == uintptr(0) {
		**(**int32)(__ccgo_up(pnChangeset)) = 0
		**(**uintptr)(__ccgo_up(ppChangeset)) = uintptr(0)
	}
	if (*Tsqlite3_session)(unsafe.Pointer(pSession)).Frc != 0 {
		return (*Tsqlite3_session)(unsafe.Pointer(pSession)).Frc
	}
	Xsqlite3_mutex_enter(tls, Xsqlite3_db_mutex(tls, db))
	**(**int32)(__ccgo_up(bp + 16)) = Xsqlite3_exec(tls, (*Tsqlite3_session)(unsafe.Pointer(pSession)).Fdb, __ccgo_ts+35844, uintptr(0), uintptr(0), uintptr(0))
	if **(**int32)(__ccgo_up(bp + 16)) != SQLITE_OK {
		Xsqlite3_mutex_leave(tls, Xsqlite3_db_mutex(tls, db))
		return **(**int32)(__ccgo_up(bp + 16))
	}
	pTab = (*Tsqlite3_session)(unsafe.Pointer(pSession)).FpTable
	for {
		if !(**(**int32)(__ccgo_up(bp + 16)) == SQLITE_OK && pTab != 0) {
			break
		}
		if (*TSessionTable)(unsafe.Pointer(pTab)).FnEntry != 0 {
			zName = (*TSessionTable)(unsafe.Pointer(pTab)).FzName /* Used to iterate through hash buckets */
			**(**uintptr)(__ccgo_up(bp + 24)) = uintptr(0)        /* SELECT statement to query table pTab */
			nRewind = (**(**TSessionBuffer)(__ccgo_up(bp))).FnBuf /* Size of buffer after writing tbl header */
			nOldCol = (*TSessionTable)(unsafe.Pointer(pTab)).FnCol
			/* Check the table schema is still Ok. */
			**(**int32)(__ccgo_up(bp + 16)) = _sessionReinitTable(tls, pSession, pTab)
			if **(**int32)(__ccgo_up(bp + 16)) == SQLITE_OK && (*TSessionTable)(unsafe.Pointer(pTab)).FnCol != nOldCol {
				**(**int32)(__ccgo_up(bp + 16)) = _sessionUpdateChanges(tls, pSession, pTab)
			}
			/* Write a table header */
			_sessionAppendTableHdr(tls, bp, bPatchset, pTab, bp+16)
			/* Build and compile a statement to execute: */
			if **(**int32)(__ccgo_up(bp + 16)) == SQLITE_OK {
				**(**int32)(__ccgo_up(bp + 16)) = _sessionSelectStmt(tls, db, 0, (*Tsqlite3_session)(unsafe.Pointer(pSession)).FzDb, zName, (*TSessionTable)(unsafe.Pointer(pTab)).FbRowid, (*TSessionTable)(unsafe.Pointer(pTab)).FnCol, (*TSessionTable)(unsafe.Pointer(pTab)).FazCol, (*TSessionTable)(unsafe.Pointer(pTab)).FabPK, bp+24, uintptr(0))
			}
			nNoop = (**(**TSessionBuffer)(__ccgo_up(bp))).FnBuf
			i = 0
			for {
				if !(i < (*TSessionTable)(unsafe.Pointer(pTab)).FnChange && **(**int32)(__ccgo_up(bp + 16)) == SQLITE_OK) {
					break
				} /* Used to iterate through changes */
				p = **(**uintptr)(__ccgo_up((*TSessionTable)(unsafe.Pointer(pTab)).FapChange + uintptr(i)*8))
				for {
					if !(**(**int32)(__ccgo_up(bp + 16)) == SQLITE_OK && p != 0) {
						break
					}
					**(**int32)(__ccgo_up(bp + 16)) = _sessionSelectBind(tls, **(**uintptr)(__ccgo_up(bp + 24)), (*TSessionTable)(unsafe.Pointer(pTab)).FnCol, (*TSessionTable)(unsafe.Pointer(pTab)).FabPK, p)
					if **(**int32)(__ccgo_up(bp + 16)) != SQLITE_OK {
						goto _3
					}
					if Xsqlite3_step(tls, **(**uintptr)(__ccgo_up(bp + 24))) == int32(SQLITE_ROW) {
						if libc.Int32FromUint8((*TSessionChange)(unsafe.Pointer(p)).Fop) == int32(SQLITE_INSERT) {
							_sessionAppendByte(tls, bp, uint8(SQLITE_INSERT), bp+16)
							_sessionAppendByte(tls, bp, (*TSessionChange)(unsafe.Pointer(p)).FbIndirect, bp+16)
							iCol = 0
							for {
								if !(iCol < (*TSessionTable)(unsafe.Pointer(pTab)).FnCol) {
									break
								}
								_sessionAppendCol(tls, bp, **(**uintptr)(__ccgo_up(bp + 24)), iCol, bp+16)
								goto _4
							_4:
								;
								iCol = iCol + 1
							}
						} else {
							**(**int32)(__ccgo_up(bp + 16)) = _sessionAppendUpdate(tls, bp, bPatchset, **(**uintptr)(__ccgo_up(bp + 24)), p, (*TSessionTable)(unsafe.Pointer(pTab)).FabPK)
						}
					} else {
						if libc.Int32FromUint8((*TSessionChange)(unsafe.Pointer(p)).Fop) != int32(SQLITE_INSERT) {
							**(**int32)(__ccgo_up(bp + 16)) = _sessionAppendDelete(tls, bp, bPatchset, p, (*TSessionTable)(unsafe.Pointer(pTab)).FnCol, (*TSessionTable)(unsafe.Pointer(pTab)).FabPK)
						}
					}
					if **(**int32)(__ccgo_up(bp + 16)) == SQLITE_OK {
						**(**int32)(__ccgo_up(bp + 16)) = Xsqlite3_reset(tls, **(**uintptr)(__ccgo_up(bp + 24)))
					}
					/* If the buffer is now larger than sessions_strm_chunk_size, pass
					 ** its contents to the xOutput() callback. */
					if __ccgo_fp_xOutput != 0 && **(**int32)(__ccgo_up(bp + 16)) == SQLITE_OK && (**(**TSessionBuffer)(__ccgo_up(bp))).FnBuf > nNoop && (**(**TSessionBuffer)(__ccgo_up(bp))).FnBuf > _sessions_strm_chunk_size {
						**(**int32)(__ccgo_up(bp + 16)) = (*(*func(*libc.TLS, uintptr, uintptr, int32) int32)(unsafe.Pointer(&struct{ uintptr }{__ccgo_fp_xOutput})))(tls, pOut, (**(**TSessionBuffer)(__ccgo_up(bp))).FaBuf, (**(**TSessionBuffer)(__ccgo_up(bp))).FnBuf)
						nNoop = -int32(1)
						(**(**TSessionBuffer)(__ccgo_up(bp))).FnBuf = 0
					}
					goto _3
				_3:
					;
					p = (*TSessionChange)(unsafe.Pointer(p)).FpNext
				}
				goto _2
			_2:
				;
				i = i + 1
			}
			Xsqlite3_finalize(tls, **(**uintptr)(__ccgo_up(bp + 24)))
			if (**(**TSessionBuffer)(__ccgo_up(bp))).FnBuf == nNoop {
				(**(**TSessionBuffer)(__ccgo_up(bp))).FnBuf = nRewind
			}
		}
		goto _1
	_1:
		;
		pTab = (*TSessionTable)(unsafe.Pointer(pTab)).FpNext
	}
	if **(**int32)(__ccgo_up(bp + 16)) == SQLITE_OK {
		if __ccgo_fp_xOutput == uintptr(0) {
			**(**int32)(__ccgo_up(pnChangeset)) = (**(**TSessionBuffer)(__ccgo_up(bp))).FnBuf
			**(**uintptr)(__ccgo_up(ppChangeset)) = (**(**TSessionBuffer)(__ccgo_up(bp))).FaBuf
			(**(**TSessionBuffer)(__ccgo_up(bp))).FaBuf = uintptr(0)
		} else {
			if (**(**TSessionBuffer)(__ccgo_up(bp))).FnBuf > 0 {
				**(**int32)(__ccgo_up(bp + 16)) = (*(*func(*libc.TLS, uintptr, uintptr, int32) int32)(unsafe.Pointer(&struct{ uintptr }{__ccgo_fp_xOutput})))(tls, pOut, (**(**TSessionBuffer)(__ccgo_up(bp))).FaBuf, (**(**TSessionBuffer)(__ccgo_up(bp))).FnBuf)
			}
		}
	}
	Xsqlite3_free(tls, (**(**TSessionBuffer)(__ccgo_up(bp))).FaBuf)
	Xsqlite3_exec(tls, db, __ccgo_ts+35864, uintptr(0), uintptr(0), uintptr(0))
	Xsqlite3_mutex_leave(tls, Xsqlite3_db_mutex(tls, db))
	return **(**int32)(__ccgo_up(bp + 16))
}

// C documentation
//
//	/*
//	** This function is called to initialize the SessionTable.nCol, azCol[]
//	** abPK[] and azDflt[] members of SessionTable object pTab. If these
//	** fields are already initialized, this function is a no-op.
//	**
//	** If an error occurs, an error code is stored in sqlite3_session.rc and
//	** non-zero returned. Or, if no error occurs but the table has no primary
//	** key, sqlite3_session.rc is left set to SQLITE_OK and non-zero returned to
//	** indicate that updates on this table should be ignored. SessionTable.abPK
//	** is set to NULL in this case.
//	*/
func _sessionInitTable(tls *libc.TLS, pSession uintptr, pTab uintptr, db uintptr, zDb uintptr) (r int32) {
	bp := tls.Alloc(16)
	defer tls.Free(16)
	var i, rc int32
	var v1 uintptr
	var _ /* abPK at bp+0 */ uintptr
	_, _, _ = i, rc, v1
	rc = SQLITE_OK
	if (*TSessionTable)(unsafe.Pointer(pTab)).FnCol == 0 {
		Xsqlite3_free(tls, (*TSessionTable)(unsafe.Pointer(pTab)).FazCol)
		(*TSessionTable)(unsafe.Pointer(pTab)).FabPK = uintptr(0)
		if pSession == uintptr(0) || (*Tsqlite3_session)(unsafe.Pointer(pSession)).FbImplicitPK != 0 {
			v1 = pTab + 28
		} else {
			v1 = uintptr(0)
		}
		rc = _sessionTableInfo(tls, pSession, db, zDb, (*TSessionTable)(unsafe.Pointer(pTab)).FzName, pTab+16, pTab+20, uintptr(0), pTab+32, pTab+40, pTab+48, bp, v1)
		if rc == SQLITE_OK {
			i = 0
			for {
				if !(i < (*TSessionTable)(unsafe.Pointer(pTab)).FnCol) {
					break
				}
				if **(**Tu8)(__ccgo_up(**(**uintptr)(__ccgo_up(bp)) + uintptr(i))) != 0 {
					(*TSessionTable)(unsafe.Pointer(pTab)).FabPK = **(**uintptr)(__ccgo_up(bp))
					break
				}
				goto _2
			_2:
				;
				i = i + 1
			}
			if 0 == Xsqlite3_stricmp(tls, __ccgo_ts+12826, (*TSessionTable)(unsafe.Pointer(pTab)).FzName) {
				(*TSessionTable)(unsafe.Pointer(pTab)).FbStat1 = int32(1)
			}
			if pSession != 0 && (*Tsqlite3_session)(unsafe.Pointer(pSession)).FbEnableSize != 0 {
				v1 = pSession + 64
				*(*Ti64)(unsafe.Pointer(v1)) = Ti64(uint64(*(*Ti64)(unsafe.Pointer(v1))) + uint64(libc.Uint64FromInt32(libc.Int32FromInt32(1)+_sessionVarintLen(tls, (*TSessionTable)(unsafe.Pointer(pTab)).FnCol)+(*TSessionTable)(unsafe.Pointer(pTab)).FnCol)+libc.Xstrlen(tls, (*TSessionTable)(unsafe.Pointer(pTab)).FzName)+libc.Uint64FromInt32(1)))
			}
		}
	}
	if pSession != 0 {
		(*Tsqlite3_session)(unsafe.Pointer(pSession)).Frc = rc
		return libc.BoolInt32(rc != 0 || (*TSessionTable)(unsafe.Pointer(pTab)).FabPK == uintptr(0))
	}
	return rc
}

// C documentation
//
//	/*
//	** Formulate and prepare an INSERT statement to add a record to table zTab.
//	** For example:
//	**
//	**     INSERT INTO main."zTab" VALUES(?1, ?2, ?3 ...);
//	**
//	** If successful, SQLITE_OK is returned and SessionApplyCtx.pInsert is left
//	** pointing to the prepared version of the SQL statement.
//	*/
func _sessionInsertRow(tls *libc.TLS, db uintptr, zTab uintptr, p uintptr) (r int32) {
	bp := tls.Alloc(32)
	defer tls.Free(32)
	var i int32
	var _ /* buf at bp+8 */ TSessionBuffer
	var _ /* rc at bp+0 */ int32
	_ = i
	**(**int32)(__ccgo_up(bp)) = SQLITE_OK
	**(**TSessionBuffer)(__ccgo_up(bp + 8)) = TSessionBuffer{}
	_sessionAppendStr(tls, bp+8, __ccgo_ts+36026, bp)
	_sessionAppendIdent(tls, bp+8, zTab, bp)
	_sessionAppendStr(tls, bp+8, __ccgo_ts+23624, bp)
	i = 0
	for {
		if !(i < (*TSessionApplyCtx)(unsafe.Pointer(p)).FnCol) {
			break
		}
		if i != 0 {
			_sessionAppendStr(tls, bp+8, __ccgo_ts+16207, bp)
		}
		_sessionAppendIdent(tls, bp+8, **(**uintptr)(__ccgo_up((*TSessionApplyCtx)(unsafe.Pointer(p)).FazCol + uintptr(i)*8)), bp)
		goto _1
	_1:
		;
		i = i + 1
	}
	_sessionAppendStr(tls, bp+8, __ccgo_ts+36044, bp)
	i = int32(1)
	for {
		if !(i < (*TSessionApplyCtx)(unsafe.Pointer(p)).FnCol) {
			break
		}
		_sessionAppendStr(tls, bp+8, __ccgo_ts+36055, bp)
		goto _2
	_2:
		;
		i = i + 1
	}
	_sessionAppendStr(tls, bp+8, __ccgo_ts+5250, bp)
	if **(**int32)(__ccgo_up(bp)) == SQLITE_OK {
		**(**int32)(__ccgo_up(bp)) = _sessionPrepare(tls, db, p+16, p+128, (**(**TSessionBuffer)(__ccgo_up(bp + 8))).FaBuf)
	}
	Xsqlite3_free(tls, (**(**TSessionBuffer)(__ccgo_up(bp + 8))).FaBuf)
	return **(**int32)(__ccgo_up(bp))
}

func _sessionPrepare(tls *libc.TLS, db uintptr, pp uintptr, pzErrmsg uintptr, zSql uintptr) (r int32) {
	bp := tls.Alloc(16)
	defer tls.Free(16)
	var rc int32
	_ = rc
	rc = Xsqlite3_prepare_v2(tls, db, zSql, -int32(1), pp, uintptr(0))
	if pzErrmsg != 0 && rc != SQLITE_OK {
		**(**uintptr)(__ccgo_up(pzErrmsg)) = Xsqlite3_mprintf(tls, __ccgo_ts+3933, libc.VaList(bp+8, Xsqlite3_errmsg(tls, db)))
	}
	return rc
}

// C documentation
//
//	/*
//	** Prepare a statement against database handle db that SELECTs a single
//	** row containing the default values for each column in table pTab. For
//	** example, if pTab is declared as:
//	**
//	**   CREATE TABLE pTab(a PRIMARY KEY, b DEFAULT 123, c DEFAULT 'abcd');
//	**
//	** Then this function prepares and returns the SQL statement:
//	**
//	**   SELECT NULL, 123, 'abcd';
//	*/
func _sessionPrepareDfltStmt(tls *libc.TLS, db uintptr, pTab uintptr, ppStmt uintptr) (r int32) {
	bp := tls.Alloc(48)
	defer tls.Free(48)
	var ii int32
	var zDflt, zSep, v2 uintptr
	var _ /* rc at bp+16 */ int32
	var _ /* sql at bp+0 */ TSessionBuffer
	_, _, _, _ = ii, zDflt, zSep, v2
	**(**TSessionBuffer)(__ccgo_up(bp)) = TSessionBuffer{}
	**(**int32)(__ccgo_up(bp + 16)) = SQLITE_OK
	zSep = __ccgo_ts + 11534
	ii = 0
	**(**uintptr)(__ccgo_up(ppStmt)) = uintptr(0)
	_sessionAppendPrintf(tls, bp, bp+16, __ccgo_ts+35343, 0)
	ii = 0
	for {
		if !(ii < (*TSessionTable)(unsafe.Pointer(pTab)).FnCol) {
			break
		}
		if **(**uintptr)(__ccgo_up((*TSessionTable)(unsafe.Pointer(pTab)).FazDflt + uintptr(ii)*8)) != 0 {
			v2 = **(**uintptr)(__ccgo_up((*TSessionTable)(unsafe.Pointer(pTab)).FazDflt + uintptr(ii)*8))
		} else {
			v2 = __ccgo_ts + 1694
		}
		zDflt = v2
		_sessionAppendPrintf(tls, bp, bp+16, __ccgo_ts+5220, libc.VaList(bp+32, zSep, zDflt))
		zSep = __ccgo_ts + 16207
		goto _1
	_1:
		;
		ii = ii + 1
	}
	if **(**int32)(__ccgo_up(bp + 16)) == SQLITE_OK {
		**(**int32)(__ccgo_up(bp + 16)) = Xsqlite3_prepare_v2(tls, db, (**(**TSessionBuffer)(__ccgo_up(bp))).FaBuf, -int32(1), ppStmt, uintptr(0))
	}
	Xsqlite3_free(tls, (**(**TSessionBuffer)(__ccgo_up(bp))).FaBuf)
	return **(**int32)(__ccgo_up(bp + 16))
}

// C documentation
//
//	/*
//	** This function is only called from with a pre-update-hook reporting a
//	** change on table pTab (attached to session pSession). The type of change
//	** (UPDATE, INSERT, DELETE) is specified by the first argument.
//	**
//	** Unless one is already present or an error occurs, an entry is added
//	** to the changed-rows hash table associated with table pTab.
//	*/
func _sessionPreupdateOneChange(tls *libc.TLS, op int32, iRowid Ti64, pSession uintptr, pTab uintptr) {
	bp := tls.Alloc(80)
	defer tls.Free(80)
	var i, iIdx, iIdx1, nExpect, rc int32
	var p, pC uintptr
	var _ /* bNull at bp+4 */ int32
	var _ /* iHash at bp+0 */ int32
	var _ /* nByte at bp+56 */ Tsqlite3_int64
	var _ /* p at bp+64 */ uintptr
	var _ /* p at bp+72 */ uintptr
	var _ /* stat1 at bp+8 */ TSessionStat1Ctx
	_, _, _, _, _, _, _ = i, iIdx, iIdx1, nExpect, p, pC, rc
	**(**int32)(__ccgo_up(bp + 4)) = 0
	rc = SQLITE_OK
	nExpect = 0
	**(**TSessionStat1Ctx)(__ccgo_up(bp + 8)) = TSessionStat1Ctx{}
	if (*Tsqlite3_session)(unsafe.Pointer(pSession)).Frc != 0 {
		return
	}
	/* Load table details if required */
	if _sessionInitTable(tls, pSession, pTab, (*Tsqlite3_session)(unsafe.Pointer(pSession)).Fdb, (*Tsqlite3_session)(unsafe.Pointer(pSession)).FzDb) != 0 {
		return
	}
	/* Check the number of columns in this xPreUpdate call matches the
	 ** number of columns in the table.  */
	nExpect = (*(*func(*libc.TLS, uintptr) int32)(unsafe.Pointer(&struct{ uintptr }{(*Tsqlite3_session)(unsafe.Pointer(pSession)).Fhook.FxCount})))(tls, (*Tsqlite3_session)(unsafe.Pointer(pSession)).Fhook.FpCtx)
	if (*TSessionTable)(unsafe.Pointer(pTab)).FnTotalCol < nExpect {
		if _sessionReinitTable(tls, pSession, pTab) != 0 {
			return
		}
		if _sessionUpdateChanges(tls, pSession, pTab) != 0 {
			return
		}
	}
	if (*TSessionTable)(unsafe.Pointer(pTab)).FnTotalCol != nExpect {
		(*Tsqlite3_session)(unsafe.Pointer(pSession)).Frc = int32(SQLITE_SCHEMA)
		return
	}
	/* Grow the hash table if required */
	if _sessionGrowHash(tls, pSession, 0, pTab) != 0 {
		(*Tsqlite3_session)(unsafe.Pointer(pSession)).Frc = int32(SQLITE_NOMEM)
		return
	}
	if (*TSessionTable)(unsafe.Pointer(pTab)).FbStat1 != 0 {
		(**(**TSessionStat1Ctx)(__ccgo_up(bp + 8))).Fhook = (*Tsqlite3_session)(unsafe.Pointer(pSession)).Fhook
		(**(**TSessionStat1Ctx)(__ccgo_up(bp + 8))).FpSession = pSession
		(*Tsqlite3_session)(unsafe.Pointer(pSession)).Fhook.FpCtx = bp + 8
		(*Tsqlite3_session)(unsafe.Pointer(pSession)).Fhook.FxNew = __ccgo_fp(_sessionStat1New)
		(*Tsqlite3_session)(unsafe.Pointer(pSession)).Fhook.FxOld = __ccgo_fp(_sessionStat1Old)
		(*Tsqlite3_session)(unsafe.Pointer(pSession)).Fhook.FxCount = __ccgo_fp(_sessionStat1Count)
		(*Tsqlite3_session)(unsafe.Pointer(pSession)).Fhook.FxDepth = __ccgo_fp(_sessionStat1Depth)
		if (*Tsqlite3_session)(unsafe.Pointer(pSession)).FpZeroBlob == uintptr(0) {
			p = _sqlite3ValueNew(tls, uintptr(0))
			if p == uintptr(0) {
				rc = int32(SQLITE_NOMEM)
				goto error_out
			}
			_sqlite3ValueSetStr(tls, p, 0, __ccgo_ts+1693, uint8(0), libc.UintptrFromInt32(0))
			(*Tsqlite3_session)(unsafe.Pointer(pSession)).FpZeroBlob = p
		}
	}
	/* Calculate the hash-key for this change. If the primary key of the row
	 ** includes a NULL value, exit early. Such changes are ignored by the
	 ** session module. */
	rc = _sessionPreupdateHash(tls, pSession, iRowid, pTab, libc.BoolInt32(op == int32(SQLITE_INSERT)), bp, bp+4)
	if rc != SQLITE_OK {
		goto error_out
	}
	if **(**int32)(__ccgo_up(bp + 4)) == 0 {
		pC = **(**uintptr)(__ccgo_up((*TSessionTable)(unsafe.Pointer(pTab)).FapChange + uintptr(**(**int32)(__ccgo_up(bp)))*8))
		for {
			if !(pC != 0) {
				break
			}
			if _sessionPreupdateEqual(tls, pSession, iRowid, pTab, pC, op) != 0 {
				break
			}
			goto _1
		_1:
			;
			pC = (*TSessionChange)(unsafe.Pointer(pC)).FpNext
		}
		if pC == uintptr(0) { /* Used to iterate through columns */
			(*TSessionTable)(unsafe.Pointer(pTab)).FnEntry = (*TSessionTable)(unsafe.Pointer(pTab)).FnEntry + 1
			/* Figure out how large an allocation is required */
			**(**Tsqlite3_int64)(__ccgo_up(bp + 56)) = int64(32)
			i = (*TSessionTable)(unsafe.Pointer(pTab)).FbRowid
			for {
				if !(i < (*TSessionTable)(unsafe.Pointer(pTab)).FnCol) {
					break
				}
				iIdx = **(**int32)(__ccgo_up((*TSessionTable)(unsafe.Pointer(pTab)).FaiIdx + uintptr(i)*4))
				**(**uintptr)(__ccgo_up(bp + 64)) = uintptr(0)
				if op != int32(SQLITE_INSERT) {
					/* This may fail if the column has a non-NULL default and was added
					 ** using ALTER TABLE ADD COLUMN after this record was created. */
					rc = (*(*func(*libc.TLS, uintptr, int32, uintptr) int32)(unsafe.Pointer(&struct{ uintptr }{(*Tsqlite3_session)(unsafe.Pointer(pSession)).Fhook.FxOld})))(tls, (*Tsqlite3_session)(unsafe.Pointer(pSession)).Fhook.FpCtx, iIdx, bp+64)
				} else {
					if **(**Tu8)(__ccgo_up((*TSessionTable)(unsafe.Pointer(pTab)).FabPK + uintptr(i))) != 0 {
						(*(*func(*libc.TLS, uintptr, int32, uintptr) int32)(unsafe.Pointer(&struct{ uintptr }{(*Tsqlite3_session)(unsafe.Pointer(pSession)).Fhook.FxNew})))(tls, (*Tsqlite3_session)(unsafe.Pointer(pSession)).Fhook.FpCtx, iIdx, bp+64)
					}
				}
				if rc == SQLITE_OK {
					/* This may fail if SQLite value p contains a utf-16 string that must
					 ** be converted to utf-8 and an OOM error occurs while doing so. */
					rc = _sessionSerializeValue(tls, uintptr(0), **(**uintptr)(__ccgo_up(bp + 64)), bp+56)
				}
				if rc != SQLITE_OK {
					goto error_out
				}
				goto _2
			_2:
				;
				i = i + 1
			}
			if (*TSessionTable)(unsafe.Pointer(pTab)).FbRowid != 0 {
				**(**Tsqlite3_int64)(__ccgo_up(bp + 56)) = **(**Tsqlite3_int64)(__ccgo_up(bp + 56)) + int64(9) /* Size of rowid field - an integer */
			}
			/* Allocate the change object */
			pC = _sessionMalloc64(tls, pSession, **(**Tsqlite3_int64)(__ccgo_up(bp + 56)))
			if !(pC != 0) {
				rc = int32(SQLITE_NOMEM)
				goto error_out
			} else {
				libc.Xmemset(tls, pC, 0, uint64(32))
				(*TSessionChange)(unsafe.Pointer(pC)).FaRecord = pC + 1*32
			}
			/* Populate the change object. None of the preupdate_old(),
			 ** preupdate_new() or SerializeValue() calls below may fail as all
			 ** required values and encodings have already been cached in memory.
			 ** It is not possible for an OOM to occur in this block. */
			**(**Tsqlite3_int64)(__ccgo_up(bp + 56)) = 0
			if (*TSessionTable)(unsafe.Pointer(pTab)).FbRowid != 0 {
				**(**Tu8)(__ccgo_up((*TSessionChange)(unsafe.Pointer(pC)).FaRecord)) = uint8(SQLITE_INTEGER)
				_sessionPutI64(tls, (*TSessionChange)(unsafe.Pointer(pC)).FaRecord+1, iRowid)
				**(**Tsqlite3_int64)(__ccgo_up(bp + 56)) = int64(9)
			}
			i = (*TSessionTable)(unsafe.Pointer(pTab)).FbRowid
			for {
				if !(i < (*TSessionTable)(unsafe.Pointer(pTab)).FnCol) {
					break
				}
				**(**uintptr)(__ccgo_up(bp + 72)) = uintptr(0)
				iIdx1 = **(**int32)(__ccgo_up((*TSessionTable)(unsafe.Pointer(pTab)).FaiIdx + uintptr(i)*4))
				if op != int32(SQLITE_INSERT) {
					(*(*func(*libc.TLS, uintptr, int32, uintptr) int32)(unsafe.Pointer(&struct{ uintptr }{(*Tsqlite3_session)(unsafe.Pointer(pSession)).Fhook.FxOld})))(tls, (*Tsqlite3_session)(unsafe.Pointer(pSession)).Fhook.FpCtx, iIdx1, bp+72)
				} else {
					if **(**Tu8)(__ccgo_up((*TSessionTable)(unsafe.Pointer(pTab)).FabPK + uintptr(i))) != 0 {
						(*(*func(*libc.TLS, uintptr, int32, uintptr) int32)(unsafe.Pointer(&struct{ uintptr }{(*Tsqlite3_session)(unsafe.Pointer(pSession)).Fhook.FxNew})))(tls, (*Tsqlite3_session)(unsafe.Pointer(pSession)).Fhook.FpCtx, iIdx1, bp+72)
					}
				}
				_sessionSerializeValue(tls, (*TSessionChange)(unsafe.Pointer(pC)).FaRecord+uintptr(**(**Tsqlite3_int64)(__ccgo_up(bp + 56))), **(**uintptr)(__ccgo_up(bp + 72)), bp+56)
				goto _3
			_3:
				;
				i = i + 1
			}
			/* Add the change to the hash-table */
			if (*Tsqlite3_session)(unsafe.Pointer(pSession)).FbIndirect != 0 || (*(*func(*libc.TLS, uintptr) int32)(unsafe.Pointer(&struct{ uintptr }{(*Tsqlite3_session)(unsafe.Pointer(pSession)).Fhook.FxDepth})))(tls, (*Tsqlite3_session)(unsafe.Pointer(pSession)).Fhook.FpCtx) != 0 {
				(*TSessionChange)(unsafe.Pointer(pC)).FbIndirect = uint8(1)
			}
			(*TSessionChange)(unsafe.Pointer(pC)).FnRecordField = libc.Uint16FromInt32((*TSessionTable)(unsafe.Pointer(pTab)).FnCol)
			(*TSessionChange)(unsafe.Pointer(pC)).FnRecord = int32(**(**Tsqlite3_int64)(__ccgo_up(bp + 56)))
			(*TSessionChange)(unsafe.Pointer(pC)).Fop = libc.Uint8FromInt32(op)
			(*TSessionChange)(unsafe.Pointer(pC)).FpNext = **(**uintptr)(__ccgo_up((*TSessionTable)(unsafe.Pointer(pTab)).FapChange + uintptr(**(**int32)(__ccgo_up(bp)))*8))
			**(**uintptr)(__ccgo_up((*TSessionTable)(unsafe.Pointer(pTab)).FapChange + uintptr(**(**int32)(__ccgo_up(bp)))*8)) = pC
		} else {
			if (*TSessionChange)(unsafe.Pointer(pC)).FbIndirect != 0 {
				/* If the existing change is considered "indirect", but this current
				 ** change is "direct", mark the change object as direct. */
				if (*(*func(*libc.TLS, uintptr) int32)(unsafe.Pointer(&struct{ uintptr }{(*Tsqlite3_session)(unsafe.Pointer(pSession)).Fhook.FxDepth})))(tls, (*Tsqlite3_session)(unsafe.Pointer(pSession)).Fhook.FpCtx) == 0 && (*Tsqlite3_session)(unsafe.Pointer(pSession)).FbIndirect == 0 {
					(*TSessionChange)(unsafe.Pointer(pC)).FbIndirect = uint8(0)
				}
			}
		}
		if (*Tsqlite3_session)(unsafe.Pointer(pSession)).FbEnableSize != 0 {
			rc = _sessionUpdateMaxSize(tls, op, pSession, pTab, pC)
		}
	}
	/* If an error has occurred, mark the session object as failed. */
	goto error_out
error_out:
	;
	if (*TSessionTable)(unsafe.Pointer(pTab)).FbStat1 != 0 {
		(*Tsqlite3_session)(unsafe.Pointer(pSession)).Fhook = (**(**TSessionStat1Ctx)(__ccgo_up(bp + 8))).Fhook
	}
	if rc != SQLITE_OK {
		(*Tsqlite3_session)(unsafe.Pointer(pSession)).Frc = rc
	}
}

// C documentation
//
//	/*
//	** Retry the changes accumulated in the pApply->constraints buffer. The
//	** pApply->constraints buffer contains all changes to table zTab that
//	** could not be applied due to SQLITE_CONSTRAINT errors. This function
//	** attempts to apply them as follows:
//	**
//	**   1) It runs through the buffer and attempts to retry each change,
//	**      removing any that are successfully applied from the buffer. This
//	**      is repeated until no further progress can be made.
//	**
//	**   2) For each UPDATE change in the buffer, try the following in a
//	**      savepoint transaction:
//	**
//	**      a) DELETE the affected row,
//	**      b) Attempt step (1) with remaining changes,
//	**      c) Attempt to INSERT a row equivalent to the one that would be
//	**         created by applying this UPDATE change.
//	**
//	**      If the INSERT in (c) succeeds, the savepoint is committed and all
//	**      successfully applied changes are removed from the buffer. Step (2)
//	**      is then repeated.
//	**
//	**   3) Once step (2) has been attempted for each UPDATE in the change,
//	**      a final attempt is made to apply each remaining change. This time,
//	**      if an SQLITE_CONSTRAINT error is encountered, the conflict handler
//	**      is invoked and the user has to decide whether to omit the change
//	**      or rollback the entire _apply() operation.
//	*/
func _sessionRetryConstraints(tls *libc.TLS, db uintptr, bPatchset int32, zTab uintptr, pApply uintptr, __ccgo_fp_xConflict uintptr, pCtx uintptr) (r int32) {
	bp := tls.Alloc(80)
	defer tls.Free(80)
	var iSkip, iThis, iUpdate, rc int32
	var _ /* app at bp+48 */ TSessionBuffer
	var _ /* cons at bp+0 */ TSessionBuffer
	var _ /* cons at bp+16 */ TSessionBuffer
	var _ /* cons at bp+64 */ TSessionBuffer
	var _ /* pInsert at bp+40 */ uintptr
	var _ /* pUp at bp+32 */ uintptr
	_, _, _, _ = iSkip, iThis, iUpdate, rc
	rc = SQLITE_OK
	iUpdate = 0
	/* Step (1) */
	for (*TSessionApplyCtx)(unsafe.Pointer(pApply)).Fconstraints.FnBuf != 0 {
		**(**TSessionBuffer)(__ccgo_up(bp)) = (*TSessionApplyCtx)(unsafe.Pointer(pApply)).Fconstraints
		libc.Xmemset(tls, pApply+88, 0, uint64(16))
		rc = _sessionApplyRetryBuffer(tls, bp, -int32(1), db, bPatchset, zTab, pApply, __ccgo_fp_xConflict, pCtx)
		Xsqlite3_free(tls, (**(**TSessionBuffer)(__ccgo_up(bp))).FaBuf)
		if rc != SQLITE_OK {
			break
		}
		/* If no progress has been made this round, break out of the loop. */
		if (*TSessionApplyCtx)(unsafe.Pointer(pApply)).Fconstraints.FnBuf >= (**(**TSessionBuffer)(__ccgo_up(bp))).FnBuf {
			break
		}
	}
	/* Step (2) */
	for rc == SQLITE_OK && (*TSessionApplyCtx)(unsafe.Pointer(pApply)).Fconstraints.FnBuf != 0 && !((*TSessionApplyCtx)(unsafe.Pointer(pApply)).FbNoUpdateLoop != 0) {
		**(**TSessionBuffer)(__ccgo_up(bp + 16)) = TSessionBuffer{}
		**(**uintptr)(__ccgo_up(bp + 32)) = uintptr(0)
		**(**uintptr)(__ccgo_up(bp + 40)) = uintptr(0)
		iSkip = 0
		rc = _sessionRetryIterInit(tls, pApply+88, bPatchset, zTab, pApply, bp+32)
		if rc == SQLITE_OK {
			iThis = -int32(1)
			for int32(SQLITE_ROW) == Xsqlite3changeset_next(tls, **(**uintptr)(__ccgo_up(bp + 32))) {
				if (*Tsqlite3_changeset_iter)(unsafe.Pointer(**(**uintptr)(__ccgo_up(bp + 32)))).Fop == int32(SQLITE_UPDATE) {
					iThis = iThis + 1
				}
				if iThis == iUpdate {
					break
				}
				iSkip = iSkip + 1
			}
			if iThis == iUpdate {
				rc = Xsqlite3_exec(tls, db, __ccgo_ts+36446, uintptr(0), uintptr(0), uintptr(0))
				if rc == SQLITE_OK {
					rc = _sessionUpdateToDeleteInsert(tls, db, zTab, pApply, **(**uintptr)(__ccgo_up(bp + 32)), bp+40)
				}
			}
			Xsqlite3changeset_finalize(tls, **(**uintptr)(__ccgo_up(bp + 32)))
			if iThis != iUpdate {
				break
			}
		}
		if rc == SQLITE_OK {
			**(**TSessionBuffer)(__ccgo_up(bp + 16)) = (*TSessionApplyCtx)(unsafe.Pointer(pApply)).Fconstraints
			for rc == SQLITE_OK && (*TSessionApplyCtx)(unsafe.Pointer(pApply)).Fconstraints.FnBuf > 0 {
				**(**TSessionBuffer)(__ccgo_up(bp + 48)) = (*TSessionApplyCtx)(unsafe.Pointer(pApply)).Fconstraints
				libc.Xmemset(tls, pApply+88, 0, uint64(16))
				rc = _sessionApplyRetryBuffer(tls, bp+48, iSkip, db, bPatchset, zTab, pApply, __ccgo_fp_xConflict, pCtx)
				if (**(**TSessionBuffer)(__ccgo_up(bp + 48))).FaBuf != (**(**TSessionBuffer)(__ccgo_up(bp + 16))).FaBuf {
					Xsqlite3_free(tls, (**(**TSessionBuffer)(__ccgo_up(bp + 48))).FaBuf)
				}
				if (*TSessionApplyCtx)(unsafe.Pointer(pApply)).Fconstraints.FnBuf >= (**(**TSessionBuffer)(__ccgo_up(bp + 48))).FnBuf {
					break
				}
				iSkip = -int32(1)
			}
		}
		iUpdate = iUpdate + 1
		if rc == SQLITE_OK {
			Xsqlite3_step(tls, **(**uintptr)(__ccgo_up(bp + 40)))
			rc = Xsqlite3_finalize(tls, **(**uintptr)(__ccgo_up(bp + 40)))
			if rc == int32(SQLITE_CONSTRAINT) {
				rc = Xsqlite3_exec(tls, db, __ccgo_ts+36466, uintptr(0), uintptr(0), uintptr(0))
				Xsqlite3_free(tls, (*TSessionApplyCtx)(unsafe.Pointer(pApply)).Fconstraints.FaBuf)
				(*TSessionApplyCtx)(unsafe.Pointer(pApply)).Fconstraints = **(**TSessionBuffer)(__ccgo_up(bp + 16))
				libc.Xmemset(tls, bp+16, 0, uint64(16))
			} else {
				if rc == SQLITE_OK {
					iUpdate = 0
				}
			}
			if rc == SQLITE_OK {
				rc = Xsqlite3_exec(tls, db, __ccgo_ts+36488, uintptr(0), uintptr(0), uintptr(0))
			}
		} else {
			Xsqlite3_finalize(tls, **(**uintptr)(__ccgo_up(bp + 40)))
		}
		Xsqlite3_free(tls, (**(**TSessionBuffer)(__ccgo_up(bp + 16))).FaBuf)
	}
	/* Step (3) */
	if rc == SQLITE_OK && (*TSessionApplyCtx)(unsafe.Pointer(pApply)).Fconstraints.FnBuf != 0 {
		**(**TSessionBuffer)(__ccgo_up(bp + 64)) = (*TSessionApplyCtx)(unsafe.Pointer(pApply)).Fconstraints
		libc.Xmemset(tls, pApply+88, 0, uint64(16))
		(*TSessionApplyCtx)(unsafe.Pointer(pApply)).FbDeferConstraints = 0
		rc = _sessionApplyRetryBuffer(tls, bp+64, -int32(1), db, bPatchset, zTab, pApply, __ccgo_fp_xConflict, pCtx)
		Xsqlite3_free(tls, (**(**TSessionBuffer)(__ccgo_up(bp + 64))).FaBuf)
	}
	return rc
}

func _sessionSelectFindNew(tls *libc.TLS, zDb1 uintptr, zDb2 uintptr, bRowid int32, zTbl uintptr, zExpr uintptr) (r uintptr) {
	bp := tls.Alloc(64)
	defer tls.Free(64)
	var zRet, zSel, v1 uintptr
	_, _, _ = zRet, zSel, v1
	if bRowid != 0 {
		v1 = __ccgo_ts + 35430
	} else {
		v1 = __ccgo_ts + 6814
	}
	zSel = v1
	zRet = Xsqlite3_mprintf(tls, __ccgo_ts+35441, libc.VaList(bp+8, zSel, zDb1, zTbl, zDb2, zTbl, zExpr))
	return zRet
}

// C documentation
//
//	/*
//	** Formulate and prepare an SQL statement to query table zTab by primary
//	** key. Assuming the following table structure:
//	**
//	**     CREATE TABLE x(a, b, c, d, PRIMARY KEY(a, c));
//	**
//	** The SELECT statement looks like this:
//	**
//	**     SELECT * FROM x WHERE a = ?1 AND c = ?3
//	**
//	** If successful, SQLITE_OK is returned and SessionApplyCtx.pSelect is left
//	** pointing to the prepared version of the SQL statement.
//	*/
func _sessionSelectRow(tls *libc.TLS, db uintptr, zTab uintptr, p uintptr) (r int32) {
	/* TODO */
	return _sessionSelectStmt(tls, db, libc.Int32FromUint8((*TSessionApplyCtx)(unsafe.Pointer(p)).FbIgnoreNoop), __ccgo_ts+6809, zTab, (*TSessionApplyCtx)(unsafe.Pointer(p)).FbRowid, (*TSessionApplyCtx)(unsafe.Pointer(p)).FnCol, (*TSessionApplyCtx)(unsafe.Pointer(p)).FazCol, (*TSessionApplyCtx)(unsafe.Pointer(p)).FabPK, p+24, p+128)
}

// C documentation
//
//	/*
//	** Formulate and prepare a SELECT statement to retrieve a row from table
//	** zTab in database zDb based on its primary key. i.e.
//	**
//	**   SELECT *, <noop-test> FROM zDb.zTab WHERE (pk1, pk2,...) IS (?1, ?2,...)
//	**
//	** where <noop-test> is:
//	**
//	**   1 AND (?A OR ?1 IS <column>) AND ...
//	**
//	** for each non-pk <column>.
//	*/
func _sessionSelectStmt(tls *libc.TLS, db uintptr, bIgnoreNoop int32, zDb uintptr, zTab uintptr, bRowid int32, nCol int32, azCol uintptr, abPK uintptr, ppStmt uintptr, pzErrmsg uintptr) (r int32) {
	bp := tls.Alloc(128)
	defer tls.Free(128)
	var i int32
	var zSep, zSql, v2 uintptr
	var _ /* cols at bp+8 */ TSessionBuffer
	var _ /* nooptest at bp+24 */ TSessionBuffer
	var _ /* pkfield at bp+40 */ TSessionBuffer
	var _ /* pkvar at bp+56 */ TSessionBuffer
	var _ /* rc at bp+0 */ int32
	_, _, _, _ = i, zSep, zSql, v2
	**(**int32)(__ccgo_up(bp)) = SQLITE_OK
	zSql = uintptr(0)
	zSep = __ccgo_ts + 1693
	**(**TSessionBuffer)(__ccgo_up(bp + 8)) = TSessionBuffer{}
	**(**TSessionBuffer)(__ccgo_up(bp + 24)) = TSessionBuffer{}
	**(**TSessionBuffer)(__ccgo_up(bp + 40)) = TSessionBuffer{}
	**(**TSessionBuffer)(__ccgo_up(bp + 56)) = TSessionBuffer{}
	_sessionAppendStr(tls, bp+24, __ccgo_ts+35675, bp)
	if 0 == Xsqlite3_stricmp(tls, __ccgo_ts+12826, zTab) {
		_sessionAppendStr(tls, bp+24, __ccgo_ts+35679, bp)
		_sessionAppendStr(tls, bp+40, __ccgo_ts+35703, bp)
		_sessionAppendStr(tls, bp+56, __ccgo_ts+35712, bp)
		_sessionAppendStr(tls, bp+8, __ccgo_ts+35757, bp)
	} else {
		i = 0
		for {
			if !(i < nCol) {
				break
			}
			if (**(**TSessionBuffer)(__ccgo_up(bp + 8))).FnBuf != 0 {
				_sessionAppendStr(tls, bp+8, __ccgo_ts+16207, bp)
			}
			_sessionAppendIdent(tls, bp+8, **(**uintptr)(__ccgo_up(azCol + uintptr(i)*8)), bp)
			if **(**Tu8)(__ccgo_up(abPK + uintptr(i))) != 0 {
				_sessionAppendStr(tls, bp+40, zSep, bp)
				_sessionAppendStr(tls, bp+56, zSep, bp)
				zSep = __ccgo_ts + 16207
				_sessionAppendIdent(tls, bp+40, **(**uintptr)(__ccgo_up(azCol + uintptr(i)*8)), bp)
				_sessionAppendPrintf(tls, bp+56, bp, __ccgo_ts+35771, libc.VaList(bp+80, i+int32(1)))
			} else {
				_sessionAppendPrintf(tls, bp+24, bp, __ccgo_ts+35775, libc.VaList(bp+80, i+int32(1)+nCol, i+int32(1), zTab, **(**uintptr)(__ccgo_up(azCol + uintptr(i)*8))))
			}
			goto _1
		_1:
			;
			i = i + 1
		}
	}
	if **(**int32)(__ccgo_up(bp)) == SQLITE_OK {
		if bIgnoreNoop != 0 {
			v2 = (**(**TSessionBuffer)(__ccgo_up(bp + 24))).FaBuf
		} else {
			v2 = __ccgo_ts + 1693
		}
		zSql = Xsqlite3_mprintf(tls, __ccgo_ts+35802, libc.VaList(bp+80, (**(**TSessionBuffer)(__ccgo_up(bp + 8))).FaBuf, v2, zDb, zTab, (**(**TSessionBuffer)(__ccgo_up(bp + 40))).FaBuf, (**(**TSessionBuffer)(__ccgo_up(bp + 56))).FaBuf))
		if zSql == uintptr(0) {
			**(**int32)(__ccgo_up(bp)) = int32(SQLITE_NOMEM)
		}
	}
	if **(**int32)(__ccgo_up(bp)) == SQLITE_OK {
		**(**int32)(__ccgo_up(bp)) = _sessionPrepare(tls, db, ppStmt, pzErrmsg, zSql)
	}
	Xsqlite3_free(tls, zSql)
	Xsqlite3_free(tls, (**(**TSessionBuffer)(__ccgo_up(bp + 24))).FaBuf)
	Xsqlite3_free(tls, (**(**TSessionBuffer)(__ccgo_up(bp + 40))).FaBuf)
	Xsqlite3_free(tls, (**(**TSessionBuffer)(__ccgo_up(bp + 56))).FaBuf)
	Xsqlite3_free(tls, (**(**TSessionBuffer)(__ccgo_up(bp + 8))).FaBuf)
	return **(**int32)(__ccgo_up(bp))
}

// C documentation
//
//	/*
//	** Prepare statements for applying changes to the sqlite_stat1 table.
//	** These are similar to those created by sessionSelectRow(),
//	** sessionInsertRow(), sessionUpdateRow() and sessionDeleteRow() for
//	** other tables.
//	*/
func _sessionStat1Sql(tls *libc.TLS, db uintptr, p uintptr) (r int32) {
	var rc int32
	_ = rc
	rc = _sessionSelectRow(tls, db, __ccgo_ts+12826, p)
	if rc == SQLITE_OK {
		rc = _sessionPrepare(tls, db, p+16, uintptr(0), __ccgo_ts+36059)
	}
	if rc == SQLITE_OK {
		rc = _sessionPrepare(tls, db, p+8, uintptr(0), __ccgo_ts+36172)
	}
	return rc
}

// C documentation
//
//	/*
//	** This function queries the database for the names of the columns of table
//	** zThis, in schema zDb.
//	**
//	** Otherwise, if they are not NULL, variable *pnCol is set to the number
//	** of columns in the database table and variable *pzTab is set to point to a
//	** nul-terminated copy of the table name. *pazCol (if not NULL) is set to
//	** point to an array of pointers to column names. And *pabPK (again, if not
//	** NULL) is set to point to an array of booleans - true if the corresponding
//	** column is part of the primary key.
//	**
//	** For example, if the table is declared as:
//	**
//	**     CREATE TABLE tbl1(w, x DEFAULT 'abc', y, z, PRIMARY KEY(w, z));
//	**
//	** Then the five output variables are populated as follows:
//	**
//	**     *pnCol  = 4
//	**     *pzTab  = "tbl1"
//	**     *pazCol = {"w", "x", "y", "z"}
//	**     *pazDflt = {NULL, 'abc', NULL, NULL}
//	**     *pabPK  = {1, 0, 0, 1}
//	**
//	** All returned buffers are part of the same single allocation, which must
//	** be freed using sqlite3_free() by the caller
//	*/
func _sessionTableInfo(tls *libc.TLS, pSession uintptr, db uintptr, zDb uintptr, zThis uintptr, pnCol uintptr, pnTotalCol uintptr, pzTab uintptr, pazCol uintptr, pazDflt uintptr, paiIdx uintptr, pabPK uintptr, pbRowid uintptr) (r int32) {
	bp := tls.Alloc(32)
	defer tls.Free(32)
	var abPK, aiIdx, azCol, azDflt, pAlloc, zDflt, zName, zPragma uintptr
	var bRowid, i, nDbCol, nDflt, nName1, nThis, rc int32
	var nByte Tsqlite3_int64
	var nName Tsize_t
	var _ /* pStmt at bp+0 */ uintptr
	_, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _ = abPK, aiIdx, azCol, azDflt, bRowid, i, nByte, nDbCol, nDflt, nName, nName1, nThis, pAlloc, rc, zDflt, zName, zPragma
	nDbCol = 0
	pAlloc = uintptr(0)
	azCol = uintptr(0)
	azDflt = uintptr(0)
	abPK = uintptr(0)
	aiIdx = uintptr(0)
	bRowid = 0 /* Set to true to use rowid as PK */
	**(**uintptr)(__ccgo_up(pazCol)) = uintptr(0)
	**(**uintptr)(__ccgo_up(pabPK)) = uintptr(0)
	**(**int32)(__ccgo_up(pnCol)) = 0
	if pnTotalCol != 0 {
		**(**int32)(__ccgo_up(pnTotalCol)) = 0
	}
	if paiIdx != 0 {
		**(**uintptr)(__ccgo_up(paiIdx)) = uintptr(0)
	}
	if pzTab != 0 {
		**(**uintptr)(__ccgo_up(pzTab)) = uintptr(0)
	}
	if pazDflt != 0 {
		**(**uintptr)(__ccgo_up(pazDflt)) = uintptr(0)
	}
	nThis = _sqlite3Strlen30(tls, zThis)
	if nThis == int32(12) && 0 == Xsqlite3_stricmp(tls, __ccgo_ts+12826, zThis) {
		rc = Xsqlite3_table_column_metadata(tls, db, zDb, zThis, uintptr(0), uintptr(0), uintptr(0), uintptr(0), uintptr(0), uintptr(0))
		if rc == SQLITE_OK {
			/* For sqlite_stat1, pretend that (tbl,idx) is the PRIMARY KEY. */
			zPragma = Xsqlite3_mprintf(tls, __ccgo_ts+35183, 0)
		} else {
			if rc == int32(SQLITE_ERROR) {
				zPragma = Xsqlite3_mprintf(tls, __ccgo_ts+1693, 0)
			} else {
				return rc
			}
		}
	} else {
		zPragma = Xsqlite3_mprintf(tls, __ccgo_ts+35313, libc.VaList(bp+16, zDb, zThis))
	}
	if !(zPragma != 0) {
		return int32(SQLITE_NOMEM)
	}
	rc = Xsqlite3_prepare_v2(tls, db, zPragma, -int32(1), bp, uintptr(0))
	Xsqlite3_free(tls, zPragma)
	if rc != SQLITE_OK {
		return rc
	}
	nByte = int64(nThis + int32(1))
	bRowid = libc.BoolInt32(pbRowid != uintptr(0))
	for int32(SQLITE_ROW) == Xsqlite3_step(tls, **(**uintptr)(__ccgo_up(bp))) {
		nByte = nByte + int64(Xsqlite3_column_bytes(tls, **(**uintptr)(__ccgo_up(bp)), int32(1))) /* name */
		nByte = nByte + int64(Xsqlite3_column_bytes(tls, **(**uintptr)(__ccgo_up(bp)), int32(4))) /* dflt_value */
		if Xsqlite3_column_int(tls, **(**uintptr)(__ccgo_up(bp)), int32(6)) == 0 {                /* !hidden */
			nDbCol = nDbCol + 1
		}
		if Xsqlite3_column_int(tls, **(**uintptr)(__ccgo_up(bp)), int32(5)) != 0 {
			bRowid = 0
		} /* pk */
	}
	if nDbCol == 0 {
		bRowid = 0
	}
	nDbCol = nDbCol + bRowid
	nByte = libc.Int64FromUint64(uint64(nByte) + uint64(libc.Xstrlen(tls, __ccgo_ts+31331)))
	rc = Xsqlite3_reset(tls, **(**uintptr)(__ccgo_up(bp)))
	if rc == SQLITE_OK {
		nByte = libc.Int64FromUint64(uint64(nByte) + uint64(libc.Uint64FromInt32(nDbCol)*(libc.Uint64FromInt64(8)*libc.Uint64FromInt32(2)+libc.Uint64FromInt64(4)+libc.Uint64FromInt64(1)+libc.Uint64FromInt32(1)+libc.Uint64FromInt32(1))))
		pAlloc = _sessionMalloc64(tls, pSession, nByte)
		if pAlloc == uintptr(0) {
			rc = int32(SQLITE_NOMEM)
		} else {
			libc.Xmemset(tls, pAlloc, 0, libc.Uint64FromInt64(nByte))
		}
	}
	if rc == SQLITE_OK {
		azCol = pAlloc
		azDflt = azCol + uintptr(nDbCol)*8
		aiIdx = azDflt + uintptr(nDbCol)*8
		abPK = aiIdx + uintptr(nDbCol)*4
		pAlloc = abPK + uintptr(nDbCol)
		if pzTab != 0 {
			libc.Xmemcpy(tls, pAlloc, zThis, libc.Uint64FromInt32(nThis+int32(1)))
			**(**uintptr)(__ccgo_up(pzTab)) = pAlloc
			pAlloc = pAlloc + uintptr(nThis+int32(1))
		}
		i = 0
		if bRowid != 0 {
			nName = libc.Xstrlen(tls, __ccgo_ts+31331)
			libc.Xmemcpy(tls, pAlloc, __ccgo_ts+31331, nName+uint64(1))
			**(**uintptr)(__ccgo_up(azCol + uintptr(i)*8)) = pAlloc
			pAlloc = pAlloc + uintptr(nName+uint64(1))
			**(**Tu8)(__ccgo_up(abPK + uintptr(i))) = uint8(1)
			**(**int32)(__ccgo_up(aiIdx + uintptr(i)*4)) = -int32(1)
			i = i + 1
		}
		for int32(SQLITE_ROW) == Xsqlite3_step(tls, **(**uintptr)(__ccgo_up(bp))) {
			if Xsqlite3_column_int(tls, **(**uintptr)(__ccgo_up(bp)), int32(6)) == 0 { /* !hidden */
				nName1 = Xsqlite3_column_bytes(tls, **(**uintptr)(__ccgo_up(bp)), int32(1))
				nDflt = Xsqlite3_column_bytes(tls, **(**uintptr)(__ccgo_up(bp)), int32(4))
				zName = Xsqlite3_column_text(tls, **(**uintptr)(__ccgo_up(bp)), int32(1))
				zDflt = Xsqlite3_column_text(tls, **(**uintptr)(__ccgo_up(bp)), int32(4))
				if zName == uintptr(0) {
					break
				}
				libc.Xmemcpy(tls, pAlloc, zName, libc.Uint64FromInt32(nName1+int32(1)))
				**(**uintptr)(__ccgo_up(azCol + uintptr(i)*8)) = pAlloc
				pAlloc = pAlloc + uintptr(nName1+int32(1))
				if zDflt != 0 {
					libc.Xmemcpy(tls, pAlloc, zDflt, libc.Uint64FromInt32(nDflt+int32(1)))
					**(**uintptr)(__ccgo_up(azDflt + uintptr(i)*8)) = pAlloc
					pAlloc = pAlloc + uintptr(nDflt+int32(1))
				} else {
					**(**uintptr)(__ccgo_up(azDflt + uintptr(i)*8)) = uintptr(0)
				}
				**(**Tu8)(__ccgo_up(abPK + uintptr(i))) = libc.Uint8FromInt32(Xsqlite3_column_int(tls, **(**uintptr)(__ccgo_up(bp)), int32(5)))
				**(**int32)(__ccgo_up(aiIdx + uintptr(i)*4)) = Xsqlite3_column_int(tls, **(**uintptr)(__ccgo_up(bp)), 0)
				i = i + 1
			}
			if pnTotalCol != 0 {
				**(**int32)(__ccgo_up(pnTotalCol)) = **(**int32)(__ccgo_up(pnTotalCol)) + 1
			}
		}
		rc = Xsqlite3_reset(tls, **(**uintptr)(__ccgo_up(bp)))
	}
	/* If successful, populate the output variables. Otherwise, zero them and
	 ** free any allocation made. An error code will be returned in this case.
	 */
	if rc == SQLITE_OK {
		**(**uintptr)(__ccgo_up(pazCol)) = azCol
		if pazDflt != 0 {
			**(**uintptr)(__ccgo_up(pazDflt)) = azDflt
		}
		**(**uintptr)(__ccgo_up(pabPK)) = abPK
		**(**int32)(__ccgo_up(pnCol)) = nDbCol
		if paiIdx != 0 {
			**(**uintptr)(__ccgo_up(paiIdx)) = aiIdx
		}
	} else {
		_sessionFree(tls, pSession, azCol)
	}
	if pbRowid != 0 {
		**(**int32)(__ccgo_up(pbRowid)) = bRowid
	}
	Xsqlite3_finalize(tls, **(**uintptr)(__ccgo_up(bp)))
	return rc
}

// C documentation
//
//	/*
//	** Check if table zTab in the "main" database of db is a WITHOUT ROWID
//	** table.
//	**
//	** If no error occurs, return SQLITE_OK and set output variable (*pbWR) to
//	** true if zTab is a WITHOUT ROWID table, or false otherwise. Or, if an
//	** error does occur, return an SQLite error code. The final value of (*pbWR)
//	** is undefined in this case.
//	*/
func _sessionTableIsWithoutRowid(tls *libc.TLS, db uintptr, zTab uintptr, pbWR uintptr) (r int32) {
	bp := tls.Alloc(32)
	defer tls.Free(32)
	var rc int32
	var zSql uintptr
	var _ /* pList at bp+0 */ uintptr
	_, _ = rc, zSql
	**(**uintptr)(__ccgo_up(bp)) = uintptr(0)
	zSql = uintptr(0)
	rc = SQLITE_OK
	zSql = Xsqlite3_mprintf(tls, __ccgo_ts+36356, libc.VaList(bp+16, zTab))
	if zSql == uintptr(0) {
		rc = int32(SQLITE_NOMEM)
	} else {
		rc = Xsqlite3_prepare_v2(tls, db, zSql, -int32(1), bp, uintptr(0))
		Xsqlite3_free(tls, zSql)
	}
	if rc == SQLITE_OK {
		Xsqlite3_step(tls, **(**uintptr)(__ccgo_up(bp)))
		**(**int32)(__ccgo_up(pbWR)) = Xsqlite3_column_int(tls, **(**uintptr)(__ccgo_up(bp)), int32(4))
		rc = Xsqlite3_finalize(tls, **(**uintptr)(__ccgo_up(bp)))
	}
	return rc
}

// C documentation
//
//	/*
//	** Find a prepared UPDATE statement suitable for the UPDATE step currently
//	** being visited by the iterator. The UPDATE is of the form:
//	**
//	**   UPDATE tbl SET col = ?, col2 = ? WHERE pk1 IS ? AND pk2 IS ?
//	*/
func _sessionUpdateFind(tls *libc.TLS, pIter uintptr, p uintptr, bPatchset int32, ppStmt uintptr) (r int32) {
	bp := tls.Alloc(32)
	defer tls.Free(32)
	var bStat1, ii, nByte, nCol, nU32, nUp int32
	var pUp, pp, zSep, zSql uintptr
	var _ /* buf at bp+8 */ TSessionBuffer
	var _ /* rc at bp+0 */ int32
	_, _, _, _, _, _, _, _, _, _ = bStat1, ii, nByte, nCol, nU32, nUp, pUp, pp, zSep, zSql
	**(**int32)(__ccgo_up(bp)) = SQLITE_OK
	pUp = uintptr(0)
	nCol = (*Tsqlite3_changeset_iter)(unsafe.Pointer(pIter)).FnCol
	nU32 = ((*Tsqlite3_changeset_iter)(unsafe.Pointer(pIter)).FnCol + int32(33)) / int32(32)
	if (*TSessionApplyCtx)(unsafe.Pointer(p)).FaUpdateMask == uintptr(0) {
		(*TSessionApplyCtx)(unsafe.Pointer(p)).FaUpdateMask = Xsqlite3_malloc(tls, libc.Int32FromUint64(libc.Uint64FromInt32(nU32)*uint64(4)))
		if (*TSessionApplyCtx)(unsafe.Pointer(p)).FaUpdateMask == uintptr(0) {
			**(**int32)(__ccgo_up(bp)) = int32(SQLITE_NOMEM)
		}
	}
	if **(**int32)(__ccgo_up(bp)) == SQLITE_OK {
		libc.Xmemset(tls, (*TSessionApplyCtx)(unsafe.Pointer(p)).FaUpdateMask, 0, libc.Uint64FromInt32(nU32)*uint64(4))
		**(**int32)(__ccgo_up(bp)) = int32(SQLITE_CORRUPT)
		ii = 0
		for {
			if !(ii < (*Tsqlite3_changeset_iter)(unsafe.Pointer(pIter)).FnCol) {
				break
			}
			if **(**uintptr)(__ccgo_up((*Tsqlite3_changeset_iter)(unsafe.Pointer(pIter)).FapValue + uintptr((*Tsqlite3_changeset_iter)(unsafe.Pointer(pIter)).FnCol+ii)*8)) != 0 {
				**(**Tu32)(__ccgo_up((*TSessionApplyCtx)(unsafe.Pointer(p)).FaUpdateMask + uintptr(ii/int32(32))*4)) |= libc.Uint32FromInt32(libc.Int32FromInt32(1) << (ii % libc.Int32FromInt32(32)))
				**(**int32)(__ccgo_up(bp)) = SQLITE_OK
			}
			goto _1
		_1:
			;
			ii = ii + 1
		}
	}
	if **(**int32)(__ccgo_up(bp)) == SQLITE_OK {
		if bPatchset != 0 {
			**(**Tu32)(__ccgo_up((*TSessionApplyCtx)(unsafe.Pointer(p)).FaUpdateMask + uintptr(nCol/int32(32))*4)) |= libc.Uint32FromInt32(libc.Int32FromInt32(1) << (nCol % libc.Int32FromInt32(32)))
		}
		if (*TSessionApplyCtx)(unsafe.Pointer(p)).FpUp != 0 {
			nUp = 0
			pp = p + 64
			for int32(1) != 0 {
				nUp = nUp + 1
				if 0 == libc.Xmemcmp(tls, (*TSessionApplyCtx)(unsafe.Pointer(p)).FaUpdateMask, (*TSessionUpdate)(unsafe.Pointer(**(**uintptr)(__ccgo_up(pp)))).FaMask, libc.Uint64FromInt32(nU32)*uint64(4)) {
					pUp = **(**uintptr)(__ccgo_up(pp))
					**(**uintptr)(__ccgo_up(pp)) = (*TSessionUpdate)(unsafe.Pointer(pUp)).FpNext
					(*TSessionUpdate)(unsafe.Pointer(pUp)).FpNext = (*TSessionApplyCtx)(unsafe.Pointer(p)).FpUp
					(*TSessionApplyCtx)(unsafe.Pointer(p)).FpUp = pUp
					break
				}
				if (*TSessionUpdate)(unsafe.Pointer(**(**uintptr)(__ccgo_up(pp)))).FpNext != 0 {
					pp = **(**uintptr)(__ccgo_up(pp)) + 16
				} else {
					if nUp >= int32(SESSION_UPDATE_CACHE_SZ) {
						Xsqlite3_finalize(tls, (*TSessionUpdate)(unsafe.Pointer(**(**uintptr)(__ccgo_up(pp)))).FpStmt)
						Xsqlite3_free(tls, **(**uintptr)(__ccgo_up(pp)))
						**(**uintptr)(__ccgo_up(pp)) = uintptr(0)
					}
					break
				}
			}
		}
		if pUp == uintptr(0) {
			nByte = libc.Int32FromUint64(uint64(24) * libc.Uint64FromInt32(nU32) * uint64(4))
			bStat1 = libc.BoolInt32(Xsqlite3_stricmp(tls, (*Tsqlite3_changeset_iter)(unsafe.Pointer(pIter)).FzTab, __ccgo_ts+12826) == 0)
			pUp = Xsqlite3_malloc(tls, nByte)
			if pUp == uintptr(0) {
				**(**int32)(__ccgo_up(bp)) = int32(SQLITE_NOMEM)
			} else {
				zSep = __ccgo_ts + 1693
				libc.Xmemset(tls, bp+8, 0, uint64(16))
				(*TSessionUpdate)(unsafe.Pointer(pUp)).FaMask = pUp + 1*24
				libc.Xmemcpy(tls, (*TSessionUpdate)(unsafe.Pointer(pUp)).FaMask, (*TSessionApplyCtx)(unsafe.Pointer(p)).FaUpdateMask, libc.Uint64FromInt32(nU32)*uint64(4))
				_sessionAppendStr(tls, bp+8, __ccgo_ts+35882, bp)
				_sessionAppendIdent(tls, bp+8, (*Tsqlite3_changeset_iter)(unsafe.Pointer(pIter)).FzTab, bp)
				_sessionAppendStr(tls, bp+8, __ccgo_ts+35895, bp)
				/* Create the assignments part of the UPDATE */
				ii = 0
				for {
					if !(ii < (*Tsqlite3_changeset_iter)(unsafe.Pointer(pIter)).FnCol) {
						break
					}
					if libc.Int32FromUint8(**(**Tu8)(__ccgo_up((*TSessionApplyCtx)(unsafe.Pointer(p)).FabPK + uintptr(ii)))) == 0 && **(**uintptr)(__ccgo_up((*Tsqlite3_changeset_iter)(unsafe.Pointer(pIter)).FapValue + uintptr((*Tsqlite3_changeset_iter)(unsafe.Pointer(pIter)).FnCol+ii)*8)) != 0 {
						_sessionAppendStr(tls, bp+8, zSep, bp)
						_sessionAppendIdent(tls, bp+8, **(**uintptr)(__ccgo_up((*TSessionApplyCtx)(unsafe.Pointer(p)).FazCol + uintptr(ii)*8)), bp)
						_sessionAppendStr(tls, bp+8, __ccgo_ts+35901, bp)
						_sessionAppendInteger(tls, bp+8, ii*int32(2)+int32(1), bp)
						zSep = __ccgo_ts + 16207
					}
					goto _2
				_2:
					;
					ii = ii + 1
				}
				/* Create the WHERE clause part of the UPDATE */
				zSep = __ccgo_ts + 1693
				_sessionAppendStr(tls, bp+8, __ccgo_ts+35906, bp)
				ii = 0
				for {
					if !(ii < (*Tsqlite3_changeset_iter)(unsafe.Pointer(pIter)).FnCol) {
						break
					}
					if **(**Tu8)(__ccgo_up((*TSessionApplyCtx)(unsafe.Pointer(p)).FabPK + uintptr(ii))) != 0 || bPatchset == 0 && **(**uintptr)(__ccgo_up((*Tsqlite3_changeset_iter)(unsafe.Pointer(pIter)).FapValue + uintptr(ii)*8)) != 0 {
						_sessionAppendStr(tls, bp+8, zSep, bp)
						if bStat1 != 0 && ii == int32(1) {
							_sessionAppendStr(tls, bp+8, __ccgo_ts+35914, bp)
						} else {
							_sessionAppendIdent(tls, bp+8, **(**uintptr)(__ccgo_up((*TSessionApplyCtx)(unsafe.Pointer(p)).FazCol + uintptr(ii)*8)), bp)
							_sessionAppendStr(tls, bp+8, __ccgo_ts+35989, bp)
							_sessionAppendInteger(tls, bp+8, ii*int32(2)+int32(2), bp)
						}
						zSep = __ccgo_ts + 23618
					}
					goto _3
				_3:
					;
					ii = ii + 1
				}
				if **(**int32)(__ccgo_up(bp)) == SQLITE_OK {
					zSql = (**(**TSessionBuffer)(__ccgo_up(bp + 8))).FaBuf
					**(**int32)(__ccgo_up(bp)) = Xsqlite3_prepare_v2(tls, (*TSessionApplyCtx)(unsafe.Pointer(p)).Fdb, zSql, (**(**TSessionBuffer)(__ccgo_up(bp + 8))).FnBuf, pUp, uintptr(0))
				}
				if **(**int32)(__ccgo_up(bp)) != SQLITE_OK {
					Xsqlite3_free(tls, pUp)
					pUp = uintptr(0)
				} else {
					(*TSessionUpdate)(unsafe.Pointer(pUp)).FpNext = (*TSessionApplyCtx)(unsafe.Pointer(p)).FpUp
					(*TSessionApplyCtx)(unsafe.Pointer(p)).FpUp = pUp
				}
				Xsqlite3_free(tls, (**(**TSessionBuffer)(__ccgo_up(bp + 8))).FaBuf)
			}
		}
	}
	if pUp != 0 {
		**(**uintptr)(__ccgo_up(ppStmt)) = (*TSessionUpdate)(unsafe.Pointer(pUp)).FpStmt
	} else {
		**(**uintptr)(__ccgo_up(ppStmt)) = uintptr(0)
	}
	return **(**int32)(__ccgo_up(bp))
}

// C documentation
//
//	/*
//	** Iterator pUp points to an UPDATE change. This function deletes the
//	** affected row from the database and creates an INSERT statement that
//	** may be used to reinsert the row as it is after the UPDATE change
//	** has been applied.
//	**
//	** If successful, SQLITE_OK is returned and output variable (*ppInsert)
//	** is left pointing to a prepared INSERT statement. It is the responsibility
//	** of the caller to eventually free this statement using sqlite3_finalize().
//	** Or, if an error occurs, an SQLite error code is returned and (*ppInsert)
//	** set to NULL. pApply->zErr may be set to an error message in this case.
//	*/
func _sessionUpdateToDeleteInsert(tls *libc.TLS, db uintptr, zTab uintptr, pApply uintptr, pUp uintptr, ppInsert uintptr) (r int32) {
	bp := tls.Alloc(128)
	defer tls.Free(128)
	var iCol, ii int32
	var pVal, zComma, zComma2, zInsert, zSelect uintptr
	var _ /* bWR at bp+20 */ int32
	var _ /* cols at bp+24 */ TSessionBuffer
	var _ /* insbind at bp+40 */ TSessionBuffer
	var _ /* pRet at bp+0 */ uintptr
	var _ /* pSelect at bp+8 */ uintptr
	var _ /* pkcols at bp+56 */ TSessionBuffer
	var _ /* rc at bp+16 */ int32
	var _ /* selbind at bp+72 */ TSessionBuffer
	_, _, _, _, _, _, _ = iCol, ii, pVal, zComma, zComma2, zInsert, zSelect
	**(**uintptr)(__ccgo_up(bp)) = uintptr(0)     /* The INSERT statement */
	**(**uintptr)(__ccgo_up(bp + 8)) = uintptr(0) /* SELECT to read current values of row */
	**(**int32)(__ccgo_up(bp + 16)) = SQLITE_OK
	**(**int32)(__ccgo_up(bp + 20)) = 0
	**(**int32)(__ccgo_up(bp + 16)) = _sessionTableIsWithoutRowid(tls, db, zTab, bp+20)
	if **(**int32)(__ccgo_up(bp + 16)) == SQLITE_OK {
		zSelect = uintptr(0)
		zInsert = uintptr(0)
		**(**TSessionBuffer)(__ccgo_up(bp + 24)) = TSessionBuffer{}
		**(**TSessionBuffer)(__ccgo_up(bp + 40)) = TSessionBuffer{}
		**(**TSessionBuffer)(__ccgo_up(bp + 56)) = TSessionBuffer{}
		**(**TSessionBuffer)(__ccgo_up(bp + 72)) = TSessionBuffer{}
		zComma = __ccgo_ts + 1693
		zComma2 = __ccgo_ts + 1693
		ii = 0
		for {
			if !(ii < (*TSessionApplyCtx)(unsafe.Pointer(pApply)).FnCol) {
				break
			}
			_sessionAppendStr(tls, bp+24, zComma, bp+16)
			_sessionAppendIdent(tls, bp+24, **(**uintptr)(__ccgo_up((*TSessionApplyCtx)(unsafe.Pointer(pApply)).FazCol + uintptr(ii)*8)), bp+16)
			_sessionAppendStr(tls, bp+40, zComma, bp+16)
			_sessionAppendStr(tls, bp+40, __ccgo_ts+5252, bp+16)
			zComma = __ccgo_ts + 16207
			if **(**Tu8)(__ccgo_up((*TSessionApplyCtx)(unsafe.Pointer(pApply)).FabPK + uintptr(ii))) != 0 {
				_sessionAppendStr(tls, bp+56, zComma2, bp+16)
				_sessionAppendIdent(tls, bp+56, **(**uintptr)(__ccgo_up((*TSessionApplyCtx)(unsafe.Pointer(pApply)).FazCol + uintptr(ii)*8)), bp+16)
				_sessionAppendStr(tls, bp+72, zComma2, bp+16)
				_sessionAppendPrintf(tls, bp+72, bp+16, __ccgo_ts+35771, libc.VaList(bp+96, ii+int32(1)))
				zComma2 = __ccgo_ts + 16207
			}
			goto _1
		_1:
			;
			ii = ii + 1
		}
		if **(**int32)(__ccgo_up(bp + 20)) == 0 {
			_sessionAppendStr(tls, bp+24, zComma, bp+16)
			_sessionAppendStr(tls, bp+24, __ccgo_ts+31331, bp+16)
			_sessionAppendStr(tls, bp+40, zComma, bp+16)
			_sessionAppendStr(tls, bp+40, __ccgo_ts+5252, bp+16)
		}
		if **(**int32)(__ccgo_up(bp + 16)) == SQLITE_OK {
			zSelect = Xsqlite3_mprintf(tls, __ccgo_ts+36379, libc.VaList(bp+96, (**(**TSessionBuffer)(__ccgo_up(bp + 24))).FaBuf, zTab, (**(**TSessionBuffer)(__ccgo_up(bp + 56))).FaBuf, (**(**TSessionBuffer)(__ccgo_up(bp + 72))).FaBuf))
			if zSelect == uintptr(0) {
				**(**int32)(__ccgo_up(bp + 16)) = int32(SQLITE_NOMEM)
			}
		}
		if **(**int32)(__ccgo_up(bp + 16)) == SQLITE_OK {
			zInsert = Xsqlite3_mprintf(tls, __ccgo_ts+36416, libc.VaList(bp+96, zTab, (**(**TSessionBuffer)(__ccgo_up(bp + 24))).FaBuf, (**(**TSessionBuffer)(__ccgo_up(bp + 40))).FaBuf))
			if zInsert == uintptr(0) {
				**(**int32)(__ccgo_up(bp + 16)) = int32(SQLITE_NOMEM)
			}
		}
		if **(**int32)(__ccgo_up(bp + 16)) == SQLITE_OK {
			**(**int32)(__ccgo_up(bp + 16)) = _sessionPrepare(tls, db, bp+8, pApply+128, zSelect)
		}
		if **(**int32)(__ccgo_up(bp + 16)) == SQLITE_OK {
			**(**int32)(__ccgo_up(bp + 16)) = _sessionPrepare(tls, db, bp, pApply+128, zInsert)
		}
		Xsqlite3_free(tls, zSelect)
		Xsqlite3_free(tls, zInsert)
		Xsqlite3_free(tls, (**(**TSessionBuffer)(__ccgo_up(bp + 24))).FaBuf)
		Xsqlite3_free(tls, (**(**TSessionBuffer)(__ccgo_up(bp + 40))).FaBuf)
		Xsqlite3_free(tls, (**(**TSessionBuffer)(__ccgo_up(bp + 56))).FaBuf)
		Xsqlite3_free(tls, (**(**TSessionBuffer)(__ccgo_up(bp + 72))).FaBuf)
	}
	if **(**int32)(__ccgo_up(bp + 16)) == SQLITE_OK {
		**(**int32)(__ccgo_up(bp + 16)) = _sessionBindRow(tls, pUp, __ccgo_fp(Xsqlite3changeset_old), (*TSessionApplyCtx)(unsafe.Pointer(pApply)).FnCol, (*TSessionApplyCtx)(unsafe.Pointer(pApply)).FabPK, **(**uintptr)(__ccgo_up(bp + 8)))
	}
	if **(**int32)(__ccgo_up(bp + 16)) == SQLITE_OK && Xsqlite3_step(tls, **(**uintptr)(__ccgo_up(bp + 8))) == int32(SQLITE_ROW) {
		iCol = 0
		for {
			if !(iCol < (*TSessionApplyCtx)(unsafe.Pointer(pApply)).FnCol) {
				break
			}
			pVal = **(**uintptr)(__ccgo_up((*Tsqlite3_changeset_iter)(unsafe.Pointer(pUp)).FapValue + uintptr(iCol+(*TSessionApplyCtx)(unsafe.Pointer(pApply)).FnCol)*8))
			if pVal == uintptr(0) {
				pVal = Xsqlite3_column_value(tls, **(**uintptr)(__ccgo_up(bp + 8)), iCol)
			}
			**(**int32)(__ccgo_up(bp + 16)) = Xsqlite3_bind_value(tls, **(**uintptr)(__ccgo_up(bp)), iCol+int32(1), pVal)
			goto _2
		_2:
			;
			iCol = iCol + 1
		}
		if **(**int32)(__ccgo_up(bp + 20)) == 0 {
			Xsqlite3_bind_int64(tls, **(**uintptr)(__ccgo_up(bp)), iCol+int32(1), Xsqlite3_column_int64(tls, **(**uintptr)(__ccgo_up(bp + 8)), iCol))
		}
	}
	_sessionFinalizeStmt(tls, **(**uintptr)(__ccgo_up(bp + 8)), bp+16)
	/* Delete the row from the database. */
	if **(**int32)(__ccgo_up(bp + 16)) == SQLITE_OK {
		**(**int32)(__ccgo_up(bp + 16)) = _sessionBindRow(tls, pUp, __ccgo_fp(Xsqlite3changeset_old), (*TSessionApplyCtx)(unsafe.Pointer(pApply)).FnCol, (*TSessionApplyCtx)(unsafe.Pointer(pApply)).FabPK, (*TSessionApplyCtx)(unsafe.Pointer(pApply)).FpDelete)
		Xsqlite3_bind_int(tls, (*TSessionApplyCtx)(unsafe.Pointer(pApply)).FpDelete, (*TSessionApplyCtx)(unsafe.Pointer(pApply)).FnCol+int32(1), int32(1))
	}
	if **(**int32)(__ccgo_up(bp + 16)) == SQLITE_OK {
		Xsqlite3_step(tls, (*TSessionApplyCtx)(unsafe.Pointer(pApply)).FpDelete)
		**(**int32)(__ccgo_up(bp + 16)) = Xsqlite3_reset(tls, (*TSessionApplyCtx)(unsafe.Pointer(pApply)).FpDelete)
	}
	if **(**int32)(__ccgo_up(bp + 16)) != SQLITE_OK {
		Xsqlite3_finalize(tls, **(**uintptr)(__ccgo_up(bp)))
		**(**uintptr)(__ccgo_up(bp)) = uintptr(0)
	}
	**(**uintptr)(__ccgo_up(ppInsert)) = **(**uintptr)(__ccgo_up(bp))
	return **(**int32)(__ccgo_up(bp + 16))
}

// C documentation
//
//	/*
//	** The expression is the default value for the most recently added column
//	** of the table currently under construction.
//	**
//	** Default value expressions must be constant.  Raise an exception if this
//	** is not the case.
//	**
//	** This routine is called by the parser while in the middle of
//	** parsing a CREATE TABLE statement.
//	*/
func _sqlite3AddDefaultValue(tls *libc.TLS, pParse uintptr, pExpr uintptr, zStart uintptr, zEnd uintptr) {
	bp := tls.Alloc(96)
	defer tls.Free(96)
	var db, p, pCol, pDfltExpr uintptr
	var isInit int32
	var _ /* x at bp+0 */ TExpr
	_, _, _, _, _ = db, isInit, p, pCol, pDfltExpr
	db = (*TParse)(unsafe.Pointer(pParse)).Fdb
	p = (*TParse)(unsafe.Pointer(pParse)).FpNewTable
	if p != uintptr(0) {
		isInit = libc.BoolInt32((*Tsqlite3)(unsafe.Pointer(db)).Finit1.Fbusy != 0 && libc.Int32FromUint8((*Tsqlite3)(unsafe.Pointer(db)).Finit1.FiDb) != int32(1))
		pCol = (*TTable)(unsafe.Pointer(p)).FaCol + uintptr(int32((*TTable)(unsafe.Pointer(p)).FnCol)-int32(1))*16
		if !(_sqlite3ExprIsConstantOrFunction(tls, pExpr, libc.Uint8FromInt32(isInit)) != 0) {
			_sqlite3ErrorMsg(tls, pParse, __ccgo_ts+14015, libc.VaList(bp+80, (*TColumn)(unsafe.Pointer(pCol)).FzCnName))
		} else {
			if libc.Int32FromUint16((*TColumn)(unsafe.Pointer(pCol)).FcolFlags)&int32(COLFLAG_GENERATED) != 0 {
				_sqlite3ErrorMsg(tls, pParse, __ccgo_ts+14060, 0)
			} else {
				libc.Xmemset(tls, bp, 0, uint64(72))
				(**(**TExpr)(__ccgo_up(bp))).Fop = uint8(TK_SPAN)
				*(*uintptr)(unsafe.Pointer(bp + 8)) = _sqlite3DbSpanDup(tls, db, zStart, zEnd)
				(**(**TExpr)(__ccgo_up(bp))).FpLeft = pExpr
				(**(**TExpr)(__ccgo_up(bp))).Fflags = uint32(EP_Skip)
				pDfltExpr = _sqlite3ExprDup(tls, db, bp, int32(EXPRDUP_REDUCE))
				_sqlite3DbFree(tls, db, *(*uintptr)(unsafe.Pointer(bp + 8)))
				_sqlite3ColumnSetExpr(tls, pParse, p, pCol, pDfltExpr)
			}
		}
	}
	if libc.Int32FromUint8((*TParse)(unsafe.Pointer(pParse)).FeParseMode) >= int32(PARSE_MODE_RENAME) {
		_sqlite3RenameExprUnmap(tls, pParse, pExpr)
	}
	_sqlite3ExprDelete(tls, db, pExpr)
}

// C documentation
//
//	/* Change the most recently parsed column to be a GENERATED ALWAYS AS
//	** column.
//	*/
func _sqlite3AddGenerated(tls *libc.TLS, pParse uintptr, pExpr uintptr, pType uintptr) {
	bp := tls.Alloc(16)
	defer tls.Free(16)
	var eType Tu8
	var pCol, pTab, v1 uintptr
	_, _, _, _ = eType, pCol, pTab, v1
	eType = uint8(COLFLAG_VIRTUAL)
	pTab = (*TParse)(unsafe.Pointer(pParse)).FpNewTable
	if pTab == uintptr(0) {
		/* generated column in an CREATE TABLE IF NOT EXISTS that already exists */
		goto generated_done
	}
	pCol = (*TTable)(unsafe.Pointer(pTab)).FaCol + uintptr(int32((*TTable)(unsafe.Pointer(pTab)).FnCol)-int32(1))*16
	if libc.Int32FromUint8((*TParse)(unsafe.Pointer(pParse)).FeParseMode) == int32(PARSE_MODE_DECLARE_VTAB) {
		_sqlite3ErrorMsg(tls, pParse, __ccgo_ts+14250, 0)
		goto generated_done
	}
	if libc.Int32FromUint16((*TColumn)(unsafe.Pointer(pCol)).FiDflt) > 0 {
		goto generated_error
	}
	if pType != 0 {
		if (*TToken)(unsafe.Pointer(pType)).Fn == uint32(7) && Xsqlite3_strnicmp(tls, __ccgo_ts+14293, (*TToken)(unsafe.Pointer(pType)).Fz, int32(7)) == 0 {
			/* no-op */
		} else {
			if (*TToken)(unsafe.Pointer(pType)).Fn == uint32(6) && Xsqlite3_strnicmp(tls, __ccgo_ts+14301, (*TToken)(unsafe.Pointer(pType)).Fz, int32(6)) == 0 {
				eType = uint8(COLFLAG_STORED)
			} else {
				goto generated_error
			}
		}
	}
	if libc.Int32FromUint8(eType) == int32(COLFLAG_VIRTUAL) {
		(*TTable)(unsafe.Pointer(pTab)).FnNVCol = (*TTable)(unsafe.Pointer(pTab)).FnNVCol - 1
	}
	v1 = pCol + 14
	*(*Tu16)(unsafe.Pointer(v1)) = Tu16(int32(*(*Tu16)(unsafe.Pointer(v1))) | libc.Int32FromUint8(eType))
	**(**Tu32)(__ccgo_up(pTab + 48)) |= uint32(eType)
	if libc.Int32FromUint16((*TColumn)(unsafe.Pointer(pCol)).FcolFlags)&int32(COLFLAG_PRIMKEY) != 0 {
		_makeColumnPartOfPrimaryKey(tls, pParse, pCol) /* For the error message */
	}
	if pExpr != 0 && libc.Int32FromUint8((*TExpr)(unsafe.Pointer(pExpr)).Fop) == int32(TK_ID) {
		/* The value of a generated column needs to be a real expression, not
		 ** just a reference to another column, in order for covering index
		 ** optimizations to work correctly.  So if the value is not an expression,
		 ** turn it into one by adding a unary "+" operator. */
		pExpr = _sqlite3PExpr(tls, pParse, int32(TK_UPLUS), pExpr, uintptr(0))
	}
	if pExpr != 0 && libc.Int32FromUint8((*TExpr)(unsafe.Pointer(pExpr)).Fop) != int32(TK_RAISE) {
		(*TExpr)(unsafe.Pointer(pExpr)).FaffExpr = (*TColumn)(unsafe.Pointer(pCol)).Faffinity
	}
	_sqlite3ColumnSetExpr(tls, pParse, pTab, pCol, pExpr)
	pExpr = uintptr(0)
	goto generated_done
	goto generated_error
generated_error:
	;
	_sqlite3ErrorMsg(tls, pParse, __ccgo_ts+14308, libc.VaList(bp+8, (*TColumn)(unsafe.Pointer(pCol)).FzCnName))
	goto generated_done
generated_done:
	;
	_sqlite3ExprDelete(tls, (*TParse)(unsafe.Pointer(pParse)).Fdb, pExpr)
}

// C documentation
//
//	/*
//	** Designate the PRIMARY KEY for the table.  pList is a list of names
//	** of columns that form the primary key.  If pList is NULL, then the
//	** most recently added column of the table is the primary key.
//	**
//	** A table can have at most one primary key.  If the table already has
//	** a primary key (and this is the second primary key) then create an
//	** error.
//	**
//	** If the PRIMARY KEY is on a single column whose datatype is INTEGER,
//	** then we will try to use that column as the rowid.  Set the Table.iPKey
//	** field of the table under construction to be the index of the
//	** INTEGER PRIMARY KEY column.  Table.iPKey is set to -1 if there is
//	** no INTEGER PRIMARY KEY.
//	**
//	** If the key is not an INTEGER PRIMARY KEY, then create a unique
//	** index for the key.  No index is created for INTEGER PRIMARY KEYs.
//	*/
func _sqlite3AddPrimaryKey(tls *libc.TLS, pParse uintptr, pList uintptr, onError int32, autoInc int32, sortOrder int32) {
	bp := tls.Alloc(16)
	defer tls.Free(16)
	var i, iCol, nTerm int32
	var pCExpr, pCExpr1, pCol, pTab uintptr
	_, _, _, _, _, _, _ = i, iCol, nTerm, pCExpr, pCExpr1, pCol, pTab
	pTab = (*TParse)(unsafe.Pointer(pParse)).FpNewTable
	pCol = uintptr(0)
	iCol = -int32(1)
	if pTab == uintptr(0) {
		goto primary_key_exit
	}
	if (*TTable)(unsafe.Pointer(pTab)).FtabFlags&uint32(TF_HasPrimaryKey) != 0 {
		_sqlite3ErrorMsg(tls, pParse, __ccgo_ts+14153, libc.VaList(bp+8, (*TTable)(unsafe.Pointer(pTab)).FzName))
		goto primary_key_exit
	}
	**(**Tu32)(__ccgo_up(pTab + 48)) |= uint32(TF_HasPrimaryKey)
	if pList == uintptr(0) {
		iCol = int32((*TTable)(unsafe.Pointer(pTab)).FnCol) - int32(1)
		pCol = (*TTable)(unsafe.Pointer(pTab)).FaCol + uintptr(iCol)*16
		_makeColumnPartOfPrimaryKey(tls, pParse, pCol)
		nTerm = int32(1)
	} else {
		nTerm = (*TExprList)(unsafe.Pointer(pList)).FnExpr
		i = 0
		for {
			if !(i < nTerm) {
				break
			}
			pCExpr = _sqlite3ExprSkipCollate(tls, (*(*TExprList_item)(unsafe.Pointer(pList + 8 + uintptr(i)*32))).FpExpr)
			_sqlite3StringToId(tls, pCExpr)
			if libc.Int32FromUint8((*TExpr)(unsafe.Pointer(pCExpr)).Fop) == int32(TK_ID) {
				iCol = _sqlite3ColumnIndex(tls, pTab, *(*uintptr)(unsafe.Pointer(pCExpr + 8)))
				if iCol >= 0 {
					pCol = (*TTable)(unsafe.Pointer(pTab)).FaCol + uintptr(iCol)*16
					_makeColumnPartOfPrimaryKey(tls, pParse, pCol)
				}
			}
			goto _1
		_1:
			;
			i = i + 1
		}
	}
	if nTerm == int32(1) && pCol != 0 && int32(uint32(*(*uint8)(unsafe.Pointer(pCol + 8))&0xf0>>4)) == int32(COLTYPE_INTEGER) && sortOrder != int32(SQLITE_SO_DESC) {
		if libc.Int32FromUint8((*TParse)(unsafe.Pointer(pParse)).FeParseMode) >= int32(PARSE_MODE_RENAME) && pList != 0 {
			pCExpr1 = _sqlite3ExprSkipCollate(tls, (*(*TExprList_item)(unsafe.Pointer(pList + 8))).FpExpr)
			_sqlite3RenameTokenRemap(tls, pParse, pTab+52, pCExpr1)
		}
		(*TTable)(unsafe.Pointer(pTab)).FiPKey = int16(iCol)
		(*TTable)(unsafe.Pointer(pTab)).FkeyConf = libc.Uint8FromInt32(onError)
		**(**Tu32)(__ccgo_up(pTab + 48)) |= libc.Uint32FromInt32(autoInc * int32(TF_Autoincrement))
		if pList != 0 {
			(*TParse)(unsafe.Pointer(pParse)).FiPkSortOrder = (*(*TExprList_item)(unsafe.Pointer(pList + 8))).Ffg.FsortFlags
		}
		_sqlite3HasExplicitNulls(tls, pParse, pList)
	} else {
		if autoInc != 0 {
			_sqlite3ErrorMsg(tls, pParse, __ccgo_ts+14194, 0)
		} else {
			_sqlite3CreateIndex(tls, pParse, uintptr(0), uintptr(0), uintptr(0), pList, onError, uintptr(0), uintptr(0), sortOrder, 0, uint8(SQLITE_IDXTYPE_PRIMARYKEY))
			pList = uintptr(0)
		}
	}
	goto primary_key_exit
primary_key_exit:
	;
	_sqlite3ExprListDelete(tls, (*TParse)(unsafe.Pointer(pParse)).Fdb, pList)
	return
}

// C documentation
//
//	/*
//	** Add the RETURNING clause to the parse currently underway.
//	**
//	** This routine creates a special TEMP trigger that will fire for each row
//	** of the DML statement.  That TEMP trigger contains a single SELECT
//	** statement with a result set that is the argument of the RETURNING clause.
//	** The trigger has the Trigger.bReturning flag and an opcode of
//	** TK_RETURNING instead of TK_SELECT, so that the trigger code generator
//	** knows to handle it specially.  The TEMP trigger is automatically
//	** removed at the end of the parse.
//	**
//	** When this routine is called, we do not yet know if the RETURNING clause
//	** is attached to a DELETE, INSERT, or UPDATE, so construct it as a
//	** RETURNING trigger instead.  It will then be converted into the appropriate
//	** type on the first call to sqlite3TriggersExist().
//	*/
func _sqlite3AddReturning(tls *libc.TLS, pParse uintptr, pList uintptr) {
	bp := tls.Alloc(16)
	defer tls.Free(16)
	var db, pHash, pRet uintptr
	_, _, _ = db, pHash, pRet
	db = (*TParse)(unsafe.Pointer(pParse)).Fdb
	if (*TParse)(unsafe.Pointer(pParse)).FpNewTrigger != 0 {
		_sqlite3ErrorMsg(tls, pParse, __ccgo_ts+13895, 0)
	} else {
	}
	libc.SetBitFieldPtr16Uint32(pParse+40, libc.Uint32FromInt32(1), 3, 0x8)
	pRet = _sqlite3DbMallocZero(tls, db, uint64(232))
	if pRet == uintptr(0) {
		_sqlite3ExprListDelete(tls, db, pList)
		return
	}
	(*(*struct {
		FpReturning uintptr
	})(unsafe.Pointer(&(*TParse)(unsafe.Pointer(pParse)).Fu1))).FpReturning = pRet
	(*TReturning)(unsafe.Pointer(pRet)).FpParse = pParse
	(*TReturning)(unsafe.Pointer(pRet)).FpReturnEL = pList
	_sqlite3ParserAddCleanup(tls, pParse, __ccgo_fp(_sqlite3DeleteReturning), pRet)
	if (*Tsqlite3)(unsafe.Pointer(db)).FmallocFailed != 0 {
		return
	}
	Xsqlite3_snprintf(tls, int32(40), pRet+188, __ccgo_ts+13929, libc.VaList(bp+8, pParse))
	(*TReturning)(unsafe.Pointer(pRet)).FretTrig.FzName = pRet + 188
	(*TReturning)(unsafe.Pointer(pRet)).FretTrig.Fop = uint8(TK_RETURNING)
	(*TReturning)(unsafe.Pointer(pRet)).FretTrig.Ftr_tm = uint8(TRIGGER_AFTER)
	(*TReturning)(unsafe.Pointer(pRet)).FretTrig.FbReturning = uint8(1)
	(*TReturning)(unsafe.Pointer(pRet)).FretTrig.FpSchema = (**(**TDb)(__ccgo_up((*Tsqlite3)(unsafe.Pointer(db)).FaDb + 1*32))).FpSchema
	(*TReturning)(unsafe.Pointer(pRet)).FretTrig.FpTabSchema = (**(**TDb)(__ccgo_up((*Tsqlite3)(unsafe.Pointer(db)).FaDb + 1*32))).FpSchema
	(*TReturning)(unsafe.Pointer(pRet)).FretTrig.Fstep_list = pRet + 88
	(*TReturning)(unsafe.Pointer(pRet)).FretTStep.Fop = uint8(TK_RETURNING)
	(*TReturning)(unsafe.Pointer(pRet)).FretTStep.FpTrig = pRet + 16
	(*TReturning)(unsafe.Pointer(pRet)).FretTStep.FpExprList = pList
	pHash = (**(**TDb)(__ccgo_up((*Tsqlite3)(unsafe.Pointer(db)).FaDb + 1*32))).FpSchema + 56
	if _sqlite3HashInsert(tls, pHash, pRet+188, pRet+16) == pRet+16 {
		_sqlite3OomFault(tls, db)
	}
}

// C documentation
//
//	/*
//	** Generate bytecode to implement:
//	**
//	**    ALTER TABLE pSrc ADD [CONSTRAINT pName] CHECK(pExpr)
//	**
//	** Any "ON CONFLICT" text that occurs after the "CHECK(...)", up
//	** until pParse->sLastToken, is included as part of the new constraint.
//	*/
func _sqlite3AlterAddConstraint(tls *libc.TLS, pParse uintptr, pSrc uintptr, pFirst uintptr, pName uintptr, zExpr uintptr, nExpr int32, pExpr uintptr) {
	bp := tls.Alloc(64)
	defer tls.Free(64)
	var nCons, rc int32
	var pCons, pTab, zName uintptr
	var _ /* iDb at bp+0 */ int32
	var _ /* zDb at bp+8 */ uintptr
	_, _, _, _, _ = nCons, pCons, pTab, rc, zName
	pTab = uintptr(0)                             /* Table identified by pSrc */
	**(**int32)(__ccgo_up(bp)) = 0                /* Which schema does pTab live in */
	**(**uintptr)(__ccgo_up(bp + 8)) = uintptr(0) /* Name of the schema in which pTab lives */
	pCons = uintptr(0)                            /* Result from error checking pExpr */
	/* Look up the table being altered. */
	pTab = _alterFindTable(tls, pParse, pSrc, bp, bp+8, int32(1))
	if !(pTab != 0) {
		_sqlite3ExprDelete(tls, (*TParse)(unsafe.Pointer(pParse)).Fdb, pExpr)
		return
	}
	/* Verify that the new CHECK constraint does not contain any
	 ** internal-use-only function.  Forum post 2026-05-10T01:11:28Z
	 */
	rc = _sqlite3ResolveSelfReference(tls, pParse, pTab, int32(NC_IsCheck), pExpr, uintptr(0))
	_sqlite3ExprDelete(tls, (*TParse)(unsafe.Pointer(pParse)).Fdb, pExpr)
	if rc != 0 {
		return
	}
	/* If this new constraint has a name, check that it is not a duplicate of
	 ** an existing constraint. It is an error if it is.  */
	if pName != 0 {
		zName = _sqlite3NameFromToken(tls, (*TParse)(unsafe.Pointer(pParse)).Fdb, pName)
		_sqlite3NestedParse(tls, pParse, __ccgo_ts+12276, libc.VaList(bp+24, zName, int32(SQLITE_ERROR), **(**uintptr)(__ccgo_up(bp + 8)), (*TTable)(unsafe.Pointer(pTab)).FzName, zName))
		_sqlite3DbFree(tls, (*TParse)(unsafe.Pointer(pParse)).Fdb, zName)
	}
	/* Search for a constraint violation. Throw an exception if one is found. */
	_sqlite3NestedParse(tls, pParse, __ccgo_ts+12441, libc.VaList(bp+24, int32(SQLITE_CONSTRAINT), **(**uintptr)(__ccgo_up(bp + 8)), (*TTable)(unsafe.Pointer(pTab)).FzName, nExpr, zExpr))
	/* Edit the SQL for the named table. */
	pCons = (*TToken)(unsafe.Pointer(pFirst)).Fz
	nCons = _alterRtrimConstraint(tls, (*TParse)(unsafe.Pointer(pParse)).Fdb, pCons, int32(int64((*TParse)(unsafe.Pointer(pParse)).FsLastToken.Fz)-int64(pCons)))
	_sqlite3NestedParse(tls, pParse, __ccgo_ts+12521, libc.VaList(bp+24, **(**uintptr)(__ccgo_up(bp + 8)), nCons, pCons, (*TTable)(unsafe.Pointer(pTab)).FzName))
	/* Finally, reload the database schema. */
	_renameReloadSchema(tls, pParse, **(**int32)(__ccgo_up(bp)), uint16(INITFLAG_AlterDropCons))
}

// C documentation
//
//	/*
//	** This function is called by the parser after the table-name in
//	** an "ALTER TABLE <table-name> ADD" statement is parsed. Argument
//	** pSrc is the full-name of the table being altered.
//	**
//	** This routine makes a (partial) copy of the Table structure
//	** for the table being altered and sets Parse.pNewTable to point
//	** to it. Routines called by the parser as the column definition
//	** is parsed (i.e. sqlite3AddColumn()) add the new Column data to
//	** the copy. The copy of the Table structure is deleted by tokenize.c
//	** after parsing is finished.
//	**
//	** Routine sqlite3AlterFinishAddColumn() will be called to complete
//	** coding the "ALTER TABLE ... ADD" statement.
//	*/
func _sqlite3AlterBeginAddColumn(tls *libc.TLS, pParse uintptr, pSrc uintptr) {
	bp := tls.Alloc(16)
	defer tls.Free(16)
	var db, pCol, pNew, pTab uintptr
	var i, iDb, nAlloc int32
	_, _, _, _, _, _, _ = db, i, iDb, nAlloc, pCol, pNew, pTab
	db = (*TParse)(unsafe.Pointer(pParse)).Fdb
	/* Look up the table being altered. */
	if (*Tsqlite3)(unsafe.Pointer(db)).FmallocFailed != 0 {
		goto exit_begin_add_column
	}
	pTab = _sqlite3LocateTableItem(tls, pParse, uint32(0), pSrc+8)
	if !(pTab != 0) {
		goto exit_begin_add_column
	}
	if libc.Int32FromUint8((*TTable)(unsafe.Pointer(pTab)).FeTabType) == int32(TABTYP_VTAB) {
		_sqlite3ErrorMsg(tls, pParse, __ccgo_ts+11025, 0)
		goto exit_begin_add_column
	}
	/* Make sure this is not an attempt to ALTER a view. */
	if libc.Int32FromUint8((*TTable)(unsafe.Pointer(pTab)).FeTabType) == int32(TABTYP_VIEW) {
		_sqlite3ErrorMsg(tls, pParse, __ccgo_ts+11059, 0)
		goto exit_begin_add_column
	}
	if SQLITE_OK != _isAlterableTable(tls, pParse, pTab) {
		goto exit_begin_add_column
	}
	_sqlite3MayAbort(tls, pParse)
	iDb = _sqlite3SchemaToIndex(tls, db, (*TTable)(unsafe.Pointer(pTab)).FpSchema)
	/* Put a copy of the Table struct in Parse.pNewTable for the
	 ** sqlite3AddColumn() function and friends to modify.  But modify
	 ** the name by adding an "sqlite_altertab_" prefix.  By adding this
	 ** prefix, we insure that the name will not collide with an existing
	 ** table because user table are not allowed to have the "sqlite_"
	 ** prefix on their name.
	 */
	pNew = _sqlite3DbMallocZero(tls, db, uint64(120))
	if !(pNew != 0) {
		goto exit_begin_add_column
	}
	(*TParse)(unsafe.Pointer(pParse)).FpNewTable = pNew
	(*TTable)(unsafe.Pointer(pNew)).FnTabRef = uint32(1)
	(*TTable)(unsafe.Pointer(pNew)).FnCol = (*TTable)(unsafe.Pointer(pTab)).FnCol
	nAlloc = (int32((*TTable)(unsafe.Pointer(pNew)).FnCol)-int32(1))/int32(8)*int32(8) + int32(8)
	(*TTable)(unsafe.Pointer(pNew)).FaCol = _sqlite3DbMallocZero(tls, db, uint64(16)*uint64(libc.Uint32FromInt32(nAlloc)))
	(*TTable)(unsafe.Pointer(pNew)).FzName = _sqlite3MPrintf(tls, db, __ccgo_ts+11089, libc.VaList(bp+8, (*TTable)(unsafe.Pointer(pTab)).FzName))
	if !((*TTable)(unsafe.Pointer(pNew)).FaCol != 0) || !((*TTable)(unsafe.Pointer(pNew)).FzName != 0) {
		goto exit_begin_add_column
	}
	libc.Xmemcpy(tls, (*TTable)(unsafe.Pointer(pNew)).FaCol, (*TTable)(unsafe.Pointer(pTab)).FaCol, uint64(16)*libc.Uint64FromInt16((*TTable)(unsafe.Pointer(pNew)).FnCol))
	i = 0
	for {
		if !(i < int32((*TTable)(unsafe.Pointer(pNew)).FnCol)) {
			break
		}
		pCol = (*TTable)(unsafe.Pointer(pNew)).FaCol + uintptr(i)*16
		(*TColumn)(unsafe.Pointer(pCol)).FzCnName = _sqlite3DbStrDup(tls, db, (*TColumn)(unsafe.Pointer(pCol)).FzCnName)
		(*TColumn)(unsafe.Pointer(pCol)).FhName = _sqlite3StrIHash(tls, (*TColumn)(unsafe.Pointer(pCol)).FzCnName)
		goto _1
	_1:
		;
		i = i + 1
	}
	(*(*struct {
		FaddColOffset int32
		FpFKey        uintptr
		FpDfltList    uintptr
	})(unsafe.Pointer(pNew + 64))).FpDfltList = _sqlite3ExprListDup(tls, db, (*(*struct {
		FaddColOffset int32
		FpFKey        uintptr
		FpDfltList    uintptr
	})(unsafe.Pointer(pTab + 64))).FpDfltList, 0)
	(*TTable)(unsafe.Pointer(pNew)).FpSchema = (**(**TDb)(__ccgo_up((*Tsqlite3)(unsafe.Pointer(db)).FaDb + uintptr(iDb)*32))).FpSchema
	(*(*struct {
		FaddColOffset int32
		FpFKey        uintptr
		FpDfltList    uintptr
	})(unsafe.Pointer(pNew + 64))).FaddColOffset = (*(*struct {
		FaddColOffset int32
		FpFKey        uintptr
		FpDfltList    uintptr
	})(unsafe.Pointer(pTab + 64))).FaddColOffset
	goto exit_begin_add_column
exit_begin_add_column:
	;
	_sqlite3SrcListDelete(tls, db, pSrc)
	return
}

// C documentation
//
//	/*
//	** Generate bytecode for one of:
//	**
//	**  (1)   ALTER TABLE pSrc DROP CONSTRAINT pCons
//	**  (2)   ALTER TABLE pSrc ALTER pCol DROP NOT NULL
//	**
//	** One of pCons and pCol must be NULL and the other non-null.
//	*/
func _sqlite3AlterDropConstraint(tls *libc.TLS, pParse uintptr, pSrc uintptr, pCons uintptr, pCol uintptr) {
	bp := tls.Alloc(64)
	defer tls.Free(64)
	var db, pTab, z, zArg uintptr
	var _ /* iCol at bp+16 */ int32
	var _ /* iDb at bp+0 */ int32
	var _ /* zDb at bp+8 */ uintptr
	_, _, _, _ = db, pTab, z, zArg
	db = (*TParse)(unsafe.Pointer(pParse)).Fdb
	pTab = uintptr(0)
	**(**int32)(__ccgo_up(bp)) = 0
	**(**uintptr)(__ccgo_up(bp + 8)) = uintptr(0)
	zArg = uintptr(0)
	pTab = _alterFindTable(tls, pParse, pSrc, bp, bp+8, libc.BoolInt32(pCons != uintptr(0)))
	if !(pTab != 0) {
		return
	}
	if pCons != 0 {
		z = _sqlite3NameFromToken(tls, db, pCons)
		zArg = _sqlite3MPrintf(tls, db, __ccgo_ts+11918, libc.VaList(bp+32, z))
		_sqlite3DbFree(tls, db, z)
	} else {
		if _alterFindCol(tls, pParse, pTab, pCol, bp+16) != 0 {
			return
		}
		zArg = _sqlite3MPrintf(tls, db, __ccgo_ts+5282, libc.VaList(bp+32, **(**int32)(__ccgo_up(bp + 16))))
	}
	/* Edit the SQL for the named table. */
	_sqlite3NestedParse(tls, pParse, __ccgo_ts+11921, libc.VaList(bp+32, **(**uintptr)(__ccgo_up(bp + 8)), zArg, (*TTable)(unsafe.Pointer(pTab)).FzName))
	_sqlite3DbFree(tls, db, zArg)
	/* Finally, reload the database schema. */
	_renameReloadSchema(tls, pParse, **(**int32)(__ccgo_up(bp)), uint16(INITFLAG_AlterDropCons))
}

// C documentation
//
//	/*
//	** Generate code to implement the "ALTER TABLE xxx RENAME TO yyy"
//	** command.
//	*/
func _sqlite3AlterRenameTable(tls *libc.TLS, pParse uintptr, pSrc uintptr, pName uintptr) {
	bp := tls.Alloc(64)
	defer tls.Free(64)
	var db, pTab, pVTab, v, zDb, zName, zTabName, v2 uintptr
	var i, iDb, nTabName, v1 int32
	_, _, _, _, _, _, _, _, _, _, _, _ = db, i, iDb, nTabName, pTab, pVTab, v, zDb, zName, zTabName, v1, v2 /* Table being renamed */
	zName = uintptr(0)                                                                                      /* NULL-terminated version of pName */
	db = (*TParse)(unsafe.Pointer(pParse)).Fdb
	pVTab = uintptr(0) /* Non-zero if this is a v-tab with an xRename() */
	if (*Tsqlite3)(unsafe.Pointer(db)).FmallocFailed != 0 {
		goto exit_rename_table
	}
	pTab = _sqlite3LocateTableItem(tls, pParse, uint32(0), pSrc+8)
	if !(pTab != 0) {
		goto exit_rename_table
	}
	iDb = _sqlite3SchemaToIndex(tls, (*TParse)(unsafe.Pointer(pParse)).Fdb, (*TTable)(unsafe.Pointer(pTab)).FpSchema)
	zDb = (**(**TDb)(__ccgo_up((*Tsqlite3)(unsafe.Pointer(db)).FaDb + uintptr(iDb)*32))).FzDbSName
	/* Get a NULL terminated version of the new table name. */
	zName = _sqlite3NameFromToken(tls, db, pName)
	if !(zName != 0) {
		goto exit_rename_table
	}
	/* Check that a table or index named 'zName' does not already exist
	 ** in database iDb. If so, this is an error.
	 */
	if _sqlite3FindTable(tls, db, zName, zDb) != 0 || _sqlite3FindIndex(tls, db, zName, zDb) != 0 || _sqlite3IsShadowTableOf(tls, db, pTab, zName) != 0 {
		_sqlite3ErrorMsg(tls, pParse, __ccgo_ts+9311, libc.VaList(bp+8, zName))
		goto exit_rename_table
	}
	/* Make sure it is not a system table being altered, or a reserved name
	 ** that the table is being renamed to.
	 */
	if SQLITE_OK != _isAlterableTable(tls, pParse, pTab) {
		goto exit_rename_table
	}
	if SQLITE_OK != _sqlite3CheckObjectName(tls, pParse, zName, __ccgo_ts+9370, zName) {
		goto exit_rename_table
	}
	if libc.Int32FromUint8((*TTable)(unsafe.Pointer(pTab)).FeTabType) == int32(TABTYP_VIEW) {
		_sqlite3ErrorMsg(tls, pParse, __ccgo_ts+9376, libc.VaList(bp+8, (*TTable)(unsafe.Pointer(pTab)).FzName))
		goto exit_rename_table
	}
	/* Invoke the authorization callback. */
	if _sqlite3AuthCheck(tls, pParse, int32(SQLITE_ALTER_TABLE), zDb, (*TTable)(unsafe.Pointer(pTab)).FzName, uintptr(0)) != 0 {
		goto exit_rename_table
	}
	if _sqlite3ViewGetColumnNames(tls, pParse, pTab) != 0 {
		goto exit_rename_table
	}
	if libc.Int32FromUint8((*TTable)(unsafe.Pointer(pTab)).FeTabType) == int32(TABTYP_VTAB) {
		pVTab = _sqlite3GetVTable(tls, db, pTab)
		if (*Tsqlite3_module)(unsafe.Pointer((*Tsqlite3_vtab)(unsafe.Pointer((*TVTable)(unsafe.Pointer(pVTab)).FpVtab)).FpModule)).FxRename == uintptr(0) {
			pVTab = uintptr(0)
		}
	}
	/* Begin a transaction for database iDb. Then modify the schema cookie
	 ** (since the ALTER TABLE modifies the schema). Call sqlite3MayAbort(),
	 ** as the scalar functions (e.g. sqlite_rename_table()) invoked by the
	 ** nested SQL may raise an exception.  */
	v = _sqlite3GetVdbe(tls, pParse)
	if v == uintptr(0) {
		goto exit_rename_table
	}
	_sqlite3MayAbort(tls, pParse)
	/* figure out how many UTF-8 characters are in zName */
	zTabName = (*TTable)(unsafe.Pointer(pTab)).FzName
	nTabName = _sqlite3Utf8CharLen(tls, zTabName, -int32(1))
	/* Rewrite all CREATE TABLE, INDEX, TRIGGER or VIEW statements in
	 ** the schema to use the new table name.  */
	_sqlite3NestedParse(tls, pParse, __ccgo_ts+9403, libc.VaList(bp+8, zDb, zDb, zTabName, zName, libc.BoolInt32(iDb == int32(1)), zTabName))
	/* Update the tbl_name and name columns of the sqlite_schema table
	 ** as required.  */
	_sqlite3NestedParse(tls, pParse, __ccgo_ts+9587, libc.VaList(bp+8, zDb, zName, zName, zName, nTabName, zTabName))
	/* If the sqlite_sequence table exists in this database, then update
	 ** it with the new table name.
	 */
	if _sqlite3FindTable(tls, db, __ccgo_ts+9892, zDb) != 0 {
		_sqlite3NestedParse(tls, pParse, __ccgo_ts+9908, libc.VaList(bp+8, zDb, zName, (*TTable)(unsafe.Pointer(pTab)).FzName))
	}
	/* If the table being renamed is not itself part of the temp database,
	 ** edit view and trigger definitions within the temp database
	 ** as required.  */
	if iDb != int32(1) {
		_sqlite3NestedParse(tls, pParse, __ccgo_ts+9966, libc.VaList(bp+8, zDb, zTabName, zName, zTabName, zDb, zName))
	}
	/* If this is a virtual table, invoke the xRename() function if
	 ** one is defined. The xRename() callback will modify the names
	 ** of any resources used by the v-table implementation (including other
	 ** SQLite tables) that are identified by the name of the virtual table.
	 */
	if pVTab != 0 {
		v2 = pParse + 60
		*(*int32)(unsafe.Pointer(v2)) = *(*int32)(unsafe.Pointer(v2)) + 1
		v1 = *(*int32)(unsafe.Pointer(v2))
		i = v1
		_sqlite3VdbeLoadString(tls, v, i, zName)
		_sqlite3VdbeAddOp4(tls, v, int32(OP_VRename), i, 0, 0, pVTab, -int32(12))
	}
	_renameReloadSchema(tls, pParse, iDb, uint16(INITFLAG_AlterRename))
	_renameTestSchema(tls, pParse, zDb, libc.BoolInt32(iDb == int32(1)), __ccgo_ts+10231, 0)
	goto exit_rename_table
exit_rename_table:
	;
	_sqlite3SrcListDelete(tls, db, pSrc)
	_sqlite3DbFree(tls, db, zName)
}

// C documentation
//
//	/*
//	** Prepare a statement of the form:
//	**
//	**   ALTER TABLE pSrc ALTER pCol SET NOT NULL
//	*/
func _sqlite3AlterSetNotNull(tls *libc.TLS, pParse uintptr, pSrc uintptr, pCol uintptr, pFirst uintptr) {
	bp := tls.Alloc(80)
	defer tls.Free(80)
	var nCons int32
	var pCons, pTab uintptr
	var _ /* iCol at bp+0 */ int32
	var _ /* iDb at bp+4 */ int32
	var _ /* zDb at bp+8 */ uintptr
	_, _, _ = nCons, pCons, pTab
	pTab = uintptr(0)
	**(**int32)(__ccgo_up(bp)) = 0
	**(**int32)(__ccgo_up(bp + 4)) = 0
	**(**uintptr)(__ccgo_up(bp + 8)) = uintptr(0)
	pCons = uintptr(0)
	nCons = 0
	/* Look up the table being altered. */
	pTab = _alterFindTable(tls, pParse, pSrc, bp+4, bp+8, 0)
	if !(pTab != 0) {
		return
	}
	/* Find the column being altered. */
	if _alterFindCol(tls, pParse, pTab, pCol, bp) != 0 {
		return
	}
	/* Find the length in bytes of the constraint definition */
	pCons = (*TToken)(unsafe.Pointer(pFirst)).Fz
	nCons = _alterRtrimConstraint(tls, (*TParse)(unsafe.Pointer(pParse)).Fdb, pCons, int32(int64((*TParse)(unsafe.Pointer(pParse)).FsLastToken.Fz)-int64(pCons)))
	/* Search for a constraint violation. Throw an exception if one is found. */
	_sqlite3NestedParse(tls, pParse, __ccgo_ts+12044, libc.VaList(bp+24, int32(SQLITE_CONSTRAINT), **(**uintptr)(__ccgo_up(bp + 8)), (*TTable)(unsafe.Pointer(pTab)).FzName, libc.Int32FromUint32((*TToken)(unsafe.Pointer(pCol)).Fn), (*TToken)(unsafe.Pointer(pCol)).Fz))
	/* Edit the SQL for the named table. */
	_sqlite3NestedParse(tls, pParse, __ccgo_ts+12125, libc.VaList(bp+24, **(**uintptr)(__ccgo_up(bp + 8)), **(**int32)(__ccgo_up(bp)), nCons, pCons, **(**int32)(__ccgo_up(bp)), (*TTable)(unsafe.Pointer(pTab)).FzName))
	/* Finally, reload the database schema. */
	_renameReloadSchema(tls, pParse, **(**int32)(__ccgo_up(bp + 4)), uint16(INITFLAG_AlterDropCons))
}

// C documentation
//
//	/*
//	** Load the content of the sqlite_stat1 and sqlite_stat4 tables. The
//	** contents of sqlite_stat1 are used to populate the Index.aiRowEst[]
//	** arrays. The contents of sqlite_stat4 are used to populate the
//	** Index.aSample[] arrays.
//	**
//	** If the sqlite_stat1 table is not present in the database, SQLITE_ERROR
//	** is returned. In this case, even if SQLITE_ENABLE_STAT4 was defined
//	** during compilation and the sqlite_stat4 table is present, no data is
//	** read from it.
//	**
//	** If SQLITE_ENABLE_STAT4 was defined during compilation and the
//	** sqlite_stat4 table is not present in the database, SQLITE_ERROR is
//	** returned. However, in this case, data is read from the sqlite_stat1
//	** table (if it is present) before returning.
//	**
//	** If an OOM error occurs, this function always sets db->mallocFailed.
//	** This means if the caller does not care about other errors, the return
//	** code may be ignored.
//	*/
func _sqlite3AnalysisLoad(tls *libc.TLS, db uintptr, iDb int32) (r int32) {
	bp := tls.Alloc(32)
	defer tls.Free(32)
	var i, pIdx, pIdx1, pIdx2, pSchema, pStat1, pTab, zSql, v3 uintptr
	var rc, v5 int32
	var _ /* sInfo at bp+0 */ TanalysisInfo
	_, _, _, _, _, _, _, _, _, _, _ = i, pIdx, pIdx1, pIdx2, pSchema, pStat1, pTab, rc, zSql, v3, v5
	rc = SQLITE_OK
	pSchema = (**(**TDb)(__ccgo_up((*Tsqlite3)(unsafe.Pointer(db)).FaDb + uintptr(iDb)*32))).FpSchema
	/* Clear any prior statistics */
	i = (*THash)(unsafe.Pointer(pSchema + 8)).Ffirst
	for {
		if !(i != 0) {
			break
		}
		pTab = (*THashElem)(unsafe.Pointer(i)).Fdata
		**(**Tu32)(__ccgo_up(pTab + 48)) &= libc.Uint32FromInt32(^libc.Int32FromInt32(TF_HasStat1))
		goto _1
	_1:
		;
		i = (*THashElem)(unsafe.Pointer(i)).Fnext
	}
	i = (*THash)(unsafe.Pointer(pSchema + 32)).Ffirst
	for {
		if !(i != 0) {
			break
		}
		pIdx = (*THashElem)(unsafe.Pointer(i)).Fdata
		libc.SetBitFieldPtr16Uint32(pIdx+100, libc.Uint32FromInt32(0), 7, 0x80)
		_sqlite3DeleteIndexSamples(tls, db, pIdx)
		(*TIndex)(unsafe.Pointer(pIdx)).FaSample = uintptr(0)
		goto _2
	_2:
		;
		i = (*THashElem)(unsafe.Pointer(i)).Fnext
	}
	/* Load new statistics out of the sqlite_stat1 table */
	(**(**TanalysisInfo)(__ccgo_up(bp))).Fdb = db
	(**(**TanalysisInfo)(__ccgo_up(bp))).FzDatabase = (**(**TDb)(__ccgo_up((*Tsqlite3)(unsafe.Pointer(db)).FaDb + uintptr(iDb)*32))).FzDbSName
	v3 = _sqlite3FindTable(tls, db, __ccgo_ts+12826, (**(**TanalysisInfo)(__ccgo_up(bp))).FzDatabase)
	pStat1 = v3
	if v3 != 0 && libc.Int32FromUint8((*TTable)(unsafe.Pointer(pStat1)).FeTabType) == TABTYP_NORM {
		zSql = _sqlite3MPrintf(tls, db, __ccgo_ts+13199, libc.VaList(bp+24, (**(**TanalysisInfo)(__ccgo_up(bp))).FzDatabase))
		if zSql == uintptr(0) {
			rc = int32(SQLITE_NOMEM)
		} else {
			rc = Xsqlite3_exec(tls, db, zSql, __ccgo_fp(_analysisLoader), bp, uintptr(0))
			_sqlite3DbFree(tls, db, zSql)
		}
	}
	/* Set appropriate defaults on all indexes not in the sqlite_stat1 table */
	i = (*THash)(unsafe.Pointer(pSchema + 32)).Ffirst
	for {
		if !(i != 0) {
			break
		}
		pIdx1 = (*THashElem)(unsafe.Pointer(i)).Fdata
		if !(int32(uint32(*(*uint16)(unsafe.Pointer(pIdx1 + 100))&0x80>>7)) != 0) {
			_sqlite3DefaultRowEst(tls, pIdx1)
		}
		goto _4
	_4:
		;
		i = (*THashElem)(unsafe.Pointer(i)).Fnext
	}
	/* Load the statistics from the sqlite_stat4 table. */
	if rc == SQLITE_OK {
		(*Tsqlite3)(unsafe.Pointer(db)).Flookaside.FbDisable = (*Tsqlite3)(unsafe.Pointer(db)).Flookaside.FbDisable + 1
		(*Tsqlite3)(unsafe.Pointer(db)).Flookaside.Fsz = uint16(0)
		rc = _loadStat4(tls, db, (**(**TanalysisInfo)(__ccgo_up(bp))).FzDatabase)
		(*Tsqlite3)(unsafe.Pointer(db)).Flookaside.FbDisable = (*Tsqlite3)(unsafe.Pointer(db)).Flookaside.FbDisable - 1
		if (*Tsqlite3)(unsafe.Pointer(db)).Flookaside.FbDisable != 0 {
			v5 = 0
		} else {
			v5 = libc.Int32FromUint16((*Tsqlite3)(unsafe.Pointer(db)).Flookaside.FszTrue)
		}
		(*Tsqlite3)(unsafe.Pointer(db)).Flookaside.Fsz = libc.Uint16FromInt32(v5)
	}
	i = (*THash)(unsafe.Pointer(pSchema + 32)).Ffirst
	for {
		if !(i != 0) {
			break
		}
		pIdx2 = (*THashElem)(unsafe.Pointer(i)).Fdata
		Xsqlite3_free(tls, (*TIndex)(unsafe.Pointer(pIdx2)).FaiRowEst)
		(*TIndex)(unsafe.Pointer(pIdx2)).FaiRowEst = uintptr(0)
		goto _6
	_6:
		;
		i = (*THashElem)(unsafe.Pointer(i)).Fnext
	}
	if rc == int32(SQLITE_NOMEM) {
		_sqlite3OomFault(tls, db)
	}
	return rc
}

/************** End of analyze.c *********************************************/
/************** Begin file attach.c ******************************************/
/*
** 2003 April 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.
**
*************************************************************************
** This file contains code used to implement the ATTACH and DETACH commands.
 */
/* #include "sqliteInt.h" */

// C documentation
//
//	/*
//	** Do an authorization check using the code and arguments given.  Return
//	** either SQLITE_OK (zero) or SQLITE_IGNORE or SQLITE_DENY.  If SQLITE_DENY
//	** is returned, then the error count and error message in pParse are
//	** modified appropriately.
//	*/
func _sqlite3AuthCheck(tls *libc.TLS, pParse uintptr, code int32, zArg1 uintptr, zArg2 uintptr, zArg3 uintptr) (r int32) {
	var db uintptr
	var rc int32
	_, _ = db, rc
	db = (*TParse)(unsafe.Pointer(pParse)).Fdb
	/* Don't do any authorization checks if the database is initializing
	 ** or if the parser is being invoked from within sqlite3_declare_vtab.
	 */
	if (*Tsqlite3)(unsafe.Pointer(db)).FxAuth == uintptr(0) || (*Tsqlite3)(unsafe.Pointer(db)).Finit1.Fbusy != 0 || libc.Int32FromUint8((*TParse)(unsafe.Pointer(pParse)).FeParseMode) != PARSE_MODE_NORMAL {
		return SQLITE_OK
	}
	/* EVIDENCE-OF: R-43249-19882 The third through sixth parameters to the
	 ** callback are either NULL pointers or zero-terminated strings that
	 ** contain additional details about the action to be authorized.
	 **
	 ** The following testcase() macros show that any of the 3rd through 6th
	 ** parameters can be either NULL or a string. */
	rc = (*(*func(*libc.TLS, uintptr, int32, uintptr, uintptr, uintptr, uintptr) int32)(unsafe.Pointer(&struct{ uintptr }{(*Tsqlite3)(unsafe.Pointer(db)).FxAuth})))(tls, (*Tsqlite3)(unsafe.Pointer(db)).FpAuthArg, code, zArg1, zArg2, zArg3, (*TParse)(unsafe.Pointer(pParse)).FzAuthContext)
	if rc == int32(SQLITE_DENY) {
		_sqlite3ErrorMsg(tls, pParse, __ccgo_ts+13664, 0)
		(*TParse)(unsafe.Pointer(pParse)).Frc = int32(SQLITE_AUTH)
	} else {
		if rc != SQLITE_OK && rc != int32(SQLITE_IGNORE) {
			rc = int32(SQLITE_DENY)
			_sqliteAuthBadReturnCode(tls, pParse)
		}
	}
	return rc
}

// C documentation
//
//	/*
//	** The pExpr should be a TK_COLUMN expression.  The table referred to
//	** is in pTabList or else it is the NEW or OLD table of a trigger.
//	** Check to see if it is OK to read this particular column.
//	**
//	** If the auth function returns SQLITE_IGNORE, change the TK_COLUMN
//	** instruction into a TK_NULL.  If the auth function returns SQLITE_DENY,
//	** then generate an error.
//	*/
func _sqlite3AuthRead(tls *libc.TLS, pParse uintptr, pExpr uintptr, pSchema uintptr, pTabList uintptr) {
	var iCol, iDb, iSrc int32
	var pTab, zCol uintptr
	_, _, _, _, _ = iCol, iDb, iSrc, pTab, zCol
	pTab = uintptr(0) /* Index of column in table */
	iDb = _sqlite3SchemaToIndex(tls, (*TParse)(unsafe.Pointer(pParse)).Fdb, pSchema)
	if iDb < 0 {
		/* An attempt to read a column out of a subquery or other
		 ** temporary table. */
		return
	}
	if libc.Int32FromUint8((*TExpr)(unsafe.Pointer(pExpr)).Fop) == int32(TK_TRIGGER) {
		pTab = (*TParse)(unsafe.Pointer(pParse)).FpTriggerTab
	} else {
		iSrc = 0
		for {
			if !(iSrc < (*TSrcList)(unsafe.Pointer(pTabList)).FnSrc) {
				break
			}
			if (*TExpr)(unsafe.Pointer(pExpr)).FiTable == (*(*TSrcItem)(unsafe.Pointer(pTabList + 8 + uintptr(iSrc)*80))).FiCursor {
				pTab = (*(*TSrcItem)(unsafe.Pointer(pTabList + 8 + uintptr(iSrc)*80))).FpSTab
				break
			}
			goto _1
		_1:
			;
			iSrc = iSrc + 1
		}
	}
	iCol = int32((*TExpr)(unsafe.Pointer(pExpr)).FiColumn)
	if pTab == uintptr(0) {
		return
	}
	if iCol >= 0 {
		zCol = (**(**TColumn)(__ccgo_up((*TTable)(unsafe.Pointer(pTab)).FaCol + uintptr(iCol)*16))).FzCnName
	} else {
		if int32((*TTable)(unsafe.Pointer(pTab)).FiPKey) >= 0 {
			zCol = (**(**TColumn)(__ccgo_up((*TTable)(unsafe.Pointer(pTab)).FaCol + uintptr((*TTable)(unsafe.Pointer(pTab)).FiPKey)*16))).FzCnName
		} else {
			zCol = __ccgo_ts + 8190
		}
	}
	if int32(SQLITE_IGNORE) == _sqlite3AuthReadCol(tls, pParse, (*TTable)(unsafe.Pointer(pTab)).FzName, zCol, iDb) {
		(*TExpr)(unsafe.Pointer(pExpr)).Fop = uint8(TK_NULL)
	}
}

// C documentation
//
//	/*
//	** Invoke the authorization callback for permission to read column zCol from
//	** table zTab in database zDb. This function assumes that an authorization
//	** callback has been registered (i.e. that sqlite3.xAuth is not NULL).
//	**
//	** If SQLITE_IGNORE is returned and pExpr is not NULL, then pExpr is changed
//	** to an SQL NULL expression. Otherwise, if pExpr is NULL, then SQLITE_IGNORE
//	** is treated as SQLITE_DENY. In this case an error is left in pParse.
//	*/
func _sqlite3AuthReadCol(tls *libc.TLS, pParse uintptr, zTab uintptr, zCol uintptr, iDb int32) (r int32) {
	bp := tls.Alloc(32)
	defer tls.Free(32)
	var db, z, zDb uintptr
	var rc int32
	_, _, _, _ = db, rc, z, zDb
	db = (*TParse)(unsafe.Pointer(pParse)).Fdb                                                     /* Database handle */
	zDb = (**(**TDb)(__ccgo_up((*Tsqlite3)(unsafe.Pointer(db)).FaDb + uintptr(iDb)*32))).FzDbSName /* Auth callback return code */
	if (*Tsqlite3)(unsafe.Pointer(db)).Finit1.Fbusy != 0 {
		return SQLITE_OK
	}
	rc = (*(*func(*libc.TLS, uintptr, int32, uintptr, uintptr, uintptr, uintptr) int32)(unsafe.Pointer(&struct{ uintptr }{(*Tsqlite3)(unsafe.Pointer(db)).FxAuth})))(tls, (*Tsqlite3)(unsafe.Pointer(db)).FpAuthArg, int32(SQLITE_READ), zTab, zCol, zDb, (*TParse)(unsafe.Pointer(pParse)).FzAuthContext)
	if rc == int32(SQLITE_DENY) {
		z = Xsqlite3_mprintf(tls, __ccgo_ts+13625, libc.VaList(bp+8, zTab, zCol))
		if (*Tsqlite3)(unsafe.Pointer(db)).FnDb > int32(2) || iDb != 0 {
			z = Xsqlite3_mprintf(tls, __ccgo_ts+13631, libc.VaList(bp+8, zDb, z))
		}
		_sqlite3ErrorMsg(tls, pParse, __ccgo_ts+13637, libc.VaList(bp+8, z))
		(*TParse)(unsafe.Pointer(pParse)).Frc = int32(SQLITE_AUTH)
	} else {
		if rc != int32(SQLITE_IGNORE) && rc != SQLITE_OK {
			_sqliteAuthBadReturnCode(tls, pParse)
		}
	}
	return rc
}

// C documentation
//
//	/*
//	** Load all automatic extensions.
//	**
//	** If anything goes wrong, set an error in the database connection.
//	*/
func _sqlite3AutoLoadExtensions(tls *libc.TLS, db uintptr) {
	bp := tls.Alloc(32)
	defer tls.Free(32)
	var go1, rc, v2 int32
	var i Tu32
	var mutex, pThunk uintptr
	var xInit Tsqlite3_loadext_entry
	var v3 bool
	var _ /* zErrmsg at bp+0 */ uintptr
	_, _, _, _, _, _, _, _ = go1, i, mutex, pThunk, rc, xInit, v2, v3
	go1 = int32(1)
	if _sqlite3Autoext.FnExt == uint32(0) {
		/* Common case: early out without every having to acquire a mutex */
		return
	}
	i = uint32(0)
	for {
		if !(go1 != 0) {
			break
		}
		mutex = _sqlite3MutexAlloc(tls, int32(SQLITE_MUTEX_STATIC_MAIN))
		pThunk = uintptr(unsafe.Pointer(&_sqlite3Apis))
		Xsqlite3_mutex_enter(tls, mutex)
		if i >= _sqlite3Autoext.FnExt {
			xInit = uintptr(0)
			go1 = 0
		} else {
			xInit = **(**uintptr)(__ccgo_up(_sqlite3Autoext.FaExt + uintptr(i)*8))
		}
		Xsqlite3_mutex_leave(tls, mutex)
		**(**uintptr)(__ccgo_up(bp)) = uintptr(0)
		if v3 = xInit != 0; v3 {
			v2 = (*(*func(*libc.TLS, uintptr, uintptr, uintptr) int32)(unsafe.Pointer(&struct{ uintptr }{xInit})))(tls, db, bp, pThunk)
			rc = v2
		}
		if v3 && v2 != 0 {
			_sqlite3ErrorWithMsg(tls, db, rc, __ccgo_ts+17734, libc.VaList(bp+16, **(**uintptr)(__ccgo_up(bp))))
			go1 = 0
		}
		Xsqlite3_free(tls, **(**uintptr)(__ccgo_up(bp)))
		goto _1
	_1:
		;
		i = i + 1
	}
}

/************** End of loadext.c *********************************************/
/************** Begin file pragma.c ******************************************/
/*
** 2003 April 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.
**
*************************************************************************
** This file contains code used to implement the PRAGMA command.
 */
/* #include "sqliteInt.h" */

/***************************************************************************
** The "pragma.h" include file is an automatically generated file that
** that includes the PragType_XXXX macro definitions and the aPragmaName[]
** object.  This ensures that the aPragmaName[] table is arranged in
** lexicographical order to facility a binary search of the pragma name.
** Do not edit pragma.h directly.  Edit and rerun the script in at
** ../tool/mkpragmatab.tcl. */
/************** Include pragma.h in the middle of pragma.c *******************/
/************** Begin file pragma.h ******************************************/
/* DO NOT EDIT!
** This file is automatically generated by the script at
** ../tool/mkpragmatab.tcl.  To update the set of pragmas, edit
** that script and rerun it.
 */

/* The various pragma types */

/* Property flags associated with various pragma. */

// C documentation
//
//	/*
//	** Generate VDBE code for a BEGIN statement.
//	*/
func _sqlite3BeginTransaction(tls *libc.TLS, pParse uintptr, type1 int32) {
	var db, pBt, v uintptr
	var eTxnType, i int32
	_, _, _, _, _ = db, eTxnType, i, pBt, v
	db = (*TParse)(unsafe.Pointer(pParse)).Fdb
	if _sqlite3AuthCheck(tls, pParse, int32(SQLITE_TRANSACTION), __ccgo_ts+16096, uintptr(0), uintptr(0)) != 0 {
		return
	}
	v = _sqlite3GetVdbe(tls, pParse)
	if !(v != 0) {
		return
	}
	if type1 != int32(TK_DEFERRED) {
		i = 0
		for {
			if !(i < (*Tsqlite3)(unsafe.Pointer(db)).FnDb) {
				break
			}
			pBt = (**(**TDb)(__ccgo_up((*Tsqlite3)(unsafe.Pointer(db)).FaDb + uintptr(i)*32))).FpBt
			if pBt != 0 && _sqlite3BtreeIsReadonly(tls, pBt) != 0 {
				eTxnType = 0 /* Read txn */
			} else {
				if type1 == int32(TK_EXCLUSIVE) {
					eTxnType = int32(2) /* Exclusive txn */
				} else {
					eTxnType = int32(1) /* Write txn */
				}
			}
			_sqlite3VdbeAddOp2(tls, v, int32(OP_Transaction), i, eTxnType)
			_sqlite3VdbeUsesBtree(tls, v, i)
			goto _1
		_1:
			;
			i = i + 1
		}
	}
	_sqlite3VdbeAddOp0(tls, v, int32(OP_AutoCommit))
}

// C documentation
//
//	/*
//	** This is called by the parser when it sees a CREATE TRIGGER statement
//	** up to the point of the BEGIN before the trigger actions.  A Trigger
//	** structure is generated based on the information available and stored
//	** in pParse->pNewTrigger.  After the trigger actions have been parsed, the
//	** sqlite3FinishTrigger() function is called to complete the trigger
//	** construction process.
//	*/
func _sqlite3BeginTrigger(tls *libc.TLS, pParse uintptr, pName1 uintptr, pName2 uintptr, tr_tm int32, op int32, pColumns uintptr, pTableName uintptr, pWhen uintptr, isTemp int32, noErr int32) {
	bp := tls.Alloc(128)
	defer tls.Free(128)
	var code, iDb, iTabDb, v4 int32
	var db, pTab, pTrigger, zDb, zDbTrig, zName, v1 uintptr
	var _ /* pName at bp+0 */ uintptr
	var _ /* sFix at bp+8 */ TDbFixer
	_, _, _, _, _, _, _, _, _, _, _ = code, db, iDb, iTabDb, pTab, pTrigger, zDb, zDbTrig, zName, v1, v4
	pTrigger = uintptr(0)                      /* Table that the trigger fires off of */
	zName = uintptr(0)                         /* Name of the trigger */
	db = (*TParse)(unsafe.Pointer(pParse)).Fdb /* State vector for the DB fixer */
	/* pName1->z might be NULL, but not pName1 itself */
	if isTemp != 0 {
		/* If TEMP was specified, then the trigger name may not be qualified. */
		if (*TToken)(unsafe.Pointer(pName2)).Fn > uint32(0) {
			_sqlite3ErrorMsg(tls, pParse, __ccgo_ts+21829, 0)
			goto trigger_cleanup
		}
		iDb = int32(1)
		**(**uintptr)(__ccgo_up(bp)) = pName1
	} else {
		/* Figure out the db that the trigger will be created in */
		iDb = _sqlite3TwoPartName(tls, pParse, pName1, pName2, bp)
		if iDb < 0 {
			goto trigger_cleanup
		}
	}
	if !(pTableName != 0) || (*Tsqlite3)(unsafe.Pointer(db)).FmallocFailed != 0 {
		goto trigger_cleanup
	}
	/* A long-standing parser bug is that this syntax was allowed:
	 **
	 **    CREATE TRIGGER attached.demo AFTER INSERT ON attached.tab ....
	 **                                                 ^^^^^^^^
	 **
	 ** To maintain backwards compatibility, ignore the database
	 ** name on pTableName if we are reparsing out of the schema table
	 */
	if (*Tsqlite3)(unsafe.Pointer(db)).Finit1.Fbusy != 0 && iDb != int32(1) {
		_sqlite3DbFree(tls, db, *(*uintptr)(unsafe.Pointer(pTableName + 8 + 72)))
		*(*uintptr)(unsafe.Pointer(pTableName + 8 + 72)) = uintptr(0)
	}
	/* If the trigger name was unqualified, and the table is a temp table,
	 ** then set iDb to 1 to create the trigger in the temporary database.
	 ** If sqlite3SrcListLookup() returns 0, indicating the table does not
	 ** exist, the error is caught by the block below.
	 */
	pTab = _sqlite3SrcListLookup(tls, pParse, pTableName)
	if libc.Int32FromUint8((*Tsqlite3)(unsafe.Pointer(db)).Finit1.Fbusy) == 0 && (*TToken)(unsafe.Pointer(pName2)).Fn == uint32(0) && pTab != 0 && (*TTable)(unsafe.Pointer(pTab)).FpSchema == (**(**TDb)(__ccgo_up((*Tsqlite3)(unsafe.Pointer(db)).FaDb + 1*32))).FpSchema {
		iDb = int32(1)
	}
	/* Ensure the table name matches database name and that the table exists */
	if (*Tsqlite3)(unsafe.Pointer(db)).FmallocFailed != 0 {
		goto trigger_cleanup
	}
	_sqlite3FixInit(tls, bp+8, pParse, iDb, __ccgo_ts+21875, **(**uintptr)(__ccgo_up(bp)))
	if _sqlite3FixSrcList(tls, bp+8, pTableName) != 0 {
		goto trigger_cleanup
	}
	pTab = _sqlite3SrcListLookup(tls, pParse, pTableName)
	if !(pTab != 0) {
		/* The table does not exist. */
		goto trigger_orphan_error
	}
	if libc.Int32FromUint8((*TTable)(unsafe.Pointer(pTab)).FeTabType) == int32(TABTYP_VTAB) {
		_sqlite3ErrorMsg(tls, pParse, __ccgo_ts+21883, 0)
		goto trigger_orphan_error
	}
	if (*TTable)(unsafe.Pointer(pTab)).FtabFlags&uint32(TF_Shadow) != uint32(0) && _sqlite3ReadOnlyShadowTables(tls, db) != 0 {
		_sqlite3ErrorMsg(tls, pParse, __ccgo_ts+21924, 0)
		goto trigger_orphan_error
	}
	/* Check that the trigger name is not reserved and that no trigger of the
	 ** specified name exists */
	zName = _sqlite3NameFromToken(tls, db, **(**uintptr)(__ccgo_up(bp)))
	if zName == uintptr(0) {
		goto trigger_cleanup
	}
	if _sqlite3CheckObjectName(tls, pParse, zName, __ccgo_ts+21875, (*TTable)(unsafe.Pointer(pTab)).FzName) != 0 {
		goto trigger_cleanup
	}
	if !(libc.Int32FromUint8((*TParse)(unsafe.Pointer(pParse)).FeParseMode) >= libc.Int32FromInt32(PARSE_MODE_RENAME)) {
		if _sqlite3HashFind(tls, (**(**TDb)(__ccgo_up((*Tsqlite3)(unsafe.Pointer(db)).FaDb + uintptr(iDb)*32))).FpSchema+56, zName) != 0 {
			if !(noErr != 0) {
				_sqlite3ErrorMsg(tls, pParse, __ccgo_ts+21964, libc.VaList(bp+112, **(**uintptr)(__ccgo_up(bp))))
			} else {
				_sqlite3CodeVerifySchema(tls, pParse, iDb)
			}
			goto trigger_cleanup
		}
	}
	/* NB: The SQLITE_ALLOW_TRIGGERS_ON_SYSTEM_TABLES compile-time option is
	 ** experimental and unsupported. Do not use it unless understand the
	 ** implications and you cannot get by without this capability. */
	/* Do not create a trigger on a system table */
	if Xsqlite3_strnicmp(tls, (*TTable)(unsafe.Pointer(pTab)).FzName, __ccgo_ts+6749, int32(7)) == 0 {
		_sqlite3ErrorMsg(tls, pParse, __ccgo_ts+21990, 0)
		goto trigger_cleanup
	}
	/* INSTEAD of triggers are only for views and views only support INSTEAD
	 ** of triggers.
	 */
	if libc.Int32FromUint8((*TTable)(unsafe.Pointer(pTab)).FeTabType) == int32(TABTYP_VIEW) && tr_tm != int32(TK_INSTEAD) {
		if tr_tm == int32(TK_BEFORE) {
			v1 = __ccgo_ts + 22028
		} else {
			v1 = __ccgo_ts + 22035
		}
		_sqlite3ErrorMsg(tls, pParse, __ccgo_ts+22041, libc.VaList(bp+112, v1, pTableName+8))
		goto trigger_orphan_error
	}
	if !(libc.Int32FromUint8((*TTable)(unsafe.Pointer(pTab)).FeTabType) == libc.Int32FromInt32(TABTYP_VIEW)) && tr_tm == int32(TK_INSTEAD) {
		_sqlite3ErrorMsg(tls, pParse, __ccgo_ts+22078, libc.VaList(bp+112, pTableName+8))
		goto trigger_orphan_error
	}
	if !(libc.Int32FromUint8((*TParse)(unsafe.Pointer(pParse)).FeParseMode) >= libc.Int32FromInt32(PARSE_MODE_RENAME)) {
		iTabDb = _sqlite3SchemaToIndex(tls, db, (*TTable)(unsafe.Pointer(pTab)).FpSchema)
		code = int32(SQLITE_CREATE_TRIGGER)
		zDb = (**(**TDb)(__ccgo_up((*Tsqlite3)(unsafe.Pointer(db)).FaDb + uintptr(iTabDb)*32))).FzDbSName
		if isTemp != 0 {
			v1 = (**(**TDb)(__ccgo_up((*Tsqlite3)(unsafe.Pointer(db)).FaDb + 1*32))).FzDbSName
		} else {
			v1 = zDb
		}
		zDbTrig = v1
		if iTabDb == int32(1) || isTemp != 0 {
			code = int32(SQLITE_CREATE_TEMP_TRIGGER)
		}
		if _sqlite3AuthCheck(tls, pParse, code, zName, (*TTable)(unsafe.Pointer(pTab)).FzName, zDbTrig) != 0 {
			goto trigger_cleanup
		}
		if libc.Bool(!(libc.Int32FromInt32(OMIT_TEMPDB) != 0)) && iTabDb == int32(1) {
			v1 = __ccgo_ts + 6757
		} else {
			v1 = __ccgo_ts + 6277
		}
		if _sqlite3AuthCheck(tls, pParse, int32(SQLITE_INSERT), v1, uintptr(0), zDb) != 0 {
			goto trigger_cleanup
		}
	}
	/* INSTEAD OF triggers can only appear on views and BEFORE triggers
	 ** cannot appear on views.  So we might as well translate every
	 ** INSTEAD OF trigger into a BEFORE trigger.  It simplifies code
	 ** elsewhere.
	 */
	if tr_tm == int32(TK_INSTEAD) {
		tr_tm = int32(TK_BEFORE)
	}
	/* Build the Trigger object */
	pTrigger = _sqlite3DbMallocZero(tls, db, uint64(72))
	if pTrigger == uintptr(0) {
		goto trigger_cleanup
	}
	(*TTrigger)(unsafe.Pointer(pTrigger)).FzName = zName
	zName = uintptr(0)
	(*TTrigger)(unsafe.Pointer(pTrigger)).Ftable = _sqlite3DbStrDup(tls, db, (*(*TSrcItem)(unsafe.Pointer(pTableName + 8))).FzName)
	(*TTrigger)(unsafe.Pointer(pTrigger)).FpSchema = (**(**TDb)(__ccgo_up((*Tsqlite3)(unsafe.Pointer(db)).FaDb + uintptr(iDb)*32))).FpSchema
	(*TTrigger)(unsafe.Pointer(pTrigger)).FpTabSchema = (*TTable)(unsafe.Pointer(pTab)).FpSchema
	(*TTrigger)(unsafe.Pointer(pTrigger)).Fop = libc.Uint8FromInt32(op)
	if tr_tm == int32(TK_BEFORE) {
		v4 = int32(TRIGGER_BEFORE)
	} else {
		v4 = int32(TRIGGER_AFTER)
	}
	(*TTrigger)(unsafe.Pointer(pTrigger)).Ftr_tm = libc.Uint8FromInt32(v4)
	if libc.Int32FromUint8((*TParse)(unsafe.Pointer(pParse)).FeParseMode) >= int32(PARSE_MODE_RENAME) {
		_sqlite3RenameTokenRemap(tls, pParse, (*TTrigger)(unsafe.Pointer(pTrigger)).Ftable, (*(*TSrcItem)(unsafe.Pointer(pTableName + 8))).FzName)
		(*TTrigger)(unsafe.Pointer(pTrigger)).FpWhen = pWhen
		pWhen = uintptr(0)
	} else {
		(*TTrigger)(unsafe.Pointer(pTrigger)).FpWhen = _sqlite3ExprDup(tls, db, pWhen, int32(EXPRDUP_REDUCE))
	}
	(*TTrigger)(unsafe.Pointer(pTrigger)).FpColumns = pColumns
	pColumns = uintptr(0)
	(*TParse)(unsafe.Pointer(pParse)).FpNewTrigger = pTrigger
	goto trigger_cleanup
trigger_cleanup:
	;
	_sqlite3DbFree(tls, db, zName)
	_sqlite3SrcListDelete(tls, db, pTableName)
	_sqlite3IdListDelete(tls, db, pColumns)
	_sqlite3ExprDelete(tls, db, pWhen)
	if !((*TParse)(unsafe.Pointer(pParse)).FpNewTrigger != 0) {
		_sqlite3DeleteTrigger(tls, db, pTrigger)
	} else {
	}
	return
	goto trigger_orphan_error
trigger_orphan_error:
	;
	if libc.Int32FromUint8((*Tsqlite3)(unsafe.Pointer(db)).Finit1.FiDb) == int32(1) {
		/* Ticket #3810.
		 ** Normally, whenever a table is dropped, all associated triggers are
		 ** dropped too.  But if a TEMP trigger is created on a non-TEMP table
		 ** and the table is dropped by a different database connection, the
		 ** trigger is not visible to the database connection that does the
		 ** drop so the trigger cannot be dropped.  This results in an
		 ** "orphaned trigger" - a trigger whose associated table is missing.
		 **
		 ** 2020-11-05 see also https://sqlite.org/forum/forumpost/157dc791df
		 */
		libc.SetBitFieldPtr8Uint32(db+192+8, libc.Uint32FromInt32(1), 0, 0x1)
	}
	goto trigger_cleanup
}

func _sqlite3CantopenError(tls *libc.TLS, lineno int32) (r int32) {
	return _sqlite3ReportError(tls, int32(SQLITE_CANTOPEN), lineno, __ccgo_ts+26312)
}

// C documentation
//
//	/*
//	** This routine is used to check if the UTF-8 string zName is a legal
//	** unqualified name for a new schema object (table, index, view or
//	** trigger). All names are legal except those that begin with the string
//	** "sqlite_" (in upper, lower or mixed case). This portion of the namespace
//	** is reserved for internal use.
//	**
//	** When parsing the sqlite_schema table, this routine also checks to
//	** make sure the "type", "name", and "tbl_name" columns are consistent
//	** with the SQL.
//	*/
func _sqlite3CheckObjectName(tls *libc.TLS, pParse uintptr, zName uintptr, zType uintptr, zTblName uintptr) (r int32) {
	bp := tls.Alloc(16)
	defer tls.Free(16)
	var db uintptr
	_ = db
	db = (*TParse)(unsafe.Pointer(pParse)).Fdb
	if _sqlite3WritableSchema(tls, db) != 0 || int32(uint32(*(*uint8)(unsafe.Pointer(db + 192 + 8))&0x6>>1)) != 0 || !(_sqlite3Config.FbExtraSchemaChecks != 0) {
		/* Skip these error checks for writable_schema=ON */
		return SQLITE_OK
	}
	if (*Tsqlite3)(unsafe.Pointer(db)).Finit1.Fbusy != 0 {
		if Xsqlite3_stricmp(tls, zType, **(**uintptr)(__ccgo_up((*Tsqlite3)(unsafe.Pointer(db)).Finit1.FazInit))) != 0 || Xsqlite3_stricmp(tls, zName, **(**uintptr)(__ccgo_up((*Tsqlite3)(unsafe.Pointer(db)).Finit1.FazInit + 1*8))) != 0 || Xsqlite3_stricmp(tls, zTblName, **(**uintptr)(__ccgo_up((*Tsqlite3)(unsafe.Pointer(db)).Finit1.FazInit + 2*8))) != 0 {
			_sqlite3ErrorMsg(tls, pParse, __ccgo_ts+1693, 0) /* corruptSchema() will supply the error */
			return int32(SQLITE_ERROR)
		}
	} else {
		if libc.Int32FromUint8((*TParse)(unsafe.Pointer(pParse)).Fnested) == 0 && 0 == Xsqlite3_strnicmp(tls, zName, __ccgo_ts+6749, int32(7)) || _sqlite3ReadOnlyShadowTables(tls, db) != 0 && _sqlite3ShadowTableName(tls, db, zName) != 0 {
			_sqlite3ErrorMsg(tls, pParse, __ccgo_ts+13756, libc.VaList(bp+8, zName))
			return int32(SQLITE_ERROR)
		}
	}
	return SQLITE_OK
}

// C documentation
//
//	/*
//	** Close an existing SQLite database
//	*/
func _sqlite3Close(tls *libc.TLS, db uintptr, forceZombie int32) (r int32) {
	var p uintptr
	_ = p
	if !(db != 0) {
		/* EVIDENCE-OF: R-63257-11740 Calling sqlite3_close() or
		 ** sqlite3_close_v2() with a NULL pointer argument is a harmless no-op. */
		return SQLITE_OK
	}
	if !(_sqlite3SafetyCheckSickOrOk(tls, db) != 0) {
		return _sqlite3MisuseError(tls, int32(188636))
	}
	Xsqlite3_mutex_enter(tls, (*Tsqlite3)(unsafe.Pointer(db)).Fmutex)
	if libc.Int32FromUint8((*Tsqlite3)(unsafe.Pointer(db)).FmTrace)&int32(SQLITE_TRACE_CLOSE) != 0 {
		(*(*func(*libc.TLS, Tu32, uintptr, uintptr, uintptr) int32)(unsafe.Pointer(&struct{ uintptr }{*(*uintptr)(unsafe.Pointer(&(*Tsqlite3)(unsafe.Pointer(db)).Ftrace))})))(tls, uint32(SQLITE_TRACE_CLOSE), (*Tsqlite3)(unsafe.Pointer(db)).FpTraceArg, db, uintptr(0))
	}
	/* Force xDisconnect calls on all virtual tables */
	_disconnectAllVtab(tls, db)
	/* If a transaction is open, the disconnectAllVtab() call above
	 ** will not have called the xDisconnect() method on any virtual
	 ** tables in the db->aVTrans[] array. The following sqlite3VtabRollback()
	 ** call will do so. We need to do this before the check for active
	 ** SQL statements below, as the v-table implementation may be storing
	 ** some prepared statements internally.
	 */
	_sqlite3VtabRollback(tls, db)
	/* Legacy behavior (sqlite3_close() behavior) is to return
	 ** SQLITE_BUSY if the connection can not be closed immediately.
	 */
	if !(forceZombie != 0) && _connectionIsBusy(tls, db) != 0 {
		_sqlite3ErrorWithMsg(tls, db, int32(SQLITE_BUSY), __ccgo_ts+25280, 0)
		Xsqlite3_mutex_leave(tls, (*Tsqlite3)(unsafe.Pointer(db)).Fmutex)
		return int32(SQLITE_BUSY)
	}
	for (*Tsqlite3)(unsafe.Pointer(db)).FpDbData != 0 {
		p = (*Tsqlite3)(unsafe.Pointer(db)).FpDbData
		(*Tsqlite3)(unsafe.Pointer(db)).FpDbData = (*TDbClientData)(unsafe.Pointer(p)).FpNext
		if (*TDbClientData)(unsafe.Pointer(p)).FxDestructor != 0 {
			(*(*func(*libc.TLS, uintptr))(unsafe.Pointer(&struct{ uintptr }{(*TDbClientData)(unsafe.Pointer(p)).FxDestructor})))(tls, (*TDbClientData)(unsafe.Pointer(p)).FpData)
		}
		Xsqlite3_free(tls, p)
	}
	/* Convert the connection into a zombie and then close it.
	 */
	(*Tsqlite3)(unsafe.Pointer(db)).FeOpenState = uint8(SQLITE_STATE_ZOMBIE)
	_sqlite3LeaveMutexAndCloseZombie(tls, db)
	return SQLITE_OK
}

// C documentation
//
//	/*
//	** Generate code to drop a table.
//	*/
func _sqlite3CodeDropTable(tls *libc.TLS, pParse uintptr, pTab uintptr, iDb int32, isView int32) {
	bp := tls.Alloc(32)
	defer tls.Free(32)
	var db, pDb, pTrigger, v uintptr
	_, _, _, _ = db, pDb, pTrigger, v
	db = (*TParse)(unsafe.Pointer(pParse)).Fdb
	pDb = (*Tsqlite3)(unsafe.Pointer(db)).FaDb + uintptr(iDb)*32
	v = _sqlite3GetVdbe(tls, pParse)
	_sqlite3BeginWriteOperation(tls, pParse, int32(1), iDb)
	if libc.Int32FromUint8((*TTable)(unsafe.Pointer(pTab)).FeTabType) == int32(TABTYP_VTAB) {
		_sqlite3VdbeAddOp0(tls, v, int32(OP_VBegin))
	}
	/* Drop all triggers associated with the table being dropped. Code
	 ** is generated to remove entries from sqlite_schema and/or
	 ** sqlite_temp_schema if required.
	 */
	pTrigger = _sqlite3TriggerList(tls, pParse, pTab)
	for pTrigger != 0 {
		_sqlite3DropTriggerPtr(tls, pParse, pTrigger)
		pTrigger = (*TTrigger)(unsafe.Pointer(pTrigger)).FpNext
	}
	/* Remove any entries of the sqlite_sequence table associated with
	 ** the table being dropped. This is done before the table is dropped
	 ** at the btree level, in case the sqlite_sequence table needs to
	 ** move as a result of the drop (can happen in auto-vacuum mode).
	 */
	if (*TTable)(unsafe.Pointer(pTab)).FtabFlags&uint32(TF_Autoincrement) != 0 {
		_sqlite3NestedParse(tls, pParse, __ccgo_ts+14958, libc.VaList(bp+8, (*TDb)(unsafe.Pointer(pDb)).FzDbSName, (*TTable)(unsafe.Pointer(pTab)).FzName))
	}
	/* Drop all entries in the schema table that refer to the
	 ** table. The program name loops through the schema table and deletes
	 ** every row that refers to a table of the same name as the one being
	 ** dropped. Triggers are handled separately because a trigger can be
	 ** created in the temp database that refers to a table in another
	 ** database.
	 */
	_sqlite3NestedParse(tls, pParse, __ccgo_ts+15003, libc.VaList(bp+8, (*TDb)(unsafe.Pointer(pDb)).FzDbSName, (*TTable)(unsafe.Pointer(pTab)).FzName))
	if !(isView != 0) && !(libc.Int32FromUint8((*TTable)(unsafe.Pointer(pTab)).FeTabType) == libc.Int32FromInt32(TABTYP_VTAB)) {
		_destroyTable(tls, pParse, pTab)
	}
	/* Remove the table entry from SQLite's internal schema and modify
	 ** the schema cookie.
	 */
	if libc.Int32FromUint8((*TTable)(unsafe.Pointer(pTab)).FeTabType) == int32(TABTYP_VTAB) {
		_sqlite3VdbeAddOp4(tls, v, int32(OP_VDestroy), iDb, 0, 0, (*TTable)(unsafe.Pointer(pTab)).FzName, 0)
		_sqlite3MayAbort(tls, pParse)
	}
	_sqlite3VdbeAddOp4(tls, v, int32(OP_DropTable), iDb, 0, 0, (*TTable)(unsafe.Pointer(pTab)).FzName, 0)
	_sqlite3ChangeCookie(tls, pParse, iDb)
	_sqliteViewResetAll(tls, db, iDb)
}

func _sqlite3CorruptError(tls *libc.TLS, lineno int32) (r int32) {
	return _sqlite3ReportError(tls, int32(SQLITE_CORRUPT), lineno, __ccgo_ts+26285)
}

// C documentation
//
//	/*
//	** This function is exactly the same as sqlite3_create_function(), except
//	** that it is designed to be called by internal code. The difference is
//	** that if a malloc() fails in sqlite3_create_function(), an error code
//	** is returned and the mallocFailed flag cleared.
//	*/
func _sqlite3CreateFunc(tls *libc.TLS, db uintptr, zFunctionName uintptr, nArg int32, enc int32, pUserData uintptr, __ccgo_fp_xSFunc uintptr, __ccgo_fp_xStep uintptr, __ccgo_fp_xFinal uintptr, __ccgo_fp_xValue uintptr, __ccgo_fp_xInverse uintptr, pDestructor uintptr) (r int32) {
	var extraFlags, rc int32
	var p, v1 uintptr
	_, _, _, _ = extraFlags, p, rc, v1
	if zFunctionName == uintptr(0) || __ccgo_fp_xSFunc != uintptr(0) && __ccgo_fp_xFinal != uintptr(0) || libc.BoolInt32(__ccgo_fp_xFinal == uintptr(0)) != libc.BoolInt32(__ccgo_fp_xStep == uintptr(0)) || libc.BoolInt32(__ccgo_fp_xValue == uintptr(0)) != libc.BoolInt32(__ccgo_fp_xInverse == uintptr(0)) || (nArg < -int32(1) || nArg > int32(SQLITE_MAX_FUNCTION_ARG)) || int32(255) < _sqlite3Strlen30(tls, zFunctionName) {
		return _sqlite3MisuseError(tls, int32(189333))
	}
	extraFlags = enc & (libc.Int32FromInt32(SQLITE_DETERMINISTIC) | libc.Int32FromInt32(SQLITE_DIRECTONLY) | libc.Int32FromInt32(SQLITE_SUBTYPE) | libc.Int32FromInt32(SQLITE_INNOCUOUS) | libc.Int32FromInt32(SQLITE_RESULT_SUBTYPE) | libc.Int32FromInt32(SQLITE_SELFORDER1))
	enc = enc & (libc.Int32FromInt32(SQLITE_FUNC_ENCMASK) | libc.Int32FromInt32(SQLITE_ANY))
	/* The SQLITE_INNOCUOUS flag is the same bit as SQLITE_FUNC_UNSAFE.  But
	 ** the meaning is inverted.  So flip the bit. */
	extraFlags = extraFlags ^ int32(SQLITE_FUNC_UNSAFE) /* tag-20230109-1 */
	/* If SQLITE_UTF16 is specified as the encoding type, transform this
	 ** to one of SQLITE_UTF16LE or SQLITE_UTF16BE using the
	 ** SQLITE_UTF16NATIVE macro. SQLITE_UTF16 is not used internally.
	 **
	 ** If SQLITE_ANY is specified, add three versions of the function
	 ** to the hash table.
	 */
	switch enc {
	case int32(SQLITE_UTF16):
		enc = int32(SQLITE_UTF16LE)
	case int32(SQLITE_ANY):
		rc = _sqlite3CreateFunc(tls, db, zFunctionName, nArg, int32(SQLITE_UTF8)|extraFlags^int32(SQLITE_FUNC_UNSAFE), pUserData, __ccgo_fp_xSFunc, __ccgo_fp_xStep, __ccgo_fp_xFinal, __ccgo_fp_xValue, __ccgo_fp_xInverse, pDestructor)
		if rc == SQLITE_OK {
			rc = _sqlite3CreateFunc(tls, db, zFunctionName, nArg, int32(SQLITE_UTF16LE)|extraFlags^int32(SQLITE_FUNC_UNSAFE), pUserData, __ccgo_fp_xSFunc, __ccgo_fp_xStep, __ccgo_fp_xFinal, __ccgo_fp_xValue, __ccgo_fp_xInverse, pDestructor)
		}
		if rc != SQLITE_OK {
			return rc
		}
		enc = int32(SQLITE_UTF16BE)
	case int32(SQLITE_UTF8):
		fallthrough
	case int32(SQLITE_UTF16LE):
		fallthrough
	case int32(SQLITE_UTF16BE):
	default:
		enc = int32(SQLITE_UTF8)
		break
	}
	/* Check if an existing function is being overridden or deleted. If so,
	 ** and there are active VMs, then return SQLITE_BUSY. If a function
	 ** is being overridden/deleted but there are no active VMs, allow the
	 ** operation to continue but invalidate all precompiled statements.
	 */
	p = _sqlite3FindFunction(tls, db, zFunctionName, nArg, libc.Uint8FromInt32(enc), uint8(0))
	if p != 0 && (*TFuncDef)(unsafe.Pointer(p)).FfuncFlags&uint32(SQLITE_FUNC_ENCMASK) == libc.Uint32FromInt32(enc) && int32((*TFuncDef)(unsafe.Pointer(p)).FnArg) == nArg {
		if (*Tsqlite3)(unsafe.Pointer(db)).FnVdbeActive != 0 {
			_sqlite3ErrorWithMsg(tls, db, int32(SQLITE_BUSY), __ccgo_ts+25904, 0)
			return int32(SQLITE_BUSY)
		} else {
			_sqlite3ExpirePreparedStatements(tls, db, 0)
		}
	} else {
		if __ccgo_fp_xSFunc == uintptr(0) && __ccgo_fp_xFinal == uintptr(0) {
			/* Trying to delete a function that does not exist.  This is a no-op.
			 ** https://sqlite.org/forum/forumpost/726219164b */
			return SQLITE_OK
		}
	}
	p = _sqlite3FindFunction(tls, db, zFunctionName, nArg, libc.Uint8FromInt32(enc), uint8(1))
	if !(p != 0) {
		return int32(SQLITE_NOMEM)
	}
	/* If an older version of the function with a configured destructor is
	 ** being replaced invoke the destructor function here. */
	_functionDestroy(tls, db, p)
	if pDestructor != 0 {
		(*TFuncDestructor)(unsafe.Pointer(pDestructor)).FnRef = (*TFuncDestructor)(unsafe.Pointer(pDestructor)).FnRef + 1
	}
	*(*uintptr)(unsafe.Pointer(p + 64)) = pDestructor
	(*TFuncDef)(unsafe.Pointer(p)).FfuncFlags = (*TFuncDef)(unsafe.Pointer(p)).FfuncFlags&uint32(SQLITE_FUNC_ENCMASK) | libc.Uint32FromInt32(extraFlags)
	if __ccgo_fp_xSFunc != 0 {
		v1 = __ccgo_fp_xSFunc
	} else {
		v1 = __ccgo_fp_xStep
	}
	(*TFuncDef)(unsafe.Pointer(p)).FxSFunc = v1
	(*TFuncDef)(unsafe.Pointer(p)).FxFinalize = __ccgo_fp_xFinal
	(*TFuncDef)(unsafe.Pointer(p)).FxValue = __ccgo_fp_xValue
	(*TFuncDef)(unsafe.Pointer(p)).FxInverse = __ccgo_fp_xInverse
	(*TFuncDef)(unsafe.Pointer(p)).FpUserData = pUserData
	(*TFuncDef)(unsafe.Pointer(p)).FnArg = libc.Int16FromUint16(libc.Uint16FromInt32(nArg))
	return SQLITE_OK
}

// C documentation
//
//	/*
//	** Return true if zName points to a name that may be used to refer to
//	** database iDb attached to handle db.
//	*/
func _sqlite3DbIsNamed(tls *libc.TLS, db uintptr, iDb int32, zName uintptr) (r int32) {
	return libc.BoolInt32(_sqlite3StrICmp(tls, (**(**TDb)(__ccgo_up((*Tsqlite3)(unsafe.Pointer(db)).FaDb + uintptr(iDb)*32))).FzDbSName, zName) == 0 || iDb == 0 && _sqlite3StrICmp(tls, __ccgo_ts+6809, zName) == 0)
}

// C documentation
//
//	/*
//	** Invoke this routine to register the "dbpage" virtual table module
//	*/
func _sqlite3DbpageRegister(tls *libc.TLS, db uintptr) (r int32) {
	return Xsqlite3_create_module(tls, db, __ccgo_ts+35169, uintptr(unsafe.Pointer(&_dbpage_module)), uintptr(0))
}

// C documentation
//
//	/*
//	** Invoke this routine to register the "dbstat" virtual table module
//	*/
func _sqlite3DbstatRegister(tls *libc.TLS, db uintptr) (r int32) {
	return Xsqlite3_create_module(tls, db, __ccgo_ts+34984, uintptr(unsafe.Pointer(&_dbstat_module)), uintptr(0))
}

// C documentation
//
//	/*
//	** Generate code for a DELETE FROM statement.
//	**
//	**     DELETE FROM table_wxyz WHERE a<5 AND b NOT NULL;
//	**                 \________/       \________________/
//	**                  pTabList              pWhere
//	*/
func _sqlite3DeleteFrom(tls *libc.TLS, pParse uintptr, pTabList uintptr, pWhere uintptr, pOrderBy uintptr, pLimit uintptr) {
	bp := tls.Alloc(96)
	defer tls.Free(96)
	var aToOpen, db, pIdx, pPk, pTab, pTrigger, pVTab, pWInfo, v, v3 uintptr
	var addrBypass, addrEphOpen, addrLoop, bComplex, count, eOnePass, i, iAddrOnce, iDb, iEphCur, iKey, iPk, iRowSet, iTabCur, isView, memCnt, nIdx, rcauth, v1, v2 int32
	var nKey, nPk Ti16
	var wcf Tu16
	var _ /* aiCurOnePass at bp+80 */ [2]int32
	var _ /* iDataCur at bp+0 */ int32
	var _ /* iIdxCur at bp+4 */ int32
	var _ /* sContext at bp+8 */ TAuthContext
	var _ /* sNC at bp+24 */ TNameContext
	_, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _ = aToOpen, addrBypass, addrEphOpen, addrLoop, bComplex, count, db, eOnePass, i, iAddrOnce, iDb, iEphCur, iKey, iPk, iRowSet, iTabCur, isView, memCnt, nIdx, nKey, nPk, pIdx, pPk, pTab, pTrigger, pVTab, pWInfo, rcauth, v, wcf, v1, v2, v3 /* Cursor number for the table */
	**(**int32)(__ccgo_up(bp)) = 0                                                                                                                                                                                                                                                                                                                /* VDBE cursor for the canonical data source */
	**(**int32)(__ccgo_up(bp + 4)) = 0                                                                                                                                                                                                                                                                                                            /* Database number */
	memCnt = 0                                                                                                                                                                                                                                                                                                                                    /* The write cursors opened by WHERE_ONEPASS */
	aToOpen = uintptr(0)                                                                                                                                                                                                                                                                                                                          /* The PRIMARY KEY index on the table */
	iPk = 0                                                                                                                                                                                                                                                                                                                                       /* First of nPk registers holding PRIMARY KEY value */
	nPk = int16(1)                                                                                                                                                                                                                                                                                                                                /* Number of memory cells in the row key */
	iEphCur = 0                                                                                                                                                                                                                                                                                                                                   /* Ephemeral table holding all primary key values */
	iRowSet = 0                                                                                                                                                                                                                                                                                                                                   /* Register for rowset of rows to delete */
	addrBypass = 0                                                                                                                                                                                                                                                                                                                                /* Address of jump over the delete logic */
	addrLoop = 0                                                                                                                                                                                                                                                                                                                                  /* Top of the delete loop */
	addrEphOpen = 0                                                                                                                                                                                                                                                                                                                               /* List of table triggers, if required */
	libc.Xmemset(tls, bp+8, 0, uint64(16))
	db = (*TParse)(unsafe.Pointer(pParse)).Fdb
	if (*TParse)(unsafe.Pointer(pParse)).FnErr != 0 {
		goto delete_from_cleanup
	}
	/* Locate the table which we want to delete.  This table has to be
	 ** put in an SrcList structure because some of the subroutines we
	 ** will be calling are designed to work with multiple tables and expect
	 ** an SrcList* parameter instead of just a Table* parameter.
	 */
	pTab = _sqlite3SrcListLookup(tls, pParse, pTabList)
	if pTab == uintptr(0) {
		goto delete_from_cleanup
	}
	/* Figure out if we have any triggers and if the table being
	 ** deleted from is a view
	 */
	pTrigger = _sqlite3TriggersExist(tls, pParse, pTab, int32(TK_DELETE), uintptr(0), uintptr(0))
	isView = libc.BoolInt32(libc.Int32FromUint8((*TTable)(unsafe.Pointer(pTab)).FeTabType) == int32(TABTYP_VIEW))
	bComplex = libc.BoolInt32(pTrigger != 0 || _sqlite3FkRequired(tls, pParse, pTab, uintptr(0), 0) != 0)
	/* If pTab is really a view, make sure it has been initialized.
	 */
	if _sqlite3ViewGetColumnNames(tls, pParse, pTab) != 0 {
		goto delete_from_cleanup
	}
	if _sqlite3IsReadOnly(tls, pParse, pTab, pTrigger) != 0 {
		goto delete_from_cleanup
	}
	iDb = _sqlite3SchemaToIndex(tls, db, (*TTable)(unsafe.Pointer(pTab)).FpSchema)
	rcauth = _sqlite3AuthCheck(tls, pParse, int32(SQLITE_DELETE), (*TTable)(unsafe.Pointer(pTab)).FzName, uintptr(0), (**(**TDb)(__ccgo_up((*Tsqlite3)(unsafe.Pointer(db)).FaDb + uintptr(iDb)*32))).FzDbSName)
	if rcauth == int32(SQLITE_DENY) {
		goto delete_from_cleanup
	}
	/* Assign cursor numbers to the table and all its indices.
	 */
	v3 = pParse + 56
	v2 = *(*int32)(unsafe.Pointer(v3))
	*(*int32)(unsafe.Pointer(v3)) = *(*int32)(unsafe.Pointer(v3)) + 1
	v1 = v2
	(*(*TSrcItem)(unsafe.Pointer(pTabList + 8))).FiCursor = v1
	iTabCur = v1
	nIdx = 0
	pIdx = (*TTable)(unsafe.Pointer(pTab)).FpIndex
	for {
		if !(pIdx != 0) {
			break
		}
		(*TParse)(unsafe.Pointer(pParse)).FnTab = (*TParse)(unsafe.Pointer(pParse)).FnTab + 1
		goto _4
	_4:
		;
		pIdx = (*TIndex)(unsafe.Pointer(pIdx)).FpNext
		nIdx = nIdx + 1
	}
	/* Start the view context
	 */
	if isView != 0 {
		_sqlite3AuthContextPush(tls, pParse, bp+8, (*TTable)(unsafe.Pointer(pTab)).FzName)
	}
	/* Begin generating code.
	 */
	v = _sqlite3GetVdbe(tls, pParse)
	if v == uintptr(0) {
		goto delete_from_cleanup
	}
	if libc.Int32FromUint8((*TParse)(unsafe.Pointer(pParse)).Fnested) == 0 {
		_sqlite3VdbeCountChanges(tls, v)
	}
	_sqlite3BeginWriteOperation(tls, pParse, bComplex, iDb)
	/* If we are trying to delete from a view, realize that view into
	 ** an ephemeral table.
	 */
	if isView != 0 {
		_sqlite3MaterializeView(tls, pParse, pTab, pWhere, pOrderBy, pLimit, iTabCur)
		v1 = iTabCur
		**(**int32)(__ccgo_up(bp + 4)) = v1
		**(**int32)(__ccgo_up(bp)) = v1
		pOrderBy = uintptr(0)
		pLimit = uintptr(0)
	}
	/* Resolve the column names in the WHERE clause.
	 */
	libc.Xmemset(tls, bp+24, 0, uint64(56))
	(**(**TNameContext)(__ccgo_up(bp + 24))).FpParse = pParse
	(**(**TNameContext)(__ccgo_up(bp + 24))).FpSrcList = pTabList
	if _sqlite3ResolveExprNames(tls, bp+24, pWhere) != 0 {
		goto delete_from_cleanup
	}
	/* Initialize the counter of the number of rows deleted, if
	 ** we are counting rows.
	 */
	if (*Tsqlite3)(unsafe.Pointer(db)).Fflags&(libc.Uint64FromInt32(libc.Int32FromInt32(0x00001))<<libc.Int32FromInt32(32)) != uint64(0) && !((*TParse)(unsafe.Pointer(pParse)).Fnested != 0) && !((*TParse)(unsafe.Pointer(pParse)).FpTriggerTab != 0) && !(int32(Tbft(*(*uint16)(unsafe.Pointer(pParse + 40))&0x8>>3)) != 0) {
		v3 = pParse + 60
		*(*int32)(unsafe.Pointer(v3)) = *(*int32)(unsafe.Pointer(v3)) + 1
		v1 = *(*int32)(unsafe.Pointer(v3))
		memCnt = v1
		_sqlite3VdbeAddOp2(tls, v, int32(OP_Integer), 0, memCnt)
	}
	/* Special case: A DELETE without a WHERE clause deletes everything.
	 ** It is easier just to erase the whole table. Prior to version 3.6.5,
	 ** this optimization caused the row change count (the value returned by
	 ** API function sqlite3_count_changes) to be set incorrectly.
	 **
	 ** The "rcauth==SQLITE_OK" terms is the
	 ** IMPLEMENTATION-OF: R-17228-37124 If the action code is SQLITE_DELETE and
	 ** the callback returns SQLITE_IGNORE then the DELETE operation proceeds but
	 ** the truncate optimization is disabled and all rows are deleted
	 ** individually.
	 */
	if rcauth == SQLITE_OK && pWhere == uintptr(0) && !(bComplex != 0) && !(libc.Int32FromUint8((*TTable)(unsafe.Pointer(pTab)).FeTabType) == libc.Int32FromInt32(TABTYP_VTAB)) && (*Tsqlite3)(unsafe.Pointer(db)).FxPreUpdateCallback == uintptr(0) {
		_sqlite3TableLock(tls, pParse, iDb, (*TTable)(unsafe.Pointer(pTab)).Ftnum, uint8(1), (*TTable)(unsafe.Pointer(pTab)).FzName)
		if (*TTable)(unsafe.Pointer(pTab)).FtabFlags&uint32(TF_WithoutRowid) == uint32(0) {
			if memCnt != 0 {
				v1 = memCnt
			} else {
				v1 = -int32(1)
			}
			_sqlite3VdbeAddOp4(tls, v, int32(OP_Clear), libc.Int32FromUint32((*TTable)(unsafe.Pointer(pTab)).Ftnum), iDb, v1, (*TTable)(unsafe.Pointer(pTab)).FzName, -int32(1))
		}
		pIdx = (*TTable)(unsafe.Pointer(pTab)).FpIndex
		for {
			if !(pIdx != 0) {
				break
			}
			if int32(uint32(*(*uint16)(unsafe.Pointer(pIdx + 100))&0x3>>0)) == int32(SQLITE_IDXTYPE_PRIMARYKEY) && !((*TTable)(unsafe.Pointer(pTab)).FtabFlags&libc.Uint32FromInt32(TF_WithoutRowid) == libc.Uint32FromInt32(0)) {
				if memCnt != 0 {
					v1 = memCnt
				} else {
					v1 = -int32(1)
				}
				_sqlite3VdbeAddOp3(tls, v, int32(OP_Clear), libc.Int32FromUint32((*TIndex)(unsafe.Pointer(pIdx)).Ftnum), iDb, v1)
			} else {
				_sqlite3VdbeAddOp2(tls, v, int32(OP_Clear), libc.Int32FromUint32((*TIndex)(unsafe.Pointer(pIdx)).Ftnum), iDb)
			}
			goto _9
		_9:
			;
			pIdx = (*TIndex)(unsafe.Pointer(pIdx)).FpNext
		}
	} else {
		wcf = libc.Uint16FromInt32(libc.Int32FromInt32(WHERE_ONEPASS_DESIRED) | libc.Int32FromInt32(WHERE_DUPLICATES_OK))
		if (**(**TNameContext)(__ccgo_up(bp + 24))).FncFlags&int32(NC_Subquery) != 0 {
			bComplex = int32(1)
		}
		if bComplex != 0 {
			v1 = 0
		} else {
			v1 = int32(WHERE_ONEPASS_MULTIROW)
		}
		wcf = libc.Uint16FromInt32(int32(wcf) | v1)
		if (*TTable)(unsafe.Pointer(pTab)).FtabFlags&uint32(TF_WithoutRowid) == uint32(0) {
			/* For a rowid table, initialize the RowSet to an empty set */
			pPk = uintptr(0)
			v3 = pParse + 60
			*(*int32)(unsafe.Pointer(v3)) = *(*int32)(unsafe.Pointer(v3)) + 1
			v1 = *(*int32)(unsafe.Pointer(v3))
			iRowSet = v1
			_sqlite3VdbeAddOp2(tls, v, int32(OP_Null), 0, iRowSet)
		} else {
			/* For a WITHOUT ROWID table, create an ephemeral table used to
			 ** hold all primary keys for rows to be deleted. */
			pPk = _sqlite3PrimaryKeyIndex(tls, pTab)
			nPk = libc.Int16FromUint16((*TIndex)(unsafe.Pointer(pPk)).FnKeyCol)
			iPk = (*TParse)(unsafe.Pointer(pParse)).FnMem + int32(1)
			**(**int32)(__ccgo_up(pParse + 60)) += int32(nPk)
			v3 = pParse + 56
			v1 = *(*int32)(unsafe.Pointer(v3))
			*(*int32)(unsafe.Pointer(v3)) = *(*int32)(unsafe.Pointer(v3)) + 1
			iEphCur = v1
			addrEphOpen = _sqlite3VdbeAddOp2(tls, v, int32(OP_OpenEphemeral), iEphCur, int32(nPk))
			_sqlite3VdbeSetP4KeyInfo(tls, pParse, pPk)
		}
		/* Construct a query to find the rowid or primary key for every row
		 ** to be deleted, based on the WHERE clause. Set variable eOnePass
		 ** to indicate the strategy used to implement this delete:
		 **
		 **  ONEPASS_OFF:    Two-pass approach - use a FIFO for rowids/PK values.
		 **  ONEPASS_SINGLE: One-pass approach - at most one row deleted.
		 **  ONEPASS_MULTI:  One-pass approach - any number of rows may be deleted.
		 */
		pWInfo = _sqlite3WhereBegin(tls, pParse, pTabList, pWhere, uintptr(0), uintptr(0), uintptr(0), wcf, iTabCur+int32(1))
		if pWInfo == uintptr(0) {
			goto delete_from_cleanup
		}
		eOnePass = _sqlite3WhereOkOnePass(tls, pWInfo, bp+80)
		if eOnePass != int32(ONEPASS_SINGLE) {
			_sqlite3MultiWrite(tls, pParse)
		}
		if _sqlite3WhereUsesDeferredSeek(tls, pWInfo) != 0 {
			_sqlite3VdbeAddOp1(tls, v, int32(OP_FinishSeek), iTabCur)
		}
		/* Keep track of the number of rows to be deleted */
		if memCnt != 0 {
			_sqlite3VdbeAddOp2(tls, v, int32(OP_AddImm), memCnt, int32(1))
		}
		/* Extract the rowid or primary key for the current row */
		if pPk != 0 {
			i = 0
			for {
				if !(i < int32(nPk)) {
					break
				}
				_sqlite3ExprCodeGetColumnOfTable(tls, v, pTab, iTabCur, int32(**(**Ti16)(__ccgo_up((*TIndex)(unsafe.Pointer(pPk)).FaiColumn + uintptr(i)*2))), iPk+i)
				goto _16
			_16:
				;
				i = i + 1
			}
			iKey = iPk
		} else {
			v3 = pParse + 60
			*(*int32)(unsafe.Pointer(v3)) = *(*int32)(unsafe.Pointer(v3)) + 1
			v1 = *(*int32)(unsafe.Pointer(v3))
			iKey = v1
			_sqlite3ExprCodeGetColumnOfTable(tls, v, pTab, iTabCur, -int32(1), iKey)
		}
		if eOnePass != ONEPASS_OFF {
			/* For ONEPASS, no need to store the rowid/primary-key. There is only
			 ** one, so just keep it in its register(s) and fall through to the
			 ** delete code.  */
			nKey = nPk /* OP_Found will use an unpacked key */
			aToOpen = _sqlite3DbMallocRawNN(tls, db, libc.Uint64FromInt32(nIdx+int32(2)))
			if aToOpen == uintptr(0) {
				_sqlite3WhereEnd(tls, pWInfo)
				goto delete_from_cleanup
			}
			libc.Xmemset(tls, aToOpen, int32(1), libc.Uint64FromInt32(nIdx+int32(1)))
			**(**Tu8)(__ccgo_up(aToOpen + uintptr(nIdx+int32(1)))) = uint8(0)
			if (**(**[2]int32)(__ccgo_up(bp + 80)))[0] >= 0 {
				**(**Tu8)(__ccgo_up(aToOpen + uintptr((**(**[2]int32)(__ccgo_up(bp + 80)))[0]-iTabCur))) = uint8(0)
			}
			if (**(**[2]int32)(__ccgo_up(bp + 80)))[int32(1)] >= 0 {
				**(**Tu8)(__ccgo_up(aToOpen + uintptr((**(**[2]int32)(__ccgo_up(bp + 80)))[int32(1)]-iTabCur))) = uint8(0)
			}
			if addrEphOpen != 0 {
				_sqlite3VdbeChangeToNoop(tls, v, addrEphOpen)
			}
			addrBypass = _sqlite3VdbeMakeLabel(tls, pParse)
		} else {
			if pPk != 0 {
				/* Add the PK key for this row to the temporary table */
				v3 = pParse + 60
				*(*int32)(unsafe.Pointer(v3)) = *(*int32)(unsafe.Pointer(v3)) + 1
				v1 = *(*int32)(unsafe.Pointer(v3))
				iKey = v1
				nKey = 0 /* Zero tells OP_Found to use a composite key */
				_sqlite3VdbeAddOp4(tls, v, int32(OP_MakeRecord), iPk, int32(nPk), iKey, _sqlite3IndexAffinityStr(tls, (*TParse)(unsafe.Pointer(pParse)).Fdb, pPk), int32(nPk))
				_sqlite3VdbeAddOp4Int(tls, v, int32(OP_IdxInsert), iEphCur, iKey, iPk, int32(nPk))
			} else {
				/* Add the rowid of the row to be deleted to the RowSet */
				nKey = int16(1) /* OP_DeferredSeek always uses a single rowid */
				_sqlite3VdbeAddOp2(tls, v, int32(OP_RowSetAdd), iRowSet, iKey)
			}
			_sqlite3WhereEnd(tls, pWInfo)
		}
		/* Unless this is a view, open cursors for the table we are
		 ** deleting from and all its indices. If this is a view, then the
		 ** only effect this statement has is to fire the INSTEAD OF
		 ** triggers.
		 */
		if !(isView != 0) {
			iAddrOnce = 0
			if eOnePass == int32(ONEPASS_MULTI) {
				iAddrOnce = _sqlite3VdbeAddOp0(tls, v, int32(OP_Once))
			}
			_sqlite3OpenTableAndIndices(tls, pParse, pTab, int32(OP_OpenWrite), uint8(OPFLAG_FORDELETE), iTabCur, aToOpen, bp, bp+4)
			if eOnePass == int32(ONEPASS_MULTI) {
				_sqlite3VdbeJumpHereOrPopInst(tls, v, iAddrOnce)
			}
		}
		/* Set up a loop over the rowids/primary-keys that were found in the
		 ** where-clause loop above.
		 */
		if eOnePass != ONEPASS_OFF {
			/* OP_Found will use an unpacked key */
			if !(libc.Int32FromUint8((*TTable)(unsafe.Pointer(pTab)).FeTabType) == libc.Int32FromInt32(TABTYP_VTAB)) && **(**Tu8)(__ccgo_up(aToOpen + uintptr(**(**int32)(__ccgo_up(bp))-iTabCur))) != 0 {
				_sqlite3VdbeAddOp4Int(tls, v, int32(OP_NotFound), **(**int32)(__ccgo_up(bp)), addrBypass, iKey, int32(nKey))
			}
		} else {
			if pPk != 0 {
				addrLoop = _sqlite3VdbeAddOp1(tls, v, int32(OP_Rewind), iEphCur)
				if libc.Int32FromUint8((*TTable)(unsafe.Pointer(pTab)).FeTabType) == int32(TABTYP_VTAB) {
					_sqlite3VdbeAddOp3(tls, v, int32(OP_Column), iEphCur, 0, iKey)
				} else {
					_sqlite3VdbeAddOp2(tls, v, int32(OP_RowData), iEphCur, iKey)
				}
				/* OP_Found will use a composite key */
			} else {
				addrLoop = _sqlite3VdbeAddOp3(tls, v, int32(OP_RowSetRead), iRowSet, 0, iKey)
			}
		}
		/* Delete the row */
		if libc.Int32FromUint8((*TTable)(unsafe.Pointer(pTab)).FeTabType) == int32(TABTYP_VTAB) {
			pVTab = _sqlite3GetVTable(tls, db, pTab)
			_sqlite3VtabMakeWritable(tls, pParse, pTab)
			_sqlite3MayAbort(tls, pParse)
			if eOnePass == int32(ONEPASS_SINGLE) {
				_sqlite3VdbeAddOp1(tls, v, int32(OP_Close), iTabCur)
				if (*TParse)(unsafe.Pointer(pParse)).FpToplevel == uintptr(0) {
					(*TParse)(unsafe.Pointer(pParse)).FisMultiWrite = uint8(0)
				}
			}
			_sqlite3VdbeAddOp4(tls, v, int32(OP_VUpdate), 0, int32(1), iKey, pVTab, -int32(12))
			_sqlite3VdbeChangeP5(tls, v, uint16(OE_Abort))
		} else {
			count = libc.BoolInt32(libc.Int32FromUint8((*TParse)(unsafe.Pointer(pParse)).Fnested) == 0) /* True to count changes */
			_sqlite3GenerateRowDelete(tls, pParse, pTab, pTrigger, **(**int32)(__ccgo_up(bp)), **(**int32)(__ccgo_up(bp + 4)), iKey, nKey, libc.Uint8FromInt32(count), uint8(OE_Default), libc.Uint8FromInt32(eOnePass), (**(**[2]int32)(__ccgo_up(bp + 80)))[int32(1)])
		}
		/* End of the loop over all rowids/primary-keys. */
		if eOnePass != ONEPASS_OFF {
			_sqlite3VdbeResolveLabel(tls, v, addrBypass)
			_sqlite3WhereEnd(tls, pWInfo)
		} else {
			if pPk != 0 {
				_sqlite3VdbeAddOp2(tls, v, int32(OP_Next), iEphCur, addrLoop+int32(1))
				_sqlite3VdbeJumpHere(tls, v, addrLoop)
			} else {
				_sqlite3VdbeGoto(tls, v, addrLoop)
				_sqlite3VdbeJumpHere(tls, v, addrLoop)
			}
		}
	} /* End non-truncate path */
	/* Update the sqlite_sequence table by storing the content of the
	 ** maximum rowid counter values recorded while inserting into
	 ** autoincrement tables.
	 */
	if libc.Int32FromUint8((*TParse)(unsafe.Pointer(pParse)).Fnested) == 0 && (*TParse)(unsafe.Pointer(pParse)).FpTriggerTab == uintptr(0) {
		_sqlite3AutoincrementEnd(tls, pParse)
	}
	/* Return the number of rows that were deleted. If this routine is
	 ** generating code because of a call to sqlite3NestedParse(), do not
	 ** invoke the callback function.
	 */
	if memCnt != 0 {
		_sqlite3CodeChangeCount(tls, v, memCnt, __ccgo_ts+16438)
	}
	goto delete_from_cleanup
delete_from_cleanup:
	;
	_sqlite3AuthContextPop(tls, bp+8)
	_sqlite3SrcListDelete(tls, db, pTabList)
	_sqlite3ExprDelete(tls, db, pWhere)
	if aToOpen != 0 {
		_sqlite3DbNNFreeNN(tls, db, aToOpen)
	}
	return
}

/* Make sure "isView" and other macros defined above are undefined. Otherwise
** they may interfere with compilation of other functions in this file
** (or in another file, if this file becomes part of the amalgamation).  */

// C documentation
//
//	/*
//	** This routine will drop an existing named index.  This routine
//	** implements the DROP INDEX statement.
//	*/
func _sqlite3DropIndex(tls *libc.TLS, pParse uintptr, pName uintptr, ifExists int32) {
	bp := tls.Alloc(32)
	defer tls.Free(32)
	var code, iDb int32
	var db, pIndex, pTab, v, zDb, zTab, v1 uintptr
	_, _, _, _, _, _, _, _, _ = code, db, iDb, pIndex, pTab, v, zDb, zTab, v1
	db = (*TParse)(unsafe.Pointer(pParse)).Fdb
	if (*Tsqlite3)(unsafe.Pointer(db)).FmallocFailed != 0 {
		goto exit_drop_index
	}
	/* Never called with prior non-OOM errors */
	if SQLITE_OK != _sqlite3ReadSchema(tls, pParse) {
		goto exit_drop_index
	}
	pIndex = _sqlite3FindIndex(tls, db, (*(*TSrcItem)(unsafe.Pointer(pName + 8))).FzName, *(*uintptr)(unsafe.Pointer(pName + 8 + 72)))
	if pIndex == uintptr(0) {
		if !(ifExists != 0) {
			_sqlite3ErrorMsg(tls, pParse, __ccgo_ts+15864, libc.VaList(bp+8, pName+8))
		} else {
			_sqlite3CodeVerifyNamedSchema(tls, pParse, *(*uintptr)(unsafe.Pointer(pName + 8 + 72)))
			_sqlite3ForceNotReadOnly(tls, pParse)
		}
		libc.SetBitFieldPtr16Uint32(pParse+40, libc.Uint32FromInt32(1), 8, 0x100)
		goto exit_drop_index
	}
	if int32(uint32(*(*uint16)(unsafe.Pointer(pIndex + 100))&0x3>>0)) != SQLITE_IDXTYPE_APPDEF {
		_sqlite3ErrorMsg(tls, pParse, __ccgo_ts+15882, libc.VaList(bp+8, 0))
		goto exit_drop_index
	}
	iDb = _sqlite3SchemaToIndex(tls, db, (*TIndex)(unsafe.Pointer(pIndex)).FpSchema)
	code = int32(SQLITE_DROP_INDEX)
	pTab = (*TIndex)(unsafe.Pointer(pIndex)).FpTable
	zDb = (**(**TDb)(__ccgo_up((*Tsqlite3)(unsafe.Pointer(db)).FaDb + uintptr(iDb)*32))).FzDbSName
	if libc.Bool(!(libc.Int32FromInt32(OMIT_TEMPDB) != 0)) && iDb == int32(1) {
		v1 = __ccgo_ts + 6757
	} else {
		v1 = __ccgo_ts + 6277
	}
	zTab = v1
	if _sqlite3AuthCheck(tls, pParse, int32(SQLITE_DELETE), zTab, uintptr(0), zDb) != 0 {
		goto exit_drop_index
	}
	if libc.Bool(!(libc.Int32FromInt32(OMIT_TEMPDB) != 0)) && iDb == int32(1) {
		code = int32(SQLITE_DROP_TEMP_INDEX)
	}
	if _sqlite3AuthCheck(tls, pParse, code, (*TIndex)(unsafe.Pointer(pIndex)).FzName, (*TTable)(unsafe.Pointer(pTab)).FzName, zDb) != 0 {
		goto exit_drop_index
	}
	/* Generate code to remove the index and from the schema table */
	v = _sqlite3GetVdbe(tls, pParse)
	if v != 0 {
		_sqlite3BeginWriteOperation(tls, pParse, int32(1), iDb)
		_sqlite3NestedParse(tls, pParse, __ccgo_ts+15955, libc.VaList(bp+8, (**(**TDb)(__ccgo_up((*Tsqlite3)(unsafe.Pointer(db)).FaDb + uintptr(iDb)*32))).FzDbSName, (*TIndex)(unsafe.Pointer(pIndex)).FzName))
		_sqlite3ClearStatTables(tls, pParse, iDb, __ccgo_ts+13037, (*TIndex)(unsafe.Pointer(pIndex)).FzName)
		_sqlite3ChangeCookie(tls, pParse, iDb)
		_destroyRootPage(tls, pParse, libc.Int32FromUint32((*TIndex)(unsafe.Pointer(pIndex)).Ftnum), iDb)
		_sqlite3VdbeAddOp4(tls, v, int32(OP_DropIndex), iDb, 0, 0, (*TIndex)(unsafe.Pointer(pIndex)).FzName, 0)
	}
	goto exit_drop_index
exit_drop_index:
	;
	_sqlite3SrcListDelete(tls, db, pName)
}

// C documentation
//
//	/*
//	** This routine is called to do the work of a DROP TABLE statement.
//	** pName is the name of the table to be dropped.
//	*/
func _sqlite3DropTable(tls *libc.TLS, pParse uintptr, pName uintptr, isView int32, noErr int32) {
	bp := tls.Alloc(16)
	defer tls.Free(16)
	var code, iDb int32
	var db, pTab, v, zArg2, zDb, zTab, v1 uintptr
	_, _, _, _, _, _, _, _, _ = code, db, iDb, pTab, v, zArg2, zDb, zTab, v1
	db = (*TParse)(unsafe.Pointer(pParse)).Fdb
	if (*Tsqlite3)(unsafe.Pointer(db)).FmallocFailed != 0 {
		goto exit_drop_table
	}
	if _sqlite3ReadSchema(tls, pParse) != 0 {
		goto exit_drop_table
	}
	if noErr != 0 {
		(*Tsqlite3)(unsafe.Pointer(db)).FsuppressErr = (*Tsqlite3)(unsafe.Pointer(db)).FsuppressErr + 1
	}
	pTab = _sqlite3LocateTableItem(tls, pParse, libc.Uint32FromInt32(isView), pName+8)
	if noErr != 0 {
		(*Tsqlite3)(unsafe.Pointer(db)).FsuppressErr = (*Tsqlite3)(unsafe.Pointer(db)).FsuppressErr - 1
	}
	if pTab == uintptr(0) {
		if noErr != 0 {
			_sqlite3CodeVerifyNamedSchema(tls, pParse, *(*uintptr)(unsafe.Pointer(pName + 8 + 72)))
			_sqlite3ForceNotReadOnly(tls, pParse)
		}
		goto exit_drop_table
	}
	iDb = _sqlite3SchemaToIndex(tls, db, (*TTable)(unsafe.Pointer(pTab)).FpSchema)
	/* If pTab is a virtual table, call ViewGetColumnNames() to ensure
	 ** it is initialized.
	 */
	if libc.Int32FromUint8((*TTable)(unsafe.Pointer(pTab)).FeTabType) == int32(TABTYP_VTAB) && _sqlite3ViewGetColumnNames(tls, pParse, pTab) != 0 {
		goto exit_drop_table
	}
	if libc.Bool(!(libc.Int32FromInt32(OMIT_TEMPDB) != 0)) && iDb == int32(1) {
		v1 = __ccgo_ts + 6757
	} else {
		v1 = __ccgo_ts + 6277
	}
	zTab = v1
	zDb = (**(**TDb)(__ccgo_up((*Tsqlite3)(unsafe.Pointer(db)).FaDb + uintptr(iDb)*32))).FzDbSName
	zArg2 = uintptr(0)
	if _sqlite3AuthCheck(tls, pParse, int32(SQLITE_DELETE), zTab, uintptr(0), zDb) != 0 {
		goto exit_drop_table
	}
	if isView != 0 {
		if libc.Bool(!(libc.Int32FromInt32(OMIT_TEMPDB) != 0)) && iDb == int32(1) {
			code = int32(SQLITE_DROP_TEMP_VIEW)
		} else {
			code = int32(SQLITE_DROP_VIEW)
		}
	} else {
		if libc.Int32FromUint8((*TTable)(unsafe.Pointer(pTab)).FeTabType) == int32(TABTYP_VTAB) {
			code = int32(SQLITE_DROP_VTABLE)
			zArg2 = (*TModule)(unsafe.Pointer((*TVTable)(unsafe.Pointer(_sqlite3GetVTable(tls, db, pTab))).FpMod)).FzName
		} else {
			if libc.Bool(!(libc.Int32FromInt32(OMIT_TEMPDB) != 0)) && iDb == int32(1) {
				code = int32(SQLITE_DROP_TEMP_TABLE)
			} else {
				code = int32(SQLITE_DROP_TABLE)
			}
		}
	}
	if _sqlite3AuthCheck(tls, pParse, code, (*TTable)(unsafe.Pointer(pTab)).FzName, zArg2, zDb) != 0 {
		goto exit_drop_table
	}
	if _sqlite3AuthCheck(tls, pParse, int32(SQLITE_DELETE), (*TTable)(unsafe.Pointer(pTab)).FzName, uintptr(0), zDb) != 0 {
		goto exit_drop_table
	}
	if _tableMayNotBeDropped(tls, db, pTab) != 0 {
		_sqlite3ErrorMsg(tls, pParse, __ccgo_ts+15070, libc.VaList(bp+8, (*TTable)(unsafe.Pointer(pTab)).FzName))
		goto exit_drop_table
	}
	/* Ensure DROP TABLE is not used on a view, and DROP VIEW is not used
	 ** on a table.
	 */
	if isView != 0 && !(libc.Int32FromUint8((*TTable)(unsafe.Pointer(pTab)).FeTabType) == libc.Int32FromInt32(TABTYP_VIEW)) {
		_sqlite3ErrorMsg(tls, pParse, __ccgo_ts+15098, libc.VaList(bp+8, (*TTable)(unsafe.Pointer(pTab)).FzName))
		goto exit_drop_table
	}
	if !(isView != 0) && libc.Int32FromUint8((*TTable)(unsafe.Pointer(pTab)).FeTabType) == int32(TABTYP_VIEW) {
		_sqlite3ErrorMsg(tls, pParse, __ccgo_ts+15132, libc.VaList(bp+8, (*TTable)(unsafe.Pointer(pTab)).FzName))
		goto exit_drop_table
	}
	/* Generate code to remove the table from the schema table
	 ** on disk.
	 */
	v = _sqlite3GetVdbe(tls, pParse)
	if v != 0 {
		_sqlite3BeginWriteOperation(tls, pParse, int32(1), iDb)
		if !(isView != 0) {
			_sqlite3ClearStatTables(tls, pParse, iDb, __ccgo_ts+13041, (*TTable)(unsafe.Pointer(pTab)).FzName)
			_sqlite3FkDropTable(tls, pParse, pName, pTab)
		}
		_sqlite3CodeDropTable(tls, pParse, pTab, iDb, isView)
	}
	goto exit_drop_table
exit_drop_table:
	;
	_sqlite3SrcListDelete(tls, db, pName)
}

// C documentation
//
//	/*
//	** This function is called to drop a trigger from the database schema.
//	**
//	** This may be called directly from the parser and therefore identifies
//	** the trigger by name.  The sqlite3DropTriggerPtr() routine does the
//	** same job as this routine except it takes a pointer to the trigger
//	** instead of the trigger name.
//	**/
func _sqlite3DropTrigger(tls *libc.TLS, pParse uintptr, pName uintptr, noErr int32) {
	bp := tls.Alloc(16)
	defer tls.Free(16)
	var db, pTrigger, zDb, zName uintptr
	var i, j, v2 int32
	_, _, _, _, _, _, _ = db, i, j, pTrigger, zDb, zName, v2
	pTrigger = uintptr(0)
	db = (*TParse)(unsafe.Pointer(pParse)).Fdb
	if (*Tsqlite3)(unsafe.Pointer(db)).FmallocFailed != 0 {
		goto drop_trigger_cleanup
	}
	if SQLITE_OK != _sqlite3ReadSchema(tls, pParse) {
		goto drop_trigger_cleanup
	}
	zDb = *(*uintptr)(unsafe.Pointer(pName + 8 + 72))
	zName = (*(*TSrcItem)(unsafe.Pointer(pName + 8))).FzName
	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 */
		if zDb != 0 && _sqlite3DbIsNamed(tls, db, j, zDb) == 0 {
			goto _1
		}
		pTrigger = _sqlite3HashFind(tls, (**(**TDb)(__ccgo_up((*Tsqlite3)(unsafe.Pointer(db)).FaDb + uintptr(j)*32))).FpSchema+56, zName)
		if pTrigger != 0 {
			break
		}
		goto _1
	_1:
		;
		i = i + 1
	}
	if !(pTrigger != 0) {
		if !(noErr != 0) {
			_sqlite3ErrorMsg(tls, pParse, __ccgo_ts+22371, libc.VaList(bp+8, pName+8))
		} else {
			_sqlite3CodeVerifyNamedSchema(tls, pParse, zDb)
		}
		libc.SetBitFieldPtr16Uint32(pParse+40, libc.Uint32FromInt32(1), 8, 0x100)
		goto drop_trigger_cleanup
	}
	_sqlite3DropTriggerPtr(tls, pParse, pTrigger)
	goto drop_trigger_cleanup
drop_trigger_cleanup:
	;
	_sqlite3SrcListDelete(tls, db, pName)
}

// C documentation
//
//	/*
//	** Drop a trigger given a pointer to that trigger.
//	*/
func _sqlite3DropTriggerPtr(tls *libc.TLS, pParse uintptr, pTrigger uintptr) {
	bp := tls.Alloc(32)
	defer tls.Free(32)
	var code, iDb int32
	var db, pTable, v, zDb, zTab, v1 uintptr
	_, _, _, _, _, _, _, _ = code, db, iDb, pTable, v, zDb, zTab, v1
	db = (*TParse)(unsafe.Pointer(pParse)).Fdb
	iDb = _sqlite3SchemaToIndex(tls, (*TParse)(unsafe.Pointer(pParse)).Fdb, (*TTrigger)(unsafe.Pointer(pTrigger)).FpSchema)
	pTable = _tableOfTrigger(tls, pTrigger)
	if pTable != 0 {
		code = int32(SQLITE_DROP_TRIGGER)
		zDb = (**(**TDb)(__ccgo_up((*Tsqlite3)(unsafe.Pointer(db)).FaDb + uintptr(iDb)*32))).FzDbSName
		if libc.Bool(!(libc.Int32FromInt32(OMIT_TEMPDB) != 0)) && iDb == int32(1) {
			v1 = __ccgo_ts + 6757
		} else {
			v1 = __ccgo_ts + 6277
		}
		zTab = v1
		if iDb == int32(1) {
			code = int32(SQLITE_DROP_TEMP_TRIGGER)
		}
		if _sqlite3AuthCheck(tls, pParse, code, (*TTrigger)(unsafe.Pointer(pTrigger)).FzName, (*TTable)(unsafe.Pointer(pTable)).FzName, zDb) != 0 || _sqlite3AuthCheck(tls, pParse, int32(SQLITE_DELETE), zTab, uintptr(0), zDb) != 0 {
			return
		}
	}
	/* Generate code to destroy the database record of the trigger.
	 */
	v1 = _sqlite3GetVdbe(tls, pParse)
	v = v1
	if v1 != uintptr(0) {
		_sqlite3NestedParse(tls, pParse, __ccgo_ts+22391, libc.VaList(bp+8, (**(**TDb)(__ccgo_up((*Tsqlite3)(unsafe.Pointer(db)).FaDb + uintptr(iDb)*32))).FzDbSName, (*TTrigger)(unsafe.Pointer(pTrigger)).FzName))
		_sqlite3ChangeCookie(tls, pParse, iDb)
		_sqlite3VdbeAddOp4(tls, v, int32(OP_DropTrigger), iDb, 0, 0, (*TTrigger)(unsafe.Pointer(pTrigger)).FzName, 0)
	}
}

// C documentation
//
//	/*
//	** Generate VDBE code for a COMMIT or ROLLBACK statement.
//	** Code for ROLLBACK is generated if eType==TK_ROLLBACK.  Otherwise
//	** code is generated for a COMMIT.
//	*/
func _sqlite3EndTransaction(tls *libc.TLS, pParse uintptr, eType int32) {
	var isRollback int32
	var v, v1 uintptr
	_, _, _ = isRollback, v, v1
	isRollback = libc.BoolInt32(eType == int32(TK_ROLLBACK))
	if isRollback != 0 {
		v1 = __ccgo_ts + 16102
	} else {
		v1 = __ccgo_ts + 16111
	}
	if _sqlite3AuthCheck(tls, pParse, int32(SQLITE_TRANSACTION), v1, uintptr(0), uintptr(0)) != 0 {
		return
	}
	v = _sqlite3GetVdbe(tls, pParse)
	if v != 0 {
		_sqlite3VdbeAddOp2(tls, v, int32(OP_AutoCommit), int32(1), isRollback)
	}
}

// C documentation
//
//	/*
//	** Return a static string that describes the kind of error specified in the
//	** argument.
//	*/
func _sqlite3ErrStr(tls *libc.TLS, rc int32) (r uintptr) {
	var zErr uintptr
	_ = zErr
	zErr = __ccgo_ts + 25823
	switch rc {
	case libc.Int32FromInt32(SQLITE_ABORT) | libc.Int32FromInt32(2)<<libc.Int32FromInt32(8):
		zErr = __ccgo_ts + 25837
	case int32(SQLITE_ROW):
		zErr = __ccgo_ts + 25859
	case int32(SQLITE_DONE):
		zErr = __ccgo_ts + 25881
	default:
		rc = rc & int32(0xff)
		if rc >= 0 && rc < libc.Int32FromUint64(libc.Uint64FromInt64(232)/libc.Uint64FromInt64(8)) && _aMsg[rc] != uintptr(0) {
			zErr = _aMsg[rc]
		}
		break
	}
	return zErr
}

// C documentation
//
//	/*
//	** Write code that will raise an error if the table described by
//	** zDb and zTab is not empty.
//	*/
func _sqlite3ErrorIfNotEmpty(tls *libc.TLS, pParse uintptr, zDb uintptr, zTab uintptr, zErr uintptr) {
	bp := tls.Alloc(32)
	defer tls.Free(32)
	_sqlite3NestedParse(tls, pParse, __ccgo_ts+10244, libc.VaList(bp+8, zErr, zDb, zTab))
}

// C documentation
//
//	/*
//	** The SrcItem structure passed as the second argument represents a
//	** sub-query in the FROM clause of a SELECT statement. This function
//	** allocates and populates the SrcItem.pTab object. If successful,
//	** SQLITE_OK is returned. Otherwise, if an OOM error is encountered,
//	** SQLITE_NOMEM.
//	*/
func _sqlite3ExpandSubquery(tls *libc.TLS, pParse uintptr, pFrom uintptr) (r int32) {
	bp := tls.Alloc(16)
	defer tls.Free(16)
	var pSel, pTab, v1 uintptr
	var v2 int32
	_, _, _, _ = pSel, pTab, v1, v2
	pSel = (*TSubquery)(unsafe.Pointer(*(*uintptr)(unsafe.Pointer(pFrom + 72)))).FpSelect
	v1 = _sqlite3DbMallocZero(tls, (*TParse)(unsafe.Pointer(pParse)).Fdb, uint64(120))
	pTab = v1
	(*TSrcItem)(unsafe.Pointer(pFrom)).FpSTab = v1
	if pTab == uintptr(0) {
		return int32(SQLITE_NOMEM)
	}
	(*TTable)(unsafe.Pointer(pTab)).FnTabRef = uint32(1)
	if (*TSrcItem)(unsafe.Pointer(pFrom)).FzAlias != 0 {
		(*TTable)(unsafe.Pointer(pTab)).FzName = _sqlite3DbStrDup(tls, (*TParse)(unsafe.Pointer(pParse)).Fdb, (*TSrcItem)(unsafe.Pointer(pFrom)).FzAlias)
	} else {
		(*TTable)(unsafe.Pointer(pTab)).FzName = _sqlite3MPrintf(tls, (*TParse)(unsafe.Pointer(pParse)).Fdb, __ccgo_ts+21244, libc.VaList(bp+8, pFrom))
	}
	for (*TSelect)(unsafe.Pointer(pSel)).FpPrior != 0 {
		pSel = (*TSelect)(unsafe.Pointer(pSel)).FpPrior
	}
	_sqlite3ColumnsFromExprList(tls, pParse, (*TSelect)(unsafe.Pointer(pSel)).FpEList, pTab+54, pTab+8)
	(*TTable)(unsafe.Pointer(pTab)).FiPKey = int16(-int32(1))
	(*TTable)(unsafe.Pointer(pTab)).FeTabType = uint8(TABTYP_VIEW)
	(*TTable)(unsafe.Pointer(pTab)).FnRowLogEst = int16(200)
	/* The usual case - do not allow ROWID on a subquery */
	**(**Tu32)(__ccgo_up(pTab + 48)) |= libc.Uint32FromInt32(libc.Int32FromInt32(TF_Ephemeral) | libc.Int32FromInt32(TF_NoVisibleRowid))
	if (*TParse)(unsafe.Pointer(pParse)).FnErr != 0 {
		v2 = int32(SQLITE_ERROR)
	} else {
		v2 = SQLITE_OK
	}
	return v2
}

// C documentation
//
//	/*
//	** Attach an ORDER BY clause to a function call.
//	**
//	**     functionname( arguments ORDER BY sortlist )
//	**     \_____________________/          \______/
//	**             pExpr                    pOrderBy
//	**
//	** The ORDER BY clause is inserted into a new Expr node of type TK_ORDER
//	** and added to the Expr.pLeft field of the parent TK_FUNCTION node.
//	*/
func _sqlite3ExprAddFunctionOrderBy(tls *libc.TLS, pParse uintptr, pExpr uintptr, pOrderBy uintptr) {
	var db, pOB uintptr
	_, _ = db, pOB
	db = (*TParse)(unsafe.Pointer(pParse)).Fdb
	if pOrderBy == uintptr(0) {
		return
	}
	if pExpr == uintptr(0) {
		_sqlite3ExprListDelete(tls, db, pOrderBy)
		return
	}
	if *(*uintptr)(unsafe.Pointer(pExpr + 32)) == uintptr(0) || (*TExprList)(unsafe.Pointer(*(*uintptr)(unsafe.Pointer(pExpr + 32)))).FnExpr == 0 {
		/* Ignore ORDER BY on zero-argument aggregates */
		_sqlite3ParserAddCleanup(tls, pParse, __ccgo_fp(_sqlite3ExprListDeleteGeneric), pOrderBy)
		return
	}
	if (*TExpr)(unsafe.Pointer(pExpr)).Fflags&libc.Uint32FromInt32(libc.Int32FromInt32(EP_WinFunc)) != uint32(0) && libc.Int32FromUint8((*TWindow)(unsafe.Pointer(*(*uintptr)(unsafe.Pointer(pExpr + 64)))).FeFrmType) != int32(TK_FILTER) {
		_sqlite3ExprOrderByAggregateError(tls, pParse, pExpr)
		_sqlite3ExprListDelete(tls, db, pOrderBy)
		return
	}
	if (*TExprList)(unsafe.Pointer(pOrderBy)).FnExpr > **(**int32)(__ccgo_up(db + 136 + 2*4)) {
		_sqlite3ErrorMsg(tls, pParse, __ccgo_ts+7618, 0)
		_sqlite3ExprListDelete(tls, db, pOrderBy)
		return
	}
	pOB = _sqlite3ExprAlloc(tls, db, int32(TK_ORDER), uintptr(0), 0)
	if pOB == uintptr(0) {
		_sqlite3ExprListDelete(tls, db, pOrderBy)
		return
	}
	*(*uintptr)(unsafe.Pointer(pOB + 32)) = pOrderBy
	(*TExpr)(unsafe.Pointer(pExpr)).FpLeft = pOB
	**(**Tu32)(__ccgo_up(pOB + 4)) |= libc.Uint32FromInt32(libc.Int32FromInt32(EP_FullSize))
}

// C documentation
//
//	/*
//	** Check that argument nHeight is less than or equal to the maximum
//	** expression depth allowed. If it is not, leave an error message in
//	** pParse.
//	*/
func _sqlite3ExprCheckHeight(tls *libc.TLS, pParse uintptr, nHeight int32) (r int32) {
	bp := tls.Alloc(16)
	defer tls.Free(16)
	var mxHeight, rc int32
	_, _ = mxHeight, rc
	rc = SQLITE_OK
	mxHeight = **(**int32)(__ccgo_up((*TParse)(unsafe.Pointer(pParse)).Fdb + 136 + 3*4))
	if nHeight > mxHeight {
		_sqlite3ErrorMsg(tls, pParse, __ccgo_ts+7854, libc.VaList(bp+8, mxHeight))
		rc = int32(SQLITE_ERROR)
	}
	return rc
}

// C documentation
//
//	/*
//	** Generate code to extract the value of the iCol-th column of a table.
//	*/
func _sqlite3ExprCodeGetColumnOfTable(tls *libc.TLS, v uintptr, pTab uintptr, iTabCur int32, iCol int32, regOut int32) {
	bp := tls.Alloc(16)
	defer tls.Free(16)
	var op, savedSelfTab, x int32
	var pCol, pParse, v1 uintptr
	_, _, _, _, _, _ = op, pCol, pParse, savedSelfTab, x, v1
	if iCol < 0 || iCol == int32((*TTable)(unsafe.Pointer(pTab)).FiPKey) {
		_sqlite3VdbeAddOp2(tls, v, int32(OP_Rowid), iTabCur, regOut)
	} else {
		if libc.Int32FromUint8((*TTable)(unsafe.Pointer(pTab)).FeTabType) == int32(TABTYP_VTAB) {
			op = int32(OP_VColumn)
			x = iCol
		} else {
			v1 = (*TTable)(unsafe.Pointer(pTab)).FaCol + uintptr(iCol)*16
			pCol = v1
			if libc.Int32FromUint16((*TColumn)(unsafe.Pointer(v1)).FcolFlags)&int32(COLFLAG_VIRTUAL) != 0 {
				pParse = _sqlite3VdbeParser(tls, v)
				if libc.Int32FromUint16((*TColumn)(unsafe.Pointer(pCol)).FcolFlags)&int32(COLFLAG_BUSY) != 0 {
					_sqlite3ErrorMsg(tls, pParse, __ccgo_ts+8445, libc.VaList(bp+8, (*TColumn)(unsafe.Pointer(pCol)).FzCnName))
				} else {
					savedSelfTab = (*TParse)(unsafe.Pointer(pParse)).FiSelfTab
					v1 = pCol + 14
					*(*Tu16)(unsafe.Pointer(v1)) = Tu16(int32(*(*Tu16)(unsafe.Pointer(v1))) | libc.Int32FromInt32(COLFLAG_BUSY))
					(*TParse)(unsafe.Pointer(pParse)).FiSelfTab = iTabCur + int32(1)
					_sqlite3ExprCodeGeneratedColumn(tls, pParse, pTab, pCol, regOut)
					(*TParse)(unsafe.Pointer(pParse)).FiSelfTab = savedSelfTab
					v1 = pCol + 14
					*(*Tu16)(unsafe.Pointer(v1)) = Tu16(int32(*(*Tu16)(unsafe.Pointer(v1))) & ^libc.Int32FromInt32(COLFLAG_BUSY))
				}
				return
			} else {
				if !((*TTable)(unsafe.Pointer(pTab)).FtabFlags&libc.Uint32FromInt32(TF_WithoutRowid) == libc.Uint32FromInt32(0)) {
					x = _sqlite3TableColumnToIndex(tls, _sqlite3PrimaryKeyIndex(tls, pTab), iCol)
					op = int32(OP_Column)
				} else {
					x = int32(_sqlite3TableColumnToStorage(tls, pTab, int16(iCol)))
					op = int32(OP_Column)
				}
			}
		}
		_sqlite3VdbeAddOp3(tls, v, op, iTabCur, x, regOut)
		_sqlite3ColumnDefault(tls, v, pTab, iCol, regOut)
	}
}

// C documentation
//
//	/*
//	** Construct a new expression node for a function with multiple
//	** arguments.
//	*/
func _sqlite3ExprFunction(tls *libc.TLS, pParse uintptr, pList uintptr, pToken uintptr, eDistinct int32) (r uintptr) {
	bp := tls.Alloc(16)
	defer tls.Free(16)
	var db, pNew uintptr
	_, _ = db, pNew
	db = (*TParse)(unsafe.Pointer(pParse)).Fdb
	pNew = _sqlite3ExprAlloc(tls, db, int32(TK_FUNCTION), pToken, int32(1))
	if pNew == uintptr(0) {
		_sqlite3ExprListDelete(tls, db, pList) /* Avoid memory leak when malloc fails */
		return uintptr(0)
	}
	*(*int32)(unsafe.Pointer(pNew + 52)) = int32(int64((*TToken)(unsafe.Pointer(pToken)).Fz) - int64((*TParse)(unsafe.Pointer(pParse)).FzTail))
	if pList != 0 && (*TExprList)(unsafe.Pointer(pList)).FnExpr > **(**int32)(__ccgo_up((*TParse)(unsafe.Pointer(pParse)).Fdb + 136 + 6*4)) && !((*TParse)(unsafe.Pointer(pParse)).Fnested != 0) {
		_sqlite3ErrorMsg(tls, pParse, __ccgo_ts+7948, libc.VaList(bp+8, pToken))
	}
	*(*uintptr)(unsafe.Pointer(pNew + 32)) = pList
	**(**Tu32)(__ccgo_up(pNew + 4)) |= libc.Uint32FromInt32(libc.Int32FromInt32(EP_HasFunc))
	_sqlite3ExprSetHeightAndFlags(tls, pParse, pNew)
	if eDistinct == int32(SF_Distinct) {
		**(**Tu32)(__ccgo_up(pNew + 4)) |= libc.Uint32FromInt32(libc.Int32FromInt32(EP_Distinct))
	}
	return pNew
}

// C documentation
//
//	/*
//	** Check to see if a function is usable according to current access
//	** rules:
//	**
//	**    SQLITE_FUNC_DIRECT    -     Only usable from top-level SQL
//	**
//	**    SQLITE_FUNC_UNSAFE    -     Usable if TRUSTED_SCHEMA or from
//	**                                top-level SQL
//	**
//	** If the function is not usable, create an error.
//	*/
func _sqlite3ExprFunctionUsable(tls *libc.TLS, pParse uintptr, pExpr uintptr, pDef uintptr) {
	bp := tls.Alloc(16)
	defer tls.Free(16)
	if (*TExpr)(unsafe.Pointer(pExpr)).Fflags&libc.Uint32FromInt32(libc.Int32FromInt32(EP_FromDDL)) != uint32(0) || libc.Int32FromUint8((*TParse)(unsafe.Pointer(pParse)).FprepFlags)&int32(SQLITE_PREPARE_FROM_DDL) != 0 {
		if (*TFuncDef)(unsafe.Pointer(pDef)).FfuncFlags&uint32(SQLITE_FUNC_DIRECT) != uint32(0) || (*Tsqlite3)(unsafe.Pointer((*TParse)(unsafe.Pointer(pParse)).Fdb)).Fflags&uint64(SQLITE_TrustedSchema) == uint64(0) {
			/* Functions prohibited in triggers and views if:
			 **     (1) tagged with SQLITE_DIRECTONLY
			 **     (2) not tagged with SQLITE_INNOCUOUS (which means it
			 **         is tagged with SQLITE_FUNC_UNSAFE) and
			 **         SQLITE_DBCONFIG_TRUSTED_SCHEMA is off (meaning
			 **         that the schema is possibly tainted).
			 */
			_sqlite3ErrorMsg(tls, pParse, __ccgo_ts+8032, libc.VaList(bp+8, pExpr))
		}
	}
}

// C documentation
//
//	/*
//	** pColumns and pExpr form a vector assignment which is part of the SET
//	** clause of an UPDATE statement.  Like this:
//	**
//	**        (a,b,c) = (expr1,expr2,expr3)
//	** Or:    (a,b,c) = (SELECT x,y,z FROM ....)
//	**
//	** For each term of the vector assignment, append new entries to the
//	** expression list pList.  In the case of a subquery on the RHS, append
//	** TK_SELECT_COLUMN expressions.
//	*/
func _sqlite3ExprListAppendVector(tls *libc.TLS, pParse uintptr, pList uintptr, pColumns uintptr, pExpr uintptr) (r uintptr) {
	bp := tls.Alloc(32)
	defer tls.Free(32)
	var db, pFirst, pSubExpr uintptr
	var i, iFirst, n, v1 int32
	var v3 bool
	_, _, _, _, _, _, _, _ = db, i, iFirst, n, pFirst, pSubExpr, v1, v3
	db = (*TParse)(unsafe.Pointer(pParse)).Fdb
	if pList != 0 {
		v1 = (*TExprList)(unsafe.Pointer(pList)).FnExpr
	} else {
		v1 = 0
	}
	iFirst = v1
	/* pColumns can only be NULL due to an OOM but an OOM will cause an
	 ** exit prior to this routine being invoked */
	if pColumns == uintptr(0) {
		goto vector_append_error
	}
	if pExpr == uintptr(0) {
		goto vector_append_error
	}
	/* If the RHS is a vector, then we can immediately check to see that
	 ** the size of the RHS and LHS match.  But if the RHS is a SELECT,
	 ** wildcards ("*") in the result set of the SELECT must be expanded before
	 ** we can do the size check, so defer the size check until code generation.
	 */
	if v3 = libc.Int32FromUint8((*TExpr)(unsafe.Pointer(pExpr)).Fop) != int32(TK_SELECT); v3 {
		v1 = _sqlite3ExprVectorSize(tls, pExpr)
		n = v1
	}
	if v3 && (*TIdList)(unsafe.Pointer(pColumns)).FnId != v1 {
		_sqlite3ErrorMsg(tls, pParse, __ccgo_ts+8118, libc.VaList(bp+8, (*TIdList)(unsafe.Pointer(pColumns)).FnId, n))
		goto vector_append_error
	}
	i = 0
	for {
		if !(i < (*TIdList)(unsafe.Pointer(pColumns)).FnId) {
			break
		}
		pSubExpr = _sqlite3ExprForVectorField(tls, pParse, pExpr, i, (*TIdList)(unsafe.Pointer(pColumns)).FnId)
		if pSubExpr == uintptr(0) {
			goto _4
		}
		pList = _sqlite3ExprListAppend(tls, pParse, pList, pSubExpr)
		if pList != 0 {
			(*(*TExprList_item)(unsafe.Pointer(pList + 8 + uintptr((*TExprList)(unsafe.Pointer(pList)).FnExpr-int32(1))*32))).FzEName = (*(*TIdList_item)(unsafe.Pointer(pColumns + 8 + uintptr(i)*8))).FzName
			(*(*TIdList_item)(unsafe.Pointer(pColumns + 8 + uintptr(i)*8))).FzName = uintptr(0)
		}
		goto _4
	_4:
		;
		i = i + 1
	}
	if !((*Tsqlite3)(unsafe.Pointer(db)).FmallocFailed != 0) && libc.Int32FromUint8((*TExpr)(unsafe.Pointer(pExpr)).Fop) == int32(TK_SELECT) && pList != uintptr(0) {
		pFirst = (*(*TExprList_item)(unsafe.Pointer(pList + 8 + uintptr(iFirst)*32))).FpExpr
		/* Store the SELECT statement in pRight so it will be deleted when
		 ** sqlite3ExprListDelete() is called */
		(*TExpr)(unsafe.Pointer(pFirst)).FpRight = pExpr
		pExpr = uintptr(0)
		/* Remember the size of the LHS in iTable so that we can check that
		 ** the RHS and LHS sizes match during code generation. */
		(*TExpr)(unsafe.Pointer(pFirst)).FiTable = (*TIdList)(unsafe.Pointer(pColumns)).FnId
	}
	goto vector_append_error
vector_append_error:
	;
	_sqlite3ExprUnmapAndDelete(tls, pParse, pExpr)
	_sqlite3IdListDelete(tls, db, pColumns)
	return pList
}

// C documentation
//
//	/*
//	** If the expression list pEList contains more than iLimit elements,
//	** leave an error message in pParse.
//	*/
func _sqlite3ExprListCheckLength(tls *libc.TLS, pParse uintptr, pEList uintptr, zObject uintptr) {
	bp := tls.Alloc(16)
	defer tls.Free(16)
	var mx int32
	_ = mx
	mx = **(**int32)(__ccgo_up((*TParse)(unsafe.Pointer(pParse)).Fdb + 136 + 2*4))
	if pEList != 0 && (*TExprList)(unsafe.Pointer(pEList)).FnExpr > mx {
		_sqlite3ErrorMsg(tls, pParse, __ccgo_ts+8148, libc.VaList(bp+8, zObject))
	}
}

// C documentation
//
//	/*
//	** Expression list pEList is a list of vector values. This function
//	** converts the contents of pEList to a VALUES(...) Select statement
//	** returning 1 row for each element of the list. For example, the
//	** expression list:
//	**
//	**   ( (1,2), (3,4) (5,6) )
//	**
//	** is translated to the equivalent of:
//	**
//	**   VALUES(1,2), (3,4), (5,6)
//	**
//	** Each of the vector values in pEList must contain exactly nElem terms.
//	** If a list element that is not a vector or does not contain nElem terms,
//	** an error message is left in pParse.
//	**
//	** This is used as part of processing IN(...) expressions with a list
//	** of vectors on the RHS. e.g. "... IN ((1,2), (3,4), (5,6))".
//	*/
func _sqlite3ExprListToValues(tls *libc.TLS, pParse uintptr, nElem int32, pEList uintptr) (r uintptr) {
	bp := tls.Alloc(32)
	defer tls.Free(32)
	var ii, nExprElem int32
	var pExpr, pRet, pSel, v2 uintptr
	_, _, _, _, _, _ = ii, nExprElem, pExpr, pRet, pSel, v2
	pRet = uintptr(0)
	ii = 0
	for {
		if !(ii < (*TExprList)(unsafe.Pointer(pEList)).FnExpr) {
			break
		}
		pExpr = (*(*TExprList_item)(unsafe.Pointer(pEList + 8 + uintptr(ii)*32))).FpExpr
		if libc.Int32FromUint8((*TExpr)(unsafe.Pointer(pExpr)).Fop) == int32(TK_VECTOR) {
			nExprElem = (*TExprList)(unsafe.Pointer(*(*uintptr)(unsafe.Pointer(pExpr + 32)))).FnExpr
		} else {
			nExprElem = int32(1)
		}
		if nExprElem != nElem {
			if nExprElem > int32(1) {
				v2 = __ccgo_ts + 7902
			} else {
				v2 = __ccgo_ts + 1693
			}
			_sqlite3ErrorMsg(tls, pParse, __ccgo_ts+7904, libc.VaList(bp+8, nExprElem, v2, nElem))
			break
		}
		pSel = _sqlite3SelectNew(tls, pParse, *(*uintptr)(unsafe.Pointer(pExpr + 32)), uintptr(0), uintptr(0), uintptr(0), uintptr(0), uintptr(0), uint32(SF_Values), uintptr(0))
		*(*uintptr)(unsafe.Pointer(pExpr + 32)) = uintptr(0)
		if pSel != 0 {
			if pRet != 0 {
				(*TSelect)(unsafe.Pointer(pSel)).Fop = uint8(TK_ALL)
				(*TSelect)(unsafe.Pointer(pSel)).FpPrior = pRet
			}
			pRet = pSel
		}
		goto _1
	_1:
		;
		ii = ii + 1
	}
	if pRet != 0 && (*TSelect)(unsafe.Pointer(pRet)).FpPrior != 0 {
		**(**Tu32)(__ccgo_up(pRet + 4)) |= uint32(SF_MultiValue)
	}
	_sqlite3ExprListDelete(tls, (*TParse)(unsafe.Pointer(pParse)).Fdb, pEList)
	return pRet
}

// C documentation
//
//	/*
//	** Report an error when attempting to use an ORDER BY clause within
//	** the arguments of a non-aggregate function.
//	*/
func _sqlite3ExprOrderByAggregateError(tls *libc.TLS, pParse uintptr, p uintptr) {
	bp := tls.Alloc(16)
	defer tls.Free(16)
	_sqlite3ErrorMsg(tls, pParse, __ccgo_ts+7982, libc.VaList(bp+8, p))
}

// C documentation
//
//	/*
//	** Parameter zName points to a nul-terminated buffer containing the name
//	** of a database ("main", "temp" or the name of an attached db). This
//	** function returns the index of the named database in db->aDb[], or
//	** -1 if the named db cannot be found.
//	*/
func _sqlite3FindDbName(tls *libc.TLS, db uintptr, zName uintptr) (r int32) {
	var i int32
	var pDb uintptr
	_, _ = i, pDb
	i = -int32(1) /* Database number */
	if zName != 0 {
		i = (*Tsqlite3)(unsafe.Pointer(db)).FnDb - int32(1)
		pDb = (*Tsqlite3)(unsafe.Pointer(db)).FaDb + uintptr(i)*32
		for {
			if !(i >= 0) {
				break
			}
			if 0 == Xsqlite3_stricmp(tls, (*TDb)(unsafe.Pointer(pDb)).FzDbSName, zName) {
				break
			}
			/* "main" is always an acceptable alias for the primary database
			 ** even if it has been renamed using SQLITE_DBCONFIG_MAINDBNAME. */
			if i == 0 && 0 == Xsqlite3_stricmp(tls, __ccgo_ts+6809, zName) {
				break
			}
			goto _1
		_1:
			;
			i = i - 1
			pDb -= 32
		}
	}
	return i
}

// C documentation
//
//	/*
//	** Locate the in-memory structure that describes a particular database
//	** table given the name of that table and (optionally) the name of the
//	** database containing the table.  Return NULL if not found.
//	**
//	** If zDatabase is 0, all databases are searched for the table and the
//	** first matching table is returned.  (No checking for duplicate table
//	** names is done.)  The search order is TEMP first, then MAIN, then any
//	** auxiliary databases added using the ATTACH command.
//	**
//	** See also sqlite3LocateTable().
//	*/
func _sqlite3FindTable(tls *libc.TLS, db uintptr, zName uintptr, zDatabase uintptr) (r uintptr) {
	var i int32
	var p uintptr
	_, _ = i, p
	p = uintptr(0)
	/* All mutexes are required for schema access.  Make sure we hold them. */
	if zDatabase != 0 {
		i = 0
		for {
			if !(i < (*Tsqlite3)(unsafe.Pointer(db)).FnDb) {
				break
			}
			if _sqlite3StrICmp(tls, zDatabase, (**(**TDb)(__ccgo_up((*Tsqlite3)(unsafe.Pointer(db)).FaDb + uintptr(i)*32))).FzDbSName) == 0 {
				break
			}
			goto _1
		_1:
			;
			i = i + 1
		}
		if i >= (*Tsqlite3)(unsafe.Pointer(db)).FnDb {
			/* No match against the official names.  But always match "main"
			 ** to schema 0 as a legacy fallback. */
			if _sqlite3StrICmp(tls, zDatabase, __ccgo_ts+6809) == 0 {
				i = 0
			} else {
				return uintptr(0)
			}
		}
		p = _sqlite3HashFind(tls, (**(**TDb)(__ccgo_up((*Tsqlite3)(unsafe.Pointer(db)).FaDb + uintptr(i)*32))).FpSchema+8, zName)
		if p == uintptr(0) && Xsqlite3_strnicmp(tls, zName, __ccgo_ts+6749, int32(7)) == 0 {
			if i == int32(1) {
				if _sqlite3StrICmp(tls, zName+uintptr(7), __ccgo_ts+6776+7) == 0 || _sqlite3StrICmp(tls, zName+uintptr(7), __ccgo_ts+6795+7) == 0 || _sqlite3StrICmp(tls, zName+uintptr(7), __ccgo_ts+6277+7) == 0 {
					p = _sqlite3HashFind(tls, (**(**TDb)(__ccgo_up((*Tsqlite3)(unsafe.Pointer(db)).FaDb + 1*32))).FpSchema+8, __ccgo_ts+6757)
				}
			} else {
				if _sqlite3StrICmp(tls, zName+uintptr(7), __ccgo_ts+6795+7) == 0 {
					p = _sqlite3HashFind(tls, (**(**TDb)(__ccgo_up((*Tsqlite3)(unsafe.Pointer(db)).FaDb + uintptr(i)*32))).FpSchema+8, __ccgo_ts+6277)
				}
			}
		}
	} else {
		/* Match against TEMP first */
		p = _sqlite3HashFind(tls, (**(**TDb)(__ccgo_up((*Tsqlite3)(unsafe.Pointer(db)).FaDb + 1*32))).FpSchema+8, zName)
		if p != 0 {
			return p
		}
		/* The main database is second */
		p = _sqlite3HashFind(tls, (**(**TDb)(__ccgo_up((*Tsqlite3)(unsafe.Pointer(db)).FaDb))).FpSchema+8, zName)
		if p != 0 {
			return p
		}
		/* Attached databases are in order of attachment */
		i = int32(2)
		for {
			if !(i < (*Tsqlite3)(unsafe.Pointer(db)).FnDb) {
				break
			}
			p = _sqlite3HashFind(tls, (**(**TDb)(__ccgo_up((*Tsqlite3)(unsafe.Pointer(db)).FaDb + uintptr(i)*32))).FpSchema+8, zName)
			if p != 0 {
				break
			}
			goto _2
		_2:
			;
			i = i + 1
		}
		if p == uintptr(0) && Xsqlite3_strnicmp(tls, zName, __ccgo_ts+6749, int32(7)) == 0 {
			if _sqlite3StrICmp(tls, zName+uintptr(7), __ccgo_ts+6795+7) == 0 {
				p = _sqlite3HashFind(tls, (**(**TDb)(__ccgo_up((*Tsqlite3)(unsafe.Pointer(db)).FaDb))).FpSchema+8, __ccgo_ts+6277)
			} else {
				if _sqlite3StrICmp(tls, zName+uintptr(7), __ccgo_ts+6776+7) == 0 {
					p = _sqlite3HashFind(tls, (**(**TDb)(__ccgo_up((*Tsqlite3)(unsafe.Pointer(db)).FaDb + 1*32))).FpSchema+8, __ccgo_ts+6757)
				}
			}
		}
	}
	return p
}

// C documentation
//
//	/*
//	** This routine is called after all of the trigger actions have been parsed
//	** in order to complete the process of building the trigger.
//	*/
func _sqlite3FinishTrigger(tls *libc.TLS, pParse uintptr, pStepList uintptr, pAll uintptr) {
	bp := tls.Alloc(160)
	defer tls.Free(160)
	var db, pHash, pLink, pStep, pTab, pTrig, v, z, zName uintptr
	var iDb int32
	var _ /* nameToken at bp+96 */ TToken
	var _ /* sFix at bp+0 */ TDbFixer
	_, _, _, _, _, _, _, _, _, _ = db, iDb, pHash, pLink, pStep, pTab, pTrig, v, z, zName
	pTrig = (*TParse)(unsafe.Pointer(pParse)).FpNewTrigger /* Name of trigger */
	db = (*TParse)(unsafe.Pointer(pParse)).Fdb             /* Trigger name for error reporting */
	(*TParse)(unsafe.Pointer(pParse)).FpNewTrigger = uintptr(0)
	if (*TParse)(unsafe.Pointer(pParse)).FnErr != 0 || !(pTrig != 0) {
		goto triggerfinish_cleanup
	}
	zName = (*TTrigger)(unsafe.Pointer(pTrig)).FzName
	iDb = _sqlite3SchemaToIndex(tls, (*TParse)(unsafe.Pointer(pParse)).Fdb, (*TTrigger)(unsafe.Pointer(pTrig)).FpSchema)
	(*TTrigger)(unsafe.Pointer(pTrig)).Fstep_list = pStepList
	for pStepList != 0 {
		(*TTriggerStep)(unsafe.Pointer(pStepList)).FpTrig = pTrig
		pStepList = (*TTriggerStep)(unsafe.Pointer(pStepList)).FpNext
	}
	_sqlite3TokenInit(tls, bp+96, (*TTrigger)(unsafe.Pointer(pTrig)).FzName)
	_sqlite3FixInit(tls, bp, pParse, iDb, __ccgo_ts+21875, bp+96)
	if _sqlite3FixTriggerStep(tls, bp, (*TTrigger)(unsafe.Pointer(pTrig)).Fstep_list) != 0 || _sqlite3FixExpr(tls, bp, (*TTrigger)(unsafe.Pointer(pTrig)).FpWhen) != 0 {
		goto triggerfinish_cleanup
	}
	if libc.Int32FromUint8((*TParse)(unsafe.Pointer(pParse)).FeParseMode) >= int32(PARSE_MODE_RENAME) {
		(*TParse)(unsafe.Pointer(pParse)).FpNewTrigger = pTrig
		pTrig = uintptr(0)
	} else {
		/* if we are not initializing,
		 ** build the sqlite_schema entry
		 */
		if !((*Tsqlite3)(unsafe.Pointer(db)).Finit1.Fbusy != 0) {
			/* If this is a new CREATE TABLE statement, and if shadow tables
			 ** are read-only, and the trigger makes a change to a shadow table,
			 ** then raise an error - do not allow the trigger to be created. */
			if _sqlite3ReadOnlyShadowTables(tls, db) != 0 {
				pStep = (*TTrigger)(unsafe.Pointer(pTrig)).Fstep_list
				for {
					if !(pStep != 0) {
						break
					}
					if (*TTriggerStep)(unsafe.Pointer(pStep)).FpSrc != uintptr(0) && _sqlite3ShadowTableName(tls, db, (*(*TSrcItem)(unsafe.Pointer((*TTriggerStep)(unsafe.Pointer(pStep)).FpSrc + 8))).FzName) != 0 {
						_sqlite3ErrorMsg(tls, pParse, __ccgo_ts+22124, libc.VaList(bp+120, (*TTrigger)(unsafe.Pointer(pTrig)).FzName, (*(*TSrcItem)(unsafe.Pointer((*TTriggerStep)(unsafe.Pointer(pStep)).FpSrc + 8))).FzName))
						goto triggerfinish_cleanup
					}
					goto _1
				_1:
					;
					pStep = (*TTriggerStep)(unsafe.Pointer(pStep)).FpNext
				}
			}
			/* Make an entry in the sqlite_schema table */
			v = _sqlite3GetVdbe(tls, pParse)
			if v == uintptr(0) {
				goto triggerfinish_cleanup
			}
			_sqlite3BeginWriteOperation(tls, pParse, 0, iDb)
			z = _sqlite3DbStrNDup(tls, db, (*TToken)(unsafe.Pointer(pAll)).Fz, uint64((*TToken)(unsafe.Pointer(pAll)).Fn))
			_sqlite3NestedParse(tls, pParse, __ccgo_ts+22172, libc.VaList(bp+120, (**(**TDb)(__ccgo_up((*Tsqlite3)(unsafe.Pointer(db)).FaDb + uintptr(iDb)*32))).FzDbSName, zName, (*TTrigger)(unsafe.Pointer(pTrig)).Ftable, z))
			_sqlite3DbFree(tls, db, z)
			_sqlite3ChangeCookie(tls, pParse, iDb)
			_sqlite3VdbeAddParseSchemaOp(tls, v, iDb, _sqlite3MPrintf(tls, db, __ccgo_ts+22247, libc.VaList(bp+120, zName)), uint16(0))
		}
	}
	if (*Tsqlite3)(unsafe.Pointer(db)).Finit1.Fbusy != 0 {
		pLink = pTrig
		pHash = (**(**TDb)(__ccgo_up((*Tsqlite3)(unsafe.Pointer(db)).FaDb + uintptr(iDb)*32))).FpSchema + 56
		pTrig = _sqlite3HashInsert(tls, pHash, zName, pTrig)
		if pTrig != 0 {
			_sqlite3OomFault(tls, db)
		} else {
			if (*TTrigger)(unsafe.Pointer(pLink)).FpSchema == (*TTrigger)(unsafe.Pointer(pLink)).FpTabSchema {
				pTab = _sqlite3HashFind(tls, (*TTrigger)(unsafe.Pointer(pLink)).FpTabSchema+8, (*TTrigger)(unsafe.Pointer(pLink)).Ftable)
				(*TTrigger)(unsafe.Pointer(pLink)).FpNext = (*TTable)(unsafe.Pointer(pTab)).FpTrigger
				(*TTable)(unsafe.Pointer(pTab)).FpTrigger = pLink
			}
		}
	}
	goto triggerfinish_cleanup
triggerfinish_cleanup:
	;
	_sqlite3DeleteTrigger(tls, db, pTrig)
	_sqlite3DeleteTriggerStep(tls, db, pStepList)
}

// C documentation
//
//	/*
//	** A foreign key constraint requires that the key columns in the parent
//	** table are collectively subject to a UNIQUE or PRIMARY KEY constraint.
//	** Given that pParent is the parent table for foreign key constraint pFKey,
//	** search the schema for a unique index on the parent key columns.
//	**
//	** If successful, zero is returned. If the parent key is an INTEGER PRIMARY
//	** KEY column, then output variable *ppIdx is set to NULL. Otherwise, *ppIdx
//	** is set to point to the unique index.
//	**
//	** If the parent key consists of a single column (the foreign key constraint
//	** is not a composite foreign key), output variable *paiCol is set to NULL.
//	** Otherwise, it is set to point to an allocated array of size N, where
//	** N is the number of columns in the parent key. The first element of the
//	** array is the index of the child table column that is mapped by the FK
//	** constraint to the parent table column stored in the left-most column
//	** of index *ppIdx. The second element of the array is the index of the
//	** child table column that corresponds to the second left-most column of
//	** *ppIdx, and so on.
//	**
//	** If the required index cannot be found, either because:
//	**
//	**   1) The named parent key columns do not exist, or
//	**
//	**   2) The named parent key columns do exist, but are not subject to a
//	**      UNIQUE or PRIMARY KEY constraint, or
//	**
//	**   3) No parent key columns were provided explicitly as part of the
//	**      foreign key definition, and the parent table does not have a
//	**      PRIMARY KEY, or
//	**
//	**   4) No parent key columns were provided explicitly as part of the
//	**      foreign key definition, and the PRIMARY KEY of the parent table
//	**      consists of a different number of columns to the child key in
//	**      the child table.
//	**
//	** then non-zero is returned, and a "foreign key mismatch" error loaded
//	** into pParse. If an OOM error occurs, non-zero is returned and the
//	** pParse->db->mallocFailed flag is set.
//	*/
func _sqlite3FkLocateIndex(tls *libc.TLS, pParse uintptr, pParent uintptr, pFKey uintptr, ppIdx uintptr, paiCol uintptr) (r int32) {
	bp := tls.Alloc(32)
	defer tls.Free(32)
	var aiCol, pIdx, zDfltColl, zIdxCol, zKey uintptr
	var i, i1, j, nCol int32
	var iCol Ti16
	_, _, _, _, _, _, _, _, _, _ = aiCol, i, i1, iCol, j, nCol, pIdx, zDfltColl, zIdxCol, zKey
	pIdx = uintptr(0)                                       /* Value to return via *ppIdx */
	aiCol = uintptr(0)                                      /* Value to return via *paiCol */
	nCol = (*TFKey)(unsafe.Pointer(pFKey)).FnCol            /* Number of columns in parent key */
	zKey = (*(*TsColMap)(unsafe.Pointer(pFKey + 64))).FzCol /* Name of left-most parent key column */
	/* The caller is responsible for zeroing output parameters. */
	/* If this is a non-composite (single column) foreign key, check if it
	 ** maps to the INTEGER PRIMARY KEY of table pParent. If so, leave *ppIdx
	 ** and *paiCol set to zero and return early.
	 **
	 ** Otherwise, for a composite foreign key (more than one column), allocate
	 ** space for the aiCol array (returned via output parameter *paiCol).
	 ** Non-composite foreign keys do not require the aiCol array.
	 */
	if nCol == int32(1) {
		/* The FK maps to the IPK if any of the following are true:
		 **
		 **   1) There is an INTEGER PRIMARY KEY column and the FK is implicitly
		 **      mapped to the primary key of table pParent, or
		 **   2) The FK is explicitly mapped to a column declared as INTEGER
		 **      PRIMARY KEY.
		 */
		if int32((*TTable)(unsafe.Pointer(pParent)).FiPKey) >= 0 {
			if !(zKey != 0) {
				return 0
			}
			if !(_sqlite3StrICmp(tls, (**(**TColumn)(__ccgo_up((*TTable)(unsafe.Pointer(pParent)).FaCol + uintptr((*TTable)(unsafe.Pointer(pParent)).FiPKey)*16))).FzCnName, zKey) != 0) {
				return 0
			}
		}
	} else {
		if paiCol != 0 {
			aiCol = _sqlite3DbMallocRawNN(tls, (*TParse)(unsafe.Pointer(pParse)).Fdb, uint64(libc.Uint64FromInt32(nCol)*uint64(4)))
			if !(aiCol != 0) {
				return int32(1)
			}
			**(**uintptr)(__ccgo_up(paiCol)) = aiCol
		}
	}
	pIdx = (*TTable)(unsafe.Pointer(pParent)).FpIndex
	for {
		if !(pIdx != 0) {
			break
		}
		if libc.Int32FromUint16((*TIndex)(unsafe.Pointer(pIdx)).FnKeyCol) == nCol && libc.Int32FromUint8((*TIndex)(unsafe.Pointer(pIdx)).FonError) != OE_None && (*TIndex)(unsafe.Pointer(pIdx)).FpPartIdxWhere == uintptr(0) {
			/* pIdx is a UNIQUE index (or a PRIMARY KEY) and has the right number
			 ** of columns. If each indexed column corresponds to a foreign key
			 ** column of pFKey, then this index is a winner.  */
			if zKey == uintptr(0) {
				/* If zKey is NULL, then this foreign key is implicitly mapped to
				 ** the PRIMARY KEY of table pParent. The PRIMARY KEY index may be
				 ** identified by the test.  */
				if int32(uint32(*(*uint16)(unsafe.Pointer(pIdx + 100))&0x3>>0)) == int32(SQLITE_IDXTYPE_PRIMARYKEY) {
					if aiCol != 0 {
						i = 0
						for {
							if !(i < nCol) {
								break
							}
							**(**int32)(__ccgo_up(aiCol + uintptr(i)*4)) = (*(*TsColMap)(unsafe.Pointer(pFKey + 64 + uintptr(i)*16))).FiFrom
							goto _2
						_2:
							;
							i = i + 1
						}
					}
					break
				}
			} else {
				i1 = 0
				for {
					if !(i1 < nCol) {
						break
					}
					iCol = **(**Ti16)(__ccgo_up((*TIndex)(unsafe.Pointer(pIdx)).FaiColumn + uintptr(i1)*2)) /* Name of indexed column */
					if int32(iCol) < 0 {
						break
					} /* No foreign keys against expression indexes */
					/* If the index uses a collation sequence that is different from
					 ** the default collation sequence for the column, this index is
					 ** unusable. Bail out early in this case.  */
					zDfltColl = _sqlite3ColumnColl(tls, (*TTable)(unsafe.Pointer(pParent)).FaCol+uintptr(iCol)*16)
					if !(zDfltColl != 0) {
						zDfltColl = uintptr(unsafe.Pointer(&_sqlite3StrBINARY))
					}
					if _sqlite3StrICmp(tls, **(**uintptr)(__ccgo_up((*TIndex)(unsafe.Pointer(pIdx)).FazColl + uintptr(i1)*8)), zDfltColl) != 0 {
						break
					}
					zIdxCol = (**(**TColumn)(__ccgo_up((*TTable)(unsafe.Pointer(pParent)).FaCol + uintptr(iCol)*16))).FzCnName
					j = 0
					for {
						if !(j < nCol) {
							break
						}
						if _sqlite3StrICmp(tls, (*(*TsColMap)(unsafe.Pointer(pFKey + 64 + uintptr(j)*16))).FzCol, zIdxCol) == 0 {
							if aiCol != 0 {
								**(**int32)(__ccgo_up(aiCol + uintptr(i1)*4)) = (*(*TsColMap)(unsafe.Pointer(pFKey + 64 + uintptr(j)*16))).FiFrom
							}
							break
						}
						goto _4
					_4:
						;
						j = j + 1
					}
					if j == nCol {
						break
					}
					goto _3
				_3:
					;
					i1 = i1 + 1
				}
				if i1 == nCol {
					break
				} /* pIdx is usable */
			}
		}
		goto _1
	_1:
		;
		pIdx = (*TIndex)(unsafe.Pointer(pIdx)).FpNext
	}
	if !(pIdx != 0) {
		if !(int32(Tbft(*(*uint16)(unsafe.Pointer(pParse + 40))&0x1>>0)) != 0) {
			_sqlite3ErrorMsg(tls, pParse, __ccgo_ts+17293, libc.VaList(bp+8, (*TTable)(unsafe.Pointer((*TFKey)(unsafe.Pointer(pFKey)).FpFrom)).FzName, (*TFKey)(unsafe.Pointer(pFKey)).FzTo))
		}
		_sqlite3DbFree(tls, (*TParse)(unsafe.Pointer(pParse)).Fdb, aiCol)
		return int32(1)
	}
	**(**uintptr)(__ccgo_up(ppIdx)) = pIdx
	return 0
}

func _sqlite3Fts5AuxInit(tls *libc.TLS, pApi uintptr) (r int32) {
	var aBuiltin [4]struct {
		FzFunc     uintptr
		FpUserData uintptr
		FxFunc     Tfts5_extension_function
		FxDestroy  uintptr
	}
	var i, rc int32
	_, _, _ = aBuiltin, i, rc
	aBuiltin = [4]struct {
		FzFunc     uintptr
		FpUserData uintptr
		FxFunc     Tfts5_extension_function
		FxDestroy  uintptr
	}{
		0: {
			FzFunc: __ccgo_ts + 37357,
			FxFunc: __ccgo_fp(_fts5SnippetFunction),
		},
		1: {
			FzFunc: __ccgo_ts + 37365,
			FxFunc: __ccgo_fp(_fts5HighlightFunction),
		},
		2: {
			FzFunc: __ccgo_ts + 37375,
			FxFunc: __ccgo_fp(_fts5Bm25Function),
		},
		3: {
			FzFunc: __ccgo_ts + 37380,
			FxFunc: __ccgo_fp(_fts5GetLocaleFunction),
		},
	}
	rc = SQLITE_OK /* To iterate through builtin functions */
	i = 0
	for {
		if !(rc == SQLITE_OK && i < libc.Int32FromUint64(libc.Uint64FromInt64(128)/libc.Uint64FromInt64(32))) {
			break
		}
		rc = (*(*func(*libc.TLS, uintptr, uintptr, uintptr, Tfts5_extension_function, uintptr) int32)(unsafe.Pointer(&struct{ uintptr }{(*Tfts5_api)(unsafe.Pointer(pApi)).FxCreateFunction})))(tls, pApi, aBuiltin[i].FzFunc, aBuiltin[i].FpUserData, aBuiltin[i].FxFunc, aBuiltin[i].FxDestroy)
		goto _1
	_1:
		;
		i = i + 1
	}
	return rc
}

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

/* #include "fts5Int.h" */

// C documentation
//
//	/*
//	** Call sqlite3_declare_vtab() based on the contents of the configuration
//	** object passed as the only argument. Return SQLITE_OK if successful, or
//	** an SQLite error code if an error occurs.
//	*/
func _sqlite3Fts5ConfigDeclareVtab(tls *libc.TLS, pConfig uintptr) (r int32) {
	bp := tls.Alloc(48)
	defer tls.Free(48)
	var i int32
	var zSep, zSql, v2 uintptr
	var _ /* rc at bp+0 */ int32
	_, _, _, _ = i, zSep, zSql, v2
	**(**int32)(__ccgo_up(bp)) = SQLITE_OK
	zSql = _sqlite3Fts5Mprintf(tls, bp, __ccgo_ts+38294, 0)
	i = 0
	for {
		if !(zSql != 0 && i < (*TFts5Config)(unsafe.Pointer(pConfig)).FnCol) {
			break
		}
		if i == 0 {
			v2 = __ccgo_ts + 1693
		} else {
			v2 = __ccgo_ts + 16207
		}
		zSep = v2
		zSql = _sqlite3Fts5Mprintf(tls, bp, __ccgo_ts+38310, libc.VaList(bp+16, zSql, zSep, **(**uintptr)(__ccgo_up((*TFts5Config)(unsafe.Pointer(pConfig)).FazCol + uintptr(i)*8))))
		goto _1
	_1:
		;
		i = i + 1
	}
	zSql = _sqlite3Fts5Mprintf(tls, bp, __ccgo_ts+38317, libc.VaList(bp+16, zSql, (*TFts5Config)(unsafe.Pointer(pConfig)).FzName, __ccgo_ts+37957))
	if zSql != 0 {
		**(**int32)(__ccgo_up(bp)) = Xsqlite3_declare_vtab(tls, (*TFts5Config)(unsafe.Pointer(pConfig)).Fdb, zSql)
		Xsqlite3_free(tls, zSql)
	}
	return **(**int32)(__ccgo_up(bp))
}

// C documentation
//
//	/*
//	** Load the contents of the %_config table into memory.
//	*/
func _sqlite3Fts5ConfigLoad(tls *libc.TLS, pConfig uintptr, iCookie int32) (r int32) {
	bp := tls.Alloc(48)
	defer tls.Free(48)
	var iVersion int32
	var pVal, zK, zSelect, zSql uintptr
	var _ /* bDummy at bp+12 */ int32
	var _ /* p at bp+0 */ uintptr
	var _ /* rc at bp+8 */ int32
	_, _, _, _, _ = iVersion, pVal, zK, zSelect, zSql
	zSelect = __ccgo_ts + 38425
	**(**uintptr)(__ccgo_up(bp)) = uintptr(0)
	**(**int32)(__ccgo_up(bp + 8)) = SQLITE_OK
	iVersion = 0
	/* Set default values */
	(*TFts5Config)(unsafe.Pointer(pConfig)).Fpgsz = int32(FTS5_DEFAULT_PAGE_SIZE)
	(*TFts5Config)(unsafe.Pointer(pConfig)).FnAutomerge = int32(FTS5_DEFAULT_AUTOMERGE)
	(*TFts5Config)(unsafe.Pointer(pConfig)).FnUsermerge = int32(FTS5_DEFAULT_USERMERGE)
	(*TFts5Config)(unsafe.Pointer(pConfig)).FnCrisisMerge = int32(FTS5_DEFAULT_CRISISMERGE)
	(*TFts5Config)(unsafe.Pointer(pConfig)).FnHashSize = libc.Int32FromInt32(1024) * libc.Int32FromInt32(1024)
	(*TFts5Config)(unsafe.Pointer(pConfig)).FnDeleteMerge = int32(FTS5_DEFAULT_DELETE_AUTOMERGE)
	zSql = _sqlite3Fts5Mprintf(tls, bp+8, zSelect, libc.VaList(bp+24, (*TFts5Config)(unsafe.Pointer(pConfig)).FzDb, (*TFts5Config)(unsafe.Pointer(pConfig)).FzName))
	if zSql != 0 {
		**(**int32)(__ccgo_up(bp + 8)) = Xsqlite3_prepare_v2(tls, (*TFts5Config)(unsafe.Pointer(pConfig)).Fdb, zSql, -int32(1), bp, uintptr(0))
		Xsqlite3_free(tls, zSql)
	}
	if **(**int32)(__ccgo_up(bp + 8)) == SQLITE_OK {
		for int32(SQLITE_ROW) == Xsqlite3_step(tls, **(**uintptr)(__ccgo_up(bp))) {
			zK = Xsqlite3_column_text(tls, **(**uintptr)(__ccgo_up(bp)), 0)
			pVal = Xsqlite3_column_value(tls, **(**uintptr)(__ccgo_up(bp)), int32(1))
			if 0 == Xsqlite3_stricmp(tls, zK, __ccgo_ts+38457) {
				iVersion = Xsqlite3_value_int(tls, pVal)
			} else {
				**(**int32)(__ccgo_up(bp + 12)) = 0
				_sqlite3Fts5ConfigSetValue(tls, pConfig, zK, pVal, bp+12)
			}
		}
		**(**int32)(__ccgo_up(bp + 8)) = Xsqlite3_finalize(tls, **(**uintptr)(__ccgo_up(bp)))
	}
	if **(**int32)(__ccgo_up(bp + 8)) == SQLITE_OK && iVersion != int32(FTS5_CURRENT_VERSION) && iVersion != int32(FTS5_CURRENT_VERSION_SECUREDELETE) {
		**(**int32)(__ccgo_up(bp + 8)) = int32(SQLITE_ERROR)
		_sqlite3Fts5ConfigErrmsg(tls, pConfig, __ccgo_ts+38465, libc.VaList(bp+24, iVersion, int32(FTS5_CURRENT_VERSION), int32(FTS5_CURRENT_VERSION_SECUREDELETE)))
	} else {
		(*TFts5Config)(unsafe.Pointer(pConfig)).FiVersion = iVersion
	}
	if **(**int32)(__ccgo_up(bp + 8)) == SQLITE_OK {
		(*TFts5Config)(unsafe.Pointer(pConfig)).FiCookie = iCookie
	}
	return **(**int32)(__ccgo_up(bp + 8))
}

func _sqlite3Fts5ConfigSetValue(tls *libc.TLS, pConfig uintptr, zKey uintptr, pVal uintptr, pbBadkey uintptr) (r int32) {
	bp := tls.Alloc(16)
	defer tls.Free(16)
	var bVal, bVal1, nAutomerge, nCrisisMerge, nHashSize, nUsermerge, nVal, pgsz, rc, v1 int32
	var zIn uintptr
	var _ /* zRank at bp+0 */ uintptr
	var _ /* zRankArgs at bp+8 */ uintptr
	_, _, _, _, _, _, _, _, _, _, _ = bVal, bVal1, nAutomerge, nCrisisMerge, nHashSize, nUsermerge, nVal, pgsz, rc, zIn, v1
	rc = SQLITE_OK
	if 0 == Xsqlite3_stricmp(tls, zKey, __ccgo_ts+38343) {
		pgsz = 0
		if int32(SQLITE_INTEGER) == Xsqlite3_value_numeric_type(tls, pVal) {
			pgsz = Xsqlite3_value_int(tls, pVal)
		}
		if pgsz < int32(32) || pgsz > libc.Int32FromInt32(64)*libc.Int32FromInt32(1024) {
			**(**int32)(__ccgo_up(pbBadkey)) = int32(1)
		} else {
			(*TFts5Config)(unsafe.Pointer(pConfig)).Fpgsz = pgsz
		}
	} else {
		if 0 == Xsqlite3_stricmp(tls, zKey, __ccgo_ts+38348) {
			nHashSize = -int32(1)
			if int32(SQLITE_INTEGER) == Xsqlite3_value_numeric_type(tls, pVal) {
				nHashSize = Xsqlite3_value_int(tls, pVal)
			}
			if nHashSize <= 0 {
				**(**int32)(__ccgo_up(pbBadkey)) = int32(1)
			} else {
				(*TFts5Config)(unsafe.Pointer(pConfig)).FnHashSize = nHashSize
			}
		} else {
			if 0 == Xsqlite3_stricmp(tls, zKey, __ccgo_ts+38357) {
				nAutomerge = -int32(1)
				if int32(SQLITE_INTEGER) == Xsqlite3_value_numeric_type(tls, pVal) {
					nAutomerge = Xsqlite3_value_int(tls, pVal)
				}
				if nAutomerge < 0 || nAutomerge > int32(64) {
					**(**int32)(__ccgo_up(pbBadkey)) = int32(1)
				} else {
					if nAutomerge == int32(1) {
						nAutomerge = int32(FTS5_DEFAULT_AUTOMERGE)
					}
					(*TFts5Config)(unsafe.Pointer(pConfig)).FnAutomerge = nAutomerge
				}
			} else {
				if 0 == Xsqlite3_stricmp(tls, zKey, __ccgo_ts+38367) {
					nUsermerge = -int32(1)
					if int32(SQLITE_INTEGER) == Xsqlite3_value_numeric_type(tls, pVal) {
						nUsermerge = Xsqlite3_value_int(tls, pVal)
					}
					if nUsermerge < int32(2) || nUsermerge > int32(16) {
						**(**int32)(__ccgo_up(pbBadkey)) = int32(1)
					} else {
						(*TFts5Config)(unsafe.Pointer(pConfig)).FnUsermerge = nUsermerge
					}
				} else {
					if 0 == Xsqlite3_stricmp(tls, zKey, __ccgo_ts+38377) {
						nCrisisMerge = -int32(1)
						if int32(SQLITE_INTEGER) == Xsqlite3_value_numeric_type(tls, pVal) {
							nCrisisMerge = Xsqlite3_value_int(tls, pVal)
						}
						if nCrisisMerge < 0 {
							**(**int32)(__ccgo_up(pbBadkey)) = int32(1)
						} else {
							if nCrisisMerge <= int32(1) {
								nCrisisMerge = int32(FTS5_DEFAULT_CRISISMERGE)
							}
							if nCrisisMerge >= int32(FTS5_MAX_SEGMENT) {
								nCrisisMerge = libc.Int32FromInt32(FTS5_MAX_SEGMENT) - libc.Int32FromInt32(1)
							}
							(*TFts5Config)(unsafe.Pointer(pConfig)).FnCrisisMerge = nCrisisMerge
						}
					} else {
						if 0 == Xsqlite3_stricmp(tls, zKey, __ccgo_ts+38389) {
							nVal = -int32(1)
							if int32(SQLITE_INTEGER) == Xsqlite3_value_numeric_type(tls, pVal) {
								nVal = Xsqlite3_value_int(tls, pVal)
							} else {
								**(**int32)(__ccgo_up(pbBadkey)) = int32(1)
							}
							if nVal < 0 {
								nVal = int32(FTS5_DEFAULT_DELETE_AUTOMERGE)
							}
							if nVal > int32(100) {
								nVal = 0
							}
							(*TFts5Config)(unsafe.Pointer(pConfig)).FnDeleteMerge = nVal
						} else {
							if 0 == Xsqlite3_stricmp(tls, zKey, __ccgo_ts+37957) {
								zIn = Xsqlite3_value_text(tls, pVal)
								rc = _sqlite3Fts5ConfigParseRank(tls, zIn, bp, bp+8)
								if rc == SQLITE_OK {
									Xsqlite3_free(tls, (*TFts5Config)(unsafe.Pointer(pConfig)).FzRank)
									Xsqlite3_free(tls, (*TFts5Config)(unsafe.Pointer(pConfig)).FzRankArgs)
									(*TFts5Config)(unsafe.Pointer(pConfig)).FzRank = **(**uintptr)(__ccgo_up(bp))
									(*TFts5Config)(unsafe.Pointer(pConfig)).FzRankArgs = **(**uintptr)(__ccgo_up(bp + 8))
								} else {
									if rc == int32(SQLITE_ERROR) {
										rc = SQLITE_OK
										**(**int32)(__ccgo_up(pbBadkey)) = int32(1)
									}
								}
							} else {
								if 0 == Xsqlite3_stricmp(tls, zKey, __ccgo_ts+38401) {
									bVal = -int32(1)
									if int32(SQLITE_INTEGER) == Xsqlite3_value_numeric_type(tls, pVal) {
										bVal = Xsqlite3_value_int(tls, pVal)
									}
									if bVal < 0 {
										**(**int32)(__ccgo_up(pbBadkey)) = int32(1)
									} else {
										if bVal != 0 {
											v1 = int32(1)
										} else {
											v1 = 0
										}
										(*TFts5Config)(unsafe.Pointer(pConfig)).FbSecureDelete = v1
									}
								} else {
									if 0 == Xsqlite3_stricmp(tls, zKey, __ccgo_ts+38415) {
										bVal1 = -int32(1)
										if int32(SQLITE_INTEGER) == Xsqlite3_value_numeric_type(tls, pVal) {
											bVal1 = Xsqlite3_value_int(tls, pVal)
										}
										if bVal1 < 0 {
											**(**int32)(__ccgo_up(pbBadkey)) = int32(1)
										} else {
											if bVal1 != 0 {
												v1 = int32(1)
											} else {
												v1 = 0
											}
											(*TFts5Config)(unsafe.Pointer(pConfig)).FbPrefixInsttoken = v1
										}
									} else {
										**(**int32)(__ccgo_up(pbBadkey)) = int32(1)
									}
								}
							}
						}
					}
				}
			}
		}
	}
	return rc
}

// C documentation
//
//	/*
//	** Create the shadow table named zPost, with definition zDefn. Return
//	** SQLITE_OK if successful, or an SQLite error code otherwise.
//	*/
func _sqlite3Fts5CreateTable(tls *libc.TLS, pConfig uintptr, zPost uintptr, zDefn uintptr, bWithout int32, pzErr uintptr) (r int32) {
	bp := tls.Alloc(64)
	defer tls.Free(64)
	var rc int32
	var v1 uintptr
	var _ /* zErr at bp+0 */ uintptr
	_, _ = rc, v1
	**(**uintptr)(__ccgo_up(bp)) = uintptr(0)
	if bWithout != 0 {
		v1 = __ccgo_ts + 32072
	} else {
		v1 = __ccgo_ts + 1693
	}
	rc = _fts5ExecPrintf(tls, (*TFts5Config)(unsafe.Pointer(pConfig)).Fdb, bp, __ccgo_ts+41477, libc.VaList(bp+16, (*TFts5Config)(unsafe.Pointer(pConfig)).FzDb, (*TFts5Config)(unsafe.Pointer(pConfig)).FzName, zPost, zDefn, v1))
	if **(**uintptr)(__ccgo_up(bp)) != 0 {
		**(**uintptr)(__ccgo_up(pzErr)) = Xsqlite3_mprintf(tls, __ccgo_ts+41507, libc.VaList(bp+16, (*TFts5Config)(unsafe.Pointer(pConfig)).FzName, zPost, **(**uintptr)(__ccgo_up(bp))))
		Xsqlite3_free(tls, **(**uintptr)(__ccgo_up(bp)))
	}
	return rc
}

// C documentation
//
//	/*
//	** Drop all shadow tables. Return SQLITE_OK if successful or an SQLite error
//	** code otherwise.
//	*/
func _sqlite3Fts5DropAll(tls *libc.TLS, pConfig uintptr) (r int32) {
	bp := tls.Alloc(64)
	defer tls.Free(64)
	var rc int32
	_ = rc
	rc = _fts5ExecPrintf(tls, (*TFts5Config)(unsafe.Pointer(pConfig)).Fdb, uintptr(0), __ccgo_ts+41255, libc.VaList(bp+8, (*TFts5Config)(unsafe.Pointer(pConfig)).FzDb, (*TFts5Config)(unsafe.Pointer(pConfig)).FzName, (*TFts5Config)(unsafe.Pointer(pConfig)).FzDb, (*TFts5Config)(unsafe.Pointer(pConfig)).FzName, (*TFts5Config)(unsafe.Pointer(pConfig)).FzDb, (*TFts5Config)(unsafe.Pointer(pConfig)).FzName))
	if rc == SQLITE_OK && (*TFts5Config)(unsafe.Pointer(pConfig)).FbColumnsize != 0 {
		rc = _fts5ExecPrintf(tls, (*TFts5Config)(unsafe.Pointer(pConfig)).Fdb, uintptr(0), __ccgo_ts+41359, libc.VaList(bp+8, (*TFts5Config)(unsafe.Pointer(pConfig)).FzDb, (*TFts5Config)(unsafe.Pointer(pConfig)).FzName))
	}
	if rc == SQLITE_OK && (*TFts5Config)(unsafe.Pointer(pConfig)).FeContent == FTS5_CONTENT_NORMAL {
		rc = _fts5ExecPrintf(tls, (*TFts5Config)(unsafe.Pointer(pConfig)).Fdb, uintptr(0), __ccgo_ts+41397, libc.VaList(bp+8, (*TFts5Config)(unsafe.Pointer(pConfig)).FzDb, (*TFts5Config)(unsafe.Pointer(pConfig)).FzName))
	}
	return rc
}

// C documentation
//
//	/*
//	** Run internal checks to ensure that the FTS index (a) is internally
//	** consistent and (b) contains entries for which the XOR of the checksums
//	** as calculated by sqlite3Fts5IndexEntryCksum() is cksum.
//	**
//	** Return SQLITE_CORRUPT if any of the internal checks fail, or if the
//	** checksum does not match. Return SQLITE_OK if all checks pass without
//	** error, or some other SQLite error code if another error (e.g. OOM)
//	** occurs.
//	*/
func _sqlite3Fts5IndexIntegrityCheck(tls *libc.TLS, p uintptr, cksum Tu64, bUseCksum int32) (r int32) {
	bp := tls.Alloc(64)
	defer tls.Free(64)
	var cksum2 Tu64
	var eDetail, flags, iCol, iLvl, iSeg, iTokOff int32
	var iRowid Ti64
	var pSeg, pStruct, z uintptr
	var _ /* iOff at bp+40 */ int32
	var _ /* iPos at bp+32 */ Ti64
	var _ /* n at bp+24 */ int32
	var _ /* pIter at bp+16 */ uintptr
	var _ /* poslist at bp+0 */ TFts5Buffer
	_, _, _, _, _, _, _, _, _, _, _ = cksum2, eDetail, flags, iCol, iLvl, iRowid, iSeg, iTokOff, pSeg, pStruct, z
	eDetail = (*TFts5Config)(unsafe.Pointer((*TFts5Index)(unsafe.Pointer(p)).FpConfig)).FeDetail
	cksum2 = uint64(0) /* Checksum based on contents of indexes */
	**(**TFts5Buffer)(__ccgo_up(bp)) = TFts5Buffer{}
	flags = int32(FTS5INDEX_QUERY_NOOUTPUT)
	/* Load the FTS index structure */
	pStruct = _fts5StructureRead(tls, p)
	if pStruct == uintptr(0) {
		return _fts5IndexReturn(tls, p)
	}
	/* Check that the internal nodes of each segment match the leaves */
	iLvl = 0
	for {
		if !(iLvl < (*TFts5Structure)(unsafe.Pointer(pStruct)).FnLevel) {
			break
		}
		iSeg = 0
		for {
			if !(iSeg < (*(*TFts5StructureLevel)(unsafe.Pointer(pStruct + 32 + uintptr(iLvl)*16))).FnSeg) {
				break
			}
			pSeg = (*(*TFts5StructureLevel)(unsafe.Pointer(pStruct + 32 + uintptr(iLvl)*16))).FaSeg + uintptr(iSeg)*56
			_fts5IndexIntegrityCheckSegment(tls, p, pSeg)
			goto _2
		_2:
			;
			iSeg = iSeg + 1
		}
		goto _1
	_1:
		;
		iLvl = iLvl + 1
	}
	/* The cksum argument passed to this function is a checksum calculated
	 ** based on all expected entries in the FTS index (including prefix index
	 ** entries). This block checks that a checksum calculated based on the
	 ** actual contents of FTS index is identical.
	 **
	 ** Two versions of the same checksum are calculated. The first (stack
	 ** variable cksum2) based on entries extracted from the full-text index
	 ** while doing a linear scan of each individual index in turn.
	 **
	 ** As each term visited by the linear scans, a separate query for the
	 ** same term is performed. cksum3 is calculated based on the entries
	 ** extracted by these queries.
	 */
	_fts5MultiIterNew(tls, p, pStruct, flags, uintptr(0), uintptr(0), 0, -int32(1), 0, bp+16)
	for {
		if !(_fts5MultiIterEof(tls, p, **(**uintptr)(__ccgo_up(bp + 16))) == 0) {
			break
		} /* Size of term in bytes */
		**(**Ti64)(__ccgo_up(bp + 32)) = 0  /* Position read from poslist */
		**(**int32)(__ccgo_up(bp + 40)) = 0 /* Offset within poslist */
		iRowid = _fts5MultiIterRowid(tls, **(**uintptr)(__ccgo_up(bp + 16)))
		z = _fts5MultiIterTerm(tls, **(**uintptr)(__ccgo_up(bp + 16)), bp+24)
		/* If this is a new term, query for it. Update cksum3 with the results. */
		if (*TFts5Index)(unsafe.Pointer(p)).Frc != 0 {
			break
		}
		if eDetail == int32(FTS5_DETAIL_NONE) {
			if 0 == _fts5MultiIterIsEmpty(tls, p, **(**uintptr)(__ccgo_up(bp + 16))) {
				cksum2 = cksum2 ^ _sqlite3Fts5IndexEntryCksum(tls, iRowid, 0, 0, -int32(1), z, **(**int32)(__ccgo_up(bp + 24)))
			}
		} else {
			(**(**TFts5Buffer)(__ccgo_up(bp))).Fn = 0
			_fts5SegiterPoslist(tls, p, **(**uintptr)(__ccgo_up(bp + 16))+104+uintptr((**(**TFts5CResult)(__ccgo_up((*TFts5Iter)(unsafe.Pointer(**(**uintptr)(__ccgo_up(bp + 16)))).FaFirst + 1*4))).FiFirst)*128, uintptr(0), bp)
			_sqlite3Fts5BufferAppendBlob(tls, p+60, bp, uint32(4), __ccgo_ts+39661)
			for 0 == _sqlite3Fts5PoslistNext64(tls, (**(**TFts5Buffer)(__ccgo_up(bp))).Fp, (**(**TFts5Buffer)(__ccgo_up(bp))).Fn, bp+40, bp+32) {
				iCol = int32(**(**Ti64)(__ccgo_up(bp + 32)) >> libc.Int32FromInt32(32) & libc.Int64FromInt32(0x7FFFFFFF))
				iTokOff = int32(**(**Ti64)(__ccgo_up(bp + 32)) & libc.Int64FromInt32(0x7FFFFFFF))
				cksum2 = cksum2 ^ _sqlite3Fts5IndexEntryCksum(tls, iRowid, iCol, iTokOff, -int32(1), z, **(**int32)(__ccgo_up(bp + 24)))
			}
		}
		goto _3
	_3:
		;
		_fts5MultiIterNext(tls, p, **(**uintptr)(__ccgo_up(bp + 16)), 0, 0)
	}
	_fts5MultiIterFree(tls, **(**uintptr)(__ccgo_up(bp + 16)))
	if (*TFts5Index)(unsafe.Pointer(p)).Frc == SQLITE_OK && bUseCksum != 0 && cksum != cksum2 {
		(*TFts5Index)(unsafe.Pointer(p)).Frc = libc.Int32FromInt32(SQLITE_CORRUPT) | libc.Int32FromInt32(1)<<libc.Int32FromInt32(8)
		_sqlite3Fts5ConfigErrmsg(tls, (*TFts5Index)(unsafe.Pointer(p)).FpConfig, __ccgo_ts+39666, libc.VaList(bp+56, (*TFts5Config)(unsafe.Pointer((*TFts5Index)(unsafe.Pointer(p)).FpConfig)).FzName))
	}
	_fts5StructureRelease(tls, pStruct)
	_sqlite3Fts5BufferFree(tls, bp)
	return _fts5IndexReturn(tls, p)
}

/*************************************************************************
**************************************************************************
** Below this point is the implementation of the fts5_decode() scalar
** function only.
 */

// C documentation
//
//	/*
//	** Open a new Fts5Index handle. If the bCreate argument is true, create
//	** and initialize the underlying %_data table.
//	**
//	** If successful, set *pp to point to the new object and return SQLITE_OK.
//	** Otherwise, set *pp to NULL and return an SQLite error code.
//	*/
func _sqlite3Fts5IndexOpen(tls *libc.TLS, pConfig uintptr, bCreate int32, pp uintptr, pzErr uintptr) (r int32) {
	bp := tls.Alloc(32)
	defer tls.Free(32)
	var p, v1 uintptr
	var _ /* rc at bp+0 */ int32
	_, _ = p, v1
	**(**int32)(__ccgo_up(bp)) = SQLITE_OK /* New object */
	v1 = _sqlite3Fts5MallocZero(tls, bp, int64(168))
	p = v1
	**(**uintptr)(__ccgo_up(pp)) = v1
	if **(**int32)(__ccgo_up(bp)) == SQLITE_OK {
		(*TFts5Index)(unsafe.Pointer(p)).FpConfig = pConfig
		(*TFts5Index)(unsafe.Pointer(p)).FnWorkUnit = int32(FTS5_WORK_UNIT)
		(*TFts5Index)(unsafe.Pointer(p)).FzDataTbl = _sqlite3Fts5Mprintf(tls, bp, __ccgo_ts+39486, libc.VaList(bp+16, (*TFts5Config)(unsafe.Pointer(pConfig)).FzName))
		if (*TFts5Index)(unsafe.Pointer(p)).FzDataTbl != 0 && bCreate != 0 {
			**(**int32)(__ccgo_up(bp)) = _sqlite3Fts5CreateTable(tls, pConfig, __ccgo_ts+27397, __ccgo_ts+39494, 0, pzErr)
			if **(**int32)(__ccgo_up(bp)) == SQLITE_OK {
				**(**int32)(__ccgo_up(bp)) = _sqlite3Fts5CreateTable(tls, pConfig, __ccgo_ts+13037, __ccgo_ts+39529, int32(1), pzErr)
			}
			if **(**int32)(__ccgo_up(bp)) == SQLITE_OK {
				**(**int32)(__ccgo_up(bp)) = _sqlite3Fts5IndexReinit(tls, p)
			}
		}
	}
	if **(**int32)(__ccgo_up(bp)) != 0 {
		_sqlite3Fts5IndexClose(tls, p)
		**(**uintptr)(__ccgo_up(pp)) = uintptr(0)
	}
	return **(**int32)(__ccgo_up(bp))
}

// C documentation
//
//	/*
//	** The %_data table is completely empty when this function is called. This
//	** function populates it with the initial structure objects for each index,
//	** and the initial version of the "averages" record (a zero-byte blob).
//	*/
func _sqlite3Fts5IndexReinit(tls *libc.TLS, p uintptr) (r int32) {
	bp := tls.Alloc(48)
	defer tls.Free(48)
	var pTmp uintptr
	var _ /* uFts at bp+0 */ struct {
		FtmpSpace    [0][48]Tu8
		FsFts        TFts5Structure
		F__ccgo_pad2 [16]byte
	}
	_ = pTmp
	_fts5StructureInvalidate(tls, p)
	_fts5IndexDiscardData(tls, p)
	pTmp = bp
	libc.Xmemset(tls, bp, 0, uint64(48))
	if (*TFts5Config)(unsafe.Pointer((*TFts5Index)(unsafe.Pointer(p)).FpConfig)).FbContentlessDelete != 0 {
		(*TFts5Structure)(unsafe.Pointer(pTmp)).FnOriginCntr = uint64(1)
	}
	_fts5DataWrite(tls, p, int64(FTS5_AVERAGES_ROWID), __ccgo_ts+1693, 0)
	_fts5StructureWrite(tls, p, pTmp)
	return _fts5IndexReturn(tls, p)
}

// C documentation
//
//	/*
//	** Set the 32-bit cookie value stored at the start of all structure
//	** records to the value passed as the second argument.
//	**
//	** Return SQLITE_OK if successful, or an SQLite error code if an error
//	** occurs.
//	*/
func _sqlite3Fts5IndexSetCookie(tls *libc.TLS, p uintptr, iNew int32) (r int32) {
	bp := tls.Alloc(16)
	defer tls.Free(16)
	var pConfig uintptr
	var rc int32
	var _ /* aCookie at bp+0 */ [4]Tu8
	var _ /* pBlob at bp+8 */ uintptr
	_, _ = pConfig, rc                                  /* Return code */
	pConfig = (*TFts5Index)(unsafe.Pointer(p)).FpConfig /* Binary representation of iNew */
	**(**uintptr)(__ccgo_up(bp + 8)) = uintptr(0)
	_sqlite3Fts5Put32(tls, bp, iNew)
	rc = Xsqlite3_blob_open(tls, (*TFts5Config)(unsafe.Pointer(pConfig)).Fdb, (*TFts5Config)(unsafe.Pointer(pConfig)).FzDb, (*TFts5Index)(unsafe.Pointer(p)).FzDataTbl, __ccgo_ts+38931, int64(FTS5_STRUCTURE_ROWID), int32(1), bp+8)
	if rc == SQLITE_OK {
		Xsqlite3_blob_write(tls, **(**uintptr)(__ccgo_up(bp + 8)), bp, int32(4), 0)
		rc = Xsqlite3_blob_close(tls, **(**uintptr)(__ccgo_up(bp + 8)))
	}
	return rc
}

// C documentation
//
//	/*
//	** Attempt to instantiate the tokenizer.
//	*/
func _sqlite3Fts5LoadTokenizer(tls *libc.TLS, pConfig uintptr) (r int32) {
	bp := tls.Alloc(16)
	defer tls.Free(16)
	var azArg, pMod, xCreate, v1 uintptr
	var nArg, rc, v3 int32
	_, _, _, _, _, _, _ = azArg, nArg, pMod, rc, xCreate, v1, v3
	azArg = (*TFts5Config)(unsafe.Pointer(pConfig)).Ft.FazArg
	nArg = (*TFts5Config)(unsafe.Pointer(pConfig)).Ft.FnArg
	pMod = uintptr(0)
	rc = SQLITE_OK
	if nArg == 0 {
		v1 = uintptr(0)
	} else {
		v1 = **(**uintptr)(__ccgo_up(azArg))
	}
	pMod = _fts5LocateTokenizer(tls, (*TFts5Config)(unsafe.Pointer(pConfig)).FpGlobal, v1)
	if pMod == uintptr(0) {
		rc = int32(SQLITE_ERROR)
		_sqlite3Fts5ConfigErrmsg(tls, pConfig, __ccgo_ts+40432, libc.VaList(bp+8, **(**uintptr)(__ccgo_up(azArg))))
	} else {
		xCreate = uintptr(0)
		if (*TFts5TokenizerModule)(unsafe.Pointer(pMod)).FbV2Native != 0 {
			xCreate = (*TFts5TokenizerModule)(unsafe.Pointer(pMod)).Fx2.FxCreate
			(*TFts5Config)(unsafe.Pointer(pConfig)).Ft.FpApi2 = pMod + 48
		} else {
			(*TFts5Config)(unsafe.Pointer(pConfig)).Ft.FpApi1 = pMod + 24
			xCreate = (*TFts5TokenizerModule)(unsafe.Pointer(pMod)).Fx1.FxCreate
		}
		if azArg != 0 {
			v1 = azArg + 1*8
		} else {
			v1 = uintptr(0)
		}
		if nArg != 0 {
			v3 = nArg - int32(1)
		} else {
			v3 = 0
		}
		rc = (*(*func(*libc.TLS, uintptr, uintptr, int32, uintptr) int32)(unsafe.Pointer(&struct{ uintptr }{xCreate})))(tls, (*TFts5TokenizerModule)(unsafe.Pointer(pMod)).FpUserData, v1, v3, pConfig+128)
		if rc != SQLITE_OK {
			if rc != int32(SQLITE_NOMEM) {
				_sqlite3Fts5ConfigErrmsg(tls, pConfig, __ccgo_ts+40454, 0)
			}
		} else {
			if (*TFts5TokenizerModule)(unsafe.Pointer(pMod)).FbV2Native == 0 {
				(*TFts5Config)(unsafe.Pointer(pConfig)).Ft.FePattern = _sqlite3Fts5TokenizerPattern(tls, (*TFts5TokenizerModule)(unsafe.Pointer(pMod)).Fx1.FxCreate, (*TFts5Config)(unsafe.Pointer(pConfig)).Ft.FpTok)
			}
		}
	}
	if rc != SQLITE_OK {
		(*TFts5Config)(unsafe.Pointer(pConfig)).Ft.FpApi1 = uintptr(0)
		(*TFts5Config)(unsafe.Pointer(pConfig)).Ft.FpApi2 = uintptr(0)
		(*TFts5Config)(unsafe.Pointer(pConfig)).Ft.FpTok = uintptr(0)
	}
	return rc
}

func _sqlite3Fts5ParseColset(tls *libc.TLS, pParse uintptr, pColset uintptr, p uintptr) (r uintptr) {
	bp := tls.Alloc(16)
	defer tls.Free(16)
	var iCol int32
	var pConfig, pRet, z uintptr
	_, _, _, _ = iCol, pConfig, pRet, z
	pRet = uintptr(0) /* Dequoted copy of token p */
	z = _sqlite3Fts5Strndup(tls, pParse+16, (*TFts5Token)(unsafe.Pointer(p)).Fp, (*TFts5Token)(unsafe.Pointer(p)).Fn)
	if (*TFts5Parse)(unsafe.Pointer(pParse)).Frc == SQLITE_OK {
		pConfig = (*TFts5Parse)(unsafe.Pointer(pParse)).FpConfig
		_sqlite3Fts5Dequote(tls, z)
		iCol = 0
		for {
			if !(iCol < (*TFts5Config)(unsafe.Pointer(pConfig)).FnCol) {
				break
			}
			if 0 == Xsqlite3_stricmp(tls, **(**uintptr)(__ccgo_up((*TFts5Config)(unsafe.Pointer(pConfig)).FazCol + uintptr(iCol)*8)), z) {
				break
			}
			goto _1
		_1:
			;
			iCol = iCol + 1
		}
		if iCol == (*TFts5Config)(unsafe.Pointer(pConfig)).FnCol {
			_sqlite3Fts5ParseError(tls, pParse, __ccgo_ts+11899, libc.VaList(bp+8, z))
		} else {
			pRet = _fts5ParseColset(tls, pParse, pColset, iCol)
		}
		Xsqlite3_free(tls, z)
	}
	if pRet == uintptr(0) {
		Xsqlite3_free(tls, pColset)
	}
	return pRet
}

// C documentation
//
//	/*
//	** Token pTok has appeared in a MATCH expression where the NEAR operator
//	** is expected. If token pTok does not contain "NEAR", store an error
//	** in the pParse object.
//	*/
func _sqlite3Fts5ParseNear(tls *libc.TLS, pParse uintptr, pTok uintptr) {
	bp := tls.Alloc(32)
	defer tls.Free(32)
	if (*TFts5Token)(unsafe.Pointer(pTok)).Fn != int32(4) || libc.Xmemcmp(tls, __ccgo_ts+38594, (*TFts5Token)(unsafe.Pointer(pTok)).Fp, uint64(4)) != 0 {
		_sqlite3Fts5ParseError(tls, pParse, __ccgo_ts+37107, libc.VaList(bp+8, (*TFts5Token)(unsafe.Pointer(pTok)).Fn, (*TFts5Token)(unsafe.Pointer(pTok)).Fp))
	}
}

// C documentation
//
//	/*
//	** Allocate and return a new expression object. If anything goes wrong (i.e.
//	** OOM error), leave an error code in pParse and return NULL.
//	*/
func _sqlite3Fts5ParseNode(tls *libc.TLS, pParse uintptr, eType int32, pLeft uintptr, pRight uintptr, pNear uintptr) (r uintptr) {
	bp := tls.Alloc(16)
	defer tls.Free(16)
	var iPhrase, nChild int32
	var nByte Tsqlite3_int64
	var pPhrase, pRet, v2 uintptr
	_, _, _, _, _, _ = iPhrase, nByte, nChild, pPhrase, pRet, v2
	pRet = uintptr(0)
	if (*TFts5Parse)(unsafe.Pointer(pParse)).Frc == SQLITE_OK {
		nChild = 0 /* Bytes of space to allocate for this node */
		if eType == int32(FTS5_STRING) && pNear == uintptr(0) {
			return uintptr(0)
		}
		if eType != int32(FTS5_STRING) && pLeft == uintptr(0) {
			return pRight
		}
		if eType != int32(FTS5_STRING) && pRight == uintptr(0) {
			return pLeft
		}
		if eType == int32(FTS5_STRING) && (*TFts5Parse)(unsafe.Pointer(pParse)).FbPhraseToAnd != 0 && (*TFts5ExprPhrase)(unsafe.Pointer(*(*uintptr)(unsafe.Pointer(pNear + 24)))).FnTerm > int32(1) {
			pRet = _fts5ParsePhraseToAnd(tls, pParse, pNear)
		} else {
			if eType == int32(FTS5_NOT) {
				nChild = int32(2)
			} else {
				if eType == int32(FTS5_AND) || eType == int32(FTS5_OR) {
					nChild = int32(2)
					if (*TFts5ExprNode)(unsafe.Pointer(pLeft)).FeType == eType {
						nChild = nChild + ((*TFts5ExprNode)(unsafe.Pointer(pLeft)).FnChild - int32(1))
					}
					if (*TFts5ExprNode)(unsafe.Pointer(pRight)).FeType == eType {
						nChild = nChild + ((*TFts5ExprNode)(unsafe.Pointer(pRight)).FnChild - int32(1))
					}
				}
			}
			nByte = libc.Int64FromUint64(uint64(libc.UintptrFromInt32(0)+48) + libc.Uint64FromInt32(nChild)*libc.Uint64FromInt64(8))
			pRet = _sqlite3Fts5MallocZero(tls, pParse+16, nByte)
			if pRet != 0 {
				(*TFts5ExprNode)(unsafe.Pointer(pRet)).FeType = eType
				(*TFts5ExprNode)(unsafe.Pointer(pRet)).FpNear = pNear
				_fts5ExprAssignXNext(tls, pRet)
				if eType == int32(FTS5_STRING) {
					iPhrase = 0
					for {
						if !(iPhrase < (*TFts5ExprNearset)(unsafe.Pointer(pNear)).FnPhrase) {
							break
						}
						(*TFts5ExprPhrase)(unsafe.Pointer(*(*uintptr)(unsafe.Pointer(pNear + 24 + uintptr(iPhrase)*8)))).FpNode = pRet
						if (*TFts5ExprPhrase)(unsafe.Pointer(*(*uintptr)(unsafe.Pointer(pNear + 24 + uintptr(iPhrase)*8)))).FnTerm == 0 {
							(*TFts5ExprNode)(unsafe.Pointer(pRet)).FxNext = uintptr(0)
							(*TFts5ExprNode)(unsafe.Pointer(pRet)).FeType = FTS5_EOF
						}
						goto _1
					_1:
						;
						iPhrase = iPhrase + 1
					}
					if (*TFts5Config)(unsafe.Pointer((*TFts5Parse)(unsafe.Pointer(pParse)).FpConfig)).FeDetail != FTS5_DETAIL_FULL {
						pPhrase = *(*uintptr)(unsafe.Pointer(pNear + 24))
						if (*TFts5ExprNearset)(unsafe.Pointer(pNear)).FnPhrase != int32(1) || (*TFts5ExprPhrase)(unsafe.Pointer(pPhrase)).FnTerm > int32(1) || (*TFts5ExprPhrase)(unsafe.Pointer(pPhrase)).FnTerm > 0 && (*(*TFts5ExprTerm)(unsafe.Pointer(pPhrase + 32))).FbFirst != 0 {
							if (*TFts5ExprNearset)(unsafe.Pointer(pNear)).FnPhrase == int32(1) {
								v2 = __ccgo_ts + 38681
							} else {
								v2 = __ccgo_ts + 38594
							}
							_sqlite3Fts5ParseError(tls, pParse, __ccgo_ts+38688, libc.VaList(bp+8, v2))
							_sqlite3Fts5ParseNodeFree(tls, pRet)
							pRet = uintptr(0)
							pNear = uintptr(0)
						}
					}
				} else {
					_fts5ExprAddChildren(tls, pRet, pLeft)
					_fts5ExprAddChildren(tls, pRet, pRight)
					v2 = libc.UintptrFromInt32(0)
					pRight = v2
					pLeft = v2
					if (*TFts5ExprNode)(unsafe.Pointer(pRet)).FiHeight > int32(SQLITE_FTS5_MAX_EXPR_DEPTH) {
						_sqlite3Fts5ParseError(tls, pParse, __ccgo_ts+38738, libc.VaList(bp+8, int32(SQLITE_FTS5_MAX_EXPR_DEPTH)))
						_sqlite3Fts5ParseNodeFree(tls, pRet)
						pRet = uintptr(0)
					}
				}
			}
		}
	}
	if pRet == uintptr(0) {
		_sqlite3Fts5ParseNodeFree(tls, pLeft)
		_sqlite3Fts5ParseNodeFree(tls, pRight)
		_sqlite3Fts5ParseNearsetFree(tls, pNear)
	}
	return pRet
}

// C documentation
//
//	/*
//	** Apply colset pColset to expression node pExpr and all of its descendents.
//	*/
func _sqlite3Fts5ParseSetColset(tls *libc.TLS, pParse uintptr, pExpr uintptr, pColset uintptr) {
	bp := tls.Alloc(16)
	defer tls.Free(16)
	var _ /* pFree at bp+0 */ uintptr
	**(**uintptr)(__ccgo_up(bp)) = pColset
	if (*TFts5Config)(unsafe.Pointer((*TFts5Parse)(unsafe.Pointer(pParse)).FpConfig)).FeDetail == int32(FTS5_DETAIL_NONE) {
		_sqlite3Fts5ParseError(tls, pParse, __ccgo_ts+38628, 0)
	} else {
		_fts5ParseSetColset(tls, pParse, pExpr, pColset, bp)
	}
	Xsqlite3_free(tls, **(**uintptr)(__ccgo_up(bp)))
}

// C documentation
//
//	/*
//	** Return the fallback token corresponding to canonical token iToken, or
//	** 0 if iToken has no fallback.
//	*/
func _sqlite3Fts5ParserFallback(tls *libc.TLS, iToken int32) (r int32) {
	_ = iToken
	return 0
}

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

/* #include "fts5Int.h" */
/*	$OpenBSD: math.h,v 1.36 2018/03/10 20:52:58 kettenis Exp $	*/
/*
 * ====================================================
 * Copyright (C) 1993 by Sun Microsystems, Inc. All rights reserved.
 *
 * Developed at SunPro, a Sun Microsystems, Inc. business.
 * Permission to use, copy, modify, and distribute this
 * software is freely granted, provided that this notice
 * is preserved.
 * ====================================================
 */

/*
 * from: @(#)fdlibm.h 5.1 93/09/24
 */

// C documentation
//
//	/*
//	** Delete all entries in the FTS5 index.
//	*/
func _sqlite3Fts5StorageDeleteAll(tls *libc.TLS, p uintptr) (r int32) {
	bp := tls.Alloc(48)
	defer tls.Free(48)
	var pConfig uintptr
	var rc int32
	_, _ = pConfig, rc
	pConfig = (*TFts5Storage)(unsafe.Pointer(p)).FpConfig
	(*TFts5Storage)(unsafe.Pointer(p)).FbTotalsValid = 0
	/* Delete the contents of the %_data and %_docsize tables. */
	rc = _fts5ExecPrintf(tls, (*TFts5Config)(unsafe.Pointer(pConfig)).Fdb, uintptr(0), __ccgo_ts+41683, libc.VaList(bp+8, (*TFts5Config)(unsafe.Pointer(pConfig)).FzDb, (*TFts5Config)(unsafe.Pointer(pConfig)).FzName, (*TFts5Config)(unsafe.Pointer(pConfig)).FzDb, (*TFts5Config)(unsafe.Pointer(pConfig)).FzName))
	if rc == SQLITE_OK && (*TFts5Config)(unsafe.Pointer(pConfig)).FbColumnsize != 0 {
		rc = _fts5ExecPrintf(tls, (*TFts5Config)(unsafe.Pointer(pConfig)).Fdb, uintptr(0), __ccgo_ts+41733, libc.VaList(bp+8, (*TFts5Config)(unsafe.Pointer(pConfig)).FzDb, (*TFts5Config)(unsafe.Pointer(pConfig)).FzName))
	}
	if rc == SQLITE_OK && (*TFts5Config)(unsafe.Pointer(pConfig)).FeContent == int32(FTS5_CONTENT_UNINDEXED) {
		rc = _fts5ExecPrintf(tls, (*TFts5Config)(unsafe.Pointer(pConfig)).Fdb, uintptr(0), __ccgo_ts+41762, libc.VaList(bp+8, (*TFts5Config)(unsafe.Pointer(pConfig)).FzDb, (*TFts5Config)(unsafe.Pointer(pConfig)).FzName))
	}
	/* Reinitialize the %_data table. This call creates the initial structure
	 ** and averages records.  */
	if rc == SQLITE_OK {
		rc = _sqlite3Fts5IndexReinit(tls, (*TFts5Storage)(unsafe.Pointer(p)).FpIndex)
	}
	if rc == SQLITE_OK {
		rc = _sqlite3Fts5StorageConfigValue(tls, p, __ccgo_ts+38457, uintptr(0), int32(FTS5_CURRENT_VERSION))
	}
	return rc
}

// C documentation
//
//	/*
//	** Check that the contents of the FTS index match that of the %_content
//	** table. Return SQLITE_OK if they do, or SQLITE_CORRUPT if not. Return
//	** some other SQLite error code if an error occurs while attempting to
//	** determine this.
//	*/
func _sqlite3Fts5StorageIntegrity(tls *libc.TLS, p uintptr, iArg int32) (r int32) {
	bp := tls.Alloc(96)
	defer tls.Free(96)
	var aColSize, aTotalSize, pConfig, pVal uintptr
	var bUseCksum, i, i1, iCol, rc, rc2 int32
	var _ /* ctx at bp+0 */ TFts5IntegrityCtx
	var _ /* nLoc at bp+72 */ int32
	var _ /* nRow at bp+80 */ Ti64
	var _ /* nRow at bp+88 */ Ti64
	var _ /* nText at bp+56 */ int32
	var _ /* pLoc at bp+64 */ uintptr
	var _ /* pScan at bp+40 */ uintptr
	var _ /* pText at bp+48 */ uintptr
	_, _, _, _, _, _, _, _, _, _ = aColSize, aTotalSize, bUseCksum, i, i1, iCol, pConfig, pVal, rc, rc2
	pConfig = (*TFts5Storage)(unsafe.Pointer(p)).FpConfig
	rc = SQLITE_OK
	libc.Xmemset(tls, bp, 0, uint64(40))
	(**(**TFts5IntegrityCtx)(__ccgo_up(bp))).FpConfig = (*TFts5Storage)(unsafe.Pointer(p)).FpConfig
	aTotalSize = Xsqlite3_malloc64(tls, uint64(libc.Uint64FromInt32((*TFts5Config)(unsafe.Pointer(pConfig)).FnCol)*(libc.Uint64FromInt64(4)+libc.Uint64FromInt64(8))))
	if !(aTotalSize != 0) {
		return int32(SQLITE_NOMEM)
	}
	aColSize = aTotalSize + uintptr((*TFts5Config)(unsafe.Pointer(pConfig)).FnCol)*8
	libc.Xmemset(tls, aTotalSize, 0, uint64(8)*libc.Uint64FromInt32((*TFts5Config)(unsafe.Pointer(pConfig)).FnCol))
	bUseCksum = libc.BoolInt32((*TFts5Config)(unsafe.Pointer(pConfig)).FeContent == FTS5_CONTENT_NORMAL || (*TFts5Config)(unsafe.Pointer(pConfig)).FeContent == int32(FTS5_CONTENT_EXTERNAL) && iArg != 0)
	if bUseCksum != 0 {
		/* Generate the expected index checksum based on the contents of the
		 ** %_content table. This block stores the checksum in ctx.cksum. */
		rc = _fts5StorageGetStmt(tls, p, int32(FTS5_STMT_SCAN), bp+40, uintptr(0))
		if rc == SQLITE_OK {
			for int32(SQLITE_ROW) == Xsqlite3_step(tls, **(**uintptr)(__ccgo_up(bp + 40))) {
				(**(**TFts5IntegrityCtx)(__ccgo_up(bp))).FiRowid = Xsqlite3_column_int64(tls, **(**uintptr)(__ccgo_up(bp + 40)), 0)
				(**(**TFts5IntegrityCtx)(__ccgo_up(bp))).FszCol = 0
				if (*TFts5Config)(unsafe.Pointer(pConfig)).FbColumnsize != 0 {
					rc = _sqlite3Fts5StorageDocsize(tls, p, (**(**TFts5IntegrityCtx)(__ccgo_up(bp))).FiRowid, aColSize)
				}
				if rc == SQLITE_OK && (*TFts5Config)(unsafe.Pointer(pConfig)).FeDetail == int32(FTS5_DETAIL_NONE) {
					rc = _sqlite3Fts5TermsetNew(tls, bp+24)
				}
				i = 0
				for {
					if !(rc == SQLITE_OK && i < (*TFts5Config)(unsafe.Pointer(pConfig)).FnCol) {
						break
					}
					if libc.Int32FromUint8(**(**Tu8)(__ccgo_up((*TFts5Config)(unsafe.Pointer(pConfig)).FabUnindexed + uintptr(i)))) == 0 {
						**(**uintptr)(__ccgo_up(bp + 48)) = uintptr(0)
						**(**int32)(__ccgo_up(bp + 56)) = 0
						**(**uintptr)(__ccgo_up(bp + 64)) = uintptr(0)
						**(**int32)(__ccgo_up(bp + 72)) = 0
						pVal = Xsqlite3_column_value(tls, **(**uintptr)(__ccgo_up(bp + 40)), i+int32(1))
						if (*TFts5Config)(unsafe.Pointer(pConfig)).FeContent == int32(FTS5_CONTENT_EXTERNAL) && _sqlite3Fts5IsLocaleValue(tls, pConfig, pVal) != 0 {
							rc = _sqlite3Fts5DecodeLocaleValue(tls, pVal, bp+48, bp+56, bp+64, bp+72)
						} else {
							if (*TFts5Config)(unsafe.Pointer(pConfig)).FeContent == FTS5_CONTENT_NORMAL && (*TFts5Config)(unsafe.Pointer(pConfig)).FbLocale != 0 {
								iCol = i + int32(1) + (*TFts5Config)(unsafe.Pointer(pConfig)).FnCol
								**(**uintptr)(__ccgo_up(bp + 64)) = Xsqlite3_column_text(tls, **(**uintptr)(__ccgo_up(bp + 40)), iCol)
								**(**int32)(__ccgo_up(bp + 72)) = Xsqlite3_column_bytes(tls, **(**uintptr)(__ccgo_up(bp + 40)), iCol)
							}
							**(**uintptr)(__ccgo_up(bp + 48)) = Xsqlite3_value_text(tls, pVal)
							**(**int32)(__ccgo_up(bp + 56)) = Xsqlite3_value_bytes(tls, pVal)
						}
						(**(**TFts5IntegrityCtx)(__ccgo_up(bp))).FiCol = i
						(**(**TFts5IntegrityCtx)(__ccgo_up(bp))).FszCol = 0
						if rc == SQLITE_OK && (*TFts5Config)(unsafe.Pointer(pConfig)).FeDetail == int32(FTS5_DETAIL_COLUMNS) {
							rc = _sqlite3Fts5TermsetNew(tls, bp+24)
						}
						if rc == SQLITE_OK {
							_sqlite3Fts5SetLocale(tls, pConfig, **(**uintptr)(__ccgo_up(bp + 64)), **(**int32)(__ccgo_up(bp + 72)))
							rc = _sqlite3Fts5Tokenize(tls, pConfig, int32(FTS5_TOKENIZE_DOCUMENT), **(**uintptr)(__ccgo_up(bp + 48)), **(**int32)(__ccgo_up(bp + 56)), bp, __ccgo_fp(_fts5StorageIntegrityCallback))
							_sqlite3Fts5ClearLocale(tls, pConfig)
						}
						/* If this is not a columnsize=0 database, check that the number
						 ** of tokens in the value matches the aColSize[] value read from
						 ** the %_docsize table.  */
						if rc == SQLITE_OK && (*TFts5Config)(unsafe.Pointer(pConfig)).FbColumnsize != 0 && (**(**TFts5IntegrityCtx)(__ccgo_up(bp))).FszCol != **(**int32)(__ccgo_up(aColSize + uintptr(i)*4)) {
							rc = libc.Int32FromInt32(SQLITE_CORRUPT) | libc.Int32FromInt32(1)<<libc.Int32FromInt32(8)
						}
						**(**Ti64)(__ccgo_up(aTotalSize + uintptr(i)*8)) += int64((**(**TFts5IntegrityCtx)(__ccgo_up(bp))).FszCol)
						if (*TFts5Config)(unsafe.Pointer(pConfig)).FeDetail == int32(FTS5_DETAIL_COLUMNS) {
							_sqlite3Fts5TermsetFree(tls, (**(**TFts5IntegrityCtx)(__ccgo_up(bp))).FpTermset)
							(**(**TFts5IntegrityCtx)(__ccgo_up(bp))).FpTermset = uintptr(0)
						}
					}
					goto _1
				_1:
					;
					i = i + 1
				}
				_sqlite3Fts5TermsetFree(tls, (**(**TFts5IntegrityCtx)(__ccgo_up(bp))).FpTermset)
				(**(**TFts5IntegrityCtx)(__ccgo_up(bp))).FpTermset = uintptr(0)
				if rc != SQLITE_OK {
					break
				}
			}
			rc2 = Xsqlite3_reset(tls, **(**uintptr)(__ccgo_up(bp + 40)))
			if rc == SQLITE_OK {
				rc = rc2
			}
		}
		/* Test that the "totals" (sometimes called "averages") record looks Ok */
		if rc == SQLITE_OK {
			rc = _fts5StorageLoadTotals(tls, p, 0)
			i1 = 0
			for {
				if !(rc == SQLITE_OK && i1 < (*TFts5Config)(unsafe.Pointer(pConfig)).FnCol) {
					break
				}
				if **(**Ti64)(__ccgo_up((*TFts5Storage)(unsafe.Pointer(p)).FaTotalSize + uintptr(i1)*8)) != **(**Ti64)(__ccgo_up(aTotalSize + uintptr(i1)*8)) {
					rc = libc.Int32FromInt32(SQLITE_CORRUPT) | libc.Int32FromInt32(1)<<libc.Int32FromInt32(8)
				}
				goto _2
			_2:
				;
				i1 = i1 + 1
			}
		}
		/* Check that the %_docsize and %_content tables contain the expected
		 ** number of rows.  */
		if rc == SQLITE_OK && (*TFts5Config)(unsafe.Pointer(pConfig)).FeContent == FTS5_CONTENT_NORMAL {
			**(**Ti64)(__ccgo_up(bp + 80)) = 0
			rc = _fts5StorageCount(tls, p, __ccgo_ts+37580, bp+80)
			if rc == SQLITE_OK && **(**Ti64)(__ccgo_up(bp + 80)) != (*TFts5Storage)(unsafe.Pointer(p)).FnTotalRow {
				rc = libc.Int32FromInt32(SQLITE_CORRUPT) | libc.Int32FromInt32(1)<<libc.Int32FromInt32(8)
			}
		}
		if rc == SQLITE_OK && (*TFts5Config)(unsafe.Pointer(pConfig)).FbColumnsize != 0 {
			**(**Ti64)(__ccgo_up(bp + 88)) = 0
			rc = _fts5StorageCount(tls, p, __ccgo_ts+38275, bp+88)
			if rc == SQLITE_OK && **(**Ti64)(__ccgo_up(bp + 88)) != (*TFts5Storage)(unsafe.Pointer(p)).FnTotalRow {
				rc = libc.Int32FromInt32(SQLITE_CORRUPT) | libc.Int32FromInt32(1)<<libc.Int32FromInt32(8)
			}
		}
	}
	/* Pass the expected checksum down to the FTS index module. It will
	 ** verify, amongst other things, that it matches the checksum generated by
	 ** inspecting the index itself.  */
	if rc == SQLITE_OK {
		rc = _sqlite3Fts5IndexIntegrityCheck(tls, (*TFts5Storage)(unsafe.Pointer(p)).FpIndex, (**(**TFts5IntegrityCtx)(__ccgo_up(bp))).Fcksum, bUseCksum)
	}
	Xsqlite3_free(tls, aTotalSize)
	return rc
}

// C documentation
//
//	/*
//	** Open a new Fts5Index handle. If the bCreate argument is true, create
//	** and initialize the underlying tables
//	**
//	** If successful, set *pp to point to the new object and return SQLITE_OK.
//	** Otherwise, set *pp to NULL and return an SQLite error code.
//	*/
func _sqlite3Fts5StorageOpen(tls *libc.TLS, pConfig uintptr, pIndex uintptr, bCreate int32, pp uintptr, pzErr uintptr) (r int32) {
	bp := tls.Alloc(16)
	defer tls.Free(16)
	var i, rc int32
	var nByte Tsqlite3_int64
	var p, pDefn, zCols, zDefn, v1 uintptr
	_, _, _, _, _, _, _, _ = i, nByte, p, pDefn, rc, zCols, zDefn, v1
	rc = SQLITE_OK                                                                                                            /* Bytes of space to allocate */
	nByte = libc.Int64FromUint64(uint64(144) + libc.Uint64FromInt32((*TFts5Config)(unsafe.Pointer(pConfig)).FnCol)*uint64(8)) /* Fts5Storage.aTotalSize[] */
	v1 = Xsqlite3_malloc64(tls, libc.Uint64FromInt64(nByte))
	p = v1
	**(**uintptr)(__ccgo_up(pp)) = v1
	if !(p != 0) {
		return int32(SQLITE_NOMEM)
	}
	libc.Xmemset(tls, p, 0, libc.Uint64FromInt64(nByte))
	(*TFts5Storage)(unsafe.Pointer(p)).FaTotalSize = p + 1*144
	(*TFts5Storage)(unsafe.Pointer(p)).FpConfig = pConfig
	(*TFts5Storage)(unsafe.Pointer(p)).FpIndex = pIndex
	if bCreate != 0 {
		if (*TFts5Config)(unsafe.Pointer(pConfig)).FeContent == FTS5_CONTENT_NORMAL || (*TFts5Config)(unsafe.Pointer(pConfig)).FeContent == int32(FTS5_CONTENT_UNINDEXED) {
			i = 0
			zDefn = uintptr(0)
			pDefn = Xsqlite3_str_new(tls, (*TFts5Config)(unsafe.Pointer(pConfig)).Fdb)
			Xsqlite3_str_appendf(tls, pDefn, __ccgo_ts+41551, 0)
			i = 0
			for {
				if !(i < (*TFts5Config)(unsafe.Pointer(pConfig)).FnCol) {
					break
				}
				if (*TFts5Config)(unsafe.Pointer(pConfig)).FeContent == FTS5_CONTENT_NORMAL || **(**Tu8)(__ccgo_up((*TFts5Config)(unsafe.Pointer(pConfig)).FabUnindexed + uintptr(i))) != 0 {
					Xsqlite3_str_appendf(tls, pDefn, __ccgo_ts+41574, libc.VaList(bp+8, i))
				}
				goto _2
			_2:
				;
				i = i + 1
			}
			if (*TFts5Config)(unsafe.Pointer(pConfig)).FbLocale != 0 {
				i = 0
				for {
					if !(i < (*TFts5Config)(unsafe.Pointer(pConfig)).FnCol) {
						break
					}
					if libc.Int32FromUint8(**(**Tu8)(__ccgo_up((*TFts5Config)(unsafe.Pointer(pConfig)).FabUnindexed + uintptr(i)))) == 0 {
						Xsqlite3_str_appendf(tls, pDefn, __ccgo_ts+41580, libc.VaList(bp+8, i))
					}
					goto _3
				_3:
					;
					i = i + 1
				}
			}
			zDefn = Xsqlite3_str_finish(tls, pDefn)
			if zDefn != 0 {
				rc = _sqlite3Fts5CreateTable(tls, pConfig, __ccgo_ts+37580, zDefn, 0, pzErr)
				Xsqlite3_free(tls, zDefn)
			} else {
				rc = int32(SQLITE_NOMEM)
			}
		}
		if rc == SQLITE_OK && (*TFts5Config)(unsafe.Pointer(pConfig)).FbColumnsize != 0 {
			zCols = __ccgo_ts + 41586
			if (*TFts5Config)(unsafe.Pointer(pConfig)).FbContentlessDelete != 0 {
				zCols = __ccgo_ts + 41618
			}
			rc = _sqlite3Fts5CreateTable(tls, pConfig, __ccgo_ts+38275, zCols, 0, pzErr)
		}
		if rc == SQLITE_OK {
			rc = _sqlite3Fts5CreateTable(tls, pConfig, __ccgo_ts+40589, __ccgo_ts+41666, int32(1), pzErr)
		}
		if rc == SQLITE_OK {
			rc = _sqlite3Fts5StorageConfigValue(tls, p, __ccgo_ts+38457, uintptr(0), int32(FTS5_CURRENT_VERSION))
		}
	}
	if rc != 0 {
		_sqlite3Fts5StorageClose(tls, p)
		**(**uintptr)(__ccgo_up(pp)) = uintptr(0)
	}
	return rc
}

func _sqlite3Fts5StorageRename(tls *libc.TLS, pStorage uintptr, zName uintptr) (r int32) {
	bp := tls.Alloc(16)
	defer tls.Free(16)
	var pConfig uintptr
	var _ /* rc at bp+0 */ int32
	_ = pConfig
	pConfig = (*TFts5Storage)(unsafe.Pointer(pStorage)).FpConfig
	**(**int32)(__ccgo_up(bp)) = _sqlite3Fts5StorageSync(tls, pStorage)
	_fts5StorageRenameOne(tls, pConfig, bp, __ccgo_ts+27397, zName)
	_fts5StorageRenameOne(tls, pConfig, bp, __ccgo_ts+13037, zName)
	_fts5StorageRenameOne(tls, pConfig, bp, __ccgo_ts+40589, zName)
	if (*TFts5Config)(unsafe.Pointer(pConfig)).FbColumnsize != 0 {
		_fts5StorageRenameOne(tls, pConfig, bp, __ccgo_ts+38275, zName)
	}
	if (*TFts5Config)(unsafe.Pointer(pConfig)).FeContent == FTS5_CONTENT_NORMAL {
		_fts5StorageRenameOne(tls, pConfig, bp, __ccgo_ts+37580, zName)
	}
	return **(**int32)(__ccgo_up(bp))
}

// C documentation
//
//	/*
//	** Register all built-in tokenizers with FTS5.
//	*/
func _sqlite3Fts5TokenizerInit(tls *libc.TLS, pApi uintptr) (r int32) {
	bp := tls.Alloc(128)
	defer tls.Free(128)
	var i, rc int32
	var _ /* aBuiltin at bp+0 */ [3]struct {
		FzName uintptr
		Fx     Tfts5_tokenizer
	}
	var _ /* sPorter at bp+96 */ Tfts5_tokenizer_v2
	_, _ = i, rc
	**(**[3]struct {
		FzName uintptr
		Fx     Tfts5_tokenizer
	})(__ccgo_up(bp)) = [3]struct {
		FzName uintptr
		Fx     Tfts5_tokenizer
	}{
		0: {
			FzName: __ccgo_ts + 41883,
			Fx: Tfts5_tokenizer{
				FxCreate:   __ccgo_fp(_fts5UnicodeCreate),
				FxDelete:   __ccgo_fp(_fts5UnicodeDelete),
				FxTokenize: __ccgo_fp(_fts5UnicodeTokenize),
			},
		},
		1: {
			FzName: __ccgo_ts + 42202,
			Fx: Tfts5_tokenizer{
				FxCreate:   __ccgo_fp(_fts5AsciiCreate),
				FxDelete:   __ccgo_fp(_fts5AsciiDelete),
				FxTokenize: __ccgo_fp(_fts5AsciiTokenize),
			},
		},
		2: {
			FzName: __ccgo_ts + 42194,
			Fx: Tfts5_tokenizer{
				FxCreate:   __ccgo_fp(_fts5TriCreate),
				FxDelete:   __ccgo_fp(_fts5TriDelete),
				FxTokenize: __ccgo_fp(_fts5TriTokenize),
			},
		},
	}
	rc = SQLITE_OK /* To iterate through builtin functions */
	i = 0
	for {
		if !(rc == SQLITE_OK && i < libc.Int32FromUint64(libc.Uint64FromInt64(96)/libc.Uint64FromInt64(32))) {
			break
		}
		rc = (*(*func(*libc.TLS, uintptr, uintptr, uintptr, uintptr, uintptr) int32)(unsafe.Pointer(&struct{ uintptr }{(*Tfts5_api)(unsafe.Pointer(pApi)).FxCreateTokenizer})))(tls, pApi, (**(**[3]struct {
			FzName uintptr
			Fx     Tfts5_tokenizer
		})(__ccgo_up(bp)))[i].FzName, pApi, bp+uintptr(i)*32+8, uintptr(0))
		goto _1
	_1:
		;
		i = i + 1
	}
	if rc == SQLITE_OK {
		**(**Tfts5_tokenizer_v2)(__ccgo_up(bp + 96)) = Tfts5_tokenizer_v2{
			FiVersion:  int32(2),
			FxCreate:   __ccgo_fp(_fts5PorterCreate),
			FxDelete:   __ccgo_fp(_fts5PorterDelete),
			FxTokenize: __ccgo_fp(_fts5PorterTokenize),
		}
		rc = (*(*func(*libc.TLS, uintptr, uintptr, uintptr, uintptr, uintptr) int32)(unsafe.Pointer(&struct{ uintptr }{(*Tfts5_api)(unsafe.Pointer(pApi)).FxCreateTokenizer_v2})))(tls, pApi, __ccgo_ts+41893, pApi, bp+96, uintptr(0))
	}
	return rc
}

/*
** 2012-05-25
**
** 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.
**
******************************************************************************
 */

/*
** DO NOT EDIT THIS MACHINE GENERATED FILE.
 */

/* #include <assert.h> */

// C documentation
//
//	/*
//	** Return true if the tokenizer described by p->azArg[] is the trigram
//	** tokenizer. This tokenizer needs to be loaded before xBestIndex is
//	** called for the first time in order to correctly handle LIKE/GLOB.
//	*/
func _sqlite3Fts5TokenizerPreload(tls *libc.TLS, p uintptr) (r int32) {
	return libc.BoolInt32((*TFts5TokenizerConfig)(unsafe.Pointer(p)).FnArg >= int32(1) && 0 == Xsqlite3_stricmp(tls, **(**uintptr)(__ccgo_up((*TFts5TokenizerConfig)(unsafe.Pointer(p)).FazArg)), __ccgo_ts+42194))
}

func _sqlite3Fts5VocabInit(tls *libc.TLS, pGlobal uintptr, db uintptr) (r int32) {
	var p uintptr
	_ = p
	p = pGlobal
	return Xsqlite3_create_module_v2(tls, db, __ccgo_ts+42518, uintptr(unsafe.Pointer(&_fts5Vocab)), p, uintptr(0))
}

// C documentation
//
//	/*
//	** Compute the column names for a SELECT statement.
//	**
//	** The only guarantee that SQLite makes about column names is that if the
//	** column has an AS clause assigning it a name, that will be the name used.
//	** That is the only documented guarantee.  However, countless applications
//	** developed over the years have made baseless assumptions about column names
//	** and will break if those assumptions changes.  Hence, use extreme caution
//	** when modifying this routine to avoid breaking legacy.
//	**
//	** See Also: sqlite3ColumnsFromExprList()
//	**
//	** The PRAGMA short_column_names and PRAGMA full_column_names settings are
//	** deprecated.  The default setting is short=ON, full=OFF.  99.9% of all
//	** applications should operate this way.  Nevertheless, we need to support the
//	** other modes for legacy:
//	**
//	**    short=OFF, full=OFF:      Column name is the text of the expression has it
//	**                              originally appears in the SELECT statement.  In
//	**                              other words, the zSpan of the result expression.
//	**
//	**    short=ON, full=OFF:       (This is the default setting).  If the result
//	**                              refers directly to a table column, then the
//	**                              result column name is just the table column
//	**                              name: COLUMN.  Otherwise use zSpan.
//	**
//	**    full=ON, short=ANY:       If the result refers directly to a table column,
//	**                              then the result column name with the table name
//	**                              prefix, ex: TABLE.COLUMN.  Otherwise use zSpan.
//	*/
func _sqlite3GenerateColumnNames(tls *libc.TLS, pParse uintptr, pSelect uintptr) {
	bp := tls.Alloc(32)
	defer tls.Free(32)
	var db, p, pEList, pTab, pTabList, v, z, zCol, zName, zName1, v2 uintptr
	var fullName, i, iCol, srcName int32
	_, _, _, _, _, _, _, _, _, _, _, _, _, _, _ = db, fullName, i, iCol, p, pEList, pTab, pTabList, srcName, v, z, zCol, zName, zName1, v2
	v = (*TParse)(unsafe.Pointer(pParse)).FpVdbe
	db = (*TParse)(unsafe.Pointer(pParse)).Fdb /* COLUMN or TABLE.COLUMN if no AS clause and is direct */
	if int32(Tbft(*(*uint16)(unsafe.Pointer(pParse + 40))&0x20>>5)) != 0 {
		return
	}
	/* Column names are determined by the left-most term of a compound select */
	for (*TSelect)(unsafe.Pointer(pSelect)).FpPrior != 0 {
		pSelect = (*TSelect)(unsafe.Pointer(pSelect)).FpPrior
	}
	pTabList = (*TSelect)(unsafe.Pointer(pSelect)).FpSrc
	pEList = (*TSelect)(unsafe.Pointer(pSelect)).FpEList
	libc.SetBitFieldPtr16Uint32(pParse+40, libc.Uint32FromInt32(1), 5, 0x20)
	fullName = libc.BoolInt32((*Tsqlite3)(unsafe.Pointer(db)).Fflags&uint64(SQLITE_FullColNames) != uint64(0))
	srcName = libc.BoolInt32((*Tsqlite3)(unsafe.Pointer(db)).Fflags&uint64(SQLITE_ShortColNames) != uint64(0) || fullName != 0)
	_sqlite3VdbeSetNumCols(tls, v, (*TExprList)(unsafe.Pointer(pEList)).FnExpr)
	i = 0
	for {
		if !(i < (*TExprList)(unsafe.Pointer(pEList)).FnExpr) {
			break
		}
		p = (*(*TExprList_item)(unsafe.Pointer(pEList + 8 + uintptr(i)*32))).FpExpr
		/* Agg processing has not run yet */
		/* Covering idx not yet coded */
		if (*(*TExprList_item)(unsafe.Pointer(pEList + 8 + uintptr(i)*32))).FzEName != 0 && int32(uint32(*(*uint16)(unsafe.Pointer(pEList + 8 + uintptr(i)*32 + 16 + 4))&0x3>>0)) == ENAME_NAME {
			/* An AS clause always takes first priority */
			zName = (*(*TExprList_item)(unsafe.Pointer(pEList + 8 + uintptr(i)*32))).FzEName
			_sqlite3VdbeSetColName(tls, v, i, COLNAME_NAME, zName, uintptr(-libc.Int32FromInt32(1)))
		} else {
			if srcName != 0 && libc.Int32FromUint8((*TExpr)(unsafe.Pointer(p)).Fop) == int32(TK_COLUMN) {
				iCol = int32((*TExpr)(unsafe.Pointer(p)).FiColumn)
				pTab = *(*uintptr)(unsafe.Pointer(p + 64))
				if iCol < 0 {
					iCol = int32((*TTable)(unsafe.Pointer(pTab)).FiPKey)
				}
				if iCol < 0 {
					zCol = __ccgo_ts + 17956
				} else {
					zCol = (**(**TColumn)(__ccgo_up((*TTable)(unsafe.Pointer(pTab)).FaCol + uintptr(iCol)*16))).FzCnName
				}
				if fullName != 0 {
					zName1 = uintptr(0)
					zName1 = _sqlite3MPrintf(tls, db, __ccgo_ts+13625, libc.VaList(bp+8, (*TTable)(unsafe.Pointer(pTab)).FzName, zCol))
					_sqlite3VdbeSetColName(tls, v, i, COLNAME_NAME, zName1, __ccgo_fp(_sqlite3RowSetClear))
				} else {
					_sqlite3VdbeSetColName(tls, v, i, COLNAME_NAME, zCol, uintptr(-libc.Int32FromInt32(1)))
				}
			} else {
				z = (*(*TExprList_item)(unsafe.Pointer(pEList + 8 + uintptr(i)*32))).FzEName
				if z == uintptr(0) {
					v2 = _sqlite3MPrintf(tls, db, __ccgo_ts+20625, libc.VaList(bp+8, i+int32(1)))
				} else {
					v2 = _sqlite3DbStrDup(tls, db, z)
				}
				z = v2
				_sqlite3VdbeSetColName(tls, v, i, COLNAME_NAME, z, __ccgo_fp(_sqlite3RowSetClear))
			}
		}
		goto _1
	_1:
		;
		i = i + 1
	}
	_generateColumnTypes(tls, pParse, pTabList, pEList)
}

// C documentation
//
//	/*
//	** Generate code to do constraint checks prior to an INSERT or an UPDATE
//	** on table pTab.
//	**
//	** The regNewData parameter is the first register in a range that contains
//	** the data to be inserted or the data after the update.  There will be
//	** pTab->nCol+1 registers in this range.  The first register (the one
//	** that regNewData points to) will contain the new rowid, or NULL in the
//	** case of a WITHOUT ROWID table.  The second register in the range will
//	** contain the content of the first table column.  The third register will
//	** contain the content of the second table column.  And so forth.
//	**
//	** The regOldData parameter is similar to regNewData except that it contains
//	** the data prior to an UPDATE rather than afterwards.  regOldData is zero
//	** for an INSERT.  This routine can distinguish between UPDATE and INSERT by
//	** checking regOldData for zero.
//	**
//	** For an UPDATE, the pkChng boolean is true if the true primary key (the
//	** rowid for a normal table or the PRIMARY KEY for a WITHOUT ROWID table)
//	** might be modified by the UPDATE.  If pkChng is false, then the key of
//	** the iDataCur content table is guaranteed to be unchanged by the UPDATE.
//	**
//	** For an INSERT, the pkChng boolean indicates whether or not the rowid
//	** was explicitly specified as part of the INSERT statement.  If pkChng
//	** is zero, it means that the either rowid is computed automatically or
//	** that the table is a WITHOUT ROWID table and has no rowid.  On an INSERT,
//	** pkChng will only be true if the INSERT statement provides an integer
//	** value for either the rowid column or its INTEGER PRIMARY KEY alias.
//	**
//	** The code generated by this routine will store new index entries into
//	** registers identified by aRegIdx[].  No index entry is created for
//	** indices where aRegIdx[i]==0.  The order of indices in aRegIdx[] is
//	** the same as the order of indices on the linked list of indices
//	** at pTab->pIndex.
//	**
//	** (2019-05-07) The generated code also creates a new record for the
//	** main table, if pTab is a rowid table, and stores that record in the
//	** register identified by aRegIdx[nIdx] - in other words in the first
//	** entry of aRegIdx[] past the last index.  It is important that the
//	** record be generated during constraint checks to avoid affinity changes
//	** to the register content that occur after constraint checks but before
//	** the new record is inserted.
//	**
//	** The caller must have already opened writeable cursors on the main
//	** table and all applicable indices (that is to say, all indices for which
//	** aRegIdx[] is not zero).  iDataCur is the cursor for the main table when
//	** inserting or updating a rowid table, or the cursor for the PRIMARY KEY
//	** index when operating on a WITHOUT ROWID table.  iIdxCur is the cursor
//	** for the first index in the pTab->pIndex list.  Cursors for other indices
//	** are at iIdxCur+N for the N-th element of the pTab->pIndex list.
//	**
//	** This routine also generates code to check constraints.  NOT NULL,
//	** CHECK, and UNIQUE constraints are all checked.  If a constraint fails,
//	** then the appropriate action is performed.  There are five possible
//	** actions: ROLLBACK, ABORT, FAIL, REPLACE, and IGNORE.
//	**
//	**  Constraint type  Action       What Happens
//	**  ---------------  ----------   ----------------------------------------
//	**  any              ROLLBACK     The current transaction is rolled back and
//	**                                sqlite3_step() returns immediately with a
//	**                                return code of SQLITE_CONSTRAINT.
//	**
//	**  any              ABORT        Back out changes from the current command
//	**                                only (do not do a complete rollback) then
//	**                                cause sqlite3_step() to return immediately
//	**                                with SQLITE_CONSTRAINT.
//	**
//	**  any              FAIL         Sqlite3_step() returns immediately with a
//	**                                return code of SQLITE_CONSTRAINT.  The
//	**                                transaction is not rolled back and any
//	**                                changes to prior rows are retained.
//	**
//	**  any              IGNORE       The attempt in insert or update the current
//	**                                row is skipped, without throwing an error.
//	**                                Processing continues with the next row.
//	**                                (There is an immediate jump to ignoreDest.)
//	**
//	**  NOT NULL         REPLACE      The NULL value is replace by the default
//	**                                value for that column.  If the default value
//	**                                is NULL, the action is the same as ABORT.
//	**
//	**  UNIQUE           REPLACE      The other row that conflicts with the row
//	**                                being inserted is removed.
//	**
//	**  CHECK            REPLACE      Illegal.  The results in an exception.
//	**
//	** Which action to take is determined by the overrideError parameter.
//	** Or if overrideError==OE_Default, then the pParse->onError parameter
//	** is used.  Or if pParse->onError==OE_Default then the onError value
//	** for the constraint is used.
//	*/
func _sqlite3GenerateConstraintChecks(tls *libc.TLS, pParse uintptr, pTab uintptr, aRegIdx uintptr, iDataCur int32, iIdxCur int32, regNewData int32, regOldData int32, pkChng Tu8, overrideError Tu8, ignoreDest int32, pbMayReplace uintptr, aiChng uintptr, pUpsert uintptr) {
	bp := tls.Alloc(80)
	defer tls.Free(80)
	var addr1, addrBypass, addrConflictCk, addrJump, addrRecheck, addrRowidOk, addrUniqueOk, allOk, b2ndPass, i, iField, iReg, iThisCur, ipkBottom, ipkTop, isGenerated, jj, lblRecheckOk, nCol, nConflictCk, nGenerated, nIdx, nPkField, nReplaceTrig, nSeenReplace, onError, op, p2, regCmp, regIdx, regR, regRec, regTrigCnt, seenReplace, upsertIpkDelay, upsertIpkReturn, x, x1, v2 int32
	var bAffinityDone, isUpdate Tu8
	var bUsed, db, p4, pCheck, pCol, pCopy, pExpr, pIdx, pPk, pTerm, pTrigger, pUpsertClause, v, zMsg, zName, zP4, v8 uintptr
	var nByte Tu64
	var _ /* ix at bp+0 */ int32
	var _ /* sIdxIter at bp+8 */ TIndexIterator
	var _ /* x at bp+32 */ TVdbeOp
	_, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _ = addr1, addrBypass, addrConflictCk, addrJump, addrRecheck, addrRowidOk, addrUniqueOk, allOk, b2ndPass, bAffinityDone, bUsed, db, i, iField, iReg, iThisCur, ipkBottom, ipkTop, isGenerated, isUpdate, jj, lblRecheckOk, nByte, nCol, nConflictCk, nGenerated, nIdx, nPkField, nReplaceTrig, nSeenReplace, onError, op, p2, p4, pCheck, pCol, pCopy, pExpr, pIdx, pPk, pTerm, pTrigger, pUpsertClause, regCmp, regIdx, regR, regRec, regTrigCnt, seenReplace, upsertIpkDelay, upsertIpkReturn, v, x, x1, zMsg, zName, zP4, v2, v8 /* Pointer to one of the indices */
	pPk = uintptr(0)                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                  /* Conflict resolution strategy */
	seenReplace = 0                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                   /* Number of fields in PRIMARY KEY. 1 for ROWID tables */
	pUpsertClause = uintptr(0)                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                        /* True if this is an UPDATE operation */
	bAffinityDone = uint8(0)                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                          /* True if the OP_Affinity operation has been run */
	upsertIpkReturn = 0                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                               /* Address of Goto at end of IPK uniqueness check */
	upsertIpkDelay = 0                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                /* Address of Goto to bypass initial IPK check */
	ipkTop = 0                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                        /* Top of the IPK uniqueness check */
	ipkBottom = 0                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                     /* Register used to count replace trigger invocations */
	addrRecheck = 0                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                   /* Jump here to recheck all uniqueness constraints */
	lblRecheckOk = 0                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                  /* List of DELETE triggers on the table pTab */
	nReplaceTrig = 0                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                  /* Index iterator */
	isUpdate = libc.BoolUint8(regOldData != 0)
	db = (*TParse)(unsafe.Pointer(pParse)).Fdb
	v = (*TParse)(unsafe.Pointer(pParse)).FpVdbe
	/* This table is not a VIEW */
	nCol = int32((*TTable)(unsafe.Pointer(pTab)).FnCol)
	/* pPk is the PRIMARY KEY index for WITHOUT ROWID tables and NULL for
	 ** normal rowid tables.  nPkField is the number of key fields in the
	 ** pPk index or 1 for a rowid table.  In other words, nPkField is the
	 ** number of fields in the true primary key of the table. */
	if (*TTable)(unsafe.Pointer(pTab)).FtabFlags&uint32(TF_WithoutRowid) == uint32(0) {
		pPk = uintptr(0)
		nPkField = int32(1)
	} else {
		pPk = _sqlite3PrimaryKeyIndex(tls, pTab)
		nPkField = libc.Int32FromUint16((*TIndex)(unsafe.Pointer(pPk)).FnKeyCol)
	}
	/* Record that this module has started */
	/* Test all NOT NULL constraints.
	 */
	if (*TTable)(unsafe.Pointer(pTab)).FtabFlags&uint32(TF_HasNotNull) != 0 {
		b2ndPass = 0        /* True if currently running 2nd pass */
		nSeenReplace = 0    /* Number of ON CONFLICT REPLACE operations */
		nGenerated = 0      /* Number of generated columns with NOT NULL */
		for int32(1) != 0 { /* Make 2 passes over columns. Exit loop via "break" */
			i = 0
			for {
				if !(i < nCol) {
					break
				} /* Register holding column value */
				pCol = (*TTable)(unsafe.Pointer(pTab)).FaCol + uintptr(i)*16 /* non-zero if column is generated */
				onError = int32(uint32(*(*uint8)(unsafe.Pointer(pCol + 8)) & 0xf >> 0))
				if onError == OE_None {
					goto _1
				} /* No NOT NULL on this column */
				if i == int32((*TTable)(unsafe.Pointer(pTab)).FiPKey) {
					goto _1 /* ROWID is never NULL */
				}
				isGenerated = libc.Int32FromUint16((*TColumn)(unsafe.Pointer(pCol)).FcolFlags) & int32(COLFLAG_GENERATED)
				if isGenerated != 0 && !(b2ndPass != 0) {
					nGenerated = nGenerated + 1
					goto _1 /* Generated columns processed on 2nd pass */
				}
				if aiChng != 0 && **(**int32)(__ccgo_up(aiChng + uintptr(i)*4)) < 0 && !(isGenerated != 0) {
					/* Do not check NOT NULL on columns that do not change */
					goto _1
				}
				if libc.Int32FromUint8(overrideError) != int32(OE_Default) {
					onError = libc.Int32FromUint8(overrideError)
				} else {
					if onError == int32(OE_Default) {
						onError = int32(OE_Abort)
					}
				}
				if onError == int32(OE_Replace) {
					if b2ndPass != 0 || libc.Int32FromUint16((*TColumn)(unsafe.Pointer(pCol)).FiDflt) == 0 {
						onError = int32(OE_Abort)
					} else {
					}
				} else {
					if b2ndPass != 0 && !(isGenerated != 0) {
						goto _1
					}
				}
				iReg = int32(_sqlite3TableColumnToStorage(tls, pTab, int16(i))) + regNewData + int32(1)
				switch onError {
				case int32(OE_Replace):
					addr1 = _sqlite3VdbeAddOp1(tls, v, int32(OP_NotNull), iReg)
					nSeenReplace = nSeenReplace + 1
					_sqlite3ExprCodeCopy(tls, pParse, _sqlite3ColumnExpr(tls, pTab, pCol), iReg)
					_sqlite3VdbeJumpHere(tls, v, addr1)
				case int32(OE_Abort):
					_sqlite3MayAbort(tls, pParse)
					fallthrough
				case int32(OE_Rollback):
					fallthrough
				case int32(OE_Fail):
					zMsg = _sqlite3MPrintf(tls, db, __ccgo_ts+13625, libc.VaList(bp+64, (*TTable)(unsafe.Pointer(pTab)).FzName, (*TColumn)(unsafe.Pointer(pCol)).FzCnName))
					_sqlite3VdbeAddOp3(tls, v, int32(OP_HaltIfNull), libc.Int32FromInt32(SQLITE_CONSTRAINT)|libc.Int32FromInt32(5)<<libc.Int32FromInt32(8), onError, iReg)
					_sqlite3VdbeAppendP4(tls, v, zMsg, -int32(7))
					_sqlite3VdbeChangeP5(tls, v, uint16(P5_ConstraintNotNull))
				default:
					_sqlite3VdbeAddOp2(tls, v, int32(OP_IsNull), iReg, ignoreDest)
					break
				} /* end switch(onError) */
				goto _1
			_1:
				;
				i = i + 1
			} /* end loop i over columns */
			if nGenerated == 0 && nSeenReplace == 0 {
				/* If there are no generated columns with NOT NULL constraints
				 ** and no NOT NULL ON CONFLICT REPLACE constraints, then a single
				 ** pass is sufficient */
				break
			}
			if b2ndPass != 0 {
				break
			} /* Never need more than 2 passes */
			b2ndPass = int32(1)
			if nSeenReplace > 0 && (*TTable)(unsafe.Pointer(pTab)).FtabFlags&uint32(TF_HasGenerated) != uint32(0) {
				/* If any NOT NULL ON CONFLICT REPLACE constraints fired on the
				 ** first pass, recomputed values for all generated columns, as
				 ** those values might depend on columns affected by the REPLACE.
				 */
				_sqlite3ComputeGeneratedColumns(tls, pParse, regNewData+int32(1), pTab)
			}
		} /* end of 2-pass loop */
	} /* end if( has-not-null-constraints ) */
	/* Test all CHECK constraints
	 */
	if (*TTable)(unsafe.Pointer(pTab)).FpCheck != 0 && (*Tsqlite3)(unsafe.Pointer(db)).Fflags&uint64(SQLITE_IgnoreChecks) == uint64(0) {
		pCheck = (*TTable)(unsafe.Pointer(pTab)).FpCheck
		(*TParse)(unsafe.Pointer(pParse)).FiSelfTab = -(regNewData + int32(1))
		if libc.Int32FromUint8(overrideError) != int32(OE_Default) {
			v2 = libc.Int32FromUint8(overrideError)
		} else {
			v2 = int32(OE_Abort)
		}
		onError = v2
		i = 0
		for {
			if !(i < (*TExprList)(unsafe.Pointer(pCheck)).FnExpr) {
				break
			}
			pExpr = (*(*TExprList_item)(unsafe.Pointer(pCheck + 8 + uintptr(i)*32))).FpExpr
			if aiChng != 0 && !(_sqlite3ExprReferencesUpdatedColumn(tls, pExpr, aiChng, libc.Int32FromUint8(pkChng)) != 0) {
				/* The check constraints do not reference any of the columns being
				 ** updated so there is no point it verifying the check constraint */
				goto _3
			}
			if libc.Int32FromUint8(bAffinityDone) == 0 {
				_sqlite3TableAffinity(tls, v, pTab, regNewData+int32(1))
				bAffinityDone = uint8(1)
			}
			allOk = _sqlite3VdbeMakeLabel(tls, pParse)
			pCopy = _sqlite3ExprDup(tls, db, pExpr, 0)
			if !((*Tsqlite3)(unsafe.Pointer(db)).FmallocFailed != 0) {
				_sqlite3ExprIfTrue(tls, pParse, pCopy, allOk, int32(SQLITE_JUMPIFNULL))
			}
			_sqlite3ExprDelete(tls, db, pCopy)
			if onError == int32(OE_Ignore) {
				_sqlite3VdbeGoto(tls, v, ignoreDest)
			} else {
				zName = (*(*TExprList_item)(unsafe.Pointer(pCheck + 8 + uintptr(i)*32))).FzEName
				if onError == int32(OE_Replace) {
					onError = int32(OE_Abort)
				} /* IMP: R-26383-51744 */
				_sqlite3HaltConstraint(tls, pParse, libc.Int32FromInt32(SQLITE_CONSTRAINT)|libc.Int32FromInt32(1)<<libc.Int32FromInt32(8), onError, zName, P4_TRANSIENT, uint8(P5_ConstraintCheck))
			}
			_sqlite3VdbeResolveLabel(tls, v, allOk)
			goto _3
		_3:
			;
			i = i + 1
		}
		(*TParse)(unsafe.Pointer(pParse)).FiSelfTab = 0
	}
	/* UNIQUE and PRIMARY KEY constraints should be handled in the following
	 ** order:
	 **
	 **   (1)  OE_Update
	 **   (2)  OE_Abort, OE_Fail, OE_Rollback, OE_Ignore
	 **   (3)  OE_Replace
	 **
	 ** OE_Fail and OE_Ignore must happen before any changes are made.
	 ** OE_Update guarantees that only a single row will change, so it
	 ** must happen before OE_Replace.  Technically, OE_Abort and OE_Rollback
	 ** could happen in any order, but they are grouped up front for
	 ** convenience.
	 **
	 ** 2018-08-14: Ticket https://sqlite.org/src/info/908f001483982c43
	 ** The order of constraints used to have OE_Update as (2) and OE_Abort
	 ** and so forth as (1). But apparently PostgreSQL checks the OE_Update
	 ** constraint before any others, so it had to be moved.
	 **
	 ** Constraint checking code is generated in this order:
	 **   (A)  The rowid constraint
	 **   (B)  Unique index constraints that do not have OE_Replace as their
	 **        default conflict resolution strategy
	 **   (C)  Unique index that do use OE_Replace by default.
	 **
	 ** The ordering of (2) and (3) is accomplished by making sure the linked
	 ** list of indexes attached to a table puts all OE_Replace indexes last
	 ** in the list.  See sqlite3CreateIndex() for where that happens.
	 */
	(**(**TIndexIterator)(__ccgo_up(bp + 8))).FeType = 0
	(**(**TIndexIterator)(__ccgo_up(bp + 8))).Fi = 0
	*(*uintptr)(unsafe.Pointer(bp + 8 + 8 + 8)) = uintptr(0) /* Silence harmless compiler warning */
	*(*uintptr)(unsafe.Pointer(bp + 8 + 8)) = (*TTable)(unsafe.Pointer(pTab)).FpIndex
	if pUpsert != 0 {
		if (*TUpsert)(unsafe.Pointer(pUpsert)).FpUpsertTarget == uintptr(0) {
			/* There is just on ON CONFLICT clause and it has no constraint-target */
			if libc.Int32FromUint8((*TUpsert)(unsafe.Pointer(pUpsert)).FisDoUpdate) == 0 {
				/* A single ON CONFLICT DO NOTHING clause, without a constraint-target.
				 ** Make all unique constraint resolution be OE_Ignore */
				overrideError = uint8(OE_Ignore)
				pUpsert = uintptr(0)
			} else {
				/* A single ON CONFLICT DO UPDATE.  Make all resolutions OE_Update */
				overrideError = uint8(OE_Update)
			}
		} else {
			if (*TTable)(unsafe.Pointer(pTab)).FpIndex != uintptr(0) {
				nIdx = 0
				pIdx = (*TTable)(unsafe.Pointer(pTab)).FpIndex
				for {
					if !(pIdx != 0) {
						break
					}
					goto _4
				_4:
					;
					pIdx = (*TIndex)(unsafe.Pointer(pIdx)).FpNext
					nIdx = nIdx + 1
				}
				(**(**TIndexIterator)(__ccgo_up(bp + 8))).FeType = int32(1)
				*(*int32)(unsafe.Pointer(bp + 8 + 8)) = nIdx
				nByte = uint64((libc.Uint64FromInt64(16)+libc.Uint64FromInt32(1))*libc.Uint64FromInt32(nIdx) + libc.Uint64FromInt32(nIdx))
				*(*uintptr)(unsafe.Pointer(bp + 8 + 8 + 8)) = _sqlite3DbMallocZero(tls, db, nByte)
				if *(*uintptr)(unsafe.Pointer(bp + 8 + 8 + 8)) == uintptr(0) {
					return
				} /* OOM */
				bUsed = *(*uintptr)(unsafe.Pointer(bp + 8 + 8 + 8)) + uintptr(nIdx)*16
				(*TUpsert)(unsafe.Pointer(pUpsert)).FpToFree = *(*uintptr)(unsafe.Pointer(bp + 8 + 8 + 8))
				i = 0
				pTerm = pUpsert
				for {
					if !(pTerm != 0) {
						break
					}
					if (*TUpsert)(unsafe.Pointer(pTerm)).FpUpsertTarget == uintptr(0) {
						break
					}
					if (*TUpsert)(unsafe.Pointer(pTerm)).FpUpsertIdx == uintptr(0) {
						goto _5
					} /* Skip ON CONFLICT for the IPK */
					jj = 0
					pIdx = (*TTable)(unsafe.Pointer(pTab)).FpIndex
					for pIdx != uintptr(0) && pIdx != (*TUpsert)(unsafe.Pointer(pTerm)).FpUpsertIdx {
						pIdx = (*TIndex)(unsafe.Pointer(pIdx)).FpNext
						jj = jj + 1
					}
					if **(**Tu8)(__ccgo_up(bUsed + uintptr(jj))) != 0 {
						goto _5
					} /* Duplicate ON CONFLICT clause ignored */
					**(**Tu8)(__ccgo_up(bUsed + uintptr(jj))) = uint8(1)
					(**(**TIndexListTerm)(__ccgo_up(*(*uintptr)(unsafe.Pointer(bp + 8 + 8 + 8)) + uintptr(i)*16))).Fp = pIdx
					(**(**TIndexListTerm)(__ccgo_up(*(*uintptr)(unsafe.Pointer(bp + 8 + 8 + 8)) + uintptr(i)*16))).Fix = jj
					i = i + 1
					goto _5
				_5:
					;
					pTerm = (*TUpsert)(unsafe.Pointer(pTerm)).FpNextUpsert
				}
				jj = 0
				pIdx = (*TTable)(unsafe.Pointer(pTab)).FpIndex
				for {
					if !(pIdx != 0) {
						break
					}
					if **(**Tu8)(__ccgo_up(bUsed + uintptr(jj))) != 0 {
						goto _6
					}
					(**(**TIndexListTerm)(__ccgo_up(*(*uintptr)(unsafe.Pointer(bp + 8 + 8 + 8)) + uintptr(i)*16))).Fp = pIdx
					(**(**TIndexListTerm)(__ccgo_up(*(*uintptr)(unsafe.Pointer(bp + 8 + 8 + 8)) + uintptr(i)*16))).Fix = jj
					i = i + 1
					goto _6
				_6:
					;
					pIdx = (*TIndex)(unsafe.Pointer(pIdx)).FpNext
					jj = jj + 1
				}
			}
		}
	}
	/* Determine if it is possible that triggers (either explicitly coded
	 ** triggers or FK resolution actions) might run as a result of deletes
	 ** that happen when OE_Replace conflict resolution occurs. (Call these
	 ** "replace triggers".)  If any replace triggers run, we will need to
	 ** recheck all of the uniqueness constraints after they have all run.
	 ** But on the recheck, the resolution is OE_Abort instead of OE_Replace.
	 **
	 ** If replace triggers are a possibility, then
	 **
	 **   (1) Allocate register regTrigCnt and initialize it to zero.
	 **       That register will count the number of replace triggers that
	 **       fire.  Constraint recheck only occurs if the number is positive.
	 **   (2) Initialize pTrigger to the list of all DELETE triggers on pTab.
	 **   (3) Initialize addrRecheck and lblRecheckOk
	 **
	 ** The uniqueness rechecking code will create a series of tests to run
	 ** in a second pass.  The addrRecheck and lblRecheckOk variables are
	 ** used to link together these tests which are separated from each other
	 ** in the generate bytecode.
	 */
	if (*Tsqlite3)(unsafe.Pointer(db)).Fflags&libc.Uint64FromInt32(libc.Int32FromInt32(SQLITE_RecTriggers)|libc.Int32FromInt32(SQLITE_ForeignKeys)) == uint64(0) {
		/* There are not DELETE triggers nor FK constraints.  No constraint
		 ** rechecks are needed. */
		pTrigger = uintptr(0)
		regTrigCnt = 0
	} else {
		if (*Tsqlite3)(unsafe.Pointer(db)).Fflags&uint64(SQLITE_RecTriggers) != 0 {
			pTrigger = _sqlite3TriggersExist(tls, pParse, pTab, int32(TK_DELETE), uintptr(0), uintptr(0))
			regTrigCnt = libc.BoolInt32(pTrigger != uintptr(0) || _sqlite3FkRequired(tls, pParse, pTab, uintptr(0), 0) != 0)
		} else {
			pTrigger = uintptr(0)
			regTrigCnt = _sqlite3FkRequired(tls, pParse, pTab, uintptr(0), 0)
		}
		if regTrigCnt != 0 {
			/* Replace triggers might exist.  Allocate the counter and
			 ** initialize it to zero. */
			v8 = pParse + 60
			*(*int32)(unsafe.Pointer(v8)) = *(*int32)(unsafe.Pointer(v8)) + 1
			v2 = *(*int32)(unsafe.Pointer(v8))
			regTrigCnt = v2
			_sqlite3VdbeAddOp2(tls, v, int32(OP_Integer), 0, regTrigCnt)
			lblRecheckOk = _sqlite3VdbeMakeLabel(tls, pParse)
			addrRecheck = lblRecheckOk
		}
	}
	/* If rowid is changing, make sure the new rowid does not previously
	 ** exist in the table.
	 */
	if pkChng != 0 && pPk == uintptr(0) {
		addrRowidOk = _sqlite3VdbeMakeLabel(tls, pParse)
		/* Figure out what action to take in case of a rowid collision */
		onError = libc.Int32FromUint8((*TTable)(unsafe.Pointer(pTab)).FkeyConf)
		if libc.Int32FromUint8(overrideError) != int32(OE_Default) {
			onError = libc.Int32FromUint8(overrideError)
		} else {
			if onError == int32(OE_Default) {
				onError = int32(OE_Abort)
			}
		}
		/* figure out whether or not upsert applies in this case */
		if pUpsert != 0 {
			pUpsertClause = _sqlite3UpsertOfIndex(tls, pUpsert, uintptr(0))
			if pUpsertClause != uintptr(0) {
				if libc.Int32FromUint8((*TUpsert)(unsafe.Pointer(pUpsertClause)).FisDoUpdate) == 0 {
					onError = int32(OE_Ignore) /* DO NOTHING is the same as INSERT OR IGNORE */
				} else {
					onError = int32(OE_Update) /* DO UPDATE */
				}
			}
			if pUpsertClause != pUpsert {
				/* The first ON CONFLICT clause has a conflict target other than
				 ** the IPK.  We have to jump ahead to that first ON CONFLICT clause
				 ** and then come back here and deal with the IPK afterwards */
				upsertIpkDelay = _sqlite3VdbeAddOp0(tls, v, int32(OP_Goto))
			}
		}
		/* If the response to a rowid conflict is REPLACE but the response
		 ** to some other UNIQUE constraint is FAIL or IGNORE, then we need
		 ** to defer the running of the rowid conflict checking until after
		 ** the UNIQUE constraints have run.
		 */
		if onError == int32(OE_Replace) && onError != libc.Int32FromUint8(overrideError) && (*TTable)(unsafe.Pointer(pTab)).FpIndex != 0 && !(upsertIpkDelay != 0) {
			ipkTop = _sqlite3VdbeAddOp0(tls, v, int32(OP_Goto)) + int32(1)
		}
		if isUpdate != 0 {
			/* pkChng!=0 does not mean that the rowid has changed, only that
			 ** it might have changed.  Skip the conflict logic below if the rowid
			 ** is unchanged. */
			_sqlite3VdbeAddOp3(tls, v, int32(OP_Eq), regNewData, addrRowidOk, regOldData)
			_sqlite3VdbeChangeP5(tls, v, uint16(SQLITE_NOTNULL))
		}
		/* Check to see if the new rowid already exists in the table.  Skip
		 ** the following conflict logic if it does not. */
		_sqlite3VdbeAddOp3(tls, v, int32(OP_NotExists), iDataCur, addrRowidOk, regNewData)
		switch onError {
		default:
			onError = int32(OE_Abort)
			fallthrough
		case int32(OE_Rollback):
			fallthrough
		case int32(OE_Abort):
			fallthrough
		case int32(OE_Fail):
			_sqlite3RowidConstraint(tls, pParse, onError, pTab)
		case int32(OE_Replace):
			/* If there are DELETE triggers on this table and the
			 ** recursive-triggers flag is set, call GenerateRowDelete() to
			 ** remove the conflicting row from the table. This will fire
			 ** the triggers and remove both the table and index b-tree entries.
			 **
			 ** Otherwise, if there are no triggers or the recursive-triggers
			 ** flag is not set, but the table has one or more indexes, call
			 ** GenerateRowIndexDelete(). This removes the index b-tree entries
			 ** only. The table b-tree entry will be replaced by the new entry
			 ** when it is inserted.
			 **
			 ** If either GenerateRowDelete() or GenerateRowIndexDelete() is called,
			 ** also invoke MultiWrite() to indicate that this VDBE may require
			 ** statement rollback (if the statement is aborted after the delete
			 ** takes place). Earlier versions called sqlite3MultiWrite() regardless,
			 ** but being more selective here allows statements like:
			 **
			 **   REPLACE INTO t(rowid) VALUES($newrowid)
			 **
			 ** to run without a statement journal if there are no indexes on the
			 ** table.
			 */
			if regTrigCnt != 0 {
				_sqlite3MultiWrite(tls, pParse)
				_sqlite3GenerateRowDelete(tls, pParse, pTab, pTrigger, iDataCur, iIdxCur, regNewData, int16(1), uint8(0), uint8(OE_Replace), uint8(1), -int32(1))
				_sqlite3VdbeAddOp2(tls, v, int32(OP_AddImm), regTrigCnt, int32(1)) /* incr trigger cnt */
				nReplaceTrig = nReplaceTrig + 1
			} else {
				/* This OP_Delete opcode fires the pre-update-hook only. It does
				 ** not modify the b-tree. It is more efficient to let the coming
				 ** OP_Insert replace the existing entry than it is to delete the
				 ** existing entry and then insert a new one. */
				_sqlite3VdbeAddOp2(tls, v, int32(OP_Delete), iDataCur, int32(OPFLAG_ISNOOP))
				_sqlite3VdbeAppendP4(tls, v, pTab, -int32(5))
				if (*TTable)(unsafe.Pointer(pTab)).FpIndex != 0 {
					_sqlite3MultiWrite(tls, pParse)
					_sqlite3GenerateRowIndexDelete(tls, pParse, pTab, iDataCur, iIdxCur, uintptr(0), -int32(1))
				}
			}
			seenReplace = int32(1)
		case int32(OE_Update):
			_sqlite3UpsertDoUpdate(tls, pParse, pUpsert, pTab, uintptr(0), iDataCur)
			fallthrough
		case int32(OE_Ignore):
			_sqlite3VdbeGoto(tls, v, ignoreDest)
			break
		}
		_sqlite3VdbeResolveLabel(tls, v, addrRowidOk)
		if pUpsert != 0 && pUpsertClause != pUpsert {
			upsertIpkReturn = _sqlite3VdbeAddOp0(tls, v, int32(OP_Goto))
		} else {
			if ipkTop != 0 {
				ipkBottom = _sqlite3VdbeAddOp0(tls, v, int32(OP_Goto))
				_sqlite3VdbeJumpHere(tls, v, ipkTop-int32(1))
			}
		}
	}
	/* Test all UNIQUE constraints by creating entries for each UNIQUE
	 ** index and making sure that duplicate entries do not already exist.
	 ** Compute the revised record entries for indices as we go.
	 **
	 ** This loop also handles the case of the PRIMARY KEY index for a
	 ** WITHOUT ROWID table.
	 */
	pIdx = _indexIteratorFirst(tls, bp+8, bp)
	for {
		if !(pIdx != 0) {
			break
		} /* First opcode in the conflict check logic */
		if **(**int32)(__ccgo_up(aRegIdx + uintptr(**(**int32)(__ccgo_up(bp)))*4)) == 0 {
			goto _9
		} /* Skip indices that do not change */
		if pUpsert != 0 {
			pUpsertClause = _sqlite3UpsertOfIndex(tls, pUpsert, pIdx)
			if upsertIpkDelay != 0 && pUpsertClause == pUpsert {
				_sqlite3VdbeJumpHere(tls, v, upsertIpkDelay)
			}
		}
		addrUniqueOk = _sqlite3VdbeMakeLabel(tls, pParse)
		if libc.Int32FromUint8(bAffinityDone) == 0 {
			_sqlite3TableAffinity(tls, v, pTab, regNewData+int32(1))
			bAffinityDone = uint8(1)
		}
		iThisCur = iIdxCur + **(**int32)(__ccgo_up(bp))
		/* Skip partial indices for which the WHERE clause is not true */
		if (*TIndex)(unsafe.Pointer(pIdx)).FpPartIdxWhere != 0 {
			_sqlite3VdbeAddOp2(tls, v, int32(OP_Null), 0, **(**int32)(__ccgo_up(aRegIdx + uintptr(**(**int32)(__ccgo_up(bp)))*4)))
			(*TParse)(unsafe.Pointer(pParse)).FiSelfTab = -(regNewData + int32(1))
			_sqlite3ExprIfFalseDup(tls, pParse, (*TIndex)(unsafe.Pointer(pIdx)).FpPartIdxWhere, addrUniqueOk, int32(SQLITE_JUMPIFNULL))
			(*TParse)(unsafe.Pointer(pParse)).FiSelfTab = 0
		}
		/* Create a record for this index entry as it should appear after
		 ** the insert or update.  Store that record in the aRegIdx[ix] register
		 */
		regIdx = **(**int32)(__ccgo_up(aRegIdx + uintptr(**(**int32)(__ccgo_up(bp)))*4)) + int32(1)
		i = 0
		for {
			if !(i < libc.Int32FromUint16((*TIndex)(unsafe.Pointer(pIdx)).FnColumn)) {
				break
			}
			iField = int32(**(**Ti16)(__ccgo_up((*TIndex)(unsafe.Pointer(pIdx)).FaiColumn + uintptr(i)*2)))
			if iField == -int32(2) {
				(*TParse)(unsafe.Pointer(pParse)).FiSelfTab = -(regNewData + int32(1))
				_sqlite3ExprCodeCopy(tls, pParse, (*(*TExprList_item)(unsafe.Pointer((*TIndex)(unsafe.Pointer(pIdx)).FaColExpr + 8 + uintptr(i)*32))).FpExpr, regIdx+i)
				(*TParse)(unsafe.Pointer(pParse)).FiSelfTab = 0
			} else {
				if iField == -int32(1) || iField == int32((*TTable)(unsafe.Pointer(pTab)).FiPKey) {
					x = regNewData
					_sqlite3VdbeAddOp2(tls, v, int32(OP_IntCopy), x, regIdx+i)
				} else {
					x = int32(_sqlite3TableColumnToStorage(tls, pTab, int16(iField))) + regNewData + int32(1)
					_sqlite3VdbeAddOp2(tls, v, int32(OP_SCopy), x, regIdx+i)
				}
			}
			goto _10
		_10:
			;
			i = i + 1
		}
		_sqlite3VdbeAddOp3(tls, v, int32(OP_MakeRecord), regIdx, libc.Int32FromUint16((*TIndex)(unsafe.Pointer(pIdx)).FnColumn), **(**int32)(__ccgo_up(aRegIdx + uintptr(**(**int32)(__ccgo_up(bp)))*4)))
		/* In an UPDATE operation, if this index is the PRIMARY KEY index
		 ** of a WITHOUT ROWID table and there has been no change the
		 ** primary key, then no collision is possible.  The collision detection
		 ** logic below can all be skipped. */
		if isUpdate != 0 && pPk == pIdx && libc.Int32FromUint8(pkChng) == 0 {
			_sqlite3VdbeResolveLabel(tls, v, addrUniqueOk)
			goto _9
		}
		/* Find out what action to take in case there is a uniqueness conflict */
		onError = libc.Int32FromUint8((*TIndex)(unsafe.Pointer(pIdx)).FonError)
		if onError == OE_None {
			_sqlite3VdbeResolveLabel(tls, v, addrUniqueOk)
			goto _9 /* pIdx is not a UNIQUE index */
		}
		if libc.Int32FromUint8(overrideError) != int32(OE_Default) {
			onError = libc.Int32FromUint8(overrideError)
		} else {
			if onError == int32(OE_Default) {
				onError = int32(OE_Abort)
			}
		}
		/* Figure out if the upsert clause applies to this index */
		if pUpsertClause != 0 {
			if libc.Int32FromUint8((*TUpsert)(unsafe.Pointer(pUpsertClause)).FisDoUpdate) == 0 {
				onError = int32(OE_Ignore) /* DO NOTHING is the same as INSERT OR IGNORE */
			} else {
				onError = int32(OE_Update) /* DO UPDATE */
			}
		}
		/* Collision detection may be omitted if all of the following are true:
		 **   (1) The conflict resolution algorithm is REPLACE
		 **   (2) The table is a WITHOUT ROWID table
		 **   (3) There are no secondary indexes on the table
		 **   (4) No delete triggers need to be fired if there is a conflict
		 **   (5) No FK constraint counters need to be updated if a conflict occurs.
		 **
		 ** This is not possible for ENABLE_PREUPDATE_HOOK builds, as the row
		 ** must be explicitly deleted in order to ensure any pre-update hook
		 ** is invoked.  */
		/* Check to see if the new index entry will be unique */
		addrConflictCk = _sqlite3VdbeAddOp4Int(tls, v, int32(OP_NoConflict), iThisCur, addrUniqueOk, regIdx, libc.Int32FromUint16((*TIndex)(unsafe.Pointer(pIdx)).FnKeyCol))
		/* Generate code to handle collisions */
		if pIdx == pPk {
			v2 = regIdx
		} else {
			v2 = _sqlite3GetTempRange(tls, pParse, nPkField)
		}
		regR = v2
		if isUpdate != 0 || onError == int32(OE_Replace) {
			if (*TTable)(unsafe.Pointer(pTab)).FtabFlags&uint32(TF_WithoutRowid) == uint32(0) {
				_sqlite3VdbeAddOp2(tls, v, int32(OP_IdxRowid), iThisCur, regR)
				/* Conflict only if the rowid of the existing index entry
				 ** is different from old-rowid */
				if isUpdate != 0 {
					_sqlite3VdbeAddOp3(tls, v, int32(OP_Eq), regR, addrUniqueOk, regOldData)
					_sqlite3VdbeChangeP5(tls, v, uint16(SQLITE_NOTNULL))
				}
			} else {
				/* Extract the PRIMARY KEY from the end of the index entry and
				 ** store it in registers regR..regR+nPk-1 */
				if pIdx != pPk {
					i = 0
					for {
						if !(i < libc.Int32FromUint16((*TIndex)(unsafe.Pointer(pPk)).FnKeyCol)) {
							break
						}
						x1 = _sqlite3TableColumnToIndex(tls, pIdx, int32(**(**Ti16)(__ccgo_up((*TIndex)(unsafe.Pointer(pPk)).FaiColumn + uintptr(i)*2))))
						_sqlite3VdbeAddOp3(tls, v, int32(OP_Column), iThisCur, x1, regR+i)
						goto _12
					_12:
						;
						i = i + 1
					}
				}
				if isUpdate != 0 {
					/* If currently processing the PRIMARY KEY of a WITHOUT ROWID
					 ** table, only conflict if the new PRIMARY KEY values are actually
					 ** different from the old.  See TH3 withoutrowid04.test.
					 **
					 ** For a UNIQUE index, only conflict if the PRIMARY KEY values
					 ** of the matched index row are different from the original PRIMARY
					 ** KEY values of this row before the update.  */
					addrJump = _sqlite3VdbeCurrentAddr(tls, v) + libc.Int32FromUint16((*TIndex)(unsafe.Pointer(pPk)).FnKeyCol)
					op = int32(OP_Ne)
					if int32(uint32(*(*uint16)(unsafe.Pointer(pIdx + 100))&0x3>>0)) == int32(SQLITE_IDXTYPE_PRIMARYKEY) {
						v2 = regIdx
					} else {
						v2 = regR
					}
					regCmp = v2
					i = 0
					for {
						if !(i < libc.Int32FromUint16((*TIndex)(unsafe.Pointer(pPk)).FnKeyCol)) {
							break
						}
						p4 = _sqlite3LocateCollSeq(tls, pParse, **(**uintptr)(__ccgo_up((*TIndex)(unsafe.Pointer(pPk)).FazColl + uintptr(i)*8)))
						x1 = int32(**(**Ti16)(__ccgo_up((*TIndex)(unsafe.Pointer(pPk)).FaiColumn + uintptr(i)*2)))
						if i == libc.Int32FromUint16((*TIndex)(unsafe.Pointer(pPk)).FnKeyCol)-int32(1) {
							addrJump = addrUniqueOk
							op = int32(OP_Eq)
						}
						x1 = int32(_sqlite3TableColumnToStorage(tls, pTab, int16(x1)))
						_sqlite3VdbeAddOp4(tls, v, op, regOldData+int32(1)+x1, addrJump, regCmp+i, p4, -int32(2))
						_sqlite3VdbeChangeP5(tls, v, uint16(SQLITE_NOTNULL))
						goto _14
					_14:
						;
						i = i + 1
					}
				}
			}
		}
		/* Generate code that executes if the new index entry is not unique */
		switch onError {
		case int32(OE_Rollback):
			fallthrough
		case int32(OE_Abort):
			fallthrough
		case int32(OE_Fail):
			_sqlite3UniqueConstraint(tls, pParse, onError, pIdx)
		case int32(OE_Update):
			_sqlite3UpsertDoUpdate(tls, pParse, pUpsert, pTab, pIdx, iIdxCur+**(**int32)(__ccgo_up(bp)))
			fallthrough
		case int32(OE_Ignore):
			_sqlite3VdbeGoto(tls, v, ignoreDest)
		default: /* Number of opcodes in conflict check logic */
			nConflictCk = _sqlite3VdbeCurrentAddr(tls, v) - addrConflictCk
			if regTrigCnt != 0 {
				_sqlite3MultiWrite(tls, pParse)
				nReplaceTrig = nReplaceTrig + 1
			}
			if pTrigger != 0 && isUpdate != 0 {
				_sqlite3VdbeAddOp1(tls, v, int32(OP_CursorLock), iDataCur)
			}
			if pIdx == pPk {
				v2 = int32(ONEPASS_SINGLE)
			} else {
				v2 = ONEPASS_OFF
			}
			_sqlite3GenerateRowDelete(tls, pParse, pTab, pTrigger, iDataCur, iIdxCur, regR, int16(nPkField), uint8(0), uint8(OE_Replace), libc.Uint8FromInt32(v2), iThisCur)
			if pTrigger != 0 && isUpdate != 0 {
				_sqlite3VdbeAddOp1(tls, v, int32(OP_CursorUnlock), iDataCur)
			}
			if regTrigCnt != 0 { /* Jump destination to bypass recheck logic */
				_sqlite3VdbeAddOp2(tls, v, int32(OP_AddImm), regTrigCnt, int32(1)) /* incr trigger cnt */
				addrBypass = _sqlite3VdbeAddOp0(tls, v, int32(OP_Goto))            /* Bypass recheck */
				/* Here we insert code that will be invoked after all constraint
				 ** checks have run, if and only if one or more replace triggers
				 ** fired. */
				_sqlite3VdbeResolveLabel(tls, v, lblRecheckOk)
				lblRecheckOk = _sqlite3VdbeMakeLabel(tls, pParse)
				if (*TIndex)(unsafe.Pointer(pIdx)).FpPartIdxWhere != 0 {
					/* Bypass the recheck if this partial index is not defined
					 ** for the current row */
					_sqlite3VdbeAddOp2(tls, v, int32(OP_IsNull), regIdx-int32(1), lblRecheckOk)
				}
				/* Copy the constraint check code from above, except change
				 ** the constraint-ok jump destination to be the address of
				 ** the next retest block */
				for nConflictCk > 0 { /* Conflict check opcode to copy */
					/* The sqlite3VdbeAddOp4() call might reallocate the opcode array.
					 ** Hence, make a complete copy of the opcode, rather than using
					 ** a pointer to the opcode. */
					**(**TVdbeOp)(__ccgo_up(bp + 32)) = **(**TVdbeOp)(__ccgo_up(_sqlite3VdbeGetOp(tls, v, addrConflictCk)))
					if libc.Int32FromUint8((**(**TVdbeOp)(__ccgo_up(bp + 32))).Fopcode) != int32(OP_IdxRowid) {
						if libc.Int32FromUint8(_sqlite3OpcodeProperty[(**(**TVdbeOp)(__ccgo_up(bp + 32))).Fopcode])&int32(OPFLG_JUMP) != 0 {
							p2 = lblRecheckOk
						} else {
							p2 = (**(**TVdbeOp)(__ccgo_up(bp + 32))).Fp2
						}
						if int32((**(**TVdbeOp)(__ccgo_up(bp + 32))).Fp4type) == -int32(3) {
							v8 = uintptr(int64(*(*int32)(unsafe.Pointer(bp + 32 + 16))))
						} else {
							v8 = *(*uintptr)(unsafe.Pointer(bp + 32 + 16))
						}
						zP4 = v8
						_sqlite3VdbeAddOp4(tls, v, libc.Int32FromUint8((**(**TVdbeOp)(__ccgo_up(bp + 32))).Fopcode), (**(**TVdbeOp)(__ccgo_up(bp + 32))).Fp1, p2, (**(**TVdbeOp)(__ccgo_up(bp + 32))).Fp3, zP4, int32((**(**TVdbeOp)(__ccgo_up(bp + 32))).Fp4type))
						_sqlite3VdbeChangeP5(tls, v, (**(**TVdbeOp)(__ccgo_up(bp + 32))).Fp5)
					}
					nConflictCk = nConflictCk - 1
					addrConflictCk = addrConflictCk + 1
				}
				/* If the retest fails, issue an abort */
				_sqlite3UniqueConstraint(tls, pParse, int32(OE_Abort), pIdx)
				_sqlite3VdbeJumpHere(tls, v, addrBypass) /* Terminate the recheck bypass */
			}
			seenReplace = int32(1)
			break
		}
		_sqlite3VdbeResolveLabel(tls, v, addrUniqueOk)
		if regR != regIdx {
			_sqlite3ReleaseTempRange(tls, pParse, regR, nPkField)
		}
		if pUpsertClause != 0 && upsertIpkReturn != 0 && _sqlite3UpsertNextIsIPK(tls, pUpsertClause) != 0 {
			_sqlite3VdbeGoto(tls, v, upsertIpkDelay+int32(1))
			_sqlite3VdbeJumpHere(tls, v, upsertIpkReturn)
			upsertIpkReturn = 0
		}
		goto _9
	_9:
		;
		pIdx = _indexIteratorNext(tls, bp+8, bp)
	}
	/* If the IPK constraint is a REPLACE, run it last */
	if ipkTop != 0 {
		_sqlite3VdbeGoto(tls, v, ipkTop)
		_sqlite3VdbeJumpHere(tls, v, ipkBottom)
	}
	/* Recheck all uniqueness constraints after replace triggers have run */
	if nReplaceTrig != 0 {
		_sqlite3VdbeAddOp2(tls, v, int32(OP_IfNot), regTrigCnt, lblRecheckOk)
		if !(pPk != 0) {
			if isUpdate != 0 {
				_sqlite3VdbeAddOp3(tls, v, int32(OP_Eq), regNewData, addrRecheck, regOldData)
				_sqlite3VdbeChangeP5(tls, v, uint16(SQLITE_NOTNULL))
			}
			_sqlite3VdbeAddOp3(tls, v, int32(OP_NotExists), iDataCur, addrRecheck, regNewData)
			_sqlite3RowidConstraint(tls, pParse, int32(OE_Abort), pTab)
		} else {
			_sqlite3VdbeGoto(tls, v, addrRecheck)
		}
		_sqlite3VdbeResolveLabel(tls, v, lblRecheckOk)
	}
	/* Generate the table record */
	if (*TTable)(unsafe.Pointer(pTab)).FtabFlags&uint32(TF_WithoutRowid) == uint32(0) {
		regRec = **(**int32)(__ccgo_up(aRegIdx + uintptr(**(**int32)(__ccgo_up(bp)))*4))
		_sqlite3VdbeAddOp3(tls, v, int32(OP_MakeRecord), regNewData+int32(1), int32((*TTable)(unsafe.Pointer(pTab)).FnNVCol), regRec)
		if !(bAffinityDone != 0) {
			_sqlite3TableAffinity(tls, v, pTab, 0)
		}
	}
	**(**int32)(__ccgo_up(pbMayReplace)) = seenReplace
}

// C documentation
//
//	/*
//	** This routine generates VDBE code that causes a single row of a
//	** single table to be deleted.  Both the original table entry and
//	** all indices are removed.
//	**
//	** Preconditions:
//	**
//	**   1.  iDataCur is an open cursor on the btree that is the canonical data
//	**       store for the table.  (This will be either the table itself,
//	**       in the case of a rowid table, or the PRIMARY KEY index in the case
//	**       of a WITHOUT ROWID table.)
//	**
//	**   2.  Read/write cursors for all indices of pTab must be open as
//	**       cursor number iIdxCur+i for the i-th index.
//	**
//	**   3.  The primary key for the row to be deleted must be stored in a
//	**       sequence of nPk memory cells starting at iPk.  If nPk==0 that means
//	**       that a search record formed from OP_MakeRecord is contained in the
//	**       single memory location iPk.
//	**
//	** eMode:
//	**   Parameter eMode may be passed either ONEPASS_OFF (0), ONEPASS_SINGLE, or
//	**   ONEPASS_MULTI.  If eMode is not ONEPASS_OFF, then the cursor
//	**   iDataCur already points to the row to delete. If eMode is ONEPASS_OFF
//	**   then this function must seek iDataCur to the entry identified by iPk
//	**   and nPk before reading from it.
//	**
//	**   If eMode is ONEPASS_MULTI, then this call is being made as part
//	**   of a ONEPASS delete that affects multiple rows. In this case, if
//	**   iIdxNoSeek is a valid cursor number (>=0) and is not the same as
//	**   iDataCur, then its position should be preserved following the delete
//	**   operation. Or, if iIdxNoSeek is not a valid cursor number, the
//	**   position of iDataCur should be preserved instead.
//	**
//	** iIdxNoSeek:
//	**   If iIdxNoSeek is a valid cursor number (>=0) not equal to iDataCur,
//	**   then it identifies an index cursor (from within array of cursors
//	**   starting at iIdxCur) that already points to the index entry to be deleted.
//	**   Except, this optimization is disabled if there are BEFORE triggers since
//	**   the trigger body might have moved the cursor.
//	*/
func _sqlite3GenerateRowDelete(tls *libc.TLS, pParse uintptr, pTab uintptr, pTrigger uintptr, iDataCur int32, iIdxCur int32, iPk int32, nPk Ti16, count Tu8, onconf Tu8, eMode Tu8, iIdxNoSeek int32) {
	var addrStart, iCol, iLabel, iOld, kk, v1 int32
	var mask Tu32
	var opSeek, p5 Tu8
	var v uintptr
	_, _, _, _, _, _, _, _, _, _ = addrStart, iCol, iLabel, iOld, kk, mask, opSeek, p5, v, v1
	v = (*TParse)(unsafe.Pointer(pParse)).FpVdbe /* Vdbe */
	iOld = 0                                     /* Seek opcode */
	/* Vdbe is guaranteed to have been allocated by this stage. */
	/* Seek cursor iCur to the row to delete. If this row no longer exists
	 ** (this can happen if a trigger program has already deleted it), do
	 ** not attempt to delete it or fire any DELETE triggers.  */
	iLabel = _sqlite3VdbeMakeLabel(tls, pParse)
	if (*TTable)(unsafe.Pointer(pTab)).FtabFlags&uint32(TF_WithoutRowid) == uint32(0) {
		v1 = int32(OP_NotExists)
	} else {
		v1 = int32(OP_NotFound)
	}
	opSeek = libc.Uint8FromInt32(v1)
	if libc.Int32FromUint8(eMode) == ONEPASS_OFF {
		_sqlite3VdbeAddOp4Int(tls, v, libc.Int32FromUint8(opSeek), iDataCur, iLabel, iPk, int32(nPk))
	}
	/* If there are any triggers to fire, allocate a range of registers to
	 ** use for the old.* references in the triggers.  */
	if _sqlite3FkRequired(tls, pParse, pTab, uintptr(0), 0) != 0 || pTrigger != 0 { /* Start of BEFORE trigger programs */
		/* TODO: Could use temporary registers here. Also could attempt to
		 ** avoid copying the contents of the rowid register.  */
		mask = _sqlite3TriggerColmask(tls, pParse, pTrigger, uintptr(0), 0, libc.Int32FromInt32(TRIGGER_BEFORE)|libc.Int32FromInt32(TRIGGER_AFTER), pTab, libc.Int32FromUint8(onconf))
		mask = mask | _sqlite3FkOldmask(tls, pParse, pTab)
		iOld = (*TParse)(unsafe.Pointer(pParse)).FnMem + int32(1)
		**(**int32)(__ccgo_up(pParse + 60)) += int32(1) + int32((*TTable)(unsafe.Pointer(pTab)).FnCol)
		/* Populate the OLD.* pseudo-table register array. These values will be
		 ** used by any BEFORE and AFTER triggers that exist.  */
		_sqlite3VdbeAddOp2(tls, v, int32(OP_Copy), iPk, iOld)
		iCol = 0
		for {
			if !(iCol < int32((*TTable)(unsafe.Pointer(pTab)).FnCol)) {
				break
			}
			if mask == uint32(0xffffffff) || iCol <= int32(31) && mask&(libc.Uint32FromInt32(1)<<iCol) != uint32(0) {
				kk = int32(_sqlite3TableColumnToStorage(tls, pTab, int16(iCol)))
				_sqlite3ExprCodeGetColumnOfTable(tls, v, pTab, iDataCur, iCol, iOld+kk+int32(1))
			}
			goto _2
		_2:
			;
			iCol = iCol + 1
		}
		/* Invoke BEFORE DELETE trigger programs. */
		addrStart = _sqlite3VdbeCurrentAddr(tls, v)
		_sqlite3CodeRowTrigger(tls, pParse, pTrigger, int32(TK_DELETE), uintptr(0), int32(TRIGGER_BEFORE), pTab, iOld, libc.Int32FromUint8(onconf), iLabel)
		/* If any BEFORE triggers were coded, then seek the cursor to the
		 ** row to be deleted again. It may be that the BEFORE triggers moved
		 ** the cursor or already deleted the row that the cursor was
		 ** pointing to.
		 **
		 ** Also disable the iIdxNoSeek optimization since the BEFORE trigger
		 ** may have moved that cursor.
		 */
		if addrStart < _sqlite3VdbeCurrentAddr(tls, v) {
			_sqlite3VdbeAddOp4Int(tls, v, libc.Int32FromUint8(opSeek), iDataCur, iLabel, iPk, int32(nPk))
			iIdxNoSeek = -int32(1)
		}
		/* Do FK processing. This call checks that any FK constraints that
		 ** refer to this table (i.e. constraints attached to other tables)
		 ** are not violated by deleting this row.  */
		_sqlite3FkCheck(tls, pParse, pTab, iOld, 0, uintptr(0), 0)
	}
	/* Delete the index and table entries. Skip this step if pTab is really
	 ** a view (in which case the only effect of the DELETE statement is to
	 ** fire the INSTEAD OF triggers).
	 **
	 ** If variable 'count' is non-zero, then this OP_Delete instruction should
	 ** invoke the update-hook. The pre-update-hook, on the other hand should
	 ** be invoked unless table pTab is a system table. The difference is that
	 ** the update-hook is not invoked for rows removed by REPLACE, but the
	 ** pre-update-hook is.
	 */
	if !(libc.Int32FromUint8((*TTable)(unsafe.Pointer(pTab)).FeTabType) == libc.Int32FromInt32(TABTYP_VIEW)) {
		p5 = uint8(0)
		_sqlite3GenerateRowIndexDelete(tls, pParse, pTab, iDataCur, iIdxCur, uintptr(0), iIdxNoSeek)
		if count != 0 {
			v1 = int32(OPFLAG_NCHANGE)
		} else {
			v1 = 0
		}
		_sqlite3VdbeAddOp2(tls, v, int32(OP_Delete), iDataCur, v1)
		if libc.Int32FromUint8((*TParse)(unsafe.Pointer(pParse)).Fnested) == 0 || 0 == Xsqlite3_stricmp(tls, (*TTable)(unsafe.Pointer(pTab)).FzName, __ccgo_ts+12826) {
			_sqlite3VdbeAppendP4(tls, v, pTab, -int32(5))
		}
		if libc.Int32FromUint8(eMode) != ONEPASS_OFF {
			_sqlite3VdbeChangeP5(tls, v, uint16(OPFLAG_AUXDELETE))
		}
		if iIdxNoSeek >= 0 && iIdxNoSeek != iDataCur {
			_sqlite3VdbeAddOp1(tls, v, int32(OP_Delete), iIdxNoSeek)
		}
		if libc.Int32FromUint8(eMode) == int32(ONEPASS_MULTI) {
			p5 = libc.Uint8FromInt32(int32(p5) | libc.Int32FromInt32(OPFLAG_SAVEPOSITION))
		}
		_sqlite3VdbeChangeP5(tls, v, uint16(p5))
	}
	/* Do any ON CASCADE, SET NULL or SET DEFAULT operations required to
	 ** handle rows (possibly in other tables) that refer via a foreign key
	 ** to the row just deleted. */
	_sqlite3FkActions(tls, pParse, pTab, uintptr(0), iOld, uintptr(0), 0)
	/* Invoke AFTER DELETE trigger programs. */
	if pTrigger != 0 {
		_sqlite3CodeRowTrigger(tls, pParse, pTrigger, int32(TK_DELETE), uintptr(0), int32(TRIGGER_AFTER), pTab, iOld, libc.Int32FromUint8(onconf), iLabel)
	}
	/* Jump here if the row had already been deleted before any BEFORE
	 ** trigger programs were invoked. Or if a trigger program throws a
	 ** RAISE(IGNORE) exception.  */
	_sqlite3VdbeResolveLabel(tls, v, iLabel)
}

// C documentation
//
//	/*
//	** This function is responsible for invoking the collation factory callback
//	** or substituting a collation sequence of a different encoding when the
//	** requested collation sequence is not available in the desired encoding.
//	**
//	** If it is not NULL, then pColl must point to the database native encoding
//	** collation sequence with name zName, length nName.
//	**
//	** The return value is either the collation sequence to be used in database
//	** db for collation type name zName, length nName, or NULL, if no collation
//	** sequence can be found.  If no collation is found, leave an error message.
//	**
//	** See also: sqlite3LocateCollSeq(), sqlite3FindCollSeq()
//	*/
func _sqlite3GetCollSeq(tls *libc.TLS, pParse uintptr, enc Tu8, pColl uintptr, zName uintptr) (r uintptr) {
	bp := tls.Alloc(16)
	defer tls.Free(16)
	var db, p uintptr
	_, _ = db, p
	db = (*TParse)(unsafe.Pointer(pParse)).Fdb
	p = pColl
	if !(p != 0) {
		p = _sqlite3FindCollSeq(tls, db, enc, zName, 0)
	}
	if !(p != 0) || !((*TCollSeq)(unsafe.Pointer(p)).FxCmp != 0) {
		/* No collation sequence of this type for this encoding is registered.
		 ** Call the collation factory to see if it can supply us with one.
		 */
		_callCollNeeded(tls, db, libc.Int32FromUint8(enc), zName)
		p = _sqlite3FindCollSeq(tls, db, enc, zName, 0)
	}
	if p != 0 && !((*TCollSeq)(unsafe.Pointer(p)).FxCmp != 0) && _synthCollSeq(tls, db, p) != 0 {
		p = uintptr(0)
	}
	if p == uintptr(0) {
		_sqlite3ErrorMsg(tls, pParse, __ccgo_ts+16307, libc.VaList(bp+8, zName))
		(*TParse)(unsafe.Pointer(pParse)).Frc = libc.Int32FromInt32(SQLITE_ERROR) | libc.Int32FromInt32(1)<<libc.Int32FromInt32(8)
	}
	return p
}

// C documentation
//
//	/*
//	** If expression list pList contains an expression that was parsed with
//	** an explicit "NULLS FIRST" or "NULLS LAST" clause, leave an error in
//	** pParse and return non-zero. Otherwise, return zero.
//	*/
func _sqlite3HasExplicitNulls(tls *libc.TLS, pParse uintptr, pList uintptr) (r int32) {
	bp := tls.Alloc(16)
	defer tls.Free(16)
	var i int32
	var sf Tu8
	var v2 uintptr
	_, _, _ = i, sf, v2
	if pList != 0 {
		i = 0
		for {
			if !(i < (*TExprList)(unsafe.Pointer(pList)).FnExpr) {
				break
			}
			if int32(uint32(*(*uint16)(unsafe.Pointer(pList + 8 + uintptr(i)*32 + 16 + 4))&0x20>>5)) != 0 {
				sf = (*(*TExprList_item)(unsafe.Pointer(pList + 8 + uintptr(i)*32))).Ffg.FsortFlags
				if libc.Int32FromUint8(sf) == 0 || libc.Int32FromUint8(sf) == int32(3) {
					v2 = __ccgo_ts + 15367
				} else {
					v2 = __ccgo_ts + 15373
				}
				_sqlite3ErrorMsg(tls, pParse, __ccgo_ts+15378, libc.VaList(bp+8, v2))
				return int32(1)
			}
			goto _1
		_1:
			;
			i = i + 1
		}
	}
	return 0
}

// C documentation
//
//	/*
//	** If the source-list item passed as an argument was augmented with an
//	** INDEXED BY clause, then try to locate the specified index. If there
//	** was such a clause and the named index cannot be found, return
//	** SQLITE_ERROR and leave an error in pParse. Otherwise, populate
//	** pFrom->pIndex and return SQLITE_OK.
//	*/
func _sqlite3IndexedByLookup(tls *libc.TLS, pParse uintptr, pFrom uintptr) (r int32) {
	bp := tls.Alloc(32)
	defer tls.Free(32)
	var pIdx, pTab, zIndexedBy uintptr
	_, _, _ = pIdx, pTab, zIndexedBy
	pTab = (*TSrcItem)(unsafe.Pointer(pFrom)).FpSTab
	zIndexedBy = *(*uintptr)(unsafe.Pointer(pFrom + 48))
	pIdx = (*TTable)(unsafe.Pointer(pTab)).FpIndex
	for {
		if !(pIdx != 0 && _sqlite3StrICmp(tls, (*TIndex)(unsafe.Pointer(pIdx)).FzName, zIndexedBy) != 0) {
			break
		}
		goto _1
	_1:
		;
		pIdx = (*TIndex)(unsafe.Pointer(pIdx)).FpNext
	}
	if !(pIdx != 0) {
		_sqlite3ErrorMsg(tls, pParse, __ccgo_ts+21007, libc.VaList(bp+8, zIndexedBy, 0))
		libc.SetBitFieldPtr16Uint32(pParse+40, libc.Uint32FromInt32(1), 8, 0x100)
		return int32(SQLITE_ERROR)
	}
	*(*uintptr)(unsafe.Pointer(pFrom + 56)) = pIdx
	return SQLITE_OK
}

// C documentation
//
//	/*
//	** Attempt to read the database schema and initialize internal
//	** data structures for a single database file.  The index of the
//	** database file is given by iDb.  iDb==0 is used for the main
//	** database.  iDb==1 should never be used.  iDb>=2 is used for
//	** auxiliary databases.  Return one of the SQLITE_ error codes to
//	** indicate success or failure.
//	*/
func _sqlite3InitOne(tls *libc.TLS, db uintptr, iDb int32, pzErrMsg uintptr, mFlags Tu32) (r int32) {
	bp := tls.Alloc(144)
	defer tls.Free(144)
	var encoding Tu8
	var i, mask, openedTransaction, rc, size int32
	var pDb, zSchemaTabName, zSql, v1, v2 uintptr
	var xAuth Tsqlite3_xauth
	var _ /* azArg at bp+0 */ [6]uintptr
	var _ /* initData at bp+72 */ TInitData
	var _ /* meta at bp+48 */ [5]int32
	_, _, _, _, _, _, _, _, _, _, _, _ = encoding, i, mask, openedTransaction, pDb, rc, size, xAuth, zSchemaTabName, zSql, v1, v2
	openedTransaction = 0
	mask = libc.Int32FromUint32((*Tsqlite3)(unsafe.Pointer(db)).FmDbFlags&libc.Uint32FromInt32(DBFLAG_EncodingFixed) | libc.Uint32FromInt32(^libc.Int32FromInt32(DBFLAG_EncodingFixed)))
	(*Tsqlite3)(unsafe.Pointer(db)).Finit1.Fbusy = uint8(1)
	/* Construct the in-memory representation schema tables (sqlite_schema or
	 ** sqlite_temp_schema) by invoking the parser directly.  The appropriate
	 ** table name will be inserted automatically by the parser so we can just
	 ** use the abbreviation "x" here.  The parser will also automatically tag
	 ** the schema table as read-only. */
	(**(**[6]uintptr)(__ccgo_up(bp)))[0] = __ccgo_ts + 9370
	if libc.Bool(!(libc.Int32FromInt32(OMIT_TEMPDB) != 0)) && iDb == int32(1) {
		v2 = __ccgo_ts + 6757
	} else {
		v2 = __ccgo_ts + 6277
	}
	v1 = v2
	zSchemaTabName = v1
	(**(**[6]uintptr)(__ccgo_up(bp)))[int32(1)] = v1
	(**(**[6]uintptr)(__ccgo_up(bp)))[int32(2)] = (**(**[6]uintptr)(__ccgo_up(bp)))[int32(1)]
	(**(**[6]uintptr)(__ccgo_up(bp)))[int32(3)] = __ccgo_ts + 20096
	(**(**[6]uintptr)(__ccgo_up(bp)))[int32(4)] = __ccgo_ts + 20098
	(**(**[6]uintptr)(__ccgo_up(bp)))[int32(5)] = uintptr(0)
	(**(**TInitData)(__ccgo_up(bp + 72))).Fdb = db
	(**(**TInitData)(__ccgo_up(bp + 72))).FiDb = iDb
	(**(**TInitData)(__ccgo_up(bp + 72))).Frc = SQLITE_OK
	(**(**TInitData)(__ccgo_up(bp + 72))).FpzErrMsg = pzErrMsg
	(**(**TInitData)(__ccgo_up(bp + 72))).FmInitFlags = mFlags
	(**(**TInitData)(__ccgo_up(bp + 72))).FnInitRow = uint32(0)
	(**(**TInitData)(__ccgo_up(bp + 72))).FmxPage = uint32(0)
	_sqlite3InitCallback(tls, bp+72, int32(5), bp, uintptr(0))
	**(**Tu32)(__ccgo_up(db + 44)) &= libc.Uint32FromInt32(mask)
	if (**(**TInitData)(__ccgo_up(bp + 72))).Frc != 0 {
		rc = (**(**TInitData)(__ccgo_up(bp + 72))).Frc
		goto error_out
	}
	/* Create a cursor to hold the database open
	 */
	pDb = (*Tsqlite3)(unsafe.Pointer(db)).FaDb + uintptr(iDb)*32
	if (*TDb)(unsafe.Pointer(pDb)).FpBt == uintptr(0) {
		v1 = (**(**TDb)(__ccgo_up((*Tsqlite3)(unsafe.Pointer(db)).FaDb + 1*32))).FpSchema + 114
		*(*Tu16)(unsafe.Pointer(v1)) = Tu16(int32(*(*Tu16)(unsafe.Pointer(v1))) | libc.Int32FromInt32(DB_SchemaLoaded))
		rc = SQLITE_OK
		goto error_out
	}
	/* If there is not already a read-only (or read-write) transaction opened
	 ** on the b-tree database, open one now. If a transaction is opened, it
	 ** will be closed before this function returns.  */
	_sqlite3BtreeEnter(tls, (*TDb)(unsafe.Pointer(pDb)).FpBt)
	if _sqlite3BtreeTxnState(tls, (*TDb)(unsafe.Pointer(pDb)).FpBt) == SQLITE_TXN_NONE {
		rc = _sqlite3BtreeBeginTrans(tls, (*TDb)(unsafe.Pointer(pDb)).FpBt, 0, uintptr(0))
		if rc != SQLITE_OK {
			_sqlite3SetString(tls, pzErrMsg, db, _sqlite3ErrStr(tls, rc))
			goto initone_error_out
		}
		openedTransaction = int32(1)
	}
	/* Get the database meta information.
	 **
	 ** Meta values are as follows:
	 **    meta[0]   Schema cookie.  Changes with each schema change.
	 **    meta[1]   File format of schema layer.
	 **    meta[2]   Size of the page cache.
	 **    meta[3]   Largest rootpage (auto/incr_vacuum mode)
	 **    meta[4]   Db text encoding. 1:UTF-8 2:UTF-16LE 3:UTF-16BE
	 **    meta[5]   User version
	 **    meta[6]   Incremental vacuum mode
	 **    meta[7]   unused
	 **    meta[8]   unused
	 **    meta[9]   unused
	 **
	 ** Note: The #defined SQLITE_UTF* symbols in sqliteInt.h correspond to
	 ** the possible values of meta[4].
	 */
	i = 0
	for {
		if !(i < libc.Int32FromUint64(libc.Uint64FromInt64(20)/libc.Uint64FromInt64(4))) {
			break
		}
		_sqlite3BtreeGetMeta(tls, (*TDb)(unsafe.Pointer(pDb)).FpBt, i+int32(1), bp+48+uintptr(i)*4)
		goto _4
	_4:
		;
		i = i + 1
	}
	if (*Tsqlite3)(unsafe.Pointer(db)).Fflags&uint64(SQLITE_ResetDatabase) != uint64(0) {
		libc.Xmemset(tls, bp+48, 0, uint64(20))
	}
	(*TSchema)(unsafe.Pointer((*TDb)(unsafe.Pointer(pDb)).FpSchema)).Fschema_cookie = (**(**[5]int32)(__ccgo_up(bp + 48)))[libc.Int32FromInt32(BTREE_SCHEMA_VERSION)-libc.Int32FromInt32(1)]
	/* If opening a non-empty database, check the text encoding. For the
	 ** main database, set sqlite3.enc to the encoding of the main database.
	 ** For an attached db, it is an error if the encoding is not the same
	 ** as sqlite3.enc.
	 */
	if (**(**[5]int32)(__ccgo_up(bp + 48)))[libc.Int32FromInt32(BTREE_TEXT_ENCODING)-libc.Int32FromInt32(1)] != 0 { /* text encoding */
		if iDb == 0 && (*Tsqlite3)(unsafe.Pointer(db)).FmDbFlags&uint32(DBFLAG_EncodingFixed) == uint32(0) {
			/* If opening the main database, set ENC(db). */
			encoding = libc.Uint8FromInt32(libc.Int32FromUint8(libc.Uint8FromInt32((**(**[5]int32)(__ccgo_up(bp + 48)))[libc.Int32FromInt32(BTREE_TEXT_ENCODING)-libc.Int32FromInt32(1)])) & int32(3))
			if libc.Int32FromUint8(encoding) == 0 {
				encoding = uint8(SQLITE_UTF8)
			}
			_sqlite3SetTextEncoding(tls, db, encoding)
		} else {
			/* If opening an attached database, the encoding much match ENC(db) */
			if (**(**[5]int32)(__ccgo_up(bp + 48)))[libc.Int32FromInt32(BTREE_TEXT_ENCODING)-libc.Int32FromInt32(1)]&int32(3) != libc.Int32FromUint8((*Tsqlite3)(unsafe.Pointer(db)).Fenc) {
				_sqlite3SetString(tls, pzErrMsg, db, __ccgo_ts+13339)
				rc = int32(SQLITE_ERROR)
				goto initone_error_out
			}
		}
	}
	(*TSchema)(unsafe.Pointer((*TDb)(unsafe.Pointer(pDb)).FpSchema)).Fenc = (*Tsqlite3)(unsafe.Pointer(db)).Fenc
	if (*TSchema)(unsafe.Pointer((*TDb)(unsafe.Pointer(pDb)).FpSchema)).Fcache_size == 0 {
		size = _sqlite3AbsInt32(tls, (**(**[5]int32)(__ccgo_up(bp + 48)))[libc.Int32FromInt32(BTREE_DEFAULT_CACHE_SIZE)-libc.Int32FromInt32(1)])
		if size == 0 {
			size = -int32(2000)
		}
		(*TSchema)(unsafe.Pointer((*TDb)(unsafe.Pointer(pDb)).FpSchema)).Fcache_size = size
		_sqlite3BtreeSetCacheSize(tls, (*TDb)(unsafe.Pointer(pDb)).FpBt, (*TSchema)(unsafe.Pointer((*TDb)(unsafe.Pointer(pDb)).FpSchema)).Fcache_size)
	}
	/*
	 ** file_format==1    Version 3.0.0.
	 ** file_format==2    Version 3.1.3.  // ALTER TABLE ADD COLUMN
	 ** file_format==3    Version 3.1.4.  // ditto but with non-NULL defaults
	 ** file_format==4    Version 3.3.0.  // DESC indices.  Boolean constants
	 */
	(*TSchema)(unsafe.Pointer((*TDb)(unsafe.Pointer(pDb)).FpSchema)).Ffile_format = libc.Uint8FromInt32((**(**[5]int32)(__ccgo_up(bp + 48)))[libc.Int32FromInt32(BTREE_FILE_FORMAT)-libc.Int32FromInt32(1)])
	if libc.Int32FromUint8((*TSchema)(unsafe.Pointer((*TDb)(unsafe.Pointer(pDb)).FpSchema)).Ffile_format) == 0 {
		(*TSchema)(unsafe.Pointer((*TDb)(unsafe.Pointer(pDb)).FpSchema)).Ffile_format = uint8(1)
	}
	if libc.Int32FromUint8((*TSchema)(unsafe.Pointer((*TDb)(unsafe.Pointer(pDb)).FpSchema)).Ffile_format) > int32(SQLITE_MAX_FILE_FORMAT) {
		_sqlite3SetString(tls, pzErrMsg, db, __ccgo_ts+20170)
		rc = int32(SQLITE_ERROR)
		goto initone_error_out
	}
	/* Ticket #2804:  When we open a database in the newer file format,
	 ** clear the legacy_file_format pragma flag so that a VACUUM will
	 ** not downgrade the database and thus invalidate any descending
	 ** indices that the user might have created.
	 */
	if iDb == 0 && (**(**[5]int32)(__ccgo_up(bp + 48)))[libc.Int32FromInt32(BTREE_FILE_FORMAT)-libc.Int32FromInt32(1)] >= int32(4) {
		**(**Tu64)(__ccgo_up(db + 48)) &= ^libc.Uint64FromInt32(SQLITE_LegacyFileFmt)
	}
	/* Read the schema information out of the schema tables
	 */
	(**(**TInitData)(__ccgo_up(bp + 72))).FmxPage = _sqlite3BtreeLastPage(tls, (*TDb)(unsafe.Pointer(pDb)).FpBt)
	zSql = _sqlite3MPrintf(tls, db, __ccgo_ts+20194, libc.VaList(bp+120, (**(**TDb)(__ccgo_up((*Tsqlite3)(unsafe.Pointer(db)).FaDb + uintptr(iDb)*32))).FzDbSName, zSchemaTabName))
	xAuth = (*Tsqlite3)(unsafe.Pointer(db)).FxAuth
	(*Tsqlite3)(unsafe.Pointer(db)).FxAuth = uintptr(0)
	rc = Xsqlite3_exec(tls, db, zSql, __ccgo_fp(_sqlite3InitCallback), bp+72, uintptr(0))
	(*Tsqlite3)(unsafe.Pointer(db)).FxAuth = xAuth
	if rc == SQLITE_OK {
		rc = (**(**TInitData)(__ccgo_up(bp + 72))).Frc
	}
	_sqlite3DbFree(tls, db, zSql)
	if rc == SQLITE_OK {
		_sqlite3AnalysisLoad(tls, db, iDb)
	}
	if (*Tsqlite3)(unsafe.Pointer(db)).FmallocFailed != 0 {
		rc = int32(SQLITE_NOMEM)
		_sqlite3ResetAllSchemasOfConnection(tls, db)
		pDb = (*Tsqlite3)(unsafe.Pointer(db)).FaDb + uintptr(iDb)*32
	} else {
		if rc == SQLITE_OK || (*Tsqlite3)(unsafe.Pointer(db)).Fflags&uint64(SQLITE_NoSchemaError) != 0 && rc != int32(SQLITE_NOMEM) {
			/* Hack: If the SQLITE_NoSchemaError flag is set, then consider
			 ** the schema loaded, even if errors (other than OOM) occurred. In
			 ** this situation the current sqlite3_prepare() operation will fail,
			 ** but the following one will attempt to compile the supplied statement
			 ** against whatever subset of the schema was loaded before the error
			 ** occurred.
			 **
			 ** The primary purpose of this is to allow access to the sqlite_schema
			 ** table even when its contents have been corrupted.
			 */
			v1 = (**(**TDb)(__ccgo_up((*Tsqlite3)(unsafe.Pointer(db)).FaDb + uintptr(iDb)*32))).FpSchema + 114
			*(*Tu16)(unsafe.Pointer(v1)) = Tu16(int32(*(*Tu16)(unsafe.Pointer(v1))) | libc.Int32FromInt32(DB_SchemaLoaded))
			rc = SQLITE_OK
		}
	}
	/* Jump here for an error that occurs after successfully allocating
	 ** curMain and calling sqlite3BtreeEnter(). For an error that occurs
	 ** before that point, jump to error_out.
	 */
	goto initone_error_out
initone_error_out:
	;
	if openedTransaction != 0 {
		_sqlite3BtreeCommit(tls, (*TDb)(unsafe.Pointer(pDb)).FpBt)
	}
	_sqlite3BtreeLeave(tls, (*TDb)(unsafe.Pointer(pDb)).FpBt)
	goto error_out
error_out:
	;
	if rc != 0 {
		if rc == int32(SQLITE_NOMEM) || rc == libc.Int32FromInt32(SQLITE_IOERR)|libc.Int32FromInt32(12)<<libc.Int32FromInt32(8) {
			_sqlite3OomFault(tls, db)
		}
		_sqlite3ResetOneSchema(tls, db, iDb)
	}
	(*Tsqlite3)(unsafe.Pointer(db)).Finit1.Fbusy = uint8(0)
	return rc
}

// C documentation
//
//	/*
//	** This routine is called to handle SQL of the following forms:
//	**
//	**    insert into TABLE (IDLIST) values(EXPRLIST),(EXPRLIST),...
//	**    insert into TABLE (IDLIST) select
//	**    insert into TABLE (IDLIST) default values
//	**
//	** The IDLIST following the table name is always optional.  If omitted,
//	** then a list of all (non-hidden) columns for the table is substituted.
//	** The IDLIST appears in the pColumn parameter.  pColumn is NULL if IDLIST
//	** is omitted.
//	**
//	** For the pSelect parameter holds the values to be inserted for the
//	** first two forms shown above.  A VALUES clause is really just short-hand
//	** for a SELECT statement that omits the FROM clause and everything else
//	** that follows.  If the pSelect parameter is NULL, that means that the
//	** DEFAULT VALUES form of the INSERT statement is intended.
//	**
//	** The code generated follows one of four templates.  For a simple
//	** insert with data coming from a single-row VALUES clause, the code executes
//	** once straight down through.  Pseudo-code follows (we call this
//	** the "1st template"):
//	**
//	**         open write cursor to <table> and its indices
//	**         put VALUES clause expressions into registers
//	**         write the resulting record into <table>
//	**         cleanup
//	**
//	** The three remaining templates assume the statement is of the form
//	**
//	**   INSERT INTO <table> SELECT ...
//	**
//	** If the SELECT clause is of the restricted form "SELECT * FROM <table2>" -
//	** in other words if the SELECT pulls all columns from a single table
//	** and there is no WHERE or LIMIT or GROUP BY or ORDER BY clauses, and
//	** if <table2> and <table1> are distinct tables but have identical
//	** schemas, including all the same indices, then a special optimization
//	** is invoked that copies raw records from <table2> over to <table1>.
//	** See the xferOptimization() function for the implementation of this
//	** template.  This is the 2nd template.
//	**
//	**         open a write cursor to <table>
//	**         open read cursor on <table2>
//	**         transfer all records in <table2> over to <table>
//	**         close cursors
//	**         foreach index on <table>
//	**           open a write cursor on the <table> index
//	**           open a read cursor on the corresponding <table2> index
//	**           transfer all records from the read to the write cursors
//	**           close cursors
//	**         end foreach
//	**
//	** The 3rd template is for when the second template does not apply
//	** and the SELECT clause does not read from <table> at any time.
//	** The generated code follows this template:
//	**
//	**         X <- A
//	**         goto B
//	**      A: setup for the SELECT
//	**         loop over the rows in the SELECT
//	**           load values into registers R..R+n
//	**           yield X
//	**         end loop
//	**         cleanup after the SELECT
//	**         end-coroutine X
//	**      B: open write cursor to <table> and its indices
//	**      C: yield X, at EOF goto D
//	**         insert the select result into <table> from R..R+n
//	**         goto C
//	**      D: cleanup
//	**
//	** The 4th template is used if the insert statement takes its
//	** values from a SELECT but the data is being inserted into a table
//	** that is also read as part of the SELECT.  In the third form,
//	** we have to use an intermediate table to store the results of
//	** the select.  The template is like this:
//	**
//	**         X <- A
//	**         goto B
//	**      A: setup for the SELECT
//	**         loop over the tables in the SELECT
//	**           load value into register R..R+n
//	**           yield X
//	**         end loop
//	**         cleanup after the SELECT
//	**         end co-routine R
//	**      B: open temp table
//	**      L: yield X, at EOF goto M
//	**         insert row from R..R+n into temp table
//	**         goto L
//	**      M: open write cursor to <table> and its indices
//	**         rewind temp table
//	**      C: loop over rows of intermediate table
//	**           transfer values form intermediate table into <table>
//	**         end loop
//	**      D: cleanup
//	*/
func _sqlite3Insert(tls *libc.TLS, pParse uintptr, pTabList uintptr, pSelect uintptr, pColumn uintptr, onError int32, pUpsert uintptr) {
	bp := tls.Alloc(160)
	defer tls.Free(160)
	var aRegIdx, aTabColMap, db, pIdx, pIpk, pItem, pList, pNx, pSubq, pTab, pTrigger, pVTab, pX, v, v5 uintptr
	var addr1, addr11, addrCont, addrInsTop, addrL, addrTop, bUseSeek, endOfLoop, i, iDb, iRegStore, ipkColumn, isView, j, k, nColumn, nHidden, nIdx, rc, regAutoinc, regCols, regData, regFromSelect, regIns, regRec, regRowCount, regRowid, regTempRowid, regYield, srcTab, y, v1 int32
	var appendFlag, bIdListInOrder, useTempTable, withoutRowid Tu8
	var colFlags, v20 Tu32
	var _ /* dest at bp+8 */ TSelectDest
	var _ /* iDataCur at bp+0 */ int32
	var _ /* iIdxCur at bp+4 */ int32
	var _ /* isReplace at bp+112 */ int32
	var _ /* sNC at bp+56 */ TNameContext
	var _ /* tmask at bp+48 */ int32
	_, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _ = aRegIdx, aTabColMap, addr1, addr11, addrCont, addrInsTop, addrL, addrTop, appendFlag, bIdListInOrder, bUseSeek, colFlags, db, endOfLoop, i, iDb, iRegStore, ipkColumn, isView, j, k, nColumn, nHidden, nIdx, pIdx, pIpk, pItem, pList, pNx, pSubq, pTab, pTrigger, pVTab, pX, rc, regAutoinc, regCols, regData, regFromSelect, regIns, regRec, regRowCount, regRowid, regTempRowid, regYield, srcTab, useTempTable, v, withoutRowid, y, v1, v20, v5 /* Number of columns in the data */
	nHidden = 0                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                         /* Number of hidden columns if TABLE is virtual */
	**(**int32)(__ccgo_up(bp)) = 0                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                      /* VDBE cursor that is the main data repository */
	**(**int32)(__ccgo_up(bp + 4)) = 0                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                  /* First index cursor */
	ipkColumn = -int32(1)                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                               /* Label for the end of the insertion loop */
	srcTab = 0                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                          /* Data comes from this temporary cursor if >=0 */
	addrInsTop = 0                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                      /* Jump to label "D" */
	addrCont = 0                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                        /* Index of database holding TABLE */
	useTempTable = uint8(0)                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                             /* Store SELECT results in intermediate table */
	appendFlag = uint8(0)                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                               /* True if IDLIST is in table order */
	pList = uintptr(0)                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                  /* Register in which to store next column */
	/* Register allocations */
	regFromSelect = 0       /* Base register for data coming from SELECT */
	regAutoinc = 0          /* Register holding the AUTOINCREMENT counter */
	regRowCount = 0         /* register holding first column to insert */
	aRegIdx = uintptr(0)    /* One register allocated to each index */
	aTabColMap = uintptr(0) /* Mask of trigger times */
	db = (*TParse)(unsafe.Pointer(pParse)).Fdb
	if (*TParse)(unsafe.Pointer(pParse)).FnErr != 0 {
		goto insert_cleanup
	}
	(**(**TSelectDest)(__ccgo_up(bp + 8))).FiSDParm = 0 /* Suppress a harmless compiler warning */
	/* If the Select object is really just a simple VALUES() list with a
	 ** single row (the common case) then keep that one row of values
	 ** and discard the other (unused) parts of the pSelect object
	 */
	if pSelect != 0 && (*TSelect)(unsafe.Pointer(pSelect)).FselFlags&uint32(SF_Values) != uint32(0) && (*TSelect)(unsafe.Pointer(pSelect)).FpPrior == uintptr(0) {
		pList = (*TSelect)(unsafe.Pointer(pSelect)).FpEList
		(*TSelect)(unsafe.Pointer(pSelect)).FpEList = uintptr(0)
		_sqlite3SelectDelete(tls, db, pSelect)
		pSelect = uintptr(0)
	}
	/* Locate the table into which we will be inserting new information.
	 */
	pTab = _sqlite3SrcListLookup(tls, pParse, pTabList)
	if pTab == uintptr(0) {
		goto insert_cleanup
	}
	iDb = _sqlite3SchemaToIndex(tls, db, (*TTable)(unsafe.Pointer(pTab)).FpSchema)
	if _sqlite3AuthCheck(tls, pParse, int32(SQLITE_INSERT), (*TTable)(unsafe.Pointer(pTab)).FzName, uintptr(0), (**(**TDb)(__ccgo_up((*Tsqlite3)(unsafe.Pointer(db)).FaDb + uintptr(iDb)*32))).FzDbSName) != 0 {
		goto insert_cleanup
	}
	withoutRowid = libc.BoolUint8(!((*TTable)(unsafe.Pointer(pTab)).FtabFlags&libc.Uint32FromInt32(TF_WithoutRowid) == libc.Uint32FromInt32(0)))
	/* Figure out if we have any triggers and if the table being
	 ** inserted into is a view
	 */
	pTrigger = _sqlite3TriggersExist(tls, pParse, pTab, int32(TK_INSERT), uintptr(0), bp+48)
	isView = libc.BoolInt32(libc.Int32FromUint8((*TTable)(unsafe.Pointer(pTab)).FeTabType) == int32(TABTYP_VIEW))
	/* If pTab is really a view, make sure it has been initialized.
	 ** ViewGetColumnNames() is a no-op if pTab is not a view.
	 */
	if _sqlite3ViewGetColumnNames(tls, pParse, pTab) != 0 {
		goto insert_cleanup
	}
	/* Cannot insert into a read-only table.
	 */
	if _sqlite3IsReadOnly(tls, pParse, pTab, pTrigger) != 0 {
		goto insert_cleanup
	}
	/* Allocate a VDBE
	 */
	v = _sqlite3GetVdbe(tls, pParse)
	if v == uintptr(0) {
		goto insert_cleanup
	}
	if libc.Int32FromUint8((*TParse)(unsafe.Pointer(pParse)).Fnested) == 0 {
		_sqlite3VdbeCountChanges(tls, v)
	}
	_sqlite3BeginWriteOperation(tls, pParse, libc.BoolInt32(pSelect != 0 || pTrigger != 0), iDb)
	/* If the statement is of the form
	 **
	 **       INSERT INTO <table1> SELECT * FROM <table2>;
	 **
	 ** Then special optimizations can be applied that make the transfer
	 ** very fast and which reduce fragmentation of indices.
	 **
	 ** This is the 2nd template.
	 */
	if pColumn == uintptr(0) && pSelect != uintptr(0) && pTrigger == uintptr(0) && _xferOptimization(tls, pParse, pTab, pSelect, onError, iDb) != 0 {
		goto insert_end
	}
	/* If this is an AUTOINCREMENT table, look up the sequence number in the
	 ** sqlite_sequence table and store it in memory cell regAutoinc.
	 */
	regAutoinc = _autoIncBegin(tls, pParse, iDb, pTab)
	/* Allocate a block registers to hold the rowid and the values
	 ** for all columns of the new row.
	 */
	v1 = (*TParse)(unsafe.Pointer(pParse)).FnMem + libc.Int32FromInt32(1)
	regIns = v1
	regRowid = v1
	**(**int32)(__ccgo_up(pParse + 60)) += int32((*TTable)(unsafe.Pointer(pTab)).FnCol) + int32(1)
	if libc.Int32FromUint8((*TTable)(unsafe.Pointer(pTab)).FeTabType) == int32(TABTYP_VTAB) {
		regRowid = regRowid + 1
		(*TParse)(unsafe.Pointer(pParse)).FnMem = (*TParse)(unsafe.Pointer(pParse)).FnMem + 1
	}
	regData = regRowid + int32(1)
	/* If the INSERT statement included an IDLIST term, then make sure
	 ** all elements of the IDLIST really are columns of the table and
	 ** remember the column indices.
	 **
	 ** If the table has an INTEGER PRIMARY KEY column and that column
	 ** is named in the IDLIST, then record in the ipkColumn variable
	 ** the index into IDLIST of the primary key column.  ipkColumn is
	 ** the index of the primary key as it appears in IDLIST, not as
	 ** is appears in the original table.  (The index of the INTEGER
	 ** PRIMARY KEY in the original table is pTab->iPKey.)  After this
	 ** loop, if ipkColumn==(-1), that means that integer primary key
	 ** is unspecified, and hence the table is either WITHOUT ROWID or
	 ** it will automatically generated an integer primary key.
	 **
	 ** bIdListInOrder is true if the columns in IDLIST are in storage
	 ** order.  This enables an optimization that avoids shuffling the
	 ** columns into storage order.  False negatives are harmless,
	 ** but false positives will cause database corruption.
	 */
	bIdListInOrder = libc.BoolUint8((*TTable)(unsafe.Pointer(pTab)).FtabFlags&libc.Uint32FromInt32(libc.Int32FromInt32(TF_OOOHidden)|libc.Int32FromInt32(TF_HasStored)) == uint32(0))
	if pColumn != 0 {
		aTabColMap = _sqlite3DbMallocZero(tls, db, uint64(libc.Uint64FromInt16((*TTable)(unsafe.Pointer(pTab)).FnCol)*uint64(4)))
		if aTabColMap == uintptr(0) {
			goto insert_cleanup
		}
		i = 0
		for {
			if !(i < (*TIdList)(unsafe.Pointer(pColumn)).FnId) {
				break
			}
			j = _sqlite3ColumnIndex(tls, pTab, (*(*TIdList_item)(unsafe.Pointer(pColumn + 8 + uintptr(i)*8))).FzName)
			if j >= 0 {
				if **(**int32)(__ccgo_up(aTabColMap + uintptr(j)*4)) == 0 {
					**(**int32)(__ccgo_up(aTabColMap + uintptr(j)*4)) = i + int32(1)
				}
				if i != j {
					bIdListInOrder = uint8(0)
				}
				if j == int32((*TTable)(unsafe.Pointer(pTab)).FiPKey) {
					ipkColumn = i
				}
				if libc.Int32FromUint16((**(**TColumn)(__ccgo_up((*TTable)(unsafe.Pointer(pTab)).FaCol + uintptr(j)*16))).FcolFlags)&(libc.Int32FromInt32(COLFLAG_STORED)|libc.Int32FromInt32(COLFLAG_VIRTUAL)) != 0 {
					_sqlite3ErrorMsg(tls, pParse, __ccgo_ts+17338, libc.VaList(bp+128, (**(**TColumn)(__ccgo_up((*TTable)(unsafe.Pointer(pTab)).FaCol + uintptr(j)*16))).FzCnName))
					goto insert_cleanup
				}
			} else {
				if _sqlite3IsRowid(tls, (*(*TIdList_item)(unsafe.Pointer(pColumn + 8 + uintptr(i)*8))).FzName) != 0 && !(withoutRowid != 0) {
					ipkColumn = i
					bIdListInOrder = uint8(0)
				} else {
					_sqlite3ErrorMsg(tls, pParse, __ccgo_ts+17379, libc.VaList(bp+128, pTabList+8, (*(*TIdList_item)(unsafe.Pointer(pColumn + 8 + uintptr(i)*8))).FzName))
					libc.SetBitFieldPtr16Uint32(pParse+40, libc.Uint32FromInt32(1), 8, 0x100)
					goto insert_cleanup
				}
			}
			goto _2
		_2:
			;
			i = i + 1
		}
	}
	/* Figure out how many columns of data are supplied.  If the data
	 ** is coming from a SELECT statement, then generate a co-routine that
	 ** produces a single row of the SELECT on each invocation.  The
	 ** co-routine is the common header to the 3rd and 4th templates.
	 */
	if pSelect != 0 { /* Result code */
		if (*TSrcList)(unsafe.Pointer((*TSelect)(unsafe.Pointer(pSelect)).FpSrc)).FnSrc == int32(1) && int32(*(*uint32)(unsafe.Pointer((*TSelect)(unsafe.Pointer(pSelect)).FpSrc + 8 + 24 + 4))&0x40>>6) != 0 && (*TSelect)(unsafe.Pointer(pSelect)).FpPrior == uintptr(0) {
			pItem = (*TSelect)(unsafe.Pointer(pSelect)).FpSrc + 8
			pSubq = *(*uintptr)(unsafe.Pointer(pItem + 72))
			(**(**TSelectDest)(__ccgo_up(bp + 8))).FiSDParm = (*TSubquery)(unsafe.Pointer(pSubq)).FregReturn
			regFromSelect = (*TSubquery)(unsafe.Pointer(pSubq)).FregResult
			nColumn = (*TExprList)(unsafe.Pointer((*TSelect)(unsafe.Pointer((*TSubquery)(unsafe.Pointer(pSubq)).FpSelect)).FpEList)).FnExpr
			_sqlite3VdbeExplain(tls, pParse, uint8(0), __ccgo_ts+17411, libc.VaList(bp+128, pItem))
			if bIdListInOrder != 0 && nColumn == int32((*TTable)(unsafe.Pointer(pTab)).FnCol) {
				regData = regFromSelect
				regRowid = regData - int32(1)
				if libc.Int32FromUint8((*TTable)(unsafe.Pointer(pTab)).FeTabType) == int32(TABTYP_VTAB) {
					v1 = int32(1)
				} else {
					v1 = 0
				}
				regIns = regRowid - v1
			}
		} else {
			v5 = pParse + 60
			*(*int32)(unsafe.Pointer(v5)) = *(*int32)(unsafe.Pointer(v5)) + 1
			v1 = *(*int32)(unsafe.Pointer(v5)) /* Top of the co-routine */
			regYield = v1
			addrTop = _sqlite3VdbeCurrentAddr(tls, v) + int32(1)
			_sqlite3VdbeAddOp3(tls, v, int32(OP_InitCoroutine), regYield, 0, addrTop)
			_sqlite3SelectDestInit(tls, bp+8, int32(SRT_Coroutine), regYield)
			if bIdListInOrder != 0 {
				v1 = regData
			} else {
				v1 = 0
			}
			(**(**TSelectDest)(__ccgo_up(bp + 8))).FiSdst = v1
			(**(**TSelectDest)(__ccgo_up(bp + 8))).FnSdst = int32((*TTable)(unsafe.Pointer(pTab)).FnCol)
			rc = _sqlite3Select(tls, pParse, pSelect, bp+8)
			regFromSelect = (**(**TSelectDest)(__ccgo_up(bp + 8))).FiSdst
			if rc != 0 || (*TParse)(unsafe.Pointer(pParse)).FnErr != 0 {
				goto insert_cleanup
			}
			_sqlite3VdbeEndCoroutine(tls, v, regYield)
			_sqlite3VdbeJumpHere(tls, v, addrTop-int32(1)) /* label B: */
			nColumn = (*TExprList)(unsafe.Pointer((*TSelect)(unsafe.Pointer(pSelect)).FpEList)).FnExpr
		}
		/* Set useTempTable to TRUE if the result of the SELECT statement
		 ** should be written into a temporary table (template 4).  Set to
		 ** FALSE if each output row of the SELECT can be written directly into
		 ** the destination table (template 3).
		 **
		 ** A temp table must be used if the table being updated is also one
		 ** of the tables being read by the SELECT statement.  Also use a
		 ** temp table in the case of row triggers.
		 */
		if pTrigger != 0 || _readsTable(tls, pParse, iDb, pTab) != 0 {
			useTempTable = uint8(1)
		}
		if useTempTable != 0 { /* Label "L" */
			v5 = pParse + 56
			v1 = *(*int32)(unsafe.Pointer(v5))
			*(*int32)(unsafe.Pointer(v5)) = *(*int32)(unsafe.Pointer(v5)) + 1
			srcTab = v1
			regRec = _sqlite3GetTempReg(tls, pParse)
			regTempRowid = _sqlite3GetTempReg(tls, pParse)
			_sqlite3VdbeAddOp2(tls, v, int32(OP_OpenEphemeral), srcTab, nColumn)
			addrL = _sqlite3VdbeAddOp1(tls, v, int32(OP_Yield), (**(**TSelectDest)(__ccgo_up(bp + 8))).FiSDParm)
			_sqlite3VdbeAddOp3(tls, v, int32(OP_MakeRecord), regFromSelect, nColumn, regRec)
			_sqlite3VdbeAddOp2(tls, v, int32(OP_NewRowid), srcTab, regTempRowid)
			_sqlite3VdbeAddOp3(tls, v, int32(OP_Insert), srcTab, regRec, regTempRowid)
			_sqlite3VdbeGoto(tls, v, addrL)
			_sqlite3VdbeJumpHere(tls, v, addrL)
			_sqlite3ReleaseTempReg(tls, pParse, regRec)
			_sqlite3ReleaseTempReg(tls, pParse, regTempRowid)
		}
	} else {
		libc.Xmemset(tls, bp+56, 0, uint64(56))
		(**(**TNameContext)(__ccgo_up(bp + 56))).FpParse = pParse
		srcTab = -int32(1)
		if pList != 0 {
			nColumn = (*TExprList)(unsafe.Pointer(pList)).FnExpr
			if _sqlite3ResolveExprListNames(tls, bp+56, pList) != 0 {
				goto insert_cleanup
			}
		} else {
			nColumn = 0
		}
	}
	/* If there is no IDLIST term but the table has an integer primary
	 ** key, the set the ipkColumn variable to the integer primary key
	 ** column index in the original table definition.
	 */
	if pColumn == uintptr(0) && nColumn > 0 {
		ipkColumn = int32((*TTable)(unsafe.Pointer(pTab)).FiPKey)
		if ipkColumn >= 0 && (*TTable)(unsafe.Pointer(pTab)).FtabFlags&uint32(TF_HasGenerated) != uint32(0) {
			i = ipkColumn - int32(1)
			for {
				if !(i >= 0) {
					break
				}
				if libc.Int32FromUint16((**(**TColumn)(__ccgo_up((*TTable)(unsafe.Pointer(pTab)).FaCol + uintptr(i)*16))).FcolFlags)&int32(COLFLAG_GENERATED) != 0 {
					ipkColumn = ipkColumn - 1
				}
				goto _9
			_9:
				;
				i = i - 1
			}
		}
		/* Make sure the number of columns in the source data matches the number
		 ** of columns to be inserted into the table.
		 */
		if (*TTable)(unsafe.Pointer(pTab)).FtabFlags&libc.Uint32FromInt32(libc.Int32FromInt32(TF_HasGenerated)|libc.Int32FromInt32(TF_HasHidden)) != uint32(0) {
			i = 0
			for {
				if !(i < int32((*TTable)(unsafe.Pointer(pTab)).FnCol)) {
					break
				}
				if libc.Int32FromUint16((**(**TColumn)(__ccgo_up((*TTable)(unsafe.Pointer(pTab)).FaCol + uintptr(i)*16))).FcolFlags)&int32(COLFLAG_NOINSERT) != 0 {
					nHidden = nHidden + 1
				}
				goto _10
			_10:
				;
				i = i + 1
			}
		}
		if nColumn != int32((*TTable)(unsafe.Pointer(pTab)).FnCol)-nHidden {
			_sqlite3ErrorMsg(tls, pParse, __ccgo_ts+17419, libc.VaList(bp+128, pTabList+8, int32((*TTable)(unsafe.Pointer(pTab)).FnCol)-nHidden, nColumn))
			goto insert_cleanup
		}
	}
	if pColumn != uintptr(0) && nColumn != (*TIdList)(unsafe.Pointer(pColumn)).FnId {
		_sqlite3ErrorMsg(tls, pParse, __ccgo_ts+17471, libc.VaList(bp+128, nColumn, (*TIdList)(unsafe.Pointer(pColumn)).FnId))
		goto insert_cleanup
	}
	/* Initialize the count of rows to be inserted
	 */
	if (*Tsqlite3)(unsafe.Pointer(db)).Fflags&(libc.Uint64FromInt32(libc.Int32FromInt32(0x00001))<<libc.Int32FromInt32(32)) != uint64(0) && !((*TParse)(unsafe.Pointer(pParse)).Fnested != 0) && !((*TParse)(unsafe.Pointer(pParse)).FpTriggerTab != 0) && !(int32(Tbft(*(*uint16)(unsafe.Pointer(pParse + 40))&0x8>>3)) != 0) {
		v5 = pParse + 60
		*(*int32)(unsafe.Pointer(v5)) = *(*int32)(unsafe.Pointer(v5)) + 1
		v1 = *(*int32)(unsafe.Pointer(v5))
		regRowCount = v1
		_sqlite3VdbeAddOp2(tls, v, int32(OP_Integer), 0, regRowCount)
	}
	/* If this is not a view, open the table and and all indices */
	if !(isView != 0) {
		nIdx = _sqlite3OpenTableAndIndices(tls, pParse, pTab, int32(OP_OpenWrite), uint8(0), -int32(1), uintptr(0), bp, bp+4)
		aRegIdx = _sqlite3DbMallocRawNN(tls, db, uint64(uint64(4)*libc.Uint64FromInt32(nIdx+libc.Int32FromInt32(2))))
		if aRegIdx == uintptr(0) {
			goto insert_cleanup
		}
		i = 0
		pIdx = (*TTable)(unsafe.Pointer(pTab)).FpIndex
		for {
			if !(i < nIdx) {
				break
			}
			v5 = pParse + 60
			*(*int32)(unsafe.Pointer(v5)) = *(*int32)(unsafe.Pointer(v5)) + 1
			v1 = *(*int32)(unsafe.Pointer(v5))
			**(**int32)(__ccgo_up(aRegIdx + uintptr(i)*4)) = v1
			**(**int32)(__ccgo_up(pParse + 60)) += libc.Int32FromUint16((*TIndex)(unsafe.Pointer(pIdx)).FnColumn)
			goto _13
		_13:
			;
			pIdx = (*TIndex)(unsafe.Pointer(pIdx)).FpNext
			i = i + 1
		}
		v5 = pParse + 60
		*(*int32)(unsafe.Pointer(v5)) = *(*int32)(unsafe.Pointer(v5)) + 1
		v1 = *(*int32)(unsafe.Pointer(v5))
		**(**int32)(__ccgo_up(aRegIdx + uintptr(i)*4)) = v1 /* Register to store the table record */
	}
	if pUpsert != 0 {
		if libc.Int32FromUint8((*TTable)(unsafe.Pointer(pTab)).FeTabType) == int32(TABTYP_VTAB) {
			_sqlite3ErrorMsg(tls, pParse, __ccgo_ts+17496, libc.VaList(bp+128, (*TTable)(unsafe.Pointer(pTab)).FzName))
			goto insert_cleanup
		}
		if libc.Int32FromUint8((*TTable)(unsafe.Pointer(pTab)).FeTabType) == int32(TABTYP_VIEW) {
			_sqlite3ErrorMsg(tls, pParse, __ccgo_ts+17542, 0)
			goto insert_cleanup
		}
		if _sqlite3HasExplicitNulls(tls, pParse, (*TUpsert)(unsafe.Pointer(pUpsert)).FpUpsertTarget) != 0 {
			goto insert_cleanup
		}
		(*(*TSrcItem)(unsafe.Pointer(pTabList + 8))).FiCursor = **(**int32)(__ccgo_up(bp))
		pNx = pUpsert
		for cond := true; cond; cond = pNx != uintptr(0) {
			(*TUpsert)(unsafe.Pointer(pNx)).FpUpsertSrc = pTabList
			(*TUpsert)(unsafe.Pointer(pNx)).FregData = regData
			(*TUpsert)(unsafe.Pointer(pNx)).FiDataCur = **(**int32)(__ccgo_up(bp))
			(*TUpsert)(unsafe.Pointer(pNx)).FiIdxCur = **(**int32)(__ccgo_up(bp + 4))
			if (*TUpsert)(unsafe.Pointer(pNx)).FpUpsertTarget != 0 {
				if _sqlite3UpsertAnalyzeTarget(tls, pParse, pTabList, pNx, pUpsert) != 0 {
					goto insert_cleanup
				}
			}
			pNx = (*TUpsert)(unsafe.Pointer(pNx)).FpNextUpsert
		}
	}
	/* This is the top of the main insertion loop */
	if useTempTable != 0 {
		/* This block codes the top of loop only.  The complete loop is the
		 ** following pseudocode (template 4):
		 **
		 **         rewind temp table, if empty goto D
		 **      C: loop over rows of intermediate table
		 **           transfer values form intermediate table into <table>
		 **         end loop
		 **      D: ...
		 */
		addrInsTop = _sqlite3VdbeAddOp1(tls, v, int32(OP_Rewind), srcTab)
		addrCont = _sqlite3VdbeCurrentAddr(tls, v)
	} else {
		if pSelect != 0 {
			/* This block codes the top of loop only.  The complete loop is the
			 ** following pseudocode (template 3):
			 **
			 **      C: yield X, at EOF goto D
			 **         insert the select result into <table> from R..R+n
			 **         goto C
			 **      D: ...
			 */
			v1 = _sqlite3VdbeAddOp1(tls, v, int32(OP_Yield), (**(**TSelectDest)(__ccgo_up(bp + 8))).FiSDParm)
			addrCont = v1
			addrInsTop = v1
			if ipkColumn >= 0 {
				/* tag-20191021-001: If the INTEGER PRIMARY KEY is being generated by the
				 ** SELECT, go ahead and copy the value into the rowid slot now, so that
				 ** the value does not get overwritten by a NULL at tag-20191021-002. */
				_sqlite3VdbeAddOp2(tls, v, int32(OP_Copy), regFromSelect+ipkColumn, regRowid)
			}
		}
	}
	/* Compute data for ordinary columns of the new entry.  Values
	 ** are written in storage order into registers starting with regData.
	 ** Only ordinary columns are computed in this loop. The rowid
	 ** (if there is one) is computed later and generated columns are
	 ** computed after the rowid since they might depend on the value
	 ** of the rowid.
	 */
	nHidden = 0
	iRegStore = regData
	i = 0
	for {
		if !(i < int32((*TTable)(unsafe.Pointer(pTab)).FnCol)) {
			break
		}
		if i == int32((*TTable)(unsafe.Pointer(pTab)).FiPKey) {
			/* tag-20191021-002: References to the INTEGER PRIMARY KEY are filled
			 ** using the rowid. So put a NULL in the IPK slot of the record to avoid
			 ** using excess space.  The file format definition requires this extra
			 ** NULL - we cannot optimize further by skipping the column completely */
			_sqlite3VdbeAddOp1(tls, v, int32(OP_SoftNull), iRegStore)
			goto _19
		}
		v20 = uint32((**(**TColumn)(__ccgo_up((*TTable)(unsafe.Pointer(pTab)).FaCol + uintptr(i)*16))).FcolFlags)
		colFlags = v20
		if v20&uint32(COLFLAG_NOINSERT) != uint32(0) {
			nHidden = nHidden + 1
			if colFlags&uint32(COLFLAG_VIRTUAL) != uint32(0) {
				/* Virtual columns do not participate in OP_MakeRecord.  So back up
				 ** iRegStore by one slot to compensate for the iRegStore++ in the
				 ** outer for() loop */
				iRegStore = iRegStore - 1
				goto _19
			} else {
				if colFlags&uint32(COLFLAG_STORED) != uint32(0) {
					/* Stored columns are computed later.  But if there are BEFORE
					 ** triggers, the slots used for stored columns will be OP_Copy-ed
					 ** to a second block of registers, so the register needs to be
					 ** initialized to NULL to avoid an uninitialized register read */
					if **(**int32)(__ccgo_up(bp + 48))&int32(TRIGGER_BEFORE) != 0 {
						_sqlite3VdbeAddOp1(tls, v, int32(OP_SoftNull), iRegStore)
					}
					goto _19
				} else {
					if pColumn == uintptr(0) {
						/* Hidden columns that are not explicitly named in the INSERT
						 ** get their default value */
						_sqlite3ExprCodeFactorable(tls, pParse, _sqlite3ColumnExpr(tls, pTab, (*TTable)(unsafe.Pointer(pTab)).FaCol+uintptr(i)*16), iRegStore)
						goto _19
					}
				}
			}
		}
		if pColumn != 0 {
			j = **(**int32)(__ccgo_up(aTabColMap + uintptr(i)*4))
			if j == 0 {
				/* A column not named in the insert column list gets its
				 ** default value */
				_sqlite3ExprCodeFactorable(tls, pParse, _sqlite3ColumnExpr(tls, pTab, (*TTable)(unsafe.Pointer(pTab)).FaCol+uintptr(i)*16), iRegStore)
				goto _19
			}
			k = j - int32(1)
		} else {
			if nColumn == 0 {
				/* This is INSERT INTO ... DEFAULT VALUES.  Load the default value. */
				_sqlite3ExprCodeFactorable(tls, pParse, _sqlite3ColumnExpr(tls, pTab, (*TTable)(unsafe.Pointer(pTab)).FaCol+uintptr(i)*16), iRegStore)
				goto _19
			} else {
				k = i - nHidden
			}
		}
		if useTempTable != 0 {
			_sqlite3VdbeAddOp3(tls, v, int32(OP_Column), srcTab, k, iRegStore)
		} else {
			if pSelect != 0 {
				if regFromSelect != regData {
					_sqlite3VdbeAddOp2(tls, v, int32(OP_SCopy), regFromSelect+k, iRegStore)
				}
			} else {
				pX = (*(*TExprList_item)(unsafe.Pointer(pList + 8 + uintptr(k)*32))).FpExpr
				y = _sqlite3ExprCodeTarget(tls, pParse, pX, iRegStore)
				if y != iRegStore {
					if (*TExpr)(unsafe.Pointer(pX)).Fflags&libc.Uint32FromInt32(libc.Int32FromInt32(EP_Subquery)) != uint32(0) {
						v1 = int32(OP_Copy)
					} else {
						v1 = int32(OP_SCopy)
					}
					_sqlite3VdbeAddOp2(tls, v, v1, y, iRegStore)
				}
			}
		}
		goto _19
	_19:
		;
		i = i + 1
		iRegStore = iRegStore + 1
	}
	/* Run the BEFORE and INSTEAD OF triggers, if there are any
	 */
	endOfLoop = _sqlite3VdbeMakeLabel(tls, pParse)
	if **(**int32)(__ccgo_up(bp + 48))&int32(TRIGGER_BEFORE) != 0 {
		regCols = _sqlite3GetTempRange(tls, pParse, int32((*TTable)(unsafe.Pointer(pTab)).FnCol)+int32(1))
		/* build the NEW.* reference row.  Note that if there is an INTEGER
		 ** PRIMARY KEY into which a NULL is being inserted, that NULL will be
		 ** translated into a unique ID for the row.  But on a BEFORE trigger,
		 ** we do not know what the unique ID will be (because the insert has
		 ** not happened yet) so we substitute a rowid of -1
		 */
		if ipkColumn < 0 {
			_sqlite3VdbeAddOp2(tls, v, int32(OP_Integer), -int32(1), regCols)
		} else {
			if useTempTable != 0 {
				_sqlite3VdbeAddOp3(tls, v, int32(OP_Column), srcTab, ipkColumn, regCols)
			} else {
				/* Otherwise useTempTable is true */
				_sqlite3ExprCode(tls, pParse, (*(*TExprList_item)(unsafe.Pointer(pList + 8 + uintptr(ipkColumn)*32))).FpExpr, regCols)
			}
			addr1 = _sqlite3VdbeAddOp1(tls, v, int32(OP_NotNull), regCols)
			_sqlite3VdbeAddOp2(tls, v, int32(OP_Integer), -int32(1), regCols)
			_sqlite3VdbeJumpHere(tls, v, addr1)
			_sqlite3VdbeAddOp1(tls, v, int32(OP_MustBeInt), regCols)
		}
		/* Copy the new data already generated. */
		_sqlite3VdbeAddOp3(tls, v, int32(OP_Copy), regRowid+int32(1), regCols+int32(1), int32((*TTable)(unsafe.Pointer(pTab)).FnNVCol)-int32(1))
		/* Compute the new value for generated columns after all other
		 ** columns have already been computed.  This must be done after
		 ** computing the ROWID in case one of the generated columns
		 ** refers to the ROWID. */
		if (*TTable)(unsafe.Pointer(pTab)).FtabFlags&uint32(TF_HasGenerated) != 0 {
			_sqlite3ComputeGeneratedColumns(tls, pParse, regCols+int32(1), pTab)
		}
		/* If this is an INSERT on a view with an INSTEAD OF INSERT trigger,
		 ** do not attempt any conversions before assembling the record.
		 ** If this is a real table, attempt conversions as required by the
		 ** table column affinities.
		 */
		if !(isView != 0) {
			_sqlite3TableAffinity(tls, v, pTab, regCols+int32(1))
		}
		/* Fire BEFORE or INSTEAD OF triggers */
		_sqlite3CodeRowTrigger(tls, pParse, pTrigger, int32(TK_INSERT), uintptr(0), int32(TRIGGER_BEFORE), pTab, regCols-int32((*TTable)(unsafe.Pointer(pTab)).FnCol)-int32(1), onError, endOfLoop)
		_sqlite3ReleaseTempRange(tls, pParse, regCols, int32((*TTable)(unsafe.Pointer(pTab)).FnCol)+int32(1))
	}
	if !(isView != 0) {
		if libc.Int32FromUint8((*TTable)(unsafe.Pointer(pTab)).FeTabType) == int32(TABTYP_VTAB) {
			/* The row that the VUpdate opcode will delete: none */
			_sqlite3VdbeAddOp2(tls, v, int32(OP_Null), 0, regIns)
		}
		if ipkColumn >= 0 {
			/* Compute the new rowid */
			if useTempTable != 0 {
				_sqlite3VdbeAddOp3(tls, v, int32(OP_Column), srcTab, ipkColumn, regRowid)
			} else {
				if pSelect != 0 {
					/* Rowid already initialized at tag-20191021-001 */
				} else {
					pIpk = (*(*TExprList_item)(unsafe.Pointer(pList + 8 + uintptr(ipkColumn)*32))).FpExpr
					if libc.Int32FromUint8((*TExpr)(unsafe.Pointer(pIpk)).Fop) == int32(TK_NULL) && !(libc.Int32FromUint8((*TTable)(unsafe.Pointer(pTab)).FeTabType) == libc.Int32FromInt32(TABTYP_VTAB)) {
						_sqlite3VdbeAddOp3(tls, v, int32(OP_NewRowid), **(**int32)(__ccgo_up(bp)), regRowid, regAutoinc)
						appendFlag = uint8(1)
					} else {
						_sqlite3ExprCode(tls, pParse, (*(*TExprList_item)(unsafe.Pointer(pList + 8 + uintptr(ipkColumn)*32))).FpExpr, regRowid)
					}
				}
			}
			/* If the PRIMARY KEY expression is NULL, then use OP_NewRowid
			 ** to generate a unique primary key value.
			 */
			if !(appendFlag != 0) {
				if !(libc.Int32FromUint8((*TTable)(unsafe.Pointer(pTab)).FeTabType) == libc.Int32FromInt32(TABTYP_VTAB)) {
					addr11 = _sqlite3VdbeAddOp1(tls, v, int32(OP_NotNull), regRowid)
					_sqlite3VdbeAddOp3(tls, v, int32(OP_NewRowid), **(**int32)(__ccgo_up(bp)), regRowid, regAutoinc)
					_sqlite3VdbeJumpHere(tls, v, addr11)
				} else {
					addr11 = _sqlite3VdbeCurrentAddr(tls, v)
					_sqlite3VdbeAddOp2(tls, v, int32(OP_IsNull), regRowid, addr11+int32(2))
				}
				_sqlite3VdbeAddOp1(tls, v, int32(OP_MustBeInt), regRowid)
			}
		} else {
			if libc.Int32FromUint8((*TTable)(unsafe.Pointer(pTab)).FeTabType) == int32(TABTYP_VTAB) || withoutRowid != 0 {
				_sqlite3VdbeAddOp2(tls, v, int32(OP_Null), 0, regRowid)
			} else {
				_sqlite3VdbeAddOp3(tls, v, int32(OP_NewRowid), **(**int32)(__ccgo_up(bp)), regRowid, regAutoinc)
				appendFlag = uint8(1)
			}
		}
		_autoIncStep(tls, pParse, regAutoinc, regRowid)
		/* Compute the new value for generated columns after all other
		 ** columns have already been computed.  This must be done after
		 ** computing the ROWID in case one of the generated columns
		 ** is derived from the INTEGER PRIMARY KEY. */
		if (*TTable)(unsafe.Pointer(pTab)).FtabFlags&uint32(TF_HasGenerated) != 0 {
			_sqlite3ComputeGeneratedColumns(tls, pParse, regRowid+int32(1), pTab)
		}
		/* Generate code to check constraints and generate index keys and
		 ** do the insertion.
		 */
		if libc.Int32FromUint8((*TTable)(unsafe.Pointer(pTab)).FeTabType) == int32(TABTYP_VTAB) {
			pVTab = _sqlite3GetVTable(tls, db, pTab)
			_sqlite3VtabMakeWritable(tls, pParse, pTab)
			_sqlite3VdbeAddOp4(tls, v, int32(OP_VUpdate), int32(1), int32((*TTable)(unsafe.Pointer(pTab)).FnCol)+int32(2), regIns, pVTab, -int32(12))
			if onError == int32(OE_Default) {
				v1 = int32(OE_Abort)
			} else {
				v1 = onError
			}
			_sqlite3VdbeChangeP5(tls, v, libc.Uint16FromInt32(v1))
			_sqlite3MayAbort(tls, pParse)
		} else {
			**(**int32)(__ccgo_up(bp + 112)) = 0 /* True to use OPFLAG_SEEKRESULT */
			_sqlite3GenerateConstraintChecks(tls, pParse, pTab, aRegIdx, **(**int32)(__ccgo_up(bp)), **(**int32)(__ccgo_up(bp + 4)), regIns, 0, libc.BoolUint8(ipkColumn >= 0), libc.Uint8FromInt32(onError), endOfLoop, bp+112, uintptr(0), pUpsert)
			if (*Tsqlite3)(unsafe.Pointer(db)).Fflags&uint64(SQLITE_ForeignKeys) != 0 {
				_sqlite3FkCheck(tls, pParse, pTab, 0, regIns, uintptr(0), 0)
			}
			/* Set the OPFLAG_USESEEKRESULT flag if either (a) there are no REPLACE
			 ** constraints or (b) there are no triggers and this table is not a
			 ** parent table in a foreign key constraint. It is safe to set the
			 ** flag in the second case as if any REPLACE constraint is hit, an
			 ** OP_Delete or OP_IdxDelete instruction will be executed on each
			 ** cursor that is disturbed. And these instructions both clear the
			 ** VdbeCursor.seekResult variable, disabling the OPFLAG_USESEEKRESULT
			 ** functionality.  */
			bUseSeek = libc.BoolInt32(**(**int32)(__ccgo_up(bp + 112)) == 0 || !(_sqlite3VdbeHasSubProgram(tls, v) != 0))
			_sqlite3CompleteInsertion(tls, pParse, pTab, **(**int32)(__ccgo_up(bp)), **(**int32)(__ccgo_up(bp + 4)), regIns, aRegIdx, 0, libc.Int32FromUint8(appendFlag), bUseSeek)
		}
	}
	/* Update the count of rows that are inserted
	 */
	if regRowCount != 0 {
		_sqlite3VdbeAddOp2(tls, v, int32(OP_AddImm), regRowCount, int32(1))
	}
	if pTrigger != 0 {
		/* Code AFTER triggers */
		_sqlite3CodeRowTrigger(tls, pParse, pTrigger, int32(TK_INSERT), uintptr(0), int32(TRIGGER_AFTER), pTab, regData-int32(2)-int32((*TTable)(unsafe.Pointer(pTab)).FnCol), onError, endOfLoop)
	}
	/* The bottom of the main insertion loop, if the data source
	 ** is a SELECT statement.
	 */
	_sqlite3VdbeResolveLabel(tls, v, endOfLoop)
	if useTempTable != 0 {
		_sqlite3VdbeAddOp2(tls, v, int32(OP_Next), srcTab, addrCont)
		_sqlite3VdbeJumpHere(tls, v, addrInsTop)
		_sqlite3VdbeAddOp1(tls, v, int32(OP_Close), srcTab)
	} else {
		if pSelect != 0 {
			_sqlite3VdbeGoto(tls, v, addrCont)
			_sqlite3VdbeJumpHere(tls, v, addrInsTop)
		}
	}
	goto insert_end
insert_end:
	;
	/* Update the sqlite_sequence table by storing the content of the
	 ** maximum rowid counter values recorded while inserting into
	 ** autoincrement tables.
	 */
	if libc.Int32FromUint8((*TParse)(unsafe.Pointer(pParse)).Fnested) == 0 && (*TParse)(unsafe.Pointer(pParse)).FpTriggerTab == uintptr(0) {
		_sqlite3AutoincrementEnd(tls, pParse)
	}
	/*
	 ** Return the number of rows inserted. If this routine is
	 ** generating code because of a call to sqlite3NestedParse(), do not
	 ** invoke the callback function.
	 */
	if regRowCount != 0 {
		_sqlite3CodeChangeCount(tls, v, regRowCount, __ccgo_ts+17563)
	}
	goto insert_cleanup
insert_cleanup:
	;
	_sqlite3SrcListDelete(tls, db, pTabList)
	_sqlite3ExprListDelete(tls, db, pList)
	_sqlite3UpsertDelete(tls, db, pUpsert)
	_sqlite3SelectDelete(tls, db, pSelect)
	if pColumn != 0 {
		_sqlite3IdListDelete(tls, db, pColumn)
		_sqlite3DbFree(tls, db, aTabColMap)
	}
	if aRegIdx != 0 {
		_sqlite3DbNNFreeNN(tls, db, aRegIdx)
	}
}

/* Make sure "isView" and other macros defined above are undefined. Otherwise
** they may interfere with compilation of other functions in this file
** (or in another file, if this file becomes part of the amalgamation).  */

/*
** Meanings of bits in of pWalker->eCode for
** sqlite3ExprReferencesUpdatedColumn()
 */

// C documentation
//
//	/*
//	** The following is the implementation of an SQL function that always
//	** fails with an error message stating that the function is used in the
//	** wrong context.  The sqlite3_overload_function() API might construct
//	** SQL function that use this routine so that the functions will exist
//	** for name resolution but are actually overloaded by the xFindFunction
//	** method of virtual tables.
//	*/
func _sqlite3InvalidFunction(tls *libc.TLS, context uintptr, NotUsed int32, NotUsed2 uintptr) {
	bp := tls.Alloc(16)
	defer tls.Free(16)
	var zErr, zName uintptr
	_, _ = zErr, zName
	zName = Xsqlite3_user_data(tls, context)
	_ = NotUsed
	_ = NotUsed2
	zErr = Xsqlite3_mprintf(tls, __ccgo_ts+25967, libc.VaList(bp+8, zName))
	Xsqlite3_result_error(tls, context, zErr, -int32(1))
	Xsqlite3_free(tls, zErr)
}

// C documentation
//
//	/*
//	** Check to make sure the given table is writable.
//	**
//	** If pTab is not writable  ->  generate an error message and return 1.
//	** If pTab is writable but other errors have occurred -> return 1.
//	** If pTab is writable and no prior errors -> return 0;
//	*/
func _sqlite3IsReadOnly(tls *libc.TLS, pParse uintptr, pTab uintptr, pTrigger uintptr) (r int32) {
	bp := tls.Alloc(16)
	defer tls.Free(16)
	if _tabIsReadOnly(tls, pParse, pTab) != 0 {
		_sqlite3ErrorMsg(tls, pParse, __ccgo_ts+16371, libc.VaList(bp+8, (*TTable)(unsafe.Pointer(pTab)).FzName))
		return int32(1)
	}
	if libc.Int32FromUint8((*TTable)(unsafe.Pointer(pTab)).FeTabType) == int32(TABTYP_VIEW) && (pTrigger == uintptr(0) || (*TTrigger)(unsafe.Pointer(pTrigger)).FbReturning != 0 && (*TTrigger)(unsafe.Pointer(pTrigger)).FpNext == uintptr(0)) {
		_sqlite3ErrorMsg(tls, pParse, __ccgo_ts+16400, libc.VaList(bp+8, (*TTable)(unsafe.Pointer(pTab)).FzName))
		return int32(1)
	}
	return 0
}

// C documentation
//
//	/*
//	** Return TRUE if the given string is a row-id column name.
//	*/
func _sqlite3IsRowid(tls *libc.TLS, z uintptr) (r int32) {
	if _sqlite3StrICmp(tls, z, __ccgo_ts+8182) == 0 {
		return int32(1)
	}
	if _sqlite3StrICmp(tls, z, __ccgo_ts+8190) == 0 {
		return int32(1)
	}
	if _sqlite3StrICmp(tls, z, __ccgo_ts+8196) == 0 {
		return int32(1)
	}
	return 0
}

// C documentation
//
//	/*
//	** Check the input string to see if it is "true" or "false" (in any case).
//	**
//	**       If the string is....           Return
//	**         "true"                         EP_IsTrue
//	**         "false"                        EP_IsFalse
//	**         anything else                  0
//	*/
func _sqlite3IsTrueOrFalse(tls *libc.TLS, zIn uintptr) (r Tu32) {
	if _sqlite3StrICmp(tls, zIn, __ccgo_ts+8171) == 0 {
		return uint32(EP_IsTrue)
	}
	if _sqlite3StrICmp(tls, zIn, __ccgo_ts+8176) == 0 {
		return uint32(EP_IsFalse)
	}
	return uint32(0)
}

// C documentation
//
//	/*
//	** Given 1 to 3 identifiers preceding the JOIN keyword, determine the
//	** type of join.  Return an integer constant that expresses that type
//	** in terms of the following bit values:
//	**
//	**     JT_INNER
//	**     JT_CROSS
//	**     JT_OUTER
//	**     JT_NATURAL
//	**     JT_LEFT
//	**     JT_RIGHT
//	**
//	** A full outer join is the combination of JT_LEFT and JT_RIGHT.
//	**
//	** If an illegal or unsupported join type is seen, then still return
//	** a join type, but put an error in the pParse structure.
//	**
//	** These are the valid join types:
//	**
//	**
//	**      pA       pB       pC               Return Value
//	**     -------  -----    -----             ------------
//	**     CROSS      -        -                 JT_CROSS
//	**     INNER      -        -                 JT_INNER
//	**     LEFT       -        -                 JT_LEFT|JT_OUTER
//	**     LEFT     OUTER      -                 JT_LEFT|JT_OUTER
//	**     RIGHT      -        -                 JT_RIGHT|JT_OUTER
//	**     RIGHT    OUTER      -                 JT_RIGHT|JT_OUTER
//	**     FULL       -        -                 JT_LEFT|JT_RIGHT|JT_OUTER
//	**     FULL     OUTER      -                 JT_LEFT|JT_RIGHT|JT_OUTER
//	**     NATURAL  INNER      -                 JT_NATURAL|JT_INNER
//	**     NATURAL  LEFT       -                 JT_NATURAL|JT_LEFT|JT_OUTER
//	**     NATURAL  LEFT     OUTER               JT_NATURAL|JT_LEFT|JT_OUTER
//	**     NATURAL  RIGHT      -                 JT_NATURAL|JT_RIGHT|JT_OUTER
//	**     NATURAL  RIGHT    OUTER               JT_NATURAL|JT_RIGHT|JT_OUTER
//	**     NATURAL  FULL       -                 JT_NATURAL|JT_LEFT|JT_RIGHT
//	**     NATURAL  FULL     OUTER               JT_NATRUAL|JT_LEFT|JT_RIGHT
//	**
//	** To preserve historical compatibly, SQLite also accepts a variety
//	** of other non-standard and in many cases nonsensical join types.
//	** This routine makes as much sense at it can from the nonsense join
//	** type and returns a result.  Examples of accepted nonsense join types
//	** include but are not limited to:
//	**
//	**          INNER CROSS JOIN        ->   same as JOIN
//	**          NATURAL CROSS JOIN      ->   same as NATURAL JOIN
//	**          OUTER LEFT JOIN         ->   same as LEFT JOIN
//	**          LEFT NATURAL JOIN       ->   same as NATURAL LEFT JOIN
//	**          LEFT RIGHT JOIN         ->   same as FULL JOIN
//	**          RIGHT OUTER FULL JOIN   ->   same as FULL JOIN
//	**          CROSS CROSS CROSS JOIN  ->   same as JOIN
//	**
//	** The only restrictions on the join type name are:
//	**
//	**    *   "INNER" cannot appear together with "OUTER", "LEFT", "RIGHT",
//	**        or "FULL".
//	**
//	**    *   "CROSS" cannot appear together with "OUTER", "LEFT", "RIGHT,
//	**        or "FULL".
//	**
//	**    *   If "OUTER" is present then there must also be one of
//	**        "LEFT", "RIGHT", or "FULL"
//	*/
func _sqlite3JoinType(tls *libc.TLS, pParse uintptr, pA uintptr, pB uintptr, pC uintptr) (r int32) {
	bp := tls.Alloc(48)
	defer tls.Free(48)
	var apAll [3]uintptr
	var i, j, jointype int32
	var p, zSp1, zSp2 uintptr
	_, _, _, _, _, _, _ = apAll, i, j, jointype, p, zSp1, zSp2
	jointype = 0
	apAll[0] = pA
	apAll[int32(1)] = pB
	apAll[int32(2)] = pC
	i = 0
	for {
		if !(i < int32(3) && apAll[i] != 0) {
			break
		}
		p = apAll[i]
		j = 0
		for {
			if !(j < libc.Int32FromUint64(libc.Uint64FromInt64(21)/libc.Uint64FromInt64(3))) {
				break
			}
			if (*TToken)(unsafe.Pointer(p)).Fn == uint32(_aKeyword[j].FnChar) && Xsqlite3_strnicmp(tls, (*TToken)(unsafe.Pointer(p)).Fz, uintptr(unsafe.Pointer(&_zKeyText))+uintptr(_aKeyword[j].Fi), libc.Int32FromUint32((*TToken)(unsafe.Pointer(p)).Fn)) == 0 {
				jointype = jointype | libc.Int32FromUint8(_aKeyword[j].Fcode)
				break
			}
			goto _2
		_2:
			;
			j = j + 1
		}
		if j >= libc.Int32FromUint64(libc.Uint64FromInt64(21)/libc.Uint64FromInt64(3)) {
			jointype = jointype | int32(JT_ERROR)
			break
		}
		goto _1
	_1:
		;
		i = i + 1
	}
	if jointype&(libc.Int32FromInt32(JT_INNER)|libc.Int32FromInt32(JT_OUTER)) == libc.Int32FromInt32(JT_INNER)|libc.Int32FromInt32(JT_OUTER) || jointype&int32(JT_ERROR) != 0 || jointype&(libc.Int32FromInt32(JT_OUTER)|libc.Int32FromInt32(JT_LEFT)|libc.Int32FromInt32(JT_RIGHT)) == int32(JT_OUTER) {
		zSp1 = __ccgo_ts + 11534
		zSp2 = __ccgo_ts + 11534
		if pB == uintptr(0) {
			zSp1 = zSp1 + 1
		}
		if pC == uintptr(0) {
			zSp2 = zSp2 + 1
		}
		_sqlite3ErrorMsg(tls, pParse, __ccgo_ts+20277, libc.VaList(bp+8, pA, zSp1, pB, zSp2, pC))
		jointype = int32(JT_INNER)
	}
	return jointype
}

// C documentation
//
//	/*
//	** Locate the in-memory structure that describes a particular database
//	** table given the name of that table and (optionally) the name of the
//	** database containing the table.  Return NULL if not found.  Also leave an
//	** error message in pParse->zErrMsg.
//	**
//	** The difference between this routine and sqlite3FindTable() is that this
//	** routine leaves an error message in pParse->zErrMsg where
//	** sqlite3FindTable() does not.
//	*/
func _sqlite3LocateTable(tls *libc.TLS, pParse uintptr, flags Tu32, zName uintptr, zDbase uintptr) (r uintptr) {
	bp := tls.Alloc(32)
	defer tls.Free(32)
	var db, p, pMod, zMsg, v1 uintptr
	_, _, _, _, _ = db, p, pMod, zMsg, v1
	db = (*TParse)(unsafe.Pointer(pParse)).Fdb
	/* Read the database schema. If an error occurs, leave an error message
	 ** and code in pParse and return NULL. */
	if (*Tsqlite3)(unsafe.Pointer(db)).FmDbFlags&uint32(DBFLAG_SchemaKnownOk) == uint32(0) && SQLITE_OK != _sqlite3ReadSchema(tls, pParse) {
		return uintptr(0)
	}
	p = _sqlite3FindTable(tls, db, zName, zDbase)
	if p == uintptr(0) {
		/* If zName is the not the name of a table in the schema created using
		 ** CREATE, then check to see if it is the name of an virtual table that
		 ** can be an eponymous virtual table. */
		if libc.Int32FromUint8((*TParse)(unsafe.Pointer(pParse)).FprepFlags)&int32(SQLITE_PREPARE_NO_VTAB) == 0 && libc.Int32FromUint8((*Tsqlite3)(unsafe.Pointer(db)).Finit1.Fbusy) == 0 {
			pMod = _sqlite3HashFind(tls, db+576, zName)
			if pMod == uintptr(0) && Xsqlite3_strnicmp(tls, zName, __ccgo_ts+13679, int32(7)) == 0 {
				pMod = _sqlite3PragmaVtabRegister(tls, db, zName)
			}
			if pMod == uintptr(0) && Xsqlite3_strnicmp(tls, zName, __ccgo_ts+13687, int32(4)) == 0 {
				pMod = _sqlite3JsonVtabRegister(tls, db, zName)
			}
			if pMod != 0 && _sqlite3VtabEponymousTableInit(tls, pParse, pMod) != 0 {
				return (*TModule)(unsafe.Pointer(pMod)).FpEpoTab
			}
		}
		if flags&uint32(LOCATE_NOERR) != 0 {
			return uintptr(0)
		}
		libc.SetBitFieldPtr16Uint32(pParse+40, libc.Uint32FromInt32(1), 8, 0x100)
	} else {
		if libc.Int32FromUint8((*TTable)(unsafe.Pointer(p)).FeTabType) == int32(TABTYP_VTAB) && libc.Int32FromUint8((*TParse)(unsafe.Pointer(pParse)).FprepFlags)&int32(SQLITE_PREPARE_NO_VTAB) != 0 {
			p = uintptr(0)
		}
	}
	if p == uintptr(0) {
		if flags&uint32(LOCATE_VIEW) != 0 {
			v1 = __ccgo_ts + 13692
		} else {
			v1 = __ccgo_ts + 13705
		}
		zMsg = v1
		if zDbase != 0 {
			_sqlite3ErrorMsg(tls, pParse, __ccgo_ts+7013, libc.VaList(bp+8, zMsg, zDbase, zName))
		} else {
			_sqlite3ErrorMsg(tls, pParse, __ccgo_ts+7084, libc.VaList(bp+8, zMsg, zName))
		}
	} else {
	}
	return p
}

// C documentation
//
//	/*
//	** Like malloc(), but remember the size of the allocation
//	** so that we can find it later using sqlite3MemSize().
//	**
//	** For this low-level routine, we are guaranteed that nByte>0 because
//	** cases of nByte<=0 will be intercepted and dealt with by higher level
//	** routines.
//	*/
func _sqlite3MemMalloc(tls *libc.TLS, nByte int32) (r uintptr) {
	bp := tls.Alloc(16)
	defer tls.Free(16)
	var p uintptr
	_ = p
	p = libc.Xmalloc(tls, libc.Uint64FromInt32(nByte+int32(8)))
	if p != 0 {
		**(**Tsqlite3_int64)(__ccgo_up(p)) = int64(nByte)
		p += 8
	} else {
		Xsqlite3_log(tls, int32(SQLITE_NOMEM), __ccgo_ts+1589, libc.VaList(bp+8, nByte))
	}
	return p
}

// C documentation
//
//	/*
//	** Like realloc().  Resize an allocation previously obtained from
//	** sqlite3MemMalloc().
//	**
//	** For this low-level interface, we know that pPrior!=0.  Cases where
//	** pPrior==0 while have been intercepted by higher-level routine and
//	** redirected to xMalloc.  Similarly, we know that nByte>0 because
//	** cases where nByte<=0 will have been intercepted by higher-level
//	** routines and redirected to xFree.
//	*/
func _sqlite3MemRealloc(tls *libc.TLS, pPrior uintptr, nByte int32) (r uintptr) {
	bp := tls.Alloc(32)
	defer tls.Free(32)
	var p uintptr
	_ = p
	p = pPrior
	/* EV: R-46199-30249 */
	p -= 8
	p = libc.Xrealloc(tls, p, libc.Uint64FromInt32(nByte+libc.Int32FromInt32(8)))
	if p != 0 {
		**(**Tsqlite3_int64)(__ccgo_up(p)) = int64(nByte)
		p += 8
	} else {
		Xsqlite3_log(tls, int32(SQLITE_NOMEM), __ccgo_ts+1627, libc.VaList(bp+8, _sqlite3MemSize(tls, pPrior), nByte))
	}
	return p
}

func _sqlite3MisuseError(tls *libc.TLS, lineno int32) (r int32) {
	return _sqlite3ReportError(tls, int32(SQLITE_MISUSE), lineno, __ccgo_ts+26305)
}

// C documentation
//
//	/*
//	** Cause a function to throw an error if it was call from OP_PureFunc
//	** rather than OP_Function.
//	**
//	** OP_PureFunc means that the function must be deterministic, and should
//	** throw an error if it is given inputs that would make it non-deterministic.
//	** This routine is invoked by date/time functions that use non-deterministic
//	** features such as 'now'.
//	*/
func _sqlite3NotPureFunc(tls *libc.TLS, pCtx uintptr) (r int32) {
	bp := tls.Alloc(32)
	defer tls.Free(32)
	var pOp, zContext, zMsg uintptr
	_, _, _ = pOp, zContext, zMsg
	if (*Tsqlite3_context)(unsafe.Pointer(pCtx)).FpVdbe == uintptr(0) {
		return int32(1)
	}
	pOp = (*TVdbe)(unsafe.Pointer((*Tsqlite3_context)(unsafe.Pointer(pCtx)).FpVdbe)).FaOp + uintptr((*Tsqlite3_context)(unsafe.Pointer(pCtx)).FiOp)*24
	if libc.Int32FromUint8((*TVdbeOp)(unsafe.Pointer(pOp)).Fopcode) == int32(OP_PureFunc) {
		if libc.Int32FromUint16((*TVdbeOp)(unsafe.Pointer(pOp)).Fp5)&int32(NC_IsCheck) != 0 {
			zContext = __ccgo_ts + 5415
		} else {
			if libc.Int32FromUint16((*TVdbeOp)(unsafe.Pointer(pOp)).Fp5)&int32(NC_GenCol) != 0 {
				zContext = __ccgo_ts + 5434
			} else {
				zContext = __ccgo_ts + 5453
			}
		}
		zMsg = Xsqlite3_mprintf(tls, __ccgo_ts+5462, libc.VaList(bp+8, (*TFuncDef)(unsafe.Pointer((*Tsqlite3_context)(unsafe.Pointer(pCtx)).FpFunc)).FzName, zContext))
		Xsqlite3_result_error(tls, pCtx, zMsg, -int32(1))
		Xsqlite3_free(tls, zMsg)
		return 0
	}
	return int32(1)
}

// C documentation
//
//	/*
//	** Call this routine to record the fact that an OOM (out-of-memory) error
//	** has happened.  This routine will set db->mallocFailed, and also
//	** temporarily disable the lookaside memory allocator and interrupt
//	** any running VDBEs.
//	**
//	** Always return a NULL pointer so that this routine can be invoked using
//	**
//	**      return sqlite3OomFault(db);
//	**
//	** and thereby avoid unnecessary stack frame allocations for the overwhelmingly
//	** common case where no OOM occurs.
//	*/
func _sqlite3OomFault(tls *libc.TLS, db uintptr) (r uintptr) {
	var pParse uintptr
	_ = pParse
	if libc.Int32FromUint8((*Tsqlite3)(unsafe.Pointer(db)).FmallocFailed) == 0 && libc.Int32FromUint8((*Tsqlite3)(unsafe.Pointer(db)).FbBenignMalloc) == 0 {
		(*Tsqlite3)(unsafe.Pointer(db)).FmallocFailed = uint8(1)
		if (*Tsqlite3)(unsafe.Pointer(db)).FnVdbeExec > 0 {
			libc.AtomicStoreNInt32(db+432, libc.Int32FromInt32(1), libc.Int32FromInt32(__ATOMIC_RELAXED))
		}
		(*Tsqlite3)(unsafe.Pointer(db)).Flookaside.FbDisable = (*Tsqlite3)(unsafe.Pointer(db)).Flookaside.FbDisable + 1
		(*Tsqlite3)(unsafe.Pointer(db)).Flookaside.Fsz = uint16(0)
		if (*Tsqlite3)(unsafe.Pointer(db)).FpParse != 0 {
			_sqlite3ErrorMsg(tls, (*Tsqlite3)(unsafe.Pointer(db)).FpParse, __ccgo_ts+1663, 0)
			(*TParse)(unsafe.Pointer((*Tsqlite3)(unsafe.Pointer(db)).FpParse)).Frc = int32(SQLITE_NOMEM)
			pParse = (*TParse)(unsafe.Pointer((*Tsqlite3)(unsafe.Pointer(db)).FpParse)).FpOuterParse
			for {
				if !(pParse != 0) {
					break
				}
				(*TParse)(unsafe.Pointer(pParse)).FnErr = (*TParse)(unsafe.Pointer(pParse)).FnErr + 1
				(*TParse)(unsafe.Pointer(pParse)).Frc = int32(SQLITE_NOMEM)
				goto _1
			_1:
				;
				pParse = (*TParse)(unsafe.Pointer(pParse)).FpOuterParse
			}
		}
	}
	return uintptr(0)
}

// C documentation
//
//	/*
//	** Open the sqlite_schema table stored in database number iDb for
//	** writing. The table is opened using cursor 0.
//	*/
func _sqlite3OpenSchemaTable(tls *libc.TLS, p uintptr, iDb int32) {
	var v uintptr
	_ = v
	v = _sqlite3GetVdbe(tls, p)
	_sqlite3TableLock(tls, p, iDb, uint32(SCHEMA_ROOT), uint8(1), __ccgo_ts+6277)
	_sqlite3VdbeAddOp4Int(tls, v, int32(OP_OpenWrite), 0, int32(SCHEMA_ROOT), iDb, int32(5))
	if (*TParse)(unsafe.Pointer(p)).FnTab == 0 {
		(*TParse)(unsafe.Pointer(p)).FnTab = int32(1)
	}
}

// C documentation
//
//	/*
//	** Make sure the TEMP database is open and available for use.  Return
//	** the number of errors.  Leave any error messages in the pParse structure.
//	*/
func _sqlite3OpenTempDatabase(tls *libc.TLS, pParse uintptr) (r int32) {
	bp := tls.Alloc(16)
	defer tls.Free(16)
	var db uintptr
	var rc int32
	var _ /* pBt at bp+0 */ uintptr
	_, _ = db, rc
	db = (*TParse)(unsafe.Pointer(pParse)).Fdb
	if (**(**TDb)(__ccgo_up((*Tsqlite3)(unsafe.Pointer(db)).FaDb + 1*32))).FpBt == uintptr(0) && !((*TParse)(unsafe.Pointer(pParse)).Fexplain != 0) {
		rc = _sqlite3BtreeOpen(tls, (*Tsqlite3)(unsafe.Pointer(db)).FpVfs, uintptr(0), db, bp, 0, _flags)
		if rc != SQLITE_OK {
			_sqlite3ErrorMsg(tls, pParse, __ccgo_ts+16126, 0)
			(*TParse)(unsafe.Pointer(pParse)).Frc = rc
			return int32(1)
		}
		(**(**TDb)(__ccgo_up((*Tsqlite3)(unsafe.Pointer(db)).FaDb + 1*32))).FpBt = **(**uintptr)(__ccgo_up(bp))
		if int32(SQLITE_NOMEM) == _sqlite3BtreeSetPageSize(tls, **(**uintptr)(__ccgo_up(bp)), (*Tsqlite3)(unsafe.Pointer(db)).FnextPagesize, 0, 0) {
			_sqlite3OomFault(tls, db)
			return int32(1)
		}
	}
	return 0
}

// C documentation
//
//	/*
//	** This function is called when the user invokes "PRAGMA wal_checkpoint",
//	** "PRAGMA wal_blocking_checkpoint" or calls the sqlite3_wal_checkpoint()
//	** or wal_blocking_checkpoint() API functions.
//	**
//	** Parameter eMode is one of SQLITE_CHECKPOINT_PASSIVE, FULL or RESTART.
//	*/
func _sqlite3PagerCheckpoint(tls *libc.TLS, pPager uintptr, db uintptr, eMode int32, pnLog uintptr, pnCkpt uintptr) (r int32) {
	var rc int32
	var v1 uintptr
	_, _ = rc, v1
	rc = SQLITE_OK
	if (*TPager)(unsafe.Pointer(pPager)).FpWal == uintptr(0) && libc.Int32FromUint8((*TPager)(unsafe.Pointer(pPager)).FjournalMode) == int32(PAGER_JOURNALMODE_WAL) {
		/* This only happens when a database file is zero bytes in size opened and
		 ** then "PRAGMA journal_mode=WAL" is run and then sqlite3_wal_checkpoint()
		 ** is invoked without any intervening transactions.  We need to start
		 ** a transaction to initialize pWal.  The PRAGMA table_list statement is
		 ** used for this since it starts transactions on every database file,
		 ** including all ATTACHed databases.  This seems expensive for a single
		 ** sqlite3_wal_checkpoint() call, but it happens very rarely.
		 ** https://sqlite.org/forum/forumpost/fd0f19d229156939
		 */
		Xsqlite3_exec(tls, db, __ccgo_ts+4251, uintptr(0), uintptr(0), uintptr(0))
	}
	if (*TPager)(unsafe.Pointer(pPager)).FpWal != 0 {
		if eMode <= SQLITE_CHECKPOINT_PASSIVE {
			v1 = uintptr(0)
		} else {
			v1 = (*TPager)(unsafe.Pointer(pPager)).FxBusyHandler
		}
		rc = _sqlite3WalCheckpoint(tls, (*TPager)(unsafe.Pointer(pPager)).FpWal, db, eMode, v1, (*TPager)(unsafe.Pointer(pPager)).FpBusyHandlerArg, libc.Int32FromUint8((*TPager)(unsafe.Pointer(pPager)).FwalSyncFlags), int32((*TPager)(unsafe.Pointer(pPager)).FpageSize), (*TPager)(unsafe.Pointer(pPager)).FpTmpSpace, pnLog, pnCkpt)
	}
	return rc
}

// C documentation
//
//	/*
//	** Turn bulk memory into a valid Parse object and link that Parse object
//	** into database connection db.
//	**
//	** Call sqlite3ParseObjectReset() to undo this operation.
//	**
//	** Caution:  Do not confuse this routine with sqlite3ParseObjectInit() which
//	** is generated by Lemon.
//	*/
func _sqlite3ParseObjectInit(tls *libc.TLS, pParse uintptr, db uintptr) {
	libc.Xmemset(tls, pParse+uintptr(uint64(libc.UintptrFromInt32(0)+8)), 0, uint64(libc.UintptrFromInt32(0)+192)-uint64(libc.UintptrFromInt32(0)+8))
	libc.Xmemset(tls, pParse+uintptr(uint64(libc.UintptrFromInt32(0)+288)), 0, libc.Uint64FromInt64(424)-uint64(libc.UintptrFromInt32(0)+288))
	(*TParse)(unsafe.Pointer(pParse)).FpOuterParse = (*Tsqlite3)(unsafe.Pointer(db)).FpParse
	(*Tsqlite3)(unsafe.Pointer(db)).FpParse = pParse
	(*TParse)(unsafe.Pointer(pParse)).Fdb = db
	if (*Tsqlite3)(unsafe.Pointer(db)).FmallocFailed != 0 {
		_sqlite3ErrorMsg(tls, pParse, __ccgo_ts+1663, 0)
	}
}

/*
** Maximum number of times that we will try again to prepare a statement
** that returns SQLITE_ERROR_RETRY.
 */

// C documentation
//
//	/*
//	** Return the preferred table name for system tables.  Translate legacy
//	** names into the new preferred names, as appropriate.
//	*/
func _sqlite3PreferredTableName(tls *libc.TLS, zName uintptr) (r uintptr) {
	if Xsqlite3_strnicmp(tls, zName, __ccgo_ts+6749, int32(7)) == 0 {
		if _sqlite3StrICmp(tls, zName+uintptr(7), __ccgo_ts+6277+7) == 0 {
			return __ccgo_ts + 6795
		}
		if _sqlite3StrICmp(tls, zName+uintptr(7), __ccgo_ts+6757+7) == 0 {
			return __ccgo_ts + 6776
		}
	}
	return zName
}

// C documentation
//
//	/*
//	** Re-register the built-in LIKE functions.  The caseSensitive
//	** parameter determines whether or not the LIKE operator is case
//	** sensitive.
//	*/
func _sqlite3RegisterLikeFunctions(tls *libc.TLS, db uintptr, caseSensitive int32) {
	var flags, nArg int32
	var pDef, pInfo uintptr
	_, _, _, _ = flags, nArg, pDef, pInfo
	if caseSensitive != 0 {
		pInfo = uintptr(unsafe.Pointer(&_likeInfoAlt))
		flags = libc.Int32FromInt32(SQLITE_FUNC_LIKE) | libc.Int32FromInt32(SQLITE_FUNC_CASE)
	} else {
		pInfo = uintptr(unsafe.Pointer(&_likeInfoNorm))
		flags = int32(SQLITE_FUNC_LIKE)
	}
	nArg = int32(2)
	for {
		if !(nArg <= int32(3)) {
			break
		}
		_sqlite3CreateFunc(tls, db, __ccgo_ts+16598, nArg, int32(SQLITE_UTF8), pInfo, __ccgo_fp(_likeFunc), uintptr(0), uintptr(0), uintptr(0), uintptr(0), uintptr(0))
		pDef = _sqlite3FindFunction(tls, db, __ccgo_ts+16598, nArg, uint8(SQLITE_UTF8), uint8(0))
		/* The sqlite3CreateFunc() call above cannot fail
		 ** because the "like" SQL-function already exists */
		**(**Tu32)(__ccgo_up(pDef + 4)) |= libc.Uint32FromInt32(flags)
		**(**Tu32)(__ccgo_up(pDef + 4)) &= libc.Uint32FromInt32(^libc.Int32FromInt32(SQLITE_FUNC_UNSAFE))
		goto _1
	_1:
		;
		nArg = nArg + 1
	}
}

// C documentation
//
//	/*
//	** This routine does per-connection function registration.  Most
//	** of the built-in functions above are part of the global function set.
//	** This routine only deals with those that are not global.
//	*/
func _sqlite3RegisterPerConnectionBuiltinFunctions(tls *libc.TLS, db uintptr) {
	var rc int32
	_ = rc
	rc = Xsqlite3_overload_function(tls, db, __ccgo_ts+16592, int32(2))
	if rc == int32(SQLITE_NOMEM) {
		_sqlite3OomFault(tls, db)
	}
}

// C documentation
//
//	/*
//	** Generate code for the REINDEX command.
//	**
//	**        REINDEX                            -- 1
//	**        REINDEX  <collation>               -- 2
//	**        REINDEX  ?<database>.?<indexname>  -- 3
//	**        REINDEX  ?<database>.?<tablename>  -- 4
//	**        REINDEX  EXPRESSIONS               -- 5
//	**
//	** Form 1 causes all indexes in all attached databases to be rebuilt.
//	** Form 2 rebuilds all indexes in all databases that use the named
//	** collating function.  Forms 3 and 4 rebuild the named index or all
//	** indexes associated with the named table, respectively.  Form 5
//	** rebuilds all expression indexes in addition to all collations,
//	** indexes, or tables named "EXPRESSIONS".
//	**
//	** If the name is ambiguous such that it matches two or more of
//	** forms 2 through 5, then rebuild the union of all matching indexes,
//	** taken care to avoid rebuilding the same index more than once.
//	*/
func _sqlite3Reindex(tls *libc.TLS, pParse uintptr, pName1 uintptr, pName2 uintptr) {
	bp := tls.Alloc(16)
	defer tls.Free(16)
	var bAll, bMatch, iDb, iReDb, isExprIdx int32
	var db, k, pDb, pIdx, pReIndex, pReTab, pTab, z, zColl, zDb, v1 uintptr
	var v2 bool
	var _ /* pObjName at bp+0 */ uintptr
	_, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _ = bAll, bMatch, db, iDb, iReDb, isExprIdx, k, pDb, pIdx, pReIndex, pReTab, pTab, z, zColl, zDb, v1, v2
	z = uintptr(0)                             /* Name of a table or index or collation */
	zDb = uintptr(0)                           /* Name of the database */
	iReDb = -int32(1)                          /* The database index number */
	db = (*TParse)(unsafe.Pointer(pParse)).Fdb /* Name of the table or index to be reindexed */
	bMatch = 0                                 /* At least one name match */
	zColl = uintptr(0)                         /* Rebuild indexes using this collation */
	pReTab = uintptr(0)                        /* Rebuild all indexes of this table */
	pReIndex = uintptr(0)                      /* Rebuild this index */
	isExprIdx = 0                              /* Rebuild all expression indexes */
	bAll = 0                                   /* Rebuild all indexes */
	/* Read the database schema. If an error occurs, leave an error message
	 ** and code in pParse and return NULL. */
	if SQLITE_OK != _sqlite3ReadSchema(tls, pParse) {
		return
	}
	if pName1 == uintptr(0) {
		/* rebuild all indexes */
		bMatch = int32(1)
		bAll = int32(1)
	} else {
		if pName2 == uintptr(0) || (*TToken)(unsafe.Pointer(pName2)).Fz == uintptr(0) {
			z = _sqlite3NameFromToken(tls, (*TParse)(unsafe.Pointer(pParse)).Fdb, pName1)
			if z == uintptr(0) {
				return
			}
		} else {
			iReDb = _sqlite3TwoPartName(tls, pParse, pName1, pName2, bp)
			if iReDb < 0 {
				return
			}
			z = _sqlite3NameFromToken(tls, db, **(**uintptr)(__ccgo_up(bp)))
			if z == uintptr(0) {
				return
			}
			zDb = (**(**TDb)(__ccgo_up((*Tsqlite3)(unsafe.Pointer(db)).FaDb + uintptr(iReDb)*32))).FzDbSName
		}
	}
	if !(bAll != 0) {
		if zDb == uintptr(0) && _sqlite3StrICmp(tls, z, __ccgo_ts+16219) == 0 {
			isExprIdx = int32(1)
			bMatch = int32(1)
		}
		if zDb == uintptr(0) && _sqlite3FindCollSeq(tls, db, (*Tsqlite3)(unsafe.Pointer(db)).Fenc, z, 0) != uintptr(0) {
			zColl = z
			bMatch = int32(1)
		}
		if v2 = zColl == uintptr(0); v2 {
			v1 = _sqlite3FindTable(tls, db, z, zDb)
			pReTab = v1
		}
		if v2 && v1 != uintptr(0) {
			bMatch = int32(1)
		}
		if v2 = zColl == uintptr(0); v2 {
			v1 = _sqlite3FindIndex(tls, db, z, zDb)
			pReIndex = v1
		}
		if v2 && v1 != uintptr(0) {
			bMatch = int32(1)
		}
	}
	if bMatch != 0 {
		iDb = 0
		pDb = (*Tsqlite3)(unsafe.Pointer(db)).FaDb
		for {
			if !(iDb < (*Tsqlite3)(unsafe.Pointer(db)).FnDb) {
				break
			}
			if iReDb >= 0 && iReDb != iDb {
				goto _5
			}
			k = (*THash)(unsafe.Pointer((*TDb)(unsafe.Pointer(pDb)).FpSchema + 8)).Ffirst
			for {
				if !(k != 0) {
					break
				}
				pTab = (*THashElem)(unsafe.Pointer(k)).Fdata
				if libc.Int32FromUint8((*TTable)(unsafe.Pointer(pTab)).FeTabType) == int32(TABTYP_VTAB) {
					goto _6
				}
				pIdx = (*TTable)(unsafe.Pointer(pTab)).FpIndex
				for {
					if !(pIdx != 0) {
						break
					}
					if bAll != 0 || pTab == pReTab || pIdx == pReIndex || isExprIdx != 0 && int32(uint32(*(*uint16)(unsafe.Pointer(pIdx + 100))&0x800>>11)) != 0 || zColl != uintptr(0) && _collationMatch(tls, zColl, pIdx) != 0 {
						_sqlite3BeginWriteOperation(tls, pParse, 0, iDb)
						_sqlite3RefillIndex(tls, pParse, pIdx, -int32(1))
					}
					goto _7
				_7:
					;
					pIdx = (*TIndex)(unsafe.Pointer(pIdx)).FpNext
				} /* End loop over indexes of pTab */
				goto _6
			_6:
				;
				k = (*THashElem)(unsafe.Pointer(k)).Fnext
			} /* End loop over tables of iDb */
			goto _5
		_5:
			;
			iDb = iDb + 1
			pDb += 32
		} /* End loop over databases */
	} else {
		_sqlite3ErrorMsg(tls, pParse, __ccgo_ts+16231, 0)
	}
	_sqlite3DbFree(tls, db, z)
	return
}

// C documentation
//
//	/*
//	** The following routines are substitutes for constants SQLITE_CORRUPT,
//	** SQLITE_MISUSE, SQLITE_CANTOPEN, SQLITE_NOMEM and possibly other error
//	** constants.  They serve two purposes:
//	**
//	**   1.  Serve as a convenient place to set a breakpoint in a debugger
//	**       to detect when version error conditions occurs.
//	**
//	**   2.  Invoke sqlite3_log() to provide the source code location where
//	**       a low-level error is first detected.
//	*/
func _sqlite3ReportError(tls *libc.TLS, iErr int32, lineno int32, zType uintptr) (r int32) {
	bp := tls.Alloc(32)
	defer tls.Free(32)
	Xsqlite3_log(tls, iErr, __ccgo_ts+26260, libc.VaList(bp+8, zType, lineno, uintptr(20)+Xsqlite3_sourceid(tls)))
	return iErr
}

// C documentation
//
//	/*
//	** Check every term in the ORDER BY or GROUP BY clause pOrderBy of
//	** the SELECT statement pSelect.  If any term is reference to a
//	** result set expression (as determined by the ExprList.a.u.x.iOrderByCol
//	** field) then convert that term into a copy of the corresponding result set
//	** column.
//	**
//	** If any errors are detected, add an error message to pParse and
//	** return non-zero.  Return zero if no errors are seen.
//	*/
func _sqlite3ResolveOrderGroupBy(tls *libc.TLS, pParse uintptr, pSelect uintptr, pOrderBy uintptr, zType uintptr) (r int32) {
	bp := tls.Alloc(16)
	defer tls.Free(16)
	var db, pEList, pItem uintptr
	var i int32
	_, _, _, _ = db, i, pEList, pItem
	db = (*TParse)(unsafe.Pointer(pParse)).Fdb
	if pOrderBy == uintptr(0) || (*Tsqlite3)(unsafe.Pointer((*TParse)(unsafe.Pointer(pParse)).Fdb)).FmallocFailed != 0 || libc.Int32FromUint8((*TParse)(unsafe.Pointer(pParse)).FeParseMode) >= int32(PARSE_MODE_RENAME) {
		return 0
	}
	if (*TExprList)(unsafe.Pointer(pOrderBy)).FnExpr > **(**int32)(__ccgo_up(db + 136 + 2*4)) {
		_sqlite3ErrorMsg(tls, pParse, __ccgo_ts+7719, libc.VaList(bp+8, zType))
		return int32(1)
	}
	pEList = (*TSelect)(unsafe.Pointer(pSelect)).FpEList
	/* sqlite3SelectNew() guarantees this */
	i = 0
	pItem = pOrderBy + 8
	for {
		if !(i < (*TExprList)(unsafe.Pointer(pOrderBy)).FnExpr) {
			break
		}
		if (*(*struct {
			FiOrderByCol Tu16
			FiAlias      Tu16
		})(unsafe.Pointer(pItem + 24))).FiOrderByCol != 0 {
			if libc.Int32FromUint16((*(*struct {
				FiOrderByCol Tu16
				FiAlias      Tu16
			})(unsafe.Pointer(pItem + 24))).FiOrderByCol) > (*TExprList)(unsafe.Pointer(pEList)).FnExpr {
				_resolveOutOfRangeError(tls, pParse, zType, i+int32(1), (*TExprList)(unsafe.Pointer(pEList)).FnExpr, uintptr(0))
				return int32(1)
			}
			_resolveAlias(tls, pParse, pEList, libc.Int32FromUint16((*(*struct {
				FiOrderByCol Tu16
				FiAlias      Tu16
			})(unsafe.Pointer(pItem + 24))).FiOrderByCol)-int32(1), (*TExprList_item)(unsafe.Pointer(pItem)).FpExpr, 0)
		}
		goto _1
	_1:
		;
		i = i + 1
		pItem += 32
	}
	return 0
}

// C documentation
//
//	/*
//	** Use the content of the StrAccum passed as the second argument
//	** as the result of an SQL function.
//	*/
func _sqlite3ResultStrAccum(tls *libc.TLS, pCtx uintptr, p uintptr) {
	if (*TStrAccum)(unsafe.Pointer(p)).FaccError != 0 {
		Xsqlite3_result_error_code(tls, pCtx, libc.Int32FromUint8((*TStrAccum)(unsafe.Pointer(p)).FaccError))
		Xsqlite3_str_reset(tls, p)
	} else {
		if libc.Int32FromUint8((*TStrAccum)(unsafe.Pointer(p)).FprintfFlags)&int32(SQLITE_PRINTF_MALLOCED) != 0 {
			Xsqlite3_result_text(tls, pCtx, (*TStrAccum)(unsafe.Pointer(p)).FzText, libc.Int32FromUint32((*TStrAccum)(unsafe.Pointer(p)).FnChar), __ccgo_fp(_sqlite3RowSetClear))
		} else {
			Xsqlite3_result_text(tls, pCtx, __ccgo_ts+1693, 0, libc.UintptrFromInt32(0))
			Xsqlite3_str_reset(tls, p)
		}
	}
}

// C documentation
//
//	/*
//	** Return a pointer to a buffer containing a usable rowid alias for table
//	** pTab. An alias is usable if there is not an explicit user-defined column
//	** of the same name.
//	*/
func _sqlite3RowidAlias(tls *libc.TLS, pTab uintptr) (r uintptr) {
	var azOpt [3]uintptr
	var ii int32
	_, _ = azOpt, ii
	azOpt = [3]uintptr{
		0: __ccgo_ts + 8182,
		1: __ccgo_ts + 8190,
		2: __ccgo_ts + 8196,
	}
	ii = 0
	for {
		if !(ii < libc.Int32FromUint64(libc.Uint64FromInt64(24)/libc.Uint64FromInt64(8))) {
			break
		}
		if _sqlite3ColumnIndex(tls, pTab, azOpt[ii]) < 0 {
			return azOpt[ii]
		}
		goto _1
	_1:
		;
		ii = ii + 1
	}
	return uintptr(0)
}

// C documentation
//
//	/*
//	** Code an OP_Halt due to non-unique rowid.
//	*/
func _sqlite3RowidConstraint(tls *libc.TLS, pParse uintptr, onError int32, pTab uintptr) {
	bp := tls.Alloc(32)
	defer tls.Free(32)
	var rc int32
	var zMsg uintptr
	_, _ = rc, zMsg
	if int32((*TTable)(unsafe.Pointer(pTab)).FiPKey) >= 0 {
		zMsg = _sqlite3MPrintf(tls, (*TParse)(unsafe.Pointer(pParse)).Fdb, __ccgo_ts+13625, libc.VaList(bp+8, (*TTable)(unsafe.Pointer(pTab)).FzName, (**(**TColumn)(__ccgo_up((*TTable)(unsafe.Pointer(pTab)).FaCol + uintptr((*TTable)(unsafe.Pointer(pTab)).FiPKey)*16))).FzCnName))
		rc = libc.Int32FromInt32(SQLITE_CONSTRAINT) | libc.Int32FromInt32(6)<<libc.Int32FromInt32(8)
	} else {
		zMsg = _sqlite3MPrintf(tls, (*TParse)(unsafe.Pointer(pParse)).Fdb, __ccgo_ts+16210, libc.VaList(bp+8, (*TTable)(unsafe.Pointer(pTab)).FzName))
		rc = libc.Int32FromInt32(SQLITE_CONSTRAINT) | libc.Int32FromInt32(10)<<libc.Int32FromInt32(8)
	}
	_sqlite3HaltConstraint(tls, pParse, rc, onError, zMsg, int8(-libc.Int32FromInt32(7)), uint8(P5_ConstraintUnique))
}

// C documentation
//
//	/*
//	** Register the r-tree module with database handle db. This creates the
//	** virtual table module "rtree" and the debugging/analysis scalar
//	** function "rtreenode".
//	*/
func _sqlite3RtreeInit(tls *libc.TLS, db uintptr) (r int32) {
	var c, c1 uintptr
	var rc, utf8 int32
	_, _, _, _ = c, c1, rc, utf8
	utf8 = int32(SQLITE_UTF8)
	rc = Xsqlite3_create_function(tls, db, __ccgo_ts+30218, int32(2), utf8, uintptr(0), __ccgo_fp(_rtreenode), uintptr(0), uintptr(0))
	if rc == SQLITE_OK {
		rc = Xsqlite3_create_function(tls, db, __ccgo_ts+30228, int32(1), utf8, uintptr(0), __ccgo_fp(_rtreedepth), uintptr(0), uintptr(0))
	}
	if rc == SQLITE_OK {
		rc = Xsqlite3_create_function(tls, db, __ccgo_ts+30239, -int32(1), utf8, uintptr(0), __ccgo_fp(_rtreecheck), uintptr(0), uintptr(0))
	}
	if rc == SQLITE_OK {
		c = libc.UintptrFromInt32(RTREE_COORD_REAL32)
		rc = Xsqlite3_create_module_v2(tls, db, __ccgo_ts+29962, uintptr(unsafe.Pointer(&_rtreeModule)), c, uintptr(0))
	}
	if rc == SQLITE_OK {
		c1 = libc.UintptrFromInt32(RTREE_COORD_INT32)
		rc = Xsqlite3_create_module_v2(tls, db, __ccgo_ts+30250, uintptr(unsafe.Pointer(&_rtreeModule)), c1, uintptr(0))
	}
	if rc == SQLITE_OK {
		rc = _sqlite3_geopoly_init(tls, db)
	}
	return rc
}

// C documentation
//
//	/*
//	** Check to make sure we have a valid db pointer.  This test is not
//	** foolproof but it does provide some measure of protection against
//	** misuse of the interface such as passing in db pointers that are
//	** NULL or which have been previously closed.  If this routine returns
//	** 1 it means that the db pointer is valid and 0 if it should not be
//	** dereferenced for any reason.  The calling function should invoke
//	** SQLITE_MISUSE immediately.
//	**
//	** sqlite3SafetyCheckOk() requires that the db pointer be valid for
//	** use.  sqlite3SafetyCheckSickOrOk() allows a db pointer that failed to
//	** open properly and is not fit for general use but which can be
//	** used as an argument to sqlite3_errmsg() or sqlite3_close().
//	*/
func _sqlite3SafetyCheckOk(tls *libc.TLS, db uintptr) (r int32) {
	var eOpenState Tu8
	_ = eOpenState
	if db == uintptr(0) {
		_logBadConnection(tls, __ccgo_ts+1694)
		return 0
	}
	eOpenState = (*Tsqlite3)(unsafe.Pointer(db)).FeOpenState
	if libc.Int32FromUint8(eOpenState) != int32(SQLITE_STATE_OPEN) {
		if _sqlite3SafetyCheckSickOrOk(tls, db) != 0 {
			_logBadConnection(tls, __ccgo_ts+1886)
		}
		return 0
	} else {
		return int32(1)
	}
	return r
}

func _sqlite3SafetyCheckSickOrOk(tls *libc.TLS, db uintptr) (r int32) {
	var eOpenState Tu8
	_ = eOpenState
	eOpenState = (*Tsqlite3)(unsafe.Pointer(db)).FeOpenState
	if libc.Int32FromUint8(eOpenState) != int32(SQLITE_STATE_SICK) && libc.Int32FromUint8(eOpenState) != int32(SQLITE_STATE_OPEN) && libc.Int32FromUint8(eOpenState) != int32(SQLITE_STATE_BUSY) {
		_logBadConnection(tls, __ccgo_ts+1895)
		return 0
	} else {
		return int32(1)
	}
	return r
}

// C documentation
//
//	/*
//	** Generate byte-code for the SELECT statement given in the p argument.
//	**
//	** The results are returned according to the SelectDest structure.
//	** See comments in sqliteInt.h for further information.
//	**
//	** This routine returns the number of errors.  If any errors are
//	** encountered, then an appropriate error message is left in
//	** pParse->zErrMsg.
//	**
//	** This routine does NOT free the Select structure passed in.  The
//	** calling function needs to do that.
//	**
//	** This is a long function.  The following is an outline of the processing
//	** steps, with tags referencing various milestones:
//	**
//	**  *  Resolve names and similar preparation                tag-select-0100
//	**  *  Scan of the FROM clause                              tag-select-0200
//	**      +  OUTER JOIN strength reduction                      tag-select-0220
//	**      +  Sub-query ORDER BY removal                         tag-select-0230
//	**      +  Query flattening                                   tag-select-0240
//	**  *  Separate subroutine for compound-SELECT              tag-select-0300
//	**  *  WHERE-clause constant propagation                    tag-select-0330
//	**  *  Count()-of-VIEW optimization                         tag-select-0350
//	**  *  Scan of the FROM clause again                        tag-select-0400
//	**      +  Authorize unreferenced tables                      tag-select-0410
//	**      +  Predicate push-down optimization                   tag-select-0420
//	**      +  Omit unused subquery columns optimization          tag-select-0440
//	**      +  Generate code to implement subqueries              tag-select-0480
//	**         -  Co-routines                                       tag-select-0482
//	**         -  Reuse previously computed CTE                     tag-select-0484
//	**         -  REuse previously computed VIEW                    tag-select-0486
//	**         -  Materialize a VIEW or CTE                         tag-select-0488
//	**  *  DISTINCT ORDER BY -> GROUP BY optimization           tag-select-0500
//	**  *  Set up for ORDER BY                                  tag-select-0600
//	**  *  Create output table                                  tag-select-0630
//	**  *  Prepare registers for LIMIT                          tag-select-0650
//	**  *  Setup for DISTINCT                                   tag-select-0680
//	**  *  Generate code for non-aggregate and non-GROUP BY     tag-select-0700
//	**  *  Generate code for aggregate and/or GROUP BY          tag-select-0800
//	**      +  GROUP BY queries                                   tag-select-0810
//	**      +  non-GROUP BY queries                               tag-select-0820
//	**         -  Special case of count() w/o GROUP BY              tag-select-0821
//	**         -  General case of non-GROUP BY aggregates           tag-select-0822
//	**  *  Sort results, as needed                              tag-select-0900
//	**  *  Internal self-checks                                 tag-select-1000
//	*/
func _sqlite3Select(tls *libc.TLS, pParse uintptr, p uintptr, pDest uintptr) (r int32) {
	bp := tls.Alloc(208)
	defer tls.Free(208)
	var addr1, addrEnd, addrGosub, addrOutputRow, addrReset, addrSetAbort, addrSortingIdx, addrTop, addrTopOfLoop, eDist, eDist1, groupBySort, i, iAMem, iAbortFlag, iBMem, iBreak, iCont, iCsr, iDb, iDb1, iEnd, iOrderByCol, iUseFlag, ii, isAgg, j, k, nCol, nGroupBy, onceAddr, orderByGrp, rc, regAcc, regBase, regGosub, regOutputRow, regRecord, regReset, sortOut, sortPTab, topAddr, v12, v15 int32
	var db, p0, pAggInfo, pBase, pBest, pCol, pCteUse, pCteUse1, pDistinct, pDistinct1, pEList, pExpr, pF, pF1, pGroupBy, pHaving, pI2, pIdx, pItem, pItem1, pItem2, pKeyInfo, pKeyInfo1, pKeyInfo2, pPrior, pPriorSubq, pSub, pSub1, pSubq, pTab, pTab1, pTabList, pWInfo, pWhere, pWin, pX, v, zDb, zSavedAuthContext, v1, v3 uintptr
	var distFlag, distFlag1, wctrlFlags Tu16
	var iRoot TPgno
	var minMaxFlag Tu8
	var _ /* dest at bp+72 */ TSelectDest
	var _ /* pMinMaxOrderBy at bp+64 */ uintptr
	var _ /* sDistinct at bp+0 */ TDistinctCtx
	var _ /* sNC at bp+112 */ TNameContext
	var _ /* sSort at bp+16 */ TSortCtx
	_, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _ = addr1, addrEnd, addrGosub, addrOutputRow, addrReset, addrSetAbort, addrSortingIdx, addrTop, addrTopOfLoop, db, distFlag, distFlag1, eDist, eDist1, groupBySort, i, iAMem, iAbortFlag, iBMem, iBreak, iCont, iCsr, iDb, iDb1, iEnd, iOrderByCol, iRoot, iUseFlag, ii, isAgg, j, k, minMaxFlag, nCol, nGroupBy, onceAddr, orderByGrp, p0, pAggInfo, pBase, pBest, pCol, pCteUse, pCteUse1, pDistinct, pDistinct1, pEList, pExpr, pF, pF1, pGroupBy, pHaving, pI2, pIdx, pItem, pItem1, pItem2, pKeyInfo, pKeyInfo1, pKeyInfo2, pPrior, pPriorSubq, pSub, pSub1, pSubq, pTab, pTab1, pTabList, pWInfo, pWhere, pWin, pX, rc, regAcc, regBase, regGosub, regOutputRow, regRecord, regReset, sortOut, sortPTab, topAddr, v, wctrlFlags, zDb, zSavedAuthContext, v1, v12, v15, v3 /* True for select lists like "count(*)" */
	pEList = uintptr(0)                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                        /* The HAVING clause.  May be NULL */
	pAggInfo = uintptr(0)                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                      /* Aggregate information */
	rc = int32(1)                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                              /* The database connection */
	**(**uintptr)(__ccgo_up(bp + 64)) = uintptr(0)                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                             /* Flag for min/max queries */
	db = (*TParse)(unsafe.Pointer(pParse)).Fdb
	v = _sqlite3GetVdbe(tls, pParse)
	if p == uintptr(0) || (*TParse)(unsafe.Pointer(pParse)).FnErr != 0 {
		return int32(1)
	}
	if _sqlite3AuthCheck(tls, pParse, int32(SQLITE_SELECT), uintptr(0), uintptr(0), uintptr(0)) != 0 {
		return int32(1)
	}
	/* tag-select-0100 */
	if libc.Int32FromUint8((*TSelectDest)(unsafe.Pointer(pDest)).FeDest) <= int32(SRT_DistQueue) {
		/* All of these destinations are also able to ignore the ORDER BY clause */
		if (*TSelect)(unsafe.Pointer(p)).FpOrderBy != 0 {
			_sqlite3ParserAddCleanup(tls, pParse, __ccgo_fp(_sqlite3ExprListDeleteGeneric), (*TSelect)(unsafe.Pointer(p)).FpOrderBy)
			(*TSelect)(unsafe.Pointer(p)).FpOrderBy = uintptr(0)
		}
		**(**Tu32)(__ccgo_up(p + 4)) &= ^libc.Uint32FromInt32(SF_Distinct)
	}
	_sqlite3SelectPrep(tls, pParse, p, uintptr(0))
	if (*TParse)(unsafe.Pointer(pParse)).FnErr != 0 {
		goto select_end
	}
	/* If the SF_UFSrcCheck flag is set, then this function is being called
	 ** as part of populating the temp table for an UPDATE...FROM statement.
	 ** In this case, it is an error if the target object (pSrc->a[0]) name
	 ** or alias is duplicated within FROM clause (pSrc->a[1..n]).
	 **
	 ** Postgres disallows this case too. The reason is that some other
	 ** systems handle this case differently, and not all the same way,
	 ** which is just confusing. To avoid this, we follow PG's lead and
	 ** disallow it altogether.  */
	if (*TSelect)(unsafe.Pointer(p)).FselFlags&uint32(SF_UFSrcCheck) != 0 {
		p0 = (*TSelect)(unsafe.Pointer(p)).FpSrc + 8
		if _sameSrcAlias(tls, p0, (*TSelect)(unsafe.Pointer(p)).FpSrc) != 0 {
			if (*TSrcItem)(unsafe.Pointer(p0)).FzAlias != 0 {
				v1 = (*TSrcItem)(unsafe.Pointer(p0)).FzAlias
			} else {
				v1 = (*TTable)(unsafe.Pointer((*TSrcItem)(unsafe.Pointer(p0)).FpSTab)).FzName
			}
			_sqlite3ErrorMsg(tls, pParse, __ccgo_ts+21621, libc.VaList(bp+176, v1))
			goto select_end
		}
		/* Clear the SF_UFSrcCheck flag. The check has already been performed,
		 ** and leaving this flag set can cause errors if a compound sub-query
		 ** in p->pSrc is flattened into this query and this function called
		 ** again as part of compound SELECT processing.  */
		**(**Tu32)(__ccgo_up(p + 4)) &= ^libc.Uint32FromInt32(SF_UFSrcCheck)
	}
	if libc.Int32FromUint8((*TSelectDest)(unsafe.Pointer(pDest)).FeDest) == int32(SRT_Output) {
		_sqlite3GenerateColumnNames(tls, pParse, p)
	}
	if _sqlite3WindowRewrite(tls, pParse, p) != 0 {
		goto select_end
	}
	pTabList = (*TSelect)(unsafe.Pointer(p)).FpSrc
	isAgg = libc.BoolInt32((*TSelect)(unsafe.Pointer(p)).FselFlags&uint32(SF_Aggregate) != uint32(0))
	libc.Xmemset(tls, bp+16, 0, uint64(48))
	(**(**TSortCtx)(__ccgo_up(bp + 16))).FpOrderBy = (*TSelect)(unsafe.Pointer(p)).FpOrderBy
	/* Try to do various optimizations (flattening subqueries, and strength
	 ** reduction of join operators) in the FROM clause up into the main query
	 ** tag-select-0200
	 */
	i = 0
	for {
		if !(!((*TSelect)(unsafe.Pointer(p)).FpPrior != 0) && i < (*TSrcList)(unsafe.Pointer(pTabList)).FnSrc) {
			break
		}
		pItem = pTabList + 8 + uintptr(i)*80
		if int32(*(*uint32)(unsafe.Pointer(pItem + 24 + 4))&0x4>>2) != 0 {
			v1 = (*TSubquery)(unsafe.Pointer(*(*uintptr)(unsafe.Pointer(pItem + 72)))).FpSelect
		} else {
			v1 = uintptr(0)
		}
		pSub = v1
		pTab = (*TSrcItem)(unsafe.Pointer(pItem)).FpSTab
		/* The expander should have already created transient Table objects
		 ** even for FROM clause elements such as subqueries that do not correspond
		 ** to a real table */
		/* Try to simplify joins:
		 **
		 **      LEFT JOIN  ->  JOIN
		 **     RIGHT JOIN  ->  JOIN
		 **      FULL JOIN  ->  RIGHT JOIN
		 **
		 ** If terms of the i-th table are used in the WHERE clause in such a
		 ** way that the i-th table cannot be the NULL row of a join, then
		 ** perform the appropriate simplification. This is called
		 ** "OUTER JOIN strength reduction" in the SQLite documentation.
		 ** tag-select-0220
		 */
		if libc.Int32FromUint8((*TSrcItem)(unsafe.Pointer(pItem)).Ffg.Fjointype)&(libc.Int32FromInt32(JT_LEFT)|libc.Int32FromInt32(JT_LTORJ)) != 0 && _sqlite3ExprImpliesNonNullRow(tls, (*TSelect)(unsafe.Pointer(p)).FpWhere, (*TSrcItem)(unsafe.Pointer(pItem)).FiCursor, libc.Int32FromUint8((*TSrcItem)(unsafe.Pointer(pItem)).Ffg.Fjointype)&int32(JT_LTORJ)) != 0 && (*Tsqlite3)(unsafe.Pointer(db)).FdbOptFlags&libc.Uint32FromInt32(libc.Int32FromInt32(SQLITE_SimplifyJoin)) == uint32(0) {
			if libc.Int32FromUint8((*TSrcItem)(unsafe.Pointer(pItem)).Ffg.Fjointype)&int32(JT_LEFT) != 0 {
				if libc.Int32FromUint8((*TSrcItem)(unsafe.Pointer(pItem)).Ffg.Fjointype)&int32(JT_RIGHT) != 0 {
					v1 = pItem + 24
					*(*Tu8)(unsafe.Pointer(v1)) = Tu8(int32(*(*Tu8)(unsafe.Pointer(v1))) & ^libc.Int32FromInt32(JT_LEFT))
				} else {
					v1 = pItem + 24
					*(*Tu8)(unsafe.Pointer(v1)) = Tu8(int32(*(*Tu8)(unsafe.Pointer(v1))) & ^(libc.Int32FromInt32(JT_LEFT) | libc.Int32FromInt32(JT_OUTER)))
					_unsetJoinExpr(tls, (*TSelect)(unsafe.Pointer(p)).FpWhere, (*TSrcItem)(unsafe.Pointer(pItem)).FiCursor, 0)
				}
			}
			if libc.Int32FromUint8((*TSrcItem)(unsafe.Pointer(pItem)).Ffg.Fjointype)&int32(JT_LTORJ) != 0 {
				j = i + int32(1)
				for {
					if !(j < (*TSrcList)(unsafe.Pointer(pTabList)).FnSrc) {
						break
					}
					pI2 = pTabList + 8 + uintptr(j)*80
					if libc.Int32FromUint8((*TSrcItem)(unsafe.Pointer(pI2)).Ffg.Fjointype)&int32(JT_RIGHT) != 0 {
						if libc.Int32FromUint8((*TSrcItem)(unsafe.Pointer(pI2)).Ffg.Fjointype)&int32(JT_LEFT) != 0 {
							v1 = pI2 + 24
							*(*Tu8)(unsafe.Pointer(v1)) = Tu8(int32(*(*Tu8)(unsafe.Pointer(v1))) & ^libc.Int32FromInt32(JT_RIGHT))
						} else {
							v1 = pI2 + 24
							*(*Tu8)(unsafe.Pointer(v1)) = Tu8(int32(*(*Tu8)(unsafe.Pointer(v1))) & ^(libc.Int32FromInt32(JT_RIGHT) | libc.Int32FromInt32(JT_OUTER)))
							_unsetJoinExpr(tls, (*TSelect)(unsafe.Pointer(p)).FpWhere, (*TSrcItem)(unsafe.Pointer(pI2)).FiCursor, int32(1))
						}
					}
					goto _6
				_6:
					;
					j = j + 1
				}
				j = (*TSrcList)(unsafe.Pointer(pTabList)).FnSrc - int32(1)
				for {
					if !(j >= 0) {
						break
					}
					v1 = pTabList + 8 + uintptr(j)*80 + 24
					*(*Tu8)(unsafe.Pointer(v1)) = Tu8(int32(*(*Tu8)(unsafe.Pointer(v1))) & ^libc.Int32FromInt32(JT_LTORJ))
					if libc.Int32FromUint8((*(*TSrcItem)(unsafe.Pointer(pTabList + 8 + uintptr(j)*80))).Ffg.Fjointype)&int32(JT_RIGHT) != 0 {
						break
					}
					goto _9
				_9:
					;
					j = j - 1
				}
			}
		}
		/* No further action if this term of the FROM clause is not a subquery */
		if pSub == uintptr(0) {
			goto _2
		}
		/* Catch mismatch in the declared columns of a view and the number of
		 ** columns in the SELECT on the RHS */
		if int32((*TTable)(unsafe.Pointer(pTab)).FnCol) != (*TExprList)(unsafe.Pointer((*TSelect)(unsafe.Pointer(pSub)).FpEList)).FnExpr {
			_sqlite3ErrorMsg(tls, pParse, __ccgo_ts+21675, libc.VaList(bp+176, int32((*TTable)(unsafe.Pointer(pTab)).FnCol), (*TTable)(unsafe.Pointer(pTab)).FzName, (*TExprList)(unsafe.Pointer((*TSelect)(unsafe.Pointer(pSub)).FpEList)).FnExpr))
			goto select_end
		}
		/* Do not attempt the usual optimizations (flattening and ORDER BY
		 ** elimination) on a MATERIALIZED common table expression because
		 ** a MATERIALIZED common table expression is an optimization fence.
		 */
		if int32(*(*uint32)(unsafe.Pointer(pItem + 24 + 4))&0x200>>9) != 0 && libc.Int32FromUint8((*TCteUse)(unsafe.Pointer(*(*uintptr)(unsafe.Pointer(pItem + 56)))).FeM10d) == M10d_Yes {
			goto _2
		}
		/* Do not try to flatten an aggregate subquery.
		 **
		 ** Flattening an aggregate subquery is only possible if the outer query
		 ** is not a join.  But if the outer query is not a join, then the subquery
		 ** will be implemented as a co-routine and there is no advantage to
		 ** flattening in that case.
		 */
		if (*TSelect)(unsafe.Pointer(pSub)).FselFlags&uint32(SF_Aggregate) != uint32(0) {
			goto _2
		}
		/* tag-select-0230:
		 ** If a FROM-clause subquery has an ORDER BY clause that is not
		 ** really doing anything, then delete it now so that it does not
		 ** interfere with query flattening.  See the discussion at
		 ** https://sqlite.org/forum/forumpost/2d76f2bcf65d256a
		 **
		 ** Beware of these cases where the ORDER BY clause may not be safely
		 ** omitted:
		 **
		 **    (1)   There is also a LIMIT clause
		 **    (2)   The subquery was added to help with window-function
		 **          processing
		 **    (3)   The subquery is in the FROM clause of an UPDATE
		 **    (4)   The outer query uses an aggregate function other than
		 **          the built-in count(), min(), or max().
		 **    (5)   The ORDER BY isn't going to accomplish anything because
		 **          one of:
		 **            (a)  The outer query has a different ORDER BY clause
		 **            (b)  The subquery is part of a join
		 **          See forum post 062d576715d277c8
		 **    (6)   The subquery is not a recursive CTE.  ORDER BY has a different
		 **          meaning for recursive CTEs and this optimization does not
		 **          apply.
		 **
		 ** Also retain the ORDER BY if the OmitOrderBy optimization is disabled.
		 */
		if (*TSelect)(unsafe.Pointer(pSub)).FpOrderBy != uintptr(0) && ((*TSelect)(unsafe.Pointer(p)).FpOrderBy != uintptr(0) || (*TSrcList)(unsafe.Pointer(pTabList)).FnSrc > int32(1)) && (*TSelect)(unsafe.Pointer(pSub)).FpLimit == uintptr(0) && (*TSelect)(unsafe.Pointer(pSub)).FselFlags&libc.Uint32FromInt32(libc.Int32FromInt32(SF_OrderByReqd)|libc.Int32FromInt32(SF_Recursive)) == uint32(0) && (*TSelect)(unsafe.Pointer(p)).FselFlags&uint32(SF_OrderByReqd) == uint32(0) && (*Tsqlite3)(unsafe.Pointer(db)).FdbOptFlags&libc.Uint32FromInt32(libc.Int32FromInt32(SQLITE_OmitOrderBy)) == uint32(0) {
			_sqlite3ParserAddCleanup(tls, pParse, __ccgo_fp(_sqlite3ExprListDeleteGeneric), (*TSelect)(unsafe.Pointer(pSub)).FpOrderBy)
			(*TSelect)(unsafe.Pointer(pSub)).FpOrderBy = uintptr(0)
		}
		/* If the outer query contains a "complex" result set (that is,
		 ** if the result set of the outer query uses functions or subqueries)
		 ** and if the subquery contains an ORDER BY clause and if
		 ** it will be implemented as a co-routine, then do not flatten.  This
		 ** restriction allows SQL constructs like this:
		 **
		 **  SELECT expensive_function(x)
		 **    FROM (SELECT x FROM tab ORDER BY y LIMIT 10);
		 **
		 ** The expensive_function() is only computed on the 10 rows that
		 ** are output, rather than every row of the table.
		 **
		 ** The requirement that the outer query have a complex result set
		 ** means that flattening does occur on simpler SQL constraints without
		 ** the expensive_function() like:
		 **
		 **  SELECT x FROM (SELECT x FROM tab ORDER BY y LIMIT 10);
		 */
		if (*TSelect)(unsafe.Pointer(pSub)).FpOrderBy != uintptr(0) && i == 0 && (*TSelect)(unsafe.Pointer(p)).FselFlags&uint32(SF_ComplexResult) != uint32(0) && ((*TSrcList)(unsafe.Pointer(pTabList)).FnSrc == int32(1) || libc.Int32FromUint8((*(*TSrcItem)(unsafe.Pointer(pTabList + 8 + 1*80))).Ffg.Fjointype)&(libc.Int32FromInt32(JT_OUTER)|libc.Int32FromInt32(JT_CROSS)) != 0) {
			goto _2
		}
		/* tag-select-0240 */
		if _flattenSubquery(tls, pParse, p, i, isAgg) != 0 {
			if (*TParse)(unsafe.Pointer(pParse)).FnErr != 0 {
				goto select_end
			}
			/* This subquery can be absorbed into its parent. */
			i = -int32(1)
		}
		pTabList = (*TSelect)(unsafe.Pointer(p)).FpSrc
		if (*Tsqlite3)(unsafe.Pointer(db)).FmallocFailed != 0 {
			goto select_end
		}
		if !(libc.Int32FromUint8((*TSelectDest)(unsafe.Pointer(pDest)).FeDest) <= libc.Int32FromInt32(SRT_Fifo)) {
			(**(**TSortCtx)(__ccgo_up(bp + 16))).FpOrderBy = (*TSelect)(unsafe.Pointer(p)).FpOrderBy
		}
		goto _2
	_2:
		;
		i = i + 1
	}
	/* Handle compound SELECT statements using the separate multiSelect()
	 ** procedure.  tag-select-0300
	 */
	if (*TSelect)(unsafe.Pointer(p)).FpPrior != 0 {
		rc = _multiSelect(tls, pParse, p, pDest)
		if (*TSelect)(unsafe.Pointer(p)).FpNext == uintptr(0) {
			_sqlite3VdbeExplainPop(tls, pParse)
		}
		return rc
	}
	/* If there may be an "EXISTS (SELECT ...)" in the WHERE clause, attempt
	 ** to change it into a join.  */
	if int32(Tbft(*(*uint16)(unsafe.Pointer(pParse + 40))&0x10>>4)) != 0 && (*Tsqlite3)(unsafe.Pointer(db)).FdbOptFlags&libc.Uint32FromInt32(libc.Int32FromInt32(SQLITE_ExistsToJoin)) == uint32(0) {
		_existsToJoin(tls, pParse, p, (*TSelect)(unsafe.Pointer(p)).FpWhere)
		pTabList = (*TSelect)(unsafe.Pointer(p)).FpSrc
	}
	/* Do the WHERE-clause constant propagation optimization if this is
	 ** a join.  No need to spend time on this operation for non-join queries
	 ** as the equivalent optimization will be handled by query planner in
	 ** sqlite3WhereBegin().  tag-select-0330
	 */
	if (*TSelect)(unsafe.Pointer(p)).FpWhere != uintptr(0) && libc.Int32FromUint8((*TExpr)(unsafe.Pointer((*TSelect)(unsafe.Pointer(p)).FpWhere)).Fop) == int32(TK_AND) && (*Tsqlite3)(unsafe.Pointer(db)).FdbOptFlags&libc.Uint32FromInt32(libc.Int32FromInt32(SQLITE_PropagateConst)) == uint32(0) && _propagateConstants(tls, pParse, p) != 0 {
	} else {
	}
	/* tag-select-0350 */
	if (*Tsqlite3)(unsafe.Pointer(db)).FdbOptFlags&libc.Uint32FromInt32(libc.Int32FromInt32(SQLITE_QueryFlattener)|libc.Int32FromInt32(SQLITE_CountOfView)) == uint32(0) && _countOfViewOptimization(tls, pParse, p) != 0 {
		if (*Tsqlite3)(unsafe.Pointer(db)).FmallocFailed != 0 {
			goto select_end
		}
		pTabList = (*TSelect)(unsafe.Pointer(p)).FpSrc
	}
	/* Loop over all terms in the FROM clause and do two things for each term:
	 **
	 **   (1) Authorize unreferenced tables
	 **   (2) Generate code for all sub-queries
	 **
	 ** tag-select-0400
	 */
	i = 0
	for {
		if !(i < (*TSrcList)(unsafe.Pointer(pTabList)).FnSrc) {
			break
		}
		pItem1 = pTabList + 8 + uintptr(i)*80
		/* Authorized unreferenced tables.  tag-select-0410
		 **
		 ** Issue SQLITE_READ authorizations with a fake column name for any
		 ** tables that are referenced but from which no values are extracted.
		 ** Examples of where these kinds of null SQLITE_READ authorizations
		 ** would occur:
		 **
		 **     SELECT count(*) FROM t1;   -- SQLITE_READ t1.""
		 **     SELECT t1.* FROM t1, t2;   -- SQLITE_READ t2.""
		 **
		 ** The fake column name is an empty string.  It is possible for a table to
		 ** have a column named by the empty string, in which case there is no way to
		 ** distinguish between an unreferenced table and an actual reference to the
		 ** "" column. The original design was for the fake column name to be a NULL,
		 ** which would be unambiguous.  But legacy authorization callbacks might
		 ** assume the column name is non-NULL and segfault.  The use of an empty
		 ** string for the fake column name seems safer.
		 */
		if (*TSrcItem)(unsafe.Pointer(pItem1)).FcolUsed == uint64(0) && (*TSrcItem)(unsafe.Pointer(pItem1)).FzName != uintptr(0) {
			if int32(*(*uint32)(unsafe.Pointer(pItem1 + 24 + 4))&0x10000>>16) != 0 {
				iDb = _sqlite3SchemaToIndex(tls, (*TParse)(unsafe.Pointer(pParse)).Fdb, *(*uintptr)(unsafe.Pointer(pItem1 + 72)))
				zDb = (**(**TDb)(__ccgo_up((*Tsqlite3)(unsafe.Pointer(db)).FaDb + uintptr(iDb)*32))).FzDbSName
			} else {
				if int32(*(*uint32)(unsafe.Pointer(pItem1 + 24 + 4))&0x4>>2) != 0 {
					zDb = uintptr(0)
				} else {
					zDb = *(*uintptr)(unsafe.Pointer(pItem1 + 72))
				}
			}
			_sqlite3AuthCheck(tls, pParse, int32(SQLITE_READ), (*TSrcItem)(unsafe.Pointer(pItem1)).FzName, __ccgo_ts+1693, zDb)
		}
		/* Generate code for all sub-queries in the FROM clause
		 */
		if int32(*(*uint32)(unsafe.Pointer(pItem1 + 24 + 4))&0x4>>2) == 0 {
			goto _11
		}
		pSubq = *(*uintptr)(unsafe.Pointer(pItem1 + 72))
		pSub1 = (*TSubquery)(unsafe.Pointer(pSubq)).FpSelect
		/* The code for a subquery should only be generated once. */
		if (*TSubquery)(unsafe.Pointer(pSubq)).FaddrFillSub != 0 {
			goto _11
		}
		/* Increment Parse.nHeight by the height of the largest expression
		 ** tree referred to by this, the parent select. The child select
		 ** may contain expression trees of at most
		 ** (SQLITE_MAX_EXPR_DEPTH-Parse.nHeight) height. This is a bit
		 ** more conservative than necessary, but much easier than enforcing
		 ** an exact limit.
		 */
		**(**int32)(__ccgo_up(pParse + 316)) += _sqlite3SelectExprHeight(tls, p)
		/* Make copies of constant WHERE-clause terms in the outer query down
		 ** inside the subquery.  This can help the subquery to run more efficiently.
		 ** This is the "predicate push-down optimization".  tag-select-0420
		 */
		if (*Tsqlite3)(unsafe.Pointer(db)).FdbOptFlags&libc.Uint32FromInt32(libc.Int32FromInt32(SQLITE_PushDown)) == uint32(0) && (int32(*(*uint32)(unsafe.Pointer(pItem1 + 24 + 4))&0x200>>9) == 0 || libc.Int32FromUint8((*TCteUse)(unsafe.Pointer(*(*uintptr)(unsafe.Pointer(pItem1 + 56)))).FeM10d) != M10d_Yes && (*TCteUse)(unsafe.Pointer(*(*uintptr)(unsafe.Pointer(pItem1 + 56)))).FnUse < int32(2)) && _pushDownWhereTerms(tls, pParse, pSub1, (*TSelect)(unsafe.Pointer(p)).FpWhere, pTabList, i) != 0 {
		} else {
		}
		/* Convert unused result columns of the subquery into simple NULL
		 ** expressions, to avoid unneeded searching and computation.
		 ** tag-select-0440
		 */
		if (*Tsqlite3)(unsafe.Pointer(db)).FdbOptFlags&libc.Uint32FromInt32(libc.Int32FromInt32(SQLITE_NullUnusedCols)) == uint32(0) && _disableUnusedSubqueryResultColumns(tls, pItem1) != 0 {
		}
		zSavedAuthContext = (*TParse)(unsafe.Pointer(pParse)).FzAuthContext
		(*TParse)(unsafe.Pointer(pParse)).FzAuthContext = (*TSrcItem)(unsafe.Pointer(pItem1)).FzName
		/* Generate byte-code to implement the subquery  tag-select-0480
		 */
		if _fromClauseTermCanBeCoroutine(tls, pParse, pTabList, i, libc.Int32FromUint32((*TSelect)(unsafe.Pointer(p)).FselFlags)) != 0 {
			/* Implement a co-routine that will return a single row of the result
			 ** set on each invocation.  tag-select-0482
			 */
			addrTop = _sqlite3VdbeCurrentAddr(tls, v) + int32(1)
			v1 = pParse + 60
			*(*int32)(unsafe.Pointer(v1)) = *(*int32)(unsafe.Pointer(v1)) + 1
			v12 = *(*int32)(unsafe.Pointer(v1))
			(*TSubquery)(unsafe.Pointer(pSubq)).FregReturn = v12
			_sqlite3VdbeAddOp3(tls, v, int32(OP_InitCoroutine), (*TSubquery)(unsafe.Pointer(pSubq)).FregReturn, 0, addrTop)
			(*TSubquery)(unsafe.Pointer(pSubq)).FaddrFillSub = addrTop
			_sqlite3SelectDestInit(tls, bp+72, int32(SRT_Coroutine), (*TSubquery)(unsafe.Pointer(pSubq)).FregReturn)
			_sqlite3VdbeExplain(tls, pParse, uint8(1), __ccgo_ts+21715, libc.VaList(bp+176, pItem1))
			_sqlite3Select(tls, pParse, pSub1, bp+72)
			(*TTable)(unsafe.Pointer((*TSrcItem)(unsafe.Pointer(pItem1)).FpSTab)).FnRowLogEst = (*TSelect)(unsafe.Pointer(pSub1)).FnSelectRow
			libc.SetBitFieldPtr32Uint32(pItem1+24+4, libc.Uint32FromInt32(1), 6, 0x40)
			(*TSubquery)(unsafe.Pointer(pSubq)).FregResult = (**(**TSelectDest)(__ccgo_up(bp + 72))).FiSdst
			_sqlite3VdbeEndCoroutine(tls, v, (*TSubquery)(unsafe.Pointer(pSubq)).FregReturn)
			_sqlite3VdbeJumpHere(tls, v, addrTop-int32(1))
			_sqlite3ClearTempRegCache(tls, pParse)
		} else {
			if int32(*(*uint32)(unsafe.Pointer(pItem1 + 24 + 4))&0x200>>9) != 0 && (*TCteUse)(unsafe.Pointer(*(*uintptr)(unsafe.Pointer(pItem1 + 56)))).FaddrM9e > 0 {
				/* This is a CTE for which materialization code has already been
				 ** generated.  Invoke the subroutine to compute the materialization,
				 ** then make the pItem->iCursor be a copy of the ephemeral table that
				 ** holds the result of the materialization. tag-select-0484 */
				pCteUse = *(*uintptr)(unsafe.Pointer(pItem1 + 56))
				_sqlite3VdbeAddOp2(tls, v, int32(OP_Gosub), (*TCteUse)(unsafe.Pointer(pCteUse)).FregRtn, (*TCteUse)(unsafe.Pointer(pCteUse)).FaddrM9e)
				if (*TSrcItem)(unsafe.Pointer(pItem1)).FiCursor != (*TCteUse)(unsafe.Pointer(pCteUse)).FiCur {
					_sqlite3VdbeAddOp2(tls, v, int32(OP_OpenDup), (*TSrcItem)(unsafe.Pointer(pItem1)).FiCursor, (*TCteUse)(unsafe.Pointer(pCteUse)).FiCur)
				}
				(*TSelect)(unsafe.Pointer(pSub1)).FnSelectRow = (*TCteUse)(unsafe.Pointer(pCteUse)).FnRowEst
			} else {
				v1 = _isSelfJoinView(tls, pTabList, pItem1, 0, i)
				pPrior = v1
				if v1 != uintptr(0) {
					pPriorSubq = *(*uintptr)(unsafe.Pointer(pPrior + 72))
					if (*TSubquery)(unsafe.Pointer(pPriorSubq)).FaddrFillSub != 0 {
						_sqlite3VdbeAddOp2(tls, v, int32(OP_Gosub), (*TSubquery)(unsafe.Pointer(pPriorSubq)).FregReturn, (*TSubquery)(unsafe.Pointer(pPriorSubq)).FaddrFillSub)
					}
					_sqlite3VdbeAddOp2(tls, v, int32(OP_OpenDup), (*TSrcItem)(unsafe.Pointer(pItem1)).FiCursor, (*TSrcItem)(unsafe.Pointer(pPrior)).FiCursor)
					(*TSelect)(unsafe.Pointer(pSub1)).FnSelectRow = (*TSelect)(unsafe.Pointer((*TSubquery)(unsafe.Pointer(pPriorSubq)).FpSelect)).FnSelectRow
				} else {
					onceAddr = 0
					v1 = pParse + 60
					*(*int32)(unsafe.Pointer(v1)) = *(*int32)(unsafe.Pointer(v1)) + 1
					v12 = *(*int32)(unsafe.Pointer(v1))
					(*TSubquery)(unsafe.Pointer(pSubq)).FregReturn = v12
					topAddr = _sqlite3VdbeAddOp0(tls, v, int32(OP_Goto))
					(*TSubquery)(unsafe.Pointer(pSubq)).FaddrFillSub = topAddr + int32(1)
					libc.SetBitFieldPtr32Uint32(pItem1+24+4, libc.Uint32FromInt32(1), 5, 0x20)
					if int32(*(*uint32)(unsafe.Pointer(pItem1 + 24 + 4))&0x10>>4) == 0 {
						/* If the subquery is not correlated and if we are not inside of
						 ** a trigger, then we only need to compute the value of the subquery
						 ** once. */
						onceAddr = _sqlite3VdbeAddOp0(tls, v, int32(OP_Once))
					} else {
					}
					_sqlite3SelectDestInit(tls, bp+72, int32(SRT_EphemTab), (*TSrcItem)(unsafe.Pointer(pItem1)).FiCursor)
					_sqlite3VdbeExplain(tls, pParse, uint8(1), __ccgo_ts+21730, libc.VaList(bp+176, pItem1))
					_sqlite3Select(tls, pParse, pSub1, bp+72)
					(*TTable)(unsafe.Pointer((*TSrcItem)(unsafe.Pointer(pItem1)).FpSTab)).FnRowLogEst = (*TSelect)(unsafe.Pointer(pSub1)).FnSelectRow
					if onceAddr != 0 {
						_sqlite3VdbeJumpHere(tls, v, onceAddr)
					}
					_sqlite3VdbeAddOp2(tls, v, int32(OP_Return), (*TSubquery)(unsafe.Pointer(pSubq)).FregReturn, topAddr+int32(1))
					_sqlite3VdbeJumpHere(tls, v, topAddr)
					_sqlite3ClearTempRegCache(tls, pParse)
					if int32(*(*uint32)(unsafe.Pointer(pItem1 + 24 + 4))&0x200>>9) != 0 && int32(*(*uint32)(unsafe.Pointer(pItem1 + 24 + 4))&0x10>>4) == 0 {
						pCteUse1 = *(*uintptr)(unsafe.Pointer(pItem1 + 56))
						(*TCteUse)(unsafe.Pointer(pCteUse1)).FaddrM9e = (*TSubquery)(unsafe.Pointer(pSubq)).FaddrFillSub
						(*TCteUse)(unsafe.Pointer(pCteUse1)).FregRtn = (*TSubquery)(unsafe.Pointer(pSubq)).FregReturn
						(*TCteUse)(unsafe.Pointer(pCteUse1)).FiCur = (*TSrcItem)(unsafe.Pointer(pItem1)).FiCursor
						(*TCteUse)(unsafe.Pointer(pCteUse1)).FnRowEst = (*TSelect)(unsafe.Pointer(pSub1)).FnSelectRow
					}
				}
			}
		}
		if (*Tsqlite3)(unsafe.Pointer(db)).FmallocFailed != 0 {
			goto select_end
		}
		**(**int32)(__ccgo_up(pParse + 316)) -= _sqlite3SelectExprHeight(tls, p)
		(*TParse)(unsafe.Pointer(pParse)).FzAuthContext = zSavedAuthContext
		goto _11
	_11:
		;
		i = i + 1
	}
	/* Various elements of the SELECT copied into local variables for
	 ** convenience */
	pEList = (*TSelect)(unsafe.Pointer(p)).FpEList
	pWhere = (*TSelect)(unsafe.Pointer(p)).FpWhere
	pGroupBy = (*TSelect)(unsafe.Pointer(p)).FpGroupBy
	pHaving = (*TSelect)(unsafe.Pointer(p)).FpHaving
	(**(**TDistinctCtx)(__ccgo_up(bp))).FisTnct = libc.BoolUint8((*TSelect)(unsafe.Pointer(p)).FselFlags&uint32(SF_Distinct) != uint32(0))
	/* tag-select-0500
	 **
	 ** If the query is DISTINCT with an ORDER BY but is not an aggregate, and
	 ** if the select-list is the same as the ORDER BY list, then this query
	 ** can be rewritten as a GROUP BY. In other words, this:
	 **
	 **     SELECT DISTINCT xyz FROM ... ORDER BY xyz
	 **
	 ** is transformed to:
	 **
	 **     SELECT xyz FROM ... GROUP BY xyz ORDER BY xyz
	 **
	 ** The second form is preferred as a single index (or temp-table) may be
	 ** used for both the ORDER BY and DISTINCT processing. As originally
	 ** written the query must use a temp-table for at least one of the ORDER
	 ** BY and DISTINCT, and an index or separate temp-table for the other.
	 */
	if (*TSelect)(unsafe.Pointer(p)).FselFlags&libc.Uint32FromInt32(libc.Int32FromInt32(SF_Distinct)|libc.Int32FromInt32(SF_Aggregate)) == uint32(SF_Distinct) && _sqlite3CopySortOrder(tls, pEList, (**(**TSortCtx)(__ccgo_up(bp + 16))).FpOrderBy) != 0 && _sqlite3ExprListCompare(tls, pEList, (**(**TSortCtx)(__ccgo_up(bp + 16))).FpOrderBy, -int32(1)) == 0 && (*Tsqlite3)(unsafe.Pointer(db)).FdbOptFlags&libc.Uint32FromInt32(libc.Int32FromInt32(SQLITE_GroupByOrder)) == uint32(0) && (*TSelect)(unsafe.Pointer(p)).FpWin == uintptr(0) {
		**(**Tu32)(__ccgo_up(p + 4)) &= ^libc.Uint32FromInt32(SF_Distinct)
		v1 = _sqlite3ExprListDup(tls, db, pEList, 0)
		(*TSelect)(unsafe.Pointer(p)).FpGroupBy = v1
		pGroupBy = v1
		if pGroupBy != 0 {
			i = 0
			for {
				if !(i < (*TExprList)(unsafe.Pointer(pGroupBy)).FnExpr) {
					break
				}
				*(*Tu16)(unsafe.Pointer(pGroupBy + 8 + uintptr(i)*32 + 24)) = libc.Uint16FromInt32(i + int32(1))
				goto _18
			_18:
				;
				i = i + 1
			}
		}
		**(**Tu32)(__ccgo_up(p + 4)) |= uint32(SF_Aggregate)
		/* Notice that even thought SF_Distinct has been cleared from p->selFlags,
		 ** the sDistinct.isTnct is still set.  Hence, isTnct represents the
		 ** original setting of the SF_Distinct flag, not the current setting */
		(**(**TDistinctCtx)(__ccgo_up(bp))).FisTnct = uint8(2)
	}
	/* If there is an ORDER BY clause, then create an ephemeral index to
	 ** do the sorting.  But this sorting ephemeral index might end up
	 ** being unused if the data can be extracted in pre-sorted order.
	 ** If that is the case, then the OP_OpenEphemeral instruction will be
	 ** changed to an OP_Noop once we figure out that the sorting index is
	 ** not needed.  The sSort.addrSortIndex variable is used to facilitate
	 ** that change.  tag-select-0600
	 */
	if (**(**TSortCtx)(__ccgo_up(bp + 16))).FpOrderBy != 0 {
		pKeyInfo = _sqlite3KeyInfoFromExprList(tls, pParse, (**(**TSortCtx)(__ccgo_up(bp + 16))).FpOrderBy, 0, (*TExprList)(unsafe.Pointer(pEList)).FnExpr)
		v1 = pParse + 56
		v12 = *(*int32)(unsafe.Pointer(v1))
		*(*int32)(unsafe.Pointer(v1)) = *(*int32)(unsafe.Pointer(v1)) + 1
		(**(**TSortCtx)(__ccgo_up(bp + 16))).FiECursor = v12
		(**(**TSortCtx)(__ccgo_up(bp + 16))).FaddrSortIndex = _sqlite3VdbeAddOp4(tls, v, int32(OP_OpenEphemeral), (**(**TSortCtx)(__ccgo_up(bp + 16))).FiECursor, (*TExprList)(unsafe.Pointer((**(**TSortCtx)(__ccgo_up(bp + 16))).FpOrderBy)).FnExpr+int32(1)+(*TExprList)(unsafe.Pointer(pEList)).FnExpr, 0, pKeyInfo, -int32(9))
	} else {
		(**(**TSortCtx)(__ccgo_up(bp + 16))).FaddrSortIndex = -int32(1)
	}
	/* If the output is destined for a temporary table, open that table.
	 ** tag-select-0630
	 */
	if libc.Int32FromUint8((*TSelectDest)(unsafe.Pointer(pDest)).FeDest) == int32(SRT_EphemTab) {
		_sqlite3VdbeAddOp2(tls, v, int32(OP_OpenEphemeral), (*TSelectDest)(unsafe.Pointer(pDest)).FiSDParm, (*TExprList)(unsafe.Pointer(pEList)).FnExpr)
		if (*TSelect)(unsafe.Pointer(p)).FselFlags&uint32(SF_NestedFrom) != 0 {
			ii = (*TExprList)(unsafe.Pointer(pEList)).FnExpr - int32(1)
			for {
				if !(ii > 0 && int32(uint32(*(*uint16)(unsafe.Pointer(pEList + 8 + uintptr(ii)*32 + 16 + 4))&0x40>>6)) == 0) {
					break
				}
				_sqlite3ExprDelete(tls, db, (*(*TExprList_item)(unsafe.Pointer(pEList + 8 + uintptr(ii)*32))).FpExpr)
				_sqlite3DbFree(tls, db, (*(*TExprList_item)(unsafe.Pointer(pEList + 8 + uintptr(ii)*32))).FzEName)
				(*TExprList)(unsafe.Pointer(pEList)).FnExpr = (*TExprList)(unsafe.Pointer(pEList)).FnExpr - 1
				goto _21
			_21:
				;
				ii = ii - 1
			}
			ii = 0
			for {
				if !(ii < (*TExprList)(unsafe.Pointer(pEList)).FnExpr) {
					break
				}
				if int32(uint32(*(*uint16)(unsafe.Pointer(pEList + 8 + uintptr(ii)*32 + 16 + 4))&0x40>>6)) == 0 {
					(*TExpr)(unsafe.Pointer((*(*TExprList_item)(unsafe.Pointer(pEList + 8 + uintptr(ii)*32))).FpExpr)).Fop = uint8(TK_NULL)
				}
				goto _22
			_22:
				;
				ii = ii + 1
			}
		}
	}
	/* Set the limiter.  tag-select-0650
	 */
	iEnd = _sqlite3VdbeMakeLabel(tls, pParse)
	if (*TSelect)(unsafe.Pointer(p)).FselFlags&uint32(SF_FixedLimit) == uint32(0) {
		(*TSelect)(unsafe.Pointer(p)).FnSelectRow = int16(320) /* 4 billion rows */
	}
	if (*TSelect)(unsafe.Pointer(p)).FpLimit != 0 {
		_computeLimitRegisters(tls, pParse, p, iEnd)
	}
	if (*TSelect)(unsafe.Pointer(p)).FiLimit == 0 && (**(**TSortCtx)(__ccgo_up(bp + 16))).FaddrSortIndex >= 0 {
		_sqlite3VdbeChangeOpcode(tls, v, (**(**TSortCtx)(__ccgo_up(bp + 16))).FaddrSortIndex, uint8(OP_SorterOpen))
		v1 = bp + 16 + 36
		*(*Tu8)(unsafe.Pointer(v1)) = Tu8(int32(*(*Tu8)(unsafe.Pointer(v1))) | libc.Int32FromInt32(SORTFLAG_UseSorter))
	}
	/* Open an ephemeral index to use for the distinct set. tag-select-0680
	 */
	if (*TSelect)(unsafe.Pointer(p)).FselFlags&uint32(SF_Distinct) != 0 {
		v1 = pParse + 56
		v12 = *(*int32)(unsafe.Pointer(v1))
		*(*int32)(unsafe.Pointer(v1)) = *(*int32)(unsafe.Pointer(v1)) + 1
		(**(**TDistinctCtx)(__ccgo_up(bp))).FtabTnct = v12
		(**(**TDistinctCtx)(__ccgo_up(bp))).FaddrTnct = _sqlite3VdbeAddOp4(tls, v, int32(OP_OpenEphemeral), (**(**TDistinctCtx)(__ccgo_up(bp))).FtabTnct, 0, 0, _sqlite3KeyInfoFromExprList(tls, pParse, (*TSelect)(unsafe.Pointer(p)).FpEList, 0, 0), -int32(9))
		_sqlite3VdbeChangeP5(tls, v, uint16(BTREE_UNORDERED))
		(**(**TDistinctCtx)(__ccgo_up(bp))).FeTnctType = uint8(WHERE_DISTINCT_UNORDERED)
	} else {
		(**(**TDistinctCtx)(__ccgo_up(bp))).FeTnctType = uint8(WHERE_DISTINCT_NOOP)
	}
	if !(isAgg != 0) && pGroupBy == uintptr(0) {
		if (**(**TDistinctCtx)(__ccgo_up(bp))).FisTnct != 0 {
			v12 = int32(WHERE_WANT_DISTINCT)
		} else {
			v12 = 0
		}
		/* No aggregate functions and no GROUP BY clause.  tag-select-0700 */
		wctrlFlags = uint16(libc.Uint32FromInt32(v12) | (*TSelect)(unsafe.Pointer(p)).FselFlags&uint32(SF_FixedLimit))
		pWin = (*TSelect)(unsafe.Pointer(p)).FpWin /* Main window object (or NULL) */
		if pWin != 0 {
			_sqlite3WindowCodeInit(tls, pParse, p)
		}
		/* Begin the database scan. */
		pWInfo = _sqlite3WhereBegin(tls, pParse, pTabList, pWhere, (**(**TSortCtx)(__ccgo_up(bp + 16))).FpOrderBy, (*TSelect)(unsafe.Pointer(p)).FpEList, p, wctrlFlags, int32((*TSelect)(unsafe.Pointer(p)).FnSelectRow))
		if pWInfo == uintptr(0) {
			goto select_end
		}
		if int32(_sqlite3WhereOutputRowCount(tls, pWInfo)) < int32((*TSelect)(unsafe.Pointer(p)).FnSelectRow) {
			(*TSelect)(unsafe.Pointer(p)).FnSelectRow = _sqlite3WhereOutputRowCount(tls, pWInfo)
			if libc.Int32FromUint8((*TSelectDest)(unsafe.Pointer(pDest)).FeDest) <= int32(SRT_DistQueue) && libc.Int32FromUint8((*TSelectDest)(unsafe.Pointer(pDest)).FeDest) >= int32(SRT_DistFifo) {
				/* TUNING: For a UNION CTE, because UNION is implies DISTINCT,
				 ** reduce the estimated output row count by 8 (LogEst 30).
				 ** Search for tag-20250414a to see other cases */
				v1 = p + 2
				*(*TLogEst)(unsafe.Pointer(v1)) = TLogEst(int32(*(*TLogEst)(unsafe.Pointer(v1))) - libc.Int32FromInt32(30))
			}
		}
		if (**(**TDistinctCtx)(__ccgo_up(bp))).FisTnct != 0 && _sqlite3WhereIsDistinct(tls, pWInfo) != 0 {
			(**(**TDistinctCtx)(__ccgo_up(bp))).FeTnctType = libc.Uint8FromInt32(_sqlite3WhereIsDistinct(tls, pWInfo))
		}
		if (**(**TSortCtx)(__ccgo_up(bp + 16))).FpOrderBy != 0 {
			(**(**TSortCtx)(__ccgo_up(bp + 16))).FnOBSat = _sqlite3WhereIsOrdered(tls, pWInfo)
			(**(**TSortCtx)(__ccgo_up(bp + 16))).FlabelOBLopt = _sqlite3WhereOrderByLimitOptLabel(tls, pWInfo)
			if (**(**TSortCtx)(__ccgo_up(bp + 16))).FnOBSat == (*TExprList)(unsafe.Pointer((**(**TSortCtx)(__ccgo_up(bp + 16))).FpOrderBy)).FnExpr {
				(**(**TSortCtx)(__ccgo_up(bp + 16))).FpOrderBy = uintptr(0)
			}
		}
		/* If sorting index that was created by a prior OP_OpenEphemeral
		 ** instruction ended up not being needed, then change the OP_OpenEphemeral
		 ** into an OP_Noop.
		 */
		if (**(**TSortCtx)(__ccgo_up(bp + 16))).FaddrSortIndex >= 0 && (**(**TSortCtx)(__ccgo_up(bp + 16))).FpOrderBy == uintptr(0) {
			_sqlite3VdbeChangeToNoop(tls, v, (**(**TSortCtx)(__ccgo_up(bp + 16))).FaddrSortIndex)
		}
		if pWin != 0 {
			addrGosub = _sqlite3VdbeMakeLabel(tls, pParse)
			iCont = _sqlite3VdbeMakeLabel(tls, pParse)
			iBreak = _sqlite3VdbeMakeLabel(tls, pParse)
			v1 = pParse + 60
			*(*int32)(unsafe.Pointer(v1)) = *(*int32)(unsafe.Pointer(v1)) + 1
			v12 = *(*int32)(unsafe.Pointer(v1))
			regGosub = v12
			_sqlite3WindowCodeStep(tls, pParse, p, pWInfo, regGosub, addrGosub)
			_sqlite3VdbeAddOp2(tls, v, int32(OP_Goto), 0, iBreak)
			_sqlite3VdbeResolveLabel(tls, v, addrGosub)
			(**(**TSortCtx)(__ccgo_up(bp + 16))).FlabelOBLopt = 0
			_selectInnerLoop(tls, pParse, p, -int32(1), bp+16, bp, pDest, iCont, iBreak)
			_sqlite3VdbeResolveLabel(tls, v, iCont)
			_sqlite3VdbeAddOp1(tls, v, int32(OP_Return), regGosub)
			_sqlite3VdbeResolveLabel(tls, v, iBreak)
		} else {
			/* Use the standard inner loop. */
			_selectInnerLoop(tls, pParse, p, -int32(1), bp+16, bp, pDest, _sqlite3WhereContinueLabel(tls, pWInfo), _sqlite3WhereBreakLabel(tls, pWInfo))
			/* End the database scan loop.
			 */
			_sqlite3WhereEnd(tls, pWInfo)
		}
	} else { /* End of processing for this SELECT */
		sortPTab = 0   /* Pseudotable used to decode sorting results */
		sortOut = 0    /* Output register from the sorter */
		orderByGrp = 0 /* True if the GROUP BY and ORDER BY are the same */
		/* Remove any and all aliases between the result set and the
		 ** GROUP BY clause.
		 */
		if pGroupBy != 0 { /* For looping over expression in a list */
			k = (*TExprList)(unsafe.Pointer((*TSelect)(unsafe.Pointer(p)).FpEList)).FnExpr
			pItem2 = (*TSelect)(unsafe.Pointer(p)).FpEList + 8
			for {
				if !(k > 0) {
					break
				}
				(*(*struct {
					FiOrderByCol Tu16
					FiAlias      Tu16
				})(unsafe.Pointer(pItem2 + 24))).FiAlias = uint16(0)
				goto _30
			_30:
				;
				k = k - 1
				pItem2 += 32
			}
			k = (*TExprList)(unsafe.Pointer(pGroupBy)).FnExpr
			pItem2 = pGroupBy + 8
			for {
				if !(k > 0) {
					break
				}
				(*(*struct {
					FiOrderByCol Tu16
					FiAlias      Tu16
				})(unsafe.Pointer(pItem2 + 24))).FiAlias = uint16(0)
				goto _31
			_31:
				;
				k = k - 1
				pItem2 += 32
			}
			if int32((*TSelect)(unsafe.Pointer(p)).FnSelectRow) > int32(66) {
				(*TSelect)(unsafe.Pointer(p)).FnSelectRow = int16(66)
			}
			/* If there is both a GROUP BY and an ORDER BY clause and they are
			 ** identical, then it may be possible to disable the ORDER BY clause
			 ** on the grounds that the GROUP BY will cause elements to come out
			 ** in the correct order. It also may not - the GROUP BY might use a
			 ** database index that causes rows to be grouped together as required
			 ** but not actually sorted. Either way, record the fact that the
			 ** ORDER BY and GROUP BY clauses are the same by setting the orderByGrp
			 ** variable.  */
			if _sqlite3CopySortOrder(tls, pGroupBy, (**(**TSortCtx)(__ccgo_up(bp + 16))).FpOrderBy) != 0 && _sqlite3ExprListCompare(tls, pGroupBy, (**(**TSortCtx)(__ccgo_up(bp + 16))).FpOrderBy, -int32(1)) == 0 {
				orderByGrp = int32(1)
			}
		} else {
			(*TSelect)(unsafe.Pointer(p)).FnSelectRow = 0
		}
		/* Create a label to jump to when we want to abort the query */
		addrEnd = _sqlite3VdbeMakeLabel(tls, pParse)
		/* Convert TK_COLUMN nodes into TK_AGG_COLUMN and make entries in
		 ** sAggInfo for all TK_AGG_FUNCTION nodes in expressions of the
		 ** SELECT statement.
		 */
		pAggInfo = _sqlite3DbMallocZero(tls, db, uint64(64))
		if pAggInfo != 0 {
			_sqlite3ParserAddCleanup(tls, pParse, __ccgo_fp(_agginfoFree), pAggInfo)
		}
		if (*Tsqlite3)(unsafe.Pointer(db)).FmallocFailed != 0 {
			goto select_end
		}
		(*TAggInfo)(unsafe.Pointer(pAggInfo)).FselId = (*TSelect)(unsafe.Pointer(p)).FselId
		libc.Xmemset(tls, bp+112, 0, uint64(56))
		(**(**TNameContext)(__ccgo_up(bp + 112))).FpParse = pParse
		(**(**TNameContext)(__ccgo_up(bp + 112))).FpSrcList = pTabList
		*(*uintptr)(unsafe.Pointer(bp + 112 + 16)) = pAggInfo
		if pGroupBy != 0 {
			v12 = (*TExprList)(unsafe.Pointer(pGroupBy)).FnExpr
		} else {
			v12 = 0
		}
		(*TAggInfo)(unsafe.Pointer(pAggInfo)).FnSortingColumn = libc.Uint32FromInt32(v12)
		(*TAggInfo)(unsafe.Pointer(pAggInfo)).FpGroupBy = pGroupBy
		_sqlite3ExprAnalyzeAggList(tls, bp+112, pEList)
		_sqlite3ExprAnalyzeAggList(tls, bp+112, (**(**TSortCtx)(__ccgo_up(bp + 16))).FpOrderBy)
		if pHaving != 0 {
			if pGroupBy != 0 {
				_havingToWhere(tls, pParse, p)
				pWhere = (*TSelect)(unsafe.Pointer(p)).FpWhere
			}
			_sqlite3ExprAnalyzeAggregates(tls, bp+112, pHaving)
		}
		(*TAggInfo)(unsafe.Pointer(pAggInfo)).FnAccumulator = (*TAggInfo)(unsafe.Pointer(pAggInfo)).FnColumn
		if (*TSelect)(unsafe.Pointer(p)).FpGroupBy == uintptr(0) && (*TSelect)(unsafe.Pointer(p)).FpHaving == uintptr(0) && (*TAggInfo)(unsafe.Pointer(pAggInfo)).FnFunc == int32(1) {
			minMaxFlag = _minMaxQuery(tls, db, (**(**TAggInfo_func)(__ccgo_up((*TAggInfo)(unsafe.Pointer(pAggInfo)).FaFunc))).FpFExpr, bp+64)
		} else {
			minMaxFlag = uint8(WHERE_ORDERBY_NORMAL)
		}
		_analyzeAggFuncArgs(tls, pAggInfo, bp+112)
		if (*Tsqlite3)(unsafe.Pointer(db)).FmallocFailed != 0 {
			goto select_end
		}
		/* Processing for aggregates with GROUP BY is very different and
		 ** much more complex than aggregates without a GROUP BY.  tag-select-0810
		 */
		if pGroupBy != 0 { /* Return address register for reset subroutine */
			pDistinct = uintptr(0)
			distFlag = uint16(0)
			eDist = WHERE_DISTINCT_NOOP
			if (*TAggInfo)(unsafe.Pointer(pAggInfo)).FnFunc == int32(1) && (**(**TAggInfo_func)(__ccgo_up((*TAggInfo)(unsafe.Pointer(pAggInfo)).FaFunc))).FiDistinct >= 0 && (**(**TAggInfo_func)(__ccgo_up((*TAggInfo)(unsafe.Pointer(pAggInfo)).FaFunc))).FpFExpr != uintptr(0) && (*TExpr)(unsafe.Pointer((**(**TAggInfo_func)(__ccgo_up((*TAggInfo)(unsafe.Pointer(pAggInfo)).FaFunc))).FpFExpr)).Fflags&uint32(EP_xIsSelect) == uint32(0) && *(*uintptr)(unsafe.Pointer((**(**TAggInfo_func)(__ccgo_up((*TAggInfo)(unsafe.Pointer(pAggInfo)).FaFunc))).FpFExpr + 32)) != uintptr(0) {
				pExpr = (*(*TExprList_item)(unsafe.Pointer(*(*uintptr)(unsafe.Pointer((**(**TAggInfo_func)(__ccgo_up((*TAggInfo)(unsafe.Pointer(pAggInfo)).FaFunc))).FpFExpr + 32)) + 8))).FpExpr
				pExpr = _sqlite3ExprDup(tls, db, pExpr, 0)
				pDistinct = _sqlite3ExprListDup(tls, db, pGroupBy, 0)
				pDistinct = _sqlite3ExprListAppend(tls, pParse, pDistinct, pExpr)
				if pDistinct != 0 {
					v12 = libc.Int32FromInt32(WHERE_WANT_DISTINCT) | libc.Int32FromInt32(WHERE_AGG_DISTINCT)
				} else {
					v12 = 0
				}
				distFlag = libc.Uint16FromInt32(v12)
			}
			/* If there is a GROUP BY clause we might need a sorting index to
			 ** implement it.  Allocate that sorting index now.  If it turns out
			 ** that we do not need it after all, the OP_SorterOpen instruction
			 ** will be converted into a Noop.
			 */
			v1 = pParse + 56
			v12 = *(*int32)(unsafe.Pointer(v1))
			*(*int32)(unsafe.Pointer(v1)) = *(*int32)(unsafe.Pointer(v1)) + 1
			(*TAggInfo)(unsafe.Pointer(pAggInfo)).FsortingIdx = v12
			pKeyInfo1 = _sqlite3KeyInfoFromExprList(tls, pParse, pGroupBy, 0, (*TAggInfo)(unsafe.Pointer(pAggInfo)).FnColumn)
			addrSortingIdx = _sqlite3VdbeAddOp4(tls, v, int32(OP_SorterOpen), (*TAggInfo)(unsafe.Pointer(pAggInfo)).FsortingIdx, libc.Int32FromUint32((*TAggInfo)(unsafe.Pointer(pAggInfo)).FnSortingColumn), 0, pKeyInfo1, -int32(9))
			/* Initialize memory locations used by GROUP BY aggregate processing
			 */
			v1 = pParse + 60
			*(*int32)(unsafe.Pointer(v1)) = *(*int32)(unsafe.Pointer(v1)) + 1
			v12 = *(*int32)(unsafe.Pointer(v1))
			iUseFlag = v12
			v1 = pParse + 60
			*(*int32)(unsafe.Pointer(v1)) = *(*int32)(unsafe.Pointer(v1)) + 1
			v12 = *(*int32)(unsafe.Pointer(v1))
			iAbortFlag = v12
			v1 = pParse + 60
			*(*int32)(unsafe.Pointer(v1)) = *(*int32)(unsafe.Pointer(v1)) + 1
			v12 = *(*int32)(unsafe.Pointer(v1))
			regOutputRow = v12
			addrOutputRow = _sqlite3VdbeMakeLabel(tls, pParse)
			v1 = pParse + 60
			*(*int32)(unsafe.Pointer(v1)) = *(*int32)(unsafe.Pointer(v1)) + 1
			v12 = *(*int32)(unsafe.Pointer(v1))
			regReset = v12
			addrReset = _sqlite3VdbeMakeLabel(tls, pParse)
			iAMem = (*TParse)(unsafe.Pointer(pParse)).FnMem + int32(1)
			**(**int32)(__ccgo_up(pParse + 60)) += (*TExprList)(unsafe.Pointer(pGroupBy)).FnExpr
			iBMem = (*TParse)(unsafe.Pointer(pParse)).FnMem + int32(1)
			**(**int32)(__ccgo_up(pParse + 60)) += (*TExprList)(unsafe.Pointer(pGroupBy)).FnExpr
			_sqlite3VdbeAddOp2(tls, v, int32(OP_Integer), 0, iAbortFlag)
			_sqlite3VdbeAddOp3(tls, v, int32(OP_Null), 0, iAMem, iAMem+(*TExprList)(unsafe.Pointer(pGroupBy)).FnExpr-int32(1))
			_sqlite3ExprNullRegisterRange(tls, pParse, iAMem, (*TExprList)(unsafe.Pointer(pGroupBy)).FnExpr)
			/* Begin a loop that will extract all source rows in GROUP BY order.
			 ** This might involve two separate loops with an OP_Sort in between, or
			 ** it might be a single loop that uses an index to extract information
			 ** in the right order to begin with.
			 */
			_sqlite3VdbeAddOp2(tls, v, int32(OP_Gosub), regReset, addrReset)
			if libc.Int32FromUint8((**(**TDistinctCtx)(__ccgo_up(bp))).FisTnct) == int32(2) {
				v12 = int32(WHERE_DISTINCTBY)
			} else {
				v12 = int32(WHERE_GROUPBY)
			}
			if orderByGrp != 0 {
				v15 = int32(WHERE_SORTBYGROUP)
			} else {
				v15 = 0
			}
			pWInfo = _sqlite3WhereBegin(tls, pParse, pTabList, pWhere, pGroupBy, pDistinct, p, libc.Uint16FromInt32(v12|v15|libc.Int32FromUint16(distFlag)), 0)
			if pWInfo == uintptr(0) {
				_sqlite3ExprListDelete(tls, db, pDistinct)
				goto select_end
			}
			if (*TParse)(unsafe.Pointer(pParse)).FpIdxEpr != 0 {
				_optimizeAggregateUseOfIndexedExpr(tls, pParse, p, pAggInfo, bp+112)
			}
			_assignAggregateRegisters(tls, pParse, pAggInfo)
			eDist = _sqlite3WhereIsDistinct(tls, pWInfo)
			if _sqlite3WhereIsOrdered(tls, pWInfo) == (*TExprList)(unsafe.Pointer(pGroupBy)).FnExpr {
				/* The optimizer is able to deliver rows in group by order so
				 ** we do not have to sort.  The OP_OpenEphemeral table will be
				 ** cancelled later because we still need to use the pKeyInfo
				 */
				groupBySort = 0
			} else {
				if (**(**TDistinctCtx)(__ccgo_up(bp))).FisTnct != 0 && (*TSelect)(unsafe.Pointer(p)).FselFlags&uint32(SF_Distinct) == uint32(0) {
					v1 = __ccgo_ts + 21746
				} else {
					v1 = __ccgo_ts + 21755
				}
				_sqlite3VdbeExplain(tls, pParse, uint8(0), __ccgo_ts+20511, libc.VaList(bp+176, v1))
				groupBySort = int32(1)
				nGroupBy = (*TExprList)(unsafe.Pointer(pGroupBy)).FnExpr
				nCol = nGroupBy
				j = nGroupBy
				i = 0
				for {
					if !(i < (*TAggInfo)(unsafe.Pointer(pAggInfo)).FnColumn) {
						break
					}
					if (**(**TAggInfo_col)(__ccgo_up((*TAggInfo)(unsafe.Pointer(pAggInfo)).FaCol + uintptr(i)*32))).FiSorterColumn >= j {
						nCol = nCol + 1
						j = j + 1
					}
					goto _47
				_47:
					;
					i = i + 1
				}
				regBase = _sqlite3GetTempRange(tls, pParse, nCol)
				_sqlite3ExprCodeExprList(tls, pParse, pGroupBy, regBase, 0, uint8(0))
				j = nGroupBy
				(*TAggInfo)(unsafe.Pointer(pAggInfo)).FdirectMode = uint8(1)
				i = 0
				for {
					if !(i < (*TAggInfo)(unsafe.Pointer(pAggInfo)).FnColumn) {
						break
					}
					pCol = (*TAggInfo)(unsafe.Pointer(pAggInfo)).FaCol + uintptr(i)*32
					if (*TAggInfo_col)(unsafe.Pointer(pCol)).FiSorterColumn >= j {
						_sqlite3ExprCode(tls, pParse, (*TAggInfo_col)(unsafe.Pointer(pCol)).FpCExpr, j+regBase)
						j = j + 1
					}
					goto _48
				_48:
					;
					i = i + 1
				}
				(*TAggInfo)(unsafe.Pointer(pAggInfo)).FdirectMode = uint8(0)
				regRecord = _sqlite3GetTempReg(tls, pParse)
				_sqlite3VdbeAddOp3(tls, v, int32(OP_MakeRecord), regBase, nCol, regRecord)
				_sqlite3VdbeAddOp2(tls, v, int32(OP_SorterInsert), (*TAggInfo)(unsafe.Pointer(pAggInfo)).FsortingIdx, regRecord)
				_sqlite3ReleaseTempReg(tls, pParse, regRecord)
				_sqlite3ReleaseTempRange(tls, pParse, regBase, nCol)
				_sqlite3WhereEnd(tls, pWInfo)
				v1 = pParse + 56
				v15 = *(*int32)(unsafe.Pointer(v1))
				*(*int32)(unsafe.Pointer(v1)) = *(*int32)(unsafe.Pointer(v1)) + 1
				v12 = v15
				sortPTab = v12
				(*TAggInfo)(unsafe.Pointer(pAggInfo)).FsortingIdxPTab = v12
				sortOut = _sqlite3GetTempReg(tls, pParse)
				_sqlite3VdbeAddOp3(tls, v, int32(OP_OpenPseudo), sortPTab, sortOut, nCol)
				_sqlite3VdbeAddOp2(tls, v, int32(OP_SorterSort), (*TAggInfo)(unsafe.Pointer(pAggInfo)).FsortingIdx, addrEnd)
				(*TAggInfo)(unsafe.Pointer(pAggInfo)).FuseSortingIdx = uint8(1)
			}
			/* If there are entries in pAgggInfo->aFunc[] that contain subexpressions
			 ** that are indexed (and that were previously identified and tagged
			 ** in optimizeAggregateUseOfIndexedExpr()) then those subexpressions
			 ** must now be converted into a TK_AGG_COLUMN node so that the value
			 ** is correctly pulled from the index rather than being recomputed. */
			if (*TParse)(unsafe.Pointer(pParse)).FpIdxEpr != 0 {
				_aggregateConvertIndexedExprRefToColumn(tls, pAggInfo)
			}
			/* If the index or temporary table used by the GROUP BY sort
			 ** will naturally deliver rows in the order required by the ORDER BY
			 ** clause, cancel the ephemeral table open coded earlier.
			 **
			 ** This is an optimization - the correct answer should result regardless.
			 ** Use the SQLITE_GroupByOrder flag with SQLITE_TESTCTRL_OPTIMIZER to
			 ** disable this optimization for testing purposes.  */
			if orderByGrp != 0 && (*Tsqlite3)(unsafe.Pointer(db)).FdbOptFlags&libc.Uint32FromInt32(libc.Int32FromInt32(SQLITE_GroupByOrder)) == uint32(0) && (groupBySort != 0 || _sqlite3WhereIsSorted(tls, pWInfo) != 0) {
				(**(**TSortCtx)(__ccgo_up(bp + 16))).FpOrderBy = uintptr(0)
				_sqlite3VdbeChangeToNoop(tls, v, (**(**TSortCtx)(__ccgo_up(bp + 16))).FaddrSortIndex)
			}
			/* Evaluate the current GROUP BY terms and store in b0, b1, b2...
			 ** (b0 is memory location iBMem+0, b1 is iBMem+1, and so forth)
			 ** Then compare the current GROUP BY terms against the GROUP BY terms
			 ** from the previous row currently stored in a0, a1, a2...
			 */
			addrTopOfLoop = _sqlite3VdbeCurrentAddr(tls, v)
			if groupBySort != 0 {
				_sqlite3VdbeAddOp3(tls, v, int32(OP_SorterData), (*TAggInfo)(unsafe.Pointer(pAggInfo)).FsortingIdx, sortOut, sortPTab)
			}
			j = 0
			for {
				if !(j < (*TExprList)(unsafe.Pointer(pGroupBy)).FnExpr) {
					break
				}
				iOrderByCol = libc.Int32FromUint16(*(*Tu16)(unsafe.Pointer(pGroupBy + 8 + uintptr(j)*32 + 24)))
				if groupBySort != 0 {
					_sqlite3VdbeAddOp3(tls, v, int32(OP_Column), sortPTab, j, iBMem+j)
				} else {
					(*TAggInfo)(unsafe.Pointer(pAggInfo)).FdirectMode = uint8(1)
					_sqlite3ExprCode(tls, pParse, (*(*TExprList_item)(unsafe.Pointer(pGroupBy + 8 + uintptr(j)*32))).FpExpr, iBMem+j)
				}
				if iOrderByCol != 0 {
					pX = (*(*TExprList_item)(unsafe.Pointer((*TSelect)(unsafe.Pointer(p)).FpEList + 8 + uintptr(iOrderByCol-int32(1))*32))).FpExpr
					pBase = _sqlite3ExprSkipCollateAndLikely(tls, pX)
					for pBase != uintptr(0) && libc.Int32FromUint8((*TExpr)(unsafe.Pointer(pBase)).Fop) == int32(TK_IF_NULL_ROW) {
						pX = (*TExpr)(unsafe.Pointer(pBase)).FpLeft
						pBase = _sqlite3ExprSkipCollateAndLikely(tls, pX)
					}
					if pBase != uintptr(0) && libc.Int32FromUint8((*TExpr)(unsafe.Pointer(pBase)).Fop) != int32(TK_AGG_COLUMN) && libc.Int32FromUint8((*TExpr)(unsafe.Pointer(pBase)).Fop) != int32(TK_REGISTER) {
						_sqlite3ExprToRegister(tls, pX, iAMem+j)
					}
				}
				goto _52
			_52:
				;
				j = j + 1
			}
			_sqlite3VdbeAddOp4(tls, v, int32(OP_Compare), iAMem, iBMem, (*TExprList)(unsafe.Pointer(pGroupBy)).FnExpr, _sqlite3KeyInfoRef(tls, pKeyInfo1), -int32(9))
			addr1 = _sqlite3VdbeCurrentAddr(tls, v)
			_sqlite3VdbeAddOp3(tls, v, int32(OP_Jump), addr1+int32(1), 0, addr1+int32(1))
			/* Generate code that runs whenever the GROUP BY changes.
			 ** Changes in the GROUP BY are detected by the previous code
			 ** block.  If there were no changes, this block is skipped.
			 **
			 ** This code copies current group by terms in b0,b1,b2,...
			 ** over to a0,a1,a2.  It then calls the output subroutine
			 ** and resets the aggregate accumulator registers in preparation
			 ** for the next GROUP BY batch.
			 */
			_sqlite3VdbeAddOp2(tls, v, int32(OP_Gosub), regOutputRow, addrOutputRow)
			_sqlite3ExprCodeMove(tls, pParse, iBMem, iAMem, (*TExprList)(unsafe.Pointer(pGroupBy)).FnExpr)
			_sqlite3VdbeAddOp2(tls, v, int32(OP_IfPos), iAbortFlag, addrEnd)
			_sqlite3VdbeAddOp2(tls, v, int32(OP_Gosub), regReset, addrReset)
			/* Update the aggregate accumulators based on the content of
			 ** the current row
			 */
			_sqlite3VdbeJumpHere(tls, v, addr1)
			_updateAccumulator(tls, pParse, iUseFlag, pAggInfo, eDist)
			_sqlite3VdbeAddOp2(tls, v, int32(OP_Integer), int32(1), iUseFlag)
			/* End of the loop
			 */
			if groupBySort != 0 {
				_sqlite3VdbeAddOp2(tls, v, int32(OP_SorterNext), (*TAggInfo)(unsafe.Pointer(pAggInfo)).FsortingIdx, addrTopOfLoop)
			} else {
				_sqlite3WhereEnd(tls, pWInfo)
				_sqlite3VdbeChangeToNoop(tls, v, addrSortingIdx)
			}
			_sqlite3ExprListDelete(tls, db, pDistinct)
			/* Output the final row of result
			 */
			_sqlite3VdbeAddOp2(tls, v, int32(OP_Gosub), regOutputRow, addrOutputRow)
			/* Jump over the subroutines
			 */
			_sqlite3VdbeGoto(tls, v, addrEnd)
			/* Generate a subroutine that outputs a single row of the result
			 ** set.  This subroutine first looks at the iUseFlag.  If iUseFlag
			 ** is less than or equal to zero, the subroutine is a no-op.  If
			 ** the processing calls for the query to abort, this subroutine
			 ** increments the iAbortFlag memory location before returning in
			 ** order to signal the caller to abort.
			 */
			addrSetAbort = _sqlite3VdbeCurrentAddr(tls, v)
			_sqlite3VdbeAddOp2(tls, v, int32(OP_Integer), int32(1), iAbortFlag)
			_sqlite3VdbeAddOp1(tls, v, int32(OP_Return), regOutputRow)
			_sqlite3VdbeResolveLabel(tls, v, addrOutputRow)
			addrOutputRow = _sqlite3VdbeCurrentAddr(tls, v)
			_sqlite3VdbeAddOp2(tls, v, int32(OP_IfPos), iUseFlag, addrOutputRow+int32(2))
			_sqlite3VdbeAddOp1(tls, v, int32(OP_Return), regOutputRow)
			_finalizeAggFunctions(tls, pParse, pAggInfo)
			_sqlite3ExprIfFalse(tls, pParse, pHaving, addrOutputRow+int32(1), int32(SQLITE_JUMPIFNULL))
			_selectInnerLoop(tls, pParse, p, -int32(1), bp+16, bp, pDest, addrOutputRow+int32(1), addrSetAbort)
			_sqlite3VdbeAddOp1(tls, v, int32(OP_Return), regOutputRow)
			/* Generate a subroutine that will reset the group-by accumulator
			 */
			_sqlite3VdbeResolveLabel(tls, v, addrReset)
			_resetAccumulator(tls, pParse, pAggInfo)
			_sqlite3VdbeAddOp2(tls, v, int32(OP_Integer), 0, iUseFlag)
			_sqlite3VdbeAddOp1(tls, v, int32(OP_Return), regReset)
			if libc.Int32FromUint16(distFlag) != 0 && eDist != WHERE_DISTINCT_NOOP {
				pF = (*TAggInfo)(unsafe.Pointer(pAggInfo)).FaFunc
				_fixDistinctOpenEph(tls, pParse, eDist, (*TAggInfo_func)(unsafe.Pointer(pF)).FiDistinct, (*TAggInfo_func)(unsafe.Pointer(pF)).FiDistAddr)
			}
		} else {
			v1 = _isSimpleCount(tls, p, pAggInfo)
			pTab1 = v1
			if v1 != uintptr(0) {
				/* tag-select-0821
				 **
				 ** If isSimpleCount() returns a pointer to a Table structure, then
				 ** the SQL statement is of the form:
				 **
				 **   SELECT count(*) FROM <tbl>
				 **
				 ** where the Table structure returned represents table <tbl>.
				 **
				 ** This statement is so common that it is optimized specially. The
				 ** OP_Count instruction is executed either on the intkey table that
				 ** contains the data for table <tbl> or on one of its indexes. It
				 ** is better to execute the op on an index, as indexes are almost
				 ** always spread across less pages than their corresponding tables.
				 */
				iDb1 = _sqlite3SchemaToIndex(tls, (*TParse)(unsafe.Pointer(pParse)).Fdb, (*TTable)(unsafe.Pointer(pTab1)).FpSchema)
				v3 = pParse + 56
				v12 = *(*int32)(unsafe.Pointer(v3))
				*(*int32)(unsafe.Pointer(v3)) = *(*int32)(unsafe.Pointer(v3)) + 1
				iCsr = v12                                     /* Iterator variable */
				pKeyInfo2 = uintptr(0)                         /* Keyinfo for scanned index */
				pBest = uintptr(0)                             /* Best index found so far */
				iRoot = (*TTable)(unsafe.Pointer(pTab1)).Ftnum /* Root page of scanned b-tree */
				_sqlite3CodeVerifySchema(tls, pParse, iDb1)
				_sqlite3TableLock(tls, pParse, iDb1, (*TTable)(unsafe.Pointer(pTab1)).Ftnum, uint8(0), (*TTable)(unsafe.Pointer(pTab1)).FzName)
				/* Search for the index that has the lowest scan cost.
				 **
				 ** (2011-04-15) Do not do a full scan of an unordered index.
				 **
				 ** (2013-10-03) Do not count the entries in a partial index.
				 **
				 ** In practice the KeyInfo structure will not be used. It is only
				 ** passed to keep OP_OpenRead happy.
				 */
				if !((*TTable)(unsafe.Pointer(pTab1)).FtabFlags&libc.Uint32FromInt32(TF_WithoutRowid) == libc.Uint32FromInt32(0)) {
					pBest = _sqlite3PrimaryKeyIndex(tls, pTab1)
				}
				if !(int32(*(*uint32)(unsafe.Pointer((*TSelect)(unsafe.Pointer(p)).FpSrc + 8 + 24 + 4))&0x1>>0) != 0) {
					pIdx = (*TTable)(unsafe.Pointer(pTab1)).FpIndex
					for {
						if !(pIdx != 0) {
							break
						}
						if int32(uint32(*(*uint16)(unsafe.Pointer(pIdx + 100))&0x4>>2)) == 0 && int32((*TIndex)(unsafe.Pointer(pIdx)).FszIdxRow) < int32((*TTable)(unsafe.Pointer(pTab1)).FszTabRow) && (*TIndex)(unsafe.Pointer(pIdx)).FpPartIdxWhere == uintptr(0) && (!(pBest != 0) || int32((*TIndex)(unsafe.Pointer(pIdx)).FszIdxRow) < int32((*TIndex)(unsafe.Pointer(pBest)).FszIdxRow)) {
							pBest = pIdx
						}
						goto _56
					_56:
						;
						pIdx = (*TIndex)(unsafe.Pointer(pIdx)).FpNext
					}
				}
				if pBest != 0 {
					iRoot = (*TIndex)(unsafe.Pointer(pBest)).Ftnum
					pKeyInfo2 = _sqlite3KeyInfoOfIndex(tls, pParse, pBest)
				}
				/* Open a read-only cursor, execute the OP_Count, close the cursor. */
				_sqlite3VdbeAddOp4Int(tls, v, int32(OP_OpenRead), iCsr, libc.Int32FromUint32(iRoot), iDb1, int32(1))
				if pKeyInfo2 != 0 {
					_sqlite3VdbeChangeP4(tls, v, -int32(1), pKeyInfo2, -int32(9))
				}
				_assignAggregateRegisters(tls, pParse, pAggInfo)
				_sqlite3VdbeAddOp2(tls, v, int32(OP_Count), iCsr, (*TAggInfo)(unsafe.Pointer(pAggInfo)).FiFirstReg+(*TAggInfo)(unsafe.Pointer(pAggInfo)).FnColumn+0)
				_sqlite3VdbeAddOp1(tls, v, int32(OP_Close), iCsr)
				_explainSimpleCount(tls, pParse, pTab1, pBest)
			} else {
				/* The general case of an aggregate query without GROUP BY
				 ** tag-select-0822 */
				regAcc = 0 /* "populate accumulators" flag */
				pDistinct1 = uintptr(0)
				distFlag1 = uint16(0)
				/* If there are accumulator registers but no min() or max() functions
				 ** without FILTER clauses, allocate register regAcc. Register regAcc
				 ** will contain 0 the first time the inner loop runs, and 1 thereafter.
				 ** The code generated by updateAccumulator() uses this to ensure
				 ** that the accumulator registers are (a) updated only once if
				 ** there are no min() or max functions or (b) always updated for the
				 ** first row visited by the aggregate, so that they are updated at
				 ** least once even if the FILTER clause means the min() or max()
				 ** function visits zero rows.  */
				if (*TAggInfo)(unsafe.Pointer(pAggInfo)).FnAccumulator != 0 {
					i = 0
					for {
						if !(i < (*TAggInfo)(unsafe.Pointer(pAggInfo)).FnFunc) {
							break
						}
						if (*TExpr)(unsafe.Pointer((**(**TAggInfo_func)(__ccgo_up((*TAggInfo)(unsafe.Pointer(pAggInfo)).FaFunc + uintptr(i)*32))).FpFExpr)).Fflags&libc.Uint32FromInt32(libc.Int32FromInt32(EP_WinFunc)) != uint32(0) {
							goto _57
						}
						if (*TFuncDef)(unsafe.Pointer((**(**TAggInfo_func)(__ccgo_up((*TAggInfo)(unsafe.Pointer(pAggInfo)).FaFunc + uintptr(i)*32))).FpFunc)).FfuncFlags&uint32(SQLITE_FUNC_NEEDCOLL) != 0 {
							break
						}
						goto _57
					_57:
						;
						i = i + 1
					}
					if i == (*TAggInfo)(unsafe.Pointer(pAggInfo)).FnFunc {
						v1 = pParse + 60
						*(*int32)(unsafe.Pointer(v1)) = *(*int32)(unsafe.Pointer(v1)) + 1
						v12 = *(*int32)(unsafe.Pointer(v1))
						regAcc = v12
						_sqlite3VdbeAddOp2(tls, v, int32(OP_Integer), 0, regAcc)
					}
				} else {
					if (*TAggInfo)(unsafe.Pointer(pAggInfo)).FnFunc == int32(1) && (**(**TAggInfo_func)(__ccgo_up((*TAggInfo)(unsafe.Pointer(pAggInfo)).FaFunc))).FiDistinct >= 0 {
						pDistinct1 = *(*uintptr)(unsafe.Pointer((**(**TAggInfo_func)(__ccgo_up((*TAggInfo)(unsafe.Pointer(pAggInfo)).FaFunc))).FpFExpr + 32))
						if pDistinct1 != 0 {
							v12 = libc.Int32FromInt32(WHERE_WANT_DISTINCT) | libc.Int32FromInt32(WHERE_AGG_DISTINCT)
						} else {
							v12 = 0
						}
						distFlag1 = libc.Uint16FromInt32(v12)
					}
				}
				_assignAggregateRegisters(tls, pParse, pAggInfo)
				/* This case runs if the aggregate has no GROUP BY clause.  The
				 ** processing is much simpler since there is only a single row
				 ** of output.
				 */
				_resetAccumulator(tls, pParse, pAggInfo)
				/* If this query is a candidate for the min/max optimization, then
				 ** minMaxFlag will have been previously set to either
				 ** WHERE_ORDERBY_MIN or WHERE_ORDERBY_MAX and pMinMaxOrderBy will
				 ** be an appropriate ORDER BY expression for the optimization.
				 */
				pWInfo = _sqlite3WhereBegin(tls, pParse, pTabList, pWhere, **(**uintptr)(__ccgo_up(bp + 64)), pDistinct1, p, libc.Uint16FromInt32(libc.Int32FromUint8(minMaxFlag)|libc.Int32FromUint16(distFlag1)), 0)
				if pWInfo == uintptr(0) {
					goto select_end
				}
				eDist1 = _sqlite3WhereIsDistinct(tls, pWInfo)
				_updateAccumulator(tls, pParse, regAcc, pAggInfo, eDist1)
				if eDist1 != WHERE_DISTINCT_NOOP {
					pF1 = (*TAggInfo)(unsafe.Pointer(pAggInfo)).FaFunc
					if pF1 != 0 {
						_fixDistinctOpenEph(tls, pParse, eDist1, (*TAggInfo_func)(unsafe.Pointer(pF1)).FiDistinct, (*TAggInfo_func)(unsafe.Pointer(pF1)).FiDistAddr)
					}
				}
				if regAcc != 0 {
					_sqlite3VdbeAddOp2(tls, v, int32(OP_Integer), int32(1), regAcc)
				}
				if minMaxFlag != 0 {
					_sqlite3WhereMinMaxOptEarlyOut(tls, v, pWInfo)
				}
				_sqlite3WhereEnd(tls, pWInfo)
				_finalizeAggFunctions(tls, pParse, pAggInfo)
			}
			(**(**TSortCtx)(__ccgo_up(bp + 16))).FpOrderBy = uintptr(0)
			_sqlite3ExprIfFalse(tls, pParse, pHaving, addrEnd, int32(SQLITE_JUMPIFNULL))
			_selectInnerLoop(tls, pParse, p, -int32(1), uintptr(0), uintptr(0), pDest, addrEnd, addrEnd)
		}
		_sqlite3VdbeResolveLabel(tls, v, addrEnd)
	} /* endif aggregate query */
	if libc.Int32FromUint8((**(**TDistinctCtx)(__ccgo_up(bp))).FeTnctType) == int32(WHERE_DISTINCT_UNORDERED) {
		_explainTempTable(tls, pParse, __ccgo_ts+21746)
	}
	/* If there is an ORDER BY clause, then we need to sort the results
	 ** and send them to the callback one by one.  tag-select-0900
	 */
	if (**(**TSortCtx)(__ccgo_up(bp + 16))).FpOrderBy != 0 {
		_generateSortTail(tls, pParse, p, bp+16, (*TExprList)(unsafe.Pointer(pEList)).FnExpr, pDest)
	}
	/* Jump here to skip this query
	 */
	_sqlite3VdbeResolveLabel(tls, v, iEnd)
	/* The SELECT has been coded. If there is an error in the Parse structure,
	 ** set the return code to 1. Otherwise 0. */
	rc = libc.BoolInt32((*TParse)(unsafe.Pointer(pParse)).FnErr > 0)
	/* Control jumps to here if an error is encountered above, or upon
	 ** successful coding of the SELECT.
	 */
	goto select_end
select_end:
	;
	_sqlite3ExprListDelete(tls, db, **(**uintptr)(__ccgo_up(bp + 64)))
	_sqlite3VdbeExplainPop(tls, pParse)
	return rc
}

/************** End of select.c **********************************************/
/************** Begin file table.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 the sqlite3_get_table() and sqlite3_free_table()
** interface routines.  These are just wrappers around the main
** interface routine of sqlite3_exec().
**
** These routines are in a separate files so that they will not be linked
** if they are not used.
 */
/* #include "sqliteInt.h" */

// C documentation
//
//	/*
//	** Name of the connection operator, used for error messages.
//	*/
func _sqlite3SelectOpName(tls *libc.TLS, id int32) (r uintptr) {
	var z uintptr
	_ = z
	switch id {
	case int32(TK_ALL):
		z = __ccgo_ts + 20478
	case int32(TK_INTERSECT):
		z = __ccgo_ts + 20488
	case int32(TK_EXCEPT):
		z = __ccgo_ts + 20498
	default:
		z = __ccgo_ts + 20505
		break
	}
	return z
}

// C documentation
//
//	/*
//	** Error message for when two or more terms of a compound select have different
//	** size result sets.
//	*/
func _sqlite3SelectWrongNumTermsError(tls *libc.TLS, pParse uintptr, p uintptr) {
	bp := tls.Alloc(16)
	defer tls.Free(16)
	if (*TSelect)(unsafe.Pointer(p)).FselFlags&uint32(SF_Values) != 0 {
		_sqlite3ErrorMsg(tls, pParse, __ccgo_ts+20857, 0)
	} else {
		_sqlite3ErrorMsg(tls, pParse, __ccgo_ts+20903, libc.VaList(bp+8, _sqlite3SelectOpName(tls, libc.Int32FromUint8((*TSelect)(unsafe.Pointer(p)).Fop))))
	}
}

// C documentation
//
//	/*
//	** This routine is called by the parser to add a new term to the
//	** end of a growing FROM clause.  The "p" parameter is the part of
//	** the FROM clause that has already been constructed.  "p" is NULL
//	** if this is the first term of the FROM clause.  pTable and pDatabase
//	** are the name of the table and database named in the FROM clause term.
//	** pDatabase is NULL if the database name qualifier is missing - the
//	** usual case.  If the term has an alias, then pAlias points to the
//	** alias token.  If the term is a subquery, then pSubquery is the
//	** SELECT statement that the subquery encodes.  The pTable and
//	** pDatabase parameters are NULL for subqueries.  The pOn and pUsing
//	** parameters are the content of the ON and USING clauses.
//	**
//	** Return a new SrcList which encodes is the FROM with the new
//	** term added.
//	*/
func _sqlite3SrcListAppendFromTerm(tls *libc.TLS, pParse uintptr, p uintptr, pTable uintptr, pDatabase uintptr, pAlias uintptr, pSubquery uintptr, pOnUsing uintptr) (r uintptr) {
	bp := tls.Alloc(16)
	defer tls.Free(16)
	var db, pItem, pToken, v1 uintptr
	_, _, _, _ = db, pItem, pToken, v1
	db = (*TParse)(unsafe.Pointer(pParse)).Fdb
	if !(p != 0) && pOnUsing != uintptr(0) && ((*TOnOrUsing)(unsafe.Pointer(pOnUsing)).FpOn != 0 || (*TOnOrUsing)(unsafe.Pointer(pOnUsing)).FpUsing != 0) {
		if (*TOnOrUsing)(unsafe.Pointer(pOnUsing)).FpOn != 0 {
			v1 = __ccgo_ts + 16051
		} else {
			v1 = __ccgo_ts + 16054
		}
		_sqlite3ErrorMsg(tls, pParse, __ccgo_ts+16060, libc.VaList(bp+8, v1))
		goto append_from_error
	}
	p = _sqlite3SrcListAppend(tls, pParse, p, pTable, pDatabase)
	if p == uintptr(0) {
		goto append_from_error
	}
	pItem = p + 8 + uintptr((*TSrcList)(unsafe.Pointer(p)).FnSrc-int32(1))*80
	if libc.Int32FromUint8((*TParse)(unsafe.Pointer(pParse)).FeParseMode) >= int32(PARSE_MODE_RENAME) && (*TSrcItem)(unsafe.Pointer(pItem)).FzName != 0 {
		if pDatabase != 0 && (*TToken)(unsafe.Pointer(pDatabase)).Fz != 0 {
			v1 = pDatabase
		} else {
			v1 = pTable
		}
		pToken = v1
		_sqlite3RenameTokenMap(tls, pParse, (*TSrcItem)(unsafe.Pointer(pItem)).FzName, pToken)
	}
	if (*TToken)(unsafe.Pointer(pAlias)).Fn != 0 {
		(*TSrcItem)(unsafe.Pointer(pItem)).FzAlias = _sqlite3NameFromToken(tls, db, pAlias)
	}
	if pSubquery != 0 {
		if _sqlite3SrcItemAttachSubquery(tls, pParse, pItem, pSubquery, 0) != 0 {
			if (*TSelect)(unsafe.Pointer(pSubquery)).FselFlags&uint32(SF_NestedFrom) != 0 {
				libc.SetBitFieldPtr32Uint32(pItem+24+4, libc.Uint32FromInt32(1), 14, 0x4000)
			}
		}
	}
	if pOnUsing == uintptr(0) {
		*(*uintptr)(unsafe.Pointer(pItem + 64)) = uintptr(0)
	} else {
		if (*TOnOrUsing)(unsafe.Pointer(pOnUsing)).FpUsing != 0 {
			libc.SetBitFieldPtr32Uint32(pItem+24+4, libc.Uint32FromInt32(1), 11, 0x800)
			*(*uintptr)(unsafe.Pointer(pItem + 64)) = (*TOnOrUsing)(unsafe.Pointer(pOnUsing)).FpUsing
		} else {
			*(*uintptr)(unsafe.Pointer(pItem + 64)) = (*TOnOrUsing)(unsafe.Pointer(pOnUsing)).FpOn
		}
	}
	return p
	goto append_from_error
append_from_error:
	;
	_sqlite3ClearOnOrUsing(tls, db, pOnUsing)
	_sqlite3SelectDelete(tls, db, pSubquery)
	return uintptr(0)
}

// C documentation
//
//	/*
//	** Expand the space allocated for the given SrcList object by
//	** creating nExtra new slots beginning at iStart.  iStart is zero based.
//	** New slots are zeroed.
//	**
//	** For example, suppose a SrcList initially contains two entries: A,B.
//	** To append 3 new entries onto the end, do this:
//	**
//	**    sqlite3SrcListEnlarge(db, pSrclist, 3, 2);
//	**
//	** After the call above it would contain:  A, B, nil, nil, nil.
//	** If the iStart argument had been 1 instead of 2, then the result
//	** would have been:  A, nil, nil, nil, B.  To prepend the new slots,
//	** the iStart value would be 0.  The result then would
//	** be: nil, nil, nil, A, B.
//	**
//	** If a memory allocation fails or the SrcList becomes too large, leave
//	** the original SrcList unchanged, return NULL, and leave an error message
//	** in pParse.
//	*/
func _sqlite3SrcListEnlarge(tls *libc.TLS, pParse uintptr, pSrc uintptr, nExtra int32, iStart int32) (r uintptr) {
	bp := tls.Alloc(16)
	defer tls.Free(16)
	var db, pNew uintptr
	var i int32
	var nAlloc Tsqlite3_int64
	_, _, _, _ = db, i, nAlloc, pNew
	/* Sanity checking on calling parameters */
	/* Allocate additional space if needed */
	if libc.Uint32FromInt32((*TSrcList)(unsafe.Pointer(pSrc)).FnSrc)+libc.Uint32FromInt32(nExtra) > (*TSrcList)(unsafe.Pointer(pSrc)).FnAlloc {
		nAlloc = int64(2)*int64((*TSrcList)(unsafe.Pointer(pSrc)).FnSrc) + int64(nExtra)
		db = (*TParse)(unsafe.Pointer(pParse)).Fdb
		if (*TSrcList)(unsafe.Pointer(pSrc)).FnSrc+nExtra >= int32(SQLITE_MAX_SRCLIST) {
			_sqlite3ErrorMsg(tls, pParse, __ccgo_ts+16015, libc.VaList(bp+8, int32(SQLITE_MAX_SRCLIST)))
			return uintptr(0)
		}
		if nAlloc > int64(SQLITE_MAX_SRCLIST) {
			nAlloc = int64(SQLITE_MAX_SRCLIST)
		}
		pNew = _sqlite3DbRealloc(tls, db, pSrc, uint64(libc.UintptrFromInt32(0)+8)+libc.Uint64FromInt64(nAlloc)*libc.Uint64FromInt64(80))
		if pNew == uintptr(0) {
			return uintptr(0)
		}
		pSrc = pNew
		(*TSrcList)(unsafe.Pointer(pSrc)).FnAlloc = libc.Uint32FromInt64(nAlloc)
	}
	/* Move existing slots that come after the newly inserted slots
	 ** out of the way */
	i = (*TSrcList)(unsafe.Pointer(pSrc)).FnSrc - int32(1)
	for {
		if !(i >= iStart) {
			break
		}
		*(*TSrcItem)(unsafe.Pointer(pSrc + 8 + uintptr(i+nExtra)*80)) = *(*TSrcItem)(unsafe.Pointer(pSrc + 8 + uintptr(i)*80))
		goto _1
	_1:
		;
		i = i - 1
	}
	**(**int32)(__ccgo_up(pSrc)) += nExtra
	/* Zero the newly allocated slots */
	libc.Xmemset(tls, pSrc+8+uintptr(iStart)*80, 0, uint64(80)*libc.Uint64FromInt32(nExtra))
	i = iStart
	for {
		if !(i < iStart+nExtra) {
			break
		}
		(*(*TSrcItem)(unsafe.Pointer(pSrc + 8 + uintptr(i)*80))).FiCursor = -int32(1)
		goto _2
	_2:
		;
		i = i + 1
	}
	/* Return a pointer to the enlarged SrcList */
	return pSrc
}

// C documentation
//
//	/*
//	** Begin constructing a new table representation in memory.  This is
//	** the first of several action routines that get called in response
//	** to a CREATE TABLE statement.  In particular, this routine is called
//	** after seeing tokens "CREATE" and "TABLE" and the table name. The isTemp
//	** flag is true if the table should be stored in the auxiliary database
//	** file instead of in the main database file.  This is normally the case
//	** when the "TEMP" or "TEMPORARY" keyword occurs in between
//	** CREATE and TABLE.
//	**
//	** The new table record is initialized and put in pParse->pNewTable.
//	** As more of the CREATE TABLE statement is parsed, additional action
//	** routines will be called to add more information to this record.
//	** At the end of the CREATE TABLE statement, the sqlite3EndTable() routine
//	** is called to complete the construction of the new table record.
//	*/
func _sqlite3StartTable(tls *libc.TLS, pParse uintptr, pName1 uintptr, pName2 uintptr, isTemp int32, isView int32, isVirtual int32, noErr int32) {
	bp := tls.Alloc(32)
	defer tls.Free(32)
	var addr1, fileFormat, iDb, reg1, reg2, reg3, v7, v8 int32
	var db, pTable, v, zDb, zDb1, zName, v1 uintptr
	var v6 bool
	var _ /* pName at bp+0 */ uintptr
	_, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _ = addr1, db, fileFormat, iDb, pTable, reg1, reg2, reg3, v, zDb, zDb1, zName, v1, v6, v7, v8
	zName = uintptr(0)                         /* The name of the new table */
	db = (*TParse)(unsafe.Pointer(pParse)).Fdb /* Unqualified name of the table to create */
	if (*Tsqlite3)(unsafe.Pointer(db)).Finit1.Fbusy != 0 && (*Tsqlite3)(unsafe.Pointer(db)).Finit1.FnewTnum == uint32(1) {
		/* Special case:  Parsing the sqlite_schema or sqlite_temp_schema schema */
		iDb = libc.Int32FromUint8((*Tsqlite3)(unsafe.Pointer(db)).Finit1.FiDb)
		if libc.Bool(!(libc.Int32FromInt32(OMIT_TEMPDB) != 0)) && iDb == int32(1) {
			v1 = __ccgo_ts + 6757
		} else {
			v1 = __ccgo_ts + 6277
		}
		zName = _sqlite3DbStrDup(tls, db, v1)
		**(**uintptr)(__ccgo_up(bp)) = pName1
	} else {
		/* The common case */
		iDb = _sqlite3TwoPartName(tls, pParse, pName1, pName2, bp)
		if iDb < 0 {
			return
		}
		if libc.Bool(!(libc.Int32FromInt32(OMIT_TEMPDB) != 0)) && isTemp != 0 && (*TToken)(unsafe.Pointer(pName2)).Fn > uint32(0) && iDb != int32(1) {
			/* If creating a temp table, the name may not be qualified. Unless
			 ** the database name is "temp" anyway.  */
			_sqlite3ErrorMsg(tls, pParse, __ccgo_ts+13798, 0)
			return
		}
		if libc.Bool(!(libc.Int32FromInt32(OMIT_TEMPDB) != 0)) && isTemp != 0 {
			iDb = int32(1)
		}
		zName = _sqlite3NameFromToken(tls, db, **(**uintptr)(__ccgo_up(bp)))
		if libc.Int32FromUint8((*TParse)(unsafe.Pointer(pParse)).FeParseMode) >= int32(PARSE_MODE_RENAME) {
			_sqlite3RenameTokenMap(tls, pParse, zName, **(**uintptr)(__ccgo_up(bp)))
		}
	}
	(*TParse)(unsafe.Pointer(pParse)).FsNameToken = **(**TToken)(__ccgo_up(**(**uintptr)(__ccgo_up(bp))))
	if zName == uintptr(0) {
		return
	}
	if isView != 0 {
		v1 = __ccgo_ts + 11108
	} else {
		v1 = __ccgo_ts + 9370
	}
	if _sqlite3CheckObjectName(tls, pParse, zName, v1, zName) != 0 {
		goto begin_table_error
	}
	if libc.Int32FromUint8((*Tsqlite3)(unsafe.Pointer(db)).Finit1.FiDb) == int32(1) {
		isTemp = int32(1)
	}
	zDb = (**(**TDb)(__ccgo_up((*Tsqlite3)(unsafe.Pointer(db)).FaDb + uintptr(iDb)*32))).FzDbSName
	if libc.Bool(!(libc.Int32FromInt32(OMIT_TEMPDB) != 0)) && isTemp == int32(1) {
		v1 = __ccgo_ts + 6757
	} else {
		v1 = __ccgo_ts + 6277
	}
	if _sqlite3AuthCheck(tls, pParse, int32(SQLITE_INSERT), v1, uintptr(0), zDb) != 0 {
		goto begin_table_error
	}
	if !(isVirtual != 0) && _sqlite3AuthCheck(tls, pParse, libc.Int32FromUint8(_aCode[isTemp+int32(2)*isView]), zName, uintptr(0), zDb) != 0 {
		goto begin_table_error
	}
	/* Make sure the new table name does not collide with an existing
	 ** index or table name in the same database.  Issue an error message if
	 ** it does. The exception is if the statement being parsed was passed
	 ** to an sqlite3_declare_vtab() call. In that case only the column names
	 ** and types will be used, so there is no need to test for namespace
	 ** collisions.
	 */
	if !(libc.Int32FromUint8((*TParse)(unsafe.Pointer(pParse)).FeParseMode) != libc.Int32FromInt32(PARSE_MODE_NORMAL)) {
		zDb1 = (**(**TDb)(__ccgo_up((*Tsqlite3)(unsafe.Pointer(db)).FaDb + uintptr(iDb)*32))).FzDbSName
		if SQLITE_OK != _sqlite3ReadSchema(tls, pParse) {
			goto begin_table_error
		}
		pTable = _sqlite3FindTable(tls, db, zName, zDb1)
		if pTable != 0 {
			if !(noErr != 0) {
				if libc.Int32FromUint8((*TTable)(unsafe.Pointer(pTable)).FeTabType) == int32(TABTYP_VIEW) {
					v1 = __ccgo_ts + 11108
				} else {
					v1 = __ccgo_ts + 9370
				}
				_sqlite3ErrorMsg(tls, pParse, __ccgo_ts+13839, libc.VaList(bp+16, v1, **(**uintptr)(__ccgo_up(bp))))
			} else {
				_sqlite3CodeVerifySchema(tls, pParse, iDb)
				_sqlite3ForceNotReadOnly(tls, pParse)
			}
			goto begin_table_error
		}
		if _sqlite3FindIndex(tls, db, zName, zDb1) != uintptr(0) {
			_sqlite3ErrorMsg(tls, pParse, __ccgo_ts+13860, libc.VaList(bp+16, zName))
			goto begin_table_error
		}
	}
	pTable = _sqlite3DbMallocZero(tls, db, uint64(120))
	if pTable == uintptr(0) {
		(*TParse)(unsafe.Pointer(pParse)).Frc = int32(SQLITE_NOMEM)
		(*TParse)(unsafe.Pointer(pParse)).FnErr = (*TParse)(unsafe.Pointer(pParse)).FnErr + 1
		goto begin_table_error
	}
	(*TTable)(unsafe.Pointer(pTable)).FzName = zName
	(*TTable)(unsafe.Pointer(pTable)).FiPKey = int16(-int32(1))
	(*TTable)(unsafe.Pointer(pTable)).FpSchema = (**(**TDb)(__ccgo_up((*Tsqlite3)(unsafe.Pointer(db)).FaDb + uintptr(iDb)*32))).FpSchema
	(*TTable)(unsafe.Pointer(pTable)).FnTabRef = uint32(1)
	(*TTable)(unsafe.Pointer(pTable)).FnRowLogEst = int16(200)
	(*TParse)(unsafe.Pointer(pParse)).FpNewTable = pTable
	/* Begin generating the code that will insert the table record into
	 ** the schema table.  Note in particular that we must go ahead
	 ** and allocate the record number for the table entry now.  Before any
	 ** PRIMARY KEY or UNIQUE keywords are parsed.  Those keywords will cause
	 ** indices to be created and the table record must come before the
	 ** indices.  Hence, the record number for the table must be allocated
	 ** now.
	 */
	if v6 = !((*Tsqlite3)(unsafe.Pointer(db)).Finit1.Fbusy != 0); v6 {
		v1 = _sqlite3GetVdbe(tls, pParse)
		v = v1
	}
	if v6 && v1 != uintptr(0) {
		_sqlite3BeginWriteOperation(tls, pParse, int32(1), iDb)
		if isVirtual != 0 {
			_sqlite3VdbeAddOp0(tls, v, int32(OP_VBegin))
		}
		/* If the file format and encoding in the database have not been set,
		 ** set them now.
		 */
		v1 = pParse + 60
		*(*int32)(unsafe.Pointer(v1)) = *(*int32)(unsafe.Pointer(v1)) + 1
		v8 = *(*int32)(unsafe.Pointer(v1))
		v7 = v8
		(*(*struct {
			FaddrCrTab      int32
			FregRowid       int32
			FregRoot        int32
			FconstraintName TToken
		})(unsafe.Pointer(pParse + 256))).FregRowid = v7
		reg1 = v7
		v1 = pParse + 60
		*(*int32)(unsafe.Pointer(v1)) = *(*int32)(unsafe.Pointer(v1)) + 1
		v8 = *(*int32)(unsafe.Pointer(v1))
		v7 = v8
		(*(*struct {
			FaddrCrTab      int32
			FregRowid       int32
			FregRoot        int32
			FconstraintName TToken
		})(unsafe.Pointer(pParse + 256))).FregRoot = v7
		reg2 = v7
		v1 = pParse + 60
		*(*int32)(unsafe.Pointer(v1)) = *(*int32)(unsafe.Pointer(v1)) + 1
		v7 = *(*int32)(unsafe.Pointer(v1))
		reg3 = v7
		_sqlite3VdbeAddOp3(tls, v, int32(OP_ReadCookie), iDb, reg3, int32(BTREE_FILE_FORMAT))
		_sqlite3VdbeUsesBtree(tls, v, iDb)
		addr1 = _sqlite3VdbeAddOp1(tls, v, int32(OP_If), reg3)
		if (*Tsqlite3)(unsafe.Pointer(db)).Fflags&uint64(SQLITE_LegacyFileFmt) != uint64(0) {
			v7 = int32(1)
		} else {
			v7 = int32(SQLITE_MAX_FILE_FORMAT)
		}
		fileFormat = v7
		_sqlite3VdbeAddOp3(tls, v, int32(OP_SetCookie), iDb, int32(BTREE_FILE_FORMAT), fileFormat)
		_sqlite3VdbeAddOp3(tls, v, int32(OP_SetCookie), iDb, int32(BTREE_TEXT_ENCODING), libc.Int32FromUint8((*Tsqlite3)(unsafe.Pointer(db)).Fenc))
		_sqlite3VdbeJumpHere(tls, v, addr1)
		/* This just creates a place-holder record in the sqlite_schema table.
		 ** The record created does not contain anything yet.  It will be replaced
		 ** by the real entry in code generated at sqlite3EndTable().
		 **
		 ** The rowid for the new entry is left in register pParse->u1.cr.regRowid.
		 ** The root page of the new table is left in reg pParse->u1.cr.regRoot.
		 ** The rowid and root page number values are needed by the code that
		 ** sqlite3EndTable will generate.
		 */
		if isView != 0 || isVirtual != 0 {
			_sqlite3VdbeAddOp2(tls, v, int32(OP_Integer), 0, reg2)
		} else {
			(*(*struct {
				FaddrCrTab      int32
				FregRowid       int32
				FregRoot        int32
				FconstraintName TToken
			})(unsafe.Pointer(pParse + 256))).FaddrCrTab = _sqlite3VdbeAddOp3(tls, v, int32(OP_CreateBtree), iDb, reg2, int32(BTREE_INTKEY))
		}
		_sqlite3OpenSchemaTable(tls, pParse, iDb)
		_sqlite3VdbeAddOp2(tls, v, int32(OP_NewRowid), 0, reg1)
		_sqlite3VdbeAddOp4(tls, v, int32(OP_Blob), int32(6), reg3, 0, uintptr(unsafe.Pointer(&_nullRow)), -int32(1))
		_sqlite3VdbeAddOp3(tls, v, int32(OP_Insert), 0, reg3, reg1)
		_sqlite3VdbeChangeP5(tls, v, uint16(OPFLAG_APPEND))
		_sqlite3VdbeAddOp0(tls, v, int32(OP_Close))
	} else {
		if int32(uint32(*(*uint8)(unsafe.Pointer(db + 192 + 8))&0x6>>1)) != 0 {
			**(**Tu32)(__ccgo_up(pTable + 48)) |= uint32(TF_Imposter)
			if int32(uint32(*(*uint8)(unsafe.Pointer(db + 192 + 8))&0x6>>1)) >= int32(2) {
				**(**Tu32)(__ccgo_up(pTable + 48)) |= uint32(TF_Readonly)
			}
		}
	}
	/* Normal (non-error) return. */
	return
	/* If an error occurs, we jump here */
	goto begin_table_error
begin_table_error:
	;
	libc.SetBitFieldPtr16Uint32(pParse+40, libc.Uint32FromInt32(1), 8, 0x100)
	_sqlite3DbFree(tls, db, zName)
	return
}

var _sqlite3StdType = [6]uintptr{
	0: __ccgo_ts + 1154,
	1: __ccgo_ts + 1158,
	2: __ccgo_ts + 1163,
	3: __ccgo_ts + 1167,
	4: __ccgo_ts + 1175,
	5: __ccgo_ts + 1180,
}

/************** End of global.c **********************************************/
/************** Begin file status.c ******************************************/
/*
** 2008 June 18
**
** 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 module implements the sqlite3_status() interface and related
** functionality.
 */
/* #include "sqliteInt.h" */
/************** Include vdbeInt.h in the middle of status.c ******************/
/************** Begin file vdbeInt.h *****************************************/
/*
** 2003 September 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.
**
*************************************************************************
** This is the header file for information that is private to the
** VDBE.  This information used to all be at the top of the single
** source code file "vdbe.c".  When that file became too big (over
** 6000 lines long) it was split up into several smaller files and
** this header information was factored out.
 */

/*
** The maximum number of times that a statement will try to reparse
** itself before giving up and returning SQLITE_SCHEMA.
 */

/*
** VDBE_DISPLAY_P4 is true or false depending on whether or not the
** "explain" P4 display logic is enabled.
 */

// C documentation
//
//	/*
//	** Load the Parse object passed as the first argument with an error
//	** message of the form:
//	**
//	**   "sub-select returns N columns - expected M"
//	*/
func _sqlite3SubselectError(tls *libc.TLS, pParse uintptr, nActual int32, nExpect int32) {
	bp := tls.Alloc(32)
	defer tls.Free(32)
	var zFmt uintptr
	_ = zFmt
	if (*TParse)(unsafe.Pointer(pParse)).FnErr == 0 {
		zFmt = __ccgo_ts + 8278
		_sqlite3ErrorMsg(tls, pParse, zFmt, libc.VaList(bp+8, nActual, nExpect))
	}
}

// C documentation
//
//	/* The table or view or trigger name is passed to this routine via tokens
//	** pName1 and pName2. If the table name was fully qualified, for example:
//	**
//	** CREATE TABLE xxx.yyy (...);
//	**
//	** Then pName1 is set to "xxx" and pName2 "yyy". On the other hand if
//	** the table name is not fully qualified, i.e.:
//	**
//	** CREATE TABLE yyy(...);
//	**
//	** Then pName1 is set to "yyy" and pName2 is "".
//	**
//	** This routine sets the *ppUnqual pointer to point at the token (pName1 or
//	** pName2) that stores the unqualified table name.  The index of the
//	** database "xxx" is returned.
//	*/
func _sqlite3TwoPartName(tls *libc.TLS, pParse uintptr, pName1 uintptr, pName2 uintptr, pUnqual uintptr) (r int32) {
	bp := tls.Alloc(16)
	defer tls.Free(16)
	var db uintptr
	var iDb int32
	_, _ = db, iDb /* Database holding the object */
	db = (*TParse)(unsafe.Pointer(pParse)).Fdb
	if (*TToken)(unsafe.Pointer(pName2)).Fn > uint32(0) {
		if (*Tsqlite3)(unsafe.Pointer(db)).Finit1.Fbusy != 0 {
			_sqlite3ErrorMsg(tls, pParse, __ccgo_ts+13719, 0)
			return -int32(1)
		}
		**(**uintptr)(__ccgo_up(pUnqual)) = pName2
		iDb = _sqlite3FindDb(tls, db, pName1)
		if iDb < 0 {
			_sqlite3ErrorMsg(tls, pParse, __ccgo_ts+13736, libc.VaList(bp+8, pName1))
			return -int32(1)
		}
	} else {
		iDb = libc.Int32FromUint8((*Tsqlite3)(unsafe.Pointer(db)).Finit1.FiDb)
		**(**uintptr)(__ccgo_up(pUnqual)) = pName1
	}
	return iDb
}

// C documentation
//
//	/*
//	** Code an OP_Halt due to UNIQUE or PRIMARY KEY constraint violation.
//	*/
func _sqlite3UniqueConstraint(tls *libc.TLS, pParse uintptr, onError int32, pIdx uintptr) {
	bp := tls.Alloc(48)
	defer tls.Free(48)
	var j, v2 int32
	var pTab, zCol, zErr uintptr
	var _ /* errMsg at bp+0 */ TStrAccum
	_, _, _, _, _ = j, pTab, zCol, zErr, v2
	pTab = (*TIndex)(unsafe.Pointer(pIdx)).FpTable
	_sqlite3StrAccumInit(tls, bp, (*TParse)(unsafe.Pointer(pParse)).Fdb, uintptr(0), 0, **(**int32)(__ccgo_up((*TParse)(unsafe.Pointer(pParse)).Fdb + 136)))
	if (*TIndex)(unsafe.Pointer(pIdx)).FaColExpr != 0 {
		Xsqlite3_str_appendf(tls, bp, __ccgo_ts+16196, libc.VaList(bp+40, (*TIndex)(unsafe.Pointer(pIdx)).FzName))
	} else {
		j = 0
		for {
			if !(j < libc.Int32FromUint16((*TIndex)(unsafe.Pointer(pIdx)).FnKeyCol)) {
				break
			}
			zCol = (**(**TColumn)(__ccgo_up((*TTable)(unsafe.Pointer(pTab)).FaCol + uintptr(**(**Ti16)(__ccgo_up((*TIndex)(unsafe.Pointer(pIdx)).FaiColumn + uintptr(j)*2)))*16))).FzCnName
			if j != 0 {
				Xsqlite3_str_append(tls, bp, __ccgo_ts+16207, int32(2))
			}
			Xsqlite3_str_appendall(tls, bp, (*TTable)(unsafe.Pointer(pTab)).FzName)
			Xsqlite3_str_append(tls, bp, __ccgo_ts+1732, int32(1))
			Xsqlite3_str_appendall(tls, bp, zCol)
			goto _1
		_1:
			;
			j = j + 1
		}
	}
	zErr = _sqlite3StrAccumFinish(tls, bp)
	if int32(uint32(*(*uint16)(unsafe.Pointer(pIdx + 100))&0x3>>0)) == int32(SQLITE_IDXTYPE_PRIMARYKEY) {
		v2 = libc.Int32FromInt32(SQLITE_CONSTRAINT) | libc.Int32FromInt32(6)<<libc.Int32FromInt32(8)
	} else {
		v2 = libc.Int32FromInt32(SQLITE_CONSTRAINT) | libc.Int32FromInt32(8)<<libc.Int32FromInt32(8)
	}
	_sqlite3HaltConstraint(tls, pParse, v2, onError, zErr, int8(-libc.Int32FromInt32(7)), uint8(P5_ConstraintUnique))
}

// C documentation
//
//	/*
//	** Process an UPDATE statement.
//	**
//	**   UPDATE OR IGNORE tbl SET a=b, c=d FROM tbl2... WHERE e<5 AND f NOT NULL;
//	**          \_______/ \_/     \______/      \_____/       \________________/
//	**           onError   |      pChanges         |                pWhere
//	**                     \_______________________/
//	**                               pTabList
//	*/
func _sqlite3Update(tls *libc.TLS, pParse uintptr, pTabList uintptr, pChanges uintptr, pWhere uintptr, onError int32, pOrderBy uintptr, pLimit uintptr, pUpsert uintptr) {
	bp := tls.Alloc(128)
	defer tls.Free(128)
	var aRegIdx, aToOpen, aXRef, db, pIdx, pKeyInfo, pPk, pRowidExpr, pTab, pTrigger, pWInfo, v, v4 uintptr
	var addrOnce, addrOpen, addrTop, bFinishSeek, bProgress, eOnePass, flags, hasFK, i, iBaseCur, iCur, iDataCur, iDb, iEph, iIdxCur, iPk, iRowidExpr, isView, j, k, labelBreak, labelContinue, nAllIdx, nChangeFrom, nEphCol, nIdx, nKey, nOff, newmask, rc, reg, regKey, regNew, regNewRowid, regOld, regOldRowid, regRowCount, regRowSet, v1, v2 int32
	var chngKey, chngPk, chngRowid, v8 Tu8
	var colFlags, oldmask Tu32
	var nPk Ti16
	var v12 uint64
	var v42 uint32
	var _ /* aiCurOnePass at bp+80 */ [2]int32
	var _ /* bReplace at bp+88 */ int32
	var _ /* iNotUsed1 at bp+92 */ int32
	var _ /* iNotUsed2 at bp+96 */ int32
	var _ /* sContext at bp+0 */ TAuthContext
	var _ /* sNC at bp+16 */ TNameContext
	var _ /* tmask at bp+72 */ int32
	_, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _ = aRegIdx, aToOpen, aXRef, addrOnce, addrOpen, addrTop, bFinishSeek, bProgress, chngKey, chngPk, chngRowid, colFlags, db, eOnePass, flags, hasFK, i, iBaseCur, iCur, iDataCur, iDb, iEph, iIdxCur, iPk, iRowidExpr, isView, j, k, labelBreak, labelContinue, nAllIdx, nChangeFrom, nEphCol, nIdx, nKey, nOff, nPk, newmask, oldmask, pIdx, pKeyInfo, pPk, pRowidExpr, pTab, pTrigger, pWInfo, rc, reg, regKey, regNew, regNewRowid, regOld, regOldRowid, regRowCount, regRowSet, v, v1, v12, v2, v4, v42, v8 /* The table to be updated */
	addrTop = 0                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                           /* VDBE instruction address of the start of the loop */
	pWInfo = uintptr(0)                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                   /* The database structure */
	aRegIdx = uintptr(0)                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                  /* Registers for to each index and the main table */
	aXRef = uintptr(0)                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                    /* Either chngPk or chngRowid */
	pRowidExpr = uintptr(0)                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                               /* Expression defining the new record number */
	iRowidExpr = -int32(1)                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                /* Mask of NEW.* columns accessed by BEFORE triggers */
	iEph = 0                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                              /* Ephemeral table holding all primary key values */
	nKey = 0                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                              /* The write cursors opened by WHERE_ONEPASS */
	addrOpen = 0                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                          /* Address of OP_OpenEphemeral */
	iPk = 0                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                               /* First of nPk cells holding PRIMARY KEY value */
	nPk = 0                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                               /* Number of components of the PRIMARY KEY */
	**(**int32)(__ccgo_up(bp + 88)) = 0                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                   /* True if REPLACE conflict resolution might happen */
	bFinishSeek = int32(1)                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                /* The OP_FinishSeek opcode is needed */
	nChangeFrom = 0                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                       /* If there is a FROM, pChanges->nExpr, else 0 */
	/* Register Allocations */
	regRowCount = 0 /* A count of rows changed */
	regOldRowid = 0 /* The old rowid */
	regNewRowid = 0 /* The new rowid */
	regNew = 0      /* Content of the NEW.* table in triggers */
	regOld = 0      /* Content of OLD.* table in triggers */
	regRowSet = 0   /* Rowset of rows to be updated */
	regKey = 0      /* composite PRIMARY KEY value */
	libc.Xmemset(tls, bp, 0, uint64(16))
	db = (*TParse)(unsafe.Pointer(pParse)).Fdb
	if (*TParse)(unsafe.Pointer(pParse)).FnErr != 0 {
		goto update_cleanup
	}
	/* Locate the table which we want to update.
	 */
	pTab = _sqlite3SrcListLookup(tls, pParse, pTabList)
	if pTab == uintptr(0) {
		goto update_cleanup
	}
	iDb = _sqlite3SchemaToIndex(tls, (*TParse)(unsafe.Pointer(pParse)).Fdb, (*TTable)(unsafe.Pointer(pTab)).FpSchema)
	/* Figure out if we have any triggers and if the table being
	 ** updated is a view.
	 */
	pTrigger = _sqlite3TriggersExist(tls, pParse, pTab, int32(TK_UPDATE), pChanges, bp+72)
	isView = libc.BoolInt32(libc.Int32FromUint8((*TTable)(unsafe.Pointer(pTab)).FeTabType) == int32(TABTYP_VIEW))
	/* If there was a FROM clause, set nChangeFrom to the number of expressions
	 ** in the change-list. Otherwise, set it to 0. There cannot be a FROM
	 ** clause if this function is being called to generate code for part of
	 ** an UPSERT statement.  */
	if (*TSrcList)(unsafe.Pointer(pTabList)).FnSrc > int32(1) {
		v1 = (*TExprList)(unsafe.Pointer(pChanges)).FnExpr
	} else {
		v1 = 0
	}
	nChangeFrom = v1
	if _sqlite3ViewGetColumnNames(tls, pParse, pTab) != 0 {
		goto update_cleanup
	}
	if _sqlite3IsReadOnly(tls, pParse, pTab, pTrigger) != 0 {
		goto update_cleanup
	}
	/* Allocate a cursors for the main database table and for all indices.
	 ** The index cursors might not be used, but if they are used they
	 ** need to occur right after the database cursor.  So go ahead and
	 ** allocate enough space, just in case.
	 */
	v4 = pParse + 56
	v2 = *(*int32)(unsafe.Pointer(v4))
	*(*int32)(unsafe.Pointer(v4)) = *(*int32)(unsafe.Pointer(v4)) + 1
	v1 = v2
	iDataCur = v1
	iBaseCur = v1
	iIdxCur = iDataCur + int32(1)
	if (*TTable)(unsafe.Pointer(pTab)).FtabFlags&uint32(TF_WithoutRowid) == uint32(0) {
		v4 = uintptr(0)
	} else {
		v4 = _sqlite3PrimaryKeyIndex(tls, pTab)
	}
	pPk = v4
	nIdx = 0
	pIdx = (*TTable)(unsafe.Pointer(pTab)).FpIndex
	for {
		if !(pIdx != 0) {
			break
		}
		if pPk == pIdx {
			iDataCur = (*TParse)(unsafe.Pointer(pParse)).FnTab
		}
		(*TParse)(unsafe.Pointer(pParse)).FnTab = (*TParse)(unsafe.Pointer(pParse)).FnTab + 1
		goto _6
	_6:
		;
		pIdx = (*TIndex)(unsafe.Pointer(pIdx)).FpNext
		nIdx = nIdx + 1
	}
	if pUpsert != 0 {
		/* On an UPSERT, reuse the same cursors already opened by INSERT */
		iDataCur = (*TUpsert)(unsafe.Pointer(pUpsert)).FiDataCur
		iIdxCur = (*TUpsert)(unsafe.Pointer(pUpsert)).FiIdxCur
		(*TParse)(unsafe.Pointer(pParse)).FnTab = iBaseCur
	}
	(*(*TSrcItem)(unsafe.Pointer(pTabList + 8))).FiCursor = iDataCur
	/* Allocate space for aXRef[], aRegIdx[], and aToOpen[].
	 ** Initialize aXRef[] and aToOpen[] to their default values.
	 */
	aXRef = _sqlite3DbMallocRawNN(tls, db, uint64(uint64(4)*libc.Uint64FromInt32(int32((*TTable)(unsafe.Pointer(pTab)).FnCol)+nIdx+libc.Int32FromInt32(1))+libc.Uint64FromInt32(nIdx)+uint64(2)))
	if aXRef == uintptr(0) {
		goto update_cleanup
	}
	aRegIdx = aXRef + uintptr((*TTable)(unsafe.Pointer(pTab)).FnCol)*4
	aToOpen = aRegIdx + uintptr(nIdx)*4 + libc.UintptrFromInt32(1)*4
	libc.Xmemset(tls, aToOpen, int32(1), libc.Uint64FromInt32(nIdx+int32(1)))
	**(**Tu8)(__ccgo_up(aToOpen + uintptr(nIdx+int32(1)))) = uint8(0)
	i = 0
	for {
		if !(i < int32((*TTable)(unsafe.Pointer(pTab)).FnCol)) {
			break
		}
		**(**int32)(__ccgo_up(aXRef + uintptr(i)*4)) = -int32(1)
		goto _7
	_7:
		;
		i = i + 1
	}
	/* Initialize the name-context */
	libc.Xmemset(tls, bp+16, 0, uint64(56))
	(**(**TNameContext)(__ccgo_up(bp + 16))).FpParse = pParse
	(**(**TNameContext)(__ccgo_up(bp + 16))).FpSrcList = pTabList
	*(*uintptr)(unsafe.Pointer(bp + 16 + 16)) = pUpsert
	(**(**TNameContext)(__ccgo_up(bp + 16))).FncFlags = int32(NC_UUpsert)
	/* Begin generating code. */
	v = _sqlite3GetVdbe(tls, pParse)
	if v == uintptr(0) {
		goto update_cleanup
	}
	/* Resolve the column names in all the expressions of the
	 ** of the UPDATE statement.  Also find the column index
	 ** for each column to be updated in the pChanges array.  For each
	 ** column to be updated, make sure we have authorization to change
	 ** that column.
	 */
	v8 = libc.Uint8FromInt32(0)
	chngPk = v8
	chngRowid = v8
	i = 0
	for {
		if !(i < (*TExprList)(unsafe.Pointer(pChanges)).FnExpr) {
			break
		}
		/* If this is an UPDATE with a FROM clause, do not resolve expressions
		 ** here. The call to sqlite3Select() below will do that. */
		if nChangeFrom == 0 && _sqlite3ResolveExprNames(tls, bp+16, (*(*TExprList_item)(unsafe.Pointer(pChanges + 8 + uintptr(i)*32))).FpExpr) != 0 {
			goto update_cleanup
		}
		j = _sqlite3ColumnIndex(tls, pTab, (*(*TExprList_item)(unsafe.Pointer(pChanges + 8 + uintptr(i)*32))).FzEName)
		if j >= 0 {
			if j == int32((*TTable)(unsafe.Pointer(pTab)).FiPKey) {
				chngRowid = uint8(1)
				pRowidExpr = (*(*TExprList_item)(unsafe.Pointer(pChanges + 8 + uintptr(i)*32))).FpExpr
				iRowidExpr = i
			} else {
				if pPk != 0 && libc.Int32FromUint16((**(**TColumn)(__ccgo_up((*TTable)(unsafe.Pointer(pTab)).FaCol + uintptr(j)*16))).FcolFlags)&int32(COLFLAG_PRIMKEY) != 0 {
					chngPk = uint8(1)
				} else {
					if libc.Int32FromUint16((**(**TColumn)(__ccgo_up((*TTable)(unsafe.Pointer(pTab)).FaCol + uintptr(j)*16))).FcolFlags)&int32(COLFLAG_GENERATED) != 0 {
						_sqlite3ErrorMsg(tls, pParse, __ccgo_ts+22596, libc.VaList(bp+112, (**(**TColumn)(__ccgo_up((*TTable)(unsafe.Pointer(pTab)).FaCol + uintptr(j)*16))).FzCnName))
						goto update_cleanup
					}
				}
			}
			**(**int32)(__ccgo_up(aXRef + uintptr(j)*4)) = i
		} else {
			if pPk == uintptr(0) && _sqlite3IsRowid(tls, (*(*TExprList_item)(unsafe.Pointer(pChanges + 8 + uintptr(i)*32))).FzEName) != 0 {
				j = -int32(1)
				chngRowid = uint8(1)
				pRowidExpr = (*(*TExprList_item)(unsafe.Pointer(pChanges + 8 + uintptr(i)*32))).FpExpr
				iRowidExpr = i
			} else {
				_sqlite3ErrorMsg(tls, pParse, __ccgo_ts+11899, libc.VaList(bp+112, (*(*TExprList_item)(unsafe.Pointer(pChanges + 8 + uintptr(i)*32))).FzEName))
				libc.SetBitFieldPtr16Uint32(pParse+40, libc.Uint32FromInt32(1), 8, 0x100)
				goto update_cleanup
			}
		}
		if j < 0 {
			v4 = __ccgo_ts + 8190
		} else {
			v4 = (**(**TColumn)(__ccgo_up((*TTable)(unsafe.Pointer(pTab)).FaCol + uintptr(j)*16))).FzCnName
		}
		rc = _sqlite3AuthCheck(tls, pParse, int32(SQLITE_UPDATE), (*TTable)(unsafe.Pointer(pTab)).FzName, v4, (**(**TDb)(__ccgo_up((*Tsqlite3)(unsafe.Pointer(db)).FaDb + uintptr(iDb)*32))).FzDbSName)
		if rc == int32(SQLITE_DENY) {
			goto update_cleanup
		} else {
			if rc == int32(SQLITE_IGNORE) {
				**(**int32)(__ccgo_up(aXRef + uintptr(j)*4)) = -int32(1)
			}
		}
		goto _9
	_9:
		;
		i = i + 1
	}
	chngKey = libc.Uint8FromInt32(libc.Int32FromUint8(chngRowid) + libc.Int32FromUint8(chngPk))
	/* Mark generated columns as changing if their generator expressions
	 ** reference any changing column.  The actual aXRef[] value for
	 ** generated expressions is not used, other than to check to see that it
	 ** is non-negative, so the value of aXRef[] for generated columns can be
	 ** set to any non-negative number.  We use 99999 so that the value is
	 ** obvious when looking at aXRef[] in a symbolic debugger.
	 */
	if (*TTable)(unsafe.Pointer(pTab)).FtabFlags&uint32(TF_HasGenerated) != 0 {
		for cond := true; cond; cond = bProgress != 0 {
			bProgress = 0
			i = 0
			for {
				if !(i < int32((*TTable)(unsafe.Pointer(pTab)).FnCol)) {
					break
				}
				if **(**int32)(__ccgo_up(aXRef + uintptr(i)*4)) >= 0 {
					goto _11
				}
				if libc.Int32FromUint16((**(**TColumn)(__ccgo_up((*TTable)(unsafe.Pointer(pTab)).FaCol + uintptr(i)*16))).FcolFlags)&int32(COLFLAG_GENERATED) == 0 {
					goto _11
				}
				if _sqlite3ExprReferencesUpdatedColumn(tls, _sqlite3ColumnExpr(tls, pTab, (*TTable)(unsafe.Pointer(pTab)).FaCol+uintptr(i)*16), aXRef, libc.Int32FromUint8(chngRowid)) != 0 {
					**(**int32)(__ccgo_up(aXRef + uintptr(i)*4)) = int32(99999)
					bProgress = int32(1)
				}
				goto _11
			_11:
				;
				i = i + 1
			}
		}
	}
	/* The SET expressions are not actually used inside the WHERE loop.
	 ** So reset the colUsed mask. Unless this is a virtual table. In that
	 ** case, set all bits of the colUsed mask (to ensure that the virtual
	 ** table implementation makes all columns available).
	 */
	if libc.Int32FromUint8((*TTable)(unsafe.Pointer(pTab)).FeTabType) == int32(TABTYP_VTAB) {
		v12 = libc.Uint64FromInt32(-libc.Int32FromInt32(1))
	} else {
		v12 = uint64(0)
	}
	(*(*TSrcItem)(unsafe.Pointer(pTabList + 8))).FcolUsed = v12
	hasFK = _sqlite3FkRequired(tls, pParse, pTab, aXRef, libc.Int32FromUint8(chngKey))
	/* There is one entry in the aRegIdx[] array for each index on the table
	 ** being updated.  Fill in aRegIdx[] with a register number that will hold
	 ** the key for accessing each index.
	 */
	if onError == int32(OE_Replace) {
		**(**int32)(__ccgo_up(bp + 88)) = int32(1)
	}
	nAllIdx = 0
	pIdx = (*TTable)(unsafe.Pointer(pTab)).FpIndex
	for {
		if !(pIdx != 0) {
			break
		}
		if chngKey != 0 || hasFK > int32(1) || pIdx == pPk || _indexWhereClauseMightChange(tls, pIdx, aXRef, libc.Int32FromUint8(chngRowid)) != 0 {
			v4 = pParse + 60
			*(*int32)(unsafe.Pointer(v4)) = *(*int32)(unsafe.Pointer(v4)) + 1
			v1 = *(*int32)(unsafe.Pointer(v4))
			reg = v1
			**(**int32)(__ccgo_up(pParse + 60)) += libc.Int32FromUint16((*TIndex)(unsafe.Pointer(pIdx)).FnColumn)
		} else {
			reg = 0
			i = 0
			for {
				if !(i < libc.Int32FromUint16((*TIndex)(unsafe.Pointer(pIdx)).FnKeyCol)) {
					break
				}
				if _indexColumnIsBeingUpdated(tls, pIdx, i, aXRef, libc.Int32FromUint8(chngRowid)) != 0 {
					v4 = pParse + 60
					*(*int32)(unsafe.Pointer(v4)) = *(*int32)(unsafe.Pointer(v4)) + 1
					v1 = *(*int32)(unsafe.Pointer(v4))
					reg = v1
					**(**int32)(__ccgo_up(pParse + 60)) += libc.Int32FromUint16((*TIndex)(unsafe.Pointer(pIdx)).FnColumn)
					if onError == int32(OE_Default) && libc.Int32FromUint8((*TIndex)(unsafe.Pointer(pIdx)).FonError) == int32(OE_Replace) {
						**(**int32)(__ccgo_up(bp + 88)) = int32(1)
					}
					break
				}
				goto _16
			_16:
				;
				i = i + 1
			}
		}
		if reg == 0 {
			**(**Tu8)(__ccgo_up(aToOpen + uintptr(nAllIdx+int32(1)))) = uint8(0)
		}
		**(**int32)(__ccgo_up(aRegIdx + uintptr(nAllIdx)*4)) = reg
		goto _13
	_13:
		;
		pIdx = (*TIndex)(unsafe.Pointer(pIdx)).FpNext
		nAllIdx = nAllIdx + 1
	}
	v4 = pParse + 60
	*(*int32)(unsafe.Pointer(v4)) = *(*int32)(unsafe.Pointer(v4)) + 1
	v1 = *(*int32)(unsafe.Pointer(v4))
	**(**int32)(__ccgo_up(aRegIdx + uintptr(nAllIdx)*4)) = v1 /* Register storing the table record */
	if **(**int32)(__ccgo_up(bp + 88)) != 0 {
		/* If REPLACE conflict resolution might be invoked, open cursors on all
		 ** indexes in case they are needed to delete records.  */
		libc.Xmemset(tls, aToOpen, int32(1), libc.Uint64FromInt32(nIdx+int32(1)))
	}
	if libc.Int32FromUint8((*TParse)(unsafe.Pointer(pParse)).Fnested) == 0 {
		_sqlite3VdbeCountChanges(tls, v)
	}
	_sqlite3BeginWriteOperation(tls, pParse, libc.BoolInt32(pTrigger != 0 || hasFK != 0), iDb)
	/* Allocate required registers. */
	if !(libc.Int32FromUint8((*TTable)(unsafe.Pointer(pTab)).FeTabType) == libc.Int32FromInt32(TABTYP_VTAB)) {
		/* For now, regRowSet and aRegIdx[nAllIdx] share the same register.
		 ** If regRowSet turns out to be needed, then aRegIdx[nAllIdx] will be
		 ** reallocated.  aRegIdx[nAllIdx] is the register in which the main
		 ** table record is written.  regRowSet holds the RowSet for the
		 ** two-pass update algorithm. */
		regRowSet = **(**int32)(__ccgo_up(aRegIdx + uintptr(nAllIdx)*4))
		v4 = pParse + 60
		*(*int32)(unsafe.Pointer(v4)) = *(*int32)(unsafe.Pointer(v4)) + 1
		v2 = *(*int32)(unsafe.Pointer(v4))
		v1 = v2
		regNewRowid = v1
		regOldRowid = v1
		if chngPk != 0 || pTrigger != 0 || hasFK != 0 {
			regOld = (*TParse)(unsafe.Pointer(pParse)).FnMem + int32(1)
			**(**int32)(__ccgo_up(pParse + 60)) += int32((*TTable)(unsafe.Pointer(pTab)).FnCol)
		}
		if chngKey != 0 || pTrigger != 0 || hasFK != 0 {
			v4 = pParse + 60
			*(*int32)(unsafe.Pointer(v4)) = *(*int32)(unsafe.Pointer(v4)) + 1
			v1 = *(*int32)(unsafe.Pointer(v4))
			regNewRowid = v1
		}
		regNew = (*TParse)(unsafe.Pointer(pParse)).FnMem + int32(1)
		**(**int32)(__ccgo_up(pParse + 60)) += int32((*TTable)(unsafe.Pointer(pTab)).FnCol)
	}
	/* Start the view context. */
	if isView != 0 {
		_sqlite3AuthContextPush(tls, pParse, bp, (*TTable)(unsafe.Pointer(pTab)).FzName)
	}
	/* If we are trying to update a view, realize that view into
	 ** an ephemeral table.
	 */
	if nChangeFrom == 0 && isView != 0 {
		_sqlite3MaterializeView(tls, pParse, pTab, pWhere, pOrderBy, pLimit, iDataCur)
		pOrderBy = uintptr(0)
		pLimit = uintptr(0)
	}
	/* Resolve the column names in all the expressions in the
	 ** WHERE clause.
	 */
	if nChangeFrom == 0 && _sqlite3ResolveExprNames(tls, bp+16, pWhere) != 0 {
		goto update_cleanup
	}
	/* Virtual tables must be handled separately */
	if libc.Int32FromUint8((*TTable)(unsafe.Pointer(pTab)).FeTabType) == int32(TABTYP_VTAB) {
		_updateVirtualTable(tls, pParse, pTabList, pTab, pChanges, pRowidExpr, aXRef, pWhere, onError)
		goto update_cleanup
	}
	/* Jump to labelBreak to abandon further processing of this UPDATE */
	v1 = _sqlite3VdbeMakeLabel(tls, pParse)
	labelBreak = v1
	labelContinue = v1
	/* Not an UPSERT.  Normal processing.  Begin by
	 ** initialize the count of updated rows */
	if (*Tsqlite3)(unsafe.Pointer(db)).Fflags&(libc.Uint64FromInt32(libc.Int32FromInt32(0x00001))<<libc.Int32FromInt32(32)) != uint64(0) && !((*TParse)(unsafe.Pointer(pParse)).FpTriggerTab != 0) && !((*TParse)(unsafe.Pointer(pParse)).Fnested != 0) && !(int32(Tbft(*(*uint16)(unsafe.Pointer(pParse + 40))&0x8>>3)) != 0) && pUpsert == uintptr(0) {
		v4 = pParse + 60
		*(*int32)(unsafe.Pointer(v4)) = *(*int32)(unsafe.Pointer(v4)) + 1
		v1 = *(*int32)(unsafe.Pointer(v4))
		regRowCount = v1
		_sqlite3VdbeAddOp2(tls, v, int32(OP_Integer), 0, regRowCount)
	}
	if nChangeFrom == 0 && (*TTable)(unsafe.Pointer(pTab)).FtabFlags&uint32(TF_WithoutRowid) == uint32(0) {
		_sqlite3VdbeAddOp3(tls, v, int32(OP_Null), 0, regRowSet, regOldRowid)
		v4 = pParse + 56
		v1 = *(*int32)(unsafe.Pointer(v4))
		*(*int32)(unsafe.Pointer(v4)) = *(*int32)(unsafe.Pointer(v4)) + 1
		iEph = v1
		addrOpen = _sqlite3VdbeAddOp3(tls, v, int32(OP_OpenEphemeral), iEph, 0, regRowSet)
	} else {
		if pPk != 0 {
			v1 = libc.Int32FromUint16((*TIndex)(unsafe.Pointer(pPk)).FnKeyCol)
		} else {
			v1 = 0
		}
		nPk = int16(v1)
		iPk = (*TParse)(unsafe.Pointer(pParse)).FnMem + int32(1)
		**(**int32)(__ccgo_up(pParse + 60)) += int32(nPk)
		**(**int32)(__ccgo_up(pParse + 60)) += nChangeFrom
		v4 = pParse + 60
		*(*int32)(unsafe.Pointer(v4)) = *(*int32)(unsafe.Pointer(v4)) + 1
		v1 = *(*int32)(unsafe.Pointer(v4))
		regKey = v1
		if pUpsert == uintptr(0) {
			if isView != 0 {
				v1 = int32((*TTable)(unsafe.Pointer(pTab)).FnCol)
			} else {
				v1 = 0
			}
			nEphCol = int32(nPk) + nChangeFrom + v1
			v4 = pParse + 56
			v2 = *(*int32)(unsafe.Pointer(v4))
			*(*int32)(unsafe.Pointer(v4)) = *(*int32)(unsafe.Pointer(v4)) + 1
			iEph = v2
			if pPk != 0 {
				_sqlite3VdbeAddOp3(tls, v, int32(OP_Null), 0, iPk, iPk+int32(nPk)-int32(1))
			}
			addrOpen = _sqlite3VdbeAddOp2(tls, v, int32(OP_OpenEphemeral), iEph, nEphCol)
			if pPk != 0 {
				pKeyInfo = _sqlite3KeyInfoOfIndex(tls, pParse, pPk)
				if pKeyInfo != 0 {
					(*TKeyInfo)(unsafe.Pointer(pKeyInfo)).FnAllField = libc.Uint16FromInt32(nEphCol)
					_sqlite3VdbeAppendP4(tls, v, pKeyInfo, -int32(9))
				}
			}
			if nChangeFrom != 0 {
				_updateFromSelect(tls, pParse, iEph, pPk, pChanges, pTabList, pWhere, pOrderBy, pLimit)
				if isView != 0 {
					iDataCur = iEph
				}
			}
		}
	}
	if nChangeFrom != 0 {
		_sqlite3MultiWrite(tls, pParse)
		eOnePass = ONEPASS_OFF
		nKey = int32(nPk)
		regKey = iPk
	} else {
		if pUpsert != 0 {
			/* If this is an UPSERT, then all cursors have already been opened by
			 ** the outer INSERT and the data cursor should be pointing at the row
			 ** that is to be updated.  So bypass the code that searches for the
			 ** row(s) to be updated.
			 */
			pWInfo = uintptr(0)
			eOnePass = int32(ONEPASS_SINGLE)
			_sqlite3ExprIfFalse(tls, pParse, pWhere, labelBreak, int32(SQLITE_JUMPIFNULL))
			bFinishSeek = 0
		} else {
			/* Begin the database scan.
			 **
			 ** Do not consider a single-pass strategy for a multi-row update if
			 ** there is anything that might disrupt the cursor being used to do
			 ** the UPDATE:
			 **   (1) This is a nested UPDATE
			 **   (2) There are triggers
			 **   (3) There are FOREIGN KEY constraints
			 **   (4) There are REPLACE conflict handlers
			 **   (5) There are subqueries in the WHERE clause
			 */
			flags = int32(WHERE_ONEPASS_DESIRED)
			if !((*TParse)(unsafe.Pointer(pParse)).Fnested != 0) && !(pTrigger != 0) && !(hasFK != 0) && !(chngKey != 0) && !(**(**int32)(__ccgo_up(bp + 88)) != 0) && (pWhere == uintptr(0) || !((*TExpr)(unsafe.Pointer(pWhere)).Fflags&libc.Uint32FromInt32(libc.Int32FromInt32(EP_Subquery)) != libc.Uint32FromInt32(0))) {
				flags = flags | int32(WHERE_ONEPASS_MULTIROW)
			}
			pWInfo = _sqlite3WhereBegin(tls, pParse, pTabList, pWhere, uintptr(0), uintptr(0), uintptr(0), libc.Uint16FromInt32(flags), iIdxCur)
			if pWInfo == uintptr(0) {
				goto update_cleanup
			}
			/* A one-pass strategy that might update more than one row may not
			 ** be used if any column of the index used for the scan is being
			 ** updated. Otherwise, if there is an index on "b", statements like
			 ** the following could create an infinite loop:
			 **
			 **   UPDATE t1 SET b=b+1 WHERE b>?
			 **
			 ** Fall back to ONEPASS_OFF if where.c has selected a ONEPASS_MULTI
			 ** strategy that uses an index for which one or more columns are being
			 ** updated.  */
			eOnePass = _sqlite3WhereOkOnePass(tls, pWInfo, bp+80)
			bFinishSeek = _sqlite3WhereUsesDeferredSeek(tls, pWInfo)
			if eOnePass != int32(ONEPASS_SINGLE) {
				_sqlite3MultiWrite(tls, pParse)
				if eOnePass == int32(ONEPASS_MULTI) {
					iCur = (**(**[2]int32)(__ccgo_up(bp + 80)))[int32(1)]
					if iCur >= 0 && iCur != iDataCur && **(**Tu8)(__ccgo_up(aToOpen + uintptr(iCur-iBaseCur))) != 0 {
						eOnePass = ONEPASS_OFF
					}
				}
			}
		}
		if (*TTable)(unsafe.Pointer(pTab)).FtabFlags&uint32(TF_WithoutRowid) == uint32(0) {
			/* Read the rowid of the current row of the WHERE scan. In ONEPASS_OFF
			 ** mode, write the rowid into the FIFO. In either of the one-pass modes,
			 ** leave it in register regOldRowid.  */
			_sqlite3VdbeAddOp2(tls, v, int32(OP_Rowid), iDataCur, regOldRowid)
			if eOnePass == ONEPASS_OFF {
				v4 = pParse + 60
				*(*int32)(unsafe.Pointer(v4)) = *(*int32)(unsafe.Pointer(v4)) + 1
				v1 = *(*int32)(unsafe.Pointer(v4))
				**(**int32)(__ccgo_up(aRegIdx + uintptr(nAllIdx)*4)) = v1
				_sqlite3VdbeAddOp3(tls, v, int32(OP_Insert), iEph, regRowSet, regOldRowid)
			} else {
				if addrOpen != 0 {
					_sqlite3VdbeChangeToNoop(tls, v, addrOpen)
				}
			}
		} else {
			/* Read the PK of the current row into an array of registers. In
			 ** ONEPASS_OFF mode, serialize the array into a record and store it in
			 ** the ephemeral table. Or, in ONEPASS_SINGLE or MULTI mode, change
			 ** the OP_OpenEphemeral instruction to a Noop (the ephemeral table
			 ** is not required) and leave the PK fields in the array of registers.  */
			i = 0
			for {
				if !(i < int32(nPk)) {
					break
				}
				_sqlite3ExprCodeGetColumnOfTable(tls, v, pTab, iDataCur, int32(**(**Ti16)(__ccgo_up((*TIndex)(unsafe.Pointer(pPk)).FaiColumn + uintptr(i)*2))), iPk+i)
				goto _39
			_39:
				;
				i = i + 1
			}
			if eOnePass != 0 {
				if addrOpen != 0 {
					_sqlite3VdbeChangeToNoop(tls, v, addrOpen)
				}
				nKey = int32(nPk)
				regKey = iPk
			} else {
				_sqlite3VdbeAddOp4(tls, v, int32(OP_MakeRecord), iPk, int32(nPk), regKey, _sqlite3IndexAffinityStr(tls, db, pPk), int32(nPk))
				_sqlite3VdbeAddOp4Int(tls, v, int32(OP_IdxInsert), iEph, regKey, iPk, int32(nPk))
			}
		}
	}
	if pUpsert == uintptr(0) {
		if nChangeFrom == 0 && eOnePass != int32(ONEPASS_MULTI) {
			_sqlite3WhereEnd(tls, pWInfo)
		}
		if !(isView != 0) {
			addrOnce = 0
			**(**int32)(__ccgo_up(bp + 92)) = 0
			**(**int32)(__ccgo_up(bp + 96)) = 0
			/* Open every index that needs updating. */
			if eOnePass != ONEPASS_OFF {
				if (**(**[2]int32)(__ccgo_up(bp + 80)))[0] >= 0 {
					**(**Tu8)(__ccgo_up(aToOpen + uintptr((**(**[2]int32)(__ccgo_up(bp + 80)))[0]-iBaseCur))) = uint8(0)
				}
				if (**(**[2]int32)(__ccgo_up(bp + 80)))[int32(1)] >= 0 {
					**(**Tu8)(__ccgo_up(aToOpen + uintptr((**(**[2]int32)(__ccgo_up(bp + 80)))[int32(1)]-iBaseCur))) = uint8(0)
				}
			}
			if eOnePass == int32(ONEPASS_MULTI) && nIdx-libc.BoolInt32((**(**[2]int32)(__ccgo_up(bp + 80)))[int32(1)] >= 0) > 0 {
				addrOnce = _sqlite3VdbeAddOp0(tls, v, int32(OP_Once))
			}
			_sqlite3OpenTableAndIndices(tls, pParse, pTab, int32(OP_OpenWrite), uint8(0), iBaseCur, aToOpen, bp+92, bp+96)
			if addrOnce != 0 {
				_sqlite3VdbeJumpHereOrPopInst(tls, v, addrOnce)
			}
		}
		/* Top of the update loop */
		if eOnePass != ONEPASS_OFF {
			if (**(**[2]int32)(__ccgo_up(bp + 80)))[0] != iDataCur && (**(**[2]int32)(__ccgo_up(bp + 80)))[int32(1)] != iDataCur {
				_sqlite3VdbeAddOp4Int(tls, v, int32(OP_NotFound), iDataCur, labelBreak, regKey, nKey)
			}
			if eOnePass != int32(ONEPASS_SINGLE) {
				labelContinue = _sqlite3VdbeMakeLabel(tls, pParse)
			}
			if pPk != 0 {
				v1 = regKey
			} else {
				v1 = regOldRowid
			}
			_sqlite3VdbeAddOp2(tls, v, int32(OP_IsNull), v1, labelBreak)
		} else {
			if pPk != 0 || nChangeFrom != 0 {
				labelContinue = _sqlite3VdbeMakeLabel(tls, pParse)
				_sqlite3VdbeAddOp2(tls, v, int32(OP_Rewind), iEph, labelBreak)
				addrTop = _sqlite3VdbeCurrentAddr(tls, v)
				if nChangeFrom != 0 {
					if !(isView != 0) {
						if pPk != 0 {
							i = 0
							for {
								if !(i < int32(nPk)) {
									break
								}
								_sqlite3VdbeAddOp3(tls, v, int32(OP_Column), iEph, i, iPk+i)
								goto _41
							_41:
								;
								i = i + 1
							}
							_sqlite3VdbeAddOp4Int(tls, v, int32(OP_NotFound), iDataCur, labelContinue, iPk, int32(nPk))
						} else {
							_sqlite3VdbeAddOp2(tls, v, int32(OP_Rowid), iEph, regOldRowid)
							_sqlite3VdbeAddOp3(tls, v, int32(OP_NotExists), iDataCur, labelContinue, regOldRowid)
						}
					}
				} else {
					_sqlite3VdbeAddOp2(tls, v, int32(OP_RowData), iEph, regKey)
					_sqlite3VdbeAddOp4Int(tls, v, int32(OP_NotFound), iDataCur, labelContinue, regKey, 0)
				}
			} else {
				_sqlite3VdbeAddOp2(tls, v, int32(OP_Rewind), iEph, labelBreak)
				labelContinue = _sqlite3VdbeMakeLabel(tls, pParse)
				addrTop = _sqlite3VdbeAddOp2(tls, v, int32(OP_Rowid), iEph, regOldRowid)
				_sqlite3VdbeAddOp3(tls, v, int32(OP_NotExists), iDataCur, labelContinue, regOldRowid)
			}
		}
	}
	/* If the rowid value will change, set register regNewRowid to
	 ** contain the new value. If the rowid is not being modified,
	 ** then regNewRowid is the same register as regOldRowid, which is
	 ** already populated.  */
	if chngRowid != 0 {
		if nChangeFrom == 0 {
			_sqlite3ExprCode(tls, pParse, pRowidExpr, regNewRowid)
		} else {
			_sqlite3VdbeAddOp3(tls, v, int32(OP_Column), iEph, iRowidExpr, regNewRowid)
		}
		_sqlite3VdbeAddOp1(tls, v, int32(OP_MustBeInt), regNewRowid)
	}
	/* Compute the old pre-UPDATE content of the row being changed, if that
	 ** information is needed */
	if chngPk != 0 || hasFK != 0 || pTrigger != 0 {
		if hasFK != 0 {
			v42 = _sqlite3FkOldmask(tls, pParse, pTab)
		} else {
			v42 = uint32(0)
		}
		oldmask = v42
		oldmask = oldmask | _sqlite3TriggerColmask(tls, pParse, pTrigger, pChanges, 0, libc.Int32FromInt32(TRIGGER_BEFORE)|libc.Int32FromInt32(TRIGGER_AFTER), pTab, onError)
		i = 0
		for {
			if !(i < int32((*TTable)(unsafe.Pointer(pTab)).FnCol)) {
				break
			}
			colFlags = uint32((**(**TColumn)(__ccgo_up((*TTable)(unsafe.Pointer(pTab)).FaCol + uintptr(i)*16))).FcolFlags)
			k = int32(_sqlite3TableColumnToStorage(tls, pTab, int16(i))) + regOld
			if oldmask == uint32(0xffffffff) || i < int32(32) && oldmask&(libc.Uint32FromInt32(1)<<i) != uint32(0) || colFlags&uint32(COLFLAG_PRIMKEY) != uint32(0) {
				_sqlite3ExprCodeGetColumnOfTable(tls, v, pTab, iDataCur, i, k)
			} else {
				_sqlite3VdbeAddOp2(tls, v, int32(OP_Null), 0, k)
			}
			goto _43
		_43:
			;
			i = i + 1
		}
		if libc.Int32FromUint8(chngRowid) == 0 && pPk == uintptr(0) {
			_sqlite3VdbeAddOp2(tls, v, int32(OP_Copy), regOldRowid, regNewRowid)
		}
	}
	/* Populate the array of registers beginning at regNew with the new
	 ** row data. This array is used to check constants, create the new
	 ** table and index records, and as the values for any new.* references
	 ** made by triggers.
	 **
	 ** If there are one or more BEFORE triggers, then do not populate the
	 ** registers associated with columns that are (a) not modified by
	 ** this UPDATE statement and (b) not accessed by new.* references. The
	 ** values for registers not modified by the UPDATE must be reloaded from
	 ** the database after the BEFORE triggers are fired anyway (as the trigger
	 ** may have modified them). So not loading those that are not going to
	 ** be used eliminates some redundant opcodes.
	 */
	newmask = libc.Int32FromUint32(_sqlite3TriggerColmask(tls, pParse, pTrigger, pChanges, int32(1), int32(TRIGGER_BEFORE), pTab, onError))
	i = 0
	k = regNew
	for {
		if !(i < int32((*TTable)(unsafe.Pointer(pTab)).FnCol)) {
			break
		}
		if i == int32((*TTable)(unsafe.Pointer(pTab)).FiPKey) {
			_sqlite3VdbeAddOp2(tls, v, int32(OP_Null), 0, k)
		} else {
			if libc.Int32FromUint16((**(**TColumn)(__ccgo_up((*TTable)(unsafe.Pointer(pTab)).FaCol + uintptr(i)*16))).FcolFlags)&int32(COLFLAG_GENERATED) != 0 {
				if libc.Int32FromUint16((**(**TColumn)(__ccgo_up((*TTable)(unsafe.Pointer(pTab)).FaCol + uintptr(i)*16))).FcolFlags)&int32(COLFLAG_VIRTUAL) != 0 {
					k = k - 1
				}
			} else {
				j = **(**int32)(__ccgo_up(aXRef + uintptr(i)*4))
				if j >= 0 {
					if nChangeFrom != 0 {
						if isView != 0 {
							v1 = int32((*TTable)(unsafe.Pointer(pTab)).FnCol)
						} else {
							v1 = int32(nPk)
						}
						nOff = v1
						_sqlite3VdbeAddOp3(tls, v, int32(OP_Column), iEph, nOff+j, k)
					} else {
						_sqlite3ExprCode(tls, pParse, (*(*TExprList_item)(unsafe.Pointer(pChanges + 8 + uintptr(j)*32))).FpExpr, k)
					}
				} else {
					if 0 == **(**int32)(__ccgo_up(bp + 72))&int32(TRIGGER_BEFORE) || i > int32(31) || libc.Uint32FromInt32(newmask)&(libc.Uint32FromInt32(1)<<i) != 0 {
						/* This branch loads the value of a column that will not be changed
						 ** into a register. This is done if there are no BEFORE triggers, or
						 ** if there are one or more BEFORE triggers that use this value via
						 ** a new.* reference in a trigger program.
						 */
						_sqlite3ExprCodeGetColumnOfTable(tls, v, pTab, iDataCur, i, k)
						bFinishSeek = 0
					} else {
						_sqlite3VdbeAddOp2(tls, v, int32(OP_Null), 0, k)
					}
				}
			}
		}
		goto _44
	_44:
		;
		i = i + 1
		k = k + 1
	}
	if (*TTable)(unsafe.Pointer(pTab)).FtabFlags&uint32(TF_HasGenerated) != 0 {
		_sqlite3ComputeGeneratedColumns(tls, pParse, regNew, pTab)
	}
	/* Fire any BEFORE UPDATE triggers. This happens before constraints are
	 ** verified. One could argue that this is wrong.
	 */
	if **(**int32)(__ccgo_up(bp + 72))&int32(TRIGGER_BEFORE) != 0 {
		_sqlite3TableAffinity(tls, v, pTab, regNew)
		_sqlite3CodeRowTrigger(tls, pParse, pTrigger, int32(TK_UPDATE), pChanges, int32(TRIGGER_BEFORE), pTab, regOldRowid, onError, labelContinue)
		if !(isView != 0) {
			/* The row-trigger may have deleted the row being updated. In this
			 ** case, jump to the next row. No updates or AFTER triggers are
			 ** required. This behavior - what happens when the row being updated
			 ** is deleted or renamed by a BEFORE trigger - is left undefined in the
			 ** documentation.
			 */
			if pPk != 0 {
				_sqlite3VdbeAddOp4Int(tls, v, int32(OP_NotFound), iDataCur, labelContinue, regKey, nKey)
			} else {
				_sqlite3VdbeAddOp3(tls, v, int32(OP_NotExists), iDataCur, labelContinue, regOldRowid)
			}
			/* After-BEFORE-trigger-reload-loop:
			 ** If it did not delete it, the BEFORE trigger may still have modified
			 ** some of the columns of the row being updated. Load the values for
			 ** all columns not modified by the update statement into their registers
			 ** in case this has happened. Only unmodified columns are reloaded.
			 ** The values computed for modified columns use the values before the
			 ** BEFORE trigger runs.  See test case trigger1-18.0 (added 2018-04-26)
			 ** for an example.
			 */
			i = 0
			k = regNew
			for {
				if !(i < int32((*TTable)(unsafe.Pointer(pTab)).FnCol)) {
					break
				}
				if libc.Int32FromUint16((**(**TColumn)(__ccgo_up((*TTable)(unsafe.Pointer(pTab)).FaCol + uintptr(i)*16))).FcolFlags)&int32(COLFLAG_GENERATED) != 0 {
					if libc.Int32FromUint16((**(**TColumn)(__ccgo_up((*TTable)(unsafe.Pointer(pTab)).FaCol + uintptr(i)*16))).FcolFlags)&int32(COLFLAG_VIRTUAL) != 0 {
						k = k - 1
					}
				} else {
					if **(**int32)(__ccgo_up(aXRef + uintptr(i)*4)) < 0 && i != int32((*TTable)(unsafe.Pointer(pTab)).FiPKey) {
						_sqlite3ExprCodeGetColumnOfTable(tls, v, pTab, iDataCur, i, k)
					}
				}
				goto _46
			_46:
				;
				i = i + 1
				k = k + 1
			}
			if (*TTable)(unsafe.Pointer(pTab)).FtabFlags&uint32(TF_HasGenerated) != 0 {
				_sqlite3ComputeGeneratedColumns(tls, pParse, regNew, pTab)
			}
		}
	}
	if !(isView != 0) {
		/* Do constraint checks. */
		_sqlite3GenerateConstraintChecks(tls, pParse, pTab, aRegIdx, iDataCur, iIdxCur, regNewRowid, regOldRowid, chngKey, libc.Uint8FromInt32(onError), labelContinue, bp+88, aXRef, uintptr(0))
		/* If REPLACE conflict handling may have been used, or if the PK of the
		 ** row is changing, then the GenerateConstraintChecks() above may have
		 ** moved cursor iDataCur. Reseek it. */
		if **(**int32)(__ccgo_up(bp + 88)) != 0 || chngKey != 0 {
			if pPk != 0 {
				_sqlite3VdbeAddOp4Int(tls, v, int32(OP_NotFound), iDataCur, labelContinue, regKey, nKey)
			} else {
				_sqlite3VdbeAddOp3(tls, v, int32(OP_NotExists), iDataCur, labelContinue, regOldRowid)
			}
		}
		/* Do FK constraint checks. */
		if hasFK != 0 {
			_sqlite3FkCheck(tls, pParse, pTab, regOldRowid, 0, aXRef, libc.Int32FromUint8(chngKey))
		}
		/* Delete the index entries associated with the current record.  */
		_sqlite3GenerateRowIndexDelete(tls, pParse, pTab, iDataCur, iIdxCur, aRegIdx, -int32(1))
		/* We must run the OP_FinishSeek opcode to resolve a prior
		 ** OP_DeferredSeek if there is any possibility that there have been
		 ** no OP_Column opcodes since the OP_DeferredSeek was issued.  But
		 ** we want to avoid the OP_FinishSeek if possible, as running it
		 ** costs CPU cycles. */
		if bFinishSeek != 0 {
			_sqlite3VdbeAddOp1(tls, v, int32(OP_FinishSeek), iDataCur)
		}
		/* If changing the rowid value, or if there are foreign key constraints
		 ** to process, delete the old record. Otherwise, add a noop OP_Delete
		 ** to invoke the pre-update hook.
		 **
		 ** That (regNew==regnewRowid+1) is true is also important for the
		 ** pre-update hook. If the caller invokes preupdate_new(), the returned
		 ** value is copied from memory cell (regNewRowid+1+iCol), where iCol
		 ** is the column index supplied by the user.
		 */
		if hasFK > int32(1) || chngKey != 0 {
			v1 = 0
		} else {
			v1 = int32(OPFLAG_ISNOOP)
		}
		_sqlite3VdbeAddOp3(tls, v, int32(OP_Delete), iDataCur, int32(OPFLAG_ISUPDATE)|v1, regNewRowid)
		if eOnePass == int32(ONEPASS_MULTI) {
			_sqlite3VdbeChangeP5(tls, v, uint16(OPFLAG_SAVEPOSITION))
		}
		if !((*TParse)(unsafe.Pointer(pParse)).Fnested != 0) {
			_sqlite3VdbeAppendP4(tls, v, pTab, -int32(5))
		}
		if hasFK != 0 {
			_sqlite3FkCheck(tls, pParse, pTab, 0, regNewRowid, aXRef, libc.Int32FromUint8(chngKey))
		}
		/* Insert the new index entries and the new record. */
		if eOnePass == int32(ONEPASS_MULTI) {
			v1 = int32(OPFLAG_SAVEPOSITION)
		} else {
			v1 = 0
		}
		_sqlite3CompleteInsertion(tls, pParse, pTab, iDataCur, iIdxCur, regNewRowid, aRegIdx, int32(OPFLAG_ISUPDATE)|v1, 0, 0)
		/* Do any ON CASCADE, SET NULL or SET DEFAULT operations required to
		 ** handle rows (possibly in other tables) that refer via a foreign key
		 ** to the row just updated. */
		if hasFK != 0 {
			_sqlite3FkActions(tls, pParse, pTab, pChanges, regOldRowid, aXRef, libc.Int32FromUint8(chngKey))
		}
	}
	/* Increment the row counter
	 */
	if regRowCount != 0 {
		_sqlite3VdbeAddOp2(tls, v, int32(OP_AddImm), regRowCount, int32(1))
	}
	if pTrigger != 0 {
		_sqlite3CodeRowTrigger(tls, pParse, pTrigger, int32(TK_UPDATE), pChanges, int32(TRIGGER_AFTER), pTab, regOldRowid, onError, labelContinue)
	}
	/* Repeat the above with the next record to be updated, until
	 ** all record selected by the WHERE clause have been updated.
	 */
	if eOnePass == int32(ONEPASS_SINGLE) {
		/* Nothing to do at end-of-loop for a single-pass */
	} else {
		if eOnePass == int32(ONEPASS_MULTI) {
			_sqlite3VdbeResolveLabel(tls, v, labelContinue)
			_sqlite3WhereEnd(tls, pWInfo)
		} else {
			_sqlite3VdbeResolveLabel(tls, v, labelContinue)
			_sqlite3VdbeAddOp2(tls, v, int32(OP_Next), iEph, addrTop)
		}
	}
	_sqlite3VdbeResolveLabel(tls, v, labelBreak)
	/* Update the sqlite_sequence table by storing the content of the
	 ** maximum rowid counter values recorded while inserting into
	 ** autoincrement tables.
	 */
	if libc.Int32FromUint8((*TParse)(unsafe.Pointer(pParse)).Fnested) == 0 && (*TParse)(unsafe.Pointer(pParse)).FpTriggerTab == uintptr(0) && pUpsert == uintptr(0) {
		_sqlite3AutoincrementEnd(tls, pParse)
	}
	/*
	 ** Return the number of rows that were changed, if we are tracking
	 ** that information.
	 */
	if regRowCount != 0 {
		_sqlite3CodeChangeCount(tls, v, regRowCount, __ccgo_ts+22632)
	}
	goto update_cleanup
update_cleanup:
	;
	_sqlite3AuthContextPop(tls, bp)
	_sqlite3DbFree(tls, db, aXRef) /* Also frees aRegIdx[] and aToOpen[] */
	_sqlite3SrcListDelete(tls, db, pTabList)
	_sqlite3ExprListDelete(tls, db, pChanges)
	_sqlite3ExprDelete(tls, db, pWhere)
	return
}

/* Make sure "isView" and other macros defined above are undefined. Otherwise
** they may interfere with compilation of other functions in this file
** (or in another file, if this file becomes part of the amalgamation).  */

// C documentation
//
//	/*
//	** Compute a string that describes the P4 parameter for an opcode.
//	** Use zTemp for any required temporary buffer space.
//	*/
func _sqlite3VdbeDisplayP4(tls *libc.TLS, db uintptr, pOp uintptr) (r uintptr) {
	bp := tls.Alloc(64)
	defer tls.Free(64)
	var ai, pColl, pColl1, pDef, pDef1, pKeyInfo, pMem, pSig, pVtab, zColl, zP4, v2, v3 uintptr
	var i, n Tu32
	var j, v6 int32
	var _ /* x at bp+0 */ TStrAccum
	_, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _ = ai, i, j, n, pColl, pColl1, pDef, pDef1, pKeyInfo, pMem, pSig, pVtab, zColl, zP4, v2, v3, v6
	zP4 = uintptr(0)
	_sqlite3StrAccumInit(tls, bp, uintptr(0), uintptr(0), 0, int32(SQLITE_MAX_LENGTH))
	switch int32((*TOp)(unsafe.Pointer(pOp)).Fp4type) {
	case -int32(9):
		pKeyInfo = *(*uintptr)(unsafe.Pointer(pOp + 16))
		Xsqlite3_str_appendf(tls, bp, __ccgo_ts+5225, libc.VaList(bp+40, libc.Int32FromUint16((*TKeyInfo)(unsafe.Pointer(pKeyInfo)).FnKeyField)))
		j = 0
		for {
			if !(j < libc.Int32FromUint16((*TKeyInfo)(unsafe.Pointer(pKeyInfo)).FnKeyField)) {
				break
			}
			pColl = *(*uintptr)(unsafe.Pointer(pKeyInfo + 32 + uintptr(j)*8))
			if pColl != 0 {
				v2 = (*TCollSeq)(unsafe.Pointer(pColl)).FzName
			} else {
				v2 = __ccgo_ts + 1693
			}
			zColl = v2
			if libc.Xstrcmp(tls, zColl, __ccgo_ts+5230) == 0 {
				zColl = __ccgo_ts + 5237
			}
			if libc.Int32FromUint8(**(**Tu8)(__ccgo_up((*TKeyInfo)(unsafe.Pointer(pKeyInfo)).FaSortFlags + uintptr(j))))&int32(KEYINFO_ORDER_DESC) != 0 {
				v2 = __ccgo_ts + 5218
			} else {
				v2 = __ccgo_ts + 1693
			}
			if libc.Int32FromUint8(**(**Tu8)(__ccgo_up((*TKeyInfo)(unsafe.Pointer(pKeyInfo)).FaSortFlags + uintptr(j))))&int32(KEYINFO_ORDER_BIGNULL) != 0 {
				v3 = __ccgo_ts + 5239
			} else {
				v3 = __ccgo_ts + 1693
			}
			Xsqlite3_str_appendf(tls, bp, __ccgo_ts+5242, libc.VaList(bp+40, v2, v3, zColl))
			goto _1
		_1:
			;
			j = j + 1
		}
		Xsqlite3_str_append(tls, bp, __ccgo_ts+5250, int32(1))
	case -int32(2):
		pColl1 = *(*uintptr)(unsafe.Pointer(pOp + 16))
		Xsqlite3_str_appendf(tls, bp, __ccgo_ts+5266, libc.VaList(bp+40, (*TCollSeq)(unsafe.Pointer(pColl1)).FzName, _encnames[(*TCollSeq)(unsafe.Pointer(pColl1)).Fenc]))
	case -int32(8):
		pDef = *(*uintptr)(unsafe.Pointer(pOp + 16))
		Xsqlite3_str_appendf(tls, bp, __ccgo_ts+5275, libc.VaList(bp+40, (*TFuncDef)(unsafe.Pointer(pDef)).FzName, int32((*TFuncDef)(unsafe.Pointer(pDef)).FnArg)))
	case -int32(16):
		pDef1 = (*Tsqlite3_context)(unsafe.Pointer(*(*uintptr)(unsafe.Pointer(pOp + 16)))).FpFunc
		Xsqlite3_str_appendf(tls, bp, __ccgo_ts+5275, libc.VaList(bp+40, (*TFuncDef)(unsafe.Pointer(pDef1)).FzName, int32((*TFuncDef)(unsafe.Pointer(pDef1)).FnArg)))
	case -int32(14):
		Xsqlite3_str_appendf(tls, bp, __ccgo_ts+1454, libc.VaList(bp+40, **(**Ti64)(__ccgo_up(*(*uintptr)(unsafe.Pointer(pOp + 16))))))
	case -int32(3):
		Xsqlite3_str_appendf(tls, bp, __ccgo_ts+5282, libc.VaList(bp+40, (*TOp)(unsafe.Pointer(pOp)).Fp4.Fi))
	case -int32(13):
		Xsqlite3_str_appendf(tls, bp, __ccgo_ts+1421, libc.VaList(bp+40, **(**float64)(__ccgo_up(*(*uintptr)(unsafe.Pointer(pOp + 16))))))
	case -int32(11):
		pMem = *(*uintptr)(unsafe.Pointer(pOp + 16))
		if libc.Int32FromUint16((*TMem)(unsafe.Pointer(pMem)).Fflags)&int32(MEM_Str) != 0 {
			zP4 = (*TMem)(unsafe.Pointer(pMem)).Fz
		} else {
			if libc.Int32FromUint16((*TMem)(unsafe.Pointer(pMem)).Fflags)&(libc.Int32FromInt32(MEM_Int)|libc.Int32FromInt32(MEM_IntReal)) != 0 {
				Xsqlite3_str_appendf(tls, bp, __ccgo_ts+1454, libc.VaList(bp+40, *(*Ti64)(unsafe.Pointer(pMem))))
			} else {
				if libc.Int32FromUint16((*TMem)(unsafe.Pointer(pMem)).Fflags)&int32(MEM_Real) != 0 {
					Xsqlite3_str_appendf(tls, bp, __ccgo_ts+1421, libc.VaList(bp+40, *(*float64)(unsafe.Pointer(pMem))))
				} else {
					if libc.Int32FromUint16((*TMem)(unsafe.Pointer(pMem)).Fflags)&int32(MEM_Null) != 0 {
						zP4 = __ccgo_ts + 1694
					} else {
						zP4 = __ccgo_ts + 5285
					}
				}
			}
		}
	case -int32(12):
		pVtab = (*TVTable)(unsafe.Pointer(*(*uintptr)(unsafe.Pointer(pOp + 16)))).FpVtab
		Xsqlite3_str_appendf(tls, bp, __ccgo_ts+5292, libc.VaList(bp+40, pVtab))
	case -int32(15):
		ai = *(*uintptr)(unsafe.Pointer(pOp + 16))
		n = **(**Tu32)(__ccgo_up(ai)) /* The first element of an INTARRAY is always the
		 ** count of the number of elements to follow */
		i = uint32(1)
		for {
			if !(i <= n) {
				break
			}
			if i == uint32(1) {
				v6 = int32('[')
			} else {
				v6 = int32(',')
			}
			Xsqlite3_str_appendf(tls, bp, __ccgo_ts+5300, libc.VaList(bp+40, v6, **(**Tu32)(__ccgo_up(ai + uintptr(i)*4))))
			goto _5
		_5:
			;
			i = i + 1
		}
		Xsqlite3_str_append(tls, bp, __ccgo_ts+5305, int32(1))
	case -int32(4):
		zP4 = __ccgo_ts + 5307
	case -int32(5):
		zP4 = (*TTable)(unsafe.Pointer(*(*uintptr)(unsafe.Pointer(pOp + 16)))).FzName
	case -int32(6):
		zP4 = (*TIndex)(unsafe.Pointer(*(*uintptr)(unsafe.Pointer(pOp + 16)))).FzName
	case -int32(18):
		pSig = *(*uintptr)(unsafe.Pointer(pOp + 16))
		Xsqlite3_str_appendf(tls, bp, __ccgo_ts+5315, libc.VaList(bp+40, (*TSubrtnSig)(unsafe.Pointer(pSig)).FselId, (*TSubrtnSig)(unsafe.Pointer(pSig)).FzAff))
	default:
		zP4 = *(*uintptr)(unsafe.Pointer(pOp + 16))
	}
	if zP4 != 0 {
		Xsqlite3_str_appendall(tls, bp, zP4)
	}
	if libc.Int32FromUint8((**(**TStrAccum)(__ccgo_up(bp))).FaccError)&int32(SQLITE_NOMEM) != 0 {
		_sqlite3OomFault(tls, db)
	}
	return _sqlite3StrAccumFinish(tls, bp)
}

// C documentation
//
//	/*
//	** Set the value stored in *pMem should already be a NULL.
//	** Also store a pointer to go with it.
//	*/
func _sqlite3VdbeMemSetPointer(tls *libc.TLS, pMem uintptr, pPtr uintptr, zPType uintptr, __ccgo_fp_xDestructor uintptr) {
	var v1 uintptr
	_ = v1
	_vdbeMemClear(tls, pMem)
	if zPType != 0 {
		v1 = zPType
	} else {
		v1 = __ccgo_ts + 1693
	}
	*(*uintptr)(unsafe.Pointer(pMem)) = v1
	(*TMem)(unsafe.Pointer(pMem)).Fz = pPtr
	(*TMem)(unsafe.Pointer(pMem)).Fflags = libc.Uint16FromInt32(libc.Int32FromInt32(MEM_Null) | libc.Int32FromInt32(MEM_Dyn) | libc.Int32FromInt32(MEM_Subtype) | libc.Int32FromInt32(MEM_Term))
	(*TMem)(unsafe.Pointer(pMem)).FeSubtype = uint8('p')
	if __ccgo_fp_xDestructor != 0 {
		v1 = __ccgo_fp_xDestructor
	} else {
		v1 = __ccgo_fp(_sqlite3NoopDestructor)
	}
	(*TMem)(unsafe.Pointer(pMem)).FxDel = v1
}

// C documentation
//
//	/*
//	** Expression pExpr is a vector that has been used in a context where
//	** it is not permitted. If pExpr is a sub-select vector, this routine
//	** loads the Parse object with a message of the form:
//	**
//	**   "sub-select returns N columns - expected 1"
//	**
//	** Or, if it is a regular scalar vector:
//	**
//	**   "row value misused"
//	*/
func _sqlite3VectorErrorMsg(tls *libc.TLS, pParse uintptr, pExpr uintptr) {
	if (*TExpr)(unsafe.Pointer(pExpr)).Fflags&uint32(EP_xIsSelect) != uint32(0) {
		_sqlite3SubselectError(tls, pParse, (*TExprList)(unsafe.Pointer((*TSelect)(unsafe.Pointer(*(*uintptr)(unsafe.Pointer(pExpr + 32)))).FpEList)).FnExpr, int32(1))
	} else {
		_sqlite3ErrorMsg(tls, pParse, __ccgo_ts+6901, 0)
	}
}

// C documentation
//
//	/*
//	** This function is invoked by the parser to call the xConnect() method
//	** of the virtual table pTab. If an error occurs, an error code is returned
//	** and an error left in pParse.
//	**
//	** This call is a no-op if table pTab is not a virtual table.
//	*/
func _sqlite3VtabCallConnect(tls *libc.TLS, pParse uintptr, pTab uintptr) (r int32) {
	bp := tls.Alloc(32)
	defer tls.Free(32)
	var db, pMod, zMod, zModule uintptr
	var rc int32
	var _ /* zErr at bp+0 */ uintptr
	_, _, _, _, _ = db, pMod, rc, zMod, zModule
	db = (*TParse)(unsafe.Pointer(pParse)).Fdb
	if _sqlite3GetVTable(tls, db, pTab) != 0 {
		return SQLITE_OK
	}
	/* Locate the required virtual table module */
	zMod = **(**uintptr)(__ccgo_up((*(*struct {
		FnArg  int32
		FazArg uintptr
		Fp     uintptr
	})(unsafe.Pointer(pTab + 64))).FazArg))
	pMod = _sqlite3HashFind(tls, db+576, zMod)
	if !(pMod != 0) {
		zModule = **(**uintptr)(__ccgo_up((*(*struct {
			FnArg  int32
			FazArg uintptr
			Fp     uintptr
		})(unsafe.Pointer(pTab + 64))).FazArg))
		_sqlite3ErrorMsg(tls, pParse, __ccgo_ts+23579, libc.VaList(bp+16, zModule))
		rc = int32(SQLITE_ERROR)
	} else {
		**(**uintptr)(__ccgo_up(bp)) = uintptr(0)
		rc = _vtabCallConstructor(tls, db, pTab, pMod, (*Tsqlite3_module)(unsafe.Pointer((*TModule)(unsafe.Pointer(pMod)).FpModule)).FxConnect, bp)
		if rc != SQLITE_OK {
			_sqlite3ErrorMsg(tls, pParse, __ccgo_ts+3933, libc.VaList(bp+16, **(**uintptr)(__ccgo_up(bp))))
			(*TParse)(unsafe.Pointer(pParse)).Frc = rc
		}
		_sqlite3DbFree(tls, db, **(**uintptr)(__ccgo_up(bp)))
	}
	return rc
}

// C documentation
//
//	/*
//	** This function is invoked by the vdbe to call the xCreate method
//	** of the virtual table named zTab in database iDb.
//	**
//	** If an error occurs, *pzErr is set to point to an English language
//	** description of the error and an SQLITE_XXX error code is returned.
//	** In this case the caller must call sqlite3DbFree(db, ) on *pzErr.
//	*/
func _sqlite3VtabCallCreate(tls *libc.TLS, db uintptr, iDb int32, zTab uintptr, pzErr uintptr) (r int32) {
	bp := tls.Alloc(16)
	defer tls.Free(16)
	var pMod, pTab, zMod uintptr
	var rc int32
	_, _, _, _ = pMod, pTab, rc, zMod
	rc = SQLITE_OK
	pTab = _sqlite3FindTable(tls, db, zTab, (**(**TDb)(__ccgo_up((*Tsqlite3)(unsafe.Pointer(db)).FaDb + uintptr(iDb)*32))).FzDbSName)
	/* Locate the required virtual table module */
	zMod = **(**uintptr)(__ccgo_up((*(*struct {
		FnArg  int32
		FazArg uintptr
		Fp     uintptr
	})(unsafe.Pointer(pTab + 64))).FazArg))
	pMod = _sqlite3HashFind(tls, db+576, zMod)
	/* If the module has been registered and includes a Create method,
	 ** invoke it now. If the module has not been registered, return an
	 ** error. Otherwise, do nothing.
	 */
	if pMod == uintptr(0) || (*Tsqlite3_module)(unsafe.Pointer((*TModule)(unsafe.Pointer(pMod)).FpModule)).FxCreate == uintptr(0) || (*Tsqlite3_module)(unsafe.Pointer((*TModule)(unsafe.Pointer(pMod)).FpModule)).FxDestroy == uintptr(0) {
		**(**uintptr)(__ccgo_up(pzErr)) = _sqlite3MPrintf(tls, db, __ccgo_ts+23579, libc.VaList(bp+8, zMod))
		rc = int32(SQLITE_ERROR)
	} else {
		rc = _vtabCallConstructor(tls, db, pTab, pMod, (*Tsqlite3_module)(unsafe.Pointer((*TModule)(unsafe.Pointer(pMod)).FpModule)).FxCreate, pzErr)
	}
	/* Justification of ALWAYS():  The xConstructor method is required to
	 ** create a valid sqlite3_vtab if it returns SQLITE_OK. */
	if rc == SQLITE_OK && _sqlite3GetVTable(tls, db, pTab) != 0 {
		rc = _growVTrans(tls, db)
		if rc == SQLITE_OK {
			_addToVTrans(tls, db, _sqlite3GetVTable(tls, db, pTab))
		}
	}
	return rc
}

// C documentation
//
//	/*
//	** Check to see if virtual table module pMod can be have an eponymous
//	** virtual table instance.  If it can, create one if one does not already
//	** exist. Return non-zero if either the eponymous virtual table instance
//	** exists when this routine returns or if an attempt to create it failed
//	** and an error message was left in pParse.
//	**
//	** An eponymous virtual table instance is one that is named after its
//	** module, and more importantly, does not require a CREATE VIRTUAL TABLE
//	** statement in order to come into existence.  Eponymous virtual table
//	** instances always exist.  They cannot be DROP-ed.
//	**
//	** Any virtual table module for which xConnect and xCreate are the same
//	** method can have an eponymous virtual table instance.
//	*/
func _sqlite3VtabEponymousTableInit(tls *libc.TLS, pParse uintptr, pMod uintptr) (r int32) {
	bp := tls.Alloc(32)
	defer tls.Free(32)
	var db, pModule, pTab uintptr
	var rc int32
	var _ /* zErr at bp+0 */ uintptr
	_, _, _, _ = db, pModule, pTab, rc
	pModule = (*TModule)(unsafe.Pointer(pMod)).FpModule
	**(**uintptr)(__ccgo_up(bp)) = uintptr(0)
	db = (*TParse)(unsafe.Pointer(pParse)).Fdb
	if (*TModule)(unsafe.Pointer(pMod)).FpEpoTab != 0 {
		return int32(1)
	}
	if (*Tsqlite3_module)(unsafe.Pointer(pModule)).FxCreate != uintptr(0) && (*Tsqlite3_module)(unsafe.Pointer(pModule)).FxCreate != (*Tsqlite3_module)(unsafe.Pointer(pModule)).FxConnect {
		return 0
	}
	pTab = _sqlite3DbMallocZero(tls, db, uint64(120))
	if pTab == uintptr(0) {
		return 0
	}
	(*TTable)(unsafe.Pointer(pTab)).FzName = _sqlite3DbStrDup(tls, db, (*TModule)(unsafe.Pointer(pMod)).FzName)
	if (*TTable)(unsafe.Pointer(pTab)).FzName == uintptr(0) {
		_sqlite3DbFree(tls, db, pTab)
		return 0
	}
	(*TModule)(unsafe.Pointer(pMod)).FpEpoTab = pTab
	(*TTable)(unsafe.Pointer(pTab)).FnTabRef = uint32(1)
	(*TTable)(unsafe.Pointer(pTab)).FeTabType = uint8(TABTYP_VTAB)
	(*TTable)(unsafe.Pointer(pTab)).FpSchema = (**(**TDb)(__ccgo_up((*Tsqlite3)(unsafe.Pointer(db)).FaDb))).FpSchema
	(*TTable)(unsafe.Pointer(pTab)).FiPKey = int16(-int32(1))
	**(**Tu32)(__ccgo_up(pTab + 48)) |= uint32(TF_Eponymous)
	_addModuleArgument(tls, pParse, pTab, _sqlite3DbStrDup(tls, db, (*TTable)(unsafe.Pointer(pTab)).FzName))
	_addModuleArgument(tls, pParse, pTab, uintptr(0))
	_addModuleArgument(tls, pParse, pTab, _sqlite3DbStrDup(tls, db, (*TTable)(unsafe.Pointer(pTab)).FzName))
	(*Tsqlite3)(unsafe.Pointer(db)).FnSchemaLock = (*Tsqlite3)(unsafe.Pointer(db)).FnSchemaLock + 1
	rc = _vtabCallConstructor(tls, db, pTab, pMod, (*Tsqlite3_module)(unsafe.Pointer(pModule)).FxConnect, bp)
	(*Tsqlite3)(unsafe.Pointer(db)).FnSchemaLock = (*Tsqlite3)(unsafe.Pointer(db)).FnSchemaLock - 1
	if rc != 0 {
		_sqlite3ErrorMsg(tls, pParse, __ccgo_ts+3933, libc.VaList(bp+16, **(**uintptr)(__ccgo_up(bp))))
		(*TParse)(unsafe.Pointer(pParse)).Frc = rc
		_sqlite3DbFree(tls, db, **(**uintptr)(__ccgo_up(bp)))
		_sqlite3VtabEponymousTableClear(tls, db, pMod)
	}
	return int32(1)
}

// C documentation
//
//	/*
//	** The parser calls this routine after the CREATE VIRTUAL TABLE statement
//	** has been completely parsed.
//	*/
func _sqlite3VtabFinishParse(tls *libc.TLS, pParse uintptr, pEnd uintptr) {
	bp := tls.Alloc(48)
	defer tls.Free(48)
	var db, pOld, pSchema, pTab, v, zName, zStmt, zWhere, v2 uintptr
	var iDb, iReg, v1 int32
	_, _, _, _, _, _, _, _, _, _, _, _ = db, iDb, iReg, pOld, pSchema, pTab, v, zName, zStmt, zWhere, v1, v2
	pTab = (*TParse)(unsafe.Pointer(pParse)).FpNewTable /* The table being constructed */
	db = (*TParse)(unsafe.Pointer(pParse)).Fdb          /* The database connection */
	if pTab == uintptr(0) {
		return
	}
	_addArgumentToVtab(tls, pParse)
	(*TParse)(unsafe.Pointer(pParse)).FsArg.Fz = uintptr(0)
	if (*(*struct {
		FnArg  int32
		FazArg uintptr
		Fp     uintptr
	})(unsafe.Pointer(pTab + 64))).FnArg < int32(1) {
		return
	}
	/* If the CREATE VIRTUAL TABLE statement is being entered for the
	 ** first time (in other words if the virtual table is actually being
	 ** created now instead of just being read out of sqlite_schema) then
	 ** do additional initialization work and store the statement text
	 ** in the sqlite_schema table.
	 */
	if !((*Tsqlite3)(unsafe.Pointer(db)).Finit1.Fbusy != 0) {
		_sqlite3MayAbort(tls, pParse)
		/* Compute the complete text of the CREATE VIRTUAL TABLE statement */
		if pEnd != 0 {
			(*TParse)(unsafe.Pointer(pParse)).FsNameToken.Fn = libc.Uint32FromInt32(int32(int64((*TToken)(unsafe.Pointer(pEnd)).Fz)-int64((*TParse)(unsafe.Pointer(pParse)).FsNameToken.Fz))) + (*TToken)(unsafe.Pointer(pEnd)).Fn
		}
		zStmt = _sqlite3MPrintf(tls, db, __ccgo_ts+23319, libc.VaList(bp+8, pParse+232))
		/* A slot for the record has already been allocated in the
		 ** schema table.  We just need to update that slot with all
		 ** the information we've collected.
		 **
		 ** The VM register number pParse->u1.cr.regRowid holds the rowid of an
		 ** entry in the sqlite_schema table that was created for this vtab
		 ** by sqlite3StartTable().
		 */
		iDb = _sqlite3SchemaToIndex(tls, db, (*TTable)(unsafe.Pointer(pTab)).FpSchema)
		_sqlite3NestedParse(tls, pParse, __ccgo_ts+23343, libc.VaList(bp+8, (**(**TDb)(__ccgo_up((*Tsqlite3)(unsafe.Pointer(db)).FaDb + uintptr(iDb)*32))).FzDbSName, (*TTable)(unsafe.Pointer(pTab)).FzName, (*TTable)(unsafe.Pointer(pTab)).FzName, zStmt, (*(*struct {
			FaddrCrTab      int32
			FregRowid       int32
			FregRoot        int32
			FconstraintName TToken
		})(unsafe.Pointer(pParse + 256))).FregRowid))
		v = _sqlite3GetVdbe(tls, pParse)
		_sqlite3ChangeCookie(tls, pParse, iDb)
		_sqlite3VdbeAddOp0(tls, v, int32(OP_Expire))
		zWhere = _sqlite3MPrintf(tls, db, __ccgo_ts+23442, libc.VaList(bp+8, (*TTable)(unsafe.Pointer(pTab)).FzName, zStmt))
		_sqlite3VdbeAddParseSchemaOp(tls, v, iDb, zWhere, uint16(0))
		_sqlite3DbFree(tls, db, zStmt)
		v2 = pParse + 60
		*(*int32)(unsafe.Pointer(v2)) = *(*int32)(unsafe.Pointer(v2)) + 1
		v1 = *(*int32)(unsafe.Pointer(v2))
		iReg = v1
		_sqlite3VdbeLoadString(tls, v, iReg, (*TTable)(unsafe.Pointer(pTab)).FzName)
		_sqlite3VdbeAddOp2(tls, v, int32(OP_VCreate), iDb, iReg)
	} else {
		pSchema = (*TTable)(unsafe.Pointer(pTab)).FpSchema
		zName = (*TTable)(unsafe.Pointer(pTab)).FzName
		_sqlite3MarkAllShadowTablesOf(tls, db, pTab)
		pOld = _sqlite3HashInsert(tls, pSchema+8, zName, pTab)
		if pOld != 0 {
			_sqlite3OomFault(tls, db)
			/* Malloc must have failed inside HashInsert() */
			return
		}
		(*TParse)(unsafe.Pointer(pParse)).FpNewTable = uintptr(0)
	}
}

// C documentation
//
//	/*
//	** Generate the beginning of the loop used for WHERE clause processing.
//	** The return value is a pointer to an opaque structure that contains
//	** information needed to terminate the loop.  Later, the calling routine
//	** should invoke sqlite3WhereEnd() with the return value of this function
//	** in order to complete the WHERE clause processing.
//	**
//	** If an error occurs, this routine returns NULL.
//	**
//	** The basic idea is to do a nested loop, one loop for each table in
//	** the FROM clause of a select.  (INSERT and UPDATE statements are the
//	** same as a SELECT with only a single table in the FROM clause.)  For
//	** example, if the SQL is this:
//	**
//	**       SELECT * FROM t1, t2, t3 WHERE ...;
//	**
//	** Then the code generated is conceptually like the following:
//	**
//	**      foreach row1 in t1 do       \    Code generated
//	**        foreach row2 in t2 do      |-- by sqlite3WhereBegin()
//	**          foreach row3 in t3 do   /
//	**            ...
//	**          end                     \    Code generated
//	**        end                        |-- by sqlite3WhereEnd()
//	**      end                         /
//	**
//	** Note that the loops might not be nested in the order in which they
//	** appear in the FROM clause if a different order is better able to make
//	** use of indices.  Note also that when the IN operator appears in
//	** the WHERE clause, it might result in additional nested loops for
//	** scanning through all values on the right-hand side of the IN.
//	**
//	** There are Btree cursors associated with each table.  t1 uses cursor
//	** number pTabList->a[0].iCursor.  t2 uses the cursor pTabList->a[1].iCursor.
//	** And so forth.  This routine generates code to open those VDBE cursors
//	** and sqlite3WhereEnd() generates the code to close them.
//	**
//	** The code that sqlite3WhereBegin() generates leaves the cursors named
//	** in pTabList pointing at their appropriate entries.  The [...] code
//	** can use OP_Column and OP_Rowid opcodes on these cursors to extract
//	** data from the various tables of the loop.
//	**
//	** If the WHERE clause is empty, the foreach loops must each scan their
//	** entire tables.  Thus a three-way join is an O(N^3) operation.  But if
//	** the tables have indices and there are terms in the WHERE clause that
//	** refer to those indices, a complete table scan can be avoided and the
//	** code will run much faster.  Most of the work of this routine is checking
//	** to see if there are indices that can be used to speed up the loop.
//	**
//	** Terms of the WHERE clause are also used to limit which rows actually
//	** make it to the "..." in the middle of the loop.  After each "foreach",
//	** terms of the WHERE clause that use only terms in that loop and outer
//	** loops are evaluated and if false a jump is made around all subsequent
//	** inner loops (or around the "..." if the test occurs within the inner-
//	** most loop)
//	**
//	** OUTER JOINS
//	**
//	** An outer join of tables t1 and t2 is conceptually coded as follows:
//	**
//	**    foreach row1 in t1 do
//	**      flag = 0
//	**      foreach row2 in t2 do
//	**        start:
//	**          ...
//	**          flag = 1
//	**      end
//	**      if flag==0 then
//	**        move the row2 cursor to a null row
//	**        goto start
//	**      fi
//	**    end
//	**
//	** ORDER BY CLAUSE PROCESSING
//	**
//	** pOrderBy is a pointer to the ORDER BY clause (or the GROUP BY clause
//	** if the WHERE_GROUPBY flag is set in wctrlFlags) of a SELECT statement
//	** if there is one.  If there is no ORDER BY clause or if this routine
//	** is called from an UPDATE or DELETE statement, then pOrderBy is NULL.
//	**
//	** The iIdxCur parameter is the cursor number of an index.  If
//	** WHERE_OR_SUBCLAUSE is set, iIdxCur is the cursor number of an index
//	** to use for OR clause processing.  The WHERE clause should use this
//	** specific cursor.  If WHERE_ONEPASS_DESIRED is set, then iIdxCur is
//	** the first cursor in an array of cursors for all indices.  iIdxCur should
//	** be used to compute the appropriate cursor depending on which index is
//	** used.
//	*/
func _sqlite3WhereBegin(tls *libc.TLS, pParse uintptr, pTabList uintptr, pWhere uintptr, pOrderBy uintptr, pResultSet uintptr, pSelect uintptr, wctrlFlags Tu16, iAuxArg int32) (r uintptr) {
	bp := tls.Alloc(80)
	defer tls.Free(80)
	var addrExplain, bOnerow, iCur, iDb, iIndexCur, iOnce, ii, n, nByteWInfo, nTabList, op, op1, rc, wsFlags, wsFlags1, v1 int32
	var b, notReady TBitmask
	var bFordelete Tu8
	var db, p, pInfo, pIx, pJ, pLevel, pLoop, pMaskSet, pPk, pRJ, pSrc, pSubq, pT, pTab, pTabItem, pVTab, pWInfo, pX, v, v7, v8 uintptr
	var v19 bool
	var _ /* sWLB at bp+0 */ TWhereLoopBuilder
	_, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _ = addrExplain, b, bFordelete, bOnerow, db, iCur, iDb, iIndexCur, iOnce, ii, n, nByteWInfo, nTabList, notReady, op, op1, p, pInfo, pIx, pJ, pLevel, pLoop, pMaskSet, pPk, pRJ, pSrc, pSubq, pT, pTab, pTabItem, pVTab, pWInfo, pX, rc, v, wsFlags, wsFlags1, v1, v19, v7, v8 /* Will become the return value of this function */
	v = (*TParse)(unsafe.Pointer(pParse)).FpVdbe                                                                                                                                                                                                                                                                                                                                                          /* Return code */
	bFordelete = uint8(0)                                                                                                                                                                                                                                                                                                                                                                                 /* OPFLAG_FORDELETE or zero, as appropriate */
	/* Only one of WHERE_OR_SUBCLAUSE or WHERE_USE_LIMIT */
	/* Variable initialization */
	db = (*TParse)(unsafe.Pointer(pParse)).Fdb
	libc.Xmemset(tls, bp, 0, uint64(56))
	/* An ORDER/GROUP BY clause of more than 63 terms cannot be optimized */
	if pOrderBy != 0 && (*TExprList)(unsafe.Pointer(pOrderBy)).FnExpr >= libc.Int32FromUint64(libc.Uint64FromInt64(8)*libc.Uint64FromInt32(8)) {
		pOrderBy = uintptr(0)
		wctrlFlags = libc.Uint16FromInt32(int32(wctrlFlags) & ^libc.Int32FromInt32(WHERE_WANT_DISTINCT))
		wctrlFlags = libc.Uint16FromInt32(int32(wctrlFlags) | libc.Int32FromInt32(WHERE_KEEP_ALL_JOINS)) /* Disable omit-noop-join opt */
	}
	/* The number of tables in the FROM clause is limited by the number of
	 ** bits in a Bitmask
	 */
	if (*TSrcList)(unsafe.Pointer(pTabList)).FnSrc > libc.Int32FromUint64(libc.Uint64FromInt64(8)*libc.Uint64FromInt32(8)) {
		_sqlite3ErrorMsg(tls, pParse, __ccgo_ts+24093, libc.VaList(bp+64, libc.Int32FromUint64(libc.Uint64FromInt64(8)*libc.Uint64FromInt32(8))))
		return uintptr(0)
	}
	/* This function normally generates a nested loop for all tables in
	 ** pTabList.  But if the WHERE_OR_SUBCLAUSE flag is set, then we should
	 ** only generate code for the first table in pTabList and assume that
	 ** any cursors associated with subsequent tables are uninitialized.
	 */
	if libc.Int32FromUint16(wctrlFlags)&int32(WHERE_OR_SUBCLAUSE) != 0 {
		v1 = int32(1)
	} else {
		v1 = (*TSrcList)(unsafe.Pointer(pTabList)).FnSrc
	}
	nTabList = v1
	/* Allocate and initialize the WhereInfo structure that will become the
	 ** return value. A single allocation is used to store the WhereInfo
	 ** struct, the contents of WhereInfo.a[], the WhereClause structure
	 ** and the WhereMaskSet structure. Since WhereClause contains an 8-byte
	 ** field (type Bitmask) it must be aligned on an 8-byte boundary on
	 ** some architectures. Hence the ROUND8() below.
	 */
	nByteWInfo = libc.Int32FromUint64((uint64(libc.UintptrFromInt32(0)+856) + libc.Uint64FromInt32(nTabList)*libc.Uint64FromInt64(112) + libc.Uint64FromInt32(7)) & libc.Uint64FromInt32(^libc.Int32FromInt32(7)))
	pWInfo = _sqlite3DbMallocRawNN(tls, db, uint64(libc.Uint64FromInt32(nByteWInfo)+uint64(104)))
	if (*Tsqlite3)(unsafe.Pointer(db)).FmallocFailed != 0 {
		_sqlite3DbFree(tls, db, pWInfo)
		pWInfo = uintptr(0)
		goto whereBeginError
	}
	(*TWhereInfo)(unsafe.Pointer(pWInfo)).FpParse = pParse
	(*TWhereInfo)(unsafe.Pointer(pWInfo)).FpTabList = pTabList
	(*TWhereInfo)(unsafe.Pointer(pWInfo)).FpOrderBy = pOrderBy
	(*TWhereInfo)(unsafe.Pointer(pWInfo)).FpResultSet = pResultSet
	v1 = -libc.Int32FromInt32(1)
	**(**int32)(__ccgo_up(pWInfo + 40 + 1*4)) = v1
	**(**int32)(__ccgo_up(pWInfo + 40)) = v1
	(*TWhereInfo)(unsafe.Pointer(pWInfo)).FnLevel = libc.Uint8FromInt32(nTabList)
	v1 = _sqlite3VdbeMakeLabel(tls, pParse)
	(*TWhereInfo)(unsafe.Pointer(pWInfo)).FiContinue = v1
	(*TWhereInfo)(unsafe.Pointer(pWInfo)).FiBreak = v1
	(*TWhereInfo)(unsafe.Pointer(pWInfo)).FwctrlFlags = wctrlFlags
	(*TWhereInfo)(unsafe.Pointer(pWInfo)).FiLimit = int16(iAuxArg)
	(*TWhereInfo)(unsafe.Pointer(pWInfo)).FsavedNQueryLoop = int32((*TParse)(unsafe.Pointer(pParse)).FnQueryLoop)
	(*TWhereInfo)(unsafe.Pointer(pWInfo)).FpSelect = pSelect
	libc.Xmemset(tls, pWInfo+65, 0, uint64(libc.UintptrFromInt32(0)+104)-uint64(libc.UintptrFromInt32(0)+65))
	libc.Xmemset(tls, pWInfo+856, 0, uint64(104)+libc.Uint64FromInt32(nTabList)*uint64(112))
	/* ONEPASS defaults to OFF */
	pMaskSet = pWInfo + 592
	(*TWhereMaskSet)(unsafe.Pointer(pMaskSet)).Fn = 0
	**(**int32)(__ccgo_up(pMaskSet + 8)) = -int32(99) /* Initialize ix[0] to a value that can never be
	 ** a valid cursor number, to avoid an initial
	 ** test for pMaskSet->n==0 in sqlite3WhereGetMask() */
	(**(**TWhereLoopBuilder)(__ccgo_up(bp))).FpWInfo = pWInfo
	(**(**TWhereLoopBuilder)(__ccgo_up(bp))).FpWC = pWInfo + 104
	(**(**TWhereLoopBuilder)(__ccgo_up(bp))).FpNew = pWInfo + uintptr(nByteWInfo)
	_whereLoopInit(tls, (**(**TWhereLoopBuilder)(__ccgo_up(bp))).FpNew)
	/* Split the WHERE clause into separate subexpressions where each
	 ** subexpression is separated by an AND operator.
	 */
	_sqlite3WhereClauseInit(tls, pWInfo+104, pWInfo)
	_sqlite3WhereSplit(tls, pWInfo+104, pWhere, uint8(TK_AND))
	/* Special case: No FROM clause
	 */
	if nTabList == 0 {
		if pOrderBy != 0 {
			(*TWhereInfo)(unsafe.Pointer(pWInfo)).FnOBSat = int8((*TExprList)(unsafe.Pointer(pOrderBy)).FnExpr)
		}
		if libc.Int32FromUint16(wctrlFlags)&int32(WHERE_WANT_DISTINCT) != 0 && (*Tsqlite3)(unsafe.Pointer(db)).FdbOptFlags&libc.Uint32FromInt32(libc.Int32FromInt32(SQLITE_DistinctOpt)) == uint32(0) {
			(*TWhereInfo)(unsafe.Pointer(pWInfo)).FeDistinct = uint8(WHERE_DISTINCT_UNIQUE)
		}
		if (*TWhereInfo)(unsafe.Pointer(pWInfo)).FpSelect != 0 && (*TSelect)(unsafe.Pointer((*TWhereInfo)(unsafe.Pointer(pWInfo)).FpSelect)).FselFlags&uint32(SF_MultiValue) == uint32(0) {
			_sqlite3VdbeExplain(tls, pParse, uint8(0), __ccgo_ts+24121, 0)
		}
	} else {
		/* Assign a bit from the bitmask to every term in the FROM clause.
		 **
		 ** The N-th term of the FROM clause is assigned a bitmask of 1<<N.
		 **
		 ** The rule of the previous sentence ensures that if X is the bitmask for
		 ** a table T, then X-1 is the bitmask for all other tables to the left of T.
		 ** Knowing the bitmask for all tables to the left of a left join is
		 ** important.  Ticket #3015.
		 **
		 ** Note that bitmasks are created for all pTabList->nSrc tables in
		 ** pTabList, not just the first nTabList tables.  nTabList is normally
		 ** equal to pTabList->nSrc but might be shortened to 1 if the
		 ** WHERE_OR_SUBCLAUSE flag is set.
		 */
		ii = 0
		for {
			_createMask(tls, pMaskSet, (*(*TSrcItem)(unsafe.Pointer(pTabList + 8 + uintptr(ii)*80))).FiCursor)
			_sqlite3WhereTabFuncArgs(tls, pParse, pTabList+8+uintptr(ii)*80, pWInfo+104)
			goto _5
		_5:
			;
			ii = ii + 1
			v1 = ii
			if !(v1 < (*TSrcList)(unsafe.Pointer(pTabList)).FnSrc) {
				break
			}
		}
	}
	/* Analyze all of the subexpressions. */
	_sqlite3WhereExprAnalyze(tls, pTabList, pWInfo+104)
	if pSelect != 0 && (*TSelect)(unsafe.Pointer(pSelect)).FpLimit != 0 {
		_sqlite3WhereAddLimit(tls, pWInfo+104, pSelect)
	}
	if (*TParse)(unsafe.Pointer(pParse)).FnErr != 0 {
		goto whereBeginError
	}
	/* The False-WHERE-Term-Bypass optimization:
	 **
	 ** If there are WHERE terms that are false, then no rows will be output,
	 ** so skip over all of the code generated here.
	 **
	 ** Conditions:
	 **
	 **   (1)  The WHERE term must not refer to any tables in the join.
	 **   (2)  The term must not come from an ON clause on the
	 **        right-hand side of a LEFT or FULL JOIN.
	 **   (3)  The term must not come from an ON clause, or there must be
	 **        no RIGHT or FULL OUTER joins in pTabList.
	 **   (4)  If the expression contains non-deterministic functions
	 **        that are not within a sub-select. This is not required
	 **        for correctness but rather to preserves SQLite's legacy
	 **        behaviour in the following two cases:
	 **
	 **          WHERE random()>0;           -- eval random() once per row
	 **          WHERE (SELECT random())>0;  -- eval random() just once overall
	 **
	 ** Note that the Where term need not be a constant in order for this
	 ** optimization to apply, though it does need to be constant relative to
	 ** the current subquery (condition 1).  The term might include variables
	 ** from outer queries so that the value of the term changes from one
	 ** invocation of the current subquery to the next.
	 */
	ii = 0
	for {
		if !(ii < (*TWhereClause)(unsafe.Pointer((**(**TWhereLoopBuilder)(__ccgo_up(bp))).FpWC)).FnBase) {
			break
		}
		pT = (*TWhereClause)(unsafe.Pointer((**(**TWhereLoopBuilder)(__ccgo_up(bp))).FpWC)).Fa + uintptr(ii)*56 /* The expression of pT */
		if libc.Int32FromUint16((*TWhereTerm)(unsafe.Pointer(pT)).FwtFlags)&int32(TERM_VIRTUAL) != 0 {
			goto _6
		}
		pX = (*TWhereTerm)(unsafe.Pointer(pT)).FpExpr
		if (*TWhereTerm)(unsafe.Pointer(pT)).FprereqAll == uint64(0) && (nTabList == 0 || _exprIsDeterministic(tls, pX) != 0) && !((*TExpr)(unsafe.Pointer(pX)).Fflags&libc.Uint32FromInt32(libc.Int32FromInt32(EP_InnerON)) != uint32(0) && libc.Int32FromUint8((*(*TSrcItem)(unsafe.Pointer(pTabList + 8))).Ffg.Fjointype)&int32(JT_LTORJ) != 0) {
			_sqlite3ExprIfFalse(tls, pParse, pX, (*TWhereInfo)(unsafe.Pointer(pWInfo)).FiBreak, int32(SQLITE_JUMPIFNULL))
			v7 = pT + 18
			*(*Tu16)(unsafe.Pointer(v7)) = Tu16(int32(*(*Tu16)(unsafe.Pointer(v7))) | libc.Int32FromInt32(TERM_CODED))
		}
		goto _6
	_6:
		;
		ii = ii + 1
	}
	if libc.Int32FromUint16(wctrlFlags)&int32(WHERE_WANT_DISTINCT) != 0 {
		if (*Tsqlite3)(unsafe.Pointer(db)).FdbOptFlags&libc.Uint32FromInt32(libc.Int32FromInt32(SQLITE_DistinctOpt)) != uint32(0) {
			/* Disable the DISTINCT optimization if SQLITE_DistinctOpt is set via
			 ** sqlite3_test_ctrl(SQLITE_TESTCTRL_OPTIMIZATIONS,...) */
			wctrlFlags = libc.Uint16FromInt32(int32(wctrlFlags) & ^libc.Int32FromInt32(WHERE_WANT_DISTINCT))
			v7 = pWInfo + 60
			*(*Tu16)(unsafe.Pointer(v7)) = Tu16(int32(*(*Tu16)(unsafe.Pointer(v7))) & ^libc.Int32FromInt32(WHERE_WANT_DISTINCT))
		} else {
			if _isDistinctRedundant(tls, pParse, pTabList, pWInfo+104, pResultSet) != 0 {
				/* The DISTINCT marking is pointless.  Ignore it. */
				(*TWhereInfo)(unsafe.Pointer(pWInfo)).FeDistinct = uint8(WHERE_DISTINCT_UNIQUE)
			} else {
				if pOrderBy == uintptr(0) {
					/* Try to ORDER BY the result set to make distinct processing easier */
					v7 = pWInfo + 60
					*(*Tu16)(unsafe.Pointer(v7)) = Tu16(int32(*(*Tu16)(unsafe.Pointer(v7))) | libc.Int32FromInt32(WHERE_DISTINCTBY))
					(*TWhereInfo)(unsafe.Pointer(pWInfo)).FpOrderBy = pResultSet
				}
			}
		}
	}
	/* Construct the WhereLoop objects */
	if nTabList != int32(1) || _whereShortCut(tls, bp) == 0 {
		rc = _whereLoopAddAll(tls, bp)
		if rc != 0 {
			goto whereBeginError
		}
		/* If one or more WhereTerm.truthProb values were used in estimating
		 ** loop parameters, but then those truthProb values were subsequently
		 ** changed based on STAT4 information while computing subsequent loops,
		 ** then we need to rerun the whole loop building process so that all
		 ** loops will be built using the revised truthProb values. */
		if libc.Int32FromUint8((**(**TWhereLoopBuilder)(__ccgo_up(bp))).FbldFlags2)&int32(SQLITE_BLDF2_2NDPASS) != 0 {
			for (*TWhereInfo)(unsafe.Pointer(pWInfo)).FpLoops != 0 {
				p = (*TWhereInfo)(unsafe.Pointer(pWInfo)).FpLoops
				(*TWhereInfo)(unsafe.Pointer(pWInfo)).FpLoops = (*TWhereLoop)(unsafe.Pointer(p)).FpNextLoop
				_whereLoopDelete(tls, db, p)
			}
			rc = _whereLoopAddAll(tls, bp)
			if rc != 0 {
				goto whereBeginError
			}
		}
		_wherePathSolver(tls, pWInfo, 0)
		if (*Tsqlite3)(unsafe.Pointer(db)).FmallocFailed != 0 {
			goto whereBeginError
		}
		if (*TWhereInfo)(unsafe.Pointer(pWInfo)).FpOrderBy != 0 {
			_whereInterstageHeuristic(tls, pWInfo)
			if int32((*TWhereInfo)(unsafe.Pointer(pWInfo)).FnRowOut) < 0 {
				v1 = int32(1)
			} else {
				v1 = int32((*TWhereInfo)(unsafe.Pointer(pWInfo)).FnRowOut) + int32(1)
			}
			_wherePathSolver(tls, pWInfo, int16(v1))
			if (*Tsqlite3)(unsafe.Pointer(db)).FmallocFailed != 0 {
				goto whereBeginError
			}
		}
		/* TUNING:  Assume that a DISTINCT clause on a subquery reduces
		 ** the output size by a factor of 8 (LogEst -30).  Search for
		 ** tag-20250414a to see other cases.
		 */
		if libc.Int32FromUint16((*TWhereInfo)(unsafe.Pointer(pWInfo)).FwctrlFlags)&int32(WHERE_WANT_DISTINCT) != 0 {
			v7 = pWInfo + 70
			*(*TLogEst)(unsafe.Pointer(v7)) = TLogEst(int32(*(*TLogEst)(unsafe.Pointer(v7))) - libc.Int32FromInt32(30))
		}
	}
	if (*TWhereInfo)(unsafe.Pointer(pWInfo)).FpOrderBy == uintptr(0) && (*Tsqlite3)(unsafe.Pointer(db)).Fflags&uint64(SQLITE_ReverseOrder) != uint64(0) {
		_whereReverseScanOrder(tls, pWInfo)
	}
	if (*TParse)(unsafe.Pointer(pParse)).FnErr != 0 {
		goto whereBeginError
	}
	/* Attempt to omit tables from a join that do not affect the result.
	 ** See the comment on whereOmitNoopJoin() for further information.
	 **
	 ** This query optimization is factored out into a separate "no-inline"
	 ** procedure to keep the sqlite3WhereBegin() procedure from becoming
	 ** too large.  If sqlite3WhereBegin() becomes too large, that prevents
	 ** some C-compiler optimizers from in-lining the
	 ** sqlite3WhereCodeOneLoopStart() procedure, and it is important to
	 ** in-line sqlite3WhereCodeOneLoopStart() for performance reasons.
	 */
	notReady = ^libc.Uint64FromInt32(0)
	if libc.Int32FromUint8((*TWhereInfo)(unsafe.Pointer(pWInfo)).FnLevel) >= int32(2) && pResultSet != uintptr(0) && 0 == libc.Int32FromUint16(wctrlFlags)&(libc.Int32FromInt32(WHERE_AGG_DISTINCT)|libc.Int32FromInt32(WHERE_KEEP_ALL_JOINS)) && (*Tsqlite3)(unsafe.Pointer(db)).FdbOptFlags&libc.Uint32FromInt32(libc.Int32FromInt32(SQLITE_OmitNoopJoin)) == uint32(0) {
		notReady = _whereOmitNoopJoin(tls, pWInfo, notReady)
		nTabList = libc.Int32FromUint8((*TWhereInfo)(unsafe.Pointer(pWInfo)).FnLevel)
	}
	/* Check to see if there are any SEARCH loops that might benefit from
	 ** using a Bloom filter.
	 */
	if libc.Int32FromUint8((*TWhereInfo)(unsafe.Pointer(pWInfo)).FnLevel) >= int32(2) && (*Tsqlite3)(unsafe.Pointer(db)).FdbOptFlags&libc.Uint32FromInt32(libc.Int32FromInt32(SQLITE_BloomFilter)) == uint32(0) {
		_whereCheckIfBloomFilterIsUseful(tls, pWInfo)
	}
	v7 = (*TWhereInfo)(unsafe.Pointer(pWInfo)).FpParse + 28
	*(*TLogEst)(unsafe.Pointer(v7)) = TLogEst(int32(*(*TLogEst)(unsafe.Pointer(v7))) + int32((*TWhereInfo)(unsafe.Pointer(pWInfo)).FnRowOut))
	/* If the caller is an UPDATE or DELETE statement that is requesting
	 ** to use a one-pass algorithm, determine if this is appropriate.
	 **
	 ** A one-pass approach can be used if the caller has requested one
	 ** and either (a) the scan visits at most one row or (b) each
	 ** of the following are true:
	 **
	 **   * the caller has indicated that a one-pass approach can be used
	 **     with multiple rows (by setting WHERE_ONEPASS_MULTIROW), and
	 **   * the table is not a virtual table, and
	 **   * either the scan does not use the OR optimization or the caller
	 **     is a DELETE operation (WHERE_DUPLICATES_OK is only specified
	 **     for DELETE).
	 **
	 ** The last qualification is because an UPDATE statement uses
	 ** WhereInfo.aiCurOnePass[1] to determine whether or not it really can
	 ** use a one-pass approach, and this is not set accurately for scans
	 ** that use the OR optimization.
	 */
	if libc.Int32FromUint16(wctrlFlags)&int32(WHERE_ONEPASS_DESIRED) != 0 {
		wsFlags = libc.Int32FromUint32((*TWhereLoop)(unsafe.Pointer((*(*TWhereLevel)(unsafe.Pointer(pWInfo + 856))).FpWLoop)).FwsFlags)
		bOnerow = libc.BoolInt32(wsFlags&int32(WHERE_ONEROW) != 0)
		if bOnerow != 0 || 0 != libc.Int32FromUint16(wctrlFlags)&int32(WHERE_ONEPASS_MULTIROW) && !(libc.Int32FromUint8((*TTable)(unsafe.Pointer((*(*TSrcItem)(unsafe.Pointer(pTabList + 8))).FpSTab)).FeTabType) == libc.Int32FromInt32(TABTYP_VTAB)) && (0 == wsFlags&int32(WHERE_MULTI_OR) || libc.Int32FromUint16(wctrlFlags)&int32(WHERE_DUPLICATES_OK) != 0) && (*Tsqlite3)(unsafe.Pointer(db)).FdbOptFlags&libc.Uint32FromInt32(libc.Int32FromInt32(SQLITE_OnePass)) == uint32(0) {
			if bOnerow != 0 {
				v1 = int32(ONEPASS_SINGLE)
			} else {
				v1 = int32(ONEPASS_MULTI)
			}
			(*TWhereInfo)(unsafe.Pointer(pWInfo)).FeOnePass = libc.Uint8FromInt32(v1)
			if (*TTable)(unsafe.Pointer((*(*TSrcItem)(unsafe.Pointer(pTabList + 8))).FpSTab)).FtabFlags&uint32(TF_WithoutRowid) == uint32(0) && wsFlags&int32(WHERE_IDX_ONLY) != 0 {
				if libc.Int32FromUint16(wctrlFlags)&int32(WHERE_ONEPASS_MULTIROW) != 0 {
					bFordelete = uint8(OPFLAG_FORDELETE)
				}
				(*TWhereLoop)(unsafe.Pointer((*(*TWhereLevel)(unsafe.Pointer(pWInfo + 856))).FpWLoop)).FwsFlags = libc.Uint32FromInt32(wsFlags & ^libc.Int32FromInt32(WHERE_IDX_ONLY))
			}
		}
	}
	/* Open all tables in the pTabList and any indices selected for
	 ** searching those tables.
	 */
	ii = 0
	pLevel = pWInfo + 856
	for {
		if !(ii < nTabList) {
			break
		}
		pTabItem = pTabList + 8 + uintptr((*TWhereLevel)(unsafe.Pointer(pLevel)).FiFrom)*80
		pTab = (*TSrcItem)(unsafe.Pointer(pTabItem)).FpSTab
		iDb = _sqlite3SchemaToIndex(tls, db, (*TTable)(unsafe.Pointer(pTab)).FpSchema)
		pLoop = (*TWhereLevel)(unsafe.Pointer(pLevel)).FpWLoop
		(*TWhereLevel)(unsafe.Pointer(pLevel)).FaddrBrk = _sqlite3VdbeMakeLabel(tls, pParse)
		if ii == 0 || libc.Int32FromUint8((**(**TSrcItem)(__ccgo_up(pTabItem))).Ffg.Fjointype)&int32(JT_LEFT) != 0 {
			(*TWhereLevel)(unsafe.Pointer(pLevel)).FaddrHalt = (*TWhereLevel)(unsafe.Pointer(pLevel)).FaddrBrk
		} else {
			if (*(*TWhereLevel)(unsafe.Pointer(pWInfo + 856 + uintptr(ii-int32(1))*112))).FpRJ != 0 {
				(*TWhereLevel)(unsafe.Pointer(pLevel)).FaddrHalt = (*(*TWhereLevel)(unsafe.Pointer(pWInfo + 856 + uintptr(ii-int32(1))*112))).FaddrBrk
			} else {
				(*TWhereLevel)(unsafe.Pointer(pLevel)).FaddrHalt = (*(*TWhereLevel)(unsafe.Pointer(pWInfo + 856 + uintptr(ii-int32(1))*112))).FaddrHalt
			}
		}
		if (*TTable)(unsafe.Pointer(pTab)).FtabFlags&uint32(TF_Ephemeral) != uint32(0) || libc.Int32FromUint8((*TTable)(unsafe.Pointer(pTab)).FeTabType) == int32(TABTYP_VIEW) {
			/* Do nothing */
		} else {
			if (*TWhereLoop)(unsafe.Pointer(pLoop)).FwsFlags&uint32(WHERE_VIRTUALTABLE) != uint32(0) {
				pVTab = _sqlite3GetVTable(tls, db, pTab)
				iCur = (*TSrcItem)(unsafe.Pointer(pTabItem)).FiCursor
				_sqlite3VdbeAddOp4(tls, v, int32(OP_VOpen), iCur, 0, 0, pVTab, -int32(12))
			} else {
				if libc.Int32FromUint8((*TTable)(unsafe.Pointer(pTab)).FeTabType) == int32(TABTYP_VTAB) {
					/* noop */
				} else {
					if (*TWhereLoop)(unsafe.Pointer(pLoop)).FwsFlags&uint32(WHERE_IDX_ONLY) == uint32(0) && libc.Int32FromUint16(wctrlFlags)&int32(WHERE_OR_SUBCLAUSE) == 0 || libc.Int32FromUint8((*TSrcItem)(unsafe.Pointer(pTabItem)).Ffg.Fjointype)&(libc.Int32FromInt32(JT_LTORJ)|libc.Int32FromInt32(JT_RIGHT)) != 0 {
						op = int32(OP_OpenRead)
						if libc.Int32FromUint8((*TWhereInfo)(unsafe.Pointer(pWInfo)).FeOnePass) != ONEPASS_OFF {
							op = int32(OP_OpenWrite)
							**(**int32)(__ccgo_up(pWInfo + 40)) = (*TSrcItem)(unsafe.Pointer(pTabItem)).FiCursor
						}
						_sqlite3OpenTable(tls, pParse, (*TSrcItem)(unsafe.Pointer(pTabItem)).FiCursor, iDb, pTab, op)
						if libc.Int32FromUint8((*TWhereInfo)(unsafe.Pointer(pWInfo)).FeOnePass) == ONEPASS_OFF && int32((*TTable)(unsafe.Pointer(pTab)).FnCol) < libc.Int32FromUint64(libc.Uint64FromInt64(8)*libc.Uint64FromInt32(8)) && (*TTable)(unsafe.Pointer(pTab)).FtabFlags&libc.Uint32FromInt32(libc.Int32FromInt32(TF_HasGenerated)|libc.Int32FromInt32(TF_WithoutRowid)) == uint32(0) && (*TWhereLoop)(unsafe.Pointer(pLoop)).FwsFlags&libc.Uint32FromInt32(libc.Int32FromInt32(WHERE_AUTO_INDEX)|libc.Int32FromInt32(WHERE_BLOOMFILTER)) == uint32(0) {
							/* If we know that only a prefix of the record will be used,
							 ** it is advantageous to reduce the "column count" field in
							 ** the P4 operand of the OP_OpenRead/Write opcode. */
							b = (*TSrcItem)(unsafe.Pointer(pTabItem)).FcolUsed
							n = 0
							for {
								if !(b != 0) {
									break
								}
								goto _15
							_15:
								;
								b = b >> int32(1)
								n = n + 1
							}
							_sqlite3VdbeChangeP4(tls, v, -int32(1), uintptr(int64(n)), -int32(3))
						}
						_sqlite3VdbeChangeP5(tls, v, uint16(bFordelete))
						if ii >= int32(2) && libc.Int32FromUint8((**(**TSrcItem)(__ccgo_up(pTabItem))).Ffg.Fjointype)&(libc.Int32FromInt32(JT_LTORJ)|libc.Int32FromInt32(JT_LEFT)) == 0 && (*TWhereLevel)(unsafe.Pointer(pLevel)).FaddrHalt == (*(*TWhereLevel)(unsafe.Pointer(pWInfo + 856))).FaddrHalt {
							_sqlite3VdbeAddOp2(tls, v, int32(OP_IfEmpty), (*TSrcItem)(unsafe.Pointer(pTabItem)).FiCursor, (*TWhereInfo)(unsafe.Pointer(pWInfo)).FiBreak)
						}
					} else {
						_sqlite3TableLock(tls, pParse, iDb, (*TTable)(unsafe.Pointer(pTab)).Ftnum, uint8(0), (*TTable)(unsafe.Pointer(pTab)).FzName)
					}
				}
			}
		}
		if (*TWhereLoop)(unsafe.Pointer(pLoop)).FwsFlags&uint32(WHERE_INDEXED) != 0 {
			pIx = (*(*struct {
				FnEq          Tu16
				FnBtm         Tu16
				FnTop         Tu16
				FnDistinctCol Tu16
				FpIndex       uintptr
				FpOrderBy     uintptr
			})(unsafe.Pointer(pLoop + 24))).FpIndex
			op1 = int32(OP_OpenRead)
			/* iAuxArg is always set to a positive value if ONEPASS is possible */
			if !((*TTable)(unsafe.Pointer(pTab)).FtabFlags&libc.Uint32FromInt32(TF_WithoutRowid) == libc.Uint32FromInt32(0)) && int32(uint32(*(*uint16)(unsafe.Pointer(pIx + 100))&0x3>>0)) == int32(SQLITE_IDXTYPE_PRIMARYKEY) && libc.Int32FromUint16(wctrlFlags)&int32(WHERE_OR_SUBCLAUSE) != 0 {
				/* This is one term of an OR-optimization using the PRIMARY KEY of a
				 ** WITHOUT ROWID table.  No need for a separate index */
				iIndexCur = (*TWhereLevel)(unsafe.Pointer(pLevel)).FiTabCur
				op1 = 0
			} else {
				if libc.Int32FromUint8((*TWhereInfo)(unsafe.Pointer(pWInfo)).FeOnePass) != ONEPASS_OFF {
					pJ = (*TTable)(unsafe.Pointer((*TSrcItem)(unsafe.Pointer(pTabItem)).FpSTab)).FpIndex
					iIndexCur = iAuxArg
					for pJ != 0 && pJ != pIx {
						iIndexCur = iIndexCur + 1
						pJ = (*TIndex)(unsafe.Pointer(pJ)).FpNext
					}
					op1 = int32(OP_OpenWrite)
					**(**int32)(__ccgo_up(pWInfo + 40 + 1*4)) = iIndexCur
				} else {
					if iAuxArg != 0 && libc.Int32FromUint16(wctrlFlags)&int32(WHERE_OR_SUBCLAUSE) != 0 {
						iIndexCur = iAuxArg
						op1 = int32(OP_ReopenIdx)
					} else {
						v7 = pParse + 56
						v1 = *(*int32)(unsafe.Pointer(v7))
						*(*int32)(unsafe.Pointer(v7)) = *(*int32)(unsafe.Pointer(v7)) + 1
						iIndexCur = v1
						if int32(uint32(*(*uint16)(unsafe.Pointer(pIx + 100))&0x800>>11)) != 0 && (*Tsqlite3)(unsafe.Pointer(db)).FdbOptFlags&libc.Uint32FromInt32(libc.Int32FromInt32(SQLITE_IndexedExpr)) == uint32(0) {
							_whereAddIndexedExpr(tls, pParse, pIx, iIndexCur, pTabItem)
						}
						if (*TIndex)(unsafe.Pointer(pIx)).FpPartIdxWhere != 0 && libc.Int32FromUint8((*TSrcItem)(unsafe.Pointer(pTabItem)).Ffg.Fjointype)&int32(JT_RIGHT) == 0 {
							_wherePartIdxExpr(tls, pParse, pIx, (*TIndex)(unsafe.Pointer(pIx)).FpPartIdxWhere, uintptr(0), iIndexCur, pTabItem)
						}
					}
				}
			}
			(*TWhereLevel)(unsafe.Pointer(pLevel)).FiIdxCur = iIndexCur
			if op1 != 0 {
				_sqlite3VdbeAddOp3(tls, v, op1, iIndexCur, libc.Int32FromUint32((*TIndex)(unsafe.Pointer(pIx)).Ftnum), iDb)
				_sqlite3VdbeSetP4KeyInfo(tls, pParse, pIx)
				if (*TWhereLoop)(unsafe.Pointer(pLoop)).FwsFlags&uint32(WHERE_CONSTRAINT) != uint32(0) && (*TWhereLoop)(unsafe.Pointer(pLoop)).FwsFlags&libc.Uint32FromInt32(libc.Int32FromInt32(WHERE_COLUMN_RANGE)|libc.Int32FromInt32(WHERE_SKIPSCAN)) == uint32(0) && (*TWhereLoop)(unsafe.Pointer(pLoop)).FwsFlags&uint32(WHERE_BIGNULL_SORT) == uint32(0) && (*TWhereLoop)(unsafe.Pointer(pLoop)).FwsFlags&uint32(WHERE_IN_SEEKSCAN) == uint32(0) && libc.Int32FromUint16((*TWhereInfo)(unsafe.Pointer(pWInfo)).FwctrlFlags)&int32(WHERE_ORDERBY_MIN) == 0 && libc.Int32FromUint8((*TWhereInfo)(unsafe.Pointer(pWInfo)).FeDistinct) != int32(WHERE_DISTINCT_ORDERED) {
					_sqlite3VdbeChangeP5(tls, v, uint16(OPFLAG_SEEKEQ))
				}
			}
		}
		if iDb >= 0 {
			_sqlite3CodeVerifySchema(tls, pParse, iDb)
		}
		if v19 = libc.Int32FromUint8((*TSrcItem)(unsafe.Pointer(pTabItem)).Ffg.Fjointype)&int32(JT_RIGHT) != 0; v19 {
			v7 = _sqlite3WhereMalloc(tls, pWInfo, uint64(20))
			(*TWhereLevel)(unsafe.Pointer(pLevel)).FpRJ = v7
		}
		if v19 && v7 != uintptr(0) {
			pRJ = (*TWhereLevel)(unsafe.Pointer(pLevel)).FpRJ
			v8 = pParse + 56
			v1 = *(*int32)(unsafe.Pointer(v8))
			*(*int32)(unsafe.Pointer(v8)) = *(*int32)(unsafe.Pointer(v8)) + 1
			(*TWhereRightJoin)(unsafe.Pointer(pRJ)).FiMatch = v1
			v7 = pParse + 60
			*(*int32)(unsafe.Pointer(v7)) = *(*int32)(unsafe.Pointer(v7)) + 1
			v1 = *(*int32)(unsafe.Pointer(v7))
			(*TWhereRightJoin)(unsafe.Pointer(pRJ)).FregBloom = v1
			_sqlite3VdbeAddOp2(tls, v, int32(OP_Blob), int32(65536), (*TWhereRightJoin)(unsafe.Pointer(pRJ)).FregBloom)
			v7 = pParse + 60
			*(*int32)(unsafe.Pointer(v7)) = *(*int32)(unsafe.Pointer(v7)) + 1
			v1 = *(*int32)(unsafe.Pointer(v7))
			(*TWhereRightJoin)(unsafe.Pointer(pRJ)).FregReturn = v1
			_sqlite3VdbeAddOp2(tls, v, int32(OP_Null), 0, (*TWhereRightJoin)(unsafe.Pointer(pRJ)).FregReturn)
			if (*TTable)(unsafe.Pointer(pTab)).FtabFlags&uint32(TF_WithoutRowid) == uint32(0) {
				_sqlite3VdbeAddOp2(tls, v, int32(OP_OpenEphemeral), (*TWhereRightJoin)(unsafe.Pointer(pRJ)).FiMatch, int32(1))
				pInfo = _sqlite3KeyInfoAlloc(tls, (*TParse)(unsafe.Pointer(pParse)).Fdb, int32(1), 0)
				if pInfo != 0 {
					*(*uintptr)(unsafe.Pointer(pInfo + 32)) = uintptr(0)
					**(**Tu8)(__ccgo_up((*TKeyInfo)(unsafe.Pointer(pInfo)).FaSortFlags)) = uint8(0)
					_sqlite3VdbeAppendP4(tls, v, pInfo, -int32(9))
				}
			} else {
				pPk = _sqlite3PrimaryKeyIndex(tls, pTab)
				_sqlite3VdbeAddOp2(tls, v, int32(OP_OpenEphemeral), (*TWhereRightJoin)(unsafe.Pointer(pRJ)).FiMatch, libc.Int32FromUint16((*TIndex)(unsafe.Pointer(pPk)).FnKeyCol))
				_sqlite3VdbeSetP4KeyInfo(tls, pParse, pPk)
			}
			**(**Tu32)(__ccgo_up(pLoop + 48)) &= libc.Uint32FromInt32(^libc.Int32FromInt32(WHERE_IDX_ONLY))
			/* The nature of RIGHT JOIN processing is such that it messes up
			 ** the output order.  So omit any ORDER BY/GROUP BY elimination
			 ** optimizations.  We need to do an actual sort for RIGHT JOIN. */
			(*TWhereInfo)(unsafe.Pointer(pWInfo)).FnOBSat = 0
			(*TWhereInfo)(unsafe.Pointer(pWInfo)).FeDistinct = uint8(WHERE_DISTINCT_UNORDERED)
		}
		goto _14
	_14:
		;
		ii = ii + 1
		pLevel += 112
	}
	(*TWhereInfo)(unsafe.Pointer(pWInfo)).FiTop = _sqlite3VdbeCurrentAddr(tls, v)
	if (*Tsqlite3)(unsafe.Pointer(db)).FmallocFailed != 0 {
		goto whereBeginError
	}
	/* Generate the code to do the search.  Each iteration of the for
	 ** loop below generates code for a single nested loop of the VM
	 ** program.
	 */
	ii = 0
	for {
		if !(ii < nTabList) {
			break
		}
		if (*TParse)(unsafe.Pointer(pParse)).FnErr != 0 {
			goto whereBeginError
		}
		pLevel = pWInfo + 856 + uintptr(ii)*112
		wsFlags1 = libc.Int32FromUint32((*TWhereLoop)(unsafe.Pointer((*TWhereLevel)(unsafe.Pointer(pLevel)).FpWLoop)).FwsFlags)
		pSrc = pTabList + 8 + uintptr((*TWhereLevel)(unsafe.Pointer(pLevel)).FiFrom)*80
		if int32(*(*uint32)(unsafe.Pointer(pSrc + 24 + 4))&0x20>>5) != 0 {
			iOnce = 0
			pSubq = *(*uintptr)(unsafe.Pointer(pSrc + 72))
			if int32(*(*uint32)(unsafe.Pointer(pSrc + 24 + 4))&0x10>>4) == 0 {
				iOnce = _sqlite3VdbeAddOp0(tls, v, int32(OP_Once))
			} else {
				iOnce = 0
			}
			_sqlite3VdbeAddOp2(tls, v, int32(OP_Gosub), (*TSubquery)(unsafe.Pointer(pSubq)).FregReturn, (*TSubquery)(unsafe.Pointer(pSubq)).FaddrFillSub)
			if iOnce != 0 {
				_sqlite3VdbeJumpHere(tls, v, iOnce)
			}
		}
		if wsFlags1&(libc.Int32FromInt32(WHERE_AUTO_INDEX)|libc.Int32FromInt32(WHERE_BLOOMFILTER)) != 0 {
			if wsFlags1&int32(WHERE_AUTO_INDEX) != 0 {
				_constructAutomaticIndex(tls, pParse, pWInfo+104, notReady, pLevel)
			} else {
				_sqlite3ConstructBloomFilter(tls, pWInfo, ii, pLevel, notReady)
			}
			if (*Tsqlite3)(unsafe.Pointer(db)).FmallocFailed != 0 {
				goto whereBeginError
			}
		}
		addrExplain = _sqlite3WhereExplainOneScan(tls, pParse, pTabList, pLevel, wctrlFlags)
		(*TWhereLevel)(unsafe.Pointer(pLevel)).FaddrBody = _sqlite3VdbeCurrentAddr(tls, v)
		notReady = _sqlite3WhereCodeOneLoopStart(tls, pParse, v, pWInfo, ii, pLevel, notReady)
		(*TWhereInfo)(unsafe.Pointer(pWInfo)).FiContinue = (*TWhereLevel)(unsafe.Pointer(pLevel)).FaddrCont
		if wsFlags1&int32(WHERE_MULTI_OR) == 0 && libc.Int32FromUint16(wctrlFlags)&int32(WHERE_OR_SUBCLAUSE) == 0 {
			_ = addrExplain
		}
		goto _26
	_26:
		;
		ii = ii + 1
	}
	/* Done. */
	(*TWhereInfo)(unsafe.Pointer(pWInfo)).FiEndWhere = _sqlite3VdbeCurrentAddr(tls, v)
	return pWInfo
	/* Jump here if malloc fails */
	goto whereBeginError
whereBeginError:
	;
	if pWInfo != 0 {
		(*TParse)(unsafe.Pointer(pParse)).FnQueryLoop = int16((*TWhereInfo)(unsafe.Pointer(pWInfo)).FsavedNQueryLoop)
		_whereInfoFree(tls, db, pWInfo)
	}
	return uintptr(0)
}

/*
** Part of sqlite3WhereEnd() will rewrite opcodes to reference the
** index rather than the main table.  In SQLITE_DEBUG mode, we want
** to trace those changes if PRAGMA vdbe_addoptrace=on.  This routine
** does that.
 */

// C documentation
//
//	/*
//	** Generate code for the start of the iLevel-th loop in the WHERE clause
//	** implementation described by pWInfo.
//	*/
func _sqlite3WhereCodeOneLoopStart(tls *libc.TLS, pParse uintptr, v uintptr, pWInfo uintptr, iLevel int32, pLevel uintptr, notReady TBitmask) (r2 TBitmask) {
	bp := tls.Alloc(112)
	defer tls.Free(112)
	var aMoveOp [4]Tu8
	var addrBrk, addrCont, addrExplain, addrNotFound, addrNxt, addrSeekScan, bRev, endEq, iCache, iCol, iCol1, iCovCur, iCur, iFld, iIdxCur, iIn, iLoop, iLoopBody, iNext, iPk, iPk1, iReg, iReleaseReg, iRetInit, iRowidReg, iSet, iTab, iTarget, iTerm, ii, j, jmp1, jmp11, k, memEndValue, nConstraint, nConstraint1, nExtraReg, nNotReady, nPk, nPk1, omitTable, op, op1, r, r1, r11, regBase, regBignull, regReturn, regRowid, regRowset, regYield, skipLikeAddr, start, startEq, start_constraints, testOp, untestedTerms, v1, v2 int32
	var bSeekPastNull, bStopAtNull, t1, t2 Tu8
	var db, origSrc, pAlt, pAndExpr, pCompare, pCov, pDelete, pE, pE1, pEnd, pExpr, pIdx, pLeft, pLoop, pOp, pOrExpr, pOrTab, pOrTerm, pOrWc, pPk, pPk1, pPk2, pPk3, pRJ, pRJ1, pRangeEnd, pRangeStart, pRight, pRight1, pRight2, pRight3, pStart, pSubLoop, pSubWInfo, pSubq, pTab, pTab1, pTabItem, pTerm, pWC, pX, pX1, t, zEndAff, v4, v8 uintptr
	var m TBitmask
	var nBtm, nEq, nTop Tu16
	var v6 uint32
	var v15 bool
	var _ /* rTemp at bp+0 */ int32
	var _ /* sEAlt at bp+16 */ TExpr
	var _ /* zStartAff at bp+8 */ uintptr
	_, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _ = aMoveOp, addrBrk, addrCont, addrExplain, addrNotFound, addrNxt, addrSeekScan, bRev, bSeekPastNull, bStopAtNull, db, endEq, iCache, iCol, iCol1, iCovCur, iCur, iFld, iIdxCur, iIn, iLoop, iLoopBody, iNext, iPk, iPk1, iReg, iReleaseReg, iRetInit, iRowidReg, iSet, iTab, iTarget, iTerm, ii, j, jmp1, jmp11, k, m, memEndValue, nBtm, nConstraint, nConstraint1, nEq, nExtraReg, nNotReady, nPk, nPk1, nTop, omitTable, op, op1, origSrc, pAlt, pAndExpr, pCompare, pCov, pDelete, pE, pE1, pEnd, pExpr, pIdx, pLeft, pLoop, pOp, pOrExpr, pOrTab, pOrTerm, pOrWc, pPk, pPk1, pPk2, pPk3, pRJ, pRJ1, pRangeEnd, pRangeStart, pRight, pRight1, pRight2, pRight3, pStart, pSubLoop, pSubWInfo, pSubq, pTab, pTab1, pTabItem, pTerm, pWC, pX, pX1, r, r1, r11, regBase, regBignull, regReturn, regRowid, regRowset, regYield, skipLikeAddr, start, startEq, start_constraints, t, t1, t2, testOp, untestedTerms, zEndAff, v1, v15, v2, v4, v6, v8 /* Jump here to continue with next cycle */
	iRowidReg = 0                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                       /* Rowid is stored in this register, if not zero */
	iReleaseReg = 0                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                     /* Temp register to free before returning */
	pIdx = uintptr(0)                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                   /* Iteration of constraint generator loop */
	pWC = pWInfo + 104
	db = (*TParse)(unsafe.Pointer(pParse)).Fdb
	pLoop = (*TWhereLevel)(unsafe.Pointer(pLevel)).FpWLoop
	pTabItem = (*TWhereInfo)(unsafe.Pointer(pWInfo)).FpTabList + 8 + uintptr((*TWhereLevel)(unsafe.Pointer(pLevel)).FiFrom)*80
	iCur = (*TSrcItem)(unsafe.Pointer(pTabItem)).FiCursor
	(*TWhereLevel)(unsafe.Pointer(pLevel)).FnotReady = notReady & ^_sqlite3WhereGetMask(tls, pWInfo+592, iCur)
	bRev = libc.Int32FromUint64((*TWhereInfo)(unsafe.Pointer(pWInfo)).FrevMask >> iLevel & uint64(1))
	/* Create labels for the "break" and "continue" instructions
	 ** for the current loop.  Jump to addrBrk to break out of a loop.
	 ** Jump to cont to go immediately to the next iteration of the
	 ** loop.
	 **
	 ** When there is an IN operator, we also have a "addrNxt" label that
	 ** means to continue with the next IN value combination.  When
	 ** there are no IN operators in the constraints, the "addrNxt" label
	 ** is the same as "addrBrk".
	 */
	v1 = (*TWhereLevel)(unsafe.Pointer(pLevel)).FaddrBrk
	(*TWhereLevel)(unsafe.Pointer(pLevel)).FaddrNxt = v1
	addrBrk = v1
	v1 = _sqlite3VdbeMakeLabel(tls, pParse)
	(*TWhereLevel)(unsafe.Pointer(pLevel)).FaddrCont = v1
	addrCont = v1
	/* If this is the right table of a LEFT OUTER JOIN, allocate and
	 ** initialize a memory cell that records if this table matches any
	 ** row of the left table of the join.
	 */
	if libc.Int32FromUint8((*TWhereLevel)(unsafe.Pointer(pLevel)).FiFrom) > 0 && libc.Int32FromUint8((**(**TSrcItem)(__ccgo_up(pTabItem))).Ffg.Fjointype)&int32(JT_LEFT) != 0 {
		v4 = pParse + 60
		*(*int32)(unsafe.Pointer(v4)) = *(*int32)(unsafe.Pointer(v4)) + 1
		v1 = *(*int32)(unsafe.Pointer(v4))
		(*TWhereLevel)(unsafe.Pointer(pLevel)).FiLeftJoin = v1
		_sqlite3VdbeAddOp2(tls, v, int32(OP_Integer), 0, (*TWhereLevel)(unsafe.Pointer(pLevel)).FiLeftJoin)
	}
	/* Special case of a FROM clause subquery implemented as a co-routine */
	if int32(*(*uint32)(unsafe.Pointer(pTabItem + 24 + 4))&0x40>>6) != 0 {
		pSubq = *(*uintptr)(unsafe.Pointer(pTabItem + 72))
		regYield = (*TSubquery)(unsafe.Pointer(pSubq)).FregReturn
		_sqlite3VdbeAddOp3(tls, v, int32(OP_InitCoroutine), regYield, 0, (*TSubquery)(unsafe.Pointer(pSubq)).FaddrFillSub)
		(*TWhereLevel)(unsafe.Pointer(pLevel)).Fp2 = _sqlite3VdbeAddOp2(tls, v, int32(OP_Yield), regYield, addrBrk)
		(*TWhereLevel)(unsafe.Pointer(pLevel)).Fop = uint8(OP_Goto)
	} else {
		if (*TWhereLoop)(unsafe.Pointer(pLoop)).FwsFlags&uint32(WHERE_VIRTUALTABLE) != uint32(0) {
			nConstraint = libc.Int32FromUint16((*TWhereLoop)(unsafe.Pointer(pLoop)).FnLTerm)
			iReg = _sqlite3GetTempRange(tls, pParse, nConstraint+int32(2))
			addrNotFound = (*TWhereLevel)(unsafe.Pointer(pLevel)).FaddrBrk
			j = 0
			for {
				if !(j < nConstraint) {
					break
				}
				iTarget = iReg + j + int32(2)
				pTerm = **(**uintptr)(__ccgo_up((*TWhereLoop)(unsafe.Pointer(pLoop)).FaLTerm + uintptr(j)*8))
				if pTerm == uintptr(0) {
					goto _5
				}
				if libc.Int32FromUint16((*TWhereTerm)(unsafe.Pointer(pTerm)).FeOperator)&int32(WO_IN) != 0 {
					if j <= int32(31) {
						v6 = libc.Uint32FromInt32(1) << j
					} else {
						v6 = uint32(0)
					}
					if v6&(*(*struct {
						FidxNum    int32
						F__ccgo4   uint8
						FisOrdered Ti8
						FomitMask  Tu16
						FidxStr    uintptr
						FmHandleIn Tu32
					})(unsafe.Pointer(pLoop + 24))).FmHandleIn != 0 {
						v4 = pParse + 56
						v1 = *(*int32)(unsafe.Pointer(v4))
						*(*int32)(unsafe.Pointer(v4)) = *(*int32)(unsafe.Pointer(v4)) + 1
						iTab = v1
						v8 = pParse + 60
						*(*int32)(unsafe.Pointer(v8)) = *(*int32)(unsafe.Pointer(v8)) + 1
						v2 = *(*int32)(unsafe.Pointer(v8))
						iCache = v2
						_sqlite3CodeRhsOfIN(tls, pParse, (*TWhereTerm)(unsafe.Pointer(pTerm)).FpExpr, iTab, 0)
						_sqlite3VdbeAddOp3(tls, v, int32(OP_VInitIn), iTab, iTarget, iCache)
					} else {
						_codeEqualityTerm(tls, pParse, pTerm, pLevel, j, bRev, iTarget)
						addrNotFound = (*TWhereLevel)(unsafe.Pointer(pLevel)).FaddrNxt
					}
				} else {
					pRight = (*TExpr)(unsafe.Pointer((*TWhereTerm)(unsafe.Pointer(pTerm)).FpExpr)).FpRight
					_codeExprOrVector(tls, pParse, pRight, iTarget, int32(1))
					if libc.Int32FromUint8((*TWhereTerm)(unsafe.Pointer(pTerm)).FeMatchOp) == int32(SQLITE_INDEX_CONSTRAINT_OFFSET) && int32(Tu32(*(*uint8)(unsafe.Pointer(pLoop + 24 + 4))&0x2>>1)) != 0 {
						_sqlite3VdbeAddOp2(tls, v, int32(OP_Integer), 0, (*TSelect)(unsafe.Pointer((*TWhereInfo)(unsafe.Pointer(pWInfo)).FpSelect)).FiOffset)
					}
				}
				goto _5
			_5:
				;
				j = j + 1
			}
			_sqlite3VdbeAddOp2(tls, v, int32(OP_Integer), (*(*struct {
				FidxNum    int32
				F__ccgo4   uint8
				FisOrdered Ti8
				FomitMask  Tu16
				FidxStr    uintptr
				FmHandleIn Tu32
			})(unsafe.Pointer(pLoop + 24))).FidxNum, iReg)
			_sqlite3VdbeAddOp2(tls, v, int32(OP_Integer), nConstraint, iReg+int32(1))
			/* The instruction immediately prior to OP_VFilter must be an OP_Integer
			 ** that sets the "argc" value for xVFilter.  This is necessary for
			 ** resolveP2() to work correctly.  See tag-20250207a. */
			if int32(Tu32(*(*uint8)(unsafe.Pointer(pLoop + 24 + 4))&0x1>>0)) != 0 {
				v1 = -int32(7)
			} else {
				v1 = -int32(1)
			}
			_sqlite3VdbeAddOp4(tls, v, int32(OP_VFilter), iCur, addrNotFound, iReg, (*(*struct {
				FidxNum    int32
				F__ccgo4   uint8
				FisOrdered Ti8
				FomitMask  Tu16
				FidxStr    uintptr
				FmHandleIn Tu32
			})(unsafe.Pointer(pLoop + 24))).FidxStr, v1)
			libc.SetBitFieldPtr8Uint32(pLoop+24+4, libc.Uint32FromInt32(0), 0, 0x1)
			/* An OOM inside of AddOp4(OP_VFilter) instruction above might have freed
			 ** the u.vtab.idxStr.  NULL it out to prevent a use-after-free */
			if (*Tsqlite3)(unsafe.Pointer(db)).FmallocFailed != 0 {
				(*(*struct {
					FidxNum    int32
					F__ccgo4   uint8
					FisOrdered Ti8
					FomitMask  Tu16
					FidxStr    uintptr
					FmHandleIn Tu32
				})(unsafe.Pointer(pLoop + 24))).FidxStr = uintptr(0)
			}
			(*TWhereLevel)(unsafe.Pointer(pLevel)).Fp1 = iCur
			if (*TWhereInfo)(unsafe.Pointer(pWInfo)).FeOnePass != 0 {
				v1 = int32(OP_Noop)
			} else {
				v1 = int32(OP_VNext)
			}
			(*TWhereLevel)(unsafe.Pointer(pLevel)).Fop = libc.Uint8FromInt32(v1)
			(*TWhereLevel)(unsafe.Pointer(pLevel)).Fp2 = _sqlite3VdbeCurrentAddr(tls, v)
			j = 0
			for {
				if !(j < nConstraint) {
					break
				}
				pTerm = **(**uintptr)(__ccgo_up((*TWhereLoop)(unsafe.Pointer(pLoop)).FaLTerm + uintptr(j)*8))
				if j < int32(16) && libc.Int32FromUint16((*(*struct {
					FidxNum    int32
					F__ccgo4   uint8
					FisOrdered Ti8
					FomitMask  Tu16
					FidxStr    uintptr
					FmHandleIn Tu32
				})(unsafe.Pointer(pLoop + 24))).FomitMask)>>j&int32(1) != 0 {
					_disableTerm(tls, pLevel, pTerm)
					goto _13
				}
				if v15 = libc.Int32FromUint16((*TWhereTerm)(unsafe.Pointer(pTerm)).FeOperator)&int32(WO_IN) != 0; v15 {
					if j <= int32(31) {
						v6 = libc.Uint32FromInt32(1) << j
					} else {
						v6 = uint32(0)
					}
				}
				if v15 && v6&(*(*struct {
					FidxNum    int32
					F__ccgo4   uint8
					FisOrdered Ti8
					FomitMask  Tu16
					FidxStr    uintptr
					FmHandleIn Tu32
				})(unsafe.Pointer(pLoop + 24))).FmHandleIn == uint32(0) && !((*Tsqlite3)(unsafe.Pointer(db)).FmallocFailed != 0) { /* IN loop corresponding to the j-th constraint */
					/* Reload the constraint value into reg[iReg+j+2].  The same value
					 ** was loaded into the same register prior to the OP_VFilter, but
					 ** the xFilter implementation might have changed the datatype or
					 ** encoding of the value in the register, so it *must* be reloaded.
					 */
					iIn = 0
					for {
						if !(iIn < (*(*struct {
							FnIn     int32
							FaInLoop uintptr
						})(unsafe.Pointer(pLevel + 80))).FnIn) {
							break
						}
						pOp = _sqlite3VdbeGetOp(tls, v, (**(**TInLoop)(__ccgo_up((*(*struct {
							FnIn     int32
							FaInLoop uintptr
						})(unsafe.Pointer(pLevel + 80))).FaInLoop + uintptr(iIn)*20))).FaddrInTop)
						if libc.Int32FromUint8((*TVdbeOp)(unsafe.Pointer(pOp)).Fopcode) == int32(OP_Column) && (*TVdbeOp)(unsafe.Pointer(pOp)).Fp3 == iReg+j+int32(2) || libc.Int32FromUint8((*TVdbeOp)(unsafe.Pointer(pOp)).Fopcode) == int32(OP_Rowid) && (*TVdbeOp)(unsafe.Pointer(pOp)).Fp2 == iReg+j+int32(2) {
							_sqlite3VdbeAddOp3(tls, v, libc.Int32FromUint8((*TVdbeOp)(unsafe.Pointer(pOp)).Fopcode), (*TVdbeOp)(unsafe.Pointer(pOp)).Fp1, (*TVdbeOp)(unsafe.Pointer(pOp)).Fp2, (*TVdbeOp)(unsafe.Pointer(pOp)).Fp3)
							break
						}
						goto _16
					_16:
						;
						iIn = iIn + 1
					}
					/* Generate code that will continue to the next row if
					 ** the IN constraint is not satisfied
					 */
					pCompare = _sqlite3PExpr(tls, pParse, int32(TK_EQ), uintptr(0), uintptr(0))
					if !((*Tsqlite3)(unsafe.Pointer(db)).FmallocFailed != 0) {
						iFld = (*(*struct {
							FleftColumn int32
							FiField     int32
						})(unsafe.Pointer(pTerm + 32))).FiField
						pLeft = (*TExpr)(unsafe.Pointer((*TWhereTerm)(unsafe.Pointer(pTerm)).FpExpr)).FpLeft
						if iFld > 0 {
							(*TExpr)(unsafe.Pointer(pCompare)).FpLeft = (*(*TExprList_item)(unsafe.Pointer(*(*uintptr)(unsafe.Pointer(pLeft + 32)) + 8 + uintptr(iFld-int32(1))*32))).FpExpr
						} else {
							(*TExpr)(unsafe.Pointer(pCompare)).FpLeft = pLeft
						}
						v4 = _sqlite3Expr(tls, db, int32(TK_REGISTER), uintptr(0))
						pRight1 = v4
						(*TExpr)(unsafe.Pointer(pCompare)).FpRight = v4
						if pRight1 != 0 {
							(*TExpr)(unsafe.Pointer(pRight1)).FiTable = iReg + j + int32(2)
							_sqlite3ExprIfFalse(tls, pParse, pCompare, (*TWhereLevel)(unsafe.Pointer(pLevel)).FaddrCont, int32(SQLITE_JUMPIFNULL))
						}
						(*TExpr)(unsafe.Pointer(pCompare)).FpLeft = uintptr(0)
					}
					_sqlite3ExprDelete(tls, db, pCompare)
				}
				goto _13
			_13:
				;
				j = j + 1
			}
			/* These registers need to be preserved in case there is an IN operator
			 ** loop.  So we could deallocate the registers here (and potentially
			 ** reuse them later) if (pLoop->wsFlags & WHERE_IN_ABLE)==0.  But it seems
			 ** simpler and safer to simply not reuse the registers.
			 **
			 **    sqlite3ReleaseTempRange(pParse, iReg, nConstraint+2);
			 */
		} else {
			if (*TWhereLoop)(unsafe.Pointer(pLoop)).FwsFlags&uint32(WHERE_IPK) != uint32(0) && (*TWhereLoop)(unsafe.Pointer(pLoop)).FwsFlags&libc.Uint32FromInt32(libc.Int32FromInt32(WHERE_COLUMN_IN)|libc.Int32FromInt32(WHERE_COLUMN_EQ)) != uint32(0) {
				/* Case 2:  We can directly reference a single row using an
				 **          equality comparison against the ROWID field.  Or
				 **          we reference multiple rows using a "rowid IN (...)"
				 **          construct.
				 */
				pTerm = **(**uintptr)(__ccgo_up((*TWhereLoop)(unsafe.Pointer(pLoop)).FaLTerm))
				v4 = pParse + 60
				*(*int32)(unsafe.Pointer(v4)) = *(*int32)(unsafe.Pointer(v4)) + 1
				v1 = *(*int32)(unsafe.Pointer(v4))
				iReleaseReg = v1
				iRowidReg = _codeEqualityTerm(tls, pParse, pTerm, pLevel, 0, bRev, iReleaseReg)
				if iRowidReg != iReleaseReg {
					_sqlite3ReleaseTempReg(tls, pParse, iReleaseReg)
				}
				addrNxt = (*TWhereLevel)(unsafe.Pointer(pLevel)).FaddrNxt
				if (*TWhereLevel)(unsafe.Pointer(pLevel)).FregFilter != 0 {
					_sqlite3VdbeAddOp2(tls, v, int32(OP_MustBeInt), iRowidReg, addrNxt)
					_sqlite3VdbeAddOp4Int(tls, v, int32(OP_Filter), (*TWhereLevel)(unsafe.Pointer(pLevel)).FregFilter, addrNxt, iRowidReg, int32(1))
					_filterPullDown(tls, pParse, pWInfo, iLevel, addrNxt, notReady)
				}
				_sqlite3VdbeAddOp3(tls, v, int32(OP_SeekRowid), iCur, addrNxt, iRowidReg)
				(*TWhereLevel)(unsafe.Pointer(pLevel)).Fop = uint8(OP_Noop)
			} else {
				if (*TWhereLoop)(unsafe.Pointer(pLoop)).FwsFlags&uint32(WHERE_IPK) != uint32(0) && (*TWhereLoop)(unsafe.Pointer(pLoop)).FwsFlags&uint32(WHERE_COLUMN_RANGE) != uint32(0) {
					/* Case 3:  We have an inequality comparison against the ROWID field.
					 */
					testOp = int32(OP_Noop)
					memEndValue = 0
					j = 0
					v4 = libc.UintptrFromInt32(0)
					pEnd = v4
					pStart = v4
					if (*TWhereLoop)(unsafe.Pointer(pLoop)).FwsFlags&uint32(WHERE_BTM_LIMIT) != 0 {
						v1 = j
						j = j + 1
						pStart = **(**uintptr)(__ccgo_up((*TWhereLoop)(unsafe.Pointer(pLoop)).FaLTerm + uintptr(v1)*8))
					}
					if (*TWhereLoop)(unsafe.Pointer(pLoop)).FwsFlags&uint32(WHERE_TOP_LIMIT) != 0 {
						v1 = j
						j = j + 1
						pEnd = **(**uintptr)(__ccgo_up((*TWhereLoop)(unsafe.Pointer(pLoop)).FaLTerm + uintptr(v1)*8))
					}
					if bRev != 0 {
						pTerm = pStart
						pStart = pEnd
						pEnd = pTerm
					}
					if pStart != 0 { /* Cursor seek operation */
						/* The following constant maps TK_xx codes into corresponding
						 ** seek opcodes.  It depends on a particular ordering of TK_xx
						 */
						aMoveOp = [4]Tu8{
							0: uint8(OP_SeekGT),
							1: uint8(OP_SeekLE),
							2: uint8(OP_SeekLT),
							3: uint8(OP_SeekGE),
						}
						/* Make sure the ordering.. */
						/*  ... of the TK_xx values... */
						/*  ... is correct. */
						pX = (*TWhereTerm)(unsafe.Pointer(pStart)).FpExpr
						/* transitive constraints */
						if _sqlite3ExprIsVector(tls, (*TExpr)(unsafe.Pointer(pX)).FpRight) != 0 {
							v1 = _sqlite3GetTempReg(tls, pParse)
							**(**int32)(__ccgo_up(bp)) = v1
							r11 = v1
							_codeExprOrVector(tls, pParse, (*TExpr)(unsafe.Pointer(pX)).FpRight, r11, int32(1))
							op = libc.Int32FromUint8(aMoveOp[(libc.Int32FromUint8((*TExpr)(unsafe.Pointer(pX)).Fop)-int32(TK_GT)-int32(1))&int32(0x3)|int32(0x1)])
						} else {
							r11 = _sqlite3ExprCodeTemp(tls, pParse, (*TExpr)(unsafe.Pointer(pX)).FpRight, bp)
							_disableTerm(tls, pLevel, pStart)
							op = libc.Int32FromUint8(aMoveOp[libc.Int32FromUint8((*TExpr)(unsafe.Pointer(pX)).Fop)-int32(TK_GT)])
						}
						_sqlite3VdbeAddOp3(tls, v, op, iCur, addrBrk, r11)
						_sqlite3ReleaseTempReg(tls, pParse, **(**int32)(__ccgo_up(bp)))
					} else {
						if bRev != 0 {
							v1 = int32(OP_Last)
						} else {
							v1 = int32(OP_Rewind)
						}
						_sqlite3VdbeAddOp2(tls, v, v1, iCur, (*TWhereLevel)(unsafe.Pointer(pLevel)).FaddrHalt)
					}
					if pEnd != 0 {
						pX1 = (*TWhereTerm)(unsafe.Pointer(pEnd)).FpExpr
						/* Transitive constraints */
						v4 = pParse + 60
						*(*int32)(unsafe.Pointer(v4)) = *(*int32)(unsafe.Pointer(v4)) + 1
						v1 = *(*int32)(unsafe.Pointer(v4))
						memEndValue = v1
						_codeExprOrVector(tls, pParse, (*TExpr)(unsafe.Pointer(pX1)).FpRight, memEndValue, int32(1))
						if 0 == _sqlite3ExprIsVector(tls, (*TExpr)(unsafe.Pointer(pX1)).FpRight) && (libc.Int32FromUint8((*TExpr)(unsafe.Pointer(pX1)).Fop) == int32(TK_LT) || libc.Int32FromUint8((*TExpr)(unsafe.Pointer(pX1)).Fop) == int32(TK_GT)) {
							if bRev != 0 {
								v1 = int32(OP_Le)
							} else {
								v1 = int32(OP_Ge)
							}
							testOp = v1
						} else {
							if bRev != 0 {
								v1 = int32(OP_Lt)
							} else {
								v1 = int32(OP_Gt)
							}
							testOp = v1
						}
						if 0 == _sqlite3ExprIsVector(tls, (*TExpr)(unsafe.Pointer(pX1)).FpRight) {
							_disableTerm(tls, pLevel, pEnd)
						}
					}
					start = _sqlite3VdbeCurrentAddr(tls, v)
					if bRev != 0 {
						v1 = int32(OP_Prev)
					} else {
						v1 = int32(OP_Next)
					}
					(*TWhereLevel)(unsafe.Pointer(pLevel)).Fop = libc.Uint8FromInt32(v1)
					(*TWhereLevel)(unsafe.Pointer(pLevel)).Fp1 = iCur
					(*TWhereLevel)(unsafe.Pointer(pLevel)).Fp2 = start
					if testOp != int32(OP_Noop) {
						v4 = pParse + 60
						*(*int32)(unsafe.Pointer(v4)) = *(*int32)(unsafe.Pointer(v4)) + 1
						v1 = *(*int32)(unsafe.Pointer(v4))
						iRowidReg = v1
						_sqlite3VdbeAddOp2(tls, v, int32(OP_Rowid), iCur, iRowidReg)
						_sqlite3VdbeAddOp3(tls, v, testOp, memEndValue, addrBrk, iRowidReg)
						_sqlite3VdbeChangeP5(tls, v, libc.Uint16FromInt32(libc.Int32FromInt32(SQLITE_AFF_NUMERIC)|libc.Int32FromInt32(SQLITE_JUMPIFNULL)))
					}
				} else {
					if (*TWhereLoop)(unsafe.Pointer(pLoop)).FwsFlags&uint32(WHERE_INDEXED) != 0 {
						nEq = (*(*struct {
							FnEq          Tu16
							FnBtm         Tu16
							FnTop         Tu16
							FnDistinctCol Tu16
							FpIndex       uintptr
							FpOrderBy     uintptr
						})(unsafe.Pointer(pLoop + 24))).FnEq /* Number of == or IN terms */
						nBtm = (*(*struct {
							FnEq          Tu16
							FnBtm         Tu16
							FnTop         Tu16
							FnDistinctCol Tu16
							FpIndex       uintptr
							FpOrderBy     uintptr
						})(unsafe.Pointer(pLoop + 24))).FnBtm /* Length of BTM vector */
						nTop = (*(*struct {
							FnEq          Tu16
							FnBtm         Tu16
							FnTop         Tu16
							FnDistinctCol Tu16
							FpIndex       uintptr
							FpOrderBy     uintptr
						})(unsafe.Pointer(pLoop + 24))).FnTop /* Base register holding constraint values */
						pRangeStart = uintptr(0) /* Inequality constraint at range start */
						pRangeEnd = uintptr(0)   /* The VDBE cursor for the index */
						nExtraReg = 0            /* Affinity for start of range constraint */
						zEndAff = uintptr(0)     /* Affinity for end of range constraint */
						bSeekPastNull = uint8(0) /* True to seek past initial nulls */
						bStopAtNull = uint8(0)   /* True if we use the index only */
						regBignull = 0           /* big-null flag register */
						addrSeekScan = 0         /* Opcode of the OP_SeekScan, if any */
						pIdx = (*(*struct {
							FnEq          Tu16
							FnBtm         Tu16
							FnTop         Tu16
							FnDistinctCol Tu16
							FpIndex       uintptr
							FpOrderBy     uintptr
						})(unsafe.Pointer(pLoop + 24))).FpIndex
						iIdxCur = (*TWhereLevel)(unsafe.Pointer(pLevel)).FiIdxCur
						/* Find any inequality constraint terms for the start and end
						 ** of the range.
						 */
						j = libc.Int32FromUint16(nEq)
						if (*TWhereLoop)(unsafe.Pointer(pLoop)).FwsFlags&uint32(WHERE_BTM_LIMIT) != 0 {
							v1 = j
							j = j + 1
							pRangeStart = **(**uintptr)(__ccgo_up((*TWhereLoop)(unsafe.Pointer(pLoop)).FaLTerm + uintptr(v1)*8))
							if nExtraReg > libc.Int32FromUint16((*(*struct {
								FnEq          Tu16
								FnBtm         Tu16
								FnTop         Tu16
								FnDistinctCol Tu16
								FpIndex       uintptr
								FpOrderBy     uintptr
							})(unsafe.Pointer(pLoop + 24))).FnBtm) {
								v1 = nExtraReg
							} else {
								v1 = libc.Int32FromUint16((*(*struct {
									FnEq          Tu16
									FnBtm         Tu16
									FnTop         Tu16
									FnDistinctCol Tu16
									FpIndex       uintptr
									FpOrderBy     uintptr
								})(unsafe.Pointer(pLoop + 24))).FnBtm)
							}
							nExtraReg = v1
							/* Like optimization range constraints always occur in pairs */
						}
						if (*TWhereLoop)(unsafe.Pointer(pLoop)).FwsFlags&uint32(WHERE_TOP_LIMIT) != 0 {
							v1 = j
							j = j + 1
							pRangeEnd = **(**uintptr)(__ccgo_up((*TWhereLoop)(unsafe.Pointer(pLoop)).FaLTerm + uintptr(v1)*8))
							if nExtraReg > libc.Int32FromUint16((*(*struct {
								FnEq          Tu16
								FnBtm         Tu16
								FnTop         Tu16
								FnDistinctCol Tu16
								FpIndex       uintptr
								FpOrderBy     uintptr
							})(unsafe.Pointer(pLoop + 24))).FnTop) {
								v1 = nExtraReg
							} else {
								v1 = libc.Int32FromUint16((*(*struct {
									FnEq          Tu16
									FnBtm         Tu16
									FnTop         Tu16
									FnDistinctCol Tu16
									FpIndex       uintptr
									FpOrderBy     uintptr
								})(unsafe.Pointer(pLoop + 24))).FnTop)
							}
							nExtraReg = v1
							if pRangeStart == uintptr(0) {
								j = int32(**(**Ti16)(__ccgo_up((*TIndex)(unsafe.Pointer(pIdx)).FaiColumn + uintptr(nEq)*2)))
								if j >= 0 && int32(uint32(*(*uint8)(unsafe.Pointer((*TTable)(unsafe.Pointer((*TIndex)(unsafe.Pointer(pIdx)).FpTable)).FaCol + uintptr(j)*16 + 8))&0xf>>0)) == 0 || j == -int32(2) {
									bSeekPastNull = uint8(1)
								}
							}
						}
						/* If the WHERE_BIGNULL_SORT flag is set, then index column nEq uses
						 ** a non-default "big-null" sort (either ASC NULLS LAST or DESC NULLS
						 ** FIRST). In both cases separate ordered scans are made of those
						 ** index entries for which the column is null and for those for which
						 ** it is not. For an ASC sort, the non-NULL entries are scanned first.
						 ** For DESC, NULL entries are scanned first.
						 */
						if (*TWhereLoop)(unsafe.Pointer(pLoop)).FwsFlags&libc.Uint32FromInt32(libc.Int32FromInt32(WHERE_TOP_LIMIT)|libc.Int32FromInt32(WHERE_BTM_LIMIT)) == uint32(0) && (*TWhereLoop)(unsafe.Pointer(pLoop)).FwsFlags&uint32(WHERE_BIGNULL_SORT) != uint32(0) {
							nExtraReg = int32(1)
							bSeekPastNull = uint8(1)
							v4 = pParse + 60
							*(*int32)(unsafe.Pointer(v4)) = *(*int32)(unsafe.Pointer(v4)) + 1
							v2 = *(*int32)(unsafe.Pointer(v4))
							v1 = v2
							regBignull = v1
							(*TWhereLevel)(unsafe.Pointer(pLevel)).FregBignull = v1
							if (*TWhereLevel)(unsafe.Pointer(pLevel)).FiLeftJoin != 0 {
								_sqlite3VdbeAddOp2(tls, v, int32(OP_Integer), 0, regBignull)
							}
							(*TWhereLevel)(unsafe.Pointer(pLevel)).FaddrBignull = _sqlite3VdbeMakeLabel(tls, pParse)
						}
						/* If we are doing a reverse order scan on an ascending index, or
						 ** a forward order scan on a descending index, interchange the
						 ** start and end terms (pRangeStart and pRangeEnd).
						 */
						if libc.Int32FromUint16(nEq) < libc.Int32FromUint16((*TIndex)(unsafe.Pointer(pIdx)).FnColumn) && bRev == libc.BoolInt32(libc.Int32FromUint8(**(**Tu8)(__ccgo_up((*TIndex)(unsafe.Pointer(pIdx)).FaSortOrder + uintptr(nEq)))) == SQLITE_SO_ASC) {
							t = pRangeEnd
							pRangeEnd = pRangeStart
							pRangeStart = t
							t1 = bSeekPastNull
							bSeekPastNull = bStopAtNull
							bStopAtNull = t1
							t2 = uint8(nBtm)
							nBtm = nTop
							nTop = uint16(t2)
						}
						if iLevel > 0 && (*TWhereLoop)(unsafe.Pointer(pLoop)).FwsFlags&uint32(WHERE_IN_SEEKSCAN) != uint32(0) {
							/* In case OP_SeekScan is used, ensure that the index cursor does not
							 ** point to a valid row for the first iteration of this loop. */
							_sqlite3VdbeAddOp1(tls, v, int32(OP_NullRow), iIdxCur)
						}
						/* Generate code to evaluate all constraint terms using == or IN
						 ** and store the values of those terms in an array of registers
						 ** starting at regBase.
						 */
						regBase = _codeAllEqualityTerms(tls, pParse, pLevel, bRev, nExtraReg, bp+8)
						if **(**uintptr)(__ccgo_up(bp + 8)) != 0 && nTop != 0 {
							zEndAff = _sqlite3DbStrDup(tls, db, **(**uintptr)(__ccgo_up(bp + 8))+uintptr(nEq))
						}
						if regBignull != 0 {
							v1 = (*TWhereLevel)(unsafe.Pointer(pLevel)).FaddrBignull
						} else {
							v1 = (*TWhereLevel)(unsafe.Pointer(pLevel)).FaddrNxt
						}
						addrNxt = v1
						startEq = libc.BoolInt32(!(pRangeStart != 0) || libc.Int32FromUint16((*TWhereTerm)(unsafe.Pointer(pRangeStart)).FeOperator)&(libc.Int32FromInt32(WO_EQ)<<(libc.Int32FromInt32(TK_LE)-libc.Int32FromInt32(TK_EQ))|libc.Int32FromInt32(WO_EQ)<<(libc.Int32FromInt32(TK_GE)-libc.Int32FromInt32(TK_EQ))) != 0)
						endEq = libc.BoolInt32(!(pRangeEnd != 0) || libc.Int32FromUint16((*TWhereTerm)(unsafe.Pointer(pRangeEnd)).FeOperator)&(libc.Int32FromInt32(WO_EQ)<<(libc.Int32FromInt32(TK_LE)-libc.Int32FromInt32(TK_EQ))|libc.Int32FromInt32(WO_EQ)<<(libc.Int32FromInt32(TK_GE)-libc.Int32FromInt32(TK_EQ))) != 0)
						start_constraints = libc.BoolInt32(pRangeStart != 0 || libc.Int32FromUint16(nEq) > 0)
						/* Seek the index cursor to the start of the range. */
						nConstraint1 = libc.Int32FromUint16(nEq)
						if pRangeStart != 0 {
							pRight2 = (*TExpr)(unsafe.Pointer((*TWhereTerm)(unsafe.Pointer(pRangeStart)).FpExpr)).FpRight
							_codeExprOrVector(tls, pParse, pRight2, regBase+libc.Int32FromUint16(nEq), libc.Int32FromUint16(nBtm))
							if libc.Int32FromUint16((*TWhereTerm)(unsafe.Pointer(pRangeStart)).FwtFlags)&int32(TERM_VNULL) == 0 && _sqlite3ExprCanBeNull(tls, pRight2) != 0 {
								_sqlite3VdbeAddOp2(tls, v, int32(OP_IsNull), regBase+libc.Int32FromUint16(nEq), addrNxt)
							}
							if **(**uintptr)(__ccgo_up(bp + 8)) != 0 {
								_updateRangeAffinityStr(tls, pRight2, libc.Int32FromUint16(nBtm), **(**uintptr)(__ccgo_up(bp + 8))+uintptr(nEq))
							}
							nConstraint1 = nConstraint1 + libc.Int32FromUint16(nBtm)
							if _sqlite3ExprIsVector(tls, pRight2) == 0 {
								_disableTerm(tls, pLevel, pRangeStart)
							} else {
								startEq = int32(1)
							}
							bSeekPastNull = uint8(0)
						} else {
							if bSeekPastNull != 0 {
								startEq = 0
								_sqlite3VdbeAddOp2(tls, v, int32(OP_Null), 0, regBase+libc.Int32FromUint16(nEq))
								start_constraints = int32(1)
								nConstraint1 = nConstraint1 + 1
							} else {
								if regBignull != 0 {
									_sqlite3VdbeAddOp2(tls, v, int32(OP_Null), 0, regBase+libc.Int32FromUint16(nEq))
									start_constraints = int32(1)
									nConstraint1 = nConstraint1 + 1
								}
							}
						}
						_codeApplyAffinity(tls, pParse, regBase, nConstraint1-libc.Int32FromUint8(bSeekPastNull), **(**uintptr)(__ccgo_up(bp + 8)))
						if libc.Int32FromUint16((*TWhereLoop)(unsafe.Pointer(pLoop)).FnSkip) > 0 && nConstraint1 == libc.Int32FromUint16((*TWhereLoop)(unsafe.Pointer(pLoop)).FnSkip) {
							/* The skip-scan logic inside the call to codeAllEqualityConstraints()
							 ** above has already left the cursor sitting on the correct row,
							 ** so no further seeking is needed */
						} else {
							if regBignull != 0 {
								_sqlite3VdbeAddOp2(tls, v, int32(OP_Integer), int32(1), regBignull)
							}
							if (*TWhereLevel)(unsafe.Pointer(pLevel)).FregFilter != 0 {
								_sqlite3VdbeAddOp4Int(tls, v, int32(OP_Filter), (*TWhereLevel)(unsafe.Pointer(pLevel)).FregFilter, addrNxt, regBase, libc.Int32FromUint16(nEq))
								_filterPullDown(tls, pParse, pWInfo, iLevel, addrNxt, notReady)
							}
							op1 = libc.Int32FromUint8(_aStartOp[start_constraints<<int32(2)+startEq<<int32(1)+bRev])
							if (*TWhereLoop)(unsafe.Pointer(pLoop)).FwsFlags&uint32(WHERE_IN_SEEKSCAN) != uint32(0) && op1 == int32(OP_SeekGE) {
								/* TUNING:  The OP_SeekScan opcode seeks to reduce the number
								 ** of expensive seek operations by replacing a single seek with
								 ** 1 or more step operations.  The question is, how many steps
								 ** should we try before giving up and going with a seek.  The cost
								 ** of a seek is proportional to the logarithm of the of the number
								 ** of entries in the tree, so basing the number of steps to try
								 ** on the estimated number of rows in the btree seems like a good
								 ** guess. */
								addrSeekScan = _sqlite3VdbeAddOp1(tls, v, int32(OP_SeekScan), (int32(**(**TLogEst)(__ccgo_up((*TIndex)(unsafe.Pointer(pIdx)).FaiRowLogEst)))+int32(9))/int32(10))
								if pRangeStart != 0 || pRangeEnd != 0 {
									_sqlite3VdbeChangeP5(tls, v, uint16(1))
									_sqlite3VdbeChangeP2(tls, v, addrSeekScan, _sqlite3VdbeCurrentAddr(tls, v)+int32(1))
									addrSeekScan = 0
								}
							}
							_sqlite3VdbeAddOp4Int(tls, v, op1, iIdxCur, addrNxt, regBase, nConstraint1)
							if regBignull != 0 {
								_sqlite3VdbeAddOp2(tls, v, int32(OP_Goto), 0, _sqlite3VdbeCurrentAddr(tls, v)+int32(2))
								op1 = libc.Int32FromUint8(_aStartOp[libc.BoolInt32(nConstraint1 > int32(1))*int32(4)+int32(2)+bRev])
								_sqlite3VdbeAddOp4Int(tls, v, op1, iIdxCur, addrNxt, regBase, nConstraint1-startEq)
							}
						}
						/* Load the value for the inequality constraint at the end of the
						 ** range (if any).
						 */
						nConstraint1 = libc.Int32FromUint16(nEq)
						if pRangeEnd != 0 {
							pRight3 = (*TExpr)(unsafe.Pointer((*TWhereTerm)(unsafe.Pointer(pRangeEnd)).FpExpr)).FpRight
							_codeExprOrVector(tls, pParse, pRight3, regBase+libc.Int32FromUint16(nEq), libc.Int32FromUint16(nTop))
							if libc.Int32FromUint16((*TWhereTerm)(unsafe.Pointer(pRangeEnd)).FwtFlags)&int32(TERM_VNULL) == 0 && _sqlite3ExprCanBeNull(tls, pRight3) != 0 {
								_sqlite3VdbeAddOp2(tls, v, int32(OP_IsNull), regBase+libc.Int32FromUint16(nEq), addrNxt)
							}
							if zEndAff != 0 {
								_updateRangeAffinityStr(tls, pRight3, libc.Int32FromUint16(nTop), zEndAff)
								_codeApplyAffinity(tls, pParse, regBase+libc.Int32FromUint16(nEq), libc.Int32FromUint16(nTop), zEndAff)
							} else {
							}
							nConstraint1 = nConstraint1 + libc.Int32FromUint16(nTop)
							if _sqlite3ExprIsVector(tls, pRight3) == 0 {
								_disableTerm(tls, pLevel, pRangeEnd)
							} else {
								endEq = int32(1)
							}
						} else {
							if bStopAtNull != 0 {
								if regBignull == 0 {
									_sqlite3VdbeAddOp2(tls, v, int32(OP_Null), 0, regBase+libc.Int32FromUint16(nEq))
									endEq = 0
								}
								nConstraint1 = nConstraint1 + 1
							}
						}
						if **(**uintptr)(__ccgo_up(bp + 8)) != 0 {
							_sqlite3DbNNFreeNN(tls, db, **(**uintptr)(__ccgo_up(bp + 8)))
						}
						if zEndAff != 0 {
							_sqlite3DbNNFreeNN(tls, db, zEndAff)
						}
						/* Top of the loop body */
						(*TWhereLevel)(unsafe.Pointer(pLevel)).Fp2 = _sqlite3VdbeCurrentAddr(tls, v)
						/* Check if the index cursor is past the end of the range. */
						if nConstraint1 != 0 {
							if regBignull != 0 {
								/* Except, skip the end-of-range check while doing the NULL-scan */
								_sqlite3VdbeAddOp2(tls, v, int32(OP_IfNot), regBignull, _sqlite3VdbeCurrentAddr(tls, v)+int32(3))
							}
							op1 = libc.Int32FromUint8(_aEndOp[bRev*int32(2)+endEq])
							_sqlite3VdbeAddOp4Int(tls, v, op1, iIdxCur, addrNxt, regBase, nConstraint1)
							if addrSeekScan != 0 {
								_sqlite3VdbeJumpHere(tls, v, addrSeekScan)
							}
						}
						if regBignull != 0 {
							/* During a NULL-scan, check to see if we have reached the end of
							 ** the NULLs */
							_sqlite3VdbeAddOp2(tls, v, int32(OP_If), regBignull, _sqlite3VdbeCurrentAddr(tls, v)+int32(2))
							op1 = libc.Int32FromUint8(_aEndOp[bRev*int32(2)+libc.Int32FromUint8(bSeekPastNull)])
							_sqlite3VdbeAddOp4Int(tls, v, op1, iIdxCur, addrNxt, regBase, nConstraint1+libc.Int32FromUint8(bSeekPastNull))
						}
						if (*TWhereLoop)(unsafe.Pointer(pLoop)).FwsFlags&uint32(WHERE_IN_EARLYOUT) != uint32(0) {
							_sqlite3VdbeAddOp3(tls, v, int32(OP_SeekHit), iIdxCur, libc.Int32FromUint16(nEq), libc.Int32FromUint16(nEq))
						}
						/* Seek the table cursor, if required */
						omitTable = libc.BoolInt32((*TWhereLoop)(unsafe.Pointer(pLoop)).FwsFlags&uint32(WHERE_IDX_ONLY) != uint32(0) && libc.Int32FromUint16((*TWhereInfo)(unsafe.Pointer(pWInfo)).FwctrlFlags)&(libc.Int32FromInt32(WHERE_OR_SUBCLAUSE)|libc.Int32FromInt32(WHERE_RIGHT_JOIN)) == 0)
						if omitTable != 0 {
							/* pIdx is a covering index.  No need to access the main table. */
						} else {
							if (*TTable)(unsafe.Pointer((*TIndex)(unsafe.Pointer(pIdx)).FpTable)).FtabFlags&uint32(TF_WithoutRowid) == uint32(0) {
								_codeDeferredSeek(tls, pWInfo, pIdx, iCur, iIdxCur)
							} else {
								if iCur != iIdxCur {
									pPk = _sqlite3PrimaryKeyIndex(tls, (*TIndex)(unsafe.Pointer(pIdx)).FpTable)
									iRowidReg = _sqlite3GetTempRange(tls, pParse, libc.Int32FromUint16((*TIndex)(unsafe.Pointer(pPk)).FnKeyCol))
									j = 0
									for {
										if !(j < libc.Int32FromUint16((*TIndex)(unsafe.Pointer(pPk)).FnKeyCol)) {
											break
										}
										k = _sqlite3TableColumnToIndex(tls, pIdx, int32(**(**Ti16)(__ccgo_up((*TIndex)(unsafe.Pointer(pPk)).FaiColumn + uintptr(j)*2))))
										_sqlite3VdbeAddOp3(tls, v, int32(OP_Column), iIdxCur, k, iRowidReg+j)
										goto _40
									_40:
										;
										j = j + 1
									}
									_sqlite3VdbeAddOp4Int(tls, v, int32(OP_NotFound), iCur, addrCont, iRowidReg, libc.Int32FromUint16((*TIndex)(unsafe.Pointer(pPk)).FnKeyCol))
								}
							}
						}
						if (*TWhereLevel)(unsafe.Pointer(pLevel)).FiLeftJoin == 0 {
							/* If a partial index is driving the loop, try to eliminate WHERE clause
							 ** terms from the query that must be true due to the WHERE clause of
							 ** the partial index.  This optimization does not work on an outer join,
							 ** as shown by:
							 **
							 ** 2019-11-02 ticket 623eff57e76d45f6      (LEFT JOIN)
							 ** 2025-05-29 forum post 7dee41d32506c4ae  (RIGHT JOIN)
							 */
							if (*TIndex)(unsafe.Pointer(pIdx)).FpPartIdxWhere != 0 && (*TWhereLevel)(unsafe.Pointer(pLevel)).FpRJ == uintptr(0) {
								_whereApplyPartialIndexConstraints(tls, (*TIndex)(unsafe.Pointer(pIdx)).FpPartIdxWhere, iCur, pWC)
							}
						} else {
							/* The following assert() is not a requirement, merely an observation:
							 ** The OR-optimization doesn't work for the right hand table of
							 ** a LEFT JOIN: */
						}
						/* Record the instruction used to terminate the loop. */
						if (*TWhereLoop)(unsafe.Pointer(pLoop)).FwsFlags&uint32(WHERE_ONEROW) != 0 || (*(*struct {
							FnIn     int32
							FaInLoop uintptr
						})(unsafe.Pointer(pLevel + 80))).FnIn != 0 && regBignull == 0 && _whereLoopIsOneRow(tls, pLoop) != 0 {
							(*TWhereLevel)(unsafe.Pointer(pLevel)).Fop = uint8(OP_Noop)
						} else {
							if bRev != 0 {
								(*TWhereLevel)(unsafe.Pointer(pLevel)).Fop = uint8(OP_Prev)
							} else {
								(*TWhereLevel)(unsafe.Pointer(pLevel)).Fop = uint8(OP_Next)
							}
						}
						(*TWhereLevel)(unsafe.Pointer(pLevel)).Fp1 = iIdxCur
						if (*TWhereLoop)(unsafe.Pointer(pLoop)).FwsFlags&uint32(WHERE_UNQ_WANTED) != uint32(0) {
							v1 = int32(1)
						} else {
							v1 = 0
						}
						(*TWhereLevel)(unsafe.Pointer(pLevel)).Fp3 = libc.Uint8FromInt32(v1)
						if (*TWhereLoop)(unsafe.Pointer(pLoop)).FwsFlags&uint32(WHERE_CONSTRAINT) == uint32(0) {
							(*TWhereLevel)(unsafe.Pointer(pLevel)).Fp5 = uint8(SQLITE_STMTSTATUS_FULLSCAN_STEP)
						} else {
						}
						if omitTable != 0 {
							pIdx = uintptr(0)
						}
					} else {
						if (*TWhereLoop)(unsafe.Pointer(pLoop)).FwsFlags&uint32(WHERE_MULTI_OR) != 0 { /* Shortened table list or OR-clause generation */
							pCov = uintptr(0)
							v4 = pParse + 56
							v1 = *(*int32)(unsafe.Pointer(v4))
							*(*int32)(unsafe.Pointer(v4)) = *(*int32)(unsafe.Pointer(v4)) + 1 /* Potential covering index (or NULL) */
							iCovCur = v1
							v8 = pParse + 60
							*(*int32)(unsafe.Pointer(v8)) = *(*int32)(unsafe.Pointer(v8)) + 1
							v2 = *(*int32)(unsafe.Pointer(v8))             /* Cursor used for index scans (if any) */
							regReturn = v2                                 /* Register used with OP_Gosub */
							regRowset = 0                                  /* Register for RowSet object */
							regRowid = 0                                   /* Register holding rowid */
							iLoopBody = _sqlite3VdbeMakeLabel(tls, pParse) /* Address of regReturn init */
							untestedTerms = 0                              /* Loop counter */
							pAndExpr = uintptr(0)                          /* An ".. AND (...)" expression */
							pTab = (*TSrcItem)(unsafe.Pointer(pTabItem)).FpSTab
							pTerm = **(**uintptr)(__ccgo_up((*TWhereLoop)(unsafe.Pointer(pLoop)).FaLTerm))
							pOrWc = *(*uintptr)(unsafe.Pointer(pTerm + 32))
							(*TWhereLevel)(unsafe.Pointer(pLevel)).Fop = uint8(OP_Return)
							(*TWhereLevel)(unsafe.Pointer(pLevel)).Fp1 = regReturn
							/* Set up a new SrcList in pOrTab containing the table being scanned
							 ** by this loop in the a[0] slot and all notReady tables in a[1..] slots.
							 ** This becomes the SrcList in the recursive call to sqlite3WhereBegin().
							 */
							if libc.Int32FromUint8((*TWhereInfo)(unsafe.Pointer(pWInfo)).FnLevel) > int32(1) || int32(*(*uint32)(unsafe.Pointer(pTabItem + 24 + 4))&0x40000>>18) != 0 { /* Original list of tables */
								nNotReady = libc.Int32FromUint8((*TWhereInfo)(unsafe.Pointer(pWInfo)).FnLevel) - iLevel - int32(1)
								pOrTab = _sqlite3DbMallocRawNN(tls, db, uint64(uint64(libc.UintptrFromInt32(0)+8)+libc.Uint64FromInt32(nNotReady+libc.Int32FromInt32(1))*libc.Uint64FromInt64(80)))
								if pOrTab == uintptr(0) {
									return notReady
								}
								(*TSrcList)(unsafe.Pointer(pOrTab)).FnAlloc = uint32(libc.Uint8FromInt32(nNotReady + libc.Int32FromInt32(1)))
								(*TSrcList)(unsafe.Pointer(pOrTab)).FnSrc = libc.Int32FromUint32((*TSrcList)(unsafe.Pointer(pOrTab)).FnAlloc)
								libc.Xmemcpy(tls, pOrTab+8, pTabItem, uint64(80))
								origSrc = (*TWhereInfo)(unsafe.Pointer(pWInfo)).FpTabList + 8
								k = int32(1)
								for {
									if !(k <= nNotReady) {
										break
									}
									libc.Xmemcpy(tls, pOrTab+8+uintptr(k)*80, origSrc+uintptr((**(**TWhereLevel)(__ccgo_up(pLevel + uintptr(k)*112))).FiFrom)*80, uint64(80))
									goto _46
								_46:
									;
									k = k + 1
								}
								/* Clear the fromExists flag on the OR-optimized table entry so that
								 ** the calls to sqlite3WhereEnd() do not code early-exits after the
								 ** first row is visited. The early exit applies to this table's
								 ** overall loop - including the multiple OR branches and any WHERE
								 ** conditions not passed to the sub-loops - not to the sub-loops.  */
								libc.SetBitFieldPtr32Uint32(pOrTab+8+24+4, libc.Uint32FromInt32(0), 18, 0x40000)
							} else {
								pOrTab = (*TWhereInfo)(unsafe.Pointer(pWInfo)).FpTabList
							}
							/* Initialize the rowset register to contain NULL. An SQL NULL is
							 ** equivalent to an empty rowset.  Or, create an ephemeral index
							 ** capable of holding primary keys in the case of a WITHOUT ROWID.
							 **
							 ** Also initialize regReturn to contain the address of the instruction
							 ** immediately following the OP_Return at the bottom of the loop. This
							 ** is required in a few obscure LEFT JOIN cases where control jumps
							 ** over the top of the loop into the body of it. In this case the
							 ** correct response for the end-of-loop code (the OP_Return) is to
							 ** fall through to the next instruction, just as an OP_Next does if
							 ** called on an uninitialized cursor.
							 */
							if libc.Int32FromUint16((*TWhereInfo)(unsafe.Pointer(pWInfo)).FwctrlFlags)&int32(WHERE_DUPLICATES_OK) == 0 {
								if (*TTable)(unsafe.Pointer(pTab)).FtabFlags&uint32(TF_WithoutRowid) == uint32(0) {
									v4 = pParse + 60
									*(*int32)(unsafe.Pointer(v4)) = *(*int32)(unsafe.Pointer(v4)) + 1
									v1 = *(*int32)(unsafe.Pointer(v4))
									regRowset = v1
									_sqlite3VdbeAddOp2(tls, v, int32(OP_Null), 0, regRowset)
								} else {
									pPk1 = _sqlite3PrimaryKeyIndex(tls, pTab)
									v4 = pParse + 56
									v1 = *(*int32)(unsafe.Pointer(v4))
									*(*int32)(unsafe.Pointer(v4)) = *(*int32)(unsafe.Pointer(v4)) + 1
									regRowset = v1
									_sqlite3VdbeAddOp2(tls, v, int32(OP_OpenEphemeral), regRowset, libc.Int32FromUint16((*TIndex)(unsafe.Pointer(pPk1)).FnKeyCol))
									_sqlite3VdbeSetP4KeyInfo(tls, pParse, pPk1)
								}
								v4 = pParse + 60
								*(*int32)(unsafe.Pointer(v4)) = *(*int32)(unsafe.Pointer(v4)) + 1
								v1 = *(*int32)(unsafe.Pointer(v4))
								regRowid = v1
							}
							iRetInit = _sqlite3VdbeAddOp2(tls, v, int32(OP_Integer), 0, regReturn)
							/* If the original WHERE clause is z of the form:  (x1 OR x2 OR ...) AND y
							 ** Then for every term xN, evaluate as the subexpression: xN AND y
							 ** That way, terms in y that are factored into the disjunction will
							 ** be picked up by the recursive calls to sqlite3WhereBegin() below.
							 **
							 ** Actually, each subexpression is converted to "xN AND w" where w is
							 ** the "interesting" terms of z - terms that did not originate in the
							 ** ON or USING clause of a LEFT JOIN, and terms that are usable as
							 ** indices.
							 **
							 ** This optimization also only applies if the (x1 OR x2 OR ...) term
							 ** is not contained in the ON clause of a LEFT JOIN.
							 ** See ticket http://sqlite.org/src/info/f2369304e4
							 **
							 ** 2022-02-04:  Do not push down slices of a row-value comparison.
							 ** In other words, "w" or "y" may not be a slice of a vector.  Otherwise,
							 ** the initialization of the right-hand operand of the vector comparison
							 ** might not occur, or might occur only in an OR branch that is not
							 ** taken.  dbsqlfuzz 80a9fade844b4fb43564efc972bcb2c68270f5d1.
							 **
							 ** 2022-03-03:  Do not push down expressions that involve subqueries.
							 ** The subquery might get coded as a subroutine.  Any table-references
							 ** in the subquery might be resolved to index-references for the index on
							 ** the OR branch in which the subroutine is coded.  But if the subroutine
							 ** is invoked from a different OR branch that uses a different index, such
							 ** index-references will not work.  tag-20220303a
							 ** https://sqlite.org/forum/forumpost/36937b197273d403
							 */
							if (*TWhereClause)(unsafe.Pointer(pWC)).FnTerm > int32(1) {
								iTerm = 0
								for {
									if !(iTerm < (*TWhereClause)(unsafe.Pointer(pWC)).FnTerm) {
										break
									}
									pExpr = (**(**TWhereTerm)(__ccgo_up((*TWhereClause)(unsafe.Pointer(pWC)).Fa + uintptr(iTerm)*56))).FpExpr
									if (*TWhereClause)(unsafe.Pointer(pWC)).Fa+uintptr(iTerm)*56 == pTerm {
										goto _53
									}
									if libc.Int32FromUint16((**(**TWhereTerm)(__ccgo_up((*TWhereClause)(unsafe.Pointer(pWC)).Fa + uintptr(iTerm)*56))).FwtFlags)&(libc.Int32FromInt32(TERM_VIRTUAL)|libc.Int32FromInt32(TERM_CODED)|libc.Int32FromInt32(TERM_SLICE)) != 0 {
										goto _53
									}
									if libc.Int32FromUint16((**(**TWhereTerm)(__ccgo_up((*TWhereClause)(unsafe.Pointer(pWC)).Fa + uintptr(iTerm)*56))).FeOperator)&int32(WO_ALL) == 0 {
										goto _53
									}
									if (*TExpr)(unsafe.Pointer(pExpr)).Fflags&libc.Uint32FromInt32(libc.Int32FromInt32(EP_Subquery)) != uint32(0) {
										goto _53
									} /* tag-20220303a */
									pExpr = _sqlite3ExprDup(tls, db, pExpr, 0)
									pAndExpr = _sqlite3ExprAnd(tls, pParse, pAndExpr, pExpr)
									goto _53
								_53:
									;
									iTerm = iTerm + 1
								}
								if pAndExpr != 0 {
									/* The extra 0x10000 bit on the opcode is masked off and does not
									 ** become part of the new Expr.op.  However, it does make the
									 ** op==TK_AND comparison inside of sqlite3PExpr() false, and this
									 ** prevents sqlite3PExpr() from applying the AND short-circuit
									 ** optimization, which we do not want here. */
									pAndExpr = _sqlite3PExpr(tls, pParse, libc.Int32FromInt32(TK_AND)|libc.Int32FromInt32(0x10000), uintptr(0), pAndExpr)
								}
							}
							/* Run a separate WHERE clause for each term of the OR clause.  After
							 ** eliminating duplicates from other WHERE clauses, the action for each
							 ** sub-WHERE clause is to to invoke the main loop body as a subroutine.
							 */
							_sqlite3VdbeExplain(tls, pParse, uint8(1), __ccgo_ts+23889, 0)
							ii = 0
							for {
								if !(ii < (*TWhereClause)(unsafe.Pointer(pOrWc)).FnTerm) {
									break
								}
								pOrTerm = (*TWhereClause)(unsafe.Pointer(pOrWc)).Fa + uintptr(ii)*56
								if (*TWhereTerm)(unsafe.Pointer(pOrTerm)).FleftCursor == iCur || libc.Int32FromUint16((*TWhereTerm)(unsafe.Pointer(pOrTerm)).FeOperator)&int32(WO_AND) != 0 { /* Info for single OR-term scan */
									pOrExpr = (*TWhereTerm)(unsafe.Pointer(pOrTerm)).FpExpr /* Local copy of OR clause term */
									jmp1 = 0                                                /* Address of jump operation */
									/* See TH3 vtab25.400 and ticket 614b25314c766238 */
									v4 = _sqlite3ExprDup(tls, db, pOrExpr, 0)
									pOrExpr = v4
									pDelete = v4
									if (*Tsqlite3)(unsafe.Pointer(db)).FmallocFailed != 0 {
										_sqlite3ExprDelete(tls, db, pDelete)
										goto _54
									}
									if pAndExpr != 0 {
										(*TExpr)(unsafe.Pointer(pAndExpr)).FpLeft = pOrExpr
										pOrExpr = pAndExpr
									}
									/* Loop through table entries that match term pOrTerm. */
									_sqlite3VdbeExplain(tls, pParse, uint8(1), __ccgo_ts+23904, libc.VaList(bp+96, ii+int32(1)))
									pSubWInfo = _sqlite3WhereBegin(tls, pParse, pOrTab, pOrExpr, uintptr(0), uintptr(0), uintptr(0), uint16(WHERE_OR_SUBCLAUSE), iCovCur)
									if pSubWInfo != 0 {
										addrExplain = _sqlite3WhereExplainOneScan(tls, pParse, pOrTab, pSubWInfo+856, uint16(0))
										_ = addrExplain
										/* This is the sub-WHERE clause body.  First skip over
										 ** duplicate rows from prior sub-WHERE clauses, and record the
										 ** rowid (or PRIMARY KEY) for the current row so that the same
										 ** row will be skipped in subsequent sub-WHERE clauses.
										 */
										if libc.Int32FromUint16((*TWhereInfo)(unsafe.Pointer(pWInfo)).FwctrlFlags)&int32(WHERE_DUPLICATES_OK) == 0 {
											if ii == (*TWhereClause)(unsafe.Pointer(pOrWc)).FnTerm-int32(1) {
												v1 = -int32(1)
											} else {
												v1 = ii
											}
											iSet = v1
											if (*TTable)(unsafe.Pointer(pTab)).FtabFlags&uint32(TF_WithoutRowid) == uint32(0) {
												_sqlite3ExprCodeGetColumnOfTable(tls, v, pTab, iCur, -int32(1), regRowid)
												jmp1 = _sqlite3VdbeAddOp4Int(tls, v, int32(OP_RowSetTest), regRowset, 0, regRowid, iSet)
											} else {
												pPk2 = _sqlite3PrimaryKeyIndex(tls, pTab)
												nPk = libc.Int32FromUint16((*TIndex)(unsafe.Pointer(pPk2)).FnKeyCol)
												/* Read the PK into an array of temp registers. */
												r = _sqlite3GetTempRange(tls, pParse, nPk)
												iPk = 0
												for {
													if !(iPk < nPk) {
														break
													}
													iCol = int32(**(**Ti16)(__ccgo_up((*TIndex)(unsafe.Pointer(pPk2)).FaiColumn + uintptr(iPk)*2)))
													_sqlite3ExprCodeGetColumnOfTable(tls, v, pTab, iCur, iCol, r+iPk)
													goto _57
												_57:
													;
													iPk = iPk + 1
												}
												/* Check if the temp table already contains this key. If so,
												 ** the row has already been included in the result set and
												 ** can be ignored (by jumping past the Gosub below). Otherwise,
												 ** insert the key into the temp table and proceed with processing
												 ** the row.
												 **
												 ** Use some of the same optimizations as OP_RowSetTest: If iSet
												 ** is zero, assume that the key cannot already be present in
												 ** the temp table. And if iSet is -1, assume that there is no
												 ** need to insert the key into the temp table, as it will never
												 ** be tested for.  */
												if iSet != 0 {
													jmp1 = _sqlite3VdbeAddOp4Int(tls, v, int32(OP_Found), regRowset, 0, r, nPk)
												}
												if iSet >= 0 {
													_sqlite3VdbeAddOp3(tls, v, int32(OP_MakeRecord), r, nPk, regRowid)
													_sqlite3VdbeAddOp4Int(tls, v, int32(OP_IdxInsert), regRowset, regRowid, r, nPk)
													if iSet != 0 {
														_sqlite3VdbeChangeP5(tls, v, uint16(OPFLAG_USESEEKRESULT))
													}
												}
												/* Release the array of temp registers */
												_sqlite3ReleaseTempRange(tls, pParse, r, nPk)
											}
										}
										/* Invoke the main loop body as a subroutine */
										_sqlite3VdbeAddOp2(tls, v, int32(OP_Gosub), regReturn, iLoopBody)
										/* Jump here (skipping the main loop body subroutine) if the
										 ** current sub-WHERE row is a duplicate from prior sub-WHEREs. */
										if jmp1 != 0 {
											_sqlite3VdbeJumpHere(tls, v, jmp1)
										}
										/* The pSubWInfo->untestedTerms flag means that this OR term
										 ** contained one or more AND term from a notReady table.  The
										 ** terms from the notReady table could not be tested and will
										 ** need to be tested later.
										 */
										if int32(uint32(*(*uint8)(unsafe.Pointer(pSubWInfo + 68))&0x2>>1)) != 0 {
											untestedTerms = int32(1)
										}
										/* If all of the OR-connected terms are optimized using the same
										 ** index, and the index is opened using the same cursor number
										 ** by each call to sqlite3WhereBegin() made by this loop, it may
										 ** be possible to use that index as a covering index.
										 **
										 ** If the call to sqlite3WhereBegin() above resulted in a scan that
										 ** uses an index, and this is either the first OR-connected term
										 ** processed or the index is the same as that used by all previous
										 ** terms, set pCov to the candidate covering index. Otherwise, set
										 ** pCov to NULL to indicate that no candidate covering index will
										 ** be available.
										 */
										pSubLoop = (*(*TWhereLevel)(unsafe.Pointer(pSubWInfo + 856))).FpWLoop
										if (*TWhereLoop)(unsafe.Pointer(pSubLoop)).FwsFlags&uint32(WHERE_INDEXED) != uint32(0) && (ii == 0 || (*(*struct {
											FnEq          Tu16
											FnBtm         Tu16
											FnTop         Tu16
											FnDistinctCol Tu16
											FpIndex       uintptr
											FpOrderBy     uintptr
										})(unsafe.Pointer(pSubLoop + 24))).FpIndex == pCov) && ((*TTable)(unsafe.Pointer(pTab)).FtabFlags&uint32(TF_WithoutRowid) == uint32(0) || !(int32(uint32(*(*uint16)(unsafe.Pointer((*(*struct {
											FnEq          Tu16
											FnBtm         Tu16
											FnTop         Tu16
											FnDistinctCol Tu16
											FpIndex       uintptr
											FpOrderBy     uintptr
										})(unsafe.Pointer(pSubLoop + 24))).FpIndex + 100))&0x3>>0)) == libc.Int32FromInt32(SQLITE_IDXTYPE_PRIMARYKEY))) {
											pCov = (*(*struct {
												FnEq          Tu16
												FnBtm         Tu16
												FnTop         Tu16
												FnDistinctCol Tu16
												FpIndex       uintptr
												FpOrderBy     uintptr
											})(unsafe.Pointer(pSubLoop + 24))).FpIndex
										} else {
											pCov = uintptr(0)
										}
										if _sqlite3WhereUsesDeferredSeek(tls, pSubWInfo) != 0 {
											libc.SetBitFieldPtr8Uint32(pWInfo+68, libc.Uint32FromInt32(1), 0, 0x1)
										}
										/* Finish the loop through table entries that match term pOrTerm. */
										_sqlite3WhereEnd(tls, pSubWInfo)
										_sqlite3VdbeExplainPop(tls, pParse)
									}
									_sqlite3ExprDelete(tls, db, pDelete)
								}
								goto _54
							_54:
								;
								ii = ii + 1
							}
							_sqlite3VdbeExplainPop(tls, pParse)
							*(*uintptr)(unsafe.Pointer(&(*TWhereLevel)(unsafe.Pointer(pLevel)).Fu)) = pCov
							if pCov != 0 {
								(*TWhereLevel)(unsafe.Pointer(pLevel)).FiIdxCur = iCovCur
							}
							if pAndExpr != 0 {
								(*TExpr)(unsafe.Pointer(pAndExpr)).FpLeft = uintptr(0)
								_sqlite3ExprDelete(tls, db, pAndExpr)
							}
							_sqlite3VdbeChangeP1(tls, v, iRetInit, _sqlite3VdbeCurrentAddr(tls, v))
							_sqlite3VdbeGoto(tls, v, (*TWhereLevel)(unsafe.Pointer(pLevel)).FaddrBrk)
							_sqlite3VdbeResolveLabel(tls, v, iLoopBody)
							/* Set the P2 operand of the OP_Return opcode that will end the current
							 ** loop to point to this spot, which is the top of the next containing
							 ** loop.  The byte-code formatter will use that P2 value as a hint to
							 ** indent everything in between the this point and the final OP_Return.
							 ** See tag-20220407a in vdbe.c and shell.c */
							(*TWhereLevel)(unsafe.Pointer(pLevel)).Fp2 = _sqlite3VdbeCurrentAddr(tls, v)
							if (*TWhereInfo)(unsafe.Pointer(pWInfo)).FpTabList != pOrTab {
								_sqlite3DbFreeNN(tls, db, pOrTab)
							}
							if !(untestedTerms != 0) {
								_disableTerm(tls, pLevel, pTerm)
							}
						} else {
							if int32(*(*uint32)(unsafe.Pointer(pTabItem + 24 + 4))&0x80>>7) != 0 {
								/* Tables marked isRecursive have only a single row that is stored in
								 ** a pseudo-cursor.  No need to Rewind or Next such cursors. */
								(*TWhereLevel)(unsafe.Pointer(pLevel)).Fop = uint8(OP_Noop)
							} else {
								(*TWhereLevel)(unsafe.Pointer(pLevel)).Fop = _aStep[bRev]
								(*TWhereLevel)(unsafe.Pointer(pLevel)).Fp1 = iCur
								(*TWhereLevel)(unsafe.Pointer(pLevel)).Fp2 = int32(1) + _sqlite3VdbeAddOp2(tls, v, libc.Int32FromUint8(_aStart[bRev]), iCur, (*TWhereLevel)(unsafe.Pointer(pLevel)).FaddrHalt)
								(*TWhereLevel)(unsafe.Pointer(pLevel)).Fp5 = uint8(SQLITE_STMTSTATUS_FULLSCAN_STEP)
							}
						}
					}
				}
			}
		}
	}
	/* Insert code to test every subexpression that can be completely
	 ** computed using the current set of tables.
	 **
	 ** This loop may run between one and three times, depending on the
	 ** constraints to be generated. The value of stack variable iLoop
	 ** determines the constraints coded by each iteration, as follows:
	 **
	 ** iLoop==1: Code only expressions that are entirely covered by pIdx.
	 ** iLoop==2: Code remaining expressions that do not contain correlated
	 **           sub-queries.
	 ** iLoop==3: Code all remaining expressions.
	 **
	 ** An effort is made to skip unnecessary iterations of the loop.
	 **
	 ** This optimization of causing simple query restrictions to occur before
	 ** more complex one is call the "push-down" optimization in MySQL.  Here
	 ** in SQLite, the name is "MySQL push-down", since there is also another
	 ** totally unrelated optimization called "WHERE-clause push-down".
	 ** Sometimes the qualifier is omitted, resulting in an ambiguity, so beware.
	 */
	if pIdx != 0 {
		v1 = int32(1)
	} else {
		v1 = int32(2)
	}
	iLoop = v1
	for cond := true; cond; cond = iLoop > 0 {
		iNext = 0 /* Next value for iLoop */
		pTerm = (*TWhereClause)(unsafe.Pointer(pWC)).Fa
		j = (*TWhereClause)(unsafe.Pointer(pWC)).FnTerm
		for {
			if !(j > 0) {
				break
			}
			skipLikeAddr = 0
			if libc.Int32FromUint16((*TWhereTerm)(unsafe.Pointer(pTerm)).FwtFlags)&(libc.Int32FromInt32(TERM_VIRTUAL)|libc.Int32FromInt32(TERM_CODED)) != 0 {
				goto _59
			}
			if (*TWhereTerm)(unsafe.Pointer(pTerm)).FprereqAll&(*TWhereLevel)(unsafe.Pointer(pLevel)).FnotReady != uint64(0) {
				libc.SetBitFieldPtr8Uint32(pWInfo+68, libc.Uint32FromInt32(1), 1, 0x2)
				goto _59
			}
			pE = (*TWhereTerm)(unsafe.Pointer(pTerm)).FpExpr
			if libc.Int32FromUint8((*TSrcItem)(unsafe.Pointer(pTabItem)).Ffg.Fjointype)&(libc.Int32FromInt32(JT_LEFT)|libc.Int32FromInt32(JT_LTORJ)|libc.Int32FromInt32(JT_RIGHT)) != 0 {
				if !((*TExpr)(unsafe.Pointer(pE)).Fflags&libc.Uint32FromInt32(libc.Int32FromInt32(EP_OuterON)|libc.Int32FromInt32(EP_InnerON)) != libc.Uint32FromInt32(0)) {
					/* Defer processing WHERE clause constraints until after outer
					 ** join processing.  tag-20220513a */
					goto _59
				} else {
					if libc.Int32FromUint8((*TSrcItem)(unsafe.Pointer(pTabItem)).Ffg.Fjointype)&int32(JT_LEFT) == int32(JT_LEFT) && !((*TExpr)(unsafe.Pointer(pE)).Fflags&libc.Uint32FromInt32(libc.Int32FromInt32(EP_OuterON)) != libc.Uint32FromInt32(0)) {
						goto _59
					} else {
						m = _sqlite3WhereGetMask(tls, pWInfo+592, *(*int32)(unsafe.Pointer(pE + 52)))
						if m&(*TWhereLevel)(unsafe.Pointer(pLevel)).FnotReady != 0 {
							/* An ON clause that is not ripe */
							goto _59
						}
					}
				}
			}
			if iLoop == int32(1) && !(_sqlite3ExprCoveredByIndex(tls, pE, (*TWhereLevel)(unsafe.Pointer(pLevel)).FiTabCur, pIdx) != 0) {
				iNext = int32(2)
				goto _59
			}
			if iLoop < int32(3) && libc.Int32FromUint16((*TWhereTerm)(unsafe.Pointer(pTerm)).FwtFlags)&int32(TERM_VARSELECT) != 0 {
				if iNext == 0 {
					iNext = int32(3)
				}
				goto _59
			}
			if libc.Int32FromUint16((*TWhereTerm)(unsafe.Pointer(pTerm)).FwtFlags)&int32(TERM_LIKECOND) != 0 {
				/* If the TERM_LIKECOND flag is set, that means that the range search
				 ** is sufficient to guarantee that the LIKE operator is true, so we
				 ** can skip the call to the like(A,B) function.  But this only works
				 ** for strings.  So do not skip the call to the function on the pass
				 ** that compares BLOBs. */
				goto _59
			}
			_sqlite3ExprIfFalse(tls, pParse, pE, addrCont, int32(SQLITE_JUMPIFNULL))
			if skipLikeAddr != 0 {
				_sqlite3VdbeJumpHere(tls, v, skipLikeAddr)
			}
			v4 = pTerm + 18
			*(*Tu16)(unsafe.Pointer(v4)) = Tu16(int32(*(*Tu16)(unsafe.Pointer(v4))) | libc.Int32FromInt32(TERM_CODED))
			goto _59
		_59:
			;
			j = j - 1
			pTerm += 56
		}
		iLoop = iNext
	}
	/* Insert code to test for implied constraints based on transitivity
	 ** of the "==" operator.
	 **
	 ** Example: If the WHERE clause contains "t1.a=t2.b" and "t2.b=123"
	 ** and we are coding the t1 loop and the t2 loop has not yet coded,
	 ** then we cannot use the "t1.a=t2.b" constraint, but we can code
	 ** the implied "t1.a=123" constraint.
	 */
	pTerm = (*TWhereClause)(unsafe.Pointer(pWC)).Fa
	j = (*TWhereClause)(unsafe.Pointer(pWC)).FnBase
	for {
		if !(j > 0) {
			break
		}
		if libc.Int32FromUint16((*TWhereTerm)(unsafe.Pointer(pTerm)).FwtFlags)&(libc.Int32FromInt32(TERM_VIRTUAL)|libc.Int32FromInt32(TERM_CODED)) != 0 {
			goto _61
		}
		if libc.Int32FromUint16((*TWhereTerm)(unsafe.Pointer(pTerm)).FeOperator)&(libc.Int32FromInt32(WO_EQ)|libc.Int32FromInt32(WO_IS)) == 0 {
			goto _61
		}
		if libc.Int32FromUint16((*TWhereTerm)(unsafe.Pointer(pTerm)).FeOperator)&int32(WO_EQUIV) == 0 {
			goto _61
		}
		if (*TWhereTerm)(unsafe.Pointer(pTerm)).FleftCursor != iCur {
			goto _61
		}
		if libc.Int32FromUint8((*TSrcItem)(unsafe.Pointer(pTabItem)).Ffg.Fjointype)&(libc.Int32FromInt32(JT_LEFT)|libc.Int32FromInt32(JT_LTORJ)|libc.Int32FromInt32(JT_RIGHT)) != 0 {
			goto _61
		}
		pE1 = (*TWhereTerm)(unsafe.Pointer(pTerm)).FpExpr
		pAlt = _sqlite3WhereFindTerm(tls, pWC, iCur, (*(*struct {
			FleftColumn int32
			FiField     int32
		})(unsafe.Pointer(pTerm + 32))).FleftColumn, notReady, libc.Uint32FromInt32(libc.Int32FromInt32(WO_EQ)|libc.Int32FromInt32(WO_IN)|libc.Int32FromInt32(WO_IS)), uintptr(0))
		if pAlt == uintptr(0) {
			goto _61
		}
		if libc.Int32FromUint16((*TWhereTerm)(unsafe.Pointer(pAlt)).FwtFlags)&int32(TERM_CODED) != 0 {
			goto _61
		}
		if (*TExpr)(unsafe.Pointer((*TWhereTerm)(unsafe.Pointer(pAlt)).FpExpr)).Fflags&libc.Uint32FromInt32(libc.Int32FromInt32(EP_Collate)) != uint32(0) {
			goto _61
		}
		if libc.Int32FromUint16((*TWhereTerm)(unsafe.Pointer(pAlt)).FeOperator)&int32(WO_IN) != 0 && (*TExpr)(unsafe.Pointer((*TWhereTerm)(unsafe.Pointer(pAlt)).FpExpr)).Fflags&uint32(EP_xIsSelect) != uint32(0) && (*TExprList)(unsafe.Pointer((*TSelect)(unsafe.Pointer(*(*uintptr)(unsafe.Pointer((*TWhereTerm)(unsafe.Pointer(pAlt)).FpExpr + 32)))).FpEList)).FnExpr > int32(1) {
			goto _61
		}
		**(**TExpr)(__ccgo_up(bp + 16)) = **(**TExpr)(__ccgo_up((*TWhereTerm)(unsafe.Pointer(pAlt)).FpExpr))
		(**(**TExpr)(__ccgo_up(bp + 16))).FpLeft = (*TExpr)(unsafe.Pointer(pE1)).FpLeft
		_sqlite3ExprIfFalse(tls, pParse, bp+16, addrCont, int32(SQLITE_JUMPIFNULL))
		v4 = pAlt + 18
		*(*Tu16)(unsafe.Pointer(v4)) = Tu16(int32(*(*Tu16)(unsafe.Pointer(v4))) | libc.Int32FromInt32(TERM_CODED))
		goto _61
	_61:
		;
		j = j - 1
		pTerm += 56
	}
	/* For a RIGHT OUTER JOIN, record the fact that the current row has
	 ** been matched at least once.
	 */
	if (*TWhereLevel)(unsafe.Pointer(pLevel)).FpRJ != 0 {
		jmp11 = 0
		pRJ = (*TWhereLevel)(unsafe.Pointer(pLevel)).FpRJ
		/* pTab is the right-hand table of the RIGHT JOIN.  Generate code that
		 ** will record that the current row of that table has been matched at
		 ** least once.  This is accomplished by storing the PK for the row in
		 ** both the iMatch index and the regBloom Bloom filter.
		 */
		pTab1 = (*(*TSrcItem)(unsafe.Pointer((*TWhereInfo)(unsafe.Pointer(pWInfo)).FpTabList + 8 + uintptr((*TWhereLevel)(unsafe.Pointer(pLevel)).FiFrom)*80))).FpSTab
		if (*TTable)(unsafe.Pointer(pTab1)).FtabFlags&uint32(TF_WithoutRowid) == uint32(0) {
			r1 = _sqlite3GetTempRange(tls, pParse, int32(2))
			_sqlite3ExprCodeGetColumnOfTable(tls, v, pTab1, (*TWhereLevel)(unsafe.Pointer(pLevel)).FiTabCur, -int32(1), r1+int32(1))
			nPk1 = int32(1)
		} else {
			pPk3 = _sqlite3PrimaryKeyIndex(tls, pTab1)
			nPk1 = libc.Int32FromUint16((*TIndex)(unsafe.Pointer(pPk3)).FnKeyCol)
			r1 = _sqlite3GetTempRange(tls, pParse, nPk1+int32(1))
			iPk1 = 0
			for {
				if !(iPk1 < nPk1) {
					break
				}
				iCol1 = int32(**(**Ti16)(__ccgo_up((*TIndex)(unsafe.Pointer(pPk3)).FaiColumn + uintptr(iPk1)*2)))
				_sqlite3ExprCodeGetColumnOfTable(tls, v, pTab1, iCur, iCol1, r1+int32(1)+iPk1)
				goto _63
			_63:
				;
				iPk1 = iPk1 + 1
			}
		}
		jmp11 = _sqlite3VdbeAddOp4Int(tls, v, int32(OP_Found), (*TWhereRightJoin)(unsafe.Pointer(pRJ)).FiMatch, 0, r1+int32(1), nPk1)
		_sqlite3VdbeAddOp3(tls, v, int32(OP_MakeRecord), r1+int32(1), nPk1, r1)
		_sqlite3VdbeAddOp4Int(tls, v, int32(OP_IdxInsert), (*TWhereRightJoin)(unsafe.Pointer(pRJ)).FiMatch, r1, r1+int32(1), nPk1)
		_sqlite3VdbeAddOp4Int(tls, v, int32(OP_FilterAdd), (*TWhereRightJoin)(unsafe.Pointer(pRJ)).FregBloom, 0, r1+int32(1), nPk1)
		_sqlite3VdbeChangeP5(tls, v, uint16(OPFLAG_USESEEKRESULT))
		_sqlite3VdbeJumpHere(tls, v, jmp11)
		_sqlite3ReleaseTempRange(tls, pParse, r1, nPk1+int32(1))
	}
	/* For a LEFT OUTER JOIN, generate code that will record the fact that
	 ** at least one row of the right table has matched the left table.
	 */
	if (*TWhereLevel)(unsafe.Pointer(pLevel)).FiLeftJoin != 0 {
		(*TWhereLevel)(unsafe.Pointer(pLevel)).FaddrFirst = _sqlite3VdbeCurrentAddr(tls, v)
		_sqlite3VdbeAddOp2(tls, v, int32(OP_Integer), int32(1), (*TWhereLevel)(unsafe.Pointer(pLevel)).FiLeftJoin)
		if (*TWhereLevel)(unsafe.Pointer(pLevel)).FpRJ == uintptr(0) {
			goto code_outer_join_constraints /* WHERE clause constraints */
		}
	}
	if !((*TWhereLevel)(unsafe.Pointer(pLevel)).FpRJ != 0) {
		goto _64
	}
	/* Create a subroutine used to process all interior loops and code
	 ** of the RIGHT JOIN.  During normal operation, the subroutine will
	 ** be in-line with the rest of the code.  But at the end, a separate
	 ** loop will run that invokes this subroutine for unmatched rows
	 ** of pTab, with all tables to left begin set to NULL.
	 */
	pRJ1 = (*TWhereLevel)(unsafe.Pointer(pLevel)).FpRJ
	_sqlite3VdbeAddOp2(tls, v, int32(OP_BeginSubrtn), 0, (*TWhereRightJoin)(unsafe.Pointer(pRJ1)).FregReturn)
	(*TWhereRightJoin)(unsafe.Pointer(pRJ1)).FaddrSubrtn = _sqlite3VdbeCurrentAddr(tls, v)
	(*TParse)(unsafe.Pointer(pParse)).FwithinRJSubrtn = (*TParse)(unsafe.Pointer(pParse)).FwithinRJSubrtn + 1
	/* WHERE clause constraints must be deferred until after outer join
	 ** row elimination has completed, since WHERE clause constraints apply
	 ** to the results of the OUTER JOIN.  The following loop generates the
	 ** appropriate WHERE clause constraint checks.  tag-20220513a.
	 */
	goto code_outer_join_constraints
code_outer_join_constraints:
	;
	pTerm = (*TWhereClause)(unsafe.Pointer(pWC)).Fa
	j = libc.Int32FromInt32(0)
	for {
		if !(j < (*TWhereClause)(unsafe.Pointer(pWC)).FnBase) {
			break
		}
		if libc.Int32FromUint16((*TWhereTerm)(unsafe.Pointer(pTerm)).FwtFlags)&(libc.Int32FromInt32(TERM_VIRTUAL)|libc.Int32FromInt32(TERM_CODED)) != 0 {
			goto _65
		}
		if (*TWhereTerm)(unsafe.Pointer(pTerm)).FprereqAll&(*TWhereLevel)(unsafe.Pointer(pLevel)).FnotReady != uint64(0) {
			goto _65
		}
		if libc.Int32FromUint8((*TSrcItem)(unsafe.Pointer(pTabItem)).Ffg.Fjointype)&int32(JT_LTORJ) != 0 {
			goto _65
		}
		_sqlite3ExprIfFalse(tls, pParse, (*TWhereTerm)(unsafe.Pointer(pTerm)).FpExpr, addrCont, int32(SQLITE_JUMPIFNULL))
		v4 = pTerm + 18
		*(*Tu16)(unsafe.Pointer(v4)) = Tu16(int32(*(*Tu16)(unsafe.Pointer(v4))) | libc.Int32FromInt32(TERM_CODED))
		goto _65
	_65:
		;
		j = j + 1
		pTerm += 56
	}
_64:
	;
	return (*TWhereLevel)(unsafe.Pointer(pLevel)).FnotReady
}

// C documentation
//
//	/*
//	** Generate the end of the WHERE loop.  See comments on
//	** sqlite3WhereBegin() for additional information.
//	*/
func _sqlite3WhereEnd(tls *libc.TLS, pWInfo uintptr) {
	var addr, addrIfNull, addrSeek, bEarlyOut, i, iDb, iEnd, j, j1, k, last, m, n, n1, nRJ, op, r1, ws, x, v4 int32
	var db, p, pIdx, pIdx1, pIn, pIx, pLastOp, pLevel, pLoop, pOp, pParse, pPk, pRJ, pSrc, pTab, pTabItem, pTabList, v, v2 uintptr
	var v3, v5 bool
	_, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _ = addr, addrIfNull, addrSeek, bEarlyOut, db, i, iDb, iEnd, j, j1, k, last, m, n, n1, nRJ, op, p, pIdx, pIdx1, pIn, pIx, pLastOp, pLevel, pLoop, pOp, pParse, pPk, pRJ, pSrc, pTab, pTabItem, pTabList, r1, v, ws, x, v2, v3, v4, v5
	pParse = (*TWhereInfo)(unsafe.Pointer(pWInfo)).FpParse
	v = (*TParse)(unsafe.Pointer(pParse)).FpVdbe
	pTabList = (*TWhereInfo)(unsafe.Pointer(pWInfo)).FpTabList
	db = (*TParse)(unsafe.Pointer(pParse)).Fdb
	iEnd = _sqlite3VdbeCurrentAddr(tls, v)
	nRJ = 0
	addrSeek = 0
	/* Generate loop termination code.
	 */
	i = libc.Int32FromUint8((*TWhereInfo)(unsafe.Pointer(pWInfo)).FnLevel) - int32(1)
	for {
		if !(i >= 0) {
			break
		}
		pLevel = pWInfo + 856 + uintptr(i)*112
		if (*TWhereLevel)(unsafe.Pointer(pLevel)).FpRJ != 0 {
			/* Terminate the subroutine that forms the interior of the loop of
			 ** the RIGHT JOIN table */
			pRJ = (*TWhereLevel)(unsafe.Pointer(pLevel)).FpRJ
			_sqlite3VdbeResolveLabel(tls, v, (*TWhereLevel)(unsafe.Pointer(pLevel)).FaddrCont)
			/* Replace addrCont with a new label that will never be used, just so
			 ** the subsequent call to resolve pLevel->addrCont will have something
			 ** to resolve. */
			(*TWhereLevel)(unsafe.Pointer(pLevel)).FaddrCont = _sqlite3VdbeMakeLabel(tls, pParse)
			(*TWhereRightJoin)(unsafe.Pointer(pRJ)).FendSubrtn = _sqlite3VdbeCurrentAddr(tls, v)
			_sqlite3VdbeAddOp3(tls, v, int32(OP_Return), (*TWhereRightJoin)(unsafe.Pointer(pRJ)).FregReturn, (*TWhereRightJoin)(unsafe.Pointer(pRJ)).FaddrSubrtn, int32(1))
			nRJ = nRJ + 1
		}
		pLoop = (*TWhereLevel)(unsafe.Pointer(pLevel)).FpWLoop
		if libc.Int32FromUint8((*TWhereLevel)(unsafe.Pointer(pLevel)).Fop) != int32(OP_Noop) {
			if v3 = libc.Int32FromUint8((*TWhereInfo)(unsafe.Pointer(pWInfo)).FeDistinct) == int32(WHERE_DISTINCT_ORDERED) && i == libc.Int32FromUint8((*TWhereInfo)(unsafe.Pointer(pWInfo)).FnLevel)-int32(1) && (*TWhereLoop)(unsafe.Pointer(pLoop)).FwsFlags&uint32(WHERE_INDEXED) != uint32(0); v3 {
				v2 = (*(*struct {
					FnEq          Tu16
					FnBtm         Tu16
					FnTop         Tu16
					FnDistinctCol Tu16
					FpIndex       uintptr
					FpOrderBy     uintptr
				})(unsafe.Pointer(pLoop + 24))).FpIndex
				pIdx = v2
			}
			if v5 = v3 && int32(uint32(*(*uint16)(unsafe.Pointer(v2 + 100))&0x80>>7)) != 0; v5 {
				v4 = libc.Int32FromUint16((*(*struct {
					FnEq          Tu16
					FnBtm         Tu16
					FnTop         Tu16
					FnDistinctCol Tu16
					FpIndex       uintptr
					FpOrderBy     uintptr
				})(unsafe.Pointer(pLoop + 24))).FnDistinctCol)
				n = v4
			}
			if v5 && v4 > 0 && int32(**(**TLogEst)(__ccgo_up((*TIndex)(unsafe.Pointer(pIdx)).FaiRowLogEst + uintptr(n)*2))) >= int32(36) {
				r1 = (*TParse)(unsafe.Pointer(pParse)).FnMem + int32(1)
				addrIfNull = 0 /* Init to avoid false-positive compiler warning */
				if (*TWhereLevel)(unsafe.Pointer(pLevel)).FiLeftJoin != 0 {
					addrIfNull = _sqlite3VdbeAddOp2(tls, v, int32(OP_IfNullRow), (*TWhereLevel)(unsafe.Pointer(pLevel)).FiIdxCur, r1)
				}
				j = 0
				for {
					if !(j < n) {
						break
					}
					_sqlite3VdbeAddOp3(tls, v, int32(OP_Column), (*TWhereLevel)(unsafe.Pointer(pLevel)).FiIdxCur, j, r1+j)
					goto _6
				_6:
					;
					j = j + 1
				}
				**(**int32)(__ccgo_up(pParse + 60)) += n + int32(1)
				if libc.Int32FromUint8((*TWhereLevel)(unsafe.Pointer(pLevel)).Fop) == int32(OP_Prev) {
					v4 = int32(OP_SeekLT)
				} else {
					v4 = int32(OP_SeekGT)
				}
				op = v4
				addrSeek = _sqlite3VdbeAddOp4Int(tls, v, op, (*TWhereLevel)(unsafe.Pointer(pLevel)).FiIdxCur, 0, r1, n)
				_sqlite3VdbeAddOp2(tls, v, int32(OP_Goto), int32(1), (*TWhereLevel)(unsafe.Pointer(pLevel)).Fp2)
				if (*TWhereLevel)(unsafe.Pointer(pLevel)).FiLeftJoin != 0 {
					_sqlite3VdbeJumpHere(tls, v, addrIfNull)
				}
			}
		}
		if int32(*(*uint32)(unsafe.Pointer(pTabList + 8 + uintptr((*TWhereLevel)(unsafe.Pointer(pLevel)).FiFrom)*80 + 24 + 4))&0x40000>>18) != 0 {
			/* This is an EXISTS-to-JOIN optimization loop. If this loop sees a
			 ** successful row, it should break out of itself. */
			_sqlite3VdbeAddOp2(tls, v, int32(OP_Goto), 0, (*TWhereLevel)(unsafe.Pointer(pLevel)).FaddrBrk)
		}
		_sqlite3VdbeResolveLabel(tls, v, (*TWhereLevel)(unsafe.Pointer(pLevel)).FaddrCont)
		if libc.Int32FromUint8((*TWhereLevel)(unsafe.Pointer(pLevel)).Fop) != int32(OP_Noop) {
			_sqlite3VdbeAddOp3(tls, v, libc.Int32FromUint8((*TWhereLevel)(unsafe.Pointer(pLevel)).Fop), (*TWhereLevel)(unsafe.Pointer(pLevel)).Fp1, (*TWhereLevel)(unsafe.Pointer(pLevel)).Fp2, libc.Int32FromUint8((*TWhereLevel)(unsafe.Pointer(pLevel)).Fp3))
			_sqlite3VdbeChangeP5(tls, v, uint16((*TWhereLevel)(unsafe.Pointer(pLevel)).Fp5))
			if (*TWhereLevel)(unsafe.Pointer(pLevel)).FregBignull != 0 {
				_sqlite3VdbeResolveLabel(tls, v, (*TWhereLevel)(unsafe.Pointer(pLevel)).FaddrBignull)
				_sqlite3VdbeAddOp2(tls, v, int32(OP_DecrJumpZero), (*TWhereLevel)(unsafe.Pointer(pLevel)).FregBignull, (*TWhereLevel)(unsafe.Pointer(pLevel)).Fp2-int32(1))
			}
			if addrSeek != 0 {
				_sqlite3VdbeJumpHere(tls, v, addrSeek)
				addrSeek = 0
			}
		}
		if (*TWhereLoop)(unsafe.Pointer(pLoop)).FwsFlags&uint32(WHERE_IN_ABLE) != uint32(0) && (*(*struct {
			FnIn     int32
			FaInLoop uintptr
		})(unsafe.Pointer(pLevel + 80))).FnIn > 0 {
			_sqlite3VdbeResolveLabel(tls, v, (*TWhereLevel)(unsafe.Pointer(pLevel)).FaddrNxt)
			j1 = (*(*struct {
				FnIn     int32
				FaInLoop uintptr
			})(unsafe.Pointer(pLevel + 80))).FnIn
			pIn = (*(*struct {
				FnIn     int32
				FaInLoop uintptr
			})(unsafe.Pointer(pLevel + 80))).FaInLoop + uintptr(j1-int32(1))*20
			for {
				if !(j1 > 0) {
					break
				}
				_sqlite3VdbeJumpHere(tls, v, (*TInLoop)(unsafe.Pointer(pIn)).FaddrInTop+int32(1))
				if libc.Int32FromUint8((*TInLoop)(unsafe.Pointer(pIn)).FeEndLoopOp) != int32(OP_Noop) {
					if (*TInLoop)(unsafe.Pointer(pIn)).FnPrefix != 0 {
						bEarlyOut = libc.BoolInt32((*TWhereLoop)(unsafe.Pointer(pLoop)).FwsFlags&uint32(WHERE_VIRTUALTABLE) == uint32(0) && (*TWhereLoop)(unsafe.Pointer(pLoop)).FwsFlags&uint32(WHERE_IN_EARLYOUT) != uint32(0))
						if (*TWhereLevel)(unsafe.Pointer(pLevel)).FiLeftJoin != 0 {
							/* For LEFT JOIN queries, cursor pIn->iCur may not have been
							 ** opened yet. This occurs for WHERE clauses such as
							 ** "a = ? AND b IN (...)", where the index is on (a, b). If
							 ** the RHS of the (a=?) is NULL, then the "b IN (...)" may
							 ** never have been coded, but the body of the loop run to
							 ** return the null-row. So, if the cursor is not open yet,
							 ** jump over the OP_Next or OP_Prev instruction about to
							 ** be coded.  */
							_sqlite3VdbeAddOp2(tls, v, int32(OP_IfNotOpen), (*TInLoop)(unsafe.Pointer(pIn)).FiCur, _sqlite3VdbeCurrentAddr(tls, v)+int32(2)+bEarlyOut)
						}
						if bEarlyOut != 0 {
							_sqlite3VdbeAddOp4Int(tls, v, int32(OP_IfNoHope), (*TWhereLevel)(unsafe.Pointer(pLevel)).FiIdxCur, _sqlite3VdbeCurrentAddr(tls, v)+int32(2), (*TInLoop)(unsafe.Pointer(pIn)).FiBase, (*TInLoop)(unsafe.Pointer(pIn)).FnPrefix)
							/* Retarget the OP_IsNull against the left operand of IN so
							 ** it jumps past the OP_IfNoHope.  This is because the
							 ** OP_IsNull also bypasses the OP_Affinity opcode that is
							 ** required by OP_IfNoHope. */
							_sqlite3VdbeJumpHere(tls, v, (*TInLoop)(unsafe.Pointer(pIn)).FaddrInTop+int32(1))
						}
					}
					_sqlite3VdbeAddOp2(tls, v, libc.Int32FromUint8((*TInLoop)(unsafe.Pointer(pIn)).FeEndLoopOp), (*TInLoop)(unsafe.Pointer(pIn)).FiCur, (*TInLoop)(unsafe.Pointer(pIn)).FaddrInTop)
				}
				_sqlite3VdbeJumpHere(tls, v, (*TInLoop)(unsafe.Pointer(pIn)).FaddrInTop-int32(1))
				goto _8
			_8:
				;
				j1 = j1 - 1
				pIn -= 20
			}
		}
		_sqlite3VdbeResolveLabel(tls, v, (*TWhereLevel)(unsafe.Pointer(pLevel)).FaddrBrk)
		if (*TWhereLevel)(unsafe.Pointer(pLevel)).FpRJ != 0 {
			_sqlite3VdbeAddOp3(tls, v, int32(OP_Return), (*TWhereRightJoin)(unsafe.Pointer((*TWhereLevel)(unsafe.Pointer(pLevel)).FpRJ)).FregReturn, 0, int32(1))
		}
		if (*TWhereLevel)(unsafe.Pointer(pLevel)).FaddrSkip != 0 {
			_sqlite3VdbeGoto(tls, v, (*TWhereLevel)(unsafe.Pointer(pLevel)).FaddrSkip)
			_sqlite3VdbeJumpHere(tls, v, (*TWhereLevel)(unsafe.Pointer(pLevel)).FaddrSkip)
			_sqlite3VdbeJumpHere(tls, v, (*TWhereLevel)(unsafe.Pointer(pLevel)).FaddrSkip-int32(2))
		}
		if (*TWhereLevel)(unsafe.Pointer(pLevel)).FiLeftJoin != 0 {
			ws = libc.Int32FromUint32((*TWhereLoop)(unsafe.Pointer(pLoop)).FwsFlags)
			addr = _sqlite3VdbeAddOp1(tls, v, int32(OP_IfPos), (*TWhereLevel)(unsafe.Pointer(pLevel)).FiLeftJoin)
			if ws&int32(WHERE_IDX_ONLY) == 0 {
				pSrc = pTabList + 8 + uintptr((*TWhereLevel)(unsafe.Pointer(pLevel)).FiFrom)*80
				if int32(*(*uint32)(unsafe.Pointer(pSrc + 24 + 4))&0x40>>6) != 0 {
					n1 = (*TSubquery)(unsafe.Pointer(*(*uintptr)(unsafe.Pointer(pSrc + 72)))).FregResult
					m = int32((*TTable)(unsafe.Pointer((*TSrcItem)(unsafe.Pointer(pSrc)).FpSTab)).FnCol)
					_sqlite3VdbeAddOp3(tls, v, int32(OP_Null), 0, n1, n1+m-int32(1))
				}
				_sqlite3VdbeAddOp1(tls, v, int32(OP_NullRow), (*TWhereLevel)(unsafe.Pointer(pLevel)).FiTabCur)
			}
			if ws&int32(WHERE_INDEXED) != 0 || ws&int32(WHERE_MULTI_OR) != 0 && *(*uintptr)(unsafe.Pointer(&(*TWhereLevel)(unsafe.Pointer(pLevel)).Fu)) != 0 {
				if ws&int32(WHERE_MULTI_OR) != 0 {
					pIx = *(*uintptr)(unsafe.Pointer(&(*TWhereLevel)(unsafe.Pointer(pLevel)).Fu))
					iDb = _sqlite3SchemaToIndex(tls, db, (*TIndex)(unsafe.Pointer(pIx)).FpSchema)
					_sqlite3VdbeAddOp3(tls, v, int32(OP_ReopenIdx), (*TWhereLevel)(unsafe.Pointer(pLevel)).FiIdxCur, libc.Int32FromUint32((*TIndex)(unsafe.Pointer(pIx)).Ftnum), iDb)
					_sqlite3VdbeSetP4KeyInfo(tls, pParse, pIx)
				}
				_sqlite3VdbeAddOp1(tls, v, int32(OP_NullRow), (*TWhereLevel)(unsafe.Pointer(pLevel)).FiIdxCur)
			}
			if libc.Int32FromUint8((*TWhereLevel)(unsafe.Pointer(pLevel)).Fop) == int32(OP_Return) {
				_sqlite3VdbeAddOp2(tls, v, int32(OP_Gosub), (*TWhereLevel)(unsafe.Pointer(pLevel)).Fp1, (*TWhereLevel)(unsafe.Pointer(pLevel)).FaddrFirst)
			} else {
				_sqlite3VdbeGoto(tls, v, (*TWhereLevel)(unsafe.Pointer(pLevel)).FaddrFirst)
			}
			_sqlite3VdbeJumpHere(tls, v, addr)
		}
		goto _1
	_1:
		;
		i = i - 1
	}
	i = 0
	pLevel = pWInfo + 856
	for {
		if !(i < libc.Int32FromUint8((*TWhereInfo)(unsafe.Pointer(pWInfo)).FnLevel)) {
			break
		}
		pIdx1 = uintptr(0)
		pTabItem = pTabList + 8 + uintptr((*TWhereLevel)(unsafe.Pointer(pLevel)).FiFrom)*80
		pTab = (*TSrcItem)(unsafe.Pointer(pTabItem)).FpSTab
		pLoop = (*TWhereLevel)(unsafe.Pointer(pLevel)).FpWLoop
		/* Do RIGHT JOIN processing.  Generate code that will output the
		 ** unmatched rows of the right operand of the RIGHT JOIN with
		 ** all of the columns of the left operand set to NULL.
		 */
		if (*TWhereLevel)(unsafe.Pointer(pLevel)).FpRJ != 0 {
			_sqlite3WhereRightJoinLoop(tls, pWInfo, i, pLevel)
			goto _9
		}
		/* For a co-routine, change all OP_Column references to the table of
		 ** the co-routine into OP_Copy of result contained in a register.
		 ** OP_Rowid becomes OP_Null.
		 */
		if int32(*(*uint32)(unsafe.Pointer(pTabItem + 24 + 4))&0x40>>6) != 0 {
			_translateColumnToCopy(tls, pParse, (*TWhereLevel)(unsafe.Pointer(pLevel)).FaddrBody, (*TWhereLevel)(unsafe.Pointer(pLevel)).FiTabCur, (*TSubquery)(unsafe.Pointer(*(*uintptr)(unsafe.Pointer(pTabItem + 72)))).FregResult, 0)
			goto _9
		}
		/* If this scan uses an index, make VDBE code substitutions to read data
		 ** from the index instead of from the table where possible.  In some cases
		 ** this optimization prevents the table from ever being read, which can
		 ** yield a significant performance boost.
		 **
		 ** Calls to the code generator in between sqlite3WhereBegin and
		 ** sqlite3WhereEnd will have created code that references the table
		 ** directly.  This loop scans all that code looking for opcodes
		 ** that reference the table and converts them into opcodes that
		 ** reference the index.
		 */
		if (*TWhereLoop)(unsafe.Pointer(pLoop)).FwsFlags&libc.Uint32FromInt32(libc.Int32FromInt32(WHERE_INDEXED)|libc.Int32FromInt32(WHERE_IDX_ONLY)) != 0 {
			pIdx1 = (*(*struct {
				FnEq          Tu16
				FnBtm         Tu16
				FnTop         Tu16
				FnDistinctCol Tu16
				FpIndex       uintptr
				FpOrderBy     uintptr
			})(unsafe.Pointer(pLoop + 24))).FpIndex
		} else {
			if (*TWhereLoop)(unsafe.Pointer(pLoop)).FwsFlags&uint32(WHERE_MULTI_OR) != 0 {
				pIdx1 = *(*uintptr)(unsafe.Pointer(&(*TWhereLevel)(unsafe.Pointer(pLevel)).Fu))
			}
		}
		if pIdx1 != 0 && !((*Tsqlite3)(unsafe.Pointer(db)).FmallocFailed != 0) {
			if libc.Int32FromUint8((*TWhereInfo)(unsafe.Pointer(pWInfo)).FeOnePass) == ONEPASS_OFF || !((*TTable)(unsafe.Pointer((*TIndex)(unsafe.Pointer(pIdx1)).FpTable)).FtabFlags&libc.Uint32FromInt32(TF_WithoutRowid) == libc.Uint32FromInt32(0)) {
				last = iEnd
			} else {
				last = (*TWhereInfo)(unsafe.Pointer(pWInfo)).FiEndWhere
			}
			if int32(uint32(*(*uint16)(unsafe.Pointer(pIdx1 + 100))&0x800>>11)) != 0 {
				p = (*TParse)(unsafe.Pointer(pParse)).FpIdxEpr
				for p != 0 {
					if (*TIndexedExpr)(unsafe.Pointer(p)).FiIdxCur == (*TWhereLevel)(unsafe.Pointer(pLevel)).FiIdxCur {
						(*TIndexedExpr)(unsafe.Pointer(p)).FiDataCur = -int32(1)
						(*TIndexedExpr)(unsafe.Pointer(p)).FiIdxCur = -int32(1)
					}
					p = (*TIndexedExpr)(unsafe.Pointer(p)).FpIENext
				}
			}
			k = (*TWhereLevel)(unsafe.Pointer(pLevel)).FaddrBody + int32(1)
			pOp = _sqlite3VdbeGetOp(tls, v, k)
			pLastOp = pOp + uintptr(last-k)*24
			for {
				if (*TVdbeOp)(unsafe.Pointer(pOp)).Fp1 != (*TWhereLevel)(unsafe.Pointer(pLevel)).FiTabCur {
					/* no-op */
				} else {
					if libc.Int32FromUint8((*TVdbeOp)(unsafe.Pointer(pOp)).Fopcode) == int32(OP_Column) || libc.Int32FromUint8((*TVdbeOp)(unsafe.Pointer(pOp)).Fopcode) == int32(OP_Offset) {
						x = (*TVdbeOp)(unsafe.Pointer(pOp)).Fp2
						if libc.Int32FromUint8((*TVdbeOp)(unsafe.Pointer(pOp)).Fopcode) == int32(OP_Offset) {
							/* Do not need to translate the column number */
						} else {
							if !((*TTable)(unsafe.Pointer(pTab)).FtabFlags&libc.Uint32FromInt32(TF_WithoutRowid) == libc.Uint32FromInt32(0)) {
								pPk = _sqlite3PrimaryKeyIndex(tls, pTab)
								x = int32(**(**Ti16)(__ccgo_up((*TIndex)(unsafe.Pointer(pPk)).FaiColumn + uintptr(x)*2)))
							} else {
								x = int32(_sqlite3StorageColumnToTable(tls, pTab, int16(x)))
							}
						}
						x = _sqlite3TableColumnToIndex(tls, pIdx1, x)
						if x >= 0 {
							(*TVdbeOp)(unsafe.Pointer(pOp)).Fp2 = x
							(*TVdbeOp)(unsafe.Pointer(pOp)).Fp1 = (*TWhereLevel)(unsafe.Pointer(pLevel)).FiIdxCur
						} else {
							if (*TWhereLoop)(unsafe.Pointer(pLoop)).FwsFlags&libc.Uint32FromInt32(libc.Int32FromInt32(WHERE_IDX_ONLY)|libc.Int32FromInt32(WHERE_EXPRIDX)) != 0 {
								if (*TWhereLoop)(unsafe.Pointer(pLoop)).FwsFlags&uint32(WHERE_IDX_ONLY) != 0 {
									/* An error. pLoop is supposed to be a covering index loop,
									 ** and yet the VM code refers to a column of the table that
									 ** is not part of the index.  */
									_sqlite3ErrorMsg(tls, pParse, __ccgo_ts+24139, 0)
									(*TParse)(unsafe.Pointer(pParse)).Frc = int32(SQLITE_INTERNAL)
								} else {
									/* The WHERE_EXPRIDX flag is set by the planner when it is likely
									 ** that pLoop is a covering index loop, but it is not possible
									 ** to be 100% sure. In this case, any OP_Explain opcode
									 ** corresponding to this loop describes the index as a "COVERING
									 ** INDEX". But, pOp proves that pLoop is not actually a covering
									 ** index loop. So clear the WHERE_EXPRIDX flag and rewrite the
									 ** text that accompanies the OP_Explain opcode, if any.  */
									**(**Tu32)(__ccgo_up(pLoop + 48)) &= libc.Uint32FromInt32(^libc.Int32FromInt32(WHERE_EXPRIDX))
									_sqlite3WhereAddExplainText(tls, pParse, (*TWhereLevel)(unsafe.Pointer(pLevel)).FaddrBody-int32(1), pTabList, pLevel, (*TWhereInfo)(unsafe.Pointer(pWInfo)).FwctrlFlags)
								}
							}
						}
					} else {
						if libc.Int32FromUint8((*TVdbeOp)(unsafe.Pointer(pOp)).Fopcode) == int32(OP_Rowid) {
							(*TVdbeOp)(unsafe.Pointer(pOp)).Fp1 = (*TWhereLevel)(unsafe.Pointer(pLevel)).FiIdxCur
							(*TVdbeOp)(unsafe.Pointer(pOp)).Fopcode = uint8(OP_IdxRowid)
						} else {
							if libc.Int32FromUint8((*TVdbeOp)(unsafe.Pointer(pOp)).Fopcode) == int32(OP_IfNullRow) {
								(*TVdbeOp)(unsafe.Pointer(pOp)).Fp1 = (*TWhereLevel)(unsafe.Pointer(pLevel)).FiIdxCur
							}
						}
					}
				}
				goto _11
			_11:
				;
				pOp += 24
				v2 = pOp
				if !(v2 < pLastOp) {
					break
				}
			}
		}
		goto _9
	_9:
		;
		i = i + 1
		pLevel += 112
	}
	/* The "break" point is here, just past the end of the outer loop.
	 ** Set it.
	 */
	_sqlite3VdbeResolveLabel(tls, v, (*TWhereInfo)(unsafe.Pointer(pWInfo)).FiBreak)
	/* Final cleanup
	 */
	(*TParse)(unsafe.Pointer(pParse)).FnQueryLoop = int16((*TWhereInfo)(unsafe.Pointer(pWInfo)).FsavedNQueryLoop)
	_whereInfoFree(tls, db, pWInfo)
	v2 = pParse + 35
	*(*Tu8)(unsafe.Pointer(v2)) = Tu8(int32(*(*Tu8)(unsafe.Pointer(v2))) - nRJ)
	return
}

/************** End of where.c ***********************************************/
/************** Begin file window.c ******************************************/
/*
** 2018 May 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.
**
*************************************************************************
 */
/* #include "sqliteInt.h" */

/*
** SELECT REWRITING
**
**   Any SELECT statement that contains one or more window functions in
**   either the select list or ORDER BY clause (the only two places window
**   functions may be used) is transformed by function sqlite3WindowRewrite()
**   in order to support window function processing. For example, with the
**   schema:
**
**     CREATE TABLE t1(a, b, c, d, e, f, g);
**
**   the statement:
**
**     SELECT a+1, max(b) OVER (PARTITION BY c ORDER BY d) FROM t1 ORDER BY e;
**
**   is transformed to:
**
**     SELECT a+1, max(b) OVER (PARTITION BY c ORDER BY d) FROM (
**         SELECT a, e, c, d, b FROM t1 ORDER BY c, d
**     ) ORDER BY e;
**
**   The flattening optimization is disabled when processing this transformed
**   SELECT statement. This allows the implementation of the window function
**   (in this case max()) to process rows sorted in order of (c, d), which
**   makes things easier for obvious reasons. More generally:
**
**     * FROM, WHERE, GROUP BY and HAVING clauses are all moved to
**       the sub-query.
**
**     * ORDER BY, LIMIT and OFFSET remain part of the parent query.
**
**     * Terminals from each of the expression trees that make up the
**       select-list and ORDER BY expressions in the parent query are
**       selected by the sub-query. For the purposes of the transformation,
**       terminals are column references and aggregate functions.
**
**   If there is more than one window function in the SELECT that uses
**   the same window declaration (the OVER bit), then a single scan may
**   be used to process more than one window function. For example:
**
**     SELECT max(b) OVER (PARTITION BY c ORDER BY d),
**            min(e) OVER (PARTITION BY c ORDER BY d)
**     FROM t1;
**
**   is transformed in the same way as the example above. However:
**
**     SELECT max(b) OVER (PARTITION BY c ORDER BY d),
**            min(e) OVER (PARTITION BY a ORDER BY b)
**     FROM t1;
**
**   Must be transformed to:
**
**     SELECT max(b) OVER (PARTITION BY c ORDER BY d) FROM (
**         SELECT e, min(e) OVER (PARTITION BY a ORDER BY b), c, d, b FROM
**           SELECT a, e, c, d, b FROM t1 ORDER BY a, b
**         ) ORDER BY c, d
**     ) ORDER BY e;
**
**   so that both min() and max() may process rows in the order defined by
**   their respective window declarations.
**
** INTERFACE WITH SELECT.C
**
**   When processing the rewritten SELECT statement, code in select.c calls
**   sqlite3WhereBegin() to begin iterating through the results of the
**   sub-query, which is always implemented as a co-routine. It then calls
**   sqlite3WindowCodeStep() to process rows and finish the scan by calling
**   sqlite3WhereEnd().
**
**   sqlite3WindowCodeStep() generates VM code so that, for each row returned
**   by the sub-query a sub-routine (OP_Gosub) coded by select.c is invoked.
**   When the sub-routine is invoked:
**
**     * The results of all window-functions for the row are stored
**       in the associated Window.regResult registers.
**
**     * The required terminal values are stored in the current row of
**       temp table Window.iEphCsr.
**
**   In some cases, depending on the window frame and the specific window
**   functions invoked, sqlite3WindowCodeStep() caches each entire partition
**   in a temp table before returning any rows. In other cases it does not.
**   This detail is encapsulated within this file, the code generated by
**   select.c is the same in either case.
**
** BUILT-IN WINDOW FUNCTIONS
**
**   This implementation features the following built-in window functions:
**
**     row_number()
**     rank()
**     dense_rank()
**     percent_rank()
**     cume_dist()
**     ntile(N)
**     lead(expr [, offset [, default]])
**     lag(expr [, offset [, default]])
**     first_value(expr)
**     last_value(expr)
**     nth_value(expr, N)
**
**   These are the same built-in window functions supported by Postgres.
**   Although the behaviour of aggregate window functions (functions that
**   can be used as either aggregates or window functions) allows them to
**   be implemented using an API, built-in window functions are much more
**   esoteric. Additionally, some window functions (e.g. nth_value())
**   may only be implemented by caching the entire partition in memory.
**   As such, some built-in window functions use the same API as aggregate
**   window functions and some are implemented directly using VDBE
**   instructions. Additionally, for those functions that use the API, the
**   window frame is sometimes modified before the SELECT statement is
**   rewritten. For example, regardless of the specified window frame, the
**   row_number() function always uses:
**
**     ROWS BETWEEN UNBOUNDED PRECEDING AND CURRENT ROW
**
**   See sqlite3WindowUpdate() for details.
**
**   As well as some of the built-in window functions, aggregate window
**   functions min() and max() are implemented using VDBE instructions if
**   the start of the window frame is declared as anything other than
**   UNBOUNDED PRECEDING.
 */

// C documentation
//
//	/*
//	** Generate the code for the loop that finds all non-matched terms
//	** for a RIGHT JOIN.
//	*/
func _sqlite3WhereRightJoinLoop(tls *libc.TLS, pWInfo uintptr, iLevel int32, pLevel uintptr) {
	bp := tls.Alloc(112)
	defer tls.Free(112)
	var addrCont, iCol, iCur, iIdxCur, iPk, jmp, k, nPk, r, v3 int32
	var mAll TBitmask
	var pFrom, pLoop, pParse, pPk, pRJ, pRight, pSubWInfo, pSubWhere, pSubq, pTab, pTabItem, pTerm, pWC, v, v4 uintptr
	var _ /* uSrc at bp+0 */ struct {
		FfromSpace   [0][88]Tu8
		FsSrc        TSrcList
		F__ccgo_pad2 [80]byte
	}
	_, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _ = addrCont, iCol, iCur, iIdxCur, iPk, jmp, k, mAll, nPk, pFrom, pLoop, pParse, pPk, pRJ, pRight, pSubWInfo, pSubWhere, pSubq, pTab, pTabItem, pTerm, pWC, r, v, v3, v4
	pParse = (*TWhereInfo)(unsafe.Pointer(pWInfo)).FpParse
	v = (*TParse)(unsafe.Pointer(pParse)).FpVdbe
	pRJ = (*TWhereLevel)(unsafe.Pointer(pLevel)).FpRJ
	pSubWhere = uintptr(0)
	pWC = pWInfo + 104
	pLoop = (*TWhereLevel)(unsafe.Pointer(pLevel)).FpWLoop
	pTabItem = (*TWhereInfo)(unsafe.Pointer(pWInfo)).FpTabList + 8 + uintptr((*TWhereLevel)(unsafe.Pointer(pLevel)).FiFrom)*80
	mAll = uint64(0)
	_sqlite3VdbeExplain(tls, pParse, uint8(1), __ccgo_ts+23913, libc.VaList(bp+96, (*TTable)(unsafe.Pointer((*TSrcItem)(unsafe.Pointer(pTabItem)).FpSTab)).FzName))
	k = 0
	for {
		if !(k < iLevel) {
			break
		}
		pRight = (*TWhereInfo)(unsafe.Pointer(pWInfo)).FpTabList + 8 + uintptr((*(*TWhereLevel)(unsafe.Pointer(pWInfo + 856 + uintptr(k)*112))).FiFrom)*80
		mAll = mAll | (*TWhereLoop)(unsafe.Pointer((*(*TWhereLevel)(unsafe.Pointer(pWInfo + 856 + uintptr(k)*112))).FpWLoop)).FmaskSelf
		if int32(*(*uint32)(unsafe.Pointer(pRight + 24 + 4))&0x40>>6) != 0 {
			pSubq = *(*uintptr)(unsafe.Pointer(pRight + 72))
			_sqlite3VdbeAddOp3(tls, v, int32(OP_Null), 0, (*TSubquery)(unsafe.Pointer(pSubq)).FregResult, (*TSubquery)(unsafe.Pointer(pSubq)).FregResult+(*TExprList)(unsafe.Pointer((*TSelect)(unsafe.Pointer((*TSubquery)(unsafe.Pointer(pSubq)).FpSelect)).FpEList)).FnExpr-int32(1))
		}
		_sqlite3VdbeAddOp1(tls, v, int32(OP_NullRow), (*(*TWhereLevel)(unsafe.Pointer(pWInfo + 856 + uintptr(k)*112))).FiTabCur)
		iIdxCur = (*(*TWhereLevel)(unsafe.Pointer(pWInfo + 856 + uintptr(k)*112))).FiIdxCur
		if iIdxCur != 0 {
			_sqlite3VdbeAddOp1(tls, v, int32(OP_NullRow), iIdxCur)
		}
		goto _1
	_1:
		;
		k = k + 1
	}
	if libc.Int32FromUint8((*TSrcItem)(unsafe.Pointer(pTabItem)).Ffg.Fjointype)&int32(JT_LTORJ) == 0 {
		mAll = mAll | (*TWhereLoop)(unsafe.Pointer(pLoop)).FmaskSelf
		k = 0
		for {
			if !(k < (*TWhereClause)(unsafe.Pointer(pWC)).FnTerm) {
				break
			}
			pTerm = (*TWhereClause)(unsafe.Pointer(pWC)).Fa + uintptr(k)*56
			if libc.Int32FromUint16((*TWhereTerm)(unsafe.Pointer(pTerm)).FwtFlags)&(libc.Int32FromInt32(TERM_VIRTUAL)|libc.Int32FromInt32(TERM_SLICE)) != 0 && libc.Int32FromUint16((*TWhereTerm)(unsafe.Pointer(pTerm)).FeOperator) != int32(WO_ROWVAL) {
				break
			}
			if (*TWhereTerm)(unsafe.Pointer(pTerm)).FprereqAll & ^mAll != 0 {
				goto _2
			}
			if (*TExpr)(unsafe.Pointer((*TWhereTerm)(unsafe.Pointer(pTerm)).FpExpr)).Fflags&libc.Uint32FromInt32(libc.Int32FromInt32(EP_OuterON)|libc.Int32FromInt32(EP_InnerON)) != uint32(0) {
				goto _2
			}
			pSubWhere = _sqlite3ExprAnd(tls, pParse, pSubWhere, _sqlite3ExprDup(tls, (*TParse)(unsafe.Pointer(pParse)).Fdb, (*TWhereTerm)(unsafe.Pointer(pTerm)).FpExpr, 0))
			goto _2
		_2:
			;
			k = k + 1
		}
	}
	if (*TWhereLevel)(unsafe.Pointer(pLevel)).FiIdxCur != 0 {
		/* pSubWhere may contain expressions that read from an index on the
		 ** table on the RHS of the right join. All such expressions first test
		 ** if the index is pointing at a NULL row, and if so, read from the
		 ** table cursor instead. So ensure that the index cursor really is
		 ** pointing at a NULL row here, so that no values are read from it during
		 ** the scan of the RHS of the RIGHT join below.  */
		_sqlite3VdbeAddOp1(tls, v, int32(OP_NullRow), (*TWhereLevel)(unsafe.Pointer(pLevel)).FiIdxCur)
	}
	pFrom = bp
	(*TSrcList)(unsafe.Pointer(pFrom)).FnSrc = int32(1)
	(*TSrcList)(unsafe.Pointer(pFrom)).FnAlloc = uint32(1)
	libc.Xmemcpy(tls, pFrom+8, pTabItem, uint64(80))
	(*(*TSrcItem)(unsafe.Pointer(pFrom + 8))).Ffg.Fjointype = uint8(0)
	(*TParse)(unsafe.Pointer(pParse)).FwithinRJSubrtn = (*TParse)(unsafe.Pointer(pParse)).FwithinRJSubrtn + 1
	pSubWInfo = _sqlite3WhereBegin(tls, pParse, pFrom, pSubWhere, uintptr(0), uintptr(0), uintptr(0), uint16(WHERE_RIGHT_JOIN), 0)
	if pSubWInfo != 0 {
		iCur = (*TWhereLevel)(unsafe.Pointer(pLevel)).FiTabCur
		v4 = pParse + 60
		*(*int32)(unsafe.Pointer(v4)) = *(*int32)(unsafe.Pointer(v4)) + 1
		v3 = *(*int32)(unsafe.Pointer(v4))
		r = v3
		addrCont = _sqlite3WhereContinueLabel(tls, pSubWInfo)
		pTab = (*TSrcItem)(unsafe.Pointer(pTabItem)).FpSTab
		if (*TTable)(unsafe.Pointer(pTab)).FtabFlags&uint32(TF_WithoutRowid) == uint32(0) {
			_sqlite3ExprCodeGetColumnOfTable(tls, v, pTab, iCur, -int32(1), r)
			nPk = int32(1)
		} else {
			pPk = _sqlite3PrimaryKeyIndex(tls, pTab)
			nPk = libc.Int32FromUint16((*TIndex)(unsafe.Pointer(pPk)).FnKeyCol)
			**(**int32)(__ccgo_up(pParse + 60)) += nPk - int32(1)
			iPk = 0
			for {
				if !(iPk < nPk) {
					break
				}
				iCol = int32(**(**Ti16)(__ccgo_up((*TIndex)(unsafe.Pointer(pPk)).FaiColumn + uintptr(iPk)*2)))
				_sqlite3ExprCodeGetColumnOfTable(tls, v, pTab, iCur, iCol, r+iPk)
				goto _5
			_5:
				;
				iPk = iPk + 1
			}
		}
		jmp = _sqlite3VdbeAddOp4Int(tls, v, int32(OP_Filter), (*TWhereRightJoin)(unsafe.Pointer(pRJ)).FregBloom, 0, r, nPk)
		_sqlite3VdbeAddOp4Int(tls, v, int32(OP_Found), (*TWhereRightJoin)(unsafe.Pointer(pRJ)).FiMatch, addrCont, r, nPk)
		_sqlite3VdbeJumpHere(tls, v, jmp)
		_sqlite3VdbeAddOp2(tls, v, int32(OP_Gosub), (*TWhereRightJoin)(unsafe.Pointer(pRJ)).FregReturn, (*TWhereRightJoin)(unsafe.Pointer(pRJ)).FaddrSubrtn)
		_sqlite3WhereEnd(tls, pSubWInfo)
	}
	_sqlite3ExprDelete(tls, (*TParse)(unsafe.Pointer(pParse)).Fdb, pSubWhere)
	_sqlite3VdbeExplainPop(tls, pParse)
	(*TParse)(unsafe.Pointer(pParse)).FwithinRJSubrtn = (*TParse)(unsafe.Pointer(pParse)).FwithinRJSubrtn - 1
}

// C documentation
//
//	/*
//	** For table-valued-functions, transform the function arguments into
//	** new WHERE clause terms.
//	**
//	** Each function argument translates into an equality constraint against
//	** a HIDDEN column in the table.
//	*/
func _sqlite3WhereTabFuncArgs(tls *libc.TLS, pParse uintptr, pItem uintptr, pWC uintptr) {
	bp := tls.Alloc(32)
	defer tls.Free(32)
	var j, k, v2 int32
	var joinType Tu32
	var pArgs, pColRef, pRhs, pTab, pTerm uintptr
	_, _, _, _, _, _, _, _, _ = j, joinType, k, pArgs, pColRef, pRhs, pTab, pTerm, v2
	if int32(*(*uint32)(unsafe.Pointer(pItem + 24 + 4))&0x8>>3) == 0 {
		return
	}
	pTab = (*TSrcItem)(unsafe.Pointer(pItem)).FpSTab
	pArgs = *(*uintptr)(unsafe.Pointer(pItem + 48))
	if pArgs == uintptr(0) {
		return
	}
	v2 = libc.Int32FromInt32(0)
	k = v2
	j = v2
	for {
		if !(j < (*TExprList)(unsafe.Pointer(pArgs)).FnExpr) {
			break
		}
		for k < int32((*TTable)(unsafe.Pointer(pTab)).FnCol) && libc.Int32FromUint16((**(**TColumn)(__ccgo_up((*TTable)(unsafe.Pointer(pTab)).FaCol + uintptr(k)*16))).FcolFlags)&int32(COLFLAG_HIDDEN) == 0 {
			k = k + 1
		}
		if k >= int32((*TTable)(unsafe.Pointer(pTab)).FnCol) {
			_sqlite3ErrorMsg(tls, pParse, __ccgo_ts+23941, libc.VaList(bp+8, (*TTable)(unsafe.Pointer(pTab)).FzName, j))
			return
		}
		pColRef = _sqlite3ExprAlloc(tls, (*TParse)(unsafe.Pointer(pParse)).Fdb, int32(TK_COLUMN), uintptr(0), 0)
		if pColRef == uintptr(0) {
			return
		}
		(*TExpr)(unsafe.Pointer(pColRef)).FiTable = (*TSrcItem)(unsafe.Pointer(pItem)).FiCursor
		v2 = k
		k = k + 1
		(*TExpr)(unsafe.Pointer(pColRef)).FiColumn = int16(v2)
		*(*uintptr)(unsafe.Pointer(pColRef + 64)) = pTab
		**(**TBitmask)(__ccgo_up(pItem + 40)) |= _sqlite3ExprColUsed(tls, pColRef)
		pRhs = _sqlite3PExpr(tls, pParse, int32(TK_UPLUS), _sqlite3ExprDup(tls, (*TParse)(unsafe.Pointer(pParse)).Fdb, (*(*TExprList_item)(unsafe.Pointer(pArgs + 8 + uintptr(j)*32))).FpExpr, 0), uintptr(0))
		pTerm = _sqlite3PExpr(tls, pParse, int32(TK_EQ), pColRef, pRhs)
		if libc.Int32FromUint8((*TSrcItem)(unsafe.Pointer(pItem)).Ffg.Fjointype)&(libc.Int32FromInt32(JT_LEFT)|libc.Int32FromInt32(JT_RIGHT)) != 0 {
			/* testtag-20230227a */
			/* testtag-20230227b */
			joinType = uint32(EP_OuterON)
		} else {
			/* testtag-20230227c */
			joinType = uint32(EP_InnerON)
		}
		_sqlite3SetJoinExpr(tls, pTerm, (*TSrcItem)(unsafe.Pointer(pItem)).FiCursor, joinType)
		_whereClauseInsert(tls, pWC, pTerm, uint16(TERM_DYNAMIC))
		goto _1
	_1:
		;
		j = j + 1
	}
}

/************** End of whereexpr.c *******************************************/
/************** Begin file where.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 module contains C code that generates VDBE code used to process
** the WHERE clause of SQL statements.  This module is responsible for
** generating the code that loops through a table looking for applicable
** rows.  Indices are selected and used to speed the search when doing
** so is applicable.  Because this module is responsible for selecting
** indices, you might also think of this module as the "query optimizer".
 */
/* #include "sqliteInt.h" */
/* #include "whereInt.h" */

// C documentation
//
//	/*
//	** Allocate and return a new Window object describing a Window Definition.
//	*/
func _sqlite3WindowAlloc(tls *libc.TLS, pParse uintptr, eType int32, eStart int32, pStart uintptr, eEnd int32, pEnd uintptr, eExclude Tu8) (r uintptr) {
	var bImplicitFrame int32
	var pWin uintptr
	_, _ = bImplicitFrame, pWin
	pWin = uintptr(0)
	bImplicitFrame = 0
	/* Parser assures the following: */
	if eType == 0 {
		bImplicitFrame = int32(1)
		eType = int32(TK_RANGE)
	}
	/* Additionally, the
	 ** starting boundary type may not occur earlier in the following list than
	 ** the ending boundary type:
	 **
	 **   UNBOUNDED PRECEDING
	 **   <expr> PRECEDING
	 **   CURRENT ROW
	 **   <expr> FOLLOWING
	 **   UNBOUNDED FOLLOWING
	 **
	 ** The parser ensures that "UNBOUNDED PRECEDING" cannot be used as an ending
	 ** boundary, and than "UNBOUNDED FOLLOWING" cannot be used as a starting
	 ** frame boundary.
	 */
	if eStart == int32(TK_CURRENT) && eEnd == int32(TK_PRECEDING) || eStart == int32(TK_FOLLOWING) && (eEnd == int32(TK_PRECEDING) || eEnd == int32(TK_CURRENT)) {
		_sqlite3ErrorMsg(tls, pParse, __ccgo_ts+24448, 0)
		goto windowAllocErr
	}
	pWin = _sqlite3DbMallocZero(tls, (*TParse)(unsafe.Pointer(pParse)).Fdb, uint64(144))
	if pWin == uintptr(0) {
		goto windowAllocErr
	}
	(*TWindow)(unsafe.Pointer(pWin)).FeFrmType = libc.Uint8FromInt32(eType)
	(*TWindow)(unsafe.Pointer(pWin)).FeStart = libc.Uint8FromInt32(eStart)
	(*TWindow)(unsafe.Pointer(pWin)).FeEnd = libc.Uint8FromInt32(eEnd)
	if libc.Int32FromUint8(eExclude) == 0 && (*Tsqlite3)(unsafe.Pointer((*TParse)(unsafe.Pointer(pParse)).Fdb)).FdbOptFlags&libc.Uint32FromInt32(libc.Int32FromInt32(SQLITE_WindowFunc)) != uint32(0) {
		eExclude = uint8(TK_NO)
	}
	(*TWindow)(unsafe.Pointer(pWin)).FeExclude = eExclude
	(*TWindow)(unsafe.Pointer(pWin)).FbImplicitFrame = libc.Uint8FromInt32(bImplicitFrame)
	(*TWindow)(unsafe.Pointer(pWin)).FpEnd = _sqlite3WindowOffsetExpr(tls, pParse, pEnd)
	(*TWindow)(unsafe.Pointer(pWin)).FpStart = _sqlite3WindowOffsetExpr(tls, pParse, pStart)
	return pWin
	goto windowAllocErr
windowAllocErr:
	;
	_sqlite3ExprDelete(tls, (*TParse)(unsafe.Pointer(pParse)).Fdb, pEnd)
	_sqlite3ExprDelete(tls, (*TParse)(unsafe.Pointer(pParse)).Fdb, pStart)
	return uintptr(0)
}

// C documentation
//
//	/*
//	** Attach window object pWin to expression p.
//	*/
func _sqlite3WindowAttach(tls *libc.TLS, pParse uintptr, p uintptr, pWin uintptr) {
	if p != 0 {
		*(*uintptr)(unsafe.Pointer(p + 64)) = pWin
		**(**Tu32)(__ccgo_up(p + 4)) |= libc.Uint32FromInt32(libc.Int32FromInt32(EP_WinFunc) | libc.Int32FromInt32(EP_FullSize))
		(*TWindow)(unsafe.Pointer(pWin)).FpOwner = p
		if (*TExpr)(unsafe.Pointer(p)).Fflags&uint32(EP_Distinct) != 0 && libc.Int32FromUint8((*TWindow)(unsafe.Pointer(pWin)).FeFrmType) != int32(TK_FILTER) {
			_sqlite3ErrorMsg(tls, pParse, __ccgo_ts+24566, 0)
		}
	} else {
		_sqlite3WindowDelete(tls, (*TParse)(unsafe.Pointer(pParse)).Fdb, pWin)
	}
}

// C documentation
//
//	/*
//	** Window *pWin has just been created from a WINDOW clause. Token pBase
//	** is the base window. Earlier windows from the same WINDOW clause are
//	** stored in the linked list starting at pWin->pNextWin. This function
//	** either updates *pWin according to the base specification, or else
//	** leaves an error in pParse.
//	*/
func _sqlite3WindowChain(tls *libc.TLS, pParse uintptr, pWin uintptr, pList uintptr) {
	bp := tls.Alloc(32)
	defer tls.Free(32)
	var db, pExist, zErr uintptr
	_, _, _ = db, pExist, zErr
	if (*TWindow)(unsafe.Pointer(pWin)).FzBase != 0 {
		db = (*TParse)(unsafe.Pointer(pParse)).Fdb
		pExist = _windowFind(tls, pParse, pList, (*TWindow)(unsafe.Pointer(pWin)).FzBase)
		if pExist != 0 {
			zErr = uintptr(0)
			/* Check for errors */
			if (*TWindow)(unsafe.Pointer(pWin)).FpPartition != 0 {
				zErr = __ccgo_ts + 24480
			} else {
				if (*TWindow)(unsafe.Pointer(pExist)).FpOrderBy != 0 && (*TWindow)(unsafe.Pointer(pWin)).FpOrderBy != 0 {
					zErr = __ccgo_ts + 24497
				} else {
					if libc.Int32FromUint8((*TWindow)(unsafe.Pointer(pExist)).FbImplicitFrame) == 0 {
						zErr = __ccgo_ts + 24513
					}
				}
			}
			if zErr != 0 {
				_sqlite3ErrorMsg(tls, pParse, __ccgo_ts+24533, libc.VaList(bp+8, zErr, (*TWindow)(unsafe.Pointer(pWin)).FzBase))
			} else {
				(*TWindow)(unsafe.Pointer(pWin)).FpPartition = _sqlite3ExprListDup(tls, db, (*TWindow)(unsafe.Pointer(pExist)).FpPartition, 0)
				if (*TWindow)(unsafe.Pointer(pExist)).FpOrderBy != 0 {
					(*TWindow)(unsafe.Pointer(pWin)).FpOrderBy = _sqlite3ExprListDup(tls, db, (*TWindow)(unsafe.Pointer(pExist)).FpOrderBy, 0)
				}
				_sqlite3DbFree(tls, db, (*TWindow)(unsafe.Pointer(pWin)).FzBase)
				(*TWindow)(unsafe.Pointer(pWin)).FzBase = uintptr(0)
			}
		}
	}
}

// C documentation
//
//	/*
//	** This function is called immediately after resolving the function name
//	** for a window function within a SELECT statement. Argument pList is a
//	** linked list of WINDOW definitions for the current SELECT statement.
//	** Argument pFunc is the function definition just resolved and pWin
//	** is the Window object representing the associated OVER clause. This
//	** function updates the contents of pWin as follows:
//	**
//	**   * If the OVER clause referred to a named window (as in "max(x) OVER win"),
//	**     search list pList for a matching WINDOW definition, and update pWin
//	**     accordingly. If no such WINDOW clause can be found, leave an error
//	**     in pParse.
//	**
//	**   * If the function is a built-in window function that requires the
//	**     window to be coerced (see "BUILT-IN WINDOW FUNCTIONS" at the top
//	**     of this file), pWin is updated here.
//	*/
func _sqlite3WindowUpdate(tls *libc.TLS, pParse uintptr, pList uintptr, pWin uintptr, pFunc uintptr) {
	var aUp [8]struct {
		FzFunc    uintptr
		FeFrmType int32
		FeStart   int32
		FeEnd     int32
	}
	var db, p, v2 uintptr
	var i int32
	_, _, _, _, _ = aUp, db, i, p, v2
	if (*TWindow)(unsafe.Pointer(pWin)).FzName != 0 && libc.Int32FromUint8((*TWindow)(unsafe.Pointer(pWin)).FeFrmType) == 0 {
		p = _windowFind(tls, pParse, pList, (*TWindow)(unsafe.Pointer(pWin)).FzName)
		if p == uintptr(0) {
			return
		}
		(*TWindow)(unsafe.Pointer(pWin)).FpPartition = _sqlite3ExprListDup(tls, (*TParse)(unsafe.Pointer(pParse)).Fdb, (*TWindow)(unsafe.Pointer(p)).FpPartition, 0)
		(*TWindow)(unsafe.Pointer(pWin)).FpOrderBy = _sqlite3ExprListDup(tls, (*TParse)(unsafe.Pointer(pParse)).Fdb, (*TWindow)(unsafe.Pointer(p)).FpOrderBy, 0)
		(*TWindow)(unsafe.Pointer(pWin)).FpStart = _sqlite3ExprDup(tls, (*TParse)(unsafe.Pointer(pParse)).Fdb, (*TWindow)(unsafe.Pointer(p)).FpStart, 0)
		(*TWindow)(unsafe.Pointer(pWin)).FpEnd = _sqlite3ExprDup(tls, (*TParse)(unsafe.Pointer(pParse)).Fdb, (*TWindow)(unsafe.Pointer(p)).FpEnd, 0)
		(*TWindow)(unsafe.Pointer(pWin)).FeStart = (*TWindow)(unsafe.Pointer(p)).FeStart
		(*TWindow)(unsafe.Pointer(pWin)).FeEnd = (*TWindow)(unsafe.Pointer(p)).FeEnd
		(*TWindow)(unsafe.Pointer(pWin)).FeFrmType = (*TWindow)(unsafe.Pointer(p)).FeFrmType
		(*TWindow)(unsafe.Pointer(pWin)).FeExclude = (*TWindow)(unsafe.Pointer(p)).FeExclude
	} else {
		_sqlite3WindowChain(tls, pParse, pWin, pList)
	}
	if libc.Int32FromUint8((*TWindow)(unsafe.Pointer(pWin)).FeFrmType) == int32(TK_RANGE) && ((*TWindow)(unsafe.Pointer(pWin)).FpStart != 0 || (*TWindow)(unsafe.Pointer(pWin)).FpEnd != 0) && ((*TWindow)(unsafe.Pointer(pWin)).FpOrderBy == uintptr(0) || (*TExprList)(unsafe.Pointer((*TWindow)(unsafe.Pointer(pWin)).FpOrderBy)).FnExpr != int32(1)) {
		_sqlite3ErrorMsg(tls, pParse, __ccgo_ts+24288, 0)
	} else {
		if (*TFuncDef)(unsafe.Pointer(pFunc)).FfuncFlags&uint32(SQLITE_FUNC_WINDOW) != 0 {
			db = (*TParse)(unsafe.Pointer(pParse)).Fdb
			if (*TWindow)(unsafe.Pointer(pWin)).FpFilter != 0 {
				_sqlite3ErrorMsg(tls, pParse, __ccgo_ts+24359, 0)
			} else {
				aUp = [8]struct {
					FzFunc    uintptr
					FeFrmType int32
					FeStart   int32
					FeEnd     int32
				}{
					0: {
						FzFunc:    uintptr(unsafe.Pointer(&_row_numberName)),
						FeFrmType: int32(TK_ROWS),
						FeStart:   int32(TK_UNBOUNDED),
						FeEnd:     int32(TK_CURRENT),
					},
					1: {
						FzFunc:    uintptr(unsafe.Pointer(&_dense_rankName)),
						FeFrmType: int32(TK_RANGE),
						FeStart:   int32(TK_UNBOUNDED),
						FeEnd:     int32(TK_CURRENT),
					},
					2: {
						FzFunc:    uintptr(unsafe.Pointer(&_rankName)),
						FeFrmType: int32(TK_RANGE),
						FeStart:   int32(TK_UNBOUNDED),
						FeEnd:     int32(TK_CURRENT),
					},
					3: {
						FzFunc:    uintptr(unsafe.Pointer(&_percent_rankName)),
						FeFrmType: int32(TK_GROUPS),
						FeStart:   int32(TK_CURRENT),
						FeEnd:     int32(TK_UNBOUNDED),
					},
					4: {
						FzFunc:    uintptr(unsafe.Pointer(&_cume_distName)),
						FeFrmType: int32(TK_GROUPS),
						FeStart:   int32(TK_FOLLOWING),
						FeEnd:     int32(TK_UNBOUNDED),
					},
					5: {
						FzFunc:    uintptr(unsafe.Pointer(&_ntileName)),
						FeFrmType: int32(TK_ROWS),
						FeStart:   int32(TK_CURRENT),
						FeEnd:     int32(TK_UNBOUNDED),
					},
					6: {
						FzFunc:    uintptr(unsafe.Pointer(&_leadName)),
						FeFrmType: int32(TK_ROWS),
						FeStart:   int32(TK_UNBOUNDED),
						FeEnd:     int32(TK_UNBOUNDED),
					},
					7: {
						FzFunc:    uintptr(unsafe.Pointer(&_lagName)),
						FeFrmType: int32(TK_ROWS),
						FeStart:   int32(TK_UNBOUNDED),
						FeEnd:     int32(TK_CURRENT),
					},
				}
				i = 0
				for {
					if !(i < libc.Int32FromUint64(libc.Uint64FromInt64(192)/libc.Uint64FromInt64(24))) {
						break
					}
					if (*TFuncDef)(unsafe.Pointer(pFunc)).FzName == aUp[i].FzFunc {
						_sqlite3ExprDelete(tls, db, (*TWindow)(unsafe.Pointer(pWin)).FpStart)
						_sqlite3ExprDelete(tls, db, (*TWindow)(unsafe.Pointer(pWin)).FpEnd)
						v2 = libc.UintptrFromInt32(0)
						(*TWindow)(unsafe.Pointer(pWin)).FpStart = v2
						(*TWindow)(unsafe.Pointer(pWin)).FpEnd = v2
						(*TWindow)(unsafe.Pointer(pWin)).FeFrmType = libc.Uint8FromInt32(aUp[i].FeFrmType)
						(*TWindow)(unsafe.Pointer(pWin)).FeStart = libc.Uint8FromInt32(aUp[i].FeStart)
						(*TWindow)(unsafe.Pointer(pWin)).FeEnd = libc.Uint8FromInt32(aUp[i].FeEnd)
						(*TWindow)(unsafe.Pointer(pWin)).FeExclude = uint8(0)
						if libc.Int32FromUint8((*TWindow)(unsafe.Pointer(pWin)).FeStart) == int32(TK_FOLLOWING) {
							(*TWindow)(unsafe.Pointer(pWin)).FpStart = _sqlite3ExprInt32(tls, db, int32(1))
						}
						break
					}
					goto _1
				_1:
					;
					i = i + 1
				}
			}
		}
	}
	(*TWindow)(unsafe.Pointer(pWin)).FpWFunc = pFunc
}

// C documentation
//
//	/*
//	** This routine is invoked once per CTE by the parser while parsing a
//	** WITH clause.  The CTE described by the third argument is added to
//	** the WITH clause of the second argument.  If the second argument is
//	** NULL, then a new WITH argument is created.
//	*/
func _sqlite3WithAdd(tls *libc.TLS, pParse uintptr, pWith uintptr, pCte uintptr) (r uintptr) {
	bp := tls.Alloc(16)
	defer tls.Free(16)
	var db, pNew, zName, v3 uintptr
	var i, v2 int32
	_, _, _, _, _, _ = db, i, pNew, zName, v2, v3
	db = (*TParse)(unsafe.Pointer(pParse)).Fdb
	if pCte == uintptr(0) {
		return pWith
	}
	/* Check that the CTE name is unique within this WITH clause. If
	 ** not, store an error in the Parse structure. */
	zName = (*TCte)(unsafe.Pointer(pCte)).FzName
	if zName != 0 && pWith != 0 {
		i = 0
		for {
			if !(i < (*TWith)(unsafe.Pointer(pWith)).FnCte) {
				break
			}
			if _sqlite3StrICmp(tls, zName, (*(*TCte)(unsafe.Pointer(pWith + 16 + uintptr(i)*48))).FzName) == 0 {
				_sqlite3ErrorMsg(tls, pParse, __ccgo_ts+16277, libc.VaList(bp+8, zName))
			}
			goto _1
		_1:
			;
			i = i + 1
		}
	}
	if pWith != 0 {
		pNew = _sqlite3DbRealloc(tls, db, pWith, uint64(uint64(libc.UintptrFromInt32(0)+16)+libc.Uint64FromInt32((*TWith)(unsafe.Pointer(pWith)).FnCte+libc.Int32FromInt32(1))*libc.Uint64FromInt64(48)))
	} else {
		pNew = _sqlite3DbMallocZero(tls, db, uint64(uint64(libc.UintptrFromInt32(0)+16)+libc.Uint64FromInt32(libc.Int32FromInt32(1))*libc.Uint64FromInt64(48)))
	}
	if (*Tsqlite3)(unsafe.Pointer(db)).FmallocFailed != 0 {
		_sqlite3CteDelete(tls, db, pCte)
		pNew = pWith
	} else {
		v3 = pNew
		v2 = *(*int32)(unsafe.Pointer(v3))
		*(*int32)(unsafe.Pointer(v3)) = *(*int32)(unsafe.Pointer(v3)) + 1
		*(*TCte)(unsafe.Pointer(pNew + 16 + uintptr(v2)*48)) = **(**TCte)(__ccgo_up(pCte))
		_sqlite3DbFree(tls, db, pCte)
	}
	return pNew
}

func _sqlite3_geopoly_init(tls *libc.TLS, db uintptr) (r int32) {
	var enc, rc int32
	var i uint32
	_, _, _ = enc, i, rc
	rc = SQLITE_OK
	i = uint32(0)
	for {
		if !(uint64(i) < libc.Uint64FromInt64(288)/libc.Uint64FromInt64(24) && rc == SQLITE_OK) {
			break
		}
		if _aFunc[i].FbPure != 0 {
			enc = libc.Int32FromInt32(SQLITE_UTF8) | libc.Int32FromInt32(SQLITE_DETERMINISTIC) | libc.Int32FromInt32(SQLITE_INNOCUOUS)
		} else {
			enc = libc.Int32FromInt32(SQLITE_UTF8) | libc.Int32FromInt32(SQLITE_DIRECTONLY)
		}
		rc = Xsqlite3_create_function(tls, db, _aFunc[i].FzName, int32(_aFunc[i].FnArg), enc, uintptr(0), _aFunc[i].FxFunc, uintptr(0), uintptr(0))
		goto _1
	_1:
		;
		i = i + 1
	}
	i = uint32(0)
	for {
		if !(uint64(i) < libc.Uint64FromInt64(24)/libc.Uint64FromInt64(24) && rc == SQLITE_OK) {
			break
		}
		rc = Xsqlite3_create_function(tls, db, _aAgg[i].FzName, int32(1), libc.Int32FromInt32(SQLITE_UTF8)|libc.Int32FromInt32(SQLITE_DETERMINISTIC)|libc.Int32FromInt32(SQLITE_INNOCUOUS), uintptr(0), uintptr(0), _aAgg[i].FxStep, _aAgg[i].FxFinal)
		goto _2
	_2:
		;
		i = i + 1
	}
	if rc == SQLITE_OK {
		rc = Xsqlite3_create_module_v2(tls, db, __ccgo_ts+30210, uintptr(unsafe.Pointer(&_geopolyModule)), uintptr(0), uintptr(0))
	}
	return rc
}

// C documentation
//
//	/*
//	** This routine is called once for each row in the result table.  Its job
//	** is to fill in the TabResult structure appropriately, allocating new
//	** memory as necessary.
//	*/
func _sqlite3_get_table_cb(tls *libc.TLS, pArg uintptr, nCol int32, argv uintptr, colv uintptr) (r int32) {
	bp := tls.Alloc(16)
	defer tls.Free(16)
	var azNew, p, z, v3 uintptr
	var i, n, need int32
	var v2 Tu32
	_, _, _, _, _, _, _, _ = azNew, i, n, need, p, z, v2, v3
	p = pArg /* A single column of result */
	/* Make sure there is enough space in p->azResult to hold everything
	 ** we need to remember from this invocation of the callback.
	 */
	if (*TTabResult)(unsafe.Pointer(p)).FnRow == uint32(0) && argv != uintptr(0) {
		need = nCol * int32(2)
	} else {
		need = nCol
	}
	if (*TTabResult)(unsafe.Pointer(p)).FnData+libc.Uint32FromInt32(need) > (*TTabResult)(unsafe.Pointer(p)).FnAlloc {
		(*TTabResult)(unsafe.Pointer(p)).FnAlloc = (*TTabResult)(unsafe.Pointer(p)).FnAlloc*uint32(2) + libc.Uint32FromInt32(need)
		azNew = _sqlite3Realloc(tls, (*TTabResult)(unsafe.Pointer(p)).FazResult, uint64(8)*uint64((*TTabResult)(unsafe.Pointer(p)).FnAlloc))
		if azNew == uintptr(0) {
			goto malloc_failed
		}
		(*TTabResult)(unsafe.Pointer(p)).FazResult = azNew
	}
	/* If this is the first row, then generate an extra row containing
	 ** the names of all columns.
	 */
	if (*TTabResult)(unsafe.Pointer(p)).FnRow == uint32(0) {
		(*TTabResult)(unsafe.Pointer(p)).FnColumn = libc.Uint32FromInt32(nCol)
		i = 0
		for {
			if !(i < nCol) {
				break
			}
			z = Xsqlite3_mprintf(tls, __ccgo_ts+3933, libc.VaList(bp+8, **(**uintptr)(__ccgo_up(colv + uintptr(i)*8))))
			if z == uintptr(0) {
				goto malloc_failed
			}
			v3 = p + 28
			v2 = *(*Tu32)(unsafe.Pointer(v3))
			*(*Tu32)(unsafe.Pointer(v3)) = *(*Tu32)(unsafe.Pointer(v3)) + 1
			**(**uintptr)(__ccgo_up((*TTabResult)(unsafe.Pointer(p)).FazResult + uintptr(v2)*8)) = z
			goto _1
		_1:
			;
			i = i + 1
		}
	} else {
		if libc.Int32FromUint32((*TTabResult)(unsafe.Pointer(p)).FnColumn) != nCol {
			Xsqlite3_free(tls, (*TTabResult)(unsafe.Pointer(p)).FzErrMsg)
			(*TTabResult)(unsafe.Pointer(p)).FzErrMsg = Xsqlite3_mprintf(tls, __ccgo_ts+21764, 0)
			(*TTabResult)(unsafe.Pointer(p)).Frc = int32(SQLITE_ERROR)
			return int32(1)
		}
	}
	/* Copy over the row data
	 */
	if argv != uintptr(0) {
		i = 0
		for {
			if !(i < nCol) {
				break
			}
			if **(**uintptr)(__ccgo_up(argv + uintptr(i)*8)) == uintptr(0) {
				z = uintptr(0)
			} else {
				n = _sqlite3Strlen30(tls, **(**uintptr)(__ccgo_up(argv + uintptr(i)*8))) + int32(1)
				z = Xsqlite3_malloc64(tls, libc.Uint64FromInt32(n))
				if z == uintptr(0) {
					goto malloc_failed
				}
				libc.Xmemcpy(tls, z, **(**uintptr)(__ccgo_up(argv + uintptr(i)*8)), libc.Uint64FromInt32(n))
			}
			v3 = p + 28
			v2 = *(*Tu32)(unsafe.Pointer(v3))
			*(*Tu32)(unsafe.Pointer(v3)) = *(*Tu32)(unsafe.Pointer(v3)) + 1
			**(**uintptr)(__ccgo_up((*TTabResult)(unsafe.Pointer(p)).FazResult + uintptr(v2)*8)) = z
			goto _4
		_4:
			;
			i = i + 1
		}
		(*TTabResult)(unsafe.Pointer(p)).FnRow = (*TTabResult)(unsafe.Pointer(p)).FnRow + 1
	}
	return 0
	goto malloc_failed
malloc_failed:
	;
	(*TTabResult)(unsafe.Pointer(p)).Frc = int32(SQLITE_NOMEM)
	return int32(1)
}

// C documentation
//
//	/*
//	** An array of names of all compile-time options.  This array should
//	** be sorted A-Z.
//	**
//	** This array looks large, but in a typical installation actually uses
//	** only a handful of compile-time options, so most times this array is usually
//	** rather short and uses little memory space.
//	*/
var _sqlite3azCompileOpt = [56]uintptr{
	0:  __ccgo_ts,
	1:  __ccgo_ts + 20,
	2:  __ccgo_ts + 42,
	3:  __ccgo_ts + 61,
	4:  __ccgo_ts + 86,
	5:  __ccgo_ts + 108,
	6:  __ccgo_ts + 138,
	7:  __ccgo_ts + 158,
	8:  __ccgo_ts + 178,
	9:  __ccgo_ts + 201,
	10: __ccgo_ts + 226,
	11: __ccgo_ts + 253,
	12: __ccgo_ts + 278,
	13: __ccgo_ts + 300,
	14: __ccgo_ts + 332,
	15: __ccgo_ts + 358,
	16: __ccgo_ts + 383,
	17: __ccgo_ts + 404,
	18: __ccgo_ts + 422,
	19: __ccgo_ts + 445,
	20: __ccgo_ts + 464,
	21: __ccgo_ts + 483,
	22: __ccgo_ts + 495,
	23: __ccgo_ts + 510,
	24: __ccgo_ts + 532,
	25: __ccgo_ts + 557,
	26: __ccgo_ts + 580,
	27: __ccgo_ts + 602,
	28: __ccgo_ts + 613,
	29: __ccgo_ts + 626,
	30: __ccgo_ts + 641,
	31: __ccgo_ts + 657,
	32: __ccgo_ts + 670,
	33: __ccgo_ts + 691,
	34: __ccgo_ts + 715,
	35: __ccgo_ts + 738,
	36: __ccgo_ts + 754,
	37: __ccgo_ts + 770,
	38: __ccgo_ts + 794,
	39: __ccgo_ts + 821,
	40: __ccgo_ts + 841,
	41: __ccgo_ts + 863,
	42: __ccgo_ts + 885,
	43: __ccgo_ts + 915,
	44: __ccgo_ts + 931,
	45: __ccgo_ts + 957,
	46: __ccgo_ts + 977,
	47: __ccgo_ts + 1003,
	48: __ccgo_ts + 1026,
	49: __ccgo_ts + 1052,
	50: __ccgo_ts + 1074,
	51: __ccgo_ts + 1095,
	52: __ccgo_ts + 1106,
	53: __ccgo_ts + 1114,
	54: __ccgo_ts + 1128,
	55: __ccgo_ts + 1141,
}

// C documentation
//
//	/*
//	** Write an error message into pParse->zErrMsg that explains that the
//	** user-supplied authorization function returned an illegal value.
//	*/
func _sqliteAuthBadReturnCode(tls *libc.TLS, pParse uintptr) {
	_sqlite3ErrorMsg(tls, pParse, __ccgo_ts+13602, 0)
	(*TParse)(unsafe.Pointer(pParse)).Frc = int32(SQLITE_ERROR)
}

// C documentation
//
//	/*
//	** Connect to or create a new DBSTAT virtual table.
//	*/
func _statConnect(tls *libc.TLS, db uintptr, pAux uintptr, argc int32, argv uintptr, ppVtab uintptr, pzErr uintptr) (r int32) {
	bp := tls.Alloc(32)
	defer tls.Free(32)
	var iDb, rc int32
	var pTab uintptr
	var _ /* nm at bp+0 */ TToken
	_, _, _ = iDb, pTab, rc
	pTab = uintptr(0)
	rc = SQLITE_OK
	_ = pAux
	if argc >= int32(4) {
		_sqlite3TokenInit(tls, bp, **(**uintptr)(__ccgo_up(argv + 3*8)))
		iDb = _sqlite3FindDb(tls, db, bp)
		if iDb < 0 {
			**(**uintptr)(__ccgo_up(pzErr)) = Xsqlite3_mprintf(tls, __ccgo_ts+13435, libc.VaList(bp+24, **(**uintptr)(__ccgo_up(argv + 3*8))))
			return int32(SQLITE_ERROR)
		}
	} else {
		iDb = 0
	}
	Xsqlite3_vtab_config(tls, db, int32(SQLITE_VTAB_DIRECTONLY), 0)
	rc = Xsqlite3_declare_vtab(tls, db, uintptr(unsafe.Pointer(&_zDbstatSchema)))
	if rc == SQLITE_OK {
		pTab = Xsqlite3_malloc64(tls, uint64(40))
		if pTab == uintptr(0) {
			rc = int32(SQLITE_NOMEM)
		}
	}
	if rc == SQLITE_OK {
		libc.Xmemset(tls, pTab, 0, uint64(40))
		(*TStatTable)(unsafe.Pointer(pTab)).Fdb = db
		(*TStatTable)(unsafe.Pointer(pTab)).FiDb = iDb
	}
	**(**uintptr)(__ccgo_up(ppVtab)) = pTab
	return rc
}

// C documentation
//
//	/* Initialize a cursor according to the query plan idxNum using the
//	** arguments in argv[0].  See statBestIndex() for a description of the
//	** meaning of the bits in idxNum.
//	*/
func _statFilter(tls *libc.TLS, pCursor uintptr, idxNum int32, idxStr uintptr, argc int32, argv uintptr) (r int32) {
	bp := tls.Alloc(16)
	defer tls.Free(16)
	var iArg, rc, v1 int32
	var pCsr, pSql, pTab, zDbase, zName, zSql uintptr
	_, _, _, _, _, _, _, _, _ = iArg, pCsr, pSql, pTab, rc, zDbase, zName, zSql, v1
	pCsr = pCursor
	pTab = (*Tsqlite3_vtab_cursor)(unsafe.Pointer(pCursor)).FpVtab /* String value of pSql */
	iArg = 0                                                       /* Count of argv[] parameters used so far */
	rc = SQLITE_OK                                                 /* Result of this operation */
	zName = uintptr(0)                                             /* Only provide analysis of this table */
	_ = argc
	_ = idxStr
	_statResetCsr(tls, pCsr)
	Xsqlite3_finalize(tls, (*TStatCursor)(unsafe.Pointer(pCsr)).FpStmt)
	(*TStatCursor)(unsafe.Pointer(pCsr)).FpStmt = uintptr(0)
	if idxNum&int32(0x01) != 0 {
		v1 = iArg
		iArg = iArg + 1
		/* schema=? constraint is present.  Get its value */
		zDbase = Xsqlite3_value_text(tls, **(**uintptr)(__ccgo_up(argv + uintptr(v1)*8)))
		(*TStatCursor)(unsafe.Pointer(pCsr)).FiDb = _sqlite3FindDbName(tls, (*TStatTable)(unsafe.Pointer(pTab)).Fdb, zDbase)
		if (*TStatCursor)(unsafe.Pointer(pCsr)).FiDb < 0 {
			(*TStatCursor)(unsafe.Pointer(pCsr)).FiDb = 0
			(*TStatCursor)(unsafe.Pointer(pCsr)).FisEof = uint8(1)
			return SQLITE_OK
		}
	} else {
		(*TStatCursor)(unsafe.Pointer(pCsr)).FiDb = (*TStatTable)(unsafe.Pointer(pTab)).FiDb
	}
	if idxNum&int32(0x02) != 0 {
		/* name=? constraint is present */
		v1 = iArg
		iArg = iArg + 1
		zName = Xsqlite3_value_text(tls, **(**uintptr)(__ccgo_up(argv + uintptr(v1)*8)))
	}
	if idxNum&int32(0x04) != 0 {
		/* aggregate=? constraint is present */
		v1 = iArg
		iArg = iArg + 1
		(*TStatCursor)(unsafe.Pointer(pCsr)).FisAgg = libc.BoolUint8(Xsqlite3_value_double(tls, **(**uintptr)(__ccgo_up(argv + uintptr(v1)*8))) != float64(0))
	} else {
		(*TStatCursor)(unsafe.Pointer(pCsr)).FisAgg = uint8(0)
	}
	pSql = Xsqlite3_str_new(tls, (*TStatTable)(unsafe.Pointer(pTab)).Fdb)
	Xsqlite3_str_appendf(tls, pSql, __ccgo_ts+34800, libc.VaList(bp+8, (**(**TDb)(__ccgo_up((*Tsqlite3)(unsafe.Pointer((*TStatTable)(unsafe.Pointer(pTab)).Fdb)).FaDb + uintptr((*TStatCursor)(unsafe.Pointer(pCsr)).FiDb)*32))).FzDbSName))
	if zName != 0 {
		Xsqlite3_str_appendf(tls, pSql, __ccgo_ts+34955, libc.VaList(bp+8, zName))
	}
	if idxNum&int32(0x08) != 0 {
		Xsqlite3_str_appendf(tls, pSql, __ccgo_ts+34969, 0)
	}
	zSql = Xsqlite3_str_finish(tls, pSql)
	if zSql == uintptr(0) {
		return int32(SQLITE_NOMEM)
	} else {
		rc = Xsqlite3_prepare_v2(tls, (*TStatTable)(unsafe.Pointer(pTab)).Fdb, zSql, -int32(1), pCsr+8, uintptr(0))
		Xsqlite3_free(tls, zSql)
	}
	if rc == SQLITE_OK {
		(*TStatCursor)(unsafe.Pointer(pCsr)).FiPage = -int32(1)
		rc = _statNext(tls, pCursor)
	}
	return rc
}

// C documentation
//
//	/*
//	** Implementation of the stat_get(P,J) SQL function.  This routine is
//	** used to query statistical information that has been gathered into
//	** the StatAccum object by prior calls to stat_push().  The P parameter
//	** has type BLOB but it is really just a pointer to the StatAccum object.
//	** The content to returned is determined by the parameter J
//	** which is one of the STAT_GET_xxxx values defined above.
//	**
//	** The stat_get(P,J) function is not available to generic SQL.  It is
//	** inserted as part of a manually constructed bytecode program.  (See
//	** the callStatGet() routine below.)  It is guaranteed that the P
//	** parameter will always be a pointer to a StatAccum object, never a
//	** NULL.
//	**
//	** If STAT4 is not enabled, then J is always
//	** STAT_GET_STAT1 and is hence omitted and this routine becomes
//	** a one-parameter function, stat_get(P), that always returns the
//	** stat1 table entry information.
//	*/
func _statGet(tls *libc.TLS, context uintptr, argc int32, argv uintptr) {
	bp := tls.Alloc(80)
	defer tls.Free(80)
	var aCnt, p, pS uintptr
	var eCall, i, i1 int32
	var iVal, nDistinct Tu64
	var v1 uint64
	var _ /* sStat at bp+0 */ Tsqlite3_str
	var _ /* sStat at bp+32 */ Tsqlite3_str
	_, _, _, _, _, _, _, _, _ = aCnt, eCall, i, i1, iVal, nDistinct, p, pS, v1
	p = Xsqlite3_value_blob(tls, **(**uintptr)(__ccgo_up(argv)))
	/* STAT4 has a parameter on this routine. */
	eCall = Xsqlite3_value_int(tls, **(**uintptr)(__ccgo_up(argv + 1*8)))
	if eCall == STAT_GET_STAT1 {
		/* Loop counter */
		_sqlite3StrAccumInit(tls, bp, uintptr(0), uintptr(0), 0, ((*TStatAccum)(unsafe.Pointer(p)).FnKeyCol+int32(1))*int32(100))
		if (*TStatAccum)(unsafe.Pointer(p)).FnSkipAhead != 0 {
			v1 = (*TStatAccum)(unsafe.Pointer(p)).FnEst
		} else {
			v1 = (*TStatAccum)(unsafe.Pointer(p)).FnRow
		}
		Xsqlite3_str_appendf(tls, bp, __ccgo_ts+12997, libc.VaList(bp+72, v1))
		i = 0
		for {
			if !(i < (*TStatAccum)(unsafe.Pointer(p)).FnKeyCol) {
				break
			}
			nDistinct = **(**TtRowcnt)(__ccgo_up((*TStatAccum)(unsafe.Pointer(p)).Fcurrent.FanDLt + uintptr(i)*8)) + uint64(1)
			iVal = ((*TStatAccum)(unsafe.Pointer(p)).FnRow + nDistinct - uint64(1)) / nDistinct
			if iVal == uint64(2) && (*TStatAccum)(unsafe.Pointer(p)).FnRow*uint64(10) <= nDistinct*uint64(11) {
				iVal = uint64(1)
			}
			Xsqlite3_str_appendf(tls, bp, __ccgo_ts+13002, libc.VaList(bp+72, iVal))
			goto _2
		_2:
			;
			i = i + 1
		}
		_sqlite3ResultStrAccum(tls, context, bp)
	} else {
		if eCall == int32(STAT_GET_ROWID) {
			if (*TStatAccum)(unsafe.Pointer(p)).FiGet < 0 {
				_samplePushPrevious(tls, p, 0)
				(*TStatAccum)(unsafe.Pointer(p)).FiGet = 0
			}
			if (*TStatAccum)(unsafe.Pointer(p)).FiGet < (*TStatAccum)(unsafe.Pointer(p)).FnSample {
				pS = (*TStatAccum)(unsafe.Pointer(p)).Fa + uintptr((*TStatAccum)(unsafe.Pointer(p)).FiGet)*48
				if (*TStatSample)(unsafe.Pointer(pS)).FnRowid == uint32(0) {
					Xsqlite3_result_int64(tls, context, *(*Ti64)(unsafe.Pointer(pS + 24)))
				} else {
					Xsqlite3_result_blob(tls, context, *(*uintptr)(unsafe.Pointer(pS + 24)), libc.Int32FromUint32((*TStatSample)(unsafe.Pointer(pS)).FnRowid), uintptr(-libc.Int32FromInt32(1)))
				}
			}
		} else {
			aCnt = uintptr(0)
			switch eCall {
			case int32(STAT_GET_NEQ):
				aCnt = (**(**TStatSample)(__ccgo_up((*TStatAccum)(unsafe.Pointer(p)).Fa + uintptr((*TStatAccum)(unsafe.Pointer(p)).FiGet)*48))).FanEq
			case int32(STAT_GET_NLT):
				aCnt = (**(**TStatSample)(__ccgo_up((*TStatAccum)(unsafe.Pointer(p)).Fa + uintptr((*TStatAccum)(unsafe.Pointer(p)).FiGet)*48))).FanLt
			default:
				aCnt = (**(**TStatSample)(__ccgo_up((*TStatAccum)(unsafe.Pointer(p)).Fa + uintptr((*TStatAccum)(unsafe.Pointer(p)).FiGet)*48))).FanDLt
				(*TStatAccum)(unsafe.Pointer(p)).FiGet = (*TStatAccum)(unsafe.Pointer(p)).FiGet + 1
				break
			}
			_sqlite3StrAccumInit(tls, bp+32, uintptr(0), uintptr(0), 0, (*TStatAccum)(unsafe.Pointer(p)).FnCol*int32(100))
			i1 = 0
			for {
				if !(i1 < (*TStatAccum)(unsafe.Pointer(p)).FnCol) {
					break
				}
				Xsqlite3_str_appendf(tls, bp+32, __ccgo_ts+13008, libc.VaList(bp+72, **(**TtRowcnt)(__ccgo_up(aCnt + uintptr(i1)*8))))
				goto _3
			_3:
				;
				i1 = i1 + 1
			}
			if (**(**Tsqlite3_str)(__ccgo_up(bp + 32))).FnChar != 0 {
				(**(**Tsqlite3_str)(__ccgo_up(bp + 32))).FnChar = (**(**Tsqlite3_str)(__ccgo_up(bp + 32))).FnChar - 1
			}
			_sqlite3ResultStrAccum(tls, context, bp+32)
		}
	}
	_ = argc
}

var _statGetFuncdef = TFuncDef{
	FnArg:      int16(libc.Int32FromInt32(1) + libc.Int32FromInt32(IsStat4)),
	FfuncFlags: uint32(SQLITE_UTF8),
	FzName:     __ccgo_ts + 13014,
}

var _statInitFuncdef = TFuncDef{
	FnArg:      int16(4),
	FfuncFlags: uint32(SQLITE_UTF8),
	FzName:     __ccgo_ts + 12977,
}

// C documentation
//
//	/*
//	** Move a DBSTAT cursor to the next entry.  Normally, the next
//	** entry will be the next page, but in aggregated mode (pCsr->isAgg!=0),
//	** the next entry is the next btree.
//	*/
func _statNext(tls *libc.TLS, pCursor uintptr) (r int32) {
	bp := tls.Alloc(48)
	defer tls.Free(48)
	var i, iOvfl, nPayload, nUsable, rc, v3 int32
	var iRoot Tu32
	var p, p1, pBt, pCell, pCsr, pPager, pTab, z, v1 uintptr
	var _ /* nPage at bp+0 */ int32
	_, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _ = i, iOvfl, iRoot, nPayload, nUsable, p, p1, pBt, pCell, pCsr, pPager, pTab, rc, z, v1, v3
	pCsr = pCursor
	pTab = (*Tsqlite3_vtab_cursor)(unsafe.Pointer(pCursor)).FpVtab
	pBt = (**(**TDb)(__ccgo_up((*Tsqlite3)(unsafe.Pointer((*TStatTable)(unsafe.Pointer(pTab)).Fdb)).FaDb + uintptr((*TStatCursor)(unsafe.Pointer(pCsr)).FiDb)*32))).FpBt
	pPager = _sqlite3BtreePager(tls, pBt)
	Xsqlite3_free(tls, (*TStatCursor)(unsafe.Pointer(pCsr)).FzPath)
	(*TStatCursor)(unsafe.Pointer(pCsr)).FzPath = uintptr(0)
	goto statNextRestart
statNextRestart:
	;
	if (*TStatCursor)(unsafe.Pointer(pCsr)).FiPage < 0 {
		/* Start measuring space on the next btree */
		_statResetCounts(tls, pCsr)
		rc = Xsqlite3_step(tls, (*TStatCursor)(unsafe.Pointer(pCsr)).FpStmt)
		if rc == int32(SQLITE_ROW) {
			iRoot = libc.Uint32FromInt64(Xsqlite3_column_int64(tls, (*TStatCursor)(unsafe.Pointer(pCsr)).FpStmt, int32(1)))
			_sqlite3PagerPagecount(tls, pPager, bp)
			if **(**int32)(__ccgo_up(bp)) == 0 {
				(*TStatCursor)(unsafe.Pointer(pCsr)).FisEof = uint8(1)
				return Xsqlite3_reset(tls, (*TStatCursor)(unsafe.Pointer(pCsr)).FpStmt)
			}
			rc = _statGetPage(tls, pBt, iRoot, pCsr+24)
			(**(**TStatPage)(__ccgo_up(pCsr + 24))).FiPgno = iRoot
			(**(**TStatPage)(__ccgo_up(pCsr + 24))).FiCell = 0
			if !((*TStatCursor)(unsafe.Pointer(pCsr)).FisAgg != 0) {
				v1 = Xsqlite3_mprintf(tls, __ccgo_ts+34745, 0)
				z = v1
				(**(**TStatPage)(__ccgo_up(pCsr + 24))).FzPath = v1
				if z == uintptr(0) {
					rc = int32(SQLITE_NOMEM)
				}
			}
			(*TStatCursor)(unsafe.Pointer(pCsr)).FiPage = 0
			(*TStatCursor)(unsafe.Pointer(pCsr)).FnPage = int32(1)
		} else {
			(*TStatCursor)(unsafe.Pointer(pCsr)).FisEof = uint8(1)
			return Xsqlite3_reset(tls, (*TStatCursor)(unsafe.Pointer(pCsr)).FpStmt)
		}
	} else {
		/* Continue analyzing the btree previously started */
		p = pCsr + 24 + uintptr((*TStatCursor)(unsafe.Pointer(pCsr)).FiPage)*64
		if !((*TStatCursor)(unsafe.Pointer(pCsr)).FisAgg != 0) {
			_statResetCounts(tls, pCsr)
		}
		for (*TStatPage)(unsafe.Pointer(p)).FiCell < (*TStatPage)(unsafe.Pointer(p)).FnCell {
			pCell = (*TStatPage)(unsafe.Pointer(p)).FaCell + uintptr((*TStatPage)(unsafe.Pointer(p)).FiCell)*32
			for (*TStatCell)(unsafe.Pointer(pCell)).FiOvfl < (*TStatCell)(unsafe.Pointer(pCell)).FnOvfl {
				_sqlite3BtreeEnter(tls, pBt)
				nUsable = _sqlite3BtreeGetPageSize(tls, pBt) - _sqlite3BtreeGetReserveNoMutex(tls, pBt)
				_sqlite3BtreeLeave(tls, pBt)
				(*TStatCursor)(unsafe.Pointer(pCsr)).FnPage = (*TStatCursor)(unsafe.Pointer(pCsr)).FnPage + 1
				_statSizeAndOffset(tls, pCsr)
				if (*TStatCell)(unsafe.Pointer(pCell)).FiOvfl < (*TStatCell)(unsafe.Pointer(pCell)).FnOvfl-int32(1) {
					**(**Ti64)(__ccgo_up(pCsr + 2128)) += int64(nUsable - int32(4))
				} else {
					**(**Ti64)(__ccgo_up(pCsr + 2128)) += int64((*TStatCell)(unsafe.Pointer(pCell)).FnLastOvfl)
					**(**Ti64)(__ccgo_up(pCsr + 2120)) += int64(nUsable - int32(4) - (*TStatCell)(unsafe.Pointer(pCell)).FnLastOvfl)
				}
				iOvfl = (*TStatCell)(unsafe.Pointer(pCell)).FiOvfl
				(*TStatCell)(unsafe.Pointer(pCell)).FiOvfl = (*TStatCell)(unsafe.Pointer(pCell)).FiOvfl + 1
				if !((*TStatCursor)(unsafe.Pointer(pCsr)).FisAgg != 0) {
					(*TStatCursor)(unsafe.Pointer(pCsr)).FzName = Xsqlite3_column_text(tls, (*TStatCursor)(unsafe.Pointer(pCsr)).FpStmt, 0)
					(*TStatCursor)(unsafe.Pointer(pCsr)).FiPageno = **(**Tu32)(__ccgo_up((*TStatCell)(unsafe.Pointer(pCell)).FaOvfl + uintptr(iOvfl)*4))
					(*TStatCursor)(unsafe.Pointer(pCsr)).FzPagetype = __ccgo_ts + 34747
					v1 = Xsqlite3_mprintf(tls, __ccgo_ts+34756, libc.VaList(bp+16, (*TStatPage)(unsafe.Pointer(p)).FzPath, (*TStatPage)(unsafe.Pointer(p)).FiCell, iOvfl))
					z = v1
					(*TStatCursor)(unsafe.Pointer(pCsr)).FzPath = v1
					if z == uintptr(0) {
						v3 = int32(SQLITE_NOMEM)
					} else {
						v3 = SQLITE_OK
					}
					return v3
				}
			}
			if (*TStatPage)(unsafe.Pointer(p)).FiRightChildPg != 0 {
				break
			}
			(*TStatPage)(unsafe.Pointer(p)).FiCell = (*TStatPage)(unsafe.Pointer(p)).FiCell + 1
		}
		if !((*TStatPage)(unsafe.Pointer(p)).FiRightChildPg != 0) || (*TStatPage)(unsafe.Pointer(p)).FiCell > (*TStatPage)(unsafe.Pointer(p)).FnCell {
			_statClearPage(tls, p)
			(*TStatCursor)(unsafe.Pointer(pCsr)).FiPage = (*TStatCursor)(unsafe.Pointer(pCsr)).FiPage - 1
			if (*TStatCursor)(unsafe.Pointer(pCsr)).FisAgg != 0 && (*TStatCursor)(unsafe.Pointer(pCsr)).FiPage < 0 {
				/* label-statNext-done:  When computing aggregate space usage over
				 ** an entire btree, this is the exit point from this function */
				return SQLITE_OK
			}
			goto statNextRestart /* Tail recursion */
		}
		(*TStatCursor)(unsafe.Pointer(pCsr)).FiPage = (*TStatCursor)(unsafe.Pointer(pCsr)).FiPage + 1
		if (*TStatCursor)(unsafe.Pointer(pCsr)).FiPage >= libc.Int32FromUint64(libc.Uint64FromInt64(2048)/libc.Uint64FromInt64(64)) {
			_statResetCsr(tls, pCsr)
			return _sqlite3CorruptError(tls, int32(232421))
		}
		if (*TStatPage)(unsafe.Pointer(p)).FiCell == (*TStatPage)(unsafe.Pointer(p)).FnCell {
			(**(**TStatPage)(__ccgo_up(p + 1*64))).FiPgno = (*TStatPage)(unsafe.Pointer(p)).FiRightChildPg
		} else {
			(**(**TStatPage)(__ccgo_up(p + 1*64))).FiPgno = (**(**TStatCell)(__ccgo_up((*TStatPage)(unsafe.Pointer(p)).FaCell + uintptr((*TStatPage)(unsafe.Pointer(p)).FiCell)*32))).FiChildPg
		}
		rc = _statGetPage(tls, pBt, (**(**TStatPage)(__ccgo_up(p + 1*64))).FiPgno, p+1*64)
		(*TStatCursor)(unsafe.Pointer(pCsr)).FnPage = (*TStatCursor)(unsafe.Pointer(pCsr)).FnPage + 1
		(**(**TStatPage)(__ccgo_up(p + 1*64))).FiCell = 0
		if !((*TStatCursor)(unsafe.Pointer(pCsr)).FisAgg != 0) {
			v1 = Xsqlite3_mprintf(tls, __ccgo_ts+34768, libc.VaList(bp+16, (*TStatPage)(unsafe.Pointer(p)).FzPath, (*TStatPage)(unsafe.Pointer(p)).FiCell))
			z = v1
			(**(**TStatPage)(__ccgo_up(p + 1*64))).FzPath = v1
			if z == uintptr(0) {
				rc = int32(SQLITE_NOMEM)
			}
		}
		(*TStatPage)(unsafe.Pointer(p)).FiCell = (*TStatPage)(unsafe.Pointer(p)).FiCell + 1
	}
	/* Populate the StatCursor fields with the values to be returned
	 ** by the xColumn() and xRowid() methods.
	 */
	if rc == SQLITE_OK {
		p1 = pCsr + 24 + uintptr((*TStatCursor)(unsafe.Pointer(pCsr)).FiPage)*64
		(*TStatCursor)(unsafe.Pointer(pCsr)).FzName = Xsqlite3_column_text(tls, (*TStatCursor)(unsafe.Pointer(pCsr)).FpStmt, 0)
		(*TStatCursor)(unsafe.Pointer(pCsr)).FiPageno = (*TStatPage)(unsafe.Pointer(p1)).FiPgno
		rc = _statDecodePage(tls, pBt, p1)
		if rc == SQLITE_OK {
			_statSizeAndOffset(tls, pCsr)
			switch libc.Int32FromUint8((*TStatPage)(unsafe.Pointer(p1)).Fflags) {
			case int32(0x05): /* table internal */
				fallthrough
			case int32(0x02): /* index internal */
				(*TStatCursor)(unsafe.Pointer(pCsr)).FzPagetype = __ccgo_ts + 34776
			case int32(0x0D): /* table leaf */
				fallthrough
			case int32(0x0A): /* index leaf */
				(*TStatCursor)(unsafe.Pointer(pCsr)).FzPagetype = __ccgo_ts + 34785
			default:
				(*TStatCursor)(unsafe.Pointer(pCsr)).FzPagetype = __ccgo_ts + 34790
				break
			}
			**(**int32)(__ccgo_up(pCsr + 2108)) += (*TStatPage)(unsafe.Pointer(p1)).FnCell
			**(**Ti64)(__ccgo_up(pCsr + 2120)) += int64((*TStatPage)(unsafe.Pointer(p1)).FnUnused)
			if (*TStatPage)(unsafe.Pointer(p1)).FnMxPayload > (*TStatCursor)(unsafe.Pointer(pCsr)).FnMxPayload {
				(*TStatCursor)(unsafe.Pointer(pCsr)).FnMxPayload = (*TStatPage)(unsafe.Pointer(p1)).FnMxPayload
			}
			if !((*TStatCursor)(unsafe.Pointer(pCsr)).FisAgg != 0) {
				v1 = Xsqlite3_mprintf(tls, __ccgo_ts+3933, libc.VaList(bp+16, (*TStatPage)(unsafe.Pointer(p1)).FzPath))
				z = v1
				(*TStatCursor)(unsafe.Pointer(pCsr)).FzPath = v1
				if z == uintptr(0) {
					rc = int32(SQLITE_NOMEM)
				}
			}
			nPayload = 0
			i = 0
			for {
				if !(i < (*TStatPage)(unsafe.Pointer(p1)).FnCell) {
					break
				}
				nPayload = nPayload + (**(**TStatCell)(__ccgo_up((*TStatPage)(unsafe.Pointer(p1)).FaCell + uintptr(i)*32))).FnLocal
				goto _6
			_6:
				;
				i = i + 1
			}
			**(**Ti64)(__ccgo_up(pCsr + 2128)) += int64(nPayload)
			/* If computing aggregate space usage by btree, continue with the
			 ** next page.  The loop will exit via the return at label-statNext-done
			 */
			if (*TStatCursor)(unsafe.Pointer(pCsr)).FisAgg != 0 {
				goto statNextRestart
			}
		}
	}
	return rc
}

var _statPushFuncdef = TFuncDef{
	FnArg:      int16(libc.Int32FromInt32(2) + libc.Int32FromInt32(IsStat4)),
	FfuncFlags: uint32(SQLITE_UTF8),
	FzName:     __ccgo_ts + 12987,
}

// C documentation
//
//	/*
//	** Scan through the expression pExpr.  Replace every reference to
//	** a column in table number iTable with a copy of the iColumn-th
//	** entry in pEList.  (But leave references to the ROWID column
//	** unchanged.)
//	**
//	** This routine is part of the flattening procedure.  A subquery
//	** whose result set is defined by pEList appears as entry in the
//	** FROM clause of a SELECT such that the VDBE cursor assigned to that
//	** FORM clause entry is iTable.  This routine makes the necessary
//	** changes to pExpr so that it refers directly to the source table
//	** of the subquery rather the result set of the subquery.
//	*/
func _substExpr(tls *libc.TLS, pSubst uintptr, pExpr uintptr) (r uintptr) {
	bp := tls.Alloc(80)
	defer tls.Free(80)
	var db, pColl, pCopy, pNat, pNew, pWin, v1 uintptr
	var iColumn int32
	var _ /* ifNullRow at bp+0 */ TExpr
	_, _, _, _, _, _, _, _ = db, iColumn, pColl, pCopy, pNat, pNew, pWin, v1
	if pExpr == uintptr(0) {
		return uintptr(0)
	}
	if (*TExpr)(unsafe.Pointer(pExpr)).Fflags&libc.Uint32FromInt32(libc.Int32FromInt32(EP_OuterON)|libc.Int32FromInt32(EP_InnerON)) != uint32(0) && *(*int32)(unsafe.Pointer(pExpr + 52)) == (*TSubstContext)(unsafe.Pointer(pSubst)).FiTable {
		*(*int32)(unsafe.Pointer(pExpr + 52)) = (*TSubstContext)(unsafe.Pointer(pSubst)).FiNewTable
	}
	if libc.Int32FromUint8((*TExpr)(unsafe.Pointer(pExpr)).Fop) == int32(TK_COLUMN) && (*TExpr)(unsafe.Pointer(pExpr)).FiTable == (*TSubstContext)(unsafe.Pointer(pSubst)).FiTable && !((*TExpr)(unsafe.Pointer(pExpr)).Fflags&libc.Uint32FromInt32(libc.Int32FromInt32(EP_FixedCol)) != libc.Uint32FromInt32(0)) {
		iColumn = int32((*TExpr)(unsafe.Pointer(pExpr)).FiColumn)
		pCopy = (*(*TExprList_item)(unsafe.Pointer((*TSubstContext)(unsafe.Pointer(pSubst)).FpEList + 8 + uintptr(iColumn)*32))).FpExpr
		if _sqlite3ExprIsVector(tls, pCopy) != 0 {
			_sqlite3VectorErrorMsg(tls, (*TSubstContext)(unsafe.Pointer(pSubst)).FpParse, pCopy)
		} else {
			db = (*TParse)(unsafe.Pointer((*TSubstContext)(unsafe.Pointer(pSubst)).FpParse)).Fdb
			if (*TSubstContext)(unsafe.Pointer(pSubst)).FisOuterJoin != 0 && (libc.Int32FromUint8((*TExpr)(unsafe.Pointer(pCopy)).Fop) != int32(TK_COLUMN) || (*TExpr)(unsafe.Pointer(pCopy)).FiTable != (*TSubstContext)(unsafe.Pointer(pSubst)).FiNewTable) {
				libc.Xmemset(tls, bp, 0, uint64(72))
				(**(**TExpr)(__ccgo_up(bp))).Fop = uint8(TK_IF_NULL_ROW)
				(**(**TExpr)(__ccgo_up(bp))).FpLeft = pCopy
				(**(**TExpr)(__ccgo_up(bp))).FiTable = (*TSubstContext)(unsafe.Pointer(pSubst)).FiNewTable
				(**(**TExpr)(__ccgo_up(bp))).FiColumn = int16(-int32(99))
				(**(**TExpr)(__ccgo_up(bp))).Fflags = uint32(EP_IfNullRow)
				pCopy = bp
			}
			pNew = _sqlite3ExprDup(tls, db, pCopy, 0)
			if (*Tsqlite3)(unsafe.Pointer(db)).FmallocFailed != 0 {
				_sqlite3ExprDelete(tls, db, pNew)
				return pExpr
			}
			if (*TSubstContext)(unsafe.Pointer(pSubst)).FisOuterJoin != 0 {
				**(**Tu32)(__ccgo_up(pNew + 4)) |= libc.Uint32FromInt32(libc.Int32FromInt32(EP_CanBeNull))
			}
			if libc.Int32FromUint8((*TExpr)(unsafe.Pointer(pNew)).Fop) == int32(TK_TRUEFALSE) {
				*(*int32)(unsafe.Pointer(&(*TExpr)(unsafe.Pointer(pNew)).Fu)) = _sqlite3ExprTruthValue(tls, pNew)
				(*TExpr)(unsafe.Pointer(pNew)).Fop = uint8(TK_INTEGER)
				**(**Tu32)(__ccgo_up(pNew + 4)) |= libc.Uint32FromInt32(libc.Int32FromInt32(EP_IntValue))
			}
			/* Ensure that the expression now has an implicit collation sequence,
			 ** just as it did when it was a column of a view or sub-query. */
			pNat = _sqlite3ExprCollSeq(tls, (*TSubstContext)(unsafe.Pointer(pSubst)).FpParse, pNew)
			pColl = _sqlite3ExprCollSeq(tls, (*TSubstContext)(unsafe.Pointer(pSubst)).FpParse, (*(*TExprList_item)(unsafe.Pointer((*TSubstContext)(unsafe.Pointer(pSubst)).FpCList + 8 + uintptr(iColumn)*32))).FpExpr)
			if pNat != pColl || libc.Int32FromUint8((*TExpr)(unsafe.Pointer(pNew)).Fop) != int32(TK_COLUMN) && libc.Int32FromUint8((*TExpr)(unsafe.Pointer(pNew)).Fop) != int32(TK_COLLATE) {
				if pColl != 0 {
					v1 = (*TCollSeq)(unsafe.Pointer(pColl)).FzName
				} else {
					v1 = __ccgo_ts + 5230
				}
				pNew = _sqlite3ExprAddCollateString(tls, (*TSubstContext)(unsafe.Pointer(pSubst)).FpParse, pNew, v1)
			}
			**(**Tu32)(__ccgo_up(pNew + 4)) &= ^libc.Uint32FromInt32(libc.Int32FromInt32(EP_Collate))
			if (*TExpr)(unsafe.Pointer(pExpr)).Fflags&libc.Uint32FromInt32(libc.Int32FromInt32(EP_OuterON)|libc.Int32FromInt32(EP_InnerON)) != uint32(0) {
				_sqlite3SetJoinExpr(tls, pNew, *(*int32)(unsafe.Pointer(pExpr + 52)), (*TExpr)(unsafe.Pointer(pExpr)).Fflags&libc.Uint32FromInt32(libc.Int32FromInt32(EP_OuterON)|libc.Int32FromInt32(EP_InnerON)))
			}
			_sqlite3ExprDelete(tls, db, pExpr)
			pExpr = pNew
		}
	} else {
		if libc.Int32FromUint8((*TExpr)(unsafe.Pointer(pExpr)).Fop) == int32(TK_IF_NULL_ROW) && (*TExpr)(unsafe.Pointer(pExpr)).FiTable == (*TSubstContext)(unsafe.Pointer(pSubst)).FiTable {
			(*TExpr)(unsafe.Pointer(pExpr)).FiTable = (*TSubstContext)(unsafe.Pointer(pSubst)).FiNewTable
		}
		if libc.Int32FromUint8((*TExpr)(unsafe.Pointer(pExpr)).Fop) == int32(TK_AGG_FUNCTION) && libc.Int32FromUint8((*TExpr)(unsafe.Pointer(pExpr)).Fop2) >= (*TSubstContext)(unsafe.Pointer(pSubst)).FnSelDepth {
			(*TExpr)(unsafe.Pointer(pExpr)).Fop2 = (*TExpr)(unsafe.Pointer(pExpr)).Fop2 - 1
		}
		(*TExpr)(unsafe.Pointer(pExpr)).FpLeft = _substExpr(tls, pSubst, (*TExpr)(unsafe.Pointer(pExpr)).FpLeft)
		(*TExpr)(unsafe.Pointer(pExpr)).FpRight = _substExpr(tls, pSubst, (*TExpr)(unsafe.Pointer(pExpr)).FpRight)
		if (*TExpr)(unsafe.Pointer(pExpr)).Fflags&uint32(EP_xIsSelect) != uint32(0) {
			_substSelect(tls, pSubst, *(*uintptr)(unsafe.Pointer(pExpr + 32)), int32(1))
		} else {
			_substExprList(tls, pSubst, *(*uintptr)(unsafe.Pointer(pExpr + 32)))
		}
		if (*TExpr)(unsafe.Pointer(pExpr)).Fflags&libc.Uint32FromInt32(libc.Int32FromInt32(EP_WinFunc)) != uint32(0) {
			pWin = *(*uintptr)(unsafe.Pointer(pExpr + 64))
			(*TWindow)(unsafe.Pointer(pWin)).FpFilter = _substExpr(tls, pSubst, (*TWindow)(unsafe.Pointer(pWin)).FpFilter)
			_substExprList(tls, pSubst, (*TWindow)(unsafe.Pointer(pWin)).FpPartition)
			_substExprList(tls, pSubst, (*TWindow)(unsafe.Pointer(pWin)).FpOrderBy)
		}
	}
	return pExpr
}

func _sumFinalize(tls *libc.TLS, context uintptr) {
	var p uintptr
	_ = p
	p = Xsqlite3_aggregate_context(tls, context, 0)
	if p != 0 && (*TSumCtx)(unsafe.Pointer(p)).Fcnt > 0 {
		if (*TSumCtx)(unsafe.Pointer(p)).Fapprox != 0 {
			if (*TSumCtx)(unsafe.Pointer(p)).Fovrfl != 0 {
				Xsqlite3_result_error(tls, context, __ccgo_ts+16451, -int32(1))
			} else {
				if !(_sqlite3IsOverflow(tls, (*TSumCtx)(unsafe.Pointer(p)).FrErr) != 0) {
					Xsqlite3_result_double(tls, context, (*TSumCtx)(unsafe.Pointer(p)).FrSum+(*TSumCtx)(unsafe.Pointer(p)).FrErr)
				} else {
					Xsqlite3_result_double(tls, context, (*TSumCtx)(unsafe.Pointer(p)).FrSum)
				}
			}
		} else {
			Xsqlite3_result_int64(tls, context, (*TSumCtx)(unsafe.Pointer(p)).FiSum)
		}
	}
}

// C documentation
//
//	/*
//	** Return true if it is not allowed to drop the given table
//	*/
func _tableMayNotBeDropped(tls *libc.TLS, db uintptr, pTab uintptr) (r int32) {
	if Xsqlite3_strnicmp(tls, (*TTable)(unsafe.Pointer(pTab)).FzName, __ccgo_ts+6749, int32(7)) == 0 {
		if Xsqlite3_strnicmp(tls, (*TTable)(unsafe.Pointer(pTab)).FzName+uintptr(7), __ccgo_ts+3556, int32(4)) == 0 {
			return 0
		}
		if Xsqlite3_strnicmp(tls, (*TTable)(unsafe.Pointer(pTab)).FzName+uintptr(7), __ccgo_ts+7551, int32(10)) == 0 {
			return 0
		}
		return int32(1)
	}
	if (*TTable)(unsafe.Pointer(pTab)).FtabFlags&uint32(TF_Shadow) != uint32(0) && _sqlite3ReadOnlyShadowTables(tls, db) != 0 {
		return int32(1)
	}
	if (*TTable)(unsafe.Pointer(pTab)).FtabFlags&uint32(TF_Eponymous) != 0 {
		return int32(1)
	}
	return 0
}

var _tkCoalesce = TToken{
	Fz: __ccgo_ts + 6954,
	Fn: uint32(8),
}

// C documentation
//
//	/*
//	** Allocate space to hold a new trigger step.  The allocated space
//	** holds both the TriggerStep object and the TriggerStep.target.z string.
//	**
//	** If an OOM error occurs, NULL is returned and db->mallocFailed is set.
//	*/
func _triggerStepAllocate(tls *libc.TLS, pParse uintptr, op Tu8, pTabList uintptr, zStart uintptr, zEnd uintptr) (r uintptr) {
	var db, pNew, pTriggerStep uintptr
	_, _, _ = db, pNew, pTriggerStep
	pNew = (*TParse)(unsafe.Pointer(pParse)).FpNewTrigger
	db = (*TParse)(unsafe.Pointer(pParse)).Fdb
	pTriggerStep = uintptr(0)
	if (*TParse)(unsafe.Pointer(pParse)).FnErr == 0 {
		if pNew != 0 && (*TTrigger)(unsafe.Pointer(pNew)).FpSchema != (**(**TDb)(__ccgo_up((*Tsqlite3)(unsafe.Pointer(db)).FaDb + 1*32))).FpSchema && *(*uintptr)(unsafe.Pointer(pTabList + 8 + 72)) != 0 {
			_sqlite3ErrorMsg(tls, pParse, __ccgo_ts+22276, 0)
		} else {
			pTriggerStep = _sqlite3DbMallocZero(tls, db, uint64(88))
			if pTriggerStep != 0 {
				(*TTriggerStep)(unsafe.Pointer(pTriggerStep)).FpSrc = _sqlite3SrcListDup(tls, db, pTabList, int32(EXPRDUP_REDUCE))
				(*TTriggerStep)(unsafe.Pointer(pTriggerStep)).Fop = op
				(*TTriggerStep)(unsafe.Pointer(pTriggerStep)).FzSpan = _triggerSpanDup(tls, db, zStart, zEnd)
				if (*TTriggerStep)(unsafe.Pointer(pTriggerStep)).FpSrc != 0 && libc.Int32FromUint8((*TParse)(unsafe.Pointer(pParse)).FeParseMode) >= int32(PARSE_MODE_RENAME) {
					_sqlite3RenameTokenRemap(tls, pParse, (*(*TSrcItem)(unsafe.Pointer((*TTriggerStep)(unsafe.Pointer(pTriggerStep)).FpSrc + 8))).FzName, (*(*TSrcItem)(unsafe.Pointer(pTabList + 8))).FzName)
				}
			}
		}
	}
	_sqlite3SrcListDelete(tls, db, pTabList)
	return pTriggerStep
}

// C documentation
//
//	/*
//	** Return a list of all triggers on table pTab if there exists at least
//	** one trigger that must be fired when an operation of type 'op' is
//	** performed on the table, and, if that operation is an UPDATE, if at
//	** least one of the columns in pChanges is being modified.
//	*/
func _triggersReallyExist(tls *libc.TLS, pParse uintptr, pTab uintptr, op int32, pChanges uintptr, pMask uintptr) (r uintptr) {
	bp := tls.Alloc(16)
	defer tls.Free(16)
	var mask int32
	var p, pList, v1 uintptr
	_, _, _, _ = mask, p, pList, v1
	mask = 0
	pList = uintptr(0)
	pList = _sqlite3TriggerList(tls, pParse, pTab)
	if pList != uintptr(0) {
		p = pList
		if (*Tsqlite3)(unsafe.Pointer((*TParse)(unsafe.Pointer(pParse)).Fdb)).Fflags&uint64(SQLITE_EnableTrigger) == uint64(0) && (*TTable)(unsafe.Pointer(pTab)).FpTrigger != uintptr(0) && _sqlite3SchemaToIndex(tls, (*TParse)(unsafe.Pointer(pParse)).Fdb, (*TTrigger)(unsafe.Pointer((*TTable)(unsafe.Pointer(pTab)).FpTrigger)).FpSchema) != int32(1) {
			/* The SQLITE_DBCONFIG_ENABLE_TRIGGER setting is off.  That means that
			 ** only TEMP triggers are allowed.  Truncate the pList so that it
			 ** includes only TEMP triggers */
			if pList == (*TTable)(unsafe.Pointer(pTab)).FpTrigger {
				pList = uintptr(0)
				goto exit_triggers_exist
			}
			for (*TTrigger)(unsafe.Pointer(p)).FpNext != 0 && (*TTrigger)(unsafe.Pointer(p)).FpNext != (*TTable)(unsafe.Pointer(pTab)).FpTrigger {
				p = (*TTrigger)(unsafe.Pointer(p)).FpNext
			}
			(*TTrigger)(unsafe.Pointer(p)).FpNext = uintptr(0)
			p = pList
		}
		for cond := true; cond; cond = p != 0 {
			if libc.Int32FromUint8((*TTrigger)(unsafe.Pointer(p)).Fop) == op && _checkColumnOverlap(tls, (*TTrigger)(unsafe.Pointer(p)).FpColumns, pChanges) != 0 {
				mask = mask | libc.Int32FromUint8((*TTrigger)(unsafe.Pointer(p)).Ftr_tm)
			} else {
				if libc.Int32FromUint8((*TTrigger)(unsafe.Pointer(p)).Fop) == int32(TK_RETURNING) {
					/* The first time a RETURNING trigger is seen, the "op" value tells
					 ** us what time of trigger it should be. */
					(*TTrigger)(unsafe.Pointer(p)).Fop = libc.Uint8FromInt32(op)
					if libc.Int32FromUint8((*TTable)(unsafe.Pointer(pTab)).FeTabType) == int32(TABTYP_VTAB) {
						if op != int32(TK_INSERT) {
							if op == int32(TK_DELETE) {
								v1 = __ccgo_ts + 22453
							} else {
								v1 = __ccgo_ts + 22460
							}
							_sqlite3ErrorMsg(tls, pParse, __ccgo_ts+22467, libc.VaList(bp+8, v1))
						}
						(*TTrigger)(unsafe.Pointer(p)).Ftr_tm = uint8(TRIGGER_BEFORE)
					} else {
						(*TTrigger)(unsafe.Pointer(p)).Ftr_tm = uint8(TRIGGER_AFTER)
					}
					mask = mask | libc.Int32FromUint8((*TTrigger)(unsafe.Pointer(p)).Ftr_tm)
				} else {
					if (*TTrigger)(unsafe.Pointer(p)).FbReturning != 0 && libc.Int32FromUint8((*TTrigger)(unsafe.Pointer(p)).Fop) == int32(TK_INSERT) && op == int32(TK_UPDATE) && (*TParse)(unsafe.Pointer(pParse)).FpToplevel == uintptr(0) {
						/* Also fire a RETURNING trigger for an UPSERT */
						mask = mask | libc.Int32FromUint8((*TTrigger)(unsafe.Pointer(p)).Ftr_tm)
					}
				}
			}
			p = (*TTrigger)(unsafe.Pointer(p)).FpNext
		}
	}
	goto exit_triggers_exist
exit_triggers_exist:
	;
	if pMask != 0 {
		**(**int32)(__ccgo_up(pMask)) = mask
	}
	if mask != 0 {
		v1 = pList
	} else {
		v1 = uintptr(0)
	}
	return v1
}

// C documentation
//
//	/*
//	** The unhex() function. This function may be invoked with either one or
//	** two arguments. In both cases the first argument is interpreted as text
//	** a text value containing a set of pairs of hexadecimal digits which are
//	** decoded and returned as a blob.
//	**
//	** If there is only a single argument, then it must consist only of an
//	** even number of hexadecimal digits. Otherwise, return NULL.
//	**
//	** Or, if there is a second argument, then any character that appears in
//	** the second argument is also allowed to appear between pairs of hexadecimal
//	** digits in the first argument. If any other character appears in the
//	** first argument, or if one of the allowed characters appears between
//	** two hexadecimal digits that make up a single byte, NULL is returned.
//	**
//	** The following expressions are all true:
//	**
//	**     unhex('ABCD')       IS x'ABCD'
//	**     unhex('AB CD')      IS NULL
//	**     unhex('AB CD', ' ') IS x'ABCD'
//	**     unhex('A BCD', ' ') IS NULL
//	*/
func _unhexFunc(tls *libc.TLS, pCtx uintptr, argc int32, argv uintptr) {
	bp := tls.Alloc(16)
	defer tls.Free(16)
	var c, d, v2 Tu8
	var ch Tu32
	var nHex, nPass int32
	var p, pBlob, zPass, v1 uintptr
	var v3 uint32
	var _ /* zHex at bp+0 */ uintptr
	_, _, _, _, _, _, _, _, _, _, _ = c, ch, d, nHex, nPass, p, pBlob, zPass, v1, v2, v3
	zPass = __ccgo_ts + 1693
	nPass = 0
	**(**uintptr)(__ccgo_up(bp)) = Xsqlite3_value_text(tls, **(**uintptr)(__ccgo_up(argv)))
	nHex = Xsqlite3_value_bytes(tls, **(**uintptr)(__ccgo_up(argv)))
	pBlob = uintptr(0)
	p = uintptr(0)
	if argc == int32(2) {
		zPass = Xsqlite3_value_text(tls, **(**uintptr)(__ccgo_up(argv + 1*8)))
		nPass = Xsqlite3_value_bytes(tls, **(**uintptr)(__ccgo_up(argv + 1*8)))
	}
	if !(**(**uintptr)(__ccgo_up(bp)) != 0) || !(zPass != 0) {
		return
	}
	v1 = _contextMalloc(tls, pCtx, int64(nHex/int32(2)+int32(1)))
	pBlob = v1
	p = v1
	if pBlob != 0 { /* Least significant digit of next byte */
		for {
			v2 = **(**Tu8)(__ccgo_up(**(**uintptr)(__ccgo_up(bp))))
			c = v2
			if !(libc.Int32FromUint8(v2) != 0x00) {
				break
			}
			for !(libc.Int32FromUint8(_sqlite3CtypeMap[c])&libc.Int32FromInt32(0x08) != 0) {
				if libc.Int32FromUint8(**(**Tu8)(__ccgo_up(**(**uintptr)(__ccgo_up(bp))))) < int32(0x80) {
					v1 = **(**uintptr)(__ccgo_up(bp))
					**(**uintptr)(__ccgo_up(bp)) = **(**uintptr)(__ccgo_up(bp)) + 1
					v3 = uint32(**(**Tu8)(__ccgo_up(v1)))
				} else {
					v3 = _sqlite3Utf8Read(tls, bp)
				}
				ch = v3
				if !(_strContainsChar(tls, zPass, nPass, ch) != 0) {
					goto unhex_null
				}
				c = **(**Tu8)(__ccgo_up(**(**uintptr)(__ccgo_up(bp))))
				if libc.Int32FromUint8(c) == 0x00 {
					goto unhex_done
				}
			}
			**(**uintptr)(__ccgo_up(bp)) = **(**uintptr)(__ccgo_up(bp)) + 1
			v1 = **(**uintptr)(__ccgo_up(bp))
			**(**uintptr)(__ccgo_up(bp)) = **(**uintptr)(__ccgo_up(bp)) + 1
			d = **(**Tu8)(__ccgo_up(v1))
			if !(libc.Int32FromUint8(_sqlite3CtypeMap[d])&libc.Int32FromInt32(0x08) != 0) {
				goto unhex_null
			}
			v1 = p
			p = p + 1
			**(**Tu8)(__ccgo_up(v1)) = libc.Uint8FromInt32(libc.Int32FromUint8(_sqlite3HexToInt(tls, libc.Int32FromUint8(c)))<<int32(4) | libc.Int32FromUint8(_sqlite3HexToInt(tls, libc.Int32FromUint8(d))))
		}
	}
	goto unhex_done
unhex_done:
	;
	Xsqlite3_result_blob(tls, pCtx, pBlob, int32(int64(p)-int64(pBlob)), __ccgo_fp(Xsqlite3_free))
	return
	goto unhex_null
unhex_null:
	;
	Xsqlite3_free(tls, pBlob)
	return
}

// C documentation
//
//	/*
//	** Test the existence of or access permissions of file zPath. The
//	** test performed depends on the value of flags:
//	**
//	**     SQLITE_ACCESS_EXISTS: Return 1 if the file exists
//	**     SQLITE_ACCESS_READWRITE: Return 1 if the file is read and writable.
//	**     SQLITE_ACCESS_READONLY: Return 1 if the file is readable.
//	**
//	** Otherwise return 0.
//	*/
func _unixAccess(tls *libc.TLS, NotUsed uintptr, zPath uintptr, flags int32, pResOut uintptr) (r int32) {
	bp := tls.Alloc(128)
	defer tls.Free(128)
	var _ /* buf at bp+0 */ Tstat
	_ = NotUsed
	/* The spec says there are three possible values for flags.  But only
	 ** two of them are actually used */
	if flags == SQLITE_ACCESS_EXISTS {
		**(**int32)(__ccgo_up(pResOut)) = libc.BoolInt32(0 == (*(*func(*libc.TLS, uintptr, uintptr) int32)(unsafe.Pointer(&struct{ uintptr }{_aSyscall[int32(4)].FpCurrent})))(tls, zPath, bp) && (!((**(**Tstat)(__ccgo_up(bp))).Fst_mode&libc.Uint32FromInt32(0170000) == libc.Uint32FromInt32(0100000)) || (**(**Tstat)(__ccgo_up(bp))).Fst_size > 0))
	} else {
		**(**int32)(__ccgo_up(pResOut)) = libc.BoolInt32((*(*func(*libc.TLS, uintptr, int32) int32)(unsafe.Pointer(&struct{ uintptr }{_aSyscall[int32(2)].FpCurrent})))(tls, zPath, libc.Int32FromInt32(W_OK)|libc.Int32FromInt32(R_OK)) == 0)
	}
	return SQLITE_OK
}

// C documentation
//
//	/*
//	** Find the current time (in Universal Coordinated Time).  Write into *piNow
//	** the current time and date as a Julian Day number times 86_400_000.  In
//	** other words, write into *piNow the number of milliseconds since the Julian
//	** epoch of noon in Greenwich on November 24, 4714 B.C according to the
//	** proleptic Gregorian calendar.
//	**
//	** On success, return SQLITE_OK.  Return SQLITE_ERROR if the time and date
//	** cannot be found.
//	*/
func _unixCurrentTimeInt64(tls *libc.TLS, NotUsed uintptr, piNow uintptr) (r int32) {
	bp := tls.Alloc(16)
	defer tls.Free(16)
	var rc int32
	var _ /* sNow at bp+0 */ Ttimeval
	_ = rc
	rc = SQLITE_OK
	libc.Xgettimeofday(tls, bp, uintptr(0)) /* Cannot fail given valid arguments */
	**(**Tsqlite3_int64)(__ccgo_up(piNow)) = _unixEpoch + int64(1000)*(**(**Ttimeval)(__ccgo_up(bp))).Ftv_sec + int64((**(**Ttimeval)(__ccgo_up(bp))).Ftv_usec/int64(1000))
	_ = NotUsed
	return rc
}

// C documentation
//
//	/*
//	** Delete the file at zPath. If the dirSync argument is true, fsync()
//	** the directory after deleting the file.
//	*/
func _unixDelete(tls *libc.TLS, NotUsed uintptr, zPath uintptr, dirSync int32) (r int32) {
	bp := tls.Alloc(16)
	defer tls.Free(16)
	var rc int32
	var _ /* fd at bp+0 */ int32
	_ = rc
	rc = SQLITE_OK
	_ = NotUsed
	if (*(*func(*libc.TLS, uintptr) int32)(unsafe.Pointer(&struct{ uintptr }{_aSyscall[int32(16)].FpCurrent})))(tls, zPath) == -int32(1) {
		if **(**int32)(__ccgo_up(libc.X__errno(tls))) == int32(ENOENT) {
			rc = libc.Int32FromInt32(SQLITE_IOERR) | libc.Int32FromInt32(23)<<libc.Int32FromInt32(8)
		} else {
			rc = _unixLogErrorAtLine(tls, libc.Int32FromInt32(SQLITE_IOERR)|libc.Int32FromInt32(10)<<libc.Int32FromInt32(8), __ccgo_ts+3641, zPath, int32(47046))
		}
		return rc
	}
	if dirSync&int32(1) != 0 {
		rc = (*(*func(*libc.TLS, uintptr, uintptr) int32)(unsafe.Pointer(&struct{ uintptr }{_aSyscall[int32(17)].FpCurrent})))(tls, zPath, bp)
		if rc == SQLITE_OK {
			if _full_fsync(tls, **(**int32)(__ccgo_up(bp)), 0, 0) != 0 {
				rc = _unixLogErrorAtLine(tls, libc.Int32FromInt32(SQLITE_IOERR)|libc.Int32FromInt32(5)<<libc.Int32FromInt32(8), __ccgo_ts+4058, zPath, int32(47056))
			}
			_robust_close(tls, uintptr(0), **(**int32)(__ccgo_up(bp)), int32(47058))
		} else {
			rc = SQLITE_OK
		}
	}
	return rc
}

// C documentation
//
//	/*
//	** SQLite calls this function immediately after a call to unixDlSym() or
//	** unixDlOpen() fails (returns a null pointer). If a more detailed error
//	** message is available, it is written to zBufOut. If no error message
//	** is available, zBufOut is left unmodified and SQLite uses a default
//	** error message.
//	*/
func _unixDlError(tls *libc.TLS, NotUsed uintptr, nBuf int32, zBufOut uintptr) {
	bp := tls.Alloc(16)
	defer tls.Free(16)
	var zErr uintptr
	_ = zErr
	_ = NotUsed
	_unixEnterMutex(tls)
	zErr = libc.Xdlerror(tls)
	if zErr != 0 {
		Xsqlite3_snprintf(tls, nBuf, zBufOut, __ccgo_ts+3933, libc.VaList(bp+8, zErr))
	}
	_unixLeaveMutex(tls)
}

// C documentation
//
//	/*
//	** Information and control of an open file handle.
//	*/
func _unixFileControl(tls *libc.TLS, id uintptr, op int32, pArg uintptr) (r int32) {
	bp := tls.Alloc(16)
	defer tls.Free(16)
	var pFile, zTFile uintptr
	var rc int32
	_, _, _ = pFile, rc, zTFile
	pFile = id
	switch op {
	case int32(SQLITE_FCNTL_NULL_IO):
		(*(*func(*libc.TLS, int32) int32)(unsafe.Pointer(&struct{ uintptr }{_aSyscall[int32(1)].FpCurrent})))(tls, (*TunixFile)(unsafe.Pointer(pFile)).Fh)
		(*TunixFile)(unsafe.Pointer(pFile)).Fh = -int32(1)
		return SQLITE_OK
	case int32(SQLITE_FCNTL_LOCKSTATE):
		**(**int32)(__ccgo_up(pArg)) = libc.Int32FromUint8((*TunixFile)(unsafe.Pointer(pFile)).FeFileLock)
		return SQLITE_OK
	case int32(SQLITE_FCNTL_LAST_ERRNO):
		**(**int32)(__ccgo_up(pArg)) = (*TunixFile)(unsafe.Pointer(pFile)).FlastErrno
		return SQLITE_OK
	case int32(SQLITE_FCNTL_CHUNK_SIZE):
		(*TunixFile)(unsafe.Pointer(pFile)).FszChunk = **(**int32)(__ccgo_up(pArg))
		return SQLITE_OK
	case int32(SQLITE_FCNTL_SIZE_HINT):
		rc = _fcntlSizeHint(tls, pFile, **(**Ti64)(__ccgo_up(pArg)))
		return rc
	case int32(SQLITE_FCNTL_PERSIST_WAL):
		_unixModeBit(tls, pFile, uint8(UNIXFILE_PERSIST_WAL), pArg)
		return SQLITE_OK
	case int32(SQLITE_FCNTL_POWERSAFE_OVERWRITE):
		_unixModeBit(tls, pFile, uint8(UNIXFILE_PSOW), pArg)
		return SQLITE_OK
	case int32(SQLITE_FCNTL_VFSNAME):
		**(**uintptr)(__ccgo_up(pArg)) = Xsqlite3_mprintf(tls, __ccgo_ts+3933, libc.VaList(bp+8, (*Tsqlite3_vfs)(unsafe.Pointer((*TunixFile)(unsafe.Pointer(pFile)).FpVfs)).FzName))
		return SQLITE_OK
	case int32(SQLITE_FCNTL_TEMPFILENAME):
		zTFile = Xsqlite3_malloc64(tls, libc.Uint64FromInt32((*Tsqlite3_vfs)(unsafe.Pointer((*TunixFile)(unsafe.Pointer(pFile)).FpVfs)).FmxPathname))
		if zTFile != 0 {
			_unixGetTempname(tls, (*Tsqlite3_vfs)(unsafe.Pointer((*TunixFile)(unsafe.Pointer(pFile)).FpVfs)).FmxPathname, zTFile)
			**(**uintptr)(__ccgo_up(pArg)) = zTFile
		}
		return SQLITE_OK
	case int32(SQLITE_FCNTL_HAS_MOVED):
		**(**int32)(__ccgo_up(pArg)) = _fileHasMoved(tls, pFile)
		return SQLITE_OK
	case int32(SQLITE_FCNTL_EXTERNAL_READER):
		return _unixFcntlExternalReader(tls, id, pArg)
	}
	return int32(SQLITE_NOTFOUND)
}

// C documentation
//
//	/*
//	** Determine the current size of a file in bytes
//	*/
func _unixFileSize(tls *libc.TLS, id uintptr, pSize uintptr) (r int32) {
	bp := tls.Alloc(128)
	defer tls.Free(128)
	var rc int32
	var _ /* buf at bp+0 */ Tstat
	_ = rc
	rc = (*(*func(*libc.TLS, int32, uintptr) int32)(unsafe.Pointer(&struct{ uintptr }{_aSyscall[int32(5)].FpCurrent})))(tls, (*TunixFile)(unsafe.Pointer(id)).Fh, bp)
	if rc != 0 {
		_storeLastErrno(tls, id, **(**int32)(__ccgo_up(libc.X__errno(tls))))
		return libc.Int32FromInt32(SQLITE_IOERR) | libc.Int32FromInt32(7)<<libc.Int32FromInt32(8)
	}
	**(**Ti64)(__ccgo_up(pSize)) = (**(**Tstat)(__ccgo_up(bp))).Fst_size
	/* When opening a zero-size database, the findInodeInfo() procedure
	 ** writes a single byte into that file in order to work around a bug
	 ** in the OS-X msdos filesystem.  In order to avoid problems with upper
	 ** layers, we need to report this file size as zero even though it is
	 ** really 1.   Ticket #3260.
	 */
	if **(**Ti64)(__ccgo_up(pSize)) == int64(1) {
		**(**Ti64)(__ccgo_up(pSize)) = 0
	}
	return SQLITE_OK
}

// C documentation
//
//	/*
//	** Return the system page size.
//	**
//	** This function should not be called directly by other code in this file.
//	** Instead, it should be called via macro osGetpagesize().
//	*/
func _unixGetpagesize(tls *libc.TLS) (r int32) {
	return libc.Xgetpagesize(tls)
}

/*
** Constants used for locking
 */

// C documentation
//
//	/*
//	** The DMS lock has not yet been taken on shm file pShmNode. Attempt to
//	** take it now. Return SQLITE_OK if successful, or an SQLite error
//	** code otherwise.
//	**
//	** If the DMS cannot be locked because this is a readonly_shm=1
//	** connection and no other process already holds a lock, return
//	** SQLITE_READONLY_CANTINIT and set pShmNode->isUnlocked=1.
//	*/
func _unixLockSharedMemory(tls *libc.TLS, pDbFd uintptr, pShmNode uintptr) (r int32) {
	bp := tls.Alloc(48)
	defer tls.Free(48)
	var rc int32
	var _ /* lock at bp+0 */ Tflock
	_ = rc
	rc = SQLITE_OK
	/* Use F_GETLK to determine the locks other processes are holding
	 ** on the DMS byte. If it indicates that another process is holding
	 ** a SHARED lock, then this process may also take a SHARED lock
	 ** and proceed with opening the *-shm file.
	 **
	 ** Or, if no other process is holding any lock, then this process
	 ** is the first to open it. In this case take an EXCLUSIVE lock on the
	 ** DMS byte and truncate the *-shm file to zero bytes in size. Then
	 ** downgrade to a SHARED lock on the DMS byte.
	 **
	 ** If another process is holding an EXCLUSIVE lock on the DMS byte,
	 ** return SQLITE_BUSY to the caller (it will try again). An earlier
	 ** version of this code attempted the SHARED lock at this point. But
	 ** this introduced a subtle race condition: if the process holding
	 ** EXCLUSIVE failed just before truncating the *-shm file, then this
	 ** process might open and use the *-shm file without truncating it.
	 ** And if the *-shm file has been corrupted by a power failure or
	 ** system crash, the database itself may also become corrupt.  */
	(**(**Tflock)(__ccgo_up(bp))).Fl_whence = SEEK_SET
	(**(**Tflock)(__ccgo_up(bp))).Fl_start = int64((libc.Int32FromInt32(22)+libc.Int32FromInt32(SQLITE_SHM_NLOCK))*libc.Int32FromInt32(4) + libc.Int32FromInt32(SQLITE_SHM_NLOCK))
	(**(**Tflock)(__ccgo_up(bp))).Fl_len = int64(1)
	(**(**Tflock)(__ccgo_up(bp))).Fl_type = int16(F_WRLCK)
	if (*(*func(*libc.TLS, int32, int32, uintptr) int32)(unsafe.Pointer(&struct{ uintptr }{_aSyscall[int32(7)].FpCurrent})))(tls, (*TunixShmNode)(unsafe.Pointer(pShmNode)).FhShm, int32(F_GETLK), libc.VaList(bp+32, bp)) != 0 {
		rc = libc.Int32FromInt32(SQLITE_IOERR) | libc.Int32FromInt32(15)<<libc.Int32FromInt32(8)
	} else {
		if int32((**(**Tflock)(__ccgo_up(bp))).Fl_type) == int32(F_UNLCK) {
			if (*TunixShmNode)(unsafe.Pointer(pShmNode)).FisReadonly != 0 {
				(*TunixShmNode)(unsafe.Pointer(pShmNode)).FisUnlocked = uint8(1)
				rc = libc.Int32FromInt32(SQLITE_READONLY) | libc.Int32FromInt32(5)<<libc.Int32FromInt32(8)
			} else {
				rc = _unixShmSystemLock(tls, pDbFd, int32(F_WRLCK), (libc.Int32FromInt32(22)+libc.Int32FromInt32(SQLITE_SHM_NLOCK))*libc.Int32FromInt32(4)+libc.Int32FromInt32(SQLITE_SHM_NLOCK), int32(1))
				/* The first connection to attach must truncate the -shm file.  We
				 ** truncate to 3 bytes (an arbitrary small number, less than the
				 ** -shm header size) rather than 0 as a system debugging aid, to
				 ** help detect if a -shm file truncation is legitimate or is the work
				 ** or a rogue process. */
				if rc == SQLITE_OK && _robust_ftruncate(tls, (*TunixShmNode)(unsafe.Pointer(pShmNode)).FhShm, int64(3)) != 0 {
					rc = _unixLogErrorAtLine(tls, libc.Int32FromInt32(SQLITE_IOERR)|libc.Int32FromInt32(18)<<libc.Int32FromInt32(8), __ccgo_ts+3567, (*TunixShmNode)(unsafe.Pointer(pShmNode)).FzFilename, int32(45100))
				}
			}
		} else {
			if int32((**(**Tflock)(__ccgo_up(bp))).Fl_type) == int32(F_WRLCK) {
				rc = int32(SQLITE_BUSY)
			}
		}
	}
	if rc == SQLITE_OK {
		rc = _unixShmSystemLock(tls, pDbFd, int32(F_RDLCK), (libc.Int32FromInt32(22)+libc.Int32FromInt32(SQLITE_SHM_NLOCK))*libc.Int32FromInt32(4)+libc.Int32FromInt32(SQLITE_SHM_NLOCK), int32(1))
	}
	return rc
}

// C documentation
//
//	/*
//	**
//	** This function - unixLogErrorAtLine(), is only ever called via the macro
//	** unixLogError().
//	**
//	** It is invoked after an error occurs in an OS function and errno has been
//	** set. It logs a message using sqlite3_log() containing the current value of
//	** errno and, if possible, the human-readable equivalent from strerror() or
//	** strerror_r().
//	**
//	** The first argument passed to the macro should be the error code that
//	** will be returned to SQLite (e.g. SQLITE_IOERR_DELETE, SQLITE_CANTOPEN).
//	** The two subsequent arguments should be the name of the OS function that
//	** failed (e.g. "unlink", "open") and the associated file-system path,
//	** if any.
//	*/
func _unixLogErrorAtLine(tls *libc.TLS, errcode int32, zFunc uintptr, zPath uintptr, iLine int32) (r int32) {
	bp := tls.Alloc(48)
	defer tls.Free(48)
	var iErrno int32
	var zErr uintptr
	_, _ = iErrno, zErr                                 /* Message from strerror() or equivalent */
	iErrno = **(**int32)(__ccgo_up(libc.X__errno(tls))) /* Saved syscall error number */
	/* If this is not a threadsafe build (SQLITE_THREADSAFE==0), then use
	 ** the strerror() function to obtain the human-readable error message
	 ** equivalent to errno. Otherwise, use strerror_r().
	 */
	/* This is a threadsafe build, but strerror_r() is not available. */
	zErr = __ccgo_ts + 1693
	if zPath == uintptr(0) {
		zPath = __ccgo_ts + 1693
	}
	Xsqlite3_log(tls, errcode, __ccgo_ts+3794, libc.VaList(bp+8, iLine, iErrno, zFunc, zPath, zErr))
	return errcode
}

// C documentation
//
//	/*
//	** Open a shared-memory area associated with open database file pDbFd.
//	** This particular implementation uses mmapped files.
//	**
//	** The file used to implement shared-memory is in the same directory
//	** as the open database file and has the same name as the open database
//	** file with the "-shm" suffix added.  For example, if the database file
//	** is "/home/user1/config.db" then the file that is created and mmapped
//	** for shared memory will be called "/home/user1/config.db-shm".
//	**
//	** Another approach to is to use files in /dev/shm or /dev/tmp or an
//	** some other tmpfs mount. But if a file in a different directory
//	** from the database file is used, then differing access permissions
//	** or a chroot() might cause two different processes on the same
//	** database to end up using different files for shared memory -
//	** meaning that their memory would not really be shared - resulting
//	** in database corruption.  Nevertheless, this tmpfs file usage
//	** can be enabled at compile-time using -DSQLITE_SHM_DIRECTORY="/dev/shm"
//	** or the equivalent.  The use of the SQLITE_SHM_DIRECTORY compile-time
//	** option results in an incompatible build of SQLite;  builds of SQLite
//	** that with differing SQLITE_SHM_DIRECTORY settings attempt to use the
//	** same database file at the same time, database corruption will likely
//	** result. The SQLITE_SHM_DIRECTORY compile-time option is considered
//	** "unsupported" and may go away in a future SQLite release.
//	**
//	** When opening a new shared-memory file, if no other instances of that
//	** file are currently open, in this process or in other processes, then
//	** the file must be truncated to zero length or have its header cleared.
//	**
//	** If the original database file (pDbFd) is using the "unix-excl" VFS
//	** that means that an exclusive lock is held on the database file and
//	** that no other processes are able to read or write the database.  In
//	** that case, we do not really need shared memory.  No shared memory
//	** file is created.  The shared memory will be simulated with heap memory.
//	*/
func _unixOpenSharedMemory(tls *libc.TLS, pDbFd uintptr) (r int32) {
	bp := tls.Alloc(144)
	defer tls.Free(144)
	var nShmFilename, rc int32
	var p, pInode, pShmNode, zBasePath, zShm, v1 uintptr
	var _ /* sStat at bp+0 */ Tstat
	_, _, _, _, _, _, _, _ = nShmFilename, p, pInode, pShmNode, rc, zBasePath, zShm, v1
	p = uintptr(0) /* The underlying mmapped file */
	rc = SQLITE_OK /* Size of the SHM filename in bytes */
	/* Allocate space for the new unixShm object. */
	p = Xsqlite3_malloc64(tls, uint64(24))
	if p == uintptr(0) {
		return int32(SQLITE_NOMEM)
	}
	libc.Xmemset(tls, p, 0, uint64(24))
	/* Check to see if a unixShmNode object already exists. Reuse an existing
	 ** one if present. Create a new one if necessary.
	 */
	_unixEnterMutex(tls)
	pInode = (*TunixFile)(unsafe.Pointer(pDbFd)).FpInode
	pShmNode = (*TunixInodeInfo)(unsafe.Pointer(pInode)).FpShmNode
	if pShmNode == uintptr(0) { /* fstat() info for database file */
		zBasePath = (*TunixFile)(unsafe.Pointer(pDbFd)).FzPath
		/* Call fstat() to figure out the permissions on the database file. If
		 ** a new *-shm file is created, an attempt will be made to create it
		 ** with the same permissions.
		 */
		if (*(*func(*libc.TLS, int32, uintptr) int32)(unsafe.Pointer(&struct{ uintptr }{_aSyscall[int32(5)].FpCurrent})))(tls, (*TunixFile)(unsafe.Pointer(pDbFd)).Fh, bp) != 0 {
			rc = libc.Int32FromInt32(SQLITE_IOERR) | libc.Int32FromInt32(7)<<libc.Int32FromInt32(8)
			goto shm_open_err
		}
		nShmFilename = int32(6) + libc.Int32FromUint64(libc.Xstrlen(tls, zBasePath))
		pShmNode = Xsqlite3_malloc64(tls, uint64(uint64(96)+libc.Uint64FromInt32(nShmFilename)))
		if pShmNode == uintptr(0) {
			rc = int32(SQLITE_NOMEM)
			goto shm_open_err
		}
		libc.Xmemset(tls, pShmNode, 0, uint64(96)+libc.Uint64FromInt32(nShmFilename))
		v1 = pShmNode + 1*96
		(*TunixShmNode)(unsafe.Pointer(pShmNode)).FzFilename = v1
		zShm = v1
		Xsqlite3_snprintf(tls, nShmFilename, zShm, __ccgo_ts+3947, libc.VaList(bp+136, zBasePath))
		(*TunixShmNode)(unsafe.Pointer(pShmNode)).FhShm = -int32(1)
		(*TunixInodeInfo)(unsafe.Pointer((*TunixFile)(unsafe.Pointer(pDbFd)).FpInode)).FpShmNode = pShmNode
		(*TunixShmNode)(unsafe.Pointer(pShmNode)).FpInode = (*TunixFile)(unsafe.Pointer(pDbFd)).FpInode
		if _sqlite3Config.FbCoreMutex != 0 {
			(*TunixShmNode)(unsafe.Pointer(pShmNode)).FpShmMutex = Xsqlite3_mutex_alloc(tls, SQLITE_MUTEX_FAST)
			if (*TunixShmNode)(unsafe.Pointer(pShmNode)).FpShmMutex == uintptr(0) {
				rc = int32(SQLITE_NOMEM)
				goto shm_open_err
			}
		}
		if libc.Int32FromUint8((*TunixInodeInfo)(unsafe.Pointer(pInode)).FbProcessLock) == 0 {
			if 0 == Xsqlite3_uri_boolean(tls, (*TunixFile)(unsafe.Pointer(pDbFd)).FzPath, __ccgo_ts+3954, 0) {
				(*TunixShmNode)(unsafe.Pointer(pShmNode)).FhShm = _robust_open(tls, zShm, libc.Int32FromInt32(O_RDWR)|libc.Int32FromInt32(O_CREAT)|libc.Int32FromInt32(O_NOFOLLOW), (**(**Tstat)(__ccgo_up(bp))).Fst_mode&libc.Uint32FromInt32(0777))
			}
			if (*TunixShmNode)(unsafe.Pointer(pShmNode)).FhShm < 0 {
				(*TunixShmNode)(unsafe.Pointer(pShmNode)).FhShm = _robust_open(tls, zShm, libc.Int32FromInt32(O_RDONLY)|libc.Int32FromInt32(O_NOFOLLOW), (**(**Tstat)(__ccgo_up(bp))).Fst_mode&libc.Uint32FromInt32(0777))
				if (*TunixShmNode)(unsafe.Pointer(pShmNode)).FhShm < 0 {
					rc = _unixLogErrorAtLine(tls, _sqlite3CantopenError(tls, int32(45237)), __ccgo_ts+3531, zShm, int32(45237))
					goto shm_open_err
				}
				(*TunixShmNode)(unsafe.Pointer(pShmNode)).FisReadonly = uint8(1)
			}
			/* If this process is running as root, make sure that the SHM file
			 ** is owned by the same user that owns the original database.  Otherwise,
			 ** the original owner will not be able to connect.
			 */
			_robustFchown(tls, (*TunixShmNode)(unsafe.Pointer(pShmNode)).FhShm, (**(**Tstat)(__ccgo_up(bp))).Fst_uid, (**(**Tstat)(__ccgo_up(bp))).Fst_gid)
			rc = _unixLockSharedMemory(tls, pDbFd, pShmNode)
			if rc != SQLITE_OK && rc != libc.Int32FromInt32(SQLITE_READONLY)|libc.Int32FromInt32(5)<<libc.Int32FromInt32(8) {
				goto shm_open_err
			}
		}
	}
	/* Make the new connection a child of the unixShmNode */
	(*TunixShm)(unsafe.Pointer(p)).FpShmNode = pShmNode
	(*TunixShmNode)(unsafe.Pointer(pShmNode)).FnRef = (*TunixShmNode)(unsafe.Pointer(pShmNode)).FnRef + 1
	(*TunixFile)(unsafe.Pointer(pDbFd)).FpShm = p
	_unixLeaveMutex(tls)
	/* The reference count on pShmNode has already been incremented under
	 ** the cover of the unixEnterMutex() mutex and the pointer from the
	 ** new (struct unixShm) object to the pShmNode has been set. All that is
	 ** left to do is to link the new object into the linked list starting
	 ** at pShmNode->pFirst. This must be done while holding the
	 ** pShmNode->pShmMutex.
	 */
	Xsqlite3_mutex_enter(tls, (*TunixShmNode)(unsafe.Pointer(pShmNode)).FpShmMutex)
	(*TunixShm)(unsafe.Pointer(p)).FpNext = (*TunixShmNode)(unsafe.Pointer(pShmNode)).FpFirst
	(*TunixShmNode)(unsafe.Pointer(pShmNode)).FpFirst = p
	Xsqlite3_mutex_leave(tls, (*TunixShmNode)(unsafe.Pointer(pShmNode)).FpShmMutex)
	return rc
	/* Jump here on any error */
	goto shm_open_err
shm_open_err:
	;
	_unixShmPurge(tls, pDbFd) /* This call frees pShmNode if required */
	Xsqlite3_free(tls, p)
	_unixLeaveMutex(tls)
	return rc
}

// C documentation
//
//	/*
//	** Write nBuf bytes of random data to the supplied buffer zBuf.
//	*/
func _unixRandomness(tls *libc.TLS, NotUsed uintptr, nBuf int32, zBuf uintptr) (r int32) {
	bp := tls.Alloc(16)
	defer tls.Free(16)
	var fd, got int32
	var _ /* rp at bp+8 */ Tpid_t
	var _ /* t at bp+0 */ Ttime_t
	_, _ = fd, got
	_ = NotUsed
	/* We have to initialize zBuf to prevent valgrind from reporting
	 ** errors.  The reports issued by valgrind are incorrect - we would
	 ** prefer that the randomness be increased by making use of the
	 ** uninitialized space in zBuf - but valgrind errors tend to worry
	 ** some users.  Rather than argue, it seems easier just to initialize
	 ** the whole array and silence valgrind, even if that means less randomness
	 ** in the random seed.
	 **
	 ** When testing, initializing zBuf[] to zero is all we do.  That means
	 ** that we always use the same random number sequence.  This makes the
	 ** tests repeatable.
	 */
	libc.Xmemset(tls, zBuf, 0, libc.Uint64FromInt32(nBuf))
	libc.AtomicStorePInt32(uintptr(unsafe.Pointer(&_randomnessPid)), libc.Xgetpid(tls))
	fd = _robust_open(tls, __ccgo_ts+4064, O_RDONLY, uint32(0))
	if fd < 0 {
		libc.Xtime(tls, bp)
		libc.Xmemcpy(tls, zBuf, bp, uint64(8))
		**(**Tpid_t)(__ccgo_up(bp + 8)) = libc.AtomicLoadPInt32(uintptr(unsafe.Pointer(&_randomnessPid)))
		libc.Xmemcpy(tls, zBuf+uintptr(8), bp+8, uint64(4))
		nBuf = libc.Int32FromUint64(libc.Uint64FromInt64(8) + libc.Uint64FromInt64(4))
	} else {
		for cond := true; cond; cond = got < 0 && **(**int32)(__ccgo_up(libc.X__errno(tls))) == int32(EINTR) {
			got = int32((*(*func(*libc.TLS, int32, uintptr, Tsize_t) Tssize_t)(unsafe.Pointer(&struct{ uintptr }{_aSyscall[int32(8)].FpCurrent})))(tls, fd, zBuf, libc.Uint64FromInt32(nBuf)))
		}
		_robust_close(tls, uintptr(0), fd, int32(47329))
	}
	return nBuf
}

// C documentation
//
//	/*
//	** This function is called to obtain a pointer to region iRegion of the
//	** shared-memory associated with the database file fd. Shared-memory regions
//	** are numbered starting from zero. Each shared-memory region is szRegion
//	** bytes in size.
//	**
//	** If an error occurs, an error code is returned and *pp is set to NULL.
//	**
//	** Otherwise, if the bExtend parameter is 0 and the requested shared-memory
//	** region has not been allocated (by any client, including one running in a
//	** separate process), then *pp is set to NULL and SQLITE_OK returned. If
//	** bExtend is non-zero and the requested shared-memory region has not yet
//	** been allocated, it is allocated by this function.
//	**
//	** If the shared-memory region has already been allocated or is allocated by
//	** this call as described above, then it is mapped into this processes
//	** address space (if it is not already), *pp is set to point to the mapped
//	** memory and SQLITE_OK returned.
//	*/
func _unixShmMap(tls *libc.TLS, fd uintptr, iRegion int32, szRegion int32, bExtend int32, pp uintptr) (r int32) {
	bp := tls.Alloc(144)
	defer tls.Free(144)
	var apNew, p, pDbFd, pMem, pShmNode, zFile, v4 uintptr
	var i, iPg, nByte, nMap Ti64
	var nReqRegion, nShmPerMap, rc, v2 int32
	var _ /* sStat at bp+0 */ Tstat
	var _ /* x at bp+128 */ int32
	_, _, _, _, _, _, _, _, _, _, _, _, _, _, _ = apNew, i, iPg, nByte, nMap, nReqRegion, nShmPerMap, p, pDbFd, pMem, pShmNode, rc, zFile, v2, v4
	pDbFd = fd
	rc = SQLITE_OK
	nShmPerMap = _unixShmRegionPerMap(tls)
	/* If the shared-memory file has not yet been opened, open it now. */
	if (*TunixFile)(unsafe.Pointer(pDbFd)).FpShm == uintptr(0) {
		rc = _unixOpenSharedMemory(tls, pDbFd)
		if rc != SQLITE_OK {
			return rc
		}
	}
	p = (*TunixFile)(unsafe.Pointer(pDbFd)).FpShm
	pShmNode = (*TunixShm)(unsafe.Pointer(p)).FpShmNode
	Xsqlite3_mutex_enter(tls, (*TunixShmNode)(unsafe.Pointer(pShmNode)).FpShmMutex)
	if (*TunixShmNode)(unsafe.Pointer(pShmNode)).FisUnlocked != 0 {
		rc = _unixLockSharedMemory(tls, pDbFd, pShmNode)
		if rc != SQLITE_OK {
			goto shmpage_out
		}
		(*TunixShmNode)(unsafe.Pointer(pShmNode)).FisUnlocked = uint8(0)
	}
	/* Minimum number of regions required to be mapped. */
	nReqRegion = (iRegion + nShmPerMap) / nShmPerMap * nShmPerMap
	if libc.Int32FromUint16((*TunixShmNode)(unsafe.Pointer(pShmNode)).FnRegion) < nReqRegion { /* New apRegion[] array */
		nByte = int64(nReqRegion) * int64(szRegion) /* Used by fstat() */
		(*TunixShmNode)(unsafe.Pointer(pShmNode)).FszRegion = szRegion
		if (*TunixShmNode)(unsafe.Pointer(pShmNode)).FhShm >= 0 {
			/* The requested region is not mapped into this processes address space.
			 ** Check to see if it has been allocated (i.e. if the wal-index file is
			 ** large enough to contain the requested region).
			 */
			if (*(*func(*libc.TLS, int32, uintptr) int32)(unsafe.Pointer(&struct{ uintptr }{_aSyscall[int32(5)].FpCurrent})))(tls, (*TunixShmNode)(unsafe.Pointer(pShmNode)).FhShm, bp) != 0 {
				rc = libc.Int32FromInt32(SQLITE_IOERR) | libc.Int32FromInt32(19)<<libc.Int32FromInt32(8)
				goto shmpage_out
			}
			if (**(**Tstat)(__ccgo_up(bp))).Fst_size < nByte {
				/* The requested memory region does not exist. If bExtend is set to
				 ** false, exit early. *pp will be set to NULL and SQLITE_OK returned.
				 */
				if !(bExtend != 0) {
					goto shmpage_out
				} else {
					/* Write to the last byte of each newly allocated or extended page */
					iPg = (**(**Tstat)(__ccgo_up(bp))).Fst_size / int64(_pgsz)
					for {
						if !(iPg < nByte/int64(_pgsz)) {
							break
						}
						**(**int32)(__ccgo_up(bp + 128)) = 0
						if _seekAndWriteFd(tls, (*TunixShmNode)(unsafe.Pointer(pShmNode)).FhShm, iPg*int64(_pgsz)+int64(_pgsz)-int64(1), __ccgo_ts+1693, int32(1), bp+128) != int32(1) {
							zFile = (*TunixShmNode)(unsafe.Pointer(pShmNode)).FzFilename
							rc = _unixLogErrorAtLine(tls, libc.Int32FromInt32(SQLITE_IOERR)|libc.Int32FromInt32(19)<<libc.Int32FromInt32(8), __ccgo_ts+3602, zFile, int32(45381))
							goto shmpage_out
						}
						goto _1
					_1:
						;
						iPg = iPg + 1
					}
				}
			}
		}
		/* Map the requested memory region into this processes address space. */
		apNew = Xsqlite3_realloc64(tls, (*TunixShmNode)(unsafe.Pointer(pShmNode)).FapRegion, uint64(libc.Uint64FromInt32(nReqRegion)*uint64(8)))
		if !(apNew != 0) {
			rc = libc.Int32FromInt32(SQLITE_IOERR) | libc.Int32FromInt32(12)<<libc.Int32FromInt32(8)
			goto shmpage_out
		}
		(*TunixShmNode)(unsafe.Pointer(pShmNode)).FapRegion = apNew
		for libc.Int32FromUint16((*TunixShmNode)(unsafe.Pointer(pShmNode)).FnRegion) < nReqRegion {
			nMap = int64(szRegion) * int64(nShmPerMap)
			if (*TunixShmNode)(unsafe.Pointer(pShmNode)).FhShm >= 0 {
				if (*TunixShmNode)(unsafe.Pointer(pShmNode)).FisReadonly != 0 {
					v2 = int32(PROT_READ)
				} else {
					v2 = libc.Int32FromInt32(PROT_READ) | libc.Int32FromInt32(PROT_WRITE)
				}
				pMem = (*(*func(*libc.TLS, uintptr, Tsize_t, int32, int32, int32, Toff_t) uintptr)(unsafe.Pointer(&struct{ uintptr }{_aSyscall[int32(22)].FpCurrent})))(tls, uintptr(0), libc.Uint64FromInt64(nMap), v2, int32(MAP_SHARED), (*TunixShmNode)(unsafe.Pointer(pShmNode)).FhShm, int64(szRegion)*libc.Int64FromUint16((*TunixShmNode)(unsafe.Pointer(pShmNode)).FnRegion))
				if pMem == uintptr(-libc.Int32FromInt32(1)) {
					rc = _unixLogErrorAtLine(tls, libc.Int32FromInt32(SQLITE_IOERR)|libc.Int32FromInt32(21)<<libc.Int32FromInt32(8), __ccgo_ts+3689, (*TunixShmNode)(unsafe.Pointer(pShmNode)).FzFilename, int32(45408))
					goto shmpage_out
				}
			} else {
				pMem = Xsqlite3_malloc64(tls, libc.Uint64FromInt64(nMap))
				if pMem == uintptr(0) {
					rc = int32(SQLITE_NOMEM)
					goto shmpage_out
				}
				libc.Xmemset(tls, pMem, 0, libc.Uint64FromInt64(nMap))
			}
			i = 0
			for {
				if !(i < int64(nShmPerMap)) {
					break
				}
				**(**uintptr)(__ccgo_up((*TunixShmNode)(unsafe.Pointer(pShmNode)).FapRegion + uintptr(libc.Int64FromUint16((*TunixShmNode)(unsafe.Pointer(pShmNode)).FnRegion)+i)*8)) = pMem + uintptr(int64(szRegion)*i)
				goto _3
			_3:
				;
				i = i + 1
			}
			v4 = pShmNode + 32
			*(*Tu16)(unsafe.Pointer(v4)) = Tu16(int32(*(*Tu16)(unsafe.Pointer(v4))) + nShmPerMap)
		}
	}
	goto shmpage_out
shmpage_out:
	;
	if libc.Int32FromUint16((*TunixShmNode)(unsafe.Pointer(pShmNode)).FnRegion) > iRegion {
		**(**uintptr)(__ccgo_up(pp)) = **(**uintptr)(__ccgo_up((*TunixShmNode)(unsafe.Pointer(pShmNode)).FapRegion + uintptr(iRegion)*8))
	} else {
		**(**uintptr)(__ccgo_up(pp)) = uintptr(0)
	}
	if (*TunixShmNode)(unsafe.Pointer(pShmNode)).FisReadonly != 0 && rc == SQLITE_OK {
		rc = int32(SQLITE_READONLY)
	}
	Xsqlite3_mutex_leave(tls, (*TunixShmNode)(unsafe.Pointer(pShmNode)).FpShmMutex)
	return rc
}

// C documentation
//
//	/*
//	** Make sure all writes to a particular file are committed to disk.
//	**
//	** If dataOnly==0 then both the file itself and its metadata (file
//	** size, access time, etc) are synced.  If dataOnly!=0 then only the
//	** file data is synced.
//	**
//	** Under Unix, also make sure that the directory entry for the file
//	** has been created by fsync-ing the directory that contains the file.
//	** If we do not do this and we encounter a power failure, the directory
//	** entry for the journal might not exist after we reboot.  The next
//	** SQLite to access the file will not know that the journal exists (because
//	** the directory entry for the journal was never created) and the transaction
//	** will not roll back - possibly leading to database corruption.
//	*/
func _unixSync(tls *libc.TLS, id uintptr, flags int32) (r int32) {
	bp := tls.Alloc(16)
	defer tls.Free(16)
	var isDataOnly, isFullsync, rc int32
	var pFile, v1 uintptr
	var _ /* dirfd at bp+0 */ int32
	_, _, _, _, _ = isDataOnly, isFullsync, pFile, rc, v1
	pFile = id
	isDataOnly = flags & int32(SQLITE_SYNC_DATAONLY)
	isFullsync = libc.BoolInt32(flags&int32(0x0F) == int32(SQLITE_SYNC_FULL))
	/* Check that one of SQLITE_SYNC_NORMAL or FULL was passed */
	/* Unix cannot, but some systems may return SQLITE_FULL from here. This
	 ** line is to test that doing so does not cause any problems.
	 */
	rc = _full_fsync(tls, (*TunixFile)(unsafe.Pointer(pFile)).Fh, isFullsync, isDataOnly)
	if rc != 0 {
		_storeLastErrno(tls, pFile, **(**int32)(__ccgo_up(libc.X__errno(tls))))
		return _unixLogErrorAtLine(tls, libc.Int32FromInt32(SQLITE_IOERR)|libc.Int32FromInt32(4)<<libc.Int32FromInt32(8), __ccgo_ts+3936, (*TunixFile)(unsafe.Pointer(pFile)).FzPath, int32(44131))
	}
	/* Also fsync the directory containing the file if the DIRSYNC flag
	 ** is set.  This is a one-time occurrence.  Many systems (examples: AIX)
	 ** are unable to fsync a directory, so ignore errors on the fsync.
	 */
	if libc.Int32FromUint16((*TunixFile)(unsafe.Pointer(pFile)).FctrlFlags)&int32(UNIXFILE_DIRSYNC) != 0 {
		rc = (*(*func(*libc.TLS, uintptr, uintptr) int32)(unsafe.Pointer(&struct{ uintptr }{_aSyscall[int32(17)].FpCurrent})))(tls, (*TunixFile)(unsafe.Pointer(pFile)).FzPath, bp)
		if rc == SQLITE_OK {
			_full_fsync(tls, **(**int32)(__ccgo_up(bp)), 0, 0)
			_robust_close(tls, pFile, **(**int32)(__ccgo_up(bp)), int32(44145))
		} else {
			rc = SQLITE_OK
		}
		v1 = pFile + 30
		*(*uint16)(unsafe.Pointer(v1)) = uint16(int32(*(*uint16)(unsafe.Pointer(v1))) & ^libc.Int32FromInt32(UNIXFILE_DIRSYNC))
	}
	return rc
}

// C documentation
//
//	/*
//	** Return the name of a directory in which to put temporary files.
//	** If no suitable temporary file directory can be found, return NULL.
//	*/
func _unixTempFileDir(tls *libc.TLS) (r uintptr) {
	bp := tls.Alloc(128)
	defer tls.Free(128)
	var i, v1 uint32
	var zDir uintptr
	var _ /* buf at bp+0 */ Tstat
	_, _, _ = i, zDir, v1
	i = uint32(0)
	zDir = Xsqlite3_temp_directory
	for int32(1) != 0 {
		if zDir != uintptr(0) && (*(*func(*libc.TLS, uintptr, uintptr) int32)(unsafe.Pointer(&struct{ uintptr }{_aSyscall[int32(4)].FpCurrent})))(tls, zDir, bp) == 0 && (**(**Tstat)(__ccgo_up(bp))).Fst_mode&uint32(0170000) == uint32(0040000) && (*(*func(*libc.TLS, uintptr, int32) int32)(unsafe.Pointer(&struct{ uintptr }{_aSyscall[int32(2)].FpCurrent})))(tls, zDir, int32(03)) == 0 {
			return zDir
		}
		if uint64(i) >= libc.Uint64FromInt64(48)/libc.Uint64FromInt64(8) {
			break
		}
		v1 = i
		i = i + 1
		zDir = _azTempDirs[v1]
	}
	return uintptr(0)
}

// C documentation
//
//	/*
//	** Initialize first two members of azTempDirs[] array.
//	*/
func _unixTempFileInit(tls *libc.TLS) {
	_azTempDirs[0] = libc.Xgetenv(tls, __ccgo_ts+4013)
	_azTempDirs[int32(1)] = libc.Xgetenv(tls, __ccgo_ts+4027)
}

// C documentation
//
//	/*
//	** Truncate an open file to a specified size
//	*/
func _unixTruncate(tls *libc.TLS, id uintptr, nByte Ti64) (r int32) {
	var pFile uintptr
	var rc int32
	_, _ = pFile, rc
	pFile = id
	/* If the user has configured a chunk-size for this file, truncate the
	 ** file so that it consists of an integer number of chunks (i.e. the
	 ** actual file size after the operation may be larger than the requested
	 ** size).
	 */
	if (*TunixFile)(unsafe.Pointer(pFile)).FszChunk > 0 {
		nByte = (nByte + int64((*TunixFile)(unsafe.Pointer(pFile)).FszChunk) - int64(1)) / int64((*TunixFile)(unsafe.Pointer(pFile)).FszChunk) * int64((*TunixFile)(unsafe.Pointer(pFile)).FszChunk)
	}
	rc = _robust_ftruncate(tls, (*TunixFile)(unsafe.Pointer(pFile)).Fh, nByte)
	if rc != 0 {
		_storeLastErrno(tls, pFile, **(**int32)(__ccgo_up(libc.X__errno(tls))))
		return _unixLogErrorAtLine(tls, libc.Int32FromInt32(SQLITE_IOERR)|libc.Int32FromInt32(6)<<libc.Int32FromInt32(8), __ccgo_ts+3567, (*TunixFile)(unsafe.Pointer(pFile)).FzPath, int32(44176))
	} else {
		return SQLITE_OK
	}
	return r
}

// C documentation
//
//	/*
//	** The expression object indicated by the second argument is guaranteed
//	** to be a scalar SQL function. If
//	**
//	**   * all function arguments are SQL literals,
//	**   * one of the SQLITE_FUNC_CONSTANT or _SLOCHNG function flags is set, and
//	**   * the SQLITE_FUNC_NEEDCOLL function flag is not set,
//	**
//	** then this routine attempts to invoke the SQL function. Assuming no
//	** error occurs, output parameter (*ppVal) is set to point to a value
//	** object containing the result before returning SQLITE_OK.
//	**
//	** Affinity aff is applied to the result of the function before returning.
//	** If the result is a text value, the sqlite3_value object uses encoding
//	** enc.
//	**
//	** If the conditions above are not met, this function returns SQLITE_OK
//	** and sets (*ppVal) to NULL. Or, if an error occurs, (*ppVal) is set to
//	** NULL and an SQLite error code returned.
//	*/
func _valueFromFunction(tls *libc.TLS, db uintptr, p uintptr, enc Tu8, aff Tu8, ppVal uintptr, pCtx uintptr) (r int32) {
	bp := tls.Alloc(64)
	defer tls.Free(64)
	var apVal, pFunc, pList, pVal uintptr
	var i, nVal, rc int32
	var _ /* ctx at bp+0 */ Tsqlite3_context
	_, _, _, _, _, _, _ = apVal, i, nVal, pFunc, pList, pVal, rc /* Context object for function invocation */
	apVal = uintptr(0)                                           /* Function arguments */
	nVal = 0                                                     /* Number of function arguments */
	pFunc = uintptr(0)                                           /* Function definition */
	pVal = uintptr(0)                                            /* New value */
	rc = SQLITE_OK                                               /* Return code */
	pList = uintptr(0)                                           /* Iterator variable */
	pList = *(*uintptr)(unsafe.Pointer(p + 32))
	if pList != 0 {
		nVal = (*TExprList)(unsafe.Pointer(pList)).FnExpr
	}
	pFunc = _sqlite3FindFunction(tls, db, *(*uintptr)(unsafe.Pointer(p + 8)), nVal, enc, uint8(0))
	if (*TFuncDef)(unsafe.Pointer(pFunc)).FfuncFlags&libc.Uint32FromInt32(libc.Int32FromInt32(SQLITE_FUNC_CONSTANT)|libc.Int32FromInt32(SQLITE_FUNC_SLOCHNG)) == uint32(0) || (*TFuncDef)(unsafe.Pointer(pFunc)).FfuncFlags&libc.Uint32FromInt32(libc.Int32FromInt32(SQLITE_FUNC_NEEDCOLL)|libc.Int32FromInt32(SQLITE_FUNC_RUNONLY)) != uint32(0) {
		return SQLITE_OK
	}
	if pList != 0 {
		apVal = _sqlite3DbMallocZero(tls, db, uint64(uint64(8)*libc.Uint64FromInt32(nVal)))
		if apVal == uintptr(0) {
			rc = int32(SQLITE_NOMEM)
			goto value_from_function_out
		}
		i = 0
		for {
			if !(i < nVal) {
				break
			}
			rc = _sqlite3Stat4ValueFromExpr(tls, (*TValueNewStat4Ctx)(unsafe.Pointer(pCtx)).FpParse, (*(*TExprList_item)(unsafe.Pointer(pList + 8 + uintptr(i)*32))).FpExpr, aff, apVal+uintptr(i)*8)
			if **(**uintptr)(__ccgo_up(apVal + uintptr(i)*8)) == uintptr(0) || rc != SQLITE_OK {
				goto value_from_function_out
			}
			goto _1
		_1:
			;
			i = i + 1
		}
	}
	pVal = _valueNew(tls, db, pCtx)
	if pVal == uintptr(0) {
		rc = int32(SQLITE_NOMEM)
		goto value_from_function_out
	}
	libc.Xmemset(tls, bp, 0, uint64(48))
	(**(**Tsqlite3_context)(__ccgo_up(bp))).FpOut = pVal
	(**(**Tsqlite3_context)(__ccgo_up(bp))).FpFunc = pFunc
	(**(**Tsqlite3_context)(__ccgo_up(bp))).Fenc = (*Tsqlite3)(unsafe.Pointer(db)).Fenc
	(*(*func(*libc.TLS, uintptr, int32, uintptr))(unsafe.Pointer(&struct{ uintptr }{(*TFuncDef)(unsafe.Pointer(pFunc)).FxSFunc})))(tls, bp, nVal, apVal)
	if (**(**Tsqlite3_context)(__ccgo_up(bp))).FisError != 0 {
		rc = (**(**Tsqlite3_context)(__ccgo_up(bp))).FisError
		_sqlite3ErrorMsg(tls, (*TValueNewStat4Ctx)(unsafe.Pointer(pCtx)).FpParse, __ccgo_ts+3933, libc.VaList(bp+56, Xsqlite3_value_text(tls, pVal)))
	} else {
		_sqlite3ValueApplyAffinity(tls, pVal, aff, uint8(SQLITE_UTF8))
		rc = _sqlite3VdbeChangeEncoding(tls, pVal, libc.Int32FromUint8(enc))
		if rc == SQLITE_OK && _sqlite3VdbeMemTooBig(tls, pVal) != 0 {
			rc = int32(SQLITE_TOOBIG)
			(*TParse)(unsafe.Pointer((*TValueNewStat4Ctx)(unsafe.Pointer(pCtx)).FpParse)).FnErr = (*TParse)(unsafe.Pointer((*TValueNewStat4Ctx)(unsafe.Pointer(pCtx)).FpParse)).FnErr + 1
		}
	}
	goto value_from_function_out
value_from_function_out:
	;
	if rc != SQLITE_OK {
		pVal = uintptr(0)
		(*TParse)(unsafe.Pointer((*TValueNewStat4Ctx)(unsafe.Pointer(pCtx)).FpParse)).Frc = rc
	}
	if apVal != 0 {
		i = 0
		for {
			if !(i < nVal) {
				break
			}
			_sqlite3ValueFree(tls, **(**uintptr)(__ccgo_up(apVal + uintptr(i)*8)))
			goto _2
		_2:
			;
			i = i + 1
		}
		_sqlite3DbFreeNN(tls, db, apVal)
	}
	**(**uintptr)(__ccgo_up(ppVal)) = pVal
	return rc
}

// C documentation
//
//	/*
//	** A read or write transaction may or may not be active on database handle
//	** db. If a transaction is active, commit it. If there is a
//	** write-transaction spanning more than one database file, this routine
//	** takes care of the super-journal trickery.
//	*/
func _vdbeCommit(tls *libc.TLS, db uintptr, p uintptr) (r int32) {
	bp := tls.Alloc(48)
	defer tls.Free(48)
	var i, nMainFile, nTrans, needXcommit, rc, retryCount, txn, v5 int32
	var offset Ti64
	var pBt, pBt1, pBt2, pBt3, pBt4, pBt5, pPager, pVfs, zFile, zMainFile, zSuper uintptr
	var v6 bool
	var _ /* iRandom at bp+12 */ Tu32
	var _ /* pSuperJrnl at bp+0 */ uintptr
	var _ /* res at bp+8 */ int32
	_, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _ = i, nMainFile, nTrans, needXcommit, offset, pBt, pBt1, pBt2, pBt3, pBt4, pBt5, pPager, pVfs, rc, retryCount, txn, zFile, zMainFile, zSuper, v5, v6
	nTrans = 0 /* Number of databases with an active write-transaction
	 ** that are candidates for a two-phase commit using a
	 ** super-journal */
	rc = SQLITE_OK
	needXcommit = 0
	/* Before doing anything else, call the xSync() callback for any
	 ** virtual module tables written in this transaction. This has to
	 ** be done before determining whether a super-journal file is
	 ** required, as an xSync() callback may add an attached database
	 ** to the transaction.
	 */
	rc = _sqlite3VtabSync(tls, db, p)
	/* This loop determines (a) if the commit hook should be invoked and
	 ** (b) how many database files have open write transactions, not
	 ** including the temp database. (b) is important because if more than
	 ** one database file has an open write transaction, a super-journal
	 ** file is required for an atomic commit.
	 */
	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)*32))).FpBt
		if _sqlite3BtreeTxnState(tls, pBt) == int32(SQLITE_TXN_WRITE) {
			needXcommit = int32(1)
			_sqlite3BtreeEnter(tls, pBt)
			pPager = _sqlite3BtreePager(tls, pBt)
			if libc.Int32FromUint8((**(**TDb)(__ccgo_up((*Tsqlite3)(unsafe.Pointer(db)).FaDb + uintptr(i)*32))).Fsafety_level) != int32(PAGER_SYNCHRONOUS_OFF) && _aMJNeeded[_sqlite3PagerGetJournalMode(tls, pPager)] != 0 && _sqlite3PagerIsMemdb(tls, pPager) == 0 {
				nTrans = nTrans + 1
			}
			rc = _sqlite3PagerExclusiveLock(tls, pPager)
			_sqlite3BtreeLeave(tls, pBt)
		}
		goto _1
	_1:
		;
		i = i + 1
	}
	if rc != SQLITE_OK {
		return rc
	}
	/* If there are any write-transactions at all, invoke the commit hook */
	if needXcommit != 0 && (*Tsqlite3)(unsafe.Pointer(db)).FxCommitCallback != 0 {
		rc = (*(*func(*libc.TLS, uintptr) int32)(unsafe.Pointer(&struct{ uintptr }{(*Tsqlite3)(unsafe.Pointer(db)).FxCommitCallback})))(tls, (*Tsqlite3)(unsafe.Pointer(db)).FpCommitArg)
		if rc != 0 {
			return libc.Int32FromInt32(SQLITE_CONSTRAINT) | libc.Int32FromInt32(2)<<libc.Int32FromInt32(8)
		}
	}
	/* The simple case - no more than one database file (not counting the
	 ** TEMP database) has a transaction active.   There is no need for the
	 ** super-journal.
	 **
	 ** If the return value of sqlite3BtreeGetFilename() is a zero length
	 ** string, it means the main database is :memory: or a temp file.  In
	 ** that case we do not support atomic multi-file commits, so use the
	 ** simple case then too.
	 */
	if 0 == _sqlite3Strlen30(tls, _sqlite3BtreeGetFilename(tls, (**(**TDb)(__ccgo_up((*Tsqlite3)(unsafe.Pointer(db)).FaDb))).FpBt)) || nTrans <= int32(1) {
		if needXcommit != 0 {
			i = 0
			for {
				if !(rc == SQLITE_OK && i < (*Tsqlite3)(unsafe.Pointer(db)).FnDb) {
					break
				}
				pBt1 = (**(**TDb)(__ccgo_up((*Tsqlite3)(unsafe.Pointer(db)).FaDb + uintptr(i)*32))).FpBt
				if _sqlite3BtreeTxnState(tls, pBt1) >= int32(SQLITE_TXN_WRITE) {
					rc = _sqlite3BtreeCommitPhaseOne(tls, pBt1, uintptr(0))
				}
				goto _2
			_2:
				;
				i = i + 1
			}
		}
		/* Do the commit only if all databases successfully complete phase 1.
		 ** If one of the BtreeCommitPhaseOne() calls fails, this indicates an
		 ** IO error while deleting or truncating a journal file. It is unlikely,
		 ** but could happen. In this case abandon processing and return the error.
		 */
		i = 0
		for {
			if !(rc == SQLITE_OK && i < (*Tsqlite3)(unsafe.Pointer(db)).FnDb) {
				break
			}
			pBt2 = (**(**TDb)(__ccgo_up((*Tsqlite3)(unsafe.Pointer(db)).FaDb + uintptr(i)*32))).FpBt
			txn = _sqlite3BtreeTxnState(tls, pBt2)
			if txn != SQLITE_TXN_NONE {
				rc = _sqlite3BtreeCommitPhaseTwo(tls, pBt2, 0)
			}
			goto _3
		_3:
			;
			i = i + 1
		}
		if rc == SQLITE_OK {
			_sqlite3VtabCommit(tls, db)
		}
	} else {
		pVfs = (*Tsqlite3)(unsafe.Pointer(db)).FpVfs
		zSuper = uintptr(0) /* File-name for the super-journal */
		zMainFile = _sqlite3BtreeGetFilename(tls, (**(**TDb)(__ccgo_up((*Tsqlite3)(unsafe.Pointer(db)).FaDb))).FpBt)
		**(**uintptr)(__ccgo_up(bp)) = uintptr(0)
		offset = 0
		retryCount = 0
		/* Select a super-journal file name */
		nMainFile = _sqlite3Strlen30(tls, zMainFile)
		zSuper = _sqlite3MPrintf(tls, db, __ccgo_ts+5331, libc.VaList(bp+24, 0, zMainFile, 0))
		if zSuper == uintptr(0) {
			return int32(SQLITE_NOMEM)
		}
		zSuper = zSuper + uintptr(4)
		for cond := true; cond; cond = rc == SQLITE_OK && **(**int32)(__ccgo_up(bp + 8)) != 0 {
			if retryCount != 0 {
				if retryCount > int32(100) {
					Xsqlite3_log(tls, int32(SQLITE_FULL), __ccgo_ts+5343, libc.VaList(bp+24, zSuper))
					_sqlite3OsDelete(tls, pVfs, zSuper, 0)
					break
				} else {
					if retryCount == int32(1) {
						Xsqlite3_log(tls, int32(SQLITE_FULL), __ccgo_ts+5357, libc.VaList(bp+24, zSuper))
					}
				}
			}
			retryCount = retryCount + 1
			Xsqlite3_randomness(tls, int32(4), bp+12)
			Xsqlite3_snprintf(tls, int32(13), zSuper+uintptr(nMainFile), __ccgo_ts+5372, libc.VaList(bp+24, **(**Tu32)(__ccgo_up(bp + 12))>>libc.Int32FromInt32(8)&uint32(0xffffff), **(**Tu32)(__ccgo_up(bp + 12))&uint32(0xff)))
			/* The antipenultimate character of the super-journal name must
			 ** be "9" to avoid name collisions when using 8+3 filenames. */
			rc = _sqlite3OsAccess(tls, pVfs, zSuper, SQLITE_ACCESS_EXISTS, bp+8)
		}
		if rc == SQLITE_OK {
			/* Open the super-journal. */
			rc = _sqlite3OsOpenMalloc(tls, pVfs, zSuper, bp, libc.Int32FromInt32(SQLITE_OPEN_READWRITE)|libc.Int32FromInt32(SQLITE_OPEN_CREATE)|libc.Int32FromInt32(SQLITE_OPEN_EXCLUSIVE)|libc.Int32FromInt32(SQLITE_OPEN_SUPER_JOURNAL), uintptr(0))
		}
		if rc != SQLITE_OK {
			_sqlite3DbFree(tls, db, zSuper-uintptr(4))
			return rc
		}
		/* Write the name of each database file in the transaction into the new
		 ** super-journal file. If an error occurs at this point close
		 ** and delete the super-journal file. All the individual journal files
		 ** still have 'null' as the super-journal pointer, so they will roll
		 ** back independently if a failure occurs.
		 */
		i = 0
		for {
			if !(i < (*Tsqlite3)(unsafe.Pointer(db)).FnDb) {
				break
			}
			pBt3 = (**(**TDb)(__ccgo_up((*Tsqlite3)(unsafe.Pointer(db)).FaDb + uintptr(i)*32))).FpBt
			if _sqlite3BtreeTxnState(tls, pBt3) == int32(SQLITE_TXN_WRITE) {
				zFile = _sqlite3BtreeGetJournalname(tls, pBt3)
				if zFile == uintptr(0) {
					goto _4 /* Ignore TEMP and :memory: databases */
				}
				rc = _sqlite3OsWrite(tls, **(**uintptr)(__ccgo_up(bp)), zFile, _sqlite3Strlen30(tls, zFile)+int32(1), offset)
				offset = offset + int64(_sqlite3Strlen30(tls, zFile)+int32(1))
				if rc != SQLITE_OK {
					_sqlite3OsCloseFree(tls, **(**uintptr)(__ccgo_up(bp)))
					_sqlite3OsDelete(tls, pVfs, zSuper, 0)
					_sqlite3DbFree(tls, db, zSuper-uintptr(4))
					return rc
				}
			}
			goto _4
		_4:
			;
			i = i + 1
		}
		/* Sync the super-journal file. If the IOCAP_SEQUENTIAL device
		 ** flag is set this is not required.
		 */
		if v6 = 0 == _sqlite3OsDeviceCharacteristics(tls, **(**uintptr)(__ccgo_up(bp)))&int32(SQLITE_IOCAP_SEQUENTIAL); v6 {
			v5 = _sqlite3OsSync(tls, **(**uintptr)(__ccgo_up(bp)), int32(SQLITE_SYNC_NORMAL))
			rc = v5
		}
		if v6 && SQLITE_OK != v5 {
			_sqlite3OsCloseFree(tls, **(**uintptr)(__ccgo_up(bp)))
			_sqlite3OsDelete(tls, pVfs, zSuper, 0)
			_sqlite3DbFree(tls, db, zSuper-uintptr(4))
			return rc
		}
		/* Sync all the db files involved in the transaction. The same call
		 ** sets the super-journal pointer in each individual journal. If
		 ** an error occurs here, do not delete the super-journal file.
		 **
		 ** If the error occurs during the first call to
		 ** sqlite3BtreeCommitPhaseOne(), then there is a chance that the
		 ** super-journal file will be orphaned. But we cannot delete it,
		 ** in case the super-journal file name was written into the journal
		 ** file before the failure occurred.
		 */
		i = 0
		for {
			if !(rc == SQLITE_OK && i < (*Tsqlite3)(unsafe.Pointer(db)).FnDb) {
				break
			}
			pBt4 = (**(**TDb)(__ccgo_up((*Tsqlite3)(unsafe.Pointer(db)).FaDb + uintptr(i)*32))).FpBt
			if pBt4 != 0 {
				rc = _sqlite3BtreeCommitPhaseOne(tls, pBt4, zSuper)
			}
			goto _7
		_7:
			;
			i = i + 1
		}
		_sqlite3OsCloseFree(tls, **(**uintptr)(__ccgo_up(bp)))
		if rc != SQLITE_OK {
			_sqlite3DbFree(tls, db, zSuper-uintptr(4))
			return rc
		}
		/* Delete the super-journal file. This commits the transaction. After
		 ** doing this the directory is synced again before any individual
		 ** transaction files are deleted.
		 */
		rc = _sqlite3OsDelete(tls, pVfs, zSuper, int32(1))
		_sqlite3DbFree(tls, db, zSuper-uintptr(4))
		zSuper = uintptr(0)
		if rc != 0 {
			return rc
		}
		/* All files and directories have already been synced, so the following
		 ** calls to sqlite3BtreeCommitPhaseTwo() are only closing files and
		 ** deleting or truncating journals. If something goes wrong while
		 ** this is happening we don't really care. The integrity of the
		 ** transaction is already guaranteed, but some stray 'cold' journals
		 ** may be lying around. Returning an error code won't help matters.
		 */
		_sqlite3BeginBenignMalloc(tls)
		i = 0
		for {
			if !(i < (*Tsqlite3)(unsafe.Pointer(db)).FnDb) {
				break
			}
			pBt5 = (**(**TDb)(__ccgo_up((*Tsqlite3)(unsafe.Pointer(db)).FaDb + uintptr(i)*32))).FpBt
			if pBt5 != 0 {
				_sqlite3BtreeCommitPhaseTwo(tls, pBt5, int32(1))
			}
			goto _8
		_8:
			;
			i = i + 1
		}
		_sqlite3EndBenignMalloc(tls)
		_sqlite3VtabCommit(tls, db)
	}
	return rc
}

// C documentation
//
//	/*
//	** These functions are called when a transaction opened by the database
//	** handle associated with the VM passed as an argument is about to be
//	** committed. If there are outstanding foreign key constraint violations
//	** return an error code. Otherwise, SQLITE_OK.
//	**
//	** If there are outstanding FK violations and this function returns
//	** non-zero, set the result of the VM to SQLITE_CONSTRAINT_FOREIGNKEY
//	** and write an error message to it.
//	*/
func _vdbeFkError(tls *libc.TLS, p uintptr) (r int32) {
	(*TVdbe)(unsafe.Pointer(p)).Frc = libc.Int32FromInt32(SQLITE_CONSTRAINT) | libc.Int32FromInt32(3)<<libc.Int32FromInt32(8)
	(*TVdbe)(unsafe.Pointer(p)).FerrorAction = uint8(OE_Abort)
	_sqlite3VdbeError(tls, p, __ccgo_ts+5385, 0)
	if libc.Int32FromUint8((*TVdbe)(unsafe.Pointer(p)).FprepFlags)&int32(SQLITE_PREPARE_SAVESQL) == 0 {
		return int32(SQLITE_ERROR)
	}
	return libc.Int32FromInt32(SQLITE_CONSTRAINT) | libc.Int32FromInt32(3)<<libc.Int32FromInt32(8)
}

// C documentation
//
//	/*
//	** Check on a Vdbe to make sure it has not been finalized.  Log
//	** an error and return true if it has been finalized (or is otherwise
//	** invalid).  Return false if it is ok.
//	*/
func _vdbeSafety(tls *libc.TLS, p uintptr) (r int32) {
	if (*TVdbe)(unsafe.Pointer(p)).Fdb == uintptr(0) {
		Xsqlite3_log(tls, int32(SQLITE_MISUSE), __ccgo_ts+5498, 0)
		return int32(1)
	} else {
		return 0
	}
	return r
}

func _vdbeSafetyNotNull(tls *libc.TLS, p uintptr) (r int32) {
	if p == uintptr(0) {
		Xsqlite3_log(tls, int32(SQLITE_MISUSE), __ccgo_ts+5543, 0)
		return int32(1)
	} else {
		return _vdbeSafety(tls, p)
	}
	return r
}

// C documentation
//
//	/*
//	** Allocate space for a file-handle and open a temporary file. If successful,
//	** set *ppFd to point to the malloc'd file-handle and return SQLITE_OK.
//	** Otherwise, set *ppFd to 0 and return an SQLite error code.
//	*/
func _vdbeSorterOpenTempFile(tls *libc.TLS, db uintptr, nExtend Ti64, ppFd uintptr) (r int32) {
	bp := tls.Alloc(16)
	defer tls.Free(16)
	var _ /* max at bp+8 */ Ti64
	var _ /* rc at bp+0 */ int32
	if _sqlite3FaultSim(tls, int32(202)) != 0 {
		return libc.Int32FromInt32(SQLITE_IOERR) | libc.Int32FromInt32(13)<<libc.Int32FromInt32(8)
	}
	**(**int32)(__ccgo_up(bp)) = _sqlite3OsOpenMalloc(tls, (*Tsqlite3)(unsafe.Pointer(db)).FpVfs, uintptr(0), ppFd, libc.Int32FromInt32(SQLITE_OPEN_TEMP_JOURNAL)|libc.Int32FromInt32(SQLITE_OPEN_READWRITE)|libc.Int32FromInt32(SQLITE_OPEN_CREATE)|libc.Int32FromInt32(SQLITE_OPEN_EXCLUSIVE)|libc.Int32FromInt32(SQLITE_OPEN_DELETEONCLOSE), bp)
	if **(**int32)(__ccgo_up(bp)) == SQLITE_OK {
		**(**Ti64)(__ccgo_up(bp + 8)) = 0
		_sqlite3OsFileControlHint(tls, **(**uintptr)(__ccgo_up(ppFd)), int32(SQLITE_FCNTL_MMAP_SIZE), bp+8)
		if nExtend > 0 {
		}
	}
	return **(**int32)(__ccgo_up(bp))
}

// C documentation
//
//	/******************************* sqlite3_bind_  ***************************
//	**
//	** Routines used to attach values to wildcards in a compiled SQL statement.
//	*/
//	/*
//	** Unbind the value bound to variable i in virtual machine p. This is the
//	** the same as binding a NULL value to the column. If the "i" parameter is
//	** out of range, then SQLITE_RANGE is returned. Otherwise SQLITE_OK.
//	**
//	** A successful evaluation of this routine acquires the mutex on p.
//	** the mutex is released if any kind of error occurs.
//	**
//	** The error code stored in database p->db is overwritten with the return
//	** value in any case.
//	**
//	** (tag-20240917-01) If  vdbeUnbind(p,(u32)(i-1))  returns SQLITE_OK,
//	** that means all of the the following will be true:
//	**
//	**     p!=0
//	**     p->pVar!=0
//	**     i>0
//	**     i<=p->nVar
//	**
//	** An assert() is normally added after vdbeUnbind() to help static analyzers
//	** realize this.
//	*/
func _vdbeUnbind(tls *libc.TLS, p uintptr, i uint32) (r int32) {
	bp := tls.Alloc(16)
	defer tls.Free(16)
	var pVar uintptr
	var v1 uint32
	var v2 bool
	_, _, _ = pVar, v1, v2
	if _vdbeSafetyNotNull(tls, p) != 0 {
		return _sqlite3MisuseError(tls, int32(95346))
	}
	Xsqlite3_mutex_enter(tls, (*Tsqlite3)(unsafe.Pointer((*TVdbe)(unsafe.Pointer(p)).Fdb)).Fmutex)
	if libc.Int32FromUint8((*TVdbe)(unsafe.Pointer(p)).FeVdbeState) != int32(VDBE_READY_STATE) {
		_sqlite3Error(tls, (*TVdbe)(unsafe.Pointer(p)).Fdb, _sqlite3MisuseError(tls, int32(95350)))
		Xsqlite3_mutex_leave(tls, (*Tsqlite3)(unsafe.Pointer((*TVdbe)(unsafe.Pointer(p)).Fdb)).Fmutex)
		Xsqlite3_log(tls, int32(SQLITE_MISUSE), __ccgo_ts+5666, libc.VaList(bp+8, (*TVdbe)(unsafe.Pointer(p)).FzSql))
		return _sqlite3MisuseError(tls, int32(95354))
	}
	if i >= libc.Uint32FromInt16((*TVdbe)(unsafe.Pointer(p)).FnVar) {
		_sqlite3Error(tls, (*TVdbe)(unsafe.Pointer(p)).Fdb, int32(SQLITE_RANGE))
		Xsqlite3_mutex_leave(tls, (*Tsqlite3)(unsafe.Pointer((*TVdbe)(unsafe.Pointer(p)).Fdb)).Fmutex)
		return int32(SQLITE_RANGE)
	}
	pVar = (*TVdbe)(unsafe.Pointer(p)).FaVar + uintptr(i)*56
	_sqlite3VdbeMemRelease(tls, pVar)
	(*TMem)(unsafe.Pointer(pVar)).Fflags = uint16(MEM_Null)
	(*Tsqlite3)(unsafe.Pointer((*TVdbe)(unsafe.Pointer(p)).Fdb)).FerrCode = SQLITE_OK
	/* If the bit corresponding to this variable in Vdbe.expmask is set, then
	 ** binding a new value to this variable invalidates the current query plan.
	 **
	 ** IMPLEMENTATION-OF: R-57496-20354 If the specific value bound to a host
	 ** parameter in the WHERE clause might influence the choice of query plan
	 ** for a statement, then the statement will be automatically recompiled,
	 ** as if there had been a schema change, on the first sqlite3_step() call
	 ** following any change to the bindings of that parameter.
	 */
	if v2 = (*TVdbe)(unsafe.Pointer(p)).Fexpmask != uint32(0); v2 {
		if i >= uint32(31) {
			v1 = uint32(0x80000000)
		} else {
			v1 = libc.Uint32FromInt32(1) << i
		}
	}
	if v2 && (*TVdbe)(unsafe.Pointer(p)).Fexpmask&v1 != uint32(0) {
		libc.SetBitFieldPtr16Uint32(p+200, libc.Uint32FromInt32(1), 0, 0x3)
	}
	return SQLITE_OK
}

// C documentation
//
//	/*
//	** Check a unixFile that is a database.  Verify the following:
//	**
//	** (1) There is exactly one hard link on the file
//	** (2) The file is not a symbolic link
//	** (3) The file has not been renamed or unlinked
//	**
//	** Issue sqlite3_log(SQLITE_WARNING,...) messages if anything is not right.
//	*/
func _verifyDbFile(tls *libc.TLS, pFile uintptr) {
	bp := tls.Alloc(144)
	defer tls.Free(144)
	var rc int32
	var _ /* buf at bp+0 */ Tstat
	_ = rc
	/* These verifications occurs for the main database only */
	if libc.Int32FromUint16((*TunixFile)(unsafe.Pointer(pFile)).FctrlFlags)&int32(UNIXFILE_NOLOCK) != 0 {
		return
	}
	rc = (*(*func(*libc.TLS, int32, uintptr) int32)(unsafe.Pointer(&struct{ uintptr }{_aSyscall[int32(5)].FpCurrent})))(tls, (*TunixFile)(unsafe.Pointer(pFile)).Fh, bp)
	if rc != 0 {
		Xsqlite3_log(tls, int32(SQLITE_WARNING), __ccgo_ts+3825, libc.VaList(bp+136, (*TunixFile)(unsafe.Pointer(pFile)).FzPath))
		return
	}
	if (**(**Tstat)(__ccgo_up(bp))).Fst_nlink == uint32(0) {
		Xsqlite3_log(tls, int32(SQLITE_WARNING), __ccgo_ts+3849, libc.VaList(bp+136, (*TunixFile)(unsafe.Pointer(pFile)).FzPath))
		return
	}
	if (**(**Tstat)(__ccgo_up(bp))).Fst_nlink > uint32(1) {
		Xsqlite3_log(tls, int32(SQLITE_WARNING), __ccgo_ts+3878, libc.VaList(bp+136, (*TunixFile)(unsafe.Pointer(pFile)).FzPath))
		return
	}
	if _fileHasMoved(tls, pFile) != 0 {
		Xsqlite3_log(tls, int32(SQLITE_WARNING), __ccgo_ts+3905, libc.VaList(bp+136, (*TunixFile)(unsafe.Pointer(pFile)).FzPath))
		return
	}
}

// C documentation
//
//	/*
//	** The table object reference passed as the second argument to this function
//	** must represent a virtual table. This function invokes the xBestIndex()
//	** method of the virtual table with the sqlite3_index_info object that
//	** comes in as the 3rd argument to this function.
//	**
//	** If an error occurs, pParse is populated with an error message and an
//	** appropriate error code is returned.  A return of SQLITE_CONSTRAINT from
//	** xBestIndex is not considered an error.  SQLITE_CONSTRAINT indicates that
//	** the current configuration of "unusable" flags in sqlite3_index_info can
//	** not result in a valid plan.
//	**
//	** Whether or not an error is returned, it is the responsibility of the
//	** caller to eventually free p->idxStr if p->needToFreeIdxStr indicates
//	** that this is required.
//	*/
func _vtabBestIndex(tls *libc.TLS, pParse uintptr, pTab uintptr, p uintptr) (r int32) {
	bp := tls.Alloc(16)
	defer tls.Free(16)
	var pVtab uintptr
	var rc int32
	_, _ = pVtab, rc
	pVtab = (*TVTable)(unsafe.Pointer(_sqlite3GetVTable(tls, (*TParse)(unsafe.Pointer(pParse)).Fdb, pTab))).FpVtab
	(*Tsqlite3)(unsafe.Pointer((*TParse)(unsafe.Pointer(pParse)).Fdb)).FnSchemaLock = (*Tsqlite3)(unsafe.Pointer((*TParse)(unsafe.Pointer(pParse)).Fdb)).FnSchemaLock + 1
	rc = (*(*func(*libc.TLS, uintptr, uintptr) int32)(unsafe.Pointer(&struct{ uintptr }{(*Tsqlite3_module)(unsafe.Pointer((*Tsqlite3_vtab)(unsafe.Pointer(pVtab)).FpModule)).FxBestIndex})))(tls, pVtab, p)
	(*Tsqlite3)(unsafe.Pointer((*TParse)(unsafe.Pointer(pParse)).Fdb)).FnSchemaLock = (*Tsqlite3)(unsafe.Pointer((*TParse)(unsafe.Pointer(pParse)).Fdb)).FnSchemaLock - 1
	if rc != SQLITE_OK && rc != int32(SQLITE_CONSTRAINT) {
		if rc == int32(SQLITE_NOMEM) {
			_sqlite3OomFault(tls, (*TParse)(unsafe.Pointer(pParse)).Fdb)
		} else {
			if !((*Tsqlite3_vtab)(unsafe.Pointer(pVtab)).FzErrMsg != 0) {
				_sqlite3ErrorMsg(tls, pParse, __ccgo_ts+3933, libc.VaList(bp+8, _sqlite3ErrStr(tls, rc)))
			} else {
				_sqlite3ErrorMsg(tls, pParse, __ccgo_ts+3933, libc.VaList(bp+8, (*Tsqlite3_vtab)(unsafe.Pointer(pVtab)).FzErrMsg))
			}
		}
	}
	if (*TVTable)(unsafe.Pointer((*(*struct {
		FnArg  int32
		FazArg uintptr
		Fp     uintptr
	})(unsafe.Pointer(pTab + 64))).Fp)).FbAllSchemas != 0 {
		_sqlite3VtabUsesAllSchemas(tls, pParse)
	}
	Xsqlite3_free(tls, (*Tsqlite3_vtab)(unsafe.Pointer(pVtab)).FzErrMsg)
	(*Tsqlite3_vtab)(unsafe.Pointer(pVtab)).FzErrMsg = uintptr(0)
	return rc
}

// C documentation
//
//	/* Return true if table pTab is read-only.
//	**
//	** A table is read-only if any of the following are true:
//	**
//	**   1) It is a virtual table and no implementation of the xUpdate method
//	**      has been provided
//	**
//	**   2) A trigger is currently being coded and the table is a virtual table
//	**      that is SQLITE_VTAB_DIRECTONLY or if PRAGMA trusted_schema=OFF and
//	**      the table is not SQLITE_VTAB_INNOCUOUS.
//	**
//	**   3) It is a system table (i.e. sqlite_schema), this call is not
//	**      part of a nested parse and writable_schema pragma has not
//	**      been specified
//	**
//	**   4) The table is a shadow table, the database connection is in
//	**      defensive mode, and the current sqlite3_prepare()
//	**      is for a top-level SQL statement.
//	*/
func _vtabIsReadOnly(tls *libc.TLS, pParse uintptr, pTab uintptr) (r int32) {
	bp := tls.Alloc(16)
	defer tls.Free(16)
	if (*Tsqlite3_module)(unsafe.Pointer((*TModule)(unsafe.Pointer((*TVTable)(unsafe.Pointer(_sqlite3GetVTable(tls, (*TParse)(unsafe.Pointer(pParse)).Fdb, pTab))).FpMod)).FpModule)).FxUpdate == uintptr(0) {
		return int32(1)
	}
	/* Within triggers:
	 **   *  Do not allow DELETE, INSERT, or UPDATE of SQLITE_VTAB_DIRECTONLY
	 **      virtual tables
	 **   *  Only allow DELETE, INSERT, or UPDATE of non-SQLITE_VTAB_INNOCUOUS
	 **      virtual tables if PRAGMA trusted_schema=ON.
	 */
	if ((*TParse)(unsafe.Pointer(pParse)).FpToplevel != uintptr(0) || libc.Int32FromUint8((*TParse)(unsafe.Pointer(pParse)).FprepFlags)&int32(SQLITE_PREPARE_FROM_DDL) != 0) && libc.Int32FromUint8((*TVTable)(unsafe.Pointer((*(*struct {
		FnArg  int32
		FazArg uintptr
		Fp     uintptr
	})(unsafe.Pointer(pTab + 64))).Fp)).FeVtabRisk) > libc.BoolInt32((*Tsqlite3)(unsafe.Pointer((*TParse)(unsafe.Pointer(pParse)).Fdb)).Fflags&uint64(SQLITE_TrustedSchema) != uint64(0)) {
		_sqlite3ErrorMsg(tls, pParse, __ccgo_ts+16338, libc.VaList(bp+8, (*TTable)(unsafe.Pointer(pTab)).FzName))
	}
	return 0
}

// C documentation
//
//	/*
//	** Recover the wal-index by reading the write-ahead log file.
//	**
//	** This routine first tries to establish an exclusive lock on the
//	** wal-index to prevent other threads/processes from doing anything
//	** with the WAL or wal-index while recovery is running.  The
//	** WAL_RECOVER_LOCK is also held so that other threads will know
//	** that this thread is running recovery.  If unable to establish
//	** the necessary locks, this routine returns SQLITE_BUSY.
//	*/
func _walIndexRecover(tls *libc.TLS, pWal uintptr) (r int32) {
	bp := tls.Alloc(80)
	defer tls.Free(80)
	var aData, aFrame, aPrivate, pInfo uintptr
	var aFrameCksum [2]Tu32
	var i, iLock, isValid, rc, szFrame, szPage int32
	var iFirst, iFrame, iLast, iLastFrame, iPg, magic, nHdr, nHdr32, version Tu32
	var iOffset Ti64
	var v2, v3 uint64
	var _ /* aBuf at bp+8 */ [32]Tu8
	var _ /* aShare at bp+40 */ uintptr
	var _ /* nSize at bp+0 */ Ti64
	var _ /* nTruncate at bp+52 */ Tu32
	var _ /* pgno at bp+48 */ Tu32
	_, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _ = aData, aFrame, aFrameCksum, aPrivate, i, iFirst, iFrame, iLast, iLastFrame, iLock, iOffset, iPg, isValid, magic, nHdr, nHdr32, pInfo, rc, szFrame, szPage, version, v2, v3 /* Size of log file */
	aFrameCksum = [2]Tu32{}                                                                                                                                                                                                                          /* Lock offset to lock for checkpoint */
	/* Obtain an exclusive lock on all byte in the locking range not already
	 ** locked by the caller. The caller is guaranteed to have locked the
	 ** WAL_WRITE_LOCK byte, and may have also locked the WAL_CKPT_LOCK byte.
	 ** If successful, the same bytes that are locked here are unlocked before
	 ** this function returns.
	 */
	iLock = int32(WAL_ALL_BUT_WRITE) + libc.Int32FromUint8((*TWal)(unsafe.Pointer(pWal)).FckptLock)
	rc = _walLockExclusive(tls, pWal, iLock, libc.Int32FromInt32(3)+libc.Int32FromInt32(0)-iLock)
	if rc != 0 {
		return rc
	}
	libc.Xmemset(tls, pWal+72, 0, uint64(48))
	rc = _sqlite3OsFileSize(tls, (*TWal)(unsafe.Pointer(pWal)).FpWalFd, bp)
	if rc != SQLITE_OK {
		goto recovery_error
	}
	if **(**Ti64)(__ccgo_up(bp)) > int64(WAL_HDRSIZE) { /* Buffer to load WAL header into */
		aPrivate = uintptr(0) /* Heap copy of *-shm hash being populated */
		aFrame = uintptr(0)   /* Last frame in wal, based on nSize alone */
		/* Read in the WAL header. */
		rc = _sqlite3OsRead(tls, (*TWal)(unsafe.Pointer(pWal)).FpWalFd, bp+8, int32(WAL_HDRSIZE), 0)
		if rc != SQLITE_OK {
			goto recovery_error
		}
		/* If the database page size is not a power of two, or is greater than
		 ** SQLITE_MAX_PAGE_SIZE, conclude that the WAL file contains no valid
		 ** data. Similarly, if the 'magic' value is invalid, ignore the whole
		 ** WAL file.
		 */
		magic = _sqlite3Get4byte(tls, bp+8)
		szPage = libc.Int32FromUint32(_sqlite3Get4byte(tls, bp+8+8))
		if magic&uint32(0xFFFFFFFE) != uint32(WAL_MAGIC) || szPage&(szPage-int32(1)) != 0 || szPage > int32(SQLITE_MAX_PAGE_SIZE) || szPage < int32(512) {
			goto finished
		}
		(*TWal)(unsafe.Pointer(pWal)).Fhdr.FbigEndCksum = uint8(magic & libc.Uint32FromInt32(0x00000001))
		(*TWal)(unsafe.Pointer(pWal)).FszPage = libc.Uint32FromInt32(szPage)
		(*TWal)(unsafe.Pointer(pWal)).FnCkpt = _sqlite3Get4byte(tls, bp+8+12)
		libc.Xmemcpy(tls, pWal+72+32, bp+8+16, uint64(8))
		/* Verify that the WAL header checksum is correct */
		_walChecksumBytes(tls, libc.BoolInt32(libc.Int32FromUint8((*TWal)(unsafe.Pointer(pWal)).Fhdr.FbigEndCksum) == SQLITE_BIGENDIAN), bp+8, libc.Int32FromInt32(WAL_HDRSIZE)-libc.Int32FromInt32(2)*libc.Int32FromInt32(4), uintptr(0), pWal+72+24)
		if **(**Tu32)(__ccgo_up(pWal + 72 + 24)) != _sqlite3Get4byte(tls, bp+8+24) || **(**Tu32)(__ccgo_up(pWal + 72 + 24 + 1*4)) != _sqlite3Get4byte(tls, bp+8+28) {
			goto finished
		}
		/* Verify that the version number on the WAL format is one that
		 ** are able to understand */
		version = _sqlite3Get4byte(tls, bp+8+4)
		if version != uint32(WAL_MAX_VERSION) {
			rc = _sqlite3CantopenError(tls, int32(68992))
			goto finished
		}
		/* Malloc a buffer to read frames into. */
		szFrame = szPage + int32(WAL_FRAME_HDRSIZE)
		aFrame = Xsqlite3_malloc64(tls, uint64(libc.Uint64FromInt32(szFrame)+(libc.Uint64FromInt64(2)*libc.Uint64FromInt32(libc.Int32FromInt32(HASHTABLE_NPAGE)*libc.Int32FromInt32(2))+libc.Uint64FromInt32(HASHTABLE_NPAGE)*libc.Uint64FromInt64(4))))
		if !(aFrame != 0) {
			rc = int32(SQLITE_NOMEM)
			goto recovery_error
		}
		aData = aFrame + 24
		aPrivate = aData + uintptr(szPage)
		/* Read all frames from the log file. */
		iLastFrame = libc.Uint32FromInt64((**(**Ti64)(__ccgo_up(bp)) - int64(WAL_HDRSIZE)) / int64(szFrame))
		iPg = uint32(0)
		for {
			if !(iPg <= libc.Uint32FromInt32(_walFramePage(tls, iLastFrame))) {
				break
			}
			if uint64(iLastFrame) < libc.Uint64FromInt32(HASHTABLE_NPAGE)-(libc.Uint64FromInt64(48)*libc.Uint64FromInt32(2)+libc.Uint64FromInt64(40))/libc.Uint64FromInt64(4)+uint64(iPg*uint32(HASHTABLE_NPAGE)) {
				v2 = uint64(iLastFrame)
			} else {
				v2 = libc.Uint64FromInt32(HASHTABLE_NPAGE) - (libc.Uint64FromInt64(48)*libc.Uint64FromInt32(2)+libc.Uint64FromInt64(40))/libc.Uint64FromInt64(4) + uint64(iPg*uint32(HASHTABLE_NPAGE))
			} /* Index of last frame read */
			iLast = uint32(v2)
			if iPg == uint32(0) {
				v3 = uint64(0)
			} else {
				v3 = libc.Uint64FromInt32(HASHTABLE_NPAGE) - (libc.Uint64FromInt64(48)*libc.Uint64FromInt32(2)+libc.Uint64FromInt64(40))/libc.Uint64FromInt64(4) + uint64((iPg-uint32(1))*uint32(HASHTABLE_NPAGE))
			}
			iFirst = uint32(uint64(1) + v3)
			rc = _walIndexPage(tls, pWal, libc.Int32FromUint32(iPg), bp+40)
			if **(**uintptr)(__ccgo_up(bp + 40)) == uintptr(0) {
				break
			}
			**(**uintptr)(__ccgo_up((*TWal)(unsafe.Pointer(pWal)).FapWiData + uintptr(iPg)*8)) = aPrivate
			iFrame = iFirst
			for {
				if !(iFrame <= iLast) {
					break
				}
				iOffset = libc.Int64FromInt32(WAL_HDRSIZE) + libc.Int64FromUint32(iFrame-libc.Uint32FromInt32(1))*int64(szPage+libc.Int32FromInt32(WAL_FRAME_HDRSIZE)) /* dbsize field from frame header */
				/* Read and decode the next log frame. */
				rc = _sqlite3OsRead(tls, (*TWal)(unsafe.Pointer(pWal)).FpWalFd, aFrame, szFrame, iOffset)
				if rc != SQLITE_OK {
					break
				}
				isValid = _walDecodeFrame(tls, pWal, bp+48, bp+52, aData, aFrame)
				if !(isValid != 0) {
					break
				}
				rc = _walIndexAppend(tls, pWal, iFrame, **(**Tu32)(__ccgo_up(bp + 48)))
				if rc != SQLITE_OK {
					break
				}
				/* If nTruncate is non-zero, this is a commit record. */
				if **(**Tu32)(__ccgo_up(bp + 52)) != 0 {
					(*TWal)(unsafe.Pointer(pWal)).Fhdr.FmxFrame = iFrame
					(*TWal)(unsafe.Pointer(pWal)).Fhdr.FnPage = **(**Tu32)(__ccgo_up(bp + 52))
					(*TWal)(unsafe.Pointer(pWal)).Fhdr.FszPage = libc.Uint16FromInt32(szPage&libc.Int32FromInt32(0xff00) | szPage>>libc.Int32FromInt32(16))
					aFrameCksum[0] = **(**Tu32)(__ccgo_up(pWal + 72 + 24))
					aFrameCksum[int32(1)] = **(**Tu32)(__ccgo_up(pWal + 72 + 24 + 1*4))
				}
				goto _4
			_4:
				;
				iFrame = iFrame + 1
			}
			**(**uintptr)(__ccgo_up((*TWal)(unsafe.Pointer(pWal)).FapWiData + uintptr(iPg)*8)) = **(**uintptr)(__ccgo_up(bp + 40))
			if iPg == uint32(0) {
				v2 = libc.Uint64FromInt64(48)*libc.Uint64FromInt32(2) + libc.Uint64FromInt64(40)
			} else {
				v2 = uint64(0)
			}
			nHdr = uint32(v2)
			nHdr32 = uint32(uint64(nHdr) / uint64(4))
			/* Memcpy() should work fine here, on all reasonable implementations.
			 ** Technically, memcpy() might change the destination to some
			 ** intermediate value before setting to the final value, and that might
			 ** cause a concurrent reader to malfunction.  Memcpy() is allowed to
			 ** do that, according to the spec, but no memcpy() implementation that
			 ** we know of actually does that, which is why we say that memcpy()
			 ** is safe for this.  Memcpy() is certainly a lot faster.
			 */
			libc.Xmemcpy(tls, **(**uintptr)(__ccgo_up(bp + 40))+uintptr(nHdr32)*4, aPrivate+uintptr(nHdr32)*4, libc.Uint64FromInt64(2)*libc.Uint64FromInt32(libc.Int32FromInt32(HASHTABLE_NPAGE)*libc.Int32FromInt32(2))+libc.Uint64FromInt32(HASHTABLE_NPAGE)*libc.Uint64FromInt64(4)-uint64(nHdr))
			if iFrame <= iLast {
				break
			}
			goto _1
		_1:
			;
			iPg = iPg + 1
		}
		Xsqlite3_free(tls, aFrame)
	}
	goto finished
finished:
	;
	if rc == SQLITE_OK {
		**(**Tu32)(__ccgo_up(pWal + 72 + 24)) = aFrameCksum[0]
		**(**Tu32)(__ccgo_up(pWal + 72 + 24 + 1*4)) = aFrameCksum[int32(1)]
		_walIndexWriteHdr(tls, pWal)
		/* Reset the checkpoint-header. This is safe because this thread is
		 ** currently holding locks that exclude all other writers and
		 ** checkpointers. Then set the values of read-mark slots 1 through N.
		 */
		pInfo = _walCkptInfo(tls, pWal)
		(*TWalCkptInfo)(unsafe.Pointer(pInfo)).FnBackfill = uint32(0)
		(*TWalCkptInfo)(unsafe.Pointer(pInfo)).FnBackfillAttempted = (*TWal)(unsafe.Pointer(pWal)).Fhdr.FmxFrame
		**(**Tu32)(__ccgo_up(pInfo + 4)) = uint32(0)
		i = int32(1)
		for {
			if !(i < libc.Int32FromInt32(SQLITE_SHM_NLOCK)-libc.Int32FromInt32(3)) {
				break
			}
			rc = _walLockExclusive(tls, pWal, int32(3)+i, int32(1))
			if rc == SQLITE_OK {
				if i == int32(1) && (*TWal)(unsafe.Pointer(pWal)).Fhdr.FmxFrame != 0 {
					**(**Tu32)(__ccgo_up(pInfo + 4 + uintptr(i)*4)) = (*TWal)(unsafe.Pointer(pWal)).Fhdr.FmxFrame
				} else {
					**(**Tu32)(__ccgo_up(pInfo + 4 + uintptr(i)*4)) = uint32(READMARK_NOT_USED)
				}
				_walUnlockExclusive(tls, pWal, int32(3)+i, int32(1))
			} else {
				if rc != int32(SQLITE_BUSY) {
					goto recovery_error
				}
			}
			goto _6
		_6:
			;
			i = i + 1
		}
		/* If more than one frame was recovered from the log file, report an
		 ** event via sqlite3_log(). This is to help with identifying performance
		 ** problems caused by applications routinely shutting down without
		 ** checkpointing the log file.
		 */
		if (*TWal)(unsafe.Pointer(pWal)).Fhdr.FnPage != 0 {
			Xsqlite3_log(tls, libc.Int32FromInt32(SQLITE_NOTICE)|libc.Int32FromInt32(1)<<libc.Int32FromInt32(8), __ccgo_ts+4269, libc.VaList(bp+64, (*TWal)(unsafe.Pointer(pWal)).Fhdr.FmxFrame, (*TWal)(unsafe.Pointer(pWal)).FzWalName))
		}
	}
	goto recovery_error
recovery_error:
	;
	_walUnlockExclusive(tls, pWal, iLock, libc.Int32FromInt32(3)+libc.Int32FromInt32(0)-iLock)
	return rc
}

// C documentation
//
//	/*
//	** If the WAL file is currently larger than nMax bytes in size, truncate
//	** it to exactly nMax bytes. If an error occurs while doing so, ignore it.
//	*/
func _walLimitSize(tls *libc.TLS, pWal uintptr, nMax Ti64) {
	bp := tls.Alloc(32)
	defer tls.Free(32)
	var rx int32
	var _ /* sz at bp+0 */ Ti64
	_ = rx
	_sqlite3BeginBenignMalloc(tls)
	rx = _sqlite3OsFileSize(tls, (*TWal)(unsafe.Pointer(pWal)).FpWalFd, bp)
	if rx == SQLITE_OK && **(**Ti64)(__ccgo_up(bp)) > nMax {
		rx = _sqlite3OsTruncate(tls, (*TWal)(unsafe.Pointer(pWal)).FpWalFd, nMax)
	}
	_sqlite3EndBenignMalloc(tls)
	if rx != 0 {
		Xsqlite3_log(tls, rx, __ccgo_ts+4306, libc.VaList(bp+16, (*TWal)(unsafe.Pointer(pWal)).FzWalName))
	}
}

// C documentation
//
//	/*
//	** Add all WhereLoop objects for all tables
//	*/
func _whereLoopAddAll(tls *libc.TLS, pBuilder uintptr) (r int32) {
	var bFirstPastRJ, hasRightCrossJoin, i, iTab, rc int32
	var db, p, pEnd, pItem, pNew, pTabList, pTerm, pWC, pWInfo uintptr
	var mPrereq, mPrior, mUnusable TBitmask
	_, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _ = bFirstPastRJ, db, hasRightCrossJoin, i, iTab, mPrereq, mPrior, mUnusable, p, pEnd, pItem, pNew, pTabList, pTerm, pWC, pWInfo, rc
	pWInfo = (*TWhereLoopBuilder)(unsafe.Pointer(pBuilder)).FpWInfo
	mPrereq = uint64(0)
	mPrior = uint64(0)
	pTabList = (*TWhereInfo)(unsafe.Pointer(pWInfo)).FpTabList
	pEnd = pTabList + 8 + uintptr((*TWhereInfo)(unsafe.Pointer(pWInfo)).FnLevel)*80
	db = (*TParse)(unsafe.Pointer((*TWhereInfo)(unsafe.Pointer(pWInfo)).FpParse)).Fdb
	rc = SQLITE_OK
	bFirstPastRJ = 0
	hasRightCrossJoin = 0
	/* Loop over the tables in the join, from left to right */
	pNew = (*TWhereLoopBuilder)(unsafe.Pointer(pBuilder)).FpNew
	/* Verify that pNew has already been initialized */
	(*TWhereLoopBuilder)(unsafe.Pointer(pBuilder)).FiPlanLimit = uint32(SQLITE_QUERY_PLANNER_LIMIT)
	iTab = 0
	pItem = pTabList + 8
	for {
		if !(pItem < pEnd) {
			break
		}
		mUnusable = uint64(0)
		(*TWhereLoop)(unsafe.Pointer(pNew)).FiTab = libc.Uint8FromInt32(iTab)
		**(**uint32)(__ccgo_up(pBuilder + 48)) += uint32(SQLITE_QUERY_PLANNER_LIMIT_INCR)
		(*TWhereLoop)(unsafe.Pointer(pNew)).FmaskSelf = _sqlite3WhereGetMask(tls, pWInfo+592, (*TSrcItem)(unsafe.Pointer(pItem)).FiCursor)
		if bFirstPastRJ != 0 || libc.Int32FromUint8((*TSrcItem)(unsafe.Pointer(pItem)).Ffg.Fjointype)&(libc.Int32FromInt32(JT_OUTER)|libc.Int32FromInt32(JT_CROSS)|libc.Int32FromInt32(JT_LTORJ)) != 0 {
			/* Add prerequisites to prevent reordering of FROM clause terms
			 ** across CROSS joins and outer joins.  The bFirstPastRJ boolean
			 ** prevents the right operand of a RIGHT JOIN from being swapped with
			 ** other elements even further to the right.
			 **
			 ** The hasRightCrossJoin flag prevent FROM-clause terms from moving
			 ** from the right side of a LEFT JOIN or CROSS JOIN over to the
			 ** left side of that same join.  This is a required restriction in
			 ** the case of LEFT JOIN - an incorrect answer may results if it is
			 ** not enforced.  This restriction is not required for CROSS JOIN.
			 ** It is provided merely as a means of controlling join order, under
			 ** the theory that no real-world queries that care about performance
			 ** actually use the CROSS JOIN syntax.
			 */
			if libc.Int32FromUint8((*TSrcItem)(unsafe.Pointer(pItem)).Ffg.Fjointype)&(libc.Int32FromInt32(JT_LTORJ)|libc.Int32FromInt32(JT_CROSS)) != 0 {
				hasRightCrossJoin = int32(1)
			}
			mPrereq = mPrereq | mPrior
			bFirstPastRJ = libc.BoolInt32(libc.Int32FromUint8((*TSrcItem)(unsafe.Pointer(pItem)).Ffg.Fjointype)&int32(JT_RIGHT) != 0)
		} else {
			if int32(*(*uint32)(unsafe.Pointer(pItem + 24 + 4))&0x40000>>18) != 0 {
				/* joins that result from the EXISTS-to-JOIN optimization should not
				 ** be moved to the left of any of their dependencies */
				pWC = pWInfo + 104
				i = (*TWhereClause)(unsafe.Pointer(pWC)).FnBase
				pTerm = (*TWhereClause)(unsafe.Pointer(pWC)).Fa
				for {
					if !(i > 0) {
						break
					}
					if (*TWhereLoop)(unsafe.Pointer(pNew)).FmaskSelf&(*TWhereTerm)(unsafe.Pointer(pTerm)).FprereqAll != uint64(0) {
						mPrereq = mPrereq | (*TWhereTerm)(unsafe.Pointer(pTerm)).FprereqAll&((*TWhereLoop)(unsafe.Pointer(pNew)).FmaskSelf-uint64(1))
					}
					goto _2
				_2:
					;
					i = i - 1
					pTerm += 56
				}
			} else {
				if !(hasRightCrossJoin != 0) {
					mPrereq = uint64(0)
				}
			}
		}
		if libc.Int32FromUint8((*TTable)(unsafe.Pointer((*TSrcItem)(unsafe.Pointer(pItem)).FpSTab)).FeTabType) == int32(TABTYP_VTAB) {
			p = pItem + 1*80
			for {
				if !(p < pEnd) {
					break
				}
				if mUnusable != 0 || libc.Int32FromUint8((*TSrcItem)(unsafe.Pointer(p)).Ffg.Fjointype)&(libc.Int32FromInt32(JT_OUTER)|libc.Int32FromInt32(JT_CROSS)) != 0 {
					mUnusable = mUnusable | _sqlite3WhereGetMask(tls, pWInfo+592, (*TSrcItem)(unsafe.Pointer(p)).FiCursor)
				}
				goto _3
			_3:
				;
				p += 80
			}
			rc = _whereLoopAddVirtual(tls, pBuilder, mPrereq, mUnusable)
		} else {
			rc = _whereLoopAddBtree(tls, pBuilder, mPrereq)
		}
		if rc == SQLITE_OK && (*TWhereClause)(unsafe.Pointer((*TWhereLoopBuilder)(unsafe.Pointer(pBuilder)).FpWC)).FhasOr != 0 {
			rc = _whereLoopAddOr(tls, pBuilder, mPrereq, mUnusable)
		}
		mPrior = mPrior | (*TWhereLoop)(unsafe.Pointer(pNew)).FmaskSelf
		if rc != 0 || (*Tsqlite3)(unsafe.Pointer(db)).FmallocFailed != 0 {
			if rc == int32(SQLITE_DONE) {
				/* We hit the query planner search limit set by iPlanLimit */
				Xsqlite3_log(tls, int32(SQLITE_WARNING), __ccgo_ts+24040, 0)
				rc = SQLITE_OK
			} else {
				break
			}
		}
		goto _1
	_1:
		;
		iTab = iTab + 1
		pItem += 80
	}
	_whereLoopClear(tls, db, pNew)
	return rc
}

// C documentation
//
//	/*
//	** Argument pIdxInfo is already populated with all constraints that may
//	** be used by the virtual table identified by pBuilder->pNew->iTab. This
//	** function marks a subset of those constraints usable, invokes the
//	** xBestIndex method and adds the returned plan to pBuilder.
//	**
//	** A constraint is marked usable if:
//	**
//	**   * Argument mUsable indicates that its prerequisites are available, and
//	**
//	**   * It is not one of the operators specified in the mExclude mask passed
//	**     as the fourth argument (which in practice is either WO_IN or 0).
//	**
//	** Argument mPrereq is a mask of tables that must be scanned before the
//	** virtual table in question. These are added to the plans prerequisites
//	** before it is added to pBuilder.
//	**
//	** Output parameter *pbIn is set to true if the plan added to pBuilder
//	** uses one or more WO_IN terms, or false otherwise.
//	*/
func _whereLoopAddVirtualOne(tls *libc.TLS, pBuilder uintptr, mPrereq TBitmask, mUsable TBitmask, mExclude Tu16, pIdxInfo uintptr, mNoOmit Tu16, pbIn uintptr, pbRetryLimit uintptr) (r int32) {
	bp := tls.Alloc(16)
	defer tls.Free(16)
	var i, iTerm, j, mxTerm, nConstraint, rc, v3 int32
	var pHidden, pIdxCons, pNew, pParse, pSrc, pTerm, pTerm1, pUsage, pWC, v4 uintptr
	var v5 bool
	var v7 uint32
	_, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _ = i, iTerm, j, mxTerm, nConstraint, pHidden, pIdxCons, pNew, pParse, pSrc, pTerm, pTerm1, pUsage, pWC, rc, v3, v4, v5, v7
	pWC = (*TWhereLoopBuilder)(unsafe.Pointer(pBuilder)).FpWC
	pHidden = pIdxInfo + 1*96
	pUsage = (*Tsqlite3_index_info)(unsafe.Pointer(pIdxInfo)).FaConstraintUsage
	rc = SQLITE_OK
	pNew = (*TWhereLoopBuilder)(unsafe.Pointer(pBuilder)).FpNew
	pParse = (*TWhereInfo)(unsafe.Pointer((*TWhereLoopBuilder)(unsafe.Pointer(pBuilder)).FpWInfo)).FpParse
	pSrc = (*TWhereInfo)(unsafe.Pointer((*TWhereLoopBuilder)(unsafe.Pointer(pBuilder)).FpWInfo)).FpTabList + 8 + uintptr((*TWhereLoop)(unsafe.Pointer(pNew)).FiTab)*80
	nConstraint = (*Tsqlite3_index_info)(unsafe.Pointer(pIdxInfo)).FnConstraint
	**(**int32)(__ccgo_up(pbIn)) = 0
	(*TWhereLoop)(unsafe.Pointer(pNew)).Fprereq = mPrereq
	/* Set the usable flag on the subset of constraints identified by
	 ** arguments mUsable and mExclude. */
	pIdxCons = **(**uintptr)(__ccgo_up(pIdxInfo + 8))
	i = 0
	for {
		if !(i < nConstraint) {
			break
		}
		pTerm = _termFromWhereClause(tls, pWC, (*Tsqlite3_index_constraint)(unsafe.Pointer(pIdxCons)).FiTermOffset)
		(*Tsqlite3_index_constraint)(unsafe.Pointer(pIdxCons)).Fusable = uint8(0)
		if (*TWhereTerm)(unsafe.Pointer(pTerm)).FprereqRight&mUsable == (*TWhereTerm)(unsafe.Pointer(pTerm)).FprereqRight && libc.Int32FromUint16((*TWhereTerm)(unsafe.Pointer(pTerm)).FeOperator)&libc.Int32FromUint16(mExclude) == 0 && (pbRetryLimit != 0 || !(_isLimitTerm(tls, pTerm) != 0)) {
			(*Tsqlite3_index_constraint)(unsafe.Pointer(pIdxCons)).Fusable = uint8(1)
		}
		goto _1
	_1:
		;
		i = i + 1
		pIdxCons += 12
	}
	/* Initialize the output fields of the sqlite3_index_info structure */
	libc.Xmemset(tls, pUsage, 0, uint64(8)*libc.Uint64FromInt32(nConstraint))
	(*Tsqlite3_index_info)(unsafe.Pointer(pIdxInfo)).FidxStr = uintptr(0)
	(*Tsqlite3_index_info)(unsafe.Pointer(pIdxInfo)).FidxNum = 0
	(*Tsqlite3_index_info)(unsafe.Pointer(pIdxInfo)).ForderByConsumed = 0
	(*Tsqlite3_index_info)(unsafe.Pointer(pIdxInfo)).FestimatedCost = float64(1e+99) / libc.Float64FromInt32(2)
	(*Tsqlite3_index_info)(unsafe.Pointer(pIdxInfo)).FestimatedRows = int64(25)
	(*Tsqlite3_index_info)(unsafe.Pointer(pIdxInfo)).FidxFlags = 0
	(*THiddenIndexInfo)(unsafe.Pointer(pHidden)).FmHandleIn = uint32(0)
	/* Invoke the virtual table xBestIndex() method */
	rc = _vtabBestIndex(tls, pParse, (*TSrcItem)(unsafe.Pointer(pSrc)).FpSTab, pIdxInfo)
	if rc != 0 {
		if rc == int32(SQLITE_CONSTRAINT) {
			/* If the xBestIndex method returns SQLITE_CONSTRAINT, that means
			 ** that the particular combination of parameters provided is unusable.
			 ** Make no entries in the loop table.
			 */
			_freeIdxStr(tls, pIdxInfo)
			return SQLITE_OK
		}
		return rc
	}
	mxTerm = -int32(1)
	libc.Xmemset(tls, (*TWhereLoop)(unsafe.Pointer(pNew)).FaLTerm, 0, uint64(8)*libc.Uint64FromInt32(nConstraint))
	libc.Xmemset(tls, pNew+24, 0, uint64(24))
	pIdxCons = **(**uintptr)(__ccgo_up(pIdxInfo + 8))
	i = 0
	for {
		if !(i < nConstraint) {
			break
		}
		v3 = (**(**Tsqlite3_index_constraint_usage)(__ccgo_up(pUsage + uintptr(i)*8))).FargvIndex - libc.Int32FromInt32(1)
		iTerm = v3
		if v3 >= 0 {
			j = (*Tsqlite3_index_constraint)(unsafe.Pointer(pIdxCons)).FiTermOffset
			if v5 = iTerm >= nConstraint || j < 0; !v5 {
				v4 = _termFromWhereClause(tls, pWC, j)
				pTerm1 = v4
			}
			if v5 || v4 == uintptr(0) || **(**uintptr)(__ccgo_up((*TWhereLoop)(unsafe.Pointer(pNew)).FaLTerm + uintptr(iTerm)*8)) != uintptr(0) || libc.Int32FromUint8((*Tsqlite3_index_constraint)(unsafe.Pointer(pIdxCons)).Fusable) == 0 {
				_sqlite3ErrorMsg(tls, pParse, __ccgo_ts+24014, libc.VaList(bp+8, (*TTable)(unsafe.Pointer((*TSrcItem)(unsafe.Pointer(pSrc)).FpSTab)).FzName))
				_freeIdxStr(tls, pIdxInfo)
				return int32(SQLITE_ERROR)
			}
			**(**TBitmask)(__ccgo_up(pNew)) |= (*TWhereTerm)(unsafe.Pointer(pTerm1)).FprereqRight
			**(**uintptr)(__ccgo_up((*TWhereLoop)(unsafe.Pointer(pNew)).FaLTerm + uintptr(iTerm)*8)) = pTerm1
			if iTerm > mxTerm {
				mxTerm = iTerm
			}
			if (**(**Tsqlite3_index_constraint_usage)(__ccgo_up(pUsage + uintptr(i)*8))).Fomit != 0 {
				if i < int32(16) && int32(1)<<i&libc.Int32FromUint16(mNoOmit) == 0 {
					v4 = pNew + 24 + 6
					*(*Tu16)(unsafe.Pointer(v4)) = Tu16(int32(*(*Tu16)(unsafe.Pointer(v4))) | libc.Int32FromInt32(1)<<iTerm)
				} else {
				}
				if libc.Int32FromUint8((*TWhereTerm)(unsafe.Pointer(pTerm1)).FeMatchOp) == int32(SQLITE_INDEX_CONSTRAINT_OFFSET) {
					libc.SetBitFieldPtr8Uint32(pNew+24+4, libc.Uint32FromInt32(1), 1, 0x2)
				}
			}
			if i <= int32(31) {
				v7 = libc.Uint32FromInt32(1) << i
			} else {
				v7 = uint32(0)
			}
			if v7&(*THiddenIndexInfo)(unsafe.Pointer(pHidden)).FmHandleIn != 0 {
				(*(*struct {
					FidxNum    int32
					F__ccgo4   uint8
					FisOrdered Ti8
					FomitMask  Tu16
					FidxStr    uintptr
					FmHandleIn Tu32
				})(unsafe.Pointer(pNew + 24))).FmHandleIn |= libc.Uint32FromInt32(1) << iTerm
			} else {
				if libc.Int32FromUint16((*TWhereTerm)(unsafe.Pointer(pTerm1)).FeOperator)&int32(WO_IN) != 0 {
					/* A virtual table that is constrained by an IN clause may not
					 ** consume the ORDER BY clause because (1) the order of IN terms
					 ** is not necessarily related to the order of output terms and
					 ** (2) Multiple outputs from a single IN value will not merge
					 ** together.  */
					(*Tsqlite3_index_info)(unsafe.Pointer(pIdxInfo)).ForderByConsumed = 0
					**(**int32)(__ccgo_up(pIdxInfo + 80)) &= ^libc.Int32FromInt32(SQLITE_INDEX_SCAN_UNIQUE)
					**(**int32)(__ccgo_up(pbIn)) = int32(1)
				}
			}
			/* Unless pbRetryLimit is non-NULL, there should be no LIMIT/OFFSET
			 ** terms. And if there are any, they should follow all other terms. */
			if _isLimitTerm(tls, pTerm1) != 0 && (**(**int32)(__ccgo_up(pbIn)) != 0 || !(_allConstraintsUsed(tls, pUsage, i) != 0)) {
				/* If there is an IN(...) term handled as an == (separate call to
				 ** xFilter for each value on the RHS of the IN) and a LIMIT or
				 ** OFFSET term handled as well, the plan is unusable. Similarly,
				 ** if there is a LIMIT/OFFSET and there are other unused terms,
				 ** the plan cannot be used. In these cases set variable *pbRetryLimit
				 ** to true to tell the caller to retry with LIMIT and OFFSET
				 ** disabled. */
				_freeIdxStr(tls, pIdxInfo)
				**(**int32)(__ccgo_up(pbRetryLimit)) = int32(1)
				return SQLITE_OK
			}
		}
		goto _2
	_2:
		;
		i = i + 1
		pIdxCons += 12
	}
	(*TWhereLoop)(unsafe.Pointer(pNew)).FnLTerm = libc.Uint16FromInt32(mxTerm + int32(1))
	i = 0
	for {
		if !(i <= mxTerm) {
			break
		}
		if **(**uintptr)(__ccgo_up((*TWhereLoop)(unsafe.Pointer(pNew)).FaLTerm + uintptr(i)*8)) == uintptr(0) {
			/* The non-zero argvIdx values must be contiguous.  Raise an
			 ** error if they are not */
			_sqlite3ErrorMsg(tls, pParse, __ccgo_ts+24014, libc.VaList(bp+8, (*TTable)(unsafe.Pointer((*TSrcItem)(unsafe.Pointer(pSrc)).FpSTab)).FzName))
			_freeIdxStr(tls, pIdxInfo)
			return int32(SQLITE_ERROR)
		}
		goto _8
	_8:
		;
		i = i + 1
	}
	(*(*struct {
		FidxNum    int32
		F__ccgo4   uint8
		FisOrdered Ti8
		FomitMask  Tu16
		FidxStr    uintptr
		FmHandleIn Tu32
	})(unsafe.Pointer(pNew + 24))).FidxNum = (*Tsqlite3_index_info)(unsafe.Pointer(pIdxInfo)).FidxNum
	libc.SetBitFieldPtr8Uint32(pNew+24+4, libc.Uint32FromInt32((*Tsqlite3_index_info)(unsafe.Pointer(pIdxInfo)).FneedToFreeIdxStr), 0, 0x1)
	(*Tsqlite3_index_info)(unsafe.Pointer(pIdxInfo)).FneedToFreeIdxStr = 0
	(*(*struct {
		FidxNum    int32
		F__ccgo4   uint8
		FisOrdered Ti8
		FomitMask  Tu16
		FidxStr    uintptr
		FmHandleIn Tu32
	})(unsafe.Pointer(pNew + 24))).FidxStr = (*Tsqlite3_index_info)(unsafe.Pointer(pIdxInfo)).FidxStr
	if (*Tsqlite3_index_info)(unsafe.Pointer(pIdxInfo)).ForderByConsumed != 0 {
		v3 = (*Tsqlite3_index_info)(unsafe.Pointer(pIdxInfo)).FnOrderBy
	} else {
		v3 = 0
	}
	(*(*struct {
		FidxNum    int32
		F__ccgo4   uint8
		FisOrdered Ti8
		FomitMask  Tu16
		FidxStr    uintptr
		FmHandleIn Tu32
	})(unsafe.Pointer(pNew + 24))).FisOrdered = int8(v3)
	libc.SetBitFieldPtr8Uint32(pNew+24+4, libc.BoolUint32((*Tsqlite3_index_info)(unsafe.Pointer(pIdxInfo)).FidxFlags&libc.Int32FromInt32(SQLITE_INDEX_SCAN_HEX) != libc.Int32FromInt32(0)), 2, 0x4)
	(*TWhereLoop)(unsafe.Pointer(pNew)).FrSetup = 0
	(*TWhereLoop)(unsafe.Pointer(pNew)).FrRun = _sqlite3LogEstFromDouble(tls, (*Tsqlite3_index_info)(unsafe.Pointer(pIdxInfo)).FestimatedCost)
	(*TWhereLoop)(unsafe.Pointer(pNew)).FnOut = _sqlite3LogEst(tls, libc.Uint64FromInt64((*Tsqlite3_index_info)(unsafe.Pointer(pIdxInfo)).FestimatedRows))
	/* Set the WHERE_ONEROW flag if the xBestIndex() method indicated
	 ** that the scan will visit at most one row. Clear it otherwise. */
	if (*Tsqlite3_index_info)(unsafe.Pointer(pIdxInfo)).FidxFlags&int32(SQLITE_INDEX_SCAN_UNIQUE) != 0 {
		**(**Tu32)(__ccgo_up(pNew + 48)) |= uint32(WHERE_ONEROW)
	} else {
		**(**Tu32)(__ccgo_up(pNew + 48)) &= libc.Uint32FromInt32(^libc.Int32FromInt32(WHERE_ONEROW))
	}
	rc = _whereLoopInsert(tls, pBuilder, pNew)
	if int32(Tu32(*(*uint8)(unsafe.Pointer(pNew + 24 + 4))&0x1>>0)) != 0 {
		Xsqlite3_free(tls, (*(*struct {
			FidxNum    int32
			F__ccgo4   uint8
			FisOrdered Ti8
			FomitMask  Tu16
			FidxStr    uintptr
			FmHandleIn Tu32
		})(unsafe.Pointer(pNew + 24))).FidxStr)
		libc.SetBitFieldPtr8Uint32(pNew+24+4, libc.Uint32FromInt32(0), 0, 0x1)
	}
	return rc
}

// C documentation
//
//	/*
//	** Given the list of WhereLoop objects at pWInfo->pLoops, this routine
//	** attempts to find the lowest cost path that visits each WhereLoop
//	** once.  This path is then loaded into the pWInfo->a[].pWLoop fields.
//	**
//	** Assume that the total number of output rows that will need to be sorted
//	** will be nRowEst (in the 10*log2 representation).  Or, ignore sorting
//	** costs if nRowEst==0.
//	**
//	** Return SQLITE_OK on success or SQLITE_NOMEM of a memory allocation
//	** error occurs.
//	*/
func _wherePathSolver(tls *libc.TLS, pWInfo uintptr, nRowEst TLogEst) (r int32) {
	bp := tls.Alloc(32)
	defer tls.Free(32)
	var aFrom, aSortCost, aTo, pFrom, pLevel, pParse, pSpace, pTo, pWLoop, pX, v11 uintptr
	var iLoop, ii, jj, mxChoice, mxI, nFrom, nLoop, nOrder, nOrderBy, nSpace, nTo, rc, rc1, v2 int32
	var isOrdered Ti8
	var maskNew TBitmask
	var mxCost, mxUnsort, nOut, rCost, rUnsort TLogEst
	var wsFlags Tu32
	var _ /* m at bp+16 */ TBitmask
	var _ /* notUsed at bp+8 */ TBitmask
	var _ /* revMask at bp+0 */ TBitmask
	var _ /* revMask at bp+24 */ TBitmask
	_, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _ = aFrom, aSortCost, aTo, iLoop, ii, isOrdered, jj, maskNew, mxChoice, mxCost, mxI, mxUnsort, nFrom, nLoop, nOrder, nOrderBy, nOut, nSpace, nTo, pFrom, pLevel, pParse, pSpace, pTo, pWLoop, pX, rCost, rUnsort, rc, rc1, wsFlags, v11, v2 /* Loop counters */
	mxI = 0                                                                                                                                                                                                                                                                                                                                     /* Number of ORDER BY clause terms */
	mxCost = 0                                                                                                                                                                                                                                                                                                                                  /* Maximum cost of a set of paths */
	mxUnsort = 0                                                                                                                                                                                                                                                                                                                                /* Used to divy up the pSpace memory */
	aSortCost = uintptr(0)                                                                                                                                                                                                                                                                                                                      /* Bytes of space allocated at pSpace */
	pParse = (*TWhereInfo)(unsafe.Pointer(pWInfo)).FpParse
	nLoop = libc.Int32FromUint8((*TWhereInfo)(unsafe.Pointer(pWInfo)).FnLevel)
	/* TUNING: mxChoice is the maximum number of possible paths to preserve
	 ** at each step.  Based on the number of loops in the FROM clause:
	 **
	 **     nLoop      mxChoice
	 **     -----      --------
	 **       1            1            // the most common case
	 **       2            5
	 **       3+        12 or 18        // see computeMxChoice()
	 */
	if nLoop <= int32(1) {
		mxChoice = int32(1)
	} else {
		if nLoop == int32(2) {
			mxChoice = int32(5)
		} else {
			if (*TParse)(unsafe.Pointer(pParse)).FnErr != 0 {
				mxChoice = int32(1)
			} else {
				mxChoice = _computeMxChoice(tls, pWInfo)
			}
		}
	}
	/* If nRowEst is zero and there is an ORDER BY clause, ignore it. In this
	 ** case the purpose of this call is to estimate the number of rows returned
	 ** by the overall query. Once this estimate has been obtained, the caller
	 ** will invoke this function a second time, passing the estimate as the
	 ** nRowEst parameter.  */
	if (*TWhereInfo)(unsafe.Pointer(pWInfo)).FpOrderBy == uintptr(0) || int32(nRowEst) == 0 {
		nOrderBy = 0
	} else {
		nOrderBy = (*TExprList)(unsafe.Pointer((*TWhereInfo)(unsafe.Pointer(pWInfo)).FpOrderBy)).FnExpr
	}
	/* Allocate and initialize space for aTo, aFrom and aSortCost[] */
	nSpace = libc.Int32FromUint64((uint64(32) + uint64(8)*libc.Uint64FromInt32(nLoop)) * libc.Uint64FromInt32(mxChoice) * uint64(2))
	nSpace = libc.Int32FromUint64(uint64(nSpace) + libc.Uint64FromInt64(2)*libc.Uint64FromInt32(nOrderBy))
	pSpace = _sqlite3DbMallocRawNN(tls, (*TParse)(unsafe.Pointer(pParse)).Fdb, libc.Uint64FromInt32(nSpace))
	if pSpace == uintptr(0) {
		return int32(SQLITE_NOMEM)
	}
	aTo = pSpace
	aFrom = aTo + uintptr(mxChoice)*32
	libc.Xmemset(tls, aFrom, 0, uint64(32))
	pX = aFrom + uintptr(mxChoice)*32
	ii = mxChoice * int32(2)
	pFrom = aTo
	for {
		if !(ii > 0) {
			break
		}
		(*TWherePath)(unsafe.Pointer(pFrom)).FaLoop = pX
		goto _1
	_1:
		;
		ii = ii - 1
		pFrom += 32
		pX = pX + uintptr(nLoop)*8
	}
	if nOrderBy != 0 {
		/* If there is an ORDER BY clause and it is not being ignored, set up
		 ** space for the aSortCost[] array. Each element of the aSortCost array
		 ** is either zero - meaning it has not yet been initialized - or the
		 ** cost of sorting nRowEst rows of data where the first X terms of
		 ** the ORDER BY clause are already in order, where X is the array
		 ** index.  */
		aSortCost = pX
		libc.Xmemset(tls, aSortCost, 0, uint64(2)*libc.Uint64FromInt32(nOrderBy))
	}
	/* Seed the search with a single WherePath containing zero WhereLoops.
	 **
	 ** TUNING: Do not let the number of iterations go above 28.  If the cost
	 ** of computing an automatic index is not paid back within the first 28
	 ** rows, then do not use the automatic index. */
	if int32((*TParse)(unsafe.Pointer(pParse)).FnQueryLoop) < int32(48) {
		v2 = int32((*TParse)(unsafe.Pointer(pParse)).FnQueryLoop)
	} else {
		v2 = int32(48)
	}
	(**(**TWherePath)(__ccgo_up(aFrom))).FnRow = int16(v2)
	nFrom = int32(1)
	if nOrderBy != 0 {
		/* If nLoop is zero, then there are no FROM terms in the query. Since
		 ** in this case the query may return a maximum of one row, the results
		 ** are already in the requested order. Set isOrdered to nOrderBy to
		 ** indicate this. Or, if nLoop is greater than zero, set isOrdered to
		 ** -1, indicating that the result set may or may not be ordered,
		 ** depending on the loops added to the current plan.  */
		if nLoop > 0 {
			v2 = -int32(1)
		} else {
			v2 = nOrderBy
		}
		(**(**TWherePath)(__ccgo_up(aFrom))).FisOrdered = int8(v2)
	}
	/* Compute successively longer WherePaths using the previous generation
	 ** of WherePaths as the basis for the next.  Keep track of the mxChoice
	 ** best paths at each generation */
	iLoop = 0
	for {
		if !(iLoop < nLoop) {
			break
		}
		nTo = 0
		ii = 0
		pFrom = aFrom
		for {
			if !(ii < nFrom) {
				break
			}
			pWLoop = (*TWhereInfo)(unsafe.Pointer(pWInfo)).FpLoops
			for {
				if !(pWLoop != 0) {
					break
				} /* Mask of rev-order loops for (..) */
				if (*TWhereLoop)(unsafe.Pointer(pWLoop)).Fprereq & ^(*TWherePath)(unsafe.Pointer(pFrom)).FmaskLoop != uint64(0) {
					goto _6
				}
				if (*TWhereLoop)(unsafe.Pointer(pWLoop)).FmaskSelf&(*TWherePath)(unsafe.Pointer(pFrom)).FmaskLoop != uint64(0) {
					goto _6
				}
				if (*TWhereLoop)(unsafe.Pointer(pWLoop)).FwsFlags&uint32(WHERE_AUTO_INDEX) != uint32(0) && int32((*TWherePath)(unsafe.Pointer(pFrom)).FnRow) < int32(3) {
					/* Do not use an automatic index if the this loop is expected
					 ** to run less than 1.25 times.  It is tempting to also exclude
					 ** automatic index usage on an outer loop, but sometimes an automatic
					 ** index is useful in the outer loop of a correlated subquery. */
					goto _6
				}
				/* At this point, pWLoop is a candidate to be the next loop.
				 ** Compute its cost */
				rUnsort = int16(int32((*TWhereLoop)(unsafe.Pointer(pWLoop)).FrRun) + int32((*TWherePath)(unsafe.Pointer(pFrom)).FnRow))
				if (*TWhereLoop)(unsafe.Pointer(pWLoop)).FrSetup != 0 {
					rUnsort = _sqlite3LogEstAdd(tls, (*TWhereLoop)(unsafe.Pointer(pWLoop)).FrSetup, rUnsort)
				}
				rUnsort = _sqlite3LogEstAdd(tls, rUnsort, (*TWherePath)(unsafe.Pointer(pFrom)).FrUnsort)
				nOut = int16(int32((*TWherePath)(unsafe.Pointer(pFrom)).FnRow) + int32((*TWhereLoop)(unsafe.Pointer(pWLoop)).FnOut))
				maskNew = (*TWherePath)(unsafe.Pointer(pFrom)).FmaskLoop | (*TWhereLoop)(unsafe.Pointer(pWLoop)).FmaskSelf
				isOrdered = (*TWherePath)(unsafe.Pointer(pFrom)).FisOrdered
				if int32(isOrdered) < 0 {
					**(**TBitmask)(__ccgo_up(bp)) = uint64(0)
					isOrdered = _wherePathSatisfiesOrderBy(tls, pWInfo, (*TWhereInfo)(unsafe.Pointer(pWInfo)).FpOrderBy, pFrom, (*TWhereInfo)(unsafe.Pointer(pWInfo)).FwctrlFlags, libc.Uint16FromInt32(iLoop), pWLoop, bp)
				} else {
					**(**TBitmask)(__ccgo_up(bp)) = (*TWherePath)(unsafe.Pointer(pFrom)).FrevLoop
				}
				if int32(isOrdered) >= 0 && int32(isOrdered) < nOrderBy {
					if int32(**(**TLogEst)(__ccgo_up(aSortCost + uintptr(isOrdered)*2))) == 0 {
						**(**TLogEst)(__ccgo_up(aSortCost + uintptr(isOrdered)*2)) = _whereSortingCost(tls, pWInfo, nRowEst, nOrderBy, int32(isOrdered))
					}
					/* TUNING:  Add a small extra penalty (3) to sorting as an
					 ** extra encouragement to the query planner to select a plan
					 ** where the rows emerge in the correct order without any sorting
					 ** required. */
					rCost = int16(int32(_sqlite3LogEstAdd(tls, rUnsort, **(**TLogEst)(__ccgo_up(aSortCost + uintptr(isOrdered)*2)))) + int32(3))
				} else {
					rCost = rUnsort
					rUnsort = int16(int32(rUnsort) - libc.Int32FromInt32(2)) /* TUNING:  Slight bias in favor of no-sort plans */
				}
				/* Check to see if pWLoop should be added to the set of
				 ** mxChoice best-so-far paths.
				 **
				 ** First look for an existing path among best-so-far paths
				 ** that:
				 **     (1) covers the same set of loops, and
				 **     (2) has a compatible isOrdered value.
				 **
				 ** "Compatible isOrdered value" means either
				 **     (A) both have isOrdered==-1, or
				 **     (B) both have isOrder>=0, or
				 **     (C) ordering does not matter because this is the last round
				 **         of the solver.
				 **
				 ** The term "((pTo->isOrdered^isOrdered)&0x80)==0" is equivalent
				 ** to (pTo->isOrdered==(-1))==(isOrdered==(-1))" for the range
				 ** of legal values for isOrdered, -1..64.
				 */
				jj = 0
				pTo = aTo
				for {
					if !(jj < nTo) {
						break
					}
					if (*TWherePath)(unsafe.Pointer(pTo)).FmaskLoop == maskNew && ((int32((*TWherePath)(unsafe.Pointer(pTo)).FisOrdered)^int32(isOrdered))&int32(0x80) == 0 || iLoop == nLoop-int32(1)) {
						break
					}
					goto _7
				_7:
					;
					jj = jj + 1
					pTo += 32
				}
				if jj >= nTo {
					/* None of the existing best-so-far paths match the candidate. */
					if nTo >= mxChoice && (int32(rCost) > int32(mxCost) || int32(rCost) == int32(mxCost) && int32(rUnsort) >= int32(mxUnsort)) {
						/* The current candidate is no better than any of the mxChoice
						 ** paths currently in the best-so-far buffer.  So discard
						 ** this candidate as not viable. */
						goto _6
					}
					/* If we reach this points it means that the new candidate path
					 ** needs to be added to the set of best-so-far paths. */
					if nTo < mxChoice {
						/* Increase the size of the aTo set by one */
						v2 = nTo
						nTo = nTo + 1
						jj = v2
					} else {
						/* New path replaces the prior worst to keep count below mxChoice */
						jj = mxI
					}
					pTo = aTo + uintptr(jj)*32
				} else {
					/* Control reaches here if best-so-far path pTo=aTo[jj] covers the
					 ** same set of loops and has the same isOrdered setting as the
					 ** candidate path.  Check to see if the candidate should replace
					 ** pTo or if the candidate should be skipped.
					 **
					 ** The conditional is an expanded vector comparison equivalent to:
					 **   (pTo->rCost,pTo->nRow,pTo->rUnsort) <= (rCost,nOut,rUnsort)
					 */
					if int32((*TWherePath)(unsafe.Pointer(pTo)).FrCost) < int32(rCost) || int32((*TWherePath)(unsafe.Pointer(pTo)).FrCost) == int32(rCost) && int32((*TWherePath)(unsafe.Pointer(pTo)).FnRow) < int32(nOut) || int32((*TWherePath)(unsafe.Pointer(pTo)).FrCost) == int32(rCost) && int32((*TWherePath)(unsafe.Pointer(pTo)).FnRow) == int32(nOut) && int32((*TWherePath)(unsafe.Pointer(pTo)).FrUnsort) < int32(rUnsort) || int32((*TWherePath)(unsafe.Pointer(pTo)).FrCost) == int32(rCost) && int32((*TWherePath)(unsafe.Pointer(pTo)).FnRow) == int32(nOut) && int32((*TWherePath)(unsafe.Pointer(pTo)).FrUnsort) == int32(rUnsort) && _whereLoopIsNoBetter(tls, pWLoop, **(**uintptr)(__ccgo_up((*TWherePath)(unsafe.Pointer(pTo)).FaLoop + uintptr(iLoop)*8))) != 0 {
						/* Discard the candidate path from further consideration */
						goto _6
					}
					/* Control reaches here if the candidate path is better than the
					 ** pTo path.  Replace pTo with the candidate. */
				}
				/* pWLoop is a winner.  Add it to the set of best so far */
				(*TWherePath)(unsafe.Pointer(pTo)).FmaskLoop = (*TWherePath)(unsafe.Pointer(pFrom)).FmaskLoop | (*TWhereLoop)(unsafe.Pointer(pWLoop)).FmaskSelf
				(*TWherePath)(unsafe.Pointer(pTo)).FrevLoop = **(**TBitmask)(__ccgo_up(bp))
				(*TWherePath)(unsafe.Pointer(pTo)).FnRow = nOut
				(*TWherePath)(unsafe.Pointer(pTo)).FrCost = rCost
				(*TWherePath)(unsafe.Pointer(pTo)).FrUnsort = rUnsort
				(*TWherePath)(unsafe.Pointer(pTo)).FisOrdered = isOrdered
				libc.Xmemcpy(tls, (*TWherePath)(unsafe.Pointer(pTo)).FaLoop, (*TWherePath)(unsafe.Pointer(pFrom)).FaLoop, uint64(8)*libc.Uint64FromInt32(iLoop))
				**(**uintptr)(__ccgo_up((*TWherePath)(unsafe.Pointer(pTo)).FaLoop + uintptr(iLoop)*8)) = pWLoop
				if nTo >= mxChoice {
					mxI = 0
					mxCost = (**(**TWherePath)(__ccgo_up(aTo))).FrCost
					mxUnsort = (**(**TWherePath)(__ccgo_up(aTo))).FnRow
					jj = int32(1)
					pTo = aTo + 1*32
					for {
						if !(jj < mxChoice) {
							break
						}
						if int32((*TWherePath)(unsafe.Pointer(pTo)).FrCost) > int32(mxCost) || int32((*TWherePath)(unsafe.Pointer(pTo)).FrCost) == int32(mxCost) && int32((*TWherePath)(unsafe.Pointer(pTo)).FrUnsort) > int32(mxUnsort) {
							mxCost = (*TWherePath)(unsafe.Pointer(pTo)).FrCost
							mxUnsort = (*TWherePath)(unsafe.Pointer(pTo)).FrUnsort
							mxI = jj
						}
						goto _9
					_9:
						;
						jj = jj + 1
						pTo += 32
					}
				}
				goto _6
			_6:
				;
				pWLoop = (*TWhereLoop)(unsafe.Pointer(pWLoop)).FpNextLoop
			}
			goto _5
		_5:
			;
			ii = ii + 1
			pFrom += 32
		}
		/* Swap the roles of aFrom and aTo for the next generation */
		pFrom = aTo
		aTo = aFrom
		aFrom = pFrom
		nFrom = nTo
		goto _4
	_4:
		;
		iLoop = iLoop + 1
	}
	if nFrom == 0 {
		_sqlite3ErrorMsg(tls, pParse, __ccgo_ts+24075, 0)
		_sqlite3DbFreeNN(tls, (*TParse)(unsafe.Pointer(pParse)).Fdb, pSpace)
		return int32(SQLITE_ERROR)
	}
	/* Only one path is available, which is the best path */
	pFrom = aFrom
	/* Load the lowest cost path into pWInfo */
	iLoop = 0
	for {
		if !(iLoop < nLoop) {
			break
		}
		pLevel = pWInfo + 856 + uintptr(iLoop)*112
		v11 = **(**uintptr)(__ccgo_up((*TWherePath)(unsafe.Pointer(pFrom)).FaLoop + uintptr(iLoop)*8))
		pWLoop = v11
		(*TWhereLevel)(unsafe.Pointer(pLevel)).FpWLoop = v11
		(*TWhereLevel)(unsafe.Pointer(pLevel)).FiFrom = (*TWhereLoop)(unsafe.Pointer(pWLoop)).FiTab
		(*TWhereLevel)(unsafe.Pointer(pLevel)).FiTabCur = (*(*TSrcItem)(unsafe.Pointer((*TWhereInfo)(unsafe.Pointer(pWInfo)).FpTabList + 8 + uintptr((*TWhereLevel)(unsafe.Pointer(pLevel)).FiFrom)*80))).FiCursor
		goto _10
	_10:
		;
		iLoop = iLoop + 1
	}
	if libc.Int32FromUint16((*TWhereInfo)(unsafe.Pointer(pWInfo)).FwctrlFlags)&int32(WHERE_WANT_DISTINCT) != 0 && libc.Int32FromUint16((*TWhereInfo)(unsafe.Pointer(pWInfo)).FwctrlFlags)&int32(WHERE_DISTINCTBY) == 0 && libc.Int32FromUint8((*TWhereInfo)(unsafe.Pointer(pWInfo)).FeDistinct) == WHERE_DISTINCT_NOOP && nRowEst != 0 {
		rc = int32(_wherePathSatisfiesOrderBy(tls, pWInfo, (*TWhereInfo)(unsafe.Pointer(pWInfo)).FpResultSet, pFrom, uint16(WHERE_DISTINCTBY), libc.Uint16FromInt32(nLoop-int32(1)), **(**uintptr)(__ccgo_up((*TWherePath)(unsafe.Pointer(pFrom)).FaLoop + uintptr(nLoop-int32(1))*8)), bp+8))
		if rc == (*TExprList)(unsafe.Pointer((*TWhereInfo)(unsafe.Pointer(pWInfo)).FpResultSet)).FnExpr {
			(*TWhereInfo)(unsafe.Pointer(pWInfo)).FeDistinct = uint8(WHERE_DISTINCT_ORDERED)
		}
	}
	libc.SetBitFieldPtr8Uint32(pWInfo+68, libc.Uint32FromInt32(0), 2, 0x4)
	if (*TWhereInfo)(unsafe.Pointer(pWInfo)).FpOrderBy != 0 {
		(*TWhereInfo)(unsafe.Pointer(pWInfo)).FnOBSat = (*TWherePath)(unsafe.Pointer(pFrom)).FisOrdered
		if libc.Int32FromUint16((*TWhereInfo)(unsafe.Pointer(pWInfo)).FwctrlFlags)&int32(WHERE_DISTINCTBY) != 0 {
			if int32((*TWherePath)(unsafe.Pointer(pFrom)).FisOrdered) == (*TExprList)(unsafe.Pointer((*TWhereInfo)(unsafe.Pointer(pWInfo)).FpOrderBy)).FnExpr {
				(*TWhereInfo)(unsafe.Pointer(pWInfo)).FeDistinct = uint8(WHERE_DISTINCT_ORDERED)
			}
			/* vvv--- See check-in [12ad822d9b827777] on 2023-03-16 ---vvv */
		} else {
			(*TWhereInfo)(unsafe.Pointer(pWInfo)).FrevMask = (*TWherePath)(unsafe.Pointer(pFrom)).FrevLoop
			if int32((*TWhereInfo)(unsafe.Pointer(pWInfo)).FnOBSat) <= 0 {
				(*TWhereInfo)(unsafe.Pointer(pWInfo)).FnOBSat = 0
				if nLoop > 0 {
					wsFlags = (*TWhereLoop)(unsafe.Pointer(**(**uintptr)(__ccgo_up((*TWherePath)(unsafe.Pointer(pFrom)).FaLoop + uintptr(nLoop-int32(1))*8)))).FwsFlags
					if wsFlags&uint32(WHERE_ONEROW) == uint32(0) && wsFlags&libc.Uint32FromInt32(libc.Int32FromInt32(WHERE_IPK)|libc.Int32FromInt32(WHERE_COLUMN_IN)) != libc.Uint32FromInt32(libc.Int32FromInt32(WHERE_IPK)|libc.Int32FromInt32(WHERE_COLUMN_IN)) {
						**(**TBitmask)(__ccgo_up(bp + 16)) = uint64(0)
						rc1 = int32(_wherePathSatisfiesOrderBy(tls, pWInfo, (*TWhereInfo)(unsafe.Pointer(pWInfo)).FpOrderBy, pFrom, uint16(WHERE_ORDERBY_LIMIT), libc.Uint16FromInt32(nLoop-int32(1)), **(**uintptr)(__ccgo_up((*TWherePath)(unsafe.Pointer(pFrom)).FaLoop + uintptr(nLoop-int32(1))*8)), bp+16))
						if rc1 == (*TExprList)(unsafe.Pointer((*TWhereInfo)(unsafe.Pointer(pWInfo)).FpOrderBy)).FnExpr {
							libc.SetBitFieldPtr8Uint32(pWInfo+68, libc.Uint32FromInt32(1), 2, 0x4)
							(*TWhereInfo)(unsafe.Pointer(pWInfo)).FrevMask = **(**TBitmask)(__ccgo_up(bp + 16))
						}
					}
				}
			} else {
				if nLoop != 0 && int32((*TWhereInfo)(unsafe.Pointer(pWInfo)).FnOBSat) == int32(1) && libc.Int32FromUint16((*TWhereInfo)(unsafe.Pointer(pWInfo)).FwctrlFlags)&(libc.Int32FromInt32(WHERE_ORDERBY_MIN)|libc.Int32FromInt32(WHERE_ORDERBY_MAX)) != 0 {
					libc.SetBitFieldPtr8Uint32(pWInfo+68, libc.Uint32FromInt32(1), 2, 0x4)
				}
			}
		}
		if libc.Int32FromUint16((*TWhereInfo)(unsafe.Pointer(pWInfo)).FwctrlFlags)&int32(WHERE_SORTBYGROUP) != 0 && int32((*TWhereInfo)(unsafe.Pointer(pWInfo)).FnOBSat) == (*TExprList)(unsafe.Pointer((*TWhereInfo)(unsafe.Pointer(pWInfo)).FpOrderBy)).FnExpr && nLoop > 0 {
			**(**TBitmask)(__ccgo_up(bp + 24)) = uint64(0)
			nOrder = int32(_wherePathSatisfiesOrderBy(tls, pWInfo, (*TWhereInfo)(unsafe.Pointer(pWInfo)).FpOrderBy, pFrom, uint16(0), libc.Uint16FromInt32(nLoop-int32(1)), **(**uintptr)(__ccgo_up((*TWherePath)(unsafe.Pointer(pFrom)).FaLoop + uintptr(nLoop-int32(1))*8)), bp+24))
			if nOrder == (*TExprList)(unsafe.Pointer((*TWhereInfo)(unsafe.Pointer(pWInfo)).FpOrderBy)).FnExpr {
				libc.SetBitFieldPtr8Uint32(pWInfo+68, libc.Uint32FromInt32(1), 3, 0x8)
				(*TWhereInfo)(unsafe.Pointer(pWInfo)).FrevMask = **(**TBitmask)(__ccgo_up(bp + 24))
			}
		}
	}
	(*TWhereInfo)(unsafe.Pointer(pWInfo)).FnRowOut = (*TWherePath)(unsafe.Pointer(pFrom)).FnRow
	/* Free temporary memory and return success */
	_sqlite3DbFreeNN(tls, (*TParse)(unsafe.Pointer(pParse)).Fdb, pSpace)
	return SQLITE_OK
}

// C documentation
//
//	/*
//	** A "PRECEDING <expr>" (eCond==0) or "FOLLOWING <expr>" (eCond==1) or the
//	** value of the second argument to nth_value() (eCond==2) has just been
//	** evaluated and the result left in register reg. This function generates VM
//	** code to check that the value is a non-negative integer and throws an
//	** exception if it is not.
//	*/
func _windowCheckValue(tls *libc.TLS, pParse uintptr, reg int32, eCond int32) {
	var regString, regZero int32
	var v uintptr
	_, _, _ = regString, regZero, v
	v = _sqlite3GetVdbe(tls, pParse)
	regZero = _sqlite3GetTempReg(tls, pParse)
	_sqlite3VdbeAddOp2(tls, v, int32(OP_Integer), 0, regZero)
	if eCond >= int32(WINDOW_STARTING_NUM) {
		regString = _sqlite3GetTempReg(tls, pParse)
		_sqlite3VdbeAddOp4(tls, v, int32(OP_String8), 0, regString, 0, __ccgo_ts+1693, -int32(1))
		_sqlite3VdbeAddOp3(tls, v, int32(OP_Ge), regString, _sqlite3VdbeCurrentAddr(tls, v)+int32(2), reg)
		_sqlite3VdbeChangeP5(tls, v, libc.Uint16FromInt32(libc.Int32FromInt32(SQLITE_AFF_NUMERIC)|libc.Int32FromInt32(SQLITE_JUMPIFNULL)))
	} else {
		_sqlite3VdbeAddOp2(tls, v, int32(OP_MustBeInt), reg, _sqlite3VdbeCurrentAddr(tls, v)+int32(2))
	}
	_sqlite3VdbeAddOp3(tls, v, _aOp1[eCond], regZero, _sqlite3VdbeCurrentAddr(tls, v)+int32(2), reg)
	_sqlite3VdbeChangeP5(tls, v, uint16(SQLITE_AFF_NUMERIC))
	/* NULL case captured by */
	/*   the OP_MustBeInt */
	/* NULL case caught by */
	/*   the OP_Ge */
	_sqlite3MayAbort(tls, pParse)
	_sqlite3VdbeAddOp2(tls, v, int32(OP_Halt), int32(SQLITE_ERROR), int32(OE_Abort))
	_sqlite3VdbeAppendP4(tls, v, _azErr[eCond], -int32(1))
	_sqlite3ReleaseTempReg(tls, pParse, regZero)
}

// C documentation
//
//	/*
//	** This function is called as part of generating VM programs for RANGE
//	** offset PRECEDING/FOLLOWING frame boundaries. Assuming "ASC" order for
//	** the ORDER BY term in the window, and that argument op is OP_Ge, it generates
//	** code equivalent to:
//	**
//	**   if( csr1.peerVal + regVal >= csr2.peerVal ) goto lbl;
//	**
//	** The value of parameter op may also be OP_Gt or OP_Le. In these cases the
//	** operator in the above pseudo-code is replaced with ">" or "<=", respectively.
//	**
//	** If the sort-order for the ORDER BY term in the window is DESC, then the
//	** comparison is reversed. Instead of adding regVal to csr1.peerVal, it is
//	** subtracted. And the comparison operator is inverted to - ">=" becomes "<=",
//	** ">" becomes "<", and so on. So, with DESC sort order, if the argument op
//	** is OP_Ge, the generated code is equivalent to:
//	**
//	**   if( csr1.peerVal - regVal <= csr2.peerVal ) goto lbl;
//	**
//	** A special type of arithmetic is used such that if csr1.peerVal is not
//	** a numeric type (real or integer), then the result of the addition
//	** or subtraction is a a copy of csr1.peerVal.
//	*/
func _windowCodeRangeTest(tls *libc.TLS, p uintptr, op int32, csr1 int32, regVal int32, csr2 int32, lbl int32) {
	var addr, addrDone, addrGe, arith, reg1, reg2, regString, v1 int32
	var pColl, pOrderBy, pParse, v, v2 uintptr
	_, _, _, _, _, _, _, _, _, _, _, _, _ = addr, addrDone, addrGe, arith, pColl, pOrderBy, pParse, reg1, reg2, regString, v, v1, v2
	pParse = (*TWindowCodeArg)(unsafe.Pointer(p)).FpParse
	v = _sqlite3GetVdbe(tls, pParse)
	pOrderBy = (*TWindow)(unsafe.Pointer((*TWindowCodeArg)(unsafe.Pointer(p)).FpMWin)).FpOrderBy /* ORDER BY clause for window */
	reg1 = _sqlite3GetTempReg(tls, pParse)                                                       /* Reg. for csr1.peerVal+regVal */
	reg2 = _sqlite3GetTempReg(tls, pParse)
	v2 = pParse + 60
	*(*int32)(unsafe.Pointer(v2)) = *(*int32)(unsafe.Pointer(v2)) + 1
	v1 = *(*int32)(unsafe.Pointer(v2)) /* Reg. for csr2.peerVal */
	regString = v1                     /* Reg. for constant value '' */
	arith = int32(OP_Add)              /* Jump destination */
	addrDone = _sqlite3VdbeMakeLabel(tls, pParse)
	/* Read the peer-value from each cursor into a register */
	_windowReadPeerValues(tls, p, csr1, reg1)
	_windowReadPeerValues(tls, p, csr2, reg2)
	if libc.Int32FromUint8((*(*TExprList_item)(unsafe.Pointer(pOrderBy + 8))).Ffg.FsortFlags)&int32(KEYINFO_ORDER_DESC) != 0 {
		switch op {
		case int32(OP_Ge):
			op = int32(OP_Le)
		case int32(OP_Gt):
			op = int32(OP_Lt)
		default:
			op = int32(OP_Ge)
			break
		}
		arith = int32(OP_Subtract)
	}
	/* If the BIGNULL flag is set for the ORDER BY, then it is required to
	 ** consider NULL values to be larger than all other values, instead of
	 ** the usual smaller. The VDBE opcodes OP_Ge and so on do not handle this
	 ** (and adding that capability causes a performance regression), so
	 ** instead if the BIGNULL flag is set then cases where either reg1 or
	 ** reg2 are NULL are handled separately in the following block. The code
	 ** generated is equivalent to:
	 **
	 **   if( reg1 IS NULL ){
	 **     if( op==OP_Ge ) goto lbl;
	 **     if( op==OP_Gt && reg2 IS NOT NULL ) goto lbl;
	 **     if( op==OP_Le && reg2 IS NULL ) goto lbl;
	 **   }else if( reg2 IS NULL ){
	 **     if( op==OP_Le ) goto lbl;
	 **   }
	 **
	 ** Additionally, if either reg1 or reg2 are NULL but the jump to lbl is
	 ** not taken, control jumps over the comparison operator coded below this
	 ** block.  */
	if libc.Int32FromUint8((*(*TExprList_item)(unsafe.Pointer(pOrderBy + 8))).Ffg.FsortFlags)&int32(KEYINFO_ORDER_BIGNULL) != 0 {
		/* This block runs if reg1 contains a NULL. */
		addr = _sqlite3VdbeAddOp1(tls, v, int32(OP_NotNull), reg1)
		switch op {
		case int32(OP_Ge):
			_sqlite3VdbeAddOp2(tls, v, int32(OP_Goto), 0, lbl)
		case int32(OP_Gt):
			_sqlite3VdbeAddOp2(tls, v, int32(OP_NotNull), reg2, lbl)
		case int32(OP_Le):
			_sqlite3VdbeAddOp2(tls, v, int32(OP_IsNull), reg2, lbl)
		default: /* no-op */
			break
		}
		_sqlite3VdbeAddOp2(tls, v, int32(OP_Goto), 0, addrDone)
		/* This block runs if reg1 is not NULL, but reg2 is. */
		_sqlite3VdbeJumpHere(tls, v, addr)
		if op == int32(OP_Gt) || op == int32(OP_Ge) {
			v1 = addrDone
		} else {
			v1 = lbl
		}
		_sqlite3VdbeAddOp2(tls, v, int32(OP_IsNull), reg2, v1)
	}
	/* Register reg1 currently contains csr1.peerVal (the peer-value from csr1).
	 ** This block adds (or subtracts for DESC) the numeric value in regVal
	 ** from it. Or, if reg1 is not numeric (it is a NULL, a text value or a blob),
	 ** then leave reg1 as it is. In pseudo-code, this is implemented as:
	 **
	 **   if( reg1>='' ) goto addrGe;
	 **   reg1 = reg1 +/- regVal
	 **   addrGe:
	 **
	 ** Since all strings and blobs are greater-than-or-equal-to an empty string,
	 ** the add/subtract is skipped for these, as required. If reg1 is a NULL,
	 ** then the arithmetic is performed, but since adding or subtracting from
	 ** NULL is always NULL anyway, this case is handled as required too.  */
	_sqlite3VdbeAddOp4(tls, v, int32(OP_String8), 0, regString, 0, __ccgo_ts+1693, -int32(1))
	addrGe = _sqlite3VdbeAddOp3(tls, v, int32(OP_Ge), regString, 0, reg1)
	if op == int32(OP_Ge) && arith == int32(OP_Add) || op == int32(OP_Le) && arith == int32(OP_Subtract) {
		_sqlite3VdbeAddOp3(tls, v, op, reg2, lbl, reg1)
	}
	_sqlite3VdbeAddOp3(tls, v, arith, regVal, reg1, reg1)
	_sqlite3VdbeJumpHere(tls, v, addrGe)
	/* Compare registers reg2 and reg1, taking the jump if required. Note that
	 ** control skips over this test if the BIGNULL flag is set and either
	 ** reg1 or reg2 contain a NULL value.  */
	_sqlite3VdbeAddOp3(tls, v, op, reg2, lbl, reg1)
	pColl = _sqlite3ExprNNCollSeq(tls, pParse, (*(*TExprList_item)(unsafe.Pointer(pOrderBy + 8))).FpExpr)
	_sqlite3VdbeAppendP4(tls, v, pColl, -int32(2))
	_sqlite3VdbeChangeP5(tls, v, uint16(SQLITE_NULLEQ))
	_sqlite3VdbeResolveLabel(tls, v, addrDone)
	_sqlite3ReleaseTempReg(tls, pParse, reg1)
	_sqlite3ReleaseTempReg(tls, pParse, reg2)
}

func _windowFind(tls *libc.TLS, pParse uintptr, pList uintptr, zName uintptr) (r uintptr) {
	bp := tls.Alloc(16)
	defer tls.Free(16)
	var p uintptr
	_ = p
	p = pList
	for {
		if !(p != 0) {
			break
		}
		if _sqlite3StrICmp(tls, (*TWindow)(unsafe.Pointer(p)).FzName, zName) == 0 {
			break
		}
		goto _1
	_1:
		;
		p = (*TWindow)(unsafe.Pointer(p)).FpNextWin
	}
	if p == uintptr(0) {
		_sqlite3ErrorMsg(tls, pParse, __ccgo_ts+24269, libc.VaList(bp+8, zName))
	}
	return p
}

// C documentation
//
//	/*
//	** The following routine is called if the stack overflows.
//	*/
func _yyStackOverflow(tls *libc.TLS, yypParser uintptr) {
	var pParse uintptr
	_ = pParse
	pParse = (*TyyParser)(unsafe.Pointer(yypParser)).FpParse
	for (*TyyParser)(unsafe.Pointer(yypParser)).Fyytos > (*TyyParser)(unsafe.Pointer(yypParser)).Fyystack {
		_yy_pop_parser_stack(tls, yypParser)
	}
	/* Here code is inserted which will execute if the parser
	 ** stack every overflows */
	/******** Begin %stack_overflow code ******************************************/
	if (*TParse)(unsafe.Pointer(pParse)).FnErr == 0 {
		_sqlite3ErrorMsg(tls, pParse, __ccgo_ts+24972, 0)
	}
	/******** End %stack_overflow code ********************************************/
	/* Suppress warning about unused %extra_argument var */
	(*TyyParser)(unsafe.Pointer(yypParser)).FpParse = pParse
}

/*
** Print tracing information for a SHIFT action
 */

type daddr32_t = Tdaddr32_t

type mbstate_t = Tmbstate_t

type paddr_t = Tpaddr_t

type psize_t = Tpsize_t

type t__clock_t = int64

type t__cpuid_t = uint64

type t__dev_t = int32

type t__id_t = uint32

type t__kbind = struct {
	Fkb_addr uintptr
	Fkb_size Tsize_t
}

/*
** Try to determine if gethostuuid() is available based on standard
** macros.  This might sometimes compute the wrong value for some
** obscure platforms.  For those cases, simply compile with one of
** the following:
**
**    -DHAVE_GETHOSTUUID=0
**    -DHAVE_GETHOSTUUID=1
**
** None if this matters except when building on Apple products with
** -DSQLITE_ENABLE_LOCKING_STYLE.
 */

/*
** Allowed values of unixFile.fsFlags
 */

/*
** If we are to be thread-safe, include the pthreads header.
 */
/* # include <pthread.h> */

/*
** Default permissions when creating a new file
 */

/*
** Default permissions when creating auto proxy dir
 */

/*
** Maximum supported path-length.
 */

/*
** Maximum supported symbolic links
 */

/*
** Remove and stub certain info for WASI (WebAssembly System
** Interface) builds.
 */

/* Always cast the getpid() return type for compatibility with
** kernel modules in VxWorks. */

/*
** Only set the lastErrno if the error code is a real error and not
** a normal expected return code of SQLITE_BUSY or SQLITE_OK
 */

type t__nlink_t = uint32

type t__paddr_t = uint64

type t__psize_t = uint64

type t__rlim_t = uint64

type t__sFstub = struct {
	F_stub int64
}

type t__tfork = struct {
	Ftf_tcb   uintptr
	Ftf_tid   uintptr
	Ftf_stack uintptr
}

type t__timer_t = int32

type t__vaddr_t = uint64

type t__vsize_t = uint64

type t__wchar_t = int32

type tstamps = Ttstamps

type uintmax_t = Tuintmax_t

/*
 * 7.18.2 Limits of specified-width integer types.
 *
 * The following object-like macros specify the minimum and maximum limits
 * of integer types corresponding to the typedef names defined above.
 */

/* 7.18.2.1 Limits of exact-width integer types */

/* 7.18.2.2 Limits of minimum-width integer types */

/* 7.18.2.3 Limits of fastest minimum-width integer types */

/* 7.18.2.4 Limits of integer types capable of holding object pointers */

/* 7.18.2.5 Limits of greatest-width integer types */

/*
 * 7.18.3 Limits of other integer types.
 *
 * The following object-like macros specify the minimum and maximum limits
 * of integer types corresponding to types specified in other standard
 * header files.
 */

/* Limits of ptrdiff_t */

/* Limits of sig_atomic_t */

/* Limit of size_t */

/* Limits of wchar_t */

/* Limits of wint_t */

/*
 * 7.18.4 Macros for integer constants.
 *
 * The following function-like macros expand to integer constants
 * suitable for initializing objects that have integer types corresponding
 * to types defined in <stdint.h>.  The argument in any instance of
 * these macros shall be a decimal, octal, or hexadecimal constant with
 * a value that does not exceed the limits for the corresponding type.
 */

/* 7.18.4.1 Macros for minimum-width integer constants. */

/* 7.18.4.2 Macros for greatest-width integer constants. */

/*
** The following macros are used to cast pointers to integers and
** integers to pointers.  The way you do this varies from one compiler
** to the next, so we have developed the following set of #if statements
** to generate appropriate macros for a wide range of compilers.
**
** The correct "ANSI" way to do this is to use the intptr_t type.
** Unfortunately, that typedef is not available on all compilers, or
** if it is available, it requires an #include of specific headers
** that vary from one machine to the next.
**
** Ticket #3860:  The llvm-gcc-4.2 compiler from Apple chokes on
** the ((void*)&((char*)0)[X]) construct.  But MSVC chokes on ((void*)(X)).
** So we have to define the macros in different ways depending on the
** compiler.
 */

/*
** Macros to hint to the compiler that a function should or should not be
** inlined.
 */

/*
** Make sure that the compiler intrinsics we desire are enabled when
** compiling with an appropriate version of MSVC unless prevented by
** the SQLITE_DISABLE_INTRINSIC define.
 */

/*
** Enable SQLITE_USE_SEH by default on MSVC builds.  Only omit
** SEH support if the -DSQLITE_OMIT_SEH option is given.
 */

/*
** Enable SQLITE_DIRECT_OVERFLOW_READ, unless the build explicitly
** disables it using -DSQLITE_DIRECT_OVERFLOW_READ=0
 */
/* In all other cases, enable */

/*
** The SQLITE_THREADSAFE macro must be defined as 0, 1, or 2.
** 0 means mutexes are permanently disable and the library is never
** threadsafe.  1 means the library is serialized which is the highest
** level of threadsafety.  2 means the library is multithreaded - multiple
** threads can use SQLite as long as no two threads try to use the same
** database connection at the same time.
**
** Older versions of SQLite used an optional THREADSAFE macro.
** We support that for legacy.
**
** To ensure that the correct value of "THREADSAFE" is reported when querying
** for compile-time options at runtime (e.g. "PRAGMA compile_options"), this
** logic is partially replicated in ctime.c. If it is updated here, it should
** also be updated there.
 */

/*
** Powersafe overwrite is on by default.  But can be turned off using
** the -DSQLITE_POWERSAFE_OVERWRITE=0 command-line option.
 */

/*
** EVIDENCE-OF: R-25715-37072 Memory allocation statistics are enabled by
** default unless SQLite is compiled with SQLITE_DEFAULT_MEMSTATUS=0 in
** which case memory allocation statistics are disabled by default.
 */

/*
** Exactly one of the following macros must be defined in order to
** specify which memory allocation subsystem to use.
**
**     SQLITE_SYSTEM_MALLOC          // Use normal system malloc()
**     SQLITE_WIN32_MALLOC           // Use Win32 native heap API
**     SQLITE_ZERO_MALLOC            // Use a stub allocator that always fails
**     SQLITE_MEMDEBUG               // Debugging version of system malloc()
**
** On Windows, if the SQLITE_WIN32_MALLOC_VALIDATE macro is defined and the
** assert() macro is enabled, each call into the Win32 native heap subsystem
** will cause HeapValidate to be called.  If heap validation should fail, an
** assertion will be triggered.
**
** If none of the above are defined, then set SQLITE_SYSTEM_MALLOC as
** the default.
 */

/*
** If SQLITE_MALLOC_SOFT_LIMIT is not zero, then try to keep the
** sizes of memory allocations below this value where possible.
 */

/*
** We need to define _XOPEN_SOURCE as follows in order to enable
** recursive mutexes on most Unix systems and fchmod() on OpenBSD.
** But _XOPEN_SOURCE define causes problems for Mac OS X, so omit
** it.
 */

/*
** NDEBUG and SQLITE_DEBUG are opposites.  It should always be true that
** defined(NDEBUG)==!defined(SQLITE_DEBUG).  If this is not currently true,
** make it true by defining or undefining NDEBUG.
**
** Setting NDEBUG makes the code smaller and faster by disabling the
** assert() statements in the code.  So we want the default action
** to be for NDEBUG to be set and NDEBUG to be undefined only if SQLITE_DEBUG
** is set.  Thus NDEBUG becomes an opt-in rather than an opt-out
** feature.
 */

/*
** Enable SQLITE_ENABLE_EXPLAIN_COMMENTS if SQLITE_DEBUG is turned on.
 */

/*
** The testcase() macro is used to aid in coverage testing.  When
** doing coverage testing, the condition inside the argument to
** testcase() must be evaluated both true and false in order to
** get full branch coverage.  The testcase() macro is inserted
** to help ensure adequate test coverage in places where simple
** condition/decision coverage is inadequate.  For example, testcase()
** can be used to make sure boundary values are tested.  For
** bitmask tests, testcase() can be used to make sure each bit
** is significant and used at least once.  On switch statements
** where multiple cases go to the same block of code, testcase()
** can insure that all cases are evaluated.
 */

/*
** The TESTONLY macro is used to enclose variable declarations or
** other bits of code that are needed to support the arguments
** within testcase() and assert() macros.
 */

/*
** Sometimes we need a small amount of code such as a variable initialization
** to setup for a later assert() statement.  We do not want this code to
** appear when assert() is disabled.  The following macro is therefore
** used to contain that setup code.  The "VVA" acronym stands for
** "Verification, Validation, and Accreditation".  In other words, the
** code within VVA_ONLY() will only run during verification processes.
 */

/*
** Disable ALWAYS() and NEVER() (make them pass-throughs) for coverage
** and mutation testing
 */

/*
** The ALWAYS and NEVER macros surround boolean expressions which
** are intended to always be true or false, respectively.  Such
** expressions could be omitted from the code completely.  But they
** are included in a few cases in order to enhance the resilience
** of SQLite to unexpected behavior - to make the code "self-healing"
** or "ductile" rather than being "brittle" and crashing at the first
** hint of unplanned behavior.
**
** In other words, ALWAYS and NEVER are added for defensive code.
**
** When doing coverage testing ALWAYS and NEVER are hard-coded to
** be true and false so that the unreachable code they specify will
** not be counted as untested code.
 */

/*
** Some conditionals are optimizations only.  In other words, if the
** conditionals are replaced with a constant 1 (true) or 0 (false) then
** the correct answer is still obtained, though perhaps not as quickly.
**
** The following macros mark these optimizations conditionals.
 */

/*
** Some malloc failures are only possible if SQLITE_TEST_REALLOC_STRESS is
** defined.  We need to defend against those failures when testing with
** SQLITE_TEST_REALLOC_STRESS, but we don't want the unreachable branches
** during a normal build.  The following macro can be used to disable tests
** that are always false except when SQLITE_TEST_REALLOC_STRESS is set.
 */

/*
** Declarations used for tracing the operating system interfaces.
 */

/*
** Is the sqlite3ErrName() function needed in the build?  Currently,
** it is needed by "mutex_w32.c" (when debugging), "os_win.c" (when
** OSTRACE is enabled), and by several "test*.c" files (which are
** compiled using SQLITE_TEST).
 */

/*
** SQLITE_ENABLE_EXPLAIN_COMMENTS is incompatible with SQLITE_OMIT_EXPLAIN
 */

/*
** SQLITE_OMIT_VIRTUALTABLE implies SQLITE_OMIT_ALTERTABLE
 */

/*
** Return true (non-zero) if the input is an integer that is too large
** to fit in 32-bits.  This macro is used inside of various testcase()
** macros to verify that we have tested SQLite for large-file support.
 */

/*
** The macro unlikely() is a hint that surrounds a boolean
** expression that is usually false.  Macro likely() surrounds
** a boolean expression that is usually true.  These hints could,
** in theory, be used by the compiler to generate better code, but
** currently they are just comments for human readers.
 */

/************** Include hash.h in the middle of sqliteInt.h ******************/
/************** Begin file hash.h ********************************************/
/*
** 2001 September 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 is the header file for the generic hash-table implementation
** used in SQLite.
 */

type vaddr_t = Tvaddr_t

type vsize_t = Tvsize_t
