6c92f85d10
Bring the Nexus/Praxis/Hexis integration in line with MAVEN_ECOSYSTEM_ARCHITECTURE.md: - Praxis over HTTP: drop the in-process praxis.db open (praxisstore/ praxistools) and call praxisd's /api/v1/tools/* API via a new praxisClient. Honors the "no component reads another's DB" invariant (AC#12). PraxisConfig.DBPath -> URL. - Hexis confirmation gate: mutating capabilities (ReadOnly=false) now park a bound pendingHexis confirmation and require a spoken "да" before executing; read-only run immediately (AC#7, no auto attention->action). - Capability safety: >1 verb match is ambiguous -> ask instead of firing the first; ambiguous Nexus resolution asks for clarification (AC#2). - Correlation IDs on Hexis execute, recorded in the cross-service trace. - Bug: importance arrives as JSON float64 over HTTP, not int. - Tests: confirm-gate, decline, read-only, and ambiguity paths. Build: vendor/ bakes in the hexis client (replace-directed at a sibling repo outside the Docker context); Dockerfile builds from vendor and no longer `go mod download`s the unreachable replace paths. Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
41339 lines
1.7 MiB
Plaintext
41339 lines
1.7 MiB
Plaintext
// Code generated for freebsd/386 by 'generator -mlong-double-64 --package-name libsqlite3 --prefix-enumerator=_ --prefix-external=x_ --prefix-field=F --prefix-static-internal=_ --prefix-static-none=_ --prefix-tagged-enum=_ --prefix-tagged-struct=T --prefix-tagged-union=T --prefix-typename=T --prefix-undefined=_ -ignore-unsupported-alignment -ignore-link-errors -import=sync -DHAVE_USLEEP -DLONGDOUBLE_TYPE=double -DNDEBUG -DSQLITE_DEFAULT_MEMSTATUS=0 -DSQLITE_DISABLE_INTRINSIC -DSQLITE_ENABLE_COLUMN_METADATA -DSQLITE_ENABLE_DBPAGE_VTAB -DSQLITE_ENABLE_DBSTAT_VTAB -DSQLITE_ENABLE_FTS5 -DSQLITE_ENABLE_GEOPOLY -DSQLITE_ENABLE_JSON1 -DSQLITE_ENABLE_MATH_FUNCTIONS -DSQLITE_ENABLE_MEMORY_MANAGEMENT -DSQLITE_ENABLE_OFFSET_SQL_FUNC -DSQLITE_ENABLE_PREUPDATE_HOOK -DSQLITE_ENABLE_RBU -DSQLITE_ENABLE_RTREE -DSQLITE_ENABLE_SESSION -DSQLITE_ENABLE_SNAPSHOT -DSQLITE_ENABLE_STAT4 -DSQLITE_ENABLE_UNLOCK_NOTIFY -DSQLITE_HAVE_ZLIB=1 -DSQLITE_LIKE_DOESNT_MATCH_BLOBS -DSQLITE_SOUNDEX -DSQLITE_THREADSAFE=1 -DSQLITE_WITHOUT_ZONEMALLOC -D_LARGEFILE64_SOURCE -I /home/jnml/src/modernc.org/builder/.exclude/modernc.org/libc/include/freebsd/386 -I /home/jnml/src/modernc.org/builder/.exclude/modernc.org/libz/include/freebsd/386 -I /home/jnml/src/modernc.org/builder/.exclude/modernc.org/libtcl8.6/include/freebsd/386 -extended-errors -o sqlite3.go sqlite3.c -DSQLITE_MUTEX_NOOP -DSQLITE_OS_UNIX=1 -ltcl8.6 -eval-all-macros', DO NOT EDIT.
|
|
|
|
//go:build freebsd && 386
|
|
|
|
package sqlite3
|
|
|
|
import (
|
|
"unsafe"
|
|
|
|
"modernc.org/libc"
|
|
)
|
|
|
|
const CLOCK_BOOTTIME = 5
|
|
|
|
type T_RuneLocale = struct {
|
|
F__magic [8]int8
|
|
F__encoding [32]int8
|
|
F__sgetrune uintptr
|
|
F__sputrune uintptr
|
|
F__invalid_rune t__rune_t
|
|
F__runetype [256]uint32
|
|
F__maplower [256]t__rune_t
|
|
F__mapupper [256]t__rune_t
|
|
F__runetype_ext T_RuneRange
|
|
F__maplower_ext T_RuneRange
|
|
F__mapupper_ext T_RuneRange
|
|
F__variable uintptr
|
|
F__variable_len int32
|
|
}
|
|
|
|
type Tstat = struct {
|
|
Fst_dev Tdev_t
|
|
Fst_ino Tino_t
|
|
Fst_nlink Tnlink_t
|
|
Fst_mode Tmode_t
|
|
Fst_bsdflags t__int16_t
|
|
Fst_uid Tuid_t
|
|
Fst_gid Tgid_t
|
|
Fst_padding1 t__int32_t
|
|
Fst_rdev Tdev_t
|
|
Fst_atim_ext t__int32_t
|
|
Fst_atim Ttimespec
|
|
Fst_mtim_ext t__int32_t
|
|
Fst_mtim Ttimespec
|
|
Fst_ctim_ext t__int32_t
|
|
Fst_ctim Ttimespec
|
|
Fst_btim_ext t__int32_t
|
|
Fst_birthtim Ttimespec
|
|
Fst_size Toff_t
|
|
Fst_blocks Tblkcnt_t
|
|
Fst_blksize Tblksize_t
|
|
Fst_flags Tfflags_t
|
|
Fst_gen t__uint64_t
|
|
Fst_filerev t__uint64_t
|
|
Fst_spare [9]t__uint64_t
|
|
}
|
|
|
|
// C documentation
|
|
//
|
|
// /*
|
|
// ** Given the name of a compile-time option, return true if that option
|
|
// ** was used and false if not.
|
|
// **
|
|
// ** The name can optionally begin with "SQLITE_" but the "SQLITE_" prefix
|
|
// ** is not required for a match.
|
|
// */
|
|
func Xsqlite3_compileoption_used(tls *libc.TLS, zOptName uintptr) (r int32) {
|
|
bp := tls.Alloc(16)
|
|
defer tls.Free(16)
|
|
var azCompileOpt uintptr
|
|
var i, n int32
|
|
var _ /* nOpt at bp+0 */ int32
|
|
_, _, _ = azCompileOpt, i, n
|
|
azCompileOpt = _sqlite3CompileOptions(tls, bp)
|
|
if Xsqlite3_strnicmp(tls, zOptName, __ccgo_ts+26366, int32(7)) == 0 {
|
|
zOptName = zOptName + uintptr(7)
|
|
}
|
|
n = _sqlite3Strlen30(tls, zOptName)
|
|
/* Since nOpt is normally in single digits, a linear search is
|
|
** adequate. No need for a binary search. */
|
|
i = 0
|
|
for {
|
|
if !(i < **(**int32)(__ccgo_up(bp))) {
|
|
break
|
|
}
|
|
if Xsqlite3_strnicmp(tls, zOptName, **(**uintptr)(__ccgo_up(azCompileOpt + uintptr(i)*4)), n) == 0 && _sqlite3IsIdChar(tls, libc.Uint8FromInt8(**(**int8)(__ccgo_up(**(**uintptr)(__ccgo_up(azCompileOpt + uintptr(i)*4)) + uintptr(n))))) == 0 {
|
|
return int32(1)
|
|
}
|
|
goto _1
|
|
_1:
|
|
;
|
|
i = i + 1
|
|
}
|
|
return 0
|
|
}
|
|
|
|
// 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+4183, 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+172+8, libc.Uint32FromInt32(1), 3, 0x8)
|
|
Xsqlite3_step(tls, **(**uintptr)(__ccgo_up(bp)))
|
|
libc.SetBitFieldPtr8Uint32(db+172+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
|
|
//
|
|
// /*
|
|
// ** Execute SQL code. Return one of the SQLITE_ success/failure
|
|
// ** codes. Also write an error message into memory obtained from
|
|
// ** malloc() and make *pzErrMsg point to that message.
|
|
// **
|
|
// ** If the SQL is a query, then for each row in the query result
|
|
// ** the xCallback() function is called. pArg becomes the first
|
|
// ** argument to xCallback(). If xCallback=NULL then no callback
|
|
// ** is invoked, even for queries.
|
|
// */
|
|
func Xsqlite3_exec(tls *libc.TLS, db uintptr, zSql uintptr, __ccgo_fp_xCallback Tsqlite3_callback, pArg uintptr, pzErrMsg uintptr) (r int32) {
|
|
bp := tls.Alloc(16)
|
|
defer tls.Free(16)
|
|
var azCols, azVals uintptr
|
|
var callbackIsInit, i, nCol, rc int32
|
|
var _ /* pStmt at bp+4 */ uintptr
|
|
var _ /* zLeftover at bp+0 */ uintptr
|
|
_, _, _, _, _, _ = azCols, azVals, callbackIsInit, i, nCol, rc
|
|
rc = SQLITE_OK /* Tail of unprocessed SQL */
|
|
**(**uintptr)(__ccgo_up(bp + 4)) = uintptr(0) /* The current SQL statement */
|
|
azCols = uintptr(0) /* True if callback data is initialized */
|
|
if !(_sqlite3SafetyCheckOk(tls, db) != 0) {
|
|
return _sqlite3MisuseError(tls, int32(142334))
|
|
}
|
|
if zSql == uintptr(0) {
|
|
zSql = __ccgo_ts + 1702
|
|
}
|
|
Xsqlite3_mutex_enter(tls, (*Tsqlite3)(unsafe.Pointer(db)).Fmutex)
|
|
_sqlite3Error(tls, db, SQLITE_OK)
|
|
for rc == SQLITE_OK && **(**int8)(__ccgo_up(zSql)) != 0 {
|
|
nCol = 0
|
|
azVals = uintptr(0)
|
|
**(**uintptr)(__ccgo_up(bp + 4)) = uintptr(0)
|
|
rc = Xsqlite3_prepare_v2(tls, db, zSql, -int32(1), bp+4, bp)
|
|
if rc != SQLITE_OK {
|
|
continue
|
|
}
|
|
if !(**(**uintptr)(__ccgo_up(bp + 4)) != 0) {
|
|
/* this happens for a comment or white-space */
|
|
zSql = **(**uintptr)(__ccgo_up(bp))
|
|
continue
|
|
}
|
|
callbackIsInit = 0
|
|
for int32(1) != 0 {
|
|
rc = Xsqlite3_step(tls, **(**uintptr)(__ccgo_up(bp + 4)))
|
|
/* Invoke the callback function if required */
|
|
if __ccgo_fp_xCallback != 0 && (int32(SQLITE_ROW) == rc || int32(SQLITE_DONE) == rc && !(callbackIsInit != 0) && (*Tsqlite3)(unsafe.Pointer(db)).Fflags&uint64(SQLITE_NullCallback) != 0) {
|
|
if !(callbackIsInit != 0) {
|
|
nCol = Xsqlite3_column_count(tls, **(**uintptr)(__ccgo_up(bp + 4)))
|
|
azCols = _sqlite3DbMallocRaw(tls, db, uint64(libc.Uint32FromInt32(libc.Int32FromInt32(2)*nCol+libc.Int32FromInt32(1))*uint32(4)))
|
|
if azCols == uintptr(0) {
|
|
goto exec_out
|
|
}
|
|
i = 0
|
|
for {
|
|
if !(i < nCol) {
|
|
break
|
|
}
|
|
**(**uintptr)(__ccgo_up(azCols + uintptr(i)*4)) = Xsqlite3_column_name(tls, **(**uintptr)(__ccgo_up(bp + 4)), i)
|
|
/* sqlite3VdbeSetColName() installs column names as UTF8
|
|
** strings so there is no way for sqlite3_column_name() to fail. */
|
|
goto _1
|
|
_1:
|
|
;
|
|
i = i + 1
|
|
}
|
|
callbackIsInit = int32(1)
|
|
}
|
|
if rc == int32(SQLITE_ROW) {
|
|
azVals = azCols + uintptr(nCol)*4
|
|
i = 0
|
|
for {
|
|
if !(i < nCol) {
|
|
break
|
|
}
|
|
**(**uintptr)(__ccgo_up(azVals + uintptr(i)*4)) = Xsqlite3_column_text(tls, **(**uintptr)(__ccgo_up(bp + 4)), i)
|
|
if !(**(**uintptr)(__ccgo_up(azVals + uintptr(i)*4)) != 0) && Xsqlite3_column_type(tls, **(**uintptr)(__ccgo_up(bp + 4)), i) != int32(SQLITE_NULL) {
|
|
_sqlite3OomFault(tls, db)
|
|
goto exec_out
|
|
}
|
|
goto _2
|
|
_2:
|
|
;
|
|
i = i + 1
|
|
}
|
|
**(**uintptr)(__ccgo_up(azVals + uintptr(i)*4)) = uintptr(0)
|
|
}
|
|
if (*(*func(*libc.TLS, uintptr, int32, uintptr, uintptr) int32)(unsafe.Pointer(&struct{ uintptr }{__ccgo_fp_xCallback})))(tls, pArg, nCol, azVals, azCols) != 0 {
|
|
/* EVIDENCE-OF: R-38229-40159 If the callback function to
|
|
** sqlite3_exec() returns non-zero, then sqlite3_exec() will
|
|
** return SQLITE_ABORT. */
|
|
rc = int32(SQLITE_ABORT)
|
|
_sqlite3VdbeFinalize(tls, **(**uintptr)(__ccgo_up(bp + 4)))
|
|
**(**uintptr)(__ccgo_up(bp + 4)) = uintptr(0)
|
|
_sqlite3Error(tls, db, int32(SQLITE_ABORT))
|
|
goto exec_out
|
|
}
|
|
}
|
|
if rc != int32(SQLITE_ROW) {
|
|
rc = _sqlite3VdbeFinalize(tls, **(**uintptr)(__ccgo_up(bp + 4)))
|
|
**(**uintptr)(__ccgo_up(bp + 4)) = uintptr(0)
|
|
zSql = **(**uintptr)(__ccgo_up(bp))
|
|
for libc.Int32FromUint8(_sqlite3CtypeMap[libc.Uint8FromInt8(**(**int8)(__ccgo_up(zSql)))])&int32(0x01) != 0 {
|
|
zSql = zSql + 1
|
|
}
|
|
break
|
|
}
|
|
}
|
|
_sqlite3DbFree(tls, db, azCols)
|
|
azCols = uintptr(0)
|
|
}
|
|
goto exec_out
|
|
exec_out:
|
|
;
|
|
if **(**uintptr)(__ccgo_up(bp + 4)) != 0 {
|
|
_sqlite3VdbeFinalize(tls, **(**uintptr)(__ccgo_up(bp + 4)))
|
|
}
|
|
_sqlite3DbFree(tls, db, azCols)
|
|
rc = _sqlite3ApiExit(tls, db, rc)
|
|
if rc != SQLITE_OK && pzErrMsg != 0 {
|
|
**(**uintptr)(__ccgo_up(pzErrMsg)) = _sqlite3DbStrDup(tls, uintptr(0), Xsqlite3_errmsg(tls, db))
|
|
if **(**uintptr)(__ccgo_up(pzErrMsg)) == uintptr(0) {
|
|
rc = int32(SQLITE_NOMEM)
|
|
_sqlite3Error(tls, db, int32(SQLITE_NOMEM))
|
|
}
|
|
} else {
|
|
if pzErrMsg != 0 {
|
|
**(**uintptr)(__ccgo_up(pzErrMsg)) = uintptr(0)
|
|
}
|
|
}
|
|
Xsqlite3_mutex_leave(tls, (*Tsqlite3)(unsafe.Pointer(db)).Fmutex)
|
|
return rc
|
|
}
|
|
|
|
// C documentation
|
|
//
|
|
// /*
|
|
// ** Render a string given by "fmt" into the StrAccum object.
|
|
// */
|
|
func Xsqlite3_str_vappendf(tls *libc.TLS, pAccum uintptr, fmt uintptr, ap Tva_list) {
|
|
bp := tls.Alloc(128)
|
|
defer tls.Free(128)
|
|
var adj, c, e2, exp, iRound, idx, ii, ix, j, length, nOut, needQuote, nn, nn1, nn2, nn3, precision, width, x, v2, v3 int32
|
|
var bArgList, base Tu8
|
|
var bufpt, cset, escarg, infop, pArgList, pExpr, pItem, pSel, pToken, pre, z, zExtra, zOut, v4 uintptr
|
|
var cThousand, done, flag_alternateform, flag_altform2, flag_dp, flag_leftjustify, flag_long, flag_prefix, flag_rtz, flag_zeropad, xtype, v5, v6, v7, v8, v9 TetByte
|
|
var ch, px, wx uint32
|
|
var ch1, prefix, q, x1, v54 int8
|
|
var i, j1, k, n1, nBack, nCopyBytes, nCtrl, nPad, nPrior, szBufNeeded, v, v90 Ti64
|
|
var longvalue Tsqlite_uint64
|
|
var n Tu64
|
|
var realvalue float64
|
|
var v12 bool
|
|
var _ /* buf at bp+0 */ [70]int8
|
|
var _ /* s at bp+72 */ TFpDecode
|
|
_, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _ = adj, bArgList, base, bufpt, c, cThousand, ch, ch1, cset, done, e2, escarg, exp, flag_alternateform, flag_altform2, flag_dp, flag_leftjustify, flag_long, flag_prefix, flag_rtz, flag_zeropad, i, iRound, idx, ii, infop, ix, j, j1, k, length, longvalue, n, n1, nBack, nCopyBytes, nCtrl, nOut, nPad, nPrior, needQuote, nn, nn1, nn2, nn3, pArgList, pExpr, pItem, pSel, pToken, pre, precision, prefix, px, q, realvalue, szBufNeeded, v, width, wx, x, x1, xtype, z, zExtra, zOut, v12, v2, v3, v4, v5, v54, v6, v7, v8, v9, v90 /* Thousands separator for %d and %u */
|
|
xtype = uint8(etINVALID) /* Size of the rendering buffer */
|
|
zExtra = uintptr(0) /* True if trailing zeros should be removed */
|
|
pArgList = uintptr(0) /* Conversion buffer */
|
|
/* pAccum never starts out with an empty buffer that was obtained from
|
|
** malloc(). This precondition is required by the mprintf("%z...")
|
|
** optimization. */
|
|
bufpt = uintptr(0)
|
|
if libc.Int32FromUint8((*Tsqlite3_str)(unsafe.Pointer(pAccum)).FprintfFlags)&int32(SQLITE_PRINTF_SQLFUNC) != 0 {
|
|
pArgList = libc.VaUintptr(&ap)
|
|
bArgList = uint8(1)
|
|
} else {
|
|
bArgList = uint8(0)
|
|
}
|
|
for {
|
|
v2 = int32(**(**int8)(__ccgo_up(fmt)))
|
|
c = v2
|
|
if !(v2 != 0) {
|
|
break
|
|
}
|
|
if c != int32('%') {
|
|
bufpt = fmt
|
|
fmt = libc.Xstrchr(tls, fmt, int32('%'))
|
|
if fmt == uintptr(0) {
|
|
fmt = bufpt + uintptr(libc.Xstrlen(tls, bufpt))
|
|
}
|
|
Xsqlite3_str_append(tls, pAccum, bufpt, int32(fmt)-int32(bufpt))
|
|
if int32(**(**int8)(__ccgo_up(fmt))) == 0 {
|
|
break
|
|
}
|
|
}
|
|
fmt = fmt + 1
|
|
v4 = fmt
|
|
v2 = int32(**(**int8)(__ccgo_up(v4)))
|
|
c = v2
|
|
if v2 == 0 {
|
|
Xsqlite3_str_append(tls, pAccum, __ccgo_ts+1686, int32(1))
|
|
break
|
|
}
|
|
/* Find out what flags are present */
|
|
v9 = libc.Uint8FromInt32(0)
|
|
flag_zeropad = v9
|
|
v8 = v9
|
|
flag_altform2 = v8
|
|
v7 = v8
|
|
flag_alternateform = v7
|
|
v6 = v7
|
|
cThousand = v6
|
|
v5 = v6
|
|
flag_prefix = v5
|
|
flag_leftjustify = v5
|
|
done = uint8(0)
|
|
width = 0
|
|
flag_long = uint8(0)
|
|
precision = -int32(1)
|
|
for {
|
|
switch c {
|
|
case int32('-'):
|
|
flag_leftjustify = uint8(1)
|
|
case int32('+'):
|
|
flag_prefix = uint8('+')
|
|
case int32(' '):
|
|
flag_prefix = uint8(' ')
|
|
case int32('#'):
|
|
flag_alternateform = uint8(1)
|
|
case int32('!'):
|
|
flag_altform2 = uint8(1)
|
|
case int32('0'):
|
|
flag_zeropad = uint8(1)
|
|
case int32(','):
|
|
cThousand = uint8(',')
|
|
default:
|
|
done = uint8(1)
|
|
case int32('l'):
|
|
flag_long = uint8(1)
|
|
fmt = fmt + 1
|
|
v4 = fmt
|
|
c = int32(**(**int8)(__ccgo_up(v4)))
|
|
if c == int32('l') {
|
|
fmt = fmt + 1
|
|
v4 = fmt
|
|
c = int32(**(**int8)(__ccgo_up(v4)))
|
|
flag_long = uint8(2)
|
|
}
|
|
done = uint8(1)
|
|
case int32('1'):
|
|
fallthrough
|
|
case int32('2'):
|
|
fallthrough
|
|
case int32('3'):
|
|
fallthrough
|
|
case int32('4'):
|
|
fallthrough
|
|
case int32('5'):
|
|
fallthrough
|
|
case int32('6'):
|
|
fallthrough
|
|
case int32('7'):
|
|
fallthrough
|
|
case int32('8'):
|
|
fallthrough
|
|
case int32('9'):
|
|
wx = libc.Uint32FromInt32(c - int32('0'))
|
|
for {
|
|
fmt = fmt + 1
|
|
v4 = fmt
|
|
v2 = int32(**(**int8)(__ccgo_up(v4)))
|
|
c = v2
|
|
if !(v2 >= int32('0') && c <= int32('9')) {
|
|
break
|
|
}
|
|
wx = wx*uint32(10) + libc.Uint32FromInt32(c) - uint32('0')
|
|
}
|
|
width = libc.Int32FromUint32(wx & uint32(0x7fffffff))
|
|
if c != int32('.') && c != int32('l') {
|
|
done = uint8(1)
|
|
} else {
|
|
fmt = fmt - 1
|
|
}
|
|
case int32('*'):
|
|
if bArgList != 0 {
|
|
width = int32(_getIntArg(tls, pArgList))
|
|
} else {
|
|
width = libc.VaInt32(&ap)
|
|
}
|
|
if width < 0 {
|
|
flag_leftjustify = uint8(1)
|
|
if width >= -int32(2147483647) {
|
|
v2 = -width
|
|
} else {
|
|
v2 = 0
|
|
}
|
|
width = v2
|
|
}
|
|
v2 = int32(**(**int8)(__ccgo_up(fmt + 1)))
|
|
c = v2
|
|
if v2 != int32('.') && c != int32('l') {
|
|
fmt = fmt + 1
|
|
v4 = fmt
|
|
c = int32(**(**int8)(__ccgo_up(v4)))
|
|
done = uint8(1)
|
|
}
|
|
case int32('.'):
|
|
fmt = fmt + 1
|
|
v4 = fmt
|
|
c = int32(**(**int8)(__ccgo_up(v4)))
|
|
if c == int32('*') {
|
|
if bArgList != 0 {
|
|
precision = int32(_getIntArg(tls, pArgList))
|
|
} else {
|
|
precision = libc.VaInt32(&ap)
|
|
}
|
|
if precision < 0 {
|
|
if precision >= -int32(2147483647) {
|
|
v2 = -precision
|
|
} else {
|
|
v2 = -int32(1)
|
|
}
|
|
precision = v2
|
|
}
|
|
fmt = fmt + 1
|
|
v4 = fmt
|
|
c = int32(**(**int8)(__ccgo_up(v4)))
|
|
} else {
|
|
px = uint32(0)
|
|
for c >= int32('0') && c <= int32('9') {
|
|
px = px*uint32(10) + libc.Uint32FromInt32(c) - uint32('0')
|
|
fmt = fmt + 1
|
|
v4 = fmt
|
|
c = int32(**(**int8)(__ccgo_up(v4)))
|
|
}
|
|
precision = libc.Int32FromUint32(px & uint32(0x7fffffff))
|
|
}
|
|
if c == int32('l') {
|
|
fmt = fmt - 1
|
|
} else {
|
|
done = uint8(1)
|
|
}
|
|
break
|
|
}
|
|
goto _13
|
|
_13:
|
|
;
|
|
if v12 = !(done != 0); v12 {
|
|
fmt = fmt + 1
|
|
v4 = fmt
|
|
v2 = int32(**(**int8)(__ccgo_up(v4)))
|
|
c = v2
|
|
}
|
|
if !(v12 && v2 != 0) {
|
|
break
|
|
}
|
|
}
|
|
/* Fetch the info entry for the field */
|
|
/* Fast hash-table lookup */
|
|
idx = libc.Int32FromUint32(libc.Uint32FromInt32(c) % uint32(23))
|
|
if v12 = int32(_fmtinfo[idx].Ffmttype) == c; !v12 {
|
|
v2 = int32(_fmtinfo[idx].FiNxt)
|
|
idx = v2
|
|
}
|
|
if v12 || int32(_fmtinfo[v2].Ffmttype) == c {
|
|
infop = uintptr(unsafe.Pointer(&_fmtinfo)) + uintptr(idx)*7
|
|
xtype = (*Tet_info)(unsafe.Pointer(infop)).Ftype1
|
|
} else {
|
|
infop = uintptr(unsafe.Pointer(&_fmtinfo))
|
|
xtype = uint8(etINVALID)
|
|
}
|
|
/*
|
|
** At this point, variables are initialized as follows:
|
|
**
|
|
** flag_alternateform TRUE if a '#' is present.
|
|
** flag_altform2 TRUE if a '!' is present.
|
|
** flag_prefix '+' or ' ' or zero
|
|
** flag_leftjustify TRUE if a '-' is present or if the
|
|
** field width was negative.
|
|
** flag_zeropad TRUE if the width began with 0.
|
|
** flag_long 1 for "l", 2 for "ll"
|
|
** width The specified field width. This is
|
|
** always non-negative. Zero is the default.
|
|
** precision The specified precision. The default
|
|
** is -1.
|
|
** xtype The class of the conversion.
|
|
** infop Pointer to the appropriate info struct.
|
|
*/
|
|
switch libc.Int32FromUint8(xtype) {
|
|
case int32(etPOINTER):
|
|
goto _27
|
|
case etRADIX:
|
|
goto _28
|
|
case int32(etORDINAL):
|
|
goto _29
|
|
case int32(etDECIMAL):
|
|
goto _30
|
|
case int32(etGENERIC):
|
|
goto _31
|
|
case int32(etEXP):
|
|
goto _32
|
|
case int32(etFLOAT):
|
|
goto _33
|
|
case int32(etSIZE):
|
|
goto _34
|
|
case int32(etPERCENT):
|
|
goto _35
|
|
case int32(etCHARX):
|
|
goto _36
|
|
case int32(etDYNSTRING):
|
|
goto _37
|
|
case int32(etSTRING):
|
|
goto _38
|
|
case int32(etESCAPE_w):
|
|
goto _39
|
|
case int32(etESCAPE_Q):
|
|
goto _40
|
|
case int32(etESCAPE_q):
|
|
goto _41
|
|
case int32(etTOKEN):
|
|
goto _42
|
|
case int32(etSRCITEM):
|
|
goto _43
|
|
default:
|
|
goto _44
|
|
}
|
|
goto _45
|
|
_27:
|
|
;
|
|
flag_long = uint8(1)
|
|
_29:
|
|
;
|
|
_28:
|
|
;
|
|
cThousand = uint8(0)
|
|
_30:
|
|
;
|
|
if libc.Int32FromUint8((*Tet_info)(unsafe.Pointer(infop)).Fflags)&int32(FLAG_SIGNED) != 0 {
|
|
if bArgList != 0 {
|
|
v = _getIntArg(tls, pArgList)
|
|
} else {
|
|
if flag_long != 0 {
|
|
if libc.Int32FromUint8(flag_long) == int32(2) {
|
|
v = libc.VaInt64(&ap)
|
|
} else {
|
|
v = int64(libc.VaInt32(&ap))
|
|
}
|
|
} else {
|
|
v = int64(libc.VaInt32(&ap))
|
|
}
|
|
}
|
|
if v < 0 {
|
|
longvalue = libc.Uint64FromInt64(^v)
|
|
longvalue = longvalue + 1
|
|
prefix = int8('-')
|
|
} else {
|
|
longvalue = libc.Uint64FromInt64(v)
|
|
prefix = libc.Int8FromUint8(flag_prefix)
|
|
}
|
|
} else {
|
|
if bArgList != 0 {
|
|
longvalue = libc.Uint64FromInt64(_getIntArg(tls, pArgList))
|
|
} else {
|
|
if flag_long != 0 {
|
|
if libc.Int32FromUint8(flag_long) == int32(2) {
|
|
longvalue = libc.VaUint64(&ap)
|
|
} else {
|
|
longvalue = uint64(libc.VaUint32(&ap))
|
|
}
|
|
} else {
|
|
longvalue = uint64(libc.VaUint32(&ap))
|
|
}
|
|
}
|
|
prefix = 0
|
|
}
|
|
if longvalue == uint64(0) {
|
|
flag_alternateform = uint8(0)
|
|
}
|
|
if flag_zeropad != 0 && precision < width-libc.BoolInt32(int32(prefix) != 0) {
|
|
precision = width - libc.BoolInt32(int32(prefix) != 0)
|
|
}
|
|
if precision < libc.Int32FromInt32(SQLITE_PRINT_BUF_SIZE)-libc.Int32FromInt32(10)-libc.Int32FromInt32(SQLITE_PRINT_BUF_SIZE)/libc.Int32FromInt32(3) {
|
|
nOut = int32(SQLITE_PRINT_BUF_SIZE)
|
|
zOut = bp
|
|
} else {
|
|
n = libc.Uint64FromInt32(precision) + uint64(10)
|
|
if cThousand != 0 {
|
|
n = n + libc.Uint64FromInt32(precision/int32(3))
|
|
}
|
|
v4 = _printfTempBuf(tls, pAccum, libc.Int64FromUint64(n))
|
|
zExtra = v4
|
|
zOut = v4
|
|
if zOut == uintptr(0) {
|
|
return
|
|
}
|
|
nOut = libc.Int32FromUint64(n)
|
|
}
|
|
bufpt = zOut + uintptr(nOut-int32(1))
|
|
if libc.Int32FromUint8(xtype) == int32(etORDINAL) {
|
|
x = libc.Int32FromUint64(longvalue % libc.Uint64FromInt32(10))
|
|
if x >= int32(4) || longvalue/uint64(10)%uint64(10) == uint64(1) {
|
|
x = 0
|
|
}
|
|
bufpt = bufpt - 1
|
|
v4 = bufpt
|
|
**(**int8)(__ccgo_up(v4)) = _zOrd[x*int32(2)+int32(1)]
|
|
bufpt = bufpt - 1
|
|
v4 = bufpt
|
|
**(**int8)(__ccgo_up(v4)) = _zOrd[x*int32(2)]
|
|
}
|
|
cset = uintptr(unsafe.Pointer(&_aDigits)) + uintptr((*Tet_info)(unsafe.Pointer(infop)).Fcharset)
|
|
base = (*Tet_info)(unsafe.Pointer(infop)).Fbase
|
|
for cond := true; cond; cond = longvalue > uint64(0) { /* Convert to ascii */
|
|
bufpt = bufpt - 1
|
|
v4 = bufpt
|
|
**(**int8)(__ccgo_up(v4)) = **(**int8)(__ccgo_up(cset + uintptr(longvalue%uint64(base))))
|
|
longvalue = longvalue / uint64(base)
|
|
}
|
|
length = t__predefined_ptrdiff_t(zOut+uintptr(nOut-int32(1))) - int32(bufpt)
|
|
if precision > length { /* zero pad */
|
|
nn = precision - length
|
|
bufpt = bufpt - uintptr(nn)
|
|
libc.Xmemset(tls, bufpt, int32('0'), libc.Uint32FromInt32(nn))
|
|
length = precision
|
|
}
|
|
if cThousand != 0 {
|
|
nn1 = (length - int32(1)) / int32(3) /* Number of "," to insert */
|
|
ix = (length-int32(1))%int32(3) + int32(1)
|
|
bufpt = bufpt - uintptr(nn1)
|
|
idx = 0
|
|
for {
|
|
if !(nn1 > 0) {
|
|
break
|
|
}
|
|
**(**int8)(__ccgo_up(bufpt + uintptr(idx))) = **(**int8)(__ccgo_up(bufpt + uintptr(idx+nn1)))
|
|
ix = ix - 1
|
|
if ix == 0 {
|
|
idx = idx + 1
|
|
v2 = idx
|
|
**(**int8)(__ccgo_up(bufpt + uintptr(v2))) = libc.Int8FromUint8(cThousand)
|
|
nn1 = nn1 - 1
|
|
ix = int32(3)
|
|
}
|
|
goto _50
|
|
_50:
|
|
;
|
|
idx = idx + 1
|
|
}
|
|
}
|
|
if prefix != 0 {
|
|
bufpt = bufpt - 1
|
|
v4 = bufpt
|
|
**(**int8)(__ccgo_up(v4)) = prefix
|
|
} /* Add sign */
|
|
if flag_alternateform != 0 && (*Tet_info)(unsafe.Pointer(infop)).Fprefix != 0 {
|
|
pre = uintptr(unsafe.Pointer(&_aPrefix)) + uintptr((*Tet_info)(unsafe.Pointer(infop)).Fprefix)
|
|
for {
|
|
v54 = **(**int8)(__ccgo_up(pre))
|
|
x1 = v54
|
|
if !(int32(v54) != 0) {
|
|
break
|
|
}
|
|
bufpt = bufpt - 1
|
|
v4 = bufpt
|
|
**(**int8)(__ccgo_up(v4)) = x1
|
|
goto _53
|
|
_53:
|
|
;
|
|
pre = pre + 1
|
|
}
|
|
}
|
|
length = t__predefined_ptrdiff_t(zOut+uintptr(nOut-int32(1))) - int32(bufpt)
|
|
goto _45
|
|
_33:
|
|
;
|
|
_32:
|
|
;
|
|
_31:
|
|
; /* Size needed to hold the output */
|
|
if bArgList != 0 {
|
|
realvalue = _getDoubleArg(tls, pArgList)
|
|
} else {
|
|
realvalue = libc.VaFloat64(&ap)
|
|
}
|
|
if precision < 0 {
|
|
precision = int32(6)
|
|
} /* Set default precision */
|
|
if precision > int32(SQLITE_FP_PRECISION_LIMIT) {
|
|
precision = int32(SQLITE_FP_PRECISION_LIMIT)
|
|
}
|
|
if libc.Int32FromUint8(xtype) == int32(etFLOAT) {
|
|
iRound = -precision
|
|
} else {
|
|
if libc.Int32FromUint8(xtype) == int32(etGENERIC) {
|
|
if precision == 0 {
|
|
precision = int32(1)
|
|
}
|
|
iRound = precision
|
|
} else {
|
|
iRound = precision + int32(1)
|
|
}
|
|
}
|
|
if flag_altform2 != 0 {
|
|
v2 = int32(20)
|
|
} else {
|
|
v2 = int32(16)
|
|
}
|
|
_sqlite3FpDecode(tls, bp+72, realvalue, iRound, v2)
|
|
if (**(**TFpDecode)(__ccgo_up(bp + 72))).FisSpecial != 0 {
|
|
if int32((**(**TFpDecode)(__ccgo_up(bp + 72))).FisSpecial) == int32(2) {
|
|
if flag_zeropad != 0 {
|
|
v4 = __ccgo_ts + 1688
|
|
} else {
|
|
v4 = __ccgo_ts + 1693
|
|
}
|
|
bufpt = v4
|
|
length = _sqlite3Strlen30(tls, bufpt)
|
|
goto _45
|
|
} else {
|
|
if flag_zeropad != 0 {
|
|
**(**int8)(__ccgo_up((**(**TFpDecode)(__ccgo_up(bp + 72))).Fz)) = int8('9')
|
|
(**(**TFpDecode)(__ccgo_up(bp + 72))).FiDP = int32(1000)
|
|
(**(**TFpDecode)(__ccgo_up(bp + 72))).Fn = int32(1)
|
|
} else {
|
|
libc.Xmemcpy(tls, bp, __ccgo_ts+1697, uint32(5))
|
|
bufpt = bp
|
|
if int32((**(**TFpDecode)(__ccgo_up(bp + 72))).Fsign) == int32('-') {
|
|
/* no-op */
|
|
} else {
|
|
if flag_prefix != 0 {
|
|
(**(**[70]int8)(__ccgo_up(bp)))[0] = libc.Int8FromUint8(flag_prefix)
|
|
} else {
|
|
bufpt = bufpt + 1
|
|
}
|
|
}
|
|
length = _sqlite3Strlen30(tls, bufpt)
|
|
goto _45
|
|
}
|
|
}
|
|
}
|
|
if int32((**(**TFpDecode)(__ccgo_up(bp + 72))).Fsign) == int32('-') {
|
|
if flag_alternateform != 0 && !(flag_prefix != 0) && libc.Int32FromUint8(xtype) == int32(etFLOAT) && (**(**TFpDecode)(__ccgo_up(bp + 72))).FiDP <= iRound {
|
|
/* Suppress the minus sign if all of the following are true:
|
|
** * The value displayed is zero
|
|
** * The '#' flag is used
|
|
** * The '+' flag is not used, and
|
|
** * The format is %f
|
|
*/
|
|
prefix = 0
|
|
} else {
|
|
prefix = int8('-')
|
|
}
|
|
} else {
|
|
prefix = libc.Int8FromUint8(flag_prefix)
|
|
}
|
|
exp = (**(**TFpDecode)(__ccgo_up(bp + 72))).FiDP - int32(1)
|
|
/*
|
|
** If the field type is etGENERIC, then convert to either etEXP
|
|
** or etFLOAT, as appropriate.
|
|
*/
|
|
if libc.Int32FromUint8(xtype) == int32(etGENERIC) {
|
|
precision = precision - 1
|
|
flag_rtz = libc.BoolUint8(!(flag_alternateform != 0))
|
|
if exp < -int32(4) || exp > precision {
|
|
xtype = uint8(etEXP)
|
|
} else {
|
|
precision = precision - exp
|
|
xtype = uint8(etFLOAT)
|
|
}
|
|
} else {
|
|
flag_rtz = flag_altform2
|
|
}
|
|
if libc.Int32FromUint8(xtype) == int32(etEXP) {
|
|
e2 = 0
|
|
} else {
|
|
e2 = (**(**TFpDecode)(__ccgo_up(bp + 72))).FiDP - int32(1)
|
|
}
|
|
if e2 > 0 {
|
|
v2 = e2
|
|
} else {
|
|
v2 = 0
|
|
}
|
|
szBufNeeded = int64(v2) + int64(precision) + int64(width) + int64(10)
|
|
if cThousand != 0 && e2 > 0 {
|
|
szBufNeeded = szBufNeeded + int64((e2+int32(2))/int32(3))
|
|
}
|
|
if szBufNeeded+libc.Int64FromUint32((*Tsqlite3_str)(unsafe.Pointer(pAccum)).FnChar) >= libc.Int64FromUint32((*Tsqlite3_str)(unsafe.Pointer(pAccum)).FnAlloc) {
|
|
if (*Tsqlite3_str)(unsafe.Pointer(pAccum)).FmxAlloc == uint32(0) && libc.Int32FromUint8((*Tsqlite3_str)(unsafe.Pointer(pAccum)).FaccError) == 0 {
|
|
/* Unable to allocate space in pAccum, perhaps because it
|
|
** is coming from sqlite3_snprintf() or similar. We'll have
|
|
** to render into temporary space and the memcpy() it over. */
|
|
bufpt = Xsqlite3_malloc(tls, int32(szBufNeeded))
|
|
if bufpt == uintptr(0) {
|
|
_sqlite3StrAccumSetError(tls, pAccum, uint8(SQLITE_NOMEM))
|
|
return
|
|
}
|
|
zExtra = bufpt
|
|
} else {
|
|
if int64(_sqlite3StrAccumEnlarge(tls, pAccum, szBufNeeded)) < szBufNeeded {
|
|
v2 = libc.Int32FromInt32(0)
|
|
length = v2
|
|
width = v2
|
|
goto _45
|
|
} else {
|
|
bufpt = (*Tsqlite3_str)(unsafe.Pointer(pAccum)).FzText + uintptr((*Tsqlite3_str)(unsafe.Pointer(pAccum)).FnChar)
|
|
}
|
|
}
|
|
} else {
|
|
bufpt = (*Tsqlite3_str)(unsafe.Pointer(pAccum)).FzText + uintptr((*Tsqlite3_str)(unsafe.Pointer(pAccum)).FnChar)
|
|
}
|
|
zOut = bufpt
|
|
if precision > 0 {
|
|
v2 = int32(1)
|
|
} else {
|
|
v2 = 0
|
|
}
|
|
flag_dp = libc.Uint8FromInt32(v2 | libc.Int32FromUint8(flag_alternateform) | libc.Int32FromUint8(flag_altform2))
|
|
/* The sign in front of the number */
|
|
if prefix != 0 {
|
|
v4 = bufpt
|
|
bufpt = bufpt + 1
|
|
**(**int8)(__ccgo_up(v4)) = prefix
|
|
}
|
|
/* Digits prior to the decimal point */
|
|
j = 0
|
|
if e2 < 0 {
|
|
v4 = bufpt
|
|
bufpt = bufpt + 1
|
|
**(**int8)(__ccgo_up(v4)) = int8('0')
|
|
} else {
|
|
if cThousand != 0 {
|
|
for {
|
|
if !(e2 >= 0) {
|
|
break
|
|
}
|
|
v4 = bufpt
|
|
bufpt = bufpt + 1
|
|
if j < (**(**TFpDecode)(__ccgo_up(bp + 72))).Fn {
|
|
v3 = j
|
|
j = j + 1
|
|
v2 = int32(**(**int8)(__ccgo_up((**(**TFpDecode)(__ccgo_up(bp + 72))).Fz + uintptr(v3))))
|
|
} else {
|
|
v2 = int32('0')
|
|
}
|
|
**(**int8)(__ccgo_up(v4)) = int8(v2)
|
|
if e2%int32(3) == 0 && e2 > int32(1) {
|
|
v4 = bufpt
|
|
bufpt = bufpt + 1
|
|
**(**int8)(__ccgo_up(v4)) = int8(',')
|
|
}
|
|
goto _63
|
|
_63:
|
|
;
|
|
e2 = e2 - 1
|
|
}
|
|
} else {
|
|
j = e2 + int32(1)
|
|
if j > (**(**TFpDecode)(__ccgo_up(bp + 72))).Fn {
|
|
j = (**(**TFpDecode)(__ccgo_up(bp + 72))).Fn
|
|
}
|
|
libc.Xmemcpy(tls, bufpt, (**(**TFpDecode)(__ccgo_up(bp + 72))).Fz, libc.Uint32FromInt32(j))
|
|
bufpt = bufpt + uintptr(j)
|
|
e2 = e2 - j
|
|
if e2 >= 0 {
|
|
libc.Xmemset(tls, bufpt, int32('0'), libc.Uint32FromInt32(e2+int32(1)))
|
|
bufpt = bufpt + uintptr(e2+int32(1))
|
|
e2 = -int32(1)
|
|
}
|
|
}
|
|
}
|
|
/* The decimal point */
|
|
if flag_dp != 0 {
|
|
v4 = bufpt
|
|
bufpt = bufpt + 1
|
|
**(**int8)(__ccgo_up(v4)) = int8('.')
|
|
}
|
|
/* "0" digits after the decimal point but before the first
|
|
** significant digit of the number */
|
|
if e2 < -int32(1) && precision > 0 {
|
|
nn2 = -int32(1) - e2
|
|
if nn2 > precision {
|
|
nn2 = precision
|
|
}
|
|
libc.Xmemset(tls, bufpt, int32('0'), libc.Uint32FromInt32(nn2))
|
|
bufpt = bufpt + uintptr(nn2)
|
|
precision = precision - nn2
|
|
}
|
|
/* Significant digits after the decimal point */
|
|
if precision > 0 {
|
|
nn3 = (**(**TFpDecode)(__ccgo_up(bp + 72))).Fn - j
|
|
if nn3 > precision {
|
|
nn3 = precision
|
|
}
|
|
if nn3 > 0 {
|
|
libc.Xmemcpy(tls, bufpt, (**(**TFpDecode)(__ccgo_up(bp + 72))).Fz+uintptr(j), libc.Uint32FromInt32(nn3))
|
|
bufpt = bufpt + uintptr(nn3)
|
|
precision = precision - nn3
|
|
}
|
|
if precision > 0 && !(flag_rtz != 0) {
|
|
libc.Xmemset(tls, bufpt, int32('0'), libc.Uint32FromInt32(precision))
|
|
bufpt = bufpt + uintptr(precision)
|
|
}
|
|
}
|
|
/* Remove trailing zeros and the "." if no digits follow the "." */
|
|
if flag_rtz != 0 && flag_dp != 0 {
|
|
for int32(**(**int8)(__ccgo_up(bufpt + uintptr(-libc.Int32FromInt32(1))))) == int32('0') {
|
|
bufpt = bufpt - 1
|
|
v4 = bufpt
|
|
**(**int8)(__ccgo_up(v4)) = 0
|
|
}
|
|
if int32(**(**int8)(__ccgo_up(bufpt + uintptr(-libc.Int32FromInt32(1))))) == int32('.') {
|
|
if flag_altform2 != 0 {
|
|
v4 = bufpt
|
|
bufpt = bufpt + 1
|
|
**(**int8)(__ccgo_up(v4)) = int8('0')
|
|
} else {
|
|
bufpt = bufpt - 1
|
|
v4 = bufpt
|
|
**(**int8)(__ccgo_up(v4)) = 0
|
|
}
|
|
}
|
|
}
|
|
/* Add the "eNNN" suffix */
|
|
if libc.Int32FromUint8(xtype) == int32(etEXP) {
|
|
exp = (**(**TFpDecode)(__ccgo_up(bp + 72))).FiDP - int32(1)
|
|
v4 = bufpt
|
|
bufpt = bufpt + 1
|
|
**(**int8)(__ccgo_up(v4)) = _aDigits[(*Tet_info)(unsafe.Pointer(infop)).Fcharset]
|
|
if exp < 0 {
|
|
v4 = bufpt
|
|
bufpt = bufpt + 1
|
|
**(**int8)(__ccgo_up(v4)) = int8('-')
|
|
exp = -exp
|
|
} else {
|
|
v4 = bufpt
|
|
bufpt = bufpt + 1
|
|
**(**int8)(__ccgo_up(v4)) = int8('+')
|
|
}
|
|
if exp >= int32(100) {
|
|
v4 = bufpt
|
|
bufpt = bufpt + 1
|
|
**(**int8)(__ccgo_up(v4)) = int8(exp/libc.Int32FromInt32(100) + libc.Int32FromUint8('0')) /* 100's digit */
|
|
exp = exp % int32(100)
|
|
}
|
|
v4 = bufpt
|
|
bufpt = bufpt + 1
|
|
**(**int8)(__ccgo_up(v4)) = int8(exp/libc.Int32FromInt32(10) + libc.Int32FromUint8('0')) /* 10's digit */
|
|
v4 = bufpt
|
|
bufpt = bufpt + 1
|
|
**(**int8)(__ccgo_up(v4)) = int8(exp%libc.Int32FromInt32(10) + libc.Int32FromUint8('0')) /* 1's digit */
|
|
}
|
|
length = int32(bufpt) - int32(zOut)
|
|
if length < width {
|
|
nPad = int64(width - length)
|
|
if flag_leftjustify != 0 {
|
|
libc.Xmemset(tls, bufpt, int32(' '), libc.Uint32FromInt64(nPad))
|
|
} else {
|
|
if !(flag_zeropad != 0) {
|
|
libc.Xmemmove(tls, zOut+uintptr(nPad), zOut, libc.Uint32FromInt32(length))
|
|
libc.Xmemset(tls, zOut, int32(' '), libc.Uint32FromInt64(nPad))
|
|
} else {
|
|
adj = libc.BoolInt32(int32(prefix) != 0)
|
|
libc.Xmemmove(tls, zOut+uintptr(nPad)+uintptr(adj), zOut+uintptr(adj), libc.Uint32FromInt32(length-adj))
|
|
libc.Xmemset(tls, zOut+uintptr(adj), int32('0'), libc.Uint32FromInt64(nPad))
|
|
}
|
|
}
|
|
length = width
|
|
}
|
|
if zExtra == uintptr(0) {
|
|
/* The result is being rendered directory into pAccum. This
|
|
** is the command and fast case */
|
|
**(**Tu32)(__ccgo_up(pAccum + 16)) += libc.Uint32FromInt32(length)
|
|
**(**int8)(__ccgo_up(zOut + uintptr(length))) = 0
|
|
goto _1
|
|
} else {
|
|
/* We were unable to render directly into pAccum because we
|
|
** couldn't allocate sufficient memory. We need to memcpy()
|
|
** the rendering (or some prefix thereof) into the output
|
|
** buffer. */
|
|
**(**int8)(__ccgo_up(bufpt)) = 0
|
|
bufpt = zExtra
|
|
goto _45
|
|
}
|
|
_34:
|
|
;
|
|
if !(bArgList != 0) {
|
|
**(**int32)(__ccgo_up(libc.VaUintptr(&ap))) = libc.Int32FromUint32((*Tsqlite3_str)(unsafe.Pointer(pAccum)).FnChar)
|
|
}
|
|
v2 = libc.Int32FromInt32(0)
|
|
width = v2
|
|
length = v2
|
|
goto _45
|
|
_35:
|
|
;
|
|
(**(**[70]int8)(__ccgo_up(bp)))[0] = int8('%')
|
|
bufpt = bp
|
|
length = int32(1)
|
|
goto _45
|
|
_36:
|
|
;
|
|
if bArgList != 0 {
|
|
bufpt = _getTextArg(tls, pArgList)
|
|
length = int32(1)
|
|
if bufpt != 0 {
|
|
v4 = bufpt
|
|
bufpt = bufpt + 1
|
|
v2 = int32(**(**int8)(__ccgo_up(v4)))
|
|
c = v2
|
|
(**(**[70]int8)(__ccgo_up(bp)))[0] = int8(v2)
|
|
if c&int32(0xc0) == int32(0xc0) {
|
|
for length < int32(4) && int32(**(**int8)(__ccgo_up(bufpt)))&int32(0xc0) == int32(0x80) {
|
|
v2 = length
|
|
length = length + 1
|
|
v4 = bufpt
|
|
bufpt = bufpt + 1
|
|
(**(**[70]int8)(__ccgo_up(bp)))[v2] = **(**int8)(__ccgo_up(v4))
|
|
}
|
|
}
|
|
} else {
|
|
(**(**[70]int8)(__ccgo_up(bp)))[0] = 0
|
|
}
|
|
} else {
|
|
ch = libc.VaUint32(&ap)
|
|
length = _sqlite3AppendOneUtf8Character(tls, bp, ch)
|
|
}
|
|
if precision > int32(1) {
|
|
nPrior = int64(1)
|
|
width = width - (precision - int32(1))
|
|
if width > int32(1) && !(flag_leftjustify != 0) {
|
|
Xsqlite3_str_appendchar(tls, pAccum, width-int32(1), int8(' '))
|
|
width = 0
|
|
}
|
|
Xsqlite3_str_append(tls, pAccum, bp, length)
|
|
precision = precision - 1
|
|
for precision > int32(1) {
|
|
if nPrior > int64(precision-int32(1)) {
|
|
nPrior = int64(precision - int32(1))
|
|
}
|
|
nCopyBytes = int64(length) * nPrior
|
|
if _sqlite3StrAccumEnlargeIfNeeded(tls, pAccum, nCopyBytes) != 0 {
|
|
break
|
|
}
|
|
Xsqlite3_str_append(tls, pAccum, (*Tsqlite3_str)(unsafe.Pointer(pAccum)).FzText+uintptr(libc.Int64FromUint32((*Tsqlite3_str)(unsafe.Pointer(pAccum)).FnChar)-nCopyBytes), int32(nCopyBytes))
|
|
precision = int32(int64(precision) - nPrior)
|
|
nPrior = nPrior * int64(2)
|
|
}
|
|
}
|
|
bufpt = bp
|
|
flag_altform2 = uint8(1)
|
|
goto adjust_width_for_utf8
|
|
_38:
|
|
;
|
|
_37:
|
|
;
|
|
if bArgList != 0 {
|
|
bufpt = _getTextArg(tls, pArgList)
|
|
xtype = uint8(etSTRING)
|
|
} else {
|
|
bufpt = libc.VaUintptr(&ap)
|
|
}
|
|
if bufpt == uintptr(0) {
|
|
bufpt = __ccgo_ts + 1702
|
|
} else {
|
|
if libc.Int32FromUint8(xtype) == int32(etDYNSTRING) {
|
|
if (*Tsqlite3_str)(unsafe.Pointer(pAccum)).FnChar == uint32(0) && (*Tsqlite3_str)(unsafe.Pointer(pAccum)).FmxAlloc != 0 && width == 0 && precision < 0 && libc.Int32FromUint8((*Tsqlite3_str)(unsafe.Pointer(pAccum)).FaccError) == 0 {
|
|
/* Special optimization for sqlite3_mprintf("%z..."):
|
|
** Extend an existing memory allocation rather than creating
|
|
** a new one. */
|
|
(*Tsqlite3_str)(unsafe.Pointer(pAccum)).FzText = bufpt
|
|
(*Tsqlite3_str)(unsafe.Pointer(pAccum)).FnAlloc = libc.Uint32FromInt32(_sqlite3DbMallocSize(tls, (*Tsqlite3_str)(unsafe.Pointer(pAccum)).Fdb, bufpt))
|
|
(*Tsqlite3_str)(unsafe.Pointer(pAccum)).FnChar = libc.Uint32FromInt32(int32(0x7fffffff) & libc.Int32FromUint32(libc.Xstrlen(tls, bufpt)))
|
|
v4 = pAccum + 21
|
|
*(*Tu8)(unsafe.Pointer(v4)) = Tu8(int32(*(*Tu8)(unsafe.Pointer(v4))) | libc.Int32FromInt32(SQLITE_PRINTF_MALLOCED))
|
|
length = 0
|
|
goto _45
|
|
}
|
|
zExtra = bufpt
|
|
}
|
|
}
|
|
if precision >= 0 {
|
|
if flag_altform2 != 0 {
|
|
/* Set length to the number of bytes needed in order to display
|
|
** precision characters */
|
|
z = bufpt
|
|
for {
|
|
v2 = precision
|
|
precision = precision - 1
|
|
if !(v2 > 0 && **(**uint8)(__ccgo_up(z)) != 0) {
|
|
break
|
|
}
|
|
v4 = z
|
|
z = z + 1
|
|
if libc.Int32FromUint8(**(**uint8)(__ccgo_up(v4))) >= int32(0xc0) {
|
|
for libc.Int32FromUint8(**(**uint8)(__ccgo_up(z)))&int32(0xc0) == int32(0x80) {
|
|
z = z + 1
|
|
}
|
|
}
|
|
}
|
|
length = int32(z) - int32(bufpt)
|
|
} else {
|
|
length = 0
|
|
for {
|
|
if !(length < precision && **(**int8)(__ccgo_up(bufpt + uintptr(length))) != 0) {
|
|
break
|
|
}
|
|
goto _86
|
|
_86:
|
|
;
|
|
length = length + 1
|
|
}
|
|
}
|
|
} else {
|
|
length = int32(0x7fffffff) & libc.Int32FromUint32(libc.Xstrlen(tls, bufpt))
|
|
}
|
|
goto adjust_width_for_utf8
|
|
adjust_width_for_utf8:
|
|
;
|
|
if flag_altform2 != 0 && width > 0 {
|
|
/* Adjust width to account for extra bytes in UTF-8 characters */
|
|
ii = length - int32(1)
|
|
for ii >= 0 {
|
|
v2 = ii
|
|
ii = ii - 1
|
|
if int32(**(**int8)(__ccgo_up(bufpt + uintptr(v2))))&int32(0xc0) == int32(0x80) {
|
|
width = width + 1
|
|
}
|
|
}
|
|
}
|
|
goto _45
|
|
_41:
|
|
; /* %q: Escape ' characters */
|
|
_40:
|
|
; /* %Q: Escape ' and enclose in '...' */
|
|
_39:
|
|
;
|
|
needQuote = 0
|
|
if bArgList != 0 {
|
|
escarg = _getTextArg(tls, pArgList)
|
|
} else {
|
|
escarg = libc.VaUintptr(&ap)
|
|
}
|
|
if escarg == uintptr(0) {
|
|
if libc.Int32FromUint8(xtype) == int32(etESCAPE_Q) {
|
|
v4 = __ccgo_ts + 1703
|
|
} else {
|
|
v4 = __ccgo_ts + 1708
|
|
}
|
|
escarg = v4
|
|
} else {
|
|
if libc.Int32FromUint8(xtype) == int32(etESCAPE_Q) {
|
|
needQuote = int32(1)
|
|
}
|
|
}
|
|
if libc.Int32FromUint8(xtype) == int32(etESCAPE_w) {
|
|
q = int8('"')
|
|
flag_alternateform = uint8(0)
|
|
} else {
|
|
q = int8('\'')
|
|
}
|
|
/* For %q, %Q, and %w, the precision is the number of bytes (or
|
|
** characters if the ! flags is present) to use from the input.
|
|
** Because of the extra quoting characters inserted, the number
|
|
** of output characters may be larger than the precision.
|
|
*/
|
|
k = int64(precision)
|
|
v90 = libc.Int64FromInt32(0)
|
|
n1 = v90
|
|
i = v90
|
|
for {
|
|
if v12 = k != 0; v12 {
|
|
v54 = **(**int8)(__ccgo_up(escarg + uintptr(i)))
|
|
ch1 = v54
|
|
}
|
|
if !(v12 && int32(v54) != 0) {
|
|
break
|
|
}
|
|
if int32(ch1) == int32(q) {
|
|
n1 = n1 + 1
|
|
}
|
|
if flag_altform2 != 0 && int32(ch1)&int32(0xc0) == int32(0xc0) {
|
|
for int32(**(**int8)(__ccgo_up(escarg + uintptr(i+int64(1)))))&int32(0xc0) == int32(0x80) {
|
|
i = i + 1
|
|
}
|
|
}
|
|
goto _89
|
|
_89:
|
|
;
|
|
i = i + 1
|
|
k = k - 1
|
|
}
|
|
if flag_alternateform != 0 {
|
|
/* For %#q, do unistr()-style backslash escapes for
|
|
** all control characters, and for backslash itself.
|
|
** For %#Q, do the same but only if there is at least
|
|
** one control character. */
|
|
nBack = 0
|
|
nCtrl = 0
|
|
k = 0
|
|
for {
|
|
if !(k < i) {
|
|
break
|
|
}
|
|
if int32(**(**int8)(__ccgo_up(escarg + uintptr(k)))) == int32('\\') {
|
|
nBack = nBack + 1
|
|
} else {
|
|
if libc.Int32FromUint8(**(**Tu8)(__ccgo_up(escarg + uintptr(k)))) <= int32(0x1f) {
|
|
nCtrl = nCtrl + 1
|
|
}
|
|
}
|
|
goto _93
|
|
_93:
|
|
;
|
|
k = k + 1
|
|
}
|
|
if nCtrl != 0 || libc.Int32FromUint8(xtype) == int32(etESCAPE_q) {
|
|
n1 = n1 + (nBack + int64(5)*nCtrl)
|
|
if libc.Int32FromUint8(xtype) == int32(etESCAPE_Q) {
|
|
n1 = n1 + int64(10)
|
|
needQuote = int32(2)
|
|
}
|
|
} else {
|
|
flag_alternateform = uint8(0)
|
|
}
|
|
}
|
|
n1 = n1 + (i + int64(3))
|
|
if n1 > int64(SQLITE_PRINT_BUF_SIZE) {
|
|
v4 = _printfTempBuf(tls, pAccum, n1)
|
|
zExtra = v4
|
|
bufpt = v4
|
|
if bufpt == uintptr(0) {
|
|
return
|
|
}
|
|
} else {
|
|
bufpt = bp
|
|
}
|
|
j1 = 0
|
|
if needQuote != 0 {
|
|
if needQuote == int32(2) {
|
|
libc.Xmemcpy(tls, bufpt+uintptr(j1), __ccgo_ts+1715, uint32(8))
|
|
j1 = j1 + int64(8)
|
|
} else {
|
|
v90 = j1
|
|
j1 = j1 + 1
|
|
**(**int8)(__ccgo_up(bufpt + uintptr(v90))) = int8('\'')
|
|
}
|
|
}
|
|
k = i
|
|
if flag_alternateform != 0 {
|
|
i = 0
|
|
for {
|
|
if !(i < k) {
|
|
break
|
|
}
|
|
v90 = j1
|
|
j1 = j1 + 1
|
|
v54 = **(**int8)(__ccgo_up(escarg + uintptr(i)))
|
|
ch1 = v54
|
|
**(**int8)(__ccgo_up(bufpt + uintptr(v90))) = v54
|
|
if int32(ch1) == int32(q) {
|
|
v90 = j1
|
|
j1 = j1 + 1
|
|
**(**int8)(__ccgo_up(bufpt + uintptr(v90))) = ch1
|
|
} else {
|
|
if int32(ch1) == int32('\\') {
|
|
v90 = j1
|
|
j1 = j1 + 1
|
|
**(**int8)(__ccgo_up(bufpt + uintptr(v90))) = int8('\\')
|
|
} else {
|
|
if libc.Int32FromUint8(libc.Uint8FromInt8(ch1)) <= int32(0x1f) {
|
|
**(**int8)(__ccgo_up(bufpt + uintptr(j1-int64(1)))) = int8('\\')
|
|
v90 = j1
|
|
j1 = j1 + 1
|
|
**(**int8)(__ccgo_up(bufpt + uintptr(v90))) = int8('u')
|
|
v90 = j1
|
|
j1 = j1 + 1
|
|
**(**int8)(__ccgo_up(bufpt + uintptr(v90))) = int8('0')
|
|
v90 = j1
|
|
j1 = j1 + 1
|
|
**(**int8)(__ccgo_up(bufpt + uintptr(v90))) = int8('0')
|
|
v90 = j1
|
|
j1 = j1 + 1
|
|
if int32(ch1) >= int32(0x10) {
|
|
v2 = int32('1')
|
|
} else {
|
|
v2 = int32('0')
|
|
}
|
|
**(**int8)(__ccgo_up(bufpt + uintptr(v90))) = int8(v2)
|
|
v90 = j1
|
|
j1 = j1 + 1
|
|
**(**int8)(__ccgo_up(bufpt + uintptr(v90))) = **(**int8)(__ccgo_up(__ccgo_ts + 1724 + uintptr(int32(ch1)&int32(0xf))))
|
|
}
|
|
}
|
|
}
|
|
goto _96
|
|
_96:
|
|
;
|
|
i = i + 1
|
|
}
|
|
} else {
|
|
i = 0
|
|
for {
|
|
if !(i < k) {
|
|
break
|
|
}
|
|
v90 = j1
|
|
j1 = j1 + 1
|
|
v54 = **(**int8)(__ccgo_up(escarg + uintptr(i)))
|
|
ch1 = v54
|
|
**(**int8)(__ccgo_up(bufpt + uintptr(v90))) = v54
|
|
if int32(ch1) == int32(q) {
|
|
v90 = j1
|
|
j1 = j1 + 1
|
|
**(**int8)(__ccgo_up(bufpt + uintptr(v90))) = ch1
|
|
}
|
|
goto _107
|
|
_107:
|
|
;
|
|
i = i + 1
|
|
}
|
|
}
|
|
if needQuote != 0 {
|
|
v90 = j1
|
|
j1 = j1 + 1
|
|
**(**int8)(__ccgo_up(bufpt + uintptr(v90))) = int8('\'')
|
|
if needQuote == int32(2) {
|
|
v90 = j1
|
|
j1 = j1 + 1
|
|
**(**int8)(__ccgo_up(bufpt + uintptr(v90))) = int8(')')
|
|
}
|
|
}
|
|
**(**int8)(__ccgo_up(bufpt + uintptr(j1))) = 0
|
|
length = int32(j1)
|
|
goto adjust_width_for_utf8
|
|
_42:
|
|
;
|
|
if libc.Int32FromUint8((*Tsqlite3_str)(unsafe.Pointer(pAccum)).FprintfFlags)&int32(SQLITE_PRINTF_INTERNAL) == 0 {
|
|
return
|
|
}
|
|
if flag_alternateform != 0 {
|
|
/* %#T means an Expr pointer that uses Expr.u.zToken */
|
|
pExpr = libc.VaUintptr(&ap)
|
|
if pExpr != 0 && !((*TExpr)(unsafe.Pointer(pExpr)).Fflags&libc.Uint32FromInt32(libc.Int32FromInt32(EP_IntValue)) != libc.Uint32FromInt32(0)) {
|
|
Xsqlite3_str_appendall(tls, pAccum, *(*uintptr)(unsafe.Pointer(pExpr + 8)))
|
|
_sqlite3RecordErrorOffsetOfExpr(tls, (*Tsqlite3_str)(unsafe.Pointer(pAccum)).Fdb, pExpr)
|
|
}
|
|
} else {
|
|
/* %T means a Token pointer */
|
|
pToken = libc.VaUintptr(&ap)
|
|
if pToken != 0 && (*TToken)(unsafe.Pointer(pToken)).Fn != 0 {
|
|
Xsqlite3_str_append(tls, pAccum, (*TToken)(unsafe.Pointer(pToken)).Fz, libc.Int32FromUint32((*TToken)(unsafe.Pointer(pToken)).Fn))
|
|
_sqlite3RecordErrorByteOffset(tls, (*Tsqlite3_str)(unsafe.Pointer(pAccum)).Fdb, (*TToken)(unsafe.Pointer(pToken)).Fz)
|
|
}
|
|
}
|
|
v2 = libc.Int32FromInt32(0)
|
|
width = v2
|
|
length = v2
|
|
goto _45
|
|
_43:
|
|
;
|
|
if libc.Int32FromUint8((*Tsqlite3_str)(unsafe.Pointer(pAccum)).FprintfFlags)&int32(SQLITE_PRINTF_INTERNAL) == 0 {
|
|
return
|
|
}
|
|
pItem = libc.VaUintptr(&ap)
|
|
if (*TSrcItem)(unsafe.Pointer(pItem)).FzAlias != 0 && !(flag_altform2 != 0) {
|
|
Xsqlite3_str_appendall(tls, pAccum, (*TSrcItem)(unsafe.Pointer(pItem)).FzAlias)
|
|
} else {
|
|
if (*TSrcItem)(unsafe.Pointer(pItem)).FzName != 0 {
|
|
if int32(*(*uint32)(unsafe.Pointer(pItem + 12 + 4))&0x10000>>16) == 0 && int32(*(*uint32)(unsafe.Pointer(pItem + 12 + 4))&0x4>>2) == 0 && *(*uintptr)(unsafe.Pointer(pItem + 44)) != uintptr(0) {
|
|
Xsqlite3_str_appendall(tls, pAccum, *(*uintptr)(unsafe.Pointer(pItem + 44)))
|
|
Xsqlite3_str_append(tls, pAccum, __ccgo_ts+1741, int32(1))
|
|
}
|
|
Xsqlite3_str_appendall(tls, pAccum, (*TSrcItem)(unsafe.Pointer(pItem)).FzName)
|
|
} else {
|
|
if (*TSrcItem)(unsafe.Pointer(pItem)).FzAlias != 0 {
|
|
Xsqlite3_str_appendall(tls, pAccum, (*TSrcItem)(unsafe.Pointer(pItem)).FzAlias)
|
|
} else {
|
|
if int32(*(*uint32)(unsafe.Pointer(pItem + 12 + 4))&0x4>>2) != 0 { /* Because of tag-20240424-1 */
|
|
pSel = (*TSubquery)(unsafe.Pointer(*(*uintptr)(unsafe.Pointer(pItem + 44)))).FpSelect
|
|
if (*TSelect)(unsafe.Pointer(pSel)).FselFlags&uint32(SF_NestedFrom) != 0 {
|
|
Xsqlite3_str_appendf(tls, pAccum, __ccgo_ts+1743, libc.VaList(bp+120, (*TSelect)(unsafe.Pointer(pSel)).FselId))
|
|
} else {
|
|
if (*TSelect)(unsafe.Pointer(pSel)).FselFlags&uint32(SF_MultiValue) != 0 {
|
|
Xsqlite3_str_appendf(tls, pAccum, __ccgo_ts+1753, libc.VaList(bp+120, *(*Tu32)(unsafe.Pointer(pItem + 32))))
|
|
} else {
|
|
Xsqlite3_str_appendf(tls, pAccum, __ccgo_ts+1774, libc.VaList(bp+120, (*TSelect)(unsafe.Pointer(pSel)).FselId))
|
|
}
|
|
}
|
|
}
|
|
}
|
|
}
|
|
}
|
|
v2 = libc.Int32FromInt32(0)
|
|
width = v2
|
|
length = v2
|
|
goto _45
|
|
_44:
|
|
;
|
|
return
|
|
_45:
|
|
; /* End switch over the format type */
|
|
/*
|
|
** The text of the conversion is pointed to by "bufpt" and is
|
|
** "length" characters long. The field width is "width". Do
|
|
** the output. Both length and width are in bytes, not characters,
|
|
** at this point. If the "!" flag was present on string conversions
|
|
** indicating that width and precision should be expressed in characters,
|
|
** then the values have been translated prior to reaching this point.
|
|
*/
|
|
width = width - length
|
|
if width > 0 {
|
|
if !(flag_leftjustify != 0) {
|
|
Xsqlite3_str_appendchar(tls, pAccum, width, int8(' '))
|
|
}
|
|
Xsqlite3_str_append(tls, pAccum, bufpt, length)
|
|
if flag_leftjustify != 0 {
|
|
Xsqlite3_str_appendchar(tls, pAccum, width, int8(' '))
|
|
}
|
|
} else {
|
|
Xsqlite3_str_append(tls, pAccum, bufpt, length)
|
|
}
|
|
if zExtra != 0 {
|
|
_sqlite3DbFree(tls, (*Tsqlite3_str)(unsafe.Pointer(pAccum)).Fdb, zExtra)
|
|
zExtra = uintptr(0)
|
|
}
|
|
goto _1
|
|
_1:
|
|
;
|
|
fmt = fmt + 1
|
|
} /* End for loop over the format string */
|
|
}
|
|
|
|
// C documentation
|
|
//
|
|
// /*
|
|
// ** Checkpoint database zDb.
|
|
// */
|
|
func Xsqlite3_wal_checkpoint_v2(tls *libc.TLS, db uintptr, zDb uintptr, eMode int32, pnLog uintptr, pnCkpt uintptr) (r int32) {
|
|
bp := tls.Alloc(16)
|
|
defer tls.Free(16)
|
|
var iDb, rc int32
|
|
_, _ = iDb, rc /* Schema to checkpoint */
|
|
/* Initialize the output variables to -1 in case an error occurs. */
|
|
if pnLog != 0 {
|
|
**(**int32)(__ccgo_up(pnLog)) = -int32(1)
|
|
}
|
|
if pnCkpt != 0 {
|
|
**(**int32)(__ccgo_up(pnCkpt)) = -int32(1)
|
|
}
|
|
if eMode < -int32(1) || eMode > int32(SQLITE_CHECKPOINT_TRUNCATE) {
|
|
/* EVIDENCE-OF: R-03996-12088 The M parameter must be a valid checkpoint
|
|
** mode: */
|
|
return _sqlite3MisuseError(tls, int32(189958))
|
|
}
|
|
Xsqlite3_mutex_enter(tls, (*Tsqlite3)(unsafe.Pointer(db)).Fmutex)
|
|
if zDb != 0 && **(**int8)(__ccgo_up(zDb)) != 0 {
|
|
iDb = _sqlite3FindDbName(tls, db, zDb)
|
|
} else {
|
|
iDb = libc.Int32FromInt32(SQLITE_MAX_ATTACHED) + libc.Int32FromInt32(2) /* This means process all schemas */
|
|
}
|
|
if iDb < 0 {
|
|
rc = int32(SQLITE_ERROR)
|
|
_sqlite3ErrorWithMsg(tls, db, int32(SQLITE_ERROR), __ccgo_ts+26027, libc.VaList(bp+8, zDb))
|
|
} else {
|
|
(*Tsqlite3)(unsafe.Pointer(db)).FbusyHandler.FnBusy = 0
|
|
rc = _sqlite3Checkpoint(tls, db, iDb, eMode, pnLog, pnCkpt)
|
|
_sqlite3Error(tls, db, rc)
|
|
}
|
|
rc = _sqlite3ApiExit(tls, db, rc)
|
|
/* If there are no active statements, clear the interrupt flag at this
|
|
** point. */
|
|
if (*Tsqlite3)(unsafe.Pointer(db)).FnVdbeActive == 0 {
|
|
libc.AtomicStoreNInt32(db+308, libc.Int32FromInt32(0), libc.Int32FromInt32(__ATOMIC_RELAXED))
|
|
}
|
|
Xsqlite3_mutex_leave(tls, (*Tsqlite3)(unsafe.Pointer(db)).Fmutex)
|
|
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+16120, uintptr(0), uintptr(0), p+36)
|
|
}
|
|
/* 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+16120, uintptr(0), uintptr(0), p+36)
|
|
}
|
|
/* Close any open statement handles. */
|
|
_rbuObjIterFinalize(tls, p+52)
|
|
/* 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+34682, 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
|
|
}
|
|
|
|
// 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 + 52
|
|
/* 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+18938)
|
|
_rbuCopyPragma(tls, p, __ccgo_ts+18049)
|
|
}
|
|
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+34275, libc.VaList(bp+16, p+24, (*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+16120, uintptr(0), uintptr(0), p+36)
|
|
}
|
|
if (*Tsqlite3rbu)(unsafe.Pointer(p)).Frc == SQLITE_OK {
|
|
(*Tsqlite3rbu)(unsafe.Pointer(p)).Frc = Xsqlite3_exec(tls, (*Tsqlite3rbu)(unsafe.Pointer(p)).FdbRbu, __ccgo_ts+16120, uintptr(0), uintptr(0), p+36)
|
|
}
|
|
(*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
|
|
}
|
|
|
|
const __CC_SUPPORTS_DYNAMIC_ARRAY_INIT = 1
|
|
|
|
const __CC_SUPPORTS_INLINE = 1
|
|
|
|
const __CC_SUPPORTS_VARADIC_XXX = 1
|
|
|
|
const __CC_SUPPORTS_WARNING = 1
|
|
|
|
const __CC_SUPPORTS___FUNC__ = 1
|
|
|
|
const __CC_SUPPORTS___INLINE__ = 1
|
|
|
|
const __FreeBSD__ = 14
|
|
|
|
const __FreeBSD_cc_version = 1400006
|
|
|
|
const __GNUCLIKE_ASM = 3
|
|
|
|
const __GNUCLIKE_BUILTIN_CONSTANT_P = 1
|
|
|
|
const __GNUCLIKE_BUILTIN_MEMCPY = 1
|
|
|
|
const __GNUCLIKE_BUILTIN_NEXT_ARG = 1
|
|
|
|
const __GNUCLIKE_BUILTIN_STDARG = 1
|
|
|
|
const __GNUCLIKE_BUILTIN_VAALIST = 1
|
|
|
|
const __GNUCLIKE_BUILTIN_VARARGS = 1
|
|
|
|
const __GNUCLIKE_CTOR_SECTION_HANDLING = 1
|
|
|
|
const __GNUCLIKE___SECTION = 1
|
|
|
|
const __GNUCLIKE___TYPEOF = 1
|
|
|
|
const __GNUC_VA_LIST_COMPATIBILITY = 1
|
|
|
|
const __STAT_TIME_T_EXT = 1
|
|
|
|
const __tune_i686__ = 1
|
|
|
|
const __tune_pentiumpro__ = 1
|
|
|
|
/*
|
|
** 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(84),
|
|
FmxPathname: int32(MAX_PATHNAME),
|
|
FzName: __ccgo_ts + 4086,
|
|
},
|
|
1: {
|
|
FiVersion: int32(3),
|
|
FszOsFile: int32(84),
|
|
FmxPathname: int32(MAX_PATHNAME),
|
|
FzName: __ccgo_ts + 4091,
|
|
},
|
|
2: {
|
|
FiVersion: int32(3),
|
|
FszOsFile: int32(84),
|
|
FmxPathname: int32(MAX_PATHNAME),
|
|
FzName: __ccgo_ts + 4101,
|
|
},
|
|
3: {
|
|
FiVersion: int32(3),
|
|
FszOsFile: int32(84),
|
|
FmxPathname: int32(MAX_PATHNAME),
|
|
FzName: __ccgo_ts + 3981,
|
|
},
|
|
}
|
|
|
|
// 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.Int64FromUint32(uint32(4) * libc.Uint32FromInt32(libc.Int32FromInt32(2)+(*(*struct {
|
|
FnArg int32
|
|
FazArg uintptr
|
|
Fp uintptr
|
|
})(unsafe.Pointer(pTable + 44))).FnArg))
|
|
if (*(*struct {
|
|
FnArg int32
|
|
FazArg uintptr
|
|
Fp uintptr
|
|
})(unsafe.Pointer(pTable + 44))).FnArg+int32(3) >= **(**int32)(__ccgo_up(db + 116 + 2*4)) {
|
|
_sqlite3ErrorMsg(tls, pParse, __ccgo_ts+13958, libc.VaList(bp+8, (*TTable)(unsafe.Pointer(pTable)).FzName))
|
|
}
|
|
azModuleArg = _sqlite3DbRealloc(tls, db, (*(*struct {
|
|
FnArg int32
|
|
FazArg uintptr
|
|
Fp uintptr
|
|
})(unsafe.Pointer(pTable + 44))).FazArg, libc.Uint64FromInt64(nBytes))
|
|
if azModuleArg == uintptr(0) {
|
|
_sqlite3DbFree(tls, db, zArg)
|
|
} else {
|
|
v2 = pTable + 44
|
|
v1 = *(*int32)(unsafe.Pointer(v2))
|
|
*(*int32)(unsafe.Pointer(v2)) = *(*int32)(unsafe.Pointer(v2)) + 1
|
|
i = v1
|
|
**(**uintptr)(__ccgo_up(azModuleArg + uintptr(i)*4)) = zArg
|
|
**(**uintptr)(__ccgo_up(azModuleArg + uintptr(i+int32(1))*4)) = uintptr(0)
|
|
(*(*struct {
|
|
FnArg int32
|
|
FazArg uintptr
|
|
Fp uintptr
|
|
})(unsafe.Pointer(pTable + 44))).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 + 10
|
|
*(*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 + 10
|
|
*(*Tu16)(unsafe.Pointer(v3)) = Tu16(int32(*(*Tu16)(unsafe.Pointer(v3))) | libc.Int32FromInt32(TERM_OK))
|
|
goto _2
|
|
_2:
|
|
;
|
|
i = i + 1
|
|
pTerm += 48
|
|
}
|
|
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)*20))).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)*20))).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)*12)
|
|
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 + 12 + 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(uint32(64)+(libc.Uint32FromInt64(12)+libc.Uint32FromInt64(8))*libc.Uint32FromInt32(nTerm)+uint32(8)*libc.Uint32FromInt32(nOrderBy)+(uint32(libc.UintptrFromInt32(0)+20)+libc.Uint32FromInt32(nTerm)*uint32(4))))
|
|
if pIdxInfo == uintptr(0) {
|
|
_sqlite3ErrorMsg(tls, pParse, __ccgo_ts+1672, 0)
|
|
return uintptr(0)
|
|
}
|
|
pHidden = pIdxInfo + 1*64
|
|
pIdxCons = pHidden + 20 + uintptr(nTerm)*4
|
|
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.Int32FromUint32(libc.Uint32FromInt64(8)*libc.Uint32FromInt32(8))-libc.Int32FromInt32(1) {
|
|
iCol = libc.Int32FromUint32(libc.Uint32FromInt64(8)*libc.Uint32FromInt32(8)) - libc.Int32FromInt32(1)
|
|
}
|
|
**(**Tsqlite3_uint64)(__ccgo_up(pIdxInfo + 56)) |= 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 + 24))).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 + 12)) |= 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 += 48
|
|
}
|
|
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)*20))).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)*20))).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
|
|
//
|
|
// /*
|
|
// ** 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(80)
|
|
defer tls.Free(80)
|
|
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 + 24))
|
|
pParse = (*TNameContext)(unsafe.Pointer(pNC)).FpParse
|
|
pSrcList = (*TNameContext)(unsafe.Pointer(pNC)).FpSrcList
|
|
pAggInfo = *(*uintptr)(unsafe.Pointer(pNC + 8))
|
|
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)*48))).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, uint32(52))
|
|
(**(**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)*20))).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 += 48
|
|
} /* 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 + 116 + 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 += 24
|
|
}
|
|
if i > mxTerm {
|
|
_sqlite3ErrorMsg(tls, pParse, __ccgo_ts+8616, libc.VaList(bp+64, 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)*24
|
|
(*TAggInfo_func)(unsafe.Pointer(pItem1)).FpFExpr = pExpr
|
|
if *(*uintptr)(unsafe.Pointer(pExpr + 20)) != 0 {
|
|
v5 = (*TExprList)(unsafe.Pointer(*(*uintptr)(unsafe.Pointer(pExpr + 20)))).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 + 44
|
|
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 + 20))
|
|
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 + 20)) + 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 + 44
|
|
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
|
|
//
|
|
// /*
|
|
// ** Append a single path element to the DbPath under construction
|
|
// */
|
|
func _appendOnePathElement(tls *libc.TLS, pPath uintptr, zName uintptr, nName int32) {
|
|
bp := tls.Alloc(1248)
|
|
defer tls.Free(1248)
|
|
var got Tssize_t
|
|
var zIn, v2 uintptr
|
|
var v1 int32
|
|
var _ /* buf at bp+0 */ Tstat
|
|
var _ /* zLnk at bp+208 */ [1026]int8
|
|
_, _, _, _ = got, zIn, v1, v2
|
|
if int32(**(**int8)(__ccgo_up(zName))) == int32('.') {
|
|
if nName == int32(1) {
|
|
return
|
|
}
|
|
if int32(**(**int8)(__ccgo_up(zName + 1))) == int32('.') && nName == int32(2) {
|
|
if (*TDbPath)(unsafe.Pointer(pPath)).FnUsed > int32(1) {
|
|
for {
|
|
v2 = pPath + 16
|
|
*(*int32)(unsafe.Pointer(v2)) = *(*int32)(unsafe.Pointer(v2)) - 1
|
|
v1 = *(*int32)(unsafe.Pointer(v2))
|
|
if !(int32(**(**int8)(__ccgo_up((*TDbPath)(unsafe.Pointer(pPath)).FzOut + uintptr(v1)))) != int32('/')) {
|
|
break
|
|
}
|
|
}
|
|
}
|
|
return
|
|
}
|
|
}
|
|
if (*TDbPath)(unsafe.Pointer(pPath)).FnUsed+nName+int32(2) >= (*TDbPath)(unsafe.Pointer(pPath)).FnOut {
|
|
(*TDbPath)(unsafe.Pointer(pPath)).Frc = int32(SQLITE_ERROR)
|
|
return
|
|
}
|
|
v2 = pPath + 16
|
|
v1 = *(*int32)(unsafe.Pointer(v2))
|
|
*(*int32)(unsafe.Pointer(v2)) = *(*int32)(unsafe.Pointer(v2)) + 1
|
|
**(**int8)(__ccgo_up((*TDbPath)(unsafe.Pointer(pPath)).FzOut + uintptr(v1))) = int8('/')
|
|
libc.Xmemcpy(tls, (*TDbPath)(unsafe.Pointer(pPath)).FzOut+uintptr((*TDbPath)(unsafe.Pointer(pPath)).FnUsed), zName, libc.Uint32FromInt32(nName))
|
|
**(**int32)(__ccgo_up(pPath + 16)) += nName
|
|
if (*TDbPath)(unsafe.Pointer(pPath)).Frc == SQLITE_OK {
|
|
**(**int8)(__ccgo_up((*TDbPath)(unsafe.Pointer(pPath)).FzOut + uintptr((*TDbPath)(unsafe.Pointer(pPath)).FnUsed))) = 0
|
|
zIn = (*TDbPath)(unsafe.Pointer(pPath)).FzOut
|
|
if (*(*func(*libc.TLS, uintptr, uintptr) int32)(unsafe.Pointer(&struct{ uintptr }{_aSyscall[int32(27)].FpCurrent})))(tls, zIn, bp) != 0 {
|
|
if **(**int32)(__ccgo_up(libc.X__error(tls))) != int32(ENOENT) {
|
|
(*TDbPath)(unsafe.Pointer(pPath)).Frc = _unixLogErrorAtLine(tls, _sqlite3CantopenError(tls, int32(47152)), __ccgo_ts+3738, zIn, int32(47152))
|
|
}
|
|
} else {
|
|
if libc.Int32FromUint16((**(**Tstat)(__ccgo_up(bp))).Fst_mode)&int32(0170000) == int32(0120000) {
|
|
v2 = pPath + 4
|
|
v1 = *(*int32)(unsafe.Pointer(v2))
|
|
*(*int32)(unsafe.Pointer(v2)) = *(*int32)(unsafe.Pointer(v2)) + 1
|
|
if v1 > int32(SQLITE_MAX_SYMLINK) {
|
|
(*TDbPath)(unsafe.Pointer(pPath)).Frc = _sqlite3CantopenError(tls, int32(47158))
|
|
return
|
|
}
|
|
got = (*(*func(*libc.TLS, uintptr, uintptr, Tsize_t) Tssize_t)(unsafe.Pointer(&struct{ uintptr }{_aSyscall[int32(26)].FpCurrent})))(tls, zIn, bp+208, libc.Uint32FromInt64(1026)-libc.Uint32FromInt32(2))
|
|
if got <= 0 || got >= libc.Int32FromInt64(1026)-libc.Int32FromInt32(2) {
|
|
(*TDbPath)(unsafe.Pointer(pPath)).Frc = _unixLogErrorAtLine(tls, _sqlite3CantopenError(tls, int32(47163)), __ccgo_ts+3729, zIn, int32(47163))
|
|
return
|
|
}
|
|
(**(**[1026]int8)(__ccgo_up(bp + 208)))[got] = 0
|
|
if int32((**(**[1026]int8)(__ccgo_up(bp + 208)))[0]) == int32('/') {
|
|
(*TDbPath)(unsafe.Pointer(pPath)).FnUsed = 0
|
|
} else {
|
|
**(**int32)(__ccgo_up(pPath + 16)) -= nName + int32(1)
|
|
}
|
|
_appendAllPathElements(tls, pPath, bp+208)
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|
|
// 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(48)
|
|
defer tls.Free(48)
|
|
var aNew, db, pNew, pNewSchema, pPager, zFile, zName uintptr
|
|
var i, iDb, rc int32
|
|
var _ /* flags at bp+8 */ uint32
|
|
var _ /* pNewBt at bp+20 */ uintptr
|
|
var _ /* pVfs at bp+16 */ uintptr
|
|
var _ /* zErr at bp+4 */ uintptr
|
|
var _ /* zErrDyn at bp+12 */ 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 + 4)) = uintptr(0) /* New array of Db pointers */
|
|
pNew = uintptr(0) /* Db object for the newly attached database */
|
|
**(**uintptr)(__ccgo_up(bp + 12)) = uintptr(0)
|
|
_ = NotUsed
|
|
zFile = Xsqlite3_value_text(tls, **(**uintptr)(__ccgo_up(argv)))
|
|
zName = Xsqlite3_value_text(tls, **(**uintptr)(__ccgo_up(argv + 1*4)))
|
|
if zFile == uintptr(0) {
|
|
zFile = __ccgo_ts + 1702
|
|
}
|
|
if zName == uintptr(0) {
|
|
zName = __ccgo_ts + 1702
|
|
}
|
|
if int32(uint32(*(*uint8)(unsafe.Pointer(db + 172 + 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 + 20)) = uintptr(0)
|
|
pNew = (*Tsqlite3)(unsafe.Pointer(db)).FaDb + uintptr((*Tsqlite3)(unsafe.Pointer(db)).Finit1.FiDb)*16
|
|
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 + 16)) = Xsqlite3_vfs_find(tls, __ccgo_ts+4114)
|
|
if **(**uintptr)(__ccgo_up(bp + 16)) == uintptr(0) {
|
|
return
|
|
}
|
|
rc = _sqlite3BtreeOpen(tls, **(**uintptr)(__ccgo_up(bp + 16)), __ccgo_ts+13249, db, bp+20, 0, int32(SQLITE_OPEN_MAIN_DB))
|
|
if rc == SQLITE_OK {
|
|
pNewSchema = _sqlite3SchemaGet(tls, db, **(**uintptr)(__ccgo_up(bp + 20)))
|
|
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 + 20))
|
|
(*TDb)(unsafe.Pointer(pNew)).FpSchema = pNewSchema
|
|
} else {
|
|
_sqlite3BtreeClose(tls, **(**uintptr)(__ccgo_up(bp + 20)))
|
|
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 + 116 + 7*4))+int32(2) {
|
|
**(**uintptr)(__ccgo_up(bp + 12)) = _sqlite3MPrintf(tls, db, __ccgo_ts+13252, libc.VaList(bp+32, **(**int32)(__ccgo_up(db + 116 + 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 + 12)) = _sqlite3MPrintf(tls, db, __ccgo_ts+13289, libc.VaList(bp+32, 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+472 {
|
|
aNew = _sqlite3DbMallocRawNN(tls, db, uint64(libc.Uint32FromInt64(16)*libc.Uint32FromInt32(3)))
|
|
if aNew == uintptr(0) {
|
|
return
|
|
}
|
|
libc.Xmemcpy(tls, aNew, (*Tsqlite3)(unsafe.Pointer(db)).FaDb, libc.Uint32FromInt64(16)*libc.Uint32FromInt32(2))
|
|
} else {
|
|
aNew = _sqlite3DbRealloc(tls, db, (*Tsqlite3)(unsafe.Pointer(db)).FaDb, libc.Uint64FromInt64(int64(16)*(int64(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)*16
|
|
libc.Xmemset(tls, pNew, 0, uint32(16))
|
|
/* 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 + 8)) = (*Tsqlite3)(unsafe.Pointer(db)).FopenFlags
|
|
rc = _sqlite3ParseUri(tls, (*Tsqlite3_vfs)(unsafe.Pointer((*Tsqlite3)(unsafe.Pointer(db)).FpVfs)).FzName, zFile, bp+8, bp+16, bp, bp+4)
|
|
if rc != SQLITE_OK {
|
|
if rc == int32(SQLITE_NOMEM) {
|
|
_sqlite3OomFault(tls, db)
|
|
}
|
|
Xsqlite3_result_error(tls, context, **(**uintptr)(__ccgo_up(bp + 4)), -int32(1))
|
|
Xsqlite3_free(tls, **(**uintptr)(__ccgo_up(bp + 4)))
|
|
return
|
|
}
|
|
if (*Tsqlite3)(unsafe.Pointer(db)).Fflags&(libc.Uint64FromInt32(libc.Int32FromInt32(0x00020))<<libc.Int32FromInt32(32)) == uint64(0) {
|
|
**(**uint32)(__ccgo_up(bp + 8)) = **(**uint32)(__ccgo_up(bp + 8)) & libc.Uint32FromInt32(^(libc.Int32FromInt32(SQLITE_OPEN_CREATE) | libc.Int32FromInt32(SQLITE_OPEN_READWRITE)))
|
|
**(**uint32)(__ccgo_up(bp + 8)) = **(**uint32)(__ccgo_up(bp + 8)) | 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 + 8)) = **(**uint32)(__ccgo_up(bp + 8)) & libc.Uint32FromInt32(^libc.Int32FromInt32(SQLITE_OPEN_CREATE))
|
|
}
|
|
}
|
|
**(**uint32)(__ccgo_up(bp + 8)) = **(**uint32)(__ccgo_up(bp + 8)) | uint32(SQLITE_OPEN_MAIN_DB)
|
|
rc = _sqlite3BtreeOpen(tls, **(**uintptr)(__ccgo_up(bp + 16)), **(**uintptr)(__ccgo_up(bp)), db, pNew+4, 0, libc.Int32FromUint32(**(**uint32)(__ccgo_up(bp + 8))))
|
|
(*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 + 12)) = _sqlite3MPrintf(tls, db, __ccgo_ts+13319, 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 + 12)) = _sqlite3MPrintf(tls, db, __ccgo_ts+13348, 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 + 24)) &= libc.Uint32FromInt32(^libc.Int32FromInt32(DBFLAG_SchemaKnownOk))
|
|
if !(int32(uint32(*(*uint8)(unsafe.Pointer(db + 172 + 8))&0x8>>3)) != 0) {
|
|
rc = _sqlite3Init(tls, db, bp+12)
|
|
}
|
|
_sqlite3BtreeLeaveAll(tls, db)
|
|
}
|
|
if rc != 0 {
|
|
if !(int32(uint32(*(*uint8)(unsafe.Pointer(db + 172 + 8))&0x8>>3)) != 0) {
|
|
iDb = (*Tsqlite3)(unsafe.Pointer(db)).FnDb - int32(1)
|
|
if (**(**TDb)(__ccgo_up((*Tsqlite3)(unsafe.Pointer(db)).FaDb + uintptr(iDb)*16))).FpBt != 0 {
|
|
_sqlite3BtreeClose(tls, (**(**TDb)(__ccgo_up((*Tsqlite3)(unsafe.Pointer(db)).FaDb + uintptr(iDb)*16))).FpBt)
|
|
(**(**TDb)(__ccgo_up((*Tsqlite3)(unsafe.Pointer(db)).FaDb + uintptr(iDb)*16))).FpBt = uintptr(0)
|
|
(**(**TDb)(__ccgo_up((*Tsqlite3)(unsafe.Pointer(db)).FaDb + uintptr(iDb)*16))).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 + 12)))
|
|
**(**uintptr)(__ccgo_up(bp + 12)) = _sqlite3MPrintf(tls, db, __ccgo_ts+1672, 0)
|
|
} else {
|
|
if **(**uintptr)(__ccgo_up(bp + 12)) == uintptr(0) {
|
|
**(**uintptr)(__ccgo_up(bp + 12)) = _sqlite3MPrintf(tls, db, __ccgo_ts+13416, libc.VaList(bp+32, zFile))
|
|
}
|
|
}
|
|
}
|
|
goto attach_error
|
|
}
|
|
return
|
|
goto attach_error
|
|
attach_error:
|
|
;
|
|
/* Return an error if we get here */
|
|
if **(**uintptr)(__ccgo_up(bp + 12)) != 0 {
|
|
Xsqlite3_result_error(tls, context, **(**uintptr)(__ccgo_up(bp + 12)), -int32(1))
|
|
_sqlite3DbFree(tls, db, **(**uintptr)(__ccgo_up(bp + 12)))
|
|
}
|
|
if rc != 0 {
|
|
Xsqlite3_result_error_code(tls, context, rc)
|
|
}
|
|
}
|
|
|
|
// 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(336)
|
|
defer tls.Free(336)
|
|
var db, pPrg, pProgram, pTop, pWhen, v, v2 uintptr
|
|
var iEndTrigger, nDepth int32
|
|
var _ /* sNC at bp+0 */ TNameContext
|
|
var _ /* sSubParse at bp+36 */ 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 + 116 + 10*4)) {
|
|
_sqlite3ErrorMsg(tls, pParse, __ccgo_ts+22566, 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(24))
|
|
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(28))
|
|
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 + 16)) = uint32(0xffffffff)
|
|
**(**Tu32)(__ccgo_up(pPrg + 16 + 1*4)) = uint32(0xffffffff)
|
|
/* Allocate and populate a new Parse context to use for coding the
|
|
** trigger sub-program. */
|
|
_sqlite3ParseObjectInit(tls, bp+36, db)
|
|
libc.Xmemset(tls, bp, 0, uint32(36))
|
|
(**(**TNameContext)(__ccgo_up(bp))).FpParse = bp + 36
|
|
(**(**TParse)(__ccgo_up(bp + 36))).FpTriggerTab = pTab
|
|
(**(**TParse)(__ccgo_up(bp + 36))).FpToplevel = pTop
|
|
(**(**TParse)(__ccgo_up(bp + 36))).FzAuthContext = (*TTrigger)(unsafe.Pointer(pTrigger)).FzName
|
|
(**(**TParse)(__ccgo_up(bp + 36))).FeTriggerOp = (*TTrigger)(unsafe.Pointer(pTrigger)).Fop
|
|
(**(**TParse)(__ccgo_up(bp + 36))).FnQueryLoop = (*TParse)(unsafe.Pointer(pParse)).FnQueryLoop
|
|
(**(**TParse)(__ccgo_up(bp + 36))).FprepFlags = (*TParse)(unsafe.Pointer(pParse)).FprepFlags
|
|
(**(**TParse)(__ccgo_up(bp + 36))).Foldmask = uint32(0)
|
|
(**(**TParse)(__ccgo_up(bp + 36))).Fnewmask = uint32(0)
|
|
v = _sqlite3GetVdbe(tls, bp+36)
|
|
if v != 0 {
|
|
if (*TTrigger)(unsafe.Pointer(pTrigger)).FzName != 0 {
|
|
_sqlite3VdbeChangeP4(tls, v, -int32(1), _sqlite3MPrintf(tls, db, __ccgo_ts+22591, libc.VaList(bp+328, (*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+36)
|
|
_sqlite3ExprIfFalse(tls, bp+36, pWhen, iEndTrigger, int32(SQLITE_JUMPIFNULL))
|
|
}
|
|
_sqlite3ExprDelete(tls, db, pWhen)
|
|
}
|
|
/* Code the trigger program into the sub-vdbe. */
|
|
_codeTriggerProgram(tls, bp+36, (*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+36)
|
|
if (*TParse)(unsafe.Pointer(pParse)).FnErr == 0 {
|
|
(*TSubProgram)(unsafe.Pointer(pProgram)).FaOp = _sqlite3VdbeTakeOpArray(tls, v, pProgram+4, pTop+96)
|
|
}
|
|
(*TSubProgram)(unsafe.Pointer(pProgram)).FnMem = (**(**TParse)(__ccgo_up(bp + 36))).FnMem
|
|
(*TSubProgram)(unsafe.Pointer(pProgram)).FnCsr = (**(**TParse)(__ccgo_up(bp + 36))).FnTab
|
|
(*TSubProgram)(unsafe.Pointer(pProgram)).Ftoken = pTrigger
|
|
**(**Tu32)(__ccgo_up(pPrg + 16)) = (**(**TParse)(__ccgo_up(bp + 36))).Foldmask
|
|
**(**Tu32)(__ccgo_up(pPrg + 16 + 1*4)) = (**(**TParse)(__ccgo_up(bp + 36))).Fnewmask
|
|
_sqlite3VdbeDelete(tls, v)
|
|
} else {
|
|
_transferParseError(tls, pParse, bp+36)
|
|
}
|
|
_sqlite3ParseObjectReset(tls, bp+36)
|
|
return pPrg
|
|
}
|
|
|
|
// C documentation
|
|
//
|
|
// /*
|
|
// ** Generate code to construct the Index object for an automatic index
|
|
// ** and to set up the WhereLevel object pLevel so that the code generator
|
|
// ** makes use of the automatic index.
|
|
// */
|
|
func _constructAutomaticIndex(tls *libc.TLS, pParse uintptr, pWC uintptr, notReady TBitmask, pLevel uintptr) {
|
|
bp := tls.Alloc(32)
|
|
defer tls.Free(32)
|
|
var addrCounter, addrInit, addrTop, i, iCol, iCol1, iContinue, mxBitCol, n, nKeyCol, regBase, regRecord, regYield, v3 int32
|
|
var cMask, cMask1, extraCols, idxCols TBitmask
|
|
var pColl, pExpr, pIdx, pLoop, pPartial, pSrc, pSubq, pTabList, pTable, pTerm, pWCEnd, pX, v, v10 uintptr
|
|
var sentWarning, useBloomFilter Tu8
|
|
var v2 uint64
|
|
var v4 Tu16
|
|
var _ /* zNotUsed at bp+0 */ uintptr
|
|
_, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _ = addrCounter, addrInit, addrTop, cMask, cMask1, extraCols, i, iCol, iCol1, iContinue, idxCols, mxBitCol, n, nKeyCol, pColl, pExpr, pIdx, pLoop, pPartial, pSrc, pSubq, pTabList, pTable, pTerm, pWCEnd, pX, regBase, regRecord, regYield, sentWarning, useBloomFilter, v, v10, v2, v3, v4 /* Bitmap of additional columns */
|
|
sentWarning = uint8(0) /* True if a warning has been issued */
|
|
useBloomFilter = uint8(0) /* True to also add a Bloom filter */
|
|
pPartial = uintptr(0) /* Partial Index Expression */
|
|
iContinue = 0 /* The FROM clause term to get the next index */
|
|
addrCounter = 0 /* Array of registers where record is assembled */
|
|
/* Generate code to skip over the creation and initialization of the
|
|
** transient index on 2nd and subsequent iterations of the loop. */
|
|
v = (*TParse)(unsafe.Pointer(pParse)).FpVdbe
|
|
addrInit = _sqlite3VdbeAddOp0(tls, v, int32(OP_Once))
|
|
/* Count the number of columns that will be added to the index
|
|
** and used to match WHERE clause constraints */
|
|
nKeyCol = 0
|
|
pTabList = (*TWhereInfo)(unsafe.Pointer((*TWhereClause)(unsafe.Pointer(pWC)).FpWInfo)).FpTabList
|
|
pSrc = pTabList + 8 + uintptr((*TWhereLevel)(unsafe.Pointer(pLevel)).FiFrom)*48
|
|
pTable = (*TSrcItem)(unsafe.Pointer(pSrc)).FpSTab
|
|
pWCEnd = (*TWhereClause)(unsafe.Pointer(pWC)).Fa + uintptr((*TWhereClause)(unsafe.Pointer(pWC)).FnTerm)*48
|
|
pLoop = (*TWhereLevel)(unsafe.Pointer(pLevel)).FpWLoop
|
|
idxCols = uint64(0)
|
|
pTerm = (*TWhereClause)(unsafe.Pointer(pWC)).Fa
|
|
for {
|
|
if !(pTerm < pWCEnd) {
|
|
break
|
|
}
|
|
pExpr = (*TWhereTerm)(unsafe.Pointer(pTerm)).FpExpr
|
|
/* Make the automatic index a partial index if there are terms in the
|
|
** WHERE clause (or the ON clause of a LEFT join) that constrain which
|
|
** rows of the target table (pSrc) that can be used. */
|
|
if libc.Int32FromUint16((*TWhereTerm)(unsafe.Pointer(pTerm)).FwtFlags)&int32(TERM_VIRTUAL) == 0 && _sqlite3ExprIsSingleTableConstraint(tls, pExpr, pTabList, libc.Int32FromUint8((*TWhereLevel)(unsafe.Pointer(pLevel)).FiFrom), 0) != 0 {
|
|
pPartial = _sqlite3ExprAnd(tls, pParse, pPartial, _sqlite3ExprDup(tls, (*TParse)(unsafe.Pointer(pParse)).Fdb, pExpr, 0))
|
|
}
|
|
if _termCanDriveIndex(tls, pTerm, pSrc, notReady) != 0 {
|
|
iCol = (*(*struct {
|
|
FleftColumn int32
|
|
FiField int32
|
|
})(unsafe.Pointer(pTerm + 24))).FleftColumn
|
|
if iCol >= libc.Int32FromUint32(libc.Uint32FromInt64(8)*libc.Uint32FromInt32(8)) {
|
|
v2 = libc.Uint64FromInt32(1) << (libc.Int32FromUint32(libc.Uint32FromInt64(8)*libc.Uint32FromInt32(8)) - libc.Int32FromInt32(1))
|
|
} else {
|
|
v2 = libc.Uint64FromInt32(1) << iCol
|
|
}
|
|
cMask = v2
|
|
if !(sentWarning != 0) {
|
|
Xsqlite3_log(tls, libc.Int32FromInt32(SQLITE_WARNING)|libc.Int32FromInt32(1)<<libc.Int32FromInt32(8), __ccgo_ts+23986, libc.VaList(bp+16, (*TTable)(unsafe.Pointer(pTable)).FzName, (**(**TColumn)(__ccgo_up((*TTable)(unsafe.Pointer(pTable)).FaCol + uintptr(iCol)*12))).FzCnName))
|
|
sentWarning = uint8(1)
|
|
}
|
|
if idxCols&cMask == uint64(0) {
|
|
if _whereLoopResize(tls, (*TParse)(unsafe.Pointer(pParse)).Fdb, pLoop, nKeyCol+int32(1)) != 0 {
|
|
goto end_auto_index_create
|
|
}
|
|
v3 = nKeyCol
|
|
nKeyCol = nKeyCol + 1
|
|
**(**uintptr)(__ccgo_up((*TWhereLoop)(unsafe.Pointer(pLoop)).FaLTerm + uintptr(v3)*4)) = pTerm
|
|
idxCols = idxCols | cMask
|
|
}
|
|
}
|
|
goto _1
|
|
_1:
|
|
;
|
|
pTerm += 48
|
|
}
|
|
v4 = libc.Uint16FromInt32(nKeyCol)
|
|
(*TWhereLoop)(unsafe.Pointer(pLoop)).FnLTerm = v4
|
|
(*(*struct {
|
|
FnEq Tu16
|
|
FnBtm Tu16
|
|
FnTop Tu16
|
|
FnDistinctCol Tu16
|
|
FpIndex uintptr
|
|
FpOrderBy uintptr
|
|
})(unsafe.Pointer(pLoop + 24))).FnEq = v4
|
|
(*TWhereLoop)(unsafe.Pointer(pLoop)).FwsFlags = libc.Uint32FromInt32(libc.Int32FromInt32(WHERE_COLUMN_EQ) | libc.Int32FromInt32(WHERE_IDX_ONLY) | libc.Int32FromInt32(WHERE_INDEXED) | libc.Int32FromInt32(WHERE_AUTO_INDEX))
|
|
/* Count the number of additional columns needed to create a
|
|
** covering index. A "covering index" is an index that contains all
|
|
** columns that are needed by the query. With a covering index, the
|
|
** original table never needs to be accessed. Automatic indices must
|
|
** be a covering index because the index will not be updated if the
|
|
** original table changes and the index and table cannot both be used
|
|
** if they go out of sync.
|
|
*/
|
|
if libc.Int32FromUint8((*TTable)(unsafe.Pointer(pTable)).FeTabType) == int32(TABTYP_VIEW) {
|
|
extraCols = libc.Uint64FromInt32(-libc.Int32FromInt32(1)) & ^idxCols
|
|
} else {
|
|
extraCols = (*TSrcItem)(unsafe.Pointer(pSrc)).FcolUsed & (^idxCols | libc.Uint64FromInt32(1)<<(libc.Int32FromUint32(libc.Uint32FromInt64(8)*libc.Uint32FromInt32(8))-libc.Int32FromInt32(1)))
|
|
}
|
|
if !((*TTable)(unsafe.Pointer(pTable)).FtabFlags&libc.Uint32FromInt32(TF_WithoutRowid) == libc.Uint32FromInt32(0)) {
|
|
/* For WITHOUT ROWID tables, ensure that all PRIMARY KEY columns are
|
|
** either in the idxCols mask or in the extraCols mask */
|
|
i = 0
|
|
for {
|
|
if !(i < int32((*TTable)(unsafe.Pointer(pTable)).FnCol)) {
|
|
break
|
|
}
|
|
if libc.Int32FromUint16((**(**TColumn)(__ccgo_up((*TTable)(unsafe.Pointer(pTable)).FaCol + uintptr(i)*12))).FcolFlags)&int32(COLFLAG_PRIMKEY) == 0 {
|
|
goto _5
|
|
}
|
|
if i >= libc.Int32FromUint32(libc.Uint32FromInt64(8)*libc.Uint32FromInt32(8))-libc.Int32FromInt32(1) {
|
|
extraCols = extraCols | libc.Uint64FromInt32(1)<<(libc.Int32FromUint32(libc.Uint32FromInt64(8)*libc.Uint32FromInt32(8))-libc.Int32FromInt32(1))
|
|
break
|
|
}
|
|
if idxCols&(libc.Uint64FromInt32(1)<<i) != 0 {
|
|
goto _5
|
|
}
|
|
extraCols = extraCols | libc.Uint64FromInt32(1)<<i
|
|
goto _5
|
|
_5:
|
|
;
|
|
i = i + 1
|
|
}
|
|
}
|
|
if libc.Int32FromUint32(libc.Uint32FromInt64(8)*libc.Uint32FromInt32(8))-libc.Int32FromInt32(1) < int32((*TTable)(unsafe.Pointer(pTable)).FnCol) {
|
|
v3 = libc.Int32FromUint32(libc.Uint32FromInt64(8)*libc.Uint32FromInt32(8)) - libc.Int32FromInt32(1)
|
|
} else {
|
|
v3 = int32((*TTable)(unsafe.Pointer(pTable)).FnCol)
|
|
}
|
|
mxBitCol = v3
|
|
i = 0
|
|
for {
|
|
if !(i < mxBitCol) {
|
|
break
|
|
}
|
|
if extraCols&(libc.Uint64FromInt32(1)<<i) != 0 {
|
|
nKeyCol = nKeyCol + 1
|
|
}
|
|
goto _7
|
|
_7:
|
|
;
|
|
i = i + 1
|
|
}
|
|
if (*TSrcItem)(unsafe.Pointer(pSrc)).FcolUsed&(libc.Uint64FromInt32(1)<<(libc.Int32FromUint32(libc.Uint32FromInt64(8)*libc.Uint32FromInt32(8))-libc.Int32FromInt32(1))) != 0 {
|
|
nKeyCol = nKeyCol + (int32((*TTable)(unsafe.Pointer(pTable)).FnCol) - libc.Int32FromUint32(libc.Uint32FromInt64(8)*libc.Uint32FromInt32(8)) + int32(1))
|
|
}
|
|
/* Construct the Index object to describe this index */
|
|
/* ^-- This guarantees that the number of index columns will fit in the u16 */
|
|
pIdx = _sqlite3AllocateIndexObject(tls, (*TParse)(unsafe.Pointer(pParse)).Fdb, nKeyCol+libc.BoolInt32((*TTable)(unsafe.Pointer(pTable)).FtabFlags&uint32(TF_WithoutRowid) == uint32(0)), 0, bp)
|
|
if pIdx == uintptr(0) {
|
|
goto end_auto_index_create
|
|
}
|
|
(*(*struct {
|
|
FnEq Tu16
|
|
FnBtm Tu16
|
|
FnTop Tu16
|
|
FnDistinctCol Tu16
|
|
FpIndex uintptr
|
|
FpOrderBy uintptr
|
|
})(unsafe.Pointer(pLoop + 24))).FpIndex = pIdx
|
|
(*TIndex)(unsafe.Pointer(pIdx)).FzName = __ccgo_ts + 24012
|
|
(*TIndex)(unsafe.Pointer(pIdx)).FpTable = pTable
|
|
n = 0
|
|
idxCols = uint64(0)
|
|
pTerm = (*TWhereClause)(unsafe.Pointer(pWC)).Fa
|
|
for {
|
|
if !(pTerm < pWCEnd) {
|
|
break
|
|
}
|
|
if _termCanDriveIndex(tls, pTerm, pSrc, notReady) != 0 {
|
|
iCol1 = (*(*struct {
|
|
FleftColumn int32
|
|
FiField int32
|
|
})(unsafe.Pointer(pTerm + 24))).FleftColumn
|
|
if iCol1 >= libc.Int32FromUint32(libc.Uint32FromInt64(8)*libc.Uint32FromInt32(8)) {
|
|
v2 = libc.Uint64FromInt32(1) << (libc.Int32FromUint32(libc.Uint32FromInt64(8)*libc.Uint32FromInt32(8)) - libc.Int32FromInt32(1))
|
|
} else {
|
|
v2 = libc.Uint64FromInt32(1) << iCol1
|
|
}
|
|
cMask1 = v2
|
|
if idxCols&cMask1 == uint64(0) {
|
|
pX = (*TWhereTerm)(unsafe.Pointer(pTerm)).FpExpr
|
|
idxCols = idxCols | cMask1
|
|
**(**Ti16)(__ccgo_up((*TIndex)(unsafe.Pointer(pIdx)).FaiColumn + uintptr(n)*2)) = int16((*(*struct {
|
|
FleftColumn int32
|
|
FiField int32
|
|
})(unsafe.Pointer(pTerm + 24))).FleftColumn)
|
|
pColl = _sqlite3ExprCompareCollSeq(tls, pParse, pX)
|
|
/* TH3 collate01.800 */
|
|
if pColl != 0 {
|
|
v10 = (*TCollSeq)(unsafe.Pointer(pColl)).FzName
|
|
} else {
|
|
v10 = uintptr(unsafe.Pointer(&_sqlite3StrBINARY))
|
|
}
|
|
**(**uintptr)(__ccgo_up((*TIndex)(unsafe.Pointer(pIdx)).FazColl + uintptr(n)*4)) = v10
|
|
n = n + 1
|
|
if (*TExpr)(unsafe.Pointer(pX)).FpLeft != uintptr(0) && int32(_sqlite3ExprAffinity(tls, (*TExpr)(unsafe.Pointer(pX)).FpLeft)) != int32(SQLITE_AFF_TEXT) {
|
|
/* TUNING: only use a Bloom filter on an automatic index
|
|
** if one or more key columns has the ability to hold numeric
|
|
** values, since strings all have the same hash in the Bloom
|
|
** filter implementation and hence a Bloom filter on a text column
|
|
** is not usually helpful. */
|
|
useBloomFilter = uint8(1)
|
|
}
|
|
}
|
|
}
|
|
goto _8
|
|
_8:
|
|
;
|
|
pTerm += 48
|
|
}
|
|
/* Add additional columns needed to make the automatic index into
|
|
** a covering index */
|
|
i = 0
|
|
for {
|
|
if !(i < mxBitCol) {
|
|
break
|
|
}
|
|
if extraCols&(libc.Uint64FromInt32(1)<<i) != 0 {
|
|
**(**Ti16)(__ccgo_up((*TIndex)(unsafe.Pointer(pIdx)).FaiColumn + uintptr(n)*2)) = int16(i)
|
|
**(**uintptr)(__ccgo_up((*TIndex)(unsafe.Pointer(pIdx)).FazColl + uintptr(n)*4)) = uintptr(unsafe.Pointer(&_sqlite3StrBINARY))
|
|
n = n + 1
|
|
}
|
|
goto _11
|
|
_11:
|
|
;
|
|
i = i + 1
|
|
}
|
|
if (*TSrcItem)(unsafe.Pointer(pSrc)).FcolUsed&(libc.Uint64FromInt32(1)<<(libc.Int32FromUint32(libc.Uint32FromInt64(8)*libc.Uint32FromInt32(8))-libc.Int32FromInt32(1))) != 0 {
|
|
i = libc.Int32FromUint32(libc.Uint32FromInt64(8)*libc.Uint32FromInt32(8)) - libc.Int32FromInt32(1)
|
|
for {
|
|
if !(i < int32((*TTable)(unsafe.Pointer(pTable)).FnCol)) {
|
|
break
|
|
}
|
|
**(**Ti16)(__ccgo_up((*TIndex)(unsafe.Pointer(pIdx)).FaiColumn + uintptr(n)*2)) = int16(i)
|
|
**(**uintptr)(__ccgo_up((*TIndex)(unsafe.Pointer(pIdx)).FazColl + uintptr(n)*4)) = uintptr(unsafe.Pointer(&_sqlite3StrBINARY))
|
|
n = n + 1
|
|
goto _12
|
|
_12:
|
|
;
|
|
i = i + 1
|
|
}
|
|
}
|
|
if (*TTable)(unsafe.Pointer(pTable)).FtabFlags&uint32(TF_WithoutRowid) == uint32(0) {
|
|
**(**Ti16)(__ccgo_up((*TIndex)(unsafe.Pointer(pIdx)).FaiColumn + uintptr(n)*2)) = int16(-libc.Int32FromInt32(1))
|
|
**(**uintptr)(__ccgo_up((*TIndex)(unsafe.Pointer(pIdx)).FazColl + uintptr(n)*4)) = uintptr(unsafe.Pointer(&_sqlite3StrBINARY))
|
|
}
|
|
/* Create the automatic index */
|
|
v10 = pParse + 44
|
|
v3 = *(*int32)(unsafe.Pointer(v10))
|
|
*(*int32)(unsafe.Pointer(v10)) = *(*int32)(unsafe.Pointer(v10)) + 1
|
|
(*TWhereLevel)(unsafe.Pointer(pLevel)).FiIdxCur = v3
|
|
_sqlite3VdbeAddOp2(tls, v, int32(OP_OpenAutoindex), (*TWhereLevel)(unsafe.Pointer(pLevel)).FiIdxCur, nKeyCol+int32(1))
|
|
_sqlite3VdbeSetP4KeyInfo(tls, pParse, pIdx)
|
|
if (*Tsqlite3)(unsafe.Pointer((*TParse)(unsafe.Pointer(pParse)).Fdb)).FdbOptFlags&libc.Uint32FromInt32(libc.Int32FromInt32(SQLITE_BloomFilter)) == uint32(0) && useBloomFilter != 0 {
|
|
_sqlite3WhereExplainBloomFilter(tls, pParse, (*TWhereClause)(unsafe.Pointer(pWC)).FpWInfo, pLevel)
|
|
v10 = pParse + 48
|
|
*(*int32)(unsafe.Pointer(v10)) = *(*int32)(unsafe.Pointer(v10)) + 1
|
|
v3 = *(*int32)(unsafe.Pointer(v10))
|
|
(*TWhereLevel)(unsafe.Pointer(pLevel)).FregFilter = v3
|
|
_sqlite3VdbeAddOp2(tls, v, int32(OP_Blob), int32(10000), (*TWhereLevel)(unsafe.Pointer(pLevel)).FregFilter)
|
|
}
|
|
/* Fill the automatic index with content */
|
|
if int32(*(*uint32)(unsafe.Pointer(pSrc + 12 + 4))&0x40>>6) != 0 {
|
|
pSubq = *(*uintptr)(unsafe.Pointer(pSrc + 44))
|
|
regYield = (*TSubquery)(unsafe.Pointer(pSubq)).FregReturn
|
|
addrCounter = _sqlite3VdbeAddOp2(tls, v, int32(OP_Integer), 0, 0)
|
|
_sqlite3VdbeAddOp3(tls, v, int32(OP_InitCoroutine), regYield, 0, (*TSubquery)(unsafe.Pointer(pSubq)).FaddrFillSub)
|
|
addrTop = _sqlite3VdbeAddOp1(tls, v, int32(OP_Yield), regYield)
|
|
} else {
|
|
addrTop = _sqlite3VdbeAddOp2(tls, v, int32(OP_Rewind), (*TWhereLevel)(unsafe.Pointer(pLevel)).FiTabCur, (*TWhereLevel)(unsafe.Pointer(pLevel)).FaddrHalt)
|
|
}
|
|
if pPartial != 0 {
|
|
iContinue = _sqlite3VdbeMakeLabel(tls, pParse)
|
|
_sqlite3ExprIfFalse(tls, pParse, pPartial, iContinue, int32(SQLITE_JUMPIFNULL))
|
|
**(**Tu32)(__ccgo_up(pLoop + 40)) |= uint32(WHERE_PARTIALIDX)
|
|
}
|
|
regRecord = _sqlite3GetTempReg(tls, pParse)
|
|
regBase = _sqlite3GenerateIndexKey(tls, pParse, pIdx, (*TWhereLevel)(unsafe.Pointer(pLevel)).FiTabCur, regRecord, 0, uintptr(0), uintptr(0), 0)
|
|
if (*TWhereLevel)(unsafe.Pointer(pLevel)).FregFilter != 0 {
|
|
_sqlite3VdbeAddOp4Int(tls, v, int32(OP_FilterAdd), (*TWhereLevel)(unsafe.Pointer(pLevel)).FregFilter, 0, regBase, libc.Int32FromUint16((*(*struct {
|
|
FnEq Tu16
|
|
FnBtm Tu16
|
|
FnTop Tu16
|
|
FnDistinctCol Tu16
|
|
FpIndex uintptr
|
|
FpOrderBy uintptr
|
|
})(unsafe.Pointer(pLoop + 24))).FnEq))
|
|
}
|
|
_sqlite3VdbeAddOp2(tls, v, int32(OP_IdxInsert), (*TWhereLevel)(unsafe.Pointer(pLevel)).FiIdxCur, regRecord)
|
|
_sqlite3VdbeChangeP5(tls, v, uint16(OPFLAG_USESEEKRESULT))
|
|
if pPartial != 0 {
|
|
_sqlite3VdbeResolveLabel(tls, v, iContinue)
|
|
}
|
|
if int32(*(*uint32)(unsafe.Pointer(pSrc + 12 + 4))&0x40>>6) != 0 {
|
|
_sqlite3VdbeChangeP2(tls, v, addrCounter, regBase+n)
|
|
_translateColumnToCopy(tls, pParse, addrTop, (*TWhereLevel)(unsafe.Pointer(pLevel)).FiTabCur, (*TSubquery)(unsafe.Pointer(*(*uintptr)(unsafe.Pointer(pSrc + 44)))).FregResult, (*TWhereLevel)(unsafe.Pointer(pLevel)).FiIdxCur)
|
|
_sqlite3VdbeGoto(tls, v, addrTop)
|
|
libc.SetBitFieldPtr32Uint32(pSrc+12+4, libc.Uint32FromInt32(0), 6, 0x40)
|
|
_sqlite3VdbeJumpHere(tls, v, addrTop)
|
|
} else {
|
|
_sqlite3VdbeAddOp2(tls, v, int32(OP_Next), (*TWhereLevel)(unsafe.Pointer(pLevel)).FiTabCur, addrTop+int32(1))
|
|
_sqlite3VdbeChangeP5(tls, v, uint16(SQLITE_STMTSTATUS_AUTOINDEX))
|
|
if libc.Int32FromUint8((*TSrcItem)(unsafe.Pointer(pSrc)).Ffg.Fjointype)&int32(JT_LEFT) != 0 {
|
|
_sqlite3VdbeJumpHere(tls, v, addrTop)
|
|
}
|
|
}
|
|
_sqlite3ReleaseTempReg(tls, pParse, regRecord)
|
|
/* Jump here when skipping the initialization */
|
|
_sqlite3VdbeJumpHere(tls, v, addrInit)
|
|
goto end_auto_index_create
|
|
end_auto_index_create:
|
|
;
|
|
_sqlite3ExprDelete(tls, (*TParse)(unsafe.Pointer(pParse)).Fdb, pPartial)
|
|
}
|
|
|
|
// C documentation
|
|
//
|
|
// /*
|
|
// ** Fill the InitData structure with an error message that indicates
|
|
// ** that the database is corrupt.
|
|
// */
|
|
func _corruptSchema(tls *libc.TLS, pData uintptr, azObj uintptr, zExtra uintptr) {
|
|
bp := tls.Alloc(48)
|
|
defer tls.Free(48)
|
|
var db, z, zObj, v1 uintptr
|
|
_, _, _, _ = db, z, zObj, v1
|
|
db = (*TInitData)(unsafe.Pointer(pData)).Fdb
|
|
if (*Tsqlite3)(unsafe.Pointer(db)).FmallocFailed != 0 {
|
|
(*TInitData)(unsafe.Pointer(pData)).Frc = int32(SQLITE_NOMEM)
|
|
} else {
|
|
if **(**uintptr)(__ccgo_up((*TInitData)(unsafe.Pointer(pData)).FpzErrMsg)) != uintptr(0) {
|
|
/* A error message has already been generated. Do not overwrite it */
|
|
} else {
|
|
if (*TInitData)(unsafe.Pointer(pData)).FmInitFlags&libc.Uint32FromInt32(libc.Int32FromInt32(INITFLAG_AlterMask)) != 0 {
|
|
**(**uintptr)(__ccgo_up((*TInitData)(unsafe.Pointer(pData)).FpzErrMsg)) = _sqlite3MPrintf(tls, db, __ccgo_ts+20025, libc.VaList(bp+8, **(**uintptr)(__ccgo_up(azObj)), **(**uintptr)(__ccgo_up(azObj + 1*4)), _azAlterType[(*TInitData)(unsafe.Pointer(pData)).FmInitFlags&uint32(INITFLAG_AlterMask)-uint32(1)], zExtra))
|
|
(*TInitData)(unsafe.Pointer(pData)).Frc = int32(SQLITE_ERROR)
|
|
} else {
|
|
if (*Tsqlite3)(unsafe.Pointer(db)).Fflags&uint64(SQLITE_WriteSchema) != 0 {
|
|
(*TInitData)(unsafe.Pointer(pData)).Frc = _sqlite3CorruptError(tls, int32(147944))
|
|
} else {
|
|
if **(**uintptr)(__ccgo_up(azObj + 1*4)) != 0 {
|
|
v1 = **(**uintptr)(__ccgo_up(azObj + 1*4))
|
|
} else {
|
|
v1 = __ccgo_ts + 5261
|
|
}
|
|
zObj = v1
|
|
z = _sqlite3MPrintf(tls, db, __ccgo_ts+20053, libc.VaList(bp+8, zObj))
|
|
if zExtra != 0 && **(**int8)(__ccgo_up(zExtra)) != 0 {
|
|
z = _sqlite3MPrintf(tls, db, __ccgo_ts+20084, libc.VaList(bp+8, z, zExtra))
|
|
}
|
|
**(**uintptr)(__ccgo_up((*TInitData)(unsafe.Pointer(pData)).FpzErrMsg)) = z
|
|
(*TInitData)(unsafe.Pointer(pData)).Frc = _sqlite3CorruptError(tls, int32(147951))
|
|
}
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|
|
// 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+26048, 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+444, zName)
|
|
j = 0
|
|
for {
|
|
if !(j < int32(3)) {
|
|
break
|
|
}
|
|
p = aColl + uintptr(j)*20
|
|
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
|
|
//
|
|
// /*
|
|
// ** Generate a CREATE TABLE statement appropriate for the given
|
|
// ** table. Memory to hold the text of the statement is obtained
|
|
// ** from sqliteMalloc() and must be freed by the calling function.
|
|
// */
|
|
func _createTableStmt(tls *libc.TLS, db uintptr, p uintptr) (r uintptr) {
|
|
bp := tls.Alloc(16)
|
|
defer tls.Free(16)
|
|
var i, len1, v2 int32
|
|
var n Ti64
|
|
var pCol, zEnd, zSep, zSep2, zStmt, zType uintptr
|
|
var _ /* k at bp+0 */ int32
|
|
_, _, _, _, _, _, _, _, _, _ = i, len1, n, pCol, zEnd, zSep, zSep2, zStmt, zType, v2
|
|
n = 0
|
|
pCol = (*TTable)(unsafe.Pointer(p)).FaCol
|
|
i = libc.Int32FromInt32(0)
|
|
for {
|
|
if !(i < int32((*TTable)(unsafe.Pointer(p)).FnCol)) {
|
|
break
|
|
}
|
|
n = n + (_identLength(tls, (*TColumn)(unsafe.Pointer(pCol)).FzCnName) + int64(5))
|
|
goto _1
|
|
_1:
|
|
;
|
|
i = i + 1
|
|
pCol += 12
|
|
}
|
|
n = n + _identLength(tls, (*TTable)(unsafe.Pointer(p)).FzName)
|
|
if n < int64(50) {
|
|
zSep = __ccgo_ts + 1702
|
|
zSep2 = __ccgo_ts + 14348
|
|
zEnd = __ccgo_ts + 5259
|
|
} else {
|
|
zSep = __ccgo_ts + 14350
|
|
zSep2 = __ccgo_ts + 14354
|
|
zEnd = __ccgo_ts + 14359
|
|
}
|
|
n = n + int64(int32(35)+int32(6)*int32((*TTable)(unsafe.Pointer(p)).FnCol))
|
|
zStmt = _sqlite3DbMallocRaw(tls, uintptr(0), libc.Uint64FromInt64(n))
|
|
if zStmt == uintptr(0) {
|
|
_sqlite3OomFault(tls, db)
|
|
return uintptr(0)
|
|
}
|
|
libc.Xmemcpy(tls, zStmt, __ccgo_ts+14362, uint32(13))
|
|
**(**int32)(__ccgo_up(bp)) = int32(13)
|
|
_identPut(tls, zStmt, bp, (*TTable)(unsafe.Pointer(p)).FzName)
|
|
v2 = **(**int32)(__ccgo_up(bp))
|
|
**(**int32)(__ccgo_up(bp)) = **(**int32)(__ccgo_up(bp)) + 1
|
|
**(**int8)(__ccgo_up(zStmt + uintptr(v2))) = int8('(')
|
|
pCol = (*TTable)(unsafe.Pointer(p)).FaCol
|
|
i = libc.Int32FromInt32(0)
|
|
for {
|
|
if !(i < int32((*TTable)(unsafe.Pointer(p)).FnCol)) {
|
|
break
|
|
}
|
|
len1 = _sqlite3Strlen30(tls, zSep)
|
|
libc.Xmemcpy(tls, zStmt+uintptr(**(**int32)(__ccgo_up(bp))), zSep, libc.Uint32FromInt32(len1))
|
|
**(**int32)(__ccgo_up(bp)) = **(**int32)(__ccgo_up(bp)) + len1
|
|
zSep = zSep2
|
|
_identPut(tls, zStmt, bp, (*TColumn)(unsafe.Pointer(pCol)).FzCnName)
|
|
zType = _azType1[int32((*TColumn)(unsafe.Pointer(pCol)).Faffinity)-int32(SQLITE_AFF_BLOB)]
|
|
len1 = _sqlite3Strlen30(tls, zType)
|
|
libc.Xmemcpy(tls, zStmt+uintptr(**(**int32)(__ccgo_up(bp))), zType, libc.Uint32FromInt32(len1))
|
|
**(**int32)(__ccgo_up(bp)) = **(**int32)(__ccgo_up(bp)) + len1
|
|
goto _3
|
|
_3:
|
|
;
|
|
i = i + 1
|
|
pCol += 12
|
|
}
|
|
len1 = _sqlite3Strlen30(tls, zEnd)
|
|
libc.Xmemcpy(tls, zStmt+uintptr(**(**int32)(__ccgo_up(bp))), zEnd, libc.Uint32FromInt32(len1+int32(1)))
|
|
return zStmt
|
|
}
|
|
|
|
// C documentation
|
|
//
|
|
// /*
|
|
// ** The first argument points to a nul-terminated string containing a
|
|
// ** list of space separated integers. Read the first nOut of these into
|
|
// ** the array aOut[].
|
|
// */
|
|
func _decodeIntArray(tls *libc.TLS, zIntArray uintptr, nOut int32, aOut uintptr, aLog uintptr, pIndex uintptr) {
|
|
var c, i, sz, v2 int32
|
|
var v TtRowcnt
|
|
var z uintptr
|
|
_, _, _, _, _, _ = c, i, sz, v, z, v2
|
|
z = zIntArray
|
|
if z == uintptr(0) {
|
|
z = __ccgo_ts + 1702
|
|
}
|
|
i = 0
|
|
for {
|
|
if !(**(**int8)(__ccgo_up(z)) != 0 && i < nOut) {
|
|
break
|
|
}
|
|
v = uint64(0)
|
|
for {
|
|
v2 = int32(**(**int8)(__ccgo_up(z)))
|
|
c = v2
|
|
if !(v2 >= int32('0') && c <= int32('9')) {
|
|
break
|
|
}
|
|
v = v*uint64(10) + libc.Uint64FromInt32(c) - uint64('0')
|
|
z = z + 1
|
|
}
|
|
if aOut != 0 {
|
|
**(**TtRowcnt)(__ccgo_up(aOut + uintptr(i)*8)) = v
|
|
}
|
|
if aLog != 0 {
|
|
**(**TLogEst)(__ccgo_up(aLog + uintptr(i)*2)) = _sqlite3LogEst(tls, v)
|
|
}
|
|
if int32(**(**int8)(__ccgo_up(z))) == int32(' ') {
|
|
z = z + 1
|
|
}
|
|
goto _1
|
|
_1:
|
|
;
|
|
i = i + 1
|
|
}
|
|
if pIndex != 0 {
|
|
libc.SetBitFieldPtr16Uint32(pIndex+56, libc.Uint32FromInt32(0), 2, 0x4)
|
|
libc.SetBitFieldPtr16Uint32(pIndex+56, libc.Uint32FromInt32(0), 6, 0x40)
|
|
for **(**int8)(__ccgo_up(z)) != 0 {
|
|
if Xsqlite3_strglob(tls, __ccgo_ts+13054, z) == 0 {
|
|
libc.SetBitFieldPtr16Uint32(pIndex+56, libc.Uint32FromInt32(1), 2, 0x4)
|
|
} else {
|
|
if Xsqlite3_strglob(tls, __ccgo_ts+13065, z) == 0 {
|
|
sz = _sqlite3Atoi(tls, z+uintptr(3))
|
|
if sz < int32(2) {
|
|
sz = int32(2)
|
|
}
|
|
(*TIndex)(unsafe.Pointer(pIndex)).FszIdxRow = _sqlite3LogEst(tls, libc.Uint64FromInt32(sz))
|
|
} else {
|
|
if Xsqlite3_strglob(tls, __ccgo_ts+13075, z) == 0 {
|
|
libc.SetBitFieldPtr16Uint32(pIndex+56, libc.Uint32FromInt32(1), 6, 0x40)
|
|
}
|
|
}
|
|
}
|
|
for int32(**(**int8)(__ccgo_up(z))) != 0 && int32(**(**int8)(__ccgo_up(z))) != int32(' ') {
|
|
z = z + 1
|
|
}
|
|
for int32(**(**int8)(__ccgo_up(z))) == int32(' ') {
|
|
z = z + 1
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|
|
// 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+27493)
|
|
if pSrc == uintptr(0) {
|
|
return int32(SQLITE_ERROR)
|
|
}
|
|
pInfo = Xsqlite3_malloc64(tls, uint64(uint32(76)+(*TRtreeMatchArg)(unsafe.Pointer(pSrc)).FiSize))
|
|
if !(pInfo != 0) {
|
|
return int32(SQLITE_NOMEM)
|
|
}
|
|
libc.Xmemset(tls, pInfo, 0, uint32(76))
|
|
pBlob = pInfo + 1*76
|
|
libc.Xmemcpy(tls, pBlob, pSrc, (*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 + 28
|
|
(*Tsqlite3_rtree_query_info)(unsafe.Pointer(pInfo)).FapSqlParam = (*TRtreeMatchArg)(unsafe.Pointer(pBlob)).FapSqlParam
|
|
if (*TRtreeMatchArg)(unsafe.Pointer(pBlob)).Fcb.FxGeom != 0 {
|
|
*(*uintptr)(unsafe.Pointer(&(*TRtreeConstraint)(unsafe.Pointer(pCons)).Fu)) = (*TRtreeMatchArg)(unsafe.Pointer(pBlob)).Fcb.FxGeom
|
|
} else {
|
|
(*TRtreeConstraint)(unsafe.Pointer(pCons)).Fop = int32(RTREE_QUERY)
|
|
*(*uintptr)(unsafe.Pointer(&(*TRtreeConstraint)(unsafe.Pointer(pCons)).Fu)) = (*TRtreeMatchArg)(unsafe.Pointer(pBlob)).Fcb.FxQueryFunc
|
|
}
|
|
(*TRtreeConstraint)(unsafe.Pointer(pCons)).FpInfo = pInfo
|
|
return SQLITE_OK
|
|
}
|
|
|
|
// C documentation
|
|
//
|
|
// /*
|
|
// ** An SQL user-function registered to do the work of an DETACH statement. The
|
|
// ** three arguments to the function come directly from a detach statement:
|
|
// **
|
|
// ** DETACH DATABASE x
|
|
// **
|
|
// ** SELECT sqlite_detach(x)
|
|
// */
|
|
func _detachFunc(tls *libc.TLS, context uintptr, NotUsed int32, argv uintptr) {
|
|
bp := tls.Alloc(144)
|
|
defer tls.Free(144)
|
|
var db, pDb, pEntry, pTrig, zName uintptr
|
|
var i int32
|
|
var _ /* zErr at bp+0 */ [128]int8
|
|
_, _, _, _, _, _ = db, i, pDb, pEntry, pTrig, zName
|
|
zName = Xsqlite3_value_text(tls, **(**uintptr)(__ccgo_up(argv)))
|
|
db = Xsqlite3_context_db_handle(tls, context)
|
|
pDb = uintptr(0)
|
|
_ = NotUsed
|
|
if zName == uintptr(0) {
|
|
zName = __ccgo_ts + 1702
|
|
}
|
|
i = 0
|
|
for {
|
|
if !(i < (*Tsqlite3)(unsafe.Pointer(db)).FnDb) {
|
|
break
|
|
}
|
|
pDb = (*Tsqlite3)(unsafe.Pointer(db)).FaDb + uintptr(i)*16
|
|
if (*TDb)(unsafe.Pointer(pDb)).FpBt == uintptr(0) {
|
|
goto _1
|
|
}
|
|
if _sqlite3DbIsNamed(tls, db, i, zName) != 0 {
|
|
break
|
|
}
|
|
goto _1
|
|
_1:
|
|
;
|
|
i = i + 1
|
|
}
|
|
if i >= (*Tsqlite3)(unsafe.Pointer(db)).FnDb {
|
|
Xsqlite3_snprintf(tls, int32(128), bp, __ccgo_ts+13444, libc.VaList(bp+136, zName))
|
|
goto detach_error
|
|
}
|
|
if i < int32(2) {
|
|
Xsqlite3_snprintf(tls, int32(128), bp, __ccgo_ts+13465, libc.VaList(bp+136, zName))
|
|
goto detach_error
|
|
}
|
|
if _sqlite3BtreeTxnState(tls, (*TDb)(unsafe.Pointer(pDb)).FpBt) != SQLITE_TXN_NONE || _sqlite3BtreeIsInBackup(tls, (*TDb)(unsafe.Pointer(pDb)).FpBt) != 0 {
|
|
Xsqlite3_snprintf(tls, int32(128), bp, __ccgo_ts+13491, libc.VaList(bp+136, zName))
|
|
goto detach_error
|
|
}
|
|
/* If any TEMP triggers reference the schema being detached, move those
|
|
** triggers to reference the TEMP schema itself. */
|
|
pEntry = (*THash)(unsafe.Pointer((**(**TDb)(__ccgo_up((*Tsqlite3)(unsafe.Pointer(db)).FaDb + 1*16))).FpSchema + 40)).Ffirst
|
|
for pEntry != 0 {
|
|
pTrig = (*THashElem)(unsafe.Pointer(pEntry)).Fdata
|
|
if (*TTrigger)(unsafe.Pointer(pTrig)).FpTabSchema == (*TDb)(unsafe.Pointer(pDb)).FpSchema {
|
|
(*TTrigger)(unsafe.Pointer(pTrig)).FpTabSchema = (*TTrigger)(unsafe.Pointer(pTrig)).FpSchema
|
|
}
|
|
pEntry = (*THashElem)(unsafe.Pointer(pEntry)).Fnext
|
|
}
|
|
_sqlite3BtreeClose(tls, (*TDb)(unsafe.Pointer(pDb)).FpBt)
|
|
(*TDb)(unsafe.Pointer(pDb)).FpBt = uintptr(0)
|
|
(*TDb)(unsafe.Pointer(pDb)).FpSchema = uintptr(0)
|
|
_sqlite3CollapseDatabaseArray(tls, db)
|
|
return
|
|
goto detach_error
|
|
detach_error:
|
|
;
|
|
Xsqlite3_result_error(tls, context, bp, -int32(1))
|
|
}
|
|
|
|
// C documentation
|
|
//
|
|
// /*
|
|
// ** The input to this routine is an WhereTerm structure with only the
|
|
// ** "pExpr" field filled in. The job of this routine is to analyze the
|
|
// ** subexpression and populate all the other fields of the WhereTerm
|
|
// ** structure.
|
|
// **
|
|
// ** If the expression is of the form "<expr> <op> X" it gets commuted
|
|
// ** to the standard form of "X <op> <expr>".
|
|
// **
|
|
// ** If the expression is of the form "X <op> Y" where both X and Y are
|
|
// ** columns, then the original expression is unchanged and a new virtual
|
|
// ** term of the form "Y <op> X" is added to the WHERE clause and
|
|
// ** analyzed separately. The original term is marked with TERM_COPIED
|
|
// ** and the new term is marked with TERM_DYNAMIC (because it's pExpr
|
|
// ** needs to be freed with the WhereClause) and TERM_VIRTUAL (because it
|
|
// ** is a commuted copy of a prior term.) The original term has nChild=1
|
|
// ** and the copy has idxParent set to the index of the original term.
|
|
// */
|
|
func _exprAnalyze(tls *libc.TLS, pSrc uintptr, pWC uintptr, idxTerm int32) {
|
|
bp := tls.Alloc(32)
|
|
defer tls.Free(32)
|
|
var c, v12 int8
|
|
var db, pC, pDup, pExpr, pLeft, pLeft1, pLeft2, pLeft3, pList, pMaskSet, pNew, pNew1, pNewExpr, pNewExpr1, pNewExpr11, pNewExpr2, pNewExpr21, pNewTerm, pNewTerm1, pParse, pRight, pRight1, pStr2, pTerm, pWInfo, t, zCollSeqName, v1 uintptr
|
|
var eExtraOp, opMask, wtFlags Tu16
|
|
var extraRight, prereqAll, prereqColumn, prereqExpr, prereqLeft, x TBitmask
|
|
var i, i1, i2, i3, idxNew, idxNew1, idxNew11, idxNew2, idxNew21, idxNew3, idxNew4, idxNew5, nLeft, op, res, v2 int32
|
|
var v15 bool
|
|
var _ /* aiCurCol at bp+16 */ [2]int32
|
|
var _ /* eOp2 at bp+12 */ uint8
|
|
var _ /* isComplete at bp+4 */ int32
|
|
var _ /* noCase at bp+8 */ int32
|
|
var _ /* pLeft at bp+28 */ uintptr
|
|
var _ /* pRight at bp+24 */ uintptr
|
|
var _ /* pStr1 at bp+0 */ uintptr
|
|
_, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _ = c, db, eExtraOp, extraRight, i, i1, i2, i3, idxNew, idxNew1, idxNew11, idxNew2, idxNew21, idxNew3, idxNew4, idxNew5, nLeft, op, opMask, pC, pDup, pExpr, pLeft, pLeft1, pLeft2, pLeft3, pList, pMaskSet, pNew, pNew1, pNewExpr, pNewExpr1, pNewExpr11, pNewExpr2, pNewExpr21, pNewTerm, pNewTerm1, pParse, pRight, pRight1, pStr2, pTerm, pWInfo, prereqAll, prereqColumn, prereqExpr, prereqLeft, res, t, wtFlags, x, zCollSeqName, v1, v12, v15, v2
|
|
pWInfo = (*TWhereClause)(unsafe.Pointer(pWC)).FpWInfo /* Prerequisites of pExpr */
|
|
extraRight = uint64(0) /* Extra dependencies on LEFT JOIN */
|
|
**(**uintptr)(__ccgo_up(bp)) = uintptr(0) /* RHS of LIKE/GLOB operator */
|
|
**(**int32)(__ccgo_up(bp + 4)) = 0 /* RHS of LIKE/GLOB ends with wildcard */
|
|
**(**int32)(__ccgo_up(bp + 8)) = 0 /* Top-level operator. pExpr->op */
|
|
pParse = (*TWhereInfo)(unsafe.Pointer(pWInfo)).FpParse /* Parsing context */
|
|
db = (*TParse)(unsafe.Pointer(pParse)).Fdb /* Database connection */
|
|
**(**uint8)(__ccgo_up(bp + 12)) = uint8(0) /* Number of elements on left side vector */
|
|
if (*Tsqlite3)(unsafe.Pointer(db)).FmallocFailed != 0 {
|
|
return
|
|
}
|
|
pTerm = (*TWhereClause)(unsafe.Pointer(pWC)).Fa + uintptr(idxTerm)*48
|
|
pMaskSet = pWInfo + 488
|
|
pExpr = (*TWhereTerm)(unsafe.Pointer(pTerm)).FpExpr
|
|
/* Because malloc() has not failed */
|
|
(*TWhereMaskSet)(unsafe.Pointer(pMaskSet)).FbVarSelect = 0
|
|
prereqLeft = _sqlite3WhereExprUsage(tls, pMaskSet, (*TExpr)(unsafe.Pointer(pExpr)).FpLeft)
|
|
op = libc.Int32FromUint8((*TExpr)(unsafe.Pointer(pExpr)).Fop)
|
|
if op == int32(TK_IN) {
|
|
if _sqlite3ExprCheckIN(tls, pParse, pExpr) != 0 {
|
|
return
|
|
}
|
|
if (*TExpr)(unsafe.Pointer(pExpr)).Fflags&uint32(EP_xIsSelect) != uint32(0) {
|
|
(*TWhereTerm)(unsafe.Pointer(pTerm)).FprereqRight = _exprSelectUsage(tls, pMaskSet, *(*uintptr)(unsafe.Pointer(pExpr + 20)))
|
|
} else {
|
|
(*TWhereTerm)(unsafe.Pointer(pTerm)).FprereqRight = _sqlite3WhereExprListUsage(tls, pMaskSet, *(*uintptr)(unsafe.Pointer(pExpr + 20)))
|
|
}
|
|
prereqAll = prereqLeft | (*TWhereTerm)(unsafe.Pointer(pTerm)).FprereqRight
|
|
} else {
|
|
(*TWhereTerm)(unsafe.Pointer(pTerm)).FprereqRight = _sqlite3WhereExprUsage(tls, pMaskSet, (*TExpr)(unsafe.Pointer(pExpr)).FpRight)
|
|
if (*TExpr)(unsafe.Pointer(pExpr)).FpLeft == uintptr(0) || (*TExpr)(unsafe.Pointer(pExpr)).Fflags&libc.Uint32FromInt32(libc.Int32FromInt32(EP_xIsSelect)|libc.Int32FromInt32(EP_IfNullRow)) != uint32(0) || *(*uintptr)(unsafe.Pointer(pExpr + 20)) != uintptr(0) {
|
|
prereqAll = _sqlite3WhereExprUsageNN(tls, pMaskSet, pExpr)
|
|
} else {
|
|
prereqAll = prereqLeft | (*TWhereTerm)(unsafe.Pointer(pTerm)).FprereqRight
|
|
}
|
|
}
|
|
if (*TWhereMaskSet)(unsafe.Pointer(pMaskSet)).FbVarSelect != 0 {
|
|
v1 = pTerm + 10
|
|
*(*Tu16)(unsafe.Pointer(v1)) = Tu16(int32(*(*Tu16)(unsafe.Pointer(v1))) | libc.Int32FromInt32(TERM_VARSELECT))
|
|
}
|
|
if (*TExpr)(unsafe.Pointer(pExpr)).Fflags&libc.Uint32FromInt32(libc.Int32FromInt32(EP_OuterON)|libc.Int32FromInt32(EP_InnerON)) != uint32(0) {
|
|
x = _sqlite3WhereGetMask(tls, pMaskSet, *(*int32)(unsafe.Pointer(pExpr + 36)))
|
|
if (*TExpr)(unsafe.Pointer(pExpr)).Fflags&libc.Uint32FromInt32(libc.Int32FromInt32(EP_OuterON)) != uint32(0) {
|
|
prereqAll = prereqAll | x
|
|
extraRight = x - uint64(1) /* ON clause terms may not be used with an index
|
|
** on left table of a LEFT JOIN. Ticket #3015 */
|
|
} else {
|
|
if prereqAll>>libc.Int32FromInt32(1) >= x {
|
|
**(**Tu32)(__ccgo_up(pExpr + 4)) &= ^libc.Uint32FromInt32(libc.Int32FromInt32(EP_InnerON))
|
|
}
|
|
}
|
|
}
|
|
(*TWhereTerm)(unsafe.Pointer(pTerm)).FprereqAll = prereqAll
|
|
(*TWhereTerm)(unsafe.Pointer(pTerm)).FleftCursor = -int32(1)
|
|
(*TWhereTerm)(unsafe.Pointer(pTerm)).FiParent = -int32(1)
|
|
(*TWhereTerm)(unsafe.Pointer(pTerm)).FeOperator = uint16(0)
|
|
if _allowedOp(tls, op) != 0 {
|
|
pLeft = _sqlite3ExprSkipCollate(tls, (*TExpr)(unsafe.Pointer(pExpr)).FpLeft)
|
|
pRight = _sqlite3ExprSkipCollate(tls, (*TExpr)(unsafe.Pointer(pExpr)).FpRight)
|
|
if (*TWhereTerm)(unsafe.Pointer(pTerm)).FprereqRight&prereqLeft == uint64(0) {
|
|
v2 = int32(WO_ALL)
|
|
} else {
|
|
v2 = int32(WO_EQUIV)
|
|
}
|
|
opMask = libc.Uint16FromInt32(v2)
|
|
if (*(*struct {
|
|
FleftColumn int32
|
|
FiField int32
|
|
})(unsafe.Pointer(pTerm + 24))).FiField > 0 {
|
|
pLeft = (*(*TExprList_item)(unsafe.Pointer(*(*uintptr)(unsafe.Pointer(pLeft + 20)) + 8 + uintptr((*(*struct {
|
|
FleftColumn int32
|
|
FiField int32
|
|
})(unsafe.Pointer(pTerm + 24))).FiField-int32(1))*20))).FpExpr
|
|
}
|
|
if _exprMightBeIndexed(tls, pSrc, bp+16, pLeft, op) != 0 {
|
|
(*TWhereTerm)(unsafe.Pointer(pTerm)).FleftCursor = (**(**[2]int32)(__ccgo_up(bp + 16)))[0]
|
|
(*(*struct {
|
|
FleftColumn int32
|
|
FiField int32
|
|
})(unsafe.Pointer(pTerm + 24))).FleftColumn = (**(**[2]int32)(__ccgo_up(bp + 16)))[int32(1)]
|
|
(*TWhereTerm)(unsafe.Pointer(pTerm)).FeOperator = libc.Uint16FromInt32(libc.Int32FromUint16(_operatorMask(tls, op)) & libc.Int32FromUint16(opMask))
|
|
}
|
|
if op == int32(TK_IS) {
|
|
v1 = pTerm + 10
|
|
*(*Tu16)(unsafe.Pointer(v1)) = Tu16(int32(*(*Tu16)(unsafe.Pointer(v1))) | libc.Int32FromInt32(TERM_IS))
|
|
}
|
|
if pRight != 0 && _exprMightBeIndexed(tls, pSrc, bp+16, pRight, op) != 0 && !((*TExpr)(unsafe.Pointer(pRight)).Fflags&libc.Uint32FromInt32(libc.Int32FromInt32(EP_FixedCol)) != libc.Uint32FromInt32(0)) {
|
|
eExtraOp = uint16(0) /* Extra bits for pNew->eOperator */
|
|
if (*TWhereTerm)(unsafe.Pointer(pTerm)).FleftCursor >= 0 {
|
|
pDup = _sqlite3ExprDup(tls, db, pExpr, 0)
|
|
if (*Tsqlite3)(unsafe.Pointer(db)).FmallocFailed != 0 {
|
|
_sqlite3ExprDelete(tls, db, pDup)
|
|
return
|
|
}
|
|
idxNew = _whereClauseInsert(tls, pWC, pDup, libc.Uint16FromInt32(libc.Int32FromInt32(TERM_VIRTUAL)|libc.Int32FromInt32(TERM_DYNAMIC)))
|
|
if idxNew == 0 {
|
|
return
|
|
}
|
|
pNew = (*TWhereClause)(unsafe.Pointer(pWC)).Fa + uintptr(idxNew)*48
|
|
_markTermAsChild(tls, pWC, idxNew, idxTerm)
|
|
if op == int32(TK_IS) {
|
|
v1 = pNew + 10
|
|
*(*Tu16)(unsafe.Pointer(v1)) = Tu16(int32(*(*Tu16)(unsafe.Pointer(v1))) | libc.Int32FromInt32(TERM_IS))
|
|
}
|
|
pTerm = (*TWhereClause)(unsafe.Pointer(pWC)).Fa + uintptr(idxTerm)*48
|
|
v1 = pTerm + 10
|
|
*(*Tu16)(unsafe.Pointer(v1)) = Tu16(int32(*(*Tu16)(unsafe.Pointer(v1))) | libc.Int32FromInt32(TERM_COPIED))
|
|
if _termIsEquivalence(tls, pParse, pDup, (*TWhereInfo)(unsafe.Pointer(pWInfo)).FpTabList) != 0 {
|
|
v1 = pTerm + 12
|
|
*(*Tu16)(unsafe.Pointer(v1)) = Tu16(int32(*(*Tu16)(unsafe.Pointer(v1))) | libc.Int32FromInt32(WO_EQUIV))
|
|
eExtraOp = uint16(WO_EQUIV)
|
|
}
|
|
} else {
|
|
pDup = pExpr
|
|
pNew = pTerm
|
|
}
|
|
v1 = pNew + 10
|
|
*(*Tu16)(unsafe.Pointer(v1)) = Tu16(int32(*(*Tu16)(unsafe.Pointer(v1))) | libc.Int32FromUint16(_exprCommute(tls, pParse, pDup)))
|
|
(*TWhereTerm)(unsafe.Pointer(pNew)).FleftCursor = (**(**[2]int32)(__ccgo_up(bp + 16)))[0]
|
|
(*(*struct {
|
|
FleftColumn int32
|
|
FiField int32
|
|
})(unsafe.Pointer(pNew + 24))).FleftColumn = (**(**[2]int32)(__ccgo_up(bp + 16)))[int32(1)]
|
|
(*TWhereTerm)(unsafe.Pointer(pNew)).FprereqRight = prereqLeft | extraRight
|
|
(*TWhereTerm)(unsafe.Pointer(pNew)).FprereqAll = prereqAll
|
|
(*TWhereTerm)(unsafe.Pointer(pNew)).FeOperator = libc.Uint16FromInt32((libc.Int32FromUint16(_operatorMask(tls, libc.Int32FromUint8((*TExpr)(unsafe.Pointer(pDup)).Fop))) + libc.Int32FromUint16(eExtraOp)) & libc.Int32FromUint16(opMask))
|
|
} else {
|
|
if op == int32(TK_ISNULL) && !((*TExpr)(unsafe.Pointer(pExpr)).Fflags&libc.Uint32FromInt32(libc.Int32FromInt32(EP_OuterON)) != libc.Uint32FromInt32(0)) && 0 == _sqlite3ExprCanBeNull(tls, pLeft) {
|
|
(*TExpr)(unsafe.Pointer(pExpr)).Fop = uint8(TK_TRUEFALSE) /* See tag-20230504-1 */
|
|
*(*uintptr)(unsafe.Pointer(pExpr + 8)) = __ccgo_ts + 8185
|
|
**(**Tu32)(__ccgo_up(pExpr + 4)) |= libc.Uint32FromInt32(libc.Int32FromInt32(EP_IsFalse))
|
|
(*TWhereTerm)(unsafe.Pointer(pTerm)).FprereqAll = uint64(0)
|
|
(*TWhereTerm)(unsafe.Pointer(pTerm)).FeOperator = uint16(0)
|
|
}
|
|
}
|
|
} else {
|
|
if libc.Int32FromUint8((*TExpr)(unsafe.Pointer(pExpr)).Fop) == int32(TK_BETWEEN) && libc.Int32FromUint8((*TWhereClause)(unsafe.Pointer(pWC)).Fop) == int32(TK_AND) {
|
|
pList = *(*uintptr)(unsafe.Pointer(pExpr + 20))
|
|
i = 0
|
|
for {
|
|
if !(i < int32(2)) {
|
|
break
|
|
}
|
|
pNewExpr = _sqlite3PExpr(tls, pParse, libc.Int32FromUint8(_ops[i]), _sqlite3ExprDup(tls, db, (*TExpr)(unsafe.Pointer(pExpr)).FpLeft, 0), _sqlite3ExprDup(tls, db, (*(*TExprList_item)(unsafe.Pointer(pList + 8 + uintptr(i)*20))).FpExpr, 0))
|
|
_transferJoinMarkings(tls, pNewExpr, pExpr)
|
|
idxNew1 = _whereClauseInsert(tls, pWC, pNewExpr, libc.Uint16FromInt32(libc.Int32FromInt32(TERM_VIRTUAL)|libc.Int32FromInt32(TERM_DYNAMIC)))
|
|
_exprAnalyze(tls, pSrc, pWC, idxNew1)
|
|
pTerm = (*TWhereClause)(unsafe.Pointer(pWC)).Fa + uintptr(idxTerm)*48
|
|
_markTermAsChild(tls, pWC, idxNew1, idxTerm)
|
|
goto _8
|
|
_8:
|
|
;
|
|
i = i + 1
|
|
}
|
|
} else {
|
|
if libc.Int32FromUint8((*TExpr)(unsafe.Pointer(pExpr)).Fop) == int32(TK_OR) && !((*TExpr)(unsafe.Pointer(pExpr)).Fflags&libc.Uint32FromInt32(libc.Int32FromInt32(EP_Collate)) != libc.Uint32FromInt32(0)) {
|
|
_exprAnalyzeOrTerm(tls, pSrc, pWC, idxTerm)
|
|
pTerm = (*TWhereClause)(unsafe.Pointer(pWC)).Fa + uintptr(idxTerm)*48
|
|
} else {
|
|
if libc.Int32FromUint8((*TExpr)(unsafe.Pointer(pExpr)).Fop) == int32(TK_NOTNULL) {
|
|
if libc.Int32FromUint8((*TExpr)(unsafe.Pointer((*TExpr)(unsafe.Pointer(pExpr)).FpLeft)).Fop) == int32(TK_COLUMN) && int32((*TExpr)(unsafe.Pointer((*TExpr)(unsafe.Pointer(pExpr)).FpLeft)).FiColumn) >= 0 && !((*TExpr)(unsafe.Pointer(pExpr)).Fflags&libc.Uint32FromInt32(libc.Int32FromInt32(EP_OuterON)) != libc.Uint32FromInt32(0)) {
|
|
pLeft1 = (*TExpr)(unsafe.Pointer(pExpr)).FpLeft
|
|
pNewExpr1 = _sqlite3PExpr(tls, pParse, int32(TK_GT), _sqlite3ExprDup(tls, db, pLeft1, 0), _sqlite3ExprAlloc(tls, db, int32(TK_NULL), uintptr(0), 0))
|
|
idxNew2 = _whereClauseInsert(tls, pWC, pNewExpr1, libc.Uint16FromInt32(libc.Int32FromInt32(TERM_VIRTUAL)|libc.Int32FromInt32(TERM_DYNAMIC)|libc.Int32FromInt32(TERM_VNULL)))
|
|
if idxNew2 != 0 {
|
|
pNewTerm = (*TWhereClause)(unsafe.Pointer(pWC)).Fa + uintptr(idxNew2)*48
|
|
(*TWhereTerm)(unsafe.Pointer(pNewTerm)).FprereqRight = uint64(0)
|
|
(*TWhereTerm)(unsafe.Pointer(pNewTerm)).FleftCursor = (*TExpr)(unsafe.Pointer(pLeft1)).FiTable
|
|
(*(*struct {
|
|
FleftColumn int32
|
|
FiField int32
|
|
})(unsafe.Pointer(pNewTerm + 24))).FleftColumn = int32((*TExpr)(unsafe.Pointer(pLeft1)).FiColumn)
|
|
(*TWhereTerm)(unsafe.Pointer(pNewTerm)).FeOperator = libc.Uint16FromInt32(libc.Int32FromInt32(WO_EQ) << (libc.Int32FromInt32(TK_GT) - libc.Int32FromInt32(TK_EQ)))
|
|
_markTermAsChild(tls, pWC, idxNew2, idxTerm)
|
|
pTerm = (*TWhereClause)(unsafe.Pointer(pWC)).Fa + uintptr(idxTerm)*48
|
|
v1 = pTerm + 10
|
|
*(*Tu16)(unsafe.Pointer(v1)) = Tu16(int32(*(*Tu16)(unsafe.Pointer(v1))) | libc.Int32FromInt32(TERM_COPIED))
|
|
(*TWhereTerm)(unsafe.Pointer(pNewTerm)).FprereqAll = (*TWhereTerm)(unsafe.Pointer(pTerm)).FprereqAll
|
|
}
|
|
}
|
|
} else {
|
|
if libc.Int32FromUint8((*TExpr)(unsafe.Pointer(pExpr)).Fop) == int32(TK_FUNCTION) && libc.Int32FromUint8((*TWhereClause)(unsafe.Pointer(pWC)).Fop) == int32(TK_AND) && _isLikeOrGlob(tls, pParse, pExpr, bp, bp+4, bp+8) != 0 { /* Name of collating sequence */
|
|
wtFlags = libc.Uint16FromInt32(libc.Int32FromInt32(TERM_LIKEOPT) | libc.Int32FromInt32(TERM_VIRTUAL) | libc.Int32FromInt32(TERM_DYNAMIC))
|
|
pLeft2 = (*(*TExprList_item)(unsafe.Pointer(*(*uintptr)(unsafe.Pointer(pExpr + 20)) + 8 + 1*20))).FpExpr
|
|
pStr2 = _sqlite3ExprDup(tls, db, **(**uintptr)(__ccgo_up(bp)), 0)
|
|
/* Convert the lower bound to upper-case and the upper bound to
|
|
** lower-case (upper-case is less than lower-case in ASCII) so that
|
|
** the range constraints also work for BLOBs
|
|
*/
|
|
if **(**int32)(__ccgo_up(bp + 8)) != 0 && !((*Tsqlite3)(unsafe.Pointer((*TParse)(unsafe.Pointer(pParse)).Fdb)).FmallocFailed != 0) {
|
|
v1 = pTerm + 10
|
|
*(*Tu16)(unsafe.Pointer(v1)) = Tu16(int32(*(*Tu16)(unsafe.Pointer(v1))) | libc.Int32FromInt32(TERM_LIKE))
|
|
i1 = 0
|
|
for {
|
|
v12 = **(**int8)(__ccgo_up(*(*uintptr)(unsafe.Pointer(**(**uintptr)(__ccgo_up(bp)) + 8)) + uintptr(i1)))
|
|
c = v12
|
|
if !(int32(v12) != 0) {
|
|
break
|
|
}
|
|
**(**int8)(__ccgo_up(*(*uintptr)(unsafe.Pointer(**(**uintptr)(__ccgo_up(bp)) + 8)) + uintptr(i1))) = int8(int32(c) & ^(libc.Int32FromUint8(_sqlite3CtypeMap[libc.Uint8FromInt8(c)]) & libc.Int32FromInt32(0x20)))
|
|
**(**int8)(__ccgo_up(*(*uintptr)(unsafe.Pointer(pStr2 + 8)) + uintptr(i1))) = libc.Int8FromUint8(_sqlite3UpperToLower[libc.Uint8FromInt8(c)])
|
|
goto _11
|
|
_11:
|
|
;
|
|
i1 = i1 + 1
|
|
}
|
|
}
|
|
if !((*Tsqlite3)(unsafe.Pointer(db)).FmallocFailed != 0) { /* Last character before the first wildcard */
|
|
pC = *(*uintptr)(unsafe.Pointer(pStr2 + 8)) + uintptr(_sqlite3Strlen30(tls, *(*uintptr)(unsafe.Pointer(pStr2 + 8)))-int32(1))
|
|
if **(**int32)(__ccgo_up(bp + 8)) != 0 {
|
|
/* The point is to increment the last character before the first
|
|
** wildcard. But if we increment '@', that will push it into the
|
|
** alphabetic range where case conversions will mess up the
|
|
** inequality. To avoid this, make sure to also run the full
|
|
** LIKE on all candidate expressions by clearing the isComplete flag
|
|
*/
|
|
if libc.Int32FromUint8(**(**Tu8)(__ccgo_up(pC))) == libc.Int32FromUint8('A')-libc.Int32FromInt32(1) {
|
|
**(**int32)(__ccgo_up(bp + 4)) = 0
|
|
}
|
|
**(**Tu8)(__ccgo_up(pC)) = _sqlite3UpperToLower[**(**Tu8)(__ccgo_up(pC))]
|
|
}
|
|
/* Increment the value of the last utf8 character in the prefix. */
|
|
for libc.Int32FromUint8(**(**Tu8)(__ccgo_up(pC))) == int32(0xBF) && pC > *(*uintptr)(unsafe.Pointer(pStr2 + 8)) {
|
|
**(**Tu8)(__ccgo_up(pC)) = uint8(0x80)
|
|
pC = pC - 1
|
|
}
|
|
/* isLikeOrGlob() guarantees this */
|
|
**(**Tu8)(__ccgo_up(pC)) = **(**Tu8)(__ccgo_up(pC)) + 1
|
|
}
|
|
if **(**int32)(__ccgo_up(bp + 8)) != 0 {
|
|
v1 = __ccgo_ts + 23943
|
|
} else {
|
|
v1 = uintptr(unsafe.Pointer(&_sqlite3StrBINARY))
|
|
}
|
|
zCollSeqName = v1
|
|
pNewExpr11 = _sqlite3ExprDup(tls, db, pLeft2, 0)
|
|
pNewExpr11 = _sqlite3PExpr(tls, pParse, int32(TK_GE), _sqlite3ExprAddCollateString(tls, pParse, pNewExpr11, zCollSeqName), **(**uintptr)(__ccgo_up(bp)))
|
|
_transferJoinMarkings(tls, pNewExpr11, pExpr)
|
|
idxNew11 = _whereClauseInsert(tls, pWC, pNewExpr11, wtFlags)
|
|
pNewExpr21 = _sqlite3ExprDup(tls, db, pLeft2, 0)
|
|
pNewExpr21 = _sqlite3PExpr(tls, pParse, int32(TK_LT), _sqlite3ExprAddCollateString(tls, pParse, pNewExpr21, zCollSeqName), pStr2)
|
|
_transferJoinMarkings(tls, pNewExpr21, pExpr)
|
|
idxNew21 = _whereClauseInsert(tls, pWC, pNewExpr21, wtFlags)
|
|
_exprAnalyze(tls, pSrc, pWC, idxNew11)
|
|
_exprAnalyze(tls, pSrc, pWC, idxNew21)
|
|
pTerm = (*TWhereClause)(unsafe.Pointer(pWC)).Fa + uintptr(idxTerm)*48
|
|
if **(**int32)(__ccgo_up(bp + 4)) != 0 {
|
|
_markTermAsChild(tls, pWC, idxNew11, idxTerm)
|
|
_markTermAsChild(tls, pWC, idxNew21, idxTerm)
|
|
}
|
|
}
|
|
}
|
|
}
|
|
}
|
|
}
|
|
/* If there is a vector == or IS term - e.g. "(a, b) == (?, ?)" - create
|
|
** new terms for each component comparison - "a = ?" and "b = ?". The
|
|
** new terms completely replace the original vector comparison, which is
|
|
** no longer used.
|
|
**
|
|
** This is only required if at least one side of the comparison operation
|
|
** is not a sub-select.
|
|
**
|
|
** tag-20220128a
|
|
*/
|
|
if v15 = libc.Int32FromUint8((*TExpr)(unsafe.Pointer(pExpr)).Fop) == int32(TK_EQ) || libc.Int32FromUint8((*TExpr)(unsafe.Pointer(pExpr)).Fop) == int32(TK_IS); v15 {
|
|
v2 = _sqlite3ExprVectorSize(tls, (*TExpr)(unsafe.Pointer(pExpr)).FpLeft)
|
|
nLeft = v2
|
|
}
|
|
if v15 && v2 > int32(1) && _sqlite3ExprVectorSize(tls, (*TExpr)(unsafe.Pointer(pExpr)).FpRight) == nLeft && ((*TExpr)(unsafe.Pointer((*TExpr)(unsafe.Pointer(pExpr)).FpLeft)).Fflags&uint32(EP_xIsSelect) == uint32(0) || (*TExpr)(unsafe.Pointer((*TExpr)(unsafe.Pointer(pExpr)).FpRight)).Fflags&uint32(EP_xIsSelect) == uint32(0)) && libc.Int32FromUint8((*TWhereClause)(unsafe.Pointer(pWC)).Fop) == int32(TK_AND) {
|
|
i2 = 0
|
|
for {
|
|
if !(i2 < nLeft) {
|
|
break
|
|
}
|
|
pLeft3 = _sqlite3ExprForVectorField(tls, pParse, (*TExpr)(unsafe.Pointer(pExpr)).FpLeft, i2, nLeft)
|
|
pRight1 = _sqlite3ExprForVectorField(tls, pParse, (*TExpr)(unsafe.Pointer(pExpr)).FpRight, i2, nLeft)
|
|
pNew1 = _sqlite3PExpr(tls, pParse, libc.Int32FromUint8((*TExpr)(unsafe.Pointer(pExpr)).Fop), pLeft3, pRight1)
|
|
_transferJoinMarkings(tls, pNew1, pExpr)
|
|
idxNew3 = _whereClauseInsert(tls, pWC, pNew1, libc.Uint16FromInt32(libc.Int32FromInt32(TERM_DYNAMIC)|libc.Int32FromInt32(TERM_SLICE)))
|
|
_exprAnalyze(tls, pSrc, pWC, idxNew3)
|
|
goto _16
|
|
_16:
|
|
;
|
|
i2 = i2 + 1
|
|
}
|
|
pTerm = (*TWhereClause)(unsafe.Pointer(pWC)).Fa + uintptr(idxTerm)*48
|
|
v1 = pTerm + 10
|
|
*(*Tu16)(unsafe.Pointer(v1)) = Tu16(int32(*(*Tu16)(unsafe.Pointer(v1))) | (libc.Int32FromInt32(TERM_CODED) | libc.Int32FromInt32(TERM_VIRTUAL))) /* Disable the original */
|
|
(*TWhereTerm)(unsafe.Pointer(pTerm)).FeOperator = uint16(WO_ROWVAL)
|
|
} else {
|
|
if libc.Int32FromUint8((*TExpr)(unsafe.Pointer(pExpr)).Fop) == int32(TK_IN) && (*(*struct {
|
|
FleftColumn int32
|
|
FiField int32
|
|
})(unsafe.Pointer(pTerm + 24))).FiField == 0 && libc.Int32FromUint8((*TExpr)(unsafe.Pointer((*TExpr)(unsafe.Pointer(pExpr)).FpLeft)).Fop) == int32(TK_VECTOR) && (*TExpr)(unsafe.Pointer(pExpr)).Fflags&uint32(EP_xIsSelect) != uint32(0) && ((*TSelect)(unsafe.Pointer(*(*uintptr)(unsafe.Pointer(pExpr + 20)))).FpPrior == uintptr(0) || (*TSelect)(unsafe.Pointer(*(*uintptr)(unsafe.Pointer(pExpr + 20)))).FselFlags&uint32(SF_Values) != 0) && (*TSelect)(unsafe.Pointer(*(*uintptr)(unsafe.Pointer(pExpr + 20)))).FpWin == uintptr(0) && libc.Int32FromUint8((*TWhereClause)(unsafe.Pointer(pWC)).Fop) == int32(TK_AND) && int64((*TExprList)(unsafe.Pointer((*TSelect)(unsafe.Pointer(*(*uintptr)(unsafe.Pointer(pExpr + 20)))).FpEList)).FnExpr) <= libc.Int64FromInt32(1)<<(libc.Uint32FromInt64(1)*libc.Uint32FromInt32(8))-libc.Int64FromInt32(1) {
|
|
i3 = 0
|
|
for {
|
|
if !(i3 < _sqlite3ExprVectorSize(tls, (*TExpr)(unsafe.Pointer(pExpr)).FpLeft)) {
|
|
break
|
|
}
|
|
idxNew4 = _whereClauseInsert(tls, pWC, pExpr, libc.Uint16FromInt32(libc.Int32FromInt32(TERM_VIRTUAL)|libc.Int32FromInt32(TERM_SLICE)))
|
|
*(*int32)(unsafe.Pointer((*TWhereClause)(unsafe.Pointer(pWC)).Fa + uintptr(idxNew4)*48 + 24 + 4)) = i3 + int32(1)
|
|
_exprAnalyze(tls, pSrc, pWC, idxNew4)
|
|
_markTermAsChild(tls, pWC, idxNew4, idxTerm)
|
|
goto _18
|
|
_18:
|
|
;
|
|
i3 = i3 + 1
|
|
}
|
|
} else {
|
|
if libc.Int32FromUint8((*TWhereClause)(unsafe.Pointer(pWC)).Fop) == int32(TK_AND) {
|
|
**(**uintptr)(__ccgo_up(bp + 24)) = uintptr(0)
|
|
**(**uintptr)(__ccgo_up(bp + 28)) = uintptr(0)
|
|
res = _isAuxiliaryVtabOperator(tls, db, pExpr, bp+12, bp+28, bp+24)
|
|
for {
|
|
v2 = res
|
|
res = res - 1
|
|
if !(v2 > 0) {
|
|
break
|
|
}
|
|
prereqExpr = _sqlite3WhereExprUsage(tls, pMaskSet, **(**uintptr)(__ccgo_up(bp + 24)))
|
|
prereqColumn = _sqlite3WhereExprUsage(tls, pMaskSet, **(**uintptr)(__ccgo_up(bp + 28)))
|
|
if prereqExpr&prereqColumn == uint64(0) {
|
|
pNewExpr2 = _sqlite3PExpr(tls, pParse, int32(TK_MATCH), uintptr(0), _sqlite3ExprDup(tls, db, **(**uintptr)(__ccgo_up(bp + 24)), 0))
|
|
if (*TExpr)(unsafe.Pointer(pExpr)).Fflags&libc.Uint32FromInt32(libc.Int32FromInt32(EP_OuterON)) != uint32(0) && pNewExpr2 != 0 {
|
|
**(**Tu32)(__ccgo_up(pNewExpr2 + 4)) |= libc.Uint32FromInt32(libc.Int32FromInt32(EP_OuterON))
|
|
*(*int32)(unsafe.Pointer(pNewExpr2 + 36)) = *(*int32)(unsafe.Pointer(pExpr + 36))
|
|
}
|
|
idxNew5 = _whereClauseInsert(tls, pWC, pNewExpr2, libc.Uint16FromInt32(libc.Int32FromInt32(TERM_VIRTUAL)|libc.Int32FromInt32(TERM_DYNAMIC)))
|
|
pNewTerm1 = (*TWhereClause)(unsafe.Pointer(pWC)).Fa + uintptr(idxNew5)*48
|
|
(*TWhereTerm)(unsafe.Pointer(pNewTerm1)).FprereqRight = prereqExpr | extraRight
|
|
(*TWhereTerm)(unsafe.Pointer(pNewTerm1)).FleftCursor = (*TExpr)(unsafe.Pointer(**(**uintptr)(__ccgo_up(bp + 28)))).FiTable
|
|
(*(*struct {
|
|
FleftColumn int32
|
|
FiField int32
|
|
})(unsafe.Pointer(pNewTerm1 + 24))).FleftColumn = int32((*TExpr)(unsafe.Pointer(**(**uintptr)(__ccgo_up(bp + 28)))).FiColumn)
|
|
(*TWhereTerm)(unsafe.Pointer(pNewTerm1)).FeOperator = uint16(WO_AUX)
|
|
(*TWhereTerm)(unsafe.Pointer(pNewTerm1)).FeMatchOp = **(**uint8)(__ccgo_up(bp + 12))
|
|
_markTermAsChild(tls, pWC, idxNew5, idxTerm)
|
|
pTerm = (*TWhereClause)(unsafe.Pointer(pWC)).Fa + uintptr(idxTerm)*48
|
|
v1 = pTerm + 10
|
|
*(*Tu16)(unsafe.Pointer(v1)) = Tu16(int32(*(*Tu16)(unsafe.Pointer(v1))) | libc.Int32FromInt32(TERM_COPIED))
|
|
(*TWhereTerm)(unsafe.Pointer(pNewTerm1)).FprereqAll = (*TWhereTerm)(unsafe.Pointer(pTerm)).FprereqAll
|
|
}
|
|
t = **(**uintptr)(__ccgo_up(bp + 28))
|
|
**(**uintptr)(__ccgo_up(bp + 28)) = **(**uintptr)(__ccgo_up(bp + 24))
|
|
**(**uintptr)(__ccgo_up(bp + 24)) = t
|
|
}
|
|
}
|
|
}
|
|
}
|
|
/* Prevent ON clause terms of a LEFT JOIN from being used to drive
|
|
** an index for tables to the left of the join.
|
|
*/
|
|
pTerm = (*TWhereClause)(unsafe.Pointer(pWC)).Fa + uintptr(idxTerm)*48
|
|
**(**TBitmask)(__ccgo_up(pTerm + 32)) |= extraRight
|
|
}
|
|
|
|
// C documentation
|
|
//
|
|
// /*
|
|
// ** Generate code to implement special SQL functions that are implemented
|
|
// ** in-line rather than by using the usual callbacks.
|
|
// */
|
|
func _exprCodeInlineFunction(tls *libc.TLS, pParse uintptr, pFarg uintptr, iFuncId int32, target int32) (r int32) {
|
|
bp := tls.Alloc(64)
|
|
defer tls.Free(64)
|
|
var aff int8
|
|
var azAff [6]uintptr
|
|
var endCoalesce, i, nFarg int32
|
|
var pA1, pArg, v, v2 uintptr
|
|
var _ /* caseExpr at bp+0 */ TExpr
|
|
_, _, _, _, _, _, _, _, _ = aff, azAff, endCoalesce, i, nFarg, pA1, pArg, v, v2
|
|
v = (*TParse)(unsafe.Pointer(pParse)).FpVdbe
|
|
nFarg = (*TExprList)(unsafe.Pointer(pFarg)).FnExpr
|
|
/* All in-line functions have at least one argument */
|
|
switch iFuncId {
|
|
case INLINEFUNC_coalesce:
|
|
/* Attempt a direct implementation of the built-in COALESCE() and
|
|
** IFNULL() functions. This avoids unnecessary evaluation of
|
|
** arguments past the first non-NULL argument.
|
|
*/
|
|
endCoalesce = _sqlite3VdbeMakeLabel(tls, pParse)
|
|
_sqlite3ExprCode(tls, pParse, (*(*TExprList_item)(unsafe.Pointer(pFarg + 8))).FpExpr, target)
|
|
i = int32(1)
|
|
for {
|
|
if !(i < nFarg) {
|
|
break
|
|
}
|
|
_sqlite3VdbeAddOp2(tls, v, int32(OP_NotNull), target, endCoalesce)
|
|
_sqlite3ExprCode(tls, pParse, (*(*TExprList_item)(unsafe.Pointer(pFarg + 8 + uintptr(i)*20))).FpExpr, target)
|
|
goto _1
|
|
_1:
|
|
;
|
|
i = i + 1
|
|
}
|
|
_setDoNotMergeFlagOnCopy(tls, v)
|
|
_sqlite3VdbeResolveLabel(tls, v, endCoalesce)
|
|
case int32(INLINEFUNC_iif):
|
|
libc.Xmemset(tls, bp, 0, uint32(52))
|
|
(**(**TExpr)(__ccgo_up(bp))).Fop = uint8(TK_CASE)
|
|
*(*uintptr)(unsafe.Pointer(bp + 20)) = pFarg
|
|
return _sqlite3ExprCodeTarget(tls, pParse, bp, target)
|
|
case int32(INLINEFUNC_sqlite_offset):
|
|
pArg = (*(*TExprList_item)(unsafe.Pointer(pFarg + 8))).FpExpr
|
|
if libc.Int32FromUint8((*TExpr)(unsafe.Pointer(pArg)).Fop) == int32(TK_COLUMN) && (*TExpr)(unsafe.Pointer(pArg)).FiTable >= 0 {
|
|
_sqlite3VdbeAddOp3(tls, v, int32(OP_Offset), (*TExpr)(unsafe.Pointer(pArg)).FiTable, int32((*TExpr)(unsafe.Pointer(pArg)).FiColumn), target)
|
|
} else {
|
|
_sqlite3VdbeAddOp2(tls, v, int32(OP_Null), 0, target)
|
|
}
|
|
default:
|
|
/* The UNLIKELY() function is a no-op. The result is the value
|
|
** of the first argument.
|
|
*/
|
|
target = _sqlite3ExprCodeTarget(tls, pParse, (*(*TExprList_item)(unsafe.Pointer(pFarg + 8))).FpExpr, target)
|
|
break
|
|
/***********************************************************************
|
|
** Test-only SQL functions that are only usable if enabled
|
|
** via SQLITE_TESTCTRL_INTERNAL_FUNCTIONS
|
|
*/
|
|
fallthrough
|
|
case int32(INLINEFUNC_expr_compare):
|
|
/* Compare two expressions using sqlite3ExprCompare() */
|
|
_sqlite3VdbeAddOp2(tls, v, int32(OP_Integer), _sqlite3ExprCompare(tls, uintptr(0), (*(*TExprList_item)(unsafe.Pointer(pFarg + 8))).FpExpr, (*(*TExprList_item)(unsafe.Pointer(pFarg + 8 + 1*20))).FpExpr, -int32(1)), target)
|
|
case int32(INLINEFUNC_expr_implies_expr):
|
|
/* Compare two expressions using sqlite3ExprImpliesExpr() */
|
|
_sqlite3VdbeAddOp2(tls, v, int32(OP_Integer), _sqlite3ExprImpliesExpr(tls, pParse, (*(*TExprList_item)(unsafe.Pointer(pFarg + 8))).FpExpr, (*(*TExprList_item)(unsafe.Pointer(pFarg + 8 + 1*20))).FpExpr, -int32(1)), target)
|
|
case int32(INLINEFUNC_implies_nonnull_row):
|
|
pA1 = (*(*TExprList_item)(unsafe.Pointer(pFarg + 8 + 1*20))).FpExpr
|
|
if libc.Int32FromUint8((*TExpr)(unsafe.Pointer(pA1)).Fop) == int32(TK_COLUMN) {
|
|
_sqlite3VdbeAddOp2(tls, v, int32(OP_Integer), _sqlite3ExprImpliesNonNullRow(tls, (*(*TExprList_item)(unsafe.Pointer(pFarg + 8))).FpExpr, (*TExpr)(unsafe.Pointer(pA1)).FiTable, int32(1)), target)
|
|
} else {
|
|
_sqlite3VdbeAddOp2(tls, v, int32(OP_Null), 0, target)
|
|
}
|
|
case int32(INLINEFUNC_affinity):
|
|
/* The AFFINITY() function evaluates to a string that describes
|
|
** the type affinity of the argument. This is used for testing of
|
|
** the SQLite type logic.
|
|
*/
|
|
azAff = [6]uintptr{
|
|
0: __ccgo_ts + 8484,
|
|
1: __ccgo_ts + 8489,
|
|
2: __ccgo_ts + 8494,
|
|
3: __ccgo_ts + 6494,
|
|
4: __ccgo_ts + 6489,
|
|
5: __ccgo_ts + 8502,
|
|
}
|
|
aff = _sqlite3ExprAffinity(tls, (*(*TExprList_item)(unsafe.Pointer(pFarg + 8))).FpExpr)
|
|
if int32(aff) <= int32(SQLITE_AFF_NONE) {
|
|
v2 = __ccgo_ts + 8510
|
|
} else {
|
|
v2 = azAff[int32(aff)-int32(SQLITE_AFF_BLOB)]
|
|
}
|
|
_sqlite3VdbeLoadString(tls, v, target, v2)
|
|
break
|
|
}
|
|
return target
|
|
}
|
|
|
|
// 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(208)
|
|
defer tls.Free(208)
|
|
var iWrite, nSize Ti64
|
|
var nBlk, nWrite, rc int32
|
|
var _ /* buf at bp+0 */ Tstat
|
|
_, _, _, _, _ = iWrite, nBlk, nSize, nWrite, rc
|
|
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+1702, int32(1))
|
|
if nWrite != int32(1) {
|
|
return libc.Int32FromInt32(SQLITE_IOERR) | libc.Int32FromInt32(3)<<libc.Int32FromInt32(8)
|
|
}
|
|
goto _1
|
|
_1:
|
|
;
|
|
iWrite = iWrite + int64(nBlk)
|
|
}
|
|
}
|
|
}
|
|
if (*TunixFile)(unsafe.Pointer(pFile)).FmmapSizeMax > 0 && nByte > (*TunixFile)(unsafe.Pointer(pFile)).FmmapSize {
|
|
if (*TunixFile)(unsafe.Pointer(pFile)).FszChunk <= 0 {
|
|
if _robust_ftruncate(tls, (*TunixFile)(unsafe.Pointer(pFile)).Fh, nByte) != 0 {
|
|
_storeLastErrno(tls, pFile, **(**int32)(__ccgo_up(libc.X__error(tls))))
|
|
return _unixLogErrorAtLine(tls, libc.Int32FromInt32(SQLITE_IOERR)|libc.Int32FromInt32(6)<<libc.Int32FromInt32(8), __ccgo_ts+3576, (*TunixFile)(unsafe.Pointer(pFile)).FzPath, int32(44297))
|
|
}
|
|
}
|
|
rc = _unixMapfile(tls, pFile, nByte)
|
|
return rc
|
|
}
|
|
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(208)
|
|
defer tls.Free(208)
|
|
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
|
|
//
|
|
// /*
|
|
// ** This function is called by unixOpen() to determine the unix permissions
|
|
// ** to create new files with. If no error occurs, then SQLITE_OK is returned
|
|
// ** and a value suitable for passing as the third argument to open(2) is
|
|
// ** written to *pMode. If an IO error occurs, an SQLite error code is
|
|
// ** returned and the value of *pMode is not modified.
|
|
// **
|
|
// ** In most cases, this routine sets *pMode to 0, which will become
|
|
// ** an indication to robust_open() to create the file using
|
|
// ** SQLITE_DEFAULT_FILE_PERMISSIONS adjusted by the umask.
|
|
// ** But if the file being opened is a WAL or regular journal file, then
|
|
// ** this function queries the file-system for the permissions on the
|
|
// ** corresponding database file and sets *pMode to this value. Whenever
|
|
// ** possible, WAL and journal files are created using the same permissions
|
|
// ** as the associated database file.
|
|
// **
|
|
// ** If the SQLITE_ENABLE_8_3_NAMES option is enabled, then the
|
|
// ** original filename is unavailable. But 8_3_NAMES is only used for
|
|
// ** FAT filesystems and permissions do not matter there, so just use
|
|
// ** the default permissions. In 8_3_NAMES mode, leave *pMode set to zero.
|
|
// */
|
|
func _findCreateFileMode(tls *libc.TLS, zPath uintptr, flags int32, pMode uintptr, pUid uintptr, pGid uintptr) (r int32) {
|
|
bp := tls.Alloc(528)
|
|
defer tls.Free(528)
|
|
var nDb, rc int32
|
|
var z uintptr
|
|
var _ /* zDb at bp+0 */ [513]int8
|
|
_, _, _ = nDb, rc, z
|
|
rc = SQLITE_OK /* Return Code */
|
|
**(**Tmode_t)(__ccgo_up(pMode)) = uint16(0)
|
|
**(**Tuid_t)(__ccgo_up(pUid)) = uint32(0)
|
|
**(**Tgid_t)(__ccgo_up(pGid)) = uint32(0)
|
|
if flags&(libc.Int32FromInt32(SQLITE_OPEN_WAL)|libc.Int32FromInt32(SQLITE_OPEN_MAIN_JOURNAL)) != 0 { /* Number of valid bytes in zDb */
|
|
/* zPath is a path to a WAL or journal file. The following block derives
|
|
** the path to the associated database file from zPath. This block handles
|
|
** the following naming conventions:
|
|
**
|
|
** "<path to db>-journal"
|
|
** "<path to db>-wal"
|
|
** "<path to db>-journalNN"
|
|
** "<path to db>-walNN"
|
|
**
|
|
** where NN is a decimal number. The NN naming schemes are
|
|
** used by the test_multiplex.c module.
|
|
**
|
|
** In normal operation, the journal file name will always contain
|
|
** a '-' character. However in 8+3 filename mode, or if a corrupt
|
|
** rollback journal specifies a super-journal with a goofy name, then
|
|
** the '-' might be missing or the '-' might be the first character in
|
|
** the filename. In that case, just return SQLITE_OK with *pMode==0.
|
|
*/
|
|
nDb = _sqlite3Strlen30(tls, zPath) - int32(1)
|
|
for nDb > 0 && int32(**(**int8)(__ccgo_up(zPath + uintptr(nDb)))) != int32('.') {
|
|
if int32(**(**int8)(__ccgo_up(zPath + uintptr(nDb)))) == int32('-') {
|
|
libc.Xmemcpy(tls, bp, zPath, libc.Uint32FromInt32(nDb))
|
|
(**(**[513]int8)(__ccgo_up(bp)))[nDb] = int8('\000')
|
|
rc = _getFileMode(tls, bp, pMode, pUid, pGid)
|
|
break
|
|
}
|
|
nDb = nDb - 1
|
|
}
|
|
} else {
|
|
if flags&int32(SQLITE_OPEN_DELETEONCLOSE) != 0 {
|
|
**(**Tmode_t)(__ccgo_up(pMode)) = uint16(0600)
|
|
} else {
|
|
if flags&int32(SQLITE_OPEN_URI) != 0 {
|
|
/* If this is a main database file and the file was opened using a URI
|
|
** filename, check for the "modeof" parameter. If present, interpret
|
|
** its value as a filename and try to copy the mode, uid and gid from
|
|
** that file. */
|
|
z = Xsqlite3_uri_parameter(tls, zPath, __ccgo_ts+4060)
|
|
if z != 0 {
|
|
rc = _getFileMode(tls, z, pMode, pUid, pGid)
|
|
}
|
|
}
|
|
}
|
|
}
|
|
return rc
|
|
}
|
|
|
|
// 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(224)
|
|
defer tls.Free(224)
|
|
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__error(tls))))
|
|
return int32(SQLITE_IOERR)
|
|
}
|
|
libc.Xmemset(tls, bp, 0, uint32(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, uint32(16)) != 0 {
|
|
pInode = (*TunixInodeInfo)(unsafe.Pointer(pInode)).FpNext
|
|
}
|
|
if pInode == uintptr(0) {
|
|
pInode = Xsqlite3_malloc64(tls, uint64(52))
|
|
if pInode == uintptr(0) {
|
|
return int32(SQLITE_NOMEM)
|
|
}
|
|
libc.Xmemset(tls, pInode, 0, uint32(52))
|
|
libc.Xmemcpy(tls, pInode, bp, uint32(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 + 116 + 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 += 20
|
|
}
|
|
k = _addAggInfoColumn(tls, (*TParse)(unsafe.Pointer(pParse)).Fdb, pAggInfo)
|
|
if k < 0 {
|
|
/* OOM on resize */
|
|
return
|
|
}
|
|
if k > mxTerm {
|
|
_sqlite3ErrorMsg(tls, pParse, __ccgo_ts+8616, libc.VaList(bp+8, mxTerm))
|
|
k = mxTerm
|
|
}
|
|
pCol = (*TAggInfo)(unsafe.Pointer(pAggInfo)).FaCol + uintptr(k)*20
|
|
(*TAggInfo_col)(unsafe.Pointer(pCol)).FpTab = (*TExpr)(unsafe.Pointer(pExpr)).Fy.FpTab
|
|
(*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 += 20
|
|
}
|
|
}
|
|
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(208)
|
|
defer tls.Free(208)
|
|
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 + 32
|
|
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
|
|
//
|
|
// /*
|
|
// ** This function is called when an UPDATE or DELETE operation is being
|
|
// ** compiled on table pTab, which is the parent table of foreign-key pFKey.
|
|
// ** If the current operation is an UPDATE, then the pChanges parameter is
|
|
// ** passed a pointer to the list of columns being modified. If it is a
|
|
// ** DELETE, pChanges is passed a NULL pointer.
|
|
// **
|
|
// ** It returns a pointer to a Trigger structure containing a trigger
|
|
// ** equivalent to the ON UPDATE or ON DELETE action specified by pFKey.
|
|
// ** If the action is "NO ACTION" then a NULL pointer is returned (these actions
|
|
// ** require no special handling by the triggers sub-system, code for them is
|
|
// ** created by fkScanChildren()).
|
|
// **
|
|
// ** For example, if pFKey is the foreign key and pTab is table "p" in
|
|
// ** the following schema:
|
|
// **
|
|
// ** CREATE TABLE p(pk PRIMARY KEY);
|
|
// ** CREATE TABLE c(ck REFERENCES p ON DELETE CASCADE);
|
|
// **
|
|
// ** then the returned trigger structure is equivalent to:
|
|
// **
|
|
// ** CREATE TRIGGER ... DELETE ON p BEGIN
|
|
// ** DELETE FROM c WHERE ck = old.pk;
|
|
// ** END;
|
|
// **
|
|
// ** The returned pointer is cached as part of the foreign key object. It
|
|
// ** is eventually freed along with the rest of the foreign key object by
|
|
// ** sqlite3FkDelete().
|
|
// */
|
|
func _fkActionTrigger(tls *libc.TLS, pParse uintptr, pTab uintptr, pFKey uintptr, pChanges uintptr) (r uintptr) {
|
|
bp := tls.Alloc(48)
|
|
defer tls.Free(48)
|
|
var action, i, iAction, iFromCol, nFrom, v2 int32
|
|
var db, pCol, pDflt, pEq, pItem, pItem1, pList, pNew, pRaise, pSelect, pSrc, pStep, pTrigger, pWhen, pWhere, zFrom, v4 uintptr
|
|
var _ /* aiCol at bp+4 */ uintptr
|
|
var _ /* pIdx at bp+0 */ uintptr
|
|
var _ /* tFromCol at bp+24 */ TToken
|
|
var _ /* tNew at bp+16 */ TToken
|
|
var _ /* tOld at bp+8 */ TToken
|
|
var _ /* tToCol at bp+32 */ TToken
|
|
_, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _ = action, db, i, iAction, iFromCol, nFrom, pCol, pDflt, pEq, pItem, pItem1, pList, pNew, pRaise, pSelect, pSrc, pStep, pTrigger, pWhen, pWhere, zFrom, v2, v4
|
|
db = (*TParse)(unsafe.Pointer(pParse)).Fdb /* Trigger definition to return */
|
|
iAction = libc.BoolInt32(pChanges != uintptr(0)) /* 1 for UPDATE, 0 for DELETE */
|
|
action = libc.Int32FromUint8(**(**Tu8)(__ccgo_up(pFKey + 25 + uintptr(iAction))))
|
|
if (*Tsqlite3)(unsafe.Pointer(db)).Fflags&(libc.Uint64FromInt32(libc.Int32FromInt32(0x00008))<<libc.Int32FromInt32(32)) != 0 {
|
|
action = OE_None
|
|
}
|
|
if action == int32(OE_Restrict) && (*Tsqlite3)(unsafe.Pointer(db)).Fflags&uint64(SQLITE_DeferFKs) != 0 {
|
|
return uintptr(0)
|
|
}
|
|
pTrigger = **(**uintptr)(__ccgo_up(pFKey + 28 + uintptr(iAction)*4))
|
|
if action != OE_None && !(pTrigger != 0) { /* Length in bytes of zFrom */
|
|
**(**uintptr)(__ccgo_up(bp)) = uintptr(0) /* Parent key index for this FK */
|
|
**(**uintptr)(__ccgo_up(bp + 4)) = uintptr(0) /* child table cols -> parent key cols */
|
|
pStep = uintptr(0) /* First (only) step of trigger program */
|
|
pWhere = uintptr(0) /* WHERE clause of trigger step */
|
|
pList = uintptr(0) /* Changes list if ON UPDATE CASCADE */
|
|
pSelect = uintptr(0) /* Iterator variable */
|
|
pWhen = uintptr(0) /* WHEN clause for the trigger */
|
|
if _sqlite3FkLocateIndex(tls, pParse, pTab, pFKey, bp, bp+4) != 0 {
|
|
return uintptr(0)
|
|
}
|
|
i = 0
|
|
for {
|
|
if !(i < (*TFKey)(unsafe.Pointer(pFKey)).FnCol) {
|
|
break
|
|
}
|
|
**(**TToken)(__ccgo_up(bp + 8)) = TToken{
|
|
Fz: __ccgo_ts + 6829,
|
|
Fn: uint32(3),
|
|
} /* Literal "old" token */
|
|
**(**TToken)(__ccgo_up(bp + 16)) = TToken{
|
|
Fz: __ccgo_ts + 6825,
|
|
Fn: uint32(3),
|
|
} /* tFromCol = OLD.tToCol */
|
|
if **(**uintptr)(__ccgo_up(bp + 4)) != 0 {
|
|
v2 = **(**int32)(__ccgo_up(**(**uintptr)(__ccgo_up(bp + 4)) + uintptr(i)*4))
|
|
} else {
|
|
v2 = (*(*TsColMap)(unsafe.Pointer(pFKey + 36))).FiFrom
|
|
}
|
|
iFromCol = v2
|
|
if **(**uintptr)(__ccgo_up(bp)) != 0 {
|
|
v2 = int32(**(**Ti16)(__ccgo_up((*TIndex)(unsafe.Pointer(**(**uintptr)(__ccgo_up(bp)))).FaiColumn + uintptr(i)*2)))
|
|
} else {
|
|
v2 = int32((*TTable)(unsafe.Pointer(pTab)).FiPKey)
|
|
}
|
|
_sqlite3TokenInit(tls, bp+32, (**(**TColumn)(__ccgo_up((*TTable)(unsafe.Pointer(pTab)).FaCol + uintptr(v2)*12))).FzCnName)
|
|
_sqlite3TokenInit(tls, bp+24, (**(**TColumn)(__ccgo_up((*TTable)(unsafe.Pointer((*TFKey)(unsafe.Pointer(pFKey)).FpFrom)).FaCol + uintptr(iFromCol)*12))).FzCnName)
|
|
/* Create the expression "OLD.zToCol = zFromCol". It is important
|
|
** that the "OLD.zToCol" term is on the LHS of the = operator, so
|
|
** that the affinity and collation sequence associated with the
|
|
** parent table are used for the comparison. */
|
|
pEq = _sqlite3PExpr(tls, pParse, int32(TK_EQ), _sqlite3PExpr(tls, pParse, int32(TK_DOT), _sqlite3ExprAlloc(tls, db, int32(TK_ID), bp+8, 0), _sqlite3ExprAlloc(tls, db, int32(TK_ID), bp+32, 0)), _sqlite3ExprAlloc(tls, db, int32(TK_ID), bp+24, 0))
|
|
pWhere = _sqlite3ExprAnd(tls, pParse, pWhere, pEq)
|
|
/* For ON UPDATE, construct the next term of the WHEN clause.
|
|
** The final WHEN clause will be like this:
|
|
**
|
|
** WHEN NOT(old.col1 IS new.col1 AND ... AND old.colN IS new.colN)
|
|
*/
|
|
if pChanges != 0 {
|
|
pEq = _sqlite3PExpr(tls, pParse, int32(TK_IS), _sqlite3PExpr(tls, pParse, int32(TK_DOT), _sqlite3ExprAlloc(tls, db, int32(TK_ID), bp+8, 0), _sqlite3ExprAlloc(tls, db, int32(TK_ID), bp+32, 0)), _sqlite3PExpr(tls, pParse, int32(TK_DOT), _sqlite3ExprAlloc(tls, db, int32(TK_ID), bp+16, 0), _sqlite3ExprAlloc(tls, db, int32(TK_ID), bp+32, 0)))
|
|
pWhen = _sqlite3ExprAnd(tls, pParse, pWhen, pEq)
|
|
}
|
|
if action != int32(OE_Restrict) && (action != int32(OE_Cascade) || pChanges != 0) {
|
|
if action == int32(OE_Cascade) {
|
|
pNew = _sqlite3PExpr(tls, pParse, int32(TK_DOT), _sqlite3ExprAlloc(tls, db, int32(TK_ID), bp+16, 0), _sqlite3ExprAlloc(tls, db, int32(TK_ID), bp+32, 0))
|
|
} else {
|
|
if action == int32(OE_SetDflt) {
|
|
pCol = (*TTable)(unsafe.Pointer((*TFKey)(unsafe.Pointer(pFKey)).FpFrom)).FaCol + uintptr(iFromCol)*12
|
|
if libc.Int32FromUint16((*TColumn)(unsafe.Pointer(pCol)).FcolFlags)&int32(COLFLAG_GENERATED) != 0 {
|
|
pDflt = uintptr(0)
|
|
} else {
|
|
pDflt = _sqlite3ColumnExpr(tls, (*TFKey)(unsafe.Pointer(pFKey)).FpFrom, pCol)
|
|
}
|
|
if pDflt != 0 {
|
|
pNew = _sqlite3ExprDup(tls, db, pDflt, 0)
|
|
} else {
|
|
pNew = _sqlite3ExprAlloc(tls, db, int32(TK_NULL), uintptr(0), 0)
|
|
}
|
|
} else {
|
|
pNew = _sqlite3ExprAlloc(tls, db, int32(TK_NULL), uintptr(0), 0)
|
|
}
|
|
}
|
|
pList = _sqlite3ExprListAppend(tls, pParse, pList, pNew)
|
|
_sqlite3ExprListSetName(tls, pParse, pList, bp+24, 0)
|
|
}
|
|
goto _1
|
|
_1:
|
|
;
|
|
i = i + 1
|
|
}
|
|
_sqlite3DbFree(tls, db, **(**uintptr)(__ccgo_up(bp + 4)))
|
|
zFrom = (*TTable)(unsafe.Pointer((*TFKey)(unsafe.Pointer(pFKey)).FpFrom)).FzName
|
|
nFrom = _sqlite3Strlen30(tls, zFrom)
|
|
if action == int32(OE_Restrict) {
|
|
pRaise = _sqlite3Expr(tls, db, int32(TK_STRING), __ccgo_ts+5394)
|
|
pRaise = _sqlite3PExpr(tls, pParse, int32(TK_RAISE), pRaise, uintptr(0))
|
|
if pRaise != 0 {
|
|
(*TExpr)(unsafe.Pointer(pRaise)).FaffExpr = int8(OE_Abort)
|
|
}
|
|
pSrc = _sqlite3SrcListAppend(tls, pParse, uintptr(0), uintptr(0), uintptr(0))
|
|
if pSrc != 0 {
|
|
pItem = pSrc + 8
|
|
(*TSrcItem)(unsafe.Pointer(pItem)).FzName = _sqlite3DbStrDup(tls, db, zFrom)
|
|
libc.SetBitFieldPtr32Uint32(pItem+12+4, libc.Uint32FromInt32(1), 16, 0x10000)
|
|
*(*uintptr)(unsafe.Pointer(pItem + 44)) = (*TTable)(unsafe.Pointer(pTab)).FpSchema
|
|
}
|
|
pSelect = _sqlite3SelectNew(tls, pParse, _sqlite3ExprListAppend(tls, pParse, uintptr(0), pRaise), pSrc, pWhere, uintptr(0), uintptr(0), uintptr(0), uint32(0), uintptr(0))
|
|
pWhere = uintptr(0)
|
|
}
|
|
/* Disable lookaside memory allocation */
|
|
(*Tsqlite3)(unsafe.Pointer(db)).Flookaside.FbDisable = (*Tsqlite3)(unsafe.Pointer(db)).Flookaside.FbDisable + 1
|
|
(*Tsqlite3)(unsafe.Pointer(db)).Flookaside.Fsz = uint16(0)
|
|
pTrigger = _sqlite3DbMallocZero(tls, db, uint64(libc.Uint32FromInt64(36)+libc.Uint32FromInt64(44)))
|
|
if pTrigger != 0 {
|
|
v4 = pTrigger + 1*36
|
|
(*TTrigger)(unsafe.Pointer(pTrigger)).Fstep_list = v4
|
|
pStep = v4
|
|
(*TTriggerStep)(unsafe.Pointer(pStep)).FpSrc = _sqlite3SrcListAppend(tls, pParse, uintptr(0), uintptr(0), uintptr(0))
|
|
if (*TTriggerStep)(unsafe.Pointer(pStep)).FpSrc != 0 {
|
|
pItem1 = (*TTriggerStep)(unsafe.Pointer(pStep)).FpSrc + 8
|
|
(*TSrcItem)(unsafe.Pointer(pItem1)).FzName = _sqlite3DbStrNDup(tls, db, zFrom, libc.Uint64FromInt32(nFrom))
|
|
*(*uintptr)(unsafe.Pointer(pItem1 + 44)) = (*TTable)(unsafe.Pointer(pTab)).FpSchema
|
|
libc.SetBitFieldPtr32Uint32(pItem1+12+4, libc.Uint32FromInt32(1), 16, 0x10000)
|
|
}
|
|
(*TTriggerStep)(unsafe.Pointer(pStep)).FpWhere = _sqlite3ExprDup(tls, db, pWhere, int32(EXPRDUP_REDUCE))
|
|
(*TTriggerStep)(unsafe.Pointer(pStep)).FpExprList = _sqlite3ExprListDup(tls, db, pList, int32(EXPRDUP_REDUCE))
|
|
(*TTriggerStep)(unsafe.Pointer(pStep)).FpSelect = _sqlite3SelectDup(tls, db, pSelect, int32(EXPRDUP_REDUCE))
|
|
if pWhen != 0 {
|
|
pWhen = _sqlite3PExpr(tls, pParse, int32(TK_NOT), pWhen, uintptr(0))
|
|
(*TTrigger)(unsafe.Pointer(pTrigger)).FpWhen = _sqlite3ExprDup(tls, db, pWhen, int32(EXPRDUP_REDUCE))
|
|
}
|
|
}
|
|
/* Re-enable the lookaside buffer, if it was disabled earlier. */
|
|
(*Tsqlite3)(unsafe.Pointer(db)).Flookaside.FbDisable = (*Tsqlite3)(unsafe.Pointer(db)).Flookaside.FbDisable - 1
|
|
if (*Tsqlite3)(unsafe.Pointer(db)).Flookaside.FbDisable != 0 {
|
|
v2 = 0
|
|
} else {
|
|
v2 = libc.Int32FromUint16((*Tsqlite3)(unsafe.Pointer(db)).Flookaside.FszTrue)
|
|
}
|
|
(*Tsqlite3)(unsafe.Pointer(db)).Flookaside.Fsz = libc.Uint16FromInt32(v2)
|
|
_sqlite3ExprDelete(tls, db, pWhere)
|
|
_sqlite3ExprDelete(tls, db, pWhen)
|
|
_sqlite3ExprListDelete(tls, db, pList)
|
|
_sqlite3SelectDelete(tls, db, pSelect)
|
|
if libc.Int32FromUint8((*Tsqlite3)(unsafe.Pointer(db)).FmallocFailed) == int32(1) {
|
|
_fkTriggerDelete(tls, db, pTrigger)
|
|
return uintptr(0)
|
|
}
|
|
switch action {
|
|
case int32(OE_Restrict):
|
|
(*TTriggerStep)(unsafe.Pointer(pStep)).Fop = uint8(TK_SELECT)
|
|
case int32(OE_Cascade):
|
|
if !(pChanges != 0) {
|
|
(*TTriggerStep)(unsafe.Pointer(pStep)).Fop = uint8(TK_DELETE)
|
|
break
|
|
}
|
|
fallthrough
|
|
default:
|
|
(*TTriggerStep)(unsafe.Pointer(pStep)).Fop = uint8(TK_UPDATE)
|
|
}
|
|
(*TTriggerStep)(unsafe.Pointer(pStep)).FpTrig = pTrigger
|
|
(*TTrigger)(unsafe.Pointer(pTrigger)).FpSchema = (*TTable)(unsafe.Pointer(pTab)).FpSchema
|
|
(*TTrigger)(unsafe.Pointer(pTrigger)).FpTabSchema = (*TTable)(unsafe.Pointer(pTab)).FpSchema
|
|
**(**uintptr)(__ccgo_up(pFKey + 28 + uintptr(iAction)*4)) = pTrigger
|
|
if pChanges != 0 {
|
|
v2 = int32(TK_UPDATE)
|
|
} else {
|
|
v2 = int32(TK_DELETE)
|
|
}
|
|
(*TTrigger)(unsafe.Pointer(pTrigger)).Fop = libc.Uint8FromInt32(v2)
|
|
}
|
|
return pTrigger
|
|
}
|
|
|
|
// C documentation
|
|
//
|
|
// /*
|
|
// ** Implementation of the xBestIndex method for FTS5 tables. Within the
|
|
// ** WHERE constraint, it searches for the following:
|
|
// **
|
|
// ** 1. A MATCH constraint against the table column.
|
|
// ** 2. A MATCH constraint against the "rank" column.
|
|
// ** 3. A MATCH constraint against some other column.
|
|
// ** 4. An == constraint against the rowid column.
|
|
// ** 5. A < or <= constraint against the rowid column.
|
|
// ** 6. A > or >= constraint against the rowid column.
|
|
// **
|
|
// ** Within the ORDER BY, the following are supported:
|
|
// **
|
|
// ** 5. ORDER BY rank [ASC|DESC]
|
|
// ** 6. ORDER BY rowid [ASC|DESC]
|
|
// **
|
|
// ** Information for the xFilter call is passed via both the idxNum and
|
|
// ** idxStr variables. Specifically, idxNum is a bitmask of the following
|
|
// ** flags used to encode the ORDER BY clause:
|
|
// **
|
|
// ** FTS5_BI_ORDER_RANK
|
|
// ** FTS5_BI_ORDER_ROWID
|
|
// ** FTS5_BI_ORDER_DESC
|
|
// **
|
|
// ** idxStr is used to encode data from the WHERE clause. For each argument
|
|
// ** passed to the xFilter method, the following is appended to idxStr:
|
|
// **
|
|
// ** Match against table column: "m"
|
|
// ** Match against rank column: "r"
|
|
// ** Match against other column: "M<column-number>"
|
|
// ** LIKE against other column: "L<column-number>"
|
|
// ** GLOB against other column: "G<column-number>"
|
|
// ** Equality constraint against the rowid: "="
|
|
// ** A < or <= against the rowid: "<"
|
|
// ** A > or >= against the rowid: ">"
|
|
// **
|
|
// ** This function ensures that there is at most one "r" or "=". And that if
|
|
// ** there exists an "=" then there is no "<" or ">".
|
|
// **
|
|
// ** If an unusable MATCH operator is present in the WHERE clause, then
|
|
// ** SQLITE_CONSTRAINT is returned.
|
|
// **
|
|
// ** Costs are assigned as follows:
|
|
// **
|
|
// ** a) If a MATCH operator is present, the cost depends on the other
|
|
// ** constraints also present. As follows:
|
|
// **
|
|
// ** * No other constraints: cost=50000.0
|
|
// ** * One rowid range constraint: cost=37500.0
|
|
// ** * Both rowid range constraints: cost=30000.0
|
|
// ** * An == rowid constraint: cost=25000.0
|
|
// **
|
|
// ** b) Otherwise, if there is no MATCH:
|
|
// **
|
|
// ** * No other constraints: cost=3000000.0
|
|
// ** * One rowid range constraints: cost=2250000.0
|
|
// ** * Both rowid range constraint: cost=750000.0
|
|
// ** * An == rowid constraint: cost=25.0
|
|
// **
|
|
// ** Costs are not modified by the ORDER BY clause.
|
|
// **
|
|
// ** The ratios used in case (a) are based on informal results obtained from
|
|
// ** the tool/fts5cost.tcl script. The "MATCH and ==" combination has the
|
|
// ** cost set quite high because the query may be a prefix query. Unless
|
|
// ** there is a prefix index, prefix queries with rowid constraints are much
|
|
// ** more expensive than non-prefix queries with rowid constraints.
|
|
// **
|
|
// ** The estimated rows returned is set to the cost/40. For simple queries,
|
|
// ** experimental results show that cost/4 might be about right. But for
|
|
// ** more complex queries that use multiple terms the number of rows might
|
|
// ** be far fewer than this. So we compromise and use cost/40.
|
|
// */
|
|
func _fts5BestIndexMethod(tls *libc.TLS, pVTab uintptr, pInfo uintptr) (r int32) {
|
|
bp := tls.Alloc(16)
|
|
defer tls.Free(16)
|
|
var bSeenEq, bSeenGt, bSeenLt, bSeenRank, i, iCol, iCons, iIdxStr, iSort, idxFlags, nCol, nSeenMatch, op, v2, v3 int32
|
|
var idxStr, p, p1, pConfig, pTab uintptr
|
|
var nEstRows Ti64
|
|
var v15 float64
|
|
_, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _ = bSeenEq, bSeenGt, bSeenLt, bSeenRank, i, iCol, iCons, iIdxStr, iSort, idxFlags, idxStr, nCol, nEstRows, nSeenMatch, op, p, p1, pConfig, pTab, v15, v2, v3
|
|
pTab = pVTab
|
|
pConfig = (*TFts5Table)(unsafe.Pointer(pTab)).FpConfig
|
|
nCol = (*TFts5Config)(unsafe.Pointer(pConfig)).FnCol
|
|
idxFlags = 0
|
|
iIdxStr = 0
|
|
iCons = 0
|
|
bSeenEq = 0
|
|
bSeenGt = 0
|
|
bSeenLt = 0
|
|
nSeenMatch = 0
|
|
bSeenRank = 0
|
|
if (*TFts5Config)(unsafe.Pointer(pConfig)).FbLock != 0 {
|
|
(*TFts5Table)(unsafe.Pointer(pTab)).Fbase.FzErrMsg = Xsqlite3_mprintf(tls, __ccgo_ts+39714, 0)
|
|
return int32(SQLITE_ERROR)
|
|
}
|
|
idxStr = Xsqlite3_malloc64(tls, libc.Uint64FromInt64(int64((*Tsqlite3_index_info)(unsafe.Pointer(pInfo)).FnConstraint)*int64(8)+int64(1)))
|
|
if idxStr == uintptr(0) {
|
|
return int32(SQLITE_NOMEM)
|
|
}
|
|
(*Tsqlite3_index_info)(unsafe.Pointer(pInfo)).FidxStr = idxStr
|
|
(*Tsqlite3_index_info)(unsafe.Pointer(pInfo)).FneedToFreeIdxStr = int32(1)
|
|
i = 0
|
|
for {
|
|
if !(i < (*Tsqlite3_index_info)(unsafe.Pointer(pInfo)).FnConstraint) {
|
|
break
|
|
}
|
|
p = (*Tsqlite3_index_info)(unsafe.Pointer(pInfo)).FaConstraint + uintptr(i)*12
|
|
iCol = (*Tsqlite3_index_constraint)(unsafe.Pointer(p)).FiColumn
|
|
if libc.Int32FromUint8((*Tsqlite3_index_constraint)(unsafe.Pointer(p)).Fop) == int32(SQLITE_INDEX_CONSTRAINT_MATCH) || libc.Int32FromUint8((*Tsqlite3_index_constraint)(unsafe.Pointer(p)).Fop) == int32(SQLITE_INDEX_CONSTRAINT_EQ) && iCol >= nCol {
|
|
/* A MATCH operator or equivalent */
|
|
if libc.Int32FromUint8((*Tsqlite3_index_constraint)(unsafe.Pointer(p)).Fusable) == 0 || iCol < 0 {
|
|
/* As there exists an unusable MATCH constraint this is an
|
|
** unusable plan. Return SQLITE_CONSTRAINT. */
|
|
**(**int8)(__ccgo_up(idxStr + uintptr(iIdxStr))) = 0
|
|
return int32(SQLITE_CONSTRAINT)
|
|
} else {
|
|
if iCol == nCol+int32(1) {
|
|
if bSeenRank != 0 {
|
|
goto _1
|
|
}
|
|
v2 = iIdxStr
|
|
iIdxStr = iIdxStr + 1
|
|
**(**int8)(__ccgo_up(idxStr + uintptr(v2))) = int8('r')
|
|
bSeenRank = int32(1)
|
|
} else {
|
|
nSeenMatch = nSeenMatch + 1
|
|
v2 = iIdxStr
|
|
iIdxStr = iIdxStr + 1
|
|
**(**int8)(__ccgo_up(idxStr + uintptr(v2))) = int8('M')
|
|
Xsqlite3_snprintf(tls, int32(6), idxStr+uintptr(iIdxStr), __ccgo_ts+5291, libc.VaList(bp+8, iCol))
|
|
iIdxStr = iIdxStr + libc.Int32FromUint32(libc.Xstrlen(tls, idxStr+uintptr(iIdxStr)))
|
|
}
|
|
iCons = iCons + 1
|
|
v2 = iCons
|
|
(**(**Tsqlite3_index_constraint_usage)(__ccgo_up((*Tsqlite3_index_info)(unsafe.Pointer(pInfo)).FaConstraintUsage + uintptr(i)*8))).FargvIndex = v2
|
|
(**(**Tsqlite3_index_constraint_usage)(__ccgo_up((*Tsqlite3_index_info)(unsafe.Pointer(pInfo)).FaConstraintUsage + uintptr(i)*8))).Fomit = uint8(1)
|
|
}
|
|
} else {
|
|
if (*Tsqlite3_index_constraint)(unsafe.Pointer(p)).Fusable != 0 {
|
|
if iCol >= 0 && iCol < nCol && _fts5UsePatternMatch(tls, pConfig, p) != 0 {
|
|
v2 = iIdxStr
|
|
iIdxStr = iIdxStr + 1
|
|
if libc.Int32FromUint8((*Tsqlite3_index_constraint)(unsafe.Pointer(p)).Fop) == int32(FTS5_PATTERN_LIKE) {
|
|
v3 = int32('L')
|
|
} else {
|
|
v3 = int32('G')
|
|
}
|
|
**(**int8)(__ccgo_up(idxStr + uintptr(v2))) = int8(v3)
|
|
Xsqlite3_snprintf(tls, int32(6), idxStr+uintptr(iIdxStr), __ccgo_ts+5291, libc.VaList(bp+8, iCol))
|
|
idxStr = idxStr + uintptr(libc.Xstrlen(tls, idxStr+uintptr(iIdxStr)))
|
|
iCons = iCons + 1
|
|
v2 = iCons
|
|
(**(**Tsqlite3_index_constraint_usage)(__ccgo_up((*Tsqlite3_index_info)(unsafe.Pointer(pInfo)).FaConstraintUsage + uintptr(i)*8))).FargvIndex = v2
|
|
nSeenMatch = nSeenMatch + 1
|
|
} else {
|
|
if bSeenEq == 0 && libc.Int32FromUint8((*Tsqlite3_index_constraint)(unsafe.Pointer(p)).Fop) == int32(SQLITE_INDEX_CONSTRAINT_EQ) && iCol < 0 {
|
|
v2 = iIdxStr
|
|
iIdxStr = iIdxStr + 1
|
|
**(**int8)(__ccgo_up(idxStr + uintptr(v2))) = int8('=')
|
|
bSeenEq = int32(1)
|
|
iCons = iCons + 1
|
|
v2 = iCons
|
|
(**(**Tsqlite3_index_constraint_usage)(__ccgo_up((*Tsqlite3_index_info)(unsafe.Pointer(pInfo)).FaConstraintUsage + uintptr(i)*8))).FargvIndex = v2
|
|
(**(**Tsqlite3_index_constraint_usage)(__ccgo_up((*Tsqlite3_index_info)(unsafe.Pointer(pInfo)).FaConstraintUsage + uintptr(i)*8))).Fomit = uint8(1)
|
|
}
|
|
}
|
|
}
|
|
}
|
|
goto _1
|
|
_1:
|
|
;
|
|
i = i + 1
|
|
}
|
|
if bSeenEq == 0 {
|
|
i = 0
|
|
for {
|
|
if !(i < (*Tsqlite3_index_info)(unsafe.Pointer(pInfo)).FnConstraint) {
|
|
break
|
|
}
|
|
p1 = (*Tsqlite3_index_info)(unsafe.Pointer(pInfo)).FaConstraint + uintptr(i)*12
|
|
if (*Tsqlite3_index_constraint)(unsafe.Pointer(p1)).FiColumn < 0 && (*Tsqlite3_index_constraint)(unsafe.Pointer(p1)).Fusable != 0 {
|
|
op = libc.Int32FromUint8((*Tsqlite3_index_constraint)(unsafe.Pointer(p1)).Fop)
|
|
if op == int32(SQLITE_INDEX_CONSTRAINT_LT) || op == int32(SQLITE_INDEX_CONSTRAINT_LE) {
|
|
if bSeenLt != 0 {
|
|
goto _10
|
|
}
|
|
v2 = iIdxStr
|
|
iIdxStr = iIdxStr + 1
|
|
**(**int8)(__ccgo_up(idxStr + uintptr(v2))) = int8('<')
|
|
iCons = iCons + 1
|
|
v2 = iCons
|
|
(**(**Tsqlite3_index_constraint_usage)(__ccgo_up((*Tsqlite3_index_info)(unsafe.Pointer(pInfo)).FaConstraintUsage + uintptr(i)*8))).FargvIndex = v2
|
|
bSeenLt = int32(1)
|
|
} else {
|
|
if op == int32(SQLITE_INDEX_CONSTRAINT_GT) || op == int32(SQLITE_INDEX_CONSTRAINT_GE) {
|
|
if bSeenGt != 0 {
|
|
goto _10
|
|
}
|
|
v2 = iIdxStr
|
|
iIdxStr = iIdxStr + 1
|
|
**(**int8)(__ccgo_up(idxStr + uintptr(v2))) = int8('>')
|
|
iCons = iCons + 1
|
|
v2 = iCons
|
|
(**(**Tsqlite3_index_constraint_usage)(__ccgo_up((*Tsqlite3_index_info)(unsafe.Pointer(pInfo)).FaConstraintUsage + uintptr(i)*8))).FargvIndex = v2
|
|
bSeenGt = int32(1)
|
|
}
|
|
}
|
|
}
|
|
goto _10
|
|
_10:
|
|
;
|
|
i = i + 1
|
|
}
|
|
}
|
|
**(**int8)(__ccgo_up(idxStr + uintptr(iIdxStr))) = int8('\000')
|
|
/* Set idxFlags flags for the ORDER BY clause
|
|
**
|
|
** Note that tokendata=1 tables cannot currently handle "ORDER BY rowid DESC".
|
|
*/
|
|
if (*Tsqlite3_index_info)(unsafe.Pointer(pInfo)).FnOrderBy == int32(1) {
|
|
iSort = (**(**Tsqlite3_index_orderby)(__ccgo_up((*Tsqlite3_index_info)(unsafe.Pointer(pInfo)).FaOrderBy))).FiColumn
|
|
if iSort == (*TFts5Config)(unsafe.Pointer(pConfig)).FnCol+int32(1) && nSeenMatch > 0 {
|
|
idxFlags = idxFlags | int32(FTS5_BI_ORDER_RANK)
|
|
} else {
|
|
if iSort == -int32(1) && (!((**(**Tsqlite3_index_orderby)(__ccgo_up((*Tsqlite3_index_info)(unsafe.Pointer(pInfo)).FaOrderBy))).Fdesc != 0) || !((*TFts5Config)(unsafe.Pointer(pConfig)).FbTokendata != 0)) {
|
|
idxFlags = idxFlags | int32(FTS5_BI_ORDER_ROWID)
|
|
}
|
|
}
|
|
if idxFlags&(libc.Int32FromInt32(FTS5_BI_ORDER_RANK)|libc.Int32FromInt32(FTS5_BI_ORDER_ROWID)) != 0 {
|
|
(*Tsqlite3_index_info)(unsafe.Pointer(pInfo)).ForderByConsumed = int32(1)
|
|
if (**(**Tsqlite3_index_orderby)(__ccgo_up((*Tsqlite3_index_info)(unsafe.Pointer(pInfo)).FaOrderBy))).Fdesc != 0 {
|
|
idxFlags = idxFlags | int32(FTS5_BI_ORDER_DESC)
|
|
}
|
|
}
|
|
}
|
|
/* Calculate the estimated cost based on the flags set in idxFlags. */
|
|
if bSeenEq != 0 {
|
|
if nSeenMatch != 0 {
|
|
v15 = float64(25000)
|
|
} else {
|
|
v15 = float64(25)
|
|
}
|
|
(*Tsqlite3_index_info)(unsafe.Pointer(pInfo)).FestimatedCost = v15
|
|
_fts5SetEstimatedRows(tls, pInfo, int64(1))
|
|
_fts5SetUniqueFlag(tls, pInfo)
|
|
} else {
|
|
if nSeenMatch != 0 {
|
|
if bSeenLt != 0 && bSeenGt != 0 {
|
|
(*Tsqlite3_index_info)(unsafe.Pointer(pInfo)).FestimatedCost = float64(50000)
|
|
} else {
|
|
if bSeenLt != 0 || bSeenGt != 0 {
|
|
(*Tsqlite3_index_info)(unsafe.Pointer(pInfo)).FestimatedCost = float64(37500)
|
|
} else {
|
|
(*Tsqlite3_index_info)(unsafe.Pointer(pInfo)).FestimatedCost = float64(50000)
|
|
}
|
|
}
|
|
nEstRows = int64((*Tsqlite3_index_info)(unsafe.Pointer(pInfo)).FestimatedCost / libc.Float64FromFloat64(40))
|
|
i = int32(1)
|
|
for {
|
|
if !(i < nSeenMatch) {
|
|
break
|
|
}
|
|
**(**float64)(__ccgo_up(pInfo + 36)) *= float64(2.5)
|
|
nEstRows = nEstRows / int64(2)
|
|
goto _16
|
|
_16:
|
|
;
|
|
i = i + 1
|
|
}
|
|
} else {
|
|
if bSeenLt != 0 && bSeenGt != 0 {
|
|
(*Tsqlite3_index_info)(unsafe.Pointer(pInfo)).FestimatedCost = float64(750000)
|
|
} else {
|
|
if bSeenLt != 0 || bSeenGt != 0 {
|
|
(*Tsqlite3_index_info)(unsafe.Pointer(pInfo)).FestimatedCost = float64(2.25e+06)
|
|
} else {
|
|
(*Tsqlite3_index_info)(unsafe.Pointer(pInfo)).FestimatedCost = float64(3e+06)
|
|
}
|
|
}
|
|
nEstRows = int64((*Tsqlite3_index_info)(unsafe.Pointer(pInfo)).FestimatedCost / libc.Float64FromFloat64(4))
|
|
}
|
|
_fts5SetEstimatedRows(tls, pInfo, nEstRows)
|
|
}
|
|
(*Tsqlite3_index_info)(unsafe.Pointer(pInfo)).FidxNum = idxFlags
|
|
return SQLITE_OK
|
|
}
|
|
|
|
// C documentation
|
|
//
|
|
// /*
|
|
// ** Parse a "special" CREATE VIRTUAL TABLE directive and update
|
|
// ** configuration object pConfig as appropriate.
|
|
// **
|
|
// ** If successful, object pConfig is updated and SQLITE_OK returned. If
|
|
// ** an error occurs, an SQLite error code is returned and an error message
|
|
// ** may be left in *pzErr. It is the responsibility of the caller to
|
|
// ** eventually free any such error message using sqlite3_free().
|
|
// */
|
|
func _fts5ConfigParseSpecial(tls *libc.TLS, pConfig uintptr, zCmd uintptr, zArg uintptr, pzErr uintptr) (r int32) {
|
|
bp := tls.Alloc(64)
|
|
defer tls.Free(64)
|
|
var azArg, p, p1, p2, pSpace uintptr
|
|
var bFirst, nByte, nCmd, nPre, v2 int32
|
|
var nArg Tsqlite3_int64
|
|
var _ /* aDetail at bp+4 */ [4]TFts5Enum
|
|
var _ /* rc at bp+0 */ int32
|
|
_, _, _, _, _, _, _, _, _, _, _ = azArg, bFirst, nArg, nByte, nCmd, nPre, p, p1, p2, pSpace, v2
|
|
**(**int32)(__ccgo_up(bp)) = SQLITE_OK
|
|
nCmd = libc.Int32FromUint32(libc.Xstrlen(tls, zCmd))
|
|
if Xsqlite3_strnicmp(tls, __ccgo_ts+37405, zCmd, nCmd) == 0 {
|
|
nByte = libc.Int32FromUint32(libc.Uint32FromInt64(4) * libc.Uint32FromInt32(FTS5_MAX_PREFIX_INDEXES))
|
|
bFirst = int32(1)
|
|
if (*TFts5Config)(unsafe.Pointer(pConfig)).FaPrefix == uintptr(0) {
|
|
(*TFts5Config)(unsafe.Pointer(pConfig)).FaPrefix = _sqlite3Fts5MallocZero(tls, bp, int64(nByte))
|
|
if **(**int32)(__ccgo_up(bp)) != 0 {
|
|
return **(**int32)(__ccgo_up(bp))
|
|
}
|
|
}
|
|
p = zArg
|
|
for int32(1) != 0 {
|
|
nPre = 0
|
|
for int32(**(**int8)(__ccgo_up(p))) == int32(' ') {
|
|
p = p + 1
|
|
}
|
|
if bFirst == 0 && int32(**(**int8)(__ccgo_up(p))) == int32(',') {
|
|
p = p + 1
|
|
for int32(**(**int8)(__ccgo_up(p))) == int32(' ') {
|
|
p = p + 1
|
|
}
|
|
} else {
|
|
if int32(**(**int8)(__ccgo_up(p))) == int32('\000') {
|
|
break
|
|
}
|
|
}
|
|
if int32(**(**int8)(__ccgo_up(p))) < int32('0') || int32(**(**int8)(__ccgo_up(p))) > int32('9') {
|
|
**(**uintptr)(__ccgo_up(pzErr)) = Xsqlite3_mprintf(tls, __ccgo_ts+37412, 0)
|
|
**(**int32)(__ccgo_up(bp)) = int32(SQLITE_ERROR)
|
|
break
|
|
}
|
|
if (*TFts5Config)(unsafe.Pointer(pConfig)).FnPrefix == int32(FTS5_MAX_PREFIX_INDEXES) {
|
|
**(**uintptr)(__ccgo_up(pzErr)) = Xsqlite3_mprintf(tls, __ccgo_ts+37443, libc.VaList(bp+48, int32(FTS5_MAX_PREFIX_INDEXES)))
|
|
**(**int32)(__ccgo_up(bp)) = int32(SQLITE_ERROR)
|
|
break
|
|
}
|
|
for int32(**(**int8)(__ccgo_up(p))) >= int32('0') && int32(**(**int8)(__ccgo_up(p))) <= int32('9') && nPre < int32(1000) {
|
|
nPre = nPre*int32(10) + (int32(**(**int8)(__ccgo_up(p))) - int32('0'))
|
|
p = p + 1
|
|
}
|
|
if nPre <= 0 || nPre >= int32(1000) {
|
|
**(**uintptr)(__ccgo_up(pzErr)) = Xsqlite3_mprintf(tls, __ccgo_ts+37476, 0)
|
|
**(**int32)(__ccgo_up(bp)) = int32(SQLITE_ERROR)
|
|
break
|
|
}
|
|
**(**int32)(__ccgo_up((*TFts5Config)(unsafe.Pointer(pConfig)).FaPrefix + uintptr((*TFts5Config)(unsafe.Pointer(pConfig)).FnPrefix)*4)) = nPre
|
|
(*TFts5Config)(unsafe.Pointer(pConfig)).FnPrefix = (*TFts5Config)(unsafe.Pointer(pConfig)).FnPrefix + 1
|
|
bFirst = 0
|
|
}
|
|
return **(**int32)(__ccgo_up(bp))
|
|
}
|
|
if Xsqlite3_strnicmp(tls, __ccgo_ts+37513, zCmd, nCmd) == 0 {
|
|
p1 = zArg
|
|
nArg = libc.Int64FromUint32(libc.Xstrlen(tls, zArg) + uint32(1))
|
|
azArg = _sqlite3Fts5MallocZero(tls, bp, libc.Int64FromUint32(libc.Uint32FromInt64(4)+libc.Uint32FromInt32(2))*nArg)
|
|
if azArg != 0 {
|
|
pSpace = azArg + uintptr(nArg)*4
|
|
if (*TFts5Config)(unsafe.Pointer(pConfig)).Ft.FazArg != 0 {
|
|
**(**uintptr)(__ccgo_up(pzErr)) = Xsqlite3_mprintf(tls, __ccgo_ts+37522, 0)
|
|
**(**int32)(__ccgo_up(bp)) = int32(SQLITE_ERROR)
|
|
} else {
|
|
nArg = 0
|
|
for {
|
|
if !(p1 != 0 && **(**int8)(__ccgo_up(p1)) != 0) {
|
|
break
|
|
}
|
|
p2 = _fts5ConfigSkipWhitespace(tls, p1)
|
|
if int32(**(**int8)(__ccgo_up(p2))) == int32('\'') {
|
|
p1 = _fts5ConfigSkipLiteral(tls, p2)
|
|
} else {
|
|
p1 = _fts5ConfigSkipBareword(tls, p2)
|
|
}
|
|
if p1 != 0 {
|
|
libc.Xmemcpy(tls, pSpace, p2, libc.Uint32FromInt32(int32(p1)-int32(p2)))
|
|
**(**uintptr)(__ccgo_up(azArg + uintptr(nArg)*4)) = pSpace
|
|
_sqlite3Fts5Dequote(tls, pSpace)
|
|
pSpace = pSpace + uintptr(int32(p1)-int32(p2)+int32(1))
|
|
p1 = _fts5ConfigSkipWhitespace(tls, p1)
|
|
}
|
|
goto _1
|
|
_1:
|
|
;
|
|
nArg = nArg + 1
|
|
}
|
|
if p1 == uintptr(0) {
|
|
**(**uintptr)(__ccgo_up(pzErr)) = Xsqlite3_mprintf(tls, __ccgo_ts+37555, 0)
|
|
**(**int32)(__ccgo_up(bp)) = int32(SQLITE_ERROR)
|
|
} else {
|
|
(*TFts5Config)(unsafe.Pointer(pConfig)).Ft.FazArg = azArg
|
|
(*TFts5Config)(unsafe.Pointer(pConfig)).Ft.FnArg = int32(nArg)
|
|
azArg = uintptr(0)
|
|
}
|
|
}
|
|
}
|
|
Xsqlite3_free(tls, azArg)
|
|
return **(**int32)(__ccgo_up(bp))
|
|
}
|
|
if Xsqlite3_strnicmp(tls, __ccgo_ts+37589, zCmd, nCmd) == 0 {
|
|
if (*TFts5Config)(unsafe.Pointer(pConfig)).FeContent != FTS5_CONTENT_NORMAL {
|
|
**(**uintptr)(__ccgo_up(pzErr)) = Xsqlite3_mprintf(tls, __ccgo_ts+37597, 0)
|
|
**(**int32)(__ccgo_up(bp)) = int32(SQLITE_ERROR)
|
|
} else {
|
|
if **(**int8)(__ccgo_up(zArg)) != 0 {
|
|
(*TFts5Config)(unsafe.Pointer(pConfig)).FeContent = int32(FTS5_CONTENT_EXTERNAL)
|
|
(*TFts5Config)(unsafe.Pointer(pConfig)).FzContent = _sqlite3Fts5Mprintf(tls, bp, __ccgo_ts+37629, libc.VaList(bp+48, (*TFts5Config)(unsafe.Pointer(pConfig)).FzDb, zArg))
|
|
} else {
|
|
(*TFts5Config)(unsafe.Pointer(pConfig)).FeContent = int32(FTS5_CONTENT_NONE)
|
|
}
|
|
}
|
|
return **(**int32)(__ccgo_up(bp))
|
|
}
|
|
if Xsqlite3_strnicmp(tls, __ccgo_ts+37635, zCmd, nCmd) == 0 {
|
|
if int32(**(**int8)(__ccgo_up(zArg))) != int32('0') && int32(**(**int8)(__ccgo_up(zArg))) != int32('1') || int32(**(**int8)(__ccgo_up(zArg + 1))) != int32('\000') {
|
|
**(**uintptr)(__ccgo_up(pzErr)) = Xsqlite3_mprintf(tls, __ccgo_ts+37654, 0)
|
|
**(**int32)(__ccgo_up(bp)) = int32(SQLITE_ERROR)
|
|
} else {
|
|
(*TFts5Config)(unsafe.Pointer(pConfig)).FbContentlessDelete = libc.BoolInt32(int32(**(**int8)(__ccgo_up(zArg))) == int32('1'))
|
|
}
|
|
return **(**int32)(__ccgo_up(bp))
|
|
}
|
|
if Xsqlite3_strnicmp(tls, __ccgo_ts+37697, zCmd, nCmd) == 0 {
|
|
if int32(**(**int8)(__ccgo_up(zArg))) != int32('0') && int32(**(**int8)(__ccgo_up(zArg))) != int32('1') || int32(**(**int8)(__ccgo_up(zArg + 1))) != int32('\000') {
|
|
**(**uintptr)(__ccgo_up(pzErr)) = Xsqlite3_mprintf(tls, __ccgo_ts+37654, 0)
|
|
**(**int32)(__ccgo_up(bp)) = int32(SQLITE_ERROR)
|
|
} else {
|
|
(*TFts5Config)(unsafe.Pointer(pConfig)).FbContentlessUnindexed = libc.BoolInt32(int32(**(**int8)(__ccgo_up(zArg))) == int32('1'))
|
|
}
|
|
return **(**int32)(__ccgo_up(bp))
|
|
}
|
|
if Xsqlite3_strnicmp(tls, __ccgo_ts+37719, zCmd, nCmd) == 0 {
|
|
if (*TFts5Config)(unsafe.Pointer(pConfig)).FzContentRowid != 0 {
|
|
**(**uintptr)(__ccgo_up(pzErr)) = Xsqlite3_mprintf(tls, __ccgo_ts+37733, 0)
|
|
**(**int32)(__ccgo_up(bp)) = int32(SQLITE_ERROR)
|
|
} else {
|
|
(*TFts5Config)(unsafe.Pointer(pConfig)).FzContentRowid = _sqlite3Fts5Strndup(tls, bp, zArg, -int32(1))
|
|
}
|
|
return **(**int32)(__ccgo_up(bp))
|
|
}
|
|
if Xsqlite3_strnicmp(tls, __ccgo_ts+37771, zCmd, nCmd) == 0 {
|
|
if int32(**(**int8)(__ccgo_up(zArg))) != int32('0') && int32(**(**int8)(__ccgo_up(zArg))) != int32('1') || int32(**(**int8)(__ccgo_up(zArg + 1))) != int32('\000') {
|
|
**(**uintptr)(__ccgo_up(pzErr)) = Xsqlite3_mprintf(tls, __ccgo_ts+37782, 0)
|
|
**(**int32)(__ccgo_up(bp)) = int32(SQLITE_ERROR)
|
|
} else {
|
|
(*TFts5Config)(unsafe.Pointer(pConfig)).FbColumnsize = libc.BoolInt32(int32(**(**int8)(__ccgo_up(zArg))) == int32('1'))
|
|
}
|
|
return **(**int32)(__ccgo_up(bp))
|
|
}
|
|
if Xsqlite3_strnicmp(tls, __ccgo_ts+37817, zCmd, nCmd) == 0 {
|
|
if int32(**(**int8)(__ccgo_up(zArg))) != int32('0') && int32(**(**int8)(__ccgo_up(zArg))) != int32('1') || int32(**(**int8)(__ccgo_up(zArg + 1))) != int32('\000') {
|
|
**(**uintptr)(__ccgo_up(pzErr)) = Xsqlite3_mprintf(tls, __ccgo_ts+37824, 0)
|
|
**(**int32)(__ccgo_up(bp)) = int32(SQLITE_ERROR)
|
|
} else {
|
|
(*TFts5Config)(unsafe.Pointer(pConfig)).FbLocale = libc.BoolInt32(int32(**(**int8)(__ccgo_up(zArg))) == int32('1'))
|
|
}
|
|
return **(**int32)(__ccgo_up(bp))
|
|
}
|
|
if Xsqlite3_strnicmp(tls, __ccgo_ts+5668, zCmd, nCmd) == 0 {
|
|
**(**[4]TFts5Enum)(__ccgo_up(bp + 4)) = [4]TFts5Enum{
|
|
0: {
|
|
FzName: __ccgo_ts + 8510,
|
|
FeVal: int32(FTS5_DETAIL_NONE),
|
|
},
|
|
1: {
|
|
FzName: __ccgo_ts + 19018,
|
|
},
|
|
2: {
|
|
FzName: __ccgo_ts + 37855,
|
|
FeVal: int32(FTS5_DETAIL_COLUMNS),
|
|
},
|
|
3: {},
|
|
}
|
|
v2 = _fts5ConfigSetEnum(tls, bp+4, zArg, pConfig+68)
|
|
**(**int32)(__ccgo_up(bp)) = v2
|
|
if v2 != 0 {
|
|
**(**uintptr)(__ccgo_up(pzErr)) = Xsqlite3_mprintf(tls, __ccgo_ts+37863, 0)
|
|
}
|
|
return **(**int32)(__ccgo_up(bp))
|
|
}
|
|
if Xsqlite3_strnicmp(tls, __ccgo_ts+37894, zCmd, nCmd) == 0 {
|
|
if int32(**(**int8)(__ccgo_up(zArg))) != int32('0') && int32(**(**int8)(__ccgo_up(zArg))) != int32('1') || int32(**(**int8)(__ccgo_up(zArg + 1))) != int32('\000') {
|
|
**(**uintptr)(__ccgo_up(pzErr)) = Xsqlite3_mprintf(tls, __ccgo_ts+37904, 0)
|
|
**(**int32)(__ccgo_up(bp)) = int32(SQLITE_ERROR)
|
|
} else {
|
|
(*TFts5Config)(unsafe.Pointer(pConfig)).FbTokendata = libc.BoolInt32(int32(**(**int8)(__ccgo_up(zArg))) == int32('1'))
|
|
}
|
|
return **(**int32)(__ccgo_up(bp))
|
|
}
|
|
**(**uintptr)(__ccgo_up(pzErr)) = Xsqlite3_mprintf(tls, __ccgo_ts+37938, libc.VaList(bp+48, nCmd, zCmd))
|
|
return int32(SQLITE_ERROR)
|
|
}
|
|
|
|
func _fts5ConfigSkipLiteral(tls *libc.TLS, pIn uintptr) (r uintptr) {
|
|
var p uintptr
|
|
_ = p
|
|
p = pIn
|
|
switch int32(**(**int8)(__ccgo_up(p))) {
|
|
case int32('n'):
|
|
fallthrough
|
|
case int32('N'):
|
|
if Xsqlite3_strnicmp(tls, __ccgo_ts+1688, p, int32(4)) == 0 {
|
|
p = p + 4
|
|
} else {
|
|
p = uintptr(0)
|
|
}
|
|
case int32('x'):
|
|
fallthrough
|
|
case int32('X'):
|
|
p = p + 1
|
|
if int32(**(**int8)(__ccgo_up(p))) == int32('\'') {
|
|
p = p + 1
|
|
for int32(**(**int8)(__ccgo_up(p))) >= int32('a') && int32(**(**int8)(__ccgo_up(p))) <= int32('f') || int32(**(**int8)(__ccgo_up(p))) >= int32('A') && int32(**(**int8)(__ccgo_up(p))) <= int32('F') || int32(**(**int8)(__ccgo_up(p))) >= int32('0') && int32(**(**int8)(__ccgo_up(p))) <= int32('9') {
|
|
p = p + 1
|
|
}
|
|
if int32(**(**int8)(__ccgo_up(p))) == int32('\'') && 0 == (int32(p)-int32(pIn))%int32(2) {
|
|
p = p + 1
|
|
} else {
|
|
p = uintptr(0)
|
|
}
|
|
} else {
|
|
p = uintptr(0)
|
|
}
|
|
case int32('\''):
|
|
p = p + 1
|
|
for p != 0 {
|
|
if int32(**(**int8)(__ccgo_up(p))) == int32('\'') {
|
|
p = p + 1
|
|
if int32(**(**int8)(__ccgo_up(p))) != int32('\'') {
|
|
break
|
|
}
|
|
}
|
|
p = p + 1
|
|
if int32(**(**int8)(__ccgo_up(p))) == 0 {
|
|
p = uintptr(0)
|
|
}
|
|
}
|
|
default:
|
|
/* maybe a number */
|
|
if int32(**(**int8)(__ccgo_up(p))) == int32('+') || int32(**(**int8)(__ccgo_up(p))) == int32('-') {
|
|
p = p + 1
|
|
}
|
|
for _fts5_isdigit(tls, **(**int8)(__ccgo_up(p))) != 0 {
|
|
p = p + 1
|
|
}
|
|
/* At this point, if the literal was an integer, the parse is
|
|
** finished. Or, if it is a floating point value, it may continue
|
|
** with either a decimal point or an 'E' character. */
|
|
if int32(**(**int8)(__ccgo_up(p))) == int32('.') && _fts5_isdigit(tls, **(**int8)(__ccgo_up(p + 1))) != 0 {
|
|
p = p + uintptr(2)
|
|
for _fts5_isdigit(tls, **(**int8)(__ccgo_up(p))) != 0 {
|
|
p = p + 1
|
|
}
|
|
}
|
|
if p == pIn {
|
|
p = uintptr(0)
|
|
}
|
|
break
|
|
}
|
|
return p
|
|
}
|
|
|
|
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.Int64FromUint32(uint32(libc.UintptrFromInt32(0)+16) + libc.Uint32FromInt32((nPhrase+libc.Int32FromInt32(2))/libc.Int32FromInt32(2))*libc.Uint32FromInt64(8))
|
|
pSorter = Xsqlite3_malloc64(tls, libc.Uint64FromInt64(nByte))
|
|
if pSorter == uintptr(0) {
|
|
return int32(SQLITE_NOMEM)
|
|
}
|
|
libc.Xmemset(tls, pSorter, 0, libc.Uint32FromInt64(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 + 16216
|
|
} else {
|
|
v1 = __ccgo_ts + 1702
|
|
}
|
|
if zRankArgs != 0 {
|
|
v2 = zRankArgs
|
|
} else {
|
|
v2 = __ccgo_ts + 1702
|
|
}
|
|
if bDesc != 0 {
|
|
v3 = __ccgo_ts + 39753
|
|
} else {
|
|
v3 = __ccgo_ts + 39758
|
|
}
|
|
rc = _fts5PrepareStatement(tls, pSorter, pConfig, __ccgo_ts+39762, 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+4 */ 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 + 4)) = 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+4)
|
|
}
|
|
if rc == SQLITE_OK {
|
|
(*TFts5Cursor)(unsafe.Pointer(pCsr)).FzRank = **(**uintptr)(__ccgo_up(bp))
|
|
(*TFts5Cursor)(unsafe.Pointer(pCsr)).FzRankArgs = **(**uintptr)(__ccgo_up(bp + 4))
|
|
**(**int32)(__ccgo_up(pCsr + 56)) |= 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+39882, libc.VaList(bp+16, 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 + 37384
|
|
(*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+38997, libc.VaList(bp+8, (*TFts5Config)(unsafe.Pointer(pConfig)).FzDb, (*TFts5Config)(unsafe.Pointer(pConfig)).FzName))
|
|
if _fts5IndexPrepareStmt(tls, p, p+56, 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+38940, iRowid, 0, p+48)
|
|
}
|
|
/* 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.Int64FromUint32((libc.Uint32FromInt64(12) + libc.Uint32FromInt32(7)) & libc.Uint32FromInt32(^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+64, Xsqlite3_mprintf(tls, __ccgo_ts+39046, 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+52, Xsqlite3_mprintf(tls, __ccgo_ts+38946, 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
|
|
//
|
|
// /*
|
|
// ** Read the first token from the nul-terminated string at *pz.
|
|
// */
|
|
func _fts5ExprGetToken(tls *libc.TLS, pParse uintptr, pz uintptr, pToken uintptr) (r int32) {
|
|
bp := tls.Alloc(16)
|
|
defer tls.Free(16)
|
|
var tok int32
|
|
var z, z2, z21 uintptr
|
|
_, _, _, _ = tok, z, z2, z21
|
|
z = **(**uintptr)(__ccgo_up(pz))
|
|
/* Skip past any whitespace */
|
|
for _fts5ExprIsspace(tls, **(**int8)(__ccgo_up(z))) != 0 {
|
|
z = z + 1
|
|
}
|
|
(*TFts5Token)(unsafe.Pointer(pToken)).Fp = z
|
|
(*TFts5Token)(unsafe.Pointer(pToken)).Fn = int32(1)
|
|
switch int32(**(**int8)(__ccgo_up(z))) {
|
|
case int32('('):
|
|
tok = int32(FTS5_LP)
|
|
case int32(')'):
|
|
tok = int32(FTS5_RP)
|
|
case int32('{'):
|
|
tok = int32(FTS5_LCP)
|
|
case int32('}'):
|
|
tok = int32(FTS5_RCP)
|
|
case int32(':'):
|
|
tok = int32(FTS5_COLON)
|
|
case int32(','):
|
|
tok = int32(FTS5_COMMA)
|
|
case int32('+'):
|
|
tok = int32(FTS5_PLUS)
|
|
case int32('*'):
|
|
tok = int32(FTS5_STAR)
|
|
case int32('-'):
|
|
tok = int32(FTS5_MINUS)
|
|
case int32('^'):
|
|
tok = int32(FTS5_CARET)
|
|
case int32('\000'):
|
|
tok = FTS5_EOF
|
|
case int32('"'):
|
|
tok = int32(FTS5_STRING)
|
|
z2 = z + 1
|
|
for {
|
|
if !(int32(1) != 0) {
|
|
break
|
|
}
|
|
if int32(**(**int8)(__ccgo_up(z2))) == int32('"') {
|
|
z2 = z2 + 1
|
|
if int32(**(**int8)(__ccgo_up(z2))) != int32('"') {
|
|
break
|
|
}
|
|
}
|
|
if int32(**(**int8)(__ccgo_up(z2))) == int32('\000') {
|
|
_sqlite3Fts5ParseError(tls, pParse, __ccgo_ts+38545, 0)
|
|
return FTS5_EOF
|
|
}
|
|
goto _1
|
|
_1:
|
|
;
|
|
z2 = z2 + 1
|
|
}
|
|
(*TFts5Token)(unsafe.Pointer(pToken)).Fn = int32(z2) - int32(z)
|
|
default:
|
|
if _sqlite3Fts5IsBareword(tls, **(**int8)(__ccgo_up(z))) == 0 {
|
|
_sqlite3Fts5ParseError(tls, pParse, __ccgo_ts+38565, libc.VaList(bp+8, z))
|
|
return FTS5_EOF
|
|
}
|
|
tok = int32(FTS5_STRING)
|
|
z21 = z + 1
|
|
for {
|
|
if !(_sqlite3Fts5IsBareword(tls, **(**int8)(__ccgo_up(z21))) != 0) {
|
|
break
|
|
}
|
|
goto _2
|
|
_2:
|
|
;
|
|
z21 = z21 + 1
|
|
}
|
|
(*TFts5Token)(unsafe.Pointer(pToken)).Fn = int32(z21) - int32(z)
|
|
if (*TFts5Token)(unsafe.Pointer(pToken)).Fn == int32(2) && libc.Xmemcmp(tls, (*TFts5Token)(unsafe.Pointer(pToken)).Fp, __ccgo_ts+38596, uint32(2)) == 0 {
|
|
tok = int32(FTS5_OR)
|
|
}
|
|
if (*TFts5Token)(unsafe.Pointer(pToken)).Fn == int32(3) && libc.Xmemcmp(tls, (*TFts5Token)(unsafe.Pointer(pToken)).Fp, __ccgo_ts+38599, uint32(3)) == 0 {
|
|
tok = int32(FTS5_NOT)
|
|
}
|
|
if (*TFts5Token)(unsafe.Pointer(pToken)).Fn == int32(3) && libc.Xmemcmp(tls, (*TFts5Token)(unsafe.Pointer(pToken)).Fp, __ccgo_ts+32406, uint32(3)) == 0 {
|
|
tok = int32(FTS5_AND)
|
|
}
|
|
break
|
|
}
|
|
**(**uintptr)(__ccgo_up(pz)) = (*TFts5Token)(unsafe.Pointer(pToken)).Fp + uintptr((*TFts5Token)(unsafe.Pointer(pToken)).Fn)
|
|
return tok
|
|
}
|
|
|
|
// C documentation
|
|
//
|
|
// /*
|
|
// ** This is the xFilter interface for the virtual table. See
|
|
// ** the virtual table xFilter method documentation for additional
|
|
// ** information.
|
|
// **
|
|
// ** There are three possible query strategies:
|
|
// **
|
|
// ** 1. Full-text search using a MATCH operator.
|
|
// ** 2. A by-rowid lookup.
|
|
// ** 3. A full-table scan.
|
|
// */
|
|
func _fts5FilterMethod(tls *libc.TLS, pCursor uintptr, idxNum int32, idxStr uintptr, nVal int32, apVal uintptr) (r int32) {
|
|
bp := tls.Alloc(32)
|
|
defer tls.Free(32)
|
|
var bDesc, bGlob, bInternal, bOrderByRank, bPrefixInsttoken, i, iCol, iIdxStr, rc, v2, v3 int32
|
|
var pConfig, pCsr, pRank, pRowidEq, pRowidGe, pRowidLe, pTab, pzErr, pzErrmsg, zText1, v6 uintptr
|
|
var _ /* bFreeAndReset at bp+8 */ int32
|
|
var _ /* pExpr at bp+0 */ uintptr
|
|
var _ /* zText at bp+4 */ uintptr
|
|
_, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _ = bDesc, bGlob, bInternal, bOrderByRank, bPrefixInsttoken, i, iCol, iIdxStr, pConfig, pCsr, pRank, pRowidEq, pRowidGe, pRowidLe, pTab, pzErr, pzErrmsg, rc, zText1, v2, v3, v6
|
|
pTab = (*Tsqlite3_vtab_cursor)(unsafe.Pointer(pCursor)).FpVtab
|
|
pConfig = (*TFts5FullTable)(unsafe.Pointer(pTab)).Fp.FpConfig
|
|
pCsr = pCursor
|
|
rc = SQLITE_OK /* True if ORDER BY rank */
|
|
pRank = uintptr(0) /* rank MATCH ? expression (or NULL) */
|
|
pRowidEq = uintptr(0) /* rowid = ? expression (or NULL) */
|
|
pRowidLe = uintptr(0) /* rowid <= ? expression (or NULL) */
|
|
pRowidGe = uintptr(0) /* Column on LHS of MATCH operator */
|
|
pzErrmsg = (*TFts5Config)(unsafe.Pointer(pConfig)).FpzErrmsg
|
|
bPrefixInsttoken = (*TFts5Config)(unsafe.Pointer(pConfig)).FbPrefixInsttoken
|
|
iIdxStr = 0
|
|
**(**uintptr)(__ccgo_up(bp)) = uintptr(0)
|
|
if (*TFts5Cursor)(unsafe.Pointer(pCsr)).FePlan != 0 {
|
|
_fts5FreeCursorComponents(tls, pCsr)
|
|
libc.Xmemset(tls, pCsr+20, 0, uint32(116)-libc.Uint32FromInt32(int32(pCsr+20)-int32(pCsr)))
|
|
}
|
|
(*TFts5Config)(unsafe.Pointer(pConfig)).FpzErrmsg = pTab + 8
|
|
/* Decode the arguments passed through to this function. */
|
|
i = 0
|
|
for {
|
|
if !(i < nVal) {
|
|
break
|
|
}
|
|
v2 = iIdxStr
|
|
iIdxStr = iIdxStr + 1
|
|
switch int32(**(**int8)(__ccgo_up(idxStr + uintptr(v2)))) {
|
|
case int32('r'):
|
|
pRank = **(**uintptr)(__ccgo_up(apVal + uintptr(i)*4))
|
|
case int32('M'):
|
|
**(**uintptr)(__ccgo_up(bp + 4)) = uintptr(0)
|
|
**(**int32)(__ccgo_up(bp + 8)) = 0
|
|
bInternal = 0
|
|
rc = _fts5ExtractExprText(tls, pConfig, **(**uintptr)(__ccgo_up(apVal + uintptr(i)*4)), bp+4, bp+8)
|
|
if rc != SQLITE_OK {
|
|
goto filter_out
|
|
}
|
|
if **(**uintptr)(__ccgo_up(bp + 4)) == uintptr(0) {
|
|
**(**uintptr)(__ccgo_up(bp + 4)) = __ccgo_ts + 1702
|
|
}
|
|
if Xsqlite3_value_subtype(tls, **(**uintptr)(__ccgo_up(apVal + uintptr(i)*4))) == uint32(FTS5_INSTTOKEN_SUBTYPE) {
|
|
(*TFts5Config)(unsafe.Pointer(pConfig)).FbPrefixInsttoken = int32(1)
|
|
}
|
|
iCol = 0
|
|
for cond := true; cond; cond = int32(**(**int8)(__ccgo_up(idxStr + uintptr(iIdxStr)))) >= int32('0') && int32(**(**int8)(__ccgo_up(idxStr + uintptr(iIdxStr)))) <= int32('9') {
|
|
iCol = iCol*int32(10) + (int32(**(**int8)(__ccgo_up(idxStr + uintptr(iIdxStr)))) - int32('0'))
|
|
iIdxStr = iIdxStr + 1
|
|
}
|
|
if int32(**(**int8)(__ccgo_up(**(**uintptr)(__ccgo_up(bp + 4))))) == int32('*') {
|
|
/* The user has issued a query of the form "MATCH '*...'". This
|
|
** indicates that the MATCH expression is not a full text query,
|
|
** but a request for an internal parameter. */
|
|
rc = _fts5SpecialMatch(tls, pTab, pCsr, **(**uintptr)(__ccgo_up(bp + 4))+1)
|
|
bInternal = int32(1)
|
|
} else {
|
|
pzErr = pTab + 8
|
|
rc = _sqlite3Fts5ExprNew(tls, pConfig, 0, iCol, **(**uintptr)(__ccgo_up(bp + 4)), bp, pzErr)
|
|
if rc == SQLITE_OK {
|
|
rc = _sqlite3Fts5ExprAnd(tls, pCsr+48, **(**uintptr)(__ccgo_up(bp)))
|
|
**(**uintptr)(__ccgo_up(bp)) = uintptr(0)
|
|
}
|
|
}
|
|
if **(**int32)(__ccgo_up(bp + 8)) != 0 {
|
|
Xsqlite3_free(tls, **(**uintptr)(__ccgo_up(bp + 4)))
|
|
_sqlite3Fts5ClearLocale(tls, pConfig)
|
|
}
|
|
if bInternal != 0 || rc != SQLITE_OK {
|
|
goto filter_out
|
|
}
|
|
case int32('L'):
|
|
fallthrough
|
|
case int32('G'):
|
|
bGlob = libc.BoolInt32(int32(**(**int8)(__ccgo_up(idxStr + uintptr(iIdxStr-int32(1))))) == int32('G'))
|
|
zText1 = Xsqlite3_value_text(tls, **(**uintptr)(__ccgo_up(apVal + uintptr(i)*4)))
|
|
iCol = 0
|
|
for cond := true; cond; cond = int32(**(**int8)(__ccgo_up(idxStr + uintptr(iIdxStr)))) >= int32('0') && int32(**(**int8)(__ccgo_up(idxStr + uintptr(iIdxStr)))) <= int32('9') {
|
|
iCol = iCol*int32(10) + (int32(**(**int8)(__ccgo_up(idxStr + uintptr(iIdxStr)))) - int32('0'))
|
|
iIdxStr = iIdxStr + 1
|
|
}
|
|
if zText1 != 0 {
|
|
rc = _sqlite3Fts5ExprPattern(tls, pConfig, bGlob, iCol, zText1, bp)
|
|
}
|
|
if rc == SQLITE_OK {
|
|
rc = _sqlite3Fts5ExprAnd(tls, pCsr+48, **(**uintptr)(__ccgo_up(bp)))
|
|
**(**uintptr)(__ccgo_up(bp)) = uintptr(0)
|
|
}
|
|
if rc != SQLITE_OK {
|
|
goto filter_out
|
|
}
|
|
case int32('='):
|
|
pRowidEq = **(**uintptr)(__ccgo_up(apVal + uintptr(i)*4))
|
|
case int32('<'):
|
|
pRowidLe = **(**uintptr)(__ccgo_up(apVal + uintptr(i)*4))
|
|
default:
|
|
pRowidGe = **(**uintptr)(__ccgo_up(apVal + uintptr(i)*4))
|
|
break
|
|
}
|
|
goto _1
|
|
_1:
|
|
;
|
|
i = i + 1
|
|
}
|
|
if idxNum&int32(FTS5_BI_ORDER_RANK) != 0 {
|
|
v2 = int32(1)
|
|
} else {
|
|
v2 = 0
|
|
}
|
|
bOrderByRank = v2
|
|
if idxNum&int32(FTS5_BI_ORDER_DESC) != 0 {
|
|
v3 = int32(1)
|
|
} else {
|
|
v3 = 0
|
|
}
|
|
v2 = v3
|
|
bDesc = v2
|
|
(*TFts5Cursor)(unsafe.Pointer(pCsr)).FbDesc = v2
|
|
/* Set the cursor upper and lower rowid limits. Only some strategies
|
|
** actually use them. This is ok, as the xBestIndex() method leaves the
|
|
** sqlite3_index_constraint.omit flag clear for range constraints
|
|
** on the rowid field. */
|
|
if pRowidEq != 0 {
|
|
v6 = pRowidEq
|
|
pRowidGe = v6
|
|
pRowidLe = v6
|
|
}
|
|
if bDesc != 0 {
|
|
(*TFts5Cursor)(unsafe.Pointer(pCsr)).FiFirstRowid = _fts5GetRowidLimit(tls, pRowidLe, libc.Int64FromUint32(0xffffffff)|libc.Int64FromInt32(0x7fffffff)<<libc.Int32FromInt32(32))
|
|
(*TFts5Cursor)(unsafe.Pointer(pCsr)).FiLastRowid = _fts5GetRowidLimit(tls, pRowidGe, int64(-libc.Int32FromInt32(1))-(libc.Int64FromUint32(0xffffffff)|libc.Int64FromInt32(0x7fffffff)<<libc.Int32FromInt32(32)))
|
|
} else {
|
|
(*TFts5Cursor)(unsafe.Pointer(pCsr)).FiLastRowid = _fts5GetRowidLimit(tls, pRowidLe, libc.Int64FromUint32(0xffffffff)|libc.Int64FromInt32(0x7fffffff)<<libc.Int32FromInt32(32))
|
|
(*TFts5Cursor)(unsafe.Pointer(pCsr)).FiFirstRowid = _fts5GetRowidLimit(tls, pRowidGe, int64(-libc.Int32FromInt32(1))-(libc.Int64FromUint32(0xffffffff)|libc.Int64FromInt32(0x7fffffff)<<libc.Int32FromInt32(32)))
|
|
}
|
|
rc = _sqlite3Fts5IndexLoadConfig(tls, (*TFts5FullTable)(unsafe.Pointer(pTab)).Fp.FpIndex)
|
|
if rc != SQLITE_OK {
|
|
goto filter_out
|
|
}
|
|
if (*TFts5FullTable)(unsafe.Pointer(pTab)).FpSortCsr != 0 {
|
|
/* If pSortCsr is non-NULL, then this call is being made as part of
|
|
** processing for a "... MATCH <expr> ORDER BY rank" query (ePlan is
|
|
** set to FTS5_PLAN_SORTED_MATCH). pSortCsr is the cursor that will
|
|
** return results to the user for this query. The current cursor
|
|
** (pCursor) is used to execute the query issued by function
|
|
** fts5CursorFirstSorted() above. */
|
|
if (*TFts5Cursor)(unsafe.Pointer((*TFts5FullTable)(unsafe.Pointer(pTab)).FpSortCsr)).FbDesc != 0 {
|
|
(*TFts5Cursor)(unsafe.Pointer(pCsr)).FiLastRowid = (*TFts5Cursor)(unsafe.Pointer((*TFts5FullTable)(unsafe.Pointer(pTab)).FpSortCsr)).FiFirstRowid
|
|
(*TFts5Cursor)(unsafe.Pointer(pCsr)).FiFirstRowid = (*TFts5Cursor)(unsafe.Pointer((*TFts5FullTable)(unsafe.Pointer(pTab)).FpSortCsr)).FiLastRowid
|
|
} else {
|
|
(*TFts5Cursor)(unsafe.Pointer(pCsr)).FiLastRowid = (*TFts5Cursor)(unsafe.Pointer((*TFts5FullTable)(unsafe.Pointer(pTab)).FpSortCsr)).FiLastRowid
|
|
(*TFts5Cursor)(unsafe.Pointer(pCsr)).FiFirstRowid = (*TFts5Cursor)(unsafe.Pointer((*TFts5FullTable)(unsafe.Pointer(pTab)).FpSortCsr)).FiFirstRowid
|
|
}
|
|
(*TFts5Cursor)(unsafe.Pointer(pCsr)).FePlan = int32(FTS5_PLAN_SOURCE)
|
|
(*TFts5Cursor)(unsafe.Pointer(pCsr)).FpExpr = (*TFts5Cursor)(unsafe.Pointer((*TFts5FullTable)(unsafe.Pointer(pTab)).FpSortCsr)).FpExpr
|
|
rc = _fts5CursorFirst(tls, pTab, pCsr, bDesc)
|
|
} else {
|
|
if (*TFts5Cursor)(unsafe.Pointer(pCsr)).FpExpr != 0 {
|
|
rc = _fts5CursorParseRank(tls, pConfig, pCsr, pRank)
|
|
if rc == SQLITE_OK {
|
|
if bOrderByRank != 0 {
|
|
(*TFts5Cursor)(unsafe.Pointer(pCsr)).FePlan = int32(FTS5_PLAN_SORTED_MATCH)
|
|
rc = _fts5CursorFirstSorted(tls, pTab, pCsr, bDesc)
|
|
} else {
|
|
(*TFts5Cursor)(unsafe.Pointer(pCsr)).FePlan = int32(FTS5_PLAN_MATCH)
|
|
rc = _fts5CursorFirst(tls, pTab, pCsr, bDesc)
|
|
}
|
|
}
|
|
} else {
|
|
if (*TFts5Config)(unsafe.Pointer(pConfig)).FzContent == uintptr(0) {
|
|
_fts5SetVtabError(tls, pTab, __ccgo_ts+39915, libc.VaList(bp+24, (*TFts5Config)(unsafe.Pointer(pConfig)).FzName))
|
|
rc = int32(SQLITE_ERROR)
|
|
} else {
|
|
/* This is either a full-table scan (ePlan==FTS5_PLAN_SCAN) or a lookup
|
|
** by rowid (ePlan==FTS5_PLAN_ROWID). */
|
|
if pRowidEq != 0 {
|
|
v2 = int32(FTS5_PLAN_ROWID)
|
|
} else {
|
|
v2 = int32(FTS5_PLAN_SCAN)
|
|
}
|
|
(*TFts5Cursor)(unsafe.Pointer(pCsr)).FePlan = v2
|
|
rc = _sqlite3Fts5StorageStmt(tls, (*TFts5FullTable)(unsafe.Pointer(pTab)).FpStorage, _fts5StmtType(tls, pCsr), pCsr+44, pTab+8)
|
|
if rc == SQLITE_OK {
|
|
if pRowidEq != uintptr(0) {
|
|
Xsqlite3_bind_value(tls, (*TFts5Cursor)(unsafe.Pointer(pCsr)).FpStmt, int32(1), pRowidEq)
|
|
} else {
|
|
Xsqlite3_bind_int64(tls, (*TFts5Cursor)(unsafe.Pointer(pCsr)).FpStmt, int32(1), (*TFts5Cursor)(unsafe.Pointer(pCsr)).FiFirstRowid)
|
|
Xsqlite3_bind_int64(tls, (*TFts5Cursor)(unsafe.Pointer(pCsr)).FpStmt, int32(2), (*TFts5Cursor)(unsafe.Pointer(pCsr)).FiLastRowid)
|
|
}
|
|
rc = _fts5NextMethod(tls, pCursor)
|
|
}
|
|
}
|
|
}
|
|
}
|
|
goto filter_out
|
|
filter_out:
|
|
;
|
|
_sqlite3Fts5ExprFree(tls, **(**uintptr)(__ccgo_up(bp)))
|
|
(*TFts5Config)(unsafe.Pointer(pConfig)).FpzErrmsg = pzErrmsg
|
|
(*TFts5Config)(unsafe.Pointer(pConfig)).FbPrefixInsttoken = bPrefixInsttoken
|
|
return rc
|
|
}
|
|
|
|
// 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+4 */ 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 + 4)) = uintptr(0)
|
|
_fts5IndexPrepareStmt(tls, p, bp+4, Xsqlite3_mprintf(tls, __ccgo_ts+39444, libc.VaList(bp+16, (*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 + 4)))
|
|
rc = Xsqlite3_finalize(tls, **(**uintptr)(__ccgo_up(bp + 4)))
|
|
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)) + 72 + uintptr((**(**TFts5CResult)(__ccgo_up((*TFts5Iter)(unsafe.Pointer(**(**uintptr)(__ccgo_up(bp)))).FaFirst + 1*4))).FiFirst)*96
|
|
_fts5DoSecureDelete(tls, p, pSeg)
|
|
}
|
|
}
|
|
_fts5MultiIterFree(tls, **(**uintptr)(__ccgo_up(bp)))
|
|
return (*TFts5Index)(unsafe.Pointer(p)).Frc
|
|
}
|
|
|
|
// 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+72, Xsqlite3_mprintf(tls, __ccgo_ts+39244, 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+68, Xsqlite3_mprintf(tls, __ccgo_ts+39160, libc.VaList(bp+8, (*TFts5Config)(unsafe.Pointer(pConfig)).FzDb, (*TFts5Config)(unsafe.Pointer(pConfig)).FzName)))
|
|
}
|
|
return (*TFts5Index)(unsafe.Pointer(p)).FpIdxSelect
|
|
}
|
|
|
|
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+84, Xsqlite3_mprintf(tls, __ccgo_ts+39137, 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 _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(68))
|
|
if pGlobal == uintptr(0) {
|
|
rc = int32(SQLITE_NOMEM)
|
|
} else {
|
|
p = pGlobal
|
|
libc.Xmemset(tls, pGlobal, 0, uint32(68))
|
|
(*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+52)
|
|
**(**Tu32)(__ccgo_up(pGlobal + 52)) ^= uint32(0xF924976D)
|
|
**(**Tu32)(__ccgo_up(pGlobal + 52 + 1*4)) ^= uint32(0x16596E13)
|
|
**(**Tu32)(__ccgo_up(pGlobal + 52 + 2*4)) ^= uint32(0x7C80BEAA)
|
|
**(**Tu32)(__ccgo_up(pGlobal + 52 + 3*4)) ^= uint32(0x9B03A67F)
|
|
rc = Xsqlite3_create_module_v2(tls, db, __ccgo_ts+40714, 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+40714, 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+40719, 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+40734, 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+40746, 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
|
|
//
|
|
// /*
|
|
// ** 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 + 56)) |= _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 + 56)) |= 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 + 56)) |= 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+3942, libc.VaList(bp+16, Xsqlite3_errmsg(tls, (*TFts5Config)(unsafe.Pointer(pConfig)).Fdb)))
|
|
}
|
|
} else {
|
|
rc = SQLITE_OK
|
|
**(**int32)(__ccgo_up(pCsr + 56)) |= int32(FTS5CSR_REQUIRE_DOCSIZE)
|
|
}
|
|
break
|
|
}
|
|
}
|
|
return rc
|
|
}
|
|
|
|
func _fts5PorterStep1B(tls *libc.TLS, aBuf uintptr, pnBuf uintptr) (r int32) {
|
|
var nBuf, ret int32
|
|
_, _ = nBuf, ret
|
|
ret = 0
|
|
nBuf = **(**int32)(__ccgo_up(pnBuf))
|
|
switch int32(**(**int8)(__ccgo_up(aBuf + uintptr(nBuf-int32(2))))) {
|
|
case int32('e'):
|
|
if nBuf > int32(3) && 0 == libc.Xmemcmp(tls, __ccgo_ts+42174, aBuf+uintptr(nBuf-int32(3)), uint32(3)) {
|
|
if _fts5Porter_MGt0(tls, aBuf, nBuf-int32(3)) != 0 {
|
|
libc.Xmemcpy(tls, aBuf+uintptr(nBuf-int32(3)), __ccgo_ts+42178, uint32(2))
|
|
**(**int32)(__ccgo_up(pnBuf)) = nBuf - int32(3) + int32(2)
|
|
}
|
|
} else {
|
|
if nBuf > int32(2) && 0 == libc.Xmemcmp(tls, __ccgo_ts+42181, aBuf+uintptr(nBuf-int32(2)), uint32(2)) {
|
|
if _fts5Porter_Vowel(tls, aBuf, nBuf-int32(2)) != 0 {
|
|
**(**int32)(__ccgo_up(pnBuf)) = nBuf - int32(2)
|
|
ret = int32(1)
|
|
}
|
|
}
|
|
}
|
|
case int32('n'):
|
|
if nBuf > int32(3) && 0 == libc.Xmemcmp(tls, __ccgo_ts+42184, aBuf+uintptr(nBuf-int32(3)), uint32(3)) {
|
|
if _fts5Porter_Vowel(tls, aBuf, nBuf-int32(3)) != 0 {
|
|
**(**int32)(__ccgo_up(pnBuf)) = nBuf - int32(3)
|
|
ret = int32(1)
|
|
}
|
|
}
|
|
break
|
|
}
|
|
return ret
|
|
}
|
|
|
|
/*
|
|
** GENERATED CODE ENDS HERE (mkportersteps.tcl)
|
|
***************************************************************************
|
|
**************************************************************************/
|
|
|
|
func _fts5PorterStep1B2(tls *libc.TLS, aBuf uintptr, pnBuf uintptr) (r int32) {
|
|
var nBuf, ret int32
|
|
_, _ = nBuf, ret
|
|
ret = 0
|
|
nBuf = **(**int32)(__ccgo_up(pnBuf))
|
|
switch int32(**(**int8)(__ccgo_up(aBuf + uintptr(nBuf-int32(2))))) {
|
|
case int32('a'):
|
|
if nBuf > int32(2) && 0 == libc.Xmemcmp(tls, __ccgo_ts+41988, aBuf+uintptr(nBuf-int32(2)), uint32(2)) {
|
|
libc.Xmemcpy(tls, aBuf+uintptr(nBuf-int32(2)), __ccgo_ts+41968, uint32(3))
|
|
**(**int32)(__ccgo_up(pnBuf)) = nBuf - int32(2) + int32(3)
|
|
ret = int32(1)
|
|
}
|
|
case int32('b'):
|
|
if nBuf > int32(2) && 0 == libc.Xmemcmp(tls, __ccgo_ts+41991, aBuf+uintptr(nBuf-int32(2)), uint32(2)) {
|
|
libc.Xmemcpy(tls, aBuf+uintptr(nBuf-int32(2)), __ccgo_ts+41994, uint32(3))
|
|
**(**int32)(__ccgo_up(pnBuf)) = nBuf - int32(2) + int32(3)
|
|
ret = int32(1)
|
|
}
|
|
case int32('i'):
|
|
if nBuf > int32(2) && 0 == libc.Xmemcmp(tls, __ccgo_ts+41998, aBuf+uintptr(nBuf-int32(2)), uint32(2)) {
|
|
libc.Xmemcpy(tls, aBuf+uintptr(nBuf-int32(2)), __ccgo_ts+41984, uint32(3))
|
|
**(**int32)(__ccgo_up(pnBuf)) = nBuf - int32(2) + int32(3)
|
|
ret = int32(1)
|
|
}
|
|
break
|
|
}
|
|
return ret
|
|
}
|
|
|
|
func _fts5PorterStep2(tls *libc.TLS, aBuf uintptr, pnBuf uintptr) (r int32) {
|
|
var nBuf, ret int32
|
|
_, _ = nBuf, ret
|
|
ret = 0
|
|
nBuf = **(**int32)(__ccgo_up(pnBuf))
|
|
switch int32(**(**int8)(__ccgo_up(aBuf + uintptr(nBuf-int32(2))))) {
|
|
case int32('a'):
|
|
if nBuf > int32(7) && 0 == libc.Xmemcmp(tls, __ccgo_ts+42001, aBuf+uintptr(nBuf-int32(7)), uint32(7)) {
|
|
if _fts5Porter_MGt0(tls, aBuf, nBuf-int32(7)) != 0 {
|
|
libc.Xmemcpy(tls, aBuf+uintptr(nBuf-int32(7)), __ccgo_ts+41968, uint32(3))
|
|
**(**int32)(__ccgo_up(pnBuf)) = nBuf - int32(7) + int32(3)
|
|
}
|
|
} else {
|
|
if nBuf > int32(6) && 0 == libc.Xmemcmp(tls, __ccgo_ts+42009, aBuf+uintptr(nBuf-int32(6)), uint32(6)) {
|
|
if _fts5Porter_MGt0(tls, aBuf, nBuf-int32(6)) != 0 {
|
|
libc.Xmemcpy(tls, aBuf+uintptr(nBuf-int32(6)), __ccgo_ts+42016, uint32(4))
|
|
**(**int32)(__ccgo_up(pnBuf)) = nBuf - int32(6) + int32(4)
|
|
}
|
|
}
|
|
}
|
|
case int32('c'):
|
|
if nBuf > int32(4) && 0 == libc.Xmemcmp(tls, __ccgo_ts+42021, aBuf+uintptr(nBuf-int32(4)), uint32(4)) {
|
|
if _fts5Porter_MGt0(tls, aBuf, nBuf-int32(4)) != 0 {
|
|
libc.Xmemcpy(tls, aBuf+uintptr(nBuf-int32(4)), __ccgo_ts+41917, uint32(4))
|
|
**(**int32)(__ccgo_up(pnBuf)) = nBuf - int32(4) + int32(4)
|
|
}
|
|
} else {
|
|
if nBuf > int32(4) && 0 == libc.Xmemcmp(tls, __ccgo_ts+42026, aBuf+uintptr(nBuf-int32(4)), uint32(4)) {
|
|
if _fts5Porter_MGt0(tls, aBuf, nBuf-int32(4)) != 0 {
|
|
libc.Xmemcpy(tls, aBuf+uintptr(nBuf-int32(4)), __ccgo_ts+41912, uint32(4))
|
|
**(**int32)(__ccgo_up(pnBuf)) = nBuf - int32(4) + int32(4)
|
|
}
|
|
}
|
|
}
|
|
case int32('e'):
|
|
if nBuf > int32(4) && 0 == libc.Xmemcmp(tls, __ccgo_ts+42031, aBuf+uintptr(nBuf-int32(4)), uint32(4)) {
|
|
if _fts5Porter_MGt0(tls, aBuf, nBuf-int32(4)) != 0 {
|
|
libc.Xmemcpy(tls, aBuf+uintptr(nBuf-int32(4)), __ccgo_ts+41984, uint32(3))
|
|
**(**int32)(__ccgo_up(pnBuf)) = nBuf - int32(4) + int32(3)
|
|
}
|
|
}
|
|
case int32('g'):
|
|
if nBuf > int32(4) && 0 == libc.Xmemcmp(tls, __ccgo_ts+42036, aBuf+uintptr(nBuf-int32(4)), uint32(4)) {
|
|
if _fts5Porter_MGt0(tls, aBuf, nBuf-int32(4)) != 0 {
|
|
libc.Xmemcpy(tls, aBuf+uintptr(nBuf-int32(4)), __ccgo_ts+17167, uint32(3))
|
|
**(**int32)(__ccgo_up(pnBuf)) = nBuf - int32(4) + int32(3)
|
|
}
|
|
}
|
|
case int32('l'):
|
|
if nBuf > int32(3) && 0 == libc.Xmemcmp(tls, __ccgo_ts+42041, aBuf+uintptr(nBuf-int32(3)), uint32(3)) {
|
|
if _fts5Porter_MGt0(tls, aBuf, nBuf-int32(3)) != 0 {
|
|
libc.Xmemcpy(tls, aBuf+uintptr(nBuf-int32(3)), __ccgo_ts+41994, uint32(3))
|
|
**(**int32)(__ccgo_up(pnBuf)) = nBuf - int32(3) + int32(3)
|
|
}
|
|
} else {
|
|
if nBuf > int32(4) && 0 == libc.Xmemcmp(tls, __ccgo_ts+42045, aBuf+uintptr(nBuf-int32(4)), uint32(4)) {
|
|
if _fts5Porter_MGt0(tls, aBuf, nBuf-int32(4)) != 0 {
|
|
libc.Xmemcpy(tls, aBuf+uintptr(nBuf-int32(4)), __ccgo_ts+41909, uint32(2))
|
|
**(**int32)(__ccgo_up(pnBuf)) = nBuf - int32(4) + int32(2)
|
|
}
|
|
} else {
|
|
if nBuf > int32(5) && 0 == libc.Xmemcmp(tls, __ccgo_ts+42050, aBuf+uintptr(nBuf-int32(5)), uint32(5)) {
|
|
if _fts5Porter_MGt0(tls, aBuf, nBuf-int32(5)) != 0 {
|
|
libc.Xmemcpy(tls, aBuf+uintptr(nBuf-int32(5)), __ccgo_ts+41953, uint32(3))
|
|
**(**int32)(__ccgo_up(pnBuf)) = nBuf - int32(5) + int32(3)
|
|
}
|
|
} else {
|
|
if nBuf > int32(3) && 0 == libc.Xmemcmp(tls, __ccgo_ts+42056, aBuf+uintptr(nBuf-int32(3)), uint32(3)) {
|
|
if _fts5Porter_MGt0(tls, aBuf, nBuf-int32(3)) != 0 {
|
|
libc.Xmemcpy(tls, aBuf+uintptr(nBuf-int32(3)), __ccgo_ts+42060, uint32(1))
|
|
**(**int32)(__ccgo_up(pnBuf)) = nBuf - int32(3) + int32(1)
|
|
}
|
|
} else {
|
|
if nBuf > int32(5) && 0 == libc.Xmemcmp(tls, __ccgo_ts+42062, aBuf+uintptr(nBuf-int32(5)), uint32(5)) {
|
|
if _fts5Porter_MGt0(tls, aBuf, nBuf-int32(5)) != 0 {
|
|
libc.Xmemcpy(tls, aBuf+uintptr(nBuf-int32(5)), __ccgo_ts+41976, uint32(3))
|
|
**(**int32)(__ccgo_up(pnBuf)) = nBuf - int32(5) + int32(3)
|
|
}
|
|
}
|
|
}
|
|
}
|
|
}
|
|
}
|
|
case int32('o'):
|
|
if nBuf > int32(7) && 0 == libc.Xmemcmp(tls, __ccgo_ts+42068, aBuf+uintptr(nBuf-int32(7)), uint32(7)) {
|
|
if _fts5Porter_MGt0(tls, aBuf, nBuf-int32(7)) != 0 {
|
|
libc.Xmemcpy(tls, aBuf+uintptr(nBuf-int32(7)), __ccgo_ts+41984, uint32(3))
|
|
**(**int32)(__ccgo_up(pnBuf)) = nBuf - int32(7) + int32(3)
|
|
}
|
|
} else {
|
|
if nBuf > int32(5) && 0 == libc.Xmemcmp(tls, __ccgo_ts+42076, aBuf+uintptr(nBuf-int32(5)), uint32(5)) {
|
|
if _fts5Porter_MGt0(tls, aBuf, nBuf-int32(5)) != 0 {
|
|
libc.Xmemcpy(tls, aBuf+uintptr(nBuf-int32(5)), __ccgo_ts+41968, uint32(3))
|
|
**(**int32)(__ccgo_up(pnBuf)) = nBuf - int32(5) + int32(3)
|
|
}
|
|
} else {
|
|
if nBuf > int32(4) && 0 == libc.Xmemcmp(tls, __ccgo_ts+42082, aBuf+uintptr(nBuf-int32(4)), uint32(4)) {
|
|
if _fts5Porter_MGt0(tls, aBuf, nBuf-int32(4)) != 0 {
|
|
libc.Xmemcpy(tls, aBuf+uintptr(nBuf-int32(4)), __ccgo_ts+41968, uint32(3))
|
|
**(**int32)(__ccgo_up(pnBuf)) = nBuf - int32(4) + int32(3)
|
|
}
|
|
}
|
|
}
|
|
}
|
|
case int32('s'):
|
|
if nBuf > int32(5) && 0 == libc.Xmemcmp(tls, __ccgo_ts+42087, aBuf+uintptr(nBuf-int32(5)), uint32(5)) {
|
|
if _fts5Porter_MGt0(tls, aBuf, nBuf-int32(5)) != 0 {
|
|
libc.Xmemcpy(tls, aBuf+uintptr(nBuf-int32(5)), __ccgo_ts+41909, uint32(2))
|
|
**(**int32)(__ccgo_up(pnBuf)) = nBuf - int32(5) + int32(2)
|
|
}
|
|
} else {
|
|
if nBuf > int32(7) && 0 == libc.Xmemcmp(tls, __ccgo_ts+42093, aBuf+uintptr(nBuf-int32(7)), uint32(7)) {
|
|
if _fts5Porter_MGt0(tls, aBuf, nBuf-int32(7)) != 0 {
|
|
libc.Xmemcpy(tls, aBuf+uintptr(nBuf-int32(7)), __ccgo_ts+41980, uint32(3))
|
|
**(**int32)(__ccgo_up(pnBuf)) = nBuf - int32(7) + int32(3)
|
|
}
|
|
} else {
|
|
if nBuf > int32(7) && 0 == libc.Xmemcmp(tls, __ccgo_ts+42101, aBuf+uintptr(nBuf-int32(7)), uint32(7)) {
|
|
if _fts5Porter_MGt0(tls, aBuf, nBuf-int32(7)) != 0 {
|
|
libc.Xmemcpy(tls, aBuf+uintptr(nBuf-int32(7)), __ccgo_ts+42109, uint32(3))
|
|
**(**int32)(__ccgo_up(pnBuf)) = nBuf - int32(7) + int32(3)
|
|
}
|
|
} else {
|
|
if nBuf > int32(7) && 0 == libc.Xmemcmp(tls, __ccgo_ts+42113, aBuf+uintptr(nBuf-int32(7)), uint32(7)) {
|
|
if _fts5Porter_MGt0(tls, aBuf, nBuf-int32(7)) != 0 {
|
|
libc.Xmemcpy(tls, aBuf+uintptr(nBuf-int32(7)), __ccgo_ts+41976, uint32(3))
|
|
**(**int32)(__ccgo_up(pnBuf)) = nBuf - int32(7) + int32(3)
|
|
}
|
|
}
|
|
}
|
|
}
|
|
}
|
|
case int32('t'):
|
|
if nBuf > int32(5) && 0 == libc.Xmemcmp(tls, __ccgo_ts+42121, aBuf+uintptr(nBuf-int32(5)), uint32(5)) {
|
|
if _fts5Porter_MGt0(tls, aBuf, nBuf-int32(5)) != 0 {
|
|
libc.Xmemcpy(tls, aBuf+uintptr(nBuf-int32(5)), __ccgo_ts+41909, uint32(2))
|
|
**(**int32)(__ccgo_up(pnBuf)) = nBuf - int32(5) + int32(2)
|
|
}
|
|
} else {
|
|
if nBuf > int32(5) && 0 == libc.Xmemcmp(tls, __ccgo_ts+42127, aBuf+uintptr(nBuf-int32(5)), uint32(5)) {
|
|
if _fts5Porter_MGt0(tls, aBuf, nBuf-int32(5)) != 0 {
|
|
libc.Xmemcpy(tls, aBuf+uintptr(nBuf-int32(5)), __ccgo_ts+41980, uint32(3))
|
|
**(**int32)(__ccgo_up(pnBuf)) = nBuf - int32(5) + int32(3)
|
|
}
|
|
} else {
|
|
if nBuf > int32(6) && 0 == libc.Xmemcmp(tls, __ccgo_ts+42133, aBuf+uintptr(nBuf-int32(6)), uint32(6)) {
|
|
if _fts5Porter_MGt0(tls, aBuf, nBuf-int32(6)) != 0 {
|
|
libc.Xmemcpy(tls, aBuf+uintptr(nBuf-int32(6)), __ccgo_ts+41994, uint32(3))
|
|
**(**int32)(__ccgo_up(pnBuf)) = nBuf - int32(6) + int32(3)
|
|
}
|
|
}
|
|
}
|
|
}
|
|
break
|
|
}
|
|
return ret
|
|
}
|
|
|
|
func _fts5PorterStep3(tls *libc.TLS, aBuf uintptr, pnBuf uintptr) (r int32) {
|
|
var nBuf, ret int32
|
|
_, _ = nBuf, ret
|
|
ret = 0
|
|
nBuf = **(**int32)(__ccgo_up(pnBuf))
|
|
switch int32(**(**int8)(__ccgo_up(aBuf + uintptr(nBuf-int32(2))))) {
|
|
case int32('a'):
|
|
if nBuf > int32(4) && 0 == libc.Xmemcmp(tls, __ccgo_ts+42140, aBuf+uintptr(nBuf-int32(4)), uint32(4)) {
|
|
if _fts5Porter_MGt0(tls, aBuf, nBuf-int32(4)) != 0 {
|
|
libc.Xmemcpy(tls, aBuf+uintptr(nBuf-int32(4)), __ccgo_ts+41925, uint32(2))
|
|
**(**int32)(__ccgo_up(pnBuf)) = nBuf - int32(4) + int32(2)
|
|
}
|
|
}
|
|
case int32('s'):
|
|
if nBuf > int32(4) && 0 == libc.Xmemcmp(tls, __ccgo_ts+42145, aBuf+uintptr(nBuf-int32(4)), uint32(4)) {
|
|
if _fts5Porter_MGt0(tls, aBuf, nBuf-int32(4)) != 0 {
|
|
**(**int32)(__ccgo_up(pnBuf)) = nBuf - int32(4)
|
|
}
|
|
}
|
|
case int32('t'):
|
|
if nBuf > int32(5) && 0 == libc.Xmemcmp(tls, __ccgo_ts+42150, aBuf+uintptr(nBuf-int32(5)), uint32(5)) {
|
|
if _fts5Porter_MGt0(tls, aBuf, nBuf-int32(5)) != 0 {
|
|
libc.Xmemcpy(tls, aBuf+uintptr(nBuf-int32(5)), __ccgo_ts+41925, uint32(2))
|
|
**(**int32)(__ccgo_up(pnBuf)) = nBuf - int32(5) + int32(2)
|
|
}
|
|
} else {
|
|
if nBuf > int32(5) && 0 == libc.Xmemcmp(tls, __ccgo_ts+42156, aBuf+uintptr(nBuf-int32(5)), uint32(5)) {
|
|
if _fts5Porter_MGt0(tls, aBuf, nBuf-int32(5)) != 0 {
|
|
libc.Xmemcpy(tls, aBuf+uintptr(nBuf-int32(5)), __ccgo_ts+41925, uint32(2))
|
|
**(**int32)(__ccgo_up(pnBuf)) = nBuf - int32(5) + int32(2)
|
|
}
|
|
}
|
|
}
|
|
case int32('u'):
|
|
if nBuf > int32(3) && 0 == libc.Xmemcmp(tls, __ccgo_ts+42109, aBuf+uintptr(nBuf-int32(3)), uint32(3)) {
|
|
if _fts5Porter_MGt0(tls, aBuf, nBuf-int32(3)) != 0 {
|
|
**(**int32)(__ccgo_up(pnBuf)) = nBuf - int32(3)
|
|
}
|
|
}
|
|
case int32('v'):
|
|
if nBuf > int32(5) && 0 == libc.Xmemcmp(tls, __ccgo_ts+42162, aBuf+uintptr(nBuf-int32(5)), uint32(5)) {
|
|
if _fts5Porter_MGt0(tls, aBuf, nBuf-int32(5)) != 0 {
|
|
**(**int32)(__ccgo_up(pnBuf)) = nBuf - int32(5)
|
|
}
|
|
}
|
|
case int32('z'):
|
|
if nBuf > int32(5) && 0 == libc.Xmemcmp(tls, __ccgo_ts+42168, aBuf+uintptr(nBuf-int32(5)), uint32(5)) {
|
|
if _fts5Porter_MGt0(tls, aBuf, nBuf-int32(5)) != 0 {
|
|
libc.Xmemcpy(tls, aBuf+uintptr(nBuf-int32(5)), __ccgo_ts+41909, uint32(2))
|
|
**(**int32)(__ccgo_up(pnBuf)) = nBuf - int32(5) + int32(2)
|
|
}
|
|
}
|
|
break
|
|
}
|
|
return ret
|
|
}
|
|
|
|
func _fts5PorterStep4(tls *libc.TLS, aBuf uintptr, pnBuf uintptr) (r int32) {
|
|
var nBuf, ret int32
|
|
_, _ = nBuf, ret
|
|
ret = 0
|
|
nBuf = **(**int32)(__ccgo_up(pnBuf))
|
|
switch int32(**(**int8)(__ccgo_up(aBuf + uintptr(nBuf-int32(2))))) {
|
|
case int32('a'):
|
|
if nBuf > int32(2) && 0 == libc.Xmemcmp(tls, __ccgo_ts+41909, aBuf+uintptr(nBuf-int32(2)), uint32(2)) {
|
|
if _fts5Porter_MGt1(tls, aBuf, nBuf-int32(2)) != 0 {
|
|
**(**int32)(__ccgo_up(pnBuf)) = nBuf - int32(2)
|
|
}
|
|
}
|
|
case int32('c'):
|
|
if nBuf > int32(4) && 0 == libc.Xmemcmp(tls, __ccgo_ts+41912, aBuf+uintptr(nBuf-int32(4)), uint32(4)) {
|
|
if _fts5Porter_MGt1(tls, aBuf, nBuf-int32(4)) != 0 {
|
|
**(**int32)(__ccgo_up(pnBuf)) = nBuf - int32(4)
|
|
}
|
|
} else {
|
|
if nBuf > int32(4) && 0 == libc.Xmemcmp(tls, __ccgo_ts+41917, aBuf+uintptr(nBuf-int32(4)), uint32(4)) {
|
|
if _fts5Porter_MGt1(tls, aBuf, nBuf-int32(4)) != 0 {
|
|
**(**int32)(__ccgo_up(pnBuf)) = nBuf - int32(4)
|
|
}
|
|
}
|
|
}
|
|
case int32('e'):
|
|
if nBuf > int32(2) && 0 == libc.Xmemcmp(tls, __ccgo_ts+41922, aBuf+uintptr(nBuf-int32(2)), uint32(2)) {
|
|
if _fts5Porter_MGt1(tls, aBuf, nBuf-int32(2)) != 0 {
|
|
**(**int32)(__ccgo_up(pnBuf)) = nBuf - int32(2)
|
|
}
|
|
}
|
|
case int32('i'):
|
|
if nBuf > int32(2) && 0 == libc.Xmemcmp(tls, __ccgo_ts+41925, aBuf+uintptr(nBuf-int32(2)), uint32(2)) {
|
|
if _fts5Porter_MGt1(tls, aBuf, nBuf-int32(2)) != 0 {
|
|
**(**int32)(__ccgo_up(pnBuf)) = nBuf - int32(2)
|
|
}
|
|
}
|
|
case int32('l'):
|
|
if nBuf > int32(4) && 0 == libc.Xmemcmp(tls, __ccgo_ts+41928, aBuf+uintptr(nBuf-int32(4)), uint32(4)) {
|
|
if _fts5Porter_MGt1(tls, aBuf, nBuf-int32(4)) != 0 {
|
|
**(**int32)(__ccgo_up(pnBuf)) = nBuf - int32(4)
|
|
}
|
|
} else {
|
|
if nBuf > int32(4) && 0 == libc.Xmemcmp(tls, __ccgo_ts+41933, aBuf+uintptr(nBuf-int32(4)), uint32(4)) {
|
|
if _fts5Porter_MGt1(tls, aBuf, nBuf-int32(4)) != 0 {
|
|
**(**int32)(__ccgo_up(pnBuf)) = nBuf - int32(4)
|
|
}
|
|
}
|
|
}
|
|
case int32('n'):
|
|
if nBuf > int32(3) && 0 == libc.Xmemcmp(tls, __ccgo_ts+41938, aBuf+uintptr(nBuf-int32(3)), uint32(3)) {
|
|
if _fts5Porter_MGt1(tls, aBuf, nBuf-int32(3)) != 0 {
|
|
**(**int32)(__ccgo_up(pnBuf)) = nBuf - int32(3)
|
|
}
|
|
} else {
|
|
if nBuf > int32(5) && 0 == libc.Xmemcmp(tls, __ccgo_ts+41942, aBuf+uintptr(nBuf-int32(5)), uint32(5)) {
|
|
if _fts5Porter_MGt1(tls, aBuf, nBuf-int32(5)) != 0 {
|
|
**(**int32)(__ccgo_up(pnBuf)) = nBuf - int32(5)
|
|
}
|
|
} else {
|
|
if nBuf > int32(4) && 0 == libc.Xmemcmp(tls, __ccgo_ts+41948, aBuf+uintptr(nBuf-int32(4)), uint32(4)) {
|
|
if _fts5Porter_MGt1(tls, aBuf, nBuf-int32(4)) != 0 {
|
|
**(**int32)(__ccgo_up(pnBuf)) = nBuf - int32(4)
|
|
}
|
|
} else {
|
|
if nBuf > int32(3) && 0 == libc.Xmemcmp(tls, __ccgo_ts+41953, aBuf+uintptr(nBuf-int32(3)), uint32(3)) {
|
|
if _fts5Porter_MGt1(tls, aBuf, nBuf-int32(3)) != 0 {
|
|
**(**int32)(__ccgo_up(pnBuf)) = nBuf - int32(3)
|
|
}
|
|
}
|
|
}
|
|
}
|
|
}
|
|
case int32('o'):
|
|
if nBuf > int32(3) && 0 == libc.Xmemcmp(tls, __ccgo_ts+41957, aBuf+uintptr(nBuf-int32(3)), uint32(3)) {
|
|
if _fts5Porter_MGt1_and_S_or_T(tls, aBuf, nBuf-int32(3)) != 0 {
|
|
**(**int32)(__ccgo_up(pnBuf)) = nBuf - int32(3)
|
|
}
|
|
} else {
|
|
if nBuf > int32(2) && 0 == libc.Xmemcmp(tls, __ccgo_ts+41961, aBuf+uintptr(nBuf-int32(2)), uint32(2)) {
|
|
if _fts5Porter_MGt1(tls, aBuf, nBuf-int32(2)) != 0 {
|
|
**(**int32)(__ccgo_up(pnBuf)) = nBuf - int32(2)
|
|
}
|
|
}
|
|
}
|
|
case int32('s'):
|
|
if nBuf > int32(3) && 0 == libc.Xmemcmp(tls, __ccgo_ts+41964, aBuf+uintptr(nBuf-int32(3)), uint32(3)) {
|
|
if _fts5Porter_MGt1(tls, aBuf, nBuf-int32(3)) != 0 {
|
|
**(**int32)(__ccgo_up(pnBuf)) = nBuf - int32(3)
|
|
}
|
|
}
|
|
case int32('t'):
|
|
if nBuf > int32(3) && 0 == libc.Xmemcmp(tls, __ccgo_ts+41968, aBuf+uintptr(nBuf-int32(3)), uint32(3)) {
|
|
if _fts5Porter_MGt1(tls, aBuf, nBuf-int32(3)) != 0 {
|
|
**(**int32)(__ccgo_up(pnBuf)) = nBuf - int32(3)
|
|
}
|
|
} else {
|
|
if nBuf > int32(3) && 0 == libc.Xmemcmp(tls, __ccgo_ts+41972, aBuf+uintptr(nBuf-int32(3)), uint32(3)) {
|
|
if _fts5Porter_MGt1(tls, aBuf, nBuf-int32(3)) != 0 {
|
|
**(**int32)(__ccgo_up(pnBuf)) = nBuf - int32(3)
|
|
}
|
|
}
|
|
}
|
|
case int32('u'):
|
|
if nBuf > int32(3) && 0 == libc.Xmemcmp(tls, __ccgo_ts+41976, aBuf+uintptr(nBuf-int32(3)), uint32(3)) {
|
|
if _fts5Porter_MGt1(tls, aBuf, nBuf-int32(3)) != 0 {
|
|
**(**int32)(__ccgo_up(pnBuf)) = nBuf - int32(3)
|
|
}
|
|
}
|
|
case int32('v'):
|
|
if nBuf > int32(3) && 0 == libc.Xmemcmp(tls, __ccgo_ts+41980, aBuf+uintptr(nBuf-int32(3)), uint32(3)) {
|
|
if _fts5Porter_MGt1(tls, aBuf, nBuf-int32(3)) != 0 {
|
|
**(**int32)(__ccgo_up(pnBuf)) = nBuf - int32(3)
|
|
}
|
|
}
|
|
case int32('z'):
|
|
if nBuf > int32(3) && 0 == libc.Xmemcmp(tls, __ccgo_ts+41984, aBuf+uintptr(nBuf-int32(3)), uint32(3)) {
|
|
if _fts5Porter_MGt1(tls, aBuf, nBuf-int32(3)) != 0 {
|
|
**(**int32)(__ccgo_up(pnBuf)) = nBuf - int32(3)
|
|
}
|
|
}
|
|
break
|
|
}
|
|
return ret
|
|
}
|
|
|
|
// 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+80, Xsqlite3_mprintf(tls, __ccgo_ts+39383, 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 + 8
|
|
} else {
|
|
v1 = uintptr(0)
|
|
}
|
|
rc = _sqlite3Fts5StorageStmt(tls, (*TFts5FullTable)(unsafe.Pointer(pTab)).FpStorage, eStmt, pCsr+44, 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 + 56)) &= ^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+39951, 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+3942, 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 + 56 + uintptr((*TFts5TokenDataIter)(unsafe.Pointer(pSet)).FnIter-int64(1))*4))
|
|
} 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+40, bp, (*TFts5Buffer)(unsafe.Pointer(pSmall)).Fn, (*TFts5Buffer)(unsafe.Pointer(pSmall)).Fp)
|
|
_sqlite3Fts5BufferAppendBlob(tls, p+40, bp, uint32(1), __ccgo_ts+39582)
|
|
} else {
|
|
_sqlite3Fts5BufferSet(tls, p+40, bp, nToken, pToken)
|
|
}
|
|
if (*TFts5Index)(unsafe.Pointer(p)).Frc != 0 {
|
|
_fts5IterClose(tls, pNew)
|
|
break
|
|
}
|
|
pNewIter = pNew + 72
|
|
if pPrev != 0 {
|
|
v1 = pPrev + 72
|
|
} else {
|
|
v1 = uintptr(0)
|
|
}
|
|
pPrevIter = v1
|
|
iLvl = 0
|
|
for {
|
|
if !(iLvl < (*TFts5Structure)(unsafe.Pointer(pStruct)).FnLevel) {
|
|
break
|
|
}
|
|
iSeg = (*(*TFts5StructureLevel)(unsafe.Pointer(pStruct + 28 + uintptr(iLvl)*12))).FnSeg - int32(1)
|
|
for {
|
|
if !(iSeg >= 0) {
|
|
break
|
|
}
|
|
pSeg = (*(*TFts5StructureLevel)(unsafe.Pointer(pStruct + 28 + uintptr(iLvl)*12))).FaSeg + uintptr(iSeg)*48
|
|
bDone = 0
|
|
if pPrevIter != 0 {
|
|
if _fts5BufferCompare(tls, pSmall, pPrevIter+68) != 0 {
|
|
libc.Xmemcpy(tls, pNewIter, pPrevIter, uint32(96))
|
|
libc.Xmemset(tls, pPrevIter, 0, uint32(96))
|
|
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 += 96
|
|
if pPrevIter != 0 {
|
|
pPrevIter += 96
|
|
}
|
|
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+40, 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 + 72 + uintptr(ii)*96
|
|
if 0 == _fts5IsTokendataPrefix(tls, pII+68, pToken, nToken) {
|
|
_fts5SegIterSetEOF(tls, pII)
|
|
}
|
|
if (*TFts5SegIter)(unsafe.Pointer(pII)).FpLeaf != 0 && (!(pSmall != 0) || _fts5BufferCompare(tls, pSmall, pII+68) > 0) {
|
|
pSmall = pII + 68
|
|
}
|
|
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 + 56 + uintptr(ii1)*4))
|
|
iSeg1 = 0
|
|
for {
|
|
if !(iSeg1 < (*TFts5Iter)(unsafe.Pointer(pIter)).FnSeg) {
|
|
break
|
|
}
|
|
(*(*TFts5SegIter)(unsafe.Pointer(pIter + 72 + uintptr(iSeg1)*96))).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
|
|
//
|
|
// /*
|
|
// ** 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 + 28 + uintptr(eStmt)*4)) == uintptr(0) {
|
|
azStmt = [12]uintptr{
|
|
0: __ccgo_ts + 40761,
|
|
1: __ccgo_ts + 40829,
|
|
2: __ccgo_ts + 40898,
|
|
3: __ccgo_ts + 40898,
|
|
4: __ccgo_ts + 40931,
|
|
5: __ccgo_ts + 40970,
|
|
6: __ccgo_ts + 41010,
|
|
7: __ccgo_ts + 41049,
|
|
8: __ccgo_ts + 41092,
|
|
9: __ccgo_ts + 41131,
|
|
10: __ccgo_ts + 41175,
|
|
11: __ccgo_ts + 41215,
|
|
}
|
|
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 + 14348
|
|
} else {
|
|
v2 = __ccgo_ts + 1702
|
|
}
|
|
zBind = _sqlite3Fts5Mprintf(tls, bp, __ccgo_ts+41238, 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+41246, 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 + 41253
|
|
} else {
|
|
v2 = __ccgo_ts + 1702
|
|
}
|
|
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 + 41256
|
|
} else {
|
|
v2 = __ccgo_ts + 1702
|
|
}
|
|
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+28+uintptr(eStmt)*4, 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+3942, 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 + 28 + uintptr(eStmt)*4))
|
|
Xsqlite3_reset(tls, **(**uintptr)(__ccgo_up(ppStmt)))
|
|
return **(**int32)(__ccgo_up(bp))
|
|
}
|
|
|
|
// 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+39086, uint32(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.Int64FromUint32(uint32(libc.UintptrFromInt32(0)+28) + libc.Uint32FromInt32(**(**int32)(__ccgo_up(bp + 4)))*libc.Uint32FromInt64(12))
|
|
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+4))
|
|
iLvl = 0
|
|
for {
|
|
if !(**(**int32)(__ccgo_up(bp)) == SQLITE_OK && iLvl < **(**int32)(__ccgo_up(bp + 4))) {
|
|
break
|
|
}
|
|
pLvl = pRet + 28 + uintptr(iLvl)*12
|
|
**(**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, int64(**(**int32)(__ccgo_up(bp + 12)))*int64(48))
|
|
**(**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)*48
|
|
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+12))
|
|
i = i + libc.Int32FromUint8(_sqlite3Fts5GetVarint(tls, pData+uintptr(i), pSeg+20))
|
|
i = i + _sqlite3Fts5GetVarint32(tls, pData+uintptr(i), pSeg+28)
|
|
i = i + libc.Int32FromUint8(_sqlite3Fts5GetVarint(tls, pData+uintptr(i), pSeg+32))
|
|
i = i + libc.Int32FromUint8(_sqlite3Fts5GetVarint(tls, pData+uintptr(i), pSeg+40))
|
|
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))*12))).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))
|
|
}
|
|
|
|
// 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, uint32(12))
|
|
/* 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+40, 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+39086, uint32(4))
|
|
**(**int32)(__ccgo_up(bp + 4)) += int32(4)
|
|
}
|
|
**(**int32)(__ccgo_up(bp + 4)) += _sqlite3Fts5PutVarint(tls, (*TFts5Buffer)(unsafe.Pointer(bp)).Fp+uintptr((*TFts5Buffer)(unsafe.Pointer(bp)).Fn), libc.Uint64FromInt32((*TFts5Structure)(unsafe.Pointer(pStruct)).FnLevel))
|
|
**(**int32)(__ccgo_up(bp + 4)) += _sqlite3Fts5PutVarint(tls, (*TFts5Buffer)(unsafe.Pointer(bp)).Fp+uintptr((*TFts5Buffer)(unsafe.Pointer(bp)).Fn), libc.Uint64FromInt32((*TFts5Structure)(unsafe.Pointer(pStruct)).FnSegment))
|
|
**(**int32)(__ccgo_up(bp + 4)) += _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 + 28 + uintptr(iLvl)*12
|
|
_sqlite3Fts5BufferAppendVarint(tls, p+40, bp, int64((*TFts5StructureLevel)(unsafe.Pointer(pLvl)).FnMerge))
|
|
_sqlite3Fts5BufferAppendVarint(tls, p+40, 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)*48
|
|
_sqlite3Fts5BufferAppendVarint(tls, p+40, bp, int64((*TFts5StructureSegment)(unsafe.Pointer(pSeg)).FiSegid))
|
|
_sqlite3Fts5BufferAppendVarint(tls, p+40, bp, int64((*TFts5StructureSegment)(unsafe.Pointer(pSeg)).FpgnoFirst))
|
|
_sqlite3Fts5BufferAppendVarint(tls, p+40, bp, int64((*TFts5StructureSegment)(unsafe.Pointer(pSeg)).FpgnoLast))
|
|
if (*TFts5Structure)(unsafe.Pointer(pStruct)).FnOriginCntr > uint64(0) {
|
|
_sqlite3Fts5BufferAppendVarint(tls, p+40, bp, libc.Int64FromUint64((*TFts5StructureSegment)(unsafe.Pointer(pSeg)).FiOrigin1))
|
|
_sqlite3Fts5BufferAppendVarint(tls, p+40, bp, libc.Int64FromUint64((*TFts5StructureSegment)(unsafe.Pointer(pSeg)).FiOrigin2))
|
|
_sqlite3Fts5BufferAppendVarint(tls, p+40, bp, int64((*TFts5StructureSegment)(unsafe.Pointer(pSeg)).FnPgTombstone))
|
|
_sqlite3Fts5BufferAppendVarint(tls, p+40, bp, libc.Int64FromUint64((*TFts5StructureSegment)(unsafe.Pointer(pSeg)).FnEntryTombstone))
|
|
_sqlite3Fts5BufferAppendVarint(tls, p+40, 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
|
|
//
|
|
// /*
|
|
// ** Allocate a trigram tokenizer.
|
|
// */
|
|
func _fts5TriCreate(tls *libc.TLS, pUnused uintptr, azArg uintptr, nArg int32, ppOut uintptr) (r int32) {
|
|
var i, rc, v2 int32
|
|
var pNew, zArg uintptr
|
|
_, _, _, _, _ = i, pNew, rc, zArg, v2
|
|
rc = SQLITE_OK
|
|
pNew = uintptr(0)
|
|
_ = pUnused
|
|
if nArg%int32(2) != 0 {
|
|
rc = int32(SQLITE_ERROR)
|
|
} else {
|
|
pNew = Xsqlite3_malloc64(tls, uint64(8))
|
|
if pNew == uintptr(0) {
|
|
rc = int32(SQLITE_NOMEM)
|
|
} else {
|
|
(*TTrigramTokenizer)(unsafe.Pointer(pNew)).FbFold = int32(1)
|
|
(*TTrigramTokenizer)(unsafe.Pointer(pNew)).FiFoldParam = 0
|
|
i = 0
|
|
for {
|
|
if !(rc == SQLITE_OK && i < nArg) {
|
|
break
|
|
}
|
|
zArg = **(**uintptr)(__ccgo_up(azArg + uintptr(i+int32(1))*4))
|
|
if 0 == Xsqlite3_stricmp(tls, **(**uintptr)(__ccgo_up(azArg + uintptr(i)*4)), __ccgo_ts+42188) {
|
|
if int32(**(**int8)(__ccgo_up(zArg))) != int32('0') && int32(**(**int8)(__ccgo_up(zArg))) != int32('1') || **(**int8)(__ccgo_up(zArg + 1)) != 0 {
|
|
rc = int32(SQLITE_ERROR)
|
|
} else {
|
|
(*TTrigramTokenizer)(unsafe.Pointer(pNew)).FbFold = libc.BoolInt32(int32(**(**int8)(__ccgo_up(zArg))) == int32('0'))
|
|
}
|
|
} else {
|
|
if 0 == Xsqlite3_stricmp(tls, **(**uintptr)(__ccgo_up(azArg + uintptr(i)*4)), __ccgo_ts+41874) {
|
|
if int32(**(**int8)(__ccgo_up(zArg))) != int32('0') && int32(**(**int8)(__ccgo_up(zArg))) != int32('1') && int32(**(**int8)(__ccgo_up(zArg))) != int32('2') || **(**int8)(__ccgo_up(zArg + 1)) != 0 {
|
|
rc = int32(SQLITE_ERROR)
|
|
} else {
|
|
if int32(**(**int8)(__ccgo_up(zArg))) != int32('0') {
|
|
v2 = int32(2)
|
|
} else {
|
|
v2 = 0
|
|
}
|
|
(*TTrigramTokenizer)(unsafe.Pointer(pNew)).FiFoldParam = v2
|
|
}
|
|
} else {
|
|
rc = int32(SQLITE_ERROR)
|
|
}
|
|
}
|
|
goto _1
|
|
_1:
|
|
;
|
|
i = i + int32(2)
|
|
}
|
|
if (*TTrigramTokenizer)(unsafe.Pointer(pNew)).FiFoldParam != 0 && (*TTrigramTokenizer)(unsafe.Pointer(pNew)).FbFold == 0 {
|
|
rc = int32(SQLITE_ERROR)
|
|
}
|
|
if rc != SQLITE_OK {
|
|
_fts5TriDelete(tls, pNew)
|
|
pNew = uintptr(0)
|
|
}
|
|
}
|
|
}
|
|
**(**uintptr)(__ccgo_up(ppOut)) = pNew
|
|
return rc
|
|
}
|
|
|
|
// C documentation
|
|
//
|
|
// /*
|
|
// ** Create a "unicode61" tokenizer.
|
|
// */
|
|
func _fts5UnicodeCreate(tls *libc.TLS, pUnused uintptr, azArg uintptr, nArg int32, ppOut uintptr) (r int32) {
|
|
var i, rc int32
|
|
var p, zArg, zCat uintptr
|
|
_, _, _, _, _ = i, p, rc, zArg, zCat
|
|
rc = SQLITE_OK /* Return code */
|
|
p = uintptr(0) /* New tokenizer object */
|
|
_ = pUnused
|
|
if nArg%int32(2) != 0 {
|
|
rc = int32(SQLITE_ERROR)
|
|
} else {
|
|
p = Xsqlite3_malloc64(tls, uint64(180))
|
|
if p != 0 {
|
|
zCat = __ccgo_ts + 41854
|
|
libc.Xmemset(tls, p, 0, uint32(180))
|
|
(*TUnicode61Tokenizer)(unsafe.Pointer(p)).FeRemoveDiacritic = int32(FTS5_REMOVE_DIACRITICS_SIMPLE)
|
|
(*TUnicode61Tokenizer)(unsafe.Pointer(p)).FnFold = int32(64)
|
|
(*TUnicode61Tokenizer)(unsafe.Pointer(p)).FaFold = Xsqlite3_malloc64(tls, uint64(libc.Uint32FromInt32((*TUnicode61Tokenizer)(unsafe.Pointer(p)).FnFold)*uint32(1)))
|
|
if (*TUnicode61Tokenizer)(unsafe.Pointer(p)).FaFold == uintptr(0) {
|
|
rc = int32(SQLITE_NOMEM)
|
|
}
|
|
/* Search for a "categories" argument */
|
|
i = 0
|
|
for {
|
|
if !(rc == SQLITE_OK && i < nArg) {
|
|
break
|
|
}
|
|
if 0 == Xsqlite3_stricmp(tls, **(**uintptr)(__ccgo_up(azArg + uintptr(i)*4)), __ccgo_ts+41863) {
|
|
zCat = **(**uintptr)(__ccgo_up(azArg + uintptr(i+int32(1))*4))
|
|
}
|
|
goto _1
|
|
_1:
|
|
;
|
|
i = i + int32(2)
|
|
}
|
|
if rc == SQLITE_OK {
|
|
rc = _unicodeSetCategories(tls, p, zCat)
|
|
}
|
|
i = 0
|
|
for {
|
|
if !(rc == SQLITE_OK && i < nArg) {
|
|
break
|
|
}
|
|
zArg = **(**uintptr)(__ccgo_up(azArg + uintptr(i+int32(1))*4))
|
|
if 0 == Xsqlite3_stricmp(tls, **(**uintptr)(__ccgo_up(azArg + uintptr(i)*4)), __ccgo_ts+41874) {
|
|
if int32(**(**int8)(__ccgo_up(zArg))) != int32('0') && int32(**(**int8)(__ccgo_up(zArg))) != int32('1') && int32(**(**int8)(__ccgo_up(zArg))) != int32('2') || **(**int8)(__ccgo_up(zArg + 1)) != 0 {
|
|
rc = int32(SQLITE_ERROR)
|
|
} else {
|
|
(*TUnicode61Tokenizer)(unsafe.Pointer(p)).FeRemoveDiacritic = int32(**(**int8)(__ccgo_up(zArg))) - int32('0')
|
|
}
|
|
} else {
|
|
if 0 == Xsqlite3_stricmp(tls, **(**uintptr)(__ccgo_up(azArg + uintptr(i)*4)), __ccgo_ts+41832) {
|
|
rc = _fts5UnicodeAddExceptions(tls, p, zArg, int32(1))
|
|
} else {
|
|
if 0 == Xsqlite3_stricmp(tls, **(**uintptr)(__ccgo_up(azArg + uintptr(i)*4)), __ccgo_ts+41843) {
|
|
rc = _fts5UnicodeAddExceptions(tls, p, zArg, 0)
|
|
} else {
|
|
if 0 == Xsqlite3_stricmp(tls, **(**uintptr)(__ccgo_up(azArg + uintptr(i)*4)), __ccgo_ts+41863) {
|
|
/* no-op */
|
|
} else {
|
|
rc = int32(SQLITE_ERROR)
|
|
}
|
|
}
|
|
}
|
|
}
|
|
goto _2
|
|
_2:
|
|
;
|
|
i = i + int32(2)
|
|
}
|
|
} else {
|
|
rc = int32(SQLITE_NOMEM)
|
|
}
|
|
if rc != SQLITE_OK {
|
|
_fts5UnicodeDelete(tls, p)
|
|
p = uintptr(0)
|
|
}
|
|
**(**uintptr)(__ccgo_up(ppOut)) = p
|
|
}
|
|
return rc
|
|
}
|
|
|
|
// C documentation
|
|
//
|
|
// /*
|
|
// ** Implementation of xOpen method.
|
|
// */
|
|
func _fts5VocabOpenMethod(tls *libc.TLS, pVTab uintptr, ppCsr uintptr) (r int32) {
|
|
bp := tls.Alloc(48)
|
|
defer tls.Free(48)
|
|
var iId, nByte Ti64
|
|
var pCsr, pFts5, pTab, zSql uintptr
|
|
var _ /* pStmt at bp+4 */ 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 + 4)) = uintptr(0)
|
|
zSql = uintptr(0)
|
|
if (*TFts5VocabTable)(unsafe.Pointer(pTab)).FbBusy != 0 {
|
|
(*Tsqlite3_vtab)(unsafe.Pointer(pVTab)).FzErrMsg = Xsqlite3_mprintf(tls, __ccgo_ts+42419, libc.VaList(bp+16, (*TFts5VocabTable)(unsafe.Pointer(pTab)).FzFts5Db, (*TFts5VocabTable)(unsafe.Pointer(pTab)).FzFts5Tbl))
|
|
return int32(SQLITE_ERROR)
|
|
}
|
|
zSql = _sqlite3Fts5Mprintf(tls, bp, __ccgo_ts+42450, libc.VaList(bp+16, (*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+4, 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 + 4)) != 0 && Xsqlite3_step(tls, **(**uintptr)(__ccgo_up(bp + 4))) == int32(SQLITE_ROW) {
|
|
iId = Xsqlite3_column_int64(tls, **(**uintptr)(__ccgo_up(bp + 4)), 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 + 4)))
|
|
**(**uintptr)(__ccgo_up(bp + 4)) = uintptr(0)
|
|
if **(**int32)(__ccgo_up(bp)) == SQLITE_OK {
|
|
(*Tsqlite3_vtab)(unsafe.Pointer(pVTab)).FzErrMsg = Xsqlite3_mprintf(tls, __ccgo_ts+42501, libc.VaList(bp+16, (*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.Int64FromUint32(libc.Uint32FromInt32((*TFts5Config)(unsafe.Pointer((*TFts5Table)(unsafe.Pointer(pFts5)).FpConfig)).FnCol)*uint32(8)*uint32(2) + uint32(80))
|
|
pCsr = _sqlite3Fts5MallocZero(tls, bp, nByte)
|
|
}
|
|
if pCsr != 0 {
|
|
(*TFts5VocabCursor)(unsafe.Pointer(pCsr)).FpFts5 = pFts5
|
|
(*TFts5VocabCursor)(unsafe.Pointer(pCsr)).FpStmt = **(**uintptr)(__ccgo_up(bp + 4))
|
|
(*TFts5VocabCursor)(unsafe.Pointer(pCsr)).FaCnt = pCsr + 1*80
|
|
(*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 + 4)))
|
|
}
|
|
**(**uintptr)(__ccgo_up(ppCsr)) = pCsr
|
|
return **(**int32)(__ccgo_up(bp))
|
|
}
|
|
|
|
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, uint32(92))
|
|
(*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+40, pWriter+4+20, libc.Uint32FromInt32(nBuffer))
|
|
_sqlite3Fts5BufferSize(tls, p+40, pWriter+4+8, libc.Uint32FromInt32(nBuffer))
|
|
if (*TFts5Index)(unsafe.Pointer(p)).FpIdxWriter == uintptr(0) {
|
|
pConfig = (*TFts5Index)(unsafe.Pointer(p)).FpConfig
|
|
_fts5IndexPrepareStmt(tls, p, p+60, Xsqlite3_mprintf(tls, __ccgo_ts+39326, 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, uint32(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
|
|
//
|
|
// /*
|
|
// ** 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.Int64FromUint32(uint32(libc.UintptrFromInt32(0)+28) + libc.Uint32FromInt32(nArg)*uint32(8) + libc.Uint32FromInt32(nArg)*uint32(4))
|
|
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 + 28 + 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)*4)) = Xsqlite3_value_dup(tls, **(**uintptr)(__ccgo_up(aArg + uintptr(i)*4)))
|
|
if **(**uintptr)(__ccgo_up((*TRtreeMatchArg)(unsafe.Pointer(pBlob)).FapSqlParam + uintptr(i)*4)) == uintptr(0) {
|
|
memErr = int32(1)
|
|
}
|
|
*(*TRtreeDValue)(unsafe.Pointer(pBlob + 28 + uintptr(i)*8)) = Xsqlite3_value_double(tls, **(**uintptr)(__ccgo_up(aArg + uintptr(i)*4)))
|
|
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+27493, __ccgo_fp(_rtreeMatchArgFree))
|
|
}
|
|
}
|
|
}
|
|
|
|
// 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+29908, 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.Int64FromUint32(libc.Xstrlen(tls, **(**uintptr)(__ccgo_up(argv + 1*4))))
|
|
nName = libc.Int64FromUint32(libc.Xstrlen(tls, **(**uintptr)(__ccgo_up(argv + 2*4))))
|
|
pRtree = Xsqlite3_malloc64(tls, libc.Uint64FromInt64(int64(504)+nDb+nName*int64(2)+int64(8)))
|
|
if !(pRtree != 0) {
|
|
return int32(SQLITE_NOMEM)
|
|
}
|
|
libc.Xmemset(tls, pRtree, 0, libc.Uint32FromInt64(int64(504)+nDb+nName*int64(2)+int64(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*504
|
|
(*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*4)), libc.Uint32FromInt64(nDb))
|
|
libc.Xmemcpy(tls, (*TRtree)(unsafe.Pointer(pRtree)).FzName, **(**uintptr)(__ccgo_up(argv + 2*4)), libc.Uint32FromInt64(nName))
|
|
libc.Xmemcpy(tls, (*TRtree)(unsafe.Pointer(pRtree)).FzNodeName, **(**uintptr)(__ccgo_up(argv + 2*4)), libc.Uint32FromInt64(nName))
|
|
libc.Xmemcpy(tls, (*TRtree)(unsafe.Pointer(pRtree)).FzNodeName+uintptr(nName), __ccgo_ts+28950, uint32(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+29945, 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+29967, libc.VaList(bp+8, **(**uintptr)(__ccgo_up(argv + uintptr(ii)*4))))
|
|
goto _1
|
|
_1:
|
|
;
|
|
ii = ii + 1
|
|
}
|
|
Xsqlite3_str_appendf(tls, pSql, __ccgo_ts+29007, 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+3942, 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*4)), **(**uintptr)(__ccgo_up(argv + 2*4)), isCreate)
|
|
if rc != 0 {
|
|
**(**uintptr)(__ccgo_up(pzErr)) = Xsqlite3_mprintf(tls, __ccgo_ts+3942, 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_svg(X, ....)
|
|
// **
|
|
// ** Interpret X as a polygon and render it as a SVG <polyline>.
|
|
// ** Additional arguments are added as attributes to the <polyline>.
|
|
// */
|
|
func _geopolySvgFunc(tls *libc.TLS, context uintptr, argc int32, argv uintptr) {
|
|
bp := tls.Alloc(32)
|
|
defer tls.Free(32)
|
|
var cSep int8
|
|
var db, p, x, z uintptr
|
|
var i int32
|
|
_, _, _, _, _, _ = cSep, db, i, p, x, z
|
|
if argc < int32(1) {
|
|
return
|
|
}
|
|
p = _geopolyFuncParam(tls, context, **(**uintptr)(__ccgo_up(argv)), uintptr(0))
|
|
if p != 0 {
|
|
db = Xsqlite3_context_db_handle(tls, context)
|
|
x = Xsqlite3_str_new(tls, db)
|
|
cSep = int8('\'')
|
|
Xsqlite3_str_appendf(tls, x, __ccgo_ts+29857, 0)
|
|
i = 0
|
|
for {
|
|
if !(i < (*TGeoPoly)(unsafe.Pointer(p)).FnVertex) {
|
|
break
|
|
}
|
|
Xsqlite3_str_appendf(tls, x, __ccgo_ts+29875, libc.VaList(bp+8, int32(cSep), float64(**(**TGeoCoord)(__ccgo_up(p + 8 + uintptr(i*int32(2))*4))), float64(**(**TGeoCoord)(__ccgo_up(p + 8 + uintptr(i*int32(2)+int32(1))*4)))))
|
|
cSep = int8(' ')
|
|
goto _1
|
|
_1:
|
|
;
|
|
i = i + 1
|
|
}
|
|
Xsqlite3_str_appendf(tls, x, __ccgo_ts+29883, 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)))))
|
|
i = int32(1)
|
|
for {
|
|
if !(i < argc) {
|
|
break
|
|
}
|
|
z = Xsqlite3_value_text(tls, **(**uintptr)(__ccgo_up(argv + uintptr(i)*4)))
|
|
if z != 0 && **(**int8)(__ccgo_up(z)) != 0 {
|
|
Xsqlite3_str_appendf(tls, x, __ccgo_ts+29891, libc.VaList(bp+8, z))
|
|
}
|
|
goto _2
|
|
_2:
|
|
;
|
|
i = i + 1
|
|
}
|
|
Xsqlite3_str_appendf(tls, x, __ccgo_ts+29895, 0)
|
|
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+4 */ TRtreeCell
|
|
var _ /* pLeaf at bp+52 */ 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*4))) != int32(SQLITE_NULL))
|
|
if newRowidValid != 0 {
|
|
v1 = Xsqlite3_value_int64(tls, **(**uintptr)(__ccgo_up(aData + 1*4)))
|
|
} else {
|
|
v1 = 0
|
|
}
|
|
newRowid = v1
|
|
(**(**TRtreeCell)(__ccgo_up(bp + 4))).FiRowid = newRowid
|
|
if nData > int32(1) && (!(oldRowidValid != 0) || !(Xsqlite3_value_nochange(tls, **(**uintptr)(__ccgo_up(aData + 2*4))) != 0) || oldRowid != newRowid) {
|
|
_geopolyBBox(tls, uintptr(0), **(**uintptr)(__ccgo_up(aData + 2*4)), bp+4+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+29986, 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 + 4))).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 + 4))).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 + 52)) = uintptr(0)
|
|
if !(newRowidValid != 0) {
|
|
**(**int32)(__ccgo_up(bp)) = _rtreeNewRowid(tls, pRtree, bp+4)
|
|
}
|
|
**(**Tsqlite_int64)(__ccgo_up(pRowid)) = (**(**TRtreeCell)(__ccgo_up(bp + 4))).FiRowid
|
|
if **(**int32)(__ccgo_up(bp)) == SQLITE_OK {
|
|
**(**int32)(__ccgo_up(bp)) = _ChooseLeaf(tls, pRtree, bp+4, 0, bp+52)
|
|
}
|
|
if **(**int32)(__ccgo_up(bp)) == SQLITE_OK {
|
|
**(**int32)(__ccgo_up(bp)) = _rtreeInsertCell(tls, pRtree, **(**uintptr)(__ccgo_up(bp + 52)), bp+4, 0)
|
|
rc2 = _nodeRelease(tls, pRtree, **(**uintptr)(__ccgo_up(bp + 52)))
|
|
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 + 4))).FiRowid)
|
|
if Xsqlite3_value_nochange(tls, **(**uintptr)(__ccgo_up(aData + 2*4))) != 0 {
|
|
Xsqlite3_bind_null(tls, pUp, int32(2))
|
|
} else {
|
|
p = uintptr(0)
|
|
if v4 = Xsqlite3_value_type(tls, **(**uintptr)(__ccgo_up(aData + 2*4))) == int32(SQLITE_TEXT); v4 {
|
|
v3 = _geopolyFuncParam(tls, uintptr(0), **(**uintptr)(__ccgo_up(aData + 2*4)), 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*4)))
|
|
}
|
|
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))*4)))
|
|
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
|
|
//
|
|
// /*
|
|
// ** Find the mode, uid and gid of file zFile.
|
|
// */
|
|
func _getFileMode(tls *libc.TLS, zFile uintptr, pMode uintptr, pUid uintptr, pGid uintptr) (r int32) {
|
|
bp := tls.Alloc(208)
|
|
defer tls.Free(208)
|
|
var rc int32
|
|
var _ /* sStat at bp+0 */ Tstat
|
|
_ = rc /* Output of stat() on database file */
|
|
rc = SQLITE_OK
|
|
if 0 == (*(*func(*libc.TLS, uintptr, uintptr) int32)(unsafe.Pointer(&struct{ uintptr }{_aSyscall[int32(4)].FpCurrent})))(tls, zFile, bp) {
|
|
**(**Tmode_t)(__ccgo_up(pMode)) = libc.Uint16FromInt32(libc.Int32FromUint16((**(**Tstat)(__ccgo_up(bp))).Fst_mode) & int32(0777))
|
|
**(**Tuid_t)(__ccgo_up(pUid)) = (**(**Tstat)(__ccgo_up(bp))).Fst_uid
|
|
**(**Tgid_t)(__ccgo_up(pGid)) = (**(**Tstat)(__ccgo_up(bp))).Fst_gid
|
|
} else {
|
|
rc = libc.Int32FromInt32(SQLITE_IOERR) | libc.Int32FromInt32(7)<<libc.Int32FromInt32(8)
|
|
}
|
|
return rc
|
|
}
|
|
|
|
// C documentation
|
|
//
|
|
// /* c is a control character. Append the canonical JSON representation
|
|
// ** of that control character to p.
|
|
// **
|
|
// ** This routine assumes that the output buffer has already been enlarged
|
|
// ** sufficiently to hold the worst-case encoding plus a nul terminator.
|
|
// */
|
|
func _jsonAppendControlChar(tls *libc.TLS, p uintptr, c Tu8) {
|
|
if _aSpecial[c] != 0 {
|
|
**(**int8)(__ccgo_up((*TJsonString)(unsafe.Pointer(p)).FzBuf + uintptr((*TJsonString)(unsafe.Pointer(p)).FnUsed))) = int8('\\')
|
|
**(**int8)(__ccgo_up((*TJsonString)(unsafe.Pointer(p)).FzBuf + uintptr((*TJsonString)(unsafe.Pointer(p)).FnUsed+uint64(1)))) = _aSpecial[c]
|
|
**(**Tu64)(__ccgo_up(p + 16)) += uint64(2)
|
|
} else {
|
|
**(**int8)(__ccgo_up((*TJsonString)(unsafe.Pointer(p)).FzBuf + uintptr((*TJsonString)(unsafe.Pointer(p)).FnUsed))) = int8('\\')
|
|
**(**int8)(__ccgo_up((*TJsonString)(unsafe.Pointer(p)).FzBuf + uintptr((*TJsonString)(unsafe.Pointer(p)).FnUsed+uint64(1)))) = int8('u')
|
|
**(**int8)(__ccgo_up((*TJsonString)(unsafe.Pointer(p)).FzBuf + uintptr((*TJsonString)(unsafe.Pointer(p)).FnUsed+uint64(2)))) = int8('0')
|
|
**(**int8)(__ccgo_up((*TJsonString)(unsafe.Pointer(p)).FzBuf + uintptr((*TJsonString)(unsafe.Pointer(p)).FnUsed+uint64(3)))) = int8('0')
|
|
**(**int8)(__ccgo_up((*TJsonString)(unsafe.Pointer(p)).FzBuf + uintptr((*TJsonString)(unsafe.Pointer(p)).FnUsed+uint64(4)))) = **(**int8)(__ccgo_up(__ccgo_ts + 1724 + uintptr(libc.Int32FromUint8(c)>>int32(4))))
|
|
**(**int8)(__ccgo_up((*TJsonString)(unsafe.Pointer(p)).FzBuf + uintptr((*TJsonString)(unsafe.Pointer(p)).FnUsed+uint64(5)))) = **(**int8)(__ccgo_up(__ccgo_ts + 1724 + uintptr(libc.Int32FromUint8(c)&int32(0xf))))
|
|
**(**Tu64)(__ccgo_up(p + 16)) += uint64(6)
|
|
}
|
|
}
|
|
|
|
// C documentation
|
|
//
|
|
// /*
|
|
// ** Append the path name for the current element.
|
|
// */
|
|
func _jsonAppendPathName(tls *libc.TLS, p uintptr) {
|
|
bp := tls.Alloc(32)
|
|
defer tls.Free(32)
|
|
var i, k, n Tu32
|
|
var needQuote int32
|
|
var z uintptr
|
|
var _ /* sz at bp+0 */ Tu32
|
|
_, _, _, _, _ = i, k, n, needQuote, z
|
|
if libc.Int32FromUint8((*TJsonEachCursor)(unsafe.Pointer(p)).FeType) == int32(JSONB_ARRAY) {
|
|
_jsonPrintf(tls, int32(30), p+40, __ccgo_ts+26943, libc.VaList(bp+16, (**(**TJsonParent)(__ccgo_up((*TJsonEachCursor)(unsafe.Pointer(p)).FaParent + uintptr((*TJsonEachCursor)(unsafe.Pointer(p)).FnParent-uint32(1))*24))).FiKey))
|
|
} else {
|
|
**(**Tu32)(__ccgo_up(bp)) = uint32(0)
|
|
needQuote = 0
|
|
n = _jsonbPayloadSize(tls, p+168, (*TJsonEachCursor)(unsafe.Pointer(p)).Fi, bp)
|
|
k = (*TJsonEachCursor)(unsafe.Pointer(p)).Fi + n
|
|
z = (*TJsonEachCursor)(unsafe.Pointer(p)).FsParse.FaBlob + uintptr(k)
|
|
if **(**Tu32)(__ccgo_up(bp)) == uint32(0) || !(libc.Int32FromUint8(_sqlite3CtypeMap[libc.Uint8FromInt8(**(**int8)(__ccgo_up(z)))])&libc.Int32FromInt32(0x02) != 0) {
|
|
needQuote = int32(1)
|
|
} else {
|
|
i = uint32(0)
|
|
for {
|
|
if !(i < **(**Tu32)(__ccgo_up(bp))) {
|
|
break
|
|
}
|
|
if !(libc.Int32FromUint8(_sqlite3CtypeMap[libc.Uint8FromInt8(**(**int8)(__ccgo_up(z + uintptr(i))))])&libc.Int32FromInt32(0x06) != 0) {
|
|
needQuote = int32(1)
|
|
break
|
|
}
|
|
goto _1
|
|
_1:
|
|
;
|
|
i = i + 1
|
|
}
|
|
}
|
|
if needQuote != 0 {
|
|
_jsonPrintf(tls, libc.Int32FromUint32(**(**Tu32)(__ccgo_up(bp))+uint32(4)), p+40, __ccgo_ts+26950, libc.VaList(bp+16, **(**Tu32)(__ccgo_up(bp)), z))
|
|
} else {
|
|
_jsonPrintf(tls, libc.Int32FromUint32(**(**Tu32)(__ccgo_up(bp))+uint32(2)), p+40, __ccgo_ts+26958, libc.VaList(bp+16, **(**Tu32)(__ccgo_up(bp)), z))
|
|
}
|
|
}
|
|
}
|
|
|
|
// C documentation
|
|
//
|
|
// /*
|
|
// ** json_array_length(JSON)
|
|
// ** json_array_length(JSON, PATH)
|
|
// **
|
|
// ** Return the number of elements in the top-level JSON array.
|
|
// ** Return 0 if the input is not a well-formed JSON array.
|
|
// */
|
|
func _jsonArrayLengthFunc(tls *libc.TLS, ctx uintptr, argc int32, argv uintptr) {
|
|
var cnt Tsqlite3_int64
|
|
var eErr Tu8
|
|
var i Tu32
|
|
var p, zPath, v1 uintptr
|
|
_, _, _, _, _, _ = cnt, eErr, i, p, zPath, v1 /* The parse */
|
|
cnt = 0
|
|
eErr = uint8(0)
|
|
p = _jsonParseFuncArg(tls, ctx, **(**uintptr)(__ccgo_up(argv)), uint32(0))
|
|
if p == uintptr(0) {
|
|
return
|
|
}
|
|
if argc == int32(2) {
|
|
zPath = Xsqlite3_value_text(tls, **(**uintptr)(__ccgo_up(argv + 1*4)))
|
|
if zPath == uintptr(0) {
|
|
_jsonParseFree(tls, p)
|
|
return
|
|
}
|
|
if int32(**(**int8)(__ccgo_up(zPath))) == int32('$') {
|
|
v1 = zPath + uintptr(1)
|
|
} else {
|
|
v1 = __ccgo_ts + 26670
|
|
}
|
|
i = _jsonLookupStep(tls, p, uint32(0), v1, uint32(0))
|
|
if i >= uint32(JSON_LOOKUP_PATHERROR) {
|
|
if i == uint32(JSON_LOOKUP_NOTFOUND) {
|
|
/* no-op */
|
|
} else {
|
|
_jsonBadPathError(tls, ctx, zPath, libc.Int32FromUint32(i))
|
|
}
|
|
eErr = uint8(1)
|
|
i = uint32(0)
|
|
}
|
|
} else {
|
|
i = uint32(0)
|
|
}
|
|
if libc.Int32FromUint8(**(**Tu8)(__ccgo_up((*TJsonParse)(unsafe.Pointer(p)).FaBlob + uintptr(i))))&int32(0x0f) == int32(JSONB_ARRAY) {
|
|
cnt = libc.Int64FromUint32(_jsonbArrayCount(tls, p, i))
|
|
}
|
|
if !(eErr != 0) {
|
|
Xsqlite3_result_int64(tls, ctx, cnt)
|
|
}
|
|
_jsonParseFree(tls, p)
|
|
}
|
|
|
|
// C documentation
|
|
//
|
|
// /* Constructor for the json_each virtual table */
|
|
func _jsonEachConnect(tls *libc.TLS, db uintptr, pAux uintptr, argc int32, argv uintptr, ppVtab uintptr, pzErr uintptr) (r int32) {
|
|
var pNew uintptr
|
|
var rc, v1 int32
|
|
_, _, _ = pNew, rc, v1
|
|
/* Column numbers */
|
|
/* The xBestIndex method assumes that the JSON and ROOT columns are
|
|
** the last two columns in the table. Should this ever changes, be
|
|
** sure to update the xBestIndex method. */
|
|
_ = pzErr
|
|
_ = argv
|
|
_ = argc
|
|
_ = pAux
|
|
rc = Xsqlite3_declare_vtab(tls, db, __ccgo_ts+26860)
|
|
if rc == SQLITE_OK {
|
|
pNew = _sqlite3DbMallocZero(tls, db, uint64(20))
|
|
**(**uintptr)(__ccgo_up(ppVtab)) = pNew
|
|
if pNew == uintptr(0) {
|
|
return int32(SQLITE_NOMEM)
|
|
}
|
|
Xsqlite3_vtab_config(tls, db, int32(SQLITE_VTAB_INNOCUOUS), 0)
|
|
(*TJsonEachConnection)(unsafe.Pointer(pNew)).Fdb = db
|
|
if int32(**(**int8)(__ccgo_up(**(**uintptr)(__ccgo_up(argv)) + 4))) == int32('b') {
|
|
v1 = int32(2)
|
|
} else {
|
|
v1 = int32(1)
|
|
}
|
|
(*TJsonEachConnection)(unsafe.Pointer(pNew)).FeMode = libc.Uint8FromInt32(v1)
|
|
(*TJsonEachConnection)(unsafe.Pointer(pNew)).FbRecursive = libc.BoolUint8(int32(**(**int8)(__ccgo_up(**(**uintptr)(__ccgo_up(argv)) + uintptr(int32(4)+libc.Int32FromUint8((*TJsonEachConnection)(unsafe.Pointer(pNew)).FeMode))))) == int32('t'))
|
|
}
|
|
return rc
|
|
}
|
|
|
|
// C documentation
|
|
//
|
|
// /* Start a search on a new JSON string */
|
|
func _jsonEachFilter(tls *libc.TLS, cur uintptr, idxNum int32, idxStr uintptr, argc int32, argv uintptr) (r int32) {
|
|
bp := tls.Alloc(16)
|
|
defer tls.Free(16)
|
|
var i, n, v1 Tu32
|
|
var p, zRoot uintptr
|
|
var v2 int32
|
|
var _ /* sz at bp+0 */ Tu32
|
|
_, _, _, _, _, _ = i, n, p, zRoot, v1, v2
|
|
p = cur
|
|
zRoot = uintptr(0)
|
|
_ = idxStr
|
|
_ = argc
|
|
_jsonEachCursorReset(tls, p)
|
|
if idxNum == 0 {
|
|
return SQLITE_OK
|
|
}
|
|
libc.Xmemset(tls, p+168, 0, uint32(56))
|
|
(*TJsonEachCursor)(unsafe.Pointer(p)).FsParse.FnJPRef = uint32(1)
|
|
(*TJsonEachCursor)(unsafe.Pointer(p)).FsParse.Fdb = (*TJsonEachCursor)(unsafe.Pointer(p)).Fdb
|
|
if _jsonArgIsJsonb(tls, **(**uintptr)(__ccgo_up(argv)), p+168) != 0 {
|
|
/* We have JSONB */
|
|
} else {
|
|
(*TJsonEachCursor)(unsafe.Pointer(p)).FsParse.FzJson = Xsqlite3_value_text(tls, **(**uintptr)(__ccgo_up(argv)))
|
|
(*TJsonEachCursor)(unsafe.Pointer(p)).FsParse.FnJson = Xsqlite3_value_bytes(tls, **(**uintptr)(__ccgo_up(argv)))
|
|
if (*TJsonEachCursor)(unsafe.Pointer(p)).FsParse.FzJson == uintptr(0) {
|
|
v1 = libc.Uint32FromInt32(0)
|
|
(*TJsonEachCursor)(unsafe.Pointer(p)).FiEnd = v1
|
|
(*TJsonEachCursor)(unsafe.Pointer(p)).Fi = v1
|
|
return SQLITE_OK
|
|
}
|
|
if _jsonConvertTextToBlob(tls, p+168, uintptr(0)) != 0 {
|
|
if (*TJsonEachCursor)(unsafe.Pointer(p)).FsParse.Foom != 0 {
|
|
return int32(SQLITE_NOMEM)
|
|
}
|
|
goto json_each_malformed_input
|
|
}
|
|
}
|
|
if idxNum == int32(3) {
|
|
zRoot = Xsqlite3_value_text(tls, **(**uintptr)(__ccgo_up(argv + 1*4)))
|
|
if zRoot == uintptr(0) {
|
|
return SQLITE_OK
|
|
}
|
|
if int32(**(**int8)(__ccgo_up(zRoot))) != int32('$') {
|
|
Xsqlite3_free(tls, (*Tsqlite3_vtab)(unsafe.Pointer((*Tsqlite3_vtab_cursor)(unsafe.Pointer(cur)).FpVtab)).FzErrMsg)
|
|
(*Tsqlite3_vtab)(unsafe.Pointer((*Tsqlite3_vtab_cursor)(unsafe.Pointer(cur)).FpVtab)).FzErrMsg = _jsonBadPathError(tls, uintptr(0), zRoot, 0)
|
|
_jsonEachCursorReset(tls, p)
|
|
if (*Tsqlite3_vtab)(unsafe.Pointer((*Tsqlite3_vtab_cursor)(unsafe.Pointer(cur)).FpVtab)).FzErrMsg != 0 {
|
|
v2 = int32(SQLITE_ERROR)
|
|
} else {
|
|
v2 = int32(SQLITE_NOMEM)
|
|
}
|
|
return v2
|
|
}
|
|
(*TJsonEachCursor)(unsafe.Pointer(p)).FnRoot = libc.Uint32FromInt32(_sqlite3Strlen30(tls, zRoot))
|
|
if int32(**(**int8)(__ccgo_up(zRoot + 1))) == 0 {
|
|
v1 = libc.Uint32FromInt32(0)
|
|
(*TJsonEachCursor)(unsafe.Pointer(p)).Fi = v1
|
|
i = v1
|
|
(*TJsonEachCursor)(unsafe.Pointer(p)).FeType = uint8(0)
|
|
} else {
|
|
i = _jsonLookupStep(tls, p+168, uint32(0), zRoot+uintptr(1), uint32(0))
|
|
if i >= uint32(JSON_LOOKUP_PATHERROR) {
|
|
if i == uint32(JSON_LOOKUP_NOTFOUND) {
|
|
(*TJsonEachCursor)(unsafe.Pointer(p)).Fi = uint32(0)
|
|
(*TJsonEachCursor)(unsafe.Pointer(p)).FeType = uint8(0)
|
|
(*TJsonEachCursor)(unsafe.Pointer(p)).FiEnd = uint32(0)
|
|
return SQLITE_OK
|
|
}
|
|
Xsqlite3_free(tls, (*Tsqlite3_vtab)(unsafe.Pointer((*Tsqlite3_vtab_cursor)(unsafe.Pointer(cur)).FpVtab)).FzErrMsg)
|
|
(*Tsqlite3_vtab)(unsafe.Pointer((*Tsqlite3_vtab_cursor)(unsafe.Pointer(cur)).FpVtab)).FzErrMsg = _jsonBadPathError(tls, uintptr(0), zRoot, 0)
|
|
_jsonEachCursorReset(tls, p)
|
|
if (*Tsqlite3_vtab)(unsafe.Pointer((*Tsqlite3_vtab_cursor)(unsafe.Pointer(cur)).FpVtab)).FzErrMsg != 0 {
|
|
v2 = int32(SQLITE_ERROR)
|
|
} else {
|
|
v2 = int32(SQLITE_NOMEM)
|
|
}
|
|
return v2
|
|
}
|
|
if (*TJsonEachCursor)(unsafe.Pointer(p)).FsParse.FiLabel != 0 {
|
|
(*TJsonEachCursor)(unsafe.Pointer(p)).Fi = (*TJsonEachCursor)(unsafe.Pointer(p)).FsParse.FiLabel
|
|
(*TJsonEachCursor)(unsafe.Pointer(p)).FeType = uint8(JSONB_OBJECT)
|
|
} else {
|
|
(*TJsonEachCursor)(unsafe.Pointer(p)).Fi = i
|
|
(*TJsonEachCursor)(unsafe.Pointer(p)).FeType = uint8(JSONB_ARRAY)
|
|
}
|
|
}
|
|
_jsonAppendRaw(tls, p+40, zRoot, (*TJsonEachCursor)(unsafe.Pointer(p)).FnRoot)
|
|
} else {
|
|
v1 = libc.Uint32FromInt32(0)
|
|
(*TJsonEachCursor)(unsafe.Pointer(p)).Fi = v1
|
|
i = v1
|
|
(*TJsonEachCursor)(unsafe.Pointer(p)).FeType = uint8(0)
|
|
(*TJsonEachCursor)(unsafe.Pointer(p)).FnRoot = uint32(1)
|
|
_jsonAppendRaw(tls, p+40, __ccgo_ts+26964, uint32(1))
|
|
}
|
|
(*TJsonEachCursor)(unsafe.Pointer(p)).FnParent = uint32(0)
|
|
n = _jsonbPayloadSize(tls, p+168, i, bp)
|
|
(*TJsonEachCursor)(unsafe.Pointer(p)).FiEnd = i + n + **(**Tu32)(__ccgo_up(bp))
|
|
if libc.Int32FromUint8(**(**Tu8)(__ccgo_up((*TJsonEachCursor)(unsafe.Pointer(p)).FsParse.FaBlob + uintptr(i))))&int32(0x0f) >= int32(JSONB_ARRAY) && !((*TJsonEachCursor)(unsafe.Pointer(p)).FbRecursive != 0) {
|
|
(*TJsonEachCursor)(unsafe.Pointer(p)).Fi = i + n
|
|
(*TJsonEachCursor)(unsafe.Pointer(p)).FeType = libc.Uint8FromInt32(libc.Int32FromUint8(**(**Tu8)(__ccgo_up((*TJsonEachCursor)(unsafe.Pointer(p)).FsParse.FaBlob + uintptr(i)))) & int32(0x0f))
|
|
(*TJsonEachCursor)(unsafe.Pointer(p)).FaParent = _sqlite3DbMallocZero(tls, (*TJsonEachCursor)(unsafe.Pointer(p)).Fdb, uint64(24))
|
|
if (*TJsonEachCursor)(unsafe.Pointer(p)).FaParent == uintptr(0) {
|
|
return int32(SQLITE_NOMEM)
|
|
}
|
|
(*TJsonEachCursor)(unsafe.Pointer(p)).FnParent = uint32(1)
|
|
(*TJsonEachCursor)(unsafe.Pointer(p)).FnParentAlloc = uint32(1)
|
|
(**(**TJsonParent)(__ccgo_up((*TJsonEachCursor)(unsafe.Pointer(p)).FaParent))).FiKey = 0
|
|
(**(**TJsonParent)(__ccgo_up((*TJsonEachCursor)(unsafe.Pointer(p)).FaParent))).FiEnd = (*TJsonEachCursor)(unsafe.Pointer(p)).FiEnd
|
|
(**(**TJsonParent)(__ccgo_up((*TJsonEachCursor)(unsafe.Pointer(p)).FaParent))).FiHead = (*TJsonEachCursor)(unsafe.Pointer(p)).Fi
|
|
(**(**TJsonParent)(__ccgo_up((*TJsonEachCursor)(unsafe.Pointer(p)).FaParent))).FiValue = i
|
|
}
|
|
return SQLITE_OK
|
|
goto json_each_malformed_input
|
|
json_each_malformed_input:
|
|
;
|
|
Xsqlite3_free(tls, (*Tsqlite3_vtab)(unsafe.Pointer((*Tsqlite3_vtab_cursor)(unsafe.Pointer(cur)).FpVtab)).FzErrMsg)
|
|
(*Tsqlite3_vtab)(unsafe.Pointer((*Tsqlite3_vtab_cursor)(unsafe.Pointer(cur)).FpVtab)).FzErrMsg = Xsqlite3_mprintf(tls, __ccgo_ts+26460, 0)
|
|
_jsonEachCursorReset(tls, p)
|
|
if (*Tsqlite3_vtab)(unsafe.Pointer((*Tsqlite3_vtab_cursor)(unsafe.Pointer(cur)).FpVtab)).FzErrMsg != 0 {
|
|
v2 = int32(SQLITE_ERROR)
|
|
} else {
|
|
v2 = int32(SQLITE_NOMEM)
|
|
}
|
|
return v2
|
|
}
|
|
|
|
// C documentation
|
|
//
|
|
// /*
|
|
// ** json_extract(JSON, PATH, ...)
|
|
// ** "->"(JSON,PATH)
|
|
// ** "->>"(JSON,PATH)
|
|
// **
|
|
// ** Return the element described by PATH. Return NULL if that PATH element
|
|
// ** is not found.
|
|
// **
|
|
// ** If JSON_JSON is set or if more that one PATH argument is supplied then
|
|
// ** always return a JSON representation of the result. If JSON_SQL is set,
|
|
// ** then always return an SQL representation of the result. If neither flag
|
|
// ** is present and argc==2, then return JSON for objects and arrays and SQL
|
|
// ** for all other values.
|
|
// **
|
|
// ** When multiple PATH arguments are supplied, the result is a JSON array
|
|
// ** containing the result of each PATH.
|
|
// **
|
|
// ** Abbreviated JSON path expressions are allows if JSON_ABPATH, for
|
|
// ** compatibility with PG.
|
|
// */
|
|
func _jsonExtractFunc(tls *libc.TLS, ctx uintptr, argc int32, argv uintptr) {
|
|
bp := tls.Alloc(128)
|
|
defer tls.Free(128)
|
|
var flags, i, nPath int32
|
|
var j Tu32
|
|
var p, zPath uintptr
|
|
var _ /* jx at bp+0 */ TJsonString
|
|
_, _, _, _, _, _ = flags, i, j, nPath, p, zPath
|
|
p = uintptr(0) /* String for array result */
|
|
if argc < int32(2) {
|
|
return
|
|
}
|
|
p = _jsonParseFuncArg(tls, ctx, **(**uintptr)(__ccgo_up(argv)), uint32(0))
|
|
if p == uintptr(0) {
|
|
return
|
|
}
|
|
flags = int32(Xsqlite3_user_data(tls, ctx))
|
|
_jsonStringInit(tls, bp, ctx)
|
|
if argc > int32(2) {
|
|
_jsonAppendChar(tls, bp, int8('['))
|
|
}
|
|
i = int32(1)
|
|
for {
|
|
if !(i < argc) {
|
|
break
|
|
}
|
|
/* With a single PATH argument */
|
|
zPath = Xsqlite3_value_text(tls, **(**uintptr)(__ccgo_up(argv + uintptr(i)*4)))
|
|
if zPath == uintptr(0) {
|
|
goto json_extract_error
|
|
}
|
|
nPath = _sqlite3Strlen30(tls, zPath)
|
|
if int32(**(**int8)(__ccgo_up(zPath))) == int32('$') {
|
|
j = _jsonLookupStep(tls, p, uint32(0), zPath+uintptr(1), uint32(0))
|
|
} else {
|
|
if flags&int32(JSON_ABPATH) != 0 {
|
|
/* The -> and ->> operators accept abbreviated PATH arguments. This
|
|
** is mostly for compatibility with PostgreSQL, but also for
|
|
** convenience.
|
|
**
|
|
** NUMBER ==> $[NUMBER] // PG compatible
|
|
** LABEL ==> $.LABEL // PG compatible
|
|
** [NUMBER] ==> $[NUMBER] // Not PG. Purely for convenience
|
|
**
|
|
** Updated 2024-05-27: If the NUMBER is negative, then PG counts from
|
|
** the right of the array. Hence for negative NUMBER:
|
|
**
|
|
** NUMBER ==> $[#NUMBER] // PG compatible
|
|
*/
|
|
_jsonStringInit(tls, bp, ctx)
|
|
if Xsqlite3_value_type(tls, **(**uintptr)(__ccgo_up(argv + uintptr(i)*4))) == int32(SQLITE_INTEGER) {
|
|
_jsonAppendRawNZ(tls, bp, __ccgo_ts+26672, uint32(1))
|
|
if int32(**(**int8)(__ccgo_up(zPath))) == int32('-') {
|
|
_jsonAppendRawNZ(tls, bp, __ccgo_ts+26674, uint32(1))
|
|
}
|
|
_jsonAppendRaw(tls, bp, zPath, libc.Uint32FromInt32(nPath))
|
|
_jsonAppendRawNZ(tls, bp, __ccgo_ts+5314, uint32(2))
|
|
} else {
|
|
if _jsonAllAlphanum(tls, zPath, nPath) != 0 {
|
|
_jsonAppendRawNZ(tls, bp, __ccgo_ts+1741, uint32(1))
|
|
_jsonAppendRaw(tls, bp, zPath, libc.Uint32FromInt32(nPath))
|
|
} else {
|
|
if int32(**(**int8)(__ccgo_up(zPath))) == int32('[') && nPath >= int32(3) && int32(**(**int8)(__ccgo_up(zPath + uintptr(nPath-int32(1))))) == int32(']') {
|
|
_jsonAppendRaw(tls, bp, zPath, libc.Uint32FromInt32(nPath))
|
|
} else {
|
|
_jsonAppendRawNZ(tls, bp, __ccgo_ts+26676, uint32(2))
|
|
_jsonAppendRaw(tls, bp, zPath, libc.Uint32FromInt32(nPath))
|
|
_jsonAppendRawNZ(tls, bp, __ccgo_ts+26679, uint32(1))
|
|
}
|
|
}
|
|
}
|
|
_jsonStringTerminate(tls, bp)
|
|
j = _jsonLookupStep(tls, p, uint32(0), (**(**TJsonString)(__ccgo_up(bp))).FzBuf, uint32(0))
|
|
_jsonStringReset(tls, bp)
|
|
} else {
|
|
_jsonBadPathError(tls, ctx, zPath, 0)
|
|
goto json_extract_error
|
|
}
|
|
}
|
|
if j < (*TJsonParse)(unsafe.Pointer(p)).FnBlob {
|
|
if argc == int32(2) {
|
|
if flags&int32(JSON_JSON) != 0 {
|
|
_jsonStringInit(tls, bp, ctx)
|
|
_jsonTranslateBlobToText(tls, p, j, bp)
|
|
_jsonReturnString(tls, bp, uintptr(0), uintptr(0))
|
|
_jsonStringReset(tls, bp)
|
|
Xsqlite3_result_subtype(tls, ctx, uint32(JSON_SUBTYPE))
|
|
} else {
|
|
_jsonReturnFromBlob(tls, p, j, ctx, 0)
|
|
if flags&(libc.Int32FromInt32(JSON_SQL)|libc.Int32FromInt32(JSON_BLOB)) == 0 && libc.Int32FromUint8(**(**Tu8)(__ccgo_up((*TJsonParse)(unsafe.Pointer(p)).FaBlob + uintptr(j))))&int32(0x0f) >= int32(JSONB_ARRAY) {
|
|
Xsqlite3_result_subtype(tls, ctx, uint32(JSON_SUBTYPE))
|
|
}
|
|
}
|
|
} else {
|
|
_jsonAppendSeparator(tls, bp)
|
|
_jsonTranslateBlobToText(tls, p, j, bp)
|
|
}
|
|
} else {
|
|
if j == uint32(JSON_LOOKUP_NOTFOUND) {
|
|
if argc == int32(2) {
|
|
goto json_extract_error /* Return NULL if not found */
|
|
} else {
|
|
_jsonAppendSeparator(tls, bp)
|
|
_jsonAppendRawNZ(tls, bp, __ccgo_ts+1688, uint32(4))
|
|
}
|
|
} else {
|
|
_jsonBadPathError(tls, ctx, zPath, libc.Int32FromUint32(j))
|
|
goto json_extract_error
|
|
}
|
|
}
|
|
goto _1
|
|
_1:
|
|
;
|
|
i = i + 1
|
|
}
|
|
if argc > int32(2) {
|
|
_jsonAppendChar(tls, bp, int8(']'))
|
|
_jsonReturnString(tls, bp, uintptr(0), uintptr(0))
|
|
if flags&int32(JSON_BLOB) == 0 {
|
|
Xsqlite3_result_subtype(tls, ctx, uint32(JSON_SUBTYPE))
|
|
}
|
|
}
|
|
goto json_extract_error
|
|
json_extract_error:
|
|
;
|
|
_jsonStringReset(tls, bp)
|
|
_jsonParseFree(tls, p)
|
|
return
|
|
}
|
|
|
|
/*
|
|
** Return codes for jsonMergePatch()
|
|
*/
|
|
|
|
// C documentation
|
|
//
|
|
// /*
|
|
// ** pArg is a function argument that might be an SQL value or a JSON
|
|
// ** value. Figure out what it is and encode it as a JSONB blob.
|
|
// ** Return the results in pParse.
|
|
// **
|
|
// ** pParse is uninitialized upon entry. This routine will handle the
|
|
// ** initialization of pParse. The result will be contained in
|
|
// ** pParse->aBlob and pParse->nBlob. pParse->aBlob might be dynamically
|
|
// ** allocated (if pParse->nBlobAlloc is greater than zero) in which case
|
|
// ** the caller is responsible for freeing the space allocated to pParse->aBlob
|
|
// ** when it has finished with it. Or pParse->aBlob might be a static string
|
|
// ** or a value obtained from sqlite3_value_blob(pArg).
|
|
// **
|
|
// ** If the argument is a BLOB that is clearly not a JSONB, then this
|
|
// ** function might set an error message in ctx and return non-zero.
|
|
// ** It might also set an error message and return non-zero on an OOM error.
|
|
// */
|
|
func _jsonFunctionArgToBlob(tls *libc.TLS, ctx uintptr, pArg uintptr, pParse uintptr) (r1 int32) {
|
|
var eType, n, n1, nJson int32
|
|
var r float64
|
|
var z, z1, zJson uintptr
|
|
_, _, _, _, _, _, _, _ = eType, n, n1, nJson, r, z, z1, zJson
|
|
eType = Xsqlite3_value_type(tls, pArg)
|
|
libc.Xmemset(tls, pParse, 0, uint32(56))
|
|
(*TJsonParse)(unsafe.Pointer(pParse)).Fdb = Xsqlite3_context_db_handle(tls, ctx)
|
|
switch eType {
|
|
default:
|
|
(*TJsonParse)(unsafe.Pointer(pParse)).FaBlob = uintptr(unsafe.Pointer(&_aNull))
|
|
(*TJsonParse)(unsafe.Pointer(pParse)).FnBlob = uint32(1)
|
|
return 0
|
|
case int32(SQLITE_BLOB):
|
|
if !(_jsonArgIsJsonb(tls, pArg, pParse) != 0) {
|
|
Xsqlite3_result_error(tls, ctx, __ccgo_ts+26431, -int32(1))
|
|
return int32(1)
|
|
}
|
|
case int32(SQLITE_TEXT):
|
|
zJson = Xsqlite3_value_text(tls, pArg)
|
|
nJson = Xsqlite3_value_bytes(tls, pArg)
|
|
if zJson == uintptr(0) {
|
|
return int32(1)
|
|
}
|
|
if Xsqlite3_value_subtype(tls, pArg) == uint32(JSON_SUBTYPE) {
|
|
(*TJsonParse)(unsafe.Pointer(pParse)).FzJson = zJson
|
|
(*TJsonParse)(unsafe.Pointer(pParse)).FnJson = nJson
|
|
if _jsonConvertTextToBlob(tls, pParse, ctx) != 0 {
|
|
Xsqlite3_result_error(tls, ctx, __ccgo_ts+26460, -int32(1))
|
|
_sqlite3DbFree(tls, (*TJsonParse)(unsafe.Pointer(pParse)).Fdb, (*TJsonParse)(unsafe.Pointer(pParse)).FaBlob)
|
|
libc.Xmemset(tls, pParse, 0, uint32(56))
|
|
return int32(1)
|
|
}
|
|
} else {
|
|
_jsonBlobAppendNode(tls, pParse, uint8(JSONB_TEXTRAW), libc.Uint64FromInt32(nJson), zJson)
|
|
}
|
|
case int32(SQLITE_FLOAT):
|
|
r = Xsqlite3_value_double(tls, pArg)
|
|
if _sqlite3IsNaN(tls, r) != 0 {
|
|
_jsonBlobAppendNode(tls, pParse, uint8(JSONB_NULL), uint64(0), uintptr(0))
|
|
} else {
|
|
n = Xsqlite3_value_bytes(tls, pArg)
|
|
z = Xsqlite3_value_text(tls, pArg)
|
|
if z == uintptr(0) {
|
|
return int32(1)
|
|
}
|
|
if int32(**(**int8)(__ccgo_up(z))) == int32('I') {
|
|
_jsonBlobAppendNode(tls, pParse, uint8(JSONB_FLOAT), uint64(5), __ccgo_ts+26565)
|
|
} else {
|
|
if int32(**(**int8)(__ccgo_up(z))) == int32('-') && int32(**(**int8)(__ccgo_up(z + 1))) == int32('I') {
|
|
_jsonBlobAppendNode(tls, pParse, uint8(JSONB_FLOAT), uint64(6), __ccgo_ts+26558)
|
|
} else {
|
|
_jsonBlobAppendNode(tls, pParse, uint8(JSONB_FLOAT), libc.Uint64FromInt32(n), z)
|
|
}
|
|
}
|
|
}
|
|
case int32(SQLITE_INTEGER):
|
|
n1 = Xsqlite3_value_bytes(tls, pArg)
|
|
z1 = Xsqlite3_value_text(tls, pArg)
|
|
if z1 == uintptr(0) {
|
|
return int32(1)
|
|
}
|
|
_jsonBlobAppendNode(tls, pParse, uint8(JSONB_INT), libc.Uint64FromInt32(n1), z1)
|
|
break
|
|
}
|
|
if (*TJsonParse)(unsafe.Pointer(pParse)).Foom != 0 {
|
|
Xsqlite3_result_error_nomem(tls, ctx)
|
|
return int32(1)
|
|
} else {
|
|
return 0
|
|
}
|
|
return r1
|
|
}
|
|
|
|
// C documentation
|
|
//
|
|
// /*
|
|
// ** Search along zPath to find the Json element specified. Return an
|
|
// ** index into pParse->aBlob[] for the start of that element's value.
|
|
// **
|
|
// ** If the value found by this routine is the value half of label/value pair
|
|
// ** within an object, then set pPath->iLabel to the start of the corresponding
|
|
// ** label, before returning.
|
|
// **
|
|
// ** Return one of the JSON_LOOKUP error codes if problems are seen.
|
|
// **
|
|
// ** This routine will also modify the blob. If pParse->eEdit is one of
|
|
// ** JEDIT_DEL, JEDIT_REPL, JEDIT_INS, JEDIT_SET, or JEDIT_AINS, then changes
|
|
// ** might be made to the selected value. If an edit is performed, then the
|
|
// ** return value does not necessarily point to the select element. If an edit
|
|
// ** is performed, the return value is only useful for detecting error
|
|
// ** conditions.
|
|
// */
|
|
func _jsonLookupStep(tls *libc.TLS, pParse uintptr, iRoot Tu32, zPath uintptr, iLabel Tu32) (r Tu32) {
|
|
bp := tls.Alloc(176)
|
|
defer tls.Free(176)
|
|
var i, iEnd, j, k, n, nIns, nKey, rc, v Tu32
|
|
var kk, nn Tu64
|
|
var rawKey, rawLabel, v5 int32
|
|
var x Tu8
|
|
var zKey, zLabel, v4 uintptr
|
|
var v3 Tu16
|
|
var _ /* ix at bp+60 */ TJsonParse
|
|
var _ /* sz at bp+0 */ Tu32
|
|
var _ /* v at bp+116 */ TJsonParse
|
|
var _ /* v at bp+4 */ TJsonParse
|
|
_, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _ = i, iEnd, j, k, kk, n, nIns, nKey, nn, rawKey, rawLabel, rc, v, x, zKey, zLabel, v3, v4, v5
|
|
if int32(**(**int8)(__ccgo_up(zPath))) == 0 {
|
|
if (*TJsonParse)(unsafe.Pointer(pParse)).FeEdit != 0 && _jsonBlobMakeEditable(tls, pParse, (*TJsonParse)(unsafe.Pointer(pParse)).FnIns) != 0 {
|
|
n = _jsonbPayloadSize(tls, pParse, iRoot, bp)
|
|
**(**Tu32)(__ccgo_up(bp)) = **(**Tu32)(__ccgo_up(bp)) + n
|
|
if libc.Int32FromUint8((*TJsonParse)(unsafe.Pointer(pParse)).FeEdit) == int32(JEDIT_DEL) {
|
|
if iLabel > uint32(0) {
|
|
**(**Tu32)(__ccgo_up(bp)) = **(**Tu32)(__ccgo_up(bp)) + (iRoot - iLabel)
|
|
iRoot = iLabel
|
|
}
|
|
_jsonBlobEdit(tls, pParse, iRoot, **(**Tu32)(__ccgo_up(bp)), uintptr(0), uint32(0))
|
|
} else {
|
|
if libc.Int32FromUint8((*TJsonParse)(unsafe.Pointer(pParse)).FeEdit) == int32(JEDIT_INS) {
|
|
/* Already exists, so json_insert() is a no-op */
|
|
} else {
|
|
if libc.Int32FromUint8((*TJsonParse)(unsafe.Pointer(pParse)).FeEdit) == int32(JEDIT_AINS) {
|
|
/* json_array_insert() */
|
|
if int32(**(**int8)(__ccgo_up(zPath + uintptr(-libc.Int32FromInt32(1))))) != int32(']') {
|
|
return uint32(JSON_LOOKUP_NOTARRAY)
|
|
} else {
|
|
_jsonBlobEdit(tls, pParse, iRoot, uint32(0), (*TJsonParse)(unsafe.Pointer(pParse)).FaIns, (*TJsonParse)(unsafe.Pointer(pParse)).FnIns)
|
|
}
|
|
} else {
|
|
/* json_set() or json_replace() */
|
|
_jsonBlobEdit(tls, pParse, iRoot, **(**Tu32)(__ccgo_up(bp)), (*TJsonParse)(unsafe.Pointer(pParse)).FaIns, (*TJsonParse)(unsafe.Pointer(pParse)).FnIns)
|
|
}
|
|
}
|
|
}
|
|
}
|
|
(*TJsonParse)(unsafe.Pointer(pParse)).FiLabel = iLabel
|
|
return iRoot
|
|
}
|
|
if int32(**(**int8)(__ccgo_up(zPath))) == int32('.') {
|
|
rawKey = int32(1)
|
|
x = **(**Tu8)(__ccgo_up((*TJsonParse)(unsafe.Pointer(pParse)).FaBlob + uintptr(iRoot)))
|
|
zPath = zPath + 1
|
|
if int32(**(**int8)(__ccgo_up(zPath))) == int32('"') {
|
|
zKey = zPath + uintptr(1)
|
|
i = uint32(1)
|
|
for {
|
|
if !(**(**int8)(__ccgo_up(zPath + uintptr(i))) != 0 && int32(**(**int8)(__ccgo_up(zPath + uintptr(i)))) != int32('"')) {
|
|
break
|
|
}
|
|
if int32(**(**int8)(__ccgo_up(zPath + uintptr(i)))) == int32('\\') && int32(**(**int8)(__ccgo_up(zPath + uintptr(i+uint32(1))))) != 0 {
|
|
i = i + 1
|
|
}
|
|
goto _1
|
|
_1:
|
|
;
|
|
i = i + 1
|
|
}
|
|
nKey = i - uint32(1)
|
|
if **(**int8)(__ccgo_up(zPath + uintptr(i))) != 0 {
|
|
i = i + 1
|
|
} else {
|
|
return uint32(JSON_LOOKUP_PATHERROR)
|
|
}
|
|
rawKey = libc.BoolInt32(libc.Xmemchr(tls, zKey, int32('\\'), nKey) == uintptr(0))
|
|
} else {
|
|
zKey = zPath
|
|
i = uint32(0)
|
|
for {
|
|
if !(**(**int8)(__ccgo_up(zPath + uintptr(i))) != 0 && int32(**(**int8)(__ccgo_up(zPath + uintptr(i)))) != int32('.') && int32(**(**int8)(__ccgo_up(zPath + uintptr(i)))) != int32('[')) {
|
|
break
|
|
}
|
|
goto _2
|
|
_2:
|
|
;
|
|
i = i + 1
|
|
}
|
|
nKey = i
|
|
if nKey == uint32(0) {
|
|
return uint32(JSON_LOOKUP_PATHERROR)
|
|
}
|
|
}
|
|
if libc.Int32FromUint8(x)&int32(0x0f) != int32(JSONB_OBJECT) {
|
|
return uint32(JSON_LOOKUP_NOTFOUND)
|
|
}
|
|
n = _jsonbPayloadSize(tls, pParse, iRoot, bp)
|
|
j = iRoot + n /* j is the index of a label */
|
|
iEnd = j + **(**Tu32)(__ccgo_up(bp))
|
|
for j < iEnd {
|
|
x = libc.Uint8FromInt32(libc.Int32FromUint8(**(**Tu8)(__ccgo_up((*TJsonParse)(unsafe.Pointer(pParse)).FaBlob + uintptr(j)))) & int32(0x0f))
|
|
if libc.Int32FromUint8(x) < int32(JSONB_TEXT) || libc.Int32FromUint8(x) > int32(JSONB_TEXTRAW) {
|
|
return uint32(JSON_LOOKUP_ERROR)
|
|
}
|
|
n = _jsonbPayloadSize(tls, pParse, j, bp)
|
|
if n == uint32(0) {
|
|
return uint32(JSON_LOOKUP_ERROR)
|
|
}
|
|
k = j + n /* k is the index of the label text */
|
|
if k+**(**Tu32)(__ccgo_up(bp)) >= iEnd {
|
|
return uint32(JSON_LOOKUP_ERROR)
|
|
}
|
|
zLabel = (*TJsonParse)(unsafe.Pointer(pParse)).FaBlob + uintptr(k)
|
|
rawLabel = libc.BoolInt32(libc.Int32FromUint8(x) == int32(JSONB_TEXT) || libc.Int32FromUint8(x) == int32(JSONB_TEXTRAW))
|
|
if _jsonLabelCompare(tls, zKey, nKey, rawKey, zLabel, **(**Tu32)(__ccgo_up(bp)), rawLabel) != 0 {
|
|
v = k + **(**Tu32)(__ccgo_up(bp)) /* v is the index of the value */
|
|
if libc.Int32FromUint8(**(**Tu8)(__ccgo_up((*TJsonParse)(unsafe.Pointer(pParse)).FaBlob + uintptr(v))))&int32(0x0f) > int32(JSONB_OBJECT) {
|
|
return uint32(JSON_LOOKUP_ERROR)
|
|
}
|
|
n = _jsonbPayloadSize(tls, pParse, v, bp)
|
|
if n == uint32(0) || v+n+**(**Tu32)(__ccgo_up(bp)) > iEnd {
|
|
return uint32(JSON_LOOKUP_ERROR)
|
|
}
|
|
v4 = pParse + 32
|
|
*(*Tu16)(unsafe.Pointer(v4)) = *(*Tu16)(unsafe.Pointer(v4)) + 1
|
|
v3 = *(*Tu16)(unsafe.Pointer(v4))
|
|
if libc.Int32FromUint16(v3) >= int32(JSON_MAX_DEPTH) {
|
|
return uint32(JSON_LOOKUP_TOODEEP)
|
|
}
|
|
rc = _jsonLookupStep(tls, pParse, v, zPath+uintptr(i), j)
|
|
(*TJsonParse)(unsafe.Pointer(pParse)).FiDepth = (*TJsonParse)(unsafe.Pointer(pParse)).FiDepth - 1
|
|
if (*TJsonParse)(unsafe.Pointer(pParse)).Fdelta != 0 {
|
|
_jsonAfterEditSizeAdjust(tls, pParse, iRoot)
|
|
}
|
|
return rc
|
|
}
|
|
j = k + **(**Tu32)(__ccgo_up(bp))
|
|
if libc.Int32FromUint8(**(**Tu8)(__ccgo_up((*TJsonParse)(unsafe.Pointer(pParse)).FaBlob + uintptr(j))))&int32(0x0f) > int32(JSONB_OBJECT) {
|
|
return uint32(JSON_LOOKUP_ERROR)
|
|
}
|
|
n = _jsonbPayloadSize(tls, pParse, j, bp)
|
|
if n == uint32(0) {
|
|
return uint32(JSON_LOOKUP_ERROR)
|
|
}
|
|
j = j + (n + **(**Tu32)(__ccgo_up(bp)))
|
|
}
|
|
if j > iEnd {
|
|
return uint32(JSON_LOOKUP_ERROR)
|
|
}
|
|
if libc.Int32FromUint8((*TJsonParse)(unsafe.Pointer(pParse)).FeEdit) >= int32(JEDIT_INS) { /* Header of the label to be inserted */
|
|
if libc.Int32FromUint8((*TJsonParse)(unsafe.Pointer(pParse)).FeEdit) == int32(JEDIT_AINS) && Xsqlite3_strglob(tls, __ccgo_ts+26605, zPath+uintptr(i)) != 0 {
|
|
return uint32(JSON_LOOKUP_NOTARRAY)
|
|
}
|
|
libc.Xmemset(tls, bp+60, 0, uint32(56))
|
|
(**(**TJsonParse)(__ccgo_up(bp + 60))).Fdb = (*TJsonParse)(unsafe.Pointer(pParse)).Fdb
|
|
if rawKey != 0 {
|
|
v5 = int32(JSONB_TEXTRAW)
|
|
} else {
|
|
v5 = int32(JSONB_TEXT5)
|
|
}
|
|
_jsonBlobAppendNode(tls, bp+60, libc.Uint8FromInt32(v5), uint64(nKey), uintptr(0))
|
|
v4 = pParse + 35
|
|
*(*Tu8)(unsafe.Pointer(v4)) = Tu8(int32(*(*Tu8)(unsafe.Pointer(v4))) | libc.Int32FromUint8((**(**TJsonParse)(__ccgo_up(bp + 60))).Foom))
|
|
rc = _jsonCreateEditSubstructure(tls, pParse, bp+4, zPath+uintptr(i))
|
|
if !(rc >= libc.Uint32FromUint32(JSON_LOOKUP_PATHERROR)) && _jsonBlobMakeEditable(tls, pParse, (**(**TJsonParse)(__ccgo_up(bp + 60))).FnBlob+nKey+(**(**TJsonParse)(__ccgo_up(bp + 4))).FnBlob) != 0 {
|
|
nIns = (**(**TJsonParse)(__ccgo_up(bp + 60))).FnBlob + nKey + (**(**TJsonParse)(__ccgo_up(bp + 4))).FnBlob
|
|
_jsonBlobEdit(tls, pParse, j, uint32(0), uintptr(0), nIns)
|
|
if !((*TJsonParse)(unsafe.Pointer(pParse)).Foom != 0) {
|
|
/* Because pParse->oom!=0 */
|
|
/* Because pPasre->oom!=0 */
|
|
libc.Xmemcpy(tls, (*TJsonParse)(unsafe.Pointer(pParse)).FaBlob+uintptr(j), (**(**TJsonParse)(__ccgo_up(bp + 60))).FaBlob, (**(**TJsonParse)(__ccgo_up(bp + 60))).FnBlob)
|
|
k = j + (**(**TJsonParse)(__ccgo_up(bp + 60))).FnBlob
|
|
libc.Xmemcpy(tls, (*TJsonParse)(unsafe.Pointer(pParse)).FaBlob+uintptr(k), zKey, nKey)
|
|
k = k + nKey
|
|
libc.Xmemcpy(tls, (*TJsonParse)(unsafe.Pointer(pParse)).FaBlob+uintptr(k), (**(**TJsonParse)(__ccgo_up(bp + 4))).FaBlob, (**(**TJsonParse)(__ccgo_up(bp + 4))).FnBlob)
|
|
if (*TJsonParse)(unsafe.Pointer(pParse)).Fdelta != 0 {
|
|
_jsonAfterEditSizeAdjust(tls, pParse, iRoot)
|
|
}
|
|
}
|
|
}
|
|
_jsonParseReset(tls, bp+4)
|
|
_jsonParseReset(tls, bp+60)
|
|
return rc
|
|
}
|
|
} else {
|
|
if int32(**(**int8)(__ccgo_up(zPath))) == int32('[') {
|
|
kk = uint64(0)
|
|
x = libc.Uint8FromInt32(libc.Int32FromUint8(**(**Tu8)(__ccgo_up((*TJsonParse)(unsafe.Pointer(pParse)).FaBlob + uintptr(iRoot)))) & int32(0x0f))
|
|
if libc.Int32FromUint8(x) != int32(JSONB_ARRAY) {
|
|
return uint32(JSON_LOOKUP_NOTFOUND)
|
|
}
|
|
n = _jsonbPayloadSize(tls, pParse, iRoot, bp)
|
|
i = uint32(1)
|
|
for libc.Int32FromUint8(_sqlite3CtypeMap[libc.Uint8FromInt8(**(**int8)(__ccgo_up(zPath + uintptr(i))))])&int32(0x04) != 0 {
|
|
if kk < uint64(0xffffffff) {
|
|
kk = kk*uint64(10) + libc.Uint64FromInt8(**(**int8)(__ccgo_up(zPath + uintptr(i)))) - uint64('0')
|
|
}
|
|
/* ^^^^^^^^^^--- Allow kk to be bigger than any JSON array so that
|
|
** we get NOTFOUND instead of PATHERROR, without overflowing kk. */
|
|
i = i + 1
|
|
}
|
|
if i < uint32(2) || int32(**(**int8)(__ccgo_up(zPath + uintptr(i)))) != int32(']') {
|
|
if int32(**(**int8)(__ccgo_up(zPath + 1))) == int32('#') {
|
|
kk = uint64(_jsonbArrayCount(tls, pParse, iRoot))
|
|
i = uint32(2)
|
|
if int32(**(**int8)(__ccgo_up(zPath + 2))) == int32('-') && libc.Int32FromUint8(_sqlite3CtypeMap[libc.Uint8FromInt8(**(**int8)(__ccgo_up(zPath + 3)))])&int32(0x04) != 0 {
|
|
nn = uint64(0)
|
|
i = uint32(3)
|
|
for cond := true; cond; cond = libc.Int32FromUint8(_sqlite3CtypeMap[libc.Uint8FromInt8(**(**int8)(__ccgo_up(zPath + uintptr(i))))])&int32(0x04) != 0 {
|
|
if nn < uint64(0xffffffff) {
|
|
nn = nn*uint64(10) + libc.Uint64FromInt8(**(**int8)(__ccgo_up(zPath + uintptr(i)))) - uint64('0')
|
|
}
|
|
/* ^^^^^^^^^^--- Allow nn to be bigger than any JSON array to
|
|
** get NOTFOUND instead of PATHERROR, without overflowing nn. */
|
|
i = i + 1
|
|
}
|
|
if nn > kk {
|
|
return uint32(JSON_LOOKUP_NOTFOUND)
|
|
}
|
|
kk = kk - nn
|
|
}
|
|
if int32(**(**int8)(__ccgo_up(zPath + uintptr(i)))) != int32(']') {
|
|
return uint32(JSON_LOOKUP_PATHERROR)
|
|
}
|
|
} else {
|
|
return uint32(JSON_LOOKUP_PATHERROR)
|
|
}
|
|
}
|
|
j = iRoot + n
|
|
iEnd = j + **(**Tu32)(__ccgo_up(bp))
|
|
for j < iEnd {
|
|
if kk == uint64(0) {
|
|
v4 = pParse + 32
|
|
*(*Tu16)(unsafe.Pointer(v4)) = *(*Tu16)(unsafe.Pointer(v4)) + 1
|
|
v3 = *(*Tu16)(unsafe.Pointer(v4))
|
|
if libc.Int32FromUint16(v3) >= int32(JSON_MAX_DEPTH) {
|
|
return uint32(JSON_LOOKUP_TOODEEP)
|
|
}
|
|
rc = _jsonLookupStep(tls, pParse, j, zPath+uintptr(i+uint32(1)), uint32(0))
|
|
(*TJsonParse)(unsafe.Pointer(pParse)).FiDepth = (*TJsonParse)(unsafe.Pointer(pParse)).FiDepth - 1
|
|
if (*TJsonParse)(unsafe.Pointer(pParse)).Fdelta != 0 {
|
|
_jsonAfterEditSizeAdjust(tls, pParse, iRoot)
|
|
}
|
|
return rc
|
|
}
|
|
kk = kk - 1
|
|
n = _jsonbPayloadSize(tls, pParse, j, bp)
|
|
if n == uint32(0) {
|
|
return uint32(JSON_LOOKUP_ERROR)
|
|
}
|
|
j = j + (n + **(**Tu32)(__ccgo_up(bp)))
|
|
}
|
|
if j > iEnd {
|
|
return uint32(JSON_LOOKUP_ERROR)
|
|
}
|
|
if kk > uint64(0) {
|
|
return uint32(JSON_LOOKUP_NOTFOUND)
|
|
}
|
|
if libc.Int32FromUint8((*TJsonParse)(unsafe.Pointer(pParse)).FeEdit) >= int32(JEDIT_INS) {
|
|
rc = _jsonCreateEditSubstructure(tls, pParse, bp+116, zPath+uintptr(i+uint32(1)))
|
|
if !(rc >= libc.Uint32FromUint32(JSON_LOOKUP_PATHERROR)) && _jsonBlobMakeEditable(tls, pParse, (**(**TJsonParse)(__ccgo_up(bp + 116))).FnBlob) != 0 {
|
|
_jsonBlobEdit(tls, pParse, j, uint32(0), (**(**TJsonParse)(__ccgo_up(bp + 116))).FaBlob, (**(**TJsonParse)(__ccgo_up(bp + 116))).FnBlob)
|
|
}
|
|
_jsonParseReset(tls, bp+116)
|
|
if (*TJsonParse)(unsafe.Pointer(pParse)).Fdelta != 0 {
|
|
_jsonAfterEditSizeAdjust(tls, pParse, iRoot)
|
|
}
|
|
return rc
|
|
}
|
|
} else {
|
|
return uint32(JSON_LOOKUP_PATHERROR)
|
|
}
|
|
}
|
|
return uint32(JSON_LOOKUP_NOTFOUND)
|
|
}
|
|
|
|
func _jsonObjectCompute(tls *libc.TLS, ctx uintptr, isFinal int32) {
|
|
bp := tls.Alloc(128)
|
|
defer tls.Free(128)
|
|
var c int8
|
|
var flags, inStr int32
|
|
var i, j, v2, v3 Tu64
|
|
var pOgStr, pStr uintptr
|
|
var v8 Tsqlite3_destructor_type
|
|
var _ /* tmpStr at bp+0 */ TJsonString
|
|
_, _, _, _, _, _, _, _, _, _ = c, flags, i, inStr, j, pOgStr, pStr, v2, v3, v8
|
|
flags = int32(Xsqlite3_user_data(tls, ctx))
|
|
pStr = Xsqlite3_aggregate_context(tls, ctx, 0)
|
|
if pStr != 0 {
|
|
pOgStr = pStr
|
|
_jsonAppendRawNZ(tls, pOgStr, __ccgo_ts+26855, uint32(2)) /* Ensure it is zero-terminated */
|
|
_jsonStringTrimOneChar(tls, pOgStr) /* Remove the zero terminator */
|
|
(*TJsonString)(unsafe.Pointer(pStr)).FpCtx = ctx
|
|
if (*TJsonString)(unsafe.Pointer(pStr)).FeErr != 0 {
|
|
_jsonReturnString(tls, pStr, uintptr(0), uintptr(0))
|
|
return
|
|
}
|
|
if int32(**(**int8)(__ccgo_up((*TJsonString)(unsafe.Pointer(pStr)).FzBuf))) != int32('{') {
|
|
inStr = 0
|
|
if !(isFinal != 0) {
|
|
/* Work with a temporary copy of the string if this is not the
|
|
** final result */
|
|
_jsonStringInit(tls, bp, ctx)
|
|
_jsonAppendRawNZ(tls, bp, (*TJsonString)(unsafe.Pointer(pStr)).FzBuf, uint32((*TJsonString)(unsafe.Pointer(pStr)).FnUsed+uint64(1)))
|
|
pStr = bp
|
|
if (*TJsonString)(unsafe.Pointer(pStr)).FeErr != 0 {
|
|
_jsonReturnString(tls, pStr, uintptr(0), uintptr(0))
|
|
return
|
|
}
|
|
_jsonStringTrimOneChar(tls, pStr) /* Remove zero terminator */
|
|
}
|
|
/* Fix up the string by changing the initial "@" flag back to
|
|
** to "{" and removing all subsequence "@" entries, with their
|
|
** associated comma delimeters. */
|
|
**(**int8)(__ccgo_up((*TJsonString)(unsafe.Pointer(pStr)).FzBuf)) = int8('{')
|
|
v2 = libc.Uint64FromInt32(1)
|
|
j = v2
|
|
i = v2
|
|
for {
|
|
if !(i < (*TJsonString)(unsafe.Pointer(pStr)).FnUsed) {
|
|
break
|
|
}
|
|
c = **(**int8)(__ccgo_up((*TJsonString)(unsafe.Pointer(pStr)).FzBuf + uintptr(i)))
|
|
if int32(c) == int32('"') {
|
|
inStr = libc.BoolInt32(!(inStr != 0))
|
|
v2 = j
|
|
j = j + 1
|
|
**(**int8)(__ccgo_up((*TJsonString)(unsafe.Pointer(pStr)).FzBuf + uintptr(v2))) = int8('"')
|
|
} else {
|
|
if int32(c) == int32('\\') {
|
|
v2 = j
|
|
j = j + 1
|
|
**(**int8)(__ccgo_up((*TJsonString)(unsafe.Pointer(pStr)).FzBuf + uintptr(v2))) = int8('\\')
|
|
v2 = j
|
|
j = j + 1
|
|
i = i + 1
|
|
v3 = i
|
|
**(**int8)(__ccgo_up((*TJsonString)(unsafe.Pointer(pStr)).FzBuf + uintptr(v2))) = **(**int8)(__ccgo_up((*TJsonString)(unsafe.Pointer(pStr)).FzBuf + uintptr(v3)))
|
|
} else {
|
|
if int32(c) == int32('@') && !(inStr != 0) {
|
|
if int32(**(**int8)(__ccgo_up((*TJsonString)(unsafe.Pointer(pStr)).FzBuf + uintptr(i+uint64(1))))) == int32(',') {
|
|
i = i + 1
|
|
} else {
|
|
if int32(**(**int8)(__ccgo_up((*TJsonString)(unsafe.Pointer(pStr)).FzBuf + uintptr(j-uint64(1))))) == int32(',') {
|
|
j = j - 1
|
|
}
|
|
}
|
|
} else {
|
|
v2 = j
|
|
j = j + 1
|
|
**(**int8)(__ccgo_up((*TJsonString)(unsafe.Pointer(pStr)).FzBuf + uintptr(v2))) = c
|
|
}
|
|
}
|
|
}
|
|
goto _1
|
|
_1:
|
|
;
|
|
i = i + 1
|
|
}
|
|
**(**int8)(__ccgo_up((*TJsonString)(unsafe.Pointer(pStr)).FzBuf + uintptr(j))) = 0 /* Restore zero terminator */
|
|
(*TJsonString)(unsafe.Pointer(pStr)).FnUsed = j /* Truncate the string */
|
|
}
|
|
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, pOgStr)
|
|
}
|
|
} else {
|
|
if isFinal != 0 {
|
|
if (*TJsonString)(unsafe.Pointer(pStr)).FbStatic != 0 {
|
|
v8 = uintptr(-libc.Int32FromInt32(1))
|
|
} else {
|
|
v8 = __ccgo_fp(_sqlite3RCStrUnref)
|
|
}
|
|
Xsqlite3_result_text(tls, ctx, (*TJsonString)(unsafe.Pointer(pStr)).FzBuf, libc.Int32FromUint64((*TJsonString)(unsafe.Pointer(pStr)).FnUsed), v8)
|
|
(*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, pOgStr)
|
|
}
|
|
}
|
|
if pStr != pOgStr {
|
|
_jsonStringReset(tls, pStr)
|
|
}
|
|
} else {
|
|
if flags&int32(JSON_BLOB) != 0 {
|
|
Xsqlite3_result_blob(tls, ctx, uintptr(unsafe.Pointer(&_emptyObject1)), int32(1), libc.UintptrFromInt32(0))
|
|
} else {
|
|
Xsqlite3_result_text(tls, ctx, __ccgo_ts+26857, int32(2), libc.UintptrFromInt32(0))
|
|
}
|
|
}
|
|
Xsqlite3_result_subtype(tls, ctx, uint32(JSON_SUBTYPE))
|
|
}
|
|
|
|
// C documentation
|
|
//
|
|
// /*
|
|
// ** Implementation of the json_object(NAME,VALUE,...) function. Return a JSON
|
|
// ** object that contains all name/value given in arguments. Or if any name
|
|
// ** is not a string or if any value is a BLOB, throw an error.
|
|
// */
|
|
func _jsonObjectFunc(tls *libc.TLS, ctx uintptr, argc int32, argv uintptr) {
|
|
bp := tls.Alloc(128)
|
|
defer tls.Free(128)
|
|
var i int32
|
|
var n Tu32
|
|
var z uintptr
|
|
var _ /* jx at bp+0 */ TJsonString
|
|
_, _, _ = i, n, z
|
|
if argc&int32(1) != 0 {
|
|
Xsqlite3_result_error(tls, ctx, __ccgo_ts+26681, -int32(1))
|
|
return
|
|
}
|
|
_jsonStringInit(tls, bp, ctx)
|
|
_jsonAppendChar(tls, bp, int8('{'))
|
|
i = 0
|
|
for {
|
|
if !(i < argc) {
|
|
break
|
|
}
|
|
if Xsqlite3_value_type(tls, **(**uintptr)(__ccgo_up(argv + uintptr(i)*4))) != int32(SQLITE_TEXT) {
|
|
Xsqlite3_result_error(tls, ctx, __ccgo_ts+26732, -int32(1))
|
|
_jsonStringReset(tls, bp)
|
|
return
|
|
}
|
|
_jsonAppendSeparator(tls, bp)
|
|
z = Xsqlite3_value_text(tls, **(**uintptr)(__ccgo_up(argv + uintptr(i)*4)))
|
|
n = libc.Uint32FromInt32(Xsqlite3_value_bytes(tls, **(**uintptr)(__ccgo_up(argv + uintptr(i)*4))))
|
|
_jsonAppendString(tls, bp, z, n)
|
|
_jsonAppendChar(tls, bp, int8(':'))
|
|
_jsonAppendSqlValue(tls, bp, **(**uintptr)(__ccgo_up(argv + uintptr(i+int32(1))*4)))
|
|
goto _1
|
|
_1:
|
|
;
|
|
i = i + int32(2)
|
|
}
|
|
_jsonAppendChar(tls, bp, int8('}'))
|
|
_jsonReturnString(tls, bp, uintptr(0), uintptr(0))
|
|
Xsqlite3_result_subtype(tls, ctx, uint32(JSON_SUBTYPE))
|
|
}
|
|
|
|
// C documentation
|
|
//
|
|
// /*
|
|
// ** json_group_obj(NAME,VALUE)
|
|
// **
|
|
// ** Return a JSON object composed of all names and values in the aggregate.
|
|
// **
|
|
// ** Rows for which NAME is NULL do not result in a new entry. However, we
|
|
// ** do initially insert a "@" entry into the growing string for each null entry
|
|
// ** and change the first character of the string to "@" to signal that the
|
|
// ** string contains null entries. The "@" markers are needed in order to
|
|
// ** correctly process xInverse() requests. The initial "@" is converted
|
|
// ** back into "{" and the "@" null values are removed by jsonObjectCompute().
|
|
// */
|
|
func _jsonObjectStep(tls *libc.TLS, ctx uintptr, argc int32, argv uintptr) {
|
|
var n Tu32
|
|
var pStr, z uintptr
|
|
_, _, _ = n, pStr, z
|
|
_ = argc
|
|
pStr = Xsqlite3_aggregate_context(tls, ctx, int32(128))
|
|
if pStr != 0 {
|
|
z = Xsqlite3_value_text(tls, **(**uintptr)(__ccgo_up(argv)))
|
|
n = libc.Uint32FromInt32(_sqlite3Strlen30(tls, z))
|
|
if (*TJsonString)(unsafe.Pointer(pStr)).FzBuf == uintptr(0) {
|
|
_jsonStringInit(tls, pStr, ctx)
|
|
_jsonAppendChar(tls, pStr, int8('{'))
|
|
} else {
|
|
if (*TJsonString)(unsafe.Pointer(pStr)).FnUsed > uint64(1) {
|
|
_jsonAppendChar(tls, pStr, int8(','))
|
|
}
|
|
}
|
|
(*TJsonString)(unsafe.Pointer(pStr)).FpCtx = ctx
|
|
if z != uintptr(0) {
|
|
_jsonAppendString(tls, pStr, z, n)
|
|
_jsonAppendChar(tls, pStr, int8(':'))
|
|
_jsonAppendSqlValue(tls, pStr, **(**uintptr)(__ccgo_up(argv + 1*4)))
|
|
} else {
|
|
**(**int8)(__ccgo_up((*TJsonString)(unsafe.Pointer(pStr)).FzBuf)) = int8('@')
|
|
_jsonAppendRawNZ(tls, pStr, __ccgo_ts+26670, uint32(1))
|
|
}
|
|
}
|
|
}
|
|
|
|
// C documentation
|
|
//
|
|
// /*
|
|
// ** Generate a JsonParse object, containing valid JSONB in aBlob and nBlob,
|
|
// ** from the SQL function argument pArg. Return a pointer to the new
|
|
// ** JsonParse object.
|
|
// **
|
|
// ** Ownership of the new JsonParse object is passed to the caller. The
|
|
// ** caller should invoke jsonParseFree() on the return value when it
|
|
// ** has finished using it.
|
|
// **
|
|
// ** If any errors are detected, an appropriate error messages is set
|
|
// ** using sqlite3_result_error() or the equivalent and this routine
|
|
// ** returns NULL. This routine also returns NULL if the pArg argument
|
|
// ** is an SQL NULL value, but no error message is set in that case. This
|
|
// ** is so that SQL functions that are given NULL arguments will return
|
|
// ** a NULL value.
|
|
// */
|
|
func _jsonParseFuncArg(tls *libc.TLS, ctx uintptr, pArg uintptr, flgs Tu32) (r uintptr) {
|
|
var db, p, pFromCache, zNew, v2 uintptr
|
|
var eType, isRCStr, rc int32
|
|
var nBlob, v1 Tu32
|
|
_, _, _, _, _, _, _, _, _, _ = db, eType, isRCStr, nBlob, p, pFromCache, rc, zNew, v1, v2 /* Datatype of pArg */
|
|
p = uintptr(0) /* Value to be returned */
|
|
pFromCache = uintptr(0) /* The database connection */
|
|
eType = Xsqlite3_value_type(tls, pArg)
|
|
if eType == int32(SQLITE_NULL) {
|
|
return uintptr(0)
|
|
}
|
|
pFromCache = _jsonCacheSearch(tls, ctx, pArg)
|
|
if pFromCache != 0 {
|
|
(*TJsonParse)(unsafe.Pointer(pFromCache)).FnJPRef = (*TJsonParse)(unsafe.Pointer(pFromCache)).FnJPRef + 1
|
|
if flgs&uint32(JSON_EDITABLE) == uint32(0) {
|
|
return pFromCache
|
|
}
|
|
}
|
|
db = Xsqlite3_context_db_handle(tls, ctx)
|
|
goto rebuild_from_cache
|
|
rebuild_from_cache:
|
|
;
|
|
p = _sqlite3DbMallocZero(tls, db, uint64(56))
|
|
if p == uintptr(0) {
|
|
goto json_pfa_oom
|
|
}
|
|
libc.Xmemset(tls, p, 0, uint32(56))
|
|
(*TJsonParse)(unsafe.Pointer(p)).Fdb = db
|
|
(*TJsonParse)(unsafe.Pointer(p)).FnJPRef = uint32(1)
|
|
if pFromCache != uintptr(0) {
|
|
nBlob = (*TJsonParse)(unsafe.Pointer(pFromCache)).FnBlob
|
|
(*TJsonParse)(unsafe.Pointer(p)).FaBlob = _sqlite3DbMallocRaw(tls, db, uint64(nBlob))
|
|
if (*TJsonParse)(unsafe.Pointer(p)).FaBlob == uintptr(0) {
|
|
goto json_pfa_oom
|
|
}
|
|
libc.Xmemcpy(tls, (*TJsonParse)(unsafe.Pointer(p)).FaBlob, (*TJsonParse)(unsafe.Pointer(pFromCache)).FaBlob, nBlob)
|
|
v1 = nBlob
|
|
(*TJsonParse)(unsafe.Pointer(p)).FnBlob = v1
|
|
(*TJsonParse)(unsafe.Pointer(p)).FnBlobAlloc = v1
|
|
(*TJsonParse)(unsafe.Pointer(p)).FhasNonstd = (*TJsonParse)(unsafe.Pointer(pFromCache)).FhasNonstd
|
|
_jsonParseFree(tls, pFromCache)
|
|
return p
|
|
}
|
|
if eType == int32(SQLITE_BLOB) {
|
|
if _jsonArgIsJsonb(tls, pArg, p) != 0 {
|
|
if flgs&uint32(JSON_EDITABLE) != uint32(0) && _jsonBlobMakeEditable(tls, p, uint32(0)) == 0 {
|
|
goto json_pfa_oom
|
|
}
|
|
return p
|
|
}
|
|
/* If the blob is not valid JSONB, fall through into trying to cast
|
|
** the blob into text which is then interpreted as JSON. (tag-20240123-a)
|
|
**
|
|
** This goes against all historical documentation about how the SQLite
|
|
** JSON functions were suppose to work. From the beginning, blob was
|
|
** reserved for expansion and a blob value should have raised an error.
|
|
** But it did not, due to a bug. And many applications came to depend
|
|
** upon this buggy behavior, especially when using the CLI and reading
|
|
** JSON text using readfile(), which returns a blob. For this reason
|
|
** we will continue to support the bug moving forward.
|
|
** See for example https://sqlite.org/forum/forumpost/012136abd5292b8d
|
|
*/
|
|
}
|
|
(*TJsonParse)(unsafe.Pointer(p)).FzJson = Xsqlite3_value_text(tls, pArg)
|
|
(*TJsonParse)(unsafe.Pointer(p)).FnJson = Xsqlite3_value_bytes(tls, pArg)
|
|
if (*Tsqlite3)(unsafe.Pointer(db)).FmallocFailed != 0 {
|
|
goto json_pfa_oom
|
|
}
|
|
if (*TJsonParse)(unsafe.Pointer(p)).FnJson == 0 {
|
|
goto json_pfa_malformed
|
|
}
|
|
if flgs&uint32(JSON_KEEPERROR) != 0 {
|
|
v2 = uintptr(0)
|
|
} else {
|
|
v2 = ctx
|
|
}
|
|
if _jsonConvertTextToBlob(tls, p, v2) != 0 {
|
|
if flgs&uint32(JSON_KEEPERROR) != 0 {
|
|
(*TJsonParse)(unsafe.Pointer(p)).FnErr = uint8(1)
|
|
return p
|
|
} else {
|
|
_jsonParseFree(tls, p)
|
|
return uintptr(0)
|
|
}
|
|
} else {
|
|
isRCStr = _sqlite3ValueIsOfClass(tls, pArg, __ccgo_fp(_sqlite3RCStrUnref))
|
|
if !(isRCStr != 0) {
|
|
zNew = _sqlite3RCStrNew(tls, libc.Uint64FromInt32((*TJsonParse)(unsafe.Pointer(p)).FnJson))
|
|
if zNew == uintptr(0) {
|
|
goto json_pfa_oom
|
|
}
|
|
libc.Xmemcpy(tls, zNew, (*TJsonParse)(unsafe.Pointer(p)).FzJson, libc.Uint32FromInt32((*TJsonParse)(unsafe.Pointer(p)).FnJson))
|
|
(*TJsonParse)(unsafe.Pointer(p)).FzJson = zNew
|
|
**(**int8)(__ccgo_up((*TJsonParse)(unsafe.Pointer(p)).FzJson + uintptr((*TJsonParse)(unsafe.Pointer(p)).FnJson))) = 0
|
|
} else {
|
|
_sqlite3RCStrRef(tls, (*TJsonParse)(unsafe.Pointer(p)).FzJson)
|
|
}
|
|
(*TJsonParse)(unsafe.Pointer(p)).FbJsonIsRCStr = uint8(1)
|
|
rc = _jsonCacheInsert(tls, ctx, p)
|
|
if rc == int32(SQLITE_NOMEM) {
|
|
goto json_pfa_oom
|
|
}
|
|
if flgs&uint32(JSON_EDITABLE) != 0 {
|
|
pFromCache = p
|
|
p = uintptr(0)
|
|
goto rebuild_from_cache
|
|
}
|
|
}
|
|
return p
|
|
goto json_pfa_malformed
|
|
json_pfa_malformed:
|
|
;
|
|
if flgs&uint32(JSON_KEEPERROR) != 0 {
|
|
(*TJsonParse)(unsafe.Pointer(p)).FnErr = uint8(1)
|
|
return p
|
|
} else {
|
|
_jsonParseFree(tls, p)
|
|
Xsqlite3_result_error(tls, ctx, __ccgo_ts+26460, -int32(1))
|
|
return uintptr(0)
|
|
}
|
|
goto json_pfa_oom
|
|
json_pfa_oom:
|
|
;
|
|
_jsonParseFree(tls, pFromCache)
|
|
_jsonParseFree(tls, p)
|
|
Xsqlite3_result_error_nomem(tls, ctx)
|
|
return uintptr(0)
|
|
}
|
|
|
|
// C documentation
|
|
//
|
|
// /*
|
|
// ** Return the value of the BLOB node at index i.
|
|
// **
|
|
// ** If the value is a primitive, return it as an SQL value.
|
|
// ** If the value is an array or object, return it as either
|
|
// ** JSON text or the BLOB encoding, depending on the eMode flag
|
|
// ** as follows:
|
|
// **
|
|
// ** eMode==0 JSONB if the JSON_B flag is set in userdata or
|
|
// ** text if the JSON_B flag is omitted from userdata.
|
|
// **
|
|
// ** eMode==1 Text
|
|
// **
|
|
// ** eMode==2 JSONB
|
|
// */
|
|
func _jsonReturnFromBlob(tls *libc.TLS, pParse uintptr, i Tu32, pCtx uintptr, eMode int32) {
|
|
bp := tls.Alloc(32)
|
|
defer tls.Free(32)
|
|
var bNeg, rc int32
|
|
var c, x int8
|
|
var db, z, z1, z2, zOut uintptr
|
|
var iIn, iOut, n, nOut, szEscape, v19, v20 Tu32
|
|
var r, v16 float64
|
|
var v17 int64
|
|
var _ /* iRes at bp+8 */ Tsqlite3_int64
|
|
var _ /* r at bp+16 */ float64
|
|
var _ /* sz at bp+0 */ Tu32
|
|
var _ /* v at bp+24 */ Tu32
|
|
_, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _ = bNeg, c, db, iIn, iOut, n, nOut, r, rc, szEscape, x, z, z1, z2, zOut, v16, v17, v19, v20
|
|
db = Xsqlite3_context_db_handle(tls, pCtx)
|
|
n = _jsonbPayloadSize(tls, pParse, i, bp)
|
|
if n == uint32(0) {
|
|
Xsqlite3_result_error(tls, pCtx, __ccgo_ts+26460, -int32(1))
|
|
return
|
|
}
|
|
switch libc.Int32FromUint8(**(**Tu8)(__ccgo_up((*TJsonParse)(unsafe.Pointer(pParse)).FaBlob + uintptr(i)))) & libc.Int32FromInt32(0x0f) {
|
|
case JSONB_NULL:
|
|
goto _1
|
|
case int32(JSONB_TRUE):
|
|
goto _2
|
|
case int32(JSONB_FALSE):
|
|
goto _3
|
|
case int32(JSONB_INT):
|
|
goto _4
|
|
case int32(JSONB_INT5):
|
|
goto _5
|
|
case int32(JSONB_FLOAT):
|
|
goto _6
|
|
case int32(JSONB_FLOAT5):
|
|
goto _7
|
|
case int32(JSONB_TEXT):
|
|
goto _8
|
|
case int32(JSONB_TEXTRAW):
|
|
goto _9
|
|
case int32(JSONB_TEXTJ):
|
|
goto _10
|
|
case int32(JSONB_TEXT5):
|
|
goto _11
|
|
case int32(JSONB_OBJECT):
|
|
goto _12
|
|
case int32(JSONB_ARRAY):
|
|
goto _13
|
|
default:
|
|
goto _14
|
|
}
|
|
goto _15
|
|
_1:
|
|
;
|
|
if **(**Tu32)(__ccgo_up(bp)) != 0 {
|
|
goto returnfromblob_malformed
|
|
}
|
|
Xsqlite3_result_null(tls, pCtx)
|
|
goto _15
|
|
_2:
|
|
;
|
|
if **(**Tu32)(__ccgo_up(bp)) != 0 {
|
|
goto returnfromblob_malformed
|
|
}
|
|
Xsqlite3_result_int(tls, pCtx, int32(1))
|
|
goto _15
|
|
_3:
|
|
;
|
|
if **(**Tu32)(__ccgo_up(bp)) != 0 {
|
|
goto returnfromblob_malformed
|
|
}
|
|
Xsqlite3_result_int(tls, pCtx, 0)
|
|
goto _15
|
|
_5:
|
|
;
|
|
_4:
|
|
;
|
|
**(**Tsqlite3_int64)(__ccgo_up(bp + 8)) = 0
|
|
bNeg = 0
|
|
if **(**Tu32)(__ccgo_up(bp)) == uint32(0) {
|
|
goto returnfromblob_malformed
|
|
}
|
|
x = libc.Int8FromUint8(**(**Tu8)(__ccgo_up((*TJsonParse)(unsafe.Pointer(pParse)).FaBlob + uintptr(i+n))))
|
|
if int32(x) == int32('-') {
|
|
if **(**Tu32)(__ccgo_up(bp)) < uint32(2) {
|
|
goto returnfromblob_malformed
|
|
}
|
|
n = n + 1
|
|
**(**Tu32)(__ccgo_up(bp)) = **(**Tu32)(__ccgo_up(bp)) - 1
|
|
bNeg = int32(1)
|
|
}
|
|
z = _sqlite3DbStrNDup(tls, db, (*TJsonParse)(unsafe.Pointer(pParse)).FaBlob+uintptr(i+n), libc.Uint64FromInt32(libc.Int32FromUint32(**(**Tu32)(__ccgo_up(bp)))))
|
|
if z == uintptr(0) {
|
|
goto returnfromblob_oom
|
|
}
|
|
rc = _sqlite3DecOrHexToI64(tls, z, bp+8)
|
|
_sqlite3DbFree(tls, db, z)
|
|
if rc == 0 {
|
|
if **(**Tsqlite3_int64)(__ccgo_up(bp + 8)) < 0 {
|
|
r = float64(**(**Tsqlite3_uint64)(__ccgo_up(bp + 8)))
|
|
if bNeg != 0 {
|
|
v16 = -r
|
|
} else {
|
|
v16 = r
|
|
}
|
|
Xsqlite3_result_double(tls, pCtx, v16)
|
|
} else {
|
|
if bNeg != 0 {
|
|
v17 = -**(**Tsqlite3_int64)(__ccgo_up(bp + 8))
|
|
} else {
|
|
v17 = **(**Tsqlite3_int64)(__ccgo_up(bp + 8))
|
|
}
|
|
Xsqlite3_result_int64(tls, pCtx, v17)
|
|
}
|
|
} else {
|
|
if rc == int32(3) && bNeg != 0 {
|
|
Xsqlite3_result_int64(tls, pCtx, int64(-libc.Int32FromInt32(1))-(libc.Int64FromUint32(0xffffffff)|libc.Int64FromInt32(0x7fffffff)<<libc.Int32FromInt32(32)))
|
|
} else {
|
|
if rc == int32(1) {
|
|
goto returnfromblob_malformed
|
|
} else {
|
|
if bNeg != 0 {
|
|
n = n - 1
|
|
**(**Tu32)(__ccgo_up(bp)) = **(**Tu32)(__ccgo_up(bp)) + 1
|
|
}
|
|
goto to_double
|
|
}
|
|
}
|
|
}
|
|
goto _15
|
|
_7:
|
|
;
|
|
_6:
|
|
;
|
|
if **(**Tu32)(__ccgo_up(bp)) == uint32(0) {
|
|
goto returnfromblob_malformed
|
|
}
|
|
goto to_double
|
|
to_double:
|
|
;
|
|
z1 = _sqlite3DbStrNDup(tls, db, (*TJsonParse)(unsafe.Pointer(pParse)).FaBlob+uintptr(i+n), libc.Uint64FromInt32(libc.Int32FromUint32(**(**Tu32)(__ccgo_up(bp)))))
|
|
if z1 == uintptr(0) {
|
|
goto returnfromblob_oom
|
|
}
|
|
rc = _sqlite3AtoF(tls, z1, bp+16)
|
|
_sqlite3DbFree(tls, db, z1)
|
|
if rc <= 0 {
|
|
goto returnfromblob_malformed
|
|
}
|
|
Xsqlite3_result_double(tls, pCtx, **(**float64)(__ccgo_up(bp + 16)))
|
|
goto _15
|
|
_9:
|
|
;
|
|
_8:
|
|
;
|
|
Xsqlite3_result_text(tls, pCtx, (*TJsonParse)(unsafe.Pointer(pParse)).FaBlob+uintptr(i+n), libc.Int32FromUint32(**(**Tu32)(__ccgo_up(bp))), uintptr(-libc.Int32FromInt32(1)))
|
|
goto _15
|
|
_11:
|
|
;
|
|
_10:
|
|
;
|
|
nOut = **(**Tu32)(__ccgo_up(bp))
|
|
z2 = (*TJsonParse)(unsafe.Pointer(pParse)).FaBlob + uintptr(i+n)
|
|
zOut = _sqlite3DbMallocRaw(tls, db, uint64(nOut)+uint64(1))
|
|
if zOut == uintptr(0) {
|
|
goto returnfromblob_oom
|
|
}
|
|
v19 = libc.Uint32FromInt32(0)
|
|
iOut = v19
|
|
iIn = v19
|
|
for {
|
|
if !(iIn < **(**Tu32)(__ccgo_up(bp))) {
|
|
break
|
|
}
|
|
c = **(**int8)(__ccgo_up(z2 + uintptr(iIn)))
|
|
if int32(c) == int32('\\') {
|
|
szEscape = _jsonUnescapeOneChar(tls, z2+uintptr(iIn), **(**Tu32)(__ccgo_up(bp))-iIn, bp+24)
|
|
if **(**Tu32)(__ccgo_up(bp + 24)) <= uint32(0x7f) {
|
|
v20 = iOut
|
|
iOut = iOut + 1
|
|
**(**int8)(__ccgo_up(zOut + uintptr(v20))) = libc.Int8FromUint32(**(**Tu32)(__ccgo_up(bp + 24)))
|
|
} else {
|
|
if **(**Tu32)(__ccgo_up(bp + 24)) <= uint32(0x7ff) {
|
|
v19 = iOut
|
|
iOut = iOut + 1
|
|
**(**int8)(__ccgo_up(zOut + uintptr(v19))) = libc.Int8FromUint32(libc.Uint32FromInt32(0xc0) | **(**Tu32)(__ccgo_up(bp + 24))>>libc.Int32FromInt32(6))
|
|
v19 = iOut
|
|
iOut = iOut + 1
|
|
**(**int8)(__ccgo_up(zOut + uintptr(v19))) = libc.Int8FromUint32(uint32(0x80) | **(**Tu32)(__ccgo_up(bp + 24))&uint32(0x3f))
|
|
} else {
|
|
if **(**Tu32)(__ccgo_up(bp + 24)) < uint32(0x10000) {
|
|
v19 = iOut
|
|
iOut = iOut + 1
|
|
**(**int8)(__ccgo_up(zOut + uintptr(v19))) = libc.Int8FromUint32(uint32(0xe0) | **(**Tu32)(__ccgo_up(bp + 24))>>libc.Int32FromInt32(12))
|
|
v19 = iOut
|
|
iOut = iOut + 1
|
|
**(**int8)(__ccgo_up(zOut + uintptr(v19))) = libc.Int8FromUint32(uint32(0x80) | **(**Tu32)(__ccgo_up(bp + 24))>>libc.Int32FromInt32(6)&uint32(0x3f))
|
|
v19 = iOut
|
|
iOut = iOut + 1
|
|
**(**int8)(__ccgo_up(zOut + uintptr(v19))) = libc.Int8FromUint32(uint32(0x80) | **(**Tu32)(__ccgo_up(bp + 24))&uint32(0x3f))
|
|
} else {
|
|
if **(**Tu32)(__ccgo_up(bp + 24)) == uint32(JSON_INVALID_CHAR) {
|
|
/* Silently ignore illegal unicode */
|
|
} else {
|
|
v19 = iOut
|
|
iOut = iOut + 1
|
|
**(**int8)(__ccgo_up(zOut + uintptr(v19))) = libc.Int8FromUint32(uint32(0xf0) | **(**Tu32)(__ccgo_up(bp + 24))>>libc.Int32FromInt32(18))
|
|
v19 = iOut
|
|
iOut = iOut + 1
|
|
**(**int8)(__ccgo_up(zOut + uintptr(v19))) = libc.Int8FromUint32(uint32(0x80) | **(**Tu32)(__ccgo_up(bp + 24))>>libc.Int32FromInt32(12)&uint32(0x3f))
|
|
v19 = iOut
|
|
iOut = iOut + 1
|
|
**(**int8)(__ccgo_up(zOut + uintptr(v19))) = libc.Int8FromUint32(uint32(0x80) | **(**Tu32)(__ccgo_up(bp + 24))>>libc.Int32FromInt32(6)&uint32(0x3f))
|
|
v19 = iOut
|
|
iOut = iOut + 1
|
|
**(**int8)(__ccgo_up(zOut + uintptr(v19))) = libc.Int8FromUint32(uint32(0x80) | **(**Tu32)(__ccgo_up(bp + 24))&uint32(0x3f))
|
|
}
|
|
}
|
|
}
|
|
}
|
|
iIn = iIn + (szEscape - uint32(1))
|
|
} else {
|
|
v19 = iOut
|
|
iOut = iOut + 1
|
|
**(**int8)(__ccgo_up(zOut + uintptr(v19))) = c
|
|
}
|
|
goto _18
|
|
_18:
|
|
;
|
|
iIn = iIn + 1
|
|
} /* end for() */
|
|
**(**int8)(__ccgo_up(zOut + uintptr(iOut))) = 0
|
|
Xsqlite3_result_text(tls, pCtx, zOut, libc.Int32FromUint32(iOut), __ccgo_fp(_sqlite3RowSetClear))
|
|
goto _15
|
|
_13:
|
|
;
|
|
_12:
|
|
;
|
|
if eMode == 0 {
|
|
if int32(Xsqlite3_user_data(tls, pCtx))&int32(JSON_BLOB) != 0 {
|
|
eMode = int32(2)
|
|
} else {
|
|
eMode = int32(1)
|
|
}
|
|
}
|
|
if eMode == int32(2) {
|
|
Xsqlite3_result_blob(tls, pCtx, (*TJsonParse)(unsafe.Pointer(pParse)).FaBlob+uintptr(i), libc.Int32FromUint32(**(**Tu32)(__ccgo_up(bp))+n), uintptr(-libc.Int32FromInt32(1)))
|
|
} else {
|
|
_jsonReturnTextJsonFromBlob(tls, pCtx, (*TJsonParse)(unsafe.Pointer(pParse)).FaBlob+uintptr(i), **(**Tu32)(__ccgo_up(bp))+n)
|
|
}
|
|
goto _15
|
|
_14:
|
|
;
|
|
goto returnfromblob_malformed
|
|
_15:
|
|
;
|
|
return
|
|
goto returnfromblob_oom
|
|
returnfromblob_oom:
|
|
;
|
|
Xsqlite3_result_error_nomem(tls, pCtx)
|
|
return
|
|
goto returnfromblob_malformed
|
|
returnfromblob_malformed:
|
|
;
|
|
Xsqlite3_result_error(tls, pCtx, __ccgo_ts+26460, -int32(1))
|
|
return
|
|
}
|
|
|
|
// C documentation
|
|
//
|
|
// /*
|
|
// ** Translate the binary JSONB representation of JSON beginning at
|
|
// ** pParse->aBlob[i] into a JSON text string. Append the JSON
|
|
// ** text onto the end of pOut. Return the index in pParse->aBlob[]
|
|
// ** of the first byte past the end of the element that is translated.
|
|
// **
|
|
// ** This is a variant of jsonTranslateBlobToText() that "pretty-prints"
|
|
// ** the output. Extra whitespace is inserted to make the JSON easier
|
|
// ** for humans to read.
|
|
// **
|
|
// ** If an error is detected in the BLOB input, the pOut->eErr flag
|
|
// ** might get set to JSTRING_MALFORMED. But not all BLOB input errors
|
|
// ** are detected. So a malformed JSONB input might either result
|
|
// ** in an error, or in incorrect JSON.
|
|
// **
|
|
// ** The pOut->eErr JSTRING_OOM flag is set on a OOM.
|
|
// */
|
|
func _jsonTranslateBlobToPrettyText(tls *libc.TLS, pPretty uintptr, i Tu32) (r Tu32) {
|
|
bp := tls.Alloc(16)
|
|
defer tls.Free(16)
|
|
var iEnd, j, n Tu32
|
|
var pOut, pParse, v1 uintptr
|
|
var _ /* sz at bp+0 */ Tu32
|
|
_, _, _, _, _, _ = iEnd, j, n, pOut, pParse, v1
|
|
pParse = (*TJsonPretty)(unsafe.Pointer(pPretty)).FpParse
|
|
pOut = (*TJsonPretty)(unsafe.Pointer(pPretty)).FpOut
|
|
n = _jsonbPayloadSize(tls, pParse, i, bp)
|
|
if n == uint32(0) {
|
|
v1 = pOut + 25
|
|
*(*Tu8)(unsafe.Pointer(v1)) = Tu8(int32(*(*Tu8)(unsafe.Pointer(v1))) | libc.Int32FromInt32(JSTRING_MALFORMED))
|
|
return (*TJsonParse)(unsafe.Pointer(pParse)).FnBlob + uint32(1)
|
|
}
|
|
switch libc.Int32FromUint8(**(**Tu8)(__ccgo_up((*TJsonParse)(unsafe.Pointer(pParse)).FaBlob + uintptr(i)))) & libc.Int32FromInt32(0x0f) {
|
|
case int32(JSONB_ARRAY):
|
|
j = i + n
|
|
iEnd = j + **(**Tu32)(__ccgo_up(bp))
|
|
_jsonAppendChar(tls, pOut, int8('['))
|
|
if j < iEnd {
|
|
_jsonAppendChar(tls, pOut, int8('\n'))
|
|
(*TJsonPretty)(unsafe.Pointer(pPretty)).FnIndent = (*TJsonPretty)(unsafe.Pointer(pPretty)).FnIndent + 1
|
|
if (*TJsonPretty)(unsafe.Pointer(pPretty)).FnIndent >= uint32(JSON_MAX_DEPTH) {
|
|
_jsonStringTooDeep(tls, pOut)
|
|
}
|
|
for libc.Int32FromUint8((*TJsonString)(unsafe.Pointer(pOut)).FeErr) == 0 {
|
|
_jsonPrettyIndent(tls, pPretty)
|
|
j = _jsonTranslateBlobToPrettyText(tls, pPretty, j)
|
|
if j >= iEnd {
|
|
break
|
|
}
|
|
_jsonAppendRawNZ(tls, pOut, __ccgo_ts+26599, uint32(2))
|
|
}
|
|
_jsonAppendChar(tls, pOut, int8('\n'))
|
|
(*TJsonPretty)(unsafe.Pointer(pPretty)).FnIndent = (*TJsonPretty)(unsafe.Pointer(pPretty)).FnIndent - 1
|
|
_jsonPrettyIndent(tls, pPretty)
|
|
}
|
|
_jsonAppendChar(tls, pOut, int8(']'))
|
|
i = iEnd
|
|
case int32(JSONB_OBJECT):
|
|
j = i + n
|
|
iEnd = j + **(**Tu32)(__ccgo_up(bp))
|
|
_jsonAppendChar(tls, pOut, int8('{'))
|
|
if j < iEnd {
|
|
_jsonAppendChar(tls, pOut, int8('\n'))
|
|
(*TJsonPretty)(unsafe.Pointer(pPretty)).FnIndent = (*TJsonPretty)(unsafe.Pointer(pPretty)).FnIndent + 1
|
|
if (*TJsonPretty)(unsafe.Pointer(pPretty)).FnIndent >= uint32(JSON_MAX_DEPTH) {
|
|
_jsonStringTooDeep(tls, pOut)
|
|
}
|
|
(*TJsonParse)(unsafe.Pointer(pParse)).FiDepth = uint16((*TJsonPretty)(unsafe.Pointer(pPretty)).FnIndent)
|
|
for libc.Int32FromUint8((*TJsonString)(unsafe.Pointer(pOut)).FeErr) == 0 {
|
|
_jsonPrettyIndent(tls, pPretty)
|
|
j = _jsonTranslateBlobToText(tls, pParse, j, pOut)
|
|
if j > iEnd {
|
|
v1 = pOut + 25
|
|
*(*Tu8)(unsafe.Pointer(v1)) = Tu8(int32(*(*Tu8)(unsafe.Pointer(v1))) | libc.Int32FromInt32(JSTRING_MALFORMED))
|
|
break
|
|
}
|
|
_jsonAppendRawNZ(tls, pOut, __ccgo_ts+26602, uint32(2))
|
|
j = _jsonTranslateBlobToPrettyText(tls, pPretty, j)
|
|
if j >= iEnd {
|
|
break
|
|
}
|
|
_jsonAppendRawNZ(tls, pOut, __ccgo_ts+26599, uint32(2))
|
|
}
|
|
_jsonAppendChar(tls, pOut, int8('\n'))
|
|
(*TJsonPretty)(unsafe.Pointer(pPretty)).FnIndent = (*TJsonPretty)(unsafe.Pointer(pPretty)).FnIndent - 1
|
|
_jsonPrettyIndent(tls, pPretty)
|
|
}
|
|
_jsonAppendChar(tls, pOut, int8('}'))
|
|
i = iEnd
|
|
default:
|
|
i = _jsonTranslateBlobToText(tls, pParse, i, pOut)
|
|
break
|
|
}
|
|
return i
|
|
}
|
|
|
|
// C documentation
|
|
//
|
|
// /*
|
|
// ** Translate the binary JSONB representation of JSON beginning at
|
|
// ** pParse->aBlob[i] into a JSON text string. Append the JSON
|
|
// ** text onto the end of pOut. Return the index in pParse->aBlob[]
|
|
// ** of the first byte past the end of the element that is translated.
|
|
// **
|
|
// ** If an error is detected in the BLOB input, the pOut->eErr flag
|
|
// ** might get set to JSTRING_MALFORMED. But not all BLOB input errors
|
|
// ** are detected. So a malformed JSONB input might either result
|
|
// ** in an error, or in incorrect JSON.
|
|
// **
|
|
// ** The pOut->eErr JSTRING_OOM flag is set on a OOM.
|
|
// */
|
|
func _jsonTranslateBlobToText(tls *libc.TLS, pParse uintptr, i Tu32, pOut uintptr) (r Tu32) {
|
|
bp := tls.Alloc(32)
|
|
defer tls.Free(32)
|
|
var bOverflow, x, v30, v31 int32
|
|
var iEnd, j, k, k1, k2, n, sz2 Tu32
|
|
var u Tsqlite3_uint64
|
|
var zIn, zIn1, zIn2, v1 uintptr
|
|
var v25 Tu16
|
|
var _ /* sz at bp+0 */ Tu32
|
|
_, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _ = bOverflow, iEnd, j, k, k1, k2, n, sz2, u, x, zIn, zIn1, zIn2, v1, v25, v30, v31
|
|
n = _jsonbPayloadSize(tls, pParse, i, bp)
|
|
if n == uint32(0) {
|
|
v1 = pOut + 25
|
|
*(*Tu8)(unsafe.Pointer(v1)) = Tu8(int32(*(*Tu8)(unsafe.Pointer(v1))) | libc.Int32FromInt32(JSTRING_MALFORMED))
|
|
return (*TJsonParse)(unsafe.Pointer(pParse)).FnBlob + uint32(1)
|
|
}
|
|
switch libc.Int32FromUint8(**(**Tu8)(__ccgo_up((*TJsonParse)(unsafe.Pointer(pParse)).FaBlob + uintptr(i)))) & libc.Int32FromInt32(0x0f) {
|
|
case JSONB_NULL:
|
|
goto _2
|
|
case int32(JSONB_TRUE):
|
|
goto _3
|
|
case int32(JSONB_FALSE):
|
|
goto _4
|
|
case int32(JSONB_FLOAT):
|
|
goto _5
|
|
case int32(JSONB_INT):
|
|
goto _6
|
|
case int32(JSONB_INT5):
|
|
goto _7
|
|
case int32(JSONB_FLOAT5):
|
|
goto _8
|
|
case int32(JSONB_TEXTJ):
|
|
goto _9
|
|
case int32(JSONB_TEXT):
|
|
goto _10
|
|
case int32(JSONB_TEXT5):
|
|
goto _11
|
|
case int32(JSONB_TEXTRAW):
|
|
goto _12
|
|
case int32(JSONB_ARRAY):
|
|
goto _13
|
|
case int32(JSONB_OBJECT):
|
|
goto _14
|
|
default:
|
|
goto _15
|
|
}
|
|
goto _16
|
|
_2:
|
|
;
|
|
_jsonAppendRawNZ(tls, pOut, __ccgo_ts+1688, uint32(4))
|
|
return i + uint32(1)
|
|
_3:
|
|
;
|
|
_jsonAppendRawNZ(tls, pOut, __ccgo_ts+8180, uint32(4))
|
|
return i + uint32(1)
|
|
_4:
|
|
;
|
|
_jsonAppendRawNZ(tls, pOut, __ccgo_ts+8185, uint32(5))
|
|
return i + uint32(1)
|
|
_6:
|
|
;
|
|
_5:
|
|
;
|
|
if **(**Tu32)(__ccgo_up(bp)) == uint32(0) {
|
|
goto malformed_jsonb
|
|
}
|
|
_jsonAppendRaw(tls, pOut, (*TJsonParse)(unsafe.Pointer(pParse)).FaBlob+uintptr(i+n), **(**Tu32)(__ccgo_up(bp)))
|
|
goto _16
|
|
_7:
|
|
; /* Integer literal in hexadecimal notation */
|
|
k = uint32(2)
|
|
u = uint64(0)
|
|
zIn = (*TJsonParse)(unsafe.Pointer(pParse)).FaBlob + uintptr(i+n)
|
|
bOverflow = 0
|
|
if **(**Tu32)(__ccgo_up(bp)) == uint32(0) {
|
|
goto malformed_jsonb
|
|
}
|
|
if int32(**(**int8)(__ccgo_up(zIn))) == int32('-') {
|
|
_jsonAppendChar(tls, pOut, int8('-'))
|
|
k = k + 1
|
|
} else {
|
|
if int32(**(**int8)(__ccgo_up(zIn))) == int32('+') {
|
|
k = k + 1
|
|
}
|
|
}
|
|
for {
|
|
if !(k < **(**Tu32)(__ccgo_up(bp))) {
|
|
break
|
|
}
|
|
if !(libc.Int32FromUint8(_sqlite3CtypeMap[libc.Uint8FromInt8(**(**int8)(__ccgo_up(zIn + uintptr(k))))])&libc.Int32FromInt32(0x08) != 0) {
|
|
v1 = pOut + 25
|
|
*(*Tu8)(unsafe.Pointer(v1)) = Tu8(int32(*(*Tu8)(unsafe.Pointer(v1))) | libc.Int32FromInt32(JSTRING_MALFORMED))
|
|
break
|
|
} else {
|
|
if u>>libc.Int32FromInt32(60) != uint64(0) {
|
|
bOverflow = int32(1)
|
|
} else {
|
|
u = u*uint64(16) + uint64(_sqlite3HexToInt(tls, int32(**(**int8)(__ccgo_up(zIn + uintptr(k))))))
|
|
}
|
|
}
|
|
goto _17
|
|
_17:
|
|
;
|
|
k = k + 1
|
|
}
|
|
if bOverflow != 0 {
|
|
v1 = __ccgo_ts + 26479
|
|
} else {
|
|
v1 = __ccgo_ts + 13006
|
|
}
|
|
_jsonPrintf(tls, int32(100), pOut, v1, libc.VaList(bp+16, u))
|
|
goto _16
|
|
_8:
|
|
; /* Float literal missing digits beside "." */
|
|
k1 = uint32(0)
|
|
zIn1 = (*TJsonParse)(unsafe.Pointer(pParse)).FaBlob + uintptr(i+n)
|
|
if **(**Tu32)(__ccgo_up(bp)) == uint32(0) {
|
|
goto malformed_jsonb
|
|
}
|
|
if int32(**(**int8)(__ccgo_up(zIn1))) == int32('-') {
|
|
_jsonAppendChar(tls, pOut, int8('-'))
|
|
k1 = k1 + 1
|
|
}
|
|
if int32(**(**int8)(__ccgo_up(zIn1 + uintptr(k1)))) == int32('.') {
|
|
_jsonAppendChar(tls, pOut, int8('0'))
|
|
}
|
|
for {
|
|
if !(k1 < **(**Tu32)(__ccgo_up(bp))) {
|
|
break
|
|
}
|
|
_jsonAppendChar(tls, pOut, **(**int8)(__ccgo_up(zIn1 + uintptr(k1))))
|
|
if int32(**(**int8)(__ccgo_up(zIn1 + uintptr(k1)))) == int32('.') && (k1+uint32(1) == **(**Tu32)(__ccgo_up(bp)) || !(libc.Int32FromUint8(_sqlite3CtypeMap[libc.Uint8FromInt8(**(**int8)(__ccgo_up(zIn1 + uintptr(k1+uint32(1)))))])&libc.Int32FromInt32(0x04) != 0)) {
|
|
_jsonAppendChar(tls, pOut, int8('0'))
|
|
}
|
|
goto _20
|
|
_20:
|
|
;
|
|
k1 = k1 + 1
|
|
}
|
|
goto _16
|
|
_10:
|
|
;
|
|
_9:
|
|
;
|
|
if (*TJsonString)(unsafe.Pointer(pOut)).FnUsed+uint64(**(**Tu32)(__ccgo_up(bp)))+uint64(2) <= (*TJsonString)(unsafe.Pointer(pOut)).FnAlloc || _jsonStringGrow(tls, pOut, **(**Tu32)(__ccgo_up(bp))+uint32(2)) == 0 {
|
|
**(**int8)(__ccgo_up((*TJsonString)(unsafe.Pointer(pOut)).FzBuf + uintptr((*TJsonString)(unsafe.Pointer(pOut)).FnUsed))) = int8('"')
|
|
libc.Xmemcpy(tls, (*TJsonString)(unsafe.Pointer(pOut)).FzBuf+uintptr((*TJsonString)(unsafe.Pointer(pOut)).FnUsed)+uintptr(1), (*TJsonParse)(unsafe.Pointer(pParse)).FaBlob+uintptr(i+n), **(**Tu32)(__ccgo_up(bp)))
|
|
**(**int8)(__ccgo_up((*TJsonString)(unsafe.Pointer(pOut)).FzBuf + uintptr((*TJsonString)(unsafe.Pointer(pOut)).FnUsed+uint64(**(**Tu32)(__ccgo_up(bp)))+uint64(1)))) = int8('"')
|
|
**(**Tu64)(__ccgo_up(pOut + 16)) += uint64(**(**Tu32)(__ccgo_up(bp)) + uint32(2))
|
|
}
|
|
goto _16
|
|
_11:
|
|
;
|
|
sz2 = **(**Tu32)(__ccgo_up(bp))
|
|
zIn2 = (*TJsonParse)(unsafe.Pointer(pParse)).FaBlob + uintptr(i+n)
|
|
_jsonAppendChar(tls, pOut, int8('"'))
|
|
for sz2 > uint32(0) {
|
|
k2 = uint32(0)
|
|
for {
|
|
if !(k2 < sz2 && (_jsonIsOk[libc.Uint8FromInt8(**(**int8)(__ccgo_up(zIn2 + uintptr(k2))))] != 0 || int32(**(**int8)(__ccgo_up(zIn2 + uintptr(k2)))) == int32('\''))) {
|
|
break
|
|
}
|
|
goto _21
|
|
_21:
|
|
;
|
|
k2 = k2 + 1
|
|
}
|
|
if k2 > uint32(0) {
|
|
_jsonAppendRawNZ(tls, pOut, zIn2, k2)
|
|
if k2 >= sz2 {
|
|
break
|
|
}
|
|
zIn2 = zIn2 + uintptr(k2)
|
|
sz2 = sz2 - k2
|
|
}
|
|
if int32(**(**int8)(__ccgo_up(zIn2))) == int32('"') {
|
|
_jsonAppendRawNZ(tls, pOut, __ccgo_ts+26577, uint32(2))
|
|
zIn2 = zIn2 + 1
|
|
sz2 = sz2 - 1
|
|
continue
|
|
}
|
|
if int32(**(**int8)(__ccgo_up(zIn2))) <= int32(0x1f) {
|
|
if (*TJsonString)(unsafe.Pointer(pOut)).FnUsed+uint64(7) > (*TJsonString)(unsafe.Pointer(pOut)).FnAlloc && _jsonStringGrow(tls, pOut, uint32(7)) != 0 {
|
|
break
|
|
}
|
|
_jsonAppendControlChar(tls, pOut, libc.Uint8FromInt8(**(**int8)(__ccgo_up(zIn2))))
|
|
zIn2 = zIn2 + 1
|
|
sz2 = sz2 - 1
|
|
continue
|
|
}
|
|
if sz2 < uint32(2) {
|
|
v1 = pOut + 25
|
|
*(*Tu8)(unsafe.Pointer(v1)) = Tu8(int32(*(*Tu8)(unsafe.Pointer(v1))) | libc.Int32FromInt32(JSTRING_MALFORMED))
|
|
break
|
|
}
|
|
switch libc.Int32FromUint8(libc.Uint8FromInt8(**(**int8)(__ccgo_up(zIn2 + 1)))) {
|
|
case int32('\''):
|
|
_jsonAppendChar(tls, pOut, int8('\''))
|
|
case int32('v'):
|
|
_jsonAppendRawNZ(tls, pOut, __ccgo_ts+26580, uint32(6))
|
|
case int32('x'):
|
|
if sz2 < uint32(4) {
|
|
v1 = pOut + 25
|
|
*(*Tu8)(unsafe.Pointer(v1)) = Tu8(int32(*(*Tu8)(unsafe.Pointer(v1))) | libc.Int32FromInt32(JSTRING_MALFORMED))
|
|
sz2 = uint32(2)
|
|
break
|
|
}
|
|
_jsonAppendRawNZ(tls, pOut, __ccgo_ts+26587, uint32(4))
|
|
_jsonAppendRawNZ(tls, pOut, zIn2+2, uint32(2))
|
|
zIn2 = zIn2 + uintptr(2)
|
|
sz2 = sz2 - uint32(2)
|
|
case int32('0'):
|
|
_jsonAppendRawNZ(tls, pOut, __ccgo_ts+26592, uint32(6))
|
|
case int32('\r'):
|
|
if sz2 > uint32(2) && int32(**(**int8)(__ccgo_up(zIn2 + 2))) == int32('\n') {
|
|
zIn2 = zIn2 + 1
|
|
sz2 = sz2 - 1
|
|
}
|
|
case int32('\n'):
|
|
case int32(0xe2):
|
|
/* '\' followed by either U+2028 or U+2029 is ignored as
|
|
** whitespace. Not that in UTF8, U+2028 is 0xe2 0x80 0x29.
|
|
** U+2029 is the same except for the last byte */
|
|
if sz2 < uint32(4) || int32(0x80) != libc.Int32FromUint8(libc.Uint8FromInt8(**(**int8)(__ccgo_up(zIn2 + 2)))) || int32(0xa8) != libc.Int32FromUint8(libc.Uint8FromInt8(**(**int8)(__ccgo_up(zIn2 + 3)))) && int32(0xa9) != libc.Int32FromUint8(libc.Uint8FromInt8(**(**int8)(__ccgo_up(zIn2 + 3)))) {
|
|
v1 = pOut + 25
|
|
*(*Tu8)(unsafe.Pointer(v1)) = Tu8(int32(*(*Tu8)(unsafe.Pointer(v1))) | libc.Int32FromInt32(JSTRING_MALFORMED))
|
|
sz2 = uint32(2)
|
|
break
|
|
}
|
|
zIn2 = zIn2 + uintptr(2)
|
|
sz2 = sz2 - uint32(2)
|
|
default:
|
|
_jsonAppendRawNZ(tls, pOut, zIn2, uint32(2))
|
|
break
|
|
}
|
|
zIn2 = zIn2 + uintptr(2)
|
|
sz2 = sz2 - uint32(2)
|
|
}
|
|
_jsonAppendChar(tls, pOut, int8('"'))
|
|
goto _16
|
|
_12:
|
|
;
|
|
_jsonAppendString(tls, pOut, (*TJsonParse)(unsafe.Pointer(pParse)).FaBlob+uintptr(i+n), **(**Tu32)(__ccgo_up(bp)))
|
|
goto _16
|
|
_13:
|
|
;
|
|
_jsonAppendChar(tls, pOut, int8('['))
|
|
j = i + n
|
|
iEnd = j + **(**Tu32)(__ccgo_up(bp))
|
|
v1 = pParse + 32
|
|
*(*Tu16)(unsafe.Pointer(v1)) = *(*Tu16)(unsafe.Pointer(v1)) + 1
|
|
v25 = *(*Tu16)(unsafe.Pointer(v1))
|
|
if libc.Int32FromUint16(v25) > int32(JSON_MAX_DEPTH) {
|
|
_jsonStringTooDeep(tls, pOut)
|
|
}
|
|
for j < iEnd && libc.Int32FromUint8((*TJsonString)(unsafe.Pointer(pOut)).FeErr) == 0 {
|
|
j = _jsonTranslateBlobToText(tls, pParse, j, pOut)
|
|
_jsonAppendChar(tls, pOut, int8(','))
|
|
}
|
|
(*TJsonParse)(unsafe.Pointer(pParse)).FiDepth = (*TJsonParse)(unsafe.Pointer(pParse)).FiDepth - 1
|
|
if j > iEnd {
|
|
v1 = pOut + 25
|
|
*(*Tu8)(unsafe.Pointer(v1)) = Tu8(int32(*(*Tu8)(unsafe.Pointer(v1))) | libc.Int32FromInt32(JSTRING_MALFORMED))
|
|
}
|
|
if **(**Tu32)(__ccgo_up(bp)) > uint32(0) {
|
|
_jsonStringTrimOneChar(tls, pOut)
|
|
}
|
|
_jsonAppendChar(tls, pOut, int8(']'))
|
|
goto _16
|
|
_14:
|
|
;
|
|
x = 0
|
|
_jsonAppendChar(tls, pOut, int8('{'))
|
|
j = i + n
|
|
iEnd = j + **(**Tu32)(__ccgo_up(bp))
|
|
v1 = pParse + 32
|
|
*(*Tu16)(unsafe.Pointer(v1)) = *(*Tu16)(unsafe.Pointer(v1)) + 1
|
|
v25 = *(*Tu16)(unsafe.Pointer(v1))
|
|
if libc.Int32FromUint16(v25) > int32(JSON_MAX_DEPTH) {
|
|
_jsonStringTooDeep(tls, pOut)
|
|
}
|
|
for j < iEnd && libc.Int32FromUint8((*TJsonString)(unsafe.Pointer(pOut)).FeErr) == 0 {
|
|
j = _jsonTranslateBlobToText(tls, pParse, j, pOut)
|
|
v31 = x
|
|
x = x + 1
|
|
if v31&int32(1) != 0 {
|
|
v30 = int32(',')
|
|
} else {
|
|
v30 = int32(':')
|
|
}
|
|
_jsonAppendChar(tls, pOut, int8(v30))
|
|
}
|
|
(*TJsonParse)(unsafe.Pointer(pParse)).FiDepth = (*TJsonParse)(unsafe.Pointer(pParse)).FiDepth - 1
|
|
if x&int32(1) != 0 || j > iEnd {
|
|
v1 = pOut + 25
|
|
*(*Tu8)(unsafe.Pointer(v1)) = Tu8(int32(*(*Tu8)(unsafe.Pointer(v1))) | libc.Int32FromInt32(JSTRING_MALFORMED))
|
|
}
|
|
if **(**Tu32)(__ccgo_up(bp)) > uint32(0) {
|
|
_jsonStringTrimOneChar(tls, pOut)
|
|
}
|
|
_jsonAppendChar(tls, pOut, int8('}'))
|
|
goto _16
|
|
_15:
|
|
;
|
|
goto malformed_jsonb
|
|
malformed_jsonb:
|
|
;
|
|
v1 = pOut + 25
|
|
*(*Tu8)(unsafe.Pointer(v1)) = Tu8(int32(*(*Tu8)(unsafe.Pointer(v1))) | libc.Int32FromInt32(JSTRING_MALFORMED))
|
|
goto _16
|
|
_16:
|
|
;
|
|
return i + n + **(**Tu32)(__ccgo_up(bp))
|
|
}
|
|
|
|
// C documentation
|
|
//
|
|
// /*
|
|
// ** Translate a single element of JSON text at pParse->zJson[i] into
|
|
// ** its equivalent binary JSONB representation. Append the translation into
|
|
// ** pParse->aBlob[] beginning at pParse->nBlob. The size of
|
|
// ** pParse->aBlob[] is increased as necessary.
|
|
// **
|
|
// ** Return the index of the first character past the end of the element parsed,
|
|
// ** or one of the following special result codes:
|
|
// **
|
|
// ** 0 End of input
|
|
// ** -1 Syntax error or OOM
|
|
// ** -2 '}' seen ** -3 ']' seen \___ For these returns, pParse->iErr is set to
|
|
// ** -4 ',' seen / the index in zJson[] of the seen character
|
|
// ** -5 ':' seen /
|
|
// */
|
|
func _jsonTranslateTextToBlob(tls *libc.TLS, pParse uintptr, i Tu32) (r int32) {
|
|
bp := tls.Alloc(16)
|
|
defer tls.Free(16)
|
|
var c, cDelim int8
|
|
var iBlob, iStart, iThis, j, k1, v46 Tu32
|
|
var k, nn, x, v48 int32
|
|
var opcode, seenE, t Tu8
|
|
var z, v41 uintptr
|
|
var v40 Tu16
|
|
var _ /* op at bp+0 */ int32
|
|
_, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _ = c, cDelim, iBlob, iStart, iThis, j, k, k1, nn, opcode, seenE, t, x, z, v40, v41, v46, v48
|
|
z = (*TJsonParse)(unsafe.Pointer(pParse)).FzJson
|
|
goto json_parse_restart
|
|
json_parse_restart:
|
|
;
|
|
switch libc.Int32FromUint8(libc.Uint8FromInt8(**(**int8)(__ccgo_up(z + uintptr(i))))) {
|
|
case int32('{'):
|
|
goto _1
|
|
case int32('['):
|
|
goto _2
|
|
case int32('"'):
|
|
goto _3
|
|
case int32('\''):
|
|
goto _4
|
|
case int32('t'):
|
|
goto _5
|
|
case int32('f'):
|
|
goto _6
|
|
case int32('.'):
|
|
goto _7
|
|
case int32('9'):
|
|
goto _8
|
|
case int32('8'):
|
|
goto _9
|
|
case int32('7'):
|
|
goto _10
|
|
case int32('6'):
|
|
goto _11
|
|
case int32('5'):
|
|
goto _12
|
|
case int32('4'):
|
|
goto _13
|
|
case int32('3'):
|
|
goto _14
|
|
case int32('2'):
|
|
goto _15
|
|
case int32('1'):
|
|
goto _16
|
|
case int32('0'):
|
|
goto _17
|
|
case int32('-'):
|
|
goto _18
|
|
case int32('+'):
|
|
goto _19
|
|
case int32('}'):
|
|
goto _20
|
|
case int32(']'):
|
|
goto _21
|
|
case int32(','):
|
|
goto _22
|
|
case int32(':'):
|
|
goto _23
|
|
case 0:
|
|
goto _24
|
|
case int32(0x20):
|
|
goto _25
|
|
case int32(0x0d):
|
|
goto _26
|
|
case int32(0x0a):
|
|
goto _27
|
|
case int32(0x09):
|
|
goto _28
|
|
case int32(0xef):
|
|
goto _29
|
|
case int32(0xe3):
|
|
goto _30
|
|
case int32(0xe2):
|
|
goto _31
|
|
case int32(0xe1):
|
|
goto _32
|
|
case int32(0xc2):
|
|
goto _33
|
|
case int32('/'):
|
|
goto _34
|
|
case int32(0x0c):
|
|
goto _35
|
|
case int32(0x0b):
|
|
goto _36
|
|
case int32('n'):
|
|
goto _37
|
|
default:
|
|
goto _38
|
|
}
|
|
goto _39
|
|
_1:
|
|
;
|
|
/* Parse object */
|
|
iThis = (*TJsonParse)(unsafe.Pointer(pParse)).FnBlob
|
|
_jsonBlobAppendNode(tls, pParse, uint8(JSONB_OBJECT), uint64(libc.Uint32FromInt32((*TJsonParse)(unsafe.Pointer(pParse)).FnJson)-i), uintptr(0))
|
|
v41 = pParse + 32
|
|
*(*Tu16)(unsafe.Pointer(v41)) = *(*Tu16)(unsafe.Pointer(v41)) + 1
|
|
v40 = *(*Tu16)(unsafe.Pointer(v41))
|
|
if libc.Int32FromUint16(v40) > int32(JSON_MAX_DEPTH) {
|
|
(*TJsonParse)(unsafe.Pointer(pParse)).FiErr = i
|
|
return -int32(1)
|
|
}
|
|
iStart = (*TJsonParse)(unsafe.Pointer(pParse)).FnBlob
|
|
j = i + uint32(1)
|
|
for {
|
|
iBlob = (*TJsonParse)(unsafe.Pointer(pParse)).FnBlob
|
|
x = _jsonTranslateTextToBlob(tls, pParse, j)
|
|
if x <= 0 {
|
|
if x == -int32(2) {
|
|
j = (*TJsonParse)(unsafe.Pointer(pParse)).FiErr
|
|
if (*TJsonParse)(unsafe.Pointer(pParse)).FnBlob != iStart {
|
|
(*TJsonParse)(unsafe.Pointer(pParse)).FhasNonstd = uint8(1)
|
|
}
|
|
break
|
|
}
|
|
j = j + libc.Uint32FromInt32(_json5Whitespace(tls, z+uintptr(j)))
|
|
**(**int32)(__ccgo_up(bp)) = int32(JSONB_TEXT)
|
|
if libc.Int32FromUint8(_sqlite3CtypeMap[libc.Uint8FromInt8(**(**int8)(__ccgo_up(z + uintptr(j))))])&int32(0x42) != 0 || int32(**(**int8)(__ccgo_up(z + uintptr(j)))) == int32('\\') && _jsonIs4HexB(tls, z+uintptr(j+uint32(1)), bp) != 0 {
|
|
k = libc.Int32FromUint32(j + uint32(1))
|
|
for libc.Int32FromUint8(_sqlite3CtypeMap[libc.Uint8FromInt8(**(**int8)(__ccgo_up(z + uintptr(k))))])&int32(0x46) != 0 && _json5Whitespace(tls, z+uintptr(k)) == 0 || int32(**(**int8)(__ccgo_up(z + uintptr(k)))) == int32('\\') && _jsonIs4HexB(tls, z+uintptr(k+int32(1)), bp) != 0 {
|
|
k = k + 1
|
|
}
|
|
_jsonBlobAppendNode(tls, pParse, libc.Uint8FromInt32(**(**int32)(__ccgo_up(bp))), uint64(libc.Uint32FromInt32(k)-j), z+uintptr(j))
|
|
(*TJsonParse)(unsafe.Pointer(pParse)).FhasNonstd = uint8(1)
|
|
x = k
|
|
} else {
|
|
if x != -int32(1) {
|
|
(*TJsonParse)(unsafe.Pointer(pParse)).FiErr = j
|
|
}
|
|
return -int32(1)
|
|
}
|
|
}
|
|
if (*TJsonParse)(unsafe.Pointer(pParse)).Foom != 0 {
|
|
return -int32(1)
|
|
}
|
|
t = libc.Uint8FromInt32(libc.Int32FromUint8(**(**Tu8)(__ccgo_up((*TJsonParse)(unsafe.Pointer(pParse)).FaBlob + uintptr(iBlob)))) & int32(0x0f))
|
|
if libc.Int32FromUint8(t) < int32(JSONB_TEXT) || libc.Int32FromUint8(t) > int32(JSONB_TEXTRAW) {
|
|
(*TJsonParse)(unsafe.Pointer(pParse)).FiErr = j
|
|
return -int32(1)
|
|
}
|
|
j = libc.Uint32FromInt32(x)
|
|
if int32(**(**int8)(__ccgo_up(z + uintptr(j)))) == int32(':') {
|
|
j = j + 1
|
|
} else {
|
|
if _jsonIsSpace[libc.Uint8FromInt8(**(**int8)(__ccgo_up(z + uintptr(j))))] != 0 {
|
|
/* strspn() is not helpful here */
|
|
for cond := true; cond; cond = _jsonIsSpace[libc.Uint8FromInt8(**(**int8)(__ccgo_up(z + uintptr(j))))] != 0 {
|
|
j = j + 1
|
|
}
|
|
if int32(**(**int8)(__ccgo_up(z + uintptr(j)))) == int32(':') {
|
|
j = j + 1
|
|
goto parse_object_value
|
|
}
|
|
}
|
|
x = _jsonTranslateTextToBlob(tls, pParse, j)
|
|
if x != -int32(5) {
|
|
if x != -int32(1) {
|
|
(*TJsonParse)(unsafe.Pointer(pParse)).FiErr = j
|
|
}
|
|
return -int32(1)
|
|
}
|
|
j = (*TJsonParse)(unsafe.Pointer(pParse)).FiErr + uint32(1)
|
|
}
|
|
goto parse_object_value
|
|
parse_object_value:
|
|
;
|
|
x = _jsonTranslateTextToBlob(tls, pParse, j)
|
|
if x <= 0 {
|
|
if x != -int32(1) {
|
|
(*TJsonParse)(unsafe.Pointer(pParse)).FiErr = j
|
|
}
|
|
return -int32(1)
|
|
}
|
|
j = libc.Uint32FromInt32(x)
|
|
if int32(**(**int8)(__ccgo_up(z + uintptr(j)))) == int32(',') {
|
|
goto _42
|
|
} else {
|
|
if int32(**(**int8)(__ccgo_up(z + uintptr(j)))) == int32('}') {
|
|
break
|
|
} else {
|
|
if _jsonIsSpace[libc.Uint8FromInt8(**(**int8)(__ccgo_up(z + uintptr(j))))] != 0 {
|
|
j = j + (uint32(1) + libc.Xstrspn(tls, z+uintptr(j+uint32(1)), uintptr(unsafe.Pointer(&_jsonSpaces))))
|
|
if int32(**(**int8)(__ccgo_up(z + uintptr(j)))) == int32(',') {
|
|
goto _42
|
|
} else {
|
|
if int32(**(**int8)(__ccgo_up(z + uintptr(j)))) == int32('}') {
|
|
break
|
|
}
|
|
}
|
|
}
|
|
x = _jsonTranslateTextToBlob(tls, pParse, j)
|
|
if x == -int32(4) {
|
|
j = (*TJsonParse)(unsafe.Pointer(pParse)).FiErr
|
|
goto _42
|
|
}
|
|
if x == -int32(2) {
|
|
j = (*TJsonParse)(unsafe.Pointer(pParse)).FiErr
|
|
break
|
|
}
|
|
}
|
|
}
|
|
(*TJsonParse)(unsafe.Pointer(pParse)).FiErr = j
|
|
return -int32(1)
|
|
goto _42
|
|
_42:
|
|
;
|
|
j = j + 1
|
|
}
|
|
_jsonBlobChangePayloadSize(tls, pParse, iThis, (*TJsonParse)(unsafe.Pointer(pParse)).FnBlob-iStart)
|
|
(*TJsonParse)(unsafe.Pointer(pParse)).FiDepth = (*TJsonParse)(unsafe.Pointer(pParse)).FiDepth - 1
|
|
return libc.Int32FromUint32(j + uint32(1))
|
|
_2:
|
|
;
|
|
/* Parse array */
|
|
iThis = (*TJsonParse)(unsafe.Pointer(pParse)).FnBlob
|
|
_jsonBlobAppendNode(tls, pParse, uint8(JSONB_ARRAY), uint64(libc.Uint32FromInt32((*TJsonParse)(unsafe.Pointer(pParse)).FnJson)-i), uintptr(0))
|
|
iStart = (*TJsonParse)(unsafe.Pointer(pParse)).FnBlob
|
|
if (*TJsonParse)(unsafe.Pointer(pParse)).Foom != 0 {
|
|
return -int32(1)
|
|
}
|
|
v41 = pParse + 32
|
|
*(*Tu16)(unsafe.Pointer(v41)) = *(*Tu16)(unsafe.Pointer(v41)) + 1
|
|
v40 = *(*Tu16)(unsafe.Pointer(v41))
|
|
if libc.Int32FromUint16(v40) > int32(JSON_MAX_DEPTH) {
|
|
(*TJsonParse)(unsafe.Pointer(pParse)).FiErr = i
|
|
return -int32(1)
|
|
}
|
|
j = i + uint32(1)
|
|
for {
|
|
x = _jsonTranslateTextToBlob(tls, pParse, j)
|
|
if x <= 0 {
|
|
if x == -int32(3) {
|
|
j = (*TJsonParse)(unsafe.Pointer(pParse)).FiErr
|
|
if (*TJsonParse)(unsafe.Pointer(pParse)).FnBlob != iStart {
|
|
(*TJsonParse)(unsafe.Pointer(pParse)).FhasNonstd = uint8(1)
|
|
}
|
|
break
|
|
}
|
|
if x != -int32(1) {
|
|
(*TJsonParse)(unsafe.Pointer(pParse)).FiErr = j
|
|
}
|
|
return -int32(1)
|
|
}
|
|
j = libc.Uint32FromInt32(x)
|
|
if int32(**(**int8)(__ccgo_up(z + uintptr(j)))) == int32(',') {
|
|
goto _45
|
|
} else {
|
|
if int32(**(**int8)(__ccgo_up(z + uintptr(j)))) == int32(']') {
|
|
break
|
|
} else {
|
|
if _jsonIsSpace[libc.Uint8FromInt8(**(**int8)(__ccgo_up(z + uintptr(j))))] != 0 {
|
|
j = j + (uint32(1) + libc.Xstrspn(tls, z+uintptr(j+uint32(1)), uintptr(unsafe.Pointer(&_jsonSpaces))))
|
|
if int32(**(**int8)(__ccgo_up(z + uintptr(j)))) == int32(',') {
|
|
goto _45
|
|
} else {
|
|
if int32(**(**int8)(__ccgo_up(z + uintptr(j)))) == int32(']') {
|
|
break
|
|
}
|
|
}
|
|
}
|
|
x = _jsonTranslateTextToBlob(tls, pParse, j)
|
|
if x == -int32(4) {
|
|
j = (*TJsonParse)(unsafe.Pointer(pParse)).FiErr
|
|
goto _45
|
|
}
|
|
if x == -int32(3) {
|
|
j = (*TJsonParse)(unsafe.Pointer(pParse)).FiErr
|
|
break
|
|
}
|
|
}
|
|
}
|
|
(*TJsonParse)(unsafe.Pointer(pParse)).FiErr = j
|
|
return -int32(1)
|
|
goto _45
|
|
_45:
|
|
;
|
|
j = j + 1
|
|
}
|
|
_jsonBlobChangePayloadSize(tls, pParse, iThis, (*TJsonParse)(unsafe.Pointer(pParse)).FnBlob-iStart)
|
|
(*TJsonParse)(unsafe.Pointer(pParse)).FiDepth = (*TJsonParse)(unsafe.Pointer(pParse)).FiDepth - 1
|
|
return libc.Int32FromUint32(j + uint32(1))
|
|
_4:
|
|
;
|
|
(*TJsonParse)(unsafe.Pointer(pParse)).FhasNonstd = uint8(1)
|
|
opcode = uint8(JSONB_TEXT)
|
|
goto parse_string
|
|
_3:
|
|
;
|
|
/* Parse string */
|
|
opcode = uint8(JSONB_TEXT)
|
|
goto parse_string
|
|
parse_string:
|
|
;
|
|
cDelim = **(**int8)(__ccgo_up(z + uintptr(i)))
|
|
j = i + uint32(1)
|
|
for int32(1) != 0 {
|
|
if _jsonIsOk[libc.Uint8FromInt8(**(**int8)(__ccgo_up(z + uintptr(j))))] != 0 {
|
|
if !(_jsonIsOk[libc.Uint8FromInt8(**(**int8)(__ccgo_up(z + uintptr(j+uint32(1)))))] != 0) {
|
|
j = j + uint32(1)
|
|
} else {
|
|
if !(_jsonIsOk[libc.Uint8FromInt8(**(**int8)(__ccgo_up(z + uintptr(j+uint32(2)))))] != 0) {
|
|
j = j + uint32(2)
|
|
} else {
|
|
j = j + uint32(3)
|
|
continue
|
|
}
|
|
}
|
|
}
|
|
c = **(**int8)(__ccgo_up(z + uintptr(j)))
|
|
if int32(c) == int32(cDelim) {
|
|
break
|
|
} else {
|
|
if int32(c) == int32('\\') {
|
|
j = j + 1
|
|
v46 = j
|
|
c = **(**int8)(__ccgo_up(z + uintptr(v46)))
|
|
if int32(c) == int32('"') || int32(c) == int32('\\') || int32(c) == int32('/') || int32(c) == int32('b') || int32(c) == int32('f') || int32(c) == int32('n') || int32(c) == int32('r') || int32(c) == int32('t') || int32(c) == int32('u') && _jsonIs4Hex(tls, z+uintptr(j+uint32(1))) != 0 {
|
|
if libc.Int32FromUint8(opcode) == int32(JSONB_TEXT) {
|
|
opcode = uint8(JSONB_TEXTJ)
|
|
}
|
|
} else {
|
|
if int32(c) == int32('\'') || int32(c) == int32('v') || int32(c) == int32('\n') || int32(c) == int32('0') && !(libc.Int32FromUint8(_sqlite3CtypeMap[libc.Uint8FromInt8(**(**int8)(__ccgo_up(z + uintptr(j+uint32(1)))))])&libc.Int32FromInt32(0x04) != 0) || int32(0xe2) == libc.Int32FromUint8(libc.Uint8FromInt8(c)) && int32(0x80) == libc.Int32FromUint8(libc.Uint8FromInt8(**(**int8)(__ccgo_up(z + uintptr(j+uint32(1)))))) && (int32(0xa8) == libc.Int32FromUint8(libc.Uint8FromInt8(**(**int8)(__ccgo_up(z + uintptr(j+uint32(2)))))) || int32(0xa9) == libc.Int32FromUint8(libc.Uint8FromInt8(**(**int8)(__ccgo_up(z + uintptr(j+uint32(2))))))) || int32(c) == int32('x') && _jsonIs2Hex(tls, z+uintptr(j+uint32(1))) != 0 {
|
|
opcode = uint8(JSONB_TEXT5)
|
|
(*TJsonParse)(unsafe.Pointer(pParse)).FhasNonstd = uint8(1)
|
|
} else {
|
|
if int32(c) == int32('\r') {
|
|
if int32(**(**int8)(__ccgo_up(z + uintptr(j+uint32(1))))) == int32('\n') {
|
|
j = j + 1
|
|
}
|
|
opcode = uint8(JSONB_TEXT5)
|
|
(*TJsonParse)(unsafe.Pointer(pParse)).FhasNonstd = uint8(1)
|
|
} else {
|
|
(*TJsonParse)(unsafe.Pointer(pParse)).FiErr = j
|
|
return -int32(1)
|
|
}
|
|
}
|
|
}
|
|
} else {
|
|
if int32(c) <= int32(0x1f) {
|
|
if int32(c) == 0 {
|
|
(*TJsonParse)(unsafe.Pointer(pParse)).FiErr = j
|
|
return -int32(1)
|
|
}
|
|
/* Control characters are not allowed in canonical JSON string
|
|
** literals, but are allowed in JSON5 string literals. */
|
|
opcode = uint8(JSONB_TEXT5)
|
|
(*TJsonParse)(unsafe.Pointer(pParse)).FhasNonstd = uint8(1)
|
|
} else {
|
|
if int32(c) == int32('"') {
|
|
opcode = uint8(JSONB_TEXT5)
|
|
}
|
|
}
|
|
}
|
|
}
|
|
j = j + 1
|
|
}
|
|
_jsonBlobAppendNode(tls, pParse, opcode, uint64(j-uint32(1)-i), z+uintptr(i+uint32(1)))
|
|
return libc.Int32FromUint32(j + uint32(1))
|
|
_5:
|
|
;
|
|
if libc.Xstrncmp(tls, z+uintptr(i), __ccgo_ts+8180, uint32(4)) == 0 && !(libc.Int32FromUint8(_sqlite3CtypeMap[libc.Uint8FromInt8(**(**int8)(__ccgo_up(z + uintptr(i+uint32(4)))))])&libc.Int32FromInt32(0x06) != 0) {
|
|
_jsonBlobAppendOneByte(tls, pParse, uint8(JSONB_TRUE))
|
|
return libc.Int32FromUint32(i + uint32(4))
|
|
}
|
|
(*TJsonParse)(unsafe.Pointer(pParse)).FiErr = i
|
|
return -int32(1)
|
|
_6:
|
|
;
|
|
if libc.Xstrncmp(tls, z+uintptr(i), __ccgo_ts+8185, uint32(5)) == 0 && !(libc.Int32FromUint8(_sqlite3CtypeMap[libc.Uint8FromInt8(**(**int8)(__ccgo_up(z + uintptr(i+uint32(5)))))])&libc.Int32FromInt32(0x06) != 0) {
|
|
_jsonBlobAppendOneByte(tls, pParse, uint8(JSONB_FALSE))
|
|
return libc.Int32FromUint32(i + uint32(5))
|
|
}
|
|
(*TJsonParse)(unsafe.Pointer(pParse)).FiErr = i
|
|
return -int32(1)
|
|
_19:
|
|
;
|
|
(*TJsonParse)(unsafe.Pointer(pParse)).FhasNonstd = uint8(1)
|
|
t = uint8(0x00) /* Bit 0x01: JSON5. Bit 0x02: FLOAT */
|
|
goto parse_number
|
|
_7:
|
|
;
|
|
if libc.Int32FromUint8(_sqlite3CtypeMap[libc.Uint8FromInt8(**(**int8)(__ccgo_up(z + uintptr(i+uint32(1)))))])&int32(0x04) != 0 {
|
|
(*TJsonParse)(unsafe.Pointer(pParse)).FhasNonstd = uint8(1)
|
|
t = uint8(0x03) /* Bit 0x01: JSON5. Bit 0x02: FLOAT */
|
|
seenE = uint8(0)
|
|
goto parse_number_2
|
|
}
|
|
(*TJsonParse)(unsafe.Pointer(pParse)).FiErr = i
|
|
return -int32(1)
|
|
_18:
|
|
;
|
|
_17:
|
|
;
|
|
_16:
|
|
;
|
|
_15:
|
|
;
|
|
_14:
|
|
;
|
|
_13:
|
|
;
|
|
_12:
|
|
;
|
|
_11:
|
|
;
|
|
_10:
|
|
;
|
|
_9:
|
|
;
|
|
_8:
|
|
;
|
|
/* Parse number */
|
|
t = uint8(0x00) /* Bit 0x01: JSON5. Bit 0x02: FLOAT */
|
|
goto parse_number
|
|
parse_number:
|
|
;
|
|
seenE = uint8(0)
|
|
c = **(**int8)(__ccgo_up(z + uintptr(i)))
|
|
if int32(c) <= int32('0') {
|
|
if int32(c) == int32('0') {
|
|
if (int32(**(**int8)(__ccgo_up(z + uintptr(i+uint32(1))))) == int32('x') || int32(**(**int8)(__ccgo_up(z + uintptr(i+uint32(1))))) == int32('X')) && libc.Int32FromUint8(_sqlite3CtypeMap[libc.Uint8FromInt8(**(**int8)(__ccgo_up(z + uintptr(i+uint32(2)))))])&int32(0x08) != 0 {
|
|
(*TJsonParse)(unsafe.Pointer(pParse)).FhasNonstd = uint8(1)
|
|
t = uint8(0x01)
|
|
j = i + uint32(3)
|
|
for {
|
|
if !(libc.Int32FromUint8(_sqlite3CtypeMap[libc.Uint8FromInt8(**(**int8)(__ccgo_up(z + uintptr(j))))])&int32(0x08) != 0) {
|
|
break
|
|
}
|
|
goto _47
|
|
_47:
|
|
;
|
|
j = j + 1
|
|
}
|
|
goto parse_number_finish
|
|
} else {
|
|
if libc.Int32FromUint8(_sqlite3CtypeMap[libc.Uint8FromInt8(**(**int8)(__ccgo_up(z + uintptr(i+uint32(1)))))])&int32(0x04) != 0 {
|
|
(*TJsonParse)(unsafe.Pointer(pParse)).FiErr = i + uint32(1)
|
|
return -int32(1)
|
|
}
|
|
}
|
|
} else {
|
|
if !(libc.Int32FromUint8(_sqlite3CtypeMap[libc.Uint8FromInt8(**(**int8)(__ccgo_up(z + uintptr(i+uint32(1)))))])&libc.Int32FromInt32(0x04) != 0) {
|
|
/* JSON5 allows for "+Infinity" and "-Infinity" using exactly
|
|
** that case. SQLite also allows these in any case and it allows
|
|
** "+inf" and "-inf". */
|
|
if (int32(**(**int8)(__ccgo_up(z + uintptr(i+uint32(1))))) == int32('I') || int32(**(**int8)(__ccgo_up(z + uintptr(i+uint32(1))))) == int32('i')) && Xsqlite3_strnicmp(tls, z+uintptr(i+uint32(1)), __ccgo_ts+26475, int32(3)) == 0 {
|
|
(*TJsonParse)(unsafe.Pointer(pParse)).FhasNonstd = uint8(1)
|
|
if int32(**(**int8)(__ccgo_up(z + uintptr(i)))) == int32('-') {
|
|
_jsonBlobAppendNode(tls, pParse, uint8(JSONB_FLOAT), uint64(6), __ccgo_ts+26558)
|
|
} else {
|
|
_jsonBlobAppendNode(tls, pParse, uint8(JSONB_FLOAT), uint64(5), __ccgo_ts+26565)
|
|
}
|
|
if Xsqlite3_strnicmp(tls, z+uintptr(i+uint32(4)), __ccgo_ts+26571, int32(5)) == 0 {
|
|
v48 = int32(9)
|
|
} else {
|
|
v48 = int32(4)
|
|
}
|
|
return libc.Int32FromUint32(i + libc.Uint32FromInt32(v48))
|
|
}
|
|
if int32(**(**int8)(__ccgo_up(z + uintptr(i+uint32(1))))) == int32('.') {
|
|
(*TJsonParse)(unsafe.Pointer(pParse)).FhasNonstd = uint8(1)
|
|
t = libc.Uint8FromInt32(int32(t) | libc.Int32FromInt32(0x01))
|
|
goto parse_number_2
|
|
}
|
|
(*TJsonParse)(unsafe.Pointer(pParse)).FiErr = i
|
|
return -int32(1)
|
|
}
|
|
if int32(**(**int8)(__ccgo_up(z + uintptr(i+uint32(1))))) == int32('0') {
|
|
if libc.Int32FromUint8(_sqlite3CtypeMap[libc.Uint8FromInt8(**(**int8)(__ccgo_up(z + uintptr(i+uint32(2)))))])&int32(0x04) != 0 {
|
|
(*TJsonParse)(unsafe.Pointer(pParse)).FiErr = i + uint32(1)
|
|
return -int32(1)
|
|
} else {
|
|
if (int32(**(**int8)(__ccgo_up(z + uintptr(i+uint32(2))))) == int32('x') || int32(**(**int8)(__ccgo_up(z + uintptr(i+uint32(2))))) == int32('X')) && libc.Int32FromUint8(_sqlite3CtypeMap[libc.Uint8FromInt8(**(**int8)(__ccgo_up(z + uintptr(i+uint32(3)))))])&int32(0x08) != 0 {
|
|
(*TJsonParse)(unsafe.Pointer(pParse)).FhasNonstd = uint8(1)
|
|
t = libc.Uint8FromInt32(int32(t) | libc.Int32FromInt32(0x01))
|
|
j = i + uint32(4)
|
|
for {
|
|
if !(libc.Int32FromUint8(_sqlite3CtypeMap[libc.Uint8FromInt8(**(**int8)(__ccgo_up(z + uintptr(j))))])&int32(0x08) != 0) {
|
|
break
|
|
}
|
|
goto _49
|
|
_49:
|
|
;
|
|
j = j + 1
|
|
}
|
|
goto parse_number_finish
|
|
}
|
|
}
|
|
}
|
|
}
|
|
}
|
|
goto parse_number_2
|
|
parse_number_2:
|
|
;
|
|
j = i + uint32(1)
|
|
for {
|
|
c = **(**int8)(__ccgo_up(z + uintptr(j)))
|
|
if libc.Int32FromUint8(_sqlite3CtypeMap[libc.Uint8FromInt8(c)])&int32(0x04) != 0 {
|
|
goto _50
|
|
}
|
|
if int32(c) == int32('.') {
|
|
if libc.Int32FromUint8(t)&int32(0x02) != 0 {
|
|
(*TJsonParse)(unsafe.Pointer(pParse)).FiErr = j
|
|
return -int32(1)
|
|
}
|
|
t = libc.Uint8FromInt32(int32(t) | libc.Int32FromInt32(0x02))
|
|
goto _50
|
|
}
|
|
if int32(c) == int32('e') || int32(c) == int32('E') {
|
|
if int32(**(**int8)(__ccgo_up(z + uintptr(j-uint32(1))))) < int32('0') {
|
|
if int32(**(**int8)(__ccgo_up(z + uintptr(j-uint32(1))))) == int32('.') && j-uint32(2) >= i && libc.Int32FromUint8(_sqlite3CtypeMap[libc.Uint8FromInt8(**(**int8)(__ccgo_up(z + uintptr(j-uint32(2)))))])&int32(0x04) != 0 {
|
|
(*TJsonParse)(unsafe.Pointer(pParse)).FhasNonstd = uint8(1)
|
|
t = libc.Uint8FromInt32(int32(t) | libc.Int32FromInt32(0x01))
|
|
} else {
|
|
(*TJsonParse)(unsafe.Pointer(pParse)).FiErr = j
|
|
return -int32(1)
|
|
}
|
|
}
|
|
if seenE != 0 {
|
|
(*TJsonParse)(unsafe.Pointer(pParse)).FiErr = j
|
|
return -int32(1)
|
|
}
|
|
t = libc.Uint8FromInt32(int32(t) | libc.Int32FromInt32(0x02))
|
|
seenE = uint8(1)
|
|
c = **(**int8)(__ccgo_up(z + uintptr(j+uint32(1))))
|
|
if int32(c) == int32('+') || int32(c) == int32('-') {
|
|
j = j + 1
|
|
c = **(**int8)(__ccgo_up(z + uintptr(j+uint32(1))))
|
|
}
|
|
if int32(c) < int32('0') || int32(c) > int32('9') {
|
|
(*TJsonParse)(unsafe.Pointer(pParse)).FiErr = j
|
|
return -int32(1)
|
|
}
|
|
goto _50
|
|
}
|
|
break
|
|
goto _50
|
|
_50:
|
|
;
|
|
j = j + 1
|
|
}
|
|
if int32(**(**int8)(__ccgo_up(z + uintptr(j-uint32(1))))) < int32('0') {
|
|
if int32(**(**int8)(__ccgo_up(z + uintptr(j-uint32(1))))) == int32('.') && j-uint32(2) >= i && libc.Int32FromUint8(_sqlite3CtypeMap[libc.Uint8FromInt8(**(**int8)(__ccgo_up(z + uintptr(j-uint32(2)))))])&int32(0x04) != 0 {
|
|
(*TJsonParse)(unsafe.Pointer(pParse)).FhasNonstd = uint8(1)
|
|
t = libc.Uint8FromInt32(int32(t) | libc.Int32FromInt32(0x01))
|
|
} else {
|
|
(*TJsonParse)(unsafe.Pointer(pParse)).FiErr = j
|
|
return -int32(1)
|
|
}
|
|
}
|
|
goto parse_number_finish
|
|
parse_number_finish:
|
|
;
|
|
if int32(**(**int8)(__ccgo_up(z + uintptr(i)))) == int32('+') {
|
|
i = i + 1
|
|
}
|
|
_jsonBlobAppendNode(tls, pParse, libc.Uint8FromInt32(int32(JSONB_INT)+libc.Int32FromUint8(t)), uint64(j-i), z+uintptr(i))
|
|
return libc.Int32FromUint32(j)
|
|
_20:
|
|
;
|
|
(*TJsonParse)(unsafe.Pointer(pParse)).FiErr = i
|
|
return -int32(2) /* End of {...} */
|
|
_21:
|
|
;
|
|
(*TJsonParse)(unsafe.Pointer(pParse)).FiErr = i
|
|
return -int32(3) /* End of [...] */
|
|
_22:
|
|
;
|
|
(*TJsonParse)(unsafe.Pointer(pParse)).FiErr = i
|
|
return -int32(4) /* List separator */
|
|
_23:
|
|
;
|
|
(*TJsonParse)(unsafe.Pointer(pParse)).FiErr = i
|
|
return -int32(5) /* Object label/value separator */
|
|
_24:
|
|
;
|
|
return 0 /* End of file */
|
|
_28:
|
|
;
|
|
_27:
|
|
;
|
|
_26:
|
|
;
|
|
_25:
|
|
;
|
|
i = i + (uint32(1) + libc.Xstrspn(tls, z+uintptr(i+uint32(1)), uintptr(unsafe.Pointer(&_jsonSpaces))))
|
|
goto json_parse_restart
|
|
_36:
|
|
;
|
|
_35:
|
|
;
|
|
_34:
|
|
;
|
|
_33:
|
|
;
|
|
_32:
|
|
;
|
|
_31:
|
|
;
|
|
_30:
|
|
;
|
|
_29:
|
|
;
|
|
j = libc.Uint32FromInt32(_json5Whitespace(tls, z+uintptr(i)))
|
|
if j > uint32(0) {
|
|
i = i + j
|
|
(*TJsonParse)(unsafe.Pointer(pParse)).FhasNonstd = uint8(1)
|
|
goto json_parse_restart
|
|
}
|
|
(*TJsonParse)(unsafe.Pointer(pParse)).FiErr = i
|
|
return -int32(1)
|
|
_37:
|
|
;
|
|
if libc.Xstrncmp(tls, z+uintptr(i), __ccgo_ts+1688, uint32(4)) == 0 && !(libc.Int32FromUint8(_sqlite3CtypeMap[libc.Uint8FromInt8(**(**int8)(__ccgo_up(z + uintptr(i+uint32(4)))))])&libc.Int32FromInt32(0x06) != 0) {
|
|
_jsonBlobAppendOneByte(tls, pParse, uint8(JSONB_NULL))
|
|
return libc.Int32FromUint32(i + uint32(4))
|
|
}
|
|
/* fall-through into the default case that checks for NaN */
|
|
_38:
|
|
;
|
|
c = **(**int8)(__ccgo_up(z + uintptr(i)))
|
|
k1 = uint32(0)
|
|
for {
|
|
if !(k1 < libc.Uint32FromInt64(80)/libc.Uint32FromInt64(16)) {
|
|
break
|
|
}
|
|
if int32(c) != int32(_aNanInfName[k1].Fc1) && int32(c) != int32(_aNanInfName[k1].Fc2) {
|
|
goto _51
|
|
}
|
|
nn = int32(_aNanInfName[k1].Fn)
|
|
if Xsqlite3_strnicmp(tls, z+uintptr(i), _aNanInfName[k1].FzMatch, nn) != 0 {
|
|
goto _51
|
|
}
|
|
if libc.Int32FromUint8(_sqlite3CtypeMap[libc.Uint8FromInt8(**(**int8)(__ccgo_up(z + uintptr(i+libc.Uint32FromInt32(nn)))))])&int32(0x06) != 0 {
|
|
goto _51
|
|
}
|
|
if int32(_aNanInfName[k1].FeType) == int32(JSONB_FLOAT) {
|
|
_jsonBlobAppendNode(tls, pParse, uint8(JSONB_FLOAT), uint64(5), __ccgo_ts+26565)
|
|
} else {
|
|
_jsonBlobAppendOneByte(tls, pParse, uint8(JSONB_NULL))
|
|
}
|
|
(*TJsonParse)(unsafe.Pointer(pParse)).FhasNonstd = uint8(1)
|
|
return libc.Int32FromUint32(i + libc.Uint32FromInt32(nn))
|
|
goto _51
|
|
_51:
|
|
;
|
|
k1 = k1 + 1
|
|
}
|
|
(*TJsonParse)(unsafe.Pointer(pParse)).FiErr = i
|
|
return -int32(1) /* Syntax error */
|
|
_39:
|
|
; /* End switch(z[i]) */
|
|
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+4 */ 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*4))) == 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 + 116 + 8*4)) {
|
|
Xsqlite3_result_error(tls, context, __ccgo_ts+16483, -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 + 4)) = Xsqlite3_value_text(tls, **(**uintptr)(__ccgo_up(argv + 2*4)))
|
|
if **(**uintptr)(__ccgo_up(bp + 4)) == uintptr(0) {
|
|
return
|
|
}
|
|
if _sqlite3Utf8CharLen(tls, **(**uintptr)(__ccgo_up(bp + 4)), -int32(1)) != int32(1) {
|
|
Xsqlite3_result_error(tls, context, __ccgo_ts+16516, -int32(1))
|
|
return
|
|
}
|
|
escape = _sqlite3Utf8Read(tls, bp+4)
|
|
if escape == uint32((*TcompareInfo)(unsafe.Pointer(pInfo)).FmatchAll) || escape == uint32((*TcompareInfo)(unsafe.Pointer(pInfo)).FmatchOne) {
|
|
libc.Xmemcpy(tls, bp, pInfo, uint32(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*4)))
|
|
if zA != 0 && zB != 0 {
|
|
Xsqlite3_result_int(tls, context, libc.BoolInt32(_patternCompare(tls, zB, zA, pInfo, escape) == SQLITE_MATCH))
|
|
}
|
|
}
|
|
|
|
// C documentation
|
|
//
|
|
// /*
|
|
// ** Given the name of a column of the form X.Y.Z or Y.Z or just Z, look up
|
|
// ** that name in the set of source tables in pSrcList and make the pExpr
|
|
// ** expression node refer back to that source column. The following changes
|
|
// ** are made to pExpr:
|
|
// **
|
|
// ** pExpr->iDb Set the index in db->aDb[] of the database X
|
|
// ** (even if X is implied).
|
|
// ** pExpr->iTable Set to the cursor number for the table obtained
|
|
// ** from pSrcList.
|
|
// ** pExpr->y.pTab Points to the Table structure of X.Y (even if
|
|
// ** X and/or Y are implied.)
|
|
// ** pExpr->iColumn Set to the column number within the table.
|
|
// ** pExpr->op Set to TK_COLUMN.
|
|
// ** pExpr->pLeft Any expression this points to is deleted
|
|
// ** pExpr->pRight Any expression this points to is deleted.
|
|
// **
|
|
// ** The zDb variable is the name of the database (the "X"). This value may be
|
|
// ** NULL meaning that name is of the form Y.Z or Z. Any available database
|
|
// ** can be used. The zTable variable is the name of the table (the "Y"). This
|
|
// ** value can be NULL if zDb is also NULL. If zTable is NULL it
|
|
// ** means that the form of the name is Z and that columns from any table
|
|
// ** can be used.
|
|
// **
|
|
// ** If the name cannot be resolved unambiguously, leave an error message
|
|
// ** in pParse and return WRC_Abort. Return WRC_Prune on success.
|
|
// */
|
|
func _lookupName(tls *libc.TLS, pParse uintptr, zDb uintptr, zTab uintptr, pRight uintptr, pNC uintptr, pExpr uintptr) (r int32) {
|
|
bp := tls.Alloc(48)
|
|
defer tls.Free(48)
|
|
var cnt, cntTab, eNewExprOp, hit, i, iCol, j, nSubquery, op, v4 int32
|
|
var db, pEList, pItem, pMatch, pOrig, pSchema, pSel, pSrcList, pTab, pTopNC, pUpsert, zAs, zCol, zErr, v8 uintptr
|
|
var v5 uint32
|
|
var _ /* bRowid at bp+4 */ int32
|
|
var _ /* pFJMatch at bp+0 */ uintptr
|
|
_, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _ = cnt, cntTab, db, eNewExprOp, hit, i, iCol, j, nSubquery, op, pEList, pItem, pMatch, pOrig, pSchema, pSel, pSrcList, pTab, pTopNC, pUpsert, zAs, zCol, zErr, v4, v5, v8 /* Loop counters */
|
|
cnt = 0 /* Number of matching column names */
|
|
cntTab = 0 /* Number of potential "rowid" matches */
|
|
nSubquery = 0 /* How many levels of subquery */
|
|
db = (*TParse)(unsafe.Pointer(pParse)).Fdb /* Use for looping over pSrcList items */
|
|
pMatch = uintptr(0) /* The matching pSrcList item */
|
|
pTopNC = pNC /* First namecontext in the list */
|
|
pSchema = uintptr(0) /* Schema of the expression */
|
|
eNewExprOp = int32(TK_COLUMN) /* New value for pExpr->op on success */
|
|
pTab = uintptr(0) /* Table holding the row */
|
|
**(**uintptr)(__ccgo_up(bp)) = uintptr(0) /* Matches for FULL JOIN .. USING */
|
|
zCol = *(*uintptr)(unsafe.Pointer(pRight + 8))
|
|
/* the name context cannot be NULL. */
|
|
/* The Z in X.Y.Z cannot be NULL */
|
|
/* Initialize the node to no-match */
|
|
(*TExpr)(unsafe.Pointer(pExpr)).FiTable = -int32(1)
|
|
/* Translate the schema name in zDb into a pointer to the corresponding
|
|
** schema. If not found, pSchema will remain NULL and nothing will match
|
|
** resulting in an appropriate error message toward the end of this routine
|
|
*/
|
|
if zDb != 0 {
|
|
if (*TNameContext)(unsafe.Pointer(pNC)).FncFlags&(libc.Int32FromInt32(NC_PartIdx)|libc.Int32FromInt32(NC_IsCheck)) != 0 {
|
|
/* Silently ignore database qualifiers inside CHECK constraints and
|
|
** partial indices. Do not raise errors because that might break
|
|
** legacy and because it does not hurt anything to just ignore the
|
|
** database name. */
|
|
zDb = uintptr(0)
|
|
} else {
|
|
i = 0
|
|
for {
|
|
if !(i < (*Tsqlite3)(unsafe.Pointer(db)).FnDb) {
|
|
break
|
|
}
|
|
if _sqlite3StrICmp(tls, (**(**TDb)(__ccgo_up((*Tsqlite3)(unsafe.Pointer(db)).FaDb + uintptr(i)*16))).FzDbSName, zDb) == 0 {
|
|
pSchema = (**(**TDb)(__ccgo_up((*Tsqlite3)(unsafe.Pointer(db)).FaDb + uintptr(i)*16))).FpSchema
|
|
break
|
|
}
|
|
goto _1
|
|
_1:
|
|
;
|
|
i = i + 1
|
|
}
|
|
if i == (*Tsqlite3)(unsafe.Pointer(db)).FnDb && _sqlite3StrICmp(tls, __ccgo_ts+6818, zDb) == 0 {
|
|
/* This branch is taken when the main database has been renamed
|
|
** using SQLITE_DBCONFIG_MAINDBNAME. */
|
|
pSchema = (**(**TDb)(__ccgo_up((*Tsqlite3)(unsafe.Pointer(db)).FaDb))).FpSchema
|
|
zDb = (**(**TDb)(__ccgo_up((*Tsqlite3)(unsafe.Pointer(db)).FaDb))).FzDbSName
|
|
}
|
|
}
|
|
}
|
|
/* Start at the inner-most context and move outward until a match is found */
|
|
for cond := true; cond; cond = pNC != 0 {
|
|
pSrcList = (*TNameContext)(unsafe.Pointer(pNC)).FpSrcList
|
|
if pSrcList != 0 {
|
|
i = 0
|
|
pItem = pSrcList + 8
|
|
for {
|
|
if !(i < (*TSrcList)(unsafe.Pointer(pSrcList)).FnSrc) {
|
|
break
|
|
}
|
|
pTab = (*TSrcItem)(unsafe.Pointer(pItem)).FpSTab
|
|
if int32(*(*uint32)(unsafe.Pointer(pItem + 12 + 4))&0x4000>>14) != 0 {
|
|
/* In this case, pItem is a subquery that has been formed from a
|
|
** parenthesized subset of the FROM clause terms. Example:
|
|
** .... FROM t1 LEFT JOIN (t2 RIGHT JOIN t3 USING(x)) USING(y) ...
|
|
** \_________________________/
|
|
** This pItem -------------^
|
|
*/
|
|
hit = 0
|
|
pSel = (*TSubquery)(unsafe.Pointer(*(*uintptr)(unsafe.Pointer(pItem + 44)))).FpSelect
|
|
pEList = (*TSelect)(unsafe.Pointer(pSel)).FpEList
|
|
j = 0
|
|
for {
|
|
if !(j < (*TExprList)(unsafe.Pointer(pEList)).FnExpr) {
|
|
break
|
|
}
|
|
**(**int32)(__ccgo_up(bp + 4)) = 0 /* True if possible rowid match */
|
|
if !(_sqlite3MatchEName(tls, pEList+8+uintptr(j)*20, zCol, zTab, zDb, bp+4) != 0) {
|
|
goto _3
|
|
}
|
|
if **(**int32)(__ccgo_up(bp + 4)) == 0 {
|
|
if cnt > 0 {
|
|
if int32(*(*uint32)(unsafe.Pointer(pItem + 12 + 4))&0x800>>11) == 0 || _sqlite3IdListIndex(tls, *(*uintptr)(unsafe.Pointer(pItem + 40)), zCol) < 0 || pMatch == pItem {
|
|
/* Two or more tables have the same column name which is
|
|
** not joined by USING. Or, a single table has two columns
|
|
** that match a USING term (if pMatch==pItem). These are both
|
|
** "ambiguous column name" errors. Signal as much by clearing
|
|
** pFJMatch and letting cnt go above 1. */
|
|
_sqlite3ExprListDelete(tls, db, **(**uintptr)(__ccgo_up(bp)))
|
|
**(**uintptr)(__ccgo_up(bp)) = uintptr(0)
|
|
} else {
|
|
if libc.Int32FromUint8((*TSrcItem)(unsafe.Pointer(pItem)).Ffg.Fjointype)&int32(JT_RIGHT) == 0 {
|
|
/* An INNER or LEFT JOIN. Use the left-most table */
|
|
goto _3
|
|
} else {
|
|
if libc.Int32FromUint8((*TSrcItem)(unsafe.Pointer(pItem)).Ffg.Fjointype)&int32(JT_LEFT) == 0 {
|
|
/* A RIGHT JOIN. Use the right-most table */
|
|
cnt = 0
|
|
_sqlite3ExprListDelete(tls, db, **(**uintptr)(__ccgo_up(bp)))
|
|
**(**uintptr)(__ccgo_up(bp)) = uintptr(0)
|
|
} else {
|
|
/* For a FULL JOIN, we must construct a coalesce() func */
|
|
_extendFJMatch(tls, pParse, bp, pMatch, (*TExpr)(unsafe.Pointer(pExpr)).FiColumn)
|
|
}
|
|
}
|
|
}
|
|
}
|
|
cnt = cnt + 1
|
|
hit = int32(1)
|
|
} else {
|
|
if cnt > 0 {
|
|
/* This is a potential rowid match, but there has already been
|
|
** a real match found. So this can be ignored. */
|
|
goto _3
|
|
}
|
|
}
|
|
cntTab = cntTab + 1
|
|
pMatch = pItem
|
|
(*TExpr)(unsafe.Pointer(pExpr)).FiColumn = int16(j)
|
|
libc.SetBitFieldPtr16Uint32(pEList+8+uintptr(j)*20+8+4, libc.Uint32FromInt32(1), 6, 0x40)
|
|
/* rowid cannot be part of a USING clause - assert() this. */
|
|
if int32(uint32(*(*uint16)(unsafe.Pointer(pEList + 8 + uintptr(j)*20 + 8 + 4))&0x80>>7)) != 0 {
|
|
break
|
|
}
|
|
goto _3
|
|
_3:
|
|
;
|
|
j = j + 1
|
|
}
|
|
if hit != 0 || zTab == uintptr(0) {
|
|
goto _2
|
|
}
|
|
}
|
|
if zTab != 0 {
|
|
if zDb != 0 {
|
|
if (*TTable)(unsafe.Pointer(pTab)).FpSchema != pSchema {
|
|
goto _2
|
|
}
|
|
if pSchema == uintptr(0) && libc.Xstrcmp(tls, zDb, __ccgo_ts+6823) != 0 {
|
|
goto _2
|
|
}
|
|
}
|
|
if (*TSrcItem)(unsafe.Pointer(pItem)).FzAlias != uintptr(0) {
|
|
if _sqlite3StrICmp(tls, zTab, (*TSrcItem)(unsafe.Pointer(pItem)).FzAlias) != 0 {
|
|
goto _2
|
|
}
|
|
} else {
|
|
if _sqlite3StrICmp(tls, zTab, (*TTable)(unsafe.Pointer(pTab)).FzName) != 0 {
|
|
if (*TTable)(unsafe.Pointer(pTab)).Ftnum != uint32(1) {
|
|
goto _2
|
|
}
|
|
if !(_isValidSchemaTableName(tls, zTab, pTab, zDb) != 0) {
|
|
goto _2
|
|
}
|
|
}
|
|
}
|
|
if libc.Int32FromUint8((*TParse)(unsafe.Pointer(pParse)).FeParseMode) >= int32(PARSE_MODE_RENAME) && (*TSrcItem)(unsafe.Pointer(pItem)).FzAlias != 0 {
|
|
_sqlite3RenameTokenRemap(tls, pParse, uintptr(0), pExpr+44)
|
|
}
|
|
}
|
|
j = _sqlite3ColumnIndex(tls, pTab, zCol)
|
|
if j >= 0 {
|
|
if cnt > 0 {
|
|
if int32(*(*uint32)(unsafe.Pointer(pItem + 12 + 4))&0x800>>11) == 0 || _sqlite3IdListIndex(tls, *(*uintptr)(unsafe.Pointer(pItem + 40)), zCol) < 0 {
|
|
/* Two or more tables have the same column name which is
|
|
** not joined by USING. This is an error. Signal as much
|
|
** by clearing pFJMatch and letting cnt go above 1. */
|
|
_sqlite3ExprListDelete(tls, db, **(**uintptr)(__ccgo_up(bp)))
|
|
**(**uintptr)(__ccgo_up(bp)) = uintptr(0)
|
|
} else {
|
|
if libc.Int32FromUint8((*TSrcItem)(unsafe.Pointer(pItem)).Ffg.Fjointype)&int32(JT_RIGHT) == 0 {
|
|
/* An INNER or LEFT JOIN. Use the left-most table */
|
|
goto _2
|
|
} else {
|
|
if libc.Int32FromUint8((*TSrcItem)(unsafe.Pointer(pItem)).Ffg.Fjointype)&int32(JT_LEFT) == 0 {
|
|
/* A RIGHT JOIN. Use the right-most table */
|
|
cnt = 0
|
|
_sqlite3ExprListDelete(tls, db, **(**uintptr)(__ccgo_up(bp)))
|
|
**(**uintptr)(__ccgo_up(bp)) = uintptr(0)
|
|
} else {
|
|
/* For a FULL JOIN, we must construct a coalesce() func */
|
|
_extendFJMatch(tls, pParse, bp, pMatch, (*TExpr)(unsafe.Pointer(pExpr)).FiColumn)
|
|
}
|
|
}
|
|
}
|
|
}
|
|
cnt = cnt + 1
|
|
pMatch = pItem
|
|
/* Substitute the rowid (column -1) for the INTEGER PRIMARY KEY */
|
|
if j == int32((*TTable)(unsafe.Pointer(pTab)).FiPKey) {
|
|
v4 = -int32(1)
|
|
} else {
|
|
v4 = int32(int16(j))
|
|
}
|
|
(*TExpr)(unsafe.Pointer(pExpr)).FiColumn = int16(v4)
|
|
if int32(*(*uint32)(unsafe.Pointer(pItem + 12 + 4))&0x4000>>14) != 0 {
|
|
_sqlite3SrcItemColumnUsed(tls, pItem, j)
|
|
}
|
|
}
|
|
if 0 == cnt && (*TTable)(unsafe.Pointer(pTab)).FtabFlags&uint32(TF_NoVisibleRowid) == uint32(0) {
|
|
/* pTab is a potential ROWID match. Keep track of it and match
|
|
** the ROWID later if that seems appropriate. (Search for "cntTab"
|
|
** to find related code.) Only allow a ROWID match if there is
|
|
** a single ROWID match candidate.
|
|
*/
|
|
/* The (much more common) non-SQLITE_ALLOW_ROWID_IN_VIEW case is
|
|
** simpler since we require exactly one candidate, which will
|
|
** always be a non-VIEW
|
|
*/
|
|
cntTab = cntTab + 1
|
|
pMatch = pItem
|
|
}
|
|
goto _2
|
|
_2:
|
|
;
|
|
i = i + 1
|
|
pItem += 48
|
|
}
|
|
if pMatch != 0 {
|
|
(*TExpr)(unsafe.Pointer(pExpr)).FiTable = (*TSrcItem)(unsafe.Pointer(pMatch)).FiCursor
|
|
(*TExpr)(unsafe.Pointer(pExpr)).Fy.FpTab = (*TSrcItem)(unsafe.Pointer(pMatch)).FpSTab
|
|
if libc.Int32FromUint8((*TSrcItem)(unsafe.Pointer(pMatch)).Ffg.Fjointype)&(libc.Int32FromInt32(JT_LEFT)|libc.Int32FromInt32(JT_LTORJ)) != 0 {
|
|
**(**Tu32)(__ccgo_up(pExpr + 4)) |= libc.Uint32FromInt32(libc.Int32FromInt32(EP_CanBeNull))
|
|
}
|
|
pSchema = (*TTable)(unsafe.Pointer((*TExpr)(unsafe.Pointer(pExpr)).Fy.FpTab)).FpSchema
|
|
}
|
|
} /* if( pSrcList ) */
|
|
/* If we have not already resolved the name, then maybe
|
|
** it is a new.* or old.* trigger argument reference. Or
|
|
** maybe it is an excluded.* from an upsert. Or maybe it is
|
|
** a reference in the RETURNING clause to a table being modified.
|
|
*/
|
|
if cnt == 0 && zDb == uintptr(0) {
|
|
pTab = uintptr(0)
|
|
if (*TParse)(unsafe.Pointer(pParse)).FpTriggerTab != uintptr(0) {
|
|
op = libc.Int32FromUint8((*TParse)(unsafe.Pointer(pParse)).FeTriggerOp)
|
|
if int32(Tbft(*(*uint16)(unsafe.Pointer(pParse + 28))&0x8>>3)) != 0 {
|
|
if (*TNameContext)(unsafe.Pointer(pNC)).FncFlags&int32(NC_UBaseReg) != 0 && (zTab == uintptr(0) || _sqlite3StrICmp(tls, zTab, (*TTable)(unsafe.Pointer((*TParse)(unsafe.Pointer(pParse)).FpTriggerTab)).FzName) == 0 || _isValidSchemaTableName(tls, zTab, (*TParse)(unsafe.Pointer(pParse)).FpTriggerTab, uintptr(0)) != 0) {
|
|
(*TExpr)(unsafe.Pointer(pExpr)).FiTable = libc.BoolInt32(op != int32(TK_DELETE))
|
|
pTab = (*TParse)(unsafe.Pointer(pParse)).FpTriggerTab
|
|
}
|
|
} else {
|
|
if op != int32(TK_DELETE) && zTab != 0 && _sqlite3StrICmp(tls, __ccgo_ts+6825, zTab) == 0 {
|
|
(*TExpr)(unsafe.Pointer(pExpr)).FiTable = int32(1)
|
|
pTab = (*TParse)(unsafe.Pointer(pParse)).FpTriggerTab
|
|
} else {
|
|
if op != int32(TK_INSERT) && zTab != 0 && _sqlite3StrICmp(tls, __ccgo_ts+6829, zTab) == 0 {
|
|
(*TExpr)(unsafe.Pointer(pExpr)).FiTable = 0
|
|
pTab = (*TParse)(unsafe.Pointer(pParse)).FpTriggerTab
|
|
}
|
|
}
|
|
}
|
|
}
|
|
if (*TNameContext)(unsafe.Pointer(pNC)).FncFlags&int32(NC_UUpsert) != 0 && zTab != uintptr(0) {
|
|
pUpsert = *(*uintptr)(unsafe.Pointer(pNC + 8))
|
|
if pUpsert != 0 && _sqlite3StrICmp(tls, __ccgo_ts+6833, zTab) == 0 {
|
|
pTab = (*(*TSrcItem)(unsafe.Pointer((*TUpsert)(unsafe.Pointer(pUpsert)).FpUpsertSrc + 8))).FpSTab
|
|
(*TExpr)(unsafe.Pointer(pExpr)).FiTable = int32(EXCLUDED_TABLE_NUMBER)
|
|
}
|
|
}
|
|
if pTab != 0 {
|
|
pSchema = (*TTable)(unsafe.Pointer(pTab)).FpSchema
|
|
cntTab = cntTab + 1
|
|
iCol = _sqlite3ColumnIndex(tls, pTab, zCol)
|
|
if iCol >= 0 {
|
|
if int32((*TTable)(unsafe.Pointer(pTab)).FiPKey) == iCol {
|
|
iCol = -int32(1)
|
|
}
|
|
} else {
|
|
if _sqlite3IsRowid(tls, zCol) != 0 && (*TTable)(unsafe.Pointer(pTab)).FtabFlags&uint32(TF_NoVisibleRowid) == uint32(0) {
|
|
iCol = -int32(1)
|
|
} else {
|
|
iCol = int32((*TTable)(unsafe.Pointer(pTab)).FnCol)
|
|
}
|
|
}
|
|
if iCol < int32((*TTable)(unsafe.Pointer(pTab)).FnCol) {
|
|
cnt = cnt + 1
|
|
pMatch = uintptr(0)
|
|
if (*TExpr)(unsafe.Pointer(pExpr)).FiTable == int32(EXCLUDED_TABLE_NUMBER) {
|
|
if libc.Int32FromUint8((*TParse)(unsafe.Pointer(pParse)).FeParseMode) >= int32(PARSE_MODE_RENAME) {
|
|
(*TExpr)(unsafe.Pointer(pExpr)).FiColumn = int16(iCol)
|
|
(*TExpr)(unsafe.Pointer(pExpr)).Fy.FpTab = pTab
|
|
eNewExprOp = int32(TK_COLUMN)
|
|
} else {
|
|
(*TExpr)(unsafe.Pointer(pExpr)).FiTable = (*TUpsert)(unsafe.Pointer(*(*uintptr)(unsafe.Pointer(pNC + 8)))).FregData + int32(_sqlite3TableColumnToStorage(tls, pTab, int16(iCol)))
|
|
eNewExprOp = int32(TK_REGISTER)
|
|
}
|
|
} else {
|
|
(*TExpr)(unsafe.Pointer(pExpr)).Fy.FpTab = pTab
|
|
if int32(Tbft(*(*uint16)(unsafe.Pointer(pParse + 28))&0x8>>3)) != 0 {
|
|
eNewExprOp = int32(TK_REGISTER)
|
|
(*TExpr)(unsafe.Pointer(pExpr)).Fop2 = uint8(TK_COLUMN)
|
|
(*TExpr)(unsafe.Pointer(pExpr)).FiColumn = int16(iCol)
|
|
(*TExpr)(unsafe.Pointer(pExpr)).FiTable = *(*int32)(unsafe.Pointer(pNC + 8)) + (int32((*TTable)(unsafe.Pointer(pTab)).FnCol)+int32(1))*(*TExpr)(unsafe.Pointer(pExpr)).FiTable + int32(_sqlite3TableColumnToStorage(tls, pTab, int16(iCol))) + int32(1)
|
|
} else {
|
|
(*TExpr)(unsafe.Pointer(pExpr)).FiColumn = int16(iCol)
|
|
eNewExprOp = int32(TK_TRIGGER)
|
|
if iCol < 0 {
|
|
(*TExpr)(unsafe.Pointer(pExpr)).FaffExpr = int8(SQLITE_AFF_INTEGER)
|
|
} else {
|
|
if (*TExpr)(unsafe.Pointer(pExpr)).FiTable == 0 {
|
|
if iCol >= int32(32) {
|
|
v5 = uint32(0xffffffff)
|
|
} else {
|
|
v5 = libc.Uint32FromInt32(1) << iCol
|
|
}
|
|
**(**Tu32)(__ccgo_up(pParse + 180)) |= v5
|
|
} else {
|
|
if iCol >= int32(32) {
|
|
v5 = uint32(0xffffffff)
|
|
} else {
|
|
v5 = libc.Uint32FromInt32(1) << iCol
|
|
}
|
|
**(**Tu32)(__ccgo_up(pParse + 184)) |= v5
|
|
}
|
|
}
|
|
}
|
|
}
|
|
}
|
|
}
|
|
}
|
|
/*
|
|
** Perhaps the name is a reference to the ROWID
|
|
*/
|
|
if cnt == 0 && cntTab >= int32(1) && pMatch != 0 && (*TNameContext)(unsafe.Pointer(pNC)).FncFlags&(libc.Int32FromInt32(NC_IdxExpr)|libc.Int32FromInt32(NC_GenCol)) == 0 && _sqlite3IsRowid(tls, zCol) != 0 && ((*TTable)(unsafe.Pointer((*TSrcItem)(unsafe.Pointer(pMatch)).FpSTab)).FtabFlags&uint32(TF_NoVisibleRowid) == uint32(0) || int32(*(*uint32)(unsafe.Pointer(pMatch + 12 + 4))&0x4000>>14) != 0) {
|
|
cnt = cntTab
|
|
if int32(*(*uint32)(unsafe.Pointer(pMatch + 12 + 4))&0x4000>>14) == 0 {
|
|
(*TExpr)(unsafe.Pointer(pExpr)).FiColumn = int16(-int32(1))
|
|
}
|
|
(*TExpr)(unsafe.Pointer(pExpr)).FaffExpr = int8(SQLITE_AFF_INTEGER)
|
|
}
|
|
/*
|
|
** If the input is of the form Z (not Y.Z or X.Y.Z) then the name Z
|
|
** might refer to an result-set alias. This happens, for example, when
|
|
** we are resolving names in the WHERE clause of the following command:
|
|
**
|
|
** SELECT a+b AS x FROM table WHERE x<10;
|
|
**
|
|
** In cases like this, replace pExpr with a copy of the expression that
|
|
** forms the result set entry ("a+b" in the example) and return immediately.
|
|
** Note that the expression in the result set should have already been
|
|
** resolved by the time the WHERE clause is resolved.
|
|
**
|
|
** The ability to use an output result-set column in the WHERE, GROUP BY,
|
|
** or HAVING clauses, or as part of a larger expression in the ORDER BY
|
|
** clause is not standard SQL. This is a (goofy) SQLite extension, that
|
|
** is supported for backwards compatibility only. Hence, we issue a warning
|
|
** on sqlite3_log() whenever the capability is used.
|
|
*/
|
|
if cnt == 0 && (*TNameContext)(unsafe.Pointer(pNC)).FncFlags&int32(NC_UEList) != 0 && zTab == uintptr(0) {
|
|
pEList = *(*uintptr)(unsafe.Pointer(pNC + 8))
|
|
j = 0
|
|
for {
|
|
if !(j < (*TExprList)(unsafe.Pointer(pEList)).FnExpr) {
|
|
break
|
|
}
|
|
zAs = (*(*TExprList_item)(unsafe.Pointer(pEList + 8 + uintptr(j)*20))).FzEName
|
|
if int32(uint32(*(*uint16)(unsafe.Pointer(pEList + 8 + uintptr(j)*20 + 8 + 4))&0x3>>0)) == ENAME_NAME && Xsqlite3_stricmp(tls, zAs, zCol) == 0 {
|
|
pOrig = (*(*TExprList_item)(unsafe.Pointer(pEList + 8 + uintptr(j)*20))).FpExpr
|
|
if (*TNameContext)(unsafe.Pointer(pNC)).FncFlags&int32(NC_AllowAgg) == 0 && (*TExpr)(unsafe.Pointer(pOrig)).Fflags&libc.Uint32FromInt32(libc.Int32FromInt32(EP_Agg)) != uint32(0) {
|
|
_sqlite3ErrorMsg(tls, pParse, __ccgo_ts+6842, libc.VaList(bp+16, zAs))
|
|
return int32(WRC_Abort)
|
|
}
|
|
if (*TExpr)(unsafe.Pointer(pOrig)).Fflags&libc.Uint32FromInt32(libc.Int32FromInt32(EP_Win)) != uint32(0) && ((*TNameContext)(unsafe.Pointer(pNC)).FncFlags&int32(NC_AllowWin) == 0 || pNC != pTopNC) {
|
|
_sqlite3ErrorMsg(tls, pParse, __ccgo_ts+6873, libc.VaList(bp+16, zAs))
|
|
return int32(WRC_Abort)
|
|
}
|
|
if _sqlite3ExprVectorSize(tls, pOrig) != int32(1) {
|
|
_sqlite3ErrorMsg(tls, pParse, __ccgo_ts+6910, 0)
|
|
return int32(WRC_Abort)
|
|
}
|
|
_resolveAlias(tls, pParse, pEList, j, pExpr, nSubquery)
|
|
cnt = int32(1)
|
|
pMatch = uintptr(0)
|
|
if libc.Int32FromUint8((*TParse)(unsafe.Pointer(pParse)).FeParseMode) >= int32(PARSE_MODE_RENAME) {
|
|
_sqlite3RenameTokenRemap(tls, pParse, uintptr(0), pExpr)
|
|
}
|
|
goto lookupname_end
|
|
}
|
|
goto _7
|
|
_7:
|
|
;
|
|
j = j + 1
|
|
}
|
|
}
|
|
/* Advance to the next name context. The loop will exit when either
|
|
** we have a match (cnt>0) or when we run out of name contexts.
|
|
*/
|
|
if cnt != 0 {
|
|
break
|
|
}
|
|
pNC = (*TNameContext)(unsafe.Pointer(pNC)).FpNext
|
|
nSubquery = nSubquery + 1
|
|
}
|
|
/*
|
|
** If X and Y are NULL (in other words if only the column name Z is
|
|
** supplied) and the value of Z is enclosed in double-quotes, then
|
|
** Z is a string literal if it doesn't match any column names. In that
|
|
** case, we need to return right away and not make any changes to
|
|
** pExpr.
|
|
**
|
|
** Because no reference was made to outer contexts, the pNC->nRef
|
|
** fields are not changed in any context.
|
|
*/
|
|
if cnt == 0 && zTab == uintptr(0) {
|
|
if (*TExpr)(unsafe.Pointer(pExpr)).Fflags&libc.Uint32FromInt32(libc.Int32FromInt32(EP_DblQuoted)) != uint32(0) && _areDoubleQuotedStringsEnabled(tls, db, pTopNC) != 0 {
|
|
/* If a double-quoted identifier does not match any known column name,
|
|
** then treat it as a string.
|
|
**
|
|
** This hack was added in the early days of SQLite in a misguided attempt
|
|
** to be compatible with MySQL 3.x, which used double-quotes for strings.
|
|
** I now sorely regret putting in this hack. The effect of this hack is
|
|
** that misspelled identifier names are silently converted into strings
|
|
** rather than causing an error, to the frustration of countless
|
|
** programmers. To all those frustrated programmers, my apologies.
|
|
**
|
|
** Someday, I hope to get rid of this hack. Unfortunately there is
|
|
** a huge amount of legacy SQL that uses it. So for now, we just
|
|
** issue a warning.
|
|
*/
|
|
Xsqlite3_log(tls, int32(SQLITE_WARNING), __ccgo_ts+6928, libc.VaList(bp+16, zCol))
|
|
(*TExpr)(unsafe.Pointer(pExpr)).Fop = uint8(TK_STRING)
|
|
libc.Xmemset(tls, pExpr+44, 0, uint32(8))
|
|
return int32(WRC_Prune)
|
|
}
|
|
if _sqlite3ExprIdToTrueFalse(tls, pExpr) != 0 {
|
|
return int32(WRC_Prune)
|
|
}
|
|
}
|
|
/*
|
|
** cnt==0 means there was not match.
|
|
** cnt>1 means there were two or more matches.
|
|
**
|
|
** cnt==0 is always an error. cnt>1 is often an error, but might
|
|
** be multiple matches for a NATURAL LEFT JOIN or a LEFT JOIN USING.
|
|
*/
|
|
if cnt != int32(1) {
|
|
if **(**uintptr)(__ccgo_up(bp)) != 0 {
|
|
if (*TExprList)(unsafe.Pointer(**(**uintptr)(__ccgo_up(bp)))).FnExpr == cnt-int32(1) {
|
|
if (*TExpr)(unsafe.Pointer(pExpr)).Fflags&libc.Uint32FromInt32(libc.Int32FromInt32(EP_Leaf)) != uint32(0) {
|
|
**(**Tu32)(__ccgo_up(pExpr + 4)) &= ^libc.Uint32FromInt32(libc.Int32FromInt32(EP_Leaf))
|
|
} else {
|
|
_sqlite3ExprDelete(tls, db, (*TExpr)(unsafe.Pointer(pExpr)).FpLeft)
|
|
(*TExpr)(unsafe.Pointer(pExpr)).FpLeft = uintptr(0)
|
|
_sqlite3ExprDelete(tls, db, (*TExpr)(unsafe.Pointer(pExpr)).FpRight)
|
|
(*TExpr)(unsafe.Pointer(pExpr)).FpRight = uintptr(0)
|
|
}
|
|
_extendFJMatch(tls, pParse, bp, pMatch, (*TExpr)(unsafe.Pointer(pExpr)).FiColumn)
|
|
(*TExpr)(unsafe.Pointer(pExpr)).Fop = uint8(TK_FUNCTION)
|
|
*(*uintptr)(unsafe.Pointer(pExpr + 8)) = __ccgo_ts + 6963
|
|
*(*uintptr)(unsafe.Pointer(pExpr + 20)) = **(**uintptr)(__ccgo_up(bp))
|
|
(*TExpr)(unsafe.Pointer(pExpr)).FaffExpr = int8(SQLITE_AFF_DEFER)
|
|
cnt = int32(1)
|
|
goto lookupname_end
|
|
} else {
|
|
_sqlite3ExprListDelete(tls, db, **(**uintptr)(__ccgo_up(bp)))
|
|
**(**uintptr)(__ccgo_up(bp)) = uintptr(0)
|
|
}
|
|
}
|
|
if cnt == 0 {
|
|
v8 = __ccgo_ts + 6972
|
|
} else {
|
|
v8 = __ccgo_ts + 6987
|
|
}
|
|
zErr = v8
|
|
if zDb != 0 {
|
|
_sqlite3ErrorMsg(tls, pParse, __ccgo_ts+7009, libc.VaList(bp+16, zErr, zDb, zTab, zCol))
|
|
} else {
|
|
if zTab != 0 {
|
|
_sqlite3ErrorMsg(tls, pParse, __ccgo_ts+7022, libc.VaList(bp+16, zErr, zTab, zCol))
|
|
} else {
|
|
if cnt == 0 && (*TExpr)(unsafe.Pointer(pRight)).Fflags&libc.Uint32FromInt32(libc.Int32FromInt32(EP_DblQuoted)) != uint32(0) {
|
|
_sqlite3ErrorMsg(tls, pParse, __ccgo_ts+7032, libc.VaList(bp+16, zErr, zCol))
|
|
} else {
|
|
_sqlite3ErrorMsg(tls, pParse, __ccgo_ts+7093, libc.VaList(bp+16, zErr, zCol))
|
|
}
|
|
}
|
|
}
|
|
_sqlite3RecordErrorOffsetOfExpr(tls, (*TParse)(unsafe.Pointer(pParse)).Fdb, pExpr)
|
|
libc.SetBitFieldPtr16Uint32(pParse+28, libc.Uint32FromInt32(1), 8, 0x100)
|
|
(*TNameContext)(unsafe.Pointer(pTopNC)).FnNcErr = (*TNameContext)(unsafe.Pointer(pTopNC)).FnNcErr + 1
|
|
eNewExprOp = int32(TK_NULL)
|
|
}
|
|
/* Remove all substructure from pExpr */
|
|
if !((*TExpr)(unsafe.Pointer(pExpr)).Fflags&libc.Uint32FromInt32(libc.Int32FromInt32(EP_TokenOnly)|libc.Int32FromInt32(EP_Leaf)) != libc.Uint32FromInt32(0)) {
|
|
_sqlite3ExprDelete(tls, db, (*TExpr)(unsafe.Pointer(pExpr)).FpLeft)
|
|
(*TExpr)(unsafe.Pointer(pExpr)).FpLeft = uintptr(0)
|
|
_sqlite3ExprDelete(tls, db, (*TExpr)(unsafe.Pointer(pExpr)).FpRight)
|
|
(*TExpr)(unsafe.Pointer(pExpr)).FpRight = uintptr(0)
|
|
**(**Tu32)(__ccgo_up(pExpr + 4)) |= libc.Uint32FromInt32(libc.Int32FromInt32(EP_Leaf))
|
|
}
|
|
/* If a column from a table in pSrcList is referenced, then record
|
|
** this fact in the pSrcList.a[].colUsed bitmask. Column 0 causes
|
|
** bit 0 to be set. Column 1 sets bit 1. And so forth. Bit 63 is
|
|
** set if the 63rd or any subsequent column is used.
|
|
**
|
|
** The colUsed mask is an optimization used to help determine if an
|
|
** index is a covering index. The correct answer is still obtained
|
|
** if the mask contains extra set bits. However, it is important to
|
|
** avoid setting bits beyond the maximum column number of the table.
|
|
** (See ticket [b92e5e8ec2cdbaa1]).
|
|
**
|
|
** If a generated column is referenced, set bits for every column
|
|
** of the table.
|
|
*/
|
|
if pMatch != 0 {
|
|
if int32((*TExpr)(unsafe.Pointer(pExpr)).FiColumn) >= 0 {
|
|
**(**TBitmask)(__ccgo_up(pMatch + 24)) |= _sqlite3ExprColUsed(tls, pExpr)
|
|
} else {
|
|
libc.SetBitFieldPtr32Uint32(pMatch+12+4, libc.Uint32FromInt32(1), 15, 0x8000)
|
|
}
|
|
}
|
|
(*TExpr)(unsafe.Pointer(pExpr)).Fop = libc.Uint8FromInt32(eNewExprOp)
|
|
goto lookupname_end
|
|
lookupname_end:
|
|
;
|
|
if cnt == int32(1) {
|
|
if (*Tsqlite3)(unsafe.Pointer((*TParse)(unsafe.Pointer(pParse)).Fdb)).FxAuth != 0 && (libc.Int32FromUint8((*TExpr)(unsafe.Pointer(pExpr)).Fop) == int32(TK_COLUMN) || libc.Int32FromUint8((*TExpr)(unsafe.Pointer(pExpr)).Fop) == int32(TK_TRIGGER)) {
|
|
_sqlite3AuthRead(tls, pParse, pExpr, pSchema, (*TNameContext)(unsafe.Pointer(pNC)).FpSrcList)
|
|
}
|
|
/* Increment the nRef value on all name contexts from TopNC up to
|
|
** the point where the name matched. */
|
|
for {
|
|
(*TNameContext)(unsafe.Pointer(pTopNC)).FnRef = (*TNameContext)(unsafe.Pointer(pTopNC)).FnRef + 1
|
|
if pTopNC == pNC {
|
|
break
|
|
}
|
|
pTopNC = (*TNameContext)(unsafe.Pointer(pTopNC)).FpNext
|
|
goto _9
|
|
_9:
|
|
}
|
|
return int32(WRC_Prune)
|
|
} else {
|
|
return int32(WRC_Abort)
|
|
}
|
|
return r
|
|
}
|
|
|
|
// 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+27406, iNode, 0, pRtree+76)
|
|
}
|
|
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(uint32(28)+libc.Uint32FromInt32((*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*28
|
|
(*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
|
|
}
|
|
|
|
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(12))
|
|
if p != 0 {
|
|
switch Xsqlite3_value_numeric_type(tls, **(**uintptr)(__ccgo_up(apArg + 1*4))) {
|
|
case int32(SQLITE_INTEGER):
|
|
iVal = Xsqlite3_value_int64(tls, **(**uintptr)(__ccgo_up(apArg + 1*4)))
|
|
case int32(SQLITE_FLOAT):
|
|
fVal = Xsqlite3_value_double(tls, **(**uintptr)(__ccgo_up(apArg + 1*4)))
|
|
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+24177, -int32(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(32)
|
|
defer tls.Free(32)
|
|
*(*uint32)(unsafe.Pointer(bp)) = _flags
|
|
var db, v2 uintptr
|
|
var i, isThreadsafe, rc int32
|
|
var v1 uint32
|
|
var _ /* zErrMsg at bp+8 */ uintptr
|
|
var _ /* zOpen at bp+4 */ uintptr
|
|
_, _, _, _, _, _ = db, i, isThreadsafe, rc, v1, v2 /* True for threadsafe connections */
|
|
**(**uintptr)(__ccgo_up(bp + 4)) = uintptr(0) /* Filename argument to pass to BtreeOpen() */
|
|
**(**uintptr)(__ccgo_up(bp + 8)) = 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(576))
|
|
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 + 472
|
|
(*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+116, uintptr(unsafe.Pointer(&_aHardLimit)), uint32(52))
|
|
**(**int32)(__ccgo_up(db + 116 + 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 + 28)) |= 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+444)
|
|
_sqlite3HashInit(tls, db+400)
|
|
/* 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+23943, uint8(SQLITE_UTF8), uintptr(0), __ccgo_fp(_nocaseCollatingFunc), uintptr(0))
|
|
_createCollation(tls, db, __ccgo_ts+26260, 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 + 4341
|
|
}
|
|
rc = _sqlite3ParseUri(tls, zVfs, zFilename, bp, db, bp+4, bp+8)
|
|
}
|
|
if rc != SQLITE_OK {
|
|
if rc == int32(SQLITE_NOMEM) {
|
|
_sqlite3OomFault(tls, db)
|
|
}
|
|
if **(**uintptr)(__ccgo_up(bp + 8)) != 0 {
|
|
v2 = __ccgo_ts + 3942
|
|
} else {
|
|
v2 = uintptr(0)
|
|
}
|
|
_sqlite3ErrorWithMsg(tls, db, rc, v2, libc.VaList(bp+24, **(**uintptr)(__ccgo_up(bp + 8))))
|
|
Xsqlite3_free(tls, **(**uintptr)(__ccgo_up(bp + 8)))
|
|
goto opendb_out
|
|
}
|
|
/* Open the backend database driver */
|
|
rc = _sqlite3BtreeOpen(tls, (*Tsqlite3)(unsafe.Pointer(db)).FpVfs, **(**uintptr)(__ccgo_up(bp + 4)), db, (*Tsqlite3)(unsafe.Pointer(db)).FaDb+4, 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*16))).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 + 6818
|
|
(**(**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*16))).FzDbSName = __ccgo_ts + 25262
|
|
(**(**TDb)(__ccgo_up((*Tsqlite3)(unsafe.Pointer(db)).FaDb + 1*16))).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.Int32FromUint32(libc.Uint32FromInt64(20)/libc.Uint32FromInt64(4))) {
|
|
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 + 4)))
|
|
return rc
|
|
}
|
|
|
|
// C documentation
|
|
//
|
|
// /*
|
|
// ** Open a file descriptor to the directory containing file zFilename.
|
|
// ** If successful, *pFd is set to the opened file descriptor and
|
|
// ** SQLITE_OK is returned. If an error occurs, either SQLITE_NOMEM
|
|
// ** or SQLITE_CANTOPEN is returned and *pFd is set to an undefined
|
|
// ** value.
|
|
// **
|
|
// ** The directory file descriptor is used for only one thing - to
|
|
// ** fsync() a directory to make sure file creation and deletion events
|
|
// ** are flushed to disk. Such fsyncs are not needed on newer
|
|
// ** journaling filesystems, but are required on older filesystems.
|
|
// **
|
|
// ** This routine can be overridden using the xSetSysCall interface.
|
|
// ** The ability to override this routine was added in support of the
|
|
// ** chromium sandbox. Opening a directory is a security risk (we are
|
|
// ** told) so making it overrideable allows the chromium sandbox to
|
|
// ** replace this routine with a harmless no-op. To make this routine
|
|
// ** a no-op, replace it with a stub that returns SQLITE_OK but leaves
|
|
// ** *pFd set to a negative number.
|
|
// **
|
|
// ** If SQLITE_OK is returned, the caller is responsible for closing
|
|
// ** the file descriptor *pFd using close().
|
|
// */
|
|
func _openDirectory(tls *libc.TLS, zFilename uintptr, pFd uintptr) (r int32) {
|
|
bp := tls.Alloc(544)
|
|
defer tls.Free(544)
|
|
var fd, ii int32
|
|
var _ /* zDirname at bp+0 */ [513]int8
|
|
_, _ = fd, ii
|
|
fd = -int32(1)
|
|
Xsqlite3_snprintf(tls, int32(MAX_PATHNAME), bp, __ccgo_ts+3942, libc.VaList(bp+528, zFilename))
|
|
ii = libc.Int32FromUint32(libc.Xstrlen(tls, bp))
|
|
for {
|
|
if !(ii > 0 && int32((**(**[513]int8)(__ccgo_up(bp)))[ii]) != int32('/')) {
|
|
break
|
|
}
|
|
goto _1
|
|
_1:
|
|
;
|
|
ii = ii - 1
|
|
}
|
|
if ii > 0 {
|
|
(**(**[513]int8)(__ccgo_up(bp)))[ii] = int8('\000')
|
|
} else {
|
|
if int32((**(**[513]int8)(__ccgo_up(bp)))[0]) != int32('/') {
|
|
(**(**[513]int8)(__ccgo_up(bp)))[0] = int8('.')
|
|
}
|
|
(**(**[513]int8)(__ccgo_up(bp)))[int32(1)] = 0
|
|
}
|
|
fd = _robust_open(tls, bp, libc.Int32FromInt32(O_RDONLY)|libc.Int32FromInt32(O_BINARY), uint16(0))
|
|
if fd >= 0 {
|
|
}
|
|
**(**int32)(__ccgo_up(pFd)) = fd
|
|
if fd >= 0 {
|
|
return SQLITE_OK
|
|
}
|
|
return _unixLogErrorAtLine(tls, _sqlite3CantopenError(tls, int32(44090)), __ccgo_ts+3657, bp, int32(44090))
|
|
}
|
|
|
|
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 uint32
|
|
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 = uint32(0)
|
|
}
|
|
nTarget = v1
|
|
nRbu = libc.Xstrlen(tls, zRbu)
|
|
nByte = uint32(256) + nTarget + uint32(1) + nRbu + uint32(1)
|
|
p = Xsqlite3_malloc64(tls, uint64(nByte))
|
|
if p != 0 {
|
|
pState = uintptr(0)
|
|
/* Create the custom VFS. */
|
|
libc.Xmemset(tls, p, 0, uint32(256))
|
|
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*256
|
|
**(**int32)(__ccgo_up(bp)) = 0
|
|
if zTarget != 0 {
|
|
(*Tsqlite3rbu)(unsafe.Pointer(p)).FzTarget = pCsr
|
|
libc.Xmemcpy(tls, (*Tsqlite3rbu)(unsafe.Pointer(p)).FzTarget, zTarget, nTarget+uint32(1))
|
|
pCsr = pCsr + uintptr(nTarget+uint32(1))
|
|
}
|
|
(*Tsqlite3rbu)(unsafe.Pointer(p)).FzRbu = pCsr
|
|
libc.Xmemcpy(tls, (*Tsqlite3rbu)(unsafe.Pointer(p)).FzRbu, zRbu, nRbu+uint32(1))
|
|
pCsr = pCsr + uintptr(nRbu+uint32(1))
|
|
if zState != 0 {
|
|
(*Tsqlite3rbu)(unsafe.Pointer(p)).FzState = _rbuMPrintf(tls, p, __ccgo_ts+3942, 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+34556, 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 + 34588
|
|
} else {
|
|
v2 = __ccgo_ts + 34595
|
|
}
|
|
(*Tsqlite3rbu)(unsafe.Pointer(p)).FzErrmsg = Xsqlite3_mprintf(tls, __ccgo_ts+34602, 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+16105, uintptr(0), uintptr(0), p+36)
|
|
/* 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+52)
|
|
}
|
|
/* 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+18652)
|
|
_rbuCopyPragma(tls, p, __ccgo_ts+18064)
|
|
}
|
|
/* 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+34634, uintptr(0), uintptr(0), p+36)
|
|
}
|
|
/* 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+6818, int32(SQLITE_FCNTL_ZIPVFS), uintptr(0))
|
|
if frc == SQLITE_OK {
|
|
(*Tsqlite3rbu)(unsafe.Pointer(p)).Frc = Xsqlite3_exec(tls, db, __ccgo_ts+34650, uintptr(0), uintptr(0), p+36)
|
|
}
|
|
}
|
|
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
|
|
//
|
|
// /*
|
|
// ** Check if zSuper is a valid super-journal name. There are two valid
|
|
// ** formats:
|
|
// **
|
|
// ** + The 3rd and 4th last bytes of the filename are ".9", and the
|
|
// ** following 2 bytes are hex digits. This is a file created in 8.3
|
|
// ** filenames mode.
|
|
// **
|
|
// ** + The 3rd last byte of the filename is "9" and the filename
|
|
// ** contains the string "-mj" starting at the 12th last byte.
|
|
// ** All bytes following the "-mj" are hex digits.
|
|
// **
|
|
// ** If the filename matches either of these patterns, return non-zero.
|
|
// ** Otherwise, return zero.
|
|
// */
|
|
func _pagerIsSuperJrnlName(tls *libc.TLS, zSuper uintptr) (r int32) {
|
|
var ii, nSuper int32
|
|
_, _ = ii, nSuper
|
|
nSuper = _sqlite3Strlen30(tls, zSuper)
|
|
if nSuper < int32(4) {
|
|
return 0
|
|
}
|
|
if int32(**(**int8)(__ccgo_up(zSuper + uintptr(nSuper-int32(3))))) != int32('9') {
|
|
return 0
|
|
}
|
|
if nSuper < int32(12) {
|
|
return 0
|
|
}
|
|
if libc.Xmemcmp(tls, zSuper+uintptr(nSuper-int32(12)), __ccgo_ts+4198, uint32(3)) != 0 {
|
|
return 0
|
|
}
|
|
ii = nSuper - int32(9)
|
|
for {
|
|
if !(ii < nSuper) {
|
|
break
|
|
}
|
|
if libc.Int32FromUint8(_sqlite3CtypeMap[libc.Uint8FromInt8(**(**int8)(__ccgo_up(zSuper + uintptr(ii))))])&int32(0x08) == 0 {
|
|
return 0
|
|
}
|
|
goto _1
|
|
_1:
|
|
;
|
|
ii = ii + 1
|
|
}
|
|
return int32(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+24 */ Tu32
|
|
var _ /* szJ at bp+0 */ Ti64
|
|
var _ /* zSuper at bp+20 */ 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 + 20)) = uintptr(0) /* True to reset page prior to first page rollback */
|
|
nPlayback = 0 /* Total number of pages restored from journal */
|
|
**(**Tu32)(__ccgo_up(bp + 24)) = 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+20)
|
|
if rc == SQLITE_OK && **(**uintptr)(__ccgo_up(bp + 20)) != 0 {
|
|
rc = _sqlite3OsAccess(tls, pVfs, **(**uintptr)(__ccgo_up(bp + 20)), 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+76, 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+24, -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 + 20)) != uintptr(0)), 0)
|
|
}
|
|
if rc == SQLITE_OK && **(**uintptr)(__ccgo_up(bp + 20)) != 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 + 20)))
|
|
}
|
|
if isHot != 0 && nPlayback != 0 {
|
|
Xsqlite3_log(tls, libc.Int32FromInt32(SQLITE_NOTICE)|libc.Int32FromInt32(2)<<libc.Int32FromInt32(8), __ccgo_ts+4202, libc.VaList(bp+40, 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 + 20)))
|
|
_setSectorSize(tls, pPager)
|
|
return rc
|
|
}
|
|
|
|
// C documentation
|
|
//
|
|
// /*
|
|
// ** Process a modifier to a date-time stamp. The modifiers are
|
|
// ** as follows:
|
|
// **
|
|
// ** NNN days
|
|
// ** NNN hours
|
|
// ** NNN minutes
|
|
// ** NNN.NNNN seconds
|
|
// ** NNN months
|
|
// ** NNN years
|
|
// ** +/-YYYY-MM-DD HH:MM:SS.SSS
|
|
// ** ceiling
|
|
// ** floor
|
|
// ** start of month
|
|
// ** start of year
|
|
// ** start of week
|
|
// ** start of day
|
|
// ** weekday N
|
|
// ** unixepoch
|
|
// ** auto
|
|
// ** localtime
|
|
// ** utc
|
|
// ** subsec
|
|
// ** subsecond
|
|
// **
|
|
// ** Return 0 on success and 1 if there is any kind of error. If the error
|
|
// ** is in a system call (i.e. localtime()), then an error message is written
|
|
// ** to context pCtx. If the error is an unrecognized modifier, no error is
|
|
// ** written to pCtx.
|
|
// */
|
|
func _parseModifier(tls *libc.TLS, pCtx uintptr, z uintptr, n int32, p uintptr, idx int32) (r int32) {
|
|
bp := tls.Alloc(160)
|
|
defer tls.Free(160)
|
|
var Z, day Tsqlite3_int64
|
|
var cnt, i, rc, rx, x, y, v1 int32
|
|
var db, z2, zCopy uintptr
|
|
var iErr, iGuess, iOrigJD, v2 Ti64
|
|
var rRounder, v11 float64
|
|
var z0 int8
|
|
var v4 bool
|
|
var _ /* D at bp+64 */ int32
|
|
var _ /* M at bp+60 */ int32
|
|
var _ /* Y at bp+56 */ int32
|
|
var _ /* h at bp+68 */ int32
|
|
var _ /* m at bp+72 */ int32
|
|
var _ /* new at bp+8 */ TDateTime
|
|
var _ /* r at bp+0 */ float64
|
|
var _ /* tx at bp+76 */ TDateTime
|
|
_, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _ = Z, cnt, day, db, i, iErr, iGuess, iOrigJD, rRounder, rc, rx, x, y, z0, z2, zCopy, v1, v11, v2, v4
|
|
rc = int32(1)
|
|
switch libc.Int32FromUint8(_sqlite3UpperToLower[libc.Uint8FromInt8(**(**int8)(__ccgo_up(z)))]) {
|
|
case int32('a'):
|
|
/*
|
|
** auto
|
|
**
|
|
** If rawS is available, then interpret as a julian day number, or
|
|
** a unix timestamp, depending on its magnitude.
|
|
*/
|
|
if Xsqlite3_stricmp(tls, z, __ccgo_ts+1270) == 0 {
|
|
if idx > int32(1) {
|
|
return int32(1)
|
|
} /* IMP: R-33611-57934 */
|
|
_autoAdjustDate(tls, p)
|
|
rc = 0
|
|
}
|
|
case int32('c'):
|
|
/*
|
|
** ceiling
|
|
**
|
|
** Resolve day-of-month overflow by rolling forward into the next
|
|
** month. As this is the default action, this modifier is really
|
|
** a no-op that is only included for symmetry. See "floor".
|
|
*/
|
|
if Xsqlite3_stricmp(tls, z, __ccgo_ts+1275) == 0 {
|
|
_computeJD(tls, p)
|
|
_clearYMD_HMS_TZ(tls, p)
|
|
rc = 0
|
|
(*TDateTime)(unsafe.Pointer(p)).FnFloor = 0
|
|
}
|
|
case int32('f'):
|
|
/*
|
|
** floor
|
|
**
|
|
** Resolve day-of-month overflow by rolling back to the end of the
|
|
** previous month.
|
|
*/
|
|
if Xsqlite3_stricmp(tls, z, __ccgo_ts+1283) == 0 {
|
|
_computeJD(tls, p)
|
|
**(**Tsqlite3_int64)(__ccgo_up(p)) -= int64(int32((*TDateTime)(unsafe.Pointer(p)).FnFloor) * int32(86400000))
|
|
_clearYMD_HMS_TZ(tls, p)
|
|
rc = 0
|
|
}
|
|
case int32('j'):
|
|
/*
|
|
** julianday
|
|
**
|
|
** Always interpret the prior number as a julian-day value. If this
|
|
** is not the first modifier, or if the prior argument is not a numeric
|
|
** value in the allowed range of julian day numbers understood by
|
|
** SQLite (0..5373484.5) then the result will be NULL.
|
|
*/
|
|
if Xsqlite3_stricmp(tls, z, __ccgo_ts+1289) == 0 {
|
|
if idx > int32(1) {
|
|
return int32(1)
|
|
} /* IMP: R-31176-64601 */
|
|
if (*TDateTime)(unsafe.Pointer(p)).FvalidJD != 0 && int32(uint32(*(*uint8)(unsafe.Pointer(p + 44))&0x1>>0)) != 0 {
|
|
rc = 0
|
|
libc.SetBitFieldPtr8Uint32(p+44, libc.Uint32FromInt32(0), 0, 0x1)
|
|
}
|
|
}
|
|
case int32('l'):
|
|
/* localtime
|
|
**
|
|
** Assuming the current time value is UTC (a.k.a. GMT), shift it to
|
|
** show local time.
|
|
*/
|
|
if Xsqlite3_stricmp(tls, z, __ccgo_ts+1299) == 0 && _sqlite3NotPureFunc(tls, pCtx) != 0 {
|
|
if int32(uint32(*(*uint8)(unsafe.Pointer(p + 44))&0x10>>4)) != 0 {
|
|
v1 = SQLITE_OK
|
|
} else {
|
|
v1 = _toLocaltime(tls, p, pCtx)
|
|
}
|
|
rc = v1
|
|
libc.SetBitFieldPtr8Uint32(p+44, libc.Uint32FromInt32(0), 3, 0x8)
|
|
libc.SetBitFieldPtr8Uint32(p+44, libc.Uint32FromInt32(1), 4, 0x10)
|
|
}
|
|
case int32('u'):
|
|
/*
|
|
** unixepoch
|
|
**
|
|
** Treat the current value of p->s as the number of
|
|
** seconds since 1970. Convert to a real julian day number.
|
|
*/
|
|
if Xsqlite3_stricmp(tls, z, __ccgo_ts+1309) == 0 && int32(uint32(*(*uint8)(unsafe.Pointer(p + 44))&0x1>>0)) != 0 {
|
|
if idx > int32(1) {
|
|
return int32(1)
|
|
} /* IMP: R-49255-55373 */
|
|
**(**float64)(__ccgo_up(bp)) = float64((*TDateTime)(unsafe.Pointer(p)).Fs*float64(1000)) + float64(2.1086676e+14)
|
|
if **(**float64)(__ccgo_up(bp)) >= float64(0) && **(**float64)(__ccgo_up(bp)) < float64(4.642690608e+14) {
|
|
_clearYMD_HMS_TZ(tls, p)
|
|
(*TDateTime)(unsafe.Pointer(p)).FiJD = int64(**(**float64)(__ccgo_up(bp)) + libc.Float64FromFloat64(0.5))
|
|
(*TDateTime)(unsafe.Pointer(p)).FvalidJD = int8(1)
|
|
libc.SetBitFieldPtr8Uint32(p+44, libc.Uint32FromInt32(0), 0, 0x1)
|
|
rc = 0
|
|
}
|
|
} else {
|
|
if Xsqlite3_stricmp(tls, z, __ccgo_ts+1319) == 0 && _sqlite3NotPureFunc(tls, pCtx) != 0 {
|
|
if int32(uint32(*(*uint8)(unsafe.Pointer(p + 44))&0x8>>3)) == 0 { /* Guess at the corresponding utc time */
|
|
cnt = 0 /* Guess is off by this much */
|
|
_computeJD(tls, p)
|
|
v2 = (*TDateTime)(unsafe.Pointer(p)).FiJD
|
|
iOrigJD = v2
|
|
iGuess = v2
|
|
iErr = 0
|
|
for {
|
|
libc.Xmemset(tls, bp+8, 0, uint32(48))
|
|
iGuess = iGuess - iErr
|
|
(**(**TDateTime)(__ccgo_up(bp + 8))).FiJD = iGuess
|
|
(**(**TDateTime)(__ccgo_up(bp + 8))).FvalidJD = int8(1)
|
|
rc = _toLocaltime(tls, bp+8, pCtx)
|
|
if rc != 0 {
|
|
return rc
|
|
}
|
|
_computeJD(tls, bp+8)
|
|
iErr = (**(**TDateTime)(__ccgo_up(bp + 8))).FiJD - iOrigJD
|
|
goto _5
|
|
_5:
|
|
;
|
|
if v4 = iErr != 0; v4 {
|
|
v1 = cnt
|
|
cnt = cnt + 1
|
|
}
|
|
if !(v4 && v1 < int32(3)) {
|
|
break
|
|
}
|
|
}
|
|
libc.Xmemset(tls, p, 0, uint32(48))
|
|
(*TDateTime)(unsafe.Pointer(p)).FiJD = iGuess
|
|
(*TDateTime)(unsafe.Pointer(p)).FvalidJD = int8(1)
|
|
libc.SetBitFieldPtr8Uint32(p+44, libc.Uint32FromInt32(1), 3, 0x8)
|
|
libc.SetBitFieldPtr8Uint32(p+44, libc.Uint32FromInt32(0), 4, 0x10)
|
|
}
|
|
rc = SQLITE_OK
|
|
}
|
|
}
|
|
case int32('w'):
|
|
/*
|
|
** weekday N
|
|
**
|
|
** Move the date to the same time on the next occurrence of
|
|
** weekday N where 0==Sunday, 1==Monday, and so forth. If the
|
|
** date is already on the appropriate weekday, this is a no-op.
|
|
*/
|
|
if v4 = Xsqlite3_strnicmp(tls, z, __ccgo_ts+1323, int32(8)) == 0 && _sqlite3AtoF(tls, z+8, bp) > 0 && **(**float64)(__ccgo_up(bp)) >= float64(0) && **(**float64)(__ccgo_up(bp)) < float64(7); v4 {
|
|
v1 = int32(**(**float64)(__ccgo_up(bp)))
|
|
n = v1
|
|
}
|
|
if v4 && float64(v1) == **(**float64)(__ccgo_up(bp)) {
|
|
_computeYMD_HMS(tls, p)
|
|
(*TDateTime)(unsafe.Pointer(p)).Ftz = 0
|
|
(*TDateTime)(unsafe.Pointer(p)).FvalidJD = 0
|
|
_computeJD(tls, p)
|
|
Z = ((*TDateTime)(unsafe.Pointer(p)).FiJD + int64(129600000)) / int64(86400000) % int64(7)
|
|
if Z > int64(n) {
|
|
Z = Z - int64(7)
|
|
}
|
|
**(**Tsqlite3_int64)(__ccgo_up(p)) += (int64(n) - Z) * int64(86400000)
|
|
_clearYMD_HMS_TZ(tls, p)
|
|
rc = 0
|
|
}
|
|
case int32('s'):
|
|
/*
|
|
** start of TTTTT
|
|
**
|
|
** Move the date backwards to the beginning of the current day,
|
|
** or month or year.
|
|
**
|
|
** subsecond
|
|
** subsec
|
|
**
|
|
** Show subsecond precision in the output of datetime() and
|
|
** unixepoch() and strftime('%s').
|
|
*/
|
|
if Xsqlite3_strnicmp(tls, z, __ccgo_ts+1332, int32(9)) != 0 {
|
|
if Xsqlite3_stricmp(tls, z, __ccgo_ts+1230) == 0 || Xsqlite3_stricmp(tls, z, __ccgo_ts+1237) == 0 {
|
|
libc.SetBitFieldPtr8Uint32(p+44, libc.Uint32FromInt32(1), 2, 0x4)
|
|
rc = 0
|
|
}
|
|
break
|
|
}
|
|
if !((*TDateTime)(unsafe.Pointer(p)).FvalidJD != 0) && !((*TDateTime)(unsafe.Pointer(p)).FvalidYMD != 0) && !((*TDateTime)(unsafe.Pointer(p)).FvalidHMS != 0) {
|
|
break
|
|
}
|
|
z = z + uintptr(9)
|
|
_computeYMD(tls, p)
|
|
(*TDateTime)(unsafe.Pointer(p)).FvalidHMS = int8(1)
|
|
v1 = libc.Int32FromInt32(0)
|
|
(*TDateTime)(unsafe.Pointer(p)).Fm = v1
|
|
(*TDateTime)(unsafe.Pointer(p)).Fh = v1
|
|
(*TDateTime)(unsafe.Pointer(p)).Fs = float64(0)
|
|
libc.SetBitFieldPtr8Uint32(p+44, libc.Uint32FromInt32(0), 0, 0x1)
|
|
(*TDateTime)(unsafe.Pointer(p)).Ftz = 0
|
|
(*TDateTime)(unsafe.Pointer(p)).FvalidJD = 0
|
|
if Xsqlite3_stricmp(tls, z, __ccgo_ts+1342) == 0 {
|
|
(*TDateTime)(unsafe.Pointer(p)).FD = int32(1)
|
|
rc = 0
|
|
} else {
|
|
if Xsqlite3_stricmp(tls, z, __ccgo_ts+1348) == 0 {
|
|
(*TDateTime)(unsafe.Pointer(p)).FM = int32(1)
|
|
(*TDateTime)(unsafe.Pointer(p)).FD = int32(1)
|
|
rc = 0
|
|
} else {
|
|
if Xsqlite3_stricmp(tls, z, __ccgo_ts+1353) == 0 {
|
|
rc = 0
|
|
}
|
|
}
|
|
}
|
|
case int32('+'):
|
|
fallthrough
|
|
case int32('-'):
|
|
fallthrough
|
|
case int32('0'):
|
|
fallthrough
|
|
case int32('1'):
|
|
fallthrough
|
|
case int32('2'):
|
|
fallthrough
|
|
case int32('3'):
|
|
fallthrough
|
|
case int32('4'):
|
|
fallthrough
|
|
case int32('5'):
|
|
fallthrough
|
|
case int32('6'):
|
|
fallthrough
|
|
case int32('7'):
|
|
fallthrough
|
|
case int32('8'):
|
|
fallthrough
|
|
case int32('9'):
|
|
z2 = z
|
|
db = Xsqlite3_context_db_handle(tls, pCtx)
|
|
z0 = **(**int8)(__ccgo_up(z))
|
|
n = int32(1)
|
|
for {
|
|
if !(**(**int8)(__ccgo_up(z + uintptr(n))) != 0) {
|
|
break
|
|
}
|
|
if int32(**(**int8)(__ccgo_up(z + uintptr(n)))) == int32(':') {
|
|
break
|
|
}
|
|
if libc.Int32FromUint8(_sqlite3CtypeMap[libc.Uint8FromInt8(**(**int8)(__ccgo_up(z + uintptr(n))))])&int32(0x01) != 0 {
|
|
break
|
|
}
|
|
if int32(**(**int8)(__ccgo_up(z + uintptr(n)))) == int32('-') {
|
|
if n == int32(5) && _getDigits(tls, z+1, __ccgo_ts+1357, libc.VaList(bp+136, bp+56)) == int32(1) {
|
|
break
|
|
}
|
|
if n == int32(6) && _getDigits(tls, z+1, __ccgo_ts+1361, libc.VaList(bp+136, bp+56)) == int32(1) {
|
|
break
|
|
}
|
|
}
|
|
goto _9
|
|
_9:
|
|
;
|
|
n = n + 1
|
|
}
|
|
zCopy = _sqlite3DbStrNDup(tls, db, z, libc.Uint64FromInt32(n))
|
|
if zCopy == uintptr(0) {
|
|
break
|
|
}
|
|
rx = libc.BoolInt32(_sqlite3AtoF(tls, zCopy, bp) <= 0)
|
|
_sqlite3DbFree(tls, db, zCopy)
|
|
if rx != 0 {
|
|
break
|
|
}
|
|
if int32(**(**int8)(__ccgo_up(z + uintptr(n)))) == int32('-') {
|
|
/* A modifier of the form (+|-)YYYY-MM-DD adds or subtracts the
|
|
** specified number of years, months, and days. MM is limited to
|
|
** the range 0-11 and DD is limited to 0-30.
|
|
*/
|
|
if int32(z0) != int32('+') && int32(z0) != int32('-') {
|
|
break
|
|
} /* Must start with +/- */
|
|
if n == int32(5) {
|
|
if _getDigits(tls, z+1, __ccgo_ts+1365, libc.VaList(bp+136, bp+56, bp+60, bp+64)) != int32(3) {
|
|
break
|
|
}
|
|
} else {
|
|
if _getDigits(tls, z+1, __ccgo_ts+1377, libc.VaList(bp+136, bp+56, bp+60, bp+64)) != int32(3) {
|
|
break
|
|
}
|
|
z = z + 1
|
|
}
|
|
if **(**int32)(__ccgo_up(bp + 60)) >= int32(12) {
|
|
break
|
|
} /* M range 0..11 */
|
|
if **(**int32)(__ccgo_up(bp + 64)) >= int32(31) {
|
|
break
|
|
} /* D range 0..30 */
|
|
_computeYMD_HMS(tls, p)
|
|
(*TDateTime)(unsafe.Pointer(p)).FvalidJD = 0
|
|
if int32(z0) == int32('-') {
|
|
**(**int32)(__ccgo_up(p + 8)) -= **(**int32)(__ccgo_up(bp + 56))
|
|
**(**int32)(__ccgo_up(p + 12)) -= **(**int32)(__ccgo_up(bp + 60))
|
|
**(**int32)(__ccgo_up(bp + 64)) = -**(**int32)(__ccgo_up(bp + 64))
|
|
} else {
|
|
**(**int32)(__ccgo_up(p + 8)) += **(**int32)(__ccgo_up(bp + 56))
|
|
**(**int32)(__ccgo_up(p + 12)) += **(**int32)(__ccgo_up(bp + 60))
|
|
}
|
|
if (*TDateTime)(unsafe.Pointer(p)).FM > 0 {
|
|
v1 = ((*TDateTime)(unsafe.Pointer(p)).FM - int32(1)) / int32(12)
|
|
} else {
|
|
v1 = ((*TDateTime)(unsafe.Pointer(p)).FM - int32(12)) / int32(12)
|
|
}
|
|
x = v1
|
|
**(**int32)(__ccgo_up(p + 8)) += x
|
|
**(**int32)(__ccgo_up(p + 12)) -= x * int32(12)
|
|
_computeFloor(tls, p)
|
|
_computeJD(tls, p)
|
|
(*TDateTime)(unsafe.Pointer(p)).FvalidHMS = 0
|
|
(*TDateTime)(unsafe.Pointer(p)).FvalidYMD = 0
|
|
**(**Tsqlite3_int64)(__ccgo_up(p)) += int64(**(**int32)(__ccgo_up(bp + 64))) * int64(86400000)
|
|
if int32(**(**int8)(__ccgo_up(z + 11))) == 0 {
|
|
rc = 0
|
|
break
|
|
}
|
|
if libc.Int32FromUint8(_sqlite3CtypeMap[libc.Uint8FromInt8(**(**int8)(__ccgo_up(z + 11)))])&int32(0x01) != 0 && _getDigits(tls, z+12, __ccgo_ts+1202, libc.VaList(bp+136, bp+68, bp+72)) == int32(2) {
|
|
z2 = z + 12
|
|
n = int32(2)
|
|
} else {
|
|
break
|
|
}
|
|
}
|
|
if int32(**(**int8)(__ccgo_up(z2 + uintptr(n)))) == int32(':') {
|
|
if !(libc.Int32FromUint8(_sqlite3CtypeMap[libc.Uint8FromInt8(**(**int8)(__ccgo_up(z2)))])&libc.Int32FromInt32(0x04) != 0) {
|
|
z2 = z2 + 1
|
|
}
|
|
libc.Xmemset(tls, bp+76, 0, uint32(48))
|
|
if _parseHhMmSs(tls, z2, bp+76) != 0 {
|
|
break
|
|
}
|
|
_computeJD(tls, bp+76)
|
|
(**(**TDateTime)(__ccgo_up(bp + 76))).FiJD -= int64(43200000)
|
|
day = (**(**TDateTime)(__ccgo_up(bp + 76))).FiJD / int64(86400000)
|
|
(**(**TDateTime)(__ccgo_up(bp + 76))).FiJD -= day * int64(86400000)
|
|
if int32(z0) == int32('-') {
|
|
(**(**TDateTime)(__ccgo_up(bp + 76))).FiJD = -(**(**TDateTime)(__ccgo_up(bp + 76))).FiJD
|
|
}
|
|
_computeJD(tls, p)
|
|
_clearYMD_HMS_TZ(tls, p)
|
|
**(**Tsqlite3_int64)(__ccgo_up(p)) += (**(**TDateTime)(__ccgo_up(bp + 76))).FiJD
|
|
rc = 0
|
|
break
|
|
}
|
|
/* If control reaches this point, it means the transformation is
|
|
** one of the forms like "+NNN days". */
|
|
z = z + uintptr(n)
|
|
for libc.Int32FromUint8(_sqlite3CtypeMap[libc.Uint8FromInt8(**(**int8)(__ccgo_up(z)))])&int32(0x01) != 0 {
|
|
z = z + 1
|
|
}
|
|
n = _sqlite3Strlen30(tls, z)
|
|
if n < int32(3) || n > int32(10) {
|
|
break
|
|
}
|
|
if libc.Int32FromUint8(_sqlite3UpperToLower[libc.Uint8FromInt8(**(**int8)(__ccgo_up(z + uintptr(n-int32(1)))))]) == int32('s') {
|
|
n = n - 1
|
|
}
|
|
_computeJD(tls, p)
|
|
if **(**float64)(__ccgo_up(bp)) < libc.Float64FromInt32(0) {
|
|
v11 = -libc.Float64FromFloat64(0.5)
|
|
} else {
|
|
v11 = +libc.Float64FromFloat64(0.5)
|
|
}
|
|
rRounder = v11
|
|
(*TDateTime)(unsafe.Pointer(p)).FnFloor = 0
|
|
i = 0
|
|
for {
|
|
if !(i < libc.Int32FromUint32(libc.Uint32FromInt64(96)/libc.Uint32FromInt64(16))) {
|
|
break
|
|
}
|
|
if libc.Int32FromUint8(_aXformType[i].FnName) == n && Xsqlite3_strnicmp(tls, uintptr(unsafe.Pointer(&_aXformType))+uintptr(i)*16+1, z, n) == 0 && **(**float64)(__ccgo_up(bp)) > float64(-_aXformType[i].FrLimit) && **(**float64)(__ccgo_up(bp)) < float64(_aXformType[i].FrLimit) {
|
|
switch i {
|
|
case int32(4): /* Special processing to add months */
|
|
_computeYMD_HMS(tls, p)
|
|
**(**int32)(__ccgo_up(p + 12)) += int32(**(**float64)(__ccgo_up(bp)))
|
|
if (*TDateTime)(unsafe.Pointer(p)).FM > 0 {
|
|
v1 = ((*TDateTime)(unsafe.Pointer(p)).FM - int32(1)) / int32(12)
|
|
} else {
|
|
v1 = ((*TDateTime)(unsafe.Pointer(p)).FM - int32(12)) / int32(12)
|
|
}
|
|
x = v1
|
|
**(**int32)(__ccgo_up(p + 8)) += x
|
|
**(**int32)(__ccgo_up(p + 12)) -= x * int32(12)
|
|
_computeFloor(tls, p)
|
|
(*TDateTime)(unsafe.Pointer(p)).FvalidJD = 0
|
|
**(**float64)(__ccgo_up(bp)) = **(**float64)(__ccgo_up(bp)) - float64(int32(**(**float64)(__ccgo_up(bp))))
|
|
case int32(5): /* Special processing to add years */
|
|
y = int32(**(**float64)(__ccgo_up(bp)))
|
|
_computeYMD_HMS(tls, p)
|
|
**(**int32)(__ccgo_up(p + 8)) += y
|
|
_computeFloor(tls, p)
|
|
(*TDateTime)(unsafe.Pointer(p)).FvalidJD = 0
|
|
**(**float64)(__ccgo_up(bp)) = **(**float64)(__ccgo_up(bp)) - float64(int32(**(**float64)(__ccgo_up(bp))))
|
|
break
|
|
}
|
|
_computeJD(tls, p)
|
|
**(**Tsqlite3_int64)(__ccgo_up(p)) += int64(float64(float64(**(**float64)(__ccgo_up(bp))*libc.Float64FromFloat64(1000))*float64(_aXformType[i].FrXform)) + rRounder)
|
|
rc = 0
|
|
break
|
|
}
|
|
goto _12
|
|
_12:
|
|
;
|
|
i = i + 1
|
|
}
|
|
_clearYMD_HMS_TZ(tls, p)
|
|
default:
|
|
break
|
|
}
|
|
return rc
|
|
}
|
|
|
|
// 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 + 24852
|
|
} else {
|
|
v1 = __ccgo_ts + 24861
|
|
}
|
|
_sqlite3ErrorMsg(tls, pParse, __ccgo_ts+24867, 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 + 116 + 4*4))
|
|
mxSelect = v2
|
|
}
|
|
if v3 && v2 > 0 && cnt > mxSelect {
|
|
_sqlite3ErrorMsg(tls, pParse, __ccgo_ts+24909, 0)
|
|
}
|
|
}
|
|
}
|
|
|
|
// C documentation
|
|
//
|
|
// /*
|
|
// ** Pragma virtual table module xConnect method.
|
|
// */
|
|
func _pragmaVtabConnect(tls *libc.TLS, db uintptr, pAux uintptr, argc int32, argv uintptr, ppVtab uintptr, pzErr uintptr) (r int32) {
|
|
bp := tls.Alloc(256)
|
|
defer tls.Free(256)
|
|
var cSep int8
|
|
var i, j, rc int32
|
|
var pPragma, pTab uintptr
|
|
var _ /* acc at bp+0 */ TStrAccum
|
|
var _ /* zBuf at bp+24 */ [200]int8
|
|
_, _, _, _, _, _ = cSep, i, j, pPragma, pTab, rc
|
|
pPragma = pAux
|
|
pTab = uintptr(0)
|
|
cSep = int8('(')
|
|
_ = argc
|
|
_ = argv
|
|
_sqlite3StrAccumInit(tls, bp, uintptr(0), bp+24, int32(200), 0)
|
|
Xsqlite3_str_appendall(tls, bp, __ccgo_ts+19908)
|
|
i = 0
|
|
j = libc.Int32FromUint8((*TPragmaName)(unsafe.Pointer(pPragma)).FiPragCName)
|
|
for {
|
|
if !(i < libc.Int32FromUint8((*TPragmaName)(unsafe.Pointer(pPragma)).FnPragCName)) {
|
|
break
|
|
}
|
|
Xsqlite3_str_appendf(tls, bp, __ccgo_ts+19923, libc.VaList(bp+232, int32(cSep), _pragCName[j]))
|
|
cSep = int8(',')
|
|
goto _1
|
|
_1:
|
|
;
|
|
i = i + 1
|
|
j = j + 1
|
|
}
|
|
if i == 0 {
|
|
Xsqlite3_str_appendf(tls, bp, __ccgo_ts+19930, libc.VaList(bp+232, (*TPragmaName)(unsafe.Pointer(pPragma)).FzName))
|
|
i = i + 1
|
|
}
|
|
j = 0
|
|
if libc.Int32FromUint8((*TPragmaName)(unsafe.Pointer(pPragma)).FmPragFlg)&int32(PragFlg_Result1) != 0 {
|
|
Xsqlite3_str_appendall(tls, bp, __ccgo_ts+19936)
|
|
j = j + 1
|
|
}
|
|
if libc.Int32FromUint8((*TPragmaName)(unsafe.Pointer(pPragma)).FmPragFlg)&(libc.Int32FromInt32(PragFlg_SchemaOpt)|libc.Int32FromInt32(PragFlg_SchemaReq)) != 0 {
|
|
Xsqlite3_str_appendall(tls, bp, __ccgo_ts+19948)
|
|
j = j + 1
|
|
}
|
|
Xsqlite3_str_append(tls, bp, __ccgo_ts+5259, int32(1))
|
|
_sqlite3StrAccumFinish(tls, bp)
|
|
rc = Xsqlite3_declare_vtab(tls, db, bp+24)
|
|
if rc == SQLITE_OK {
|
|
pTab = Xsqlite3_malloc(tls, int32(24))
|
|
if pTab == uintptr(0) {
|
|
rc = int32(SQLITE_NOMEM)
|
|
} else {
|
|
libc.Xmemset(tls, pTab, 0, uint32(24))
|
|
(*TPragmaVtab)(unsafe.Pointer(pTab)).FpName = pPragma
|
|
(*TPragmaVtab)(unsafe.Pointer(pTab)).Fdb = db
|
|
(*TPragmaVtab)(unsafe.Pointer(pTab)).FiHidden = libc.Uint8FromInt32(i)
|
|
(*TPragmaVtab)(unsafe.Pointer(pTab)).FnHidden = libc.Uint8FromInt32(j)
|
|
}
|
|
} else {
|
|
**(**uintptr)(__ccgo_up(pzErr)) = Xsqlite3_mprintf(tls, __ccgo_ts+3942, libc.VaList(bp+232, Xsqlite3_errmsg(tls, db)))
|
|
}
|
|
**(**uintptr)(__ccgo_up(ppVtab)) = pTab
|
|
return rc
|
|
}
|
|
|
|
// 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)*4)))
|
|
if zText != 0 {
|
|
**(**uintptr)(__ccgo_up(pCsr + 16 + uintptr(j)*4)) = Xsqlite3_mprintf(tls, __ccgo_ts+3942, libc.VaList(bp+32, zText))
|
|
if **(**uintptr)(__ccgo_up(pCsr + 16 + uintptr(j)*4)) == 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 + 116 + 1*4)))
|
|
Xsqlite3_str_appendall(tls, bp, __ccgo_ts+19963)
|
|
if **(**uintptr)(__ccgo_up(pCsr + 16 + 1*4)) != 0 {
|
|
Xsqlite3_str_appendf(tls, bp, __ccgo_ts+19971, libc.VaList(bp+32, **(**uintptr)(__ccgo_up(pCsr + 16 + 1*4))))
|
|
}
|
|
Xsqlite3_str_appendall(tls, bp, (*TPragmaName)(unsafe.Pointer((*TPragmaVtab)(unsafe.Pointer(pTab)).FpName)).FzName)
|
|
if **(**uintptr)(__ccgo_up(pCsr + 16)) != 0 {
|
|
Xsqlite3_str_appendf(tls, bp, __ccgo_ts+19975, libc.VaList(bp+32, **(**uintptr)(__ccgo_up(pCsr + 16))))
|
|
}
|
|
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+4, uintptr(0))
|
|
Xsqlite3_free(tls, zSql)
|
|
if rc != SQLITE_OK {
|
|
(*TPragmaVtab)(unsafe.Pointer(pTab)).Fbase.FzErrMsg = Xsqlite3_mprintf(tls, __ccgo_ts+3942, libc.VaList(bp+32, Xsqlite3_errmsg(tls, (*TPragmaVtab)(unsafe.Pointer(pTab)).Fdb)))
|
|
return rc
|
|
}
|
|
return _pragmaVtabNext(tls, pVtabCursor)
|
|
}
|
|
|
|
// C documentation
|
|
//
|
|
// /*
|
|
// ** If the error code currently stored in the RBU handle is SQLITE_CONSTRAINT,
|
|
// ** then edit any error message string so as to remove all occurrences of
|
|
// ** the pattern "rbu_imp_[0-9]*".
|
|
// */
|
|
func _rbuEditErrmsg(tls *libc.TLS, p uintptr) {
|
|
var i uint32
|
|
var nDel int32
|
|
var nErrmsg Tsize_t
|
|
_, _, _ = i, nDel, nErrmsg
|
|
if (*Tsqlite3rbu)(unsafe.Pointer(p)).Frc == int32(SQLITE_CONSTRAINT) && (*Tsqlite3rbu)(unsafe.Pointer(p)).FzErrmsg != 0 {
|
|
nErrmsg = libc.Xstrlen(tls, (*Tsqlite3rbu)(unsafe.Pointer(p)).FzErrmsg)
|
|
i = uint32(0)
|
|
for {
|
|
if !(i < nErrmsg-uint32(8)) {
|
|
break
|
|
}
|
|
if libc.Xmemcmp(tls, (*Tsqlite3rbu)(unsafe.Pointer(p)).FzErrmsg+uintptr(i), __ccgo_ts+32697, uint32(8)) == 0 {
|
|
nDel = int32(8)
|
|
for int32(**(**int8)(__ccgo_up((*Tsqlite3rbu)(unsafe.Pointer(p)).FzErrmsg + uintptr(i+libc.Uint32FromInt32(nDel))))) >= int32('0') && int32(**(**int8)(__ccgo_up((*Tsqlite3rbu)(unsafe.Pointer(p)).FzErrmsg + uintptr(i+libc.Uint32FromInt32(nDel))))) <= int32('9') {
|
|
nDel = nDel + 1
|
|
}
|
|
libc.Xmemmove(tls, (*Tsqlite3rbu)(unsafe.Pointer(p)).FzErrmsg+uintptr(i), (*Tsqlite3rbu)(unsafe.Pointer(p)).FzErrmsg+uintptr(i+libc.Uint32FromInt32(nDel)), nErrmsg+uint32(1)-i-libc.Uint32FromInt32(nDel))
|
|
nErrmsg = nErrmsg - libc.Uint32FromInt32(nDel)
|
|
}
|
|
goto _1
|
|
_1:
|
|
;
|
|
i = i + 1
|
|
}
|
|
}
|
|
}
|
|
|
|
// 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+4 */ int32
|
|
_, _ = pRet, rc2
|
|
pRet = uintptr(0)
|
|
**(**uintptr)(__ccgo_up(bp)) = uintptr(0)
|
|
pRet = _rbuMalloc(tls, p, int64(56))
|
|
if pRet == uintptr(0) {
|
|
return uintptr(0)
|
|
}
|
|
**(**int32)(__ccgo_up(bp + 4)) = _prepareFreeAndCollectError(tls, (*Tsqlite3rbu)(unsafe.Pointer(p)).FdbRbu, bp, p+36, Xsqlite3_mprintf(tls, __ccgo_ts+33388, libc.VaList(bp+16, p+24)))
|
|
for **(**int32)(__ccgo_up(bp + 4)) == 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+4)
|
|
case int32(RBU_STATE_IDX):
|
|
(*TRbuState)(unsafe.Pointer(pRet)).FzIdx = _rbuStrndup(tls, Xsqlite3_column_text(tls, **(**uintptr)(__ccgo_up(bp)), int32(1)), bp+4)
|
|
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+4)
|
|
default:
|
|
**(**int32)(__ccgo_up(bp + 4)) = int32(SQLITE_CORRUPT)
|
|
break
|
|
}
|
|
}
|
|
rc2 = Xsqlite3_finalize(tls, **(**uintptr)(__ccgo_up(bp)))
|
|
if **(**int32)(__ccgo_up(bp + 4)) == SQLITE_OK {
|
|
**(**int32)(__ccgo_up(bp + 4)) = rc2
|
|
}
|
|
(*Tsqlite3rbu)(unsafe.Pointer(p)).Frc = **(**int32)(__ccgo_up(bp + 4))
|
|
return pRet
|
|
}
|
|
|
|
// 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+6818)
|
|
zMove = zBase
|
|
if (*Tsqlite3rbu)(unsafe.Pointer(p)).FzTarget == uintptr(0) {
|
|
zMove = Xsqlite3_db_filename(tls, (*Tsqlite3rbu)(unsafe.Pointer(p)).FdbRbu, __ccgo_ts+6818)
|
|
}
|
|
zOal = Xsqlite3_mprintf(tls, __ccgo_ts+33750, libc.VaList(bp+8, zMove))
|
|
zWal = Xsqlite3_mprintf(tls, __ccgo_ts+33757, 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+52)
|
|
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)
|
|
}
|
|
|
|
func _rbuObjIterGetIndexWhere(tls *libc.TLS, p uintptr, pIter uintptr) (r uintptr) {
|
|
bp := tls.Alloc(16)
|
|
defer tls.Free(16)
|
|
var aIdxCol, zRet, zSql, v1 uintptr
|
|
var c int8
|
|
var i, iIdxCol, nIdxAlloc, nParen, nSpan, nSpan1, rc2, v3 int32
|
|
var _ /* pStmt at bp+0 */ uintptr
|
|
var _ /* rc at bp+4 */ int32
|
|
_, _, _, _, _, _, _, _, _, _, _, _, _ = aIdxCol, c, i, iIdxCol, nIdxAlloc, nParen, nSpan, nSpan1, rc2, zRet, zSql, v1, v3
|
|
**(**uintptr)(__ccgo_up(bp)) = uintptr(0)
|
|
**(**int32)(__ccgo_up(bp + 4)) = (*Tsqlite3rbu)(unsafe.Pointer(p)).Frc
|
|
zRet = uintptr(0)
|
|
if **(**int32)(__ccgo_up(bp + 4)) == SQLITE_OK {
|
|
**(**int32)(__ccgo_up(bp + 4)) = _prepareAndCollectError(tls, (*Tsqlite3rbu)(unsafe.Pointer(p)).FdbMain, bp, p+36, __ccgo_ts+32185)
|
|
}
|
|
if **(**int32)(__ccgo_up(bp + 4)) == SQLITE_OK {
|
|
**(**int32)(__ccgo_up(bp + 4)) = Xsqlite3_bind_text(tls, **(**uintptr)(__ccgo_up(bp)), int32(1), (*TRbuObjIter)(unsafe.Pointer(pIter)).FzIdx, -int32(1), libc.UintptrFromInt32(0))
|
|
if **(**int32)(__ccgo_up(bp + 4)) == SQLITE_OK && int32(SQLITE_ROW) == Xsqlite3_step(tls, **(**uintptr)(__ccgo_up(bp))) {
|
|
zSql = Xsqlite3_column_text(tls, **(**uintptr)(__ccgo_up(bp)), 0)
|
|
if zSql != 0 {
|
|
v1 = _rbuStrndup(tls, zSql, bp+4)
|
|
zSql = v1
|
|
(*TRbuObjIter)(unsafe.Pointer(pIter)).FzIdxSql = v1
|
|
}
|
|
if zSql != 0 {
|
|
nParen = 0
|
|
iIdxCol = 0
|
|
nIdxAlloc = 0
|
|
i = 0
|
|
for {
|
|
if !(**(**int8)(__ccgo_up(zSql + uintptr(i))) != 0) {
|
|
break
|
|
}
|
|
c = **(**int8)(__ccgo_up(zSql + uintptr(i)))
|
|
/* If necessary, grow the pIter->aIdxCol[] array */
|
|
if iIdxCol == nIdxAlloc {
|
|
aIdxCol = Xsqlite3_realloc64(tls, (*TRbuObjIter)(unsafe.Pointer(pIter)).FaIdxCol, uint64(libc.Uint32FromInt32(nIdxAlloc)*uint32(8)+libc.Uint32FromInt32(16)*libc.Uint32FromInt64(8)))
|
|
if aIdxCol == uintptr(0) {
|
|
**(**int32)(__ccgo_up(bp + 4)) = int32(SQLITE_NOMEM)
|
|
break
|
|
}
|
|
(*TRbuObjIter)(unsafe.Pointer(pIter)).FaIdxCol = aIdxCol
|
|
nIdxAlloc = nIdxAlloc + int32(16)
|
|
}
|
|
if int32(c) == int32('(') {
|
|
if nParen == 0 {
|
|
(**(**TRbuSpan)(__ccgo_up((*TRbuObjIter)(unsafe.Pointer(pIter)).FaIdxCol))).FzSpan = zSql + uintptr(i+int32(1))
|
|
}
|
|
nParen = nParen + 1
|
|
} else {
|
|
if int32(c) == int32(')') {
|
|
nParen = nParen - 1
|
|
if nParen == 0 {
|
|
nSpan = t__predefined_ptrdiff_t(zSql+uintptr(i)) - int32((**(**TRbuSpan)(__ccgo_up((*TRbuObjIter)(unsafe.Pointer(pIter)).FaIdxCol + uintptr(iIdxCol)*8))).FzSpan)
|
|
v3 = iIdxCol
|
|
iIdxCol = iIdxCol + 1
|
|
(**(**TRbuSpan)(__ccgo_up((*TRbuObjIter)(unsafe.Pointer(pIter)).FaIdxCol + uintptr(v3)*8))).FnSpan = nSpan
|
|
i = i + 1
|
|
break
|
|
}
|
|
} else {
|
|
if int32(c) == int32(',') && nParen == int32(1) {
|
|
nSpan1 = t__predefined_ptrdiff_t(zSql+uintptr(i)) - int32((**(**TRbuSpan)(__ccgo_up((*TRbuObjIter)(unsafe.Pointer(pIter)).FaIdxCol + uintptr(iIdxCol)*8))).FzSpan)
|
|
v3 = iIdxCol
|
|
iIdxCol = iIdxCol + 1
|
|
(**(**TRbuSpan)(__ccgo_up((*TRbuObjIter)(unsafe.Pointer(pIter)).FaIdxCol + uintptr(v3)*8))).FnSpan = nSpan1
|
|
(**(**TRbuSpan)(__ccgo_up((*TRbuObjIter)(unsafe.Pointer(pIter)).FaIdxCol + uintptr(iIdxCol)*8))).FzSpan = zSql + uintptr(i+int32(1))
|
|
} else {
|
|
if int32(c) == int32('"') || int32(c) == int32('\'') || int32(c) == int32('`') {
|
|
i = i + 1
|
|
for {
|
|
if !(int32(1) != 0) {
|
|
break
|
|
}
|
|
if int32(**(**int8)(__ccgo_up(zSql + uintptr(i)))) == int32(c) {
|
|
if int32(**(**int8)(__ccgo_up(zSql + uintptr(i+int32(1))))) != int32(c) {
|
|
break
|
|
}
|
|
i = i + 1
|
|
}
|
|
goto _5
|
|
_5:
|
|
;
|
|
i = i + 1
|
|
}
|
|
} else {
|
|
if int32(c) == int32('[') {
|
|
i = i + 1
|
|
for {
|
|
if !(int32(1) != 0) {
|
|
break
|
|
}
|
|
if int32(**(**int8)(__ccgo_up(zSql + uintptr(i)))) == int32(']') {
|
|
break
|
|
}
|
|
goto _6
|
|
_6:
|
|
;
|
|
i = i + 1
|
|
}
|
|
} else {
|
|
if int32(c) == int32('-') && int32(**(**int8)(__ccgo_up(zSql + uintptr(i+int32(1))))) == int32('-') {
|
|
i = i + int32(2)
|
|
for {
|
|
if !(**(**int8)(__ccgo_up(zSql + uintptr(i))) != 0 && int32(**(**int8)(__ccgo_up(zSql + uintptr(i)))) != int32('\n')) {
|
|
break
|
|
}
|
|
goto _7
|
|
_7:
|
|
;
|
|
i = i + 1
|
|
}
|
|
if int32(**(**int8)(__ccgo_up(zSql + uintptr(i)))) == int32('\000') {
|
|
break
|
|
}
|
|
} else {
|
|
if int32(c) == int32('/') && int32(**(**int8)(__ccgo_up(zSql + uintptr(i+int32(1))))) == int32('*') {
|
|
i = i + int32(2)
|
|
for {
|
|
if !(**(**int8)(__ccgo_up(zSql + uintptr(i))) != 0 && (int32(**(**int8)(__ccgo_up(zSql + uintptr(i)))) != int32('*') || int32(**(**int8)(__ccgo_up(zSql + uintptr(i+int32(1))))) != int32('/'))) {
|
|
break
|
|
}
|
|
goto _8
|
|
_8:
|
|
;
|
|
i = i + 1
|
|
}
|
|
if int32(**(**int8)(__ccgo_up(zSql + uintptr(i)))) == int32('\000') {
|
|
break
|
|
}
|
|
i = i + 1
|
|
}
|
|
}
|
|
}
|
|
}
|
|
}
|
|
}
|
|
}
|
|
goto _2
|
|
_2:
|
|
;
|
|
i = i + 1
|
|
}
|
|
if **(**int8)(__ccgo_up(zSql + uintptr(i))) != 0 {
|
|
zRet = _rbuStrndup(tls, zSql+uintptr(i), bp+4)
|
|
}
|
|
(*TRbuObjIter)(unsafe.Pointer(pIter)).FnIdxCol = iIdxCol
|
|
}
|
|
}
|
|
rc2 = Xsqlite3_finalize(tls, **(**uintptr)(__ccgo_up(bp)))
|
|
if **(**int32)(__ccgo_up(bp + 4)) == SQLITE_OK {
|
|
**(**int32)(__ccgo_up(bp + 4)) = rc2
|
|
}
|
|
}
|
|
(*Tsqlite3rbu)(unsafe.Pointer(p)).Frc = **(**int32)(__ccgo_up(bp + 4))
|
|
return zRet
|
|
}
|
|
|
|
// C documentation
|
|
//
|
|
// /*
|
|
// ** Return a nul-terminated string containing the comma separated list of
|
|
// ** assignments that should be included following the "SET" keyword of
|
|
// ** an UPDATE statement used to update the table object that the iterator
|
|
// ** passed as the second argument currently points to if the rbu_control
|
|
// ** column of the data_xxx table entry is set to zMask.
|
|
// **
|
|
// ** The memory for the returned string is obtained from sqlite3_malloc().
|
|
// ** It is the responsibility of the caller to eventually free it using
|
|
// ** sqlite3_free().
|
|
// **
|
|
// ** If an OOM error is encountered when allocating space for the new
|
|
// ** string, an error code is left in the rbu handle passed as the first
|
|
// ** argument and NULL is returned. Or, if an error has already occurred
|
|
// ** when this function is called, NULL is returned immediately, without
|
|
// ** attempting the allocation or modifying the stored error code.
|
|
// */
|
|
func _rbuObjIterGetSetlist(tls *libc.TLS, p uintptr, pIter uintptr, zMask uintptr) (r uintptr) {
|
|
bp := tls.Alloc(48)
|
|
defer tls.Free(48)
|
|
var c int8
|
|
var i int32
|
|
var zList, zSep uintptr
|
|
_, _, _, _ = c, i, zList, zSep
|
|
zList = uintptr(0)
|
|
if (*Tsqlite3rbu)(unsafe.Pointer(p)).Frc == SQLITE_OK {
|
|
if libc.Int32FromUint32(libc.Xstrlen(tls, zMask)) != (*TRbuObjIter)(unsafe.Pointer(pIter)).FnTblCol {
|
|
_rbuBadControlError(tls, p)
|
|
} else {
|
|
zSep = __ccgo_ts + 1702
|
|
i = 0
|
|
for {
|
|
if !(i < (*TRbuObjIter)(unsafe.Pointer(pIter)).FnTblCol) {
|
|
break
|
|
}
|
|
c = **(**int8)(__ccgo_up(zMask + uintptr(**(**int32)(__ccgo_up((*TRbuObjIter)(unsafe.Pointer(pIter)).FaiSrcOrder + uintptr(i)*4)))))
|
|
if int32(c) == int32('x') {
|
|
zList = _rbuMPrintf(tls, p, __ccgo_ts+31731, libc.VaList(bp+8, zList, zSep, **(**uintptr)(__ccgo_up((*TRbuObjIter)(unsafe.Pointer(pIter)).FazTblCol + uintptr(i)*4)), i+int32(1)))
|
|
zSep = __ccgo_ts + 16216
|
|
} else {
|
|
if int32(c) == int32('d') {
|
|
zList = _rbuMPrintf(tls, p, __ccgo_ts+31770, libc.VaList(bp+8, zList, zSep, **(**uintptr)(__ccgo_up((*TRbuObjIter)(unsafe.Pointer(pIter)).FazTblCol + uintptr(i)*4)), **(**uintptr)(__ccgo_up((*TRbuObjIter)(unsafe.Pointer(pIter)).FazTblCol + uintptr(i)*4)), i+int32(1)))
|
|
zSep = __ccgo_ts + 16216
|
|
} else {
|
|
if int32(c) == int32('f') {
|
|
zList = _rbuMPrintf(tls, p, __ccgo_ts+31800, libc.VaList(bp+8, zList, zSep, **(**uintptr)(__ccgo_up((*TRbuObjIter)(unsafe.Pointer(pIter)).FazTblCol + uintptr(i)*4)), **(**uintptr)(__ccgo_up((*TRbuObjIter)(unsafe.Pointer(pIter)).FazTblCol + uintptr(i)*4)), i+int32(1)))
|
|
zSep = __ccgo_ts + 16216
|
|
}
|
|
}
|
|
}
|
|
goto _1
|
|
_1:
|
|
;
|
|
i = i + 1
|
|
}
|
|
}
|
|
}
|
|
return zList
|
|
}
|
|
|
|
// C documentation
|
|
//
|
|
// /*
|
|
// ** Open the database handle and attach the RBU database as "rbu". If an
|
|
// ** error occurs, leave an error code and message in the RBU handle.
|
|
// **
|
|
// ** If argument dbMain is not NULL, then it is a database handle already
|
|
// ** open on the target database. Use this handle instead of opening a new
|
|
// ** one.
|
|
// */
|
|
func _rbuOpenDatabase(tls *libc.TLS, p uintptr, dbMain uintptr, pbRetry uintptr) {
|
|
bp := tls.Alloc(32)
|
|
defer tls.Free(32)
|
|
var bOpen, rc int32
|
|
var pState, zExtra, zFile, zTarget, v1, v2 uintptr
|
|
_, _, _, _, _, _, _, _ = bOpen, pState, rc, zExtra, zFile, zTarget, v1, v2
|
|
/* Open the RBU database */
|
|
(*Tsqlite3rbu)(unsafe.Pointer(p)).FdbRbu = _rbuOpenDbhandle(tls, p, (*Tsqlite3rbu)(unsafe.Pointer(p)).FzRbu, int32(1))
|
|
(*Tsqlite3rbu)(unsafe.Pointer(p)).FdbMain = dbMain
|
|
if (*Tsqlite3rbu)(unsafe.Pointer(p)).Frc == SQLITE_OK && (*Tsqlite3rbu)(unsafe.Pointer(p)).FzTarget == uintptr(0) {
|
|
Xsqlite3_file_control(tls, (*Tsqlite3rbu)(unsafe.Pointer(p)).FdbRbu, __ccgo_ts+6818, int32(SQLITE_FCNTL_RBUCNT), p)
|
|
if (*Tsqlite3rbu)(unsafe.Pointer(p)).FzState == uintptr(0) {
|
|
zFile = Xsqlite3_db_filename(tls, (*Tsqlite3rbu)(unsafe.Pointer(p)).FdbRbu, __ccgo_ts+6818)
|
|
(*Tsqlite3rbu)(unsafe.Pointer(p)).FzState = _rbuMPrintf(tls, p, __ccgo_ts+33418, libc.VaList(bp+8, zFile, zFile))
|
|
}
|
|
}
|
|
/* If using separate RBU and state databases, attach the state database to
|
|
** the RBU db handle now. */
|
|
if (*Tsqlite3rbu)(unsafe.Pointer(p)).FzState != 0 {
|
|
_rbuMPrintfExec(tls, p, (*Tsqlite3rbu)(unsafe.Pointer(p)).FdbRbu, __ccgo_ts+33446, libc.VaList(bp+8, (*Tsqlite3rbu)(unsafe.Pointer(p)).FzState))
|
|
libc.Xmemcpy(tls, p+24, __ccgo_ts+3565, uint32(4))
|
|
} else {
|
|
libc.Xmemcpy(tls, p+24, __ccgo_ts+6818, uint32(4))
|
|
}
|
|
/* If it has not already been created, create the rbu_state table */
|
|
_rbuMPrintfExec(tls, p, (*Tsqlite3rbu)(unsafe.Pointer(p)).FdbRbu, __ccgo_ts+33464, libc.VaList(bp+8, p+24))
|
|
if (*Tsqlite3rbu)(unsafe.Pointer(p)).Frc == SQLITE_OK && (*Tsqlite3rbu)(unsafe.Pointer(p)).FzTarget == uintptr(0) {
|
|
bOpen = 0
|
|
(*Tsqlite3rbu)(unsafe.Pointer(p)).FnRbu = 0
|
|
(*Tsqlite3rbu)(unsafe.Pointer(p)).FpRbuFd = uintptr(0)
|
|
rc = Xsqlite3_file_control(tls, (*Tsqlite3rbu)(unsafe.Pointer(p)).FdbRbu, __ccgo_ts+6818, int32(SQLITE_FCNTL_RBUCNT), p)
|
|
if rc != int32(SQLITE_NOTFOUND) {
|
|
(*Tsqlite3rbu)(unsafe.Pointer(p)).Frc = rc
|
|
}
|
|
if (*Tsqlite3rbu)(unsafe.Pointer(p)).FeStage >= int32(RBU_STAGE_MOVE) {
|
|
bOpen = int32(1)
|
|
} else {
|
|
pState = _rbuLoadState(tls, p)
|
|
if pState != 0 {
|
|
bOpen = libc.BoolInt32((*TRbuState)(unsafe.Pointer(pState)).FeStage >= int32(RBU_STAGE_MOVE))
|
|
_rbuFreeState(tls, pState)
|
|
}
|
|
}
|
|
if bOpen != 0 {
|
|
(*Tsqlite3rbu)(unsafe.Pointer(p)).FdbMain = _rbuOpenDbhandle(tls, p, (*Tsqlite3rbu)(unsafe.Pointer(p)).FzRbu, libc.BoolInt32((*Tsqlite3rbu)(unsafe.Pointer(p)).FnRbu <= int32(1)))
|
|
}
|
|
}
|
|
(*Tsqlite3rbu)(unsafe.Pointer(p)).FeStage = 0
|
|
if (*Tsqlite3rbu)(unsafe.Pointer(p)).Frc == SQLITE_OK && (*Tsqlite3rbu)(unsafe.Pointer(p)).FdbMain == uintptr(0) {
|
|
if !((*Tsqlite3rbu)(unsafe.Pointer(p)).FzTarget == libc.UintptrFromInt32(0)) {
|
|
(*Tsqlite3rbu)(unsafe.Pointer(p)).FdbMain = _rbuOpenDbhandle(tls, p, (*Tsqlite3rbu)(unsafe.Pointer(p)).FzTarget, int32(1))
|
|
} else {
|
|
if (*Trbu_file)(unsafe.Pointer((*Tsqlite3rbu)(unsafe.Pointer(p)).FpRbuFd)).FpWalFd != 0 {
|
|
if pbRetry != 0 {
|
|
(*Trbu_file)(unsafe.Pointer((*Tsqlite3rbu)(unsafe.Pointer(p)).FpRbuFd)).FbNolock = uint8(0)
|
|
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)
|
|
**(**int32)(__ccgo_up(pbRetry)) = int32(1)
|
|
return
|
|
}
|
|
(*Tsqlite3rbu)(unsafe.Pointer(p)).Frc = int32(SQLITE_ERROR)
|
|
(*Tsqlite3rbu)(unsafe.Pointer(p)).FzErrmsg = Xsqlite3_mprintf(tls, __ccgo_ts+33530, 0)
|
|
} else {
|
|
zExtra = uintptr(0)
|
|
if libc.Xstrlen(tls, (*Tsqlite3rbu)(unsafe.Pointer(p)).FzRbu) >= uint32(5) && 0 == libc.Xmemcmp(tls, __ccgo_ts+26116, (*Tsqlite3rbu)(unsafe.Pointer(p)).FzRbu, uint32(5)) {
|
|
zExtra = (*Tsqlite3rbu)(unsafe.Pointer(p)).FzRbu + 5
|
|
for **(**int8)(__ccgo_up(zExtra)) != 0 {
|
|
v1 = zExtra
|
|
zExtra = zExtra + 1
|
|
if int32(**(**int8)(__ccgo_up(v1))) == int32('?') {
|
|
break
|
|
}
|
|
}
|
|
if int32(**(**int8)(__ccgo_up(zExtra))) == int32('\000') {
|
|
zExtra = uintptr(0)
|
|
}
|
|
}
|
|
if zExtra == uintptr(0) {
|
|
v1 = __ccgo_ts + 1702
|
|
} else {
|
|
v1 = __ccgo_ts + 33562
|
|
}
|
|
if zExtra == uintptr(0) {
|
|
v2 = __ccgo_ts + 1702
|
|
} else {
|
|
v2 = zExtra
|
|
}
|
|
zTarget = Xsqlite3_mprintf(tls, __ccgo_ts+33564, libc.VaList(bp+8, Xsqlite3_db_filename(tls, (*Tsqlite3rbu)(unsafe.Pointer(p)).FdbRbu, __ccgo_ts+6818), v1, v2))
|
|
if zTarget == uintptr(0) {
|
|
(*Tsqlite3rbu)(unsafe.Pointer(p)).Frc = int32(SQLITE_NOMEM)
|
|
return
|
|
}
|
|
(*Tsqlite3rbu)(unsafe.Pointer(p)).FdbMain = _rbuOpenDbhandle(tls, p, zTarget, libc.BoolInt32((*Tsqlite3rbu)(unsafe.Pointer(p)).FnRbu <= int32(1)))
|
|
Xsqlite3_free(tls, zTarget)
|
|
}
|
|
}
|
|
}
|
|
if (*Tsqlite3rbu)(unsafe.Pointer(p)).Frc == SQLITE_OK {
|
|
(*Tsqlite3rbu)(unsafe.Pointer(p)).Frc = Xsqlite3_create_function(tls, (*Tsqlite3rbu)(unsafe.Pointer(p)).FdbMain, __ccgo_ts+33596, -int32(1), int32(SQLITE_UTF8), p, __ccgo_fp(_rbuTmpInsertFunc), uintptr(0), uintptr(0))
|
|
}
|
|
if (*Tsqlite3rbu)(unsafe.Pointer(p)).Frc == SQLITE_OK {
|
|
(*Tsqlite3rbu)(unsafe.Pointer(p)).Frc = Xsqlite3_create_function(tls, (*Tsqlite3rbu)(unsafe.Pointer(p)).FdbMain, __ccgo_ts+33611, int32(2), int32(SQLITE_UTF8), uintptr(0), __ccgo_fp(_rbuFossilDeltaFunc), uintptr(0), uintptr(0))
|
|
}
|
|
if (*Tsqlite3rbu)(unsafe.Pointer(p)).Frc == SQLITE_OK {
|
|
(*Tsqlite3rbu)(unsafe.Pointer(p)).Frc = Xsqlite3_create_function(tls, (*Tsqlite3rbu)(unsafe.Pointer(p)).FdbRbu, __ccgo_ts+33628, -int32(1), int32(SQLITE_UTF8), p, __ccgo_fp(_rbuTargetNameFunc), uintptr(0), uintptr(0))
|
|
}
|
|
if (*Tsqlite3rbu)(unsafe.Pointer(p)).Frc == SQLITE_OK {
|
|
(*Tsqlite3rbu)(unsafe.Pointer(p)).Frc = Xsqlite3_file_control(tls, (*Tsqlite3rbu)(unsafe.Pointer(p)).FdbMain, __ccgo_ts+6818, int32(SQLITE_FCNTL_RBU), p)
|
|
}
|
|
_rbuMPrintfExec(tls, p, (*Tsqlite3rbu)(unsafe.Pointer(p)).FdbMain, __ccgo_ts+33644, 0)
|
|
/* Mark the database file just opened as an RBU target database. If
|
|
** this call returns SQLITE_NOTFOUND, then the RBU vfs is not in use.
|
|
** This is an error. */
|
|
if (*Tsqlite3rbu)(unsafe.Pointer(p)).Frc == SQLITE_OK {
|
|
(*Tsqlite3rbu)(unsafe.Pointer(p)).Frc = Xsqlite3_file_control(tls, (*Tsqlite3rbu)(unsafe.Pointer(p)).FdbMain, __ccgo_ts+6818, int32(SQLITE_FCNTL_RBU), p)
|
|
}
|
|
if (*Tsqlite3rbu)(unsafe.Pointer(p)).Frc == int32(SQLITE_NOTFOUND) {
|
|
(*Tsqlite3rbu)(unsafe.Pointer(p)).Frc = int32(SQLITE_ERROR)
|
|
(*Tsqlite3rbu)(unsafe.Pointer(p)).FzErrmsg = Xsqlite3_mprintf(tls, __ccgo_ts+33672, 0)
|
|
}
|
|
}
|
|
|
|
// 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 + 52
|
|
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+34303, 0)
|
|
}
|
|
if rc == SQLITE_OK {
|
|
(*Tsqlite3rbu)(unsafe.Pointer(p)).FnStep = (*TRbuState)(unsafe.Pointer(pState)).FnRow
|
|
rc = _rbuObjIterPrepareAll(tls, p, p+52, (*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 + 52
|
|
/* 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 + 180)) -= 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+25673, 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+36)
|
|
}
|
|
}
|
|
|
|
// C documentation
|
|
//
|
|
// /*
|
|
// ** The implementation of the rbu_target_name() SQL function. This function
|
|
// ** accepts one or two arguments. The first argument is the name of a table -
|
|
// ** the name of a table in the RBU database. The second, if it is present, is 1
|
|
// ** for a view or 0 for a table.
|
|
// **
|
|
// ** For a non-vacuum RBU handle, if the table name matches the pattern:
|
|
// **
|
|
// ** data[0-9]_<name>
|
|
// **
|
|
// ** where <name> is any sequence of 1 or more characters, <name> is returned.
|
|
// ** Otherwise, if the only argument does not match the above pattern, an SQL
|
|
// ** NULL is returned.
|
|
// **
|
|
// ** "data_t1" -> "t1"
|
|
// ** "data0123_t2" -> "t2"
|
|
// ** "dataAB_t3" -> NULL
|
|
// **
|
|
// ** For an rbu vacuum handle, a copy of the first argument is returned if
|
|
// ** the second argument is either missing or 0 (not a view).
|
|
// */
|
|
func _rbuTargetNameFunc(tls *libc.TLS, pCtx uintptr, argc int32, argv uintptr) {
|
|
var i int32
|
|
var p, zIn uintptr
|
|
_, _, _ = i, p, zIn
|
|
p = Xsqlite3_user_data(tls, pCtx)
|
|
zIn = Xsqlite3_value_text(tls, **(**uintptr)(__ccgo_up(argv)))
|
|
if zIn != 0 {
|
|
if (*Tsqlite3rbu)(unsafe.Pointer(p)).FzTarget == uintptr(0) {
|
|
if argc == int32(1) || 0 == Xsqlite3_value_int(tls, **(**uintptr)(__ccgo_up(argv + 1*4))) {
|
|
Xsqlite3_result_text(tls, pCtx, zIn, -int32(1), libc.UintptrFromInt32(0))
|
|
}
|
|
} else {
|
|
if libc.Xstrlen(tls, zIn) > uint32(4) && libc.Xmemcmp(tls, __ccgo_ts+27406, zIn, uint32(4)) == 0 {
|
|
i = int32(4)
|
|
for {
|
|
if !(int32(**(**int8)(__ccgo_up(zIn + uintptr(i)))) >= int32('0') && int32(**(**int8)(__ccgo_up(zIn + uintptr(i)))) <= int32('9')) {
|
|
break
|
|
}
|
|
goto _1
|
|
_1:
|
|
;
|
|
i = i + 1
|
|
}
|
|
if int32(**(**int8)(__ccgo_up(zIn + uintptr(i)))) == int32('_') && **(**int8)(__ccgo_up(zIn + uintptr(i+int32(1)))) != 0 {
|
|
Xsqlite3_result_text(tls, pCtx, zIn+uintptr(i+int32(1)), -int32(1), libc.UintptrFromInt32(0))
|
|
}
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|
|
// C documentation
|
|
//
|
|
// /*
|
|
// ** This function is called as part of restating an RBU vacuum when the
|
|
// ** current operation is writing content to an index. If possible, it
|
|
// ** queries the target index b-tree for the largest key already written to
|
|
// ** it, then composes and returns an expression that can be used in a WHERE
|
|
// ** clause to select the remaining required rows from the source table.
|
|
// ** It is only possible to return such an expression if:
|
|
// **
|
|
// ** * The index contains no DESC columns, and
|
|
// ** * The last key written to the index before the operation was
|
|
// ** suspended does not contain any NULL values.
|
|
// **
|
|
// ** The expression is of the form:
|
|
// **
|
|
// ** (index-field1, index-field2, ...) > (?, ?, ...)
|
|
// **
|
|
// ** except that the "?" placeholders are replaced with literal values.
|
|
// **
|
|
// ** If the expression cannot be created, NULL is returned. In this case,
|
|
// ** the caller has to use an OFFSET clause to extract only the required
|
|
// ** rows from the sourct table, just as it does for an RBU update operation.
|
|
// */
|
|
func _rbuVacuumIndexStart(tls *libc.TLS, p uintptr, pIter uintptr) (r uintptr) {
|
|
bp := tls.Alloc(64)
|
|
defer tls.Free(64)
|
|
var bFailed, i, iCid, iCol int32
|
|
var zCol, zCollate, zLhs, zOrder, zQuoted, zRet, zSelect, zSep, zVector uintptr
|
|
var _ /* pSel at bp+4 */ uintptr
|
|
var _ /* pXInfo at bp+0 */ uintptr
|
|
_, _, _, _, _, _, _, _, _, _, _, _, _ = bFailed, i, iCid, iCol, zCol, zCollate, zLhs, zOrder, zQuoted, zRet, zSelect, zSep, zVector
|
|
zOrder = uintptr(0)
|
|
zLhs = uintptr(0)
|
|
zSelect = uintptr(0)
|
|
zVector = uintptr(0)
|
|
zRet = uintptr(0)
|
|
bFailed = 0
|
|
zSep = __ccgo_ts + 1702
|
|
iCol = 0
|
|
**(**uintptr)(__ccgo_up(bp)) = uintptr(0)
|
|
(*Tsqlite3rbu)(unsafe.Pointer(p)).Frc = _prepareFreeAndCollectError(tls, (*Tsqlite3rbu)(unsafe.Pointer(p)).FdbMain, bp, p+36, Xsqlite3_mprintf(tls, __ccgo_ts+31017, libc.VaList(bp+16, (*TRbuObjIter)(unsafe.Pointer(pIter)).FzIdx)))
|
|
for (*Tsqlite3rbu)(unsafe.Pointer(p)).Frc == SQLITE_OK && int32(SQLITE_ROW) == Xsqlite3_step(tls, **(**uintptr)(__ccgo_up(bp))) {
|
|
iCid = Xsqlite3_column_int(tls, **(**uintptr)(__ccgo_up(bp)), int32(1))
|
|
zCollate = Xsqlite3_column_text(tls, **(**uintptr)(__ccgo_up(bp)), int32(4))
|
|
if Xsqlite3_column_int(tls, **(**uintptr)(__ccgo_up(bp)), int32(3)) != 0 {
|
|
bFailed = int32(1)
|
|
break
|
|
}
|
|
if iCid < 0 {
|
|
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)*4))
|
|
} else {
|
|
zCol = __ccgo_ts + 31340
|
|
}
|
|
} else {
|
|
zCol = **(**uintptr)(__ccgo_up((*TRbuObjIter)(unsafe.Pointer(pIter)).FazTblCol + uintptr(iCid)*4))
|
|
}
|
|
zLhs = _rbuMPrintf(tls, p, __ccgo_ts+31348, libc.VaList(bp+16, zLhs, zSep, zCol, zCollate))
|
|
zOrder = _rbuMPrintf(tls, p, __ccgo_ts+31369, libc.VaList(bp+16, zOrder, zSep, iCol, zCol, zCollate))
|
|
zSelect = _rbuMPrintf(tls, p, __ccgo_ts+31405, libc.VaList(bp+16, zSelect, zSep, iCol, zCol))
|
|
zSep = __ccgo_ts + 16216
|
|
iCol = iCol + 1
|
|
}
|
|
_rbuFinalize(tls, p, **(**uintptr)(__ccgo_up(bp)))
|
|
if bFailed != 0 {
|
|
goto index_start_out
|
|
}
|
|
if (*Tsqlite3rbu)(unsafe.Pointer(p)).Frc == SQLITE_OK {
|
|
**(**uintptr)(__ccgo_up(bp + 4)) = uintptr(0)
|
|
(*Tsqlite3rbu)(unsafe.Pointer(p)).Frc = _prepareFreeAndCollectError(tls, (*Tsqlite3rbu)(unsafe.Pointer(p)).FdbMain, bp+4, p+36, Xsqlite3_mprintf(tls, __ccgo_ts+31432, libc.VaList(bp+16, zSelect, (*TRbuObjIter)(unsafe.Pointer(pIter)).FzTbl, zOrder)))
|
|
if (*Tsqlite3rbu)(unsafe.Pointer(p)).Frc == SQLITE_OK && int32(SQLITE_ROW) == Xsqlite3_step(tls, **(**uintptr)(__ccgo_up(bp + 4))) {
|
|
zSep = __ccgo_ts + 1702
|
|
iCol = 0
|
|
for {
|
|
if !(iCol < (*TRbuObjIter)(unsafe.Pointer(pIter)).FnCol) {
|
|
break
|
|
}
|
|
zQuoted = Xsqlite3_column_text(tls, **(**uintptr)(__ccgo_up(bp + 4)), iCol)
|
|
if zQuoted == uintptr(0) {
|
|
(*Tsqlite3rbu)(unsafe.Pointer(p)).Frc = int32(SQLITE_NOMEM)
|
|
} else {
|
|
if int32(**(**int8)(__ccgo_up(zQuoted))) == int32('N') {
|
|
bFailed = int32(1)
|
|
break
|
|
}
|
|
}
|
|
zVector = _rbuMPrintf(tls, p, __ccgo_ts+31480, libc.VaList(bp+16, zVector, zSep, zQuoted))
|
|
zSep = __ccgo_ts + 16216
|
|
goto _2
|
|
_2:
|
|
;
|
|
iCol = iCol + 1
|
|
}
|
|
if !(bFailed != 0) {
|
|
zRet = _rbuMPrintf(tls, p, __ccgo_ts+31487, libc.VaList(bp+16, zLhs, zVector))
|
|
}
|
|
}
|
|
_rbuFinalize(tls, p, **(**uintptr)(__ccgo_up(bp + 4)))
|
|
}
|
|
goto index_start_out
|
|
index_start_out:
|
|
;
|
|
Xsqlite3_free(tls, zOrder)
|
|
Xsqlite3_free(tls, zSelect)
|
|
Xsqlite3_free(tls, zVector)
|
|
Xsqlite3_free(tls, zLhs)
|
|
return zRet
|
|
}
|
|
|
|
// C documentation
|
|
//
|
|
// /*
|
|
// ** Open an rbu file handle.
|
|
// */
|
|
func _rbuVfsOpen(tls *libc.TLS, pVfs uintptr, zName uintptr, pFile uintptr, flags int32, pOutFlags uintptr) (r int32) {
|
|
var nOpen Tsize_t
|
|
var oflags, rc int32
|
|
var pDb, pFd, pMeth, pRbuVfs, pRealVfs, zOpen uintptr
|
|
_, _, _, _, _, _, _, _, _ = nOpen, oflags, pDb, pFd, pMeth, pRbuVfs, pRealVfs, rc, zOpen
|
|
pRbuVfs = pVfs
|
|
pRealVfs = (*Trbu_vfs)(unsafe.Pointer(pRbuVfs)).FpRealVfs
|
|
pFd = pFile
|
|
rc = SQLITE_OK
|
|
zOpen = zName
|
|
oflags = flags
|
|
libc.Xmemset(tls, pFd, 0, uint32(64))
|
|
(*Trbu_file)(unsafe.Pointer(pFd)).FpReal = pFd + 1*64
|
|
(*Trbu_file)(unsafe.Pointer(pFd)).FpRbuVfs = pRbuVfs
|
|
(*Trbu_file)(unsafe.Pointer(pFd)).FopenFlags = flags
|
|
if zName != 0 {
|
|
if flags&int32(SQLITE_OPEN_MAIN_DB) != 0 {
|
|
/* A main database has just been opened. The following block sets
|
|
** (pFd->zWal) to point to a buffer owned by SQLite that contains
|
|
** the name of the *-wal file this db connection will use. SQLite
|
|
** happens to pass a pointer to this buffer when using xAccess()
|
|
** or xOpen() to operate on the *-wal file. */
|
|
(*Trbu_file)(unsafe.Pointer(pFd)).FzWal = Xsqlite3_filename_wal(tls, zName)
|
|
} else {
|
|
if flags&int32(SQLITE_OPEN_WAL) != 0 {
|
|
pDb = _rbuFindMaindb(tls, pRbuVfs, zName, 0)
|
|
if pDb != 0 {
|
|
if (*Trbu_file)(unsafe.Pointer(pDb)).FpRbu != 0 && (*Tsqlite3rbu)(unsafe.Pointer((*Trbu_file)(unsafe.Pointer(pDb)).FpRbu)).FeStage == int32(RBU_STAGE_OAL) {
|
|
if (*Tsqlite3rbu)(unsafe.Pointer((*Trbu_file)(unsafe.Pointer(pDb)).FpRbu)).FzTarget == uintptr(0) {
|
|
zOpen = Xsqlite3_db_filename(tls, (*Tsqlite3rbu)(unsafe.Pointer((*Trbu_file)(unsafe.Pointer(pDb)).FpRbu)).FdbRbu, __ccgo_ts+6818)
|
|
zOpen = Xsqlite3_filename_wal(tls, zOpen)
|
|
}
|
|
nOpen = libc.Xstrlen(tls, zOpen)
|
|
**(**int8)(__ccgo_up(zOpen + uintptr(nOpen-uint32(3)))) = int8('o')
|
|
(*Trbu_file)(unsafe.Pointer(pFd)).FpRbu = (*Trbu_file)(unsafe.Pointer(pDb)).FpRbu
|
|
}
|
|
(*Trbu_file)(unsafe.Pointer(pDb)).FpWalFd = pFd
|
|
}
|
|
}
|
|
}
|
|
} else {
|
|
(*Trbu_file)(unsafe.Pointer(pFd)).FpRbu = (*Trbu_vfs)(unsafe.Pointer(pRbuVfs)).FpRbu
|
|
}
|
|
if oflags&int32(SQLITE_OPEN_MAIN_DB) != 0 && Xsqlite3_uri_boolean(tls, zName, __ccgo_ts+34743, 0) != 0 {
|
|
oflags = libc.Int32FromInt32(SQLITE_OPEN_TEMP_DB) | libc.Int32FromInt32(SQLITE_OPEN_READWRITE) | libc.Int32FromInt32(SQLITE_OPEN_CREATE) | libc.Int32FromInt32(SQLITE_OPEN_EXCLUSIVE) | libc.Int32FromInt32(SQLITE_OPEN_DELETEONCLOSE)
|
|
zOpen = uintptr(0)
|
|
}
|
|
if rc == SQLITE_OK {
|
|
rc = (*(*func(*libc.TLS, uintptr, Tsqlite3_filename, uintptr, int32, uintptr) int32)(unsafe.Pointer(&struct{ uintptr }{(*Tsqlite3_vfs)(unsafe.Pointer(pRealVfs)).FxOpen})))(tls, pRealVfs, zOpen, (*Trbu_file)(unsafe.Pointer(pFd)).FpReal, oflags, pOutFlags)
|
|
}
|
|
if (*Tsqlite3_file)(unsafe.Pointer((*Trbu_file)(unsafe.Pointer(pFd)).FpReal)).FpMethods != 0 {
|
|
pMeth = (*Tsqlite3_file)(unsafe.Pointer((*Trbu_file)(unsafe.Pointer(pFd)).FpReal)).FpMethods
|
|
/* The xOpen() operation has succeeded. Set the sqlite3_file.pMethods
|
|
** pointer and, if the file is a main database file, link it into the
|
|
** mutex protected linked list of all such files. */
|
|
if (*Tsqlite3_io_methods)(unsafe.Pointer(pMeth)).FiVersion < int32(2) || (*Tsqlite3_io_methods)(unsafe.Pointer(pMeth)).FxShmLock == uintptr(0) {
|
|
(*Tsqlite3_file)(unsafe.Pointer(pFile)).FpMethods = uintptr(unsafe.Pointer(&_rbuvfs_io_methods1))
|
|
} else {
|
|
(*Tsqlite3_file)(unsafe.Pointer(pFile)).FpMethods = uintptr(unsafe.Pointer(&_rbuvfs_io_methods))
|
|
}
|
|
if flags&int32(SQLITE_OPEN_MAIN_DB) != 0 {
|
|
_rbuMainlistAdd(tls, pFd)
|
|
}
|
|
} else {
|
|
Xsqlite3_free(tls, (*Trbu_file)(unsafe.Pointer(pFd)).FzDel)
|
|
}
|
|
return rc
|
|
}
|
|
|
|
// C documentation
|
|
//
|
|
// /*
|
|
// ** This function edits SQL statement zSql, replacing each token identified
|
|
// ** by the linked list pRename with the text of zNew. If argument bQuote is
|
|
// ** true, then zNew is always quoted first. If no error occurs, the result
|
|
// ** is loaded into context object pCtx as the result.
|
|
// **
|
|
// ** Or, if an error occurs (i.e. an OOM condition), an error is left in
|
|
// ** pCtx and an SQLite error code returned.
|
|
// */
|
|
func _renameEditSql(tls *libc.TLS, pCtx uintptr, pRename uintptr, zSql uintptr, zNew uintptr, bQuote int32) (r int32) {
|
|
bp := tls.Alloc(32)
|
|
defer tls.Free(32)
|
|
var db, pBest, zBuf1, zBuf2, zOut, zQuot, zReplace, v1 uintptr
|
|
var iOff, rc int32
|
|
var nNew, nOut, nQuot, nReplace, nSql Ti64
|
|
_, _, _, _, _, _, _, _, _, _, _, _, _, _, _ = db, iOff, nNew, nOut, nQuot, nReplace, nSql, pBest, rc, zBuf1, zBuf2, zOut, zQuot, zReplace, v1
|
|
nNew = int64(_sqlite3Strlen30(tls, zNew))
|
|
nSql = int64(_sqlite3Strlen30(tls, zSql))
|
|
db = Xsqlite3_context_db_handle(tls, pCtx)
|
|
rc = SQLITE_OK
|
|
zQuot = uintptr(0)
|
|
nQuot = 0
|
|
zBuf1 = uintptr(0)
|
|
zBuf2 = uintptr(0)
|
|
if zNew != 0 {
|
|
/* Set zQuot to point to a buffer containing a quoted copy of the
|
|
** identifier zNew. If the corresponding identifier in the original
|
|
** ALTER TABLE statement was quoted (bQuote==1), then set zNew to
|
|
** point to zQuot so that all substitutions are made using the
|
|
** quoted version of the new column name. */
|
|
zQuot = _sqlite3MPrintf(tls, db, __ccgo_ts+11576, libc.VaList(bp+8, zNew))
|
|
if zQuot == uintptr(0) {
|
|
return int32(SQLITE_NOMEM)
|
|
} else {
|
|
nQuot = int64(_sqlite3Strlen30(tls, zQuot) - int32(1))
|
|
}
|
|
zOut = _sqlite3DbMallocZero(tls, db, libc.Uint64FromInt64(nSql)+libc.Uint64FromInt32((*TRenameCtx)(unsafe.Pointer(pRename)).FnList)*libc.Uint64FromInt64(nQuot)+uint64(1))
|
|
} else {
|
|
zOut = _sqlite3DbMallocZero(tls, db, (uint64(2)*libc.Uint64FromInt64(nSql)+uint64(1))*uint64(3))
|
|
if zOut != 0 {
|
|
zBuf1 = zOut + uintptr(nSql*int64(2)+int64(1))
|
|
zBuf2 = zOut + uintptr(nSql*int64(4)+int64(2))
|
|
}
|
|
}
|
|
/* At this point pRename->pList contains a list of RenameToken objects
|
|
** corresponding to all tokens in the input SQL that must be replaced
|
|
** with the new column name, or with single-quoted versions of themselves.
|
|
** All that remains is to construct and return the edited SQL string. */
|
|
if zOut != 0 {
|
|
nOut = nSql
|
|
libc.Xmemcpy(tls, zOut, zSql, libc.Uint32FromInt64(nSql))
|
|
for (*TRenameCtx)(unsafe.Pointer(pRename)).FpList != 0 {
|
|
pBest = _renameColumnTokenNext(tls, pRename)
|
|
if zNew != 0 {
|
|
if bQuote == 0 && _sqlite3IsIdChar(tls, **(**Tu8)(__ccgo_up((*TRenameToken)(unsafe.Pointer(pBest)).Ft.Fz))) != 0 {
|
|
nReplace = nNew
|
|
zReplace = zNew
|
|
} else {
|
|
nReplace = nQuot
|
|
zReplace = zQuot
|
|
if int32(**(**int8)(__ccgo_up((*TRenameToken)(unsafe.Pointer(pBest)).Ft.Fz + uintptr((*TRenameToken)(unsafe.Pointer(pBest)).Ft.Fn)))) == int32('"') {
|
|
nReplace = nReplace + 1
|
|
}
|
|
}
|
|
} else {
|
|
/* Dequote the double-quoted token. Then requote it again, this time
|
|
** using single quotes. If the character immediately following the
|
|
** original token within the input SQL was a single quote ('), then
|
|
** add another space after the new, single-quoted version of the
|
|
** token. This is so that (SELECT "string"'alias') maps to
|
|
** (SELECT 'string' 'alias'), and not (SELECT 'string''alias'). */
|
|
libc.Xmemcpy(tls, zBuf1, (*TRenameToken)(unsafe.Pointer(pBest)).Ft.Fz, (*TRenameToken)(unsafe.Pointer(pBest)).Ft.Fn)
|
|
**(**int8)(__ccgo_up(zBuf1 + uintptr((*TRenameToken)(unsafe.Pointer(pBest)).Ft.Fn))) = 0
|
|
_sqlite3Dequote(tls, zBuf1)
|
|
if int32(**(**int8)(__ccgo_up((*TRenameToken)(unsafe.Pointer(pBest)).Ft.Fz + uintptr((*TRenameToken)(unsafe.Pointer(pBest)).Ft.Fn)))) == int32('\'') {
|
|
v1 = __ccgo_ts + 11543
|
|
} else {
|
|
v1 = __ccgo_ts + 1702
|
|
}
|
|
Xsqlite3_snprintf(tls, int32(nSql*libc.Int64FromInt32(2)), zBuf2, __ccgo_ts+11582, libc.VaList(bp+8, zBuf1, v1))
|
|
zReplace = zBuf2
|
|
nReplace = int64(_sqlite3Strlen30(tls, zReplace))
|
|
}
|
|
iOff = int32((*TRenameToken)(unsafe.Pointer(pBest)).Ft.Fz) - int32(zSql)
|
|
if libc.Int64FromUint32((*TRenameToken)(unsafe.Pointer(pBest)).Ft.Fn) != nReplace {
|
|
libc.Xmemmove(tls, zOut+uintptr(int64(iOff)+nReplace), zOut+uintptr(libc.Uint32FromInt32(iOff)+(*TRenameToken)(unsafe.Pointer(pBest)).Ft.Fn), libc.Uint32FromInt64(nOut-libc.Int64FromUint32(libc.Uint32FromInt32(iOff)+(*TRenameToken)(unsafe.Pointer(pBest)).Ft.Fn)))
|
|
nOut = nOut + (nReplace - libc.Int64FromUint32((*TRenameToken)(unsafe.Pointer(pBest)).Ft.Fn))
|
|
**(**int8)(__ccgo_up(zOut + uintptr(nOut))) = int8('\000')
|
|
}
|
|
libc.Xmemcpy(tls, zOut+uintptr(iOff), zReplace, libc.Uint32FromInt64(nReplace))
|
|
_sqlite3DbFree(tls, db, pBest)
|
|
}
|
|
Xsqlite3_result_text(tls, pCtx, zOut, -int32(1), uintptr(-libc.Int32FromInt32(1)))
|
|
_sqlite3DbFree(tls, db, zOut)
|
|
} else {
|
|
rc = int32(SQLITE_NOMEM)
|
|
}
|
|
Xsqlite3_free(tls, zQuot)
|
|
return rc
|
|
}
|
|
|
|
// 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+11568, 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 + 28)) |= 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
|
|
//
|
|
// /*
|
|
// ** 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 + 116 + 2*4)) {
|
|
_sqlite3ErrorMsg(tls, pParse, __ccgo_ts+7627, 0)
|
|
return int32(1)
|
|
}
|
|
i = 0
|
|
for {
|
|
if !(i < (*TExprList)(unsafe.Pointer(pOrderBy)).FnExpr) {
|
|
break
|
|
}
|
|
libc.SetBitFieldPtr16Uint32(pOrderBy+8+uintptr(i)*20+8+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 + 8 + 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+7661, 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 + 16))).FiOrderByCol = libc.Uint16FromInt32(**(**int32)(__ccgo_up(bp)))
|
|
}
|
|
libc.SetBitFieldPtr16Uint32(pItem+8+4, libc.Uint32FromInt32(1), 2, 0x4)
|
|
} else {
|
|
moreToDo = int32(1)
|
|
}
|
|
goto _2
|
|
_2:
|
|
;
|
|
i = i + 1
|
|
pItem += 20
|
|
}
|
|
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)*20 + 8 + 4))&0x4>>2)) == 0 {
|
|
_sqlite3ErrorMsg(tls, pParse, __ccgo_ts+7667, libc.VaList(bp+16, i+int32(1)))
|
|
return int32(1)
|
|
}
|
|
goto _3
|
|
_3:
|
|
;
|
|
i = i + 1
|
|
}
|
|
return 0
|
|
}
|
|
|
|
// C documentation
|
|
//
|
|
// /*
|
|
// ** This routine is callback for sqlite3WalkExpr().
|
|
// **
|
|
// ** Resolve symbolic names into TK_COLUMN operators for the current
|
|
// ** node in the expression tree. Return 0 to continue the search down
|
|
// ** the tree or 2 to abort the tree walk.
|
|
// **
|
|
// ** This routine also does error checking and name resolution for
|
|
// ** function names. The operator for aggregate functions is changed
|
|
// ** to TK_AGG_FUNCTION.
|
|
// */
|
|
func _resolveExprStep(tls *libc.TLS, pWalker uintptr, pExpr uintptr) (r int32) {
|
|
bp := tls.Alloc(32)
|
|
defer tls.Free(32)
|
|
var anRef [8]int32
|
|
var auth, i, is_agg, n, nLeft, nRef, nRight, no_such_func, rc, savedAllowFlags, wrong_num_args, v5 int32
|
|
var enc Tu8
|
|
var p, pDef, pItem, pLeft, pList, pNC, pNC2, pParse, pRight, pRight1, pSel, pSrcList, pWin, zDb, zId, zTable, zType, v4 uintptr
|
|
_, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _ = anRef, auth, enc, i, is_agg, n, nLeft, nRef, nRight, no_such_func, p, pDef, pItem, pLeft, pList, pNC, pNC2, pParse, pRight, pRight1, pSel, pSrcList, pWin, rc, savedAllowFlags, wrong_num_args, zDb, zId, zTable, zType, v4, v5
|
|
pNC = *(*uintptr)(unsafe.Pointer(pWalker + 24))
|
|
pParse = (*TNameContext)(unsafe.Pointer(pNC)).FpParse
|
|
switch libc.Int32FromUint8((*TExpr)(unsafe.Pointer(pExpr)).Fop) {
|
|
/* The special operator TK_ROW means use the rowid for the first
|
|
** column in the FROM clause. This is used by the LIMIT and ORDER BY
|
|
** clause processing on UPDATE and DELETE statements, and by
|
|
** UPDATE ... FROM statement processing.
|
|
*/
|
|
case int32(TK_ROW):
|
|
pSrcList = (*TNameContext)(unsafe.Pointer(pNC)).FpSrcList
|
|
pItem = pSrcList + 8
|
|
(*TExpr)(unsafe.Pointer(pExpr)).Fop = uint8(TK_COLUMN)
|
|
(*TExpr)(unsafe.Pointer(pExpr)).Fy.FpTab = (*TSrcItem)(unsafe.Pointer(pItem)).FpSTab
|
|
(*TExpr)(unsafe.Pointer(pExpr)).FiTable = (*TSrcItem)(unsafe.Pointer(pItem)).FiCursor
|
|
(*TExpr)(unsafe.Pointer(pExpr)).FiColumn = (*TExpr)(unsafe.Pointer(pExpr)).FiColumn - 1
|
|
(*TExpr)(unsafe.Pointer(pExpr)).FaffExpr = int8(SQLITE_AFF_INTEGER)
|
|
break
|
|
/* An optimization: Attempt to convert
|
|
**
|
|
** "expr IS NOT NULL" --> "TRUE"
|
|
** "expr IS NULL" --> "FALSE"
|
|
**
|
|
** if we can prove that "expr" is never NULL. Call this the
|
|
** "NOT NULL strength reduction optimization".
|
|
**
|
|
** If this optimization occurs, also restore the NameContext ref-counts
|
|
** to the state they where in before the "column" LHS expression was
|
|
** resolved. This prevents "column" from being counted as having been
|
|
** referenced, which might prevent a SELECT from being erroneously
|
|
** marked as correlated.
|
|
**
|
|
** 2024-03-28: Beware of aggregates. A bare column of aggregated table
|
|
** can still evaluate to NULL even though it is marked as NOT NULL.
|
|
** Example:
|
|
**
|
|
** CREATE TABLE t1(a INT NOT NULL);
|
|
** SELECT a, a IS NULL, a IS NOT NULL, count(*) FROM t1;
|
|
**
|
|
** The "a IS NULL" and "a IS NOT NULL" expressions cannot be optimized
|
|
** here because at the time this case is hit, we do not yet know whether
|
|
** or not t1 is being aggregated. We have to assume the worst and omit
|
|
** the optimization. The only time it is safe to apply this optimization
|
|
** is within the WHERE clause.
|
|
*/
|
|
fallthrough
|
|
case int32(TK_NOTNULL):
|
|
fallthrough
|
|
case int32(TK_ISNULL):
|
|
i = 0
|
|
p = pNC
|
|
for {
|
|
if !(p != 0 && i < libc.Int32FromUint32(libc.Uint32FromInt64(32)/libc.Uint32FromInt64(4))) {
|
|
break
|
|
}
|
|
anRef[i] = (*TNameContext)(unsafe.Pointer(p)).FnRef
|
|
goto _1
|
|
_1:
|
|
;
|
|
p = (*TNameContext)(unsafe.Pointer(p)).FpNext
|
|
i = i + 1
|
|
}
|
|
_sqlite3WalkExpr(tls, pWalker, (*TExpr)(unsafe.Pointer(pExpr)).FpLeft)
|
|
if libc.Int32FromUint8((*TParse)(unsafe.Pointer(pParse)).FeParseMode) >= int32(PARSE_MODE_RENAME) {
|
|
return int32(WRC_Prune)
|
|
}
|
|
if _sqlite3ExprCanBeNull(tls, (*TExpr)(unsafe.Pointer(pExpr)).FpLeft) != 0 {
|
|
/* The expression can be NULL. So the optimization does not apply */
|
|
return int32(WRC_Prune)
|
|
}
|
|
i = 0
|
|
p = pNC
|
|
for {
|
|
if !(p != 0) {
|
|
break
|
|
}
|
|
if (*TNameContext)(unsafe.Pointer(p)).FncFlags&int32(NC_Where) == 0 {
|
|
return int32(WRC_Prune) /* Not in a WHERE clause. Unsafe to optimize. */
|
|
}
|
|
goto _2
|
|
_2:
|
|
;
|
|
p = (*TNameContext)(unsafe.Pointer(p)).FpNext
|
|
i = i + 1
|
|
}
|
|
*(*int32)(unsafe.Pointer(pExpr + 8)) = libc.BoolInt32(libc.Int32FromUint8((*TExpr)(unsafe.Pointer(pExpr)).Fop) == int32(TK_NOTNULL))
|
|
**(**Tu32)(__ccgo_up(pExpr + 4)) |= uint32(EP_IntValue)
|
|
(*TExpr)(unsafe.Pointer(pExpr)).Fop = uint8(TK_INTEGER)
|
|
i = 0
|
|
p = pNC
|
|
for {
|
|
if !(p != 0 && i < libc.Int32FromUint32(libc.Uint32FromInt64(32)/libc.Uint32FromInt64(4))) {
|
|
break
|
|
}
|
|
(*TNameContext)(unsafe.Pointer(p)).FnRef = anRef[i]
|
|
goto _3
|
|
_3:
|
|
;
|
|
p = (*TNameContext)(unsafe.Pointer(p)).FpNext
|
|
i = i + 1
|
|
}
|
|
_sqlite3ExprDelete(tls, (*TParse)(unsafe.Pointer(pParse)).Fdb, (*TExpr)(unsafe.Pointer(pExpr)).FpLeft)
|
|
(*TExpr)(unsafe.Pointer(pExpr)).FpLeft = uintptr(0)
|
|
return int32(WRC_Prune)
|
|
/* A column name: ID
|
|
** Or table name and column name: ID.ID
|
|
** Or a database, table and column: ID.ID.ID
|
|
**
|
|
** The TK_ID and TK_OUT cases are combined so that there will only
|
|
** be one call to lookupName(). Then the compiler will in-line
|
|
** lookupName() for a size reduction and performance increase.
|
|
*/
|
|
fallthrough
|
|
case int32(TK_ID):
|
|
fallthrough
|
|
case int32(TK_DOT):
|
|
if libc.Int32FromUint8((*TExpr)(unsafe.Pointer(pExpr)).Fop) == int32(TK_ID) {
|
|
zDb = uintptr(0)
|
|
zTable = uintptr(0)
|
|
pRight = pExpr
|
|
} else {
|
|
pLeft = (*TExpr)(unsafe.Pointer(pExpr)).FpLeft
|
|
if (*TNameContext)(unsafe.Pointer(pNC)).FncFlags&(libc.Int32FromInt32(NC_IdxExpr)|libc.Int32FromInt32(NC_GenCol)) != 0 {
|
|
_notValidImpl(tls, pParse, pNC, __ccgo_ts+7202, uintptr(0), pExpr)
|
|
}
|
|
pRight = (*TExpr)(unsafe.Pointer(pExpr)).FpRight
|
|
if libc.Int32FromUint8((*TExpr)(unsafe.Pointer(pRight)).Fop) == int32(TK_ID) {
|
|
zDb = uintptr(0)
|
|
} else {
|
|
zDb = *(*uintptr)(unsafe.Pointer(pLeft + 8))
|
|
pLeft = (*TExpr)(unsafe.Pointer(pRight)).FpLeft
|
|
pRight = (*TExpr)(unsafe.Pointer(pRight)).FpRight
|
|
}
|
|
zTable = *(*uintptr)(unsafe.Pointer(pLeft + 8))
|
|
if libc.Int32FromUint8((*TParse)(unsafe.Pointer(pParse)).FeParseMode) >= int32(PARSE_MODE_RENAME) {
|
|
_sqlite3RenameTokenRemap(tls, pParse, pExpr, pRight)
|
|
_sqlite3RenameTokenRemap(tls, pParse, pExpr+44, pLeft)
|
|
}
|
|
}
|
|
return _lookupName(tls, pParse, zDb, zTable, pRight, pNC, pExpr)
|
|
/* Resolve function names
|
|
*/
|
|
fallthrough
|
|
case int32(TK_FUNCTION): /* Number of arguments */
|
|
no_such_func = 0 /* True if no such function exists */
|
|
wrong_num_args = 0 /* True if wrong number of arguments */
|
|
is_agg = 0 /* Information about the function */
|
|
enc = (*Tsqlite3)(unsafe.Pointer((*TParse)(unsafe.Pointer(pParse)).Fdb)).Fenc /* The database encoding */
|
|
savedAllowFlags = (*TNameContext)(unsafe.Pointer(pNC)).FncFlags & (libc.Int32FromInt32(NC_AllowAgg) | libc.Int32FromInt32(NC_AllowWin))
|
|
if (*TExpr)(unsafe.Pointer(pExpr)).Fflags&libc.Uint32FromInt32(libc.Int32FromInt32(EP_WinFunc)) != uint32(0) && libc.Int32FromUint8((*TWindow)(unsafe.Pointer(*(*uintptr)(unsafe.Pointer(&(*TExpr)(unsafe.Pointer(pExpr)).Fy)))).FeFrmType) != int32(TK_FILTER) {
|
|
v4 = *(*uintptr)(unsafe.Pointer(&(*TExpr)(unsafe.Pointer(pExpr)).Fy))
|
|
} else {
|
|
v4 = uintptr(0)
|
|
}
|
|
pWin = v4
|
|
pList = *(*uintptr)(unsafe.Pointer(pExpr + 20))
|
|
if pList != 0 {
|
|
v5 = (*TExprList)(unsafe.Pointer(pList)).FnExpr
|
|
} else {
|
|
v5 = 0
|
|
}
|
|
n = v5
|
|
zId = *(*uintptr)(unsafe.Pointer(pExpr + 8))
|
|
pDef = _sqlite3FindFunction(tls, (*TParse)(unsafe.Pointer(pParse)).Fdb, zId, n, enc, uint8(0))
|
|
if pDef == uintptr(0) {
|
|
pDef = _sqlite3FindFunction(tls, (*TParse)(unsafe.Pointer(pParse)).Fdb, zId, -int32(2), enc, uint8(0))
|
|
if pDef == uintptr(0) {
|
|
no_such_func = int32(1)
|
|
} else {
|
|
wrong_num_args = int32(1)
|
|
}
|
|
} else {
|
|
is_agg = libc.BoolInt32((*TFuncDef)(unsafe.Pointer(pDef)).FxFinalize != uintptr(0))
|
|
if (*TFuncDef)(unsafe.Pointer(pDef)).FfuncFlags&uint32(SQLITE_FUNC_UNLIKELY) != 0 {
|
|
**(**Tu32)(__ccgo_up(pExpr + 4)) |= libc.Uint32FromInt32(libc.Int32FromInt32(EP_Unlikely))
|
|
if n == int32(2) {
|
|
(*TExpr)(unsafe.Pointer(pExpr)).FiTable = _exprProbability(tls, (*(*TExprList_item)(unsafe.Pointer(pList + 8 + 1*20))).FpExpr)
|
|
if (*TExpr)(unsafe.Pointer(pExpr)).FiTable < 0 {
|
|
_sqlite3ErrorMsg(tls, pParse, __ccgo_ts+7219, libc.VaList(bp+8, pExpr))
|
|
(*TNameContext)(unsafe.Pointer(pNC)).FnNcErr = (*TNameContext)(unsafe.Pointer(pNC)).FnNcErr + 1
|
|
}
|
|
} else {
|
|
/* EVIDENCE-OF: R-61304-29449 The unlikely(X) function is
|
|
** equivalent to likelihood(X, 0.0625).
|
|
** EVIDENCE-OF: R-01283-11636 The unlikely(X) function is
|
|
** short-hand for likelihood(X,0.0625).
|
|
** EVIDENCE-OF: R-36850-34127 The likely(X) function is short-hand
|
|
** for likelihood(X,0.9375).
|
|
** EVIDENCE-OF: R-53436-40973 The likely(X) function is equivalent
|
|
** to likelihood(X,0.9375). */
|
|
/* TUNING: unlikely() probability is 0.0625. likely() is 0.9375 */
|
|
if int32(**(**int8)(__ccgo_up((*TFuncDef)(unsafe.Pointer(pDef)).FzName))) == int32('u') {
|
|
v5 = int32(8388608)
|
|
} else {
|
|
v5 = int32(125829120)
|
|
}
|
|
(*TExpr)(unsafe.Pointer(pExpr)).FiTable = v5
|
|
}
|
|
}
|
|
auth = _sqlite3AuthCheck(tls, pParse, int32(SQLITE_FUNCTION), uintptr(0), (*TFuncDef)(unsafe.Pointer(pDef)).FzName, uintptr(0))
|
|
if auth != SQLITE_OK {
|
|
if auth == int32(SQLITE_DENY) {
|
|
_sqlite3ErrorMsg(tls, pParse, __ccgo_ts+7283, libc.VaList(bp+8, pExpr))
|
|
(*TNameContext)(unsafe.Pointer(pNC)).FnNcErr = (*TNameContext)(unsafe.Pointer(pNC)).FnNcErr + 1
|
|
}
|
|
(*TExpr)(unsafe.Pointer(pExpr)).Fop = uint8(TK_NULL)
|
|
return int32(WRC_Prune)
|
|
}
|
|
/* If the function may call sqlite3_value_subtype(), then set the
|
|
** EP_SubtArg flag on all of its argument expressions. This prevents
|
|
** where.c from replacing the expression with a value read from an
|
|
** index on the same expression, which will not have the correct
|
|
** subtype. Also set the flag if the function expression itself is
|
|
** an EP_SubtArg expression. In this case subtypes are required as
|
|
** the function may return a value with a subtype back to its
|
|
** caller using sqlite3_result_value(). */
|
|
if (*TFuncDef)(unsafe.Pointer(pDef)).FfuncFlags&uint32(SQLITE_SUBTYPE) != 0 || (*TExpr)(unsafe.Pointer(pExpr)).Fflags&libc.Uint32FromUint32(EP_SubtArg) != uint32(0) {
|
|
_resolveSetExprSubtypeArg(tls, pList)
|
|
}
|
|
if (*TFuncDef)(unsafe.Pointer(pDef)).FfuncFlags&libc.Uint32FromInt32(libc.Int32FromInt32(SQLITE_FUNC_CONSTANT)|libc.Int32FromInt32(SQLITE_FUNC_SLOCHNG)) != 0 {
|
|
/* For the purposes of the EP_ConstFunc flag, date and time
|
|
** functions and other functions that change slowly are considered
|
|
** constant because they are constant for the duration of one query.
|
|
** This allows them to be factored out of inner loops. */
|
|
**(**Tu32)(__ccgo_up(pExpr + 4)) |= libc.Uint32FromInt32(libc.Int32FromInt32(EP_ConstFunc))
|
|
}
|
|
if (*TFuncDef)(unsafe.Pointer(pDef)).FfuncFlags&uint32(SQLITE_FUNC_CONSTANT) == uint32(0) {
|
|
/* Clearly non-deterministic functions like random(), but also
|
|
** date/time functions that use 'now', and other functions like
|
|
** sqlite_version() that might change over time cannot be used
|
|
** in an index or generated column. Curiously, they can be used
|
|
** in a CHECK constraint. SQLServer, MySQL, and PostgreSQL all
|
|
** allow this. */
|
|
if (*TNameContext)(unsafe.Pointer(pNC)).FncFlags&(libc.Int32FromInt32(NC_IdxExpr)|libc.Int32FromInt32(NC_PartIdx)|libc.Int32FromInt32(NC_GenCol)) != 0 {
|
|
_notValidImpl(tls, pParse, pNC, __ccgo_ts+7319, uintptr(0), pExpr)
|
|
}
|
|
} else {
|
|
/* Must fit in 8 bits */
|
|
(*TExpr)(unsafe.Pointer(pExpr)).Fop2 = libc.Uint8FromInt32((*TNameContext)(unsafe.Pointer(pNC)).FncFlags & int32(NC_SelfRef))
|
|
}
|
|
if (*TFuncDef)(unsafe.Pointer(pDef)).FfuncFlags&uint32(SQLITE_FUNC_INTERNAL) != uint32(0) && libc.Int32FromUint8((*TParse)(unsafe.Pointer(pParse)).Fnested) == 0 && (*Tsqlite3)(unsafe.Pointer((*TParse)(unsafe.Pointer(pParse)).Fdb)).FmDbFlags&uint32(DBFLAG_InternalFunc) == uint32(0) {
|
|
/* Internal-use-only functions are disallowed unless the
|
|
** SQL is being compiled using sqlite3NestedParse() or
|
|
** the SQLITE_TESTCTRL_INTERNAL_FUNCTIONS test-control has be
|
|
** used to activate internal functions for testing purposes */
|
|
no_such_func = int32(1)
|
|
pDef = uintptr(0)
|
|
} else {
|
|
if (*TFuncDef)(unsafe.Pointer(pDef)).FfuncFlags&libc.Uint32FromInt32(libc.Int32FromInt32(SQLITE_FUNC_DIRECT)|libc.Int32FromInt32(SQLITE_FUNC_UNSAFE)) != uint32(0) && !(libc.Int32FromUint8((*TParse)(unsafe.Pointer(pParse)).FeParseMode) >= libc.Int32FromInt32(PARSE_MODE_RENAME)) {
|
|
if (*TNameContext)(unsafe.Pointer(pNC)).FncFlags&int32(NC_FromDDL) != 0 {
|
|
**(**Tu32)(__ccgo_up(pExpr + 4)) |= libc.Uint32FromInt32(libc.Int32FromInt32(EP_FromDDL))
|
|
}
|
|
_sqlite3ExprFunctionUsable(tls, pParse, pExpr, pDef)
|
|
}
|
|
}
|
|
}
|
|
if 0 == libc.BoolInt32(libc.Int32FromUint8((*TParse)(unsafe.Pointer(pParse)).FeParseMode) >= int32(PARSE_MODE_RENAME)) {
|
|
if pDef != 0 && (*TFuncDef)(unsafe.Pointer(pDef)).FxValue == uintptr(0) && pWin != 0 {
|
|
_sqlite3ErrorMsg(tls, pParse, __ccgo_ts+7347, libc.VaList(bp+8, pExpr))
|
|
(*TNameContext)(unsafe.Pointer(pNC)).FnNcErr = (*TNameContext)(unsafe.Pointer(pNC)).FnNcErr + 1
|
|
} else {
|
|
if is_agg != 0 && (*TNameContext)(unsafe.Pointer(pNC)).FncFlags&int32(NC_AllowAgg) == 0 || is_agg != 0 && (*TFuncDef)(unsafe.Pointer(pDef)).FfuncFlags&uint32(SQLITE_FUNC_WINDOW) != 0 && !(pWin != 0) || is_agg != 0 && pWin != 0 && (*TNameContext)(unsafe.Pointer(pNC)).FncFlags&int32(NC_AllowWin) == 0 {
|
|
if (*TFuncDef)(unsafe.Pointer(pDef)).FfuncFlags&uint32(SQLITE_FUNC_WINDOW) != 0 || pWin != 0 {
|
|
zType = __ccgo_ts + 7390
|
|
} else {
|
|
zType = __ccgo_ts + 7397
|
|
}
|
|
_sqlite3ErrorMsg(tls, pParse, __ccgo_ts+7407, libc.VaList(bp+8, zType, pExpr))
|
|
(*TNameContext)(unsafe.Pointer(pNC)).FnNcErr = (*TNameContext)(unsafe.Pointer(pNC)).FnNcErr + 1
|
|
is_agg = 0
|
|
} else {
|
|
if no_such_func != 0 && libc.Int32FromUint8((*Tsqlite3)(unsafe.Pointer((*TParse)(unsafe.Pointer(pParse)).Fdb)).Finit1.Fbusy) == 0 {
|
|
_sqlite3ErrorMsg(tls, pParse, __ccgo_ts+7435, libc.VaList(bp+8, pExpr))
|
|
(*TNameContext)(unsafe.Pointer(pNC)).FnNcErr = (*TNameContext)(unsafe.Pointer(pNC)).FnNcErr + 1
|
|
} else {
|
|
if wrong_num_args != 0 {
|
|
_sqlite3ErrorMsg(tls, pParse, __ccgo_ts+7457, libc.VaList(bp+8, pExpr))
|
|
(*TNameContext)(unsafe.Pointer(pNC)).FnNcErr = (*TNameContext)(unsafe.Pointer(pNC)).FnNcErr + 1
|
|
} else {
|
|
if is_agg == 0 && (*TExpr)(unsafe.Pointer(pExpr)).Fflags&libc.Uint32FromInt32(libc.Int32FromInt32(EP_WinFunc)) != uint32(0) {
|
|
_sqlite3ErrorMsg(tls, pParse, __ccgo_ts+7501, libc.VaList(bp+8, pExpr))
|
|
(*TNameContext)(unsafe.Pointer(pNC)).FnNcErr = (*TNameContext)(unsafe.Pointer(pNC)).FnNcErr + 1
|
|
} else {
|
|
if is_agg == 0 && (*TExpr)(unsafe.Pointer(pExpr)).FpLeft != 0 {
|
|
_sqlite3ExprOrderByAggregateError(tls, pParse, pExpr)
|
|
(*TNameContext)(unsafe.Pointer(pNC)).FnNcErr = (*TNameContext)(unsafe.Pointer(pNC)).FnNcErr + 1
|
|
}
|
|
}
|
|
}
|
|
}
|
|
}
|
|
}
|
|
if is_agg != 0 {
|
|
/* Window functions may not be arguments of aggregate functions.
|
|
** Or arguments of other window functions. But aggregate functions
|
|
** may be arguments for window functions. */
|
|
if !(pWin != 0) {
|
|
v5 = int32(NC_AllowAgg)
|
|
} else {
|
|
v5 = 0
|
|
}
|
|
**(**int32)(__ccgo_up(pNC + 24)) &= ^(libc.Int32FromInt32(NC_AllowWin) | v5)
|
|
}
|
|
} else {
|
|
if (*TExpr)(unsafe.Pointer(pExpr)).Fflags&libc.Uint32FromInt32(libc.Int32FromInt32(EP_WinFunc)) != uint32(0) || (*TExpr)(unsafe.Pointer(pExpr)).FpLeft != 0 {
|
|
is_agg = int32(1)
|
|
}
|
|
}
|
|
_sqlite3WalkExprList(tls, pWalker, pList)
|
|
if is_agg != 0 {
|
|
if (*TExpr)(unsafe.Pointer(pExpr)).FpLeft != 0 {
|
|
_sqlite3WalkExprList(tls, pWalker, *(*uintptr)(unsafe.Pointer((*TExpr)(unsafe.Pointer(pExpr)).FpLeft + 20)))
|
|
}
|
|
if pWin != 0 && (*TParse)(unsafe.Pointer(pParse)).FnErr == 0 {
|
|
pSel = (*TNameContext)(unsafe.Pointer(pNC)).FpWinSelect
|
|
if libc.BoolInt32(libc.Int32FromUint8((*TParse)(unsafe.Pointer(pParse)).FeParseMode) >= int32(PARSE_MODE_RENAME)) == 0 {
|
|
if pSel != 0 {
|
|
v4 = (*TSelect)(unsafe.Pointer(pSel)).FpWinDefn
|
|
} else {
|
|
v4 = uintptr(0)
|
|
}
|
|
_sqlite3WindowUpdate(tls, pParse, v4, pWin, pDef)
|
|
if (*Tsqlite3)(unsafe.Pointer((*TParse)(unsafe.Pointer(pParse)).Fdb)).FmallocFailed != 0 {
|
|
break
|
|
}
|
|
}
|
|
_sqlite3WalkExprList(tls, pWalker, (*TWindow)(unsafe.Pointer(pWin)).FpPartition)
|
|
_sqlite3WalkExprList(tls, pWalker, (*TWindow)(unsafe.Pointer(pWin)).FpOrderBy)
|
|
_sqlite3WalkExpr(tls, pWalker, (*TWindow)(unsafe.Pointer(pWin)).FpFilter)
|
|
_sqlite3WindowLink(tls, pSel, pWin)
|
|
**(**int32)(__ccgo_up(pNC + 24)) |= int32(NC_HasWin)
|
|
} else {
|
|
/* For looping up thru outer contexts */
|
|
(*TExpr)(unsafe.Pointer(pExpr)).Fop = uint8(TK_AGG_FUNCTION)
|
|
(*TExpr)(unsafe.Pointer(pExpr)).Fop2 = uint8(0)
|
|
if (*TExpr)(unsafe.Pointer(pExpr)).Fflags&libc.Uint32FromInt32(libc.Int32FromInt32(EP_WinFunc)) != uint32(0) {
|
|
_sqlite3WalkExpr(tls, pWalker, (*TWindow)(unsafe.Pointer(*(*uintptr)(unsafe.Pointer(&(*TExpr)(unsafe.Pointer(pExpr)).Fy)))).FpFilter)
|
|
}
|
|
pNC2 = pNC
|
|
for pNC2 != 0 && _sqlite3ReferencesSrcList(tls, pParse, pExpr, (*TNameContext)(unsafe.Pointer(pNC2)).FpSrcList) == 0 {
|
|
v4 = pExpr + 2
|
|
*(*Tu8)(unsafe.Pointer(v4)) = Tu8(uint32(*(*Tu8)(unsafe.Pointer(v4))) + (libc.Uint32FromInt32(1) + (*TNameContext)(unsafe.Pointer(pNC2)).FnNestedSelect))
|
|
pNC2 = (*TNameContext)(unsafe.Pointer(pNC2)).FpNext
|
|
}
|
|
if pNC2 != 0 && pDef != 0 {
|
|
v4 = pExpr + 2
|
|
*(*Tu8)(unsafe.Pointer(v4)) = Tu8(uint32(*(*Tu8)(unsafe.Pointer(v4))) + (*TNameContext)(unsafe.Pointer(pNC2)).FnNestedSelect)
|
|
v4 = pNC2 + 24
|
|
*(*int32)(unsafe.Pointer(v4)) = int32(uint32(*(*int32)(unsafe.Pointer(v4))) | (libc.Uint32FromInt32(NC_HasAgg) | ((*TFuncDef)(unsafe.Pointer(pDef)).FfuncFlags^libc.Uint32FromInt32(SQLITE_FUNC_ANYORDER))&libc.Uint32FromInt32(libc.Int32FromInt32(SQLITE_FUNC_MINMAX)|libc.Int32FromInt32(SQLITE_FUNC_ANYORDER))))
|
|
}
|
|
}
|
|
**(**int32)(__ccgo_up(pNC + 24)) |= savedAllowFlags
|
|
}
|
|
/* FIX ME: Compute pExpr->affinity based on the expected return
|
|
** type of the function
|
|
*/
|
|
return int32(WRC_Prune)
|
|
case int32(TK_EXISTS):
|
|
fallthrough
|
|
case int32(TK_SELECT):
|
|
fallthrough
|
|
case int32(TK_IN):
|
|
if (*TExpr)(unsafe.Pointer(pExpr)).Fflags&uint32(EP_xIsSelect) != uint32(0) {
|
|
nRef = (*TNameContext)(unsafe.Pointer(pNC)).FnRef
|
|
if libc.Int32FromUint8((*TExpr)(unsafe.Pointer(pExpr)).Fop) == int32(TK_EXISTS) {
|
|
libc.SetBitFieldPtr16Uint32(pParse+28, libc.Uint32FromInt32(1), 4, 0x10)
|
|
}
|
|
if (*TNameContext)(unsafe.Pointer(pNC)).FncFlags&int32(NC_SelfRef) != 0 {
|
|
_notValidImpl(tls, pParse, pNC, __ccgo_ts+7549, pExpr, pExpr)
|
|
} else {
|
|
_sqlite3WalkSelect(tls, pWalker, *(*uintptr)(unsafe.Pointer(pExpr + 20)))
|
|
}
|
|
if nRef != (*TNameContext)(unsafe.Pointer(pNC)).FnRef {
|
|
**(**Tu32)(__ccgo_up(pExpr + 4)) |= libc.Uint32FromInt32(libc.Int32FromInt32(EP_VarSelect))
|
|
**(**Tu32)(__ccgo_up(*(*uintptr)(unsafe.Pointer(pExpr + 20)) + 4)) |= uint32(SF_Correlated)
|
|
}
|
|
**(**int32)(__ccgo_up(pNC + 24)) |= int32(NC_Subquery)
|
|
}
|
|
case int32(TK_VARIABLE):
|
|
if (*TNameContext)(unsafe.Pointer(pNC)).FncFlags&(libc.Int32FromInt32(NC_IsCheck)|libc.Int32FromInt32(NC_PartIdx)|libc.Int32FromInt32(NC_IdxExpr)|libc.Int32FromInt32(NC_GenCol)) != 0 {
|
|
_notValidImpl(tls, pParse, pNC, __ccgo_ts+7560, pExpr, pExpr)
|
|
}
|
|
case int32(TK_IS):
|
|
fallthrough
|
|
case int32(TK_ISNOT):
|
|
pRight1 = _sqlite3ExprSkipCollateAndLikely(tls, (*TExpr)(unsafe.Pointer(pExpr)).FpRight)
|
|
/* Handle special cases of "x IS TRUE", "x IS FALSE", "x IS NOT TRUE",
|
|
** and "x IS NOT FALSE". */
|
|
if pRight1 != 0 && (libc.Int32FromUint8((*TExpr)(unsafe.Pointer(pRight1)).Fop) == int32(TK_ID) || libc.Int32FromUint8((*TExpr)(unsafe.Pointer(pRight1)).Fop) == int32(TK_TRUEFALSE)) {
|
|
rc = _resolveExprStep(tls, pWalker, pRight1)
|
|
if rc == int32(WRC_Abort) {
|
|
return int32(WRC_Abort)
|
|
}
|
|
if libc.Int32FromUint8((*TExpr)(unsafe.Pointer(pRight1)).Fop) == int32(TK_TRUEFALSE) {
|
|
(*TExpr)(unsafe.Pointer(pExpr)).Fop2 = (*TExpr)(unsafe.Pointer(pExpr)).Fop
|
|
(*TExpr)(unsafe.Pointer(pExpr)).Fop = uint8(TK_TRUTH)
|
|
return WRC_Continue
|
|
}
|
|
}
|
|
fallthrough
|
|
case int32(TK_BETWEEN):
|
|
fallthrough
|
|
case int32(TK_EQ):
|
|
fallthrough
|
|
case int32(TK_NE):
|
|
fallthrough
|
|
case int32(TK_LT):
|
|
fallthrough
|
|
case int32(TK_LE):
|
|
fallthrough
|
|
case int32(TK_GT):
|
|
fallthrough
|
|
case int32(TK_GE):
|
|
if (*Tsqlite3)(unsafe.Pointer((*TParse)(unsafe.Pointer(pParse)).Fdb)).FmallocFailed != 0 {
|
|
break
|
|
}
|
|
nLeft = _sqlite3ExprVectorSize(tls, (*TExpr)(unsafe.Pointer(pExpr)).FpLeft)
|
|
if libc.Int32FromUint8((*TExpr)(unsafe.Pointer(pExpr)).Fop) == int32(TK_BETWEEN) {
|
|
nRight = _sqlite3ExprVectorSize(tls, (*(*TExprList_item)(unsafe.Pointer(*(*uintptr)(unsafe.Pointer(pExpr + 20)) + 8))).FpExpr)
|
|
if nRight == nLeft {
|
|
nRight = _sqlite3ExprVectorSize(tls, (*(*TExprList_item)(unsafe.Pointer(*(*uintptr)(unsafe.Pointer(pExpr + 20)) + 8 + 1*20))).FpExpr)
|
|
}
|
|
} else {
|
|
nRight = _sqlite3ExprVectorSize(tls, (*TExpr)(unsafe.Pointer(pExpr)).FpRight)
|
|
}
|
|
if nLeft != nRight {
|
|
_sqlite3ErrorMsg(tls, pParse, __ccgo_ts+6910, 0)
|
|
_sqlite3RecordErrorOffsetOfExpr(tls, (*TParse)(unsafe.Pointer(pParse)).Fdb, pExpr)
|
|
}
|
|
break
|
|
}
|
|
if (*TParse)(unsafe.Pointer(pParse)).FnErr != 0 {
|
|
v5 = int32(WRC_Abort)
|
|
} else {
|
|
v5 = WRC_Continue
|
|
}
|
|
return v5
|
|
}
|
|
|
|
// 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(240)
|
|
defer tls.Free(240)
|
|
var fd, v1 int32
|
|
var m2 Tmode_t
|
|
var _ /* statbuf at bp+0 */ Tstat
|
|
_, _, _ = fd, m2, v1
|
|
if m != 0 {
|
|
v1 = libc.Int32FromUint16(m)
|
|
} else {
|
|
v1 = int32(SQLITE_DEFAULT_FILE_PERMISSIONS)
|
|
}
|
|
m2 = libc.Uint16FromInt32(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.Int32FromUint16(m2))
|
|
if fd < 0 {
|
|
if **(**int32)(__ccgo_up(libc.X__error(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+3750, libc.VaList(bp+216, z, fd))
|
|
fd = -int32(1)
|
|
if (*(*func(*libc.TLS, uintptr, int32, int32) int32)(unsafe.Pointer(&struct{ uintptr }{_aSyscall[0].FpCurrent})))(tls, __ccgo_ts+3793, O_RDONLY, libc.Int32FromUint16(m)) < 0 {
|
|
break
|
|
}
|
|
}
|
|
if fd >= 0 {
|
|
if libc.Int32FromUint16(m) != 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 && libc.Int32FromUint16((**(**Tstat)(__ccgo_up(bp))).Fst_mode)&int32(0777) != libc.Int32FromUint16(m) {
|
|
(*(*func(*libc.TLS, int32, Tmode_t) int32)(unsafe.Pointer(&struct{ uintptr }{_aSyscall[int32(14)].FpCurrent})))(tls, fd, m)
|
|
}
|
|
}
|
|
}
|
|
return fd
|
|
}
|
|
|
|
// C documentation
|
|
//
|
|
// /*
|
|
// ** This function is the implementation of both the xConnect and xCreate
|
|
// ** methods of the r-tree virtual table.
|
|
// **
|
|
// ** argv[0] -> module name
|
|
// ** argv[1] -> database name
|
|
// ** argv[2] -> table name
|
|
// ** argv[...] -> column names...
|
|
// */
|
|
func _rtreeInit(tls *libc.TLS, db uintptr, pAux uintptr, argc int32, argv uintptr, ppVtab uintptr, pzErr uintptr, isCreate int32) (r int32) {
|
|
bp := tls.Alloc(32)
|
|
defer tls.Free(32)
|
|
var aErrMsg [5]uintptr
|
|
var eCoordType, iErr, ii, nDb, nName, rc, v1 int32
|
|
var pRtree, pSql, zArg, zSql uintptr
|
|
_, _, _, _, _, _, _, _, _, _, _, _ = aErrMsg, eCoordType, iErr, ii, nDb, nName, pRtree, pSql, rc, zArg, zSql, v1
|
|
rc = SQLITE_OK
|
|
if pAux != 0 {
|
|
v1 = int32(RTREE_COORD_INT32)
|
|
} else {
|
|
v1 = RTREE_COORD_REAL32
|
|
} /* Length of string argv[2] */
|
|
eCoordType = v1
|
|
ii = int32(4)
|
|
aErrMsg = [5]uintptr{
|
|
1: __ccgo_ts + 28799,
|
|
2: __ccgo_ts + 28842,
|
|
3: __ccgo_ts + 28877,
|
|
4: __ccgo_ts + 28913,
|
|
}
|
|
if argc < int32(6) || argc > libc.Int32FromInt32(RTREE_MAX_AUX_COLUMN)+libc.Int32FromInt32(3) {
|
|
**(**uintptr)(__ccgo_up(pzErr)) = Xsqlite3_mprintf(tls, __ccgo_ts+3942, libc.VaList(bp+8, aErrMsg[int32(2)+libc.BoolInt32(argc >= int32(6))]))
|
|
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.Int32FromUint32(libc.Xstrlen(tls, **(**uintptr)(__ccgo_up(argv + 1*4))))
|
|
nName = libc.Int32FromUint32(libc.Xstrlen(tls, **(**uintptr)(__ccgo_up(argv + 2*4))))
|
|
pRtree = Xsqlite3_malloc64(tls, uint64(uint32(504)+libc.Uint32FromInt32(nDb)+libc.Uint32FromInt32(nName*int32(2))+uint32(8)))
|
|
if !(pRtree != 0) {
|
|
return int32(SQLITE_NOMEM)
|
|
}
|
|
libc.Xmemset(tls, pRtree, 0, uint32(504)+libc.Uint32FromInt32(nDb)+libc.Uint32FromInt32(nName*int32(2))+uint32(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*504
|
|
(*TRtree)(unsafe.Pointer(pRtree)).FzName = (*TRtree)(unsafe.Pointer(pRtree)).FzDb + uintptr(nDb+int32(1))
|
|
(*TRtree)(unsafe.Pointer(pRtree)).FzNodeName = (*TRtree)(unsafe.Pointer(pRtree)).FzName + uintptr(nName+int32(1))
|
|
(*TRtree)(unsafe.Pointer(pRtree)).FeCoordType = libc.Uint8FromInt32(eCoordType)
|
|
libc.Xmemcpy(tls, (*TRtree)(unsafe.Pointer(pRtree)).FzDb, **(**uintptr)(__ccgo_up(argv + 1*4)), libc.Uint32FromInt32(nDb))
|
|
libc.Xmemcpy(tls, (*TRtree)(unsafe.Pointer(pRtree)).FzName, **(**uintptr)(__ccgo_up(argv + 2*4)), libc.Uint32FromInt32(nName))
|
|
libc.Xmemcpy(tls, (*TRtree)(unsafe.Pointer(pRtree)).FzNodeName, **(**uintptr)(__ccgo_up(argv + 2*4)), libc.Uint32FromInt32(nName))
|
|
libc.Xmemcpy(tls, (*TRtree)(unsafe.Pointer(pRtree)).FzNodeName+uintptr(nName), __ccgo_ts+28950, uint32(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+28956, libc.VaList(bp+8, _rtreeTokenLength(tls, **(**uintptr)(__ccgo_up(argv + 3*4))), **(**uintptr)(__ccgo_up(argv + 3*4))))
|
|
ii = int32(4)
|
|
for {
|
|
if !(ii < argc) {
|
|
break
|
|
}
|
|
zArg = **(**uintptr)(__ccgo_up(argv + uintptr(ii)*4))
|
|
if int32(**(**int8)(__ccgo_up(zArg))) == int32('+') {
|
|
(*TRtree)(unsafe.Pointer(pRtree)).FnAux = (*TRtree)(unsafe.Pointer(pRtree)).FnAux + 1
|
|
Xsqlite3_str_appendf(tls, pSql, __ccgo_ts+28980, libc.VaList(bp+8, _rtreeTokenLength(tls, zArg+uintptr(1)), zArg+uintptr(1)))
|
|
} else {
|
|
if libc.Int32FromUint16((*TRtree)(unsafe.Pointer(pRtree)).FnAux) > 0 {
|
|
break
|
|
} else {
|
|
(*TRtree)(unsafe.Pointer(pRtree)).FnDim2 = (*TRtree)(unsafe.Pointer(pRtree)).FnDim2 + 1
|
|
Xsqlite3_str_appendf(tls, pSql, _azFormat[eCoordType], libc.VaList(bp+8, _rtreeTokenLength(tls, zArg), zArg))
|
|
}
|
|
}
|
|
goto _2
|
|
_2:
|
|
;
|
|
ii = ii + 1
|
|
}
|
|
Xsqlite3_str_appendf(tls, pSql, __ccgo_ts+29007, 0)
|
|
zSql = Xsqlite3_str_finish(tls, pSql)
|
|
if !(zSql != 0) {
|
|
rc = int32(SQLITE_NOMEM)
|
|
} else {
|
|
if ii < argc {
|
|
**(**uintptr)(__ccgo_up(pzErr)) = Xsqlite3_mprintf(tls, __ccgo_ts+3942, libc.VaList(bp+8, aErrMsg[int32(4)]))
|
|
rc = int32(SQLITE_ERROR)
|
|
} else {
|
|
v1 = Xsqlite3_declare_vtab(tls, db, zSql)
|
|
rc = v1
|
|
if SQLITE_OK != v1 {
|
|
**(**uintptr)(__ccgo_up(pzErr)) = Xsqlite3_mprintf(tls, __ccgo_ts+3942, libc.VaList(bp+8, Xsqlite3_errmsg(tls, db)))
|
|
}
|
|
}
|
|
}
|
|
Xsqlite3_free(tls, zSql)
|
|
if rc != 0 {
|
|
goto rtreeInit_fail
|
|
}
|
|
(*TRtree)(unsafe.Pointer(pRtree)).FnDim = libc.Uint8FromInt32(libc.Int32FromUint8((*TRtree)(unsafe.Pointer(pRtree)).FnDim2) / int32(2))
|
|
if libc.Int32FromUint8((*TRtree)(unsafe.Pointer(pRtree)).FnDim) < int32(1) {
|
|
iErr = int32(2)
|
|
} else {
|
|
if libc.Int32FromUint8((*TRtree)(unsafe.Pointer(pRtree)).FnDim2) > libc.Int32FromInt32(RTREE_MAX_DIMENSIONS)*libc.Int32FromInt32(2) {
|
|
iErr = int32(3)
|
|
} else {
|
|
if libc.Int32FromUint8((*TRtree)(unsafe.Pointer(pRtree)).FnDim2)%int32(2) != 0 {
|
|
iErr = int32(1)
|
|
} else {
|
|
iErr = 0
|
|
}
|
|
}
|
|
}
|
|
if iErr != 0 {
|
|
**(**uintptr)(__ccgo_up(pzErr)) = Xsqlite3_mprintf(tls, __ccgo_ts+3942, libc.VaList(bp+8, aErrMsg[iErr]))
|
|
goto rtreeInit_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 rtreeInit_fail
|
|
}
|
|
rc = _rtreeSqlInit(tls, pRtree, db, **(**uintptr)(__ccgo_up(argv + 1*4)), **(**uintptr)(__ccgo_up(argv + 2*4)), isCreate)
|
|
if rc != 0 {
|
|
**(**uintptr)(__ccgo_up(pzErr)) = Xsqlite3_mprintf(tls, __ccgo_ts+3942, libc.VaList(bp+8, Xsqlite3_errmsg(tls, db)))
|
|
goto rtreeInit_fail
|
|
}
|
|
**(**uintptr)(__ccgo_up(ppVtab)) = pRtree
|
|
return SQLITE_OK
|
|
goto rtreeInit_fail
|
|
rtreeInit_fail:
|
|
;
|
|
if rc == SQLITE_OK {
|
|
rc = int32(SQLITE_ERROR)
|
|
}
|
|
_rtreeRelease(tls, pRtree)
|
|
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+28211, 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+28273, libc.VaList(bp+8, ii))
|
|
goto _1
|
|
_1:
|
|
;
|
|
ii = ii + 1
|
|
}
|
|
Xsqlite3_str_appendf(tls, p, __ccgo_ts+28278, libc.VaList(bp+8, zDb, zPrefix))
|
|
Xsqlite3_str_appendf(tls, p, __ccgo_ts+28342, libc.VaList(bp+8, zDb, zPrefix))
|
|
Xsqlite3_str_appendf(tls, p, __ccgo_ts+28412, 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 + 80
|
|
appStmt[int32(1)] = pRtree + 84
|
|
appStmt[int32(2)] = pRtree + 88
|
|
appStmt[int32(3)] = pRtree + 92
|
|
appStmt[int32(4)] = pRtree + 96
|
|
appStmt[int32(5)] = pRtree + 100
|
|
appStmt[int32(6)] = pRtree + 104
|
|
appStmt[int32(7)] = pRtree + 108
|
|
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 + 28461
|
|
}
|
|
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+28569, 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+28614, 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+14348, int32(1))
|
|
}
|
|
if ii1 < libc.Int32FromUint8((*TRtree)(unsafe.Pointer(pRtree)).FnAuxNotNull) {
|
|
Xsqlite3_str_appendf(tls, p1, __ccgo_ts+28641, libc.VaList(bp+8, ii1, ii1+int32(2), ii1))
|
|
} else {
|
|
Xsqlite3_str_appendf(tls, p1, __ccgo_ts+28663, libc.VaList(bp+8, ii1, ii1+int32(2)))
|
|
}
|
|
goto _3
|
|
_3:
|
|
;
|
|
ii1 = ii1 + 1
|
|
}
|
|
Xsqlite3_str_appendf(tls, p1, __ccgo_ts+28671, 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+112, uintptr(0))
|
|
Xsqlite3_free(tls, zSql1)
|
|
}
|
|
}
|
|
}
|
|
return rc
|
|
}
|
|
|
|
// 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(608)
|
|
defer tls.Free(608)
|
|
var errCode, ii, jj, nData int32
|
|
var pOut uintptr
|
|
var _ /* cell at bp+532 */ TRtreeCell
|
|
var _ /* node at bp+0 */ TRtreeNode
|
|
var _ /* tree at bp+28 */ TRtree
|
|
_, _, _, _, _ = errCode, ii, jj, nData, pOut
|
|
_ = nArg
|
|
libc.Xmemset(tls, bp, 0, uint32(28))
|
|
libc.Xmemset(tls, bp+28, 0, uint32(504))
|
|
(**(**TRtree)(__ccgo_up(bp + 28))).FnDim = libc.Uint8FromInt32(Xsqlite3_value_int(tls, **(**uintptr)(__ccgo_up(apArg))))
|
|
if libc.Int32FromUint8((**(**TRtree)(__ccgo_up(bp + 28))).FnDim) < int32(1) || libc.Int32FromUint8((**(**TRtree)(__ccgo_up(bp + 28))).FnDim) > int32(5) {
|
|
return
|
|
}
|
|
(**(**TRtree)(__ccgo_up(bp + 28))).FnDim2 = libc.Uint8FromInt32(libc.Int32FromUint8((**(**TRtree)(__ccgo_up(bp + 28))).FnDim) * int32(2))
|
|
(**(**TRtree)(__ccgo_up(bp + 28))).FnBytesPerCell = libc.Uint8FromInt32(int32(8) + int32(8)*libc.Int32FromUint8((**(**TRtree)(__ccgo_up(bp + 28))).FnDim))
|
|
(**(**TRtreeNode)(__ccgo_up(bp))).FzData = Xsqlite3_value_blob(tls, **(**uintptr)(__ccgo_up(apArg + 1*4)))
|
|
if (**(**TRtreeNode)(__ccgo_up(bp))).FzData == uintptr(0) {
|
|
return
|
|
}
|
|
nData = Xsqlite3_value_bytes(tls, **(**uintptr)(__ccgo_up(apArg + 1*4)))
|
|
if nData < int32(4) {
|
|
return
|
|
}
|
|
if nData < int32(4)+_readInt16(tls, (*TRtreeNode)(unsafe.Pointer(bp)).FzData+2)*libc.Int32FromUint8((**(**TRtree)(__ccgo_up(bp + 28))).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+28, bp, ii, bp+532)
|
|
if ii > 0 {
|
|
Xsqlite3_str_append(tls, pOut, __ccgo_ts+11543, int32(1))
|
|
}
|
|
Xsqlite3_str_appendf(tls, pOut, __ccgo_ts+29010, libc.VaList(bp+592, (**(**TRtreeCell)(__ccgo_up(bp + 532))).FiRowid))
|
|
jj = 0
|
|
for {
|
|
if !(jj < libc.Int32FromUint8((**(**TRtree)(__ccgo_up(bp + 28))).FnDim2)) {
|
|
break
|
|
}
|
|
Xsqlite3_str_appendf(tls, pOut, __ccgo_ts+29016, libc.VaList(bp+592, float64(*(*TRtreeValue)(unsafe.Pointer(bp + 532 + 8 + uintptr(jj)*4)))))
|
|
goto _2
|
|
_2:
|
|
;
|
|
jj = jj + 1
|
|
}
|
|
Xsqlite3_str_append(tls, pOut, __ccgo_ts+26855, 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
|
|
//
|
|
// /*
|
|
// ** 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 + 100
|
|
*(*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(uint32(libc.UintptrFromInt32(0)+12)+libc.Uint32FromInt32(libc.Int32FromInt32(1))*libc.Uint32FromInt64(24)))
|
|
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 + 44)))).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+21257, 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*16))).FpSchema {
|
|
_sqlite3ErrorMsg(tls, pParse, __ccgo_ts+21296, 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 + 12 + 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 + 44))).Fp != uintptr(0) && libc.Int32FromUint8((*TVTable)(unsafe.Pointer((*(*struct {
|
|
FnArg int32
|
|
FazArg uintptr
|
|
Fp uintptr
|
|
})(unsafe.Pointer(pTab + 44))).Fp)).FeVtabRisk) > libc.BoolInt32((*Tsqlite3)(unsafe.Pointer(db)).Fflags&uint64(SQLITE_TrustedSchema) != uint64(0)) {
|
|
_sqlite3ErrorMsg(tls, pParse, __ccgo_ts+16347, 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 + 12 + 4))&0x4>>2) != 0 {
|
|
_sqlite3WalkSelect(tls, pWalker, (*TSubquery)(unsafe.Pointer(*(*uintptr)(unsafe.Pointer(pFrom + 44)))).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 + 12 + 4))&0x2>>1) != 0 && _sqlite3IndexedByLookup(tls, pParse, pFrom) != 0 {
|
|
return int32(WRC_Abort)
|
|
}
|
|
goto _3
|
|
_3:
|
|
;
|
|
i = i + 1
|
|
pFrom += 48
|
|
}
|
|
/* 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)*20))).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)*20))).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)*20))).FpExpr)
|
|
if pNew != 0 {
|
|
(*(*TExprList_item)(unsafe.Pointer(pNew + 8 + uintptr((*TExprList)(unsafe.Pointer(pNew)).FnExpr-int32(1))*20))).FzEName = (**(**TExprList_item)(__ccgo_up(a + uintptr(k)*20))).FzEName
|
|
libc.SetBitFieldPtr16Uint32(pNew+8+uintptr((*TExprList)(unsafe.Pointer(pNew)).FnExpr-int32(1))*20+8+4, libc.Uint32FromInt32(int32(uint32(*(*uint16)(unsafe.Pointer(a + uintptr(k)*20 + 8 + 4))&0x3>>0))), 0, 0x3)
|
|
(**(**TExprList_item)(__ccgo_up(a + uintptr(k)*20))).FzEName = uintptr(0)
|
|
}
|
|
(**(**TExprList_item)(__ccgo_up(a + uintptr(k)*20))).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 + 36))
|
|
} else {
|
|
iErrOfst = *(*int32)(unsafe.Pointer(pE + 36))
|
|
}
|
|
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 + 12 + 4))&0x4000>>14) != 0 {
|
|
pNestedFrom = (*TSelect)(unsafe.Pointer((*TSubquery)(unsafe.Pointer(*(*uintptr)(unsafe.Pointer(pFrom + 44)))).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)*16))).FzDbSName
|
|
} else {
|
|
v2 = __ccgo_ts + 6823
|
|
}
|
|
zSchemaName = v2
|
|
}
|
|
if i+int32(1) < (*TSrcList)(unsafe.Pointer(pTabList)).FnSrc && int32(*(*uint32)(unsafe.Pointer(pFrom + 1*48 + 12 + 4))&0x800>>11) != 0 && libc.Int32FromUint16(selFlags)&int32(SF_NestedFrom) != 0 {
|
|
pUsing = *(*uintptr)(unsafe.Pointer(pFrom + 1*48 + 40))
|
|
ii = 0
|
|
for {
|
|
if !(ii < (*TIdList)(unsafe.Pointer(pUsing)).FnId) {
|
|
break
|
|
}
|
|
zUName = (*(*TIdList_item)(unsafe.Pointer(pUsing + 4 + uintptr(ii)*4))).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))*20
|
|
(*TExprList_item)(unsafe.Pointer(pX)).FzEName = _sqlite3MPrintf(tls, db, __ccgo_ts+21327, libc.VaList(bp+8, zUName))
|
|
libc.SetBitFieldPtr16Uint32(pX+8+4, libc.Uint32FromInt32(ENAME_TAB), 0, 0x3)
|
|
libc.SetBitFieldPtr16Uint32(pX+8+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)*12))).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)*20 + 8 + 4))&0x3>>0)) == int32(ENAME_ROWID) {
|
|
goto _12
|
|
}
|
|
if zTName != 0 && pNestedFrom != 0 && _sqlite3MatchEName(tls, pNestedFrom+8+uintptr(j)*20, 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)*12)).FcolFlags)&int32(COLFLAG_HIDDEN) != 0 {
|
|
goto _12
|
|
}
|
|
if libc.Int32FromUint16((**(**TColumn)(__ccgo_up((*TTable)(unsafe.Pointer(pTab1)).FaCol + uintptr(j)*12))).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 + 12 + 4))&0x800>>11) != 0 && _sqlite3IdListIndex(tls, *(*uintptr)(unsafe.Pointer(pFrom + 40)), 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))*20
|
|
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)*20))).FzEName)
|
|
} else {
|
|
(*TExprList_item)(unsafe.Pointer(pX1)).FzEName = _sqlite3MPrintf(tls, db, __ccgo_ts+21332, 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+8+4, libc.Uint32FromInt32(v1), 0, 0x3)
|
|
if int32(*(*uint32)(unsafe.Pointer(pFrom + 12 + 4))&0x800>>11) != 0 && _sqlite3IdListIndex(tls, *(*uintptr)(unsafe.Pointer(pFrom + 40)), 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)*12))).FcolFlags)&int32(COLFLAG_NOEXPAND) != 0 {
|
|
libc.SetBitFieldPtr16Uint32(pX1+8+4, libc.Uint32FromInt32(1), 8, 0x100)
|
|
}
|
|
} else {
|
|
if longNames != 0 {
|
|
(*TExprList_item)(unsafe.Pointer(pX1)).FzEName = _sqlite3MPrintf(tls, db, __ccgo_ts+13634, libc.VaList(bp+8, zTabName, zName))
|
|
libc.SetBitFieldPtr16Uint32(pX1+8+4, libc.Uint32FromInt32(ENAME_NAME), 0, 0x3)
|
|
} else {
|
|
(*TExprList_item)(unsafe.Pointer(pX1)).FzEName = _sqlite3DbStrDup(tls, db, zName)
|
|
libc.SetBitFieldPtr16Uint32(pX1+8+4, libc.Uint32FromInt32(ENAME_NAME), 0, 0x3)
|
|
}
|
|
}
|
|
goto _12
|
|
_12:
|
|
;
|
|
j = j + 1
|
|
}
|
|
goto _8
|
|
_8:
|
|
;
|
|
i = i + 1
|
|
pFrom += 48
|
|
}
|
|
if !(tableSeen != 0) {
|
|
if zTName != 0 {
|
|
_sqlite3ErrorMsg(tls, pParse, __ccgo_ts+21341, libc.VaList(bp+8, zTName))
|
|
} else {
|
|
_sqlite3ErrorMsg(tls, pParse, __ccgo_ts+21359, 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 + 116 + 2*4)) {
|
|
_sqlite3ErrorMsg(tls, pParse, __ccgo_ts+21379, 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 function is a no-op if *pRc is other than SQLITE_OK when it is
|
|
// ** called. Otherwise, append the string representation of integer iVal
|
|
// ** to the buffer. No nul-terminator is written.
|
|
// **
|
|
// ** If an OOM condition is encountered, set *pRc to SQLITE_NOMEM before
|
|
// ** returning.
|
|
// */
|
|
func _sessionAppendInteger(tls *libc.TLS, p uintptr, iVal int32, pRc uintptr) {
|
|
bp := tls.Alloc(48)
|
|
defer tls.Free(48)
|
|
var _ /* aBuf at bp+0 */ [24]int8
|
|
Xsqlite3_snprintf(tls, libc.Int32FromUint32(libc.Uint32FromInt64(24)-libc.Uint32FromInt32(1)), bp, __ccgo_ts+5291, libc.VaList(bp+32, iVal))
|
|
_sessionAppendStr(tls, p, bp, pRc)
|
|
}
|
|
|
|
// 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(256)
|
|
defer tls.Free(256)
|
|
var bPatchset, i, nMinCol, nTab, rc, rc2, res, schemaMismatch, v2, v3, v4 int32
|
|
var savedFlag Tu64
|
|
var v5, v7 bool
|
|
var _ /* abPK at bp+100 */ uintptr
|
|
var _ /* nCol at bp+88 */ int32
|
|
var _ /* nFk at bp+104 */ int32
|
|
var _ /* notUsed at bp+108 */ int32
|
|
var _ /* op at bp+92 */ int32
|
|
var _ /* sApply at bp+4 */ TSessionApplyCtx
|
|
var _ /* sIter at bp+112 */ Tsqlite3_changeset_iter
|
|
var _ /* zNew at bp+96 */ 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 + 28)) |= 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+4, 0, uint32(84))
|
|
(**(**TSessionApplyCtx)(__ccgo_up(bp + 4))).FbRebase = libc.BoolUint8(ppRebase != 0 && pnRebase != 0)
|
|
(**(**TSessionApplyCtx)(__ccgo_up(bp + 4))).FbInvertConstraints = libc.BoolInt32(!!(flags&libc.Int32FromInt32(SQLITE_CHANGESETAPPLY_INVERT) != 0))
|
|
(**(**TSessionApplyCtx)(__ccgo_up(bp + 4))).FbIgnoreNoop = libc.BoolUint8(!!(flags&libc.Int32FromInt32(SQLITE_CHANGESETAPPLY_IGNORENOOP) != 0))
|
|
(**(**TSessionApplyCtx)(__ccgo_up(bp + 4))).FbNoUpdateLoop = libc.BoolUint8(!!(flags&libc.Int32FromInt32(SQLITE_CHANGESETAPPLY_NOUPDATELOOP) != 0))
|
|
if flags&int32(SQLITE_CHANGESETAPPLY_NOSAVEPOINT) == 0 {
|
|
rc = Xsqlite3_exec(tls, db, __ccgo_ts+36515, uintptr(0), uintptr(0), uintptr(0))
|
|
}
|
|
if rc == SQLITE_OK {
|
|
rc = Xsqlite3_exec(tls, db, __ccgo_ts+36541, uintptr(0), uintptr(0), uintptr(0))
|
|
}
|
|
for rc == SQLITE_OK && int32(SQLITE_ROW) == Xsqlite3changeset_next(tls, pIter) {
|
|
Xsqlite3changeset_op(tls, pIter, bp+96, bp+88, bp+92, uintptr(0))
|
|
if **(**uintptr)(__ccgo_up(bp)) == uintptr(0) || Xsqlite3_strnicmp(tls, **(**uintptr)(__ccgo_up(bp + 96)), **(**uintptr)(__ccgo_up(bp)), nTab+int32(1)) != 0 {
|
|
rc = _sessionRetryConstraints(tls, db, (*Tsqlite3_changeset_iter)(unsafe.Pointer(pIter)).FbPatchset, **(**uintptr)(__ccgo_up(bp)), bp+4, __ccgo_fp_xConflict, pCtx)
|
|
if rc != SQLITE_OK {
|
|
break
|
|
}
|
|
_sessionUpdateFree(tls, bp+4)
|
|
Xsqlite3_free(tls, (**(**TSessionApplyCtx)(__ccgo_up(bp + 4))).FazCol) /* cast works around VC++ bug */
|
|
Xsqlite3_finalize(tls, (**(**TSessionApplyCtx)(__ccgo_up(bp + 4))).FpDelete)
|
|
Xsqlite3_finalize(tls, (**(**TSessionApplyCtx)(__ccgo_up(bp + 4))).FpInsert)
|
|
Xsqlite3_finalize(tls, (**(**TSessionApplyCtx)(__ccgo_up(bp + 4))).FpSelect)
|
|
(**(**TSessionApplyCtx)(__ccgo_up(bp + 4))).Fdb = db
|
|
(**(**TSessionApplyCtx)(__ccgo_up(bp + 4))).FpDelete = uintptr(0)
|
|
(**(**TSessionApplyCtx)(__ccgo_up(bp + 4))).FpInsert = uintptr(0)
|
|
(**(**TSessionApplyCtx)(__ccgo_up(bp + 4))).FpSelect = uintptr(0)
|
|
(**(**TSessionApplyCtx)(__ccgo_up(bp + 4))).FnCol = 0
|
|
(**(**TSessionApplyCtx)(__ccgo_up(bp + 4))).FazCol = uintptr(0)
|
|
(**(**TSessionApplyCtx)(__ccgo_up(bp + 4))).FabPK = uintptr(0)
|
|
(**(**TSessionApplyCtx)(__ccgo_up(bp + 4))).FbStat1 = 0
|
|
(**(**TSessionApplyCtx)(__ccgo_up(bp + 4))).FbDeferConstraints = int32(1)
|
|
(**(**TSessionApplyCtx)(__ccgo_up(bp + 4))).FbRebaseStarted = uint8(0)
|
|
(**(**TSessionApplyCtx)(__ccgo_up(bp + 4))).FbRowid = 0
|
|
libc.Xmemset(tls, bp+4+48, 0, uint32(12))
|
|
/* 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 + 96))))
|
|
if schemaMismatch != 0 {
|
|
**(**uintptr)(__ccgo_up(bp)) = Xsqlite3_mprintf(tls, __ccgo_ts+3942, libc.VaList(bp+224, **(**uintptr)(__ccgo_up(bp + 96))))
|
|
if **(**uintptr)(__ccgo_up(bp)) == uintptr(0) {
|
|
rc = int32(SQLITE_NOMEM)
|
|
break
|
|
}
|
|
nTab = libc.Int32FromUint32(libc.Xstrlen(tls, **(**uintptr)(__ccgo_up(bp))))
|
|
(**(**TSessionApplyCtx)(__ccgo_up(bp + 4))).FazCol = **(**uintptr)(__ccgo_up(bp))
|
|
} else {
|
|
nMinCol = 0
|
|
Xsqlite3changeset_pk(tls, pIter, bp+100, uintptr(0))
|
|
rc = _sessionTableInfo(tls, uintptr(0), db, __ccgo_ts+6818, **(**uintptr)(__ccgo_up(bp + 96)), bp+4+16, uintptr(0), bp, bp+4+20, uintptr(0), uintptr(0), bp+4+24, bp+4+76)
|
|
if rc != SQLITE_OK {
|
|
break
|
|
}
|
|
i = 0
|
|
for {
|
|
if !(i < (**(**TSessionApplyCtx)(__ccgo_up(bp + 4))).FnCol) {
|
|
break
|
|
}
|
|
if **(**Tu8)(__ccgo_up((**(**TSessionApplyCtx)(__ccgo_up(bp + 4))).FabPK + uintptr(i))) != 0 {
|
|
nMinCol = i + int32(1)
|
|
}
|
|
goto _1
|
|
_1:
|
|
;
|
|
i = i + 1
|
|
}
|
|
if (**(**TSessionApplyCtx)(__ccgo_up(bp + 4))).FnCol == 0 {
|
|
schemaMismatch = int32(1)
|
|
Xsqlite3_log(tls, int32(SQLITE_SCHEMA), __ccgo_ts+36571, libc.VaList(bp+224, **(**uintptr)(__ccgo_up(bp))))
|
|
} else {
|
|
if (**(**TSessionApplyCtx)(__ccgo_up(bp + 4))).FnCol < **(**int32)(__ccgo_up(bp + 88)) {
|
|
schemaMismatch = int32(1)
|
|
Xsqlite3_log(tls, int32(SQLITE_SCHEMA), __ccgo_ts+36615, libc.VaList(bp+224, **(**uintptr)(__ccgo_up(bp)), (**(**TSessionApplyCtx)(__ccgo_up(bp + 4))).FnCol, **(**int32)(__ccgo_up(bp + 88))))
|
|
} else {
|
|
if **(**int32)(__ccgo_up(bp + 88)) < nMinCol || libc.Xmemcmp(tls, (**(**TSessionApplyCtx)(__ccgo_up(bp + 4))).FabPK, **(**uintptr)(__ccgo_up(bp + 100)), libc.Uint32FromInt32(**(**int32)(__ccgo_up(bp + 88)))) != 0 {
|
|
schemaMismatch = int32(1)
|
|
Xsqlite3_log(tls, int32(SQLITE_SCHEMA), __ccgo_ts+36686, libc.VaList(bp+224, **(**uintptr)(__ccgo_up(bp))))
|
|
} else {
|
|
(**(**TSessionApplyCtx)(__ccgo_up(bp + 4))).FnCol = **(**int32)(__ccgo_up(bp + 88))
|
|
if 0 == Xsqlite3_stricmp(tls, **(**uintptr)(__ccgo_up(bp)), __ccgo_ts+12835) {
|
|
v2 = _sessionStat1Sql(tls, db, bp+4)
|
|
rc = v2
|
|
if v2 != 0 {
|
|
break
|
|
}
|
|
(**(**TSessionApplyCtx)(__ccgo_up(bp + 4))).FbStat1 = int32(1)
|
|
} else {
|
|
v2 = _sessionSelectRow(tls, db, **(**uintptr)(__ccgo_up(bp)), bp+4)
|
|
rc = v2
|
|
if v5 = v2 != 0; !v5 {
|
|
v3 = _sessionDeleteRow(tls, db, **(**uintptr)(__ccgo_up(bp)), bp+4)
|
|
rc = v3
|
|
}
|
|
if v7 = v5 || v3 != 0; !v7 {
|
|
v4 = _sessionInsertRow(tls, db, **(**uintptr)(__ccgo_up(bp)), bp+4)
|
|
rc = v4
|
|
}
|
|
if v7 || v4 != 0 {
|
|
break
|
|
}
|
|
(**(**TSessionApplyCtx)(__ccgo_up(bp + 4))).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+4, __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+4, __ccgo_fp_xConflict, pCtx)
|
|
}
|
|
if rc == SQLITE_OK {
|
|
Xsqlite3_db_status(tls, db, int32(SQLITE_DBSTATUS_DEFERRED_FKS), bp+104, bp+108, 0)
|
|
if **(**int32)(__ccgo_up(bp + 104)) != 0 {
|
|
res = int32(SQLITE_CHANGESET_ABORT)
|
|
libc.Xmemset(tls, bp+112, 0, uint32(100))
|
|
(**(**Tsqlite3_changeset_iter)(__ccgo_up(bp + 112))).FnCol = **(**int32)(__ccgo_up(bp + 104))
|
|
res = (*(*func(*libc.TLS, uintptr, int32, uintptr) int32)(unsafe.Pointer(&struct{ uintptr }{__ccgo_fp_xConflict})))(tls, pCtx, int32(SQLITE_CHANGESET_FOREIGN_KEY), bp+112)
|
|
if res != SQLITE_CHANGESET_OMIT {
|
|
rc = int32(SQLITE_CONSTRAINT)
|
|
}
|
|
}
|
|
}
|
|
rc2 = Xsqlite3_exec(tls, db, __ccgo_ts+36746, 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+36776, uintptr(0), uintptr(0), uintptr(0))
|
|
}
|
|
if rc != SQLITE_OK {
|
|
Xsqlite3_exec(tls, db, __ccgo_ts+36800, uintptr(0), uintptr(0), uintptr(0))
|
|
Xsqlite3_exec(tls, db, __ccgo_ts+36776, uintptr(0), uintptr(0), uintptr(0))
|
|
}
|
|
}
|
|
if rc == SQLITE_OK && bPatchset == 0 && (**(**TSessionApplyCtx)(__ccgo_up(bp + 4))).FbRebase != 0 {
|
|
**(**uintptr)(__ccgo_up(ppRebase)) = (**(**TSessionApplyCtx)(__ccgo_up(bp + 4))).Frebase.FaBuf
|
|
**(**int32)(__ccgo_up(pnRebase)) = (**(**TSessionApplyCtx)(__ccgo_up(bp + 4))).Frebase.FnBuf
|
|
(**(**TSessionApplyCtx)(__ccgo_up(bp + 4))).Frebase.FaBuf = uintptr(0)
|
|
}
|
|
_sessionUpdateFree(tls, bp+4)
|
|
Xsqlite3_finalize(tls, (**(**TSessionApplyCtx)(__ccgo_up(bp + 4))).FpInsert)
|
|
Xsqlite3_finalize(tls, (**(**TSessionApplyCtx)(__ccgo_up(bp + 4))).FpDelete)
|
|
Xsqlite3_finalize(tls, (**(**TSessionApplyCtx)(__ccgo_up(bp + 4))).FpSelect)
|
|
Xsqlite3_free(tls, (**(**TSessionApplyCtx)(__ccgo_up(bp + 4))).FazCol) /* cast works around VC++ bug */
|
|
Xsqlite3_free(tls, (**(**TSessionApplyCtx)(__ccgo_up(bp + 4))).Fconstraints.FaBuf)
|
|
Xsqlite3_free(tls, (**(**TSessionApplyCtx)(__ccgo_up(bp + 4))).Frebase.FaBuf)
|
|
if flags&int32(SQLITE_CHANGESETAPPLY_FKNOACTION) != 0 && savedFlag == uint64(0) {
|
|
**(**Tu64)(__ccgo_up(db + 28)) &= ^(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 + 4))).FzErr)
|
|
Xsqlite3_free(tls, (**(**TSessionApplyCtx)(__ccgo_up(bp + 4))).FzErr)
|
|
Xsqlite3_mutex_leave(tls, Xsqlite3_db_mutex(tls, db))
|
|
return rc
|
|
}
|
|
|
|
// C documentation
|
|
//
|
|
// /*
|
|
// ** Add a new column to the table currently being constructed.
|
|
// **
|
|
// ** The parser calls this routine once for each column declaration
|
|
// ** in a CREATE TABLE statement. sqlite3StartTable() gets called
|
|
// ** first to get things going. Then this routine is called for each
|
|
// ** column.
|
|
// */
|
|
func _sqlite3AddColumn(tls *libc.TLS, pParse uintptr, _sName TToken, _sType TToken) {
|
|
bp := tls.Alloc(32)
|
|
defer tls.Free(32)
|
|
*(*TToken)(unsafe.Pointer(bp)) = _sName
|
|
*(*TToken)(unsafe.Pointer(bp + 8)) = _sType
|
|
var aNew, db, p, pCol, z, zType, v1 uintptr
|
|
var affinity int8
|
|
var eType, h, szEst Tu8
|
|
var i int32
|
|
_, _, _, _, _, _, _, _, _, _, _, _ = aNew, affinity, db, eType, h, i, p, pCol, szEst, z, zType, v1
|
|
db = (*TParse)(unsafe.Pointer(pParse)).Fdb
|
|
eType = uint8(COLTYPE_CUSTOM)
|
|
szEst = uint8(1)
|
|
affinity = int8(SQLITE_AFF_BLOB)
|
|
v1 = (*TParse)(unsafe.Pointer(pParse)).FpNewTable
|
|
p = v1
|
|
if v1 == uintptr(0) {
|
|
return
|
|
}
|
|
if int32((*TTable)(unsafe.Pointer(p)).FnCol)+int32(1) > **(**int32)(__ccgo_up(db + 116 + 2*4)) {
|
|
_sqlite3ErrorMsg(tls, pParse, __ccgo_ts+13958, libc.VaList(bp+24, (*TTable)(unsafe.Pointer(p)).FzName))
|
|
return
|
|
}
|
|
if !(libc.Int32FromUint8((*TParse)(unsafe.Pointer(pParse)).FeParseMode) >= libc.Int32FromInt32(PARSE_MODE_RENAME)) {
|
|
_sqlite3DequoteToken(tls, bp)
|
|
}
|
|
/* Because keywords GENERATE ALWAYS can be converted into identifiers
|
|
** by the parser, we can sometimes end up with a typename that ends
|
|
** with "generated always". Check for this case and omit the surplus
|
|
** text. */
|
|
if (**(**TToken)(__ccgo_up(bp + 8))).Fn >= uint32(16) && Xsqlite3_strnicmp(tls, (**(**TToken)(__ccgo_up(bp + 8))).Fz+uintptr((**(**TToken)(__ccgo_up(bp + 8))).Fn-libc.Uint32FromInt32(6)), __ccgo_ts+13981, int32(6)) == 0 {
|
|
(**(**TToken)(__ccgo_up(bp + 8))).Fn -= uint32(6)
|
|
for (**(**TToken)(__ccgo_up(bp + 8))).Fn > uint32(0) && libc.Int32FromUint8(_sqlite3CtypeMap[libc.Uint8FromInt8(**(**int8)(__ccgo_up((**(**TToken)(__ccgo_up(bp + 8))).Fz + uintptr((**(**TToken)(__ccgo_up(bp + 8))).Fn-uint32(1)))))])&int32(0x01) != 0 {
|
|
(**(**TToken)(__ccgo_up(bp + 8))).Fn = (**(**TToken)(__ccgo_up(bp + 8))).Fn - 1
|
|
}
|
|
if (**(**TToken)(__ccgo_up(bp + 8))).Fn >= uint32(9) && Xsqlite3_strnicmp(tls, (**(**TToken)(__ccgo_up(bp + 8))).Fz+uintptr((**(**TToken)(__ccgo_up(bp + 8))).Fn-libc.Uint32FromInt32(9)), __ccgo_ts+13988, int32(9)) == 0 {
|
|
(**(**TToken)(__ccgo_up(bp + 8))).Fn -= uint32(9)
|
|
for (**(**TToken)(__ccgo_up(bp + 8))).Fn > uint32(0) && libc.Int32FromUint8(_sqlite3CtypeMap[libc.Uint8FromInt8(**(**int8)(__ccgo_up((**(**TToken)(__ccgo_up(bp + 8))).Fz + uintptr((**(**TToken)(__ccgo_up(bp + 8))).Fn-uint32(1)))))])&int32(0x01) != 0 {
|
|
(**(**TToken)(__ccgo_up(bp + 8))).Fn = (**(**TToken)(__ccgo_up(bp + 8))).Fn - 1
|
|
}
|
|
}
|
|
}
|
|
/* Check for standard typenames. For standard typenames we will
|
|
** set the Column.eType field rather than storing the typename after
|
|
** the column name, in order to save space. */
|
|
if (**(**TToken)(__ccgo_up(bp + 8))).Fn >= uint32(3) {
|
|
_sqlite3DequoteToken(tls, bp+8)
|
|
i = 0
|
|
for {
|
|
if !(i < int32(SQLITE_N_STDTYPE)) {
|
|
break
|
|
}
|
|
if (**(**TToken)(__ccgo_up(bp + 8))).Fn == uint32(_sqlite3StdTypeLen[i]) && Xsqlite3_strnicmp(tls, (**(**TToken)(__ccgo_up(bp + 8))).Fz, _sqlite3StdType[i], libc.Int32FromUint32((**(**TToken)(__ccgo_up(bp + 8))).Fn)) == 0 {
|
|
(**(**TToken)(__ccgo_up(bp + 8))).Fn = uint32(0)
|
|
eType = libc.Uint8FromInt32(i + int32(1))
|
|
affinity = _sqlite3StdTypeAffinity[i]
|
|
if int32(affinity) <= int32(SQLITE_AFF_TEXT) {
|
|
szEst = uint8(5)
|
|
}
|
|
break
|
|
}
|
|
goto _2
|
|
_2:
|
|
;
|
|
i = i + 1
|
|
}
|
|
}
|
|
z = _sqlite3DbMallocRaw(tls, db, libc.Uint64FromInt64(libc.Int64FromUint32((**(**TToken)(__ccgo_up(bp))).Fn)+int64(1)+libc.Int64FromUint32((**(**TToken)(__ccgo_up(bp + 8))).Fn)+libc.BoolInt64((**(**TToken)(__ccgo_up(bp + 8))).Fn > libc.Uint32FromInt32(0))))
|
|
if z == uintptr(0) {
|
|
return
|
|
}
|
|
if libc.Int32FromUint8((*TParse)(unsafe.Pointer(pParse)).FeParseMode) >= int32(PARSE_MODE_RENAME) {
|
|
_sqlite3RenameTokenMap(tls, pParse, z, bp)
|
|
}
|
|
libc.Xmemcpy(tls, z, (**(**TToken)(__ccgo_up(bp))).Fz, (**(**TToken)(__ccgo_up(bp))).Fn)
|
|
**(**int8)(__ccgo_up(z + uintptr((**(**TToken)(__ccgo_up(bp))).Fn))) = 0
|
|
_sqlite3Dequote(tls, z)
|
|
if (*TTable)(unsafe.Pointer(p)).FnCol != 0 && _sqlite3ColumnIndex(tls, p, z) >= 0 {
|
|
_sqlite3ErrorMsg(tls, pParse, __ccgo_ts+13998, libc.VaList(bp+24, z))
|
|
_sqlite3DbFree(tls, db, z)
|
|
return
|
|
}
|
|
aNew = _sqlite3DbRealloc(tls, db, (*TTable)(unsafe.Pointer(p)).FaCol, libc.Uint64FromInt64((int64((*TTable)(unsafe.Pointer(p)).FnCol)+int64(1))*int64(12)))
|
|
if aNew == uintptr(0) {
|
|
_sqlite3DbFree(tls, db, z)
|
|
return
|
|
}
|
|
(*TTable)(unsafe.Pointer(p)).FaCol = aNew
|
|
pCol = (*TTable)(unsafe.Pointer(p)).FaCol + uintptr((*TTable)(unsafe.Pointer(p)).FnCol)*12
|
|
libc.Xmemset(tls, pCol, 0, uint32(12))
|
|
(*TColumn)(unsafe.Pointer(pCol)).FzCnName = z
|
|
(*TColumn)(unsafe.Pointer(pCol)).FhName = _sqlite3StrIHash(tls, z)
|
|
if (**(**TToken)(__ccgo_up(bp + 8))).Fn == uint32(0) {
|
|
/* If there is no type specified, columns have the default affinity
|
|
** 'BLOB' with a default size of 4 bytes. */
|
|
(*TColumn)(unsafe.Pointer(pCol)).Faffinity = affinity
|
|
libc.SetBitFieldPtr8Uint32(pCol+4, uint32(eType), 4, 0xf0)
|
|
(*TColumn)(unsafe.Pointer(pCol)).FszEst = szEst
|
|
} else {
|
|
zType = z + uintptr(_sqlite3Strlen30(tls, z)) + uintptr(1)
|
|
libc.Xmemcpy(tls, zType, (**(**TToken)(__ccgo_up(bp + 8))).Fz, (**(**TToken)(__ccgo_up(bp + 8))).Fn)
|
|
**(**int8)(__ccgo_up(zType + uintptr((**(**TToken)(__ccgo_up(bp + 8))).Fn))) = 0
|
|
_sqlite3Dequote(tls, zType)
|
|
(*TColumn)(unsafe.Pointer(pCol)).Faffinity = _sqlite3AffinityType(tls, zType, pCol)
|
|
v1 = pCol + 10
|
|
*(*Tu16)(unsafe.Pointer(v1)) = Tu16(int32(*(*Tu16)(unsafe.Pointer(v1))) | libc.Int32FromInt32(COLFLAG_HASTYPE))
|
|
}
|
|
if int32((*TTable)(unsafe.Pointer(p)).FnCol) <= int32(0xff) {
|
|
h = uint8(uint32((*TColumn)(unsafe.Pointer(pCol)).FhName) % uint32(16))
|
|
**(**Tu8)(__ccgo_up(p + 64 + uintptr(h))) = libc.Uint8FromInt16((*TTable)(unsafe.Pointer(p)).FnCol)
|
|
}
|
|
(*TTable)(unsafe.Pointer(p)).FnCol = (*TTable)(unsafe.Pointer(p)).FnCol + 1
|
|
(*TTable)(unsafe.Pointer(p)).FnNVCol = (*TTable)(unsafe.Pointer(p)).FnNVCol + 1
|
|
(*(*struct {
|
|
FaddrCrTab int32
|
|
FregRowid int32
|
|
FregRoot int32
|
|
FconstraintName TToken
|
|
})(unsafe.Pointer(pParse + 188))).FconstraintName.Fn = uint32(0)
|
|
}
|
|
|
|
// C documentation
|
|
//
|
|
// /*
|
|
// ** This function is called by the parser upon parsing an
|
|
// **
|
|
// ** ALTER TABLE pSrc DROP COLUMN pName
|
|
// **
|
|
// ** statement. Argument pSrc contains the possibly qualified name of the
|
|
// ** table being edited, and token pName the name of the column to drop.
|
|
// */
|
|
func _sqlite3AlterDropColumn(tls *libc.TLS, pParse uintptr, pSrc uintptr, pName uintptr) {
|
|
bp := tls.Alloc(48)
|
|
defer tls.Free(48)
|
|
var addr, i, iCol, iColPos, iCur, iDb, iPos, nField, reg, regOut, regRec, v2 int32
|
|
var aff int8
|
|
var db, pPk, pTab, v, zCol, zDb, v1 uintptr
|
|
_, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _ = addr, aff, db, i, iCol, iColPos, iCur, iDb, iPos, nField, pPk, pTab, reg, regOut, regRec, v, zCol, zDb, v1, v2
|
|
db = (*TParse)(unsafe.Pointer(pParse)).Fdb /* Database containing pTab ("main" etc.) */
|
|
zCol = uintptr(0) /* Index of column zCol in pTab->aCol[] */
|
|
/* Look up the table being altered. */
|
|
if (*Tsqlite3)(unsafe.Pointer(db)).FmallocFailed != 0 {
|
|
goto exit_drop_column
|
|
}
|
|
pTab = _sqlite3LocateTableItem(tls, pParse, uint32(0), pSrc+8)
|
|
if !(pTab != 0) {
|
|
goto exit_drop_column
|
|
}
|
|
/* Make sure this is not an attempt to ALTER a view, virtual table or
|
|
** system table. */
|
|
if SQLITE_OK != _isAlterableTable(tls, pParse, pTab) {
|
|
goto exit_drop_column
|
|
}
|
|
if SQLITE_OK != _isRealTable(tls, pParse, pTab, int32(1)) {
|
|
goto exit_drop_column
|
|
}
|
|
/* Find the index of the column being dropped. */
|
|
zCol = _sqlite3NameFromToken(tls, db, pName)
|
|
if zCol == uintptr(0) {
|
|
goto exit_drop_column
|
|
}
|
|
iCol = _sqlite3ColumnIndex(tls, pTab, zCol)
|
|
if iCol < 0 {
|
|
_sqlite3ErrorMsg(tls, pParse, __ccgo_ts+11209, libc.VaList(bp+8, pName))
|
|
goto exit_drop_column
|
|
}
|
|
/* Do not allow the user to drop a PRIMARY KEY column or a column
|
|
** constrained by a UNIQUE constraint. */
|
|
if libc.Int32FromUint16((**(**TColumn)(__ccgo_up((*TTable)(unsafe.Pointer(pTab)).FaCol + uintptr(iCol)*12))).FcolFlags)&(libc.Int32FromInt32(COLFLAG_PRIMKEY)|libc.Int32FromInt32(COLFLAG_UNIQUE)) != 0 {
|
|
if libc.Int32FromUint16((**(**TColumn)(__ccgo_up((*TTable)(unsafe.Pointer(pTab)).FaCol + uintptr(iCol)*12))).FcolFlags)&int32(COLFLAG_PRIMKEY) != 0 {
|
|
v1 = __ccgo_ts + 11594
|
|
} else {
|
|
v1 = __ccgo_ts + 5833
|
|
}
|
|
_sqlite3ErrorMsg(tls, pParse, __ccgo_ts+11606, libc.VaList(bp+8, v1, zCol))
|
|
goto exit_drop_column
|
|
}
|
|
/* Do not allow the number of columns to go to zero */
|
|
if int32((*TTable)(unsafe.Pointer(pTab)).FnCol) <= int32(1) {
|
|
_sqlite3ErrorMsg(tls, pParse, __ccgo_ts+11634, libc.VaList(bp+8, zCol))
|
|
goto exit_drop_column
|
|
}
|
|
/* Edit the sqlite_schema table */
|
|
iDb = _sqlite3SchemaToIndex(tls, db, (*TTable)(unsafe.Pointer(pTab)).FpSchema)
|
|
zDb = (**(**TDb)(__ccgo_up((*Tsqlite3)(unsafe.Pointer(db)).FaDb + uintptr(iDb)*16))).FzDbSName
|
|
/* Invoke the authorization callback. */
|
|
if _sqlite3AuthCheck(tls, pParse, int32(SQLITE_ALTER_TABLE), zDb, (*TTable)(unsafe.Pointer(pTab)).FzName, zCol) != 0 {
|
|
goto exit_drop_column
|
|
}
|
|
_renameTestSchema(tls, pParse, zDb, libc.BoolInt32(iDb == int32(1)), __ccgo_ts+1702, 0)
|
|
_renameFixQuotes(tls, pParse, zDb, libc.BoolInt32(iDb == int32(1)))
|
|
_sqlite3NestedParse(tls, pParse, __ccgo_ts+11682, libc.VaList(bp+8, zDb, iDb, iCol, (*TTable)(unsafe.Pointer(pTab)).FzName))
|
|
/* Drop and reload the database schema. */
|
|
_renameReloadSchema(tls, pParse, iDb, uint16(INITFLAG_AlterDrop))
|
|
_renameTestSchema(tls, pParse, zDb, libc.BoolInt32(iDb == int32(1)), __ccgo_ts+11803, int32(1))
|
|
/* Edit rows of table on disk */
|
|
if (*TParse)(unsafe.Pointer(pParse)).FnErr == 0 && libc.Int32FromUint16((**(**TColumn)(__ccgo_up((*TTable)(unsafe.Pointer(pTab)).FaCol + uintptr(iCol)*12))).FcolFlags)&int32(COLFLAG_VIRTUAL) == 0 {
|
|
pPk = uintptr(0)
|
|
nField = 0
|
|
v = _sqlite3GetVdbe(tls, pParse)
|
|
v1 = pParse + 44
|
|
v2 = *(*int32)(unsafe.Pointer(v1))
|
|
*(*int32)(unsafe.Pointer(v1)) = *(*int32)(unsafe.Pointer(v1)) + 1
|
|
iCur = v2
|
|
_sqlite3OpenTable(tls, pParse, iCur, iDb, pTab, int32(OP_OpenWrite))
|
|
addr = _sqlite3VdbeAddOp1(tls, v, int32(OP_Rewind), iCur)
|
|
v1 = pParse + 48
|
|
*(*int32)(unsafe.Pointer(v1)) = *(*int32)(unsafe.Pointer(v1)) + 1
|
|
v2 = *(*int32)(unsafe.Pointer(v1))
|
|
reg = v2
|
|
if (*TTable)(unsafe.Pointer(pTab)).FtabFlags&uint32(TF_WithoutRowid) == uint32(0) {
|
|
_sqlite3VdbeAddOp2(tls, v, int32(OP_Rowid), iCur, reg)
|
|
**(**int32)(__ccgo_up(pParse + 48)) += int32((*TTable)(unsafe.Pointer(pTab)).FnCol)
|
|
} else {
|
|
pPk = _sqlite3PrimaryKeyIndex(tls, pTab)
|
|
**(**int32)(__ccgo_up(pParse + 48)) += libc.Int32FromUint16((*TIndex)(unsafe.Pointer(pPk)).FnColumn)
|
|
i = 0
|
|
for {
|
|
if !(i < libc.Int32FromUint16((*TIndex)(unsafe.Pointer(pPk)).FnKeyCol)) {
|
|
break
|
|
}
|
|
_sqlite3VdbeAddOp3(tls, v, int32(OP_Column), iCur, i, reg+i+int32(1))
|
|
goto _6
|
|
_6:
|
|
;
|
|
i = i + 1
|
|
}
|
|
nField = libc.Int32FromUint16((*TIndex)(unsafe.Pointer(pPk)).FnKeyCol)
|
|
}
|
|
v1 = pParse + 48
|
|
*(*int32)(unsafe.Pointer(v1)) = *(*int32)(unsafe.Pointer(v1)) + 1
|
|
v2 = *(*int32)(unsafe.Pointer(v1))
|
|
regRec = v2
|
|
i = 0
|
|
for {
|
|
if !(i < int32((*TTable)(unsafe.Pointer(pTab)).FnCol)) {
|
|
break
|
|
}
|
|
if i != iCol && libc.Int32FromUint16((**(**TColumn)(__ccgo_up((*TTable)(unsafe.Pointer(pTab)).FaCol + uintptr(i)*12))).FcolFlags)&int32(COLFLAG_VIRTUAL) == 0 {
|
|
if pPk != 0 {
|
|
iPos = _sqlite3TableColumnToIndex(tls, pPk, i)
|
|
iColPos = _sqlite3TableColumnToIndex(tls, pPk, iCol)
|
|
if iPos < libc.Int32FromUint16((*TIndex)(unsafe.Pointer(pPk)).FnKeyCol) {
|
|
goto _9
|
|
}
|
|
regOut = reg + int32(1) + iPos - libc.BoolInt32(iPos > iColPos)
|
|
} else {
|
|
regOut = reg + int32(1) + nField
|
|
}
|
|
if i == int32((*TTable)(unsafe.Pointer(pTab)).FiPKey) {
|
|
_sqlite3VdbeAddOp2(tls, v, int32(OP_Null), 0, regOut)
|
|
} else {
|
|
aff = (**(**TColumn)(__ccgo_up((*TTable)(unsafe.Pointer(pTab)).FaCol + uintptr(i)*12))).Faffinity
|
|
if int32(aff) == int32(SQLITE_AFF_REAL) {
|
|
(**(**TColumn)(__ccgo_up((*TTable)(unsafe.Pointer(pTab)).FaCol + uintptr(i)*12))).Faffinity = int8(SQLITE_AFF_NUMERIC)
|
|
}
|
|
_sqlite3ExprCodeGetColumnOfTable(tls, v, pTab, iCur, i, regOut)
|
|
(**(**TColumn)(__ccgo_up((*TTable)(unsafe.Pointer(pTab)).FaCol + uintptr(i)*12))).Faffinity = aff
|
|
}
|
|
nField = nField + 1
|
|
}
|
|
goto _9
|
|
_9:
|
|
;
|
|
i = i + 1
|
|
}
|
|
if nField == 0 {
|
|
/* dbsqlfuzz 5f09e7bcc78b4954d06bf9f2400d7715f48d1fef */
|
|
(*TParse)(unsafe.Pointer(pParse)).FnMem = (*TParse)(unsafe.Pointer(pParse)).FnMem + 1
|
|
_sqlite3VdbeAddOp2(tls, v, int32(OP_Null), 0, reg+int32(1))
|
|
nField = int32(1)
|
|
}
|
|
_sqlite3VdbeAddOp3(tls, v, int32(OP_MakeRecord), reg+int32(1), nField, regRec)
|
|
if pPk != 0 {
|
|
_sqlite3VdbeAddOp4Int(tls, v, int32(OP_IdxInsert), iCur, regRec, reg+int32(1), libc.Int32FromUint16((*TIndex)(unsafe.Pointer(pPk)).FnKeyCol))
|
|
} else {
|
|
_sqlite3VdbeAddOp3(tls, v, int32(OP_Insert), iCur, regRec, reg)
|
|
}
|
|
_sqlite3VdbeChangeP5(tls, v, uint16(OPFLAG_SAVEPOSITION))
|
|
_sqlite3VdbeAddOp2(tls, v, int32(OP_Next), iCur, addr+int32(1))
|
|
_sqlite3VdbeJumpHere(tls, v, addr)
|
|
}
|
|
goto exit_drop_column
|
|
exit_drop_column:
|
|
;
|
|
_sqlite3DbFree(tls, db, zCol)
|
|
_sqlite3SrcListDelete(tls, db, pSrc)
|
|
}
|
|
|
|
// C documentation
|
|
//
|
|
// /*
|
|
// ** This function is called after an "ALTER TABLE ... ADD" statement
|
|
// ** has been parsed. Argument pColDef contains the text of the new
|
|
// ** column definition.
|
|
// **
|
|
// ** The Table structure pParse->pNewTable was extended to include
|
|
// ** the new column during parsing.
|
|
// */
|
|
func _sqlite3AlterFinishAddColumn(tls *libc.TLS, pParse uintptr, pColDef uintptr) {
|
|
bp := tls.Alloc(64)
|
|
defer tls.Free(64)
|
|
var db, pCol, pDflt, pNew, pTab, v, zCol, zDb, zEnd, zTab, v1 uintptr
|
|
var iDb, r1, rc int32
|
|
var _ /* pVal at bp+0 */ uintptr
|
|
_, _, _, _, _, _, _, _, _, _, _, _, _, _ = db, iDb, pCol, pDflt, pNew, pTab, r1, rc, v, zCol, zDb, zEnd, zTab, v1 /* Temporary registers */
|
|
db = (*TParse)(unsafe.Pointer(pParse)).Fdb
|
|
if (*TParse)(unsafe.Pointer(pParse)).FnErr != 0 {
|
|
return
|
|
}
|
|
pNew = (*TParse)(unsafe.Pointer(pParse)).FpNewTable
|
|
iDb = _sqlite3SchemaToIndex(tls, db, (*TTable)(unsafe.Pointer(pNew)).FpSchema)
|
|
zDb = (**(**TDb)(__ccgo_up((*Tsqlite3)(unsafe.Pointer(db)).FaDb + uintptr(iDb)*16))).FzDbSName
|
|
zTab = (*TTable)(unsafe.Pointer(pNew)).FzName + 16 /* Skip the "sqlite_altertab_" prefix on the name */
|
|
pCol = (*TTable)(unsafe.Pointer(pNew)).FaCol + uintptr(int32((*TTable)(unsafe.Pointer(pNew)).FnCol)-int32(1))*12
|
|
pDflt = _sqlite3ColumnExpr(tls, pNew, pCol)
|
|
pTab = _sqlite3FindTable(tls, db, zTab, zDb)
|
|
/* Invoke the authorization callback. */
|
|
if _sqlite3AuthCheck(tls, pParse, int32(SQLITE_ALTER_TABLE), zDb, (*TTable)(unsafe.Pointer(pTab)).FzName, uintptr(0)) != 0 {
|
|
return
|
|
}
|
|
/* Check that the new column is not specified as PRIMARY KEY or UNIQUE.
|
|
** If there is a NOT NULL constraint, then the default value for the
|
|
** column must not be NULL.
|
|
*/
|
|
if libc.Int32FromUint16((*TColumn)(unsafe.Pointer(pCol)).FcolFlags)&int32(COLFLAG_PRIMKEY) != 0 {
|
|
_sqlite3ErrorMsg(tls, pParse, __ccgo_ts+10291, 0)
|
|
return
|
|
}
|
|
if (*TTable)(unsafe.Pointer(pNew)).FpIndex != 0 {
|
|
_sqlite3ErrorMsg(tls, pParse, __ccgo_ts+10323, 0)
|
|
return
|
|
}
|
|
if libc.Int32FromUint16((*TColumn)(unsafe.Pointer(pCol)).FcolFlags)&int32(COLFLAG_GENERATED) == 0 {
|
|
/* If the default value for the new column was specified with a
|
|
** literal NULL, then set pDflt to 0. This simplifies checking
|
|
** for an SQL NULL default below.
|
|
*/
|
|
if pDflt != 0 && libc.Int32FromUint8((*TExpr)(unsafe.Pointer((*TExpr)(unsafe.Pointer(pDflt)).FpLeft)).Fop) == int32(TK_NULL) {
|
|
pDflt = uintptr(0)
|
|
}
|
|
if (*Tsqlite3)(unsafe.Pointer(db)).Fflags&uint64(SQLITE_ForeignKeys) != 0 && (*(*struct {
|
|
FaddColOffset int32
|
|
FpFKey uintptr
|
|
FpDfltList uintptr
|
|
})(unsafe.Pointer(pNew + 44))).FpFKey != 0 && pDflt != 0 {
|
|
_sqlite3ErrorIfNotEmpty(tls, pParse, zDb, zTab, __ccgo_ts+10350)
|
|
}
|
|
if int32(uint32(*(*uint8)(unsafe.Pointer(pCol + 4))&0xf>>0)) != 0 && !(pDflt != 0) {
|
|
_sqlite3ErrorIfNotEmpty(tls, pParse, zDb, zTab, __ccgo_ts+10409)
|
|
}
|
|
/* Ensure the default expression is something that sqlite3ValueFromExpr()
|
|
** can handle (i.e. not CURRENT_TIME etc.)
|
|
*/
|
|
if pDflt != 0 {
|
|
**(**uintptr)(__ccgo_up(bp)) = uintptr(0)
|
|
rc = _sqlite3ValueFromExpr(tls, db, pDflt, uint8(SQLITE_UTF8), uint8(SQLITE_AFF_BLOB), bp)
|
|
if rc != SQLITE_OK {
|
|
return
|
|
}
|
|
if !(**(**uintptr)(__ccgo_up(bp)) != 0) {
|
|
_sqlite3ErrorIfNotEmpty(tls, pParse, zDb, zTab, __ccgo_ts+10462)
|
|
}
|
|
_sqlite3ValueFree(tls, **(**uintptr)(__ccgo_up(bp)))
|
|
}
|
|
} else {
|
|
if libc.Int32FromUint16((*TColumn)(unsafe.Pointer(pCol)).FcolFlags)&int32(COLFLAG_STORED) != 0 {
|
|
_sqlite3ErrorIfNotEmpty(tls, pParse, zDb, zTab, __ccgo_ts+10508)
|
|
}
|
|
}
|
|
/* Modify the CREATE TABLE statement. */
|
|
zCol = _sqlite3DbStrNDup(tls, db, (*TToken)(unsafe.Pointer(pColDef)).Fz, uint64((*TToken)(unsafe.Pointer(pColDef)).Fn))
|
|
if zCol != 0 {
|
|
zEnd = zCol + uintptr((*TToken)(unsafe.Pointer(pColDef)).Fn-uint32(1))
|
|
for zEnd > zCol && (int32(**(**int8)(__ccgo_up(zEnd))) == int32(';') || libc.Int32FromUint8(_sqlite3CtypeMap[libc.Uint8FromInt8(**(**int8)(__ccgo_up(zEnd)))])&int32(0x01) != 0) {
|
|
v1 = zEnd
|
|
zEnd = zEnd - 1
|
|
**(**int8)(__ccgo_up(v1)) = int8('\000')
|
|
}
|
|
/* substr() operations on characters, but addColOffset is in bytes. So we
|
|
** have to use printf() to translate between these units: */
|
|
_sqlite3NestedParse(tls, pParse, __ccgo_ts+10535, libc.VaList(bp+16, zDb, (*(*struct {
|
|
FaddColOffset int32
|
|
FpFKey uintptr
|
|
FpDfltList uintptr
|
|
})(unsafe.Pointer(pNew + 44))).FaddColOffset, zCol, (*(*struct {
|
|
FaddColOffset int32
|
|
FpFKey uintptr
|
|
FpDfltList uintptr
|
|
})(unsafe.Pointer(pNew + 44))).FaddColOffset, zTab))
|
|
_sqlite3DbFree(tls, db, zCol)
|
|
}
|
|
v = _sqlite3GetVdbe(tls, pParse)
|
|
if v != 0 {
|
|
/* Make sure the schema version is at least 3. But do not upgrade
|
|
** from less than 3 to 4, as that will corrupt any preexisting DESC
|
|
** index.
|
|
*/
|
|
r1 = _sqlite3GetTempReg(tls, pParse)
|
|
_sqlite3VdbeAddOp3(tls, v, int32(OP_ReadCookie), iDb, r1, int32(BTREE_FILE_FORMAT))
|
|
_sqlite3VdbeUsesBtree(tls, v, iDb)
|
|
_sqlite3VdbeAddOp2(tls, v, int32(OP_AddImm), r1, -int32(2))
|
|
_sqlite3VdbeAddOp2(tls, v, int32(OP_IfPos), r1, _sqlite3VdbeCurrentAddr(tls, v)+int32(2))
|
|
_sqlite3VdbeAddOp3(tls, v, int32(OP_SetCookie), iDb, int32(BTREE_FILE_FORMAT), int32(3))
|
|
_sqlite3ReleaseTempReg(tls, pParse, r1)
|
|
/* Reload the table definition */
|
|
_renameReloadSchema(tls, pParse, iDb, uint16(INITFLAG_AlterAdd))
|
|
/* Verify that constraints are still satisfied */
|
|
if (*TTable)(unsafe.Pointer(pNew)).FpCheck != uintptr(0) || int32(uint32(*(*uint8)(unsafe.Pointer(pCol + 4))&0xf>>0)) != 0 && libc.Int32FromUint16((*TColumn)(unsafe.Pointer(pCol)).FcolFlags)&int32(COLFLAG_GENERATED) != 0 || (*TTable)(unsafe.Pointer(pTab)).FtabFlags&uint32(TF_Strict) != uint32(0) {
|
|
_sqlite3NestedParse(tls, pParse, __ccgo_ts+10681, libc.VaList(bp+16, zTab, zDb))
|
|
}
|
|
}
|
|
}
|
|
|
|
// C documentation
|
|
//
|
|
// /*
|
|
// ** Handles the following parser reduction:
|
|
// **
|
|
// ** cmd ::= ALTER TABLE pSrc RENAME COLUMN pOld TO pNew
|
|
// */
|
|
func _sqlite3AlterRenameColumn(tls *libc.TLS, pParse uintptr, pSrc uintptr, pOld uintptr, pNew uintptr) {
|
|
bp := tls.Alloc(80)
|
|
defer tls.Free(80)
|
|
var bQuote, iCol, iSchema int32
|
|
var db, pTab, zDb, zNew, zOld uintptr
|
|
_, _, _, _, _, _, _, _ = bQuote, db, iCol, iSchema, pTab, zDb, zNew, zOld
|
|
db = (*TParse)(unsafe.Pointer(pParse)).Fdb /* Index of column being renamed */
|
|
zOld = uintptr(0) /* Old column name */
|
|
zNew = uintptr(0) /* True to quote the new name */
|
|
/* Locate the table to be altered */
|
|
pTab = _sqlite3LocateTableItem(tls, pParse, uint32(0), pSrc+8)
|
|
if !(pTab != 0) {
|
|
goto exit_rename_column
|
|
}
|
|
/* Cannot alter a system table */
|
|
if SQLITE_OK != _isAlterableTable(tls, pParse, pTab) {
|
|
goto exit_rename_column
|
|
}
|
|
if SQLITE_OK != _isRealTable(tls, pParse, pTab, 0) {
|
|
goto exit_rename_column
|
|
}
|
|
/* Which schema holds the table to be altered */
|
|
iSchema = _sqlite3SchemaToIndex(tls, db, (*TTable)(unsafe.Pointer(pTab)).FpSchema)
|
|
zDb = (**(**TDb)(__ccgo_up((*Tsqlite3)(unsafe.Pointer(db)).FaDb + uintptr(iSchema)*16))).FzDbSName
|
|
/* Invoke the authorization callback. */
|
|
if _sqlite3AuthCheck(tls, pParse, int32(SQLITE_ALTER_TABLE), zDb, (*TTable)(unsafe.Pointer(pTab)).FzName, uintptr(0)) != 0 {
|
|
goto exit_rename_column
|
|
}
|
|
/* Make sure the old name really is a column name in the table to be
|
|
** altered. Set iCol to be the index of the column being renamed */
|
|
zOld = _sqlite3NameFromToken(tls, db, pOld)
|
|
if !(zOld != 0) {
|
|
goto exit_rename_column
|
|
}
|
|
iCol = _sqlite3ColumnIndex(tls, pTab, zOld)
|
|
if iCol < 0 {
|
|
_sqlite3ErrorMsg(tls, pParse, __ccgo_ts+11209, libc.VaList(bp+8, pOld))
|
|
goto exit_rename_column
|
|
}
|
|
/* Ensure the schema contains no double-quoted strings */
|
|
_renameTestSchema(tls, pParse, zDb, libc.BoolInt32(iSchema == int32(1)), __ccgo_ts+1702, 0)
|
|
_renameFixQuotes(tls, pParse, zDb, libc.BoolInt32(iSchema == int32(1)))
|
|
/* Do the rename operation using a recursive UPDATE statement that
|
|
** uses the sqlite_rename_column() SQL function to compute the new
|
|
** CREATE statement text for the sqlite_schema table.
|
|
*/
|
|
_sqlite3MayAbort(tls, pParse)
|
|
zNew = _sqlite3NameFromToken(tls, db, pNew)
|
|
if !(zNew != 0) {
|
|
goto exit_rename_column
|
|
}
|
|
bQuote = libc.Int32FromUint8(_sqlite3CtypeMap[libc.Uint8FromInt8(**(**int8)(__ccgo_up((*TToken)(unsafe.Pointer(pNew)).Fz)))]) & int32(0x80)
|
|
_sqlite3NestedParse(tls, pParse, __ccgo_ts+11230, libc.VaList(bp+8, zDb, zDb, (*TTable)(unsafe.Pointer(pTab)).FzName, iCol, zNew, bQuote, libc.BoolInt32(iSchema == int32(1)), (*TTable)(unsafe.Pointer(pTab)).FzName))
|
|
_sqlite3NestedParse(tls, pParse, __ccgo_ts+11412, libc.VaList(bp+8, zDb, (*TTable)(unsafe.Pointer(pTab)).FzName, iCol, zNew, bQuote))
|
|
/* Drop and reload the database schema. */
|
|
_renameReloadSchema(tls, pParse, iSchema, uint16(INITFLAG_AlterRename))
|
|
_renameTestSchema(tls, pParse, zDb, libc.BoolInt32(iSchema == int32(1)), __ccgo_ts+10240, int32(1))
|
|
goto exit_rename_column
|
|
exit_rename_column:
|
|
;
|
|
_sqlite3SrcListDelete(tls, db, pSrc)
|
|
_sqlite3DbFree(tls, db, zOld)
|
|
_sqlite3DbFree(tls, db, zNew)
|
|
return
|
|
}
|
|
|
|
// 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(80)
|
|
defer tls.Free(80)
|
|
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+4 */ 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+21838, 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 + 44)))
|
|
*(*uintptr)(unsafe.Pointer(pTableName + 8 + 44)) = 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*16))).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+4, pParse, iDb, __ccgo_ts+21884, **(**uintptr)(__ccgo_up(bp)))
|
|
if _sqlite3FixSrcList(tls, bp+4, 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+21892, 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+21933, 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+21884, (*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)*16))).FpSchema+40, zName) != 0 {
|
|
if !(noErr != 0) {
|
|
_sqlite3ErrorMsg(tls, pParse, __ccgo_ts+21973, libc.VaList(bp+64, **(**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+6758, int32(7)) == 0 {
|
|
_sqlite3ErrorMsg(tls, pParse, __ccgo_ts+21999, 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 + 22037
|
|
} else {
|
|
v1 = __ccgo_ts + 22044
|
|
}
|
|
_sqlite3ErrorMsg(tls, pParse, __ccgo_ts+22050, libc.VaList(bp+64, 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+22087, libc.VaList(bp+64, 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)*16))).FzDbSName
|
|
if isTemp != 0 {
|
|
v1 = (**(**TDb)(__ccgo_up((*Tsqlite3)(unsafe.Pointer(db)).FaDb + 1*16))).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 + 6766
|
|
} else {
|
|
v1 = __ccgo_ts + 6286
|
|
}
|
|
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(36))
|
|
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)*16))).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+172+8, libc.Uint32FromInt32(1), 0, 0x1)
|
|
}
|
|
goto trigger_cleanup
|
|
}
|
|
|
|
// C documentation
|
|
//
|
|
// /*
|
|
// ** This routine does a complete check of the given BTree file. aRoot[] is
|
|
// ** an array of pages numbers were each page number is the root page of
|
|
// ** a table. nRoot is the number of entries in aRoot.
|
|
// **
|
|
// ** A read-only or read-write transaction must be opened before calling
|
|
// ** this function.
|
|
// **
|
|
// ** Write the number of error seen in *pnErr. Except for some memory
|
|
// ** allocation errors, an error message held in memory obtained from
|
|
// ** malloc is returned if *pnErr is non-zero. If *pnErr==0 then NULL is
|
|
// ** returned. If a memory allocation error occurs, NULL is returned.
|
|
// **
|
|
// ** If the first entry in aRoot[] is 0, that indicates that the list of
|
|
// ** root pages is incomplete. This is a "partial integrity-check". This
|
|
// ** happens when performing an integrity check on a single table. The
|
|
// ** zero is skipped, of course. But in addition, the freelist checks
|
|
// ** and the checks to make sure every page is referenced are also skipped,
|
|
// ** since obviously it is not possible to know which pages are covered by
|
|
// ** the unverified btrees. Except, if aRoot[1] is 1, then the freelist
|
|
// ** checks are still performed.
|
|
// */
|
|
func _sqlite3BtreeIntegrityCheck(tls *libc.TLS, db uintptr, p uintptr, aRoot uintptr, aCnt uintptr, nRoot int32, mxErr int32, pnErr uintptr, pzOut uintptr) (r int32) {
|
|
bp := tls.Alloc(224)
|
|
defer tls.Free(224)
|
|
var bCkFreelist, bPartial int32
|
|
var i, mx, mxInHdr TPgno
|
|
var pBt uintptr
|
|
var savedDbFlags Tu64
|
|
var _ /* notUsed at bp+192 */ Ti64
|
|
var _ /* sCheck at bp+0 */ TIntegrityCk
|
|
var _ /* zErr at bp+88 */ [100]int8
|
|
_, _, _, _, _, _, _ = bCkFreelist, bPartial, i, mx, mxInHdr, pBt, savedDbFlags
|
|
pBt = (*TBtree)(unsafe.Pointer(p)).FpBt
|
|
savedDbFlags = (*Tsqlite3)(unsafe.Pointer((*TBtShared)(unsafe.Pointer(pBt)).Fdb)).Fflags
|
|
bPartial = 0 /* True if not checking all btrees */
|
|
bCkFreelist = int32(1) /* True to scan the freelist */
|
|
/* aRoot[0]==0 means this is a partial check */
|
|
if **(**TPgno)(__ccgo_up(aRoot)) == uint32(0) {
|
|
bPartial = int32(1)
|
|
if **(**TPgno)(__ccgo_up(aRoot + 1*4)) != uint32(1) {
|
|
bCkFreelist = 0
|
|
}
|
|
}
|
|
_sqlite3BtreeEnter(tls, p)
|
|
libc.Xmemset(tls, bp, 0, uint32(88))
|
|
(**(**TIntegrityCk)(__ccgo_up(bp))).Fdb = db
|
|
(**(**TIntegrityCk)(__ccgo_up(bp))).FpBt = pBt
|
|
(**(**TIntegrityCk)(__ccgo_up(bp))).FpPager = (*TBtShared)(unsafe.Pointer(pBt)).FpPager
|
|
(**(**TIntegrityCk)(__ccgo_up(bp))).FnCkPage = _btreePagecount(tls, (**(**TIntegrityCk)(__ccgo_up(bp))).FpBt)
|
|
(**(**TIntegrityCk)(__ccgo_up(bp))).FmxErr = mxErr
|
|
_sqlite3StrAccumInit(tls, bp+48, uintptr(0), bp+88, int32(100), int32(SQLITE_MAX_LENGTH))
|
|
(**(**TIntegrityCk)(__ccgo_up(bp))).FerrMsg.FprintfFlags = uint8(SQLITE_PRINTF_INTERNAL)
|
|
if (**(**TIntegrityCk)(__ccgo_up(bp))).FnCkPage == uint32(0) {
|
|
goto integrity_ck_cleanup
|
|
}
|
|
(**(**TIntegrityCk)(__ccgo_up(bp))).FaPgRef = _sqlite3MallocZero(tls, uint64((**(**TIntegrityCk)(__ccgo_up(bp))).FnCkPage/uint32(8)+uint32(1)))
|
|
if !((**(**TIntegrityCk)(__ccgo_up(bp))).FaPgRef != 0) {
|
|
_checkOom(tls, bp)
|
|
goto integrity_ck_cleanup
|
|
}
|
|
(**(**TIntegrityCk)(__ccgo_up(bp))).Fheap = _sqlite3PageMalloc(tls, libc.Int32FromUint32((*TBtShared)(unsafe.Pointer(pBt)).FpageSize))
|
|
if (**(**TIntegrityCk)(__ccgo_up(bp))).Fheap == uintptr(0) {
|
|
_checkOom(tls, bp)
|
|
goto integrity_ck_cleanup
|
|
}
|
|
i = libc.Uint32FromInt32(_sqlite3PendingByte)/(*TBtShared)(unsafe.Pointer(pBt)).FpageSize + libc.Uint32FromInt32(1)
|
|
if i <= (**(**TIntegrityCk)(__ccgo_up(bp))).FnCkPage {
|
|
_setPageReferenced(tls, bp, i)
|
|
}
|
|
/* Check the integrity of the freelist
|
|
*/
|
|
if bCkFreelist != 0 {
|
|
(**(**TIntegrityCk)(__ccgo_up(bp))).FzPfx = __ccgo_ts + 4964
|
|
_checkList(tls, bp, int32(1), _sqlite3Get4byte(tls, (*TMemPage)(unsafe.Pointer((*TBtShared)(unsafe.Pointer(pBt)).FpPage1)).FaData+32), _sqlite3Get4byte(tls, (*TMemPage)(unsafe.Pointer((*TBtShared)(unsafe.Pointer(pBt)).FpPage1)).FaData+36))
|
|
(**(**TIntegrityCk)(__ccgo_up(bp))).FzPfx = uintptr(0)
|
|
}
|
|
/* Check all the tables.
|
|
*/
|
|
if !(bPartial != 0) {
|
|
if (*TBtShared)(unsafe.Pointer(pBt)).FautoVacuum != 0 {
|
|
mx = uint32(0)
|
|
i = uint32(0)
|
|
for {
|
|
if !(libc.Int32FromUint32(i) < nRoot) {
|
|
break
|
|
}
|
|
if mx < **(**TPgno)(__ccgo_up(aRoot + uintptr(i)*4)) {
|
|
mx = **(**TPgno)(__ccgo_up(aRoot + uintptr(i)*4))
|
|
}
|
|
goto _1
|
|
_1:
|
|
;
|
|
i = i + 1
|
|
}
|
|
mxInHdr = _sqlite3Get4byte(tls, (*TMemPage)(unsafe.Pointer((*TBtShared)(unsafe.Pointer(pBt)).FpPage1)).FaData+52)
|
|
if mx != mxInHdr {
|
|
_checkAppendMsg(tls, bp, __ccgo_ts+4975, libc.VaList(bp+208, mx, mxInHdr))
|
|
}
|
|
} else {
|
|
if _sqlite3Get4byte(tls, (*TMemPage)(unsafe.Pointer((*TBtShared)(unsafe.Pointer(pBt)).FpPage1)).FaData+64) != uint32(0) {
|
|
_checkAppendMsg(tls, bp, __ccgo_ts+5020, 0)
|
|
}
|
|
}
|
|
}
|
|
**(**Tu64)(__ccgo_up((*TBtShared)(unsafe.Pointer(pBt)).Fdb + 28)) &= ^libc.Uint64FromInt32(SQLITE_CellSizeCk)
|
|
i = uint32(0)
|
|
for {
|
|
if !(libc.Int32FromUint32(i) < nRoot && (**(**TIntegrityCk)(__ccgo_up(bp))).FmxErr != 0) {
|
|
break
|
|
}
|
|
(**(**TIntegrityCk)(__ccgo_up(bp))).FnRow = 0
|
|
if **(**TPgno)(__ccgo_up(aRoot + uintptr(i)*4)) != 0 {
|
|
if (*TBtShared)(unsafe.Pointer(pBt)).FautoVacuum != 0 && **(**TPgno)(__ccgo_up(aRoot + uintptr(i)*4)) > uint32(1) && !(bPartial != 0) {
|
|
_checkPtrmap(tls, bp, **(**TPgno)(__ccgo_up(aRoot + uintptr(i)*4)), uint8(PTRMAP_ROOTPAGE), uint32(0))
|
|
}
|
|
(**(**TIntegrityCk)(__ccgo_up(bp))).Fv0 = **(**TPgno)(__ccgo_up(aRoot + uintptr(i)*4))
|
|
_checkTreePage(tls, bp, **(**TPgno)(__ccgo_up(aRoot + uintptr(i)*4)), bp+192, libc.Int64FromUint32(0xffffffff)|libc.Int64FromInt32(0x7fffffff)<<libc.Int32FromInt32(32))
|
|
}
|
|
_sqlite3MemSetArrayInt64(tls, aCnt, libc.Int32FromUint32(i), (**(**TIntegrityCk)(__ccgo_up(bp))).FnRow)
|
|
goto _2
|
|
_2:
|
|
;
|
|
i = i + 1
|
|
}
|
|
(*Tsqlite3)(unsafe.Pointer((*TBtShared)(unsafe.Pointer(pBt)).Fdb)).Fflags = savedDbFlags
|
|
/* Make sure every page in the file is referenced
|
|
*/
|
|
if !(bPartial != 0) {
|
|
i = uint32(1)
|
|
for {
|
|
if !(i <= (**(**TIntegrityCk)(__ccgo_up(bp))).FnCkPage && (**(**TIntegrityCk)(__ccgo_up(bp))).FmxErr != 0) {
|
|
break
|
|
}
|
|
/* If the database supports auto-vacuum, make sure no tables contain
|
|
** references to pointer-map pages.
|
|
*/
|
|
if _getPageReferenced(tls, bp, i) == 0 && (_ptrmapPageno(tls, pBt, i) != i || !((*TBtShared)(unsafe.Pointer(pBt)).FautoVacuum != 0)) {
|
|
_checkAppendMsg(tls, bp, __ccgo_ts+5075, libc.VaList(bp+208, i))
|
|
}
|
|
if _getPageReferenced(tls, bp, i) != 0 && (_ptrmapPageno(tls, pBt, i) == i && (*TBtShared)(unsafe.Pointer(pBt)).FautoVacuum != 0) {
|
|
_checkAppendMsg(tls, bp, __ccgo_ts+5095, libc.VaList(bp+208, i))
|
|
}
|
|
goto _3
|
|
_3:
|
|
;
|
|
i = i + 1
|
|
}
|
|
}
|
|
/* Clean up and report errors.
|
|
*/
|
|
goto integrity_ck_cleanup
|
|
integrity_ck_cleanup:
|
|
;
|
|
_sqlite3PageFree(tls, (**(**TIntegrityCk)(__ccgo_up(bp))).Fheap)
|
|
Xsqlite3_free(tls, (**(**TIntegrityCk)(__ccgo_up(bp))).FaPgRef)
|
|
**(**int32)(__ccgo_up(pnErr)) = (**(**TIntegrityCk)(__ccgo_up(bp))).FnErr
|
|
if (**(**TIntegrityCk)(__ccgo_up(bp))).FnErr == 0 {
|
|
Xsqlite3_str_reset(tls, bp+48)
|
|
**(**uintptr)(__ccgo_up(pzOut)) = uintptr(0)
|
|
} else {
|
|
**(**uintptr)(__ccgo_up(pzOut)) = _sqlite3StrAccumFinish(tls, bp+48)
|
|
}
|
|
/* Make sure this analysis did not leave any unref() pages. */
|
|
_sqlite3BtreeLeave(tls, p)
|
|
return (**(**TIntegrityCk)(__ccgo_up(bp))).Frc
|
|
}
|
|
|
|
// C documentation
|
|
//
|
|
// /*
|
|
// ** Open a database file.
|
|
// **
|
|
// ** zFilename is the name of the database file. If zFilename is NULL
|
|
// ** then an ephemeral database is created. The ephemeral database might
|
|
// ** be exclusively in memory, or it might use a disk-based memory cache.
|
|
// ** Either way, the ephemeral database will be automatically deleted
|
|
// ** when sqlite3BtreeClose() is called.
|
|
// **
|
|
// ** If zFilename is ":memory:" then an in-memory database is created
|
|
// ** that is automatically destroyed when it is closed.
|
|
// **
|
|
// ** The "flags" parameter is a bitmask that might contain bits like
|
|
// ** BTREE_OMIT_JOURNAL and/or BTREE_MEMORY.
|
|
// **
|
|
// ** If the database is already opened in the same database connection
|
|
// ** and we are in shared cache mode, then the open will fail with an
|
|
// ** SQLITE_CONSTRAINT error. We cannot allow two or more BtShared
|
|
// ** objects in the same database connection since doing so will lead
|
|
// ** to problems with locking.
|
|
// */
|
|
func _sqlite3BtreeOpen(tls *libc.TLS, pVfs uintptr, zFilename uintptr, db uintptr, ppBtree uintptr, flags int32, vfsFlags int32) (r int32) {
|
|
bp := tls.Alloc(112)
|
|
defer tls.Free(112)
|
|
var i, iDb, isMemdb, isTempDb, nFilename, nFullPathname, rc, v1 int32
|
|
var mutexOpen, mutexShared, mutexShared1, p, pBt, pExisting, pFile, pSib, zFullPathname, v4 uintptr
|
|
var nReserve Tu8
|
|
var _ /* zDbHeader at bp+0 */ [100]uint8
|
|
_, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _ = i, iDb, isMemdb, isTempDb, mutexOpen, mutexShared, mutexShared1, nFilename, nFullPathname, nReserve, p, pBt, pExisting, pFile, pSib, rc, zFullPathname, v1, v4
|
|
pBt = uintptr(0) /* Handle to return */
|
|
mutexOpen = uintptr(0) /* Prevents a race condition. Ticket #3537 */
|
|
rc = SQLITE_OK /* Database header content */
|
|
/* True if opening an ephemeral, temporary database */
|
|
isTempDb = libc.BoolInt32(zFilename == uintptr(0) || int32(**(**int8)(__ccgo_up(zFilename))) == 0)
|
|
/* Set the variable isMemdb to true for an in-memory database, or
|
|
** false for a file-based database.
|
|
*/
|
|
isMemdb = libc.BoolInt32(zFilename != 0 && libc.Xstrcmp(tls, zFilename, __ccgo_ts+4341) == 0 || isTempDb != 0 && _sqlite3TempInMemory(tls, db) != 0 || vfsFlags&int32(SQLITE_OPEN_MEMORY) != 0)
|
|
/* flags fit in 8 bits */
|
|
/* Only a BTREE_SINGLE database can be BTREE_UNORDERED */
|
|
/* A BTREE_SINGLE database is always a temporary and/or ephemeral */
|
|
if isMemdb != 0 {
|
|
flags = flags | int32(BTREE_MEMORY)
|
|
}
|
|
if vfsFlags&int32(SQLITE_OPEN_MAIN_DB) != 0 && (isMemdb != 0 || isTempDb != 0) {
|
|
vfsFlags = vfsFlags & ^libc.Int32FromInt32(SQLITE_OPEN_MAIN_DB) | int32(SQLITE_OPEN_TEMP_DB)
|
|
}
|
|
p = _sqlite3MallocZero(tls, uint64(48))
|
|
if !(p != 0) {
|
|
return int32(SQLITE_NOMEM)
|
|
}
|
|
(*TBtree)(unsafe.Pointer(p)).FinTrans = uint8(TRANS_NONE)
|
|
(*TBtree)(unsafe.Pointer(p)).Fdb = db
|
|
(*TBtree)(unsafe.Pointer(p)).Flock.FpBtree = p
|
|
(*TBtree)(unsafe.Pointer(p)).Flock.FiTable = uint32(1)
|
|
/*
|
|
** If this Btree is a candidate for shared cache, try to find an
|
|
** existing BtShared object that we can share with
|
|
*/
|
|
if isTempDb == 0 && (isMemdb == 0 || vfsFlags&int32(SQLITE_OPEN_URI) != 0) {
|
|
if vfsFlags&int32(SQLITE_OPEN_SHAREDCACHE) != 0 {
|
|
nFilename = _sqlite3Strlen30(tls, zFilename) + int32(1)
|
|
nFullPathname = (*Tsqlite3_vfs)(unsafe.Pointer(pVfs)).FmxPathname + int32(1)
|
|
if nFullPathname > nFilename {
|
|
v1 = nFullPathname
|
|
} else {
|
|
v1 = nFilename
|
|
}
|
|
zFullPathname = _sqlite3Malloc(tls, libc.Uint64FromInt32(v1))
|
|
(*TBtree)(unsafe.Pointer(p)).Fsharable = uint8(1)
|
|
if !(zFullPathname != 0) {
|
|
Xsqlite3_free(tls, p)
|
|
return int32(SQLITE_NOMEM)
|
|
}
|
|
if isMemdb != 0 {
|
|
libc.Xmemcpy(tls, zFullPathname, zFilename, libc.Uint32FromInt32(nFilename))
|
|
} else {
|
|
rc = _sqlite3OsFullPathname(tls, pVfs, zFilename, nFullPathname, zFullPathname)
|
|
if rc != 0 {
|
|
if rc == libc.Int32FromInt32(SQLITE_OK)|libc.Int32FromInt32(2)<<libc.Int32FromInt32(8) {
|
|
rc = SQLITE_OK
|
|
} else {
|
|
Xsqlite3_free(tls, zFullPathname)
|
|
Xsqlite3_free(tls, p)
|
|
return rc
|
|
}
|
|
}
|
|
}
|
|
mutexOpen = _sqlite3MutexAlloc(tls, int32(SQLITE_MUTEX_STATIC_OPEN))
|
|
Xsqlite3_mutex_enter(tls, mutexOpen)
|
|
mutexShared = _sqlite3MutexAlloc(tls, int32(SQLITE_MUTEX_STATIC_MAIN))
|
|
Xsqlite3_mutex_enter(tls, mutexShared)
|
|
pBt = _sqlite3SharedCacheList
|
|
for {
|
|
if !(pBt != 0) {
|
|
break
|
|
}
|
|
if 0 == libc.Xstrcmp(tls, zFullPathname, _sqlite3PagerFilename(tls, (*TBtShared)(unsafe.Pointer(pBt)).FpPager, 0)) && _sqlite3PagerVfs(tls, (*TBtShared)(unsafe.Pointer(pBt)).FpPager) == pVfs {
|
|
iDb = (*Tsqlite3)(unsafe.Pointer(db)).FnDb - int32(1)
|
|
for {
|
|
if !(iDb >= 0) {
|
|
break
|
|
}
|
|
pExisting = (**(**TDb)(__ccgo_up((*Tsqlite3)(unsafe.Pointer(db)).FaDb + uintptr(iDb)*16))).FpBt
|
|
if pExisting != 0 && (*TBtree)(unsafe.Pointer(pExisting)).FpBt == pBt {
|
|
Xsqlite3_mutex_leave(tls, mutexShared)
|
|
Xsqlite3_mutex_leave(tls, mutexOpen)
|
|
Xsqlite3_free(tls, zFullPathname)
|
|
Xsqlite3_free(tls, p)
|
|
return int32(SQLITE_CONSTRAINT)
|
|
}
|
|
goto _3
|
|
_3:
|
|
;
|
|
iDb = iDb - 1
|
|
}
|
|
(*TBtree)(unsafe.Pointer(p)).FpBt = pBt
|
|
(*TBtShared)(unsafe.Pointer(pBt)).FnRef = (*TBtShared)(unsafe.Pointer(pBt)).FnRef + 1
|
|
break
|
|
}
|
|
goto _2
|
|
_2:
|
|
;
|
|
pBt = (*TBtShared)(unsafe.Pointer(pBt)).FpNext
|
|
}
|
|
Xsqlite3_mutex_leave(tls, mutexShared)
|
|
Xsqlite3_free(tls, zFullPathname)
|
|
}
|
|
}
|
|
if pBt == uintptr(0) {
|
|
/*
|
|
** The following asserts make sure that structures used by the btree are
|
|
** the right size. This is to guard against size changes that result
|
|
** when compiling on a different architecture.
|
|
*/
|
|
/* Suppress false-positive compiler warning from PVS-Studio */
|
|
libc.Xmemset(tls, bp+16, 0, uint32(8))
|
|
pBt = _sqlite3MallocZero(tls, uint64(92))
|
|
if pBt == uintptr(0) {
|
|
rc = int32(SQLITE_NOMEM)
|
|
goto btree_open_out
|
|
}
|
|
rc = _sqlite3PagerOpen(tls, pVfs, pBt, zFilename, int32(84), flags, vfsFlags, __ccgo_fp(_pageReinit))
|
|
if rc == SQLITE_OK {
|
|
_sqlite3PagerSetMmapLimit(tls, (*TBtShared)(unsafe.Pointer(pBt)).FpPager, (*Tsqlite3)(unsafe.Pointer(db)).FszMmap)
|
|
rc = _sqlite3PagerReadFileheader(tls, (*TBtShared)(unsafe.Pointer(pBt)).FpPager, int32(100), bp)
|
|
}
|
|
if rc != SQLITE_OK {
|
|
goto btree_open_out
|
|
}
|
|
(*TBtShared)(unsafe.Pointer(pBt)).FopenFlags = libc.Uint8FromInt32(flags)
|
|
(*TBtShared)(unsafe.Pointer(pBt)).Fdb = db
|
|
_sqlite3PagerSetBusyHandler(tls, (*TBtShared)(unsafe.Pointer(pBt)).FpPager, __ccgo_fp(_btreeInvokeBusyHandler), pBt)
|
|
(*TBtree)(unsafe.Pointer(p)).FpBt = pBt
|
|
(*TBtShared)(unsafe.Pointer(pBt)).FpCursor = uintptr(0)
|
|
(*TBtShared)(unsafe.Pointer(pBt)).FpPage1 = uintptr(0)
|
|
if _sqlite3PagerIsreadonly(tls, (*TBtShared)(unsafe.Pointer(pBt)).FpPager) != 0 {
|
|
v4 = pBt + 24
|
|
*(*Tu16)(unsafe.Pointer(v4)) = Tu16(int32(*(*Tu16)(unsafe.Pointer(v4))) | libc.Int32FromInt32(BTS_READ_ONLY))
|
|
}
|
|
/* 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. */
|
|
(*TBtShared)(unsafe.Pointer(pBt)).FpageSize = libc.Uint32FromInt32(libc.Int32FromUint8((**(**[100]uint8)(__ccgo_up(bp)))[int32(16)])<<int32(8) | libc.Int32FromUint8((**(**[100]uint8)(__ccgo_up(bp)))[int32(17)])<<int32(16))
|
|
if (*TBtShared)(unsafe.Pointer(pBt)).FpageSize < uint32(512) || (*TBtShared)(unsafe.Pointer(pBt)).FpageSize > uint32(SQLITE_MAX_PAGE_SIZE) || ((*TBtShared)(unsafe.Pointer(pBt)).FpageSize-uint32(1))&(*TBtShared)(unsafe.Pointer(pBt)).FpageSize != uint32(0) {
|
|
(*TBtShared)(unsafe.Pointer(pBt)).FpageSize = uint32(0)
|
|
/* If the magic name ":memory:" will create an in-memory database, then
|
|
** leave the autoVacuum mode at 0 (do not auto-vacuum), even if
|
|
** SQLITE_DEFAULT_AUTOVACUUM is true. On the other hand, if
|
|
** SQLITE_OMIT_MEMORYDB has been defined, then ":memory:" is just a
|
|
** regular file-name. In this case the auto-vacuum applies as per normal.
|
|
*/
|
|
if zFilename != 0 && !(isMemdb != 0) {
|
|
(*TBtShared)(unsafe.Pointer(pBt)).FautoVacuum = libc.Uint8FromInt32(libc.Int32FromInt32(0))
|
|
(*TBtShared)(unsafe.Pointer(pBt)).FincrVacuum = libc.Uint8FromInt32(libc.Int32FromInt32(0))
|
|
}
|
|
nReserve = uint8(0)
|
|
} else {
|
|
/* 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. */
|
|
nReserve = (**(**[100]uint8)(__ccgo_up(bp)))[int32(20)]
|
|
v4 = pBt + 24
|
|
*(*Tu16)(unsafe.Pointer(v4)) = Tu16(int32(*(*Tu16)(unsafe.Pointer(v4))) | libc.Int32FromInt32(BTS_PAGESIZE_FIXED))
|
|
if _sqlite3Get4byte(tls, bp+uintptr(libc.Int32FromInt32(36)+libc.Int32FromInt32(4)*libc.Int32FromInt32(4))) != 0 {
|
|
v1 = int32(1)
|
|
} else {
|
|
v1 = 0
|
|
}
|
|
(*TBtShared)(unsafe.Pointer(pBt)).FautoVacuum = libc.Uint8FromInt32(v1)
|
|
if _sqlite3Get4byte(tls, bp+uintptr(libc.Int32FromInt32(36)+libc.Int32FromInt32(7)*libc.Int32FromInt32(4))) != 0 {
|
|
v1 = int32(1)
|
|
} else {
|
|
v1 = 0
|
|
}
|
|
(*TBtShared)(unsafe.Pointer(pBt)).FincrVacuum = libc.Uint8FromInt32(v1)
|
|
}
|
|
rc = _sqlite3PagerSetPagesize(tls, (*TBtShared)(unsafe.Pointer(pBt)).FpPager, pBt+36, libc.Int32FromUint8(nReserve))
|
|
if rc != 0 {
|
|
goto btree_open_out
|
|
}
|
|
(*TBtShared)(unsafe.Pointer(pBt)).FusableSize = (*TBtShared)(unsafe.Pointer(pBt)).FpageSize - uint32(nReserve)
|
|
/* 8-byte alignment of pageSize */
|
|
/* Add the new BtShared object to the linked list sharable BtShareds.
|
|
*/
|
|
(*TBtShared)(unsafe.Pointer(pBt)).FnRef = int32(1)
|
|
if (*TBtree)(unsafe.Pointer(p)).Fsharable != 0 {
|
|
mutexShared1 = _sqlite3MutexAlloc(tls, int32(SQLITE_MUTEX_STATIC_MAIN))
|
|
if libc.Bool(int32(SQLITE_THREADSAFE) != 0) && _sqlite3Config.FbCoreMutex != 0 {
|
|
(*TBtShared)(unsafe.Pointer(pBt)).Fmutex = _sqlite3MutexAlloc(tls, SQLITE_MUTEX_FAST)
|
|
if (*TBtShared)(unsafe.Pointer(pBt)).Fmutex == uintptr(0) {
|
|
rc = int32(SQLITE_NOMEM)
|
|
goto btree_open_out
|
|
}
|
|
}
|
|
Xsqlite3_mutex_enter(tls, mutexShared1)
|
|
(*TBtShared)(unsafe.Pointer(pBt)).FpNext = _sqlite3SharedCacheList
|
|
_sqlite3SharedCacheList = pBt
|
|
Xsqlite3_mutex_leave(tls, mutexShared1)
|
|
}
|
|
}
|
|
/* If the new Btree uses a sharable pBtShared, then link the new
|
|
** Btree into the list of all sharable Btrees for the same connection.
|
|
** The list is kept in ascending order by pBt address.
|
|
*/
|
|
if (*TBtree)(unsafe.Pointer(p)).Fsharable != 0 {
|
|
i = 0
|
|
for {
|
|
if !(i < (*Tsqlite3)(unsafe.Pointer(db)).FnDb) {
|
|
break
|
|
}
|
|
v4 = (**(**TDb)(__ccgo_up((*Tsqlite3)(unsafe.Pointer(db)).FaDb + uintptr(i)*16))).FpBt
|
|
pSib = v4
|
|
if v4 != uintptr(0) && (*TBtree)(unsafe.Pointer(pSib)).Fsharable != 0 {
|
|
for (*TBtree)(unsafe.Pointer(pSib)).FpPrev != 0 {
|
|
pSib = (*TBtree)(unsafe.Pointer(pSib)).FpPrev
|
|
}
|
|
if uint32((*TBtree)(unsafe.Pointer(p)).FpBt) < uint32((*TBtree)(unsafe.Pointer(pSib)).FpBt) {
|
|
(*TBtree)(unsafe.Pointer(p)).FpNext = pSib
|
|
(*TBtree)(unsafe.Pointer(p)).FpPrev = uintptr(0)
|
|
(*TBtree)(unsafe.Pointer(pSib)).FpPrev = p
|
|
} else {
|
|
for (*TBtree)(unsafe.Pointer(pSib)).FpNext != 0 && uint32((*TBtree)(unsafe.Pointer((*TBtree)(unsafe.Pointer(pSib)).FpNext)).FpBt) < uint32((*TBtree)(unsafe.Pointer(p)).FpBt) {
|
|
pSib = (*TBtree)(unsafe.Pointer(pSib)).FpNext
|
|
}
|
|
(*TBtree)(unsafe.Pointer(p)).FpNext = (*TBtree)(unsafe.Pointer(pSib)).FpNext
|
|
(*TBtree)(unsafe.Pointer(p)).FpPrev = pSib
|
|
if (*TBtree)(unsafe.Pointer(p)).FpNext != 0 {
|
|
(*TBtree)(unsafe.Pointer((*TBtree)(unsafe.Pointer(p)).FpNext)).FpPrev = p
|
|
}
|
|
(*TBtree)(unsafe.Pointer(pSib)).FpNext = p
|
|
}
|
|
break
|
|
}
|
|
goto _8
|
|
_8:
|
|
;
|
|
i = i + 1
|
|
}
|
|
}
|
|
**(**uintptr)(__ccgo_up(ppBtree)) = p
|
|
goto btree_open_out
|
|
btree_open_out:
|
|
;
|
|
if rc != SQLITE_OK {
|
|
if pBt != 0 && (*TBtShared)(unsafe.Pointer(pBt)).FpPager != 0 {
|
|
_sqlite3PagerClose(tls, (*TBtShared)(unsafe.Pointer(pBt)).FpPager, uintptr(0))
|
|
}
|
|
Xsqlite3_free(tls, pBt)
|
|
Xsqlite3_free(tls, p)
|
|
**(**uintptr)(__ccgo_up(ppBtree)) = uintptr(0)
|
|
} else {
|
|
/* If the B-Tree was successfully opened, set the pager-cache size to the
|
|
** default value. Except, when opening on an existing shared pager-cache,
|
|
** do not change the pager-cache size.
|
|
*/
|
|
if _sqlite3BtreeSchema(tls, p, 0, uintptr(0)) == uintptr(0) {
|
|
_sqlite3BtreeSetCacheSize(tls, p, -int32(2000))
|
|
}
|
|
pFile = _sqlite3PagerFile(tls, (*TBtShared)(unsafe.Pointer(pBt)).FpPager)
|
|
if (*Tsqlite3_file)(unsafe.Pointer(pFile)).FpMethods != 0 {
|
|
_sqlite3OsFileControlHint(tls, pFile, int32(SQLITE_FCNTL_PDB), pBt+4)
|
|
}
|
|
}
|
|
if mutexOpen != 0 {
|
|
Xsqlite3_mutex_leave(tls, mutexOpen)
|
|
}
|
|
return rc
|
|
}
|
|
|
|
// 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 + 172 + 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*4))) != 0 || Xsqlite3_stricmp(tls, zTblName, **(**uintptr)(__ccgo_up((*Tsqlite3)(unsafe.Pointer(db)).Finit1.FazInit + 2*4))) != 0 {
|
|
_sqlite3ErrorMsg(tls, pParse, __ccgo_ts+1702, 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+6758, int32(7)) || _sqlite3ReadOnlyShadowTables(tls, db) != 0 && _sqlite3ShadowTableName(tls, db, zName) != 0 {
|
|
_sqlite3ErrorMsg(tls, pParse, __ccgo_ts+13765, libc.VaList(bp+8, zName))
|
|
return int32(SQLITE_ERROR)
|
|
}
|
|
}
|
|
return SQLITE_OK
|
|
}
|
|
|
|
// C documentation
|
|
//
|
|
// /*
|
|
// ** Remove entries from the sqlite_statN tables (for N in (1,2,3))
|
|
// ** after a DROP INDEX or DROP TABLE command.
|
|
// */
|
|
func _sqlite3ClearStatTables(tls *libc.TLS, pParse uintptr, iDb int32, zType uintptr, zName uintptr) {
|
|
bp := tls.Alloc(64)
|
|
defer tls.Free(64)
|
|
var i int32
|
|
var zDbName uintptr
|
|
var _ /* zTab at bp+0 */ [24]int8
|
|
_, _ = i, zDbName
|
|
zDbName = (**(**TDb)(__ccgo_up((*Tsqlite3)(unsafe.Pointer((*TParse)(unsafe.Pointer(pParse)).Fdb)).FaDb + uintptr(iDb)*16))).FzDbSName
|
|
i = int32(1)
|
|
for {
|
|
if !(i <= int32(4)) {
|
|
break
|
|
}
|
|
Xsqlite3_snprintf(tls, int32(24), bp, __ccgo_ts+14953, libc.VaList(bp+32, i))
|
|
if _sqlite3FindTable(tls, (*TParse)(unsafe.Pointer(pParse)).Fdb, bp, zDbName) != 0 {
|
|
_sqlite3NestedParse(tls, pParse, __ccgo_ts+12938, libc.VaList(bp+32, zDbName, bp, zType, zName))
|
|
}
|
|
goto _1
|
|
_1:
|
|
;
|
|
i = i + 1
|
|
}
|
|
}
|
|
|
|
// C documentation
|
|
//
|
|
// /*
|
|
// ** Generate code that will construct an ephemeral table containing all terms
|
|
// ** in the RHS of an IN operator. The IN operator can be in either of two
|
|
// ** forms:
|
|
// **
|
|
// ** x IN (4,5,11) -- IN operator with list on right-hand side
|
|
// ** x IN (SELECT a FROM b) -- IN operator with subquery on the right
|
|
// **
|
|
// ** The pExpr parameter is the IN operator. The cursor number for the
|
|
// ** constructed ephemeral table is returned. The first time the ephemeral
|
|
// ** table is computed, the cursor number is also stored in pExpr->iTable,
|
|
// ** however the cursor number returned might not be the same, as it might
|
|
// ** have been duplicated using OP_OpenDup.
|
|
// **
|
|
// ** If the LHS expression ("x" in the examples) is a column value, or
|
|
// ** the SELECT statement returns a column value, then the affinity of that
|
|
// ** column is used to build the index keys. If both 'x' and the
|
|
// ** SELECT... statement are columns, then numeric affinity is used
|
|
// ** if either column has NUMERIC or INTEGER affinity. If neither
|
|
// ** 'x' nor the SELECT... statement are columns, then numeric affinity
|
|
// ** is used.
|
|
// */
|
|
func _sqlite3CodeRhsOfIN(tls *libc.TLS, pParse uintptr, pExpr uintptr, iTab int32, allowBloom int32) {
|
|
bp := tls.Alloc(64)
|
|
defer tls.Free(64)
|
|
var addr, addrBloom, addrOnce, i, i1, nVal, r1, r2, rc, regBloom, v1 int32
|
|
var p, pCopy, pE2, pEList, pItem, pKeyInfo, pLeft, pList, pSelect, pSig, v, v2 uintptr
|
|
var _ /* affinity at bp+28 */ int8
|
|
var _ /* dest at bp+0 */ TSelectDest
|
|
_, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _ = addr, addrBloom, addrOnce, i, i1, nVal, p, pCopy, pE2, pEList, pItem, pKeyInfo, pLeft, pList, pSelect, pSig, r1, r2, rc, regBloom, v, v1, v2
|
|
addrOnce = 0 /* the LHS of the IN operator */
|
|
pKeyInfo = uintptr(0) /* The prepared statement under construction */
|
|
pSig = uintptr(0) /* Signature for this subroutine */
|
|
v = (*TParse)(unsafe.Pointer(pParse)).FpVdbe
|
|
/* The evaluation of the IN must be repeated every time it
|
|
** is encountered if any of the following is true:
|
|
**
|
|
** * The right-hand side is a correlated subquery
|
|
** * The right-hand side is an expression list containing variables
|
|
** * We are inside a trigger
|
|
**
|
|
** If all of the above are false, then we can compute the RHS just once
|
|
** and reuse it many names.
|
|
*/
|
|
if !((*TExpr)(unsafe.Pointer(pExpr)).Fflags&libc.Uint32FromInt32(libc.Int32FromInt32(EP_VarSelect)) != libc.Uint32FromInt32(0)) && (*TParse)(unsafe.Pointer(pParse)).FiSelfTab == 0 {
|
|
/* Reuse of the RHS is allowed
|
|
**
|
|
** Compute a signature for the RHS of the IN operator to facility
|
|
** finding and reusing prior instances of the same IN operator.
|
|
*/
|
|
if (*TExpr)(unsafe.Pointer(pExpr)).Fflags&uint32(EP_xIsSelect) != uint32(0) && (*TSelect)(unsafe.Pointer(*(*uintptr)(unsafe.Pointer(pExpr + 20)))).FselFlags&uint32(SF_All) == uint32(0) {
|
|
pSig = _sqlite3DbMallocRawNN(tls, (*TParse)(unsafe.Pointer(pParse)).Fdb, uint64(24))
|
|
if pSig != 0 {
|
|
(*TSubrtnSig)(unsafe.Pointer(pSig)).FselId = libc.Int32FromUint32((*TSelect)(unsafe.Pointer(*(*uintptr)(unsafe.Pointer(pExpr + 20)))).FselId)
|
|
(*TSubrtnSig)(unsafe.Pointer(pSig)).FzAff = _exprINAffinity(tls, pParse, pExpr)
|
|
}
|
|
}
|
|
/* Check to see if there is a prior materialization of the RHS of
|
|
** this IN operator. If there is, then make use of that prior
|
|
** materialization rather than recomputing it.
|
|
*/
|
|
if (*TExpr)(unsafe.Pointer(pExpr)).Fflags&libc.Uint32FromInt32(libc.Int32FromInt32(EP_Subrtn)) != uint32(0) || _findCompatibleInRhsSubrtn(tls, pParse, pExpr, pSig) != 0 {
|
|
addrOnce = _sqlite3VdbeAddOp0(tls, v, int32(OP_Once))
|
|
if (*TExpr)(unsafe.Pointer(pExpr)).Fflags&uint32(EP_xIsSelect) != uint32(0) {
|
|
_sqlite3VdbeExplain(tls, pParse, uint8(0), __ccgo_ts+8331, libc.VaList(bp+40, (*TSelect)(unsafe.Pointer(*(*uintptr)(unsafe.Pointer(pExpr + 20)))).FselId))
|
|
}
|
|
_sqlite3VdbeAddOp2(tls, v, int32(OP_Gosub), (*(*struct {
|
|
FiAddr int32
|
|
FregReturn int32
|
|
})(unsafe.Pointer(pExpr + 44))).FregReturn, (*(*struct {
|
|
FiAddr int32
|
|
FregReturn int32
|
|
})(unsafe.Pointer(pExpr + 44))).FiAddr)
|
|
_sqlite3VdbeAddOp2(tls, v, int32(OP_OpenDup), iTab, (*TExpr)(unsafe.Pointer(pExpr)).FiTable)
|
|
_sqlite3VdbeJumpHere(tls, v, addrOnce)
|
|
if pSig != 0 {
|
|
_sqlite3DbFree(tls, (*TParse)(unsafe.Pointer(pParse)).Fdb, (*TSubrtnSig)(unsafe.Pointer(pSig)).FzAff)
|
|
_sqlite3DbFree(tls, (*TParse)(unsafe.Pointer(pParse)).Fdb, pSig)
|
|
}
|
|
return
|
|
}
|
|
/* Begin coding the subroutine */
|
|
**(**Tu32)(__ccgo_up(pExpr + 4)) |= libc.Uint32FromInt32(libc.Int32FromInt32(EP_Subrtn))
|
|
v2 = pParse + 48
|
|
*(*int32)(unsafe.Pointer(v2)) = *(*int32)(unsafe.Pointer(v2)) + 1
|
|
v1 = *(*int32)(unsafe.Pointer(v2))
|
|
(*(*struct {
|
|
FiAddr int32
|
|
FregReturn int32
|
|
})(unsafe.Pointer(pExpr + 44))).FregReturn = v1
|
|
(*(*struct {
|
|
FiAddr int32
|
|
FregReturn int32
|
|
})(unsafe.Pointer(pExpr + 44))).FiAddr = _sqlite3VdbeAddOp2(tls, v, int32(OP_BeginSubrtn), 0, (*(*struct {
|
|
FiAddr int32
|
|
FregReturn int32
|
|
})(unsafe.Pointer(pExpr + 44))).FregReturn) + int32(1)
|
|
if pSig != 0 {
|
|
(*TSubrtnSig)(unsafe.Pointer(pSig)).FbComplete = uint8(0)
|
|
(*TSubrtnSig)(unsafe.Pointer(pSig)).FiAddr = (*(*struct {
|
|
FiAddr int32
|
|
FregReturn int32
|
|
})(unsafe.Pointer(pExpr + 44))).FiAddr
|
|
(*TSubrtnSig)(unsafe.Pointer(pSig)).FregReturn = (*(*struct {
|
|
FiAddr int32
|
|
FregReturn int32
|
|
})(unsafe.Pointer(pExpr + 44))).FregReturn
|
|
(*TSubrtnSig)(unsafe.Pointer(pSig)).FiTable = iTab
|
|
(*TParse)(unsafe.Pointer(pParse)).FmSubrtnSig = libc.Uint8FromInt32(int32(1) << ((*TSubrtnSig)(unsafe.Pointer(pSig)).FselId & int32(7)))
|
|
_sqlite3VdbeChangeP4(tls, v, -int32(1), pSig, -int32(18))
|
|
}
|
|
addrOnce = _sqlite3VdbeAddOp0(tls, v, int32(OP_Once))
|
|
}
|
|
/* Check to see if this is a vector IN operator */
|
|
pLeft = (*TExpr)(unsafe.Pointer(pExpr)).FpLeft
|
|
nVal = _sqlite3ExprVectorSize(tls, pLeft)
|
|
/* Construct the ephemeral table that will contain the content of
|
|
** RHS of the IN operator.
|
|
*/
|
|
(*TExpr)(unsafe.Pointer(pExpr)).FiTable = iTab
|
|
addr = _sqlite3VdbeAddOp2(tls, v, int32(OP_OpenEphemeral), (*TExpr)(unsafe.Pointer(pExpr)).FiTable, nVal)
|
|
pKeyInfo = _sqlite3KeyInfoAlloc(tls, (*TParse)(unsafe.Pointer(pParse)).Fdb, nVal, int32(1))
|
|
if (*TExpr)(unsafe.Pointer(pExpr)).Fflags&uint32(EP_xIsSelect) != uint32(0) {
|
|
/* Case 1: expr IN (SELECT ...)
|
|
**
|
|
** Generate code to write the results of the select into the temporary
|
|
** table allocated and opened above.
|
|
*/
|
|
pSelect = *(*uintptr)(unsafe.Pointer(pExpr + 20))
|
|
pEList = (*TSelect)(unsafe.Pointer(pSelect)).FpEList
|
|
if addrOnce != 0 {
|
|
v2 = __ccgo_ts + 1702
|
|
} else {
|
|
v2 = __ccgo_ts + 8354
|
|
}
|
|
_sqlite3VdbeExplain(tls, pParse, uint8(1), __ccgo_ts+8366, libc.VaList(bp+40, v2, (*TSelect)(unsafe.Pointer(pSelect)).FselId))
|
|
/* If the LHS and RHS of the IN operator do not match, that
|
|
** error will have been caught long before we reach this point. */
|
|
if (*TExprList)(unsafe.Pointer(pEList)).FnExpr == nVal {
|
|
addrBloom = 0
|
|
_sqlite3SelectDestInit(tls, bp, int32(SRT_Set), iTab)
|
|
(**(**TSelectDest)(__ccgo_up(bp))).FzAffSdst = _exprINAffinity(tls, pParse, pExpr)
|
|
(*TSelect)(unsafe.Pointer(pSelect)).FiLimit = 0
|
|
if addrOnce != 0 && allowBloom != 0 && (*Tsqlite3)(unsafe.Pointer((*TParse)(unsafe.Pointer(pParse)).Fdb)).FdbOptFlags&libc.Uint32FromInt32(libc.Int32FromInt32(SQLITE_BloomFilter)) == uint32(0) {
|
|
v2 = pParse + 48
|
|
*(*int32)(unsafe.Pointer(v2)) = *(*int32)(unsafe.Pointer(v2)) + 1
|
|
v1 = *(*int32)(unsafe.Pointer(v2))
|
|
regBloom = v1
|
|
addrBloom = _sqlite3VdbeAddOp2(tls, v, int32(OP_Blob), int32(10000), regBloom)
|
|
(**(**TSelectDest)(__ccgo_up(bp))).FiSDParm2 = regBloom
|
|
}
|
|
/* Caused by OOM in sqlite3KeyInfoAlloc() */
|
|
pCopy = _sqlite3SelectDup(tls, (*TParse)(unsafe.Pointer(pParse)).Fdb, pSelect, 0)
|
|
if (*Tsqlite3)(unsafe.Pointer((*TParse)(unsafe.Pointer(pParse)).Fdb)).FmallocFailed != 0 {
|
|
v1 = int32(1)
|
|
} else {
|
|
v1 = _sqlite3Select(tls, pParse, pCopy, bp)
|
|
}
|
|
rc = v1
|
|
_sqlite3SelectDelete(tls, (*TParse)(unsafe.Pointer(pParse)).Fdb, pCopy)
|
|
_sqlite3DbFree(tls, (*TParse)(unsafe.Pointer(pParse)).Fdb, (**(**TSelectDest)(__ccgo_up(bp))).FzAffSdst)
|
|
if addrBloom != 0 {
|
|
/* Remember that location of the Bloom filter in the P3 operand
|
|
** of the OP_Once that began this subroutine. tag-202407032019 */
|
|
(*TVdbeOp)(unsafe.Pointer(_sqlite3VdbeGetOp(tls, v, addrOnce))).Fp3 = (**(**TSelectDest)(__ccgo_up(bp))).FiSDParm2
|
|
if (**(**TSelectDest)(__ccgo_up(bp))).FiSDParm2 == 0 {
|
|
/* If the Bloom filter won't actually be used, keep it small */
|
|
(*TVdbeOp)(unsafe.Pointer(_sqlite3VdbeGetOp(tls, v, addrBloom))).Fp1 = int32(10)
|
|
}
|
|
}
|
|
if rc != 0 {
|
|
_sqlite3KeyInfoUnref(tls, pKeyInfo)
|
|
return
|
|
}
|
|
/* OOM will cause exit after sqlite3Select() */
|
|
i = 0
|
|
for {
|
|
if !(i < nVal) {
|
|
break
|
|
}
|
|
p = _sqlite3VectorFieldSubexpr(tls, pLeft, i)
|
|
*(*uintptr)(unsafe.Pointer(pKeyInfo + 20 + uintptr(i)*4)) = _sqlite3BinaryCompareCollSeq(tls, pParse, p, (*(*TExprList_item)(unsafe.Pointer(pEList + 8 + uintptr(i)*20))).FpExpr)
|
|
goto _7
|
|
_7:
|
|
;
|
|
i = i + 1
|
|
}
|
|
}
|
|
} else {
|
|
if *(*uintptr)(unsafe.Pointer(pExpr + 20)) != uintptr(0) {
|
|
pList = *(*uintptr)(unsafe.Pointer(pExpr + 20))
|
|
**(**int8)(__ccgo_up(bp + 28)) = _sqlite3ExprAffinity(tls, pLeft)
|
|
if int32(**(**int8)(__ccgo_up(bp + 28))) <= int32(SQLITE_AFF_NONE) {
|
|
**(**int8)(__ccgo_up(bp + 28)) = int8(SQLITE_AFF_BLOB)
|
|
} else {
|
|
if int32(**(**int8)(__ccgo_up(bp + 28))) == int32(SQLITE_AFF_REAL) {
|
|
**(**int8)(__ccgo_up(bp + 28)) = int8(SQLITE_AFF_NUMERIC)
|
|
}
|
|
}
|
|
if pKeyInfo != 0 {
|
|
*(*uintptr)(unsafe.Pointer(pKeyInfo + 20)) = _sqlite3ExprCollSeq(tls, pParse, (*TExpr)(unsafe.Pointer(pExpr)).FpLeft)
|
|
}
|
|
/* Loop through each expression in <exprlist>. */
|
|
r1 = _sqlite3GetTempReg(tls, pParse)
|
|
r2 = _sqlite3GetTempReg(tls, pParse)
|
|
i1 = (*TExprList)(unsafe.Pointer(pList)).FnExpr
|
|
pItem = pList + 8
|
|
for {
|
|
if !(i1 > 0) {
|
|
break
|
|
}
|
|
pE2 = (*TExprList_item)(unsafe.Pointer(pItem)).FpExpr
|
|
/* If the expression is not constant then we will need to
|
|
** disable the test that was generated above that makes sure
|
|
** this code only executes once. Because for a non-constant
|
|
** expression we need to rerun this code each time.
|
|
*/
|
|
if addrOnce != 0 && !(_sqlite3ExprIsConstant(tls, pParse, pE2) != 0) {
|
|
_sqlite3VdbeChangeToNoop(tls, v, addrOnce-int32(1))
|
|
_sqlite3VdbeChangeToNoop(tls, v, addrOnce)
|
|
**(**Tu32)(__ccgo_up(pExpr + 4)) &= ^libc.Uint32FromInt32(libc.Int32FromInt32(EP_Subrtn))
|
|
addrOnce = 0
|
|
}
|
|
/* Evaluate the expression and insert it into the temp table */
|
|
_sqlite3ExprCode(tls, pParse, pE2, r1)
|
|
_sqlite3VdbeAddOp4(tls, v, int32(OP_MakeRecord), r1, int32(1), r2, bp+28, int32(1))
|
|
_sqlite3VdbeAddOp4Int(tls, v, int32(OP_IdxInsert), iTab, r2, r1, int32(1))
|
|
goto _8
|
|
_8:
|
|
;
|
|
i1 = i1 - 1
|
|
pItem += 20
|
|
}
|
|
_sqlite3ReleaseTempReg(tls, pParse, r1)
|
|
_sqlite3ReleaseTempReg(tls, pParse, r2)
|
|
}
|
|
}
|
|
if pSig != 0 {
|
|
(*TSubrtnSig)(unsafe.Pointer(pSig)).FbComplete = uint8(1)
|
|
}
|
|
if pKeyInfo != 0 {
|
|
_sqlite3VdbeChangeP4(tls, v, addr, pKeyInfo, -int32(9))
|
|
}
|
|
if addrOnce != 0 {
|
|
_sqlite3VdbeAddOp1(tls, v, int32(OP_NullRow), iTab)
|
|
_sqlite3VdbeJumpHere(tls, v, addrOnce)
|
|
/* Subroutine return */
|
|
_sqlite3VdbeAddOp3(tls, v, int32(OP_Return), (*(*struct {
|
|
FiAddr int32
|
|
FregReturn int32
|
|
})(unsafe.Pointer(pExpr + 44))).FregReturn, (*(*struct {
|
|
FiAddr int32
|
|
FregReturn int32
|
|
})(unsafe.Pointer(pExpr + 44))).FiAddr, int32(1))
|
|
_sqlite3ClearTempRegCache(tls, pParse)
|
|
}
|
|
}
|
|
|
|
// C documentation
|
|
//
|
|
// /*
|
|
// ** Generate code for scalar subqueries used as a subquery expression
|
|
// ** or EXISTS operator:
|
|
// **
|
|
// ** (SELECT a FROM b) -- subquery
|
|
// ** EXISTS (SELECT a FROM b) -- EXISTS subquery
|
|
// **
|
|
// ** The pExpr parameter is the SELECT or EXISTS operator to be coded.
|
|
// **
|
|
// ** Return the register that holds the result. For a multi-column SELECT,
|
|
// ** the result is stored in a contiguous array of registers and the
|
|
// ** return value is the register of the left-most result column.
|
|
// ** Return 0 if an error occurs.
|
|
// */
|
|
func _sqlite3CodeSubselect(tls *libc.TLS, pParse uintptr, pExpr uintptr) (r int32) {
|
|
bp := tls.Alloc(64)
|
|
defer tls.Free(64)
|
|
var addrOnce, nReg, rReg, v1 int32
|
|
var db, pLeft, pLimit, pSel, v, v2 uintptr
|
|
var _ /* dest at bp+0 */ TSelectDest
|
|
_, _, _, _, _, _, _, _, _, _ = addrOnce, db, nReg, pLeft, pLimit, pSel, rReg, v, v1, v2
|
|
addrOnce = 0 /* Address of OP_Once at top of subroutine */
|
|
rReg = 0 /* New limit expression */
|
|
v = (*TParse)(unsafe.Pointer(pParse)).FpVdbe
|
|
if (*TParse)(unsafe.Pointer(pParse)).FnErr != 0 {
|
|
return 0
|
|
}
|
|
pSel = *(*uintptr)(unsafe.Pointer(pExpr + 20))
|
|
/* If this routine has already been coded, then invoke it as a
|
|
** subroutine. */
|
|
if (*TExpr)(unsafe.Pointer(pExpr)).Fflags&libc.Uint32FromInt32(libc.Int32FromInt32(EP_Subrtn)) != uint32(0) {
|
|
_sqlite3VdbeExplain(tls, pParse, uint8(0), __ccgo_ts+8385, libc.VaList(bp+40, (*TSelect)(unsafe.Pointer(pSel)).FselId))
|
|
_sqlite3VdbeAddOp2(tls, v, int32(OP_Gosub), (*(*struct {
|
|
FiAddr int32
|
|
FregReturn int32
|
|
})(unsafe.Pointer(pExpr + 44))).FregReturn, (*(*struct {
|
|
FiAddr int32
|
|
FregReturn int32
|
|
})(unsafe.Pointer(pExpr + 44))).FiAddr)
|
|
return (*TExpr)(unsafe.Pointer(pExpr)).FiTable
|
|
}
|
|
/* Begin coding the subroutine */
|
|
**(**Tu32)(__ccgo_up(pExpr + 4)) |= libc.Uint32FromInt32(libc.Int32FromInt32(EP_Subrtn))
|
|
v2 = pParse + 48
|
|
*(*int32)(unsafe.Pointer(v2)) = *(*int32)(unsafe.Pointer(v2)) + 1
|
|
v1 = *(*int32)(unsafe.Pointer(v2))
|
|
(*(*struct {
|
|
FiAddr int32
|
|
FregReturn int32
|
|
})(unsafe.Pointer(pExpr + 44))).FregReturn = v1
|
|
(*(*struct {
|
|
FiAddr int32
|
|
FregReturn int32
|
|
})(unsafe.Pointer(pExpr + 44))).FiAddr = _sqlite3VdbeAddOp2(tls, v, int32(OP_BeginSubrtn), 0, (*(*struct {
|
|
FiAddr int32
|
|
FregReturn int32
|
|
})(unsafe.Pointer(pExpr + 44))).FregReturn) + int32(1)
|
|
/* The evaluation of the EXISTS/SELECT must be repeated every time it
|
|
** is encountered if any of the following is true:
|
|
**
|
|
** * The right-hand side is a correlated subquery
|
|
** * The right-hand side is an expression list containing variables
|
|
** * We are inside a trigger
|
|
**
|
|
** If all of the above are false, then we can run this code just once
|
|
** save the results, and reuse the same result on subsequent invocations.
|
|
*/
|
|
if !((*TExpr)(unsafe.Pointer(pExpr)).Fflags&libc.Uint32FromInt32(libc.Int32FromInt32(EP_VarSelect)) != libc.Uint32FromInt32(0)) {
|
|
addrOnce = _sqlite3VdbeAddOp0(tls, v, int32(OP_Once))
|
|
}
|
|
/* For a SELECT, generate code to put the values for all columns of
|
|
** the first row into an array of registers and return the index of
|
|
** the first register.
|
|
**
|
|
** If this is an EXISTS, write an integer 0 (not exists) or 1 (exists)
|
|
** into a register and return that register number.
|
|
**
|
|
** In both cases, the query is augmented with "LIMIT 1". Any
|
|
** preexisting limit is discarded in place of the new LIMIT 1.
|
|
*/
|
|
if addrOnce != 0 {
|
|
v2 = __ccgo_ts + 1702
|
|
} else {
|
|
v2 = __ccgo_ts + 8354
|
|
}
|
|
_sqlite3VdbeExplain(tls, pParse, uint8(1), __ccgo_ts+8403, libc.VaList(bp+40, v2, (*TSelect)(unsafe.Pointer(pSel)).FselId))
|
|
if libc.Int32FromUint8((*TExpr)(unsafe.Pointer(pExpr)).Fop) == int32(TK_SELECT) {
|
|
v1 = (*TExprList)(unsafe.Pointer((*TSelect)(unsafe.Pointer(pSel)).FpEList)).FnExpr
|
|
} else {
|
|
v1 = int32(1)
|
|
}
|
|
nReg = v1
|
|
_sqlite3SelectDestInit(tls, bp, 0, (*TParse)(unsafe.Pointer(pParse)).FnMem+int32(1))
|
|
**(**int32)(__ccgo_up(pParse + 48)) += nReg
|
|
if libc.Int32FromUint8((*TExpr)(unsafe.Pointer(pExpr)).Fop) == int32(TK_SELECT) {
|
|
(**(**TSelectDest)(__ccgo_up(bp))).FeDest = uint8(SRT_Mem)
|
|
if (*TSelect)(unsafe.Pointer(pSel)).FselFlags&uint32(SF_Distinct) != 0 && (*TSelect)(unsafe.Pointer(pSel)).FpLimit != 0 && (*TExpr)(unsafe.Pointer((*TSelect)(unsafe.Pointer(pSel)).FpLimit)).FpRight != 0 {
|
|
/* If there is both a DISTINCT and an OFFSET clause, then allocate
|
|
** a separate dest.iSdst array for sqlite3Select() and other
|
|
** routines to populate. In this case results will be copied over
|
|
** into the dest.iSDParm array only after OFFSET processing. This
|
|
** ensures that in the case where OFFSET excludes all rows, the
|
|
** dest.iSDParm array is not left populated with the contents of the
|
|
** last row visited - it should be all NULLs if all rows were
|
|
** excluded by OFFSET. */
|
|
(**(**TSelectDest)(__ccgo_up(bp))).FiSdst = (*TParse)(unsafe.Pointer(pParse)).FnMem + int32(1)
|
|
**(**int32)(__ccgo_up(pParse + 48)) += nReg
|
|
} else {
|
|
(**(**TSelectDest)(__ccgo_up(bp))).FiSdst = (**(**TSelectDest)(__ccgo_up(bp))).FiSDParm
|
|
}
|
|
(**(**TSelectDest)(__ccgo_up(bp))).FnSdst = nReg
|
|
_sqlite3VdbeAddOp3(tls, v, int32(OP_Null), 0, (**(**TSelectDest)(__ccgo_up(bp))).FiSDParm, (*TParse)(unsafe.Pointer(pParse)).FnMem)
|
|
} else {
|
|
(**(**TSelectDest)(__ccgo_up(bp))).FeDest = uint8(SRT_Exists)
|
|
_sqlite3VdbeAddOp2(tls, v, int32(OP_Integer), 0, (**(**TSelectDest)(__ccgo_up(bp))).FiSDParm)
|
|
}
|
|
if (*TSelect)(unsafe.Pointer(pSel)).FpLimit != 0 {
|
|
/* The subquery already has a limit. If the pre-existing limit X is
|
|
** not already integer value 1 or 0, then make the new limit X<>0 so that
|
|
** the new limit is either 1 or 0 */
|
|
pLeft = (*TExpr)(unsafe.Pointer((*TSelect)(unsafe.Pointer(pSel)).FpLimit)).FpLeft
|
|
if libc.BoolInt32((*TExpr)(unsafe.Pointer(pLeft)).Fflags&libc.Uint32FromInt32(libc.Int32FromInt32(EP_IntValue)) != uint32(0)) == 0 || *(*int32)(unsafe.Pointer(pLeft + 8)) != int32(1) && *(*int32)(unsafe.Pointer(pLeft + 8)) != 0 {
|
|
db = (*TParse)(unsafe.Pointer(pParse)).Fdb
|
|
pLimit = _sqlite3ExprInt32(tls, db, 0)
|
|
if pLimit != 0 {
|
|
(*TExpr)(unsafe.Pointer(pLimit)).FaffExpr = int8(SQLITE_AFF_NUMERIC)
|
|
pLimit = _sqlite3PExpr(tls, pParse, int32(TK_NE), _sqlite3ExprDup(tls, db, pLeft, 0), pLimit)
|
|
}
|
|
_sqlite3ExprDeferredDelete(tls, pParse, pLeft)
|
|
(*TExpr)(unsafe.Pointer((*TSelect)(unsafe.Pointer(pSel)).FpLimit)).FpLeft = pLimit
|
|
}
|
|
} else {
|
|
/* If there is no pre-existing limit add a limit of 1 */
|
|
pLimit = _sqlite3ExprInt32(tls, (*TParse)(unsafe.Pointer(pParse)).Fdb, int32(1))
|
|
(*TSelect)(unsafe.Pointer(pSel)).FpLimit = _sqlite3PExpr(tls, pParse, int32(TK_LIMIT), pLimit, uintptr(0))
|
|
}
|
|
(*TSelect)(unsafe.Pointer(pSel)).FiLimit = 0
|
|
if _sqlite3Select(tls, pParse, pSel, bp) != 0 {
|
|
(*TExpr)(unsafe.Pointer(pExpr)).Fop2 = (*TExpr)(unsafe.Pointer(pExpr)).Fop
|
|
(*TExpr)(unsafe.Pointer(pExpr)).Fop = uint8(TK_ERROR)
|
|
return 0
|
|
}
|
|
v1 = (**(**TSelectDest)(__ccgo_up(bp))).FiSDParm
|
|
rReg = v1
|
|
(*TExpr)(unsafe.Pointer(pExpr)).FiTable = v1
|
|
if addrOnce != 0 {
|
|
_sqlite3VdbeJumpHere(tls, v, addrOnce)
|
|
}
|
|
/* Subroutine return */
|
|
_sqlite3VdbeAddOp3(tls, v, int32(OP_Return), (*(*struct {
|
|
FiAddr int32
|
|
FregReturn int32
|
|
})(unsafe.Pointer(pExpr + 44))).FregReturn, (*(*struct {
|
|
FiAddr int32
|
|
FregReturn int32
|
|
})(unsafe.Pointer(pExpr + 44))).FiAddr, int32(1))
|
|
_sqlite3ClearTempRegCache(tls, pParse)
|
|
return rReg
|
|
}
|
|
|
|
// C documentation
|
|
//
|
|
// /*
|
|
// ** Given an expression list (which is really the list of expressions
|
|
// ** that form the result set of a SELECT statement) compute appropriate
|
|
// ** column names for a table that would hold the expression list.
|
|
// **
|
|
// ** All column names will be unique.
|
|
// **
|
|
// ** Only the column names are computed. Column.zType, Column.zColl,
|
|
// ** and other fields of Column are zeroed.
|
|
// **
|
|
// ** Return SQLITE_OK on success. If a memory allocation error occurs,
|
|
// ** store NULL in *paCol and 0 in *pnCol and return SQLITE_NOMEM.
|
|
// **
|
|
// ** 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: sqlite3GenerateColumnNames()
|
|
// */
|
|
func _sqlite3ColumnsFromExprList(tls *libc.TLS, pParse uintptr, pEList uintptr, pnCol uintptr, paCol uintptr) (r int32) {
|
|
bp := tls.Alloc(64)
|
|
defer tls.Free(64)
|
|
var aCol, db, pCol, pColExpr, pCollide, pTab, pX, zName, v2, v3 uintptr
|
|
var i, iCol, j, nCol, nName int32
|
|
var v5 bool
|
|
var v8 Tu32
|
|
var _ /* cnt at bp+0 */ Tu32
|
|
var _ /* ht at bp+4 */ THash
|
|
_, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _ = aCol, db, i, iCol, j, nCol, nName, pCol, pColExpr, pCollide, pTab, pX, zName, v2, v3, v5, v8
|
|
db = (*TParse)(unsafe.Pointer(pParse)).Fdb
|
|
_sqlite3HashInit(tls, bp+4)
|
|
if pEList != 0 {
|
|
nCol = (*TExprList)(unsafe.Pointer(pEList)).FnExpr
|
|
aCol = _sqlite3DbMallocZero(tls, db, uint64(uint32(12)*libc.Uint32FromInt32(nCol)))
|
|
if nCol > int32(32767) {
|
|
nCol = int32(32767)
|
|
}
|
|
} else {
|
|
nCol = 0
|
|
aCol = uintptr(0)
|
|
}
|
|
**(**Ti16)(__ccgo_up(pnCol)) = int16(nCol)
|
|
**(**uintptr)(__ccgo_up(paCol)) = aCol
|
|
i = 0
|
|
pCol = aCol
|
|
for {
|
|
if !(i < nCol && !((*TParse)(unsafe.Pointer(pParse)).FnErr != 0)) {
|
|
break
|
|
}
|
|
pX = pEList + 8 + uintptr(i)*20
|
|
/* Get an appropriate name for the column
|
|
*/
|
|
v2 = (*TExprList_item)(unsafe.Pointer(pX)).FzEName
|
|
zName = v2
|
|
if v2 != uintptr(0) && int32(uint32(*(*uint16)(unsafe.Pointer(pX + 8 + 4))&0x3>>0)) == ENAME_NAME {
|
|
/* If the column contains an "AS <name>" phrase, use <name> as the name */
|
|
} else {
|
|
pColExpr = _sqlite3ExprSkipCollateAndLikely(tls, (*TExprList_item)(unsafe.Pointer(pX)).FpExpr)
|
|
for pColExpr != uintptr(0) && libc.Int32FromUint8((*TExpr)(unsafe.Pointer(pColExpr)).Fop) == int32(TK_DOT) {
|
|
pColExpr = (*TExpr)(unsafe.Pointer(pColExpr)).FpRight
|
|
}
|
|
if libc.Int32FromUint8((*TExpr)(unsafe.Pointer(pColExpr)).Fop) == int32(TK_COLUMN) && (*TExpr)(unsafe.Pointer(pColExpr)).Fflags&libc.Uint32FromInt32(libc.Int32FromInt32(EP_WinFunc)|libc.Int32FromInt32(EP_Subrtn)) == uint32(0) && (*TExpr)(unsafe.Pointer(pColExpr)).Fy.FpTab != uintptr(0) {
|
|
/* For columns use the column name name */
|
|
iCol = int32((*TExpr)(unsafe.Pointer(pColExpr)).FiColumn)
|
|
pTab = (*TExpr)(unsafe.Pointer(pColExpr)).Fy.FpTab
|
|
if iCol < 0 {
|
|
iCol = int32((*TTable)(unsafe.Pointer(pTab)).FiPKey)
|
|
}
|
|
if iCol >= 0 {
|
|
v2 = (**(**TColumn)(__ccgo_up((*TTable)(unsafe.Pointer(pTab)).FaCol + uintptr(iCol)*12))).FzCnName
|
|
} else {
|
|
v2 = __ccgo_ts + 17965
|
|
}
|
|
zName = v2
|
|
} else {
|
|
if libc.Int32FromUint8((*TExpr)(unsafe.Pointer(pColExpr)).Fop) == int32(TK_ID) {
|
|
zName = *(*uintptr)(unsafe.Pointer(pColExpr + 8))
|
|
} else {
|
|
/* Use the original text of the column expression as its name */
|
|
/* pointer comparison intended */
|
|
}
|
|
}
|
|
}
|
|
if zName != 0 && !(_sqlite3IsTrueOrFalse(tls, zName) != 0) {
|
|
zName = _sqlite3DbStrDup(tls, db, zName)
|
|
} else {
|
|
zName = _sqlite3MPrintf(tls, db, __ccgo_ts+20634, libc.VaList(bp+32, i+int32(1)))
|
|
}
|
|
/* Make sure the column name is unique. If the name is not unique,
|
|
** append an integer to the name so that it becomes unique.
|
|
*/
|
|
**(**Tu32)(__ccgo_up(bp)) = uint32(0)
|
|
for {
|
|
if v5 = zName != 0; v5 {
|
|
v2 = _sqlite3HashFind(tls, bp+4, zName)
|
|
pCollide = v2
|
|
}
|
|
if !(v5 && v2 != uintptr(0)) {
|
|
break
|
|
}
|
|
if int32(uint32(*(*uint16)(unsafe.Pointer(pCollide + 8 + 4))&0x80>>7)) != 0 {
|
|
v3 = pCol + 10
|
|
*(*Tu16)(unsafe.Pointer(v3)) = Tu16(int32(*(*Tu16)(unsafe.Pointer(v3))) | libc.Int32FromInt32(COLFLAG_NOEXPAND))
|
|
}
|
|
nName = _sqlite3Strlen30(tls, zName)
|
|
if nName > 0 {
|
|
j = nName - int32(1)
|
|
for {
|
|
if !(j > 0 && libc.Int32FromUint8(_sqlite3CtypeMap[libc.Uint8FromInt8(**(**int8)(__ccgo_up(zName + uintptr(j))))])&int32(0x04) != 0) {
|
|
break
|
|
}
|
|
goto _7
|
|
_7:
|
|
;
|
|
j = j - 1
|
|
}
|
|
if int32(**(**int8)(__ccgo_up(zName + uintptr(j)))) == int32(':') {
|
|
nName = j
|
|
}
|
|
}
|
|
**(**Tu32)(__ccgo_up(bp)) = **(**Tu32)(__ccgo_up(bp)) + 1
|
|
v8 = **(**Tu32)(__ccgo_up(bp))
|
|
zName = _sqlite3MPrintf(tls, db, __ccgo_ts+20643, libc.VaList(bp+32, nName, zName, v8))
|
|
_sqlite3ProgressCheck(tls, pParse)
|
|
if **(**Tu32)(__ccgo_up(bp)) > uint32(3) {
|
|
Xsqlite3_randomness(tls, int32(4), bp)
|
|
}
|
|
}
|
|
(*TColumn)(unsafe.Pointer(pCol)).FzCnName = zName
|
|
(*TColumn)(unsafe.Pointer(pCol)).FhName = _sqlite3StrIHash(tls, zName)
|
|
if int32(uint32(*(*uint16)(unsafe.Pointer(pX + 8 + 4))&0x100>>8)) != 0 {
|
|
v2 = pCol + 10
|
|
*(*Tu16)(unsafe.Pointer(v2)) = Tu16(int32(*(*Tu16)(unsafe.Pointer(v2))) | libc.Int32FromInt32(COLFLAG_NOEXPAND))
|
|
}
|
|
if zName != 0 && _sqlite3HashInsert(tls, bp+4, zName, pX) == pX {
|
|
_sqlite3OomFault(tls, db)
|
|
}
|
|
goto _1
|
|
_1:
|
|
;
|
|
i = i + 1
|
|
pCol += 12
|
|
}
|
|
_sqlite3HashClear(tls, bp+4)
|
|
if (*TParse)(unsafe.Pointer(pParse)).FnErr != 0 {
|
|
j = 0
|
|
for {
|
|
if !(j < i) {
|
|
break
|
|
}
|
|
_sqlite3DbFree(tls, db, (**(**TColumn)(__ccgo_up(aCol + uintptr(j)*12))).FzCnName)
|
|
goto _10
|
|
_10:
|
|
;
|
|
j = j + 1
|
|
}
|
|
_sqlite3DbFree(tls, db, aCol)
|
|
**(**uintptr)(__ccgo_up(paCol)) = uintptr(0)
|
|
**(**Ti16)(__ccgo_up(pnCol)) = 0
|
|
return (*TParse)(unsafe.Pointer(pParse)).Frc
|
|
}
|
|
return SQLITE_OK
|
|
}
|
|
|
|
// C documentation
|
|
//
|
|
// /*
|
|
// ** All regular columns for table pTab have been puts into registers
|
|
// ** starting with iRegStore. The registers that correspond to STORED
|
|
// ** or VIRTUAL columns have not yet been initialized. This routine goes
|
|
// ** back and computes the values for those columns based on the previously
|
|
// ** computed normal columns.
|
|
// */
|
|
func _sqlite3ComputeGeneratedColumns(tls *libc.TLS, pParse uintptr, iRegStore int32, pTab uintptr) {
|
|
bp := tls.Alloc(48)
|
|
defer tls.Free(48)
|
|
var eProgress, i, ii, jj, x, v2 int32
|
|
var pCol, pOp, pRedo, zP4, v4 uintptr
|
|
var _ /* w at bp+0 */ TWalker
|
|
_, _, _, _, _, _, _, _, _, _, _ = eProgress, i, ii, jj, pCol, pOp, pRedo, x, zP4, v2, v4
|
|
/* Before computing generated columns, first go through and make sure
|
|
** that appropriate affinity has been applied to the regular columns
|
|
*/
|
|
_sqlite3TableAffinity(tls, (*TParse)(unsafe.Pointer(pParse)).FpVdbe, pTab, iRegStore)
|
|
if (*TTable)(unsafe.Pointer(pTab)).FtabFlags&uint32(TF_HasStored) != uint32(0) {
|
|
pOp = _sqlite3VdbeGetLastOp(tls, (*TParse)(unsafe.Pointer(pParse)).FpVdbe)
|
|
if libc.Int32FromUint8((*TVdbeOp)(unsafe.Pointer(pOp)).Fopcode) == int32(OP_Affinity) {
|
|
zP4 = *(*uintptr)(unsafe.Pointer(pOp + 16))
|
|
v2 = libc.Int32FromInt32(0)
|
|
jj = v2
|
|
ii = v2
|
|
for {
|
|
if !(**(**int8)(__ccgo_up(zP4 + uintptr(jj))) != 0) {
|
|
break
|
|
}
|
|
if libc.Int32FromUint16((**(**TColumn)(__ccgo_up((*TTable)(unsafe.Pointer(pTab)).FaCol + uintptr(ii)*12))).FcolFlags)&int32(COLFLAG_VIRTUAL) != 0 {
|
|
goto _1
|
|
}
|
|
if libc.Int32FromUint16((**(**TColumn)(__ccgo_up((*TTable)(unsafe.Pointer(pTab)).FaCol + uintptr(ii)*12))).FcolFlags)&int32(COLFLAG_STORED) != 0 {
|
|
**(**int8)(__ccgo_up(zP4 + uintptr(jj))) = int8(SQLITE_AFF_NONE)
|
|
}
|
|
jj = jj + 1
|
|
goto _1
|
|
_1:
|
|
;
|
|
ii = ii + 1
|
|
}
|
|
} else {
|
|
if libc.Int32FromUint8((*TVdbeOp)(unsafe.Pointer(pOp)).Fopcode) == int32(OP_TypeCheck) {
|
|
/* If an OP_TypeCheck was generated because the table is STRICT,
|
|
** then set the P3 operand to indicate that generated columns should
|
|
** not be checked */
|
|
(*TVdbeOp)(unsafe.Pointer(pOp)).Fp3 = int32(1)
|
|
}
|
|
}
|
|
}
|
|
/* Because there can be multiple generated columns that refer to one another,
|
|
** this is a two-pass algorithm. On the first pass, mark all generated
|
|
** columns as "not available".
|
|
*/
|
|
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)*12))).FcolFlags)&int32(COLFLAG_GENERATED) != 0 {
|
|
v4 = (*TTable)(unsafe.Pointer(pTab)).FaCol + uintptr(i)*12 + 10
|
|
*(*Tu16)(unsafe.Pointer(v4)) = Tu16(int32(*(*Tu16)(unsafe.Pointer(v4))) | libc.Int32FromInt32(COLFLAG_NOTAVAIL))
|
|
}
|
|
goto _3
|
|
_3:
|
|
;
|
|
i = i + 1
|
|
}
|
|
*(*uintptr)(unsafe.Pointer(bp + 24)) = pTab
|
|
(**(**TWalker)(__ccgo_up(bp))).FxExprCallback = __ccgo_fp(_exprColumnFlagUnion)
|
|
(**(**TWalker)(__ccgo_up(bp))).FxSelectCallback = uintptr(0)
|
|
(**(**TWalker)(__ccgo_up(bp))).FxSelectCallback2 = uintptr(0)
|
|
/* On the second pass, compute the value of each NOT-AVAILABLE column.
|
|
** Companion code in the TK_COLUMN case of sqlite3ExprCodeTarget() will
|
|
** compute dependencies and mark remove the COLSPAN_NOTAVAIL mark, as
|
|
** they are needed.
|
|
*/
|
|
(*TParse)(unsafe.Pointer(pParse)).FiSelfTab = -iRegStore
|
|
for cond := true; cond; cond = pRedo != 0 && eProgress != 0 {
|
|
eProgress = 0
|
|
pRedo = uintptr(0)
|
|
i = 0
|
|
for {
|
|
if !(i < int32((*TTable)(unsafe.Pointer(pTab)).FnCol)) {
|
|
break
|
|
}
|
|
pCol = (*TTable)(unsafe.Pointer(pTab)).FaCol + uintptr(i)*12
|
|
if libc.Int32FromUint16((*TColumn)(unsafe.Pointer(pCol)).FcolFlags)&int32(COLFLAG_NOTAVAIL) != 0 {
|
|
v4 = pCol + 10
|
|
*(*Tu16)(unsafe.Pointer(v4)) = Tu16(int32(*(*Tu16)(unsafe.Pointer(v4))) | libc.Int32FromInt32(COLFLAG_BUSY))
|
|
(**(**TWalker)(__ccgo_up(bp))).FeCode = uint16(0)
|
|
_sqlite3WalkExpr(tls, bp, _sqlite3ColumnExpr(tls, pTab, pCol))
|
|
v4 = pCol + 10
|
|
*(*Tu16)(unsafe.Pointer(v4)) = Tu16(int32(*(*Tu16)(unsafe.Pointer(v4))) & ^libc.Int32FromInt32(COLFLAG_BUSY))
|
|
if libc.Int32FromUint16((**(**TWalker)(__ccgo_up(bp))).FeCode)&int32(COLFLAG_NOTAVAIL) != 0 {
|
|
pRedo = pCol
|
|
goto _5
|
|
}
|
|
eProgress = int32(1)
|
|
x = int32(_sqlite3TableColumnToStorage(tls, pTab, int16(i))) + iRegStore
|
|
_sqlite3ExprCodeGeneratedColumn(tls, pParse, pTab, pCol, x)
|
|
v4 = pCol + 10
|
|
*(*Tu16)(unsafe.Pointer(v4)) = Tu16(int32(*(*Tu16)(unsafe.Pointer(v4))) & ^libc.Int32FromInt32(COLFLAG_NOTAVAIL))
|
|
}
|
|
goto _5
|
|
_5:
|
|
;
|
|
i = i + 1
|
|
}
|
|
}
|
|
if pRedo != 0 {
|
|
_sqlite3ErrorMsg(tls, pParse, __ccgo_ts+8454, libc.VaList(bp+40, (*TColumn)(unsafe.Pointer(pRedo)).FzCnName))
|
|
}
|
|
(*TParse)(unsafe.Pointer(pParse)).FiSelfTab = 0
|
|
}
|
|
|
|
// C documentation
|
|
//
|
|
// /*
|
|
// ** This routine is called to create a new foreign key on the table
|
|
// ** currently under construction. pFromCol determines which columns
|
|
// ** in the current table point to the foreign key. If pFromCol==0 then
|
|
// ** connect the key to the last column inserted. pTo is the name of
|
|
// ** the table referred to (a.k.a the "parent" table). pToCol is a list
|
|
// ** of tables in the parent pTo table. flags contains all
|
|
// ** information about the conflict resolution algorithms specified
|
|
// ** in the ON DELETE, ON UPDATE and ON INSERT clauses.
|
|
// **
|
|
// ** An FKey structure is created and added to the table currently
|
|
// ** under construction in the pParse->pNewTable field.
|
|
// **
|
|
// ** The foreign key is set for IMMEDIATE processing. A subsequent call
|
|
// ** to sqlite3DeferForeignKey() might change this to DEFERRED.
|
|
// */
|
|
func _sqlite3CreateForeignKey(tls *libc.TLS, pParse uintptr, pFromCol uintptr, pTo uintptr, pToCol uintptr, flags int32) {
|
|
bp := tls.Alloc(32)
|
|
defer tls.Free(32)
|
|
var db, p, pFKey, pNextTo, z uintptr
|
|
var i, iCol, j, n, nCol int32
|
|
var nByte Ti64
|
|
_, _, _, _, _, _, _, _, _, _, _ = db, i, iCol, j, n, nByte, nCol, p, pFKey, pNextTo, z
|
|
db = (*TParse)(unsafe.Pointer(pParse)).Fdb
|
|
pFKey = uintptr(0)
|
|
p = (*TParse)(unsafe.Pointer(pParse)).FpNewTable
|
|
if p == uintptr(0) || libc.Int32FromUint8((*TParse)(unsafe.Pointer(pParse)).FeParseMode) == int32(PARSE_MODE_DECLARE_VTAB) {
|
|
goto fk_end
|
|
}
|
|
if pFromCol == uintptr(0) {
|
|
iCol = int32((*TTable)(unsafe.Pointer(p)).FnCol) - int32(1)
|
|
if iCol < 0 {
|
|
goto fk_end
|
|
}
|
|
if pToCol != 0 && (*TExprList)(unsafe.Pointer(pToCol)).FnExpr != int32(1) {
|
|
_sqlite3ErrorMsg(tls, pParse, __ccgo_ts+15173, libc.VaList(bp+8, (**(**TColumn)(__ccgo_up((*TTable)(unsafe.Pointer(p)).FaCol + uintptr(iCol)*12))).FzCnName, pTo))
|
|
goto fk_end
|
|
}
|
|
nCol = int32(1)
|
|
} else {
|
|
if pToCol != 0 && (*TExprList)(unsafe.Pointer(pToCol)).FnExpr != (*TExprList)(unsafe.Pointer(pFromCol)).FnExpr {
|
|
_sqlite3ErrorMsg(tls, pParse, __ccgo_ts+15236, 0)
|
|
goto fk_end
|
|
} else {
|
|
nCol = (*TExprList)(unsafe.Pointer(pFromCol)).FnExpr
|
|
}
|
|
}
|
|
nByte = libc.Int64FromUint32(uint32(libc.UintptrFromInt32(0)+36) + libc.Uint32FromInt32(nCol)*uint32(8) + (*TToken)(unsafe.Pointer(pTo)).Fn + uint32(1))
|
|
if pToCol != 0 {
|
|
i = 0
|
|
for {
|
|
if !(i < (*TExprList)(unsafe.Pointer(pToCol)).FnExpr) {
|
|
break
|
|
}
|
|
nByte = nByte + int64(_sqlite3Strlen30(tls, (*(*TExprList_item)(unsafe.Pointer(pToCol + 8 + uintptr(i)*20))).FzEName)+int32(1))
|
|
goto _1
|
|
_1:
|
|
;
|
|
i = i + 1
|
|
}
|
|
}
|
|
pFKey = _sqlite3DbMallocZero(tls, db, libc.Uint64FromInt64(nByte))
|
|
if pFKey == uintptr(0) {
|
|
goto fk_end
|
|
}
|
|
(*TFKey)(unsafe.Pointer(pFKey)).FpFrom = p
|
|
(*TFKey)(unsafe.Pointer(pFKey)).FpNextFrom = (*(*struct {
|
|
FaddColOffset int32
|
|
FpFKey uintptr
|
|
FpDfltList uintptr
|
|
})(unsafe.Pointer(p + 44))).FpFKey
|
|
z = pFKey + 36 + uintptr(nCol)*8
|
|
(*TFKey)(unsafe.Pointer(pFKey)).FzTo = z
|
|
if libc.Int32FromUint8((*TParse)(unsafe.Pointer(pParse)).FeParseMode) >= int32(PARSE_MODE_RENAME) {
|
|
_sqlite3RenameTokenMap(tls, pParse, z, pTo)
|
|
}
|
|
libc.Xmemcpy(tls, z, (*TToken)(unsafe.Pointer(pTo)).Fz, (*TToken)(unsafe.Pointer(pTo)).Fn)
|
|
**(**int8)(__ccgo_up(z + uintptr((*TToken)(unsafe.Pointer(pTo)).Fn))) = 0
|
|
_sqlite3Dequote(tls, z)
|
|
z = z + uintptr((*TToken)(unsafe.Pointer(pTo)).Fn+uint32(1))
|
|
(*TFKey)(unsafe.Pointer(pFKey)).FnCol = nCol
|
|
if pFromCol == uintptr(0) {
|
|
(*(*TsColMap)(unsafe.Pointer(pFKey + 36))).FiFrom = int32((*TTable)(unsafe.Pointer(p)).FnCol) - int32(1)
|
|
} else {
|
|
i = 0
|
|
for {
|
|
if !(i < nCol) {
|
|
break
|
|
}
|
|
j = 0
|
|
for {
|
|
if !(j < int32((*TTable)(unsafe.Pointer(p)).FnCol)) {
|
|
break
|
|
}
|
|
if _sqlite3StrICmp(tls, (**(**TColumn)(__ccgo_up((*TTable)(unsafe.Pointer(p)).FaCol + uintptr(j)*12))).FzCnName, (*(*TExprList_item)(unsafe.Pointer(pFromCol + 8 + uintptr(i)*20))).FzEName) == 0 {
|
|
(*(*TsColMap)(unsafe.Pointer(pFKey + 36 + uintptr(i)*8))).FiFrom = j
|
|
break
|
|
}
|
|
goto _3
|
|
_3:
|
|
;
|
|
j = j + 1
|
|
}
|
|
if j >= int32((*TTable)(unsafe.Pointer(p)).FnCol) {
|
|
_sqlite3ErrorMsg(tls, pParse, __ccgo_ts+15330, libc.VaList(bp+8, (*(*TExprList_item)(unsafe.Pointer(pFromCol + 8 + uintptr(i)*20))).FzEName))
|
|
goto fk_end
|
|
}
|
|
if libc.Int32FromUint8((*TParse)(unsafe.Pointer(pParse)).FeParseMode) >= int32(PARSE_MODE_RENAME) {
|
|
_sqlite3RenameTokenRemap(tls, pParse, pFKey+36+uintptr(i)*8, (*(*TExprList_item)(unsafe.Pointer(pFromCol + 8 + uintptr(i)*20))).FzEName)
|
|
}
|
|
goto _2
|
|
_2:
|
|
;
|
|
i = i + 1
|
|
}
|
|
}
|
|
if pToCol != 0 {
|
|
i = 0
|
|
for {
|
|
if !(i < nCol) {
|
|
break
|
|
}
|
|
n = _sqlite3Strlen30(tls, (*(*TExprList_item)(unsafe.Pointer(pToCol + 8 + uintptr(i)*20))).FzEName)
|
|
(*(*TsColMap)(unsafe.Pointer(pFKey + 36 + uintptr(i)*8))).FzCol = z
|
|
if libc.Int32FromUint8((*TParse)(unsafe.Pointer(pParse)).FeParseMode) >= int32(PARSE_MODE_RENAME) {
|
|
_sqlite3RenameTokenRemap(tls, pParse, z, (*(*TExprList_item)(unsafe.Pointer(pToCol + 8 + uintptr(i)*20))).FzEName)
|
|
}
|
|
libc.Xmemcpy(tls, z, (*(*TExprList_item)(unsafe.Pointer(pToCol + 8 + uintptr(i)*20))).FzEName, libc.Uint32FromInt32(n))
|
|
**(**int8)(__ccgo_up(z + uintptr(n))) = 0
|
|
z = z + uintptr(n+int32(1))
|
|
goto _4
|
|
_4:
|
|
;
|
|
i = i + 1
|
|
}
|
|
}
|
|
(*TFKey)(unsafe.Pointer(pFKey)).FisDeferred = uint8(0)
|
|
**(**Tu8)(__ccgo_up(pFKey + 25)) = libc.Uint8FromInt32(flags & libc.Int32FromInt32(0xff)) /* ON DELETE action */
|
|
**(**Tu8)(__ccgo_up(pFKey + 25 + 1)) = libc.Uint8FromInt32(flags >> libc.Int32FromInt32(8) & libc.Int32FromInt32(0xff)) /* ON UPDATE action */
|
|
pNextTo = _sqlite3HashInsert(tls, (*TTable)(unsafe.Pointer(p)).FpSchema+56, (*TFKey)(unsafe.Pointer(pFKey)).FzTo, pFKey)
|
|
if pNextTo == pFKey {
|
|
_sqlite3OomFault(tls, db)
|
|
goto fk_end
|
|
}
|
|
if pNextTo != 0 {
|
|
(*TFKey)(unsafe.Pointer(pFKey)).FpNextTo = pNextTo
|
|
(*TFKey)(unsafe.Pointer(pNextTo)).FpPrevTo = pFKey
|
|
}
|
|
/* Link the foreign key to the table as the last step.
|
|
*/
|
|
(*(*struct {
|
|
FaddColOffset int32
|
|
FpFKey uintptr
|
|
FpDfltList uintptr
|
|
})(unsafe.Pointer(p + 44))).FpFKey = pFKey
|
|
pFKey = uintptr(0)
|
|
goto fk_end
|
|
fk_end:
|
|
;
|
|
_sqlite3DbFree(tls, db, pFKey)
|
|
_sqlite3ExprListDelete(tls, db, pFromCol)
|
|
_sqlite3ExprListDelete(tls, db, pToCol)
|
|
}
|
|
|
|
// C documentation
|
|
//
|
|
// /*
|
|
// ** Create a new index for an SQL table. pName1.pName2 is the name of the index
|
|
// ** and pTblList is the name of the table that is to be indexed. Both will
|
|
// ** be NULL for a primary key or an index that is created to satisfy a
|
|
// ** UNIQUE constraint. If pTable and pIndex are NULL, use pParse->pNewTable
|
|
// ** as the table to be indexed. pParse->pNewTable is a table that is
|
|
// ** currently being constructed by a CREATE TABLE statement.
|
|
// **
|
|
// ** pList is a list of columns to be indexed. pList will be NULL if this
|
|
// ** is a primary key or unique-constraint on the most recent column added
|
|
// ** to the table currently under construction.
|
|
// */
|
|
func _sqlite3CreateIndex(tls *libc.TLS, pParse uintptr, pName1 uintptr, pName2 uintptr, pTblName uintptr, pList uintptr, onError int32, pStart uintptr, pPIWhere uintptr, sortOrder int32, ifNotExist int32, idxType Tu8) {
|
|
bp := tls.Alloc(128)
|
|
defer tls.Free(128)
|
|
var db, p, pCExpr, pCol, pDb, pExpr, pIdx, pIndex, pListItem, pLoop, pNext, pPk, pTab, pThis, ppFrom, v, z1, z2, zColl, zDb, zName, zStmt, v2 uintptr
|
|
var i, iDb, iMem, j, k, n, n1, nColl, nExtra, nExtraCol, nName, requestedSortOrder, sortOrderMask, x, v5 int32
|
|
var _ /* pName at bp+52 */ uintptr
|
|
var _ /* prevCol at bp+64 */ TToken
|
|
var _ /* sFix at bp+0 */ TDbFixer
|
|
var _ /* zExtra at bp+56 */ uintptr
|
|
_, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _ = db, i, iDb, iMem, j, k, n, n1, nColl, nExtra, nExtraCol, nName, p, pCExpr, pCol, pDb, pExpr, pIdx, pIndex, pListItem, pLoop, pNext, pPk, pTab, pThis, ppFrom, requestedSortOrder, sortOrderMask, v, x, z1, z2, zColl, zDb, zName, zStmt, v2, v5
|
|
pTab = uintptr(0) /* Table to be indexed */
|
|
pIndex = uintptr(0) /* The index to be created */
|
|
zName = uintptr(0) /* 1 to honor DESC in index. 0 to ignore. */
|
|
db = (*TParse)(unsafe.Pointer(pParse)).Fdb /* Index of the database that is being written */
|
|
**(**uintptr)(__ccgo_up(bp + 52)) = uintptr(0) /* For looping over pList */
|
|
nExtra = 0 /* Number of extra columns needed */
|
|
**(**uintptr)(__ccgo_up(bp + 56)) = uintptr(0) /* Extra space after the Index object */
|
|
pPk = uintptr(0) /* PRIMARY KEY index for WITHOUT ROWID tables */
|
|
if (*TParse)(unsafe.Pointer(pParse)).FnErr != 0 {
|
|
goto exit_create_index
|
|
}
|
|
if libc.Int32FromUint8((*TParse)(unsafe.Pointer(pParse)).FeParseMode) == int32(PARSE_MODE_DECLARE_VTAB) && libc.Int32FromUint8(idxType) != int32(SQLITE_IDXTYPE_PRIMARYKEY) {
|
|
goto exit_create_index
|
|
}
|
|
if SQLITE_OK != _sqlite3ReadSchema(tls, pParse) {
|
|
goto exit_create_index
|
|
}
|
|
if _sqlite3HasExplicitNulls(tls, pParse, pList) != 0 {
|
|
goto exit_create_index
|
|
}
|
|
/*
|
|
** Find the table that is to be indexed. Return early if not found.
|
|
*/
|
|
if pTblName != uintptr(0) {
|
|
/* Use the two-part index name to determine the database
|
|
** to search for the table. 'Fix' the table name to this db
|
|
** before looking up the table.
|
|
*/
|
|
iDb = _sqlite3TwoPartName(tls, pParse, pName1, pName2, bp+52)
|
|
if iDb < 0 {
|
|
goto exit_create_index
|
|
}
|
|
/* If the index name was unqualified, check if the table
|
|
** is a temp table. If so, set the database to 1. Do not do this
|
|
** if initializing a database schema.
|
|
*/
|
|
if !((*Tsqlite3)(unsafe.Pointer(db)).Finit1.Fbusy != 0) {
|
|
pTab = _sqlite3SrcListLookup(tls, pParse, pTblName)
|
|
if (*TToken)(unsafe.Pointer(pName2)).Fn == uint32(0) && pTab != 0 && (*TTable)(unsafe.Pointer(pTab)).FpSchema == (**(**TDb)(__ccgo_up((*Tsqlite3)(unsafe.Pointer(db)).FaDb + 1*16))).FpSchema {
|
|
iDb = int32(1)
|
|
}
|
|
}
|
|
_sqlite3FixInit(tls, bp, pParse, iDb, __ccgo_ts+15415, **(**uintptr)(__ccgo_up(bp + 52)))
|
|
if _sqlite3FixSrcList(tls, bp, pTblName) != 0 {
|
|
/* Because the parser constructs pTblName from a single identifier,
|
|
** sqlite3FixSrcList can never fail. */
|
|
}
|
|
pTab = _sqlite3LocateTableItem(tls, pParse, uint32(0), pTblName+8)
|
|
if pTab == uintptr(0) {
|
|
goto exit_create_index
|
|
}
|
|
if iDb == int32(1) && (**(**TDb)(__ccgo_up((*Tsqlite3)(unsafe.Pointer(db)).FaDb + uintptr(iDb)*16))).FpSchema != (*TTable)(unsafe.Pointer(pTab)).FpSchema {
|
|
_sqlite3ErrorMsg(tls, pParse, __ccgo_ts+15421, libc.VaList(bp+80, (*TTable)(unsafe.Pointer(pTab)).FzName))
|
|
goto exit_create_index
|
|
}
|
|
if !((*TTable)(unsafe.Pointer(pTab)).FtabFlags&libc.Uint32FromInt32(TF_WithoutRowid) == libc.Uint32FromInt32(0)) {
|
|
pPk = _sqlite3PrimaryKeyIndex(tls, pTab)
|
|
}
|
|
} else {
|
|
pTab = (*TParse)(unsafe.Pointer(pParse)).FpNewTable
|
|
if !(pTab != 0) {
|
|
goto exit_create_index
|
|
}
|
|
iDb = _sqlite3SchemaToIndex(tls, db, (*TTable)(unsafe.Pointer(pTab)).FpSchema)
|
|
}
|
|
pDb = (*Tsqlite3)(unsafe.Pointer(db)).FaDb + uintptr(iDb)*16
|
|
if Xsqlite3_strnicmp(tls, (*TTable)(unsafe.Pointer(pTab)).FzName, __ccgo_ts+6758, int32(7)) == 0 && libc.Int32FromUint8((*Tsqlite3)(unsafe.Pointer(db)).Finit1.Fbusy) == 0 && pTblName != uintptr(0) {
|
|
_sqlite3ErrorMsg(tls, pParse, __ccgo_ts+15471, libc.VaList(bp+80, (*TTable)(unsafe.Pointer(pTab)).FzName))
|
|
goto exit_create_index
|
|
}
|
|
if libc.Int32FromUint8((*TTable)(unsafe.Pointer(pTab)).FeTabType) == int32(TABTYP_VIEW) {
|
|
_sqlite3ErrorMsg(tls, pParse, __ccgo_ts+15499, 0)
|
|
goto exit_create_index
|
|
}
|
|
if libc.Int32FromUint8((*TTable)(unsafe.Pointer(pTab)).FeTabType) == int32(TABTYP_VTAB) {
|
|
_sqlite3ErrorMsg(tls, pParse, __ccgo_ts+15524, 0)
|
|
goto exit_create_index
|
|
}
|
|
/*
|
|
** Find the name of the index. Make sure there is not already another
|
|
** index or table with the same name.
|
|
**
|
|
** Exception: If we are reading the names of permanent indices from the
|
|
** sqlite_schema table (because some other process changed the schema) and
|
|
** one of the index names collides with the name of a temporary table or
|
|
** index, then we will continue to process this index.
|
|
**
|
|
** If pName==0 it means that we are
|
|
** dealing with a primary key or UNIQUE constraint. We have to invent our
|
|
** own name.
|
|
*/
|
|
if **(**uintptr)(__ccgo_up(bp + 52)) != 0 {
|
|
zName = _sqlite3NameFromToken(tls, db, **(**uintptr)(__ccgo_up(bp + 52)))
|
|
if zName == uintptr(0) {
|
|
goto exit_create_index
|
|
}
|
|
if SQLITE_OK != _sqlite3CheckObjectName(tls, pParse, zName, __ccgo_ts+15415, (*TTable)(unsafe.Pointer(pTab)).FzName) {
|
|
goto exit_create_index
|
|
}
|
|
if !(libc.Int32FromUint8((*TParse)(unsafe.Pointer(pParse)).FeParseMode) >= libc.Int32FromInt32(PARSE_MODE_RENAME)) {
|
|
if !((*Tsqlite3)(unsafe.Pointer(db)).Finit1.Fbusy != 0) {
|
|
if _sqlite3FindTable(tls, db, zName, (*TDb)(unsafe.Pointer(pDb)).FzDbSName) != uintptr(0) {
|
|
_sqlite3ErrorMsg(tls, pParse, __ccgo_ts+15558, libc.VaList(bp+80, zName))
|
|
goto exit_create_index
|
|
}
|
|
}
|
|
if _sqlite3FindIndex(tls, db, zName, (*TDb)(unsafe.Pointer(pDb)).FzDbSName) != uintptr(0) {
|
|
if !(ifNotExist != 0) {
|
|
_sqlite3ErrorMsg(tls, pParse, __ccgo_ts+15592, libc.VaList(bp+80, zName))
|
|
} else {
|
|
_sqlite3CodeVerifySchema(tls, pParse, iDb)
|
|
_sqlite3ForceNotReadOnly(tls, pParse)
|
|
}
|
|
goto exit_create_index
|
|
}
|
|
}
|
|
} else {
|
|
pLoop = (*TTable)(unsafe.Pointer(pTab)).FpIndex
|
|
n = libc.Int32FromInt32(1)
|
|
for {
|
|
if !(pLoop != 0) {
|
|
break
|
|
}
|
|
goto _1
|
|
_1:
|
|
;
|
|
pLoop = (*TIndex)(unsafe.Pointer(pLoop)).FpNext
|
|
n = n + 1
|
|
}
|
|
zName = _sqlite3MPrintf(tls, db, __ccgo_ts+15616, libc.VaList(bp+80, (*TTable)(unsafe.Pointer(pTab)).FzName, n))
|
|
if zName == uintptr(0) {
|
|
goto exit_create_index
|
|
}
|
|
/* Automatic index names generated from within sqlite3_declare_vtab()
|
|
** must have names that are distinct from normal automatic index names.
|
|
** The following statement converts "sqlite3_autoindex..." into
|
|
** "sqlite3_butoindex..." in order to make the names distinct.
|
|
** The "vtab_err.test" test demonstrates the need of this statement. */
|
|
if libc.Int32FromUint8((*TParse)(unsafe.Pointer(pParse)).FeParseMode) != PARSE_MODE_NORMAL {
|
|
**(**int8)(__ccgo_up(zName + 7)) = **(**int8)(__ccgo_up(zName + 7)) + 1
|
|
}
|
|
}
|
|
/* Check for authorization to create an index.
|
|
*/
|
|
if !(libc.Int32FromUint8((*TParse)(unsafe.Pointer(pParse)).FeParseMode) >= libc.Int32FromInt32(PARSE_MODE_RENAME)) {
|
|
zDb = (*TDb)(unsafe.Pointer(pDb)).FzDbSName
|
|
if libc.Bool(!(libc.Int32FromInt32(OMIT_TEMPDB) != 0)) && iDb == int32(1) {
|
|
v2 = __ccgo_ts + 6766
|
|
} else {
|
|
v2 = __ccgo_ts + 6286
|
|
}
|
|
if _sqlite3AuthCheck(tls, pParse, int32(SQLITE_INSERT), v2, uintptr(0), zDb) != 0 {
|
|
goto exit_create_index
|
|
}
|
|
i = int32(SQLITE_CREATE_INDEX)
|
|
if libc.Bool(!(libc.Int32FromInt32(OMIT_TEMPDB) != 0)) && iDb == int32(1) {
|
|
i = int32(SQLITE_CREATE_TEMP_INDEX)
|
|
}
|
|
if _sqlite3AuthCheck(tls, pParse, i, zName, (*TTable)(unsafe.Pointer(pTab)).FzName, zDb) != 0 {
|
|
goto exit_create_index
|
|
}
|
|
}
|
|
/* If pList==0, it means this routine was called to make a primary
|
|
** key out of the last column added to the table under construction.
|
|
** So create a fake list to simulate this.
|
|
*/
|
|
if pList == uintptr(0) {
|
|
pCol = (*TTable)(unsafe.Pointer(pTab)).FaCol + uintptr(int32((*TTable)(unsafe.Pointer(pTab)).FnCol)-int32(1))*12
|
|
v2 = pCol + 10
|
|
*(*Tu16)(unsafe.Pointer(v2)) = Tu16(int32(*(*Tu16)(unsafe.Pointer(v2))) | libc.Int32FromInt32(COLFLAG_UNIQUE))
|
|
_sqlite3TokenInit(tls, bp+64, (*TColumn)(unsafe.Pointer(pCol)).FzCnName)
|
|
pList = _sqlite3ExprListAppend(tls, pParse, uintptr(0), _sqlite3ExprAlloc(tls, db, int32(TK_ID), bp+64, 0))
|
|
if pList == uintptr(0) {
|
|
goto exit_create_index
|
|
}
|
|
_sqlite3ExprListSetSortOrder(tls, pList, sortOrder, -int32(1))
|
|
} else {
|
|
_sqlite3ExprListCheckLength(tls, pParse, pList, __ccgo_ts+15415)
|
|
if (*TParse)(unsafe.Pointer(pParse)).FnErr != 0 {
|
|
goto exit_create_index
|
|
}
|
|
}
|
|
/* Figure out how many bytes of space are required to store explicitly
|
|
** specified collation sequence names.
|
|
*/
|
|
i = 0
|
|
for {
|
|
if !(i < (*TExprList)(unsafe.Pointer(pList)).FnExpr) {
|
|
break
|
|
}
|
|
pExpr = (*(*TExprList_item)(unsafe.Pointer(pList + 8 + uintptr(i)*20))).FpExpr
|
|
if libc.Int32FromUint8((*TExpr)(unsafe.Pointer(pExpr)).Fop) == int32(TK_COLLATE) {
|
|
nExtra = nExtra + (int32(1) + _sqlite3Strlen30(tls, *(*uintptr)(unsafe.Pointer(pExpr + 8))))
|
|
}
|
|
goto _4
|
|
_4:
|
|
;
|
|
i = i + 1
|
|
}
|
|
/*
|
|
** Allocate the index structure.
|
|
*/
|
|
nName = _sqlite3Strlen30(tls, zName)
|
|
if pPk != 0 {
|
|
v5 = libc.Int32FromUint16((*TIndex)(unsafe.Pointer(pPk)).FnKeyCol)
|
|
} else {
|
|
v5 = int32(1)
|
|
}
|
|
nExtraCol = v5
|
|
pIndex = _sqlite3AllocateIndexObject(tls, db, (*TExprList)(unsafe.Pointer(pList)).FnExpr+nExtraCol, nName+nExtra+int32(1), bp+56)
|
|
if (*Tsqlite3)(unsafe.Pointer(db)).FmallocFailed != 0 {
|
|
goto exit_create_index
|
|
}
|
|
(*TIndex)(unsafe.Pointer(pIndex)).FzName = **(**uintptr)(__ccgo_up(bp + 56))
|
|
**(**uintptr)(__ccgo_up(bp + 56)) = **(**uintptr)(__ccgo_up(bp + 56)) + uintptr(nName+int32(1))
|
|
libc.Xmemcpy(tls, (*TIndex)(unsafe.Pointer(pIndex)).FzName, zName, libc.Uint32FromInt32(nName+int32(1)))
|
|
(*TIndex)(unsafe.Pointer(pIndex)).FpTable = pTab
|
|
(*TIndex)(unsafe.Pointer(pIndex)).FonError = libc.Uint8FromInt32(onError)
|
|
libc.SetBitFieldPtr16Uint32(pIndex+56, libc.BoolUint32(onError != libc.Int32FromInt32(OE_None)), 3, 0x8)
|
|
libc.SetBitFieldPtr16Uint32(pIndex+56, uint32(idxType), 0, 0x3)
|
|
(*TIndex)(unsafe.Pointer(pIndex)).FpSchema = (**(**TDb)(__ccgo_up((*Tsqlite3)(unsafe.Pointer(db)).FaDb + uintptr(iDb)*16))).FpSchema
|
|
(*TIndex)(unsafe.Pointer(pIndex)).FnKeyCol = libc.Uint16FromInt32((*TExprList)(unsafe.Pointer(pList)).FnExpr)
|
|
if pPIWhere != 0 {
|
|
_sqlite3ResolveSelfReference(tls, pParse, pTab, int32(NC_PartIdx), pPIWhere, uintptr(0))
|
|
(*TIndex)(unsafe.Pointer(pIndex)).FpPartIdxWhere = pPIWhere
|
|
pPIWhere = uintptr(0)
|
|
}
|
|
/* Check to see if we should honor DESC requests on index columns
|
|
*/
|
|
if libc.Int32FromUint8((*TSchema)(unsafe.Pointer((*TDb)(unsafe.Pointer(pDb)).FpSchema)).Ffile_format) >= int32(4) {
|
|
sortOrderMask = -int32(1) /* Honor DESC */
|
|
} else {
|
|
sortOrderMask = 0 /* Ignore DESC */
|
|
}
|
|
/* Analyze the list of expressions that form the terms of the index and
|
|
** report any errors. In the common case where the expression is exactly
|
|
** a table column, store that column in aiColumn[]. For general expressions,
|
|
** populate pIndex->aColExpr and store XN_EXPR (-2) in aiColumn[].
|
|
**
|
|
** TODO: Issue a warning if two or more columns of the index are identical.
|
|
** TODO: Issue a warning if the table primary key is used as part of the
|
|
** index key.
|
|
*/
|
|
pListItem = pList + 8
|
|
if libc.Int32FromUint8((*TParse)(unsafe.Pointer(pParse)).FeParseMode) >= int32(PARSE_MODE_RENAME) {
|
|
(*TIndex)(unsafe.Pointer(pIndex)).FaColExpr = pList
|
|
pList = uintptr(0)
|
|
}
|
|
i = 0
|
|
for {
|
|
if !(i < libc.Int32FromUint16((*TIndex)(unsafe.Pointer(pIndex)).FnKeyCol)) {
|
|
break
|
|
} /* Collation sequence name */
|
|
_sqlite3StringToId(tls, (*TExprList_item)(unsafe.Pointer(pListItem)).FpExpr)
|
|
_sqlite3ResolveSelfReference(tls, pParse, pTab, int32(NC_IdxExpr), (*TExprList_item)(unsafe.Pointer(pListItem)).FpExpr, uintptr(0))
|
|
if (*TParse)(unsafe.Pointer(pParse)).FnErr != 0 {
|
|
goto exit_create_index
|
|
}
|
|
pCExpr = _sqlite3ExprSkipCollate(tls, (*TExprList_item)(unsafe.Pointer(pListItem)).FpExpr)
|
|
if libc.Int32FromUint8((*TExpr)(unsafe.Pointer(pCExpr)).Fop) != int32(TK_COLUMN) {
|
|
if pTab == (*TParse)(unsafe.Pointer(pParse)).FpNewTable {
|
|
_sqlite3ErrorMsg(tls, pParse, __ccgo_ts+15639, 0)
|
|
goto exit_create_index
|
|
}
|
|
if (*TIndex)(unsafe.Pointer(pIndex)).FaColExpr == uintptr(0) {
|
|
(*TIndex)(unsafe.Pointer(pIndex)).FaColExpr = pList
|
|
pList = uintptr(0)
|
|
}
|
|
j = -int32(2)
|
|
**(**Ti16)(__ccgo_up((*TIndex)(unsafe.Pointer(pIndex)).FaiColumn + uintptr(i)*2)) = int16(-libc.Int32FromInt32(2))
|
|
libc.SetBitFieldPtr16Uint32(pIndex+56, libc.Uint32FromInt32(0), 3, 0x8)
|
|
libc.SetBitFieldPtr16Uint32(pIndex+56, libc.Uint32FromInt32(1), 11, 0x800)
|
|
} else {
|
|
j = int32((*TExpr)(unsafe.Pointer(pCExpr)).FiColumn)
|
|
if j < 0 {
|
|
j = int32((*TTable)(unsafe.Pointer(pTab)).FiPKey)
|
|
} else {
|
|
if int32(uint32(*(*uint8)(unsafe.Pointer((*TTable)(unsafe.Pointer(pTab)).FaCol + uintptr(j)*12 + 4))&0xf>>0)) == 0 {
|
|
libc.SetBitFieldPtr16Uint32(pIndex+56, libc.Uint32FromInt32(0), 3, 0x8)
|
|
}
|
|
if libc.Int32FromUint16((**(**TColumn)(__ccgo_up((*TTable)(unsafe.Pointer(pTab)).FaCol + uintptr(j)*12))).FcolFlags)&int32(COLFLAG_VIRTUAL) != 0 {
|
|
libc.SetBitFieldPtr16Uint32(pIndex+56, libc.Uint32FromInt32(1), 10, 0x400)
|
|
libc.SetBitFieldPtr16Uint32(pIndex+56, libc.Uint32FromInt32(1), 11, 0x800)
|
|
}
|
|
}
|
|
**(**Ti16)(__ccgo_up((*TIndex)(unsafe.Pointer(pIndex)).FaiColumn + uintptr(i)*2)) = int16(j)
|
|
}
|
|
zColl = uintptr(0)
|
|
if libc.Int32FromUint8((*TExpr)(unsafe.Pointer((*TExprList_item)(unsafe.Pointer(pListItem)).FpExpr)).Fop) == int32(TK_COLLATE) {
|
|
zColl = *(*uintptr)(unsafe.Pointer((*TExprList_item)(unsafe.Pointer(pListItem)).FpExpr + 8))
|
|
nColl = _sqlite3Strlen30(tls, zColl) + int32(1)
|
|
libc.Xmemcpy(tls, **(**uintptr)(__ccgo_up(bp + 56)), zColl, libc.Uint32FromInt32(nColl))
|
|
zColl = **(**uintptr)(__ccgo_up(bp + 56))
|
|
**(**uintptr)(__ccgo_up(bp + 56)) = **(**uintptr)(__ccgo_up(bp + 56)) + uintptr(nColl)
|
|
nExtra = nExtra - nColl
|
|
} else {
|
|
if j >= 0 {
|
|
zColl = _sqlite3ColumnColl(tls, (*TTable)(unsafe.Pointer(pTab)).FaCol+uintptr(j)*12)
|
|
}
|
|
}
|
|
if !(zColl != 0) {
|
|
zColl = uintptr(unsafe.Pointer(&_sqlite3StrBINARY))
|
|
}
|
|
if !((*Tsqlite3)(unsafe.Pointer(db)).Finit1.Fbusy != 0) && !(_sqlite3LocateCollSeq(tls, pParse, zColl) != 0) {
|
|
goto exit_create_index
|
|
}
|
|
**(**uintptr)(__ccgo_up((*TIndex)(unsafe.Pointer(pIndex)).FazColl + uintptr(i)*4)) = zColl
|
|
requestedSortOrder = libc.Int32FromUint8((*TExprList_item)(unsafe.Pointer(pListItem)).Ffg.FsortFlags) & sortOrderMask
|
|
**(**Tu8)(__ccgo_up((*TIndex)(unsafe.Pointer(pIndex)).FaSortOrder + uintptr(i))) = libc.Uint8FromInt32(requestedSortOrder)
|
|
goto _6
|
|
_6:
|
|
;
|
|
i = i + 1
|
|
pListItem += 20
|
|
}
|
|
/* Append the table key to the end of the index. For WITHOUT ROWID
|
|
** tables (when pPk!=0) this will be the declared PRIMARY KEY. For
|
|
** normal tables (when pPk==0) this will be the rowid.
|
|
*/
|
|
if pPk != 0 {
|
|
j = 0
|
|
for {
|
|
if !(j < libc.Int32FromUint16((*TIndex)(unsafe.Pointer(pPk)).FnKeyCol)) {
|
|
break
|
|
}
|
|
x = int32(**(**Ti16)(__ccgo_up((*TIndex)(unsafe.Pointer(pPk)).FaiColumn + uintptr(j)*2)))
|
|
if _isDupColumn(tls, pIndex, libc.Int32FromUint16((*TIndex)(unsafe.Pointer(pIndex)).FnKeyCol), pPk, j) != 0 {
|
|
(*TIndex)(unsafe.Pointer(pIndex)).FnColumn = (*TIndex)(unsafe.Pointer(pIndex)).FnColumn - 1
|
|
} else {
|
|
**(**Ti16)(__ccgo_up((*TIndex)(unsafe.Pointer(pIndex)).FaiColumn + uintptr(i)*2)) = int16(x)
|
|
**(**uintptr)(__ccgo_up((*TIndex)(unsafe.Pointer(pIndex)).FazColl + uintptr(i)*4)) = **(**uintptr)(__ccgo_up((*TIndex)(unsafe.Pointer(pPk)).FazColl + uintptr(j)*4))
|
|
**(**Tu8)(__ccgo_up((*TIndex)(unsafe.Pointer(pIndex)).FaSortOrder + uintptr(i))) = **(**Tu8)(__ccgo_up((*TIndex)(unsafe.Pointer(pPk)).FaSortOrder + uintptr(j)))
|
|
i = i + 1
|
|
}
|
|
goto _7
|
|
_7:
|
|
;
|
|
j = j + 1
|
|
}
|
|
} else {
|
|
**(**Ti16)(__ccgo_up((*TIndex)(unsafe.Pointer(pIndex)).FaiColumn + uintptr(i)*2)) = int16(-libc.Int32FromInt32(1))
|
|
**(**uintptr)(__ccgo_up((*TIndex)(unsafe.Pointer(pIndex)).FazColl + uintptr(i)*4)) = uintptr(unsafe.Pointer(&_sqlite3StrBINARY))
|
|
}
|
|
_sqlite3DefaultRowEst(tls, pIndex)
|
|
if (*TParse)(unsafe.Pointer(pParse)).FpNewTable == uintptr(0) {
|
|
_estimateIndexWidth(tls, pIndex)
|
|
}
|
|
/* If this index contains every column of its table, then mark
|
|
** it as a covering index */
|
|
_recomputeColumnsNotIndexed(tls, pIndex)
|
|
if pTblName != uintptr(0) && libc.Int32FromUint16((*TIndex)(unsafe.Pointer(pIndex)).FnColumn) >= int32((*TTable)(unsafe.Pointer(pTab)).FnCol) {
|
|
libc.SetBitFieldPtr16Uint32(pIndex+56, libc.Uint32FromInt32(1), 5, 0x20)
|
|
j = 0
|
|
for {
|
|
if !(j < int32((*TTable)(unsafe.Pointer(pTab)).FnCol)) {
|
|
break
|
|
}
|
|
if j == int32((*TTable)(unsafe.Pointer(pTab)).FiPKey) {
|
|
goto _8
|
|
}
|
|
if _sqlite3TableColumnToIndex(tls, pIndex, j) >= 0 {
|
|
goto _8
|
|
}
|
|
libc.SetBitFieldPtr16Uint32(pIndex+56, libc.Uint32FromInt32(0), 5, 0x20)
|
|
break
|
|
goto _8
|
|
_8:
|
|
;
|
|
j = j + 1
|
|
}
|
|
}
|
|
if pTab == (*TParse)(unsafe.Pointer(pParse)).FpNewTable {
|
|
pIdx = (*TTable)(unsafe.Pointer(pTab)).FpIndex
|
|
for {
|
|
if !(pIdx != 0) {
|
|
break
|
|
}
|
|
if libc.Int32FromUint16((*TIndex)(unsafe.Pointer(pIdx)).FnKeyCol) != libc.Int32FromUint16((*TIndex)(unsafe.Pointer(pIndex)).FnKeyCol) {
|
|
goto _9
|
|
}
|
|
k = 0
|
|
for {
|
|
if !(k < libc.Int32FromUint16((*TIndex)(unsafe.Pointer(pIdx)).FnKeyCol)) {
|
|
break
|
|
}
|
|
if int32(**(**Ti16)(__ccgo_up((*TIndex)(unsafe.Pointer(pIdx)).FaiColumn + uintptr(k)*2))) != int32(**(**Ti16)(__ccgo_up((*TIndex)(unsafe.Pointer(pIndex)).FaiColumn + uintptr(k)*2))) {
|
|
break
|
|
}
|
|
z1 = **(**uintptr)(__ccgo_up((*TIndex)(unsafe.Pointer(pIdx)).FazColl + uintptr(k)*4))
|
|
z2 = **(**uintptr)(__ccgo_up((*TIndex)(unsafe.Pointer(pIndex)).FazColl + uintptr(k)*4))
|
|
if _sqlite3StrICmp(tls, z1, z2) != 0 {
|
|
break
|
|
}
|
|
goto _10
|
|
_10:
|
|
;
|
|
k = k + 1
|
|
}
|
|
if k == libc.Int32FromUint16((*TIndex)(unsafe.Pointer(pIdx)).FnKeyCol) {
|
|
if libc.Int32FromUint8((*TIndex)(unsafe.Pointer(pIdx)).FonError) != libc.Int32FromUint8((*TIndex)(unsafe.Pointer(pIndex)).FonError) {
|
|
/* This constraint creates the same index as a previous
|
|
** constraint specified somewhere in the CREATE TABLE statement.
|
|
** However the ON CONFLICT clauses are different. If both this
|
|
** constraint and the previous equivalent constraint have explicit
|
|
** ON CONFLICT clauses this is an error. Otherwise, use the
|
|
** explicitly specified behavior for the index.
|
|
*/
|
|
if !(libc.Int32FromUint8((*TIndex)(unsafe.Pointer(pIdx)).FonError) == int32(OE_Default) || libc.Int32FromUint8((*TIndex)(unsafe.Pointer(pIndex)).FonError) == int32(OE_Default)) {
|
|
_sqlite3ErrorMsg(tls, pParse, __ccgo_ts+15700, libc.VaList(bp+80, 0))
|
|
}
|
|
if libc.Int32FromUint8((*TIndex)(unsafe.Pointer(pIdx)).FonError) == int32(OE_Default) {
|
|
(*TIndex)(unsafe.Pointer(pIdx)).FonError = (*TIndex)(unsafe.Pointer(pIndex)).FonError
|
|
}
|
|
}
|
|
if libc.Int32FromUint8(idxType) == int32(SQLITE_IDXTYPE_PRIMARYKEY) {
|
|
libc.SetBitFieldPtr16Uint32(pIdx+56, uint32(idxType), 0, 0x3)
|
|
}
|
|
if libc.Int32FromUint8((*TParse)(unsafe.Pointer(pParse)).FeParseMode) >= int32(PARSE_MODE_RENAME) {
|
|
(*TIndex)(unsafe.Pointer(pIndex)).FpNext = (*TParse)(unsafe.Pointer(pParse)).FpNewIndex
|
|
(*TParse)(unsafe.Pointer(pParse)).FpNewIndex = pIndex
|
|
pIndex = uintptr(0)
|
|
}
|
|
goto exit_create_index
|
|
}
|
|
goto _9
|
|
_9:
|
|
;
|
|
pIdx = (*TIndex)(unsafe.Pointer(pIdx)).FpNext
|
|
}
|
|
}
|
|
if !(libc.Int32FromUint8((*TParse)(unsafe.Pointer(pParse)).FeParseMode) >= libc.Int32FromInt32(PARSE_MODE_RENAME)) {
|
|
/* Link the new Index structure to its table and to the other
|
|
** in-memory database structures.
|
|
*/
|
|
if (*Tsqlite3)(unsafe.Pointer(db)).Finit1.Fbusy != 0 {
|
|
if pTblName != uintptr(0) {
|
|
(*TIndex)(unsafe.Pointer(pIndex)).Ftnum = (*Tsqlite3)(unsafe.Pointer(db)).Finit1.FnewTnum
|
|
if _sqlite3IndexHasDuplicateRootPage(tls, pIndex) != 0 {
|
|
_sqlite3ErrorMsg(tls, pParse, __ccgo_ts+15742, 0)
|
|
(*TParse)(unsafe.Pointer(pParse)).Frc = _sqlite3CorruptError(tls, int32(130930))
|
|
goto exit_create_index
|
|
}
|
|
}
|
|
p = _sqlite3HashInsert(tls, (*TIndex)(unsafe.Pointer(pIndex)).FpSchema+24, (*TIndex)(unsafe.Pointer(pIndex)).FzName, pIndex)
|
|
if p != 0 {
|
|
/* Malloc must have failed */
|
|
_sqlite3OomFault(tls, db)
|
|
goto exit_create_index
|
|
}
|
|
**(**Tu32)(__ccgo_up(db + 24)) |= uint32(DBFLAG_SchemaChange)
|
|
} else {
|
|
if (*TTable)(unsafe.Pointer(pTab)).FtabFlags&uint32(TF_WithoutRowid) == uint32(0) || pTblName != uintptr(0) {
|
|
v2 = pParse + 48
|
|
*(*int32)(unsafe.Pointer(v2)) = *(*int32)(unsafe.Pointer(v2)) + 1
|
|
v5 = *(*int32)(unsafe.Pointer(v2))
|
|
iMem = v5
|
|
v = _sqlite3GetVdbe(tls, pParse)
|
|
if v == uintptr(0) {
|
|
goto exit_create_index
|
|
}
|
|
_sqlite3BeginWriteOperation(tls, pParse, int32(1), iDb)
|
|
/* Create the rootpage for the index using CreateIndex. But before
|
|
** doing so, code a Noop instruction and store its address in
|
|
** Index.tnum. This is required in case this index is actually a
|
|
** PRIMARY KEY and the table is actually a WITHOUT ROWID table. In
|
|
** that case the convertToWithoutRowidTable() routine will replace
|
|
** the Noop with a Goto to jump over the VDBE code generated below. */
|
|
(*TIndex)(unsafe.Pointer(pIndex)).Ftnum = libc.Uint32FromInt32(_sqlite3VdbeAddOp0(tls, v, int32(OP_Noop)))
|
|
_sqlite3VdbeAddOp3(tls, v, int32(OP_CreateBtree), iDb, iMem, int32(BTREE_BLOBKEY))
|
|
/* Gather the complete text of the CREATE INDEX statement into
|
|
** the zStmt variable
|
|
*/
|
|
if pStart != 0 {
|
|
n1 = libc.Int32FromUint32(libc.Uint32FromInt32(int32((*TParse)(unsafe.Pointer(pParse)).FsLastToken.Fz)-int32((*TToken)(unsafe.Pointer(**(**uintptr)(__ccgo_up(bp + 52)))).Fz)) + (*TParse)(unsafe.Pointer(pParse)).FsLastToken.Fn)
|
|
if int32(**(**int8)(__ccgo_up((*TToken)(unsafe.Pointer(**(**uintptr)(__ccgo_up(bp + 52)))).Fz + uintptr(n1-int32(1))))) == int32(';') {
|
|
n1 = n1 - 1
|
|
}
|
|
/* A named index with an explicit CREATE INDEX statement */
|
|
if onError == OE_None {
|
|
v2 = __ccgo_ts + 1702
|
|
} else {
|
|
v2 = __ccgo_ts + 15759
|
|
}
|
|
zStmt = _sqlite3MPrintf(tls, db, __ccgo_ts+15767, libc.VaList(bp+80, v2, n1, (*TToken)(unsafe.Pointer(**(**uintptr)(__ccgo_up(bp + 52)))).Fz))
|
|
} else {
|
|
/* An automatic index created by a PRIMARY KEY or UNIQUE constraint */
|
|
/* zStmt = sqlite3MPrintf(""); */
|
|
zStmt = uintptr(0)
|
|
}
|
|
/* Add an entry in sqlite_schema for this index
|
|
*/
|
|
_sqlite3NestedParse(tls, pParse, __ccgo_ts+15787, libc.VaList(bp+80, (**(**TDb)(__ccgo_up((*Tsqlite3)(unsafe.Pointer(db)).FaDb + uintptr(iDb)*16))).FzDbSName, (*TIndex)(unsafe.Pointer(pIndex)).FzName, (*TTable)(unsafe.Pointer(pTab)).FzName, iMem, zStmt))
|
|
_sqlite3DbFree(tls, db, zStmt)
|
|
/* Fill the index with data and reparse the schema. Code an OP_Expire
|
|
** to invalidate all pre-compiled statements.
|
|
*/
|
|
if pTblName != 0 {
|
|
_sqlite3RefillIndex(tls, pParse, pIndex, iMem)
|
|
_sqlite3ChangeCookie(tls, pParse, iDb)
|
|
_sqlite3VdbeAddParseSchemaOp(tls, v, iDb, _sqlite3MPrintf(tls, db, __ccgo_ts+15846, libc.VaList(bp+80, (*TIndex)(unsafe.Pointer(pIndex)).FzName)), uint16(0))
|
|
_sqlite3VdbeAddOp2(tls, v, int32(OP_Expire), 0, int32(1))
|
|
}
|
|
_sqlite3VdbeJumpHere(tls, v, libc.Int32FromUint32((*TIndex)(unsafe.Pointer(pIndex)).Ftnum))
|
|
}
|
|
}
|
|
}
|
|
if (*Tsqlite3)(unsafe.Pointer(db)).Finit1.Fbusy != 0 || pTblName == uintptr(0) {
|
|
(*TIndex)(unsafe.Pointer(pIndex)).FpNext = (*TTable)(unsafe.Pointer(pTab)).FpIndex
|
|
(*TTable)(unsafe.Pointer(pTab)).FpIndex = pIndex
|
|
pIndex = uintptr(0)
|
|
} else {
|
|
if libc.Int32FromUint8((*TParse)(unsafe.Pointer(pParse)).FeParseMode) >= int32(PARSE_MODE_RENAME) {
|
|
(*TParse)(unsafe.Pointer(pParse)).FpNewIndex = pIndex
|
|
pIndex = uintptr(0)
|
|
}
|
|
}
|
|
/* Clean up before exiting */
|
|
goto exit_create_index
|
|
exit_create_index:
|
|
;
|
|
if pIndex != 0 {
|
|
_sqlite3FreeIndex(tls, db, pIndex)
|
|
}
|
|
if pTab != 0 {
|
|
ppFrom = pTab + 8
|
|
for {
|
|
v2 = **(**uintptr)(__ccgo_up(ppFrom))
|
|
pThis = v2
|
|
if !(v2 != uintptr(0)) {
|
|
break
|
|
}
|
|
if libc.Int32FromUint8((*TIndex)(unsafe.Pointer(pThis)).FonError) != int32(OE_Replace) {
|
|
goto _14
|
|
}
|
|
for {
|
|
v2 = (*TIndex)(unsafe.Pointer(pThis)).FpNext
|
|
pNext = v2
|
|
if !(v2 != uintptr(0) && libc.Int32FromUint8((*TIndex)(unsafe.Pointer(pNext)).FonError) != int32(OE_Replace)) {
|
|
break
|
|
}
|
|
**(**uintptr)(__ccgo_up(ppFrom)) = pNext
|
|
(*TIndex)(unsafe.Pointer(pThis)).FpNext = (*TIndex)(unsafe.Pointer(pNext)).FpNext
|
|
(*TIndex)(unsafe.Pointer(pNext)).FpNext = pThis
|
|
ppFrom = pNext + 20
|
|
}
|
|
break
|
|
goto _14
|
|
_14:
|
|
;
|
|
ppFrom = pThis + 20
|
|
}
|
|
}
|
|
_sqlite3ExprDelete(tls, db, pPIWhere)
|
|
_sqlite3ExprListDelete(tls, db, pList)
|
|
_sqlite3SrcListDelete(tls, db, pTblName)
|
|
_sqlite3DbFree(tls, db, zName)
|
|
}
|
|
|
|
// C documentation
|
|
//
|
|
// /*
|
|
// ** The parser calls this routine in order to create a new VIEW
|
|
// */
|
|
func _sqlite3CreateView(tls *libc.TLS, pParse uintptr, pBegin uintptr, pName1 uintptr, pName2 uintptr, pCNames uintptr, pSelect uintptr, isTemp int32, noErr int32) {
|
|
bp := tls.Alloc(64)
|
|
defer tls.Free(64)
|
|
var db, p, z uintptr
|
|
var iDb, n int32
|
|
var _ /* pName at bp+60 */ uintptr
|
|
var _ /* sEnd at bp+0 */ TToken
|
|
var _ /* sFix at bp+8 */ TDbFixer
|
|
_, _, _, _, _ = db, iDb, n, p, z
|
|
**(**uintptr)(__ccgo_up(bp + 60)) = uintptr(0)
|
|
db = (*TParse)(unsafe.Pointer(pParse)).Fdb
|
|
if int32((*TParse)(unsafe.Pointer(pParse)).FnVar) > 0 {
|
|
_sqlite3ErrorMsg(tls, pParse, __ccgo_ts+14805, 0)
|
|
goto create_view_fail
|
|
}
|
|
_sqlite3StartTable(tls, pParse, pName1, pName2, isTemp, int32(1), 0, noErr)
|
|
p = (*TParse)(unsafe.Pointer(pParse)).FpNewTable
|
|
if p == uintptr(0) || (*TParse)(unsafe.Pointer(pParse)).FnErr != 0 {
|
|
goto create_view_fail
|
|
}
|
|
/* Legacy versions of SQLite allowed the use of the magic "rowid" column
|
|
** on a view, even though views do not have rowids. The following flag
|
|
** setting fixes this problem. But the fix can be disabled by compiling
|
|
** with -DSQLITE_ALLOW_ROWID_IN_VIEW in case there are legacy apps that
|
|
** depend upon the old buggy behavior. The ability can also be toggled
|
|
** using sqlite3_config(SQLITE_CONFIG_ROWID_IN_VIEW,...) */
|
|
**(**Tu32)(__ccgo_up(p + 28)) |= uint32(TF_NoVisibleRowid) /* Never allow rowid in view */
|
|
_sqlite3TwoPartName(tls, pParse, pName1, pName2, bp+60)
|
|
iDb = _sqlite3SchemaToIndex(tls, db, (*TTable)(unsafe.Pointer(p)).FpSchema)
|
|
_sqlite3FixInit(tls, bp+8, pParse, iDb, __ccgo_ts+11117, **(**uintptr)(__ccgo_up(bp + 60)))
|
|
if _sqlite3FixSelect(tls, bp+8, pSelect) != 0 {
|
|
goto create_view_fail
|
|
}
|
|
/* Make a copy of the entire SELECT statement that defines the view.
|
|
** This will force all the Expr.token.z values to be dynamically
|
|
** allocated rather than point to the input string - which means that
|
|
** they will persist after the current sqlite3_exec() call returns.
|
|
*/
|
|
**(**Tu32)(__ccgo_up(pSelect + 4)) |= uint32(SF_View)
|
|
if libc.Int32FromUint8((*TParse)(unsafe.Pointer(pParse)).FeParseMode) >= int32(PARSE_MODE_RENAME) {
|
|
(*(*struct {
|
|
FpSelect uintptr
|
|
})(unsafe.Pointer(&(*TTable)(unsafe.Pointer(p)).Fu))).FpSelect = pSelect
|
|
pSelect = uintptr(0)
|
|
} else {
|
|
(*(*struct {
|
|
FpSelect uintptr
|
|
})(unsafe.Pointer(&(*TTable)(unsafe.Pointer(p)).Fu))).FpSelect = _sqlite3SelectDup(tls, db, pSelect, int32(EXPRDUP_REDUCE))
|
|
}
|
|
(*TTable)(unsafe.Pointer(p)).FpCheck = _sqlite3ExprListDup(tls, db, pCNames, int32(EXPRDUP_REDUCE))
|
|
(*TTable)(unsafe.Pointer(p)).FeTabType = uint8(TABTYP_VIEW)
|
|
if (*Tsqlite3)(unsafe.Pointer(db)).FmallocFailed != 0 {
|
|
goto create_view_fail
|
|
}
|
|
/* Locate the end of the CREATE VIEW statement. Make sEnd point to
|
|
** the end.
|
|
*/
|
|
**(**TToken)(__ccgo_up(bp)) = (*TParse)(unsafe.Pointer(pParse)).FsLastToken
|
|
if int32(**(**int8)(__ccgo_up((**(**TToken)(__ccgo_up(bp))).Fz))) != int32(';') {
|
|
(**(**TToken)(__ccgo_up(bp))).Fz += uintptr((**(**TToken)(__ccgo_up(bp))).Fn)
|
|
}
|
|
(**(**TToken)(__ccgo_up(bp))).Fn = uint32(0)
|
|
n = int32((**(**TToken)(__ccgo_up(bp))).Fz) - int32((*TToken)(unsafe.Pointer(pBegin)).Fz)
|
|
z = (*TToken)(unsafe.Pointer(pBegin)).Fz
|
|
for libc.Int32FromUint8(_sqlite3CtypeMap[libc.Uint8FromInt8(**(**int8)(__ccgo_up(z + uintptr(n-int32(1)))))])&int32(0x01) != 0 {
|
|
n = n - 1
|
|
}
|
|
(**(**TToken)(__ccgo_up(bp))).Fz = z + uintptr(n-int32(1))
|
|
(**(**TToken)(__ccgo_up(bp))).Fn = uint32(1)
|
|
/* Use sqlite3EndTable() to add the view to the schema table */
|
|
_sqlite3EndTable(tls, pParse, uintptr(0), bp, uint32(0), uintptr(0))
|
|
goto create_view_fail
|
|
create_view_fail:
|
|
;
|
|
_sqlite3SelectDelete(tls, db, pSelect)
|
|
if libc.Int32FromUint8((*TParse)(unsafe.Pointer(pParse)).FeParseMode) >= int32(PARSE_MODE_RENAME) {
|
|
_sqlite3RenameExprlistUnmap(tls, pParse, pCNames)
|
|
}
|
|
_sqlite3ExprListDelete(tls, db, pCNames)
|
|
return
|
|
}
|
|
|
|
// C documentation
|
|
//
|
|
// /*
|
|
// ** Transform a UTF-8 integer literal, in either decimal or hexadecimal,
|
|
// ** into a 64-bit signed integer. This routine accepts hexadecimal literals,
|
|
// ** whereas sqlite3Atoi64() does not.
|
|
// **
|
|
// ** Returns:
|
|
// **
|
|
// ** 0 Successful transformation. Fits in a 64-bit signed integer.
|
|
// ** 1 Excess text after the integer value
|
|
// ** 2 Integer too large for a 64-bit signed integer or is malformed
|
|
// ** 3 Special case of 9223372036854775808
|
|
// */
|
|
func _sqlite3DecOrHexToI64(tls *libc.TLS, z uintptr, pOut uintptr) (r int32) {
|
|
bp := tls.Alloc(16)
|
|
defer tls.Free(16)
|
|
var i, k, n int32
|
|
var _ /* u at bp+0 */ Tu64
|
|
_, _, _ = i, k, n
|
|
if int32(**(**int8)(__ccgo_up(z))) == int32('0') && (int32(**(**int8)(__ccgo_up(z + 1))) == int32('x') || int32(**(**int8)(__ccgo_up(z + 1))) == int32('X')) {
|
|
**(**Tu64)(__ccgo_up(bp)) = uint64(0)
|
|
i = int32(2)
|
|
for {
|
|
if !(int32(**(**int8)(__ccgo_up(z + uintptr(i)))) == int32('0')) {
|
|
break
|
|
}
|
|
goto _1
|
|
_1:
|
|
;
|
|
i = i + 1
|
|
}
|
|
k = i
|
|
for {
|
|
if !(libc.Int32FromUint8(_sqlite3CtypeMap[libc.Uint8FromInt8(**(**int8)(__ccgo_up(z + uintptr(k))))])&int32(0x08) != 0) {
|
|
break
|
|
}
|
|
**(**Tu64)(__ccgo_up(bp)) = **(**Tu64)(__ccgo_up(bp))*uint64(16) + uint64(_sqlite3HexToInt(tls, int32(**(**int8)(__ccgo_up(z + uintptr(k))))))
|
|
goto _2
|
|
_2:
|
|
;
|
|
k = k + 1
|
|
}
|
|
libc.Xmemcpy(tls, pOut, bp, uint32(8))
|
|
if k-i > int32(16) {
|
|
return int32(2)
|
|
}
|
|
if int32(**(**int8)(__ccgo_up(z + uintptr(k)))) != 0 {
|
|
return int32(1)
|
|
}
|
|
return 0
|
|
} else {
|
|
n = libc.Int32FromUint32(libc.Uint32FromInt32(0x3fffffff) & libc.Xstrspn(tls, z, __ccgo_ts+1832))
|
|
if **(**int8)(__ccgo_up(z + uintptr(n))) != 0 {
|
|
n = n + 1
|
|
}
|
|
return _sqlite3Atoi64(tls, z, pOut, n, uint8(SQLITE_UTF8))
|
|
}
|
|
return r
|
|
}
|
|
|
|
// C documentation
|
|
//
|
|
// /*
|
|
// ** Expression p is a QNUMBER (quoted number). Dequote the value in p->u.zToken
|
|
// ** and set the type to INTEGER or FLOAT. "Quoted" integers or floats are those
|
|
// ** that contain '_' characters that must be removed before further processing.
|
|
// */
|
|
func _sqlite3DequoteNumber(tls *libc.TLS, pParse uintptr, p uintptr) {
|
|
bp := tls.Alloc(32)
|
|
defer tls.Free(32)
|
|
var bHex int32
|
|
var pIn, pOut, v1, v3 uintptr
|
|
var _ /* iValue at bp+0 */ int32
|
|
_, _, _, _, _ = bHex, pIn, pOut, v1, v3
|
|
if p != 0 {
|
|
pIn = *(*uintptr)(unsafe.Pointer(p + 8))
|
|
pOut = *(*uintptr)(unsafe.Pointer(p + 8))
|
|
bHex = libc.BoolInt32(int32(**(**int8)(__ccgo_up(pIn))) == int32('0') && (int32(**(**int8)(__ccgo_up(pIn + 1))) == int32('x') || int32(**(**int8)(__ccgo_up(pIn + 1))) == int32('X')))
|
|
(*TExpr)(unsafe.Pointer(p)).Fop = uint8(TK_INTEGER)
|
|
for {
|
|
if int32(**(**int8)(__ccgo_up(pIn))) != int32('_') {
|
|
v3 = pOut
|
|
pOut = pOut + 1
|
|
**(**int8)(__ccgo_up(v3)) = **(**int8)(__ccgo_up(pIn))
|
|
if int32(**(**int8)(__ccgo_up(pIn))) == int32('e') || int32(**(**int8)(__ccgo_up(pIn))) == int32('E') || int32(**(**int8)(__ccgo_up(pIn))) == int32('.') {
|
|
(*TExpr)(unsafe.Pointer(p)).Fop = uint8(TK_FLOAT)
|
|
}
|
|
} else {
|
|
if bHex == 0 && (!(libc.Int32FromUint8(_sqlite3CtypeMap[libc.Uint8FromInt8(**(**int8)(__ccgo_up(pIn + uintptr(-libc.Int32FromInt32(1)))))])&libc.Int32FromInt32(0x04) != 0) || !(libc.Int32FromUint8(_sqlite3CtypeMap[libc.Uint8FromInt8(**(**int8)(__ccgo_up(pIn + 1)))])&libc.Int32FromInt32(0x04) != 0)) || bHex == int32(1) && (!(libc.Int32FromUint8(_sqlite3CtypeMap[libc.Uint8FromInt8(**(**int8)(__ccgo_up(pIn + uintptr(-libc.Int32FromInt32(1)))))])&libc.Int32FromInt32(0x08) != 0) || !(libc.Int32FromUint8(_sqlite3CtypeMap[libc.Uint8FromInt8(**(**int8)(__ccgo_up(pIn + 1)))])&libc.Int32FromInt32(0x08) != 0)) {
|
|
_sqlite3ErrorMsg(tls, pParse, __ccgo_ts+1788, libc.VaList(bp+16, *(*uintptr)(unsafe.Pointer(p + 8))))
|
|
}
|
|
}
|
|
goto _2
|
|
_2:
|
|
;
|
|
v1 = pIn
|
|
pIn = pIn + 1
|
|
if !(**(**int8)(__ccgo_up(v1)) != 0) {
|
|
break
|
|
}
|
|
}
|
|
if bHex != 0 {
|
|
(*TExpr)(unsafe.Pointer(p)).Fop = uint8(TK_INTEGER)
|
|
}
|
|
/* tag-20240227-a: If after dequoting, the number is an integer that
|
|
** fits in 32 bits, then it must be converted into EP_IntValue. Other
|
|
** parts of the code expect this. See also tag-20240227-b. */
|
|
if libc.Int32FromUint8((*TExpr)(unsafe.Pointer(p)).Fop) == int32(TK_INTEGER) && _sqlite3GetInt32(tls, *(*uintptr)(unsafe.Pointer(p + 8)), bp) != 0 {
|
|
*(*int32)(unsafe.Pointer(p + 8)) = **(**int32)(__ccgo_up(bp))
|
|
**(**Tu32)(__ccgo_up(p + 4)) |= uint32(EP_IntValue)
|
|
}
|
|
}
|
|
}
|
|
|
|
// C documentation
|
|
//
|
|
// /*
|
|
// ** This routine is called to report the final ")" that terminates
|
|
// ** a CREATE TABLE statement.
|
|
// **
|
|
// ** The table structure that other action routines have been building
|
|
// ** is added to the internal hash tables, assuming no errors have
|
|
// ** occurred.
|
|
// **
|
|
// ** An entry for the table is made in the schema table on disk, unless
|
|
// ** this is a temporary table or db->init.busy==1. When db->init.busy==1
|
|
// ** it means we are reading the sqlite_schema table because we just
|
|
// ** connected to the database or because the sqlite_schema table has
|
|
// ** recently changed, so the entry for this table already exists in
|
|
// ** the sqlite_schema table. We do not want to create it again.
|
|
// **
|
|
// ** If the pSelect argument is not NULL, it means that this routine
|
|
// ** was called to create a table generated from a
|
|
// ** "CREATE TABLE ... AS SELECT ..." statement. The column names of
|
|
// ** the new table will match the result set of the SELECT.
|
|
// */
|
|
func _sqlite3EndTable(tls *libc.TLS, pParse uintptr, pCons uintptr, pEnd uintptr, tabOpts Tu32, pSelect uintptr) {
|
|
bp := tls.Alloc(96)
|
|
defer tls.Free(96)
|
|
var addrInsLoop, addrTop, iCsr, iDb, ii, ii1, n, nNG, regRec, regRowid, regYield, v4 int32
|
|
var colFlags Tu32
|
|
var db, p, pCol, pDb, pEnd2, pIdx, pOld, pSchema, pSelTab, pX, v, zStmt, zType, zType2, v5 uintptr
|
|
var v12 Ti16
|
|
var _ /* dest at bp+0 */ TSelectDest
|
|
_, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _ = addrInsLoop, addrTop, colFlags, db, iCsr, iDb, ii, ii1, n, nNG, p, pCol, pDb, pEnd2, pIdx, pOld, pSchema, pSelTab, pX, regRec, regRowid, regYield, v, zStmt, zType, zType2, v12, v4, v5 /* The new table */
|
|
db = (*TParse)(unsafe.Pointer(pParse)).Fdb /* An implied index of the table */
|
|
if pEnd == uintptr(0) && pSelect == uintptr(0) {
|
|
return
|
|
}
|
|
p = (*TParse)(unsafe.Pointer(pParse)).FpNewTable
|
|
if p == uintptr(0) {
|
|
return
|
|
}
|
|
if pSelect == uintptr(0) && _sqlite3ShadowTableName(tls, db, (*TTable)(unsafe.Pointer(p)).FzName) != 0 {
|
|
**(**Tu32)(__ccgo_up(p + 28)) |= uint32(TF_Shadow)
|
|
}
|
|
/* If the db->init.busy is 1 it means we are reading the SQL off the
|
|
** "sqlite_schema" or "sqlite_temp_schema" table on the disk.
|
|
** So do not write to the disk again. Extract the root page number
|
|
** for the table from the db->init.newTnum field. (The page number
|
|
** should have been put there by the sqliteOpenCb routine.)
|
|
**
|
|
** If the root page number is 1, that means this is the sqlite_schema
|
|
** table itself. So mark it read-only.
|
|
*/
|
|
if (*Tsqlite3)(unsafe.Pointer(db)).Finit1.Fbusy != 0 {
|
|
if pSelect != 0 || !(libc.Int32FromUint8((*TTable)(unsafe.Pointer(p)).FeTabType) == libc.Int32FromInt32(TABTYP_NORM)) && (*Tsqlite3)(unsafe.Pointer(db)).Finit1.FnewTnum != 0 {
|
|
_sqlite3ErrorMsg(tls, pParse, __ccgo_ts+1702, 0)
|
|
return
|
|
}
|
|
(*TTable)(unsafe.Pointer(p)).Ftnum = (*Tsqlite3)(unsafe.Pointer(db)).Finit1.FnewTnum
|
|
if (*TTable)(unsafe.Pointer(p)).Ftnum == uint32(1) {
|
|
**(**Tu32)(__ccgo_up(p + 28)) |= uint32(TF_Readonly)
|
|
}
|
|
}
|
|
/* Special processing for tables that include the STRICT keyword:
|
|
**
|
|
** * Do not allow custom column datatypes. Every column must have
|
|
** a datatype that is one of INT, INTEGER, REAL, TEXT, or BLOB.
|
|
**
|
|
** * If a PRIMARY KEY is defined, other than the INTEGER PRIMARY KEY,
|
|
** then all columns of the PRIMARY KEY must have a NOT NULL
|
|
** constraint.
|
|
*/
|
|
if tabOpts&uint32(TF_Strict) != 0 {
|
|
**(**Tu32)(__ccgo_up(p + 28)) |= uint32(TF_Strict)
|
|
ii = 0
|
|
for {
|
|
if !(ii < int32((*TTable)(unsafe.Pointer(p)).FnCol)) {
|
|
break
|
|
}
|
|
pCol = (*TTable)(unsafe.Pointer(p)).FaCol + uintptr(ii)*12
|
|
if int32(uint32(*(*uint8)(unsafe.Pointer(pCol + 4))&0xf0>>4)) == COLTYPE_CUSTOM {
|
|
if libc.Int32FromUint16((*TColumn)(unsafe.Pointer(pCol)).FcolFlags)&int32(COLFLAG_HASTYPE) != 0 {
|
|
_sqlite3ErrorMsg(tls, pParse, __ccgo_ts+14398, libc.VaList(bp+40, (*TTable)(unsafe.Pointer(p)).FzName, (*TColumn)(unsafe.Pointer(pCol)).FzCnName, _sqlite3ColumnType(tls, pCol, __ccgo_ts+1702)))
|
|
} else {
|
|
_sqlite3ErrorMsg(tls, pParse, __ccgo_ts+14431, libc.VaList(bp+40, (*TTable)(unsafe.Pointer(p)).FzName, (*TColumn)(unsafe.Pointer(pCol)).FzCnName))
|
|
}
|
|
return
|
|
} else {
|
|
if int32(uint32(*(*uint8)(unsafe.Pointer(pCol + 4))&0xf0>>4)) == int32(COLTYPE_ANY) {
|
|
(*TColumn)(unsafe.Pointer(pCol)).Faffinity = int8(SQLITE_AFF_BLOB)
|
|
}
|
|
}
|
|
if libc.Int32FromUint16((*TColumn)(unsafe.Pointer(pCol)).FcolFlags)&int32(COLFLAG_PRIMKEY) != 0 && int32((*TTable)(unsafe.Pointer(p)).FiPKey) != ii && int32(uint32(*(*uint8)(unsafe.Pointer(pCol + 4))&0xf>>0)) == OE_None {
|
|
libc.SetBitFieldPtr8Uint32(pCol+4, libc.Uint32FromInt32(OE_Abort), 0, 0xf)
|
|
**(**Tu32)(__ccgo_up(p + 28)) |= uint32(TF_HasNotNull)
|
|
}
|
|
goto _1
|
|
_1:
|
|
;
|
|
ii = ii + 1
|
|
}
|
|
}
|
|
/* Special processing for WITHOUT ROWID Tables */
|
|
if tabOpts&uint32(TF_WithoutRowid) != 0 {
|
|
if (*TTable)(unsafe.Pointer(p)).FtabFlags&uint32(TF_Autoincrement) != 0 {
|
|
_sqlite3ErrorMsg(tls, pParse, __ccgo_ts+14458, 0)
|
|
return
|
|
}
|
|
if (*TTable)(unsafe.Pointer(p)).FtabFlags&uint32(TF_HasPrimaryKey) == uint32(0) {
|
|
_sqlite3ErrorMsg(tls, pParse, __ccgo_ts+14508, libc.VaList(bp+40, (*TTable)(unsafe.Pointer(p)).FzName))
|
|
return
|
|
}
|
|
**(**Tu32)(__ccgo_up(p + 28)) |= libc.Uint32FromInt32(libc.Int32FromInt32(TF_WithoutRowid) | libc.Int32FromInt32(TF_NoVisibleRowid))
|
|
_convertToWithoutRowidTable(tls, pParse, p)
|
|
}
|
|
iDb = _sqlite3SchemaToIndex(tls, db, (*TTable)(unsafe.Pointer(p)).FpSchema)
|
|
/* Resolve names in all CHECK constraint expressions.
|
|
*/
|
|
if (*TTable)(unsafe.Pointer(p)).FpCheck != 0 {
|
|
_sqlite3ResolveSelfReference(tls, pParse, p, int32(NC_IsCheck), uintptr(0), (*TTable)(unsafe.Pointer(p)).FpCheck)
|
|
if (*TParse)(unsafe.Pointer(pParse)).FnErr != 0 {
|
|
/* If errors are seen, delete the CHECK constraints now, else they might
|
|
** actually be used if PRAGMA writable_schema=ON is set. */
|
|
_sqlite3ExprListDelete(tls, db, (*TTable)(unsafe.Pointer(p)).FpCheck)
|
|
(*TTable)(unsafe.Pointer(p)).FpCheck = uintptr(0)
|
|
} else {
|
|
}
|
|
}
|
|
if (*TTable)(unsafe.Pointer(p)).FtabFlags&uint32(TF_HasGenerated) != 0 {
|
|
nNG = 0
|
|
ii1 = 0
|
|
for {
|
|
if !(ii1 < int32((*TTable)(unsafe.Pointer(p)).FnCol)) {
|
|
break
|
|
}
|
|
colFlags = uint32((**(**TColumn)(__ccgo_up((*TTable)(unsafe.Pointer(p)).FaCol + uintptr(ii1)*12))).FcolFlags)
|
|
if colFlags&uint32(COLFLAG_GENERATED) != uint32(0) {
|
|
pX = _sqlite3ColumnExpr(tls, p, (*TTable)(unsafe.Pointer(p)).FaCol+uintptr(ii1)*12)
|
|
if _sqlite3ResolveSelfReference(tls, pParse, p, int32(NC_GenCol), pX, uintptr(0)) != 0 {
|
|
/* If there are errors in resolving the expression, change the
|
|
** expression to a NULL. This prevents code generators that operate
|
|
** on the expression from inserting extra parts into the expression
|
|
** tree that have been allocated from lookaside memory, which is
|
|
** illegal in a schema and will lead to errors or heap corruption
|
|
** when the database connection closes. */
|
|
_sqlite3ColumnSetExpr(tls, pParse, p, (*TTable)(unsafe.Pointer(p)).FaCol+uintptr(ii1)*12, _sqlite3ExprAlloc(tls, db, int32(TK_NULL), uintptr(0), 0))
|
|
}
|
|
} else {
|
|
nNG = nNG + 1
|
|
}
|
|
goto _2
|
|
_2:
|
|
;
|
|
ii1 = ii1 + 1
|
|
}
|
|
if nNG == 0 {
|
|
_sqlite3ErrorMsg(tls, pParse, __ccgo_ts+14540, 0)
|
|
return
|
|
}
|
|
}
|
|
/* Estimate the average row size for the table and for all implied indices */
|
|
_estimateTableWidth(tls, p)
|
|
pIdx = (*TTable)(unsafe.Pointer(p)).FpIndex
|
|
for {
|
|
if !(pIdx != 0) {
|
|
break
|
|
}
|
|
_estimateIndexWidth(tls, pIdx)
|
|
goto _3
|
|
_3:
|
|
;
|
|
pIdx = (*TIndex)(unsafe.Pointer(pIdx)).FpNext
|
|
}
|
|
/* If not initializing, then create a record for the new table
|
|
** in the schema table of the database.
|
|
**
|
|
** If this is a TEMPORARY table, write the entry into the auxiliary
|
|
** file instead of into the main database file.
|
|
*/
|
|
if !((*Tsqlite3)(unsafe.Pointer(db)).Finit1.Fbusy != 0) { /* Text of the CREATE TABLE or CREATE VIEW statement */
|
|
v = _sqlite3GetVdbe(tls, pParse)
|
|
if v == uintptr(0) {
|
|
return
|
|
}
|
|
_sqlite3VdbeAddOp1(tls, v, int32(OP_Close), 0)
|
|
/*
|
|
** Initialize zType for the new view or table.
|
|
*/
|
|
if libc.Int32FromUint8((*TTable)(unsafe.Pointer(p)).FeTabType) == TABTYP_NORM {
|
|
/* A regular table */
|
|
zType = __ccgo_ts + 9379
|
|
zType2 = __ccgo_ts + 14584
|
|
} else {
|
|
/* A view */
|
|
zType = __ccgo_ts + 11117
|
|
zType2 = __ccgo_ts + 14590
|
|
}
|
|
/* If this is a CREATE TABLE xx AS SELECT ..., execute the SELECT
|
|
** statement to populate the new table. The root-page number for the
|
|
** new table is in register pParse->u1.cr.regRoot.
|
|
**
|
|
** Once the SELECT has been coded by sqlite3Select(), it is in a
|
|
** suitable state to query for the column names and types to be used
|
|
** by the new table.
|
|
**
|
|
** A shared-cache write-lock is not required to write to the new table,
|
|
** as a schema-lock must have already been obtained to create it. Since
|
|
** a schema-lock excludes all other database users, the write-lock would
|
|
** be redundant.
|
|
*/
|
|
if pSelect != 0 { /* Write cursor on the new table */
|
|
if libc.Int32FromUint8((*TParse)(unsafe.Pointer(pParse)).FeParseMode) != PARSE_MODE_NORMAL {
|
|
(*TParse)(unsafe.Pointer(pParse)).Frc = int32(SQLITE_ERROR)
|
|
(*TParse)(unsafe.Pointer(pParse)).FnErr = (*TParse)(unsafe.Pointer(pParse)).FnErr + 1
|
|
return
|
|
}
|
|
v5 = pParse + 44
|
|
v4 = *(*int32)(unsafe.Pointer(v5))
|
|
*(*int32)(unsafe.Pointer(v5)) = *(*int32)(unsafe.Pointer(v5)) + 1
|
|
iCsr = v4
|
|
v5 = pParse + 48
|
|
*(*int32)(unsafe.Pointer(v5)) = *(*int32)(unsafe.Pointer(v5)) + 1
|
|
v4 = *(*int32)(unsafe.Pointer(v5))
|
|
regYield = v4
|
|
v5 = pParse + 48
|
|
*(*int32)(unsafe.Pointer(v5)) = *(*int32)(unsafe.Pointer(v5)) + 1
|
|
v4 = *(*int32)(unsafe.Pointer(v5))
|
|
regRec = v4
|
|
v5 = pParse + 48
|
|
*(*int32)(unsafe.Pointer(v5)) = *(*int32)(unsafe.Pointer(v5)) + 1
|
|
v4 = *(*int32)(unsafe.Pointer(v5))
|
|
regRowid = v4
|
|
_sqlite3MayAbort(tls, pParse)
|
|
_sqlite3VdbeAddOp3(tls, v, int32(OP_OpenWrite), iCsr, (*(*struct {
|
|
FaddrCrTab int32
|
|
FregRowid int32
|
|
FregRoot int32
|
|
FconstraintName TToken
|
|
})(unsafe.Pointer(pParse + 188))).FregRoot, iDb)
|
|
_sqlite3VdbeChangeP5(tls, v, uint16(OPFLAG_P2ISREG))
|
|
addrTop = _sqlite3VdbeCurrentAddr(tls, v) + int32(1)
|
|
_sqlite3VdbeAddOp3(tls, v, int32(OP_InitCoroutine), regYield, 0, addrTop)
|
|
if (*TParse)(unsafe.Pointer(pParse)).FnErr != 0 {
|
|
return
|
|
}
|
|
pSelTab = _sqlite3ResultSetOfSelect(tls, pParse, pSelect, int8(SQLITE_AFF_BLOB))
|
|
if pSelTab == uintptr(0) {
|
|
return
|
|
}
|
|
v12 = (*TTable)(unsafe.Pointer(pSelTab)).FnCol
|
|
(*TTable)(unsafe.Pointer(p)).FnNVCol = v12
|
|
(*TTable)(unsafe.Pointer(p)).FnCol = v12
|
|
(*TTable)(unsafe.Pointer(p)).FaCol = (*TTable)(unsafe.Pointer(pSelTab)).FaCol
|
|
(*TTable)(unsafe.Pointer(pSelTab)).FnCol = 0
|
|
(*TTable)(unsafe.Pointer(pSelTab)).FaCol = uintptr(0)
|
|
_sqlite3DeleteTable(tls, db, pSelTab)
|
|
_sqlite3SelectDestInit(tls, bp, int32(SRT_Coroutine), regYield)
|
|
_sqlite3Select(tls, pParse, pSelect, bp)
|
|
if (*TParse)(unsafe.Pointer(pParse)).FnErr != 0 {
|
|
return
|
|
}
|
|
_sqlite3VdbeEndCoroutine(tls, v, regYield)
|
|
_sqlite3VdbeJumpHere(tls, v, addrTop-int32(1))
|
|
addrInsLoop = _sqlite3VdbeAddOp1(tls, v, int32(OP_Yield), (**(**TSelectDest)(__ccgo_up(bp))).FiSDParm)
|
|
_sqlite3VdbeAddOp3(tls, v, int32(OP_MakeRecord), (**(**TSelectDest)(__ccgo_up(bp))).FiSdst, (**(**TSelectDest)(__ccgo_up(bp))).FnSdst, regRec)
|
|
_sqlite3TableAffinity(tls, v, p, 0)
|
|
_sqlite3VdbeAddOp2(tls, v, int32(OP_NewRowid), iCsr, regRowid)
|
|
_sqlite3VdbeAddOp3(tls, v, int32(OP_Insert), iCsr, regRec, regRowid)
|
|
_sqlite3VdbeGoto(tls, v, addrInsLoop)
|
|
_sqlite3VdbeJumpHere(tls, v, addrInsLoop)
|
|
_sqlite3VdbeAddOp1(tls, v, int32(OP_Close), iCsr)
|
|
}
|
|
/* Compute the complete text of the CREATE statement */
|
|
if pSelect != 0 {
|
|
zStmt = _createTableStmt(tls, db, p)
|
|
} else {
|
|
if tabOpts != 0 {
|
|
v5 = pParse + 208
|
|
} else {
|
|
v5 = pEnd
|
|
}
|
|
pEnd2 = v5
|
|
n = int32((*TToken)(unsafe.Pointer(pEnd2)).Fz) - int32((*TParse)(unsafe.Pointer(pParse)).FsNameToken.Fz)
|
|
if int32(**(**int8)(__ccgo_up((*TToken)(unsafe.Pointer(pEnd2)).Fz))) != int32(';') {
|
|
n = libc.Int32FromUint32(uint32(n) + (*TToken)(unsafe.Pointer(pEnd2)).Fn)
|
|
}
|
|
zStmt = _sqlite3MPrintf(tls, db, __ccgo_ts+14595, libc.VaList(bp+40, zType2, n, (*TParse)(unsafe.Pointer(pParse)).FsNameToken.Fz))
|
|
}
|
|
/* 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.
|
|
*/
|
|
_sqlite3NestedParse(tls, pParse, __ccgo_ts+14610, libc.VaList(bp+40, (**(**TDb)(__ccgo_up((*Tsqlite3)(unsafe.Pointer(db)).FaDb + uintptr(iDb)*16))).FzDbSName, zType, (*TTable)(unsafe.Pointer(p)).FzName, (*TTable)(unsafe.Pointer(p)).FzName, (*(*struct {
|
|
FaddrCrTab int32
|
|
FregRowid int32
|
|
FregRoot int32
|
|
FconstraintName TToken
|
|
})(unsafe.Pointer(pParse + 188))).FregRoot, zStmt, (*(*struct {
|
|
FaddrCrTab int32
|
|
FregRowid int32
|
|
FregRoot int32
|
|
FconstraintName TToken
|
|
})(unsafe.Pointer(pParse + 188))).FregRowid))
|
|
_sqlite3DbFree(tls, db, zStmt)
|
|
_sqlite3ChangeCookie(tls, pParse, iDb)
|
|
/* Check to see if we need to create an sqlite_sequence table for
|
|
** keeping track of autoincrement keys.
|
|
*/
|
|
if (*TTable)(unsafe.Pointer(p)).FtabFlags&uint32(TF_Autoincrement) != uint32(0) && !(libc.Int32FromUint8((*TParse)(unsafe.Pointer(pParse)).FeParseMode) != libc.Int32FromInt32(PARSE_MODE_NORMAL)) {
|
|
pDb = (*Tsqlite3)(unsafe.Pointer(db)).FaDb + uintptr(iDb)*16
|
|
if (*TSchema)(unsafe.Pointer((*TDb)(unsafe.Pointer(pDb)).FpSchema)).FpSeqTab == uintptr(0) {
|
|
_sqlite3NestedParse(tls, pParse, __ccgo_ts+14708, libc.VaList(bp+40, (*TDb)(unsafe.Pointer(pDb)).FzDbSName))
|
|
}
|
|
}
|
|
/* Reparse everything to update our internal data structures */
|
|
_sqlite3VdbeAddParseSchemaOp(tls, v, iDb, _sqlite3MPrintf(tls, db, __ccgo_ts+14750, libc.VaList(bp+40, (*TTable)(unsafe.Pointer(p)).FzName)), uint16(0))
|
|
/* Test for cycles in generated columns and illegal expressions
|
|
** in CHECK constraints and in DEFAULT clauses. */
|
|
if (*TTable)(unsafe.Pointer(p)).FtabFlags&uint32(TF_HasGenerated) != 0 {
|
|
_sqlite3VdbeAddOp4(tls, v, int32(OP_SqlExec), int32(0x0001), 0, 0, _sqlite3MPrintf(tls, db, __ccgo_ts+14784, libc.VaList(bp+40, (**(**TDb)(__ccgo_up((*Tsqlite3)(unsafe.Pointer(db)).FaDb + uintptr(iDb)*16))).FzDbSName, (*TTable)(unsafe.Pointer(p)).FzName)), -int32(7))
|
|
}
|
|
}
|
|
/* Add the table to the in-memory representation of the database.
|
|
*/
|
|
if (*Tsqlite3)(unsafe.Pointer(db)).Finit1.Fbusy != 0 {
|
|
pSchema = (*TTable)(unsafe.Pointer(p)).FpSchema
|
|
pOld = _sqlite3HashInsert(tls, pSchema+8, (*TTable)(unsafe.Pointer(p)).FzName, p)
|
|
if pOld != 0 {
|
|
/* Malloc must have failed inside HashInsert() */
|
|
_sqlite3OomFault(tls, db)
|
|
return
|
|
}
|
|
(*TParse)(unsafe.Pointer(pParse)).FpNewTable = uintptr(0)
|
|
**(**Tu32)(__ccgo_up(db + 24)) |= uint32(DBFLAG_SchemaChange)
|
|
/* If this is the magic sqlite_sequence table used by autoincrement,
|
|
** then record a pointer to this table in the main database structure
|
|
** so that INSERT can find the table easily. */
|
|
if libc.Xstrcmp(tls, (*TTable)(unsafe.Pointer(p)).FzName, __ccgo_ts+9901) == 0 {
|
|
(*TSchema)(unsafe.Pointer((*TTable)(unsafe.Pointer(p)).FpSchema)).FpSeqTab = p
|
|
}
|
|
}
|
|
if !(pSelect != 0) && libc.Int32FromUint8((*TTable)(unsafe.Pointer(p)).FeTabType) == TABTYP_NORM {
|
|
if (*TToken)(unsafe.Pointer(pCons)).Fz == uintptr(0) {
|
|
pCons = pEnd
|
|
}
|
|
(*(*struct {
|
|
FaddColOffset int32
|
|
FpFKey uintptr
|
|
FpDfltList uintptr
|
|
})(unsafe.Pointer(p + 44))).FaddColOffset = int32(13) + (int32((*TToken)(unsafe.Pointer(pCons)).Fz) - int32((*TParse)(unsafe.Pointer(pParse)).FsNameToken.Fz))
|
|
}
|
|
}
|
|
|
|
// 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 + 20)) == uintptr(0) || (*TExprList)(unsafe.Pointer(*(*uintptr)(unsafe.Pointer(pExpr + 20)))).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(&(*TExpr)(unsafe.Pointer(pExpr)).Fy)))).FeFrmType) != int32(TK_FILTER) {
|
|
_sqlite3ExprOrderByAggregateError(tls, pParse, pExpr)
|
|
_sqlite3ExprListDelete(tls, db, pOrderBy)
|
|
return
|
|
}
|
|
if (*TExprList)(unsafe.Pointer(pOrderBy)).FnExpr > **(**int32)(__ccgo_up(db + 116 + 2*4)) {
|
|
_sqlite3ErrorMsg(tls, pParse, __ccgo_ts+7627, 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 + 20)) = pOrderBy
|
|
(*TExpr)(unsafe.Pointer(pExpr)).FpLeft = pOB
|
|
**(**Tu32)(__ccgo_up(pOB + 4)) |= libc.Uint32FromInt32(libc.Int32FromInt32(EP_FullSize))
|
|
}
|
|
|
|
// C documentation
|
|
//
|
|
// /*
|
|
// ** Assign a variable number to an expression that encodes a wildcard
|
|
// ** in the original SQL statement.
|
|
// **
|
|
// ** Wildcards consisting of a single "?" are assigned the next sequential
|
|
// ** variable number.
|
|
// **
|
|
// ** Wildcards of the form "?nnn" are assigned the number "nnn". We make
|
|
// ** sure "nnn" is not too big to avoid a denial of service attack when
|
|
// ** the SQL statement comes from an external source.
|
|
// **
|
|
// ** Wildcards of the form ":aaa", "@aaa", or "$aaa" are assigned the same number
|
|
// ** as the previous instance of the same wildcard. Or if this is the first
|
|
// ** instance of the wildcard, the next sequential variable number is
|
|
// ** assigned.
|
|
// */
|
|
func _sqlite3ExprAssignVarNumber(tls *libc.TLS, pParse uintptr, pExpr uintptr, n Tu32) {
|
|
bp := tls.Alloc(32)
|
|
defer tls.Free(32)
|
|
var bOk, doAdd int32
|
|
var db, z, v2 uintptr
|
|
var x, v1 TynVar
|
|
var _ /* i at bp+0 */ Ti64
|
|
_, _, _, _, _, _, _ = bOk, db, doAdd, x, z, v1, v2
|
|
db = (*TParse)(unsafe.Pointer(pParse)).Fdb
|
|
if pExpr == uintptr(0) {
|
|
return
|
|
}
|
|
z = *(*uintptr)(unsafe.Pointer(pExpr + 8))
|
|
if int32(**(**int8)(__ccgo_up(z + 1))) == 0 {
|
|
/* Wildcard of the form "?". Assign the next variable number */
|
|
v2 = pParse + 216
|
|
*(*TynVar)(unsafe.Pointer(v2)) = *(*TynVar)(unsafe.Pointer(v2)) + 1
|
|
v1 = *(*TynVar)(unsafe.Pointer(v2))
|
|
x = v1
|
|
} else {
|
|
doAdd = 0
|
|
if int32(**(**int8)(__ccgo_up(z))) == int32('?') {
|
|
if n == uint32(2) { /*OPTIMIZATION-IF-TRUE*/
|
|
**(**Ti64)(__ccgo_up(bp)) = int64(int32(**(**int8)(__ccgo_up(z + 1))) - int32('0')) /* The common case of ?N for a single digit N */
|
|
bOk = int32(1)
|
|
} else {
|
|
bOk = libc.BoolInt32(0 == _sqlite3Atoi64(tls, z+1, bp, libc.Int32FromUint32(n-uint32(1)), uint8(SQLITE_UTF8)))
|
|
}
|
|
if bOk == 0 || **(**Ti64)(__ccgo_up(bp)) < int64(1) || **(**Ti64)(__ccgo_up(bp)) > int64(**(**int32)(__ccgo_up(db + 116 + 9*4))) {
|
|
_sqlite3ErrorMsg(tls, pParse, __ccgo_ts+8061, libc.VaList(bp+16, **(**int32)(__ccgo_up(db + 116 + 9*4))))
|
|
_sqlite3RecordErrorOffsetOfExpr(tls, (*TParse)(unsafe.Pointer(pParse)).Fdb, pExpr)
|
|
return
|
|
}
|
|
x = int16(**(**Ti64)(__ccgo_up(bp)))
|
|
if int32(x) > int32((*TParse)(unsafe.Pointer(pParse)).FnVar) {
|
|
(*TParse)(unsafe.Pointer(pParse)).FnVar = int16(int32(x))
|
|
doAdd = int32(1)
|
|
} else {
|
|
if _sqlite3VListNumToName(tls, (*TParse)(unsafe.Pointer(pParse)).FpVList, int32(x)) == uintptr(0) {
|
|
doAdd = int32(1)
|
|
}
|
|
}
|
|
} else {
|
|
/* Wildcards like ":aaa", "$aaa" or "@aaa". Reuse the same variable
|
|
** number as the prior appearance of the same name, or if the name
|
|
** has never appeared before, reuse the same variable number
|
|
*/
|
|
x = int16(_sqlite3VListNameToNum(tls, (*TParse)(unsafe.Pointer(pParse)).FpVList, z, libc.Int32FromUint32(n)))
|
|
if int32(x) == 0 {
|
|
v2 = pParse + 216
|
|
*(*TynVar)(unsafe.Pointer(v2)) = *(*TynVar)(unsafe.Pointer(v2)) + 1
|
|
v1 = *(*TynVar)(unsafe.Pointer(v2))
|
|
x = v1
|
|
doAdd = int32(1)
|
|
}
|
|
}
|
|
if doAdd != 0 {
|
|
(*TParse)(unsafe.Pointer(pParse)).FpVList = _sqlite3VListAdd(tls, db, (*TParse)(unsafe.Pointer(pParse)).FpVList, z, libc.Int32FromUint32(n), int32(x))
|
|
}
|
|
}
|
|
(*TExpr)(unsafe.Pointer(pExpr)).FiColumn = x
|
|
if int32(x) > **(**int32)(__ccgo_up(db + 116 + 9*4)) {
|
|
_sqlite3ErrorMsg(tls, pParse, __ccgo_ts+8104, 0)
|
|
_sqlite3RecordErrorOffsetOfExpr(tls, (*TParse)(unsafe.Pointer(pParse)).Fdb, pExpr)
|
|
}
|
|
}
|
|
|
|
// 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 + 116 + 3*4))
|
|
if nHeight > mxHeight {
|
|
_sqlite3ErrorMsg(tls, pParse, __ccgo_ts+7863, libc.VaList(bp+8, mxHeight))
|
|
rc = int32(SQLITE_ERROR)
|
|
}
|
|
return rc
|
|
}
|
|
|
|
// C documentation
|
|
//
|
|
// /*
|
|
// ** Generate code into the current Vdbe to evaluate the given
|
|
// ** expression. Attempt to store the results in register "target".
|
|
// ** Return the register where results are stored.
|
|
// **
|
|
// ** With this routine, there is no guarantee that results will
|
|
// ** be stored in target. The result might be stored in some other
|
|
// ** register if it is convenient to do so. The calling function
|
|
// ** must check the return code and move the results to the desired
|
|
// ** register.
|
|
// */
|
|
func _sqlite3ExprCodeTarget(tls *libc.TLS, pParse uintptr, pExpr uintptr, target int32) (r int32) {
|
|
bp := tls.Alloc(144)
|
|
defer tls.Free(144)
|
|
var aListelem, db, db1, pAggInfo, pAggInfo1, pCol, pCol1, pColl, pDef, pDel, pEList, pFarg, pInfo, pLeft, pLeft1, pLeft2, pTab, pTab1, pTab2, pTest, pX, v, z, zBlob, zId, v3 uintptr
|
|
var addr, addrINR, addrIsNull, addrIsNull1, aff, bNormal, destIfFalse, destIfNull, endLabel, i, i1, iCol, iCol1, iReg, iSrc, iTab, inReg, isTrue, n, n1, nCol, nExpr, nFarg, nextCase, op, p1, p5, v1 int32
|
|
var constMask Tu32
|
|
var enc, exprOp, okConstFactor Tu8
|
|
var v2 bool
|
|
var _ /* opCompare at bp+68 */ TExpr
|
|
var _ /* r1 at bp+8 */ int32
|
|
var _ /* r2 at bp+12 */ int32
|
|
var _ /* regFree1 at bp+0 */ int32
|
|
var _ /* regFree2 at bp+4 */ int32
|
|
var _ /* tempX at bp+16 */ TExpr
|
|
_, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _ = aListelem, addr, addrINR, addrIsNull, addrIsNull1, aff, bNormal, constMask, db, db1, destIfFalse, destIfNull, enc, endLabel, exprOp, i, i1, iCol, iCol1, iReg, iSrc, iTab, inReg, isTrue, n, n1, nCol, nExpr, nFarg, nextCase, okConstFactor, op, p1, p5, pAggInfo, pAggInfo1, pCol, pCol1, pColl, pDef, pDel, pEList, pFarg, pInfo, pLeft, pLeft1, pLeft2, pTab, pTab1, pTab2, pTest, pX, v, z, zBlob, zId, v1, v2, v3
|
|
v = (*TParse)(unsafe.Pointer(pParse)).FpVdbe /* The opcode being coded */
|
|
inReg = target /* Results stored in register inReg */
|
|
**(**int32)(__ccgo_up(bp)) = 0 /* If non-zero free this temporary register */
|
|
**(**int32)(__ccgo_up(bp + 4)) = 0 /* Temporary expression node */
|
|
p5 = 0
|
|
goto expr_code_doover
|
|
expr_code_doover:
|
|
;
|
|
if pExpr == uintptr(0) {
|
|
op = int32(TK_NULL)
|
|
} else {
|
|
if v2 = (*TParse)(unsafe.Pointer(pParse)).FpIdxEpr != uintptr(0) && !((*TExpr)(unsafe.Pointer(pExpr)).Fflags&libc.Uint32FromInt32(libc.Int32FromInt32(EP_Leaf)) != libc.Uint32FromInt32(0)); v2 {
|
|
v1 = _sqlite3IndexedExprLookup(tls, pParse, pExpr, target)
|
|
**(**int32)(__ccgo_up(bp + 8)) = v1
|
|
}
|
|
if v2 && v1 >= 0 {
|
|
return **(**int32)(__ccgo_up(bp + 8))
|
|
} else {
|
|
op = libc.Int32FromUint8((*TExpr)(unsafe.Pointer(pExpr)).Fop)
|
|
}
|
|
}
|
|
switch op {
|
|
case int32(TK_AGG_COLUMN):
|
|
pAggInfo = (*TExpr)(unsafe.Pointer(pExpr)).FpAggInfo
|
|
if int32((*TExpr)(unsafe.Pointer(pExpr)).FiAgg) >= (*TAggInfo)(unsafe.Pointer(pAggInfo)).FnColumn {
|
|
/* Happens when the left table of a RIGHT JOIN is null and
|
|
** is using an expression index */
|
|
_sqlite3VdbeAddOp2(tls, v, int32(OP_Null), 0, target)
|
|
break
|
|
}
|
|
pCol = (*TAggInfo)(unsafe.Pointer(pAggInfo)).FaCol + uintptr((*TExpr)(unsafe.Pointer(pExpr)).FiAgg)*20
|
|
if !((*TAggInfo)(unsafe.Pointer(pAggInfo)).FdirectMode != 0) {
|
|
return (*TAggInfo)(unsafe.Pointer(pAggInfo)).FiFirstReg + int32((*TExpr)(unsafe.Pointer(pExpr)).FiAgg)
|
|
} else {
|
|
if (*TAggInfo)(unsafe.Pointer(pAggInfo)).FuseSortingIdx != 0 {
|
|
pTab = (*TAggInfo_col)(unsafe.Pointer(pCol)).FpTab
|
|
_sqlite3VdbeAddOp3(tls, v, int32(OP_Column), (*TAggInfo)(unsafe.Pointer(pAggInfo)).FsortingIdxPTab, (*TAggInfo_col)(unsafe.Pointer(pCol)).FiSorterColumn, target)
|
|
if pTab == uintptr(0) {
|
|
/* No comment added */
|
|
} else {
|
|
if (*TAggInfo_col)(unsafe.Pointer(pCol)).FiColumn < 0 {
|
|
} else {
|
|
if int32((**(**TColumn)(__ccgo_up((*TTable)(unsafe.Pointer(pTab)).FaCol + uintptr((*TAggInfo_col)(unsafe.Pointer(pCol)).FiColumn)*12))).Faffinity) == int32(SQLITE_AFF_REAL) {
|
|
_sqlite3VdbeAddOp1(tls, v, int32(OP_RealAffinity), target)
|
|
}
|
|
}
|
|
}
|
|
return target
|
|
} else {
|
|
if (*TExpr)(unsafe.Pointer(pExpr)).Fy.FpTab == uintptr(0) {
|
|
/* This case happens when the argument to an aggregate function
|
|
** is rewritten by aggregateConvertIndexedExprRefToColumn() */
|
|
_sqlite3VdbeAddOp3(tls, v, int32(OP_Column), (*TExpr)(unsafe.Pointer(pExpr)).FiTable, int32((*TExpr)(unsafe.Pointer(pExpr)).FiColumn), target)
|
|
return target
|
|
}
|
|
}
|
|
}
|
|
/* Otherwise, fall thru into the TK_COLUMN case */
|
|
fallthrough
|
|
case int32(TK_COLUMN):
|
|
iTab = (*TExpr)(unsafe.Pointer(pExpr)).FiTable
|
|
if (*TExpr)(unsafe.Pointer(pExpr)).Fflags&libc.Uint32FromInt32(libc.Int32FromInt32(EP_FixedCol)) != uint32(0) {
|
|
iReg = _sqlite3ExprCodeTarget(tls, pParse, (*TExpr)(unsafe.Pointer(pExpr)).FpLeft, target)
|
|
aff = int32(_sqlite3TableColumnAffinity(tls, (*TExpr)(unsafe.Pointer(pExpr)).Fy.FpTab, int32((*TExpr)(unsafe.Pointer(pExpr)).FiColumn)))
|
|
if aff > int32(SQLITE_AFF_BLOB) {
|
|
_sqlite3VdbeAddOp4(tls, v, int32(OP_Affinity), iReg, int32(1), 0, uintptr(unsafe.Pointer(&_zAff))+uintptr((aff-int32('B'))*int32(2)), -int32(1))
|
|
}
|
|
return iReg
|
|
}
|
|
if iTab < 0 {
|
|
if (*TParse)(unsafe.Pointer(pParse)).FiSelfTab < 0 {
|
|
iCol = int32((*TExpr)(unsafe.Pointer(pExpr)).FiColumn)
|
|
pTab1 = (*TExpr)(unsafe.Pointer(pExpr)).Fy.FpTab
|
|
if iCol < 0 {
|
|
return -int32(1) - (*TParse)(unsafe.Pointer(pParse)).FiSelfTab
|
|
}
|
|
pCol1 = (*TTable)(unsafe.Pointer(pTab1)).FaCol + uintptr(iCol)*12
|
|
iSrc = int32(_sqlite3TableColumnToStorage(tls, pTab1, int16(iCol))) - (*TParse)(unsafe.Pointer(pParse)).FiSelfTab
|
|
if libc.Int32FromUint16((*TColumn)(unsafe.Pointer(pCol1)).FcolFlags)&int32(COLFLAG_GENERATED) != 0 {
|
|
if libc.Int32FromUint16((*TColumn)(unsafe.Pointer(pCol1)).FcolFlags)&int32(COLFLAG_BUSY) != 0 {
|
|
_sqlite3ErrorMsg(tls, pParse, __ccgo_ts+8454, libc.VaList(bp+128, (*TColumn)(unsafe.Pointer(pCol1)).FzCnName))
|
|
return 0
|
|
}
|
|
v3 = pCol1 + 10
|
|
*(*Tu16)(unsafe.Pointer(v3)) = Tu16(int32(*(*Tu16)(unsafe.Pointer(v3))) | libc.Int32FromInt32(COLFLAG_BUSY))
|
|
if libc.Int32FromUint16((*TColumn)(unsafe.Pointer(pCol1)).FcolFlags)&int32(COLFLAG_NOTAVAIL) != 0 {
|
|
_sqlite3ExprCodeGeneratedColumn(tls, pParse, pTab1, pCol1, iSrc)
|
|
}
|
|
v3 = pCol1 + 10
|
|
*(*Tu16)(unsafe.Pointer(v3)) = Tu16(int32(*(*Tu16)(unsafe.Pointer(v3))) & ^(libc.Int32FromInt32(COLFLAG_BUSY) | libc.Int32FromInt32(COLFLAG_NOTAVAIL)))
|
|
return iSrc
|
|
} else {
|
|
if int32((*TColumn)(unsafe.Pointer(pCol1)).Faffinity) == int32(SQLITE_AFF_REAL) {
|
|
_sqlite3VdbeAddOp2(tls, v, int32(OP_SCopy), iSrc, target)
|
|
_sqlite3VdbeAddOp1(tls, v, int32(OP_RealAffinity), target)
|
|
return target
|
|
} else {
|
|
return iSrc
|
|
}
|
|
}
|
|
} else {
|
|
/* Coding an expression that is part of an index where column names
|
|
** in the index refer to the table to which the index belongs */
|
|
iTab = (*TParse)(unsafe.Pointer(pParse)).FiSelfTab - int32(1)
|
|
}
|
|
} else {
|
|
if v2 = (*TParse)(unsafe.Pointer(pParse)).FpIdxPartExpr != 0; v2 {
|
|
v1 = _exprPartidxExprLookup(tls, pParse, pExpr, target)
|
|
**(**int32)(__ccgo_up(bp + 8)) = v1
|
|
}
|
|
if v2 && 0 != v1 {
|
|
return **(**int32)(__ccgo_up(bp + 8))
|
|
}
|
|
}
|
|
iReg = _sqlite3ExprCodeGetColumn(tls, pParse, (*TExpr)(unsafe.Pointer(pExpr)).Fy.FpTab, int32((*TExpr)(unsafe.Pointer(pExpr)).FiColumn), iTab, target, (*TExpr)(unsafe.Pointer(pExpr)).Fop2)
|
|
return iReg
|
|
case int32(TK_INTEGER):
|
|
_codeInteger(tls, pParse, pExpr, 0, target)
|
|
return target
|
|
case int32(TK_TRUEFALSE):
|
|
_sqlite3VdbeAddOp2(tls, v, int32(OP_Integer), _sqlite3ExprTruthValue(tls, pExpr), target)
|
|
return target
|
|
case int32(TK_FLOAT):
|
|
_codeReal(tls, v, *(*uintptr)(unsafe.Pointer(pExpr + 8)), 0, target)
|
|
return target
|
|
case int32(TK_STRING):
|
|
_sqlite3VdbeLoadString(tls, v, target, *(*uintptr)(unsafe.Pointer(pExpr + 8)))
|
|
return target
|
|
case int32(TK_NULLS):
|
|
/* Set a range of registers to NULL. pExpr->y.nReg registers starting
|
|
** with target */
|
|
_sqlite3VdbeAddOp3(tls, v, int32(OP_Null), 0, target, target+*(*int32)(unsafe.Pointer(&(*TExpr)(unsafe.Pointer(pExpr)).Fy))-int32(1))
|
|
return target
|
|
default:
|
|
/* Make NULL the default case so that if a bug causes an illegal
|
|
** Expr node to be passed into this function, it will be handled
|
|
** sanely and not crash. But keep the assert() to bring the problem
|
|
** to the attention of the developers. */
|
|
_sqlite3VdbeAddOp2(tls, v, int32(OP_Null), 0, target)
|
|
return target
|
|
case int32(TK_BLOB):
|
|
z = *(*uintptr)(unsafe.Pointer(pExpr + 8)) + 2
|
|
n = _sqlite3Strlen30(tls, z) - int32(1)
|
|
zBlob = _sqlite3HexToBlob(tls, _sqlite3VdbeDb(tls, v), z, n)
|
|
_sqlite3VdbeAddOp4(tls, v, int32(OP_Blob), n/int32(2), target, 0, zBlob, -int32(7))
|
|
return target
|
|
case int32(TK_VARIABLE):
|
|
_sqlite3VdbeAddOp2(tls, v, int32(OP_Variable), int32((*TExpr)(unsafe.Pointer(pExpr)).FiColumn), target)
|
|
return target
|
|
case int32(TK_REGISTER):
|
|
return (*TExpr)(unsafe.Pointer(pExpr)).FiTable
|
|
case int32(TK_CAST):
|
|
/* Expressions of the form: CAST(pLeft AS token) */
|
|
_sqlite3ExprCode(tls, pParse, (*TExpr)(unsafe.Pointer(pExpr)).FpLeft, target)
|
|
_sqlite3VdbeAddOp2(tls, v, int32(OP_Cast), target, int32(_sqlite3AffinityType(tls, *(*uintptr)(unsafe.Pointer(pExpr + 8)), uintptr(0))))
|
|
return inReg
|
|
case int32(TK_IS):
|
|
fallthrough
|
|
case int32(TK_ISNOT):
|
|
if op == int32(TK_IS) {
|
|
v1 = int32(TK_EQ)
|
|
} else {
|
|
v1 = int32(TK_NE)
|
|
}
|
|
op = v1
|
|
p5 = int32(SQLITE_NULLEQ)
|
|
fallthrough
|
|
case int32(TK_LT):
|
|
fallthrough
|
|
case int32(TK_LE):
|
|
fallthrough
|
|
case int32(TK_GT):
|
|
fallthrough
|
|
case int32(TK_GE):
|
|
fallthrough
|
|
case int32(TK_NE):
|
|
fallthrough
|
|
case int32(TK_EQ):
|
|
pLeft = (*TExpr)(unsafe.Pointer(pExpr)).FpLeft
|
|
addrIsNull = 0
|
|
if _sqlite3ExprIsVector(tls, pLeft) != 0 {
|
|
_codeVectorCompare(tls, pParse, pExpr, target, libc.Uint8FromInt32(op), libc.Uint8FromInt32(p5))
|
|
} else {
|
|
if (*TExpr)(unsafe.Pointer(pExpr)).Fflags&libc.Uint32FromInt32(libc.Int32FromInt32(EP_Subquery)) != uint32(0) && p5 != int32(SQLITE_NULLEQ) {
|
|
addrIsNull = _exprComputeOperands(tls, pParse, pExpr, bp+8, bp+12, bp, bp+4)
|
|
} else {
|
|
**(**int32)(__ccgo_up(bp + 8)) = _sqlite3ExprCodeTemp(tls, pParse, (*TExpr)(unsafe.Pointer(pExpr)).FpLeft, bp)
|
|
**(**int32)(__ccgo_up(bp + 12)) = _sqlite3ExprCodeTemp(tls, pParse, (*TExpr)(unsafe.Pointer(pExpr)).FpRight, bp+4)
|
|
}
|
|
_sqlite3VdbeAddOp2(tls, v, int32(OP_Integer), int32(1), inReg)
|
|
_codeCompare(tls, pParse, pLeft, (*TExpr)(unsafe.Pointer(pExpr)).FpRight, op, **(**int32)(__ccgo_up(bp + 8)), **(**int32)(__ccgo_up(bp + 12)), _sqlite3VdbeCurrentAddr(tls, v)+int32(2), p5, libc.BoolInt32((*TExpr)(unsafe.Pointer(pExpr)).Fflags&libc.Uint32FromInt32(libc.Int32FromInt32(EP_Commuted)) != uint32(0)))
|
|
if p5 == int32(SQLITE_NULLEQ) {
|
|
_sqlite3VdbeAddOp2(tls, v, int32(OP_Integer), 0, inReg)
|
|
} else {
|
|
_sqlite3VdbeAddOp3(tls, v, int32(OP_ZeroOrNull), **(**int32)(__ccgo_up(bp + 8)), inReg, **(**int32)(__ccgo_up(bp + 12)))
|
|
if addrIsNull != 0 {
|
|
_sqlite3VdbeAddOp2(tls, v, int32(OP_Goto), 0, _sqlite3VdbeCurrentAddr(tls, v)+int32(2))
|
|
_sqlite3VdbeJumpHere(tls, v, addrIsNull)
|
|
_sqlite3VdbeAddOp2(tls, v, int32(OP_Null), 0, inReg)
|
|
}
|
|
}
|
|
}
|
|
case int32(TK_AND):
|
|
fallthrough
|
|
case int32(TK_OR):
|
|
inReg = _exprCodeTargetAndOr(tls, pParse, pExpr, target, bp)
|
|
case int32(TK_PLUS):
|
|
fallthrough
|
|
case int32(TK_STAR):
|
|
fallthrough
|
|
case int32(TK_MINUS):
|
|
fallthrough
|
|
case int32(TK_REM):
|
|
fallthrough
|
|
case int32(TK_BITAND):
|
|
fallthrough
|
|
case int32(TK_BITOR):
|
|
fallthrough
|
|
case int32(TK_SLASH):
|
|
fallthrough
|
|
case int32(TK_LSHIFT):
|
|
fallthrough
|
|
case int32(TK_RSHIFT):
|
|
fallthrough
|
|
case int32(TK_CONCAT):
|
|
if (*TExpr)(unsafe.Pointer(pExpr)).Fflags&libc.Uint32FromInt32(libc.Int32FromInt32(EP_Subquery)) != uint32(0) {
|
|
addrIsNull1 = _exprComputeOperands(tls, pParse, pExpr, bp+8, bp+12, bp, bp+4)
|
|
} else {
|
|
**(**int32)(__ccgo_up(bp + 8)) = _sqlite3ExprCodeTemp(tls, pParse, (*TExpr)(unsafe.Pointer(pExpr)).FpLeft, bp)
|
|
**(**int32)(__ccgo_up(bp + 12)) = _sqlite3ExprCodeTemp(tls, pParse, (*TExpr)(unsafe.Pointer(pExpr)).FpRight, bp+4)
|
|
addrIsNull1 = 0
|
|
}
|
|
_sqlite3VdbeAddOp3(tls, v, op, **(**int32)(__ccgo_up(bp + 12)), **(**int32)(__ccgo_up(bp + 8)), target)
|
|
if addrIsNull1 != 0 {
|
|
_sqlite3VdbeAddOp2(tls, v, int32(OP_Goto), 0, _sqlite3VdbeCurrentAddr(tls, v)+int32(2))
|
|
_sqlite3VdbeJumpHere(tls, v, addrIsNull1)
|
|
_sqlite3VdbeAddOp2(tls, v, int32(OP_Null), 0, target)
|
|
}
|
|
case int32(TK_UMINUS):
|
|
pLeft1 = (*TExpr)(unsafe.Pointer(pExpr)).FpLeft
|
|
if libc.Int32FromUint8((*TExpr)(unsafe.Pointer(pLeft1)).Fop) == int32(TK_INTEGER) {
|
|
_codeInteger(tls, pParse, pLeft1, int32(1), target)
|
|
return target
|
|
} else {
|
|
if libc.Int32FromUint8((*TExpr)(unsafe.Pointer(pLeft1)).Fop) == int32(TK_FLOAT) {
|
|
_codeReal(tls, v, *(*uintptr)(unsafe.Pointer(pLeft1 + 8)), int32(1), target)
|
|
return target
|
|
} else {
|
|
(**(**TExpr)(__ccgo_up(bp + 16))).Fop = uint8(TK_INTEGER)
|
|
(**(**TExpr)(__ccgo_up(bp + 16))).Fflags = libc.Uint32FromInt32(libc.Int32FromInt32(EP_IntValue) | libc.Int32FromInt32(EP_TokenOnly))
|
|
*(*int32)(unsafe.Pointer(bp + 16 + 8)) = 0
|
|
**(**int32)(__ccgo_up(bp + 8)) = _sqlite3ExprCodeTemp(tls, pParse, bp+16, bp)
|
|
**(**int32)(__ccgo_up(bp + 12)) = _sqlite3ExprCodeTemp(tls, pParse, (*TExpr)(unsafe.Pointer(pExpr)).FpLeft, bp+4)
|
|
_sqlite3VdbeAddOp3(tls, v, int32(OP_Subtract), **(**int32)(__ccgo_up(bp + 12)), **(**int32)(__ccgo_up(bp + 8)), target)
|
|
}
|
|
}
|
|
case int32(TK_BITNOT):
|
|
fallthrough
|
|
case int32(TK_NOT):
|
|
**(**int32)(__ccgo_up(bp + 8)) = _sqlite3ExprCodeTemp(tls, pParse, (*TExpr)(unsafe.Pointer(pExpr)).FpLeft, bp)
|
|
_sqlite3VdbeAddOp2(tls, v, op, **(**int32)(__ccgo_up(bp + 8)), inReg)
|
|
case int32(TK_TRUTH): /* IS TRUE or IS FALSE */
|
|
**(**int32)(__ccgo_up(bp + 8)) = _sqlite3ExprCodeTemp(tls, pParse, (*TExpr)(unsafe.Pointer(pExpr)).FpLeft, bp)
|
|
isTrue = _sqlite3ExprTruthValue(tls, (*TExpr)(unsafe.Pointer(pExpr)).FpRight)
|
|
bNormal = libc.BoolInt32(libc.Int32FromUint8((*TExpr)(unsafe.Pointer(pExpr)).Fop2) == int32(TK_IS))
|
|
_sqlite3VdbeAddOp4Int(tls, v, int32(OP_IsTrue), **(**int32)(__ccgo_up(bp + 8)), inReg, libc.BoolInt32(!(isTrue != 0)), isTrue^bNormal)
|
|
case int32(TK_ISNULL):
|
|
fallthrough
|
|
case int32(TK_NOTNULL):
|
|
_sqlite3VdbeAddOp2(tls, v, int32(OP_Integer), int32(1), target)
|
|
**(**int32)(__ccgo_up(bp + 8)) = _sqlite3ExprCodeTemp(tls, pParse, (*TExpr)(unsafe.Pointer(pExpr)).FpLeft, bp)
|
|
addr = _sqlite3VdbeAddOp1(tls, v, op, **(**int32)(__ccgo_up(bp + 8)))
|
|
_sqlite3VdbeAddOp2(tls, v, int32(OP_Integer), 0, target)
|
|
_sqlite3VdbeJumpHere(tls, v, addr)
|
|
case int32(TK_AGG_FUNCTION):
|
|
pInfo = (*TExpr)(unsafe.Pointer(pExpr)).FpAggInfo
|
|
if pInfo == uintptr(0) || int32((*TExpr)(unsafe.Pointer(pExpr)).FiAgg) < 0 || int32((*TExpr)(unsafe.Pointer(pExpr)).FiAgg) >= (*TAggInfo)(unsafe.Pointer(pInfo)).FnFunc {
|
|
_sqlite3ErrorMsg(tls, pParse, __ccgo_ts+8515, libc.VaList(bp+128, pExpr))
|
|
} else {
|
|
return (*TAggInfo)(unsafe.Pointer(pInfo)).FiFirstReg + (*TAggInfo)(unsafe.Pointer(pInfo)).FnColumn + int32((*TExpr)(unsafe.Pointer(pExpr)).FiAgg)
|
|
}
|
|
case int32(TK_FUNCTION): /* The function name */
|
|
constMask = uint32(0) /* Loop counter */
|
|
db = (*TParse)(unsafe.Pointer(pParse)).Fdb /* The database connection */
|
|
enc = (*Tsqlite3)(unsafe.Pointer(db)).Fenc /* The text encoding used by this database */
|
|
pColl = uintptr(0) /* A collating sequence */
|
|
if (*TExpr)(unsafe.Pointer(pExpr)).Fflags&libc.Uint32FromInt32(libc.Int32FromInt32(EP_WinFunc)) != uint32(0) {
|
|
return (*TWindow)(unsafe.Pointer(*(*uintptr)(unsafe.Pointer(&(*TExpr)(unsafe.Pointer(pExpr)).Fy)))).FregResult
|
|
}
|
|
if int32(Tbft(*(*uint16)(unsafe.Pointer(pParse + 28))&0x80>>7)) != 0 && _sqlite3ExprIsConstantNotJoin(tls, pParse, pExpr) != 0 {
|
|
/* SQL functions can be expensive. So try to avoid running them
|
|
** multiple times if we know they always give the same result */
|
|
return _sqlite3ExprCodeRunJustOnce(tls, pParse, pExpr, -int32(1))
|
|
}
|
|
pFarg = *(*uintptr)(unsafe.Pointer(pExpr + 20))
|
|
if pFarg != 0 {
|
|
v1 = (*TExprList)(unsafe.Pointer(pFarg)).FnExpr
|
|
} else {
|
|
v1 = 0
|
|
}
|
|
nFarg = v1
|
|
zId = *(*uintptr)(unsafe.Pointer(pExpr + 8))
|
|
pDef = _sqlite3FindFunction(tls, db, zId, nFarg, enc, uint8(0))
|
|
if pDef == uintptr(0) || (*TFuncDef)(unsafe.Pointer(pDef)).FxFinalize != uintptr(0) {
|
|
_sqlite3ErrorMsg(tls, pParse, __ccgo_ts+8542, libc.VaList(bp+128, pExpr))
|
|
break
|
|
}
|
|
if (*TFuncDef)(unsafe.Pointer(pDef)).FfuncFlags&uint32(SQLITE_FUNC_INLINE) != uint32(0) && pFarg != uintptr(0) {
|
|
return _exprCodeInlineFunction(tls, pParse, pFarg, int32((*TFuncDef)(unsafe.Pointer(pDef)).FpUserData), target)
|
|
} else {
|
|
if (*TFuncDef)(unsafe.Pointer(pDef)).FfuncFlags&libc.Uint32FromInt32(libc.Int32FromInt32(SQLITE_FUNC_DIRECT)|libc.Int32FromInt32(SQLITE_FUNC_UNSAFE)) != 0 {
|
|
_sqlite3ExprFunctionUsable(tls, pParse, pExpr, pDef)
|
|
}
|
|
}
|
|
i = 0
|
|
for {
|
|
if !(i < nFarg) {
|
|
break
|
|
}
|
|
if i < int32(32) && _sqlite3ExprIsConstant(tls, pParse, (*(*TExprList_item)(unsafe.Pointer(pFarg + 8 + uintptr(i)*20))).FpExpr) != 0 {
|
|
constMask = constMask | libc.Uint32FromInt32(1)<<i
|
|
}
|
|
if (*TFuncDef)(unsafe.Pointer(pDef)).FfuncFlags&uint32(SQLITE_FUNC_NEEDCOLL) != uint32(0) && !(pColl != 0) {
|
|
pColl = _sqlite3ExprCollSeq(tls, pParse, (*(*TExprList_item)(unsafe.Pointer(pFarg + 8 + uintptr(i)*20))).FpExpr)
|
|
}
|
|
goto _9
|
|
_9:
|
|
;
|
|
i = i + 1
|
|
}
|
|
if pFarg != 0 {
|
|
if constMask != 0 {
|
|
**(**int32)(__ccgo_up(bp + 8)) = (*TParse)(unsafe.Pointer(pParse)).FnMem + int32(1)
|
|
**(**int32)(__ccgo_up(pParse + 48)) += nFarg
|
|
} else {
|
|
**(**int32)(__ccgo_up(bp + 8)) = _sqlite3GetTempRange(tls, pParse, nFarg)
|
|
}
|
|
/* For length() and typeof() and octet_length() functions,
|
|
** set the P5 parameter to the OP_Column opcode to OPFLAG_LENGTHARG
|
|
** or OPFLAG_TYPEOFARG or OPFLAG_BYTELENARG respectively, to avoid
|
|
** unnecessary data loading.
|
|
*/
|
|
if (*TFuncDef)(unsafe.Pointer(pDef)).FfuncFlags&libc.Uint32FromInt32(libc.Int32FromInt32(SQLITE_FUNC_LENGTH)|libc.Int32FromInt32(SQLITE_FUNC_TYPEOF)) != uint32(0) {
|
|
exprOp = (*TExpr)(unsafe.Pointer((*(*TExprList_item)(unsafe.Pointer(pFarg + 8))).FpExpr)).Fop
|
|
if libc.Int32FromUint8(exprOp) == int32(TK_COLUMN) || libc.Int32FromUint8(exprOp) == int32(TK_AGG_COLUMN) {
|
|
(*TExpr)(unsafe.Pointer((*(*TExprList_item)(unsafe.Pointer(pFarg + 8))).FpExpr)).Fop2 = uint8((*TFuncDef)(unsafe.Pointer(pDef)).FfuncFlags & uint32(OPFLAG_BYTELENARG))
|
|
}
|
|
}
|
|
_sqlite3ExprCodeExprList(tls, pParse, pFarg, **(**int32)(__ccgo_up(bp + 8)), 0, uint8(SQLITE_ECEL_FACTOR))
|
|
} else {
|
|
**(**int32)(__ccgo_up(bp + 8)) = 0
|
|
}
|
|
/* Possibly overload the function if the first argument is
|
|
** a virtual table column.
|
|
**
|
|
** For infix functions (LIKE, GLOB, REGEXP, and MATCH) use the
|
|
** second argument, not the first, as the argument to test to
|
|
** see if it is a column in a virtual table. This is done because
|
|
** the left operand of infix functions (the operand we want to
|
|
** control overloading) ends up as the second argument to the
|
|
** function. The expression "A glob B" is equivalent to
|
|
** "glob(B,A). We want to use the A in "A glob B" to test
|
|
** for function overloading. But we use the B term in "glob(B,A)".
|
|
*/
|
|
if nFarg >= int32(2) && (*TExpr)(unsafe.Pointer(pExpr)).Fflags&libc.Uint32FromInt32(libc.Int32FromInt32(EP_InfixFunc)) != uint32(0) {
|
|
pDef = _sqlite3VtabOverloadFunction(tls, db, pDef, nFarg, (*(*TExprList_item)(unsafe.Pointer(pFarg + 8 + 1*20))).FpExpr)
|
|
} else {
|
|
if nFarg > 0 {
|
|
pDef = _sqlite3VtabOverloadFunction(tls, db, pDef, nFarg, (*(*TExprList_item)(unsafe.Pointer(pFarg + 8))).FpExpr)
|
|
}
|
|
}
|
|
if (*TFuncDef)(unsafe.Pointer(pDef)).FfuncFlags&uint32(SQLITE_FUNC_NEEDCOLL) != 0 {
|
|
if !(pColl != 0) {
|
|
pColl = (*Tsqlite3)(unsafe.Pointer(db)).FpDfltColl
|
|
}
|
|
_sqlite3VdbeAddOp4(tls, v, int32(OP_CollSeq), 0, 0, 0, pColl, -int32(2))
|
|
}
|
|
_sqlite3VdbeAddFunctionCall(tls, pParse, libc.Int32FromUint32(constMask), **(**int32)(__ccgo_up(bp + 8)), target, nFarg, pDef, libc.Int32FromUint8((*TExpr)(unsafe.Pointer(pExpr)).Fop2))
|
|
if nFarg != 0 {
|
|
if constMask == uint32(0) {
|
|
_sqlite3ReleaseTempRange(tls, pParse, **(**int32)(__ccgo_up(bp + 8)), nFarg)
|
|
} else {
|
|
}
|
|
}
|
|
return target
|
|
case int32(TK_EXISTS):
|
|
fallthrough
|
|
case int32(TK_SELECT):
|
|
if (*Tsqlite3)(unsafe.Pointer((*TParse)(unsafe.Pointer(pParse)).Fdb)).FmallocFailed != 0 {
|
|
return 0
|
|
} else {
|
|
if v2 = op == int32(TK_SELECT) && (*TExpr)(unsafe.Pointer(pExpr)).Fflags&uint32(EP_xIsSelect) != uint32(0); v2 {
|
|
v1 = (*TExprList)(unsafe.Pointer((*TSelect)(unsafe.Pointer(*(*uintptr)(unsafe.Pointer(pExpr + 20)))).FpEList)).FnExpr
|
|
nCol = v1
|
|
}
|
|
if v2 && v1 != int32(1) {
|
|
_sqlite3SubselectError(tls, pParse, nCol, int32(1))
|
|
} else {
|
|
return _sqlite3CodeSubselect(tls, pParse, pExpr)
|
|
}
|
|
}
|
|
case int32(TK_SELECT_COLUMN):
|
|
pLeft2 = (*TExpr)(unsafe.Pointer(pExpr)).FpLeft
|
|
if (*TExpr)(unsafe.Pointer(pLeft2)).FiTable == 0 || libc.Int32FromUint8((*TParse)(unsafe.Pointer(pParse)).FwithinRJSubrtn) > libc.Int32FromUint8((*TExpr)(unsafe.Pointer(pLeft2)).Fop2) {
|
|
(*TExpr)(unsafe.Pointer(pLeft2)).FiTable = _sqlite3CodeSubselect(tls, pParse, pLeft2)
|
|
(*TExpr)(unsafe.Pointer(pLeft2)).Fop2 = (*TParse)(unsafe.Pointer(pParse)).FwithinRJSubrtn
|
|
}
|
|
n1 = _sqlite3ExprVectorSize(tls, pLeft2)
|
|
if (*TExpr)(unsafe.Pointer(pExpr)).FiTable != n1 {
|
|
_sqlite3ErrorMsg(tls, pParse, __ccgo_ts+8127, libc.VaList(bp+128, (*TExpr)(unsafe.Pointer(pExpr)).FiTable, n1))
|
|
}
|
|
return (*TExpr)(unsafe.Pointer(pLeft2)).FiTable + int32((*TExpr)(unsafe.Pointer(pExpr)).FiColumn)
|
|
case int32(TK_IN):
|
|
destIfFalse = _sqlite3VdbeMakeLabel(tls, pParse)
|
|
destIfNull = _sqlite3VdbeMakeLabel(tls, pParse)
|
|
_sqlite3VdbeAddOp2(tls, v, int32(OP_Null), 0, target)
|
|
_sqlite3ExprCodeIN(tls, pParse, pExpr, destIfFalse, destIfNull)
|
|
_sqlite3VdbeAddOp2(tls, v, int32(OP_Integer), int32(1), target)
|
|
_sqlite3VdbeResolveLabel(tls, v, destIfFalse)
|
|
_sqlite3VdbeAddOp2(tls, v, int32(OP_AddImm), target, 0)
|
|
_sqlite3VdbeResolveLabel(tls, v, destIfNull)
|
|
return target
|
|
/*
|
|
** x BETWEEN y AND z
|
|
**
|
|
** This is equivalent to
|
|
**
|
|
** x>=y AND x<=z
|
|
**
|
|
** X is stored in pExpr->pLeft.
|
|
** Y is stored in pExpr->pList->a[0].pExpr.
|
|
** Z is stored in pExpr->pList->a[1].pExpr.
|
|
*/
|
|
fallthrough
|
|
case int32(TK_BETWEEN):
|
|
_exprCodeBetween(tls, pParse, pExpr, target, uintptr(0), 0)
|
|
return target
|
|
case int32(TK_COLLATE):
|
|
if !((*TExpr)(unsafe.Pointer(pExpr)).Fflags&libc.Uint32FromInt32(libc.Int32FromInt32(EP_Collate)) != libc.Uint32FromInt32(0)) {
|
|
/* A TK_COLLATE Expr node without the EP_Collate tag is a so-called
|
|
** "SOFT-COLLATE" that is added to constraints that are pushed down
|
|
** from outer queries into sub-queries by the WHERE-clause push-down
|
|
** optimization. Clear subtypes as subtypes may not cross a subquery
|
|
** boundary.
|
|
*/
|
|
_sqlite3ExprCode(tls, pParse, (*TExpr)(unsafe.Pointer(pExpr)).FpLeft, target)
|
|
_sqlite3VdbeAddOp1(tls, v, int32(OP_ClrSubtype), target)
|
|
return target
|
|
} else {
|
|
pExpr = (*TExpr)(unsafe.Pointer(pExpr)).FpLeft
|
|
goto expr_code_doover /* 2018-04-28: Prevent deep recursion. */
|
|
}
|
|
fallthrough
|
|
case int32(TK_SPAN):
|
|
fallthrough
|
|
case int32(TK_UPLUS):
|
|
pExpr = (*TExpr)(unsafe.Pointer(pExpr)).FpLeft
|
|
goto expr_code_doover /* 2018-04-28: Prevent deep recursion. OSSFuzz. */
|
|
case int32(TK_TRIGGER):
|
|
pTab2 = (*TExpr)(unsafe.Pointer(pExpr)).Fy.FpTab
|
|
iCol1 = int32((*TExpr)(unsafe.Pointer(pExpr)).FiColumn)
|
|
p1 = (*TExpr)(unsafe.Pointer(pExpr)).FiTable*(int32((*TTable)(unsafe.Pointer(pTab2)).FnCol)+int32(1)) + int32(1) + int32(_sqlite3TableColumnToStorage(tls, pTab2, int16(iCol1)))
|
|
_sqlite3VdbeAddOp2(tls, v, int32(OP_Param), p1, target)
|
|
/* If the column has REAL affinity, it may currently be stored as an
|
|
** integer. Use OP_RealAffinity to make sure it is really real.
|
|
**
|
|
** EVIDENCE-OF: R-60985-57662 SQLite will convert the value back to
|
|
** floating point when extracting it from the record. */
|
|
if iCol1 >= 0 && int32((**(**TColumn)(__ccgo_up((*TTable)(unsafe.Pointer(pTab2)).FaCol + uintptr(iCol1)*12))).Faffinity) == int32(SQLITE_AFF_REAL) {
|
|
_sqlite3VdbeAddOp1(tls, v, int32(OP_RealAffinity), target)
|
|
}
|
|
case int32(TK_VECTOR):
|
|
_sqlite3ErrorMsg(tls, pParse, __ccgo_ts+6910, 0)
|
|
break
|
|
/* TK_IF_NULL_ROW Expr nodes are inserted ahead of expressions
|
|
** that derive from the right-hand table of a LEFT JOIN. The
|
|
** Expr.iTable value is the table number for the right-hand table.
|
|
** The expression is only evaluated if that table is not currently
|
|
** on a LEFT JOIN NULL row.
|
|
*/
|
|
fallthrough
|
|
case int32(TK_IF_NULL_ROW):
|
|
okConstFactor = libc.Uint8FromInt32(int32(Tbft(*(*uint16)(unsafe.Pointer(pParse + 28)) & 0x80 >> 7)))
|
|
pAggInfo1 = (*TExpr)(unsafe.Pointer(pExpr)).FpAggInfo
|
|
if pAggInfo1 != 0 {
|
|
if !((*TAggInfo)(unsafe.Pointer(pAggInfo1)).FdirectMode != 0) {
|
|
inReg = (*TAggInfo)(unsafe.Pointer(pAggInfo1)).FiFirstReg + int32((*TExpr)(unsafe.Pointer(pExpr)).FiAgg)
|
|
break
|
|
}
|
|
if (*TAggInfo)(unsafe.Pointer((*TExpr)(unsafe.Pointer(pExpr)).FpAggInfo)).FuseSortingIdx != 0 {
|
|
_sqlite3VdbeAddOp3(tls, v, int32(OP_Column), (*TAggInfo)(unsafe.Pointer(pAggInfo1)).FsortingIdxPTab, (**(**TAggInfo_col)(__ccgo_up((*TAggInfo)(unsafe.Pointer(pAggInfo1)).FaCol + uintptr((*TExpr)(unsafe.Pointer(pExpr)).FiAgg)*20))).FiSorterColumn, target)
|
|
inReg = target
|
|
break
|
|
}
|
|
}
|
|
addrINR = _sqlite3VdbeAddOp3(tls, v, int32(OP_IfNullRow), (*TExpr)(unsafe.Pointer(pExpr)).FiTable, 0, target)
|
|
/* The OP_IfNullRow opcode above can overwrite the result register with
|
|
** NULL. So we have to ensure that the result register is not a value
|
|
** that is suppose to be a constant. Two defenses are needed:
|
|
** (1) Temporarily disable factoring of constant expressions
|
|
** (2) Make sure the computed value really is stored in register
|
|
** "target" and not someplace else.
|
|
*/
|
|
libc.SetBitFieldPtr16Uint32(pParse+28, libc.Uint32FromInt32(0), 7, 0x80) /* note (1) above */
|
|
_sqlite3ExprCode(tls, pParse, (*TExpr)(unsafe.Pointer(pExpr)).FpLeft, target)
|
|
libc.SetBitFieldPtr16Uint32(pParse+28, uint32(okConstFactor), 7, 0x80)
|
|
_sqlite3VdbeJumpHere(tls, v, addrINR)
|
|
break
|
|
/*
|
|
** Form A:
|
|
** CASE x WHEN e1 THEN r1 WHEN e2 THEN r2 ... WHEN eN THEN rN ELSE y END
|
|
**
|
|
** Form B:
|
|
** CASE WHEN e1 THEN r1 WHEN e2 THEN r2 ... WHEN eN THEN rN ELSE y END
|
|
**
|
|
** Form A is can be transformed into the equivalent form B as follows:
|
|
** CASE WHEN x=e1 THEN r1 WHEN x=e2 THEN r2 ...
|
|
** WHEN x=eN THEN rN ELSE y END
|
|
**
|
|
** X (if it exists) is in pExpr->pLeft.
|
|
** Y is in the last element of pExpr->x.pList if pExpr->x.pList->nExpr is
|
|
** odd. The Y is also optional. If the number of elements in x.pList
|
|
** is even, then Y is omitted and the "otherwise" result is NULL.
|
|
** Ei is in pExpr->pList->a[i*2] and Ri is pExpr->pList->a[i*2+1].
|
|
**
|
|
** The result of the expression is the Ri for the first matching Ei,
|
|
** or if there is no matching Ei, the ELSE term Y, or if there is
|
|
** no ELSE term, NULL.
|
|
*/
|
|
fallthrough
|
|
case int32(TK_CASE): /* The X expression */
|
|
pTest = uintptr(0) /* X==Ei (form A) or just Ei (form B) */
|
|
pDel = uintptr(0)
|
|
db1 = (*TParse)(unsafe.Pointer(pParse)).Fdb
|
|
pEList = *(*uintptr)(unsafe.Pointer(pExpr + 20))
|
|
aListelem = pEList + 8
|
|
nExpr = (*TExprList)(unsafe.Pointer(pEList)).FnExpr
|
|
endLabel = _sqlite3VdbeMakeLabel(tls, pParse)
|
|
v3 = (*TExpr)(unsafe.Pointer(pExpr)).FpLeft
|
|
pX = v3
|
|
if v3 != uintptr(0) {
|
|
pDel = _sqlite3ExprDup(tls, db1, pX, 0)
|
|
if (*Tsqlite3)(unsafe.Pointer(db1)).FmallocFailed != 0 {
|
|
_sqlite3ExprDelete(tls, db1, pDel)
|
|
break
|
|
}
|
|
_sqlite3ExprToRegister(tls, pDel, _exprCodeVector(tls, pParse, pDel, bp))
|
|
libc.Xmemset(tls, bp+68, 0, uint32(52))
|
|
(**(**TExpr)(__ccgo_up(bp + 68))).Fop = uint8(TK_EQ)
|
|
(**(**TExpr)(__ccgo_up(bp + 68))).FpLeft = pDel
|
|
pTest = bp + 68
|
|
/* Ticket b351d95f9cd5ef17e9d9dbae18f5ca8611190001:
|
|
** The value in regFree1 might get SCopy-ed into the file result.
|
|
** So make sure that the regFree1 register is not reused for other
|
|
** purposes and possibly overwritten. */
|
|
**(**int32)(__ccgo_up(bp)) = 0
|
|
}
|
|
i1 = 0
|
|
for {
|
|
if !(i1 < nExpr-int32(1)) {
|
|
break
|
|
}
|
|
if pX != 0 {
|
|
(**(**TExpr)(__ccgo_up(bp + 68))).FpRight = (**(**TExprList_item)(__ccgo_up(aListelem + uintptr(i1)*20))).FpExpr
|
|
} else {
|
|
pTest = (**(**TExprList_item)(__ccgo_up(aListelem + uintptr(i1)*20))).FpExpr
|
|
}
|
|
nextCase = _sqlite3VdbeMakeLabel(tls, pParse)
|
|
_sqlite3ExprIfFalse(tls, pParse, pTest, nextCase, int32(SQLITE_JUMPIFNULL))
|
|
_sqlite3ExprCode(tls, pParse, (**(**TExprList_item)(__ccgo_up(aListelem + uintptr(i1+int32(1))*20))).FpExpr, target)
|
|
_sqlite3VdbeGoto(tls, v, endLabel)
|
|
_sqlite3VdbeResolveLabel(tls, v, nextCase)
|
|
goto _13
|
|
_13:
|
|
;
|
|
i1 = i1 + int32(2)
|
|
}
|
|
if nExpr&int32(1) != 0 {
|
|
_sqlite3ExprCode(tls, pParse, (*(*TExprList_item)(unsafe.Pointer(pEList + 8 + uintptr(nExpr-int32(1))*20))).FpExpr, target)
|
|
} else {
|
|
_sqlite3VdbeAddOp2(tls, v, int32(OP_Null), 0, target)
|
|
}
|
|
_sqlite3ExprDelete(tls, db1, pDel)
|
|
_setDoNotMergeFlagOnCopy(tls, v)
|
|
_sqlite3VdbeResolveLabel(tls, v, endLabel)
|
|
case int32(TK_RAISE):
|
|
if !((*TParse)(unsafe.Pointer(pParse)).FpTriggerTab != 0) && !((*TParse)(unsafe.Pointer(pParse)).Fnested != 0) {
|
|
_sqlite3ErrorMsg(tls, pParse, __ccgo_ts+8566, 0)
|
|
return 0
|
|
}
|
|
if int32((*TExpr)(unsafe.Pointer(pExpr)).FaffExpr) == int32(OE_Abort) {
|
|
_sqlite3MayAbort(tls, pParse)
|
|
}
|
|
if int32((*TExpr)(unsafe.Pointer(pExpr)).FaffExpr) == int32(OE_Ignore) {
|
|
_sqlite3VdbeAddOp2(tls, v, int32(OP_Halt), SQLITE_OK, int32(OE_Ignore))
|
|
} else {
|
|
**(**int32)(__ccgo_up(bp + 8)) = _sqlite3ExprCodeTemp(tls, pParse, (*TExpr)(unsafe.Pointer(pExpr)).FpLeft, bp)
|
|
if (*TParse)(unsafe.Pointer(pParse)).FpTriggerTab != 0 {
|
|
v1 = libc.Int32FromInt32(SQLITE_CONSTRAINT) | libc.Int32FromInt32(7)<<libc.Int32FromInt32(8)
|
|
} else {
|
|
v1 = int32(SQLITE_ERROR)
|
|
}
|
|
_sqlite3VdbeAddOp3(tls, v, int32(OP_Halt), v1, int32((*TExpr)(unsafe.Pointer(pExpr)).FaffExpr), **(**int32)(__ccgo_up(bp + 8)))
|
|
}
|
|
break
|
|
}
|
|
_sqlite3ReleaseTempReg(tls, pParse, **(**int32)(__ccgo_up(bp)))
|
|
_sqlite3ReleaseTempReg(tls, pParse, **(**int32)(__ccgo_up(bp + 4)))
|
|
return inReg
|
|
}
|
|
|
|
// 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 + 36)) = int32((*TToken)(unsafe.Pointer(pToken)).Fz) - int32((*TParse)(unsafe.Pointer(pParse)).FzTail)
|
|
if pList != 0 && (*TExprList)(unsafe.Pointer(pList)).FnExpr > **(**int32)(__ccgo_up((*TParse)(unsafe.Pointer(pParse)).Fdb + 116 + 6*4)) && !((*TParse)(unsafe.Pointer(pParse)).Fnested != 0) {
|
|
_sqlite3ErrorMsg(tls, pParse, __ccgo_ts+7957, libc.VaList(bp+8, pToken))
|
|
}
|
|
*(*uintptr)(unsafe.Pointer(pNew + 20)) = 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
|
|
//
|
|
// /*
|
|
// ** 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 + 116 + 2*4))
|
|
if pEList != 0 && (*TExprList)(unsafe.Pointer(pEList)).FnExpr > mx {
|
|
_sqlite3ErrorMsg(tls, pParse, __ccgo_ts+8157, libc.VaList(bp+8, zObject))
|
|
}
|
|
}
|
|
|
|
// C documentation
|
|
//
|
|
// /*
|
|
// ** This function is used by the implementation of the IN (...) operator.
|
|
// ** The pX parameter is the expression on the RHS of the IN operator, which
|
|
// ** might be either a list of expressions or a subquery.
|
|
// **
|
|
// ** The job of this routine is to find or create a b-tree object that can
|
|
// ** be used either to test for membership in the RHS set or to iterate through
|
|
// ** all members of the RHS set, skipping duplicates.
|
|
// **
|
|
// ** A cursor is opened on the b-tree object that is the RHS of the IN operator
|
|
// ** and the *piTab parameter is set to the index of that cursor.
|
|
// **
|
|
// ** The returned value of this function indicates the b-tree type, as follows:
|
|
// **
|
|
// ** IN_INDEX_ROWID - The cursor was opened on a database table.
|
|
// ** IN_INDEX_INDEX_ASC - The cursor was opened on an ascending index.
|
|
// ** IN_INDEX_INDEX_DESC - The cursor was opened on a descending index.
|
|
// ** IN_INDEX_EPH - The cursor was opened on a specially created and
|
|
// ** populated ephemeral table.
|
|
// ** IN_INDEX_NOOP - No cursor was allocated. The IN operator must be
|
|
// ** implemented as a sequence of comparisons.
|
|
// **
|
|
// ** An existing b-tree might be used if the RHS expression pX is a simple
|
|
// ** subquery such as:
|
|
// **
|
|
// ** SELECT <column1>, <column2>... FROM <table>
|
|
// **
|
|
// ** If the RHS of the IN operator is a list or a more complex subquery, then
|
|
// ** an ephemeral table might need to be generated from the RHS and then
|
|
// ** pX->iTable made to point to the ephemeral table instead of an
|
|
// ** existing table. In this case, the creation and initialization of the
|
|
// ** ephemeral table might be put inside of a subroutine, the EP_Subrtn flag
|
|
// ** will be set on pX and the pX->y.sub fields will be set to show where
|
|
// ** the subroutine is coded.
|
|
// **
|
|
// ** The inFlags parameter must contain, at a minimum, one of the bits
|
|
// ** IN_INDEX_MEMBERSHIP or IN_INDEX_LOOP but not both. If inFlags contains
|
|
// ** IN_INDEX_MEMBERSHIP, then the generated table will be used for a fast
|
|
// ** membership test. When the IN_INDEX_LOOP bit is set, the IN index will
|
|
// ** be used to loop over all values of the RHS of the IN operator.
|
|
// **
|
|
// ** When IN_INDEX_LOOP is used (and the b-tree will be used to iterate
|
|
// ** through the set members) then the b-tree must not contain duplicates.
|
|
// ** An ephemeral table will be created unless the selected columns are guaranteed
|
|
// ** to be unique - either because it is an INTEGER PRIMARY KEY or due to
|
|
// ** a UNIQUE constraint or index.
|
|
// **
|
|
// ** When IN_INDEX_MEMBERSHIP is used (and the b-tree will be used
|
|
// ** for fast set membership tests) then an ephemeral table must
|
|
// ** be used unless <columns> is a single INTEGER PRIMARY KEY column or an
|
|
// ** index can be found with the specified <columns> as its left-most.
|
|
// **
|
|
// ** If the IN_INDEX_NOOP_OK and IN_INDEX_MEMBERSHIP are both set and
|
|
// ** if the RHS of the IN operator is a list (not a subquery) then this
|
|
// ** routine might decide that creating an ephemeral b-tree for membership
|
|
// ** testing is too expensive and return IN_INDEX_NOOP. In that case, the
|
|
// ** calling routine should implement the IN operator using a sequence
|
|
// ** of Eq or Ne comparison operations.
|
|
// **
|
|
// ** When the b-tree is being used for membership tests, the calling function
|
|
// ** might need to know whether or not the RHS side of the IN operator
|
|
// ** contains a NULL. If prRhsHasNull is not a NULL pointer and
|
|
// ** if there is any chance that the (...) might contain a NULL value at
|
|
// ** runtime, then a register is allocated and the register number written
|
|
// ** to *prRhsHasNull. If there is no chance that the (...) contains a
|
|
// ** NULL value, then *prRhsHasNull is left unchanged.
|
|
// **
|
|
// ** If a register is allocated and its location stored in *prRhsHasNull, then
|
|
// ** the value in that register will be NULL if the b-tree contains one or more
|
|
// ** NULL values, and it will be some non-NULL value if the b-tree contains no
|
|
// ** NULL values.
|
|
// **
|
|
// ** If the aiMap parameter is not NULL, it must point to an array containing
|
|
// ** one element for each column returned by the SELECT statement on the RHS
|
|
// ** of the IN(...) operator. The i'th entry of the array is populated with the
|
|
// ** offset of the index column that matches the i'th column returned by the
|
|
// ** SELECT. For example, if the expression and selected index are:
|
|
// **
|
|
// ** (?,?,?) IN (SELECT a, b, c FROM t1)
|
|
// ** CREATE INDEX i1 ON t1(b, c, a);
|
|
// **
|
|
// ** then aiMap[] is populated with {2, 0, 1}.
|
|
// */
|
|
func _sqlite3FindInIndex(tls *libc.TLS, pParse uintptr, pX uintptr, inFlags Tu32, prRhsHasNull uintptr, aiMap uintptr, piTab uintptr) (r int32) {
|
|
bp := tls.Alloc(16)
|
|
defer tls.Free(16)
|
|
var affinity_ok, bloomOk, eType, i, i1, i2, iAddr, iAddr1, iCol, iDb, iTab, j, mustBeUnique, n, nExpr, rMayHaveNull, v1, v10 int32
|
|
var cmpaff, idxaff int8
|
|
var colUsed, mCol TBitmask
|
|
var db, p, pEList, pEList1, pIdx, pLhs, pLhs1, pReq, pRhs, pTab, v, v2 uintptr
|
|
var savedNQueryLoop Tu32
|
|
var v5 bool
|
|
_, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _ = affinity_ok, bloomOk, cmpaff, colUsed, db, eType, i, i1, i2, iAddr, iAddr1, iCol, iDb, iTab, idxaff, j, mCol, mustBeUnique, n, nExpr, p, pEList, pEList1, pIdx, pLhs, pLhs1, pReq, pRhs, pTab, rMayHaveNull, savedNQueryLoop, v, v1, v10, v2, v5 /* SELECT to the right of IN operator */
|
|
eType = 0 /* True if RHS must be unique */
|
|
v = _sqlite3GetVdbe(tls, pParse) /* Virtual machine being coded */
|
|
mustBeUnique = libc.BoolInt32(inFlags&uint32(IN_INDEX_LOOP) != uint32(0))
|
|
v2 = pParse + 44
|
|
v1 = *(*int32)(unsafe.Pointer(v2))
|
|
*(*int32)(unsafe.Pointer(v2)) = *(*int32)(unsafe.Pointer(v2)) + 1
|
|
iTab = v1
|
|
/* If the RHS of this IN(...) operator is a SELECT, and if it matters
|
|
** whether or not the SELECT result contains NULL values, check whether
|
|
** or not NULL is actually possible (it may not be, for example, due
|
|
** to NOT NULL constraints in the schema). If no NULL values are possible,
|
|
** set prRhsHasNull to 0 before continuing. */
|
|
if prRhsHasNull != 0 && (*TExpr)(unsafe.Pointer(pX)).Fflags&uint32(EP_xIsSelect) != uint32(0) {
|
|
pEList = (*TSelect)(unsafe.Pointer(*(*uintptr)(unsafe.Pointer(pX + 20)))).FpEList
|
|
i = 0
|
|
for {
|
|
if !(i < (*TExprList)(unsafe.Pointer(pEList)).FnExpr) {
|
|
break
|
|
}
|
|
if _sqlite3ExprCanBeNull(tls, (*(*TExprList_item)(unsafe.Pointer(pEList + 8 + uintptr(i)*20))).FpExpr) != 0 {
|
|
break
|
|
}
|
|
goto _3
|
|
_3:
|
|
;
|
|
i = i + 1
|
|
}
|
|
if i == (*TExprList)(unsafe.Pointer(pEList)).FnExpr {
|
|
prRhsHasNull = uintptr(0)
|
|
}
|
|
}
|
|
/* Check to see if an existing table or index can be used to
|
|
** satisfy the query. This is preferable to generating a new
|
|
** ephemeral table. */
|
|
if v5 = (*TParse)(unsafe.Pointer(pParse)).FnErr == 0; v5 {
|
|
v2 = _isCandidateForInOpt(tls, pX)
|
|
p = v2
|
|
}
|
|
if v5 && v2 != uintptr(0) {
|
|
db = (*TParse)(unsafe.Pointer(pParse)).Fdb /* Database idx for pTab */
|
|
pEList1 = (*TSelect)(unsafe.Pointer(p)).FpEList
|
|
nExpr = (*TExprList)(unsafe.Pointer(pEList1)).FnExpr
|
|
/* Because of isCandidateForInOpt(p) */
|
|
/* Because of isCandidateForInOpt(p) */
|
|
/* Because of isCandidateForInOpt(p) */
|
|
pTab = (*(*TSrcItem)(unsafe.Pointer((*TSelect)(unsafe.Pointer(p)).FpSrc + 8))).FpSTab
|
|
/* Code an OP_Transaction and OP_TableLock for <table>. */
|
|
iDb = _sqlite3SchemaToIndex(tls, db, (*TTable)(unsafe.Pointer(pTab)).FpSchema)
|
|
_sqlite3CodeVerifySchema(tls, pParse, iDb)
|
|
_sqlite3TableLock(tls, pParse, iDb, (*TTable)(unsafe.Pointer(pTab)).Ftnum, uint8(0), (*TTable)(unsafe.Pointer(pTab)).FzName)
|
|
/* sqlite3GetVdbe() has always been previously called */
|
|
if nExpr == int32(1) && int32((*TExpr)(unsafe.Pointer((*(*TExprList_item)(unsafe.Pointer(pEList1 + 8))).FpExpr)).FiColumn) < 0 {
|
|
/* The "x IN (SELECT rowid FROM table)" case */
|
|
iAddr = _sqlite3VdbeAddOp0(tls, v, int32(OP_Once))
|
|
_sqlite3OpenTable(tls, pParse, iTab, iDb, pTab, int32(OP_OpenRead))
|
|
eType = int32(IN_INDEX_ROWID)
|
|
_sqlite3VdbeExplain(tls, pParse, uint8(0), __ccgo_ts+8209, libc.VaList(bp+8, (*TTable)(unsafe.Pointer(pTab)).FzName))
|
|
_sqlite3VdbeJumpHere(tls, v, iAddr)
|
|
} else { /* Iterator variable */
|
|
affinity_ok = int32(1)
|
|
/* Check that the affinity that will be used to perform each
|
|
** comparison is the same as the affinity of each column in table
|
|
** on the RHS of the IN operator. If it not, it is not possible to
|
|
** use any index of the RHS table. */
|
|
i1 = 0
|
|
for {
|
|
if !(i1 < nExpr && affinity_ok != 0) {
|
|
break
|
|
}
|
|
pLhs = _sqlite3VectorFieldSubexpr(tls, (*TExpr)(unsafe.Pointer(pX)).FpLeft, i1)
|
|
iCol = int32((*TExpr)(unsafe.Pointer((*(*TExprList_item)(unsafe.Pointer(pEList1 + 8 + uintptr(i1)*20))).FpExpr)).FiColumn)
|
|
idxaff = _sqlite3TableColumnAffinity(tls, pTab, iCol) /* RHS table */
|
|
cmpaff = _sqlite3CompareAffinity(tls, pLhs, idxaff)
|
|
switch int32(cmpaff) {
|
|
case int32(SQLITE_AFF_BLOB):
|
|
case int32(SQLITE_AFF_TEXT):
|
|
/* sqlite3CompareAffinity() only returns TEXT if one side or the
|
|
** other has no affinity and the other side is TEXT. Hence,
|
|
** the only way for cmpaff to be TEXT is for idxaff to be TEXT
|
|
** and for the term on the LHS of the IN to have no affinity. */
|
|
default:
|
|
affinity_ok = libc.BoolInt32(int32(idxaff) >= int32(SQLITE_AFF_NUMERIC))
|
|
}
|
|
goto _6
|
|
_6:
|
|
;
|
|
i1 = i1 + 1
|
|
}
|
|
if affinity_ok != 0 {
|
|
/* Search for an existing index that will work for this IN operator */
|
|
pIdx = (*TTable)(unsafe.Pointer(pTab)).FpIndex
|
|
for {
|
|
if !(pIdx != 0 && eType == 0) {
|
|
break
|
|
} /* Mask for the current column */
|
|
if libc.Int32FromUint16((*TIndex)(unsafe.Pointer(pIdx)).FnColumn) < nExpr {
|
|
goto _7
|
|
}
|
|
if (*TIndex)(unsafe.Pointer(pIdx)).FpPartIdxWhere != uintptr(0) {
|
|
goto _7
|
|
}
|
|
/* Maximum nColumn is BMS-2, not BMS-1, so that we can compute
|
|
** BITMASK(nExpr) without overflowing */
|
|
if libc.Int32FromUint16((*TIndex)(unsafe.Pointer(pIdx)).FnColumn) >= libc.Int32FromUint32(libc.Uint32FromInt64(8)*libc.Uint32FromInt32(8))-libc.Int32FromInt32(1) {
|
|
goto _7
|
|
}
|
|
if mustBeUnique != 0 {
|
|
if libc.Int32FromUint16((*TIndex)(unsafe.Pointer(pIdx)).FnKeyCol) > nExpr || libc.Int32FromUint16((*TIndex)(unsafe.Pointer(pIdx)).FnColumn) > nExpr && !(libc.Int32FromUint8((*TIndex)(unsafe.Pointer(pIdx)).FonError) != libc.Int32FromInt32(OE_None)) {
|
|
goto _7 /* This index is not unique over the IN RHS columns */
|
|
}
|
|
}
|
|
colUsed = uint64(0) /* Columns of index used so far */
|
|
i1 = 0
|
|
for {
|
|
if !(i1 < nExpr) {
|
|
break
|
|
}
|
|
pLhs1 = _sqlite3VectorFieldSubexpr(tls, (*TExpr)(unsafe.Pointer(pX)).FpLeft, i1)
|
|
pRhs = (*(*TExprList_item)(unsafe.Pointer(pEList1 + 8 + uintptr(i1)*20))).FpExpr
|
|
pReq = _sqlite3BinaryCompareCollSeq(tls, pParse, pLhs1, pRhs)
|
|
j = 0
|
|
for {
|
|
if !(j < nExpr) {
|
|
break
|
|
}
|
|
if int32(**(**Ti16)(__ccgo_up((*TIndex)(unsafe.Pointer(pIdx)).FaiColumn + uintptr(j)*2))) != int32((*TExpr)(unsafe.Pointer(pRhs)).FiColumn) {
|
|
goto _9
|
|
}
|
|
if pReq != uintptr(0) && _sqlite3StrICmp(tls, (*TCollSeq)(unsafe.Pointer(pReq)).FzName, **(**uintptr)(__ccgo_up((*TIndex)(unsafe.Pointer(pIdx)).FazColl + uintptr(j)*4))) != 0 {
|
|
goto _9
|
|
}
|
|
break
|
|
goto _9
|
|
_9:
|
|
;
|
|
j = j + 1
|
|
}
|
|
if j == nExpr {
|
|
break
|
|
}
|
|
mCol = libc.Uint64FromInt32(1) << j
|
|
if mCol&colUsed != 0 {
|
|
break
|
|
} /* Each column used only once */
|
|
colUsed = colUsed | mCol
|
|
if aiMap != 0 {
|
|
**(**int32)(__ccgo_up(aiMap + uintptr(i1)*4)) = j
|
|
}
|
|
goto _8
|
|
_8:
|
|
;
|
|
i1 = i1 + 1
|
|
}
|
|
if colUsed == libc.Uint64FromInt32(1)<<nExpr-uint64(1) {
|
|
/* If we reach this point, that means the index pIdx is usable */
|
|
iAddr1 = _sqlite3VdbeAddOp0(tls, v, int32(OP_Once))
|
|
_sqlite3VdbeExplain(tls, pParse, uint8(0), __ccgo_ts+8256, libc.VaList(bp+8, (*TIndex)(unsafe.Pointer(pIdx)).FzName))
|
|
_sqlite3VdbeAddOp3(tls, v, int32(OP_OpenRead), iTab, libc.Int32FromUint32((*TIndex)(unsafe.Pointer(pIdx)).Ftnum), iDb)
|
|
_sqlite3VdbeSetP4KeyInfo(tls, pParse, pIdx)
|
|
eType = int32(IN_INDEX_INDEX_ASC) + libc.Int32FromUint8(**(**Tu8)(__ccgo_up((*TIndex)(unsafe.Pointer(pIdx)).FaSortOrder)))
|
|
if prRhsHasNull != 0 {
|
|
v2 = pParse + 48
|
|
*(*int32)(unsafe.Pointer(v2)) = *(*int32)(unsafe.Pointer(v2)) + 1
|
|
v1 = *(*int32)(unsafe.Pointer(v2))
|
|
**(**int32)(__ccgo_up(prRhsHasNull)) = v1
|
|
if nExpr == int32(1) {
|
|
_sqlite3SetHasNullFlag(tls, v, iTab, **(**int32)(__ccgo_up(prRhsHasNull)))
|
|
}
|
|
}
|
|
_sqlite3VdbeJumpHere(tls, v, iAddr1)
|
|
}
|
|
goto _7
|
|
_7:
|
|
;
|
|
pIdx = (*TIndex)(unsafe.Pointer(pIdx)).FpNext
|
|
} /* End loop over indexes */
|
|
} /* End if( affinity_ok ) */
|
|
} /* End if not an rowid index */
|
|
} /* End attempt to optimize using an index */
|
|
/* If no preexisting index is available for the IN clause
|
|
** and IN_INDEX_NOOP is an allowed reply
|
|
** and the RHS of the IN operator is a list, not a subquery
|
|
** and the RHS is not constant or has two or fewer terms,
|
|
** then it is not worth creating an ephemeral table to evaluate
|
|
** the IN operator so return IN_INDEX_NOOP.
|
|
*/
|
|
if eType == 0 && inFlags&uint32(IN_INDEX_NOOP_OK) != 0 && (*TExpr)(unsafe.Pointer(pX)).Fflags&uint32(EP_xIsSelect) == uint32(0) && (!(_sqlite3InRhsIsConstant(tls, pParse, pX) != 0) || (*TExprList)(unsafe.Pointer(*(*uintptr)(unsafe.Pointer(pX + 20)))).FnExpr <= int32(2)) {
|
|
(*TParse)(unsafe.Pointer(pParse)).FnTab = (*TParse)(unsafe.Pointer(pParse)).FnTab - 1 /* Back out the allocation of the unused cursor */
|
|
iTab = -int32(1) /* Cursor is not allocated */
|
|
eType = int32(IN_INDEX_NOOP)
|
|
}
|
|
if eType == 0 {
|
|
/* Could not find an existing table or index to use as the RHS b-tree.
|
|
** We will have to generate an ephemeral table to do the job.
|
|
*/
|
|
savedNQueryLoop = libc.Uint32FromInt16((*TParse)(unsafe.Pointer(pParse)).FnQueryLoop)
|
|
rMayHaveNull = 0
|
|
bloomOk = libc.BoolInt32(inFlags&uint32(IN_INDEX_MEMBERSHIP) != uint32(0))
|
|
eType = int32(IN_INDEX_EPH)
|
|
if inFlags&uint32(IN_INDEX_LOOP) != 0 {
|
|
(*TParse)(unsafe.Pointer(pParse)).FnQueryLoop = 0
|
|
} else {
|
|
if prRhsHasNull != 0 {
|
|
v2 = pParse + 48
|
|
*(*int32)(unsafe.Pointer(v2)) = *(*int32)(unsafe.Pointer(v2)) + 1
|
|
v10 = *(*int32)(unsafe.Pointer(v2))
|
|
v1 = v10
|
|
rMayHaveNull = v1
|
|
**(**int32)(__ccgo_up(prRhsHasNull)) = v1
|
|
}
|
|
}
|
|
if !(bloomOk != 0) && (*TExpr)(unsafe.Pointer(pX)).Fflags&uint32(EP_xIsSelect) != uint32(0) && (*TSelect)(unsafe.Pointer(*(*uintptr)(unsafe.Pointer(pX + 20)))).FselFlags&uint32(SF_ClonedRhsIn) != uint32(0) {
|
|
bloomOk = int32(1)
|
|
}
|
|
_sqlite3CodeRhsOfIN(tls, pParse, pX, iTab, bloomOk)
|
|
if rMayHaveNull != 0 {
|
|
_sqlite3SetHasNullFlag(tls, v, iTab, rMayHaveNull)
|
|
}
|
|
(*TParse)(unsafe.Pointer(pParse)).FnQueryLoop = libc.Int16FromUint32(savedNQueryLoop)
|
|
}
|
|
if aiMap != 0 && eType != int32(IN_INDEX_INDEX_ASC) && eType != int32(IN_INDEX_INDEX_DESC) {
|
|
n = _sqlite3ExprVectorSize(tls, (*TExpr)(unsafe.Pointer(pX)).FpLeft)
|
|
i2 = 0
|
|
for {
|
|
if !(i2 < n) {
|
|
break
|
|
}
|
|
**(**int32)(__ccgo_up(aiMap + uintptr(i2)*4)) = i2
|
|
goto _15
|
|
_15:
|
|
;
|
|
i2 = i2 + 1
|
|
}
|
|
}
|
|
**(**int32)(__ccgo_up(piTab)) = iTab
|
|
return eType
|
|
}
|
|
|
|
// C documentation
|
|
//
|
|
// /*
|
|
// ** Decode a floating-point value into an approximate decimal
|
|
// ** representation.
|
|
// **
|
|
// ** If iRound<=0 then round to -iRound significant digits to the
|
|
// ** the right of the decimal point, or to a maximum of mxRound total
|
|
// ** significant digits.
|
|
// **
|
|
// ** If iRound>0 round to min(iRound,mxRound) significant digits total.
|
|
// **
|
|
// ** mxRound must be positive.
|
|
// **
|
|
// ** The significant digits of the decimal representation are
|
|
// ** stored in p->z[] which is a often (but not always) a pointer
|
|
// ** into the middle of p->zBuf[]. There are p->n significant digits.
|
|
// ** The p->z[] array is *not* zero-terminated.
|
|
// */
|
|
func _sqlite3FpDecode(tls *libc.TLS, p uintptr, _r float64, iRound int32, mxRound int32) {
|
|
bp := tls.Alloc(32)
|
|
defer tls.Free(32)
|
|
*(*float64)(unsafe.Pointer(bp)) = _r
|
|
var e, i, j, jj, jj1, kk, kk1, kk2, n, nn, v1 int32
|
|
var v2, v21 Tu64
|
|
var z, zBuf uintptr
|
|
var _ /* exp at bp+16 */ int32
|
|
var _ /* v at bp+8 */ Tu64
|
|
_, _, _, _, _, _, _, _, _, _, _, _, _, _, _ = e, i, j, jj, jj1, kk, kk1, kk2, n, nn, v2, v21, z, zBuf, v1
|
|
**(**int32)(__ccgo_up(bp + 16)) = 0 /* Local alias for p->z */
|
|
(*TFpDecode)(unsafe.Pointer(p)).FisSpecial = 0
|
|
/* Convert negative numbers to positive. Deal with Infinity, 0.0, and
|
|
** NaN. */
|
|
if **(**float64)(__ccgo_up(bp)) < float64(0) {
|
|
(*TFpDecode)(unsafe.Pointer(p)).Fsign = int8('-')
|
|
**(**float64)(__ccgo_up(bp)) = -**(**float64)(__ccgo_up(bp))
|
|
} else {
|
|
if **(**float64)(__ccgo_up(bp)) == float64(0) {
|
|
(*TFpDecode)(unsafe.Pointer(p)).Fsign = int8('+')
|
|
(*TFpDecode)(unsafe.Pointer(p)).Fn = int32(1)
|
|
(*TFpDecode)(unsafe.Pointer(p)).FiDP = int32(1)
|
|
(*TFpDecode)(unsafe.Pointer(p)).Fz = __ccgo_ts + 1848
|
|
return
|
|
} else {
|
|
(*TFpDecode)(unsafe.Pointer(p)).Fsign = int8('+')
|
|
}
|
|
}
|
|
libc.Xmemcpy(tls, bp+8, bp, uint32(8))
|
|
e = libc.Int32FromUint64(**(**Tu64)(__ccgo_up(bp + 8)) >> libc.Int32FromInt32(52) & uint64(0x7ff))
|
|
if e == int32(0x7ff) {
|
|
(*TFpDecode)(unsafe.Pointer(p)).FisSpecial = int8(int32(1) + libc.BoolInt32(**(**Tu64)(__ccgo_up(bp + 8)) != uint64(0x7ff0000000000000)))
|
|
(*TFpDecode)(unsafe.Pointer(p)).Fn = 0
|
|
(*TFpDecode)(unsafe.Pointer(p)).FiDP = 0
|
|
(*TFpDecode)(unsafe.Pointer(p)).Fz = p + 12
|
|
return
|
|
}
|
|
**(**Tu64)(__ccgo_up(bp + 8)) = **(**Tu64)(__ccgo_up(bp + 8)) & uint64(0x000fffffffffffff)
|
|
if e == 0 {
|
|
nn = _countLeadingZeros(tls, **(**Tu64)(__ccgo_up(bp + 8)))
|
|
**(**Tu64)(__ccgo_up(bp + 8)) = **(**Tu64)(__ccgo_up(bp + 8)) << libc.Uint64FromInt32(nn)
|
|
e = -int32(1074) - nn
|
|
} else {
|
|
**(**Tu64)(__ccgo_up(bp + 8)) = **(**Tu64)(__ccgo_up(bp + 8))<<libc.Int32FromInt32(11) | libc.Uint64FromInt32(1)<<libc.Int32FromInt32(63)
|
|
e = e - int32(1086)
|
|
}
|
|
if iRound <= 0 || iRound >= int32(18) {
|
|
v1 = int32(18)
|
|
} else {
|
|
v1 = iRound + int32(1)
|
|
}
|
|
_sqlite3Fp2Convert10(tls, **(**Tu64)(__ccgo_up(bp + 8)), e, v1, bp+8, bp+16)
|
|
/* Extract significant digits, start at the right-most slot in p->zBuf
|
|
** and working back to the right. "i" keeps track of the next slot in
|
|
** which to store a digit. */
|
|
zBuf = p + 12
|
|
i = int32(SQLITE_U64_DIGITS)
|
|
for **(**Tu64)(__ccgo_up(bp + 8)) >= uint64(10) {
|
|
kk = libc.Int32FromUint64(**(**Tu64)(__ccgo_up(bp + 8)) % uint64(100) * uint64(2))
|
|
**(**Tu16)(__ccgo_up(zBuf + uintptr(i-int32(2)))) = **(**Tu16)(__ccgo_up(uintptr(unsafe.Pointer(&_sqlite3DigitPairs)) + uintptr(kk)))
|
|
i = i - int32(2)
|
|
**(**Tu64)(__ccgo_up(bp + 8)) = **(**Tu64)(__ccgo_up(bp + 8)) / uint64(100)
|
|
}
|
|
if **(**Tu64)(__ccgo_up(bp + 8)) != 0 {
|
|
i = i - 1
|
|
v1 = i
|
|
**(**int8)(__ccgo_up(zBuf + uintptr(v1))) = libc.Int8FromUint64(**(**Tu64)(__ccgo_up(bp + 8)) + uint64('0'))
|
|
}
|
|
n = int32(SQLITE_U64_DIGITS) - i /* Total number of digits extracted */
|
|
(*TFpDecode)(unsafe.Pointer(p)).FiDP = n + **(**int32)(__ccgo_up(bp + 16))
|
|
if iRound <= 0 {
|
|
iRound = (*TFpDecode)(unsafe.Pointer(p)).FiDP - iRound
|
|
if iRound == 0 && int32(**(**int8)(__ccgo_up(zBuf + uintptr(i)))) >= int32('5') {
|
|
iRound = int32(1)
|
|
i = i - 1
|
|
v1 = i
|
|
**(**int8)(__ccgo_up(zBuf + uintptr(v1))) = int8('0')
|
|
n = n + 1
|
|
(*TFpDecode)(unsafe.Pointer(p)).FiDP = (*TFpDecode)(unsafe.Pointer(p)).FiDP + 1
|
|
}
|
|
}
|
|
z = zBuf + uintptr(i) /* z points to the first digit */
|
|
if iRound > 0 && (iRound < n || n > mxRound) {
|
|
if iRound > mxRound {
|
|
iRound = mxRound
|
|
}
|
|
if iRound == int32(17) {
|
|
/* If the precision is exactly 17, which only happens with the "!"
|
|
** flag (ex: "%!.17g") then try to reduce the precision if that
|
|
** yields text that will round-trip to the original floating-point.
|
|
** value. Thus, for exaple, 49.47 will render as 49.47, rather than
|
|
** as 49.469999999999999. */
|
|
if int32(**(**int8)(__ccgo_up(z + 15))) == int32('9') && int32(**(**int8)(__ccgo_up(z + 14))) == int32('9') {
|
|
jj = int32(14)
|
|
for {
|
|
if !(jj > 0 && int32(**(**int8)(__ccgo_up(z + uintptr(jj-int32(1))))) == int32('9')) {
|
|
break
|
|
}
|
|
goto _4
|
|
_4:
|
|
;
|
|
jj = jj - 1
|
|
}
|
|
if jj == 0 {
|
|
v2 = uint64(1)
|
|
} else {
|
|
v2 = libc.Uint64FromInt32(int32(**(**int8)(__ccgo_up(z))) - int32('0'))
|
|
kk1 = int32(1)
|
|
for {
|
|
if !(kk1 < jj) {
|
|
break
|
|
}
|
|
v2 = v2*uint64(10) + libc.Uint64FromInt8(**(**int8)(__ccgo_up(z + uintptr(kk1)))) - uint64('0')
|
|
goto _5
|
|
_5:
|
|
;
|
|
kk1 = kk1 + 1
|
|
}
|
|
v2 = v2 + 1
|
|
}
|
|
if **(**float64)(__ccgo_up(bp)) == _sqlite3Fp10Convert2(tls, v2, **(**int32)(__ccgo_up(bp + 16))+n-jj) {
|
|
iRound = jj + int32(1)
|
|
}
|
|
} else {
|
|
if (*TFpDecode)(unsafe.Pointer(p)).FiDP >= n || int32(**(**int8)(__ccgo_up(z + 15))) == int32('0') && int32(**(**int8)(__ccgo_up(z + 14))) == int32('0') && int32(**(**int8)(__ccgo_up(z + 13))) == int32('0') {
|
|
jj1 = int32(13)
|
|
for {
|
|
if !(int32(**(**int8)(__ccgo_up(z + uintptr(jj1-int32(1))))) == int32('0')) {
|
|
break
|
|
}
|
|
goto _6
|
|
_6:
|
|
;
|
|
jj1 = jj1 - 1
|
|
}
|
|
v21 = libc.Uint64FromInt32(int32(**(**int8)(__ccgo_up(z))) - int32('0'))
|
|
kk2 = int32(1)
|
|
for {
|
|
if !(kk2 < jj1) {
|
|
break
|
|
}
|
|
v21 = v21*uint64(10) + libc.Uint64FromInt8(**(**int8)(__ccgo_up(z + uintptr(kk2)))) - uint64('0')
|
|
goto _7
|
|
_7:
|
|
;
|
|
kk2 = kk2 + 1
|
|
}
|
|
if **(**float64)(__ccgo_up(bp)) == _sqlite3Fp10Convert2(tls, v21, **(**int32)(__ccgo_up(bp + 16))+n-jj1) {
|
|
iRound = jj1 + int32(1)
|
|
}
|
|
}
|
|
}
|
|
}
|
|
n = iRound
|
|
if int32(**(**int8)(__ccgo_up(z + uintptr(iRound)))) >= int32('5') {
|
|
j = iRound - int32(1)
|
|
for int32(1) != 0 {
|
|
**(**int8)(__ccgo_up(z + uintptr(j))) = **(**int8)(__ccgo_up(z + uintptr(j))) + 1
|
|
if int32(**(**int8)(__ccgo_up(z + uintptr(j)))) <= int32('9') {
|
|
break
|
|
}
|
|
**(**int8)(__ccgo_up(z + uintptr(j))) = int8('0')
|
|
if j == 0 {
|
|
z = z - 1
|
|
**(**int8)(__ccgo_up(z)) = int8('1')
|
|
n = n + 1
|
|
(*TFpDecode)(unsafe.Pointer(p)).FiDP = (*TFpDecode)(unsafe.Pointer(p)).FiDP + 1
|
|
break
|
|
} else {
|
|
j = j - 1
|
|
}
|
|
}
|
|
}
|
|
}
|
|
for int32(**(**int8)(__ccgo_up(z + uintptr(n-int32(1))))) == int32('0') {
|
|
n = n - 1
|
|
}
|
|
(*TFpDecode)(unsafe.Pointer(p)).Fn = n
|
|
(*TFpDecode)(unsafe.Pointer(p)).Fz = z
|
|
}
|
|
|
|
// C documentation
|
|
//
|
|
// /*
|
|
// ** Arguments nArg/azArg contain the string arguments passed to the xCreate
|
|
// ** or xConnect method of the virtual table. This function attempts to
|
|
// ** allocate an instance of Fts5Config containing the results of parsing
|
|
// ** those arguments.
|
|
// **
|
|
// ** If successful, SQLITE_OK is returned and *ppOut is set to point to the
|
|
// ** new Fts5Config object. If an error occurs, an SQLite error code is
|
|
// ** returned, *ppOut is set to NULL and an error message may be left in
|
|
// ** *pzErr. It is the responsibility of the caller to eventually free any
|
|
// ** such error message using sqlite3_free().
|
|
// */
|
|
func _sqlite3Fts5ConfigParse(tls *libc.TLS, pGlobal uintptr, db uintptr, nArg int32, azArg uintptr, ppOut uintptr, pzErr uintptr) (r int32) {
|
|
bp := tls.Alloc(64)
|
|
defer tls.Free(64)
|
|
var bOption, i int32
|
|
var nByte Tsqlite3_int64
|
|
var pRet, z, zOrig, zTail, v1, v2 uintptr
|
|
var _ /* bDummy at bp+20 */ int32
|
|
var _ /* bMustBeCol at bp+16 */ int32
|
|
var _ /* bUnindexed at bp+4 */ int32
|
|
var _ /* rc at bp+0 */ int32
|
|
var _ /* zOne at bp+8 */ uintptr
|
|
var _ /* zTwo at bp+12 */ uintptr
|
|
_, _, _, _, _, _, _, _, _ = bOption, i, nByte, pRet, z, zOrig, zTail, v1, v2
|
|
**(**int32)(__ccgo_up(bp)) = SQLITE_OK
|
|
**(**int32)(__ccgo_up(bp + 4)) = 0 /* True if there are one or more UNINDEXED */
|
|
v1 = Xsqlite3_malloc64(tls, uint64(164))
|
|
pRet = v1
|
|
**(**uintptr)(__ccgo_up(ppOut)) = v1
|
|
if pRet == uintptr(0) {
|
|
return int32(SQLITE_NOMEM)
|
|
}
|
|
libc.Xmemset(tls, pRet, 0, uint32(164))
|
|
(*TFts5Config)(unsafe.Pointer(pRet)).FpGlobal = pGlobal
|
|
(*TFts5Config)(unsafe.Pointer(pRet)).Fdb = db
|
|
(*TFts5Config)(unsafe.Pointer(pRet)).FiCookie = -int32(1)
|
|
nByte = libc.Int64FromUint32(libc.Uint32FromInt32(nArg) * (libc.Uint32FromInt64(4) + libc.Uint32FromInt64(1)))
|
|
(*TFts5Config)(unsafe.Pointer(pRet)).FazCol = _sqlite3Fts5MallocZero(tls, bp, nByte)
|
|
if (*TFts5Config)(unsafe.Pointer(pRet)).FazCol != 0 {
|
|
v1 = (*TFts5Config)(unsafe.Pointer(pRet)).FazCol + uintptr(nArg)*4
|
|
} else {
|
|
v1 = uintptr(0)
|
|
}
|
|
(*TFts5Config)(unsafe.Pointer(pRet)).FabUnindexed = v1
|
|
(*TFts5Config)(unsafe.Pointer(pRet)).FzDb = _sqlite3Fts5Strndup(tls, bp, **(**uintptr)(__ccgo_up(azArg + 1*4)), -int32(1))
|
|
(*TFts5Config)(unsafe.Pointer(pRet)).FzName = _sqlite3Fts5Strndup(tls, bp, **(**uintptr)(__ccgo_up(azArg + 2*4)), -int32(1))
|
|
(*TFts5Config)(unsafe.Pointer(pRet)).FbColumnsize = int32(1)
|
|
(*TFts5Config)(unsafe.Pointer(pRet)).FeDetail = FTS5_DETAIL_FULL
|
|
if **(**int32)(__ccgo_up(bp)) == SQLITE_OK && Xsqlite3_stricmp(tls, (*TFts5Config)(unsafe.Pointer(pRet)).FzName, __ccgo_ts+37966) == 0 {
|
|
**(**uintptr)(__ccgo_up(pzErr)) = Xsqlite3_mprintf(tls, __ccgo_ts+38077, libc.VaList(bp+32, (*TFts5Config)(unsafe.Pointer(pRet)).FzName))
|
|
**(**int32)(__ccgo_up(bp)) = int32(SQLITE_ERROR)
|
|
}
|
|
i = int32(3)
|
|
for {
|
|
if !(**(**int32)(__ccgo_up(bp)) == SQLITE_OK && i < nArg) {
|
|
break
|
|
}
|
|
zOrig = **(**uintptr)(__ccgo_up(azArg + uintptr(i)*4))
|
|
**(**uintptr)(__ccgo_up(bp + 8)) = uintptr(0)
|
|
**(**uintptr)(__ccgo_up(bp + 12)) = uintptr(0)
|
|
bOption = 0
|
|
**(**int32)(__ccgo_up(bp + 16)) = 0
|
|
z = _fts5ConfigGobbleWord(tls, bp, zOrig, bp+8, bp+16)
|
|
z = _fts5ConfigSkipWhitespace(tls, z)
|
|
if z != 0 && int32(**(**int8)(__ccgo_up(z))) == int32('=') {
|
|
bOption = int32(1)
|
|
z = z + 1
|
|
if **(**int32)(__ccgo_up(bp + 16)) != 0 {
|
|
z = uintptr(0)
|
|
}
|
|
}
|
|
z = _fts5ConfigSkipWhitespace(tls, z)
|
|
if z != 0 && **(**int8)(__ccgo_up(z)) != 0 {
|
|
z = _fts5ConfigGobbleWord(tls, bp, z, bp+12, bp+20)
|
|
if z != 0 && **(**int8)(__ccgo_up(z)) != 0 {
|
|
z = uintptr(0)
|
|
}
|
|
}
|
|
if **(**int32)(__ccgo_up(bp)) == SQLITE_OK {
|
|
if z == uintptr(0) {
|
|
**(**uintptr)(__ccgo_up(pzErr)) = Xsqlite3_mprintf(tls, __ccgo_ts+38106, libc.VaList(bp+32, zOrig))
|
|
**(**int32)(__ccgo_up(bp)) = int32(SQLITE_ERROR)
|
|
} else {
|
|
if bOption != 0 {
|
|
if **(**uintptr)(__ccgo_up(bp + 8)) != 0 {
|
|
v1 = **(**uintptr)(__ccgo_up(bp + 8))
|
|
} else {
|
|
v1 = __ccgo_ts + 1702
|
|
}
|
|
if **(**uintptr)(__ccgo_up(bp + 12)) != 0 {
|
|
v2 = **(**uintptr)(__ccgo_up(bp + 12))
|
|
} else {
|
|
v2 = __ccgo_ts + 1702
|
|
}
|
|
**(**int32)(__ccgo_up(bp)) = _fts5ConfigParseSpecial(tls, pRet, v1, v2, pzErr)
|
|
} else {
|
|
**(**int32)(__ccgo_up(bp)) = _fts5ConfigParseColumn(tls, pRet, **(**uintptr)(__ccgo_up(bp + 8)), **(**uintptr)(__ccgo_up(bp + 12)), pzErr, bp+4)
|
|
**(**uintptr)(__ccgo_up(bp + 8)) = uintptr(0)
|
|
}
|
|
}
|
|
}
|
|
Xsqlite3_free(tls, **(**uintptr)(__ccgo_up(bp + 8)))
|
|
Xsqlite3_free(tls, **(**uintptr)(__ccgo_up(bp + 12)))
|
|
goto _3
|
|
_3:
|
|
;
|
|
i = i + 1
|
|
}
|
|
/* We only allow contentless_delete=1 if the table is indeed contentless. */
|
|
if **(**int32)(__ccgo_up(bp)) == SQLITE_OK && (*TFts5Config)(unsafe.Pointer(pRet)).FbContentlessDelete != 0 && (*TFts5Config)(unsafe.Pointer(pRet)).FeContent != int32(FTS5_CONTENT_NONE) {
|
|
**(**uintptr)(__ccgo_up(pzErr)) = Xsqlite3_mprintf(tls, __ccgo_ts+38126, 0)
|
|
**(**int32)(__ccgo_up(bp)) = int32(SQLITE_ERROR)
|
|
}
|
|
/* We only allow contentless_delete=1 if columnsize=0 is not present.
|
|
**
|
|
** This restriction may be removed at some point.
|
|
*/
|
|
if **(**int32)(__ccgo_up(bp)) == SQLITE_OK && (*TFts5Config)(unsafe.Pointer(pRet)).FbContentlessDelete != 0 && (*TFts5Config)(unsafe.Pointer(pRet)).FbColumnsize == 0 {
|
|
**(**uintptr)(__ccgo_up(pzErr)) = Xsqlite3_mprintf(tls, __ccgo_ts+38176, 0)
|
|
**(**int32)(__ccgo_up(bp)) = int32(SQLITE_ERROR)
|
|
}
|
|
/* We only allow contentless_unindexed=1 if the table is actually a
|
|
** contentless one.
|
|
*/
|
|
if **(**int32)(__ccgo_up(bp)) == SQLITE_OK && (*TFts5Config)(unsafe.Pointer(pRet)).FbContentlessUnindexed != 0 && (*TFts5Config)(unsafe.Pointer(pRet)).FeContent != int32(FTS5_CONTENT_NONE) {
|
|
**(**uintptr)(__ccgo_up(pzErr)) = Xsqlite3_mprintf(tls, __ccgo_ts+38231, 0)
|
|
**(**int32)(__ccgo_up(bp)) = int32(SQLITE_ERROR)
|
|
}
|
|
/* If no zContent option was specified, fill in the default values. */
|
|
if **(**int32)(__ccgo_up(bp)) == SQLITE_OK && (*TFts5Config)(unsafe.Pointer(pRet)).FzContent == uintptr(0) {
|
|
zTail = uintptr(0)
|
|
if (*TFts5Config)(unsafe.Pointer(pRet)).FeContent == FTS5_CONTENT_NORMAL {
|
|
zTail = __ccgo_ts + 37589
|
|
} else {
|
|
if **(**int32)(__ccgo_up(bp + 4)) != 0 && (*TFts5Config)(unsafe.Pointer(pRet)).FbContentlessUnindexed != 0 {
|
|
(*TFts5Config)(unsafe.Pointer(pRet)).FeContent = int32(FTS5_CONTENT_UNINDEXED)
|
|
zTail = __ccgo_ts + 37589
|
|
} else {
|
|
if (*TFts5Config)(unsafe.Pointer(pRet)).FbColumnsize != 0 {
|
|
zTail = __ccgo_ts + 38284
|
|
}
|
|
}
|
|
}
|
|
if zTail != 0 {
|
|
(*TFts5Config)(unsafe.Pointer(pRet)).FzContent = _sqlite3Fts5Mprintf(tls, bp, __ccgo_ts+38292, libc.VaList(bp+32, (*TFts5Config)(unsafe.Pointer(pRet)).FzDb, (*TFts5Config)(unsafe.Pointer(pRet)).FzName, zTail))
|
|
}
|
|
}
|
|
if **(**int32)(__ccgo_up(bp)) == SQLITE_OK && (*TFts5Config)(unsafe.Pointer(pRet)).FzContentRowid == uintptr(0) {
|
|
(*TFts5Config)(unsafe.Pointer(pRet)).FzContentRowid = _sqlite3Fts5Strndup(tls, bp, __ccgo_ts+17965, -int32(1))
|
|
}
|
|
/* Formulate the zContentExprlist text */
|
|
if **(**int32)(__ccgo_up(bp)) == SQLITE_OK {
|
|
**(**int32)(__ccgo_up(bp)) = _fts5ConfigMakeExprlist(tls, pRet)
|
|
}
|
|
if **(**int32)(__ccgo_up(bp)) != SQLITE_OK {
|
|
_sqlite3Fts5ConfigFree(tls, pRet)
|
|
**(**uintptr)(__ccgo_up(ppOut)) = uintptr(0)
|
|
}
|
|
return **(**int32)(__ccgo_up(bp))
|
|
}
|
|
|
|
// 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+32 */ int32
|
|
var _ /* iPos at bp+24 */ Ti64
|
|
var _ /* n at bp+16 */ int32
|
|
var _ /* pIter at bp+12 */ 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 + 28 + uintptr(iLvl)*12))).FnSeg) {
|
|
break
|
|
}
|
|
pSeg = (*(*TFts5StructureLevel)(unsafe.Pointer(pStruct + 28 + uintptr(iLvl)*12))).FaSeg + uintptr(iSeg)*48
|
|
_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+12)
|
|
for {
|
|
if !(_fts5MultiIterEof(tls, p, **(**uintptr)(__ccgo_up(bp + 12))) == 0) {
|
|
break
|
|
} /* Size of term in bytes */
|
|
**(**Ti64)(__ccgo_up(bp + 24)) = 0 /* Position read from poslist */
|
|
**(**int32)(__ccgo_up(bp + 32)) = 0 /* Offset within poslist */
|
|
iRowid = _fts5MultiIterRowid(tls, **(**uintptr)(__ccgo_up(bp + 12)))
|
|
z = _fts5MultiIterTerm(tls, **(**uintptr)(__ccgo_up(bp + 12)), bp+16)
|
|
/* 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 + 12))) {
|
|
cksum2 = cksum2 ^ _sqlite3Fts5IndexEntryCksum(tls, iRowid, 0, 0, -int32(1), z, **(**int32)(__ccgo_up(bp + 16)))
|
|
}
|
|
} else {
|
|
(**(**TFts5Buffer)(__ccgo_up(bp))).Fn = 0
|
|
_fts5SegiterPoslist(tls, p, **(**uintptr)(__ccgo_up(bp + 12))+72+uintptr((**(**TFts5CResult)(__ccgo_up((*TFts5Iter)(unsafe.Pointer(**(**uintptr)(__ccgo_up(bp + 12)))).FaFirst + 1*4))).FiFirst)*96, uintptr(0), bp)
|
|
_sqlite3Fts5BufferAppendBlob(tls, p+40, bp, uint32(4), __ccgo_ts+39670)
|
|
for 0 == _sqlite3Fts5PoslistNext64(tls, (**(**TFts5Buffer)(__ccgo_up(bp))).Fp, (**(**TFts5Buffer)(__ccgo_up(bp))).Fn, bp+32, bp+24) {
|
|
iCol = int32(**(**Ti64)(__ccgo_up(bp + 24)) >> libc.Int32FromInt32(32) & libc.Int64FromInt32(0x7FFFFFFF))
|
|
iTokOff = int32(**(**Ti64)(__ccgo_up(bp + 24)) & libc.Int64FromInt32(0x7FFFFFFF))
|
|
cksum2 = cksum2 ^ _sqlite3Fts5IndexEntryCksum(tls, iRowid, iCol, iTokOff, -int32(1), z, **(**int32)(__ccgo_up(bp + 16)))
|
|
}
|
|
}
|
|
goto _3
|
|
_3:
|
|
;
|
|
_fts5MultiIterNext(tls, p, **(**uintptr)(__ccgo_up(bp + 12)), 0, 0)
|
|
}
|
|
_fts5MultiIterFree(tls, **(**uintptr)(__ccgo_up(bp + 12)))
|
|
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+39675, libc.VaList(bp+48, (*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(100))
|
|
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+39495, 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+27406, __ccgo_ts+39503, 0, pzErr)
|
|
if **(**int32)(__ccgo_up(bp)) == SQLITE_OK {
|
|
**(**int32)(__ccgo_up(bp)) = _sqlite3Fts5CreateTable(tls, pConfig, __ccgo_ts+13046, __ccgo_ts+39538, 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][40]Tu8
|
|
FsFts TFts5Structure
|
|
F__ccgo_pad2 [12]byte
|
|
}
|
|
_ = pTmp
|
|
_fts5StructureInvalidate(tls, p)
|
|
_fts5IndexDiscardData(tls, p)
|
|
pTmp = bp
|
|
libc.Xmemset(tls, bp, 0, uint32(40))
|
|
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+1702, 0)
|
|
_fts5StructureWrite(tls, p, pTmp)
|
|
return _fts5IndexReturn(tls, p)
|
|
}
|
|
|
|
// 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 + 12)))).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.Int64FromUint32(uint32(libc.UintptrFromInt32(0)+36) + libc.Uint32FromInt32(nChild)*libc.Uint32FromInt64(4))
|
|
pRet = _sqlite3Fts5MallocZero(tls, pParse+8, 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 + 12 + uintptr(iPhrase)*4)))).FpNode = pRet
|
|
if (*TFts5ExprPhrase)(unsafe.Pointer(*(*uintptr)(unsafe.Pointer(pNear + 12 + uintptr(iPhrase)*4)))).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 + 12))
|
|
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 + 20))).FbFirst != 0 {
|
|
if (*TFts5ExprNearset)(unsafe.Pointer(pNear)).FnPhrase == int32(1) {
|
|
v2 = __ccgo_ts + 38690
|
|
} else {
|
|
v2 = __ccgo_ts + 38603
|
|
}
|
|
_sqlite3Fts5ParseError(tls, pParse, __ccgo_ts+38697, 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+38747, 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
|
|
//
|
|
// /*
|
|
// ** 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" */
|
|
/*
|
|
* ====================================================
|
|
* 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
|
|
//
|
|
// /*
|
|
// ** 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.Int64FromUint32(uint32(76) + libc.Uint32FromInt32((*TFts5Config)(unsafe.Pointer(pConfig)).FnCol)*uint32(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.Uint32FromInt64(nByte))
|
|
(*TFts5Storage)(unsafe.Pointer(p)).FaTotalSize = p + 1*76
|
|
(*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+41560, 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+41583, 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+41589, 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+37589, 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 + 41595
|
|
if (*TFts5Config)(unsafe.Pointer(pConfig)).FbContentlessDelete != 0 {
|
|
zCols = __ccgo_ts + 41627
|
|
}
|
|
rc = _sqlite3Fts5CreateTable(tls, pConfig, __ccgo_ts+38284, zCols, 0, pzErr)
|
|
}
|
|
if rc == SQLITE_OK {
|
|
rc = _sqlite3Fts5CreateTable(tls, pConfig, __ccgo_ts+40598, __ccgo_ts+41675, int32(1), pzErr)
|
|
}
|
|
if rc == SQLITE_OK {
|
|
rc = _sqlite3Fts5StorageConfigValue(tls, p, __ccgo_ts+38466, uintptr(0), int32(FTS5_CURRENT_VERSION))
|
|
}
|
|
}
|
|
if rc != 0 {
|
|
_sqlite3Fts5StorageClose(tls, p)
|
|
**(**uintptr)(__ccgo_up(pp)) = uintptr(0)
|
|
}
|
|
return rc
|
|
}
|
|
|
|
// C documentation
|
|
//
|
|
// /*
|
|
// ** This is the callback routine for the code that initializes the
|
|
// ** database. See sqlite3Init() below for additional information.
|
|
// ** This routine is also called from the OP_ParseSchema opcode of the VDBE.
|
|
// **
|
|
// ** Each callback contains the following information:
|
|
// **
|
|
// ** argv[0] = type of object: "table", "index", "trigger", or "view".
|
|
// ** argv[1] = name of thing being created
|
|
// ** argv[2] = associated table if an index or trigger
|
|
// ** argv[3] = root page number for table or index. 0 for trigger or view.
|
|
// ** argv[4] = SQL text for the CREATE statement.
|
|
// **
|
|
// */
|
|
func _sqlite3InitCallback(tls *libc.TLS, pInit uintptr, argc int32, argv uintptr, NotUsed uintptr) (r int32) {
|
|
bp := tls.Alloc(16)
|
|
defer tls.Free(16)
|
|
var db, pData, pIndex uintptr
|
|
var iDb, rc int32
|
|
var saved_iDb Tu8
|
|
var _ /* pStmt at bp+0 */ uintptr
|
|
_, _, _, _, _, _ = db, iDb, pData, pIndex, rc, saved_iDb
|
|
pData = pInit
|
|
db = (*TInitData)(unsafe.Pointer(pData)).Fdb
|
|
iDb = (*TInitData)(unsafe.Pointer(pData)).FiDb
|
|
_ = NotUsed
|
|
_ = argc
|
|
**(**Tu32)(__ccgo_up(db + 24)) |= uint32(DBFLAG_EncodingFixed)
|
|
if argv == uintptr(0) {
|
|
return 0
|
|
} /* Might happen if EMPTY_RESULT_CALLBACKS are on */
|
|
(*TInitData)(unsafe.Pointer(pData)).FnInitRow = (*TInitData)(unsafe.Pointer(pData)).FnInitRow + 1
|
|
if (*Tsqlite3)(unsafe.Pointer(db)).FmallocFailed != 0 {
|
|
_corruptSchema(tls, pData, argv, uintptr(0))
|
|
return int32(1)
|
|
}
|
|
if **(**uintptr)(__ccgo_up(argv + 3*4)) == uintptr(0) {
|
|
_corruptSchema(tls, pData, argv, uintptr(0))
|
|
} else {
|
|
if **(**uintptr)(__ccgo_up(argv + 4*4)) != 0 && int32('c') == libc.Int32FromUint8(_sqlite3UpperToLower[libc.Uint8FromInt8(**(**int8)(__ccgo_up(**(**uintptr)(__ccgo_up(argv + 4*4)))))]) && int32('r') == libc.Int32FromUint8(_sqlite3UpperToLower[libc.Uint8FromInt8(**(**int8)(__ccgo_up(**(**uintptr)(__ccgo_up(argv + 4*4)) + 1)))]) {
|
|
saved_iDb = (*Tsqlite3)(unsafe.Pointer(db)).Finit1.FiDb
|
|
/* Return code from sqlite3_prepare() */
|
|
(*Tsqlite3)(unsafe.Pointer(db)).Finit1.FiDb = libc.Uint8FromInt32(iDb)
|
|
if _sqlite3GetUInt32(tls, **(**uintptr)(__ccgo_up(argv + 3*4)), db+172) == 0 || (*Tsqlite3)(unsafe.Pointer(db)).Finit1.FnewTnum > (*TInitData)(unsafe.Pointer(pData)).FmxPage && (*TInitData)(unsafe.Pointer(pData)).FmxPage > uint32(0) {
|
|
if _sqlite3Config.FbExtraSchemaChecks != 0 {
|
|
_corruptSchema(tls, pData, argv, __ccgo_ts+15742)
|
|
}
|
|
}
|
|
libc.SetBitFieldPtr8Uint32(db+172+8, libc.Uint32FromInt32(0), 0, 0x1)
|
|
(*Tsqlite3)(unsafe.Pointer(db)).Finit1.FazInit = argv
|
|
**(**uintptr)(__ccgo_up(bp)) = uintptr(0)
|
|
_sqlite3Prepare(tls, db, **(**uintptr)(__ccgo_up(argv + 4*4)), -int32(1), uint32(0), uintptr(0), bp, uintptr(0))
|
|
rc = (*Tsqlite3)(unsafe.Pointer(db)).FerrCode
|
|
(*Tsqlite3)(unsafe.Pointer(db)).Finit1.FiDb = saved_iDb
|
|
/* assert( saved_iDb==0 || (db->mDbFlags & DBFLAG_Vacuum)!=0 ); */
|
|
if SQLITE_OK != rc {
|
|
if int32(uint32(*(*uint8)(unsafe.Pointer(db + 172 + 8))&0x1>>0)) != 0 {
|
|
} else {
|
|
if rc > (*TInitData)(unsafe.Pointer(pData)).Frc {
|
|
(*TInitData)(unsafe.Pointer(pData)).Frc = rc
|
|
}
|
|
if rc == int32(SQLITE_NOMEM) {
|
|
_sqlite3OomFault(tls, db)
|
|
} else {
|
|
if rc != int32(SQLITE_INTERRUPT) && rc&int32(0xFF) != int32(SQLITE_LOCKED) {
|
|
_corruptSchema(tls, pData, argv, Xsqlite3_errmsg(tls, db))
|
|
}
|
|
}
|
|
}
|
|
}
|
|
(*Tsqlite3)(unsafe.Pointer(db)).Finit1.FazInit = uintptr(unsafe.Pointer(&_sqlite3StdType)) /* Any array of string ptrs will do */
|
|
Xsqlite3_finalize(tls, **(**uintptr)(__ccgo_up(bp)))
|
|
} else {
|
|
if **(**uintptr)(__ccgo_up(argv + 1*4)) == uintptr(0) || **(**uintptr)(__ccgo_up(argv + 4*4)) != uintptr(0) && int32(**(**int8)(__ccgo_up(**(**uintptr)(__ccgo_up(argv + 4*4))))) != 0 {
|
|
_corruptSchema(tls, pData, argv, uintptr(0))
|
|
} else {
|
|
pIndex = _sqlite3FindIndex(tls, db, **(**uintptr)(__ccgo_up(argv + 1*4)), (**(**TDb)(__ccgo_up((*Tsqlite3)(unsafe.Pointer(db)).FaDb + uintptr(iDb)*16))).FzDbSName)
|
|
if pIndex == uintptr(0) {
|
|
_corruptSchema(tls, pData, argv, __ccgo_ts+20092)
|
|
} else {
|
|
if _sqlite3GetUInt32(tls, **(**uintptr)(__ccgo_up(argv + 3*4)), pIndex+44) == 0 || (*TIndex)(unsafe.Pointer(pIndex)).Ftnum < uint32(2) || (*TIndex)(unsafe.Pointer(pIndex)).Ftnum > (*TInitData)(unsafe.Pointer(pData)).FmxPage || _sqlite3IndexHasDuplicateRootPage(tls, pIndex) != 0 {
|
|
if _sqlite3Config.FbExtraSchemaChecks != 0 {
|
|
_corruptSchema(tls, pData, argv, __ccgo_ts+15742)
|
|
}
|
|
}
|
|
}
|
|
}
|
|
}
|
|
}
|
|
return 0
|
|
}
|
|
|
|
// 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(96)
|
|
defer tls.Free(96)
|
|
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+44 */ TInitData
|
|
var _ /* meta at bp+24 */ [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 + 9379
|
|
if libc.Bool(!(libc.Int32FromInt32(OMIT_TEMPDB) != 0)) && iDb == int32(1) {
|
|
v2 = __ccgo_ts + 6766
|
|
} else {
|
|
v2 = __ccgo_ts + 6286
|
|
}
|
|
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 + 20105
|
|
(**(**[6]uintptr)(__ccgo_up(bp)))[int32(4)] = __ccgo_ts + 20107
|
|
(**(**[6]uintptr)(__ccgo_up(bp)))[int32(5)] = uintptr(0)
|
|
(**(**TInitData)(__ccgo_up(bp + 44))).Fdb = db
|
|
(**(**TInitData)(__ccgo_up(bp + 44))).FiDb = iDb
|
|
(**(**TInitData)(__ccgo_up(bp + 44))).Frc = SQLITE_OK
|
|
(**(**TInitData)(__ccgo_up(bp + 44))).FpzErrMsg = pzErrMsg
|
|
(**(**TInitData)(__ccgo_up(bp + 44))).FmInitFlags = mFlags
|
|
(**(**TInitData)(__ccgo_up(bp + 44))).FnInitRow = uint32(0)
|
|
(**(**TInitData)(__ccgo_up(bp + 44))).FmxPage = uint32(0)
|
|
_sqlite3InitCallback(tls, bp+44, int32(5), bp, uintptr(0))
|
|
**(**Tu32)(__ccgo_up(db + 24)) &= libc.Uint32FromInt32(mask)
|
|
if (**(**TInitData)(__ccgo_up(bp + 44))).Frc != 0 {
|
|
rc = (**(**TInitData)(__ccgo_up(bp + 44))).Frc
|
|
goto error_out
|
|
}
|
|
/* Create a cursor to hold the database open
|
|
*/
|
|
pDb = (*Tsqlite3)(unsafe.Pointer(db)).FaDb + uintptr(iDb)*16
|
|
if (*TDb)(unsafe.Pointer(pDb)).FpBt == uintptr(0) {
|
|
v1 = (**(**TDb)(__ccgo_up((*Tsqlite3)(unsafe.Pointer(db)).FaDb + 1*16))).FpSchema + 78
|
|
*(*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.Int32FromUint32(libc.Uint32FromInt64(20)/libc.Uint32FromInt64(4))) {
|
|
break
|
|
}
|
|
_sqlite3BtreeGetMeta(tls, (*TDb)(unsafe.Pointer(pDb)).FpBt, i+int32(1), bp+24+uintptr(i)*4)
|
|
goto _4
|
|
_4:
|
|
;
|
|
i = i + 1
|
|
}
|
|
if (*Tsqlite3)(unsafe.Pointer(db)).Fflags&uint64(SQLITE_ResetDatabase) != uint64(0) {
|
|
libc.Xmemset(tls, bp+24, 0, uint32(20))
|
|
}
|
|
(*TSchema)(unsafe.Pointer((*TDb)(unsafe.Pointer(pDb)).FpSchema)).Fschema_cookie = (**(**[5]int32)(__ccgo_up(bp + 24)))[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 + 24)))[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 + 24)))[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 + 24)))[libc.Int32FromInt32(BTREE_TEXT_ENCODING)-libc.Int32FromInt32(1)]&int32(3) != libc.Int32FromUint8((*Tsqlite3)(unsafe.Pointer(db)).Fenc) {
|
|
_sqlite3SetString(tls, pzErrMsg, db, __ccgo_ts+13348)
|
|
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 + 24)))[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 + 24)))[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+20179)
|
|
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 + 24)))[libc.Int32FromInt32(BTREE_FILE_FORMAT)-libc.Int32FromInt32(1)] >= int32(4) {
|
|
**(**Tu64)(__ccgo_up(db + 28)) &= ^libc.Uint64FromInt32(SQLITE_LegacyFileFmt)
|
|
}
|
|
/* Read the schema information out of the schema tables
|
|
*/
|
|
(**(**TInitData)(__ccgo_up(bp + 44))).FmxPage = _sqlite3BtreeLastPage(tls, (*TDb)(unsafe.Pointer(pDb)).FpBt)
|
|
zSql = _sqlite3MPrintf(tls, db, __ccgo_ts+20203, libc.VaList(bp+80, (**(**TDb)(__ccgo_up((*Tsqlite3)(unsafe.Pointer(db)).FaDb + uintptr(iDb)*16))).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+44, uintptr(0))
|
|
(*Tsqlite3)(unsafe.Pointer(db)).FxAuth = xAuth
|
|
if rc == SQLITE_OK {
|
|
rc = (**(**TInitData)(__ccgo_up(bp + 44))).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)*16
|
|
} 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)*16))).FpSchema + 78
|
|
*(*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
|
|
//
|
|
// /*
|
|
// ** Attempt to load an SQLite extension library contained in the file
|
|
// ** zFile. The entry point is zProc. zProc may be 0 in which case a
|
|
// ** default entry point name (sqlite3_extension_init) is used. Use
|
|
// ** of the default name is recommended.
|
|
// **
|
|
// ** Return SQLITE_OK on success and SQLITE_ERROR if something goes wrong.
|
|
// **
|
|
// ** If an error occurs and pzErrMsg is not 0, then fill *pzErrMsg with
|
|
// ** error message text. The calling function should free this memory
|
|
// ** by calling sqlite3DbFree(db, ).
|
|
// */
|
|
func _sqlite3LoadExtension(tls *libc.TLS, db uintptr, zFile uintptr, zProc uintptr, pzErrMsg uintptr) (r int32) {
|
|
bp := tls.Alloc(32)
|
|
defer tls.Free(32)
|
|
var aHandle, handle, pVfs, zAltEntry, zAltFile, zEntry, v1 uintptr
|
|
var c, cnt, iEntry, iFile, ii, ncFile, rc, v3, v8 int32
|
|
var nMsg Tu64
|
|
var xInit Tsqlite3_loadext_entry
|
|
var v4 bool
|
|
var _ /* zErrmsg at bp+0 */ uintptr
|
|
_, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _ = aHandle, c, cnt, handle, iEntry, iFile, ii, nMsg, ncFile, pVfs, rc, xInit, zAltEntry, zAltFile, zEntry, v1, v3, v4, v8
|
|
pVfs = (*Tsqlite3)(unsafe.Pointer(db)).FpVfs
|
|
**(**uintptr)(__ccgo_up(bp)) = uintptr(0)
|
|
zAltEntry = uintptr(0)
|
|
nMsg = uint64(libc.Xstrlen(tls, zFile))
|
|
if pzErrMsg != 0 {
|
|
**(**uintptr)(__ccgo_up(pzErrMsg)) = uintptr(0)
|
|
}
|
|
/* Ticket #1863. To avoid a creating security problems for older
|
|
** applications that relink against newer versions of SQLite, the
|
|
** ability to run load_extension is turned off by default. One
|
|
** must call either sqlite3_enable_load_extension(db) or
|
|
** sqlite3_db_config(db, SQLITE_DBCONFIG_ENABLE_LOAD_EXTENSION, 1, 0)
|
|
** to turn on extension loading.
|
|
*/
|
|
if (*Tsqlite3)(unsafe.Pointer(db)).Fflags&uint64(SQLITE_LoadExtension) == uint64(0) {
|
|
if pzErrMsg != 0 {
|
|
**(**uintptr)(__ccgo_up(pzErrMsg)) = Xsqlite3_mprintf(tls, __ccgo_ts+13673, 0)
|
|
}
|
|
return int32(SQLITE_ERROR)
|
|
}
|
|
if zProc != 0 {
|
|
v1 = zProc
|
|
} else {
|
|
v1 = __ccgo_ts + 17589
|
|
}
|
|
zEntry = v1
|
|
/* tag-20210611-1. Some dlopen() implementations will segfault if given
|
|
** an oversize filename. Most filesystems have a pathname limit of 4K,
|
|
** so limit the extension filename length to about twice that.
|
|
** https://sqlite.org/forum/forumpost/08a0d6d9bf
|
|
**
|
|
** Later (2023-03-25): Save an extra 6 bytes for the filename suffix.
|
|
** See https://sqlite.org/forum/forumpost/24083b579d.
|
|
*/
|
|
if nMsg > uint64(FILENAME_MAX) {
|
|
goto extension_not_found
|
|
}
|
|
/* Do not allow sqlite3_load_extension() to link to a copy of the
|
|
** running application, by passing in an empty filename. */
|
|
if nMsg == uint64(0) {
|
|
goto extension_not_found
|
|
}
|
|
handle = _sqlite3OsDlOpen(tls, pVfs, zFile)
|
|
ii = 0
|
|
for {
|
|
if !(ii < libc.Int32FromUint32(libc.Uint32FromInt64(4)/libc.Uint32FromInt64(4)) && handle == uintptr(0)) {
|
|
break
|
|
}
|
|
zAltFile = Xsqlite3_mprintf(tls, __ccgo_ts+13634, libc.VaList(bp+16, zFile, _azEndings[ii]))
|
|
if zAltFile == uintptr(0) {
|
|
return int32(SQLITE_NOMEM)
|
|
}
|
|
if nMsg+uint64(libc.Xstrlen(tls, _azEndings[ii]))+uint64(1) <= uint64(FILENAME_MAX) {
|
|
handle = _sqlite3OsDlOpen(tls, pVfs, zAltFile)
|
|
}
|
|
Xsqlite3_free(tls, zAltFile)
|
|
goto _2
|
|
_2:
|
|
;
|
|
ii = ii + 1
|
|
}
|
|
if handle == uintptr(0) {
|
|
goto extension_not_found
|
|
}
|
|
xInit = _sqlite3OsDlSym(tls, pVfs, handle, zEntry)
|
|
/* If no entry point was specified and the default legacy
|
|
** entry point name "sqlite3_extension_init" was not found, then
|
|
** construct an entry point name "sqlite3_X_init" where the X is
|
|
** replaced by the lowercase value of every ASCII alphabetic
|
|
** character in the filename after the last "/" up to the first ".",
|
|
** and skipping the first three characters if they are "lib".
|
|
** Examples:
|
|
**
|
|
** /usr/local/lib/libExample5.4.3.so ==> sqlite3_example_init
|
|
** C:/lib/mathfuncs.dll ==> sqlite3_mathfuncs_init
|
|
**
|
|
** If that still finds no entry point, repeat a second time but this
|
|
** time include both alphabetic and numeric characters up to the first
|
|
** ".". Example:
|
|
**
|
|
** /usr/local/lib/libExample5.4.3.so ==> sqlite3_example5_init
|
|
*/
|
|
if xInit == uintptr(0) && zProc == uintptr(0) {
|
|
ncFile = _sqlite3Strlen30(tls, zFile)
|
|
cnt = 0
|
|
zAltEntry = Xsqlite3_malloc64(tls, libc.Uint64FromInt32(ncFile+int32(30)))
|
|
if zAltEntry == uintptr(0) {
|
|
_sqlite3OsDlClose(tls, pVfs, handle)
|
|
return int32(SQLITE_NOMEM)
|
|
}
|
|
for {
|
|
libc.Xmemcpy(tls, zAltEntry, __ccgo_ts+17612, uint32(8))
|
|
iFile = ncFile - int32(1)
|
|
for {
|
|
if !(iFile >= 0 && !(int32(**(**int8)(__ccgo_up(zFile + uintptr(iFile)))) == libc.Int32FromUint8('/'))) {
|
|
break
|
|
}
|
|
goto _6
|
|
_6:
|
|
;
|
|
iFile = iFile - 1
|
|
}
|
|
iFile = iFile + 1
|
|
if Xsqlite3_strnicmp(tls, zFile+uintptr(iFile), __ccgo_ts+17621, int32(3)) == 0 {
|
|
iFile = iFile + int32(3)
|
|
}
|
|
iEntry = int32(8)
|
|
for {
|
|
v3 = int32(**(**int8)(__ccgo_up(zFile + uintptr(iFile))))
|
|
c = v3
|
|
if !(v3 != 0 && c != int32('.')) {
|
|
break
|
|
}
|
|
if libc.Int32FromUint8(_sqlite3CtypeMap[libc.Uint8FromInt32(c)])&int32(0x02) != 0 || cnt != 0 && libc.Int32FromUint8(_sqlite3CtypeMap[libc.Uint8FromInt32(c)])&int32(0x04) != 0 {
|
|
v8 = iEntry
|
|
iEntry = iEntry + 1
|
|
**(**int8)(__ccgo_up(zAltEntry + uintptr(v8))) = libc.Int8FromUint8(_sqlite3UpperToLower[libc.Uint32FromInt32(c)])
|
|
}
|
|
goto _7
|
|
_7:
|
|
;
|
|
iFile = iFile + 1
|
|
}
|
|
libc.Xmemcpy(tls, zAltEntry+uintptr(iEntry), __ccgo_ts+17625, uint32(6))
|
|
zEntry = zAltEntry
|
|
xInit = _sqlite3OsDlSym(tls, pVfs, handle, zEntry)
|
|
goto _5
|
|
_5:
|
|
;
|
|
if v4 = xInit == uintptr(0); v4 {
|
|
cnt = cnt + 1
|
|
v3 = cnt
|
|
}
|
|
if !(v4 && v3 < int32(2)) {
|
|
break
|
|
}
|
|
}
|
|
}
|
|
if xInit == uintptr(0) {
|
|
if pzErrMsg != 0 {
|
|
nMsg = nMsg + uint64(libc.Xstrlen(tls, zEntry)+uint32(300))
|
|
v1 = Xsqlite3_malloc64(tls, nMsg)
|
|
**(**uintptr)(__ccgo_up(bp)) = v1
|
|
**(**uintptr)(__ccgo_up(pzErrMsg)) = v1
|
|
if **(**uintptr)(__ccgo_up(bp)) != 0 {
|
|
/* zErrmsg would be NULL if not so */
|
|
Xsqlite3_snprintf(tls, libc.Int32FromUint64(nMsg), **(**uintptr)(__ccgo_up(bp)), __ccgo_ts+17631, libc.VaList(bp+16, zEntry, zFile))
|
|
_sqlite3OsDlError(tls, pVfs, libc.Int32FromUint64(nMsg-uint64(1)), **(**uintptr)(__ccgo_up(bp)))
|
|
}
|
|
}
|
|
_sqlite3OsDlClose(tls, pVfs, handle)
|
|
Xsqlite3_free(tls, zAltEntry)
|
|
return int32(SQLITE_ERROR)
|
|
}
|
|
Xsqlite3_free(tls, zAltEntry)
|
|
rc = (*(*func(*libc.TLS, uintptr, uintptr, uintptr) int32)(unsafe.Pointer(&struct{ uintptr }{xInit})))(tls, db, bp, uintptr(unsafe.Pointer(&_sqlite3Apis)))
|
|
if rc != 0 {
|
|
if rc == libc.Int32FromInt32(SQLITE_OK)|libc.Int32FromInt32(1)<<libc.Int32FromInt32(8) {
|
|
return SQLITE_OK
|
|
}
|
|
if pzErrMsg != 0 {
|
|
**(**uintptr)(__ccgo_up(pzErrMsg)) = Xsqlite3_mprintf(tls, __ccgo_ts+17674, libc.VaList(bp+16, **(**uintptr)(__ccgo_up(bp))))
|
|
}
|
|
Xsqlite3_free(tls, **(**uintptr)(__ccgo_up(bp)))
|
|
_sqlite3OsDlClose(tls, pVfs, handle)
|
|
return int32(SQLITE_ERROR)
|
|
}
|
|
/* Append the new shared library handle to the db->aExtension array. */
|
|
aHandle = _sqlite3DbMallocZero(tls, db, uint64(uint32(4)*libc.Uint32FromInt32((*Tsqlite3)(unsafe.Pointer(db)).FnExtension+libc.Int32FromInt32(1))))
|
|
if aHandle == uintptr(0) {
|
|
return int32(SQLITE_NOMEM)
|
|
}
|
|
if (*Tsqlite3)(unsafe.Pointer(db)).FnExtension > 0 {
|
|
libc.Xmemcpy(tls, aHandle, (*Tsqlite3)(unsafe.Pointer(db)).FaExtension, uint32(4)*libc.Uint32FromInt32((*Tsqlite3)(unsafe.Pointer(db)).FnExtension))
|
|
}
|
|
_sqlite3DbFree(tls, db, (*Tsqlite3)(unsafe.Pointer(db)).FaExtension)
|
|
(*Tsqlite3)(unsafe.Pointer(db)).FaExtension = aHandle
|
|
v1 = db + 208
|
|
v3 = *(*int32)(unsafe.Pointer(v1))
|
|
*(*int32)(unsafe.Pointer(v1)) = *(*int32)(unsafe.Pointer(v1)) + 1
|
|
**(**uintptr)(__ccgo_up((*Tsqlite3)(unsafe.Pointer(db)).FaExtension + uintptr(v3)*4)) = handle
|
|
return SQLITE_OK
|
|
goto extension_not_found
|
|
extension_not_found:
|
|
;
|
|
if pzErrMsg != 0 {
|
|
nMsg = nMsg + uint64(300)
|
|
v1 = Xsqlite3_malloc64(tls, nMsg)
|
|
**(**uintptr)(__ccgo_up(bp)) = v1
|
|
**(**uintptr)(__ccgo_up(pzErrMsg)) = v1
|
|
if **(**uintptr)(__ccgo_up(bp)) != 0 {
|
|
/* zErrmsg would be NULL if not so */
|
|
Xsqlite3_snprintf(tls, libc.Int32FromUint64(nMsg), **(**uintptr)(__ccgo_up(bp)), __ccgo_ts+17706, libc.VaList(bp+16, int32(FILENAME_MAX), zFile))
|
|
_sqlite3OsDlError(tls, pVfs, libc.Int32FromUint64(nMsg-uint64(1)), **(**uintptr)(__ccgo_up(bp)))
|
|
}
|
|
}
|
|
return int32(SQLITE_ERROR)
|
|
}
|
|
|
|
// 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+400, zName)
|
|
if pMod == uintptr(0) && Xsqlite3_strnicmp(tls, zName, __ccgo_ts+13688, int32(7)) == 0 {
|
|
pMod = _sqlite3PragmaVtabRegister(tls, db, zName)
|
|
}
|
|
if pMod == uintptr(0) && Xsqlite3_strnicmp(tls, zName, __ccgo_ts+13696, 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+28, 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 + 13701
|
|
} else {
|
|
v1 = __ccgo_ts + 13714
|
|
}
|
|
zMsg = v1
|
|
if zDbase != 0 {
|
|
_sqlite3ErrorMsg(tls, pParse, __ccgo_ts+7022, libc.VaList(bp+8, zMsg, zDbase, zName))
|
|
} else {
|
|
_sqlite3ErrorMsg(tls, pParse, __ccgo_ts+7093, libc.VaList(bp+8, zMsg, zName))
|
|
}
|
|
} else {
|
|
}
|
|
return p
|
|
}
|
|
|
|
// 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+308, 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+1672, 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
|
|
//
|
|
// /*
|
|
// ** Allocate and initialize a new Pager object and put a pointer to it
|
|
// ** in *ppPager. The pager should eventually be freed by passing it
|
|
// ** to sqlite3PagerClose().
|
|
// **
|
|
// ** The zFilename argument is the path to the database file to open.
|
|
// ** If zFilename is NULL then a randomly-named temporary file is created
|
|
// ** and used as the file to be cached. Temporary files are be deleted
|
|
// ** automatically when they are closed. If zFilename is ":memory:" then
|
|
// ** all information is held in cache. It is never written to disk.
|
|
// ** This can be used to implement an in-memory database.
|
|
// **
|
|
// ** The nExtra parameter specifies the number of bytes of space allocated
|
|
// ** along with each page reference. This space is available to the user
|
|
// ** via the sqlite3PagerGetExtra() API. When a new page is allocated, the
|
|
// ** first 8 bytes of this space are zeroed but the remainder is uninitialized.
|
|
// ** (The extra space is used by btree as the MemPage object.)
|
|
// **
|
|
// ** The flags argument is used to specify properties that affect the
|
|
// ** operation of the pager. It should be passed some bitwise combination
|
|
// ** of the PAGER_* flags.
|
|
// **
|
|
// ** The vfsFlags parameter is a bitmask to pass to the flags parameter
|
|
// ** of the xOpen() method of the supplied VFS when opening files.
|
|
// **
|
|
// ** If the pager object is allocated and the specified file opened
|
|
// ** successfully, SQLITE_OK is returned and *ppPager set to point to
|
|
// ** the new pager object. If an error occurs, *ppPager is set to NULL
|
|
// ** and error code returned. This function may return SQLITE_NOMEM
|
|
// ** (sqlite3Malloc() is used to allocate memory), SQLITE_CANTOPEN or
|
|
// ** various SQLITE_IO_XXX errors.
|
|
// */
|
|
func _sqlite3PagerOpen(tls *libc.TLS, pVfs uintptr, ppPager uintptr, zFilename uintptr, nExtra int32, flags int32, vfsFlags int32, __ccgo_fp_xReinit uintptr) (r int32) {
|
|
bp := tls.Alloc(16)
|
|
defer tls.Free(16)
|
|
var iDc, journalFileSize, memDb, memJM, nPathname, nUriByte, pcacheSize, rc, readOnly, tempFile, useJournal, v4 int32
|
|
var pPtr, z, zPathname, zUri, v1 uintptr
|
|
var _ /* fout at bp+8 */ int32
|
|
var _ /* pPager at bp+0 */ uintptr
|
|
var _ /* szPageDflt at bp+4 */ Tu32
|
|
_, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _ = iDc, journalFileSize, memDb, memJM, nPathname, nUriByte, pPtr, pcacheSize, rc, readOnly, tempFile, useJournal, z, zPathname, zUri, v1, v4
|
|
**(**uintptr)(__ccgo_up(bp)) = uintptr(0) /* Pager object to allocate and return */
|
|
rc = SQLITE_OK /* Return code */
|
|
tempFile = 0 /* True for temp files (incl. in-memory files) */
|
|
memDb = 0 /* True if this is an in-memory file */
|
|
memJM = 0 /* Memory journal mode */
|
|
readOnly = 0 /* Bytes to allocate for each journal fd */
|
|
zPathname = uintptr(0) /* Full path to database file */
|
|
nPathname = 0 /* Number of bytes in zPathname */
|
|
useJournal = libc.BoolInt32(flags&int32(PAGER_OMIT_JOURNAL) == 0) /* False to omit journal */
|
|
pcacheSize = _sqlite3PcacheSize(tls) /* Bytes to allocate for PCache */
|
|
**(**Tu32)(__ccgo_up(bp + 4)) = uint32(SQLITE_DEFAULT_PAGE_SIZE) /* Default page size */
|
|
zUri = uintptr(0) /* URI args to copy */
|
|
nUriByte = int32(1) /* Number of bytes of URI args at *zUri */
|
|
/* Figure out how much space is required for each journal file-handle
|
|
** (there are two of them, the main journal and the sub-journal). */
|
|
journalFileSize = (_sqlite3JournalSize(tls, pVfs) + int32(7)) & ^libc.Int32FromInt32(7)
|
|
/* Set the output variable to NULL in case an error occurs. */
|
|
**(**uintptr)(__ccgo_up(ppPager)) = uintptr(0)
|
|
if flags&int32(PAGER_MEMORY) != 0 {
|
|
memDb = int32(1)
|
|
if zFilename != 0 && **(**int8)(__ccgo_up(zFilename)) != 0 {
|
|
zPathname = _sqlite3DbStrDup(tls, uintptr(0), zFilename)
|
|
if zPathname == uintptr(0) {
|
|
return int32(SQLITE_NOMEM)
|
|
}
|
|
nPathname = _sqlite3Strlen30(tls, zPathname)
|
|
zFilename = uintptr(0)
|
|
}
|
|
}
|
|
/* Compute and store the full pathname in an allocated buffer pointed
|
|
** to by zPathname, length nPathname. Or, if this is a temporary file,
|
|
** leave both nPathname and zPathname set to 0.
|
|
*/
|
|
if zFilename != 0 && **(**int8)(__ccgo_up(zFilename)) != 0 {
|
|
nPathname = (*Tsqlite3_vfs)(unsafe.Pointer(pVfs)).FmxPathname + int32(1)
|
|
zPathname = _sqlite3DbMallocRaw(tls, uintptr(0), libc.Uint64FromInt64(int64(2)*int64(nPathname)))
|
|
if zPathname == uintptr(0) {
|
|
return int32(SQLITE_NOMEM)
|
|
}
|
|
**(**int8)(__ccgo_up(zPathname)) = 0 /* Make sure initialized even if FullPathname() fails */
|
|
rc = _sqlite3OsFullPathname(tls, pVfs, zFilename, nPathname, zPathname)
|
|
if rc != SQLITE_OK {
|
|
if rc == libc.Int32FromInt32(SQLITE_OK)|libc.Int32FromInt32(2)<<libc.Int32FromInt32(8) {
|
|
if vfsFlags&int32(SQLITE_OPEN_NOFOLLOW) != 0 {
|
|
rc = libc.Int32FromInt32(SQLITE_CANTOPEN) | libc.Int32FromInt32(6)<<libc.Int32FromInt32(8)
|
|
} else {
|
|
rc = SQLITE_OK
|
|
}
|
|
}
|
|
}
|
|
nPathname = _sqlite3Strlen30(tls, zPathname)
|
|
v1 = zFilename + uintptr(_sqlite3Strlen30(tls, zFilename)+int32(1))
|
|
zUri = v1
|
|
z = v1
|
|
for **(**int8)(__ccgo_up(z)) != 0 {
|
|
z = z + uintptr(libc.Xstrlen(tls, z)+uint32(1))
|
|
z = z + uintptr(libc.Xstrlen(tls, z)+uint32(1))
|
|
}
|
|
nUriByte = t__predefined_ptrdiff_t(z+1) - int32(zUri)
|
|
if rc == SQLITE_OK && nPathname+int32(8) > (*Tsqlite3_vfs)(unsafe.Pointer(pVfs)).FmxPathname {
|
|
/* This branch is taken when the journal path required by
|
|
** the database being opened will be more than pVfs->mxPathname
|
|
** bytes in length. This means the database cannot be opened,
|
|
** as it will not be possible to open the journal file or even
|
|
** check for a hot-journal before reading.
|
|
*/
|
|
rc = _sqlite3CantopenError(tls, int32(64499))
|
|
}
|
|
if rc != SQLITE_OK {
|
|
_sqlite3DbFree(tls, uintptr(0), zPathname)
|
|
return rc
|
|
}
|
|
}
|
|
/* Allocate memory for the Pager structure, PCache object, the
|
|
** three file descriptors, the database file name and the journal
|
|
** file name. The layout in memory is as follows:
|
|
**
|
|
** Pager object (sizeof(Pager) bytes)
|
|
** PCache object (sqlite3PcacheSize() bytes)
|
|
** Database file handle (pVfs->szOsFile bytes)
|
|
** Sub-journal file handle (journalFileSize bytes)
|
|
** Main journal file handle (journalFileSize bytes)
|
|
** Ptr back to the Pager (sizeof(Pager*) bytes)
|
|
** \0\0\0\0 database prefix (4 bytes)
|
|
** Database file name (nPathname+1 bytes)
|
|
** URI query parameters (nUriByte bytes)
|
|
** Journal filename (nPathname+8+1 bytes)
|
|
** WAL filename (nPathname+4+1 bytes)
|
|
** \0\0\0 terminator (3 bytes)
|
|
**
|
|
** Some 3rd-party software, over which we have no control, depends on
|
|
** the specific order of the filenames and the \0 separators between them
|
|
** so that it can (for example) find the database filename given the WAL
|
|
** filename without using the sqlite3_filename_database() API. This is a
|
|
** misuse of SQLite and a bug in the 3rd-party software, but the 3rd-party
|
|
** software is in widespread use, so we try to avoid changing the filename
|
|
** order and formatting if possible. In particular, the details of the
|
|
** filename format expected by 3rd-party software should be as follows:
|
|
**
|
|
** - Main Database Path
|
|
** - \0
|
|
** - Multiple URI components consisting of:
|
|
** - Key
|
|
** - \0
|
|
** - Value
|
|
** - \0
|
|
** - \0
|
|
** - Journal Path
|
|
** - \0
|
|
** - WAL Path (zWALName)
|
|
** - \0
|
|
**
|
|
** The sqlite3_create_filename() interface and the databaseFilename() utility
|
|
** that is used by sqlite3_filename_database() and kin also depend on the
|
|
** specific formatting and order of the various filenames, so if the format
|
|
** changes here, be sure to change it there as well.
|
|
*/
|
|
pPtr = _sqlite3MallocZero(tls, uint64((libc.Uint32FromInt64(232)+libc.Uint32FromInt32(7))&libc.Uint32FromInt32(^libc.Int32FromInt32(7))+libc.Uint32FromInt32((pcacheSize+libc.Int32FromInt32(7)) & ^libc.Int32FromInt32(7))+libc.Uint32FromInt32(((*Tsqlite3_vfs)(unsafe.Pointer(pVfs)).FszOsFile+libc.Int32FromInt32(7)) & ^libc.Int32FromInt32(7)))+libc.Uint64FromInt32(journalFileSize)*uint64(2)+uint64(__SIZEOF_POINTER__)+uint64(4)+libc.Uint64FromInt32(nPathname)+uint64(1)+libc.Uint64FromInt32(nUriByte)+libc.Uint64FromInt32(nPathname)+uint64(8)+uint64(1)+libc.Uint64FromInt32(nPathname)+uint64(4)+uint64(1)+uint64(3))
|
|
if !(pPtr != 0) {
|
|
_sqlite3DbFree(tls, uintptr(0), zPathname)
|
|
return int32(SQLITE_NOMEM)
|
|
}
|
|
**(**uintptr)(__ccgo_up(bp)) = pPtr
|
|
pPtr = pPtr + uintptr((libc.Uint32FromInt64(232)+libc.Uint32FromInt32(7))&libc.Uint32FromInt32(^libc.Int32FromInt32(7)))
|
|
(*TPager)(unsafe.Pointer(**(**uintptr)(__ccgo_up(bp)))).FpPCache = pPtr
|
|
pPtr = pPtr + uintptr((pcacheSize+libc.Int32FromInt32(7)) & ^libc.Int32FromInt32(7))
|
|
(*TPager)(unsafe.Pointer(**(**uintptr)(__ccgo_up(bp)))).Ffd = pPtr
|
|
pPtr = pPtr + uintptr(((*Tsqlite3_vfs)(unsafe.Pointer(pVfs)).FszOsFile+libc.Int32FromInt32(7)) & ^libc.Int32FromInt32(7))
|
|
(*TPager)(unsafe.Pointer(**(**uintptr)(__ccgo_up(bp)))).Fsjfd = pPtr
|
|
pPtr = pPtr + uintptr(journalFileSize)
|
|
(*TPager)(unsafe.Pointer(**(**uintptr)(__ccgo_up(bp)))).Fjfd = pPtr
|
|
pPtr = pPtr + uintptr(journalFileSize)
|
|
libc.Xmemcpy(tls, pPtr, bp, uint32(__SIZEOF_POINTER__))
|
|
pPtr = pPtr + uintptr(__SIZEOF_POINTER__)
|
|
/* Fill in the Pager.zFilename and pPager.zQueryParam fields */
|
|
pPtr = pPtr + uintptr(4) /* Skip zero prefix */
|
|
(*TPager)(unsafe.Pointer(**(**uintptr)(__ccgo_up(bp)))).FzFilename = pPtr
|
|
if nPathname > 0 {
|
|
libc.Xmemcpy(tls, pPtr, zPathname, libc.Uint32FromInt32(nPathname))
|
|
pPtr = pPtr + uintptr(nPathname+int32(1))
|
|
if zUri != 0 {
|
|
libc.Xmemcpy(tls, pPtr, zUri, libc.Uint32FromInt32(nUriByte))
|
|
pPtr = pPtr + uintptr(nUriByte)
|
|
} else {
|
|
pPtr = pPtr + 1
|
|
}
|
|
}
|
|
/* Fill in Pager.zJournal */
|
|
if nPathname > 0 {
|
|
(*TPager)(unsafe.Pointer(**(**uintptr)(__ccgo_up(bp)))).FzJournal = pPtr
|
|
libc.Xmemcpy(tls, pPtr, zPathname, libc.Uint32FromInt32(nPathname))
|
|
pPtr = pPtr + uintptr(nPathname)
|
|
libc.Xmemcpy(tls, pPtr, __ccgo_ts+4229, uint32(8))
|
|
pPtr = pPtr + uintptr(libc.Int32FromInt32(8)+libc.Int32FromInt32(1))
|
|
} else {
|
|
(*TPager)(unsafe.Pointer(**(**uintptr)(__ccgo_up(bp)))).FzJournal = uintptr(0)
|
|
}
|
|
/* Fill in Pager.zWal */
|
|
if nPathname > 0 {
|
|
(*TPager)(unsafe.Pointer(**(**uintptr)(__ccgo_up(bp)))).FzWal = pPtr
|
|
libc.Xmemcpy(tls, pPtr, zPathname, libc.Uint32FromInt32(nPathname))
|
|
pPtr = pPtr + uintptr(nPathname)
|
|
libc.Xmemcpy(tls, pPtr, __ccgo_ts+4238, uint32(4))
|
|
pPtr = pPtr + uintptr(libc.Int32FromInt32(4)+libc.Int32FromInt32(1))
|
|
} else {
|
|
(*TPager)(unsafe.Pointer(**(**uintptr)(__ccgo_up(bp)))).FzWal = uintptr(0)
|
|
}
|
|
_ = pPtr /* Suppress warning about unused pPtr value */
|
|
if nPathname != 0 {
|
|
_sqlite3DbFree(tls, uintptr(0), zPathname)
|
|
}
|
|
(*TPager)(unsafe.Pointer(**(**uintptr)(__ccgo_up(bp)))).FpVfs = pVfs
|
|
(*TPager)(unsafe.Pointer(**(**uintptr)(__ccgo_up(bp)))).FvfsFlags = libc.Uint32FromInt32(vfsFlags)
|
|
/* Open the pager file.
|
|
*/
|
|
if !(zFilename != 0 && **(**int8)(__ccgo_up(zFilename)) != 0) {
|
|
goto _2
|
|
}
|
|
**(**int32)(__ccgo_up(bp + 8)) = 0 /* VFS flags returned by xOpen() */
|
|
rc = _sqlite3OsOpen(tls, pVfs, (*TPager)(unsafe.Pointer(**(**uintptr)(__ccgo_up(bp)))).FzFilename, (*TPager)(unsafe.Pointer(**(**uintptr)(__ccgo_up(bp)))).Ffd, vfsFlags, bp+8)
|
|
v4 = libc.BoolInt32(**(**int32)(__ccgo_up(bp + 8))&libc.Int32FromInt32(SQLITE_OPEN_MEMORY) != libc.Int32FromInt32(0))
|
|
memJM = v4
|
|
(*TPager)(unsafe.Pointer(**(**uintptr)(__ccgo_up(bp)))).FmemVfs = libc.Uint8FromInt32(v4)
|
|
readOnly = libc.BoolInt32(**(**int32)(__ccgo_up(bp + 8))&int32(SQLITE_OPEN_READONLY) != 0)
|
|
/* If the file was successfully opened for read/write access,
|
|
** choose a default page size in case we have to create the
|
|
** database file. The default page size is the maximum of:
|
|
**
|
|
** + SQLITE_DEFAULT_PAGE_SIZE,
|
|
** + The value returned by sqlite3OsSectorSize()
|
|
** + The largest page size that can be written atomically.
|
|
*/
|
|
if rc == SQLITE_OK {
|
|
iDc = _sqlite3OsDeviceCharacteristics(tls, (*TPager)(unsafe.Pointer(**(**uintptr)(__ccgo_up(bp)))).Ffd)
|
|
if !(readOnly != 0) {
|
|
_setSectorSize(tls, **(**uintptr)(__ccgo_up(bp)))
|
|
if **(**Tu32)(__ccgo_up(bp + 4)) < (*TPager)(unsafe.Pointer(**(**uintptr)(__ccgo_up(bp)))).FsectorSize {
|
|
if (*TPager)(unsafe.Pointer(**(**uintptr)(__ccgo_up(bp)))).FsectorSize > uint32(SQLITE_MAX_DEFAULT_PAGE_SIZE) {
|
|
**(**Tu32)(__ccgo_up(bp + 4)) = uint32(SQLITE_MAX_DEFAULT_PAGE_SIZE)
|
|
} else {
|
|
**(**Tu32)(__ccgo_up(bp + 4)) = (*TPager)(unsafe.Pointer(**(**uintptr)(__ccgo_up(bp)))).FsectorSize
|
|
}
|
|
}
|
|
}
|
|
(*TPager)(unsafe.Pointer(**(**uintptr)(__ccgo_up(bp)))).FnoLock = libc.Uint8FromInt32(Xsqlite3_uri_boolean(tls, (*TPager)(unsafe.Pointer(**(**uintptr)(__ccgo_up(bp)))).FzFilename, __ccgo_ts+4243, 0))
|
|
if iDc&int32(SQLITE_IOCAP_IMMUTABLE) != 0 || Xsqlite3_uri_boolean(tls, (*TPager)(unsafe.Pointer(**(**uintptr)(__ccgo_up(bp)))).FzFilename, __ccgo_ts+4250, 0) != 0 {
|
|
vfsFlags = vfsFlags | int32(SQLITE_OPEN_READONLY)
|
|
goto act_like_temp_file
|
|
}
|
|
}
|
|
goto _3
|
|
_2:
|
|
;
|
|
/* If a temporary file is requested, it is not opened immediately.
|
|
** In this case we accept the default page size and delay actually
|
|
** opening the file until the first call to OsWrite().
|
|
**
|
|
** This branch is also run for an in-memory database. An in-memory
|
|
** database is the same as a temp-file that is never written out to
|
|
** disk and uses an in-memory rollback journal.
|
|
**
|
|
** This branch also runs for files marked as immutable.
|
|
*/
|
|
goto act_like_temp_file
|
|
act_like_temp_file:
|
|
;
|
|
tempFile = int32(1)
|
|
(*TPager)(unsafe.Pointer(**(**uintptr)(__ccgo_up(bp)))).FeState = uint8(PAGER_READER) /* Pretend we already have a lock */
|
|
(*TPager)(unsafe.Pointer(**(**uintptr)(__ccgo_up(bp)))).FeLock = uint8(EXCLUSIVE_LOCK) /* Pretend we are in EXCLUSIVE mode */
|
|
(*TPager)(unsafe.Pointer(**(**uintptr)(__ccgo_up(bp)))).FnoLock = uint8(1) /* Do no locking */
|
|
readOnly = vfsFlags & int32(SQLITE_OPEN_READONLY)
|
|
_3:
|
|
;
|
|
/* The following call to PagerSetPagesize() serves to set the value of
|
|
** Pager.pageSize and to allocate the Pager.pTmpSpace buffer.
|
|
*/
|
|
if rc == SQLITE_OK {
|
|
rc = _sqlite3PagerSetPagesize(tls, **(**uintptr)(__ccgo_up(bp)), bp+4, -int32(1))
|
|
}
|
|
/* Initialize the PCache object. */
|
|
if rc == SQLITE_OK {
|
|
nExtra = (nExtra + int32(7)) & ^libc.Int32FromInt32(7)
|
|
if !(memDb != 0) {
|
|
v1 = __ccgo_fp(_pagerStress)
|
|
} else {
|
|
v1 = uintptr(0)
|
|
}
|
|
rc = _sqlite3PcacheOpen(tls, libc.Int32FromUint32(**(**Tu32)(__ccgo_up(bp + 4))), nExtra, libc.BoolInt32(!(memDb != 0)), v1, **(**uintptr)(__ccgo_up(bp)), (*TPager)(unsafe.Pointer(**(**uintptr)(__ccgo_up(bp)))).FpPCache)
|
|
}
|
|
/* If an error occurred above, free the Pager structure and close the file.
|
|
*/
|
|
if rc != SQLITE_OK {
|
|
_sqlite3OsClose(tls, (*TPager)(unsafe.Pointer(**(**uintptr)(__ccgo_up(bp)))).Ffd)
|
|
_sqlite3PageFree(tls, (*TPager)(unsafe.Pointer(**(**uintptr)(__ccgo_up(bp)))).FpTmpSpace)
|
|
Xsqlite3_free(tls, **(**uintptr)(__ccgo_up(bp)))
|
|
return rc
|
|
}
|
|
(*TPager)(unsafe.Pointer(**(**uintptr)(__ccgo_up(bp)))).FuseJournal = libc.Uint8FromInt32(useJournal)
|
|
/* pPager->stmtOpen = 0; */
|
|
/* pPager->stmtInUse = 0; */
|
|
/* pPager->nRef = 0; */
|
|
/* pPager->stmtSize = 0; */
|
|
/* pPager->stmtJSize = 0; */
|
|
/* pPager->nPage = 0; */
|
|
(*TPager)(unsafe.Pointer(**(**uintptr)(__ccgo_up(bp)))).FmxPgno = uint32(SQLITE_MAX_PAGE_COUNT)
|
|
/* pPager->state = PAGER_UNLOCK; */
|
|
/* pPager->errMask = 0; */
|
|
(*TPager)(unsafe.Pointer(**(**uintptr)(__ccgo_up(bp)))).FtempFile = libc.Uint8FromInt32(tempFile)
|
|
(*TPager)(unsafe.Pointer(**(**uintptr)(__ccgo_up(bp)))).FexclusiveMode = libc.Uint8FromInt32(tempFile)
|
|
(*TPager)(unsafe.Pointer(**(**uintptr)(__ccgo_up(bp)))).FchangeCountDone = (*TPager)(unsafe.Pointer(**(**uintptr)(__ccgo_up(bp)))).FtempFile
|
|
(*TPager)(unsafe.Pointer(**(**uintptr)(__ccgo_up(bp)))).FmemDb = libc.Uint8FromInt32(memDb)
|
|
(*TPager)(unsafe.Pointer(**(**uintptr)(__ccgo_up(bp)))).FreadOnly = libc.Uint8FromInt32(readOnly)
|
|
_sqlite3PagerSetFlags(tls, **(**uintptr)(__ccgo_up(bp)), libc.Uint32FromInt32(libc.Int32FromInt32(SQLITE_DEFAULT_SYNCHRONOUS)+libc.Int32FromInt32(1)|libc.Int32FromInt32(PAGER_CACHESPILL)))
|
|
/* pPager->pFirst = 0; */
|
|
/* pPager->pFirstSynced = 0; */
|
|
/* pPager->pLast = 0; */
|
|
(*TPager)(unsafe.Pointer(**(**uintptr)(__ccgo_up(bp)))).FnExtra = libc.Uint16FromInt32(nExtra)
|
|
(*TPager)(unsafe.Pointer(**(**uintptr)(__ccgo_up(bp)))).FjournalSizeLimit = int64(-int32(1))
|
|
_setSectorSize(tls, **(**uintptr)(__ccgo_up(bp)))
|
|
if !(useJournal != 0) {
|
|
(*TPager)(unsafe.Pointer(**(**uintptr)(__ccgo_up(bp)))).FjournalMode = uint8(PAGER_JOURNALMODE_OFF)
|
|
} else {
|
|
if memDb != 0 || memJM != 0 {
|
|
(*TPager)(unsafe.Pointer(**(**uintptr)(__ccgo_up(bp)))).FjournalMode = uint8(PAGER_JOURNALMODE_MEMORY)
|
|
}
|
|
}
|
|
/* pPager->xBusyHandler = 0; */
|
|
/* pPager->pBusyHandlerArg = 0; */
|
|
(*TPager)(unsafe.Pointer(**(**uintptr)(__ccgo_up(bp)))).FxReiniter = __ccgo_fp_xReinit
|
|
_setGetterMethod(tls, **(**uintptr)(__ccgo_up(bp)))
|
|
/* memset(pPager->aHash, 0, sizeof(pPager->aHash)); */
|
|
/* pPager->szMmap = SQLITE_DEFAULT_MMAP_SIZE // will be set by btree.c */
|
|
**(**uintptr)(__ccgo_up(ppPager)) = **(**uintptr)(__ccgo_up(bp))
|
|
return SQLITE_OK
|
|
}
|
|
|
|
// C documentation
|
|
//
|
|
// /*
|
|
// ** This function is used to parse both URIs and non-URI filenames passed by the
|
|
// ** user to API functions sqlite3_open() or sqlite3_open_v2(), and for database
|
|
// ** URIs specified as part of ATTACH statements.
|
|
// **
|
|
// ** The first argument to this function is the name of the VFS to use (or
|
|
// ** a NULL to signify the default VFS) if the URI does not contain a "vfs=xxx"
|
|
// ** query parameter. The second argument contains the URI (or non-URI filename)
|
|
// ** itself. When this function is called the *pFlags variable should contain
|
|
// ** the default flags to open the database handle with. The value stored in
|
|
// ** *pFlags may be updated before returning if the URI filename contains
|
|
// ** "cache=xxx" or "mode=xxx" query parameters.
|
|
// **
|
|
// ** If successful, SQLITE_OK is returned. In this case *ppVfs is set to point to
|
|
// ** the VFS that should be used to open the database file. *pzFile is set to
|
|
// ** point to a buffer containing the name of the file to open. The value
|
|
// ** stored in *pzFile is a database name acceptable to sqlite3_uri_parameter()
|
|
// ** and is in the same format as names created using sqlite3_create_filename().
|
|
// ** The caller must invoke sqlite3_free_filename() (not sqlite3_free()!) on
|
|
// ** the value returned in *pzFile to avoid a memory leak.
|
|
// **
|
|
// ** If an error occurs, then an SQLite error code is returned and *pzErrMsg
|
|
// ** may be set to point to a buffer containing an English language error
|
|
// ** message. It is the responsibility of the caller to eventually release
|
|
// ** this buffer by calling sqlite3_free().
|
|
// */
|
|
func _sqlite3ParseUri(tls *libc.TLS, zDefaultVfs uintptr, zUri uintptr, pFlags uintptr, ppVfs uintptr, pzFile uintptr, pzErrMsg uintptr) (r int32) {
|
|
bp := tls.Alloc(32)
|
|
defer tls.Free(32)
|
|
var aMode, z, zFile, zModeType, zOpt, zVal, zVfs uintptr
|
|
var c, v2 int8
|
|
var eState, i, limit, mask, mode, octet, rc int32
|
|
var flags uint32
|
|
var iIn, iOut, nOpt, nUri, nVal, v3, v4 Ti64
|
|
var nByte Tu64
|
|
_, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _ = aMode, c, eState, flags, i, iIn, iOut, limit, mask, mode, nByte, nOpt, nUri, nVal, octet, rc, z, zFile, zModeType, zOpt, zVal, zVfs, v2, v3, v4
|
|
rc = SQLITE_OK
|
|
flags = **(**uint32)(__ccgo_up(pFlags))
|
|
zVfs = zDefaultVfs
|
|
nUri = libc.Int64FromUint32(libc.Xstrlen(tls, zUri))
|
|
if (flags&uint32(SQLITE_OPEN_URI) != 0 || libc.AtomicLoadNUint8(uintptr(unsafe.Pointer(&_sqlite3Config))+6, libc.Int32FromInt32(__ATOMIC_RELAXED)) != 0) && nUri >= int64(5) && libc.Xmemcmp(tls, zUri, __ccgo_ts+26116, uint32(5)) == 0 { /* Input character index */
|
|
iOut = 0 /* Output character index */
|
|
nByte = libc.Uint64FromInt64(nUri + int64(8)) /* Bytes of space to allocate */
|
|
/* Make sure the SQLITE_OPEN_URI flag is set to indicate to the VFS xOpen
|
|
** method that there may be extra parameters following the file-name. */
|
|
flags = flags | uint32(SQLITE_OPEN_URI)
|
|
iIn = 0
|
|
for {
|
|
if !(iIn < nUri) {
|
|
break
|
|
}
|
|
nByte = nByte + libc.BoolUint64(int32(**(**int8)(__ccgo_up(zUri + uintptr(iIn)))) == libc.Int32FromUint8('&'))
|
|
goto _1
|
|
_1:
|
|
;
|
|
iIn = iIn + 1
|
|
}
|
|
zFile = Xsqlite3_malloc64(tls, nByte)
|
|
if !(zFile != 0) {
|
|
return int32(SQLITE_NOMEM)
|
|
}
|
|
libc.Xmemset(tls, zFile, 0, uint32(4)) /* 4-byte of 0x00 is the start of DB name marker */
|
|
zFile = zFile + uintptr(4)
|
|
iIn = int64(5)
|
|
/* Discard the scheme and authority segments of the URI. */
|
|
if int32(**(**int8)(__ccgo_up(zUri + 5))) == int32('/') && int32(**(**int8)(__ccgo_up(zUri + 6))) == int32('/') {
|
|
iIn = int64(7)
|
|
for **(**int8)(__ccgo_up(zUri + uintptr(iIn))) != 0 && int32(**(**int8)(__ccgo_up(zUri + uintptr(iIn)))) != int32('/') {
|
|
iIn = iIn + 1
|
|
}
|
|
if iIn != int64(7) && (iIn != int64(16) || libc.Xmemcmp(tls, __ccgo_ts+26122, zUri+7, uint32(9)) != 0) {
|
|
**(**uintptr)(__ccgo_up(pzErrMsg)) = Xsqlite3_mprintf(tls, __ccgo_ts+26132, libc.VaList(bp+8, int32(iIn-libc.Int64FromInt32(7)), zUri+7))
|
|
rc = int32(SQLITE_ERROR)
|
|
goto parse_uri_out
|
|
}
|
|
}
|
|
/* Copy the filename and any query parameters into the zFile buffer.
|
|
** Decode %HH escape codes along the way.
|
|
**
|
|
** Within this loop, variable eState may be set to 0, 1 or 2, depending
|
|
** on the parsing context. As follows:
|
|
**
|
|
** 0: Parsing file-name.
|
|
** 1: Parsing name section of a name=value query parameter.
|
|
** 2: Parsing value section of a name=value query parameter.
|
|
*/
|
|
eState = 0
|
|
for {
|
|
v2 = **(**int8)(__ccgo_up(zUri + uintptr(iIn)))
|
|
c = v2
|
|
if !(int32(v2) != 0 && int32(c) != int32('#')) {
|
|
break
|
|
}
|
|
iIn = iIn + 1
|
|
if int32(c) == int32('%') && libc.Int32FromUint8(_sqlite3CtypeMap[libc.Uint8FromInt8(**(**int8)(__ccgo_up(zUri + uintptr(iIn))))])&int32(0x08) != 0 && libc.Int32FromUint8(_sqlite3CtypeMap[libc.Uint8FromInt8(**(**int8)(__ccgo_up(zUri + uintptr(iIn+int64(1)))))])&int32(0x08) != 0 {
|
|
v3 = iIn
|
|
iIn = iIn + 1
|
|
octet = libc.Int32FromUint8(_sqlite3HexToInt(tls, int32(**(**int8)(__ccgo_up(zUri + uintptr(v3)))))) << int32(4)
|
|
v4 = iIn
|
|
iIn = iIn + 1
|
|
octet = octet + libc.Int32FromUint8(_sqlite3HexToInt(tls, int32(**(**int8)(__ccgo_up(zUri + uintptr(v4))))))
|
|
if octet == 0 {
|
|
/* This branch is taken when "%00" appears within the URI. In this
|
|
** case we ignore all text in the remainder of the path, name or
|
|
** value currently being parsed. So ignore the current character
|
|
** and skip to the next "?", "=" or "&", as appropriate. */
|
|
for {
|
|
v2 = **(**int8)(__ccgo_up(zUri + uintptr(iIn)))
|
|
c = v2
|
|
if !(int32(v2) != 0 && int32(c) != int32('#') && (eState != 0 || int32(c) != int32('?')) && (eState != int32(1) || int32(c) != int32('=') && int32(c) != int32('&')) && (eState != int32(2) || int32(c) != int32('&'))) {
|
|
break
|
|
}
|
|
iIn = iIn + 1
|
|
}
|
|
continue
|
|
}
|
|
c = int8(octet)
|
|
} else {
|
|
if eState == int32(1) && (int32(c) == int32('&') || int32(c) == int32('=')) {
|
|
if int32(**(**int8)(__ccgo_up(zFile + uintptr(iOut-int64(1))))) == 0 {
|
|
/* An empty option name. Ignore this option altogether. */
|
|
for **(**int8)(__ccgo_up(zUri + uintptr(iIn))) != 0 && int32(**(**int8)(__ccgo_up(zUri + uintptr(iIn)))) != int32('#') && int32(**(**int8)(__ccgo_up(zUri + uintptr(iIn-int64(1))))) != int32('&') {
|
|
iIn = iIn + 1
|
|
}
|
|
continue
|
|
}
|
|
if int32(c) == int32('&') {
|
|
v3 = iOut
|
|
iOut = iOut + 1
|
|
**(**int8)(__ccgo_up(zFile + uintptr(v3))) = int8('\000')
|
|
} else {
|
|
eState = int32(2)
|
|
}
|
|
c = 0
|
|
} else {
|
|
if eState == 0 && int32(c) == int32('?') || eState == int32(2) && int32(c) == int32('&') {
|
|
c = 0
|
|
eState = int32(1)
|
|
}
|
|
}
|
|
}
|
|
v3 = iOut
|
|
iOut = iOut + 1
|
|
**(**int8)(__ccgo_up(zFile + uintptr(v3))) = c
|
|
}
|
|
if eState == int32(1) {
|
|
v3 = iOut
|
|
iOut = iOut + 1
|
|
**(**int8)(__ccgo_up(zFile + uintptr(v3))) = int8('\000')
|
|
}
|
|
libc.Xmemset(tls, zFile+uintptr(iOut), 0, uint32(4)) /* end-of-options + empty journal filenames */
|
|
/* Check if there were any options specified that should be interpreted
|
|
** here. Options that are interpreted here include "vfs" and those that
|
|
** correspond to flags that may be passed to the sqlite3_open_v2()
|
|
** method. */
|
|
zOpt = zFile + uintptr(libc.Xstrlen(tls, zFile)+uint32(1))
|
|
for **(**int8)(__ccgo_up(zOpt)) != 0 {
|
|
nOpt = libc.Int64FromUint32(libc.Xstrlen(tls, zOpt))
|
|
zVal = zOpt + uintptr(nOpt+int64(1))
|
|
nVal = libc.Int64FromUint32(libc.Xstrlen(tls, zVal))
|
|
if nOpt == int64(3) && libc.Xmemcmp(tls, __ccgo_ts+26160, zOpt, uint32(3)) == 0 {
|
|
zVfs = zVal
|
|
} else {
|
|
aMode = uintptr(0)
|
|
zModeType = uintptr(0)
|
|
mask = 0
|
|
limit = 0
|
|
if nOpt == int64(5) && libc.Xmemcmp(tls, __ccgo_ts+26164, zOpt, uint32(5)) == 0 {
|
|
mask = libc.Int32FromInt32(SQLITE_OPEN_SHAREDCACHE) | libc.Int32FromInt32(SQLITE_OPEN_PRIVATECACHE)
|
|
aMode = uintptr(unsafe.Pointer(&_aCacheMode))
|
|
limit = mask
|
|
zModeType = __ccgo_ts + 26164
|
|
}
|
|
if nOpt == int64(4) && libc.Xmemcmp(tls, __ccgo_ts+26185, zOpt, uint32(4)) == 0 {
|
|
mask = libc.Int32FromInt32(SQLITE_OPEN_READONLY) | libc.Int32FromInt32(SQLITE_OPEN_READWRITE) | libc.Int32FromInt32(SQLITE_OPEN_CREATE) | libc.Int32FromInt32(SQLITE_OPEN_MEMORY)
|
|
aMode = uintptr(unsafe.Pointer(&_aOpenMode))
|
|
limit = libc.Int32FromUint32(libc.Uint32FromInt32(mask) & flags)
|
|
zModeType = __ccgo_ts + 3551
|
|
}
|
|
if aMode != 0 {
|
|
mode = 0
|
|
i = 0
|
|
for {
|
|
if !((**(**struct {
|
|
Fz uintptr
|
|
Fmode int32
|
|
})(__ccgo_up(aMode + uintptr(i)*8))).Fz != 0) {
|
|
break
|
|
}
|
|
z = (**(**struct {
|
|
Fz uintptr
|
|
Fmode int32
|
|
})(__ccgo_up(aMode + uintptr(i)*8))).Fz
|
|
if nVal == libc.Int64FromUint32(libc.Xstrlen(tls, z)) && 0 == libc.Xmemcmp(tls, zVal, z, libc.Uint32FromInt64(nVal)) {
|
|
mode = (**(**struct {
|
|
Fz uintptr
|
|
Fmode int32
|
|
})(__ccgo_up(aMode + uintptr(i)*8))).Fmode
|
|
break
|
|
}
|
|
goto _9
|
|
_9:
|
|
;
|
|
i = i + 1
|
|
}
|
|
if mode == 0 {
|
|
**(**uintptr)(__ccgo_up(pzErrMsg)) = Xsqlite3_mprintf(tls, __ccgo_ts+26200, libc.VaList(bp+8, zModeType, zVal))
|
|
rc = int32(SQLITE_ERROR)
|
|
goto parse_uri_out
|
|
}
|
|
if mode & ^libc.Int32FromInt32(SQLITE_OPEN_MEMORY) > limit {
|
|
**(**uintptr)(__ccgo_up(pzErrMsg)) = Xsqlite3_mprintf(tls, __ccgo_ts+26220, libc.VaList(bp+8, zModeType, zVal))
|
|
rc = int32(SQLITE_PERM)
|
|
goto parse_uri_out
|
|
}
|
|
flags = flags&libc.Uint32FromInt32(^mask) | libc.Uint32FromInt32(mode)
|
|
}
|
|
}
|
|
zOpt = zVal + uintptr(nVal+int64(1))
|
|
}
|
|
} else {
|
|
zFile = Xsqlite3_malloc64(tls, libc.Uint64FromInt64(nUri+int64(8)))
|
|
if !(zFile != 0) {
|
|
return int32(SQLITE_NOMEM)
|
|
}
|
|
libc.Xmemset(tls, zFile, 0, uint32(4))
|
|
zFile = zFile + uintptr(4)
|
|
if nUri != 0 {
|
|
libc.Xmemcpy(tls, zFile, zUri, libc.Uint32FromInt64(nUri))
|
|
}
|
|
libc.Xmemset(tls, zFile+uintptr(nUri), 0, uint32(4))
|
|
flags = flags & libc.Uint32FromInt32(^libc.Int32FromInt32(SQLITE_OPEN_URI))
|
|
}
|
|
**(**uintptr)(__ccgo_up(ppVfs)) = Xsqlite3_vfs_find(tls, zVfs)
|
|
if **(**uintptr)(__ccgo_up(ppVfs)) == uintptr(0) {
|
|
**(**uintptr)(__ccgo_up(pzErrMsg)) = Xsqlite3_mprintf(tls, __ccgo_ts+26244, libc.VaList(bp+8, zVfs))
|
|
rc = int32(SQLITE_ERROR)
|
|
}
|
|
goto parse_uri_out
|
|
parse_uri_out:
|
|
;
|
|
if rc != SQLITE_OK {
|
|
Xsqlite3_free_filename(tls, zFile)
|
|
zFile = uintptr(0)
|
|
}
|
|
**(**uint32)(__ccgo_up(pFlags)) = flags
|
|
**(**uintptr)(__ccgo_up(pzFile)) = zFile
|
|
return rc
|
|
}
|
|
|
|
// C documentation
|
|
//
|
|
// /*
|
|
// ** Process a pragma statement.
|
|
// **
|
|
// ** Pragmas are of this form:
|
|
// **
|
|
// ** PRAGMA [schema.]id [= value]
|
|
// **
|
|
// ** The identifier might also be a string. The value is a string, and
|
|
// ** identifier, or a number. If minusFlag is true, then the value is
|
|
// ** a number that was preceded by a minus sign.
|
|
// **
|
|
// ** If the left side is "database.id" then pId1 is the database name
|
|
// ** and pId2 is the id. If the left side is just "id" then pId1 is the
|
|
// ** id and pId2 is any empty string.
|
|
// */
|
|
func _sqlite3Pragma(tls *libc.TLS, pParse uintptr, pId1 uintptr, pId2 uintptr, pValue uintptr, minusFlag int32) {
|
|
bp := tls.Alloc(208)
|
|
defer tls.Free(208)
|
|
var a1, a11, addr, addr1, addrCkFault, addrCkOk, addrOk, addrTop, b, bStrict, ckUniq, cnt, doTypeCheck, eAuto, eMode, eMode1, eMode2, i, i1, i10, i2, i3, i4, i5, i6, i7, i8, i9, iAddr, iAddr1, iBt, iCol, iCol1, iCookie, iDb, iDbLast, iEnd, iIdxDb, iLevel, iReg, iTab, iTabCur, iTabDb, iTabDb1, ii, ii1, ii2, ii3, ii4, initNCol, isHidden, isQuick, j2, j3, j4, jmp, jmp2, jmp21, jmp3, jmp4, jmp5, jmp6, jmp61, jmp7, k, k3, kk, label6, labelError, labelOk, loopTop, mx, mxCol, n, nBtree, nCheck, nHidden, nIdx, nIndex, nLimit, p11, p3, p4, r1, r11, r2, rc, regResult, regRow, showInternFunc, size, size1, size2, uniqOk, x1, v2 int32
|
|
var aOp, aOp1, aOp2, aOp3, aOp4, aOp5, aRoot, db, j, j1, k1, k2, k4, p, p1, pBt, pBt1, pBt2, pCheck, pCol, pCol1, pColExpr, pColl, pDb, pEnc, pFK, pFK1, pHash, pIdx, pIdx1, pIdx3, pIdx4, pIdx5, pIdx6, pIdx7, pMod, pObjTab, pPager, pPager1, pParent, pPk, pPk1, pPragma, pPrior, pSchema, pTab, pTab1, pTab10, pTab11, pTab12, pTab2, pTab3, pTab4, pTab5, pTab6, pTab7, pTab8, pTab9, pTbls, pVTab, v, x2, zDb, zErr, zErr1, zErr2, zLeft, zMod, zMode, zOpt, zRet, zRight, zSql, zSubSql, zType, v1, v5 uintptr
|
|
var azOrigin [3]uintptr
|
|
var cnum Ti16
|
|
var enc Tu8
|
|
var iPrior Tsqlite3_int64
|
|
var iRange, szThreshold TLogEst
|
|
var mask Tu64
|
|
var opMask Tu32
|
|
var _ /* N at bp+104 */ Tsqlite3_int64
|
|
var _ /* N at bp+112 */ Tsqlite3_int64
|
|
var _ /* N at bp+120 */ Tsqlite3_int64
|
|
var _ /* N at bp+96 */ Tsqlite3_int64
|
|
var _ /* aFcntl at bp+4 */ [4]uintptr
|
|
var _ /* aiCols at bp+68 */ uintptr
|
|
var _ /* iDataCur at bp+76 */ int32
|
|
var _ /* iIdxCur at bp+80 */ int32
|
|
var _ /* iLimit at bp+32 */ Ti64
|
|
var _ /* iLimit at bp+40 */ int32
|
|
var _ /* jmp3 at bp+88 */ int32
|
|
var _ /* mxErr at bp+72 */ int32
|
|
var _ /* pDfltValue at bp+84 */ uintptr
|
|
var _ /* pDummy at bp+60 */ uintptr
|
|
var _ /* pId at bp+0 */ uintptr
|
|
var _ /* pIdx at bp+64 */ uintptr
|
|
var _ /* res at bp+56 */ int32
|
|
var _ /* size at bp+44 */ int32
|
|
var _ /* sz at bp+48 */ Tsqlite3_int64
|
|
var _ /* x at bp+24 */ Ti64
|
|
_, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _ = a1, a11, aOp, aOp1, aOp2, aOp3, aOp4, aOp5, aRoot, addr, addr1, addrCkFault, addrCkOk, addrOk, addrTop, azOrigin, b, bStrict, ckUniq, cnt, cnum, db, doTypeCheck, eAuto, eMode, eMode1, eMode2, enc, i, i1, i10, i2, i3, i4, i5, i6, i7, i8, i9, iAddr, iAddr1, iBt, iCol, iCol1, iCookie, iDb, iDbLast, iEnd, iIdxDb, iLevel, iPrior, iRange, iReg, iTab, iTabCur, iTabDb, iTabDb1, ii, ii1, ii2, ii3, ii4, initNCol, isHidden, isQuick, j, j1, j2, j3, j4, jmp, jmp2, jmp21, jmp3, jmp4, jmp5, jmp6, jmp61, jmp7, k, k1, k2, k3, k4, kk, label6, labelError, labelOk, loopTop, mask, mx, mxCol, n, nBtree, nCheck, nHidden, nIdx, nIndex, nLimit, opMask, p, p1, p11, p3, p4, pBt, pBt1, pBt2, pCheck, pCol, pCol1, pColExpr, pColl, pDb, pEnc, pFK, pFK1, pHash, pIdx, pIdx1, pIdx3, pIdx4, pIdx5, pIdx6, pIdx7, pMod, pObjTab, pPager, pPager1, pParent, pPk, pPk1, pPragma, pPrior, pSchema, pTab, pTab1, pTab10, pTab11, pTab12, pTab2, pTab3, pTab4, pTab5, pTab6, pTab7, pTab8, pTab9, pTbls, pVTab, r1, r11, r2, rc, regResult, regRow, showInternFunc, size, size1, size2, szThreshold, uniqOk, v, x1, x2, zDb, zErr, zErr1, zErr2, zLeft, zMod, zMode, zOpt, zRet, zRight, zSql, zSubSql, zType, v1, v2, v5
|
|
zLeft = uintptr(0) /* Nul-terminated UTF-8 string <id> */
|
|
zRight = uintptr(0) /* Nul-terminated UTF-8 string <value>, or NULL */
|
|
zDb = uintptr(0) /* return value form SQLITE_FCNTL_PRAGMA */
|
|
db = (*TParse)(unsafe.Pointer(pParse)).Fdb /* The specific database being pragmaed */
|
|
v = _sqlite3GetVdbe(tls, pParse) /* The pragma */
|
|
if v == uintptr(0) {
|
|
return
|
|
}
|
|
_sqlite3VdbeRunOnlyOnce(tls, v)
|
|
(*TParse)(unsafe.Pointer(pParse)).FnMem = int32(2)
|
|
/* Interpret the [schema.] part of the pragma statement. iDb is the
|
|
** index of the database this pragma is being applied to in db.aDb[]. */
|
|
iDb = _sqlite3TwoPartName(tls, pParse, pId1, pId2, bp)
|
|
if iDb < 0 {
|
|
return
|
|
}
|
|
pDb = (*Tsqlite3)(unsafe.Pointer(db)).FaDb + uintptr(iDb)*16
|
|
/* If the temp database has been explicitly named as part of the
|
|
** pragma, make sure it is open.
|
|
*/
|
|
if iDb == int32(1) && _sqlite3OpenTempDatabase(tls, pParse) != 0 {
|
|
return
|
|
}
|
|
zLeft = _sqlite3NameFromToken(tls, db, **(**uintptr)(__ccgo_up(bp)))
|
|
if !(zLeft != 0) {
|
|
return
|
|
}
|
|
if minusFlag != 0 {
|
|
zRight = _sqlite3MPrintf(tls, db, __ccgo_ts+19216, libc.VaList(bp+136, pValue))
|
|
} else {
|
|
zRight = _sqlite3NameFromToken(tls, db, pValue)
|
|
}
|
|
if (*TToken)(unsafe.Pointer(pId2)).Fn > uint32(0) {
|
|
v1 = (*TDb)(unsafe.Pointer(pDb)).FzDbSName
|
|
} else {
|
|
v1 = uintptr(0)
|
|
}
|
|
zDb = v1
|
|
if _sqlite3AuthCheck(tls, pParse, int32(SQLITE_PRAGMA), zLeft, zRight, zDb) != 0 {
|
|
goto pragma_out
|
|
}
|
|
/* Send an SQLITE_FCNTL_PRAGMA file-control to the underlying VFS
|
|
** connection. If it returns SQLITE_OK, then assume that the VFS
|
|
** handled the pragma and generate a no-op prepared statement.
|
|
**
|
|
** IMPLEMENTATION-OF: R-12238-55120 Whenever a PRAGMA statement is parsed,
|
|
** an SQLITE_FCNTL_PRAGMA file control is sent to the open sqlite3_file
|
|
** object corresponding to the database file to which the pragma
|
|
** statement refers.
|
|
**
|
|
** IMPLEMENTATION-OF: R-29875-31678 The argument to the SQLITE_FCNTL_PRAGMA
|
|
** file control is an array of pointers to strings (char**) in which the
|
|
** second element of the array is the name of the pragma and the third
|
|
** element is the argument to the pragma or NULL if the pragma has no
|
|
** argument.
|
|
*/
|
|
(**(**[4]uintptr)(__ccgo_up(bp + 4)))[0] = uintptr(0)
|
|
(**(**[4]uintptr)(__ccgo_up(bp + 4)))[int32(1)] = zLeft
|
|
(**(**[4]uintptr)(__ccgo_up(bp + 4)))[int32(2)] = zRight
|
|
(**(**[4]uintptr)(__ccgo_up(bp + 4)))[int32(3)] = uintptr(0)
|
|
(*Tsqlite3)(unsafe.Pointer(db)).FbusyHandler.FnBusy = 0
|
|
rc = Xsqlite3_file_control(tls, db, zDb, int32(SQLITE_FCNTL_PRAGMA), bp+4)
|
|
if rc == SQLITE_OK {
|
|
_sqlite3VdbeSetNumCols(tls, v, int32(1))
|
|
_sqlite3VdbeSetColName(tls, v, 0, COLNAME_NAME, (**(**[4]uintptr)(__ccgo_up(bp + 4)))[0], uintptr(-libc.Int32FromInt32(1)))
|
|
_returnSingleText(tls, v, (**(**[4]uintptr)(__ccgo_up(bp + 4)))[0])
|
|
Xsqlite3_free(tls, (**(**[4]uintptr)(__ccgo_up(bp + 4)))[0])
|
|
goto pragma_out
|
|
}
|
|
if rc != int32(SQLITE_NOTFOUND) {
|
|
if (**(**[4]uintptr)(__ccgo_up(bp + 4)))[0] != 0 {
|
|
_sqlite3ErrorMsg(tls, pParse, __ccgo_ts+3942, libc.VaList(bp+136, (**(**[4]uintptr)(__ccgo_up(bp + 4)))[0]))
|
|
Xsqlite3_free(tls, (**(**[4]uintptr)(__ccgo_up(bp + 4)))[0])
|
|
}
|
|
(*TParse)(unsafe.Pointer(pParse)).FnErr = (*TParse)(unsafe.Pointer(pParse)).FnErr + 1
|
|
(*TParse)(unsafe.Pointer(pParse)).Frc = rc
|
|
goto pragma_out
|
|
}
|
|
/* Locate the pragma in the lookup table */
|
|
pPragma = _pragmaLocate(tls, zLeft)
|
|
if pPragma == uintptr(0) {
|
|
/* IMP: R-43042-22504 No error messages are generated if an
|
|
** unknown pragma is issued. */
|
|
goto pragma_out
|
|
}
|
|
/* Make sure the database schema is loaded if the pragma requires that */
|
|
if libc.Int32FromUint8((*TPragmaName)(unsafe.Pointer(pPragma)).FmPragFlg)&int32(PragFlg_NeedSchema) != 0 {
|
|
if _sqlite3ReadSchema(tls, pParse) != 0 {
|
|
goto pragma_out
|
|
}
|
|
}
|
|
/* Register the result column names for pragmas that return results */
|
|
if libc.Int32FromUint8((*TPragmaName)(unsafe.Pointer(pPragma)).FmPragFlg)&int32(PragFlg_NoColumns) == 0 && (libc.Int32FromUint8((*TPragmaName)(unsafe.Pointer(pPragma)).FmPragFlg)&int32(PragFlg_NoColumns1) == 0 || zRight == uintptr(0)) {
|
|
_setPragmaResultColumnNames(tls, v, pPragma)
|
|
}
|
|
/* Jump to the appropriate pragma handler */
|
|
switch libc.Int32FromUint8((*TPragmaName)(unsafe.Pointer(pPragma)).FePragTyp) {
|
|
/*
|
|
** PRAGMA [schema.]default_cache_size
|
|
** PRAGMA [schema.]default_cache_size=N
|
|
**
|
|
** The first form reports the current persistent setting for the
|
|
** page cache size. The value returned is the maximum number of
|
|
** pages in the page cache. The second form sets both the current
|
|
** page cache size value and the persistent page cache size value
|
|
** stored in the database file.
|
|
**
|
|
** Older versions of SQLite would set the default cache size to a
|
|
** negative number to indicate synchronous=OFF. These days, synchronous
|
|
** is always on by default regardless of the sign of the default cache
|
|
** size. But continue to take the absolute value of the default cache
|
|
** size of historical compatibility.
|
|
*/
|
|
case int32(PragTyp_DEFAULT_CACHE_SIZE):
|
|
_sqlite3VdbeUsesBtree(tls, v, iDb)
|
|
if !(zRight != 0) {
|
|
**(**int32)(__ccgo_up(pParse + 48)) += int32(2)
|
|
aOp = _sqlite3VdbeAddOpList(tls, v, libc.Int32FromUint32(libc.Uint32FromInt64(36)/libc.Uint32FromInt64(4)), uintptr(unsafe.Pointer(&_getCacheSize)), _iLn3)
|
|
if 0 != 0 {
|
|
break
|
|
}
|
|
(**(**TVdbeOp)(__ccgo_up(aOp))).Fp1 = iDb
|
|
(**(**TVdbeOp)(__ccgo_up(aOp + 1*20))).Fp1 = iDb
|
|
(**(**TVdbeOp)(__ccgo_up(aOp + 6*20))).Fp1 = -int32(2000)
|
|
} else {
|
|
size = _sqlite3AbsInt32(tls, _sqlite3Atoi(tls, zRight))
|
|
_sqlite3BeginWriteOperation(tls, pParse, 0, iDb)
|
|
_sqlite3VdbeAddOp3(tls, v, int32(OP_SetCookie), iDb, int32(BTREE_DEFAULT_CACHE_SIZE), size)
|
|
(*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)
|
|
}
|
|
break
|
|
/*
|
|
** PRAGMA [schema.]page_size
|
|
** PRAGMA [schema.]page_size=N
|
|
**
|
|
** The first form reports the current setting for the
|
|
** database page size in bytes. The second form sets the
|
|
** database page size value. The value can only be set if
|
|
** the database has not yet been created.
|
|
*/
|
|
fallthrough
|
|
case int32(PragTyp_PAGE_SIZE):
|
|
pBt = (*TDb)(unsafe.Pointer(pDb)).FpBt
|
|
if !(zRight != 0) {
|
|
if pBt != 0 {
|
|
v2 = _sqlite3BtreeGetPageSize(tls, pBt)
|
|
} else {
|
|
v2 = 0
|
|
}
|
|
size1 = v2
|
|
_returnSingleInt(tls, v, int64(size1))
|
|
} else {
|
|
/* Malloc may fail when setting the page-size, as there is an internal
|
|
** buffer that the pager module resizes using sqlite3_realloc().
|
|
*/
|
|
(*Tsqlite3)(unsafe.Pointer(db)).FnextPagesize = _sqlite3Atoi(tls, zRight)
|
|
if int32(SQLITE_NOMEM) == _sqlite3BtreeSetPageSize(tls, pBt, (*Tsqlite3)(unsafe.Pointer(db)).FnextPagesize, 0, 0) {
|
|
_sqlite3OomFault(tls, db)
|
|
}
|
|
}
|
|
break
|
|
/*
|
|
** PRAGMA [schema.]secure_delete
|
|
** PRAGMA [schema.]secure_delete=ON/OFF/FAST
|
|
**
|
|
** The first form reports the current setting for the
|
|
** secure_delete flag. The second form changes the secure_delete
|
|
** flag setting and reports the new value.
|
|
*/
|
|
fallthrough
|
|
case int32(PragTyp_SECURE_DELETE):
|
|
pBt1 = (*TDb)(unsafe.Pointer(pDb)).FpBt
|
|
b = -int32(1)
|
|
if zRight != 0 {
|
|
if Xsqlite3_stricmp(tls, zRight, __ccgo_ts+19220) == 0 {
|
|
b = int32(2)
|
|
} else {
|
|
b = libc.Int32FromUint8(_sqlite3GetBoolean(tls, zRight, uint8(0)))
|
|
}
|
|
}
|
|
if (*TToken)(unsafe.Pointer(pId2)).Fn == uint32(0) && b >= 0 {
|
|
ii = 0
|
|
for {
|
|
if !(ii < (*Tsqlite3)(unsafe.Pointer(db)).FnDb) {
|
|
break
|
|
}
|
|
_sqlite3BtreeSecureDelete(tls, (**(**TDb)(__ccgo_up((*Tsqlite3)(unsafe.Pointer(db)).FaDb + uintptr(ii)*16))).FpBt, b)
|
|
goto _3
|
|
_3:
|
|
;
|
|
ii = ii + 1
|
|
}
|
|
}
|
|
b = _sqlite3BtreeSecureDelete(tls, pBt1, b)
|
|
_returnSingleInt(tls, v, int64(b))
|
|
break
|
|
/*
|
|
** PRAGMA [schema.]max_page_count
|
|
** PRAGMA [schema.]max_page_count=N
|
|
**
|
|
** The first form reports the current setting for the
|
|
** maximum number of pages in the database file. The
|
|
** second form attempts to change this setting. Both
|
|
** forms return the current setting.
|
|
**
|
|
** The absolute value of N is used. This is undocumented and might
|
|
** change. The only purpose is to provide an easy way to test
|
|
** the sqlite3AbsInt32() function.
|
|
**
|
|
** PRAGMA [schema.]page_count
|
|
**
|
|
** Return the number of pages in the specified database.
|
|
*/
|
|
fallthrough
|
|
case int32(PragTyp_PAGE_COUNT):
|
|
**(**Ti64)(__ccgo_up(bp + 24)) = 0
|
|
_sqlite3CodeVerifySchema(tls, pParse, iDb)
|
|
v1 = pParse + 48
|
|
*(*int32)(unsafe.Pointer(v1)) = *(*int32)(unsafe.Pointer(v1)) + 1
|
|
v2 = *(*int32)(unsafe.Pointer(v1))
|
|
iReg = v2
|
|
if libc.Int32FromUint8(_sqlite3UpperToLower[libc.Uint8FromInt8(**(**int8)(__ccgo_up(zLeft)))]) == int32('p') {
|
|
_sqlite3VdbeAddOp2(tls, v, int32(OP_Pagecount), iDb, iReg)
|
|
} else {
|
|
if zRight != 0 && _sqlite3DecOrHexToI64(tls, zRight, bp+24) == 0 {
|
|
if **(**Ti64)(__ccgo_up(bp + 24)) < 0 {
|
|
**(**Ti64)(__ccgo_up(bp + 24)) = 0
|
|
} else {
|
|
if **(**Ti64)(__ccgo_up(bp + 24)) > libc.Int64FromUint32(0xfffffffe) {
|
|
**(**Ti64)(__ccgo_up(bp + 24)) = libc.Int64FromUint32(0xfffffffe)
|
|
}
|
|
}
|
|
} else {
|
|
**(**Ti64)(__ccgo_up(bp + 24)) = 0
|
|
}
|
|
_sqlite3VdbeAddOp3(tls, v, int32(OP_MaxPgcnt), iDb, iReg, int32(**(**Ti64)(__ccgo_up(bp + 24))))
|
|
}
|
|
_sqlite3VdbeAddOp2(tls, v, int32(OP_ResultRow), iReg, int32(1))
|
|
break
|
|
/*
|
|
** PRAGMA [schema.]locking_mode
|
|
** PRAGMA [schema.]locking_mode = (normal|exclusive)
|
|
*/
|
|
fallthrough
|
|
case int32(PragTyp_LOCKING_MODE):
|
|
zRet = __ccgo_ts + 19011
|
|
eMode = _getLockingMode(tls, zRight)
|
|
if (*TToken)(unsafe.Pointer(pId2)).Fn == uint32(0) && eMode == -int32(1) {
|
|
/* Simple "PRAGMA locking_mode;" statement. This is a query for
|
|
** the current default locking mode (which may be different to
|
|
** the locking-mode of the main database).
|
|
*/
|
|
eMode = libc.Int32FromUint8((*Tsqlite3)(unsafe.Pointer(db)).FdfltLockMode)
|
|
} else {
|
|
if (*TToken)(unsafe.Pointer(pId2)).Fn == uint32(0) {
|
|
ii1 = int32(2)
|
|
for {
|
|
if !(ii1 < (*Tsqlite3)(unsafe.Pointer(db)).FnDb) {
|
|
break
|
|
}
|
|
pPager = _sqlite3BtreePager(tls, (**(**TDb)(__ccgo_up((*Tsqlite3)(unsafe.Pointer(db)).FaDb + uintptr(ii1)*16))).FpBt)
|
|
_sqlite3PagerLockingMode(tls, pPager, eMode)
|
|
goto _6
|
|
_6:
|
|
;
|
|
ii1 = ii1 + 1
|
|
}
|
|
(*Tsqlite3)(unsafe.Pointer(db)).FdfltLockMode = libc.Uint8FromInt32(eMode)
|
|
}
|
|
pPager = _sqlite3BtreePager(tls, (*TDb)(unsafe.Pointer(pDb)).FpBt)
|
|
eMode = _sqlite3PagerLockingMode(tls, pPager, eMode)
|
|
}
|
|
if eMode == int32(PAGER_LOCKINGMODE_EXCLUSIVE) {
|
|
zRet = __ccgo_ts + 19001
|
|
}
|
|
_returnSingleText(tls, v, zRet)
|
|
break
|
|
/*
|
|
** PRAGMA [schema.]journal_mode
|
|
** PRAGMA [schema.]journal_mode =
|
|
** (delete|persist|off|truncate|memory|wal|off)
|
|
*/
|
|
fallthrough
|
|
case int32(PragTyp_JOURNAL_MODE): /* Loop counter */
|
|
if zRight == uintptr(0) {
|
|
/* If there is no "=MODE" part of the pragma, do a query for the
|
|
** current mode */
|
|
eMode1 = -int32(1)
|
|
} else {
|
|
n = _sqlite3Strlen30(tls, zRight)
|
|
eMode1 = 0
|
|
for {
|
|
v1 = _sqlite3JournalModename(tls, eMode1)
|
|
zMode = v1
|
|
if !(v1 != uintptr(0)) {
|
|
break
|
|
}
|
|
if Xsqlite3_strnicmp(tls, zRight, zMode, n) == 0 {
|
|
break
|
|
}
|
|
goto _7
|
|
_7:
|
|
;
|
|
eMode1 = eMode1 + 1
|
|
}
|
|
if !(zMode != 0) {
|
|
/* If the "=MODE" part does not match any known journal mode,
|
|
** then do a query */
|
|
eMode1 = -int32(1)
|
|
}
|
|
if eMode1 == int32(PAGER_JOURNALMODE_OFF) && (*Tsqlite3)(unsafe.Pointer(db)).Fflags&uint64(SQLITE_Defensive) != uint64(0) {
|
|
/* Do not allow journal-mode "OFF" in defensive since the database
|
|
** can become corrupted using ordinary SQL when the journal is off */
|
|
eMode1 = -int32(1)
|
|
}
|
|
}
|
|
if eMode1 == -int32(1) && (*TToken)(unsafe.Pointer(pId2)).Fn == uint32(0) {
|
|
/* Convert "PRAGMA journal_mode" into "PRAGMA main.journal_mode" */
|
|
iDb = 0
|
|
(*TToken)(unsafe.Pointer(pId2)).Fn = uint32(1)
|
|
}
|
|
ii2 = (*Tsqlite3)(unsafe.Pointer(db)).FnDb - int32(1)
|
|
for {
|
|
if !(ii2 >= 0) {
|
|
break
|
|
}
|
|
if (**(**TDb)(__ccgo_up((*Tsqlite3)(unsafe.Pointer(db)).FaDb + uintptr(ii2)*16))).FpBt != 0 && (ii2 == iDb || (*TToken)(unsafe.Pointer(pId2)).Fn == uint32(0)) {
|
|
_sqlite3VdbeUsesBtree(tls, v, ii2)
|
|
_sqlite3VdbeAddOp3(tls, v, int32(OP_JournalMode), ii2, int32(1), eMode1)
|
|
}
|
|
goto _9
|
|
_9:
|
|
;
|
|
ii2 = ii2 - 1
|
|
}
|
|
_sqlite3VdbeAddOp2(tls, v, int32(OP_ResultRow), int32(1), int32(1))
|
|
break
|
|
/*
|
|
** PRAGMA [schema.]journal_size_limit
|
|
** PRAGMA [schema.]journal_size_limit=N
|
|
**
|
|
** Get or set the size limit on rollback journal files.
|
|
*/
|
|
fallthrough
|
|
case int32(PragTyp_JOURNAL_SIZE_LIMIT):
|
|
pPager1 = _sqlite3BtreePager(tls, (*TDb)(unsafe.Pointer(pDb)).FpBt)
|
|
**(**Ti64)(__ccgo_up(bp + 32)) = int64(-int32(2))
|
|
if zRight != 0 {
|
|
_sqlite3DecOrHexToI64(tls, zRight, bp+32)
|
|
if **(**Ti64)(__ccgo_up(bp + 32)) < int64(-int32(1)) {
|
|
**(**Ti64)(__ccgo_up(bp + 32)) = int64(-int32(1))
|
|
}
|
|
}
|
|
**(**Ti64)(__ccgo_up(bp + 32)) = _sqlite3PagerJournalSizeLimit(tls, pPager1, **(**Ti64)(__ccgo_up(bp + 32)))
|
|
_returnSingleInt(tls, v, **(**Ti64)(__ccgo_up(bp + 32)))
|
|
break
|
|
/*
|
|
** PRAGMA [schema.]auto_vacuum
|
|
** PRAGMA [schema.]auto_vacuum=N
|
|
**
|
|
** Get or set the value of the database 'auto-vacuum' parameter.
|
|
** The value is one of: 0 NONE 1 FULL 2 INCREMENTAL
|
|
*/
|
|
fallthrough
|
|
case int32(PragTyp_AUTO_VACUUM):
|
|
pBt2 = (*TDb)(unsafe.Pointer(pDb)).FpBt
|
|
if !(zRight != 0) {
|
|
_returnSingleInt(tls, v, int64(_sqlite3BtreeGetAutoVacuum(tls, pBt2)))
|
|
} else {
|
|
eAuto = _getAutoVacuum(tls, zRight)
|
|
(*Tsqlite3)(unsafe.Pointer(db)).FnextAutovac = libc.Int8FromUint8(libc.Uint8FromInt32(eAuto))
|
|
/* Call SetAutoVacuum() to set initialize the internal auto and
|
|
** incr-vacuum flags. This is required in case this connection
|
|
** creates the database file. It is important that it is created
|
|
** as an auto-vacuum capable db.
|
|
*/
|
|
rc = _sqlite3BtreeSetAutoVacuum(tls, pBt2, eAuto)
|
|
if rc == SQLITE_OK && (eAuto == int32(1) || eAuto == int32(2)) {
|
|
iAddr = _sqlite3VdbeCurrentAddr(tls, v)
|
|
aOp1 = _sqlite3VdbeAddOpList(tls, v, libc.Int32FromUint32(libc.Uint32FromInt64(20)/libc.Uint32FromInt64(4)), uintptr(unsafe.Pointer(&_setMeta6)), _iLn11)
|
|
if 0 != 0 {
|
|
break
|
|
}
|
|
(**(**TVdbeOp)(__ccgo_up(aOp1))).Fp1 = iDb
|
|
(**(**TVdbeOp)(__ccgo_up(aOp1 + 1*20))).Fp1 = iDb
|
|
(**(**TVdbeOp)(__ccgo_up(aOp1 + 2*20))).Fp2 = iAddr + int32(4)
|
|
(**(**TVdbeOp)(__ccgo_up(aOp1 + 4*20))).Fp1 = iDb
|
|
(**(**TVdbeOp)(__ccgo_up(aOp1 + 4*20))).Fp3 = eAuto - int32(1)
|
|
_sqlite3VdbeUsesBtree(tls, v, iDb)
|
|
}
|
|
}
|
|
break
|
|
/*
|
|
** PRAGMA [schema.]incremental_vacuum(N)
|
|
**
|
|
** Do N steps of incremental vacuuming on a database.
|
|
*/
|
|
fallthrough
|
|
case int32(PragTyp_INCREMENTAL_VACUUM):
|
|
**(**int32)(__ccgo_up(bp + 40)) = 0
|
|
if zRight == uintptr(0) || !(_sqlite3GetInt32(tls, zRight, bp+40) != 0) || **(**int32)(__ccgo_up(bp + 40)) <= 0 {
|
|
**(**int32)(__ccgo_up(bp + 40)) = int32(0x7fffffff)
|
|
}
|
|
_sqlite3BeginWriteOperation(tls, pParse, 0, iDb)
|
|
_sqlite3VdbeAddOp2(tls, v, int32(OP_Integer), **(**int32)(__ccgo_up(bp + 40)), int32(1))
|
|
addr = _sqlite3VdbeAddOp1(tls, v, int32(OP_IncrVacuum), iDb)
|
|
_sqlite3VdbeAddOp1(tls, v, int32(OP_ResultRow), int32(1))
|
|
_sqlite3VdbeAddOp2(tls, v, int32(OP_AddImm), int32(1), -int32(1))
|
|
_sqlite3VdbeAddOp2(tls, v, int32(OP_IfPos), int32(1), addr)
|
|
_sqlite3VdbeJumpHere(tls, v, addr)
|
|
break
|
|
/*
|
|
** PRAGMA [schema.]cache_size
|
|
** PRAGMA [schema.]cache_size=N
|
|
**
|
|
** The first form reports the current local setting for the
|
|
** page cache size. The second form sets the local
|
|
** page cache size value. If N is positive then that is the
|
|
** number of pages in the cache. If N is negative, then the
|
|
** number of pages is adjusted so that the cache uses -N kibibytes
|
|
** of memory.
|
|
*/
|
|
fallthrough
|
|
case int32(PragTyp_CACHE_SIZE):
|
|
if !(zRight != 0) {
|
|
_returnSingleInt(tls, v, int64((*TSchema)(unsafe.Pointer((*TDb)(unsafe.Pointer(pDb)).FpSchema)).Fcache_size))
|
|
} else {
|
|
size2 = _sqlite3Atoi(tls, zRight)
|
|
(*TSchema)(unsafe.Pointer((*TDb)(unsafe.Pointer(pDb)).FpSchema)).Fcache_size = size2
|
|
_sqlite3BtreeSetCacheSize(tls, (*TDb)(unsafe.Pointer(pDb)).FpBt, (*TSchema)(unsafe.Pointer((*TDb)(unsafe.Pointer(pDb)).FpSchema)).Fcache_size)
|
|
}
|
|
break
|
|
/*
|
|
** PRAGMA [schema.]cache_spill
|
|
** PRAGMA cache_spill=BOOLEAN
|
|
** PRAGMA [schema.]cache_spill=N
|
|
**
|
|
** The first form reports the current local setting for the
|
|
** page cache spill size. The second form turns cache spill on
|
|
** or off. When turning cache spill on, the size is set to the
|
|
** current cache_size. The third form sets a spill size that
|
|
** may be different form the cache size.
|
|
** If N is positive then that is the
|
|
** number of pages in the cache. If N is negative, then the
|
|
** number of pages is adjusted so that the cache uses -N kibibytes
|
|
** of memory.
|
|
**
|
|
** If the number of cache_spill pages is less then the number of
|
|
** cache_size pages, no spilling occurs until the page count exceeds
|
|
** the number of cache_size pages.
|
|
**
|
|
** The cache_spill=BOOLEAN setting applies to all attached schemas,
|
|
** not just the schema specified.
|
|
*/
|
|
fallthrough
|
|
case int32(PragTyp_CACHE_SPILL):
|
|
if !(zRight != 0) {
|
|
if (*Tsqlite3)(unsafe.Pointer(db)).Fflags&uint64(SQLITE_CacheSpill) == uint64(0) {
|
|
v2 = 0
|
|
} else {
|
|
v2 = _sqlite3BtreeSetSpillSize(tls, (*TDb)(unsafe.Pointer(pDb)).FpBt, 0)
|
|
}
|
|
_returnSingleInt(tls, v, int64(v2))
|
|
} else {
|
|
**(**int32)(__ccgo_up(bp + 44)) = int32(1)
|
|
if _sqlite3GetInt32(tls, zRight, bp+44) != 0 {
|
|
_sqlite3BtreeSetSpillSize(tls, (*TDb)(unsafe.Pointer(pDb)).FpBt, **(**int32)(__ccgo_up(bp + 44)))
|
|
}
|
|
if _sqlite3GetBoolean(tls, zRight, libc.BoolUint8(**(**int32)(__ccgo_up(bp + 44)) != 0)) != 0 {
|
|
**(**Tu64)(__ccgo_up(db + 28)) |= uint64(SQLITE_CacheSpill)
|
|
} else {
|
|
**(**Tu64)(__ccgo_up(db + 28)) &= ^libc.Uint64FromInt32(SQLITE_CacheSpill)
|
|
}
|
|
_setAllPagerFlags(tls, db)
|
|
}
|
|
break
|
|
/*
|
|
** PRAGMA [schema.]mmap_size(N)
|
|
**
|
|
** Used to set mapping size limit. The mapping size limit is
|
|
** used to limit the aggregate size of all memory mapped regions of the
|
|
** database file. If this parameter is set to zero, then memory mapping
|
|
** is not used at all. If N is negative, then the default memory map
|
|
** limit determined by sqlite3_config(SQLITE_CONFIG_MMAP_SIZE) is set.
|
|
** The parameter N is measured in bytes.
|
|
**
|
|
** This value is advisory. The underlying VFS is free to memory map
|
|
** as little or as much as it wants. Except, if N is set to 0 then the
|
|
** upper layers will never invoke the xFetch interfaces to the VFS.
|
|
*/
|
|
fallthrough
|
|
case int32(PragTyp_MMAP_SIZE):
|
|
if zRight != 0 {
|
|
_sqlite3DecOrHexToI64(tls, zRight, bp+48)
|
|
if **(**Tsqlite3_int64)(__ccgo_up(bp + 48)) < 0 {
|
|
**(**Tsqlite3_int64)(__ccgo_up(bp + 48)) = _sqlite3Config.FszMmap
|
|
}
|
|
if (*TToken)(unsafe.Pointer(pId2)).Fn == uint32(0) {
|
|
(*Tsqlite3)(unsafe.Pointer(db)).FszMmap = **(**Tsqlite3_int64)(__ccgo_up(bp + 48))
|
|
}
|
|
ii3 = (*Tsqlite3)(unsafe.Pointer(db)).FnDb - int32(1)
|
|
for {
|
|
if !(ii3 >= 0) {
|
|
break
|
|
}
|
|
if (**(**TDb)(__ccgo_up((*Tsqlite3)(unsafe.Pointer(db)).FaDb + uintptr(ii3)*16))).FpBt != 0 && (ii3 == iDb || (*TToken)(unsafe.Pointer(pId2)).Fn == uint32(0)) {
|
|
_sqlite3BtreeSetMmapLimit(tls, (**(**TDb)(__ccgo_up((*Tsqlite3)(unsafe.Pointer(db)).FaDb + uintptr(ii3)*16))).FpBt, **(**Tsqlite3_int64)(__ccgo_up(bp + 48)))
|
|
}
|
|
goto _11
|
|
_11:
|
|
;
|
|
ii3 = ii3 - 1
|
|
}
|
|
}
|
|
**(**Tsqlite3_int64)(__ccgo_up(bp + 48)) = int64(-int32(1))
|
|
rc = Xsqlite3_file_control(tls, db, zDb, int32(SQLITE_FCNTL_MMAP_SIZE), bp+48)
|
|
if rc == SQLITE_OK {
|
|
_returnSingleInt(tls, v, **(**Tsqlite3_int64)(__ccgo_up(bp + 48)))
|
|
} else {
|
|
if rc != int32(SQLITE_NOTFOUND) {
|
|
(*TParse)(unsafe.Pointer(pParse)).FnErr = (*TParse)(unsafe.Pointer(pParse)).FnErr + 1
|
|
(*TParse)(unsafe.Pointer(pParse)).Frc = rc
|
|
}
|
|
}
|
|
break
|
|
/*
|
|
** PRAGMA temp_store
|
|
** PRAGMA temp_store = "default"|"memory"|"file"
|
|
**
|
|
** Return or set the local value of the temp_store flag. Changing
|
|
** the local value does not make changes to the disk file and the default
|
|
** value will be restored the next time the database is opened.
|
|
**
|
|
** Note that it is possible for the library compile-time options to
|
|
** override this setting
|
|
*/
|
|
fallthrough
|
|
case int32(PragTyp_TEMP_STORE):
|
|
if !(zRight != 0) {
|
|
_returnSingleInt(tls, v, libc.Int64FromUint8((*Tsqlite3)(unsafe.Pointer(db)).Ftemp_store))
|
|
} else {
|
|
_changeTempStorage(tls, pParse, zRight)
|
|
}
|
|
break
|
|
/*
|
|
** PRAGMA temp_store_directory
|
|
** PRAGMA temp_store_directory = ""|"directory_name"
|
|
**
|
|
** Return or set the local value of the temp_store_directory flag. Changing
|
|
** the value sets a specific directory to be used for temporary files.
|
|
** Setting to a null string reverts to the default temporary directory search.
|
|
** If temporary directory is changed, then invalidateTempStorage.
|
|
**
|
|
*/
|
|
fallthrough
|
|
case int32(PragTyp_TEMP_STORE_DIRECTORY):
|
|
Xsqlite3_mutex_enter(tls, _sqlite3MutexAlloc(tls, int32(SQLITE_MUTEX_STATIC_VFS1)))
|
|
if !(zRight != 0) {
|
|
_returnSingleText(tls, v, Xsqlite3_temp_directory)
|
|
} else {
|
|
if **(**int8)(__ccgo_up(zRight)) != 0 {
|
|
rc = _sqlite3OsAccess(tls, (*Tsqlite3)(unsafe.Pointer(db)).FpVfs, zRight, int32(SQLITE_ACCESS_READWRITE), bp+56)
|
|
if rc != SQLITE_OK || **(**int32)(__ccgo_up(bp + 56)) == 0 {
|
|
_sqlite3ErrorMsg(tls, pParse, __ccgo_ts+19225, 0)
|
|
Xsqlite3_mutex_leave(tls, _sqlite3MutexAlloc(tls, int32(SQLITE_MUTEX_STATIC_VFS1)))
|
|
goto pragma_out
|
|
}
|
|
}
|
|
if libc.Bool(false) || libc.Bool(true) && libc.Int32FromUint8((*Tsqlite3)(unsafe.Pointer(db)).Ftemp_store) <= int32(1) || libc.Bool(libc.Bool(false) && libc.Int32FromUint8((*Tsqlite3)(unsafe.Pointer(db)).Ftemp_store) == int32(1)) {
|
|
_invalidateTempStorage(tls, pParse)
|
|
}
|
|
Xsqlite3_free(tls, Xsqlite3_temp_directory)
|
|
if **(**int8)(__ccgo_up(zRight)) != 0 {
|
|
Xsqlite3_temp_directory = Xsqlite3_mprintf(tls, __ccgo_ts+3942, libc.VaList(bp+136, zRight))
|
|
} else {
|
|
Xsqlite3_temp_directory = uintptr(0)
|
|
}
|
|
}
|
|
Xsqlite3_mutex_leave(tls, _sqlite3MutexAlloc(tls, int32(SQLITE_MUTEX_STATIC_VFS1)))
|
|
break
|
|
/*
|
|
** PRAGMA [schema.]synchronous
|
|
** PRAGMA [schema.]synchronous=OFF|ON|NORMAL|FULL|EXTRA
|
|
**
|
|
** Return or set the local value of the synchronous flag. Changing
|
|
** the local value does not make changes to the disk file and the
|
|
** default value will be restored the next time the database is
|
|
** opened.
|
|
*/
|
|
fallthrough
|
|
case int32(PragTyp_SYNCHRONOUS):
|
|
if !(zRight != 0) {
|
|
_returnSingleInt(tls, v, int64(libc.Int32FromUint8((*TDb)(unsafe.Pointer(pDb)).Fsafety_level)-int32(1)))
|
|
} else {
|
|
if !((*Tsqlite3)(unsafe.Pointer(db)).FautoCommit != 0) {
|
|
_sqlite3ErrorMsg(tls, pParse, __ccgo_ts+19250, 0)
|
|
} else {
|
|
if iDb != int32(1) {
|
|
iLevel = (libc.Int32FromUint8(_getSafetyLevel(tls, zRight, 0, uint8(1))) + int32(1)) & int32(PAGER_SYNCHRONOUS_MASK)
|
|
if iLevel == 0 {
|
|
iLevel = int32(1)
|
|
}
|
|
(*TDb)(unsafe.Pointer(pDb)).Fsafety_level = libc.Uint8FromInt32(iLevel)
|
|
(*TDb)(unsafe.Pointer(pDb)).FbSyncSet = uint8(1)
|
|
_setAllPagerFlags(tls, db)
|
|
}
|
|
}
|
|
}
|
|
case int32(PragTyp_FLAG):
|
|
if zRight == uintptr(0) {
|
|
_setPragmaResultColumnNames(tls, v, pPragma)
|
|
_returnSingleInt(tls, v, libc.BoolInt64((*Tsqlite3)(unsafe.Pointer(db)).Fflags&(*TPragmaName)(unsafe.Pointer(pPragma)).FiArg != uint64(0)))
|
|
} else {
|
|
mask = (*TPragmaName)(unsafe.Pointer(pPragma)).FiArg /* Mask of bits to set or clear. */
|
|
if libc.Int32FromUint8((*Tsqlite3)(unsafe.Pointer(db)).FautoCommit) == 0 {
|
|
/* Foreign key support may not be enabled or disabled while not
|
|
** in auto-commit mode. */
|
|
mask = mask & libc.Uint64FromInt32(^libc.Int32FromInt32(SQLITE_ForeignKeys))
|
|
}
|
|
if _sqlite3GetBoolean(tls, zRight, uint8(0)) != 0 {
|
|
if mask&uint64(SQLITE_WriteSchema) == uint64(0) || (*Tsqlite3)(unsafe.Pointer(db)).Fflags&uint64(SQLITE_Defensive) == uint64(0) {
|
|
**(**Tu64)(__ccgo_up(db + 28)) |= mask
|
|
}
|
|
} else {
|
|
**(**Tu64)(__ccgo_up(db + 28)) &= ^mask
|
|
if mask == uint64(SQLITE_DeferFKs) {
|
|
(*Tsqlite3)(unsafe.Pointer(db)).FnDeferredImmCons = 0
|
|
(*Tsqlite3)(unsafe.Pointer(db)).FnDeferredCons = 0
|
|
}
|
|
if mask&uint64(SQLITE_WriteSchema) != uint64(0) && Xsqlite3_stricmp(tls, zRight, __ccgo_ts+19303) == 0 {
|
|
/* IMP: R-60817-01178 If the argument is "RESET" then schema
|
|
** writing is disabled (as with "PRAGMA writable_schema=OFF") and,
|
|
** in addition, the schema is reloaded. */
|
|
_sqlite3ResetAllSchemasOfConnection(tls, db)
|
|
}
|
|
}
|
|
/* Many of the flag-pragmas modify the code generated by the SQL
|
|
** compiler (eg. count_changes). So add an opcode to expire all
|
|
** compiled SQL statements after modifying a pragma value.
|
|
*/
|
|
_sqlite3VdbeAddOp0(tls, v, int32(OP_Expire))
|
|
_setAllPagerFlags(tls, db)
|
|
}
|
|
break
|
|
/*
|
|
** PRAGMA table_info(<table>)
|
|
**
|
|
** Return a single row for each column of the named table. The columns of
|
|
** the returned data set are:
|
|
**
|
|
** cid: Column id (numbered from left to right, starting at 0)
|
|
** name: Column name
|
|
** type: Column declaration type.
|
|
** notnull: True if 'NOT NULL' is part of column declaration
|
|
** dflt_value: The default value for the column, if any.
|
|
** pk: Non-zero for PK fields.
|
|
*/
|
|
fallthrough
|
|
case int32(PragTyp_TABLE_INFO):
|
|
if zRight != 0 {
|
|
_sqlite3CodeVerifyNamedSchema(tls, pParse, zDb)
|
|
pTab = _sqlite3LocateTable(tls, pParse, uint32(LOCATE_NOERR), zRight, zDb)
|
|
if pTab != 0 {
|
|
nHidden = 0
|
|
pPk = _sqlite3PrimaryKeyIndex(tls, pTab)
|
|
(*TParse)(unsafe.Pointer(pParse)).FnMem = int32(7)
|
|
_sqlite3ViewGetColumnNames(tls, pParse, pTab)
|
|
i = 0
|
|
pCol = (*TTable)(unsafe.Pointer(pTab)).FaCol
|
|
for {
|
|
if !(i < int32((*TTable)(unsafe.Pointer(pTab)).FnCol)) {
|
|
break
|
|
}
|
|
isHidden = 0
|
|
if libc.Int32FromUint16((*TColumn)(unsafe.Pointer(pCol)).FcolFlags)&int32(COLFLAG_NOINSERT) != 0 {
|
|
if (*TPragmaName)(unsafe.Pointer(pPragma)).FiArg == uint64(0) {
|
|
nHidden = nHidden + 1
|
|
goto _12
|
|
}
|
|
if libc.Int32FromUint16((*TColumn)(unsafe.Pointer(pCol)).FcolFlags)&int32(COLFLAG_VIRTUAL) != 0 {
|
|
isHidden = int32(2) /* GENERATED ALWAYS AS ... VIRTUAL */
|
|
} else {
|
|
if libc.Int32FromUint16((*TColumn)(unsafe.Pointer(pCol)).FcolFlags)&int32(COLFLAG_STORED) != 0 {
|
|
isHidden = int32(3) /* GENERATED ALWAYS AS ... STORED */
|
|
} else {
|
|
isHidden = int32(1) /* HIDDEN */
|
|
}
|
|
}
|
|
}
|
|
if libc.Int32FromUint16((*TColumn)(unsafe.Pointer(pCol)).FcolFlags)&int32(COLFLAG_PRIMKEY) == 0 {
|
|
k = 0
|
|
} else {
|
|
if pPk == uintptr(0) {
|
|
k = int32(1)
|
|
} else {
|
|
k = int32(1)
|
|
for {
|
|
if !(k <= int32((*TTable)(unsafe.Pointer(pTab)).FnCol) && int32(**(**Ti16)(__ccgo_up((*TIndex)(unsafe.Pointer(pPk)).FaiColumn + uintptr(k-int32(1))*2))) != i) {
|
|
break
|
|
}
|
|
goto _13
|
|
_13:
|
|
;
|
|
k = k + 1
|
|
}
|
|
}
|
|
}
|
|
pColExpr = _sqlite3ColumnExpr(tls, pTab, pCol)
|
|
if (*TPragmaName)(unsafe.Pointer(pPragma)).FiArg != 0 {
|
|
v1 = __ccgo_ts + 19309
|
|
} else {
|
|
v1 = __ccgo_ts + 19317
|
|
}
|
|
if int32(uint32(*(*uint8)(unsafe.Pointer(pCol + 4))&0xf>>0)) != 0 {
|
|
v2 = int32(1)
|
|
} else {
|
|
v2 = 0
|
|
}
|
|
if isHidden >= int32(2) || pColExpr == uintptr(0) {
|
|
v5 = uintptr(0)
|
|
} else {
|
|
v5 = *(*uintptr)(unsafe.Pointer(pColExpr + 8))
|
|
}
|
|
_sqlite3VdbeMultiLoad(tls, v, int32(1), v1, libc.VaList(bp+136, i-nHidden, (*TColumn)(unsafe.Pointer(pCol)).FzCnName, _sqlite3ColumnType(tls, pCol, __ccgo_ts+1702), v2, v5, k, isHidden))
|
|
goto _12
|
|
_12:
|
|
;
|
|
i = i + 1
|
|
pCol += 12
|
|
}
|
|
}
|
|
}
|
|
break
|
|
/*
|
|
** PRAGMA table_list
|
|
**
|
|
** Return a single row for each table, virtual table, or view in the
|
|
** entire schema.
|
|
**
|
|
** schema: Name of attached database hold this table
|
|
** name: Name of the table itself
|
|
** type: "table", "view", "virtual", "shadow"
|
|
** ncol: Number of columns
|
|
** wr: True for a WITHOUT ROWID table
|
|
** strict: True for a STRICT table
|
|
*/
|
|
fallthrough
|
|
case int32(PragTyp_TABLE_LIST):
|
|
(*TParse)(unsafe.Pointer(pParse)).FnMem = int32(6)
|
|
_sqlite3CodeVerifyNamedSchema(tls, pParse, zDb)
|
|
ii4 = 0
|
|
for {
|
|
if !(ii4 < (*Tsqlite3)(unsafe.Pointer(db)).FnDb) {
|
|
break
|
|
}
|
|
if zDb != 0 && Xsqlite3_stricmp(tls, zDb, (**(**TDb)(__ccgo_up((*Tsqlite3)(unsafe.Pointer(db)).FaDb + uintptr(ii4)*16))).FzDbSName) != 0 {
|
|
goto _17
|
|
}
|
|
/* Ensure that the Table.nCol field is initialized for all views
|
|
** and virtual tables. Each time we initialize a Table.nCol value
|
|
** for a table, that can potentially disrupt the hash table, so restart
|
|
** the initialization scan.
|
|
*/
|
|
pHash = (**(**TDb)(__ccgo_up((*Tsqlite3)(unsafe.Pointer(db)).FaDb + uintptr(ii4)*16))).FpSchema + 8
|
|
initNCol = libc.Int32FromUint32((*THash)(unsafe.Pointer(pHash)).Fcount)
|
|
for {
|
|
v2 = initNCol
|
|
initNCol = initNCol - 1
|
|
if !(v2 != 0) {
|
|
break
|
|
}
|
|
k1 = (*THash)(unsafe.Pointer(pHash)).Ffirst
|
|
for {
|
|
if !(int32(1) != 0) {
|
|
break
|
|
}
|
|
if k1 == uintptr(0) {
|
|
initNCol = 0
|
|
break
|
|
}
|
|
pTab1 = (*THashElem)(unsafe.Pointer(k1)).Fdata
|
|
if int32((*TTable)(unsafe.Pointer(pTab1)).FnCol) == 0 {
|
|
zSql = _sqlite3MPrintf(tls, db, __ccgo_ts+19324, libc.VaList(bp+136, (*TTable)(unsafe.Pointer(pTab1)).FzName))
|
|
if zSql != 0 {
|
|
**(**uintptr)(__ccgo_up(bp + 60)) = uintptr(0)
|
|
Xsqlite3_prepare_v3(tls, db, zSql, -int32(1), uint32(SQLITE_PREPARE_DONT_LOG), bp+60, uintptr(0))
|
|
Xsqlite3_finalize(tls, **(**uintptr)(__ccgo_up(bp + 60)))
|
|
_sqlite3DbFree(tls, db, zSql)
|
|
}
|
|
if (*Tsqlite3)(unsafe.Pointer(db)).FmallocFailed != 0 {
|
|
_sqlite3ErrorMsg(tls, (*Tsqlite3)(unsafe.Pointer(db)).FpParse, __ccgo_ts+1672, 0)
|
|
(*TParse)(unsafe.Pointer((*Tsqlite3)(unsafe.Pointer(db)).FpParse)).Frc = int32(SQLITE_NOMEM)
|
|
}
|
|
pHash = (**(**TDb)(__ccgo_up((*Tsqlite3)(unsafe.Pointer(db)).FaDb + uintptr(ii4)*16))).FpSchema + 8
|
|
break
|
|
}
|
|
goto _19
|
|
_19:
|
|
;
|
|
k1 = (*THashElem)(unsafe.Pointer(k1)).Fnext
|
|
}
|
|
}
|
|
k1 = (*THash)(unsafe.Pointer(pHash)).Ffirst
|
|
for {
|
|
if !(k1 != 0) {
|
|
break
|
|
}
|
|
pTab2 = (*THashElem)(unsafe.Pointer(k1)).Fdata
|
|
if zRight != 0 && Xsqlite3_stricmp(tls, zRight, (*TTable)(unsafe.Pointer(pTab2)).FzName) != 0 {
|
|
goto _20
|
|
}
|
|
if libc.Int32FromUint8((*TTable)(unsafe.Pointer(pTab2)).FeTabType) == int32(TABTYP_VIEW) {
|
|
zType = __ccgo_ts + 11117
|
|
} else {
|
|
if libc.Int32FromUint8((*TTable)(unsafe.Pointer(pTab2)).FeTabType) == int32(TABTYP_VTAB) {
|
|
zType = __ccgo_ts + 14302
|
|
} else {
|
|
if (*TTable)(unsafe.Pointer(pTab2)).FtabFlags&uint32(TF_Shadow) != 0 {
|
|
zType = __ccgo_ts + 19340
|
|
} else {
|
|
zType = __ccgo_ts + 9379
|
|
}
|
|
}
|
|
}
|
|
_sqlite3VdbeMultiLoad(tls, v, int32(1), __ccgo_ts+19347, libc.VaList(bp+136, (**(**TDb)(__ccgo_up((*Tsqlite3)(unsafe.Pointer(db)).FaDb + uintptr(ii4)*16))).FzDbSName, _sqlite3PreferredTableName(tls, (*TTable)(unsafe.Pointer(pTab2)).FzName), zType, int32((*TTable)(unsafe.Pointer(pTab2)).FnCol), libc.BoolInt32((*TTable)(unsafe.Pointer(pTab2)).FtabFlags&uint32(TF_WithoutRowid) != uint32(0)), libc.BoolInt32((*TTable)(unsafe.Pointer(pTab2)).FtabFlags&uint32(TF_Strict) != uint32(0))))
|
|
goto _20
|
|
_20:
|
|
;
|
|
k1 = (*THashElem)(unsafe.Pointer(k1)).Fnext
|
|
}
|
|
goto _17
|
|
_17:
|
|
;
|
|
ii4 = ii4 + 1
|
|
}
|
|
case int32(PragTyp_INDEX_INFO):
|
|
if zRight != 0 {
|
|
pIdx = _sqlite3FindIndex(tls, db, zRight, zDb)
|
|
if pIdx == uintptr(0) {
|
|
/* If there is no index named zRight, check to see if there is a
|
|
** WITHOUT ROWID table named zRight, and if there is, show the
|
|
** structure of the PRIMARY KEY index for that table. */
|
|
pTab3 = _sqlite3LocateTable(tls, pParse, uint32(LOCATE_NOERR), zRight, zDb)
|
|
if pTab3 != 0 && !((*TTable)(unsafe.Pointer(pTab3)).FtabFlags&libc.Uint32FromInt32(TF_WithoutRowid) == libc.Uint32FromInt32(0)) {
|
|
pIdx = _sqlite3PrimaryKeyIndex(tls, pTab3)
|
|
}
|
|
}
|
|
if pIdx != 0 {
|
|
iIdxDb = _sqlite3SchemaToIndex(tls, db, (*TIndex)(unsafe.Pointer(pIdx)).FpSchema)
|
|
if (*TPragmaName)(unsafe.Pointer(pPragma)).FiArg != 0 {
|
|
/* PRAGMA index_xinfo (newer version with more rows and columns) */
|
|
mx = libc.Int32FromUint16((*TIndex)(unsafe.Pointer(pIdx)).FnColumn)
|
|
(*TParse)(unsafe.Pointer(pParse)).FnMem = int32(6)
|
|
} else {
|
|
/* PRAGMA index_info (legacy version) */
|
|
mx = libc.Int32FromUint16((*TIndex)(unsafe.Pointer(pIdx)).FnKeyCol)
|
|
(*TParse)(unsafe.Pointer(pParse)).FnMem = int32(3)
|
|
}
|
|
pTab3 = (*TIndex)(unsafe.Pointer(pIdx)).FpTable
|
|
_sqlite3CodeVerifySchema(tls, pParse, iIdxDb)
|
|
i1 = 0
|
|
for {
|
|
if !(i1 < mx) {
|
|
break
|
|
}
|
|
cnum = **(**Ti16)(__ccgo_up((*TIndex)(unsafe.Pointer(pIdx)).FaiColumn + uintptr(i1)*2))
|
|
if int32(cnum) < 0 {
|
|
v1 = uintptr(0)
|
|
} else {
|
|
v1 = (**(**TColumn)(__ccgo_up((*TTable)(unsafe.Pointer(pTab3)).FaCol + uintptr(cnum)*12))).FzCnName
|
|
}
|
|
_sqlite3VdbeMultiLoad(tls, v, int32(1), __ccgo_ts+19354, libc.VaList(bp+136, i1, int32(cnum), v1))
|
|
if (*TPragmaName)(unsafe.Pointer(pPragma)).FiArg != 0 {
|
|
_sqlite3VdbeMultiLoad(tls, v, int32(4), __ccgo_ts+19359, libc.VaList(bp+136, libc.Int32FromUint8(**(**Tu8)(__ccgo_up((*TIndex)(unsafe.Pointer(pIdx)).FaSortOrder + uintptr(i1)))), **(**uintptr)(__ccgo_up((*TIndex)(unsafe.Pointer(pIdx)).FazColl + uintptr(i1)*4)), libc.BoolInt32(i1 < libc.Int32FromUint16((*TIndex)(unsafe.Pointer(pIdx)).FnKeyCol))))
|
|
}
|
|
_sqlite3VdbeAddOp2(tls, v, int32(OP_ResultRow), int32(1), (*TParse)(unsafe.Pointer(pParse)).FnMem)
|
|
goto _21
|
|
_21:
|
|
;
|
|
i1 = i1 + 1
|
|
}
|
|
}
|
|
}
|
|
case int32(PragTyp_INDEX_LIST):
|
|
if zRight != 0 {
|
|
pTab4 = _sqlite3FindTable(tls, db, zRight, zDb)
|
|
if pTab4 != 0 {
|
|
iTabDb = _sqlite3SchemaToIndex(tls, db, (*TTable)(unsafe.Pointer(pTab4)).FpSchema)
|
|
(*TParse)(unsafe.Pointer(pParse)).FnMem = int32(5)
|
|
_sqlite3CodeVerifySchema(tls, pParse, iTabDb)
|
|
pIdx1 = (*TTable)(unsafe.Pointer(pTab4)).FpIndex
|
|
i2 = libc.Int32FromInt32(0)
|
|
for {
|
|
if !(pIdx1 != 0) {
|
|
break
|
|
}
|
|
azOrigin = [3]uintptr{
|
|
0: __ccgo_ts + 19364,
|
|
1: __ccgo_ts + 19366,
|
|
2: __ccgo_ts + 17853,
|
|
}
|
|
_sqlite3VdbeMultiLoad(tls, v, int32(1), __ccgo_ts+19368, libc.VaList(bp+136, i2, (*TIndex)(unsafe.Pointer(pIdx1)).FzName, libc.BoolInt32(libc.Int32FromUint8((*TIndex)(unsafe.Pointer(pIdx1)).FonError) != OE_None), azOrigin[int32(uint32(*(*uint16)(unsafe.Pointer(pIdx1 + 56))&0x3>>0))], libc.BoolInt32((*TIndex)(unsafe.Pointer(pIdx1)).FpPartIdxWhere != uintptr(0))))
|
|
goto _23
|
|
_23:
|
|
;
|
|
pIdx1 = (*TIndex)(unsafe.Pointer(pIdx1)).FpNext
|
|
i2 = i2 + 1
|
|
}
|
|
}
|
|
}
|
|
case int32(PragTyp_DATABASE_LIST):
|
|
(*TParse)(unsafe.Pointer(pParse)).FnMem = int32(3)
|
|
i3 = 0
|
|
for {
|
|
if !(i3 < (*Tsqlite3)(unsafe.Pointer(db)).FnDb) {
|
|
break
|
|
}
|
|
if (**(**TDb)(__ccgo_up((*Tsqlite3)(unsafe.Pointer(db)).FaDb + uintptr(i3)*16))).FpBt == uintptr(0) {
|
|
goto _24
|
|
}
|
|
_sqlite3VdbeMultiLoad(tls, v, int32(1), __ccgo_ts+19374, libc.VaList(bp+136, i3, (**(**TDb)(__ccgo_up((*Tsqlite3)(unsafe.Pointer(db)).FaDb + uintptr(i3)*16))).FzDbSName, _sqlite3BtreeGetFilename(tls, (**(**TDb)(__ccgo_up((*Tsqlite3)(unsafe.Pointer(db)).FaDb + uintptr(i3)*16))).FpBt)))
|
|
goto _24
|
|
_24:
|
|
;
|
|
i3 = i3 + 1
|
|
}
|
|
case int32(PragTyp_COLLATION_LIST):
|
|
i4 = 0
|
|
(*TParse)(unsafe.Pointer(pParse)).FnMem = int32(2)
|
|
p = (*THash)(unsafe.Pointer(db + 444)).Ffirst
|
|
for {
|
|
if !(p != 0) {
|
|
break
|
|
}
|
|
pColl = (*THashElem)(unsafe.Pointer(p)).Fdata
|
|
v2 = i4
|
|
i4 = i4 + 1
|
|
_sqlite3VdbeMultiLoad(tls, v, int32(1), __ccgo_ts+19378, libc.VaList(bp+136, v2, (*TCollSeq)(unsafe.Pointer(pColl)).FzName))
|
|
goto _25
|
|
_25:
|
|
;
|
|
p = (*THashElem)(unsafe.Pointer(p)).Fnext
|
|
}
|
|
case int32(PragTyp_FUNCTION_LIST):
|
|
showInternFunc = libc.BoolInt32((*Tsqlite3)(unsafe.Pointer(db)).FmDbFlags&uint32(DBFLAG_InternalFunc) != uint32(0))
|
|
(*TParse)(unsafe.Pointer(pParse)).FnMem = int32(6)
|
|
i5 = 0
|
|
for {
|
|
if !(i5 < int32(SQLITE_FUNC_HASH_SZ)) {
|
|
break
|
|
}
|
|
p1 = **(**uintptr)(__ccgo_up(uintptr(unsafe.Pointer(&_sqlite3BuiltinFunctions)) + uintptr(i5)*4))
|
|
for {
|
|
if !(p1 != 0) {
|
|
break
|
|
}
|
|
_pragmaFunclistLine(tls, v, p1, int32(1), showInternFunc)
|
|
goto _28
|
|
_28:
|
|
;
|
|
p1 = *(*uintptr)(unsafe.Pointer(p1 + 36))
|
|
}
|
|
goto _27
|
|
_27:
|
|
;
|
|
i5 = i5 + 1
|
|
}
|
|
j = (*THash)(unsafe.Pointer(db + 428)).Ffirst
|
|
for {
|
|
if !(j != 0) {
|
|
break
|
|
}
|
|
p1 = (*THashElem)(unsafe.Pointer(j)).Fdata
|
|
_pragmaFunclistLine(tls, v, p1, 0, showInternFunc)
|
|
goto _29
|
|
_29:
|
|
;
|
|
j = (*THashElem)(unsafe.Pointer(j)).Fnext
|
|
}
|
|
case int32(PragTyp_MODULE_LIST):
|
|
(*TParse)(unsafe.Pointer(pParse)).FnMem = int32(1)
|
|
j1 = (*THash)(unsafe.Pointer(db + 400)).Ffirst
|
|
for {
|
|
if !(j1 != 0) {
|
|
break
|
|
}
|
|
pMod = (*THashElem)(unsafe.Pointer(j1)).Fdata
|
|
_sqlite3VdbeMultiLoad(tls, v, int32(1), __ccgo_ts+7911, libc.VaList(bp+136, (*TModule)(unsafe.Pointer(pMod)).FzName))
|
|
goto _30
|
|
_30:
|
|
;
|
|
j1 = (*THashElem)(unsafe.Pointer(j1)).Fnext
|
|
}
|
|
case int32(PragTyp_PRAGMA_LIST):
|
|
i6 = 0
|
|
for {
|
|
if !(i6 < libc.Int32FromUint32(libc.Uint32FromInt64(1056)/libc.Uint32FromInt64(16))) {
|
|
break
|
|
}
|
|
_sqlite3VdbeMultiLoad(tls, v, int32(1), __ccgo_ts+7911, libc.VaList(bp+136, _aPragmaName[i6].FzName))
|
|
goto _31
|
|
_31:
|
|
;
|
|
i6 = i6 + 1
|
|
}
|
|
case int32(PragTyp_FOREIGN_KEY_LIST):
|
|
if zRight != 0 {
|
|
pTab5 = _sqlite3FindTable(tls, db, zRight, zDb)
|
|
if pTab5 != 0 && libc.Int32FromUint8((*TTable)(unsafe.Pointer(pTab5)).FeTabType) == TABTYP_NORM {
|
|
pFK = (*(*struct {
|
|
FaddColOffset int32
|
|
FpFKey uintptr
|
|
FpDfltList uintptr
|
|
})(unsafe.Pointer(pTab5 + 44))).FpFKey
|
|
if pFK != 0 {
|
|
iTabDb1 = _sqlite3SchemaToIndex(tls, db, (*TTable)(unsafe.Pointer(pTab5)).FpSchema)
|
|
i7 = 0
|
|
(*TParse)(unsafe.Pointer(pParse)).FnMem = int32(8)
|
|
_sqlite3CodeVerifySchema(tls, pParse, iTabDb1)
|
|
for pFK != 0 {
|
|
j2 = 0
|
|
for {
|
|
if !(j2 < (*TFKey)(unsafe.Pointer(pFK)).FnCol) {
|
|
break
|
|
}
|
|
_sqlite3VdbeMultiLoad(tls, v, int32(1), __ccgo_ts+19381, libc.VaList(bp+136, i7, j2, (*TFKey)(unsafe.Pointer(pFK)).FzTo, (**(**TColumn)(__ccgo_up((*TTable)(unsafe.Pointer(pTab5)).FaCol + uintptr((*(*TsColMap)(unsafe.Pointer(pFK + 36 + uintptr(j2)*8))).FiFrom)*12))).FzCnName, (*(*TsColMap)(unsafe.Pointer(pFK + 36 + uintptr(j2)*8))).FzCol, _actionName(tls, **(**Tu8)(__ccgo_up(pFK + 25 + 1))), _actionName(tls, **(**Tu8)(__ccgo_up(pFK + 25))), __ccgo_ts+19390))
|
|
goto _32
|
|
_32:
|
|
;
|
|
j2 = j2 + 1
|
|
}
|
|
i7 = i7 + 1
|
|
pFK = (*TFKey)(unsafe.Pointer(pFK)).FpNextFrom
|
|
}
|
|
}
|
|
}
|
|
}
|
|
case int32(PragTyp_FOREIGN_KEY_CHECK): /* child to parent column mapping */
|
|
regResult = (*TParse)(unsafe.Pointer(pParse)).FnMem + int32(1)
|
|
**(**int32)(__ccgo_up(pParse + 48)) += int32(4)
|
|
v1 = pParse + 48
|
|
*(*int32)(unsafe.Pointer(v1)) = *(*int32)(unsafe.Pointer(v1)) + 1
|
|
v2 = *(*int32)(unsafe.Pointer(v1))
|
|
regRow = v2
|
|
k2 = (*THash)(unsafe.Pointer((**(**TDb)(__ccgo_up((*Tsqlite3)(unsafe.Pointer(db)).FaDb + uintptr(iDb)*16))).FpSchema + 8)).Ffirst
|
|
for k2 != 0 {
|
|
if zRight != 0 {
|
|
pTab6 = _sqlite3LocateTable(tls, pParse, uint32(0), zRight, zDb)
|
|
k2 = uintptr(0)
|
|
} else {
|
|
pTab6 = (*THashElem)(unsafe.Pointer(k2)).Fdata
|
|
k2 = (*THashElem)(unsafe.Pointer(k2)).Fnext
|
|
}
|
|
if pTab6 == uintptr(0) || !(libc.Int32FromUint8((*TTable)(unsafe.Pointer(pTab6)).FeTabType) == libc.Int32FromInt32(TABTYP_NORM)) || (*(*struct {
|
|
FaddColOffset int32
|
|
FpFKey uintptr
|
|
FpDfltList uintptr
|
|
})(unsafe.Pointer(pTab6 + 44))).FpFKey == uintptr(0) {
|
|
continue
|
|
}
|
|
iDb = _sqlite3SchemaToIndex(tls, db, (*TTable)(unsafe.Pointer(pTab6)).FpSchema)
|
|
zDb = (**(**TDb)(__ccgo_up((*Tsqlite3)(unsafe.Pointer(db)).FaDb + uintptr(iDb)*16))).FzDbSName
|
|
_sqlite3CodeVerifySchema(tls, pParse, iDb)
|
|
_sqlite3TableLock(tls, pParse, iDb, (*TTable)(unsafe.Pointer(pTab6)).Ftnum, uint8(0), (*TTable)(unsafe.Pointer(pTab6)).FzName)
|
|
_sqlite3TouchRegister(tls, pParse, int32((*TTable)(unsafe.Pointer(pTab6)).FnCol)+regRow)
|
|
_sqlite3OpenTable(tls, pParse, 0, iDb, pTab6, int32(OP_OpenRead))
|
|
_sqlite3VdbeLoadString(tls, v, regResult, (*TTable)(unsafe.Pointer(pTab6)).FzName)
|
|
i8 = int32(1)
|
|
pFK1 = (*(*struct {
|
|
FaddColOffset int32
|
|
FpFKey uintptr
|
|
FpDfltList uintptr
|
|
})(unsafe.Pointer(pTab6 + 44))).FpFKey
|
|
for {
|
|
if !(pFK1 != 0) {
|
|
break
|
|
}
|
|
pParent = _sqlite3FindTable(tls, db, (*TFKey)(unsafe.Pointer(pFK1)).FzTo, zDb)
|
|
if pParent == uintptr(0) {
|
|
goto _35
|
|
}
|
|
**(**uintptr)(__ccgo_up(bp + 64)) = uintptr(0)
|
|
_sqlite3TableLock(tls, pParse, iDb, (*TTable)(unsafe.Pointer(pParent)).Ftnum, uint8(0), (*TTable)(unsafe.Pointer(pParent)).FzName)
|
|
x1 = _sqlite3FkLocateIndex(tls, pParse, pParent, pFK1, bp+64, uintptr(0))
|
|
if x1 == 0 {
|
|
if **(**uintptr)(__ccgo_up(bp + 64)) == uintptr(0) {
|
|
_sqlite3OpenTable(tls, pParse, i8, iDb, pParent, int32(OP_OpenRead))
|
|
} else {
|
|
_sqlite3VdbeAddOp3(tls, v, int32(OP_OpenRead), i8, libc.Int32FromUint32((*TIndex)(unsafe.Pointer(**(**uintptr)(__ccgo_up(bp + 64)))).Ftnum), iDb)
|
|
_sqlite3VdbeSetP4KeyInfo(tls, pParse, **(**uintptr)(__ccgo_up(bp + 64)))
|
|
}
|
|
} else {
|
|
k2 = uintptr(0)
|
|
break
|
|
}
|
|
goto _35
|
|
_35:
|
|
;
|
|
i8 = i8 + 1
|
|
pFK1 = (*TFKey)(unsafe.Pointer(pFK1)).FpNextFrom
|
|
}
|
|
if pFK1 != 0 {
|
|
break
|
|
}
|
|
if (*TParse)(unsafe.Pointer(pParse)).FnTab < i8 {
|
|
(*TParse)(unsafe.Pointer(pParse)).FnTab = i8
|
|
}
|
|
addrTop = _sqlite3VdbeAddOp1(tls, v, int32(OP_Rewind), 0)
|
|
i8 = int32(1)
|
|
pFK1 = (*(*struct {
|
|
FaddColOffset int32
|
|
FpFKey uintptr
|
|
FpDfltList uintptr
|
|
})(unsafe.Pointer(pTab6 + 44))).FpFKey
|
|
for {
|
|
if !(pFK1 != 0) {
|
|
break
|
|
}
|
|
pParent = _sqlite3FindTable(tls, db, (*TFKey)(unsafe.Pointer(pFK1)).FzTo, zDb)
|
|
**(**uintptr)(__ccgo_up(bp + 64)) = uintptr(0)
|
|
**(**uintptr)(__ccgo_up(bp + 68)) = uintptr(0)
|
|
if pParent != 0 {
|
|
x1 = _sqlite3FkLocateIndex(tls, pParse, pParent, pFK1, bp+64, bp+68)
|
|
}
|
|
addrOk = _sqlite3VdbeMakeLabel(tls, pParse)
|
|
/* Generate code to read the child key values into registers
|
|
** regRow..regRow+n. If any of the child key values are NULL, this
|
|
** row cannot cause an FK violation. Jump directly to addrOk in
|
|
** this case. */
|
|
_sqlite3TouchRegister(tls, pParse, regRow+(*TFKey)(unsafe.Pointer(pFK1)).FnCol)
|
|
j3 = 0
|
|
for {
|
|
if !(j3 < (*TFKey)(unsafe.Pointer(pFK1)).FnCol) {
|
|
break
|
|
}
|
|
if **(**uintptr)(__ccgo_up(bp + 68)) != 0 {
|
|
v2 = **(**int32)(__ccgo_up(**(**uintptr)(__ccgo_up(bp + 68)) + uintptr(j3)*4))
|
|
} else {
|
|
v2 = (*(*TsColMap)(unsafe.Pointer(pFK1 + 36 + uintptr(j3)*8))).FiFrom
|
|
}
|
|
iCol = v2
|
|
_sqlite3ExprCodeGetColumnOfTable(tls, v, pTab6, 0, iCol, regRow+j3)
|
|
_sqlite3VdbeAddOp2(tls, v, int32(OP_IsNull), regRow+j3, addrOk)
|
|
goto _37
|
|
_37:
|
|
;
|
|
j3 = j3 + 1
|
|
}
|
|
/* Generate code to query the parent index for a matching parent
|
|
** key. If a match is found, jump to addrOk. */
|
|
if **(**uintptr)(__ccgo_up(bp + 64)) != 0 {
|
|
_sqlite3VdbeAddOp4(tls, v, int32(OP_Affinity), regRow, (*TFKey)(unsafe.Pointer(pFK1)).FnCol, 0, _sqlite3IndexAffinityStr(tls, db, **(**uintptr)(__ccgo_up(bp + 64))), (*TFKey)(unsafe.Pointer(pFK1)).FnCol)
|
|
_sqlite3VdbeAddOp4Int(tls, v, int32(OP_Found), i8, addrOk, regRow, (*TFKey)(unsafe.Pointer(pFK1)).FnCol)
|
|
} else {
|
|
if pParent != 0 {
|
|
jmp = _sqlite3VdbeCurrentAddr(tls, v) + int32(2)
|
|
_sqlite3VdbeAddOp3(tls, v, int32(OP_SeekRowid), i8, jmp, regRow)
|
|
_sqlite3VdbeGoto(tls, v, addrOk)
|
|
}
|
|
}
|
|
/* Generate code to report an FK violation to the caller. */
|
|
if (*TTable)(unsafe.Pointer(pTab6)).FtabFlags&uint32(TF_WithoutRowid) == uint32(0) {
|
|
_sqlite3VdbeAddOp2(tls, v, int32(OP_Rowid), 0, regResult+int32(1))
|
|
} else {
|
|
_sqlite3VdbeAddOp2(tls, v, int32(OP_Null), 0, regResult+int32(1))
|
|
}
|
|
_sqlite3VdbeMultiLoad(tls, v, regResult+int32(2), __ccgo_ts+19395, libc.VaList(bp+136, (*TFKey)(unsafe.Pointer(pFK1)).FzTo, i8-int32(1)))
|
|
_sqlite3VdbeAddOp2(tls, v, int32(OP_ResultRow), regResult, int32(4))
|
|
_sqlite3VdbeResolveLabel(tls, v, addrOk)
|
|
_sqlite3DbFree(tls, db, **(**uintptr)(__ccgo_up(bp + 68)))
|
|
goto _36
|
|
_36:
|
|
;
|
|
i8 = i8 + 1
|
|
pFK1 = (*TFKey)(unsafe.Pointer(pFK1)).FpNextFrom
|
|
}
|
|
_sqlite3VdbeAddOp2(tls, v, int32(OP_Next), 0, addrTop+int32(1))
|
|
_sqlite3VdbeJumpHere(tls, v, addrTop)
|
|
}
|
|
break
|
|
/* Reinstall the LIKE and GLOB functions. The variant of LIKE
|
|
** used will be case sensitive or not depending on the RHS.
|
|
*/
|
|
fallthrough
|
|
case int32(PragTyp_CASE_SENSITIVE_LIKE):
|
|
if zRight != 0 {
|
|
_sqlite3RegisterLikeFunctions(tls, db, libc.Int32FromUint8(_sqlite3GetBoolean(tls, zRight, uint8(0))))
|
|
}
|
|
break
|
|
/* PRAGMA integrity_check
|
|
** PRAGMA integrity_check(N)
|
|
** PRAGMA quick_check
|
|
** PRAGMA quick_check(N)
|
|
**
|
|
** Verify the integrity of the database.
|
|
**
|
|
** The "quick_check" is reduced version of
|
|
** integrity_check designed to detect most database corruption
|
|
** without the overhead of cross-checking indexes. Quick_check
|
|
** is linear time whereas integrity_check is O(NlogN).
|
|
**
|
|
** The maximum number of errors is 100 by default. A different default
|
|
** can be specified using a numeric parameter N.
|
|
**
|
|
** Or, the parameter N can be the name of a table. In that case, only
|
|
** the one table named is verified. The freelist is only verified if
|
|
** the named table is "sqlite_schema" (or one of its aliases).
|
|
**
|
|
** All schemas are checked by default. To check just a single
|
|
** schema, use the form:
|
|
**
|
|
** PRAGMA schema.integrity_check;
|
|
*/
|
|
fallthrough
|
|
case int32(PragTyp_INTEGRITY_CHECK):
|
|
pObjTab = uintptr(0) /* Check only this one table, if not NULL */
|
|
isQuick = libc.BoolInt32(libc.Int32FromUint8(_sqlite3UpperToLower[libc.Uint8FromInt8(**(**int8)(__ccgo_up(zLeft)))]) == int32('q'))
|
|
/* If the PRAGMA command was of the form "PRAGMA <db>.integrity_check",
|
|
** then iDb is set to the index of the database identified by <db>.
|
|
** In this case, the integrity of database iDb only is verified by
|
|
** the VDBE created below.
|
|
**
|
|
** Otherwise, if the command was simply "PRAGMA integrity_check" (or
|
|
** "PRAGMA quick_check"), then iDb is set to 0. In this case, set iDb
|
|
** to -1 here, to indicate that the VDBE should verify the integrity
|
|
** of all attached databases. */
|
|
if (*TToken)(unsafe.Pointer(pId2)).Fz == uintptr(0) {
|
|
iDb = -int32(1)
|
|
}
|
|
/* Initialize the VDBE program */
|
|
(*TParse)(unsafe.Pointer(pParse)).FnMem = int32(6)
|
|
/* Set the maximum error count */
|
|
**(**int32)(__ccgo_up(bp + 72)) = int32(SQLITE_INTEGRITY_CHECK_ERROR_MAX)
|
|
if zRight != 0 {
|
|
if _sqlite3GetInt32(tls, (*TToken)(unsafe.Pointer(pValue)).Fz, bp+72) != 0 {
|
|
if **(**int32)(__ccgo_up(bp + 72)) <= 0 {
|
|
**(**int32)(__ccgo_up(bp + 72)) = int32(SQLITE_INTEGRITY_CHECK_ERROR_MAX)
|
|
}
|
|
} else {
|
|
if iDb >= 0 {
|
|
v1 = (**(**TDb)(__ccgo_up((*Tsqlite3)(unsafe.Pointer(db)).FaDb + uintptr(iDb)*16))).FzDbSName
|
|
} else {
|
|
v1 = uintptr(0)
|
|
}
|
|
pObjTab = _sqlite3LocateTable(tls, pParse, uint32(0), zRight, v1)
|
|
}
|
|
}
|
|
_sqlite3VdbeAddOp2(tls, v, int32(OP_Integer), **(**int32)(__ccgo_up(bp + 72))-int32(1), int32(1)) /* reg[1] holds errors left */
|
|
/* Do an integrity check on each database file */
|
|
i9 = 0
|
|
for {
|
|
if !(i9 < (*Tsqlite3)(unsafe.Pointer(db)).FnDb) {
|
|
break
|
|
} /* Array of root page numbers of all btrees */
|
|
cnt = 0 /* Number of entries in aRoot[] */
|
|
if libc.Bool(OMIT_TEMPDB != 0) && i9 == int32(1) {
|
|
goto _40
|
|
}
|
|
if iDb >= 0 && i9 != iDb {
|
|
goto _40
|
|
}
|
|
_sqlite3CodeVerifySchema(tls, pParse, i9)
|
|
libc.SetBitFieldPtr16Uint32(pParse+28, libc.Uint32FromInt32(0), 7, 0x80) /* tag-20230327-1 */
|
|
/* Do an integrity check of the B-Tree
|
|
**
|
|
** Begin by finding the root pages numbers
|
|
** for all tables and indices in the database.
|
|
*/
|
|
pTbls = (**(**TDb)(__ccgo_up((*Tsqlite3)(unsafe.Pointer(db)).FaDb + uintptr(i9)*16))).FpSchema + 8
|
|
cnt = 0
|
|
x2 = (*THash)(unsafe.Pointer(pTbls)).Ffirst
|
|
for {
|
|
if !(x2 != 0) {
|
|
break
|
|
}
|
|
pTab7 = (*THashElem)(unsafe.Pointer(x2)).Fdata /* Number of indexes on pTab */
|
|
if _tableSkipIntegrityCheck(tls, pTab7, pObjTab) != 0 {
|
|
goto _41
|
|
}
|
|
if (*TTable)(unsafe.Pointer(pTab7)).FtabFlags&uint32(TF_WithoutRowid) == uint32(0) {
|
|
cnt = cnt + 1
|
|
}
|
|
nIdx = 0
|
|
pIdx3 = (*TTable)(unsafe.Pointer(pTab7)).FpIndex
|
|
for {
|
|
if !(pIdx3 != 0) {
|
|
break
|
|
}
|
|
cnt = cnt + 1
|
|
goto _42
|
|
_42:
|
|
;
|
|
pIdx3 = (*TIndex)(unsafe.Pointer(pIdx3)).FpNext
|
|
nIdx = nIdx + 1
|
|
}
|
|
goto _41
|
|
_41:
|
|
;
|
|
x2 = (*THashElem)(unsafe.Pointer(x2)).Fnext
|
|
}
|
|
if cnt == 0 {
|
|
goto _40
|
|
}
|
|
if pObjTab != 0 {
|
|
cnt = cnt + 1
|
|
}
|
|
aRoot = _sqlite3DbMallocRawNN(tls, db, uint64(uint32(4)*libc.Uint32FromInt32(cnt+libc.Int32FromInt32(1))))
|
|
if aRoot == uintptr(0) {
|
|
break
|
|
}
|
|
cnt = 0
|
|
if pObjTab != 0 {
|
|
cnt = cnt + 1
|
|
v2 = cnt
|
|
**(**int32)(__ccgo_up(aRoot + uintptr(v2)*4)) = 0
|
|
}
|
|
x2 = (*THash)(unsafe.Pointer(pTbls)).Ffirst
|
|
for {
|
|
if !(x2 != 0) {
|
|
break
|
|
}
|
|
pTab8 = (*THashElem)(unsafe.Pointer(x2)).Fdata
|
|
if _tableSkipIntegrityCheck(tls, pTab8, pObjTab) != 0 {
|
|
goto _44
|
|
}
|
|
if (*TTable)(unsafe.Pointer(pTab8)).FtabFlags&uint32(TF_WithoutRowid) == uint32(0) {
|
|
cnt = cnt + 1
|
|
v2 = cnt
|
|
**(**int32)(__ccgo_up(aRoot + uintptr(v2)*4)) = libc.Int32FromUint32((*TTable)(unsafe.Pointer(pTab8)).Ftnum)
|
|
}
|
|
pIdx4 = (*TTable)(unsafe.Pointer(pTab8)).FpIndex
|
|
for {
|
|
if !(pIdx4 != 0) {
|
|
break
|
|
}
|
|
cnt = cnt + 1
|
|
v2 = cnt
|
|
**(**int32)(__ccgo_up(aRoot + uintptr(v2)*4)) = libc.Int32FromUint32((*TIndex)(unsafe.Pointer(pIdx4)).Ftnum)
|
|
goto _46
|
|
_46:
|
|
;
|
|
pIdx4 = (*TIndex)(unsafe.Pointer(pIdx4)).FpNext
|
|
}
|
|
goto _44
|
|
_44:
|
|
;
|
|
x2 = (*THashElem)(unsafe.Pointer(x2)).Fnext
|
|
}
|
|
**(**int32)(__ccgo_up(aRoot)) = cnt
|
|
/* Make sure sufficient number of registers have been allocated */
|
|
_sqlite3TouchRegister(tls, pParse, int32(8)+cnt)
|
|
_sqlite3VdbeAddOp3(tls, v, int32(OP_Null), 0, int32(8), int32(8)+cnt)
|
|
_sqlite3ClearTempRegCache(tls, pParse)
|
|
/* Do the b-tree integrity checks */
|
|
_sqlite3VdbeAddOp4(tls, v, int32(OP_IntegrityCk), int32(1), cnt, int32(8), aRoot, -int32(15))
|
|
_sqlite3VdbeChangeP5(tls, v, libc.Uint16FromInt32(i9))
|
|
addr1 = _sqlite3VdbeAddOp1(tls, v, int32(OP_IsNull), int32(2))
|
|
_sqlite3VdbeAddOp4(tls, v, int32(OP_String8), 0, int32(3), 0, _sqlite3MPrintf(tls, db, __ccgo_ts+19399, libc.VaList(bp+136, (**(**TDb)(__ccgo_up((*Tsqlite3)(unsafe.Pointer(db)).FaDb + uintptr(i9)*16))).FzDbSName)), -int32(7))
|
|
_sqlite3VdbeAddOp3(tls, v, int32(OP_Concat), int32(2), int32(3), int32(3))
|
|
_integrityCheckResultRow(tls, v)
|
|
_sqlite3VdbeJumpHere(tls, v, addr1)
|
|
/* Check that the indexes all have the right number of rows */
|
|
if pObjTab != 0 {
|
|
v2 = int32(1)
|
|
} else {
|
|
v2 = 0
|
|
}
|
|
cnt = v2
|
|
_sqlite3VdbeLoadString(tls, v, int32(2), __ccgo_ts+19423)
|
|
x2 = (*THash)(unsafe.Pointer(pTbls)).Ffirst
|
|
for {
|
|
if !(x2 != 0) {
|
|
break
|
|
}
|
|
iTab = 0
|
|
pTab9 = (*THashElem)(unsafe.Pointer(x2)).Fdata
|
|
if _tableSkipIntegrityCheck(tls, pTab9, pObjTab) != 0 {
|
|
goto _49
|
|
}
|
|
if (*TTable)(unsafe.Pointer(pTab9)).FtabFlags&uint32(TF_WithoutRowid) == uint32(0) {
|
|
v2 = cnt
|
|
cnt = cnt + 1
|
|
iTab = v2
|
|
} else {
|
|
iTab = cnt
|
|
pIdx5 = (*TTable)(unsafe.Pointer(pTab9)).FpIndex
|
|
for {
|
|
if !(pIdx5 != 0) {
|
|
break
|
|
}
|
|
if int32(uint32(*(*uint16)(unsafe.Pointer(pIdx5 + 56))&0x3>>0)) == int32(SQLITE_IDXTYPE_PRIMARYKEY) {
|
|
break
|
|
}
|
|
iTab = iTab + 1
|
|
goto _51
|
|
_51:
|
|
;
|
|
pIdx5 = (*TIndex)(unsafe.Pointer(pIdx5)).FpNext
|
|
}
|
|
}
|
|
pIdx5 = (*TTable)(unsafe.Pointer(pTab9)).FpIndex
|
|
for {
|
|
if !(pIdx5 != 0) {
|
|
break
|
|
}
|
|
if (*TIndex)(unsafe.Pointer(pIdx5)).FpPartIdxWhere == uintptr(0) {
|
|
addr1 = _sqlite3VdbeAddOp3(tls, v, int32(OP_Eq), int32(8)+cnt, 0, int32(8)+iTab)
|
|
_sqlite3VdbeLoadString(tls, v, int32(4), (*TIndex)(unsafe.Pointer(pIdx5)).FzName)
|
|
_sqlite3VdbeAddOp3(tls, v, int32(OP_Concat), int32(4), int32(2), int32(3))
|
|
_integrityCheckResultRow(tls, v)
|
|
_sqlite3VdbeJumpHere(tls, v, addr1)
|
|
}
|
|
cnt = cnt + 1
|
|
goto _52
|
|
_52:
|
|
;
|
|
pIdx5 = (*TIndex)(unsafe.Pointer(pIdx5)).FpNext
|
|
}
|
|
goto _49
|
|
_49:
|
|
;
|
|
x2 = (*THashElem)(unsafe.Pointer(x2)).Fnext
|
|
}
|
|
/* Make sure all the indices are constructed correctly.
|
|
*/
|
|
x2 = (*THash)(unsafe.Pointer(pTbls)).Ffirst
|
|
for {
|
|
if !(x2 != 0) {
|
|
break
|
|
}
|
|
pTab10 = (*THashElem)(unsafe.Pointer(x2)).Fdata
|
|
pPrior = uintptr(0)
|
|
r1 = -int32(1) /* Maximum non-virtual column number */
|
|
if _tableSkipIntegrityCheck(tls, pTab10, pObjTab) != 0 {
|
|
goto _53
|
|
}
|
|
if !(libc.Int32FromUint8((*TTable)(unsafe.Pointer(pTab10)).FeTabType) == libc.Int32FromInt32(TABTYP_NORM)) {
|
|
goto _53
|
|
}
|
|
if isQuick != 0 || (*TTable)(unsafe.Pointer(pTab10)).FtabFlags&uint32(TF_WithoutRowid) == uint32(0) {
|
|
pPk1 = uintptr(0)
|
|
r2 = 0
|
|
} else {
|
|
pPk1 = _sqlite3PrimaryKeyIndex(tls, pTab10)
|
|
r2 = _sqlite3GetTempRange(tls, pParse, libc.Int32FromUint16((*TIndex)(unsafe.Pointer(pPk1)).FnKeyCol))
|
|
_sqlite3VdbeAddOp3(tls, v, int32(OP_Null), int32(1), r2, r2+libc.Int32FromUint16((*TIndex)(unsafe.Pointer(pPk1)).FnKeyCol)-int32(1))
|
|
}
|
|
_sqlite3OpenTableAndIndices(tls, pParse, pTab10, int32(OP_OpenRead), uint8(0), int32(1), uintptr(0), bp+76, bp+80)
|
|
/* reg[7] counts the number of entries in the table.
|
|
** reg[8+i] counts the number of entries in the i-th index
|
|
*/
|
|
_sqlite3VdbeAddOp2(tls, v, int32(OP_Integer), 0, int32(7))
|
|
j4 = 0
|
|
pIdx6 = (*TTable)(unsafe.Pointer(pTab10)).FpIndex
|
|
for {
|
|
if !(pIdx6 != 0) {
|
|
break
|
|
}
|
|
_sqlite3VdbeAddOp2(tls, v, int32(OP_Integer), 0, int32(8)+j4) /* index entries counter */
|
|
goto _54
|
|
_54:
|
|
;
|
|
pIdx6 = (*TIndex)(unsafe.Pointer(pIdx6)).FpNext
|
|
j4 = j4 + 1
|
|
}
|
|
_sqlite3VdbeAddOp2(tls, v, int32(OP_Rewind), **(**int32)(__ccgo_up(bp + 76)), 0)
|
|
loopTop = _sqlite3VdbeAddOp2(tls, v, int32(OP_AddImm), int32(7), int32(1))
|
|
/* Fetch the right-most column from the table. This will cause
|
|
** the entire record header to be parsed and sanity checked. It
|
|
** will also prepopulate the cursor column cache that is used
|
|
** by the OP_IsType code, so it is a required step.
|
|
*/
|
|
if (*TTable)(unsafe.Pointer(pTab10)).FtabFlags&uint32(TF_WithoutRowid) == uint32(0) {
|
|
mxCol = -int32(1)
|
|
j4 = 0
|
|
for {
|
|
if !(j4 < int32((*TTable)(unsafe.Pointer(pTab10)).FnCol)) {
|
|
break
|
|
}
|
|
if libc.Int32FromUint16((**(**TColumn)(__ccgo_up((*TTable)(unsafe.Pointer(pTab10)).FaCol + uintptr(j4)*12))).FcolFlags)&int32(COLFLAG_VIRTUAL) == 0 {
|
|
mxCol = mxCol + 1
|
|
}
|
|
goto _55
|
|
_55:
|
|
;
|
|
j4 = j4 + 1
|
|
}
|
|
if mxCol == int32((*TTable)(unsafe.Pointer(pTab10)).FiPKey) {
|
|
mxCol = mxCol - 1
|
|
}
|
|
} else {
|
|
/* COLFLAG_VIRTUAL columns are not included in the WITHOUT ROWID
|
|
** PK index column-count, so there is no need to account for them
|
|
** in this case. */
|
|
mxCol = libc.Int32FromUint16((*TIndex)(unsafe.Pointer(_sqlite3PrimaryKeyIndex(tls, pTab10))).FnColumn) - int32(1)
|
|
}
|
|
if mxCol >= 0 {
|
|
_sqlite3VdbeAddOp3(tls, v, int32(OP_Column), **(**int32)(__ccgo_up(bp + 76)), mxCol, int32(3))
|
|
_sqlite3VdbeTypeofColumn(tls, v, int32(3))
|
|
}
|
|
if !(isQuick != 0) {
|
|
if pPk1 != 0 {
|
|
a1 = _sqlite3VdbeAddOp4Int(tls, v, int32(OP_IdxGT), **(**int32)(__ccgo_up(bp + 76)), 0, r2, libc.Int32FromUint16((*TIndex)(unsafe.Pointer(pPk1)).FnKeyCol))
|
|
_sqlite3VdbeAddOp1(tls, v, int32(OP_IsNull), r2)
|
|
zErr = _sqlite3MPrintf(tls, db, __ccgo_ts+19452, libc.VaList(bp+136, (*TTable)(unsafe.Pointer(pTab10)).FzName))
|
|
_sqlite3VdbeAddOp4(tls, v, int32(OP_String8), 0, int32(3), 0, zErr, -int32(7))
|
|
_integrityCheckResultRow(tls, v)
|
|
_sqlite3VdbeJumpHere(tls, v, a1)
|
|
_sqlite3VdbeJumpHere(tls, v, a1+int32(1))
|
|
j4 = 0
|
|
for {
|
|
if !(j4 < libc.Int32FromUint16((*TIndex)(unsafe.Pointer(pPk1)).FnKeyCol)) {
|
|
break
|
|
}
|
|
_sqlite3ExprCodeLoadIndexColumn(tls, pParse, pPk1, **(**int32)(__ccgo_up(bp + 76)), j4, r2+j4)
|
|
goto _56
|
|
_56:
|
|
;
|
|
j4 = j4 + 1
|
|
}
|
|
}
|
|
}
|
|
/* Verify datatypes for all columns:
|
|
**
|
|
** (1) NOT NULL columns may not contain a NULL
|
|
** (2) Datatype must be exact for non-ANY columns in STRICT tables
|
|
** (3) Datatype for TEXT columns in non-STRICT tables must be
|
|
** NULL, TEXT, or BLOB.
|
|
** (4) Datatype for numeric columns in non-STRICT tables must not
|
|
** be a TEXT value that can be losslessly converted to numeric.
|
|
*/
|
|
bStrict = libc.BoolInt32((*TTable)(unsafe.Pointer(pTab10)).FtabFlags&uint32(TF_Strict) != uint32(0))
|
|
j4 = 0
|
|
for {
|
|
if !(j4 < int32((*TTable)(unsafe.Pointer(pTab10)).FnCol)) {
|
|
break
|
|
}
|
|
pCol1 = (*TTable)(unsafe.Pointer(pTab10)).FaCol + uintptr(j4)*12 /* Check datatypes (besides NOT NULL) */
|
|
if j4 == int32((*TTable)(unsafe.Pointer(pTab10)).FiPKey) {
|
|
goto _57
|
|
}
|
|
if bStrict != 0 {
|
|
doTypeCheck = libc.BoolInt32(int32(uint32(*(*uint8)(unsafe.Pointer(pCol1 + 4))&0xf0>>4)) > int32(COLTYPE_ANY))
|
|
} else {
|
|
doTypeCheck = libc.BoolInt32(int32((*TColumn)(unsafe.Pointer(pCol1)).Faffinity) > int32(SQLITE_AFF_BLOB))
|
|
}
|
|
if int32(uint32(*(*uint8)(unsafe.Pointer(pCol1 + 4))&0xf>>0)) == 0 && !(doTypeCheck != 0) {
|
|
goto _57
|
|
}
|
|
/* Compute the operands that will be needed for OP_IsType */
|
|
p4 = int32(SQLITE_NULL)
|
|
if libc.Int32FromUint16((*TColumn)(unsafe.Pointer(pCol1)).FcolFlags)&int32(COLFLAG_VIRTUAL) != 0 {
|
|
_sqlite3ExprCodeGetColumnOfTable(tls, v, pTab10, **(**int32)(__ccgo_up(bp + 76)), j4, int32(3))
|
|
p11 = -int32(1)
|
|
p3 = int32(3)
|
|
} else {
|
|
if (*TColumn)(unsafe.Pointer(pCol1)).FiDflt != 0 {
|
|
**(**uintptr)(__ccgo_up(bp + 84)) = uintptr(0)
|
|
_sqlite3ValueFromExpr(tls, db, _sqlite3ColumnExpr(tls, pTab10, pCol1), (*Tsqlite3)(unsafe.Pointer(db)).Fenc, libc.Uint8FromInt8((*TColumn)(unsafe.Pointer(pCol1)).Faffinity), bp+84)
|
|
if **(**uintptr)(__ccgo_up(bp + 84)) != 0 {
|
|
p4 = Xsqlite3_value_type(tls, **(**uintptr)(__ccgo_up(bp + 84)))
|
|
_sqlite3ValueFree(tls, **(**uintptr)(__ccgo_up(bp + 84)))
|
|
}
|
|
}
|
|
p11 = **(**int32)(__ccgo_up(bp + 76))
|
|
if !((*TTable)(unsafe.Pointer(pTab10)).FtabFlags&libc.Uint32FromInt32(TF_WithoutRowid) == libc.Uint32FromInt32(0)) {
|
|
p3 = _sqlite3TableColumnToIndex(tls, _sqlite3PrimaryKeyIndex(tls, pTab10), j4)
|
|
} else {
|
|
p3 = int32(_sqlite3TableColumnToStorage(tls, pTab10, int16(j4)))
|
|
}
|
|
}
|
|
labelError = _sqlite3VdbeMakeLabel(tls, pParse)
|
|
labelOk = _sqlite3VdbeMakeLabel(tls, pParse)
|
|
if int32(uint32(*(*uint8)(unsafe.Pointer(pCol1 + 4))&0xf>>0)) != 0 {
|
|
jmp2 = _sqlite3VdbeAddOp4Int(tls, v, int32(OP_IsType), p11, labelOk, p3, p4)
|
|
if p11 < 0 {
|
|
_sqlite3VdbeChangeP5(tls, v, uint16(0x0f)) /* INT, REAL, TEXT, or BLOB */
|
|
jmp3 = jmp2
|
|
} else {
|
|
_sqlite3VdbeChangeP5(tls, v, uint16(0x0d)) /* INT, TEXT, or BLOB */
|
|
/* OP_IsType does not detect NaN values in the database file
|
|
** which should be treated as a NULL. So if the header type
|
|
** is REAL, we have to load the actual data using OP_Column
|
|
** to reliably determine if the value is a NULL. */
|
|
_sqlite3VdbeAddOp3(tls, v, int32(OP_Column), p11, p3, int32(3))
|
|
_sqlite3ColumnDefault(tls, v, pTab10, j4, int32(3))
|
|
jmp3 = _sqlite3VdbeAddOp2(tls, v, int32(OP_NotNull), int32(3), labelOk)
|
|
}
|
|
zErr1 = _sqlite3MPrintf(tls, db, __ccgo_ts+19488, libc.VaList(bp+136, (*TTable)(unsafe.Pointer(pTab10)).FzName, (*TColumn)(unsafe.Pointer(pCol1)).FzCnName))
|
|
_sqlite3VdbeAddOp4(tls, v, int32(OP_String8), 0, int32(3), 0, zErr1, -int32(7))
|
|
if doTypeCheck != 0 {
|
|
_sqlite3VdbeGoto(tls, v, labelError)
|
|
_sqlite3VdbeJumpHere(tls, v, jmp2)
|
|
_sqlite3VdbeJumpHere(tls, v, jmp3)
|
|
} else {
|
|
/* VDBE byte code will fall thru */
|
|
}
|
|
}
|
|
if bStrict != 0 && doTypeCheck != 0 {
|
|
_sqlite3VdbeAddOp4Int(tls, v, int32(OP_IsType), p11, labelOk, p3, p4)
|
|
_sqlite3VdbeChangeP5(tls, v, uint16(_aStdTypeMask[int32(uint32(*(*uint8)(unsafe.Pointer(pCol1 + 4))&0xf0>>4))-int32(1)]))
|
|
zErr1 = _sqlite3MPrintf(tls, db, __ccgo_ts+19508, libc.VaList(bp+136, _sqlite3StdType[int32(uint32(*(*uint8)(unsafe.Pointer(pCol1 + 4))&0xf0>>4))-int32(1)], (*TTable)(unsafe.Pointer(pTab10)).FzName, (**(**TColumn)(__ccgo_up((*TTable)(unsafe.Pointer(pTab10)).FaCol + uintptr(j4)*12))).FzCnName))
|
|
_sqlite3VdbeAddOp4(tls, v, int32(OP_String8), 0, int32(3), 0, zErr1, -int32(7))
|
|
} else {
|
|
if !(bStrict != 0) && int32((*TColumn)(unsafe.Pointer(pCol1)).Faffinity) == int32(SQLITE_AFF_TEXT) {
|
|
/* (3) Datatype for TEXT columns in non-STRICT tables must be
|
|
** NULL, TEXT, or BLOB. */
|
|
_sqlite3VdbeAddOp4Int(tls, v, int32(OP_IsType), p11, labelOk, p3, p4)
|
|
_sqlite3VdbeChangeP5(tls, v, uint16(0x1c)) /* NULL, TEXT, or BLOB */
|
|
zErr1 = _sqlite3MPrintf(tls, db, __ccgo_ts+19530, libc.VaList(bp+136, (*TTable)(unsafe.Pointer(pTab10)).FzName, (**(**TColumn)(__ccgo_up((*TTable)(unsafe.Pointer(pTab10)).FaCol + uintptr(j4)*12))).FzCnName))
|
|
_sqlite3VdbeAddOp4(tls, v, int32(OP_String8), 0, int32(3), 0, zErr1, -int32(7))
|
|
} else {
|
|
if !(bStrict != 0) && int32((*TColumn)(unsafe.Pointer(pCol1)).Faffinity) >= int32(SQLITE_AFF_NUMERIC) {
|
|
/* (4) Datatype for numeric columns in non-STRICT tables must not
|
|
** be a TEXT value that can be converted to numeric. */
|
|
_sqlite3VdbeAddOp4Int(tls, v, int32(OP_IsType), p11, labelOk, p3, p4)
|
|
_sqlite3VdbeChangeP5(tls, v, uint16(0x1b)) /* NULL, INT, FLOAT, or BLOB */
|
|
if p11 >= 0 {
|
|
_sqlite3ExprCodeGetColumnOfTable(tls, v, pTab10, **(**int32)(__ccgo_up(bp + 76)), j4, int32(3))
|
|
}
|
|
_sqlite3VdbeAddOp4(tls, v, int32(OP_Affinity), int32(3), int32(1), 0, __ccgo_ts+19553, -int32(1))
|
|
_sqlite3VdbeAddOp4Int(tls, v, int32(OP_IsType), -int32(1), labelOk, int32(3), p4)
|
|
_sqlite3VdbeChangeP5(tls, v, uint16(0x1c)) /* NULL, TEXT, or BLOB */
|
|
zErr1 = _sqlite3MPrintf(tls, db, __ccgo_ts+19555, libc.VaList(bp+136, (*TTable)(unsafe.Pointer(pTab10)).FzName, (**(**TColumn)(__ccgo_up((*TTable)(unsafe.Pointer(pTab10)).FaCol + uintptr(j4)*12))).FzCnName))
|
|
_sqlite3VdbeAddOp4(tls, v, int32(OP_String8), 0, int32(3), 0, zErr1, -int32(7))
|
|
}
|
|
}
|
|
}
|
|
_sqlite3VdbeResolveLabel(tls, v, labelError)
|
|
_integrityCheckResultRow(tls, v)
|
|
_sqlite3VdbeResolveLabel(tls, v, labelOk)
|
|
goto _57
|
|
_57:
|
|
;
|
|
j4 = j4 + 1
|
|
}
|
|
/* Verify CHECK constraints */
|
|
if (*TTable)(unsafe.Pointer(pTab10)).FpCheck != 0 && (*Tsqlite3)(unsafe.Pointer(db)).Fflags&uint64(SQLITE_IgnoreChecks) == uint64(0) {
|
|
pCheck = _sqlite3ExprListDup(tls, db, (*TTable)(unsafe.Pointer(pTab10)).FpCheck, 0)
|
|
if libc.Int32FromUint8((*Tsqlite3)(unsafe.Pointer(db)).FmallocFailed) == 0 {
|
|
addrCkFault = _sqlite3VdbeMakeLabel(tls, pParse)
|
|
addrCkOk = _sqlite3VdbeMakeLabel(tls, pParse)
|
|
(*TParse)(unsafe.Pointer(pParse)).FiSelfTab = **(**int32)(__ccgo_up(bp + 76)) + int32(1)
|
|
k3 = (*TExprList)(unsafe.Pointer(pCheck)).FnExpr - int32(1)
|
|
for {
|
|
if !(k3 > 0) {
|
|
break
|
|
}
|
|
_sqlite3ExprIfFalse(tls, pParse, (*(*TExprList_item)(unsafe.Pointer(pCheck + 8 + uintptr(k3)*20))).FpExpr, addrCkFault, 0)
|
|
goto _58
|
|
_58:
|
|
;
|
|
k3 = k3 - 1
|
|
}
|
|
_sqlite3ExprIfTrue(tls, pParse, (*(*TExprList_item)(unsafe.Pointer(pCheck + 8))).FpExpr, addrCkOk, int32(SQLITE_JUMPIFNULL))
|
|
_sqlite3VdbeResolveLabel(tls, v, addrCkFault)
|
|
(*TParse)(unsafe.Pointer(pParse)).FiSelfTab = 0
|
|
zErr2 = _sqlite3MPrintf(tls, db, __ccgo_ts+19575, libc.VaList(bp+136, (*TTable)(unsafe.Pointer(pTab10)).FzName))
|
|
_sqlite3VdbeAddOp4(tls, v, int32(OP_String8), 0, int32(3), 0, zErr2, -int32(7))
|
|
_integrityCheckResultRow(tls, v)
|
|
_sqlite3VdbeResolveLabel(tls, v, addrCkOk)
|
|
}
|
|
_sqlite3ExprListDelete(tls, db, pCheck)
|
|
}
|
|
if !(isQuick != 0) { /* Omit the remaining tests for quick_check */
|
|
/* Validate index entries for the current row */
|
|
j4 = 0
|
|
pIdx6 = (*TTable)(unsafe.Pointer(pTab10)).FpIndex
|
|
for {
|
|
if !(pIdx6 != 0) {
|
|
break
|
|
}
|
|
ckUniq = _sqlite3VdbeMakeLabel(tls, pParse)
|
|
if pPk1 == pIdx6 {
|
|
goto _59
|
|
}
|
|
r1 = _sqlite3GenerateIndexKey(tls, pParse, pIdx6, **(**int32)(__ccgo_up(bp + 76)), 0, 0, bp+88, pPrior, r1)
|
|
pPrior = pIdx6
|
|
_sqlite3VdbeAddOp2(tls, v, int32(OP_AddImm), int32(8)+j4, int32(1)) /* increment entry count */
|
|
/* Verify that an index entry exists for the current table row */
|
|
_sqlite3VdbeAddOp4Int(tls, v, int32(OP_Found), **(**int32)(__ccgo_up(bp + 80))+j4, ckUniq, r1, libc.Int32FromUint16((*TIndex)(unsafe.Pointer(pIdx6)).FnColumn))
|
|
jmp21 = _sqlite3VdbeAddOp3(tls, v, int32(OP_IFindKey), **(**int32)(__ccgo_up(bp + 80))+j4, ckUniq, r1)
|
|
_sqlite3VdbeChangeP4(tls, v, -int32(1), pIdx6, -int32(6))
|
|
_sqlite3VdbeAddOp4(tls, v, int32(OP_String8), 0, int32(3), 0, _sqlite3MPrintf(tls, db, __ccgo_ts+19605, libc.VaList(bp+136, (*TIndex)(unsafe.Pointer(pIdx6)).FzName)), -int32(7))
|
|
_sqlite3VdbeAddOp3(tls, v, int32(OP_Concat), int32(7), int32(3), int32(3))
|
|
_integrityCheckResultRow(tls, v)
|
|
_sqlite3VdbeAddOp2(tls, v, int32(OP_Goto), 0, ckUniq)
|
|
_sqlite3VdbeJumpHere(tls, v, jmp21)
|
|
_sqlite3VdbeLoadString(tls, v, int32(3), __ccgo_ts+19664)
|
|
_sqlite3VdbeAddOp3(tls, v, int32(OP_Concat), int32(7), int32(3), int32(3))
|
|
_sqlite3VdbeLoadString(tls, v, int32(4), __ccgo_ts+19669)
|
|
_sqlite3VdbeAddOp3(tls, v, int32(OP_Concat), int32(4), int32(3), int32(3))
|
|
jmp5 = _sqlite3VdbeLoadString(tls, v, int32(4), (*TIndex)(unsafe.Pointer(pIdx6)).FzName)
|
|
_sqlite3VdbeAddOp3(tls, v, int32(OP_Concat), int32(4), int32(3), int32(3))
|
|
jmp4 = _integrityCheckResultRow(tls, v)
|
|
_sqlite3VdbeResolveLabel(tls, v, ckUniq)
|
|
/* The OP_IdxRowid opcode is an optimized version of OP_Column
|
|
** that extracts the rowid off the end of the index record.
|
|
** But it only works correctly if index record does not have
|
|
** any extra bytes at the end. Verify that this is the case. */
|
|
if (*TTable)(unsafe.Pointer(pTab10)).FtabFlags&uint32(TF_WithoutRowid) == uint32(0) {
|
|
_sqlite3VdbeAddOp2(tls, v, int32(OP_IdxRowid), **(**int32)(__ccgo_up(bp + 80))+j4, int32(3))
|
|
jmp7 = _sqlite3VdbeAddOp3(tls, v, int32(OP_Eq), int32(3), 0, r1+libc.Int32FromUint16((*TIndex)(unsafe.Pointer(pIdx6)).FnColumn)-int32(1))
|
|
_sqlite3VdbeLoadString(tls, v, int32(3), __ccgo_ts+19690)
|
|
_sqlite3VdbeAddOp3(tls, v, int32(OP_Concat), int32(7), int32(3), int32(3))
|
|
_sqlite3VdbeLoadString(tls, v, int32(4), __ccgo_ts+19726)
|
|
_sqlite3VdbeGoto(tls, v, jmp5-int32(1))
|
|
_sqlite3VdbeJumpHere(tls, v, jmp7)
|
|
}
|
|
/* Any indexed columns with non-BINARY collations must still hold
|
|
** the exact same text value as the table. */
|
|
label6 = 0
|
|
kk = 0
|
|
for {
|
|
if !(kk < libc.Int32FromUint16((*TIndex)(unsafe.Pointer(pIdx6)).FnKeyCol)) {
|
|
break
|
|
}
|
|
if **(**uintptr)(__ccgo_up((*TIndex)(unsafe.Pointer(pIdx6)).FazColl + uintptr(kk)*4)) == uintptr(unsafe.Pointer(&_sqlite3StrBINARY)) {
|
|
goto _60
|
|
}
|
|
if label6 == 0 {
|
|
label6 = _sqlite3VdbeMakeLabel(tls, pParse)
|
|
}
|
|
_sqlite3VdbeAddOp3(tls, v, int32(OP_Column), **(**int32)(__ccgo_up(bp + 80))+j4, kk, int32(3))
|
|
_sqlite3VdbeAddOp3(tls, v, int32(OP_Ne), int32(3), label6, r1+kk)
|
|
goto _60
|
|
_60:
|
|
;
|
|
kk = kk + 1
|
|
}
|
|
if label6 != 0 {
|
|
jmp6 = _sqlite3VdbeAddOp0(tls, v, int32(OP_Goto))
|
|
_sqlite3VdbeResolveLabel(tls, v, label6)
|
|
_sqlite3VdbeLoadString(tls, v, int32(3), __ccgo_ts+19664)
|
|
_sqlite3VdbeAddOp3(tls, v, int32(OP_Concat), int32(7), int32(3), int32(3))
|
|
_sqlite3VdbeLoadString(tls, v, int32(4), __ccgo_ts+19737)
|
|
_sqlite3VdbeGoto(tls, v, jmp5-int32(1))
|
|
_sqlite3VdbeJumpHere(tls, v, jmp6)
|
|
}
|
|
/* For UNIQUE indexes, verify that only one entry exists with the
|
|
** current key. The entry is unique if (1) any column is NULL
|
|
** or (2) the next entry has a different key */
|
|
if libc.Int32FromUint8((*TIndex)(unsafe.Pointer(pIdx6)).FonError) != OE_None {
|
|
uniqOk = _sqlite3VdbeMakeLabel(tls, pParse)
|
|
kk = 0
|
|
for {
|
|
if !(kk < libc.Int32FromUint16((*TIndex)(unsafe.Pointer(pIdx6)).FnKeyCol)) {
|
|
break
|
|
}
|
|
iCol1 = int32(**(**Ti16)(__ccgo_up((*TIndex)(unsafe.Pointer(pIdx6)).FaiColumn + uintptr(kk)*2)))
|
|
if iCol1 >= 0 && int32(uint32(*(*uint8)(unsafe.Pointer((*TTable)(unsafe.Pointer(pTab10)).FaCol + uintptr(iCol1)*12 + 4))&0xf>>0)) != 0 {
|
|
goto _61
|
|
}
|
|
_sqlite3VdbeAddOp2(tls, v, int32(OP_IsNull), r1+kk, uniqOk)
|
|
goto _61
|
|
_61:
|
|
;
|
|
kk = kk + 1
|
|
}
|
|
jmp61 = _sqlite3VdbeAddOp1(tls, v, int32(OP_Next), **(**int32)(__ccgo_up(bp + 80))+j4)
|
|
_sqlite3VdbeGoto(tls, v, uniqOk)
|
|
_sqlite3VdbeJumpHere(tls, v, jmp61)
|
|
_sqlite3VdbeAddOp4Int(tls, v, int32(OP_IdxGT), **(**int32)(__ccgo_up(bp + 80))+j4, uniqOk, r1, libc.Int32FromUint16((*TIndex)(unsafe.Pointer(pIdx6)).FnKeyCol))
|
|
_sqlite3VdbeLoadString(tls, v, int32(3), __ccgo_ts+19764)
|
|
_sqlite3VdbeGoto(tls, v, jmp5)
|
|
_sqlite3VdbeResolveLabel(tls, v, uniqOk)
|
|
}
|
|
_sqlite3VdbeJumpHere(tls, v, jmp4)
|
|
_sqlite3ResolvePartIdxLabel(tls, pParse, **(**int32)(__ccgo_up(bp + 88)))
|
|
goto _59
|
|
_59:
|
|
;
|
|
pIdx6 = (*TIndex)(unsafe.Pointer(pIdx6)).FpNext
|
|
j4 = j4 + 1
|
|
}
|
|
}
|
|
_sqlite3VdbeAddOp2(tls, v, int32(OP_Next), **(**int32)(__ccgo_up(bp + 76)), loopTop)
|
|
_sqlite3VdbeJumpHere(tls, v, loopTop-int32(1))
|
|
if pPk1 != 0 {
|
|
_sqlite3ReleaseTempRange(tls, pParse, r2, libc.Int32FromUint16((*TIndex)(unsafe.Pointer(pPk1)).FnKeyCol))
|
|
}
|
|
goto _53
|
|
_53:
|
|
;
|
|
x2 = (*THashElem)(unsafe.Pointer(x2)).Fnext
|
|
}
|
|
/* Second pass to invoke the xIntegrity method on all virtual
|
|
** tables.
|
|
*/
|
|
x2 = (*THash)(unsafe.Pointer(pTbls)).Ffirst
|
|
for {
|
|
if !(x2 != 0) {
|
|
break
|
|
}
|
|
pTab11 = (*THashElem)(unsafe.Pointer(x2)).Fdata
|
|
if _tableSkipIntegrityCheck(tls, pTab11, pObjTab) != 0 {
|
|
goto _62
|
|
}
|
|
if libc.Int32FromUint8((*TTable)(unsafe.Pointer(pTab11)).FeTabType) == TABTYP_NORM {
|
|
goto _62
|
|
}
|
|
if !(libc.Int32FromUint8((*TTable)(unsafe.Pointer(pTab11)).FeTabType) == libc.Int32FromInt32(TABTYP_VTAB)) {
|
|
goto _62
|
|
}
|
|
if int32((*TTable)(unsafe.Pointer(pTab11)).FnCol) <= 0 {
|
|
zMod = **(**uintptr)(__ccgo_up((*(*struct {
|
|
FnArg int32
|
|
FazArg uintptr
|
|
Fp uintptr
|
|
})(unsafe.Pointer(pTab11 + 44))).FazArg))
|
|
if _sqlite3HashFind(tls, db+400, zMod) == uintptr(0) {
|
|
goto _62
|
|
}
|
|
}
|
|
_sqlite3ViewGetColumnNames(tls, pParse, pTab11)
|
|
if (*(*struct {
|
|
FnArg int32
|
|
FazArg uintptr
|
|
Fp uintptr
|
|
})(unsafe.Pointer(pTab11 + 44))).Fp == uintptr(0) {
|
|
goto _62
|
|
}
|
|
pVTab = (*TVTable)(unsafe.Pointer((*(*struct {
|
|
FnArg int32
|
|
FazArg uintptr
|
|
Fp uintptr
|
|
})(unsafe.Pointer(pTab11 + 44))).Fp)).FpVtab
|
|
if pVTab == uintptr(0) {
|
|
goto _62
|
|
}
|
|
if (*Tsqlite3_vtab)(unsafe.Pointer(pVTab)).FpModule == uintptr(0) {
|
|
goto _62
|
|
}
|
|
if (*Tsqlite3_module)(unsafe.Pointer((*Tsqlite3_vtab)(unsafe.Pointer(pVTab)).FpModule)).FiVersion < int32(4) {
|
|
goto _62
|
|
}
|
|
if (*Tsqlite3_module)(unsafe.Pointer((*Tsqlite3_vtab)(unsafe.Pointer(pVTab)).FpModule)).FxIntegrity == uintptr(0) {
|
|
goto _62
|
|
}
|
|
_sqlite3VdbeAddOp3(tls, v, int32(OP_VCheck), i9, int32(3), isQuick)
|
|
(*TTable)(unsafe.Pointer(pTab11)).FnTabRef = (*TTable)(unsafe.Pointer(pTab11)).FnTabRef + 1
|
|
_sqlite3VdbeAppendP4(tls, v, pTab11, -int32(17))
|
|
a11 = _sqlite3VdbeAddOp1(tls, v, int32(OP_IsNull), int32(3))
|
|
_integrityCheckResultRow(tls, v)
|
|
_sqlite3VdbeJumpHere(tls, v, a11)
|
|
goto _62
|
|
goto _62
|
|
_62:
|
|
;
|
|
x2 = (*THashElem)(unsafe.Pointer(x2)).Fnext
|
|
}
|
|
goto _40
|
|
_40:
|
|
;
|
|
i9 = i9 + 1
|
|
}
|
|
aOp2 = _sqlite3VdbeAddOpList(tls, v, libc.Int32FromUint32(libc.Uint32FromInt64(28)/libc.Uint32FromInt64(4)), uintptr(unsafe.Pointer(&_endCode)), _iLn21)
|
|
if aOp2 != 0 {
|
|
(**(**TVdbeOp)(__ccgo_up(aOp2))).Fp2 = int32(1) - **(**int32)(__ccgo_up(bp + 72))
|
|
(**(**TVdbeOp)(__ccgo_up(aOp2 + 2*20))).Fp4type = int8(-libc.Int32FromInt32(1))
|
|
*(*uintptr)(unsafe.Pointer(aOp2 + 2*20 + 16)) = __ccgo_ts + 19791
|
|
(**(**TVdbeOp)(__ccgo_up(aOp2 + 5*20))).Fp4type = int8(-libc.Int32FromInt32(1))
|
|
*(*uintptr)(unsafe.Pointer(aOp2 + 5*20 + 16)) = _sqlite3ErrStr(tls, int32(SQLITE_CORRUPT))
|
|
}
|
|
_sqlite3VdbeChangeP3(tls, v, 0, _sqlite3VdbeCurrentAddr(tls, v)-int32(2))
|
|
break
|
|
/*
|
|
** PRAGMA encoding
|
|
** PRAGMA encoding = "utf-8"|"utf-16"|"utf-16le"|"utf-16be"
|
|
**
|
|
** In its first form, this pragma returns the encoding of the main
|
|
** database. If the database is not initialized, it is initialized now.
|
|
**
|
|
** The second form of this pragma is a no-op if the main database file
|
|
** has not already been initialized. In this case it sets the default
|
|
** encoding that will be used for the main database file if a new file
|
|
** is created. If an existing main database file is opened, then the
|
|
** default text encoding for the existing database is used.
|
|
**
|
|
** In all cases new databases created using the ATTACH command are
|
|
** created to use the same default text encoding as the main database. If
|
|
** the main database has not been initialized and/or created when ATTACH
|
|
** is executed, this is done before the ATTACH operation.
|
|
**
|
|
** In the second form this pragma sets the text encoding to be used in
|
|
** new database files created using this database handle. It is only
|
|
** useful if invoked immediately after the main database i
|
|
*/
|
|
fallthrough
|
|
case int32(PragTyp_ENCODING):
|
|
if !(zRight != 0) { /* "PRAGMA encoding" */
|
|
if _sqlite3ReadSchema(tls, pParse) != 0 {
|
|
goto pragma_out
|
|
}
|
|
_returnSingleText(tls, v, _encnames1[(*Tsqlite3)(unsafe.Pointer((*TParse)(unsafe.Pointer(pParse)).Fdb)).Fenc].FzName)
|
|
} else { /* "PRAGMA encoding = XXX" */
|
|
/* Only change the value of sqlite.enc if the database handle is not
|
|
** initialized. If the main database exists, the new sqlite.enc value
|
|
** will be overwritten when the schema is next loaded. If it does not
|
|
** already exists, it will be created to use the new encoding value.
|
|
*/
|
|
if (*Tsqlite3)(unsafe.Pointer(db)).FmDbFlags&uint32(DBFLAG_EncodingFixed) == uint32(0) {
|
|
pEnc = uintptr(unsafe.Pointer(&_encnames1))
|
|
for {
|
|
if !((*struct {
|
|
FzName uintptr
|
|
Fenc Tu8
|
|
})(unsafe.Pointer(pEnc)).FzName != 0) {
|
|
break
|
|
}
|
|
if 0 == _sqlite3StrICmp(tls, zRight, (*struct {
|
|
FzName uintptr
|
|
Fenc Tu8
|
|
})(unsafe.Pointer(pEnc)).FzName) {
|
|
if (*struct {
|
|
FzName uintptr
|
|
Fenc Tu8
|
|
})(unsafe.Pointer(pEnc)).Fenc != 0 {
|
|
v2 = libc.Int32FromUint8((*struct {
|
|
FzName uintptr
|
|
Fenc Tu8
|
|
})(unsafe.Pointer(pEnc)).Fenc)
|
|
} else {
|
|
v2 = int32(SQLITE_UTF16LE)
|
|
}
|
|
enc = libc.Uint8FromInt32(v2)
|
|
(*TSchema)(unsafe.Pointer((**(**TDb)(__ccgo_up((*Tsqlite3)(unsafe.Pointer(db)).FaDb))).FpSchema)).Fenc = enc
|
|
_sqlite3SetTextEncoding(tls, db, enc)
|
|
break
|
|
}
|
|
goto _63
|
|
_63:
|
|
;
|
|
pEnc += 8
|
|
}
|
|
if !((*struct {
|
|
FzName uintptr
|
|
Fenc Tu8
|
|
})(unsafe.Pointer(pEnc)).FzName != 0) {
|
|
_sqlite3ErrorMsg(tls, pParse, __ccgo_ts+19852, libc.VaList(bp+136, zRight))
|
|
}
|
|
}
|
|
}
|
|
break
|
|
/*
|
|
** PRAGMA [schema.]schema_version
|
|
** PRAGMA [schema.]schema_version = <integer>
|
|
**
|
|
** PRAGMA [schema.]user_version
|
|
** PRAGMA [schema.]user_version = <integer>
|
|
**
|
|
** PRAGMA [schema.]freelist_count
|
|
**
|
|
** PRAGMA [schema.]data_version
|
|
**
|
|
** PRAGMA [schema.]application_id
|
|
** PRAGMA [schema.]application_id = <integer>
|
|
**
|
|
** The pragma's schema_version and user_version are used to set or get
|
|
** the value of the schema-version and user-version, respectively. Both
|
|
** the schema-version and the user-version are 32-bit signed integers
|
|
** stored in the database header.
|
|
**
|
|
** The schema-cookie is usually only manipulated internally by SQLite. It
|
|
** is incremented by SQLite whenever the database schema is modified (by
|
|
** creating or dropping a table or index). The schema version is used by
|
|
** SQLite each time a query is executed to ensure that the internal cache
|
|
** of the schema used when compiling the SQL query matches the schema of
|
|
** the database against which the compiled query is actually executed.
|
|
** Subverting this mechanism by using "PRAGMA schema_version" to modify
|
|
** the schema-version is potentially dangerous and may lead to program
|
|
** crashes or database corruption. Use with caution!
|
|
**
|
|
** The user-version is not used internally by SQLite. It may be used by
|
|
** applications for any purpose.
|
|
*/
|
|
fallthrough
|
|
case int32(PragTyp_HEADER_VALUE):
|
|
iCookie = libc.Int32FromUint64((*TPragmaName)(unsafe.Pointer(pPragma)).FiArg) /* Which cookie to read or write */
|
|
_sqlite3VdbeUsesBtree(tls, v, iDb)
|
|
if zRight != 0 && libc.Int32FromUint8((*TPragmaName)(unsafe.Pointer(pPragma)).FmPragFlg)&int32(PragFlg_ReadOnly) == 0 {
|
|
aOp3 = _sqlite3VdbeAddOpList(tls, v, libc.Int32FromUint32(libc.Uint32FromInt64(8)/libc.Uint32FromInt64(4)), uintptr(unsafe.Pointer(&_setCookie)), 0)
|
|
if 0 != 0 {
|
|
break
|
|
}
|
|
(**(**TVdbeOp)(__ccgo_up(aOp3))).Fp1 = iDb
|
|
(**(**TVdbeOp)(__ccgo_up(aOp3 + 1*20))).Fp1 = iDb
|
|
(**(**TVdbeOp)(__ccgo_up(aOp3 + 1*20))).Fp2 = iCookie
|
|
(**(**TVdbeOp)(__ccgo_up(aOp3 + 1*20))).Fp3 = _sqlite3Atoi(tls, zRight)
|
|
(**(**TVdbeOp)(__ccgo_up(aOp3 + 1*20))).Fp5 = uint16(1)
|
|
if iCookie == int32(BTREE_SCHEMA_VERSION) && (*Tsqlite3)(unsafe.Pointer(db)).Fflags&uint64(SQLITE_Defensive) != uint64(0) {
|
|
/* Do not allow the use of PRAGMA schema_version=VALUE in defensive
|
|
** mode. Change the OP_SetCookie opcode into a no-op. */
|
|
(**(**TVdbeOp)(__ccgo_up(aOp3 + 1*20))).Fopcode = uint8(OP_Noop)
|
|
}
|
|
} else {
|
|
aOp4 = _sqlite3VdbeAddOpList(tls, v, libc.Int32FromUint32(libc.Uint32FromInt64(12)/libc.Uint32FromInt64(4)), uintptr(unsafe.Pointer(&_readCookie)), 0)
|
|
if 0 != 0 {
|
|
break
|
|
}
|
|
(**(**TVdbeOp)(__ccgo_up(aOp4))).Fp1 = iDb
|
|
(**(**TVdbeOp)(__ccgo_up(aOp4 + 1*20))).Fp1 = iDb
|
|
(**(**TVdbeOp)(__ccgo_up(aOp4 + 1*20))).Fp3 = iCookie
|
|
_sqlite3VdbeReusable(tls, v)
|
|
}
|
|
break
|
|
/*
|
|
** PRAGMA compile_options
|
|
**
|
|
** Return the names of all compile-time options used in this build,
|
|
** one option per row.
|
|
*/
|
|
fallthrough
|
|
case int32(PragTyp_COMPILE_OPTIONS):
|
|
i10 = 0
|
|
(*TParse)(unsafe.Pointer(pParse)).FnMem = int32(1)
|
|
for {
|
|
v2 = i10
|
|
i10 = i10 + 1
|
|
v1 = Xsqlite3_compileoption_get(tls, v2)
|
|
zOpt = v1
|
|
if !(v1 != uintptr(0)) {
|
|
break
|
|
}
|
|
_sqlite3VdbeLoadString(tls, v, int32(1), zOpt)
|
|
_sqlite3VdbeAddOp2(tls, v, int32(OP_ResultRow), int32(1), int32(1))
|
|
}
|
|
_sqlite3VdbeReusable(tls, v)
|
|
break
|
|
/*
|
|
** PRAGMA [schema.]wal_checkpoint = passive|full|restart|truncate
|
|
**
|
|
** Checkpoint the database.
|
|
*/
|
|
fallthrough
|
|
case int32(PragTyp_WAL_CHECKPOINT):
|
|
if (*TToken)(unsafe.Pointer(pId2)).Fz != 0 {
|
|
v2 = iDb
|
|
} else {
|
|
v2 = libc.Int32FromInt32(SQLITE_MAX_ATTACHED) + libc.Int32FromInt32(2)
|
|
}
|
|
iBt = v2
|
|
eMode2 = SQLITE_CHECKPOINT_PASSIVE
|
|
if zRight != 0 {
|
|
if _sqlite3StrICmp(tls, zRight, __ccgo_ts+19018) == 0 {
|
|
eMode2 = int32(SQLITE_CHECKPOINT_FULL)
|
|
} else {
|
|
if _sqlite3StrICmp(tls, zRight, __ccgo_ts+19877) == 0 {
|
|
eMode2 = int32(SQLITE_CHECKPOINT_RESTART)
|
|
} else {
|
|
if _sqlite3StrICmp(tls, zRight, __ccgo_ts+19171) == 0 {
|
|
eMode2 = int32(SQLITE_CHECKPOINT_TRUNCATE)
|
|
} else {
|
|
if _sqlite3StrICmp(tls, zRight, __ccgo_ts+19885) == 0 {
|
|
eMode2 = -int32(1)
|
|
}
|
|
}
|
|
}
|
|
}
|
|
}
|
|
(*TParse)(unsafe.Pointer(pParse)).FnMem = int32(3)
|
|
_sqlite3VdbeAddOp3(tls, v, int32(OP_Checkpoint), iBt, eMode2, int32(1))
|
|
_sqlite3VdbeAddOp2(tls, v, int32(OP_ResultRow), int32(1), int32(3))
|
|
break
|
|
/*
|
|
** PRAGMA wal_autocheckpoint
|
|
** PRAGMA wal_autocheckpoint = N
|
|
**
|
|
** Configure a database connection to automatically checkpoint a database
|
|
** after accumulating N frames in the log. Or query for the current value
|
|
** of N.
|
|
*/
|
|
fallthrough
|
|
case int32(PragTyp_WAL_AUTOCHECKPOINT):
|
|
if zRight != 0 {
|
|
Xsqlite3_wal_autocheckpoint(tls, db, _sqlite3Atoi(tls, zRight))
|
|
}
|
|
if (*Tsqlite3)(unsafe.Pointer(db)).FxWalCallback == __ccgo_fp(_sqlite3WalDefaultHook) {
|
|
v2 = int32((*Tsqlite3)(unsafe.Pointer(db)).FpWalArg)
|
|
} else {
|
|
v2 = 0
|
|
}
|
|
_returnSingleInt(tls, v, int64(v2))
|
|
break
|
|
/*
|
|
** PRAGMA shrink_memory
|
|
**
|
|
** IMPLEMENTATION-OF: R-23445-46109 This pragma causes the database
|
|
** connection on which it is invoked to free up as much memory as it
|
|
** can, by calling sqlite3_db_release_memory().
|
|
*/
|
|
fallthrough
|
|
case int32(PragTyp_SHRINK_MEMORY):
|
|
Xsqlite3_db_release_memory(tls, db)
|
|
break
|
|
/*
|
|
** PRAGMA optimize
|
|
** PRAGMA optimize(MASK)
|
|
** PRAGMA schema.optimize
|
|
** PRAGMA schema.optimize(MASK)
|
|
**
|
|
** Attempt to optimize the database. All schemas are optimized in the first
|
|
** two forms, and only the specified schema is optimized in the latter two.
|
|
**
|
|
** The details of optimizations performed by this pragma are expected
|
|
** to change and improve over time. Applications should anticipate that
|
|
** this pragma will perform new optimizations in future releases.
|
|
**
|
|
** The optional argument is a bitmask of optimizations to perform:
|
|
**
|
|
** 0x00001 Debugging mode. Do not actually perform any optimizations
|
|
** but instead return one line of text for each optimization
|
|
** that would have been done. Off by default.
|
|
**
|
|
** 0x00002 Run ANALYZE on tables that might benefit. On by default.
|
|
** See below for additional information.
|
|
**
|
|
** 0x00010 Run all ANALYZE operations using an analysis_limit that
|
|
** is the lessor of the current analysis_limit and the
|
|
** SQLITE_DEFAULT_OPTIMIZE_LIMIT compile-time option.
|
|
** The default value of SQLITE_DEFAULT_OPTIMIZE_LIMIT is
|
|
** currently (2024-02-19) set to 2000, which is such that
|
|
** the worst case run-time for PRAGMA optimize on a 100MB
|
|
** database will usually be less than 100 milliseconds on
|
|
** a RaspberryPI-4 class machine. On by default.
|
|
**
|
|
** 0x10000 Look at tables to see if they need to be reanalyzed
|
|
** due to growth or shrinkage even if they have not been
|
|
** queried during the current connection. Off by default.
|
|
**
|
|
** The default MASK is and always shall be 0x0fffe. In the current
|
|
** implementation, the default mask only covers the 0x00002 optimization,
|
|
** though additional optimizations that are covered by 0x0fffe might be
|
|
** added in the future. Optimizations that are off by default and must
|
|
** be explicitly requested have masks of 0x10000 or greater.
|
|
**
|
|
** DETERMINATION OF WHEN TO RUN ANALYZE
|
|
**
|
|
** In the current implementation, a table is analyzed if only if all of
|
|
** the following are true:
|
|
**
|
|
** (1) MASK bit 0x00002 is set.
|
|
**
|
|
** (2) The table is an ordinary table, not a virtual table or view.
|
|
**
|
|
** (3) The table name does not begin with "sqlite_".
|
|
**
|
|
** (4) One or more of the following is true:
|
|
** (4a) The 0x10000 MASK bit is set.
|
|
** (4b) One or more indexes on the table lacks an entry
|
|
** in the sqlite_stat1 table.
|
|
** (4c) The query planner used sqlite_stat1-style statistics for one
|
|
** or more indexes of the table at some point during the lifetime
|
|
** of the current connection.
|
|
**
|
|
** (5) One or more of the following is true:
|
|
** (5a) One or more indexes on the table lacks an entry
|
|
** in the sqlite_stat1 table. (Same as 4a)
|
|
** (5b) The number of rows in the table has increased or decreased by
|
|
** 10-fold. In other words, the current size of the table is
|
|
** 10 times larger than the size in sqlite_stat1 or else the
|
|
** current size is less than 1/10th the size in sqlite_stat1.
|
|
**
|
|
** The rules for when tables are analyzed are likely to change in
|
|
** future releases. Future versions of SQLite might accept a string
|
|
** literal argument to this pragma that contains a mnemonic description
|
|
** of the options rather than a bitmap.
|
|
*/
|
|
fallthrough
|
|
case int32(PragTyp_OPTIMIZE): /* Analysis limit to use */
|
|
nCheck = 0 /* Number of tables to be optimized */
|
|
nBtree = 0 /* Number of indexes on the current table */
|
|
if zRight != 0 {
|
|
opMask = libc.Uint32FromInt32(_sqlite3Atoi(tls, zRight))
|
|
if opMask&uint32(0x02) == uint32(0) {
|
|
break
|
|
}
|
|
} else {
|
|
opMask = uint32(0xfffe)
|
|
}
|
|
if opMask&uint32(0x10) == uint32(0) {
|
|
nLimit = 0
|
|
} else {
|
|
if (*Tsqlite3)(unsafe.Pointer(db)).FnAnalysisLimit > 0 && (*Tsqlite3)(unsafe.Pointer(db)).FnAnalysisLimit < int32(SQLITE_DEFAULT_OPTIMIZE_LIMIT) {
|
|
nLimit = 0
|
|
} else {
|
|
nLimit = int32(SQLITE_DEFAULT_OPTIMIZE_LIMIT)
|
|
}
|
|
}
|
|
v1 = pParse + 44
|
|
v2 = *(*int32)(unsafe.Pointer(v1))
|
|
*(*int32)(unsafe.Pointer(v1)) = *(*int32)(unsafe.Pointer(v1)) + 1
|
|
iTabCur = v2
|
|
if zDb != 0 {
|
|
v2 = iDb
|
|
} else {
|
|
v2 = (*Tsqlite3)(unsafe.Pointer(db)).FnDb - int32(1)
|
|
}
|
|
iDbLast = v2
|
|
for {
|
|
if !(iDb <= iDbLast) {
|
|
break
|
|
}
|
|
if iDb == int32(1) {
|
|
goto _71
|
|
}
|
|
_sqlite3CodeVerifySchema(tls, pParse, iDb)
|
|
pSchema = (**(**TDb)(__ccgo_up((*Tsqlite3)(unsafe.Pointer(db)).FaDb + uintptr(iDb)*16))).FpSchema
|
|
k4 = (*THash)(unsafe.Pointer(pSchema + 8)).Ffirst
|
|
for {
|
|
if !(k4 != 0) {
|
|
break
|
|
}
|
|
pTab12 = (*THashElem)(unsafe.Pointer(k4)).Fdata
|
|
/* This only works for ordinary tables */
|
|
if !(libc.Int32FromUint8((*TTable)(unsafe.Pointer(pTab12)).FeTabType) == libc.Int32FromInt32(TABTYP_NORM)) {
|
|
goto _73
|
|
}
|
|
/* Do not scan system tables */
|
|
if 0 == Xsqlite3_strnicmp(tls, (*TTable)(unsafe.Pointer(pTab12)).FzName, __ccgo_ts+6758, int32(7)) {
|
|
goto _73
|
|
}
|
|
/* Find the size of the table as last recorded in sqlite_stat1.
|
|
** If any index is unanalyzed, then the threshold is -1 to
|
|
** indicate a new, unanalyzed index
|
|
*/
|
|
szThreshold = (*TTable)(unsafe.Pointer(pTab12)).FnRowLogEst
|
|
nIndex = 0
|
|
pIdx7 = (*TTable)(unsafe.Pointer(pTab12)).FpIndex
|
|
for {
|
|
if !(pIdx7 != 0) {
|
|
break
|
|
}
|
|
nIndex = nIndex + 1
|
|
if !(int32(uint32(*(*uint16)(unsafe.Pointer(pIdx7 + 56))&0x80>>7)) != 0) {
|
|
szThreshold = int16(-int32(1)) /* Always analyze if any index lacks statistics */
|
|
}
|
|
goto _74
|
|
_74:
|
|
;
|
|
pIdx7 = (*TIndex)(unsafe.Pointer(pIdx7)).FpNext
|
|
}
|
|
/* If table pTab has not been used in a way that would benefit from
|
|
** having analysis statistics during the current session, then skip it,
|
|
** unless the 0x10000 MASK bit is set. */
|
|
if (*TTable)(unsafe.Pointer(pTab12)).FtabFlags&uint32(TF_MaybeReanalyze) != uint32(0) {
|
|
/* Check for size change if stat1 has been used for a query */
|
|
} else {
|
|
if opMask&uint32(0x10000) != 0 {
|
|
/* Check for size change if 0x10000 is set */
|
|
} else {
|
|
if (*TTable)(unsafe.Pointer(pTab12)).FpIndex != uintptr(0) && int32(szThreshold) < 0 {
|
|
/* Do analysis if unanalyzed indexes exists */
|
|
} else {
|
|
/* Otherwise, we can skip this table */
|
|
goto _73
|
|
}
|
|
}
|
|
}
|
|
nCheck = nCheck + 1
|
|
if nCheck == int32(2) {
|
|
/* If ANALYZE might be invoked two or more times, hold a write
|
|
** transaction for efficiency */
|
|
_sqlite3BeginWriteOperation(tls, pParse, 0, iDb)
|
|
}
|
|
nBtree = nBtree + (nIndex + int32(1))
|
|
/* Reanalyze if the table is 10 times larger or smaller than
|
|
** the last analysis. Unconditional reanalysis if there are
|
|
** unanalyzed indexes. */
|
|
_sqlite3OpenTable(tls, pParse, iTabCur, iDb, pTab12, int32(OP_OpenRead))
|
|
if int32(szThreshold) >= 0 {
|
|
iRange = int16(33) /* 10x size change */
|
|
if int32(szThreshold) >= int32(iRange) {
|
|
v2 = int32(szThreshold) - int32(iRange)
|
|
} else {
|
|
v2 = -int32(1)
|
|
}
|
|
_sqlite3VdbeAddOp4Int(tls, v, int32(OP_IfSizeBetween), iTabCur, libc.Int32FromUint32(libc.Uint32FromInt32(_sqlite3VdbeCurrentAddr(tls, v)+int32(2))+opMask&uint32(1)), v2, int32(szThreshold)+int32(iRange))
|
|
} else {
|
|
_sqlite3VdbeAddOp2(tls, v, int32(OP_Rewind), iTabCur, libc.Int32FromUint32(libc.Uint32FromInt32(_sqlite3VdbeCurrentAddr(tls, v)+int32(2))+opMask&uint32(1)))
|
|
}
|
|
zSubSql = _sqlite3MPrintf(tls, db, __ccgo_ts+19890, libc.VaList(bp+136, (**(**TDb)(__ccgo_up((*Tsqlite3)(unsafe.Pointer(db)).FaDb + uintptr(iDb)*16))).FzDbSName, (*TTable)(unsafe.Pointer(pTab12)).FzName))
|
|
if opMask&uint32(0x01) != 0 {
|
|
r11 = _sqlite3GetTempReg(tls, pParse)
|
|
_sqlite3VdbeAddOp4(tls, v, int32(OP_String8), 0, r11, 0, zSubSql, -int32(7))
|
|
_sqlite3VdbeAddOp2(tls, v, int32(OP_ResultRow), r11, int32(1))
|
|
} else {
|
|
if nLimit != 0 {
|
|
v2 = int32(0x02)
|
|
} else {
|
|
v2 = 00
|
|
}
|
|
_sqlite3VdbeAddOp4(tls, v, int32(OP_SqlExec), v2, nLimit, 0, zSubSql, -int32(7))
|
|
}
|
|
goto _73
|
|
_73:
|
|
;
|
|
k4 = (*THashElem)(unsafe.Pointer(k4)).Fnext
|
|
}
|
|
goto _71
|
|
_71:
|
|
;
|
|
iDb = iDb + 1
|
|
}
|
|
_sqlite3VdbeAddOp0(tls, v, int32(OP_Expire))
|
|
/* In a schema with a large number of tables and indexes, scale back
|
|
** the analysis_limit to avoid excess run-time in the worst case.
|
|
*/
|
|
if !((*Tsqlite3)(unsafe.Pointer(db)).FmallocFailed != 0) && nLimit > 0 && nBtree > int32(100) {
|
|
nLimit = int32(100) * nLimit / nBtree
|
|
if nLimit < int32(100) {
|
|
nLimit = int32(100)
|
|
}
|
|
aOp5 = _sqlite3VdbeGetOp(tls, v, 0)
|
|
iEnd = _sqlite3VdbeCurrentAddr(tls, v)
|
|
iAddr1 = 0
|
|
for {
|
|
if !(iAddr1 < iEnd) {
|
|
break
|
|
}
|
|
if libc.Int32FromUint8((**(**TVdbeOp)(__ccgo_up(aOp5 + uintptr(iAddr1)*20))).Fopcode) == int32(OP_SqlExec) {
|
|
(**(**TVdbeOp)(__ccgo_up(aOp5 + uintptr(iAddr1)*20))).Fp2 = nLimit
|
|
}
|
|
goto _77
|
|
_77:
|
|
;
|
|
iAddr1 = iAddr1 + 1
|
|
}
|
|
}
|
|
break
|
|
/*
|
|
** PRAGMA busy_timeout
|
|
** PRAGMA busy_timeout = N
|
|
**
|
|
** Call sqlite3_busy_timeout(db, N). Return the current timeout value
|
|
** if one is set. If no busy handler or a different busy handler is set
|
|
** then 0 is returned. Setting the busy_timeout to 0 or negative
|
|
** disables the timeout.
|
|
*/
|
|
/*case PragTyp_BUSY_TIMEOUT*/
|
|
fallthrough
|
|
default:
|
|
if zRight != 0 {
|
|
Xsqlite3_busy_timeout(tls, db, _sqlite3Atoi(tls, zRight))
|
|
}
|
|
_returnSingleInt(tls, v, int64((*Tsqlite3)(unsafe.Pointer(db)).FbusyTimeout))
|
|
break
|
|
/*
|
|
** PRAGMA soft_heap_limit
|
|
** PRAGMA soft_heap_limit = N
|
|
**
|
|
** IMPLEMENTATION-OF: R-26343-45930 This pragma invokes the
|
|
** sqlite3_soft_heap_limit64() interface with the argument N, if N is
|
|
** specified and is a non-negative integer.
|
|
** IMPLEMENTATION-OF: R-64451-07163 The soft_heap_limit pragma always
|
|
** returns the same integer that would be returned by the
|
|
** sqlite3_soft_heap_limit64(-1) C-language function.
|
|
*/
|
|
fallthrough
|
|
case int32(PragTyp_SOFT_HEAP_LIMIT):
|
|
if zRight != 0 && _sqlite3DecOrHexToI64(tls, zRight, bp+96) == SQLITE_OK {
|
|
Xsqlite3_soft_heap_limit64(tls, **(**Tsqlite3_int64)(__ccgo_up(bp + 96)))
|
|
}
|
|
_returnSingleInt(tls, v, Xsqlite3_soft_heap_limit64(tls, int64(-int32(1))))
|
|
break
|
|
/*
|
|
** PRAGMA hard_heap_limit
|
|
** PRAGMA hard_heap_limit = N
|
|
**
|
|
** Invoke sqlite3_hard_heap_limit64() to query or set the hard heap
|
|
** limit. The hard heap limit can be activated or lowered by this
|
|
** pragma, but not raised or deactivated. Only the
|
|
** sqlite3_hard_heap_limit64() C-language API can raise or deactivate
|
|
** the hard heap limit. This allows an application to set a heap limit
|
|
** constraint that cannot be relaxed by an untrusted SQL script.
|
|
*/
|
|
fallthrough
|
|
case int32(PragTyp_HARD_HEAP_LIMIT):
|
|
if zRight != 0 && _sqlite3DecOrHexToI64(tls, zRight, bp+104) == SQLITE_OK {
|
|
iPrior = Xsqlite3_hard_heap_limit64(tls, int64(-int32(1)))
|
|
if **(**Tsqlite3_int64)(__ccgo_up(bp + 104)) > 0 && (iPrior == 0 || iPrior > **(**Tsqlite3_int64)(__ccgo_up(bp + 104))) {
|
|
Xsqlite3_hard_heap_limit64(tls, **(**Tsqlite3_int64)(__ccgo_up(bp + 104)))
|
|
}
|
|
}
|
|
_returnSingleInt(tls, v, Xsqlite3_hard_heap_limit64(tls, int64(-int32(1))))
|
|
break
|
|
/*
|
|
** PRAGMA threads
|
|
** PRAGMA threads = N
|
|
**
|
|
** Configure the maximum number of worker threads. Return the new
|
|
** maximum, which might be less than requested.
|
|
*/
|
|
fallthrough
|
|
case int32(PragTyp_THREADS):
|
|
if zRight != 0 && _sqlite3DecOrHexToI64(tls, zRight, bp+112) == SQLITE_OK && **(**Tsqlite3_int64)(__ccgo_up(bp + 112)) >= 0 {
|
|
Xsqlite3_limit(tls, db, int32(SQLITE_LIMIT_WORKER_THREADS), int32(**(**Tsqlite3_int64)(__ccgo_up(bp + 112))&libc.Int64FromInt32(0x7fffffff)))
|
|
}
|
|
_returnSingleInt(tls, v, int64(Xsqlite3_limit(tls, db, int32(SQLITE_LIMIT_WORKER_THREADS), -int32(1))))
|
|
break
|
|
/*
|
|
** PRAGMA analysis_limit
|
|
** PRAGMA analysis_limit = N
|
|
**
|
|
** Configure the maximum number of rows that ANALYZE will examine
|
|
** in each index that it looks at. Return the new limit.
|
|
*/
|
|
fallthrough
|
|
case int32(PragTyp_ANALYSIS_LIMIT):
|
|
if zRight != 0 && _sqlite3DecOrHexToI64(tls, zRight, bp+120) == SQLITE_OK && **(**Tsqlite3_int64)(__ccgo_up(bp + 120)) >= 0 {
|
|
(*Tsqlite3)(unsafe.Pointer(db)).FnAnalysisLimit = int32(**(**Tsqlite3_int64)(__ccgo_up(bp + 120)) & libc.Int64FromInt32(0x7fffffff))
|
|
}
|
|
_returnSingleInt(tls, v, int64((*Tsqlite3)(unsafe.Pointer(db)).FnAnalysisLimit)) /* IMP: R-57594-65522 */
|
|
break
|
|
} /* End of the PRAGMA switch */
|
|
/* The following block is a no-op unless SQLITE_DEBUG is defined. Its only
|
|
** purpose is to execute assert() statements to verify that if the
|
|
** PragFlg_NoColumns1 flag is set and the caller specified an argument
|
|
** to the PRAGMA, the implementation has not added any OP_ResultRow
|
|
** instructions to the VM. */
|
|
if libc.Int32FromUint8((*TPragmaName)(unsafe.Pointer(pPragma)).FmPragFlg)&int32(PragFlg_NoColumns1) != 0 && zRight != 0 {
|
|
}
|
|
goto pragma_out
|
|
pragma_out:
|
|
;
|
|
_sqlite3DbFree(tls, db, zLeft)
|
|
_sqlite3DbFree(tls, db, zRight)
|
|
}
|
|
|
|
// C documentation
|
|
//
|
|
// /*
|
|
// ** Compile the UTF-8 encoded SQL statement zSql into a statement handle.
|
|
// */
|
|
func _sqlite3Prepare(tls *libc.TLS, db uintptr, zSql uintptr, nBytes int32, prepFlags Tu32, pReprepare uintptr, ppStmt uintptr, pzTail uintptr) (r int32) {
|
|
bp := tls.Alloc(304)
|
|
defer tls.Free(304)
|
|
var i, mxLen, rc, v1 int32
|
|
var pBt, pT, zDb, zSqlCopy uintptr
|
|
var _ /* sParse at bp+0 */ TParse
|
|
_, _, _, _, _, _, _, _ = i, mxLen, pBt, pT, rc, zDb, zSqlCopy, v1
|
|
rc = SQLITE_OK /* Parsing context */
|
|
/* sqlite3ParseObjectInit(&sParse, db); // inlined for performance */
|
|
libc.Xmemset(tls, bp+uintptr(uint32(libc.UintptrFromInt32(0)+4)), 0, uint32(libc.UintptrFromInt32(0)+136)-uint32(libc.UintptrFromInt32(0)+4))
|
|
libc.Xmemset(tls, bp+uintptr(uint32(libc.UintptrFromInt32(0)+208)), 0, libc.Uint32FromInt64(284)-uint32(libc.UintptrFromInt32(0)+208))
|
|
(**(**TParse)(__ccgo_up(bp))).FpOuterParse = (*Tsqlite3)(unsafe.Pointer(db)).FpParse
|
|
(*Tsqlite3)(unsafe.Pointer(db)).FpParse = bp
|
|
(**(**TParse)(__ccgo_up(bp))).Fdb = db
|
|
if pReprepare != 0 {
|
|
(**(**TParse)(__ccgo_up(bp))).FpReprepare = pReprepare
|
|
(**(**TParse)(__ccgo_up(bp))).Fexplain = libc.Uint8FromInt32(Xsqlite3_stmt_isexplain(tls, pReprepare))
|
|
} else {
|
|
}
|
|
if (*Tsqlite3)(unsafe.Pointer(db)).FmallocFailed != 0 {
|
|
_sqlite3ErrorMsg(tls, bp, __ccgo_ts+1672, 0)
|
|
v1 = libc.Int32FromInt32(SQLITE_NOMEM)
|
|
rc = v1
|
|
(*Tsqlite3)(unsafe.Pointer(db)).FerrCode = v1
|
|
goto end_prepare
|
|
}
|
|
/* For a long-term use prepared statement avoid the use of
|
|
** lookaside memory.
|
|
*/
|
|
if prepFlags&uint32(SQLITE_PREPARE_PERSISTENT) != 0 {
|
|
(**(**TParse)(__ccgo_up(bp))).FdisableLookaside = (**(**TParse)(__ccgo_up(bp))).FdisableLookaside + 1
|
|
(*Tsqlite3)(unsafe.Pointer(db)).Flookaside.FbDisable = (*Tsqlite3)(unsafe.Pointer(db)).Flookaside.FbDisable + 1
|
|
(*Tsqlite3)(unsafe.Pointer(db)).Flookaside.Fsz = uint16(0)
|
|
}
|
|
(**(**TParse)(__ccgo_up(bp))).FprepFlags = uint8(prepFlags & uint32(0xff))
|
|
/* Check to verify that it is possible to get a read lock on all
|
|
** database schemas. The inability to get a read lock indicates that
|
|
** some other database connection is holding a write-lock, which in
|
|
** turn means that the other connection has made uncommitted changes
|
|
** to the schema.
|
|
**
|
|
** Were we to proceed and prepare the statement against the uncommitted
|
|
** schema changes and if those schema changes are subsequently rolled
|
|
** back and different changes are made in their place, then when this
|
|
** prepared statement goes to run the schema cookie would fail to detect
|
|
** the schema change. Disaster would follow.
|
|
**
|
|
** This thread is currently holding mutexes on all Btrees (because
|
|
** of the sqlite3BtreeEnterAll() in sqlite3LockAndPrepare()) so it
|
|
** is not possible for another thread to start a new schema change
|
|
** while this routine is running. Hence, we do not need to hold
|
|
** locks on the schema, we just need to make sure nobody else is
|
|
** holding them.
|
|
**
|
|
** Note that setting READ_UNCOMMITTED overrides most lock detection,
|
|
** but it does *not* override schema lock detection, so this all still
|
|
** works even if READ_UNCOMMITTED is set.
|
|
*/
|
|
if !((*Tsqlite3)(unsafe.Pointer(db)).FnoSharedCache != 0) {
|
|
i = 0
|
|
for {
|
|
if !(i < (*Tsqlite3)(unsafe.Pointer(db)).FnDb) {
|
|
break
|
|
}
|
|
pBt = (**(**TDb)(__ccgo_up((*Tsqlite3)(unsafe.Pointer(db)).FaDb + uintptr(i)*16))).FpBt
|
|
if pBt != 0 {
|
|
rc = _sqlite3BtreeSchemaLocked(tls, pBt)
|
|
if rc != 0 {
|
|
zDb = (**(**TDb)(__ccgo_up((*Tsqlite3)(unsafe.Pointer(db)).FaDb + uintptr(i)*16))).FzDbSName
|
|
_sqlite3ErrorWithMsg(tls, db, rc, __ccgo_ts+20237, libc.VaList(bp+296, zDb))
|
|
goto end_prepare
|
|
}
|
|
}
|
|
goto _2
|
|
_2:
|
|
;
|
|
i = i + 1
|
|
}
|
|
}
|
|
if (*Tsqlite3)(unsafe.Pointer(db)).FpDisconnect != 0 {
|
|
_sqlite3VtabUnlockList(tls, db)
|
|
}
|
|
if nBytes >= 0 && (nBytes == 0 || int32(**(**int8)(__ccgo_up(zSql + uintptr(nBytes-int32(1))))) != 0) {
|
|
mxLen = **(**int32)(__ccgo_up(db + 116 + 1*4))
|
|
if nBytes > mxLen {
|
|
_sqlite3ErrorWithMsg(tls, db, int32(SQLITE_TOOBIG), __ccgo_ts+20267, 0)
|
|
rc = _sqlite3ApiExit(tls, db, int32(SQLITE_TOOBIG))
|
|
goto end_prepare
|
|
}
|
|
zSqlCopy = _sqlite3DbStrNDup(tls, db, zSql, libc.Uint64FromInt32(nBytes))
|
|
if zSqlCopy != 0 {
|
|
_sqlite3RunParser(tls, bp, zSqlCopy)
|
|
(**(**TParse)(__ccgo_up(bp))).FzTail = zSql + uintptr(int32((**(**TParse)(__ccgo_up(bp))).FzTail)-int32(zSqlCopy))
|
|
_sqlite3DbFree(tls, db, zSqlCopy)
|
|
} else {
|
|
(**(**TParse)(__ccgo_up(bp))).FzTail = zSql + uintptr(nBytes)
|
|
}
|
|
} else {
|
|
_sqlite3RunParser(tls, bp, zSql)
|
|
}
|
|
if pzTail != 0 {
|
|
**(**uintptr)(__ccgo_up(pzTail)) = (**(**TParse)(__ccgo_up(bp))).FzTail
|
|
}
|
|
if libc.Int32FromUint8((*Tsqlite3)(unsafe.Pointer(db)).Finit1.Fbusy) == 0 {
|
|
_sqlite3VdbeSetSql(tls, (**(**TParse)(__ccgo_up(bp))).FpVdbe, zSql, int32((**(**TParse)(__ccgo_up(bp))).FzTail)-int32(zSql), uint8(prepFlags))
|
|
}
|
|
if (*Tsqlite3)(unsafe.Pointer(db)).FmallocFailed != 0 {
|
|
(**(**TParse)(__ccgo_up(bp))).Frc = int32(SQLITE_NOMEM)
|
|
libc.SetBitFieldPtr16Uint32(bp+28, libc.Uint32FromInt32(0), 8, 0x100)
|
|
}
|
|
if (**(**TParse)(__ccgo_up(bp))).Frc != SQLITE_OK && (**(**TParse)(__ccgo_up(bp))).Frc != int32(SQLITE_DONE) {
|
|
if int32(Tbft(*(*uint16)(unsafe.Pointer(bp + 28))&0x100>>8)) != 0 && libc.Int32FromUint8((*Tsqlite3)(unsafe.Pointer(db)).Finit1.Fbusy) == 0 {
|
|
_schemaIsValid(tls, bp)
|
|
}
|
|
if (**(**TParse)(__ccgo_up(bp))).FpVdbe != 0 {
|
|
_sqlite3VdbeFinalize(tls, (**(**TParse)(__ccgo_up(bp))).FpVdbe)
|
|
}
|
|
rc = (**(**TParse)(__ccgo_up(bp))).Frc
|
|
if (**(**TParse)(__ccgo_up(bp))).FzErrMsg != 0 {
|
|
_sqlite3ErrorWithMsg(tls, db, rc, __ccgo_ts+3942, libc.VaList(bp+296, (**(**TParse)(__ccgo_up(bp))).FzErrMsg))
|
|
_sqlite3DbFree(tls, db, (**(**TParse)(__ccgo_up(bp))).FzErrMsg)
|
|
} else {
|
|
_sqlite3Error(tls, db, rc)
|
|
}
|
|
} else {
|
|
**(**uintptr)(__ccgo_up(ppStmt)) = (**(**TParse)(__ccgo_up(bp))).FpVdbe
|
|
rc = SQLITE_OK
|
|
_sqlite3ErrorClear(tls, db)
|
|
}
|
|
/* Delete any TriggerPrg structures allocated while parsing this statement. */
|
|
for (**(**TParse)(__ccgo_up(bp))).FpTriggerPrg != 0 {
|
|
pT = (**(**TParse)(__ccgo_up(bp))).FpTriggerPrg
|
|
(**(**TParse)(__ccgo_up(bp))).FpTriggerPrg = (*TTriggerPrg)(unsafe.Pointer(pT)).FpNext
|
|
_sqlite3DbFree(tls, db, pT)
|
|
}
|
|
goto end_prepare
|
|
end_prepare:
|
|
;
|
|
_sqlite3ParseObjectReset(tls, bp)
|
|
return rc
|
|
}
|
|
|
|
// C documentation
|
|
//
|
|
// /*
|
|
// ** This routine processes the join information for a SELECT statement.
|
|
// **
|
|
// ** * A NATURAL join is converted into a USING join. After that, we
|
|
// ** do not need to be concerned with NATURAL joins and we only have
|
|
// ** think about USING joins.
|
|
// **
|
|
// ** * ON and USING clauses result in extra terms being added to the
|
|
// ** WHERE clause to enforce the specified constraints. The extra
|
|
// ** WHERE clause terms will be tagged with EP_OuterON or
|
|
// ** EP_InnerON so that we know that they originated in ON/USING.
|
|
// **
|
|
// ** The terms of a FROM clause are contained in the Select.pSrc structure.
|
|
// ** The left most table is the first entry in Select.pSrc. The right-most
|
|
// ** table is the last entry. The join operator is held in the entry to
|
|
// ** the right. Thus entry 1 contains the join operator for the join between
|
|
// ** entries 0 and 1. Any ON or USING clauses associated with the join are
|
|
// ** also attached to the right entry.
|
|
// **
|
|
// ** This routine returns the number of errors encountered.
|
|
// */
|
|
func _sqlite3ProcessJoin(tls *libc.TLS, pParse uintptr, p uintptr) (r int32) {
|
|
bp := tls.Alloc(32)
|
|
defer tls.Free(32)
|
|
var db, pE1, pE2, pEq, pFuncArgs, pLeft, pList, pRight, pRightTab, pSrc, pUsing, zName, zName1 uintptr
|
|
var i, iRightCol, j, v2 int32
|
|
var joinType Tu32
|
|
var _ /* iLeft at bp+0 */ int32
|
|
var _ /* iLeftCol at bp+4 */ int32
|
|
_, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _ = db, i, iRightCol, j, joinType, pE1, pE2, pEq, pFuncArgs, pLeft, pList, pRight, pRightTab, pSrc, pUsing, zName, zName1, v2 /* Right table being joined */
|
|
pSrc = (*TSelect)(unsafe.Pointer(p)).FpSrc
|
|
pLeft = pSrc + 8
|
|
pRight = pLeft + 1*48
|
|
i = 0
|
|
for {
|
|
if !(i < (*TSrcList)(unsafe.Pointer(pSrc)).FnSrc-int32(1)) {
|
|
break
|
|
}
|
|
pRightTab = (*TSrcItem)(unsafe.Pointer(pRight)).FpSTab
|
|
if (*TSrcItem)(unsafe.Pointer(pLeft)).FpSTab == uintptr(0) || pRightTab == uintptr(0) {
|
|
goto _1
|
|
}
|
|
if libc.Int32FromUint8((*TSrcItem)(unsafe.Pointer(pRight)).Ffg.Fjointype)&int32(JT_OUTER) != 0 {
|
|
v2 = int32(EP_OuterON)
|
|
} else {
|
|
v2 = int32(EP_InnerON)
|
|
}
|
|
joinType = libc.Uint32FromInt32(v2)
|
|
/* If this is a NATURAL join, synthesize an appropriate USING clause
|
|
** to specify which columns should be joined.
|
|
*/
|
|
if libc.Int32FromUint8((*TSrcItem)(unsafe.Pointer(pRight)).Ffg.Fjointype)&int32(JT_NATURAL) != 0 {
|
|
pUsing = uintptr(0)
|
|
if int32(*(*uint32)(unsafe.Pointer(pRight + 12 + 4))&0x800>>11) != 0 || *(*uintptr)(unsafe.Pointer(pRight + 40)) != 0 {
|
|
_sqlite3ErrorMsg(tls, pParse, __ccgo_ts+20316, libc.VaList(bp+16, 0))
|
|
return int32(1)
|
|
}
|
|
j = 0
|
|
for {
|
|
if !(j < int32((*TTable)(unsafe.Pointer(pRightTab)).FnCol)) {
|
|
break
|
|
} /* Name of column in the right table */
|
|
if libc.Int32FromUint16((*TColumn)(unsafe.Pointer((*TTable)(unsafe.Pointer(pRightTab)).FaCol+uintptr(j)*12)).FcolFlags)&int32(COLFLAG_HIDDEN) != 0 {
|
|
goto _3
|
|
}
|
|
zName = (**(**TColumn)(__ccgo_up((*TTable)(unsafe.Pointer(pRightTab)).FaCol + uintptr(j)*12))).FzCnName
|
|
if _tableAndColumnIndex(tls, pSrc, 0, i, zName, uintptr(0), uintptr(0), int32(1)) != 0 {
|
|
pUsing = _sqlite3IdListAppend(tls, pParse, pUsing, uintptr(0))
|
|
if pUsing != 0 {
|
|
(*(*TIdList_item)(unsafe.Pointer(pUsing + 4 + uintptr((*TIdList)(unsafe.Pointer(pUsing)).FnId-int32(1))*4))).FzName = _sqlite3DbStrDup(tls, (*TParse)(unsafe.Pointer(pParse)).Fdb, zName)
|
|
}
|
|
}
|
|
goto _3
|
|
_3:
|
|
;
|
|
j = j + 1
|
|
}
|
|
if pUsing != 0 {
|
|
libc.SetBitFieldPtr32Uint32(pRight+12+4, libc.Uint32FromInt32(1), 11, 0x800)
|
|
libc.SetBitFieldPtr32Uint32(pRight+12+4, libc.Uint32FromInt32(1), 13, 0x2000)
|
|
*(*uintptr)(unsafe.Pointer(pRight + 40)) = pUsing
|
|
}
|
|
if (*TParse)(unsafe.Pointer(pParse)).FnErr != 0 {
|
|
return int32(1)
|
|
}
|
|
}
|
|
/* Create extra terms on the WHERE clause for each column named
|
|
** in the USING clause. Example: If the two tables to be joined are
|
|
** A and B and the USING clause names X, Y, and Z, then add this
|
|
** to the WHERE clause: A.X=B.X AND A.Y=B.Y AND A.Z=B.Z
|
|
** Report an error if any column mentioned in the USING clause is
|
|
** not contained in both tables to be joined.
|
|
*/
|
|
if int32(*(*uint32)(unsafe.Pointer(pRight + 12 + 4))&0x800>>11) != 0 {
|
|
pList = *(*uintptr)(unsafe.Pointer(pRight + 40))
|
|
db = (*TParse)(unsafe.Pointer(pParse)).Fdb
|
|
j = 0
|
|
for {
|
|
if !(j < (*TIdList)(unsafe.Pointer(pList)).FnId) {
|
|
break
|
|
} /* Equality constraint. pE1 == pE2 */
|
|
zName1 = (*(*TIdList_item)(unsafe.Pointer(pList + 4 + uintptr(j)*4))).FzName
|
|
iRightCol = _sqlite3ColumnIndex(tls, pRightTab, zName1)
|
|
if iRightCol < 0 || _tableAndColumnIndex(tls, pSrc, 0, i, zName1, bp, bp+4, int32(*(*uint32)(unsafe.Pointer(pRight + 12 + 4))&0x2000>>13)) == 0 {
|
|
_sqlite3ErrorMsg(tls, pParse, __ccgo_ts+20366, libc.VaList(bp+16, zName1))
|
|
return int32(1)
|
|
}
|
|
pE1 = _sqlite3CreateColumnExpr(tls, db, pSrc, **(**int32)(__ccgo_up(bp)), **(**int32)(__ccgo_up(bp + 4)))
|
|
_sqlite3SrcItemColumnUsed(tls, pSrc+8+uintptr(**(**int32)(__ccgo_up(bp)))*48, **(**int32)(__ccgo_up(bp + 4)))
|
|
if libc.Int32FromUint8((*(*TSrcItem)(unsafe.Pointer(pSrc + 8))).Ffg.Fjointype)&int32(JT_LTORJ) != 0 && (*TParse)(unsafe.Pointer(pParse)).FnErr == 0 {
|
|
/* This branch runs if the query contains one or more RIGHT or FULL
|
|
** JOINs. If only a single table on the left side of this join
|
|
** contains the zName column, then this branch is a no-op.
|
|
** But if there are two or more tables on the left side
|
|
** of the join, construct a coalesce() function that gathers all
|
|
** such tables. Raise an error if more than one of those references
|
|
** to zName is not also within a prior USING clause.
|
|
**
|
|
** We really ought to raise an error if there are two or more
|
|
** non-USING references to zName on the left of an INNER or LEFT
|
|
** JOIN. But older versions of SQLite do not do that, so we avoid
|
|
** adding a new error so as to not break legacy applications.
|
|
*/
|
|
pFuncArgs = uintptr(0) /* Arguments to the coalesce() */
|
|
**(**Tu32)(__ccgo_up(pE1 + 4)) |= libc.Uint32FromInt32(libc.Int32FromInt32(EP_CanBeNull))
|
|
for _tableAndColumnIndex(tls, pSrc, **(**int32)(__ccgo_up(bp))+int32(1), i, zName1, bp, bp+4, int32(*(*uint32)(unsafe.Pointer(pRight + 12 + 4))&0x2000>>13)) != 0 {
|
|
if int32(*(*uint32)(unsafe.Pointer(pSrc + 8 + uintptr(**(**int32)(__ccgo_up(bp)))*48 + 12 + 4))&0x800>>11) == 0 || _sqlite3IdListIndex(tls, *(*uintptr)(unsafe.Pointer(pSrc + 8 + uintptr(**(**int32)(__ccgo_up(bp)))*48 + 40)), zName1) < 0 {
|
|
_sqlite3ErrorMsg(tls, pParse, __ccgo_ts+20430, libc.VaList(bp+16, zName1))
|
|
break
|
|
}
|
|
pFuncArgs = _sqlite3ExprListAppend(tls, pParse, pFuncArgs, pE1)
|
|
pE1 = _sqlite3CreateColumnExpr(tls, db, pSrc, **(**int32)(__ccgo_up(bp)), **(**int32)(__ccgo_up(bp + 4)))
|
|
_sqlite3SrcItemColumnUsed(tls, pSrc+8+uintptr(**(**int32)(__ccgo_up(bp)))*48, **(**int32)(__ccgo_up(bp + 4)))
|
|
}
|
|
if pFuncArgs != 0 {
|
|
pFuncArgs = _sqlite3ExprListAppend(tls, pParse, pFuncArgs, pE1)
|
|
pE1 = _sqlite3ExprFunction(tls, pParse, pFuncArgs, uintptr(unsafe.Pointer(&_tkCoalesce)), 0)
|
|
if pE1 != 0 {
|
|
(*TExpr)(unsafe.Pointer(pE1)).FaffExpr = int8(SQLITE_AFF_DEFER)
|
|
}
|
|
}
|
|
} else {
|
|
if libc.Int32FromUint8((*(*TSrcItem)(unsafe.Pointer(pSrc + 8 + uintptr(i+int32(1))*48))).Ffg.Fjointype)&int32(JT_LEFT) != 0 && (*TParse)(unsafe.Pointer(pParse)).FnErr == 0 {
|
|
**(**Tu32)(__ccgo_up(pE1 + 4)) |= libc.Uint32FromInt32(libc.Int32FromInt32(EP_CanBeNull))
|
|
}
|
|
}
|
|
pE2 = _sqlite3CreateColumnExpr(tls, db, pSrc, i+int32(1), iRightCol)
|
|
_sqlite3SrcItemColumnUsed(tls, pRight, iRightCol)
|
|
pEq = _sqlite3PExpr(tls, pParse, int32(TK_EQ), pE1, pE2)
|
|
if pEq != 0 {
|
|
**(**Tu32)(__ccgo_up(pEq + 4)) |= joinType
|
|
*(*int32)(unsafe.Pointer(pEq + 36)) = (*TExpr)(unsafe.Pointer(pE2)).FiTable
|
|
}
|
|
(*TSelect)(unsafe.Pointer(p)).FpWhere = _sqlite3ExprAnd(tls, pParse, (*TSelect)(unsafe.Pointer(p)).FpWhere, pEq)
|
|
goto _4
|
|
_4:
|
|
;
|
|
j = j + 1
|
|
}
|
|
} else {
|
|
if *(*uintptr)(unsafe.Pointer(pRight + 40)) != 0 {
|
|
_sqlite3SetJoinExpr(tls, *(*uintptr)(unsafe.Pointer(pRight + 40)), (*TSrcItem)(unsafe.Pointer(pRight)).FiCursor, joinType)
|
|
(*TSelect)(unsafe.Pointer(p)).FpWhere = _sqlite3ExprAnd(tls, pParse, (*TSelect)(unsafe.Pointer(p)).FpWhere, *(*uintptr)(unsafe.Pointer(pRight + 40)))
|
|
*(*uintptr)(unsafe.Pointer(pRight + 40)) = uintptr(0)
|
|
libc.SetBitFieldPtr32Uint32(pRight+12+4, libc.Uint32FromInt32(1), 12, 0x1000)
|
|
**(**Tu32)(__ccgo_up(p + 4)) |= uint32(SF_OnToWhere)
|
|
}
|
|
}
|
|
if libc.Int32FromUint8((*TTable)(unsafe.Pointer(pRightTab)).FeTabType) == int32(TABTYP_VTAB) && joinType == uint32(EP_OuterON) && *(*uintptr)(unsafe.Pointer(pRight + 32)) != 0 {
|
|
**(**Tu32)(__ccgo_up(p + 4)) |= uint32(SF_OnToWhere)
|
|
}
|
|
goto _1
|
|
_1:
|
|
;
|
|
i = i + 1
|
|
pRight += 48
|
|
pLeft += 48
|
|
}
|
|
return 0
|
|
}
|
|
|
|
// 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 + 116 + 2*4)) {
|
|
_sqlite3ErrorMsg(tls, pParse, __ccgo_ts+7728, 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 + 16))).FiOrderByCol != 0 {
|
|
if libc.Int32FromUint16((*(*struct {
|
|
FiOrderByCol Tu16
|
|
FiAlias Tu16
|
|
})(unsafe.Pointer(pItem + 16))).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 + 16))).FiOrderByCol)-int32(1), (*TExprList_item)(unsafe.Pointer(pItem)).FpExpr, 0)
|
|
}
|
|
goto _1
|
|
_1:
|
|
;
|
|
i = i + 1
|
|
pItem += 20
|
|
}
|
|
return 0
|
|
}
|
|
|
|
// C documentation
|
|
//
|
|
// /*
|
|
// ** Given a SELECT statement, generate a Table structure that describes
|
|
// ** the result set of that SELECT.
|
|
// */
|
|
func _sqlite3ResultSetOfSelect(tls *libc.TLS, pParse uintptr, pSelect uintptr, aff int8) (r uintptr) {
|
|
var db, pTab uintptr
|
|
var savedFlags Tu64
|
|
_, _, _ = db, pTab, savedFlags
|
|
db = (*TParse)(unsafe.Pointer(pParse)).Fdb
|
|
(*TParse)(unsafe.Pointer(pParse)).FnNestSel = (*TParse)(unsafe.Pointer(pParse)).FnNestSel + 1
|
|
if (*TParse)(unsafe.Pointer(pParse)).FnNestSel >= **(**int32)(__ccgo_up(db + 116 + 3*4)) {
|
|
_sqlite3ErrorMsg(tls, pParse, __ccgo_ts+20655, 0)
|
|
return uintptr(0)
|
|
}
|
|
savedFlags = (*Tsqlite3)(unsafe.Pointer(db)).Fflags
|
|
**(**Tu64)(__ccgo_up(db + 28)) &= ^libc.Uint64FromInt32(SQLITE_FullColNames)
|
|
**(**Tu64)(__ccgo_up(db + 28)) |= uint64(SQLITE_ShortColNames)
|
|
_sqlite3SelectPrep(tls, pParse, pSelect, uintptr(0))
|
|
(*Tsqlite3)(unsafe.Pointer(db)).Fflags = savedFlags
|
|
if (*TParse)(unsafe.Pointer(pParse)).FnErr != 0 {
|
|
return uintptr(0)
|
|
}
|
|
for (*TSelect)(unsafe.Pointer(pSelect)).FpPrior != 0 {
|
|
pSelect = (*TSelect)(unsafe.Pointer(pSelect)).FpPrior
|
|
}
|
|
pTab = _sqlite3DbMallocZero(tls, db, uint64(80))
|
|
if pTab == uintptr(0) {
|
|
return uintptr(0)
|
|
}
|
|
(*TTable)(unsafe.Pointer(pTab)).FnTabRef = uint32(1)
|
|
(*TTable)(unsafe.Pointer(pTab)).FzName = uintptr(0)
|
|
(*TTable)(unsafe.Pointer(pTab)).FnRowLogEst = int16(200)
|
|
_sqlite3ColumnsFromExprList(tls, pParse, (*TSelect)(unsafe.Pointer(pSelect)).FpEList, pTab+34, pTab+4)
|
|
_sqlite3SubqueryColumnTypes(tls, pParse, pTab, pSelect, aff)
|
|
(*TTable)(unsafe.Pointer(pTab)).FiPKey = int16(-int32(1))
|
|
if (*Tsqlite3)(unsafe.Pointer(db)).FmallocFailed != 0 {
|
|
_sqlite3DeleteTable(tls, db, pTab)
|
|
return uintptr(0)
|
|
}
|
|
(*TParse)(unsafe.Pointer(pParse)).FnNestSel = (*TParse)(unsafe.Pointer(pParse)).FnNestSel - 1
|
|
return pTab
|
|
}
|
|
|
|
// C documentation
|
|
//
|
|
// /*
|
|
// ** Run the parser on the given SQL string.
|
|
// */
|
|
func _sqlite3RunParser(tls *libc.TLS, pParse uintptr, zSql uintptr) (r int32) {
|
|
bp := tls.Alloc(656)
|
|
defer tls.Free(656)
|
|
var db, pEngine, pParentParse uintptr
|
|
var lastTokenParsed, nErr int32
|
|
var mxSqlLen, n Ti64
|
|
var _ /* sEngine at bp+4 */ TyyParser
|
|
var _ /* tokenType at bp+0 */ int32
|
|
var _ /* x at bp+624 */ TToken
|
|
_, _, _, _, _, _, _ = db, lastTokenParsed, mxSqlLen, n, nErr, pEngine, pParentParse
|
|
nErr = 0 /* The LEMON-generated LALR(1) parser */
|
|
n = 0 /* type of the next token */
|
|
lastTokenParsed = -int32(1) /* type of the previous token */
|
|
db = (*TParse)(unsafe.Pointer(pParse)).Fdb /* Max length of an SQL string */
|
|
pParentParse = uintptr(0) /* Space to hold the Lemon-generated Parser object */
|
|
mxSqlLen = int64(**(**int32)(__ccgo_up(db + 116 + 1*4)))
|
|
if (*Tsqlite3)(unsafe.Pointer(db)).FnVdbeActive == 0 {
|
|
libc.AtomicStoreNInt32(db+308, libc.Int32FromInt32(0), libc.Int32FromInt32(__ATOMIC_RELAXED))
|
|
}
|
|
(*TParse)(unsafe.Pointer(pParse)).Frc = SQLITE_OK
|
|
(*TParse)(unsafe.Pointer(pParse)).FzTail = zSql
|
|
pEngine = bp + 4
|
|
_sqlite3ParserInit(tls, pEngine, pParse)
|
|
pParentParse = (*Tsqlite3)(unsafe.Pointer(db)).FpParse
|
|
(*Tsqlite3)(unsafe.Pointer(db)).FpParse = pParse
|
|
for int32(1) != 0 {
|
|
n = _sqlite3GetToken(tls, zSql, bp)
|
|
mxSqlLen = mxSqlLen - n
|
|
if mxSqlLen < 0 {
|
|
(*TParse)(unsafe.Pointer(pParse)).Frc = int32(SQLITE_TOOBIG)
|
|
(*TParse)(unsafe.Pointer(pParse)).FnErr = (*TParse)(unsafe.Pointer(pParse)).FnErr + 1
|
|
break
|
|
}
|
|
if **(**int32)(__ccgo_up(bp)) >= int32(TK_WINDOW) {
|
|
if libc.AtomicLoadNInt32(db+308, libc.Int32FromInt32(__ATOMIC_RELAXED)) != 0 {
|
|
(*TParse)(unsafe.Pointer(pParse)).Frc = int32(SQLITE_INTERRUPT)
|
|
(*TParse)(unsafe.Pointer(pParse)).FnErr = (*TParse)(unsafe.Pointer(pParse)).FnErr + 1
|
|
break
|
|
}
|
|
if **(**int32)(__ccgo_up(bp)) == int32(TK_SPACE) {
|
|
zSql = zSql + uintptr(n)
|
|
continue
|
|
}
|
|
if int32(**(**int8)(__ccgo_up(zSql))) == 0 {
|
|
/* Upon reaching the end of input, call the parser two more times
|
|
** with tokens TK_SEMI and 0, in that order. */
|
|
if lastTokenParsed == int32(TK_SEMI) {
|
|
**(**int32)(__ccgo_up(bp)) = 0
|
|
} else {
|
|
if lastTokenParsed == 0 {
|
|
break
|
|
} else {
|
|
**(**int32)(__ccgo_up(bp)) = int32(TK_SEMI)
|
|
}
|
|
}
|
|
n = 0
|
|
} else {
|
|
if **(**int32)(__ccgo_up(bp)) == int32(TK_WINDOW) {
|
|
**(**int32)(__ccgo_up(bp)) = _analyzeWindowKeyword(tls, zSql+6)
|
|
} else {
|
|
if **(**int32)(__ccgo_up(bp)) == int32(TK_OVER) {
|
|
**(**int32)(__ccgo_up(bp)) = _analyzeOverKeyword(tls, zSql+4, lastTokenParsed)
|
|
} else {
|
|
if **(**int32)(__ccgo_up(bp)) == int32(TK_FILTER) {
|
|
**(**int32)(__ccgo_up(bp)) = _analyzeFilterKeyword(tls, zSql+6, lastTokenParsed)
|
|
} else {
|
|
if **(**int32)(__ccgo_up(bp)) == int32(TK_COMMENT) && ((*Tsqlite3)(unsafe.Pointer(db)).Finit1.Fbusy != 0 || (*Tsqlite3)(unsafe.Pointer(db)).Fflags&(libc.Uint64FromInt32(libc.Int32FromInt32(0x00040))<<libc.Int32FromInt32(32)) != uint64(0)) {
|
|
/* Ignore SQL comments if either (1) we are reparsing the schema or
|
|
** (2) SQLITE_DBCONFIG_ENABLE_COMMENTS is turned on (the default). */
|
|
zSql = zSql + uintptr(n)
|
|
continue
|
|
} else {
|
|
if **(**int32)(__ccgo_up(bp)) != int32(TK_QNUMBER) {
|
|
(**(**TToken)(__ccgo_up(bp + 624))).Fz = zSql
|
|
(**(**TToken)(__ccgo_up(bp + 624))).Fn = libc.Uint32FromInt64(n)
|
|
_sqlite3ErrorMsg(tls, pParse, __ccgo_ts+25219, libc.VaList(bp+640, bp+624))
|
|
break
|
|
}
|
|
}
|
|
}
|
|
}
|
|
}
|
|
}
|
|
}
|
|
(*TParse)(unsafe.Pointer(pParse)).FsLastToken.Fz = zSql
|
|
(*TParse)(unsafe.Pointer(pParse)).FsLastToken.Fn = libc.Uint32FromInt64(n)
|
|
_sqlite3Parser(tls, pEngine, **(**int32)(__ccgo_up(bp)), (*TParse)(unsafe.Pointer(pParse)).FsLastToken)
|
|
lastTokenParsed = **(**int32)(__ccgo_up(bp))
|
|
zSql = zSql + uintptr(n)
|
|
if (*TParse)(unsafe.Pointer(pParse)).Frc != SQLITE_OK {
|
|
break
|
|
}
|
|
}
|
|
_sqlite3ParserFinalize(tls, pEngine)
|
|
if (*Tsqlite3)(unsafe.Pointer(db)).FmallocFailed != 0 {
|
|
(*TParse)(unsafe.Pointer(pParse)).Frc = int32(SQLITE_NOMEM)
|
|
}
|
|
if (*TParse)(unsafe.Pointer(pParse)).FzErrMsg != 0 || (*TParse)(unsafe.Pointer(pParse)).Frc != SQLITE_OK && (*TParse)(unsafe.Pointer(pParse)).Frc != int32(SQLITE_DONE) {
|
|
if (*TParse)(unsafe.Pointer(pParse)).FzErrMsg == uintptr(0) {
|
|
(*TParse)(unsafe.Pointer(pParse)).FzErrMsg = _sqlite3DbStrDup(tls, db, _sqlite3ErrStr(tls, (*TParse)(unsafe.Pointer(pParse)).Frc))
|
|
}
|
|
if libc.Int32FromUint8((*TParse)(unsafe.Pointer(pParse)).FprepFlags)&int32(SQLITE_PREPARE_DONT_LOG) == 0 {
|
|
Xsqlite3_log(tls, (*TParse)(unsafe.Pointer(pParse)).Frc, __ccgo_ts+25244, libc.VaList(bp+640, (*TParse)(unsafe.Pointer(pParse)).FzErrMsg, (*TParse)(unsafe.Pointer(pParse)).FzTail))
|
|
}
|
|
nErr = nErr + 1
|
|
}
|
|
(*TParse)(unsafe.Pointer(pParse)).FzTail = zSql
|
|
Xsqlite3_free(tls, (*TParse)(unsafe.Pointer(pParse)).FapVtabLock)
|
|
if (*TParse)(unsafe.Pointer(pParse)).FpNewTable != 0 && !(libc.Int32FromUint8((*TParse)(unsafe.Pointer(pParse)).FeParseMode) != libc.Int32FromInt32(PARSE_MODE_NORMAL)) {
|
|
/* If the pParse->declareVtab flag is set, do not delete any table
|
|
** structure built up in pParse->pNewTable. The calling code (see vtab.c)
|
|
** will take responsibility for freeing the Table structure.
|
|
*/
|
|
_sqlite3DeleteTable(tls, db, (*TParse)(unsafe.Pointer(pParse)).FpNewTable)
|
|
}
|
|
if (*TParse)(unsafe.Pointer(pParse)).FpNewTrigger != 0 && !(libc.Int32FromUint8((*TParse)(unsafe.Pointer(pParse)).FeParseMode) >= libc.Int32FromInt32(PARSE_MODE_RENAME)) {
|
|
_sqlite3DeleteTrigger(tls, db, (*TParse)(unsafe.Pointer(pParse)).FpNewTrigger)
|
|
}
|
|
if (*TParse)(unsafe.Pointer(pParse)).FpVList != 0 {
|
|
_sqlite3DbNNFreeNN(tls, db, (*TParse)(unsafe.Pointer(pParse)).FpVList)
|
|
}
|
|
(*Tsqlite3)(unsafe.Pointer(db)).FpParse = pParentParse
|
|
return nErr
|
|
}
|
|
|
|
/************** End of tokenize.c ********************************************/
|
|
/************** Begin file complete.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.
|
|
**
|
|
*************************************************************************
|
|
** An tokenizer for SQL
|
|
**
|
|
** This file contains C code that implements the sqlite3_complete() API.
|
|
** This code used to be part of the tokenizer.c source file. But by
|
|
** separating it out, the code will be automatically omitted from
|
|
** static links that do not use it.
|
|
*/
|
|
/* #include "sqliteInt.h" */
|
|
|
|
/*
|
|
** This is defined in tokenize.c. We just have to import the definition.
|
|
*/
|
|
|
|
/*
|
|
** Token types used by the sqlite3_complete() routine. See the header
|
|
** comments on that procedure for additional information.
|
|
*/
|
|
|
|
// C documentation
|
|
//
|
|
// /*
|
|
// ** This routine implements the OP_Vacuum opcode of the VDBE.
|
|
// */
|
|
func _sqlite3RunVacuum(tls *libc.TLS, pzErrMsg uintptr, db uintptr, iDb int32, pOut uintptr) (r int32) {
|
|
bp := tls.Alloc(112)
|
|
defer tls.Free(112)
|
|
var i, isMemDb, nDb, nNew, nRes, rc, v1 int32
|
|
var id, pDb, pMain, pTemp, zDbMain, zFilename, zOut uintptr
|
|
var pgflags, saved_mDbFlags, saved_openFlags Tu32
|
|
var saved_flags Tu64
|
|
var saved_mTrace Tu8
|
|
var saved_nChange, saved_nTotalChange Ti64
|
|
var _ /* iRandom at bp+0 */ Tu64
|
|
var _ /* meta at bp+64 */ Tu32
|
|
var _ /* sz at bp+56 */ Ti64
|
|
var _ /* zDbVacuum at bp+8 */ [42]int8
|
|
_, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _ = i, id, isMemDb, nDb, nNew, nRes, pDb, pMain, pTemp, pgflags, rc, saved_flags, saved_mDbFlags, saved_mTrace, saved_nChange, saved_nTotalChange, saved_openFlags, zDbMain, zFilename, zOut, v1
|
|
rc = SQLITE_OK /* Saved trace settings */
|
|
pDb = uintptr(0) /* Name of output file */
|
|
pgflags = uint32(PAGER_SYNCHRONOUS_OFF) /* Name of the ATTACH-ed database used for vacuum */
|
|
if !((*Tsqlite3)(unsafe.Pointer(db)).FautoCommit != 0) {
|
|
_sqlite3SetString(tls, pzErrMsg, db, __ccgo_ts+22739)
|
|
return int32(SQLITE_ERROR) /* IMP: R-12218-18073 */
|
|
}
|
|
if (*Tsqlite3)(unsafe.Pointer(db)).FnVdbeActive > int32(1) {
|
|
_sqlite3SetString(tls, pzErrMsg, db, __ccgo_ts+22779)
|
|
return int32(SQLITE_ERROR) /* IMP: R-15610-35227 */
|
|
}
|
|
saved_openFlags = (*Tsqlite3)(unsafe.Pointer(db)).FopenFlags
|
|
if pOut != 0 {
|
|
if Xsqlite3_value_type(tls, pOut) != int32(SQLITE_TEXT) {
|
|
_sqlite3SetString(tls, pzErrMsg, db, __ccgo_ts+22822)
|
|
return int32(SQLITE_ERROR)
|
|
}
|
|
zOut = Xsqlite3_value_text(tls, pOut)
|
|
**(**uint32)(__ccgo_up(db + 56)) &= libc.Uint32FromInt32(^libc.Int32FromInt32(SQLITE_OPEN_READONLY))
|
|
**(**uint32)(__ccgo_up(db + 56)) |= libc.Uint32FromInt32(libc.Int32FromInt32(SQLITE_OPEN_CREATE) | libc.Int32FromInt32(SQLITE_OPEN_READWRITE))
|
|
} else {
|
|
zOut = __ccgo_ts + 1702
|
|
}
|
|
/* Save the current value of the database flags so that it can be
|
|
** restored before returning. Then set the writable-schema flag, and
|
|
** disable CHECK and foreign key constraints. */
|
|
saved_flags = (*Tsqlite3)(unsafe.Pointer(db)).Fflags
|
|
saved_mDbFlags = (*Tsqlite3)(unsafe.Pointer(db)).FmDbFlags
|
|
saved_nChange = (*Tsqlite3)(unsafe.Pointer(db)).FnChange
|
|
saved_nTotalChange = (*Tsqlite3)(unsafe.Pointer(db)).FnTotalChange
|
|
saved_mTrace = (*Tsqlite3)(unsafe.Pointer(db)).FmTrace
|
|
**(**Tu64)(__ccgo_up(db + 28)) |= libc.Uint64FromInt32(libc.Int32FromInt32(SQLITE_WriteSchema)|libc.Int32FromInt32(SQLITE_IgnoreChecks)) | libc.Uint64FromInt32(libc.Int32FromInt32(0x00040))<<libc.Int32FromInt32(32) | libc.Uint64FromInt32(libc.Int32FromInt32(0x00010))<<libc.Int32FromInt32(32) | libc.Uint64FromInt32(libc.Int32FromInt32(0x00020))<<libc.Int32FromInt32(32)
|
|
**(**Tu32)(__ccgo_up(db + 24)) |= libc.Uint32FromInt32(libc.Int32FromInt32(DBFLAG_PreferBuiltin) | libc.Int32FromInt32(DBFLAG_Vacuum))
|
|
**(**Tu64)(__ccgo_up(db + 28)) &= ^(libc.Uint64FromInt32(libc.Int32FromInt32(SQLITE_ForeignKeys)|libc.Int32FromInt32(SQLITE_ReverseOrder)|libc.Int32FromInt32(SQLITE_Defensive)) | libc.Uint64FromInt32(libc.Int32FromInt32(0x00001))<<libc.Int32FromInt32(32))
|
|
(*Tsqlite3)(unsafe.Pointer(db)).FmTrace = uint8(0)
|
|
zDbMain = (**(**TDb)(__ccgo_up((*Tsqlite3)(unsafe.Pointer(db)).FaDb + uintptr(iDb)*16))).FzDbSName
|
|
pMain = (**(**TDb)(__ccgo_up((*Tsqlite3)(unsafe.Pointer(db)).FaDb + uintptr(iDb)*16))).FpBt
|
|
isMemDb = _sqlite3PagerIsMemdb(tls, _sqlite3BtreePager(tls, pMain))
|
|
/* Attach the temporary database as 'vacuum_XXXXXX'. The synchronous pragma
|
|
** can be set to 'off' for this file, as it is not recovered if a crash
|
|
** occurs anyway. The integrity of the database is maintained by a
|
|
** (possibly synchronous) transaction opened on the main database before
|
|
** sqlite3BtreeCopyFile() is called.
|
|
**
|
|
** An optimization would be to use a non-journaled pager.
|
|
** (Later:) I tried setting "PRAGMA vacuum_XXXXXX.journal_mode=OFF" but
|
|
** that actually made the VACUUM run slower. Very little journalling
|
|
** actually occurs when doing a vacuum since the vacuum_db is initially
|
|
** empty. Only the journal header is written. Apparently it takes more
|
|
** time to parse and run the PRAGMA to turn journalling off than it does
|
|
** to write the journal header file.
|
|
*/
|
|
Xsqlite3_randomness(tls, int32(8), bp)
|
|
Xsqlite3_snprintf(tls, int32(42), bp+8, __ccgo_ts+22840, libc.VaList(bp+80, **(**Tu64)(__ccgo_up(bp))))
|
|
nDb = (*Tsqlite3)(unsafe.Pointer(db)).FnDb
|
|
rc = _execSqlF(tls, db, pzErrMsg, __ccgo_ts+22855, libc.VaList(bp+80, zOut, bp+8))
|
|
(*Tsqlite3)(unsafe.Pointer(db)).FopenFlags = saved_openFlags
|
|
if rc != SQLITE_OK {
|
|
goto end_of_vacuum
|
|
}
|
|
pDb = (*Tsqlite3)(unsafe.Pointer(db)).FaDb + uintptr(nDb)*16
|
|
pTemp = (*TDb)(unsafe.Pointer(pDb)).FpBt
|
|
nRes = _sqlite3BtreeGetRequestedReserve(tls, pMain)
|
|
if pOut != 0 {
|
|
id = _sqlite3PagerFile(tls, _sqlite3BtreePager(tls, pTemp))
|
|
**(**Ti64)(__ccgo_up(bp + 56)) = 0
|
|
if (*Tsqlite3_file)(unsafe.Pointer(id)).FpMethods != uintptr(0) && (_sqlite3OsFileSize(tls, id, bp+56) != SQLITE_OK || **(**Ti64)(__ccgo_up(bp + 56)) > 0) {
|
|
rc = int32(SQLITE_ERROR)
|
|
_sqlite3SetString(tls, pzErrMsg, db, __ccgo_ts+22871)
|
|
goto end_of_vacuum
|
|
}
|
|
**(**Tu32)(__ccgo_up(db + 24)) |= uint32(DBFLAG_VacuumInto)
|
|
/* For a VACUUM INTO, the pager-flags are set to the same values as
|
|
** they are for the database being vacuumed, except that PAGER_CACHESPILL
|
|
** is always set. */
|
|
pgflags = uint32(uint64((**(**TDb)(__ccgo_up((*Tsqlite3)(unsafe.Pointer(db)).FaDb + uintptr(iDb)*16))).Fsafety_level) | (*Tsqlite3)(unsafe.Pointer(db)).Fflags&uint64(PAGER_FLAGS_MASK))
|
|
/* If the VACUUM INTO target file is a URI filename and if the
|
|
** "reserve=N" query parameter is present, reset the reserve to the
|
|
** amount specified, if the amount is within range */
|
|
zFilename = _sqlite3BtreeGetFilename(tls, pTemp)
|
|
if zFilename != 0 {
|
|
nNew = int32(Xsqlite3_uri_int64(tls, zFilename, __ccgo_ts+22898, int64(nRes)))
|
|
if nNew >= 0 && nNew <= int32(255) {
|
|
nRes = nNew
|
|
}
|
|
}
|
|
}
|
|
_sqlite3BtreeSetCacheSize(tls, pTemp, (*TSchema)(unsafe.Pointer((**(**TDb)(__ccgo_up((*Tsqlite3)(unsafe.Pointer(db)).FaDb + uintptr(iDb)*16))).FpSchema)).Fcache_size)
|
|
_sqlite3BtreeSetSpillSize(tls, pTemp, _sqlite3BtreeSetSpillSize(tls, pMain, 0))
|
|
_sqlite3BtreeSetPagerFlags(tls, pTemp, pgflags|uint32(PAGER_CACHESPILL))
|
|
/* Begin a transaction and take an exclusive lock on the main database
|
|
** file. This is done before the sqlite3BtreeGetPageSize(pMain) call below,
|
|
** to ensure that we do not try to change the page-size on a WAL database.
|
|
*/
|
|
rc = _execSql(tls, db, pzErrMsg, __ccgo_ts+16105)
|
|
if rc != SQLITE_OK {
|
|
goto end_of_vacuum
|
|
}
|
|
if pOut == uintptr(0) {
|
|
v1 = int32(2)
|
|
} else {
|
|
v1 = 0
|
|
}
|
|
rc = _sqlite3BtreeBeginTrans(tls, pMain, v1, uintptr(0))
|
|
if rc != SQLITE_OK {
|
|
goto end_of_vacuum
|
|
}
|
|
/* Do not attempt to change the page size for a WAL database */
|
|
if _sqlite3PagerGetJournalMode(tls, _sqlite3BtreePager(tls, pMain)) == int32(PAGER_JOURNALMODE_WAL) && pOut == uintptr(0) {
|
|
(*Tsqlite3)(unsafe.Pointer(db)).FnextPagesize = 0
|
|
}
|
|
if _sqlite3BtreeSetPageSize(tls, pTemp, _sqlite3BtreeGetPageSize(tls, pMain), nRes, 0) != 0 || !(isMemDb != 0) && _sqlite3BtreeSetPageSize(tls, pTemp, (*Tsqlite3)(unsafe.Pointer(db)).FnextPagesize, nRes, 0) != 0 || (*Tsqlite3)(unsafe.Pointer(db)).FmallocFailed != 0 {
|
|
rc = int32(SQLITE_NOMEM)
|
|
goto end_of_vacuum
|
|
}
|
|
if int32((*Tsqlite3)(unsafe.Pointer(db)).FnextAutovac) >= 0 {
|
|
v1 = int32((*Tsqlite3)(unsafe.Pointer(db)).FnextAutovac)
|
|
} else {
|
|
v1 = _sqlite3BtreeGetAutoVacuum(tls, pMain)
|
|
}
|
|
_sqlite3BtreeSetAutoVacuum(tls, pTemp, v1)
|
|
/* Query the schema of the main database. Create a mirror schema
|
|
** in the temporary database.
|
|
*/
|
|
(*Tsqlite3)(unsafe.Pointer(db)).Finit1.FiDb = libc.Uint8FromInt32(nDb) /* force new CREATE statements into vacuum_db */
|
|
rc = _execSqlF(tls, db, pzErrMsg, __ccgo_ts+22906, libc.VaList(bp+80, zDbMain))
|
|
if rc != SQLITE_OK {
|
|
goto end_of_vacuum
|
|
}
|
|
rc = _execSqlF(tls, db, pzErrMsg, __ccgo_ts+23014, libc.VaList(bp+80, zDbMain))
|
|
if rc != SQLITE_OK {
|
|
goto end_of_vacuum
|
|
}
|
|
(*Tsqlite3)(unsafe.Pointer(db)).Finit1.FiDb = uint8(0)
|
|
/* Loop through the tables in the main database. For each, do
|
|
** an "INSERT INTO vacuum_db.xxx SELECT * FROM main.xxx;" to copy
|
|
** the contents to the temporary database.
|
|
*/
|
|
rc = _execSqlF(tls, db, pzErrMsg, __ccgo_ts+23068, libc.VaList(bp+80, bp+8, zDbMain, bp+8))
|
|
**(**Tu32)(__ccgo_up(db + 24)) &= libc.Uint32FromInt32(^libc.Int32FromInt32(DBFLAG_Vacuum))
|
|
if rc != SQLITE_OK {
|
|
goto end_of_vacuum
|
|
}
|
|
/* Copy the triggers, views, and virtual tables from the main database
|
|
** over to the temporary database. None of these objects has any
|
|
** associated storage, so all we have to do is copy their entries
|
|
** from the schema table.
|
|
*/
|
|
rc = _execSqlF(tls, db, pzErrMsg, __ccgo_ts+23205, libc.VaList(bp+80, bp+8, zDbMain))
|
|
if rc != 0 {
|
|
goto end_of_vacuum
|
|
}
|
|
/* Copy Btree meta values */
|
|
i = 0
|
|
for {
|
|
if !(i < libc.Int32FromUint32(libc.Uint32FromInt64(10)/libc.Uint32FromInt64(1))) {
|
|
break
|
|
}
|
|
/* GetMeta() and UpdateMeta() cannot fail in this context because
|
|
** we already have page 1 loaded into cache and marked dirty. */
|
|
_sqlite3BtreeGetMeta(tls, pMain, libc.Int32FromUint8(_aCopy[i]), bp+64)
|
|
rc = _sqlite3BtreeUpdateMeta(tls, pTemp, libc.Int32FromUint8(_aCopy[i]), **(**Tu32)(__ccgo_up(bp + 64))+uint32(_aCopy[i+int32(1)]))
|
|
if rc != SQLITE_OK {
|
|
goto end_of_vacuum
|
|
}
|
|
goto _3
|
|
_3:
|
|
;
|
|
i = i + int32(2)
|
|
}
|
|
if pOut == uintptr(0) {
|
|
rc = _sqlite3BtreeCopyFile(tls, pMain, pTemp)
|
|
}
|
|
if rc != SQLITE_OK {
|
|
goto end_of_vacuum
|
|
}
|
|
rc = _sqlite3BtreeCommit(tls, pTemp)
|
|
if rc != SQLITE_OK {
|
|
goto end_of_vacuum
|
|
}
|
|
if pOut == uintptr(0) {
|
|
_sqlite3BtreeSetAutoVacuum(tls, pMain, _sqlite3BtreeGetAutoVacuum(tls, pTemp))
|
|
}
|
|
if pOut == uintptr(0) {
|
|
nRes = _sqlite3BtreeGetRequestedReserve(tls, pTemp)
|
|
rc = _sqlite3BtreeSetPageSize(tls, pMain, _sqlite3BtreeGetPageSize(tls, pTemp), nRes, int32(1))
|
|
}
|
|
goto end_of_vacuum
|
|
end_of_vacuum:
|
|
;
|
|
/* Restore the original value of db->flags */
|
|
(*Tsqlite3)(unsafe.Pointer(db)).Finit1.FiDb = uint8(0)
|
|
(*Tsqlite3)(unsafe.Pointer(db)).FmDbFlags = saved_mDbFlags
|
|
(*Tsqlite3)(unsafe.Pointer(db)).Fflags = saved_flags
|
|
(*Tsqlite3)(unsafe.Pointer(db)).FnChange = saved_nChange
|
|
(*Tsqlite3)(unsafe.Pointer(db)).FnTotalChange = saved_nTotalChange
|
|
(*Tsqlite3)(unsafe.Pointer(db)).FmTrace = saved_mTrace
|
|
_sqlite3BtreeSetPageSize(tls, pMain, -int32(1), 0, int32(1))
|
|
/* Currently there is an SQL level transaction open on the vacuum
|
|
** database. No locks are held on any other files (since the main file
|
|
** was committed at the btree level). So it safe to end the transaction
|
|
** by manually setting the autoCommit flag to true and detaching the
|
|
** vacuum database. The vacuum_db journal file is deleted when the pager
|
|
** is closed by the DETACH.
|
|
*/
|
|
(*Tsqlite3)(unsafe.Pointer(db)).FautoCommit = uint8(1)
|
|
if pDb != 0 {
|
|
_sqlite3BtreeClose(tls, (*TDb)(unsafe.Pointer(pDb)).FpBt)
|
|
(*TDb)(unsafe.Pointer(pDb)).FpBt = uintptr(0)
|
|
(*TDb)(unsafe.Pointer(pDb)).FpSchema = uintptr(0)
|
|
}
|
|
/* This both clears the schemas and reduces the size of the db->aDb[]
|
|
** array. */
|
|
_sqlite3ResetAllSchemasOfConnection(tls, db)
|
|
return rc
|
|
}
|
|
|
|
/* At this point, there is a write transaction open on both the
|
|
** vacuum database and the main database. Assuming no error occurs,
|
|
** both transactions are closed by this block - the main database
|
|
** transaction by sqlite3BtreeCopyFile() and the other by an explicit
|
|
** call to sqlite3BtreeCommit().
|
|
*/
|
|
|
|
// 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 + 6766
|
|
} else {
|
|
v1 = __ccgo_ts + 6286
|
|
}
|
|
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+13807, 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 + 11117
|
|
} else {
|
|
v1 = __ccgo_ts + 9379
|
|
}
|
|
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)*16))).FzDbSName
|
|
if libc.Bool(!(libc.Int32FromInt32(OMIT_TEMPDB) != 0)) && isTemp == int32(1) {
|
|
v1 = __ccgo_ts + 6766
|
|
} else {
|
|
v1 = __ccgo_ts + 6286
|
|
}
|
|
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)*16))).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 + 11117
|
|
} else {
|
|
v1 = __ccgo_ts + 9379
|
|
}
|
|
_sqlite3ErrorMsg(tls, pParse, __ccgo_ts+13848, 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+13869, libc.VaList(bp+16, zName))
|
|
goto begin_table_error
|
|
}
|
|
}
|
|
pTable = _sqlite3DbMallocZero(tls, db, uint64(80))
|
|
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)*16))).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 + 48
|
|
*(*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 + 188))).FregRowid = v7
|
|
reg1 = v7
|
|
v1 = pParse + 48
|
|
*(*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 + 188))).FregRoot = v7
|
|
reg2 = v7
|
|
v1 = pParse + 48
|
|
*(*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 + 188))).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 + 172 + 8))&0x6>>1)) != 0 {
|
|
**(**Tu32)(__ccgo_up(pTable + 28)) |= uint32(TF_Imposter)
|
|
if int32(uint32(*(*uint8)(unsafe.Pointer(db + 172 + 8))&0x6>>1)) >= int32(2) {
|
|
**(**Tu32)(__ccgo_up(pTable + 28)) |= 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+28, libc.Uint32FromInt32(1), 8, 0x100)
|
|
_sqlite3DbFree(tls, db, zName)
|
|
return
|
|
}
|
|
|
|
// C documentation
|
|
//
|
|
// /*
|
|
// ** pTab is a transient Table object that represents a subquery of some
|
|
// ** kind (maybe a parenthesized subquery in the FROM clause of a larger
|
|
// ** query, or a VIEW, or a CTE). This routine computes type information
|
|
// ** for that Table object based on the Select object that implements the
|
|
// ** subquery. For the purposes of this routine, "type information" means:
|
|
// **
|
|
// ** * The datatype name, as it might appear in a CREATE TABLE statement
|
|
// ** * Which collating sequence to use for the column
|
|
// ** * The affinity of the column
|
|
// */
|
|
func _sqlite3SubqueryColumnTypes(tls *libc.TLS, pParse uintptr, pTab uintptr, pSelect uintptr, aff int8) {
|
|
bp := tls.Alloc(48)
|
|
defer tls.Free(48)
|
|
var a, db, p, pCol, pColl, pS2, zType, v4 uintptr
|
|
var i, j, m int32
|
|
var k, n Ti64
|
|
var _ /* sNC at bp+0 */ TNameContext
|
|
_, _, _, _, _, _, _, _, _, _, _, _, _ = a, db, i, j, k, m, n, p, pCol, pColl, pS2, zType, v4
|
|
db = (*TParse)(unsafe.Pointer(pParse)).Fdb
|
|
if (*Tsqlite3)(unsafe.Pointer(db)).FmallocFailed != 0 || libc.Int32FromUint8((*TParse)(unsafe.Pointer(pParse)).FeParseMode) >= int32(PARSE_MODE_RENAME) {
|
|
return
|
|
}
|
|
for (*TSelect)(unsafe.Pointer(pSelect)).FpPrior != 0 {
|
|
pSelect = (*TSelect)(unsafe.Pointer(pSelect)).FpPrior
|
|
}
|
|
a = (*TSelect)(unsafe.Pointer(pSelect)).FpEList + 8
|
|
libc.Xmemset(tls, bp, 0, uint32(36))
|
|
(**(**TNameContext)(__ccgo_up(bp))).FpSrcList = (*TSelect)(unsafe.Pointer(pSelect)).FpSrc
|
|
i = 0
|
|
pCol = (*TTable)(unsafe.Pointer(pTab)).FaCol
|
|
for {
|
|
if !(i < int32((*TTable)(unsafe.Pointer(pTab)).FnCol)) {
|
|
break
|
|
}
|
|
m = 0
|
|
pS2 = pSelect
|
|
**(**Tu32)(__ccgo_up(pTab + 28)) |= libc.Uint32FromInt32(libc.Int32FromUint16((*TColumn)(unsafe.Pointer(pCol)).FcolFlags) & libc.Int32FromInt32(COLFLAG_NOINSERT))
|
|
p = (**(**TExprList_item)(__ccgo_up(a + uintptr(i)*20))).FpExpr
|
|
/* pCol->szEst = ... // Column size est for SELECT tables never used */
|
|
(*TColumn)(unsafe.Pointer(pCol)).Faffinity = _sqlite3ExprAffinity(tls, p)
|
|
for int32((*TColumn)(unsafe.Pointer(pCol)).Faffinity) <= int32(SQLITE_AFF_NONE) && (*TSelect)(unsafe.Pointer(pS2)).FpNext != uintptr(0) {
|
|
m = m | _sqlite3ExprDataType(tls, (*(*TExprList_item)(unsafe.Pointer((*TSelect)(unsafe.Pointer(pS2)).FpEList + 8 + uintptr(i)*20))).FpExpr)
|
|
pS2 = (*TSelect)(unsafe.Pointer(pS2)).FpNext
|
|
(*TColumn)(unsafe.Pointer(pCol)).Faffinity = _sqlite3ExprAffinity(tls, (*(*TExprList_item)(unsafe.Pointer((*TSelect)(unsafe.Pointer(pS2)).FpEList + 8 + uintptr(i)*20))).FpExpr)
|
|
}
|
|
if int32((*TColumn)(unsafe.Pointer(pCol)).Faffinity) <= int32(SQLITE_AFF_NONE) {
|
|
(*TColumn)(unsafe.Pointer(pCol)).Faffinity = aff
|
|
}
|
|
if int32((*TColumn)(unsafe.Pointer(pCol)).Faffinity) >= int32(SQLITE_AFF_TEXT) && ((*TSelect)(unsafe.Pointer(pS2)).FpNext != 0 || pS2 != pSelect) {
|
|
pS2 = (*TSelect)(unsafe.Pointer(pS2)).FpNext
|
|
for {
|
|
if !(pS2 != 0) {
|
|
break
|
|
}
|
|
m = m | _sqlite3ExprDataType(tls, (*(*TExprList_item)(unsafe.Pointer((*TSelect)(unsafe.Pointer(pS2)).FpEList + 8 + uintptr(i)*20))).FpExpr)
|
|
goto _2
|
|
_2:
|
|
;
|
|
pS2 = (*TSelect)(unsafe.Pointer(pS2)).FpNext
|
|
}
|
|
if int32((*TColumn)(unsafe.Pointer(pCol)).Faffinity) == int32(SQLITE_AFF_TEXT) && m&int32(0x01) != 0 {
|
|
(*TColumn)(unsafe.Pointer(pCol)).Faffinity = int8(SQLITE_AFF_BLOB)
|
|
} else {
|
|
if int32((*TColumn)(unsafe.Pointer(pCol)).Faffinity) >= int32(SQLITE_AFF_NUMERIC) && m&int32(0x02) != 0 {
|
|
(*TColumn)(unsafe.Pointer(pCol)).Faffinity = int8(SQLITE_AFF_BLOB)
|
|
}
|
|
}
|
|
if int32((*TColumn)(unsafe.Pointer(pCol)).Faffinity) >= int32(SQLITE_AFF_NUMERIC) && libc.Int32FromUint8((*TExpr)(unsafe.Pointer(p)).Fop) == int32(TK_CAST) {
|
|
(*TColumn)(unsafe.Pointer(pCol)).Faffinity = int8(SQLITE_AFF_FLEXNUM)
|
|
}
|
|
}
|
|
zType = _columnTypeImpl(tls, bp, p, uintptr(0), uintptr(0), uintptr(0))
|
|
if zType == uintptr(0) || int32((*TColumn)(unsafe.Pointer(pCol)).Faffinity) != int32(_sqlite3AffinityType(tls, zType, uintptr(0))) {
|
|
if int32((*TColumn)(unsafe.Pointer(pCol)).Faffinity) == int32(SQLITE_AFF_NUMERIC) || int32((*TColumn)(unsafe.Pointer(pCol)).Faffinity) == int32(SQLITE_AFF_FLEXNUM) {
|
|
zType = __ccgo_ts + 20651
|
|
} else {
|
|
zType = uintptr(0)
|
|
j = int32(1)
|
|
for {
|
|
if !(j < int32(SQLITE_N_STDTYPE)) {
|
|
break
|
|
}
|
|
if int32(_sqlite3StdTypeAffinity[j]) == int32((*TColumn)(unsafe.Pointer(pCol)).Faffinity) {
|
|
zType = _sqlite3StdType[j]
|
|
break
|
|
}
|
|
goto _3
|
|
_3:
|
|
;
|
|
j = j + 1
|
|
}
|
|
}
|
|
}
|
|
if zType != 0 {
|
|
k = libc.Int64FromUint32(libc.Xstrlen(tls, zType))
|
|
n = libc.Int64FromUint32(libc.Xstrlen(tls, (*TColumn)(unsafe.Pointer(pCol)).FzCnName))
|
|
(*TColumn)(unsafe.Pointer(pCol)).FzCnName = _sqlite3DbReallocOrFree(tls, db, (*TColumn)(unsafe.Pointer(pCol)).FzCnName, libc.Uint64FromInt64(n+k+int64(2)))
|
|
v4 = pCol + 10
|
|
*(*Tu16)(unsafe.Pointer(v4)) = Tu16(int32(*(*Tu16)(unsafe.Pointer(v4))) & ^(libc.Int32FromInt32(COLFLAG_HASTYPE) | libc.Int32FromInt32(COLFLAG_HASCOLL)))
|
|
if (*TColumn)(unsafe.Pointer(pCol)).FzCnName != 0 {
|
|
libc.Xmemcpy(tls, (*TColumn)(unsafe.Pointer(pCol)).FzCnName+uintptr(n+int64(1)), zType, libc.Uint32FromInt64(k+int64(1)))
|
|
v4 = pCol + 10
|
|
*(*Tu16)(unsafe.Pointer(v4)) = Tu16(int32(*(*Tu16)(unsafe.Pointer(v4))) | libc.Int32FromInt32(COLFLAG_HASTYPE))
|
|
}
|
|
}
|
|
pColl = _sqlite3ExprCollSeq(tls, pParse, p)
|
|
if pColl != 0 {
|
|
_sqlite3ColumnSetColl(tls, db, pCol, (*TCollSeq)(unsafe.Pointer(pColl)).FzName)
|
|
}
|
|
goto _1
|
|
_1:
|
|
;
|
|
i = i + 1
|
|
pCol += 12
|
|
}
|
|
(*TTable)(unsafe.Pointer(pTab)).FszTabRow = int16(1) /* Any non-zero value works */
|
|
}
|
|
|
|
// 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 + 116)))
|
|
if (*TIndex)(unsafe.Pointer(pIdx)).FaColExpr != 0 {
|
|
Xsqlite3_str_appendf(tls, bp, __ccgo_ts+16205, libc.VaList(bp+32, (*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)))*12))).FzCnName
|
|
if j != 0 {
|
|
Xsqlite3_str_append(tls, bp, __ccgo_ts+16216, int32(2))
|
|
}
|
|
Xsqlite3_str_appendall(tls, bp, (*TTable)(unsafe.Pointer(pTab)).FzName)
|
|
Xsqlite3_str_append(tls, bp, __ccgo_ts+1741, 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 + 56))&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
|
|
//
|
|
// /*
|
|
// ** Analyze the ON CONFLICT clause described by pUpsert. Resolve all
|
|
// ** symbols in the conflict-target.
|
|
// **
|
|
// ** Return SQLITE_OK if everything works, or an error code is something
|
|
// ** is wrong.
|
|
// */
|
|
func _sqlite3UpsertAnalyzeTarget(tls *libc.TLS, pParse uintptr, pTabList uintptr, pUpsert uintptr, pAll uintptr) (r int32) {
|
|
bp := tls.Alloc(176)
|
|
defer tls.Free(176)
|
|
var iCursor, ii, jj, nClause, nn, rc int32
|
|
var pExpr, pIdx, pTab, pTarget, pTerm, v2 uintptr
|
|
var v3 bool
|
|
var _ /* sCol at bp+36 */ [2]TExpr
|
|
var _ /* sNC at bp+0 */ TNameContext
|
|
var _ /* zWhich at bp+140 */ [16]int8
|
|
_, _, _, _, _, _, _, _, _, _, _, _, _ = iCursor, ii, jj, nClause, nn, pExpr, pIdx, pTab, pTarget, pTerm, rc, v2, v3 /* Index column converted into an Expr */
|
|
nClause = 0 /* Counter of ON CONFLICT clauses */
|
|
/* Resolve all symbolic names in the conflict-target clause, which
|
|
** includes both the list of columns and the optional partial-index
|
|
** WHERE clause.
|
|
*/
|
|
libc.Xmemset(tls, bp, 0, uint32(36))
|
|
(**(**TNameContext)(__ccgo_up(bp))).FpParse = pParse
|
|
(**(**TNameContext)(__ccgo_up(bp))).FpSrcList = pTabList
|
|
for {
|
|
if !(pUpsert != 0 && (*TUpsert)(unsafe.Pointer(pUpsert)).FpUpsertTarget != 0) {
|
|
break
|
|
}
|
|
rc = _sqlite3ResolveExprListNames(tls, bp, (*TUpsert)(unsafe.Pointer(pUpsert)).FpUpsertTarget)
|
|
if rc != 0 {
|
|
return rc
|
|
}
|
|
rc = _sqlite3ResolveExprNames(tls, bp, (*TUpsert)(unsafe.Pointer(pUpsert)).FpUpsertTargetWhere)
|
|
if rc != 0 {
|
|
return rc
|
|
}
|
|
/* Check to see if the conflict target matches the rowid. */
|
|
pTab = (*(*TSrcItem)(unsafe.Pointer(pTabList + 8))).FpSTab
|
|
pTarget = (*TUpsert)(unsafe.Pointer(pUpsert)).FpUpsertTarget
|
|
iCursor = (*(*TSrcItem)(unsafe.Pointer(pTabList + 8))).FiCursor
|
|
if v3 = (*TTable)(unsafe.Pointer(pTab)).FtabFlags&uint32(TF_WithoutRowid) == uint32(0) && (*TExprList)(unsafe.Pointer(pTarget)).FnExpr == int32(1); v3 {
|
|
v2 = (*(*TExprList_item)(unsafe.Pointer(pTarget + 8))).FpExpr
|
|
pTerm = v2
|
|
}
|
|
if v3 && libc.Int32FromUint8((*TExpr)(unsafe.Pointer(v2)).Fop) == int32(TK_COLUMN) && int32((*TExpr)(unsafe.Pointer(pTerm)).FiColumn) == -int32(1) {
|
|
/* The conflict-target is the rowid of the primary table */
|
|
goto _1
|
|
}
|
|
/* Initialize sCol[0..1] to be an expression parse tree for a
|
|
** single column of an index. The sCol[0] node will be the TK_COLLATE
|
|
** operator and sCol[1] will be the TK_COLUMN operator. Code below
|
|
** will populate the specific collation and column number values
|
|
** prior to comparing against the conflict-target expression.
|
|
*/
|
|
libc.Xmemset(tls, bp+36, 0, uint32(104))
|
|
(**(**[2]TExpr)(__ccgo_up(bp + 36)))[0].Fop = uint8(TK_COLLATE)
|
|
(**(**[2]TExpr)(__ccgo_up(bp + 36)))[0].FpLeft = bp + 36 + 1*52
|
|
(**(**[2]TExpr)(__ccgo_up(bp + 36)))[int32(1)].Fop = uint8(TK_COLUMN)
|
|
(**(**[2]TExpr)(__ccgo_up(bp + 36)))[int32(1)].FiTable = (*(*TSrcItem)(unsafe.Pointer(pTabList + 8))).FiCursor
|
|
/* Check for matches against other indexes */
|
|
pIdx = (*TTable)(unsafe.Pointer(pTab)).FpIndex
|
|
for {
|
|
if !(pIdx != 0) {
|
|
break
|
|
}
|
|
if !(libc.Int32FromUint8((*TIndex)(unsafe.Pointer(pIdx)).FonError) != libc.Int32FromInt32(OE_None)) {
|
|
goto _4
|
|
}
|
|
if (*TExprList)(unsafe.Pointer(pTarget)).FnExpr != libc.Int32FromUint16((*TIndex)(unsafe.Pointer(pIdx)).FnKeyCol) {
|
|
goto _4
|
|
}
|
|
if (*TIndex)(unsafe.Pointer(pIdx)).FpPartIdxWhere != 0 {
|
|
if (*TUpsert)(unsafe.Pointer(pUpsert)).FpUpsertTargetWhere == uintptr(0) {
|
|
goto _4
|
|
}
|
|
if _sqlite3ExprCompare(tls, pParse, (*TUpsert)(unsafe.Pointer(pUpsert)).FpUpsertTargetWhere, (*TIndex)(unsafe.Pointer(pIdx)).FpPartIdxWhere, iCursor) != 0 {
|
|
goto _4
|
|
}
|
|
}
|
|
nn = libc.Int32FromUint16((*TIndex)(unsafe.Pointer(pIdx)).FnKeyCol)
|
|
ii = 0
|
|
for {
|
|
if !(ii < nn) {
|
|
break
|
|
}
|
|
*(*uintptr)(unsafe.Pointer(bp + 36 + 8)) = **(**uintptr)(__ccgo_up((*TIndex)(unsafe.Pointer(pIdx)).FazColl + uintptr(ii)*4))
|
|
if int32(**(**Ti16)(__ccgo_up((*TIndex)(unsafe.Pointer(pIdx)).FaiColumn + uintptr(ii)*2))) == -int32(2) {
|
|
pExpr = (*(*TExprList_item)(unsafe.Pointer((*TIndex)(unsafe.Pointer(pIdx)).FaColExpr + 8 + uintptr(ii)*20))).FpExpr
|
|
if libc.Int32FromUint8((*TExpr)(unsafe.Pointer(pExpr)).Fop) != int32(TK_COLLATE) {
|
|
(**(**[2]TExpr)(__ccgo_up(bp + 36)))[0].FpLeft = pExpr
|
|
pExpr = bp + 36
|
|
}
|
|
} else {
|
|
(**(**[2]TExpr)(__ccgo_up(bp + 36)))[0].FpLeft = bp + 36 + 1*52
|
|
(**(**[2]TExpr)(__ccgo_up(bp + 36)))[int32(1)].FiColumn = **(**Ti16)(__ccgo_up((*TIndex)(unsafe.Pointer(pIdx)).FaiColumn + uintptr(ii)*2))
|
|
pExpr = bp + 36
|
|
}
|
|
jj = 0
|
|
for {
|
|
if !(jj < nn) {
|
|
break
|
|
}
|
|
if _sqlite3ExprCompare(tls, uintptr(0), (*(*TExprList_item)(unsafe.Pointer(pTarget + 8 + uintptr(jj)*20))).FpExpr, pExpr, iCursor) < int32(2) {
|
|
break /* Column ii of the index matches column jj of target */
|
|
}
|
|
goto _6
|
|
_6:
|
|
;
|
|
jj = jj + 1
|
|
}
|
|
if jj >= nn {
|
|
/* The target contains no match for column jj of the index */
|
|
break
|
|
}
|
|
goto _5
|
|
_5:
|
|
;
|
|
ii = ii + 1
|
|
}
|
|
if ii < nn {
|
|
/* Column ii of the index did not match any term of the conflict target.
|
|
** Continue the search with the next index. */
|
|
goto _4
|
|
}
|
|
(*TUpsert)(unsafe.Pointer(pUpsert)).FpUpsertIdx = pIdx
|
|
if _sqlite3UpsertOfIndex(tls, pAll, pIdx) != pUpsert {
|
|
/* Really this should be an error. The isDup ON CONFLICT clause will
|
|
** never fire. But this problem was not discovered until three years
|
|
** after multi-CONFLICT upsert was added, and so we silently ignore
|
|
** the problem to prevent breaking applications that might actually
|
|
** have redundant ON CONFLICT clauses. */
|
|
(*TUpsert)(unsafe.Pointer(pUpsert)).FisDup = uint8(1)
|
|
}
|
|
break
|
|
goto _4
|
|
_4:
|
|
;
|
|
pIdx = (*TIndex)(unsafe.Pointer(pIdx)).FpNext
|
|
}
|
|
if (*TUpsert)(unsafe.Pointer(pUpsert)).FpUpsertIdx == uintptr(0) {
|
|
if nClause == 0 && (*TUpsert)(unsafe.Pointer(pUpsert)).FpNextUpsert == uintptr(0) {
|
|
(**(**[16]int8)(__ccgo_up(bp + 140)))[0] = 0
|
|
} else {
|
|
Xsqlite3_snprintf(tls, int32(16), bp+140, __ccgo_ts+22654, libc.VaList(bp+168, nClause+int32(1)))
|
|
}
|
|
_sqlite3ErrorMsg(tls, pParse, __ccgo_ts+22658, libc.VaList(bp+168, bp+140))
|
|
return int32(SQLITE_ERROR)
|
|
}
|
|
goto _1
|
|
_1:
|
|
;
|
|
pUpsert = (*TUpsert)(unsafe.Pointer(pUpsert)).FpNextUpsert
|
|
nClause = nClause + 1
|
|
}
|
|
return SQLITE_OK
|
|
}
|
|
|
|
// C documentation
|
|
//
|
|
// /*
|
|
// ** Generate bytecode that does an UPDATE as part of an upsert.
|
|
// **
|
|
// ** If pIdx is NULL, then the UNIQUE constraint that failed was the IPK.
|
|
// ** In this case parameter iCur is a cursor open on the table b-tree that
|
|
// ** currently points to the conflicting table row. Otherwise, if pIdx
|
|
// ** is not NULL, then pIdx is the constraint that failed and iCur is a
|
|
// ** cursor points to the conflicting row.
|
|
// */
|
|
func _sqlite3UpsertDoUpdate(tls *libc.TLS, pParse uintptr, pUpsert uintptr, pTab uintptr, pIdx uintptr, iCur int32) {
|
|
var db, pPk, pSrc, pTop, v uintptr
|
|
var i, iDataCur, iPk, iStorage, k, nPk, regRowid int32
|
|
_, _, _, _, _, _, _, _, _, _, _, _ = db, i, iDataCur, iPk, iStorage, k, nPk, pPk, pSrc, pTop, regRowid, v
|
|
v = (*TParse)(unsafe.Pointer(pParse)).FpVdbe
|
|
db = (*TParse)(unsafe.Pointer(pParse)).Fdb
|
|
pTop = pUpsert
|
|
iDataCur = (*TUpsert)(unsafe.Pointer(pUpsert)).FiDataCur
|
|
pUpsert = _sqlite3UpsertOfIndex(tls, pTop, pIdx)
|
|
if pIdx != 0 && iCur != iDataCur {
|
|
if (*TTable)(unsafe.Pointer(pTab)).FtabFlags&uint32(TF_WithoutRowid) == uint32(0) {
|
|
regRowid = _sqlite3GetTempReg(tls, pParse)
|
|
_sqlite3VdbeAddOp2(tls, v, int32(OP_IdxRowid), iCur, regRowid)
|
|
_sqlite3VdbeAddOp3(tls, v, int32(OP_SeekRowid), iDataCur, 0, regRowid)
|
|
_sqlite3ReleaseTempReg(tls, pParse, regRowid)
|
|
} else {
|
|
pPk = _sqlite3PrimaryKeyIndex(tls, pTab)
|
|
nPk = libc.Int32FromUint16((*TIndex)(unsafe.Pointer(pPk)).FnKeyCol)
|
|
iPk = (*TParse)(unsafe.Pointer(pParse)).FnMem + int32(1)
|
|
**(**int32)(__ccgo_up(pParse + 48)) += nPk
|
|
i = 0
|
|
for {
|
|
if !(i < nPk) {
|
|
break
|
|
}
|
|
k = _sqlite3TableColumnToIndex(tls, pIdx, int32(**(**Ti16)(__ccgo_up((*TIndex)(unsafe.Pointer(pPk)).FaiColumn + uintptr(i)*2))))
|
|
_sqlite3VdbeAddOp3(tls, v, int32(OP_Column), iCur, k, iPk+i)
|
|
goto _1
|
|
_1:
|
|
;
|
|
i = i + 1
|
|
}
|
|
i = _sqlite3VdbeAddOp4Int(tls, v, int32(OP_Found), iDataCur, 0, iPk, nPk)
|
|
_sqlite3VdbeAddOp4(tls, v, int32(OP_Halt), int32(SQLITE_CORRUPT), int32(OE_Abort), 0, __ccgo_ts+13728, -int32(1))
|
|
_sqlite3MayAbort(tls, pParse)
|
|
_sqlite3VdbeJumpHere(tls, v, i)
|
|
}
|
|
}
|
|
/* pUpsert does not own pTop->pUpsertSrc - the outer INSERT statement does.
|
|
** So we have to make a copy before passing it down into sqlite3Update() */
|
|
pSrc = _sqlite3SrcListDup(tls, db, (*TUpsert)(unsafe.Pointer(pTop)).FpUpsertSrc, 0)
|
|
/* excluded.* columns of type REAL need to be converted to a hard real */
|
|
i = 0
|
|
for {
|
|
if !(i < int32((*TTable)(unsafe.Pointer(pTab)).FnCol)) {
|
|
break
|
|
}
|
|
if int32((**(**TColumn)(__ccgo_up((*TTable)(unsafe.Pointer(pTab)).FaCol + uintptr(i)*12))).Faffinity) == int32(SQLITE_AFF_REAL) {
|
|
iStorage = (*TUpsert)(unsafe.Pointer(pTop)).FregData + int32(_sqlite3TableColumnToStorage(tls, pTab, int16(i)))
|
|
_sqlite3VdbeAddOp1(tls, v, int32(OP_RealAffinity), iStorage)
|
|
}
|
|
goto _2
|
|
_2:
|
|
;
|
|
i = i + 1
|
|
}
|
|
_sqlite3Update(tls, pParse, pSrc, _sqlite3ExprListDup(tls, db, (*TUpsert)(unsafe.Pointer(pUpsert)).FpUpsertSet, 0), _sqlite3ExprDup(tls, db, (*TUpsert)(unsafe.Pointer(pUpsert)).FpUpsertWhere, 0), int32(OE_Abort), uintptr(0), uintptr(0), pUpsert)
|
|
}
|
|
|
|
/************** End of upsert.c **********************************************/
|
|
/************** Begin file vacuum.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 VACUUM command.
|
|
**
|
|
** Most of the code in this file may be omitted by defining the
|
|
** SQLITE_OMIT_VACUUM macro.
|
|
*/
|
|
/* #include "sqliteInt.h" */
|
|
/* #include "vdbeInt.h" */
|
|
|
|
// C documentation
|
|
//
|
|
// /*
|
|
// ** Execute as much of a VDBE program as we can.
|
|
// ** This is the core of sqlite3_step().
|
|
// */
|
|
func _sqlite3VdbeExec(tls *libc.TLS, p uintptr) (r int32) {
|
|
bp := tls.Alloc(736)
|
|
defer tls.Free(736)
|
|
var aCol, aMem, aOffset, aOp, aPermute, aRoot, apArg, apArg1, db, pArgc, pBt, pBt1, pBt2, pBt3, pC, pC1, pC10, pC11, pC12, pC13, pC14, pC15, pC16, pC17, pC18, pC19, pC2, pC20, pC21, pC22, pC23, pC24, pC25, pC26, pC27, pC28, pC29, pC3, pC30, pC31, pC32, pC33, pC34, pC4, pC5, pC6, pC7, pC8, pC9, pCaller, pColl, pCrsr, pCrsr1, pCrsr2, pCrsr3, pCrsr4, pCrsr5, pCrsr6, pCrsr7, pCrsr8, pCtx, pCtx1, pCtx2, pCur, pCur1, pCur2, pCur3, pCur4, pCur5, pCur6, pCx, pCx1, pCx2, pCx3, pData, pData0, pDb, pDb1, pDb2, pDb3, pDest, pDest1, pDest2, pEnd, pFrame, pFrame1, pFrame2, pFrame3, pFrame4, pIdxKey, pIn, pIn1, pIn2, pIn3, pKey, pKeyInfo, pKeyInfo1, pKeyInfo2, pLast, pMem, pMem1, pMem2, pMem3, pMem4, pModule, pModule1, pModule2, pModule3, pModule4, pModule5, pModule6, pName, pNew, pOp, pOrig, pOut, pPager, pProgram, pQuery, pRec, pReg, pRhs, pRt, pSavepoint, pSrc, pTab, pTab1, pTab2, pTab3, pTabCur, pTmp, pVCur1, pVTab, pVar, pVtab, pVtab1, pVtab2, pVtab3, pVtab4, pVtab5, pVtab6, pVtab7, pX, pX1, pnErr, t1, z1, z2, z3, zAffinity, zAffinity1, zData, zDb, zDb1, zEndHdr, zErr, zFilename, zHdr, zHdr1, zName, zPayload, zSchema, zSql, zTab, zTrace, v191, v194 uintptr
|
|
var affinity int8
|
|
var alreadyExists, bRev, c, c1, c2, cnt, cnt1, desiredAutoCommit, eNew, eOld, eqOnly, exists, i, i1, i2, i4, i5, i6, i7, i8, i9, iCompare, iCookie, iDb, iDb1, iDb2, iDb3, iQuery, iRollback, iSavepoint, iSet, ii, ii1, isLegacy, isSchemaChange, isTransaction, len1, n, n1, n2, n4, nArg, nArg1, nCol, nField, nField1, nField2, nHdr, nKeyCol, nMem, nName, nRoot, nStep, nVarint, oc, opflags, p1, p11, p12, p13, p2, p21, pcDest, pcx, rc, res, res11, res13, res14, res21, savedAnalysisLimit, seekResult, v11, v21, wrFlag, v190, v193 int32
|
|
var colCacheCtr, iAddr, iMap, iPrior, idx, len11, n3, p22, p23, serialType, serial_type, v215, v216 Tu32
|
|
var encoding, isWriteLock, mTrace, op, p5, resetSchemaOnFault, vtabOnConflict, v227 Tu8
|
|
var flags1, flags11, flags2, flags3, flags31, newType, nullFlag, type1, type2, typeMask, v192 Tu16
|
|
var h, h1, iKey1, nAlloc, nData, nProgressLimit, nVmStep, offset64, uu Tu64
|
|
var i3, iA, iB1, iKey, iKey2, nByte, nByte1, nByte2, nCellKey, nZero, sz, v256 Ti64
|
|
var newMax, v213 uint32
|
|
var rA, rB float64
|
|
var xAuth Tsqlite3_xauth
|
|
var v206 int64
|
|
var v217 bool
|
|
var _ /* aRes at bp+552 */ [3]int32
|
|
var _ /* iA at bp+8 */ Ti64
|
|
var _ /* iB at bp+0 */ Ti64
|
|
var _ /* iMeta at bp+88 */ int32
|
|
var _ /* iMeta at bp+92 */ int32
|
|
var _ /* iMoved at bp+444 */ int32
|
|
var _ /* initData at bp+464 */ TInitData
|
|
var _ /* m at bp+404 */ TMem
|
|
var _ /* nChange at bp+448 */ Ti64
|
|
var _ /* nEntry at bp+80 */ Ti64
|
|
var _ /* nErr at bp+492 */ int32
|
|
var _ /* nullFunc at bp+640 */ TFuncDef
|
|
var _ /* pVCur at bp+604 */ uintptr
|
|
var _ /* pgno at bp+456 */ TPgno
|
|
var _ /* r at bp+100 */ TUnpackedRecord
|
|
var _ /* r at bp+132 */ TUnpackedRecord
|
|
var _ /* r at bp+160 */ TUnpackedRecord
|
|
var _ /* r at bp+340 */ TUnpackedRecord
|
|
var _ /* r at bp+376 */ TUnpackedRecord
|
|
var _ /* r at bp+504 */ TUnpackedRecord
|
|
var _ /* res at bp+128 */ int32
|
|
var _ /* res at bp+188 */ int32
|
|
var _ /* res at bp+240 */ int32
|
|
var _ /* res at bp+276 */ int32
|
|
var _ /* res at bp+288 */ int32
|
|
var _ /* res at bp+292 */ int32
|
|
var _ /* res at bp+296 */ int32
|
|
var _ /* res at bp+300 */ int32
|
|
var _ /* res at bp+336 */ int32
|
|
var _ /* res at bp+500 */ int32
|
|
var _ /* res at bp+96 */ int32
|
|
var _ /* rowid at bp+368 */ Ti64
|
|
var _ /* rowid at bp+680 */ Tsqlite_int64
|
|
var _ /* sContext at bp+612 */ Tsqlite3_context
|
|
var _ /* sMem at bp+24 */ TMem
|
|
var _ /* sMem at bp+564 */ TMem
|
|
var _ /* t at bp+64 */ Tu32
|
|
var _ /* uA at bp+16 */ Tu64
|
|
var _ /* v at bp+232 */ Ti64
|
|
var _ /* v at bp+280 */ Ti64
|
|
var _ /* v at bp+72 */ Tu64
|
|
var _ /* val at bp+536 */ Ti64
|
|
var _ /* x at bp+192 */ TMem
|
|
var _ /* x at bp+244 */ TBtreePayload
|
|
var _ /* x at bp+304 */ TBtreePayload
|
|
var _ /* x at bp+544 */ Ti64
|
|
var _ /* z at bp+496 */ uintptr
|
|
var _ /* zErr at bp+460 */ uintptr
|
|
var _ /* zErr at bp+608 */ uintptr
|
|
_, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _ = aCol, aMem, aOffset, aOp, aPermute, aRoot, affinity, alreadyExists, apArg, apArg1, bRev, c, c1, c2, cnt, cnt1, colCacheCtr, db, desiredAutoCommit, eNew, eOld, encoding, eqOnly, exists, flags1, flags11, flags2, flags3, flags31, h, h1, i, i1, i2, i3, i4, i5, i6, i7, i8, i9, iA, iAddr, iB1, iCompare, iCookie, iDb, iDb1, iDb2, iDb3, iKey, iKey1, iKey2, iMap, iPrior, iQuery, iRollback, iSavepoint, iSet, idx, ii, ii1, isLegacy, isSchemaChange, isTransaction, isWriteLock, len1, len11, mTrace, n, n1, n2, n3, n4, nAlloc, nArg, nArg1, nByte, nByte1, nByte2, nCellKey, nCol, nData, nField, nField1, nField2, nHdr, nKeyCol, nMem, nName, nProgressLimit, nRoot, nStep, nVarint, nVmStep, nZero, newMax, newType, nullFlag, oc, offset64, op, opflags, p1, p11, p12, p13, p2, p21, p22, p23, p5, pArgc, pBt, pBt1, pBt2, pBt3, pC, pC1, pC10, pC11, pC12, pC13, pC14, pC15, pC16, pC17, pC18, pC19, pC2, pC20, pC21, pC22, pC23, pC24, pC25, pC26, pC27, pC28, pC29, pC3, pC30, pC31, pC32, pC33, pC34, pC4, pC5, pC6, pC7, pC8, pC9, pCaller, pColl, pCrsr, pCrsr1, pCrsr2, pCrsr3, pCrsr4, pCrsr5, pCrsr6, pCrsr7, pCrsr8, pCtx, pCtx1, pCtx2, pCur, pCur1, pCur2, pCur3, pCur4, pCur5, pCur6, pCx, pCx1, pCx2, pCx3, pData, pData0, pDb, pDb1, pDb2, pDb3, pDest, pDest1, pDest2, pEnd, pFrame, pFrame1, pFrame2, pFrame3, pFrame4, pIdxKey, pIn, pIn1, pIn2, pIn3, pKey, pKeyInfo, pKeyInfo1, pKeyInfo2, pLast, pMem, pMem1, pMem2, pMem3, pMem4, pModule, pModule1, pModule2, pModule3, pModule4, pModule5, pModule6, pName, pNew, pOp, pOrig, pOut, pPager, pProgram, pQuery, pRec, pReg, pRhs, pRt, pSavepoint, pSrc, pTab, pTab1, pTab2, pTab3, pTabCur, pTmp, pVCur1, pVTab, pVar, pVtab, pVtab1, pVtab2, pVtab3, pVtab4, pVtab5, pVtab6, pVtab7, pX, pX1, pcDest, pcx, pnErr, rA, rB, rc, res, res11, res13, res14, res21, resetSchemaOnFault, savedAnalysisLimit, seekResult, serialType, serial_type, sz, t1, type1, type2, typeMask, uu, v11, v21, vtabOnConflict, wrFlag, xAuth, z1, z2, z3, zAffinity, zAffinity1, zData, zDb, zDb1, zEndHdr, zErr, zFilename, zHdr, zHdr1, zName, zPayload, zSchema, zSql, zTab, zTrace, v190, v191, v192, v193, v194, v206, v213, v215, v216, v217, v227, v256
|
|
aOp = (*TVdbe)(unsafe.Pointer(p)).FaOp /* Copy of p->aOp */
|
|
pOp = aOp /* Current operation */
|
|
rc = SQLITE_OK /* Value to return */
|
|
db = (*TVdbe)(unsafe.Pointer(p)).Fdb /* The database */
|
|
resetSchemaOnFault = uint8(0) /* Reset schema after an error if positive */
|
|
encoding = (*Tsqlite3)(unsafe.Pointer(db)).Fenc /* The database encoding */
|
|
iCompare = 0 /* Result of last comparison */
|
|
nVmStep = uint64(0) /* Invoke xProgress() when nVmStep reaches this */
|
|
aMem = (*TVdbe)(unsafe.Pointer(p)).FaMem /* Copy of p->aMem */
|
|
pIn1 = uintptr(0) /* 1st input operand */
|
|
pIn2 = uintptr(0) /* 2nd input operand */
|
|
pIn3 = uintptr(0) /* 3rd input operand */
|
|
pOut = uintptr(0) /* Output operand */
|
|
colCacheCtr = uint32(0) /* Column cache counter */
|
|
/*** INSERT STACK UNION HERE ***/
|
|
/* sqlite3_step() verifies this */
|
|
if (*TVdbe)(unsafe.Pointer(p)).FlockMask != uint32(0) {
|
|
_sqlite3VdbeEnter(tls, p)
|
|
}
|
|
if (*Tsqlite3)(unsafe.Pointer(db)).FxProgress != 0 {
|
|
iPrior = **(**Tu32)(__ccgo_up(p + 156 + 4*4))
|
|
nProgressLimit = uint64((*Tsqlite3)(unsafe.Pointer(db)).FnProgressOps - iPrior%(*Tsqlite3)(unsafe.Pointer(db)).FnProgressOps)
|
|
} else {
|
|
nProgressLimit = libc.Uint64FromUint32(0xffffffff) | libc.Uint64FromUint32(0xffffffff)<<libc.Int32FromInt32(32)
|
|
}
|
|
if (*TVdbe)(unsafe.Pointer(p)).Frc == int32(SQLITE_NOMEM) {
|
|
/* This happens if a malloc() inside a call to sqlite3_column_text() or
|
|
** sqlite3_column_text16() failed. */
|
|
goto no_mem
|
|
}
|
|
(*TVdbe)(unsafe.Pointer(p)).Frc = SQLITE_OK
|
|
(*TVdbe)(unsafe.Pointer(p)).FiCurrentTime = 0
|
|
(*Tsqlite3)(unsafe.Pointer(db)).FbusyHandler.FnBusy = 0
|
|
if libc.AtomicLoadNInt32(db+308, libc.Int32FromInt32(__ATOMIC_RELAXED)) != 0 {
|
|
goto abort_due_to_interrupt
|
|
}
|
|
pOp = aOp + uintptr((*TVdbe)(unsafe.Pointer(p)).Fpc)*20
|
|
for {
|
|
if !(int32(1) != 0) {
|
|
break
|
|
}
|
|
/* Errors are detected by individual opcodes, with an immediate
|
|
** jumps to abort_due_to_error. */
|
|
nVmStep = nVmStep + 1
|
|
/* Only allow tracing if SQLITE_DEBUG is defined.
|
|
*/
|
|
/* Check to see if we need to simulate an interrupt. This only happens
|
|
** if we have a special test build.
|
|
*/
|
|
/* Sanity checking on other operands */
|
|
switch libc.Int32FromUint8((*TOp)(unsafe.Pointer(pOp)).Fopcode) {
|
|
case int32(OP_Goto):
|
|
goto _2
|
|
case int32(OP_Gosub):
|
|
goto _3
|
|
case int32(OP_Return):
|
|
goto _4
|
|
case int32(OP_InitCoroutine):
|
|
goto _5
|
|
case int32(OP_EndCoroutine):
|
|
goto _6
|
|
case int32(OP_Yield):
|
|
goto _7
|
|
case int32(OP_HaltIfNull):
|
|
goto _8
|
|
case int32(OP_Halt):
|
|
goto _9
|
|
case int32(OP_Integer):
|
|
goto _10
|
|
case int32(OP_Int64):
|
|
goto _11
|
|
case int32(OP_Real):
|
|
goto _12
|
|
case int32(OP_String8):
|
|
goto _13
|
|
case int32(OP_String):
|
|
goto _14
|
|
case int32(OP_Null):
|
|
goto _15
|
|
case int32(OP_BeginSubrtn):
|
|
goto _16
|
|
case int32(OP_SoftNull):
|
|
goto _17
|
|
case int32(OP_Blob):
|
|
goto _18
|
|
case int32(OP_Variable):
|
|
goto _19
|
|
case int32(OP_Move):
|
|
goto _20
|
|
case int32(OP_Copy):
|
|
goto _21
|
|
case int32(OP_SCopy):
|
|
goto _22
|
|
case int32(OP_IntCopy):
|
|
goto _23
|
|
case int32(OP_FkCheck):
|
|
goto _24
|
|
case int32(OP_ResultRow):
|
|
goto _25
|
|
case int32(OP_Concat):
|
|
goto _26
|
|
case int32(OP_Remainder):
|
|
goto _27
|
|
case int32(OP_Divide):
|
|
goto _28
|
|
case int32(OP_Multiply):
|
|
goto _29
|
|
case int32(OP_Subtract):
|
|
goto _30
|
|
case int32(OP_Add):
|
|
goto _31
|
|
case int32(OP_CollSeq):
|
|
goto _32
|
|
case int32(OP_ShiftRight):
|
|
goto _33
|
|
case int32(OP_ShiftLeft):
|
|
goto _34
|
|
case int32(OP_BitOr):
|
|
goto _35
|
|
case int32(OP_BitAnd):
|
|
goto _36
|
|
case int32(OP_AddImm):
|
|
goto _37
|
|
case int32(OP_MustBeInt):
|
|
goto _38
|
|
case int32(OP_RealAffinity):
|
|
goto _39
|
|
case int32(OP_Cast):
|
|
goto _40
|
|
case int32(OP_Ge):
|
|
goto _41
|
|
case int32(OP_Gt):
|
|
goto _42
|
|
case int32(OP_Le):
|
|
goto _43
|
|
case int32(OP_Lt):
|
|
goto _44
|
|
case int32(OP_Ne):
|
|
goto _45
|
|
case int32(OP_Eq):
|
|
goto _46
|
|
case int32(OP_ElseEq):
|
|
goto _47
|
|
case int32(OP_Permutation):
|
|
goto _48
|
|
case int32(OP_Compare):
|
|
goto _49
|
|
case int32(OP_Jump):
|
|
goto _50
|
|
case int32(OP_Or):
|
|
goto _51
|
|
case int32(OP_And):
|
|
goto _52
|
|
case int32(OP_IsTrue):
|
|
goto _53
|
|
case int32(OP_Not):
|
|
goto _54
|
|
case int32(OP_BitNot):
|
|
goto _55
|
|
case int32(OP_Once):
|
|
goto _56
|
|
case int32(OP_If):
|
|
goto _57
|
|
case int32(OP_IfNot):
|
|
goto _58
|
|
case int32(OP_IsNull):
|
|
goto _59
|
|
case int32(OP_IsType):
|
|
goto _60
|
|
case int32(OP_ZeroOrNull):
|
|
goto _61
|
|
case int32(OP_NotNull):
|
|
goto _62
|
|
case int32(OP_IfNullRow):
|
|
goto _63
|
|
case int32(OP_Offset):
|
|
goto _64
|
|
case int32(OP_Column):
|
|
goto _65
|
|
case int32(OP_TypeCheck):
|
|
goto _66
|
|
case int32(OP_Affinity):
|
|
goto _67
|
|
case int32(OP_MakeRecord):
|
|
goto _68
|
|
case int32(OP_Count):
|
|
goto _69
|
|
case OP_Savepoint:
|
|
goto _70
|
|
case int32(OP_AutoCommit):
|
|
goto _71
|
|
case int32(OP_Transaction):
|
|
goto _72
|
|
case int32(OP_ReadCookie):
|
|
goto _73
|
|
case int32(OP_SetCookie):
|
|
goto _74
|
|
case int32(OP_OpenWrite):
|
|
goto _75
|
|
case int32(OP_OpenRead):
|
|
goto _76
|
|
case int32(OP_ReopenIdx):
|
|
goto _77
|
|
case int32(OP_OpenDup):
|
|
goto _78
|
|
case int32(OP_OpenEphemeral):
|
|
goto _79
|
|
case int32(OP_OpenAutoindex):
|
|
goto _80
|
|
case int32(OP_SorterOpen):
|
|
goto _81
|
|
case int32(OP_SequenceTest):
|
|
goto _82
|
|
case int32(OP_OpenPseudo):
|
|
goto _83
|
|
case int32(OP_Close):
|
|
goto _84
|
|
case int32(OP_SeekGT):
|
|
goto _85
|
|
case int32(OP_SeekGE):
|
|
goto _86
|
|
case int32(OP_SeekLE):
|
|
goto _87
|
|
case int32(OP_SeekLT):
|
|
goto _88
|
|
case int32(OP_SeekScan):
|
|
goto _89
|
|
case int32(OP_SeekHit):
|
|
goto _90
|
|
case int32(OP_IfNotOpen):
|
|
goto _91
|
|
case int32(OP_IfNoHope):
|
|
goto _92
|
|
case int32(OP_Found):
|
|
goto _93
|
|
case int32(OP_NotFound):
|
|
goto _94
|
|
case int32(OP_NoConflict):
|
|
goto _95
|
|
case int32(OP_NotExists):
|
|
goto _96
|
|
case int32(OP_SeekRowid):
|
|
goto _97
|
|
case int32(OP_Sequence):
|
|
goto _98
|
|
case int32(OP_NewRowid):
|
|
goto _99
|
|
case int32(OP_Insert):
|
|
goto _100
|
|
case int32(OP_RowCell):
|
|
goto _101
|
|
case int32(OP_Delete):
|
|
goto _102
|
|
case int32(OP_ResetCount):
|
|
goto _103
|
|
case int32(OP_SorterCompare):
|
|
goto _104
|
|
case int32(OP_SorterData):
|
|
goto _105
|
|
case int32(OP_RowData):
|
|
goto _106
|
|
case int32(OP_Rowid):
|
|
goto _107
|
|
case int32(OP_NullRow):
|
|
goto _108
|
|
case int32(OP_Last):
|
|
goto _109
|
|
case int32(OP_SeekEnd):
|
|
goto _110
|
|
case int32(OP_IfSizeBetween):
|
|
goto _111
|
|
case int32(OP_Sort):
|
|
goto _112
|
|
case int32(OP_SorterSort):
|
|
goto _113
|
|
case int32(OP_Rewind):
|
|
goto _114
|
|
case int32(OP_IfEmpty):
|
|
goto _115
|
|
case int32(OP_Prev):
|
|
goto _116
|
|
case int32(OP_Next):
|
|
goto _117
|
|
case int32(OP_SorterNext):
|
|
goto _118
|
|
case int32(OP_IdxInsert):
|
|
goto _119
|
|
case int32(OP_SorterInsert):
|
|
goto _120
|
|
case int32(OP_IdxDelete):
|
|
goto _121
|
|
case int32(OP_IdxRowid):
|
|
goto _122
|
|
case int32(OP_DeferredSeek):
|
|
goto _123
|
|
case int32(OP_FinishSeek):
|
|
goto _124
|
|
case int32(OP_IdxGE):
|
|
goto _125
|
|
case int32(OP_IdxLT):
|
|
goto _126
|
|
case int32(OP_IdxGT):
|
|
goto _127
|
|
case int32(OP_IdxLE):
|
|
goto _128
|
|
case int32(OP_Destroy):
|
|
goto _129
|
|
case int32(OP_Clear):
|
|
goto _130
|
|
case int32(OP_ResetSorter):
|
|
goto _131
|
|
case int32(OP_CreateBtree):
|
|
goto _132
|
|
case int32(OP_SqlExec):
|
|
goto _133
|
|
case int32(OP_ParseSchema):
|
|
goto _134
|
|
case int32(OP_LoadAnalysis):
|
|
goto _135
|
|
case int32(OP_DropTable):
|
|
goto _136
|
|
case int32(OP_DropIndex):
|
|
goto _137
|
|
case int32(OP_DropTrigger):
|
|
goto _138
|
|
case int32(OP_IntegrityCk):
|
|
goto _139
|
|
case int32(OP_IFindKey):
|
|
goto _140
|
|
case int32(OP_RowSetAdd):
|
|
goto _141
|
|
case int32(OP_RowSetRead):
|
|
goto _142
|
|
case int32(OP_RowSetTest):
|
|
goto _143
|
|
case int32(OP_Program):
|
|
goto _144
|
|
case int32(OP_Param):
|
|
goto _145
|
|
case int32(OP_FkCounter):
|
|
goto _146
|
|
case int32(OP_FkIfZero):
|
|
goto _147
|
|
case int32(OP_MemMax):
|
|
goto _148
|
|
case int32(OP_IfPos):
|
|
goto _149
|
|
case int32(OP_OffsetLimit):
|
|
goto _150
|
|
case int32(OP_IfNotZero):
|
|
goto _151
|
|
case int32(OP_DecrJumpZero):
|
|
goto _152
|
|
case int32(OP_AggStep):
|
|
goto _153
|
|
case int32(OP_AggInverse):
|
|
goto _154
|
|
case int32(OP_AggStep1):
|
|
goto _155
|
|
case int32(OP_AggFinal):
|
|
goto _156
|
|
case int32(OP_AggValue):
|
|
goto _157
|
|
case int32(OP_Checkpoint):
|
|
goto _158
|
|
case int32(OP_JournalMode):
|
|
goto _159
|
|
case int32(OP_Vacuum):
|
|
goto _160
|
|
case int32(OP_IncrVacuum):
|
|
goto _161
|
|
case int32(OP_Expire):
|
|
goto _162
|
|
case int32(OP_CursorLock):
|
|
goto _163
|
|
case int32(OP_CursorUnlock):
|
|
goto _164
|
|
case int32(OP_TableLock):
|
|
goto _165
|
|
case int32(OP_VBegin):
|
|
goto _166
|
|
case int32(OP_VCreate):
|
|
goto _167
|
|
case int32(OP_VDestroy):
|
|
goto _168
|
|
case int32(OP_VOpen):
|
|
goto _169
|
|
case int32(OP_VCheck):
|
|
goto _170
|
|
case int32(OP_VInitIn):
|
|
goto _171
|
|
case int32(OP_VFilter):
|
|
goto _172
|
|
case int32(OP_VColumn):
|
|
goto _173
|
|
case int32(OP_VNext):
|
|
goto _174
|
|
case int32(OP_VRename):
|
|
goto _175
|
|
case int32(OP_VUpdate):
|
|
goto _176
|
|
case int32(OP_Pagecount):
|
|
goto _177
|
|
case int32(OP_MaxPgcnt):
|
|
goto _178
|
|
case int32(OP_Function):
|
|
goto _179
|
|
case int32(OP_PureFunc):
|
|
goto _180
|
|
case int32(OP_ClrSubtype):
|
|
goto _181
|
|
case int32(OP_GetSubtype):
|
|
goto _182
|
|
case int32(OP_SetSubtype):
|
|
goto _183
|
|
case int32(OP_FilterAdd):
|
|
goto _184
|
|
case int32(OP_Filter):
|
|
goto _185
|
|
case int32(OP_Init):
|
|
goto _186
|
|
case int32(OP_Trace):
|
|
goto _187
|
|
default:
|
|
goto _188
|
|
}
|
|
goto _189
|
|
/*****************************************************************************
|
|
** What follows is a massive switch statement where each case implements a
|
|
** separate instruction in the virtual machine. If we follow the usual
|
|
** indentation conventions, each case should be indented by 6 spaces. But
|
|
** that is a lot of wasted space on the left margin. So the code within
|
|
** the switch statement will break with convention and be flush-left. Another
|
|
** big comment (similar to this one) will mark the point in the code where
|
|
** we transition back to normal indentation.
|
|
**
|
|
** The formatting of each case is important. The makefile for SQLite
|
|
** generates two C files "opcodes.h" and "opcodes.c" by scanning this
|
|
** file looking for lines that begin with "case OP_". The opcodes.h files
|
|
** will be filled with #defines that give unique integer values to each
|
|
** opcode and the opcodes.c file is filled with an array of strings where
|
|
** each string is the symbolic name for the corresponding opcode. If the
|
|
** case statement is followed by a comment of the form "/# same as ... #/"
|
|
** that comment is used to determine the particular value of the opcode.
|
|
**
|
|
** Other keywords in the comment that follows each case are used to
|
|
** construct the OPFLG_INITIALIZER value that initializes opcodeProperty[].
|
|
** Keywords include: in1, in2, in3, out2, out3. See
|
|
** the mkopcodeh.awk script for additional information.
|
|
**
|
|
** Documentation about VDBE opcodes is generated by scanning this file
|
|
** for lines of that contain "Opcode:". That line and all subsequent
|
|
** comment lines are used in the generation of the opcode.html documentation
|
|
** file.
|
|
**
|
|
** SUMMARY:
|
|
**
|
|
** Formatting is important to scripts that scan this file.
|
|
** Do not deviate from the formatting style currently in use.
|
|
**
|
|
*****************************************************************************/
|
|
/* Opcode: Goto * P2 * * *
|
|
**
|
|
** An unconditional jump to address P2.
|
|
** The next instruction executed will be
|
|
** the one at index P2 from the beginning of
|
|
** the program.
|
|
**
|
|
** The P1 parameter is not actually used by this opcode. However, it
|
|
** is sometimes set to 1 instead of 0 as a hint to the command-line shell
|
|
** that this Goto is the bottom of a loop and that the lines from P2 down
|
|
** to the current line should be indented for EXPLAIN output.
|
|
*/
|
|
_2:
|
|
; /* jump */
|
|
goto jump_to_p2_and_check_for_interrupt
|
|
jump_to_p2_and_check_for_interrupt:
|
|
;
|
|
pOp = aOp + uintptr((*TOp)(unsafe.Pointer(pOp)).Fp2-int32(1))*20
|
|
/* Opcodes that are used as the bottom of a loop (OP_Next, OP_Prev,
|
|
** OP_VNext, or OP_SorterNext) all jump here upon
|
|
** completion. Check to see if sqlite3_interrupt() has been called
|
|
** or if the progress callback needs to be invoked.
|
|
**
|
|
** This code uses unstructured "goto" statements and does not look clean.
|
|
** But that is not due to sloppy coding habits. The code is written this
|
|
** way for performance, to avoid having to run the interrupt and progress
|
|
** checks on every opcode. This helps sqlite3_step() to run about 1.5%
|
|
** faster according to "valgrind --tool=cachegrind" */
|
|
goto check_for_interrupt
|
|
check_for_interrupt:
|
|
;
|
|
if libc.AtomicLoadNInt32(db+308, libc.Int32FromInt32(__ATOMIC_RELAXED)) != 0 {
|
|
goto abort_due_to_interrupt
|
|
}
|
|
/* Call the progress callback if it is configured and the required number
|
|
** of VDBE ops have been executed (either since this invocation of
|
|
** sqlite3VdbeExec() or since last time the progress callback was called).
|
|
** If the progress callback returns non-zero, exit the virtual machine with
|
|
** a return code SQLITE_ABORT.
|
|
*/
|
|
for nVmStep >= nProgressLimit && (*Tsqlite3)(unsafe.Pointer(db)).FxProgress != uintptr(0) {
|
|
nProgressLimit = nProgressLimit + uint64((*Tsqlite3)(unsafe.Pointer(db)).FnProgressOps)
|
|
if (*(*func(*libc.TLS, uintptr) int32)(unsafe.Pointer(&struct{ uintptr }{(*Tsqlite3)(unsafe.Pointer(db)).FxProgress})))(tls, (*Tsqlite3)(unsafe.Pointer(db)).FpProgressArg) != 0 {
|
|
nProgressLimit = libc.Uint64FromUint32(0xffffffff) | libc.Uint64FromUint32(0xffffffff)<<libc.Int32FromInt32(32)
|
|
rc = int32(SQLITE_INTERRUPT)
|
|
goto abort_due_to_error
|
|
}
|
|
}
|
|
goto _189
|
|
/* Opcode: Gosub P1 P2 * * *
|
|
**
|
|
** Write the current address onto register P1
|
|
** and then jump to address P2.
|
|
*/
|
|
_3:
|
|
; /* jump */
|
|
pIn1 = aMem + uintptr((*TOp)(unsafe.Pointer(pOp)).Fp1)*40
|
|
(*TMem)(unsafe.Pointer(pIn1)).Fflags = uint16(MEM_Int)
|
|
*(*Ti64)(unsafe.Pointer(pIn1)) = int64((int32(pOp) - int32(aOp)) / 20)
|
|
goto jump_to_p2_and_check_for_interrupt
|
|
/* Opcode: Return P1 P2 P3 * *
|
|
**
|
|
** Jump to the address stored in register P1. If P1 is a return address
|
|
** register, then this accomplishes a return from a subroutine.
|
|
**
|
|
** If P3 is 1, then the jump is only taken if register P1 holds an integer
|
|
** values, otherwise execution falls through to the next opcode, and the
|
|
** OP_Return becomes a no-op. If P3 is 0, then register P1 must hold an
|
|
** integer or else an assert() is raised. P3 should be set to 1 when
|
|
** this opcode is used in combination with OP_BeginSubrtn, and set to 0
|
|
** otherwise.
|
|
**
|
|
** The value in register P1 is unchanged by this opcode.
|
|
**
|
|
** P2 is not used by the byte-code engine. However, if P2 is positive
|
|
** and also less than the current address, then the "EXPLAIN" output
|
|
** formatter in the CLI will indent all opcodes from the P2 opcode up
|
|
** to be not including the current Return. P2 should be the first opcode
|
|
** in the subroutine from which this opcode is returning. Thus the P2
|
|
** value is a byte-code indentation hint. See tag-20220407a in
|
|
** wherecode.c and shell.c.
|
|
*/
|
|
_4:
|
|
; /* in1 */
|
|
pIn1 = aMem + uintptr((*TOp)(unsafe.Pointer(pOp)).Fp1)*40
|
|
if libc.Int32FromUint16((*TMem)(unsafe.Pointer(pIn1)).Fflags)&int32(MEM_Int) != 0 {
|
|
if (*TOp)(unsafe.Pointer(pOp)).Fp3 != 0 {
|
|
}
|
|
pOp = aOp + uintptr(*(*Ti64)(unsafe.Pointer(pIn1)))*20
|
|
} else {
|
|
if (*TOp)(unsafe.Pointer(pOp)).Fp3 != 0 {
|
|
}
|
|
}
|
|
goto _189
|
|
/* Opcode: InitCoroutine P1 P2 P3 * *
|
|
**
|
|
** Set up register P1 so that it will Yield to the coroutine
|
|
** located at address P3.
|
|
**
|
|
** If P2!=0 then the coroutine implementation immediately follows
|
|
** this opcode. So jump over the coroutine implementation to
|
|
** address P2.
|
|
**
|
|
** See also: EndCoroutine
|
|
*/
|
|
_5:
|
|
; /* jump0 */
|
|
pOut = aMem + uintptr((*TOp)(unsafe.Pointer(pOp)).Fp1)*40
|
|
*(*Ti64)(unsafe.Pointer(pOut)) = int64((*TOp)(unsafe.Pointer(pOp)).Fp3 - int32(1))
|
|
(*TMem)(unsafe.Pointer(pOut)).Fflags = uint16(MEM_Int)
|
|
if (*TOp)(unsafe.Pointer(pOp)).Fp2 == 0 {
|
|
goto _189
|
|
}
|
|
/* Most jump operations do a goto to this spot in order to update
|
|
** the pOp pointer. */
|
|
goto jump_to_p2
|
|
jump_to_p2:
|
|
;
|
|
/* There are never any jumps to instruction 0 */
|
|
/* Jumps must be in range */
|
|
pOp = aOp + uintptr((*TOp)(unsafe.Pointer(pOp)).Fp2-int32(1))*20
|
|
goto _189
|
|
/* Opcode: EndCoroutine P1 * * * *
|
|
**
|
|
** The instruction at the address in register P1 is a Yield.
|
|
** Jump to the P2 parameter of that Yield.
|
|
** After the jump, the value register P1 is left with a value
|
|
** such that subsequent OP_Yields go back to the this same
|
|
** OP_EndCoroutine instruction.
|
|
**
|
|
** See also: InitCoroutine
|
|
*/
|
|
_6:
|
|
;
|
|
pIn1 = aMem + uintptr((*TOp)(unsafe.Pointer(pOp)).Fp1)*40
|
|
pCaller = aOp + uintptr(*(*Ti64)(unsafe.Pointer(pIn1)))*20
|
|
*(*Ti64)(unsafe.Pointer(pIn1)) = int64((int32(pOp)-int32((*TVdbe)(unsafe.Pointer(p)).FaOp))/20 - int32(1))
|
|
pOp = aOp + uintptr((*TVdbeOp)(unsafe.Pointer(pCaller)).Fp2-int32(1))*20
|
|
goto _189
|
|
/* Opcode: Yield P1 P2 * * *
|
|
**
|
|
** Swap the program counter with the value in register P1. This
|
|
** has the effect of yielding to a coroutine.
|
|
**
|
|
** If the coroutine that is launched by this instruction ends with
|
|
** Yield or Return then continue to the next instruction. But if
|
|
** the coroutine launched by this instruction ends with
|
|
** EndCoroutine, then jump to P2 rather than continuing with the
|
|
** next instruction.
|
|
**
|
|
** See also: InitCoroutine
|
|
*/
|
|
_7:
|
|
;
|
|
pIn1 = aMem + uintptr((*TOp)(unsafe.Pointer(pOp)).Fp1)*40
|
|
(*TMem)(unsafe.Pointer(pIn1)).Fflags = uint16(MEM_Int)
|
|
pcDest = int32(*(*Ti64)(unsafe.Pointer(pIn1)))
|
|
*(*Ti64)(unsafe.Pointer(pIn1)) = int64((int32(pOp) - int32(aOp)) / 20)
|
|
pOp = aOp + uintptr(pcDest)*20
|
|
goto _189
|
|
/* Opcode: HaltIfNull P1 P2 P3 P4 P5
|
|
** Synopsis: if r[P3]=null halt
|
|
**
|
|
** Check the value in register P3. If it is NULL then Halt using
|
|
** parameter P1, P2, and P4 as if this were a Halt instruction. If the
|
|
** value in register P3 is not NULL, then this routine is a no-op.
|
|
** The P5 parameter should be 1.
|
|
*/
|
|
_8:
|
|
; /* in3 */
|
|
pIn3 = aMem + uintptr((*TOp)(unsafe.Pointer(pOp)).Fp3)*40
|
|
if libc.Int32FromUint16((*TMem)(unsafe.Pointer(pIn3)).Fflags)&int32(MEM_Null) == 0 {
|
|
goto _189
|
|
}
|
|
/* Fall through into OP_Halt */
|
|
/* Opcode: Halt P1 P2 P3 P4 P5
|
|
**
|
|
** Exit immediately. All open cursors, etc are closed
|
|
** automatically.
|
|
**
|
|
** P1 is the result code returned by sqlite3_exec(), sqlite3_reset(),
|
|
** or sqlite3_finalize(). For a normal halt, this should be SQLITE_OK (0).
|
|
** For errors, it can be some other value. If P1!=0 then P2 will determine
|
|
** whether or not to rollback the current transaction. Do not rollback
|
|
** if P2==OE_Fail. Do the rollback if P2==OE_Rollback. If P2==OE_Abort,
|
|
** then back out all changes that have occurred during this execution of the
|
|
** VDBE, but do not rollback the transaction.
|
|
**
|
|
** If P3 is not zero and P4 is NULL, then P3 is a register that holds the
|
|
** text of an error message.
|
|
**
|
|
** If P3 is zero and P4 is not null then the error message string is held
|
|
** in P4.
|
|
**
|
|
** P5 is a value between 1 and 4, inclusive, then the P4 error message
|
|
** string is modified as follows:
|
|
**
|
|
** 1: NOT NULL constraint failed: P4
|
|
** 2: UNIQUE constraint failed: P4
|
|
** 3: CHECK constraint failed: P4
|
|
** 4: FOREIGN KEY constraint failed: P4
|
|
**
|
|
** If P3 is zero and P5 is not zero and P4 is NULL, then everything after
|
|
** the ":" is omitted.
|
|
**
|
|
** There is an implied "Halt 0 0 0" instruction inserted at the very end of
|
|
** every program. So a jump past the last instruction of the program
|
|
** is the same as executing Halt.
|
|
*/
|
|
_9:
|
|
;
|
|
/* A deliberately coded "OP_Halt SQLITE_INTERNAL * * * *" opcode indicates
|
|
** something is wrong with the code generator. Raise an assertion in order
|
|
** to bring this to the attention of fuzzers and other testing tools. */
|
|
if (*TVdbe)(unsafe.Pointer(p)).FpFrame != 0 && (*TOp)(unsafe.Pointer(pOp)).Fp1 == SQLITE_OK {
|
|
/* Halt the sub-program. Return control to the parent frame. */
|
|
pFrame = (*TVdbe)(unsafe.Pointer(p)).FpFrame
|
|
(*TVdbe)(unsafe.Pointer(p)).FpFrame = (*TVdbeFrame)(unsafe.Pointer(pFrame)).FpParent
|
|
(*TVdbe)(unsafe.Pointer(p)).FnFrame = (*TVdbe)(unsafe.Pointer(p)).FnFrame - 1
|
|
_sqlite3VdbeSetChanges(tls, db, (*TVdbe)(unsafe.Pointer(p)).FnChange)
|
|
pcx = _sqlite3VdbeFrameRestore(tls, pFrame)
|
|
if (*TOp)(unsafe.Pointer(pOp)).Fp2 == int32(OE_Ignore) {
|
|
/* Instruction pcx is the OP_Program that invoked the sub-program
|
|
** currently being halted. If the p2 instruction of this OP_Halt
|
|
** instruction is set to OE_Ignore, then the sub-program is throwing
|
|
** an IGNORE exception. In this case jump to the address specified
|
|
** as the p2 of the calling OP_Program. */
|
|
pcx = (**(**TOp)(__ccgo_up((*TVdbe)(unsafe.Pointer(p)).FaOp + uintptr(pcx)*20))).Fp2 - int32(1)
|
|
}
|
|
aOp = (*TVdbe)(unsafe.Pointer(p)).FaOp
|
|
aMem = (*TVdbe)(unsafe.Pointer(p)).FaMem
|
|
pOp = aOp + uintptr(pcx)*20
|
|
goto _189
|
|
}
|
|
(*TVdbe)(unsafe.Pointer(p)).Frc = (*TOp)(unsafe.Pointer(pOp)).Fp1
|
|
(*TVdbe)(unsafe.Pointer(p)).FerrorAction = libc.Uint8FromInt32((*TOp)(unsafe.Pointer(pOp)).Fp2)
|
|
if (*TVdbe)(unsafe.Pointer(p)).Frc != 0 {
|
|
if (*TOp)(unsafe.Pointer(pOp)).Fp3 > 0 && int32((*TOp)(unsafe.Pointer(pOp)).Fp4type) == P4_NOTUSED {
|
|
zErr = _sqlite3ValueText(tls, aMem+uintptr((*TOp)(unsafe.Pointer(pOp)).Fp3)*40, uint8(SQLITE_UTF8))
|
|
_sqlite3VdbeError(tls, p, __ccgo_ts+3942, libc.VaList(bp+696, zErr))
|
|
} else {
|
|
if (*TOp)(unsafe.Pointer(pOp)).Fp5 != 0 {
|
|
_sqlite3VdbeError(tls, p, __ccgo_ts+5858, libc.VaList(bp+696, _azType[libc.Int32FromUint16((*TOp)(unsafe.Pointer(pOp)).Fp5)-int32(1)]))
|
|
if *(*uintptr)(unsafe.Pointer(pOp + 16)) != 0 {
|
|
(*TVdbe)(unsafe.Pointer(p)).FzErrMsg = _sqlite3MPrintf(tls, db, __ccgo_ts+5879, libc.VaList(bp+696, (*TVdbe)(unsafe.Pointer(p)).FzErrMsg, *(*uintptr)(unsafe.Pointer(pOp + 16))))
|
|
}
|
|
} else {
|
|
_sqlite3VdbeError(tls, p, __ccgo_ts+3942, libc.VaList(bp+696, *(*uintptr)(unsafe.Pointer(pOp + 16))))
|
|
}
|
|
}
|
|
_sqlite3VdbeLogAbort(tls, p, (*TOp)(unsafe.Pointer(pOp)).Fp1, pOp, aOp)
|
|
}
|
|
rc = _sqlite3VdbeHalt(tls, p)
|
|
if rc == int32(SQLITE_BUSY) {
|
|
(*TVdbe)(unsafe.Pointer(p)).Frc = int32(SQLITE_BUSY)
|
|
} else {
|
|
if (*TVdbe)(unsafe.Pointer(p)).Frc != 0 {
|
|
v190 = int32(SQLITE_ERROR)
|
|
} else {
|
|
v190 = int32(SQLITE_DONE)
|
|
}
|
|
rc = v190
|
|
}
|
|
goto vdbe_return
|
|
/* Opcode: Integer P1 P2 * * *
|
|
** Synopsis: r[P2]=P1
|
|
**
|
|
** The 32-bit integer value P1 is written into register P2.
|
|
*/
|
|
_10:
|
|
; /* out2 */
|
|
pOut = _out2Prerelease(tls, p, pOp)
|
|
*(*Ti64)(unsafe.Pointer(pOut)) = int64((*TOp)(unsafe.Pointer(pOp)).Fp1)
|
|
goto _189
|
|
/* Opcode: Int64 * P2 * P4 *
|
|
** Synopsis: r[P2]=P4
|
|
**
|
|
** P4 is a pointer to a 64-bit integer value.
|
|
** Write that value into register P2.
|
|
*/
|
|
_11:
|
|
; /* out2 */
|
|
pOut = _out2Prerelease(tls, p, pOp)
|
|
*(*Ti64)(unsafe.Pointer(pOut)) = **(**Ti64)(__ccgo_up(*(*uintptr)(unsafe.Pointer(pOp + 16))))
|
|
goto _189
|
|
/* Opcode: Real * P2 * P4 *
|
|
** Synopsis: r[P2]=P4
|
|
**
|
|
** P4 is a pointer to a 64-bit floating point value.
|
|
** Write that value into register P2.
|
|
*/
|
|
_12:
|
|
; /* same as TK_FLOAT, out2 */
|
|
pOut = _out2Prerelease(tls, p, pOp)
|
|
(*TMem)(unsafe.Pointer(pOut)).Fflags = uint16(MEM_Real)
|
|
*(*float64)(unsafe.Pointer(pOut)) = **(**float64)(__ccgo_up(*(*uintptr)(unsafe.Pointer(pOp + 16))))
|
|
goto _189
|
|
/* Opcode: String8 * P2 * P4 *
|
|
** Synopsis: r[P2]='P4'
|
|
**
|
|
** P4 points to a nul terminated UTF-8 string. This opcode is transformed
|
|
** into a String opcode before it is executed for the first time. During
|
|
** this transformation, the length of string P4 is computed and stored
|
|
** as the P1 parameter.
|
|
*/
|
|
_13:
|
|
; /* same as TK_STRING, out2 */
|
|
pOut = _out2Prerelease(tls, p, pOp)
|
|
(*TOp)(unsafe.Pointer(pOp)).Fp1 = _sqlite3Strlen30(tls, *(*uintptr)(unsafe.Pointer(pOp + 16)))
|
|
if libc.Int32FromUint8(encoding) != int32(SQLITE_UTF8) {
|
|
rc = _sqlite3VdbeMemSetStr(tls, pOut, *(*uintptr)(unsafe.Pointer(pOp + 16)), int64(-int32(1)), uint8(SQLITE_UTF8), libc.UintptrFromInt32(0))
|
|
if rc != 0 {
|
|
goto too_big
|
|
}
|
|
if SQLITE_OK != _sqlite3VdbeChangeEncoding(tls, pOut, libc.Int32FromUint8(encoding)) {
|
|
goto no_mem
|
|
}
|
|
(*TMem)(unsafe.Pointer(pOut)).FszMalloc = 0
|
|
v191 = pOut + 16
|
|
*(*Tu16)(unsafe.Pointer(v191)) = Tu16(int32(*(*Tu16)(unsafe.Pointer(v191))) | libc.Int32FromInt32(MEM_Static))
|
|
if int32((*TOp)(unsafe.Pointer(pOp)).Fp4type) == -int32(7) {
|
|
_sqlite3DbFree(tls, db, *(*uintptr)(unsafe.Pointer(pOp + 16)))
|
|
}
|
|
(*TOp)(unsafe.Pointer(pOp)).Fp4type = int8(-libc.Int32FromInt32(7))
|
|
*(*uintptr)(unsafe.Pointer(pOp + 16)) = (*TMem)(unsafe.Pointer(pOut)).Fz
|
|
(*TOp)(unsafe.Pointer(pOp)).Fp1 = (*TMem)(unsafe.Pointer(pOut)).Fn
|
|
}
|
|
if (*TOp)(unsafe.Pointer(pOp)).Fp1 > **(**int32)(__ccgo_up(db + 116)) {
|
|
goto too_big
|
|
}
|
|
(*TOp)(unsafe.Pointer(pOp)).Fopcode = uint8(OP_String)
|
|
/* Fall through to the next case, OP_String */
|
|
/* Opcode: String P1 P2 P3 P4 P5
|
|
** Synopsis: r[P2]='P4' (len=P1)
|
|
**
|
|
** The string value P4 of length P1 (bytes) is stored in register P2.
|
|
**
|
|
** If P3 is not zero and the content of register P3 is equal to P5, then
|
|
** the datatype of the register P2 is converted to BLOB. The content is
|
|
** the same sequence of bytes, it is merely interpreted as a BLOB instead
|
|
** of a string, as if it had been CAST. In other words:
|
|
**
|
|
** if( P3!=0 and reg[P3]==P5 ) reg[P2] := CAST(reg[P2] as BLOB)
|
|
*/
|
|
_14:
|
|
; /* out2 */
|
|
pOut = _out2Prerelease(tls, p, pOp)
|
|
(*TMem)(unsafe.Pointer(pOut)).Fflags = libc.Uint16FromInt32(libc.Int32FromInt32(MEM_Str) | libc.Int32FromInt32(MEM_Static) | libc.Int32FromInt32(MEM_Term))
|
|
(*TMem)(unsafe.Pointer(pOut)).Fz = *(*uintptr)(unsafe.Pointer(pOp + 16))
|
|
(*TMem)(unsafe.Pointer(pOut)).Fn = (*TOp)(unsafe.Pointer(pOp)).Fp1
|
|
(*TMem)(unsafe.Pointer(pOut)).Fenc = encoding
|
|
goto _189
|
|
/* Opcode: BeginSubrtn * P2 * * *
|
|
** Synopsis: r[P2]=NULL
|
|
**
|
|
** Mark the beginning of a subroutine that can be entered in-line
|
|
** or that can be called using OP_Gosub. The subroutine should
|
|
** be terminated by an OP_Return instruction that has a P1 operand that
|
|
** is the same as the P2 operand to this opcode and that has P3 set to 1.
|
|
** If the subroutine is entered in-line, then the OP_Return will simply
|
|
** fall through. But if the subroutine is entered using OP_Gosub, then
|
|
** the OP_Return will jump back to the first instruction after the OP_Gosub.
|
|
**
|
|
** This routine works by loading a NULL into the P2 register. When the
|
|
** return address register contains a NULL, the OP_Return instruction is
|
|
** a no-op that simply falls through to the next instruction (assuming that
|
|
** the OP_Return opcode has a P3 value of 1). Thus if the subroutine is
|
|
** entered in-line, then the OP_Return will cause in-line execution to
|
|
** continue. But if the subroutine is entered via OP_Gosub, then the
|
|
** OP_Return will cause a return to the address following the OP_Gosub.
|
|
**
|
|
** This opcode is identical to OP_Null. It has a different name
|
|
** only to make the byte code easier to read and verify.
|
|
*/
|
|
/* Opcode: Null P1 P2 P3 * *
|
|
** Synopsis: r[P2..P3]=NULL
|
|
**
|
|
** Write a NULL into registers P2. If P3 greater than P2, then also write
|
|
** NULL into register P3 and every register in between P2 and P3. If P3
|
|
** is less than P2 (typically P3 is zero) then only register P2 is
|
|
** set to NULL.
|
|
**
|
|
** If the P1 value is non-zero, then also set the MEM_Cleared flag so that
|
|
** NULL values will not compare equal even if SQLITE_NULLEQ is set on
|
|
** OP_Ne or OP_Eq.
|
|
*/
|
|
_16:
|
|
;
|
|
_15:
|
|
;
|
|
pOut = _out2Prerelease(tls, p, pOp)
|
|
cnt = (*TOp)(unsafe.Pointer(pOp)).Fp3 - (*TOp)(unsafe.Pointer(pOp)).Fp2
|
|
if (*TOp)(unsafe.Pointer(pOp)).Fp1 != 0 {
|
|
v190 = libc.Int32FromInt32(MEM_Null) | libc.Int32FromInt32(MEM_Cleared)
|
|
} else {
|
|
v190 = int32(MEM_Null)
|
|
}
|
|
v192 = libc.Uint16FromInt32(v190)
|
|
nullFlag = v192
|
|
(*TMem)(unsafe.Pointer(pOut)).Fflags = v192
|
|
(*TMem)(unsafe.Pointer(pOut)).Fn = 0
|
|
for cnt > 0 {
|
|
pOut += 40
|
|
_sqlite3VdbeMemSetNull(tls, pOut)
|
|
(*TMem)(unsafe.Pointer(pOut)).Fflags = nullFlag
|
|
(*TMem)(unsafe.Pointer(pOut)).Fn = 0
|
|
cnt = cnt - 1
|
|
}
|
|
goto _189
|
|
/* Opcode: SoftNull P1 * * * *
|
|
** Synopsis: r[P1]=NULL
|
|
**
|
|
** Set register P1 to have the value NULL as seen by the OP_MakeRecord
|
|
** instruction, but do not free any string or blob memory associated with
|
|
** the register, so that if the value was a string or blob that was
|
|
** previously copied using OP_SCopy, the copies will continue to be valid.
|
|
*/
|
|
_17:
|
|
;
|
|
pOut = aMem + uintptr((*TOp)(unsafe.Pointer(pOp)).Fp1)*40
|
|
(*TMem)(unsafe.Pointer(pOut)).Fflags = libc.Uint16FromInt32(libc.Int32FromUint16((*TMem)(unsafe.Pointer(pOut)).Fflags) & ^(libc.Int32FromInt32(MEM_Undefined)|libc.Int32FromInt32(MEM_AffMask)) | int32(MEM_Null))
|
|
goto _189
|
|
/* Opcode: Blob P1 P2 * P4 *
|
|
** Synopsis: r[P2]=P4 (len=P1)
|
|
**
|
|
** P4 points to a blob of data P1 bytes long. Store this
|
|
** blob in register P2. If P4 is a NULL pointer, then construct
|
|
** a zero-filled blob that is P1 bytes long in P2.
|
|
*/
|
|
_18:
|
|
; /* out2 */
|
|
pOut = _out2Prerelease(tls, p, pOp)
|
|
if *(*uintptr)(unsafe.Pointer(pOp + 16)) == uintptr(0) {
|
|
_sqlite3VdbeMemSetZeroBlob(tls, pOut, (*TOp)(unsafe.Pointer(pOp)).Fp1)
|
|
if _sqlite3VdbeMemExpandBlob(tls, pOut) != 0 {
|
|
goto no_mem
|
|
}
|
|
} else {
|
|
_sqlite3VdbeMemSetStr(tls, pOut, *(*uintptr)(unsafe.Pointer(pOp + 16)), int64((*TOp)(unsafe.Pointer(pOp)).Fp1), uint8(0), uintptr(0))
|
|
}
|
|
(*TMem)(unsafe.Pointer(pOut)).Fenc = encoding
|
|
goto _189
|
|
/* Opcode: Variable P1 P2 * * *
|
|
** Synopsis: r[P2]=parameter(P1)
|
|
**
|
|
** Transfer the values of bound parameter P1 into register P2
|
|
*/
|
|
_19:
|
|
; /* Value being transferred */
|
|
pVar = (*TVdbe)(unsafe.Pointer(p)).FaVar + uintptr((*TOp)(unsafe.Pointer(pOp)).Fp1-int32(1))*40
|
|
if _sqlite3VdbeMemTooBig(tls, pVar) != 0 {
|
|
goto too_big
|
|
}
|
|
pOut = aMem + uintptr((*TOp)(unsafe.Pointer(pOp)).Fp2)*40
|
|
if libc.Int32FromUint16((*TMem)(unsafe.Pointer(pOut)).Fflags)&(libc.Int32FromInt32(MEM_Agg)|libc.Int32FromInt32(MEM_Dyn)) != 0 {
|
|
_sqlite3VdbeMemSetNull(tls, pOut)
|
|
}
|
|
libc.Xmemcpy(tls, pOut, pVar, uint32(libc.UintptrFromInt32(0)+20))
|
|
v191 = pOut + 16
|
|
*(*Tu16)(unsafe.Pointer(v191)) = Tu16(int32(*(*Tu16)(unsafe.Pointer(v191))) & ^(libc.Int32FromInt32(MEM_Dyn) | libc.Int32FromInt32(MEM_Ephem)))
|
|
v191 = pOut + 16
|
|
*(*Tu16)(unsafe.Pointer(v191)) = Tu16(int32(*(*Tu16)(unsafe.Pointer(v191))) | (libc.Int32FromInt32(MEM_Static) | libc.Int32FromInt32(MEM_FromBind)))
|
|
goto _189
|
|
/* Opcode: Move P1 P2 P3 * *
|
|
** Synopsis: r[P2@P3]=r[P1@P3]
|
|
**
|
|
** Move the P3 values in register P1..P1+P3-1 over into
|
|
** registers P2..P2+P3-1. Registers P1..P1+P3-1 are
|
|
** left holding a NULL. It is an error for register ranges
|
|
** P1..P1+P3-1 and P2..P2+P3-1 to overlap. It is an error
|
|
** for P3 to be less than 1.
|
|
*/
|
|
_20:
|
|
; /* Register to copy to */
|
|
n = (*TOp)(unsafe.Pointer(pOp)).Fp3
|
|
p1 = (*TOp)(unsafe.Pointer(pOp)).Fp1
|
|
p2 = (*TOp)(unsafe.Pointer(pOp)).Fp2
|
|
pIn1 = aMem + uintptr(p1)*40
|
|
pOut = aMem + uintptr(p2)*40
|
|
for {
|
|
_sqlite3VdbeMemMove(tls, pOut, pIn1)
|
|
if libc.Int32FromUint16((*TMem)(unsafe.Pointer(pOut)).Fflags)&int32(MEM_Ephem) != 0 && _sqlite3VdbeMemMakeWriteable(tls, pOut) != 0 {
|
|
goto no_mem
|
|
}
|
|
pIn1 += 40
|
|
pOut += 40
|
|
goto _197
|
|
_197:
|
|
;
|
|
n = n - 1
|
|
v190 = n
|
|
if !(v190 != 0) {
|
|
break
|
|
}
|
|
}
|
|
goto _189
|
|
/* Opcode: Copy P1 P2 P3 * P5
|
|
** Synopsis: r[P2@P3+1]=r[P1@P3+1]
|
|
**
|
|
** Make a copy of registers P1..P1+P3 into registers P2..P2+P3.
|
|
**
|
|
** If the 0x0002 bit of P5 is set then also clear the MEM_Subtype flag in the
|
|
** destination. The 0x0001 bit of P5 indicates that this Copy opcode cannot
|
|
** be merged. The 0x0001 bit is used by the query planner and does not
|
|
** come into play during query execution.
|
|
**
|
|
** This instruction makes a deep copy of the value. A duplicate
|
|
** is made of any string or blob constant. See also OP_SCopy.
|
|
*/
|
|
_21:
|
|
;
|
|
n1 = (*TOp)(unsafe.Pointer(pOp)).Fp3
|
|
pIn1 = aMem + uintptr((*TOp)(unsafe.Pointer(pOp)).Fp1)*40
|
|
pOut = aMem + uintptr((*TOp)(unsafe.Pointer(pOp)).Fp2)*40
|
|
for int32(1) != 0 {
|
|
_sqlite3VdbeMemShallowCopy(tls, pOut, pIn1, int32(MEM_Ephem))
|
|
if libc.Int32FromUint16((*TMem)(unsafe.Pointer(pOut)).Fflags)&int32(MEM_Ephem) != 0 && _sqlite3VdbeMemMakeWriteable(tls, pOut) != 0 {
|
|
goto no_mem
|
|
}
|
|
if libc.Int32FromUint16((*TMem)(unsafe.Pointer(pOut)).Fflags)&int32(MEM_Subtype) != 0 && libc.Int32FromUint16((*TOp)(unsafe.Pointer(pOp)).Fp5)&int32(0x0002) != 0 {
|
|
v191 = pOut + 16
|
|
*(*Tu16)(unsafe.Pointer(v191)) = Tu16(int32(*(*Tu16)(unsafe.Pointer(v191))) & ^libc.Int32FromInt32(MEM_Subtype))
|
|
}
|
|
v190 = n1
|
|
n1 = n1 - 1
|
|
if v190 == 0 {
|
|
break
|
|
}
|
|
pOut += 40
|
|
pIn1 += 40
|
|
}
|
|
goto _189
|
|
/* Opcode: SCopy P1 P2 * * *
|
|
** Synopsis: r[P2]=r[P1]
|
|
**
|
|
** Make a shallow copy of register P1 into register P2.
|
|
**
|
|
** This instruction makes a shallow copy of the value. If the value
|
|
** is a string or blob, then the copy is only a pointer to the
|
|
** original and hence if the original changes so will the copy.
|
|
** Worse, if the original is deallocated, the copy becomes invalid.
|
|
** Thus the program must guarantee that the original will not change
|
|
** during the lifetime of the copy. Use OP_Copy to make a complete
|
|
** copy.
|
|
*/
|
|
_22:
|
|
; /* out2 */
|
|
pIn1 = aMem + uintptr((*TOp)(unsafe.Pointer(pOp)).Fp1)*40
|
|
pOut = aMem + uintptr((*TOp)(unsafe.Pointer(pOp)).Fp2)*40
|
|
_sqlite3VdbeMemShallowCopy(tls, pOut, pIn1, int32(MEM_Ephem))
|
|
goto _189
|
|
/* Opcode: IntCopy P1 P2 * * *
|
|
** Synopsis: r[P2]=r[P1]
|
|
**
|
|
** Transfer the integer value held in register P1 into register P2.
|
|
**
|
|
** This is an optimized version of SCopy that works only for integer
|
|
** values.
|
|
*/
|
|
_23:
|
|
; /* out2 */
|
|
pIn1 = aMem + uintptr((*TOp)(unsafe.Pointer(pOp)).Fp1)*40
|
|
pOut = aMem + uintptr((*TOp)(unsafe.Pointer(pOp)).Fp2)*40
|
|
_sqlite3VdbeMemSetInt64(tls, pOut, *(*Ti64)(unsafe.Pointer(pIn1)))
|
|
goto _189
|
|
/* Opcode: FkCheck * * * * *
|
|
**
|
|
** Halt with an SQLITE_CONSTRAINT error if there are any unresolved
|
|
** foreign key constraint violations. If there are no foreign key
|
|
** constraint violations, this is a no-op.
|
|
**
|
|
** FK constraint violations are also checked when the prepared statement
|
|
** exits. This opcode is used to raise foreign key constraint errors prior
|
|
** to returning results such as a row change count or the result of a
|
|
** RETURNING clause.
|
|
*/
|
|
_24:
|
|
;
|
|
v190 = _sqlite3VdbeCheckFkImmediate(tls, p)
|
|
rc = v190
|
|
if v190 != SQLITE_OK {
|
|
goto abort_due_to_error
|
|
}
|
|
goto _189
|
|
/* Opcode: ResultRow P1 P2 * * *
|
|
** Synopsis: output=r[P1@P2]
|
|
**
|
|
** The registers P1 through P1+P2-1 contain a single row of
|
|
** results. This opcode causes the sqlite3_step() call to terminate
|
|
** with an SQLITE_ROW return code and it sets up the sqlite3_stmt
|
|
** structure to provide access to the r(P1)..r(P1+P2-1) values as
|
|
** the result row.
|
|
*/
|
|
_25:
|
|
;
|
|
(*TVdbe)(unsafe.Pointer(p)).FcacheCtr = (*TVdbe)(unsafe.Pointer(p)).FcacheCtr + uint32(2) | uint32(1)
|
|
(*TVdbe)(unsafe.Pointer(p)).FpResultRow = aMem + uintptr((*TOp)(unsafe.Pointer(pOp)).Fp1)*40
|
|
if (*Tsqlite3)(unsafe.Pointer(db)).FmallocFailed != 0 {
|
|
goto no_mem
|
|
}
|
|
if libc.Int32FromUint8((*Tsqlite3)(unsafe.Pointer(db)).FmTrace)&int32(SQLITE_TRACE_ROW) != 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_ROW), (*Tsqlite3)(unsafe.Pointer(db)).FpTraceArg, p, uintptr(0))
|
|
}
|
|
(*TVdbe)(unsafe.Pointer(p)).Fpc = (int32(pOp)-int32(aOp))/20 + int32(1)
|
|
rc = int32(SQLITE_ROW)
|
|
goto vdbe_return
|
|
/* Opcode: Concat P1 P2 P3 * *
|
|
** Synopsis: r[P3]=r[P2]+r[P1]
|
|
**
|
|
** Add the text in register P1 onto the end of the text in
|
|
** register P2 and store the result in register P3.
|
|
** If either the P1 or P2 text are NULL then store NULL in P3.
|
|
**
|
|
** P3 = P2 || P1
|
|
**
|
|
** It is illegal for P1 and P3 to be the same register. Sometimes,
|
|
** if P3 is the same register as P2, the implementation is able
|
|
** to avoid a memcpy().
|
|
*/
|
|
_26:
|
|
; /* Initial flags for P2 */
|
|
pIn1 = aMem + uintptr((*TOp)(unsafe.Pointer(pOp)).Fp1)*40
|
|
pIn2 = aMem + uintptr((*TOp)(unsafe.Pointer(pOp)).Fp2)*40
|
|
pOut = aMem + uintptr((*TOp)(unsafe.Pointer(pOp)).Fp3)*40
|
|
flags1 = (*TMem)(unsafe.Pointer(pIn1)).Fflags
|
|
if (libc.Int32FromUint16(flags1)|libc.Int32FromUint16((*TMem)(unsafe.Pointer(pIn2)).Fflags))&int32(MEM_Null) != 0 {
|
|
_sqlite3VdbeMemSetNull(tls, pOut)
|
|
goto _189
|
|
}
|
|
if libc.Int32FromUint16(flags1)&(libc.Int32FromInt32(MEM_Str)|libc.Int32FromInt32(MEM_Blob)) == 0 {
|
|
if _sqlite3VdbeMemStringify(tls, pIn1, encoding, uint8(0)) != 0 {
|
|
goto no_mem
|
|
}
|
|
flags1 = libc.Uint16FromInt32(libc.Int32FromUint16((*TMem)(unsafe.Pointer(pIn1)).Fflags) & ^libc.Int32FromInt32(MEM_Str))
|
|
} else {
|
|
if libc.Int32FromUint16(flags1)&int32(MEM_Zero) != 0 {
|
|
if _sqlite3VdbeMemExpandBlob(tls, pIn1) != 0 {
|
|
goto no_mem
|
|
}
|
|
flags1 = libc.Uint16FromInt32(libc.Int32FromUint16((*TMem)(unsafe.Pointer(pIn1)).Fflags) & ^libc.Int32FromInt32(MEM_Str))
|
|
}
|
|
}
|
|
flags2 = (*TMem)(unsafe.Pointer(pIn2)).Fflags
|
|
if libc.Int32FromUint16(flags2)&(libc.Int32FromInt32(MEM_Str)|libc.Int32FromInt32(MEM_Blob)) == 0 {
|
|
if _sqlite3VdbeMemStringify(tls, pIn2, encoding, uint8(0)) != 0 {
|
|
goto no_mem
|
|
}
|
|
flags2 = libc.Uint16FromInt32(libc.Int32FromUint16((*TMem)(unsafe.Pointer(pIn2)).Fflags) & ^libc.Int32FromInt32(MEM_Str))
|
|
} else {
|
|
if libc.Int32FromUint16(flags2)&int32(MEM_Zero) != 0 {
|
|
if _sqlite3VdbeMemExpandBlob(tls, pIn2) != 0 {
|
|
goto no_mem
|
|
}
|
|
flags2 = libc.Uint16FromInt32(libc.Int32FromUint16((*TMem)(unsafe.Pointer(pIn2)).Fflags) & ^libc.Int32FromInt32(MEM_Str))
|
|
}
|
|
}
|
|
nByte = int64((*TMem)(unsafe.Pointer(pIn1)).Fn)
|
|
nByte = nByte + int64((*TMem)(unsafe.Pointer(pIn2)).Fn)
|
|
if nByte > int64(**(**int32)(__ccgo_up(db + 116))) {
|
|
goto too_big
|
|
}
|
|
if _sqlite3VdbeMemGrow(tls, pOut, int32(nByte)+int32(2), libc.BoolInt32(pOut == pIn2)) != 0 {
|
|
goto no_mem
|
|
}
|
|
(*TMem)(unsafe.Pointer(pOut)).Fflags = libc.Uint16FromInt32(libc.Int32FromUint16((*TMem)(unsafe.Pointer(pOut)).Fflags) & ^(libc.Int32FromInt32(MEM_TypeMask)|libc.Int32FromInt32(MEM_Zero)) | int32(MEM_Str))
|
|
if pOut != pIn2 {
|
|
libc.Xmemcpy(tls, (*TMem)(unsafe.Pointer(pOut)).Fz, (*TMem)(unsafe.Pointer(pIn2)).Fz, libc.Uint32FromInt32((*TMem)(unsafe.Pointer(pIn2)).Fn))
|
|
(*TMem)(unsafe.Pointer(pIn2)).Fflags = flags2
|
|
}
|
|
libc.Xmemcpy(tls, (*TMem)(unsafe.Pointer(pOut)).Fz+uintptr((*TMem)(unsafe.Pointer(pIn2)).Fn), (*TMem)(unsafe.Pointer(pIn1)).Fz, libc.Uint32FromInt32((*TMem)(unsafe.Pointer(pIn1)).Fn))
|
|
(*TMem)(unsafe.Pointer(pIn1)).Fflags = flags1
|
|
if libc.Int32FromUint8(encoding) > int32(SQLITE_UTF8) {
|
|
nByte = nByte & int64(^libc.Int32FromInt32(1))
|
|
}
|
|
**(**int8)(__ccgo_up((*TMem)(unsafe.Pointer(pOut)).Fz + uintptr(nByte))) = 0
|
|
**(**int8)(__ccgo_up((*TMem)(unsafe.Pointer(pOut)).Fz + uintptr(nByte+int64(1)))) = 0
|
|
v191 = pOut + 16
|
|
*(*Tu16)(unsafe.Pointer(v191)) = Tu16(int32(*(*Tu16)(unsafe.Pointer(v191))) | libc.Int32FromInt32(MEM_Term))
|
|
(*TMem)(unsafe.Pointer(pOut)).Fn = int32(nByte)
|
|
(*TMem)(unsafe.Pointer(pOut)).Fenc = encoding
|
|
goto _189
|
|
/* Opcode: Add P1 P2 P3 * *
|
|
** Synopsis: r[P3]=r[P1]+r[P2]
|
|
**
|
|
** Add the value in register P1 to the value in register P2
|
|
** and store the result in register P3.
|
|
** If either input is NULL, the result is NULL.
|
|
*/
|
|
/* Opcode: Multiply P1 P2 P3 * *
|
|
** Synopsis: r[P3]=r[P1]*r[P2]
|
|
**
|
|
**
|
|
** Multiply the value in register P1 by the value in register P2
|
|
** and store the result in register P3.
|
|
** If either input is NULL, the result is NULL.
|
|
*/
|
|
/* Opcode: Subtract P1 P2 P3 * *
|
|
** Synopsis: r[P3]=r[P2]-r[P1]
|
|
**
|
|
** Subtract the value in register P1 from the value in register P2
|
|
** and store the result in register P3.
|
|
** If either input is NULL, the result is NULL.
|
|
*/
|
|
/* Opcode: Divide P1 P2 P3 * *
|
|
** Synopsis: r[P3]=r[P2]/r[P1]
|
|
**
|
|
** Divide the value in register P1 by the value in register P2
|
|
** and store the result in register P3 (P3=P2/P1). If the value in
|
|
** register P1 is zero, then the result is NULL. If either input is
|
|
** NULL, the result is NULL.
|
|
*/
|
|
/* Opcode: Remainder P1 P2 P3 * *
|
|
** Synopsis: r[P3]=r[P2]%r[P1]
|
|
**
|
|
** Compute the remainder after integer register P2 is divided by
|
|
** register P1 and store the result in register P3.
|
|
** If the value in register P1 is zero the result is NULL.
|
|
** If either operand is NULL, the result is NULL.
|
|
*/
|
|
_31:
|
|
; /* same as TK_PLUS, in1, in2, out3 */
|
|
_30:
|
|
; /* same as TK_MINUS, in1, in2, out3 */
|
|
_29:
|
|
; /* same as TK_STAR, in1, in2, out3 */
|
|
_28:
|
|
; /* same as TK_SLASH, in1, in2, out3 */
|
|
_27:
|
|
; /* Real value of right operand */
|
|
pIn1 = aMem + uintptr((*TOp)(unsafe.Pointer(pOp)).Fp1)*40
|
|
type1 = (*TMem)(unsafe.Pointer(pIn1)).Fflags
|
|
pIn2 = aMem + uintptr((*TOp)(unsafe.Pointer(pOp)).Fp2)*40
|
|
type2 = (*TMem)(unsafe.Pointer(pIn2)).Fflags
|
|
pOut = aMem + uintptr((*TOp)(unsafe.Pointer(pOp)).Fp3)*40
|
|
if !(libc.Int32FromUint16(type1)&libc.Int32FromUint16(type2)&int32(MEM_Int) != 0) {
|
|
goto _202
|
|
}
|
|
goto int_math
|
|
int_math:
|
|
;
|
|
iA = *(*Ti64)(unsafe.Pointer(pIn1))
|
|
**(**Ti64)(__ccgo_up(bp)) = *(*Ti64)(unsafe.Pointer(pIn2))
|
|
switch libc.Int32FromUint8((*TOp)(unsafe.Pointer(pOp)).Fopcode) {
|
|
case int32(OP_Add):
|
|
if _sqlite3AddInt64(tls, bp, iA) != 0 {
|
|
goto fp_math
|
|
}
|
|
case int32(OP_Subtract):
|
|
if _sqlite3SubInt64(tls, bp, iA) != 0 {
|
|
goto fp_math
|
|
}
|
|
case int32(OP_Multiply):
|
|
if _sqlite3MulInt64(tls, bp, iA) != 0 {
|
|
goto fp_math
|
|
}
|
|
case int32(OP_Divide):
|
|
if iA == 0 {
|
|
goto arithmetic_result_is_null
|
|
}
|
|
if iA == int64(-int32(1)) && **(**Ti64)(__ccgo_up(bp)) == int64(-libc.Int32FromInt32(1))-(libc.Int64FromUint32(0xffffffff)|libc.Int64FromInt32(0x7fffffff)<<libc.Int32FromInt32(32)) {
|
|
goto fp_math
|
|
}
|
|
**(**Ti64)(__ccgo_up(bp)) = **(**Ti64)(__ccgo_up(bp)) / iA
|
|
default:
|
|
if iA == 0 {
|
|
goto arithmetic_result_is_null
|
|
}
|
|
if iA == int64(-int32(1)) {
|
|
iA = int64(1)
|
|
}
|
|
**(**Ti64)(__ccgo_up(bp)) = **(**Ti64)(__ccgo_up(bp)) % iA
|
|
break
|
|
}
|
|
*(*Ti64)(unsafe.Pointer(pOut)) = **(**Ti64)(__ccgo_up(bp))
|
|
(*TMem)(unsafe.Pointer(pOut)).Fflags = libc.Uint16FromInt32(libc.Int32FromUint16((*TMem)(unsafe.Pointer(pOut)).Fflags) & ^(libc.Int32FromInt32(MEM_TypeMask)|libc.Int32FromInt32(MEM_Zero)) | int32(MEM_Int))
|
|
goto _203
|
|
_202:
|
|
;
|
|
if !((libc.Int32FromUint16(type1)|libc.Int32FromUint16(type2))&int32(MEM_Null) != 0) {
|
|
goto _204
|
|
}
|
|
goto arithmetic_result_is_null
|
|
goto _205
|
|
_204:
|
|
;
|
|
type1 = _numericType(tls, pIn1)
|
|
type2 = _numericType(tls, pIn2)
|
|
if libc.Int32FromUint16(type1)&libc.Int32FromUint16(type2)&int32(MEM_Int) != 0 {
|
|
goto int_math
|
|
}
|
|
goto fp_math
|
|
fp_math:
|
|
;
|
|
rA = _sqlite3VdbeRealValue(tls, pIn1)
|
|
rB = _sqlite3VdbeRealValue(tls, pIn2)
|
|
switch libc.Int32FromUint8((*TOp)(unsafe.Pointer(pOp)).Fopcode) {
|
|
case int32(OP_Add):
|
|
rB = rB + rA
|
|
case int32(OP_Subtract):
|
|
rB = rB - rA
|
|
case int32(OP_Multiply):
|
|
rB = rB * rA
|
|
case int32(OP_Divide):
|
|
/* (double)0 In case of SQLITE_OMIT_FLOATING_POINT... */
|
|
if rA == libc.Float64FromInt32(0) {
|
|
goto arithmetic_result_is_null
|
|
}
|
|
rB = rB / rA
|
|
default:
|
|
iA = _sqlite3VdbeIntValue(tls, pIn1)
|
|
**(**Ti64)(__ccgo_up(bp)) = _sqlite3VdbeIntValue(tls, pIn2)
|
|
if iA == 0 {
|
|
goto arithmetic_result_is_null
|
|
}
|
|
if iA == int64(-int32(1)) {
|
|
iA = int64(1)
|
|
}
|
|
rB = float64(**(**Ti64)(__ccgo_up(bp)) % iA)
|
|
break
|
|
}
|
|
if _sqlite3IsNaN(tls, rB) != 0 {
|
|
goto arithmetic_result_is_null
|
|
}
|
|
*(*float64)(unsafe.Pointer(pOut)) = rB
|
|
(*TMem)(unsafe.Pointer(pOut)).Fflags = libc.Uint16FromInt32(libc.Int32FromUint16((*TMem)(unsafe.Pointer(pOut)).Fflags) & ^(libc.Int32FromInt32(MEM_TypeMask)|libc.Int32FromInt32(MEM_Zero)) | int32(MEM_Real))
|
|
_205:
|
|
;
|
|
_203:
|
|
;
|
|
goto _189
|
|
goto arithmetic_result_is_null
|
|
arithmetic_result_is_null:
|
|
;
|
|
_sqlite3VdbeMemSetNull(tls, pOut)
|
|
goto _189
|
|
/* Opcode: CollSeq P1 * * P4
|
|
**
|
|
** P4 is a pointer to a CollSeq object. If the next call to a user function
|
|
** or aggregate calls sqlite3GetFuncCollSeq(), this collation sequence will
|
|
** be returned. This is used by the built-in min(), max() and nullif()
|
|
** functions.
|
|
**
|
|
** If P1 is not zero, then it is a register that a subsequent min() or
|
|
** max() aggregate will set to 1 if the current row is not the minimum or
|
|
** maximum. The P1 register is initialized to 0 by this instruction.
|
|
**
|
|
** The interface used by the implementation of the aforementioned functions
|
|
** to retrieve the collation sequence set by this opcode is not available
|
|
** publicly. Only built-in functions have access to this feature.
|
|
*/
|
|
_32:
|
|
;
|
|
if (*TOp)(unsafe.Pointer(pOp)).Fp1 != 0 {
|
|
_sqlite3VdbeMemSetInt64(tls, aMem+uintptr((*TOp)(unsafe.Pointer(pOp)).Fp1)*40, 0)
|
|
}
|
|
goto _189
|
|
/* Opcode: BitAnd P1 P2 P3 * *
|
|
** Synopsis: r[P3]=r[P1]&r[P2]
|
|
**
|
|
** Take the bit-wise AND of the values in register P1 and P2 and
|
|
** store the result in register P3.
|
|
** If either input is NULL, the result is NULL.
|
|
*/
|
|
/* Opcode: BitOr P1 P2 P3 * *
|
|
** Synopsis: r[P3]=r[P1]|r[P2]
|
|
**
|
|
** Take the bit-wise OR of the values in register P1 and P2 and
|
|
** store the result in register P3.
|
|
** If either input is NULL, the result is NULL.
|
|
*/
|
|
/* Opcode: ShiftLeft P1 P2 P3 * *
|
|
** Synopsis: r[P3]=r[P2]<<r[P1]
|
|
**
|
|
** Shift the integer value in register P2 to the left by the
|
|
** number of bits specified by the integer in register P1.
|
|
** Store the result in register P3.
|
|
** If either input is NULL, the result is NULL.
|
|
*/
|
|
/* Opcode: ShiftRight P1 P2 P3 * *
|
|
** Synopsis: r[P3]=r[P2]>>r[P1]
|
|
**
|
|
** Shift the integer value in register P2 to the right by the
|
|
** number of bits specified by the integer in register P1.
|
|
** Store the result in register P3.
|
|
** If either input is NULL, the result is NULL.
|
|
*/
|
|
_36:
|
|
; /* same as TK_BITAND, in1, in2, out3 */
|
|
_35:
|
|
; /* same as TK_BITOR, in1, in2, out3 */
|
|
_34:
|
|
; /* same as TK_LSHIFT, in1, in2, out3 */
|
|
_33:
|
|
;
|
|
pIn1 = aMem + uintptr((*TOp)(unsafe.Pointer(pOp)).Fp1)*40
|
|
pIn2 = aMem + uintptr((*TOp)(unsafe.Pointer(pOp)).Fp2)*40
|
|
pOut = aMem + uintptr((*TOp)(unsafe.Pointer(pOp)).Fp3)*40
|
|
if (libc.Int32FromUint16((*TMem)(unsafe.Pointer(pIn1)).Fflags)|libc.Int32FromUint16((*TMem)(unsafe.Pointer(pIn2)).Fflags))&int32(MEM_Null) != 0 {
|
|
_sqlite3VdbeMemSetNull(tls, pOut)
|
|
goto _189
|
|
}
|
|
**(**Ti64)(__ccgo_up(bp + 8)) = _sqlite3VdbeIntValue(tls, pIn2)
|
|
iB1 = _sqlite3VdbeIntValue(tls, pIn1)
|
|
op = (*TOp)(unsafe.Pointer(pOp)).Fopcode
|
|
if libc.Int32FromUint8(op) == int32(OP_BitAnd) {
|
|
**(**Ti64)(__ccgo_up(bp + 8)) = **(**Ti64)(__ccgo_up(bp + 8)) & iB1
|
|
} else {
|
|
if libc.Int32FromUint8(op) == int32(OP_BitOr) {
|
|
**(**Ti64)(__ccgo_up(bp + 8)) = **(**Ti64)(__ccgo_up(bp + 8)) | iB1
|
|
} else {
|
|
if iB1 != 0 {
|
|
/* If shifting by a negative amount, shift in the other direction */
|
|
if iB1 < 0 {
|
|
op = libc.Uint8FromInt32(libc.Int32FromInt32(2)*libc.Int32FromInt32(OP_ShiftLeft) + libc.Int32FromInt32(1) - libc.Int32FromUint8(op))
|
|
if iB1 > int64(-libc.Int32FromInt32(64)) {
|
|
v206 = -iB1
|
|
} else {
|
|
v206 = int64(64)
|
|
}
|
|
iB1 = v206
|
|
}
|
|
if iB1 >= int64(64) {
|
|
if **(**Ti64)(__ccgo_up(bp + 8)) >= 0 || libc.Int32FromUint8(op) == int32(OP_ShiftLeft) {
|
|
v190 = 0
|
|
} else {
|
|
v190 = -int32(1)
|
|
}
|
|
**(**Ti64)(__ccgo_up(bp + 8)) = int64(v190)
|
|
} else {
|
|
libc.Xmemcpy(tls, bp+16, bp+8, uint32(8))
|
|
if libc.Int32FromUint8(op) == int32(OP_ShiftLeft) {
|
|
**(**Tu64)(__ccgo_up(bp + 16)) = **(**Tu64)(__ccgo_up(bp + 16)) << libc.Uint64FromInt64(iB1)
|
|
} else {
|
|
**(**Tu64)(__ccgo_up(bp + 16)) = **(**Tu64)(__ccgo_up(bp + 16)) >> libc.Uint64FromInt64(iB1)
|
|
/* Sign-extend on a right shift of a negative number */
|
|
if **(**Ti64)(__ccgo_up(bp + 8)) < 0 {
|
|
**(**Tu64)(__ccgo_up(bp + 16)) = **(**Tu64)(__ccgo_up(bp + 16)) | (libc.Uint64FromUint32(0xffffffff)<<libc.Int32FromInt32(32)|libc.Uint64FromUint32(0xffffffff))<<(int64(64)-iB1)
|
|
}
|
|
}
|
|
libc.Xmemcpy(tls, bp+8, bp+16, uint32(8))
|
|
}
|
|
}
|
|
}
|
|
}
|
|
*(*Ti64)(unsafe.Pointer(pOut)) = **(**Ti64)(__ccgo_up(bp + 8))
|
|
(*TMem)(unsafe.Pointer(pOut)).Fflags = libc.Uint16FromInt32(libc.Int32FromUint16((*TMem)(unsafe.Pointer(pOut)).Fflags) & ^(libc.Int32FromInt32(MEM_TypeMask)|libc.Int32FromInt32(MEM_Zero)) | int32(MEM_Int))
|
|
goto _189
|
|
/* Opcode: AddImm P1 P2 * * *
|
|
** Synopsis: r[P1]=r[P1]+P2
|
|
**
|
|
** Add the constant P2 to the value in register P1.
|
|
** The result is always an integer.
|
|
**
|
|
** To force any register to be an integer, just add 0.
|
|
*/
|
|
_37:
|
|
; /* in1 */
|
|
pIn1 = aMem + uintptr((*TOp)(unsafe.Pointer(pOp)).Fp1)*40
|
|
_sqlite3VdbeMemIntegerify(tls, pIn1)
|
|
**(**Tu64)(__ccgo_up(pIn1)) += libc.Uint64FromInt32((*TOp)(unsafe.Pointer(pOp)).Fp2)
|
|
goto _189
|
|
/* Opcode: MustBeInt P1 P2 * * *
|
|
**
|
|
** Force the value in register P1 to be an integer. If the value
|
|
** in P1 is not an integer and cannot be converted into an integer
|
|
** without data loss, then jump immediately to P2, or if P2==0
|
|
** raise an SQLITE_MISMATCH exception.
|
|
*/
|
|
_38:
|
|
; /* jump0, in1 */
|
|
pIn1 = aMem + uintptr((*TOp)(unsafe.Pointer(pOp)).Fp1)*40
|
|
if libc.Int32FromUint16((*TMem)(unsafe.Pointer(pIn1)).Fflags)&int32(MEM_Int) == 0 {
|
|
_applyAffinity(tls, pIn1, int8(SQLITE_AFF_NUMERIC), encoding)
|
|
if libc.Int32FromUint16((*TMem)(unsafe.Pointer(pIn1)).Fflags)&int32(MEM_Int) == 0 {
|
|
if (*TOp)(unsafe.Pointer(pOp)).Fp2 == 0 {
|
|
rc = int32(SQLITE_MISMATCH)
|
|
goto abort_due_to_error
|
|
} else {
|
|
goto jump_to_p2
|
|
}
|
|
}
|
|
}
|
|
(*TMem)(unsafe.Pointer(pIn1)).Fflags = libc.Uint16FromInt32(libc.Int32FromUint16((*TMem)(unsafe.Pointer(pIn1)).Fflags) & ^(libc.Int32FromInt32(MEM_TypeMask)|libc.Int32FromInt32(MEM_Zero)) | int32(MEM_Int))
|
|
goto _189
|
|
/* Opcode: RealAffinity P1 * * * *
|
|
**
|
|
** If register P1 holds an integer convert it to a real value.
|
|
**
|
|
** This opcode is used when extracting information from a column that
|
|
** has REAL affinity. Such column values may still be stored as
|
|
** integers, for space efficiency, but after extraction we want them
|
|
** to have only a real value.
|
|
*/
|
|
_39:
|
|
; /* in1 */
|
|
pIn1 = aMem + uintptr((*TOp)(unsafe.Pointer(pOp)).Fp1)*40
|
|
if libc.Int32FromUint16((*TMem)(unsafe.Pointer(pIn1)).Fflags)&(libc.Int32FromInt32(MEM_Int)|libc.Int32FromInt32(MEM_IntReal)) != 0 {
|
|
_sqlite3VdbeMemRealify(tls, pIn1)
|
|
}
|
|
goto _189
|
|
/* Opcode: Cast P1 P2 * * *
|
|
** Synopsis: affinity(r[P1])
|
|
**
|
|
** Force the value in register P1 to be the type defined by P2.
|
|
**
|
|
** <ul>
|
|
** <li> P2=='A' → BLOB
|
|
** <li> P2=='B' → TEXT
|
|
** <li> P2=='C' → NUMERIC
|
|
** <li> P2=='D' → INTEGER
|
|
** <li> P2=='E' → REAL
|
|
** </ul>
|
|
**
|
|
** A NULL value is not changed by this routine. It remains NULL.
|
|
*/
|
|
_40:
|
|
; /* in1 */
|
|
pIn1 = aMem + uintptr((*TOp)(unsafe.Pointer(pOp)).Fp1)*40
|
|
if libc.Int32FromUint16((*TMem)(unsafe.Pointer(pIn1)).Fflags)&int32(MEM_Zero) != 0 {
|
|
v190 = _sqlite3VdbeMemExpandBlob(tls, pIn1)
|
|
} else {
|
|
v190 = 0
|
|
}
|
|
rc = v190
|
|
if rc != 0 {
|
|
goto abort_due_to_error
|
|
}
|
|
rc = _sqlite3VdbeMemCast(tls, pIn1, libc.Uint8FromInt32((*TOp)(unsafe.Pointer(pOp)).Fp2), encoding)
|
|
if rc != 0 {
|
|
goto abort_due_to_error
|
|
}
|
|
goto _189
|
|
/* Opcode: Eq P1 P2 P3 P4 P5
|
|
** Synopsis: IF r[P3]==r[P1]
|
|
**
|
|
** Compare the values in register P1 and P3. If reg(P3)==reg(P1) then
|
|
** jump to address P2.
|
|
**
|
|
** The SQLITE_AFF_MASK portion of P5 must be an affinity character -
|
|
** SQLITE_AFF_TEXT, SQLITE_AFF_INTEGER, and so forth. An attempt is made
|
|
** to coerce both inputs according to this affinity before the
|
|
** comparison is made. If the SQLITE_AFF_MASK is 0x00, then numeric
|
|
** affinity is used. Note that the affinity conversions are stored
|
|
** back into the input registers P1 and P3. So this opcode can cause
|
|
** persistent changes to registers P1 and P3.
|
|
**
|
|
** Once any conversions have taken place, and neither value is NULL,
|
|
** the values are compared. If both values are blobs then memcmp() is
|
|
** used to determine the results of the comparison. If both values
|
|
** are text, then the appropriate collating function specified in
|
|
** P4 is used to do the comparison. If P4 is not specified then
|
|
** memcmp() is used to compare text string. If both values are
|
|
** numeric, then a numeric comparison is used. If the two values
|
|
** are of different types, then numbers are considered less than
|
|
** strings and strings are considered less than blobs.
|
|
**
|
|
** If SQLITE_NULLEQ is set in P5 then the result of comparison is always either
|
|
** true or false and is never NULL. If both operands are NULL then the result
|
|
** of comparison is true. If either operand is NULL then the result is false.
|
|
** If neither operand is NULL the result is the same as it would be if
|
|
** the SQLITE_NULLEQ flag were omitted from P5.
|
|
**
|
|
** This opcode saves the result of comparison for use by the new
|
|
** OP_Jump opcode.
|
|
*/
|
|
/* Opcode: Ne P1 P2 P3 P4 P5
|
|
** Synopsis: IF r[P3]!=r[P1]
|
|
**
|
|
** This works just like the Eq opcode except that the jump is taken if
|
|
** the operands in registers P1 and P3 are not equal. See the Eq opcode for
|
|
** additional information.
|
|
*/
|
|
/* Opcode: Lt P1 P2 P3 P4 P5
|
|
** Synopsis: IF r[P3]<r[P1]
|
|
**
|
|
** Compare the values in register P1 and P3. If reg(P3)<reg(P1) then
|
|
** jump to address P2.
|
|
**
|
|
** If the SQLITE_JUMPIFNULL bit of P5 is set and either reg(P1) or
|
|
** reg(P3) is NULL then the take the jump. If the SQLITE_JUMPIFNULL
|
|
** bit is clear then fall through if either operand is NULL.
|
|
**
|
|
** The SQLITE_AFF_MASK portion of P5 must be an affinity character -
|
|
** SQLITE_AFF_TEXT, SQLITE_AFF_INTEGER, and so forth. An attempt is made
|
|
** to coerce both inputs according to this affinity before the
|
|
** comparison is made. If the SQLITE_AFF_MASK is 0x00, then numeric
|
|
** affinity is used. Note that the affinity conversions are stored
|
|
** back into the input registers P1 and P3. So this opcode can cause
|
|
** persistent changes to registers P1 and P3.
|
|
**
|
|
** Once any conversions have taken place, and neither value is NULL,
|
|
** the values are compared. If both values are blobs then memcmp() is
|
|
** used to determine the results of the comparison. If both values
|
|
** are text, then the appropriate collating function specified in
|
|
** P4 is used to do the comparison. If P4 is not specified then
|
|
** memcmp() is used to compare text string. If both values are
|
|
** numeric, then a numeric comparison is used. If the two values
|
|
** are of different types, then numbers are considered less than
|
|
** strings and strings are considered less than blobs.
|
|
**
|
|
** This opcode saves the result of comparison for use by the new
|
|
** OP_Jump opcode.
|
|
*/
|
|
/* Opcode: Le P1 P2 P3 P4 P5
|
|
** Synopsis: IF r[P3]<=r[P1]
|
|
**
|
|
** This works just like the Lt opcode except that the jump is taken if
|
|
** the content of register P3 is less than or equal to the content of
|
|
** register P1. See the Lt opcode for additional information.
|
|
*/
|
|
/* Opcode: Gt P1 P2 P3 P4 P5
|
|
** Synopsis: IF r[P3]>r[P1]
|
|
**
|
|
** This works just like the Lt opcode except that the jump is taken if
|
|
** the content of register P3 is greater than the content of
|
|
** register P1. See the Lt opcode for additional information.
|
|
*/
|
|
/* Opcode: Ge P1 P2 P3 P4 P5
|
|
** Synopsis: IF r[P3]>=r[P1]
|
|
**
|
|
** This works just like the Lt opcode except that the jump is taken if
|
|
** the content of register P3 is greater than or equal to the content of
|
|
** register P1. See the Lt opcode for additional information.
|
|
*/
|
|
_46:
|
|
; /* same as TK_EQ, jump, in1, in3 */
|
|
_45:
|
|
; /* same as TK_NE, jump, in1, in3 */
|
|
_44:
|
|
; /* same as TK_LT, jump, in1, in3 */
|
|
_43:
|
|
; /* same as TK_LE, jump, in1, in3 */
|
|
_42:
|
|
; /* same as TK_GT, jump, in1, in3 */
|
|
_41:
|
|
; /* Copy of initial value of pIn3->flags */
|
|
pIn1 = aMem + uintptr((*TOp)(unsafe.Pointer(pOp)).Fp1)*40
|
|
pIn3 = aMem + uintptr((*TOp)(unsafe.Pointer(pOp)).Fp3)*40
|
|
flags11 = (*TMem)(unsafe.Pointer(pIn1)).Fflags
|
|
flags3 = (*TMem)(unsafe.Pointer(pIn3)).Fflags
|
|
if libc.Int32FromUint16(flags11)&libc.Int32FromUint16(flags3)&int32(MEM_Int) != 0 {
|
|
/* Common case of comparison of two integers */
|
|
if *(*Ti64)(unsafe.Pointer(pIn3)) > *(*Ti64)(unsafe.Pointer(pIn1)) {
|
|
if **(**uint8)(__ccgo_up(_sqlite3aGTb + uintptr((*TOp)(unsafe.Pointer(pOp)).Fopcode))) != 0 {
|
|
goto jump_to_p2
|
|
}
|
|
iCompare = +libc.Int32FromInt32(1)
|
|
} else {
|
|
if *(*Ti64)(unsafe.Pointer(pIn3)) < *(*Ti64)(unsafe.Pointer(pIn1)) {
|
|
if **(**uint8)(__ccgo_up(_sqlite3aLTb + uintptr((*TOp)(unsafe.Pointer(pOp)).Fopcode))) != 0 {
|
|
goto jump_to_p2
|
|
}
|
|
iCompare = -int32(1)
|
|
} else {
|
|
if **(**uint8)(__ccgo_up(_sqlite3aEQb + uintptr((*TOp)(unsafe.Pointer(pOp)).Fopcode))) != 0 {
|
|
goto jump_to_p2
|
|
}
|
|
iCompare = 0
|
|
}
|
|
}
|
|
goto _189
|
|
}
|
|
if (libc.Int32FromUint16(flags11)|libc.Int32FromUint16(flags3))&int32(MEM_Null) != 0 {
|
|
/* One or both operands are NULL */
|
|
if libc.Int32FromUint16((*TOp)(unsafe.Pointer(pOp)).Fp5)&int32(SQLITE_NULLEQ) != 0 {
|
|
/* If SQLITE_NULLEQ is set (which will only happen if the operator is
|
|
** OP_Eq or OP_Ne) then take the jump or not depending on whether
|
|
** or not both operands are null.
|
|
*/
|
|
if libc.Int32FromUint16(flags11)&libc.Int32FromUint16(flags3)&int32(MEM_Null) != 0 && libc.Int32FromUint16(flags3)&int32(MEM_Cleared) == 0 {
|
|
res = 0 /* Operands are equal */
|
|
} else {
|
|
if libc.Int32FromUint16(flags3)&int32(MEM_Null) != 0 {
|
|
v190 = -int32(1)
|
|
} else {
|
|
v190 = +libc.Int32FromInt32(1)
|
|
}
|
|
res = v190 /* Operands are not equal */
|
|
}
|
|
} else {
|
|
/* SQLITE_NULLEQ is clear and at least one operand is NULL,
|
|
** then the result is always NULL.
|
|
** The jump is taken if the SQLITE_JUMPIFNULL bit is set.
|
|
*/
|
|
if libc.Int32FromUint16((*TOp)(unsafe.Pointer(pOp)).Fp5)&int32(SQLITE_JUMPIFNULL) != 0 {
|
|
goto jump_to_p2
|
|
}
|
|
iCompare = int32(1) /* Operands are not equal */
|
|
goto _189
|
|
}
|
|
} else {
|
|
/* Neither operand is NULL and we couldn't do the special high-speed
|
|
** integer comparison case. So do a general-case comparison. */
|
|
affinity = int8(libc.Int32FromUint16((*TOp)(unsafe.Pointer(pOp)).Fp5) & int32(SQLITE_AFF_MASK))
|
|
if int32(affinity) >= int32(SQLITE_AFF_NUMERIC) {
|
|
if (libc.Int32FromUint16(flags11)|libc.Int32FromUint16(flags3))&int32(MEM_Str) != 0 {
|
|
if libc.Int32FromUint16(flags11)&(libc.Int32FromInt32(MEM_Int)|libc.Int32FromInt32(MEM_IntReal)|libc.Int32FromInt32(MEM_Real)|libc.Int32FromInt32(MEM_Str)) == int32(MEM_Str) {
|
|
_applyNumericAffinity(tls, pIn1, 0)
|
|
flags3 = (*TMem)(unsafe.Pointer(pIn3)).Fflags
|
|
}
|
|
if libc.Int32FromUint16(flags3)&(libc.Int32FromInt32(MEM_Int)|libc.Int32FromInt32(MEM_IntReal)|libc.Int32FromInt32(MEM_Real)|libc.Int32FromInt32(MEM_Str)) == int32(MEM_Str) {
|
|
_applyNumericAffinity(tls, pIn3, 0)
|
|
}
|
|
}
|
|
} else {
|
|
if int32(affinity) == int32(SQLITE_AFF_TEXT) && (libc.Int32FromUint16(flags11)|libc.Int32FromUint16(flags3))&int32(MEM_Str) != 0 {
|
|
if libc.Int32FromUint16(flags11)&int32(MEM_Str) != 0 {
|
|
v191 = pIn1 + 16
|
|
*(*Tu16)(unsafe.Pointer(v191)) = Tu16(int32(*(*Tu16)(unsafe.Pointer(v191))) & ^(libc.Int32FromInt32(MEM_Int) | libc.Int32FromInt32(MEM_Real) | libc.Int32FromInt32(MEM_IntReal)))
|
|
} else {
|
|
if libc.Int32FromUint16(flags11)&(libc.Int32FromInt32(MEM_Int)|libc.Int32FromInt32(MEM_Real)|libc.Int32FromInt32(MEM_IntReal)) != 0 {
|
|
_sqlite3VdbeMemStringify(tls, pIn1, encoding, uint8(1))
|
|
flags11 = libc.Uint16FromInt32(libc.Int32FromUint16((*TMem)(unsafe.Pointer(pIn1)).Fflags) & ^libc.Int32FromInt32(MEM_TypeMask) | libc.Int32FromUint16(flags11)&int32(MEM_TypeMask))
|
|
if pIn1 == pIn3 {
|
|
flags3 = libc.Uint16FromInt32(libc.Int32FromUint16(flags11) | int32(MEM_Str))
|
|
}
|
|
}
|
|
}
|
|
if libc.Int32FromUint16(flags3)&int32(MEM_Str) != 0 {
|
|
v191 = pIn3 + 16
|
|
*(*Tu16)(unsafe.Pointer(v191)) = Tu16(int32(*(*Tu16)(unsafe.Pointer(v191))) & ^(libc.Int32FromInt32(MEM_Int) | libc.Int32FromInt32(MEM_Real) | libc.Int32FromInt32(MEM_IntReal)))
|
|
} else {
|
|
if libc.Int32FromUint16(flags3)&(libc.Int32FromInt32(MEM_Int)|libc.Int32FromInt32(MEM_Real)|libc.Int32FromInt32(MEM_IntReal)) != 0 {
|
|
_sqlite3VdbeMemStringify(tls, pIn3, encoding, uint8(1))
|
|
flags3 = libc.Uint16FromInt32(libc.Int32FromUint16((*TMem)(unsafe.Pointer(pIn3)).Fflags) & ^libc.Int32FromInt32(MEM_TypeMask) | libc.Int32FromUint16(flags3)&int32(MEM_TypeMask))
|
|
}
|
|
}
|
|
}
|
|
}
|
|
res = _sqlite3MemCompare(tls, pIn3, pIn1, *(*uintptr)(unsafe.Pointer(pOp + 16)))
|
|
}
|
|
/* At this point, res is negative, zero, or positive if reg[P1] is
|
|
** less than, equal to, or greater than reg[P3], respectively. Compute
|
|
** the answer to this operator in res2, depending on what the comparison
|
|
** operator actually is. The next block of code depends on the fact
|
|
** that the 6 comparison operators are consecutive integers in this
|
|
** order: NE, EQ, GT, LE, LT, GE */
|
|
if res < 0 {
|
|
res21 = libc.Int32FromUint8(**(**uint8)(__ccgo_up(_sqlite3aLTb + uintptr((*TOp)(unsafe.Pointer(pOp)).Fopcode))))
|
|
} else {
|
|
if res == 0 {
|
|
res21 = libc.Int32FromUint8(**(**uint8)(__ccgo_up(_sqlite3aEQb + uintptr((*TOp)(unsafe.Pointer(pOp)).Fopcode))))
|
|
} else {
|
|
res21 = libc.Int32FromUint8(**(**uint8)(__ccgo_up(_sqlite3aGTb + uintptr((*TOp)(unsafe.Pointer(pOp)).Fopcode))))
|
|
}
|
|
}
|
|
iCompare = res
|
|
/* Undo any changes made by applyAffinity() to the input registers. */
|
|
(*TMem)(unsafe.Pointer(pIn3)).Fflags = flags3
|
|
(*TMem)(unsafe.Pointer(pIn1)).Fflags = flags11
|
|
if res21 != 0 {
|
|
goto jump_to_p2
|
|
}
|
|
goto _189
|
|
/* Opcode: ElseEq * P2 * * *
|
|
**
|
|
** This opcode must follow an OP_Lt or OP_Gt comparison operator. There
|
|
** can be zero or more OP_ReleaseReg opcodes intervening, but no other
|
|
** opcodes are allowed to occur between this instruction and the previous
|
|
** OP_Lt or OP_Gt.
|
|
**
|
|
** If the result of an OP_Eq comparison on the same two operands as
|
|
** the prior OP_Lt or OP_Gt would have been true, then jump to P2. If
|
|
** the result of an OP_Eq comparison on the two previous operands
|
|
** would have been false or NULL, then fall through.
|
|
*/
|
|
_47:
|
|
; /* same as TK_ESCAPE, jump */
|
|
if iCompare == 0 {
|
|
goto jump_to_p2
|
|
}
|
|
goto _189
|
|
/* Opcode: Permutation * * * P4 *
|
|
**
|
|
** Set the permutation used by the OP_Compare operator in the next
|
|
** instruction. The permutation is stored in the P4 operand.
|
|
**
|
|
** The permutation is only valid for the next opcode which must be
|
|
** an OP_Compare that has the OPFLAG_PERMUTE bit set in P5.
|
|
**
|
|
** The first integer in the P4 integer array is the length of the array
|
|
** and does not become part of the permutation.
|
|
*/
|
|
_48:
|
|
;
|
|
goto _189
|
|
/* Opcode: Compare P1 P2 P3 P4 P5
|
|
** Synopsis: r[P1@P3] <-> r[P2@P3]
|
|
**
|
|
** Compare two vectors of registers in reg(P1)..reg(P1+P3-1) (call this
|
|
** vector "A") and in reg(P2)..reg(P2+P3-1) ("B"). Save the result of
|
|
** the comparison for use by the next OP_Jump instruct.
|
|
**
|
|
** If P5 has the OPFLAG_PERMUTE bit set, then the order of comparison is
|
|
** determined by the most recent OP_Permutation operator. If the
|
|
** OPFLAG_PERMUTE bit is clear, then register are compared in sequential
|
|
** order.
|
|
**
|
|
** P4 is a KeyInfo structure that defines collating sequences and sort
|
|
** orders for the comparison. The permutation applies to registers
|
|
** only. The KeyInfo elements are used sequentially.
|
|
**
|
|
** The comparison is a sort comparison, so NULLs compare equal,
|
|
** NULLs are less than numbers, numbers are less than strings,
|
|
** and strings are less than blobs.
|
|
**
|
|
** This opcode must be immediately followed by an OP_Jump opcode.
|
|
*/
|
|
_49:
|
|
; /* The permutation */
|
|
if libc.Int32FromUint16((*TOp)(unsafe.Pointer(pOp)).Fp5)&int32(OPFLAG_PERMUTE) == 0 {
|
|
aPermute = uintptr(0)
|
|
} else {
|
|
aPermute = *(*uintptr)(unsafe.Pointer(pOp + uintptr(-libc.Int32FromInt32(1))*20 + 16)) + uintptr(1)*4
|
|
}
|
|
n2 = (*TOp)(unsafe.Pointer(pOp)).Fp3
|
|
pKeyInfo = *(*uintptr)(unsafe.Pointer(pOp + 16))
|
|
p11 = (*TOp)(unsafe.Pointer(pOp)).Fp1
|
|
p21 = (*TOp)(unsafe.Pointer(pOp)).Fp2
|
|
i = 0
|
|
for {
|
|
if !(i < n2) {
|
|
break
|
|
}
|
|
if aPermute != 0 {
|
|
v213 = **(**Tu32)(__ccgo_up(aPermute + uintptr(i)*4))
|
|
} else {
|
|
v213 = libc.Uint32FromInt32(i)
|
|
}
|
|
idx = v213
|
|
pColl = *(*uintptr)(unsafe.Pointer(pKeyInfo + 20 + uintptr(i)*4))
|
|
bRev = libc.Int32FromUint8(**(**Tu8)(__ccgo_up((*TKeyInfo)(unsafe.Pointer(pKeyInfo)).FaSortFlags + uintptr(i)))) & int32(KEYINFO_ORDER_DESC)
|
|
iCompare = _sqlite3MemCompare(tls, aMem+uintptr(libc.Uint32FromInt32(p11)+idx)*40, aMem+uintptr(libc.Uint32FromInt32(p21)+idx)*40, pColl)
|
|
if iCompare != 0 {
|
|
if libc.Int32FromUint8(**(**Tu8)(__ccgo_up((*TKeyInfo)(unsafe.Pointer(pKeyInfo)).FaSortFlags + uintptr(i))))&int32(KEYINFO_ORDER_BIGNULL) != 0 && (libc.Int32FromUint16((**(**TMem)(__ccgo_up(aMem + uintptr(libc.Uint32FromInt32(p11)+idx)*40))).Fflags)&int32(MEM_Null) != 0 || libc.Int32FromUint16((**(**TMem)(__ccgo_up(aMem + uintptr(libc.Uint32FromInt32(p21)+idx)*40))).Fflags)&int32(MEM_Null) != 0) {
|
|
iCompare = -iCompare
|
|
}
|
|
if bRev != 0 {
|
|
iCompare = -iCompare
|
|
}
|
|
break
|
|
}
|
|
goto _212
|
|
_212:
|
|
;
|
|
i = i + 1
|
|
}
|
|
goto _189
|
|
/* Opcode: Jump P1 P2 P3 * *
|
|
**
|
|
** Jump to the instruction at address P1, P2, or P3 depending on whether
|
|
** in the most recent OP_Compare instruction the P1 vector was less than,
|
|
** equal to, or greater than the P2 vector, respectively.
|
|
**
|
|
** This opcode must immediately follow an OP_Compare opcode.
|
|
*/
|
|
_50:
|
|
; /* jump */
|
|
if iCompare < 0 {
|
|
pOp = aOp + uintptr((*TOp)(unsafe.Pointer(pOp)).Fp1-int32(1))*20
|
|
} else {
|
|
if iCompare == 0 {
|
|
pOp = aOp + uintptr((*TOp)(unsafe.Pointer(pOp)).Fp2-int32(1))*20
|
|
} else {
|
|
pOp = aOp + uintptr((*TOp)(unsafe.Pointer(pOp)).Fp3-int32(1))*20
|
|
}
|
|
}
|
|
goto _189
|
|
/* Opcode: And P1 P2 P3 * *
|
|
** Synopsis: r[P3]=(r[P1] && r[P2])
|
|
**
|
|
** Take the logical AND of the values in registers P1 and P2 and
|
|
** write the result into register P3.
|
|
**
|
|
** If either P1 or P2 is 0 (false) then the result is 0 even if
|
|
** the other input is NULL. A NULL and true or two NULLs give
|
|
** a NULL output.
|
|
*/
|
|
/* Opcode: Or P1 P2 P3 * *
|
|
** Synopsis: r[P3]=(r[P1] || r[P2])
|
|
**
|
|
** Take the logical OR of the values in register P1 and P2 and
|
|
** store the answer in register P3.
|
|
**
|
|
** If either P1 or P2 is nonzero (true) then the result is 1 (true)
|
|
** even if the other input is NULL. A NULL and false or two NULLs
|
|
** give a NULL output.
|
|
*/
|
|
_52:
|
|
; /* same as TK_AND, in1, in2, out3 */
|
|
_51:
|
|
; /* Right operand: 0==FALSE, 1==TRUE, 2==UNKNOWN or NULL */
|
|
v11 = _sqlite3VdbeBooleanValue(tls, aMem+uintptr((*TOp)(unsafe.Pointer(pOp)).Fp1)*40, int32(2))
|
|
v21 = _sqlite3VdbeBooleanValue(tls, aMem+uintptr((*TOp)(unsafe.Pointer(pOp)).Fp2)*40, int32(2))
|
|
if libc.Int32FromUint8((*TOp)(unsafe.Pointer(pOp)).Fopcode) == int32(OP_And) {
|
|
v11 = libc.Int32FromUint8(_and_logic[v11*int32(3)+v21])
|
|
} else {
|
|
v11 = libc.Int32FromUint8(_or_logic[v11*int32(3)+v21])
|
|
}
|
|
pOut = aMem + uintptr((*TOp)(unsafe.Pointer(pOp)).Fp3)*40
|
|
if v11 == int32(2) {
|
|
(*TMem)(unsafe.Pointer(pOut)).Fflags = libc.Uint16FromInt32(libc.Int32FromUint16((*TMem)(unsafe.Pointer(pOut)).Fflags) & ^(libc.Int32FromInt32(MEM_TypeMask)|libc.Int32FromInt32(MEM_Zero)) | int32(MEM_Null))
|
|
} else {
|
|
*(*Ti64)(unsafe.Pointer(pOut)) = int64(v11)
|
|
(*TMem)(unsafe.Pointer(pOut)).Fflags = libc.Uint16FromInt32(libc.Int32FromUint16((*TMem)(unsafe.Pointer(pOut)).Fflags) & ^(libc.Int32FromInt32(MEM_TypeMask)|libc.Int32FromInt32(MEM_Zero)) | int32(MEM_Int))
|
|
}
|
|
goto _189
|
|
/* Opcode: IsTrue P1 P2 P3 P4 *
|
|
** Synopsis: r[P2] = coalesce(r[P1]==TRUE,P3) ^ P4
|
|
**
|
|
** This opcode implements the IS TRUE, IS FALSE, IS NOT TRUE, and
|
|
** IS NOT FALSE operators.
|
|
**
|
|
** Interpret the value in register P1 as a boolean value. Store that
|
|
** boolean (a 0 or 1) in register P2. Or if the value in register P1 is
|
|
** NULL, then the P3 is stored in register P2. Invert the answer if P4
|
|
** is 1.
|
|
**
|
|
** The logic is summarized like this:
|
|
**
|
|
** <ul>
|
|
** <li> If P3==0 and P4==0 then r[P2] := r[P1] IS TRUE
|
|
** <li> If P3==1 and P4==1 then r[P2] := r[P1] IS FALSE
|
|
** <li> If P3==0 and P4==1 then r[P2] := r[P1] IS NOT TRUE
|
|
** <li> If P3==1 and P4==0 then r[P2] := r[P1] IS NOT FALSE
|
|
** </ul>
|
|
*/
|
|
_53:
|
|
; /* in1, out2 */
|
|
_sqlite3VdbeMemSetInt64(tls, aMem+uintptr((*TOp)(unsafe.Pointer(pOp)).Fp2)*40, int64(_sqlite3VdbeBooleanValue(tls, aMem+uintptr((*TOp)(unsafe.Pointer(pOp)).Fp1)*40, (*TOp)(unsafe.Pointer(pOp)).Fp3)^*(*int32)(unsafe.Pointer(pOp + 16))))
|
|
goto _189
|
|
/* Opcode: Not P1 P2 * * *
|
|
** Synopsis: r[P2]= !r[P1]
|
|
**
|
|
** Interpret the value in register P1 as a boolean value. Store the
|
|
** boolean complement in register P2. If the value in register P1 is
|
|
** NULL, then a NULL is stored in P2.
|
|
*/
|
|
_54:
|
|
; /* same as TK_NOT, in1, out2 */
|
|
pIn1 = aMem + uintptr((*TOp)(unsafe.Pointer(pOp)).Fp1)*40
|
|
pOut = aMem + uintptr((*TOp)(unsafe.Pointer(pOp)).Fp2)*40
|
|
if libc.Int32FromUint16((*TMem)(unsafe.Pointer(pIn1)).Fflags)&int32(MEM_Null) == 0 {
|
|
_sqlite3VdbeMemSetInt64(tls, pOut, libc.BoolInt64(!(_sqlite3VdbeBooleanValue(tls, pIn1, 0) != 0)))
|
|
} else {
|
|
_sqlite3VdbeMemSetNull(tls, pOut)
|
|
}
|
|
goto _189
|
|
/* Opcode: BitNot P1 P2 * * *
|
|
** Synopsis: r[P2]= ~r[P1]
|
|
**
|
|
** Interpret the content of register P1 as an integer. Store the
|
|
** ones-complement of the P1 value into register P2. If P1 holds
|
|
** a NULL then store a NULL in P2.
|
|
*/
|
|
_55:
|
|
; /* same as TK_BITNOT, in1, out2 */
|
|
pIn1 = aMem + uintptr((*TOp)(unsafe.Pointer(pOp)).Fp1)*40
|
|
pOut = aMem + uintptr((*TOp)(unsafe.Pointer(pOp)).Fp2)*40
|
|
_sqlite3VdbeMemSetNull(tls, pOut)
|
|
if libc.Int32FromUint16((*TMem)(unsafe.Pointer(pIn1)).Fflags)&int32(MEM_Null) == 0 {
|
|
(*TMem)(unsafe.Pointer(pOut)).Fflags = uint16(MEM_Int)
|
|
*(*Ti64)(unsafe.Pointer(pOut)) = ^_sqlite3VdbeIntValue(tls, pIn1)
|
|
}
|
|
goto _189
|
|
/* Opcode: Once P1 P2 P3 * *
|
|
**
|
|
** Fall through to the next instruction the first time this opcode is
|
|
** encountered on each invocation of the byte-code program. Jump to P2
|
|
** on the second and all subsequent encounters during the same invocation.
|
|
**
|
|
** Top-level programs determine first invocation by comparing the P1
|
|
** operand against the P1 operand on the OP_Init opcode at the beginning
|
|
** of the program. If the P1 values differ, then fall through and make
|
|
** the P1 of this opcode equal to the P1 of OP_Init. If P1 values are
|
|
** the same then take the jump.
|
|
**
|
|
** For subprograms, there is a bitmask in the VdbeFrame that determines
|
|
** whether or not the jump should be taken. The bitmask is necessary
|
|
** because the self-altering code trick does not work for recursive
|
|
** triggers.
|
|
**
|
|
** The P3 operand is not used directly by this opcode. However P3 is
|
|
** used by the code generator as follows: If this opcode is the start
|
|
** of a subroutine and that subroutine uses a Bloom filter, then P3 will
|
|
** be the register that holds that Bloom filter. See tag-202407032019
|
|
** in the source code for implementation details.
|
|
*/
|
|
_56:
|
|
; /* Address of this instruction */
|
|
if (*TVdbe)(unsafe.Pointer(p)).FpFrame != 0 {
|
|
iAddr = libc.Uint32FromInt32((int32(pOp) - int32((*TVdbe)(unsafe.Pointer(p)).FaOp)) / 20)
|
|
if libc.Int32FromUint8(**(**Tu8)(__ccgo_up((*TVdbeFrame)(unsafe.Pointer((*TVdbe)(unsafe.Pointer(p)).FpFrame)).FaOnce + uintptr(iAddr/uint32(8)))))&(int32(1)<<(iAddr&uint32(7))) != 0 {
|
|
goto jump_to_p2
|
|
}
|
|
v191 = (*TVdbeFrame)(unsafe.Pointer((*TVdbe)(unsafe.Pointer(p)).FpFrame)).FaOnce + uintptr(iAddr/uint32(8))
|
|
*(*Tu8)(unsafe.Pointer(v191)) = Tu8(int32(*(*Tu8)(unsafe.Pointer(v191))) | libc.Int32FromInt32(1)<<(iAddr&libc.Uint32FromInt32(7)))
|
|
} else {
|
|
if (**(**TOp)(__ccgo_up((*TVdbe)(unsafe.Pointer(p)).FaOp))).Fp1 == (*TOp)(unsafe.Pointer(pOp)).Fp1 {
|
|
goto jump_to_p2
|
|
}
|
|
}
|
|
(*TOp)(unsafe.Pointer(pOp)).Fp1 = (**(**TOp)(__ccgo_up((*TVdbe)(unsafe.Pointer(p)).FaOp))).Fp1
|
|
goto _189
|
|
/* Opcode: If P1 P2 P3 * *
|
|
**
|
|
** Jump to P2 if the value in register P1 is true. The value
|
|
** is considered true if it is numeric and non-zero. If the value
|
|
** in P1 is NULL then take the jump if and only if P3 is non-zero.
|
|
*/
|
|
_57:
|
|
;
|
|
c = _sqlite3VdbeBooleanValue(tls, aMem+uintptr((*TOp)(unsafe.Pointer(pOp)).Fp1)*40, (*TOp)(unsafe.Pointer(pOp)).Fp3)
|
|
if c != 0 {
|
|
goto jump_to_p2
|
|
}
|
|
goto _189
|
|
/* Opcode: IfNot P1 P2 P3 * *
|
|
**
|
|
** Jump to P2 if the value in register P1 is False. The value
|
|
** is considered false if it has a numeric value of zero. If the value
|
|
** in P1 is NULL then take the jump if and only if P3 is non-zero.
|
|
*/
|
|
_58:
|
|
;
|
|
c1 = libc.BoolInt32(!(_sqlite3VdbeBooleanValue(tls, aMem+uintptr((*TOp)(unsafe.Pointer(pOp)).Fp1)*40, libc.BoolInt32(!((*TOp)(unsafe.Pointer(pOp)).Fp3 != 0))) != 0))
|
|
if c1 != 0 {
|
|
goto jump_to_p2
|
|
}
|
|
goto _189
|
|
/* Opcode: IsNull P1 P2 * * *
|
|
** Synopsis: if r[P1]==NULL goto P2
|
|
**
|
|
** Jump to P2 if the value in register P1 is NULL.
|
|
*/
|
|
_59:
|
|
; /* same as TK_ISNULL, jump, in1 */
|
|
pIn1 = aMem + uintptr((*TOp)(unsafe.Pointer(pOp)).Fp1)*40
|
|
if libc.Int32FromUint16((*TMem)(unsafe.Pointer(pIn1)).Fflags)&int32(MEM_Null) != 0 {
|
|
goto jump_to_p2
|
|
}
|
|
goto _189
|
|
/* Opcode: IsType P1 P2 P3 P4 P5
|
|
** Synopsis: if typeof(P1.P3) in P5 goto P2
|
|
**
|
|
** Jump to P2 if the type of a column in a btree is one of the types specified
|
|
** by the P5 bitmask.
|
|
**
|
|
** P1 is normally a cursor on a btree for which the row decode cache is
|
|
** valid through at least column P3. In other words, there should have been
|
|
** a prior OP_Column for column P3 or greater. If the cursor is not valid,
|
|
** then this opcode might give spurious results.
|
|
** The the btree row has fewer than P3 columns, then use P4 as the
|
|
** datatype.
|
|
**
|
|
** If P1 is -1, then P3 is a register number and the datatype is taken
|
|
** from the value in that register.
|
|
**
|
|
** P5 is a bitmask of data types. SQLITE_INTEGER is the least significant
|
|
** (0x01) bit. SQLITE_FLOAT is the 0x02 bit. SQLITE_TEXT is 0x04.
|
|
** SQLITE_BLOB is 0x08. SQLITE_NULL is 0x10.
|
|
**
|
|
** WARNING: This opcode does not reliably distinguish between NULL and REAL
|
|
** when P1>=0. If the database contains a NaN value, this opcode will think
|
|
** that the datatype is REAL when it should be NULL. When P1<0 and the value
|
|
** is already stored in register P3, then this opcode does reliably
|
|
** distinguish between NULL and REAL. The problem only arises then P1>=0.
|
|
**
|
|
** Take the jump to address P2 if and only if the datatype of the
|
|
** value determined by P1 and P3 corresponds to one of the bits in the
|
|
** P5 bitmask.
|
|
**
|
|
*/
|
|
_60:
|
|
;
|
|
if (*TOp)(unsafe.Pointer(pOp)).Fp1 >= 0 {
|
|
pC = **(**uintptr)(__ccgo_up((*TVdbe)(unsafe.Pointer(p)).FapCsr + uintptr((*TOp)(unsafe.Pointer(pOp)).Fp1)*4))
|
|
if (*TOp)(unsafe.Pointer(pOp)).Fp3 < libc.Int32FromUint16((*TVdbeCursor)(unsafe.Pointer(pC)).FnHdrParsed) {
|
|
serialType = *(*Tu32)(unsafe.Pointer(pC + 84 + uintptr((*TOp)(unsafe.Pointer(pOp)).Fp3)*4))
|
|
if serialType >= uint32(12) {
|
|
if serialType&uint32(1) != 0 {
|
|
typeMask = uint16(0x04) /* SQLITE_TEXT */
|
|
} else {
|
|
typeMask = uint16(0x08) /* SQLITE_BLOB */
|
|
}
|
|
} else {
|
|
typeMask = uint16(_aMask[serialType])
|
|
}
|
|
} else {
|
|
typeMask = libc.Uint16FromInt32(int32(1) << (*(*int32)(unsafe.Pointer(pOp + 16)) - int32(1)))
|
|
}
|
|
} else {
|
|
typeMask = libc.Uint16FromInt32(int32(1) << (Xsqlite3_value_type(tls, aMem+uintptr((*TOp)(unsafe.Pointer(pOp)).Fp3)*40) - int32(1)))
|
|
}
|
|
if libc.Int32FromUint16(typeMask)&libc.Int32FromUint16((*TOp)(unsafe.Pointer(pOp)).Fp5) != 0 {
|
|
goto jump_to_p2
|
|
}
|
|
goto _189
|
|
/* Opcode: ZeroOrNull P1 P2 P3 * *
|
|
** Synopsis: r[P2] = 0 OR NULL
|
|
**
|
|
** If both registers P1 and P3 are NOT NULL, then store a zero in
|
|
** register P2. If either registers P1 or P3 are NULL then put
|
|
** a NULL in register P2.
|
|
*/
|
|
_61:
|
|
; /* in1, in2, out2, in3 */
|
|
if libc.Int32FromUint16((**(**TMem)(__ccgo_up(aMem + uintptr((*TOp)(unsafe.Pointer(pOp)).Fp1)*40))).Fflags)&int32(MEM_Null) != 0 || libc.Int32FromUint16((**(**TMem)(__ccgo_up(aMem + uintptr((*TOp)(unsafe.Pointer(pOp)).Fp3)*40))).Fflags)&int32(MEM_Null) != 0 {
|
|
_sqlite3VdbeMemSetNull(tls, aMem+uintptr((*TOp)(unsafe.Pointer(pOp)).Fp2)*40)
|
|
} else {
|
|
_sqlite3VdbeMemSetInt64(tls, aMem+uintptr((*TOp)(unsafe.Pointer(pOp)).Fp2)*40, 0)
|
|
}
|
|
goto _189
|
|
/* Opcode: NotNull P1 P2 * * *
|
|
** Synopsis: if r[P1]!=NULL goto P2
|
|
**
|
|
** Jump to P2 if the value in register P1 is not NULL.
|
|
*/
|
|
_62:
|
|
; /* same as TK_NOTNULL, jump, in1 */
|
|
pIn1 = aMem + uintptr((*TOp)(unsafe.Pointer(pOp)).Fp1)*40
|
|
if libc.Int32FromUint16((*TMem)(unsafe.Pointer(pIn1)).Fflags)&int32(MEM_Null) == 0 {
|
|
goto jump_to_p2
|
|
}
|
|
goto _189
|
|
/* Opcode: IfNullRow P1 P2 P3 * *
|
|
** Synopsis: if P1.nullRow then r[P3]=NULL, goto P2
|
|
**
|
|
** Check the cursor P1 to see if it is currently pointing at a NULL row.
|
|
** If it is, then set register P3 to NULL and jump immediately to P2.
|
|
** If P1 is not on a NULL row, then fall through without making any
|
|
** changes.
|
|
**
|
|
** If P1 is not an open cursor, then this opcode is a no-op.
|
|
*/
|
|
_63:
|
|
;
|
|
pC1 = **(**uintptr)(__ccgo_up((*TVdbe)(unsafe.Pointer(p)).FapCsr + uintptr((*TOp)(unsafe.Pointer(pOp)).Fp1)*4))
|
|
if pC1 != 0 && (*TVdbeCursor)(unsafe.Pointer(pC1)).FnullRow != 0 {
|
|
_sqlite3VdbeMemSetNull(tls, aMem+uintptr((*TOp)(unsafe.Pointer(pOp)).Fp3)*40)
|
|
goto jump_to_p2
|
|
}
|
|
goto _189
|
|
/* Opcode: Offset P1 P2 P3 * *
|
|
** Synopsis: r[P3] = sqlite_offset(P1)
|
|
**
|
|
** Store in register r[P3] the byte offset into the database file that is the
|
|
** start of the payload for the record at which that cursor P1 is currently
|
|
** pointing.
|
|
**
|
|
** P2 is the column number for the argument to the sqlite_offset() function.
|
|
** This opcode does not use P2 itself, but the P2 value is used by the
|
|
** code generator. The P1, P2, and P3 operands to this opcode are the
|
|
** same as for OP_Column.
|
|
**
|
|
** This opcode is only available if SQLite is compiled with the
|
|
** -DSQLITE_ENABLE_OFFSET_SQL_FUNC option.
|
|
*/
|
|
_64:
|
|
; /* The VDBE cursor */
|
|
pC2 = **(**uintptr)(__ccgo_up((*TVdbe)(unsafe.Pointer(p)).FapCsr + uintptr((*TOp)(unsafe.Pointer(pOp)).Fp1)*4))
|
|
pOut = (*TVdbe)(unsafe.Pointer(p)).FaMem + uintptr((*TOp)(unsafe.Pointer(pOp)).Fp3)*40
|
|
if pC2 == uintptr(0) || libc.Int32FromUint8((*TVdbeCursor)(unsafe.Pointer(pC2)).FeCurType) != CURTYPE_BTREE {
|
|
_sqlite3VdbeMemSetNull(tls, pOut)
|
|
} else {
|
|
if (*TVdbeCursor)(unsafe.Pointer(pC2)).FdeferredMoveto != 0 {
|
|
rc = _sqlite3VdbeFinishMoveto(tls, pC2)
|
|
if rc != 0 {
|
|
goto abort_due_to_error
|
|
}
|
|
}
|
|
if _sqlite3BtreeEof(tls, *(*uintptr)(unsafe.Pointer(pC2 + 36))) != 0 {
|
|
_sqlite3VdbeMemSetNull(tls, pOut)
|
|
} else {
|
|
_sqlite3VdbeMemSetInt64(tls, pOut, _sqlite3BtreeOffset(tls, *(*uintptr)(unsafe.Pointer(pC2 + 36))))
|
|
}
|
|
}
|
|
goto _189
|
|
/* Opcode: Column P1 P2 P3 P4 P5
|
|
** Synopsis: r[P3]=PX cursor P1 column P2
|
|
**
|
|
** Interpret the data that cursor P1 points to as a structure built using
|
|
** the MakeRecord instruction. (See the MakeRecord opcode for additional
|
|
** information about the format of the data.) Extract the P2-th column
|
|
** from this record. If there are less than (P2+1)
|
|
** values in the record, extract a NULL.
|
|
**
|
|
** The value extracted is stored in register P3.
|
|
**
|
|
** If the record contains fewer than P2 fields, then extract a NULL. Or,
|
|
** if the P4 argument is a P4_MEM use the value of the P4 argument as
|
|
** the result.
|
|
**
|
|
** If the OPFLAG_LENGTHARG bit is set in P5 then the result is guaranteed
|
|
** to only be used by the length() function or the equivalent. The content
|
|
** of large blobs is not loaded, thus saving CPU cycles. If the
|
|
** OPFLAG_TYPEOFARG bit is set then the result will only be used by the
|
|
** typeof() function or the IS NULL or IS NOT NULL operators or the
|
|
** equivalent. In this case, all content loading can be omitted.
|
|
*/
|
|
_65:
|
|
; /* PseudoTable input register */
|
|
pC3 = **(**uintptr)(__ccgo_up((*TVdbe)(unsafe.Pointer(p)).FapCsr + uintptr((*TOp)(unsafe.Pointer(pOp)).Fp1)*4))
|
|
p22 = libc.Uint32FromInt32((*TOp)(unsafe.Pointer(pOp)).Fp2)
|
|
goto op_column_restart
|
|
op_column_restart:
|
|
;
|
|
aOffset = (*TVdbeCursor)(unsafe.Pointer(pC3)).FaOffset
|
|
if (*TVdbeCursor)(unsafe.Pointer(pC3)).FcacheStatus != (*TVdbe)(unsafe.Pointer(p)).FcacheCtr { /*OPTIMIZATION-IF-FALSE*/
|
|
if (*TVdbeCursor)(unsafe.Pointer(pC3)).FnullRow != 0 {
|
|
if libc.Int32FromUint8((*TVdbeCursor)(unsafe.Pointer(pC3)).FeCurType) == int32(CURTYPE_PSEUDO) && (*TVdbeCursor)(unsafe.Pointer(pC3)).FseekResult > 0 {
|
|
/* For the special case of as pseudo-cursor, the seekResult field
|
|
** identifies the register that holds the record */
|
|
pReg = aMem + uintptr((*TVdbeCursor)(unsafe.Pointer(pC3)).FseekResult)*40
|
|
v215 = libc.Uint32FromInt32((*TMem)(unsafe.Pointer(pReg)).Fn)
|
|
(*TVdbeCursor)(unsafe.Pointer(pC3)).FszRow = v215
|
|
(*TVdbeCursor)(unsafe.Pointer(pC3)).FpayloadSize = v215
|
|
(*TVdbeCursor)(unsafe.Pointer(pC3)).FaRow = (*TMem)(unsafe.Pointer(pReg)).Fz
|
|
} else {
|
|
pDest = aMem + uintptr((*TOp)(unsafe.Pointer(pOp)).Fp3)*40
|
|
_sqlite3VdbeMemSetNull(tls, pDest)
|
|
goto op_column_out
|
|
}
|
|
} else {
|
|
pCrsr = *(*uintptr)(unsafe.Pointer(pC3 + 36))
|
|
if (*TVdbeCursor)(unsafe.Pointer(pC3)).FdeferredMoveto != 0 {
|
|
if v217 = *(*uintptr)(unsafe.Pointer(pC3 + 12)) != 0; v217 {
|
|
v215 = **(**Tu32)(__ccgo_up(*(*uintptr)(unsafe.Pointer(pC3 + 12)) + uintptr(uint32(1)+p22)*4))
|
|
iMap = v215
|
|
}
|
|
if v217 && v215 > uint32(0) {
|
|
pC3 = (*TVdbeCursor)(unsafe.Pointer(pC3)).FpAltCursor
|
|
p22 = iMap - uint32(1)
|
|
goto op_column_restart
|
|
}
|
|
rc = _sqlite3VdbeFinishMoveto(tls, pC3)
|
|
if rc != 0 {
|
|
goto abort_due_to_error
|
|
}
|
|
} else {
|
|
if _sqlite3BtreeCursorHasMoved(tls, pCrsr) != 0 {
|
|
rc = _sqlite3VdbeHandleMovedCursor(tls, pC3)
|
|
if rc != 0 {
|
|
goto abort_due_to_error
|
|
}
|
|
goto op_column_restart
|
|
}
|
|
}
|
|
(*TVdbeCursor)(unsafe.Pointer(pC3)).FpayloadSize = _sqlite3BtreePayloadSize(tls, pCrsr)
|
|
(*TVdbeCursor)(unsafe.Pointer(pC3)).FaRow = _sqlite3BtreePayloadFetch(tls, pCrsr, pC3+76)
|
|
/* Maximum page size is 64KiB */
|
|
}
|
|
(*TVdbeCursor)(unsafe.Pointer(pC3)).FcacheStatus = (*TVdbe)(unsafe.Pointer(p)).FcacheCtr
|
|
v215 = uint32(**(**Tu8)(__ccgo_up((*TVdbeCursor)(unsafe.Pointer(pC3)).FaRow)))
|
|
**(**Tu32)(__ccgo_up(aOffset)) = v215
|
|
if v215 < uint32(0x80) {
|
|
(*TVdbeCursor)(unsafe.Pointer(pC3)).FiHdrOffset = uint32(1)
|
|
} else {
|
|
(*TVdbeCursor)(unsafe.Pointer(pC3)).FiHdrOffset = uint32(_sqlite3GetVarint32(tls, (*TVdbeCursor)(unsafe.Pointer(pC3)).FaRow, aOffset))
|
|
}
|
|
(*TVdbeCursor)(unsafe.Pointer(pC3)).FnHdrParsed = uint16(0)
|
|
if (*TVdbeCursor)(unsafe.Pointer(pC3)).FszRow < **(**Tu32)(__ccgo_up(aOffset)) { /*OPTIMIZATION-IF-FALSE*/
|
|
/* pC->aRow does not have to hold the entire row, but it does at least
|
|
** need to cover the header of the record. If pC->aRow does not contain
|
|
** the complete header, then set it to zero, forcing the header to be
|
|
** dynamically allocated. */
|
|
(*TVdbeCursor)(unsafe.Pointer(pC3)).FaRow = uintptr(0)
|
|
(*TVdbeCursor)(unsafe.Pointer(pC3)).FszRow = uint32(0)
|
|
/* Make sure a corrupt database has not given us an oversize header.
|
|
** Do this now to avoid an oversize memory allocation.
|
|
**
|
|
** Type entries can be between 1 and 5 bytes each. But 4 and 5 byte
|
|
** types use so much data space that there can only be 4096 and 32 of
|
|
** them, respectively. So the maximum header length results from a
|
|
** 3-byte type for each of the maximum of 32768 columns plus three
|
|
** extra bytes for the header length itself. 32768*3 + 3 = 98307.
|
|
*/
|
|
if **(**Tu32)(__ccgo_up(aOffset)) > uint32(98307) || **(**Tu32)(__ccgo_up(aOffset)) > (*TVdbeCursor)(unsafe.Pointer(pC3)).FpayloadSize {
|
|
goto op_column_corrupt
|
|
}
|
|
} else {
|
|
/* This is an optimization. By skipping over the first few tests
|
|
** (ex: pC->nHdrParsed<=p2) in the next section, we achieve a
|
|
** measurable performance gain.
|
|
**
|
|
** This branch is taken even if aOffset[0]==0. Such a record is never
|
|
** generated by SQLite, and could be considered corruption, but we
|
|
** accept it for historical reasons. When aOffset[0]==0, the code this
|
|
** branch jumps to reads past the end of the record, but never more
|
|
** than a few bytes. Even if the record occurs at the end of the page
|
|
** content area, the "page header" comes after the page content and so
|
|
** this overread is harmless. Similar overreads can occur for a corrupt
|
|
** database file.
|
|
*/
|
|
zData = (*TVdbeCursor)(unsafe.Pointer(pC3)).FaRow
|
|
/* Conditional skipped */
|
|
goto op_column_read_header
|
|
}
|
|
} else {
|
|
if _sqlite3BtreeCursorHasMoved(tls, *(*uintptr)(unsafe.Pointer(pC3 + 36))) != 0 {
|
|
rc = _sqlite3VdbeHandleMovedCursor(tls, pC3)
|
|
if rc != 0 {
|
|
goto abort_due_to_error
|
|
}
|
|
goto op_column_restart
|
|
}
|
|
}
|
|
/* Make sure at least the first p2+1 entries of the header have been
|
|
** parsed and valid information is in aOffset[] and pC->aType[].
|
|
*/
|
|
if !(uint32((*TVdbeCursor)(unsafe.Pointer(pC3)).FnHdrParsed) <= p22) {
|
|
goto _219
|
|
}
|
|
/* If there is more header available for parsing in the record, try
|
|
** to extract additional fields up through the p2+1-th field
|
|
*/
|
|
if !((*TVdbeCursor)(unsafe.Pointer(pC3)).FiHdrOffset < **(**Tu32)(__ccgo_up(aOffset))) {
|
|
goto _221
|
|
}
|
|
/* Make sure zData points to enough of the record to cover the header. */
|
|
if (*TVdbeCursor)(unsafe.Pointer(pC3)).FaRow == uintptr(0) {
|
|
libc.Xmemset(tls, bp+24, 0, uint32(40))
|
|
rc = _sqlite3VdbeMemFromBtreeZeroOffset(tls, *(*uintptr)(unsafe.Pointer(pC3 + 36)), **(**Tu32)(__ccgo_up(aOffset)), bp+24)
|
|
if rc != SQLITE_OK {
|
|
goto abort_due_to_error
|
|
}
|
|
zData = (**(**TMem)(__ccgo_up(bp + 24))).Fz
|
|
} else {
|
|
zData = (*TVdbeCursor)(unsafe.Pointer(pC3)).FaRow
|
|
}
|
|
/* Fill in pC->aType[i] and aOffset[i] values through the p2-th field. */
|
|
goto op_column_read_header
|
|
op_column_read_header:
|
|
;
|
|
i1 = libc.Int32FromUint16((*TVdbeCursor)(unsafe.Pointer(pC3)).FnHdrParsed)
|
|
offset64 = uint64(**(**Tu32)(__ccgo_up(aOffset + uintptr(i1)*4)))
|
|
zHdr = zData + uintptr((*TVdbeCursor)(unsafe.Pointer(pC3)).FiHdrOffset)
|
|
zEndHdr = zData + uintptr(**(**Tu32)(__ccgo_up(aOffset)))
|
|
for cond := true; cond; cond = libc.Uint32FromInt32(i1) <= p22 && zHdr < zEndHdr {
|
|
v216 = uint32(**(**Tu8)(__ccgo_up(zHdr)))
|
|
**(**Tu32)(__ccgo_up(bp + 64)) = v216
|
|
v215 = v216
|
|
*(*Tu32)(unsafe.Pointer(pC3 + 84 + uintptr(i1)*4)) = v215
|
|
if v215 < uint32(0x80) {
|
|
zHdr = zHdr + 1
|
|
offset64 = offset64 + uint64(_sqlite3VdbeOneByteSerialTypeLen(tls, uint8(**(**Tu32)(__ccgo_up(bp + 64)))))
|
|
} else {
|
|
zHdr = zHdr + uintptr(_sqlite3GetVarint32(tls, zHdr, bp+64))
|
|
*(*Tu32)(unsafe.Pointer(pC3 + 84 + uintptr(i1)*4)) = **(**Tu32)(__ccgo_up(bp + 64))
|
|
offset64 = offset64 + uint64(_sqlite3VdbeSerialTypeLen(tls, **(**Tu32)(__ccgo_up(bp + 64))))
|
|
}
|
|
i1 = i1 + 1
|
|
v190 = i1
|
|
**(**Tu32)(__ccgo_up(aOffset + uintptr(v190)*4)) = uint32(offset64 & libc.Uint64FromUint32(0xffffffff))
|
|
}
|
|
/* The record is corrupt if any of the following are true:
|
|
** (1) the bytes of the header extend past the declared header size
|
|
** (2) the entire header was used but not all data was used
|
|
** (3) the end of the data extends beyond the end of the record.
|
|
*/
|
|
if zHdr >= zEndHdr && (zHdr > zEndHdr || offset64 != uint64((*TVdbeCursor)(unsafe.Pointer(pC3)).FpayloadSize)) || offset64 > uint64((*TVdbeCursor)(unsafe.Pointer(pC3)).FpayloadSize) {
|
|
if **(**Tu32)(__ccgo_up(aOffset)) == uint32(0) {
|
|
i1 = 0
|
|
zHdr = zEndHdr
|
|
} else {
|
|
if (*TVdbeCursor)(unsafe.Pointer(pC3)).FaRow == uintptr(0) {
|
|
_sqlite3VdbeMemRelease(tls, bp+24)
|
|
}
|
|
goto op_column_corrupt
|
|
}
|
|
}
|
|
(*TVdbeCursor)(unsafe.Pointer(pC3)).FnHdrParsed = libc.Uint16FromInt32(i1)
|
|
(*TVdbeCursor)(unsafe.Pointer(pC3)).FiHdrOffset = libc.Uint32FromInt32(int32(zHdr) - int32(zData))
|
|
if (*TVdbeCursor)(unsafe.Pointer(pC3)).FaRow == uintptr(0) {
|
|
_sqlite3VdbeMemRelease(tls, bp+24)
|
|
}
|
|
goto _222
|
|
_221:
|
|
;
|
|
**(**Tu32)(__ccgo_up(bp + 64)) = uint32(0)
|
|
_222:
|
|
;
|
|
/* If after trying to extract new entries from the header, nHdrParsed is
|
|
** still not up to p2, that means that the record has fewer than p2
|
|
** columns. So the result will be either the default value or a NULL.
|
|
*/
|
|
if uint32((*TVdbeCursor)(unsafe.Pointer(pC3)).FnHdrParsed) <= p22 {
|
|
pDest = aMem + uintptr((*TOp)(unsafe.Pointer(pOp)).Fp3)*40
|
|
if int32((*TOp)(unsafe.Pointer(pOp)).Fp4type) == -int32(11) {
|
|
_sqlite3VdbeMemShallowCopy(tls, pDest, *(*uintptr)(unsafe.Pointer(pOp + 16)), int32(MEM_Static))
|
|
} else {
|
|
_sqlite3VdbeMemSetNull(tls, pDest)
|
|
}
|
|
goto op_column_out
|
|
}
|
|
goto _220
|
|
_219:
|
|
;
|
|
**(**Tu32)(__ccgo_up(bp + 64)) = *(*Tu32)(unsafe.Pointer(pC3 + 84 + uintptr(p22)*4))
|
|
_220:
|
|
;
|
|
/* Extract the content for the p2+1-th column. Control can only
|
|
** reach this point if aOffset[p2], aOffset[p2+1], and pC->aType[p2] are
|
|
** all valid.
|
|
*/
|
|
pDest = aMem + uintptr((*TOp)(unsafe.Pointer(pOp)).Fp3)*40
|
|
if libc.Int32FromUint16((*TMem)(unsafe.Pointer(pDest)).Fflags)&(libc.Int32FromInt32(MEM_Agg)|libc.Int32FromInt32(MEM_Dyn)) != 0 {
|
|
_sqlite3VdbeMemSetNull(tls, pDest)
|
|
}
|
|
if (*TVdbeCursor)(unsafe.Pointer(pC3)).FszRow >= **(**Tu32)(__ccgo_up(aOffset + uintptr(p22+uint32(1))*4)) {
|
|
/* This is the common case where the desired content fits on the original
|
|
** page - where the content is not on an overflow page */
|
|
zData = (*TVdbeCursor)(unsafe.Pointer(pC3)).FaRow + uintptr(**(**Tu32)(__ccgo_up(aOffset + uintptr(p22)*4)))
|
|
if **(**Tu32)(__ccgo_up(bp + 64)) < uint32(12) {
|
|
_sqlite3VdbeSerialGet(tls, zData, **(**Tu32)(__ccgo_up(bp + 64)), pDest)
|
|
} else {
|
|
v190 = libc.Int32FromUint32((**(**Tu32)(__ccgo_up(bp + 64)) - libc.Uint32FromInt32(12)) / libc.Uint32FromInt32(2))
|
|
len1 = v190
|
|
(*TMem)(unsafe.Pointer(pDest)).Fn = v190
|
|
(*TMem)(unsafe.Pointer(pDest)).Fenc = encoding
|
|
if (*TMem)(unsafe.Pointer(pDest)).FszMalloc < len1+int32(2) {
|
|
if len1 > **(**int32)(__ccgo_up(db + 116)) {
|
|
goto too_big
|
|
}
|
|
(*TMem)(unsafe.Pointer(pDest)).Fflags = uint16(MEM_Null)
|
|
if _sqlite3VdbeMemGrow(tls, pDest, len1+int32(2), 0) != 0 {
|
|
goto no_mem
|
|
}
|
|
} else {
|
|
(*TMem)(unsafe.Pointer(pDest)).Fz = (*TMem)(unsafe.Pointer(pDest)).FzMalloc
|
|
}
|
|
libc.Xmemcpy(tls, (*TMem)(unsafe.Pointer(pDest)).Fz, zData, libc.Uint32FromInt32(len1))
|
|
**(**int8)(__ccgo_up((*TMem)(unsafe.Pointer(pDest)).Fz + uintptr(len1))) = 0
|
|
**(**int8)(__ccgo_up((*TMem)(unsafe.Pointer(pDest)).Fz + uintptr(len1+int32(1)))) = 0
|
|
(*TMem)(unsafe.Pointer(pDest)).Fflags = _aFlag1[**(**Tu32)(__ccgo_up(bp + 64))&uint32(1)]
|
|
}
|
|
} else {
|
|
(*TMem)(unsafe.Pointer(pDest)).Fenc = encoding
|
|
/* This branch happens only when content is on overflow pages */
|
|
v227 = libc.Uint8FromInt32(libc.Int32FromUint16((*TOp)(unsafe.Pointer(pOp)).Fp5) & libc.Int32FromInt32(OPFLAG_BYTELENARG))
|
|
p5 = v227
|
|
if libc.Int32FromUint8(v227) != 0 && (libc.Int32FromUint8(p5) == int32(OPFLAG_TYPEOFARG) || **(**Tu32)(__ccgo_up(bp + 64)) >= uint32(12) && (**(**Tu32)(__ccgo_up(bp + 64))&uint32(1) == uint32(0) || libc.Int32FromUint8(p5) == int32(OPFLAG_BYTELENARG))) || _sqlite3VdbeSerialTypeLen(tls, **(**Tu32)(__ccgo_up(bp + 64))) == uint32(0) {
|
|
/* Content is irrelevant for
|
|
** 1. the typeof() function,
|
|
** 2. the length(X) function if X is a blob, and
|
|
** 3. if the content length is zero.
|
|
** So we might as well use bogus content rather than reading
|
|
** content from disk.
|
|
**
|
|
** Although sqlite3VdbeSerialGet() may read at most 8 bytes from the
|
|
** buffer passed to it, debugging function VdbeMemPrettyPrint() may
|
|
** read more. Use the global constant sqlite3CtypeMap[] as the array,
|
|
** as that array is 256 bytes long (plenty for VdbeMemPrettyPrint())
|
|
** and it begins with a bunch of zeros.
|
|
*/
|
|
_sqlite3VdbeSerialGet(tls, uintptr(unsafe.Pointer(&_sqlite3CtypeMap)), **(**Tu32)(__ccgo_up(bp + 64)), pDest)
|
|
} else {
|
|
rc = _vdbeColumnFromOverflow(tls, pC3, libc.Int32FromUint32(p22), **(**Tu32)(__ccgo_up(bp + 64)), libc.Int64FromUint32(**(**Tu32)(__ccgo_up(aOffset + uintptr(p22)*4))), (*TVdbe)(unsafe.Pointer(p)).FcacheCtr, colCacheCtr, pDest)
|
|
if rc != 0 {
|
|
if rc == int32(SQLITE_NOMEM) {
|
|
goto no_mem
|
|
}
|
|
if rc == int32(SQLITE_TOOBIG) {
|
|
goto too_big
|
|
}
|
|
goto abort_due_to_error
|
|
}
|
|
}
|
|
}
|
|
goto op_column_out
|
|
op_column_out:
|
|
;
|
|
goto _189
|
|
goto op_column_corrupt
|
|
op_column_corrupt:
|
|
;
|
|
if (**(**TOp)(__ccgo_up(aOp))).Fp3 > 0 {
|
|
pOp = aOp + uintptr((**(**TOp)(__ccgo_up(aOp))).Fp3-int32(1))*20
|
|
goto _189
|
|
} else {
|
|
rc = _sqlite3CorruptError(tls, int32(99872))
|
|
goto abort_due_to_error
|
|
}
|
|
/* Opcode: TypeCheck P1 P2 P3 P4 *
|
|
** Synopsis: typecheck(r[P1@P2])
|
|
**
|
|
** Apply affinities to the range of P2 registers beginning with P1.
|
|
** Take the affinities from the Table object in P4. If any value
|
|
** cannot be coerced into the correct type, then raise an error.
|
|
**
|
|
** If P3==0, then omit checking of VIRTUAL columns.
|
|
**
|
|
** If P3==1, then omit checking of all generated column, both VIRTUAL
|
|
** and STORED.
|
|
**
|
|
** If P3>=2, then only check column number P3-2 in the table (which will
|
|
** be a VIRTUAL column) against the value in reg[P1]. In this case,
|
|
** P2 will be 1.
|
|
**
|
|
** This opcode is similar to OP_Affinity except that this opcode
|
|
** forces the register type to the Table column type. This is used
|
|
** to implement "strict affinity".
|
|
**
|
|
** GENERATED ALWAYS AS ... STATIC columns are only checked if P3
|
|
** is zero. When P3 is non-zero, no type checking occurs for
|
|
** static generated columns. Virtual columns are computed at query time
|
|
** and so they are never checked.
|
|
**
|
|
** Preconditions:
|
|
**
|
|
** <ul>
|
|
** <li> P2 should be the number of non-virtual columns in the
|
|
** table of P4 unless P3>1, in which case P2 will be 1.
|
|
** <li> Table P4 is a STRICT table.
|
|
** </ul>
|
|
**
|
|
** If any precondition is false, an assertion fault occurs.
|
|
*/
|
|
_66:
|
|
;
|
|
pTab = *(*uintptr)(unsafe.Pointer(pOp + 16))
|
|
aCol = (*TTable)(unsafe.Pointer(pTab)).FaCol
|
|
pIn1 = aMem + uintptr((*TOp)(unsafe.Pointer(pOp)).Fp1)*40
|
|
if (*TOp)(unsafe.Pointer(pOp)).Fp3 < int32(2) {
|
|
i2 = 0
|
|
nCol = int32((*TTable)(unsafe.Pointer(pTab)).FnCol)
|
|
} else {
|
|
i2 = (*TOp)(unsafe.Pointer(pOp)).Fp3 - int32(2)
|
|
nCol = i2 + int32(1)
|
|
}
|
|
for {
|
|
if !(i2 < nCol) {
|
|
break
|
|
}
|
|
if libc.Int32FromUint16((**(**TColumn)(__ccgo_up(aCol + uintptr(i2)*12))).FcolFlags)&int32(COLFLAG_GENERATED) != 0 && (*TOp)(unsafe.Pointer(pOp)).Fp3 < int32(2) {
|
|
if libc.Int32FromUint16((**(**TColumn)(__ccgo_up(aCol + uintptr(i2)*12))).FcolFlags)&int32(COLFLAG_VIRTUAL) != 0 {
|
|
goto _228
|
|
}
|
|
if (*TOp)(unsafe.Pointer(pOp)).Fp3 != 0 {
|
|
pIn1 += 40
|
|
goto _228
|
|
}
|
|
}
|
|
_applyAffinity(tls, pIn1, (**(**TColumn)(__ccgo_up(aCol + uintptr(i2)*12))).Faffinity, encoding)
|
|
if libc.Int32FromUint16((*TMem)(unsafe.Pointer(pIn1)).Fflags)&int32(MEM_Null) == 0 {
|
|
switch int32(uint32(*(*uint8)(unsafe.Pointer(aCol + uintptr(i2)*12 + 4)) & 0xf0 >> 4)) {
|
|
case int32(COLTYPE_BLOB):
|
|
if libc.Int32FromUint16((*TMem)(unsafe.Pointer(pIn1)).Fflags)&int32(MEM_Blob) == 0 {
|
|
goto vdbe_type_error
|
|
}
|
|
case int32(COLTYPE_INTEGER):
|
|
fallthrough
|
|
case int32(COLTYPE_INT):
|
|
if libc.Int32FromUint16((*TMem)(unsafe.Pointer(pIn1)).Fflags)&int32(MEM_Int) == 0 {
|
|
goto vdbe_type_error
|
|
}
|
|
case int32(COLTYPE_TEXT):
|
|
if libc.Int32FromUint16((*TMem)(unsafe.Pointer(pIn1)).Fflags)&int32(MEM_Str) == 0 {
|
|
goto vdbe_type_error
|
|
}
|
|
case int32(COLTYPE_REAL):
|
|
if libc.Int32FromUint16((*TMem)(unsafe.Pointer(pIn1)).Fflags)&int32(MEM_Int) != 0 {
|
|
/* When applying REAL affinity, if the result is still an MEM_Int
|
|
** that will fit in 6 bytes, then change the type to MEM_IntReal
|
|
** so that we keep the high-resolution integer value but know that
|
|
** the type really wants to be REAL. */
|
|
if *(*Ti64)(unsafe.Pointer(pIn1)) <= int64(140737488355327) && *(*Ti64)(unsafe.Pointer(pIn1)) >= -int64(140737488355328) {
|
|
v191 = pIn1 + 16
|
|
*(*Tu16)(unsafe.Pointer(v191)) = Tu16(int32(*(*Tu16)(unsafe.Pointer(v191))) | libc.Int32FromInt32(MEM_IntReal))
|
|
v191 = pIn1 + 16
|
|
*(*Tu16)(unsafe.Pointer(v191)) = Tu16(int32(*(*Tu16)(unsafe.Pointer(v191))) & ^libc.Int32FromInt32(MEM_Int))
|
|
} else {
|
|
*(*float64)(unsafe.Pointer(pIn1)) = float64(*(*Ti64)(unsafe.Pointer(pIn1)))
|
|
v191 = pIn1 + 16
|
|
*(*Tu16)(unsafe.Pointer(v191)) = Tu16(int32(*(*Tu16)(unsafe.Pointer(v191))) | libc.Int32FromInt32(MEM_Real))
|
|
v191 = pIn1 + 16
|
|
*(*Tu16)(unsafe.Pointer(v191)) = Tu16(int32(*(*Tu16)(unsafe.Pointer(v191))) & ^libc.Int32FromInt32(MEM_Int))
|
|
}
|
|
} else {
|
|
if libc.Int32FromUint16((*TMem)(unsafe.Pointer(pIn1)).Fflags)&(libc.Int32FromInt32(MEM_Real)|libc.Int32FromInt32(MEM_IntReal)) == 0 {
|
|
goto vdbe_type_error
|
|
}
|
|
}
|
|
default:
|
|
/* COLTYPE_ANY. Accept anything. */
|
|
break
|
|
}
|
|
}
|
|
pIn1 += 40
|
|
goto _228
|
|
_228:
|
|
;
|
|
i2 = i2 + 1
|
|
}
|
|
goto _189
|
|
goto vdbe_type_error
|
|
vdbe_type_error:
|
|
;
|
|
_sqlite3VdbeError(tls, p, __ccgo_ts+5886, libc.VaList(bp+696, _vdbeMemTypeName(tls, pIn1), _sqlite3StdType[int32(uint32(*(*uint8)(unsafe.Pointer(aCol + uintptr(i2)*12 + 4))&0xf0>>4))-int32(1)], (*TTable)(unsafe.Pointer(pTab)).FzName, (**(**TColumn)(__ccgo_up(aCol + uintptr(i2)*12))).FzCnName))
|
|
rc = libc.Int32FromInt32(SQLITE_CONSTRAINT) | libc.Int32FromInt32(12)<<libc.Int32FromInt32(8)
|
|
goto abort_due_to_error
|
|
/* Opcode: Affinity P1 P2 * P4 *
|
|
** Synopsis: affinity(r[P1@P2])
|
|
**
|
|
** Apply affinities to a range of P2 registers starting with P1.
|
|
**
|
|
** P4 is a string that is P2 characters long. The N-th character of the
|
|
** string indicates the column affinity that should be used for the N-th
|
|
** memory cell in the range.
|
|
*/
|
|
_67:
|
|
; /* The affinity to be applied */
|
|
zAffinity = *(*uintptr)(unsafe.Pointer(pOp + 16))
|
|
pIn1 = aMem + uintptr((*TOp)(unsafe.Pointer(pOp)).Fp1)*40
|
|
for int32(1) != 0 {
|
|
_applyAffinity(tls, pIn1, **(**int8)(__ccgo_up(zAffinity)), encoding)
|
|
if int32(**(**int8)(__ccgo_up(zAffinity))) == int32(SQLITE_AFF_REAL) && libc.Int32FromUint16((*TMem)(unsafe.Pointer(pIn1)).Fflags)&int32(MEM_Int) != 0 {
|
|
/* When applying REAL affinity, if the result is still an MEM_Int
|
|
** that will fit in 6 bytes, then change the type to MEM_IntReal
|
|
** so that we keep the high-resolution integer value but know that
|
|
** the type really wants to be REAL. */
|
|
if *(*Ti64)(unsafe.Pointer(pIn1)) <= int64(140737488355327) && *(*Ti64)(unsafe.Pointer(pIn1)) >= -int64(140737488355328) {
|
|
v191 = pIn1 + 16
|
|
*(*Tu16)(unsafe.Pointer(v191)) = Tu16(int32(*(*Tu16)(unsafe.Pointer(v191))) | libc.Int32FromInt32(MEM_IntReal))
|
|
v191 = pIn1 + 16
|
|
*(*Tu16)(unsafe.Pointer(v191)) = Tu16(int32(*(*Tu16)(unsafe.Pointer(v191))) & ^libc.Int32FromInt32(MEM_Int))
|
|
} else {
|
|
*(*float64)(unsafe.Pointer(pIn1)) = float64(*(*Ti64)(unsafe.Pointer(pIn1)))
|
|
v191 = pIn1 + 16
|
|
*(*Tu16)(unsafe.Pointer(v191)) = Tu16(int32(*(*Tu16)(unsafe.Pointer(v191))) | libc.Int32FromInt32(MEM_Real))
|
|
v191 = pIn1 + 16
|
|
*(*Tu16)(unsafe.Pointer(v191)) = Tu16(int32(*(*Tu16)(unsafe.Pointer(v191))) & ^(libc.Int32FromInt32(MEM_Int) | libc.Int32FromInt32(MEM_Str)))
|
|
}
|
|
}
|
|
zAffinity = zAffinity + 1
|
|
if int32(**(**int8)(__ccgo_up(zAffinity))) == 0 {
|
|
break
|
|
}
|
|
pIn1 += 40
|
|
}
|
|
goto _189
|
|
/* Opcode: MakeRecord P1 P2 P3 P4 *
|
|
** Synopsis: r[P3]=mkrec(r[P1@P2])
|
|
**
|
|
** Convert P2 registers beginning with P1 into the [record format]
|
|
** use as a data record in a database table or as a key
|
|
** in an index. The OP_Column opcode can decode the record later.
|
|
**
|
|
** P4 may be a string that is P2 characters long. The N-th character of the
|
|
** string indicates the column affinity that should be used for the N-th
|
|
** field of the index key.
|
|
**
|
|
** The mapping from character to affinity is given by the SQLITE_AFF_
|
|
** macros defined in sqliteInt.h.
|
|
**
|
|
** If P4 is NULL then all index fields have the affinity BLOB.
|
|
**
|
|
** The meaning of P5 depends on whether or not the SQLITE_ENABLE_NULL_TRIM
|
|
** compile-time option is enabled:
|
|
**
|
|
** * If SQLITE_ENABLE_NULL_TRIM is enabled, then the P5 is the index
|
|
** of the right-most table that can be null-trimmed.
|
|
**
|
|
** * If SQLITE_ENABLE_NULL_TRIM is omitted, then P5 has the value
|
|
** OPFLAG_NOCHNG_MAGIC if the OP_MakeRecord opcode is allowed to
|
|
** accept no-change records with serial_type 10. This value is
|
|
** only used inside an assert() and does not affect the end result.
|
|
*/
|
|
_68:
|
|
; /* Where to write next byte of the payload */
|
|
/* Assuming the record contains N fields, the record format looks
|
|
** like this:
|
|
**
|
|
** ------------------------------------------------------------------------
|
|
** | hdr-size | type 0 | type 1 | ... | type N-1 | data0 | ... | data N-1 |
|
|
** ------------------------------------------------------------------------
|
|
**
|
|
** Data(0) is taken from register P1. Data(1) comes from register P1+1
|
|
** and so forth.
|
|
**
|
|
** Each type field is a varint representing the serial type of the
|
|
** corresponding data element (see sqlite3VdbeSerialType()). The
|
|
** hdr-size field is also a varint which is the offset from the beginning
|
|
** of the record to data0.
|
|
*/
|
|
nData = uint64(0) /* Number of bytes of data space */
|
|
nHdr = 0 /* Number of bytes of header space */
|
|
nZero = 0 /* Number of zero bytes at the end of the record */
|
|
nField = (*TOp)(unsafe.Pointer(pOp)).Fp1
|
|
zAffinity1 = *(*uintptr)(unsafe.Pointer(pOp + 16))
|
|
pData0 = aMem + uintptr(nField)*40
|
|
nField = (*TOp)(unsafe.Pointer(pOp)).Fp2
|
|
pLast = pData0 + uintptr(nField-int32(1))*40
|
|
/* Identify the output register */
|
|
pOut = aMem + uintptr((*TOp)(unsafe.Pointer(pOp)).Fp3)*40
|
|
/* Apply the requested affinity to all inputs
|
|
*/
|
|
if zAffinity1 != 0 {
|
|
pRec = pData0
|
|
for cond := true; cond; cond = **(**int8)(__ccgo_up(zAffinity1)) != 0 {
|
|
_applyAffinity(tls, pRec, **(**int8)(__ccgo_up(zAffinity1)), encoding)
|
|
if int32(**(**int8)(__ccgo_up(zAffinity1))) == int32(SQLITE_AFF_REAL) && libc.Int32FromUint16((*TMem)(unsafe.Pointer(pRec)).Fflags)&int32(MEM_Int) != 0 {
|
|
v191 = pRec + 16
|
|
*(*Tu16)(unsafe.Pointer(v191)) = Tu16(int32(*(*Tu16)(unsafe.Pointer(v191))) | libc.Int32FromInt32(MEM_IntReal))
|
|
v191 = pRec + 16
|
|
*(*Tu16)(unsafe.Pointer(v191)) = Tu16(int32(*(*Tu16)(unsafe.Pointer(v191))) & ^libc.Int32FromInt32(MEM_Int))
|
|
}
|
|
zAffinity1 = zAffinity1 + 1
|
|
pRec += 40
|
|
}
|
|
}
|
|
/* Loop through the elements that will make up the record to figure
|
|
** out how much space is required for the new record. After this loop,
|
|
** the Mem.uTemp field of each term should hold the serial-type that will
|
|
** be used for that term in the generated record:
|
|
**
|
|
** Mem.uTemp value type
|
|
** --------------- ---------------
|
|
** 0 NULL
|
|
** 1 1-byte signed integer
|
|
** 2 2-byte signed integer
|
|
** 3 3-byte signed integer
|
|
** 4 4-byte signed integer
|
|
** 5 6-byte signed integer
|
|
** 6 8-byte signed integer
|
|
** 7 IEEE float
|
|
** 8 Integer constant 0
|
|
** 9 Integer constant 1
|
|
** 10,11 reserved for expansion
|
|
** N>=12 and even BLOB
|
|
** N>=13 and odd text
|
|
**
|
|
** The following additional values are computed:
|
|
** nHdr Number of bytes needed for the record header
|
|
** nData Number of bytes of data space needed for the record
|
|
** nZero Zero bytes at the end of the record
|
|
*/
|
|
pRec = pLast
|
|
for cond := true; cond; cond = int32(1) != 0 {
|
|
if libc.Int32FromUint16((*TMem)(unsafe.Pointer(pRec)).Fflags)&int32(MEM_Null) != 0 {
|
|
if libc.Int32FromUint16((*TMem)(unsafe.Pointer(pRec)).Fflags)&int32(MEM_Zero) != 0 {
|
|
/* Values with MEM_Null and MEM_Zero are created by xColumn virtual
|
|
** table methods that never invoke sqlite3_result_xxxxx() while
|
|
** computing an unchanging column value in an UPDATE statement.
|
|
** Give such values a special internal-use-only serial-type of 10
|
|
** so that they can be passed through to xUpdate and have
|
|
** a true sqlite3_value_nochange(). */
|
|
(*TMem)(unsafe.Pointer(pRec)).FuTemp = uint32(10)
|
|
} else {
|
|
(*TMem)(unsafe.Pointer(pRec)).FuTemp = uint32(0)
|
|
}
|
|
nHdr = nHdr + 1
|
|
} else {
|
|
if libc.Int32FromUint16((*TMem)(unsafe.Pointer(pRec)).Fflags)&(libc.Int32FromInt32(MEM_Int)|libc.Int32FromInt32(MEM_IntReal)) != 0 {
|
|
/* Figure out whether to use 1, 2, 4, 6 or 8 bytes. */
|
|
i3 = *(*Ti64)(unsafe.Pointer(pRec))
|
|
if i3 < 0 {
|
|
uu = libc.Uint64FromInt64(^i3)
|
|
} else {
|
|
uu = libc.Uint64FromInt64(i3)
|
|
}
|
|
nHdr = nHdr + 1
|
|
if uu <= uint64(127) {
|
|
if i3&int64(1) == i3 && libc.Int32FromUint8((*TVdbe)(unsafe.Pointer(p)).FminWriteFileFormat) >= int32(4) {
|
|
(*TMem)(unsafe.Pointer(pRec)).FuTemp = uint32(8) + uint32(uu)
|
|
} else {
|
|
nData = nData + 1
|
|
(*TMem)(unsafe.Pointer(pRec)).FuTemp = uint32(1)
|
|
}
|
|
} else {
|
|
if uu <= uint64(32767) {
|
|
nData = nData + uint64(2)
|
|
(*TMem)(unsafe.Pointer(pRec)).FuTemp = uint32(2)
|
|
} else {
|
|
if uu <= uint64(8388607) {
|
|
nData = nData + uint64(3)
|
|
(*TMem)(unsafe.Pointer(pRec)).FuTemp = uint32(3)
|
|
} else {
|
|
if uu <= uint64(2147483647) {
|
|
nData = nData + uint64(4)
|
|
(*TMem)(unsafe.Pointer(pRec)).FuTemp = uint32(4)
|
|
} else {
|
|
if uu <= uint64(140737488355327) {
|
|
nData = nData + uint64(6)
|
|
(*TMem)(unsafe.Pointer(pRec)).FuTemp = uint32(5)
|
|
} else {
|
|
nData = nData + uint64(8)
|
|
if libc.Int32FromUint16((*TMem)(unsafe.Pointer(pRec)).Fflags)&int32(MEM_IntReal) != 0 {
|
|
/* If the value is IntReal and is going to take up 8 bytes to store
|
|
** as an integer, then we might as well make it an 8-byte floating
|
|
** point value */
|
|
*(*float64)(unsafe.Pointer(pRec)) = float64(*(*Ti64)(unsafe.Pointer(pRec)))
|
|
v191 = pRec + 16
|
|
*(*Tu16)(unsafe.Pointer(v191)) = Tu16(int32(*(*Tu16)(unsafe.Pointer(v191))) & ^libc.Int32FromInt32(MEM_IntReal))
|
|
v191 = pRec + 16
|
|
*(*Tu16)(unsafe.Pointer(v191)) = Tu16(int32(*(*Tu16)(unsafe.Pointer(v191))) | libc.Int32FromInt32(MEM_Real))
|
|
(*TMem)(unsafe.Pointer(pRec)).FuTemp = uint32(7)
|
|
} else {
|
|
(*TMem)(unsafe.Pointer(pRec)).FuTemp = uint32(6)
|
|
}
|
|
}
|
|
}
|
|
}
|
|
}
|
|
}
|
|
} else {
|
|
if libc.Int32FromUint16((*TMem)(unsafe.Pointer(pRec)).Fflags)&int32(MEM_Real) != 0 {
|
|
nHdr = nHdr + 1
|
|
nData = nData + uint64(8)
|
|
(*TMem)(unsafe.Pointer(pRec)).FuTemp = uint32(7)
|
|
} else {
|
|
len11 = libc.Uint32FromInt32((*TMem)(unsafe.Pointer(pRec)).Fn)
|
|
serial_type = len11*uint32(2) + uint32(12) + libc.BoolUint32(libc.Int32FromUint16((*TMem)(unsafe.Pointer(pRec)).Fflags)&libc.Int32FromInt32(MEM_Str) != libc.Int32FromInt32(0))
|
|
if libc.Int32FromUint16((*TMem)(unsafe.Pointer(pRec)).Fflags)&int32(MEM_Zero) != 0 {
|
|
serial_type = serial_type + libc.Uint32FromInt32(*(*int32)(unsafe.Pointer(&(*TMem)(unsafe.Pointer(pRec)).Fu)))*uint32(2)
|
|
if nData != 0 {
|
|
if _sqlite3VdbeMemExpandBlob(tls, pRec) != 0 {
|
|
goto no_mem
|
|
}
|
|
len11 = len11 + libc.Uint32FromInt32(*(*int32)(unsafe.Pointer(&(*TMem)(unsafe.Pointer(pRec)).Fu)))
|
|
} else {
|
|
nZero = nZero + int64(*(*int32)(unsafe.Pointer(&(*TMem)(unsafe.Pointer(pRec)).Fu)))
|
|
}
|
|
}
|
|
nData = nData + uint64(len11)
|
|
nHdr = nHdr + _sqlite3VarintLen(tls, uint64(serial_type))
|
|
(*TMem)(unsafe.Pointer(pRec)).FuTemp = serial_type
|
|
}
|
|
}
|
|
}
|
|
if pRec == pData0 {
|
|
break
|
|
}
|
|
pRec -= 40
|
|
}
|
|
/* EVIDENCE-OF: R-22564-11647 The header begins with a single varint
|
|
** which determines the total number of bytes in the header. The varint
|
|
** value is the size of the header in bytes including the size varint
|
|
** itself. */
|
|
if nHdr <= int32(126) {
|
|
/* The common case */
|
|
nHdr = nHdr + int32(1)
|
|
} else {
|
|
/* Rare case of a really large header */
|
|
nVarint = _sqlite3VarintLen(tls, libc.Uint64FromInt32(nHdr))
|
|
nHdr = nHdr + nVarint
|
|
if nVarint < _sqlite3VarintLen(tls, libc.Uint64FromInt32(nHdr)) {
|
|
nHdr = nHdr + 1
|
|
}
|
|
}
|
|
nByte1 = libc.Int64FromUint64(libc.Uint64FromInt32(nHdr) + nData)
|
|
/* Make sure the output register has a buffer large enough to store
|
|
** the new record. The output register (pOp->p3) is not allowed to
|
|
** be one of the input registers (because the following call to
|
|
** sqlite3VdbeMemClearAndResize() could clobber the value before it is used).
|
|
*/
|
|
if nByte1+nZero <= int64((*TMem)(unsafe.Pointer(pOut)).FszMalloc) {
|
|
/* The output register is already large enough to hold the record.
|
|
** No error checks or buffer enlargement is required */
|
|
(*TMem)(unsafe.Pointer(pOut)).Fz = (*TMem)(unsafe.Pointer(pOut)).FzMalloc
|
|
} else {
|
|
/* Need to make sure that the output is not too big and then enlarge
|
|
** the output register to hold the full result */
|
|
if nByte1+nZero > int64(**(**int32)(__ccgo_up(db + 116))) {
|
|
goto too_big
|
|
}
|
|
if _sqlite3VdbeMemClearAndResize(tls, pOut, int32(nByte1)) != 0 {
|
|
goto no_mem
|
|
}
|
|
}
|
|
(*TMem)(unsafe.Pointer(pOut)).Fn = int32(nByte1)
|
|
(*TMem)(unsafe.Pointer(pOut)).Fflags = uint16(MEM_Blob)
|
|
if nZero != 0 {
|
|
*(*int32)(unsafe.Pointer(&(*TMem)(unsafe.Pointer(pOut)).Fu)) = int32(nZero)
|
|
v191 = pOut + 16
|
|
*(*Tu16)(unsafe.Pointer(v191)) = Tu16(int32(*(*Tu16)(unsafe.Pointer(v191))) | libc.Int32FromInt32(MEM_Zero))
|
|
}
|
|
zHdr1 = (*TMem)(unsafe.Pointer(pOut)).Fz
|
|
zPayload = zHdr1 + uintptr(nHdr)
|
|
/* Write the record */
|
|
if nHdr < int32(0x80) {
|
|
v191 = zHdr1
|
|
zHdr1 = zHdr1 + 1
|
|
**(**Tu8)(__ccgo_up(v191)) = libc.Uint8FromInt32(nHdr)
|
|
} else {
|
|
zHdr1 = zHdr1 + uintptr(_sqlite3PutVarint(tls, zHdr1, libc.Uint64FromInt32(nHdr)))
|
|
}
|
|
pRec = pData0
|
|
for int32(1) != 0 {
|
|
serial_type = (*TMem)(unsafe.Pointer(pRec)).FuTemp
|
|
/* EVIDENCE-OF: R-06529-47362 Following the size varint are one or more
|
|
** additional varints, one per column.
|
|
** EVIDENCE-OF: R-64536-51728 The values for each column in the record
|
|
** immediately follow the header. */
|
|
if serial_type <= uint32(7) {
|
|
v191 = zHdr1
|
|
zHdr1 = zHdr1 + 1
|
|
**(**Tu8)(__ccgo_up(v191)) = uint8(serial_type)
|
|
if serial_type == uint32(0) {
|
|
/* NULL value. No change in zPayload */
|
|
} else {
|
|
if serial_type == uint32(7) {
|
|
libc.Xmemcpy(tls, bp+72, pRec, uint32(8))
|
|
} else {
|
|
**(**Tu64)(__ccgo_up(bp + 72)) = libc.Uint64FromInt64(*(*Ti64)(unsafe.Pointer(pRec)))
|
|
}
|
|
len11 = uint32(_sqlite3SmallTypeSizes[serial_type])
|
|
switch len11 {
|
|
default:
|
|
**(**Tu8)(__ccgo_up(zPayload + 7)) = uint8(**(**Tu64)(__ccgo_up(bp + 72)) & libc.Uint64FromInt32(0xff))
|
|
**(**Tu64)(__ccgo_up(bp + 72)) = **(**Tu64)(__ccgo_up(bp + 72)) >> uint64(8)
|
|
**(**Tu8)(__ccgo_up(zPayload + 6)) = uint8(**(**Tu64)(__ccgo_up(bp + 72)) & libc.Uint64FromInt32(0xff))
|
|
**(**Tu64)(__ccgo_up(bp + 72)) = **(**Tu64)(__ccgo_up(bp + 72)) >> uint64(8)
|
|
fallthrough
|
|
case uint32(6):
|
|
**(**Tu8)(__ccgo_up(zPayload + 5)) = uint8(**(**Tu64)(__ccgo_up(bp + 72)) & libc.Uint64FromInt32(0xff))
|
|
**(**Tu64)(__ccgo_up(bp + 72)) = **(**Tu64)(__ccgo_up(bp + 72)) >> uint64(8)
|
|
**(**Tu8)(__ccgo_up(zPayload + 4)) = uint8(**(**Tu64)(__ccgo_up(bp + 72)) & libc.Uint64FromInt32(0xff))
|
|
**(**Tu64)(__ccgo_up(bp + 72)) = **(**Tu64)(__ccgo_up(bp + 72)) >> uint64(8)
|
|
fallthrough
|
|
case uint32(4):
|
|
**(**Tu8)(__ccgo_up(zPayload + 3)) = uint8(**(**Tu64)(__ccgo_up(bp + 72)) & libc.Uint64FromInt32(0xff))
|
|
**(**Tu64)(__ccgo_up(bp + 72)) = **(**Tu64)(__ccgo_up(bp + 72)) >> uint64(8)
|
|
fallthrough
|
|
case uint32(3):
|
|
**(**Tu8)(__ccgo_up(zPayload + 2)) = uint8(**(**Tu64)(__ccgo_up(bp + 72)) & libc.Uint64FromInt32(0xff))
|
|
**(**Tu64)(__ccgo_up(bp + 72)) = **(**Tu64)(__ccgo_up(bp + 72)) >> uint64(8)
|
|
fallthrough
|
|
case uint32(2):
|
|
**(**Tu8)(__ccgo_up(zPayload + 1)) = uint8(**(**Tu64)(__ccgo_up(bp + 72)) & libc.Uint64FromInt32(0xff))
|
|
**(**Tu64)(__ccgo_up(bp + 72)) = **(**Tu64)(__ccgo_up(bp + 72)) >> uint64(8)
|
|
fallthrough
|
|
case uint32(1):
|
|
**(**Tu8)(__ccgo_up(zPayload)) = uint8(**(**Tu64)(__ccgo_up(bp + 72)) & libc.Uint64FromInt32(0xff))
|
|
}
|
|
zPayload = zPayload + uintptr(len11)
|
|
}
|
|
} else {
|
|
if serial_type < uint32(0x80) {
|
|
v191 = zHdr1
|
|
zHdr1 = zHdr1 + 1
|
|
**(**Tu8)(__ccgo_up(v191)) = uint8(serial_type)
|
|
if serial_type >= uint32(14) && (*TMem)(unsafe.Pointer(pRec)).Fn > 0 {
|
|
libc.Xmemcpy(tls, zPayload, (*TMem)(unsafe.Pointer(pRec)).Fz, libc.Uint32FromInt32((*TMem)(unsafe.Pointer(pRec)).Fn))
|
|
zPayload = zPayload + uintptr((*TMem)(unsafe.Pointer(pRec)).Fn)
|
|
}
|
|
} else {
|
|
zHdr1 = zHdr1 + uintptr(_sqlite3PutVarint(tls, zHdr1, uint64(serial_type)))
|
|
if (*TMem)(unsafe.Pointer(pRec)).Fn != 0 {
|
|
libc.Xmemcpy(tls, zPayload, (*TMem)(unsafe.Pointer(pRec)).Fz, libc.Uint32FromInt32((*TMem)(unsafe.Pointer(pRec)).Fn))
|
|
zPayload = zPayload + uintptr((*TMem)(unsafe.Pointer(pRec)).Fn)
|
|
}
|
|
}
|
|
}
|
|
if pRec == pLast {
|
|
break
|
|
}
|
|
pRec += 40
|
|
}
|
|
goto _189
|
|
/* Opcode: Count P1 P2 P3 * *
|
|
** Synopsis: r[P2]=count()
|
|
**
|
|
** Store the number of entries (an integer value) in the table or index
|
|
** opened by cursor P1 in register P2.
|
|
**
|
|
** If P3==0, then an exact count is obtained, which involves visiting
|
|
** every btree page of the table. But if P3 is non-zero, an estimate
|
|
** is returned based on the current cursor position.
|
|
*/
|
|
_69:
|
|
;
|
|
pCrsr1 = *(*uintptr)(unsafe.Pointer(**(**uintptr)(__ccgo_up((*TVdbe)(unsafe.Pointer(p)).FapCsr + uintptr((*TOp)(unsafe.Pointer(pOp)).Fp1)*4)) + 36))
|
|
if (*TOp)(unsafe.Pointer(pOp)).Fp3 != 0 {
|
|
**(**Ti64)(__ccgo_up(bp + 80)) = _sqlite3BtreeRowCountEst(tls, pCrsr1)
|
|
} else {
|
|
**(**Ti64)(__ccgo_up(bp + 80)) = 0 /* Not needed. Only used to silence a warning. */
|
|
rc = _sqlite3BtreeCount(tls, db, pCrsr1, bp+80)
|
|
if rc != 0 {
|
|
goto abort_due_to_error
|
|
}
|
|
}
|
|
pOut = _out2Prerelease(tls, p, pOp)
|
|
*(*Ti64)(unsafe.Pointer(pOut)) = **(**Ti64)(__ccgo_up(bp + 80))
|
|
goto check_for_interrupt
|
|
/* Opcode: Savepoint P1 * * P4 *
|
|
**
|
|
** Open, release or rollback the savepoint named by parameter P4, depending
|
|
** on the value of P1. To open a new savepoint set P1==0 (SAVEPOINT_BEGIN).
|
|
** To release (commit) an existing savepoint set P1==1 (SAVEPOINT_RELEASE).
|
|
** To rollback an existing savepoint set P1==2 (SAVEPOINT_ROLLBACK).
|
|
*/
|
|
_70:
|
|
;
|
|
p12 = (*TOp)(unsafe.Pointer(pOp)).Fp1
|
|
zName = *(*uintptr)(unsafe.Pointer(pOp + 16))
|
|
/* Assert that the p1 parameter is valid. Also that if there is no open
|
|
** transaction, then there cannot be any savepoints.
|
|
*/
|
|
if p12 == SAVEPOINT_BEGIN {
|
|
if (*Tsqlite3)(unsafe.Pointer(db)).FnVdbeWrite > 0 {
|
|
/* A new savepoint cannot be created if there are active write
|
|
** statements (i.e. open read/write incremental blob handles).
|
|
*/
|
|
_sqlite3VdbeError(tls, p, __ccgo_ts+5927, 0)
|
|
rc = int32(SQLITE_BUSY)
|
|
} else {
|
|
nName = _sqlite3Strlen30(tls, zName)
|
|
/* This call is Ok even if this savepoint is actually a transaction
|
|
** savepoint (and therefore should not prompt xSavepoint()) callbacks.
|
|
** If this is a transaction savepoint being opened, it is guaranteed
|
|
** that the db->aVTrans[] array is empty. */
|
|
rc = _sqlite3VtabSavepoint(tls, db, SAVEPOINT_BEGIN, (*Tsqlite3)(unsafe.Pointer(db)).FnStatement+(*Tsqlite3)(unsafe.Pointer(db)).FnSavepoint)
|
|
if rc != SQLITE_OK {
|
|
goto abort_due_to_error
|
|
}
|
|
/* Create a new savepoint structure. */
|
|
pNew = _sqlite3DbMallocRawNN(tls, db, uint64(uint32(24)+libc.Uint32FromInt32(nName)+uint32(1)))
|
|
if pNew != 0 {
|
|
(*TSavepoint)(unsafe.Pointer(pNew)).FzName = pNew + 1*24
|
|
libc.Xmemcpy(tls, (*TSavepoint)(unsafe.Pointer(pNew)).FzName, zName, libc.Uint32FromInt32(nName+int32(1)))
|
|
/* If there is no open transaction, then mark this as a special
|
|
** "transaction savepoint". */
|
|
if (*Tsqlite3)(unsafe.Pointer(db)).FautoCommit != 0 {
|
|
(*Tsqlite3)(unsafe.Pointer(db)).FautoCommit = uint8(0)
|
|
(*Tsqlite3)(unsafe.Pointer(db)).FisTransactionSavepoint = uint8(1)
|
|
} else {
|
|
(*Tsqlite3)(unsafe.Pointer(db)).FnSavepoint = (*Tsqlite3)(unsafe.Pointer(db)).FnSavepoint + 1
|
|
}
|
|
/* Link the new savepoint into the database handle's list. */
|
|
(*TSavepoint)(unsafe.Pointer(pNew)).FpNext = (*Tsqlite3)(unsafe.Pointer(db)).FpSavepoint
|
|
(*Tsqlite3)(unsafe.Pointer(db)).FpSavepoint = pNew
|
|
(*TSavepoint)(unsafe.Pointer(pNew)).FnDeferredCons = (*Tsqlite3)(unsafe.Pointer(db)).FnDeferredCons
|
|
(*TSavepoint)(unsafe.Pointer(pNew)).FnDeferredImmCons = (*Tsqlite3)(unsafe.Pointer(db)).FnDeferredImmCons
|
|
}
|
|
}
|
|
} else {
|
|
iSavepoint = 0
|
|
/* Find the named savepoint. If there is no such savepoint, then an
|
|
** an error is returned to the user. */
|
|
pSavepoint = (*Tsqlite3)(unsafe.Pointer(db)).FpSavepoint
|
|
for {
|
|
if !(pSavepoint != 0 && _sqlite3StrICmp(tls, (*TSavepoint)(unsafe.Pointer(pSavepoint)).FzName, zName) != 0) {
|
|
break
|
|
}
|
|
iSavepoint = iSavepoint + 1
|
|
goto _245
|
|
_245:
|
|
;
|
|
pSavepoint = (*TSavepoint)(unsafe.Pointer(pSavepoint)).FpNext
|
|
}
|
|
if !(pSavepoint != 0) {
|
|
_sqlite3VdbeError(tls, p, __ccgo_ts+5978, libc.VaList(bp+696, zName))
|
|
rc = int32(SQLITE_ERROR)
|
|
} else {
|
|
if (*Tsqlite3)(unsafe.Pointer(db)).FnVdbeWrite > 0 && p12 == int32(SAVEPOINT_RELEASE) {
|
|
/* It is not possible to release (commit) a savepoint if there are
|
|
** active write statements.
|
|
*/
|
|
_sqlite3VdbeError(tls, p, __ccgo_ts+6000, 0)
|
|
rc = int32(SQLITE_BUSY)
|
|
} else {
|
|
/* Determine whether or not this is a transaction savepoint. If so,
|
|
** and this is a RELEASE command, then the current transaction
|
|
** is committed.
|
|
*/
|
|
isTransaction = libc.BoolInt32((*TSavepoint)(unsafe.Pointer(pSavepoint)).FpNext == uintptr(0) && (*Tsqlite3)(unsafe.Pointer(db)).FisTransactionSavepoint != 0)
|
|
if isTransaction != 0 && p12 == int32(SAVEPOINT_RELEASE) {
|
|
v190 = _sqlite3VdbeCheckFkDeferred(tls, p)
|
|
rc = v190
|
|
if v190 != SQLITE_OK {
|
|
goto vdbe_return
|
|
}
|
|
(*Tsqlite3)(unsafe.Pointer(db)).FautoCommit = uint8(1)
|
|
if _sqlite3VdbeHalt(tls, p) == int32(SQLITE_BUSY) {
|
|
(*TVdbe)(unsafe.Pointer(p)).Fpc = (int32(pOp) - int32(aOp)) / 20
|
|
(*Tsqlite3)(unsafe.Pointer(db)).FautoCommit = uint8(0)
|
|
v190 = libc.Int32FromInt32(SQLITE_BUSY)
|
|
rc = v190
|
|
(*TVdbe)(unsafe.Pointer(p)).Frc = v190
|
|
goto vdbe_return
|
|
}
|
|
rc = (*TVdbe)(unsafe.Pointer(p)).Frc
|
|
if rc != 0 {
|
|
(*Tsqlite3)(unsafe.Pointer(db)).FautoCommit = uint8(0)
|
|
} else {
|
|
(*Tsqlite3)(unsafe.Pointer(db)).FisTransactionSavepoint = uint8(0)
|
|
}
|
|
} else {
|
|
iSavepoint = (*Tsqlite3)(unsafe.Pointer(db)).FnSavepoint - iSavepoint - int32(1)
|
|
if p12 == int32(SAVEPOINT_ROLLBACK) {
|
|
isSchemaChange = libc.BoolInt32((*Tsqlite3)(unsafe.Pointer(db)).FmDbFlags&uint32(DBFLAG_SchemaChange) != uint32(0))
|
|
ii = 0
|
|
for {
|
|
if !(ii < (*Tsqlite3)(unsafe.Pointer(db)).FnDb) {
|
|
break
|
|
}
|
|
rc = _sqlite3BtreeTripAllCursors(tls, (**(**TDb)(__ccgo_up((*Tsqlite3)(unsafe.Pointer(db)).FaDb + uintptr(ii)*16))).FpBt, libc.Int32FromInt32(SQLITE_ABORT)|libc.Int32FromInt32(2)<<libc.Int32FromInt32(8), libc.BoolInt32(isSchemaChange == 0))
|
|
if rc != SQLITE_OK {
|
|
goto abort_due_to_error
|
|
}
|
|
goto _248
|
|
_248:
|
|
;
|
|
ii = ii + 1
|
|
}
|
|
} else {
|
|
isSchemaChange = 0
|
|
}
|
|
ii = 0
|
|
for {
|
|
if !(ii < (*Tsqlite3)(unsafe.Pointer(db)).FnDb) {
|
|
break
|
|
}
|
|
rc = _sqlite3BtreeSavepoint(tls, (**(**TDb)(__ccgo_up((*Tsqlite3)(unsafe.Pointer(db)).FaDb + uintptr(ii)*16))).FpBt, p12, iSavepoint)
|
|
if rc != SQLITE_OK {
|
|
goto abort_due_to_error
|
|
}
|
|
goto _249
|
|
_249:
|
|
;
|
|
ii = ii + 1
|
|
}
|
|
if isSchemaChange != 0 {
|
|
_sqlite3ExpirePreparedStatements(tls, db, 0)
|
|
_sqlite3ResetAllSchemasOfConnection(tls, db)
|
|
**(**Tu32)(__ccgo_up(db + 24)) |= uint32(DBFLAG_SchemaChange)
|
|
}
|
|
}
|
|
if rc != 0 {
|
|
goto abort_due_to_error
|
|
}
|
|
/* Regardless of whether this is a RELEASE or ROLLBACK, destroy all
|
|
** savepoints nested inside of the savepoint being operated on. */
|
|
for (*Tsqlite3)(unsafe.Pointer(db)).FpSavepoint != pSavepoint {
|
|
pTmp = (*Tsqlite3)(unsafe.Pointer(db)).FpSavepoint
|
|
(*Tsqlite3)(unsafe.Pointer(db)).FpSavepoint = (*TSavepoint)(unsafe.Pointer(pTmp)).FpNext
|
|
_sqlite3DbFree(tls, db, pTmp)
|
|
(*Tsqlite3)(unsafe.Pointer(db)).FnSavepoint = (*Tsqlite3)(unsafe.Pointer(db)).FnSavepoint - 1
|
|
}
|
|
/* If it is a RELEASE, then destroy the savepoint being operated on
|
|
** too. If it is a ROLLBACK TO, then set the number of deferred
|
|
** constraint violations present in the database to the value stored
|
|
** when the savepoint was created. */
|
|
if p12 == int32(SAVEPOINT_RELEASE) {
|
|
(*Tsqlite3)(unsafe.Pointer(db)).FpSavepoint = (*TSavepoint)(unsafe.Pointer(pSavepoint)).FpNext
|
|
_sqlite3DbFree(tls, db, pSavepoint)
|
|
if !(isTransaction != 0) {
|
|
(*Tsqlite3)(unsafe.Pointer(db)).FnSavepoint = (*Tsqlite3)(unsafe.Pointer(db)).FnSavepoint - 1
|
|
}
|
|
} else {
|
|
(*Tsqlite3)(unsafe.Pointer(db)).FnDeferredCons = (*TSavepoint)(unsafe.Pointer(pSavepoint)).FnDeferredCons
|
|
(*Tsqlite3)(unsafe.Pointer(db)).FnDeferredImmCons = (*TSavepoint)(unsafe.Pointer(pSavepoint)).FnDeferredImmCons
|
|
}
|
|
if !(isTransaction != 0) || p12 == int32(SAVEPOINT_ROLLBACK) {
|
|
rc = _sqlite3VtabSavepoint(tls, db, p12, iSavepoint)
|
|
if rc != SQLITE_OK {
|
|
goto abort_due_to_error
|
|
}
|
|
}
|
|
}
|
|
}
|
|
}
|
|
if rc != 0 {
|
|
goto abort_due_to_error
|
|
}
|
|
if libc.Int32FromUint8((*TVdbe)(unsafe.Pointer(p)).FeVdbeState) == int32(VDBE_HALT_STATE) {
|
|
rc = int32(SQLITE_DONE)
|
|
goto vdbe_return
|
|
}
|
|
goto _189
|
|
/* Opcode: AutoCommit P1 P2 * * *
|
|
**
|
|
** Set the database auto-commit flag to P1 (1 or 0). If P2 is true, roll
|
|
** back any currently active btree transactions. If there are any active
|
|
** VMs (apart from this one), then a ROLLBACK fails. A COMMIT fails if
|
|
** there are active writing VMs or active VMs that use shared cache.
|
|
**
|
|
** This instruction causes the VM to halt.
|
|
*/
|
|
_71:
|
|
;
|
|
desiredAutoCommit = (*TOp)(unsafe.Pointer(pOp)).Fp1
|
|
iRollback = (*TOp)(unsafe.Pointer(pOp)).Fp2
|
|
/* At least this one VM is active */
|
|
if desiredAutoCommit != libc.Int32FromUint8((*Tsqlite3)(unsafe.Pointer(db)).FautoCommit) {
|
|
if iRollback != 0 {
|
|
_sqlite3RollbackAll(tls, db, libc.Int32FromInt32(SQLITE_ABORT)|libc.Int32FromInt32(2)<<libc.Int32FromInt32(8))
|
|
(*Tsqlite3)(unsafe.Pointer(db)).FautoCommit = uint8(1)
|
|
} else {
|
|
if desiredAutoCommit != 0 && (*Tsqlite3)(unsafe.Pointer(db)).FnVdbeWrite > 0 {
|
|
/* If this instruction implements a COMMIT and other VMs are writing
|
|
** return an error indicating that the other VMs must complete first.
|
|
*/
|
|
_sqlite3VdbeError(tls, p, __ccgo_ts+6054, 0)
|
|
rc = int32(SQLITE_BUSY)
|
|
goto abort_due_to_error
|
|
} else {
|
|
v190 = _sqlite3VdbeCheckFkDeferred(tls, p)
|
|
rc = v190
|
|
if v190 != SQLITE_OK {
|
|
goto vdbe_return
|
|
} else {
|
|
(*Tsqlite3)(unsafe.Pointer(db)).FautoCommit = libc.Uint8FromInt32(desiredAutoCommit)
|
|
}
|
|
}
|
|
}
|
|
if _sqlite3VdbeHalt(tls, p) == int32(SQLITE_BUSY) {
|
|
(*TVdbe)(unsafe.Pointer(p)).Fpc = (int32(pOp) - int32(aOp)) / 20
|
|
(*Tsqlite3)(unsafe.Pointer(db)).FautoCommit = libc.Uint8FromInt32(libc.Int32FromInt32(1) - desiredAutoCommit)
|
|
v190 = libc.Int32FromInt32(SQLITE_BUSY)
|
|
rc = v190
|
|
(*TVdbe)(unsafe.Pointer(p)).Frc = v190
|
|
goto vdbe_return
|
|
}
|
|
_sqlite3CloseSavepoints(tls, db)
|
|
if (*TVdbe)(unsafe.Pointer(p)).Frc == SQLITE_OK {
|
|
rc = int32(SQLITE_DONE)
|
|
} else {
|
|
rc = int32(SQLITE_ERROR)
|
|
}
|
|
goto vdbe_return
|
|
} else {
|
|
if !(desiredAutoCommit != 0) {
|
|
v191 = __ccgo_ts + 6109
|
|
} else {
|
|
if iRollback != 0 {
|
|
v194 = __ccgo_ts + 6157
|
|
} else {
|
|
v194 = __ccgo_ts + 6200
|
|
}
|
|
v191 = v194
|
|
}
|
|
_sqlite3VdbeError(tls, p, v191, 0)
|
|
rc = int32(SQLITE_ERROR)
|
|
goto abort_due_to_error
|
|
}
|
|
/* Opcode: Transaction P1 P2 P3 P4 P5
|
|
**
|
|
** Begin a transaction on database P1 if a transaction is not already
|
|
** active.
|
|
** If P2 is non-zero, then a write-transaction is started, or if a
|
|
** read-transaction is already active, it is upgraded to a write-transaction.
|
|
** If P2 is zero, then a read-transaction is started. If P2 is 2 or more
|
|
** then an exclusive transaction is started.
|
|
**
|
|
** P1 is the index of the database file on which the transaction is
|
|
** started. Index 0 is the main database file and index 1 is the
|
|
** file used for temporary tables. Indices of 2 or more are used for
|
|
** attached databases.
|
|
**
|
|
** If a write-transaction is started and the Vdbe.usesStmtJournal flag is
|
|
** true (this flag is set if the Vdbe may modify more than one row and may
|
|
** throw an ABORT exception), a statement transaction may also be opened.
|
|
** More specifically, a statement transaction is opened iff the database
|
|
** connection is currently not in autocommit mode, or if there are other
|
|
** active statements. A statement transaction allows the changes made by this
|
|
** VDBE to be rolled back after an error without having to roll back the
|
|
** entire transaction. If no error is encountered, the statement transaction
|
|
** will automatically commit when the VDBE halts.
|
|
**
|
|
** If P5!=0 then this opcode also checks the schema cookie against P3
|
|
** and the schema generation counter against P4.
|
|
** The cookie changes its value whenever the database schema changes.
|
|
** This operation is used to detect when that the cookie has changed
|
|
** and that the current process needs to reread the schema. If the schema
|
|
** cookie in P3 differs from the schema cookie in the database header or
|
|
** if the schema generation counter in P4 differs from the current
|
|
** generation counter, then an SQLITE_SCHEMA error is raised and execution
|
|
** halts. The sqlite3_step() wrapper function might then reprepare the
|
|
** statement and rerun it from the beginning.
|
|
*/
|
|
_72:
|
|
;
|
|
**(**int32)(__ccgo_up(bp + 88)) = 0
|
|
if (*TOp)(unsafe.Pointer(pOp)).Fp2 != 0 && (*Tsqlite3)(unsafe.Pointer(db)).Fflags&(libc.Uint64FromInt32(SQLITE_QueryOnly)|libc.Uint64FromInt32(libc.Int32FromInt32(0x00002))<<libc.Int32FromInt32(32)) != uint64(0) {
|
|
if (*Tsqlite3)(unsafe.Pointer(db)).Fflags&uint64(SQLITE_QueryOnly) != 0 {
|
|
/* Writes prohibited by the "PRAGMA query_only=TRUE" statement */
|
|
rc = int32(SQLITE_READONLY)
|
|
} else {
|
|
/* Writes prohibited due to a prior SQLITE_CORRUPT in the current
|
|
** transaction */
|
|
rc = int32(SQLITE_CORRUPT)
|
|
}
|
|
goto abort_due_to_error
|
|
}
|
|
pDb = (*Tsqlite3)(unsafe.Pointer(db)).FaDb + uintptr((*TOp)(unsafe.Pointer(pOp)).Fp1)*16
|
|
pBt = (*TDb)(unsafe.Pointer(pDb)).FpBt
|
|
if pBt != 0 {
|
|
rc = _sqlite3BtreeBeginTrans(tls, pBt, (*TOp)(unsafe.Pointer(pOp)).Fp2, bp+88)
|
|
if rc != SQLITE_OK {
|
|
if rc&int32(0xff) == int32(SQLITE_BUSY) {
|
|
(*TVdbe)(unsafe.Pointer(p)).Fpc = (int32(pOp) - int32(aOp)) / 20
|
|
(*TVdbe)(unsafe.Pointer(p)).Frc = rc
|
|
goto vdbe_return
|
|
}
|
|
goto abort_due_to_error
|
|
}
|
|
if int32(Tbft(*(*uint16)(unsafe.Pointer(p + 144))&0x20>>5)) != 0 && (*TOp)(unsafe.Pointer(pOp)).Fp2 != 0 && (libc.Int32FromUint8((*Tsqlite3)(unsafe.Pointer(db)).FautoCommit) == 0 || (*Tsqlite3)(unsafe.Pointer(db)).FnVdbeRead > int32(1)) {
|
|
if (*TVdbe)(unsafe.Pointer(p)).FiStatement == 0 {
|
|
(*Tsqlite3)(unsafe.Pointer(db)).FnStatement = (*Tsqlite3)(unsafe.Pointer(db)).FnStatement + 1
|
|
(*TVdbe)(unsafe.Pointer(p)).FiStatement = (*Tsqlite3)(unsafe.Pointer(db)).FnSavepoint + (*Tsqlite3)(unsafe.Pointer(db)).FnStatement
|
|
}
|
|
rc = _sqlite3VtabSavepoint(tls, db, SAVEPOINT_BEGIN, (*TVdbe)(unsafe.Pointer(p)).FiStatement-int32(1))
|
|
if rc == SQLITE_OK {
|
|
rc = _sqlite3BtreeBeginStmt(tls, pBt, (*TVdbe)(unsafe.Pointer(p)).FiStatement)
|
|
}
|
|
/* Store the current value of the database handles deferred constraint
|
|
** counter. If the statement transaction needs to be rolled back,
|
|
** the value of this counter needs to be restored too. */
|
|
(*TVdbe)(unsafe.Pointer(p)).FnStmtDefCons = (*Tsqlite3)(unsafe.Pointer(db)).FnDeferredCons
|
|
(*TVdbe)(unsafe.Pointer(p)).FnStmtDefImmCons = (*Tsqlite3)(unsafe.Pointer(db)).FnDeferredImmCons
|
|
}
|
|
}
|
|
if rc == SQLITE_OK && (*TOp)(unsafe.Pointer(pOp)).Fp5 != 0 && (**(**int32)(__ccgo_up(bp + 88)) != (*TOp)(unsafe.Pointer(pOp)).Fp3 || (*TSchema)(unsafe.Pointer((*TDb)(unsafe.Pointer(pDb)).FpSchema)).FiGeneration != *(*int32)(unsafe.Pointer(pOp + 16))) {
|
|
/*
|
|
** IMPLEMENTATION-OF: R-03189-51135 As each SQL statement runs, the schema
|
|
** version is checked to ensure that the schema has not changed since the
|
|
** SQL statement was prepared.
|
|
*/
|
|
_sqlite3DbFree(tls, db, (*TVdbe)(unsafe.Pointer(p)).FzErrMsg)
|
|
(*TVdbe)(unsafe.Pointer(p)).FzErrMsg = _sqlite3DbStrDup(tls, db, __ccgo_ts+6241)
|
|
/* If the schema-cookie from the database file matches the cookie
|
|
** stored with the in-memory representation of the schema, do
|
|
** not reload the schema from the database file.
|
|
**
|
|
** If virtual-tables are in use, this is not just an optimization.
|
|
** Often, v-tables store their data in other SQLite tables, which
|
|
** are queried from within xNext() and other v-table methods using
|
|
** prepared queries. If such a query is out-of-date, we do not want to
|
|
** discard the database schema, as the user code implementing the
|
|
** v-table would have to be ready for the sqlite3_vtab structure itself
|
|
** to be invalidated whenever sqlite3_step() is called from within
|
|
** a v-table method.
|
|
*/
|
|
if (*TSchema)(unsafe.Pointer((**(**TDb)(__ccgo_up((*Tsqlite3)(unsafe.Pointer(db)).FaDb + uintptr((*TOp)(unsafe.Pointer(pOp)).Fp1)*16))).FpSchema)).Fschema_cookie != **(**int32)(__ccgo_up(bp + 88)) {
|
|
_sqlite3ResetOneSchema(tls, db, (*TOp)(unsafe.Pointer(pOp)).Fp1)
|
|
}
|
|
libc.SetBitFieldPtr16Uint32(p+144, libc.Uint32FromInt32(1), 0, 0x3)
|
|
rc = int32(SQLITE_SCHEMA)
|
|
/* Set changeCntOn to 0 to prevent the value returned by sqlite3_changes()
|
|
** from being modified in sqlite3VdbeHalt(). If this statement is
|
|
** reprepared, changeCntOn will be set again. */
|
|
libc.SetBitFieldPtr16Uint32(p+144, libc.Uint32FromInt32(0), 4, 0x10)
|
|
}
|
|
if rc != 0 {
|
|
goto abort_due_to_error
|
|
}
|
|
goto _189
|
|
/* Opcode: ReadCookie P1 P2 P3 * *
|
|
**
|
|
** Read cookie number P3 from database P1 and write it into register P2.
|
|
** P3==1 is the schema version. P3==2 is the database format.
|
|
** P3==3 is the recommended pager cache size, and so forth. P1==0 is
|
|
** the main database file and P1==1 is the database file used to store
|
|
** temporary tables.
|
|
**
|
|
** There must be a read-lock on the database (either a transaction
|
|
** must be started or there must be an open cursor) before
|
|
** executing this instruction.
|
|
*/
|
|
_73:
|
|
;
|
|
iDb = (*TOp)(unsafe.Pointer(pOp)).Fp1
|
|
iCookie = (*TOp)(unsafe.Pointer(pOp)).Fp3
|
|
_sqlite3BtreeGetMeta(tls, (**(**TDb)(__ccgo_up((*Tsqlite3)(unsafe.Pointer(db)).FaDb + uintptr(iDb)*16))).FpBt, iCookie, bp+92)
|
|
pOut = _out2Prerelease(tls, p, pOp)
|
|
*(*Ti64)(unsafe.Pointer(pOut)) = int64(**(**int32)(__ccgo_up(bp + 92)))
|
|
goto _189
|
|
/* Opcode: SetCookie P1 P2 P3 * P5
|
|
**
|
|
** Write the integer value P3 into cookie number P2 of database P1.
|
|
** P2==1 is the schema version. P2==2 is the database format.
|
|
** P2==3 is the recommended pager cache
|
|
** size, and so forth. P1==0 is the main database file and P1==1 is the
|
|
** database file used to store temporary tables.
|
|
**
|
|
** A transaction must be started before executing this opcode.
|
|
**
|
|
** If P2 is the SCHEMA_VERSION cookie (cookie number 1) then the internal
|
|
** schema version is set to P3-P5. The "PRAGMA schema_version=N" statement
|
|
** has P5 set to 1, so that the internal schema version will be different
|
|
** from the database schema version, resulting in a schema reset.
|
|
*/
|
|
_74:
|
|
;
|
|
pDb1 = (*Tsqlite3)(unsafe.Pointer(db)).FaDb + uintptr((*TOp)(unsafe.Pointer(pOp)).Fp1)*16
|
|
/* See note about index shifting on OP_ReadCookie */
|
|
rc = _sqlite3BtreeUpdateMeta(tls, (*TDb)(unsafe.Pointer(pDb1)).FpBt, (*TOp)(unsafe.Pointer(pOp)).Fp2, libc.Uint32FromInt32((*TOp)(unsafe.Pointer(pOp)).Fp3))
|
|
if (*TOp)(unsafe.Pointer(pOp)).Fp2 == int32(BTREE_SCHEMA_VERSION) {
|
|
/* When the schema cookie changes, record the new cookie internally */
|
|
**(**Tu32)(__ccgo_up((*TDb)(unsafe.Pointer(pDb1)).FpSchema)) = **(**Tu32)(__ccgo_up(pOp + 12)) - uint32((*TOp)(unsafe.Pointer(pOp)).Fp5)
|
|
**(**Tu32)(__ccgo_up(db + 24)) |= uint32(DBFLAG_SchemaChange)
|
|
_sqlite3FkClearTriggerCache(tls, db, (*TOp)(unsafe.Pointer(pOp)).Fp1)
|
|
} else {
|
|
if (*TOp)(unsafe.Pointer(pOp)).Fp2 == int32(BTREE_FILE_FORMAT) {
|
|
/* Record changes in the file format */
|
|
(*TSchema)(unsafe.Pointer((*TDb)(unsafe.Pointer(pDb1)).FpSchema)).Ffile_format = libc.Uint8FromInt32((*TOp)(unsafe.Pointer(pOp)).Fp3)
|
|
}
|
|
}
|
|
if (*TOp)(unsafe.Pointer(pOp)).Fp1 == int32(1) {
|
|
/* Invalidate all prepared statements whenever the TEMP database
|
|
** schema is changed. Ticket #1644 */
|
|
_sqlite3ExpirePreparedStatements(tls, db, 0)
|
|
libc.SetBitFieldPtr16Uint32(p+144, libc.Uint32FromInt32(0), 0, 0x3)
|
|
}
|
|
if rc != 0 {
|
|
goto abort_due_to_error
|
|
}
|
|
goto _189
|
|
/* Opcode: OpenRead P1 P2 P3 P4 P5
|
|
** Synopsis: root=P2 iDb=P3
|
|
**
|
|
** Open a read-only cursor for the database table whose root page is
|
|
** P2 in a database file. The database file is determined by P3.
|
|
** P3==0 means the main database, P3==1 means the database used for
|
|
** temporary tables, and P3>1 means used the corresponding attached
|
|
** database. Give the new cursor an identifier of P1. The P1
|
|
** values need not be contiguous but all P1 values should be small integers.
|
|
** It is an error for P1 to be negative.
|
|
**
|
|
** Allowed P5 bits:
|
|
** <ul>
|
|
** <li> <b>0x02 OPFLAG_SEEKEQ</b>: This cursor will only be used for
|
|
** equality lookups (implemented as a pair of opcodes OP_SeekGE/OP_IdxGT
|
|
** of OP_SeekLE/OP_IdxLT)
|
|
** </ul>
|
|
**
|
|
** The P4 value may be either an integer (P4_INT32) or a pointer to
|
|
** a KeyInfo structure (P4_KEYINFO). If it is a pointer to a KeyInfo
|
|
** object, then table being opened must be an [index b-tree] where the
|
|
** KeyInfo object defines the content and collating
|
|
** sequence of that index b-tree. Otherwise, if P4 is an integer
|
|
** value, then the table being opened must be a [table b-tree] with a
|
|
** number of columns no less than the value of P4.
|
|
**
|
|
** See also: OpenWrite, ReopenIdx
|
|
*/
|
|
/* Opcode: ReopenIdx P1 P2 P3 P4 P5
|
|
** Synopsis: root=P2 iDb=P3
|
|
**
|
|
** The ReopenIdx opcode works like OP_OpenRead except that it first
|
|
** checks to see if the cursor on P1 is already open on the same
|
|
** b-tree and if it is this opcode becomes a no-op. In other words,
|
|
** if the cursor is already open, do not reopen it.
|
|
**
|
|
** The ReopenIdx opcode may only be used with P5==0 or P5==OPFLAG_SEEKEQ
|
|
** and with P4 being a P4_KEYINFO object. Furthermore, the P3 value must
|
|
** be the same as every other ReopenIdx or OpenRead for the same cursor
|
|
** number.
|
|
**
|
|
** Allowed P5 bits:
|
|
** <ul>
|
|
** <li> <b>0x02 OPFLAG_SEEKEQ</b>: This cursor will only be used for
|
|
** equality lookups (implemented as a pair of opcodes OP_SeekGE/OP_IdxGT
|
|
** of OP_SeekLE/OP_IdxLT)
|
|
** </ul>
|
|
**
|
|
** See also: OP_OpenRead, OP_OpenWrite
|
|
*/
|
|
/* Opcode: OpenWrite P1 P2 P3 P4 P5
|
|
** Synopsis: root=P2 iDb=P3
|
|
**
|
|
** Open a read/write cursor named P1 on the table or index whose root
|
|
** page is P2 (or whose root page is held in register P2 if the
|
|
** OPFLAG_P2ISREG bit is set in P5 - see below).
|
|
**
|
|
** The P4 value may be either an integer (P4_INT32) or a pointer to
|
|
** a KeyInfo structure (P4_KEYINFO). If it is a pointer to a KeyInfo
|
|
** object, then table being opened must be an [index b-tree] where the
|
|
** KeyInfo object defines the content and collating
|
|
** sequence of that index b-tree. Otherwise, if P4 is an integer
|
|
** value, then the table being opened must be a [table b-tree] with a
|
|
** number of columns no less than the value of P4.
|
|
**
|
|
** Allowed P5 bits:
|
|
** <ul>
|
|
** <li> <b>0x02 OPFLAG_SEEKEQ</b>: This cursor will only be used for
|
|
** equality lookups (implemented as a pair of opcodes OP_SeekGE/OP_IdxGT
|
|
** of OP_SeekLE/OP_IdxLT)
|
|
** <li> <b>0x08 OPFLAG_FORDELETE</b>: This cursor is used only to seek
|
|
** and subsequently delete entries in an index btree. This is a
|
|
** hint to the storage engine that the storage engine is allowed to
|
|
** ignore. The hint is not used by the official SQLite b*tree storage
|
|
** engine, but is used by COMDB2.
|
|
** <li> <b>0x10 OPFLAG_P2ISREG</b>: Use the content of register P2
|
|
** as the root page, not the value of P2 itself.
|
|
** </ul>
|
|
**
|
|
** This instruction works like OpenRead except that it opens the cursor
|
|
** in read/write mode.
|
|
**
|
|
** See also: OP_OpenRead, OP_ReopenIdx
|
|
*/
|
|
_77:
|
|
;
|
|
pCur = **(**uintptr)(__ccgo_up((*TVdbe)(unsafe.Pointer(p)).FapCsr + uintptr((*TOp)(unsafe.Pointer(pOp)).Fp1)*4))
|
|
if pCur != 0 && (*TVdbeCursor)(unsafe.Pointer(pCur)).FpgnoRoot == libc.Uint32FromInt32((*TOp)(unsafe.Pointer(pOp)).Fp2) {
|
|
/* Guaranteed by the code generator */
|
|
_sqlite3BtreeClearCursor(tls, *(*uintptr)(unsafe.Pointer(pCur + 36)))
|
|
goto open_cursor_set_hints
|
|
}
|
|
/* If the cursor is not currently open or is open on a different
|
|
** index, then fall through into OP_OpenRead to force a reopen */
|
|
_76:
|
|
; /* ncycle */
|
|
_75:
|
|
;
|
|
if int32(Tbft(*(*uint16)(unsafe.Pointer(p + 144))&0x3>>0)) == int32(1) {
|
|
rc = libc.Int32FromInt32(SQLITE_ABORT) | libc.Int32FromInt32(2)<<libc.Int32FromInt32(8)
|
|
goto abort_due_to_error
|
|
}
|
|
nField1 = 0
|
|
pKeyInfo1 = uintptr(0)
|
|
p23 = libc.Uint32FromInt32((*TOp)(unsafe.Pointer(pOp)).Fp2)
|
|
iDb1 = (*TOp)(unsafe.Pointer(pOp)).Fp3
|
|
pDb2 = (*Tsqlite3)(unsafe.Pointer(db)).FaDb + uintptr(iDb1)*16
|
|
pX = (*TDb)(unsafe.Pointer(pDb2)).FpBt
|
|
if libc.Int32FromUint8((*TOp)(unsafe.Pointer(pOp)).Fopcode) == int32(OP_OpenWrite) {
|
|
wrFlag = int32(BTREE_WRCSR) | libc.Int32FromUint16((*TOp)(unsafe.Pointer(pOp)).Fp5)&int32(OPFLAG_FORDELETE)
|
|
if libc.Int32FromUint8((*TSchema)(unsafe.Pointer((*TDb)(unsafe.Pointer(pDb2)).FpSchema)).Ffile_format) < libc.Int32FromUint8((*TVdbe)(unsafe.Pointer(p)).FminWriteFileFormat) {
|
|
(*TVdbe)(unsafe.Pointer(p)).FminWriteFileFormat = (*TSchema)(unsafe.Pointer((*TDb)(unsafe.Pointer(pDb2)).FpSchema)).Ffile_format
|
|
}
|
|
if libc.Int32FromUint16((*TOp)(unsafe.Pointer(pOp)).Fp5)&int32(OPFLAG_P2ISREG) != 0 {
|
|
pIn2 = aMem + uintptr(p23)*40
|
|
_sqlite3VdbeMemIntegerify(tls, pIn2)
|
|
p23 = libc.Uint32FromInt32(int32(*(*Ti64)(unsafe.Pointer(pIn2))))
|
|
/* The p2 value always comes from a prior OP_CreateBtree opcode and
|
|
** that opcode will always set the p2 value to 2 or more or else fail.
|
|
** If there were a failure, the prepared statement would have halted
|
|
** before reaching this instruction. */
|
|
}
|
|
} else {
|
|
wrFlag = 0
|
|
}
|
|
if int32((*TOp)(unsafe.Pointer(pOp)).Fp4type) == -int32(9) {
|
|
pKeyInfo1 = *(*uintptr)(unsafe.Pointer(pOp + 16))
|
|
nField1 = libc.Int32FromUint16((*TKeyInfo)(unsafe.Pointer(pKeyInfo1)).FnAllField)
|
|
} else {
|
|
if int32((*TOp)(unsafe.Pointer(pOp)).Fp4type) == -int32(3) {
|
|
nField1 = *(*int32)(unsafe.Pointer(pOp + 16))
|
|
}
|
|
}
|
|
/* Table with INTEGER PRIMARY KEY and nothing else */
|
|
pCur = _allocateCursor(tls, p, (*TOp)(unsafe.Pointer(pOp)).Fp1, nField1, uint8(CURTYPE_BTREE))
|
|
if pCur == uintptr(0) {
|
|
goto no_mem
|
|
}
|
|
(*TVdbeCursor)(unsafe.Pointer(pCur)).FiDb = int8(iDb1)
|
|
(*TVdbeCursor)(unsafe.Pointer(pCur)).FnullRow = uint8(1)
|
|
libc.SetBitFieldPtr8Uint32(pCur+8, libc.Uint32FromInt32(1), 2, 0x4)
|
|
(*TVdbeCursor)(unsafe.Pointer(pCur)).FpgnoRoot = p23
|
|
rc = _sqlite3BtreeCursor(tls, pX, p23, wrFlag, pKeyInfo1, *(*uintptr)(unsafe.Pointer(pCur + 36)))
|
|
(*TVdbeCursor)(unsafe.Pointer(pCur)).FpKeyInfo = pKeyInfo1
|
|
/* Set the VdbeCursor.isTable variable. Previous versions of
|
|
** SQLite used to check if the root-page flags were sane at this point
|
|
** and report database corruption if they were not, but this check has
|
|
** since moved into the btree layer. */
|
|
(*TVdbeCursor)(unsafe.Pointer(pCur)).FisTable = libc.BoolUint8(int32((*TOp)(unsafe.Pointer(pOp)).Fp4type) != -int32(9))
|
|
goto open_cursor_set_hints
|
|
open_cursor_set_hints:
|
|
;
|
|
_sqlite3BtreeCursorHintFlags(tls, *(*uintptr)(unsafe.Pointer(pCur + 36)), libc.Uint32FromInt32(libc.Int32FromUint16((*TOp)(unsafe.Pointer(pOp)).Fp5)&(libc.Int32FromInt32(OPFLAG_BULKCSR)|libc.Int32FromInt32(OPFLAG_SEEKEQ))))
|
|
if rc != 0 {
|
|
goto abort_due_to_error
|
|
}
|
|
goto _189
|
|
/* Opcode: OpenDup P1 P2 * * *
|
|
**
|
|
** Open a new cursor P1 that points to the same ephemeral table as
|
|
** cursor P2. The P2 cursor must have been opened by a prior OP_OpenEphemeral
|
|
** opcode. Only ephemeral cursors may be duplicated.
|
|
**
|
|
** Duplicate ephemeral cursors are used for self-joins of materialized views.
|
|
*/
|
|
_78:
|
|
; /* The new cursor */
|
|
pOrig = **(**uintptr)(__ccgo_up((*TVdbe)(unsafe.Pointer(p)).FapCsr + uintptr((*TOp)(unsafe.Pointer(pOp)).Fp2)*4))
|
|
/* Only ephemeral cursors can be duplicated */
|
|
pCx = _allocateCursor(tls, p, (*TOp)(unsafe.Pointer(pOp)).Fp1, int32((*TVdbeCursor)(unsafe.Pointer(pOrig)).FnField), uint8(CURTYPE_BTREE))
|
|
if pCx == uintptr(0) {
|
|
goto no_mem
|
|
}
|
|
(*TVdbeCursor)(unsafe.Pointer(pCx)).FnullRow = uint8(1)
|
|
libc.SetBitFieldPtr8Uint32(pCx+8, libc.Uint32FromInt32(1), 0, 0x1)
|
|
(*TVdbeCursor)(unsafe.Pointer(pCx)).FpKeyInfo = (*TVdbeCursor)(unsafe.Pointer(pOrig)).FpKeyInfo
|
|
(*TVdbeCursor)(unsafe.Pointer(pCx)).FisTable = (*TVdbeCursor)(unsafe.Pointer(pOrig)).FisTable
|
|
(*TVdbeCursor)(unsafe.Pointer(pCx)).FpgnoRoot = (*TVdbeCursor)(unsafe.Pointer(pOrig)).FpgnoRoot
|
|
libc.SetBitFieldPtr8Uint32(pCx+8, libc.Uint32FromInt32(int32(TBool(*(*uint8)(unsafe.Pointer(pOrig + 8))&0x4>>2))), 2, 0x4)
|
|
*(*uintptr)(unsafe.Pointer(pCx + 12)) = *(*uintptr)(unsafe.Pointer(pOrig + 12))
|
|
libc.SetBitFieldPtr8Uint32(pCx+8, libc.Uint32FromInt32(1), 3, 0x8)
|
|
libc.SetBitFieldPtr8Uint32(pOrig+8, libc.Uint32FromInt32(1), 3, 0x8)
|
|
rc = _sqlite3BtreeCursor(tls, *(*uintptr)(unsafe.Pointer(pCx + 12)), (*TVdbeCursor)(unsafe.Pointer(pCx)).FpgnoRoot, int32(BTREE_WRCSR), (*TVdbeCursor)(unsafe.Pointer(pCx)).FpKeyInfo, *(*uintptr)(unsafe.Pointer(pCx + 36)))
|
|
/* The sqlite3BtreeCursor() routine can only fail for the first cursor
|
|
** opened for a database. Since there is already an open cursor when this
|
|
** opcode is run, the sqlite3BtreeCursor() cannot fail */
|
|
goto _189
|
|
/* Opcode: OpenEphemeral P1 P2 P3 P4 P5
|
|
** Synopsis: nColumn=P2
|
|
**
|
|
** Open a new cursor P1 to a transient table.
|
|
** The cursor is always opened read/write even if
|
|
** the main database is read-only. The ephemeral
|
|
** table is deleted automatically when the cursor is closed.
|
|
**
|
|
** If the cursor P1 is already opened on an ephemeral table, the table
|
|
** is cleared (all content is erased).
|
|
**
|
|
** P2 is the number of columns in the ephemeral table.
|
|
** The cursor points to a BTree table if P4==0 and to a BTree index
|
|
** if P4 is not 0. If P4 is not NULL, it points to a KeyInfo structure
|
|
** that defines the format of keys in the index.
|
|
**
|
|
** The P5 parameter can be a mask of the BTREE_* flags defined
|
|
** in btree.h. These flags control aspects of the operation of
|
|
** the btree. The BTREE_OMIT_JOURNAL and BTREE_SINGLE flags are
|
|
** added automatically.
|
|
**
|
|
** If P3 is positive, then reg[P3] is modified slightly so that it
|
|
** can be used as zero-length data for OP_Insert. This is an optimization
|
|
** that avoids an extra OP_Blob opcode to initialize that register.
|
|
*/
|
|
/* Opcode: OpenAutoindex P1 P2 * P4 *
|
|
** Synopsis: nColumn=P2
|
|
**
|
|
** This opcode works the same as OP_OpenEphemeral. It has a
|
|
** different name to distinguish its use. Tables created using
|
|
** by this opcode will be used for automatically created transient
|
|
** indices in joins.
|
|
*/
|
|
_80:
|
|
; /* ncycle */
|
|
_79:
|
|
;
|
|
if (*TOp)(unsafe.Pointer(pOp)).Fp3 > 0 {
|
|
/* Make register reg[P3] into a value that can be used as the data
|
|
** form sqlite3BtreeInsert() where the length of the data is zero. */
|
|
/* Only used when number of columns is zero */
|
|
(**(**TMem)(__ccgo_up(aMem + uintptr((*TOp)(unsafe.Pointer(pOp)).Fp3)*40))).Fn = 0
|
|
(**(**TMem)(__ccgo_up(aMem + uintptr((*TOp)(unsafe.Pointer(pOp)).Fp3)*40))).Fz = __ccgo_ts + 1702
|
|
}
|
|
pCx1 = **(**uintptr)(__ccgo_up((*TVdbe)(unsafe.Pointer(p)).FapCsr + uintptr((*TOp)(unsafe.Pointer(pOp)).Fp1)*4))
|
|
if pCx1 != 0 && !(int32(TBool(*(*uint8)(unsafe.Pointer(pCx1 + 8))&0x8>>3)) != 0) && (*TOp)(unsafe.Pointer(pOp)).Fp2 <= int32((*TVdbeCursor)(unsafe.Pointer(pCx1)).FnField) {
|
|
/* If the ephemeral table is already open and has no duplicates from
|
|
** OP_OpenDup, then erase all existing content so that the table is
|
|
** empty again, rather than creating a new table. */
|
|
(*TVdbeCursor)(unsafe.Pointer(pCx1)).FseqCount = 0
|
|
(*TVdbeCursor)(unsafe.Pointer(pCx1)).FcacheStatus = uint32(CACHE_STALE)
|
|
rc = _sqlite3BtreeClearTable(tls, *(*uintptr)(unsafe.Pointer(pCx1 + 12)), libc.Int32FromUint32((*TVdbeCursor)(unsafe.Pointer(pCx1)).FpgnoRoot), uintptr(0))
|
|
} else {
|
|
pCx1 = _allocateCursor(tls, p, (*TOp)(unsafe.Pointer(pOp)).Fp1, (*TOp)(unsafe.Pointer(pOp)).Fp2, uint8(CURTYPE_BTREE))
|
|
if pCx1 == uintptr(0) {
|
|
goto no_mem
|
|
}
|
|
libc.SetBitFieldPtr8Uint32(pCx1+8, libc.Uint32FromInt32(1), 0, 0x1)
|
|
rc = _sqlite3BtreeOpen(tls, (*Tsqlite3)(unsafe.Pointer(db)).FpVfs, uintptr(0), db, pCx1+12, libc.Int32FromInt32(BTREE_OMIT_JOURNAL)|libc.Int32FromInt32(BTREE_SINGLE)|libc.Int32FromUint16((*TOp)(unsafe.Pointer(pOp)).Fp5), _vfsFlags)
|
|
if rc == SQLITE_OK {
|
|
rc = _sqlite3BtreeBeginTrans(tls, *(*uintptr)(unsafe.Pointer(pCx1 + 12)), int32(1), uintptr(0))
|
|
if rc == SQLITE_OK {
|
|
/* If a transient index is required, create it by calling
|
|
** sqlite3BtreeCreateTable() with the BTREE_BLOBKEY flag before
|
|
** opening it. If a transient table is required, just use the
|
|
** automatically created table with root-page 1 (an BLOB_INTKEY table).
|
|
*/
|
|
v194 = *(*uintptr)(unsafe.Pointer(pOp + 16))
|
|
pKeyInfo2 = v194
|
|
v191 = v194
|
|
(*TVdbeCursor)(unsafe.Pointer(pCx1)).FpKeyInfo = v191
|
|
if v191 != uintptr(0) {
|
|
rc = _sqlite3BtreeCreateTable(tls, *(*uintptr)(unsafe.Pointer(pCx1 + 12)), pCx1+48, int32(BTREE_BLOBKEY)|libc.Int32FromUint16((*TOp)(unsafe.Pointer(pOp)).Fp5))
|
|
if rc == SQLITE_OK {
|
|
rc = _sqlite3BtreeCursor(tls, *(*uintptr)(unsafe.Pointer(pCx1 + 12)), (*TVdbeCursor)(unsafe.Pointer(pCx1)).FpgnoRoot, int32(BTREE_WRCSR), pKeyInfo2, *(*uintptr)(unsafe.Pointer(pCx1 + 36)))
|
|
}
|
|
(*TVdbeCursor)(unsafe.Pointer(pCx1)).FisTable = uint8(0)
|
|
} else {
|
|
(*TVdbeCursor)(unsafe.Pointer(pCx1)).FpgnoRoot = uint32(SCHEMA_ROOT)
|
|
rc = _sqlite3BtreeCursor(tls, *(*uintptr)(unsafe.Pointer(pCx1 + 12)), uint32(SCHEMA_ROOT), int32(BTREE_WRCSR), uintptr(0), *(*uintptr)(unsafe.Pointer(pCx1 + 36)))
|
|
(*TVdbeCursor)(unsafe.Pointer(pCx1)).FisTable = uint8(1)
|
|
}
|
|
}
|
|
libc.SetBitFieldPtr8Uint32(pCx1+8, libc.BoolUint32(libc.Int32FromUint16((*TOp)(unsafe.Pointer(pOp)).Fp5) != libc.Int32FromInt32(BTREE_UNORDERED)), 2, 0x4)
|
|
if rc != 0 {
|
|
_sqlite3BtreeClose(tls, *(*uintptr)(unsafe.Pointer(pCx1 + 12)))
|
|
**(**uintptr)(__ccgo_up((*TVdbe)(unsafe.Pointer(p)).FapCsr + uintptr((*TOp)(unsafe.Pointer(pOp)).Fp1)*4)) = uintptr(0) /* Not required; helps with static analysis */
|
|
} else {
|
|
}
|
|
}
|
|
}
|
|
if rc != 0 {
|
|
goto abort_due_to_error
|
|
}
|
|
(*TVdbeCursor)(unsafe.Pointer(pCx1)).FnullRow = uint8(1)
|
|
goto _189
|
|
/* Opcode: SorterOpen P1 P2 P3 P4 *
|
|
**
|
|
** This opcode works like OP_OpenEphemeral except that it opens
|
|
** a transient index that is specifically designed to sort large
|
|
** tables using an external merge-sort algorithm.
|
|
**
|
|
** If argument P3 is non-zero, then it indicates that the sorter may
|
|
** assume that a stable sort considering the first P3 fields of each
|
|
** key is sufficient to produce the required results.
|
|
*/
|
|
_81:
|
|
;
|
|
pCx2 = _allocateCursor(tls, p, (*TOp)(unsafe.Pointer(pOp)).Fp1, (*TOp)(unsafe.Pointer(pOp)).Fp2, uint8(CURTYPE_SORTER))
|
|
if pCx2 == uintptr(0) {
|
|
goto no_mem
|
|
}
|
|
(*TVdbeCursor)(unsafe.Pointer(pCx2)).FpKeyInfo = *(*uintptr)(unsafe.Pointer(pOp + 16))
|
|
rc = _sqlite3VdbeSorterInit(tls, db, (*TOp)(unsafe.Pointer(pOp)).Fp3, pCx2)
|
|
if rc != 0 {
|
|
goto abort_due_to_error
|
|
}
|
|
goto _189
|
|
/* Opcode: SequenceTest P1 P2 * * *
|
|
** Synopsis: if( cursor[P1].ctr++ ) pc = P2
|
|
**
|
|
** P1 is a sorter cursor. If the sequence counter is currently zero, jump
|
|
** to P2. Regardless of whether or not the jump is taken, increment the
|
|
** the sequence value.
|
|
*/
|
|
_82:
|
|
;
|
|
pC4 = **(**uintptr)(__ccgo_up((*TVdbe)(unsafe.Pointer(p)).FapCsr + uintptr((*TOp)(unsafe.Pointer(pOp)).Fp1)*4))
|
|
v191 = pC4 + 16
|
|
v256 = *(*Ti64)(unsafe.Pointer(v191))
|
|
*(*Ti64)(unsafe.Pointer(v191)) = *(*Ti64)(unsafe.Pointer(v191)) + 1
|
|
if v256 == 0 {
|
|
goto jump_to_p2
|
|
}
|
|
goto _189
|
|
/* Opcode: OpenPseudo P1 P2 P3 * *
|
|
** Synopsis: P3 columns in r[P2]
|
|
**
|
|
** Open a new cursor that points to a fake table that contains a single
|
|
** row of data. The content of that one row is the content of memory
|
|
** register P2. In other words, cursor P1 becomes an alias for the
|
|
** MEM_Blob content contained in register P2.
|
|
**
|
|
** A pseudo-table created by this opcode is used to hold a single
|
|
** row output from the sorter so that the row can be decomposed into
|
|
** individual columns using the OP_Column opcode. The OP_Column opcode
|
|
** is the only cursor opcode that works with a pseudo-table.
|
|
**
|
|
** P3 is the number of fields in the records that will be stored by
|
|
** the pseudo-table. If P2 is 0 or negative then the pseudo-cursor
|
|
** will return NULL for every column.
|
|
*/
|
|
_83:
|
|
;
|
|
pCx3 = _allocateCursor(tls, p, (*TOp)(unsafe.Pointer(pOp)).Fp1, (*TOp)(unsafe.Pointer(pOp)).Fp3, uint8(CURTYPE_PSEUDO))
|
|
if pCx3 == uintptr(0) {
|
|
goto no_mem
|
|
}
|
|
(*TVdbeCursor)(unsafe.Pointer(pCx3)).FnullRow = uint8(1)
|
|
(*TVdbeCursor)(unsafe.Pointer(pCx3)).FseekResult = (*TOp)(unsafe.Pointer(pOp)).Fp2
|
|
(*TVdbeCursor)(unsafe.Pointer(pCx3)).FisTable = uint8(1)
|
|
/* Give this pseudo-cursor a fake BtCursor pointer so that pCx
|
|
** can be safely passed to sqlite3VdbeCursorMoveto(). This avoids a test
|
|
** for pCx->eCurType==CURTYPE_BTREE inside of sqlite3VdbeCursorMoveto()
|
|
** which is a performance optimization */
|
|
*(*uintptr)(unsafe.Pointer(pCx3 + 36)) = _sqlite3BtreeFakeValidCursor(tls)
|
|
goto _189
|
|
/* Opcode: Close P1 * * * *
|
|
**
|
|
** Close a cursor previously opened as P1. If P1 is not
|
|
** currently open, this instruction is a no-op.
|
|
*/
|
|
_84:
|
|
; /* ncycle */
|
|
_sqlite3VdbeFreeCursor(tls, p, **(**uintptr)(__ccgo_up((*TVdbe)(unsafe.Pointer(p)).FapCsr + uintptr((*TOp)(unsafe.Pointer(pOp)).Fp1)*4)))
|
|
**(**uintptr)(__ccgo_up((*TVdbe)(unsafe.Pointer(p)).FapCsr + uintptr((*TOp)(unsafe.Pointer(pOp)).Fp1)*4)) = uintptr(0)
|
|
goto _189
|
|
/* Opcode: SeekGE P1 P2 P3 P4 *
|
|
** Synopsis: key=r[P3@P4]
|
|
**
|
|
** If cursor P1 refers to an SQL table (B-Tree that uses integer keys),
|
|
** use the value in register P3 as the key. If cursor P1 refers
|
|
** to an SQL index, then P3 is the first in an array of P4 registers
|
|
** that are used as an unpacked index key.
|
|
**
|
|
** Reposition cursor P1 so that it points to the smallest entry that
|
|
** is greater than or equal to the key value. If there are no records
|
|
** greater than or equal to the key and P2 is not zero, then jump to P2.
|
|
**
|
|
** If the cursor P1 was opened using the OPFLAG_SEEKEQ flag, then this
|
|
** opcode will either land on a record that exactly matches the key, or
|
|
** else it will cause a jump to P2. When the cursor is OPFLAG_SEEKEQ,
|
|
** this opcode must be followed by an IdxLE opcode with the same arguments.
|
|
** The IdxGT opcode will be skipped if this opcode succeeds, but the
|
|
** IdxGT opcode will be used on subsequent loop iterations. The
|
|
** OPFLAG_SEEKEQ flags is a hint to the btree layer to say that this
|
|
** is an equality search.
|
|
**
|
|
** This opcode leaves the cursor configured to move in forward order,
|
|
** from the beginning toward the end. In other words, the cursor is
|
|
** configured to use Next, not Prev.
|
|
**
|
|
** See also: Found, NotFound, SeekLt, SeekGt, SeekLe
|
|
*/
|
|
/* Opcode: SeekGT P1 P2 P3 P4 *
|
|
** Synopsis: key=r[P3@P4]
|
|
**
|
|
** If cursor P1 refers to an SQL table (B-Tree that uses integer keys),
|
|
** use the value in register P3 as a key. If cursor P1 refers
|
|
** to an SQL index, then P3 is the first in an array of P4 registers
|
|
** that are used as an unpacked index key.
|
|
**
|
|
** Reposition cursor P1 so that it points to the smallest entry that
|
|
** is greater than the key value. If there are no records greater than
|
|
** the key and P2 is not zero, then jump to P2.
|
|
**
|
|
** This opcode leaves the cursor configured to move in forward order,
|
|
** from the beginning toward the end. In other words, the cursor is
|
|
** configured to use Next, not Prev.
|
|
**
|
|
** See also: Found, NotFound, SeekLt, SeekGe, SeekLe
|
|
*/
|
|
/* Opcode: SeekLT P1 P2 P3 P4 *
|
|
** Synopsis: key=r[P3@P4]
|
|
**
|
|
** If cursor P1 refers to an SQL table (B-Tree that uses integer keys),
|
|
** use the value in register P3 as a key. If cursor P1 refers
|
|
** to an SQL index, then P3 is the first in an array of P4 registers
|
|
** that are used as an unpacked index key.
|
|
**
|
|
** Reposition cursor P1 so that it points to the largest entry that
|
|
** is less than the key value. If there are no records less than
|
|
** the key and P2 is not zero, then jump to P2.
|
|
**
|
|
** This opcode leaves the cursor configured to move in reverse order,
|
|
** from the end toward the beginning. In other words, the cursor is
|
|
** configured to use Prev, not Next.
|
|
**
|
|
** See also: Found, NotFound, SeekGt, SeekGe, SeekLe
|
|
*/
|
|
/* Opcode: SeekLE P1 P2 P3 P4 *
|
|
** Synopsis: key=r[P3@P4]
|
|
**
|
|
** If cursor P1 refers to an SQL table (B-Tree that uses integer keys),
|
|
** use the value in register P3 as a key. If cursor P1 refers
|
|
** to an SQL index, then P3 is the first in an array of P4 registers
|
|
** that are used as an unpacked index key.
|
|
**
|
|
** Reposition cursor P1 so that it points to the largest entry that
|
|
** is less than or equal to the key value. If there are no records
|
|
** less than or equal to the key and P2 is not zero, then jump to P2.
|
|
**
|
|
** This opcode leaves the cursor configured to move in reverse order,
|
|
** from the end toward the beginning. In other words, the cursor is
|
|
** configured to use Prev, not Next.
|
|
**
|
|
** If the cursor P1 was opened using the OPFLAG_SEEKEQ flag, then this
|
|
** opcode will either land on a record that exactly matches the key, or
|
|
** else it will cause a jump to P2. When the cursor is OPFLAG_SEEKEQ,
|
|
** this opcode must be followed by an IdxLE opcode with the same arguments.
|
|
** The IdxGE opcode will be skipped if this opcode succeeds, but the
|
|
** IdxGE opcode will be used on subsequent loop iterations. The
|
|
** OPFLAG_SEEKEQ flags is a hint to the btree layer to say that this
|
|
** is an equality search.
|
|
**
|
|
** See also: Found, NotFound, SeekGt, SeekGe, SeekLt
|
|
*/
|
|
_88:
|
|
; /* jump0, in3, group, ncycle */
|
|
_87:
|
|
; /* jump0, in3, group, ncycle */
|
|
_86:
|
|
; /* jump0, in3, group, ncycle */
|
|
_85:
|
|
; /* Only interested in == results */
|
|
pC5 = **(**uintptr)(__ccgo_up((*TVdbe)(unsafe.Pointer(p)).FapCsr + uintptr((*TOp)(unsafe.Pointer(pOp)).Fp1)*4))
|
|
oc = libc.Int32FromUint8((*TOp)(unsafe.Pointer(pOp)).Fopcode)
|
|
eqOnly = 0
|
|
(*TVdbeCursor)(unsafe.Pointer(pC5)).FnullRow = uint8(0)
|
|
(*TVdbeCursor)(unsafe.Pointer(pC5)).FdeferredMoveto = uint8(0)
|
|
(*TVdbeCursor)(unsafe.Pointer(pC5)).FcacheStatus = uint32(CACHE_STALE)
|
|
if (*TVdbeCursor)(unsafe.Pointer(pC5)).FisTable != 0 {
|
|
/* The OPFLAG_SEEKEQ/BTREE_SEEK_EQ flag is only set on index cursors */
|
|
/* The input value in P3 might be of any type: integer, real, string,
|
|
** blob, or NULL. But it needs to be an integer before we can do
|
|
** the seek, so convert it. */
|
|
pIn3 = aMem + uintptr((*TOp)(unsafe.Pointer(pOp)).Fp3)*40
|
|
flags31 = (*TMem)(unsafe.Pointer(pIn3)).Fflags
|
|
if libc.Int32FromUint16(flags31)&(libc.Int32FromInt32(MEM_Int)|libc.Int32FromInt32(MEM_Real)|libc.Int32FromInt32(MEM_IntReal)|libc.Int32FromInt32(MEM_Str)) == int32(MEM_Str) {
|
|
_applyNumericAffinity(tls, pIn3, 0)
|
|
}
|
|
iKey = _sqlite3VdbeIntValue(tls, pIn3) /* Get the integer key value */
|
|
newType = (*TMem)(unsafe.Pointer(pIn3)).Fflags /* Record the type after applying numeric affinity */
|
|
(*TMem)(unsafe.Pointer(pIn3)).Fflags = flags31 /* But convert the type back to its original */
|
|
/* If the P3 value could not be converted into an integer without
|
|
** loss of information, then special processing is required... */
|
|
if libc.Int32FromUint16(newType)&(libc.Int32FromInt32(MEM_Int)|libc.Int32FromInt32(MEM_IntReal)) == 0 {
|
|
if libc.Int32FromUint16(newType)&int32(MEM_Real) == 0 {
|
|
if libc.Int32FromUint16(newType)&int32(MEM_Null) != 0 || oc >= int32(OP_SeekGE) {
|
|
goto jump_to_p2
|
|
} else {
|
|
rc = _sqlite3BtreeLast(tls, *(*uintptr)(unsafe.Pointer(pC5 + 36)), bp+96)
|
|
if rc != SQLITE_OK {
|
|
goto abort_due_to_error
|
|
}
|
|
goto seek_not_found
|
|
}
|
|
}
|
|
c2 = _sqlite3IntFloatCompare(tls, iKey, *(*float64)(unsafe.Pointer(pIn3)))
|
|
/* If the approximation iKey is larger than the actual real search
|
|
** term, substitute >= for > and < for <=. e.g. if the search term
|
|
** is 4.9 and the integer approximation 5:
|
|
**
|
|
** (x > 4.9) -> (x >= 5)
|
|
** (x <= 4.9) -> (x < 5)
|
|
*/
|
|
if c2 > 0 {
|
|
if oc&int32(0x0001) == libc.Int32FromInt32(OP_SeekGT)&libc.Int32FromInt32(0x0001) {
|
|
oc = oc - 1
|
|
}
|
|
} else {
|
|
if c2 < 0 {
|
|
if oc&int32(0x0001) == libc.Int32FromInt32(OP_SeekLT)&libc.Int32FromInt32(0x0001) {
|
|
oc = oc + 1
|
|
}
|
|
}
|
|
}
|
|
}
|
|
rc = _sqlite3BtreeTableMoveto(tls, *(*uintptr)(unsafe.Pointer(pC5 + 36)), libc.Int64FromUint64(libc.Uint64FromInt64(iKey)), 0, bp+96)
|
|
(*TVdbeCursor)(unsafe.Pointer(pC5)).FmovetoTarget = iKey /* Used by OP_Delete */
|
|
if rc != SQLITE_OK {
|
|
goto abort_due_to_error
|
|
}
|
|
} else {
|
|
/* For a cursor with the OPFLAG_SEEKEQ/BTREE_SEEK_EQ hint, only the
|
|
** OP_SeekGE and OP_SeekLE opcodes are allowed, and these must be
|
|
** immediately followed by an OP_IdxGT or OP_IdxLT opcode, respectively,
|
|
** with the same key.
|
|
*/
|
|
if _sqlite3BtreeCursorHasHint(tls, *(*uintptr)(unsafe.Pointer(pC5 + 36)), uint32(BTREE_SEEK_EQ)) != 0 {
|
|
eqOnly = int32(1)
|
|
}
|
|
nField2 = *(*int32)(unsafe.Pointer(pOp + 16))
|
|
(**(**TUnpackedRecord)(__ccgo_up(bp + 100))).FpKeyInfo = (*TVdbeCursor)(unsafe.Pointer(pC5)).FpKeyInfo
|
|
(**(**TUnpackedRecord)(__ccgo_up(bp + 100))).FnField = libc.Uint16FromInt32(nField2)
|
|
/* The next line of code computes as follows, only faster:
|
|
** if( oc==OP_SeekGT || oc==OP_SeekLE ){
|
|
** r.default_rc = -1;
|
|
** }else{
|
|
** r.default_rc = +1;
|
|
** }
|
|
*/
|
|
if int32(1)&(oc-int32(OP_SeekLT)) != 0 {
|
|
v190 = -int32(1)
|
|
} else {
|
|
v190 = +libc.Int32FromInt32(1)
|
|
}
|
|
(**(**TUnpackedRecord)(__ccgo_up(bp + 100))).Fdefault_rc = int8(v190)
|
|
(**(**TUnpackedRecord)(__ccgo_up(bp + 100))).FaMem = aMem + uintptr((*TOp)(unsafe.Pointer(pOp)).Fp3)*40
|
|
(**(**TUnpackedRecord)(__ccgo_up(bp + 100))).FeqSeen = uint8(0)
|
|
rc = _sqlite3BtreeIndexMoveto(tls, *(*uintptr)(unsafe.Pointer(pC5 + 36)), bp+100, bp+96)
|
|
if rc != SQLITE_OK {
|
|
goto abort_due_to_error
|
|
}
|
|
if eqOnly != 0 && libc.Int32FromUint8((**(**TUnpackedRecord)(__ccgo_up(bp + 100))).FeqSeen) == 0 {
|
|
goto seek_not_found
|
|
}
|
|
}
|
|
if oc >= int32(OP_SeekGE) {
|
|
if **(**int32)(__ccgo_up(bp + 96)) < 0 || **(**int32)(__ccgo_up(bp + 96)) == 0 && oc == int32(OP_SeekGT) {
|
|
**(**int32)(__ccgo_up(bp + 96)) = 0
|
|
rc = _sqlite3BtreeNext(tls, *(*uintptr)(unsafe.Pointer(pC5 + 36)), 0)
|
|
if rc != SQLITE_OK {
|
|
if rc == int32(SQLITE_DONE) {
|
|
rc = SQLITE_OK
|
|
**(**int32)(__ccgo_up(bp + 96)) = int32(1)
|
|
} else {
|
|
goto abort_due_to_error
|
|
}
|
|
}
|
|
} else {
|
|
**(**int32)(__ccgo_up(bp + 96)) = 0
|
|
}
|
|
} else {
|
|
if **(**int32)(__ccgo_up(bp + 96)) > 0 || **(**int32)(__ccgo_up(bp + 96)) == 0 && oc == int32(OP_SeekLT) {
|
|
**(**int32)(__ccgo_up(bp + 96)) = 0
|
|
rc = _sqlite3BtreePrevious(tls, *(*uintptr)(unsafe.Pointer(pC5 + 36)), 0)
|
|
if rc != SQLITE_OK {
|
|
if rc == int32(SQLITE_DONE) {
|
|
rc = SQLITE_OK
|
|
**(**int32)(__ccgo_up(bp + 96)) = int32(1)
|
|
} else {
|
|
goto abort_due_to_error
|
|
}
|
|
}
|
|
} else {
|
|
/* res might be negative because the table is empty. Check to
|
|
** see if this is the case.
|
|
*/
|
|
**(**int32)(__ccgo_up(bp + 96)) = _sqlite3BtreeEof(tls, *(*uintptr)(unsafe.Pointer(pC5 + 36)))
|
|
}
|
|
}
|
|
goto seek_not_found
|
|
seek_not_found:
|
|
;
|
|
if **(**int32)(__ccgo_up(bp + 96)) != 0 {
|
|
goto jump_to_p2
|
|
} else {
|
|
if eqOnly != 0 {
|
|
pOp += 20 /* Skip the OP_IdxLt or OP_IdxGT that follows */
|
|
}
|
|
}
|
|
goto _189
|
|
/* Opcode: SeekScan P1 P2 * * P5
|
|
** Synopsis: Scan-ahead up to P1 rows
|
|
**
|
|
** This opcode is a prefix opcode to OP_SeekGE. In other words, this
|
|
** opcode must be immediately followed by OP_SeekGE. This constraint is
|
|
** checked by assert() statements.
|
|
**
|
|
** This opcode uses the P1 through P4 operands of the subsequent
|
|
** OP_SeekGE. In the text that follows, the operands of the subsequent
|
|
** OP_SeekGE opcode are denoted as SeekOP.P1 through SeekOP.P4. Only
|
|
** the P1, P2 and P5 operands of this opcode are also used, and are called
|
|
** This.P1, This.P2 and This.P5.
|
|
**
|
|
** This opcode helps to optimize IN operators on a multi-column index
|
|
** where the IN operator is on the later terms of the index by avoiding
|
|
** unnecessary seeks on the btree, substituting steps to the next row
|
|
** of the b-tree instead. A correct answer is obtained if this opcode
|
|
** is omitted or is a no-op.
|
|
**
|
|
** The SeekGE.P3 and SeekGE.P4 operands identify an unpacked key which
|
|
** is the desired entry that we want the cursor SeekGE.P1 to be pointing
|
|
** to. Call this SeekGE.P3/P4 row the "target".
|
|
**
|
|
** If the SeekGE.P1 cursor is not currently pointing to a valid row,
|
|
** then this opcode is a no-op and control passes through into the OP_SeekGE.
|
|
**
|
|
** If the SeekGE.P1 cursor is pointing to a valid row, then that row
|
|
** might be the target row, or it might be near and slightly before the
|
|
** target row, or it might be after the target row. If the cursor is
|
|
** currently before the target row, then this opcode attempts to position
|
|
** the cursor on or after the target row by invoking sqlite3BtreeStep()
|
|
** on the cursor between 1 and This.P1 times.
|
|
**
|
|
** The This.P5 parameter is a flag that indicates what to do if the
|
|
** cursor ends up pointing at a valid row that is past the target
|
|
** row. If This.P5 is false (0) then a jump is made to SeekGE.P2. If
|
|
** This.P5 is true (non-zero) then a jump is made to This.P2. The P5==0
|
|
** case occurs when there are no inequality constraints to the right of
|
|
** the IN constraint. The jump to SeekGE.P2 ends the loop. The P5!=0 case
|
|
** occurs when there are inequality constraints to the right of the IN
|
|
** operator. In that case, the This.P2 will point either directly to or
|
|
** to setup code prior to the OP_IdxGT or OP_IdxGE opcode that checks for
|
|
** loop terminate.
|
|
**
|
|
** Possible outcomes from this opcode:<ol>
|
|
**
|
|
** <li> If the cursor is initially not pointed to any valid row, then
|
|
** fall through into the subsequent OP_SeekGE opcode.
|
|
**
|
|
** <li> If the cursor is left pointing to a row that is before the target
|
|
** row, even after making as many as This.P1 calls to
|
|
** sqlite3BtreeNext(), then also fall through into OP_SeekGE.
|
|
**
|
|
** <li> If the cursor is left pointing at the target row, either because it
|
|
** was at the target row to begin with or because one or more
|
|
** sqlite3BtreeNext() calls moved the cursor to the target row,
|
|
** then jump to This.P2..,
|
|
**
|
|
** <li> If the cursor started out before the target row and a call to
|
|
** to sqlite3BtreeNext() moved the cursor off the end of the index
|
|
** (indicating that the target row definitely does not exist in the
|
|
** btree) then jump to SeekGE.P2, ending the loop.
|
|
**
|
|
** <li> If the cursor ends up on a valid row that is past the target row
|
|
** (indicating that the target row does not exist in the btree) then
|
|
** jump to SeekOP.P2 if This.P5==0 or to This.P2 if This.P5>0.
|
|
** </ol>
|
|
*/
|
|
_89:
|
|
;
|
|
/* If pOp->p5 is clear, then pOp->p2 points to the first instruction past the
|
|
** OP_IdxGT that follows the OP_SeekGE. Otherwise, it points to the first
|
|
** opcode past the OP_SeekGE itself. */
|
|
pC6 = **(**uintptr)(__ccgo_up((*TVdbe)(unsafe.Pointer(p)).FapCsr + uintptr((**(**TOp)(__ccgo_up(pOp + 1*20))).Fp1)*4))
|
|
if !(_sqlite3BtreeCursorIsValidNN(tls, *(*uintptr)(unsafe.Pointer(pC6 + 36))) != 0) {
|
|
goto _189
|
|
}
|
|
nStep = (*TOp)(unsafe.Pointer(pOp)).Fp1
|
|
(**(**TUnpackedRecord)(__ccgo_up(bp + 132))).FpKeyInfo = (*TVdbeCursor)(unsafe.Pointer(pC6)).FpKeyInfo
|
|
(**(**TUnpackedRecord)(__ccgo_up(bp + 132))).FnField = libc.Uint16FromInt32(*(*int32)(unsafe.Pointer(pOp + 1*20 + 16)))
|
|
(**(**TUnpackedRecord)(__ccgo_up(bp + 132))).Fdefault_rc = 0
|
|
(**(**TUnpackedRecord)(__ccgo_up(bp + 132))).FaMem = aMem + uintptr((**(**TOp)(__ccgo_up(pOp + 1*20))).Fp3)*40
|
|
**(**int32)(__ccgo_up(bp + 128)) = 0 /* Not needed. Only used to silence a warning. */
|
|
_260:
|
|
;
|
|
if !(int32(1) != 0) {
|
|
goto _259
|
|
}
|
|
rc = _sqlite3VdbeIdxKeyCompare(tls, db, pC6, bp+132, bp+128)
|
|
if rc != 0 {
|
|
goto abort_due_to_error
|
|
}
|
|
if !(**(**int32)(__ccgo_up(bp + 128)) > 0 && libc.Int32FromUint16((*TOp)(unsafe.Pointer(pOp)).Fp5) == 0) {
|
|
goto _261
|
|
}
|
|
goto seekscan_search_fail
|
|
seekscan_search_fail:
|
|
;
|
|
/* Jump to SeekGE.P2, ending the loop */
|
|
pOp += 20
|
|
goto jump_to_p2
|
|
_261:
|
|
;
|
|
if **(**int32)(__ccgo_up(bp + 128)) >= 0 {
|
|
/* Jump to This.P2, bypassing the OP_SeekGE opcode */
|
|
goto jump_to_p2
|
|
goto _259
|
|
}
|
|
if nStep <= 0 {
|
|
goto _259
|
|
}
|
|
nStep = nStep - 1
|
|
(*TVdbeCursor)(unsafe.Pointer(pC6)).FcacheStatus = uint32(CACHE_STALE)
|
|
rc = _sqlite3BtreeNext(tls, *(*uintptr)(unsafe.Pointer(pC6 + 36)), 0)
|
|
if rc != 0 {
|
|
if rc == int32(SQLITE_DONE) {
|
|
rc = SQLITE_OK
|
|
goto seekscan_search_fail
|
|
} else {
|
|
goto abort_due_to_error
|
|
}
|
|
}
|
|
goto _260
|
|
_259:
|
|
;
|
|
goto _189
|
|
/* Opcode: SeekHit P1 P2 P3 * *
|
|
** Synopsis: set P2<=seekHit<=P3
|
|
**
|
|
** Increase or decrease the seekHit value for cursor P1, if necessary,
|
|
** so that it is no less than P2 and no greater than P3.
|
|
**
|
|
** The seekHit integer represents the maximum of terms in an index for which
|
|
** there is known to be at least one match. If the seekHit value is smaller
|
|
** than the total number of equality terms in an index lookup, then the
|
|
** OP_IfNoHope opcode might run to see if the IN loop can be abandoned
|
|
** early, thus saving work. This is part of the IN-early-out optimization.
|
|
**
|
|
** P1 must be a valid b-tree cursor.
|
|
*/
|
|
_90:
|
|
;
|
|
pC7 = **(**uintptr)(__ccgo_up((*TVdbe)(unsafe.Pointer(p)).FapCsr + uintptr((*TOp)(unsafe.Pointer(pOp)).Fp1)*4))
|
|
if libc.Int32FromUint16((*TVdbeCursor)(unsafe.Pointer(pC7)).FseekHit) < (*TOp)(unsafe.Pointer(pOp)).Fp2 {
|
|
(*TVdbeCursor)(unsafe.Pointer(pC7)).FseekHit = libc.Uint16FromInt32((*TOp)(unsafe.Pointer(pOp)).Fp2)
|
|
} else {
|
|
if libc.Int32FromUint16((*TVdbeCursor)(unsafe.Pointer(pC7)).FseekHit) > (*TOp)(unsafe.Pointer(pOp)).Fp3 {
|
|
(*TVdbeCursor)(unsafe.Pointer(pC7)).FseekHit = libc.Uint16FromInt32((*TOp)(unsafe.Pointer(pOp)).Fp3)
|
|
}
|
|
}
|
|
goto _189
|
|
/* Opcode: IfNotOpen P1 P2 * * *
|
|
** Synopsis: if( !csr[P1] ) goto P2
|
|
**
|
|
** If cursor P1 is not open or if P1 is set to a NULL row using the
|
|
** OP_NullRow opcode, then jump to instruction P2. Otherwise, fall through.
|
|
*/
|
|
_91:
|
|
;
|
|
pCur1 = **(**uintptr)(__ccgo_up((*TVdbe)(unsafe.Pointer(p)).FapCsr + uintptr((*TOp)(unsafe.Pointer(pOp)).Fp1)*4))
|
|
if pCur1 == uintptr(0) || (*TVdbeCursor)(unsafe.Pointer(pCur1)).FnullRow != 0 {
|
|
goto jump_to_p2_and_check_for_interrupt
|
|
}
|
|
goto _189
|
|
/* Opcode: Found P1 P2 P3 P4 *
|
|
** Synopsis: key=r[P3@P4]
|
|
**
|
|
** If P4==0 then register P3 holds a blob constructed by MakeRecord. If
|
|
** P4>0 then register P3 is the first of P4 registers that form an unpacked
|
|
** record.
|
|
**
|
|
** Cursor P1 is on an index btree. If the record identified by P3 and P4
|
|
** is a prefix of any entry in P1 then a jump is made to P2 and
|
|
** P1 is left pointing at the matching entry.
|
|
**
|
|
** This operation leaves the cursor in a state where it can be
|
|
** advanced in the forward direction. The Next instruction will work,
|
|
** but not the Prev instruction.
|
|
**
|
|
** See also: NotFound, NoConflict, NotExists. SeekGe
|
|
*/
|
|
/* Opcode: NotFound P1 P2 P3 P4 *
|
|
** Synopsis: key=r[P3@P4]
|
|
**
|
|
** If P4==0 then register P3 holds a blob constructed by MakeRecord. If
|
|
** P4>0 then register P3 is the first of P4 registers that form an unpacked
|
|
** record.
|
|
**
|
|
** Cursor P1 is on an index btree. If the record identified by P3 and P4
|
|
** is not the prefix of any entry in P1 then a jump is made to P2. If P1
|
|
** does contain an entry whose prefix matches the P3/P4 record then control
|
|
** falls through to the next instruction and P1 is left pointing at the
|
|
** matching entry.
|
|
**
|
|
** This operation leaves the cursor in a state where it cannot be
|
|
** advanced in either direction. In other words, the Next and Prev
|
|
** opcodes do not work after this operation.
|
|
**
|
|
** See also: Found, NotExists, NoConflict, IfNoHope
|
|
*/
|
|
/* Opcode: IfNoHope P1 P2 P3 P4 *
|
|
** Synopsis: key=r[P3@P4]
|
|
**
|
|
** Register P3 is the first of P4 registers that form an unpacked
|
|
** record. Cursor P1 is an index btree. P2 is a jump destination.
|
|
** In other words, the operands to this opcode are the same as the
|
|
** operands to OP_NotFound and OP_IdxGT.
|
|
**
|
|
** This opcode is an optimization attempt only. If this opcode always
|
|
** falls through, the correct answer is still obtained, but extra work
|
|
** is performed.
|
|
**
|
|
** A value of N in the seekHit flag of cursor P1 means that there exists
|
|
** a key P3:N that will match some record in the index. We want to know
|
|
** if it is possible for a record P3:P4 to match some record in the
|
|
** index. If it is not possible, we can skip some work. So if seekHit
|
|
** is less than P4, attempt to find out if a match is possible by running
|
|
** OP_NotFound.
|
|
**
|
|
** This opcode is used in IN clause processing for a multi-column key.
|
|
** If an IN clause is attached to an element of the key other than the
|
|
** left-most element, and if there are no matches on the most recent
|
|
** seek over the whole key, then it might be that one of the key element
|
|
** to the left is prohibiting a match, and hence there is "no hope" of
|
|
** any match regardless of how many IN clause elements are checked.
|
|
** In such a case, we abandon the IN clause search early, using this
|
|
** opcode. The opcode name comes from the fact that the
|
|
** jump is taken if there is "no hope" of achieving a match.
|
|
**
|
|
** See also: NotFound, SeekHit
|
|
*/
|
|
/* Opcode: NoConflict P1 P2 P3 P4 *
|
|
** Synopsis: key=r[P3@P4]
|
|
**
|
|
** If P4==0 then register P3 holds a blob constructed by MakeRecord. If
|
|
** P4>0 then register P3 is the first of P4 registers that form an unpacked
|
|
** record.
|
|
**
|
|
** Cursor P1 is on an index btree. If the record identified by P3 and P4
|
|
** contains any NULL value, jump immediately to P2. If all terms of the
|
|
** record are not-NULL then a check is done to determine if any row in the
|
|
** P1 index btree has a matching key prefix. If there are no matches, jump
|
|
** immediately to P2. If there is a match, fall through and leave the P1
|
|
** cursor pointing to the matching row.
|
|
**
|
|
** This opcode is similar to OP_NotFound with the exceptions that the
|
|
** branch is always taken if any part of the search key input is NULL.
|
|
**
|
|
** This operation leaves the cursor in a state where it cannot be
|
|
** advanced in either direction. In other words, the Next and Prev
|
|
** opcodes do not work after this operation.
|
|
**
|
|
** See also: NotFound, Found, NotExists
|
|
*/
|
|
_92:
|
|
;
|
|
pC8 = **(**uintptr)(__ccgo_up((*TVdbe)(unsafe.Pointer(p)).FapCsr + uintptr((*TOp)(unsafe.Pointer(pOp)).Fp1)*4))
|
|
if libc.Int32FromUint16((*TVdbeCursor)(unsafe.Pointer(pC8)).FseekHit) >= *(*int32)(unsafe.Pointer(pOp + 16)) {
|
|
goto _189
|
|
}
|
|
/* Fall through into OP_NotFound */
|
|
_95:
|
|
; /* jump, in3, ncycle */
|
|
_94:
|
|
; /* jump, in3, ncycle */
|
|
_93:
|
|
;
|
|
pC9 = **(**uintptr)(__ccgo_up((*TVdbe)(unsafe.Pointer(p)).FapCsr + uintptr((*TOp)(unsafe.Pointer(pOp)).Fp1)*4))
|
|
(**(**TUnpackedRecord)(__ccgo_up(bp + 160))).FaMem = aMem + uintptr((*TOp)(unsafe.Pointer(pOp)).Fp3)*40
|
|
(**(**TUnpackedRecord)(__ccgo_up(bp + 160))).FnField = libc.Uint16FromInt32(*(*int32)(unsafe.Pointer(pOp + 16)))
|
|
if libc.Int32FromUint16((**(**TUnpackedRecord)(__ccgo_up(bp + 160))).FnField) > 0 {
|
|
/* Key values in an array of registers */
|
|
(**(**TUnpackedRecord)(__ccgo_up(bp + 160))).FpKeyInfo = (*TVdbeCursor)(unsafe.Pointer(pC9)).FpKeyInfo
|
|
(**(**TUnpackedRecord)(__ccgo_up(bp + 160))).Fdefault_rc = 0
|
|
rc = _sqlite3BtreeIndexMoveto(tls, *(*uintptr)(unsafe.Pointer(pC9 + 36)), bp+160, pC9+28)
|
|
} else {
|
|
/* Composite key generated by OP_MakeRecord */
|
|
if libc.Int32FromUint16((*TMem)(unsafe.Pointer((**(**TUnpackedRecord)(__ccgo_up(bp + 160))).FaMem)).Fflags)&int32(MEM_Zero) != 0 {
|
|
v190 = _sqlite3VdbeMemExpandBlob(tls, (**(**TUnpackedRecord)(__ccgo_up(bp + 160))).FaMem)
|
|
} else {
|
|
v190 = 0
|
|
}
|
|
rc = v190
|
|
if rc != 0 {
|
|
goto no_mem
|
|
}
|
|
pIdxKey = _sqlite3VdbeAllocUnpackedRecord(tls, (*TVdbeCursor)(unsafe.Pointer(pC9)).FpKeyInfo)
|
|
if pIdxKey == uintptr(0) {
|
|
goto no_mem
|
|
}
|
|
_sqlite3VdbeRecordUnpack(tls, (*TMem)(unsafe.Pointer((**(**TUnpackedRecord)(__ccgo_up(bp + 160))).FaMem)).Fn, (*TMem)(unsafe.Pointer((**(**TUnpackedRecord)(__ccgo_up(bp + 160))).FaMem)).Fz, pIdxKey)
|
|
(*TUnpackedRecord)(unsafe.Pointer(pIdxKey)).Fdefault_rc = 0
|
|
rc = _sqlite3BtreeIndexMoveto(tls, *(*uintptr)(unsafe.Pointer(pC9 + 36)), pIdxKey, pC9+28)
|
|
_sqlite3DbFreeNN(tls, db, pIdxKey)
|
|
}
|
|
if rc != SQLITE_OK {
|
|
goto abort_due_to_error
|
|
}
|
|
alreadyExists = libc.BoolInt32((*TVdbeCursor)(unsafe.Pointer(pC9)).FseekResult == 0)
|
|
(*TVdbeCursor)(unsafe.Pointer(pC9)).FnullRow = libc.Uint8FromInt32(int32(1) - alreadyExists)
|
|
(*TVdbeCursor)(unsafe.Pointer(pC9)).FdeferredMoveto = uint8(0)
|
|
(*TVdbeCursor)(unsafe.Pointer(pC9)).FcacheStatus = uint32(CACHE_STALE)
|
|
if libc.Int32FromUint8((*TOp)(unsafe.Pointer(pOp)).Fopcode) == int32(OP_Found) {
|
|
if alreadyExists != 0 {
|
|
goto jump_to_p2
|
|
}
|
|
} else {
|
|
if !(alreadyExists != 0) {
|
|
goto jump_to_p2
|
|
}
|
|
if libc.Int32FromUint8((*TOp)(unsafe.Pointer(pOp)).Fopcode) == int32(OP_NoConflict) {
|
|
/* For the OP_NoConflict opcode, take the jump if any of the
|
|
** input fields are NULL, since any key with a NULL will not
|
|
** conflict */
|
|
ii1 = 0
|
|
for {
|
|
if !(ii1 < libc.Int32FromUint16((**(**TUnpackedRecord)(__ccgo_up(bp + 160))).FnField)) {
|
|
break
|
|
}
|
|
if libc.Int32FromUint16((**(**TMem)(__ccgo_up((**(**TUnpackedRecord)(__ccgo_up(bp + 160))).FaMem + uintptr(ii1)*40))).Fflags)&int32(MEM_Null) != 0 {
|
|
goto jump_to_p2
|
|
}
|
|
goto _263
|
|
_263:
|
|
;
|
|
ii1 = ii1 + 1
|
|
}
|
|
}
|
|
if libc.Int32FromUint8((*TOp)(unsafe.Pointer(pOp)).Fopcode) == int32(OP_IfNoHope) {
|
|
(*TVdbeCursor)(unsafe.Pointer(pC9)).FseekHit = libc.Uint16FromInt32(*(*int32)(unsafe.Pointer(pOp + 16)))
|
|
}
|
|
}
|
|
goto _189
|
|
/* Opcode: SeekRowid P1 P2 P3 * *
|
|
** Synopsis: intkey=r[P3]
|
|
**
|
|
** P1 is the index of a cursor open on an SQL table btree (with integer
|
|
** keys). If register P3 does not contain an integer or if P1 does not
|
|
** contain a record with rowid P3 then jump immediately to P2.
|
|
** Or, if P2 is 0, raise an SQLITE_CORRUPT error. If P1 does contain
|
|
** a record with rowid P3 then
|
|
** leave the cursor pointing at that record and fall through to the next
|
|
** instruction.
|
|
**
|
|
** The OP_NotExists opcode performs the same operation, but with OP_NotExists
|
|
** the P3 register must be guaranteed to contain an integer value. With this
|
|
** opcode, register P3 might not contain an integer.
|
|
**
|
|
** The OP_NotFound opcode performs the same operation on index btrees
|
|
** (with arbitrary multi-value keys).
|
|
**
|
|
** This opcode leaves the cursor in a state where it cannot be advanced
|
|
** in either direction. In other words, the Next and Prev opcodes will
|
|
** not work following this opcode.
|
|
**
|
|
** See also: Found, NotFound, NoConflict, SeekRowid
|
|
*/
|
|
/* Opcode: NotExists P1 P2 P3 * *
|
|
** Synopsis: intkey=r[P3]
|
|
**
|
|
** P1 is the index of a cursor open on an SQL table btree (with integer
|
|
** keys). P3 is an integer rowid. If P1 does not contain a record with
|
|
** rowid P3 then jump immediately to P2. Or, if P2 is 0, raise an
|
|
** SQLITE_CORRUPT error. If P1 does contain a record with rowid P3 then
|
|
** leave the cursor pointing at that record and fall through to the next
|
|
** instruction.
|
|
**
|
|
** The OP_SeekRowid opcode performs the same operation but also allows the
|
|
** P3 register to contain a non-integer value, in which case the jump is
|
|
** always taken. This opcode requires that P3 always contain an integer.
|
|
**
|
|
** The OP_NotFound opcode performs the same operation on index btrees
|
|
** (with arbitrary multi-value keys).
|
|
**
|
|
** This opcode leaves the cursor in a state where it cannot be advanced
|
|
** in either direction. In other words, the Next and Prev opcodes will
|
|
** not work following this opcode.
|
|
**
|
|
** See also: Found, NotFound, NoConflict, SeekRowid
|
|
*/
|
|
_97:
|
|
;
|
|
pIn3 = aMem + uintptr((*TOp)(unsafe.Pointer(pOp)).Fp3)*40
|
|
if libc.Int32FromUint16((*TMem)(unsafe.Pointer(pIn3)).Fflags)&(libc.Int32FromInt32(MEM_Int)|libc.Int32FromInt32(MEM_IntReal)) == 0 {
|
|
/* If pIn3->u.i does not contain an integer, compute iKey as the
|
|
** integer value of pIn3. Jump to P2 if pIn3 cannot be converted
|
|
** into an integer without loss of information. Take care to avoid
|
|
** changing the datatype of pIn3, however, as it is used by other
|
|
** parts of the prepared statement. */
|
|
*(*TMem)(unsafe.Pointer(bp + 192)) = TMem{}
|
|
/* If pIn3->u.i does not contain an integer, compute iKey as the
|
|
** integer value of pIn3. Jump to P2 if pIn3 cannot be converted
|
|
** into an integer without loss of information. Take care to avoid
|
|
** changing the datatype of pIn3, however, as it is used by other
|
|
** parts of the prepared statement. */
|
|
*(*Tsqlite3_value)(unsafe.Pointer(bp + 192)) = **(**TMem)(__ccgo_up(pIn3))
|
|
_applyAffinity(tls, bp+192, int8(SQLITE_AFF_NUMERIC), encoding)
|
|
if libc.Int32FromUint16((**(**TMem)(__ccgo_up(bp + 192))).Fflags)&int32(MEM_Int) == 0 {
|
|
goto jump_to_p2
|
|
}
|
|
iKey1 = libc.Uint64FromInt64(*(*Ti64)(unsafe.Pointer(bp + 192)))
|
|
goto notExistsWithKey
|
|
}
|
|
/* Fall through into OP_NotExists */
|
|
_96:
|
|
; /* jump, in3, ncycle */
|
|
pIn3 = aMem + uintptr((*TOp)(unsafe.Pointer(pOp)).Fp3)*40
|
|
iKey1 = libc.Uint64FromInt64(*(*Ti64)(unsafe.Pointer(pIn3)))
|
|
goto notExistsWithKey
|
|
notExistsWithKey:
|
|
;
|
|
pC10 = **(**uintptr)(__ccgo_up((*TVdbe)(unsafe.Pointer(p)).FapCsr + uintptr((*TOp)(unsafe.Pointer(pOp)).Fp1)*4))
|
|
pCrsr2 = *(*uintptr)(unsafe.Pointer(pC10 + 36))
|
|
**(**int32)(__ccgo_up(bp + 188)) = 0
|
|
rc = _sqlite3BtreeTableMoveto(tls, pCrsr2, libc.Int64FromUint64(iKey1), 0, bp+188)
|
|
(*TVdbeCursor)(unsafe.Pointer(pC10)).FmovetoTarget = libc.Int64FromUint64(iKey1) /* Used by OP_Delete */
|
|
(*TVdbeCursor)(unsafe.Pointer(pC10)).FnullRow = uint8(0)
|
|
(*TVdbeCursor)(unsafe.Pointer(pC10)).FcacheStatus = uint32(CACHE_STALE)
|
|
(*TVdbeCursor)(unsafe.Pointer(pC10)).FdeferredMoveto = uint8(0)
|
|
(*TVdbeCursor)(unsafe.Pointer(pC10)).FseekResult = **(**int32)(__ccgo_up(bp + 188))
|
|
if **(**int32)(__ccgo_up(bp + 188)) != 0 {
|
|
if (*TOp)(unsafe.Pointer(pOp)).Fp2 == 0 {
|
|
rc = _sqlite3CorruptError(tls, int32(102154))
|
|
} else {
|
|
goto jump_to_p2
|
|
}
|
|
}
|
|
if rc != 0 {
|
|
goto abort_due_to_error
|
|
}
|
|
goto _189
|
|
/* Opcode: Sequence P1 P2 * * *
|
|
** Synopsis: r[P2]=cursor[P1].ctr++
|
|
**
|
|
** Find the next available sequence number for cursor P1.
|
|
** Write the sequence number into register P2.
|
|
** The sequence number on the cursor is incremented after this
|
|
** instruction.
|
|
*/
|
|
_98:
|
|
; /* out2 */
|
|
pOut = _out2Prerelease(tls, p, pOp)
|
|
v191 = **(**uintptr)(__ccgo_up((*TVdbe)(unsafe.Pointer(p)).FapCsr + uintptr((*TOp)(unsafe.Pointer(pOp)).Fp1)*4)) + 16
|
|
v256 = *(*Ti64)(unsafe.Pointer(v191))
|
|
*(*Ti64)(unsafe.Pointer(v191)) = *(*Ti64)(unsafe.Pointer(v191)) + 1
|
|
*(*Ti64)(unsafe.Pointer(pOut)) = v256
|
|
goto _189
|
|
/* Opcode: NewRowid P1 P2 P3 * *
|
|
** Synopsis: r[P2]=rowid
|
|
**
|
|
** Get a new integer record number (a.k.a "rowid") used as the key to a table.
|
|
** The record number is not previously used as a key in the database
|
|
** table that cursor P1 points to. The new record number is written
|
|
** written to register P2.
|
|
**
|
|
** If P3>0 then P3 is a register in the root frame of this VDBE that holds
|
|
** the largest previously generated record number. No new record numbers are
|
|
** allowed to be less than this value. When this value reaches its maximum,
|
|
** an SQLITE_FULL error is generated. The P3 register is updated with the '
|
|
** generated record number. This P3 mechanism is used to help implement the
|
|
** AUTOINCREMENT feature.
|
|
*/
|
|
_99:
|
|
; /* Root frame of VDBE */
|
|
**(**Ti64)(__ccgo_up(bp + 232)) = 0
|
|
**(**int32)(__ccgo_up(bp + 240)) = 0
|
|
pOut = _out2Prerelease(tls, p, pOp)
|
|
pC11 = **(**uintptr)(__ccgo_up((*TVdbe)(unsafe.Pointer(p)).FapCsr + uintptr((*TOp)(unsafe.Pointer(pOp)).Fp1)*4))
|
|
/* The next rowid or record number (different terms for the same
|
|
** thing) is obtained in a two-step algorithm.
|
|
**
|
|
** First we attempt to find the largest existing rowid and add one
|
|
** to that. But if the largest existing rowid is already the maximum
|
|
** positive integer, we have to fall through to the second
|
|
** probabilistic algorithm
|
|
**
|
|
** The second algorithm is to select a rowid at random and see if
|
|
** it already exists in the table. If it does not exist, we have
|
|
** succeeded. If the random rowid does exist, we select a new one
|
|
** and try again, up to 100 times.
|
|
*/
|
|
/* Some compilers complain about constants of the form 0x7fffffffffffffff.
|
|
** Others complain about 0x7ffffffffffffffffLL. The following macro seems
|
|
** to provide the constant while making all compilers happy.
|
|
*/
|
|
if !(int32(TBool(*(*uint8)(unsafe.Pointer(pC11 + 8))&0x2>>1)) != 0) {
|
|
rc = _sqlite3BtreeLast(tls, *(*uintptr)(unsafe.Pointer(pC11 + 36)), bp+240)
|
|
if rc != SQLITE_OK {
|
|
goto abort_due_to_error
|
|
}
|
|
if **(**int32)(__ccgo_up(bp + 240)) != 0 {
|
|
**(**Ti64)(__ccgo_up(bp + 232)) = int64(1) /* IMP: R-61914-48074 */
|
|
} else {
|
|
**(**Ti64)(__ccgo_up(bp + 232)) = _sqlite3BtreeIntegerKey(tls, *(*uintptr)(unsafe.Pointer(pC11 + 36)))
|
|
if **(**Ti64)(__ccgo_up(bp + 232)) >= libc.Int64FromUint64(libc.Uint64FromInt32(0x7fffffff)<<libc.Int32FromInt32(32)|libc.Uint64FromUint32(0xffffffff)) {
|
|
libc.SetBitFieldPtr8Uint32(pC11+8, libc.Uint32FromInt32(1), 1, 0x2)
|
|
} else {
|
|
**(**Ti64)(__ccgo_up(bp + 232)) = **(**Ti64)(__ccgo_up(bp + 232)) + 1 /* IMP: R-29538-34987 */
|
|
}
|
|
}
|
|
}
|
|
if (*TOp)(unsafe.Pointer(pOp)).Fp3 != 0 {
|
|
/* Assert that P3 is a valid memory cell. */
|
|
if (*TVdbe)(unsafe.Pointer(p)).FpFrame != 0 {
|
|
pFrame1 = (*TVdbe)(unsafe.Pointer(p)).FpFrame
|
|
for {
|
|
if !((*TVdbeFrame)(unsafe.Pointer(pFrame1)).FpParent != 0) {
|
|
break
|
|
}
|
|
goto _266
|
|
_266:
|
|
;
|
|
pFrame1 = (*TVdbeFrame)(unsafe.Pointer(pFrame1)).FpParent
|
|
}
|
|
/* Assert that P3 is a valid memory cell. */
|
|
pMem = (*TVdbeFrame)(unsafe.Pointer(pFrame1)).FaMem + uintptr((*TOp)(unsafe.Pointer(pOp)).Fp3)*40
|
|
} else {
|
|
/* Assert that P3 is a valid memory cell. */
|
|
pMem = aMem + uintptr((*TOp)(unsafe.Pointer(pOp)).Fp3)*40
|
|
}
|
|
_sqlite3VdbeMemIntegerify(tls, pMem)
|
|
/* mem(P3) holds an integer */
|
|
if *(*Ti64)(unsafe.Pointer(pMem)) == libc.Int64FromUint64(libc.Uint64FromInt32(0x7fffffff)<<libc.Int32FromInt32(32)|libc.Uint64FromUint32(0xffffffff)) || int32(TBool(*(*uint8)(unsafe.Pointer(pC11 + 8))&0x2>>1)) != 0 {
|
|
rc = int32(SQLITE_FULL) /* IMP: R-17817-00630 */
|
|
goto abort_due_to_error
|
|
}
|
|
if **(**Ti64)(__ccgo_up(bp + 232)) < *(*Ti64)(unsafe.Pointer(pMem))+int64(1) {
|
|
**(**Ti64)(__ccgo_up(bp + 232)) = *(*Ti64)(unsafe.Pointer(pMem)) + int64(1)
|
|
}
|
|
*(*Ti64)(unsafe.Pointer(pMem)) = **(**Ti64)(__ccgo_up(bp + 232))
|
|
}
|
|
if int32(TBool(*(*uint8)(unsafe.Pointer(pC11 + 8))&0x2>>1)) != 0 {
|
|
/* IMPLEMENTATION-OF: R-07677-41881 If the largest ROWID is equal to the
|
|
** largest possible integer (9223372036854775807) then the database
|
|
** engine starts picking positive candidate ROWIDs at random until
|
|
** it finds one that is not previously used. */
|
|
/* We cannot be in random rowid mode if this is
|
|
** an AUTOINCREMENT table. */
|
|
cnt1 = 0
|
|
for {
|
|
Xsqlite3_randomness(tls, int32(8), bp+232)
|
|
**(**Ti64)(__ccgo_up(bp + 232)) = **(**Ti64)(__ccgo_up(bp + 232)) & (libc.Int64FromUint64(libc.Uint64FromInt32(0x7fffffff)<<libc.Int32FromInt32(32)|libc.Uint64FromUint32(0xffffffff)) >> libc.Int32FromInt32(1))
|
|
**(**Ti64)(__ccgo_up(bp + 232)) = **(**Ti64)(__ccgo_up(bp + 232)) + 1 /* Ensure that v is greater than zero */
|
|
goto _270
|
|
_270:
|
|
;
|
|
v190 = _sqlite3BtreeTableMoveto(tls, *(*uintptr)(unsafe.Pointer(pC11 + 36)), libc.Int64FromUint64(libc.Uint64FromInt64(**(**Ti64)(__ccgo_up(bp + 232)))), 0, bp+240)
|
|
rc = v190
|
|
if v217 = v190 == SQLITE_OK && **(**int32)(__ccgo_up(bp + 240)) == 0; v217 {
|
|
cnt1 = cnt1 + 1
|
|
v193 = cnt1
|
|
}
|
|
if !(v217 && v193 < int32(100)) {
|
|
break
|
|
}
|
|
}
|
|
if rc != 0 {
|
|
goto abort_due_to_error
|
|
}
|
|
if **(**int32)(__ccgo_up(bp + 240)) == 0 {
|
|
rc = int32(SQLITE_FULL) /* IMP: R-38219-53002 */
|
|
goto abort_due_to_error
|
|
}
|
|
/* EV: R-40812-03570 */
|
|
}
|
|
(*TVdbeCursor)(unsafe.Pointer(pC11)).FdeferredMoveto = uint8(0)
|
|
(*TVdbeCursor)(unsafe.Pointer(pC11)).FcacheStatus = uint32(CACHE_STALE)
|
|
*(*Ti64)(unsafe.Pointer(pOut)) = **(**Ti64)(__ccgo_up(bp + 232))
|
|
goto _189
|
|
/* Opcode: Insert P1 P2 P3 P4 P5
|
|
** Synopsis: intkey=r[P3] data=r[P2]
|
|
**
|
|
** Write an entry into the table of cursor P1. A new entry is
|
|
** created if it doesn't already exist or the data for an existing
|
|
** entry is overwritten. The data is the value MEM_Blob stored in register
|
|
** number P2. The key is stored in register P3. The key must
|
|
** be a MEM_Int.
|
|
**
|
|
** If the OPFLAG_NCHANGE flag of P5 is set, then the row change count is
|
|
** incremented (otherwise not). If the OPFLAG_LASTROWID flag of P5 is set,
|
|
** then rowid is stored for subsequent return by the
|
|
** sqlite3_last_insert_rowid() function (otherwise it is unmodified).
|
|
**
|
|
** If the OPFLAG_USESEEKRESULT flag of P5 is set, the implementation might
|
|
** run faster by avoiding an unnecessary seek on cursor P1. However,
|
|
** the OPFLAG_USESEEKRESULT flag must only be set if there have been no prior
|
|
** seeks on the cursor or if the most recent seek used a key equal to P3.
|
|
**
|
|
** If the OPFLAG_ISUPDATE flag is set, then this opcode is part of an
|
|
** UPDATE operation. Otherwise (if the flag is clear) then this opcode
|
|
** is part of an INSERT operation. The difference is only important to
|
|
** the update hook.
|
|
**
|
|
** Parameter P4 may point to a Table structure, or may be NULL. If it is
|
|
** not NULL, then the update-hook (sqlite3.xUpdateCallback) is invoked
|
|
** following a successful insert.
|
|
**
|
|
** (WARNING/TODO: If P1 is a pseudo-cursor and P2 is dynamically
|
|
** allocated, then ownership of P2 is transferred to the pseudo-cursor
|
|
** and register P2 becomes ephemeral. If the cursor is changed, the
|
|
** value of register P2 will then change. Make sure this does not
|
|
** cause any problems.)
|
|
**
|
|
** This instruction only works on tables. The equivalent instruction
|
|
** for indices is OP_IdxInsert.
|
|
*/
|
|
_100:
|
|
; /* Payload to be inserted */
|
|
pData = aMem + uintptr((*TOp)(unsafe.Pointer(pOp)).Fp2)*40
|
|
pC12 = **(**uintptr)(__ccgo_up((*TVdbe)(unsafe.Pointer(p)).FapCsr + uintptr((*TOp)(unsafe.Pointer(pOp)).Fp1)*4))
|
|
pKey = aMem + uintptr((*TOp)(unsafe.Pointer(pOp)).Fp3)*40
|
|
(**(**TBtreePayload)(__ccgo_up(bp + 244))).FnKey = *(*Ti64)(unsafe.Pointer(pKey))
|
|
if int32((*TOp)(unsafe.Pointer(pOp)).Fp4type) == -int32(5) && ((*Tsqlite3)(unsafe.Pointer(db)).FxPreUpdateCallback != 0 || (*Tsqlite3)(unsafe.Pointer(db)).FxUpdateCallback != 0) {
|
|
zDb = (**(**TDb)(__ccgo_up((*Tsqlite3)(unsafe.Pointer(db)).FaDb + uintptr((*TVdbeCursor)(unsafe.Pointer(pC12)).FiDb)*16))).FzDbSName
|
|
pTab1 = *(*uintptr)(unsafe.Pointer(pOp + 16))
|
|
} else {
|
|
pTab1 = uintptr(0)
|
|
zDb = uintptr(0)
|
|
}
|
|
/* Invoke the pre-update hook, if any */
|
|
if pTab1 != 0 {
|
|
if (*Tsqlite3)(unsafe.Pointer(db)).FxPreUpdateCallback != 0 && !(libc.Int32FromUint16((*TOp)(unsafe.Pointer(pOp)).Fp5)&libc.Int32FromInt32(OPFLAG_ISUPDATE) != 0) {
|
|
_sqlite3VdbePreUpdateHook(tls, p, pC12, int32(SQLITE_INSERT), zDb, pTab1, (**(**TBtreePayload)(__ccgo_up(bp + 244))).FnKey, (*TOp)(unsafe.Pointer(pOp)).Fp2, -int32(1))
|
|
}
|
|
if (*Tsqlite3)(unsafe.Pointer(db)).FxUpdateCallback == uintptr(0) || (*TTable)(unsafe.Pointer(pTab1)).FaCol == uintptr(0) {
|
|
/* Prevent post-update hook from running in cases when it should not */
|
|
pTab1 = uintptr(0)
|
|
}
|
|
}
|
|
if libc.Int32FromUint16((*TOp)(unsafe.Pointer(pOp)).Fp5)&int32(OPFLAG_ISNOOP) != 0 {
|
|
goto _189
|
|
}
|
|
if libc.Int32FromUint16((*TOp)(unsafe.Pointer(pOp)).Fp5)&int32(OPFLAG_NCHANGE) != 0 {
|
|
(*TVdbe)(unsafe.Pointer(p)).FnChange = (*TVdbe)(unsafe.Pointer(p)).FnChange + 1
|
|
if libc.Int32FromUint16((*TOp)(unsafe.Pointer(pOp)).Fp5)&int32(OPFLAG_LASTROWID) != 0 {
|
|
(*Tsqlite3)(unsafe.Pointer(db)).FlastRowid = (**(**TBtreePayload)(__ccgo_up(bp + 244))).FnKey
|
|
}
|
|
}
|
|
(**(**TBtreePayload)(__ccgo_up(bp + 244))).FpData = (*TMem)(unsafe.Pointer(pData)).Fz
|
|
(**(**TBtreePayload)(__ccgo_up(bp + 244))).FnData = (*TMem)(unsafe.Pointer(pData)).Fn
|
|
if libc.Int32FromUint16((*TOp)(unsafe.Pointer(pOp)).Fp5)&int32(OPFLAG_USESEEKRESULT) != 0 {
|
|
v190 = (*TVdbeCursor)(unsafe.Pointer(pC12)).FseekResult
|
|
} else {
|
|
v190 = 0
|
|
}
|
|
seekResult = v190
|
|
if libc.Int32FromUint16((*TMem)(unsafe.Pointer(pData)).Fflags)&int32(MEM_Zero) != 0 {
|
|
(**(**TBtreePayload)(__ccgo_up(bp + 244))).FnZero = *(*int32)(unsafe.Pointer(&(*TMem)(unsafe.Pointer(pData)).Fu))
|
|
} else {
|
|
(**(**TBtreePayload)(__ccgo_up(bp + 244))).FnZero = 0
|
|
}
|
|
(**(**TBtreePayload)(__ccgo_up(bp + 244))).FpKey = uintptr(0)
|
|
rc = _sqlite3BtreeInsert(tls, *(*uintptr)(unsafe.Pointer(pC12 + 36)), bp+244, libc.Int32FromUint16((*TOp)(unsafe.Pointer(pOp)).Fp5)&(libc.Int32FromInt32(OPFLAG_APPEND)|libc.Int32FromInt32(OPFLAG_SAVEPOSITION)|libc.Int32FromInt32(OPFLAG_PREFORMAT)), seekResult)
|
|
(*TVdbeCursor)(unsafe.Pointer(pC12)).FdeferredMoveto = uint8(0)
|
|
(*TVdbeCursor)(unsafe.Pointer(pC12)).FcacheStatus = uint32(CACHE_STALE)
|
|
colCacheCtr = colCacheCtr + 1
|
|
/* Invoke the update-hook if required. */
|
|
if rc != 0 {
|
|
goto abort_due_to_error
|
|
}
|
|
if pTab1 != 0 {
|
|
if libc.Int32FromUint16((*TOp)(unsafe.Pointer(pOp)).Fp5)&int32(OPFLAG_ISUPDATE) != 0 {
|
|
v190 = int32(SQLITE_UPDATE)
|
|
} else {
|
|
v190 = int32(SQLITE_INSERT)
|
|
}
|
|
(*(*func(*libc.TLS, uintptr, int32, uintptr, uintptr, Tsqlite_int64))(unsafe.Pointer(&struct{ uintptr }{(*Tsqlite3)(unsafe.Pointer(db)).FxUpdateCallback})))(tls, (*Tsqlite3)(unsafe.Pointer(db)).FpUpdateArg, v190, zDb, (*TTable)(unsafe.Pointer(pTab1)).FzName, (**(**TBtreePayload)(__ccgo_up(bp + 244))).FnKey)
|
|
}
|
|
goto _189
|
|
/* Opcode: RowCell P1 P2 P3 * *
|
|
**
|
|
** P1 and P2 are both open cursors. Both must be opened on the same type
|
|
** of table - intkey or index. This opcode is used as part of copying
|
|
** the current row from P2 into P1. If the cursors are opened on intkey
|
|
** tables, register P3 contains the rowid to use with the new record in
|
|
** P1. If they are opened on index tables, P3 is not used.
|
|
**
|
|
** This opcode must be followed by either an Insert or InsertIdx opcode
|
|
** with the OPFLAG_PREFORMAT flag set to complete the insert operation.
|
|
*/
|
|
_101:
|
|
; /* Rowid value to insert with */
|
|
pDest1 = **(**uintptr)(__ccgo_up((*TVdbe)(unsafe.Pointer(p)).FapCsr + uintptr((*TOp)(unsafe.Pointer(pOp)).Fp1)*4))
|
|
pSrc = **(**uintptr)(__ccgo_up((*TVdbe)(unsafe.Pointer(p)).FapCsr + uintptr((*TOp)(unsafe.Pointer(pOp)).Fp2)*4))
|
|
if (*TOp)(unsafe.Pointer(pOp)).Fp3 != 0 {
|
|
v206 = *(*Ti64)(unsafe.Pointer(aMem + uintptr((*TOp)(unsafe.Pointer(pOp)).Fp3)*40))
|
|
} else {
|
|
v206 = 0
|
|
}
|
|
iKey2 = v206
|
|
rc = _sqlite3BtreeTransferRow(tls, *(*uintptr)(unsafe.Pointer(pDest1 + 36)), *(*uintptr)(unsafe.Pointer(pSrc + 36)), iKey2)
|
|
if rc != SQLITE_OK {
|
|
goto abort_due_to_error
|
|
}
|
|
goto _189
|
|
/* Opcode: Delete P1 P2 P3 P4 P5
|
|
**
|
|
** Delete the record at which the P1 cursor is currently pointing.
|
|
**
|
|
** If the OPFLAG_SAVEPOSITION bit of the P5 parameter is set, then
|
|
** the cursor will be left pointing at either the next or the previous
|
|
** record in the table. If it is left pointing at the next record, then
|
|
** the next Next instruction will be a no-op. As a result, in this case
|
|
** it is ok to delete a record from within a Next loop. If
|
|
** OPFLAG_SAVEPOSITION bit of P5 is clear, then the cursor will be
|
|
** left in an undefined state.
|
|
**
|
|
** If the OPFLAG_AUXDELETE bit is set on P5, that indicates that this
|
|
** delete is one of several associated with deleting a table row and
|
|
** all its associated index entries. Exactly one of those deletes is
|
|
** the "primary" delete. The others are all on OPFLAG_FORDELETE
|
|
** cursors or else are marked with the AUXDELETE flag.
|
|
**
|
|
** If the OPFLAG_NCHANGE (0x01) flag of P2 (NB: P2 not P5) is set, then
|
|
** the row change count is incremented (otherwise not).
|
|
**
|
|
** If the OPFLAG_ISNOOP (0x40) flag of P2 (not P5!) is set, then the
|
|
** pre-update-hook for deletes is run, but the btree is otherwise unchanged.
|
|
** This happens when the OP_Delete is to be shortly followed by an OP_Insert
|
|
** with the same key, causing the btree entry to be overwritten.
|
|
**
|
|
** P1 must not be pseudo-table. It has to be a real table with
|
|
** multiple rows.
|
|
**
|
|
** If P4 is not NULL then it points to a Table object. In this case either
|
|
** the update or pre-update hook, or both, may be invoked. The P1 cursor must
|
|
** have been positioned using OP_NotFound prior to invoking this opcode in
|
|
** this case. Specifically, if one is configured, the pre-update hook is
|
|
** invoked if P4 is not NULL. The update-hook is invoked if one is configured,
|
|
** P4 is not NULL, and the OPFLAG_NCHANGE flag is set in P2.
|
|
**
|
|
** If the OPFLAG_ISUPDATE flag is set in P2, then P3 contains the address
|
|
** of the memory cell that contains the value that the rowid of the row will
|
|
** be set to by the update.
|
|
*/
|
|
_102:
|
|
;
|
|
opflags = (*TOp)(unsafe.Pointer(pOp)).Fp2
|
|
pC13 = **(**uintptr)(__ccgo_up((*TVdbe)(unsafe.Pointer(p)).FapCsr + uintptr((*TOp)(unsafe.Pointer(pOp)).Fp1)*4))
|
|
/* If the update-hook or pre-update-hook will be invoked, set zDb to
|
|
** the name of the db to pass as to it. Also set local pTab to a copy
|
|
** of p4.pTab. Finally, if p5 is true, indicating that this cursor was
|
|
** last moved with OP_Next or OP_Prev, not Seek or NotFound, set
|
|
** VdbeCursor.movetoTarget to the current rowid. */
|
|
if int32((*TOp)(unsafe.Pointer(pOp)).Fp4type) == -int32(5) && ((*Tsqlite3)(unsafe.Pointer(db)).FxPreUpdateCallback != 0 || (*Tsqlite3)(unsafe.Pointer(db)).FxUpdateCallback != 0) {
|
|
zDb1 = (**(**TDb)(__ccgo_up((*Tsqlite3)(unsafe.Pointer(db)).FaDb + uintptr((*TVdbeCursor)(unsafe.Pointer(pC13)).FiDb)*16))).FzDbSName
|
|
pTab2 = *(*uintptr)(unsafe.Pointer(pOp + 16))
|
|
if libc.Int32FromUint16((*TOp)(unsafe.Pointer(pOp)).Fp5)&int32(OPFLAG_SAVEPOSITION) != 0 && (*TVdbeCursor)(unsafe.Pointer(pC13)).FisTable != 0 {
|
|
(*TVdbeCursor)(unsafe.Pointer(pC13)).FmovetoTarget = _sqlite3BtreeIntegerKey(tls, *(*uintptr)(unsafe.Pointer(pC13 + 36)))
|
|
}
|
|
} else {
|
|
zDb1 = uintptr(0)
|
|
pTab2 = uintptr(0)
|
|
}
|
|
/* Invoke the pre-update-hook if required. */
|
|
if (*Tsqlite3)(unsafe.Pointer(db)).FxPreUpdateCallback != 0 && pTab2 != 0 {
|
|
if opflags&int32(OPFLAG_ISUPDATE) != 0 {
|
|
v190 = int32(SQLITE_UPDATE)
|
|
} else {
|
|
v190 = int32(SQLITE_DELETE)
|
|
}
|
|
_sqlite3VdbePreUpdateHook(tls, p, pC13, v190, zDb1, pTab2, (*TVdbeCursor)(unsafe.Pointer(pC13)).FmovetoTarget, (*TOp)(unsafe.Pointer(pOp)).Fp3, -int32(1))
|
|
}
|
|
if opflags&int32(OPFLAG_ISNOOP) != 0 {
|
|
goto _189
|
|
}
|
|
/* Only flags that can be set are SAVEPOISTION and AUXDELETE */
|
|
rc = _sqlite3BtreeDelete(tls, *(*uintptr)(unsafe.Pointer(pC13 + 36)), uint8((*TOp)(unsafe.Pointer(pOp)).Fp5))
|
|
(*TVdbeCursor)(unsafe.Pointer(pC13)).FcacheStatus = uint32(CACHE_STALE)
|
|
colCacheCtr = colCacheCtr + 1
|
|
(*TVdbeCursor)(unsafe.Pointer(pC13)).FseekResult = 0
|
|
if rc != 0 {
|
|
goto abort_due_to_error
|
|
}
|
|
/* Invoke the update-hook if required. */
|
|
if opflags&int32(OPFLAG_NCHANGE) != 0 {
|
|
(*TVdbe)(unsafe.Pointer(p)).FnChange = (*TVdbe)(unsafe.Pointer(p)).FnChange + 1
|
|
if (*Tsqlite3)(unsafe.Pointer(db)).FxUpdateCallback != 0 && pTab2 != uintptr(0) && (*TTable)(unsafe.Pointer(pTab2)).FtabFlags&uint32(TF_WithoutRowid) == uint32(0) {
|
|
(*(*func(*libc.TLS, uintptr, int32, uintptr, uintptr, Tsqlite_int64))(unsafe.Pointer(&struct{ uintptr }{(*Tsqlite3)(unsafe.Pointer(db)).FxUpdateCallback})))(tls, (*Tsqlite3)(unsafe.Pointer(db)).FpUpdateArg, int32(SQLITE_DELETE), zDb1, (*TTable)(unsafe.Pointer(pTab2)).FzName, (*TVdbeCursor)(unsafe.Pointer(pC13)).FmovetoTarget)
|
|
}
|
|
}
|
|
goto _189
|
|
/* Opcode: ResetCount * * * * *
|
|
**
|
|
** The value of the change counter is copied to the database handle
|
|
** change counter (returned by subsequent calls to sqlite3_changes()).
|
|
** Then the VMs internal change counter resets to 0.
|
|
** This is used by trigger programs.
|
|
*/
|
|
_103:
|
|
;
|
|
_sqlite3VdbeSetChanges(tls, db, (*TVdbe)(unsafe.Pointer(p)).FnChange)
|
|
(*TVdbe)(unsafe.Pointer(p)).FnChange = 0
|
|
goto _189
|
|
/* Opcode: SorterCompare P1 P2 P3 P4
|
|
** Synopsis: if key(P1)!=trim(r[P3],P4) goto P2
|
|
**
|
|
** P1 is a sorter cursor. This instruction compares a prefix of the
|
|
** record blob in register P3 against a prefix of the entry that
|
|
** the sorter cursor currently points to. Only the first P4 fields
|
|
** of r[P3] and the sorter record are compared.
|
|
**
|
|
** If either P3 or the sorter contains a NULL in one of their significant
|
|
** fields (not counting the P4 fields at the end which are ignored) then
|
|
** the comparison is assumed to be equal.
|
|
**
|
|
** Fall through to next instruction if the two records compare equal to
|
|
** each other. Jump to P2 if they are different.
|
|
*/
|
|
_104:
|
|
;
|
|
pC14 = **(**uintptr)(__ccgo_up((*TVdbe)(unsafe.Pointer(p)).FapCsr + uintptr((*TOp)(unsafe.Pointer(pOp)).Fp1)*4))
|
|
pIn3 = aMem + uintptr((*TOp)(unsafe.Pointer(pOp)).Fp3)*40
|
|
nKeyCol = *(*int32)(unsafe.Pointer(pOp + 16))
|
|
**(**int32)(__ccgo_up(bp + 276)) = 0
|
|
rc = _sqlite3VdbeSorterCompare(tls, pC14, pIn3, nKeyCol, bp+276)
|
|
if rc != 0 {
|
|
goto abort_due_to_error
|
|
}
|
|
if **(**int32)(__ccgo_up(bp + 276)) != 0 {
|
|
goto jump_to_p2
|
|
}
|
|
goto _189
|
|
/* Opcode: SorterData P1 P2 P3 * *
|
|
** Synopsis: r[P2]=data
|
|
**
|
|
** Write into register P2 the current sorter data for sorter cursor P1.
|
|
** Then clear the column header cache on cursor P3.
|
|
**
|
|
** This opcode is normally used to move a record out of the sorter and into
|
|
** a register that is the source for a pseudo-table cursor created using
|
|
** OpenPseudo. That pseudo-table cursor is the one that is identified by
|
|
** parameter P3. Clearing the P3 column cache as part of this opcode saves
|
|
** us from having to issue a separate NullRow instruction to clear that cache.
|
|
*/
|
|
_105:
|
|
;
|
|
pOut = aMem + uintptr((*TOp)(unsafe.Pointer(pOp)).Fp2)*40
|
|
pC15 = **(**uintptr)(__ccgo_up((*TVdbe)(unsafe.Pointer(p)).FapCsr + uintptr((*TOp)(unsafe.Pointer(pOp)).Fp1)*4))
|
|
rc = _sqlite3VdbeSorterRowkey(tls, pC15, pOut)
|
|
if rc != 0 {
|
|
goto abort_due_to_error
|
|
}
|
|
(*TVdbeCursor)(unsafe.Pointer(**(**uintptr)(__ccgo_up((*TVdbe)(unsafe.Pointer(p)).FapCsr + uintptr((*TOp)(unsafe.Pointer(pOp)).Fp3)*4)))).FcacheStatus = uint32(CACHE_STALE)
|
|
goto _189
|
|
/* Opcode: RowData P1 P2 P3 * *
|
|
** Synopsis: r[P2]=data
|
|
**
|
|
** Write into register P2 the complete row content for the row at
|
|
** which cursor P1 is currently pointing.
|
|
** There is no interpretation of the data.
|
|
** It is just copied onto the P2 register exactly as
|
|
** it is found in the database file.
|
|
**
|
|
** If cursor P1 is an index, then the content is the key of the row.
|
|
** If cursor P2 is a table, then the content extracted is the data.
|
|
**
|
|
** If the P1 cursor must be pointing to a valid row (not a NULL row)
|
|
** of a real table, not a pseudo-table.
|
|
**
|
|
** If P3!=0 then this opcode is allowed to make an ephemeral pointer
|
|
** into the database page. That means that the content of the output
|
|
** register will be invalidated as soon as the cursor moves - including
|
|
** moves caused by other cursors that "save" the current cursors
|
|
** position in order that they can write to the same table. If P3==0
|
|
** then a copy of the data is made into memory. P3!=0 is faster, but
|
|
** P3==0 is safer.
|
|
**
|
|
** If P3!=0 then the content of the P2 register is unsuitable for use
|
|
** in OP_Result and any OP_Result will invalidate the P2 register content.
|
|
** The P2 register content is invalidated by opcodes like OP_Function or
|
|
** by any use of another cursor pointing to the same table.
|
|
*/
|
|
_106:
|
|
;
|
|
pOut = _out2Prerelease(tls, p, pOp)
|
|
pC16 = **(**uintptr)(__ccgo_up((*TVdbe)(unsafe.Pointer(p)).FapCsr + uintptr((*TOp)(unsafe.Pointer(pOp)).Fp1)*4))
|
|
pCrsr3 = *(*uintptr)(unsafe.Pointer(pC16 + 36))
|
|
/* The OP_RowData opcodes always follow OP_NotExists or
|
|
** OP_SeekRowid or OP_Rewind/Op_Next with no intervening instructions
|
|
** that might invalidate the cursor.
|
|
** If this were not the case, one of the following assert()s
|
|
** would fail. Should this ever change (because of changes in the code
|
|
** generator) then the fix would be to insert a call to
|
|
** sqlite3VdbeCursorMoveto().
|
|
*/
|
|
n3 = _sqlite3BtreePayloadSize(tls, pCrsr3)
|
|
if n3 > libc.Uint32FromInt32(**(**int32)(__ccgo_up(db + 116))) {
|
|
goto too_big
|
|
}
|
|
rc = _sqlite3VdbeMemFromBtreeZeroOffset(tls, pCrsr3, n3, pOut)
|
|
if rc != 0 {
|
|
goto abort_due_to_error
|
|
}
|
|
if !((*TOp)(unsafe.Pointer(pOp)).Fp3 != 0) {
|
|
if libc.Int32FromUint16((*TMem)(unsafe.Pointer(pOut)).Fflags)&int32(MEM_Ephem) != 0 && _sqlite3VdbeMemMakeWriteable(tls, pOut) != 0 {
|
|
goto no_mem
|
|
}
|
|
}
|
|
goto _189
|
|
/* Opcode: Rowid P1 P2 * * *
|
|
** Synopsis: r[P2]=PX rowid of P1
|
|
**
|
|
** Store in register P2 an integer which is the key of the table entry that
|
|
** P1 is currently point to.
|
|
**
|
|
** P1 can be either an ordinary table or a virtual table. There used to
|
|
** be a separate OP_VRowid opcode for use with virtual tables, but this
|
|
** one opcode now works for both table types.
|
|
*/
|
|
_107:
|
|
;
|
|
pOut = _out2Prerelease(tls, p, pOp)
|
|
pC17 = **(**uintptr)(__ccgo_up((*TVdbe)(unsafe.Pointer(p)).FapCsr + uintptr((*TOp)(unsafe.Pointer(pOp)).Fp1)*4))
|
|
if (*TVdbeCursor)(unsafe.Pointer(pC17)).FnullRow != 0 {
|
|
(*TMem)(unsafe.Pointer(pOut)).Fflags = uint16(MEM_Null)
|
|
goto _189
|
|
} else {
|
|
if (*TVdbeCursor)(unsafe.Pointer(pC17)).FdeferredMoveto != 0 {
|
|
**(**Ti64)(__ccgo_up(bp + 280)) = (*TVdbeCursor)(unsafe.Pointer(pC17)).FmovetoTarget
|
|
} else {
|
|
if libc.Int32FromUint8((*TVdbeCursor)(unsafe.Pointer(pC17)).FeCurType) == int32(CURTYPE_VTAB) {
|
|
pVtab = (*Tsqlite3_vtab_cursor)(unsafe.Pointer(*(*uintptr)(unsafe.Pointer(pC17 + 36)))).FpVtab
|
|
pModule = (*Tsqlite3_vtab)(unsafe.Pointer(pVtab)).FpModule
|
|
rc = (*(*func(*libc.TLS, uintptr, uintptr) int32)(unsafe.Pointer(&struct{ uintptr }{(*Tsqlite3_module)(unsafe.Pointer(pModule)).FxRowid})))(tls, *(*uintptr)(unsafe.Pointer(pC17 + 36)), bp+280)
|
|
_sqlite3VtabImportErrmsg(tls, p, pVtab)
|
|
if rc != 0 {
|
|
goto abort_due_to_error
|
|
}
|
|
} else {
|
|
rc = _sqlite3VdbeCursorRestore(tls, pC17)
|
|
if rc != 0 {
|
|
goto abort_due_to_error
|
|
}
|
|
if (*TVdbeCursor)(unsafe.Pointer(pC17)).FnullRow != 0 {
|
|
(*TMem)(unsafe.Pointer(pOut)).Fflags = uint16(MEM_Null)
|
|
goto _189
|
|
}
|
|
**(**Ti64)(__ccgo_up(bp + 280)) = _sqlite3BtreeIntegerKey(tls, *(*uintptr)(unsafe.Pointer(pC17 + 36)))
|
|
}
|
|
}
|
|
}
|
|
*(*Ti64)(unsafe.Pointer(pOut)) = **(**Ti64)(__ccgo_up(bp + 280))
|
|
goto _189
|
|
/* Opcode: NullRow P1 * * * *
|
|
**
|
|
** Move the cursor P1 to a null row. Any OP_Column operations
|
|
** that occur while the cursor is on the null row will always
|
|
** write a NULL.
|
|
**
|
|
** If cursor P1 is not previously opened, open it now to a special
|
|
** pseudo-cursor that always returns NULL for every column.
|
|
*/
|
|
_108:
|
|
;
|
|
pC18 = **(**uintptr)(__ccgo_up((*TVdbe)(unsafe.Pointer(p)).FapCsr + uintptr((*TOp)(unsafe.Pointer(pOp)).Fp1)*4))
|
|
if pC18 == uintptr(0) {
|
|
/* If the cursor is not already open, create a special kind of
|
|
** pseudo-cursor that always gives null rows. */
|
|
pC18 = _allocateCursor(tls, p, (*TOp)(unsafe.Pointer(pOp)).Fp1, int32(1), uint8(CURTYPE_PSEUDO))
|
|
if pC18 == uintptr(0) {
|
|
goto no_mem
|
|
}
|
|
(*TVdbeCursor)(unsafe.Pointer(pC18)).FseekResult = 0
|
|
(*TVdbeCursor)(unsafe.Pointer(pC18)).FisTable = uint8(1)
|
|
libc.SetBitFieldPtr8Uint32(pC18+8, libc.Uint32FromInt32(1), 3, 0x8)
|
|
*(*uintptr)(unsafe.Pointer(pC18 + 36)) = _sqlite3BtreeFakeValidCursor(tls)
|
|
}
|
|
(*TVdbeCursor)(unsafe.Pointer(pC18)).FnullRow = uint8(1)
|
|
(*TVdbeCursor)(unsafe.Pointer(pC18)).FcacheStatus = uint32(CACHE_STALE)
|
|
if libc.Int32FromUint8((*TVdbeCursor)(unsafe.Pointer(pC18)).FeCurType) == CURTYPE_BTREE {
|
|
_sqlite3BtreeClearCursor(tls, *(*uintptr)(unsafe.Pointer(pC18 + 36)))
|
|
}
|
|
goto _189
|
|
/* Opcode: SeekEnd P1 * * * *
|
|
**
|
|
** Position cursor P1 at the end of the btree for the purpose of
|
|
** appending a new entry onto the btree.
|
|
**
|
|
** It is assumed that the cursor is used only for appending and so
|
|
** if the cursor is valid, then the cursor must already be pointing
|
|
** at the end of the btree and so no changes are made to
|
|
** the cursor.
|
|
*/
|
|
/* Opcode: Last P1 P2 * * *
|
|
**
|
|
** The next use of the Rowid or Column or Prev instruction for P1
|
|
** will refer to the last entry in the database table or index.
|
|
** If the table or index is empty and P2>0, then jump immediately to P2.
|
|
** If P2 is 0 or if the table or index is not empty, fall through
|
|
** to the following instruction.
|
|
**
|
|
** This opcode leaves the cursor configured to move in reverse order,
|
|
** from the end toward the beginning. In other words, the cursor is
|
|
** configured to use Prev, not Next.
|
|
*/
|
|
_110:
|
|
; /* ncycle */
|
|
_109:
|
|
;
|
|
pC19 = **(**uintptr)(__ccgo_up((*TVdbe)(unsafe.Pointer(p)).FapCsr + uintptr((*TOp)(unsafe.Pointer(pOp)).Fp1)*4))
|
|
pCrsr4 = *(*uintptr)(unsafe.Pointer(pC19 + 36))
|
|
**(**int32)(__ccgo_up(bp + 288)) = 0
|
|
if libc.Int32FromUint8((*TOp)(unsafe.Pointer(pOp)).Fopcode) == int32(OP_SeekEnd) {
|
|
(*TVdbeCursor)(unsafe.Pointer(pC19)).FseekResult = -int32(1)
|
|
if _sqlite3BtreeCursorIsValidNN(tls, pCrsr4) != 0 {
|
|
goto _189
|
|
}
|
|
}
|
|
rc = _sqlite3BtreeLast(tls, pCrsr4, bp+288)
|
|
(*TVdbeCursor)(unsafe.Pointer(pC19)).FnullRow = libc.Uint8FromInt32(**(**int32)(__ccgo_up(bp + 288)))
|
|
(*TVdbeCursor)(unsafe.Pointer(pC19)).FdeferredMoveto = uint8(0)
|
|
(*TVdbeCursor)(unsafe.Pointer(pC19)).FcacheStatus = uint32(CACHE_STALE)
|
|
if rc != 0 {
|
|
goto abort_due_to_error
|
|
}
|
|
if (*TOp)(unsafe.Pointer(pOp)).Fp2 > 0 {
|
|
if **(**int32)(__ccgo_up(bp + 288)) != 0 {
|
|
goto jump_to_p2
|
|
}
|
|
}
|
|
goto _189
|
|
/* Opcode: IfSizeBetween P1 P2 P3 P4 *
|
|
**
|
|
** Let N be the approximate number of rows in the table or index
|
|
** with cursor P1 and let X be 10*log2(N) if N is positive or -1
|
|
** if N is zero.
|
|
**
|
|
** Jump to P2 if X is in between P3 and P4, inclusive.
|
|
*/
|
|
_111:
|
|
;
|
|
pC20 = **(**uintptr)(__ccgo_up((*TVdbe)(unsafe.Pointer(p)).FapCsr + uintptr((*TOp)(unsafe.Pointer(pOp)).Fp1)*4))
|
|
pCrsr5 = *(*uintptr)(unsafe.Pointer(pC20 + 36))
|
|
rc = _sqlite3BtreeFirst(tls, pCrsr5, bp+292)
|
|
if rc != 0 {
|
|
goto abort_due_to_error
|
|
}
|
|
if **(**int32)(__ccgo_up(bp + 292)) != 0 {
|
|
sz = int64(-int32(1)) /* -Infinity encoding */
|
|
} else {
|
|
sz = _sqlite3BtreeRowCountEst(tls, pCrsr5)
|
|
sz = int64(_sqlite3LogEst(tls, libc.Uint64FromInt64(sz)))
|
|
}
|
|
**(**int32)(__ccgo_up(bp + 292)) = libc.BoolInt32(sz >= int64((*TOp)(unsafe.Pointer(pOp)).Fp3) && sz <= int64(*(*int32)(unsafe.Pointer(pOp + 16))))
|
|
if **(**int32)(__ccgo_up(bp + 292)) != 0 {
|
|
goto jump_to_p2
|
|
}
|
|
goto _189
|
|
/* Opcode: SorterSort P1 P2 * * *
|
|
**
|
|
** After all records have been inserted into the Sorter object
|
|
** identified by P1, invoke this opcode to actually do the sorting.
|
|
** Jump to P2 if there are no records to be sorted.
|
|
**
|
|
** This opcode is an alias for OP_Sort and OP_Rewind that is used
|
|
** for Sorter objects.
|
|
*/
|
|
/* Opcode: Sort P1 P2 * * *
|
|
**
|
|
** This opcode does exactly the same thing as OP_Rewind except that
|
|
** it increments an undocumented global variable used for testing.
|
|
**
|
|
** Sorting is accomplished by writing records into a sorting index,
|
|
** then rewinding that index and playing it back from beginning to
|
|
** end. We use the OP_Sort opcode instead of OP_Rewind to do the
|
|
** rewinding so that the global variable will be incremented and
|
|
** regression tests can determine whether or not the optimizer is
|
|
** correctly optimizing out sorts.
|
|
*/
|
|
_113:
|
|
; /* jump ncycle */
|
|
_112:
|
|
; /* jump ncycle */
|
|
**(**Tu32)(__ccgo_up(p + 156 + 2*4)) = **(**Tu32)(__ccgo_up(p + 156 + 2*4)) + 1
|
|
/* Fall through into OP_Rewind */
|
|
/* Opcode: Rewind P1 P2 * * *
|
|
**
|
|
** The next use of the Rowid or Column or Next instruction for P1
|
|
** will refer to the first entry in the database table or index.
|
|
** If the table or index is empty, jump immediately to P2.
|
|
** If the table or index is not empty, fall through to the following
|
|
** instruction.
|
|
**
|
|
** If P2 is zero, that is an assertion that the P1 table is never
|
|
** empty and hence the jump will never be taken.
|
|
**
|
|
** This opcode leaves the cursor configured to move in forward order,
|
|
** from the beginning toward the end. In other words, the cursor is
|
|
** configured to use Next, not Prev.
|
|
*/
|
|
_114:
|
|
;
|
|
pC21 = **(**uintptr)(__ccgo_up((*TVdbe)(unsafe.Pointer(p)).FapCsr + uintptr((*TOp)(unsafe.Pointer(pOp)).Fp1)*4))
|
|
**(**int32)(__ccgo_up(bp + 296)) = int32(1)
|
|
if libc.Int32FromUint8((*TVdbeCursor)(unsafe.Pointer(pC21)).FeCurType) == int32(CURTYPE_SORTER) {
|
|
rc = _sqlite3VdbeSorterRewind(tls, pC21, bp+296)
|
|
} else {
|
|
pCrsr6 = *(*uintptr)(unsafe.Pointer(pC21 + 36))
|
|
rc = _sqlite3BtreeFirst(tls, pCrsr6, bp+296)
|
|
(*TVdbeCursor)(unsafe.Pointer(pC21)).FdeferredMoveto = uint8(0)
|
|
(*TVdbeCursor)(unsafe.Pointer(pC21)).FcacheStatus = uint32(CACHE_STALE)
|
|
}
|
|
if rc != 0 {
|
|
goto abort_due_to_error
|
|
}
|
|
(*TVdbeCursor)(unsafe.Pointer(pC21)).FnullRow = libc.Uint8FromInt32(**(**int32)(__ccgo_up(bp + 296)))
|
|
if (*TOp)(unsafe.Pointer(pOp)).Fp2 > 0 {
|
|
if **(**int32)(__ccgo_up(bp + 296)) != 0 {
|
|
goto jump_to_p2
|
|
}
|
|
}
|
|
goto _189
|
|
/* Opcode: IfEmpty P1 P2 * * *
|
|
** Synopsis: if( empty(P1) ) goto P2
|
|
**
|
|
** Check to see if the b-tree table that cursor P1 references is empty
|
|
** and jump to P2 if it is.
|
|
*/
|
|
_115:
|
|
;
|
|
pC22 = **(**uintptr)(__ccgo_up((*TVdbe)(unsafe.Pointer(p)).FapCsr + uintptr((*TOp)(unsafe.Pointer(pOp)).Fp1)*4))
|
|
pCrsr7 = *(*uintptr)(unsafe.Pointer(pC22 + 36))
|
|
rc = _sqlite3BtreeIsEmpty(tls, pCrsr7, bp+300)
|
|
if rc != 0 {
|
|
goto abort_due_to_error
|
|
}
|
|
if **(**int32)(__ccgo_up(bp + 300)) != 0 {
|
|
goto jump_to_p2
|
|
}
|
|
goto _189
|
|
/* Opcode: Next P1 P2 P3 * P5
|
|
**
|
|
** Advance cursor P1 so that it points to the next key/data pair in its
|
|
** table or index. If there are no more key/value pairs then fall through
|
|
** to the following instruction. But if the cursor advance was successful,
|
|
** jump immediately to P2.
|
|
**
|
|
** The Next opcode is only valid following an SeekGT, SeekGE, or
|
|
** OP_Rewind opcode used to position the cursor. Next is not allowed
|
|
** to follow SeekLT, SeekLE, or OP_Last.
|
|
**
|
|
** The P1 cursor must be for a real table, not a pseudo-table. P1 must have
|
|
** been opened prior to this opcode or the program will segfault.
|
|
**
|
|
** The P3 value is a hint to the btree implementation. If P3==1, that
|
|
** means P1 is an SQL index and that this instruction could have been
|
|
** omitted if that index had been unique. P3 is usually 0. P3 is
|
|
** always either 0 or 1.
|
|
**
|
|
** If P5 is positive and the jump is taken, then event counter
|
|
** number P5-1 in the prepared statement is incremented.
|
|
**
|
|
** See also: Prev
|
|
*/
|
|
/* Opcode: Prev P1 P2 P3 * P5
|
|
**
|
|
** Back up cursor P1 so that it points to the previous key/data pair in its
|
|
** table or index. If there is no previous key/value pairs then fall through
|
|
** to the following instruction. But if the cursor backup was successful,
|
|
** jump immediately to P2.
|
|
**
|
|
**
|
|
** The Prev opcode is only valid following an SeekLT, SeekLE, or
|
|
** OP_Last opcode used to position the cursor. Prev is not allowed
|
|
** to follow SeekGT, SeekGE, or OP_Rewind.
|
|
**
|
|
** The P1 cursor must be for a real table, not a pseudo-table. If P1 is
|
|
** not open then the behavior is undefined.
|
|
**
|
|
** The P3 value is a hint to the btree implementation. If P3==1, that
|
|
** means P1 is an SQL index and that this instruction could have been
|
|
** omitted if that index had been unique. P3 is usually 0. P3 is
|
|
** always either 0 or 1.
|
|
**
|
|
** If P5 is positive and the jump is taken, then event counter
|
|
** number P5-1 in the prepared statement is incremented.
|
|
*/
|
|
/* Opcode: SorterNext P1 P2 * * P5
|
|
**
|
|
** This opcode works just like OP_Next except that P1 must be a
|
|
** sorter object for which the OP_SorterSort opcode has been
|
|
** invoked. This opcode advances the cursor to the next sorted
|
|
** record, or jumps to P2 if there are no more sorted records.
|
|
*/
|
|
_118:
|
|
;
|
|
pC23 = **(**uintptr)(__ccgo_up((*TVdbe)(unsafe.Pointer(p)).FapCsr + uintptr((*TOp)(unsafe.Pointer(pOp)).Fp1)*4))
|
|
rc = _sqlite3VdbeSorterNext(tls, db, pC23)
|
|
goto next_tail
|
|
_116:
|
|
; /* jump, ncycle */
|
|
pC23 = **(**uintptr)(__ccgo_up((*TVdbe)(unsafe.Pointer(p)).FapCsr + uintptr((*TOp)(unsafe.Pointer(pOp)).Fp1)*4))
|
|
rc = _sqlite3BtreePrevious(tls, *(*uintptr)(unsafe.Pointer(pC23 + 36)), (*TOp)(unsafe.Pointer(pOp)).Fp3)
|
|
goto next_tail
|
|
_117:
|
|
; /* jump, ncycle */
|
|
pC23 = **(**uintptr)(__ccgo_up((*TVdbe)(unsafe.Pointer(p)).FapCsr + uintptr((*TOp)(unsafe.Pointer(pOp)).Fp1)*4))
|
|
rc = _sqlite3BtreeNext(tls, *(*uintptr)(unsafe.Pointer(pC23 + 36)), (*TOp)(unsafe.Pointer(pOp)).Fp3)
|
|
goto next_tail
|
|
next_tail:
|
|
;
|
|
(*TVdbeCursor)(unsafe.Pointer(pC23)).FcacheStatus = uint32(CACHE_STALE)
|
|
if rc == SQLITE_OK {
|
|
(*TVdbeCursor)(unsafe.Pointer(pC23)).FnullRow = uint8(0)
|
|
**(**Tu32)(__ccgo_up(p + 156 + uintptr((*TOp)(unsafe.Pointer(pOp)).Fp5)*4)) = **(**Tu32)(__ccgo_up(p + 156 + uintptr((*TOp)(unsafe.Pointer(pOp)).Fp5)*4)) + 1
|
|
goto jump_to_p2_and_check_for_interrupt
|
|
}
|
|
if rc != int32(SQLITE_DONE) {
|
|
goto abort_due_to_error
|
|
}
|
|
rc = SQLITE_OK
|
|
(*TVdbeCursor)(unsafe.Pointer(pC23)).FnullRow = uint8(1)
|
|
goto check_for_interrupt
|
|
/* Opcode: IdxInsert P1 P2 P3 P4 P5
|
|
** Synopsis: key=r[P2]
|
|
**
|
|
** Register P2 holds an SQL index key made using the
|
|
** MakeRecord instructions. This opcode writes that key
|
|
** into the index P1. Data for the entry is nil.
|
|
**
|
|
** If P4 is not zero, then it is the number of values in the unpacked
|
|
** key of reg(P2). In that case, P3 is the index of the first register
|
|
** for the unpacked key. The availability of the unpacked key can sometimes
|
|
** be an optimization.
|
|
**
|
|
** If P5 has the OPFLAG_APPEND bit set, that is a hint to the b-tree layer
|
|
** that this insert is likely to be an append.
|
|
**
|
|
** If P5 has the OPFLAG_NCHANGE bit set, then the change counter is
|
|
** incremented by this instruction. If the OPFLAG_NCHANGE bit is clear,
|
|
** then the change counter is unchanged.
|
|
**
|
|
** If the OPFLAG_USESEEKRESULT flag of P5 is set, the implementation might
|
|
** run faster by avoiding an unnecessary seek on cursor P1. However,
|
|
** the OPFLAG_USESEEKRESULT flag must only be set if there have been no prior
|
|
** seeks on the cursor or if the most recent seek used a key equivalent
|
|
** to P2.
|
|
**
|
|
** This instruction only works for indices. The equivalent instruction
|
|
** for tables is OP_Insert.
|
|
*/
|
|
_119:
|
|
;
|
|
pC24 = **(**uintptr)(__ccgo_up((*TVdbe)(unsafe.Pointer(p)).FapCsr + uintptr((*TOp)(unsafe.Pointer(pOp)).Fp1)*4))
|
|
pIn2 = aMem + uintptr((*TOp)(unsafe.Pointer(pOp)).Fp2)*40
|
|
if libc.Int32FromUint16((*TOp)(unsafe.Pointer(pOp)).Fp5)&int32(OPFLAG_NCHANGE) != 0 {
|
|
(*TVdbe)(unsafe.Pointer(p)).FnChange = (*TVdbe)(unsafe.Pointer(p)).FnChange + 1
|
|
}
|
|
if libc.Int32FromUint16((*TMem)(unsafe.Pointer(pIn2)).Fflags)&int32(MEM_Zero) != 0 {
|
|
v190 = _sqlite3VdbeMemExpandBlob(tls, pIn2)
|
|
} else {
|
|
v190 = 0
|
|
}
|
|
rc = v190
|
|
if rc != 0 {
|
|
goto abort_due_to_error
|
|
}
|
|
(**(**TBtreePayload)(__ccgo_up(bp + 304))).FnKey = int64((*TMem)(unsafe.Pointer(pIn2)).Fn)
|
|
(**(**TBtreePayload)(__ccgo_up(bp + 304))).FpKey = (*TMem)(unsafe.Pointer(pIn2)).Fz
|
|
(**(**TBtreePayload)(__ccgo_up(bp + 304))).FaMem = aMem + uintptr((*TOp)(unsafe.Pointer(pOp)).Fp3)*40
|
|
(**(**TBtreePayload)(__ccgo_up(bp + 304))).FnMem = libc.Uint16FromInt32(*(*int32)(unsafe.Pointer(pOp + 16)))
|
|
if libc.Int32FromUint16((*TOp)(unsafe.Pointer(pOp)).Fp5)&int32(OPFLAG_USESEEKRESULT) != 0 {
|
|
v190 = (*TVdbeCursor)(unsafe.Pointer(pC24)).FseekResult
|
|
} else {
|
|
v190 = 0
|
|
}
|
|
rc = _sqlite3BtreeInsert(tls, *(*uintptr)(unsafe.Pointer(pC24 + 36)), bp+304, libc.Int32FromUint16((*TOp)(unsafe.Pointer(pOp)).Fp5)&(libc.Int32FromInt32(OPFLAG_APPEND)|libc.Int32FromInt32(OPFLAG_SAVEPOSITION)|libc.Int32FromInt32(OPFLAG_PREFORMAT)), v190)
|
|
(*TVdbeCursor)(unsafe.Pointer(pC24)).FcacheStatus = uint32(CACHE_STALE)
|
|
if rc != 0 {
|
|
goto abort_due_to_error
|
|
}
|
|
goto _189
|
|
/* Opcode: SorterInsert P1 P2 * * *
|
|
** Synopsis: key=r[P2]
|
|
**
|
|
** Register P2 holds an SQL index key made using the
|
|
** MakeRecord instructions. This opcode writes that key
|
|
** into the sorter P1. Data for the entry is nil.
|
|
*/
|
|
_120:
|
|
;
|
|
pC25 = **(**uintptr)(__ccgo_up((*TVdbe)(unsafe.Pointer(p)).FapCsr + uintptr((*TOp)(unsafe.Pointer(pOp)).Fp1)*4))
|
|
pIn2 = aMem + uintptr((*TOp)(unsafe.Pointer(pOp)).Fp2)*40
|
|
if libc.Int32FromUint16((*TMem)(unsafe.Pointer(pIn2)).Fflags)&int32(MEM_Zero) != 0 {
|
|
v190 = _sqlite3VdbeMemExpandBlob(tls, pIn2)
|
|
} else {
|
|
v190 = 0
|
|
}
|
|
rc = v190
|
|
if rc != 0 {
|
|
goto abort_due_to_error
|
|
}
|
|
rc = _sqlite3VdbeSorterWrite(tls, pC25, pIn2)
|
|
if rc != 0 {
|
|
goto abort_due_to_error
|
|
}
|
|
goto _189
|
|
/* Opcode: IdxDelete P1 P2 P3 P4 *
|
|
** Synopsis: key=r[P2@P3]
|
|
**
|
|
** The content of P3 registers starting at register P2 form
|
|
** an unpacked index key. This opcode removes that entry from the
|
|
** index opened by cursor P1.
|
|
**
|
|
** P4 is a pointer to an Index structure.
|
|
**
|
|
** Raise an SQLITE_CORRUPT_INDEX error if no matching index entry is found
|
|
** and not in writable_schema mode.
|
|
*/
|
|
_121:
|
|
;
|
|
pC26 = **(**uintptr)(__ccgo_up((*TVdbe)(unsafe.Pointer(p)).FapCsr + uintptr((*TOp)(unsafe.Pointer(pOp)).Fp1)*4))
|
|
pCrsr8 = *(*uintptr)(unsafe.Pointer(pC26 + 36))
|
|
(**(**TUnpackedRecord)(__ccgo_up(bp + 340))).FpKeyInfo = (*TVdbeCursor)(unsafe.Pointer(pC26)).FpKeyInfo
|
|
(**(**TUnpackedRecord)(__ccgo_up(bp + 340))).FnField = libc.Uint16FromInt32((*TOp)(unsafe.Pointer(pOp)).Fp3)
|
|
(**(**TUnpackedRecord)(__ccgo_up(bp + 340))).Fdefault_rc = 0
|
|
(**(**TUnpackedRecord)(__ccgo_up(bp + 340))).FaMem = aMem + uintptr((*TOp)(unsafe.Pointer(pOp)).Fp2)*40
|
|
rc = _sqlite3BtreeIndexMoveto(tls, pCrsr8, bp+340, bp+336)
|
|
if rc != 0 {
|
|
goto abort_due_to_error
|
|
}
|
|
if **(**int32)(__ccgo_up(bp + 336)) != 0 {
|
|
rc = _sqlite3VdbeFindIndexKey(tls, pCrsr8, *(*uintptr)(unsafe.Pointer(pOp + 16)), bp+340, bp+336, 0)
|
|
if rc != SQLITE_OK {
|
|
goto abort_due_to_error
|
|
}
|
|
if **(**int32)(__ccgo_up(bp + 336)) != 0 {
|
|
if !(_sqlite3WritableSchema(tls, db) != 0) {
|
|
rc = _sqlite3ReportError(tls, libc.Int32FromInt32(SQLITE_CORRUPT)|libc.Int32FromInt32(3)<<libc.Int32FromInt32(8), int32(103271), __ccgo_ts+6269)
|
|
goto abort_due_to_error
|
|
}
|
|
(*TVdbeCursor)(unsafe.Pointer(pC26)).FcacheStatus = uint32(CACHE_STALE)
|
|
(*TVdbeCursor)(unsafe.Pointer(pC26)).FseekResult = 0
|
|
goto _189
|
|
}
|
|
}
|
|
rc = _sqlite3BtreeDelete(tls, pCrsr8, uint8(BTREE_AUXDELETE))
|
|
if rc != 0 {
|
|
goto abort_due_to_error
|
|
}
|
|
(*TVdbeCursor)(unsafe.Pointer(pC26)).FcacheStatus = uint32(CACHE_STALE)
|
|
(*TVdbeCursor)(unsafe.Pointer(pC26)).FseekResult = 0
|
|
goto _189
|
|
/* Opcode: DeferredSeek P1 * P3 P4 *
|
|
** Synopsis: Move P3 to P1.rowid if needed
|
|
**
|
|
** P1 is an open index cursor and P3 is a cursor on the corresponding
|
|
** table. This opcode does a deferred seek of the P3 table cursor
|
|
** to the row that corresponds to the current row of P1.
|
|
**
|
|
** This is a deferred seek. Nothing actually happens until
|
|
** the cursor is used to read a record. That way, if no reads
|
|
** occur, no unnecessary I/O happens.
|
|
**
|
|
** P4 may be an array of integers (type P4_INTARRAY) containing
|
|
** one entry for each column in the P3 table. If array entry a(i)
|
|
** is non-zero, then reading column a(i)-1 from cursor P3 is
|
|
** equivalent to performing the deferred seek and then reading column i
|
|
** from P1. This information is stored in P3 and used to redirect
|
|
** reads against P3 over to P1, thus possibly avoiding the need to
|
|
** seek and read cursor P3.
|
|
*/
|
|
/* Opcode: IdxRowid P1 P2 * * *
|
|
** Synopsis: r[P2]=rowid
|
|
**
|
|
** Write into register P2 an integer which is the last entry in the record at
|
|
** the end of the index key pointed to by cursor P1. This integer should be
|
|
** the rowid of the table entry to which this index entry points.
|
|
**
|
|
** See also: Rowid, MakeRecord.
|
|
*/
|
|
_123:
|
|
; /* ncycle */
|
|
_122:
|
|
; /* Rowid that P1 current points to */
|
|
pC27 = **(**uintptr)(__ccgo_up((*TVdbe)(unsafe.Pointer(p)).FapCsr + uintptr((*TOp)(unsafe.Pointer(pOp)).Fp1)*4))
|
|
/* The IdxRowid and Seek opcodes are combined because of the commonality
|
|
** of sqlite3VdbeCursorRestore() and sqlite3VdbeIdxRowid(). */
|
|
rc = _sqlite3VdbeCursorRestore(tls, pC27)
|
|
/* sqlite3VdbeCursorRestore() may fail if the cursor has been disturbed
|
|
** since it was last positioned and an error (e.g. OOM or an IO error)
|
|
** occurs while trying to reposition it. */
|
|
if rc != SQLITE_OK {
|
|
goto abort_due_to_error
|
|
}
|
|
if !((*TVdbeCursor)(unsafe.Pointer(pC27)).FnullRow != 0) {
|
|
**(**Ti64)(__ccgo_up(bp + 368)) = 0 /* Not needed. Only used to silence a warning. */
|
|
rc = _sqlite3VdbeIdxRowid(tls, db, *(*uintptr)(unsafe.Pointer(pC27 + 36)), bp+368)
|
|
if rc != SQLITE_OK {
|
|
goto abort_due_to_error
|
|
}
|
|
if libc.Int32FromUint8((*TOp)(unsafe.Pointer(pOp)).Fopcode) == int32(OP_DeferredSeek) {
|
|
pTabCur = **(**uintptr)(__ccgo_up((*TVdbe)(unsafe.Pointer(p)).FapCsr + uintptr((*TOp)(unsafe.Pointer(pOp)).Fp3)*4))
|
|
(*TVdbeCursor)(unsafe.Pointer(pTabCur)).FnullRow = uint8(0)
|
|
(*TVdbeCursor)(unsafe.Pointer(pTabCur)).FmovetoTarget = **(**Ti64)(__ccgo_up(bp + 368))
|
|
(*TVdbeCursor)(unsafe.Pointer(pTabCur)).FdeferredMoveto = uint8(1)
|
|
(*TVdbeCursor)(unsafe.Pointer(pTabCur)).FcacheStatus = uint32(CACHE_STALE)
|
|
*(*uintptr)(unsafe.Pointer(pTabCur + 12)) = *(*uintptr)(unsafe.Pointer(pOp + 16))
|
|
(*TVdbeCursor)(unsafe.Pointer(pTabCur)).FpAltCursor = pC27
|
|
} else {
|
|
pOut = _out2Prerelease(tls, p, pOp)
|
|
*(*Ti64)(unsafe.Pointer(pOut)) = **(**Ti64)(__ccgo_up(bp + 368))
|
|
}
|
|
} else {
|
|
_sqlite3VdbeMemSetNull(tls, aMem+uintptr((*TOp)(unsafe.Pointer(pOp)).Fp2)*40)
|
|
}
|
|
goto _189
|
|
/* Opcode: FinishSeek P1 * * * *
|
|
**
|
|
** If cursor P1 was previously moved via OP_DeferredSeek, complete that
|
|
** seek operation now, without further delay. If the cursor seek has
|
|
** already occurred, this instruction is a no-op.
|
|
*/
|
|
_124:
|
|
; /* The P1 index cursor */
|
|
pC28 = **(**uintptr)(__ccgo_up((*TVdbe)(unsafe.Pointer(p)).FapCsr + uintptr((*TOp)(unsafe.Pointer(pOp)).Fp1)*4))
|
|
if (*TVdbeCursor)(unsafe.Pointer(pC28)).FdeferredMoveto != 0 {
|
|
rc = _sqlite3VdbeFinishMoveto(tls, pC28)
|
|
if rc != 0 {
|
|
goto abort_due_to_error
|
|
}
|
|
}
|
|
goto _189
|
|
/* Opcode: IdxGE P1 P2 P3 P4 *
|
|
** Synopsis: key=r[P3@P4]
|
|
**
|
|
** The P4 register values beginning with P3 form an unpacked index
|
|
** key that omits the PRIMARY KEY. Compare this key value against the index
|
|
** that P1 is currently pointing to, ignoring the PRIMARY KEY or ROWID
|
|
** fields at the end.
|
|
**
|
|
** If the P1 index entry is greater than or equal to the key value
|
|
** then jump to P2. Otherwise fall through to the next instruction.
|
|
*/
|
|
/* Opcode: IdxGT P1 P2 P3 P4 *
|
|
** Synopsis: key=r[P3@P4]
|
|
**
|
|
** The P4 register values beginning with P3 form an unpacked index
|
|
** key that omits the PRIMARY KEY. Compare this key value against the index
|
|
** that P1 is currently pointing to, ignoring the PRIMARY KEY or ROWID
|
|
** fields at the end.
|
|
**
|
|
** If the P1 index entry is greater than the key value
|
|
** then jump to P2. Otherwise fall through to the next instruction.
|
|
*/
|
|
/* Opcode: IdxLT P1 P2 P3 P4 *
|
|
** Synopsis: key=r[P3@P4]
|
|
**
|
|
** The P4 register values beginning with P3 form an unpacked index
|
|
** key that omits the PRIMARY KEY or ROWID. Compare this key value against
|
|
** the index that P1 is currently pointing to, ignoring the PRIMARY KEY or
|
|
** ROWID on the P1 index.
|
|
**
|
|
** If the P1 index entry is less than the key value then jump to P2.
|
|
** Otherwise fall through to the next instruction.
|
|
*/
|
|
/* Opcode: IdxLE P1 P2 P3 P4 *
|
|
** Synopsis: key=r[P3@P4]
|
|
**
|
|
** The P4 register values beginning with P3 form an unpacked index
|
|
** key that omits the PRIMARY KEY or ROWID. Compare this key value against
|
|
** the index that P1 is currently pointing to, ignoring the PRIMARY KEY or
|
|
** ROWID on the P1 index.
|
|
**
|
|
** If the P1 index entry is less than or equal to the key value then jump
|
|
** to P2. Otherwise fall through to the next instruction.
|
|
*/
|
|
_128:
|
|
; /* jump, ncycle */
|
|
_127:
|
|
; /* jump, ncycle */
|
|
_126:
|
|
; /* jump, ncycle */
|
|
_125:
|
|
;
|
|
pC29 = **(**uintptr)(__ccgo_up((*TVdbe)(unsafe.Pointer(p)).FapCsr + uintptr((*TOp)(unsafe.Pointer(pOp)).Fp1)*4))
|
|
(**(**TUnpackedRecord)(__ccgo_up(bp + 376))).FpKeyInfo = (*TVdbeCursor)(unsafe.Pointer(pC29)).FpKeyInfo
|
|
(**(**TUnpackedRecord)(__ccgo_up(bp + 376))).FnField = libc.Uint16FromInt32(*(*int32)(unsafe.Pointer(pOp + 16)))
|
|
if libc.Int32FromUint8((*TOp)(unsafe.Pointer(pOp)).Fopcode) < int32(OP_IdxLT) {
|
|
(**(**TUnpackedRecord)(__ccgo_up(bp + 376))).Fdefault_rc = int8(-int32(1))
|
|
} else {
|
|
(**(**TUnpackedRecord)(__ccgo_up(bp + 376))).Fdefault_rc = 0
|
|
}
|
|
(**(**TUnpackedRecord)(__ccgo_up(bp + 376))).FaMem = aMem + uintptr((*TOp)(unsafe.Pointer(pOp)).Fp3)*40
|
|
/* Inlined version of sqlite3VdbeIdxKeyCompare() */
|
|
nCellKey = 0
|
|
pCur2 = *(*uintptr)(unsafe.Pointer(pC29 + 36))
|
|
nCellKey = libc.Int64FromUint32(_sqlite3BtreePayloadSize(tls, pCur2))
|
|
/* nCellKey will always be between 0 and 0xffffffff because of the way
|
|
** that btreeParseCellPtr() and sqlite3GetVarint32() are implemented */
|
|
if nCellKey <= 0 || nCellKey > int64(0x7fffffff) {
|
|
rc = _sqlite3CorruptError(tls, int32(103483))
|
|
goto abort_due_to_error
|
|
}
|
|
_sqlite3VdbeMemInit(tls, bp+404, db, uint16(0))
|
|
rc = _sqlite3VdbeMemFromBtreeZeroOffset(tls, pCur2, libc.Uint32FromInt64(nCellKey), bp+404)
|
|
if rc != 0 {
|
|
goto abort_due_to_error
|
|
}
|
|
res11 = _sqlite3VdbeRecordCompareWithSkip(tls, (**(**TMem)(__ccgo_up(bp + 404))).Fn, (**(**TMem)(__ccgo_up(bp + 404))).Fz, bp+376, 0)
|
|
_sqlite3VdbeMemReleaseMalloc(tls, bp+404)
|
|
/* End of inlined sqlite3VdbeIdxKeyCompare() */
|
|
if libc.Int32FromUint8((*TOp)(unsafe.Pointer(pOp)).Fopcode)&int32(1) == libc.Int32FromInt32(OP_IdxLT)&libc.Int32FromInt32(1) {
|
|
res11 = -res11
|
|
} else {
|
|
res11 = res11 + 1
|
|
}
|
|
if res11 > 0 {
|
|
goto jump_to_p2
|
|
}
|
|
goto _189
|
|
/* Opcode: Destroy P1 P2 P3 * *
|
|
**
|
|
** Delete an entire database table or index whose root page in the database
|
|
** file is given by P1.
|
|
**
|
|
** The table being destroyed is in the main database file if P3==0. If
|
|
** P3==1 then the table to be destroyed is in the auxiliary database file
|
|
** that is used to store tables create using CREATE TEMPORARY TABLE.
|
|
**
|
|
** If AUTOVACUUM is enabled then it is possible that another root page
|
|
** might be moved into the newly deleted root page in order to keep all
|
|
** root pages contiguous at the beginning of the database. The former
|
|
** value of the root page that moved - its value before the move occurred -
|
|
** is stored in register P2. If no page movement was required (because the
|
|
** table being dropped was already the last one in the database) then a
|
|
** zero is stored in register P2. If AUTOVACUUM is disabled then a zero
|
|
** is stored in register P2.
|
|
**
|
|
** This opcode throws an error if there are any active reader VMs when
|
|
** it is invoked. This is done to avoid the difficulty associated with
|
|
** updating existing cursors when a root page is moved in an AUTOVACUUM
|
|
** database. This error is thrown even if the database is not an AUTOVACUUM
|
|
** db in order to avoid introducing an incompatibility between autovacuum
|
|
** and non-autovacuum modes.
|
|
**
|
|
** See also: Clear
|
|
*/
|
|
_129:
|
|
;
|
|
pOut = _out2Prerelease(tls, p, pOp)
|
|
(*TMem)(unsafe.Pointer(pOut)).Fflags = uint16(MEM_Null)
|
|
if (*Tsqlite3)(unsafe.Pointer(db)).FnVdbeRead > (*Tsqlite3)(unsafe.Pointer(db)).FnVDestroy+int32(1) {
|
|
rc = int32(SQLITE_LOCKED)
|
|
(*TVdbe)(unsafe.Pointer(p)).FerrorAction = uint8(OE_Abort)
|
|
goto abort_due_to_error
|
|
} else {
|
|
iDb2 = (*TOp)(unsafe.Pointer(pOp)).Fp3
|
|
**(**int32)(__ccgo_up(bp + 444)) = 0 /* Not needed. Only to silence a warning. */
|
|
rc = _sqlite3BtreeDropTable(tls, (**(**TDb)(__ccgo_up((*Tsqlite3)(unsafe.Pointer(db)).FaDb + uintptr(iDb2)*16))).FpBt, (*TOp)(unsafe.Pointer(pOp)).Fp1, bp+444)
|
|
(*TMem)(unsafe.Pointer(pOut)).Fflags = uint16(MEM_Int)
|
|
*(*Ti64)(unsafe.Pointer(pOut)) = int64(**(**int32)(__ccgo_up(bp + 444)))
|
|
if rc != 0 {
|
|
goto abort_due_to_error
|
|
}
|
|
if **(**int32)(__ccgo_up(bp + 444)) != 0 {
|
|
_sqlite3RootPageMoved(tls, db, iDb2, libc.Uint32FromInt32(**(**int32)(__ccgo_up(bp + 444))), libc.Uint32FromInt32((*TOp)(unsafe.Pointer(pOp)).Fp1))
|
|
/* All OP_Destroy operations occur on the same btree */
|
|
resetSchemaOnFault = libc.Uint8FromInt32(iDb2 + int32(1))
|
|
}
|
|
}
|
|
goto _189
|
|
/* Opcode: Clear P1 P2 P3
|
|
**
|
|
** Delete all contents of the database table or index whose root page
|
|
** in the database file is given by P1. But, unlike Destroy, do not
|
|
** remove the table or index from the database file.
|
|
**
|
|
** The table being cleared is in the main database file if P2==0. If
|
|
** P2==1 then the table to be cleared is in the auxiliary database file
|
|
** that is used to store tables create using CREATE TEMPORARY TABLE.
|
|
**
|
|
** If the P3 value is non-zero, then the row change count is incremented
|
|
** by the number of rows in the table being cleared. If P3 is greater
|
|
** than zero, then the value stored in register P3 is also incremented
|
|
** by the number of rows in the table being cleared.
|
|
**
|
|
** See also: Destroy
|
|
*/
|
|
_130:
|
|
;
|
|
**(**Ti64)(__ccgo_up(bp + 448)) = 0
|
|
rc = _sqlite3BtreeClearTable(tls, (**(**TDb)(__ccgo_up((*Tsqlite3)(unsafe.Pointer(db)).FaDb + uintptr((*TOp)(unsafe.Pointer(pOp)).Fp2)*16))).FpBt, libc.Int32FromUint32(libc.Uint32FromInt32((*TOp)(unsafe.Pointer(pOp)).Fp1)), bp+448)
|
|
if (*TOp)(unsafe.Pointer(pOp)).Fp3 != 0 {
|
|
**(**Ti64)(__ccgo_up(p + 40)) += **(**Ti64)(__ccgo_up(bp + 448))
|
|
if (*TOp)(unsafe.Pointer(pOp)).Fp3 > 0 {
|
|
*(*Ti64)(unsafe.Pointer(aMem + uintptr((*TOp)(unsafe.Pointer(pOp)).Fp3)*40)) += **(**Ti64)(__ccgo_up(bp + 448))
|
|
}
|
|
}
|
|
if rc != 0 {
|
|
goto abort_due_to_error
|
|
}
|
|
goto _189
|
|
/* Opcode: ResetSorter P1 * * * *
|
|
**
|
|
** Delete all contents from the ephemeral table or sorter
|
|
** that is open on cursor P1.
|
|
**
|
|
** This opcode only works for cursors used for sorting and
|
|
** opened with OP_OpenEphemeral or OP_SorterOpen.
|
|
*/
|
|
_131:
|
|
;
|
|
pC30 = **(**uintptr)(__ccgo_up((*TVdbe)(unsafe.Pointer(p)).FapCsr + uintptr((*TOp)(unsafe.Pointer(pOp)).Fp1)*4))
|
|
if libc.Int32FromUint8((*TVdbeCursor)(unsafe.Pointer(pC30)).FeCurType) == int32(CURTYPE_SORTER) {
|
|
_sqlite3VdbeSorterReset(tls, db, *(*uintptr)(unsafe.Pointer(pC30 + 36)))
|
|
} else {
|
|
rc = _sqlite3BtreeClearTableOfCursor(tls, *(*uintptr)(unsafe.Pointer(pC30 + 36)))
|
|
if rc != 0 {
|
|
goto abort_due_to_error
|
|
}
|
|
}
|
|
goto _189
|
|
/* Opcode: CreateBtree P1 P2 P3 * *
|
|
** Synopsis: r[P2]=root iDb=P1 flags=P3
|
|
**
|
|
** Allocate a new b-tree in the main database file if P1==0 or in the
|
|
** TEMP database file if P1==1 or in an attached database if
|
|
** P1>1. The P3 argument must be 1 (BTREE_INTKEY) for a rowid table
|
|
** it must be 2 (BTREE_BLOBKEY) for an index or WITHOUT ROWID table.
|
|
** The root page number of the new b-tree is stored in register P2.
|
|
*/
|
|
_132:
|
|
;
|
|
pOut = _out2Prerelease(tls, p, pOp)
|
|
**(**TPgno)(__ccgo_up(bp + 456)) = uint32(0)
|
|
pDb3 = (*Tsqlite3)(unsafe.Pointer(db)).FaDb + uintptr((*TOp)(unsafe.Pointer(pOp)).Fp1)*16
|
|
rc = _sqlite3BtreeCreateTable(tls, (*TDb)(unsafe.Pointer(pDb3)).FpBt, bp+456, (*TOp)(unsafe.Pointer(pOp)).Fp3)
|
|
if rc != 0 {
|
|
goto abort_due_to_error
|
|
}
|
|
*(*Ti64)(unsafe.Pointer(pOut)) = libc.Int64FromUint32(**(**TPgno)(__ccgo_up(bp + 456)))
|
|
goto _189
|
|
/* Opcode: SqlExec P1 P2 * P4 *
|
|
**
|
|
** Run the SQL statement or statements specified in the P4 string.
|
|
**
|
|
** The P1 parameter is a bitmask of options:
|
|
**
|
|
** 0x0001 Disable Auth and Trace callbacks while the statements
|
|
** in P4 are running.
|
|
**
|
|
** 0x0002 Set db->nAnalysisLimit to P2 while the statements in
|
|
** P4 are running.
|
|
**
|
|
*/
|
|
_133:
|
|
;
|
|
(*Tsqlite3)(unsafe.Pointer(db)).FnSqlExec = (*Tsqlite3)(unsafe.Pointer(db)).FnSqlExec + 1
|
|
**(**uintptr)(__ccgo_up(bp + 460)) = uintptr(0)
|
|
xAuth = (*Tsqlite3)(unsafe.Pointer(db)).FxAuth
|
|
mTrace = (*Tsqlite3)(unsafe.Pointer(db)).FmTrace
|
|
savedAnalysisLimit = (*Tsqlite3)(unsafe.Pointer(db)).FnAnalysisLimit
|
|
if (*TOp)(unsafe.Pointer(pOp)).Fp1&int32(0x0001) != 0 {
|
|
(*Tsqlite3)(unsafe.Pointer(db)).FxAuth = uintptr(0)
|
|
(*Tsqlite3)(unsafe.Pointer(db)).FmTrace = uint8(0)
|
|
}
|
|
if (*TOp)(unsafe.Pointer(pOp)).Fp1&int32(0x0002) != 0 {
|
|
(*Tsqlite3)(unsafe.Pointer(db)).FnAnalysisLimit = (*TOp)(unsafe.Pointer(pOp)).Fp2
|
|
}
|
|
rc = Xsqlite3_exec(tls, db, *(*uintptr)(unsafe.Pointer(pOp + 16)), uintptr(0), uintptr(0), bp+460)
|
|
(*Tsqlite3)(unsafe.Pointer(db)).FnSqlExec = (*Tsqlite3)(unsafe.Pointer(db)).FnSqlExec - 1
|
|
(*Tsqlite3)(unsafe.Pointer(db)).FxAuth = xAuth
|
|
(*Tsqlite3)(unsafe.Pointer(db)).FmTrace = mTrace
|
|
(*Tsqlite3)(unsafe.Pointer(db)).FnAnalysisLimit = savedAnalysisLimit
|
|
if **(**uintptr)(__ccgo_up(bp + 460)) != 0 || rc != 0 {
|
|
_sqlite3VdbeError(tls, p, __ccgo_ts+3942, libc.VaList(bp+696, **(**uintptr)(__ccgo_up(bp + 460))))
|
|
Xsqlite3_free(tls, **(**uintptr)(__ccgo_up(bp + 460)))
|
|
if rc == int32(SQLITE_NOMEM) {
|
|
goto no_mem
|
|
}
|
|
goto abort_due_to_error
|
|
}
|
|
goto _189
|
|
/* Opcode: ParseSchema P1 * * P4 *
|
|
**
|
|
** Read and parse all entries from the schema table of database P1
|
|
** that match the WHERE clause P4. If P4 is a NULL pointer, then the
|
|
** entire schema for P1 is reparsed.
|
|
**
|
|
** This opcode invokes the parser to create a new virtual machine,
|
|
** then runs the new virtual machine. It is thus a re-entrant opcode.
|
|
*/
|
|
_134:
|
|
;
|
|
/* Any prepared statement that invokes this opcode will hold mutexes
|
|
** on every btree. This is a prerequisite for invoking
|
|
** sqlite3InitCallback().
|
|
*/
|
|
iDb3 = (*TOp)(unsafe.Pointer(pOp)).Fp1
|
|
if *(*uintptr)(unsafe.Pointer(pOp + 16)) == uintptr(0) {
|
|
_sqlite3SchemaClear(tls, (**(**TDb)(__ccgo_up((*Tsqlite3)(unsafe.Pointer(db)).FaDb + uintptr(iDb3)*16))).FpSchema)
|
|
**(**Tu32)(__ccgo_up(db + 24)) &= libc.Uint32FromInt32(^libc.Int32FromInt32(DBFLAG_SchemaKnownOk))
|
|
rc = _sqlite3InitOne(tls, db, iDb3, p+120, uint32((*TOp)(unsafe.Pointer(pOp)).Fp5))
|
|
**(**Tu32)(__ccgo_up(db + 24)) |= uint32(DBFLAG_SchemaChange)
|
|
libc.SetBitFieldPtr16Uint32(p+144, libc.Uint32FromInt32(0), 0, 0x3)
|
|
} else {
|
|
zSchema = __ccgo_ts + 6286
|
|
(**(**TInitData)(__ccgo_up(bp + 464))).Fdb = db
|
|
(**(**TInitData)(__ccgo_up(bp + 464))).FiDb = iDb3
|
|
(**(**TInitData)(__ccgo_up(bp + 464))).FpzErrMsg = p + 120
|
|
(**(**TInitData)(__ccgo_up(bp + 464))).FmInitFlags = uint32(0)
|
|
(**(**TInitData)(__ccgo_up(bp + 464))).FmxPage = _sqlite3BtreeLastPage(tls, (**(**TDb)(__ccgo_up((*Tsqlite3)(unsafe.Pointer(db)).FaDb + uintptr(iDb3)*16))).FpBt)
|
|
zSql = _sqlite3MPrintf(tls, db, __ccgo_ts+6300, libc.VaList(bp+696, (**(**TDb)(__ccgo_up((*Tsqlite3)(unsafe.Pointer(db)).FaDb + uintptr(iDb3)*16))).FzDbSName, zSchema, *(*uintptr)(unsafe.Pointer(pOp + 16))))
|
|
if zSql == uintptr(0) {
|
|
rc = int32(SQLITE_NOMEM)
|
|
} else {
|
|
(*Tsqlite3)(unsafe.Pointer(db)).Finit1.Fbusy = uint8(1)
|
|
(**(**TInitData)(__ccgo_up(bp + 464))).Frc = SQLITE_OK
|
|
(**(**TInitData)(__ccgo_up(bp + 464))).FnInitRow = uint32(0)
|
|
rc = Xsqlite3_exec(tls, db, zSql, __ccgo_fp(_sqlite3InitCallback), bp+464, uintptr(0))
|
|
if rc == SQLITE_OK {
|
|
rc = (**(**TInitData)(__ccgo_up(bp + 464))).Frc
|
|
}
|
|
if rc == SQLITE_OK && (**(**TInitData)(__ccgo_up(bp + 464))).FnInitRow == uint32(0) {
|
|
/* The OP_ParseSchema opcode with a non-NULL P4 argument should parse
|
|
** at least one SQL statement. Any less than that indicates that
|
|
** the sqlite_schema table is corrupt. */
|
|
rc = _sqlite3CorruptError(tls, int32(103776))
|
|
}
|
|
_sqlite3DbFreeNN(tls, db, zSql)
|
|
(*Tsqlite3)(unsafe.Pointer(db)).Finit1.Fbusy = uint8(0)
|
|
}
|
|
}
|
|
if rc != 0 {
|
|
_sqlite3ResetAllSchemasOfConnection(tls, db)
|
|
if rc == int32(SQLITE_NOMEM) {
|
|
goto no_mem
|
|
}
|
|
goto abort_due_to_error
|
|
}
|
|
goto _189
|
|
/* Opcode: LoadAnalysis P1 * * * *
|
|
**
|
|
** Read the sqlite_stat1 table for database P1 and load the content
|
|
** of that table into the internal index hash table. This will cause
|
|
** the analysis to be used when preparing all subsequent queries.
|
|
*/
|
|
_135:
|
|
;
|
|
rc = _sqlite3AnalysisLoad(tls, db, (*TOp)(unsafe.Pointer(pOp)).Fp1)
|
|
if rc != 0 {
|
|
goto abort_due_to_error
|
|
}
|
|
goto _189
|
|
/* Opcode: DropTable P1 * * P4 *
|
|
**
|
|
** Remove the internal (in-memory) data structures that describe
|
|
** the table named P4 in database P1. This is called after a table
|
|
** is dropped from disk (using the Destroy opcode) in order to keep
|
|
** the internal representation of the
|
|
** schema consistent with what is on disk.
|
|
*/
|
|
_136:
|
|
;
|
|
_sqlite3UnlinkAndDeleteTable(tls, db, (*TOp)(unsafe.Pointer(pOp)).Fp1, *(*uintptr)(unsafe.Pointer(pOp + 16)))
|
|
goto _189
|
|
/* Opcode: DropIndex P1 * * P4 *
|
|
**
|
|
** Remove the internal (in-memory) data structures that describe
|
|
** the index named P4 in database P1. This is called after an index
|
|
** is dropped from disk (using the Destroy opcode)
|
|
** in order to keep the internal representation of the
|
|
** schema consistent with what is on disk.
|
|
*/
|
|
_137:
|
|
;
|
|
_sqlite3UnlinkAndDeleteIndex(tls, db, (*TOp)(unsafe.Pointer(pOp)).Fp1, *(*uintptr)(unsafe.Pointer(pOp + 16)))
|
|
goto _189
|
|
/* Opcode: DropTrigger P1 * * P4 *
|
|
**
|
|
** Remove the internal (in-memory) data structures that describe
|
|
** the trigger named P4 in database P1. This is called after a trigger
|
|
** is dropped from disk (using the Destroy opcode) in order to keep
|
|
** the internal representation of the
|
|
** schema consistent with what is on disk.
|
|
*/
|
|
_138:
|
|
;
|
|
_sqlite3UnlinkAndDeleteTrigger(tls, db, (*TOp)(unsafe.Pointer(pOp)).Fp1, *(*uintptr)(unsafe.Pointer(pOp + 16)))
|
|
goto _189
|
|
/* Opcode: IntegrityCk P1 P2 P3 P4 P5
|
|
**
|
|
** Do an analysis of the currently open database. Store in
|
|
** register (P1+1) the text of an error message describing any problems.
|
|
** If no problems are found, store a NULL in register (P1+1).
|
|
**
|
|
** The register (P1) contains one less than the maximum number of allowed
|
|
** errors. At most reg(P1) errors will be reported.
|
|
** In other words, the analysis stops as soon as reg(P1) errors are
|
|
** seen. Reg(P1) is updated with the number of errors remaining.
|
|
**
|
|
** The root page numbers of all tables in the database are integers
|
|
** stored in P4_INTARRAY argument.
|
|
**
|
|
** If P5 is not zero, the check is done on the auxiliary database
|
|
** file, not the main database file.
|
|
**
|
|
** This opcode is used to implement the integrity_check pragma.
|
|
*/
|
|
_139:
|
|
; /* Register keeping track of errors remaining */
|
|
nRoot = (*TOp)(unsafe.Pointer(pOp)).Fp2
|
|
aRoot = *(*uintptr)(unsafe.Pointer(pOp + 16))
|
|
pnErr = aMem + uintptr((*TOp)(unsafe.Pointer(pOp)).Fp1)*40
|
|
pIn1 = aMem + uintptr((*TOp)(unsafe.Pointer(pOp)).Fp1+int32(1))*40
|
|
rc = _sqlite3BtreeIntegrityCheck(tls, db, (**(**TDb)(__ccgo_up((*Tsqlite3)(unsafe.Pointer(db)).FaDb + uintptr((*TOp)(unsafe.Pointer(pOp)).Fp5)*16))).FpBt, aRoot+1*4, aMem+uintptr((*TOp)(unsafe.Pointer(pOp)).Fp3)*40, nRoot, int32(*(*Ti64)(unsafe.Pointer(pnErr)))+int32(1), bp+492, bp+496)
|
|
_sqlite3VdbeMemSetNull(tls, pIn1)
|
|
if **(**int32)(__ccgo_up(bp + 492)) == 0 {
|
|
} else {
|
|
if rc != 0 {
|
|
Xsqlite3_free(tls, **(**uintptr)(__ccgo_up(bp + 496)))
|
|
goto abort_due_to_error
|
|
} else {
|
|
*(*Ti64)(unsafe.Pointer(pnErr)) -= int64(**(**int32)(__ccgo_up(bp + 492)) - int32(1))
|
|
_sqlite3VdbeMemSetStr(tls, pIn1, **(**uintptr)(__ccgo_up(bp + 496)), int64(-int32(1)), uint8(SQLITE_UTF8), __ccgo_fp(Xsqlite3_free))
|
|
}
|
|
}
|
|
_sqlite3VdbeChangeEncoding(tls, pIn1, libc.Int32FromUint8(encoding))
|
|
goto check_for_interrupt
|
|
/* Opcode: IFindKey P1 P2 P3 P4 *
|
|
**
|
|
** This instruction always follows an OP_Found with the same P1, P2 and P3
|
|
** values as this instruction and a non-zero P4 value. The P4 value to
|
|
** this opcode is of type P4_INDEX and contains a pointer to the Index
|
|
** object of for the index being searched.
|
|
**
|
|
** This opcode uses sqlite3VdbeFindIndexKey() to search around the current
|
|
** cursor location for an index key that exactly matches all fields that
|
|
** are not indexed expressions or references to VIRTUAL generated columns,
|
|
** and either exactly match or are real numbers that are within 2 ULPs of
|
|
** each other if the don't match.
|
|
**
|
|
** To put it another way, this opcode looks for nearby index entries that
|
|
** are very close to the search key, but which might have small differences
|
|
** in floating-point values that come via an expression.
|
|
**
|
|
** If no nearby alternative entry is found in cursor P1, then jump to P2.
|
|
** But if a close match is found, fall through.
|
|
**
|
|
** This opcode is used by PRAGMA integrity_check to help distinguish
|
|
** between truely corrupt indexes and expression indexes that are holding
|
|
** floating-point values that are off by one or two ULPs.
|
|
*/
|
|
_140:
|
|
;
|
|
pC31 = **(**uintptr)(__ccgo_up((*TVdbe)(unsafe.Pointer(p)).FapCsr + uintptr((*TOp)(unsafe.Pointer(pOp)).Fp1)*4))
|
|
libc.Xmemset(tls, bp+504, 0, uint32(28))
|
|
(**(**TUnpackedRecord)(__ccgo_up(bp + 504))).FaMem = aMem + uintptr((*TOp)(unsafe.Pointer(pOp)).Fp3)*40
|
|
(**(**TUnpackedRecord)(__ccgo_up(bp + 504))).FnField = (*TIndex)(unsafe.Pointer(*(*uintptr)(unsafe.Pointer(pOp + 16)))).FnColumn
|
|
(**(**TUnpackedRecord)(__ccgo_up(bp + 504))).FpKeyInfo = (*TVdbeCursor)(unsafe.Pointer(pC31)).FpKeyInfo
|
|
rc = _sqlite3VdbeFindIndexKey(tls, *(*uintptr)(unsafe.Pointer(pC31 + 36)), *(*uintptr)(unsafe.Pointer(pOp + 16)), bp+504, bp+500, int32(1))
|
|
if rc != 0 || **(**int32)(__ccgo_up(bp + 500)) != 0 {
|
|
rc = SQLITE_OK
|
|
goto jump_to_p2
|
|
}
|
|
(*TVdbeCursor)(unsafe.Pointer(pC31)).FnullRow = uint8(0)
|
|
goto _189
|
|
/* Opcode: RowSetAdd P1 P2 * * *
|
|
** Synopsis: rowset(P1)=r[P2]
|
|
**
|
|
** Insert the integer value held by register P2 into a RowSet object
|
|
** held in register P1.
|
|
**
|
|
** An assertion fails if P2 is not an integer.
|
|
*/
|
|
_141:
|
|
; /* in1, in2 */
|
|
pIn1 = aMem + uintptr((*TOp)(unsafe.Pointer(pOp)).Fp1)*40
|
|
pIn2 = aMem + uintptr((*TOp)(unsafe.Pointer(pOp)).Fp2)*40
|
|
if libc.Int32FromUint16((*TMem)(unsafe.Pointer(pIn1)).Fflags)&int32(MEM_Blob) == 0 {
|
|
if _sqlite3VdbeMemSetRowSet(tls, pIn1) != 0 {
|
|
goto no_mem
|
|
}
|
|
}
|
|
_sqlite3RowSetInsert(tls, (*TMem)(unsafe.Pointer(pIn1)).Fz, *(*Ti64)(unsafe.Pointer(pIn2)))
|
|
goto _189
|
|
/* Opcode: RowSetRead P1 P2 P3 * *
|
|
** Synopsis: r[P3]=rowset(P1)
|
|
**
|
|
** Extract the smallest value from the RowSet object in P1
|
|
** and put that value into register P3.
|
|
** Or, if RowSet object P1 is initially empty, leave P3
|
|
** unchanged and jump to instruction P2.
|
|
*/
|
|
_142:
|
|
;
|
|
pIn1 = aMem + uintptr((*TOp)(unsafe.Pointer(pOp)).Fp1)*40
|
|
if libc.Int32FromUint16((*TMem)(unsafe.Pointer(pIn1)).Fflags)&int32(MEM_Blob) == 0 || _sqlite3RowSetNext(tls, (*TMem)(unsafe.Pointer(pIn1)).Fz, bp+536) == 0 {
|
|
/* The boolean index is empty */
|
|
_sqlite3VdbeMemSetNull(tls, pIn1)
|
|
goto jump_to_p2_and_check_for_interrupt
|
|
} else {
|
|
/* A value was pulled from the index */
|
|
_sqlite3VdbeMemSetInt64(tls, aMem+uintptr((*TOp)(unsafe.Pointer(pOp)).Fp3)*40, **(**Ti64)(__ccgo_up(bp + 536)))
|
|
}
|
|
goto check_for_interrupt
|
|
/* Opcode: RowSetTest P1 P2 P3 P4
|
|
** Synopsis: if r[P3] in rowset(P1) goto P2
|
|
**
|
|
** Register P3 is assumed to hold a 64-bit integer value. If register P1
|
|
** contains a RowSet object and that RowSet object contains
|
|
** the value held in P3, jump to register P2. Otherwise, insert the
|
|
** integer in P3 into the RowSet and continue on to the
|
|
** next opcode.
|
|
**
|
|
** The RowSet object is optimized for the case where sets of integers
|
|
** are inserted in distinct phases, which each set contains no duplicates.
|
|
** Each set is identified by a unique P4 value. The first set
|
|
** must have P4==0, the final set must have P4==-1, and for all other sets
|
|
** must have P4>0.
|
|
**
|
|
** This allows optimizations: (a) when P4==0 there is no need to test
|
|
** the RowSet object for P3, as it is guaranteed not to contain it,
|
|
** (b) when P4==-1 there is no need to insert the value, as it will
|
|
** never be tested for, and (c) when a value that is part of set X is
|
|
** inserted, there is no need to search to see if the same value was
|
|
** previously inserted as part of set X (only if it was previously
|
|
** inserted as part of some other set).
|
|
*/
|
|
_143:
|
|
;
|
|
pIn1 = aMem + uintptr((*TOp)(unsafe.Pointer(pOp)).Fp1)*40
|
|
pIn3 = aMem + uintptr((*TOp)(unsafe.Pointer(pOp)).Fp3)*40
|
|
iSet = *(*int32)(unsafe.Pointer(pOp + 16))
|
|
/* If there is anything other than a rowset object in memory cell P1,
|
|
** delete it now and initialize P1 with an empty rowset
|
|
*/
|
|
if libc.Int32FromUint16((*TMem)(unsafe.Pointer(pIn1)).Fflags)&int32(MEM_Blob) == 0 {
|
|
if _sqlite3VdbeMemSetRowSet(tls, pIn1) != 0 {
|
|
goto no_mem
|
|
}
|
|
}
|
|
if iSet != 0 {
|
|
exists = _sqlite3RowSetTest(tls, (*TMem)(unsafe.Pointer(pIn1)).Fz, iSet, *(*Ti64)(unsafe.Pointer(pIn3)))
|
|
if exists != 0 {
|
|
goto jump_to_p2
|
|
}
|
|
}
|
|
if iSet >= 0 {
|
|
_sqlite3RowSetInsert(tls, (*TMem)(unsafe.Pointer(pIn1)).Fz, *(*Ti64)(unsafe.Pointer(pIn3)))
|
|
}
|
|
goto _189
|
|
/* Opcode: Program P1 P2 P3 P4 P5
|
|
**
|
|
** Execute the trigger program passed as P4 (type P4_SUBPROGRAM).
|
|
**
|
|
** P1 contains the address of the memory cell that contains the first memory
|
|
** cell in an array of values used as arguments to the sub-program. P2
|
|
** contains the address to jump to if the sub-program throws an IGNORE
|
|
** exception using the RAISE() function. P2 might be zero, if there is
|
|
** no possibility that an IGNORE exception will be raised.
|
|
** Register P3 contains the address
|
|
** of a memory cell in this (the parent) VM that is used to allocate the
|
|
** memory required by the sub-vdbe at runtime.
|
|
**
|
|
** P4 is a pointer to the VM containing the trigger program.
|
|
**
|
|
** If P5 is non-zero, then recursive program invocation is enabled.
|
|
*/
|
|
_144:
|
|
; /* Token identifying trigger */
|
|
pProgram = *(*uintptr)(unsafe.Pointer(pOp + 16))
|
|
pRt = aMem + uintptr((*TOp)(unsafe.Pointer(pOp)).Fp3)*40
|
|
/* If the p5 flag is clear, then recursive invocation of triggers is
|
|
** disabled for backwards compatibility (p5 is set if this sub-program
|
|
** is really a trigger, not a foreign key action, and the flag set
|
|
** and cleared by the "PRAGMA recursive_triggers" command is clear).
|
|
**
|
|
** It is recursive invocation of triggers, at the SQL level, that is
|
|
** disabled. In some cases a single trigger may generate more than one
|
|
** SubProgram (if the trigger may be executed with more than one different
|
|
** ON CONFLICT algorithm). SubProgram structures associated with a
|
|
** single trigger all have the same value for the SubProgram.token
|
|
** variable. */
|
|
if (*TOp)(unsafe.Pointer(pOp)).Fp5 != 0 {
|
|
t1 = (*TSubProgram)(unsafe.Pointer(pProgram)).Ftoken
|
|
pFrame2 = (*TVdbe)(unsafe.Pointer(p)).FpFrame
|
|
for {
|
|
if !(pFrame2 != 0 && (*TVdbeFrame)(unsafe.Pointer(pFrame2)).Ftoken != t1) {
|
|
break
|
|
}
|
|
goto _278
|
|
_278:
|
|
;
|
|
pFrame2 = (*TVdbeFrame)(unsafe.Pointer(pFrame2)).FpParent
|
|
}
|
|
if pFrame2 != 0 {
|
|
goto _189
|
|
}
|
|
}
|
|
if (*TVdbe)(unsafe.Pointer(p)).FnFrame >= **(**int32)(__ccgo_up(db + 116 + 10*4)) {
|
|
rc = int32(SQLITE_ERROR)
|
|
_sqlite3VdbeError(tls, p, __ccgo_ts+6343, 0)
|
|
goto abort_due_to_error
|
|
}
|
|
/* Register pRt is used to store the memory required to save the state
|
|
** of the current program, and the memory required at runtime to execute
|
|
** the trigger program. If this trigger has been fired before, then pRt
|
|
** is already allocated. Otherwise, it must be initialized. */
|
|
if libc.Int32FromUint16((*TMem)(unsafe.Pointer(pRt)).Fflags)&int32(MEM_Blob) == 0 {
|
|
/* SubProgram.nMem is set to the number of memory cells used by the
|
|
** program stored in SubProgram.aOp. As well as these, one memory
|
|
** cell is required for each cursor used by the program. Set local
|
|
** variable nMem (and later, VdbeFrame.nChildMem) to this value.
|
|
*/
|
|
nMem = (*TSubProgram)(unsafe.Pointer(pProgram)).FnMem + (*TSubProgram)(unsafe.Pointer(pProgram)).FnCsr
|
|
if (*TSubProgram)(unsafe.Pointer(pProgram)).FnCsr == 0 {
|
|
nMem = nMem + 1
|
|
}
|
|
nByte2 = libc.Int64FromUint32((libc.Uint32FromInt64(80)+libc.Uint32FromInt32(7))&libc.Uint32FromInt32(^libc.Int32FromInt32(7))+libc.Uint32FromInt32(nMem)*uint32(40)+libc.Uint32FromInt32((*TSubProgram)(unsafe.Pointer(pProgram)).FnCsr)*uint32(4)) + (int64(7)+int64((*TSubProgram)(unsafe.Pointer(pProgram)).FnOp))/int64(8)
|
|
pFrame2 = _sqlite3DbMallocZero(tls, db, libc.Uint64FromInt64(nByte2))
|
|
if !(pFrame2 != 0) {
|
|
goto no_mem
|
|
}
|
|
_sqlite3VdbeMemRelease(tls, pRt)
|
|
(*TMem)(unsafe.Pointer(pRt)).Fflags = libc.Uint16FromInt32(libc.Int32FromInt32(MEM_Blob) | libc.Int32FromInt32(MEM_Dyn))
|
|
(*TMem)(unsafe.Pointer(pRt)).Fz = pFrame2
|
|
(*TMem)(unsafe.Pointer(pRt)).Fn = int32(nByte2)
|
|
(*TMem)(unsafe.Pointer(pRt)).FxDel = __ccgo_fp(_sqlite3VdbeFrameMemDel)
|
|
(*TVdbeFrame)(unsafe.Pointer(pFrame2)).Fv = p
|
|
(*TVdbeFrame)(unsafe.Pointer(pFrame2)).FnChildMem = nMem
|
|
(*TVdbeFrame)(unsafe.Pointer(pFrame2)).FnChildCsr = (*TSubProgram)(unsafe.Pointer(pProgram)).FnCsr
|
|
(*TVdbeFrame)(unsafe.Pointer(pFrame2)).Fpc = (int32(pOp) - int32(aOp)) / 20
|
|
(*TVdbeFrame)(unsafe.Pointer(pFrame2)).FaMem = (*TVdbe)(unsafe.Pointer(p)).FaMem
|
|
(*TVdbeFrame)(unsafe.Pointer(pFrame2)).FnMem = (*TVdbe)(unsafe.Pointer(p)).FnMem
|
|
(*TVdbeFrame)(unsafe.Pointer(pFrame2)).FapCsr = (*TVdbe)(unsafe.Pointer(p)).FapCsr
|
|
(*TVdbeFrame)(unsafe.Pointer(pFrame2)).FnCursor = (*TVdbe)(unsafe.Pointer(p)).FnCursor
|
|
(*TVdbeFrame)(unsafe.Pointer(pFrame2)).FaOp = (*TVdbe)(unsafe.Pointer(p)).FaOp
|
|
(*TVdbeFrame)(unsafe.Pointer(pFrame2)).FnOp = (*TVdbe)(unsafe.Pointer(p)).FnOp
|
|
(*TVdbeFrame)(unsafe.Pointer(pFrame2)).Ftoken = (*TSubProgram)(unsafe.Pointer(pProgram)).Ftoken
|
|
pEnd = pFrame2 + uintptr((libc.Uint32FromInt64(80)+libc.Uint32FromInt32(7))&libc.Uint32FromInt32(^libc.Int32FromInt32(7))) + uintptr((*TVdbeFrame)(unsafe.Pointer(pFrame2)).FnChildMem)*40
|
|
pMem1 = pFrame2 + uintptr((libc.Uint32FromInt64(80)+libc.Uint32FromInt32(7))&libc.Uint32FromInt32(^libc.Int32FromInt32(7)))
|
|
for {
|
|
if !(pMem1 != pEnd) {
|
|
break
|
|
}
|
|
(*TMem)(unsafe.Pointer(pMem1)).Fflags = uint16(MEM_Undefined)
|
|
(*TMem)(unsafe.Pointer(pMem1)).Fdb = db
|
|
goto _279
|
|
_279:
|
|
;
|
|
pMem1 += 40
|
|
}
|
|
} else {
|
|
pFrame2 = (*TMem)(unsafe.Pointer(pRt)).Fz
|
|
}
|
|
(*TVdbe)(unsafe.Pointer(p)).FnFrame = (*TVdbe)(unsafe.Pointer(p)).FnFrame + 1
|
|
(*TVdbeFrame)(unsafe.Pointer(pFrame2)).FpParent = (*TVdbe)(unsafe.Pointer(p)).FpFrame
|
|
(*TVdbeFrame)(unsafe.Pointer(pFrame2)).FlastRowid = (*Tsqlite3)(unsafe.Pointer(db)).FlastRowid
|
|
(*TVdbeFrame)(unsafe.Pointer(pFrame2)).FnChange = (*TVdbe)(unsafe.Pointer(p)).FnChange
|
|
(*TVdbeFrame)(unsafe.Pointer(pFrame2)).FnDbChange = (*Tsqlite3)(unsafe.Pointer((*TVdbe)(unsafe.Pointer(p)).Fdb)).FnChange
|
|
(*TVdbeFrame)(unsafe.Pointer(pFrame2)).FpAuxData = (*TVdbe)(unsafe.Pointer(p)).FpAuxData
|
|
(*TVdbe)(unsafe.Pointer(p)).FpAuxData = uintptr(0)
|
|
(*TVdbe)(unsafe.Pointer(p)).FnChange = 0
|
|
(*TVdbe)(unsafe.Pointer(p)).FpFrame = pFrame2
|
|
v191 = pFrame2 + uintptr((libc.Uint32FromInt64(80)+libc.Uint32FromInt32(7))&libc.Uint32FromInt32(^libc.Int32FromInt32(7)))
|
|
aMem = v191
|
|
(*TVdbe)(unsafe.Pointer(p)).FaMem = v191
|
|
(*TVdbe)(unsafe.Pointer(p)).FnMem = (*TVdbeFrame)(unsafe.Pointer(pFrame2)).FnChildMem
|
|
(*TVdbe)(unsafe.Pointer(p)).FnCursor = libc.Int32FromUint16(libc.Uint16FromInt32((*TVdbeFrame)(unsafe.Pointer(pFrame2)).FnChildCsr))
|
|
(*TVdbe)(unsafe.Pointer(p)).FapCsr = aMem + uintptr((*TVdbe)(unsafe.Pointer(p)).FnMem)*40
|
|
(*TVdbeFrame)(unsafe.Pointer(pFrame2)).FaOnce = (*TVdbe)(unsafe.Pointer(p)).FapCsr + uintptr((*TSubProgram)(unsafe.Pointer(pProgram)).FnCsr)*4
|
|
libc.Xmemset(tls, (*TVdbeFrame)(unsafe.Pointer(pFrame2)).FaOnce, 0, libc.Uint32FromInt32(((*TSubProgram)(unsafe.Pointer(pProgram)).FnOp+int32(7))/int32(8)))
|
|
v191 = (*TSubProgram)(unsafe.Pointer(pProgram)).FaOp
|
|
aOp = v191
|
|
(*TVdbe)(unsafe.Pointer(p)).FaOp = v191
|
|
(*TVdbe)(unsafe.Pointer(p)).FnOp = (*TSubProgram)(unsafe.Pointer(pProgram)).FnOp
|
|
pOp = aOp + uintptr(-libc.Int32FromInt32(1))*20
|
|
goto check_for_interrupt
|
|
/* Opcode: Param P1 P2 * * *
|
|
**
|
|
** This opcode is only ever present in sub-programs called via the
|
|
** OP_Program instruction. Copy a value currently stored in a memory
|
|
** cell of the calling (parent) frame to cell P2 in the current frames
|
|
** address space. This is used by trigger programs to access the new.*
|
|
** and old.* values.
|
|
**
|
|
** The address of the cell in the parent frame is determined by adding
|
|
** the value of the P1 argument to the value of the P1 argument to the
|
|
** calling OP_Program instruction.
|
|
*/
|
|
_145:
|
|
;
|
|
pOut = _out2Prerelease(tls, p, pOp)
|
|
pFrame3 = (*TVdbe)(unsafe.Pointer(p)).FpFrame
|
|
pIn = (*TVdbeFrame)(unsafe.Pointer(pFrame3)).FaMem + uintptr((*TOp)(unsafe.Pointer(pOp)).Fp1+(**(**TOp)(__ccgo_up((*TVdbeFrame)(unsafe.Pointer(pFrame3)).FaOp + uintptr((*TVdbeFrame)(unsafe.Pointer(pFrame3)).Fpc)*20))).Fp1)*40
|
|
_sqlite3VdbeMemShallowCopy(tls, pOut, pIn, int32(MEM_Ephem))
|
|
goto _189
|
|
/* Opcode: FkCounter P1 P2 * * *
|
|
** Synopsis: fkctr[P1]+=P2
|
|
**
|
|
** Increment a "constraint counter" by P2 (P2 may be negative or positive).
|
|
** If P1 is non-zero, the database constraint counter is incremented
|
|
** (deferred foreign key constraints). Otherwise, if P1 is zero, the
|
|
** statement counter is incremented (immediate foreign key constraints).
|
|
*/
|
|
_146:
|
|
;
|
|
if (*TOp)(unsafe.Pointer(pOp)).Fp1 != 0 {
|
|
**(**Ti64)(__ccgo_up(db + 524)) += int64((*TOp)(unsafe.Pointer(pOp)).Fp2)
|
|
} else {
|
|
if (*Tsqlite3)(unsafe.Pointer(db)).Fflags&uint64(SQLITE_DeferFKs) != 0 {
|
|
**(**Ti64)(__ccgo_up(db + 532)) += int64((*TOp)(unsafe.Pointer(pOp)).Fp2)
|
|
} else {
|
|
**(**Ti64)(__ccgo_up(p + 60)) += int64((*TOp)(unsafe.Pointer(pOp)).Fp2)
|
|
}
|
|
}
|
|
goto _189
|
|
/* Opcode: FkIfZero P1 P2 * * *
|
|
** Synopsis: if fkctr[P1]==0 goto P2
|
|
**
|
|
** This opcode tests if a foreign key constraint-counter is currently zero.
|
|
** If so, jump to instruction P2. Otherwise, fall through to the next
|
|
** instruction.
|
|
**
|
|
** If P1 is non-zero, then the jump is taken if the database constraint-counter
|
|
** is zero (the one that counts deferred constraint violations). If P1 is
|
|
** zero, the jump is taken if the statement constraint-counter is zero
|
|
** (immediate foreign key constraint violations).
|
|
*/
|
|
_147:
|
|
; /* jump */
|
|
if (*TOp)(unsafe.Pointer(pOp)).Fp1 != 0 {
|
|
if (*Tsqlite3)(unsafe.Pointer(db)).FnDeferredCons == 0 && (*Tsqlite3)(unsafe.Pointer(db)).FnDeferredImmCons == 0 {
|
|
goto jump_to_p2
|
|
}
|
|
} else {
|
|
if (*TVdbe)(unsafe.Pointer(p)).FnFkConstraint == 0 && (*Tsqlite3)(unsafe.Pointer(db)).FnDeferredImmCons == 0 {
|
|
goto jump_to_p2
|
|
}
|
|
}
|
|
goto _189
|
|
/* Opcode: MemMax P1 P2 * * *
|
|
** Synopsis: r[P1]=max(r[P1],r[P2])
|
|
**
|
|
** P1 is a register in the root frame of this VM (the root frame is
|
|
** different from the current frame if this instruction is being executed
|
|
** within a sub-program). Set the value of register P1 to the maximum of
|
|
** its current value and the value in register P2.
|
|
**
|
|
** This instruction throws an error if the memory cell is not initially
|
|
** an integer.
|
|
*/
|
|
_148:
|
|
;
|
|
if (*TVdbe)(unsafe.Pointer(p)).FpFrame != 0 {
|
|
pFrame4 = (*TVdbe)(unsafe.Pointer(p)).FpFrame
|
|
for {
|
|
if !((*TVdbeFrame)(unsafe.Pointer(pFrame4)).FpParent != 0) {
|
|
break
|
|
}
|
|
goto _282
|
|
_282:
|
|
;
|
|
pFrame4 = (*TVdbeFrame)(unsafe.Pointer(pFrame4)).FpParent
|
|
}
|
|
pIn1 = (*TVdbeFrame)(unsafe.Pointer(pFrame4)).FaMem + uintptr((*TOp)(unsafe.Pointer(pOp)).Fp1)*40
|
|
} else {
|
|
pIn1 = aMem + uintptr((*TOp)(unsafe.Pointer(pOp)).Fp1)*40
|
|
}
|
|
_sqlite3VdbeMemIntegerify(tls, pIn1)
|
|
pIn2 = aMem + uintptr((*TOp)(unsafe.Pointer(pOp)).Fp2)*40
|
|
_sqlite3VdbeMemIntegerify(tls, pIn2)
|
|
if *(*Ti64)(unsafe.Pointer(pIn1)) < *(*Ti64)(unsafe.Pointer(pIn2)) {
|
|
*(*Ti64)(unsafe.Pointer(pIn1)) = *(*Ti64)(unsafe.Pointer(pIn2))
|
|
}
|
|
goto _189
|
|
/* Opcode: IfPos P1 P2 P3 * *
|
|
** Synopsis: if r[P1]>0 then r[P1]-=P3, goto P2
|
|
**
|
|
** Register P1 must contain an integer.
|
|
** If the value of register P1 is 1 or greater, subtract P3 from the
|
|
** value in P1 and jump to P2.
|
|
**
|
|
** If the initial value of register P1 is less than 1, then the
|
|
** value is unchanged and control passes through to the next instruction.
|
|
*/
|
|
_149:
|
|
; /* jump, in1 */
|
|
pIn1 = aMem + uintptr((*TOp)(unsafe.Pointer(pOp)).Fp1)*40
|
|
if *(*Ti64)(unsafe.Pointer(pIn1)) > 0 {
|
|
*(*Ti64)(unsafe.Pointer(pIn1)) -= int64((*TOp)(unsafe.Pointer(pOp)).Fp3)
|
|
goto jump_to_p2
|
|
}
|
|
goto _189
|
|
/* Opcode: OffsetLimit P1 P2 P3 * *
|
|
** Synopsis: if r[P1]>0 then r[P2]=r[P1]+max(0,r[P3]) else r[P2]=(-1)
|
|
**
|
|
** This opcode performs a commonly used computation associated with
|
|
** LIMIT and OFFSET processing. r[P1] holds the limit counter. r[P3]
|
|
** holds the offset counter. The opcode computes the combined value
|
|
** of the LIMIT and OFFSET and stores that value in r[P2]. The r[P2]
|
|
** value computed is the total number of rows that will need to be
|
|
** visited in order to complete the query.
|
|
**
|
|
** If r[P3] is zero or negative, that means there is no OFFSET
|
|
** and r[P2] is set to be the value of the LIMIT, r[P1].
|
|
**
|
|
** if r[P1] is zero or negative, that means there is no LIMIT
|
|
** and r[P2] is set to -1.
|
|
**
|
|
** Otherwise, r[P2] is set to the sum of r[P1] and r[P3].
|
|
*/
|
|
_150:
|
|
;
|
|
pIn1 = aMem + uintptr((*TOp)(unsafe.Pointer(pOp)).Fp1)*40
|
|
pIn3 = aMem + uintptr((*TOp)(unsafe.Pointer(pOp)).Fp3)*40
|
|
pOut = _out2Prerelease(tls, p, pOp)
|
|
**(**Ti64)(__ccgo_up(bp + 544)) = *(*Ti64)(unsafe.Pointer(pIn1))
|
|
if v217 = **(**Ti64)(__ccgo_up(bp + 544)) <= 0; !v217 {
|
|
if *(*Ti64)(unsafe.Pointer(pIn3)) > 0 {
|
|
v206 = *(*Ti64)(unsafe.Pointer(pIn3))
|
|
} else {
|
|
v206 = 0
|
|
}
|
|
}
|
|
if v217 || _sqlite3AddInt64(tls, bp+544, v206) != 0 {
|
|
/* If the LIMIT is less than or equal to zero, loop forever. This
|
|
** is documented. But also, if the LIMIT+OFFSET exceeds 2^63 then
|
|
** also loop forever. This is undocumented. In fact, one could argue
|
|
** that the loop should terminate. But assuming 1 billion iterations
|
|
** per second (far exceeding the capabilities of any current hardware)
|
|
** it would take nearly 300 years to actually reach the limit. So
|
|
** looping forever is a reasonable approximation. */
|
|
*(*Ti64)(unsafe.Pointer(pOut)) = int64(-int32(1))
|
|
} else {
|
|
*(*Ti64)(unsafe.Pointer(pOut)) = **(**Ti64)(__ccgo_up(bp + 544))
|
|
}
|
|
goto _189
|
|
/* Opcode: IfNotZero P1 P2 * * *
|
|
** Synopsis: if r[P1]!=0 then r[P1]--, goto P2
|
|
**
|
|
** Register P1 must contain an integer. If the content of register P1 is
|
|
** initially greater than zero, then decrement the value in register P1.
|
|
** If it is non-zero (negative or positive) and then also jump to P2.
|
|
** If register P1 is initially zero, leave it unchanged and fall through.
|
|
*/
|
|
_151:
|
|
; /* jump, in1 */
|
|
pIn1 = aMem + uintptr((*TOp)(unsafe.Pointer(pOp)).Fp1)*40
|
|
if *(*Ti64)(unsafe.Pointer(pIn1)) != 0 {
|
|
if *(*Ti64)(unsafe.Pointer(pIn1)) > 0 {
|
|
*(*Ti64)(unsafe.Pointer(pIn1)) = *(*Ti64)(unsafe.Pointer(pIn1)) - 1
|
|
}
|
|
goto jump_to_p2
|
|
}
|
|
goto _189
|
|
/* Opcode: DecrJumpZero P1 P2 * * *
|
|
** Synopsis: if (--r[P1])==0 goto P2
|
|
**
|
|
** Register P1 must hold an integer. Decrement the value in P1
|
|
** and jump to P2 if the new value is exactly zero.
|
|
*/
|
|
_152:
|
|
; /* jump, in1 */
|
|
pIn1 = aMem + uintptr((*TOp)(unsafe.Pointer(pOp)).Fp1)*40
|
|
if *(*Ti64)(unsafe.Pointer(pIn1)) > int64(-libc.Int32FromInt32(1))-(libc.Int64FromUint32(0xffffffff)|libc.Int64FromInt32(0x7fffffff)<<libc.Int32FromInt32(32)) {
|
|
*(*Ti64)(unsafe.Pointer(pIn1)) = *(*Ti64)(unsafe.Pointer(pIn1)) - 1
|
|
}
|
|
if *(*Ti64)(unsafe.Pointer(pIn1)) == 0 {
|
|
goto jump_to_p2
|
|
}
|
|
goto _189
|
|
/* Opcode: AggStep * P2 P3 P4 P5
|
|
** Synopsis: accum=r[P3] step(r[P2@P5])
|
|
**
|
|
** Execute the xStep function for an aggregate.
|
|
** The function has P5 arguments. P4 is a pointer to the
|
|
** FuncDef structure that specifies the function. Register P3 is the
|
|
** accumulator.
|
|
**
|
|
** The P5 arguments are taken from register P2 and its
|
|
** successors.
|
|
*/
|
|
/* Opcode: AggInverse * P2 P3 P4 P5
|
|
** Synopsis: accum=r[P3] inverse(r[P2@P5])
|
|
**
|
|
** Execute the xInverse function for an aggregate.
|
|
** The function has P5 arguments. P4 is a pointer to the
|
|
** FuncDef structure that specifies the function. Register P3 is the
|
|
** accumulator.
|
|
**
|
|
** The P5 arguments are taken from register P2 and its
|
|
** successors.
|
|
*/
|
|
/* Opcode: AggStep1 P1 P2 P3 P4 P5
|
|
** Synopsis: accum=r[P3] step(r[P2@P5])
|
|
**
|
|
** Execute the xStep (if P1==0) or xInverse (if P1!=0) function for an
|
|
** aggregate. The function has P5 arguments. P4 is a pointer to the
|
|
** FuncDef structure that specifies the function. Register P3 is the
|
|
** accumulator.
|
|
**
|
|
** The P5 arguments are taken from register P2 and its
|
|
** successors.
|
|
**
|
|
** This opcode is initially coded as OP_AggStep0. On first evaluation,
|
|
** the FuncDef stored in P4 is converted into an sqlite3_context and
|
|
** the opcode is changed. In this way, the initialization of the
|
|
** sqlite3_context only happens once, instead of on each call to the
|
|
** step function.
|
|
*/
|
|
_154:
|
|
;
|
|
_153:
|
|
;
|
|
n4 = libc.Int32FromUint16((*TOp)(unsafe.Pointer(pOp)).Fp5)
|
|
/* Allocate space for (a) the context object and (n-1) extra pointers
|
|
** to append to the sqlite3_context.argv[1] array, and (b) a memory
|
|
** cell in which to store the accumulation. Be careful that the memory
|
|
** cell is 8-byte aligned, even on platforms where a pointer is 32-bits.
|
|
**
|
|
** Note: We could avoid this by using a regular memory cell from aMem[] for
|
|
** the accumulator, instead of allocating one here. */
|
|
nAlloc = uint64((uint32(libc.UintptrFromInt32(0)+28) + libc.Uint32FromInt32(n4)*libc.Uint32FromInt64(4) + libc.Uint32FromInt32(7)) & libc.Uint32FromInt32(^libc.Int32FromInt32(7)))
|
|
pCtx = _sqlite3DbMallocRawNN(tls, db, nAlloc+uint64(40))
|
|
if pCtx == uintptr(0) {
|
|
goto no_mem
|
|
}
|
|
(*Tsqlite3_context)(unsafe.Pointer(pCtx)).FpOut = pCtx + uintptr(nAlloc)
|
|
_sqlite3VdbeMemInit(tls, (*Tsqlite3_context)(unsafe.Pointer(pCtx)).FpOut, db, uint16(MEM_Null))
|
|
(*Tsqlite3_context)(unsafe.Pointer(pCtx)).FpMem = uintptr(0)
|
|
(*Tsqlite3_context)(unsafe.Pointer(pCtx)).FpFunc = *(*uintptr)(unsafe.Pointer(pOp + 16))
|
|
(*Tsqlite3_context)(unsafe.Pointer(pCtx)).FiOp = (int32(pOp) - int32(aOp)) / 20
|
|
(*Tsqlite3_context)(unsafe.Pointer(pCtx)).FpVdbe = p
|
|
(*Tsqlite3_context)(unsafe.Pointer(pCtx)).FskipFlag = uint8(0)
|
|
(*Tsqlite3_context)(unsafe.Pointer(pCtx)).FisError = 0
|
|
(*Tsqlite3_context)(unsafe.Pointer(pCtx)).Fenc = encoding
|
|
(*Tsqlite3_context)(unsafe.Pointer(pCtx)).Fargc = libc.Uint16FromInt32(n4)
|
|
(*TOp)(unsafe.Pointer(pOp)).Fp4type = int8(-libc.Int32FromInt32(16))
|
|
*(*uintptr)(unsafe.Pointer(pOp + 16)) = pCtx
|
|
/* OP_AggInverse must have P1==1 and OP_AggStep must have P1==0 */
|
|
(*TOp)(unsafe.Pointer(pOp)).Fopcode = uint8(OP_AggStep1)
|
|
/* Fall through into OP_AggStep */
|
|
_155:
|
|
;
|
|
pCtx1 = *(*uintptr)(unsafe.Pointer(pOp + 16))
|
|
pMem2 = aMem + uintptr((*TOp)(unsafe.Pointer(pOp)).Fp3)*40
|
|
/* If this function is inside of a trigger, the register array in aMem[]
|
|
** might change from one evaluation to the next. The next block of code
|
|
** checks to see if the register array has changed, and if so it
|
|
** reinitializes the relevant parts of the sqlite3_context object */
|
|
if (*Tsqlite3_context)(unsafe.Pointer(pCtx1)).FpMem != pMem2 {
|
|
(*Tsqlite3_context)(unsafe.Pointer(pCtx1)).FpMem = pMem2
|
|
i4 = libc.Int32FromUint16((*Tsqlite3_context)(unsafe.Pointer(pCtx1)).Fargc) - int32(1)
|
|
for {
|
|
if !(i4 >= 0) {
|
|
break
|
|
}
|
|
*(*uintptr)(unsafe.Pointer(pCtx1 + 28 + uintptr(i4)*4)) = aMem + uintptr((*TOp)(unsafe.Pointer(pOp)).Fp2+i4)*40
|
|
goto _285
|
|
_285:
|
|
;
|
|
i4 = i4 - 1
|
|
}
|
|
}
|
|
(*TMem)(unsafe.Pointer(pMem2)).Fn = (*TMem)(unsafe.Pointer(pMem2)).Fn + 1
|
|
if (*TOp)(unsafe.Pointer(pOp)).Fp1 != 0 {
|
|
(*(*func(*libc.TLS, uintptr, int32, uintptr))(unsafe.Pointer(&struct{ uintptr }{(*TFuncDef)(unsafe.Pointer((*Tsqlite3_context)(unsafe.Pointer(pCtx1)).FpFunc)).FxInverse})))(tls, pCtx1, libc.Int32FromUint16((*Tsqlite3_context)(unsafe.Pointer(pCtx1)).Fargc), pCtx1+28)
|
|
} else {
|
|
(*(*func(*libc.TLS, uintptr, int32, uintptr))(unsafe.Pointer(&struct{ uintptr }{(*TFuncDef)(unsafe.Pointer((*Tsqlite3_context)(unsafe.Pointer(pCtx1)).FpFunc)).FxSFunc})))(tls, pCtx1, libc.Int32FromUint16((*Tsqlite3_context)(unsafe.Pointer(pCtx1)).Fargc), pCtx1+28)
|
|
} /* IMP: R-24505-23230 */
|
|
if (*Tsqlite3_context)(unsafe.Pointer(pCtx1)).FisError != 0 {
|
|
if (*Tsqlite3_context)(unsafe.Pointer(pCtx1)).FisError > 0 {
|
|
_sqlite3VdbeError(tls, p, __ccgo_ts+3942, libc.VaList(bp+696, Xsqlite3_value_text(tls, (*Tsqlite3_context)(unsafe.Pointer(pCtx1)).FpOut)))
|
|
rc = (*Tsqlite3_context)(unsafe.Pointer(pCtx1)).FisError
|
|
}
|
|
if (*Tsqlite3_context)(unsafe.Pointer(pCtx1)).FskipFlag != 0 {
|
|
i4 = (**(**TOp)(__ccgo_up(pOp + uintptr(-libc.Int32FromInt32(1))*20))).Fp1
|
|
if i4 != 0 {
|
|
_sqlite3VdbeMemSetInt64(tls, aMem+uintptr(i4)*40, int64(1))
|
|
}
|
|
(*Tsqlite3_context)(unsafe.Pointer(pCtx1)).FskipFlag = uint8(0)
|
|
}
|
|
_sqlite3VdbeMemRelease(tls, (*Tsqlite3_context)(unsafe.Pointer(pCtx1)).FpOut)
|
|
(*TMem)(unsafe.Pointer((*Tsqlite3_context)(unsafe.Pointer(pCtx1)).FpOut)).Fflags = uint16(MEM_Null)
|
|
(*Tsqlite3_context)(unsafe.Pointer(pCtx1)).FisError = 0
|
|
if rc != 0 {
|
|
goto abort_due_to_error
|
|
}
|
|
}
|
|
goto _189
|
|
/* Opcode: AggFinal P1 P2 * P4 *
|
|
** Synopsis: accum=r[P1] N=P2
|
|
**
|
|
** P1 is the memory location that is the accumulator for an aggregate
|
|
** or window function. Execute the finalizer function
|
|
** for an aggregate and store the result in P1.
|
|
**
|
|
** P2 is the number of arguments that the step function takes and
|
|
** P4 is a pointer to the FuncDef for this function. The P2
|
|
** argument is not used by this opcode. It is only there to disambiguate
|
|
** functions that can take varying numbers of arguments. The
|
|
** P4 argument is only needed for the case where
|
|
** the step function was not previously called.
|
|
*/
|
|
/* Opcode: AggValue * P2 P3 P4 *
|
|
** Synopsis: r[P3]=value N=P2
|
|
**
|
|
** Invoke the xValue() function and store the result in register P3.
|
|
**
|
|
** P2 is the number of arguments that the step function takes and
|
|
** P4 is a pointer to the FuncDef for this function. The P2
|
|
** argument is not used by this opcode. It is only there to disambiguate
|
|
** functions that can take varying numbers of arguments. The
|
|
** P4 argument is only needed for the case where
|
|
** the step function was not previously called.
|
|
*/
|
|
_157:
|
|
;
|
|
_156:
|
|
;
|
|
pMem3 = aMem + uintptr((*TOp)(unsafe.Pointer(pOp)).Fp1)*40
|
|
if (*TOp)(unsafe.Pointer(pOp)).Fp3 != 0 {
|
|
rc = _sqlite3VdbeMemAggValue(tls, pMem3, aMem+uintptr((*TOp)(unsafe.Pointer(pOp)).Fp3)*40, *(*uintptr)(unsafe.Pointer(pOp + 16)))
|
|
pMem3 = aMem + uintptr((*TOp)(unsafe.Pointer(pOp)).Fp3)*40
|
|
} else {
|
|
rc = _sqlite3VdbeMemFinalize(tls, pMem3, *(*uintptr)(unsafe.Pointer(pOp + 16)))
|
|
}
|
|
if rc != 0 {
|
|
_sqlite3VdbeError(tls, p, __ccgo_ts+3942, libc.VaList(bp+696, Xsqlite3_value_text(tls, pMem3)))
|
|
goto abort_due_to_error
|
|
}
|
|
_sqlite3VdbeChangeEncoding(tls, pMem3, libc.Int32FromUint8(encoding))
|
|
goto _189
|
|
/* Opcode: Checkpoint P1 P2 P3 * *
|
|
**
|
|
** Checkpoint database P1. This is a no-op if P1 is not currently in
|
|
** WAL mode. Parameter P2 is one of SQLITE_CHECKPOINT_PASSIVE, FULL,
|
|
** RESTART, or TRUNCATE. Write 1 or 0 into mem[P3] if the checkpoint returns
|
|
** SQLITE_BUSY or not, respectively. Write the number of pages in the
|
|
** WAL after the checkpoint into mem[P3+1] and the number of pages
|
|
** in the WAL that have been checkpointed after the checkpoint
|
|
** completes into mem[P3+2]. However on an error, mem[P3+1] and
|
|
** mem[P3+2] are initialized to -1.
|
|
*/
|
|
_158:
|
|
; /* Write results here */
|
|
(**(**[3]int32)(__ccgo_up(bp + 552)))[0] = 0
|
|
v190 = -libc.Int32FromInt32(1)
|
|
(**(**[3]int32)(__ccgo_up(bp + 552)))[int32(2)] = v190
|
|
(**(**[3]int32)(__ccgo_up(bp + 552)))[int32(1)] = v190
|
|
rc = _sqlite3Checkpoint(tls, db, (*TOp)(unsafe.Pointer(pOp)).Fp1, (*TOp)(unsafe.Pointer(pOp)).Fp2, bp+552+1*4, bp+552+2*4)
|
|
if rc != 0 {
|
|
if rc != int32(SQLITE_BUSY) {
|
|
goto abort_due_to_error
|
|
}
|
|
rc = SQLITE_OK
|
|
(**(**[3]int32)(__ccgo_up(bp + 552)))[0] = int32(1)
|
|
}
|
|
i5 = 0
|
|
pMem4 = aMem + uintptr((*TOp)(unsafe.Pointer(pOp)).Fp3)*40
|
|
for {
|
|
if !(i5 < int32(3)) {
|
|
break
|
|
}
|
|
_sqlite3VdbeMemSetInt64(tls, pMem4, int64((**(**[3]int32)(__ccgo_up(bp + 552)))[i5]))
|
|
goto _287
|
|
_287:
|
|
;
|
|
i5 = i5 + 1
|
|
pMem4 += 40
|
|
}
|
|
goto _189
|
|
/* Opcode: JournalMode P1 P2 P3 * *
|
|
**
|
|
** Change the journal mode of database P1 to P3. P3 must be one of the
|
|
** PAGER_JOURNALMODE_XXX values. If changing between the various rollback
|
|
** modes (delete, truncate, persist, off and memory), this is a simple
|
|
** operation. No IO is required.
|
|
**
|
|
** If changing into or out of WAL mode the procedure is more complicated.
|
|
**
|
|
** Write a string containing the final journal-mode to register P2.
|
|
*/
|
|
_159:
|
|
; /* Name of database file for pPager */
|
|
pOut = _out2Prerelease(tls, p, pOp)
|
|
eNew = (*TOp)(unsafe.Pointer(pOp)).Fp3
|
|
pBt1 = (**(**TDb)(__ccgo_up((*Tsqlite3)(unsafe.Pointer(db)).FaDb + uintptr((*TOp)(unsafe.Pointer(pOp)).Fp1)*16))).FpBt
|
|
pPager = _sqlite3BtreePager(tls, pBt1)
|
|
eOld = _sqlite3PagerGetJournalMode(tls, pPager)
|
|
if eNew == -int32(1) {
|
|
eNew = eOld
|
|
}
|
|
if !(_sqlite3PagerOkToChangeJournalMode(tls, pPager) != 0) {
|
|
eNew = eOld
|
|
}
|
|
zFilename = _sqlite3PagerFilename(tls, pPager, int32(1))
|
|
/* Do not allow a transition to journal_mode=WAL for a database
|
|
** in temporary storage or if the VFS does not support shared memory
|
|
*/
|
|
if eNew == int32(PAGER_JOURNALMODE_WAL) && (_sqlite3Strlen30(tls, zFilename) == 0 || !(_sqlite3PagerWalSupported(tls, pPager) != 0)) {
|
|
eNew = eOld
|
|
}
|
|
if eNew != eOld && (eOld == int32(PAGER_JOURNALMODE_WAL) || eNew == int32(PAGER_JOURNALMODE_WAL)) {
|
|
if !((*Tsqlite3)(unsafe.Pointer(db)).FautoCommit != 0) || (*Tsqlite3)(unsafe.Pointer(db)).FnVdbeRead > int32(1) {
|
|
rc = int32(SQLITE_ERROR)
|
|
if eNew == int32(PAGER_JOURNALMODE_WAL) {
|
|
v191 = __ccgo_ts + 6380
|
|
} else {
|
|
v191 = __ccgo_ts + 6385
|
|
}
|
|
_sqlite3VdbeError(tls, p, __ccgo_ts+6392, libc.VaList(bp+696, v191))
|
|
goto abort_due_to_error
|
|
} else {
|
|
if eOld == int32(PAGER_JOURNALMODE_WAL) {
|
|
/* If leaving WAL mode, close the log file. If successful, the call
|
|
** to PagerCloseWal() checkpoints and deletes the write-ahead-log
|
|
** file. An EXCLUSIVE lock may still be held on the database file
|
|
** after a successful return.
|
|
*/
|
|
rc = _sqlite3PagerCloseWal(tls, pPager, db)
|
|
if rc == SQLITE_OK {
|
|
_sqlite3PagerSetJournalMode(tls, pPager, eNew)
|
|
}
|
|
} else {
|
|
if eOld == int32(PAGER_JOURNALMODE_MEMORY) {
|
|
/* Cannot transition directly from MEMORY to WAL. Use mode OFF
|
|
** as an intermediate */
|
|
_sqlite3PagerSetJournalMode(tls, pPager, int32(PAGER_JOURNALMODE_OFF))
|
|
}
|
|
}
|
|
/* Open a transaction on the database file. Regardless of the journal
|
|
** mode, this transaction always uses a rollback journal.
|
|
*/
|
|
if rc == SQLITE_OK {
|
|
if eNew == int32(PAGER_JOURNALMODE_WAL) {
|
|
v190 = int32(2)
|
|
} else {
|
|
v190 = int32(1)
|
|
}
|
|
rc = _sqlite3BtreeSetVersion(tls, pBt1, v190)
|
|
}
|
|
}
|
|
}
|
|
if rc != 0 {
|
|
eNew = eOld
|
|
}
|
|
eNew = _sqlite3PagerSetJournalMode(tls, pPager, eNew)
|
|
(*TMem)(unsafe.Pointer(pOut)).Fflags = libc.Uint16FromInt32(libc.Int32FromInt32(MEM_Str) | libc.Int32FromInt32(MEM_Static) | libc.Int32FromInt32(MEM_Term))
|
|
(*TMem)(unsafe.Pointer(pOut)).Fz = _sqlite3JournalModename(tls, eNew)
|
|
(*TMem)(unsafe.Pointer(pOut)).Fn = _sqlite3Strlen30(tls, (*TMem)(unsafe.Pointer(pOut)).Fz)
|
|
(*TMem)(unsafe.Pointer(pOut)).Fenc = uint8(SQLITE_UTF8)
|
|
_sqlite3VdbeChangeEncoding(tls, pOut, libc.Int32FromUint8(encoding))
|
|
if rc != 0 {
|
|
goto abort_due_to_error
|
|
}
|
|
goto _189
|
|
/* Opcode: Vacuum P1 P2 * * *
|
|
**
|
|
** Vacuum the entire database P1. P1 is 0 for "main", and 2 or more
|
|
** for an attached database. The "temp" database may not be vacuumed.
|
|
**
|
|
** If P2 is not zero, then it is a register holding a string which is
|
|
** the file into which the result of vacuum should be written. When
|
|
** P2 is zero, the vacuum overwrites the original database.
|
|
*/
|
|
_160:
|
|
;
|
|
if (*TOp)(unsafe.Pointer(pOp)).Fp2 != 0 {
|
|
v191 = aMem + uintptr((*TOp)(unsafe.Pointer(pOp)).Fp2)*40
|
|
} else {
|
|
v191 = uintptr(0)
|
|
}
|
|
rc = _sqlite3RunVacuum(tls, p+120, db, (*TOp)(unsafe.Pointer(pOp)).Fp1, v191)
|
|
if rc != 0 {
|
|
goto abort_due_to_error
|
|
}
|
|
goto _189
|
|
/* Opcode: IncrVacuum P1 P2 * * *
|
|
**
|
|
** Perform a single step of the incremental vacuum procedure on
|
|
** the P1 database. If the vacuum has finished, jump to instruction
|
|
** P2. Otherwise, fall through to the next instruction.
|
|
*/
|
|
_161:
|
|
;
|
|
pBt2 = (**(**TDb)(__ccgo_up((*Tsqlite3)(unsafe.Pointer(db)).FaDb + uintptr((*TOp)(unsafe.Pointer(pOp)).Fp1)*16))).FpBt
|
|
rc = _sqlite3BtreeIncrVacuum(tls, pBt2)
|
|
if rc != 0 {
|
|
if rc != int32(SQLITE_DONE) {
|
|
goto abort_due_to_error
|
|
}
|
|
rc = SQLITE_OK
|
|
goto jump_to_p2
|
|
}
|
|
goto _189
|
|
/* Opcode: Expire P1 P2 * * *
|
|
**
|
|
** Cause precompiled statements to expire. When an expired statement
|
|
** is executed using sqlite3_step() it will either automatically
|
|
** reprepare itself (if it was originally created using sqlite3_prepare_v2())
|
|
** or it will fail with SQLITE_SCHEMA.
|
|
**
|
|
** If P1 is 0, then all SQL statements become expired. If P1 is non-zero,
|
|
** then only the currently executing statement is expired.
|
|
**
|
|
** If P2 is 0, then SQL statements are expired immediately. If P2 is 1,
|
|
** then running SQL statements are allowed to continue to run to completion.
|
|
** The P2==1 case occurs when a CREATE INDEX or similar schema change happens
|
|
** that might help the statement run faster but which does not affect the
|
|
** correctness of operation.
|
|
*/
|
|
_162:
|
|
;
|
|
if !((*TOp)(unsafe.Pointer(pOp)).Fp1 != 0) {
|
|
_sqlite3ExpirePreparedStatements(tls, db, (*TOp)(unsafe.Pointer(pOp)).Fp2)
|
|
} else {
|
|
libc.SetBitFieldPtr16Uint32(p+144, libc.Uint32FromInt32((*TOp)(unsafe.Pointer(pOp)).Fp2+libc.Int32FromInt32(1)), 0, 0x3)
|
|
}
|
|
goto _189
|
|
/* Opcode: CursorLock P1 * * * *
|
|
**
|
|
** Lock the btree to which cursor P1 is pointing so that the btree cannot be
|
|
** written by an other cursor.
|
|
*/
|
|
_163:
|
|
;
|
|
pC32 = **(**uintptr)(__ccgo_up((*TVdbe)(unsafe.Pointer(p)).FapCsr + uintptr((*TOp)(unsafe.Pointer(pOp)).Fp1)*4))
|
|
_sqlite3BtreeCursorPin(tls, *(*uintptr)(unsafe.Pointer(pC32 + 36)))
|
|
goto _189
|
|
/* Opcode: CursorUnlock P1 * * * *
|
|
**
|
|
** Unlock the btree to which cursor P1 is pointing so that it can be
|
|
** written by other cursors.
|
|
*/
|
|
_164:
|
|
;
|
|
pC33 = **(**uintptr)(__ccgo_up((*TVdbe)(unsafe.Pointer(p)).FapCsr + uintptr((*TOp)(unsafe.Pointer(pOp)).Fp1)*4))
|
|
_sqlite3BtreeCursorUnpin(tls, *(*uintptr)(unsafe.Pointer(pC33 + 36)))
|
|
goto _189
|
|
/* Opcode: TableLock P1 P2 P3 P4 *
|
|
** Synopsis: iDb=P1 root=P2 write=P3
|
|
**
|
|
** Obtain a lock on a particular table. This instruction is only used when
|
|
** the shared-cache feature is enabled.
|
|
**
|
|
** P1 is the index of the database in sqlite3.aDb[] of the database
|
|
** on which the lock is acquired. A readlock is obtained if P3==0 or
|
|
** a write lock if P3==1.
|
|
**
|
|
** P2 contains the root-page of the table to lock.
|
|
**
|
|
** P4 contains a pointer to the name of the table being locked. This is only
|
|
** used to generate an error message if the lock cannot be obtained.
|
|
*/
|
|
_165:
|
|
;
|
|
isWriteLock = libc.Uint8FromInt32((*TOp)(unsafe.Pointer(pOp)).Fp3)
|
|
if isWriteLock != 0 || uint64(0) == (*Tsqlite3)(unsafe.Pointer(db)).Fflags&(libc.Uint64FromInt32(libc.Int32FromInt32(0x00004))<<libc.Int32FromInt32(32)) {
|
|
p13 = (*TOp)(unsafe.Pointer(pOp)).Fp1
|
|
rc = _sqlite3BtreeLockTable(tls, (**(**TDb)(__ccgo_up((*Tsqlite3)(unsafe.Pointer(db)).FaDb + uintptr(p13)*16))).FpBt, (*TOp)(unsafe.Pointer(pOp)).Fp2, isWriteLock)
|
|
if rc != 0 {
|
|
if rc&int32(0xFF) == int32(SQLITE_LOCKED) {
|
|
z1 = *(*uintptr)(unsafe.Pointer(pOp + 16))
|
|
_sqlite3VdbeError(tls, p, __ccgo_ts+6444, libc.VaList(bp+696, z1))
|
|
}
|
|
goto abort_due_to_error
|
|
}
|
|
}
|
|
goto _189
|
|
/* Opcode: VBegin * * * P4 *
|
|
**
|
|
** P4 may be a pointer to an sqlite3_vtab structure. If so, call the
|
|
** xBegin method for that table.
|
|
**
|
|
** Also, whether or not P4 is set, check that this is not being called from
|
|
** within a callback to a virtual table xSync() method. If it is, the error
|
|
** code will be set to SQLITE_LOCKED.
|
|
*/
|
|
_166:
|
|
;
|
|
pVTab = *(*uintptr)(unsafe.Pointer(pOp + 16))
|
|
rc = _sqlite3VtabBegin(tls, db, pVTab)
|
|
if pVTab != 0 {
|
|
_sqlite3VtabImportErrmsg(tls, p, (*TVTable)(unsafe.Pointer(pVTab)).FpVtab)
|
|
}
|
|
if rc != 0 {
|
|
goto abort_due_to_error
|
|
}
|
|
goto _189
|
|
/* Opcode: VCreate P1 P2 * * *
|
|
**
|
|
** P2 is a register that holds the name of a virtual table in database
|
|
** P1. Call the xCreate method for that table.
|
|
*/
|
|
_167:
|
|
; /* Name of the virtual table */
|
|
libc.Xmemset(tls, bp+564, 0, uint32(40))
|
|
(**(**TMem)(__ccgo_up(bp + 564))).Fdb = db
|
|
/* Because P2 is always a static string, it is impossible for the
|
|
** sqlite3VdbeMemCopy() to fail */
|
|
rc = _sqlite3VdbeMemCopy(tls, bp+564, aMem+uintptr((*TOp)(unsafe.Pointer(pOp)).Fp2)*40)
|
|
zTab = Xsqlite3_value_text(tls, bp+564)
|
|
if zTab != 0 {
|
|
rc = _sqlite3VtabCallCreate(tls, db, (*TOp)(unsafe.Pointer(pOp)).Fp1, zTab, p+120)
|
|
}
|
|
_sqlite3VdbeMemRelease(tls, bp+564)
|
|
if rc != 0 {
|
|
goto abort_due_to_error
|
|
}
|
|
goto _189
|
|
/* Opcode: VDestroy P1 * * P4 *
|
|
**
|
|
** P4 is the name of a virtual table in database P1. Call the xDestroy method
|
|
** of that table.
|
|
*/
|
|
_168:
|
|
;
|
|
(*Tsqlite3)(unsafe.Pointer(db)).FnVDestroy = (*Tsqlite3)(unsafe.Pointer(db)).FnVDestroy + 1
|
|
rc = _sqlite3VtabCallDestroy(tls, db, (*TOp)(unsafe.Pointer(pOp)).Fp1, *(*uintptr)(unsafe.Pointer(pOp + 16)))
|
|
(*Tsqlite3)(unsafe.Pointer(db)).FnVDestroy = (*Tsqlite3)(unsafe.Pointer(db)).FnVDestroy - 1
|
|
if rc != 0 {
|
|
goto abort_due_to_error
|
|
}
|
|
goto _189
|
|
/* Opcode: VOpen P1 * * P4 *
|
|
**
|
|
** P4 is a pointer to a virtual table object, an sqlite3_vtab structure.
|
|
** P1 is a cursor number. This opcode opens a cursor to the virtual
|
|
** table and stores that cursor in P1.
|
|
*/
|
|
_169:
|
|
;
|
|
pCur3 = **(**uintptr)(__ccgo_up((*TVdbe)(unsafe.Pointer(p)).FapCsr + uintptr((*TOp)(unsafe.Pointer(pOp)).Fp1)*4))
|
|
if pCur3 != uintptr(0) && libc.Int32FromUint8((*TVdbeCursor)(unsafe.Pointer(pCur3)).FeCurType) == int32(CURTYPE_VTAB) && (*Tsqlite3_vtab_cursor)(unsafe.Pointer(*(*uintptr)(unsafe.Pointer(pCur3 + 36)))).FpVtab == (*TVTable)(unsafe.Pointer(*(*uintptr)(unsafe.Pointer(pOp + 16)))).FpVtab {
|
|
/* This opcode is a no-op if the cursor is already open */
|
|
goto _189
|
|
}
|
|
**(**uintptr)(__ccgo_up(bp + 604)) = uintptr(0)
|
|
pVtab1 = (*TVTable)(unsafe.Pointer(*(*uintptr)(unsafe.Pointer(pOp + 16)))).FpVtab
|
|
if pVtab1 == uintptr(0) || (*Tsqlite3_vtab)(unsafe.Pointer(pVtab1)).FpModule == uintptr(0) {
|
|
rc = int32(SQLITE_LOCKED)
|
|
goto abort_due_to_error
|
|
}
|
|
pModule1 = (*Tsqlite3_vtab)(unsafe.Pointer(pVtab1)).FpModule
|
|
rc = (*(*func(*libc.TLS, uintptr, uintptr) int32)(unsafe.Pointer(&struct{ uintptr }{(*Tsqlite3_module)(unsafe.Pointer(pModule1)).FxOpen})))(tls, pVtab1, bp+604)
|
|
_sqlite3VtabImportErrmsg(tls, p, pVtab1)
|
|
if rc != 0 {
|
|
goto abort_due_to_error
|
|
}
|
|
/* Initialize sqlite3_vtab_cursor base class */
|
|
(*Tsqlite3_vtab_cursor)(unsafe.Pointer(**(**uintptr)(__ccgo_up(bp + 604)))).FpVtab = pVtab1
|
|
/* Initialize vdbe cursor object */
|
|
pCur3 = _allocateCursor(tls, p, (*TOp)(unsafe.Pointer(pOp)).Fp1, 0, uint8(CURTYPE_VTAB))
|
|
if pCur3 != 0 {
|
|
*(*uintptr)(unsafe.Pointer(pCur3 + 36)) = **(**uintptr)(__ccgo_up(bp + 604))
|
|
(*Tsqlite3_vtab)(unsafe.Pointer(pVtab1)).FnRef = (*Tsqlite3_vtab)(unsafe.Pointer(pVtab1)).FnRef + 1
|
|
} else {
|
|
(*(*func(*libc.TLS, uintptr) int32)(unsafe.Pointer(&struct{ uintptr }{(*Tsqlite3_module)(unsafe.Pointer(pModule1)).FxClose})))(tls, **(**uintptr)(__ccgo_up(bp + 604)))
|
|
goto no_mem
|
|
}
|
|
goto _189
|
|
/* Opcode: VCheck P1 P2 P3 P4 *
|
|
**
|
|
** P4 is a pointer to a Table object that is a virtual table in schema P1
|
|
** that supports the xIntegrity() method. This opcode runs the xIntegrity()
|
|
** method for that virtual table, using P3 as the integer argument. If
|
|
** an error is reported back, the table name is prepended to the error
|
|
** message and that message is stored in P2. If no errors are seen,
|
|
** register P2 is set to NULL.
|
|
*/
|
|
_170:
|
|
;
|
|
**(**uintptr)(__ccgo_up(bp + 608)) = uintptr(0)
|
|
pOut = aMem + uintptr((*TOp)(unsafe.Pointer(pOp)).Fp2)*40
|
|
_sqlite3VdbeMemSetNull(tls, pOut) /* Innocent until proven guilty */
|
|
pTab3 = *(*uintptr)(unsafe.Pointer(pOp + 16))
|
|
if (*(*struct {
|
|
FnArg int32
|
|
FazArg uintptr
|
|
Fp uintptr
|
|
})(unsafe.Pointer(pTab3 + 44))).Fp == uintptr(0) {
|
|
goto _189
|
|
}
|
|
pVtab2 = (*TVTable)(unsafe.Pointer((*(*struct {
|
|
FnArg int32
|
|
FazArg uintptr
|
|
Fp uintptr
|
|
})(unsafe.Pointer(pTab3 + 44))).Fp)).FpVtab
|
|
pModule2 = (*Tsqlite3_vtab)(unsafe.Pointer(pVtab2)).FpModule
|
|
_sqlite3VtabLock(tls, (*(*struct {
|
|
FnArg int32
|
|
FazArg uintptr
|
|
Fp uintptr
|
|
})(unsafe.Pointer(pTab3 + 44))).Fp)
|
|
rc = (*(*func(*libc.TLS, uintptr, uintptr, uintptr, int32, uintptr) int32)(unsafe.Pointer(&struct{ uintptr }{(*Tsqlite3_module)(unsafe.Pointer(pModule2)).FxIntegrity})))(tls, pVtab2, (**(**TDb)(__ccgo_up((*Tsqlite3)(unsafe.Pointer(db)).FaDb + uintptr((*TOp)(unsafe.Pointer(pOp)).Fp1)*16))).FzDbSName, (*TTable)(unsafe.Pointer(pTab3)).FzName, (*TOp)(unsafe.Pointer(pOp)).Fp3, bp+608)
|
|
_sqlite3VtabUnlock(tls, (*(*struct {
|
|
FnArg int32
|
|
FazArg uintptr
|
|
Fp uintptr
|
|
})(unsafe.Pointer(pTab3 + 44))).Fp)
|
|
if rc != 0 {
|
|
Xsqlite3_free(tls, **(**uintptr)(__ccgo_up(bp + 608)))
|
|
goto abort_due_to_error
|
|
}
|
|
if **(**uintptr)(__ccgo_up(bp + 608)) != 0 {
|
|
_sqlite3VdbeMemSetStr(tls, pOut, **(**uintptr)(__ccgo_up(bp + 608)), int64(-int32(1)), uint8(SQLITE_UTF8), __ccgo_fp(Xsqlite3_free))
|
|
}
|
|
goto _189
|
|
/* Opcode: VInitIn P1 P2 P3 * *
|
|
** Synopsis: r[P2]=ValueList(P1,P3)
|
|
**
|
|
** Set register P2 to be a pointer to a ValueList object for cursor P1
|
|
** with cache register P3 and output register P3+1. This ValueList object
|
|
** can be used as the first argument to sqlite3_vtab_in_first() and
|
|
** sqlite3_vtab_in_next() to extract all of the values stored in the P1
|
|
** cursor. Register P3 is used to hold the values returned by
|
|
** sqlite3_vtab_in_first() and sqlite3_vtab_in_next().
|
|
*/
|
|
_171:
|
|
; /* New ValueList object to put in reg[P2] */
|
|
pC34 = **(**uintptr)(__ccgo_up((*TVdbe)(unsafe.Pointer(p)).FapCsr + uintptr((*TOp)(unsafe.Pointer(pOp)).Fp1)*4))
|
|
pRhs = Xsqlite3_malloc64(tls, uint64(8))
|
|
if pRhs == uintptr(0) {
|
|
goto no_mem
|
|
}
|
|
(*TValueList)(unsafe.Pointer(pRhs)).FpCsr = *(*uintptr)(unsafe.Pointer(pC34 + 36))
|
|
(*TValueList)(unsafe.Pointer(pRhs)).FpOut = aMem + uintptr((*TOp)(unsafe.Pointer(pOp)).Fp3)*40
|
|
pOut = _out2Prerelease(tls, p, pOp)
|
|
(*TMem)(unsafe.Pointer(pOut)).Fflags = uint16(MEM_Null)
|
|
_sqlite3VdbeMemSetPointer(tls, pOut, pRhs, __ccgo_ts+6473, __ccgo_fp(_sqlite3VdbeValueListFree))
|
|
goto _189
|
|
/* Opcode: VFilter P1 P2 P3 P4 *
|
|
** Synopsis: iplan=r[P3] zplan='P4'
|
|
**
|
|
** P1 is a cursor opened using VOpen. P2 is an address to jump to if
|
|
** the filtered result set is empty.
|
|
**
|
|
** P4 is either NULL or a string that was generated by the xBestIndex
|
|
** method of the module. The interpretation of the P4 string is left
|
|
** to the module implementation.
|
|
**
|
|
** This opcode invokes the xFilter method on the virtual table specified
|
|
** by P1. The integer query plan parameter to xFilter is stored in register
|
|
** P3. Register P3+1 stores the argc parameter to be passed to the
|
|
** xFilter method. Registers P3+2..P3+1+argc are the argc
|
|
** additional parameters which are passed to
|
|
** xFilter as argv. Register P3+2 becomes argv[0] when passed to xFilter.
|
|
**
|
|
** A jump is made to P2 if the result set after filtering would be empty.
|
|
*/
|
|
_172:
|
|
;
|
|
pQuery = aMem + uintptr((*TOp)(unsafe.Pointer(pOp)).Fp3)*40
|
|
pArgc = pQuery + 1*40
|
|
pCur4 = **(**uintptr)(__ccgo_up((*TVdbe)(unsafe.Pointer(p)).FapCsr + uintptr((*TOp)(unsafe.Pointer(pOp)).Fp1)*4))
|
|
pVCur1 = *(*uintptr)(unsafe.Pointer(pCur4 + 36))
|
|
pVtab3 = (*Tsqlite3_vtab_cursor)(unsafe.Pointer(pVCur1)).FpVtab
|
|
pModule3 = (*Tsqlite3_vtab)(unsafe.Pointer(pVtab3)).FpModule
|
|
/* Grab the index number and argc parameters */
|
|
nArg = int32(*(*Ti64)(unsafe.Pointer(pArgc)))
|
|
iQuery = int32(*(*Ti64)(unsafe.Pointer(pQuery)))
|
|
/* Invoke the xFilter method */
|
|
apArg = (*TVdbe)(unsafe.Pointer(p)).FapArg
|
|
i6 = 0
|
|
for {
|
|
if !(i6 < nArg) {
|
|
break
|
|
}
|
|
**(**uintptr)(__ccgo_up(apArg + uintptr(i6)*4)) = pArgc + uintptr(i6+int32(1))*40
|
|
goto _291
|
|
_291:
|
|
;
|
|
i6 = i6 + 1
|
|
}
|
|
rc = (*(*func(*libc.TLS, uintptr, int32, uintptr, int32, uintptr) int32)(unsafe.Pointer(&struct{ uintptr }{(*Tsqlite3_module)(unsafe.Pointer(pModule3)).FxFilter})))(tls, pVCur1, iQuery, *(*uintptr)(unsafe.Pointer(pOp + 16)), nArg, apArg)
|
|
_sqlite3VtabImportErrmsg(tls, p, pVtab3)
|
|
if rc != 0 {
|
|
goto abort_due_to_error
|
|
}
|
|
res13 = (*(*func(*libc.TLS, uintptr) int32)(unsafe.Pointer(&struct{ uintptr }{(*Tsqlite3_module)(unsafe.Pointer(pModule3)).FxEof})))(tls, pVCur1)
|
|
(*TVdbeCursor)(unsafe.Pointer(pCur4)).FnullRow = uint8(0)
|
|
if res13 != 0 {
|
|
goto jump_to_p2
|
|
}
|
|
goto _189
|
|
/* Opcode: VColumn P1 P2 P3 * P5
|
|
** Synopsis: r[P3]=vcolumn(P2)
|
|
**
|
|
** Store in register P3 the value of the P2-th column of
|
|
** the current row of the virtual-table of cursor P1.
|
|
**
|
|
** If the VColumn opcode is being used to fetch the value of
|
|
** an unchanging column during an UPDATE operation, then the P5
|
|
** value is OPFLAG_NOCHNG. This will cause the sqlite3_vtab_nochange()
|
|
** function to return true inside the xColumn method of the virtual
|
|
** table implementation. The P5 column might also contain other
|
|
** bits (OPFLAG_LENGTHARG or OPFLAG_TYPEOFARG) but those bits are
|
|
** unused by OP_VColumn.
|
|
*/
|
|
_173:
|
|
;
|
|
pCur5 = **(**uintptr)(__ccgo_up((*TVdbe)(unsafe.Pointer(p)).FapCsr + uintptr((*TOp)(unsafe.Pointer(pOp)).Fp1)*4))
|
|
pDest2 = aMem + uintptr((*TOp)(unsafe.Pointer(pOp)).Fp3)*40
|
|
if (*TVdbeCursor)(unsafe.Pointer(pCur5)).FnullRow != 0 {
|
|
_sqlite3VdbeMemSetNull(tls, pDest2)
|
|
goto _189
|
|
}
|
|
pVtab4 = (*Tsqlite3_vtab_cursor)(unsafe.Pointer(*(*uintptr)(unsafe.Pointer(pCur5 + 36)))).FpVtab
|
|
pModule4 = (*Tsqlite3_vtab)(unsafe.Pointer(pVtab4)).FpModule
|
|
libc.Xmemset(tls, bp+612, 0, uint32(28))
|
|
(**(**Tsqlite3_context)(__ccgo_up(bp + 612))).FpOut = pDest2
|
|
(**(**Tsqlite3_context)(__ccgo_up(bp + 612))).Fenc = encoding
|
|
(**(**TFuncDef)(__ccgo_up(bp + 640))).FpUserData = uintptr(0)
|
|
(**(**TFuncDef)(__ccgo_up(bp + 640))).FfuncFlags = uint32(SQLITE_RESULT_SUBTYPE)
|
|
(**(**Tsqlite3_context)(__ccgo_up(bp + 612))).FpFunc = bp + 640
|
|
if libc.Int32FromUint16((*TOp)(unsafe.Pointer(pOp)).Fp5)&int32(OPFLAG_NOCHNG) != 0 {
|
|
_sqlite3VdbeMemSetNull(tls, pDest2)
|
|
(*TMem)(unsafe.Pointer(pDest2)).Fflags = libc.Uint16FromInt32(libc.Int32FromInt32(MEM_Null) | libc.Int32FromInt32(MEM_Zero))
|
|
*(*int32)(unsafe.Pointer(&(*TMem)(unsafe.Pointer(pDest2)).Fu)) = 0
|
|
} else {
|
|
(*TMem)(unsafe.Pointer(pDest2)).Fflags = libc.Uint16FromInt32(libc.Int32FromUint16((*TMem)(unsafe.Pointer(pDest2)).Fflags) & ^(libc.Int32FromInt32(MEM_TypeMask)|libc.Int32FromInt32(MEM_Zero)) | int32(MEM_Null))
|
|
}
|
|
rc = (*(*func(*libc.TLS, uintptr, uintptr, int32) int32)(unsafe.Pointer(&struct{ uintptr }{(*Tsqlite3_module)(unsafe.Pointer(pModule4)).FxColumn})))(tls, *(*uintptr)(unsafe.Pointer(pCur5 + 36)), bp+612, (*TOp)(unsafe.Pointer(pOp)).Fp2)
|
|
_sqlite3VtabImportErrmsg(tls, p, pVtab4)
|
|
if (**(**Tsqlite3_context)(__ccgo_up(bp + 612))).FisError > 0 {
|
|
_sqlite3VdbeError(tls, p, __ccgo_ts+3942, libc.VaList(bp+696, Xsqlite3_value_text(tls, pDest2)))
|
|
rc = (**(**Tsqlite3_context)(__ccgo_up(bp + 612))).FisError
|
|
}
|
|
_sqlite3VdbeChangeEncoding(tls, pDest2, libc.Int32FromUint8(encoding))
|
|
if rc != 0 {
|
|
goto abort_due_to_error
|
|
}
|
|
goto _189
|
|
/* Opcode: VNext P1 P2 * * *
|
|
**
|
|
** Advance virtual table P1 to the next row in its result set and
|
|
** jump to instruction P2. Or, if the virtual table has reached
|
|
** the end of its result set, then fall through to the next instruction.
|
|
*/
|
|
_174:
|
|
;
|
|
pCur6 = **(**uintptr)(__ccgo_up((*TVdbe)(unsafe.Pointer(p)).FapCsr + uintptr((*TOp)(unsafe.Pointer(pOp)).Fp1)*4))
|
|
if (*TVdbeCursor)(unsafe.Pointer(pCur6)).FnullRow != 0 {
|
|
goto _189
|
|
}
|
|
pVtab5 = (*Tsqlite3_vtab_cursor)(unsafe.Pointer(*(*uintptr)(unsafe.Pointer(pCur6 + 36)))).FpVtab
|
|
pModule5 = (*Tsqlite3_vtab)(unsafe.Pointer(pVtab5)).FpModule
|
|
/* Invoke the xNext() method of the module. There is no way for the
|
|
** underlying implementation to return an error if one occurs during
|
|
** xNext(). Instead, if an error occurs, true is returned (indicating that
|
|
** data is available) and the error code returned when xColumn or
|
|
** some other method is next invoked on the save virtual table cursor.
|
|
*/
|
|
rc = (*(*func(*libc.TLS, uintptr) int32)(unsafe.Pointer(&struct{ uintptr }{(*Tsqlite3_module)(unsafe.Pointer(pModule5)).FxNext})))(tls, *(*uintptr)(unsafe.Pointer(pCur6 + 36)))
|
|
_sqlite3VtabImportErrmsg(tls, p, pVtab5)
|
|
if rc != 0 {
|
|
goto abort_due_to_error
|
|
}
|
|
res14 = (*(*func(*libc.TLS, uintptr) int32)(unsafe.Pointer(&struct{ uintptr }{(*Tsqlite3_module)(unsafe.Pointer(pModule5)).FxEof})))(tls, *(*uintptr)(unsafe.Pointer(pCur6 + 36)))
|
|
if !(res14 != 0) {
|
|
/* If there is data, jump to P2 */
|
|
goto jump_to_p2_and_check_for_interrupt
|
|
}
|
|
goto check_for_interrupt
|
|
/* Opcode: VRename P1 * * P4 *
|
|
**
|
|
** P4 is a pointer to a virtual table object, an sqlite3_vtab structure.
|
|
** This opcode invokes the corresponding xRename method. The value
|
|
** in register P1 is passed as the zName argument to the xRename method.
|
|
*/
|
|
_175:
|
|
;
|
|
isLegacy = libc.Int32FromUint64((*Tsqlite3)(unsafe.Pointer(db)).Fflags & libc.Uint64FromInt32(SQLITE_LegacyAlter))
|
|
**(**Tu64)(__ccgo_up(db + 28)) |= uint64(SQLITE_LegacyAlter)
|
|
pVtab6 = (*TVTable)(unsafe.Pointer(*(*uintptr)(unsafe.Pointer(pOp + 16)))).FpVtab
|
|
pName = aMem + uintptr((*TOp)(unsafe.Pointer(pOp)).Fp1)*40
|
|
rc = _sqlite3VdbeChangeEncoding(tls, pName, int32(SQLITE_UTF8))
|
|
if rc != 0 {
|
|
goto abort_due_to_error
|
|
}
|
|
rc = (*(*func(*libc.TLS, uintptr, uintptr) int32)(unsafe.Pointer(&struct{ uintptr }{(*Tsqlite3_module)(unsafe.Pointer((*Tsqlite3_vtab)(unsafe.Pointer(pVtab6)).FpModule)).FxRename})))(tls, pVtab6, (*TMem)(unsafe.Pointer(pName)).Fz)
|
|
if isLegacy == 0 {
|
|
**(**Tu64)(__ccgo_up(db + 28)) &= ^libc.Uint64FromInt32(SQLITE_LegacyAlter)
|
|
}
|
|
_sqlite3VtabImportErrmsg(tls, p, pVtab6)
|
|
libc.SetBitFieldPtr16Uint32(p+144, libc.Uint32FromInt32(0), 0, 0x3)
|
|
if rc != 0 {
|
|
goto abort_due_to_error
|
|
}
|
|
goto _189
|
|
/* Opcode: VUpdate P1 P2 P3 P4 P5
|
|
** Synopsis: data=r[P3@P2]
|
|
**
|
|
** P4 is a pointer to a virtual table object, an sqlite3_vtab structure.
|
|
** This opcode invokes the corresponding xUpdate method. P2 values
|
|
** are contiguous memory cells starting at P3 to pass to the xUpdate
|
|
** invocation. The value in register (P3+P2-1) corresponds to the
|
|
** p2th element of the argv array passed to xUpdate.
|
|
**
|
|
** The xUpdate method will do a DELETE or an INSERT or both.
|
|
** The argv[0] element (which corresponds to memory cell P3)
|
|
** is the rowid of a row to delete. If argv[0] is NULL then no
|
|
** deletion occurs. The argv[1] element is the rowid of the new
|
|
** row. This can be NULL to have the virtual table select the new
|
|
** rowid for itself. The subsequent elements in the array are
|
|
** the values of columns in the new row.
|
|
**
|
|
** If P2==1 then no insert is performed. argv[0] is the rowid of
|
|
** a row to delete.
|
|
**
|
|
** P1 is a boolean flag. If it is set to true and the xUpdate call
|
|
** is successful, then the value returned by sqlite3_last_insert_rowid()
|
|
** is set to the value of the rowid for the row just inserted.
|
|
**
|
|
** P5 is the error actions (OE_Replace, OE_Fail, OE_Ignore, etc) to
|
|
** apply in the case of a constraint failure on an insert or update.
|
|
*/
|
|
_176:
|
|
;
|
|
**(**Tsqlite_int64)(__ccgo_up(bp + 680)) = 0
|
|
if (*Tsqlite3)(unsafe.Pointer(db)).FmallocFailed != 0 {
|
|
goto no_mem
|
|
}
|
|
pVtab7 = (*TVTable)(unsafe.Pointer(*(*uintptr)(unsafe.Pointer(pOp + 16)))).FpVtab
|
|
if pVtab7 == uintptr(0) || (*Tsqlite3_vtab)(unsafe.Pointer(pVtab7)).FpModule == uintptr(0) {
|
|
rc = int32(SQLITE_LOCKED)
|
|
goto abort_due_to_error
|
|
}
|
|
pModule6 = (*Tsqlite3_vtab)(unsafe.Pointer(pVtab7)).FpModule
|
|
nArg1 = (*TOp)(unsafe.Pointer(pOp)).Fp2
|
|
if (*Tsqlite3_module)(unsafe.Pointer(pModule6)).FxUpdate != 0 {
|
|
vtabOnConflict = (*Tsqlite3)(unsafe.Pointer(db)).FvtabOnConflict
|
|
apArg1 = (*TVdbe)(unsafe.Pointer(p)).FapArg
|
|
pX1 = aMem + uintptr((*TOp)(unsafe.Pointer(pOp)).Fp3)*40
|
|
i7 = 0
|
|
for {
|
|
if !(i7 < nArg1) {
|
|
break
|
|
}
|
|
**(**uintptr)(__ccgo_up(apArg1 + uintptr(i7)*4)) = pX1
|
|
pX1 += 40
|
|
goto _292
|
|
_292:
|
|
;
|
|
i7 = i7 + 1
|
|
}
|
|
(*Tsqlite3)(unsafe.Pointer(db)).FvtabOnConflict = uint8((*TOp)(unsafe.Pointer(pOp)).Fp5)
|
|
rc = (*(*func(*libc.TLS, uintptr, int32, uintptr, uintptr) int32)(unsafe.Pointer(&struct{ uintptr }{(*Tsqlite3_module)(unsafe.Pointer(pModule6)).FxUpdate})))(tls, pVtab7, nArg1, apArg1, bp+680)
|
|
(*Tsqlite3)(unsafe.Pointer(db)).FvtabOnConflict = vtabOnConflict
|
|
_sqlite3VtabImportErrmsg(tls, p, pVtab7)
|
|
if rc == SQLITE_OK && (*TOp)(unsafe.Pointer(pOp)).Fp1 != 0 {
|
|
(*Tsqlite3)(unsafe.Pointer(db)).FlastRowid = **(**Tsqlite_int64)(__ccgo_up(bp + 680))
|
|
}
|
|
if rc&int32(0xff) == int32(SQLITE_CONSTRAINT) && (*TVTable)(unsafe.Pointer(*(*uintptr)(unsafe.Pointer(pOp + 16)))).FbConstraint != 0 {
|
|
if libc.Int32FromUint16((*TOp)(unsafe.Pointer(pOp)).Fp5) == int32(OE_Ignore) {
|
|
rc = SQLITE_OK
|
|
} else {
|
|
if libc.Int32FromUint16((*TOp)(unsafe.Pointer(pOp)).Fp5) == int32(OE_Replace) {
|
|
v190 = int32(OE_Abort)
|
|
} else {
|
|
v190 = libc.Int32FromUint16((*TOp)(unsafe.Pointer(pOp)).Fp5)
|
|
}
|
|
(*TVdbe)(unsafe.Pointer(p)).FerrorAction = libc.Uint8FromInt32(v190)
|
|
}
|
|
} else {
|
|
(*TVdbe)(unsafe.Pointer(p)).FnChange = (*TVdbe)(unsafe.Pointer(p)).FnChange + 1
|
|
}
|
|
if rc != 0 {
|
|
goto abort_due_to_error
|
|
}
|
|
}
|
|
goto _189
|
|
/* Opcode: Pagecount P1 P2 * * *
|
|
**
|
|
** Write the current number of pages in database P1 to memory cell P2.
|
|
*/
|
|
_177:
|
|
; /* out2 */
|
|
pOut = _out2Prerelease(tls, p, pOp)
|
|
*(*Ti64)(unsafe.Pointer(pOut)) = libc.Int64FromUint32(_sqlite3BtreeLastPage(tls, (**(**TDb)(__ccgo_up((*Tsqlite3)(unsafe.Pointer(db)).FaDb + uintptr((*TOp)(unsafe.Pointer(pOp)).Fp1)*16))).FpBt))
|
|
goto _189
|
|
/* Opcode: MaxPgcnt P1 P2 P3 * *
|
|
**
|
|
** Try to set the maximum page count for database P1 to the value in P3.
|
|
** Do not let the maximum page count fall below the current page count and
|
|
** do not change the maximum page count value if P3==0.
|
|
**
|
|
** Store the maximum page count after the change in register P2.
|
|
*/
|
|
_178:
|
|
;
|
|
pOut = _out2Prerelease(tls, p, pOp)
|
|
pBt3 = (**(**TDb)(__ccgo_up((*Tsqlite3)(unsafe.Pointer(db)).FaDb + uintptr((*TOp)(unsafe.Pointer(pOp)).Fp1)*16))).FpBt
|
|
newMax = uint32(0)
|
|
if (*TOp)(unsafe.Pointer(pOp)).Fp3 != 0 {
|
|
newMax = _sqlite3BtreeLastPage(tls, pBt3)
|
|
if newMax < libc.Uint32FromInt32((*TOp)(unsafe.Pointer(pOp)).Fp3) {
|
|
newMax = libc.Uint32FromInt32((*TOp)(unsafe.Pointer(pOp)).Fp3)
|
|
}
|
|
}
|
|
*(*Ti64)(unsafe.Pointer(pOut)) = libc.Int64FromUint32(_sqlite3BtreeMaxPageCount(tls, pBt3, newMax))
|
|
goto _189
|
|
/* Opcode: Function P1 P2 P3 P4 *
|
|
** Synopsis: r[P3]=func(r[P2@NP])
|
|
**
|
|
** Invoke a user function (P4 is a pointer to an sqlite3_context object that
|
|
** contains a pointer to the function to be run) with arguments taken
|
|
** from register P2 and successors. The number of arguments is in
|
|
** the sqlite3_context object that P4 points to.
|
|
** The result of the function is stored
|
|
** in register P3. Register P3 must not be one of the function inputs.
|
|
**
|
|
** P1 is a 32-bit bitmask indicating whether or not each argument to the
|
|
** function was determined to be constant at compile time. If the first
|
|
** argument was constant then bit 0 of P1 is set. This is used to determine
|
|
** whether meta data associated with a user function argument using the
|
|
** sqlite3_set_auxdata() API may be safely retained until the next
|
|
** invocation of this opcode.
|
|
**
|
|
** See also: AggStep, AggFinal, PureFunc
|
|
*/
|
|
/* Opcode: PureFunc P1 P2 P3 P4 *
|
|
** Synopsis: r[P3]=func(r[P2@NP])
|
|
**
|
|
** Invoke a user function (P4 is a pointer to an sqlite3_context object that
|
|
** contains a pointer to the function to be run) with arguments taken
|
|
** from register P2 and successors. The number of arguments is in
|
|
** the sqlite3_context object that P4 points to.
|
|
** The result of the function is stored
|
|
** in register P3. Register P3 must not be one of the function inputs.
|
|
**
|
|
** P1 is a 32-bit bitmask indicating whether or not each argument to the
|
|
** function was determined to be constant at compile time. If the first
|
|
** argument was constant then bit 0 of P1 is set. This is used to determine
|
|
** whether meta data associated with a user function argument using the
|
|
** sqlite3_set_auxdata() API may be safely retained until the next
|
|
** invocation of this opcode.
|
|
**
|
|
** This opcode works exactly like OP_Function. The only difference is in
|
|
** its name. This opcode is used in places where the function must be
|
|
** purely non-deterministic. Some built-in date/time functions can be
|
|
** either deterministic of non-deterministic, depending on their arguments.
|
|
** When those function are used in a non-deterministic way, they will check
|
|
** to see if they were called using OP_PureFunc instead of OP_Function, and
|
|
** if they were, they throw an error.
|
|
**
|
|
** See also: AggStep, AggFinal, Function
|
|
*/
|
|
_180:
|
|
; /* group */
|
|
_179:
|
|
;
|
|
pCtx2 = *(*uintptr)(unsafe.Pointer(pOp + 16))
|
|
/* If this function is inside of a trigger, the register array in aMem[]
|
|
** might change from one evaluation to the next. The next block of code
|
|
** checks to see if the register array has changed, and if so it
|
|
** reinitializes the relevant parts of the sqlite3_context object */
|
|
pOut = aMem + uintptr((*TOp)(unsafe.Pointer(pOp)).Fp3)*40
|
|
if (*Tsqlite3_context)(unsafe.Pointer(pCtx2)).FpOut != pOut {
|
|
(*Tsqlite3_context)(unsafe.Pointer(pCtx2)).FpVdbe = p
|
|
(*Tsqlite3_context)(unsafe.Pointer(pCtx2)).FpOut = pOut
|
|
(*Tsqlite3_context)(unsafe.Pointer(pCtx2)).Fenc = encoding
|
|
i8 = libc.Int32FromUint16((*Tsqlite3_context)(unsafe.Pointer(pCtx2)).Fargc) - int32(1)
|
|
for {
|
|
if !(i8 >= 0) {
|
|
break
|
|
}
|
|
*(*uintptr)(unsafe.Pointer(pCtx2 + 28 + uintptr(i8)*4)) = aMem + uintptr((*TOp)(unsafe.Pointer(pOp)).Fp2+i8)*40
|
|
goto _294
|
|
_294:
|
|
;
|
|
i8 = i8 - 1
|
|
}
|
|
}
|
|
(*TMem)(unsafe.Pointer(pOut)).Fflags = libc.Uint16FromInt32(libc.Int32FromUint16((*TMem)(unsafe.Pointer(pOut)).Fflags) & ^(libc.Int32FromInt32(MEM_TypeMask)|libc.Int32FromInt32(MEM_Zero)) | int32(MEM_Null))
|
|
(*(*func(*libc.TLS, uintptr, int32, uintptr))(unsafe.Pointer(&struct{ uintptr }{(*TFuncDef)(unsafe.Pointer((*Tsqlite3_context)(unsafe.Pointer(pCtx2)).FpFunc)).FxSFunc})))(tls, pCtx2, libc.Int32FromUint16((*Tsqlite3_context)(unsafe.Pointer(pCtx2)).Fargc), pCtx2+28) /* IMP: R-24505-23230 */
|
|
/* If the function returned an error, throw an exception */
|
|
if (*Tsqlite3_context)(unsafe.Pointer(pCtx2)).FisError != 0 {
|
|
if (*Tsqlite3_context)(unsafe.Pointer(pCtx2)).FisError > 0 {
|
|
_sqlite3VdbeError(tls, p, __ccgo_ts+3942, libc.VaList(bp+696, Xsqlite3_value_text(tls, pOut)))
|
|
rc = (*Tsqlite3_context)(unsafe.Pointer(pCtx2)).FisError
|
|
}
|
|
_sqlite3VdbeDeleteAuxData(tls, db, p+220, (*Tsqlite3_context)(unsafe.Pointer(pCtx2)).FiOp, (*TOp)(unsafe.Pointer(pOp)).Fp1)
|
|
(*Tsqlite3_context)(unsafe.Pointer(pCtx2)).FisError = 0
|
|
if rc != 0 {
|
|
goto abort_due_to_error
|
|
}
|
|
}
|
|
goto _189
|
|
/* Opcode: ClrSubtype P1 * * * *
|
|
** Synopsis: r[P1].subtype = 0
|
|
**
|
|
** Clear the subtype from register P1.
|
|
*/
|
|
_181:
|
|
; /* in1 */
|
|
pIn1 = aMem + uintptr((*TOp)(unsafe.Pointer(pOp)).Fp1)*40
|
|
v191 = pIn1 + 16
|
|
*(*Tu16)(unsafe.Pointer(v191)) = Tu16(int32(*(*Tu16)(unsafe.Pointer(v191))) & ^libc.Int32FromInt32(MEM_Subtype))
|
|
goto _189
|
|
/* Opcode: GetSubtype P1 P2 * * *
|
|
** Synopsis: r[P2] = r[P1].subtype
|
|
**
|
|
** Extract the subtype value from register P1 and write that subtype
|
|
** into register P2. If P1 has no subtype, then P1 gets a NULL.
|
|
*/
|
|
_182:
|
|
; /* in1 out2 */
|
|
pIn1 = aMem + uintptr((*TOp)(unsafe.Pointer(pOp)).Fp1)*40
|
|
pOut = aMem + uintptr((*TOp)(unsafe.Pointer(pOp)).Fp2)*40
|
|
if libc.Int32FromUint16((*TMem)(unsafe.Pointer(pIn1)).Fflags)&int32(MEM_Subtype) != 0 {
|
|
_sqlite3VdbeMemSetInt64(tls, pOut, libc.Int64FromUint8((*TMem)(unsafe.Pointer(pIn1)).FeSubtype))
|
|
} else {
|
|
_sqlite3VdbeMemSetNull(tls, pOut)
|
|
}
|
|
goto _189
|
|
/* Opcode: SetSubtype P1 P2 * * *
|
|
** Synopsis: r[P2].subtype = r[P1]
|
|
**
|
|
** Set the subtype value of register P2 to the integer from register P1.
|
|
** If P1 is NULL, clear the subtype from p2.
|
|
*/
|
|
_183:
|
|
; /* in1 out2 */
|
|
pIn1 = aMem + uintptr((*TOp)(unsafe.Pointer(pOp)).Fp1)*40
|
|
pOut = aMem + uintptr((*TOp)(unsafe.Pointer(pOp)).Fp2)*40
|
|
if libc.Int32FromUint16((*TMem)(unsafe.Pointer(pIn1)).Fflags)&int32(MEM_Null) != 0 {
|
|
v191 = pOut + 16
|
|
*(*Tu16)(unsafe.Pointer(v191)) = Tu16(int32(*(*Tu16)(unsafe.Pointer(v191))) & ^libc.Int32FromInt32(MEM_Subtype))
|
|
} else {
|
|
v191 = pOut + 16
|
|
*(*Tu16)(unsafe.Pointer(v191)) = Tu16(int32(*(*Tu16)(unsafe.Pointer(v191))) | libc.Int32FromInt32(MEM_Subtype))
|
|
(*TMem)(unsafe.Pointer(pOut)).FeSubtype = libc.Uint8FromInt64(*(*Ti64)(unsafe.Pointer(pIn1)) & libc.Int64FromInt32(0xff))
|
|
}
|
|
goto _189
|
|
/* Opcode: FilterAdd P1 * P3 P4 *
|
|
** Synopsis: filter(P1) += key(P3@P4)
|
|
**
|
|
** Compute a hash on the P4 registers starting with r[P3] and
|
|
** add that hash to the bloom filter contained in r[P1].
|
|
*/
|
|
_184:
|
|
;
|
|
pIn1 = aMem + uintptr((*TOp)(unsafe.Pointer(pOp)).Fp1)*40
|
|
h = _filterHash(tls, aMem, pOp)
|
|
h = h % libc.Uint64FromInt32((*TMem)(unsafe.Pointer(pIn1)).Fn*libc.Int32FromInt32(8))
|
|
v191 = (*TMem)(unsafe.Pointer(pIn1)).Fz + uintptr(h/uint64(8))
|
|
*(*int8)(unsafe.Pointer(v191)) = int8(int32(*(*int8)(unsafe.Pointer(v191))) | libc.Int32FromInt32(1)<<(h&libc.Uint64FromInt32(7)))
|
|
goto _189
|
|
/* Opcode: Filter P1 P2 P3 P4 *
|
|
** Synopsis: if key(P3@P4) not in filter(P1) goto P2
|
|
**
|
|
** Compute a hash on the key contained in the P4 registers starting
|
|
** with r[P3]. Check to see if that hash is found in the
|
|
** bloom filter hosted by register P1. If it is not present then
|
|
** maybe jump to P2. Otherwise fall through.
|
|
**
|
|
** False negatives are harmless. It is always safe to fall through,
|
|
** even if the value is in the bloom filter. A false negative causes
|
|
** more CPU cycles to be used, but it should still yield the correct
|
|
** answer. However, an incorrect answer may well arise from a
|
|
** false positive - if the jump is taken when it should fall through.
|
|
*/
|
|
_185:
|
|
;
|
|
pIn1 = aMem + uintptr((*TOp)(unsafe.Pointer(pOp)).Fp1)*40
|
|
h1 = _filterHash(tls, aMem, pOp)
|
|
h1 = h1 % libc.Uint64FromInt32((*TMem)(unsafe.Pointer(pIn1)).Fn*libc.Int32FromInt32(8))
|
|
if int32(**(**int8)(__ccgo_up((*TMem)(unsafe.Pointer(pIn1)).Fz + uintptr(h1/uint64(8)))))&(int32(1)<<(h1&uint64(7))) == 0 {
|
|
**(**Tu32)(__ccgo_up(p + 156 + 8*4)) = **(**Tu32)(__ccgo_up(p + 156 + 8*4)) + 1
|
|
goto jump_to_p2
|
|
} else {
|
|
**(**Tu32)(__ccgo_up(p + 156 + 7*4)) = **(**Tu32)(__ccgo_up(p + 156 + 7*4)) + 1
|
|
}
|
|
goto _189
|
|
/* Opcode: Trace P1 P2 * P4 *
|
|
**
|
|
** Write P4 on the statement trace output if statement tracing is
|
|
** enabled.
|
|
**
|
|
** Operand P1 must be 0x7fffffff and P2 must positive.
|
|
*/
|
|
/* Opcode: Init P1 P2 P3 P4 *
|
|
** Synopsis: Start at P2
|
|
**
|
|
** Programs contain a single instance of this opcode as the very first
|
|
** opcode.
|
|
**
|
|
** If tracing is enabled (by the sqlite3_trace()) interface, then
|
|
** the UTF-8 string contained in P4 is emitted on the trace callback.
|
|
** Or if P4 is blank, use the string returned by sqlite3_sql().
|
|
**
|
|
** If P2 is not zero, jump to instruction P2.
|
|
**
|
|
** Increment the value of P1 so that OP_Once opcodes will jump the
|
|
** first time they are evaluated for this run.
|
|
**
|
|
** If P3 is not zero, then it is an address to jump to if an SQLITE_CORRUPT
|
|
** error is encountered.
|
|
*/
|
|
_187:
|
|
;
|
|
_186:
|
|
;
|
|
/* If the P4 argument is not NULL, then it must be an SQL comment string.
|
|
** The "--" string is broken up to prevent false-positives with srcck1.c.
|
|
**
|
|
** This assert() provides evidence for:
|
|
** EVIDENCE-OF: R-50676-09860 The callback can compute the same text that
|
|
** would have been returned by the legacy sqlite3_trace() interface by
|
|
** using the X argument when X begins with "--" and invoking
|
|
** sqlite3_expanded_sql(P) otherwise.
|
|
*/
|
|
/* OP_Init is always instruction 0 */
|
|
if v217 = libc.Int32FromUint8((*Tsqlite3)(unsafe.Pointer(db)).FmTrace)&(libc.Int32FromInt32(SQLITE_TRACE_STMT)|libc.Int32FromInt32(SQLITE_TRACE_LEGACY)) != 0 && libc.Int32FromUint8((*TVdbe)(unsafe.Pointer(p)).FminWriteFileFormat) != int32(254); v217 {
|
|
if *(*uintptr)(unsafe.Pointer(pOp + 16)) != 0 {
|
|
v194 = *(*uintptr)(unsafe.Pointer(pOp + 16))
|
|
} else {
|
|
v194 = (*TVdbe)(unsafe.Pointer(p)).FzSql
|
|
}
|
|
v191 = v194
|
|
zTrace = v191
|
|
}
|
|
if v217 && v191 != uintptr(0) {
|
|
if libc.Int32FromUint8((*Tsqlite3)(unsafe.Pointer(db)).FmTrace)&int32(SQLITE_TRACE_LEGACY) != 0 {
|
|
z2 = _sqlite3VdbeExpandSql(tls, p, zTrace)
|
|
(*(*func(*libc.TLS, uintptr, uintptr))(unsafe.Pointer(&struct{ uintptr }{(*Tsqlite3)(unsafe.Pointer(db)).Ftrace.FxLegacy})))(tls, (*Tsqlite3)(unsafe.Pointer(db)).FpTraceArg, z2)
|
|
Xsqlite3_free(tls, z2)
|
|
} else {
|
|
if (*Tsqlite3)(unsafe.Pointer(db)).FnVdbeExec > int32(1) {
|
|
z3 = _sqlite3MPrintf(tls, db, __ccgo_ts+6483, libc.VaList(bp+696, zTrace))
|
|
(*(*func(*libc.TLS, Tu32, uintptr, uintptr, uintptr) int32)(unsafe.Pointer(&struct{ uintptr }{*(*uintptr)(unsafe.Pointer(&(*Tsqlite3)(unsafe.Pointer(db)).Ftrace))})))(tls, uint32(SQLITE_TRACE_STMT), (*Tsqlite3)(unsafe.Pointer(db)).FpTraceArg, p, z3)
|
|
_sqlite3DbFree(tls, db, z3)
|
|
} else {
|
|
(*(*func(*libc.TLS, Tu32, uintptr, uintptr, uintptr) int32)(unsafe.Pointer(&struct{ uintptr }{*(*uintptr)(unsafe.Pointer(&(*Tsqlite3)(unsafe.Pointer(db)).Ftrace))})))(tls, uint32(SQLITE_TRACE_STMT), (*Tsqlite3)(unsafe.Pointer(db)).FpTraceArg, p, zTrace)
|
|
}
|
|
}
|
|
}
|
|
if (*TOp)(unsafe.Pointer(pOp)).Fp1 >= _sqlite3Config.FiOnceResetThreshold {
|
|
if libc.Int32FromUint8((*TOp)(unsafe.Pointer(pOp)).Fopcode) == int32(OP_Trace) {
|
|
goto _189
|
|
}
|
|
i9 = int32(1)
|
|
for {
|
|
if !(i9 < (*TVdbe)(unsafe.Pointer(p)).FnOp) {
|
|
break
|
|
}
|
|
if libc.Int32FromUint8((**(**TOp)(__ccgo_up((*TVdbe)(unsafe.Pointer(p)).FaOp + uintptr(i9)*20))).Fopcode) == int32(OP_Once) {
|
|
(**(**TOp)(__ccgo_up((*TVdbe)(unsafe.Pointer(p)).FaOp + uintptr(i9)*20))).Fp1 = 0
|
|
}
|
|
goto _302
|
|
_302:
|
|
;
|
|
i9 = i9 + 1
|
|
}
|
|
(*TOp)(unsafe.Pointer(pOp)).Fp1 = 0
|
|
}
|
|
(*TOp)(unsafe.Pointer(pOp)).Fp1 = (*TOp)(unsafe.Pointer(pOp)).Fp1 + 1
|
|
**(**Tu32)(__ccgo_up(p + 156 + 6*4)) = **(**Tu32)(__ccgo_up(p + 156 + 6*4)) + 1
|
|
goto jump_to_p2
|
|
/* Opcode: Noop * * * * *
|
|
**
|
|
** Do nothing. Continue downward to the next opcode.
|
|
*/
|
|
/* Opcode: Explain P1 P2 P3 P4 *
|
|
**
|
|
** This is the same as OP_Noop during normal query execution. The
|
|
** purpose of this opcode is to hold information about the query
|
|
** plan for the purpose of EXPLAIN QUERY PLAN output.
|
|
**
|
|
** The P4 value is human-readable text that describes the query plan
|
|
** element. Something like "SCAN t1" or "SEARCH t2 USING INDEX t2x1".
|
|
**
|
|
** The P1 value is the ID of the current element and P2 is the parent
|
|
** element for the case of nested query plan elements. If P2 is zero
|
|
** then this element is a top-level element.
|
|
**
|
|
** For loop elements, P3 is the estimated code of each invocation of this
|
|
** element.
|
|
**
|
|
** As with all opcodes, the meanings of the parameters for OP_Explain
|
|
** are subject to change from one release to the next. Applications
|
|
** should not attempt to interpret or use any of the information
|
|
** contained in the OP_Explain opcode. The information provided by this
|
|
** opcode is intended for testing and debugging use only.
|
|
*/
|
|
_188:
|
|
; /* This is really OP_Noop, OP_Explain */
|
|
goto _189
|
|
/*****************************************************************************
|
|
** The cases of the switch statement above this line should all be indented
|
|
** by 6 spaces. But the left-most 6 spaces have been removed to improve the
|
|
** readability. From this point on down, the normal indentation rules are
|
|
** restored.
|
|
*****************************************************************************/
|
|
_189:
|
|
;
|
|
/* The following code adds nothing to the actual functionality
|
|
** of the program. It is only here for testing and debugging.
|
|
** On the other hand, it does burn CPU cycles every time through
|
|
** the evaluator loop. So we can leave it out when NDEBUG is defined.
|
|
*/
|
|
goto _1
|
|
_1:
|
|
;
|
|
pOp += 20
|
|
} /* The end of the for(;;) loop the loops through opcodes */
|
|
/* If we reach this point, it means that execution is finished with
|
|
** an error of some kind.
|
|
*/
|
|
goto abort_due_to_error
|
|
abort_due_to_error:
|
|
;
|
|
if (*Tsqlite3)(unsafe.Pointer(db)).FmallocFailed != 0 {
|
|
rc = int32(SQLITE_NOMEM)
|
|
} else {
|
|
if rc == libc.Int32FromInt32(SQLITE_IOERR)|libc.Int32FromInt32(33)<<libc.Int32FromInt32(8) {
|
|
rc = _sqlite3CorruptError(tls, int32(105898))
|
|
}
|
|
}
|
|
if (*TVdbe)(unsafe.Pointer(p)).FzErrMsg == uintptr(0) && rc != libc.Int32FromInt32(SQLITE_IOERR)|libc.Int32FromInt32(12)<<libc.Int32FromInt32(8) {
|
|
_sqlite3VdbeError(tls, p, __ccgo_ts+3942, libc.VaList(bp+696, _sqlite3ErrStr(tls, rc)))
|
|
}
|
|
(*TVdbe)(unsafe.Pointer(p)).Frc = rc
|
|
_sqlite3SystemError(tls, db, rc)
|
|
_sqlite3VdbeLogAbort(tls, p, rc, pOp, aOp)
|
|
if libc.Int32FromUint8((*TVdbe)(unsafe.Pointer(p)).FeVdbeState) == int32(VDBE_RUN_STATE) {
|
|
_sqlite3VdbeHalt(tls, p)
|
|
}
|
|
if rc == libc.Int32FromInt32(SQLITE_IOERR)|libc.Int32FromInt32(12)<<libc.Int32FromInt32(8) {
|
|
_sqlite3OomFault(tls, db)
|
|
}
|
|
if rc == int32(SQLITE_CORRUPT) && libc.Int32FromUint8((*Tsqlite3)(unsafe.Pointer(db)).FautoCommit) == 0 {
|
|
**(**Tu64)(__ccgo_up(db + 28)) |= libc.Uint64FromInt32(libc.Int32FromInt32(0x00002)) << libc.Int32FromInt32(32)
|
|
}
|
|
rc = int32(SQLITE_ERROR)
|
|
if libc.Int32FromUint8(resetSchemaOnFault) > 0 {
|
|
_sqlite3ResetOneSchema(tls, db, libc.Int32FromUint8(resetSchemaOnFault)-int32(1))
|
|
}
|
|
/* This is the only way out of this procedure. We have to
|
|
** release the mutexes on btrees that were acquired at the
|
|
** top. */
|
|
goto vdbe_return
|
|
vdbe_return:
|
|
;
|
|
for nVmStep >= nProgressLimit && (*Tsqlite3)(unsafe.Pointer(db)).FxProgress != uintptr(0) {
|
|
nProgressLimit = nProgressLimit + uint64((*Tsqlite3)(unsafe.Pointer(db)).FnProgressOps)
|
|
if (*(*func(*libc.TLS, uintptr) int32)(unsafe.Pointer(&struct{ uintptr }{(*Tsqlite3)(unsafe.Pointer(db)).FxProgress})))(tls, (*Tsqlite3)(unsafe.Pointer(db)).FpProgressArg) != 0 {
|
|
nProgressLimit = libc.Uint64FromUint32(0xffffffff) | libc.Uint64FromUint32(0xffffffff)<<libc.Int32FromInt32(32)
|
|
rc = int32(SQLITE_INTERRUPT)
|
|
goto abort_due_to_error
|
|
}
|
|
}
|
|
**(**Tu32)(__ccgo_up(p + 156 + 4*4)) += libc.Uint32FromInt32(libc.Int32FromUint64(nVmStep))
|
|
if (*TVdbe)(unsafe.Pointer(p)).FlockMask != uint32(0) {
|
|
_sqlite3VdbeLeave(tls, p)
|
|
}
|
|
return rc
|
|
/* Jump to here if a string or blob larger than SQLITE_MAX_LENGTH
|
|
** is encountered.
|
|
*/
|
|
goto too_big
|
|
too_big:
|
|
;
|
|
_sqlite3VdbeError(tls, p, __ccgo_ts+5592, 0)
|
|
rc = int32(SQLITE_TOOBIG)
|
|
goto abort_due_to_error
|
|
/* Jump to here if a malloc() fails.
|
|
*/
|
|
goto no_mem
|
|
no_mem:
|
|
;
|
|
_sqlite3OomFault(tls, db)
|
|
_sqlite3VdbeError(tls, p, __ccgo_ts+1672, 0)
|
|
rc = int32(SQLITE_NOMEM)
|
|
goto abort_due_to_error
|
|
/* Jump to here if the sqlite3_interrupt() API sets the interrupt
|
|
** flag.
|
|
*/
|
|
goto abort_due_to_interrupt
|
|
abort_due_to_interrupt:
|
|
;
|
|
rc = int32(SQLITE_INTERRUPT)
|
|
goto abort_due_to_error
|
|
return r
|
|
}
|
|
|
|
// C documentation
|
|
//
|
|
// /*
|
|
// ** This function returns a pointer to a nul-terminated string in memory
|
|
// ** obtained from sqlite3DbMalloc(). If sqlite3.nVdbeExec is 1, then the
|
|
// ** string contains a copy of zRawSql but with host parameters expanded to
|
|
// ** their current bindings. Or, if sqlite3.nVdbeExec is greater than 1,
|
|
// ** then the returned string holds a copy of zRawSql with "-- " prepended
|
|
// ** to each line of text.
|
|
// **
|
|
// ** If the SQLITE_TRACE_SIZE_LIMIT macro is defined to an integer, then
|
|
// ** then long strings and blobs are truncated to that many bytes. This
|
|
// ** can be used to prevent unreasonably large trace strings when dealing
|
|
// ** with large (multi-megabyte) strings and blobs.
|
|
// **
|
|
// ** The calling function is responsible for making sure the memory returned
|
|
// ** is eventually freed.
|
|
// **
|
|
// ** ALGORITHM: Scan the input string looking for host parameters in any of
|
|
// ** these forms: ?, ?N, $A, @A, :A. Take care to avoid text within
|
|
// ** string literals, quoted identifier names, and comments. For text forms,
|
|
// ** the host parameter index is found by scanning the prepared
|
|
// ** statement for the corresponding OP_Variable opcode. Once the host
|
|
// ** parameter index is known, locate the value in p->aVar[]. Then render
|
|
// ** the value as a literal in place of the host parameter name.
|
|
// */
|
|
func _sqlite3VdbeExpandSql(tls *libc.TLS, p uintptr, zRawSql uintptr) (r uintptr) {
|
|
bp := tls.Alloc(112)
|
|
defer tls.Free(112)
|
|
var db, pVar, zStart, v1 uintptr
|
|
var enc Tu8
|
|
var i, nOut, nOut1, nextIndex, v2 int32
|
|
var n Ti64
|
|
var _ /* idx at bp+0 */ int32
|
|
var _ /* nToken at bp+8 */ Ti64
|
|
var _ /* out at bp+16 */ TStrAccum
|
|
var _ /* utf8 at bp+40 */ TMem
|
|
_, _, _, _, _, _, _, _, _, _, _ = db, enc, i, n, nOut, nOut1, nextIndex, pVar, zStart, v1, v2 /* The database connection */
|
|
**(**int32)(__ccgo_up(bp)) = 0 /* Index of a host parameter */
|
|
nextIndex = int32(1) /* Used to convert UTF16 into UTF8 for display */
|
|
db = (*TVdbe)(unsafe.Pointer(p)).Fdb
|
|
_sqlite3StrAccumInit(tls, bp+16, uintptr(0), uintptr(0), 0, **(**int32)(__ccgo_up(db + 116)))
|
|
if (*Tsqlite3)(unsafe.Pointer(db)).FnVdbeExec > int32(1) {
|
|
for **(**int8)(__ccgo_up(zRawSql)) != 0 {
|
|
zStart = zRawSql
|
|
for {
|
|
v1 = zRawSql
|
|
zRawSql = zRawSql + 1
|
|
if !(int32(**(**int8)(__ccgo_up(v1))) != int32('\n') && **(**int8)(__ccgo_up(zRawSql)) != 0) {
|
|
break
|
|
}
|
|
}
|
|
Xsqlite3_str_append(tls, bp+16, __ccgo_ts+5715, int32(3))
|
|
Xsqlite3_str_append(tls, bp+16, zStart, int32(zRawSql)-int32(zStart))
|
|
}
|
|
} else {
|
|
if int32((*TVdbe)(unsafe.Pointer(p)).FnVar) == 0 {
|
|
Xsqlite3_str_append(tls, bp+16, zRawSql, _sqlite3Strlen30(tls, zRawSql))
|
|
} else {
|
|
for **(**int8)(__ccgo_up(zRawSql)) != 0 {
|
|
n = _findNextHostParameter(tls, zRawSql, bp+8)
|
|
Xsqlite3_str_append(tls, bp+16, zRawSql, int32(n))
|
|
zRawSql = zRawSql + uintptr(n)
|
|
if **(**Ti64)(__ccgo_up(bp + 8)) == 0 {
|
|
break
|
|
}
|
|
if int32(**(**int8)(__ccgo_up(zRawSql))) == int32('?') {
|
|
if **(**Ti64)(__ccgo_up(bp + 8)) > int64(1) {
|
|
_sqlite3GetInt32(tls, zRawSql+1, bp)
|
|
} else {
|
|
**(**int32)(__ccgo_up(bp)) = nextIndex
|
|
}
|
|
} else {
|
|
**(**int32)(__ccgo_up(bp)) = _sqlite3VdbeParameterIndex(tls, p, zRawSql, int32(**(**Ti64)(__ccgo_up(bp + 8))))
|
|
}
|
|
zRawSql = zRawSql + uintptr(**(**Ti64)(__ccgo_up(bp + 8)))
|
|
if **(**int32)(__ccgo_up(bp))+int32(1) > nextIndex {
|
|
v2 = **(**int32)(__ccgo_up(bp)) + int32(1)
|
|
} else {
|
|
v2 = nextIndex
|
|
}
|
|
nextIndex = v2
|
|
pVar = (*TVdbe)(unsafe.Pointer(p)).FaVar + uintptr(**(**int32)(__ccgo_up(bp))-int32(1))*40
|
|
if libc.Int32FromUint16((*TMem)(unsafe.Pointer(pVar)).Fflags)&int32(MEM_Null) != 0 {
|
|
Xsqlite3_str_append(tls, bp+16, __ccgo_ts+1703, int32(4))
|
|
} else {
|
|
if libc.Int32FromUint16((*TMem)(unsafe.Pointer(pVar)).Fflags)&(libc.Int32FromInt32(MEM_Int)|libc.Int32FromInt32(MEM_IntReal)) != 0 {
|
|
Xsqlite3_str_appendf(tls, bp+16, __ccgo_ts+1463, libc.VaList(bp+88, *(*Ti64)(unsafe.Pointer(pVar))))
|
|
} else {
|
|
if libc.Int32FromUint16((*TMem)(unsafe.Pointer(pVar)).Fflags)&int32(MEM_Real) != 0 {
|
|
Xsqlite3_str_appendf(tls, bp+16, __ccgo_ts+5719, libc.VaList(bp+88, *(*float64)(unsafe.Pointer(pVar))))
|
|
} else {
|
|
if libc.Int32FromUint16((*TMem)(unsafe.Pointer(pVar)).Fflags)&int32(MEM_Str) != 0 { /* Number of bytes of the string text to include in output */
|
|
enc = (*Tsqlite3)(unsafe.Pointer(db)).Fenc
|
|
if libc.Int32FromUint8(enc) != int32(SQLITE_UTF8) {
|
|
libc.Xmemset(tls, bp+40, 0, uint32(40))
|
|
(**(**TMem)(__ccgo_up(bp + 40))).Fdb = db
|
|
_sqlite3VdbeMemSetStr(tls, bp+40, (*TMem)(unsafe.Pointer(pVar)).Fz, int64((*TMem)(unsafe.Pointer(pVar)).Fn), enc, libc.UintptrFromInt32(0))
|
|
if int32(SQLITE_NOMEM) == _sqlite3VdbeChangeEncoding(tls, bp+40, int32(SQLITE_UTF8)) {
|
|
(**(**TStrAccum)(__ccgo_up(bp + 16))).FaccError = uint8(SQLITE_NOMEM)
|
|
(**(**TStrAccum)(__ccgo_up(bp + 16))).FnAlloc = uint32(0)
|
|
}
|
|
pVar = bp + 40
|
|
}
|
|
nOut = (*TMem)(unsafe.Pointer(pVar)).Fn
|
|
Xsqlite3_str_appendf(tls, bp+16, __ccgo_ts+5726, libc.VaList(bp+88, nOut, (*TMem)(unsafe.Pointer(pVar)).Fz))
|
|
if libc.Int32FromUint8(enc) != int32(SQLITE_UTF8) {
|
|
_sqlite3VdbeMemRelease(tls, bp+40)
|
|
}
|
|
} else {
|
|
if libc.Int32FromUint16((*TMem)(unsafe.Pointer(pVar)).Fflags)&int32(MEM_Zero) != 0 {
|
|
Xsqlite3_str_appendf(tls, bp+16, __ccgo_ts+5733, libc.VaList(bp+88, *(*int32)(unsafe.Pointer(&(*TMem)(unsafe.Pointer(pVar)).Fu))))
|
|
} else { /* Number of bytes of the blob to include in output */
|
|
Xsqlite3_str_append(tls, bp+16, __ccgo_ts+5746, int32(2))
|
|
nOut1 = (*TMem)(unsafe.Pointer(pVar)).Fn
|
|
i = 0
|
|
for {
|
|
if !(i < nOut1) {
|
|
break
|
|
}
|
|
Xsqlite3_str_appendf(tls, bp+16, __ccgo_ts+5749, libc.VaList(bp+88, int32(**(**int8)(__ccgo_up((*TMem)(unsafe.Pointer(pVar)).Fz + uintptr(i))))&int32(0xff)))
|
|
goto _3
|
|
_3:
|
|
;
|
|
i = i + 1
|
|
}
|
|
Xsqlite3_str_append(tls, bp+16, __ccgo_ts+5754, int32(1))
|
|
}
|
|
}
|
|
}
|
|
}
|
|
}
|
|
}
|
|
}
|
|
}
|
|
if (**(**TStrAccum)(__ccgo_up(bp + 16))).FaccError != 0 {
|
|
Xsqlite3_str_reset(tls, bp+16)
|
|
}
|
|
return _sqlite3StrAccumFinish(tls, bp+16)
|
|
}
|
|
|
|
/************** End of vdbetrace.c *******************************************/
|
|
/************** Begin file vdbe.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.
|
|
**
|
|
*************************************************************************
|
|
** The code in this file implements the function that runs the
|
|
** bytecode of a prepared statement.
|
|
**
|
|
** Various scripts scan this source file in order to generate HTML
|
|
** documentation, headers files, or other derived files. The formatting
|
|
** of the code in this file is, therefore, important. See other comments
|
|
** in this file for details. If in doubt, do not deviate from existing
|
|
** commenting and indentation practices when changing or adding code.
|
|
*/
|
|
/* #include "sqliteInt.h" */
|
|
/* #include "vdbeInt.h" */
|
|
|
|
/*
|
|
** High-resolution hardware timer used for debugging and testing only.
|
|
*/
|
|
|
|
/*
|
|
** Invoke this macro on memory cells just prior to changing the
|
|
** value of the cell. This macro verifies that shallow copies are
|
|
** not misused. A shallow copy of a string or blob just copies a
|
|
** pointer to the string or blob, not the content. If the original
|
|
** is changed while the copy is still in use, the string or blob might
|
|
** be changed out from under the copy. This macro verifies that nothing
|
|
** like that ever happens.
|
|
*/
|
|
|
|
/*
|
|
** The following global variable is incremented every time a cursor
|
|
** moves, either by the OP_SeekXX, OP_Next, or OP_Prev opcodes. The test
|
|
** procedures use this information to make sure that indices are
|
|
** working correctly. This variable has no function other than to
|
|
** help verify the correct operation of the library.
|
|
*/
|
|
|
|
/*
|
|
** When this global variable is positive, it gets decremented once before
|
|
** each instruction in the VDBE. When it reaches zero, the u1.isInterrupted
|
|
** field of the sqlite3 structure is set in order to simulate an interrupt.
|
|
**
|
|
** This facility is used for testing purposes only. It does not function
|
|
** in an ordinary build.
|
|
*/
|
|
|
|
/*
|
|
** The next global variable is incremented each type the OP_Sort opcode
|
|
** is executed. The test procedures use this information to make sure that
|
|
** sorting is occurring or not occurring at appropriate times. This variable
|
|
** has no function other than to help verify the correct operation of the
|
|
** library.
|
|
*/
|
|
|
|
/*
|
|
** The next global variable records the size of the largest MEM_Blob
|
|
** or MEM_Str that has been used by a VDBE opcode. The test procedures
|
|
** use this information to make sure that the zero-blob functionality
|
|
** is working correctly. This variable has no function other than to
|
|
** help verify the correct operation of the library.
|
|
*/
|
|
|
|
/*
|
|
** This macro evaluates to true if either the update hook or the preupdate
|
|
** hook are enabled for database connect DB.
|
|
*/
|
|
|
|
/*
|
|
** The next global variable is incremented each time the OP_Found opcode
|
|
** is executed. This is used to test whether or not the foreign key
|
|
** operation implemented using OP_FkIsZero is working. This variable
|
|
** has no function other than to help verify the correct operation of the
|
|
** library.
|
|
*/
|
|
|
|
/*
|
|
** Test a register to see if it exceeds the current maximum blob size.
|
|
** If it does, record the new maximum blob size.
|
|
*/
|
|
|
|
/*
|
|
** Invoke the VDBE coverage callback, if that callback is defined. This
|
|
** feature is used for test suite validation only and does not appear an
|
|
** production builds.
|
|
**
|
|
** M is the type of branch. I is the direction taken for this instance of
|
|
** the branch.
|
|
**
|
|
** M: 2 - two-way branch (I=0: fall-thru 1: jump )
|
|
** 3 - two-way + NULL (I=0: fall-thru 1: jump 2: NULL )
|
|
** 4 - OP_Jump (I=0: jump p1 1: jump p2 2: jump p3)
|
|
**
|
|
** In other words, if M is 2, then I is either 0 (for fall-through) or
|
|
** 1 (for when the branch is taken). If M is 3, the I is 0 for an
|
|
** ordinary fall-through, I is 1 if the branch was taken, and I is 2
|
|
** if the result of comparison is NULL. For M=3, I=2 the jump may or
|
|
** may not be taken, depending on the SQLITE_JUMPIFNULL flags in p5.
|
|
** When M is 4, that means that an OP_Jump is being run. I is 0, 1, or 2
|
|
** depending on if the operands are less than, equal, or greater than.
|
|
**
|
|
** iSrcLine is the source code line (from the __LINE__ macro) that
|
|
** generated the VDBE instruction combined with flag bits. The source
|
|
** code line number is in the lower 24 bits of iSrcLine and the upper
|
|
** 8 bytes are flags. The lower three bits of the flags indicate
|
|
** values for I that should never occur. For example, if the branch is
|
|
** always taken, the flags should be 0x05 since the fall-through and
|
|
** alternate branch are never taken. If a branch is never taken then
|
|
** flags should be 0x06 since only the fall-through approach is allowed.
|
|
**
|
|
** Bit 0x08 of the flags indicates an OP_Jump opcode that is only
|
|
** interested in equal or not-equal. In other words, I==0 and I==2
|
|
** should be treated as equivalent
|
|
**
|
|
** Since only a line number is retained, not the filename, this macro
|
|
** only works for amalgamation builds. But that is ok, since these macros
|
|
** should be no-ops except for special builds used to measure test coverage.
|
|
*/
|
|
|
|
/*
|
|
** An ephemeral string value (signified by the MEM_Ephem flag) contains
|
|
** a pointer to a dynamically allocated string where some other entity
|
|
** is responsible for deallocating that string. Because the register
|
|
** does not control the string, it might be deleted without the register
|
|
** knowing it.
|
|
**
|
|
** This routine converts an ephemeral string into a dynamically allocated
|
|
** string that the register itself controls. In other words, it
|
|
** converts an MEM_Ephem string into a string with P.z==P.zMalloc.
|
|
*/
|
|
|
|
/* Return true if the cursor was opened using the OP_OpenSorter opcode. */
|
|
|
|
// C documentation
|
|
//
|
|
// /*
|
|
// ** Send a "statement aborts" message to the error log.
|
|
// */
|
|
func _sqlite3VdbeLogAbort(tls *libc.TLS, p uintptr, rc int32, pOp uintptr, aOp uintptr) {
|
|
bp := tls.Alloc(144)
|
|
defer tls.Free(144)
|
|
var pc int32
|
|
var zPrefix, zSql uintptr
|
|
var _ /* zXtra at bp+0 */ [100]int8
|
|
_, _, _ = pc, zPrefix, zSql
|
|
zSql = (*TVdbe)(unsafe.Pointer(p)).FzSql /* Original SQL text */
|
|
zPrefix = __ccgo_ts + 1702 /* Buffer space to store zPrefix */
|
|
if (*TVdbe)(unsafe.Pointer(p)).FpFrame != 0 {
|
|
if *(*uintptr)(unsafe.Pointer(aOp + 16)) != uintptr(0) {
|
|
Xsqlite3_snprintf(tls, int32(100), bp, __ccgo_ts+5756, libc.VaList(bp+112, *(*uintptr)(unsafe.Pointer(aOp + 16))+uintptr(3)))
|
|
zPrefix = bp
|
|
} else {
|
|
zPrefix = __ccgo_ts + 5766
|
|
}
|
|
}
|
|
pc = (int32(pOp) - int32(aOp)) / 20
|
|
Xsqlite3_log(tls, rc, __ccgo_ts+5789, libc.VaList(bp+112, pc, (*TVdbe)(unsafe.Pointer(p)).FzErrMsg, zPrefix, zSql))
|
|
}
|
|
|
|
// 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 + 44))).FazArg))
|
|
pMod = _sqlite3HashFind(tls, db+400, zMod)
|
|
if !(pMod != 0) {
|
|
zModule = **(**uintptr)(__ccgo_up((*(*struct {
|
|
FnArg int32
|
|
FazArg uintptr
|
|
Fp uintptr
|
|
})(unsafe.Pointer(pTab + 44))).FazArg))
|
|
_sqlite3ErrorMsg(tls, pParse, __ccgo_ts+23588, 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+3942, 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)*16))).FzDbSName)
|
|
/* Locate the required virtual table module */
|
|
zMod = **(**uintptr)(__ccgo_up((*(*struct {
|
|
FnArg int32
|
|
FazArg uintptr
|
|
Fp uintptr
|
|
})(unsafe.Pointer(pTab + 44))).FazArg))
|
|
pMod = _sqlite3HashFind(tls, db+400, 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+23588, 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
|
|
//
|
|
// /*
|
|
// ** This function sets the P4 value of an existing OP_Explain opcode to
|
|
// ** text describing the loop in pLevel. If the OP_Explain opcode already has
|
|
// ** a P4 value, it is freed before it is overwritten.
|
|
// */
|
|
func _sqlite3WhereAddExplainText(tls *libc.TLS, pParse uintptr, addr int32, pTabList uintptr, pLevel uintptr, wctrlFlags Tu16) {
|
|
bp := tls.Alloc(160)
|
|
defer tls.Free(160)
|
|
var cRangeOp int8
|
|
var db, pIdx, pItem, pLoop, pOp, zFmt, zRowid, v1, v2 uintptr
|
|
var flags Tu32
|
|
var isSearch int32
|
|
var _ /* str at bp+0 */ TStrAccum
|
|
var _ /* zBuf at bp+24 */ [100]int8
|
|
_, _, _, _, _, _, _, _, _, _, _, _ = cRangeOp, db, flags, isSearch, pIdx, pItem, pLoop, pOp, zFmt, zRowid, v1, v2
|
|
if (*TParse)(unsafe.Pointer(pParse)).FpToplevel != 0 {
|
|
v1 = (*TParse)(unsafe.Pointer(pParse)).FpToplevel
|
|
} else {
|
|
v1 = pParse
|
|
}
|
|
if libc.Int32FromUint8((*TParse)(unsafe.Pointer(v1)).Fexplain) == int32(2) || libc.Bool(0 != 0) {
|
|
pOp = _sqlite3VdbeGetOp(tls, (*TParse)(unsafe.Pointer(pParse)).FpVdbe, addr)
|
|
pItem = pTabList + 8 + uintptr((*TWhereLevel)(unsafe.Pointer(pLevel)).FiFrom)*48
|
|
db = (*TParse)(unsafe.Pointer(pParse)).Fdb /* Initial space for EQP output string */
|
|
if (*Tsqlite3)(unsafe.Pointer(db)).FmallocFailed != 0 {
|
|
return
|
|
}
|
|
pLoop = (*TWhereLevel)(unsafe.Pointer(pLevel)).FpWLoop
|
|
flags = (*TWhereLoop)(unsafe.Pointer(pLoop)).FwsFlags
|
|
isSearch = libc.BoolInt32(flags&libc.Uint32FromInt32(libc.Int32FromInt32(WHERE_BTM_LIMIT)|libc.Int32FromInt32(WHERE_TOP_LIMIT)) != uint32(0) || flags&uint32(WHERE_VIRTUALTABLE) == uint32(0) && libc.Int32FromUint16((*(*struct {
|
|
FnEq Tu16
|
|
FnBtm Tu16
|
|
FnTop Tu16
|
|
FnDistinctCol Tu16
|
|
FpIndex uintptr
|
|
FpOrderBy uintptr
|
|
})(unsafe.Pointer(pLoop + 24))).FnEq) > 0 || libc.Int32FromUint16(wctrlFlags)&(libc.Int32FromInt32(WHERE_ORDERBY_MIN)|libc.Int32FromInt32(WHERE_ORDERBY_MAX)) != 0)
|
|
_sqlite3StrAccumInit(tls, bp, db, bp+24, int32(100), int32(SQLITE_MAX_LENGTH))
|
|
(**(**TStrAccum)(__ccgo_up(bp))).FprintfFlags = uint8(SQLITE_PRINTF_INTERNAL)
|
|
if isSearch != 0 {
|
|
v1 = __ccgo_ts + 23655
|
|
} else {
|
|
v1 = __ccgo_ts + 23662
|
|
}
|
|
if int32(*(*uint32)(unsafe.Pointer(pItem + 12 + 4))&0x40000>>18) != 0 {
|
|
v2 = __ccgo_ts + 23667
|
|
} else {
|
|
v2 = __ccgo_ts + 1702
|
|
}
|
|
Xsqlite3_str_appendf(tls, bp, __ccgo_ts+23675, libc.VaList(bp+136, v1, pItem, v2))
|
|
if flags&libc.Uint32FromInt32(libc.Int32FromInt32(WHERE_IPK)|libc.Int32FromInt32(WHERE_VIRTUALTABLE)) == uint32(0) {
|
|
zFmt = uintptr(0)
|
|
pIdx = (*(*struct {
|
|
FnEq Tu16
|
|
FnBtm Tu16
|
|
FnTop Tu16
|
|
FnDistinctCol Tu16
|
|
FpIndex uintptr
|
|
FpOrderBy uintptr
|
|
})(unsafe.Pointer(pLoop + 24))).FpIndex
|
|
if !((*TTable)(unsafe.Pointer((*TSrcItem)(unsafe.Pointer(pItem)).FpSTab)).FtabFlags&libc.Uint32FromInt32(TF_WithoutRowid) == libc.Uint32FromInt32(0)) && int32(uint32(*(*uint16)(unsafe.Pointer(pIdx + 56))&0x3>>0)) == int32(SQLITE_IDXTYPE_PRIMARYKEY) {
|
|
if isSearch != 0 {
|
|
zFmt = __ccgo_ts + 11594
|
|
}
|
|
} else {
|
|
if flags&uint32(WHERE_PARTIALIDX) != 0 {
|
|
zFmt = __ccgo_ts + 23683
|
|
} else {
|
|
if flags&uint32(WHERE_AUTO_INDEX) != 0 {
|
|
zFmt = __ccgo_ts + 23716
|
|
} else {
|
|
if flags&libc.Uint32FromInt32(libc.Int32FromInt32(WHERE_IDX_ONLY)|libc.Int32FromInt32(WHERE_EXPRIDX)) != 0 {
|
|
zFmt = __ccgo_ts + 23741
|
|
} else {
|
|
zFmt = __ccgo_ts + 23759
|
|
}
|
|
}
|
|
}
|
|
}
|
|
if zFmt != 0 {
|
|
Xsqlite3_str_append(tls, bp, __ccgo_ts+23768, int32(7))
|
|
Xsqlite3_str_appendf(tls, bp, zFmt, libc.VaList(bp+136, (*TIndex)(unsafe.Pointer(pIdx)).FzName))
|
|
_explainIndexRange(tls, bp, pLoop)
|
|
}
|
|
} else {
|
|
if flags&uint32(WHERE_IPK) != uint32(0) && flags&uint32(WHERE_CONSTRAINT) != uint32(0) {
|
|
zRowid = __ccgo_ts + 17965
|
|
Xsqlite3_str_appendf(tls, bp, __ccgo_ts+23776, libc.VaList(bp+136, zRowid))
|
|
if flags&libc.Uint32FromInt32(libc.Int32FromInt32(WHERE_COLUMN_EQ)|libc.Int32FromInt32(WHERE_COLUMN_IN)) != 0 {
|
|
cRangeOp = int8('=')
|
|
} else {
|
|
if flags&uint32(WHERE_BOTH_LIMIT) == uint32(WHERE_BOTH_LIMIT) {
|
|
Xsqlite3_str_appendf(tls, bp, __ccgo_ts+23807, libc.VaList(bp+136, zRowid))
|
|
cRangeOp = int8('<')
|
|
} else {
|
|
if flags&uint32(WHERE_BTM_LIMIT) != 0 {
|
|
cRangeOp = int8('>')
|
|
} else {
|
|
cRangeOp = int8('<')
|
|
}
|
|
}
|
|
}
|
|
Xsqlite3_str_appendf(tls, bp, __ccgo_ts+23817, libc.VaList(bp+136, int32(cRangeOp)))
|
|
} else {
|
|
if flags&uint32(WHERE_VIRTUALTABLE) != uint32(0) {
|
|
Xsqlite3_str_appendall(tls, bp, __ccgo_ts+23822)
|
|
if int32(Tu32(*(*uint8)(unsafe.Pointer(pLoop + 24 + 4))&0x4>>2)) != 0 {
|
|
v1 = __ccgo_ts + 23844
|
|
} else {
|
|
v1 = __ccgo_ts + 23852
|
|
}
|
|
Xsqlite3_str_appendf(tls, bp, v1, libc.VaList(bp+136, (*(*struct {
|
|
FidxNum int32
|
|
F__ccgo4 uint8
|
|
FisOrdered Ti8
|
|
FomitMask Tu16
|
|
FidxStr uintptr
|
|
FmHandleIn Tu32
|
|
})(unsafe.Pointer(pLoop + 24))).FidxNum, (*(*struct {
|
|
FidxNum int32
|
|
F__ccgo4 uint8
|
|
FisOrdered Ti8
|
|
FomitMask Tu16
|
|
FidxStr uintptr
|
|
FmHandleIn Tu32
|
|
})(unsafe.Pointer(pLoop + 24))).FidxStr))
|
|
}
|
|
}
|
|
}
|
|
if libc.Int32FromUint8((*TSrcItem)(unsafe.Pointer(pItem)).Ffg.Fjointype)&int32(JT_LEFT) != 0 {
|
|
Xsqlite3_str_appendf(tls, bp, __ccgo_ts+23858, 0)
|
|
}
|
|
_sqlite3DbFree(tls, db, *(*uintptr)(unsafe.Pointer(pOp + 16)))
|
|
(*TVdbeOp)(unsafe.Pointer(pOp)).Fp4type = int8(-libc.Int32FromInt32(7))
|
|
*(*uintptr)(unsafe.Pointer(pOp + 16)) = _sqlite3StrAccumFinish(tls, bp)
|
|
}
|
|
}
|
|
|
|
// 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(48)
|
|
defer tls.Free(48)
|
|
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, uint32(32))
|
|
/* An ORDER/GROUP BY clause of more than 63 terms cannot be optimized */
|
|
if pOrderBy != 0 && (*TExprList)(unsafe.Pointer(pOrderBy)).FnExpr >= libc.Int32FromUint32(libc.Uint32FromInt64(8)*libc.Uint32FromInt32(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.Int32FromUint32(libc.Uint32FromInt64(8)*libc.Uint32FromInt32(8)) {
|
|
_sqlite3ErrorMsg(tls, pParse, __ccgo_ts+24102, libc.VaList(bp+40, libc.Int32FromUint32(libc.Uint32FromInt64(8)*libc.Uint32FromInt32(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.Int32FromUint32((uint32(libc.UintptrFromInt32(0)+752) + libc.Uint32FromInt32(nTabList)*libc.Uint32FromInt64(88) + libc.Uint32FromInt32(7)) & libc.Uint32FromInt32(^libc.Int32FromInt32(7)))
|
|
pWInfo = _sqlite3DbMallocRawNN(tls, db, uint64(libc.Uint32FromInt32(nByteWInfo)+uint32(72)))
|
|
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 + 20 + 1*4)) = v1
|
|
**(**int32)(__ccgo_up(pWInfo + 20)) = 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+45, 0, uint32(libc.UintptrFromInt32(0)+76)-uint32(libc.UintptrFromInt32(0)+45))
|
|
libc.Xmemset(tls, pWInfo+752, 0, uint32(72)+libc.Uint32FromInt32(nTabList)*uint32(88))
|
|
/* ONEPASS defaults to OFF */
|
|
pMaskSet = pWInfo + 488
|
|
(*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 + 76
|
|
(**(**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+76, pWInfo)
|
|
_sqlite3WhereSplit(tls, pWInfo+76, 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+24130, 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)*48))).FiCursor)
|
|
_sqlite3WhereTabFuncArgs(tls, pParse, pTabList+8+uintptr(ii)*48, pWInfo+76)
|
|
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+76)
|
|
if pSelect != 0 && (*TSelect)(unsafe.Pointer(pSelect)).FpLimit != 0 {
|
|
_sqlite3WhereAddLimit(tls, pWInfo+76, 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)*48 /* 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 + 10
|
|
*(*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 + 40
|
|
*(*Tu16)(unsafe.Pointer(v7)) = Tu16(int32(*(*Tu16)(unsafe.Pointer(v7))) & ^libc.Int32FromInt32(WHERE_WANT_DISTINCT))
|
|
} else {
|
|
if _isDistinctRedundant(tls, pParse, pTabList, pWInfo+76, 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 + 40
|
|
*(*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 + 50
|
|
*(*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 + 16
|
|
*(*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 + 752))).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 + 752))).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 + 752
|
|
for {
|
|
if !(ii < nTabList) {
|
|
break
|
|
}
|
|
pTabItem = pTabList + 8 + uintptr((*TWhereLevel)(unsafe.Pointer(pLevel)).FiFrom)*48
|
|
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 + 752 + uintptr(ii-int32(1))*88))).FpRJ != 0 {
|
|
(*TWhereLevel)(unsafe.Pointer(pLevel)).FaddrHalt = (*(*TWhereLevel)(unsafe.Pointer(pWInfo + 752 + uintptr(ii-int32(1))*88))).FaddrBrk
|
|
} else {
|
|
(*TWhereLevel)(unsafe.Pointer(pLevel)).FaddrHalt = (*(*TWhereLevel)(unsafe.Pointer(pWInfo + 752 + uintptr(ii-int32(1))*88))).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 + 20)) = (*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.Int32FromUint32(libc.Uint32FromInt64(8)*libc.Uint32FromInt32(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(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 + 752))).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 + 56))&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 + 20 + 1*4)) = iIndexCur
|
|
} else {
|
|
if iAuxArg != 0 && libc.Int32FromUint16(wctrlFlags)&int32(WHERE_OR_SUBCLAUSE) != 0 {
|
|
iIndexCur = iAuxArg
|
|
op1 = int32(OP_ReopenIdx)
|
|
} else {
|
|
v7 = pParse + 44
|
|
v1 = *(*int32)(unsafe.Pointer(v7))
|
|
*(*int32)(unsafe.Pointer(v7)) = *(*int32)(unsafe.Pointer(v7)) + 1
|
|
iIndexCur = v1
|
|
if int32(uint32(*(*uint16)(unsafe.Pointer(pIx + 56))&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 + 44
|
|
v1 = *(*int32)(unsafe.Pointer(v8))
|
|
*(*int32)(unsafe.Pointer(v8)) = *(*int32)(unsafe.Pointer(v8)) + 1
|
|
(*TWhereRightJoin)(unsafe.Pointer(pRJ)).FiMatch = v1
|
|
v7 = pParse + 48
|
|
*(*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 + 48
|
|
*(*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 + 20)) = 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 + 40)) &= 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 += 88
|
|
}
|
|
(*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 + 752 + uintptr(ii)*88
|
|
wsFlags1 = libc.Int32FromUint32((*TWhereLoop)(unsafe.Pointer((*TWhereLevel)(unsafe.Pointer(pLevel)).FpWLoop)).FwsFlags)
|
|
pSrc = pTabList + 8 + uintptr((*TWhereLevel)(unsafe.Pointer(pLevel)).FiFrom)*48
|
|
if int32(*(*uint32)(unsafe.Pointer(pSrc + 12 + 4))&0x20>>5) != 0 {
|
|
iOnce = 0
|
|
pSubq = *(*uintptr)(unsafe.Pointer(pSrc + 44))
|
|
if int32(*(*uint32)(unsafe.Pointer(pSrc + 12 + 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+76, 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(80)
|
|
defer tls.Free(80)
|
|
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+8 */ TExpr
|
|
var _ /* zStartAff at bp+4 */ 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 + 76
|
|
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)*48
|
|
iCur = (*TSrcItem)(unsafe.Pointer(pTabItem)).FiCursor
|
|
(*TWhereLevel)(unsafe.Pointer(pLevel)).FnotReady = notReady & ^_sqlite3WhereGetMask(tls, pWInfo+488, 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 + 48
|
|
*(*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 + 12 + 4))&0x40>>6) != 0 {
|
|
pSubq = *(*uintptr)(unsafe.Pointer(pTabItem + 44))
|
|
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)*4))
|
|
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 + 44
|
|
v1 = *(*int32)(unsafe.Pointer(v4))
|
|
*(*int32)(unsafe.Pointer(v4)) = *(*int32)(unsafe.Pointer(v4)) + 1
|
|
iTab = v1
|
|
v8 = pParse + 48
|
|
*(*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)*4))
|
|
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 + 68))).FnIn) {
|
|
break
|
|
}
|
|
pOp = _sqlite3VdbeGetOp(tls, v, (**(**TInLoop)(__ccgo_up((*(*struct {
|
|
FnIn int32
|
|
FaInLoop uintptr
|
|
})(unsafe.Pointer(pLevel + 68))).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 + 24))).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 + 20)) + 8 + uintptr(iFld-int32(1))*20))).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 + 48
|
|
*(*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)*4))
|
|
}
|
|
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)*4))
|
|
}
|
|
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 + 48
|
|
*(*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 + 48
|
|
*(*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)*4))
|
|
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)*4))
|
|
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)*12 + 4))&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 + 48
|
|
*(*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+4)
|
|
if **(**uintptr)(__ccgo_up(bp + 4)) != 0 && nTop != 0 {
|
|
zEndAff = _sqlite3DbStrDup(tls, db, **(**uintptr)(__ccgo_up(bp + 4))+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 + 4)) != 0 {
|
|
_updateRangeAffinityStr(tls, pRight2, libc.Int32FromUint16(nBtm), **(**uintptr)(__ccgo_up(bp + 4))+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 + 4)))
|
|
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 + 4)) != 0 {
|
|
_sqlite3DbNNFreeNN(tls, db, **(**uintptr)(__ccgo_up(bp + 4)))
|
|
}
|
|
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 + 68))).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 + 44
|
|
v1 = *(*int32)(unsafe.Pointer(v4))
|
|
*(*int32)(unsafe.Pointer(v4)) = *(*int32)(unsafe.Pointer(v4)) + 1 /* Potential covering index (or NULL) */
|
|
iCovCur = v1
|
|
v8 = pParse + 48
|
|
*(*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(&(*TWhereTerm)(unsafe.Pointer(pTerm)).Fu))
|
|
(*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 + 12 + 4))&0x40000>>18) != 0 { /* Original list of tables */
|
|
nNotReady = libc.Int32FromUint8((*TWhereInfo)(unsafe.Pointer(pWInfo)).FnLevel) - iLevel - int32(1)
|
|
pOrTab = _sqlite3DbMallocRawNN(tls, db, uint64(uint32(libc.UintptrFromInt32(0)+8)+libc.Uint32FromInt32(nNotReady+libc.Int32FromInt32(1))*libc.Uint32FromInt64(48)))
|
|
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, uint32(48))
|
|
origSrc = (*TWhereInfo)(unsafe.Pointer(pWInfo)).FpTabList + 8
|
|
k = int32(1)
|
|
for {
|
|
if !(k <= nNotReady) {
|
|
break
|
|
}
|
|
libc.Xmemcpy(tls, pOrTab+8+uintptr(k)*48, origSrc+uintptr((**(**TWhereLevel)(__ccgo_up(pLevel + uintptr(k)*88))).FiFrom)*48, uint32(48))
|
|
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+12+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 + 48
|
|
*(*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 + 44
|
|
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 + 48
|
|
*(*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)*48))).FpExpr
|
|
if (*TWhereClause)(unsafe.Pointer(pWC)).Fa+uintptr(iTerm)*48 == pTerm {
|
|
goto _53
|
|
}
|
|
if libc.Int32FromUint16((**(**TWhereTerm)(__ccgo_up((*TWhereClause)(unsafe.Pointer(pWC)).Fa + uintptr(iTerm)*48))).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)*48))).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+23898, 0)
|
|
ii = 0
|
|
for {
|
|
if !(ii < (*TWhereClause)(unsafe.Pointer(pOrWc)).FnTerm) {
|
|
break
|
|
}
|
|
pOrTerm = (*TWhereClause)(unsafe.Pointer(pOrWc)).Fa + uintptr(ii)*48
|
|
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+23913, libc.VaList(bp+72, 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+752, 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 + 48))&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 + 752))).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 + 56))&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+48, 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 + 12 + 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+48, 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+488, *(*int32)(unsafe.Pointer(pE + 36)))
|
|
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 + 10
|
|
*(*Tu16)(unsafe.Pointer(v4)) = Tu16(int32(*(*Tu16)(unsafe.Pointer(v4))) | libc.Int32FromInt32(TERM_CODED))
|
|
goto _59
|
|
_59:
|
|
;
|
|
j = j - 1
|
|
pTerm += 48
|
|
}
|
|
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 + 24))).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 + 20)))).FpEList)).FnExpr > int32(1) {
|
|
goto _61
|
|
}
|
|
**(**TExpr)(__ccgo_up(bp + 8)) = **(**TExpr)(__ccgo_up((*TWhereTerm)(unsafe.Pointer(pAlt)).FpExpr))
|
|
(**(**TExpr)(__ccgo_up(bp + 8))).FpLeft = (*TExpr)(unsafe.Pointer(pE1)).FpLeft
|
|
_sqlite3ExprIfFalse(tls, pParse, bp+8, addrCont, int32(SQLITE_JUMPIFNULL))
|
|
v4 = pAlt + 10
|
|
*(*Tu16)(unsafe.Pointer(v4)) = Tu16(int32(*(*Tu16)(unsafe.Pointer(v4))) | libc.Int32FromInt32(TERM_CODED))
|
|
goto _61
|
|
_61:
|
|
;
|
|
j = j - 1
|
|
pTerm += 48
|
|
}
|
|
/* 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)*48))).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 + 10
|
|
*(*Tu16)(unsafe.Pointer(v4)) = Tu16(int32(*(*Tu16)(unsafe.Pointer(v4))) | libc.Int32FromInt32(TERM_CODED))
|
|
goto _65
|
|
_65:
|
|
;
|
|
j = j + 1
|
|
pTerm += 48
|
|
}
|
|
_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 + 752 + uintptr(i)*88
|
|
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 + 56))&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 + 48)) += 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)*48 + 12 + 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 + 68))).FnIn > 0 {
|
|
_sqlite3VdbeResolveLabel(tls, v, (*TWhereLevel)(unsafe.Pointer(pLevel)).FaddrNxt)
|
|
j1 = (*(*struct {
|
|
FnIn int32
|
|
FaInLoop uintptr
|
|
})(unsafe.Pointer(pLevel + 68))).FnIn
|
|
pIn = (*(*struct {
|
|
FnIn int32
|
|
FaInLoop uintptr
|
|
})(unsafe.Pointer(pLevel + 68))).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)*48
|
|
if int32(*(*uint32)(unsafe.Pointer(pSrc + 12 + 4))&0x40>>6) != 0 {
|
|
n1 = (*TSubquery)(unsafe.Pointer(*(*uintptr)(unsafe.Pointer(pSrc + 44)))).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 + 752
|
|
for {
|
|
if !(i < libc.Int32FromUint8((*TWhereInfo)(unsafe.Pointer(pWInfo)).FnLevel)) {
|
|
break
|
|
}
|
|
pIdx1 = uintptr(0)
|
|
pTabItem = pTabList + 8 + uintptr((*TWhereLevel)(unsafe.Pointer(pLevel)).FiFrom)*48
|
|
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 + 12 + 4))&0x40>>6) != 0 {
|
|
_translateColumnToCopy(tls, pParse, (*TWhereLevel)(unsafe.Pointer(pLevel)).FaddrBody, (*TWhereLevel)(unsafe.Pointer(pLevel)).FiTabCur, (*TSubquery)(unsafe.Pointer(*(*uintptr)(unsafe.Pointer(pTabItem + 44)))).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 + 56))&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)*20
|
|
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+24148, 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 + 40)) &= 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 += 20
|
|
v2 = pOp
|
|
if !(v2 < pLastOp) {
|
|
break
|
|
}
|
|
}
|
|
}
|
|
goto _9
|
|
_9:
|
|
;
|
|
i = i + 1
|
|
pLevel += 88
|
|
}
|
|
/* 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 + 23
|
|
*(*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
|
|
//
|
|
// /*
|
|
// ** Add a single OP_Explain opcode that describes a Bloom filter.
|
|
// **
|
|
// ** Or if not processing EXPLAIN QUERY PLAN and not in a SQLITE_DEBUG and/or
|
|
// ** SQLITE_ENABLE_STMT_SCANSTATUS build, then OP_Explain opcodes are not
|
|
// ** required and this routine is a no-op.
|
|
// **
|
|
// ** If an OP_Explain opcode is added to the VM, its address is returned.
|
|
// ** Otherwise, if no OP_Explain is coded, zero is returned.
|
|
// */
|
|
func _sqlite3WhereExplainBloomFilter(tls *libc.TLS, pParse uintptr, pWInfo uintptr, pLevel uintptr) (r int32) {
|
|
bp := tls.Alloc(144)
|
|
defer tls.Free(144)
|
|
var db, pItem, pLoop, pTab, v, z, zMsg uintptr
|
|
var i, ret int32
|
|
var _ /* str at bp+0 */ TStrAccum
|
|
var _ /* zBuf at bp+24 */ [100]int8
|
|
_, _, _, _, _, _, _, _, _ = db, i, pItem, pLoop, pTab, ret, v, z, zMsg
|
|
ret = 0
|
|
pItem = (*TWhereInfo)(unsafe.Pointer(pWInfo)).FpTabList + 8 + uintptr((*TWhereLevel)(unsafe.Pointer(pLevel)).FiFrom)*48
|
|
v = (*TParse)(unsafe.Pointer(pParse)).FpVdbe /* VM being constructed */
|
|
db = (*TParse)(unsafe.Pointer(pParse)).Fdb /* Initial space for EQP output string */
|
|
_sqlite3StrAccumInit(tls, bp, db, bp+24, int32(100), int32(SQLITE_MAX_LENGTH))
|
|
(**(**TStrAccum)(__ccgo_up(bp))).FprintfFlags = uint8(SQLITE_PRINTF_INTERNAL)
|
|
Xsqlite3_str_appendf(tls, bp, __ccgo_ts+23869, libc.VaList(bp+136, pItem))
|
|
pLoop = (*TWhereLevel)(unsafe.Pointer(pLevel)).FpWLoop
|
|
if (*TWhereLoop)(unsafe.Pointer(pLoop)).FwsFlags&uint32(WHERE_IPK) != 0 {
|
|
pTab = (*TSrcItem)(unsafe.Pointer(pItem)).FpSTab
|
|
if int32((*TTable)(unsafe.Pointer(pTab)).FiPKey) >= 0 {
|
|
Xsqlite3_str_appendf(tls, bp, __ccgo_ts+23638, libc.VaList(bp+136, (**(**TColumn)(__ccgo_up((*TTable)(unsafe.Pointer(pTab)).FaCol + uintptr((*TTable)(unsafe.Pointer(pTab)).FiPKey)*12))).FzCnName))
|
|
} else {
|
|
Xsqlite3_str_appendf(tls, bp, __ccgo_ts+23890, 0)
|
|
}
|
|
} else {
|
|
i = libc.Int32FromUint16((*TWhereLoop)(unsafe.Pointer(pLoop)).FnSkip)
|
|
for {
|
|
if !(i < libc.Int32FromUint16((*(*struct {
|
|
FnEq Tu16
|
|
FnBtm Tu16
|
|
FnTop Tu16
|
|
FnDistinctCol Tu16
|
|
FpIndex uintptr
|
|
FpOrderBy uintptr
|
|
})(unsafe.Pointer(pLoop + 24))).FnEq)) {
|
|
break
|
|
}
|
|
z = _explainIndexColumnName(tls, (*(*struct {
|
|
FnEq Tu16
|
|
FnBtm Tu16
|
|
FnTop Tu16
|
|
FnDistinctCol Tu16
|
|
FpIndex uintptr
|
|
FpOrderBy uintptr
|
|
})(unsafe.Pointer(pLoop + 24))).FpIndex, i)
|
|
if i > libc.Int32FromUint16((*TWhereLoop)(unsafe.Pointer(pLoop)).FnSkip) {
|
|
Xsqlite3_str_append(tls, bp, __ccgo_ts+23627, int32(5))
|
|
}
|
|
Xsqlite3_str_appendf(tls, bp, __ccgo_ts+23638, libc.VaList(bp+136, z))
|
|
goto _1
|
|
_1:
|
|
;
|
|
i = i + 1
|
|
}
|
|
}
|
|
Xsqlite3_str_append(tls, bp, __ccgo_ts+5259, int32(1))
|
|
zMsg = _sqlite3StrAccumFinish(tls, bp)
|
|
ret = _sqlite3VdbeAddOp4(tls, v, int32(OP_Explain), _sqlite3VdbeCurrentAddr(tls, v), (*TParse)(unsafe.Pointer(pParse)).FaddrExplain, 0, zMsg, -int32(7))
|
|
return ret
|
|
}
|
|
|
|
// 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(80)
|
|
defer tls.Free(80)
|
|
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][56]Tu8
|
|
FsSrc TSrcList
|
|
F__ccgo_pad2 [48]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 + 76
|
|
pLoop = (*TWhereLevel)(unsafe.Pointer(pLevel)).FpWLoop
|
|
pTabItem = (*TWhereInfo)(unsafe.Pointer(pWInfo)).FpTabList + 8 + uintptr((*TWhereLevel)(unsafe.Pointer(pLevel)).FiFrom)*48
|
|
mAll = uint64(0)
|
|
_sqlite3VdbeExplain(tls, pParse, uint8(1), __ccgo_ts+23922, libc.VaList(bp+64, (*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 + 752 + uintptr(k)*88))).FiFrom)*48
|
|
mAll = mAll | (*TWhereLoop)(unsafe.Pointer((*(*TWhereLevel)(unsafe.Pointer(pWInfo + 752 + uintptr(k)*88))).FpWLoop)).FmaskSelf
|
|
if int32(*(*uint32)(unsafe.Pointer(pRight + 12 + 4))&0x40>>6) != 0 {
|
|
pSubq = *(*uintptr)(unsafe.Pointer(pRight + 44))
|
|
_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 + 752 + uintptr(k)*88))).FiTabCur)
|
|
iIdxCur = (*(*TWhereLevel)(unsafe.Pointer(pWInfo + 752 + uintptr(k)*88))).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)*48
|
|
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, uint32(48))
|
|
(*(*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 + 48
|
|
*(*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 + 48)) += 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
|
|
//
|
|
// /*
|
|
// ** 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(64)
|
|
defer tls.Free(64)
|
|
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+24 */ 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*4)))
|
|
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+13006, libc.VaList(bp+56, 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+13011, libc.VaList(bp+56, 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)*36
|
|
if (*TStatSample)(unsafe.Pointer(pS)).FnRowid == uint32(0) {
|
|
Xsqlite3_result_int64(tls, context, *(*Ti64)(unsafe.Pointer(pS + 12)))
|
|
} else {
|
|
Xsqlite3_result_blob(tls, context, *(*uintptr)(unsafe.Pointer(&(*TStatSample)(unsafe.Pointer(pS)).Fu)), 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)*36))).FanEq
|
|
case int32(STAT_GET_NLT):
|
|
aCnt = (**(**TStatSample)(__ccgo_up((*TStatAccum)(unsafe.Pointer(p)).Fa + uintptr((*TStatAccum)(unsafe.Pointer(p)).FiGet)*36))).FanLt
|
|
default:
|
|
aCnt = (**(**TStatSample)(__ccgo_up((*TStatAccum)(unsafe.Pointer(p)).Fa + uintptr((*TStatAccum)(unsafe.Pointer(p)).FiGet)*36))).FanDLt
|
|
(*TStatAccum)(unsafe.Pointer(p)).FiGet = (*TStatAccum)(unsafe.Pointer(p)).FiGet + 1
|
|
break
|
|
}
|
|
_sqlite3StrAccumInit(tls, bp+24, 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+24, __ccgo_ts+13017, libc.VaList(bp+56, **(**TtRowcnt)(__ccgo_up(aCnt + uintptr(i1)*8))))
|
|
goto _3
|
|
_3:
|
|
;
|
|
i1 = i1 + 1
|
|
}
|
|
if (**(**Tsqlite3_str)(__ccgo_up(bp + 24))).FnChar != 0 {
|
|
(**(**Tsqlite3_str)(__ccgo_up(bp + 24))).FnChar = (**(**Tsqlite3_str)(__ccgo_up(bp + 24))).FnChar - 1
|
|
}
|
|
_sqlite3ResultStrAccum(tls, context, bp+24)
|
|
}
|
|
}
|
|
_ = argc
|
|
}
|
|
|
|
// C documentation
|
|
//
|
|
// /*
|
|
// ** strftime( FORMAT, TIMESTRING, MOD, MOD, ...)
|
|
// **
|
|
// ** Return a string described by FORMAT. Conversions as follows:
|
|
// **
|
|
// ** %d day of month 01-31
|
|
// ** %e day of month 1-31
|
|
// ** %f ** fractional seconds SS.SSS
|
|
// ** %F ISO date. YYYY-MM-DD
|
|
// ** %G ISO year corresponding to %V 0000-9999.
|
|
// ** %g 2-digit ISO year corresponding to %V 00-99
|
|
// ** %H hour 00-24
|
|
// ** %k hour 0-24 (leading zero converted to space)
|
|
// ** %I hour 01-12
|
|
// ** %j day of year 001-366
|
|
// ** %J ** julian day number
|
|
// ** %l hour 1-12 (leading zero converted to space)
|
|
// ** %m month 01-12
|
|
// ** %M minute 00-59
|
|
// ** %p "AM" or "PM"
|
|
// ** %P "am" or "pm"
|
|
// ** %R time as HH:MM
|
|
// ** %s seconds since 1970-01-01
|
|
// ** %S seconds 00-59
|
|
// ** %T time as HH:MM:SS
|
|
// ** %u day of week 1-7 Monday==1, Sunday==7
|
|
// ** %w day of week 0-6 Sunday==0, Monday==1
|
|
// ** %U week of year 00-53 (First Sunday is start of week 01)
|
|
// ** %V week of year 01-53 (First week containing Thursday is week 01)
|
|
// ** %W week of year 00-53 (First Monday is start of week 01)
|
|
// ** %Y year 0000-9999
|
|
// ** %% %
|
|
// */
|
|
func _strftimeFunc(tls *libc.TLS, context uintptr, argc int32, argv uintptr) {
|
|
bp := tls.Alloc(208)
|
|
defer tls.Free(208)
|
|
var c, cf int8
|
|
var db, zFmt, v3 uintptr
|
|
var h int32
|
|
var i, j, v2 Tsize_t
|
|
var iS Ti64
|
|
var s float64
|
|
var _ /* sRes at bp+48 */ Tsqlite3_str
|
|
var _ /* x at bp+0 */ TDateTime
|
|
var _ /* y at bp+120 */ TDateTime
|
|
var _ /* y at bp+72 */ TDateTime
|
|
_, _, _, _, _, _, _, _, _, _, _ = c, cf, db, h, i, iS, j, s, zFmt, v2, v3
|
|
if argc == 0 {
|
|
return
|
|
}
|
|
zFmt = Xsqlite3_value_text(tls, **(**uintptr)(__ccgo_up(argv)))
|
|
if zFmt == uintptr(0) || _isDate(tls, context, argc-int32(1), argv+uintptr(1)*4, bp) != 0 {
|
|
return
|
|
}
|
|
db = Xsqlite3_context_db_handle(tls, context)
|
|
_sqlite3StrAccumInit(tls, bp+48, uintptr(0), uintptr(0), 0, **(**int32)(__ccgo_up(db + 116)))
|
|
_computeJD(tls, bp)
|
|
_computeYMD_HMS(tls, bp)
|
|
v2 = libc.Uint32FromInt32(0)
|
|
j = v2
|
|
i = v2
|
|
for {
|
|
if !(**(**int8)(__ccgo_up(zFmt + uintptr(i))) != 0) {
|
|
break
|
|
}
|
|
if int32(**(**int8)(__ccgo_up(zFmt + uintptr(i)))) != int32('%') {
|
|
goto _1
|
|
}
|
|
if j < i {
|
|
Xsqlite3_str_append(tls, bp+48, zFmt+uintptr(j), libc.Int32FromUint32(i-j))
|
|
}
|
|
i = i + 1
|
|
j = i + uint32(1)
|
|
cf = **(**int8)(__ccgo_up(zFmt + uintptr(i)))
|
|
switch int32(cf) {
|
|
case int32('d'): /* Fall thru */
|
|
fallthrough
|
|
case int32('e'):
|
|
if int32(cf) == int32('d') {
|
|
v3 = __ccgo_ts + 1389
|
|
} else {
|
|
v3 = __ccgo_ts + 1394
|
|
}
|
|
Xsqlite3_str_appendf(tls, bp+48, v3, libc.VaList(bp+176, (**(**TDateTime)(__ccgo_up(bp))).FD))
|
|
case int32('f'): /* Fractional seconds. (Non-standard) */
|
|
s = (**(**TDateTime)(__ccgo_up(bp))).Fs
|
|
if s > float64(59.999) {
|
|
s = float64(59.999)
|
|
}
|
|
Xsqlite3_str_appendf(tls, bp+48, __ccgo_ts+1398, libc.VaList(bp+176, s))
|
|
case int32('F'):
|
|
Xsqlite3_str_appendf(tls, bp+48, __ccgo_ts+1405, libc.VaList(bp+176, (**(**TDateTime)(__ccgo_up(bp))).FY, (**(**TDateTime)(__ccgo_up(bp))).FM, (**(**TDateTime)(__ccgo_up(bp))).FD))
|
|
case int32('G'): /* Fall thru */
|
|
fallthrough
|
|
case int32('g'):
|
|
**(**TDateTime)(__ccgo_up(bp + 72)) = **(**TDateTime)(__ccgo_up(bp))
|
|
/* Move y so that it is the Thursday in the same week as x */
|
|
(**(**TDateTime)(__ccgo_up(bp + 72))).FiJD += int64((int32(3) - _daysAfterMonday(tls, bp)) * int32(86400000))
|
|
(**(**TDateTime)(__ccgo_up(bp + 72))).FvalidYMD = 0
|
|
_computeYMD(tls, bp+72)
|
|
if int32(cf) == int32('g') {
|
|
Xsqlite3_str_appendf(tls, bp+48, __ccgo_ts+1389, libc.VaList(bp+176, (**(**TDateTime)(__ccgo_up(bp + 72))).FY%int32(100)))
|
|
} else {
|
|
Xsqlite3_str_appendf(tls, bp+48, __ccgo_ts+1420, libc.VaList(bp+176, (**(**TDateTime)(__ccgo_up(bp + 72))).FY))
|
|
}
|
|
case int32('H'):
|
|
fallthrough
|
|
case int32('k'):
|
|
if int32(cf) == int32('H') {
|
|
v3 = __ccgo_ts + 1389
|
|
} else {
|
|
v3 = __ccgo_ts + 1394
|
|
}
|
|
Xsqlite3_str_appendf(tls, bp+48, v3, libc.VaList(bp+176, (**(**TDateTime)(__ccgo_up(bp))).Fh))
|
|
case int32('I'): /* Fall thru */
|
|
fallthrough
|
|
case int32('l'):
|
|
h = (**(**TDateTime)(__ccgo_up(bp))).Fh
|
|
if h > int32(12) {
|
|
h = h - int32(12)
|
|
}
|
|
if h == 0 {
|
|
h = int32(12)
|
|
}
|
|
if int32(cf) == int32('I') {
|
|
v3 = __ccgo_ts + 1389
|
|
} else {
|
|
v3 = __ccgo_ts + 1394
|
|
}
|
|
Xsqlite3_str_appendf(tls, bp+48, v3, libc.VaList(bp+176, h))
|
|
case int32('j'): /* Day of year. Jan01==1, Jan02==2, and so forth */
|
|
Xsqlite3_str_appendf(tls, bp+48, __ccgo_ts+1425, libc.VaList(bp+176, _daysAfterJan01(tls, bp)+int32(1)))
|
|
case int32('J'): /* Julian day number. (Non-standard) */
|
|
Xsqlite3_str_appendf(tls, bp+48, __ccgo_ts+1430, libc.VaList(bp+176, float64((**(**TDateTime)(__ccgo_up(bp))).FiJD)/float64(8.64e+07)))
|
|
case int32('m'):
|
|
Xsqlite3_str_appendf(tls, bp+48, __ccgo_ts+1389, libc.VaList(bp+176, (**(**TDateTime)(__ccgo_up(bp))).FM))
|
|
case int32('M'):
|
|
Xsqlite3_str_appendf(tls, bp+48, __ccgo_ts+1389, libc.VaList(bp+176, (**(**TDateTime)(__ccgo_up(bp))).Fm))
|
|
case int32('p'): /* Fall thru */
|
|
fallthrough
|
|
case int32('P'):
|
|
if (**(**TDateTime)(__ccgo_up(bp))).Fh >= int32(12) {
|
|
if int32(cf) == int32('p') {
|
|
v3 = __ccgo_ts + 1436
|
|
} else {
|
|
v3 = __ccgo_ts + 1439
|
|
}
|
|
Xsqlite3_str_append(tls, bp+48, v3, int32(2))
|
|
} else {
|
|
if int32(cf) == int32('p') {
|
|
v3 = __ccgo_ts + 1442
|
|
} else {
|
|
v3 = __ccgo_ts + 1445
|
|
}
|
|
Xsqlite3_str_append(tls, bp+48, v3, int32(2))
|
|
}
|
|
case int32('R'):
|
|
Xsqlite3_str_appendf(tls, bp+48, __ccgo_ts+1448, libc.VaList(bp+176, (**(**TDateTime)(__ccgo_up(bp))).Fh, (**(**TDateTime)(__ccgo_up(bp))).Fm))
|
|
case int32('s'):
|
|
if int32(uint32(*(*uint8)(unsafe.Pointer(bp + 44))&0x4>>2)) != 0 {
|
|
Xsqlite3_str_appendf(tls, bp+48, __ccgo_ts+1458, libc.VaList(bp+176, float64((**(**TDateTime)(__ccgo_up(bp))).FiJD-libc.Int64FromInt32(21086676)*libc.Int64FromInt32(10000000))/float64(1000)))
|
|
} else {
|
|
iS = (**(**TDateTime)(__ccgo_up(bp))).FiJD/libc.Int64FromInt32(1000) - libc.Int64FromInt32(21086676)*libc.Int64FromInt32(10000)
|
|
Xsqlite3_str_appendf(tls, bp+48, __ccgo_ts+1463, libc.VaList(bp+176, iS))
|
|
}
|
|
case int32('S'):
|
|
Xsqlite3_str_appendf(tls, bp+48, __ccgo_ts+1389, libc.VaList(bp+176, int32((**(**TDateTime)(__ccgo_up(bp))).Fs)))
|
|
case int32('T'):
|
|
Xsqlite3_str_appendf(tls, bp+48, __ccgo_ts+1468, libc.VaList(bp+176, (**(**TDateTime)(__ccgo_up(bp))).Fh, (**(**TDateTime)(__ccgo_up(bp))).Fm, int32((**(**TDateTime)(__ccgo_up(bp))).Fs)))
|
|
case int32('u'): /* Day of week. 1 to 7. Monday==1, Sunday==7 */
|
|
fallthrough
|
|
case int32('w'): /* Day of week. 0 to 6. Sunday==0, Monday==1 */
|
|
c = int8(int32(int8(_daysAfterSunday(tls, bp))) + int32('0'))
|
|
if int32(c) == int32('0') && int32(cf) == int32('u') {
|
|
c = int8('7')
|
|
}
|
|
Xsqlite3_str_appendchar(tls, bp+48, int32(1), c)
|
|
case int32('U'): /* Week num. 00-53. First Sun of the year is week 01 */
|
|
Xsqlite3_str_appendf(tls, bp+48, __ccgo_ts+1389, libc.VaList(bp+176, (_daysAfterJan01(tls, bp)-_daysAfterSunday(tls, bp)+int32(7))/int32(7)))
|
|
case int32('V'): /* Week num. 01-53. First week with a Thur is week 01 */
|
|
**(**TDateTime)(__ccgo_up(bp + 120)) = **(**TDateTime)(__ccgo_up(bp))
|
|
/* Adjust y so that is the Thursday in the same week as x */
|
|
(**(**TDateTime)(__ccgo_up(bp + 120))).FiJD += int64((int32(3) - _daysAfterMonday(tls, bp)) * int32(86400000))
|
|
(**(**TDateTime)(__ccgo_up(bp + 120))).FvalidYMD = 0
|
|
_computeYMD(tls, bp+120)
|
|
Xsqlite3_str_appendf(tls, bp+48, __ccgo_ts+1389, libc.VaList(bp+176, _daysAfterJan01(tls, bp+120)/int32(7)+int32(1)))
|
|
case int32('W'): /* Week num. 00-53. First Mon of the year is week 01 */
|
|
Xsqlite3_str_appendf(tls, bp+48, __ccgo_ts+1389, libc.VaList(bp+176, (_daysAfterJan01(tls, bp)-_daysAfterMonday(tls, bp)+int32(7))/int32(7)))
|
|
case int32('Y'):
|
|
Xsqlite3_str_appendf(tls, bp+48, __ccgo_ts+1420, libc.VaList(bp+176, (**(**TDateTime)(__ccgo_up(bp))).FY))
|
|
case int32('%'):
|
|
Xsqlite3_str_appendchar(tls, bp+48, int32(1), int8('%'))
|
|
default:
|
|
Xsqlite3_str_reset(tls, bp+48)
|
|
return
|
|
}
|
|
goto _1
|
|
_1:
|
|
;
|
|
i = i + 1
|
|
}
|
|
if j < i {
|
|
Xsqlite3_str_append(tls, bp+48, zFmt+uintptr(j), libc.Int32FromUint32(i-j))
|
|
}
|
|
_sqlite3ResultStrAccum(tls, context, bp+48)
|
|
}
|
|
|
|
// C documentation
|
|
//
|
|
// /*
|
|
// ** timediff(DATE1, DATE2)
|
|
// **
|
|
// ** Return the amount of time that must be added to DATE2 in order to
|
|
// ** convert it into DATE2. The time difference format is:
|
|
// **
|
|
// ** +YYYY-MM-DD HH:MM:SS.SSS
|
|
// **
|
|
// ** The initial "+" becomes "-" if DATE1 occurs before DATE2. For
|
|
// ** date/time values A and B, the following invariant should hold:
|
|
// **
|
|
// ** datetime(A) == (datetime(B, timediff(A,B))
|
|
// **
|
|
// ** Both DATE arguments must be either a julian day number, or an
|
|
// ** ISO-8601 string. The unix timestamps are not supported by this
|
|
// ** routine.
|
|
// */
|
|
func _timediffFunc(tls *libc.TLS, context uintptr, NotUsed1 int32, argv uintptr) {
|
|
bp := tls.Alloc(192)
|
|
defer tls.Free(192)
|
|
var M, Y int32
|
|
var sign int8
|
|
var v1 uintptr
|
|
var _ /* d1 at bp+0 */ TDateTime
|
|
var _ /* d2 at bp+48 */ TDateTime
|
|
var _ /* sRes at bp+96 */ Tsqlite3_str
|
|
_, _, _, _ = M, Y, sign, v1
|
|
_ = NotUsed1
|
|
if _isDate(tls, context, int32(1), argv, bp) != 0 {
|
|
return
|
|
}
|
|
if _isDate(tls, context, int32(1), argv+1*4, bp+48) != 0 {
|
|
return
|
|
}
|
|
_computeYMD_HMS(tls, bp)
|
|
_computeYMD_HMS(tls, bp+48)
|
|
if (**(**TDateTime)(__ccgo_up(bp))).FiJD >= (**(**TDateTime)(__ccgo_up(bp + 48))).FiJD {
|
|
sign = int8('+')
|
|
Y = (**(**TDateTime)(__ccgo_up(bp))).FY - (**(**TDateTime)(__ccgo_up(bp + 48))).FY
|
|
if Y != 0 {
|
|
(**(**TDateTime)(__ccgo_up(bp + 48))).FY = (**(**TDateTime)(__ccgo_up(bp))).FY
|
|
(**(**TDateTime)(__ccgo_up(bp + 48))).FvalidJD = 0
|
|
_computeJD(tls, bp+48)
|
|
}
|
|
M = (**(**TDateTime)(__ccgo_up(bp))).FM - (**(**TDateTime)(__ccgo_up(bp + 48))).FM
|
|
if M < 0 {
|
|
Y = Y - 1
|
|
M = M + int32(12)
|
|
}
|
|
if M != 0 {
|
|
(**(**TDateTime)(__ccgo_up(bp + 48))).FM = (**(**TDateTime)(__ccgo_up(bp))).FM
|
|
(**(**TDateTime)(__ccgo_up(bp + 48))).FvalidJD = 0
|
|
_computeJD(tls, bp+48)
|
|
}
|
|
for (**(**TDateTime)(__ccgo_up(bp))).FiJD < (**(**TDateTime)(__ccgo_up(bp + 48))).FiJD {
|
|
M = M - 1
|
|
if M < 0 {
|
|
M = int32(11)
|
|
Y = Y - 1
|
|
}
|
|
(**(**TDateTime)(__ccgo_up(bp + 48))).FM = (**(**TDateTime)(__ccgo_up(bp + 48))).FM - 1
|
|
if (**(**TDateTime)(__ccgo_up(bp + 48))).FM < int32(1) {
|
|
(**(**TDateTime)(__ccgo_up(bp + 48))).FM = int32(12)
|
|
(**(**TDateTime)(__ccgo_up(bp + 48))).FY = (**(**TDateTime)(__ccgo_up(bp + 48))).FY - 1
|
|
}
|
|
(**(**TDateTime)(__ccgo_up(bp + 48))).FvalidJD = 0
|
|
_computeJD(tls, bp+48)
|
|
}
|
|
(**(**TDateTime)(__ccgo_up(bp))).FiJD -= (**(**TDateTime)(__ccgo_up(bp + 48))).FiJD
|
|
v1 = bp
|
|
*(*Tsqlite3_int64)(unsafe.Pointer(v1)) = Tsqlite3_int64(uint64(*(*Tsqlite3_int64)(unsafe.Pointer(v1))) + libc.Uint64FromInt32(1486995408)*libc.Uint64FromInt32(100000))
|
|
} else { /* d1<d2 */
|
|
sign = int8('-')
|
|
Y = (**(**TDateTime)(__ccgo_up(bp + 48))).FY - (**(**TDateTime)(__ccgo_up(bp))).FY
|
|
if Y != 0 {
|
|
(**(**TDateTime)(__ccgo_up(bp + 48))).FY = (**(**TDateTime)(__ccgo_up(bp))).FY
|
|
(**(**TDateTime)(__ccgo_up(bp + 48))).FvalidJD = 0
|
|
_computeJD(tls, bp+48)
|
|
}
|
|
M = (**(**TDateTime)(__ccgo_up(bp + 48))).FM - (**(**TDateTime)(__ccgo_up(bp))).FM
|
|
if M < 0 {
|
|
Y = Y - 1
|
|
M = M + int32(12)
|
|
}
|
|
if M != 0 {
|
|
(**(**TDateTime)(__ccgo_up(bp + 48))).FM = (**(**TDateTime)(__ccgo_up(bp))).FM
|
|
(**(**TDateTime)(__ccgo_up(bp + 48))).FvalidJD = 0
|
|
_computeJD(tls, bp+48)
|
|
}
|
|
for (**(**TDateTime)(__ccgo_up(bp))).FiJD > (**(**TDateTime)(__ccgo_up(bp + 48))).FiJD {
|
|
M = M - 1
|
|
if M < 0 {
|
|
M = int32(11)
|
|
Y = Y - 1
|
|
}
|
|
(**(**TDateTime)(__ccgo_up(bp + 48))).FM = (**(**TDateTime)(__ccgo_up(bp + 48))).FM + 1
|
|
if (**(**TDateTime)(__ccgo_up(bp + 48))).FM > int32(12) {
|
|
(**(**TDateTime)(__ccgo_up(bp + 48))).FM = int32(1)
|
|
(**(**TDateTime)(__ccgo_up(bp + 48))).FY = (**(**TDateTime)(__ccgo_up(bp + 48))).FY + 1
|
|
}
|
|
(**(**TDateTime)(__ccgo_up(bp + 48))).FvalidJD = 0
|
|
_computeJD(tls, bp+48)
|
|
}
|
|
(**(**TDateTime)(__ccgo_up(bp))).FiJD = (**(**TDateTime)(__ccgo_up(bp + 48))).FiJD - (**(**TDateTime)(__ccgo_up(bp))).FiJD
|
|
v1 = bp
|
|
*(*Tsqlite3_int64)(unsafe.Pointer(v1)) = Tsqlite3_int64(uint64(*(*Tsqlite3_int64)(unsafe.Pointer(v1))) + libc.Uint64FromInt32(1486995408)*libc.Uint64FromInt32(100000))
|
|
}
|
|
_clearYMD_HMS_TZ(tls, bp)
|
|
_computeYMD_HMS(tls, bp)
|
|
_sqlite3StrAccumInit(tls, bp+96, uintptr(0), uintptr(0), 0, int32(100))
|
|
Xsqlite3_str_appendf(tls, bp+96, __ccgo_ts+1483, libc.VaList(bp+128, int32(sign), Y, M, (**(**TDateTime)(__ccgo_up(bp))).FD-int32(1), (**(**TDateTime)(__ccgo_up(bp))).Fh, (**(**TDateTime)(__ccgo_up(bp))).Fm, (**(**TDateTime)(__ccgo_up(bp))).Fs))
|
|
_sqlite3ResultStrAccum(tls, context, bp+96)
|
|
}
|
|
|
|
// C documentation
|
|
//
|
|
// /*
|
|
// ** Assuming the input DateTime is UTC, move it to its localtime equivalent.
|
|
// */
|
|
func _toLocaltime(tls *libc.TLS, p uintptr, pCtx uintptr) (r int32) {
|
|
bp := tls.Alloc(96)
|
|
defer tls.Free(96)
|
|
var iYearDiff int32
|
|
var _ /* sLocal at bp+4 */ Ttm
|
|
var _ /* t at bp+0 */ Ttime_t
|
|
var _ /* x at bp+48 */ TDateTime
|
|
_ = iYearDiff
|
|
/* Initialize the contents of sLocal to avoid a compiler warning. */
|
|
libc.Xmemset(tls, bp+4, 0, uint32(44))
|
|
_computeJD(tls, p)
|
|
if (*TDateTime)(unsafe.Pointer(p)).FiJD < libc.Int64FromInt32(2108667600)*libc.Int64FromInt32(100000) || (*TDateTime)(unsafe.Pointer(p)).FiJD > libc.Int64FromInt32(2130141456)*libc.Int64FromInt32(100000) {
|
|
/* EVIDENCE-OF: R-55269-29598 The localtime_r() C function normally only
|
|
** works for years between 1970 and 2037. For dates outside this range,
|
|
** SQLite attempts to map the year into an equivalent year within this
|
|
** range, do the calculation, then map the year back.
|
|
*/
|
|
**(**TDateTime)(__ccgo_up(bp + 48)) = **(**TDateTime)(__ccgo_up(p))
|
|
_computeYMD_HMS(tls, bp+48)
|
|
iYearDiff = int32(2000) + (**(**TDateTime)(__ccgo_up(bp + 48))).FY%int32(4) - (**(**TDateTime)(__ccgo_up(bp + 48))).FY
|
|
(**(**TDateTime)(__ccgo_up(bp + 48))).FY += iYearDiff
|
|
(**(**TDateTime)(__ccgo_up(bp + 48))).FvalidJD = 0
|
|
_computeJD(tls, bp+48)
|
|
**(**Ttime_t)(__ccgo_up(bp)) = int32((**(**TDateTime)(__ccgo_up(bp + 48))).FiJD/libc.Int64FromInt32(1000) - libc.Int64FromInt32(21086676)*libc.Int64FromInt32(10000))
|
|
} else {
|
|
iYearDiff = 0
|
|
**(**Ttime_t)(__ccgo_up(bp)) = int32((*TDateTime)(unsafe.Pointer(p)).FiJD/libc.Int64FromInt32(1000) - libc.Int64FromInt32(21086676)*libc.Int64FromInt32(10000))
|
|
}
|
|
if _osLocaltime(tls, bp, bp+4) != 0 {
|
|
Xsqlite3_result_error(tls, pCtx, __ccgo_ts+1247, -int32(1))
|
|
return int32(SQLITE_ERROR)
|
|
}
|
|
(*TDateTime)(unsafe.Pointer(p)).FY = (**(**Ttm)(__ccgo_up(bp + 4))).Ftm_year + int32(1900) - iYearDiff
|
|
(*TDateTime)(unsafe.Pointer(p)).FM = (**(**Ttm)(__ccgo_up(bp + 4))).Ftm_mon + int32(1)
|
|
(*TDateTime)(unsafe.Pointer(p)).FD = (**(**Ttm)(__ccgo_up(bp + 4))).Ftm_mday
|
|
(*TDateTime)(unsafe.Pointer(p)).Fh = (**(**Ttm)(__ccgo_up(bp + 4))).Ftm_hour
|
|
(*TDateTime)(unsafe.Pointer(p)).Fm = (**(**Ttm)(__ccgo_up(bp + 4))).Ftm_min
|
|
(*TDateTime)(unsafe.Pointer(p)).Fs = float64((**(**Ttm)(__ccgo_up(bp + 4))).Ftm_sec) + float64(float64((*TDateTime)(unsafe.Pointer(p)).FiJD%libc.Int64FromInt32(1000))*float64(0.001))
|
|
(*TDateTime)(unsafe.Pointer(p)).FvalidYMD = int8(1)
|
|
(*TDateTime)(unsafe.Pointer(p)).FvalidHMS = int8(1)
|
|
(*TDateTime)(unsafe.Pointer(p)).FvalidJD = 0
|
|
libc.SetBitFieldPtr8Uint32(p+44, libc.Uint32FromInt32(0), 0, 0x1)
|
|
(*TDateTime)(unsafe.Pointer(p)).Ftz = 0
|
|
libc.SetBitFieldPtr8Uint32(p+44, libc.Uint32FromInt32(0), 1, 0x2)
|
|
return SQLITE_OK
|
|
}
|
|
|
|
// C documentation
|
|
//
|
|
// /*
|
|
// ** Implementation of the UNISTR() function.
|
|
// **
|
|
// ** This is intended to be a work-alike of the UNISTR() function in
|
|
// ** PostgreSQL. Quoting from the PG documentation (PostgreSQL 17 -
|
|
// ** scraped on 2025-02-22):
|
|
// **
|
|
// ** Evaluate escaped Unicode characters in the argument. Unicode
|
|
// ** characters can be specified as \XXXX (4 hexadecimal digits),
|
|
// ** \+XXXXXX (6 hexadecimal digits), \uXXXX (4 hexadecimal digits),
|
|
// ** or \UXXXXXXXX (8 hexadecimal digits). To specify a backslash,
|
|
// ** write two backslashes. All other characters are taken literally.
|
|
// */
|
|
func _unistrFunc(tls *libc.TLS, context uintptr, argc int32, argv uintptr) {
|
|
bp := tls.Alloc(16)
|
|
defer tls.Free(16)
|
|
var i, j, n, nIn, v1 int32
|
|
var z, zIn, zOut uintptr
|
|
var _ /* v at bp+0 */ Tu32
|
|
_, _, _, _, _, _, _, _ = i, j, n, nIn, z, zIn, zOut, v1
|
|
_ = argc
|
|
zIn = Xsqlite3_value_text(tls, **(**uintptr)(__ccgo_up(argv)))
|
|
if zIn == uintptr(0) {
|
|
return
|
|
}
|
|
nIn = Xsqlite3_value_bytes(tls, **(**uintptr)(__ccgo_up(argv)))
|
|
zOut = Xsqlite3_malloc64(tls, libc.Uint64FromInt32(nIn+int32(1)))
|
|
if zOut == uintptr(0) {
|
|
Xsqlite3_result_error_nomem(tls, context)
|
|
return
|
|
}
|
|
v1 = libc.Int32FromInt32(0)
|
|
j = v1
|
|
i = v1
|
|
for i < nIn {
|
|
z = libc.Xstrchr(tls, zIn+uintptr(i), int32('\\'))
|
|
if z == uintptr(0) {
|
|
n = nIn - i
|
|
libc.Xmemmove(tls, zOut+uintptr(j), zIn+uintptr(i), libc.Uint32FromInt32(n))
|
|
j = j + n
|
|
break
|
|
}
|
|
n = int32(z) - t__predefined_ptrdiff_t(zIn+uintptr(i))
|
|
if n > 0 {
|
|
libc.Xmemmove(tls, zOut+uintptr(j), zIn+uintptr(i), libc.Uint32FromInt32(n))
|
|
j = j + n
|
|
i = i + n
|
|
}
|
|
if int32(**(**int8)(__ccgo_up(zIn + uintptr(i+int32(1))))) == int32('\\') {
|
|
i = i + int32(2)
|
|
v1 = j
|
|
j = j + 1
|
|
**(**int8)(__ccgo_up(zOut + uintptr(v1))) = int8('\\')
|
|
} else {
|
|
if libc.Int32FromUint8(_sqlite3CtypeMap[libc.Uint8FromInt8(**(**int8)(__ccgo_up(zIn + uintptr(i+int32(1)))))])&int32(0x08) != 0 {
|
|
if !(_isNHex(tls, zIn+uintptr(i+int32(1)), int32(4), bp) != 0) {
|
|
goto unistr_error
|
|
}
|
|
i = i + int32(5)
|
|
j = j + _sqlite3AppendOneUtf8Character(tls, zOut+uintptr(j), **(**Tu32)(__ccgo_up(bp)))
|
|
} else {
|
|
if int32(**(**int8)(__ccgo_up(zIn + uintptr(i+int32(1))))) == int32('+') {
|
|
if !(_isNHex(tls, zIn+uintptr(i+int32(2)), int32(6), bp) != 0) {
|
|
goto unistr_error
|
|
}
|
|
i = i + int32(8)
|
|
j = j + _sqlite3AppendOneUtf8Character(tls, zOut+uintptr(j), **(**Tu32)(__ccgo_up(bp)))
|
|
} else {
|
|
if int32(**(**int8)(__ccgo_up(zIn + uintptr(i+int32(1))))) == int32('u') {
|
|
if !(_isNHex(tls, zIn+uintptr(i+int32(2)), int32(4), bp) != 0) {
|
|
goto unistr_error
|
|
}
|
|
i = i + int32(6)
|
|
j = j + _sqlite3AppendOneUtf8Character(tls, zOut+uintptr(j), **(**Tu32)(__ccgo_up(bp)))
|
|
} else {
|
|
if int32(**(**int8)(__ccgo_up(zIn + uintptr(i+int32(1))))) == int32('U') {
|
|
if !(_isNHex(tls, zIn+uintptr(i+int32(2)), int32(8), bp) != 0) {
|
|
goto unistr_error
|
|
}
|
|
i = i + int32(10)
|
|
j = j + _sqlite3AppendOneUtf8Character(tls, zOut+uintptr(j), **(**Tu32)(__ccgo_up(bp)))
|
|
} else {
|
|
goto unistr_error
|
|
}
|
|
}
|
|
}
|
|
}
|
|
}
|
|
}
|
|
**(**int8)(__ccgo_up(zOut + uintptr(j))) = 0
|
|
Xsqlite3_result_text64(tls, context, zOut, libc.Uint64FromInt32(j), __ccgo_fp(Xsqlite3_free), uint8(SQLITE_UTF8_ZT))
|
|
return
|
|
goto unistr_error
|
|
unistr_error:
|
|
;
|
|
Xsqlite3_free(tls, zOut)
|
|
Xsqlite3_result_error(tls, context, __ccgo_ts+16573, -int32(1))
|
|
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(208)
|
|
defer tls.Free(208)
|
|
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) && (!(libc.Int32FromUint16((**(**Tstat)(__ccgo_up(bp))).Fst_mode)&libc.Int32FromInt32(0170000) == libc.Int32FromInt32(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
|
|
//
|
|
// /*
|
|
// ** Use F_GETLK to check whether or not there are any readers with open
|
|
// ** wal-mode transactions in other processes on database file pFile. If
|
|
// ** no error occurs, return SQLITE_OK and set (*piOut) to 1 if there are
|
|
// ** such transactions, or 0 otherwise. If an error occurs, return an
|
|
// ** SQLite error code. The final value of *piOut is undefined in this
|
|
// ** case.
|
|
// */
|
|
func _unixFcntlExternalReader(tls *libc.TLS, pFile uintptr, piOut uintptr) (r int32) {
|
|
bp := tls.Alloc(48)
|
|
defer tls.Free(48)
|
|
var pShmNode uintptr
|
|
var rc int32
|
|
var _ /* f at bp+0 */ Tflock
|
|
_, _ = pShmNode, rc
|
|
rc = SQLITE_OK
|
|
**(**int32)(__ccgo_up(piOut)) = 0
|
|
if (*TunixFile)(unsafe.Pointer(pFile)).FpShm != 0 {
|
|
pShmNode = (*TunixShm)(unsafe.Pointer((*TunixFile)(unsafe.Pointer(pFile)).FpShm)).FpShmNode
|
|
libc.Xmemset(tls, bp, 0, uint32(28))
|
|
(**(**Tflock)(__ccgo_up(bp))).Fl_type = int16(F_WRLCK)
|
|
(**(**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(3))
|
|
(**(**Tflock)(__ccgo_up(bp))).Fl_len = int64(libc.Int32FromInt32(SQLITE_SHM_NLOCK) - libc.Int32FromInt32(3))
|
|
Xsqlite3_mutex_enter(tls, (*TunixShmNode)(unsafe.Pointer(pShmNode)).FpShmMutex)
|
|
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+40, bp)) < 0 {
|
|
rc = libc.Int32FromInt32(SQLITE_IOERR) | libc.Int32FromInt32(15)<<libc.Int32FromInt32(8)
|
|
} else {
|
|
**(**int32)(__ccgo_up(piOut)) = libc.BoolInt32(int32((**(**Tflock)(__ccgo_up(bp))).Fl_type) != int32(F_UNLCK))
|
|
}
|
|
Xsqlite3_mutex_leave(tls, (*TunixShmNode)(unsafe.Pointer(pShmNode)).FpShmMutex)
|
|
}
|
|
return rc
|
|
}
|
|
|
|
// 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(208)
|
|
defer tls.Free(208)
|
|
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__error(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
|
|
//
|
|
// /*
|
|
// ** Turn a relative pathname into a full pathname. The relative path
|
|
// ** is stored as a nul-terminated string in the buffer pointed to by
|
|
// ** zPath.
|
|
// **
|
|
// ** zOut points to a buffer of at least sqlite3_vfs.mxPathname bytes
|
|
// ** (in this case, MAX_PATHNAME bytes). The full-path is written to
|
|
// ** this buffer before returning.
|
|
// */
|
|
func _unixFullPathname(tls *libc.TLS, pVfs uintptr, zPath uintptr, nOut int32, zOut uintptr) (r int32) {
|
|
bp := tls.Alloc(1056)
|
|
defer tls.Free(1056)
|
|
var _ /* path at bp+0 */ TDbPath
|
|
var _ /* zPwd at bp+20 */ [1026]int8
|
|
_ = pVfs
|
|
(**(**TDbPath)(__ccgo_up(bp))).Frc = 0
|
|
(**(**TDbPath)(__ccgo_up(bp))).FnUsed = 0
|
|
(**(**TDbPath)(__ccgo_up(bp))).FnSymlink = 0
|
|
(**(**TDbPath)(__ccgo_up(bp))).FnOut = nOut
|
|
(**(**TDbPath)(__ccgo_up(bp))).FzOut = zOut
|
|
if int32(**(**int8)(__ccgo_up(zPath))) != int32('/') {
|
|
if (*(*func(*libc.TLS, uintptr, Tsize_t) uintptr)(unsafe.Pointer(&struct{ uintptr }{_aSyscall[int32(3)].FpCurrent})))(tls, bp+20, libc.Uint32FromInt64(1026)-libc.Uint32FromInt32(2)) == uintptr(0) {
|
|
return _unixLogErrorAtLine(tls, _sqlite3CantopenError(tls, int32(47221)), __ccgo_ts+3558, zPath, int32(47221))
|
|
}
|
|
_appendAllPathElements(tls, bp, bp+20)
|
|
}
|
|
_appendAllPathElements(tls, bp, zPath)
|
|
**(**int8)(__ccgo_up(zOut + uintptr((**(**TDbPath)(__ccgo_up(bp))).FnUsed))) = 0
|
|
if (**(**TDbPath)(__ccgo_up(bp))).Frc != 0 || (**(**TDbPath)(__ccgo_up(bp))).FnUsed < int32(2) {
|
|
return _sqlite3CantopenError(tls, int32(47227))
|
|
}
|
|
if (**(**TDbPath)(__ccgo_up(bp))).FnSymlink != 0 {
|
|
return libc.Int32FromInt32(SQLITE_OK) | libc.Int32FromInt32(2)<<libc.Int32FromInt32(8)
|
|
}
|
|
return SQLITE_OK
|
|
}
|
|
|
|
// C documentation
|
|
//
|
|
// /*
|
|
// ** If pFile has a -shm file open and it is sharing that file with some
|
|
// ** other connection, either in the same process or in a separate process,
|
|
// ** then return true. Return false if either pFile does not have a -shm
|
|
// ** file open or if it is the only connection to that -shm file across the
|
|
// ** entire system.
|
|
// **
|
|
// ** This routine is not required for correct operation. It can always return
|
|
// ** false and SQLite will continue to operate according to spec. However,
|
|
// ** when this routine does its job, it adds extra robustness in cases
|
|
// ** where database file locks have been erroneously deleted in a WAL-mode
|
|
// ** database by doing close(open(DATABASE_PATHNAME)) or similar.
|
|
// **
|
|
// ** With false negatives, SQLite still operates to spec, though with less
|
|
// ** robustness. With false positives, the last database connection on a
|
|
// ** WAL-mode database will fail to unlink the -wal and -shm files, which
|
|
// ** is annoying but harmless. False positives will also prevent a database
|
|
// ** connection from running "PRAGMA journal_mode=DELETE" in order to take
|
|
// ** the database out of WAL mode, which is perhaps more serious, but is
|
|
// ** still not a disaster.
|
|
// */
|
|
func _unixIsSharingShmNode(tls *libc.TLS, pFile uintptr) (r int32) {
|
|
bp := tls.Alloc(48)
|
|
defer tls.Free(48)
|
|
var pShmNode uintptr
|
|
var _ /* lock at bp+0 */ Tflock
|
|
_ = pShmNode
|
|
if (*TunixFile)(unsafe.Pointer(pFile)).FpShm == uintptr(0) {
|
|
return 0
|
|
}
|
|
if libc.Int32FromUint16((*TunixFile)(unsafe.Pointer(pFile)).FctrlFlags)&int32(UNIXFILE_EXCL) != 0 {
|
|
return 0
|
|
}
|
|
pShmNode = (*TunixShm)(unsafe.Pointer((*TunixFile)(unsafe.Pointer(pFile)).FpShm)).FpShmNode
|
|
libc.Xmemset(tls, bp, 0, uint32(28))
|
|
(**(**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)
|
|
(*(*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+40, bp))
|
|
return libc.BoolInt32(int32((**(**Tflock)(__ccgo_up(bp))).Fl_type) != int32(F_UNLCK))
|
|
}
|
|
|
|
// C documentation
|
|
//
|
|
// /*
|
|
// ** Memory map or remap the file opened by file-descriptor pFd (if the file
|
|
// ** is already mapped, the existing mapping is replaced by the new). Or, if
|
|
// ** there already exists a mapping for this file, and there are still
|
|
// ** outstanding xFetch() references to it, this function is a no-op.
|
|
// **
|
|
// ** If parameter nByte is non-negative, then it is the requested size of
|
|
// ** the mapping to create. Otherwise, if nByte is less than zero, then the
|
|
// ** requested size is the size of the file on disk. The actual size of the
|
|
// ** created mapping is either the requested size or the value configured
|
|
// ** using SQLITE_FCNTL_MMAP_LIMIT, whichever is smaller.
|
|
// **
|
|
// ** SQLITE_OK is returned if no error occurs (even if the mapping is not
|
|
// ** recreated as a result of outstanding references) or an SQLite error
|
|
// ** code otherwise.
|
|
// */
|
|
func _unixMapfile(tls *libc.TLS, pFd uintptr, nMap Ti64) (r int32) {
|
|
bp := tls.Alloc(208)
|
|
defer tls.Free(208)
|
|
var _ /* statbuf at bp+0 */ Tstat
|
|
if (*TunixFile)(unsafe.Pointer(pFd)).FnFetchOut > 0 {
|
|
return SQLITE_OK
|
|
}
|
|
if nMap < 0 { /* Low-level file information */
|
|
if (*(*func(*libc.TLS, int32, uintptr) int32)(unsafe.Pointer(&struct{ uintptr }{_aSyscall[int32(5)].FpCurrent})))(tls, (*TunixFile)(unsafe.Pointer(pFd)).Fh, bp) != 0 {
|
|
return libc.Int32FromInt32(SQLITE_IOERR) | libc.Int32FromInt32(7)<<libc.Int32FromInt32(8)
|
|
}
|
|
nMap = (**(**Tstat)(__ccgo_up(bp))).Fst_size
|
|
}
|
|
if nMap > (*TunixFile)(unsafe.Pointer(pFd)).FmmapSizeMax {
|
|
nMap = (*TunixFile)(unsafe.Pointer(pFd)).FmmapSizeMax
|
|
}
|
|
if nMap != (*TunixFile)(unsafe.Pointer(pFd)).FmmapSize {
|
|
_unixRemapfile(tls, pFd, nMap)
|
|
}
|
|
return SQLITE_OK
|
|
}
|
|
|
|
// C documentation
|
|
//
|
|
// /*
|
|
// ** Open the file zPath.
|
|
// **
|
|
// ** Previously, the SQLite OS layer used three functions in place of this
|
|
// ** one:
|
|
// **
|
|
// ** sqlite3OsOpenReadWrite();
|
|
// ** sqlite3OsOpenReadOnly();
|
|
// ** sqlite3OsOpenExclusive();
|
|
// **
|
|
// ** These calls correspond to the following combinations of flags:
|
|
// **
|
|
// ** ReadWrite() -> (READWRITE | CREATE)
|
|
// ** ReadOnly() -> (READONLY)
|
|
// ** OpenExclusive() -> (READWRITE | CREATE | EXCLUSIVE)
|
|
// **
|
|
// ** The old OpenExclusive() accepted a boolean argument - "delFlag". If
|
|
// ** true, the file was configured to be automatically deleted when the
|
|
// ** file handle closed. To achieve the same effect using this new
|
|
// ** interface, add the DELETEONCLOSE flag to those specified above for
|
|
// ** OpenExclusive().
|
|
// */
|
|
func _unixOpen(tls *libc.TLS, pVfs uintptr, zPath uintptr, pFile uintptr, flags int32, pOutFlags uintptr) (r int32) {
|
|
bp := tls.Alloc(528)
|
|
defer tls.Free(528)
|
|
var ctrlFlags, eType, fd, isCreate, isDelete, isExclusive, isNewJrnl, isReadWrite, isReadonly, noLock, openFlags, rc, rc2 int32
|
|
var p, pReadonly, pUnused, zName uintptr
|
|
var _ /* gid at bp+520 */ Tgid_t
|
|
var _ /* openMode at bp+514 */ Tmode_t
|
|
var _ /* uid at bp+516 */ Tuid_t
|
|
var _ /* zTmpname at bp+0 */ [514]int8
|
|
_, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _ = ctrlFlags, eType, fd, isCreate, isDelete, isExclusive, isNewJrnl, isReadWrite, isReadonly, noLock, openFlags, p, pReadonly, pUnused, rc, rc2, zName
|
|
p = pFile
|
|
fd = -int32(1) /* File descriptor returned by open() */
|
|
openFlags = 0 /* Flags to pass to open() */
|
|
eType = flags & int32(0x0FFF00) /* True to omit locking primitives */
|
|
rc = SQLITE_OK /* Function Return Code */
|
|
ctrlFlags = 0 /* UNIXFILE_* flags */
|
|
isExclusive = flags & int32(SQLITE_OPEN_EXCLUSIVE)
|
|
isDelete = flags & int32(SQLITE_OPEN_DELETEONCLOSE)
|
|
isCreate = flags & int32(SQLITE_OPEN_CREATE)
|
|
isReadonly = flags & int32(SQLITE_OPEN_READONLY)
|
|
isReadWrite = flags & int32(SQLITE_OPEN_READWRITE)
|
|
/* If creating a super- or main-file journal, this function will open
|
|
** a file-descriptor on the directory too. The first time unixSync()
|
|
** is called the directory file descriptor will be fsync()ed and close()d.
|
|
*/
|
|
isNewJrnl = libc.BoolInt32(isCreate != 0 && (eType == int32(SQLITE_OPEN_SUPER_JOURNAL) || eType == int32(SQLITE_OPEN_MAIN_JOURNAL) || eType == int32(SQLITE_OPEN_WAL)))
|
|
zName = zPath
|
|
/* Check the following statements are true:
|
|
**
|
|
** (a) Exactly one of the READWRITE and READONLY flags must be set, and
|
|
** (b) if CREATE is set, then READWRITE must also be set, and
|
|
** (c) if EXCLUSIVE is set, then CREATE must also be set.
|
|
** (d) if DELETEONCLOSE is set, then CREATE must also be set.
|
|
*/
|
|
/* The main DB, main journal, WAL file and super-journal are never
|
|
** automatically deleted. Nor are they ever temporary files. */
|
|
/* Assert that the upper layer has set one of the "file-type" flags. */
|
|
/* Detect a pid change and reset the PRNG. There is a race condition
|
|
** here such that two or more threads all trying to open databases at
|
|
** the same instant might all reset the PRNG. But multiple resets
|
|
** are harmless.
|
|
*/
|
|
if libc.AtomicLoadPInt32(uintptr(unsafe.Pointer(&_randomnessPid))) != libc.Xgetpid(tls) {
|
|
libc.AtomicStorePInt32(uintptr(unsafe.Pointer(&_randomnessPid)), libc.Xgetpid(tls))
|
|
Xsqlite3_randomness(tls, 0, uintptr(0))
|
|
}
|
|
libc.Xmemset(tls, p, 0, uint32(84))
|
|
if eType == int32(SQLITE_OPEN_MAIN_DB) {
|
|
pUnused = _findReusableFd(tls, zName, flags)
|
|
if pUnused != 0 {
|
|
fd = (*TUnixUnusedFd)(unsafe.Pointer(pUnused)).Ffd
|
|
} else {
|
|
pUnused = Xsqlite3_malloc64(tls, uint64(12))
|
|
if !(pUnused != 0) {
|
|
return int32(SQLITE_NOMEM)
|
|
}
|
|
}
|
|
(*TunixFile)(unsafe.Pointer(p)).FpPreallocatedUnused = pUnused
|
|
/* Database filenames are double-zero terminated if they are not
|
|
** URIs with parameters. Hence, they can always be passed into
|
|
** sqlite3_uri_parameter(). */
|
|
} else {
|
|
if !(zName != 0) {
|
|
/* If zName is NULL, the upper layer is requesting a temp file. */
|
|
rc = _unixGetTempname(tls, (*Tsqlite3_vfs)(unsafe.Pointer(pVfs)).FmxPathname, bp)
|
|
if rc != SQLITE_OK {
|
|
return rc
|
|
}
|
|
zName = bp
|
|
/* Generated temporary filenames are always double-zero terminated
|
|
** for use by sqlite3_uri_parameter(). */
|
|
}
|
|
}
|
|
/* Determine the value of the flags parameter passed to POSIX function
|
|
** open(). These must be calculated even if open() is not called, as
|
|
** they may be stored as part of the file handle and used by the
|
|
** 'conch file' locking functions later on. */
|
|
if isReadonly != 0 {
|
|
openFlags = openFlags | O_RDONLY
|
|
}
|
|
if isReadWrite != 0 {
|
|
openFlags = openFlags | int32(O_RDWR)
|
|
}
|
|
if isCreate != 0 {
|
|
openFlags = openFlags | int32(O_CREAT)
|
|
}
|
|
if isExclusive != 0 {
|
|
openFlags = openFlags | (libc.Int32FromInt32(O_EXCL) | libc.Int32FromInt32(O_NOFOLLOW))
|
|
}
|
|
openFlags = openFlags | (libc.Int32FromInt32(O_LARGEFILE) | libc.Int32FromInt32(O_BINARY) | libc.Int32FromInt32(O_NOFOLLOW))
|
|
if fd < 0 { /* Groupid for the file */
|
|
rc = _findCreateFileMode(tls, zName, flags, bp+514, bp+516, bp+520)
|
|
if rc != SQLITE_OK {
|
|
return rc
|
|
}
|
|
fd = _robust_open(tls, zName, openFlags, **(**Tmode_t)(__ccgo_up(bp + 514)))
|
|
if fd < 0 {
|
|
if isNewJrnl != 0 && **(**int32)(__ccgo_up(libc.X__error(tls))) == int32(EACCES) && (*(*func(*libc.TLS, uintptr, int32) int32)(unsafe.Pointer(&struct{ uintptr }{_aSyscall[int32(2)].FpCurrent})))(tls, zName, F_OK) != 0 {
|
|
/* If unable to create a journal because the directory is not
|
|
** writable, change the error code to indicate that. */
|
|
rc = libc.Int32FromInt32(SQLITE_READONLY) | libc.Int32FromInt32(6)<<libc.Int32FromInt32(8)
|
|
} else {
|
|
if **(**int32)(__ccgo_up(libc.X__error(tls))) != int32(EISDIR) && isReadWrite != 0 {
|
|
/* Failed to open the file for read/write access. Try read-only. */
|
|
pReadonly = uintptr(0)
|
|
flags = flags & ^(libc.Int32FromInt32(SQLITE_OPEN_READWRITE) | libc.Int32FromInt32(SQLITE_OPEN_CREATE))
|
|
openFlags = openFlags & ^(libc.Int32FromInt32(O_RDWR) | libc.Int32FromInt32(O_CREAT))
|
|
flags = flags | int32(SQLITE_OPEN_READONLY)
|
|
openFlags = openFlags | O_RDONLY
|
|
isReadonly = int32(1)
|
|
pReadonly = _findReusableFd(tls, zName, flags)
|
|
if pReadonly != 0 {
|
|
fd = (*TUnixUnusedFd)(unsafe.Pointer(pReadonly)).Ffd
|
|
Xsqlite3_free(tls, pReadonly)
|
|
} else {
|
|
fd = _robust_open(tls, zName, openFlags, **(**Tmode_t)(__ccgo_up(bp + 514)))
|
|
}
|
|
}
|
|
}
|
|
}
|
|
if fd < 0 {
|
|
rc2 = _unixLogErrorAtLine(tls, _sqlite3CantopenError(tls, int32(46904)), __ccgo_ts+3540, zName, int32(46904))
|
|
if rc == SQLITE_OK {
|
|
rc = rc2
|
|
}
|
|
goto open_finished
|
|
}
|
|
/* The owner of the rollback journal or WAL file should always be the
|
|
** same as the owner of the database file. Try to ensure that this is
|
|
** the case. The chown() system call will be a no-op if the current
|
|
** process lacks root privileges, be we should at least try. Without
|
|
** this step, if a root process opens a database file, it can leave
|
|
** behinds a journal/WAL that is owned by root and hence make the
|
|
** database inaccessible to unprivileged processes.
|
|
**
|
|
** If openMode==0, then that means uid and gid are not set correctly
|
|
** (probably because SQLite is configured to use 8+3 filename mode) and
|
|
** in that case we do not want to attempt the chown().
|
|
*/
|
|
if **(**Tmode_t)(__ccgo_up(bp + 514)) != 0 && flags&(libc.Int32FromInt32(SQLITE_OPEN_WAL)|libc.Int32FromInt32(SQLITE_OPEN_MAIN_JOURNAL)) != 0 {
|
|
_robustFchown(tls, fd, **(**Tuid_t)(__ccgo_up(bp + 516)), **(**Tgid_t)(__ccgo_up(bp + 520)))
|
|
}
|
|
}
|
|
if pOutFlags != 0 {
|
|
**(**int32)(__ccgo_up(pOutFlags)) = flags
|
|
}
|
|
if (*TunixFile)(unsafe.Pointer(p)).FpPreallocatedUnused != 0 {
|
|
(*TUnixUnusedFd)(unsafe.Pointer((*TunixFile)(unsafe.Pointer(p)).FpPreallocatedUnused)).Ffd = fd
|
|
(*TUnixUnusedFd)(unsafe.Pointer((*TunixFile)(unsafe.Pointer(p)).FpPreallocatedUnused)).Fflags = flags & (libc.Int32FromInt32(SQLITE_OPEN_READONLY) | libc.Int32FromInt32(SQLITE_OPEN_READWRITE))
|
|
}
|
|
if isDelete != 0 {
|
|
(*(*func(*libc.TLS, uintptr) int32)(unsafe.Pointer(&struct{ uintptr }{_aSyscall[int32(16)].FpCurrent})))(tls, zName)
|
|
}
|
|
/* Set up appropriate ctrlFlags */
|
|
if isDelete != 0 {
|
|
ctrlFlags = ctrlFlags | int32(UNIXFILE_DELETE)
|
|
}
|
|
if isReadonly != 0 {
|
|
ctrlFlags = ctrlFlags | int32(UNIXFILE_RDONLY)
|
|
}
|
|
noLock = libc.BoolInt32(eType != int32(SQLITE_OPEN_MAIN_DB))
|
|
if noLock != 0 {
|
|
ctrlFlags = ctrlFlags | int32(UNIXFILE_NOLOCK)
|
|
}
|
|
if isNewJrnl != 0 {
|
|
ctrlFlags = ctrlFlags | int32(UNIXFILE_DIRSYNC)
|
|
}
|
|
if flags&int32(SQLITE_OPEN_URI) != 0 {
|
|
ctrlFlags = ctrlFlags | int32(UNIXFILE_URI)
|
|
}
|
|
rc = _fillInUnixFile(tls, pVfs, fd, pFile, zPath, ctrlFlags)
|
|
goto open_finished
|
|
open_finished:
|
|
;
|
|
if rc != SQLITE_OK {
|
|
Xsqlite3_free(tls, (*TunixFile)(unsafe.Pointer(p)).FpPreallocatedUnused)
|
|
}
|
|
return rc
|
|
}
|
|
|
|
// 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(224)
|
|
defer tls.Free(224)
|
|
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(16))
|
|
if p == uintptr(0) {
|
|
return int32(SQLITE_NOMEM)
|
|
}
|
|
libc.Xmemset(tls, p, 0, uint32(16))
|
|
/* 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.Int32FromUint32(libc.Xstrlen(tls, zBasePath))
|
|
pShmNode = Xsqlite3_malloc64(tls, uint64(uint32(68)+libc.Uint32FromInt32(nShmFilename)))
|
|
if pShmNode == uintptr(0) {
|
|
rc = int32(SQLITE_NOMEM)
|
|
goto shm_open_err
|
|
}
|
|
libc.Xmemset(tls, pShmNode, 0, uint32(68)+libc.Uint32FromInt32(nShmFilename))
|
|
v1 = pShmNode + 1*68
|
|
(*TunixShmNode)(unsafe.Pointer(pShmNode)).FzFilename = v1
|
|
zShm = v1
|
|
Xsqlite3_snprintf(tls, nShmFilename, zShm, __ccgo_ts+3956, libc.VaList(bp+216, 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+3963, 0) {
|
|
(*TunixShmNode)(unsafe.Pointer(pShmNode)).FhShm = _robust_open(tls, zShm, libc.Int32FromInt32(O_RDWR)|libc.Int32FromInt32(O_CREAT)|libc.Int32FromInt32(O_NOFOLLOW), libc.Uint16FromInt32(libc.Int32FromUint16((**(**Tstat)(__ccgo_up(bp))).Fst_mode)&libc.Int32FromInt32(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), libc.Uint16FromInt32(libc.Int32FromUint16((**(**Tstat)(__ccgo_up(bp))).Fst_mode)&libc.Int32FromInt32(0777)))
|
|
if (*TunixShmNode)(unsafe.Pointer(pShmNode)).FhShm < 0 {
|
|
rc = _unixLogErrorAtLine(tls, _sqlite3CantopenError(tls, int32(45237)), __ccgo_ts+3540, 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+4 */ 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.Uint32FromInt32(nBuf))
|
|
libc.AtomicStorePInt32(uintptr(unsafe.Pointer(&_randomnessPid)), libc.Xgetpid(tls))
|
|
fd = _robust_open(tls, __ccgo_ts+4073, O_RDONLY, uint16(0))
|
|
if fd < 0 {
|
|
libc.Xtime(tls, bp)
|
|
libc.Xmemcpy(tls, zBuf, bp, uint32(4))
|
|
**(**Tpid_t)(__ccgo_up(bp + 4)) = libc.AtomicLoadPInt32(uintptr(unsafe.Pointer(&_randomnessPid)))
|
|
libc.Xmemcpy(tls, zBuf+uintptr(4), bp+4, uint32(4))
|
|
nBuf = libc.Int32FromUint32(libc.Uint32FromInt64(4) + libc.Uint32FromInt64(4))
|
|
} else {
|
|
for cond := true; cond; cond = got < 0 && **(**int32)(__ccgo_up(libc.X__error(tls))) == int32(EINTR) {
|
|
got = (*(*func(*libc.TLS, int32, uintptr, Tsize_t) Tssize_t)(unsafe.Pointer(&struct{ uintptr }{_aSyscall[int32(8)].FpCurrent})))(tls, fd, zBuf, libc.Uint32FromInt32(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(224)
|
|
defer tls.Free(224)
|
|
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+208 */ 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 + 208)) = 0
|
|
if _seekAndWriteFd(tls, (*TunixShmNode)(unsafe.Pointer(pShmNode)).FhShm, iPg*int64(_pgsz)+int64(_pgsz)-int64(1), __ccgo_ts+1702, int32(1), bp+208) != int32(1) {
|
|
zFile = (*TunixShmNode)(unsafe.Pointer(pShmNode)).FzFilename
|
|
rc = _unixLogErrorAtLine(tls, libc.Int32FromInt32(SQLITE_IOERR)|libc.Int32FromInt32(19)<<libc.Int32FromInt32(8), __ccgo_ts+3611, 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.Uint32FromInt32(nReqRegion)*uint32(4)))
|
|
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.Uint32FromInt64(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+3698, (*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.Uint32FromInt64(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)*4)) = pMem + uintptr(int64(szRegion)*i)
|
|
goto _3
|
|
_3:
|
|
;
|
|
i = i + 1
|
|
}
|
|
v4 = pShmNode + 20
|
|
*(*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)*4))
|
|
} 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
|
|
//
|
|
// /*
|
|
// ** Sleep for a little while. Return the amount of time slept.
|
|
// ** The argument is the number of microseconds we want to sleep.
|
|
// ** The return value is the number of microseconds of sleep actually
|
|
// ** requested from the underlying operating system, a number which
|
|
// ** might be greater than or equal to the argument, but not less
|
|
// ** than the argument.
|
|
// */
|
|
func _unixSleep(tls *libc.TLS, NotUsed uintptr, microseconds int32) (r int32) {
|
|
bp := tls.Alloc(16)
|
|
defer tls.Free(16)
|
|
var _ /* sp at bp+0 */ Ttimespec
|
|
(**(**Ttimespec)(__ccgo_up(bp))).Ftv_sec = microseconds / int32(1000000)
|
|
(**(**Ttimespec)(__ccgo_up(bp))).Ftv_nsec = microseconds % int32(1000000) * int32(1000)
|
|
/* Almost all modern unix systems support nanosleep(). But if you are
|
|
** compiling for one of the rare exceptions, you can use
|
|
** -DHAVE_NANOSLEEP=0 (perhaps in conjunction with -DHAVE_USLEEP if
|
|
** usleep() is available) in order to bypass the use of nanosleep() */
|
|
libc.Xnanosleep(tls, bp, libc.UintptrFromInt32(0))
|
|
_ = NotUsed
|
|
return microseconds
|
|
}
|
|
|
|
/*
|
|
** The following variable, if set to a non-zero value, is interpreted as
|
|
** the number of seconds since 1970 and is used to set the result of
|
|
** sqlite3OsCurrentTime() during testing.
|
|
*/
|
|
|
|
// 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(208)
|
|
defer tls.Free(208)
|
|
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 && libc.Int32FromUint16((**(**Tstat)(__ccgo_up(bp))).Fst_mode)&int32(0170000) == int32(0040000) && (*(*func(*libc.TLS, uintptr, int32) int32)(unsafe.Pointer(&struct{ uintptr }{_aSyscall[int32(2)].FpCurrent})))(tls, zDir, int32(03)) == 0 {
|
|
return zDir
|
|
}
|
|
if i >= libc.Uint32FromInt64(24)/libc.Uint32FromInt64(4) {
|
|
break
|
|
}
|
|
v1 = i
|
|
i = i + 1
|
|
zDir = _azTempDirs[v1]
|
|
}
|
|
return uintptr(0)
|
|
}
|
|
|
|
// C documentation
|
|
//
|
|
// /*
|
|
// ** Extract a value from the supplied expression in the manner described
|
|
// ** above sqlite3ValueFromExpr(). Allocate the sqlite3_value object
|
|
// ** using valueNew().
|
|
// **
|
|
// ** If pCtx is NULL and an error occurs after the sqlite3_value object
|
|
// ** has been allocated, it is freed before returning. Or, if pCtx is not
|
|
// ** NULL, it is assumed that the caller will free any allocated object
|
|
// ** in all cases.
|
|
// */
|
|
func _valueFromExpr(tls *libc.TLS, db uintptr, pExpr uintptr, enc Tu8, affinity Tu8, ppVal uintptr, pCtx uintptr) (r int32) {
|
|
bp := tls.Alloc(48)
|
|
defer tls.Free(48)
|
|
var aff Tu8
|
|
var nVal, negInt, op, rc, v1 int32
|
|
var pLeft, zNeg, zVal, v3 uintptr
|
|
var _ /* iVal at bp+8 */ Ti64
|
|
var _ /* pVal at bp+0 */ uintptr
|
|
_, _, _, _, _, _, _, _, _, _ = aff, nVal, negInt, op, pLeft, rc, zNeg, zVal, v1, v3
|
|
zVal = uintptr(0)
|
|
**(**uintptr)(__ccgo_up(bp)) = uintptr(0)
|
|
negInt = int32(1)
|
|
zNeg = __ccgo_ts + 1702
|
|
rc = SQLITE_OK
|
|
for {
|
|
v1 = libc.Int32FromUint8((*TExpr)(unsafe.Pointer(pExpr)).Fop)
|
|
op = v1
|
|
if !(v1 == int32(TK_UPLUS) || op == int32(TK_SPAN)) {
|
|
break
|
|
}
|
|
pExpr = (*TExpr)(unsafe.Pointer(pExpr)).FpLeft
|
|
}
|
|
if op == int32(TK_REGISTER) {
|
|
op = libc.Int32FromUint8((*TExpr)(unsafe.Pointer(pExpr)).Fop2)
|
|
}
|
|
/* Compressed expressions only appear when parsing the DEFAULT clause
|
|
** on a table column definition, and hence only when pCtx==0. This
|
|
** check ensures that an EP_TokenOnly expression is never passed down
|
|
** into valueFromFunction(). */
|
|
if op == int32(TK_CAST) {
|
|
aff = libc.Uint8FromInt8(_sqlite3AffinityType(tls, *(*uintptr)(unsafe.Pointer(pExpr + 8)), uintptr(0)))
|
|
rc = _valueFromExpr(tls, db, (*TExpr)(unsafe.Pointer(pExpr)).FpLeft, enc, aff, ppVal, pCtx)
|
|
if **(**uintptr)(__ccgo_up(ppVal)) != 0 {
|
|
if libc.Int32FromUint16((*Tsqlite3_value)(unsafe.Pointer(**(**uintptr)(__ccgo_up(ppVal)))).Fflags)&int32(MEM_Zero) != 0 {
|
|
v1 = _sqlite3VdbeMemExpandBlob(tls, **(**uintptr)(__ccgo_up(ppVal)))
|
|
} else {
|
|
v1 = 0
|
|
}
|
|
rc = v1
|
|
_sqlite3VdbeMemCast(tls, **(**uintptr)(__ccgo_up(ppVal)), aff, enc)
|
|
_sqlite3ValueApplyAffinity(tls, **(**uintptr)(__ccgo_up(ppVal)), affinity, enc)
|
|
}
|
|
return rc
|
|
}
|
|
/* Handle negative integers in a single step. This is needed in the
|
|
** case when the value is -9223372036854775808. Except - do not do this
|
|
** for hexadecimal literals. */
|
|
if op == int32(TK_UMINUS) {
|
|
pLeft = (*TExpr)(unsafe.Pointer(pExpr)).FpLeft
|
|
if libc.Int32FromUint8((*TExpr)(unsafe.Pointer(pLeft)).Fop) == int32(TK_INTEGER) || libc.Int32FromUint8((*TExpr)(unsafe.Pointer(pLeft)).Fop) == int32(TK_FLOAT) {
|
|
if (*TExpr)(unsafe.Pointer(pLeft)).Fflags&libc.Uint32FromInt32(libc.Int32FromInt32(EP_IntValue)) != uint32(0) || int32(**(**int8)(__ccgo_up(*(*uintptr)(unsafe.Pointer(pLeft + 8))))) != int32('0') || int32(**(**int8)(__ccgo_up(*(*uintptr)(unsafe.Pointer(pLeft + 8)) + 1))) & ^libc.Int32FromInt32(0x20) != int32('X') {
|
|
pExpr = pLeft
|
|
op = libc.Int32FromUint8((*TExpr)(unsafe.Pointer(pExpr)).Fop)
|
|
negInt = -int32(1)
|
|
zNeg = __ccgo_ts + 5227
|
|
}
|
|
}
|
|
}
|
|
if op == int32(TK_STRING) || op == int32(TK_FLOAT) || op == int32(TK_INTEGER) {
|
|
**(**uintptr)(__ccgo_up(bp)) = _valueNew(tls, db, pCtx)
|
|
if **(**uintptr)(__ccgo_up(bp)) == uintptr(0) {
|
|
goto no_mem
|
|
}
|
|
if (*TExpr)(unsafe.Pointer(pExpr)).Fflags&libc.Uint32FromInt32(libc.Int32FromInt32(EP_IntValue)) != uint32(0) {
|
|
_sqlite3VdbeMemSetInt64(tls, **(**uintptr)(__ccgo_up(bp)), int64(*(*int32)(unsafe.Pointer(pExpr + 8)))*int64(negInt))
|
|
} else {
|
|
if op == int32(TK_INTEGER) && 0 == _sqlite3DecOrHexToI64(tls, *(*uintptr)(unsafe.Pointer(pExpr + 8)), bp+8) {
|
|
_sqlite3VdbeMemSetInt64(tls, **(**uintptr)(__ccgo_up(bp)), **(**Ti64)(__ccgo_up(bp + 8))*int64(negInt))
|
|
} else {
|
|
zVal = _sqlite3MPrintf(tls, db, __ccgo_ts+5229, libc.VaList(bp+24, zNeg, *(*uintptr)(unsafe.Pointer(pExpr + 8))))
|
|
if zVal == uintptr(0) {
|
|
goto no_mem
|
|
}
|
|
_sqlite3ValueSetStr(tls, **(**uintptr)(__ccgo_up(bp)), -int32(1), zVal, uint8(SQLITE_UTF8), __ccgo_fp(_sqlite3RowSetClear))
|
|
}
|
|
}
|
|
if libc.Int32FromUint8(affinity) == int32(SQLITE_AFF_BLOB) {
|
|
if op == int32(TK_FLOAT) {
|
|
_sqlite3AtoF(tls, (*Tsqlite3_value)(unsafe.Pointer(**(**uintptr)(__ccgo_up(bp)))).Fz, **(**uintptr)(__ccgo_up(bp)))
|
|
(*Tsqlite3_value)(unsafe.Pointer(**(**uintptr)(__ccgo_up(bp)))).Fflags = uint16(MEM_Real)
|
|
} else {
|
|
if op == int32(TK_INTEGER) {
|
|
/* This case is required by -9223372036854775808 and other strings
|
|
** that look like integers but cannot be handled by the
|
|
** sqlite3DecOrHexToI64() call above. */
|
|
_sqlite3ValueApplyAffinity(tls, **(**uintptr)(__ccgo_up(bp)), uint8(SQLITE_AFF_NUMERIC), uint8(SQLITE_UTF8))
|
|
}
|
|
}
|
|
} else {
|
|
_sqlite3ValueApplyAffinity(tls, **(**uintptr)(__ccgo_up(bp)), affinity, uint8(SQLITE_UTF8))
|
|
}
|
|
if libc.Int32FromUint16((*Tsqlite3_value)(unsafe.Pointer(**(**uintptr)(__ccgo_up(bp)))).Fflags)&(libc.Int32FromInt32(MEM_Int)|libc.Int32FromInt32(MEM_IntReal)|libc.Int32FromInt32(MEM_Real)) != 0 {
|
|
v3 = **(**uintptr)(__ccgo_up(bp)) + 16
|
|
*(*Tu16)(unsafe.Pointer(v3)) = Tu16(int32(*(*Tu16)(unsafe.Pointer(v3))) & ^libc.Int32FromInt32(MEM_Str))
|
|
}
|
|
if libc.Int32FromUint8(enc) != int32(SQLITE_UTF8) {
|
|
rc = _sqlite3VdbeChangeEncoding(tls, **(**uintptr)(__ccgo_up(bp)), libc.Int32FromUint8(enc))
|
|
}
|
|
} else {
|
|
if op == int32(TK_UMINUS) {
|
|
/* This branch happens for multiple negative signs. Ex: -(-5) */
|
|
if SQLITE_OK == _valueFromExpr(tls, db, (*TExpr)(unsafe.Pointer(pExpr)).FpLeft, enc, affinity, bp, pCtx) && **(**uintptr)(__ccgo_up(bp)) != uintptr(0) {
|
|
_sqlite3VdbeMemNumerify(tls, **(**uintptr)(__ccgo_up(bp)))
|
|
if libc.Int32FromUint16((*Tsqlite3_value)(unsafe.Pointer(**(**uintptr)(__ccgo_up(bp)))).Fflags)&int32(MEM_Real) != 0 {
|
|
*(*float64)(unsafe.Pointer(**(**uintptr)(__ccgo_up(bp)))) = -*(*float64)(unsafe.Pointer(**(**uintptr)(__ccgo_up(bp))))
|
|
} else {
|
|
if *(*Ti64)(unsafe.Pointer(**(**uintptr)(__ccgo_up(bp)))) == int64(-libc.Int32FromInt32(1))-(libc.Int64FromUint32(0xffffffff)|libc.Int64FromInt32(0x7fffffff)<<libc.Int32FromInt32(32)) {
|
|
*(*float64)(unsafe.Pointer(**(**uintptr)(__ccgo_up(bp)))) = -float64(int64(-libc.Int32FromInt32(1)) - (libc.Int64FromUint32(0xffffffff) | libc.Int64FromInt32(0x7fffffff)<<libc.Int32FromInt32(32)))
|
|
(*Tsqlite3_value)(unsafe.Pointer(**(**uintptr)(__ccgo_up(bp)))).Fflags = libc.Uint16FromInt32(libc.Int32FromUint16((*Tsqlite3_value)(unsafe.Pointer(**(**uintptr)(__ccgo_up(bp)))).Fflags) & ^(libc.Int32FromInt32(MEM_TypeMask)|libc.Int32FromInt32(MEM_Zero)) | int32(MEM_Real))
|
|
} else {
|
|
*(*Ti64)(unsafe.Pointer(**(**uintptr)(__ccgo_up(bp)))) = -*(*Ti64)(unsafe.Pointer(**(**uintptr)(__ccgo_up(bp))))
|
|
}
|
|
}
|
|
_sqlite3ValueApplyAffinity(tls, **(**uintptr)(__ccgo_up(bp)), affinity, enc)
|
|
}
|
|
} else {
|
|
if op == int32(TK_NULL) {
|
|
**(**uintptr)(__ccgo_up(bp)) = _valueNew(tls, db, pCtx)
|
|
if **(**uintptr)(__ccgo_up(bp)) == uintptr(0) {
|
|
goto no_mem
|
|
}
|
|
_sqlite3VdbeMemSetNull(tls, **(**uintptr)(__ccgo_up(bp)))
|
|
} else {
|
|
if op == int32(TK_BLOB) {
|
|
**(**uintptr)(__ccgo_up(bp)) = _valueNew(tls, db, pCtx)
|
|
if !(**(**uintptr)(__ccgo_up(bp)) != 0) {
|
|
goto no_mem
|
|
}
|
|
zVal = *(*uintptr)(unsafe.Pointer(pExpr + 8)) + 2
|
|
nVal = _sqlite3Strlen30(tls, zVal) - int32(1)
|
|
_sqlite3VdbeMemSetStr(tls, **(**uintptr)(__ccgo_up(bp)), _sqlite3HexToBlob(tls, db, zVal, nVal), int64(nVal/int32(2)), uint8(0), __ccgo_fp(_sqlite3RowSetClear))
|
|
} else {
|
|
if op == int32(TK_FUNCTION) && pCtx != uintptr(0) {
|
|
rc = _valueFromFunction(tls, db, pExpr, enc, affinity, bp, pCtx)
|
|
} else {
|
|
if op == int32(TK_TRUEFALSE) {
|
|
**(**uintptr)(__ccgo_up(bp)) = _valueNew(tls, db, pCtx)
|
|
if **(**uintptr)(__ccgo_up(bp)) != 0 {
|
|
(*Tsqlite3_value)(unsafe.Pointer(**(**uintptr)(__ccgo_up(bp)))).Fflags = uint16(MEM_Int)
|
|
*(*Ti64)(unsafe.Pointer(**(**uintptr)(__ccgo_up(bp)))) = libc.BoolInt64(int32(**(**int8)(__ccgo_up(*(*uintptr)(unsafe.Pointer(pExpr + 8)) + 4))) == 0)
|
|
_sqlite3ValueApplyAffinity(tls, **(**uintptr)(__ccgo_up(bp)), affinity, enc)
|
|
}
|
|
}
|
|
}
|
|
}
|
|
}
|
|
}
|
|
}
|
|
**(**uintptr)(__ccgo_up(ppVal)) = **(**uintptr)(__ccgo_up(bp))
|
|
return rc
|
|
goto no_mem
|
|
no_mem:
|
|
;
|
|
if pCtx == uintptr(0) || (*TParse)(unsafe.Pointer((*TValueNewStat4Ctx)(unsafe.Pointer(pCtx)).FpParse)).FnErr == 0 {
|
|
_sqlite3OomFault(tls, db)
|
|
}
|
|
_sqlite3DbFree(tls, db, zVal)
|
|
if pCtx == uintptr(0) {
|
|
_sqlite3ValueFree(tls, **(**uintptr)(__ccgo_up(bp)))
|
|
}
|
|
return int32(SQLITE_NOMEM)
|
|
}
|
|
|
|
// C documentation
|
|
//
|
|
// /*
|
|
// ** Render a Mem object which is one of MEM_Int, MEM_Real, or MEM_IntReal
|
|
// ** into a buffer.
|
|
// */
|
|
func _vdbeMemRenderNum(tls *libc.TLS, sz int32, zBuf uintptr, p uintptr) {
|
|
bp := tls.Alloc(48)
|
|
defer tls.Free(48)
|
|
var v1 int32
|
|
var _ /* acc at bp+0 */ TStrAccum
|
|
_ = v1
|
|
if libc.Int32FromUint16((*TMem)(unsafe.Pointer(p)).Fflags)&(libc.Int32FromInt32(MEM_Int)|libc.Int32FromInt32(MEM_IntReal)) != 0 {
|
|
(*TMem)(unsafe.Pointer(p)).Fn = _sqlite3Int64ToText(tls, *(*Ti64)(unsafe.Pointer(p)), zBuf)
|
|
if libc.Int32FromUint16((*TMem)(unsafe.Pointer(p)).Fflags)&int32(MEM_IntReal) != 0 {
|
|
libc.Xmemcpy(tls, zBuf+uintptr((*TMem)(unsafe.Pointer(p)).Fn), __ccgo_ts+5218, uint32(3))
|
|
**(**int32)(__ccgo_up(p + 12)) += int32(2)
|
|
}
|
|
} else {
|
|
_sqlite3StrAccumInit(tls, bp, uintptr(0), zBuf, sz, 0)
|
|
if (*TMem)(unsafe.Pointer(p)).Fdb != 0 {
|
|
v1 = libc.Int32FromUint8((*Tsqlite3)(unsafe.Pointer((*TMem)(unsafe.Pointer(p)).Fdb)).FnFpDigit)
|
|
} else {
|
|
v1 = int32(17)
|
|
}
|
|
Xsqlite3_str_appendf(tls, bp, __ccgo_ts+5221, libc.VaList(bp+32, v1, *(*float64)(unsafe.Pointer(p))))
|
|
**(**int8)(__ccgo_up(zBuf + uintptr((**(**TStrAccum)(__ccgo_up(bp))).FnChar))) = 0 /* Fast version of sqlite3StrAccumFinish(&acc) */
|
|
(*TMem)(unsafe.Pointer(p)).Fn = libc.Int32FromUint32((**(**TStrAccum)(__ccgo_up(bp))).FnChar)
|
|
}
|
|
}
|
|
|
|
// 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+5675, 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)*40
|
|
_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+144, 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(224)
|
|
defer tls.Free(224)
|
|
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+3834, libc.VaList(bp+216, (*TunixFile)(unsafe.Pointer(pFile)).FzPath))
|
|
return
|
|
}
|
|
if (**(**Tstat)(__ccgo_up(bp))).Fst_nlink == uint64(0) {
|
|
Xsqlite3_log(tls, int32(SQLITE_WARNING), __ccgo_ts+3858, libc.VaList(bp+216, (*TunixFile)(unsafe.Pointer(pFile)).FzPath))
|
|
return
|
|
}
|
|
if (**(**Tstat)(__ccgo_up(bp))).Fst_nlink > uint64(1) {
|
|
Xsqlite3_log(tls, int32(SQLITE_WARNING), __ccgo_ts+3887, libc.VaList(bp+216, (*TunixFile)(unsafe.Pointer(pFile)).FzPath))
|
|
return
|
|
}
|
|
if _fileHasMoved(tls, pFile) != 0 {
|
|
Xsqlite3_log(tls, int32(SQLITE_WARNING), __ccgo_ts+3914, libc.VaList(bp+216, (*TunixFile)(unsafe.Pointer(pFile)).FzPath))
|
|
return
|
|
}
|
|
}
|
|
|
|
// C documentation
|
|
//
|
|
// /*
|
|
// ** The Table structure pTable is really a VIEW. Fill in the names of
|
|
// ** the columns of the view in the pTable structure. Return non-zero if
|
|
// ** there are errors. If an error is seen an error message is left
|
|
// ** in pParse->zErrMsg.
|
|
// */
|
|
func _viewGetColumnNames(tls *libc.TLS, pParse uintptr, pTable uintptr) (r int32) {
|
|
bp := tls.Alloc(16)
|
|
defer tls.Free(16)
|
|
var db, pSel, pSelTab, v2 uintptr
|
|
var eParseMode Tu8
|
|
var nErr, nSelect, nTab, rc, v1 int32
|
|
var xAuth Tsqlite3_xauth
|
|
_, _, _, _, _, _, _, _, _, _, _ = db, eParseMode, nErr, nSelect, nTab, pSel, pSelTab, rc, xAuth, v1, v2 /* Copy of the SELECT that implements the view */
|
|
nErr = 0 /* Number of errors encountered */
|
|
db = (*TParse)(unsafe.Pointer(pParse)).Fdb /* Saved xAuth pointer */
|
|
if libc.Int32FromUint8((*TTable)(unsafe.Pointer(pTable)).FeTabType) == int32(TABTYP_VTAB) {
|
|
(*Tsqlite3)(unsafe.Pointer(db)).FnSchemaLock = (*Tsqlite3)(unsafe.Pointer(db)).FnSchemaLock + 1
|
|
rc = _sqlite3VtabCallConnect(tls, pParse, pTable)
|
|
(*Tsqlite3)(unsafe.Pointer(db)).FnSchemaLock = (*Tsqlite3)(unsafe.Pointer(db)).FnSchemaLock - 1
|
|
return rc
|
|
}
|
|
/* A positive nCol means the columns names for this view are
|
|
** already known. This routine is not called unless either the
|
|
** table is virtual or nCol is zero.
|
|
*/
|
|
/* A negative nCol is a special marker meaning that we are currently
|
|
** trying to compute the column names. If we enter this routine with
|
|
** a negative nCol, it means two or more views form a loop, like this:
|
|
**
|
|
** CREATE VIEW one AS SELECT * FROM two;
|
|
** CREATE VIEW two AS SELECT * FROM one;
|
|
**
|
|
** Actually, the error above is now caught prior to reaching this point.
|
|
** But the following test is still important as it does come up
|
|
** in the following:
|
|
**
|
|
** CREATE TABLE main.ex1(a);
|
|
** CREATE TEMP VIEW ex1 AS SELECT a FROM ex1;
|
|
** SELECT * FROM temp.ex1;
|
|
*/
|
|
if int32((*TTable)(unsafe.Pointer(pTable)).FnCol) < 0 {
|
|
_sqlite3ErrorMsg(tls, pParse, __ccgo_ts+14841, libc.VaList(bp+8, (*TTable)(unsafe.Pointer(pTable)).FzName))
|
|
return int32(1)
|
|
}
|
|
/* If we get this far, it means we need to compute the table names.
|
|
** Note that the call to sqlite3ResultSetOfSelect() will expand any
|
|
** "*" elements in the results set of the view and will assign cursors
|
|
** to the elements of the FROM clause. But we do not want these changes
|
|
** to be permanent. So the computation is done on a copy of the SELECT
|
|
** statement that defines the view.
|
|
*/
|
|
pSel = _sqlite3SelectDup(tls, db, (*(*struct {
|
|
FpSelect uintptr
|
|
})(unsafe.Pointer(&(*TTable)(unsafe.Pointer(pTable)).Fu))).FpSelect, 0)
|
|
if pSel != 0 {
|
|
eParseMode = (*TParse)(unsafe.Pointer(pParse)).FeParseMode
|
|
nTab = (*TParse)(unsafe.Pointer(pParse)).FnTab
|
|
nSelect = (*TParse)(unsafe.Pointer(pParse)).FnSelect
|
|
(*TParse)(unsafe.Pointer(pParse)).FeParseMode = uint8(PARSE_MODE_NORMAL)
|
|
_sqlite3SrcListAssignCursors(tls, pParse, (*TSelect)(unsafe.Pointer(pSel)).FpSrc)
|
|
(*TTable)(unsafe.Pointer(pTable)).FnCol = int16(-int32(1))
|
|
(*Tsqlite3)(unsafe.Pointer(db)).Flookaside.FbDisable = (*Tsqlite3)(unsafe.Pointer(db)).Flookaside.FbDisable + 1
|
|
(*Tsqlite3)(unsafe.Pointer(db)).Flookaside.Fsz = uint16(0)
|
|
xAuth = (*Tsqlite3)(unsafe.Pointer(db)).FxAuth
|
|
(*Tsqlite3)(unsafe.Pointer(db)).FxAuth = uintptr(0)
|
|
pSelTab = _sqlite3ResultSetOfSelect(tls, pParse, pSel, int8(SQLITE_AFF_NONE))
|
|
(*Tsqlite3)(unsafe.Pointer(db)).FxAuth = xAuth
|
|
(*TParse)(unsafe.Pointer(pParse)).FnTab = nTab
|
|
(*TParse)(unsafe.Pointer(pParse)).FnSelect = nSelect
|
|
if pSelTab == uintptr(0) {
|
|
(*TTable)(unsafe.Pointer(pTable)).FnCol = 0
|
|
nErr = nErr + 1
|
|
} else {
|
|
if (*TTable)(unsafe.Pointer(pTable)).FpCheck != 0 {
|
|
/* CREATE VIEW name(arglist) AS ...
|
|
** The names of the columns in the table are taken from
|
|
** arglist which is stored in pTable->pCheck. The pCheck field
|
|
** normally holds CHECK constraints on an ordinary table, but for
|
|
** a VIEW it holds the list of column names.
|
|
*/
|
|
_sqlite3ColumnsFromExprList(tls, pParse, (*TTable)(unsafe.Pointer(pTable)).FpCheck, pTable+34, pTable+4)
|
|
if (*TParse)(unsafe.Pointer(pParse)).FnErr == 0 && int32((*TTable)(unsafe.Pointer(pTable)).FnCol) == (*TExprList)(unsafe.Pointer((*TSelect)(unsafe.Pointer(pSel)).FpEList)).FnExpr {
|
|
_sqlite3SubqueryColumnTypes(tls, pParse, pTable, pSel, int8(SQLITE_AFF_NONE))
|
|
}
|
|
} else {
|
|
/* CREATE VIEW name AS... without an argument list. Construct
|
|
** the column names from the SELECT statement that defines the view.
|
|
*/
|
|
(*TTable)(unsafe.Pointer(pTable)).FnCol = (*TTable)(unsafe.Pointer(pSelTab)).FnCol
|
|
(*TTable)(unsafe.Pointer(pTable)).FaCol = (*TTable)(unsafe.Pointer(pSelTab)).FaCol
|
|
**(**Tu32)(__ccgo_up(pTable + 28)) |= (*TTable)(unsafe.Pointer(pSelTab)).FtabFlags & uint32(COLFLAG_NOINSERT)
|
|
(*TTable)(unsafe.Pointer(pSelTab)).FnCol = 0
|
|
(*TTable)(unsafe.Pointer(pSelTab)).FaCol = uintptr(0)
|
|
}
|
|
}
|
|
(*TTable)(unsafe.Pointer(pTable)).FnNVCol = (*TTable)(unsafe.Pointer(pTable)).FnCol
|
|
_sqlite3DeleteTable(tls, db, pSelTab)
|
|
_sqlite3SelectDelete(tls, db, pSel)
|
|
(*Tsqlite3)(unsafe.Pointer(db)).Flookaside.FbDisable = (*Tsqlite3)(unsafe.Pointer(db)).Flookaside.FbDisable - 1
|
|
if (*Tsqlite3)(unsafe.Pointer(db)).Flookaside.FbDisable != 0 {
|
|
v1 = 0
|
|
} else {
|
|
v1 = libc.Int32FromUint16((*Tsqlite3)(unsafe.Pointer(db)).Flookaside.FszTrue)
|
|
}
|
|
(*Tsqlite3)(unsafe.Pointer(db)).Flookaside.Fsz = libc.Uint16FromInt32(v1)
|
|
(*TParse)(unsafe.Pointer(pParse)).FeParseMode = eParseMode
|
|
} else {
|
|
nErr = nErr + 1
|
|
}
|
|
v2 = (*TTable)(unsafe.Pointer(pTable)).FpSchema + 78
|
|
*(*Tu16)(unsafe.Pointer(v2)) = Tu16(int32(*(*Tu16)(unsafe.Pointer(v2))) | libc.Int32FromInt32(DB_UnresetViews))
|
|
if (*Tsqlite3)(unsafe.Pointer(db)).FmallocFailed != 0 {
|
|
_sqlite3DeleteColumnNames(tls, db, pTable)
|
|
}
|
|
return nErr + (*TParse)(unsafe.Pointer(pParse)).FnErr
|
|
}
|
|
|
|
// C documentation
|
|
//
|
|
// /*
|
|
// ** Invoke a virtual table constructor (either xCreate or xConnect). The
|
|
// ** pointer to the function to invoke is passed as the fourth parameter
|
|
// ** to this procedure.
|
|
// */
|
|
func _vtabCallConstructor(tls *libc.TLS, db uintptr, pTab uintptr, pMod uintptr, __ccgo_fp_xConstruct uintptr, pzErr uintptr) (r int32) {
|
|
bp := tls.Alloc(48)
|
|
defer tls.Free(48)
|
|
var azArg, pCtx, pVTable, zFormat, zModuleName, zType, v6 uintptr
|
|
var i, iCol, iDb, j, nArg, nDel, nType, rc, v4 int32
|
|
var oooHidden Tu16
|
|
var _ /* sCtx at bp+0 */ TVtabCtx
|
|
var _ /* zErr at bp+16 */ uintptr
|
|
_, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _ = azArg, i, iCol, iDb, j, nArg, nDel, nType, oooHidden, pCtx, pVTable, rc, zFormat, zModuleName, zType, v4, v6
|
|
nArg = (*(*struct {
|
|
FnArg int32
|
|
FazArg uintptr
|
|
Fp uintptr
|
|
})(unsafe.Pointer(pTab + 44))).FnArg
|
|
**(**uintptr)(__ccgo_up(bp + 16)) = uintptr(0)
|
|
azArg = (*(*struct {
|
|
FnArg int32
|
|
FazArg uintptr
|
|
Fp uintptr
|
|
})(unsafe.Pointer(pTab + 44))).FazArg
|
|
/* Check that the virtual-table is not already being initialized */
|
|
pCtx = (*Tsqlite3)(unsafe.Pointer(db)).FpVtabCtx
|
|
for {
|
|
if !(pCtx != 0) {
|
|
break
|
|
}
|
|
if (*TVtabCtx)(unsafe.Pointer(pCtx)).FpTab == pTab {
|
|
**(**uintptr)(__ccgo_up(pzErr)) = _sqlite3MPrintf(tls, db, __ccgo_ts+23470, libc.VaList(bp+32, (*TTable)(unsafe.Pointer(pTab)).FzName))
|
|
return int32(SQLITE_LOCKED)
|
|
}
|
|
goto _1
|
|
_1:
|
|
;
|
|
pCtx = (*TVtabCtx)(unsafe.Pointer(pCtx)).FpPrior
|
|
}
|
|
zModuleName = _sqlite3DbStrDup(tls, db, (*TTable)(unsafe.Pointer(pTab)).FzName)
|
|
if !(zModuleName != 0) {
|
|
return int32(SQLITE_NOMEM)
|
|
}
|
|
pVTable = _sqlite3MallocZero(tls, uint64(28))
|
|
if !(pVTable != 0) {
|
|
_sqlite3OomFault(tls, db)
|
|
_sqlite3DbFree(tls, db, zModuleName)
|
|
return int32(SQLITE_NOMEM)
|
|
}
|
|
(*TVTable)(unsafe.Pointer(pVTable)).Fdb = db
|
|
(*TVTable)(unsafe.Pointer(pVTable)).FpMod = pMod
|
|
(*TVTable)(unsafe.Pointer(pVTable)).FeVtabRisk = uint8(SQLITE_VTABRISK_Normal)
|
|
iDb = _sqlite3SchemaToIndex(tls, db, (*TTable)(unsafe.Pointer(pTab)).FpSchema)
|
|
**(**uintptr)(__ccgo_up((*(*struct {
|
|
FnArg int32
|
|
FazArg uintptr
|
|
Fp uintptr
|
|
})(unsafe.Pointer(pTab + 44))).FazArg + 1*4)) = (**(**TDb)(__ccgo_up((*Tsqlite3)(unsafe.Pointer(db)).FaDb + uintptr(iDb)*16))).FzDbSName
|
|
/* Invoke the virtual table constructor */
|
|
(**(**TVtabCtx)(__ccgo_up(bp))).FpTab = pTab
|
|
(**(**TVtabCtx)(__ccgo_up(bp))).FpVTable = pVTable
|
|
(**(**TVtabCtx)(__ccgo_up(bp))).FpPrior = (*Tsqlite3)(unsafe.Pointer(db)).FpVtabCtx
|
|
(**(**TVtabCtx)(__ccgo_up(bp))).FbDeclared = 0
|
|
(*Tsqlite3)(unsafe.Pointer(db)).FpVtabCtx = bp
|
|
(*TTable)(unsafe.Pointer(pTab)).FnTabRef = (*TTable)(unsafe.Pointer(pTab)).FnTabRef + 1
|
|
rc = (*(*func(*libc.TLS, uintptr, uintptr, int32, uintptr, uintptr, uintptr) int32)(unsafe.Pointer(&struct{ uintptr }{__ccgo_fp_xConstruct})))(tls, db, (*TModule)(unsafe.Pointer(pMod)).FpAux, nArg, azArg, pVTable+8, bp+16)
|
|
_sqlite3DeleteTable(tls, db, pTab)
|
|
(*Tsqlite3)(unsafe.Pointer(db)).FpVtabCtx = (**(**TVtabCtx)(__ccgo_up(bp))).FpPrior
|
|
if rc == int32(SQLITE_NOMEM) {
|
|
_sqlite3OomFault(tls, db)
|
|
}
|
|
if SQLITE_OK != rc {
|
|
if **(**uintptr)(__ccgo_up(bp + 16)) == uintptr(0) {
|
|
**(**uintptr)(__ccgo_up(pzErr)) = _sqlite3MPrintf(tls, db, __ccgo_ts+23512, libc.VaList(bp+32, zModuleName))
|
|
} else {
|
|
**(**uintptr)(__ccgo_up(pzErr)) = _sqlite3MPrintf(tls, db, __ccgo_ts+3942, libc.VaList(bp+32, **(**uintptr)(__ccgo_up(bp + 16))))
|
|
Xsqlite3_free(tls, **(**uintptr)(__ccgo_up(bp + 16)))
|
|
}
|
|
_sqlite3DbFree(tls, db, pVTable)
|
|
} else {
|
|
if (*TVTable)(unsafe.Pointer(pVTable)).FpVtab != 0 {
|
|
/* Justification of ALWAYS(): A correct vtab constructor must allocate
|
|
** the sqlite3_vtab object if successful. */
|
|
libc.Xmemset(tls, (*TVTable)(unsafe.Pointer(pVTable)).FpVtab, 0, uint32(12))
|
|
(*Tsqlite3_vtab)(unsafe.Pointer((*TVTable)(unsafe.Pointer(pVTable)).FpVtab)).FpModule = (*TModule)(unsafe.Pointer(pMod)).FpModule
|
|
(*TModule)(unsafe.Pointer(pMod)).FnRefModule = (*TModule)(unsafe.Pointer(pMod)).FnRefModule + 1
|
|
(*TVTable)(unsafe.Pointer(pVTable)).FnRef = int32(1)
|
|
if (**(**TVtabCtx)(__ccgo_up(bp))).FbDeclared == 0 {
|
|
zFormat = __ccgo_ts + 23542
|
|
**(**uintptr)(__ccgo_up(pzErr)) = _sqlite3MPrintf(tls, db, zFormat, libc.VaList(bp+32, zModuleName))
|
|
_sqlite3VtabUnlock(tls, pVTable)
|
|
rc = int32(SQLITE_ERROR)
|
|
} else {
|
|
oooHidden = uint16(0)
|
|
/* If everything went according to plan, link the new VTable structure
|
|
** into the linked list headed by pTab->u.vtab.p. Then loop through the
|
|
** columns of the table to see if any of them contain the token "hidden".
|
|
** If so, set the Column COLFLAG_HIDDEN flag and remove the token from
|
|
** the type string. */
|
|
(*TVTable)(unsafe.Pointer(pVTable)).FpNext = (*(*struct {
|
|
FnArg int32
|
|
FazArg uintptr
|
|
Fp uintptr
|
|
})(unsafe.Pointer(pTab + 44))).Fp
|
|
(*(*struct {
|
|
FnArg int32
|
|
FazArg uintptr
|
|
Fp uintptr
|
|
})(unsafe.Pointer(pTab + 44))).Fp = pVTable
|
|
iCol = 0
|
|
for {
|
|
if !(iCol < int32((*TTable)(unsafe.Pointer(pTab)).FnCol)) {
|
|
break
|
|
}
|
|
zType = _sqlite3ColumnType(tls, (*TTable)(unsafe.Pointer(pTab)).FaCol+uintptr(iCol)*12, __ccgo_ts+1702)
|
|
i = 0
|
|
nType = _sqlite3Strlen30(tls, zType)
|
|
i = 0
|
|
for {
|
|
if !(i < nType) {
|
|
break
|
|
}
|
|
if 0 == Xsqlite3_strnicmp(tls, __ccgo_ts+17856, zType+uintptr(i), int32(6)) && (i == 0 || int32(**(**int8)(__ccgo_up(zType + uintptr(i-int32(1))))) == int32(' ')) && (int32(**(**int8)(__ccgo_up(zType + uintptr(i+int32(6))))) == int32('\000') || int32(**(**int8)(__ccgo_up(zType + uintptr(i+int32(6))))) == int32(' ')) {
|
|
break
|
|
}
|
|
goto _3
|
|
_3:
|
|
;
|
|
i = i + 1
|
|
}
|
|
if i < nType {
|
|
if **(**int8)(__ccgo_up(zType + uintptr(i+int32(6)))) != 0 {
|
|
v4 = int32(1)
|
|
} else {
|
|
v4 = 0
|
|
}
|
|
nDel = int32(6) + v4
|
|
j = i
|
|
for {
|
|
if !(j+nDel <= nType) {
|
|
break
|
|
}
|
|
**(**int8)(__ccgo_up(zType + uintptr(j))) = **(**int8)(__ccgo_up(zType + uintptr(j+nDel)))
|
|
goto _5
|
|
_5:
|
|
;
|
|
j = j + 1
|
|
}
|
|
if int32(**(**int8)(__ccgo_up(zType + uintptr(i)))) == int32('\000') && i > 0 {
|
|
**(**int8)(__ccgo_up(zType + uintptr(i-int32(1)))) = int8('\000')
|
|
}
|
|
v6 = (*TTable)(unsafe.Pointer(pTab)).FaCol + uintptr(iCol)*12 + 10
|
|
*(*Tu16)(unsafe.Pointer(v6)) = Tu16(int32(*(*Tu16)(unsafe.Pointer(v6))) | libc.Int32FromInt32(COLFLAG_HIDDEN))
|
|
**(**Tu32)(__ccgo_up(pTab + 28)) |= uint32(TF_HasHidden)
|
|
oooHidden = uint16(TF_OOOHidden)
|
|
} else {
|
|
**(**Tu32)(__ccgo_up(pTab + 28)) |= uint32(oooHidden)
|
|
}
|
|
goto _2
|
|
_2:
|
|
;
|
|
iCol = iCol + 1
|
|
}
|
|
}
|
|
}
|
|
}
|
|
_sqlite3DbFree(tls, db, zModuleName)
|
|
return rc
|
|
}
|
|
|
|
// 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)*48
|
|
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 + 28)) += uint32(SQLITE_QUERY_PLANNER_LIMIT_INCR)
|
|
(*TWhereLoop)(unsafe.Pointer(pNew)).FmaskSelf = _sqlite3WhereGetMask(tls, pWInfo+488, (*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 + 12 + 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 + 76
|
|
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 += 48
|
|
}
|
|
} 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*48
|
|
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+488, (*TSrcItem)(unsafe.Pointer(p)).FiCursor)
|
|
}
|
|
goto _3
|
|
_3:
|
|
;
|
|
p += 48
|
|
}
|
|
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+24049, 0)
|
|
rc = SQLITE_OK
|
|
} else {
|
|
break
|
|
}
|
|
}
|
|
goto _1
|
|
_1:
|
|
;
|
|
iTab = iTab + 1
|
|
pItem += 48
|
|
}
|
|
_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*64
|
|
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)*48
|
|
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 + 4))
|
|
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, uint32(8)*libc.Uint32FromInt32(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, uint32(4)*libc.Uint32FromInt32(nConstraint))
|
|
libc.Xmemset(tls, pNew+24, 0, uint32(16))
|
|
pIdxCons = **(**uintptr)(__ccgo_up(pIdxInfo + 4))
|
|
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)*4)) != uintptr(0) || libc.Int32FromUint8((*Tsqlite3_index_constraint)(unsafe.Pointer(pIdxCons)).Fusable) == 0 {
|
|
_sqlite3ErrorMsg(tls, pParse, __ccgo_ts+24023, 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)*4)) = 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 + 52)) &= ^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)*4)) == uintptr(0) {
|
|
/* The non-zero argvIdx values must be contiguous. Raise an
|
|
** error if they are not */
|
|
_sqlite3ErrorMsg(tls, pParse, __ccgo_ts+24023, 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 + 40)) |= uint32(WHERE_ONEROW)
|
|
} else {
|
|
**(**Tu32)(__ccgo_up(pNew + 40)) &= 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.Int32FromUint32((uint32(28) + uint32(4)*libc.Uint32FromInt32(nLoop)) * libc.Uint32FromInt32(mxChoice) * uint32(2))
|
|
nSpace = libc.Int32FromUint32(uint32(nSpace) + libc.Uint32FromInt64(2)*libc.Uint32FromInt32(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)*28
|
|
libc.Xmemset(tls, aFrom, 0, uint32(28))
|
|
pX = aFrom + uintptr(mxChoice)*28
|
|
ii = mxChoice * int32(2)
|
|
pFrom = aTo
|
|
for {
|
|
if !(ii > 0) {
|
|
break
|
|
}
|
|
(*TWherePath)(unsafe.Pointer(pFrom)).FaLoop = pX
|
|
goto _1
|
|
_1:
|
|
;
|
|
ii = ii - 1
|
|
pFrom += 28
|
|
pX = pX + uintptr(nLoop)*4
|
|
}
|
|
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, uint32(2)*libc.Uint32FromInt32(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 += 28
|
|
}
|
|
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)*28
|
|
} 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)*4))) != 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, uint32(4)*libc.Uint32FromInt32(iLoop))
|
|
**(**uintptr)(__ccgo_up((*TWherePath)(unsafe.Pointer(pTo)).FaLoop + uintptr(iLoop)*4)) = pWLoop
|
|
if nTo >= mxChoice {
|
|
mxI = 0
|
|
mxCost = (**(**TWherePath)(__ccgo_up(aTo))).FrCost
|
|
mxUnsort = (**(**TWherePath)(__ccgo_up(aTo))).FnRow
|
|
jj = int32(1)
|
|
pTo = aTo + 1*28
|
|
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 += 28
|
|
}
|
|
}
|
|
goto _6
|
|
_6:
|
|
;
|
|
pWLoop = (*TWhereLoop)(unsafe.Pointer(pWLoop)).FpNextLoop
|
|
}
|
|
goto _5
|
|
_5:
|
|
;
|
|
ii = ii + 1
|
|
pFrom += 28
|
|
}
|
|
/* 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+24084, 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 + 752 + uintptr(iLoop)*88
|
|
v11 = **(**uintptr)(__ccgo_up((*TWherePath)(unsafe.Pointer(pFrom)).FaLoop + uintptr(iLoop)*4))
|
|
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)*48))).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))*4)), 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+48, 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))*4)))).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))*4)), bp+16))
|
|
if rc1 == (*TExprList)(unsafe.Pointer((*TWhereInfo)(unsafe.Pointer(pWInfo)).FpOrderBy)).FnExpr {
|
|
libc.SetBitFieldPtr8Uint32(pWInfo+48, 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+48, 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))*4)), bp+24))
|
|
if nOrder == (*TExprList)(unsafe.Pointer((*TWhereInfo)(unsafe.Pointer(pWInfo)).FpOrderBy)).FnExpr {
|
|
libc.SetBitFieldPtr8Uint32(pWInfo+48, 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
|
|
//
|
|
// /*
|
|
// ** Perform a reduce action and the shift that must immediately
|
|
// ** follow the reduce.
|
|
// **
|
|
// ** The yyLookahead and yyLookaheadToken parameters provide reduce actions
|
|
// ** access to the lookahead token (if any). The yyLookahead will be YYNOCODE
|
|
// ** if the lookahead token has already been consumed. As this procedure is
|
|
// ** only called from one place, optimizing compilers will in-line it, which
|
|
// ** means that the extra parameters have no performance impact.
|
|
// */
|
|
func _yy_reduce(tls *libc.TLS, yypParser uintptr, yyruleno uint32, yyLookahead int32, yyLookaheadToken TToken, pParse uintptr) (r uint16) {
|
|
bp := tls.Alloc(112)
|
|
defer tls.Free(112)
|
|
var bNot, bNot1, i, nExpr, yygoto, yysize, v353 int32
|
|
var n Tu32
|
|
var op Tu8
|
|
var p, p1, p2, p3, p4, p5, pB, pDot, pFrom, pFromClause, pLeft, pLhs, pList, pList1, pList2, pList3, pList4, pNew, pOld, pRHS, pRhs, pRight, pSelect, pSelectRHS, pSrc, pSubquery, pSubquery1, temp1, temp11, temp2, temp21, temp3, temp4, yymsp, v352 uintptr
|
|
var yyact uint16
|
|
var v357 TToken
|
|
var _ /* all at bp+72 */ TToken
|
|
var _ /* as at bp+48 */ TToken
|
|
var _ /* dest at bp+8 */ TSelectDest
|
|
var _ /* iValue at bp+56 */ int32
|
|
var _ /* t at bp+64 */ TToken
|
|
var _ /* x at bp+40 */ TToken
|
|
var _ /* yylhsminor at bp+0 */ TYYMINORTYPE
|
|
_, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _ = bNot, bNot1, i, n, nExpr, op, p, p1, p2, p3, p4, p5, pB, pDot, pFrom, pFromClause, pLeft, pLhs, pList, pList1, pList2, pList3, pList4, pNew, pOld, pRHS, pRhs, pRight, pSelect, pSelectRHS, pSrc, pSubquery, pSubquery1, temp1, temp11, temp2, temp21, temp3, temp4, yyact, yygoto, yymsp, yysize, v352, v353, v357 /* Amount to pop the stack */
|
|
_ = yyLookahead
|
|
_ = yyLookaheadToken
|
|
yymsp = (*TyyParser)(unsafe.Pointer(yypParser)).Fyytos
|
|
switch yyruleno {
|
|
case uint32(0):
|
|
goto _1
|
|
case uint32(1):
|
|
goto _2
|
|
case uint32(2):
|
|
goto _3
|
|
case uint32(3):
|
|
goto _4
|
|
case uint32(4):
|
|
goto _5
|
|
case uint32(6):
|
|
goto _6
|
|
case uint32(5):
|
|
goto _7
|
|
case uint32(7):
|
|
goto _8
|
|
case uint32(328):
|
|
goto _9
|
|
case uint32(9):
|
|
goto _10
|
|
case uint32(8):
|
|
goto _11
|
|
case uint32(10):
|
|
goto _12
|
|
case uint32(11):
|
|
goto _13
|
|
case uint32(12):
|
|
goto _14
|
|
case uint32(13):
|
|
goto _15
|
|
case uint32(14):
|
|
goto _16
|
|
case uint32(18):
|
|
goto _17
|
|
case uint32(15):
|
|
goto _18
|
|
case uint32(47):
|
|
goto _19
|
|
case uint32(62):
|
|
goto _20
|
|
case uint32(72):
|
|
goto _21
|
|
case uint32(81):
|
|
goto _22
|
|
case uint32(100):
|
|
goto _23
|
|
case uint32(246):
|
|
goto _24
|
|
case uint32(16):
|
|
goto _25
|
|
case uint32(17):
|
|
goto _26
|
|
case uint32(19):
|
|
goto _27
|
|
case uint32(20):
|
|
goto _28
|
|
case uint32(21):
|
|
goto _29
|
|
case uint32(22):
|
|
goto _30
|
|
case uint32(23):
|
|
goto _31
|
|
case uint32(24):
|
|
goto _32
|
|
case uint32(25):
|
|
goto _33
|
|
case uint32(65):
|
|
goto _34
|
|
case uint32(26):
|
|
goto _35
|
|
case uint32(106):
|
|
goto _36
|
|
case uint32(27):
|
|
goto _37
|
|
case uint32(28):
|
|
goto _38
|
|
case uint32(29):
|
|
goto _39
|
|
case uint32(30):
|
|
goto _40
|
|
case uint32(31):
|
|
goto _41
|
|
case uint32(67):
|
|
goto _42
|
|
case uint32(32):
|
|
goto _43
|
|
case uint32(33):
|
|
goto _44
|
|
case uint32(34):
|
|
goto _45
|
|
case uint32(35):
|
|
goto _46
|
|
case uint32(36):
|
|
goto _47
|
|
case uint32(37):
|
|
goto _48
|
|
case uint32(38):
|
|
goto _49
|
|
case uint32(39):
|
|
goto _50
|
|
case uint32(40):
|
|
goto _51
|
|
case uint32(41):
|
|
goto _52
|
|
case uint32(42):
|
|
goto _53
|
|
case uint32(43):
|
|
goto _54
|
|
case uint32(44):
|
|
goto _55
|
|
case uint32(45):
|
|
goto _56
|
|
case uint32(46):
|
|
goto _57
|
|
case uint32(48):
|
|
goto _58
|
|
case uint32(49):
|
|
goto _59
|
|
case uint32(50):
|
|
goto _60
|
|
case uint32(51):
|
|
goto _61
|
|
case uint32(52):
|
|
goto _62
|
|
case uint32(53):
|
|
goto _63
|
|
case uint32(54):
|
|
goto _64
|
|
case uint32(55):
|
|
goto _65
|
|
case uint32(56):
|
|
goto _66
|
|
case uint32(57):
|
|
goto _67
|
|
case uint32(58):
|
|
goto _68
|
|
case uint32(59):
|
|
goto _69
|
|
case uint32(60):
|
|
goto _70
|
|
case uint32(76):
|
|
goto _71
|
|
case uint32(61):
|
|
goto _72
|
|
case uint32(173):
|
|
goto _73
|
|
case uint32(80):
|
|
goto _74
|
|
case uint32(63):
|
|
goto _75
|
|
case uint32(219):
|
|
goto _76
|
|
case uint32(222):
|
|
goto _77
|
|
case uint32(247):
|
|
goto _78
|
|
case uint32(64):
|
|
goto _79
|
|
case uint32(66):
|
|
goto _80
|
|
case uint32(68):
|
|
goto _81
|
|
case uint32(69):
|
|
goto _82
|
|
case uint32(70):
|
|
goto _83
|
|
case uint32(71):
|
|
goto _84
|
|
case uint32(75):
|
|
goto _85
|
|
case uint32(73):
|
|
goto _86
|
|
case uint32(74):
|
|
goto _87
|
|
case uint32(77):
|
|
goto _88
|
|
case uint32(174):
|
|
goto _89
|
|
case uint32(78):
|
|
goto _90
|
|
case uint32(79):
|
|
goto _91
|
|
case uint32(82):
|
|
goto _92
|
|
case uint32(83):
|
|
goto _93
|
|
case uint32(84):
|
|
goto _94
|
|
case uint32(85):
|
|
goto _95
|
|
case uint32(86):
|
|
goto _96
|
|
case uint32(87):
|
|
goto _97
|
|
case uint32(88):
|
|
goto _98
|
|
case uint32(91):
|
|
goto _99
|
|
case uint32(89):
|
|
goto _100
|
|
case uint32(90):
|
|
goto _101
|
|
case uint32(92):
|
|
goto _102
|
|
case uint32(93):
|
|
goto _103
|
|
case uint32(94):
|
|
goto _104
|
|
case uint32(95):
|
|
goto _105
|
|
case uint32(97):
|
|
goto _106
|
|
case uint32(96):
|
|
goto _107
|
|
case uint32(98):
|
|
goto _108
|
|
case uint32(99):
|
|
goto _109
|
|
case uint32(134):
|
|
goto _110
|
|
case uint32(101):
|
|
goto _111
|
|
case uint32(144):
|
|
goto _112
|
|
case uint32(234):
|
|
goto _113
|
|
case uint32(237):
|
|
goto _114
|
|
case uint32(242):
|
|
goto _115
|
|
case uint32(102):
|
|
goto _116
|
|
case uint32(103):
|
|
goto _117
|
|
case uint32(104):
|
|
goto _118
|
|
case uint32(117):
|
|
goto _119
|
|
case uint32(105):
|
|
goto _120
|
|
case uint32(258):
|
|
goto _121
|
|
case uint32(259):
|
|
goto _122
|
|
case uint32(110):
|
|
goto _123
|
|
case uint32(107):
|
|
goto _124
|
|
case uint32(108):
|
|
goto _125
|
|
case uint32(109):
|
|
goto _126
|
|
case uint32(111):
|
|
goto _127
|
|
case uint32(112):
|
|
goto _128
|
|
case uint32(113):
|
|
goto _129
|
|
case uint32(114):
|
|
goto _130
|
|
case uint32(115):
|
|
goto _131
|
|
case uint32(131):
|
|
goto _132
|
|
case uint32(116):
|
|
goto _133
|
|
case uint32(120):
|
|
goto _134
|
|
case uint32(118):
|
|
goto _135
|
|
case uint32(121):
|
|
goto _136
|
|
case uint32(119):
|
|
goto _137
|
|
case uint32(122):
|
|
goto _138
|
|
case uint32(123):
|
|
goto _139
|
|
case uint32(124):
|
|
goto _140
|
|
case uint32(125):
|
|
goto _141
|
|
case uint32(126):
|
|
goto _142
|
|
case uint32(127):
|
|
goto _143
|
|
case uint32(128):
|
|
goto _144
|
|
case uint32(129):
|
|
goto _145
|
|
case uint32(130):
|
|
goto _146
|
|
case uint32(132):
|
|
goto _147
|
|
case uint32(133):
|
|
goto _148
|
|
case uint32(145):
|
|
goto _149
|
|
case uint32(135):
|
|
goto _150
|
|
case uint32(136):
|
|
goto _151
|
|
case uint32(137):
|
|
goto _152
|
|
case uint32(138):
|
|
goto _153
|
|
case uint32(139):
|
|
goto _154
|
|
case uint32(143):
|
|
goto _155
|
|
case uint32(140):
|
|
goto _156
|
|
case uint32(141):
|
|
goto _157
|
|
case uint32(142):
|
|
goto _158
|
|
case uint32(148):
|
|
goto _159
|
|
case uint32(146):
|
|
goto _160
|
|
case uint32(153):
|
|
goto _161
|
|
case uint32(155):
|
|
goto _162
|
|
case uint32(232):
|
|
goto _163
|
|
case uint32(233):
|
|
goto _164
|
|
case uint32(252):
|
|
goto _165
|
|
case uint32(154):
|
|
goto _166
|
|
case uint32(147):
|
|
goto _167
|
|
case uint32(156):
|
|
goto _168
|
|
case uint32(231):
|
|
goto _169
|
|
case uint32(251):
|
|
goto _170
|
|
case uint32(149):
|
|
goto _171
|
|
case uint32(150):
|
|
goto _172
|
|
case uint32(151):
|
|
goto _173
|
|
case uint32(152):
|
|
goto _174
|
|
case uint32(157):
|
|
goto _175
|
|
case uint32(158):
|
|
goto _176
|
|
case uint32(159):
|
|
goto _177
|
|
case uint32(160):
|
|
goto _178
|
|
case uint32(161):
|
|
goto _179
|
|
case uint32(162):
|
|
goto _180
|
|
case uint32(163):
|
|
goto _181
|
|
case uint32(164):
|
|
goto _182
|
|
case uint32(165):
|
|
goto _183
|
|
case uint32(166):
|
|
goto _184
|
|
case uint32(167):
|
|
goto _185
|
|
case uint32(168):
|
|
goto _186
|
|
case uint32(169):
|
|
goto _187
|
|
case uint32(170):
|
|
goto _188
|
|
case uint32(171):
|
|
goto _189
|
|
case uint32(172):
|
|
goto _190
|
|
case uint32(175):
|
|
goto _191
|
|
case uint32(176):
|
|
goto _192
|
|
case uint32(177):
|
|
goto _193
|
|
case uint32(178):
|
|
goto _194
|
|
case uint32(179):
|
|
goto _195
|
|
case uint32(180):
|
|
goto _196
|
|
case uint32(181):
|
|
goto _197
|
|
case uint32(182):
|
|
goto _198
|
|
case uint32(184):
|
|
goto _199
|
|
case uint32(183):
|
|
goto _200
|
|
case uint32(185):
|
|
goto _201
|
|
case uint32(186):
|
|
goto _202
|
|
case uint32(187):
|
|
goto _203
|
|
case uint32(188):
|
|
goto _204
|
|
case uint32(189):
|
|
goto _205
|
|
case uint32(190):
|
|
goto _206
|
|
case uint32(191):
|
|
goto _207
|
|
case uint32(192):
|
|
goto _208
|
|
case uint32(193):
|
|
goto _209
|
|
case uint32(194):
|
|
goto _210
|
|
case uint32(195):
|
|
goto _211
|
|
case uint32(196):
|
|
goto _212
|
|
case uint32(197):
|
|
goto _213
|
|
case uint32(199):
|
|
goto _214
|
|
case uint32(198):
|
|
goto _215
|
|
case uint32(200):
|
|
goto _216
|
|
case uint32(201):
|
|
goto _217
|
|
case uint32(202):
|
|
goto _218
|
|
case uint32(203):
|
|
goto _219
|
|
case uint32(204):
|
|
goto _220
|
|
case uint32(205):
|
|
goto _221
|
|
case uint32(206):
|
|
goto _222
|
|
case uint32(207):
|
|
goto _223
|
|
case uint32(208):
|
|
goto _224
|
|
case uint32(209):
|
|
goto _225
|
|
case uint32(210):
|
|
goto _226
|
|
case uint32(211):
|
|
goto _227
|
|
case uint32(212):
|
|
goto _228
|
|
case uint32(213):
|
|
goto _229
|
|
case uint32(215):
|
|
goto _230
|
|
case uint32(214):
|
|
goto _231
|
|
case uint32(216):
|
|
goto _232
|
|
case uint32(217):
|
|
goto _233
|
|
case uint32(221):
|
|
goto _234
|
|
case uint32(218):
|
|
goto _235
|
|
case uint32(220):
|
|
goto _236
|
|
case uint32(223):
|
|
goto _237
|
|
case uint32(224):
|
|
goto _238
|
|
case uint32(225):
|
|
goto _239
|
|
case uint32(226):
|
|
goto _240
|
|
case uint32(227):
|
|
goto _241
|
|
case uint32(228):
|
|
goto _242
|
|
case uint32(229):
|
|
goto _243
|
|
case uint32(230):
|
|
goto _244
|
|
case uint32(235):
|
|
goto _245
|
|
case uint32(236):
|
|
goto _246
|
|
case uint32(243):
|
|
goto _247
|
|
case uint32(238):
|
|
goto _248
|
|
case uint32(239):
|
|
goto _249
|
|
case uint32(281):
|
|
goto _250
|
|
case uint32(240):
|
|
goto _251
|
|
case uint32(241):
|
|
goto _252
|
|
case uint32(244):
|
|
goto _253
|
|
case uint32(245):
|
|
goto _254
|
|
case uint32(248):
|
|
goto _255
|
|
case uint32(249):
|
|
goto _256
|
|
case uint32(250):
|
|
goto _257
|
|
case uint32(253):
|
|
goto _258
|
|
case uint32(254):
|
|
goto _259
|
|
case uint32(255):
|
|
goto _260
|
|
case uint32(256):
|
|
goto _261
|
|
case uint32(257):
|
|
goto _262
|
|
case uint32(260):
|
|
goto _263
|
|
case uint32(261):
|
|
goto _264
|
|
case uint32(262):
|
|
goto _265
|
|
case uint32(263):
|
|
goto _266
|
|
case uint32(264):
|
|
goto _267
|
|
case uint32(266):
|
|
goto _268
|
|
case uint32(265):
|
|
goto _269
|
|
case uint32(267):
|
|
goto _270
|
|
case uint32(286):
|
|
goto _271
|
|
case uint32(268):
|
|
goto _272
|
|
case uint32(287):
|
|
goto _273
|
|
case uint32(269):
|
|
goto _274
|
|
case uint32(270):
|
|
goto _275
|
|
case uint32(271):
|
|
goto _276
|
|
case uint32(272):
|
|
goto _277
|
|
case uint32(273):
|
|
goto _278
|
|
case uint32(274):
|
|
goto _279
|
|
case uint32(275):
|
|
goto _280
|
|
case uint32(276):
|
|
goto _281
|
|
case uint32(277):
|
|
goto _282
|
|
case uint32(278):
|
|
goto _283
|
|
case uint32(279):
|
|
goto _284
|
|
case uint32(280):
|
|
goto _285
|
|
case uint32(282):
|
|
goto _286
|
|
case uint32(283):
|
|
goto _287
|
|
case uint32(284):
|
|
goto _288
|
|
case uint32(285):
|
|
goto _289
|
|
case uint32(288):
|
|
goto _290
|
|
case uint32(289):
|
|
goto _291
|
|
case uint32(290):
|
|
goto _292
|
|
case uint32(291):
|
|
goto _293
|
|
case uint32(292):
|
|
goto _294
|
|
case uint32(293):
|
|
goto _295
|
|
case uint32(294):
|
|
goto _296
|
|
case uint32(295):
|
|
goto _297
|
|
case uint32(296):
|
|
goto _298
|
|
case uint32(297):
|
|
goto _299
|
|
case uint32(298):
|
|
goto _300
|
|
case uint32(299):
|
|
goto _301
|
|
case uint32(300):
|
|
goto _302
|
|
case uint32(301):
|
|
goto _303
|
|
case uint32(302):
|
|
goto _304
|
|
case uint32(303):
|
|
goto _305
|
|
case uint32(304):
|
|
goto _306
|
|
case uint32(305):
|
|
goto _307
|
|
case uint32(307):
|
|
goto _308
|
|
case uint32(306):
|
|
goto _309
|
|
case uint32(308):
|
|
goto _310
|
|
case uint32(310):
|
|
goto _311
|
|
case uint32(309):
|
|
goto _312
|
|
case uint32(311):
|
|
goto _313
|
|
case uint32(312):
|
|
goto _314
|
|
case uint32(313):
|
|
goto _315
|
|
case uint32(314):
|
|
goto _316
|
|
case uint32(315):
|
|
goto _317
|
|
case uint32(316):
|
|
goto _318
|
|
case uint32(317):
|
|
goto _319
|
|
case uint32(318):
|
|
goto _320
|
|
case uint32(319):
|
|
goto _321
|
|
case uint32(320):
|
|
goto _322
|
|
case uint32(321):
|
|
goto _323
|
|
case uint32(322):
|
|
goto _324
|
|
case uint32(323):
|
|
goto _325
|
|
case uint32(324):
|
|
goto _326
|
|
case uint32(325):
|
|
goto _327
|
|
case uint32(326):
|
|
goto _328
|
|
case uint32(327):
|
|
goto _329
|
|
case uint32(331):
|
|
goto _330
|
|
case uint32(329):
|
|
goto _331
|
|
case uint32(332):
|
|
goto _332
|
|
case uint32(330):
|
|
goto _333
|
|
case uint32(334):
|
|
goto _334
|
|
case uint32(333):
|
|
goto _335
|
|
case uint32(335):
|
|
goto _336
|
|
case uint32(336):
|
|
goto _337
|
|
case uint32(338):
|
|
goto _338
|
|
case uint32(337):
|
|
goto _339
|
|
case uint32(339):
|
|
goto _340
|
|
case uint32(340):
|
|
goto _341
|
|
case uint32(341):
|
|
goto _342
|
|
case uint32(342):
|
|
goto _343
|
|
case uint32(343):
|
|
goto _344
|
|
case uint32(344):
|
|
goto _345
|
|
case uint32(345):
|
|
goto _346
|
|
case uint32(346):
|
|
goto _347
|
|
case uint32(347):
|
|
goto _348
|
|
default:
|
|
goto _349
|
|
}
|
|
goto _350
|
|
_1:
|
|
; /* explain ::= EXPLAIN */
|
|
if (*TParse)(unsafe.Pointer(pParse)).FpReprepare == uintptr(0) {
|
|
(*TParse)(unsafe.Pointer(pParse)).Fexplain = uint8(1)
|
|
}
|
|
goto _350
|
|
_2:
|
|
; /* explain ::= EXPLAIN QUERY PLAN */
|
|
if (*TParse)(unsafe.Pointer(pParse)).FpReprepare == uintptr(0) {
|
|
(*TParse)(unsafe.Pointer(pParse)).Fexplain = uint8(2)
|
|
}
|
|
goto _350
|
|
_3:
|
|
; /* cmdx ::= cmd */
|
|
_sqlite3FinishCoding(tls, pParse)
|
|
goto _350
|
|
_4:
|
|
; /* cmd ::= BEGIN transtype trans_opt */
|
|
_sqlite3BeginTransaction(tls, pParse, *(*int32)(unsafe.Pointer(yymsp + uintptr(-libc.Int32FromInt32(1))*12 + 4)))
|
|
goto _350
|
|
_5:
|
|
; /* transtype ::= */
|
|
*(*int32)(unsafe.Pointer(yymsp + 1*12 + 4)) = int32(TK_DEFERRED)
|
|
goto _350
|
|
_7:
|
|
; /* transtype ::= DEFERRED */
|
|
_6:
|
|
;
|
|
_8:
|
|
;
|
|
_9:
|
|
;
|
|
*(*int32)(unsafe.Pointer(yymsp + 4)) = libc.Int32FromUint16((**(**TyyStackEntry)(__ccgo_up(yymsp))).Fmajor) /*A-overwrites-X*/
|
|
goto _350
|
|
_11:
|
|
; /* cmd ::= COMMIT|END trans_opt */
|
|
_10:
|
|
;
|
|
_sqlite3EndTransaction(tls, pParse, libc.Int32FromUint16((**(**TyyStackEntry)(__ccgo_up(yymsp + uintptr(-libc.Int32FromInt32(1))*12))).Fmajor))
|
|
goto _350
|
|
_12:
|
|
; /* cmd ::= SAVEPOINT nm */
|
|
_sqlite3Savepoint(tls, pParse, SAVEPOINT_BEGIN, yymsp+4)
|
|
goto _350
|
|
_13:
|
|
; /* cmd ::= RELEASE savepoint_opt nm */
|
|
_sqlite3Savepoint(tls, pParse, int32(SAVEPOINT_RELEASE), yymsp+4)
|
|
goto _350
|
|
_14:
|
|
; /* cmd ::= ROLLBACK trans_opt TO savepoint_opt nm */
|
|
_sqlite3Savepoint(tls, pParse, int32(SAVEPOINT_ROLLBACK), yymsp+4)
|
|
goto _350
|
|
_15:
|
|
; /* create_table ::= createkw temp TABLE ifnotexists nm dbnm */
|
|
_sqlite3StartTable(tls, pParse, yymsp+uintptr(-libc.Int32FromInt32(1))*12+4, yymsp+4, *(*int32)(unsafe.Pointer(yymsp + uintptr(-libc.Int32FromInt32(4))*12 + 4)), 0, 0, *(*int32)(unsafe.Pointer(yymsp + uintptr(-libc.Int32FromInt32(2))*12 + 4)))
|
|
goto _350
|
|
_16:
|
|
; /* createkw ::= CREATE */
|
|
_disableLookaside(tls, pParse)
|
|
goto _350
|
|
_18:
|
|
; /* ifnotexists ::= */
|
|
_17:
|
|
;
|
|
_19:
|
|
;
|
|
_20:
|
|
;
|
|
_21:
|
|
;
|
|
_22:
|
|
;
|
|
_23:
|
|
;
|
|
_24:
|
|
;
|
|
*(*int32)(unsafe.Pointer(yymsp + 1*12 + 4)) = 0
|
|
goto _350
|
|
_25:
|
|
; /* ifnotexists ::= IF NOT EXISTS */
|
|
*(*int32)(unsafe.Pointer(yymsp + uintptr(-libc.Int32FromInt32(2))*12 + 4)) = int32(1)
|
|
goto _350
|
|
_26:
|
|
; /* temp ::= TEMP */
|
|
*(*int32)(unsafe.Pointer(yymsp + 4)) = libc.BoolInt32(libc.Int32FromUint8((*Tsqlite3)(unsafe.Pointer((*TParse)(unsafe.Pointer(pParse)).Fdb)).Finit1.Fbusy) == 0)
|
|
goto _350
|
|
_27:
|
|
; /* create_table_args ::= LP columnlist conslist_opt RP table_option_set */
|
|
_sqlite3EndTable(tls, pParse, yymsp+uintptr(-libc.Int32FromInt32(2))*12+4, yymsp+uintptr(-libc.Int32FromInt32(1))*12+4, *(*Tu32)(unsafe.Pointer(yymsp + 4)), uintptr(0))
|
|
goto _350
|
|
_28:
|
|
; /* create_table_args ::= AS select */
|
|
_sqlite3EndTable(tls, pParse, uintptr(0), uintptr(0), uint32(0), *(*uintptr)(unsafe.Pointer(yymsp + 4)))
|
|
_sqlite3SelectDelete(tls, (*TParse)(unsafe.Pointer(pParse)).Fdb, *(*uintptr)(unsafe.Pointer(yymsp + 4)))
|
|
goto _350
|
|
_29:
|
|
; /* table_option_set ::= */
|
|
*(*Tu32)(unsafe.Pointer(yymsp + 1*12 + 4)) = uint32(0)
|
|
goto _350
|
|
_30:
|
|
; /* table_option_set ::= table_option_set COMMA table_option */
|
|
*(*Tu32)(unsafe.Pointer(&**(**TYYMINORTYPE)(__ccgo_up(bp)))) = *(*Tu32)(unsafe.Pointer(yymsp + uintptr(-libc.Int32FromInt32(2))*12 + 4)) | *(*Tu32)(unsafe.Pointer(yymsp + 4))
|
|
*(*Tu32)(unsafe.Pointer(yymsp + uintptr(-libc.Int32FromInt32(2))*12 + 4)) = *(*Tu32)(unsafe.Pointer(&**(**TYYMINORTYPE)(__ccgo_up(bp))))
|
|
goto _350
|
|
_31:
|
|
; /* table_option ::= WITHOUT nm */
|
|
if *(*uint32)(unsafe.Pointer(yymsp + 4 + 4)) == uint32(5) && Xsqlite3_strnicmp(tls, *(*uintptr)(unsafe.Pointer(yymsp + 4)), __ccgo_ts+17965, int32(5)) == 0 {
|
|
*(*Tu32)(unsafe.Pointer(yymsp + uintptr(-libc.Int32FromInt32(1))*12 + 4)) = libc.Uint32FromInt32(libc.Int32FromInt32(TF_WithoutRowid) | libc.Int32FromInt32(TF_NoVisibleRowid))
|
|
} else {
|
|
*(*Tu32)(unsafe.Pointer(yymsp + uintptr(-libc.Int32FromInt32(1))*12 + 4)) = uint32(0)
|
|
_sqlite3ErrorMsg(tls, pParse, __ccgo_ts+24997, libc.VaList(bp+88, *(*uint32)(unsafe.Pointer(yymsp + 4 + 4)), *(*uintptr)(unsafe.Pointer(yymsp + 4))))
|
|
}
|
|
goto _350
|
|
_32:
|
|
; /* table_option ::= nm */
|
|
if *(*uint32)(unsafe.Pointer(yymsp + 4 + 4)) == uint32(6) && Xsqlite3_strnicmp(tls, *(*uintptr)(unsafe.Pointer(yymsp + 4)), __ccgo_ts+17901, int32(6)) == 0 {
|
|
*(*Tu32)(unsafe.Pointer(&**(**TYYMINORTYPE)(__ccgo_up(bp)))) = uint32(TF_Strict)
|
|
} else {
|
|
*(*Tu32)(unsafe.Pointer(&**(**TYYMINORTYPE)(__ccgo_up(bp)))) = uint32(0)
|
|
_sqlite3ErrorMsg(tls, pParse, __ccgo_ts+24997, libc.VaList(bp+88, *(*uint32)(unsafe.Pointer(yymsp + 4 + 4)), *(*uintptr)(unsafe.Pointer(yymsp + 4))))
|
|
}
|
|
*(*Tu32)(unsafe.Pointer(yymsp + 4)) = *(*Tu32)(unsafe.Pointer(&**(**TYYMINORTYPE)(__ccgo_up(bp))))
|
|
goto _350
|
|
_33:
|
|
; /* columnname ::= nm typetoken */
|
|
_sqlite3AddColumn(tls, pParse, *(*TToken)(unsafe.Pointer(yymsp + uintptr(-libc.Int32FromInt32(1))*12 + 4)), *(*TToken)(unsafe.Pointer(yymsp + 4)))
|
|
goto _350
|
|
_35:
|
|
; /* typetoken ::= */
|
|
_34:
|
|
;
|
|
_36:
|
|
;
|
|
*(*uint32)(unsafe.Pointer(yymsp + 1*12 + 4 + 4)) = uint32(0)
|
|
*(*uintptr)(unsafe.Pointer(yymsp + 1*12 + 4)) = uintptr(0)
|
|
goto _350
|
|
_37:
|
|
; /* typetoken ::= typename LP signed RP */
|
|
*(*uint32)(unsafe.Pointer(yymsp + uintptr(-libc.Int32FromInt32(3))*12 + 4 + 4)) = libc.Uint32FromInt32(t__predefined_ptrdiff_t(*(*uintptr)(unsafe.Pointer(yymsp + 4))+uintptr(*(*uint32)(unsafe.Pointer(yymsp + 4 + 4)))) - int32(*(*uintptr)(unsafe.Pointer(yymsp + uintptr(-libc.Int32FromInt32(3))*12 + 4))))
|
|
goto _350
|
|
_38:
|
|
; /* typetoken ::= typename LP signed COMMA signed RP */
|
|
*(*uint32)(unsafe.Pointer(yymsp + uintptr(-libc.Int32FromInt32(5))*12 + 4 + 4)) = libc.Uint32FromInt32(t__predefined_ptrdiff_t(*(*uintptr)(unsafe.Pointer(yymsp + 4))+uintptr(*(*uint32)(unsafe.Pointer(yymsp + 4 + 4)))) - int32(*(*uintptr)(unsafe.Pointer(yymsp + uintptr(-libc.Int32FromInt32(5))*12 + 4))))
|
|
goto _350
|
|
_39:
|
|
; /* typename ::= typename ID|STRING */
|
|
*(*uint32)(unsafe.Pointer(yymsp + uintptr(-libc.Int32FromInt32(1))*12 + 4 + 4)) = *(*uint32)(unsafe.Pointer(yymsp + 4 + 4)) + libc.Uint32FromInt32(int32(*(*uintptr)(unsafe.Pointer(yymsp + 4)))-int32(*(*uintptr)(unsafe.Pointer(yymsp + uintptr(-libc.Int32FromInt32(1))*12 + 4))))
|
|
goto _350
|
|
_40:
|
|
; /* scanpt ::= */
|
|
*(*uintptr)(unsafe.Pointer(yymsp + 1*12 + 4)) = yyLookaheadToken.Fz
|
|
goto _350
|
|
_41:
|
|
; /* scantok ::= */
|
|
*(*TToken)(unsafe.Pointer(yymsp + 1*12 + 4)) = yyLookaheadToken
|
|
goto _350
|
|
_43:
|
|
; /* ccons ::= CONSTRAINT nm */
|
|
_42:
|
|
;
|
|
(*(*struct {
|
|
FaddrCrTab int32
|
|
FregRowid int32
|
|
FregRoot int32
|
|
FconstraintName TToken
|
|
})(unsafe.Pointer(pParse + 188))).FconstraintName = *(*TToken)(unsafe.Pointer(yymsp + 4))
|
|
goto _350
|
|
_44:
|
|
; /* ccons ::= DEFAULT scantok term */
|
|
_sqlite3AddDefaultValue(tls, pParse, *(*uintptr)(unsafe.Pointer(yymsp + 4)), *(*uintptr)(unsafe.Pointer(yymsp + uintptr(-libc.Int32FromInt32(1))*12 + 4)), *(*uintptr)(unsafe.Pointer(yymsp + uintptr(-libc.Int32FromInt32(1))*12 + 4))+uintptr(*(*uint32)(unsafe.Pointer(yymsp + uintptr(-libc.Int32FromInt32(1))*12 + 4 + 4))))
|
|
goto _350
|
|
_45:
|
|
; /* ccons ::= DEFAULT LP expr RP */
|
|
_sqlite3AddDefaultValue(tls, pParse, *(*uintptr)(unsafe.Pointer(yymsp + uintptr(-libc.Int32FromInt32(1))*12 + 4)), *(*uintptr)(unsafe.Pointer(yymsp + uintptr(-libc.Int32FromInt32(2))*12 + 4))+uintptr(1), *(*uintptr)(unsafe.Pointer(yymsp + 4)))
|
|
goto _350
|
|
_46:
|
|
; /* ccons ::= DEFAULT PLUS scantok term */
|
|
_sqlite3AddDefaultValue(tls, pParse, *(*uintptr)(unsafe.Pointer(yymsp + 4)), *(*uintptr)(unsafe.Pointer(yymsp + uintptr(-libc.Int32FromInt32(2))*12 + 4)), *(*uintptr)(unsafe.Pointer(yymsp + uintptr(-libc.Int32FromInt32(1))*12 + 4))+uintptr(*(*uint32)(unsafe.Pointer(yymsp + uintptr(-libc.Int32FromInt32(1))*12 + 4 + 4))))
|
|
goto _350
|
|
_47:
|
|
; /* ccons ::= DEFAULT MINUS scantok term */
|
|
p = _sqlite3PExpr(tls, pParse, int32(TK_UMINUS), *(*uintptr)(unsafe.Pointer(yymsp + 4)), uintptr(0))
|
|
_sqlite3AddDefaultValue(tls, pParse, p, *(*uintptr)(unsafe.Pointer(yymsp + uintptr(-libc.Int32FromInt32(2))*12 + 4)), *(*uintptr)(unsafe.Pointer(yymsp + uintptr(-libc.Int32FromInt32(1))*12 + 4))+uintptr(*(*uint32)(unsafe.Pointer(yymsp + uintptr(-libc.Int32FromInt32(1))*12 + 4 + 4))))
|
|
goto _350
|
|
_48:
|
|
; /* ccons ::= DEFAULT scantok ID|INDEXED */
|
|
p1 = _tokenExpr(tls, pParse, int32(TK_STRING), *(*TToken)(unsafe.Pointer(yymsp + 4)))
|
|
if p1 != 0 {
|
|
_sqlite3ExprIdToTrueFalse(tls, p1)
|
|
}
|
|
_sqlite3AddDefaultValue(tls, pParse, p1, *(*uintptr)(unsafe.Pointer(yymsp + 4)), *(*uintptr)(unsafe.Pointer(yymsp + 4))+uintptr(*(*uint32)(unsafe.Pointer(yymsp + 4 + 4))))
|
|
goto _350
|
|
_49:
|
|
; /* ccons ::= NOT NULL onconf */
|
|
_sqlite3AddNotNull(tls, pParse, *(*int32)(unsafe.Pointer(yymsp + 4)))
|
|
goto _350
|
|
_50:
|
|
; /* ccons ::= PRIMARY KEY sortorder onconf autoinc */
|
|
_sqlite3AddPrimaryKey(tls, pParse, uintptr(0), *(*int32)(unsafe.Pointer(yymsp + uintptr(-libc.Int32FromInt32(1))*12 + 4)), *(*int32)(unsafe.Pointer(yymsp + 4)), *(*int32)(unsafe.Pointer(yymsp + uintptr(-libc.Int32FromInt32(2))*12 + 4)))
|
|
goto _350
|
|
_51:
|
|
; /* ccons ::= UNIQUE onconf */
|
|
_sqlite3CreateIndex(tls, pParse, uintptr(0), uintptr(0), uintptr(0), uintptr(0), *(*int32)(unsafe.Pointer(yymsp + 4)), uintptr(0), uintptr(0), 0, 0, uint8(SQLITE_IDXTYPE_UNIQUE))
|
|
goto _350
|
|
_52:
|
|
; /* ccons ::= CHECK LP expr RP */
|
|
_sqlite3AddCheckConstraint(tls, pParse, *(*uintptr)(unsafe.Pointer(yymsp + uintptr(-libc.Int32FromInt32(1))*12 + 4)), *(*uintptr)(unsafe.Pointer(yymsp + uintptr(-libc.Int32FromInt32(2))*12 + 4)), *(*uintptr)(unsafe.Pointer(yymsp + 4)))
|
|
goto _350
|
|
_53:
|
|
; /* ccons ::= REFERENCES nm eidlist_opt refargs */
|
|
_sqlite3CreateForeignKey(tls, pParse, uintptr(0), yymsp+uintptr(-libc.Int32FromInt32(2))*12+4, *(*uintptr)(unsafe.Pointer(yymsp + uintptr(-libc.Int32FromInt32(1))*12 + 4)), *(*int32)(unsafe.Pointer(yymsp + 4)))
|
|
goto _350
|
|
_54:
|
|
; /* ccons ::= defer_subclause */
|
|
_sqlite3DeferForeignKey(tls, pParse, *(*int32)(unsafe.Pointer(yymsp + 4)))
|
|
goto _350
|
|
_55:
|
|
; /* ccons ::= COLLATE ID|STRING */
|
|
_sqlite3AddCollateType(tls, pParse, yymsp+4)
|
|
goto _350
|
|
_56:
|
|
; /* generated ::= LP expr RP */
|
|
_sqlite3AddGenerated(tls, pParse, *(*uintptr)(unsafe.Pointer(yymsp + uintptr(-libc.Int32FromInt32(1))*12 + 4)), uintptr(0))
|
|
goto _350
|
|
_57:
|
|
; /* generated ::= LP expr RP ID */
|
|
_sqlite3AddGenerated(tls, pParse, *(*uintptr)(unsafe.Pointer(yymsp + uintptr(-libc.Int32FromInt32(2))*12 + 4)), yymsp+4)
|
|
goto _350
|
|
_58:
|
|
; /* autoinc ::= AUTOINCR */
|
|
*(*int32)(unsafe.Pointer(yymsp + 4)) = int32(1)
|
|
goto _350
|
|
_59:
|
|
; /* refargs ::= */
|
|
*(*int32)(unsafe.Pointer(yymsp + 1*12 + 4)) = libc.Int32FromInt32(OE_None) * libc.Int32FromInt32(0x0101) /* EV: R-19803-45884 */
|
|
goto _350
|
|
_60:
|
|
; /* refargs ::= refargs refarg */
|
|
*(*int32)(unsafe.Pointer(yymsp + uintptr(-libc.Int32FromInt32(1))*12 + 4)) = *(*int32)(unsafe.Pointer(yymsp + uintptr(-libc.Int32FromInt32(1))*12 + 4)) & ^*(*int32)(unsafe.Pointer(yymsp + 4 + 4)) | *(*int32)(unsafe.Pointer(yymsp + 4))
|
|
goto _350
|
|
_61:
|
|
; /* refarg ::= MATCH nm */
|
|
*(*int32)(unsafe.Pointer(yymsp + uintptr(-libc.Int32FromInt32(1))*12 + 4)) = 0
|
|
*(*int32)(unsafe.Pointer(yymsp + uintptr(-libc.Int32FromInt32(1))*12 + 4 + 4)) = 0x000000
|
|
goto _350
|
|
_62:
|
|
; /* refarg ::= ON INSERT refact */
|
|
*(*int32)(unsafe.Pointer(yymsp + uintptr(-libc.Int32FromInt32(2))*12 + 4)) = 0
|
|
*(*int32)(unsafe.Pointer(yymsp + uintptr(-libc.Int32FromInt32(2))*12 + 4 + 4)) = 0x000000
|
|
goto _350
|
|
_63:
|
|
; /* refarg ::= ON DELETE refact */
|
|
*(*int32)(unsafe.Pointer(yymsp + uintptr(-libc.Int32FromInt32(2))*12 + 4)) = *(*int32)(unsafe.Pointer(yymsp + 4))
|
|
*(*int32)(unsafe.Pointer(yymsp + uintptr(-libc.Int32FromInt32(2))*12 + 4 + 4)) = int32(0x0000ff)
|
|
goto _350
|
|
_64:
|
|
; /* refarg ::= ON UPDATE refact */
|
|
*(*int32)(unsafe.Pointer(yymsp + uintptr(-libc.Int32FromInt32(2))*12 + 4)) = *(*int32)(unsafe.Pointer(yymsp + 4)) << int32(8)
|
|
*(*int32)(unsafe.Pointer(yymsp + uintptr(-libc.Int32FromInt32(2))*12 + 4 + 4)) = int32(0x00ff00)
|
|
goto _350
|
|
_65:
|
|
; /* refact ::= SET NULL */
|
|
*(*int32)(unsafe.Pointer(yymsp + uintptr(-libc.Int32FromInt32(1))*12 + 4)) = int32(OE_SetNull) /* EV: R-33326-45252 */
|
|
goto _350
|
|
_66:
|
|
; /* refact ::= SET DEFAULT */
|
|
*(*int32)(unsafe.Pointer(yymsp + uintptr(-libc.Int32FromInt32(1))*12 + 4)) = int32(OE_SetDflt) /* EV: R-33326-45252 */
|
|
goto _350
|
|
_67:
|
|
; /* refact ::= CASCADE */
|
|
*(*int32)(unsafe.Pointer(yymsp + 4)) = int32(OE_Cascade) /* EV: R-33326-45252 */
|
|
goto _350
|
|
_68:
|
|
; /* refact ::= RESTRICT */
|
|
*(*int32)(unsafe.Pointer(yymsp + 4)) = int32(OE_Restrict) /* EV: R-33326-45252 */
|
|
goto _350
|
|
_69:
|
|
; /* refact ::= NO ACTION */
|
|
*(*int32)(unsafe.Pointer(yymsp + uintptr(-libc.Int32FromInt32(1))*12 + 4)) = OE_None /* EV: R-33326-45252 */
|
|
goto _350
|
|
_70:
|
|
; /* defer_subclause ::= NOT DEFERRABLE init_deferred_pred_opt */
|
|
*(*int32)(unsafe.Pointer(yymsp + uintptr(-libc.Int32FromInt32(2))*12 + 4)) = 0
|
|
goto _350
|
|
_72:
|
|
; /* defer_subclause ::= DEFERRABLE init_deferred_pred_opt */
|
|
_71:
|
|
;
|
|
_73:
|
|
;
|
|
*(*int32)(unsafe.Pointer(yymsp + uintptr(-libc.Int32FromInt32(1))*12 + 4)) = *(*int32)(unsafe.Pointer(yymsp + 4))
|
|
goto _350
|
|
_75:
|
|
; /* init_deferred_pred_opt ::= INITIALLY DEFERRED */
|
|
_74:
|
|
;
|
|
_76:
|
|
;
|
|
_77:
|
|
;
|
|
_78:
|
|
;
|
|
*(*int32)(unsafe.Pointer(yymsp + uintptr(-libc.Int32FromInt32(1))*12 + 4)) = int32(1)
|
|
goto _350
|
|
_79:
|
|
; /* init_deferred_pred_opt ::= INITIALLY IMMEDIATE */
|
|
*(*int32)(unsafe.Pointer(yymsp + uintptr(-libc.Int32FromInt32(1))*12 + 4)) = 0
|
|
goto _350
|
|
_80:
|
|
; /* tconscomma ::= COMMA */
|
|
(*(*struct {
|
|
FaddrCrTab int32
|
|
FregRowid int32
|
|
FregRoot int32
|
|
FconstraintName TToken
|
|
})(unsafe.Pointer(pParse + 188))).FconstraintName.Fn = uint32(0)
|
|
goto _350
|
|
_81:
|
|
; /* tcons ::= PRIMARY KEY LP sortlist autoinc RP onconf */
|
|
_sqlite3AddPrimaryKey(tls, pParse, *(*uintptr)(unsafe.Pointer(yymsp + uintptr(-libc.Int32FromInt32(3))*12 + 4)), *(*int32)(unsafe.Pointer(yymsp + 4)), *(*int32)(unsafe.Pointer(yymsp + uintptr(-libc.Int32FromInt32(2))*12 + 4)), 0)
|
|
goto _350
|
|
_82:
|
|
; /* tcons ::= UNIQUE LP sortlist RP onconf */
|
|
_sqlite3CreateIndex(tls, pParse, uintptr(0), uintptr(0), uintptr(0), *(*uintptr)(unsafe.Pointer(yymsp + uintptr(-libc.Int32FromInt32(2))*12 + 4)), *(*int32)(unsafe.Pointer(yymsp + 4)), uintptr(0), uintptr(0), 0, 0, uint8(SQLITE_IDXTYPE_UNIQUE))
|
|
goto _350
|
|
_83:
|
|
; /* tcons ::= CHECK LP expr RP onconf */
|
|
_sqlite3AddCheckConstraint(tls, pParse, *(*uintptr)(unsafe.Pointer(yymsp + uintptr(-libc.Int32FromInt32(2))*12 + 4)), *(*uintptr)(unsafe.Pointer(yymsp + uintptr(-libc.Int32FromInt32(3))*12 + 4)), *(*uintptr)(unsafe.Pointer(yymsp + uintptr(-libc.Int32FromInt32(1))*12 + 4)))
|
|
goto _350
|
|
_84:
|
|
; /* tcons ::= FOREIGN KEY LP eidlist RP REFERENCES nm eidlist_opt refargs defer_subclause_opt */
|
|
_sqlite3CreateForeignKey(tls, pParse, *(*uintptr)(unsafe.Pointer(yymsp + uintptr(-libc.Int32FromInt32(6))*12 + 4)), yymsp+uintptr(-libc.Int32FromInt32(3))*12+4, *(*uintptr)(unsafe.Pointer(yymsp + uintptr(-libc.Int32FromInt32(2))*12 + 4)), *(*int32)(unsafe.Pointer(yymsp + uintptr(-libc.Int32FromInt32(1))*12 + 4)))
|
|
_sqlite3DeferForeignKey(tls, pParse, *(*int32)(unsafe.Pointer(yymsp + 4)))
|
|
goto _350
|
|
_86:
|
|
; /* onconf ::= */
|
|
_85:
|
|
;
|
|
*(*int32)(unsafe.Pointer(yymsp + 1*12 + 4)) = int32(OE_Default)
|
|
goto _350
|
|
_87:
|
|
; /* onconf ::= ON CONFLICT resolvetype */
|
|
*(*int32)(unsafe.Pointer(yymsp + uintptr(-libc.Int32FromInt32(2))*12 + 4)) = *(*int32)(unsafe.Pointer(yymsp + 4))
|
|
goto _350
|
|
_88:
|
|
; /* resolvetype ::= IGNORE */
|
|
*(*int32)(unsafe.Pointer(yymsp + 4)) = int32(OE_Ignore)
|
|
goto _350
|
|
_90:
|
|
; /* resolvetype ::= REPLACE */
|
|
_89:
|
|
;
|
|
*(*int32)(unsafe.Pointer(yymsp + 4)) = int32(OE_Replace)
|
|
goto _350
|
|
_91:
|
|
; /* cmd ::= DROP TABLE ifexists fullname */
|
|
_sqlite3DropTable(tls, pParse, *(*uintptr)(unsafe.Pointer(yymsp + 4)), 0, *(*int32)(unsafe.Pointer(yymsp + uintptr(-libc.Int32FromInt32(1))*12 + 4)))
|
|
goto _350
|
|
_92:
|
|
; /* cmd ::= createkw temp VIEW ifnotexists nm dbnm eidlist_opt AS select */
|
|
_sqlite3CreateView(tls, pParse, yymsp+uintptr(-libc.Int32FromInt32(8))*12+4, yymsp+uintptr(-libc.Int32FromInt32(4))*12+4, yymsp+uintptr(-libc.Int32FromInt32(3))*12+4, *(*uintptr)(unsafe.Pointer(yymsp + uintptr(-libc.Int32FromInt32(2))*12 + 4)), *(*uintptr)(unsafe.Pointer(yymsp + 4)), *(*int32)(unsafe.Pointer(yymsp + uintptr(-libc.Int32FromInt32(7))*12 + 4)), *(*int32)(unsafe.Pointer(yymsp + uintptr(-libc.Int32FromInt32(5))*12 + 4)))
|
|
goto _350
|
|
_93:
|
|
; /* cmd ::= DROP VIEW ifexists fullname */
|
|
_sqlite3DropTable(tls, pParse, *(*uintptr)(unsafe.Pointer(yymsp + 4)), int32(1), *(*int32)(unsafe.Pointer(yymsp + uintptr(-libc.Int32FromInt32(1))*12 + 4)))
|
|
goto _350
|
|
_94:
|
|
; /* cmd ::= select */
|
|
**(**TSelectDest)(__ccgo_up(bp + 8)) = TSelectDest{
|
|
FeDest: uint8(SRT_Output),
|
|
}
|
|
if (*Tsqlite3)(unsafe.Pointer((*TParse)(unsafe.Pointer(pParse)).Fdb)).FmDbFlags&uint32(DBFLAG_EncodingFixed) != uint32(0) || _sqlite3ReadSchema(tls, pParse) == SQLITE_OK {
|
|
_sqlite3Select(tls, pParse, *(*uintptr)(unsafe.Pointer(yymsp + 4)), bp+8)
|
|
}
|
|
_sqlite3SelectDelete(tls, (*TParse)(unsafe.Pointer(pParse)).Fdb, *(*uintptr)(unsafe.Pointer(yymsp + 4)))
|
|
goto _350
|
|
_95:
|
|
; /* select ::= WITH wqlist selectnowith */
|
|
*(*uintptr)(unsafe.Pointer(yymsp + uintptr(-libc.Int32FromInt32(2))*12 + 4)) = _attachWithToSelect(tls, pParse, *(*uintptr)(unsafe.Pointer(yymsp + 4)), *(*uintptr)(unsafe.Pointer(yymsp + uintptr(-libc.Int32FromInt32(1))*12 + 4)))
|
|
goto _350
|
|
_96:
|
|
; /* select ::= WITH RECURSIVE wqlist selectnowith */
|
|
*(*uintptr)(unsafe.Pointer(yymsp + uintptr(-libc.Int32FromInt32(3))*12 + 4)) = _attachWithToSelect(tls, pParse, *(*uintptr)(unsafe.Pointer(yymsp + 4)), *(*uintptr)(unsafe.Pointer(yymsp + uintptr(-libc.Int32FromInt32(1))*12 + 4)))
|
|
goto _350
|
|
_97:
|
|
; /* select ::= selectnowith */
|
|
p2 = *(*uintptr)(unsafe.Pointer(yymsp + 4))
|
|
if p2 != 0 {
|
|
_parserDoubleLinkSelect(tls, pParse, p2)
|
|
}
|
|
goto _350
|
|
_98:
|
|
; /* selectnowith ::= selectnowith multiselect_op oneselect */
|
|
pRhs = *(*uintptr)(unsafe.Pointer(yymsp + 4))
|
|
pLhs = *(*uintptr)(unsafe.Pointer(yymsp + uintptr(-libc.Int32FromInt32(2))*12 + 4))
|
|
if pRhs != 0 && (*TSelect)(unsafe.Pointer(pRhs)).FpPrior != 0 {
|
|
(**(**TToken)(__ccgo_up(bp + 40))).Fn = uint32(0)
|
|
_parserDoubleLinkSelect(tls, pParse, pRhs)
|
|
pFrom = _sqlite3SrcListAppendFromTerm(tls, pParse, uintptr(0), uintptr(0), uintptr(0), bp+40, pRhs, uintptr(0))
|
|
pRhs = _sqlite3SelectNew(tls, pParse, uintptr(0), pFrom, uintptr(0), uintptr(0), uintptr(0), uintptr(0), uint32(0), uintptr(0))
|
|
}
|
|
if pRhs != 0 {
|
|
(*TSelect)(unsafe.Pointer(pRhs)).Fop = libc.Uint8FromInt32(*(*int32)(unsafe.Pointer(yymsp + uintptr(-libc.Int32FromInt32(1))*12 + 4)))
|
|
(*TSelect)(unsafe.Pointer(pRhs)).FpPrior = pLhs
|
|
if pLhs != 0 {
|
|
**(**Tu32)(__ccgo_up(pLhs + 4)) &= ^libc.Uint32FromInt32(SF_MultiValue)
|
|
}
|
|
**(**Tu32)(__ccgo_up(pRhs + 4)) &= ^libc.Uint32FromInt32(SF_MultiValue)
|
|
if *(*int32)(unsafe.Pointer(yymsp + uintptr(-libc.Int32FromInt32(1))*12 + 4)) != int32(TK_ALL) {
|
|
libc.SetBitFieldPtr16Uint32(pParse+28, libc.Uint32FromInt32(1), 2, 0x4)
|
|
}
|
|
} else {
|
|
_sqlite3SelectDelete(tls, (*TParse)(unsafe.Pointer(pParse)).Fdb, pLhs)
|
|
}
|
|
*(*uintptr)(unsafe.Pointer(yymsp + uintptr(-libc.Int32FromInt32(2))*12 + 4)) = pRhs
|
|
goto _350
|
|
_100:
|
|
; /* multiselect_op ::= UNION */
|
|
_99:
|
|
;
|
|
*(*int32)(unsafe.Pointer(yymsp + 4)) = libc.Int32FromUint16((**(**TyyStackEntry)(__ccgo_up(yymsp))).Fmajor) /*A-overwrites-OP*/
|
|
goto _350
|
|
_101:
|
|
; /* multiselect_op ::= UNION ALL */
|
|
*(*int32)(unsafe.Pointer(yymsp + uintptr(-libc.Int32FromInt32(1))*12 + 4)) = int32(TK_ALL)
|
|
goto _350
|
|
_102:
|
|
; /* oneselect ::= SELECT distinct selcollist from where_opt groupby_opt having_opt orderby_opt limit_opt */
|
|
*(*uintptr)(unsafe.Pointer(yymsp + uintptr(-libc.Int32FromInt32(8))*12 + 4)) = _sqlite3SelectNew(tls, pParse, *(*uintptr)(unsafe.Pointer(yymsp + uintptr(-libc.Int32FromInt32(6))*12 + 4)), *(*uintptr)(unsafe.Pointer(yymsp + uintptr(-libc.Int32FromInt32(5))*12 + 4)), *(*uintptr)(unsafe.Pointer(yymsp + uintptr(-libc.Int32FromInt32(4))*12 + 4)), *(*uintptr)(unsafe.Pointer(yymsp + uintptr(-libc.Int32FromInt32(3))*12 + 4)), *(*uintptr)(unsafe.Pointer(yymsp + uintptr(-libc.Int32FromInt32(2))*12 + 4)), *(*uintptr)(unsafe.Pointer(yymsp + uintptr(-libc.Int32FromInt32(1))*12 + 4)), libc.Uint32FromInt32(*(*int32)(unsafe.Pointer(yymsp + uintptr(-libc.Int32FromInt32(7))*12 + 4))), *(*uintptr)(unsafe.Pointer(yymsp + 4)))
|
|
goto _350
|
|
_103:
|
|
; /* oneselect ::= SELECT distinct selcollist from where_opt groupby_opt having_opt window_clause orderby_opt limit_opt */
|
|
*(*uintptr)(unsafe.Pointer(yymsp + uintptr(-libc.Int32FromInt32(9))*12 + 4)) = _sqlite3SelectNew(tls, pParse, *(*uintptr)(unsafe.Pointer(yymsp + uintptr(-libc.Int32FromInt32(7))*12 + 4)), *(*uintptr)(unsafe.Pointer(yymsp + uintptr(-libc.Int32FromInt32(6))*12 + 4)), *(*uintptr)(unsafe.Pointer(yymsp + uintptr(-libc.Int32FromInt32(5))*12 + 4)), *(*uintptr)(unsafe.Pointer(yymsp + uintptr(-libc.Int32FromInt32(4))*12 + 4)), *(*uintptr)(unsafe.Pointer(yymsp + uintptr(-libc.Int32FromInt32(3))*12 + 4)), *(*uintptr)(unsafe.Pointer(yymsp + uintptr(-libc.Int32FromInt32(1))*12 + 4)), libc.Uint32FromInt32(*(*int32)(unsafe.Pointer(yymsp + uintptr(-libc.Int32FromInt32(8))*12 + 4))), *(*uintptr)(unsafe.Pointer(yymsp + 4)))
|
|
if *(*uintptr)(unsafe.Pointer(yymsp + uintptr(-libc.Int32FromInt32(9))*12 + 4)) != 0 {
|
|
(*TSelect)(unsafe.Pointer(*(*uintptr)(unsafe.Pointer(yymsp + uintptr(-libc.Int32FromInt32(9))*12 + 4)))).FpWinDefn = *(*uintptr)(unsafe.Pointer(yymsp + uintptr(-libc.Int32FromInt32(2))*12 + 4))
|
|
} else {
|
|
_sqlite3WindowListDelete(tls, (*TParse)(unsafe.Pointer(pParse)).Fdb, *(*uintptr)(unsafe.Pointer(yymsp + uintptr(-libc.Int32FromInt32(2))*12 + 4)))
|
|
}
|
|
goto _350
|
|
_104:
|
|
; /* values ::= VALUES LP nexprlist RP */
|
|
*(*uintptr)(unsafe.Pointer(yymsp + uintptr(-libc.Int32FromInt32(3))*12 + 4)) = _sqlite3SelectNew(tls, pParse, *(*uintptr)(unsafe.Pointer(yymsp + uintptr(-libc.Int32FromInt32(1))*12 + 4)), uintptr(0), uintptr(0), uintptr(0), uintptr(0), uintptr(0), uint32(SF_Values), uintptr(0))
|
|
goto _350
|
|
_105:
|
|
; /* oneselect ::= mvalues */
|
|
_sqlite3MultiValuesEnd(tls, pParse, *(*uintptr)(unsafe.Pointer(yymsp + 4)))
|
|
goto _350
|
|
_107:
|
|
; /* mvalues ::= values COMMA LP nexprlist RP */
|
|
_106:
|
|
;
|
|
*(*uintptr)(unsafe.Pointer(yymsp + uintptr(-libc.Int32FromInt32(4))*12 + 4)) = _sqlite3MultiValues(tls, pParse, *(*uintptr)(unsafe.Pointer(yymsp + uintptr(-libc.Int32FromInt32(4))*12 + 4)), *(*uintptr)(unsafe.Pointer(yymsp + uintptr(-libc.Int32FromInt32(1))*12 + 4)))
|
|
goto _350
|
|
_108:
|
|
; /* distinct ::= DISTINCT */
|
|
*(*int32)(unsafe.Pointer(yymsp + 4)) = int32(SF_Distinct)
|
|
goto _350
|
|
_109:
|
|
; /* distinct ::= ALL */
|
|
*(*int32)(unsafe.Pointer(yymsp + 4)) = int32(SF_All)
|
|
goto _350
|
|
_111:
|
|
; /* sclp ::= */
|
|
_110:
|
|
;
|
|
_112:
|
|
;
|
|
_113:
|
|
;
|
|
_114:
|
|
;
|
|
_115:
|
|
;
|
|
*(*uintptr)(unsafe.Pointer(yymsp + 1*12 + 4)) = uintptr(0)
|
|
goto _350
|
|
_116:
|
|
; /* selcollist ::= sclp scanpt expr scanpt as */
|
|
*(*uintptr)(unsafe.Pointer(yymsp + uintptr(-libc.Int32FromInt32(4))*12 + 4)) = _sqlite3ExprListAppend(tls, pParse, *(*uintptr)(unsafe.Pointer(yymsp + uintptr(-libc.Int32FromInt32(4))*12 + 4)), *(*uintptr)(unsafe.Pointer(yymsp + uintptr(-libc.Int32FromInt32(2))*12 + 4)))
|
|
if *(*uint32)(unsafe.Pointer(yymsp + 4 + 4)) > uint32(0) {
|
|
_sqlite3ExprListSetName(tls, pParse, *(*uintptr)(unsafe.Pointer(yymsp + uintptr(-libc.Int32FromInt32(4))*12 + 4)), yymsp+4, int32(1))
|
|
}
|
|
_sqlite3ExprListSetSpan(tls, pParse, *(*uintptr)(unsafe.Pointer(yymsp + uintptr(-libc.Int32FromInt32(4))*12 + 4)), *(*uintptr)(unsafe.Pointer(yymsp + uintptr(-libc.Int32FromInt32(3))*12 + 4)), *(*uintptr)(unsafe.Pointer(yymsp + uintptr(-libc.Int32FromInt32(1))*12 + 4)))
|
|
goto _350
|
|
_117:
|
|
; /* selcollist ::= sclp scanpt STAR */
|
|
p3 = _sqlite3Expr(tls, (*TParse)(unsafe.Pointer(pParse)).Fdb, int32(TK_ASTERISK), uintptr(0))
|
|
_sqlite3ExprSetErrorOffset(tls, p3, int32(*(*uintptr)(unsafe.Pointer(yymsp + 4)))-int32((*TParse)(unsafe.Pointer(pParse)).FzTail))
|
|
*(*uintptr)(unsafe.Pointer(yymsp + uintptr(-libc.Int32FromInt32(2))*12 + 4)) = _sqlite3ExprListAppend(tls, pParse, *(*uintptr)(unsafe.Pointer(yymsp + uintptr(-libc.Int32FromInt32(2))*12 + 4)), p3)
|
|
goto _350
|
|
_118:
|
|
; /* selcollist ::= sclp scanpt nm DOT STAR */
|
|
pRight = _sqlite3PExpr(tls, pParse, int32(TK_ASTERISK), uintptr(0), uintptr(0))
|
|
_sqlite3ExprSetErrorOffset(tls, pRight, int32(*(*uintptr)(unsafe.Pointer(yymsp + 4)))-int32((*TParse)(unsafe.Pointer(pParse)).FzTail))
|
|
pLeft = _tokenExpr(tls, pParse, int32(TK_ID), *(*TToken)(unsafe.Pointer(yymsp + uintptr(-libc.Int32FromInt32(2))*12 + 4)))
|
|
pDot = _sqlite3PExpr(tls, pParse, int32(TK_DOT), pLeft, pRight)
|
|
*(*uintptr)(unsafe.Pointer(yymsp + uintptr(-libc.Int32FromInt32(4))*12 + 4)) = _sqlite3ExprListAppend(tls, pParse, *(*uintptr)(unsafe.Pointer(yymsp + uintptr(-libc.Int32FromInt32(4))*12 + 4)), pDot)
|
|
goto _350
|
|
_120:
|
|
; /* as ::= AS nm */
|
|
_119:
|
|
;
|
|
_121:
|
|
;
|
|
_122:
|
|
;
|
|
*(*TToken)(unsafe.Pointer(yymsp + uintptr(-libc.Int32FromInt32(1))*12 + 4)) = *(*TToken)(unsafe.Pointer(yymsp + 4))
|
|
goto _350
|
|
_124:
|
|
; /* from ::= */
|
|
_123:
|
|
;
|
|
*(*uintptr)(unsafe.Pointer(yymsp + 1*12 + 4)) = uintptr(0)
|
|
goto _350
|
|
_125:
|
|
; /* from ::= FROM seltablist */
|
|
*(*uintptr)(unsafe.Pointer(yymsp + uintptr(-libc.Int32FromInt32(1))*12 + 4)) = *(*uintptr)(unsafe.Pointer(yymsp + 4))
|
|
_sqlite3SrcListShiftJoinType(tls, pParse, *(*uintptr)(unsafe.Pointer(yymsp + uintptr(-libc.Int32FromInt32(1))*12 + 4)))
|
|
goto _350
|
|
_126:
|
|
; /* stl_prefix ::= seltablist joinop */
|
|
if *(*uintptr)(unsafe.Pointer(yymsp + uintptr(-libc.Int32FromInt32(1))*12 + 4)) != 0 && (*TSrcList)(unsafe.Pointer(*(*uintptr)(unsafe.Pointer(yymsp + uintptr(-libc.Int32FromInt32(1))*12 + 4)))).FnSrc > 0 {
|
|
(*(*TSrcItem)(unsafe.Pointer(*(*uintptr)(unsafe.Pointer(yymsp + uintptr(-libc.Int32FromInt32(1))*12 + 4)) + 8 + uintptr((*TSrcList)(unsafe.Pointer(*(*uintptr)(unsafe.Pointer(yymsp + uintptr(-libc.Int32FromInt32(1))*12 + 4)))).FnSrc-int32(1))*48))).Ffg.Fjointype = libc.Uint8FromInt32(*(*int32)(unsafe.Pointer(yymsp + 4)))
|
|
}
|
|
goto _350
|
|
_127:
|
|
; /* seltablist ::= stl_prefix nm dbnm as on_using */
|
|
*(*uintptr)(unsafe.Pointer(yymsp + uintptr(-libc.Int32FromInt32(4))*12 + 4)) = _sqlite3SrcListAppendFromTerm(tls, pParse, *(*uintptr)(unsafe.Pointer(yymsp + uintptr(-libc.Int32FromInt32(4))*12 + 4)), yymsp+uintptr(-libc.Int32FromInt32(3))*12+4, yymsp+uintptr(-libc.Int32FromInt32(2))*12+4, yymsp+uintptr(-libc.Int32FromInt32(1))*12+4, uintptr(0), yymsp+4)
|
|
goto _350
|
|
_128:
|
|
; /* seltablist ::= stl_prefix nm dbnm as indexed_by on_using */
|
|
*(*uintptr)(unsafe.Pointer(yymsp + uintptr(-libc.Int32FromInt32(5))*12 + 4)) = _sqlite3SrcListAppendFromTerm(tls, pParse, *(*uintptr)(unsafe.Pointer(yymsp + uintptr(-libc.Int32FromInt32(5))*12 + 4)), yymsp+uintptr(-libc.Int32FromInt32(4))*12+4, yymsp+uintptr(-libc.Int32FromInt32(3))*12+4, yymsp+uintptr(-libc.Int32FromInt32(2))*12+4, uintptr(0), yymsp+4)
|
|
_sqlite3SrcListIndexedBy(tls, pParse, *(*uintptr)(unsafe.Pointer(yymsp + uintptr(-libc.Int32FromInt32(5))*12 + 4)), yymsp+uintptr(-libc.Int32FromInt32(1))*12+4)
|
|
goto _350
|
|
_129:
|
|
; /* seltablist ::= stl_prefix nm dbnm LP exprlist RP as on_using */
|
|
*(*uintptr)(unsafe.Pointer(yymsp + uintptr(-libc.Int32FromInt32(7))*12 + 4)) = _sqlite3SrcListAppendFromTerm(tls, pParse, *(*uintptr)(unsafe.Pointer(yymsp + uintptr(-libc.Int32FromInt32(7))*12 + 4)), yymsp+uintptr(-libc.Int32FromInt32(6))*12+4, yymsp+uintptr(-libc.Int32FromInt32(5))*12+4, yymsp+uintptr(-libc.Int32FromInt32(1))*12+4, uintptr(0), yymsp+4)
|
|
_sqlite3SrcListFuncArgs(tls, pParse, *(*uintptr)(unsafe.Pointer(yymsp + uintptr(-libc.Int32FromInt32(7))*12 + 4)), *(*uintptr)(unsafe.Pointer(yymsp + uintptr(-libc.Int32FromInt32(3))*12 + 4)))
|
|
goto _350
|
|
_130:
|
|
; /* seltablist ::= stl_prefix LP select RP as on_using */
|
|
*(*uintptr)(unsafe.Pointer(yymsp + uintptr(-libc.Int32FromInt32(5))*12 + 4)) = _sqlite3SrcListAppendFromTerm(tls, pParse, *(*uintptr)(unsafe.Pointer(yymsp + uintptr(-libc.Int32FromInt32(5))*12 + 4)), uintptr(0), uintptr(0), yymsp+uintptr(-libc.Int32FromInt32(1))*12+4, *(*uintptr)(unsafe.Pointer(yymsp + uintptr(-libc.Int32FromInt32(3))*12 + 4)), yymsp+4)
|
|
goto _350
|
|
_131:
|
|
; /* seltablist ::= stl_prefix LP seltablist RP as on_using */
|
|
if *(*uintptr)(unsafe.Pointer(yymsp + uintptr(-libc.Int32FromInt32(5))*12 + 4)) == uintptr(0) && *(*uint32)(unsafe.Pointer(yymsp + uintptr(-libc.Int32FromInt32(1))*12 + 4 + 4)) == uint32(0) && *(*uintptr)(unsafe.Pointer(yymsp + 4)) == uintptr(0) && *(*uintptr)(unsafe.Pointer(yymsp + 4 + 4)) == uintptr(0) {
|
|
*(*uintptr)(unsafe.Pointer(yymsp + uintptr(-libc.Int32FromInt32(5))*12 + 4)) = *(*uintptr)(unsafe.Pointer(yymsp + uintptr(-libc.Int32FromInt32(3))*12 + 4))
|
|
} else {
|
|
if *(*uintptr)(unsafe.Pointer(yymsp + uintptr(-libc.Int32FromInt32(3))*12 + 4)) != uintptr(0) && (*TSrcList)(unsafe.Pointer(*(*uintptr)(unsafe.Pointer(yymsp + uintptr(-libc.Int32FromInt32(3))*12 + 4)))).FnSrc == int32(1) {
|
|
*(*uintptr)(unsafe.Pointer(yymsp + uintptr(-libc.Int32FromInt32(5))*12 + 4)) = _sqlite3SrcListAppendFromTerm(tls, pParse, *(*uintptr)(unsafe.Pointer(yymsp + uintptr(-libc.Int32FromInt32(5))*12 + 4)), uintptr(0), uintptr(0), yymsp+uintptr(-libc.Int32FromInt32(1))*12+4, uintptr(0), yymsp+4)
|
|
if *(*uintptr)(unsafe.Pointer(yymsp + uintptr(-libc.Int32FromInt32(5))*12 + 4)) != 0 {
|
|
pNew = *(*uintptr)(unsafe.Pointer(yymsp + uintptr(-libc.Int32FromInt32(5))*12 + 4)) + 8 + uintptr((*TSrcList)(unsafe.Pointer(*(*uintptr)(unsafe.Pointer(yymsp + uintptr(-libc.Int32FromInt32(5))*12 + 4)))).FnSrc-int32(1))*48
|
|
pOld = *(*uintptr)(unsafe.Pointer(yymsp + uintptr(-libc.Int32FromInt32(3))*12 + 4)) + 8
|
|
(*TSrcItem)(unsafe.Pointer(pNew)).FzName = (*TSrcItem)(unsafe.Pointer(pOld)).FzName
|
|
if int32(*(*uint32)(unsafe.Pointer(pOld + 12 + 4))&0x4>>2) != 0 {
|
|
libc.SetBitFieldPtr32Uint32(pNew+12+4, libc.Uint32FromInt32(1), 2, 0x4)
|
|
*(*uintptr)(unsafe.Pointer(pNew + 44)) = *(*uintptr)(unsafe.Pointer(pOld + 44))
|
|
*(*uintptr)(unsafe.Pointer(pOld + 44)) = uintptr(0)
|
|
libc.SetBitFieldPtr32Uint32(pOld+12+4, libc.Uint32FromInt32(0), 2, 0x4)
|
|
if (*TSelect)(unsafe.Pointer((*TSubquery)(unsafe.Pointer(*(*uintptr)(unsafe.Pointer(pNew + 44)))).FpSelect)).FselFlags&uint32(SF_NestedFrom) != uint32(0) {
|
|
libc.SetBitFieldPtr32Uint32(pNew+12+4, libc.Uint32FromInt32(1), 14, 0x4000)
|
|
}
|
|
} else {
|
|
*(*uintptr)(unsafe.Pointer(pNew + 44)) = *(*uintptr)(unsafe.Pointer(pOld + 44))
|
|
*(*uintptr)(unsafe.Pointer(pOld + 44)) = uintptr(0)
|
|
}
|
|
if int32(*(*uint32)(unsafe.Pointer(pOld + 12 + 4))&0x8>>3) != 0 {
|
|
*(*uintptr)(unsafe.Pointer(pNew + 32)) = *(*uintptr)(unsafe.Pointer(pOld + 32))
|
|
*(*uintptr)(unsafe.Pointer(pOld + 32)) = uintptr(0)
|
|
libc.SetBitFieldPtr32Uint32(pOld+12+4, libc.Uint32FromInt32(0), 3, 0x8)
|
|
libc.SetBitFieldPtr32Uint32(pNew+12+4, libc.Uint32FromInt32(1), 3, 0x8)
|
|
}
|
|
(*TSrcItem)(unsafe.Pointer(pOld)).FzName = uintptr(0)
|
|
}
|
|
_sqlite3SrcListDelete(tls, (*TParse)(unsafe.Pointer(pParse)).Fdb, *(*uintptr)(unsafe.Pointer(yymsp + uintptr(-libc.Int32FromInt32(3))*12 + 4)))
|
|
} else {
|
|
_sqlite3SrcListShiftJoinType(tls, pParse, *(*uintptr)(unsafe.Pointer(yymsp + uintptr(-libc.Int32FromInt32(3))*12 + 4)))
|
|
pSubquery = _sqlite3SelectNew(tls, pParse, uintptr(0), *(*uintptr)(unsafe.Pointer(yymsp + uintptr(-libc.Int32FromInt32(3))*12 + 4)), uintptr(0), uintptr(0), uintptr(0), uintptr(0), uint32(SF_NestedFrom), uintptr(0))
|
|
*(*uintptr)(unsafe.Pointer(yymsp + uintptr(-libc.Int32FromInt32(5))*12 + 4)) = _sqlite3SrcListAppendFromTerm(tls, pParse, *(*uintptr)(unsafe.Pointer(yymsp + uintptr(-libc.Int32FromInt32(5))*12 + 4)), uintptr(0), uintptr(0), yymsp+uintptr(-libc.Int32FromInt32(1))*12+4, pSubquery, yymsp+4)
|
|
}
|
|
}
|
|
goto _350
|
|
_133:
|
|
; /* dbnm ::= */
|
|
_132:
|
|
;
|
|
*(*uintptr)(unsafe.Pointer(yymsp + 1*12 + 4)) = uintptr(0)
|
|
*(*uint32)(unsafe.Pointer(yymsp + 1*12 + 4 + 4)) = uint32(0)
|
|
goto _350
|
|
_135:
|
|
; /* fullname ::= nm */
|
|
_134:
|
|
;
|
|
*(*uintptr)(unsafe.Pointer(&**(**TYYMINORTYPE)(__ccgo_up(bp)))) = _sqlite3SrcListAppend(tls, pParse, uintptr(0), yymsp+4, uintptr(0))
|
|
if libc.Int32FromUint8((*TParse)(unsafe.Pointer(pParse)).FeParseMode) >= int32(PARSE_MODE_RENAME) && *(*uintptr)(unsafe.Pointer(&**(**TYYMINORTYPE)(__ccgo_up(bp)))) != 0 {
|
|
_sqlite3RenameTokenMap(tls, pParse, (*(*TSrcItem)(unsafe.Pointer(*(*uintptr)(unsafe.Pointer(&**(**TYYMINORTYPE)(__ccgo_up(bp)))) + 8))).FzName, yymsp+4)
|
|
}
|
|
*(*uintptr)(unsafe.Pointer(yymsp + 4)) = *(*uintptr)(unsafe.Pointer(&**(**TYYMINORTYPE)(__ccgo_up(bp))))
|
|
goto _350
|
|
_137:
|
|
; /* fullname ::= nm DOT nm */
|
|
_136:
|
|
;
|
|
*(*uintptr)(unsafe.Pointer(&**(**TYYMINORTYPE)(__ccgo_up(bp)))) = _sqlite3SrcListAppend(tls, pParse, uintptr(0), yymsp+uintptr(-libc.Int32FromInt32(2))*12+4, yymsp+4)
|
|
if libc.Int32FromUint8((*TParse)(unsafe.Pointer(pParse)).FeParseMode) >= int32(PARSE_MODE_RENAME) && *(*uintptr)(unsafe.Pointer(&**(**TYYMINORTYPE)(__ccgo_up(bp)))) != 0 {
|
|
_sqlite3RenameTokenMap(tls, pParse, (*(*TSrcItem)(unsafe.Pointer(*(*uintptr)(unsafe.Pointer(&**(**TYYMINORTYPE)(__ccgo_up(bp)))) + 8))).FzName, yymsp+4)
|
|
}
|
|
*(*uintptr)(unsafe.Pointer(yymsp + uintptr(-libc.Int32FromInt32(2))*12 + 4)) = *(*uintptr)(unsafe.Pointer(&**(**TYYMINORTYPE)(__ccgo_up(bp))))
|
|
goto _350
|
|
_138:
|
|
; /* xfullname ::= nm AS nm */
|
|
*(*uintptr)(unsafe.Pointer(&**(**TYYMINORTYPE)(__ccgo_up(bp)))) = _sqlite3SrcListAppend(tls, pParse, uintptr(0), yymsp+uintptr(-libc.Int32FromInt32(2))*12+4, uintptr(0))
|
|
if *(*uintptr)(unsafe.Pointer(&**(**TYYMINORTYPE)(__ccgo_up(bp)))) != 0 {
|
|
if libc.Int32FromUint8((*TParse)(unsafe.Pointer(pParse)).FeParseMode) >= int32(PARSE_MODE_RENAME) {
|
|
_sqlite3RenameTokenMap(tls, pParse, (*(*TSrcItem)(unsafe.Pointer(*(*uintptr)(unsafe.Pointer(&**(**TYYMINORTYPE)(__ccgo_up(bp)))) + 8))).FzName, yymsp+uintptr(-libc.Int32FromInt32(2))*12+4)
|
|
} else {
|
|
(*(*TSrcItem)(unsafe.Pointer(*(*uintptr)(unsafe.Pointer(&**(**TYYMINORTYPE)(__ccgo_up(bp)))) + 8))).FzAlias = _sqlite3NameFromToken(tls, (*TParse)(unsafe.Pointer(pParse)).Fdb, yymsp+4)
|
|
}
|
|
}
|
|
*(*uintptr)(unsafe.Pointer(yymsp + uintptr(-libc.Int32FromInt32(2))*12 + 4)) = *(*uintptr)(unsafe.Pointer(&**(**TYYMINORTYPE)(__ccgo_up(bp))))
|
|
goto _350
|
|
_139:
|
|
; /* xfullname ::= nm DOT nm AS nm */
|
|
*(*uintptr)(unsafe.Pointer(&**(**TYYMINORTYPE)(__ccgo_up(bp)))) = _sqlite3SrcListAppend(tls, pParse, uintptr(0), yymsp+uintptr(-libc.Int32FromInt32(4))*12+4, yymsp+uintptr(-libc.Int32FromInt32(2))*12+4)
|
|
if *(*uintptr)(unsafe.Pointer(&**(**TYYMINORTYPE)(__ccgo_up(bp)))) != 0 {
|
|
if libc.Int32FromUint8((*TParse)(unsafe.Pointer(pParse)).FeParseMode) >= int32(PARSE_MODE_RENAME) {
|
|
_sqlite3RenameTokenMap(tls, pParse, (*(*TSrcItem)(unsafe.Pointer(*(*uintptr)(unsafe.Pointer(&**(**TYYMINORTYPE)(__ccgo_up(bp)))) + 8))).FzName, yymsp+uintptr(-libc.Int32FromInt32(2))*12+4)
|
|
} else {
|
|
(*(*TSrcItem)(unsafe.Pointer(*(*uintptr)(unsafe.Pointer(&**(**TYYMINORTYPE)(__ccgo_up(bp)))) + 8))).FzAlias = _sqlite3NameFromToken(tls, (*TParse)(unsafe.Pointer(pParse)).Fdb, yymsp+4)
|
|
}
|
|
}
|
|
*(*uintptr)(unsafe.Pointer(yymsp + uintptr(-libc.Int32FromInt32(4))*12 + 4)) = *(*uintptr)(unsafe.Pointer(&**(**TYYMINORTYPE)(__ccgo_up(bp))))
|
|
goto _350
|
|
_140:
|
|
; /* joinop ::= COMMA|JOIN */
|
|
*(*int32)(unsafe.Pointer(yymsp + 4)) = int32(JT_INNER)
|
|
goto _350
|
|
_141:
|
|
; /* joinop ::= JOIN_KW JOIN */
|
|
*(*int32)(unsafe.Pointer(yymsp + uintptr(-libc.Int32FromInt32(1))*12 + 4)) = _sqlite3JoinType(tls, pParse, yymsp+uintptr(-libc.Int32FromInt32(1))*12+4, uintptr(0), uintptr(0)) /*X-overwrites-A*/
|
|
goto _350
|
|
_142:
|
|
; /* joinop ::= JOIN_KW nm JOIN */
|
|
*(*int32)(unsafe.Pointer(yymsp + uintptr(-libc.Int32FromInt32(2))*12 + 4)) = _sqlite3JoinType(tls, pParse, yymsp+uintptr(-libc.Int32FromInt32(2))*12+4, yymsp+uintptr(-libc.Int32FromInt32(1))*12+4, uintptr(0)) /*X-overwrites-A*/
|
|
goto _350
|
|
_143:
|
|
; /* joinop ::= JOIN_KW nm nm JOIN */
|
|
*(*int32)(unsafe.Pointer(yymsp + uintptr(-libc.Int32FromInt32(3))*12 + 4)) = _sqlite3JoinType(tls, pParse, yymsp+uintptr(-libc.Int32FromInt32(3))*12+4, yymsp+uintptr(-libc.Int32FromInt32(2))*12+4, yymsp+uintptr(-libc.Int32FromInt32(1))*12+4) /*X-overwrites-A*/
|
|
goto _350
|
|
_144:
|
|
; /* on_using ::= ON expr */
|
|
*(*uintptr)(unsafe.Pointer(yymsp + uintptr(-libc.Int32FromInt32(1))*12 + 4)) = *(*uintptr)(unsafe.Pointer(yymsp + 4))
|
|
*(*uintptr)(unsafe.Pointer(yymsp + uintptr(-libc.Int32FromInt32(1))*12 + 4 + 4)) = uintptr(0)
|
|
goto _350
|
|
_145:
|
|
; /* on_using ::= USING LP idlist RP */
|
|
*(*uintptr)(unsafe.Pointer(yymsp + uintptr(-libc.Int32FromInt32(3))*12 + 4)) = uintptr(0)
|
|
*(*uintptr)(unsafe.Pointer(yymsp + uintptr(-libc.Int32FromInt32(3))*12 + 4 + 4)) = *(*uintptr)(unsafe.Pointer(yymsp + uintptr(-libc.Int32FromInt32(1))*12 + 4))
|
|
goto _350
|
|
_146:
|
|
; /* on_using ::= */
|
|
*(*uintptr)(unsafe.Pointer(yymsp + 1*12 + 4)) = uintptr(0)
|
|
*(*uintptr)(unsafe.Pointer(yymsp + 1*12 + 4 + 4)) = uintptr(0)
|
|
goto _350
|
|
_147:
|
|
; /* indexed_by ::= INDEXED BY nm */
|
|
*(*TToken)(unsafe.Pointer(yymsp + uintptr(-libc.Int32FromInt32(2))*12 + 4)) = *(*TToken)(unsafe.Pointer(yymsp + 4))
|
|
goto _350
|
|
_148:
|
|
; /* indexed_by ::= NOT INDEXED */
|
|
*(*uintptr)(unsafe.Pointer(yymsp + uintptr(-libc.Int32FromInt32(1))*12 + 4)) = uintptr(0)
|
|
*(*uint32)(unsafe.Pointer(yymsp + uintptr(-libc.Int32FromInt32(1))*12 + 4 + 4)) = uint32(1)
|
|
goto _350
|
|
_150:
|
|
; /* orderby_opt ::= ORDER BY sortlist */
|
|
_149:
|
|
;
|
|
*(*uintptr)(unsafe.Pointer(yymsp + uintptr(-libc.Int32FromInt32(2))*12 + 4)) = *(*uintptr)(unsafe.Pointer(yymsp + 4))
|
|
goto _350
|
|
_151:
|
|
; /* sortlist ::= sortlist COMMA expr sortorder nulls */
|
|
*(*uintptr)(unsafe.Pointer(yymsp + uintptr(-libc.Int32FromInt32(4))*12 + 4)) = _sqlite3ExprListAppend(tls, pParse, *(*uintptr)(unsafe.Pointer(yymsp + uintptr(-libc.Int32FromInt32(4))*12 + 4)), *(*uintptr)(unsafe.Pointer(yymsp + uintptr(-libc.Int32FromInt32(2))*12 + 4)))
|
|
_sqlite3ExprListSetSortOrder(tls, *(*uintptr)(unsafe.Pointer(yymsp + uintptr(-libc.Int32FromInt32(4))*12 + 4)), *(*int32)(unsafe.Pointer(yymsp + uintptr(-libc.Int32FromInt32(1))*12 + 4)), *(*int32)(unsafe.Pointer(yymsp + 4)))
|
|
goto _350
|
|
_152:
|
|
; /* sortlist ::= expr sortorder nulls */
|
|
*(*uintptr)(unsafe.Pointer(yymsp + uintptr(-libc.Int32FromInt32(2))*12 + 4)) = _sqlite3ExprListAppend(tls, pParse, uintptr(0), *(*uintptr)(unsafe.Pointer(yymsp + uintptr(-libc.Int32FromInt32(2))*12 + 4))) /*A-overwrites-Y*/
|
|
_sqlite3ExprListSetSortOrder(tls, *(*uintptr)(unsafe.Pointer(yymsp + uintptr(-libc.Int32FromInt32(2))*12 + 4)), *(*int32)(unsafe.Pointer(yymsp + uintptr(-libc.Int32FromInt32(1))*12 + 4)), *(*int32)(unsafe.Pointer(yymsp + 4)))
|
|
goto _350
|
|
_153:
|
|
; /* sortorder ::= ASC */
|
|
*(*int32)(unsafe.Pointer(yymsp + 4)) = SQLITE_SO_ASC
|
|
goto _350
|
|
_154:
|
|
; /* sortorder ::= DESC */
|
|
*(*int32)(unsafe.Pointer(yymsp + 4)) = int32(SQLITE_SO_DESC)
|
|
goto _350
|
|
_156:
|
|
; /* sortorder ::= */
|
|
_155:
|
|
;
|
|
*(*int32)(unsafe.Pointer(yymsp + 1*12 + 4)) = -int32(1)
|
|
goto _350
|
|
_157:
|
|
; /* nulls ::= NULLS FIRST */
|
|
*(*int32)(unsafe.Pointer(yymsp + uintptr(-libc.Int32FromInt32(1))*12 + 4)) = SQLITE_SO_ASC
|
|
goto _350
|
|
_158:
|
|
; /* nulls ::= NULLS LAST */
|
|
*(*int32)(unsafe.Pointer(yymsp + uintptr(-libc.Int32FromInt32(1))*12 + 4)) = int32(SQLITE_SO_DESC)
|
|
goto _350
|
|
_160:
|
|
; /* having_opt ::= */
|
|
_159:
|
|
;
|
|
_161:
|
|
;
|
|
_162:
|
|
;
|
|
_163:
|
|
;
|
|
_164:
|
|
;
|
|
_165:
|
|
;
|
|
*(*uintptr)(unsafe.Pointer(yymsp + 1*12 + 4)) = uintptr(0)
|
|
goto _350
|
|
_167:
|
|
; /* having_opt ::= HAVING expr */
|
|
_166:
|
|
;
|
|
_168:
|
|
;
|
|
_169:
|
|
;
|
|
_170:
|
|
;
|
|
*(*uintptr)(unsafe.Pointer(yymsp + uintptr(-libc.Int32FromInt32(1))*12 + 4)) = *(*uintptr)(unsafe.Pointer(yymsp + 4))
|
|
goto _350
|
|
_171:
|
|
; /* limit_opt ::= LIMIT expr */
|
|
*(*uintptr)(unsafe.Pointer(yymsp + uintptr(-libc.Int32FromInt32(1))*12 + 4)) = _sqlite3PExpr(tls, pParse, int32(TK_LIMIT), *(*uintptr)(unsafe.Pointer(yymsp + 4)), uintptr(0))
|
|
goto _350
|
|
_172:
|
|
; /* limit_opt ::= LIMIT expr OFFSET expr */
|
|
*(*uintptr)(unsafe.Pointer(yymsp + uintptr(-libc.Int32FromInt32(3))*12 + 4)) = _sqlite3PExpr(tls, pParse, int32(TK_LIMIT), *(*uintptr)(unsafe.Pointer(yymsp + uintptr(-libc.Int32FromInt32(2))*12 + 4)), *(*uintptr)(unsafe.Pointer(yymsp + 4)))
|
|
goto _350
|
|
_173:
|
|
; /* limit_opt ::= LIMIT expr COMMA expr */
|
|
*(*uintptr)(unsafe.Pointer(yymsp + uintptr(-libc.Int32FromInt32(3))*12 + 4)) = _sqlite3PExpr(tls, pParse, int32(TK_LIMIT), *(*uintptr)(unsafe.Pointer(yymsp + 4)), *(*uintptr)(unsafe.Pointer(yymsp + uintptr(-libc.Int32FromInt32(2))*12 + 4)))
|
|
goto _350
|
|
_174:
|
|
; /* cmd ::= with DELETE FROM xfullname indexed_opt where_opt_ret */
|
|
_sqlite3SrcListIndexedBy(tls, pParse, *(*uintptr)(unsafe.Pointer(yymsp + uintptr(-libc.Int32FromInt32(2))*12 + 4)), yymsp+uintptr(-libc.Int32FromInt32(1))*12+4)
|
|
_sqlite3DeleteFrom(tls, pParse, *(*uintptr)(unsafe.Pointer(yymsp + uintptr(-libc.Int32FromInt32(2))*12 + 4)), *(*uintptr)(unsafe.Pointer(yymsp + 4)), uintptr(0), uintptr(0))
|
|
goto _350
|
|
_175:
|
|
; /* where_opt_ret ::= RETURNING selcollist */
|
|
_sqlite3AddReturning(tls, pParse, *(*uintptr)(unsafe.Pointer(yymsp + 4)))
|
|
*(*uintptr)(unsafe.Pointer(yymsp + uintptr(-libc.Int32FromInt32(1))*12 + 4)) = uintptr(0)
|
|
goto _350
|
|
_176:
|
|
; /* where_opt_ret ::= WHERE expr RETURNING selcollist */
|
|
_sqlite3AddReturning(tls, pParse, *(*uintptr)(unsafe.Pointer(yymsp + 4)))
|
|
*(*uintptr)(unsafe.Pointer(yymsp + uintptr(-libc.Int32FromInt32(3))*12 + 4)) = *(*uintptr)(unsafe.Pointer(yymsp + uintptr(-libc.Int32FromInt32(2))*12 + 4))
|
|
goto _350
|
|
_177:
|
|
; /* cmd ::= with UPDATE orconf xfullname indexed_opt SET setlist from where_opt_ret */
|
|
_sqlite3SrcListIndexedBy(tls, pParse, *(*uintptr)(unsafe.Pointer(yymsp + uintptr(-libc.Int32FromInt32(5))*12 + 4)), yymsp+uintptr(-libc.Int32FromInt32(4))*12+4)
|
|
_sqlite3ExprListCheckLength(tls, pParse, *(*uintptr)(unsafe.Pointer(yymsp + uintptr(-libc.Int32FromInt32(2))*12 + 4)), __ccgo_ts+25024)
|
|
if *(*uintptr)(unsafe.Pointer(yymsp + uintptr(-libc.Int32FromInt32(1))*12 + 4)) != 0 {
|
|
pFromClause = *(*uintptr)(unsafe.Pointer(yymsp + uintptr(-libc.Int32FromInt32(1))*12 + 4))
|
|
if (*TSrcList)(unsafe.Pointer(pFromClause)).FnSrc > int32(1) {
|
|
pSubquery1 = _sqlite3SelectNew(tls, pParse, uintptr(0), pFromClause, uintptr(0), uintptr(0), uintptr(0), uintptr(0), uint32(SF_NestedFrom), uintptr(0))
|
|
(**(**TToken)(__ccgo_up(bp + 48))).Fn = uint32(0)
|
|
(**(**TToken)(__ccgo_up(bp + 48))).Fz = uintptr(0)
|
|
pFromClause = _sqlite3SrcListAppendFromTerm(tls, pParse, uintptr(0), uintptr(0), uintptr(0), bp+48, pSubquery1, uintptr(0))
|
|
}
|
|
*(*uintptr)(unsafe.Pointer(yymsp + uintptr(-libc.Int32FromInt32(5))*12 + 4)) = _sqlite3SrcListAppendList(tls, pParse, *(*uintptr)(unsafe.Pointer(yymsp + uintptr(-libc.Int32FromInt32(5))*12 + 4)), pFromClause)
|
|
}
|
|
_sqlite3Update(tls, pParse, *(*uintptr)(unsafe.Pointer(yymsp + uintptr(-libc.Int32FromInt32(5))*12 + 4)), *(*uintptr)(unsafe.Pointer(yymsp + uintptr(-libc.Int32FromInt32(2))*12 + 4)), *(*uintptr)(unsafe.Pointer(yymsp + 4)), *(*int32)(unsafe.Pointer(yymsp + uintptr(-libc.Int32FromInt32(6))*12 + 4)), uintptr(0), uintptr(0), uintptr(0))
|
|
goto _350
|
|
_178:
|
|
; /* setlist ::= setlist COMMA nm EQ expr */
|
|
*(*uintptr)(unsafe.Pointer(yymsp + uintptr(-libc.Int32FromInt32(4))*12 + 4)) = _sqlite3ExprListAppend(tls, pParse, *(*uintptr)(unsafe.Pointer(yymsp + uintptr(-libc.Int32FromInt32(4))*12 + 4)), *(*uintptr)(unsafe.Pointer(yymsp + 4)))
|
|
_sqlite3ExprListSetName(tls, pParse, *(*uintptr)(unsafe.Pointer(yymsp + uintptr(-libc.Int32FromInt32(4))*12 + 4)), yymsp+uintptr(-libc.Int32FromInt32(2))*12+4, int32(1))
|
|
goto _350
|
|
_179:
|
|
; /* setlist ::= setlist COMMA LP idlist RP EQ expr */
|
|
*(*uintptr)(unsafe.Pointer(yymsp + uintptr(-libc.Int32FromInt32(6))*12 + 4)) = _sqlite3ExprListAppendVector(tls, pParse, *(*uintptr)(unsafe.Pointer(yymsp + uintptr(-libc.Int32FromInt32(6))*12 + 4)), *(*uintptr)(unsafe.Pointer(yymsp + uintptr(-libc.Int32FromInt32(3))*12 + 4)), *(*uintptr)(unsafe.Pointer(yymsp + 4)))
|
|
goto _350
|
|
_180:
|
|
; /* setlist ::= nm EQ expr */
|
|
*(*uintptr)(unsafe.Pointer(&**(**TYYMINORTYPE)(__ccgo_up(bp)))) = _sqlite3ExprListAppend(tls, pParse, uintptr(0), *(*uintptr)(unsafe.Pointer(yymsp + 4)))
|
|
_sqlite3ExprListSetName(tls, pParse, *(*uintptr)(unsafe.Pointer(&**(**TYYMINORTYPE)(__ccgo_up(bp)))), yymsp+uintptr(-libc.Int32FromInt32(2))*12+4, int32(1))
|
|
*(*uintptr)(unsafe.Pointer(yymsp + uintptr(-libc.Int32FromInt32(2))*12 + 4)) = *(*uintptr)(unsafe.Pointer(&**(**TYYMINORTYPE)(__ccgo_up(bp))))
|
|
goto _350
|
|
_181:
|
|
; /* setlist ::= LP idlist RP EQ expr */
|
|
*(*uintptr)(unsafe.Pointer(yymsp + uintptr(-libc.Int32FromInt32(4))*12 + 4)) = _sqlite3ExprListAppendVector(tls, pParse, uintptr(0), *(*uintptr)(unsafe.Pointer(yymsp + uintptr(-libc.Int32FromInt32(3))*12 + 4)), *(*uintptr)(unsafe.Pointer(yymsp + 4)))
|
|
goto _350
|
|
_182:
|
|
; /* cmd ::= with insert_cmd INTO xfullname idlist_opt select upsert */
|
|
_sqlite3Insert(tls, pParse, *(*uintptr)(unsafe.Pointer(yymsp + uintptr(-libc.Int32FromInt32(3))*12 + 4)), *(*uintptr)(unsafe.Pointer(yymsp + uintptr(-libc.Int32FromInt32(1))*12 + 4)), *(*uintptr)(unsafe.Pointer(yymsp + uintptr(-libc.Int32FromInt32(2))*12 + 4)), *(*int32)(unsafe.Pointer(yymsp + uintptr(-libc.Int32FromInt32(5))*12 + 4)), *(*uintptr)(unsafe.Pointer(yymsp + 4)))
|
|
goto _350
|
|
_183:
|
|
; /* cmd ::= with insert_cmd INTO xfullname idlist_opt DEFAULT VALUES returning */
|
|
_sqlite3Insert(tls, pParse, *(*uintptr)(unsafe.Pointer(yymsp + uintptr(-libc.Int32FromInt32(4))*12 + 4)), uintptr(0), *(*uintptr)(unsafe.Pointer(yymsp + uintptr(-libc.Int32FromInt32(3))*12 + 4)), *(*int32)(unsafe.Pointer(yymsp + uintptr(-libc.Int32FromInt32(6))*12 + 4)), uintptr(0))
|
|
goto _350
|
|
_184:
|
|
; /* upsert ::= */
|
|
*(*uintptr)(unsafe.Pointer(yymsp + 1*12 + 4)) = uintptr(0)
|
|
goto _350
|
|
_185:
|
|
; /* upsert ::= RETURNING selcollist */
|
|
*(*uintptr)(unsafe.Pointer(yymsp + uintptr(-libc.Int32FromInt32(1))*12 + 4)) = uintptr(0)
|
|
_sqlite3AddReturning(tls, pParse, *(*uintptr)(unsafe.Pointer(yymsp + 4)))
|
|
goto _350
|
|
_186:
|
|
; /* upsert ::= ON CONFLICT LP sortlist RP where_opt DO UPDATE SET setlist where_opt upsert */
|
|
*(*uintptr)(unsafe.Pointer(yymsp + uintptr(-libc.Int32FromInt32(11))*12 + 4)) = _sqlite3UpsertNew(tls, (*TParse)(unsafe.Pointer(pParse)).Fdb, *(*uintptr)(unsafe.Pointer(yymsp + uintptr(-libc.Int32FromInt32(8))*12 + 4)), *(*uintptr)(unsafe.Pointer(yymsp + uintptr(-libc.Int32FromInt32(6))*12 + 4)), *(*uintptr)(unsafe.Pointer(yymsp + uintptr(-libc.Int32FromInt32(2))*12 + 4)), *(*uintptr)(unsafe.Pointer(yymsp + uintptr(-libc.Int32FromInt32(1))*12 + 4)), *(*uintptr)(unsafe.Pointer(yymsp + 4)))
|
|
goto _350
|
|
_187:
|
|
; /* upsert ::= ON CONFLICT LP sortlist RP where_opt DO NOTHING upsert */
|
|
*(*uintptr)(unsafe.Pointer(yymsp + uintptr(-libc.Int32FromInt32(8))*12 + 4)) = _sqlite3UpsertNew(tls, (*TParse)(unsafe.Pointer(pParse)).Fdb, *(*uintptr)(unsafe.Pointer(yymsp + uintptr(-libc.Int32FromInt32(5))*12 + 4)), *(*uintptr)(unsafe.Pointer(yymsp + uintptr(-libc.Int32FromInt32(3))*12 + 4)), uintptr(0), uintptr(0), *(*uintptr)(unsafe.Pointer(yymsp + 4)))
|
|
goto _350
|
|
_188:
|
|
; /* upsert ::= ON CONFLICT DO NOTHING returning */
|
|
*(*uintptr)(unsafe.Pointer(yymsp + uintptr(-libc.Int32FromInt32(4))*12 + 4)) = _sqlite3UpsertNew(tls, (*TParse)(unsafe.Pointer(pParse)).Fdb, uintptr(0), uintptr(0), uintptr(0), uintptr(0), uintptr(0))
|
|
goto _350
|
|
_189:
|
|
; /* upsert ::= ON CONFLICT DO UPDATE SET setlist where_opt returning */
|
|
*(*uintptr)(unsafe.Pointer(yymsp + uintptr(-libc.Int32FromInt32(7))*12 + 4)) = _sqlite3UpsertNew(tls, (*TParse)(unsafe.Pointer(pParse)).Fdb, uintptr(0), uintptr(0), *(*uintptr)(unsafe.Pointer(yymsp + uintptr(-libc.Int32FromInt32(2))*12 + 4)), *(*uintptr)(unsafe.Pointer(yymsp + uintptr(-libc.Int32FromInt32(1))*12 + 4)), uintptr(0))
|
|
goto _350
|
|
_190:
|
|
; /* returning ::= RETURNING selcollist */
|
|
_sqlite3AddReturning(tls, pParse, *(*uintptr)(unsafe.Pointer(yymsp + 4)))
|
|
goto _350
|
|
_191:
|
|
; /* idlist_opt ::= */
|
|
*(*uintptr)(unsafe.Pointer(yymsp + 1*12 + 4)) = uintptr(0)
|
|
goto _350
|
|
_192:
|
|
; /* idlist_opt ::= LP idlist RP */
|
|
*(*uintptr)(unsafe.Pointer(yymsp + uintptr(-libc.Int32FromInt32(2))*12 + 4)) = *(*uintptr)(unsafe.Pointer(yymsp + uintptr(-libc.Int32FromInt32(1))*12 + 4))
|
|
goto _350
|
|
_193:
|
|
; /* idlist ::= idlist COMMA nm */
|
|
*(*uintptr)(unsafe.Pointer(yymsp + uintptr(-libc.Int32FromInt32(2))*12 + 4)) = _sqlite3IdListAppend(tls, pParse, *(*uintptr)(unsafe.Pointer(yymsp + uintptr(-libc.Int32FromInt32(2))*12 + 4)), yymsp+4)
|
|
goto _350
|
|
_194:
|
|
; /* idlist ::= nm */
|
|
*(*uintptr)(unsafe.Pointer(yymsp + 4)) = _sqlite3IdListAppend(tls, pParse, uintptr(0), yymsp+4) /*A-overwrites-Y*/
|
|
goto _350
|
|
_195:
|
|
; /* expr ::= LP expr RP */
|
|
*(*uintptr)(unsafe.Pointer(yymsp + uintptr(-libc.Int32FromInt32(2))*12 + 4)) = *(*uintptr)(unsafe.Pointer(yymsp + uintptr(-libc.Int32FromInt32(1))*12 + 4))
|
|
goto _350
|
|
_196:
|
|
; /* expr ::= ID|INDEXED|JOIN_KW */
|
|
*(*uintptr)(unsafe.Pointer(yymsp + 4)) = _tokenExpr(tls, pParse, int32(TK_ID), *(*TToken)(unsafe.Pointer(yymsp + 4))) /*A-overwrites-X*/
|
|
goto _350
|
|
_197:
|
|
; /* expr ::= nm DOT nm */
|
|
temp1 = _tokenExpr(tls, pParse, int32(TK_ID), *(*TToken)(unsafe.Pointer(yymsp + uintptr(-libc.Int32FromInt32(2))*12 + 4)))
|
|
temp2 = _tokenExpr(tls, pParse, int32(TK_ID), *(*TToken)(unsafe.Pointer(yymsp + 4)))
|
|
*(*uintptr)(unsafe.Pointer(&**(**TYYMINORTYPE)(__ccgo_up(bp)))) = _sqlite3PExpr(tls, pParse, int32(TK_DOT), temp1, temp2)
|
|
*(*uintptr)(unsafe.Pointer(yymsp + uintptr(-libc.Int32FromInt32(2))*12 + 4)) = *(*uintptr)(unsafe.Pointer(&**(**TYYMINORTYPE)(__ccgo_up(bp))))
|
|
goto _350
|
|
_198:
|
|
; /* expr ::= nm DOT nm DOT nm */
|
|
temp11 = _tokenExpr(tls, pParse, int32(TK_ID), *(*TToken)(unsafe.Pointer(yymsp + uintptr(-libc.Int32FromInt32(4))*12 + 4)))
|
|
temp21 = _tokenExpr(tls, pParse, int32(TK_ID), *(*TToken)(unsafe.Pointer(yymsp + uintptr(-libc.Int32FromInt32(2))*12 + 4)))
|
|
temp3 = _tokenExpr(tls, pParse, int32(TK_ID), *(*TToken)(unsafe.Pointer(yymsp + 4)))
|
|
temp4 = _sqlite3PExpr(tls, pParse, int32(TK_DOT), temp21, temp3)
|
|
if libc.Int32FromUint8((*TParse)(unsafe.Pointer(pParse)).FeParseMode) >= int32(PARSE_MODE_RENAME) {
|
|
_sqlite3RenameTokenRemap(tls, pParse, uintptr(0), temp11)
|
|
}
|
|
*(*uintptr)(unsafe.Pointer(&**(**TYYMINORTYPE)(__ccgo_up(bp)))) = _sqlite3PExpr(tls, pParse, int32(TK_DOT), temp11, temp4)
|
|
*(*uintptr)(unsafe.Pointer(yymsp + uintptr(-libc.Int32FromInt32(4))*12 + 4)) = *(*uintptr)(unsafe.Pointer(&**(**TYYMINORTYPE)(__ccgo_up(bp))))
|
|
goto _350
|
|
_200:
|
|
; /* term ::= NULL|FLOAT|BLOB */
|
|
_199:
|
|
;
|
|
*(*uintptr)(unsafe.Pointer(yymsp + 4)) = _tokenExpr(tls, pParse, libc.Int32FromUint16((**(**TyyStackEntry)(__ccgo_up(yymsp))).Fmajor), *(*TToken)(unsafe.Pointer(yymsp + 4))) /*A-overwrites-X*/
|
|
goto _350
|
|
_201:
|
|
; /* term ::= INTEGER */
|
|
if _sqlite3GetInt32(tls, *(*uintptr)(unsafe.Pointer(yymsp + 4)), bp+56) == 0 {
|
|
*(*uintptr)(unsafe.Pointer(&**(**TYYMINORTYPE)(__ccgo_up(bp)))) = _sqlite3ExprAlloc(tls, (*TParse)(unsafe.Pointer(pParse)).Fdb, int32(TK_INTEGER), yymsp+4, 0)
|
|
} else {
|
|
*(*uintptr)(unsafe.Pointer(&**(**TYYMINORTYPE)(__ccgo_up(bp)))) = _sqlite3ExprInt32(tls, (*TParse)(unsafe.Pointer(pParse)).Fdb, **(**int32)(__ccgo_up(bp + 56)))
|
|
}
|
|
if *(*uintptr)(unsafe.Pointer(&**(**TYYMINORTYPE)(__ccgo_up(bp)))) != 0 {
|
|
*(*int32)(unsafe.Pointer(*(*uintptr)(unsafe.Pointer(&**(**TYYMINORTYPE)(__ccgo_up(bp)))) + 36)) = int32(*(*uintptr)(unsafe.Pointer(yymsp + 4))) - int32((*TParse)(unsafe.Pointer(pParse)).FzTail)
|
|
}
|
|
*(*uintptr)(unsafe.Pointer(yymsp + 4)) = *(*uintptr)(unsafe.Pointer(&**(**TYYMINORTYPE)(__ccgo_up(bp))))
|
|
goto _350
|
|
_202:
|
|
; /* expr ::= VARIABLE */
|
|
if !(int32(**(**int8)(__ccgo_up(*(*uintptr)(unsafe.Pointer(yymsp + 4))))) == int32('#') && libc.Int32FromUint8(_sqlite3CtypeMap[libc.Uint8FromInt8(**(**int8)(__ccgo_up(*(*uintptr)(unsafe.Pointer(yymsp + 4)) + 1)))])&int32(0x04) != 0) {
|
|
n = *(*uint32)(unsafe.Pointer(yymsp + 4 + 4))
|
|
*(*uintptr)(unsafe.Pointer(yymsp + 4)) = _tokenExpr(tls, pParse, int32(TK_VARIABLE), *(*TToken)(unsafe.Pointer(yymsp + 4)))
|
|
_sqlite3ExprAssignVarNumber(tls, pParse, *(*uintptr)(unsafe.Pointer(yymsp + 4)), n)
|
|
} else {
|
|
/* When doing a nested parse, one can include terms in an expression
|
|
** that look like this: #1 #2 ... These terms refer to registers
|
|
** in the virtual machine. #N is the N-th register. */
|
|
**(**TToken)(__ccgo_up(bp + 64)) = *(*TToken)(unsafe.Pointer(yymsp + 4)) /*A-overwrites-X*/
|
|
if libc.Int32FromUint8((*TParse)(unsafe.Pointer(pParse)).Fnested) == 0 {
|
|
_parserSyntaxError(tls, pParse, bp+64)
|
|
*(*uintptr)(unsafe.Pointer(yymsp + 4)) = uintptr(0)
|
|
} else {
|
|
*(*uintptr)(unsafe.Pointer(yymsp + 4)) = _sqlite3PExpr(tls, pParse, int32(TK_REGISTER), uintptr(0), uintptr(0))
|
|
if *(*uintptr)(unsafe.Pointer(yymsp + 4)) != 0 {
|
|
_sqlite3GetInt32(tls, (**(**TToken)(__ccgo_up(bp + 64))).Fz+1, *(*uintptr)(unsafe.Pointer(yymsp + 4))+28)
|
|
}
|
|
}
|
|
}
|
|
goto _350
|
|
_203:
|
|
; /* expr ::= expr COLLATE ID|STRING */
|
|
*(*uintptr)(unsafe.Pointer(yymsp + uintptr(-libc.Int32FromInt32(2))*12 + 4)) = _sqlite3ExprAddCollateToken(tls, pParse, *(*uintptr)(unsafe.Pointer(yymsp + uintptr(-libc.Int32FromInt32(2))*12 + 4)), yymsp+4, int32(1))
|
|
goto _350
|
|
_204:
|
|
; /* expr ::= CAST LP expr AS typetoken RP */
|
|
*(*uintptr)(unsafe.Pointer(yymsp + uintptr(-libc.Int32FromInt32(5))*12 + 4)) = _sqlite3ExprAlloc(tls, (*TParse)(unsafe.Pointer(pParse)).Fdb, int32(TK_CAST), yymsp+uintptr(-libc.Int32FromInt32(1))*12+4, int32(1))
|
|
_sqlite3ExprAttachSubtrees(tls, (*TParse)(unsafe.Pointer(pParse)).Fdb, *(*uintptr)(unsafe.Pointer(yymsp + uintptr(-libc.Int32FromInt32(5))*12 + 4)), *(*uintptr)(unsafe.Pointer(yymsp + uintptr(-libc.Int32FromInt32(3))*12 + 4)), uintptr(0))
|
|
goto _350
|
|
_205:
|
|
; /* expr ::= ID|INDEXED|JOIN_KW LP distinct exprlist RP */
|
|
*(*uintptr)(unsafe.Pointer(&**(**TYYMINORTYPE)(__ccgo_up(bp)))) = _sqlite3ExprFunction(tls, pParse, *(*uintptr)(unsafe.Pointer(yymsp + uintptr(-libc.Int32FromInt32(1))*12 + 4)), yymsp+uintptr(-libc.Int32FromInt32(4))*12+4, *(*int32)(unsafe.Pointer(yymsp + uintptr(-libc.Int32FromInt32(2))*12 + 4)))
|
|
*(*uintptr)(unsafe.Pointer(yymsp + uintptr(-libc.Int32FromInt32(4))*12 + 4)) = *(*uintptr)(unsafe.Pointer(&**(**TYYMINORTYPE)(__ccgo_up(bp))))
|
|
goto _350
|
|
_206:
|
|
; /* expr ::= ID|INDEXED|JOIN_KW LP distinct exprlist ORDER BY sortlist RP */
|
|
*(*uintptr)(unsafe.Pointer(&**(**TYYMINORTYPE)(__ccgo_up(bp)))) = _sqlite3ExprFunction(tls, pParse, *(*uintptr)(unsafe.Pointer(yymsp + uintptr(-libc.Int32FromInt32(4))*12 + 4)), yymsp+uintptr(-libc.Int32FromInt32(7))*12+4, *(*int32)(unsafe.Pointer(yymsp + uintptr(-libc.Int32FromInt32(5))*12 + 4)))
|
|
_sqlite3ExprAddFunctionOrderBy(tls, pParse, *(*uintptr)(unsafe.Pointer(&**(**TYYMINORTYPE)(__ccgo_up(bp)))), *(*uintptr)(unsafe.Pointer(yymsp + uintptr(-libc.Int32FromInt32(1))*12 + 4)))
|
|
*(*uintptr)(unsafe.Pointer(yymsp + uintptr(-libc.Int32FromInt32(7))*12 + 4)) = *(*uintptr)(unsafe.Pointer(&**(**TYYMINORTYPE)(__ccgo_up(bp))))
|
|
goto _350
|
|
_207:
|
|
; /* expr ::= ID|INDEXED|JOIN_KW LP STAR RP */
|
|
*(*uintptr)(unsafe.Pointer(&**(**TYYMINORTYPE)(__ccgo_up(bp)))) = _sqlite3ExprFunction(tls, pParse, uintptr(0), yymsp+uintptr(-libc.Int32FromInt32(3))*12+4, 0)
|
|
*(*uintptr)(unsafe.Pointer(yymsp + uintptr(-libc.Int32FromInt32(3))*12 + 4)) = *(*uintptr)(unsafe.Pointer(&**(**TYYMINORTYPE)(__ccgo_up(bp))))
|
|
goto _350
|
|
_208:
|
|
; /* expr ::= ID|INDEXED|JOIN_KW LP distinct exprlist RP filter_over */
|
|
*(*uintptr)(unsafe.Pointer(&**(**TYYMINORTYPE)(__ccgo_up(bp)))) = _sqlite3ExprFunction(tls, pParse, *(*uintptr)(unsafe.Pointer(yymsp + uintptr(-libc.Int32FromInt32(2))*12 + 4)), yymsp+uintptr(-libc.Int32FromInt32(5))*12+4, *(*int32)(unsafe.Pointer(yymsp + uintptr(-libc.Int32FromInt32(3))*12 + 4)))
|
|
_sqlite3WindowAttach(tls, pParse, *(*uintptr)(unsafe.Pointer(&**(**TYYMINORTYPE)(__ccgo_up(bp)))), *(*uintptr)(unsafe.Pointer(yymsp + 4)))
|
|
*(*uintptr)(unsafe.Pointer(yymsp + uintptr(-libc.Int32FromInt32(5))*12 + 4)) = *(*uintptr)(unsafe.Pointer(&**(**TYYMINORTYPE)(__ccgo_up(bp))))
|
|
goto _350
|
|
_209:
|
|
; /* expr ::= ID|INDEXED|JOIN_KW LP distinct exprlist ORDER BY sortlist RP filter_over */
|
|
*(*uintptr)(unsafe.Pointer(&**(**TYYMINORTYPE)(__ccgo_up(bp)))) = _sqlite3ExprFunction(tls, pParse, *(*uintptr)(unsafe.Pointer(yymsp + uintptr(-libc.Int32FromInt32(5))*12 + 4)), yymsp+uintptr(-libc.Int32FromInt32(8))*12+4, *(*int32)(unsafe.Pointer(yymsp + uintptr(-libc.Int32FromInt32(6))*12 + 4)))
|
|
_sqlite3WindowAttach(tls, pParse, *(*uintptr)(unsafe.Pointer(&**(**TYYMINORTYPE)(__ccgo_up(bp)))), *(*uintptr)(unsafe.Pointer(yymsp + 4)))
|
|
_sqlite3ExprAddFunctionOrderBy(tls, pParse, *(*uintptr)(unsafe.Pointer(&**(**TYYMINORTYPE)(__ccgo_up(bp)))), *(*uintptr)(unsafe.Pointer(yymsp + uintptr(-libc.Int32FromInt32(2))*12 + 4)))
|
|
*(*uintptr)(unsafe.Pointer(yymsp + uintptr(-libc.Int32FromInt32(8))*12 + 4)) = *(*uintptr)(unsafe.Pointer(&**(**TYYMINORTYPE)(__ccgo_up(bp))))
|
|
goto _350
|
|
_210:
|
|
; /* expr ::= ID|INDEXED|JOIN_KW LP STAR RP filter_over */
|
|
*(*uintptr)(unsafe.Pointer(&**(**TYYMINORTYPE)(__ccgo_up(bp)))) = _sqlite3ExprFunction(tls, pParse, uintptr(0), yymsp+uintptr(-libc.Int32FromInt32(4))*12+4, 0)
|
|
_sqlite3WindowAttach(tls, pParse, *(*uintptr)(unsafe.Pointer(&**(**TYYMINORTYPE)(__ccgo_up(bp)))), *(*uintptr)(unsafe.Pointer(yymsp + 4)))
|
|
*(*uintptr)(unsafe.Pointer(yymsp + uintptr(-libc.Int32FromInt32(4))*12 + 4)) = *(*uintptr)(unsafe.Pointer(&**(**TYYMINORTYPE)(__ccgo_up(bp))))
|
|
goto _350
|
|
_211:
|
|
; /* term ::= CTIME_KW */
|
|
*(*uintptr)(unsafe.Pointer(&**(**TYYMINORTYPE)(__ccgo_up(bp)))) = _sqlite3ExprFunction(tls, pParse, uintptr(0), yymsp+4, 0)
|
|
*(*uintptr)(unsafe.Pointer(yymsp + 4)) = *(*uintptr)(unsafe.Pointer(&**(**TYYMINORTYPE)(__ccgo_up(bp))))
|
|
goto _350
|
|
_212:
|
|
; /* expr ::= LP nexprlist COMMA expr RP */
|
|
pList = _sqlite3ExprListAppend(tls, pParse, *(*uintptr)(unsafe.Pointer(yymsp + uintptr(-libc.Int32FromInt32(3))*12 + 4)), *(*uintptr)(unsafe.Pointer(yymsp + uintptr(-libc.Int32FromInt32(1))*12 + 4)))
|
|
*(*uintptr)(unsafe.Pointer(yymsp + uintptr(-libc.Int32FromInt32(4))*12 + 4)) = _sqlite3PExpr(tls, pParse, int32(TK_VECTOR), uintptr(0), uintptr(0))
|
|
if *(*uintptr)(unsafe.Pointer(yymsp + uintptr(-libc.Int32FromInt32(4))*12 + 4)) != 0 {
|
|
*(*uintptr)(unsafe.Pointer(*(*uintptr)(unsafe.Pointer(yymsp + uintptr(-libc.Int32FromInt32(4))*12 + 4)) + 20)) = pList
|
|
i = 0
|
|
for {
|
|
if !(i < (*TExprList)(unsafe.Pointer(pList)).FnExpr) {
|
|
break
|
|
}
|
|
**(**Tu32)(__ccgo_up(*(*uintptr)(unsafe.Pointer(yymsp + uintptr(-libc.Int32FromInt32(4))*12 + 4)) + 4)) |= (*TExpr)(unsafe.Pointer((*(*TExprList_item)(unsafe.Pointer(pList + 8 + uintptr(i)*20))).FpExpr)).Fflags & libc.Uint32FromInt32(libc.Int32FromInt32(EP_Collate)|libc.Int32FromInt32(EP_Subquery)|libc.Int32FromInt32(EP_HasFunc))
|
|
goto _351
|
|
_351:
|
|
;
|
|
i = i + 1
|
|
}
|
|
} else {
|
|
_sqlite3ExprListDelete(tls, (*TParse)(unsafe.Pointer(pParse)).Fdb, pList)
|
|
}
|
|
goto _350
|
|
_213:
|
|
; /* expr ::= expr AND expr */
|
|
*(*uintptr)(unsafe.Pointer(yymsp + uintptr(-libc.Int32FromInt32(2))*12 + 4)) = _sqlite3ExprAnd(tls, pParse, *(*uintptr)(unsafe.Pointer(yymsp + uintptr(-libc.Int32FromInt32(2))*12 + 4)), *(*uintptr)(unsafe.Pointer(yymsp + 4)))
|
|
goto _350
|
|
_215:
|
|
; /* expr ::= expr OR expr */
|
|
_214:
|
|
;
|
|
_216:
|
|
;
|
|
_217:
|
|
;
|
|
_218:
|
|
;
|
|
_219:
|
|
;
|
|
_220:
|
|
;
|
|
*(*uintptr)(unsafe.Pointer(yymsp + uintptr(-libc.Int32FromInt32(2))*12 + 4)) = _sqlite3PExpr(tls, pParse, libc.Int32FromUint16((**(**TyyStackEntry)(__ccgo_up(yymsp + uintptr(-libc.Int32FromInt32(1))*12))).Fmajor), *(*uintptr)(unsafe.Pointer(yymsp + uintptr(-libc.Int32FromInt32(2))*12 + 4)), *(*uintptr)(unsafe.Pointer(yymsp + 4)))
|
|
goto _350
|
|
_221:
|
|
; /* likeop ::= NOT LIKE_KW|MATCH */
|
|
*(*TToken)(unsafe.Pointer(yymsp + uintptr(-libc.Int32FromInt32(1))*12 + 4)) = *(*TToken)(unsafe.Pointer(yymsp + 4))
|
|
*(*uint32)(unsafe.Pointer(yymsp + uintptr(-libc.Int32FromInt32(1))*12 + 4 + 4)) |= uint32(0x80000000) /*yymsp[-1].minor.yy0-overwrite-yymsp[0].minor.yy0*/
|
|
goto _350
|
|
_222:
|
|
; /* expr ::= expr likeop expr */
|
|
bNot = libc.Int32FromUint32(*(*uint32)(unsafe.Pointer(yymsp + uintptr(-libc.Int32FromInt32(1))*12 + 4 + 4)) & uint32(0x80000000))
|
|
*(*uint32)(unsafe.Pointer(yymsp + uintptr(-libc.Int32FromInt32(1))*12 + 4 + 4)) &= uint32(0x7fffffff)
|
|
pList1 = _sqlite3ExprListAppend(tls, pParse, uintptr(0), *(*uintptr)(unsafe.Pointer(yymsp + 4)))
|
|
pList1 = _sqlite3ExprListAppend(tls, pParse, pList1, *(*uintptr)(unsafe.Pointer(yymsp + uintptr(-libc.Int32FromInt32(2))*12 + 4)))
|
|
*(*uintptr)(unsafe.Pointer(yymsp + uintptr(-libc.Int32FromInt32(2))*12 + 4)) = _sqlite3ExprFunction(tls, pParse, pList1, yymsp+uintptr(-libc.Int32FromInt32(1))*12+4, 0)
|
|
if bNot != 0 {
|
|
*(*uintptr)(unsafe.Pointer(yymsp + uintptr(-libc.Int32FromInt32(2))*12 + 4)) = _sqlite3PExpr(tls, pParse, int32(TK_NOT), *(*uintptr)(unsafe.Pointer(yymsp + uintptr(-libc.Int32FromInt32(2))*12 + 4)), uintptr(0))
|
|
}
|
|
if *(*uintptr)(unsafe.Pointer(yymsp + uintptr(-libc.Int32FromInt32(2))*12 + 4)) != 0 {
|
|
**(**Tu32)(__ccgo_up(*(*uintptr)(unsafe.Pointer(yymsp + uintptr(-libc.Int32FromInt32(2))*12 + 4)) + 4)) |= uint32(EP_InfixFunc)
|
|
}
|
|
goto _350
|
|
_223:
|
|
; /* expr ::= expr likeop expr ESCAPE expr */
|
|
bNot1 = libc.Int32FromUint32(*(*uint32)(unsafe.Pointer(yymsp + uintptr(-libc.Int32FromInt32(3))*12 + 4 + 4)) & uint32(0x80000000))
|
|
*(*uint32)(unsafe.Pointer(yymsp + uintptr(-libc.Int32FromInt32(3))*12 + 4 + 4)) &= uint32(0x7fffffff)
|
|
pList2 = _sqlite3ExprListAppend(tls, pParse, uintptr(0), *(*uintptr)(unsafe.Pointer(yymsp + uintptr(-libc.Int32FromInt32(2))*12 + 4)))
|
|
pList2 = _sqlite3ExprListAppend(tls, pParse, pList2, *(*uintptr)(unsafe.Pointer(yymsp + uintptr(-libc.Int32FromInt32(4))*12 + 4)))
|
|
pList2 = _sqlite3ExprListAppend(tls, pParse, pList2, *(*uintptr)(unsafe.Pointer(yymsp + 4)))
|
|
*(*uintptr)(unsafe.Pointer(yymsp + uintptr(-libc.Int32FromInt32(4))*12 + 4)) = _sqlite3ExprFunction(tls, pParse, pList2, yymsp+uintptr(-libc.Int32FromInt32(3))*12+4, 0)
|
|
if bNot1 != 0 {
|
|
*(*uintptr)(unsafe.Pointer(yymsp + uintptr(-libc.Int32FromInt32(4))*12 + 4)) = _sqlite3PExpr(tls, pParse, int32(TK_NOT), *(*uintptr)(unsafe.Pointer(yymsp + uintptr(-libc.Int32FromInt32(4))*12 + 4)), uintptr(0))
|
|
}
|
|
if *(*uintptr)(unsafe.Pointer(yymsp + uintptr(-libc.Int32FromInt32(4))*12 + 4)) != 0 {
|
|
**(**Tu32)(__ccgo_up(*(*uintptr)(unsafe.Pointer(yymsp + uintptr(-libc.Int32FromInt32(4))*12 + 4)) + 4)) |= uint32(EP_InfixFunc)
|
|
}
|
|
goto _350
|
|
_224:
|
|
; /* expr ::= expr ISNULL|NOTNULL */
|
|
*(*uintptr)(unsafe.Pointer(yymsp + uintptr(-libc.Int32FromInt32(1))*12 + 4)) = _sqlite3PExprIsNull(tls, pParse, libc.Int32FromUint16((**(**TyyStackEntry)(__ccgo_up(yymsp))).Fmajor), *(*uintptr)(unsafe.Pointer(yymsp + uintptr(-libc.Int32FromInt32(1))*12 + 4)))
|
|
goto _350
|
|
_225:
|
|
; /* expr ::= expr NOT NULL */
|
|
*(*uintptr)(unsafe.Pointer(yymsp + uintptr(-libc.Int32FromInt32(2))*12 + 4)) = _sqlite3PExprIsNull(tls, pParse, int32(TK_NOTNULL), *(*uintptr)(unsafe.Pointer(yymsp + uintptr(-libc.Int32FromInt32(2))*12 + 4)))
|
|
goto _350
|
|
_226:
|
|
; /* expr ::= expr IS expr */
|
|
*(*uintptr)(unsafe.Pointer(yymsp + uintptr(-libc.Int32FromInt32(2))*12 + 4)) = _sqlite3PExprIs(tls, pParse, int32(TK_IS), *(*uintptr)(unsafe.Pointer(yymsp + uintptr(-libc.Int32FromInt32(2))*12 + 4)), *(*uintptr)(unsafe.Pointer(yymsp + 4)))
|
|
goto _350
|
|
_227:
|
|
; /* expr ::= expr IS NOT expr */
|
|
*(*uintptr)(unsafe.Pointer(yymsp + uintptr(-libc.Int32FromInt32(3))*12 + 4)) = _sqlite3PExprIs(tls, pParse, int32(TK_ISNOT), *(*uintptr)(unsafe.Pointer(yymsp + uintptr(-libc.Int32FromInt32(3))*12 + 4)), *(*uintptr)(unsafe.Pointer(yymsp + 4)))
|
|
goto _350
|
|
_228:
|
|
; /* expr ::= expr IS NOT DISTINCT FROM expr */
|
|
*(*uintptr)(unsafe.Pointer(yymsp + uintptr(-libc.Int32FromInt32(5))*12 + 4)) = _sqlite3PExprIs(tls, pParse, int32(TK_IS), *(*uintptr)(unsafe.Pointer(yymsp + uintptr(-libc.Int32FromInt32(5))*12 + 4)), *(*uintptr)(unsafe.Pointer(yymsp + 4)))
|
|
goto _350
|
|
_229:
|
|
; /* expr ::= expr IS DISTINCT FROM expr */
|
|
*(*uintptr)(unsafe.Pointer(yymsp + uintptr(-libc.Int32FromInt32(4))*12 + 4)) = _sqlite3PExprIs(tls, pParse, int32(TK_ISNOT), *(*uintptr)(unsafe.Pointer(yymsp + uintptr(-libc.Int32FromInt32(4))*12 + 4)), *(*uintptr)(unsafe.Pointer(yymsp + 4)))
|
|
goto _350
|
|
_231:
|
|
; /* expr ::= NOT expr */
|
|
_230:
|
|
;
|
|
*(*uintptr)(unsafe.Pointer(yymsp + uintptr(-libc.Int32FromInt32(1))*12 + 4)) = _sqlite3PExpr(tls, pParse, libc.Int32FromUint16((**(**TyyStackEntry)(__ccgo_up(yymsp + uintptr(-libc.Int32FromInt32(1))*12))).Fmajor), *(*uintptr)(unsafe.Pointer(yymsp + 4)), uintptr(0)) /*A-overwrites-B*/
|
|
goto _350
|
|
_232:
|
|
; /* expr ::= PLUS|MINUS expr */
|
|
p4 = *(*uintptr)(unsafe.Pointer(yymsp + 4))
|
|
op = libc.Uint8FromInt32(libc.Int32FromUint16((**(**TyyStackEntry)(__ccgo_up(yymsp + uintptr(-libc.Int32FromInt32(1))*12))).Fmajor) + (libc.Int32FromInt32(TK_UPLUS) - libc.Int32FromInt32(TK_PLUS)))
|
|
if p4 != 0 && libc.Int32FromUint8((*TExpr)(unsafe.Pointer(p4)).Fop) == int32(TK_UPLUS) {
|
|
(*TExpr)(unsafe.Pointer(p4)).Fop = op
|
|
*(*uintptr)(unsafe.Pointer(yymsp + uintptr(-libc.Int32FromInt32(1))*12 + 4)) = p4
|
|
} else {
|
|
*(*uintptr)(unsafe.Pointer(yymsp + uintptr(-libc.Int32FromInt32(1))*12 + 4)) = _sqlite3PExpr(tls, pParse, libc.Int32FromUint8(op), p4, uintptr(0))
|
|
/*A-overwrites-B*/
|
|
}
|
|
goto _350
|
|
_233:
|
|
; /* expr ::= expr PTR expr */
|
|
pList3 = _sqlite3ExprListAppend(tls, pParse, uintptr(0), *(*uintptr)(unsafe.Pointer(yymsp + uintptr(-libc.Int32FromInt32(2))*12 + 4)))
|
|
pList3 = _sqlite3ExprListAppend(tls, pParse, pList3, *(*uintptr)(unsafe.Pointer(yymsp + 4)))
|
|
*(*uintptr)(unsafe.Pointer(&**(**TYYMINORTYPE)(__ccgo_up(bp)))) = _sqlite3ExprFunction(tls, pParse, pList3, yymsp+uintptr(-libc.Int32FromInt32(1))*12+4, 0)
|
|
*(*uintptr)(unsafe.Pointer(yymsp + uintptr(-libc.Int32FromInt32(2))*12 + 4)) = *(*uintptr)(unsafe.Pointer(&**(**TYYMINORTYPE)(__ccgo_up(bp))))
|
|
goto _350
|
|
_235:
|
|
; /* between_op ::= BETWEEN */
|
|
_234:
|
|
;
|
|
*(*int32)(unsafe.Pointer(yymsp + 4)) = 0
|
|
goto _350
|
|
_236:
|
|
; /* expr ::= expr between_op expr AND expr */
|
|
pList4 = _sqlite3ExprListAppend(tls, pParse, uintptr(0), *(*uintptr)(unsafe.Pointer(yymsp + uintptr(-libc.Int32FromInt32(2))*12 + 4)))
|
|
pList4 = _sqlite3ExprListAppend(tls, pParse, pList4, *(*uintptr)(unsafe.Pointer(yymsp + 4)))
|
|
*(*uintptr)(unsafe.Pointer(yymsp + uintptr(-libc.Int32FromInt32(4))*12 + 4)) = _sqlite3PExpr(tls, pParse, int32(TK_BETWEEN), *(*uintptr)(unsafe.Pointer(yymsp + uintptr(-libc.Int32FromInt32(4))*12 + 4)), uintptr(0))
|
|
if *(*uintptr)(unsafe.Pointer(yymsp + uintptr(-libc.Int32FromInt32(4))*12 + 4)) != 0 {
|
|
*(*uintptr)(unsafe.Pointer(*(*uintptr)(unsafe.Pointer(yymsp + uintptr(-libc.Int32FromInt32(4))*12 + 4)) + 20)) = pList4
|
|
_sqlite3ExprSetHeightAndFlags(tls, pParse, *(*uintptr)(unsafe.Pointer(yymsp + uintptr(-libc.Int32FromInt32(4))*12 + 4)))
|
|
} else {
|
|
_sqlite3ExprListDelete(tls, (*TParse)(unsafe.Pointer(pParse)).Fdb, pList4)
|
|
}
|
|
if *(*int32)(unsafe.Pointer(yymsp + uintptr(-libc.Int32FromInt32(3))*12 + 4)) != 0 {
|
|
*(*uintptr)(unsafe.Pointer(yymsp + uintptr(-libc.Int32FromInt32(4))*12 + 4)) = _sqlite3PExpr(tls, pParse, int32(TK_NOT), *(*uintptr)(unsafe.Pointer(yymsp + uintptr(-libc.Int32FromInt32(4))*12 + 4)), uintptr(0))
|
|
}
|
|
goto _350
|
|
_237:
|
|
; /* expr ::= expr in_op LP exprlist RP */
|
|
if *(*uintptr)(unsafe.Pointer(yymsp + uintptr(-libc.Int32FromInt32(1))*12 + 4)) == uintptr(0) {
|
|
if *(*int32)(unsafe.Pointer(yymsp + uintptr(-libc.Int32FromInt32(3))*12 + 4)) != 0 {
|
|
v352 = __ccgo_ts + 8180
|
|
} else {
|
|
v352 = __ccgo_ts + 8185
|
|
}
|
|
/* Expressions of the form
|
|
**
|
|
** expr1 IN ()
|
|
** expr1 NOT IN ()
|
|
**
|
|
** simplify to constants 0 (false) and 1 (true), respectively.
|
|
**
|
|
** Except, do not apply this optimization if expr1 contains a function
|
|
** because that function might be an aggregate (we don't know yet whether
|
|
** it is or not) and if it is an aggregate, that could change the meaning
|
|
** of the whole query.
|
|
*/
|
|
pB = _sqlite3Expr(tls, (*TParse)(unsafe.Pointer(pParse)).Fdb, int32(TK_STRING), v352)
|
|
if pB != 0 {
|
|
_sqlite3ExprIdToTrueFalse(tls, pB)
|
|
}
|
|
if !((*TExpr)(unsafe.Pointer(*(*uintptr)(unsafe.Pointer(yymsp + uintptr(-libc.Int32FromInt32(4))*12 + 4)))).Fflags&libc.Uint32FromInt32(libc.Int32FromInt32(EP_HasFunc)) != libc.Uint32FromInt32(0)) {
|
|
_sqlite3ExprUnmapAndDelete(tls, pParse, *(*uintptr)(unsafe.Pointer(yymsp + uintptr(-libc.Int32FromInt32(4))*12 + 4)))
|
|
*(*uintptr)(unsafe.Pointer(yymsp + uintptr(-libc.Int32FromInt32(4))*12 + 4)) = pB
|
|
} else {
|
|
if *(*int32)(unsafe.Pointer(yymsp + uintptr(-libc.Int32FromInt32(3))*12 + 4)) != 0 {
|
|
v353 = int32(TK_OR)
|
|
} else {
|
|
v353 = int32(TK_AND)
|
|
}
|
|
*(*uintptr)(unsafe.Pointer(yymsp + uintptr(-libc.Int32FromInt32(4))*12 + 4)) = _sqlite3PExpr(tls, pParse, v353, pB, *(*uintptr)(unsafe.Pointer(yymsp + uintptr(-libc.Int32FromInt32(4))*12 + 4)))
|
|
}
|
|
} else {
|
|
pRHS = (*(*TExprList_item)(unsafe.Pointer(*(*uintptr)(unsafe.Pointer(yymsp + uintptr(-libc.Int32FromInt32(1))*12 + 4)) + 8))).FpExpr
|
|
if (*TExprList)(unsafe.Pointer(*(*uintptr)(unsafe.Pointer(yymsp + uintptr(-libc.Int32FromInt32(1))*12 + 4)))).FnExpr == int32(1) && _sqlite3ExprIsConstant(tls, pParse, pRHS) != 0 && libc.Int32FromUint8((*TExpr)(unsafe.Pointer(*(*uintptr)(unsafe.Pointer(yymsp + uintptr(-libc.Int32FromInt32(4))*12 + 4)))).Fop) != int32(TK_VECTOR) {
|
|
(*(*TExprList_item)(unsafe.Pointer(*(*uintptr)(unsafe.Pointer(yymsp + uintptr(-libc.Int32FromInt32(1))*12 + 4)) + 8))).FpExpr = uintptr(0)
|
|
_sqlite3ExprListDelete(tls, (*TParse)(unsafe.Pointer(pParse)).Fdb, *(*uintptr)(unsafe.Pointer(yymsp + uintptr(-libc.Int32FromInt32(1))*12 + 4)))
|
|
pRHS = _sqlite3PExpr(tls, pParse, int32(TK_UPLUS), pRHS, uintptr(0))
|
|
*(*uintptr)(unsafe.Pointer(yymsp + uintptr(-libc.Int32FromInt32(4))*12 + 4)) = _sqlite3PExpr(tls, pParse, int32(TK_EQ), *(*uintptr)(unsafe.Pointer(yymsp + uintptr(-libc.Int32FromInt32(4))*12 + 4)), pRHS)
|
|
} else {
|
|
if (*TExprList)(unsafe.Pointer(*(*uintptr)(unsafe.Pointer(yymsp + uintptr(-libc.Int32FromInt32(1))*12 + 4)))).FnExpr == int32(1) && libc.Int32FromUint8((*TExpr)(unsafe.Pointer(pRHS)).Fop) == int32(TK_SELECT) {
|
|
*(*uintptr)(unsafe.Pointer(yymsp + uintptr(-libc.Int32FromInt32(4))*12 + 4)) = _sqlite3PExpr(tls, pParse, int32(TK_IN), *(*uintptr)(unsafe.Pointer(yymsp + uintptr(-libc.Int32FromInt32(4))*12 + 4)), uintptr(0))
|
|
_sqlite3PExprAddSelect(tls, pParse, *(*uintptr)(unsafe.Pointer(yymsp + uintptr(-libc.Int32FromInt32(4))*12 + 4)), *(*uintptr)(unsafe.Pointer(pRHS + 20)))
|
|
*(*uintptr)(unsafe.Pointer(pRHS + 20)) = uintptr(0)
|
|
_sqlite3ExprListDelete(tls, (*TParse)(unsafe.Pointer(pParse)).Fdb, *(*uintptr)(unsafe.Pointer(yymsp + uintptr(-libc.Int32FromInt32(1))*12 + 4)))
|
|
} else {
|
|
*(*uintptr)(unsafe.Pointer(yymsp + uintptr(-libc.Int32FromInt32(4))*12 + 4)) = _sqlite3PExpr(tls, pParse, int32(TK_IN), *(*uintptr)(unsafe.Pointer(yymsp + uintptr(-libc.Int32FromInt32(4))*12 + 4)), uintptr(0))
|
|
if *(*uintptr)(unsafe.Pointer(yymsp + uintptr(-libc.Int32FromInt32(4))*12 + 4)) == uintptr(0) {
|
|
_sqlite3ExprListDelete(tls, (*TParse)(unsafe.Pointer(pParse)).Fdb, *(*uintptr)(unsafe.Pointer(yymsp + uintptr(-libc.Int32FromInt32(1))*12 + 4)))
|
|
} else {
|
|
if libc.Int32FromUint8((*TExpr)(unsafe.Pointer((*TExpr)(unsafe.Pointer(*(*uintptr)(unsafe.Pointer(yymsp + uintptr(-libc.Int32FromInt32(4))*12 + 4)))).FpLeft)).Fop) == int32(TK_VECTOR) {
|
|
nExpr = (*TExprList)(unsafe.Pointer(*(*uintptr)(unsafe.Pointer((*TExpr)(unsafe.Pointer(*(*uintptr)(unsafe.Pointer(yymsp + uintptr(-libc.Int32FromInt32(4))*12 + 4)))).FpLeft + 20)))).FnExpr
|
|
pSelectRHS = _sqlite3ExprListToValues(tls, pParse, nExpr, *(*uintptr)(unsafe.Pointer(yymsp + uintptr(-libc.Int32FromInt32(1))*12 + 4)))
|
|
if pSelectRHS != 0 {
|
|
_parserDoubleLinkSelect(tls, pParse, pSelectRHS)
|
|
_sqlite3PExprAddSelect(tls, pParse, *(*uintptr)(unsafe.Pointer(yymsp + uintptr(-libc.Int32FromInt32(4))*12 + 4)), pSelectRHS)
|
|
}
|
|
} else {
|
|
*(*uintptr)(unsafe.Pointer(*(*uintptr)(unsafe.Pointer(yymsp + uintptr(-libc.Int32FromInt32(4))*12 + 4)) + 20)) = *(*uintptr)(unsafe.Pointer(yymsp + uintptr(-libc.Int32FromInt32(1))*12 + 4))
|
|
_sqlite3ExprSetHeightAndFlags(tls, pParse, *(*uintptr)(unsafe.Pointer(yymsp + uintptr(-libc.Int32FromInt32(4))*12 + 4)))
|
|
}
|
|
}
|
|
}
|
|
}
|
|
if *(*int32)(unsafe.Pointer(yymsp + uintptr(-libc.Int32FromInt32(3))*12 + 4)) != 0 {
|
|
*(*uintptr)(unsafe.Pointer(yymsp + uintptr(-libc.Int32FromInt32(4))*12 + 4)) = _sqlite3PExpr(tls, pParse, int32(TK_NOT), *(*uintptr)(unsafe.Pointer(yymsp + uintptr(-libc.Int32FromInt32(4))*12 + 4)), uintptr(0))
|
|
}
|
|
}
|
|
goto _350
|
|
_238:
|
|
; /* expr ::= LP select RP */
|
|
*(*uintptr)(unsafe.Pointer(yymsp + uintptr(-libc.Int32FromInt32(2))*12 + 4)) = _sqlite3PExpr(tls, pParse, int32(TK_SELECT), uintptr(0), uintptr(0))
|
|
_sqlite3PExprAddSelect(tls, pParse, *(*uintptr)(unsafe.Pointer(yymsp + uintptr(-libc.Int32FromInt32(2))*12 + 4)), *(*uintptr)(unsafe.Pointer(yymsp + uintptr(-libc.Int32FromInt32(1))*12 + 4)))
|
|
goto _350
|
|
_239:
|
|
; /* expr ::= expr in_op LP select RP */
|
|
*(*uintptr)(unsafe.Pointer(yymsp + uintptr(-libc.Int32FromInt32(4))*12 + 4)) = _sqlite3PExpr(tls, pParse, int32(TK_IN), *(*uintptr)(unsafe.Pointer(yymsp + uintptr(-libc.Int32FromInt32(4))*12 + 4)), uintptr(0))
|
|
_sqlite3PExprAddSelect(tls, pParse, *(*uintptr)(unsafe.Pointer(yymsp + uintptr(-libc.Int32FromInt32(4))*12 + 4)), *(*uintptr)(unsafe.Pointer(yymsp + uintptr(-libc.Int32FromInt32(1))*12 + 4)))
|
|
if *(*int32)(unsafe.Pointer(yymsp + uintptr(-libc.Int32FromInt32(3))*12 + 4)) != 0 {
|
|
*(*uintptr)(unsafe.Pointer(yymsp + uintptr(-libc.Int32FromInt32(4))*12 + 4)) = _sqlite3PExpr(tls, pParse, int32(TK_NOT), *(*uintptr)(unsafe.Pointer(yymsp + uintptr(-libc.Int32FromInt32(4))*12 + 4)), uintptr(0))
|
|
}
|
|
goto _350
|
|
_240:
|
|
; /* expr ::= expr in_op nm dbnm paren_exprlist */
|
|
pSrc = _sqlite3SrcListAppend(tls, pParse, uintptr(0), yymsp+uintptr(-libc.Int32FromInt32(2))*12+4, yymsp+uintptr(-libc.Int32FromInt32(1))*12+4)
|
|
pSelect = _sqlite3SelectNew(tls, pParse, uintptr(0), pSrc, uintptr(0), uintptr(0), uintptr(0), uintptr(0), uint32(0), uintptr(0))
|
|
if *(*uintptr)(unsafe.Pointer(yymsp + 4)) != 0 {
|
|
if pSelect != 0 {
|
|
v352 = pSrc
|
|
} else {
|
|
v352 = uintptr(0)
|
|
}
|
|
_sqlite3SrcListFuncArgs(tls, pParse, v352, *(*uintptr)(unsafe.Pointer(yymsp + 4)))
|
|
}
|
|
*(*uintptr)(unsafe.Pointer(yymsp + uintptr(-libc.Int32FromInt32(4))*12 + 4)) = _sqlite3PExpr(tls, pParse, int32(TK_IN), *(*uintptr)(unsafe.Pointer(yymsp + uintptr(-libc.Int32FromInt32(4))*12 + 4)), uintptr(0))
|
|
_sqlite3PExprAddSelect(tls, pParse, *(*uintptr)(unsafe.Pointer(yymsp + uintptr(-libc.Int32FromInt32(4))*12 + 4)), pSelect)
|
|
if *(*int32)(unsafe.Pointer(yymsp + uintptr(-libc.Int32FromInt32(3))*12 + 4)) != 0 {
|
|
*(*uintptr)(unsafe.Pointer(yymsp + uintptr(-libc.Int32FromInt32(4))*12 + 4)) = _sqlite3PExpr(tls, pParse, int32(TK_NOT), *(*uintptr)(unsafe.Pointer(yymsp + uintptr(-libc.Int32FromInt32(4))*12 + 4)), uintptr(0))
|
|
}
|
|
goto _350
|
|
_241:
|
|
; /* expr ::= EXISTS LP select RP */
|
|
v352 = _sqlite3PExpr(tls, pParse, int32(TK_EXISTS), uintptr(0), uintptr(0))
|
|
*(*uintptr)(unsafe.Pointer(yymsp + uintptr(-libc.Int32FromInt32(3))*12 + 4)) = v352
|
|
p5 = v352
|
|
_sqlite3PExprAddSelect(tls, pParse, p5, *(*uintptr)(unsafe.Pointer(yymsp + uintptr(-libc.Int32FromInt32(1))*12 + 4)))
|
|
goto _350
|
|
_242:
|
|
; /* expr ::= CASE case_operand case_exprlist case_else END */
|
|
*(*uintptr)(unsafe.Pointer(yymsp + uintptr(-libc.Int32FromInt32(4))*12 + 4)) = _sqlite3PExpr(tls, pParse, int32(TK_CASE), *(*uintptr)(unsafe.Pointer(yymsp + uintptr(-libc.Int32FromInt32(3))*12 + 4)), uintptr(0))
|
|
if *(*uintptr)(unsafe.Pointer(yymsp + uintptr(-libc.Int32FromInt32(4))*12 + 4)) != 0 {
|
|
if *(*uintptr)(unsafe.Pointer(yymsp + uintptr(-libc.Int32FromInt32(1))*12 + 4)) != 0 {
|
|
v352 = _sqlite3ExprListAppend(tls, pParse, *(*uintptr)(unsafe.Pointer(yymsp + uintptr(-libc.Int32FromInt32(2))*12 + 4)), *(*uintptr)(unsafe.Pointer(yymsp + uintptr(-libc.Int32FromInt32(1))*12 + 4)))
|
|
} else {
|
|
v352 = *(*uintptr)(unsafe.Pointer(yymsp + uintptr(-libc.Int32FromInt32(2))*12 + 4))
|
|
}
|
|
*(*uintptr)(unsafe.Pointer(*(*uintptr)(unsafe.Pointer(yymsp + uintptr(-libc.Int32FromInt32(4))*12 + 4)) + 20)) = v352
|
|
_sqlite3ExprSetHeightAndFlags(tls, pParse, *(*uintptr)(unsafe.Pointer(yymsp + uintptr(-libc.Int32FromInt32(4))*12 + 4)))
|
|
} else {
|
|
_sqlite3ExprListDelete(tls, (*TParse)(unsafe.Pointer(pParse)).Fdb, *(*uintptr)(unsafe.Pointer(yymsp + uintptr(-libc.Int32FromInt32(2))*12 + 4)))
|
|
_sqlite3ExprDelete(tls, (*TParse)(unsafe.Pointer(pParse)).Fdb, *(*uintptr)(unsafe.Pointer(yymsp + uintptr(-libc.Int32FromInt32(1))*12 + 4)))
|
|
}
|
|
goto _350
|
|
_243:
|
|
; /* case_exprlist ::= case_exprlist WHEN expr THEN expr */
|
|
*(*uintptr)(unsafe.Pointer(yymsp + uintptr(-libc.Int32FromInt32(4))*12 + 4)) = _sqlite3ExprListAppend(tls, pParse, *(*uintptr)(unsafe.Pointer(yymsp + uintptr(-libc.Int32FromInt32(4))*12 + 4)), *(*uintptr)(unsafe.Pointer(yymsp + uintptr(-libc.Int32FromInt32(2))*12 + 4)))
|
|
*(*uintptr)(unsafe.Pointer(yymsp + uintptr(-libc.Int32FromInt32(4))*12 + 4)) = _sqlite3ExprListAppend(tls, pParse, *(*uintptr)(unsafe.Pointer(yymsp + uintptr(-libc.Int32FromInt32(4))*12 + 4)), *(*uintptr)(unsafe.Pointer(yymsp + 4)))
|
|
goto _350
|
|
_244:
|
|
; /* case_exprlist ::= WHEN expr THEN expr */
|
|
*(*uintptr)(unsafe.Pointer(yymsp + uintptr(-libc.Int32FromInt32(3))*12 + 4)) = _sqlite3ExprListAppend(tls, pParse, uintptr(0), *(*uintptr)(unsafe.Pointer(yymsp + uintptr(-libc.Int32FromInt32(2))*12 + 4)))
|
|
*(*uintptr)(unsafe.Pointer(yymsp + uintptr(-libc.Int32FromInt32(3))*12 + 4)) = _sqlite3ExprListAppend(tls, pParse, *(*uintptr)(unsafe.Pointer(yymsp + uintptr(-libc.Int32FromInt32(3))*12 + 4)), *(*uintptr)(unsafe.Pointer(yymsp + 4)))
|
|
goto _350
|
|
_245:
|
|
; /* nexprlist ::= nexprlist COMMA expr */
|
|
*(*uintptr)(unsafe.Pointer(yymsp + uintptr(-libc.Int32FromInt32(2))*12 + 4)) = _sqlite3ExprListAppend(tls, pParse, *(*uintptr)(unsafe.Pointer(yymsp + uintptr(-libc.Int32FromInt32(2))*12 + 4)), *(*uintptr)(unsafe.Pointer(yymsp + 4)))
|
|
goto _350
|
|
_246:
|
|
; /* nexprlist ::= expr */
|
|
*(*uintptr)(unsafe.Pointer(yymsp + 4)) = _sqlite3ExprListAppend(tls, pParse, uintptr(0), *(*uintptr)(unsafe.Pointer(yymsp + 4))) /*A-overwrites-Y*/
|
|
goto _350
|
|
_248:
|
|
; /* paren_exprlist ::= LP exprlist RP */
|
|
_247:
|
|
;
|
|
*(*uintptr)(unsafe.Pointer(yymsp + uintptr(-libc.Int32FromInt32(2))*12 + 4)) = *(*uintptr)(unsafe.Pointer(yymsp + uintptr(-libc.Int32FromInt32(1))*12 + 4))
|
|
goto _350
|
|
_249:
|
|
; /* cmd ::= createkw uniqueflag INDEX ifnotexists nm dbnm ON nm LP sortlist RP where_opt */
|
|
_sqlite3CreateIndex(tls, pParse, yymsp+uintptr(-libc.Int32FromInt32(7))*12+4, yymsp+uintptr(-libc.Int32FromInt32(6))*12+4, _sqlite3SrcListAppend(tls, pParse, uintptr(0), yymsp+uintptr(-libc.Int32FromInt32(4))*12+4, uintptr(0)), *(*uintptr)(unsafe.Pointer(yymsp + uintptr(-libc.Int32FromInt32(2))*12 + 4)), *(*int32)(unsafe.Pointer(yymsp + uintptr(-libc.Int32FromInt32(10))*12 + 4)), yymsp+uintptr(-libc.Int32FromInt32(11))*12+4, *(*uintptr)(unsafe.Pointer(yymsp + 4)), SQLITE_SO_ASC, *(*int32)(unsafe.Pointer(yymsp + uintptr(-libc.Int32FromInt32(8))*12 + 4)), uint8(SQLITE_IDXTYPE_APPDEF))
|
|
if libc.Int32FromUint8((*TParse)(unsafe.Pointer(pParse)).FeParseMode) >= int32(PARSE_MODE_RENAME) && (*TParse)(unsafe.Pointer(pParse)).FpNewIndex != 0 {
|
|
_sqlite3RenameTokenMap(tls, pParse, (*TIndex)(unsafe.Pointer((*TParse)(unsafe.Pointer(pParse)).FpNewIndex)).FzName, yymsp+uintptr(-libc.Int32FromInt32(4))*12+4)
|
|
}
|
|
goto _350
|
|
_251:
|
|
; /* uniqueflag ::= UNIQUE */
|
|
_250:
|
|
;
|
|
*(*int32)(unsafe.Pointer(yymsp + 4)) = int32(OE_Abort)
|
|
goto _350
|
|
_252:
|
|
; /* uniqueflag ::= */
|
|
*(*int32)(unsafe.Pointer(yymsp + 1*12 + 4)) = OE_None
|
|
goto _350
|
|
_253:
|
|
; /* eidlist ::= eidlist COMMA nm collate sortorder */
|
|
*(*uintptr)(unsafe.Pointer(yymsp + uintptr(-libc.Int32FromInt32(4))*12 + 4)) = _parserAddExprIdListTerm(tls, pParse, *(*uintptr)(unsafe.Pointer(yymsp + uintptr(-libc.Int32FromInt32(4))*12 + 4)), yymsp+uintptr(-libc.Int32FromInt32(2))*12+4, *(*int32)(unsafe.Pointer(yymsp + uintptr(-libc.Int32FromInt32(1))*12 + 4)), *(*int32)(unsafe.Pointer(yymsp + 4)))
|
|
goto _350
|
|
_254:
|
|
; /* eidlist ::= nm collate sortorder */
|
|
*(*uintptr)(unsafe.Pointer(yymsp + uintptr(-libc.Int32FromInt32(2))*12 + 4)) = _parserAddExprIdListTerm(tls, pParse, uintptr(0), yymsp+uintptr(-libc.Int32FromInt32(2))*12+4, *(*int32)(unsafe.Pointer(yymsp + uintptr(-libc.Int32FromInt32(1))*12 + 4)), *(*int32)(unsafe.Pointer(yymsp + 4))) /*A-overwrites-Y*/
|
|
goto _350
|
|
_255:
|
|
; /* cmd ::= DROP INDEX ifexists fullname */
|
|
_sqlite3DropIndex(tls, pParse, *(*uintptr)(unsafe.Pointer(yymsp + 4)), *(*int32)(unsafe.Pointer(yymsp + uintptr(-libc.Int32FromInt32(1))*12 + 4)))
|
|
goto _350
|
|
_256:
|
|
; /* cmd ::= VACUUM vinto */
|
|
_sqlite3Vacuum(tls, pParse, uintptr(0), *(*uintptr)(unsafe.Pointer(yymsp + 4)))
|
|
goto _350
|
|
_257:
|
|
; /* cmd ::= VACUUM nm vinto */
|
|
_sqlite3Vacuum(tls, pParse, yymsp+uintptr(-libc.Int32FromInt32(1))*12+4, *(*uintptr)(unsafe.Pointer(yymsp + 4)))
|
|
goto _350
|
|
_258:
|
|
; /* cmd ::= PRAGMA nm dbnm */
|
|
_sqlite3Pragma(tls, pParse, yymsp+uintptr(-libc.Int32FromInt32(1))*12+4, yymsp+4, uintptr(0), 0)
|
|
goto _350
|
|
_259:
|
|
; /* cmd ::= PRAGMA nm dbnm EQ nmnum */
|
|
_sqlite3Pragma(tls, pParse, yymsp+uintptr(-libc.Int32FromInt32(3))*12+4, yymsp+uintptr(-libc.Int32FromInt32(2))*12+4, yymsp+4, 0)
|
|
goto _350
|
|
_260:
|
|
; /* cmd ::= PRAGMA nm dbnm LP nmnum RP */
|
|
_sqlite3Pragma(tls, pParse, yymsp+uintptr(-libc.Int32FromInt32(4))*12+4, yymsp+uintptr(-libc.Int32FromInt32(3))*12+4, yymsp+uintptr(-libc.Int32FromInt32(1))*12+4, 0)
|
|
goto _350
|
|
_261:
|
|
; /* cmd ::= PRAGMA nm dbnm EQ minus_num */
|
|
_sqlite3Pragma(tls, pParse, yymsp+uintptr(-libc.Int32FromInt32(3))*12+4, yymsp+uintptr(-libc.Int32FromInt32(2))*12+4, yymsp+4, int32(1))
|
|
goto _350
|
|
_262:
|
|
; /* cmd ::= PRAGMA nm dbnm LP minus_num RP */
|
|
_sqlite3Pragma(tls, pParse, yymsp+uintptr(-libc.Int32FromInt32(4))*12+4, yymsp+uintptr(-libc.Int32FromInt32(3))*12+4, yymsp+uintptr(-libc.Int32FromInt32(1))*12+4, int32(1))
|
|
goto _350
|
|
_263:
|
|
; /* cmd ::= createkw trigger_decl BEGIN trigger_cmd_list END */
|
|
(**(**TToken)(__ccgo_up(bp + 72))).Fz = *(*uintptr)(unsafe.Pointer(yymsp + uintptr(-libc.Int32FromInt32(3))*12 + 4))
|
|
(**(**TToken)(__ccgo_up(bp + 72))).Fn = libc.Uint32FromInt32(int32(*(*uintptr)(unsafe.Pointer(yymsp + 4)))-int32(*(*uintptr)(unsafe.Pointer(yymsp + uintptr(-libc.Int32FromInt32(3))*12 + 4)))) + *(*uint32)(unsafe.Pointer(yymsp + 4 + 4))
|
|
_sqlite3FinishTrigger(tls, pParse, *(*uintptr)(unsafe.Pointer(yymsp + uintptr(-libc.Int32FromInt32(1))*12 + 4)), bp+72)
|
|
goto _350
|
|
_264:
|
|
; /* trigger_decl ::= temp TRIGGER ifnotexists nm dbnm trigger_time trigger_event ON fullname foreach_clause when_clause */
|
|
_sqlite3BeginTrigger(tls, pParse, yymsp+uintptr(-libc.Int32FromInt32(7))*12+4, yymsp+uintptr(-libc.Int32FromInt32(6))*12+4, *(*int32)(unsafe.Pointer(yymsp + uintptr(-libc.Int32FromInt32(5))*12 + 4)), *(*int32)(unsafe.Pointer(yymsp + uintptr(-libc.Int32FromInt32(4))*12 + 4)), *(*uintptr)(unsafe.Pointer(yymsp + uintptr(-libc.Int32FromInt32(4))*12 + 4 + 4)), *(*uintptr)(unsafe.Pointer(yymsp + uintptr(-libc.Int32FromInt32(2))*12 + 4)), *(*uintptr)(unsafe.Pointer(yymsp + 4)), *(*int32)(unsafe.Pointer(yymsp + uintptr(-libc.Int32FromInt32(10))*12 + 4)), *(*int32)(unsafe.Pointer(yymsp + uintptr(-libc.Int32FromInt32(8))*12 + 4)))
|
|
if *(*uint32)(unsafe.Pointer(yymsp + uintptr(-libc.Int32FromInt32(6))*12 + 4 + 4)) == uint32(0) {
|
|
v357 = *(*TToken)(unsafe.Pointer(yymsp + uintptr(-libc.Int32FromInt32(7))*12 + 4))
|
|
} else {
|
|
v357 = *(*TToken)(unsafe.Pointer(yymsp + uintptr(-libc.Int32FromInt32(6))*12 + 4))
|
|
}
|
|
*(*TToken)(unsafe.Pointer(yymsp + uintptr(-libc.Int32FromInt32(10))*12 + 4)) = v357 /*A-overwrites-T*/
|
|
goto _350
|
|
_265:
|
|
; /* trigger_time ::= BEFORE|AFTER */
|
|
*(*int32)(unsafe.Pointer(yymsp + 4)) = libc.Int32FromUint16((**(**TyyStackEntry)(__ccgo_up(yymsp))).Fmajor) /*A-overwrites-X*/
|
|
goto _350
|
|
_266:
|
|
; /* trigger_time ::= INSTEAD OF */
|
|
*(*int32)(unsafe.Pointer(yymsp + uintptr(-libc.Int32FromInt32(1))*12 + 4)) = int32(TK_INSTEAD)
|
|
goto _350
|
|
_267:
|
|
; /* trigger_time ::= */
|
|
*(*int32)(unsafe.Pointer(yymsp + 1*12 + 4)) = int32(TK_BEFORE)
|
|
goto _350
|
|
_269:
|
|
; /* trigger_event ::= DELETE|INSERT */
|
|
_268:
|
|
;
|
|
*(*int32)(unsafe.Pointer(yymsp + 4)) = libc.Int32FromUint16((**(**TyyStackEntry)(__ccgo_up(yymsp))).Fmajor) /*A-overwrites-X*/
|
|
*(*uintptr)(unsafe.Pointer(yymsp + 4 + 4)) = uintptr(0)
|
|
goto _350
|
|
_270:
|
|
; /* trigger_event ::= UPDATE OF idlist */
|
|
*(*int32)(unsafe.Pointer(yymsp + uintptr(-libc.Int32FromInt32(2))*12 + 4)) = int32(TK_UPDATE)
|
|
*(*uintptr)(unsafe.Pointer(yymsp + uintptr(-libc.Int32FromInt32(2))*12 + 4 + 4)) = *(*uintptr)(unsafe.Pointer(yymsp + 4))
|
|
goto _350
|
|
_272:
|
|
; /* when_clause ::= */
|
|
_271:
|
|
;
|
|
*(*uintptr)(unsafe.Pointer(yymsp + 1*12 + 4)) = uintptr(0)
|
|
goto _350
|
|
_274:
|
|
; /* when_clause ::= WHEN expr */
|
|
_273:
|
|
;
|
|
*(*uintptr)(unsafe.Pointer(yymsp + uintptr(-libc.Int32FromInt32(1))*12 + 4)) = *(*uintptr)(unsafe.Pointer(yymsp + 4))
|
|
goto _350
|
|
_275:
|
|
; /* trigger_cmd_list ::= trigger_cmd_list trigger_cmd SEMI */
|
|
(*TTriggerStep)(unsafe.Pointer((*TTriggerStep)(unsafe.Pointer(*(*uintptr)(unsafe.Pointer(yymsp + uintptr(-libc.Int32FromInt32(2))*12 + 4)))).FpLast)).FpNext = *(*uintptr)(unsafe.Pointer(yymsp + uintptr(-libc.Int32FromInt32(1))*12 + 4))
|
|
(*TTriggerStep)(unsafe.Pointer(*(*uintptr)(unsafe.Pointer(yymsp + uintptr(-libc.Int32FromInt32(2))*12 + 4)))).FpLast = *(*uintptr)(unsafe.Pointer(yymsp + uintptr(-libc.Int32FromInt32(1))*12 + 4))
|
|
goto _350
|
|
_276:
|
|
; /* trigger_cmd_list ::= trigger_cmd SEMI */
|
|
(*TTriggerStep)(unsafe.Pointer(*(*uintptr)(unsafe.Pointer(yymsp + uintptr(-libc.Int32FromInt32(1))*12 + 4)))).FpLast = *(*uintptr)(unsafe.Pointer(yymsp + uintptr(-libc.Int32FromInt32(1))*12 + 4))
|
|
goto _350
|
|
_277:
|
|
; /* tridxby ::= INDEXED BY nm */
|
|
_sqlite3ErrorMsg(tls, pParse, __ccgo_ts+25033, 0)
|
|
goto _350
|
|
_278:
|
|
; /* tridxby ::= NOT INDEXED */
|
|
_sqlite3ErrorMsg(tls, pParse, __ccgo_ts+25117, 0)
|
|
goto _350
|
|
_279:
|
|
; /* trigger_cmd ::= UPDATE orconf xfullname tridxby SET setlist from where_opt scanpt */
|
|
*(*uintptr)(unsafe.Pointer(&**(**TYYMINORTYPE)(__ccgo_up(bp)))) = _sqlite3TriggerUpdateStep(tls, pParse, *(*uintptr)(unsafe.Pointer(yymsp + uintptr(-libc.Int32FromInt32(6))*12 + 4)), *(*uintptr)(unsafe.Pointer(yymsp + uintptr(-libc.Int32FromInt32(2))*12 + 4)), *(*uintptr)(unsafe.Pointer(yymsp + uintptr(-libc.Int32FromInt32(3))*12 + 4)), *(*uintptr)(unsafe.Pointer(yymsp + uintptr(-libc.Int32FromInt32(1))*12 + 4)), libc.Uint8FromInt32(*(*int32)(unsafe.Pointer(yymsp + uintptr(-libc.Int32FromInt32(7))*12 + 4))), *(*uintptr)(unsafe.Pointer(yymsp + uintptr(-libc.Int32FromInt32(8))*12 + 4)), *(*uintptr)(unsafe.Pointer(yymsp + 4)))
|
|
*(*uintptr)(unsafe.Pointer(yymsp + uintptr(-libc.Int32FromInt32(8))*12 + 4)) = *(*uintptr)(unsafe.Pointer(&**(**TYYMINORTYPE)(__ccgo_up(bp))))
|
|
goto _350
|
|
_280:
|
|
; /* trigger_cmd ::= scanpt insert_cmd INTO xfullname idlist_opt select upsert scanpt */
|
|
*(*uintptr)(unsafe.Pointer(&**(**TYYMINORTYPE)(__ccgo_up(bp)))) = _sqlite3TriggerInsertStep(tls, pParse, *(*uintptr)(unsafe.Pointer(yymsp + uintptr(-libc.Int32FromInt32(4))*12 + 4)), *(*uintptr)(unsafe.Pointer(yymsp + uintptr(-libc.Int32FromInt32(3))*12 + 4)), *(*uintptr)(unsafe.Pointer(yymsp + uintptr(-libc.Int32FromInt32(2))*12 + 4)), libc.Uint8FromInt32(*(*int32)(unsafe.Pointer(yymsp + uintptr(-libc.Int32FromInt32(6))*12 + 4))), *(*uintptr)(unsafe.Pointer(yymsp + uintptr(-libc.Int32FromInt32(1))*12 + 4)), *(*uintptr)(unsafe.Pointer(yymsp + uintptr(-libc.Int32FromInt32(7))*12 + 4)), *(*uintptr)(unsafe.Pointer(yymsp + 4))) /*yylhsminor.yy427-overwrites-yymsp[-6].minor.yy144*/
|
|
*(*uintptr)(unsafe.Pointer(yymsp + uintptr(-libc.Int32FromInt32(7))*12 + 4)) = *(*uintptr)(unsafe.Pointer(&**(**TYYMINORTYPE)(__ccgo_up(bp))))
|
|
goto _350
|
|
_281:
|
|
; /* trigger_cmd ::= DELETE FROM xfullname tridxby where_opt scanpt */
|
|
*(*uintptr)(unsafe.Pointer(&**(**TYYMINORTYPE)(__ccgo_up(bp)))) = _sqlite3TriggerDeleteStep(tls, pParse, *(*uintptr)(unsafe.Pointer(yymsp + uintptr(-libc.Int32FromInt32(3))*12 + 4)), *(*uintptr)(unsafe.Pointer(yymsp + uintptr(-libc.Int32FromInt32(1))*12 + 4)), *(*uintptr)(unsafe.Pointer(yymsp + uintptr(-libc.Int32FromInt32(5))*12 + 4)), *(*uintptr)(unsafe.Pointer(yymsp + 4)))
|
|
*(*uintptr)(unsafe.Pointer(yymsp + uintptr(-libc.Int32FromInt32(5))*12 + 4)) = *(*uintptr)(unsafe.Pointer(&**(**TYYMINORTYPE)(__ccgo_up(bp))))
|
|
goto _350
|
|
_282:
|
|
; /* trigger_cmd ::= scanpt select scanpt */
|
|
*(*uintptr)(unsafe.Pointer(&**(**TYYMINORTYPE)(__ccgo_up(bp)))) = _sqlite3TriggerSelectStep(tls, (*TParse)(unsafe.Pointer(pParse)).Fdb, *(*uintptr)(unsafe.Pointer(yymsp + uintptr(-libc.Int32FromInt32(1))*12 + 4)), *(*uintptr)(unsafe.Pointer(yymsp + uintptr(-libc.Int32FromInt32(2))*12 + 4)), *(*uintptr)(unsafe.Pointer(yymsp + 4))) /*yylhsminor.yy427-overwrites-yymsp[-1].minor.yy555*/
|
|
*(*uintptr)(unsafe.Pointer(yymsp + uintptr(-libc.Int32FromInt32(2))*12 + 4)) = *(*uintptr)(unsafe.Pointer(&**(**TYYMINORTYPE)(__ccgo_up(bp))))
|
|
goto _350
|
|
_283:
|
|
; /* expr ::= RAISE LP IGNORE RP */
|
|
*(*uintptr)(unsafe.Pointer(yymsp + uintptr(-libc.Int32FromInt32(3))*12 + 4)) = _sqlite3PExpr(tls, pParse, int32(TK_RAISE), uintptr(0), uintptr(0))
|
|
if *(*uintptr)(unsafe.Pointer(yymsp + uintptr(-libc.Int32FromInt32(3))*12 + 4)) != 0 {
|
|
(*TExpr)(unsafe.Pointer(*(*uintptr)(unsafe.Pointer(yymsp + uintptr(-libc.Int32FromInt32(3))*12 + 4)))).FaffExpr = int8(OE_Ignore)
|
|
}
|
|
goto _350
|
|
_284:
|
|
; /* expr ::= RAISE LP raisetype COMMA expr RP */
|
|
*(*uintptr)(unsafe.Pointer(yymsp + uintptr(-libc.Int32FromInt32(5))*12 + 4)) = _sqlite3PExpr(tls, pParse, int32(TK_RAISE), *(*uintptr)(unsafe.Pointer(yymsp + uintptr(-libc.Int32FromInt32(1))*12 + 4)), uintptr(0))
|
|
if *(*uintptr)(unsafe.Pointer(yymsp + uintptr(-libc.Int32FromInt32(5))*12 + 4)) != 0 {
|
|
(*TExpr)(unsafe.Pointer(*(*uintptr)(unsafe.Pointer(yymsp + uintptr(-libc.Int32FromInt32(5))*12 + 4)))).FaffExpr = int8(*(*int32)(unsafe.Pointer(yymsp + uintptr(-libc.Int32FromInt32(3))*12 + 4)))
|
|
}
|
|
goto _350
|
|
_285:
|
|
; /* raisetype ::= ROLLBACK */
|
|
*(*int32)(unsafe.Pointer(yymsp + 4)) = int32(OE_Rollback)
|
|
goto _350
|
|
_286:
|
|
; /* raisetype ::= FAIL */
|
|
*(*int32)(unsafe.Pointer(yymsp + 4)) = int32(OE_Fail)
|
|
goto _350
|
|
_287:
|
|
; /* cmd ::= DROP TRIGGER ifexists fullname */
|
|
_sqlite3DropTrigger(tls, pParse, *(*uintptr)(unsafe.Pointer(yymsp + 4)), *(*int32)(unsafe.Pointer(yymsp + uintptr(-libc.Int32FromInt32(1))*12 + 4)))
|
|
goto _350
|
|
_288:
|
|
; /* cmd ::= ATTACH database_kw_opt expr AS expr key_opt */
|
|
_sqlite3Attach(tls, pParse, *(*uintptr)(unsafe.Pointer(yymsp + uintptr(-libc.Int32FromInt32(3))*12 + 4)), *(*uintptr)(unsafe.Pointer(yymsp + uintptr(-libc.Int32FromInt32(1))*12 + 4)), *(*uintptr)(unsafe.Pointer(yymsp + 4)))
|
|
goto _350
|
|
_289:
|
|
; /* cmd ::= DETACH database_kw_opt expr */
|
|
_sqlite3Detach(tls, pParse, *(*uintptr)(unsafe.Pointer(yymsp + 4)))
|
|
goto _350
|
|
_290:
|
|
; /* cmd ::= REINDEX */
|
|
_sqlite3Reindex(tls, pParse, uintptr(0), uintptr(0))
|
|
goto _350
|
|
_291:
|
|
; /* cmd ::= REINDEX nm dbnm */
|
|
_sqlite3Reindex(tls, pParse, yymsp+uintptr(-libc.Int32FromInt32(1))*12+4, yymsp+4)
|
|
goto _350
|
|
_292:
|
|
; /* cmd ::= ANALYZE */
|
|
_sqlite3Analyze(tls, pParse, uintptr(0), uintptr(0))
|
|
goto _350
|
|
_293:
|
|
; /* cmd ::= ANALYZE nm dbnm */
|
|
_sqlite3Analyze(tls, pParse, yymsp+uintptr(-libc.Int32FromInt32(1))*12+4, yymsp+4)
|
|
goto _350
|
|
_294:
|
|
; /* cmd ::= ALTER TABLE fullname RENAME TO nm */
|
|
_sqlite3AlterRenameTable(tls, pParse, *(*uintptr)(unsafe.Pointer(yymsp + uintptr(-libc.Int32FromInt32(3))*12 + 4)), yymsp+4)
|
|
goto _350
|
|
_295:
|
|
; /* cmd ::= alter_add carglist */
|
|
*(*uint32)(unsafe.Pointer(yymsp + uintptr(-libc.Int32FromInt32(1))*12 + 4 + 4)) = libc.Uint32FromInt32(int32((*TParse)(unsafe.Pointer(pParse)).FsLastToken.Fz)-int32(*(*uintptr)(unsafe.Pointer(yymsp + uintptr(-libc.Int32FromInt32(1))*12 + 4)))) + (*TParse)(unsafe.Pointer(pParse)).FsLastToken.Fn
|
|
_sqlite3AlterFinishAddColumn(tls, pParse, yymsp+uintptr(-libc.Int32FromInt32(1))*12+4)
|
|
goto _350
|
|
_296:
|
|
; /* alter_add ::= ALTER TABLE fullname ADD kwcolumn_opt nm typetoken */
|
|
_disableLookaside(tls, pParse)
|
|
_sqlite3AlterBeginAddColumn(tls, pParse, *(*uintptr)(unsafe.Pointer(yymsp + uintptr(-libc.Int32FromInt32(4))*12 + 4)))
|
|
_sqlite3AddColumn(tls, pParse, *(*TToken)(unsafe.Pointer(yymsp + uintptr(-libc.Int32FromInt32(1))*12 + 4)), *(*TToken)(unsafe.Pointer(yymsp + 4)))
|
|
*(*TToken)(unsafe.Pointer(yymsp + uintptr(-libc.Int32FromInt32(6))*12 + 4)) = *(*TToken)(unsafe.Pointer(yymsp + uintptr(-libc.Int32FromInt32(1))*12 + 4))
|
|
goto _350
|
|
_297:
|
|
; /* cmd ::= ALTER TABLE fullname DROP kwcolumn_opt nm */
|
|
_sqlite3AlterDropColumn(tls, pParse, *(*uintptr)(unsafe.Pointer(yymsp + uintptr(-libc.Int32FromInt32(3))*12 + 4)), yymsp+4)
|
|
goto _350
|
|
_298:
|
|
; /* cmd ::= ALTER TABLE fullname RENAME kwcolumn_opt nm TO nm */
|
|
_sqlite3AlterRenameColumn(tls, pParse, *(*uintptr)(unsafe.Pointer(yymsp + uintptr(-libc.Int32FromInt32(5))*12 + 4)), yymsp+uintptr(-libc.Int32FromInt32(2))*12+4, yymsp+4)
|
|
goto _350
|
|
_299:
|
|
; /* cmd ::= ALTER TABLE fullname DROP CONSTRAINT nm */
|
|
_sqlite3AlterDropConstraint(tls, pParse, *(*uintptr)(unsafe.Pointer(yymsp + uintptr(-libc.Int32FromInt32(3))*12 + 4)), yymsp+4, uintptr(0))
|
|
goto _350
|
|
_300:
|
|
; /* cmd ::= ALTER TABLE fullname ALTER kwcolumn_opt nm DROP NOT NULL */
|
|
_sqlite3AlterDropConstraint(tls, pParse, *(*uintptr)(unsafe.Pointer(yymsp + uintptr(-libc.Int32FromInt32(6))*12 + 4)), uintptr(0), yymsp+uintptr(-libc.Int32FromInt32(3))*12+4)
|
|
goto _350
|
|
_301:
|
|
; /* cmd ::= ALTER TABLE fullname ALTER kwcolumn_opt nm SET NOT NULL onconf */
|
|
_sqlite3AlterSetNotNull(tls, pParse, *(*uintptr)(unsafe.Pointer(yymsp + uintptr(-libc.Int32FromInt32(7))*12 + 4)), yymsp+uintptr(-libc.Int32FromInt32(4))*12+4, yymsp+uintptr(-libc.Int32FromInt32(2))*12+4)
|
|
goto _350
|
|
_302:
|
|
; /* cmd ::= ALTER TABLE fullname ADD CONSTRAINT nm CHECK LP expr RP onconf */
|
|
_sqlite3AlterAddConstraint(tls, pParse, *(*uintptr)(unsafe.Pointer(yymsp + uintptr(-libc.Int32FromInt32(8))*12 + 4)), yymsp+uintptr(-libc.Int32FromInt32(6))*12+4, yymsp+uintptr(-libc.Int32FromInt32(5))*12+4, *(*uintptr)(unsafe.Pointer(yymsp + uintptr(-libc.Int32FromInt32(3))*12 + 4))+uintptr(1), int32(*(*uintptr)(unsafe.Pointer(yymsp + uintptr(-libc.Int32FromInt32(1))*12 + 4)))-int32(*(*uintptr)(unsafe.Pointer(yymsp + uintptr(-libc.Int32FromInt32(3))*12 + 4)))-int32(1), *(*uintptr)(unsafe.Pointer(yymsp + uintptr(-libc.Int32FromInt32(2))*12 + 4)))
|
|
goto _350
|
|
_303:
|
|
; /* cmd ::= ALTER TABLE fullname ADD CHECK LP expr RP onconf */
|
|
_sqlite3AlterAddConstraint(tls, pParse, *(*uintptr)(unsafe.Pointer(yymsp + uintptr(-libc.Int32FromInt32(6))*12 + 4)), yymsp+uintptr(-libc.Int32FromInt32(4))*12+4, uintptr(0), *(*uintptr)(unsafe.Pointer(yymsp + uintptr(-libc.Int32FromInt32(3))*12 + 4))+uintptr(1), int32(*(*uintptr)(unsafe.Pointer(yymsp + uintptr(-libc.Int32FromInt32(1))*12 + 4)))-int32(*(*uintptr)(unsafe.Pointer(yymsp + uintptr(-libc.Int32FromInt32(3))*12 + 4)))-int32(1), *(*uintptr)(unsafe.Pointer(yymsp + uintptr(-libc.Int32FromInt32(2))*12 + 4)))
|
|
goto _350
|
|
_304:
|
|
; /* cmd ::= create_vtab */
|
|
_sqlite3VtabFinishParse(tls, pParse, uintptr(0))
|
|
goto _350
|
|
_305:
|
|
; /* cmd ::= create_vtab LP vtabarglist RP */
|
|
_sqlite3VtabFinishParse(tls, pParse, yymsp+4)
|
|
goto _350
|
|
_306:
|
|
; /* create_vtab ::= createkw VIRTUAL TABLE ifnotexists nm dbnm USING nm */
|
|
_sqlite3VtabBeginParse(tls, pParse, yymsp+uintptr(-libc.Int32FromInt32(3))*12+4, yymsp+uintptr(-libc.Int32FromInt32(2))*12+4, yymsp+4, *(*int32)(unsafe.Pointer(yymsp + uintptr(-libc.Int32FromInt32(4))*12 + 4)))
|
|
goto _350
|
|
_307:
|
|
; /* vtabarg ::= */
|
|
_sqlite3VtabArgInit(tls, pParse)
|
|
goto _350
|
|
_309:
|
|
; /* vtabargtoken ::= ANY */
|
|
_308:
|
|
;
|
|
_310:
|
|
;
|
|
_sqlite3VtabArgExtend(tls, pParse, yymsp+4)
|
|
goto _350
|
|
_312:
|
|
; /* with ::= WITH wqlist */
|
|
_311:
|
|
;
|
|
_sqlite3WithPush(tls, pParse, *(*uintptr)(unsafe.Pointer(yymsp + 4)), uint8(1))
|
|
goto _350
|
|
_313:
|
|
; /* wqas ::= AS */
|
|
*(*Tu8)(unsafe.Pointer(yymsp + 4)) = uint8(M10d_Any)
|
|
goto _350
|
|
_314:
|
|
; /* wqas ::= AS MATERIALIZED */
|
|
*(*Tu8)(unsafe.Pointer(yymsp + uintptr(-libc.Int32FromInt32(1))*12 + 4)) = uint8(M10d_Yes)
|
|
goto _350
|
|
_315:
|
|
; /* wqas ::= AS NOT MATERIALIZED */
|
|
*(*Tu8)(unsafe.Pointer(yymsp + uintptr(-libc.Int32FromInt32(2))*12 + 4)) = uint8(M10d_No)
|
|
goto _350
|
|
_316:
|
|
; /* wqitem ::= withnm eidlist_opt wqas LP select RP */
|
|
*(*uintptr)(unsafe.Pointer(yymsp + uintptr(-libc.Int32FromInt32(5))*12 + 4)) = _sqlite3CteNew(tls, pParse, yymsp+uintptr(-libc.Int32FromInt32(5))*12+4, *(*uintptr)(unsafe.Pointer(yymsp + uintptr(-libc.Int32FromInt32(4))*12 + 4)), *(*uintptr)(unsafe.Pointer(yymsp + uintptr(-libc.Int32FromInt32(1))*12 + 4)), *(*Tu8)(unsafe.Pointer(yymsp + uintptr(-libc.Int32FromInt32(3))*12 + 4))) /*A-overwrites-X*/
|
|
goto _350
|
|
_317:
|
|
; /* withnm ::= nm */
|
|
libc.SetBitFieldPtr16Uint32(pParse+28, libc.Uint32FromInt32(1), 6, 0x40)
|
|
goto _350
|
|
_318:
|
|
; /* wqlist ::= wqitem */
|
|
*(*uintptr)(unsafe.Pointer(yymsp + 4)) = _sqlite3WithAdd(tls, pParse, uintptr(0), *(*uintptr)(unsafe.Pointer(yymsp + 4))) /*A-overwrites-X*/
|
|
goto _350
|
|
_319:
|
|
; /* wqlist ::= wqlist COMMA wqitem */
|
|
*(*uintptr)(unsafe.Pointer(yymsp + uintptr(-libc.Int32FromInt32(2))*12 + 4)) = _sqlite3WithAdd(tls, pParse, *(*uintptr)(unsafe.Pointer(yymsp + uintptr(-libc.Int32FromInt32(2))*12 + 4)), *(*uintptr)(unsafe.Pointer(yymsp + 4)))
|
|
goto _350
|
|
_320:
|
|
; /* windowdefn_list ::= windowdefn_list COMMA windowdefn */
|
|
_sqlite3WindowChain(tls, pParse, *(*uintptr)(unsafe.Pointer(yymsp + 4)), *(*uintptr)(unsafe.Pointer(yymsp + uintptr(-libc.Int32FromInt32(2))*12 + 4)))
|
|
(*TWindow)(unsafe.Pointer(*(*uintptr)(unsafe.Pointer(yymsp + 4)))).FpNextWin = *(*uintptr)(unsafe.Pointer(yymsp + uintptr(-libc.Int32FromInt32(2))*12 + 4))
|
|
*(*uintptr)(unsafe.Pointer(&**(**TYYMINORTYPE)(__ccgo_up(bp)))) = *(*uintptr)(unsafe.Pointer(yymsp + 4))
|
|
*(*uintptr)(unsafe.Pointer(yymsp + uintptr(-libc.Int32FromInt32(2))*12 + 4)) = *(*uintptr)(unsafe.Pointer(&**(**TYYMINORTYPE)(__ccgo_up(bp))))
|
|
goto _350
|
|
_321:
|
|
; /* windowdefn ::= nm AS LP window RP */
|
|
if *(*uintptr)(unsafe.Pointer(yymsp + uintptr(-libc.Int32FromInt32(1))*12 + 4)) != 0 {
|
|
(*TWindow)(unsafe.Pointer(*(*uintptr)(unsafe.Pointer(yymsp + uintptr(-libc.Int32FromInt32(1))*12 + 4)))).FzName = _sqlite3DbStrNDup(tls, (*TParse)(unsafe.Pointer(pParse)).Fdb, *(*uintptr)(unsafe.Pointer(yymsp + uintptr(-libc.Int32FromInt32(4))*12 + 4)), uint64(*(*uint32)(unsafe.Pointer(yymsp + uintptr(-libc.Int32FromInt32(4))*12 + 4 + 4))))
|
|
}
|
|
*(*uintptr)(unsafe.Pointer(&**(**TYYMINORTYPE)(__ccgo_up(bp)))) = *(*uintptr)(unsafe.Pointer(yymsp + uintptr(-libc.Int32FromInt32(1))*12 + 4))
|
|
*(*uintptr)(unsafe.Pointer(yymsp + uintptr(-libc.Int32FromInt32(4))*12 + 4)) = *(*uintptr)(unsafe.Pointer(&**(**TYYMINORTYPE)(__ccgo_up(bp))))
|
|
goto _350
|
|
_322:
|
|
; /* window ::= PARTITION BY nexprlist orderby_opt frame_opt */
|
|
*(*uintptr)(unsafe.Pointer(yymsp + uintptr(-libc.Int32FromInt32(4))*12 + 4)) = _sqlite3WindowAssemble(tls, pParse, *(*uintptr)(unsafe.Pointer(yymsp + 4)), *(*uintptr)(unsafe.Pointer(yymsp + uintptr(-libc.Int32FromInt32(2))*12 + 4)), *(*uintptr)(unsafe.Pointer(yymsp + uintptr(-libc.Int32FromInt32(1))*12 + 4)), uintptr(0))
|
|
goto _350
|
|
_323:
|
|
; /* window ::= nm PARTITION BY nexprlist orderby_opt frame_opt */
|
|
*(*uintptr)(unsafe.Pointer(&**(**TYYMINORTYPE)(__ccgo_up(bp)))) = _sqlite3WindowAssemble(tls, pParse, *(*uintptr)(unsafe.Pointer(yymsp + 4)), *(*uintptr)(unsafe.Pointer(yymsp + uintptr(-libc.Int32FromInt32(2))*12 + 4)), *(*uintptr)(unsafe.Pointer(yymsp + uintptr(-libc.Int32FromInt32(1))*12 + 4)), yymsp+uintptr(-libc.Int32FromInt32(5))*12+4)
|
|
*(*uintptr)(unsafe.Pointer(yymsp + uintptr(-libc.Int32FromInt32(5))*12 + 4)) = *(*uintptr)(unsafe.Pointer(&**(**TYYMINORTYPE)(__ccgo_up(bp))))
|
|
goto _350
|
|
_324:
|
|
; /* window ::= ORDER BY sortlist frame_opt */
|
|
*(*uintptr)(unsafe.Pointer(yymsp + uintptr(-libc.Int32FromInt32(3))*12 + 4)) = _sqlite3WindowAssemble(tls, pParse, *(*uintptr)(unsafe.Pointer(yymsp + 4)), uintptr(0), *(*uintptr)(unsafe.Pointer(yymsp + uintptr(-libc.Int32FromInt32(1))*12 + 4)), uintptr(0))
|
|
goto _350
|
|
_325:
|
|
; /* window ::= nm ORDER BY sortlist frame_opt */
|
|
*(*uintptr)(unsafe.Pointer(&**(**TYYMINORTYPE)(__ccgo_up(bp)))) = _sqlite3WindowAssemble(tls, pParse, *(*uintptr)(unsafe.Pointer(yymsp + 4)), uintptr(0), *(*uintptr)(unsafe.Pointer(yymsp + uintptr(-libc.Int32FromInt32(1))*12 + 4)), yymsp+uintptr(-libc.Int32FromInt32(4))*12+4)
|
|
*(*uintptr)(unsafe.Pointer(yymsp + uintptr(-libc.Int32FromInt32(4))*12 + 4)) = *(*uintptr)(unsafe.Pointer(&**(**TYYMINORTYPE)(__ccgo_up(bp))))
|
|
goto _350
|
|
_326:
|
|
; /* window ::= nm frame_opt */
|
|
*(*uintptr)(unsafe.Pointer(&**(**TYYMINORTYPE)(__ccgo_up(bp)))) = _sqlite3WindowAssemble(tls, pParse, *(*uintptr)(unsafe.Pointer(yymsp + 4)), uintptr(0), uintptr(0), yymsp+uintptr(-libc.Int32FromInt32(1))*12+4)
|
|
*(*uintptr)(unsafe.Pointer(yymsp + uintptr(-libc.Int32FromInt32(1))*12 + 4)) = *(*uintptr)(unsafe.Pointer(&**(**TYYMINORTYPE)(__ccgo_up(bp))))
|
|
goto _350
|
|
_327:
|
|
; /* frame_opt ::= */
|
|
*(*uintptr)(unsafe.Pointer(yymsp + 1*12 + 4)) = _sqlite3WindowAlloc(tls, pParse, 0, int32(TK_UNBOUNDED), uintptr(0), int32(TK_CURRENT), uintptr(0), uint8(0))
|
|
goto _350
|
|
_328:
|
|
; /* frame_opt ::= range_or_rows frame_bound_s frame_exclude_opt */
|
|
*(*uintptr)(unsafe.Pointer(&**(**TYYMINORTYPE)(__ccgo_up(bp)))) = _sqlite3WindowAlloc(tls, pParse, *(*int32)(unsafe.Pointer(yymsp + uintptr(-libc.Int32FromInt32(2))*12 + 4)), *(*int32)(unsafe.Pointer(yymsp + uintptr(-libc.Int32FromInt32(1))*12 + 4)), *(*uintptr)(unsafe.Pointer(yymsp + uintptr(-libc.Int32FromInt32(1))*12 + 4 + 4)), int32(TK_CURRENT), uintptr(0), *(*Tu8)(unsafe.Pointer(yymsp + 4)))
|
|
*(*uintptr)(unsafe.Pointer(yymsp + uintptr(-libc.Int32FromInt32(2))*12 + 4)) = *(*uintptr)(unsafe.Pointer(&**(**TYYMINORTYPE)(__ccgo_up(bp))))
|
|
goto _350
|
|
_329:
|
|
; /* frame_opt ::= range_or_rows BETWEEN frame_bound_s AND frame_bound_e frame_exclude_opt */
|
|
*(*uintptr)(unsafe.Pointer(&**(**TYYMINORTYPE)(__ccgo_up(bp)))) = _sqlite3WindowAlloc(tls, pParse, *(*int32)(unsafe.Pointer(yymsp + uintptr(-libc.Int32FromInt32(5))*12 + 4)), *(*int32)(unsafe.Pointer(yymsp + uintptr(-libc.Int32FromInt32(3))*12 + 4)), *(*uintptr)(unsafe.Pointer(yymsp + uintptr(-libc.Int32FromInt32(3))*12 + 4 + 4)), *(*int32)(unsafe.Pointer(yymsp + uintptr(-libc.Int32FromInt32(1))*12 + 4)), *(*uintptr)(unsafe.Pointer(yymsp + uintptr(-libc.Int32FromInt32(1))*12 + 4 + 4)), *(*Tu8)(unsafe.Pointer(yymsp + 4)))
|
|
*(*uintptr)(unsafe.Pointer(yymsp + uintptr(-libc.Int32FromInt32(5))*12 + 4)) = *(*uintptr)(unsafe.Pointer(&**(**TYYMINORTYPE)(__ccgo_up(bp))))
|
|
goto _350
|
|
_331:
|
|
; /* frame_bound_s ::= frame_bound */
|
|
_330:
|
|
;
|
|
*(*TFrameBound)(unsafe.Pointer(bp)) = *(*TFrameBound)(unsafe.Pointer(yymsp + 4))
|
|
*(*TFrameBound)(unsafe.Pointer(yymsp + 4)) = *(*TFrameBound)(unsafe.Pointer(bp))
|
|
goto _350
|
|
_333:
|
|
; /* frame_bound_s ::= UNBOUNDED PRECEDING */
|
|
_332:
|
|
;
|
|
_334:
|
|
;
|
|
(*(*TFrameBound)(unsafe.Pointer(bp))).FeType = libc.Int32FromUint16((**(**TyyStackEntry)(__ccgo_up(yymsp + uintptr(-libc.Int32FromInt32(1))*12))).Fmajor)
|
|
(*(*TFrameBound)(unsafe.Pointer(bp))).FpExpr = uintptr(0)
|
|
*(*TFrameBound)(unsafe.Pointer(yymsp + uintptr(-libc.Int32FromInt32(1))*12 + 4)) = *(*TFrameBound)(unsafe.Pointer(bp))
|
|
goto _350
|
|
_335:
|
|
; /* frame_bound ::= expr PRECEDING|FOLLOWING */
|
|
(*(*TFrameBound)(unsafe.Pointer(bp))).FeType = libc.Int32FromUint16((**(**TyyStackEntry)(__ccgo_up(yymsp))).Fmajor)
|
|
(*(*TFrameBound)(unsafe.Pointer(bp))).FpExpr = *(*uintptr)(unsafe.Pointer(yymsp + uintptr(-libc.Int32FromInt32(1))*12 + 4))
|
|
*(*TFrameBound)(unsafe.Pointer(yymsp + uintptr(-libc.Int32FromInt32(1))*12 + 4)) = *(*TFrameBound)(unsafe.Pointer(bp))
|
|
goto _350
|
|
_336:
|
|
; /* frame_exclude_opt ::= */
|
|
*(*Tu8)(unsafe.Pointer(yymsp + 1*12 + 4)) = uint8(0)
|
|
goto _350
|
|
_337:
|
|
; /* frame_exclude_opt ::= EXCLUDE frame_exclude */
|
|
*(*Tu8)(unsafe.Pointer(yymsp + uintptr(-libc.Int32FromInt32(1))*12 + 4)) = *(*Tu8)(unsafe.Pointer(yymsp + 4))
|
|
goto _350
|
|
_339:
|
|
; /* frame_exclude ::= NO OTHERS */
|
|
_338:
|
|
;
|
|
*(*Tu8)(unsafe.Pointer(yymsp + uintptr(-libc.Int32FromInt32(1))*12 + 4)) = uint8((**(**TyyStackEntry)(__ccgo_up(yymsp + uintptr(-libc.Int32FromInt32(1))*12))).Fmajor) /*A-overwrites-X*/
|
|
goto _350
|
|
_340:
|
|
; /* frame_exclude ::= GROUP|TIES */
|
|
*(*Tu8)(unsafe.Pointer(yymsp + 4)) = uint8((**(**TyyStackEntry)(__ccgo_up(yymsp))).Fmajor) /*A-overwrites-X*/
|
|
goto _350
|
|
_341:
|
|
; /* window_clause ::= WINDOW windowdefn_list */
|
|
*(*uintptr)(unsafe.Pointer(yymsp + uintptr(-libc.Int32FromInt32(1))*12 + 4)) = *(*uintptr)(unsafe.Pointer(yymsp + 4))
|
|
goto _350
|
|
_342:
|
|
; /* filter_over ::= filter_clause over_clause */
|
|
if *(*uintptr)(unsafe.Pointer(yymsp + 4)) != 0 {
|
|
(*TWindow)(unsafe.Pointer(*(*uintptr)(unsafe.Pointer(yymsp + 4)))).FpFilter = *(*uintptr)(unsafe.Pointer(yymsp + uintptr(-libc.Int32FromInt32(1))*12 + 4))
|
|
} else {
|
|
_sqlite3ExprDelete(tls, (*TParse)(unsafe.Pointer(pParse)).Fdb, *(*uintptr)(unsafe.Pointer(yymsp + uintptr(-libc.Int32FromInt32(1))*12 + 4)))
|
|
}
|
|
*(*uintptr)(unsafe.Pointer(&**(**TYYMINORTYPE)(__ccgo_up(bp)))) = *(*uintptr)(unsafe.Pointer(yymsp + 4))
|
|
*(*uintptr)(unsafe.Pointer(yymsp + uintptr(-libc.Int32FromInt32(1))*12 + 4)) = *(*uintptr)(unsafe.Pointer(&**(**TYYMINORTYPE)(__ccgo_up(bp))))
|
|
goto _350
|
|
_343:
|
|
; /* filter_over ::= over_clause */
|
|
*(*uintptr)(unsafe.Pointer(&**(**TYYMINORTYPE)(__ccgo_up(bp)))) = *(*uintptr)(unsafe.Pointer(yymsp + 4))
|
|
*(*uintptr)(unsafe.Pointer(yymsp + 4)) = *(*uintptr)(unsafe.Pointer(&**(**TYYMINORTYPE)(__ccgo_up(bp))))
|
|
goto _350
|
|
_344:
|
|
; /* filter_over ::= filter_clause */
|
|
*(*uintptr)(unsafe.Pointer(&**(**TYYMINORTYPE)(__ccgo_up(bp)))) = _sqlite3DbMallocZero(tls, (*TParse)(unsafe.Pointer(pParse)).Fdb, uint64(100))
|
|
if *(*uintptr)(unsafe.Pointer(&**(**TYYMINORTYPE)(__ccgo_up(bp)))) != 0 {
|
|
(*TWindow)(unsafe.Pointer(*(*uintptr)(unsafe.Pointer(&**(**TYYMINORTYPE)(__ccgo_up(bp)))))).FeFrmType = uint8(TK_FILTER)
|
|
(*TWindow)(unsafe.Pointer(*(*uintptr)(unsafe.Pointer(&**(**TYYMINORTYPE)(__ccgo_up(bp)))))).FpFilter = *(*uintptr)(unsafe.Pointer(yymsp + 4))
|
|
} else {
|
|
_sqlite3ExprDelete(tls, (*TParse)(unsafe.Pointer(pParse)).Fdb, *(*uintptr)(unsafe.Pointer(yymsp + 4)))
|
|
}
|
|
*(*uintptr)(unsafe.Pointer(yymsp + 4)) = *(*uintptr)(unsafe.Pointer(&**(**TYYMINORTYPE)(__ccgo_up(bp))))
|
|
goto _350
|
|
_345:
|
|
; /* over_clause ::= OVER LP window RP */
|
|
*(*uintptr)(unsafe.Pointer(yymsp + uintptr(-libc.Int32FromInt32(3))*12 + 4)) = *(*uintptr)(unsafe.Pointer(yymsp + uintptr(-libc.Int32FromInt32(1))*12 + 4))
|
|
goto _350
|
|
_346:
|
|
; /* over_clause ::= OVER nm */
|
|
*(*uintptr)(unsafe.Pointer(yymsp + uintptr(-libc.Int32FromInt32(1))*12 + 4)) = _sqlite3DbMallocZero(tls, (*TParse)(unsafe.Pointer(pParse)).Fdb, uint64(100))
|
|
if *(*uintptr)(unsafe.Pointer(yymsp + uintptr(-libc.Int32FromInt32(1))*12 + 4)) != 0 {
|
|
(*TWindow)(unsafe.Pointer(*(*uintptr)(unsafe.Pointer(yymsp + uintptr(-libc.Int32FromInt32(1))*12 + 4)))).FzName = _sqlite3DbStrNDup(tls, (*TParse)(unsafe.Pointer(pParse)).Fdb, *(*uintptr)(unsafe.Pointer(yymsp + 4)), uint64(*(*uint32)(unsafe.Pointer(yymsp + 4 + 4))))
|
|
}
|
|
goto _350
|
|
_347:
|
|
; /* filter_clause ::= FILTER LP WHERE expr RP */
|
|
*(*uintptr)(unsafe.Pointer(yymsp + uintptr(-libc.Int32FromInt32(4))*12 + 4)) = *(*uintptr)(unsafe.Pointer(yymsp + uintptr(-libc.Int32FromInt32(1))*12 + 4))
|
|
goto _350
|
|
_348:
|
|
; /* term ::= QNUMBER */
|
|
*(*uintptr)(unsafe.Pointer(&**(**TYYMINORTYPE)(__ccgo_up(bp)))) = _tokenExpr(tls, pParse, libc.Int32FromUint16((**(**TyyStackEntry)(__ccgo_up(yymsp))).Fmajor), *(*TToken)(unsafe.Pointer(yymsp + 4)))
|
|
_sqlite3DequoteNumber(tls, pParse, *(*uintptr)(unsafe.Pointer(&**(**TYYMINORTYPE)(__ccgo_up(bp)))))
|
|
*(*uintptr)(unsafe.Pointer(yymsp + 4)) = *(*uintptr)(unsafe.Pointer(&**(**TYYMINORTYPE)(__ccgo_up(bp))))
|
|
goto _350
|
|
_349:
|
|
;
|
|
goto _350
|
|
/********** End reduce actions ************************************************/
|
|
_350:
|
|
;
|
|
yygoto = libc.Int32FromUint16(_yyRuleInfoLhs[yyruleno])
|
|
yysize = int32(_yyRuleInfoNRhs[yyruleno])
|
|
yyact = _yy_find_reduce_action(tls, (**(**TyyStackEntry)(__ccgo_up(yymsp + uintptr(yysize)*12))).Fstateno, libc.Uint16FromInt32(yygoto))
|
|
/* There are no SHIFTREDUCE actions on nonterminals because the table
|
|
** generator has simplified them to pure REDUCE actions. */
|
|
/* It is not possible for a REDUCE to be followed by an error */
|
|
yymsp = yymsp + uintptr(yysize+int32(1))*12
|
|
(*TyyParser)(unsafe.Pointer(yypParser)).Fyytos = yymsp
|
|
(*TyyStackEntry)(unsafe.Pointer(yymsp)).Fstateno = yyact
|
|
(*TyyStackEntry)(unsafe.Pointer(yymsp)).Fmajor = libc.Uint16FromInt32(yygoto)
|
|
return yyact
|
|
}
|
|
|
|
/*
|
|
** The following code executes when the parse fails
|
|
*/
|
|
|
|
type t__float_t = float64
|
|
|
|
type t__time_t = int32
|