Files
Maven/vendor/modernc.org/sqlite/lib/sqlite_g_000000000000c4cf.go
T
kami 6c92f85d10 feat(ecosystem): compliant Praxis/Hexis integration + vendored build
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>
2026-07-19 20:24:33 +04:00

2245 lines
69 KiB
Go

// Code generated by modernc.org/undup from the per-target sqlite_*.go files; DO NOT EDIT.
//go:build (darwin && amd64) || (darwin && arm64) || (freebsd && 386) || (freebsd && amd64) || (linux && 386) || (linux && amd64) || (linux && loong64) || (netbsd && amd64) || (openbsd && amd64)
package sqlite3
import (
"unsafe"
"modernc.org/libc"
)
// C documentation
//
// /* Truncate the text of the string to be no more than N bytes. */
func Xsqlite3_str_truncate(tls *libc.TLS, p uintptr, N int32) {
if p != uintptr(0) && N >= 0 && libc.Uint32FromInt32(N) < (*Tsqlite3_str)(unsafe.Pointer(p)).FnChar {
(*Tsqlite3_str)(unsafe.Pointer(p)).FnChar = libc.Uint32FromInt32(N)
**(**int8)(__ccgo_up((*Tsqlite3_str)(unsafe.Pointer(p)).FzText + uintptr((*Tsqlite3_str)(unsafe.Pointer(p)).FnChar))) = 0
}
}
// C documentation
//
// /*
// ** Append all path elements in zPath to the DbPath under construction.
// */
func _appendAllPathElements(tls *libc.TLS, pPath uintptr, zPath uintptr) {
var i, j, v1 int32
_, _, _ = i, j, v1
i = 0
j = 0
for {
for **(**int8)(__ccgo_up(zPath + uintptr(i))) != 0 && int32(**(**int8)(__ccgo_up(zPath + uintptr(i)))) != int32('/') {
i = i + 1
}
if i > j {
_appendOnePathElement(tls, pPath, zPath+uintptr(j), i-j)
}
j = i + int32(1)
goto _2
_2:
;
v1 = i
i = i + 1
if !(**(**int8)(__ccgo_up(zPath + uintptr(v1))) != 0) {
break
}
}
}
// C documentation
//
// /*
// ** Return the P5 value that should be used for a binary comparison
// ** opcode (OP_Eq, OP_Ge etc.) used to compare pExpr1 and pExpr2.
// */
func _binaryCompareP5(tls *libc.TLS, pExpr1 uintptr, pExpr2 uintptr, jumpIfNull int32) (r Tu8) {
var aff Tu8
_ = aff
aff = libc.Uint8FromInt8(_sqlite3ExprAffinity(tls, pExpr2))
aff = libc.Uint8FromInt32(libc.Int32FromUint8(libc.Uint8FromInt8(_sqlite3CompareAffinity(tls, pExpr1, libc.Int8FromUint8(aff)))) | libc.Int32FromUint8(libc.Uint8FromInt32(jumpIfNull)))
return aff
}
func _fts5AsciiAddExceptions(tls *libc.TLS, p uintptr, zArg uintptr, bTokenChars int32) {
var i int32
_ = i
i = 0
for {
if !(**(**int8)(__ccgo_up(zArg + uintptr(i))) != 0) {
break
}
if int32(**(**int8)(__ccgo_up(zArg + uintptr(i))))&int32(0x80) == 0 {
**(**uint8)(__ccgo_up(p + uintptr(int32(**(**int8)(__ccgo_up(zArg + uintptr(i))))))) = libc.Uint8FromInt32(bTokenChars)
}
goto _1
_1:
;
i = i + 1
}
}
// C documentation
//
// /*
// ** Tokenize some text using the ascii tokenizer.
// */
func _fts5AsciiTokenize(tls *libc.TLS, pTokenizer uintptr, pCtx uintptr, iUnused int32, pText uintptr, nText int32, __ccgo_fp_xToken uintptr) (r int32) {
bp := tls.Alloc(64)
defer tls.Free(64)
var a, p, pFold uintptr
var ie, is, nByte, nFold, rc int32
var _ /* aFold at bp+0 */ [64]int8
_, _, _, _, _, _, _, _ = a, ie, is, nByte, nFold, p, pFold, rc
p = pTokenizer
rc = SQLITE_OK
is = 0
nFold = int32(64)
pFold = bp
a = p
_ = iUnused
for is < nText && rc == SQLITE_OK {
/* Skip any leading divider characters. */
for is < nText && (int32(**(**int8)(__ccgo_up(pText + uintptr(is))))&int32(0x80) == 0 && libc.Int32FromUint8(**(**uint8)(__ccgo_up(a + uintptr(int32(**(**int8)(__ccgo_up(pText + uintptr(is)))))))) == 0) {
is = is + 1
}
if is == nText {
break
}
/* Count the token characters */
ie = is + int32(1)
for ie < nText && (int32(**(**int8)(__ccgo_up(pText + uintptr(ie))))&int32(0x80) != 0 || **(**uint8)(__ccgo_up(a + uintptr(int32(**(**int8)(__ccgo_up(pText + uintptr(ie))))))) != 0) {
ie = ie + 1
}
/* Fold to lower case */
nByte = ie - is
if nByte > nFold {
if pFold != bp {
Xsqlite3_free(tls, pFold)
}
pFold = Xsqlite3_malloc64(tls, libc.Uint64FromInt64(int64(nByte)*int64(2)))
if pFold == uintptr(0) {
rc = int32(SQLITE_NOMEM)
break
}
nFold = nByte * int32(2)
}
_asciiFold(tls, pFold, pText+uintptr(is), nByte)
/* Invoke the token callback */
rc = (*(*func(*libc.TLS, uintptr, int32, uintptr, int32, int32, int32) int32)(unsafe.Pointer(&struct{ uintptr }{__ccgo_fp_xToken})))(tls, pCtx, 0, pFold, nByte, is, ie)
is = ie + int32(1)
}
if pFold != bp {
Xsqlite3_free(tls, pFold)
}
if rc == int32(SQLITE_DONE) {
rc = SQLITE_OK
}
return rc
}
/**************************************************************************
** Start of unicode61 tokenizer implementation.
*/
/*
** The following two macros - READ_UTF8 and WRITE_UTF8 - have been copied
** from the sqlite3 source file utf.c. If this file is compiled as part
** of the amalgamation, they are not required.
*/
// C documentation
//
// /*
// ** pIn is a UTF-8 encoded string, nIn bytes in size. Return the number of
// ** unicode characters in the string.
// */
func _fts5IndexCharlen(tls *libc.TLS, pIn uintptr, nIn int32) (r int32) {
var i, nChar, v1 int32
_, _, _ = i, nChar, v1
nChar = 0
i = 0
for i < nIn {
v1 = i
i = i + 1
if libc.Int32FromUint8(libc.Uint8FromInt8(**(**int8)(__ccgo_up(pIn + uintptr(v1))))) >= int32(0xc0) {
for i < nIn && int32(**(**int8)(__ccgo_up(pIn + uintptr(i))))&int32(0xc0) == int32(0x80) {
i = i + 1
}
}
nChar = nChar + 1
}
return nChar
}
// C documentation
//
// /* Parse out a number. Write the value into *pVal if pVal!=0.
// ** return non-zero on success and zero if the next token is not a number.
// */
func _geopolyParseNumber(tls *libc.TLS, p uintptr, pVal uintptr) (r int32) {
bp := tls.Alloc(16)
defer tls.Free(16)
var c int8
var j, seenDP, seenE, v2 int32
var z uintptr
var _ /* r at bp+0 */ float64
_, _, _, _, _, _ = c, j, seenDP, seenE, z, v2
c = _geopolySkipSpace(tls, p)
z = (*TGeoParse)(unsafe.Pointer(p)).Fz
j = 0
seenDP = 0
seenE = 0
if int32(c) == int32('-') {
j = int32(1)
c = libc.Int8FromUint8(**(**uint8)(__ccgo_up(z + uintptr(j))))
}
if int32(c) == int32('0') && libc.Int32FromUint8(**(**uint8)(__ccgo_up(z + uintptr(j+int32(1))))) >= int32('0') && libc.Int32FromUint8(**(**uint8)(__ccgo_up(z + uintptr(j+int32(1))))) <= int32('9') {
return 0
}
for {
c = libc.Int8FromUint8(**(**uint8)(__ccgo_up(z + uintptr(j))))
if libc.Int32FromUint8(_sqlite3CtypeMap[libc.Uint8FromInt8(c)])&int32(0x04) != 0 {
goto _1
}
if int32(c) == int32('.') {
if libc.Int32FromUint8(**(**uint8)(__ccgo_up(z + uintptr(j-int32(1))))) == int32('-') {
return 0
}
if seenDP != 0 {
return 0
}
seenDP = int32(1)
goto _1
}
if int32(c) == int32('e') || int32(c) == int32('E') {
if libc.Int32FromUint8(**(**uint8)(__ccgo_up(z + uintptr(j-int32(1))))) < int32('0') {
return 0
}
if seenE != 0 {
return -int32(1)
}
v2 = libc.Int32FromInt32(1)
seenE = v2
seenDP = v2
c = libc.Int8FromUint8(**(**uint8)(__ccgo_up(z + uintptr(j+int32(1)))))
if int32(c) == int32('+') || int32(c) == int32('-') {
j = j + 1
c = libc.Int8FromUint8(**(**uint8)(__ccgo_up(z + uintptr(j+int32(1)))))
}
if int32(c) < int32('0') || int32(c) > int32('9') {
return 0
}
goto _1
}
break
goto _1
_1:
;
j = j + 1
}
if libc.Int32FromUint8(**(**uint8)(__ccgo_up(z + uintptr(j-int32(1))))) < int32('0') {
return 0
}
if pVal != 0 {
_sqlite3AtoF(tls, (*TGeoParse)(unsafe.Pointer(p)).Fz, bp)
**(**TGeoCoord)(__ccgo_up(pVal)) = float32(**(**float64)(__ccgo_up(bp)))
}
**(**uintptr)(__ccgo_up(p)) += uintptr(j)
return int32(1)
}
// C documentation
//
// /* Skip whitespace. Return the next non-whitespace character. */
func _geopolySkipSpace(tls *libc.TLS, p uintptr) (r int8) {
for _geopolyIsSpace[**(**uint8)(__ccgo_up((*TGeoParse)(unsafe.Pointer(p)).Fz))] != 0 {
(*TGeoParse)(unsafe.Pointer(p)).Fz = (*TGeoParse)(unsafe.Pointer(p)).Fz + 1
}
return libc.Int8FromUint8(**(**uint8)(__ccgo_up((*TGeoParse)(unsafe.Pointer(p)).Fz)))
}
// C documentation
//
// /*
// ** Convert zDate into one or more integers according to the conversion
// ** specifier zFormat.
// **
// ** zFormat[] contains 4 characters for each integer converted, except for
// ** the last integer which is specified by three characters. The meaning
// ** of a four-character format specifiers ABCD is:
// **
// ** A: number of digits to convert. Always "2" or "4".
// ** B: minimum value. Always "0" or "1".
// ** C: maximum value, decoded as:
// ** a: 12
// ** b: 14
// ** c: 24
// ** d: 31
// ** e: 59
// ** f: 9999
// ** D: the separator character, or \000 to indicate this is the
// ** last number to convert.
// **
// ** Example: To translate an ISO-8601 date YYYY-MM-DD, the format would
// ** be "40f-21a-20c". The "40f-" indicates the 4-digit year followed by "-".
// ** The "21a-" indicates the 2-digit month followed by "-". The "20c" indicates
// ** the 2-digit day which is the last integer in the set.
// **
// ** The function returns the number of successful conversions.
// */
func _getDigits(tls *libc.TLS, zDate uintptr, zFormat uintptr, va uintptr) (r int32) {
var N, min, nextC, v1 int8
var ap Tva_list
var cnt, val int32
var max Tu16
_, _, _, _, _, _, _, _ = N, ap, cnt, max, min, nextC, val, v1
cnt = 0
ap = va
for cond := true; cond; cond = nextC != 0 {
N = int8(int32(**(**int8)(__ccgo_up(zFormat))) - int32('0'))
min = int8(int32(**(**int8)(__ccgo_up(zFormat + 1))) - int32('0'))
val = 0
max = _aMx[int32(**(**int8)(__ccgo_up(zFormat + 2)))-int32('a')]
nextC = **(**int8)(__ccgo_up(zFormat + 3))
val = 0
for {
v1 = N
N = N - 1
if !(v1 != 0) {
break
}
if !(libc.Int32FromUint8(_sqlite3CtypeMap[libc.Uint8FromInt8(**(**int8)(__ccgo_up(zDate)))])&libc.Int32FromInt32(0x04) != 0) {
goto end_getDigits
}
val = val*int32(10) + int32(**(**int8)(__ccgo_up(zDate))) - int32('0')
zDate = zDate + 1
}
if val < int32(min) || val > libc.Int32FromUint16(max) || int32(nextC) != 0 && int32(nextC) != int32(**(**int8)(__ccgo_up(zDate))) {
goto end_getDigits
}
**(**int32)(__ccgo_up(libc.VaUintptr(&ap))) = val
zDate = zDate + 1
cnt = cnt + 1
zFormat = zFormat + uintptr(4)
}
goto end_getDigits
end_getDigits:
;
_ = ap
return cnt
}
// C documentation
//
// /*
// ** The first parameter is a pointer to an output buffer. The second
// ** parameter is a pointer to an integer that contains the offset at
// ** which to write into the output buffer. This function copies the
// ** nul-terminated string pointed to by the third parameter, zSignedIdent,
// ** to the specified offset in the buffer and updates *pIdx to refer
// ** to the first byte after the last byte written before returning.
// **
// ** If the string zSignedIdent consists entirely of alphanumeric
// ** characters, does not begin with a digit and is not an SQL keyword,
// ** then it is copied to the output buffer exactly as it is. Otherwise,
// ** it is quoted using double-quotes.
// */
func _identPut(tls *libc.TLS, z uintptr, pIdx uintptr, zSignedIdent uintptr) {
var i, j, needQuote, v2 int32
var zIdent uintptr
_, _, _, _, _ = i, j, needQuote, zIdent, v2
zIdent = zSignedIdent
i = **(**int32)(__ccgo_up(pIdx))
j = 0
for {
if !(**(**uint8)(__ccgo_up(zIdent + uintptr(j))) != 0) {
break
}
if !(libc.Int32FromUint8(_sqlite3CtypeMap[**(**uint8)(__ccgo_up(zIdent + uintptr(j)))])&libc.Int32FromInt32(0x06) != 0) && libc.Int32FromUint8(**(**uint8)(__ccgo_up(zIdent + uintptr(j)))) != int32('_') {
break
}
goto _1
_1:
;
j = j + 1
}
needQuote = libc.BoolInt32(libc.Int32FromUint8(_sqlite3CtypeMap[**(**uint8)(__ccgo_up(zIdent))])&int32(0x04) != 0 || _sqlite3KeywordCode(tls, zIdent, j) != int32(TK_ID) || libc.Int32FromUint8(**(**uint8)(__ccgo_up(zIdent + uintptr(j)))) != 0 || j == 0)
if needQuote != 0 {
v2 = i
i = i + 1
**(**int8)(__ccgo_up(z + uintptr(v2))) = int8('"')
}
j = 0
for {
if !(**(**uint8)(__ccgo_up(zIdent + uintptr(j))) != 0) {
break
}
v2 = i
i = i + 1
**(**int8)(__ccgo_up(z + uintptr(v2))) = libc.Int8FromUint8(**(**uint8)(__ccgo_up(zIdent + uintptr(j))))
if libc.Int32FromUint8(**(**uint8)(__ccgo_up(zIdent + uintptr(j)))) == int32('"') {
v2 = i
i = i + 1
**(**int8)(__ccgo_up(z + uintptr(v2))) = int8('"')
}
goto _3
_3:
;
j = j + 1
}
if needQuote != 0 {
v2 = i
i = i + 1
**(**int8)(__ccgo_up(z + uintptr(v2))) = int8('"')
}
**(**int8)(__ccgo_up(z + uintptr(i))) = 0
**(**int32)(__ccgo_up(pIdx)) = i
}
// C documentation
//
// /*
// ** Return true if z[] begins with N hexadecimal digits, and write
// ** a decoding of those digits into *pVal. Or return false if any
// ** one of the first N characters in z[] is not a hexadecimal digit.
// */
func _isNHex(tls *libc.TLS, z uintptr, N int32, pVal uintptr) (r int32) {
var i int32
var v Tu32
_, _ = i, v
v = uint32(0)
i = 0
for {
if !(i < N) {
break
}
if !(libc.Int32FromUint8(_sqlite3CtypeMap[libc.Uint8FromInt8(**(**int8)(__ccgo_up(z + uintptr(i))))])&libc.Int32FromInt32(0x08) != 0) {
return 0
}
v = v<<libc.Int32FromInt32(4) + uint32(_sqlite3HexToInt(tls, int32(**(**int8)(__ccgo_up(z + uintptr(i))))))
goto _1
_1:
;
i = i + 1
}
**(**Tu32)(__ccgo_up(pVal)) = v
return int32(1)
}
// C documentation
//
// /*
// ** Return the number of bytes of JSON5 whitespace at the beginning of
// ** the input string z[].
// **
// ** JSON5 whitespace consists of any of the following characters:
// **
// ** Unicode UTF-8 Name
// ** U+0009 09 horizontal tab
// ** U+000a 0a line feed
// ** U+000b 0b vertical tab
// ** U+000c 0c form feed
// ** U+000d 0d carriage return
// ** U+0020 20 space
// ** U+00a0 c2 a0 non-breaking space
// ** U+1680 e1 9a 80 ogham space mark
// ** U+2000 e2 80 80 en quad
// ** U+2001 e2 80 81 em quad
// ** U+2002 e2 80 82 en space
// ** U+2003 e2 80 83 em space
// ** U+2004 e2 80 84 three-per-em space
// ** U+2005 e2 80 85 four-per-em space
// ** U+2006 e2 80 86 six-per-em space
// ** U+2007 e2 80 87 figure space
// ** U+2008 e2 80 88 punctuation space
// ** U+2009 e2 80 89 thin space
// ** U+200a e2 80 8a hair space
// ** U+2028 e2 80 a8 line separator
// ** U+2029 e2 80 a9 paragraph separator
// ** U+202f e2 80 af narrow no-break space (NNBSP)
// ** U+205f e2 81 9f medium mathematical space (MMSP)
// ** U+3000 e3 80 80 ideographical space
// ** U+FEFF ef bb bf byte order mark
// **
// ** In addition, comments between '/', '*' and '*', '/' and
// ** from '/', '/' to end-of-line are also considered to be whitespace.
// */
func _json5Whitespace(tls *libc.TLS, zIn uintptr) (r int32) {
var c, v3 int8
var c1 Tu8
var j, j1, n int32
var z uintptr
_, _, _, _, _, _, _ = c, c1, j, j1, n, z, v3
n = 0
z = zIn
for int32(1) != 0 {
switch libc.Int32FromUint8(**(**Tu8)(__ccgo_up(z + uintptr(n)))) {
case int32(0x09):
fallthrough
case int32(0x0a):
fallthrough
case int32(0x0b):
fallthrough
case int32(0x0c):
fallthrough
case int32(0x0d):
fallthrough
case int32(0x20):
n = n + 1
case int32('/'):
if libc.Int32FromUint8(**(**Tu8)(__ccgo_up(z + uintptr(n+int32(1))))) == int32('*') && libc.Int32FromUint8(**(**Tu8)(__ccgo_up(z + uintptr(n+int32(2))))) != 0 {
j = n + int32(3)
for {
if !(libc.Int32FromUint8(**(**Tu8)(__ccgo_up(z + uintptr(j)))) != int32('/') || libc.Int32FromUint8(**(**Tu8)(__ccgo_up(z + uintptr(j-int32(1))))) != int32('*')) {
break
}
if libc.Int32FromUint8(**(**Tu8)(__ccgo_up(z + uintptr(j)))) == 0 {
goto whitespace_done
}
goto _1
_1:
;
j = j + 1
}
n = j + int32(1)
break
} else {
if libc.Int32FromUint8(**(**Tu8)(__ccgo_up(z + uintptr(n+int32(1))))) == int32('/') {
j1 = n + int32(2)
for {
v3 = libc.Int8FromUint8(**(**Tu8)(__ccgo_up(z + uintptr(j1))))
c = v3
if !(int32(v3) != 0) {
break
}
if int32(c) == int32('\n') || int32(c) == int32('\r') {
break
}
if int32(0xe2) == libc.Int32FromUint8(libc.Uint8FromInt8(c)) && int32(0x80) == libc.Int32FromUint8(**(**Tu8)(__ccgo_up(z + uintptr(j1+int32(1))))) && (int32(0xa8) == libc.Int32FromUint8(**(**Tu8)(__ccgo_up(z + uintptr(j1+int32(2))))) || int32(0xa9) == libc.Int32FromUint8(**(**Tu8)(__ccgo_up(z + uintptr(j1+int32(2)))))) {
j1 = j1 + int32(2)
break
}
goto _2
_2:
;
j1 = j1 + 1
}
n = j1
if **(**Tu8)(__ccgo_up(z + uintptr(n))) != 0 {
n = n + 1
}
break
}
}
goto whitespace_done
case int32(0xc2):
if libc.Int32FromUint8(**(**Tu8)(__ccgo_up(z + uintptr(n+int32(1))))) == int32(0xa0) {
n = n + int32(2)
break
}
goto whitespace_done
case int32(0xe1):
if libc.Int32FromUint8(**(**Tu8)(__ccgo_up(z + uintptr(n+int32(1))))) == int32(0x9a) && libc.Int32FromUint8(**(**Tu8)(__ccgo_up(z + uintptr(n+int32(2))))) == int32(0x80) {
n = n + int32(3)
break
}
goto whitespace_done
case int32(0xe2):
if libc.Int32FromUint8(**(**Tu8)(__ccgo_up(z + uintptr(n+int32(1))))) == int32(0x80) {
c1 = **(**Tu8)(__ccgo_up(z + uintptr(n+int32(2))))
if libc.Int32FromUint8(c1) < int32(0x80) {
goto whitespace_done
}
if libc.Int32FromUint8(c1) <= int32(0x8a) || libc.Int32FromUint8(c1) == int32(0xa8) || libc.Int32FromUint8(c1) == int32(0xa9) || libc.Int32FromUint8(c1) == int32(0xaf) {
n = n + int32(3)
break
}
} else {
if libc.Int32FromUint8(**(**Tu8)(__ccgo_up(z + uintptr(n+int32(1))))) == int32(0x81) && libc.Int32FromUint8(**(**Tu8)(__ccgo_up(z + uintptr(n+int32(2))))) == int32(0x9f) {
n = n + int32(3)
break
}
}
goto whitespace_done
case int32(0xe3):
if libc.Int32FromUint8(**(**Tu8)(__ccgo_up(z + uintptr(n+int32(1))))) == int32(0x80) && libc.Int32FromUint8(**(**Tu8)(__ccgo_up(z + uintptr(n+int32(2))))) == int32(0x80) {
n = n + int32(3)
break
}
goto whitespace_done
case int32(0xef):
if libc.Int32FromUint8(**(**Tu8)(__ccgo_up(z + uintptr(n+int32(1))))) == int32(0xbb) && libc.Int32FromUint8(**(**Tu8)(__ccgo_up(z + uintptr(n+int32(2))))) == int32(0xbf) {
n = n + int32(3)
break
}
goto whitespace_done
default:
goto whitespace_done
}
}
goto whitespace_done
whitespace_done:
;
return n
return r
}
// C documentation
//
// /* True if the string is all alphanumerics and underscores */
func _jsonAllAlphanum(tls *libc.TLS, z uintptr, n int32) (r int32) {
var i int32
_ = i
i = 0
for {
if !(i < n && (libc.Int32FromUint8(_sqlite3CtypeMap[libc.Uint8FromInt8(**(**int8)(__ccgo_up(z + uintptr(i))))])&int32(0x06) != 0 || int32(**(**int8)(__ccgo_up(z + uintptr(i)))) == int32('_'))) {
break
}
goto _1
_1:
;
i = i + 1
}
return libc.BoolInt32(i == n)
}
// C documentation
//
// /*
// ** Return the number of escaped newlines to be ignored.
// ** An escaped newline is a one of the following byte sequences:
// **
// ** 0x5c 0x0a
// ** 0x5c 0x0d
// ** 0x5c 0x0d 0x0a
// ** 0x5c 0xe2 0x80 0xa8
// ** 0x5c 0xe2 0x80 0xa9
// */
func _jsonBytesToBypass(tls *libc.TLS, z uintptr, n Tu32) (r Tu32) {
var i Tu32
_ = i
i = uint32(0)
for i+uint32(1) < n {
if int32(**(**int8)(__ccgo_up(z + uintptr(i)))) != int32('\\') {
return i
}
if int32(**(**int8)(__ccgo_up(z + uintptr(i+uint32(1))))) == int32('\n') {
i = i + uint32(2)
continue
}
if int32(**(**int8)(__ccgo_up(z + uintptr(i+uint32(1))))) == int32('\r') {
if i+uint32(2) < n && int32(**(**int8)(__ccgo_up(z + uintptr(i+uint32(2))))) == int32('\n') {
i = i + uint32(3)
} else {
i = i + uint32(2)
}
continue
}
if int32(0xe2) == libc.Int32FromUint8(libc.Uint8FromInt8(**(**int8)(__ccgo_up(z + uintptr(i+uint32(1)))))) && i+uint32(3) < n && int32(0x80) == libc.Int32FromUint8(libc.Uint8FromInt8(**(**int8)(__ccgo_up(z + uintptr(i+uint32(2)))))) && (int32(0xa8) == libc.Int32FromUint8(libc.Uint8FromInt8(**(**int8)(__ccgo_up(z + uintptr(i+uint32(3)))))) || int32(0xa9) == libc.Int32FromUint8(libc.Uint8FromInt8(**(**int8)(__ccgo_up(z + uintptr(i+uint32(3))))))) {
i = i + uint32(4)
continue
}
break
}
return i
}
// C documentation
//
// /*
// ** Convert a 4-byte hex string into an integer
// */
func _jsonHexToInt4(tls *libc.TLS, z uintptr) (r Tu32) {
var v Tu32
_ = v
v = libc.Uint32FromInt32(libc.Int32FromUint8(_jsonHexToInt(tls, int32(**(**int8)(__ccgo_up(z)))))<<int32(12) + libc.Int32FromUint8(_jsonHexToInt(tls, int32(**(**int8)(__ccgo_up(z + 1)))))<<int32(8) + libc.Int32FromUint8(_jsonHexToInt(tls, int32(**(**int8)(__ccgo_up(z + 2)))))<<int32(4) + libc.Int32FromUint8(_jsonHexToInt(tls, int32(**(**int8)(__ccgo_up(z + 3))))))
return v
}
// C documentation
//
// /*
// ** Return true if z[] begins with 2 (or more) hexadecimal digits
// */
func _jsonIs2Hex(tls *libc.TLS, z uintptr) (r int32) {
return libc.BoolInt32(libc.Int32FromUint8(_sqlite3CtypeMap[libc.Uint8FromInt8(**(**int8)(__ccgo_up(z)))])&int32(0x08) != 0 && libc.Int32FromUint8(_sqlite3CtypeMap[libc.Uint8FromInt8(**(**int8)(__ccgo_up(z + 1)))])&int32(0x08) != 0)
}
// C documentation
//
// /*
// ** Compare two object labels. Return 1 if they are equal and
// ** 0 if they differ.
// **
// ** In this version, we know that one or the other or both of the
// ** two comparands contains an escape sequence.
// */
func _jsonLabelCompareEscaped(tls *libc.TLS, zLeft uintptr, nLeft Tu32, rawLeft int32, zRight uintptr, nRight Tu32, rawRight int32) (r int32) {
bp := tls.Alloc(16)
defer tls.Free(16)
var n, n1 Tu32
var sz, sz1 int32
var _ /* cLeft at bp+0 */ Tu32
var _ /* cRight at bp+4 */ Tu32
_, _, _, _ = n, n1, sz, sz1
for int32(1) != 0 {
if nLeft == uint32(0) {
**(**Tu32)(__ccgo_up(bp)) = uint32(0)
} else {
if rawLeft != 0 || int32(**(**int8)(__ccgo_up(zLeft))) != int32('\\') {
**(**Tu32)(__ccgo_up(bp)) = uint32(**(**Tu8)(__ccgo_up(zLeft)))
if **(**Tu32)(__ccgo_up(bp)) >= uint32(0xc0) {
sz = _sqlite3Utf8ReadLimited(tls, zLeft, libc.Int32FromUint32(nLeft), bp)
zLeft = zLeft + uintptr(sz)
nLeft = nLeft - libc.Uint32FromInt32(sz)
} else {
zLeft = zLeft + 1
nLeft = nLeft - 1
}
} else {
n = _jsonUnescapeOneChar(tls, zLeft, nLeft, bp)
zLeft = zLeft + uintptr(n)
nLeft = nLeft - n
}
}
if nRight == uint32(0) {
**(**Tu32)(__ccgo_up(bp + 4)) = uint32(0)
} else {
if rawRight != 0 || int32(**(**int8)(__ccgo_up(zRight))) != int32('\\') {
**(**Tu32)(__ccgo_up(bp + 4)) = uint32(**(**Tu8)(__ccgo_up(zRight)))
if **(**Tu32)(__ccgo_up(bp + 4)) >= uint32(0xc0) {
sz1 = _sqlite3Utf8ReadLimited(tls, zRight, libc.Int32FromUint32(nRight), bp+4)
zRight = zRight + uintptr(sz1)
nRight = nRight - libc.Uint32FromInt32(sz1)
} else {
zRight = zRight + 1
nRight = nRight - 1
}
} else {
n1 = _jsonUnescapeOneChar(tls, zRight, nRight, bp+4)
zRight = zRight + uintptr(n1)
nRight = nRight - n1
}
}
if **(**Tu32)(__ccgo_up(bp)) != **(**Tu32)(__ccgo_up(bp + 4)) {
return 0
}
if **(**Tu32)(__ccgo_up(bp)) == uint32(0) {
return int32(1)
}
}
return r
}
// C documentation
//
// /* Make sure there is a zero terminator on p->zBuf[]
// **
// ** Return true on success. Return false if an OOM prevents this
// ** from happening.
// */
func _jsonStringTerminate(tls *libc.TLS, p uintptr) (r int32) {
_jsonAppendChar(tls, p, 0)
_jsonStringTrimOneChar(tls, p)
return libc.BoolInt32(libc.Int32FromUint8((*TJsonString)(unsafe.Pointer(p)).FeErr) == 0)
}
// C documentation
//
// /*
// ** Input z[0..n] defines JSON escape sequence including the leading '\\'.
// ** Decode that escape sequence into a single character. Write that
// ** character into *piOut. Return the number of bytes in the escape sequence.
// **
// ** If there is a syntax error of some kind (for example too few characters
// ** after the '\\' to complete the encoding) then *piOut is set to
// ** JSON_INVALID_CHAR.
// */
func _jsonUnescapeOneChar(tls *libc.TLS, z uintptr, n Tu32, piOut uintptr) (r Tu32) {
var nSkip, v, vlo, v1 Tu32
var sz, v3 int32
var v2 bool
_, _, _, _, _, _, _ = nSkip, sz, v, vlo, v1, v2, v3
if n < uint32(2) {
**(**Tu32)(__ccgo_up(piOut)) = uint32(JSON_INVALID_CHAR)
return n
}
switch libc.Int32FromUint8(libc.Uint8FromInt8(**(**int8)(__ccgo_up(z + 1)))) {
case int32('u'):
if n < uint32(6) {
**(**Tu32)(__ccgo_up(piOut)) = uint32(JSON_INVALID_CHAR)
return n
}
v = _jsonHexToInt4(tls, z+2)
if v2 = v&uint32(0xfc00) == uint32(0xd800) && n >= uint32(12) && int32(**(**int8)(__ccgo_up(z + 6))) == int32('\\') && int32(**(**int8)(__ccgo_up(z + 7))) == int32('u'); v2 {
v1 = _jsonHexToInt4(tls, z+8)
vlo = v1
}
if v2 && v1&uint32(0xfc00) == uint32(0xdc00) {
**(**Tu32)(__ccgo_up(piOut)) = v&uint32(0x3ff)<<int32(10) + vlo&uint32(0x3ff) + uint32(0x10000)
return uint32(12)
} else {
**(**Tu32)(__ccgo_up(piOut)) = v
return uint32(6)
}
fallthrough
case int32('b'):
**(**Tu32)(__ccgo_up(piOut)) = uint32('\b')
return uint32(2)
case int32('f'):
**(**Tu32)(__ccgo_up(piOut)) = uint32('\f')
return uint32(2)
case int32('n'):
**(**Tu32)(__ccgo_up(piOut)) = uint32('\n')
return uint32(2)
case int32('r'):
**(**Tu32)(__ccgo_up(piOut)) = uint32('\r')
return uint32(2)
case int32('t'):
**(**Tu32)(__ccgo_up(piOut)) = uint32('\t')
return uint32(2)
case int32('v'):
**(**Tu32)(__ccgo_up(piOut)) = uint32('\v')
return uint32(2)
case int32('0'):
/* JSON5 requires that the \0 escape not be followed by a digit.
** But SQLite did not enforce this restriction in versions 3.42.0
** through 3.49.2. That was a bug. But some applications might have
** come to depend on that bug. Use the SQLITE_BUG_COMPATIBLE_20250510
** option to restore the old buggy behavior. */
/* Correct behavior */
if n > uint32(2) && libc.Int32FromUint8(_sqlite3CtypeMap[libc.Uint8FromInt8(**(**int8)(__ccgo_up(z + 2)))])&int32(0x04) != 0 {
v3 = int32(JSON_INVALID_CHAR)
} else {
v3 = 0
}
**(**Tu32)(__ccgo_up(piOut)) = libc.Uint32FromInt32(v3)
return uint32(2)
case int32('\''):
fallthrough
case int32('"'):
fallthrough
case int32('/'):
fallthrough
case int32('\\'):
**(**Tu32)(__ccgo_up(piOut)) = libc.Uint32FromInt8(**(**int8)(__ccgo_up(z + 1)))
return uint32(2)
case int32('x'):
if n < uint32(4) {
**(**Tu32)(__ccgo_up(piOut)) = uint32(JSON_INVALID_CHAR)
return n
}
**(**Tu32)(__ccgo_up(piOut)) = libc.Uint32FromInt32(libc.Int32FromUint8(_jsonHexToInt(tls, int32(**(**int8)(__ccgo_up(z + 2)))))<<int32(4) | libc.Int32FromUint8(_jsonHexToInt(tls, int32(**(**int8)(__ccgo_up(z + 3))))))
return uint32(4)
case int32(0xe2):
fallthrough
case int32('\r'):
fallthrough
case int32('\n'):
nSkip = _jsonBytesToBypass(tls, z, n)
if nSkip == uint32(0) {
**(**Tu32)(__ccgo_up(piOut)) = uint32(JSON_INVALID_CHAR)
return n
} else {
if nSkip == n {
**(**Tu32)(__ccgo_up(piOut)) = uint32(0)
return n
} else {
if int32(**(**int8)(__ccgo_up(z + uintptr(nSkip)))) == int32('\\') {
return nSkip + _jsonUnescapeOneChar(tls, z+uintptr(nSkip), n-nSkip, piOut)
} else {
sz = _sqlite3Utf8ReadLimited(tls, z+uintptr(nSkip), libc.Int32FromUint32(n-nSkip), piOut)
return nSkip + libc.Uint32FromInt32(sz)
}
}
}
fallthrough
default:
**(**Tu32)(__ccgo_up(piOut)) = uint32(JSON_INVALID_CHAR)
return uint32(2)
}
return r
}
// C documentation
//
// /* Hash table decoded:
// ** 0: INSERT
// ** 1: IS
// ** 2: ROLLBACK TRIGGER
// ** 3: IMMEDIATE
// ** 4: PARTITION
// ** 5: TEMP
// ** 6:
// ** 7:
// ** 8: VALUES WITHOUT
// ** 9:
// ** 10: MATCH
// ** 11: NOTHING
// ** 12:
// ** 13: OF
// ** 14: TIES IGNORE
// ** 15: PLAN
// ** 16: INSTEAD INDEXED
// ** 17:
// ** 18: TRANSACTION RIGHT
// ** 19: WHEN
// ** 20: SET HAVING
// ** 21: MATERIALIZED IF
// ** 22: ROWS
// ** 23: SELECT
// ** 24:
// ** 25:
// ** 26: VACUUM SAVEPOINT
// ** 27:
// ** 28: LIKE UNION VIRTUAL REFERENCES
// ** 29: RESTRICT
// ** 30:
// ** 31: THEN REGEXP
// ** 32: TO
// ** 33:
// ** 34: BEFORE
// ** 35:
// ** 36:
// ** 37: FOLLOWING COLLATE CASCADE
// ** 38: CREATE
// ** 39:
// ** 40: CASE REINDEX
// ** 41: EACH
// ** 42:
// ** 43: QUERY
// ** 44: AND ADD
// ** 45: PRIMARY ANALYZE
// ** 46:
// ** 47: ROW ASC DETACH
// ** 48: CURRENT_TIME CURRENT_DATE
// ** 49:
// ** 50:
// ** 51: EXCLUSIVE TEMPORARY
// ** 52:
// ** 53: DEFERRED
// ** 54: DEFERRABLE
// ** 55:
// ** 56: DATABASE
// ** 57:
// ** 58: DELETE VIEW GENERATED
// ** 59: ATTACH
// ** 60: END
// ** 61: EXCLUDE
// ** 62: ESCAPE DESC
// ** 63: GLOB
// ** 64: WINDOW ELSE
// ** 65: COLUMN
// ** 66: FIRST
// ** 67:
// ** 68: GROUPS ALL
// ** 69: DISTINCT DROP KEY
// ** 70: BETWEEN
// ** 71: INITIALLY
// ** 72: BEGIN
// ** 73: FILTER CHECK ACTION
// ** 74: GROUP INDEX
// ** 75:
// ** 76: EXISTS DEFAULT
// ** 77:
// ** 78: FOR CURRENT_TIMESTAMP
// ** 79: EXCEPT
// ** 80:
// ** 81: CROSS
// ** 82:
// ** 83:
// ** 84:
// ** 85: CAST
// ** 86: FOREIGN AUTOINCREMENT
// ** 87: COMMIT
// ** 88: CURRENT AFTER ALTER
// ** 89: FULL FAIL CONFLICT
// ** 90: EXPLAIN
// ** 91: CONSTRAINT
// ** 92: FROM ALWAYS
// ** 93:
// ** 94: ABORT
// ** 95:
// ** 96: AS DO
// ** 97: REPLACE WITH RELEASE
// ** 98: BY RENAME
// ** 99: RANGE RAISE
// ** 100: OTHERS
// ** 101: USING NULLS
// ** 102: PRAGMA
// ** 103: JOIN ISNULL OFFSET
// ** 104: NOT
// ** 105: OR LAST LEFT
// ** 106: LIMIT
// ** 107:
// ** 108:
// ** 109: IN
// ** 110: INTO
// ** 111: OVER RECURSIVE
// ** 112: ORDER OUTER
// ** 113:
// ** 114: INTERSECT UNBOUNDED
// ** 115:
// ** 116:
// ** 117: RETURNING ON
// ** 118:
// ** 119: WHERE
// ** 120: NO INNER
// ** 121: NULL
// ** 122:
// ** 123: TABLE
// ** 124: NATURAL NOTNULL
// ** 125: PRECEDING
// ** 126: UPDATE UNIQUE
// */
// /* Check to see if z[0..n-1] is a keyword. If it is, write the
// ** parser symbol code for that keyword into *pType. Always
// ** return the integer n (the length of the token). */
func _keywordCode(tls *libc.TLS, z uintptr, n Ti64, pType uintptr) (r Ti64) {
var i, j Ti64
var zKW uintptr
_, _, _ = i, j, zKW
i = (int64(libc.Int32FromUint8(_sqlite3UpperToLower[libc.Uint8FromInt8(**(**int8)(__ccgo_up(z)))])*int32(4)^libc.Int32FromUint8(_sqlite3UpperToLower[libc.Uint8FromInt8(**(**int8)(__ccgo_up(z + uintptr(n-int64(1)))))])*int32(3)) ^ n*int64(1)) % int64(127)
i = int64(libc.Int32FromUint8(_aKWHash[i]))
for {
if !(i > 0) {
break
}
if libc.Int64FromUint8(_aKWLen[i]) != n {
goto _1
}
zKW = uintptr(unsafe.Pointer(&_zKWText)) + uintptr(_aKWOffset[i])
if int32(**(**int8)(__ccgo_up(z))) & ^libc.Int32FromInt32(0x20) != int32(**(**int8)(__ccgo_up(zKW))) {
goto _1
}
if int32(**(**int8)(__ccgo_up(z + 1))) & ^libc.Int32FromInt32(0x20) != int32(**(**int8)(__ccgo_up(zKW + 1))) {
goto _1
}
j = int64(2)
for j < n && int32(**(**int8)(__ccgo_up(z + uintptr(j)))) & ^libc.Int32FromInt32(0x20) == int32(**(**int8)(__ccgo_up(zKW + uintptr(j)))) {
j = j + 1
}
if j < n {
goto _1
}
/* REINDEX */
/* INDEXED */
/* INDEX */
/* DESC */
/* ESCAPE */
/* EACH */
/* CHECK */
/* KEY */
/* BEFORE */
/* FOREIGN */
/* FOR */
/* IGNORE */
/* REGEXP */
/* EXPLAIN */
/* INSTEAD */
/* ADD */
/* DATABASE */
/* AS */
/* SELECT */
/* TABLE */
/* LEFT */
/* THEN */
/* END */
/* DEFERRABLE */
/* ELSE */
/* EXCLUDE */
/* DELETE */
/* TEMPORARY */
/* TEMP */
/* OR */
/* ISNULL */
/* NULLS */
/* SAVEPOINT */
/* INTERSECT */
/* TIES */
/* NOTNULL */
/* NOT */
/* NO */
/* NULL */
/* LIKE */
/* EXCEPT */
/* TRANSACTION */
/* ACTION */
/* ON */
/* NATURAL */
/* ALTER */
/* RAISE */
/* EXCLUSIVE */
/* EXISTS */
/* CONSTRAINT */
/* INTO */
/* OFFSET */
/* OF */
/* SET */
/* TRIGGER */
/* RANGE */
/* GENERATED */
/* DETACH */
/* HAVING */
/* GLOB */
/* BEGIN */
/* INNER */
/* REFERENCES */
/* UNIQUE */
/* QUERY */
/* WITHOUT */
/* WITH */
/* OUTER */
/* RELEASE */
/* ATTACH */
/* BETWEEN */
/* NOTHING */
/* GROUPS */
/* GROUP */
/* CASCADE */
/* ASC */
/* DEFAULT */
/* CASE */
/* COLLATE */
/* CREATE */
/* CURRENT_DATE */
/* IMMEDIATE */
/* JOIN */
/* INSERT */
/* MATCH */
/* PLAN */
/* ANALYZE */
/* PRAGMA */
/* MATERIALIZED */
/* DEFERRED */
/* DISTINCT */
/* IS */
/* UPDATE */
/* VALUES */
/* VIRTUAL */
/* ALWAYS */
/* WHEN */
/* WHERE */
/* RECURSIVE */
/* ABORT */
/* AFTER */
/* RENAME */
/* AND */
/* DROP */
/* PARTITION */
/* AUTOINCREMENT */
/* TO */
/* IN */
/* CAST */
/* COLUMN */
/* COMMIT */
/* CONFLICT */
/* CROSS */
/* CURRENT_TIMESTAMP */
/* CURRENT_TIME */
/* CURRENT */
/* PRECEDING */
/* FAIL */
/* LAST */
/* FILTER */
/* REPLACE */
/* FIRST */
/* FOLLOWING */
/* FROM */
/* FULL */
/* LIMIT */
/* IF */
/* ORDER */
/* RESTRICT */
/* OTHERS */
/* OVER */
/* RETURNING */
/* RIGHT */
/* ROLLBACK */
/* ROWS */
/* ROW */
/* UNBOUNDED */
/* UNION */
/* USING */
/* VACUUM */
/* VIEW */
/* WINDOW */
/* DO */
/* BY */
/* INITIALLY */
/* ALL */
/* PRIMARY */
**(**int32)(__ccgo_up(pType)) = libc.Int32FromUint8(_aKWCode[i])
break
goto _1
_1:
;
i = libc.Int64FromUint8(_aKWNext[i])
}
return n
}
func _lowerFunc(tls *libc.TLS, context uintptr, argc int32, argv uintptr) {
var i, n int32
var z1, z2 uintptr
_, _, _, _ = i, n, z1, z2
_ = argc
z2 = Xsqlite3_value_text(tls, **(**uintptr)(__ccgo_up(argv)))
n = Xsqlite3_value_bytes(tls, **(**uintptr)(__ccgo_up(argv)))
/* Verify that the call to _bytes() does not invalidate the _text() pointer */
if z2 != 0 {
z1 = _contextMalloc(tls, context, int64(n)+int64(1))
if z1 != 0 {
i = 0
for {
if !(i < n) {
break
}
**(**int8)(__ccgo_up(z1 + uintptr(i))) = libc.Int8FromUint8(_sqlite3UpperToLower[libc.Uint8FromInt8(**(**int8)(__ccgo_up(z2 + uintptr(i))))])
goto _1
_1:
;
i = i + 1
}
Xsqlite3_result_text(tls, context, z1, n, __ccgo_fp(Xsqlite3_free))
}
}
}
/*
** Some functions like COALESCE() and IFNULL() and UNLIKELY() are implemented
** as VDBE code so that unused argument values do not have to be computed.
** However, we still need some kind of function implementation for this
** routines in the function table. The noopFunc macro provides this.
** noopFunc will never be called so it doesn't matter what the implementation
** is. We might as well use the "version()" function as a substitute.
*/
// C documentation
//
// /*
// ** Write an entry into the pointer map.
// **
// ** This routine updates the pointer map entry for page number 'key'
// ** so that it maps to type 'eType' and parent page number 'pgno'.
// **
// ** If *pRC is initially non-zero (non-SQLITE_OK) then this routine is
// ** a no-op. If an error occurs, the appropriate error code is written
// ** into *pRC.
// */
func _ptrmapPut(tls *libc.TLS, pBt uintptr, key TPgno, eType Tu8, parent TPgno, pRC uintptr) {
bp := tls.Alloc(16)
defer tls.Free(16)
var iPtrmap TPgno
var offset, rc, v1 int32
var pPtrmap uintptr
var _ /* pDbPage at bp+0 */ uintptr
_, _, _, _, _ = iPtrmap, offset, pPtrmap, rc, v1 /* Return code from subfunctions */
if **(**int32)(__ccgo_up(pRC)) != 0 {
return
}
/* The super-journal page number must never be used as a pointer map page */
if key == uint32(0) {
**(**int32)(__ccgo_up(pRC)) = _sqlite3CorruptError(tls, int32(74301))
return
}
iPtrmap = _ptrmapPageno(tls, pBt, key)
rc = _sqlite3PagerGet(tls, (*TBtShared)(unsafe.Pointer(pBt)).FpPager, iPtrmap, bp, 0)
if rc != SQLITE_OK {
**(**int32)(__ccgo_up(pRC)) = rc
return
}
if int32(**(**int8)(__ccgo_up(_sqlite3PagerGetExtra(tls, **(**uintptr)(__ccgo_up(bp)))))) != 0 {
/* The first byte of the extra data is the MemPage.isInit byte.
** If that byte is set, it means this page is also being used
** as a btree page. */
**(**int32)(__ccgo_up(pRC)) = _sqlite3CorruptError(tls, int32(74314))
goto ptrmap_exit
}
offset = libc.Int32FromUint32(libc.Uint32FromInt32(5) * (key - iPtrmap - libc.Uint32FromInt32(1)))
if offset < 0 {
**(**int32)(__ccgo_up(pRC)) = _sqlite3CorruptError(tls, int32(74319))
goto ptrmap_exit
}
pPtrmap = _sqlite3PagerGetData(tls, **(**uintptr)(__ccgo_up(bp)))
if libc.Int32FromUint8(eType) != libc.Int32FromUint8(**(**Tu8)(__ccgo_up(pPtrmap + uintptr(offset)))) || _sqlite3Get4byte(tls, pPtrmap+uintptr(offset+int32(1))) != parent {
v1 = _sqlite3PagerWrite(tls, **(**uintptr)(__ccgo_up(bp)))
rc = v1
**(**int32)(__ccgo_up(pRC)) = v1
if rc == SQLITE_OK {
**(**Tu8)(__ccgo_up(pPtrmap + uintptr(offset))) = eType
_sqlite3Put4byte(tls, pPtrmap+uintptr(offset+int32(1)), parent)
}
}
goto ptrmap_exit
ptrmap_exit:
;
_sqlite3PagerUnref(tls, **(**uintptr)(__ccgo_up(bp)))
}
// C documentation
//
// /*
// ** Scan the column type name zType (length nType) and return the
// ** associated affinity type.
// **
// ** This routine does a case-independent search of zType for the
// ** substrings in the following table. If one of the substrings is
// ** found, the corresponding affinity is returned. If zType contains
// ** more than one of the substrings, entries toward the top of
// ** the table take priority. For example, if zType is 'BLOBINT',
// ** SQLITE_AFF_INTEGER is returned.
// **
// ** Substring | Affinity
// ** --------------------------------
// ** 'INT' | SQLITE_AFF_INTEGER
// ** 'CHAR' | SQLITE_AFF_TEXT
// ** 'CLOB' | SQLITE_AFF_TEXT
// ** 'TEXT' | SQLITE_AFF_TEXT
// ** 'BLOB' | SQLITE_AFF_BLOB
// ** 'REAL' | SQLITE_AFF_REAL
// ** 'FLOA' | SQLITE_AFF_REAL
// ** 'DOUB' | SQLITE_AFF_REAL
// **
// ** If none of the substrings in the above table are found,
// ** SQLITE_AFF_NUMERIC is returned.
// */
func _sqlite3AffinityType(tls *libc.TLS, zIn uintptr, pCol uintptr) (r int8) {
bp := tls.Alloc(16)
defer tls.Free(16)
var aff int8
var h Tu32
var x Tu8
var zChar uintptr
var _ /* v at bp+0 */ int32
_, _, _, _ = aff, h, x, zChar
h = uint32(0)
aff = int8(SQLITE_AFF_NUMERIC)
zChar = uintptr(0)
for **(**int8)(__ccgo_up(zIn)) != 0 {
x = **(**Tu8)(__ccgo_up(zIn))
h = h<<libc.Int32FromInt32(8) + uint32(_sqlite3UpperToLower[x])
zIn = zIn + 1
if h == libc.Uint32FromInt32(libc.Int32FromUint8('c')<<libc.Int32FromInt32(24)+libc.Int32FromUint8('h')<<libc.Int32FromInt32(16)+libc.Int32FromUint8('a')<<libc.Int32FromInt32(8)+libc.Int32FromUint8('r')) { /* CHAR */
aff = int8(SQLITE_AFF_TEXT)
zChar = zIn
} else {
if h == libc.Uint32FromInt32(libc.Int32FromUint8('c')<<libc.Int32FromInt32(24)+libc.Int32FromUint8('l')<<libc.Int32FromInt32(16)+libc.Int32FromUint8('o')<<libc.Int32FromInt32(8)+libc.Int32FromUint8('b')) { /* CLOB */
aff = int8(SQLITE_AFF_TEXT)
} else {
if h == libc.Uint32FromInt32(libc.Int32FromUint8('t')<<libc.Int32FromInt32(24)+libc.Int32FromUint8('e')<<libc.Int32FromInt32(16)+libc.Int32FromUint8('x')<<libc.Int32FromInt32(8)+libc.Int32FromUint8('t')) { /* TEXT */
aff = int8(SQLITE_AFF_TEXT)
} else {
if h == libc.Uint32FromInt32(libc.Int32FromUint8('b')<<libc.Int32FromInt32(24)+libc.Int32FromUint8('l')<<libc.Int32FromInt32(16)+libc.Int32FromUint8('o')<<libc.Int32FromInt32(8)+libc.Int32FromUint8('b')) && (int32(aff) == int32(SQLITE_AFF_NUMERIC) || int32(aff) == int32(SQLITE_AFF_REAL)) {
aff = int8(SQLITE_AFF_BLOB)
if int32(**(**int8)(__ccgo_up(zIn))) == int32('(') {
zChar = zIn
}
} else {
if h == libc.Uint32FromInt32(libc.Int32FromUint8('r')<<libc.Int32FromInt32(24)+libc.Int32FromUint8('e')<<libc.Int32FromInt32(16)+libc.Int32FromUint8('a')<<libc.Int32FromInt32(8)+libc.Int32FromUint8('l')) && int32(aff) == int32(SQLITE_AFF_NUMERIC) {
aff = int8(SQLITE_AFF_REAL)
} else {
if h == libc.Uint32FromInt32(libc.Int32FromUint8('f')<<libc.Int32FromInt32(24)+libc.Int32FromUint8('l')<<libc.Int32FromInt32(16)+libc.Int32FromUint8('o')<<libc.Int32FromInt32(8)+libc.Int32FromUint8('a')) && int32(aff) == int32(SQLITE_AFF_NUMERIC) {
aff = int8(SQLITE_AFF_REAL)
} else {
if h == libc.Uint32FromInt32(libc.Int32FromUint8('d')<<libc.Int32FromInt32(24)+libc.Int32FromUint8('o')<<libc.Int32FromInt32(16)+libc.Int32FromUint8('u')<<libc.Int32FromInt32(8)+libc.Int32FromUint8('b')) && int32(aff) == int32(SQLITE_AFF_NUMERIC) {
aff = int8(SQLITE_AFF_REAL)
} else {
if h&uint32(0x00FFFFFF) == libc.Uint32FromInt32(libc.Int32FromUint8('i')<<libc.Int32FromInt32(16)+libc.Int32FromUint8('n')<<libc.Int32FromInt32(8)+libc.Int32FromUint8('t')) { /* INT */
aff = int8(SQLITE_AFF_INTEGER)
break
}
}
}
}
}
}
}
}
}
/* If pCol is not NULL, store an estimate of the field size. The
** estimate is scaled so that the size of an integer is 1. */
if pCol != 0 {
**(**int32)(__ccgo_up(bp)) = 0 /* default size is approx 4 bytes */
if int32(aff) < int32(SQLITE_AFF_NUMERIC) {
if zChar != 0 {
for **(**int8)(__ccgo_up(zChar)) != 0 {
if libc.Int32FromUint8(_sqlite3CtypeMap[libc.Uint8FromInt8(**(**int8)(__ccgo_up(zChar)))])&int32(0x04) != 0 {
/* BLOB(k), VARCHAR(k), CHAR(k) -> r=(k/4+1) */
_sqlite3GetInt32(tls, zChar, bp)
break
}
zChar = zChar + 1
}
} else {
**(**int32)(__ccgo_up(bp)) = int32(16) /* BLOB, TEXT, CLOB -> r=5 (approx 20 bytes)*/
}
}
**(**int32)(__ccgo_up(bp)) = **(**int32)(__ccgo_up(bp))/int32(4) + int32(1)
if **(**int32)(__ccgo_up(bp)) > int32(255) {
**(**int32)(__ccgo_up(bp)) = int32(255)
}
(*TColumn)(unsafe.Pointer(pCol)).FszEst = libc.Uint8FromInt32(**(**int32)(__ccgo_up(bp)))
}
return aff
}
// C documentation
//
// /*
// ** Write a single UTF8 character whose value is v into the
// ** buffer starting at zOut. zOut must be sized to hold at
// ** least four bytes. Return the number of bytes needed
// ** to encode the new character.
// */
func _sqlite3AppendOneUtf8Character(tls *libc.TLS, zOut uintptr, v Tu32) (r int32) {
if v < uint32(0x00080) {
**(**int8)(__ccgo_up(zOut)) = libc.Int8FromUint8(uint8(v & libc.Uint32FromInt32(0xff)))
return int32(1)
}
if v < uint32(0x00800) {
**(**int8)(__ccgo_up(zOut)) = int8(int32(0xc0) + libc.Int32FromUint8(uint8(v>>libc.Int32FromInt32(6)&libc.Uint32FromInt32(0x1f))))
**(**int8)(__ccgo_up(zOut + 1)) = int8(int32(0x80) + libc.Int32FromUint8(uint8(v&libc.Uint32FromInt32(0x3f))))
return int32(2)
}
if v < uint32(0x10000) {
**(**int8)(__ccgo_up(zOut)) = int8(int32(0xe0) + libc.Int32FromUint8(uint8(v>>libc.Int32FromInt32(12)&libc.Uint32FromInt32(0x0f))))
**(**int8)(__ccgo_up(zOut + 1)) = int8(int32(0x80) + libc.Int32FromUint8(uint8(v>>libc.Int32FromInt32(6)&libc.Uint32FromInt32(0x3f))))
**(**int8)(__ccgo_up(zOut + 2)) = int8(int32(0x80) + libc.Int32FromUint8(uint8(v&libc.Uint32FromInt32(0x3f))))
return int32(3)
}
**(**int8)(__ccgo_up(zOut)) = int8(int32(0xf0) + libc.Int32FromUint8(uint8(v>>libc.Int32FromInt32(18)&libc.Uint32FromInt32(0x07))))
**(**int8)(__ccgo_up(zOut + 1)) = int8(int32(0x80) + libc.Int32FromUint8(uint8(v>>libc.Int32FromInt32(12)&libc.Uint32FromInt32(0x3f))))
**(**int8)(__ccgo_up(zOut + 2)) = int8(int32(0x80) + libc.Int32FromUint8(uint8(v>>libc.Int32FromInt32(6)&libc.Uint32FromInt32(0x3f))))
**(**int8)(__ccgo_up(zOut + 3)) = int8(int32(0x80) + libc.Int32FromUint8(uint8(v&libc.Uint32FromInt32(0x3f))))
return int32(4)
}
// C documentation
//
// /*
// ** Convert zNum to a 64-bit signed integer. zNum must be decimal. This
// ** routine does *not* accept hexadecimal notation.
// **
// ** Returns:
// **
// ** -1 Not even a prefix of the input text looks like an integer
// ** 0 Successful transformation. Fits in a 64-bit signed integer.
// ** 1 Excess non-space text after the integer value
// ** 2 Integer too large for a 64-bit signed integer or is malformed
// ** 3 Special case of 9223372036854775808
// **
// ** length is the number of bytes in the string (bytes, not characters).
// ** The string is not necessarily zero-terminated. The encoding is
// ** given by enc.
// */
func _sqlite3Atoi64(tls *libc.TLS, zNum uintptr, pNum uintptr, length int32, enc Tu8) (r int32) {
var c, v3 uint32
var i, incr, j, jj, neg, nonNum, rc, v6 int32
var u Tu64
var zEnd, zStart uintptr
var v4 bool
var v5 int64
_, _, _, _, _, _, _, _, _, _, _, _, _, _, _ = c, i, incr, j, jj, neg, nonNum, rc, u, zEnd, zStart, v3, v4, v5, v6
u = uint64(0)
neg = 0
c = uint32(0)
nonNum = 0
zEnd = zNum + uintptr(length)
if libc.Int32FromUint8(enc) == int32(SQLITE_UTF8) {
incr = int32(1)
} else {
incr = int32(2)
length = length & ^libc.Int32FromInt32(1)
i = int32(3) - libc.Int32FromUint8(enc)
for {
if !(i < length && int32(**(**int8)(__ccgo_up(zNum + uintptr(i)))) == 0) {
break
}
goto _1
_1:
;
i = i + int32(2)
}
nonNum = libc.BoolInt32(i < length)
zEnd = zNum + uintptr(i^int32(1))
zNum = zNum + uintptr(libc.Int32FromUint8(enc)&libc.Int32FromInt32(1))
}
for zNum < zEnd && libc.Int32FromUint8(_sqlite3CtypeMap[libc.Uint8FromInt8(**(**int8)(__ccgo_up(zNum)))])&int32(0x01) != 0 {
zNum = zNum + uintptr(incr)
}
if zNum < zEnd {
if int32(**(**int8)(__ccgo_up(zNum))) == int32('-') {
neg = int32(1)
zNum = zNum + uintptr(incr)
} else {
if int32(**(**int8)(__ccgo_up(zNum))) == int32('+') {
zNum = zNum + uintptr(incr)
}
}
}
zStart = zNum
for zNum < zEnd && int32(**(**int8)(__ccgo_up(zNum))) == int32('0') {
zNum = zNum + uintptr(incr)
} /* Skip leading zeros. */
i = 0
for {
if v4 = zNum+uintptr(i) < zEnd; v4 {
v3 = libc.Uint32FromInt8(**(**int8)(__ccgo_up(zNum + uintptr(i)))) - libc.Uint32FromUint8('0')
c = v3
}
if !(v4 && v3 <= uint32(9)) {
break
}
u = u*uint64(10) + uint64(c)
goto _2
_2:
;
i = i + incr
}
if u > libc.Uint64FromInt64(libc.Int64FromUint32(0xffffffff)|libc.Int64FromInt32(0x7fffffff)<<libc.Int32FromInt32(32)) {
/* This test and assignment is needed only to suppress UB warnings
** from clang and -fsanitize=undefined. This test and assignment make
** the code a little larger and slower, and no harm comes from omitting
** them, but we must appease the undefined-behavior pharisees. */
if neg != 0 {
v5 = int64(-libc.Int32FromInt32(1)) - (libc.Int64FromUint32(0xffffffff) | libc.Int64FromInt32(0x7fffffff)<<libc.Int32FromInt32(32))
} else {
v5 = libc.Int64FromUint32(0xffffffff) | libc.Int64FromInt32(0x7fffffff)<<libc.Int32FromInt32(32)
}
**(**Ti64)(__ccgo_up(pNum)) = v5
} else {
if neg != 0 {
**(**Ti64)(__ccgo_up(pNum)) = -libc.Int64FromUint64(u)
} else {
**(**Ti64)(__ccgo_up(pNum)) = libc.Int64FromUint64(u)
}
}
rc = 0
if i == 0 && zStart == zNum { /* No digits */
rc = -int32(1)
} else {
if nonNum != 0 { /* UTF16 with high-order bytes non-zero */
rc = int32(1)
} else {
if zNum+uintptr(i) < zEnd { /* Extra bytes at the end */
jj = i
for cond := true; cond; cond = zNum+uintptr(jj) < zEnd {
if !(libc.Int32FromUint8(_sqlite3CtypeMap[libc.Uint8FromInt8(**(**int8)(__ccgo_up(zNum + uintptr(jj))))])&libc.Int32FromInt32(0x01) != 0) {
rc = int32(1) /* Extra non-space text after the integer */
break
}
jj = jj + incr
}
}
}
}
if i < int32(19)*incr {
/* Less than 19 digits, so we know that it fits in 64 bits */
return rc
} else {
/* zNum is a 19-digit numbers. Compare it against 9223372036854775808. */
if i > int32(19)*incr {
v6 = int32(1)
} else {
v6 = _compare2pow63(tls, zNum, incr)
}
j = v6
if j < 0 {
/* zNum is less than 9223372036854775808 so it fits */
return rc
} else {
if neg != 0 {
v5 = int64(-libc.Int32FromInt32(1)) - (libc.Int64FromUint32(0xffffffff) | libc.Int64FromInt32(0x7fffffff)<<libc.Int32FromInt32(32))
} else {
v5 = libc.Int64FromUint32(0xffffffff) | libc.Int64FromInt32(0x7fffffff)<<libc.Int32FromInt32(32)
}
**(**Ti64)(__ccgo_up(pNum)) = v5
if j > 0 {
/* zNum is greater than 9223372036854775808 so it overflows */
return int32(2)
} else {
/* zNum is exactly 9223372036854775808. Fits if negative. The
** special case 2 overflow if positive */
if neg != 0 {
v6 = rc
} else {
v6 = int32(3)
}
return v6
}
}
}
return r
}
// C documentation
//
// /*
// ** Return the collating sequence name for a column
// */
func _sqlite3ColumnColl(tls *libc.TLS, pCol uintptr) (r uintptr) {
var z uintptr
_ = z
if libc.Int32FromUint16((*TColumn)(unsafe.Pointer(pCol)).FcolFlags)&int32(COLFLAG_HASCOLL) == 0 {
return uintptr(0)
}
z = (*TColumn)(unsafe.Pointer(pCol)).FzCnName
for **(**int8)(__ccgo_up(z)) != 0 {
z = z + 1
}
if libc.Int32FromUint16((*TColumn)(unsafe.Pointer(pCol)).FcolFlags)&int32(COLFLAG_HASTYPE) != 0 {
for cond := true; cond; cond = **(**int8)(__ccgo_up(z)) != 0 {
z = z + 1
}
}
return z + uintptr(1)
}
// C documentation
//
// /*
// ** Convert an SQL-style quoted string into a normal string by removing
// ** the quote characters. The conversion is done in-place. If the
// ** input does not begin with a quote character, then this routine
// ** is a no-op.
// **
// ** The input string must be zero-terminated. A new zero-terminator
// ** is added to the dequoted string.
// **
// ** The return value is -1 if no dequoting occurs or the length of the
// ** dequoted string, exclusive of the zero terminator, if dequoting does
// ** occur.
// **
// ** 2002-02-14: This routine is extended to remove MS-Access style
// ** brackets from around identifiers. For example: "[a-b-c]" becomes
// ** "a-b-c".
// */
func _sqlite3Dequote(tls *libc.TLS, z uintptr) {
var i, j, v2 int32
var quote int8
_, _, _, _ = i, j, quote, v2
if z == uintptr(0) {
return
}
quote = **(**int8)(__ccgo_up(z))
if !(libc.Int32FromUint8(_sqlite3CtypeMap[libc.Uint8FromInt8(quote)])&libc.Int32FromInt32(0x80) != 0) {
return
}
if int32(quote) == int32('[') {
quote = int8(']')
}
i = int32(1)
j = libc.Int32FromInt32(0)
for {
if int32(**(**int8)(__ccgo_up(z + uintptr(i)))) == int32(quote) {
if int32(**(**int8)(__ccgo_up(z + uintptr(i+int32(1))))) == int32(quote) {
v2 = j
j = j + 1
**(**int8)(__ccgo_up(z + uintptr(v2))) = quote
i = i + 1
} else {
break
}
} else {
v2 = j
j = j + 1
**(**int8)(__ccgo_up(z + uintptr(v2))) = **(**int8)(__ccgo_up(z + uintptr(i)))
}
goto _1
_1:
;
i = i + 1
}
**(**int8)(__ccgo_up(z + uintptr(j))) = 0
}
func _sqlite3DequoteExpr(tls *libc.TLS, p uintptr) {
var v1 int32
_ = v1
if int32(**(**int8)(__ccgo_up(*(*uintptr)(unsafe.Pointer(p + 8))))) == int32('"') {
v1 = libc.Int32FromInt32(EP_Quoted) | libc.Int32FromInt32(EP_DblQuoted)
} else {
v1 = int32(EP_Quoted)
}
**(**Tu32)(__ccgo_up(p + 4)) |= libc.Uint32FromInt32(v1)
_sqlite3Dequote(tls, *(*uintptr)(unsafe.Pointer(p + 8)))
}
// C documentation
//
// /*
// ** Return TRUE if the given expression is a constant which would be
// ** unchanged by OP_Affinity with the affinity given in the second
// ** argument.
// **
// ** This routine is used to determine if the OP_Affinity operation
// ** can be omitted. When in doubt return FALSE. A false negative
// ** is harmless. A false positive, however, can result in the wrong
// ** answer.
// */
func _sqlite3ExprNeedsNoAffinityChange(tls *libc.TLS, p uintptr, aff int8) (r int32) {
var op Tu8
var unaryMinus int32
_, _ = op, unaryMinus
unaryMinus = 0
if int32(aff) == int32(SQLITE_AFF_BLOB) {
return int32(1)
}
for libc.Int32FromUint8((*TExpr)(unsafe.Pointer(p)).Fop) == int32(TK_UPLUS) || libc.Int32FromUint8((*TExpr)(unsafe.Pointer(p)).Fop) == int32(TK_UMINUS) {
if libc.Int32FromUint8((*TExpr)(unsafe.Pointer(p)).Fop) == int32(TK_UMINUS) {
unaryMinus = int32(1)
}
p = (*TExpr)(unsafe.Pointer(p)).FpLeft
}
op = (*TExpr)(unsafe.Pointer(p)).Fop
if libc.Int32FromUint8(op) == int32(TK_REGISTER) {
op = (*TExpr)(unsafe.Pointer(p)).Fop2
}
switch libc.Int32FromUint8(op) {
case int32(TK_INTEGER):
return libc.BoolInt32(int32(aff) >= int32(SQLITE_AFF_NUMERIC))
case int32(TK_FLOAT):
return libc.BoolInt32(int32(aff) >= int32(SQLITE_AFF_NUMERIC))
case int32(TK_STRING):
return libc.BoolInt32(!(unaryMinus != 0) && int32(aff) == int32(SQLITE_AFF_TEXT))
case int32(TK_BLOB):
return libc.BoolInt32(!(unaryMinus != 0))
case int32(TK_COLUMN):
/* p cannot be part of a CHECK constraint */
return libc.BoolInt32(int32(aff) >= int32(SQLITE_AFF_NUMERIC) && int32((*TExpr)(unsafe.Pointer(p)).FiColumn) < 0)
default:
return 0
}
return r
}
// C documentation
//
// /*
// ** Argument p points to a buffer containing utf-8 text that is n bytes in
// ** size. Return the number of bytes in the nChar character prefix of the
// ** buffer, or 0 if there are less than nChar characters in total.
// */
func _sqlite3Fts5IndexCharlenToBytelen(tls *libc.TLS, p uintptr, nByte int32, nChar int32) (r int32) {
var i, n, v2 int32
_, _, _ = i, n, v2
n = 0
i = 0
for {
if !(i < nChar) {
break
}
if n >= nByte {
return 0
} /* Input contains fewer than nChar chars */
v2 = n
n = n + 1
if libc.Int32FromUint8(libc.Uint8FromInt8(**(**int8)(__ccgo_up(p + uintptr(v2))))) >= int32(0xc0) {
if n >= nByte {
return 0
}
for int32(**(**int8)(__ccgo_up(p + uintptr(n))))&int32(0xc0) == int32(0x80) {
n = n + 1
if n >= nByte {
if i+int32(1) == nChar {
break
}
return 0
}
}
}
goto _1
_1:
;
i = i + 1
}
return n
}
// C documentation
//
// /*
// ** Return a simple checksum value based on the arguments.
// */
func _sqlite3Fts5IndexEntryCksum(tls *libc.TLS, iRowid Ti64, iCol int32, iPos int32, iIdx int32, pTerm uintptr, nTerm int32) (r Tu64) {
var i int32
var ret Tu64
_, _ = i, ret
ret = libc.Uint64FromInt64(iRowid)
ret = ret + (ret<<libc.Int32FromInt32(3) + libc.Uint64FromInt32(iCol))
ret = ret + (ret<<libc.Int32FromInt32(3) + libc.Uint64FromInt32(iPos))
if iIdx >= 0 {
ret = ret + (ret<<libc.Int32FromInt32(3) + libc.Uint64FromInt32(libc.Int32FromUint8('0')+iIdx))
}
i = 0
for {
if !(i < nTerm) {
break
}
ret = ret + (ret<<libc.Int32FromInt32(3) + libc.Uint64FromInt8(**(**int8)(__ccgo_up(pTerm + uintptr(i)))))
goto _1
_1:
;
i = i + 1
}
return ret
}
// C documentation
//
// /*
// ** Try to convert z into an unsigned 32-bit integer. Return true on
// ** success and false if there is an error.
// **
// ** Only decimal notation is accepted.
// */
func _sqlite3GetUInt32(tls *libc.TLS, z uintptr, pI uintptr) (r int32) {
var i int32
var v Tu64
_, _ = i, v
v = uint64(0)
i = 0
for {
if !(libc.Int32FromUint8(_sqlite3CtypeMap[libc.Uint8FromInt8(**(**int8)(__ccgo_up(z + uintptr(i))))])&int32(0x04) != 0) {
break
}
v = v*uint64(10) + libc.Uint64FromInt8(**(**int8)(__ccgo_up(z + uintptr(i)))) - uint64('0')
if v > uint64(4294967296) {
**(**Tu32)(__ccgo_up(pI)) = uint32(0)
return 0
}
goto _1
_1:
;
i = i + 1
}
if i == 0 || int32(**(**int8)(__ccgo_up(z + uintptr(i)))) != 0 {
**(**Tu32)(__ccgo_up(pI)) = uint32(0)
return 0
}
**(**Tu32)(__ccgo_up(pI)) = uint32(v)
return int32(1)
}
/*
** The variable-length integer encoding is as follows:
**
** KEY:
** A = 0xxxxxxx 7 bits of data and one flag bit
** B = 1xxxxxxx 7 bits of data and one flag bit
** C = xxxxxxxx 8 bits of data
**
** 7 bits - A
** 14 bits - BA
** 21 bits - BBA
** 28 bits - BBBA
** 35 bits - BBBBA
** 42 bits - BBBBBA
** 49 bits - BBBBBBA
** 56 bits - BBBBBBBA
** 64 bits - BBBBBBBBC
*/
// C documentation
//
// /*
// ** Convert a BLOB literal of the form "x'hhhhhh'" into its binary
// ** value. Return a pointer to its binary value. Space to hold the
// ** binary value has been obtained from malloc and must be freed by
// ** the calling routine.
// */
func _sqlite3HexToBlob(tls *libc.TLS, db uintptr, z uintptr, n int32) (r uintptr) {
var i int32
var zBlob uintptr
_, _ = i, zBlob
zBlob = _sqlite3DbMallocRawNN(tls, db, libc.Uint64FromInt32(n/int32(2)+int32(1)))
n = n - 1
if zBlob != 0 {
i = 0
for {
if !(i < n) {
break
}
**(**int8)(__ccgo_up(zBlob + uintptr(i/int32(2)))) = int8(libc.Int32FromUint8(_sqlite3HexToInt(tls, int32(**(**int8)(__ccgo_up(z + uintptr(i))))))<<int32(4) | libc.Int32FromUint8(_sqlite3HexToInt(tls, int32(**(**int8)(__ccgo_up(z + uintptr(i+int32(1))))))))
goto _1
_1:
;
i = i + int32(2)
}
**(**int8)(__ccgo_up(zBlob + uintptr(i/int32(2)))) = 0
}
return zBlob
}
// C documentation
//
// /*
// ** Check to see if pExpr is one of the indexed expressions on pParse->pIdxEpr.
// ** If it is, then resolve the expression by reading from the index and
// ** return the register into which the value has been read. If pExpr is
// ** not an indexed expression, then return negative.
// */
func _sqlite3IndexedExprLookup(tls *libc.TLS, pParse uintptr, pExpr uintptr, target int32) (r int32) {
var addr, iDataCur int32
var exprAff Tu8
var p, v uintptr
_, _, _, _, _ = addr, exprAff, iDataCur, p, v
p = (*TParse)(unsafe.Pointer(pParse)).FpIdxEpr
for {
if !(p != 0) {
break
}
iDataCur = (*TIndexedExpr)(unsafe.Pointer(p)).FiDataCur
if iDataCur < 0 {
goto _1
}
if (*TParse)(unsafe.Pointer(pParse)).FiSelfTab != 0 {
if (*TIndexedExpr)(unsafe.Pointer(p)).FiDataCur != (*TParse)(unsafe.Pointer(pParse)).FiSelfTab-int32(1) {
goto _1
}
iDataCur = -int32(1)
}
if _sqlite3ExprCompare(tls, uintptr(0), pExpr, (*TIndexedExpr)(unsafe.Pointer(p)).FpExpr, iDataCur) != 0 {
goto _1
}
exprAff = libc.Uint8FromInt8(_sqlite3ExprAffinity(tls, pExpr))
if libc.Int32FromUint8(exprAff) <= int32(SQLITE_AFF_BLOB) && libc.Int32FromUint8((*TIndexedExpr)(unsafe.Pointer(p)).Faff) != int32(SQLITE_AFF_BLOB) || libc.Int32FromUint8(exprAff) == int32(SQLITE_AFF_TEXT) && libc.Int32FromUint8((*TIndexedExpr)(unsafe.Pointer(p)).Faff) != int32(SQLITE_AFF_TEXT) || libc.Int32FromUint8(exprAff) >= int32(SQLITE_AFF_NUMERIC) && libc.Int32FromUint8((*TIndexedExpr)(unsafe.Pointer(p)).Faff) != int32(SQLITE_AFF_NUMERIC) {
/* Affinity mismatch on a generated column */
goto _1
}
/* Functions that might set a subtype should not be replaced by the
** value taken from an expression index if they are themselves an
** argument to another scalar function or aggregate.
** https://sqlite.org/forum/forumpost/68d284c86b082c3e */
if (*TExpr)(unsafe.Pointer(pExpr)).Fflags&libc.Uint32FromUint32(EP_SubtArg) != uint32(0) && _sqlite3ExprCanReturnSubtype(tls, pParse, pExpr) != 0 {
goto _1
}
v = (*TParse)(unsafe.Pointer(pParse)).FpVdbe
if (*TIndexedExpr)(unsafe.Pointer(p)).FbMaybeNullRow != 0 {
/* If the index is on a NULL row due to an outer join, then we
** cannot extract the value from the index. The value must be
** computed using the original expression. */
addr = _sqlite3VdbeCurrentAddr(tls, v)
_sqlite3VdbeAddOp3(tls, v, int32(OP_IfNullRow), (*TIndexedExpr)(unsafe.Pointer(p)).FiIdxCur, addr+int32(3), target)
_sqlite3VdbeAddOp3(tls, v, int32(OP_Column), (*TIndexedExpr)(unsafe.Pointer(p)).FiIdxCur, (*TIndexedExpr)(unsafe.Pointer(p)).FiIdxCol, target)
_sqlite3VdbeGoto(tls, v, 0)
p = (*TParse)(unsafe.Pointer(pParse)).FpIdxEpr
(*TParse)(unsafe.Pointer(pParse)).FpIdxEpr = uintptr(0)
_sqlite3ExprCode(tls, pParse, pExpr, target)
(*TParse)(unsafe.Pointer(pParse)).FpIdxEpr = p
_sqlite3VdbeJumpHere(tls, v, addr+int32(2))
} else {
_sqlite3VdbeAddOp3(tls, v, int32(OP_Column), (*TIndexedExpr)(unsafe.Pointer(p)).FiIdxCur, (*TIndexedExpr)(unsafe.Pointer(p)).FiIdxCol, target)
}
return target
goto _1
_1:
;
p = (*TIndexedExpr)(unsafe.Pointer(p)).FpIENext
}
return -int32(1) /* Not found */
}
// C documentation
//
// /*
// ** This routine implements the uncommon and slower path for
// ** sqlite3MemRealValueRC() that has to deal with input strings
// ** that are not UTF8 or that are not zero-terminated. It is
// ** broken out into a separate no-inline routine so that the
// ** main sqlite3MemRealValueRC() routine can avoid unnecessary
// ** stack pushes.
// **
// ** A text->float translation of pMem->z is written into *pValue.
// **
// ** Result code invariants:
// **
// ** rc==0 => ERROR: Input string not well-formed, or OOM
// ** rc<0 => Some prefix of the input is well-formed
// ** rc>0 => All of the input is well-formed
// ** (rc&2)==0 => The number is expressed as an integer, with no
// ** decimal point or eNNN suffix.
// */
func _sqlite3MemRealValueRCSlowPath(tls *libc.TLS, pMem uintptr, pValue uintptr) (r int32) {
var i, j, n, rc, v2 int32
var z, zCopy, zCopy1 uintptr
_, _, _, _, _, _, _, _ = i, j, n, rc, z, zCopy, zCopy1, v2
rc = SQLITE_OK
**(**float64)(__ccgo_up(pValue)) = float64(0)
if libc.Int32FromUint8((*TMem)(unsafe.Pointer(pMem)).Fenc) == int32(SQLITE_UTF8) {
zCopy = _sqlite3DbStrNDup(tls, (*TMem)(unsafe.Pointer(pMem)).Fdb, (*TMem)(unsafe.Pointer(pMem)).Fz, libc.Uint64FromInt32((*TMem)(unsafe.Pointer(pMem)).Fn))
if zCopy != 0 {
rc = _sqlite3AtoF(tls, zCopy, pValue)
_sqlite3DbFree(tls, (*TMem)(unsafe.Pointer(pMem)).Fdb, zCopy)
}
return rc
} else {
n = (*TMem)(unsafe.Pointer(pMem)).Fn & ^libc.Int32FromInt32(1)
zCopy1 = _sqlite3DbMallocRaw(tls, (*TMem)(unsafe.Pointer(pMem)).Fdb, libc.Uint64FromInt32(n/int32(2)+int32(2)))
if zCopy1 != 0 {
z = (*TMem)(unsafe.Pointer(pMem)).Fz
if libc.Int32FromUint8((*TMem)(unsafe.Pointer(pMem)).Fenc) == int32(SQLITE_UTF16LE) {
v2 = libc.Int32FromInt32(0)
j = v2
i = v2
for {
if !(i < n-int32(1)) {
break
}
**(**int8)(__ccgo_up(zCopy1 + uintptr(j))) = **(**int8)(__ccgo_up(z + uintptr(i)))
if int32(**(**int8)(__ccgo_up(z + uintptr(i+int32(1))))) != 0 {
break
}
goto _1
_1:
;
i = i + int32(2)
j = j + 1
}
} else {
v2 = libc.Int32FromInt32(0)
j = v2
i = v2
for {
if !(i < n-int32(1)) {
break
}
if int32(**(**int8)(__ccgo_up(z + uintptr(i)))) != 0 {
break
}
**(**int8)(__ccgo_up(zCopy1 + uintptr(j))) = **(**int8)(__ccgo_up(z + uintptr(i+int32(1))))
goto _3
_3:
;
i = i + int32(2)
j = j + 1
}
}
**(**int8)(__ccgo_up(zCopy1 + uintptr(j))) = 0
rc = _sqlite3AtoF(tls, zCopy1, pValue)
if i < n {
rc = -int32(100)
}
_sqlite3DbFree(tls, (*TMem)(unsafe.Pointer(pMem)).Fdb, zCopy1)
}
return rc
}
return r
}
func _sqlite3StrAccumFinish(tls *libc.TLS, p uintptr) (r uintptr) {
if (*TStrAccum)(unsafe.Pointer(p)).FzText != 0 {
**(**int8)(__ccgo_up((*TStrAccum)(unsafe.Pointer(p)).FzText + uintptr((*TStrAccum)(unsafe.Pointer(p)).FnChar))) = 0
if (*TStrAccum)(unsafe.Pointer(p)).FmxAlloc > uint32(0) && !(libc.Int32FromUint8((*TStrAccum)(unsafe.Pointer(p)).FprintfFlags)&libc.Int32FromInt32(SQLITE_PRINTF_MALLOCED) != libc.Int32FromInt32(0)) {
return _strAccumFinishRealloc(tls, p)
}
}
return (*TStrAccum)(unsafe.Pointer(p)).FzText
}
// C documentation
//
// /*
// ** Compute an 8-bit hash on a string that is insensitive to case differences
// */
func _sqlite3StrIHash(tls *libc.TLS, z uintptr) (r Tu8) {
var h Tu8
_ = h
h = uint8(0)
if z == uintptr(0) {
return uint8(0)
}
for **(**int8)(__ccgo_up(z)) != 0 {
h = libc.Uint8FromInt32(int32(h) + libc.Int32FromUint8(_sqlite3UpperToLower[libc.Uint8FromInt8(**(**int8)(__ccgo_up(z)))]))
z = z + 1
}
return h
}
// C documentation
//
// /*
// ** Exported version of applyAffinity(). This one works on sqlite3_value*,
// ** not the internal Mem* type.
// */
func _sqlite3ValueApplyAffinity(tls *libc.TLS, pVal uintptr, affinity Tu8, enc Tu8) {
_applyAffinity(tls, pVal, libc.Int8FromUint8(affinity), enc)
}
// C documentation
//
// /*
// ** Move data out of a btree key or data field and into a Mem structure.
// ** The data is payload from the entry that pCur is currently pointing
// ** to. offset and amt determine what portion of the data or key to retrieve.
// ** The result is written into the pMem element.
// **
// ** The pMem object must have been initialized. This routine will use
// ** pMem->zMalloc to hold the content from the btree, if possible. New
// ** pMem->zMalloc space will be allocated if necessary. The calling routine
// ** is responsible for making sure that the pMem object is eventually
// ** destroyed.
// **
// ** If this routine fails for any reason (malloc returns NULL or unable
// ** to read from the disk) then the pMem is left in an inconsistent state.
// */
func _sqlite3VdbeMemFromBtree(tls *libc.TLS, pCur uintptr, offset Tu32, amt Tu32, pMem uintptr) (r int32) {
var rc, v1 int32
_, _ = rc, v1
(*TMem)(unsafe.Pointer(pMem)).Fflags = uint16(MEM_Null)
if amt >= uint32(SQLITE_MAX_ALLOCATION_SIZE) {
return int32(SQLITE_NOMEM)
}
if uint64(amt)+uint64(offset) > libc.Uint64FromInt64(_sqlite3BtreeMaxRecordSize(tls, pCur)) {
return _sqlite3CorruptError(tls, int32(87091))
}
v1 = _sqlite3VdbeMemClearAndResize(tls, pMem, libc.Int32FromUint32(amt+uint32(1)))
rc = v1
if SQLITE_OK == v1 {
rc = _sqlite3BtreePayload(tls, pCur, offset, amt, (*TMem)(unsafe.Pointer(pMem)).Fz)
if rc == SQLITE_OK {
**(**int8)(__ccgo_up((*TMem)(unsafe.Pointer(pMem)).Fz + uintptr(amt))) = 0 /* Overrun area used when reading malformed records */
(*TMem)(unsafe.Pointer(pMem)).Fflags = uint16(MEM_Blob)
(*TMem)(unsafe.Pointer(pMem)).Fn = libc.Int32FromUint32(amt)
} else {
_sqlite3VdbeMemRelease(tls, pMem)
}
}
return rc
}
// C documentation
//
// /*
// ** The hashing function.
// */
func _strHash(tls *libc.TLS, z uintptr) (r uint32) {
var h uint32
var v1 uintptr
_, _ = h, v1
h = uint32(0)
for **(**int8)(__ccgo_up(z)) != 0 { /*OPTIMIZATION-IF-TRUE*/
/* Knuth multiplicative hashing. (Sorting & Searching, p. 510).
** 0x9e3779b1 is 2654435761 which is the closest prime number to
** (2**32)*golden_ratio, where golden_ratio = (sqrt(5) - 1)/2.
**
** Only bits 0xdf for ASCII and bits 0xbf for EBCDIC each octet are
** hashed since the omitted bits determine the upper/lower case difference.
*/
v1 = z
z = z + 1
h = h + libc.Uint32FromInt32(int32(0xdf)&libc.Int32FromUint8(libc.Uint8FromInt8(**(**int8)(__ccgo_up(v1)))))
h = h * uint32(0x9e3779b1)
}
return h
}
// C documentation
//
// /*
// ** We already know that pExpr is a binary operator where both operands are
// ** column references. This routine checks to see if pExpr is an equivalence
// ** relation:
// ** 1. The SQLITE_Transitive optimization must be enabled
// ** 2. Must be either an == or an IS operator
// ** 3. Not originating in the ON clause of an OUTER JOIN
// ** 4. The operator is not IS or else the query does not contain RIGHT JOIN
// ** 5. The affinities of A and B must be compatible
// ** 6. Both operands use the same collating sequence, and they must not
// ** use explicit COLLATE clauses.
// ** If this routine returns TRUE, that means that the RHS can be substituted
// ** for the LHS anyplace else in the WHERE clause where the LHS column occurs.
// ** This is an optimization. No harm comes from returning 0. But if 1 is
// ** returned when it should not be, then incorrect answers might result.
// */
func _termIsEquivalence(tls *libc.TLS, pParse uintptr, pExpr uintptr, pSrc uintptr) (r int32) {
var aff1, aff2 int8
_, _ = aff1, aff2
if !((*Tsqlite3)(unsafe.Pointer((*TParse)(unsafe.Pointer(pParse)).Fdb)).FdbOptFlags&libc.Uint32FromInt32(libc.Int32FromInt32(SQLITE_Transitive)) == libc.Uint32FromInt32(0)) {
return 0
} /* (1) */
if libc.Int32FromUint8((*TExpr)(unsafe.Pointer(pExpr)).Fop) != int32(TK_EQ) && libc.Int32FromUint8((*TExpr)(unsafe.Pointer(pExpr)).Fop) != int32(TK_IS) {
return 0
} /* (2) */
if (*TExpr)(unsafe.Pointer(pExpr)).Fflags&libc.Uint32FromInt32(libc.Int32FromInt32(EP_OuterON)|libc.Int32FromInt32(EP_Collate)) != uint32(0) {
return 0
} /* (3) */
if libc.Int32FromUint8((*TExpr)(unsafe.Pointer(pExpr)).Fop) == int32(TK_IS) && (*TSrcList)(unsafe.Pointer(pSrc)).FnSrc >= int32(2) && libc.Int32FromUint8((*(*TSrcItem)(unsafe.Pointer(pSrc + 8))).Ffg.Fjointype)&int32(JT_LTORJ) != 0 {
return 0 /* (4) */
}
aff1 = _sqlite3ExprAffinity(tls, (*TExpr)(unsafe.Pointer(pExpr)).FpLeft)
aff2 = _sqlite3ExprAffinity(tls, (*TExpr)(unsafe.Pointer(pExpr)).FpRight)
if int32(aff1) != int32(aff2) && (!(int32(aff1) >= libc.Int32FromInt32(SQLITE_AFF_NUMERIC)) || !(int32(aff2) >= libc.Int32FromInt32(SQLITE_AFF_NUMERIC))) {
return 0 /* (5) */
}
if !(_sqlite3ExprCollSeqMatch(tls, pParse, (*TExpr)(unsafe.Pointer(pExpr)).FpLeft, (*TExpr)(unsafe.Pointer(pExpr)).FpRight) != 0) {
return 0 /* (6) */
}
return int32(1)
}
// C documentation
//
// /*
// ** Duplicate a range of text from an SQL statement, then convert all
// ** whitespace characters into ordinary space characters.
// */
func _triggerSpanDup(tls *libc.TLS, db uintptr, zStart uintptr, zEnd uintptr) (r uintptr) {
var i int32
var z uintptr
_, _ = i, z
z = _sqlite3DbSpanDup(tls, db, zStart, zEnd)
if z != 0 {
i = 0
for {
if !(**(**int8)(__ccgo_up(z + uintptr(i))) != 0) {
break
}
if libc.Int32FromUint8(_sqlite3CtypeMap[libc.Uint8FromInt8(**(**int8)(__ccgo_up(z + uintptr(i))))])&int32(0x01) != 0 {
**(**int8)(__ccgo_up(z + uintptr(i))) = int8(' ')
}
goto _1
_1:
;
i = i + 1
}
}
return z
}
// C documentation
//
// /*
// ** Implementation of the upper() and lower() SQL functions.
// */
func _upperFunc(tls *libc.TLS, context uintptr, argc int32, argv uintptr) {
var i, n int32
var z1, z2 uintptr
_, _, _, _ = i, n, z1, z2
_ = argc
z2 = Xsqlite3_value_text(tls, **(**uintptr)(__ccgo_up(argv)))
n = Xsqlite3_value_bytes(tls, **(**uintptr)(__ccgo_up(argv)))
/* Verify that the call to _bytes() does not invalidate the _text() pointer */
if z2 != 0 {
z1 = _contextMalloc(tls, context, int64(n)+int64(1))
if z1 != 0 {
i = 0
for {
if !(i < n) {
break
}
**(**int8)(__ccgo_up(z1 + uintptr(i))) = int8(int32(**(**int8)(__ccgo_up(z2 + uintptr(i)))) & ^(libc.Int32FromUint8(_sqlite3CtypeMap[libc.Uint8FromInt8(**(**int8)(__ccgo_up(z2 + uintptr(i))))]) & libc.Int32FromInt32(0x20)))
goto _1
_1:
;
i = i + 1
}
Xsqlite3_result_text(tls, context, z1, n, __ccgo_fp(Xsqlite3_free))
}
}
}