// Code generated by modernc.org/undup from the per-target sqlite_*.go files; DO NOT EDIT.
//go:build (darwin && amd64) || (darwin && arm64)
package sqlite3
import (
"unsafe"
"modernc.org/libc"
)
const ACCESSX_MAX_DESCRIPTORS = 100
const ACCESSX_MAX_TABLESIZE = 16384
const AF_CNT = 21
const AF_COIP = 20
const AF_E164 = 28
const AF_IEEE80211 = 37
const AF_INET6 = 30
const AF_IPX = 23
const AF_ISDN = 28
const AF_LINK = 18
const AF_LOCAL = 1
const AF_MAX = 41
const AF_NATM = 31
const AF_NDRV = 27
const AF_NETBIOS = 33
const AF_PPP = 34
const AF_RESERVED_36 = 36
const AF_ROUTE = 17
const AF_SIP = 24
const AF_SYSTEM = 32
const AF_UTUN = 38
const AF_VSOCK = 40
const ALIGNBYTES = -1
const APPLE_IF_FAM_BOND = 14
const APPLE_IF_FAM_CELLULAR = 15
const APPLE_IF_FAM_DISC = 8
const APPLE_IF_FAM_ETHERNET = 2
const APPLE_IF_FAM_FAITH = 11
const APPLE_IF_FAM_FIREWIRE = 13
const APPLE_IF_FAM_GIF = 10
const APPLE_IF_FAM_IPSEC = 18
const APPLE_IF_FAM_LOOPBACK = 1
const APPLE_IF_FAM_MDECAP = 9
const APPLE_IF_FAM_PPP = 6
const APPLE_IF_FAM_PVC = 7
const APPLE_IF_FAM_SLIP = 3
const APPLE_IF_FAM_STF = 12
const APPLE_IF_FAM_TUN = 4
const APPLE_IF_FAM_UNUSED_16 = 16
const APPLE_IF_FAM_UTUN = 17
const APPLE_IF_FAM_VLAN = 5
const AQ_BUFSZ = 32767
const AQ_HIWATER = 100
const AQ_LOWATER = 10
const AQ_MAXBUFSZ = 1048576
const AQ_MAXHIGH = 10000
const ARG_MAX = 1048576
const ATTRIBUTION_NAME_MAX = 255
const ATTR_BIT_MAP_COUNT = 5
const ATTR_BULK_REQUIRED = 2147483649
const ATTR_CMNEXT_ATTRIBUTION_TAG = 2048
const ATTR_CMNEXT_CLONEID = 256
const ATTR_CMNEXT_CLONE_REFCNT = 4096
const ATTR_CMNEXT_EXT_FLAGS = 512
const ATTR_CMNEXT_LINKID = 16
const ATTR_CMNEXT_NOFIRMLINKPATH = 32
const ATTR_CMNEXT_PRIVATESIZE = 8
const ATTR_CMNEXT_REALDEVID = 64
const ATTR_CMNEXT_REALFSID = 128
const ATTR_CMNEXT_RECURSIVE_GENCOUNT = 1024
const ATTR_CMNEXT_RELPATH = 4
const ATTR_CMNEXT_SETMASK = 0
const ATTR_CMNEXT_VALIDMASK = 8188
const ATTR_CMN_ACCESSMASK = 131072
const ATTR_CMN_ACCTIME = 4096
const ATTR_CMN_ADDEDTIME = 268435456
const ATTR_CMN_BKUPTIME = 8192
const ATTR_CMN_CHGTIME = 2048
const ATTR_CMN_CRTIME = 512
const ATTR_CMN_DATA_PROTECT_FLAGS = 1073741824
const ATTR_CMN_DEVID = 2
const ATTR_CMN_DOCUMENT_ID = 1048576
const ATTR_CMN_ERROR = 536870912
const ATTR_CMN_EXTENDED_SECURITY = 4194304
const ATTR_CMN_FILEID = 33554432
const ATTR_CMN_FLAGS = 262144
const ATTR_CMN_FNDRINFO = 16384
const ATTR_CMN_FSID = 4
const ATTR_CMN_FULLPATH = 134217728
const ATTR_CMN_GEN_COUNT = 524288
const ATTR_CMN_GRPID = 65536
const ATTR_CMN_GRPUUID = 16777216
const ATTR_CMN_MODTIME = 1024
const ATTR_CMN_NAME = 1
const ATTR_CMN_NAMEDATTRCOUNT = 524288
const ATTR_CMN_NAMEDATTRLIST = 1048576
const ATTR_CMN_OBJID = 32
const ATTR_CMN_OBJPERMANENTID = 64
const ATTR_CMN_OBJTAG = 16
const ATTR_CMN_OBJTYPE = 8
const ATTR_CMN_OWNERID = 32768
const ATTR_CMN_PARENTID = 67108864
const ATTR_CMN_PAROBJID = 128
const ATTR_CMN_RETURNED_ATTRS = 2147483648
const ATTR_CMN_SCRIPT = 256
const ATTR_CMN_SETMASK = 1372061440
const ATTR_CMN_USERACCESS = 2097152
const ATTR_CMN_UUID = 8388608
const ATTR_CMN_VALIDMASK = 4294967295
const ATTR_CMN_VOLSETMASK = 26368
const ATTR_DIR_ALLOCSIZE = 8
const ATTR_DIR_DATALENGTH = 32
const ATTR_DIR_ENTRYCOUNT = 2
const ATTR_DIR_IOBLOCKSIZE = 16
const ATTR_DIR_LINKCOUNT = 1
const ATTR_DIR_MOUNTSTATUS = 4
const ATTR_DIR_SETMASK = 0
const ATTR_DIR_VALIDMASK = 63
const ATTR_FILE_ALLOCSIZE = 4
const ATTR_FILE_CLUMPSIZE = 16
const ATTR_FILE_DATAALLOCSIZE = 1024
const ATTR_FILE_DATAEXTENTS = 2048
const ATTR_FILE_DATALENGTH = 512
const ATTR_FILE_DEVTYPE = 32
const ATTR_FILE_FILETYPE = 64
const ATTR_FILE_FORKCOUNT = 128
const ATTR_FILE_FORKLIST = 256
const ATTR_FILE_IOBLOCKSIZE = 8
const ATTR_FILE_LINKCOUNT = 1
const ATTR_FILE_RSRCALLOCSIZE = 8192
const ATTR_FILE_RSRCEXTENTS = 16384
const ATTR_FILE_RSRCLENGTH = 4096
const ATTR_FILE_SETMASK = 32
const ATTR_FILE_TOTALSIZE = 2
const ATTR_FILE_VALIDMASK = 14335
const ATTR_FORK_ALLOCSIZE = 2
const ATTR_FORK_RESERVED = 4294967295
const ATTR_FORK_SETMASK = 0
const ATTR_FORK_TOTALSIZE = 1
const ATTR_FORK_VALIDMASK = 3
const ATTR_MAX_BUFFER = 8192
const ATTR_MAX_BUFFER_LONGPATHS = 7168
const ATTR_VOL_ALLOCATIONCLUMP = 64
const ATTR_VOL_ATTRIBUTES = 1073741824
const ATTR_VOL_CAPABILITIES = 131072
const ATTR_VOL_DIRCOUNT = 1024
const ATTR_VOL_ENCODINGSUSED = 65536
const ATTR_VOL_FILECOUNT = 512
const ATTR_VOL_FSSUBTYPE = 2097152
const ATTR_VOL_FSTYPE = 1
const ATTR_VOL_FSTYPENAME = 1048576
const ATTR_VOL_INFO = 2147483648
const ATTR_VOL_IOBLOCKSIZE = 128
const ATTR_VOL_MAXOBJCOUNT = 2048
const ATTR_VOL_MINALLOCATION = 32
const ATTR_VOL_MOUNTEDDEVICE = 32768
const ATTR_VOL_MOUNTEXTFLAGS = 524288
const ATTR_VOL_MOUNTFLAGS = 16384
const ATTR_VOL_MOUNTPOINT = 4096
const ATTR_VOL_NAME = 8192
const ATTR_VOL_OBJCOUNT = 256
const ATTR_VOL_OWNER = 4194304
const ATTR_VOL_QUOTA_SIZE = 268435456
const ATTR_VOL_RESERVED_SIZE = 536870912
const ATTR_VOL_SETMASK = 2147491840
const ATTR_VOL_SIGNATURE = 2
const ATTR_VOL_SIZE = 4
const ATTR_VOL_SPACEAVAIL = 16
const ATTR_VOL_SPACEFREE = 8
const ATTR_VOL_SPACEUSED = 8388608
const ATTR_VOL_UUID = 262144
const ATTR_VOL_VALIDMASK = 4043309055
const AT_EACCESS = 16
const AT_FDCWD = -2
const AT_FDONLY = 1024
const AT_NODELETEBUSY = 16384
const AT_REALDEV = 512
const AT_REMOVEDIR = 128
const AT_SYMLINK_FOLLOW = 64
const AT_SYMLINK_NOFOLLOW = 32
const AT_SYMLINK_NOFOLLOW_ANY = 2048
const AT_UNIQUE = 32768
const AUC_AUDITING = 1
const AUC_DISABLED = -1
const AUC_NOAUDIT = 2
const AUC_UNSET = 0
const AUDITDEV_FILENAME = "audit"
const AUDIT_AHLT = 2
const AUDIT_ARGE = 8
const AUDIT_ARGV = 4
const AUDIT_CNT = 1
const AUDIT_GROUP = 128
const AUDIT_HARD_LIMIT_FREE_BLOCKS = 4
const AUDIT_PATH = 512
const AUDIT_PERZONE = 8192
const AUDIT_PUBLIC = 2048
const AUDIT_RECORD_MAGIC = 2190085915
const AUDIT_SCNT = 1024
const AUDIT_SEQ = 16
const AUDIT_TRAIL = 256
const AUDIT_TRIGGER_CLOSE_AND_DIE = 4
const AUDIT_TRIGGER_EXPIRE_TRAILS = 8
const AUDIT_TRIGGER_INITIALIZE = 7
const AUDIT_TRIGGER_LOW_SPACE = 1
const AUDIT_TRIGGER_MAX = 8
const AUDIT_TRIGGER_MIN = 1
const AUDIT_TRIGGER_NO_SPACE = 5
const AUDIT_TRIGGER_READ_FILE = 3
const AUDIT_TRIGGER_ROTATE_KERNEL = 2
const AUDIT_TRIGGER_ROTATE_USER = 6
const AUDIT_USER = 64
const AUDIT_WINDATA = 32
const AUDIT_ZONENAME = 4096
const AUTH_OPEN_NOAUTHFD = -1
const AU_ASSIGN_ASID = -1
const AU_CLASS_MASK_RESERVED = 268435456
const AU_DEFAUDITSID = 0
const AU_FS_MINFREE = 20
const AU_IPv4 = 4
const AU_IPv6 = 16
const A_GETCAR = 9
const A_GETCLASS = 22
const A_GETCOND = 37
const A_GETCTLMODE = 41
const A_GETCWD = 8
const A_GETEXPAFTER = 43
const A_GETFSIZE = 27
const A_GETKAUDIT = 29
const A_GETKMASK = 4
const A_GETPINFO = 24
const A_GETPINFO_ADDR = 28
const A_GETPOLICY = 33
const A_GETQCTRL = 35
const A_GETSFLAGS = 39
const A_GETSINFO_ADDR = 32
const A_GETSTAT = 12
const A_OLDGETCOND = 20
const A_OLDGETPOLICY = 2
const A_OLDGETQCTRL = 6
const A_OLDSETCOND = 21
const A_OLDSETPOLICY = 3
const A_OLDSETQCTRL = 7
const A_SENDTRIGGER = 31
const A_SETCLASS = 23
const A_SETCOND = 38
const A_SETCTLMODE = 42
const A_SETEXPAFTER = 44
const A_SETFSIZE = 26
const A_SETKAUDIT = 30
const A_SETKMASK = 5
const A_SETPMASK = 25
const A_SETPOLICY = 34
const A_SETQCTRL = 36
const A_SETSFLAGS = 40
const A_SETSMASK = 15
const A_SETSTAT = 13
const A_SETUMASK = 14
const BADSIG = "SIG_ERR"
const BC_BASE_MAX = 99
const BC_DIM_MAX = 2048
const BC_SCALE_MAX = 99
const BC_STRING_MAX = 1000
const BLKDEV_IOSIZE = 2048
const BSD = 199506
const BSD4_3 = 1
const BSD4_4 = 1
const BUS_ADRALN = 1
const BUS_ADRERR = 2
const BUS_NOOP = 0
const BUS_OBJERR = 3
type ByteRangeLockPB2 = TByteRangeLockPB2
const CBLOCK = 64
const CBQSIZE = 8
const CBSIZE = 56
const CHILD_MAX = 266
const CLBYTES = 4096
const CLD_CONTINUED = 6
const CLD_DUMPED = 3
const CLD_EXITED = 1
const CLD_KILLED = 2
const CLD_NOOP = 0
const CLD_STOPPED = 5
const CLD_TRAPPED = 4
const CLOCK_MONOTONIC = 0
const CLOCK_MONOTONIC_RAW = 0
const CLOCK_MONOTONIC_RAW_APPROX = 0
const CLOCK_PROCESS_CPUTIME_ID = 0
const CLOCK_THREAD_CPUTIME_ID = 0
const CLOCK_UPTIME_RAW = 0
const CLOCK_UPTIME_RAW_APPROX = 0
const CLOFF = 4095
const CLOFSET = 4095
const CLSHIFT = 12
const CLSIZE = 1
const CLSIZELOG2 = 0
const CMASK = 18
const CONNECT_DATA_AUTHENTICATED = 4
const CONNECT_DATA_IDEMPOTENT = 2
const CONNECT_RESUME_ON_READ_WRITE = 1
const CPF_IGNORE_MODE = 2
const CPF_MASK = 3
const CPF_OVERWRITE = 1
const CPUMON_MAKE_FATAL = 4096
const CRF_MAC_ENFORCE = 2
const CRF_NOMEMBERD = 1
const CROUND = 63
const CRYPTEX_AUTH_STRUCT_VERSION = 2
const DEV_BSHIFT = 9
const DEV_BSIZE = 512
const DIR_MNTSTATUS_MNTPOINT = 1
const DIR_MNTSTATUS_TRIGGER = 2
const DYNAMIC_TARGETS_ENABLED = 0
const EBADARCH = 86
const EBADEXEC = 85
const EBADMACHO = 88
const EBADMSG = 94
const ECANCELED = 89
const EDEVERR = 83
const EF_IS_PURGEABLE = 8
const EF_IS_SPARSE = 16
const EF_IS_SYNC_ROOT = 4
const EF_IS_SYNTHETIC = 32
const EF_MAY_SHARE_BLOCKS = 1
const EF_NO_XATTRS = 2
const EF_SHARES_ALL_BLOCKS = 64
const EIDRM = 90
const EILSEQ = 92
const ELAST = 107
const EMULTIHOP = 95
const ENODATA = 96
const ENOLINK = 97
const ENOMSG = 91
const ENOPOLICY = 103
const ENOSR = 98
const ENOSTR = 99
const ENOTCAPABLE = 107
const ENOTRECOVERABLE = 104
const EOPNOTSUPP = 102
const EOWNERDEAD = 105
const EPROTO = 100
const EPWROFF = 82
const EQFULL = 106
const EQUIV_CLASS_MAX = 2
const ESHLIBVERS = 87
const ETIME = 101
const FCNTL_FS_SPECIFIC_BASE = 65536
const FFDSYNC = 4194304
const FILESEC_GUID = 0
const FOOTPRINT_INTERVAL_RESET = 1
const FPE_FLTDIV = 1
const FPE_FLTINV = 5
const FPE_FLTOVF = 2
const FPE_FLTRES = 4
const FPE_FLTSUB = 6
const FPE_FLTUND = 3
const FPE_INTDIV = 7
const FPE_INTOVF = 8
const FPE_NOOP = 0
const FP_INFINITE = 2
const FP_QNAN = 1
const FP_SUBNORMAL = 5
const FP_SUPERNORMAL = 6
const FP_ZERO = 3
const FSCALE = 2048
const FSCRED = -1
const FSHIFT = 11
const FSOPT_ATTR_CMN_EXTENDED = 32
const FSOPT_NOFOLLOW = 1
const FSOPT_NOFOLLOW_ANY = 2048
const FSOPT_NOINMEMUPDATE = 2
const FSOPT_PACK_INVAL_ATTRS = 8
const FSOPT_REPORT_FULLSIZE = 4
const FSOPT_RESOLVE_BENEATH = 4096
const FSOPT_RETURN_REALDEV = 512
const FSOPT_UNIQUE = 8192
const FST_EOF = -1
const F_ADDFILESIGS = 61
const F_ADDFILESIGS_FOR_DYLD_SIM = 83
const F_ADDFILESIGS_INFO = 103
const F_ADDFILESIGS_RETURN = 97
const F_ADDFILESUPPL = 104
const F_ADDSIGS = 59
const F_ADDSIGS_MAIN_BINARY = 113
const F_ALLOCATEALL = 4
const F_ALLOCATECONTIG = 2
const F_ALLOCATEPERSIST = 8
const F_ATTRIBUTION_TAG = 111
const F_BARRIERFSYNC = 85
const F_CHECK_LV = 98
const F_CHKCLEAN = 41
const F_CREATE_TAG = 1
const F_DELETE_TAG = 2
const F_DUPFD_CLOEXEC = 67
const F_FINDSIGS = 78
const F_FLUSH_DATA = 40
const F_FREEZE_FS = 53
const F_FULLFSYNC = 51
const F_GETCODEDIR = 72
const F_GETLEASE = 107
const F_GETLKPID = 66
const F_GETNOSIGPIPE = 74
const F_GETPATH = 50
const F_GETPATH_MTMINFO = 71
const F_GETPATH_NOFIRMLINK = 102
const F_GETPROTECTIONCLASS = 63
const F_GETPROTECTIONLEVEL = 77
const F_GETSIGSINFO = 105
const F_GLOBAL_NOCACHE = 55
const F_LOG2PHYS = 49
const F_LOG2PHYS_EXT = 65
const F_NOCACHE = 48
const F_NOCACHE_EXT = 112
const F_NODIRECT = 62
const F_OFD_GETLK = 92
const F_OFD_SETLK = 90
const F_OFD_SETLKW = 91
const F_OFD_SETLKWTIMEOUT = 93
const F_PATHPKG_CHECK = 52
const F_PEOFPOSMODE = 3
const F_PREALLOCATE = 42
const F_PUNCHHOLE = 99
const F_QUERY_TAG = 4
const F_RDADVISE = 44
const F_RDAHEAD = 45
const F_SETBACKINGSTORE = 70
const F_SETLEASE = 106
const F_SETLKWTIMEOUT = 10
const F_SETNOSIGPIPE = 73
const F_SETPROTECTIONCLASS = 64
const F_SETSIZE = 43
const F_SINGLE_WRITER = 76
const F_SPECULATIVE_READ = 101
const F_THAW_FS = 54
const F_TRANSCODEKEY = 75
const F_TRANSFEREXTENTS = 110
const F_TRIM_ACTIVE_FILE = 100
const F_VOLPOSMODE = 4
const GETSIGSINFO_PLATFORM_BINARY = 1
const GRAFTDMG_SECURE_BOOT_CRYPTEX_ARGS_VERSION = 1
const GUARD_TYPE_MACH_PORT = 1
const HAVE_FULLFSYNC = 1
const IFCAP_AV = 256
const IFCAP_CSUM_PARTIAL = 8192
const IFCAP_CSUM_ZERO_INVERT = 16384
const IFCAP_HWCSUM = 3
const IFCAP_HW_TIMESTAMP = 2048
const IFCAP_JUMBO_MTU = 16
const IFCAP_LRO = 128
const IFCAP_LRO_NUM_SEG = 32768
const IFCAP_RXCSUM = 1
const IFCAP_SKYWALK = 1024
const IFCAP_SW_TIMESTAMP = 4096
const IFCAP_TSO = 96
const IFCAP_TSO4 = 32
const IFCAP_TSO6 = 64
const IFCAP_TXCSUM = 2
const IFCAP_TXSTATUS = 512
const IFCAP_VALID = 65535
const IFCAP_VLAN_HWTAGGING = 8
const IFCAP_VLAN_MTU = 4
const IFF_ALLMULTI = 512
const IFF_ALTPHYS = 16384
const IFF_BROADCAST = 2
const IFF_DEBUG = 4
const IFF_LINK0 = 4096
const IFF_LINK1 = 8192
const IFF_LINK2 = 16384
const IFF_LOOPBACK = 8
const IFF_MULTICAST = 32768
const IFF_NOARP = 128
const IFF_NOTRAILERS = 32
const IFF_OACTIVE = 1024
const IFF_POINTOPOINT = 16
const IFF_PROMISC = 256
const IFF_RUNNING = 64
const IFF_SIMPLEX = 2048
const IFF_UP = 1
const IFNAMSIZ = 16
const IFNET_SLOWHZ = 1
const IFQ_MAXLEN = 128
const IFRTYPE_FUNCTIONAL_CELLULAR = 5
const IFRTYPE_FUNCTIONAL_COMPANIONLINK = 7
const IFRTYPE_FUNCTIONAL_INTCOPROC = 6
const IFRTYPE_FUNCTIONAL_LAST = 8
const IFRTYPE_FUNCTIONAL_LOOPBACK = 1
const IFRTYPE_FUNCTIONAL_MANAGEMENT = 8
const IFRTYPE_FUNCTIONAL_UNKNOWN = 0
const IFRTYPE_FUNCTIONAL_WIFI_AWDL = 4
const IFRTYPE_FUNCTIONAL_WIFI_INFRA = 3
const IFRTYPE_FUNCTIONAL_WIRED = 2
const IFSTATMAX = 800
const IF_DATA_TIMEVAL = 0
const IF_MAXMTU = 65535
const IF_MINMTU = 72
const IF_NAMESIZE = 16
const IF_WAKE_ON_MAGIC_PACKET = 1
const ILL_BADSTK = 8
const ILL_COPROC = 7
const ILL_ILLADR = 5
const ILL_ILLOPC = 1
const ILL_ILLOPN = 4
const ILL_ILLTRP = 2
const ILL_NOOP = 0
const ILL_PRVOPC = 3
const ILL_PRVREG = 6
const IOPOL_APPLICATION = 5
const IOPOL_ATIME_UPDATES_DEFAULT = 0
const IOPOL_ATIME_UPDATES_OFF = 1
const IOPOL_DEFAULT = 0
const IOPOL_IMPORTANT = 1
const IOPOL_MATERIALIZE_DATALESS_FILES_BASIC_MASK = 3
const IOPOL_MATERIALIZE_DATALESS_FILES_DEFAULT = 0
const IOPOL_MATERIALIZE_DATALESS_FILES_OFF = 1
const IOPOL_MATERIALIZE_DATALESS_FILES_ON = 2
const IOPOL_MATERIALIZE_DATALESS_FILES_ORIG = 4
const IOPOL_NORMAL = 1
const IOPOL_PASSIVE = 2
const IOPOL_SCOPE_DARWIN_BG = 2
const IOPOL_SCOPE_PROCESS = 0
const IOPOL_SCOPE_THREAD = 1
const IOPOL_STANDARD = 5
const IOPOL_THROTTLE = 3
const IOPOL_TYPE_DISK = 0
const IOPOL_TYPE_VFS_ALLOW_LOW_SPACE_WRITES = 9
const IOPOL_TYPE_VFS_ATIME_UPDATES = 2
const IOPOL_TYPE_VFS_DISALLOW_RW_FOR_O_EVTONLY = 10
const IOPOL_TYPE_VFS_ENTITLED_RESERVE_ACCESS = 14
const IOPOL_TYPE_VFS_IGNORE_CONTENT_PROTECTION = 6
const IOPOL_TYPE_VFS_IGNORE_PERMISSIONS = 7
const IOPOL_TYPE_VFS_MATERIALIZE_DATALESS_FILES = 3
const IOPOL_TYPE_VFS_SKIP_MTIME_UPDATE = 8
const IOPOL_TYPE_VFS_STATFS_NO_DATA_VOLUME = 4
const IOPOL_TYPE_VFS_TRIGGER_RESOLVE = 5
const IOPOL_UTILITY = 4
const IOPOL_VFS_ALLOW_LOW_SPACE_WRITES_OFF = 0
const IOPOL_VFS_ALLOW_LOW_SPACE_WRITES_ON = 1
const IOPOL_VFS_CONTENT_PROTECTION_DEFAULT = 0
const IOPOL_VFS_CONTENT_PROTECTION_IGNORE = 1
const IOPOL_VFS_DISALLOW_RW_FOR_O_EVTONLY_DEFAULT = 0
const IOPOL_VFS_DISALLOW_RW_FOR_O_EVTONLY_ON = 1
const IOPOL_VFS_ENTITLED_RESERVE_ACCESS_OFF = 0
const IOPOL_VFS_ENTITLED_RESERVE_ACCESS_ON = 1
const IOPOL_VFS_IGNORE_PERMISSIONS_OFF = 0
const IOPOL_VFS_IGNORE_PERMISSIONS_ON = 1
const IOPOL_VFS_NOCACHE_WRITE_FS_BLKSIZE_DEFAULT = 0
const IOPOL_VFS_NOCACHE_WRITE_FS_BLKSIZE_ON = 1
const IOPOL_VFS_SKIP_MTIME_UPDATE_IGNORE = 2
const IOPOL_VFS_SKIP_MTIME_UPDATE_OFF = 0
const IOPOL_VFS_SKIP_MTIME_UPDATE_ON = 1
const IOPOL_VFS_STATFS_FORCE_NO_DATA_VOLUME = 1
const IOPOL_VFS_STATFS_NO_DATA_VOLUME_DEFAULT = 0
const IOPOL_VFS_TRIGGER_RESOLVE_DEFAULT = 0
const IOPOL_VFS_TRIGGER_RESOLVE_OFF = 1
const KEV_DL_ADDMULTI = 7
const KEV_DL_AWDL_RESTRICTED = 26
const KEV_DL_AWDL_UNRESTRICTED = 27
const KEV_DL_DELMULTI = 8
const KEV_DL_IFCAP_CHANGED = 19
const KEV_DL_IFDELEGATE_CHANGED = 25
const KEV_DL_IF_ATTACHED = 9
const KEV_DL_IF_DETACHED = 11
const KEV_DL_IF_DETACHING = 10
const KEV_DL_IF_IDLE_ROUTE_REFCNT = 18
const KEV_DL_ISSUES = 24
const KEV_DL_LINK_ADDRESS_CHANGED = 16
const KEV_DL_LINK_OFF = 12
const KEV_DL_LINK_ON = 13
const KEV_DL_LINK_QUALITY_METRIC_CHANGED = 20
const KEV_DL_LOW_POWER_MODE_CHANGED = 30
const KEV_DL_MASTER_ELECTED = 23
const KEV_DL_NODE_ABSENCE = 22
const KEV_DL_NODE_PRESENCE = 21
const KEV_DL_PRIMARY_ELECTED = 23
const KEV_DL_PROTO_ATTACHED = 14
const KEV_DL_PROTO_DETACHED = 15
const KEV_DL_QOS_MODE_CHANGED = 29
const KEV_DL_RRC_STATE_CHANGED = 28
const KEV_DL_SIFFLAGS = 1
const KEV_DL_SIFGENERIC = 6
const KEV_DL_SIFMEDIA = 5
const KEV_DL_SIFMETRICS = 2
const KEV_DL_SIFMTU = 3
const KEV_DL_SIFPHYS = 4
const KEV_DL_SUBCLASS = 2
const KEV_DL_WAKEFLAGS_CHANGED = 17
const KEV_INET6_ADDR_DELETED = 3
const KEV_INET6_CHANGED_ADDR = 2
const KEV_INET6_DEFROUTER = 6
const KEV_INET6_NEW_LL_ADDR = 4
const KEV_INET6_NEW_RTADV_ADDR = 5
const KEV_INET6_NEW_USER_ADDR = 1
const KEV_INET6_REQUEST_NAT64_PREFIX = 7
const KEV_INET6_SUBCLASS = 6
const KEV_INET_ADDR_DELETED = 3
const KEV_INET_ARPCOLLISION = 7
const KEV_INET_ARPRTRALIVE = 10
const KEV_INET_ARPRTRFAILURE = 9
const KEV_INET_CHANGED_ADDR = 2
const KEV_INET_NEW_ADDR = 1
const KEV_INET_PORTINUSE = 8
const KEV_INET_SIFBRDADDR = 5
const KEV_INET_SIFDSTADDR = 4
const KEV_INET_SIFNETMASK = 6
const KEV_INET_SUBCLASS = 1
const M16KCLBYTES = 16384
const M16KCLSHIFT = 14
const MACH_MSG_TYPE_INTEGER_T = 0
const MACH_PORT_CONNECTION_PORT_WITH_PORT_ARRAY = "com.apple.developer.allow-connection-port-with-port-array"
const MACH_PORT_DENAP_RECEIVER = 6
const MACH_PORT_DNREQUESTS_SIZE = 3
const MACH_PORT_DNREQUESTS_SIZE_COUNT = 1
const MACH_PORT_GUARD_INFO = 8
const MACH_PORT_IMPORTANCE_RECEIVER = 5
const MACH_PORT_INFO_EXT = 7
const MACH_PORT_LIMITS_INFO = 1
const MACH_PORT_NULL = 0
const MACH_PORT_QLIMIT_BASIC = 5
const MACH_PORT_QLIMIT_DEFAULT = 5
const MACH_PORT_QLIMIT_KERNEL = 65534
const MACH_PORT_QLIMIT_LARGE = 1024
const MACH_PORT_QLIMIT_MAX = 1024
const MACH_PORT_QLIMIT_MIN = 0
const MACH_PORT_QLIMIT_SMALL = 16
const MACH_PORT_QLIMIT_ZERO = 0
const MACH_PORT_RECEIVE_STATUS = 2
const MACH_PORT_SERVICE_THROTTLED = 9
const MACH_PORT_SERVICE_THROTTLED_COUNT = 1
const MACH_PORT_SRIGHTS_NONE = 0
const MACH_PORT_SRIGHTS_PRESENT = 1
const MACH_PORT_STATUS_FLAG_GUARDED = 2
const MACH_PORT_STATUS_FLAG_GUARD_IMMOVABLE_RECEIVE = 64
const MACH_PORT_STATUS_FLAG_IMP_DONATION = 8
const MACH_PORT_STATUS_FLAG_NO_GRANT = 128
const MACH_PORT_STATUS_FLAG_REVIVE = 16
const MACH_PORT_STATUS_FLAG_STRICT_GUARD = 4
const MACH_PORT_STATUS_FLAG_TASKPTR = 32
const MACH_PORT_STATUS_FLAG_TEMPOWNER = 1
const MACH_PORT_TEMPOWNER = 4
const MACH_PORT_TYPE_DNREQUEST = 2147483648
const MACH_PORT_TYPE_SPREQUEST = 1073741824
const MACH_PORT_TYPE_SPREQUEST_DELAYED = 536870912
const MACH_PORT_WEAK_REPLY_ENTITLEMENT = "com.apple.private.allow-weak-reply-port"
const MACH_SERVICE_PORT_INFO_STRING_NAME_MAX_BUF_LEN = 255
const MAC_OS_VERSION_11_0 = 110000
const MAC_OS_VERSION_11_1 = 110100
const MAC_OS_VERSION_11_3 = 110300
const MAC_OS_VERSION_11_4 = 110400
const MAC_OS_VERSION_11_5 = 110500
const MAC_OS_VERSION_11_6 = 110600
const MAC_OS_VERSION_12_0 = 120000
const MAC_OS_VERSION_12_1 = 120100
const MAC_OS_VERSION_12_2 = 120200
const MAC_OS_VERSION_12_3 = 120300
const MAC_OS_VERSION_12_4 = 120400
const MAC_OS_VERSION_12_5 = 120500
const MAC_OS_VERSION_12_6 = 120600
const MAC_OS_VERSION_12_7 = 120700
const MAC_OS_VERSION_13_0 = 130000
const MAC_OS_VERSION_13_1 = 130100
const MAC_OS_VERSION_13_2 = 130200
const MAC_OS_VERSION_13_3 = 130300
const MAC_OS_VERSION_13_4 = 130400
const MAC_OS_VERSION_13_5 = 130500
const MAC_OS_VERSION_13_6 = 130600
const MAC_OS_VERSION_13_7 = 130700
const MAC_OS_VERSION_14_0 = 140000
const MAC_OS_VERSION_14_1 = 140100
const MAC_OS_VERSION_14_2 = 140200
const MAC_OS_VERSION_14_3 = 140300
const MAC_OS_VERSION_14_4 = 140400
const MAC_OS_VERSION_14_5 = 140500
const MAC_OS_VERSION_14_6 = 140600
const MAC_OS_VERSION_14_7 = 140700
const MAC_OS_VERSION_15_0 = 150000
const MAC_OS_VERSION_15_1 = 150100
const MAC_OS_VERSION_15_2 = 150200
const MAC_OS_VERSION_15_3 = 150300
const MAC_OS_VERSION_15_4 = 150400
const MAC_OS_VERSION_15_5 = 150500
const MAC_OS_VERSION_15_6 = 150600
const MAC_OS_VERSION_16_0 = 160000
const MAC_OS_VERSION_26_0 = 260000
const MAC_OS_VERSION_26_1 = 260100
const MAC_OS_VERSION_26_2 = 260200
const MAC_OS_VERSION_26_3 = 260300
const MAC_OS_VERSION_26_4 = 260400
const MAC_OS_VERSION_26_5 = 260500
const MAC_OS_X_VERSION_10_0 = 1000
const MAC_OS_X_VERSION_10_1 = 1010
const MAC_OS_X_VERSION_10_10 = 101000
const MAC_OS_X_VERSION_10_10_2 = 101002
const MAC_OS_X_VERSION_10_10_3 = 101003
const MAC_OS_X_VERSION_10_11 = 101100
const MAC_OS_X_VERSION_10_11_2 = 101102
const MAC_OS_X_VERSION_10_11_3 = 101103
const MAC_OS_X_VERSION_10_11_4 = 101104
const MAC_OS_X_VERSION_10_12 = 101200
const MAC_OS_X_VERSION_10_12_1 = 101201
const MAC_OS_X_VERSION_10_12_2 = 101202
const MAC_OS_X_VERSION_10_12_4 = 101204
const MAC_OS_X_VERSION_10_13 = 101300
const MAC_OS_X_VERSION_10_13_1 = 101301
const MAC_OS_X_VERSION_10_13_2 = 101302
const MAC_OS_X_VERSION_10_13_4 = 101304
const MAC_OS_X_VERSION_10_14 = 101400
const MAC_OS_X_VERSION_10_14_1 = 101401
const MAC_OS_X_VERSION_10_14_4 = 101404
const MAC_OS_X_VERSION_10_14_5 = 101405
const MAC_OS_X_VERSION_10_14_6 = 101406
const MAC_OS_X_VERSION_10_15 = 101500
const MAC_OS_X_VERSION_10_15_1 = 101501
const MAC_OS_X_VERSION_10_15_4 = 101504
const MAC_OS_X_VERSION_10_16 = 101600
const MAC_OS_X_VERSION_10_2 = 1020
const MAC_OS_X_VERSION_10_3 = 1030
const MAC_OS_X_VERSION_10_4 = 1040
const MAC_OS_X_VERSION_10_5 = 1050
const MAC_OS_X_VERSION_10_6 = 1060
const MAC_OS_X_VERSION_10_7 = 1070
const MAC_OS_X_VERSION_10_8 = 1080
const MAC_OS_X_VERSION_10_9 = 1090
const MADV_CAN_REUSE = 9
const MADV_FREE_REUSABLE = 7
const MADV_FREE_REUSE = 8
const MADV_PAGEOUT = 10
const MADV_ZERO = 11
const MADV_ZERO_WIRED_PAGES = 6
const MAP_JIT = 2048
const MAP_NOCACHE = 1024
const MAP_NOEXTEND = 256
const MAP_RESILIENT_CODESIGN = 8192
const MAP_RESILIENT_MEDIA = 16384
const MAP_TPRO = 524288
const MAP_TRANSLATED_ALLOW_EXECUTE = 131072
const MAP_UNIX03 = 262144
const MAXAUDITDATA = 32767
const MAXBSIZE = 1048576
const MAXCOMLEN = 16
const MAXDOMNAMELEN = 256
const MAXFLOAT = 0
const MAXFRAG = 8
const MAXHOSTNAMELEN = 256
const MAXINTERP = 64
const MAXLOGNAME = 255
const MAXPATHLEN = 1024
const MAXPHYSIO_WIRED = 16777216
const MAXPRI = 127
const MAXSYMLINKS = 32
const MAXUPRC = 266
const MAX_AUDIT_RECORDS = 20
const MAX_AUDIT_RECORD_SIZE = 32767
const MAX_CANON = 1024
const MAX_FATAL_kGUARD_EXC_CODE = 0
const MAX_GRAFT_ARGS_SIZE = 512
const MAX_INPUT = 1024
const MAX_OPTIONAL_kGUARD_EXC_CODE = 0
const MBIGCLBYTES = 4096
const MBIGCLSHIFT = 12
const MB_LEN_MAX = 1
const MCLBYTES = 2048
const MCLOFSET = 2047
const MCLSHIFT = 11
const MFSNAMELEN = 15
const MFSTYPENAMELEN = 16
const MINCORE_ANONYMOUS = 128
const MINCORE_COPIED = 64
const MINCORE_PAGED_OUT = 32
const MINSIGSTKSZ = 32768
const MIN_AUDIT_FILE_SIZE = 524288
const MNAMELEN = 1024
const MNT_ASYNC = 64
const MNT_AUTOMOUNTED = 4194304
const MNT_CMDFLAGS = 983040
const MNT_CPROTECT = 128
const MNT_DEFWRITE = 33554432
const MNT_DONTBROWSE = 1048576
const MNT_DOVOLFS = 32768
const MNT_DWAIT = 4
const MNT_EXPORTED = 256
const MNT_EXT_FSKIT = 2
const MNT_EXT_ROOT_DATA_VOL = 1
const MNT_FORCE = 524288
const MNT_IGNORE_OWNERSHIP = 2097152
const MNT_JOURNALED = 8388608
const MNT_LOCAL = 4096
const MNT_MULTILABEL = 67108864
const MNT_NOATIME = 268435456
const MNT_NOBLOCK = 131072
const MNT_NODEV = 16
const MNT_NOEXEC = 4
const MNT_NOFOLLOW = 134217728
const MNT_NOSUID = 8
const MNT_NOUSERXATTR = 16777216
const MNT_NOWAIT = 2
const MNT_QUARANTINE = 1024
const MNT_QUOTA = 8192
const MNT_RDONLY = 1
const MNT_RELOAD = 262144
const MNT_REMOVABLE = 512
const MNT_ROOTFS = 16384
const MNT_SNAPSHOT = 1073741824
const MNT_STRICTATIME = 2147483648
const MNT_SYNCHRONOUS = 2
const MNT_UNION = 32
const MNT_UNKNOWNPERMISSIONS = 2097152
const MNT_UPDATE = 65536
const MNT_VISFLAGMASK = 3757111295
const MNT_WAIT = 1
const MPG_FLAGS_INVALID_OPTIONS_OOL_ARRAYS = 2
const MPG_FLAGS_INVALID_OPTIONS_OOL_DISP = 1
const MPG_FLAGS_INVALID_OPTIONS_OOL_RIGHT = 3
const MPG_FLAGS_INVALID_RIGHT_COPYIN = 4
const MPG_FLAGS_INVALID_RIGHT_DEALLOC = 5
const MPG_FLAGS_INVALID_RIGHT_DEALLOC_KERNEL = 6
const MPG_FLAGS_INVALID_RIGHT_DELTA = 2
const MPG_FLAGS_INVALID_RIGHT_DESTRUCT = 3
const MPG_FLAGS_INVALID_RIGHT_RECV = 1
const MPG_FLAGS_INVALID_RIGHT_TRANSLATE_PORT = 7
const MPG_FLAGS_INVALID_RIGHT_TRANSLATE_PSET = 8
const MPG_FLAGS_INVALID_VALUE_DELTA = 2
const MPG_FLAGS_INVALID_VALUE_DESTRUCT = 3
const MPG_FLAGS_INVALID_VALUE_PEEK = 1
const MPG_FLAGS_KERN_FAILURE_MULTI_NOTI = 4
const MPG_FLAGS_KERN_FAILURE_NOTIFY_RECV = 3
const MPG_FLAGS_KERN_FAILURE_NOTIFY_TYPE = 2
const MPG_FLAGS_KERN_FAILURE_TASK = 1
const MPG_FLAGS_MOD_REFS_PINNED_COPYIN = 3
const MPG_FLAGS_MOD_REFS_PINNED_DEALLOC = 1
const MPG_FLAGS_MOD_REFS_PINNED_DESTROY = 2
const MPG_FLAGS_NONE = 0
const MPG_FLAGS_SEND_INVALID_RIGHT_GUARDED = 3
const MPG_FLAGS_SEND_INVALID_RIGHT_OOL_PORT = 2
const MPG_FLAGS_SEND_INVALID_RIGHT_PORT = 1
const MPG_FLAGS_STRICT_REPLY_INVALID_VOUCHER = 4
const MPG_FLAGS_STRICT_REPLY_MISMATCHED_PERSONA = 16
const MPG_IMMOVABLE_RECEIVE = 2
const MPG_STRICT = 1
const MPO_CONTEXT_AS_GUARD = 1
const MPO_DENAP_RECEIVER = 64
const MPO_ENFORCE_REPLY_PORT_SEMANTICS = 8192
const MPO_FILTER_MSG = 256
const MPO_IMMOVABLE_RECEIVE = 128
const MPO_IMPORTANCE_RECEIVER = 8
const MPO_INSERT_SEND_RIGHT = 16
const MPO_OPTIONS_MASK = 9215
const MPO_PORT_TYPE_MASK = 121856
const MPO_PROVISIONAL_REPLY_PORT = 0
const MPO_QLIMIT = 2
const MPO_STRICT = 32
const MPO_STRICT_SERVICE_PORT = 8192
const MPO_TEMPOWNER = 4
const MPO_TG_BLOCK_TRACKING = 512
const MPO_UNUSED_BITS = -131072
const MSG_CTRUNC = 32
const MSG_DONTWAIT = 128
const MSG_EOF = 256
const MSG_EOR = 8
const MSG_FLUSH = 1024
const MSG_HAVEMORE = 8192
const MSG_HOLD = 2048
const MSG_NEEDSA = 65536
const MSG_NOSIGNAL = 524288
const MSG_RCVMORE = 16384
const MSG_SEND = 4096
const MSG_TRUNC = 16
const MSG_WAITALL = 64
const MSG_WAITSTREAM = 512
const MSIZE = 256
const MSIZESHIFT = 8
const MS_DEACTIVATE = 8
const MS_KILLPAGES = 4
const MS_SYNC = 16
const NAME_MAX = 255
const NBPG = 4096
const NBPW = 0
const NCARGS = 1048576
const NETSVC_MRKNG_LVL_L2 = 1
const NETSVC_MRKNG_LVL_L3L2_ALL = 2
const NETSVC_MRKNG_LVL_L3L2_BK = 3
const NETSVC_MRKNG_UNKNOWN = 0
const NET_MAXID = 41
const NET_RT_DUMP = 1
const NET_RT_DUMP2 = 7
const NET_RT_FLAGS = 2
const NET_RT_FLAGS_PRIV = 10
const NET_RT_IFLIST = 3
const NET_RT_IFLIST2 = 6
const NET_RT_MAXID = 11
const NET_RT_STAT = 4
const NET_RT_TRASH = 5
const NET_SERVICE_TYPE_AV = 6
const NET_SERVICE_TYPE_BE = 0
const NET_SERVICE_TYPE_BK = 1
const NET_SERVICE_TYPE_OAM = 7
const NET_SERVICE_TYPE_RD = 8
const NET_SERVICE_TYPE_RV = 5
const NET_SERVICE_TYPE_SIG = 2
const NET_SERVICE_TYPE_VI = 3
const NET_SERVICE_TYPE_VO = 4
const NFSV2_MAX_FH_SIZE = 32
const NFSV3_MAX_FH_SIZE = 64
const NFSV4_MAX_FH_SIZE = 128
const NFS_MAX_FH_SIZE = 128
const NGROUPS = 16
const NOFILE = 256
const NOGROUP = 65535
const NSIG = 32
const NeXTBSD = 1995064
const NeXTBSD4_0 = 0
const OPEN_MAX = 10240
const OS_ASSUME_PTR_ABI_SINGLE_BEGIN = 0
const OS_ASSUME_PTR_ABI_SINGLE_END = 0
const OS_HEADER_INDEXABLE = 0
const OS_UNSAFE_INDEXABLE = 0
const O_ALERT = 536870912
const O_CLOEXEC = 16777216
const O_DIRECTORY = 1048576
const O_DP_AUTHENTICATE = 4
const O_DP_GETRAWENCRYPTED = 1
const O_DP_GETRAWUNENCRYPTED = 2
const O_DSYNC = 4194304
const O_EVTONLY = 32768
const O_EXEC = 1073741824
const O_NOCTTY = 131072
const O_NOFOLLOW_ANY = 536870912
const O_POPUP = 2147483648
const O_RESOLVE_BENEATH = 4096
const O_SEARCH = 1074790400
const O_SYMLINK = 2097152
const O_UNIQUE = 8192
const PCATCH = 256
const PDROP = 1024
const PF_CNT = 21
const PF_COIP = 20
const PF_INET6 = 30
const PF_IPX = 23
const PF_ISDN = 28
const PF_KEY = 29
const PF_LINK = 18
const PF_LOCAL = 1
const PF_MAX = 41
const PF_NATM = 31
const PF_NDRV = 27
const PF_NETBIOS = 33
const PF_PIP = 25
const PF_PPP = 34
const PF_RESERVED_36 = 36
const PF_ROUTE = 17
const PF_RTIP = 22
const PF_SIP = 24
const PF_SYSTEM = 32
const PF_UTUN = 38
const PF_VSOCK = 40
const PF_XTP = 19
const PGOFSET = 4095
const PGSHIFT = 12
const PINOD = 8
const PLOCK = 36
const POLL_ERR = 4
const POLL_HUP = 6
const POLL_IN = 1
const POLL_MSG = 3
const POLL_OUT = 2
const POLL_PRI = 5
const PPAUSE = 40
const PRIBIO = 16
const PRIMASK = 255
const PRIO_DARWIN_BG = 4096
const PRIO_DARWIN_NONUI = 4097
const PRIO_DARWIN_PROCESS = 4
const PRIO_DARWIN_THREAD = 3
const PRIO_MAX = 20
const PRIO_MIN = -20
const PRIO_PGRP = 1
const PRIO_PROCESS = 0
const PRIO_USER = 2
const PROXY_CONCHVERSION = 2
const PROXY_HEADERLEN = 1
const PROXY_HOSTIDLEN = 16
const PROXY_MAXCONCHLEN = 1041
const PROXY_PATHINDEX = 17
const PSOCK = 24
const PSPIN = 2048
const PSWP = 0
const PTTYBLOCK = 512
const PUSER = 50
const PVFS = 20
const PVM = 4
const PWAIT = 32
const PZERO = 22
const P_tmpdir = "/var/tmp/"
const RENAME_EXCL = 4
const RENAME_NOFOLLOW_ANY = 16
const RENAME_RESERVED1 = 8
const RENAME_RESOLVE_BENEATH = 32
const RENAME_SECLUDE = 1
const RENAME_SWAP = 2
const RLIMIT_AS = 5
const RLIMIT_CORE = 4
const RLIMIT_CPU = 0
const RLIMIT_CPU_USAGE_MONITOR = 2
const RLIMIT_DATA = 2
const RLIMIT_FOOTPRINT_INTERVAL = 4
const RLIMIT_FSIZE = 1
const RLIMIT_MEMLOCK = 6
const RLIMIT_NOFILE = 8
const RLIMIT_NPROC = 7
const RLIMIT_RSS = 5
const RLIMIT_STACK = 3
const RLIMIT_THREAD_CPULIMITS = 3
const RLIMIT_WAKEUPS_MONITOR = 1
const RLIM_NLIMITS = 9
const RLIM_SAVED_CUR = "RLIM_INFINITY"
const RLIM_SAVED_MAX = "RLIM_INFINITY"
const RTLD_FIRST = 256
const RTLD_GLOBAL = 8
const RTLD_LOCAL = 4
const RTLD_MAIN_ONLY = -5
const RTLD_NODELETE = 128
const RTLD_NOLOAD = 16
const RUSAGE_CHILDREN = -1
const RUSAGE_INFO_CURRENT = 6
const RUSAGE_INFO_V0 = 0
const RUSAGE_INFO_V1 = 1
const RUSAGE_INFO_V2 = 2
const RUSAGE_INFO_V3 = 3
const RUSAGE_INFO_V4 = 4
const RUSAGE_INFO_V5 = 5
const RUSAGE_INFO_V6 = 6
const RUSAGE_SELF = 0
const RU_PROC_RUNS_RESLIDE = 1
const SAE_ASSOCID_ANY = 0
const SAE_CONNID_ANY = 0
const SA_64REGSET = 512
const SA_NOCLDSTOP = 8
const SA_NOCLDWAIT = 32
const SA_NODEFER = 16
const SA_ONSTACK = 1
const SA_RESETHAND = 4
const SA_RESTART = 2
const SA_SIGINFO = 64
const SA_USERSPACE_MASK = 127
const SA_USERTRAMP = 256
const SBC_ALTERNATE_SHARED_REGION = 2
const SBC_PANIC_ON_AUTHFAIL = 8
const SBC_PRESERVE_GRAFT = 32
const SBC_PRESERVE_MOUNT = 1
const SBC_STRICT_AUTH = 16
const SBC_SYSTEM_CONTENT = 4
const SCM_CREDS = 3
const SCM_RIGHTS = 1
const SCM_TIMESTAMP = 2
const SCM_TIMESTAMP_MONOTONIC = 4
const SEARCHFS_MAX_SEARCHPARMS = 4096
const SEEK_DATA = 4
const SEEK_HOLE = 3
const SEGV_ACCERR = 2
const SEGV_MAPERR = 1
const SEGV_NOOP = 0
const SF_DATALESS = 1073741824
const SF_FIRMLINK = 8388608
const SF_RESTRICTED = 524288
const SF_SETTABLE = 1073676288
const SF_SUPPORTED = 10420224
const SF_SYNTHETIC = 3221225472
const SHUT_RD = 0
const SHUT_RDWR = 2
const SHUT_WR = 1
const SIGABRT = 6
const SIGALRM = 14
const SIGBUS = 10
const SIGCHLD = 20
const SIGCONT = 19
const SIGEMT = 7
const SIGEV_KEVENT = 4
const SIGEV_NONE = 0
const SIGEV_SIGNAL = 1
const SIGEV_THREAD = 3
const SIGFPE = 8
const SIGHUP = 1
const SIGILL = 4
const SIGINFO = 29
const SIGINT = 2
const SIGIO = 23
const SIGIOT = 6
const SIGKILL = 9
const SIGPIPE = 13
const SIGPROF = 27
const SIGQUIT = 3
const SIGSEGV = 11
const SIGSTKSZ = 131072
const SIGSTOP = 17
const SIGSYS = 12
const SIGTERM = 15
const SIGTRAP = 5
const SIGTSTP = 18
const SIGTTIN = 21
const SIGTTOU = 22
const SIGURG = 16
const SIGUSR1 = 30
const SIGUSR2 = 31
const SIGVTALRM = 26
const SIGWINCH = 28
const SIGXCPU = 24
const SIGXFSZ = 25
const SIG_BLOCK = 1
const SIG_SETMASK = 3
const SIG_UNBLOCK = 2
const SIOCGETVLAN = "SIOCGIFVLAN"
const SIOCSETVLAN = "SIOCSIFVLAN"
const SI_ASYNCIO = 65540
const SI_MESGQ = 65541
const SI_QUEUE = 65538
const SI_TIMER = 65539
const SI_USER = 65537
const SOCK_MAXADDRLEN = 255
const SOMAXCONN = 128
const SONPX_SETOPTSHUT = 1
const SO_BINDTODEVICE = 4404
const SO_DONTTRUNC = 8192
const SO_LABEL = 4112
const SO_LINGER_SEC = 4224
const SO_NETSVC_MARKING_LEVEL = 4377
const SO_NET_SERVICE_TYPE = 4374
const SO_NKE = 4129
const SO_NOADDRERR = 4131
const SO_NOSIGPIPE = 4130
const SO_NOTIFYCONFLICT = 4134
const SO_NP_EXTENSIONS = 4227
const SO_NREAD = 4128
const SO_NUMRCVPKT = 4370
const SO_NWRITE = 4132
const SO_PEERLABEL = 4113
const SO_RANDOMPORT = 4226
const SO_RESOLVER_SIGNATURE = 4401
const SO_REUSEPORT = 512
const SO_REUSESHAREUID = 4133
const SO_TIMESTAMP = 1024
const SO_TIMESTAMP_MONOTONIC = 2048
const SO_UPCALLCLOSEWAIT = 4135
const SO_WANTMORE = 16384
const SO_WANTOOBFLAG = 32768
const SQLITE_ENABLE_LOCKING_STYLE = 1
const SRCHFS_MATCHDIRS = 4
const SRCHFS_MATCHFILES = 8
const SRCHFS_MATCHPARTIALNAMES = 2
const SRCHFS_NEGATEPARAMS = 2147483648
const SRCHFS_NOFOLLOW = 256
const SRCHFS_NOFOLLOW_ANY = 512
const SRCHFS_SKIPINAPPROPRIATE = 128
const SRCHFS_SKIPINVISIBLE = 32
const SRCHFS_SKIPLINKS = 16
const SRCHFS_SKIPPACKAGES = 64
const SRCHFS_START = 1
const SRCHFS_VALIDOPTIONSMASK = 2147484671
const SS_DISABLE = 4
const SS_ONSTACK = 1
const SV_INTERRUPT = 2
const SV_NOCLDSTOP = 8
const SV_NODEFER = 16
const SV_ONSTACK = 1
const SV_RESETHAND = 4
const SV_SIGINFO = 64
const SYNC_VOLUME_FULLSYNC = 1
const SYNC_VOLUME_WAIT = 2
const TARGET_CPU_68K = 0
const TARGET_CPU_ALPHA = 0
const TARGET_CPU_ARM = 0
const TARGET_CPU_MIPS = 0
const TARGET_CPU_PPC = 0
const TARGET_CPU_PPC64 = 0
const TARGET_CPU_SPARC = 0
const TARGET_CPU_X86 = 0
const TARGET_IPHONE_SIMULATOR = 0
const TARGET_OS_BRIDGE = 0
const TARGET_OS_DRIVERKIT = 0
const TARGET_OS_EMBEDDED = 0
const TARGET_OS_IOS = 0
const TARGET_OS_IOSMAC = 0
const TARGET_OS_IPHONE = 0
const TARGET_OS_LINUX = 0
const TARGET_OS_MAC = 1
const TARGET_OS_MACCATALYST = 0
const TARGET_OS_NANO = 0
const TARGET_OS_OSX = 1
const TARGET_OS_RTKIT = 0
const TARGET_OS_SIMULATOR = 0
const TARGET_OS_TV = 0
const TARGET_OS_UEFI = 0
const TARGET_OS_UIKITFORMAC = 0
const TARGET_OS_UNIX = 0
const TARGET_OS_VISION = 0
const TARGET_OS_WATCH = 0
const TARGET_OS_WIN32 = 0
const TARGET_OS_WINDOWS = 0
const TARGET_OS_XR = 0
const TARGET_RT_64_BIT = 1
const TARGET_RT_BIG_ENDIAN = 0
const TARGET_RT_LITTLE_ENDIAN = 1
const TARGET_RT_MAC_CFM = 0
const TARGET_RT_MAC_MACHO = 1
type TByteRangeLockPB2 = struct {
Foffset uint64
Flength uint64
FretRangeStart uint64
FunLockFlag uint8
FstartEndFlag uint8
Ffd int32
}
type TFILE = struct {
F_p uintptr
F_r int32
F_w int32
F_flags int16
F_file int16
F_bf t__sbuf
F_lbfsize int32
F_cookie uintptr
F_close uintptr
F_read uintptr
F_seek uintptr
F_write uintptr
F_ub t__sbuf
F_extra uintptr
F_ur int32
F_ubuf [3]uint8
F_nbuf [1]uint8
F_lb t__sbuf
F_blksize int32
F_offset Tfpos_t
}
const TRAP_BRKPT = 1
const TRAP_TRACE = 2
type T_RuneCharClass = struct {
F__name [14]int8
F__mask t__uint32_t
}
type T_RuneEntry = struct {
F__min t__darwin_rune_t
F__max t__darwin_rune_t
F__map t__darwin_rune_t
F__types uintptr
}
type T_RuneLocale = struct {
F__magic [8]int8
F__encoding [32]int8
F__sgetrune uintptr
F__sputrune uintptr
F__invalid_rune t__darwin_rune_t
F__runetype [256]t__uint32_t
F__maplower [256]t__darwin_rune_t
F__mapupper [256]t__darwin_rune_t
F__runetype_ext T_RuneRange
F__maplower_ext T_RuneRange
F__mapupper_ext T_RuneRange
F__variable uintptr
F__variable_len int32
F__ncharclasses int32
F__charclasses uintptr
}
type T_opaque_pthread_attr_t = struct {
F__sig int64
F__opaque [56]int8
}
type T_opaque_pthread_cond_t = struct {
F__sig int64
F__opaque [40]int8
}
type T_opaque_pthread_condattr_t = struct {
F__sig int64
F__opaque [8]int8
}
type T_opaque_pthread_mutex_t = struct {
F__sig int64
F__opaque [56]int8
}
type T_opaque_pthread_mutexattr_t = struct {
F__sig int64
F__opaque [8]int8
}
type T_opaque_pthread_once_t = struct {
F__sig int64
F__opaque [8]int8
}
type T_opaque_pthread_rwlock_t = struct {
F__sig int64
F__opaque [192]int8
}
type T_opaque_pthread_rwlockattr_t = struct {
F__sig int64
F__opaque [16]int8
}
type T_opaque_pthread_t = struct {
F__sig int64
F__cleanup_stack uintptr
F__opaque [8176]int8
}
type Taccessx_descriptor = struct {
Fad_name_offset uint32
Fad_flags int32
Fad_pad [2]int32
}
// C documentation
//
// /*
// ** The afpLockingContext structure contains all afp lock specific state
// */
type TafpLockingContext = struct {
Freserved int32
FdbPath uintptr
}
type Tattrgroup_t = uint32
type Tattribute_set = Tattribute_set_t
type Tattribute_set_t = struct {
Fcommonattr Tattrgroup_t
Fvolattr Tattrgroup_t
Fdirattr Tattrgroup_t
Ffileattr Tattrgroup_t
Fforkattr Tattrgroup_t
}
type Tattrlist = struct {
Fbitmapcount Tu_short
Freserved Tu_int16_t
Fcommonattr Tattrgroup_t
Fvolattr Tattrgroup_t
Fdirattr Tattrgroup_t
Ffileattr Tattrgroup_t
Fforkattr Tattrgroup_t
}
type Tattrreference = Tattrreference_t
type Tattrreference_t = struct {
Fattr_dataoffset Tint32_t
Fattr_length Tu_int32_t
}
type Tau_asflgs_t = uint64
type Tau_asid_t = int32
type Tau_class_t = uint32
type Tau_ctlmode_t = uint8
type Tau_emod_t = uint16
type Tau_evclass_map = struct {
Fec_number Tau_event_t
Fec_class Tau_class_t
}
type Tau_evclass_map_t = struct {
Fec_number Tau_event_t
Fec_class Tau_class_t
}
type Tau_event_t = uint16
type Tau_expire_after = struct {
Fage Ttime_t
Fsize Tsize_t
Fop_type uint8
}
type Tau_expire_after_t = struct {
Fage Ttime_t
Fsize Tsize_t
Fop_type uint8
}
type Tau_fstat_t = struct {
Faf_filesz Tu_int64_t
Faf_currsz Tu_int64_t
}
type Tau_id_t = uint32
type Tau_mask = struct {
Fam_success uint32
Fam_failure uint32
}
type Tau_mask_t = struct {
Fam_success uint32
Fam_failure uint32
}
type Tau_qctrl = struct {
Faq_hiwater int32
Faq_lowater int32
Faq_bufsz int32
Faq_delay int32
Faq_minfree int32
}
type Tau_qctrl_t = struct {
Faq_hiwater int32
Faq_lowater int32
Faq_bufsz int32
Faq_delay int32
Faq_minfree int32
}
type Tau_session = struct {
Fas_aia_p uintptr
Fas_mask Tau_mask_t
}
type Tau_session_t = struct {
Fas_aia_p uintptr
Fas_mask Tau_mask_t
}
type Tau_stat_t = struct {
Fas_version uint32
Fas_numevent uint32
Fas_generated int32
Fas_nonattrib int32
Fas_kernel int32
Fas_audit int32
Fas_auditctl int32
Fas_enqueue int32
Fas_written int32
Fas_wblocked int32
Fas_rblocked int32
Fas_dropped int32
Fas_totalsize int32
Fas_memused uint32
}
type Tau_tid = struct {
Fport Tdev_t
Fmachine Tu_int32_t
}
type Tau_tid_addr = struct {
Fat_port Tdev_t
Fat_type Tu_int32_t
Fat_addr [4]Tu_int32_t
}
type Tau_tid_addr_t = struct {
Fat_port Tdev_t
Fat_type Tu_int32_t
Fat_addr [4]Tu_int32_t
}
type Tau_tid_t = struct {
Fport Tdev_t
Fmachine Tu_int32_t
}
type Taudit_fstat = struct {
Faf_filesz Tu_int64_t
Faf_currsz Tu_int64_t
}
type Taudit_stat = struct {
Fas_version uint32
Fas_numevent uint32
Fas_generated int32
Fas_nonattrib int32
Fas_kernel int32
Fas_audit int32
Fas_auditctl int32
Fas_enqueue int32
Fas_written int32
Fas_wblocked int32
Fas_rblocked int32
Fas_dropped int32
Fas_totalsize int32
Fas_memused uint32
}
type Tauditinfo = struct {
Fai_auid Tau_id_t
Fai_mask Tau_mask_t
Fai_termid Tau_tid_t
Fai_asid Tau_asid_t
}
type Tauditinfo_addr = struct {
Fai_auid Tau_id_t
Fai_mask Tau_mask_t
Fai_termid Tau_tid_addr_t
Fai_asid Tau_asid_t
Fai_flags Tau_asflgs_t
}
type Tauditinfo_addr_t = struct {
Fai_auid Tau_id_t
Fai_mask Tau_mask_t
Fai_termid Tau_tid_addr_t
Fai_asid Tau_asid_t
Fai_flags Tau_asflgs_t
}
type Tauditinfo_t = struct {
Fai_auid Tau_id_t
Fai_mask Tau_mask_t
Fai_termid Tau_tid_t
Fai_asid Tau_asid_t
}
type Tauditpinfo = struct {
Fap_pid Tpid_t
Fap_auid Tau_id_t
Fap_mask Tau_mask_t
Fap_termid Tau_tid_t
Fap_asid Tau_asid_t
}
type Tauditpinfo_addr = struct {
Fap_pid Tpid_t
Fap_auid Tau_id_t
Fap_mask Tau_mask_t
Fap_termid Tau_tid_addr_t
Fap_asid Tau_asid_t
Fap_flags Tau_asflgs_t
}
type Tauditpinfo_addr_t = struct {
Fap_pid Tpid_t
Fap_auid Tau_id_t
Fap_mask Tau_mask_t
Fap_termid Tau_tid_addr_t
Fap_asid Tau_asid_t
Fap_flags Tau_asflgs_t
}
type Tauditpinfo_t = struct {
Fap_pid Tpid_t
Fap_auid Tau_id_t
Fap_mask Tau_mask_t
Fap_termid Tau_tid_t
Fap_asid Tau_asid_t
}
type Tclock_t = uint64
type Tclockinfo = struct {
Fhz int32
Ftick int32
Ftickadj int32
Fstathz int32
Fprofhz int32
}
type Tcmsghdr = struct {
Fcmsg_len Tsocklen_t
Fcmsg_level int32
Fcmsg_type int32
}
type Tcryptex_auth_type_t = uint32
type Tct_rune_t = int32
type Tdaddr_t = int32
type Tdiskextent = struct {
Fstartblock Tu_int32_t
Fblockcount Tu_int32_t
}
type Textentrecord = [8]Tdiskextent
type Tfattributiontag = Tfattributiontag_t
type Tfattributiontag_t = struct {
Fft_flags uint32
Fft_hash uint64
Fft_attribution_name [255]int8
}
type Tfchecklv = Tfchecklv_t
type Tfchecklv_t = struct {
Flv_file_start Toff_t
Flv_error_message_size Tsize_t
Flv_error_message uintptr
}
type Tfd_mask = int32
type Tfd_set = struct {
Ffds_bits [32]t__int32_t
}
type Tfgetsigsinfo = Tfgetsigsinfo_t
type Tfgetsigsinfo_t = struct {
Ffg_file_start Toff_t
Ffg_info_request int32
Ffg_sig_is_platform int32
}
type Tfhandle = struct {
Ffh_len uint32
Ffh_data [128]uint8
}
type Tfhandle_t = struct {
Ffh_len uint32
Ffh_data [128]uint8
}
type Tfilesec_property_t = int32
type Tfilesec_t = uintptr
type Tflocktimeout = struct {
Ffl Tflock
Ftimeout Ttimespec
}
type Tfpunchhole = Tfpunchhole_t
type Tfpunchhole_t = struct {
Ffp_flags uint32
Freserved uint32
Ffp_offset Toff_t
Ffp_length Toff_t
}
type Tfsblkcnt_t = uint32
type Tfsfilcnt_t = uint32
type Tfsfile_type_t = uint32
type Tfsid = Tfsid_t
type Tfsid_t = struct {
Fval [2]Tint32_t
}
type Tfsignatures = Tfsignatures_t
type Tfsignatures_t = struct {
Ffs_file_start Toff_t
Ffs_blob_start uintptr
Ffs_blob_size Tsize_t
Ffs_fsignatures_size Tsize_t
Ffs_cdhash [20]int8
Ffs_hash_type int32
}
type Tfsobj_id = Tfsobj_id_t
type Tfsobj_id_t = struct {
Ffid_objno Tu_int32_t
Ffid_generation Tu_int32_t
}
type Tfsobj_tag_t = uint32
type Tfsobj_type_t = uint32
type Tfspecread = Tfspecread_t
type Tfspecread_t = struct {
Ffsr_flags uint32
Freserved uint32
Ffsr_offset Toff_t
Ffsr_length Toff_t
}
type Tfssearchblock = struct {
Freturnattrs uintptr
Freturnbuffer uintptr
Freturnbuffersize Tsize_t
Fmaxmatches Tu_long
Ftimelimit Ttimeval
Fsearchparams1 uintptr
Fsizeofsearchparams1 Tsize_t
Fsearchparams2 uintptr
Fsizeofsearchparams2 Tsize_t
Fsearchattrs Tattrlist
}
type Tfstore = Tfstore_t
type Tfstore_t = struct {
Ffst_flags uint32
Ffst_posmode int32
Ffst_offset Toff_t
Ffst_length Toff_t
Ffst_bytesalloc Toff_t
}
type Tfsupplement = Tfsupplement_t
type Tfsupplement_t = struct {
Ffs_file_start Toff_t
Ffs_blob_start Toff_t
Ffs_blob_size Tsize_t
Ffs_orig_fd int32
}
type Tfsvolid_t = uint32
type Tftrimactivefile = Tftrimactivefile_t
type Tftrimactivefile_t = struct {
Ffta_offset Toff_t
Ffta_length Toff_t
}
type Tgraft_args = Tgraftdmg_args_un
type Tgraftdmg_args_un = struct {
Fsbc_args [0]Tsecure_boot_cryptex_args_t
Fmax_size [512]Tu_int8_t
}
type Tgraftdmg_type_t = uint32
type Tif_clonereq = struct {
Fifcr_total int32
Fifcr_count int32
Fifcr_buffer uintptr
}
type Tif_data = struct {
Fifi_type Tu_char
Fifi_typelen Tu_char
Fifi_physical Tu_char
Fifi_addrlen Tu_char
Fifi_hdrlen Tu_char
Fifi_recvquota Tu_char
Fifi_xmitquota Tu_char
Fifi_unused1 Tu_char
Fifi_mtu Tu_int32_t
Fifi_metric Tu_int32_t
Fifi_baudrate Tu_int32_t
Fifi_ipackets Tu_int32_t
Fifi_ierrors Tu_int32_t
Fifi_opackets Tu_int32_t
Fifi_oerrors Tu_int32_t
Fifi_collisions Tu_int32_t
Fifi_ibytes Tu_int32_t
Fifi_obytes Tu_int32_t
Fifi_imcasts Tu_int32_t
Fifi_omcasts Tu_int32_t
Fifi_iqdrops Tu_int32_t
Fifi_noproto Tu_int32_t
Fifi_recvtiming Tu_int32_t
Fifi_xmittiming Tu_int32_t
Fifi_lastchange Ttimeval32
Fifi_unused2 Tu_int32_t
Fifi_hwassist Tu_int32_t
Fifi_reserved1 Tu_int32_t
Fifi_reserved2 Tu_int32_t
}
type Tif_data64 = struct {
Fifi_type Tu_char
Fifi_typelen Tu_char
Fifi_physical Tu_char
Fifi_addrlen Tu_char
Fifi_hdrlen Tu_char
Fifi_recvquota Tu_char
Fifi_xmitquota Tu_char
Fifi_unused1 Tu_char
Fifi_mtu Tu_int32_t
Fifi_metric Tu_int32_t
Fifi_baudrate Tu_int64_t
Fifi_ipackets Tu_int64_t
Fifi_ierrors Tu_int64_t
Fifi_opackets Tu_int64_t
Fifi_oerrors Tu_int64_t
Fifi_collisions Tu_int64_t
Fifi_ibytes Tu_int64_t
Fifi_obytes Tu_int64_t
Fifi_imcasts Tu_int64_t
Fifi_omcasts Tu_int64_t
Fifi_iqdrops Tu_int64_t
Fifi_noproto Tu_int64_t
Fifi_recvtiming Tu_int32_t
Fifi_xmittiming Tu_int32_t
Fifi_lastchange Ttimeval32
}
type Tif_msghdr = struct {
Fifm_msglen uint16
Fifm_version uint8
Fifm_type uint8
Fifm_addrs int32
Fifm_flags int32
Fifm_index uint16
Fifm_data Tif_data
}
type Tif_msghdr2 = struct {
Fifm_msglen Tu_short
Fifm_version Tu_char
Fifm_type Tu_char
Fifm_addrs int32
Fifm_flags int32
Fifm_index Tu_short
Fifm_snd_len int32
Fifm_snd_maxlen int32
Fifm_snd_drops int32
Fifm_timer int32
Fifm_data Tif_data64
}
type Tif_nameindex = struct {
Fif_index uint32
Fif_name uintptr
}
type Tifa_msghdr = struct {
Fifam_msglen uint16
Fifam_version uint8
Fifam_type uint8
Fifam_addrs int32
Fifam_flags int32
Fifam_index uint16
Fifam_metric int32
}
type Tifaliasreq = struct {
Fifra_name [16]int8
Fifra_addr Tsockaddr
Fifra_broadaddr Tsockaddr
Fifra_mask Tsockaddr
}
type Tifconf = struct {
Fifc_len int32
Fifc_ifcu struct {
Fifcu_req [0]uintptr
Fifcu_buf Tcaddr_t
}
}
type Tifdevmtu = struct {
Fifdm_current int32
Fifdm_min int32
Fifdm_max int32
}
type Tifdrv = struct {
Fifd_name [16]int8
Fifd_cmd uint64
Fifd_len Tsize_t
Fifd_data uintptr
}
type Tifkpi = struct {
Fifk_module_id uint32
Fifk_type uint32
Fifk_data struct {
Fifk_value [0]int32
Fifk_ptr uintptr
}
}
type Tifma_msghdr = struct {
Fifmam_msglen uint16
Fifmam_version uint8
Fifmam_type uint8
Fifmam_addrs int32
Fifmam_flags int32
Fifmam_index uint16
}
type Tifma_msghdr2 = struct {
Fifmam_msglen Tu_short
Fifmam_version Tu_char
Fifmam_type Tu_char
Fifmam_addrs int32
Fifmam_flags int32
Fifmam_index Tu_short
Fifmam_refcount Tint32_t
}
type Tifmediareq = struct {
Fifm_name [16]int8
Fifm_current int32
Fifm_mask int32
Fifm_status int32
Fifm_active int32
Fifm_count int32
Fifm_ulist uintptr
}
type Tifqueue = struct {
Fifq_head uintptr
Fifq_tail uintptr
Fifq_len int32
Fifq_maxlen int32
Fifq_drops int32
}
type Tifreq = struct {
Fifr_name [16]int8
Fifr_ifru struct {
Fifru_dstaddr [0]Tsockaddr
Fifru_broadaddr [0]Tsockaddr
Fifru_flags [0]int16
Fifru_metric [0]int32
Fifru_mtu [0]int32
Fifru_phys [0]int32
Fifru_media [0]int32
Fifru_intval [0]int32
Fifru_data [0]Tcaddr_t
Fifru_devmtu [0]Tifdevmtu
Fifru_kpi [0]Tifkpi
Fifru_wake_flags [0]Tu_int32_t
Fifru_route_refcnt [0]Tu_int32_t
Fifru_cap [0][2]int32
Fifru_functional_type [0]Tu_int32_t
Fifru_peer_egress_functional_type [0]Tu_int32_t
Fifru_is_directlink [0]Tu_int8_t
Fifru_is_vpn [0]Tu_int8_t
Fifru_is_companionlink [0]Tu_int8_t
Fifru_addr Tsockaddr
}
}
type Tifstat = struct {
Fifs_name [16]int8
Fascii [801]int8
}
type Tino64_t = uint64
type Tinteger_t = int32
type Tkev_dl_proto_data = struct {
Flink_data Tnet_event_data
Fproto_family Tu_int32_t
Fproto_remaining_count Tu_int32_t
}
type Tlinger = struct {
Fl_onoff int32
Fl_linger int32
}
type Tlog2phys = struct {
Fl2p_flags uint32
Fl2p_contigbytes Toff_t
Fl2p_devoffset Toff_t
}
type Tmach_port_array_t = uintptr
type Tmach_port_context_t = uint64
type Tmach_port_delta_t = int32
type Tmach_port_flavor_t = int32
type Tmach_port_guard_info = Tmach_port_guard_info_t
type Tmach_port_guard_info_t = struct {
Fmpgi_guard Tuint64_t
}
type Tmach_port_info_ext = Tmach_port_info_ext_t
type Tmach_port_info_ext_t = struct {
Fmpie_status Tmach_port_status_t
Fmpie_boost_cnt Tmach_port_msgcount_t
Freserved [6]Tuint32_t
}
type Tmach_port_info_t = uintptr
type Tmach_port_limits = Tmach_port_limits_t
type Tmach_port_limits_t = struct {
Fmpl_qlimit Tmach_port_msgcount_t
}
type Tmach_port_mscount_t = uint32
type Tmach_port_msgcount_t = uint32
type Tmach_port_name_array_t = uintptr
type Tmach_port_name_t = uint32
type Tmach_port_options = Tmach_port_options_t
type Tmach_port_options_ptr_t = uintptr
type Tmach_port_options_t = struct {
Fflags Tuint32_t
Fmpl Tmach_port_limits_t
F__ccgo2_8 struct {
Fwork_interval_port [0]Tmach_port_name_t
Fservice_port_info [0]Tmach_service_port_info_t
Fservice_port_name [0]Tmach_port_name_t
Freserved [2]Tuint64_t
}
}
type Tmach_port_qos = Tmach_port_qos_t
type Tmach_port_qos_t = struct {
F__ccgo0 uint32
Flen1 Tnatural_t
}
type Tmach_port_right_t = uint32
type Tmach_port_rights_t = uint32
type Tmach_port_seqno_t = uint32
type Tmach_port_srights_t = uint32
type Tmach_port_status = Tmach_port_status_t
type Tmach_port_status_t = struct {
Fmps_pset Tmach_port_rights_t
Fmps_seqno Tmach_port_seqno_t
Fmps_mscount Tmach_port_mscount_t
Fmps_qlimit Tmach_port_msgcount_t
Fmps_msgcount Tmach_port_msgcount_t
Fmps_sorights Tmach_port_rights_t
Fmps_srights Tboolean_t
Fmps_pdrequest Tboolean_t
Fmps_nsrequest Tboolean_t
Fmps_flags Tnatural_t
}
type Tmach_port_t = uint32
type Tmach_port_type_array_t = uintptr
type Tmach_port_type_t = uint32
type Tmach_port_urefs_t = uint32
type Tmach_service_port_info = Tmach_service_port_info_data_t
type Tmach_service_port_info_data_t = struct {
Fmspi_string_name [255]int8
Fmspi_domain_type Tuint8_t
}
type Tmach_service_port_info_t = uintptr
type Tmach_vm_address_t = uint64
type Tmach_vm_offset_t = uint64
type Tmach_vm_size_t = uint64
type Tmalloc_type_id_t = uint64
type Tmax_align_t = float64
type Tmcontext_t = uintptr
type Tmount_t = uintptr
type Tmpo_flags_t = uint32
type Tmsghdr = struct {
Fmsg_name uintptr
Fmsg_namelen Tsocklen_t
Fmsg_iov uintptr
Fmsg_iovlen int32
Fmsg_control uintptr
Fmsg_controllen Tsocklen_t
Fmsg_flags int32
}
type Tnatural_t = uint32
type Tnet_event_data = struct {
Fif_family Tu_int32_t
Fif_unit Tu_int32_t
Fif_name [16]int8
}
type Tnetfs_status = struct {
F__ccgo_align [0]uint64
Fns_status Tu_int32_t
Fns_mountopts [512]int8
Fns_waittime Tuint32_t
Fns_threadcount Tuint32_t
}
type Tnlink_t = uint16
type Tos_block_t = uintptr
type Tos_function_t = uintptr
type Tostat = struct {
Fst_dev t__uint16_t
Fst_ino Tino_t
Fst_mode Tmode_t
Fst_nlink Tnlink_t
Fst_uid t__uint16_t
Fst_gid t__uint16_t
Fst_rdev t__uint16_t
Fst_size t__int32_t
Fst_atimespec Ttimespec
Fst_mtimespec Ttimespec
Fst_ctimespec Ttimespec
Fst_blksize t__int32_t
Fst_blocks t__int32_t
Fst_flags t__uint32_t
Fst_gen t__uint32_t
}
type Tposix_cred_t = uintptr
type Tproc_rlimit_control_wakeupmon = struct {
Fwm_flags Tuint32_t
Fwm_rate Tint32_t
}
// C documentation
//
// /*
// ** The proxyLockingContext has the path and file structures for the remote
// ** and local proxy files in it
// */
type TproxyLockingContext = struct {
FconchFile uintptr
FconchFilePath uintptr
FlockProxy uintptr
FlockProxyPath uintptr
FdbPath uintptr
FconchHeld int32
FnFails int32
FoldLockingContext uintptr
FpOldMethod uintptr
}
type Tpthread_attr_t = struct {
F__sig int64
F__opaque [56]int8
}
type Tpthread_cond_t = struct {
F__sig int64
F__opaque [40]int8
}
type Tpthread_condattr_t = struct {
F__sig int64
F__opaque [8]int8
}
type Tpthread_key_t = uint64
type Tpthread_mutex_t = struct {
F__sig int64
F__opaque [56]int8
}
type Tpthread_mutexattr_t = struct {
F__sig int64
F__opaque [8]int8
}
type Tpthread_once_t = struct {
F__sig int64
F__opaque [8]int8
}
type Tpthread_rwlock_t = struct {
F__sig int64
F__opaque [192]int8
}
type Tpthread_rwlockattr_t = struct {
F__sig int64
F__opaque [16]int8
}
type Tradvisory = struct {
Fra_offset Toff_t
Fra_count int32
}
type Trlimit = struct {
Frlim_cur Trlim_t
Frlim_max Trlim_t
}
type Trslvmulti_req = struct {
Fsa uintptr
Fllsa uintptr
}
type Trusage = struct {
Fru_utime Ttimeval
Fru_stime Ttimeval
Fru_maxrss int64
Fru_ixrss int64
Fru_idrss int64
Fru_isrss int64
Fru_minflt int64
Fru_majflt int64
Fru_nswap int64
Fru_inblock int64
Fru_oublock int64
Fru_msgsnd int64
Fru_msgrcv int64
Fru_nsignals int64
Fru_nvcsw int64
Fru_nivcsw int64
}
type Trusage_info_current = struct {
Fri_uuid [16]Tuint8_t
Fri_user_time Tuint64_t
Fri_system_time Tuint64_t
Fri_pkg_idle_wkups Tuint64_t
Fri_interrupt_wkups Tuint64_t
Fri_pageins Tuint64_t
Fri_wired_size Tuint64_t
Fri_resident_size Tuint64_t
Fri_phys_footprint Tuint64_t
Fri_proc_start_abstime Tuint64_t
Fri_proc_exit_abstime Tuint64_t
Fri_child_user_time Tuint64_t
Fri_child_system_time Tuint64_t
Fri_child_pkg_idle_wkups Tuint64_t
Fri_child_interrupt_wkups Tuint64_t
Fri_child_pageins Tuint64_t
Fri_child_elapsed_abstime Tuint64_t
Fri_diskio_bytesread Tuint64_t
Fri_diskio_byteswritten Tuint64_t
Fri_cpu_time_qos_default Tuint64_t
Fri_cpu_time_qos_maintenance Tuint64_t
Fri_cpu_time_qos_background Tuint64_t
Fri_cpu_time_qos_utility Tuint64_t
Fri_cpu_time_qos_legacy Tuint64_t
Fri_cpu_time_qos_user_initiated Tuint64_t
Fri_cpu_time_qos_user_interactive Tuint64_t
Fri_billed_system_time Tuint64_t
Fri_serviced_system_time Tuint64_t
Fri_logical_writes Tuint64_t
Fri_lifetime_max_phys_footprint Tuint64_t
Fri_instructions Tuint64_t
Fri_cycles Tuint64_t
Fri_billed_energy Tuint64_t
Fri_serviced_energy Tuint64_t
Fri_interval_max_phys_footprint Tuint64_t
Fri_runnable_time Tuint64_t
Fri_flags Tuint64_t
Fri_user_ptime Tuint64_t
Fri_system_ptime Tuint64_t
Fri_pinstructions Tuint64_t
Fri_pcycles Tuint64_t
Fri_energy_nj Tuint64_t
Fri_penergy_nj Tuint64_t
Fri_secure_time_in_system Tuint64_t
Fri_secure_ptime_in_system Tuint64_t
Fri_neural_footprint Tuint64_t
Fri_lifetime_max_neural_footprint Tuint64_t
Fri_interval_max_neural_footprint Tuint64_t
Fri_reserved [9]Tuint64_t
}
type Trusage_info_t = uintptr
type Trusage_info_v0 = struct {
Fri_uuid [16]Tuint8_t
Fri_user_time Tuint64_t
Fri_system_time Tuint64_t
Fri_pkg_idle_wkups Tuint64_t
Fri_interrupt_wkups Tuint64_t
Fri_pageins Tuint64_t
Fri_wired_size Tuint64_t
Fri_resident_size Tuint64_t
Fri_phys_footprint Tuint64_t
Fri_proc_start_abstime Tuint64_t
Fri_proc_exit_abstime Tuint64_t
}
type Trusage_info_v1 = struct {
Fri_uuid [16]Tuint8_t
Fri_user_time Tuint64_t
Fri_system_time Tuint64_t
Fri_pkg_idle_wkups Tuint64_t
Fri_interrupt_wkups Tuint64_t
Fri_pageins Tuint64_t
Fri_wired_size Tuint64_t
Fri_resident_size Tuint64_t
Fri_phys_footprint Tuint64_t
Fri_proc_start_abstime Tuint64_t
Fri_proc_exit_abstime Tuint64_t
Fri_child_user_time Tuint64_t
Fri_child_system_time Tuint64_t
Fri_child_pkg_idle_wkups Tuint64_t
Fri_child_interrupt_wkups Tuint64_t
Fri_child_pageins Tuint64_t
Fri_child_elapsed_abstime Tuint64_t
}
type Trusage_info_v2 = struct {
Fri_uuid [16]Tuint8_t
Fri_user_time Tuint64_t
Fri_system_time Tuint64_t
Fri_pkg_idle_wkups Tuint64_t
Fri_interrupt_wkups Tuint64_t
Fri_pageins Tuint64_t
Fri_wired_size Tuint64_t
Fri_resident_size Tuint64_t
Fri_phys_footprint Tuint64_t
Fri_proc_start_abstime Tuint64_t
Fri_proc_exit_abstime Tuint64_t
Fri_child_user_time Tuint64_t
Fri_child_system_time Tuint64_t
Fri_child_pkg_idle_wkups Tuint64_t
Fri_child_interrupt_wkups Tuint64_t
Fri_child_pageins Tuint64_t
Fri_child_elapsed_abstime Tuint64_t
Fri_diskio_bytesread Tuint64_t
Fri_diskio_byteswritten Tuint64_t
}
type Trusage_info_v3 = struct {
Fri_uuid [16]Tuint8_t
Fri_user_time Tuint64_t
Fri_system_time Tuint64_t
Fri_pkg_idle_wkups Tuint64_t
Fri_interrupt_wkups Tuint64_t
Fri_pageins Tuint64_t
Fri_wired_size Tuint64_t
Fri_resident_size Tuint64_t
Fri_phys_footprint Tuint64_t
Fri_proc_start_abstime Tuint64_t
Fri_proc_exit_abstime Tuint64_t
Fri_child_user_time Tuint64_t
Fri_child_system_time Tuint64_t
Fri_child_pkg_idle_wkups Tuint64_t
Fri_child_interrupt_wkups Tuint64_t
Fri_child_pageins Tuint64_t
Fri_child_elapsed_abstime Tuint64_t
Fri_diskio_bytesread Tuint64_t
Fri_diskio_byteswritten Tuint64_t
Fri_cpu_time_qos_default Tuint64_t
Fri_cpu_time_qos_maintenance Tuint64_t
Fri_cpu_time_qos_background Tuint64_t
Fri_cpu_time_qos_utility Tuint64_t
Fri_cpu_time_qos_legacy Tuint64_t
Fri_cpu_time_qos_user_initiated Tuint64_t
Fri_cpu_time_qos_user_interactive Tuint64_t
Fri_billed_system_time Tuint64_t
Fri_serviced_system_time Tuint64_t
}
type Trusage_info_v4 = struct {
Fri_uuid [16]Tuint8_t
Fri_user_time Tuint64_t
Fri_system_time Tuint64_t
Fri_pkg_idle_wkups Tuint64_t
Fri_interrupt_wkups Tuint64_t
Fri_pageins Tuint64_t
Fri_wired_size Tuint64_t
Fri_resident_size Tuint64_t
Fri_phys_footprint Tuint64_t
Fri_proc_start_abstime Tuint64_t
Fri_proc_exit_abstime Tuint64_t
Fri_child_user_time Tuint64_t
Fri_child_system_time Tuint64_t
Fri_child_pkg_idle_wkups Tuint64_t
Fri_child_interrupt_wkups Tuint64_t
Fri_child_pageins Tuint64_t
Fri_child_elapsed_abstime Tuint64_t
Fri_diskio_bytesread Tuint64_t
Fri_diskio_byteswritten Tuint64_t
Fri_cpu_time_qos_default Tuint64_t
Fri_cpu_time_qos_maintenance Tuint64_t
Fri_cpu_time_qos_background Tuint64_t
Fri_cpu_time_qos_utility Tuint64_t
Fri_cpu_time_qos_legacy Tuint64_t
Fri_cpu_time_qos_user_initiated Tuint64_t
Fri_cpu_time_qos_user_interactive Tuint64_t
Fri_billed_system_time Tuint64_t
Fri_serviced_system_time Tuint64_t
Fri_logical_writes Tuint64_t
Fri_lifetime_max_phys_footprint Tuint64_t
Fri_instructions Tuint64_t
Fri_cycles Tuint64_t
Fri_billed_energy Tuint64_t
Fri_serviced_energy Tuint64_t
Fri_interval_max_phys_footprint Tuint64_t
Fri_runnable_time Tuint64_t
}
type Trusage_info_v5 = struct {
Fri_uuid [16]Tuint8_t
Fri_user_time Tuint64_t
Fri_system_time Tuint64_t
Fri_pkg_idle_wkups Tuint64_t
Fri_interrupt_wkups Tuint64_t
Fri_pageins Tuint64_t
Fri_wired_size Tuint64_t
Fri_resident_size Tuint64_t
Fri_phys_footprint Tuint64_t
Fri_proc_start_abstime Tuint64_t
Fri_proc_exit_abstime Tuint64_t
Fri_child_user_time Tuint64_t
Fri_child_system_time Tuint64_t
Fri_child_pkg_idle_wkups Tuint64_t
Fri_child_interrupt_wkups Tuint64_t
Fri_child_pageins Tuint64_t
Fri_child_elapsed_abstime Tuint64_t
Fri_diskio_bytesread Tuint64_t
Fri_diskio_byteswritten Tuint64_t
Fri_cpu_time_qos_default Tuint64_t
Fri_cpu_time_qos_maintenance Tuint64_t
Fri_cpu_time_qos_background Tuint64_t
Fri_cpu_time_qos_utility Tuint64_t
Fri_cpu_time_qos_legacy Tuint64_t
Fri_cpu_time_qos_user_initiated Tuint64_t
Fri_cpu_time_qos_user_interactive Tuint64_t
Fri_billed_system_time Tuint64_t
Fri_serviced_system_time Tuint64_t
Fri_logical_writes Tuint64_t
Fri_lifetime_max_phys_footprint Tuint64_t
Fri_instructions Tuint64_t
Fri_cycles Tuint64_t
Fri_billed_energy Tuint64_t
Fri_serviced_energy Tuint64_t
Fri_interval_max_phys_footprint Tuint64_t
Fri_runnable_time Tuint64_t
Fri_flags Tuint64_t
}
type Trusage_info_v6 = struct {
Fri_uuid [16]Tuint8_t
Fri_user_time Tuint64_t
Fri_system_time Tuint64_t
Fri_pkg_idle_wkups Tuint64_t
Fri_interrupt_wkups Tuint64_t
Fri_pageins Tuint64_t
Fri_wired_size Tuint64_t
Fri_resident_size Tuint64_t
Fri_phys_footprint Tuint64_t
Fri_proc_start_abstime Tuint64_t
Fri_proc_exit_abstime Tuint64_t
Fri_child_user_time Tuint64_t
Fri_child_system_time Tuint64_t
Fri_child_pkg_idle_wkups Tuint64_t
Fri_child_interrupt_wkups Tuint64_t
Fri_child_pageins Tuint64_t
Fri_child_elapsed_abstime Tuint64_t
Fri_diskio_bytesread Tuint64_t
Fri_diskio_byteswritten Tuint64_t
Fri_cpu_time_qos_default Tuint64_t
Fri_cpu_time_qos_maintenance Tuint64_t
Fri_cpu_time_qos_background Tuint64_t
Fri_cpu_time_qos_utility Tuint64_t
Fri_cpu_time_qos_legacy Tuint64_t
Fri_cpu_time_qos_user_initiated Tuint64_t
Fri_cpu_time_qos_user_interactive Tuint64_t
Fri_billed_system_time Tuint64_t
Fri_serviced_system_time Tuint64_t
Fri_logical_writes Tuint64_t
Fri_lifetime_max_phys_footprint Tuint64_t
Fri_instructions Tuint64_t
Fri_cycles Tuint64_t
Fri_billed_energy Tuint64_t
Fri_serviced_energy Tuint64_t
Fri_interval_max_phys_footprint Tuint64_t
Fri_runnable_time Tuint64_t
Fri_flags Tuint64_t
Fri_user_ptime Tuint64_t
Fri_system_ptime Tuint64_t
Fri_pinstructions Tuint64_t
Fri_pcycles Tuint64_t
Fri_energy_nj Tuint64_t
Fri_penergy_nj Tuint64_t
Fri_secure_time_in_system Tuint64_t
Fri_secure_ptime_in_system Tuint64_t
Fri_neural_footprint Tuint64_t
Fri_lifetime_max_neural_footprint Tuint64_t
Fri_interval_max_neural_footprint Tuint64_t
Fri_reserved [9]Tuint64_t
}
type Tsa_endpoints = Tsa_endpoints_t
type Tsa_endpoints_t = struct {
Fsae_srcif uint32
Fsae_srcaddr uintptr
Fsae_srcaddrlen Tsocklen_t
Fsae_dstaddr uintptr
Fsae_dstaddrlen Tsocklen_t
}
type Tsa_family_t = uint8
type Tsae_associd_t = uint32
type Tsae_connid_t = uint32
type Tsearchstate = struct {
Fss_union_flags Tuint32_t
Fss_union_layer Tuint32_t
Fss_fsstate [548]Tu_char
}
type Tsecure_boot_cryptex_args = Tsecure_boot_cryptex_args_t
type Tsecure_boot_cryptex_args_t = struct {
Fsbc_version Tu_int32_t
Fsbc_4cc Tu_int32_t
Fsbc_authentic_manifest_fd int32
Fsbc_user_manifest_fd int32
Fsbc_payload_fd int32
Fsbc_flags Tu_int64_t
}
type Tsf_hdtr = struct {
Fheaders uintptr
Fhdr_cnt int32
Ftrailers uintptr
Ftrl_cnt int32
}
type Tsig_atomic_t = int32
type Tsig_t = uintptr
type Tsigaction = struct {
F__sigaction_u t__sigaction_u
Fsa_mask Tsigset_t
Fsa_flags int32
}
type Tsigevent = struct {
Fsigev_notify int32
Fsigev_signo int32
Fsigev_value Tsigval
Fsigev_notify_function uintptr
Fsigev_notify_attributes uintptr
}
type Tsiginfo_t = struct {
Fsi_signo int32
Fsi_errno int32
Fsi_code int32
Fsi_pid Tpid_t
Fsi_uid Tuid_t
Fsi_status int32
Fsi_addr uintptr
Fsi_value Tsigval
Fsi_band int64
F__pad [7]uint64
}
type Tsigstack = struct {
Fss_sp uintptr
Fss_onstack int32
}
type Tsigval = struct {
Fsival_ptr [0]uintptr
Fsival_int int32
F__ccgo_pad2 [4]byte
}
type Tsigvec = struct {
Fsv_handler uintptr
Fsv_mask int32
Fsv_flags int32
}
type Tso_np_extensions = struct {
Fnpx_flags Tu_int32_t
Fnpx_mask Tu_int32_t
}
type Tsockaddr = struct {
Fsa_len t__uint8_t
Fsa_family Tsa_family_t
Fsa_data [14]int8
}
type Tsockaddr_storage = struct {
Fss_len t__uint8_t
Fss_family Tsa_family_t
F__ss_pad1 [6]int8
F__ss_align t__int64_t
F__ss_pad2 [112]int8
}
type Tsocklen_t = uint32
type Tsockproto = struct {
Fsp_family t__uint16_t
Fsp_protocol t__uint16_t
}
type Tstack_t = struct {
Fss_sp uintptr
Fss_size t__darwin_size_t
Fss_flags int32
}
type Tstat = struct {
Fst_dev Tdev_t
Fst_mode Tmode_t
Fst_nlink Tnlink_t
Fst_ino t__darwin_ino64_t
Fst_uid Tuid_t
Fst_gid Tgid_t
Fst_rdev Tdev_t
Fst_atimespec Ttimespec
Fst_mtimespec Ttimespec
Fst_ctimespec Ttimespec
Fst_birthtimespec Ttimespec
Fst_size Toff_t
Fst_blocks Tblkcnt_t
Fst_blksize Tblksize_t
Fst_flags t__uint32_t
Fst_gen t__uint32_t
Fst_lspare t__int32_t
Fst_qspare [2]t__int64_t
}
type Tstatfs = struct {
Ff_bsize Tuint32_t
Ff_iosize Tint32_t
Ff_blocks Tuint64_t
Ff_bfree Tuint64_t
Ff_bavail Tuint64_t
Ff_files Tuint64_t
Ff_ffree Tuint64_t
Ff_fsid Tfsid_t
Ff_owner Tuid_t
Ff_type Tuint32_t
Ff_flags Tuint32_t
Ff_fssubtype Tuint32_t
Ff_fstypename [16]int8
Ff_mntonname [1024]int8
Ff_mntfromname [1024]int8
Ff_flags_ext Tuint32_t
Ff_reserved [7]Tuint32_t
}
type Tsyscall_arg_t = uint64
type Ttext_encoding_t = uint32
type Ttimespec = struct {
Ftv_sec t__darwin_time_t
Ftv_nsec int64
}
type Ttimeval = struct {
Ftv_sec t__darwin_time_t
Ftv_usec t__darwin_suseconds_t
}
type Ttimeval32 = struct {
Ftv_sec t__int32_t
Ftv_usec t__int32_t
}
type Ttimeval64 = struct {
Ftv_sec t__int64_t
Ftv_usec t__int64_t
}
type Tucontext_t = struct {
Fuc_onstack int32
Fuc_sigmask t__darwin_sigset_t
Fuc_stack t__darwin_sigaltstack
Fuc_link uintptr
Fuc_mcsize t__darwin_size_t
Fuc_mcontext uintptr
}
// C documentation
//
// /*
// ** The unixFile structure is subclass of sqlite3_file specific to the unix
// ** VFS implementations.
// */
type TunixFile = struct {
FpMethod uintptr
FpVfs uintptr
FpInode uintptr
Fh int32
FeFileLock uint8
FctrlFlags uint16
FlastErrno int32
FlockingContext uintptr
FpPreallocatedUnused uintptr
FzPath uintptr
FpShm uintptr
FszChunk int32
FnFetchOut int32
FmmapSize Tsqlite3_int64
FmmapSizeActual Tsqlite3_int64
FmmapSizeMax Tsqlite3_int64
FpMapRegion uintptr
FsectorSize int32
FdeviceCharacteristics int32
FopenFlags int32
FfsFlags uint32
}
/* Shared memory instance */
type TunixInodeInfo = struct {
FfileId TunixFileId
FpLockMutex uintptr
FnShared int32
FnLock int32
FeFileLock uint8
FbProcessLock uint8
FpUnused uintptr
FnRef int32
FpShmNode uintptr
FpNext uintptr
FpPrev uintptr
FsharedByte uint64
}
type Tuser_addr_t = uint64
type Tuser_long_t = int64
type Tuser_off_t = int64
type Tuser_size_t = uint64
type Tuser_ssize_t = int64
type Tuser_time_t = int64
type Tuser_ulong_t = uint64
type Tuuid_t = [16]uint8
type Tvfs_server = struct {
Fvs_minutes Tint32_t
Fvs_server_name [768]Tu_int8_t
}
type Tvfsconf = struct {
Fvfc_reserved1 Tuint32_t
Fvfc_name [15]int8
Fvfc_typenum int32
Fvfc_refcount int32
Fvfc_flags int32
Fvfc_reserved2 Tuint32_t
Fvfc_reserved3 Tuint32_t
}
type Tvfsidctl = struct {
Fvc_vers int32
Fvc_fsid Tfsid_t
Fvc_ptr uintptr
Fvc_len Tsize_t
Fvc_spare [12]Tu_int32_t
}
type Tvfsquery = struct {
Fvq_flags Tu_int32_t
Fvq_spare [31]Tu_int32_t
}
type Tvfsstatfs = struct {
Ff_bsize Tuint32_t
Ff_iosize Tsize_t
Ff_blocks Tuint64_t
Ff_bfree Tuint64_t
Ff_bavail Tuint64_t
Ff_bused Tuint64_t
Ff_files Tuint64_t
Ff_ffree Tuint64_t
Ff_fsid Tfsid_t
Ff_owner Tuid_t
Ff_flags Tuint64_t
Ff_fstypename [16]int8
Ff_mntonname [1024]int8
Ff_mntfromname [1024]int8
Ff_fssubtype Tuint32_t
Ff_reserved [2]uintptr
}
type Tvm_map_address_t = uint64
type Tvm_map_offset_t = uint64
type Tvm_map_size_t = uint64
type Tvnode_t = uintptr
type Tvol_attributes_attr = Tvol_attributes_attr_t
type Tvol_attributes_attr_t = struct {
Fvalidattr Tattribute_set_t
Fnativeattr Tattribute_set_t
}
type Tvol_capabilities_attr = Tvol_capabilities_attr_t
type Tvol_capabilities_attr_t = struct {
Fcapabilities Tvol_capabilities_set_t
Fvalid Tvol_capabilities_set_t
}
type Tvol_capabilities_set_t = [4]Tu_int32_t
type Twait = struct {
Fw_T [0]struct {
F__ccgo0 uint32
}
Fw_S [0]struct {
F__ccgo0 uint32
}
Fw_status int32
}
type Txucred = struct {
Fcr_version Tu_int
Fcr_uid Tuid_t
Fcr_ngroups int16
Fcr_groups [16]Tgid_t
}
const UF_COMPRESSED = 32
const UF_DATAVAULT = 128
const UF_TRACKED = 64
const UNGRAFTDMG_NOFORCE = 2
const USER_FSIGNATURES_CDHASH_LEN = 20
const VFS_CONF = 2
const VFS_CTL_DISC = 65544
const VFS_CTL_NEWADDR = 65540
const VFS_CTL_NOLOCKS = 65542
const VFS_CTL_NSTATUS = 65546
const VFS_CTL_OSTATFS = 65537
const VFS_CTL_QUERY = 65539
const VFS_CTL_SADDR = 65543
const VFS_CTL_SERVERINFO = 65545
const VFS_CTL_STATFS = 65547
const VFS_CTL_STATFS64 = 65547
const VFS_CTL_TIMEO = 65541
const VFS_CTL_UMOUNT = 65538
const VFS_CTL_VERS1 = 1
const VFS_GENERIC = 0
const VFS_MAXTYPENUM = 1
const VFS_NUMMNTOPS = 1
const VOL_CAPABILITIES_FORMAT = 0
const VOL_CAPABILITIES_INTERFACES = 1
const VOL_CAPABILITIES_RESERVED1 = 2
const VOL_CAPABILITIES_RESERVED2 = 3
const VOL_CAP_FMT_2TB_FILESIZE = 2048
const VOL_CAP_FMT_64BIT_OBJECT_IDS = 131072
const VOL_CAP_FMT_CASE_PRESERVING = 512
const VOL_CAP_FMT_CASE_SENSITIVE = 256
const VOL_CAP_FMT_CLONE_MAPPING = 67108864
const VOL_CAP_FMT_DECMPFS_COMPRESSION = 65536
const VOL_CAP_FMT_DIR_HARDLINKS = 262144
const VOL_CAP_FMT_DOCUMENT_ID = 524288
const VOL_CAP_FMT_FAST_STATFS = 1024
const VOL_CAP_FMT_HARDLINKS = 4
const VOL_CAP_FMT_HIDDEN_FILES = 8192
const VOL_CAP_FMT_JOURNAL = 8
const VOL_CAP_FMT_JOURNAL_ACTIVE = 16
const VOL_CAP_FMT_NO_IMMUTABLE_FILES = 2097152
const VOL_CAP_FMT_NO_PERMISSIONS = 4194304
const VOL_CAP_FMT_NO_ROOT_TIMES = 32
const VOL_CAP_FMT_NO_VOLUME_SIZES = 32768
const VOL_CAP_FMT_OPENDENYMODES = 4096
const VOL_CAP_FMT_PATH_FROM_ID = 16384
const VOL_CAP_FMT_PERSISTENTOBJECTIDS = 1
const VOL_CAP_FMT_SEALED = 33554432
const VOL_CAP_FMT_SHARED_SPACE = 8388608
const VOL_CAP_FMT_SPARSE_FILES = 64
const VOL_CAP_FMT_SYMBOLICLINKS = 2
const VOL_CAP_FMT_VOL_GROUPS = 16777216
const VOL_CAP_FMT_WRITE_GENERATION_COUNT = 1048576
const VOL_CAP_FMT_ZERO_RUNS = 128
const VOL_CAP_INT_ADVLOCK = 256
const VOL_CAP_INT_ALLOCATE = 64
const VOL_CAP_INT_ATTRIBUTION_TAG = 4194304
const VOL_CAP_INT_ATTRLIST = 2
const VOL_CAP_INT_BARRIERFSYNC = 16777216
const VOL_CAP_INT_CLONE = 65536
const VOL_CAP_INT_COPYFILE = 32
const VOL_CAP_INT_EXCHANGEDATA = 16
const VOL_CAP_INT_EXTENDED_ATTR = 16384
const VOL_CAP_INT_EXTENDED_SECURITY = 1024
const VOL_CAP_INT_FLOCK = 512
const VOL_CAP_INT_MANLOCK = 4096
const VOL_CAP_INT_NAMEDSTREAMS = 8192
const VOL_CAP_INT_NFSEXPORT = 4
const VOL_CAP_INT_PUNCHHOLE = 8388608
const VOL_CAP_INT_READDIRATTR = 8
const VOL_CAP_INT_RENAME_EXCL = 524288
const VOL_CAP_INT_RENAME_OPENFAIL = 1048576
const VOL_CAP_INT_RENAME_SECLUDE = 2097152
const VOL_CAP_INT_RENAME_SWAP = 262144
const VOL_CAP_INT_SEARCHFS = 1
const VOL_CAP_INT_SNAPSHOT = 131072
const VOL_CAP_INT_USERACCESS = 2048
const VOL_CAP_INT_VOL_RENAME = 128
const VQ_ASSIST = 64
const VQ_DEAD = 32
const VQ_DESIRED_DISK = 16384
const VQ_FLAG40000 = 262144
const VQ_FREE_SPACE_CHANGE = 32768
const VQ_IDLE_PURGE_NOTIFY = 131072
const VQ_LOWDISK = 4
const VQ_MOUNT = 8
const VQ_NEARLOWDISK = 8192
const VQ_NEEDAUTH = 2
const VQ_NOTRESP = 1
const VQ_NOTRESPLOCK = 128
const VQ_PURGEABLE_SPACE_CHANGE = 65536
const VQ_QUOTA = 4096
const VQ_SERVEREVENT = 2048
const VQ_SYNCEVENT = 1024
const VQ_UNMOUNT = 16
const VQ_UPDATE = 256
const VQ_VERYLOWDISK = 512
const WAIT_ANY = -1
const WAIT_MYPGRP = 0
const WAKEMON_DISABLE = 2
const WAKEMON_ENABLE = 1
const WAKEMON_GET_PARAMS = 4
const WAKEMON_MAKE_FATAL = 16
const WAKEMON_SET_DEFAULTS = 8
const WCONTINUED = 16
const WCOREFLAG = 128
const WEXITED = 4
const WNOWAIT = 32
const WSTOPPED = 8
const XUCRED_VERSION = 0
// C documentation
//
// /*
// ** Create an sqlite3_backup process to copy the contents of zSrcDb from
// ** connection handle pSrcDb to zDestDb in pDestDb. If successful, return
// ** a pointer to the new sqlite3_backup object.
// **
// ** If an error occurs, NULL is returned and an error code and error message
// ** stored in database handle pDestDb.
// */
func Xsqlite3_backup_init(tls *libc.TLS, pDestDb uintptr, zDestDb uintptr, pSrcDb uintptr, zSrcDb uintptr) (r uintptr) {
var nDest int32
var p, pDest uintptr
_, _, _ = nDest, p, pDest /* Value to return */
/* Lock the source database handle. The destination database
** handle is not locked in this routine, but it is locked in
** sqlite3_backup_step(). The user is required to ensure that no
** other thread accesses the destination handle for the duration
** of the backup operation. Any attempt to use the destination
** database connection while a backup is in progress may cause
** a malfunction or a deadlock.
*/
Xsqlite3_mutex_enter(tls, (*Tsqlite3)(unsafe.Pointer(pSrcDb)).Fmutex)
Xsqlite3_mutex_enter(tls, (*Tsqlite3)(unsafe.Pointer(pDestDb)).Fmutex)
if pSrcDb == pDestDb {
_sqlite3ErrorWithMsg(tls, pDestDb, int32(SQLITE_ERROR), __ccgo_ts+5524, 0)
p = uintptr(0)
} else {
nDest = _sqlite3Strlen30(tls, zDestDb)
/* Allocate space for a new sqlite3_backup object...
** EVIDENCE-OF: R-64852-21591 The sqlite3_backup object is created by a
** call to sqlite3_backup_init() and is destroyed by a call to
** sqlite3_backup_finish(). */
p = _sqlite3MallocZero(tls, uint64(uint64(80)+libc.Uint64FromInt32(nDest)+uint64(1)))
if !(p != 0) {
_sqlite3Error(tls, pDestDb, int32(SQLITE_NOMEM))
} else {
(*Tsqlite3_backup)(unsafe.Pointer(p)).FzDestDb = p + 1*80
libc.X__builtin___memcpy_chk(tls, (*Tsqlite3_backup)(unsafe.Pointer(p)).FzDestDb, zDestDb, libc.Uint64FromInt32(nDest), ^t__predefined_size_t(0))
}
}
/* If the allocation succeeded, populate the new object. */
if p != 0 {
/* Do not store the pointer to the destination b-tree at this point.
** This is because there is nothing preventing it from being detached
** or otherwise freed before the first call to sqlite3_backup_step()
** on this object. The source b-tree does not have this problem, as
** incrementing Btree.nBackup (see below) effectively locks the object. */
pDest = _findBtree(tls, pDestDb, pDestDb, zDestDb)
(*Tsqlite3_backup)(unsafe.Pointer(p)).FpSrc = _findBtree(tls, pDestDb, pSrcDb, zSrcDb)
(*Tsqlite3_backup)(unsafe.Pointer(p)).FpDestDb = pDestDb
(*Tsqlite3_backup)(unsafe.Pointer(p)).FpSrcDb = pSrcDb
(*Tsqlite3_backup)(unsafe.Pointer(p)).FiNext = uint32(1)
(*Tsqlite3_backup)(unsafe.Pointer(p)).FisAttached = 0
if uintptr(0) == (*Tsqlite3_backup)(unsafe.Pointer(p)).FpSrc || uintptr(0) == pDest || _checkReadTransaction(tls, pDestDb, pDest) != SQLITE_OK {
/* One (or both) of the named databases did not exist or an OOM
** error was hit. Or there is a transaction open on the destination
** database. The error has already been written into the pDestDb
** handle. All that is left to do here is free the sqlite3_backup
** structure. */
Xsqlite3_free(tls, p)
p = uintptr(0)
}
}
if p != 0 {
(*TBtree)(unsafe.Pointer((*Tsqlite3_backup)(unsafe.Pointer(p)).FpSrc)).FnBackup = (*TBtree)(unsafe.Pointer((*Tsqlite3_backup)(unsafe.Pointer(p)).FpSrc)).FnBackup + 1
}
Xsqlite3_mutex_leave(tls, (*Tsqlite3)(unsafe.Pointer(pDestDb)).Fmutex)
Xsqlite3_mutex_leave(tls, (*Tsqlite3)(unsafe.Pointer(pSrcDb)).Fmutex)
return p
}
// C documentation
//
// /*
// ** Open a blob handle.
// */
func Xsqlite3_blob_open(tls *libc.TLS, db uintptr, zDb uintptr, zTable uintptr, zColumn uintptr, iRow Tsqlite_int64, wrFlag int32, ppBlob uintptr) (r int32) {
bp := tls.Alloc(448)
defer tls.Free(448)
var aOp, pBlob, pFKey, pIdx, pTab, v, zFault, v8 uintptr
var iCol, iDb, j, j1, nAttempt, rc, v1 int32
var v2 bool
var _ /* sParse at bp+8 */ TParse
var _ /* zErr at bp+0 */ uintptr
_, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _ = aOp, iCol, iDb, j, j1, nAttempt, pBlob, pFKey, pIdx, pTab, rc, v, zFault, v1, v2, v8
nAttempt = 0 /* Index of zColumn in row-record */
rc = SQLITE_OK
**(**uintptr)(__ccgo_up(bp)) = uintptr(0)
pBlob = uintptr(0)
**(**uintptr)(__ccgo_up(ppBlob)) = uintptr(0)
wrFlag = libc.BoolInt32(!!(wrFlag != 0)) /* wrFlag = (wrFlag ? 1 : 0); */
Xsqlite3_mutex_enter(tls, (*Tsqlite3)(unsafe.Pointer(db)).Fmutex)
pBlob = _sqlite3DbMallocZero(tls, db, uint64(56))
for int32(1) != 0 {
_sqlite3ParseObjectInit(tls, bp+8, db)
if !(pBlob != 0) {
goto blob_open_out
}
_sqlite3DbFree(tls, db, **(**uintptr)(__ccgo_up(bp)))
**(**uintptr)(__ccgo_up(bp)) = uintptr(0)
_sqlite3BtreeEnterAll(tls, db)
pTab = _sqlite3LocateTable(tls, bp+8, uint32(0), zTable, zDb)
if pTab != 0 && libc.Int32FromUint8((*TTable)(unsafe.Pointer(pTab)).FeTabType) == int32(TABTYP_VTAB) {
pTab = uintptr(0)
_sqlite3ErrorMsg(tls, bp+8, __ccgo_ts+6897, libc.VaList(bp+440, zTable))
}
if pTab != 0 && !((*TTable)(unsafe.Pointer(pTab)).FtabFlags&libc.Uint32FromInt32(TF_WithoutRowid) == libc.Uint32FromInt32(0)) {
pTab = uintptr(0)
_sqlite3ErrorMsg(tls, bp+8, __ccgo_ts+6927, libc.VaList(bp+440, zTable))
}
if pTab != 0 && (*TTable)(unsafe.Pointer(pTab)).FtabFlags&uint32(TF_HasGenerated) != uint32(0) {
pTab = uintptr(0)
_sqlite3ErrorMsg(tls, bp+8, __ccgo_ts+6963, libc.VaList(bp+440, zTable))
}
if pTab != 0 && libc.Int32FromUint8((*TTable)(unsafe.Pointer(pTab)).FeTabType) == int32(TABTYP_VIEW) {
pTab = uintptr(0)
_sqlite3ErrorMsg(tls, bp+8, __ccgo_ts+7008, libc.VaList(bp+440, zTable))
}
if v2 = pTab == uintptr(0); !v2 {
v1 = _sqlite3SchemaToIndex(tls, db, (*TTable)(unsafe.Pointer(pTab)).FpSchema)
iDb = v1
}
if v2 || v1 == int32(1) && _sqlite3OpenTempDatabase(tls, bp+8) != 0 {
if (**(**TParse)(__ccgo_up(bp + 8))).FzErrMsg != 0 {
_sqlite3DbFree(tls, db, **(**uintptr)(__ccgo_up(bp)))
**(**uintptr)(__ccgo_up(bp)) = (**(**TParse)(__ccgo_up(bp + 8))).FzErrMsg
(**(**TParse)(__ccgo_up(bp + 8))).FzErrMsg = uintptr(0)
}
rc = int32(SQLITE_ERROR)
_sqlite3BtreeLeaveAll(tls, db)
goto blob_open_out
}
(*TIncrblob)(unsafe.Pointer(pBlob)).FpTab = pTab
(*TIncrblob)(unsafe.Pointer(pBlob)).FzDb = (**(**TDb)(__ccgo_up((*Tsqlite3)(unsafe.Pointer(db)).FaDb + uintptr(iDb)*32))).FzDbSName
/* Now search pTab for the exact column. */
iCol = _sqlite3ColumnIndex(tls, pTab, zColumn)
if iCol < 0 {
_sqlite3DbFree(tls, db, **(**uintptr)(__ccgo_up(bp)))
**(**uintptr)(__ccgo_up(bp)) = _sqlite3MPrintf(tls, db, __ccgo_ts+7029, libc.VaList(bp+440, zColumn))
rc = int32(SQLITE_ERROR)
_sqlite3BtreeLeaveAll(tls, db)
goto blob_open_out
}
/* If the value is being opened for writing, check that the
** column is not indexed, and that it is not part of a foreign key.
*/
if wrFlag != 0 {
zFault = uintptr(0)
if (*Tsqlite3)(unsafe.Pointer(db)).Fflags&uint64(SQLITE_ForeignKeys) != 0 {
pFKey = (*(*struct {
FaddColOffset int32
FpFKey uintptr
FpDfltList uintptr
})(unsafe.Pointer(pTab + 64))).FpFKey
for {
if !(pFKey != 0) {
break
}
j = 0
for {
if !(j < (*TFKey)(unsafe.Pointer(pFKey)).FnCol) {
break
}
if (*(*TsColMap)(unsafe.Pointer(pFKey + 64 + uintptr(j)*16))).FiFrom == iCol {
zFault = __ccgo_ts + 7050
}
goto _4
_4:
;
j = j + 1
}
goto _3
_3:
;
pFKey = (*TFKey)(unsafe.Pointer(pFKey)).FpNextFrom
}
}
pIdx = (*TTable)(unsafe.Pointer(pTab)).FpIndex
for {
if !(pIdx != 0) {
break
}
j1 = 0
for {
if !(j1 < libc.Int32FromUint16((*TIndex)(unsafe.Pointer(pIdx)).FnKeyCol)) {
break
}
/* FIXME: Be smarter about indexes that use expressions */
if int32(**(**Ti16)(__ccgo_up((*TIndex)(unsafe.Pointer(pIdx)).FaiColumn + uintptr(j1)*2))) == iCol || int32(**(**Ti16)(__ccgo_up((*TIndex)(unsafe.Pointer(pIdx)).FaiColumn + uintptr(j1)*2))) == -int32(2) {
zFault = __ccgo_ts + 7062
}
goto _6
_6:
;
j1 = j1 + 1
}
goto _5
_5:
;
pIdx = (*TIndex)(unsafe.Pointer(pIdx)).FpNext
}
if zFault != 0 {
_sqlite3DbFree(tls, db, **(**uintptr)(__ccgo_up(bp)))
**(**uintptr)(__ccgo_up(bp)) = _sqlite3MPrintf(tls, db, __ccgo_ts+7070, libc.VaList(bp+440, zFault))
rc = int32(SQLITE_ERROR)
_sqlite3BtreeLeaveAll(tls, db)
goto blob_open_out
}
}
(*TIncrblob)(unsafe.Pointer(pBlob)).FpStmt = _sqlite3VdbeCreate(tls, bp+8)
if (*TIncrblob)(unsafe.Pointer(pBlob)).FpStmt != 0 {
v = (*TIncrblob)(unsafe.Pointer(pBlob)).FpStmt
_sqlite3VdbeAddOp4Int(tls, v, int32(OP_Transaction), iDb, wrFlag, (*TSchema)(unsafe.Pointer((*TTable)(unsafe.Pointer(pTab)).FpSchema)).Fschema_cookie, (*TSchema)(unsafe.Pointer((*TTable)(unsafe.Pointer(pTab)).FpSchema)).FiGeneration)
_sqlite3VdbeChangeP5(tls, v, uint16(1))
aOp = _sqlite3VdbeAddOpList(tls, v, libc.Int32FromUint64(libc.Uint64FromInt64(24)/libc.Uint64FromInt64(4)), uintptr(unsafe.Pointer(&_openBlob)), _iLn)
/* Make sure a mutex is held on the table to be accessed */
_sqlite3VdbeUsesBtree(tls, v, iDb)
if libc.Int32FromUint8((*Tsqlite3)(unsafe.Pointer(db)).FmallocFailed) == 0 {
/* Configure the OP_TableLock instruction */
(**(**TVdbeOp)(__ccgo_up(aOp))).Fp1 = iDb
(**(**TVdbeOp)(__ccgo_up(aOp))).Fp2 = libc.Int32FromUint32((*TTable)(unsafe.Pointer(pTab)).Ftnum)
(**(**TVdbeOp)(__ccgo_up(aOp))).Fp3 = wrFlag
_sqlite3VdbeChangeP4(tls, v, int32(2), (*TTable)(unsafe.Pointer(pTab)).FzName, P4_TRANSIENT)
}
if libc.Int32FromUint8((*Tsqlite3)(unsafe.Pointer(db)).FmallocFailed) == 0 {
/* Remove either the OP_OpenWrite or OpenRead. Set the P2
** parameter of the other to pTab->tnum. */
if wrFlag != 0 {
(**(**TVdbeOp)(__ccgo_up(aOp + 1*24))).Fopcode = uint8(OP_OpenWrite)
}
(**(**TVdbeOp)(__ccgo_up(aOp + 1*24))).Fp2 = libc.Int32FromUint32((*TTable)(unsafe.Pointer(pTab)).Ftnum)
(**(**TVdbeOp)(__ccgo_up(aOp + 1*24))).Fp3 = iDb
/* Configure the number of columns. Configure the cursor to
** think that the table has one more column than it really
** does. An OP_Column to retrieve this imaginary column will
** always return an SQL NULL. This is useful because it means
** we can invoke OP_Column to fill in the vdbe cursors type
** and offset cache without causing any IO.
*/
(**(**TVdbeOp)(__ccgo_up(aOp + 1*24))).Fp4type = int8(-libc.Int32FromInt32(3))
*(*int32)(unsafe.Pointer(aOp + 1*24 + 16)) = int32((*TTable)(unsafe.Pointer(pTab)).FnCol) + int32(1)
(**(**TVdbeOp)(__ccgo_up(aOp + 3*24))).Fp2 = int32((*TTable)(unsafe.Pointer(pTab)).FnCol)
(**(**TParse)(__ccgo_up(bp + 8))).FnVar = 0
(**(**TParse)(__ccgo_up(bp + 8))).FnMem = int32(1)
(**(**TParse)(__ccgo_up(bp + 8))).FnTab = int32(1)
_sqlite3VdbeMakeReady(tls, v, bp+8)
}
}
(*TIncrblob)(unsafe.Pointer(pBlob)).FiCol = libc.Uint16FromInt32(iCol)
(*TIncrblob)(unsafe.Pointer(pBlob)).Fdb = db
_sqlite3BtreeLeaveAll(tls, db)
if (*Tsqlite3)(unsafe.Pointer(db)).FmallocFailed != 0 {
goto blob_open_out
}
rc = _blobSeekToRow(tls, pBlob, iRow, bp)
nAttempt = nAttempt + 1
v1 = nAttempt
if v1 >= int32(SQLITE_MAX_SCHEMA_RETRY) || rc != int32(SQLITE_SCHEMA) {
break
}
_sqlite3ParseObjectReset(tls, bp+8)
}
goto blob_open_out
blob_open_out:
;
if rc == SQLITE_OK && libc.Int32FromUint8((*Tsqlite3)(unsafe.Pointer(db)).FmallocFailed) == 0 {
**(**uintptr)(__ccgo_up(ppBlob)) = pBlob
} else {
if pBlob != 0 && (*TIncrblob)(unsafe.Pointer(pBlob)).FpStmt != 0 {
_sqlite3VdbeFinalize(tls, (*TIncrblob)(unsafe.Pointer(pBlob)).FpStmt)
}
_sqlite3DbFree(tls, db, pBlob)
}
if **(**uintptr)(__ccgo_up(bp)) != 0 {
v8 = __ccgo_ts + 3944
} else {
v8 = libc.UintptrFromInt32(0)
}
_sqlite3ErrorWithMsg(tls, db, rc, v8, libc.VaList(bp+440, **(**uintptr)(__ccgo_up(bp))))
_sqlite3DbFree(tls, db, **(**uintptr)(__ccgo_up(bp)))
_sqlite3ParseObjectReset(tls, bp+8)
rc = _sqlite3ApiExit(tls, db, rc)
Xsqlite3_mutex_leave(tls, (*Tsqlite3)(unsafe.Pointer(db)).Fmutex)
return rc
}
// C documentation
//
// /*
// ** 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+26759, 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)*8)), n) == 0 && _sqlite3IsIdChar(tls, libc.Uint8FromInt8(**(**int8)(__ccgo_up(**(**uintptr)(__ccgo_up(azCompileOpt + uintptr(i)*8)) + uintptr(n))))) == 0 {
return int32(1)
}
goto _1
_1:
;
i = i + 1
}
return 0
}
// C documentation
//
// /*
// ** Return TRUE if the given SQL string ends in a semicolon.
// **
// ** Special handling is require for CREATE TRIGGER statements.
// ** Whenever the CREATE TRIGGER keywords are seen, the statement
// ** must end with ";END;".
// **
// ** This implementation uses a state machine with 8 states:
// **
// ** (0) INVALID We have not yet seen a non-whitespace character.
// **
// ** (1) START At the beginning or end of an SQL statement. This routine
// ** returns 1 if it ends in the START state and 0 if it ends
// ** in any other state.
// **
// ** (2) NORMAL We are in the middle of statement which ends with a single
// ** semicolon.
// **
// ** (3) EXPLAIN The keyword EXPLAIN has been seen at the beginning of
// ** a statement.
// **
// ** (4) CREATE The keyword CREATE has been seen at the beginning of a
// ** statement, possibly preceded by EXPLAIN and/or followed by
// ** TEMP or TEMPORARY
// **
// ** (5) TRIGGER We are in the middle of a trigger definition that must be
// ** ended by a semicolon, the keyword END, and another semicolon.
// **
// ** (6) SEMI We've seen the first semicolon in the ";END;" that occurs at
// ** the end of a trigger definition.
// **
// ** (7) END We've seen the ";END" of the ";END;" that occurs at the end
// ** of a trigger definition.
// **
// ** Transitions between states above are determined by tokens extracted
// ** from the input. The following tokens are significant:
// **
// ** (0) tkSEMI A semicolon.
// ** (1) tkWS Whitespace.
// ** (2) tkOTHER Any other SQL token.
// ** (3) tkEXPLAIN The "explain" keyword.
// ** (4) tkCREATE The "create" keyword.
// ** (5) tkTEMP The "temp" or "temporary" keyword.
// ** (6) tkTRIGGER The "trigger" keyword.
// ** (7) tkEND The "end" keyword.
// **
// ** Whitespace never causes a state transition and is always ignored.
// ** This means that a SQL string of all whitespace is invalid.
// **
// ** If we compile with SQLITE_OMIT_TRIGGER, all of the computation needed
// ** to recognize the end of a trigger can be omitted. All we have to do
// ** is look for a semicolon that is not part of an string or comment.
// */
func Xsqlite3_complete(tls *libc.TLS, zSql uintptr) (r int32) {
var c, nId int32
var state, token Tu8
_, _, _, _ = c, nId, state, token
state = uint8(0) /* Value of the next token */
for **(**int8)(__ccgo_up(zSql)) != 0 {
switch int32(**(**int8)(__ccgo_up(zSql))) {
case int32(';'): /* A semicolon */
token = uint8(tkSEMI)
case int32(' '):
fallthrough
case int32('\r'):
fallthrough
case int32('\t'):
fallthrough
case int32('\n'):
fallthrough
case int32('\f'): /* White space is ignored */
token = uint8(tkWS)
case int32('/'): /* C-style comments */
if int32(**(**int8)(__ccgo_up(zSql + 1))) != int32('*') {
token = uint8(tkOTHER)
break
}
zSql = zSql + uintptr(2)
for **(**int8)(__ccgo_up(zSql)) != 0 && (int32(**(**int8)(__ccgo_up(zSql))) != int32('*') || int32(**(**int8)(__ccgo_up(zSql + 1))) != int32('/')) {
zSql = zSql + 1
}
if int32(**(**int8)(__ccgo_up(zSql))) == 0 {
return 0
}
zSql = zSql + 1
token = uint8(tkWS)
case int32('-'): /* SQL-style comments from "--" to end of line */
if int32(**(**int8)(__ccgo_up(zSql + 1))) != int32('-') {
token = uint8(tkOTHER)
break
}
for **(**int8)(__ccgo_up(zSql)) != 0 && int32(**(**int8)(__ccgo_up(zSql))) != int32('\n') {
zSql = zSql + 1
}
if int32(**(**int8)(__ccgo_up(zSql))) == 0 {
return libc.BoolInt32(libc.Int32FromUint8(state) == int32(1))
}
token = uint8(tkWS)
case int32('['): /* Microsoft-style identifiers in [...] */
zSql = zSql + 1
for **(**int8)(__ccgo_up(zSql)) != 0 && int32(**(**int8)(__ccgo_up(zSql))) != int32(']') {
zSql = zSql + 1
}
if int32(**(**int8)(__ccgo_up(zSql))) == 0 {
return 0
}
token = uint8(tkOTHER)
case int32('`'): /* Grave-accent quoted symbols used by MySQL */
fallthrough
case int32('"'): /* single- and double-quoted strings */
fallthrough
case int32('\''):
c = int32(**(**int8)(__ccgo_up(zSql)))
zSql = zSql + 1
for **(**int8)(__ccgo_up(zSql)) != 0 && int32(**(**int8)(__ccgo_up(zSql))) != c {
zSql = zSql + 1
}
if int32(**(**int8)(__ccgo_up(zSql))) == 0 {
return 0
}
token = uint8(tkOTHER)
default:
if libc.Int32FromUint8(_sqlite3CtypeMap[libc.Uint8FromInt8(**(**int8)(__ccgo_up(zSql)))])&int32(0x46) != 0 {
nId = int32(1)
for {
if !(libc.Int32FromUint8(_sqlite3CtypeMap[libc.Uint8FromInt8(**(**int8)(__ccgo_up(zSql + uintptr(nId))))])&int32(0x46) != 0) {
break
}
goto _1
_1:
;
nId = nId + 1
}
switch int32(**(**int8)(__ccgo_up(zSql))) {
case int32('c'):
fallthrough
case int32('C'):
if nId == int32(6) && Xsqlite3_strnicmp(tls, zSql, __ccgo_ts+25648, int32(6)) == 0 {
token = uint8(tkCREATE)
} else {
token = uint8(tkOTHER)
}
case int32('t'):
fallthrough
case int32('T'):
if nId == int32(7) && Xsqlite3_strnicmp(tls, zSql, __ccgo_ts+22277, int32(7)) == 0 {
token = uint8(tkTRIGGER)
} else {
if nId == int32(4) && Xsqlite3_strnicmp(tls, zSql, __ccgo_ts+25655, int32(4)) == 0 {
token = uint8(tkTEMP)
} else {
if nId == int32(9) && Xsqlite3_strnicmp(tls, zSql, __ccgo_ts+25660, int32(9)) == 0 {
token = uint8(tkTEMP)
} else {
token = uint8(tkOTHER)
}
}
}
case int32('e'):
fallthrough
case int32('E'):
if nId == int32(3) && Xsqlite3_strnicmp(tls, zSql, __ccgo_ts+25670, int32(3)) == 0 {
token = uint8(tkEND)
} else {
if nId == int32(7) && Xsqlite3_strnicmp(tls, zSql, __ccgo_ts+25674, int32(7)) == 0 {
token = uint8(tkEXPLAIN)
} else {
token = uint8(tkOTHER)
}
}
default:
token = uint8(tkOTHER)
break
}
zSql = zSql + uintptr(nId-int32(1))
} else {
/* Operators and special symbols */
token = uint8(tkOTHER)
}
break
}
state = **(**Tu8)(__ccgo_up(uintptr(unsafe.Pointer(&_trans)) + uintptr(state)*8 + uintptr(token)))
zSql = zSql + 1
}
return libc.BoolInt32(libc.Int32FromUint8(state) == int32(1))
}
// C documentation
//
// /*
// ** Allocate memory to hold names for a database, journal file, WAL file,
// ** and query parameters. The pointer returned is valid for use by
// ** sqlite3_filename_database() and sqlite3_uri_parameter() and related
// ** functions.
// **
// ** Memory layout must be compatible with that generated by the pager
// ** and expected by sqlite3_uri_parameter() and databaseName().
// */
func Xsqlite3_create_filename(tls *libc.TLS, zDatabase uintptr, zJournal uintptr, zWal uintptr, nParam int32, azParam uintptr) (r uintptr) {
var i int32
var nByte Tsqlite3_int64
var p, pResult, v2 uintptr
_, _, _, _, _ = i, nByte, p, pResult, v2
nByte = libc.Int64FromUint64(libc.Xstrlen(tls, zDatabase) + libc.Xstrlen(tls, zJournal) + libc.Xstrlen(tls, zWal) + uint64(10))
i = 0
for {
if !(i < nParam*int32(2)) {
break
}
nByte = libc.Int64FromUint64(uint64(nByte) + uint64(libc.Xstrlen(tls, **(**uintptr)(__ccgo_up(azParam + uintptr(i)*8)))+libc.Uint64FromInt32(1)))
goto _1
_1:
;
i = i + 1
}
v2 = Xsqlite3_malloc64(tls, libc.Uint64FromInt64(nByte))
p = v2
pResult = v2
if p == uintptr(0) {
return uintptr(0)
}
libc.X__builtin___memset_chk(tls, p, 0, uint64(4), ^t__predefined_size_t(0))
p = p + uintptr(4)
p = _appendText(tls, p, zDatabase)
i = 0
for {
if !(i < nParam*int32(2)) {
break
}
p = _appendText(tls, p, **(**uintptr)(__ccgo_up(azParam + uintptr(i)*8)))
goto _3
_3:
;
i = i + 1
}
v2 = p
p = p + 1
**(**int8)(__ccgo_up(v2)) = 0
p = _appendText(tls, p, zJournal)
p = _appendText(tls, p, zWal)
v2 = p
p = p + 1
**(**int8)(__ccgo_up(v2)) = 0
v2 = p
p = p + 1
**(**int8)(__ccgo_up(v2)) = 0
return pResult + uintptr(4)
}
// C documentation
//
// /*
// ** This function is used to set the schema of a virtual table. It is only
// ** valid to call this function from within the xCreate() or xConnect() of a
// ** virtual table module.
// */
func Xsqlite3_declare_vtab(tls *libc.TLS, db uintptr, zCreateTable uintptr) (r int32) {
bp := tls.Alloc(448)
defer tls.Free(448)
var i, initBusy, rc int32
var pCtx, pIdx, pNew, pTab, z, v3 uintptr
var v2 Ti16
var _ /* sParse at bp+0 */ TParse
var _ /* tokenType at bp+424 */ int32
_, _, _, _, _, _, _, _, _, _ = i, initBusy, pCtx, pIdx, pNew, pTab, rc, z, v2, v3
rc = SQLITE_OK
/* Verify that the first two keywords in the CREATE TABLE statement
** really are "CREATE" and "TABLE". If this is not the case, then
** sqlite3_declare_vtab() is being misused.
*/
z = zCreateTable
i = 0
for {
if !(_aKeyword1[i] != 0) {
break
}
**(**int32)(__ccgo_up(bp + 424)) = 0
for cond := true; cond; cond = **(**int32)(__ccgo_up(bp + 424)) == int32(TK_SPACE) || **(**int32)(__ccgo_up(bp + 424)) == int32(TK_COMMENT) {
z = z + uintptr(_sqlite3GetToken(tls, z, bp+424))
}
if **(**int32)(__ccgo_up(bp + 424)) != libc.Int32FromUint8(_aKeyword1[i]) {
_sqlite3ErrorWithMsg(tls, db, int32(SQLITE_ERROR), __ccgo_ts+24000, 0)
return int32(SQLITE_ERROR)
}
goto _1
_1:
;
i = i + 1
}
Xsqlite3_mutex_enter(tls, (*Tsqlite3)(unsafe.Pointer(db)).Fmutex)
pCtx = (*Tsqlite3)(unsafe.Pointer(db)).FpVtabCtx
if !(pCtx != 0) || (*TVtabCtx)(unsafe.Pointer(pCtx)).FbDeclared != 0 {
_sqlite3Error(tls, db, _sqlite3MisuseError(tls, int32(162730)))
Xsqlite3_mutex_leave(tls, (*Tsqlite3)(unsafe.Pointer(db)).Fmutex)
return _sqlite3MisuseError(tls, int32(162732))
}
pTab = (*TVtabCtx)(unsafe.Pointer(pCtx)).FpTab
_sqlite3ParseObjectInit(tls, bp, db)
(**(**TParse)(__ccgo_up(bp))).FeParseMode = uint8(PARSE_MODE_DECLARE_VTAB)
libc.SetBitFieldPtr16Uint32(bp+40, libc.Uint32FromInt32(1), 0, 0x1)
/* We should never be able to reach this point while loading the
** schema. Nevertheless, defend against that (turn off db->init.busy)
** in case a bug arises. */
initBusy = libc.Int32FromUint8((*Tsqlite3)(unsafe.Pointer(db)).Finit1.Fbusy)
(*Tsqlite3)(unsafe.Pointer(db)).Finit1.Fbusy = uint8(0)
(**(**TParse)(__ccgo_up(bp))).FnQueryLoop = int16(1)
if SQLITE_OK == _sqlite3RunParser(tls, bp, zCreateTable) {
if !((*TTable)(unsafe.Pointer(pTab)).FaCol != 0) {
pNew = (**(**TParse)(__ccgo_up(bp))).FpNewTable
(*TTable)(unsafe.Pointer(pTab)).FaCol = (*TTable)(unsafe.Pointer(pNew)).FaCol
_sqlite3ExprListDelete(tls, db, (*(*struct {
FaddColOffset int32
FpFKey uintptr
FpDfltList uintptr
})(unsafe.Pointer(pNew + 64))).FpDfltList)
v2 = (*TTable)(unsafe.Pointer(pNew)).FnCol
(*TTable)(unsafe.Pointer(pTab)).FnCol = v2
(*TTable)(unsafe.Pointer(pTab)).FnNVCol = v2
**(**Tu32)(__ccgo_up(pTab + 48)) |= (*TTable)(unsafe.Pointer(pNew)).FtabFlags & libc.Uint32FromInt32(libc.Int32FromInt32(TF_WithoutRowid)|libc.Int32FromInt32(TF_NoVisibleRowid))
(*TTable)(unsafe.Pointer(pNew)).FnCol = 0
(*TTable)(unsafe.Pointer(pNew)).FaCol = uintptr(0)
if !((*TTable)(unsafe.Pointer(pNew)).FtabFlags&libc.Uint32FromInt32(TF_WithoutRowid) == libc.Uint32FromInt32(0)) && (*Tsqlite3_module)(unsafe.Pointer((*TModule)(unsafe.Pointer((*TVTable)(unsafe.Pointer((*TVtabCtx)(unsafe.Pointer(pCtx)).FpVTable)).FpMod)).FpModule)).FxUpdate != uintptr(0) && libc.Int32FromUint16((*TIndex)(unsafe.Pointer(_sqlite3PrimaryKeyIndex(tls, pNew))).FnKeyCol) != int32(1) {
/* WITHOUT ROWID virtual tables must either be read-only (xUpdate==0)
** or else must have a single-column PRIMARY KEY */
rc = int32(SQLITE_ERROR)
}
pIdx = (*TTable)(unsafe.Pointer(pNew)).FpIndex
if pIdx != 0 {
(*TTable)(unsafe.Pointer(pTab)).FpIndex = pIdx
(*TTable)(unsafe.Pointer(pNew)).FpIndex = uintptr(0)
(*TIndex)(unsafe.Pointer(pIdx)).FpTable = pTab
}
}
(*TVtabCtx)(unsafe.Pointer(pCtx)).FbDeclared = int32(1)
} else {
if (**(**TParse)(__ccgo_up(bp))).FzErrMsg != 0 {
v3 = __ccgo_ts + 3944
} else {
v3 = uintptr(0)
}
_sqlite3ErrorWithMsg(tls, db, int32(SQLITE_ERROR), v3, libc.VaList(bp+440, (**(**TParse)(__ccgo_up(bp))).FzErrMsg))
_sqlite3DbFree(tls, db, (**(**TParse)(__ccgo_up(bp))).FzErrMsg)
rc = int32(SQLITE_ERROR)
}
(**(**TParse)(__ccgo_up(bp))).FeParseMode = uint8(PARSE_MODE_NORMAL)
if (**(**TParse)(__ccgo_up(bp))).FpVdbe != 0 {
_sqlite3VdbeFinalize(tls, (**(**TParse)(__ccgo_up(bp))).FpVdbe)
}
_sqlite3DeleteTable(tls, db, (**(**TParse)(__ccgo_up(bp))).FpNewTable)
_sqlite3ParseObjectReset(tls, bp)
(*Tsqlite3)(unsafe.Pointer(db)).Finit1.Fbusy = libc.Uint8FromInt32(initBusy)
rc = _sqlite3ApiExit(tls, db, rc)
Xsqlite3_mutex_leave(tls, (*Tsqlite3)(unsafe.Pointer(db)).Fmutex)
return rc
}
// C documentation
//
// /* Convert zSchema to a MemDB and initialize its content.
// */
func Xsqlite3_deserialize(tls *libc.TLS, db uintptr, zSchema uintptr, pData uintptr, szDb Tsqlite3_int64, szBuf Tsqlite3_int64, mFlags uint32) (r int32) {
bp := tls.Alloc(32)
defer tls.Free(32)
var iDb, rc int32
var p, pStore, zSql uintptr
var _ /* pStmt at bp+0 */ uintptr
_, _, _, _, _ = iDb, p, pStore, rc, zSql
**(**uintptr)(__ccgo_up(bp)) = uintptr(0)
Xsqlite3_mutex_enter(tls, (*Tsqlite3)(unsafe.Pointer(db)).Fmutex)
if zSchema == uintptr(0) {
zSchema = (**(**TDb)(__ccgo_up((*Tsqlite3)(unsafe.Pointer(db)).FaDb))).FzDbSName
}
iDb = _sqlite3FindDbName(tls, db, zSchema)
if iDb < int32(2) && iDb != 0 {
rc = int32(SQLITE_ERROR)
goto end_deserialize
}
zSql = Xsqlite3_mprintf(tls, __ccgo_ts+4529, libc.VaList(bp+16, zSchema))
if zSql == uintptr(0) {
rc = int32(SQLITE_NOMEM)
} else {
rc = Xsqlite3_prepare_v2(tls, db, zSql, -int32(1), bp, uintptr(0))
Xsqlite3_free(tls, zSql)
}
if rc != 0 {
goto end_deserialize
}
(*Tsqlite3)(unsafe.Pointer(db)).Finit1.FiDb = libc.Uint8FromInt32(iDb)
libc.SetBitFieldPtr8Uint32(db+192+8, libc.Uint32FromInt32(1), 3, 0x8)
Xsqlite3_step(tls, **(**uintptr)(__ccgo_up(bp)))
libc.SetBitFieldPtr8Uint32(db+192+8, libc.Uint32FromInt32(0), 3, 0x8)
rc = Xsqlite3_finalize(tls, **(**uintptr)(__ccgo_up(bp)))
if rc != SQLITE_OK {
goto end_deserialize
}
p = _memdbFromDbSchema(tls, db, zSchema)
if p == uintptr(0) {
rc = int32(SQLITE_ERROR)
} else {
pStore = (*TMemFile)(unsafe.Pointer(p)).FpStore
(*TMemStore)(unsafe.Pointer(pStore)).FaData = pData
pData = uintptr(0)
(*TMemStore)(unsafe.Pointer(pStore)).Fsz = szDb
(*TMemStore)(unsafe.Pointer(pStore)).FszAlloc = szBuf
(*TMemStore)(unsafe.Pointer(pStore)).FszMax = szBuf
if (*TMemStore)(unsafe.Pointer(pStore)).FszMax < _sqlite3Config.FmxMemdbSize {
(*TMemStore)(unsafe.Pointer(pStore)).FszMax = _sqlite3Config.FmxMemdbSize
}
(*TMemStore)(unsafe.Pointer(pStore)).FmFlags = mFlags
rc = SQLITE_OK
}
goto end_deserialize
end_deserialize:
;
if pData != 0 && mFlags&uint32(SQLITE_DESERIALIZE_FREEONCLOSE) != uint32(0) {
Xsqlite3_free(tls, pData)
}
Xsqlite3_mutex_leave(tls, (*Tsqlite3)(unsafe.Pointer(db)).Fmutex)
return rc
}
// C documentation
//
// /*
// ** Initialize SQLite.
// **
// ** This routine must be called to initialize the memory allocation,
// ** VFS, and mutex subsystems prior to doing any serious work with
// ** SQLite. But as long as you do not compile with SQLITE_OMIT_AUTOINIT
// ** this routine will be called automatically by key routines such as
// ** sqlite3_open().
// **
// ** This routine is a no-op except on its very first call for the process,
// ** or for the first call after a call to sqlite3_shutdown.
// **
// ** The first thread to call this routine runs the initialization to
// ** completion. If subsequent threads call this routine before the first
// ** thread has finished the initialization process, then the subsequent
// ** threads must block until the first thread finishes with the initialization.
// **
// ** The first thread might call this routine recursively. Recursive
// ** calls to this routine should not block, of course. Otherwise the
// ** initialization process would never complete.
// **
// ** Let X be the first thread to enter this routine. Let Y be some other
// ** thread. Then while the initial invocation of this routine by X is
// ** incomplete, it is required that:
// **
// ** * Calls to this routine from Y must block until the outer-most
// ** call by X completes.
// **
// ** * Recursive calls to this routine from thread X return immediately
// ** without blocking.
// */
func Xsqlite3_initialize(tls *libc.TLS) (r int32) {
var pMainMtx uintptr
var rc int32
_, _ = pMainMtx, rc /* Result code */
/* If the following assert() fails on some obscure processor/compiler
** combination, the work-around is to set the correct pointer
** size at compile-time using -DSQLITE_PTRSIZE=n compile-time option */
/* If SQLite is already completely initialized, then this call
** to sqlite3_initialize() should be a no-op. But the initialization
** must be complete. So isInit must not be set until the very end
** of this routine.
*/
if libc.AtomicLoadPInt32(uintptr(unsafe.Pointer(&_sqlite3Config))+340) != 0 {
return SQLITE_OK
}
/* Make sure the mutex subsystem is initialized. If unable to
** initialize the mutex subsystem, return early with the error.
** If the system is so sick that we are unable to allocate a mutex,
** there is not much SQLite is going to be able to do.
**
** The mutex subsystem must take care of serializing its own
** initialization.
*/
rc = _sqlite3MutexInit(tls)
if rc != 0 {
return rc
}
/* Initialize the malloc() system and the recursive pInitMutex mutex.
** This operation is protected by the STATIC_MAIN mutex. Note that
** MutexAlloc() is called for a static mutex prior to initializing the
** malloc subsystem - this implies that the allocation of a static
** mutex must not require support from the malloc subsystem.
*/
pMainMtx = _sqlite3MutexAlloc(tls, int32(SQLITE_MUTEX_STATIC_MAIN))
Xsqlite3_mutex_enter(tls, pMainMtx)
_sqlite3Config.FisMutexInit = int32(1)
if !(_sqlite3Config.FisMallocInit != 0) {
rc = _sqlite3MallocInit(tls)
}
if rc == SQLITE_OK {
_sqlite3Config.FisMallocInit = int32(1)
if !(_sqlite3Config.FpInitMutex != 0) {
_sqlite3Config.FpInitMutex = _sqlite3MutexAlloc(tls, int32(SQLITE_MUTEX_RECURSIVE))
if _sqlite3Config.FbCoreMutex != 0 && !(_sqlite3Config.FpInitMutex != 0) {
rc = int32(SQLITE_NOMEM)
}
}
}
if rc == SQLITE_OK {
_sqlite3Config.FnRefInitMutex = _sqlite3Config.FnRefInitMutex + 1
}
Xsqlite3_mutex_leave(tls, pMainMtx)
/* If rc is not SQLITE_OK at this point, then either the malloc
** subsystem could not be initialized or the system failed to allocate
** the pInitMutex mutex. Return an error in either case. */
if rc != SQLITE_OK {
return rc
}
/* Do the rest of the initialization under the recursive mutex so
** that we will be able to handle recursive calls into
** sqlite3_initialize(). The recursive calls normally come through
** sqlite3_os_init() when it invokes sqlite3_vfs_register(), but other
** recursive calls might also be possible.
**
** IMPLEMENTATION-OF: R-00140-37445 SQLite automatically serializes calls
** to the xInit method, so the xInit method need not be threadsafe.
**
** The following mutex is what serializes access to the appdef pcache xInit
** methods. The sqlite3_pcache_methods.xInit() all is embedded in the
** call to sqlite3PcacheInitialize().
*/
Xsqlite3_mutex_enter(tls, _sqlite3Config.FpInitMutex)
if libc.AtomicLoadPInt32(uintptr(unsafe.Pointer(&_sqlite3Config))+340) == 0 && _sqlite3Config.FinProgress == 0 {
_sqlite3Config.FinProgress = int32(1)
libc.X__builtin___memset_chk(tls, uintptr(unsafe.Pointer(&_sqlite3BuiltinFunctions)), 0, uint64(184), ^t__predefined_size_t(0))
_sqlite3RegisterBuiltinFunctions(tls)
if _sqlite3Config.FisPCacheInit == 0 {
rc = _sqlite3PcacheInitialize(tls)
}
if rc == SQLITE_OK {
_sqlite3Config.FisPCacheInit = int32(1)
rc = _sqlite3OsInit(tls)
}
if rc == SQLITE_OK {
rc = _sqlite3MemdbInit(tls)
}
if rc == SQLITE_OK {
_sqlite3PCacheBufferSetup(tls, _sqlite3Config.FpPage, _sqlite3Config.FszPage, _sqlite3Config.FnPage)
}
if rc == SQLITE_OK {
libc.AtomicStorePInt32(uintptr(unsafe.Pointer(&_sqlite3Config))+340, int32(1))
}
_sqlite3Config.FinProgress = 0
}
Xsqlite3_mutex_leave(tls, _sqlite3Config.FpInitMutex)
/* Go back under the static mutex and clean up the recursive
** mutex to prevent a resource leak.
*/
Xsqlite3_mutex_enter(tls, pMainMtx)
_sqlite3Config.FnRefInitMutex = _sqlite3Config.FnRefInitMutex - 1
if _sqlite3Config.FnRefInitMutex <= 0 {
Xsqlite3_mutex_free(tls, _sqlite3Config.FpInitMutex)
_sqlite3Config.FpInitMutex = uintptr(0)
}
Xsqlite3_mutex_leave(tls, pMainMtx)
/* The following is just a sanity check to make sure SQLite has
** been compiled correctly. It is important to run this code, but
** we don't want to run it too often and soak up CPU cycles for no
** reason. So we run it once during initialization.
*/
/* Do extra initialization steps requested by the SQLITE_EXTRA_INIT
** compile-time option.
*/
return rc
}
// C documentation
//
// /*
// ** Open a new database handle.
// */
func Xsqlite3_open16(tls *libc.TLS, zFilename uintptr, ppDb uintptr) (r int32) {
var pVal, zFilename8 uintptr
var rc int32
var v1 Tu8
_, _, _, _ = pVal, rc, zFilename8, v1
**(**uintptr)(__ccgo_up(ppDb)) = uintptr(0)
rc = Xsqlite3_initialize(tls)
if rc != 0 {
return rc
}
if zFilename == uintptr(0) {
zFilename = __ccgo_ts + 26659
}
pVal = _sqlite3ValueNew(tls, uintptr(0))
_sqlite3ValueSetStr(tls, pVal, -int32(1), zFilename, uint8(SQLITE_UTF16LE), libc.UintptrFromInt32(0))
zFilename8 = _sqlite3ValueText(tls, pVal, uint8(SQLITE_UTF8))
if zFilename8 != 0 {
rc = _openDatabase(tls, zFilename8, ppDb, libc.Uint32FromInt32(libc.Int32FromInt32(SQLITE_OPEN_READWRITE)|libc.Int32FromInt32(SQLITE_OPEN_CREATE)), uintptr(0))
if rc == SQLITE_OK && !(libc.Int32FromUint16((*TSchema)(unsafe.Pointer((**(**TDb)(__ccgo_up((*Tsqlite3)(unsafe.Pointer(**(**uintptr)(__ccgo_up(ppDb)))).FaDb))).FpSchema)).FschemaFlags)&libc.Int32FromInt32(DB_SchemaLoaded) == libc.Int32FromInt32(DB_SchemaLoaded)) {
v1 = libc.Uint8FromInt32(SQLITE_UTF16LE)
(*Tsqlite3)(unsafe.Pointer(**(**uintptr)(__ccgo_up(ppDb)))).Fenc = v1
(*TSchema)(unsafe.Pointer((**(**TDb)(__ccgo_up((*Tsqlite3)(unsafe.Pointer(**(**uintptr)(__ccgo_up(ppDb)))).FaDb))).FpSchema)).Fenc = v1
}
} else {
rc = int32(SQLITE_NOMEM)
}
_sqlite3ValueFree(tls, pVal)
return rc & int32(0xff)
}
// C documentation
//
// /*
// ** Initialize the operating system interface.
// **
// ** This routine registers all VFS implementations for unix-like operating
// ** systems. This routine, and the sqlite3_os_end() routine that follows,
// ** should be the only routines in this file that are visible from other
// ** files.
// **
// ** This routine is called once during SQLite initialization and by a
// ** single thread. The memory allocation and mutex subsystems have not
// ** necessarily been initialized when this routine is called, and so they
// ** should not be used.
// */
func Xsqlite3_os_init(tls *libc.TLS) (r int32) {
var i uint32
_ = i
/* Double-check that the aSyscall[] array has been constructed
** correctly. See ticket [bb3a86e890c8e96ab] */
/* Register all VFSes defined in the aVfs[] array */
i = uint32(0)
for {
if !(uint64(i) < libc.Uint64FromInt64(1512)/libc.Uint64FromInt64(168)) {
break
}
Xsqlite3_vfs_register(tls, uintptr(unsafe.Pointer(&_aVfs))+uintptr(i)*168, libc.BoolInt32(i == uint32(0)))
goto _1
_1:
;
i = i + 1
}
_unixBigLock = _sqlite3MutexAlloc(tls, int32(SQLITE_MUTEX_STATIC_VFS1))
/* Validate lock assumptions */
/* Number of available locks */
/* Start of locking area */
/* Locks:
** WRITE UNIX_SHM_BASE 120
** CKPT UNIX_SHM_BASE+1 121
** RECOVER UNIX_SHM_BASE+2 122
** READ-0 UNIX_SHM_BASE+3 123
** READ-1 UNIX_SHM_BASE+4 124
** READ-2 UNIX_SHM_BASE+5 125
** READ-3 UNIX_SHM_BASE+6 126
** READ-4 UNIX_SHM_BASE+7 127
** DMS UNIX_SHM_BASE+8 128
*/
/* Byte offset of the deadman-switch */
/* Initialize temp file dir array. */
_unixTempFileInit(tls)
return SQLITE_OK
}
/*
** The following macro defines an initializer for an sqlite3_vfs object.
** The name of the VFS is NAME. The pAppData is a pointer to a pointer
** to the "finder" function. (pAppData is a pointer to a pointer because
** silly C90 rules prohibit a void* from being cast to a function pointer
** and so we have to go through the intermediate pointer to avoid problems
** when compiling with -pedantic-errors on GCC.)
**
** The FINDER parameter to this macro is the name of the pointer to the
** finder-function. The finder-function returns a pointer to the
** sqlite_io_methods object that implements the desired locking
** behaviors. See the division above that contains the IOMETHODS
** macro for addition information on finder-functions.
**
** Most finders simply return a pointer to a fixed sqlite3_io_methods
** object. But the "autolockIoFinder" available on MacOSX does a little
** more than that; it looks at the filesystem type that hosts the
** database file and tries to choose an locking method appropriate for
** that filesystem time.
*/
// C documentation
//
// /*
// ** Return N random bytes.
// */
func Xsqlite3_randomness(tls *libc.TLS, N int32, pBuf uintptr) {
var mutex, pVfs, zBuf, v1 uintptr
_, _, _, _ = mutex, pVfs, zBuf, v1
zBuf = pBuf
if Xsqlite3_initialize(tls) != 0 {
return
}
mutex = _sqlite3MutexAlloc(tls, int32(SQLITE_MUTEX_STATIC_PRNG))
Xsqlite3_mutex_enter(tls, mutex)
if N <= 0 || pBuf == uintptr(0) {
**(**Tu32)(__ccgo_up(uintptr(unsafe.Pointer(&_sqlite3Prng)))) = uint32(0)
Xsqlite3_mutex_leave(tls, mutex)
return
}
/* Initialize the state of the random number generator once,
** the first time this routine is called.
*/
if **(**Tu32)(__ccgo_up(uintptr(unsafe.Pointer(&_sqlite3Prng)))) == uint32(0) {
pVfs = Xsqlite3_vfs_find(tls, uintptr(0))
libc.X__builtin___memcpy_chk(tls, uintptr(unsafe.Pointer(&_sqlite3Prng)), uintptr(unsafe.Pointer(&_chacha20_init)), uint64(16), ^t__predefined_size_t(0))
if pVfs == uintptr(0) {
libc.X__builtin___memset_chk(tls, uintptr(unsafe.Pointer(&_sqlite3Prng))+4*4, 0, uint64(44), ^t__predefined_size_t(0))
} else {
_sqlite3OsRandomness(tls, pVfs, int32(44), uintptr(unsafe.Pointer(&_sqlite3Prng))+4*4)
}
**(**Tu32)(__ccgo_up(uintptr(unsafe.Pointer(&_sqlite3Prng)) + 15*4)) = **(**Tu32)(__ccgo_up(uintptr(unsafe.Pointer(&_sqlite3Prng)) + 12*4))
**(**Tu32)(__ccgo_up(uintptr(unsafe.Pointer(&_sqlite3Prng)) + 12*4)) = uint32(0)
_sqlite3Prng.Fn = uint8(0)
}
for int32(1) != 0 {
if N <= libc.Int32FromUint8(_sqlite3Prng.Fn) {
libc.X__builtin___memcpy_chk(tls, zBuf, uintptr(unsafe.Pointer(&_sqlite3Prng))+64+uintptr(libc.Int32FromUint8(_sqlite3Prng.Fn)-N), libc.Uint64FromInt32(N), ^t__predefined_size_t(0))
v1 = uintptr(unsafe.Pointer(&_sqlite3Prng)) + 128
*(*Tu8)(unsafe.Pointer(v1)) = Tu8(int32(*(*Tu8)(unsafe.Pointer(v1))) - N)
break
}
if libc.Int32FromUint8(_sqlite3Prng.Fn) > 0 {
libc.X__builtin___memcpy_chk(tls, zBuf, uintptr(unsafe.Pointer(&_sqlite3Prng))+64, uint64(_sqlite3Prng.Fn), ^t__predefined_size_t(0))
N = N - libc.Int32FromUint8(_sqlite3Prng.Fn)
zBuf = zBuf + uintptr(_sqlite3Prng.Fn)
}
**(**Tu32)(__ccgo_up(uintptr(unsafe.Pointer(&_sqlite3Prng)) + 12*4)) = **(**Tu32)(__ccgo_up(uintptr(unsafe.Pointer(&_sqlite3Prng)) + 12*4)) + 1
_chacha_block(tls, uintptr(unsafe.Pointer(&_sqlite3Prng))+64, uintptr(unsafe.Pointer(&_sqlite3Prng)))
_sqlite3Prng.Fn = uint8(64)
}
Xsqlite3_mutex_leave(tls, mutex)
}
// C documentation
//
// /* Force an SQLITE_TOOBIG error. */
func Xsqlite3_result_error_toobig(tls *libc.TLS, pCtx uintptr) {
(*Tsqlite3_context)(unsafe.Pointer(pCtx)).FisError = int32(SQLITE_TOOBIG)
_sqlite3VdbeMemSetStr(tls, (*Tsqlite3_context)(unsafe.Pointer(pCtx)).FpOut, __ccgo_ts+5938, int64(-int32(1)), uint8(SQLITE_UTF8), libc.UintptrFromInt32(0))
}
// C documentation
//
// /*
// ** Return the serialization of a database
// */
func Xsqlite3_serialize(tls *libc.TLS, db uintptr, zSchema uintptr, piSize uintptr, mFlags uint32) (r uintptr) {
bp := tls.Alloc(32)
defer tls.Free(32)
var iDb, nPage, pgno, rc, szPage, v1 int32
var p, pBt, pOut, pPager, pStore, pTo, zSql uintptr
var sz Tsqlite3_int64
var _ /* pPage at bp+8 */ uintptr
var _ /* pStmt at bp+0 */ uintptr
_, _, _, _, _, _, _, _, _, _, _, _, _, _ = iDb, nPage, p, pBt, pOut, pPager, pStore, pTo, pgno, rc, sz, szPage, zSql, v1
szPage = 0
**(**uintptr)(__ccgo_up(bp)) = uintptr(0)
pOut = uintptr(0)
Xsqlite3_mutex_enter(tls, (*Tsqlite3)(unsafe.Pointer(db)).Fmutex)
if zSchema == uintptr(0) {
zSchema = (**(**TDb)(__ccgo_up((*Tsqlite3)(unsafe.Pointer(db)).FaDb))).FzDbSName
}
p = _memdbFromDbSchema(tls, db, zSchema)
iDb = _sqlite3FindDbName(tls, db, zSchema)
if piSize != 0 {
**(**Tsqlite3_int64)(__ccgo_up(piSize)) = int64(-int32(1))
}
if iDb < 0 {
goto serialize_out
}
if p != 0 {
pStore = (*TMemFile)(unsafe.Pointer(p)).FpStore
if piSize != 0 {
**(**Tsqlite3_int64)(__ccgo_up(piSize)) = (*TMemStore)(unsafe.Pointer(pStore)).Fsz
}
if mFlags&uint32(SQLITE_SERIALIZE_NOCOPY) != 0 {
pOut = (*TMemStore)(unsafe.Pointer(pStore)).FaData
} else {
pOut = Xsqlite3_malloc64(tls, libc.Uint64FromInt64((*TMemStore)(unsafe.Pointer(pStore)).Fsz))
if pOut != 0 {
libc.X__builtin___memcpy_chk(tls, pOut, (*TMemStore)(unsafe.Pointer(pStore)).FaData, libc.Uint64FromInt64((*TMemStore)(unsafe.Pointer(pStore)).Fsz), ^t__predefined_size_t(0))
}
}
goto serialize_out
}
pBt = (**(**TDb)(__ccgo_up((*Tsqlite3)(unsafe.Pointer(db)).FaDb + uintptr(iDb)*32))).FpBt
if pBt == uintptr(0) {
goto serialize_out
}
szPage = _sqlite3BtreeGetPageSize(tls, pBt)
zSql = Xsqlite3_mprintf(tls, __ccgo_ts+4481, libc.VaList(bp+24, zSchema))
if zSql != 0 {
v1 = Xsqlite3_prepare_v2(tls, db, zSql, -int32(1), bp, uintptr(0))
} else {
v1 = int32(SQLITE_NOMEM)
}
rc = v1
Xsqlite3_free(tls, zSql)
if rc != 0 {
goto serialize_out
}
rc = Xsqlite3_step(tls, **(**uintptr)(__ccgo_up(bp)))
if rc == int32(SQLITE_ROW) {
sz = Xsqlite3_column_int64(tls, **(**uintptr)(__ccgo_up(bp)), 0) * int64(szPage)
if sz == 0 {
Xsqlite3_reset(tls, **(**uintptr)(__ccgo_up(bp)))
Xsqlite3_exec(tls, db, __ccgo_ts+4504, uintptr(0), uintptr(0), uintptr(0))
rc = Xsqlite3_step(tls, **(**uintptr)(__ccgo_up(bp)))
if rc == int32(SQLITE_ROW) {
sz = Xsqlite3_column_int64(tls, **(**uintptr)(__ccgo_up(bp)), 0) * int64(szPage)
}
}
if piSize != 0 {
**(**Tsqlite3_int64)(__ccgo_up(piSize)) = sz
}
if mFlags&uint32(SQLITE_SERIALIZE_NOCOPY) != 0 {
pOut = uintptr(0)
} else {
pOut = Xsqlite3_malloc64(tls, libc.Uint64FromInt64(sz))
if pOut != 0 {
nPage = Xsqlite3_column_int(tls, **(**uintptr)(__ccgo_up(bp)), 0)
pPager = _sqlite3BtreePager(tls, pBt)
pgno = int32(1)
for {
if !(pgno <= nPage) {
break
}
**(**uintptr)(__ccgo_up(bp + 8)) = uintptr(0)
pTo = pOut + uintptr(int64(szPage)*int64(pgno-libc.Int32FromInt32(1)))
rc = _sqlite3PagerGet(tls, pPager, libc.Uint32FromInt32(pgno), bp+8, 0)
if rc == SQLITE_OK {
libc.X__builtin___memcpy_chk(tls, pTo, _sqlite3PagerGetData(tls, **(**uintptr)(__ccgo_up(bp + 8))), libc.Uint64FromInt32(szPage), ^t__predefined_size_t(0))
} else {
libc.X__builtin___memset_chk(tls, pTo, 0, libc.Uint64FromInt32(szPage), ^t__predefined_size_t(0))
}
_sqlite3PagerUnref(tls, **(**uintptr)(__ccgo_up(bp + 8)))
goto _2
_2:
;
pgno = pgno + 1
}
}
}
}
Xsqlite3_finalize(tls, **(**uintptr)(__ccgo_up(bp)))
goto serialize_out
serialize_out:
;
Xsqlite3_mutex_leave(tls, (*Tsqlite3)(unsafe.Pointer(db)).Fmutex)
return pOut
}
// C documentation
//
// /*
// ** Add new client data to a database connection.
// */
func Xsqlite3_set_clientdata(tls *libc.TLS, db uintptr, zName uintptr, pData uintptr, __ccgo_fp_xDestructor uintptr) (r int32) {
var n Tsize_t
var p, pp uintptr
_, _, _ = n, p, pp
Xsqlite3_mutex_enter(tls, (*Tsqlite3)(unsafe.Pointer(db)).Fmutex)
pp = db + 808
p = (*Tsqlite3)(unsafe.Pointer(db)).FpDbData
for {
if !(p != 0 && libc.Xstrcmp(tls, p+24, zName) != 0) {
break
}
pp = p
goto _1
_1:
;
p = (*TDbClientData)(unsafe.Pointer(p)).FpNext
}
if p != 0 {
if (*TDbClientData)(unsafe.Pointer(p)).FxDestructor != 0 {
(*(*func(*libc.TLS, uintptr))(unsafe.Pointer(&struct{ uintptr }{(*TDbClientData)(unsafe.Pointer(p)).FxDestructor})))(tls, (*TDbClientData)(unsafe.Pointer(p)).FpData)
}
if pData == uintptr(0) {
**(**uintptr)(__ccgo_up(pp)) = (*TDbClientData)(unsafe.Pointer(p)).FpNext
Xsqlite3_free(tls, p)
Xsqlite3_mutex_leave(tls, (*Tsqlite3)(unsafe.Pointer(db)).Fmutex)
return SQLITE_OK
}
} else {
if pData == uintptr(0) {
Xsqlite3_mutex_leave(tls, (*Tsqlite3)(unsafe.Pointer(db)).Fmutex)
return SQLITE_OK
} else {
n = libc.Xstrlen(tls, zName)
p = Xsqlite3_malloc64(tls, uint64(uint64(libc.UintptrFromInt32(0)+24)+(n+libc.Uint64FromInt32(1))))
if p == uintptr(0) {
if __ccgo_fp_xDestructor != 0 {
(*(*func(*libc.TLS, uintptr))(unsafe.Pointer(&struct{ uintptr }{__ccgo_fp_xDestructor})))(tls, pData)
}
Xsqlite3_mutex_leave(tls, (*Tsqlite3)(unsafe.Pointer(db)).Fmutex)
return int32(SQLITE_NOMEM)
}
libc.X__builtin___memcpy_chk(tls, p+24, zName, n+uint64(1), ^t__predefined_size_t(0))
(*TDbClientData)(unsafe.Pointer(p)).FpNext = (*Tsqlite3)(unsafe.Pointer(db)).FpDbData
(*Tsqlite3)(unsafe.Pointer(db)).FpDbData = p
}
}
(*TDbClientData)(unsafe.Pointer(p)).FpData = pData
(*TDbClientData)(unsafe.Pointer(p)).FxDestructor = __ccgo_fp_xDestructor
Xsqlite3_mutex_leave(tls, (*Tsqlite3)(unsafe.Pointer(db)).Fmutex)
return SQLITE_OK
}
// C documentation
//
// /************** End of stmt.c ************************************************/
// /* Return the source-id for this library */
func Xsqlite3_sourceid(tls *libc.TLS) (r uintptr) {
return __ccgo_ts + 42928
}
// C documentation
//
// /*
// ** Append N bytes of text from z to the StrAccum object. Increase the
// ** size of the memory allocation for StrAccum if necessary.
// */
func Xsqlite3_str_append(tls *libc.TLS, p uintptr, z uintptr, N int32) {
if (*Tsqlite3_str)(unsafe.Pointer(p)).FnChar+libc.Uint32FromInt32(N) >= (*Tsqlite3_str)(unsafe.Pointer(p)).FnAlloc {
_enlargeAndAppend(tls, p, z, N)
} else {
if N != 0 {
**(**Tu32)(__ccgo_up(p + 24)) += libc.Uint32FromInt32(N)
libc.X__builtin___memcpy_chk(tls, (*Tsqlite3_str)(unsafe.Pointer(p)).FzText+uintptr((*Tsqlite3_str)(unsafe.Pointer(p)).FnChar-libc.Uint32FromInt32(N)), z, libc.Uint64FromInt32(N), ^t__predefined_size_t(0))
}
}
}
// 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(int64(fmt)-int64(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(2)
_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.VaInt64(&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.VaUint64(&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 = int32(t__predefined_ptrdiff_t(zOut+uintptr(nOut-int32(1))) - int64(bufpt))
if precision > length { /* zero pad */
nn = precision - length
bufpt = bufpt - uintptr(nn)
libc.X__builtin___memset_chk(tls, bufpt, int32('0'), libc.Uint64FromInt32(nn), ^t__predefined_size_t(0))
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 = int32(t__predefined_ptrdiff_t(zOut+uintptr(nOut-int32(1))) - int64(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.X__builtin___memcpy_chk(tls, bp, __ccgo_ts+1697, uint64(5), ^t__predefined_size_t(0))
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.X__builtin___memcpy_chk(tls, bufpt, (**(**TFpDecode)(__ccgo_up(bp + 72))).Fz, libc.Uint64FromInt32(j), ^t__predefined_size_t(0))
bufpt = bufpt + uintptr(j)
e2 = e2 - j
if e2 >= 0 {
libc.X__builtin___memset_chk(tls, bufpt, int32('0'), libc.Uint64FromInt32(e2+int32(1)), ^t__predefined_size_t(0))
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.X__builtin___memset_chk(tls, bufpt, int32('0'), libc.Uint64FromInt32(nn2), ^t__predefined_size_t(0))
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.X__builtin___memcpy_chk(tls, bufpt, (**(**TFpDecode)(__ccgo_up(bp + 72))).Fz+uintptr(j), libc.Uint64FromInt32(nn3), ^t__predefined_size_t(0))
bufpt = bufpt + uintptr(nn3)
precision = precision - nn3
}
if precision > 0 && !(flag_rtz != 0) {
libc.X__builtin___memset_chk(tls, bufpt, int32('0'), libc.Uint64FromInt32(precision), ^t__predefined_size_t(0))
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(int64(bufpt) - int64(zOut))
if length < width {
nPad = int64(width - length)
if flag_leftjustify != 0 {
libc.X__builtin___memset_chk(tls, bufpt, int32(' '), libc.Uint64FromInt64(nPad), ^t__predefined_size_t(0))
} else {
if !(flag_zeropad != 0) {
libc.X__builtin___memmove_chk(tls, zOut+uintptr(nPad), zOut, libc.Uint64FromInt32(length), ^t__predefined_size_t(0))
libc.X__builtin___memset_chk(tls, zOut, int32(' '), libc.Uint64FromInt64(nPad), ^t__predefined_size_t(0))
} else {
adj = libc.BoolInt32(int32(prefix) != 0)
libc.X__builtin___memmove_chk(tls, zOut+uintptr(nPad)+uintptr(adj), zOut+uintptr(adj), libc.Uint64FromInt32(length-adj), ^t__predefined_size_t(0))
libc.X__builtin___memset_chk(tls, zOut+uintptr(adj), int32('0'), libc.Uint64FromInt64(nPad), ^t__predefined_size_t(0))
}
}
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 + 24)) += 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.Int32FromUint64(libc.Xstrlen(tls, bufpt)))
v4 = pAccum + 29
*(*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(int64(z) - int64(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.Int32FromUint64(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.X__builtin___memcpy_chk(tls, bufpt+uintptr(j1), __ccgo_ts+1715, uint64(8), ^t__predefined_size_t(0))
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 + 24 + 4))&0x10000>>16) == 0 && int32(*(*uint32)(unsafe.Pointer(pItem + 24 + 4))&0x4>>2) == 0 && *(*uintptr)(unsafe.Pointer(pItem + 72)) != uintptr(0) {
Xsqlite3_str_appendall(tls, pAccum, *(*uintptr)(unsafe.Pointer(pItem + 72)))
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 + 24 + 4))&0x4>>2) != 0 { /* Because of tag-20240424-1 */
pSel = (*TSubquery)(unsafe.Pointer(*(*uintptr)(unsafe.Pointer(pItem + 72)))).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(&(*TSrcItem)(unsafe.Pointer(pItem)).Fu1))))
} 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
//
// /*
// ** Return meta information about a specific column of a database table.
// ** See comment in sqlite3.h (sqlite.h.in) for details.
// */
func Xsqlite3_table_column_metadata(tls *libc.TLS, db uintptr, zDbName uintptr, zTableName uintptr, zColumnName uintptr, pzDataType uintptr, pzCollSeq uintptr, pNotNull uintptr, pPrimaryKey uintptr, pAutoinc uintptr) (r int32) {
bp := tls.Alloc(32)
defer tls.Free(32)
var autoinc, iCol, notnull, primarykey, rc int32
var pCol, pTab, zCollSeq, zDataType, v1 uintptr
var _ /* zErrMsg at bp+0 */ uintptr
_, _, _, _, _, _, _, _, _, _ = autoinc, iCol, notnull, pCol, pTab, primarykey, rc, zCollSeq, zDataType, v1
**(**uintptr)(__ccgo_up(bp)) = uintptr(0)
pTab = uintptr(0)
pCol = uintptr(0)
iCol = 0
zDataType = uintptr(0)
zCollSeq = uintptr(0)
notnull = 0
primarykey = 0
autoinc = 0
/* Ensure the database schema has been loaded */
Xsqlite3_mutex_enter(tls, (*Tsqlite3)(unsafe.Pointer(db)).Fmutex)
_sqlite3BtreeEnterAll(tls, db)
rc = _sqlite3Init(tls, db, bp)
if SQLITE_OK != rc {
goto error_out
}
/* Locate the table in question */
pTab = _sqlite3FindTable(tls, db, zTableName, zDbName)
if !(pTab != 0) || libc.Int32FromUint8((*TTable)(unsafe.Pointer(pTab)).FeTabType) == int32(TABTYP_VIEW) {
pTab = uintptr(0)
goto error_out
}
/* Find the column for which info is requested */
if zColumnName == uintptr(0) {
/* Query for existence of table only */
} else {
iCol = _sqlite3ColumnIndex(tls, pTab, zColumnName)
if iCol >= 0 {
pCol = (*TTable)(unsafe.Pointer(pTab)).FaCol + uintptr(iCol)*16
} else {
if (*TTable)(unsafe.Pointer(pTab)).FtabFlags&uint32(TF_WithoutRowid) == uint32(0) && _sqlite3IsRowid(tls, zColumnName) != 0 {
iCol = int32((*TTable)(unsafe.Pointer(pTab)).FiPKey)
if iCol >= 0 {
v1 = (*TTable)(unsafe.Pointer(pTab)).FaCol + uintptr(iCol)*16
} else {
v1 = uintptr(0)
}
pCol = v1
} else {
pTab = uintptr(0)
goto error_out
}
}
}
/* The following block stores the meta information that will be returned
** to the caller in local variables zDataType, zCollSeq, notnull, primarykey
** and autoinc. At this point there are two possibilities:
**
** 1. The specified column name was rowid", "oid" or "_rowid_"
** and there is no explicitly declared IPK column.
**
** 2. The table is not a view and the column name identified an
** explicitly declared column. Copy meta information from *pCol.
*/
if pCol != 0 {
zDataType = _sqlite3ColumnType(tls, pCol, uintptr(0))
zCollSeq = _sqlite3ColumnColl(tls, pCol)
notnull = libc.BoolInt32(int32(uint32(*(*uint8)(unsafe.Pointer(pCol + 8))&0xf>>0)) != 0)
primarykey = libc.BoolInt32(libc.Int32FromUint16((*TColumn)(unsafe.Pointer(pCol)).FcolFlags)&int32(COLFLAG_PRIMKEY) != 0)
autoinc = libc.BoolInt32(int32((*TTable)(unsafe.Pointer(pTab)).FiPKey) == iCol && (*TTable)(unsafe.Pointer(pTab)).FtabFlags&uint32(TF_Autoincrement) != uint32(0))
} else {
zDataType = __ccgo_ts + 1176
primarykey = int32(1)
}
if !(zCollSeq != 0) {
zCollSeq = uintptr(unsafe.Pointer(&_sqlite3StrBINARY))
}
goto error_out
error_out:
;
_sqlite3BtreeLeaveAll(tls, db)
/* Whether the function call succeeded or failed, set the output parameters
** to whatever their local counterparts contain. If an error did occur,
** this has the effect of zeroing all output parameters.
*/
if pzDataType != 0 {
**(**uintptr)(__ccgo_up(pzDataType)) = zDataType
}
if pzCollSeq != 0 {
**(**uintptr)(__ccgo_up(pzCollSeq)) = zCollSeq
}
if pNotNull != 0 {
**(**int32)(__ccgo_up(pNotNull)) = notnull
}
if pPrimaryKey != 0 {
**(**int32)(__ccgo_up(pPrimaryKey)) = primarykey
}
if pAutoinc != 0 {
**(**int32)(__ccgo_up(pAutoinc)) = autoinc
}
if SQLITE_OK == rc && !(pTab != 0) {
_sqlite3DbFree(tls, db, **(**uintptr)(__ccgo_up(bp)))
**(**uintptr)(__ccgo_up(bp)) = _sqlite3MPrintf(tls, db, __ccgo_ts+26731, libc.VaList(bp+16, zTableName, zColumnName))
rc = int32(SQLITE_ERROR)
}
if **(**uintptr)(__ccgo_up(bp)) != 0 {
v1 = __ccgo_ts + 3944
} else {
v1 = uintptr(0)
}
_sqlite3ErrorWithMsg(tls, db, rc, v1, libc.VaList(bp+16, **(**uintptr)(__ccgo_up(bp))))
_sqlite3DbFree(tls, db, **(**uintptr)(__ccgo_up(bp)))
rc = _sqlite3ApiExit(tls, db, rc)
Xsqlite3_mutex_leave(tls, (*Tsqlite3)(unsafe.Pointer(db)).Fmutex)
return rc
}
// C documentation
//
// /*
// ** If the following global variable points to a string which is the
// ** name of a directory, then that directory will be used to store
// ** temporary files.
// **
// ** See also the "PRAGMA temp_store_directory" SQL command.
// */
var Xsqlite3_temp_directory uintptr
/*===---- __stdarg_va_arg.h - Definitions of va_start, va_arg, va_end-------===
*
* Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
* See https://llvm.org/LICENSE.txt for license information.
* SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
*
*===-----------------------------------------------------------------------===
*/
/* Versions before C23 do require the second parameter. */
/*===---- __stdarg___va_copy.h - Definition of __va_copy -------------------===
*
* Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
* See https://llvm.org/LICENSE.txt for license information.
* SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
*
*===-----------------------------------------------------------------------===
*/
/*===---- __stdarg_va_copy.h - Definition of va_copy------------------------===
*
* Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
* See https://llvm.org/LICENSE.txt for license information.
* SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
*
*===-----------------------------------------------------------------------===
*/
/*
** Make sure we can call this stuff from C++.
*/
/*
** Facilitate override of interface linkage and calling conventions.
** Be aware that these macros may not be used within this particular
** translation of the amalgamation and its associated header file.
**
** The SQLITE_EXTERN and SQLITE_API macros are used to instruct the
** compiler that the target identifier should have external linkage.
**
** The SQLITE_CDECL macro is used to set the calling convention for
** public functions that accept a variable number of arguments.
**
** The SQLITE_APICALL macro is used to set the calling convention for
** public functions that accept a fixed number of arguments.
**
** The SQLITE_STDCALL macro is no longer used and is now deprecated.
**
** The SQLITE_CALLBACK macro is used to set the calling convention for
** function pointers.
**
** The SQLITE_SYSAPI macro is used to set the calling convention for
** functions provided by the operating system.
**
** Currently, the SQLITE_CDECL, SQLITE_APICALL, SQLITE_CALLBACK, and
** SQLITE_SYSAPI macros are used only when building for environments
** that require non-default calling conventions.
*/
/*
** These no-op macros are used in front of interfaces to mark those
** interfaces as either deprecated or experimental. New applications
** should not use deprecated interfaces - they are supported for backwards
** compatibility only. Application writers should be aware that
** experimental interfaces are subject to change in point releases.
**
** These macros used to resolve to various kinds of compiler magic that
** would generate warning messages when they were used. But that
** compiler magic ended up generating such a flurry of bug reports
** that we have taken it all out and gone back to using simple
** noop macros.
*/
/*
** Ensure these symbols were not defined by some previous header file.
*/
/*
** CAPI3REF: Compile-Time Library Version Numbers
**
** ^(The [SQLITE_VERSION] C preprocessor macro in the sqlite3.h header
** evaluates to a string literal that is the SQLite version in the
** format "X.Y.Z" where X is the major version number (always 3 for
** SQLite3) and Y is the minor version number and Z is the release number.)^
** ^(The [SQLITE_VERSION_NUMBER] C preprocessor macro resolves to an integer
** with the value (X*1000000 + Y*1000 + Z) where X, Y, and Z are the same
** numbers used in [SQLITE_VERSION].)^
** The SQLITE_VERSION_NUMBER for any given release of SQLite will also
** be larger than the release from which it is derived. Either Y will
** be held constant and Z will be incremented or else Y will be incremented
** and Z will be reset to zero.
**
** Since [version 3.6.18] ([dateof:3.6.18]),
** SQLite source code has been stored in the
** Fossil configuration management
** system. ^The SQLITE_SOURCE_ID macro evaluates to
** a string which identifies a particular check-in of SQLite
** within its configuration management system. ^The SQLITE_SOURCE_ID
** string contains the date and time of the check-in (UTC) and a SHA1
** or SHA3-256 hash of the entire source tree. If the source code has
** been edited in any way since it was last checked in, then the last
** four hexadecimal digits of the hash may be modified.
**
** See also: [sqlite3_libversion()],
** [sqlite3_libversion_number()], [sqlite3_sourceid()],
** [sqlite_version()] and [sqlite_source_id()].
*/
// C documentation
//
// /*
// ** Register an unlock-notify callback.
// **
// ** This is called after connection "db" has attempted some operation
// ** but has received an SQLITE_LOCKED error because another connection
// ** (call it pOther) in the same process was busy using the same shared
// ** cache. pOther is found by looking at db->pBlockingConnection.
// **
// ** If there is no blocking connection, the callback is invoked immediately,
// ** before this routine returns.
// **
// ** If pOther is already blocked on db, then report SQLITE_LOCKED, to indicate
// ** a deadlock.
// **
// ** Otherwise, make arrangements to invoke xNotify when pOther drops
// ** its locks.
// **
// ** Each call to this routine overrides any prior callbacks registered
// ** on the same "db". If xNotify==0 then any prior callbacks are immediately
// ** cancelled.
// */
func Xsqlite3_unlock_notify(tls *libc.TLS, db uintptr, __ccgo_fp_xNotify uintptr, _pArg uintptr) (r int32) {
bp := tls.Alloc(16)
defer tls.Free(16)
*(*uintptr)(unsafe.Pointer(bp)) = _pArg
var p, v2 uintptr
var rc int32
_, _, _ = p, rc, v2
rc = SQLITE_OK
Xsqlite3_mutex_enter(tls, (*Tsqlite3)(unsafe.Pointer(db)).Fmutex)
_enterMutex(tls)
if __ccgo_fp_xNotify == uintptr(0) {
_removeFromBlockedList(tls, db)
(*Tsqlite3)(unsafe.Pointer(db)).FpBlockingConnection = uintptr(0)
(*Tsqlite3)(unsafe.Pointer(db)).FpUnlockConnection = uintptr(0)
(*Tsqlite3)(unsafe.Pointer(db)).FxUnlockNotify = uintptr(0)
(*Tsqlite3)(unsafe.Pointer(db)).FpUnlockArg = uintptr(0)
} else {
if uintptr(0) == (*Tsqlite3)(unsafe.Pointer(db)).FpBlockingConnection {
/* The blocking transaction has been concluded. Or there never was a
** blocking transaction. In either case, invoke the notify callback
** immediately.
*/
(*(*func(*libc.TLS, uintptr, int32))(unsafe.Pointer(&struct{ uintptr }{__ccgo_fp_xNotify})))(tls, bp, int32(1))
} else {
p = (*Tsqlite3)(unsafe.Pointer(db)).FpBlockingConnection
for {
if !(p != 0 && p != db) {
break
}
goto _1
_1:
;
p = (*Tsqlite3)(unsafe.Pointer(p)).FpUnlockConnection
}
if p != 0 {
rc = int32(SQLITE_LOCKED) /* Deadlock detected. */
} else {
(*Tsqlite3)(unsafe.Pointer(db)).FpUnlockConnection = (*Tsqlite3)(unsafe.Pointer(db)).FpBlockingConnection
(*Tsqlite3)(unsafe.Pointer(db)).FxUnlockNotify = __ccgo_fp_xNotify
(*Tsqlite3)(unsafe.Pointer(db)).FpUnlockArg = **(**uintptr)(__ccgo_up(bp))
_removeFromBlockedList(tls, db)
_addToBlockedList(tls, db)
}
}
}
_leaveMutex(tls)
if rc != 0 {
v2 = __ccgo_ts + 26767
} else {
v2 = uintptr(0)
}
_sqlite3ErrorWithMsg(tls, db, rc, v2, 0)
Xsqlite3_mutex_leave(tls, (*Tsqlite3)(unsafe.Pointer(db)).Fmutex)
return rc
}
// C documentation
//
// /* Make a copy of an sqlite3_value object
// */
func Xsqlite3_value_dup(tls *libc.TLS, pOrig uintptr) (r uintptr) {
var pNew, v1 uintptr
_, _ = pNew, v1
if pOrig == uintptr(0) {
return uintptr(0)
}
pNew = Xsqlite3_malloc(tls, int32(56))
if pNew == uintptr(0) {
return uintptr(0)
}
libc.X__builtin___memset_chk(tls, pNew, 0, uint64(56), ^t__predefined_size_t(0))
libc.X__builtin___memcpy_chk(tls, pNew, pOrig, uint64(libc.UintptrFromInt32(0)+24), ^t__predefined_size_t(0))
v1 = pNew + 20
*(*Tu16)(unsafe.Pointer(v1)) = Tu16(int32(*(*Tu16)(unsafe.Pointer(v1))) & ^libc.Int32FromInt32(MEM_Dyn))
(*Tsqlite3_value)(unsafe.Pointer(pNew)).Fdb = uintptr(0)
if libc.Int32FromUint16((*Tsqlite3_value)(unsafe.Pointer(pNew)).Fflags)&(libc.Int32FromInt32(MEM_Str)|libc.Int32FromInt32(MEM_Blob)) != 0 {
v1 = pNew + 20
*(*Tu16)(unsafe.Pointer(v1)) = Tu16(int32(*(*Tu16)(unsafe.Pointer(v1))) & ^(libc.Int32FromInt32(MEM_Static) | libc.Int32FromInt32(MEM_Dyn)))
v1 = pNew + 20
*(*Tu16)(unsafe.Pointer(v1)) = Tu16(int32(*(*Tu16)(unsafe.Pointer(v1))) | libc.Int32FromInt32(MEM_Ephem))
if _sqlite3VdbeMemMakeWriteable(tls, pNew) != SQLITE_OK {
_sqlite3ValueFree(tls, pNew)
pNew = uintptr(0)
}
} else {
if libc.Int32FromUint16((*Tsqlite3_value)(unsafe.Pointer(pNew)).Fflags)&int32(MEM_Null) != 0 {
/* Do not duplicate pointer values */
v1 = pNew + 20
*(*Tu16)(unsafe.Pointer(v1)) = Tu16(int32(*(*Tu16)(unsafe.Pointer(v1))) & ^(libc.Int32FromInt32(MEM_Term) | libc.Int32FromInt32(MEM_Subtype)))
}
}
return pNew
}
// C documentation
//
// /*
// ** Return the ON CONFLICT resolution mode in effect for the virtual
// ** table update operation currently in progress.
// **
// ** The results of this routine are undefined unless it is called from
// ** within an xUpdate method.
// */
func Xsqlite3_vtab_on_conflict(tls *libc.TLS, db uintptr) (r int32) {
return libc.Int32FromUint8(_aMap1[libc.Int32FromUint8((*Tsqlite3)(unsafe.Pointer(db)).FvtabOnConflict)-int32(1)])
}
// 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+26420, 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+432, libc.Int32FromInt32(0), libc.Int32FromInt32(__ATOMIC_RELAXED))
}
Xsqlite3_mutex_leave(tls, (*Tsqlite3)(unsafe.Pointer(db)).Fmutex)
return rc
}
// C documentation
//
// /*
// ** Begin adding a change to a changegroup object.
// */
func Xsqlite3changegroup_change_begin(tls *libc.TLS, pGrp uintptr, eOp int32, zTab uintptr, bIndirect int32, pzErr uintptr) (r int32) {
bp := tls.Alloc(32)
defer tls.Free(32)
var aBuf uintptr
var nReq, rc, v1 int32
var _ /* pTab at bp+0 */ uintptr
_, _, _, _ = aBuf, nReq, rc, v1
**(**uintptr)(__ccgo_up(bp)) = uintptr(0)
rc = SQLITE_OK
if (*Tsqlite3_changegroup)(unsafe.Pointer(pGrp)).Fcd.FpTab != 0 {
rc = int32(SQLITE_MISUSE)
} else {
if eOp != int32(SQLITE_INSERT) && eOp != int32(SQLITE_UPDATE) && eOp != int32(SQLITE_DELETE) {
rc = int32(SQLITE_ERROR)
} else {
rc = _sessionChangesetFindTable(tls, pGrp, zTab, uintptr(0), bp)
}
}
if rc == SQLITE_OK {
if **(**uintptr)(__ccgo_up(bp)) == uintptr(0) {
if pzErr != 0 {
**(**uintptr)(__ccgo_up(pzErr)) = Xsqlite3_mprintf(tls, __ccgo_ts+21734, libc.VaList(bp+16, zTab))
}
rc = int32(SQLITE_ERROR)
} else {
if eOp == int32(SQLITE_UPDATE) {
v1 = int32(2)
} else {
v1 = int32(1)
}
nReq = (*TSessionTable)(unsafe.Pointer(**(**uintptr)(__ccgo_up(bp)))).FnCol * v1
(*Tsqlite3_changegroup)(unsafe.Pointer(pGrp)).Fcd.FpTab = **(**uintptr)(__ccgo_up(bp))
(*Tsqlite3_changegroup)(unsafe.Pointer(pGrp)).Fcd.FeOp = eOp
(*Tsqlite3_changegroup)(unsafe.Pointer(pGrp)).Fcd.FbIndirect = bIndirect
if (*Tsqlite3_changegroup)(unsafe.Pointer(pGrp)).Fcd.FnBufAlloc < nReq {
aBuf = Xsqlite3_realloc(tls, (*Tsqlite3_changegroup)(unsafe.Pointer(pGrp)).Fcd.FaBuf, libc.Int32FromUint64(libc.Uint64FromInt32(nReq)*uint64(16)))
if aBuf == uintptr(0) {
rc = int32(SQLITE_NOMEM)
} else {
libc.X__builtin___memset_chk(tls, aBuf+uintptr((*Tsqlite3_changegroup)(unsafe.Pointer(pGrp)).Fcd.FnBufAlloc)*16, 0, uint64(16)*libc.Uint64FromInt32(nReq-(*Tsqlite3_changegroup)(unsafe.Pointer(pGrp)).Fcd.FnBufAlloc), ^t__predefined_size_t(0))
(*Tsqlite3_changegroup)(unsafe.Pointer(pGrp)).Fcd.FaBuf = aBuf
(*Tsqlite3_changegroup)(unsafe.Pointer(pGrp)).Fcd.FnBufAlloc = nReq
}
}
}
}
return rc
}
// C documentation
//
// /*
// ** Configure the change currently under construction with a blob value.
// */
func Xsqlite3changegroup_change_blob(tls *libc.TLS, pGrp uintptr, bNew int32, iCol int32, pVal uintptr, nVal int32) (r int32) {
bp := tls.Alloc(16)
defer tls.Free(16)
var nByte Tsqlite3_int64
var rc, v1 int32
var _ /* pBuf at bp+0 */ uintptr
_, _, _ = nByte, rc, v1
nByte = int64(int32(1)+_sessionVarintLen(tls, nVal)) + int64(nVal)
rc = SQLITE_OK
**(**uintptr)(__ccgo_up(bp)) = uintptr(0)
v1 = _checkChangeParams(tls, pGrp, bNew, iCol, nByte, bp)
rc = v1
if SQLITE_OK != v1 {
return rc
}
**(**Tu8)(__ccgo_up((*TSessionBuffer)(unsafe.Pointer(**(**uintptr)(__ccgo_up(bp)))).FaBuf)) = uint8(SQLITE_BLOB)
(*TSessionBuffer)(unsafe.Pointer(**(**uintptr)(__ccgo_up(bp)))).FnBuf = int32(1) + _sessionVarintPut(tls, (*TSessionBuffer)(unsafe.Pointer(**(**uintptr)(__ccgo_up(bp)))).FaBuf+1, nVal)
libc.X__builtin___memcpy_chk(tls, (*TSessionBuffer)(unsafe.Pointer(**(**uintptr)(__ccgo_up(bp)))).FaBuf+uintptr((*TSessionBuffer)(unsafe.Pointer(**(**uintptr)(__ccgo_up(bp)))).FnBuf), pVal, libc.Uint64FromInt32(nVal), ^t__predefined_size_t(0))
**(**int32)(__ccgo_up(**(**uintptr)(__ccgo_up(bp)) + 8)) += nVal
return SQLITE_OK
}
// C documentation
//
// /*
// ** Finish any change currently being constructed by the changegroup object.
// */
func Xsqlite3changegroup_change_finish(tls *libc.TLS, pGrp uintptr, bDiscard int32, pzErr uintptr) (r int32) {
bp := tls.Alloc(48)
defer tls.Free(48)
var aBuf, p, v2, v3 uintptr
var eUndef Tu8
var ii, isPK, nBuf, nZero, v7 int32
var _ /* rc at bp+0 */ int32
_, _, _, _, _, _, _, _, _, _ = aBuf, eUndef, ii, isPK, nBuf, nZero, p, v2, v3, v7
**(**int32)(__ccgo_up(bp)) = SQLITE_OK
if (*Tsqlite3_changegroup)(unsafe.Pointer(pGrp)).Fcd.FpTab != 0 {
aBuf = (*Tsqlite3_changegroup)(unsafe.Pointer(pGrp)).Fcd.FaBuf
if bDiscard == 0 {
nBuf = (*TSessionTable)(unsafe.Pointer((*Tsqlite3_changegroup)(unsafe.Pointer(pGrp)).Fcd.FpTab)).FnCol
eUndef = uint8(SQLITE_NULL)
if (*Tsqlite3_changegroup)(unsafe.Pointer(pGrp)).Fcd.FeOp == int32(SQLITE_UPDATE) {
ii = 0
for {
if !(ii < nBuf) {
break
}
if **(**Tu8)(__ccgo_up((*TSessionTable)(unsafe.Pointer((*Tsqlite3_changegroup)(unsafe.Pointer(pGrp)).Fcd.FpTab)).FabPK + uintptr(ii))) != 0 {
if (**(**TSessionBuffer)(__ccgo_up(aBuf + uintptr(ii)*16))).FnBuf <= int32(1) {
if (**(**TSessionBuffer)(__ccgo_up(aBuf + uintptr(ii)*16))).FnBuf == int32(1) {
v2 = __ccgo_ts + 1688
} else {
v2 = __ccgo_ts + 37219
}
**(**uintptr)(__ccgo_up(pzErr)) = Xsqlite3_mprintf(tls, __ccgo_ts+37229, libc.VaList(bp+16, v2))
**(**int32)(__ccgo_up(bp)) = int32(SQLITE_ERROR)
break
} else {
if (**(**TSessionBuffer)(__ccgo_up(aBuf + uintptr(ii+nBuf)*16))).FnBuf > 0 {
**(**uintptr)(__ccgo_up(pzErr)) = Xsqlite3_mprintf(tls, __ccgo_ts+37276, 0)
**(**int32)(__ccgo_up(bp)) = int32(SQLITE_ERROR)
break
}
}
} else {
if (*Tsqlite3_changegroup)(unsafe.Pointer(pGrp)).FbPatch == 0 && libc.BoolInt32((**(**TSessionBuffer)(__ccgo_up(aBuf + uintptr(ii)*16))).FnBuf > 0) != libc.BoolInt32((**(**TSessionBuffer)(__ccgo_up(aBuf + uintptr(ii+nBuf)*16))).FnBuf > 0) {
if (**(**TSessionBuffer)(__ccgo_up(aBuf + uintptr(ii)*16))).FnBuf != 0 {
v2 = __ccgo_ts + 1702
} else {
v2 = __ccgo_ts + 37328
}
if (**(**TSessionBuffer)(__ccgo_up(aBuf + uintptr(ii+nBuf)*16))).FnBuf != 0 {
v3 = __ccgo_ts + 1702
} else {
v3 = __ccgo_ts + 37328
}
**(**uintptr)(__ccgo_up(pzErr)) = Xsqlite3_mprintf(tls, __ccgo_ts+37331, libc.VaList(bp+16, ii, v2, v3))
**(**int32)(__ccgo_up(bp)) = int32(SQLITE_ERROR)
break
}
}
goto _1
_1:
;
ii = ii + 1
}
eUndef = uint8(0x00)
if (*Tsqlite3_changegroup)(unsafe.Pointer(pGrp)).FbPatch == 0 {
nBuf = nBuf * int32(2)
}
} else {
ii = 0
for {
if !(ii < nBuf) {
break
}
isPK = libc.Int32FromUint8(**(**Tu8)(__ccgo_up((*TSessionTable)(unsafe.Pointer((*Tsqlite3_changegroup)(unsafe.Pointer(pGrp)).Fcd.FpTab)).FabPK + uintptr(ii))))
if ((*Tsqlite3_changegroup)(unsafe.Pointer(pGrp)).Fcd.FeOp == int32(SQLITE_INSERT) || (*Tsqlite3_changegroup)(unsafe.Pointer(pGrp)).FbPatch == 0 || isPK != 0) && (**(**TSessionBuffer)(__ccgo_up(aBuf + uintptr(ii)*16))).FnBuf == 0 {
**(**uintptr)(__ccgo_up(pzErr)) = Xsqlite3_mprintf(tls, __ccgo_ts+37407, libc.VaList(bp+16, ii))
**(**int32)(__ccgo_up(bp)) = int32(SQLITE_ERROR)
break
}
if (**(**TSessionBuffer)(__ccgo_up(aBuf + uintptr(ii)*16))).FnBuf == int32(1) && isPK != 0 {
**(**uintptr)(__ccgo_up(pzErr)) = Xsqlite3_mprintf(tls, __ccgo_ts+37446, 0)
**(**int32)(__ccgo_up(bp)) = int32(SQLITE_ERROR)
break
}
goto _5
_5:
;
ii = ii + 1
}
}
(*Tsqlite3_changegroup)(unsafe.Pointer(pGrp)).Fcd.Frecord.FnBuf = 0
ii = 0
for {
if !(ii < nBuf) {
break
}
p = (*Tsqlite3_changegroup)(unsafe.Pointer(pGrp)).Fcd.FaBuf + uintptr(ii)*16
if (*Tsqlite3_changegroup)(unsafe.Pointer(pGrp)).FbPatch != 0 {
if libc.Int32FromUint8(**(**Tu8)(__ccgo_up((*TSessionTable)(unsafe.Pointer((*Tsqlite3_changegroup)(unsafe.Pointer(pGrp)).Fcd.FpTab)).FabPK + uintptr(ii)))) == 0 {
if (*Tsqlite3_changegroup)(unsafe.Pointer(pGrp)).Fcd.FeOp == int32(SQLITE_UPDATE) {
p = p + uintptr((*TSessionTable)(unsafe.Pointer((*Tsqlite3_changegroup)(unsafe.Pointer(pGrp)).Fcd.FpTab)).FnCol)*16
} else {
if (*Tsqlite3_changegroup)(unsafe.Pointer(pGrp)).Fcd.FeOp == int32(SQLITE_DELETE) {
goto _6
}
}
}
}
if (*TSessionBuffer)(unsafe.Pointer(p)).FnBuf != 0 {
v7 = (*TSessionBuffer)(unsafe.Pointer(p)).FnBuf
} else {
v7 = int32(1)
}
if 0 == _sessionBufferGrow(tls, pGrp+48+32, int64(v7), bp) {
if (*TSessionBuffer)(unsafe.Pointer(p)).FnBuf != 0 {
libc.X__builtin___memcpy_chk(tls, (*Tsqlite3_changegroup)(unsafe.Pointer(pGrp)).Fcd.Frecord.FaBuf+uintptr((*Tsqlite3_changegroup)(unsafe.Pointer(pGrp)).Fcd.Frecord.FnBuf), (*TSessionBuffer)(unsafe.Pointer(p)).FaBuf, libc.Uint64FromInt32((*TSessionBuffer)(unsafe.Pointer(p)).FnBuf), ^t__predefined_size_t(0))
(*Tsqlite3_changegroup)(unsafe.Pointer(pGrp)).Fcd.Frecord.FnBuf += (*TSessionBuffer)(unsafe.Pointer(p)).FnBuf
} else {
v2 = pGrp + 48 + 32 + 8
v7 = *(*int32)(unsafe.Pointer(v2))
*(*int32)(unsafe.Pointer(v2)) = *(*int32)(unsafe.Pointer(v2)) + 1
**(**Tu8)(__ccgo_up((*Tsqlite3_changegroup)(unsafe.Pointer(pGrp)).Fcd.Frecord.FaBuf + uintptr(v7))) = eUndef
}
}
goto _6
_6:
;
ii = ii + 1
}
if **(**int32)(__ccgo_up(bp)) == SQLITE_OK {
**(**int32)(__ccgo_up(bp)) = _sessionOneChangeToHash(tls, pGrp, (*Tsqlite3_changegroup)(unsafe.Pointer(pGrp)).Fcd.FpTab, (*Tsqlite3_changegroup)(unsafe.Pointer(pGrp)).Fcd.FeOp, (*Tsqlite3_changegroup)(unsafe.Pointer(pGrp)).Fcd.FbIndirect, (*TSessionTable)(unsafe.Pointer((*Tsqlite3_changegroup)(unsafe.Pointer(pGrp)).Fcd.FpTab)).FnCol, (*Tsqlite3_changegroup)(unsafe.Pointer(pGrp)).Fcd.Frecord.FaBuf, (*Tsqlite3_changegroup)(unsafe.Pointer(pGrp)).Fcd.Frecord.FnBuf, 0)
}
}
/* Reset all aBuf[] entries to "undefined". */
nZero = (*TSessionTable)(unsafe.Pointer((*Tsqlite3_changegroup)(unsafe.Pointer(pGrp)).Fcd.FpTab)).FnCol
if (*Tsqlite3_changegroup)(unsafe.Pointer(pGrp)).Fcd.FeOp == int32(SQLITE_UPDATE) {
nZero = nZero + nZero
}
ii = 0
for {
if !(ii < nZero) {
break
}
(**(**TSessionBuffer)(__ccgo_up((*Tsqlite3_changegroup)(unsafe.Pointer(pGrp)).Fcd.FaBuf + uintptr(ii)*16))).FnBuf = 0
goto _10
_10:
;
ii = ii + 1
}
(*Tsqlite3_changegroup)(unsafe.Pointer(pGrp)).Fcd.FpTab = uintptr(0)
}
return **(**int32)(__ccgo_up(bp))
}
/************** End of sqlite3session.c **************************************/
/************** Begin file fts5.c ********************************************/
/*
** This, the "fts5.c" source file, is a composite file that is itself
** assembled from the following files:
**
** fts5.h
** fts5Int.h
** fts5parse.h <--- Generated from fts5parse.y by Lemon
** fts5parse.c <--- Generated from fts5parse.y by Lemon
** fts5_aux.c
** fts5_buffer.c
** fts5_config.c
** fts5_expr.c
** fts5_hash.c
** fts5_index.c
** fts5_main.c
** fts5_storage.c
** fts5_tokenize.c
** fts5_unicode2.c
** fts5_varint.c
** fts5_vocab.c
*/
/*
** 2014 May 31
**
** The author disclaims copyright to this source code. In place of
** a legal notice, here is a blessing:
**
** May you do good and not evil.
** May you find forgiveness for yourself and forgive others.
** May you share freely, never taking more than you give.
**
******************************************************************************
**
** Interfaces to extend FTS5. Using the interfaces defined in this file,
** FTS5 may be extended with:
**
** * custom tokenizers, and
** * custom auxiliary functions.
*/
/*
** 2014 May 31
**
** The author disclaims copyright to this source code. In place of
** a legal notice, here is a blessing:
**
** May you do good and not evil.
** May you find forgiveness for yourself and forgive others.
** May you share freely, never taking more than you give.
**
******************************************************************************
**
*/
/* #include "fts5.h" */
/* #include "sqlite3ext.h" */
/* #include */
/* #include */
/* #include */
/*
** Constants for the largest and smallest possible 32-bit signed integers.
*/
/* Truncate very long tokens to this many bytes. Hard limit is
** (65536-1-1-4-9)==65521 bytes. The limiting factor is the 16-bit offset
** field that occurs at the start of each leaf page (see fts5_index.c). */
/*
** Maximum number of prefix indexes on single FTS5 table. This must be
** less than 32. If it is set to anything large than that, an #error
** directive in fts5_index.c will cause the build to fail.
*/
/*
** Maximum segments permitted in a single index
*/
/* Name of rank and rowid columns */
/*
** The assert_nc() macro is similar to the assert() macro, except that it
** is used for assert() conditions that are true only if it can be
** guranteed that the database is not corrupt.
*/
/*
** A version of memcmp() that does not cause asan errors if one of the pointer
** parameters is NULL and the number of bytes to compare is zero.
*/
/* Mark a function parameter as unused, to suppress nuisance compiler
** warnings. */
// C documentation
//
// /*
// ** Configure the change currently under construction with a text value.
// */
func Xsqlite3changegroup_change_text(tls *libc.TLS, pGrp uintptr, bNew int32, iCol int32, pVal uintptr, nVal int32) (r int32) {
bp := tls.Alloc(16)
defer tls.Free(16)
var nByte Tsqlite3_int64
var nText, rc, v2 int32
var v1 uint64
var _ /* pBuf at bp+0 */ uintptr
_, _, _, _, _ = nByte, nText, rc, v1, v2
if nVal >= 0 {
v1 = libc.Uint64FromInt32(nVal)
} else {
v1 = libc.Xstrlen(tls, pVal)
}
nText = libc.Int32FromUint64(v1)
nByte = int64(int32(1) + _sessionVarintLen(tls, nText) + nText)
rc = SQLITE_OK
**(**uintptr)(__ccgo_up(bp)) = uintptr(0)
v2 = _checkChangeParams(tls, pGrp, bNew, iCol, nByte, bp)
rc = v2
if SQLITE_OK != v2 {
return rc
}
**(**Tu8)(__ccgo_up((*TSessionBuffer)(unsafe.Pointer(**(**uintptr)(__ccgo_up(bp)))).FaBuf)) = uint8(SQLITE_TEXT)
(*TSessionBuffer)(unsafe.Pointer(**(**uintptr)(__ccgo_up(bp)))).FnBuf = int32(1) + _sessionVarintPut(tls, (*TSessionBuffer)(unsafe.Pointer(**(**uintptr)(__ccgo_up(bp)))).FaBuf+1, nText)
libc.X__builtin___memcpy_chk(tls, (*TSessionBuffer)(unsafe.Pointer(**(**uintptr)(__ccgo_up(bp)))).FaBuf+uintptr((*TSessionBuffer)(unsafe.Pointer(**(**uintptr)(__ccgo_up(bp)))).FnBuf), pVal, libc.Uint64FromInt32(nText), ^t__predefined_size_t(0))
**(**int32)(__ccgo_up(**(**uintptr)(__ccgo_up(bp)) + 8)) += nText
return SQLITE_OK
}
// C documentation
//
// /*
// ** Allocate a new, empty, sqlite3_changegroup.
// */
func Xsqlite3changegroup_new(tls *libc.TLS, pp uintptr) (r int32) {
var p uintptr
var rc int32
_, _ = p, rc
rc = SQLITE_OK /* New object */
p = Xsqlite3_malloc(tls, int32(96))
if p == uintptr(0) {
rc = int32(SQLITE_NOMEM)
} else {
libc.X__builtin___memset_chk(tls, p, 0, uint64(96), ^t__predefined_size_t(0))
}
**(**uintptr)(__ccgo_up(pp)) = p
return rc
}
// C documentation
//
// /*
// ** Invert a changeset object.
// */
func Xsqlite3changeset_invert(tls *libc.TLS, nChangeset int32, pChangeset uintptr, pnInverted uintptr, ppInverted uintptr) (r int32) {
bp := tls.Alloc(80)
defer tls.Free(80)
var _ /* sInput at bp+0 */ TSessionInput
/* Set up the input stream */
libc.X__builtin___memset_chk(tls, bp, 0, uint64(72), ^t__predefined_size_t(0))
(**(**TSessionInput)(__ccgo_up(bp))).FnData = nChangeset
(**(**TSessionInput)(__ccgo_up(bp))).FaData = pChangeset
return _sessionChangesetInvert(tls, bp, uintptr(0), uintptr(0), pnInverted, ppInverted)
}
// C documentation
//
// /*
// ** Streaming version of sqlite3changeset_invert().
// */
func Xsqlite3changeset_invert_strm(tls *libc.TLS, __ccgo_fp_xInput uintptr, pIn uintptr, __ccgo_fp_xOutput uintptr, pOut uintptr) (r int32) {
bp := tls.Alloc(80)
defer tls.Free(80)
var rc int32
var _ /* sInput at bp+0 */ TSessionInput
_ = rc
/* Set up the input stream */
libc.X__builtin___memset_chk(tls, bp, 0, uint64(72), ^t__predefined_size_t(0))
(**(**TSessionInput)(__ccgo_up(bp))).FxInput = __ccgo_fp_xInput
(**(**TSessionInput)(__ccgo_up(bp))).FpIn = pIn
rc = _sessionChangesetInvert(tls, bp, __ccgo_fp_xOutput, pOut, uintptr(0), uintptr(0))
Xsqlite3_free(tls, (**(**TSessionInput)(__ccgo_up(bp))).Fbuf.FaBuf)
return rc
}
// C documentation
//
// /*
// ** 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+16466, uintptr(0), uintptr(0), p+64)
}
/* Sync the db file if currently doing an incremental checkpoint */
if (*Tsqlite3rbu)(unsafe.Pointer(p)).Frc == SQLITE_OK && (*Tsqlite3rbu)(unsafe.Pointer(p)).FeStage == int32(RBU_STAGE_CKPT) {
pDb = (*Trbu_file)(unsafe.Pointer((*Tsqlite3rbu)(unsafe.Pointer(p)).FpTargetFd)).FpReal
(*Tsqlite3rbu)(unsafe.Pointer(p)).Frc = (*(*func(*libc.TLS, uintptr, int32) int32)(unsafe.Pointer(&struct{ uintptr }{(*Tsqlite3_io_methods)(unsafe.Pointer((*Tsqlite3_file)(unsafe.Pointer(pDb)).FpMethods)).FxSync})))(tls, pDb, int32(SQLITE_SYNC_NORMAL))
}
_rbuSaveState(tls, p, (*Tsqlite3rbu)(unsafe.Pointer(p)).FeStage)
if (*Tsqlite3rbu)(unsafe.Pointer(p)).Frc == SQLITE_OK && (*Tsqlite3rbu)(unsafe.Pointer(p)).FeStage == int32(RBU_STAGE_OAL) {
(*Tsqlite3rbu)(unsafe.Pointer(p)).Frc = Xsqlite3_exec(tls, (*Tsqlite3rbu)(unsafe.Pointer(p)).FdbRbu, __ccgo_ts+16466, uintptr(0), uintptr(0), p+64)
}
/* Close any open statement handles. */
_rbuObjIterFinalize(tls, p+88)
/* If this is an RBU vacuum handle and the vacuum has either finished
** successfully or encountered an error, delete the contents of the
** state table. This causes the next call to sqlite3rbu_vacuum()
** specifying the current target and state databases to start a new
** vacuum from scratch. */
if (*Tsqlite3rbu)(unsafe.Pointer(p)).FzTarget == uintptr(0) && (*Tsqlite3rbu)(unsafe.Pointer(p)).Frc != SQLITE_OK && (*Tsqlite3rbu)(unsafe.Pointer(p)).FdbRbu != 0 {
rc2 = Xsqlite3_exec(tls, (*Tsqlite3rbu)(unsafe.Pointer(p)).FdbRbu, __ccgo_ts+35075, 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
//
// /*
// ** Create an RBU VFS named zName that accesses the underlying file-system
// ** via existing VFS zParent. The new object is registered as a non-default
// ** VFS with SQLite before returning.
// */
func Xsqlite3rbu_create_vfs(tls *libc.TLS, zName uintptr, zParent uintptr) (r int32) {
var nByte, nName Tsize_t
var pNew, pParent, zSpace, v1 uintptr
var rc int32
_, _, _, _, _, _, _ = nByte, nName, pNew, pParent, rc, zSpace, v1
pNew = uintptr(0) /* Newly allocated VFS */
rc = SQLITE_OK
nName = libc.Xstrlen(tls, zName)
nByte = uint64(208) + nName + uint64(1)
pNew = Xsqlite3_malloc64(tls, nByte)
if pNew == uintptr(0) {
rc = int32(SQLITE_NOMEM)
} else { /* Parent VFS */
libc.X__builtin___memset_chk(tls, pNew, 0, nByte, ^t__predefined_size_t(0))
pParent = Xsqlite3_vfs_find(tls, zParent)
if pParent == uintptr(0) {
rc = int32(SQLITE_NOTFOUND)
} else {
libc.X__builtin___memcpy_chk(tls, pNew, uintptr(unsafe.Pointer(&_vfs_template)), uint64(168), ^t__predefined_size_t(0))
(*Trbu_vfs)(unsafe.Pointer(pNew)).Fbase.FmxPathname = (*Tsqlite3_vfs)(unsafe.Pointer(pParent)).FmxPathname
(*Trbu_vfs)(unsafe.Pointer(pNew)).Fbase.FszOsFile = libc.Int32FromUint64(uint64(104) + libc.Uint64FromInt32((*Tsqlite3_vfs)(unsafe.Pointer(pParent)).FszOsFile))
(*Trbu_vfs)(unsafe.Pointer(pNew)).FpRealVfs = pParent
v1 = pNew + 1*208
zSpace = v1
(*Trbu_vfs)(unsafe.Pointer(pNew)).Fbase.FzName = v1
libc.X__builtin___memcpy_chk(tls, zSpace, zName, nName, ^t__predefined_size_t(0))
/* Allocate the mutex and register the new VFS (not as the default) */
(*Trbu_vfs)(unsafe.Pointer(pNew)).Fmutex = Xsqlite3_mutex_alloc(tls, int32(SQLITE_MUTEX_RECURSIVE))
if (*Trbu_vfs)(unsafe.Pointer(pNew)).Fmutex == uintptr(0) {
rc = int32(SQLITE_NOMEM)
} else {
rc = Xsqlite3_vfs_register(tls, pNew, 0)
}
}
if rc != SQLITE_OK {
Xsqlite3_mutex_free(tls, (*Trbu_vfs)(unsafe.Pointer(pNew)).Fmutex)
Xsqlite3_free(tls, pNew)
}
}
return rc
}
func Xsqlite3rbu_savestate(tls *libc.TLS, p uintptr) (r int32) {
var pDb, zBegin, v1 uintptr
var rc int32
_, _, _, _ = pDb, rc, zBegin, v1
rc = (*Tsqlite3rbu)(unsafe.Pointer(p)).Frc
if rc == int32(SQLITE_DONE) {
return SQLITE_OK
}
if (*Tsqlite3rbu)(unsafe.Pointer(p)).FeStage == int32(RBU_STAGE_OAL) {
if rc == SQLITE_OK {
rc = Xsqlite3_exec(tls, (*Tsqlite3rbu)(unsafe.Pointer(p)).FdbMain, __ccgo_ts+16466, uintptr(0), uintptr(0), uintptr(0))
}
}
/* Sync the db file */
if rc == SQLITE_OK && (*Tsqlite3rbu)(unsafe.Pointer(p)).FeStage == int32(RBU_STAGE_CKPT) {
pDb = (*Trbu_file)(unsafe.Pointer((*Tsqlite3rbu)(unsafe.Pointer(p)).FpTargetFd)).FpReal
rc = (*(*func(*libc.TLS, uintptr, int32) int32)(unsafe.Pointer(&struct{ uintptr }{(*Tsqlite3_io_methods)(unsafe.Pointer((*Tsqlite3_file)(unsafe.Pointer(pDb)).FpMethods)).FxSync})))(tls, pDb, int32(SQLITE_SYNC_NORMAL))
}
(*Tsqlite3rbu)(unsafe.Pointer(p)).Frc = rc
_rbuSaveState(tls, p, (*Tsqlite3rbu)(unsafe.Pointer(p)).FeStage)
rc = (*Tsqlite3rbu)(unsafe.Pointer(p)).Frc
if (*Tsqlite3rbu)(unsafe.Pointer(p)).FeStage == int32(RBU_STAGE_OAL) {
if rc == SQLITE_OK {
rc = Xsqlite3_exec(tls, (*Tsqlite3rbu)(unsafe.Pointer(p)).FdbRbu, __ccgo_ts+16466, uintptr(0), uintptr(0), uintptr(0))
}
if rc == SQLITE_OK {
if (*Tsqlite3rbu)(unsafe.Pointer(p)).FzTarget == uintptr(0) {
v1 = __ccgo_ts + 16451
} else {
v1 = __ccgo_ts + 35027
}
zBegin = v1
rc = Xsqlite3_exec(tls, (*Tsqlite3rbu)(unsafe.Pointer(p)).FdbRbu, zBegin, uintptr(0), uintptr(0), uintptr(0))
}
if rc == SQLITE_OK {
rc = Xsqlite3_exec(tls, (*Tsqlite3rbu)(unsafe.Pointer(p)).FdbMain, __ccgo_ts+35027, uintptr(0), uintptr(0), uintptr(0))
}
}
(*Tsqlite3rbu)(unsafe.Pointer(p)).Frc = rc
return rc
}
// C documentation
//
// /*
// ** Step the RBU object.
// */
func Xsqlite3rbu_step(tls *libc.TLS, p uintptr) (r int32) {
bp := tls.Alloc(32)
defer tls.Free(32)
var iSector Tu32
var pDb, pFrame, pIter uintptr
var rc int32
var _ /* ptr at bp+0 */ uintptr
_, _, _, _, _ = iSector, pDb, pFrame, pIter, rc
if p != 0 {
switch (*Tsqlite3rbu)(unsafe.Pointer(p)).FeStage {
case int32(RBU_STAGE_OAL):
pIter = p + 88
/* If this is an RBU vacuum operation and the state table was empty
** when this handle was opened, create the target database schema. */
if (*Tsqlite3rbu)(unsafe.Pointer(p)).FzTarget == uintptr(0) && (*Tsqlite3rbu)(unsafe.Pointer(p)).FnProgress == 0 && (*Tsqlite3rbu)(unsafe.Pointer(p)).Frc == SQLITE_OK {
_rbuCreateTargetSchema(tls, p)
_rbuCopyPragma(tls, p, __ccgo_ts+19303)
_rbuCopyPragma(tls, p, __ccgo_ts+18398)
}
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+34668, libc.VaList(bp+16, p+48, (*TRbuObjIter)(unsafe.Pointer(pIter)).FzDataTbl))
}
} else {
_rbuObjIterPrepareAll(tls, p, pIter, 0)
/* Advance to the next row to process. */
if (*Tsqlite3rbu)(unsafe.Pointer(p)).Frc == SQLITE_OK {
rc = Xsqlite3_step(tls, (*TRbuObjIter)(unsafe.Pointer(pIter)).FpSelect)
if rc == int32(SQLITE_ROW) {
(*Tsqlite3rbu)(unsafe.Pointer(p)).FnProgress = (*Tsqlite3rbu)(unsafe.Pointer(p)).FnProgress + 1
(*Tsqlite3rbu)(unsafe.Pointer(p)).FnStep = (*Tsqlite3rbu)(unsafe.Pointer(p)).FnStep + 1
return _rbuStep(tls, p)
}
(*Tsqlite3rbu)(unsafe.Pointer(p)).Frc = Xsqlite3_reset(tls, (*TRbuObjIter)(unsafe.Pointer(pIter)).FpSelect)
(*Tsqlite3rbu)(unsafe.Pointer(p)).FnStep = 0
}
}
_rbuObjIterNext(tls, p, pIter)
}
if (*Tsqlite3rbu)(unsafe.Pointer(p)).Frc == SQLITE_OK {
_rbuSaveState(tls, p, int32(RBU_STAGE_MOVE))
_rbuIncrSchemaCookie(tls, p)
if (*Tsqlite3rbu)(unsafe.Pointer(p)).Frc == SQLITE_OK {
(*Tsqlite3rbu)(unsafe.Pointer(p)).Frc = Xsqlite3_exec(tls, (*Tsqlite3rbu)(unsafe.Pointer(p)).FdbMain, __ccgo_ts+16466, uintptr(0), uintptr(0), p+64)
}
if (*Tsqlite3rbu)(unsafe.Pointer(p)).Frc == SQLITE_OK {
(*Tsqlite3rbu)(unsafe.Pointer(p)).Frc = Xsqlite3_exec(tls, (*Tsqlite3rbu)(unsafe.Pointer(p)).FdbRbu, __ccgo_ts+16466, uintptr(0), uintptr(0), p+64)
}
(*Tsqlite3rbu)(unsafe.Pointer(p)).FeStage = int32(RBU_STAGE_MOVE)
}
case int32(RBU_STAGE_MOVE):
if (*Tsqlite3rbu)(unsafe.Pointer(p)).Frc == SQLITE_OK {
_rbuMoveOalFile(tls, p)
(*Tsqlite3rbu)(unsafe.Pointer(p)).FnProgress = (*Tsqlite3rbu)(unsafe.Pointer(p)).FnProgress + 1
}
case int32(RBU_STAGE_CKPT):
if (*Tsqlite3rbu)(unsafe.Pointer(p)).Frc == SQLITE_OK {
if (*Tsqlite3rbu)(unsafe.Pointer(p)).FnStep >= (*Tsqlite3rbu)(unsafe.Pointer(p)).FnFrame {
pDb = (*Trbu_file)(unsafe.Pointer((*Tsqlite3rbu)(unsafe.Pointer(p)).FpTargetFd)).FpReal
/* Sync the db file */
(*Tsqlite3rbu)(unsafe.Pointer(p)).Frc = (*(*func(*libc.TLS, uintptr, int32) int32)(unsafe.Pointer(&struct{ uintptr }{(*Tsqlite3_io_methods)(unsafe.Pointer((*Tsqlite3_file)(unsafe.Pointer(pDb)).FpMethods)).FxSync})))(tls, pDb, int32(SQLITE_SYNC_NORMAL))
/* Update nBackfill */
if (*Tsqlite3rbu)(unsafe.Pointer(p)).Frc == SQLITE_OK {
(*Tsqlite3rbu)(unsafe.Pointer(p)).Frc = (*(*func(*libc.TLS, uintptr, int32, int32, int32, uintptr) int32)(unsafe.Pointer(&struct{ uintptr }{(*Tsqlite3_io_methods)(unsafe.Pointer((*Tsqlite3_file)(unsafe.Pointer(pDb)).FpMethods)).FxShmMap})))(tls, pDb, 0, libc.Int32FromInt32(32)*libc.Int32FromInt32(1024), 0, bp)
if (*Tsqlite3rbu)(unsafe.Pointer(p)).Frc == SQLITE_OK {
**(**Tu32)(__ccgo_up(**(**uintptr)(__ccgo_up(bp)) + 24*4)) = (*Tsqlite3rbu)(unsafe.Pointer(p)).FiMaxFrame
}
}
if (*Tsqlite3rbu)(unsafe.Pointer(p)).Frc == SQLITE_OK {
(*Tsqlite3rbu)(unsafe.Pointer(p)).FeStage = int32(RBU_STAGE_DONE)
(*Tsqlite3rbu)(unsafe.Pointer(p)).Frc = int32(SQLITE_DONE)
}
} else {
for cond := true; cond; cond = (*Tsqlite3rbu)(unsafe.Pointer(p)).FnStep < (*Tsqlite3rbu)(unsafe.Pointer(p)).FnFrame && iSector == ((**(**TRbuFrame)(__ccgo_up((*Tsqlite3rbu)(unsafe.Pointer(p)).FaFrame + uintptr((*Tsqlite3rbu)(unsafe.Pointer(p)).FnStep)*8))).FiDbPage-uint32(1))/libc.Uint32FromInt32((*Tsqlite3rbu)(unsafe.Pointer(p)).FnPagePerSector) && (*Tsqlite3rbu)(unsafe.Pointer(p)).Frc == SQLITE_OK {
pFrame = (*Tsqlite3rbu)(unsafe.Pointer(p)).FaFrame + uintptr((*Tsqlite3rbu)(unsafe.Pointer(p)).FnStep)*8
iSector = ((*TRbuFrame)(unsafe.Pointer(pFrame)).FiDbPage - uint32(1)) / libc.Uint32FromInt32((*Tsqlite3rbu)(unsafe.Pointer(p)).FnPagePerSector)
_rbuCheckpointFrame(tls, p, pFrame)
(*Tsqlite3rbu)(unsafe.Pointer(p)).FnStep = (*Tsqlite3rbu)(unsafe.Pointer(p)).FnStep + 1
}
}
(*Tsqlite3rbu)(unsafe.Pointer(p)).FnProgress = (*Tsqlite3rbu)(unsafe.Pointer(p)).FnProgress + 1
}
default:
break
}
return (*Tsqlite3rbu)(unsafe.Pointer(p)).Frc
} else {
return int32(SQLITE_NOMEM)
}
return r
}
// C documentation
//
// /*
// ** Open a handle to begin or resume an RBU VACUUM operation.
// */
func Xsqlite3rbu_vacuum(tls *libc.TLS, zTarget uintptr, zState uintptr) (r uintptr) {
var n Tsize_t
_ = n
if zTarget == uintptr(0) {
return _rbuMisuseError(tls)
}
if zState != 0 {
n = libc.Xstrlen(tls, zState)
if n >= uint64(7) && 0 == libc.Xmemcmp(tls, __ccgo_ts+35067, zState+uintptr(n-uint64(7)), uint64(7)) {
return _rbuMisuseError(tls)
}
}
/* TODO: Check that both arguments are non-NULL */
return _openRbuHandle(tls, uintptr(0), zTarget, zState)
}
// C documentation
//
// /*
// ** Create a new rebaser object.
// */
func Xsqlite3rebaser_create(tls *libc.TLS, ppNew uintptr) (r int32) {
var pNew uintptr
var rc int32
_, _ = pNew, rc
rc = SQLITE_OK
pNew = Xsqlite3_malloc(tls, int32(96))
if pNew == uintptr(0) {
rc = int32(SQLITE_NOMEM)
} else {
libc.X__builtin___memset_chk(tls, pNew, 0, uint64(96), ^t__predefined_size_t(0))
}
**(**uintptr)(__ccgo_up(ppNew)) = pNew
return rc
}
// C documentation
//
// /*
// ** Attach a table to a session. All subsequent changes made to the table
// ** while the session object is enabled will be recorded.
// **
// ** Only tables that have a PRIMARY KEY defined may be attached. It does
// ** not matter if the PRIMARY KEY is an "INTEGER PRIMARY KEY" (rowid alias)
// ** or not.
// */
func Xsqlite3session_attach(tls *libc.TLS, pSession uintptr, zName uintptr) (r int32) {
var nByte, nName, rc int32
var pTab, ppTab uintptr
_, _, _, _, _ = nByte, nName, pTab, ppTab, rc
rc = SQLITE_OK
Xsqlite3_mutex_enter(tls, Xsqlite3_db_mutex(tls, (*Tsqlite3_session)(unsafe.Pointer(pSession)).Fdb))
if !(zName != 0) {
(*Tsqlite3_session)(unsafe.Pointer(pSession)).FbAutoAttach = int32(1)
} else { /* Number of bytes in string zName */
/* First search for an existing entry. If one is found, this call is
** a no-op. Return early. */
nName = _sqlite3Strlen30(tls, zName)
pTab = (*Tsqlite3_session)(unsafe.Pointer(pSession)).FpTable
for {
if !(pTab != 0) {
break
}
if 0 == Xsqlite3_strnicmp(tls, (*TSessionTable)(unsafe.Pointer(pTab)).FzName, zName, nName+int32(1)) {
break
}
goto _1
_1:
;
pTab = (*TSessionTable)(unsafe.Pointer(pTab)).FpNext
}
if !(pTab != 0) {
/* Allocate new SessionTable object. */
nByte = libc.Int32FromUint64(uint64(88) + libc.Uint64FromInt32(nName) + uint64(1))
pTab = _sessionMalloc64(tls, pSession, int64(nByte))
if !(pTab != 0) {
rc = int32(SQLITE_NOMEM)
} else {
libc.X__builtin___memset_chk(tls, pTab, 0, uint64(88), ^t__predefined_size_t(0))
(*TSessionTable)(unsafe.Pointer(pTab)).FzName = pTab + 1*88
libc.X__builtin___memcpy_chk(tls, (*TSessionTable)(unsafe.Pointer(pTab)).FzName, zName, libc.Uint64FromInt32(nName+int32(1)), ^t__predefined_size_t(0))
ppTab = pSession + 88
for {
if !(**(**uintptr)(__ccgo_up(ppTab)) != 0) {
break
}
goto _2
_2:
;
ppTab = **(**uintptr)(__ccgo_up(ppTab))
}
**(**uintptr)(__ccgo_up(ppTab)) = pTab
}
}
}
Xsqlite3_mutex_leave(tls, Xsqlite3_db_mutex(tls, (*Tsqlite3_session)(unsafe.Pointer(pSession)).Fdb))
return rc
}
// C documentation
//
// /*
// ** Create a session object. This session object will record changes to
// ** database zDb attached to connection db.
// */
func Xsqlite3session_create(tls *libc.TLS, db uintptr, zDb uintptr, ppSession uintptr) (r int32) {
var nDb int32
var pNew, pOld uintptr
_, _, _ = nDb, pNew, pOld /* Session object already attached to db */
nDb = _sqlite3Strlen30(tls, zDb) /* Length of zDb in bytes */
/* Zero the output value in case an error occurs. */
**(**uintptr)(__ccgo_up(ppSession)) = uintptr(0)
/* Allocate and populate the new session object. */
pNew = Xsqlite3_malloc64(tls, uint64(uint64(136)+libc.Uint64FromInt32(nDb)+uint64(1)))
if !(pNew != 0) {
return int32(SQLITE_NOMEM)
}
libc.X__builtin___memset_chk(tls, pNew, 0, uint64(136), ^t__predefined_size_t(0))
(*Tsqlite3_session)(unsafe.Pointer(pNew)).Fdb = db
(*Tsqlite3_session)(unsafe.Pointer(pNew)).FzDb = pNew + 1*136
(*Tsqlite3_session)(unsafe.Pointer(pNew)).FbEnable = int32(1)
libc.X__builtin___memcpy_chk(tls, (*Tsqlite3_session)(unsafe.Pointer(pNew)).FzDb, zDb, libc.Uint64FromInt32(nDb+int32(1)), ^t__predefined_size_t(0))
_sessionPreupdateHooks(tls, pNew)
/* Add the new session object to the linked list of session objects
** attached to database handle $db. Do this under the cover of the db
** handle mutex. */
Xsqlite3_mutex_enter(tls, Xsqlite3_db_mutex(tls, db))
pOld = Xsqlite3_preupdate_hook(tls, db, __ccgo_fp(_xPreUpdate), pNew)
(*Tsqlite3_session)(unsafe.Pointer(pNew)).FpNext = pOld
Xsqlite3_mutex_leave(tls, Xsqlite3_db_mutex(tls, db))
**(**uintptr)(__ccgo_up(ppSession)) = pNew
return SQLITE_OK
}
func Xsqlite3session_diff(tls *libc.TLS, pSession uintptr, zFrom uintptr, zTbl uintptr, pzErrMsg uintptr) (r int32) {
bp := tls.Alloc(80)
defer tls.Free(80)
var bHasPk, bMismatch, i, rc int32
var db, zDb, zDbExists, zExpr, v1 uintptr
var _ /* abPK at bp+32 */ uintptr
var _ /* azCol at bp+40 */ uintptr
var _ /* bRowid at bp+28 */ int32
var _ /* d at bp+0 */ TSessionDiffCtx
var _ /* nCol at bp+24 */ int32
var _ /* pDbExists at bp+48 */ uintptr
var _ /* pTo at bp+16 */ uintptr
_, _, _, _, _, _, _, _, _ = bHasPk, bMismatch, db, i, rc, zDb, zDbExists, zExpr, v1
zDb = (*Tsqlite3_session)(unsafe.Pointer(pSession)).FzDb
rc = (*Tsqlite3_session)(unsafe.Pointer(pSession)).Frc
libc.X__builtin___memset_chk(tls, bp, 0, uint64(16), ^t__predefined_size_t(0))
_sessionDiffHooks(tls, pSession, bp)
Xsqlite3_mutex_enter(tls, Xsqlite3_db_mutex(tls, (*Tsqlite3_session)(unsafe.Pointer(pSession)).Fdb))
if pzErrMsg != 0 {
**(**uintptr)(__ccgo_up(pzErrMsg)) = uintptr(0)
}
if rc == SQLITE_OK {
zExpr = uintptr(0)
db = (*Tsqlite3_session)(unsafe.Pointer(pSession)).Fdb /* Table zTbl */
/* Locate and if necessary initialize the target table object */
(*Tsqlite3_session)(unsafe.Pointer(pSession)).FbAutoAttach = (*Tsqlite3_session)(unsafe.Pointer(pSession)).FbAutoAttach + 1
rc = _sessionFindTable(tls, pSession, zTbl, bp+16)
(*Tsqlite3_session)(unsafe.Pointer(pSession)).FbAutoAttach = (*Tsqlite3_session)(unsafe.Pointer(pSession)).FbAutoAttach - 1
if **(**uintptr)(__ccgo_up(bp + 16)) == uintptr(0) {
goto diff_out
}
if _sessionInitTable(tls, pSession, **(**uintptr)(__ccgo_up(bp + 16)), (*Tsqlite3_session)(unsafe.Pointer(pSession)).Fdb, (*Tsqlite3_session)(unsafe.Pointer(pSession)).FzDb) != 0 {
rc = (*Tsqlite3_session)(unsafe.Pointer(pSession)).Frc
goto diff_out
}
/* Check the table schemas match */
if rc == SQLITE_OK {
bHasPk = 0
bMismatch = 0
**(**int32)(__ccgo_up(bp + 24)) = 0 /* Columns in zFrom.zTbl */
**(**int32)(__ccgo_up(bp + 28)) = 0
**(**uintptr)(__ccgo_up(bp + 32)) = uintptr(0)
**(**uintptr)(__ccgo_up(bp + 40)) = uintptr(0)
zDbExists = uintptr(0)
/* Check that database zFrom is attached. */
zDbExists = Xsqlite3_mprintf(tls, __ccgo_ts+35996, libc.VaList(bp+64, zFrom))
if zDbExists == uintptr(0) {
rc = int32(SQLITE_NOMEM)
} else {
**(**uintptr)(__ccgo_up(bp + 48)) = uintptr(0)
rc = Xsqlite3_prepare_v2(tls, db, zDbExists, -int32(1), bp+48, uintptr(0))
if rc == int32(SQLITE_ERROR) {
rc = SQLITE_OK
**(**int32)(__ccgo_up(bp + 24)) = -int32(1)
}
Xsqlite3_finalize(tls, **(**uintptr)(__ccgo_up(bp + 48)))
Xsqlite3_free(tls, zDbExists)
}
if rc == SQLITE_OK && **(**int32)(__ccgo_up(bp + 24)) == 0 {
if (*Tsqlite3_session)(unsafe.Pointer(pSession)).FbImplicitPK != 0 {
v1 = bp + 28
} else {
v1 = uintptr(0)
}
rc = _sessionTableInfo(tls, uintptr(0), db, zFrom, zTbl, bp+24, uintptr(0), uintptr(0), bp+40, uintptr(0), uintptr(0), bp+32, v1)
}
if rc == SQLITE_OK {
if (*TSessionTable)(unsafe.Pointer(**(**uintptr)(__ccgo_up(bp + 16)))).FnCol != **(**int32)(__ccgo_up(bp + 24)) {
if **(**int32)(__ccgo_up(bp + 24)) <= 0 {
rc = int32(SQLITE_SCHEMA)
if pzErrMsg != 0 {
**(**uintptr)(__ccgo_up(pzErrMsg)) = Xsqlite3_mprintf(tls, __ccgo_ts+36027, libc.VaList(bp+64, zFrom, zTbl))
}
} else {
bMismatch = int32(1)
}
} else {
i = 0
for {
if !(i < **(**int32)(__ccgo_up(bp + 24))) {
break
}
if libc.Int32FromUint8(**(**Tu8)(__ccgo_up((*TSessionTable)(unsafe.Pointer(**(**uintptr)(__ccgo_up(bp + 16)))).FabPK + uintptr(i)))) != libc.Int32FromUint8(**(**Tu8)(__ccgo_up(**(**uintptr)(__ccgo_up(bp + 32)) + uintptr(i)))) {
bMismatch = int32(1)
}
if Xsqlite3_stricmp(tls, **(**uintptr)(__ccgo_up(**(**uintptr)(__ccgo_up(bp + 40)) + uintptr(i)*8)), **(**uintptr)(__ccgo_up((*TSessionTable)(unsafe.Pointer(**(**uintptr)(__ccgo_up(bp + 16)))).FazCol + uintptr(i)*8))) != 0 {
bMismatch = int32(1)
}
if **(**Tu8)(__ccgo_up(**(**uintptr)(__ccgo_up(bp + 32)) + uintptr(i))) != 0 {
bHasPk = int32(1)
}
goto _2
_2:
;
i = i + 1
}
}
}
Xsqlite3_free(tls, **(**uintptr)(__ccgo_up(bp + 40)))
if bMismatch != 0 {
if pzErrMsg != 0 {
**(**uintptr)(__ccgo_up(pzErrMsg)) = Xsqlite3_mprintf(tls, __ccgo_ts+36048, 0)
}
rc = int32(SQLITE_SCHEMA)
}
if bHasPk == 0 {
/* Ignore tables with no primary keys */
goto diff_out
}
}
if rc == SQLITE_OK {
zExpr = _sessionExprComparePK(tls, (*TSessionTable)(unsafe.Pointer(**(**uintptr)(__ccgo_up(bp + 16)))).FnCol, zDb, zFrom, (*TSessionTable)(unsafe.Pointer(**(**uintptr)(__ccgo_up(bp + 16)))).FzName, (*TSessionTable)(unsafe.Pointer(**(**uintptr)(__ccgo_up(bp + 16)))).FazCol, (*TSessionTable)(unsafe.Pointer(**(**uintptr)(__ccgo_up(bp + 16)))).FabPK)
}
/* Find new rows */
if rc == SQLITE_OK {
rc = _sessionDiffFindNew(tls, int32(SQLITE_INSERT), pSession, **(**uintptr)(__ccgo_up(bp + 16)), zDb, zFrom, zExpr)
}
/* Find old rows */
if rc == SQLITE_OK {
rc = _sessionDiffFindNew(tls, int32(SQLITE_DELETE), pSession, **(**uintptr)(__ccgo_up(bp + 16)), zFrom, zDb, zExpr)
}
/* Find modified rows */
if rc == SQLITE_OK {
rc = _sessionDiffFindModified(tls, pSession, **(**uintptr)(__ccgo_up(bp + 16)), zFrom, zExpr)
}
Xsqlite3_free(tls, zExpr)
}
goto diff_out
diff_out:
;
_sessionPreupdateHooks(tls, pSession)
Xsqlite3_mutex_leave(tls, Xsqlite3_db_mutex(tls, (*Tsqlite3_session)(unsafe.Pointer(pSession)).Fdb))
return rc
}
const _ACCESS_EXTENDED_MASK = 4193792
const _APPEND_OK = 8192
const _AU_SESSION_FLAG_HAS_AUTHENTICATED = 16384
const _AU_SESSION_FLAG_HAS_CONSOLE_ACCESS = 8192
const _AU_SESSION_FLAG_HAS_GRAPHIC_ACCESS = 16
const _AU_SESSION_FLAG_HAS_TTY = 32
const _AU_SESSION_FLAG_IS_INITIAL = 1
const _AU_SESSION_FLAG_IS_REMOTE = 4096
const _CHOWN_OK = 2097152
const _CRYPTEX1_AUTH_ENV_GENERIC = 4
const _CRYPTEX1_AUTH_ENV_GENERIC_SUPPLEMENTAL = 5
const _CRYPTEX_AUTH_MAX = 9
/*
** Allowed values of unixFile.fsFlags
*/
/*
** If we are to be thread-safe, include the pthreads header.
*/
/* # include */
/*
** Default permissions when creating a new file
*/
/*
** Default permissions when creating auto proxy dir
*/
/*
** Maximum supported path-length.
*/
/*
** Maximum supported symbolic links
*/
/*
** Remove and stub certain info for WASI (WebAssembly System
** Interface) builds.
*/
/* Always cast the getpid() return type for compatibility with
** kernel modules in VxWorks. */
/*
** Only set the lastErrno if the error code is a real error and not
** a normal expected return code of SQLITE_BUSY or SQLITE_OK
*/
const _CRYPTEX_AUTH_MOBILE_ASSET = 8
const _CRYPTEX_AUTH_MOBILE_ASSET_WITH_CODE = 9
const _CRYPTEX_AUTH_PDI_NONCE = 6
const _CS_DARWIN_USER_CACHE_DIR = 65538
const _CS_DARWIN_USER_DIR = 65536
const _CS_DARWIN_USER_TEMP_DIR = 65537
const _CS_XBS5_ILP32_OFF32_CFLAGS = 20
const _CS_XBS5_ILP32_OFF32_LDFLAGS = 21
const _CS_XBS5_ILP32_OFF32_LIBS = 22
const _CS_XBS5_ILP32_OFF32_LINTFLAGS = 23
const _CS_XBS5_ILP32_OFFBIG_CFLAGS = 24
const _CS_XBS5_ILP32_OFFBIG_LDFLAGS = 25
const _CS_XBS5_ILP32_OFFBIG_LIBS = 26
const _CS_XBS5_ILP32_OFFBIG_LINTFLAGS = 27
const _CS_XBS5_LP64_OFF64_CFLAGS = 28
const _CS_XBS5_LP64_OFF64_LDFLAGS = 29
const _CS_XBS5_LP64_OFF64_LIBS = 30
const _CS_XBS5_LP64_OFF64_LINTFLAGS = 31
const _CS_XBS5_LPBIG_OFFBIG_CFLAGS = 32
const _CS_XBS5_LPBIG_OFFBIG_LDFLAGS = 33
const _CS_XBS5_LPBIG_OFFBIG_LIBS = 34
const _CS_XBS5_LPBIG_OFFBIG_LINTFLAGS = 35
const _DARWIN_FEATURE_64_BIT_INODE = 1
const _DARWIN_FEATURE_ONLY_UNIX_CONFORMANCE = 1
const _DARWIN_FEATURE_UNIX_CONFORMANCE = 3
const _DELETE_OK = 4096
const _EXECUTE_OK = 2048
const _FILESEC_ACL = 5
const _FILESEC_ACL_ALLOCSIZE = 101
const _FILESEC_ACL_RAW = 100
const _FILESEC_GROUP = 2
const _FILESEC_GRPUUID = 6
const _FILESEC_MODE = 4
const _FILESEC_OWNER = 1
const _FILESEC_UUID = 3
const _FORTIFY_SOURCE = 2
const _GRAFTDMG_CRYPTEX_AUTH_ENV_GENERIC = 4
const _GRAFTDMG_CRYPTEX_BOOT = 1
const _GRAFTDMG_CRYPTEX_DOWNLEVEL = 3
const _GRAFTDMG_CRYPTEX_EFFECTIVE_AP = 7
const _GRAFTDMG_CRYPTEX_MAX = 9
const _GRAFTDMG_CRYPTEX_MOBILE_ASSET = 8
const _GRAFTDMG_CRYPTEX_MOBILE_ASSET_WITH_CODE = 9
const _GRAFTDMG_CRYPTEX_PDI_NONCE = 6
const _GRAFTDMG_CRYPTEX_PREBOOT = 2
const _HAS_BUILTIN_AVAILABLE_FEATS = 1
const _LIBC_COUNT__MB_LEN_MAX = 0
const _LIBC_COUNT__PATH_MAX = 0
const _MALLOC_TYPE_MALLOC_BACKDEPLOY_PUBLIC = 1
const _MPO_CONNECTION_PORT = 2048
const _MPO_CONNECTION_PORT_WITH_PORT_ARRAY = 65536
const _MPO_EXCEPTION_PORT = 32768
const _MPO_NOTIFICATION_PORT = 17408
const _MPO_PORT = 0
const _MPO_REPLY_PORT = 4096
const _MPO_SERVICE_PORT = 1024
const _MPO_WEAK_REPLY_PORT = 16384
const _PC_2_SYMLINKS = 15
const _PC_ALLOC_SIZE_MIN = 16
const _PC_ASYNC_IO = 17
const _PC_AUTH_OPAQUE_NP = 14
const _PC_CASE_PRESERVING = 12
const _PC_CASE_SENSITIVE = 11
const _PC_EXTENDED_SECURITY_NP = 13
const _PC_FILESIZEBITS = 18
const _PC_MIN_HOLE_SIZE = 27
const _PC_NAME_CHARS_MAX = 10
const _PC_PRIO_IO = 19
const _PC_REC_INCR_XFER_SIZE = 20
const _PC_REC_MAX_XFER_SIZE = 21
const _PC_REC_MIN_XFER_SIZE = 22
const _PC_REC_XFER_ALIGN = 23
const _PC_SYMLINK_MAX = 24
const _PC_SYNC_IO = 25
const _PC_XATTR_SIZE_BITS = 26
const _POSIX2_CHAR_TERM = 200112
const _POSIX2_C_DEV = 200112
const _POSIX2_LOCALEDEF = 200112
const _POSIX_BARRIERS = -1
const _POSIX_CHOWN_RESTRICTED = 200112
const _POSIX_CPUTIME = -1
const _POSIX_IPV6 = 200112
const _POSIX_JOB_CONTROL = 200112
const _POSIX_MEMLOCK_RANGE = -1
const _POSIX_MONOTONIC_CLOCK = -1
const _POSIX_NO_TRUNC = 200112
const _POSIX_RAW_SOCKETS = -1
const _POSIX_REGEXP = 200112
const _POSIX_SAVED_IDS = 200112
const _POSIX_SEMAPHORES = -1
const _POSIX_SHARED_MEMORY_OBJECTS = -1
const _POSIX_SHELL = 200112
const _POSIX_SPIN_LOCKS = -1
const _POSIX_THREAD_CPUTIME = -1
const _POSIX_TIMEOUTS = -1
const _POSIX_V6_ILP32_OFFBIG = -1
const _POSIX_V6_LPBIG_OFFBIG = 1
const _POSIX_V7_ILP32_OFFBIG = -1
const _POSIX_V7_LPBIG_OFFBIG = 1
const _P_PGID = 2
const _RATTR_OK = 32768
const _READ_OK = 512
const _REXT_OK = 131072
const _RLIMIT_POSIX_FLAG = 4096
const _RMFILE_OK = 16384
const _RPERM_OK = 524288
const _RUNE_MAGIC_A = "RuneMagA"
type _RuneCharClass = T_RuneCharClass
type _RuneLocale = T_RuneLocale
/*
** Use a macro to replace memcpy() if compiled with SQLITE_INLINE_MEMCPY.
** This allows better measurements of where memcpy() is used when running
** cachegrind. But this macro version of memcpy() is very slow so it
** should not be used in production. This is a performance measurement
** hack only.
*/
/*
** If compiling for a processor that lacks floating point support,
** substitute integer for floating-point
*/
/*
** OMIT_TEMPDB is set to 1 if SQLITE_OMIT_TEMPDB is defined, or 0
** afterward. Having this macro allows us to cause the C compiler
** to omit code used by TEMP tables without messy #ifndef statements.
*/
/*
** The "file format" number is an integer that is incremented whenever
** the VDBE-level file format changes. The following macros define the
** the default file format for new databases and the maximum file format
** that the library can read.
*/
/*
** Determine whether triggers are recursive by default. This can be
** changed at run-time using a pragma.
*/
/*
** Provide a default value for SQLITE_TEMP_STORE in case it is not specified
** on the command-line
*/
/*
** If no value has been provided for SQLITE_MAX_WORKER_THREADS, or if
** SQLITE_TEMP_STORE is set to 3 (never use temporary files), set it
** to zero.
*/
/*
** The default initial allocation for the pagecache when using separate
** pagecaches for each database connection. A positive number is the
** number of pages. A negative number N translations means that a buffer
** of -1024*N bytes is allocated and used for as many pages as it will hold.
**
** The default value of "20" was chosen to minimize the run-time of the
** speedtest1 test program with options: --shrink-memory --reprepare
*/
/*
** Default value for the SQLITE_CONFIG_SORTERREF_SIZE option.
*/
/*
** The compile-time options SQLITE_MMAP_READWRITE and
** SQLITE_ENABLE_BATCH_ATOMIC_WRITE are not compatible with one another.
** You must choose one or the other (or neither) but not both.
*/
/*
** GCC does not define the offsetof() macro so we'll have to do it
** ourselves.
*/
/*
** sizeof64() is like sizeof(), but always returns a 64-bit value, even
** on 32-bit builds. This can help to avoid overflow by ensuring 64-bit
** arithmetic is used consistently in both 32-bit and 64-bit builds.
*/
/*
** Work around C99 "flex-array" syntax for pre-C99 compilers, so as
** to avoid complaints from -fsanitize=strict-bounds.
*/
/*
** Macros to compute minimum and maximum of two numbers.
*/
/*
** Swap two objects of type TYPE.
*/
/*
** Check to see if this machine uses EBCDIC. (Yes, believe it or
** not, there are still machines out there that use EBCDIC.)
*/
const _SC_MAPPED_FILES = 47
const _SC_PAGESIZE = 29
const _SC_PAGE_SIZE = 29
const _SC_PASS_MAX = 131
const _SC_PHYS_PAGES = 200
const _SC_SS_REPL_MAX = 126
const _SC_TRACE_EVENT_NAME_MAX = 127
const _SC_TRACE_NAME_MAX = 128
const _SC_TRACE_SYS_MAX = 129
const _SC_TRACE_USER_EVENT_MAX = 130
const _SC_XBS5_ILP32_OFF32 = 122
const _SC_XBS5_ILP32_OFFBIG = 123
const _SC_XBS5_LP64_OFF64 = 124
const _SC_XBS5_LPBIG_OFFBIG = 125
const _SC_XOPEN_XCU_VERSION = 121
const _SS_ALIGNSIZE = 0
const _SS_MAXSIZE = 128
const _SS_PAD1SIZE = 0
const _SS_PAD2SIZE = 128
const _STRUCT_MCONTEXT = "_STRUCT_MCONTEXT64"
// C documentation
//
// /*
// ** Arguments aIdx, aCell and aSpare all point to arrays of size
// ** nIdx. The aIdx array contains the set of integers from 0 to
// ** (nIdx-1) in no particular order. This function sorts the values
// ** in aIdx according to dimension iDim of the cells in aCell. The
// ** minimum value of dimension iDim is considered first, the
// ** maximum used to break ties.
// **
// ** The aSpare array is used as temporary working space by the
// ** sorting algorithm.
// */
func _SortByDimension(tls *libc.TLS, pRtree uintptr, aIdx uintptr, nIdx int32, iDim int32, aCell uintptr, aSpare uintptr) {
var aLeft, aRight uintptr
var iLeft, iRight, nLeft, nRight int32
var xleft1, xleft2, xright1, xright2 TRtreeDValue
var v1, v2, v3, v4 float64
_, _, _, _, _, _, _, _, _, _, _, _, _, _ = aLeft, aRight, iLeft, iRight, nLeft, nRight, xleft1, xleft2, xright1, xright2, v1, v2, v3, v4
if nIdx > int32(1) {
iLeft = 0
iRight = 0
nLeft = nIdx / int32(2)
nRight = nIdx - nLeft
aLeft = aIdx
aRight = aIdx + uintptr(nLeft)*4
_SortByDimension(tls, pRtree, aLeft, nLeft, iDim, aCell, aSpare)
_SortByDimension(tls, pRtree, aRight, nRight, iDim, aCell, aSpare)
libc.X__builtin___memcpy_chk(tls, aSpare, aLeft, uint64(4)*libc.Uint64FromInt32(nLeft), ^t__predefined_size_t(0))
aLeft = aSpare
for iLeft < nLeft || iRight < nRight {
if libc.Int32FromUint8((*TRtree)(unsafe.Pointer(pRtree)).FeCoordType) == RTREE_COORD_REAL32 {
v1 = float64(*(*TRtreeValue)(unsafe.Pointer(aCell + uintptr(**(**int32)(__ccgo_up(aLeft + uintptr(iLeft)*4)))*48 + 8 + uintptr(iDim*int32(2))*4)))
} else {
v1 = float64(*(*int32)(unsafe.Pointer(aCell + uintptr(**(**int32)(__ccgo_up(aLeft + uintptr(iLeft)*4)))*48 + 8 + uintptr(iDim*int32(2))*4)))
}
xleft1 = v1
if libc.Int32FromUint8((*TRtree)(unsafe.Pointer(pRtree)).FeCoordType) == RTREE_COORD_REAL32 {
v2 = float64(*(*TRtreeValue)(unsafe.Pointer(aCell + uintptr(**(**int32)(__ccgo_up(aLeft + uintptr(iLeft)*4)))*48 + 8 + uintptr(iDim*int32(2)+int32(1))*4)))
} else {
v2 = float64(*(*int32)(unsafe.Pointer(aCell + uintptr(**(**int32)(__ccgo_up(aLeft + uintptr(iLeft)*4)))*48 + 8 + uintptr(iDim*int32(2)+int32(1))*4)))
}
xleft2 = v2
if libc.Int32FromUint8((*TRtree)(unsafe.Pointer(pRtree)).FeCoordType) == RTREE_COORD_REAL32 {
v3 = float64(*(*TRtreeValue)(unsafe.Pointer(aCell + uintptr(**(**int32)(__ccgo_up(aRight + uintptr(iRight)*4)))*48 + 8 + uintptr(iDim*int32(2))*4)))
} else {
v3 = float64(*(*int32)(unsafe.Pointer(aCell + uintptr(**(**int32)(__ccgo_up(aRight + uintptr(iRight)*4)))*48 + 8 + uintptr(iDim*int32(2))*4)))
}
xright1 = v3
if libc.Int32FromUint8((*TRtree)(unsafe.Pointer(pRtree)).FeCoordType) == RTREE_COORD_REAL32 {
v4 = float64(*(*TRtreeValue)(unsafe.Pointer(aCell + uintptr(**(**int32)(__ccgo_up(aRight + uintptr(iRight)*4)))*48 + 8 + uintptr(iDim*int32(2)+int32(1))*4)))
} else {
v4 = float64(*(*int32)(unsafe.Pointer(aCell + uintptr(**(**int32)(__ccgo_up(aRight + uintptr(iRight)*4)))*48 + 8 + uintptr(iDim*int32(2)+int32(1))*4)))
}
xright2 = v4
if iLeft != nLeft && (iRight == nRight || xleft1 < xright1 || xleft1 == xright1 && xleft2 < xright2) {
**(**int32)(__ccgo_up(aIdx + uintptr(iLeft+iRight)*4)) = **(**int32)(__ccgo_up(aLeft + uintptr(iLeft)*4))
iLeft = iLeft + 1
} else {
**(**int32)(__ccgo_up(aIdx + uintptr(iLeft+iRight)*4)) = **(**int32)(__ccgo_up(aRight + uintptr(iRight)*4))
iRight = iRight + 1
}
}
}
}
func _SplitNode(tls *libc.TLS, pRtree uintptr, pNode uintptr, pCell uintptr, iHeight int32) (r int32) {
bp := tls.Alloc(112)
defer tls.Free(112)
var aCell, aiUsed, pLeft, pParent, pRight uintptr
var i, nCell, newCellIsRight, rc, v2, v3 int32
var iRowid, iRowid1 Ti64
var v4, v5 bool
var _ /* iCell at bp+96 */ int32
var _ /* leftbbox at bp+0 */ TRtreeCell
var _ /* rightbbox at bp+48 */ TRtreeCell
_, _, _, _, _, _, _, _, _, _, _, _, _, _, _ = aCell, aiUsed, i, iRowid, iRowid1, nCell, newCellIsRight, pLeft, pParent, pRight, rc, v2, v3, v4, v5
newCellIsRight = 0
rc = SQLITE_OK
nCell = _readInt16(tls, (*TRtreeNode)(unsafe.Pointer(pNode)).FzData+2)
pLeft = uintptr(0)
pRight = uintptr(0)
/* Allocate an array and populate it with a copy of pCell and
** all cells from node pLeft. Then zero the original node.
*/
aCell = Xsqlite3_malloc64(tls, uint64((libc.Uint64FromInt64(48)+libc.Uint64FromInt64(4))*libc.Uint64FromInt32(nCell+libc.Int32FromInt32(1))))
if !(aCell != 0) {
rc = int32(SQLITE_NOMEM)
goto splitnode_out
}
aiUsed = aCell + uintptr(nCell+int32(1))*48
libc.X__builtin___memset_chk(tls, aiUsed, 0, uint64(4)*libc.Uint64FromInt32(nCell+libc.Int32FromInt32(1)), ^t__predefined_size_t(0))
i = 0
for {
if !(i < nCell) {
break
}
_nodeGetCell(tls, pRtree, pNode, i, aCell+uintptr(i)*48)
goto _1
_1:
;
i = i + 1
}
_nodeZero(tls, pRtree, pNode)
libc.X__builtin___memcpy_chk(tls, aCell+uintptr(nCell)*48, pCell, uint64(48), ^t__predefined_size_t(0))
nCell = nCell + 1
if (*TRtreeNode)(unsafe.Pointer(pNode)).FiNode == int64(1) {
pRight = _nodeNew(tls, pRtree, pNode)
pLeft = _nodeNew(tls, pRtree, pNode)
(*TRtree)(unsafe.Pointer(pRtree)).FiDepth = (*TRtree)(unsafe.Pointer(pRtree)).FiDepth + 1
(*TRtreeNode)(unsafe.Pointer(pNode)).FisDirty = int32(1)
_writeInt16(tls, (*TRtreeNode)(unsafe.Pointer(pNode)).FzData, (*TRtree)(unsafe.Pointer(pRtree)).FiDepth)
} else {
pLeft = pNode
pRight = _nodeNew(tls, pRtree, (*TRtreeNode)(unsafe.Pointer(pLeft)).FpParent)
(*TRtreeNode)(unsafe.Pointer(pLeft)).FnRef = (*TRtreeNode)(unsafe.Pointer(pLeft)).FnRef + 1
}
if !(pLeft != 0) || !(pRight != 0) {
rc = int32(SQLITE_NOMEM)
goto splitnode_out
}
libc.X__builtin___memset_chk(tls, (*TRtreeNode)(unsafe.Pointer(pLeft)).FzData, 0, libc.Uint64FromInt32((*TRtree)(unsafe.Pointer(pRtree)).FiNodeSize), ^t__predefined_size_t(0))
libc.X__builtin___memset_chk(tls, (*TRtreeNode)(unsafe.Pointer(pRight)).FzData, 0, libc.Uint64FromInt32((*TRtree)(unsafe.Pointer(pRtree)).FiNodeSize), ^t__predefined_size_t(0))
rc = _splitNodeStartree(tls, pRtree, aCell, nCell, pLeft, pRight, bp, bp+48)
if rc != SQLITE_OK {
goto splitnode_out
}
/* Ensure both child nodes have node numbers assigned to them by calling
** nodeWrite(). Node pRight always needs a node number, as it was created
** by nodeNew() above. But node pLeft sometimes already has a node number.
** In this case avoid the all to nodeWrite().
*/
v2 = _nodeWrite(tls, pRtree, pRight)
rc = v2
if v5 = SQLITE_OK != v2; !v5 {
if v4 = 0 == (*TRtreeNode)(unsafe.Pointer(pLeft)).FiNode; v4 {
v3 = _nodeWrite(tls, pRtree, pLeft)
rc = v3
}
}
if v5 || v4 && SQLITE_OK != v3 {
goto splitnode_out
}
(**(**TRtreeCell)(__ccgo_up(bp + 48))).FiRowid = (*TRtreeNode)(unsafe.Pointer(pRight)).FiNode
(**(**TRtreeCell)(__ccgo_up(bp))).FiRowid = (*TRtreeNode)(unsafe.Pointer(pLeft)).FiNode
if (*TRtreeNode)(unsafe.Pointer(pNode)).FiNode == int64(1) {
rc = _rtreeInsertCell(tls, pRtree, (*TRtreeNode)(unsafe.Pointer(pLeft)).FpParent, bp, iHeight+int32(1))
if rc != SQLITE_OK {
goto splitnode_out
}
} else {
pParent = (*TRtreeNode)(unsafe.Pointer(pLeft)).FpParent
rc = _nodeParentIndex(tls, pRtree, pLeft, bp+96)
if rc == SQLITE_OK {
_nodeOverwriteCell(tls, pRtree, pParent, bp, **(**int32)(__ccgo_up(bp + 96)))
rc = _AdjustTree(tls, pRtree, pParent, bp)
}
if rc != SQLITE_OK {
goto splitnode_out
}
}
v2 = _rtreeInsertCell(tls, pRtree, (*TRtreeNode)(unsafe.Pointer(pRight)).FpParent, bp+48, iHeight+int32(1))
rc = v2
if v2 != 0 {
goto splitnode_out
}
i = 0
for {
if !(i < _readInt16(tls, (*TRtreeNode)(unsafe.Pointer(pRight)).FzData+2)) {
break
}
iRowid = _nodeGetRowid(tls, pRtree, pRight, i)
rc = _updateMapping(tls, pRtree, iRowid, pRight, iHeight)
if iRowid == (*TRtreeCell)(unsafe.Pointer(pCell)).FiRowid {
newCellIsRight = int32(1)
}
if rc != SQLITE_OK {
goto splitnode_out
}
goto _7
_7:
;
i = i + 1
}
if (*TRtreeNode)(unsafe.Pointer(pNode)).FiNode == int64(1) {
i = 0
for {
if !(i < _readInt16(tls, (*TRtreeNode)(unsafe.Pointer(pLeft)).FzData+2)) {
break
}
iRowid1 = _nodeGetRowid(tls, pRtree, pLeft, i)
rc = _updateMapping(tls, pRtree, iRowid1, pLeft, iHeight)
if rc != SQLITE_OK {
goto splitnode_out
}
goto _8
_8:
;
i = i + 1
}
} else {
if newCellIsRight == 0 {
rc = _updateMapping(tls, pRtree, (*TRtreeCell)(unsafe.Pointer(pCell)).FiRowid, pLeft, iHeight)
}
}
goto splitnode_out
splitnode_out:
;
_nodeRelease(tls, pRtree, pRight)
_nodeRelease(tls, pRtree, pLeft)
Xsqlite3_free(tls, aCell)
return rc
}
const _V6_ILP32_OFFBIG = -1
const _V6_LP64_OFF64 = 1
const _V6_LPBIG_OFFBIG = 1
const _WATTR_OK = 65536
const _WEXT_OK = 262144
const _WPERM_OK = 1048576
const _WRITE_OK = 1024
const _WSTOPPED = 127
const _XBS5_ILP32_OFF32 = -1
const _XBS5_ILP32_OFFBIG = -1
const _XBS5_LP64_OFF64 = 1
const _XBS5_LPBIG_OFFBIG = 1
const _XOPEN_VERSION = 600
const _XOPEN_XCU_VERSION = 4
const __API_TO_BE_DEPRECATED = 100000
const __API_TO_BE_DEPRECATED_DRIVERKIT = 100000
const __API_TO_BE_DEPRECATED_IOS = 100000
const __API_TO_BE_DEPRECATED_IOSAPPLICATIONEXTENSION = 100000
const __API_TO_BE_DEPRECATED_KERNELKIT = 100000
const __API_TO_BE_DEPRECATED_MACCATALYST = 100000
const __API_TO_BE_DEPRECATED_MACCATALYSTAPPLICATIONEXTENSION = 100000
const __API_TO_BE_DEPRECATED_MACOS = 100000
const __API_TO_BE_DEPRECATED_MACOSAPPLICATIONEXTENSION = 100000
const __API_TO_BE_DEPRECATED_TVOS = 100000
const __API_TO_BE_DEPRECATED_TVOSAPPLICATIONEXTENSION = 100000
const __API_TO_BE_DEPRECATED_VISIONOS = 100000
const __API_TO_BE_DEPRECATED_VISIONOSAPPLICATIONEXTENSION = 100000
const __API_TO_BE_DEPRECATED_WATCHOS = 100000
const __API_TO_BE_DEPRECATED_WATCHOSAPPLICATIONEXTENSION = 100000
const __APPLE_CC__ = 6000
const __APPLE__ = 1
const __ASSUME_PTR_ABI_SINGLE_BEGIN = 0
const __ASSUME_PTR_ABI_SINGLE_END = 0
const __AUDIT_API_DEPRECATED = 0
const __AVAILABILITY_FILE = "AvailabilityVersions.h"
const __AVAILABILITY_VERSIONS_VERSION_HASH = 93585900
const __AVAILABILITY_VERSIONS_VERSION_STRING = "Local"
const __BLOCKS__ = 1
const __BOOL_WIDTH__ = 1
const __BRIDGEOS_10_0 = 100000
const __BRIDGEOS_10_1 = 100100
const __BRIDGEOS_10_2 = 100200
const __BRIDGEOS_10_3 = 100300
const __BRIDGEOS_10_4 = 100400
const __BRIDGEOS_26_5 = 260500
const __BRIDGEOS_2_0 = 20000
const __BRIDGEOS_3_0 = 30000
const __BRIDGEOS_3_1 = 30100
const __BRIDGEOS_3_4 = 30400
const __BRIDGEOS_4_0 = 40000
const __BRIDGEOS_4_1 = 40100
const __BRIDGEOS_5_0 = 50000
const __BRIDGEOS_5_1 = 50100
const __BRIDGEOS_5_3 = 50300
const __BRIDGEOS_6_0 = 60000
const __BRIDGEOS_6_2 = 60200
const __BRIDGEOS_6_4 = 60400
const __BRIDGEOS_6_5 = 60500
const __BRIDGEOS_6_6 = 60600
const __BRIDGEOS_7_0 = 70000
const __BRIDGEOS_7_1 = 70100
const __BRIDGEOS_7_2 = 70200
const __BRIDGEOS_7_3 = 70300
const __BRIDGEOS_7_4 = 70400
const __BRIDGEOS_7_6 = 70600
const __BRIDGEOS_8_0 = 80000
const __BRIDGEOS_8_1 = 80100
const __BRIDGEOS_8_2 = 80200
const __BRIDGEOS_8_3 = 80300
const __BRIDGEOS_8_4 = 80400
const __BRIDGEOS_8_5 = 80500
const __BRIDGEOS_8_6 = 80600
const __BRIDGEOS_9_0 = 90000
const __BRIDGEOS_9_1 = 90100
const __BRIDGEOS_9_2 = 90200
const __BRIDGEOS_9_3 = 90300
const __BRIDGEOS_9_4 = 90400
const __BRIDGEOS_9_5 = 90500
const __BRIDGEOS_9_6 = 90600
const __CLOCK_MONOTONIC = 6
const __CLOCK_MONOTONIC_RAW = 4
const __CLOCK_MONOTONIC_RAW_APPROX = 5
const __CLOCK_PROCESS_CPUTIME_ID = 12
const __CLOCK_REALTIME = 0
const __CLOCK_THREAD_CPUTIME_ID = 16
/*
** The MSVC CRT on Windows CE may not have a localtime() function.
** So declare a substitute. The substitute function itself is
** defined in "os_win.c".
*/
const __CLOCK_UPTIME_RAW = 8
const __CLOCK_UPTIME_RAW_APPROX = 9
const __DARWIN_64_BIT_INO_T = 1
const __DARWIN_ALIGNBYTES = -1
const __DARWIN_ALIGNBYTES32 = -1
const __DARWIN_BIG_ENDIAN = 4321
const __DARWIN_BYTE_ORDER = 1234
const __DARWIN_CTYPE_TOP_inline = 0
const __DARWIN_CTYPE_inline = 0
const __DARWIN_C_ANSI = 4096
const __DARWIN_C_FULL = 900000
const __DARWIN_C_LEVEL = 900000
const __DARWIN_FD_SETSIZE = 1024
const __DARWIN_LITTLE_ENDIAN = 1234
const __DARWIN_NBBY = 8
const __DARWIN_NFDBITS = 0
const __DARWIN_NON_CANCELABLE = 0
const __DARWIN_NO_LONG_LONG = 0
const __DARWIN_NSIG = 32
const __DARWIN_ONLY_UNIX_CONFORMANCE = 1
const __DARWIN_PDP_ENDIAN = 3412
const __DARWIN_SUF_EXTSN = "$DARWIN_EXTSN"
const __DARWIN_UNIX03 = 1
const __DARWIN_VERS_1050 = 1
const __DARWIN_WCHAR_MAX = 2147483647
const __DARWIN_WCHAR_MIN = -2147483648
const __DARWIN_WEOF = -1
const __DBL_MIN__ = 2.2250738585072014e-308
const __DRIVERKIT_19_0 = 190000
const __DRIVERKIT_20_0 = 200000
const __DRIVERKIT_21_0 = 210000
const __DRIVERKIT_22_0 = 220000
const __DRIVERKIT_22_4 = 220400
const __DRIVERKIT_22_5 = 220500
const __DRIVERKIT_22_6 = 220600
const __DRIVERKIT_23_0 = 230000
const __DRIVERKIT_23_1 = 230100
const __DRIVERKIT_23_2 = 230200
const __DRIVERKIT_23_3 = 230300
const __DRIVERKIT_23_4 = 230400
const __DRIVERKIT_23_5 = 230500
const __DRIVERKIT_23_6 = 230600
const __DRIVERKIT_24_0 = 240000
const __DRIVERKIT_24_1 = 240100
const __DRIVERKIT_24_2 = 240200
const __DRIVERKIT_24_3 = 240300
const __DRIVERKIT_24_4 = 240400
const __DRIVERKIT_24_5 = 240500
const __DRIVERKIT_24_6 = 240600
const __DRIVERKIT_25_0 = 250000
const __DRIVERKIT_25_1 = 250100
const __DRIVERKIT_25_2 = 250200
const __DRIVERKIT_25_3 = 250300
const __DRIVERKIT_25_4 = 250400
const __DRIVERKIT_25_5 = 250500
const __DYLDDL_DLSYM_UNAVAILABLE = 0
const __DYLDDL_UNAVAILABLE = 0
const __DYNAMIC__ = 1
const __ENABLE_LEGACY_MAC_AVAILABILITY = 1
const __ENVIRONMENT_MAC_OS_X_VERSION_MIN_REQUIRED__ = 260000
const __ENVIRONMENT_OS_VERSION_MIN_REQUIRED__ = 260000
const __FLT_MIN__ = 1.17549435e-38
const __ILP32_OFF32 = -1
const __ILP32_OFFBIG = -1
const __INT_LEAST64_MAX = 9223372036854775807
const __INT_LEAST64_MIN = -9223372036854775808
const __IPHONE_10_0 = 100000
const __IPHONE_10_1 = 100100
const __IPHONE_10_2 = 100200
const __IPHONE_10_3 = 100300
const __IPHONE_11_0 = 110000
const __IPHONE_11_1 = 110100
const __IPHONE_11_2 = 110200
const __IPHONE_11_3 = 110300
const __IPHONE_11_4 = 110400
const __IPHONE_12_0 = 120000
const __IPHONE_12_1 = 120100
const __IPHONE_12_2 = 120200
const __IPHONE_12_3 = 120300
const __IPHONE_12_4 = 120400
const __IPHONE_13_0 = 130000
const __IPHONE_13_1 = 130100
const __IPHONE_13_2 = 130200
const __IPHONE_13_3 = 130300
const __IPHONE_13_4 = 130400
const __IPHONE_13_5 = 130500
const __IPHONE_13_6 = 130600
const __IPHONE_13_7 = 130700
const __IPHONE_14_0 = 140000
const __IPHONE_14_1 = 140100
const __IPHONE_14_2 = 140200
const __IPHONE_14_3 = 140300
const __IPHONE_14_5 = 140500
const __IPHONE_14_6 = 140600
const __IPHONE_14_7 = 140700
const __IPHONE_14_8 = 140800
const __IPHONE_15_0 = 150000
const __IPHONE_15_1 = 150100
const __IPHONE_15_2 = 150200
const __IPHONE_15_3 = 150300
const __IPHONE_15_4 = 150400
const __IPHONE_15_5 = 150500
const __IPHONE_15_6 = 150600
const __IPHONE_15_7 = 150700
const __IPHONE_15_8 = 150800
const __IPHONE_16_0 = 160000
const __IPHONE_16_1 = 160100
const __IPHONE_16_2 = 160200
const __IPHONE_16_3 = 160300
const __IPHONE_16_4 = 160400
const __IPHONE_16_5 = 160500
const __IPHONE_16_6 = 160600
const __IPHONE_16_7 = 160700
const __IPHONE_17_0 = 170000
const __IPHONE_17_1 = 170100
const __IPHONE_17_2 = 170200
const __IPHONE_17_3 = 170300
const __IPHONE_17_4 = 170400
const __IPHONE_17_5 = 170500
const __IPHONE_17_6 = 170600
const __IPHONE_17_7 = 170700
const __IPHONE_18_0 = 180000
const __IPHONE_18_1 = 180100
const __IPHONE_18_2 = 180200
const __IPHONE_18_3 = 180300
const __IPHONE_18_4 = 180400
const __IPHONE_18_5 = 180500
const __IPHONE_18_6 = 180600
const __IPHONE_19_0 = 190000
const __IPHONE_26_0 = 260000
const __IPHONE_26_1 = 260100
const __IPHONE_26_2 = 260200
const __IPHONE_26_3 = 260300
const __IPHONE_26_4 = 260400
const __IPHONE_26_5 = 260500
const __IPHONE_2_0 = 20000
const __IPHONE_2_1 = 20100
const __IPHONE_2_2 = 20200
const __IPHONE_3_0 = 30000
const __IPHONE_3_1 = 30100
const __IPHONE_3_2 = 30200
const __IPHONE_4_0 = 40000
const __IPHONE_4_1 = 40100
const __IPHONE_4_2 = 40200
const __IPHONE_4_3 = 40300
const __IPHONE_5_0 = 50000
const __IPHONE_5_1 = 50100
const __IPHONE_6_0 = 60000
const __IPHONE_6_1 = 60100
const __IPHONE_7_0 = 70000
const __IPHONE_7_1 = 70100
const __IPHONE_8_0 = 80000
const __IPHONE_8_1 = 80100
const __IPHONE_8_2 = 80200
const __IPHONE_8_3 = 80300
const __IPHONE_8_4 = 80400
const __IPHONE_9_0 = 90000
const __IPHONE_9_1 = 90100
const __IPHONE_9_2 = 90200
const __IPHONE_9_3 = 90300
const __LDBL_MIN__ = 2.2250738585072014e-308
const __LP64_OFF64 = 1
const __LPBIG_OFFBIG = 1
const __MACH__ = 1
const __MAC_10_0 = 1000
const __MAC_10_1 = 1010
const __MAC_10_10 = 101000
const __MAC_10_10_2 = 101002
const __MAC_10_10_3 = 101003
const __MAC_10_11 = 101100
const __MAC_10_11_2 = 101102
const __MAC_10_11_3 = 101103
const __MAC_10_11_4 = 101104
const __MAC_10_12 = 101200
const __MAC_10_12_1 = 101201
const __MAC_10_12_2 = 101202
const __MAC_10_12_4 = 101204
const __MAC_10_13 = 101300
const __MAC_10_13_1 = 101301
const __MAC_10_13_2 = 101302
const __MAC_10_13_4 = 101304
const __MAC_10_14 = 101400
const __MAC_10_14_1 = 101401
const __MAC_10_14_4 = 101404
const __MAC_10_14_5 = 101405
const __MAC_10_14_6 = 101406
const __MAC_10_15 = 101500
const __MAC_10_15_1 = 101501
const __MAC_10_15_4 = 101504
const __MAC_10_16 = 101600
const __MAC_10_2 = 1020
const __MAC_10_3 = 1030
const __MAC_10_4 = 1040
const __MAC_10_5 = 1050
const __MAC_10_6 = 1060
const __MAC_10_7 = 1070
const __MAC_10_8 = 1080
const __MAC_10_9 = 1090
const __MAC_11_0 = 110000
const __MAC_11_1 = 110100
const __MAC_11_3 = 110300
const __MAC_11_4 = 110400
const __MAC_11_5 = 110500
const __MAC_11_6 = 110600
const __MAC_12_0 = 120000
const __MAC_12_1 = 120100
const __MAC_12_2 = 120200
const __MAC_12_3 = 120300
const __MAC_12_4 = 120400
const __MAC_12_5 = 120500
const __MAC_12_6 = 120600
const __MAC_12_7 = 120700
const __MAC_13_0 = 130000
const __MAC_13_1 = 130100
const __MAC_13_2 = 130200
const __MAC_13_3 = 130300
const __MAC_13_4 = 130400
const __MAC_13_5 = 130500
const __MAC_13_6 = 130600
const __MAC_13_7 = 130700
const __MAC_14_0 = 140000
const __MAC_14_1 = 140100
const __MAC_14_2 = 140200
const __MAC_14_3 = 140300
const __MAC_14_4 = 140400
const __MAC_14_5 = 140500
const __MAC_14_6 = 140600
const __MAC_14_7 = 140700
const __MAC_15_0 = 150000
const __MAC_15_1 = 150100
const __MAC_15_2 = 150200
const __MAC_15_3 = 150300
const __MAC_15_4 = 150400
const __MAC_15_5 = 150500
const __MAC_15_6 = 150600
const __MAC_16_0 = 160000
const __MAC_26_0 = 260000
const __MAC_26_1 = 260100
const __MAC_26_2 = 260200
const __MAC_26_3 = 260300
const __MAC_26_4 = 260400
const __MAC_26_5 = 260500
const __NULLABILITY_COMPLETENESS_POP = 0
const __NULLABILITY_COMPLETENESS_PUSH = 0
const __PTHREAD_ATTR_SIZE__ = 56
const __PTHREAD_CONDATTR_SIZE__ = 8
const __PTHREAD_COND_SIZE__ = 40
const __PTHREAD_MUTEXATTR_SIZE__ = 8
const __PTHREAD_MUTEX_SIZE__ = 56
const __PTHREAD_ONCE_SIZE__ = 8
const __PTHREAD_RWLOCKATTR_SIZE__ = 16
const __PTHREAD_RWLOCK_SIZE__ = 192
const __PTHREAD_SIZE__ = 8176
const __SSP__ = 1
const __STDC_WANT_LIB_EXT1__ = 1
const __TVOS_10_0 = 100000
const __TVOS_10_0_1 = 100001
const __TVOS_10_1 = 100100
const __TVOS_10_2 = 100200
const __TVOS_11_0 = 110000
const __TVOS_11_1 = 110100
const __TVOS_11_2 = 110200
const __TVOS_11_3 = 110300
const __TVOS_11_4 = 110400
const __TVOS_12_0 = 120000
const __TVOS_12_1 = 120100
const __TVOS_12_2 = 120200
const __TVOS_12_3 = 120300
const __TVOS_12_4 = 120400
const __TVOS_13_0 = 130000
const __TVOS_13_2 = 130200
const __TVOS_13_3 = 130300
const __TVOS_13_4 = 130400
const __TVOS_14_0 = 140000
const __TVOS_14_1 = 140100
const __TVOS_14_2 = 140200
const __TVOS_14_3 = 140300
const __TVOS_14_5 = 140500
const __TVOS_14_6 = 140600
const __TVOS_14_7 = 140700
const __TVOS_15_0 = 150000
const __TVOS_15_1 = 150100
const __TVOS_15_2 = 150200
const __TVOS_15_3 = 150300
const __TVOS_15_4 = 150400
const __TVOS_15_5 = 150500
const __TVOS_15_6 = 150600
const __TVOS_16_0 = 160000
const __TVOS_16_1 = 160100
const __TVOS_16_2 = 160200
const __TVOS_16_3 = 160300
const __TVOS_16_4 = 160400
const __TVOS_16_5 = 160500
const __TVOS_16_6 = 160600
const __TVOS_17_0 = 170000
const __TVOS_17_1 = 170100
const __TVOS_17_2 = 170200
const __TVOS_17_3 = 170300
const __TVOS_17_4 = 170400
const __TVOS_17_5 = 170500
const __TVOS_17_6 = 170600
const __TVOS_18_0 = 180000
const __TVOS_18_1 = 180100
const __TVOS_18_2 = 180200
const __TVOS_18_3 = 180300
const __TVOS_18_4 = 180400
const __TVOS_18_5 = 180500
const __TVOS_18_6 = 180600
const __TVOS_19_0 = 190000
const __TVOS_26_0 = 260000
const __TVOS_26_1 = 260100
const __TVOS_26_2 = 260200
const __TVOS_26_3 = 260300
const __TVOS_26_4 = 260400
const __TVOS_26_5 = 260500
const __TVOS_9_0 = 90000
const __TVOS_9_1 = 90100
const __TVOS_9_2 = 90200
const __UINT_LEAST64_MAX = 18446744073709551615
const __VERSION__ = "Apple LLVM 21.0.0 (clang-2100.1.1.101)"
const __VISIONOS_1_0 = 10000
const __VISIONOS_1_1 = 10100
const __VISIONOS_1_2 = 10200
const __VISIONOS_1_3 = 10300
const __VISIONOS_26_0 = 260000
const __VISIONOS_26_1 = 260100
const __VISIONOS_26_2 = 260200
const __VISIONOS_26_3 = 260300
const __VISIONOS_26_4 = 260400
const __VISIONOS_26_5 = 260500
const __VISIONOS_2_0 = 20000
const __VISIONOS_2_1 = 20100
const __VISIONOS_2_2 = 20200
const __VISIONOS_2_3 = 20300
const __VISIONOS_2_4 = 20400
const __VISIONOS_2_5 = 20500
const __VISIONOS_2_6 = 20600
const __VISIONOS_3_0 = 30000
const __WATCHOS_10_0 = 100000
const __WATCHOS_10_1 = 100100
const __WATCHOS_10_2 = 100200
const __WATCHOS_10_3 = 100300
const __WATCHOS_10_4 = 100400
const __WATCHOS_10_5 = 100500
const __WATCHOS_10_6 = 100600
const __WATCHOS_10_7 = 100700
const __WATCHOS_11_0 = 110000
const __WATCHOS_11_1 = 110100
const __WATCHOS_11_2 = 110200
const __WATCHOS_11_3 = 110300
const __WATCHOS_11_4 = 110400
const __WATCHOS_11_5 = 110500
const __WATCHOS_11_6 = 110600
const __WATCHOS_12_0 = 120000
const __WATCHOS_1_0 = 10000
const __WATCHOS_26_0 = 260000
const __WATCHOS_26_1 = 260100
const __WATCHOS_26_2 = 260200
const __WATCHOS_26_3 = 260300
const __WATCHOS_26_4 = 260400
const __WATCHOS_26_5 = 260500
const __WATCHOS_2_0 = 20000
const __WATCHOS_2_1 = 20100
const __WATCHOS_2_2 = 20200
const __WATCHOS_3_0 = 30000
const __WATCHOS_3_1 = 30100
const __WATCHOS_3_1_1 = 30101
const __WATCHOS_3_2 = 30200
const __WATCHOS_4_0 = 40000
const __WATCHOS_4_1 = 40100
const __WATCHOS_4_2 = 40200
const __WATCHOS_4_3 = 40300
const __WATCHOS_5_0 = 50000
const __WATCHOS_5_1 = 50100
const __WATCHOS_5_2 = 50200
const __WATCHOS_5_3 = 50300
const __WATCHOS_6_0 = 60000
const __WATCHOS_6_1 = 60100
const __WATCHOS_6_2 = 60200
const __WATCHOS_7_0 = 70000
const __WATCHOS_7_1 = 70100
const __WATCHOS_7_2 = 70200
const __WATCHOS_7_3 = 70300
const __WATCHOS_7_4 = 70400
const __WATCHOS_7_5 = 70500
const __WATCHOS_7_6 = 70600
const __WATCHOS_8_0 = 80000
const __WATCHOS_8_1 = 80100
const __WATCHOS_8_3 = 80300
const __WATCHOS_8_4 = 80400
const __WATCHOS_8_5 = 80500
const __WATCHOS_8_6 = 80600
const __WATCHOS_8_7 = 80700
const __WATCHOS_8_8 = 80800
const __WATCHOS_9_0 = 90000
const __WATCHOS_9_1 = 90100
const __WATCHOS_9_2 = 90200
const __WATCHOS_9_3 = 90300
const __WATCHOS_9_4 = 90400
const __WATCHOS_9_5 = 90500
const __WATCHOS_9_6 = 90600
const __apple_build_version__ = 21000101
const __bool_true_false_are_defined = 1
var __ccgo_ts1 = "ATOMIC_INTRINSICS=1\x00COMPILER=clang-21.0.0\x00DEFAULT_AUTOVACUUM\x00DEFAULT_CACHE_SIZE=-2000\x00DEFAULT_FILE_FORMAT=4\x00DEFAULT_JOURNAL_SIZE_LIMIT=-1\x00DEFAULT_MEMSTATUS=0\x00DEFAULT_MMAP_SIZE=0\x00DEFAULT_PAGE_SIZE=4096\x00DEFAULT_PCACHE_INITSZ=20\x00DEFAULT_RECURSIVE_TRIGGERS\x00DEFAULT_SECTOR_SIZE=4096\x00DEFAULT_SYNCHRONOUS=2\x00DEFAULT_WAL_AUTOCHECKPOINT=1000\x00DEFAULT_WAL_SYNCHRONOUS=2\x00DEFAULT_WORKER_THREADS=0\x00DIRECT_OVERFLOW_READ\x00DISABLE_INTRINSIC\x00ENABLE_COLUMN_METADATA\x00ENABLE_DBPAGE_VTAB\x00ENABLE_DBSTAT_VTAB\x00ENABLE_FTS5\x00ENABLE_GEOPOLY\x00ENABLE_MATH_FUNCTIONS\x00ENABLE_MEMORY_MANAGEMENT\x00ENABLE_OFFSET_SQL_FUNC\x00ENABLE_PREUPDATE_HOOK\x00ENABLE_RBU\x00ENABLE_RTREE\x00ENABLE_SESSION\x00ENABLE_SNAPSHOT\x00ENABLE_STAT4\x00ENABLE_UNLOCK_NOTIFY\x00LIKE_DOESNT_MATCH_BLOBS\x00MALLOC_SOFT_LIMIT=1024\x00MAX_ATTACHED=10\x00MAX_COLUMN=2000\x00MAX_COMPOUND_SELECT=500\x00MAX_DEFAULT_PAGE_SIZE=8192\x00MAX_EXPR_DEPTH=1000\x00MAX_FUNCTION_ARG=1000\x00MAX_LENGTH=1000000000\x00MAX_LIKE_PATTERN_LENGTH=50000\x00MAX_MMAP_SIZE=0x7fff0000\x00MAX_PAGE_COUNT=0xfffffffe\x00MAX_PAGE_SIZE=65536\x00MAX_SQL_LENGTH=1000000000\x00MAX_TRIGGER_DEPTH=1000\x00MAX_VARIABLE_NUMBER=32766\x00MAX_VDBE_OP=250000000\x00MAX_WORKER_THREADS=8\x00MUTEX_NOOP\x00SOUNDEX\x00SYSTEM_MALLOC\x00TEMP_STORE=1\x00THREADSAFE=1\x00ANY\x00BLOB\x00INT\x00INTEGER\x00REAL\x00TEXT\x0020b:20e\x0020c:20e\x0020e\x0040f-21a-21d\x00now\x00subsec\x00subsecond\x00local time unavailable\x00auto\x00ceiling\x00floor\x00julianday\x00localtime\x00unixepoch\x00utc\x00weekday \x00start of \x00month\x00year\x00day\x0040f\x0050f\x0040f-20a-20d\x0050f-20a-20d\x00%02d\x00%2d\x00%06.3f\x00%04d-%02d-%02d\x00%04d\x00%03d\x00%.16g\x00PM\x00pm\x00AM\x00am\x00%02d:%02d\x00%.3f\x00%lld\x00%02d:%02d:%02d\x00%c%04d-%02d-%02d %02d:%02d:%06.3f\x00date\x00time\x00datetime\x00strftime\x00timediff\x00current_time\x00current_timestamp\x00current_date\x00failed to allocate %u bytes of memory\x00failed memory resize %u to %u bytes\x00out of memory\x00%\x00null\x00NaN\x00-Inf\x00\x00NULL\x00(NULL)\x00unistr('\x000123456789abcdef\x00.\x00(join-%u)\x00%u-ROW VALUES CLAUSE\x00(subquery-%u)\x00unrecognized token: \"%s\"\x00922337203685477580\x00+- \n\t0123456789\x000\x00API call with %s database connection pointer\x00unopened\x00invalid\x00Savepoint\x00AutoCommit\x00Transaction\x00Checkpoint\x00JournalMode\x00Vacuum\x00VFilter\x00VUpdate\x00Init\x00Goto\x00Gosub\x00InitCoroutine\x00Yield\x00MustBeInt\x00Jump\x00Once\x00If\x00IfNot\x00IsType\x00Not\x00IfNullRow\x00SeekLT\x00SeekLE\x00SeekGE\x00SeekGT\x00IfNotOpen\x00IfNoHope\x00NoConflict\x00NotFound\x00Found\x00SeekRowid\x00NotExists\x00Last\x00IfSizeBetween\x00SorterSort\x00Sort\x00Rewind\x00IfEmpty\x00SorterNext\x00Prev\x00Next\x00IdxLE\x00IdxGT\x00Or\x00And\x00IdxLT\x00IdxGE\x00IFindKey\x00RowSetRead\x00RowSetTest\x00Program\x00IsNull\x00NotNull\x00Ne\x00Eq\x00Gt\x00Le\x00Lt\x00Ge\x00ElseEq\x00FkIfZero\x00IfPos\x00IfNotZero\x00DecrJumpZero\x00IncrVacuum\x00VNext\x00Filter\x00PureFunc\x00Function\x00Return\x00EndCoroutine\x00HaltIfNull\x00Halt\x00Integer\x00Int64\x00String\x00BeginSubrtn\x00Null\x00SoftNull\x00Blob\x00Variable\x00Move\x00Copy\x00SCopy\x00IntCopy\x00FkCheck\x00ResultRow\x00CollSeq\x00AddImm\x00RealAffinity\x00Cast\x00Permutation\x00Compare\x00IsTrue\x00ZeroOrNull\x00Offset\x00Column\x00TypeCheck\x00Affinity\x00MakeRecord\x00Count\x00ReadCookie\x00SetCookie\x00BitAnd\x00BitOr\x00ShiftLeft\x00ShiftRight\x00Add\x00Subtract\x00Multiply\x00Divide\x00Remainder\x00Concat\x00ReopenIdx\x00OpenRead\x00BitNot\x00OpenWrite\x00OpenDup\x00String8\x00OpenAutoindex\x00OpenEphemeral\x00SorterOpen\x00SequenceTest\x00OpenPseudo\x00Close\x00ColumnsUsed\x00SeekScan\x00SeekHit\x00Sequence\x00NewRowid\x00Insert\x00RowCell\x00Delete\x00ResetCount\x00SorterCompare\x00SorterData\x00RowData\x00Rowid\x00NullRow\x00SeekEnd\x00IdxInsert\x00SorterInsert\x00IdxDelete\x00DeferredSeek\x00IdxRowid\x00FinishSeek\x00Destroy\x00Clear\x00ResetSorter\x00CreateBtree\x00SqlExec\x00ParseSchema\x00LoadAnalysis\x00DropTable\x00Real\x00DropIndex\x00DropTrigger\x00IntegrityCk\x00RowSetAdd\x00Param\x00FkCounter\x00MemMax\x00OffsetLimit\x00AggInverse\x00AggStep\x00AggStep1\x00AggValue\x00AggFinal\x00Expire\x00CursorLock\x00CursorUnlock\x00TableLock\x00VBegin\x00VCreate\x00VDestroy\x00VOpen\x00VCheck\x00VInitIn\x00VColumn\x00VRename\x00Pagecount\x00MaxPgcnt\x00ClrSubtype\x00GetSubtype\x00SetSubtype\x00FilterAdd\x00Trace\x00CursorHint\x00ReleaseReg\x00Noop\x00Explain\x00Abortable\x00open\x00close\x00access\x00getcwd\x00stat\x00fstat\x00ftruncate\x00fcntl\x00read\x00pread\x00pread64\x00write\x00pwrite\x00pwrite64\x00fchmod\x00fallocate\x00unlink\x00openDirectory\x00mkdir\x00rmdir\x00fchown\x00geteuid\x00mmap\x00munmap\x00mremap\x00getpagesize\x00readlink\x00lstat\x00ioctl\x00attempt to open \"%s\" as file descriptor %d\x00/dev/null\x00os_unix.c:%d: (%d) %s(%s) - %s\x00S\x00cannot fstat db file %s\x00file unlinked while open: %s\x00multiple links to file: %s\x00file renamed while open: %s\x00%s\x00full_fsync\x00%s-shm\x00readonly_shm\x00hfs\x00ufs\x00afpfs\x00smbfs\x00webdav\x00nfs\x00psow\x00unix-excl\x00%s.lock\x00/var/tmp\x00/usr/tmp\x00/tmp\x00SQLITE_TMPDIR\x00TMPDIR\x00%s/etilqs_%llx%c\x00modeof\x00msdos\x00exfat\x00SQLITE_FORCE_PROXY_LOCKING\x00:auto:\x00fsync\x00/dev/urandom\x00sqliteplocks\x00/\x00dummy\x00break\x00path error (len %d)\x00read error (len %d)\x00create failed (%d)\x00write failed (%d)\x00rename failed (%d)\x00broke stale lock on %s\n\x00failed to break stale lock on %s, %s\n\x00-conch\x00.lock\x00:auto: (not held)\x00unix\x00unix-none\x00unix-dotfile\x00unix-posix\x00unix-flock\x00unix-afp\x00unix-nfs\x00unix-proxy\x00memdb\x00memdb(%p,%lld)\x00PRAGMA \"%w\".page_count\x00BEGIN IMMEDIATE; COMMIT;\x00ATTACH x AS %Q\x00-mj\x00recovered %d pages from %s\x00-journal\x00-wal\x00nolock\x00immutable\x00PRAGMA table_list\x00recovered %d frames from WAL file %s\x00cannot limit WAL size: %s\x00:memory:\x00@ \x00\n\x00invalid page number %u\x002nd reference to page %u\x00Failed to read ptrmap key=%u\x00Bad ptr map entry key=%u expected=(%u,%u) got=(%u,%u)\x00failed to get page %u\x00freelist leaf count too big on page %u\x00size\x00overflow list length\x00%s is %u but should be %u\x00Tree %u page %u: \x00unable to get the page. error code=%d\x00btreeInitPage() returns error code %d\x00free space corruption\x00Tree %u page %u cell %u: \x00Tree %u page %u right child: \x00Offset %u out of range %u..%u\x00Extends off end of page\x00Rowid %lld out of order\x00Child page depth differs\x00Multiple uses for byte %u of page %u\x00Fragmentation of %u bytes reported as %u on page %u\x00Freelist: \x00max rootpage (%u) disagrees with header (%u)\x00incremental_vacuum enabled with a max rootpage of zero\x00Page %u: never used\x00Page %u: pointer map referenced\x00unknown database %s\x00destination database is in use\x00source and destination must be distinct\x00.0\x00%!.*g\x00-\x00%s%s\x00k(%d\x00BINARY\x00B\x00N.\x00,%s%s%s\x00)\x00?\x008\x0016LE\x0016BE\x00%.18s-%s\x00%s(%d)\x00%d\x00(blob)\x00vtab:%p\x00%c%u\x00]\x00program\x00subrtnsig:%d,%s\x00%.4c%s%.16c\x00MJ delete: %s\x00MJ collide: %s\x00-mj%06X9%02X\x00FOREIGN KEY constraint failed\x00a CHECK constraint\x00a generated column\x00an index\x00non-deterministic use of %s() in %s\x00API called with finalized prepared statement\x00API called with NULL prepared statement\x00string or blob too big\x00addr\x00opcode\x00p1\x00p2\x00p3\x00p4\x00p5\x00comment\x00id\x00parent\x00notused\x00detail\x00bind on a busy prepared statement: [%s]\x00-- \x00%!.15g\x00'%.*q'\x00zeroblob(%d)\x00x'\x00%02x\x00'\x00/* %s */ \x00/* unknown trigger */ \x00statement aborts at %d: %s; [%s%s]\x00NOT NULL\x00UNIQUE\x00CHECK\x00FOREIGN KEY\x00%s constraint failed\x00%z: %s\x00cannot store %s value in %s column %s.%s\x00cannot open savepoint - SQL statements in progress\x00no such savepoint: %s\x00cannot release savepoint - SQL statements in progress\x00cannot commit transaction - SQL statements in progress\x00cannot start a transaction within a transaction\x00cannot rollback - no transaction is active\x00cannot commit - no transaction is active\x00database schema has changed\x00index corruption\x00sqlite_master\x00SELECT*FROM\"%w\".%s WHERE %s ORDER BY rowid\x00too many levels of trigger recursion\x00into\x00out of\x00cannot change %s wal mode from within a transaction\x00database table is locked: %s\x00ValueList\x00-- %s\x00real\x00integer\x00cannot open value of type %s\x00no such rowid: %lld\x00cannot open virtual table: %s\x00cannot open table without rowid: %s\x00cannot open table with generated columns: %s\x00cannot open view: %s\x00no such column: \"%s\"\x00foreign key\x00indexed\x00cannot open %s column for writing\x00sqlite_\x00sqlite_temp_master\x00sqlite_temp_schema\x00sqlite_schema\x00main\x00*\x00new\x00old\x00excluded\x00misuse of aliased aggregate %s\x00misuse of aliased window function %s\x00row value misused\x00double-quoted string literal: \"%w\"\x00coalesce\x00no such column\x00ambiguous column name\x00%s: %s.%s.%s\x00%s: %s.%s\x00%s: \"%s\" - should this be a string literal in single-quotes?\x00%s: %s\x00partial index WHERE clauses\x00index expressions\x00CHECK constraints\x00generated columns\x00%s prohibited in %s\x00the \".\" operator\x00second argument to %#T() must be a constant between 0.0 and 1.0\x00not authorized to use function: %#T\x00non-deterministic functions\x00%#T() may not be used as a window function\x00window\x00aggregate\x00misuse of %s function %#T()\x00no such function: %#T\x00wrong number of arguments to function %#T()\x00FILTER may not be used with non-aggregate %#T()\x00subqueries\x00parameters\x00%r %s BY term out of range - should be between 1 and %d\x00too many terms in ORDER BY clause\x00ORDER\x00%r ORDER BY term does not match any column in the result set\x00too many terms in %s BY clause\x00HAVING clause on a non-aggregate query\x00GROUP\x00aggregate functions are not allowed in the GROUP BY clause\x00Expression tree is too large (maximum depth %d)\x00s\x00IN(...) element has %d term%s - expected %d\x00too many arguments on function %T\x00ORDER BY may not be used with non-aggregate %#T()\x00unsafe use of %#T()\x00variable number must be between ?1 and ?%d\x00too many SQL variables\x00%d columns assigned %d values\x00too many columns in %s\x00true\x00false\x00_ROWID_\x00ROWID\x00OID\x00USING ROWID SEARCH ON TABLE %s FOR IN-OPERATOR\x00USING INDEX %s FOR IN-OPERATOR\x00sub-select returns %d columns - expected %d\x00REUSE LIST SUBQUERY %d\x00CORRELATED \x00%sLIST SUBQUERY %d\x00REUSE SUBQUERY %d\x00%sSCALAR SUBQUERY %d\x000x\x00hex literal too big: %s%#T\x00generated column loop on \"%s\"\x00blob\x00text\x00numeric\x00flexnum\x00none\x00misuse of aggregate: %#T()\x00unknown function: %#T()\x00RAISE() may only be used within a trigger-program\x00more than %d aggregate terms\x00table %s may not be altered\x00SELECT 1 FROM \"%w\".sqlite_master WHERE name NOT LIKE 'sqliteX_%%' ESCAPE 'X' AND sql NOT LIKE 'create virtual%%' AND sqlite_rename_test(%Q, sql, type, name, %d, %Q, %d)=NULL \x00SELECT 1 FROM temp.sqlite_master WHERE name NOT LIKE 'sqliteX_%%' ESCAPE 'X' AND sql NOT LIKE 'create virtual%%' AND sqlite_rename_test(%Q, sql, type, name, 1, %Q, %d)=NULL \x00UPDATE \"%w\".sqlite_master SET sql = sqlite_rename_quotefix(%Q, sql)WHERE name NOT LIKE 'sqliteX_%%' ESCAPE 'X' AND sql NOT LIKE 'create virtual%%'\x00UPDATE temp.sqlite_master SET sql = sqlite_rename_quotefix('temp', sql)WHERE name NOT LIKE 'sqliteX_%%' ESCAPE 'X' AND sql NOT LIKE 'create virtual%%'\x00there is already another table or index with this name: %s\x00table\x00view %s may not be altered\x00UPDATE \"%w\".sqlite_master SET sql = sqlite_rename_table(%Q, type, name, sql, %Q, %Q, %d) WHERE (type!='index' OR tbl_name=%Q COLLATE nocase)AND name NOT LIKE 'sqliteX_%%' ESCAPE 'X'\x00UPDATE %Q.sqlite_master SET tbl_name = %Q, name = CASE WHEN type='table' THEN %Q WHEN name LIKE 'sqliteX_autoindex%%' ESCAPE 'X' AND type='index' THEN 'sqlite_autoindex_' || %Q || substr(name,%d+18) ELSE name END WHERE tbl_name=%Q COLLATE nocase AND (type='table' OR type='index' OR type='trigger');\x00sqlite_sequence\x00UPDATE \"%w\".sqlite_sequence set name = %Q WHERE name = %Q\x00UPDATE sqlite_temp_schema SET sql = sqlite_rename_table(%Q, type, name, sql, %Q, %Q, 1), tbl_name = CASE WHEN tbl_name=%Q COLLATE nocase AND sqlite_rename_test(%Q, sql, type, name, 1, 'after rename', 0) THEN %Q ELSE tbl_name END WHERE type IN ('view', 'trigger')\x00after rename\x00SELECT raise(ABORT,%Q) FROM \"%w\".\"%w\"\x00Cannot add a PRIMARY KEY column\x00Cannot add a UNIQUE column\x00Cannot add a REFERENCES column with non-NULL default value\x00Cannot add a NOT NULL column with default value NULL\x00Cannot add a column with non-constant default\x00cannot add a STORED column\x00UPDATE \"%w\".sqlite_master SET sql = printf('%%.%ds, ',sql) || %Q || substr(sql,1+length(printf('%%.%ds',sql))) WHERE type = 'table' AND name = %Q\x00SELECT CASE WHEN quick_check GLOB 'CHECK*' THEN raise(ABORT,'CHECK constraint failed') WHEN quick_check GLOB 'non-* value in*' THEN raise(ABORT,'type mismatch on DEFAULT') ELSE raise(ABORT,'NOT NULL constraint failed') END FROM pragma_quick_check(%Q,%Q) WHERE quick_check GLOB 'CHECK*' OR quick_check GLOB 'NULL*' OR quick_check GLOB 'non-* value in*'\x00virtual tables may not be altered\x00Cannot add a column to a view\x00sqlite_altertab_%s\x00view\x00virtual table\x00rename columns of\x00drop column from\x00edit constraints of\x00cannot %s %s \"%s\"\x00no such column: \"%T\"\x00UPDATE \"%w\".sqlite_master SET sql = sqlite_rename_column(sql, type, name, %Q, %Q, %d, %Q, %d, %d) WHERE name NOT LIKE 'sqliteX_%%' ESCAPE 'X' AND (type != 'index' OR tbl_name = %Q)\x00UPDATE temp.sqlite_master SET sql = sqlite_rename_column(sql, type, name, %Q, %Q, %d, %Q, %d, 1) WHERE type IN ('trigger', 'view')\x00 \x00error in %s %s%s%s: %s\x00CREATE \x00\"%w\" \x00%Q%s\x00%.*s%s\x00PRIMARY KEY\x00cannot drop %s column: \"%s\"\x00cannot drop column \"%s\": no other columns exist\x00UPDATE \"%w\".sqlite_master SET sql = sqlite_drop_column(%d, sql, %d) WHERE (type=='table' AND tbl_name=%Q COLLATE nocase)\x00after drop column\x00constraint may not be dropped: %s\x00no such constraint: %s\x00%.*s%s%s\x00%.*s, %s%s\x00%.*s %s%s\x00no such column: %s\x00%Q\x00UPDATE \"%w\".sqlite_master SET sql = sqlite_drop_constraint(sql, %s) WHERE type='table' AND tbl_name=%Q COLLATE nocase\x00%.*s\x00SELECT sqlite_fail('constraint failed', %d) FROM %Q.%Q AS x WHERE x.%.*s IS NULL\x00UPDATE \"%w\".sqlite_master SET sql = sqlite_add_constraint(sqlite_drop_constraint(sql, %d), %.*Q, %d) WHERE type='table' AND tbl_name=%Q COLLATE nocase\x00SELECT sqlite_fail('constraint %q already exists', %d) FROM \"%w\".sqlite_master WHERE type='table' AND tbl_name=%Q COLLATE nocase AND sqlite_find_constraint(sql, %Q)\x00SELECT sqlite_fail('constraint failed', %d) FROM %Q.%Q WHERE (%.*s) IS NOT TRUE\x00UPDATE \"%w\".sqlite_master SET sql = sqlite_add_constraint(sql, %.*Q, -1) WHERE type='table' AND tbl_name=%Q COLLATE nocase\x00sqlite_rename_column\x00sqlite_rename_table\x00sqlite_rename_test\x00sqlite_drop_column\x00sqlite_rename_quotefix\x00sqlite_drop_constraint\x00sqlite_fail\x00sqlite_add_constraint\x00sqlite_find_constraint\x00sqlite_stat1\x00tbl,idx,stat\x00sqlite_stat4\x00tbl,idx,neq,nlt,ndlt,sample\x00sqlite_stat3\x00CREATE TABLE %Q.%s(%s)\x00DELETE FROM %Q.%s WHERE %s=%Q\x00DELETE FROM %Q.%s\x00stat_init\x00stat_push\x00%llu\x00 %llu\x00%llu \x00stat_get\x00sqlite\\_%\x00BBB\x00idx\x00tbl\x00unordered*\x00sz=[0-9]*\x00noskipscan*\x00SELECT idx,count(*) FROM %Q.sqlite_stat4 GROUP BY idx COLLATE nocase\x00SELECT idx,neq,nlt,ndlt,sample FROM %Q.sqlite_stat4\x00SELECT tbl,idx,stat FROM %Q.sqlite_stat1\x00x\x00\x00too many attached databases - max %d\x00database %s is already in use\x00database is already attached\x00attached databases must use the same text encoding as main database\x00unable to open database: %s\x00no such database: %s\x00cannot detach database %s\x00database %s is locked\x00sqlite_detach\x00sqlite_attach\x00%s cannot use variables\x00%s %T cannot reference objects in database %s\x00authorizer malfunction\x00%s.%s\x00%s.%z\x00access to %z is prohibited\x00not authorized\x00pragma_\x00json\x00no such view\x00no such table\x00corrupt database\x00unknown database %T\x00object name reserved for internal use: %s\x00temporary table name must be unqualified\x00%s %T already exists\x00there is already an index named %s\x00cannot use RETURNING in a trigger\x00sqlite_returning_%p\x00too many columns on %s\x00always\x00generated\x00duplicate column name: %s\x00default value of column [%s] is not constant\x00cannot use DEFAULT on a generated column\x00generated columns cannot be part of the PRIMARY KEY\x00table \"%s\" has more than one primary key\x00AUTOINCREMENT is only allowed on an INTEGER PRIMARY KEY\x00virtual tables cannot use computed columns\x00virtual\x00stored\x00error in generated column \"%s\"\x00,\x00\n \x00,\n \x00\n)\x00CREATE TABLE \x00 TEXT\x00 NUM\x00 INT\x00 REAL\x00unknown datatype for %s.%s: \"%s\"\x00missing datatype for %s.%s\x00AUTOINCREMENT not allowed on WITHOUT ROWID tables\x00PRIMARY KEY missing on table %s\x00must have at least one non-generated column\x00TABLE\x00VIEW\x00CREATE %s %.*s\x00UPDATE %Q.sqlite_master SET type='%s', name=%Q, tbl_name=%Q, rootpage=#%d, sql=%Q WHERE rowid=#%d\x00CREATE TABLE %Q.sqlite_sequence(name,seq)\x00tbl_name='%q' AND type!='trigger'\x00SELECT*FROM\"%w\".\"%w\"\x00parameters are not allowed in views\x00view %s is circularly defined\x00corrupt schema\x00UPDATE %Q.sqlite_master SET rootpage=%d WHERE #%d AND rootpage=#%d\x00sqlite_stat%d\x00DELETE FROM %Q.sqlite_sequence WHERE name=%Q\x00DELETE FROM %Q.sqlite_master WHERE tbl_name=%Q and type!='trigger'\x00table %s may not be dropped\x00use DROP TABLE to delete table %s\x00use DROP VIEW to delete view %s\x00foreign key on %s should reference only one column of table %T\x00number of columns in foreign key does not match the number of columns in the referenced table\x00unknown column \"%s\" in foreign key definition\x00FIRST\x00LAST\x00unsupported use of NULLS %s\x00index\x00cannot create a TEMP index on non-TEMP table \"%s\"\x00table %s may not be indexed\x00views may not be indexed\x00virtual tables may not be indexed\x00there is already a table named %s\x00index %s already exists\x00sqlite_autoindex_%s_%d\x00expressions prohibited in PRIMARY KEY and UNIQUE constraints\x00conflicting ON CONFLICT clauses specified\x00invalid rootpage\x00 UNIQUE\x00CREATE%s INDEX %.*s\x00INSERT INTO %Q.sqlite_master VALUES('index',%Q,%Q,#%d,%Q);\x00name='%q' AND type='index'\x00no such index: %S\x00index associated with UNIQUE or PRIMARY KEY constraint cannot be dropped\x00DELETE FROM %Q.sqlite_master WHERE name=%Q AND type='index'\x00too many FROM clause terms, max: %d\x00ON\x00USING\x00a JOIN clause is required before %s\x00BEGIN\x00ROLLBACK\x00COMMIT\x00RELEASE\x00unable to open a temporary database file for storing temporary tables\x00index '%q'\x00, \x00%s.rowid\x00expressions\x00unable to identify the object to be reindexed\x00duplicate WITH table name: %s\x00no such collation sequence: %s\x00unsafe use of virtual table \"%s\"\x00table %s may not be modified\x00cannot modify %s because it is a view\x00rows deleted\x00integer overflow\x00%!.*f\x00LIKE or GLOB pattern too complex\x00ESCAPE expression must be a single character\x00%!0.17g\x00%#Q\x00invalid Unicode escape\x00?000\x00MATCH\x00like\x00implies_nonnull_row\x00expr_compare\x00expr_implies_expr\x00affinity\x00soundex\x00load_extension\x00sqlite_compileoption_used\x00sqlite_compileoption_get\x00unlikely\x00likelihood\x00likely\x00sqlite_offset\x00ltrim\x00rtrim\x00trim\x00min\x00max\x00typeof\x00subtype\x00length\x00octet_length\x00instr\x00printf\x00format\x00unicode\x00char\x00abs\x00round\x00upper\x00lower\x00hex\x00unhex\x00concat\x00concat_ws\x00ifnull\x00random\x00randomblob\x00nullif\x00sqlite_version\x00sqlite_source_id\x00sqlite_log\x00unistr\x00quote\x00unistr_quote\x00last_insert_rowid\x00changes\x00total_changes\x00replace\x00zeroblob\x00substr\x00substring\x00sum\x00total\x00avg\x00count\x00group_concat\x00string_agg\x00glob\x00ceil\x00trunc\x00ln\x00log\x00log10\x00log2\x00exp\x00pow\x00power\x00mod\x00acos\x00asin\x00atan\x00atan2\x00cos\x00sin\x00tan\x00cosh\x00sinh\x00tanh\x00acosh\x00asinh\x00atanh\x00sqrt\x00radians\x00degrees\x00pi\x00sign\x00iif\x00if\x00foreign key mismatch - \"%w\" referencing \"%w\"\x00cannot INSERT into generated column \"%s\"\x00table %S has no column named %s\x00SCAN %S\x00table %S has %d columns but %d values were supplied\x00%d values for %d columns\x00UPSERT not implemented for virtual table \"%s\"\x00cannot UPSERT a view\x00rows inserted\x00dylib\x00sqlite3_extension_init\x00sqlite3_\x00lib\x00_init\x00no entry point [%s] in shared library [%s]\x00error during initialization: %s\x00unable to open shared library [%.*s]\x00automatic extension loading failed: %s\x00seq\x00from\x00to\x00on_update\x00on_delete\x00match\x00cid\x00name\x00type\x00notnull\x00dflt_value\x00pk\x00hidden\x00builtin\x00enc\x00narg\x00flags\x00schema\x00ncol\x00wr\x00strict\x00seqno\x00desc\x00coll\x00key\x00unique\x00origin\x00partial\x00wdth\x00hght\x00flgs\x00rowid\x00fkid\x00busy\x00checkpointed\x00file\x00database\x00status\x00cache_size\x00timeout\x00analysis_limit\x00application_id\x00auto_vacuum\x00automatic_index\x00busy_timeout\x00cache_spill\x00case_sensitive_like\x00cell_size_check\x00checkpoint_fullfsync\x00collation_list\x00compile_options\x00count_changes\x00data_version\x00database_list\x00default_cache_size\x00defer_foreign_keys\x00empty_result_callbacks\x00encoding\x00foreign_key_check\x00foreign_key_list\x00foreign_keys\x00freelist_count\x00full_column_names\x00fullfsync\x00function_list\x00hard_heap_limit\x00ignore_check_constraints\x00incremental_vacuum\x00index_info\x00index_list\x00index_xinfo\x00integrity_check\x00journal_mode\x00journal_size_limit\x00legacy_alter_table\x00lock_proxy_file\x00locking_mode\x00max_page_count\x00mmap_size\x00module_list\x00optimize\x00page_count\x00page_size\x00pragma_list\x00query_only\x00quick_check\x00read_uncommitted\x00recursive_triggers\x00reverse_unordered_selects\x00schema_version\x00secure_delete\x00short_column_names\x00shrink_memory\x00soft_heap_limit\x00synchronous\x00table_info\x00table_list\x00table_xinfo\x00temp_store\x00temp_store_directory\x00threads\x00trusted_schema\x00user_version\x00wal_autocheckpoint\x00wal_checkpoint\x00writable_schema\x00exclusive\x00normal\x00full\x00incremental\x00memory\x00temporary storage cannot be changed from within a transaction\x00SET NULL\x00SET DEFAULT\x00CASCADE\x00RESTRICT\x00NO ACTION\x00delete\x00persist\x00off\x00truncate\x00wal\x00utf8\x00utf16le\x00utf16be\x00w\x00a\x00sissii\x00-%T\x00fast\x00not a writable directory\x00failed to set lock proxy file\x00Safety level may not be changed inside a transaction\x00reset\x00issisii\x00issisi\x00SELECT*FROM\"%w\"\x00shadow\x00sssiii\x00iisX\x00isiX\x00c\x00u\x00isisi\x00iss\x00is\x00iissssss\x00NONE\x00siX\x00*** in database %s ***\n\x00wrong # of entries in index \x00row not in PRIMARY KEY order for %s\x00NULL value in %s.%s\x00non-%s value in %s.%s\x00NUMERIC value in %s.%s\x00C\x00TEXT value in %s.%s\x00CHECK constraint failed in %s\x00index %s stores an imprecise floating-point value for row \x00row \x00 missing from index \x00rowid not at end-of-record for row \x00 of index \x00 values differ from index \x00non-unique entry in index \x00ok\x00UTF8\x00UTF-8\x00UTF-16le\x00UTF-16be\x00UTF16le\x00UTF16be\x00UTF-16\x00UTF16\x00unsupported encoding: %s\x00restart\x00noop\x00ANALYZE \"%w\".\"%w\"\x00CREATE TABLE x\x00%c\"%s\"\x00(\"%s\"\x00,arg HIDDEN\x00,schema HIDDEN\x00PRAGMA \x00%Q.\x00=%Q\x00rename\x00drop column\x00add column\x00drop constraint\x00error in %s %s after %s: %s\x00malformed database schema (%s)\x00%z - %s\x00orphan index\x001\x00CREATE TABLE x(type text,name text,tbl_name text,rootpage int,sql text)\x00unsupported file format\x00SELECT*FROM\"%w\".%s ORDER BY rowid\x00database schema is locked: %s\x00statement too long\x00unknown join type: %T%s%T%s%T\x00a NATURAL join may not have an ON or USING clause\x00cannot join using column %s - column not present in both tables\x00ambiguous reference to %s in USING()\x00CREATE BLOOM FILTER\x00UNION ALL\x00INTERSECT\x00EXCEPT\x00UNION\x00USE TEMP B-TREE FOR %s\x00LAST TERM OF \x00USE TEMP B-TREE FOR %sORDER BY\x00USE TEMP B-TREE FOR LAST %d TERMS OF ORDER BY\x00column%d\x00%.*z:%u\x00NUM\x00VIEWs and/or subqueries nested too deep\x00cannot use window functions in recursive queries\x00recursive aggregate queries not supported\x00SETUP\x00RECURSIVE STEP\x00SCAN %d CONSTANT ROW%s\x00COMPOUND QUERY\x00LEFT-MOST SUBQUERY\x00all VALUES must have the same number of terms\x00SELECTs to the left and right of %s do not have the same number of result columns\x00MERGE (%s)\x00LEFT\x00RIGHT\x00no such index: %s\x00'%s' is not a function\x00no such index: \"%s\"\x00multiple references to recursive table: %s\x00circular reference: %s\x00table %s has %d values for %d columns\x00multiple recursive references: %s\x00recursive reference in a subquery: %s\x00%!S\x00too many references to \"%s\": max 65535\x00access to view \"%s\" prohibited\x00..%s\x00%s.%s.%s\x00no such table: %s\x00no tables specified\x00too many columns in result set\x00DISTINCT aggregates must have exactly one argument\x00USE TEMP B-TREE FOR %s(DISTINCT)\x00USE TEMP B-TREE FOR %s(ORDER BY)\x00 USING COVERING INDEX \x00SCAN %s%s%s\x00table-function argument\x00ON clause\x00%s references tables to its right\x00target object/alias may not appear in FROM clause: %s\x00expected %d columns for '%s' but got %d\x00CO-ROUTINE %!S\x00MATERIALIZE %!S\x00DISTINCT\x00GROUP BY\x00sqlite3_get_table() called with two or more incompatible queries\x00temporary trigger may not have qualified name\x00trigger\x00cannot create triggers on virtual tables\x00cannot create triggers on shadow tables\x00trigger %T already exists\x00cannot create trigger on system table\x00BEFORE\x00AFTER\x00cannot create %s trigger on view: %S\x00cannot create INSTEAD OF trigger on table: %S\x00trigger \"%s\" may not write to shadow table \"%s\"\x00INSERT INTO %Q.sqlite_master VALUES('trigger',%Q,%Q,0,'CREATE TRIGGER %q')\x00type='trigger' AND name='%q'\x00qualified table names are not allowed on INSERT, UPDATE, and DELETE statements within triggers\x00no such trigger: %S\x00DELETE FROM %Q.sqlite_master WHERE name=%Q AND type='trigger'\x00DELETE\x00UPDATE\x00%s RETURNING is not available on virtual tables\x00RETURNING may not use \"TABLE.*\" wildcards\x00triggers nested too deep\x00-- TRIGGER %s\x00cannot UPDATE generated column \"%s\"\x00rows updated\x00%r \x00%sON CONFLICT clause does not match any PRIMARY KEY or UNIQUE constraint\x00CRE\x00INS\x00cannot VACUUM from within a transaction\x00cannot VACUUM - SQL statements in progress\x00non-text filename\x00vacuum_%016llx\x00ATTACH %Q AS %s\x00output file already exists\x00reserve\x00SELECT sql FROM \"%w\".sqlite_schema WHERE type='table'AND name<>'sqlite_sequence' AND coalesce(rootpage,1)>0\x00SELECT sql FROM \"%w\".sqlite_schema WHERE type='index'\x00SELECT'INSERT INTO %s.'||quote(name)||' SELECT*FROM\"%w\".'||quote(name)FROM %s.sqlite_schema WHERE type='table'AND coalesce(rootpage,1)>0\x00INSERT INTO %s.sqlite_schema SELECT*FROM \"%w\".sqlite_schema WHERE type IN('view','trigger') OR(type='table'AND rootpage=0)\x00CREATE VIRTUAL TABLE %T\x00UPDATE %Q.sqlite_master SET type='table', name=%Q, tbl_name=%Q, rootpage=0, sql=%Q WHERE rowid=#%d\x00name=%Q AND sql=%Q\x00vtable constructor called recursively: %s\x00vtable constructor failed: %s\x00vtable constructor did not declare schema: %s\x00no such module: %s\x00syntax error\x00\x00 AND \x00(\x00 (\x00%s=?\x00ANY(%s)\x00>\x00<\x00SEARCH\x00SCAN\x00 EXISTS\x00%s %S%s\x00AUTOMATIC PARTIAL COVERING INDEX\x00AUTOMATIC COVERING INDEX\x00COVERING INDEX %s\x00INDEX %s\x00 USING \x00 USING INTEGER PRIMARY KEY (%s\x00>? AND %s\x00%c?)\x00 VIRTUAL TABLE INDEX \x000x%x:%s\x00%d:%s\x00 LEFT-JOIN\x00BLOOM FILTER ON %S (\x00rowid=?\x00MULTI-INDEX OR\x00INDEX %d\x00RIGHT-JOIN %s\x00regexp\x00NOCASE\x00too many arguments on %s() - max %d\x00automatic index on %s(%s)\x00auto-index\x00%s.xBestIndex malfunction\x00abbreviated query algorithm search\x00no query solution\x00at most %d tables in a join\x00SCAN CONSTANT ROW\x00internal query planner error\x00second argument to nth_value must be a positive integer\x00argument of ntile must be a positive integer\x00no such window: %s\x00RANGE with offset PRECEDING/FOLLOWING requires one ORDER BY expression\x00FILTER clause may only be used with aggregate window functions\x00misuse of aggregate: %s()\x00unsupported frame specification\x00PARTITION clause\x00ORDER BY clause\x00frame specification\x00cannot override %s of window: %s\x00DISTINCT is not supported for window functions\x00frame starting offset must be a non-negative integer\x00frame ending offset must be a non-negative integer\x00frame starting offset must be a non-negative number\x00frame ending offset must be a non-negative number\x00near \"%T\": syntax error\x00ORDER BY\x00LIMIT\x00%s clause should come after %s not before\x00too many terms in compound SELECT\x00syntax error after column name \"%.*s\"\x00Recursion limit\x00unknown table option: %.*s\x00set list\x00the INDEXED BY clause is not allowed on UPDATE or DELETE statements within triggers\x00the NOT INDEXED clause is not allowed on UPDATE or DELETE statements within triggers\x00incomplete input\x00unrecognized token: \"%T\"\x00%s in \"%s\"\x00create\x00temp\x00temporary\x00end\x00explain\x00unable to close due to unfinalized statements or unfinished backups\x00not an error\x00SQL logic error\x00access permission denied\x00query aborted\x00database is locked\x00database table is locked\x00attempt to write a readonly database\x00interrupted\x00disk I/O error\x00database disk image is malformed\x00unknown operation\x00database or disk is full\x00unable to open database file\x00locking protocol\x00constraint failed\x00datatype mismatch\x00bad parameter or other API misuse\x00authorization denied\x00column index out of range\x00file is not a database\x00notification message\x00warning message\x00unknown error\x00abort due to ROLLBACK\x00another row available\x00no more rows available\x00unable to delete/modify user-function due to active statements\x00unable to use function %s in the requested context\x00unknown database: %s\x00unable to delete/modify collation sequence due to active statements\x00file:\x00localhost\x00invalid uri authority: %.*s\x00vfs\x00cache\x00shared\x00private\x00mode\x00ro\x00rw\x00rwc\x00no such %s mode: %s\x00%s mode not allowed: %s\x00no such vfs: %s\x00RTRIM\x00\x00\x00\x00%s at line %d of [%.10s]\x00database corruption\x00misuse\x00cannot open file\x00no such table column: %s.%s\x00SQLITE_\x00database is deadlocked\x00array\x00object\x00JSON nested too deep\x00JSON cannot hold BLOB values\x00malformed JSON\x00inf\x009.0e999\x00infinity\x00QNaN\x00SNaN\x00json_%s() needs an odd number of arguments\x00\"\\/bfnrt\x00-9e999\x009e999\x00inity\x00\\\"\x00\\u000b\x00\\u00\x00\\u0000\x00,\n\x00: \x00*]\x00not an array element: %Q\x00JSON path too deep\x00bad JSON path: %Q\x00@\x00[\x00#\x00.\"\x00\"\x00json_object() requires an even number of arguments\x00json_object() labels must be TEXT\x00insert\x00set\x00array_insert\x00 \x00FLAGS parameter to json_valid() must be between 1 and 15\x00[]\x00}\x00{}\x00CREATE TABLE x(key,value,type,atom,id,parent,fullkey,path,json HIDDEN,root HIDDEN)\x00[%lld]\x00.\"%.*s\"\x00.%.*s\x00$\x00jsonb\x00json_array\x00jsonb_array\x00json_array_insert\x00jsonb_array_insert\x00json_array_length\x00json_error_position\x00json_extract\x00jsonb_extract\x00->\x00->>\x00json_insert\x00jsonb_insert\x00json_object\x00jsonb_object\x00json_patch\x00jsonb_patch\x00json_pretty\x00json_quote\x00json_remove\x00jsonb_remove\x00json_replace\x00jsonb_replace\x00json_set\x00jsonb_set\x00json_type\x00json_valid\x00json_group_array\x00jsonb_group_array\x00json_group_object\x00jsonb_group_object\x00json_each\x00json_tree\x00jsonb_each\x00jsonb_tree\x00data\x00DROP TABLE '%q'.'%q_node';DROP TABLE '%q'.'%q_rowid';DROP TABLE '%q'.'%q_parent';\x00RtreeMatchArg\x00SELECT * FROM %Q.%Q\x00UNIQUE constraint failed: %s.%s\x00rtree constraint failed: %s.(%s<=%s)\x00ALTER TABLE %Q.'%q_node' RENAME TO \"%w_node\";ALTER TABLE %Q.'%q_parent' RENAME TO \"%w_parent\";ALTER TABLE %Q.'%q_rowid' RENAME TO \"%w_rowid\";\x00SELECT stat FROM %Q.sqlite_stat1 WHERE tbl = '%q_rowid'\x00node\x00INSERT OR REPLACE INTO '%q'.'%q_node' VALUES(?1, ?2)\x00DELETE FROM '%q'.'%q_node' WHERE nodeno = ?1\x00SELECT nodeno FROM '%q'.'%q_rowid' WHERE rowid = ?1\x00INSERT OR REPLACE INTO '%q'.'%q_rowid' VALUES(?1, ?2)\x00DELETE FROM '%q'.'%q_rowid' WHERE rowid = ?1\x00SELECT parentnode FROM '%q'.'%q_parent' WHERE nodeno = ?1\x00INSERT OR REPLACE INTO '%q'.'%q_parent' VALUES(?1, ?2)\x00DELETE FROM '%q'.'%q_parent' WHERE nodeno = ?1\x00CREATE TABLE \"%w\".\"%w_rowid\"(rowid INTEGER PRIMARY KEY,nodeno\x00,a%d\x00);CREATE TABLE \"%w\".\"%w_node\"(nodeno INTEGER PRIMARY KEY,data);\x00CREATE TABLE \"%w\".\"%w_parent\"(nodeno INTEGER PRIMARY KEY,parentnode);\x00INSERT INTO \"%w\".\"%w_node\"VALUES(1,zeroblob(%d))\x00INSERT INTO\"%w\".\"%w_rowid\"(rowid,nodeno)VALUES(?1,?2)ON CONFLICT(rowid)DO UPDATE SET nodeno=excluded.nodeno\x00SELECT * FROM \"%w\".\"%w_rowid\" WHERE rowid=?1\x00UPDATE \"%w\".\"%w_rowid\"SET \x00a%d=coalesce(?%d,a%d)\x00a%d=?%d\x00 WHERE rowid=?1\x00PRAGMA %Q.page_size\x00SELECT length(data) FROM '%q'.'%q_node' WHERE nodeno = 1\x00undersize RTree blobs in \"%q_node\"\x00Wrong number of columns for an rtree table\x00Too few columns for an rtree table\x00Too many columns for an rtree table\x00Auxiliary rtree columns must be last\x00_node\x00CREATE TABLE x(%.*s INT\x00,%.*s\x00,%.*s REAL\x00,%.*s INT\x00);\x00{%lld\x00 %g\x00Invalid argument to rtreedepth()\x00%z%s%z\x00SELECT data FROM %Q.'%q_node' WHERE nodeno=?\x00Node %lld missing from database\x00SELECT parentnode FROM %Q.'%q_parent' WHERE nodeno=?1\x00SELECT nodeno FROM %Q.'%q_rowid' WHERE rowid=?1\x00%_rowid\x00%_parent\x00Mapping (%lld -> %lld) missing from %s table\x00Found (%lld -> %lld) in %s table, expected (%lld -> %lld)\x00Dimension %d of cell %d on node %lld is corrupt\x00Dimension %d of cell %d on node %lld is corrupt relative to parent\x00Node %lld is too small (%d bytes)\x00Rtree depth out of range (%d)\x00Node %lld is too small for cell count of %d (%d bytes)\x00SELECT count(*) FROM %Q.'%q%s'\x00Wrong number of entries in %%%s table - expected %lld, actual %lld\x00SELECT * FROM %Q.'%q_rowid'\x00Schema corrupt or not an rtree\x00_rowid\x00_parent\x00In RTree %s.%s:\n%z\x00wrong number of arguments to function rtreecheck()\x00[%!g,%!g],\x00[%!g,%!g]]\x00\x00Too many columns for a geopoly table\x00CREATE TABLE x(_shape\x00,%s\x00rtree\x00fullscan\x00_shape does not contain a valid polygon\x00geopoly_overlap\x00geopoly_within\x00geopoly_area\x00geopoly_blob\x00geopoly_json\x00geopoly_svg\x00geopoly_contains_point\x00geopoly_debug\x00geopoly_bbox\x00geopoly_xform\x00geopoly_regular\x00geopoly_ccw\x00geopoly_group_bbox\x00geopoly\x00rtreenode\x00rtreedepth\x00rtreecheck\x00rtree_i32\x00corrupt fossil delta\x00DROP TRIGGER IF EXISTS temp.rbu_insert_tr;DROP TRIGGER IF EXISTS temp.rbu_update1_tr;DROP TRIGGER IF EXISTS temp.rbu_update2_tr;DROP TRIGGER IF EXISTS temp.rbu_delete_tr;\x00AND rootpage!=0 AND rootpage IS NOT NULL\x00SELECT rbu_target_name(name, type='view') AS target, name FROM sqlite_schema WHERE type IN ('table', 'view') AND target IS NOT NULL %s ORDER BY name\x00SELECT name, rootpage, sql IS NULL OR substr(8, 6)=='UNIQUE' FROM main.sqlite_schema WHERE type='index' AND tbl_name = ?\x00SELECT (sql COLLATE nocase BETWEEN 'CREATE VIRTUAL' AND 'CREATE VIRTUAM'), rootpage FROM sqlite_schema WHERE name=%Q\x00PRAGMA index_list=%Q\x00SELECT rootpage FROM sqlite_schema WHERE name = %Q\x00PRAGMA table_info=%Q\x00PRAGMA main.index_list = %Q\x00PRAGMA main.index_xinfo = %Q\x00SELECT * FROM '%q'\x00rbu_\x00rbu_rowid\x00may not have\x00requires\x00table %q %s rbu_rowid column\x00PRAGMA table_info(%Q)\x00column missing from %q: %s\x00%z%s\"%w\"\x00%z%s%s\"%w\"%s\x00SELECT max(_rowid_) FROM \"%s%w\"\x00 WHERE _rowid_ > %lld \x00 DESC\x00quote(\x00||','||\x00SELECT %s FROM \"%s%w\" ORDER BY %s LIMIT 1\x00 WHERE (%s) > (%s) \x00_rowid_\x00%z%s \"%w\" COLLATE %Q\x00%z%s \"rbu_imp_%d%w\" COLLATE %Q DESC\x00%z%s quote(\"rbu_imp_%d%w\")\x00SELECT %s FROM \"rbu_imp_%w\" ORDER BY %s LIMIT 1\x00%z%s%s\x00(%s) > (%s)\x00%z%s(%.*s) COLLATE %Q\x00%z%s\"%w\" COLLATE %Q\x00%z%s\"rbu_imp_%d%w\"%s\x00%z%s\"rbu_imp_%d%w\" %s COLLATE %Q\x00%z%s\"rbu_imp_%d%w\" IS ?\x00%z%s%s.\"%w\"\x00%z%sNULL\x00%z, %s._rowid_\x00_rowid_ = ?%d\x00%z%sc%d=?%d\x00_rowid_ = (SELECT id FROM rbu_imposter2 WHERE %z)\x00%z%s\"%w\"=?%d\x00invalid rbu_control value\x00%z%s\"%w\"=rbu_delta(\"%w\", ?%d)\x00%z%s\"%w\"=rbu_fossil_delta(\"%w\", ?%d)\x00PRIMARY KEY(\x00%z%s\"%w\"%s\x00%z)\x00SELECT name FROM sqlite_schema WHERE rootpage = ?\x00%z%sc%d %s COLLATE %Q\x00%z%sc%d%s\x00%z, id INTEGER\x00CREATE TABLE rbu_imposter2(%z, PRIMARY KEY(%z)) WITHOUT ROWID\x00PRIMARY KEY \x00 NOT NULL\x00%z%s\"%w\" %s %sCOLLATE %Q%s\x00%z, %z\x00 WITHOUT ROWID\x00CREATE TABLE \"rbu_imp_%w\"(%z)%s\x00INSERT INTO %s.'rbu_tmp_%q'(rbu_control,%s%s) VALUES(%z)\x00SELECT trim(sql) FROM sqlite_schema WHERE type='index' AND name=?\x00 LIMIT -1 OFFSET %d\x00CREATE TABLE \"rbu_imp_%w\"( %s, PRIMARY KEY( %s ) ) WITHOUT ROWID\x00INSERT INTO \"rbu_imp_%w\" VALUES(%s)\x00DELETE FROM \"rbu_imp_%w\" WHERE %s\x00AND\x00WHERE\x00SELECT %s, 0 AS rbu_control FROM '%q' %s %s %s ORDER BY %s%s\x00SELECT %s, rbu_control FROM %s.'rbu_tmp_%q' %s ORDER BY %s%s\x00SELECT %s, rbu_control FROM %s.'rbu_tmp_%q' %s UNION ALL SELECT %s, rbu_control FROM '%q' %s %s typeof(rbu_control)='integer' AND rbu_control!=1 ORDER BY %s%s\x00rbu_imp_\x00, _rowid_\x00INSERT INTO \"%s%w\"(%s%s) VALUES(%s)\x00DELETE FROM \"%s%w\" WHERE %s\x00, rbu_rowid\x00, 0 AS rbu_rowid\x00CREATE TABLE IF NOT EXISTS %s.'rbu_tmp_%q' AS SELECT *%s FROM '%q' WHERE 0;\x00CREATE TEMP TRIGGER rbu_delete_tr BEFORE DELETE ON \"%s%w\" BEGIN SELECT rbu_tmp_insert(3, %s);END;CREATE TEMP TRIGGER rbu_update1_tr BEFORE UPDATE ON \"%s%w\" BEGIN SELECT rbu_tmp_insert(3, %s);END;CREATE TEMP TRIGGER rbu_update2_tr AFTER UPDATE ON \"%s%w\" BEGIN SELECT rbu_tmp_insert(4, %s);END;\x00CREATE TEMP TRIGGER rbu_insert_tr AFTER INSERT ON \"%s%w\" BEGIN SELECT rbu_tmp_insert(0, %s);END;\x00,_rowid_ \x00,rbu_rowid\x000 AS \x00SELECT %s,%s rbu_control%s FROM '%q'%s %s %s %s\x00UPDATE \"%s%w\" SET %s WHERE %s\x00SELECT k, v FROM %s.rbu_state\x00file:///%s-vacuum?modeof=%s\x00ATTACH %Q AS stat\x00CREATE TABLE IF NOT EXISTS %s.rbu_state(k INTEGER PRIMARY KEY, v)\x00cannot vacuum wal mode database\x00&\x00file:%s-vactmp?rbu_memory=1%s%s\x00rbu_tmp_insert\x00rbu_fossil_delta\x00rbu_target_name\x00SELECT * FROM sqlite_schema\x00rbu vfs not found\x00PRAGMA main.wal_checkpoint=restart\x00rbu_exclusive_checkpoint\x00%s-oal\x00%s-wal\x00PRAGMA schema_version\x00PRAGMA schema_version = %d\x00INSERT OR REPLACE INTO %s.rbu_state(k, v) VALUES (%d, %d), (%d, %Q), (%d, %Q), (%d, %d), (%d, %lld), (%d, %lld), (%d, %lld), (%d, %lld), (%d, %lld), (%d, %Q) \x00PRAGMA main.%s\x00PRAGMA main.%s = %d\x00PRAGMA writable_schema=1\x00SELECT sql FROM sqlite_schema WHERE sql!='' AND rootpage!=0 AND name!='sqlite_sequence' ORDER BY type DESC\x00SELECT * FROM sqlite_schema WHERE rootpage=0 OR rootpage IS NULL\x00INSERT INTO sqlite_schema VALUES(?,?,?,?,?)\x00PRAGMA writable_schema=0\x00DELETE FROM %s.'rbu_tmp_%q'\x00rbu_state mismatch error\x00rbu_vfs_%d\x00SELECT count(*) FROM sqlite_schema WHERE type='index' AND tbl_name = %Q\x00rbu_index_cnt\x00SELECT 1 FROM sqlite_schema WHERE tbl_name = 'rbu_count'\x00SELECT sum(cnt * (1 + rbu_index_cnt(rbu_target_name(tbl))))FROM rbu_count\x00cannot update wal mode database\x00vacuum\x00update\x00database modified during rbu %s\x00BEGIN IMMEDIATE\x00PRAGMA journal_mode=off\x00-vactmp\x00DELETE FROM stat.rbu_state\x00rbu/zipvfs setup error\x00rbu(%s)/%z\x00rbu_memory\x00overflow\x00%s%.3x+%.6x\x00%s%.3x/\x00internal\x00leaf\x00corrupted\x00SELECT * FROM (SELECT 'sqlite_schema' AS name,1 AS rootpage,'table' AS type UNION ALL SELECT name,rootpage,type FROM \"%w\".sqlite_schema WHERE rootpage!=0)\x00WHERE name=%Q\x00 ORDER BY name\x00dbstat\x00CREATE TABLE x(pgno INTEGER PRIMARY KEY, data BLOB, schema HIDDEN)\x00read-only\x00cannot delete\x00cannot insert\x00no such schema\x00bad page number\x00bad page value\x00failed to open transaction\x00sqlite_dbpage\x00SELECT 0, 'tbl', '', 0, '', 1, 0 UNION ALL SELECT 1, 'idx', '', 0, '', 2, 0 UNION ALL SELECT 2, 'stat', '', 0, '', 0, 0\x00PRAGMA '%q'.table_xinfo('%q')\x00SELECT\x00%z%s\"%w\".\"%w\".\"%w\"=\"%w\".\"%w\".\"%w\"\x00%z%s\"%w\".\"%w\".\"%w\" IS NOT \"%w\".\"%w\".\"%w\"\x00 OR \x00_rowid_, *\x00SELECT %s FROM \"%w\".\"%w\" WHERE NOT EXISTS ( SELECT 1 FROM \"%w\".\"%w\" WHERE %s)\x00%z%s\"%w\".\"%w\".\"%w\"\x00SELECT %s,%s FROM \"%w\".\"%w\", \"%w\".\"%w\" WHERE %s AND (%z)\x00SELECT * FROM %Q.sqlite_schema\x00no such table: %s.%s\x00table schemas do not match\x00, 1\x00 AND (?6 OR ?3 IS stat)\x00tbl, idx\x00?1, (CASE WHEN ?2=X'' THEN NULL ELSE ?2 END)\x00tbl, ?2, stat\x00?%d\x00 AND (?%d OR ?%d IS %w.%w)\x00SELECT %s%s FROM %Q.%Q WHERE (%s) IS (%s)\x00SAVEPOINT changeset\x00RELEASE changeset\x00UPDATE main.\x00 SET \x00 = ?\x00 WHERE \x00idx IS CASE WHEN length(?4)=0 AND typeof(?4)='blob' THEN NULL ELSE ?4 END \x00 IS ?\x00DELETE FROM main.\x00 AND (?\x00AND \x00INSERT INTO main.\x00) VALUES(?\x00, ?\x00INSERT INTO main.sqlite_stat1 VALUES(?1, CASE WHEN length(?2)=0 AND typeof(?2)='blob' THEN NULL ELSE ?2 END, ?3)\x00DELETE FROM main.sqlite_stat1 WHERE tbl=?1 AND idx IS CASE WHEN length(?2)=0 AND typeof(?2)='blob' THEN NULL ELSE ?2 END AND (?4 OR stat IS ?3)\x00SAVEPOINT replace_op\x00RELEASE replace_op\x00PRAGMA table_list = %Q\x00SELECT %s FROM %Q WHERE (%s) IS (%s)\x00INSERT INTO %Q(%s) VALUES(%s)\x00SAVEPOINT update_op\x00ROLLBACK TO update_op\x00RELEASE update_op\x00SAVEPOINT changeset_apply\x00PRAGMA defer_foreign_keys = 1\x00sqlite3changeset_apply(): no such table: %s\x00sqlite3changeset_apply(): table %s has %d columns, expected %d or more\x00sqlite3changeset_apply(): primary key mismatch for table %s\x00PRAGMA defer_foreign_keys = 0\x00RELEASE changeset_apply\x00ROLLBACK TO changeset_apply\x00undefined\x00invalid change: %s value in PK of old.* record\x00invalid change: defined value in PK of new.* record\x00un\x00invalid change: column %d - old.* value is %sdefined but new.* is %sdefined\x00invalid change: column %d is undefined\x00invalid change: null value in PK\x00fts5: parser stack overflow\x00fts5: syntax error near \"%.*s\"\x00%z%.*s\x00wrong number of arguments to function highlight()\x00wrong number of arguments to function snippet()\x00wrong number of arguments to function fts5_get_locale()\x00non-integer argument passed to function fts5_get_locale()\x00snippet\x00highlight\x00bm25\x00fts5_get_locale\x00prefix\x00malformed prefix=... directive\x00too many prefix indexes (max %d)\x00prefix length out of range (max 999)\x00tokenize\x00multiple tokenize=... directives\x00parse error in tokenize directive\x00content\x00multiple content=... directives\x00%Q.%Q\x00contentless_delete\x00malformed contentless_delete=... directive\x00contentless_unindexed\x00content_rowid\x00multiple content_rowid=... directives\x00columnsize\x00malformed columnsize=... directive\x00locale\x00malformed locale=... directive\x00columns\x00malformed detail=... directive\x00tokendata\x00malformed tokendata=... directive\x00unrecognized option: \"%.*s\"\x00rank\x00reserved fts5 column name: %s\x00unindexed\x00unrecognized column option: %s\x00T.%Q\x00, T.%Q\x00, T.c%d\x00, NULL\x00, T.l%d\x00reserved fts5 table name: %s\x00parse error in \"%s\"\x00contentless_delete=1 requires a contentless table\x00contentless_delete=1 is incompatible with columnsize=0\x00contentless_unindexed=1 requires a contentless table\x00docsize\x00%Q.'%q_%s'\x00CREATE TABLE x(\x00%z%s%Q\x00%z, %Q HIDDEN, %s HIDDEN)\x00pgsz\x00hashsize\x00automerge\x00usermerge\x00crisismerge\x00deletemerge\x00secure-delete\x00insttoken\x00SELECT k, v FROM %Q.'%q_config'\x00version\x00invalid fts5 file format (found %d, expected %d or %d) - run 'rebuild'\x00unterminated string\x00fts5: syntax error near \"%.1s\"\x00OR\x00NOT\x00NEAR\x00expected integer, got \"%.*s\"\x00fts5: column queries are not supported (detail=none)\x00phrase\x00fts5: %s queries are not supported (detail!=full)\x00fts5 expression tree is too large (maximum depth %d)\x00fts5: corruption found reading blob %lld from table \"%s\"\x00fts5: corruption on page %d, segment %d, table \"%s\"\x00fts5: corruption in table \"%s\"\x00block\x00REPLACE INTO '%q'.'%q_data'(id, block) VALUES(?,?)\x00DELETE FROM '%q'.'%q_data' WHERE id>=? AND id<=?\x00DELETE FROM '%q'.'%q_idx' WHERE segid=?\x00\xff\x00\x00\x01\x00fts5: corrupt structure record for table \"%s\"\x00PRAGMA %Q.data_version\x00SELECT pgno FROM '%q'.'%q_idx' WHERE segid=? AND term<=? ORDER BY term DESC LIMIT 1\x00SELECT pgno FROM '%q'.'%q_idx' WHERE segid=? AND term>? ORDER BY term ASC LIMIT 1\x00INSERT INTO '%q'.'%q_idx'(segid,term,pgno) VALUES(?,?,?)\x00DELETE FROM '%q'.'%q_idx' WHERE (segid, (pgno/2)) = (?1, ?2)\x00REPLACE INTO %Q.'%q_config' VALUES ('version', %d)\x00%s_data\x00id INTEGER PRIMARY KEY, block BLOB\x00segid, term, pgno, PRIMARY KEY(segid, term)\x00\x00\x00SELECT segid, term, (pgno>>1), (pgno&1) FROM %Q.'%q_idx' WHERE segid=%d ORDER BY 1, 2\x00\x00\x00\x00\x00\x00fts5: checksum mismatch for table \"%s\"\x00recursively defined fts5 content table\x00DESC\x00ASC\x00SELECT rowid, rank FROM %Q.%Q ORDER BY %s(\"%w\"%s%s) %s\x00reads\x00unknown special query: %.*s\x00SELECT %s\x00no such function: %s\x00parse error in rank function: %s\x00%s: table does not support scanning\x00fts5: missing row %lld from content table %s\x00delete-all\x00'delete-all' may only be used with a contentless or external content fts5 table\x00rebuild\x00'rebuild' may not be used with a contentless fts5 table\x00merge\x00integrity-check\x00flush\x00%s a subset of columns on fts5 contentless-delete table: %s\x00%s contentless fts5 table: %s\x00cannot UPDATE\x00'delete' may not be used with a contentless_delete=1 table\x00cannot DELETE from contentless fts5 table: %s\x00fts5_locale() requires locale=1\x00no such cursor: %lld\x00no such tokenizer: %s\x00error in tokenizer constructor\x00fts5_api_ptr\x00fts5: 2026-06-26 20:14:12 d4c0e51e4aeb96955b99185ab9cde75c339e2c29c3f3f12428d364a10d782c62\x00config\x00malformed inverted index for FTS5 table %s.%s\x00unable to validate the inverted index for FTS5 table %s.%s: %s\x00fts5\x00fts5_source_id\x00fts5_locale\x00fts5_insttoken\x00SELECT %s FROM %s T WHERE T.%Q >= ? AND T.%Q <= ? ORDER BY T.%Q ASC\x00SELECT %s FROM %s T WHERE T.%Q <= ? AND T.%Q >= ? ORDER BY T.%Q DESC\x00SELECT %s FROM %s T WHERE T.%Q=?\x00INSERT INTO %Q.'%q_content' VALUES(%s)\x00REPLACE INTO %Q.'%q_content' VALUES(%s)\x00DELETE FROM %Q.'%q_content' WHERE id=?\x00REPLACE INTO %Q.'%q_docsize' VALUES(?,?%s)\x00DELETE FROM %Q.'%q_docsize' WHERE id=?\x00SELECT sz%s FROM %Q.'%q_docsize' WHERE id=?\x00REPLACE INTO %Q.'%q_config' VALUES(?,?)\x00SELECT %s FROM %s AS T\x00%z%s?%d\x00%z,?%d\x00,?\x00,origin\x00DROP TABLE IF EXISTS %Q.'%q_data';DROP TABLE IF EXISTS %Q.'%q_idx';DROP TABLE IF EXISTS %Q.'%q_config';\x00DROP TABLE IF EXISTS %Q.'%q_docsize';\x00DROP TABLE IF EXISTS %Q.'%q_content';\x00ALTER TABLE %Q.'%q_%s' RENAME TO '%q_%s';\x00CREATE TABLE %Q.'%q_%q'(%s)%s\x00fts5: error creating shadow table %q_%s: %s\x00id INTEGER PRIMARY KEY\x00, c%d\x00, l%d\x00id INTEGER PRIMARY KEY, sz BLOB\x00id INTEGER PRIMARY KEY, sz BLOB, origin INTEGER\x00k PRIMARY KEY, v\x00DELETE FROM %Q.'%q_data';DELETE FROM %Q.'%q_idx';\x00DELETE FROM %Q.'%q_docsize';\x00DELETE FROM %Q.'%q_content';\x00SELECT count(*) FROM %Q.'%q_%s'\x00tokenchars\x00separators\x00L* N* Co\x00categories\x00remove_diacritics\x00unicode61\x00porter\x00al\x00ance\x00ence\x00er\x00ic\x00able\x00ible\x00ant\x00ement\x00ment\x00ent\x00ion\x00ou\x00ism\x00ate\x00iti\x00ous\x00ive\x00ize\x00at\x00bl\x00ble\x00iz\x00ational\x00tional\x00tion\x00enci\x00anci\x00izer\x00logi\x00bli\x00alli\x00entli\x00eli\x00e\x00ousli\x00ization\x00ation\x00ator\x00alism\x00iveness\x00fulness\x00ful\x00ousness\x00aliti\x00iviti\x00biliti\x00ical\x00ness\x00icate\x00iciti\x00ative\x00alize\x00eed\x00ee\x00ed\x00ing\x00case_sensitive\x00trigram\x00ascii\x00col\x00row\x00instance\x00fts5vocab: unknown table type: %Q\x00CREATE TABlE vocab(term, col, doc, cnt)\x00CREATE TABlE vocab(term, doc, cnt)\x00CREATE TABlE vocab(term, doc, col, offset)\x00wrong number of vtable arguments\x00recursive definition for %s.%s\x00SELECT t.%Q FROM %Q.%Q AS t WHERE t.%Q MATCH '*id'\x00no such fts5 table: %s.%s\x00fts5vocab\x002026-06-26 20:14:12 d4c0e51e4aeb96955b99185ab9cde75c339e2c29c3f3f12428d364a10d782c62\x00"
const __clang_major__ = 21
const __clang_minor__ = 0
const __clang_patchlevel__ = 0
const __clang_version__ = "21.0.0 (clang-2100.1.1.101)"
const __exported_hidden = 0
const __exported_pop = 0
const __exported_push = 0
const __exported_push_hidden = 0
const __has_bounds_safety_attributes = 0
const __has_ptrcheck = 0
const __has_safe_buffers = 0
const __header_inline = 0
const __nonnull = 0
const __null_unspecified = 0
const __nullable = 0
const __unreachable_ok_pop = 0
const __unreachable_ok_push = 0
var _aAgg = [1]struct {
FxStep uintptr
FxFinal uintptr
FzName uintptr
}{
0: {
FzName: __ccgo_ts + 30593,
},
}
var _aAlterTableFuncs = [9]TFuncDef{
0: {
FnArg: int16(9),
FfuncFlags: libc.Uint32FromInt32(libc.Int32FromInt32(SQLITE_FUNC_BUILTIN) | libc.Int32FromInt32(SQLITE_FUNC_INTERNAL) | libc.Int32FromInt32(SQLITE_UTF8) | libc.Int32FromInt32(SQLITE_FUNC_CONSTANT)),
FzName: __ccgo_ts + 12999,
},
1: {
FnArg: int16(7),
FfuncFlags: libc.Uint32FromInt32(libc.Int32FromInt32(SQLITE_FUNC_BUILTIN) | libc.Int32FromInt32(SQLITE_FUNC_INTERNAL) | libc.Int32FromInt32(SQLITE_UTF8) | libc.Int32FromInt32(SQLITE_FUNC_CONSTANT)),
FzName: __ccgo_ts + 13020,
},
2: {
FnArg: int16(7),
FfuncFlags: libc.Uint32FromInt32(libc.Int32FromInt32(SQLITE_FUNC_BUILTIN) | libc.Int32FromInt32(SQLITE_FUNC_INTERNAL) | libc.Int32FromInt32(SQLITE_UTF8) | libc.Int32FromInt32(SQLITE_FUNC_CONSTANT)),
FzName: __ccgo_ts + 13040,
},
3: {
FnArg: int16(3),
FfuncFlags: libc.Uint32FromInt32(libc.Int32FromInt32(SQLITE_FUNC_BUILTIN) | libc.Int32FromInt32(SQLITE_FUNC_INTERNAL) | libc.Int32FromInt32(SQLITE_UTF8) | libc.Int32FromInt32(SQLITE_FUNC_CONSTANT)),
FzName: __ccgo_ts + 13059,
},
4: {
FnArg: int16(2),
FfuncFlags: libc.Uint32FromInt32(libc.Int32FromInt32(SQLITE_FUNC_BUILTIN) | libc.Int32FromInt32(SQLITE_FUNC_INTERNAL) | libc.Int32FromInt32(SQLITE_UTF8) | libc.Int32FromInt32(SQLITE_FUNC_CONSTANT)),
FzName: __ccgo_ts + 13078,
},
5: {
FnArg: int16(2),
FfuncFlags: libc.Uint32FromInt32(libc.Int32FromInt32(SQLITE_FUNC_BUILTIN) | libc.Int32FromInt32(SQLITE_FUNC_INTERNAL) | libc.Int32FromInt32(SQLITE_UTF8) | libc.Int32FromInt32(SQLITE_FUNC_CONSTANT)),
FzName: __ccgo_ts + 13101,
},
6: {
FnArg: int16(2),
FfuncFlags: libc.Uint32FromInt32(libc.Int32FromInt32(SQLITE_FUNC_BUILTIN) | libc.Int32FromInt32(SQLITE_FUNC_INTERNAL) | libc.Int32FromInt32(SQLITE_UTF8) | libc.Int32FromInt32(SQLITE_FUNC_CONSTANT)),
FzName: __ccgo_ts + 13124,
},
7: {
FnArg: int16(3),
FfuncFlags: libc.Uint32FromInt32(libc.Int32FromInt32(SQLITE_FUNC_BUILTIN) | libc.Int32FromInt32(SQLITE_FUNC_INTERNAL) | libc.Int32FromInt32(SQLITE_UTF8) | libc.Int32FromInt32(SQLITE_FUNC_CONSTANT)),
FzName: __ccgo_ts + 13136,
},
8: {
FnArg: int16(2),
FfuncFlags: libc.Uint32FromInt32(libc.Int32FromInt32(SQLITE_FUNC_BUILTIN) | libc.Int32FromInt32(SQLITE_FUNC_INTERNAL) | libc.Int32FromInt32(SQLITE_UTF8) | libc.Int32FromInt32(SQLITE_FUNC_CONSTANT)),
FzName: __ccgo_ts + 13158,
},
}
/*
** The following array holds FuncDef structures for all of the functions
** defined in this file.
**
** The array cannot be constant since changes are made to the
** FuncDef.pHash elements at start-time. The elements of this array
** are read-only after initialization is complete.
**
** For peak efficiency, put the most frequently used function last.
*/
var _aBuiltinFunc = [106]TFuncDef{
0: {
FnArg: int16(2),
FfuncFlags: libc.Uint32FromInt32(libc.Int32FromInt32(SQLITE_FUNC_BUILTIN) | libc.Int32FromInt32(SQLITE_UTF8) | libc.Int32FromInt32(SQLITE_FUNC_INTERNAL) | libc.Int32FromInt32(SQLITE_FUNC_TEST) | libc.Int32FromInt32(SQLITE_FUNC_INLINE) | libc.Int32FromInt32(SQLITE_FUNC_CONSTANT) | libc.Int32FromInt32(0)),
FpUserData: uintptr(int64(libc.Int32FromInt32(INLINEFUNC_implies_nonnull_row))),
FzName: __ccgo_ts + 16958,
},
1: {
FnArg: int16(2),
FfuncFlags: libc.Uint32FromInt32(libc.Int32FromInt32(SQLITE_FUNC_BUILTIN) | libc.Int32FromInt32(SQLITE_UTF8) | libc.Int32FromInt32(SQLITE_FUNC_INTERNAL) | libc.Int32FromInt32(SQLITE_FUNC_TEST) | libc.Int32FromInt32(SQLITE_FUNC_INLINE) | libc.Int32FromInt32(SQLITE_FUNC_CONSTANT) | libc.Int32FromInt32(0)),
FpUserData: uintptr(int64(libc.Int32FromInt32(INLINEFUNC_expr_compare))),
FzName: __ccgo_ts + 16978,
},
2: {
FnArg: int16(2),
FfuncFlags: libc.Uint32FromInt32(libc.Int32FromInt32(SQLITE_FUNC_BUILTIN) | libc.Int32FromInt32(SQLITE_UTF8) | libc.Int32FromInt32(SQLITE_FUNC_INTERNAL) | libc.Int32FromInt32(SQLITE_FUNC_TEST) | libc.Int32FromInt32(SQLITE_FUNC_INLINE) | libc.Int32FromInt32(SQLITE_FUNC_CONSTANT) | libc.Int32FromInt32(0)),
FpUserData: uintptr(int64(libc.Int32FromInt32(INLINEFUNC_expr_implies_expr))),
FzName: __ccgo_ts + 16991,
},
3: {
FnArg: int16(1),
FfuncFlags: libc.Uint32FromInt32(libc.Int32FromInt32(SQLITE_FUNC_BUILTIN) | libc.Int32FromInt32(SQLITE_UTF8) | libc.Int32FromInt32(SQLITE_FUNC_INTERNAL) | libc.Int32FromInt32(SQLITE_FUNC_TEST) | libc.Int32FromInt32(SQLITE_FUNC_INLINE) | libc.Int32FromInt32(SQLITE_FUNC_CONSTANT) | libc.Int32FromInt32(0)),
FpUserData: uintptr(int64(libc.Int32FromInt32(INLINEFUNC_affinity))),
FzName: __ccgo_ts + 17009,
},
4: {
FnArg: int16(1),
FfuncFlags: libc.Uint32FromInt32(libc.Int32FromInt32(SQLITE_FUNC_BUILTIN) | libc.Int32FromInt32(SQLITE_FUNC_CONSTANT) | libc.Int32FromInt32(SQLITE_UTF8) | libc.Int32FromInt32(0)*libc.Int32FromInt32(SQLITE_FUNC_NEEDCOLL)),
FzName: __ccgo_ts + 17018,
},
5: {
FnArg: int16(1),
FfuncFlags: libc.Uint32FromInt32(libc.Int32FromInt32(SQLITE_FUNC_BUILTIN) | libc.Int32FromInt32(SQLITE_UTF8) | libc.Int32FromInt32(SQLITE_DIRECTONLY) | libc.Int32FromInt32(SQLITE_FUNC_UNSAFE)),
FzName: __ccgo_ts + 17026,
},
6: {
FnArg: int16(2),
FfuncFlags: libc.Uint32FromInt32(libc.Int32FromInt32(SQLITE_FUNC_BUILTIN) | libc.Int32FromInt32(SQLITE_UTF8) | libc.Int32FromInt32(SQLITE_DIRECTONLY) | libc.Int32FromInt32(SQLITE_FUNC_UNSAFE)),
FzName: __ccgo_ts + 17026,
},
7: {
FnArg: int16(1),
FfuncFlags: libc.Uint32FromInt32(libc.Int32FromInt32(SQLITE_FUNC_BUILTIN) | libc.Int32FromInt32(SQLITE_FUNC_SLOCHNG) | libc.Int32FromInt32(SQLITE_UTF8)),
FzName: __ccgo_ts + 17041,
},
8: {
FnArg: int16(1),
FfuncFlags: libc.Uint32FromInt32(libc.Int32FromInt32(SQLITE_FUNC_BUILTIN) | libc.Int32FromInt32(SQLITE_FUNC_SLOCHNG) | libc.Int32FromInt32(SQLITE_UTF8)),
FzName: __ccgo_ts + 17067,
},
9: {
FnArg: int16(1),
FfuncFlags: libc.Uint32FromInt32(libc.Int32FromInt32(SQLITE_FUNC_BUILTIN) | libc.Int32FromInt32(SQLITE_UTF8) | libc.Int32FromInt32(SQLITE_FUNC_INLINE) | libc.Int32FromInt32(SQLITE_FUNC_CONSTANT) | libc.Int32FromInt32(SQLITE_FUNC_UNLIKELY)),
FpUserData: uintptr(int64(libc.Int32FromInt32(INLINEFUNC_unlikely))),
FzName: __ccgo_ts + 17092,
},
10: {
FnArg: int16(2),
FfuncFlags: libc.Uint32FromInt32(libc.Int32FromInt32(SQLITE_FUNC_BUILTIN) | libc.Int32FromInt32(SQLITE_UTF8) | libc.Int32FromInt32(SQLITE_FUNC_INLINE) | libc.Int32FromInt32(SQLITE_FUNC_CONSTANT) | libc.Int32FromInt32(SQLITE_FUNC_UNLIKELY)),
FpUserData: uintptr(int64(libc.Int32FromInt32(INLINEFUNC_unlikely))),
FzName: __ccgo_ts + 17101,
},
11: {
FnArg: int16(1),
FfuncFlags: libc.Uint32FromInt32(libc.Int32FromInt32(SQLITE_FUNC_BUILTIN) | libc.Int32FromInt32(SQLITE_UTF8) | libc.Int32FromInt32(SQLITE_FUNC_INLINE) | libc.Int32FromInt32(SQLITE_FUNC_CONSTANT) | libc.Int32FromInt32(SQLITE_FUNC_UNLIKELY)),
FpUserData: uintptr(int64(libc.Int32FromInt32(INLINEFUNC_unlikely))),
FzName: __ccgo_ts + 17112,
},
12: {
FnArg: int16(1),
FfuncFlags: libc.Uint32FromInt32(libc.Int32FromInt32(SQLITE_FUNC_BUILTIN) | libc.Int32FromInt32(SQLITE_UTF8) | libc.Int32FromInt32(SQLITE_FUNC_INLINE) | libc.Int32FromInt32(SQLITE_FUNC_CONSTANT) | libc.Int32FromInt32(0)),
FpUserData: uintptr(int64(libc.Int32FromInt32(INLINEFUNC_sqlite_offset))),
FzName: __ccgo_ts + 17119,
},
13: {
FnArg: int16(1),
FfuncFlags: libc.Uint32FromInt32(libc.Int32FromInt32(SQLITE_FUNC_BUILTIN) | libc.Int32FromInt32(SQLITE_FUNC_CONSTANT) | libc.Int32FromInt32(SQLITE_UTF8) | libc.Int32FromInt32(0)*libc.Int32FromInt32(SQLITE_FUNC_NEEDCOLL)),
FpUserData: uintptr(int64(libc.Int32FromInt32(1))),
FzName: __ccgo_ts + 17133,
},
14: {
FnArg: int16(2),
FfuncFlags: libc.Uint32FromInt32(libc.Int32FromInt32(SQLITE_FUNC_BUILTIN) | libc.Int32FromInt32(SQLITE_FUNC_CONSTANT) | libc.Int32FromInt32(SQLITE_UTF8) | libc.Int32FromInt32(0)*libc.Int32FromInt32(SQLITE_FUNC_NEEDCOLL)),
FpUserData: uintptr(int64(libc.Int32FromInt32(1))),
FzName: __ccgo_ts + 17133,
},
15: {
FnArg: int16(1),
FfuncFlags: libc.Uint32FromInt32(libc.Int32FromInt32(SQLITE_FUNC_BUILTIN) | libc.Int32FromInt32(SQLITE_FUNC_CONSTANT) | libc.Int32FromInt32(SQLITE_UTF8) | libc.Int32FromInt32(0)*libc.Int32FromInt32(SQLITE_FUNC_NEEDCOLL)),
FpUserData: uintptr(int64(libc.Int32FromInt32(2))),
FzName: __ccgo_ts + 17139,
},
16: {
FnArg: int16(2),
FfuncFlags: libc.Uint32FromInt32(libc.Int32FromInt32(SQLITE_FUNC_BUILTIN) | libc.Int32FromInt32(SQLITE_FUNC_CONSTANT) | libc.Int32FromInt32(SQLITE_UTF8) | libc.Int32FromInt32(0)*libc.Int32FromInt32(SQLITE_FUNC_NEEDCOLL)),
FpUserData: uintptr(int64(libc.Int32FromInt32(2))),
FzName: __ccgo_ts + 17139,
},
17: {
FnArg: int16(1),
FfuncFlags: libc.Uint32FromInt32(libc.Int32FromInt32(SQLITE_FUNC_BUILTIN) | libc.Int32FromInt32(SQLITE_FUNC_CONSTANT) | libc.Int32FromInt32(SQLITE_UTF8) | libc.Int32FromInt32(0)*libc.Int32FromInt32(SQLITE_FUNC_NEEDCOLL)),
FpUserData: uintptr(int64(libc.Int32FromInt32(3))),
FzName: __ccgo_ts + 17145,
},
18: {
FnArg: int16(2),
FfuncFlags: libc.Uint32FromInt32(libc.Int32FromInt32(SQLITE_FUNC_BUILTIN) | libc.Int32FromInt32(SQLITE_FUNC_CONSTANT) | libc.Int32FromInt32(SQLITE_UTF8) | libc.Int32FromInt32(0)*libc.Int32FromInt32(SQLITE_FUNC_NEEDCOLL)),
FpUserData: uintptr(int64(libc.Int32FromInt32(3))),
FzName: __ccgo_ts + 17145,
},
19: {
FnArg: int16(-int32(3)),
FfuncFlags: libc.Uint32FromInt32(libc.Int32FromInt32(SQLITE_FUNC_BUILTIN) | libc.Int32FromInt32(SQLITE_FUNC_CONSTANT) | libc.Int32FromInt32(SQLITE_UTF8) | libc.Int32FromInt32(1)*libc.Int32FromInt32(SQLITE_FUNC_NEEDCOLL)),
FzName: __ccgo_ts + 17150,
},
20: {
FnArg: int16(1),
FfuncFlags: libc.Uint32FromInt32(libc.Int32FromInt32(SQLITE_FUNC_BUILTIN) | libc.Int32FromInt32(SQLITE_UTF8) | libc.Int32FromInt32(1)*libc.Int32FromInt32(SQLITE_FUNC_NEEDCOLL) | libc.Int32FromInt32(SQLITE_FUNC_MINMAX) | libc.Int32FromInt32(SQLITE_FUNC_ANYORDER)),
FzName: __ccgo_ts + 17150,
},
21: {
FnArg: int16(-int32(3)),
FfuncFlags: libc.Uint32FromInt32(libc.Int32FromInt32(SQLITE_FUNC_BUILTIN) | libc.Int32FromInt32(SQLITE_FUNC_CONSTANT) | libc.Int32FromInt32(SQLITE_UTF8) | libc.Int32FromInt32(1)*libc.Int32FromInt32(SQLITE_FUNC_NEEDCOLL)),
FpUserData: uintptr(int64(libc.Int32FromInt32(1))),
FzName: __ccgo_ts + 17154,
},
22: {
FnArg: int16(1),
FfuncFlags: libc.Uint32FromInt32(libc.Int32FromInt32(SQLITE_FUNC_BUILTIN) | libc.Int32FromInt32(SQLITE_UTF8) | libc.Int32FromInt32(1)*libc.Int32FromInt32(SQLITE_FUNC_NEEDCOLL) | libc.Int32FromInt32(SQLITE_FUNC_MINMAX) | libc.Int32FromInt32(SQLITE_FUNC_ANYORDER)),
FpUserData: uintptr(int64(libc.Int32FromInt32(1))),
FzName: __ccgo_ts + 17154,
},
23: {
FnArg: int16(1),
FfuncFlags: libc.Uint32FromInt32(libc.Int32FromInt32(SQLITE_FUNC_BUILTIN) | libc.Int32FromInt32(SQLITE_FUNC_CONSTANT) | libc.Int32FromInt32(SQLITE_UTF8) | libc.Int32FromInt32(0)*libc.Int32FromInt32(SQLITE_FUNC_NEEDCOLL) | libc.Int32FromInt32(SQLITE_FUNC_TYPEOF)),
FzName: __ccgo_ts + 17158,
},
24: {
FnArg: int16(1),
FfuncFlags: libc.Uint32FromInt32(libc.Int32FromInt32(SQLITE_FUNC_BUILTIN) | libc.Int32FromInt32(SQLITE_FUNC_CONSTANT) | libc.Int32FromInt32(SQLITE_UTF8) | libc.Int32FromInt32(0)*libc.Int32FromInt32(SQLITE_FUNC_NEEDCOLL) | libc.Int32FromInt32(SQLITE_FUNC_TYPEOF) | libc.Int32FromInt32(SQLITE_SUBTYPE)),
FzName: __ccgo_ts + 17165,
},
25: {
FnArg: int16(1),
FfuncFlags: libc.Uint32FromInt32(libc.Int32FromInt32(SQLITE_FUNC_BUILTIN) | libc.Int32FromInt32(SQLITE_FUNC_CONSTANT) | libc.Int32FromInt32(SQLITE_UTF8) | libc.Int32FromInt32(0)*libc.Int32FromInt32(SQLITE_FUNC_NEEDCOLL) | libc.Int32FromInt32(SQLITE_FUNC_LENGTH)),
FzName: __ccgo_ts + 17173,
},
26: {
FnArg: int16(1),
FfuncFlags: libc.Uint32FromInt32(libc.Int32FromInt32(SQLITE_FUNC_BUILTIN) | libc.Int32FromInt32(SQLITE_FUNC_CONSTANT) | libc.Int32FromInt32(SQLITE_UTF8) | libc.Int32FromInt32(0)*libc.Int32FromInt32(SQLITE_FUNC_NEEDCOLL) | libc.Int32FromInt32(SQLITE_FUNC_BYTELEN)),
FzName: __ccgo_ts + 17180,
},
27: {
FnArg: int16(2),
FfuncFlags: libc.Uint32FromInt32(libc.Int32FromInt32(SQLITE_FUNC_BUILTIN) | libc.Int32FromInt32(SQLITE_FUNC_CONSTANT) | libc.Int32FromInt32(SQLITE_UTF8) | libc.Int32FromInt32(0)*libc.Int32FromInt32(SQLITE_FUNC_NEEDCOLL)),
FzName: __ccgo_ts + 17193,
},
28: {
FnArg: int16(-int32(1)),
FfuncFlags: libc.Uint32FromInt32(libc.Int32FromInt32(SQLITE_FUNC_BUILTIN) | libc.Int32FromInt32(SQLITE_FUNC_CONSTANT) | libc.Int32FromInt32(SQLITE_UTF8) | libc.Int32FromInt32(0)*libc.Int32FromInt32(SQLITE_FUNC_NEEDCOLL)),
FzName: __ccgo_ts + 17199,
},
29: {
FnArg: int16(-int32(1)),
FfuncFlags: libc.Uint32FromInt32(libc.Int32FromInt32(SQLITE_FUNC_BUILTIN) | libc.Int32FromInt32(SQLITE_FUNC_CONSTANT) | libc.Int32FromInt32(SQLITE_UTF8) | libc.Int32FromInt32(0)*libc.Int32FromInt32(SQLITE_FUNC_NEEDCOLL)),
FzName: __ccgo_ts + 17206,
},
30: {
FnArg: int16(1),
FfuncFlags: libc.Uint32FromInt32(libc.Int32FromInt32(SQLITE_FUNC_BUILTIN) | libc.Int32FromInt32(SQLITE_FUNC_CONSTANT) | libc.Int32FromInt32(SQLITE_UTF8) | libc.Int32FromInt32(0)*libc.Int32FromInt32(SQLITE_FUNC_NEEDCOLL)),
FzName: __ccgo_ts + 17213,
},
31: {
FnArg: int16(-int32(1)),
FfuncFlags: libc.Uint32FromInt32(libc.Int32FromInt32(SQLITE_FUNC_BUILTIN) | libc.Int32FromInt32(SQLITE_FUNC_CONSTANT) | libc.Int32FromInt32(SQLITE_UTF8) | libc.Int32FromInt32(0)*libc.Int32FromInt32(SQLITE_FUNC_NEEDCOLL)),
FzName: __ccgo_ts + 17221,
},
32: {
FnArg: int16(1),
FfuncFlags: libc.Uint32FromInt32(libc.Int32FromInt32(SQLITE_FUNC_BUILTIN) | libc.Int32FromInt32(SQLITE_FUNC_CONSTANT) | libc.Int32FromInt32(SQLITE_UTF8) | libc.Int32FromInt32(0)*libc.Int32FromInt32(SQLITE_FUNC_NEEDCOLL)),
FzName: __ccgo_ts + 17226,
},
33: {
FnArg: int16(1),
FfuncFlags: libc.Uint32FromInt32(libc.Int32FromInt32(SQLITE_FUNC_BUILTIN) | libc.Int32FromInt32(SQLITE_FUNC_CONSTANT) | libc.Int32FromInt32(SQLITE_UTF8) | libc.Int32FromInt32(0)*libc.Int32FromInt32(SQLITE_FUNC_NEEDCOLL)),
FzName: __ccgo_ts + 17230,
},
34: {
FnArg: int16(2),
FfuncFlags: libc.Uint32FromInt32(libc.Int32FromInt32(SQLITE_FUNC_BUILTIN) | libc.Int32FromInt32(SQLITE_FUNC_CONSTANT) | libc.Int32FromInt32(SQLITE_UTF8) | libc.Int32FromInt32(0)*libc.Int32FromInt32(SQLITE_FUNC_NEEDCOLL)),
FzName: __ccgo_ts + 17230,
},
35: {
FnArg: int16(1),
FfuncFlags: libc.Uint32FromInt32(libc.Int32FromInt32(SQLITE_FUNC_BUILTIN) | libc.Int32FromInt32(SQLITE_FUNC_CONSTANT) | libc.Int32FromInt32(SQLITE_UTF8) | libc.Int32FromInt32(0)*libc.Int32FromInt32(SQLITE_FUNC_NEEDCOLL)),
FzName: __ccgo_ts + 17236,
},
36: {
FnArg: int16(1),
FfuncFlags: libc.Uint32FromInt32(libc.Int32FromInt32(SQLITE_FUNC_BUILTIN) | libc.Int32FromInt32(SQLITE_FUNC_CONSTANT) | libc.Int32FromInt32(SQLITE_UTF8) | libc.Int32FromInt32(0)*libc.Int32FromInt32(SQLITE_FUNC_NEEDCOLL)),
FzName: __ccgo_ts + 17242,
},
37: {
FnArg: int16(1),
FfuncFlags: libc.Uint32FromInt32(libc.Int32FromInt32(SQLITE_FUNC_BUILTIN) | libc.Int32FromInt32(SQLITE_FUNC_CONSTANT) | libc.Int32FromInt32(SQLITE_UTF8) | libc.Int32FromInt32(0)*libc.Int32FromInt32(SQLITE_FUNC_NEEDCOLL)),
FzName: __ccgo_ts + 17248,
},
38: {
FnArg: int16(1),
FfuncFlags: libc.Uint32FromInt32(libc.Int32FromInt32(SQLITE_FUNC_BUILTIN) | libc.Int32FromInt32(SQLITE_FUNC_CONSTANT) | libc.Int32FromInt32(SQLITE_UTF8) | libc.Int32FromInt32(0)*libc.Int32FromInt32(SQLITE_FUNC_NEEDCOLL)),
FzName: __ccgo_ts + 17252,
},
39: {
FnArg: int16(2),
FfuncFlags: libc.Uint32FromInt32(libc.Int32FromInt32(SQLITE_FUNC_BUILTIN) | libc.Int32FromInt32(SQLITE_FUNC_CONSTANT) | libc.Int32FromInt32(SQLITE_UTF8) | libc.Int32FromInt32(0)*libc.Int32FromInt32(SQLITE_FUNC_NEEDCOLL)),
FzName: __ccgo_ts + 17252,
},
40: {
FnArg: int16(-int32(3)),
FfuncFlags: libc.Uint32FromInt32(libc.Int32FromInt32(SQLITE_FUNC_BUILTIN) | libc.Int32FromInt32(SQLITE_FUNC_CONSTANT) | libc.Int32FromInt32(SQLITE_UTF8) | libc.Int32FromInt32(0)*libc.Int32FromInt32(SQLITE_FUNC_NEEDCOLL)),
FzName: __ccgo_ts + 17258,
},
41: {
FnArg: int16(-int32(4)),
FfuncFlags: libc.Uint32FromInt32(libc.Int32FromInt32(SQLITE_FUNC_BUILTIN) | libc.Int32FromInt32(SQLITE_FUNC_CONSTANT) | libc.Int32FromInt32(SQLITE_UTF8) | libc.Int32FromInt32(0)*libc.Int32FromInt32(SQLITE_FUNC_NEEDCOLL)),
FzName: __ccgo_ts + 17265,
},
42: {
FnArg: int16(2),
FfuncFlags: libc.Uint32FromInt32(libc.Int32FromInt32(SQLITE_FUNC_BUILTIN) | libc.Int32FromInt32(SQLITE_UTF8) | libc.Int32FromInt32(SQLITE_FUNC_INLINE) | libc.Int32FromInt32(SQLITE_FUNC_CONSTANT) | libc.Int32FromInt32(0)),
FzName: __ccgo_ts + 17275,
},
43: {
FfuncFlags: libc.Uint32FromInt32(libc.Int32FromInt32(SQLITE_FUNC_BUILTIN) | libc.Int32FromInt32(SQLITE_UTF8) | libc.Int32FromInt32(0)*libc.Int32FromInt32(SQLITE_FUNC_NEEDCOLL)),
FzName: __ccgo_ts + 17282,
},
44: {
FnArg: int16(1),
FfuncFlags: libc.Uint32FromInt32(libc.Int32FromInt32(SQLITE_FUNC_BUILTIN) | libc.Int32FromInt32(SQLITE_UTF8) | libc.Int32FromInt32(0)*libc.Int32FromInt32(SQLITE_FUNC_NEEDCOLL)),
FzName: __ccgo_ts + 17289,
},
45: {
FnArg: int16(2),
FfuncFlags: libc.Uint32FromInt32(libc.Int32FromInt32(SQLITE_FUNC_BUILTIN) | libc.Int32FromInt32(SQLITE_FUNC_CONSTANT) | libc.Int32FromInt32(SQLITE_UTF8) | libc.Int32FromInt32(1)*libc.Int32FromInt32(SQLITE_FUNC_NEEDCOLL)),
FzName: __ccgo_ts + 17300,
},
46: {
FfuncFlags: libc.Uint32FromInt32(libc.Int32FromInt32(SQLITE_FUNC_BUILTIN) | libc.Int32FromInt32(SQLITE_FUNC_SLOCHNG) | libc.Int32FromInt32(SQLITE_UTF8)),
FzName: __ccgo_ts + 17307,
},
47: {
FfuncFlags: libc.Uint32FromInt32(libc.Int32FromInt32(SQLITE_FUNC_BUILTIN) | libc.Int32FromInt32(SQLITE_FUNC_SLOCHNG) | libc.Int32FromInt32(SQLITE_UTF8)),
FzName: __ccgo_ts + 17322,
},
48: {
FnArg: int16(2),
FfuncFlags: libc.Uint32FromInt32(libc.Int32FromInt32(SQLITE_FUNC_BUILTIN) | libc.Int32FromInt32(SQLITE_FUNC_CONSTANT) | libc.Int32FromInt32(SQLITE_UTF8) | libc.Int32FromInt32(0)*libc.Int32FromInt32(SQLITE_FUNC_NEEDCOLL)),
FzName: __ccgo_ts + 17339,
},
49: {
FnArg: int16(1),
FfuncFlags: libc.Uint32FromInt32(libc.Int32FromInt32(SQLITE_FUNC_BUILTIN) | libc.Int32FromInt32(SQLITE_FUNC_CONSTANT) | libc.Int32FromInt32(SQLITE_UTF8) | libc.Int32FromInt32(0)*libc.Int32FromInt32(SQLITE_FUNC_NEEDCOLL)),
FzName: __ccgo_ts + 17350,
},
50: {
FnArg: int16(1),
FfuncFlags: libc.Uint32FromInt32(libc.Int32FromInt32(SQLITE_FUNC_BUILTIN) | libc.Int32FromInt32(SQLITE_FUNC_CONSTANT) | libc.Int32FromInt32(SQLITE_UTF8) | libc.Int32FromInt32(0)*libc.Int32FromInt32(SQLITE_FUNC_NEEDCOLL)),
FzName: __ccgo_ts + 17357,
},
51: {
FnArg: int16(1),
FfuncFlags: libc.Uint32FromInt32(libc.Int32FromInt32(SQLITE_FUNC_BUILTIN) | libc.Int32FromInt32(SQLITE_FUNC_CONSTANT) | libc.Int32FromInt32(SQLITE_UTF8) | libc.Int32FromInt32(0)*libc.Int32FromInt32(SQLITE_FUNC_NEEDCOLL)),
FpUserData: uintptr(int64(libc.Int32FromInt32(1))),
FzName: __ccgo_ts + 17363,
},
52: {
FfuncFlags: libc.Uint32FromInt32(libc.Int32FromInt32(SQLITE_FUNC_BUILTIN) | libc.Int32FromInt32(SQLITE_UTF8) | libc.Int32FromInt32(0)*libc.Int32FromInt32(SQLITE_FUNC_NEEDCOLL)),
FzName: __ccgo_ts + 17376,
},
53: {
FfuncFlags: libc.Uint32FromInt32(libc.Int32FromInt32(SQLITE_FUNC_BUILTIN) | libc.Int32FromInt32(SQLITE_UTF8) | libc.Int32FromInt32(0)*libc.Int32FromInt32(SQLITE_FUNC_NEEDCOLL)),
FzName: __ccgo_ts + 17394,
},
54: {
FfuncFlags: libc.Uint32FromInt32(libc.Int32FromInt32(SQLITE_FUNC_BUILTIN) | libc.Int32FromInt32(SQLITE_UTF8) | libc.Int32FromInt32(0)*libc.Int32FromInt32(SQLITE_FUNC_NEEDCOLL)),
FzName: __ccgo_ts + 17402,
},
55: {
FnArg: int16(3),
FfuncFlags: libc.Uint32FromInt32(libc.Int32FromInt32(SQLITE_FUNC_BUILTIN) | libc.Int32FromInt32(SQLITE_FUNC_CONSTANT) | libc.Int32FromInt32(SQLITE_UTF8) | libc.Int32FromInt32(0)*libc.Int32FromInt32(SQLITE_FUNC_NEEDCOLL)),
FzName: __ccgo_ts + 17416,
},
56: {
FnArg: int16(1),
FfuncFlags: libc.Uint32FromInt32(libc.Int32FromInt32(SQLITE_FUNC_BUILTIN) | libc.Int32FromInt32(SQLITE_FUNC_CONSTANT) | libc.Int32FromInt32(SQLITE_UTF8) | libc.Int32FromInt32(0)*libc.Int32FromInt32(SQLITE_FUNC_NEEDCOLL)),
FzName: __ccgo_ts + 17424,
},
57: {
FnArg: int16(2),
FfuncFlags: libc.Uint32FromInt32(libc.Int32FromInt32(SQLITE_FUNC_BUILTIN) | libc.Int32FromInt32(SQLITE_FUNC_CONSTANT) | libc.Int32FromInt32(SQLITE_UTF8) | libc.Int32FromInt32(0)*libc.Int32FromInt32(SQLITE_FUNC_NEEDCOLL)),
FzName: __ccgo_ts + 17433,
},
58: {
FnArg: int16(3),
FfuncFlags: libc.Uint32FromInt32(libc.Int32FromInt32(SQLITE_FUNC_BUILTIN) | libc.Int32FromInt32(SQLITE_FUNC_CONSTANT) | libc.Int32FromInt32(SQLITE_UTF8) | libc.Int32FromInt32(0)*libc.Int32FromInt32(SQLITE_FUNC_NEEDCOLL)),
FzName: __ccgo_ts + 17433,
},
59: {
FnArg: int16(2),
FfuncFlags: libc.Uint32FromInt32(libc.Int32FromInt32(SQLITE_FUNC_BUILTIN) | libc.Int32FromInt32(SQLITE_FUNC_CONSTANT) | libc.Int32FromInt32(SQLITE_UTF8) | libc.Int32FromInt32(0)*libc.Int32FromInt32(SQLITE_FUNC_NEEDCOLL)),
FzName: __ccgo_ts + 17440,
},
60: {
FnArg: int16(3),
FfuncFlags: libc.Uint32FromInt32(libc.Int32FromInt32(SQLITE_FUNC_BUILTIN) | libc.Int32FromInt32(SQLITE_FUNC_CONSTANT) | libc.Int32FromInt32(SQLITE_UTF8) | libc.Int32FromInt32(0)*libc.Int32FromInt32(SQLITE_FUNC_NEEDCOLL)),
FzName: __ccgo_ts + 17440,
},
61: {
FnArg: int16(1),
FfuncFlags: libc.Uint32FromInt32(libc.Int32FromInt32(SQLITE_FUNC_BUILTIN) | libc.Int32FromInt32(SQLITE_UTF8) | libc.Int32FromInt32(0)*libc.Int32FromInt32(SQLITE_FUNC_NEEDCOLL) | libc.Int32FromInt32(0)),
FzName: __ccgo_ts + 17450,
},
62: {
FnArg: int16(1),
FfuncFlags: libc.Uint32FromInt32(libc.Int32FromInt32(SQLITE_FUNC_BUILTIN) | libc.Int32FromInt32(SQLITE_UTF8) | libc.Int32FromInt32(0)*libc.Int32FromInt32(SQLITE_FUNC_NEEDCOLL) | libc.Int32FromInt32(0)),
FzName: __ccgo_ts + 17454,
},
63: {
FnArg: int16(1),
FfuncFlags: libc.Uint32FromInt32(libc.Int32FromInt32(SQLITE_FUNC_BUILTIN) | libc.Int32FromInt32(SQLITE_UTF8) | libc.Int32FromInt32(0)*libc.Int32FromInt32(SQLITE_FUNC_NEEDCOLL) | libc.Int32FromInt32(0)),
FzName: __ccgo_ts + 17460,
},
64: {
FfuncFlags: libc.Uint32FromInt32(libc.Int32FromInt32(SQLITE_FUNC_BUILTIN) | libc.Int32FromInt32(SQLITE_UTF8) | libc.Int32FromInt32(0)*libc.Int32FromInt32(SQLITE_FUNC_NEEDCOLL) | libc.Int32FromInt32(SQLITE_FUNC_COUNT) | libc.Int32FromInt32(SQLITE_FUNC_ANYORDER)),
FzName: __ccgo_ts + 17464,
},
65: {
FnArg: int16(1),
FfuncFlags: libc.Uint32FromInt32(libc.Int32FromInt32(SQLITE_FUNC_BUILTIN) | libc.Int32FromInt32(SQLITE_UTF8) | libc.Int32FromInt32(0)*libc.Int32FromInt32(SQLITE_FUNC_NEEDCOLL) | libc.Int32FromInt32(SQLITE_FUNC_ANYORDER)),
FzName: __ccgo_ts + 17464,
},
66: {
FnArg: int16(1),
FfuncFlags: libc.Uint32FromInt32(libc.Int32FromInt32(SQLITE_FUNC_BUILTIN) | libc.Int32FromInt32(SQLITE_UTF8) | libc.Int32FromInt32(0)*libc.Int32FromInt32(SQLITE_FUNC_NEEDCOLL) | libc.Int32FromInt32(0)),
FzName: __ccgo_ts + 17470,
},
67: {
FnArg: int16(2),
FfuncFlags: libc.Uint32FromInt32(libc.Int32FromInt32(SQLITE_FUNC_BUILTIN) | libc.Int32FromInt32(SQLITE_UTF8) | libc.Int32FromInt32(0)*libc.Int32FromInt32(SQLITE_FUNC_NEEDCOLL) | libc.Int32FromInt32(0)),
FzName: __ccgo_ts + 17470,
},
68: {
FnArg: int16(2),
FfuncFlags: libc.Uint32FromInt32(libc.Int32FromInt32(SQLITE_FUNC_BUILTIN) | libc.Int32FromInt32(SQLITE_UTF8) | libc.Int32FromInt32(0)*libc.Int32FromInt32(SQLITE_FUNC_NEEDCOLL) | libc.Int32FromInt32(0)),
FzName: __ccgo_ts + 17483,
},
69: {
FnArg: int16(2),
FfuncFlags: libc.Uint32FromInt32(libc.Int32FromInt32(SQLITE_FUNC_BUILTIN) | libc.Int32FromInt32(SQLITE_FUNC_CONSTANT) | libc.Int32FromInt32(SQLITE_UTF8) | libc.Int32FromInt32(SQLITE_FUNC_LIKE) | libc.Int32FromInt32(SQLITE_FUNC_CASE)),
FpUserData: uintptr(unsafe.Pointer(&_globInfo)),
FzName: __ccgo_ts + 17494,
},
70: {
FnArg: int16(2),
FfuncFlags: libc.Uint32FromInt32(libc.Int32FromInt32(SQLITE_FUNC_BUILTIN) | libc.Int32FromInt32(SQLITE_FUNC_CONSTANT) | libc.Int32FromInt32(SQLITE_UTF8) | libc.Int32FromInt32(SQLITE_FUNC_LIKE)),
FpUserData: uintptr(unsafe.Pointer(&_likeInfoNorm)),
FzName: __ccgo_ts + 16953,
},
71: {
FnArg: int16(3),
FfuncFlags: libc.Uint32FromInt32(libc.Int32FromInt32(SQLITE_FUNC_BUILTIN) | libc.Int32FromInt32(SQLITE_FUNC_CONSTANT) | libc.Int32FromInt32(SQLITE_UTF8) | libc.Int32FromInt32(SQLITE_FUNC_LIKE)),
FpUserData: uintptr(unsafe.Pointer(&_likeInfoNorm)),
FzName: __ccgo_ts + 16953,
},
72: {
FnArg: int16(1),
FfuncFlags: libc.Uint32FromInt32(libc.Int32FromInt32(SQLITE_FUNC_BUILTIN) | libc.Int32FromInt32(SQLITE_FUNC_CONSTANT) | libc.Int32FromInt32(SQLITE_UTF8)),
FzName: __ccgo_ts + 17499,
},
73: {
FnArg: int16(1),
FfuncFlags: libc.Uint32FromInt32(libc.Int32FromInt32(SQLITE_FUNC_BUILTIN) | libc.Int32FromInt32(SQLITE_FUNC_CONSTANT) | libc.Int32FromInt32(SQLITE_UTF8)),
FzName: __ccgo_ts + 1275,
},
74: {
FnArg: int16(1),
FfuncFlags: libc.Uint32FromInt32(libc.Int32FromInt32(SQLITE_FUNC_BUILTIN) | libc.Int32FromInt32(SQLITE_FUNC_CONSTANT) | libc.Int32FromInt32(SQLITE_UTF8)),
FzName: __ccgo_ts + 1283,
},
75: {
FnArg: int16(1),
FfuncFlags: libc.Uint32FromInt32(libc.Int32FromInt32(SQLITE_FUNC_BUILTIN) | libc.Int32FromInt32(SQLITE_FUNC_CONSTANT) | libc.Int32FromInt32(SQLITE_UTF8)),
FzName: __ccgo_ts + 17504,
},
76: {
FnArg: int16(1),
FfuncFlags: libc.Uint32FromInt32(libc.Int32FromInt32(SQLITE_FUNC_BUILTIN) | libc.Int32FromInt32(SQLITE_FUNC_CONSTANT) | libc.Int32FromInt32(SQLITE_UTF8) | libc.Int32FromInt32(0)*libc.Int32FromInt32(SQLITE_FUNC_NEEDCOLL)),
FzName: __ccgo_ts + 17510,
},
77: {
FnArg: int16(1),
FfuncFlags: libc.Uint32FromInt32(libc.Int32FromInt32(SQLITE_FUNC_BUILTIN) | libc.Int32FromInt32(SQLITE_FUNC_CONSTANT) | libc.Int32FromInt32(SQLITE_UTF8) | libc.Int32FromInt32(0)*libc.Int32FromInt32(SQLITE_FUNC_NEEDCOLL)),
FpUserData: uintptr(int64(libc.Int32FromInt32(1))),
FzName: __ccgo_ts + 17513,
},
78: {
FnArg: int16(1),
FfuncFlags: libc.Uint32FromInt32(libc.Int32FromInt32(SQLITE_FUNC_BUILTIN) | libc.Int32FromInt32(SQLITE_FUNC_CONSTANT) | libc.Int32FromInt32(SQLITE_UTF8) | libc.Int32FromInt32(0)*libc.Int32FromInt32(SQLITE_FUNC_NEEDCOLL)),
FpUserData: uintptr(int64(libc.Int32FromInt32(1))),
FzName: __ccgo_ts + 17517,
},
79: {
FnArg: int16(1),
FfuncFlags: libc.Uint32FromInt32(libc.Int32FromInt32(SQLITE_FUNC_BUILTIN) | libc.Int32FromInt32(SQLITE_FUNC_CONSTANT) | libc.Int32FromInt32(SQLITE_UTF8) | libc.Int32FromInt32(0)*libc.Int32FromInt32(SQLITE_FUNC_NEEDCOLL)),
FpUserData: uintptr(int64(libc.Int32FromInt32(2))),
FzName: __ccgo_ts + 17523,
},
80: {
FnArg: int16(2),
FfuncFlags: libc.Uint32FromInt32(libc.Int32FromInt32(SQLITE_FUNC_BUILTIN) | libc.Int32FromInt32(SQLITE_FUNC_CONSTANT) | libc.Int32FromInt32(SQLITE_UTF8) | libc.Int32FromInt32(0)*libc.Int32FromInt32(SQLITE_FUNC_NEEDCOLL)),
FzName: __ccgo_ts + 17513,
},
81: {
FnArg: int16(1),
FfuncFlags: libc.Uint32FromInt32(libc.Int32FromInt32(SQLITE_FUNC_BUILTIN) | libc.Int32FromInt32(SQLITE_FUNC_CONSTANT) | libc.Int32FromInt32(SQLITE_UTF8)),
FzName: __ccgo_ts + 17528,
},
82: {
FnArg: int16(2),
FfuncFlags: libc.Uint32FromInt32(libc.Int32FromInt32(SQLITE_FUNC_BUILTIN) | libc.Int32FromInt32(SQLITE_FUNC_CONSTANT) | libc.Int32FromInt32(SQLITE_UTF8)),
FzName: __ccgo_ts + 17532,
},
83: {
FnArg: int16(2),
FfuncFlags: libc.Uint32FromInt32(libc.Int32FromInt32(SQLITE_FUNC_BUILTIN) | libc.Int32FromInt32(SQLITE_FUNC_CONSTANT) | libc.Int32FromInt32(SQLITE_UTF8)),
FzName: __ccgo_ts + 17536,
},
84: {
FnArg: int16(2),
FfuncFlags: libc.Uint32FromInt32(libc.Int32FromInt32(SQLITE_FUNC_BUILTIN) | libc.Int32FromInt32(SQLITE_FUNC_CONSTANT) | libc.Int32FromInt32(SQLITE_UTF8)),
FzName: __ccgo_ts + 17542,
},
85: {
FnArg: int16(1),
FfuncFlags: libc.Uint32FromInt32(libc.Int32FromInt32(SQLITE_FUNC_BUILTIN) | libc.Int32FromInt32(SQLITE_FUNC_CONSTANT) | libc.Int32FromInt32(SQLITE_UTF8)),
FzName: __ccgo_ts + 17546,
},
86: {
FnArg: int16(1),
FfuncFlags: libc.Uint32FromInt32(libc.Int32FromInt32(SQLITE_FUNC_BUILTIN) | libc.Int32FromInt32(SQLITE_FUNC_CONSTANT) | libc.Int32FromInt32(SQLITE_UTF8)),
FzName: __ccgo_ts + 17551,
},
87: {
FnArg: int16(1),
FfuncFlags: libc.Uint32FromInt32(libc.Int32FromInt32(SQLITE_FUNC_BUILTIN) | libc.Int32FromInt32(SQLITE_FUNC_CONSTANT) | libc.Int32FromInt32(SQLITE_UTF8)),
FzName: __ccgo_ts + 17556,
},
88: {
FnArg: int16(2),
FfuncFlags: libc.Uint32FromInt32(libc.Int32FromInt32(SQLITE_FUNC_BUILTIN) | libc.Int32FromInt32(SQLITE_FUNC_CONSTANT) | libc.Int32FromInt32(SQLITE_UTF8)),
FzName: __ccgo_ts + 17561,
},
89: {
FnArg: int16(1),
FfuncFlags: libc.Uint32FromInt32(libc.Int32FromInt32(SQLITE_FUNC_BUILTIN) | libc.Int32FromInt32(SQLITE_FUNC_CONSTANT) | libc.Int32FromInt32(SQLITE_UTF8)),
FzName: __ccgo_ts + 17567,
},
90: {
FnArg: int16(1),
FfuncFlags: libc.Uint32FromInt32(libc.Int32FromInt32(SQLITE_FUNC_BUILTIN) | libc.Int32FromInt32(SQLITE_FUNC_CONSTANT) | libc.Int32FromInt32(SQLITE_UTF8)),
FzName: __ccgo_ts + 17571,
},
91: {
FnArg: int16(1),
FfuncFlags: libc.Uint32FromInt32(libc.Int32FromInt32(SQLITE_FUNC_BUILTIN) | libc.Int32FromInt32(SQLITE_FUNC_CONSTANT) | libc.Int32FromInt32(SQLITE_UTF8)),
FzName: __ccgo_ts + 17575,
},
92: {
FnArg: int16(1),
FfuncFlags: libc.Uint32FromInt32(libc.Int32FromInt32(SQLITE_FUNC_BUILTIN) | libc.Int32FromInt32(SQLITE_FUNC_CONSTANT) | libc.Int32FromInt32(SQLITE_UTF8)),
FzName: __ccgo_ts + 17579,
},
93: {
FnArg: int16(1),
FfuncFlags: libc.Uint32FromInt32(libc.Int32FromInt32(SQLITE_FUNC_BUILTIN) | libc.Int32FromInt32(SQLITE_FUNC_CONSTANT) | libc.Int32FromInt32(SQLITE_UTF8)),
FzName: __ccgo_ts + 17584,
},
94: {
FnArg: int16(1),
FfuncFlags: libc.Uint32FromInt32(libc.Int32FromInt32(SQLITE_FUNC_BUILTIN) | libc.Int32FromInt32(SQLITE_FUNC_CONSTANT) | libc.Int32FromInt32(SQLITE_UTF8)),
FzName: __ccgo_ts + 17589,
},
95: {
FnArg: int16(1),
FfuncFlags: libc.Uint32FromInt32(libc.Int32FromInt32(SQLITE_FUNC_BUILTIN) | libc.Int32FromInt32(SQLITE_FUNC_CONSTANT) | libc.Int32FromInt32(SQLITE_UTF8)),
FzName: __ccgo_ts + 17594,
},
96: {
FnArg: int16(1),
FfuncFlags: libc.Uint32FromInt32(libc.Int32FromInt32(SQLITE_FUNC_BUILTIN) | libc.Int32FromInt32(SQLITE_FUNC_CONSTANT) | libc.Int32FromInt32(SQLITE_UTF8)),
FzName: __ccgo_ts + 17600,
},
97: {
FnArg: int16(1),
FfuncFlags: libc.Uint32FromInt32(libc.Int32FromInt32(SQLITE_FUNC_BUILTIN) | libc.Int32FromInt32(SQLITE_FUNC_CONSTANT) | libc.Int32FromInt32(SQLITE_UTF8)),
FzName: __ccgo_ts + 17606,
},
98: {
FnArg: int16(1),
FfuncFlags: libc.Uint32FromInt32(libc.Int32FromInt32(SQLITE_FUNC_BUILTIN) | libc.Int32FromInt32(SQLITE_FUNC_CONSTANT) | libc.Int32FromInt32(SQLITE_UTF8)),
FzName: __ccgo_ts + 17612,
},
99: {
FnArg: int16(1),
FfuncFlags: libc.Uint32FromInt32(libc.Int32FromInt32(SQLITE_FUNC_BUILTIN) | libc.Int32FromInt32(SQLITE_FUNC_CONSTANT) | libc.Int32FromInt32(SQLITE_UTF8)),
FzName: __ccgo_ts + 17617,
},
100: {
FnArg: int16(1),
FfuncFlags: libc.Uint32FromInt32(libc.Int32FromInt32(SQLITE_FUNC_BUILTIN) | libc.Int32FromInt32(SQLITE_FUNC_CONSTANT) | libc.Int32FromInt32(SQLITE_UTF8)),
FzName: __ccgo_ts + 17625,
},
101: {
FfuncFlags: libc.Uint32FromInt32(libc.Int32FromInt32(SQLITE_FUNC_BUILTIN) | libc.Int32FromInt32(SQLITE_FUNC_CONSTANT) | libc.Int32FromInt32(SQLITE_UTF8)),
FzName: __ccgo_ts + 17633,
},
102: {
FnArg: int16(1),
FfuncFlags: libc.Uint32FromInt32(libc.Int32FromInt32(SQLITE_FUNC_BUILTIN) | libc.Int32FromInt32(SQLITE_FUNC_CONSTANT) | libc.Int32FromInt32(SQLITE_UTF8) | libc.Int32FromInt32(0)*libc.Int32FromInt32(SQLITE_FUNC_NEEDCOLL)),
FzName: __ccgo_ts + 17636,
},
103: {
FnArg: int16(-int32(4)),
FfuncFlags: libc.Uint32FromInt32(libc.Int32FromInt32(SQLITE_FUNC_BUILTIN) | libc.Int32FromInt32(SQLITE_UTF8) | libc.Int32FromInt32(SQLITE_FUNC_INLINE) | libc.Int32FromInt32(SQLITE_FUNC_CONSTANT) | libc.Int32FromInt32(0)),
FzName: __ccgo_ts + 7309,
},
104: {
FnArg: int16(-int32(4)),
FfuncFlags: libc.Uint32FromInt32(libc.Int32FromInt32(SQLITE_FUNC_BUILTIN) | libc.Int32FromInt32(SQLITE_UTF8) | libc.Int32FromInt32(SQLITE_FUNC_INLINE) | libc.Int32FromInt32(SQLITE_FUNC_CONSTANT) | libc.Int32FromInt32(0)),
FpUserData: uintptr(int64(libc.Int32FromInt32(INLINEFUNC_iif))),
FzName: __ccgo_ts + 17641,
},
105: {
FnArg: int16(-int32(4)),
FfuncFlags: libc.Uint32FromInt32(libc.Int32FromInt32(SQLITE_FUNC_BUILTIN) | libc.Int32FromInt32(SQLITE_UTF8) | libc.Int32FromInt32(SQLITE_FUNC_INLINE) | libc.Int32FromInt32(SQLITE_FUNC_CONSTANT) | libc.Int32FromInt32(0)),
FpUserData: uintptr(int64(libc.Int32FromInt32(INLINEFUNC_iif))),
FzName: __ccgo_ts + 17645,
},
}
var _aCacheMode = [3]struct {
Fz uintptr
Fmode int32
}{
0: {
Fz: __ccgo_ts + 26563,
Fmode: int32(SQLITE_OPEN_SHAREDCACHE),
},
1: {
Fz: __ccgo_ts + 26570,
Fmode: int32(SQLITE_OPEN_PRIVATECACHE),
},
2: {},
}
var _aFunc = [12]struct {
FxFunc uintptr
FnArg int8
FbPure uint8
FzName uintptr
}{
0: {
FnArg: int8(1),
FbPure: uint8(1),
FzName: __ccgo_ts + 30450,
},
1: {
FnArg: int8(1),
FbPure: uint8(1),
FzName: __ccgo_ts + 30463,
},
2: {
FnArg: int8(1),
FbPure: uint8(1),
FzName: __ccgo_ts + 30476,
},
3: {
FnArg: int8(-int32(1)),
FbPure: uint8(1),
FzName: __ccgo_ts + 30489,
},
4: {
FnArg: int8(2),
FbPure: uint8(1),
FzName: __ccgo_ts + 30435,
},
5: {
FnArg: int8(3),
FbPure: uint8(1),
FzName: __ccgo_ts + 30501,
},
6: {
FnArg: int8(2),
FbPure: uint8(1),
FzName: __ccgo_ts + 30419,
},
7: {
FnArg: int8(1),
FzName: __ccgo_ts + 30524,
},
8: {
FnArg: int8(1),
FbPure: uint8(1),
FzName: __ccgo_ts + 30538,
},
9: {
FnArg: int8(7),
FbPure: uint8(1),
FzName: __ccgo_ts + 30551,
},
10: {
FnArg: int8(4),
FbPure: uint8(1),
FzName: __ccgo_ts + 30565,
},
11: {
FnArg: int8(1),
FbPure: uint8(1),
FzName: __ccgo_ts + 30581,
},
}
var _aJsonFunc = [36]TFuncDef{
0: {
FnArg: int16(1),
FfuncFlags: libc.Uint32FromInt32(libc.Int32FromInt32(SQLITE_FUNC_BUILTIN) | libc.Int32FromInt32(SQLITE_DETERMINISTIC) | libc.Int32FromInt32(SQLITE_FUNC_CONSTANT) | libc.Int32FromInt32(SQLITE_UTF8) | libc.Int32FromInt32(1)*libc.Int32FromInt32(SQLITE_FUNC_RUNONLY) | libc.Int32FromInt32(0)*libc.Int32FromInt32(SQLITE_SUBTYPE) | libc.Int32FromInt32(1)*libc.Int32FromInt32(SQLITE_RESULT_SUBTYPE)),
FzName: __ccgo_ts + 14042,
},
1: {
FnArg: int16(1),
FfuncFlags: libc.Uint32FromInt32(libc.Int32FromInt32(SQLITE_FUNC_BUILTIN) | libc.Int32FromInt32(SQLITE_DETERMINISTIC) | libc.Int32FromInt32(SQLITE_FUNC_CONSTANT) | libc.Int32FromInt32(SQLITE_UTF8) | libc.Int32FromInt32(1)*libc.Int32FromInt32(SQLITE_FUNC_RUNONLY) | libc.Int32FromInt32(0)*libc.Int32FromInt32(SQLITE_SUBTYPE) | libc.Int32FromInt32(0)*libc.Int32FromInt32(SQLITE_RESULT_SUBTYPE)),
FpUserData: uintptr(int64(libc.Int32FromInt32(0) | libc.Int32FromInt32(1)*libc.Int32FromInt32(JSON_BLOB))),
FzName: __ccgo_ts + 27359,
},
2: {
FnArg: int16(-int32(1)),
FfuncFlags: libc.Uint32FromInt32(libc.Int32FromInt32(SQLITE_FUNC_BUILTIN) | libc.Int32FromInt32(SQLITE_DETERMINISTIC) | libc.Int32FromInt32(SQLITE_FUNC_CONSTANT) | libc.Int32FromInt32(SQLITE_UTF8) | libc.Int32FromInt32(0)*libc.Int32FromInt32(SQLITE_FUNC_RUNONLY) | libc.Int32FromInt32(1)*libc.Int32FromInt32(SQLITE_SUBTYPE) | libc.Int32FromInt32(1)*libc.Int32FromInt32(SQLITE_RESULT_SUBTYPE)),
FzName: __ccgo_ts + 27365,
},
3: {
FnArg: int16(-int32(1)),
FfuncFlags: libc.Uint32FromInt32(libc.Int32FromInt32(SQLITE_FUNC_BUILTIN) | libc.Int32FromInt32(SQLITE_DETERMINISTIC) | libc.Int32FromInt32(SQLITE_FUNC_CONSTANT) | libc.Int32FromInt32(SQLITE_UTF8) | libc.Int32FromInt32(0)*libc.Int32FromInt32(SQLITE_FUNC_RUNONLY) | libc.Int32FromInt32(1)*libc.Int32FromInt32(SQLITE_SUBTYPE) | libc.Int32FromInt32(1)*libc.Int32FromInt32(SQLITE_RESULT_SUBTYPE)),
FpUserData: uintptr(int64(libc.Int32FromInt32(0) | libc.Int32FromInt32(1)*libc.Int32FromInt32(JSON_BLOB))),
FzName: __ccgo_ts + 27376,
},
4: {
FnArg: int16(-int32(1)),
FfuncFlags: libc.Uint32FromInt32(libc.Int32FromInt32(SQLITE_FUNC_BUILTIN) | libc.Int32FromInt32(SQLITE_DETERMINISTIC) | libc.Int32FromInt32(SQLITE_FUNC_CONSTANT) | libc.Int32FromInt32(SQLITE_UTF8) | libc.Int32FromInt32(1)*libc.Int32FromInt32(SQLITE_FUNC_RUNONLY) | libc.Int32FromInt32(1)*libc.Int32FromInt32(SQLITE_SUBTYPE) | libc.Int32FromInt32(1)*libc.Int32FromInt32(SQLITE_RESULT_SUBTYPE)),
FpUserData: uintptr(int64(libc.Int32FromInt32(JSON_AINS) | libc.Int32FromInt32(0)*libc.Int32FromInt32(JSON_BLOB))),
FzName: __ccgo_ts + 27388,
},
5: {
FnArg: int16(-int32(1)),
FfuncFlags: libc.Uint32FromInt32(libc.Int32FromInt32(SQLITE_FUNC_BUILTIN) | libc.Int32FromInt32(SQLITE_DETERMINISTIC) | libc.Int32FromInt32(SQLITE_FUNC_CONSTANT) | libc.Int32FromInt32(SQLITE_UTF8) | libc.Int32FromInt32(1)*libc.Int32FromInt32(SQLITE_FUNC_RUNONLY) | libc.Int32FromInt32(1)*libc.Int32FromInt32(SQLITE_SUBTYPE) | libc.Int32FromInt32(0)*libc.Int32FromInt32(SQLITE_RESULT_SUBTYPE)),
FpUserData: uintptr(int64(libc.Int32FromInt32(JSON_AINS) | libc.Int32FromInt32(1)*libc.Int32FromInt32(JSON_BLOB))),
FzName: __ccgo_ts + 27406,
},
6: {
FnArg: int16(1),
FfuncFlags: libc.Uint32FromInt32(libc.Int32FromInt32(SQLITE_FUNC_BUILTIN) | libc.Int32FromInt32(SQLITE_DETERMINISTIC) | libc.Int32FromInt32(SQLITE_FUNC_CONSTANT) | libc.Int32FromInt32(SQLITE_UTF8) | libc.Int32FromInt32(1)*libc.Int32FromInt32(SQLITE_FUNC_RUNONLY) | libc.Int32FromInt32(0)*libc.Int32FromInt32(SQLITE_SUBTYPE) | libc.Int32FromInt32(0)*libc.Int32FromInt32(SQLITE_RESULT_SUBTYPE)),
FzName: __ccgo_ts + 27425,
},
7: {
FnArg: int16(2),
FfuncFlags: libc.Uint32FromInt32(libc.Int32FromInt32(SQLITE_FUNC_BUILTIN) | libc.Int32FromInt32(SQLITE_DETERMINISTIC) | libc.Int32FromInt32(SQLITE_FUNC_CONSTANT) | libc.Int32FromInt32(SQLITE_UTF8) | libc.Int32FromInt32(1)*libc.Int32FromInt32(SQLITE_FUNC_RUNONLY) | libc.Int32FromInt32(0)*libc.Int32FromInt32(SQLITE_SUBTYPE) | libc.Int32FromInt32(0)*libc.Int32FromInt32(SQLITE_RESULT_SUBTYPE)),
FzName: __ccgo_ts + 27425,
},
8: {
FnArg: int16(1),
FfuncFlags: libc.Uint32FromInt32(libc.Int32FromInt32(SQLITE_FUNC_BUILTIN) | libc.Int32FromInt32(SQLITE_DETERMINISTIC) | libc.Int32FromInt32(SQLITE_FUNC_CONSTANT) | libc.Int32FromInt32(SQLITE_UTF8) | libc.Int32FromInt32(1)*libc.Int32FromInt32(SQLITE_FUNC_RUNONLY) | libc.Int32FromInt32(0)*libc.Int32FromInt32(SQLITE_SUBTYPE) | libc.Int32FromInt32(0)*libc.Int32FromInt32(SQLITE_RESULT_SUBTYPE)),
FzName: __ccgo_ts + 27443,
},
9: {
FnArg: int16(-int32(1)),
FfuncFlags: libc.Uint32FromInt32(libc.Int32FromInt32(SQLITE_FUNC_BUILTIN) | libc.Int32FromInt32(SQLITE_DETERMINISTIC) | libc.Int32FromInt32(SQLITE_FUNC_CONSTANT) | libc.Int32FromInt32(SQLITE_UTF8) | libc.Int32FromInt32(1)*libc.Int32FromInt32(SQLITE_FUNC_RUNONLY) | libc.Int32FromInt32(0)*libc.Int32FromInt32(SQLITE_SUBTYPE) | libc.Int32FromInt32(1)*libc.Int32FromInt32(SQLITE_RESULT_SUBTYPE)),
FzName: __ccgo_ts + 27463,
},
10: {
FnArg: int16(-int32(1)),
FfuncFlags: libc.Uint32FromInt32(libc.Int32FromInt32(SQLITE_FUNC_BUILTIN) | libc.Int32FromInt32(SQLITE_DETERMINISTIC) | libc.Int32FromInt32(SQLITE_FUNC_CONSTANT) | libc.Int32FromInt32(SQLITE_UTF8) | libc.Int32FromInt32(1)*libc.Int32FromInt32(SQLITE_FUNC_RUNONLY) | libc.Int32FromInt32(0)*libc.Int32FromInt32(SQLITE_SUBTYPE) | libc.Int32FromInt32(0)*libc.Int32FromInt32(SQLITE_RESULT_SUBTYPE)),
FpUserData: uintptr(int64(libc.Int32FromInt32(0) | libc.Int32FromInt32(1)*libc.Int32FromInt32(JSON_BLOB))),
FzName: __ccgo_ts + 27476,
},
11: {
FnArg: int16(2),
FfuncFlags: libc.Uint32FromInt32(libc.Int32FromInt32(SQLITE_FUNC_BUILTIN) | libc.Int32FromInt32(SQLITE_DETERMINISTIC) | libc.Int32FromInt32(SQLITE_FUNC_CONSTANT) | libc.Int32FromInt32(SQLITE_UTF8) | libc.Int32FromInt32(1)*libc.Int32FromInt32(SQLITE_FUNC_RUNONLY) | libc.Int32FromInt32(0)*libc.Int32FromInt32(SQLITE_SUBTYPE) | libc.Int32FromInt32(1)*libc.Int32FromInt32(SQLITE_RESULT_SUBTYPE)),
FpUserData: uintptr(int64(libc.Int32FromInt32(JSON_JSON) | libc.Int32FromInt32(0)*libc.Int32FromInt32(JSON_BLOB))),
FzName: __ccgo_ts + 27490,
},
12: {
FnArg: int16(2),
FfuncFlags: libc.Uint32FromInt32(libc.Int32FromInt32(SQLITE_FUNC_BUILTIN) | libc.Int32FromInt32(SQLITE_DETERMINISTIC) | libc.Int32FromInt32(SQLITE_FUNC_CONSTANT) | libc.Int32FromInt32(SQLITE_UTF8) | libc.Int32FromInt32(1)*libc.Int32FromInt32(SQLITE_FUNC_RUNONLY) | libc.Int32FromInt32(0)*libc.Int32FromInt32(SQLITE_SUBTYPE) | libc.Int32FromInt32(0)*libc.Int32FromInt32(SQLITE_RESULT_SUBTYPE)),
FpUserData: uintptr(int64(libc.Int32FromInt32(JSON_SQL) | libc.Int32FromInt32(0)*libc.Int32FromInt32(JSON_BLOB))),
FzName: __ccgo_ts + 27493,
},
13: {
FnArg: int16(-int32(1)),
FfuncFlags: libc.Uint32FromInt32(libc.Int32FromInt32(SQLITE_FUNC_BUILTIN) | libc.Int32FromInt32(SQLITE_DETERMINISTIC) | libc.Int32FromInt32(SQLITE_FUNC_CONSTANT) | libc.Int32FromInt32(SQLITE_UTF8) | libc.Int32FromInt32(1)*libc.Int32FromInt32(SQLITE_FUNC_RUNONLY) | libc.Int32FromInt32(1)*libc.Int32FromInt32(SQLITE_SUBTYPE) | libc.Int32FromInt32(1)*libc.Int32FromInt32(SQLITE_RESULT_SUBTYPE)),
FzName: __ccgo_ts + 27497,
},
14: {
FnArg: int16(-int32(1)),
FfuncFlags: libc.Uint32FromInt32(libc.Int32FromInt32(SQLITE_FUNC_BUILTIN) | libc.Int32FromInt32(SQLITE_DETERMINISTIC) | libc.Int32FromInt32(SQLITE_FUNC_CONSTANT) | libc.Int32FromInt32(SQLITE_UTF8) | libc.Int32FromInt32(1)*libc.Int32FromInt32(SQLITE_FUNC_RUNONLY) | libc.Int32FromInt32(1)*libc.Int32FromInt32(SQLITE_SUBTYPE) | libc.Int32FromInt32(0)*libc.Int32FromInt32(SQLITE_RESULT_SUBTYPE)),
FpUserData: uintptr(int64(libc.Int32FromInt32(0) | libc.Int32FromInt32(1)*libc.Int32FromInt32(JSON_BLOB))),
FzName: __ccgo_ts + 27509,
},
15: {
FnArg: int16(-int32(1)),
FfuncFlags: libc.Uint32FromInt32(libc.Int32FromInt32(SQLITE_FUNC_BUILTIN) | libc.Int32FromInt32(SQLITE_DETERMINISTIC) | libc.Int32FromInt32(SQLITE_FUNC_CONSTANT) | libc.Int32FromInt32(SQLITE_UTF8) | libc.Int32FromInt32(0)*libc.Int32FromInt32(SQLITE_FUNC_RUNONLY) | libc.Int32FromInt32(1)*libc.Int32FromInt32(SQLITE_SUBTYPE) | libc.Int32FromInt32(1)*libc.Int32FromInt32(SQLITE_RESULT_SUBTYPE)),
FzName: __ccgo_ts + 27522,
},
16: {
FnArg: int16(-int32(1)),
FfuncFlags: libc.Uint32FromInt32(libc.Int32FromInt32(SQLITE_FUNC_BUILTIN) | libc.Int32FromInt32(SQLITE_DETERMINISTIC) | libc.Int32FromInt32(SQLITE_FUNC_CONSTANT) | libc.Int32FromInt32(SQLITE_UTF8) | libc.Int32FromInt32(0)*libc.Int32FromInt32(SQLITE_FUNC_RUNONLY) | libc.Int32FromInt32(1)*libc.Int32FromInt32(SQLITE_SUBTYPE) | libc.Int32FromInt32(1)*libc.Int32FromInt32(SQLITE_RESULT_SUBTYPE)),
FpUserData: uintptr(int64(libc.Int32FromInt32(0) | libc.Int32FromInt32(1)*libc.Int32FromInt32(JSON_BLOB))),
FzName: __ccgo_ts + 27534,
},
17: {
FnArg: int16(2),
FfuncFlags: libc.Uint32FromInt32(libc.Int32FromInt32(SQLITE_FUNC_BUILTIN) | libc.Int32FromInt32(SQLITE_DETERMINISTIC) | libc.Int32FromInt32(SQLITE_FUNC_CONSTANT) | libc.Int32FromInt32(SQLITE_UTF8) | libc.Int32FromInt32(1)*libc.Int32FromInt32(SQLITE_FUNC_RUNONLY) | libc.Int32FromInt32(0)*libc.Int32FromInt32(SQLITE_SUBTYPE) | libc.Int32FromInt32(1)*libc.Int32FromInt32(SQLITE_RESULT_SUBTYPE)),
FzName: __ccgo_ts + 27547,
},
18: {
FnArg: int16(2),
FfuncFlags: libc.Uint32FromInt32(libc.Int32FromInt32(SQLITE_FUNC_BUILTIN) | libc.Int32FromInt32(SQLITE_DETERMINISTIC) | libc.Int32FromInt32(SQLITE_FUNC_CONSTANT) | libc.Int32FromInt32(SQLITE_UTF8) | libc.Int32FromInt32(1)*libc.Int32FromInt32(SQLITE_FUNC_RUNONLY) | libc.Int32FromInt32(0)*libc.Int32FromInt32(SQLITE_SUBTYPE) | libc.Int32FromInt32(0)*libc.Int32FromInt32(SQLITE_RESULT_SUBTYPE)),
FpUserData: uintptr(int64(libc.Int32FromInt32(0) | libc.Int32FromInt32(1)*libc.Int32FromInt32(JSON_BLOB))),
FzName: __ccgo_ts + 27558,
},
19: {
FnArg: int16(1),
FfuncFlags: libc.Uint32FromInt32(libc.Int32FromInt32(SQLITE_FUNC_BUILTIN) | libc.Int32FromInt32(SQLITE_DETERMINISTIC) | libc.Int32FromInt32(SQLITE_FUNC_CONSTANT) | libc.Int32FromInt32(SQLITE_UTF8) | libc.Int32FromInt32(1)*libc.Int32FromInt32(SQLITE_FUNC_RUNONLY) | libc.Int32FromInt32(0)*libc.Int32FromInt32(SQLITE_SUBTYPE) | libc.Int32FromInt32(0)*libc.Int32FromInt32(SQLITE_RESULT_SUBTYPE)),
FzName: __ccgo_ts + 27570,
},
20: {
FnArg: int16(2),
FfuncFlags: libc.Uint32FromInt32(libc.Int32FromInt32(SQLITE_FUNC_BUILTIN) | libc.Int32FromInt32(SQLITE_DETERMINISTIC) | libc.Int32FromInt32(SQLITE_FUNC_CONSTANT) | libc.Int32FromInt32(SQLITE_UTF8) | libc.Int32FromInt32(1)*libc.Int32FromInt32(SQLITE_FUNC_RUNONLY) | libc.Int32FromInt32(0)*libc.Int32FromInt32(SQLITE_SUBTYPE) | libc.Int32FromInt32(0)*libc.Int32FromInt32(SQLITE_RESULT_SUBTYPE)),
FzName: __ccgo_ts + 27570,
},
21: {
FnArg: int16(1),
FfuncFlags: libc.Uint32FromInt32(libc.Int32FromInt32(SQLITE_FUNC_BUILTIN) | libc.Int32FromInt32(SQLITE_DETERMINISTIC) | libc.Int32FromInt32(SQLITE_FUNC_CONSTANT) | libc.Int32FromInt32(SQLITE_UTF8) | libc.Int32FromInt32(0)*libc.Int32FromInt32(SQLITE_FUNC_RUNONLY) | libc.Int32FromInt32(1)*libc.Int32FromInt32(SQLITE_SUBTYPE) | libc.Int32FromInt32(1)*libc.Int32FromInt32(SQLITE_RESULT_SUBTYPE)),
FzName: __ccgo_ts + 27582,
},
22: {
FnArg: int16(-int32(1)),
FfuncFlags: libc.Uint32FromInt32(libc.Int32FromInt32(SQLITE_FUNC_BUILTIN) | libc.Int32FromInt32(SQLITE_DETERMINISTIC) | libc.Int32FromInt32(SQLITE_FUNC_CONSTANT) | libc.Int32FromInt32(SQLITE_UTF8) | libc.Int32FromInt32(1)*libc.Int32FromInt32(SQLITE_FUNC_RUNONLY) | libc.Int32FromInt32(0)*libc.Int32FromInt32(SQLITE_SUBTYPE) | libc.Int32FromInt32(1)*libc.Int32FromInt32(SQLITE_RESULT_SUBTYPE)),
FzName: __ccgo_ts + 27593,
},
23: {
FnArg: int16(-int32(1)),
FfuncFlags: libc.Uint32FromInt32(libc.Int32FromInt32(SQLITE_FUNC_BUILTIN) | libc.Int32FromInt32(SQLITE_DETERMINISTIC) | libc.Int32FromInt32(SQLITE_FUNC_CONSTANT) | libc.Int32FromInt32(SQLITE_UTF8) | libc.Int32FromInt32(1)*libc.Int32FromInt32(SQLITE_FUNC_RUNONLY) | libc.Int32FromInt32(0)*libc.Int32FromInt32(SQLITE_SUBTYPE) | libc.Int32FromInt32(0)*libc.Int32FromInt32(SQLITE_RESULT_SUBTYPE)),
FpUserData: uintptr(int64(libc.Int32FromInt32(0) | libc.Int32FromInt32(1)*libc.Int32FromInt32(JSON_BLOB))),
FzName: __ccgo_ts + 27605,
},
24: {
FnArg: int16(-int32(1)),
FfuncFlags: libc.Uint32FromInt32(libc.Int32FromInt32(SQLITE_FUNC_BUILTIN) | libc.Int32FromInt32(SQLITE_DETERMINISTIC) | libc.Int32FromInt32(SQLITE_FUNC_CONSTANT) | libc.Int32FromInt32(SQLITE_UTF8) | libc.Int32FromInt32(1)*libc.Int32FromInt32(SQLITE_FUNC_RUNONLY) | libc.Int32FromInt32(1)*libc.Int32FromInt32(SQLITE_SUBTYPE) | libc.Int32FromInt32(1)*libc.Int32FromInt32(SQLITE_RESULT_SUBTYPE)),
FzName: __ccgo_ts + 27618,
},
25: {
FnArg: int16(-int32(1)),
FfuncFlags: libc.Uint32FromInt32(libc.Int32FromInt32(SQLITE_FUNC_BUILTIN) | libc.Int32FromInt32(SQLITE_DETERMINISTIC) | libc.Int32FromInt32(SQLITE_FUNC_CONSTANT) | libc.Int32FromInt32(SQLITE_UTF8) | libc.Int32FromInt32(1)*libc.Int32FromInt32(SQLITE_FUNC_RUNONLY) | libc.Int32FromInt32(1)*libc.Int32FromInt32(SQLITE_SUBTYPE) | libc.Int32FromInt32(0)*libc.Int32FromInt32(SQLITE_RESULT_SUBTYPE)),
FpUserData: uintptr(int64(libc.Int32FromInt32(0) | libc.Int32FromInt32(1)*libc.Int32FromInt32(JSON_BLOB))),
FzName: __ccgo_ts + 27631,
},
26: {
FnArg: int16(-int32(1)),
FfuncFlags: libc.Uint32FromInt32(libc.Int32FromInt32(SQLITE_FUNC_BUILTIN) | libc.Int32FromInt32(SQLITE_DETERMINISTIC) | libc.Int32FromInt32(SQLITE_FUNC_CONSTANT) | libc.Int32FromInt32(SQLITE_UTF8) | libc.Int32FromInt32(1)*libc.Int32FromInt32(SQLITE_FUNC_RUNONLY) | libc.Int32FromInt32(1)*libc.Int32FromInt32(SQLITE_SUBTYPE) | libc.Int32FromInt32(1)*libc.Int32FromInt32(SQLITE_RESULT_SUBTYPE)),
FpUserData: uintptr(int64(libc.Int32FromInt32(JSON_ISSET) | libc.Int32FromInt32(0)*libc.Int32FromInt32(JSON_BLOB))),
FzName: __ccgo_ts + 27645,
},
27: {
FnArg: int16(-int32(1)),
FfuncFlags: libc.Uint32FromInt32(libc.Int32FromInt32(SQLITE_FUNC_BUILTIN) | libc.Int32FromInt32(SQLITE_DETERMINISTIC) | libc.Int32FromInt32(SQLITE_FUNC_CONSTANT) | libc.Int32FromInt32(SQLITE_UTF8) | libc.Int32FromInt32(1)*libc.Int32FromInt32(SQLITE_FUNC_RUNONLY) | libc.Int32FromInt32(1)*libc.Int32FromInt32(SQLITE_SUBTYPE) | libc.Int32FromInt32(0)*libc.Int32FromInt32(SQLITE_RESULT_SUBTYPE)),
FpUserData: uintptr(int64(libc.Int32FromInt32(JSON_ISSET) | libc.Int32FromInt32(1)*libc.Int32FromInt32(JSON_BLOB))),
FzName: __ccgo_ts + 27654,
},
28: {
FnArg: int16(1),
FfuncFlags: libc.Uint32FromInt32(libc.Int32FromInt32(SQLITE_FUNC_BUILTIN) | libc.Int32FromInt32(SQLITE_DETERMINISTIC) | libc.Int32FromInt32(SQLITE_FUNC_CONSTANT) | libc.Int32FromInt32(SQLITE_UTF8) | libc.Int32FromInt32(1)*libc.Int32FromInt32(SQLITE_FUNC_RUNONLY) | libc.Int32FromInt32(0)*libc.Int32FromInt32(SQLITE_SUBTYPE) | libc.Int32FromInt32(0)*libc.Int32FromInt32(SQLITE_RESULT_SUBTYPE)),
FzName: __ccgo_ts + 27664,
},
29: {
FnArg: int16(2),
FfuncFlags: libc.Uint32FromInt32(libc.Int32FromInt32(SQLITE_FUNC_BUILTIN) | libc.Int32FromInt32(SQLITE_DETERMINISTIC) | libc.Int32FromInt32(SQLITE_FUNC_CONSTANT) | libc.Int32FromInt32(SQLITE_UTF8) | libc.Int32FromInt32(1)*libc.Int32FromInt32(SQLITE_FUNC_RUNONLY) | libc.Int32FromInt32(0)*libc.Int32FromInt32(SQLITE_SUBTYPE) | libc.Int32FromInt32(0)*libc.Int32FromInt32(SQLITE_RESULT_SUBTYPE)),
FzName: __ccgo_ts + 27664,
},
30: {
FnArg: int16(1),
FfuncFlags: libc.Uint32FromInt32(libc.Int32FromInt32(SQLITE_FUNC_BUILTIN) | libc.Int32FromInt32(SQLITE_DETERMINISTIC) | libc.Int32FromInt32(SQLITE_FUNC_CONSTANT) | libc.Int32FromInt32(SQLITE_UTF8) | libc.Int32FromInt32(1)*libc.Int32FromInt32(SQLITE_FUNC_RUNONLY) | libc.Int32FromInt32(0)*libc.Int32FromInt32(SQLITE_SUBTYPE) | libc.Int32FromInt32(0)*libc.Int32FromInt32(SQLITE_RESULT_SUBTYPE)),
FzName: __ccgo_ts + 27674,
},
31: {
FnArg: int16(2),
FfuncFlags: libc.Uint32FromInt32(libc.Int32FromInt32(SQLITE_FUNC_BUILTIN) | libc.Int32FromInt32(SQLITE_DETERMINISTIC) | libc.Int32FromInt32(SQLITE_FUNC_CONSTANT) | libc.Int32FromInt32(SQLITE_UTF8) | libc.Int32FromInt32(1)*libc.Int32FromInt32(SQLITE_FUNC_RUNONLY) | libc.Int32FromInt32(0)*libc.Int32FromInt32(SQLITE_SUBTYPE) | libc.Int32FromInt32(0)*libc.Int32FromInt32(SQLITE_RESULT_SUBTYPE)),
FzName: __ccgo_ts + 27674,
},
32: {
FnArg: int16(1),
FfuncFlags: libc.Uint32FromInt32(libc.Int32FromInt32(SQLITE_FUNC_BUILTIN) | libc.Int32FromInt32(SQLITE_UTF8) | libc.Int32FromInt32(0)*libc.Int32FromInt32(SQLITE_FUNC_NEEDCOLL) | libc.Int32FromInt32(SQLITE_SUBTYPE) | libc.Int32FromInt32(SQLITE_RESULT_SUBTYPE) | libc.Int32FromInt32(SQLITE_UTF8) | libc.Int32FromInt32(SQLITE_DETERMINISTIC)),
FzName: __ccgo_ts + 27685,
},
33: {
FnArg: int16(1),
FfuncFlags: libc.Uint32FromInt32(libc.Int32FromInt32(SQLITE_FUNC_BUILTIN) | libc.Int32FromInt32(SQLITE_UTF8) | libc.Int32FromInt32(0)*libc.Int32FromInt32(SQLITE_FUNC_NEEDCOLL) | libc.Int32FromInt32(SQLITE_SUBTYPE) | libc.Int32FromInt32(SQLITE_RESULT_SUBTYPE) | libc.Int32FromInt32(SQLITE_UTF8) | libc.Int32FromInt32(SQLITE_DETERMINISTIC)),
FpUserData: uintptr(int64(libc.Int32FromInt32(JSON_BLOB))),
FzName: __ccgo_ts + 27702,
},
34: {
FnArg: int16(2),
FfuncFlags: libc.Uint32FromInt32(libc.Int32FromInt32(SQLITE_FUNC_BUILTIN) | libc.Int32FromInt32(SQLITE_UTF8) | libc.Int32FromInt32(0)*libc.Int32FromInt32(SQLITE_FUNC_NEEDCOLL) | libc.Int32FromInt32(SQLITE_SUBTYPE) | libc.Int32FromInt32(SQLITE_RESULT_SUBTYPE) | libc.Int32FromInt32(SQLITE_UTF8) | libc.Int32FromInt32(SQLITE_DETERMINISTIC)),
FzName: __ccgo_ts + 27720,
},
35: {
FnArg: int16(2),
FfuncFlags: libc.Uint32FromInt32(libc.Int32FromInt32(SQLITE_FUNC_BUILTIN) | libc.Int32FromInt32(SQLITE_UTF8) | libc.Int32FromInt32(0)*libc.Int32FromInt32(SQLITE_FUNC_NEEDCOLL) | libc.Int32FromInt32(SQLITE_SUBTYPE) | libc.Int32FromInt32(SQLITE_RESULT_SUBTYPE) | libc.Int32FromInt32(SQLITE_UTF8) | libc.Int32FromInt32(SQLITE_DETERMINISTIC)),
FpUserData: uintptr(int64(libc.Int32FromInt32(JSON_BLOB))),
FzName: __ccgo_ts + 27738,
},
}
var _aMap = [6]struct {
FzFilesystem uintptr
FpMethods uintptr
}{
0: {
FzFilesystem: __ccgo_ts + 3978,
FpMethods: uintptr(unsafe.Pointer(&_posixIoMethods)),
},
1: {
FzFilesystem: __ccgo_ts + 3982,
FpMethods: uintptr(unsafe.Pointer(&_posixIoMethods)),
},
2: {
FzFilesystem: __ccgo_ts + 3986,
FpMethods: uintptr(unsafe.Pointer(&_afpIoMethods)),
},
3: {
FzFilesystem: __ccgo_ts + 3992,
FpMethods: uintptr(unsafe.Pointer(&_afpIoMethods)),
},
4: {
FzFilesystem: __ccgo_ts + 3998,
FpMethods: uintptr(unsafe.Pointer(&_nolockIoMethods)),
},
5: {},
}
var _aMap1 = [5]uint8{
0: uint8(SQLITE_ROLLBACK),
1: uint8(SQLITE_ABORT),
2: uint8(SQLITE_FAIL),
3: uint8(SQLITE_IGNORE),
4: uint8(SQLITE_REPLACE),
}
var _aMsg = [29]uintptr{
0: __ccgo_ts + 25750,
1: __ccgo_ts + 25763,
3: __ccgo_ts + 25779,
4: __ccgo_ts + 25804,
5: __ccgo_ts + 25818,
6: __ccgo_ts + 25837,
7: __ccgo_ts + 1672,
8: __ccgo_ts + 25862,
9: __ccgo_ts + 25899,
10: __ccgo_ts + 25911,
11: __ccgo_ts + 25926,
12: __ccgo_ts + 25959,
13: __ccgo_ts + 25977,
14: __ccgo_ts + 26002,
15: __ccgo_ts + 26031,
17: __ccgo_ts + 6587,
18: __ccgo_ts + 5938,
19: __ccgo_ts + 26048,
20: __ccgo_ts + 26066,
21: __ccgo_ts + 26084,
23: __ccgo_ts + 26118,
25: __ccgo_ts + 26139,
26: __ccgo_ts + 26165,
27: __ccgo_ts + 26188,
28: __ccgo_ts + 26209,
}
// C documentation
//
// /*
// ** Extra floating-point literals to allow in JSON.
// */
var _aNanInfName = [5]TNanInfName{
0: {
Fc1: int8('i'),
Fc2: int8('I'),
Fn: int8(3),
FeType: int8(JSONB_FLOAT),
FnRepl: int8(7),
FzMatch: __ccgo_ts + 26868,
FzRepl: __ccgo_ts + 26872,
},
1: {
Fc1: int8('i'),
Fc2: int8('I'),
Fn: int8(8),
FeType: int8(JSONB_FLOAT),
FnRepl: int8(7),
FzMatch: __ccgo_ts + 26880,
FzRepl: __ccgo_ts + 26872,
},
2: {
Fc1: int8('n'),
Fc2: int8('N'),
Fn: int8(3),
FnRepl: int8(4),
FzMatch: __ccgo_ts + 1693,
FzRepl: __ccgo_ts + 1688,
},
3: {
Fc1: int8('q'),
Fc2: int8('Q'),
Fn: int8(4),
FnRepl: int8(4),
FzMatch: __ccgo_ts + 26889,
FzRepl: __ccgo_ts + 1688,
},
4: {
Fc1: int8('s'),
Fc2: int8('S'),
Fn: int8(4),
FnRepl: int8(4),
FzMatch: __ccgo_ts + 26894,
FzRepl: __ccgo_ts + 1688,
},
}
var _aOp = [4]struct {
FzOp uintptr
FeOp uint8
}{
0: {
FzOp: __ccgo_ts + 18163,
FeOp: uint8(SQLITE_INDEX_CONSTRAINT_MATCH),
},
1: {
FzOp: __ccgo_ts + 17494,
FeOp: uint8(SQLITE_INDEX_CONSTRAINT_GLOB),
},
2: {
FzOp: __ccgo_ts + 16953,
FeOp: uint8(SQLITE_INDEX_CONSTRAINT_LIKE),
},
3: {
FzOp: __ccgo_ts + 24329,
FeOp: uint8(SQLITE_INDEX_CONSTRAINT_REGEXP),
},
}
var _aOpenMode = [5]struct {
Fz uintptr
Fmode int32
}{
0: {
Fz: __ccgo_ts + 26583,
Fmode: int32(SQLITE_OPEN_READONLY),
},
1: {
Fz: __ccgo_ts + 26586,
Fmode: int32(SQLITE_OPEN_READWRITE),
},
2: {
Fz: __ccgo_ts + 26589,
Fmode: libc.Int32FromInt32(SQLITE_OPEN_READWRITE) | libc.Int32FromInt32(SQLITE_OPEN_CREATE),
},
3: {
Fz: __ccgo_ts + 19400,
Fmode: int32(SQLITE_OPEN_MEMORY),
},
4: {},
}
var _aPragmaName = [67]TPragmaName{
0: {
FzName: __ccgo_ts + 18383,
FePragTyp: uint8(PragTyp_ANALYSIS_LIMIT),
FmPragFlg: uint8(PragFlg_Result0),
},
1: {
FzName: __ccgo_ts + 18398,
FePragTyp: uint8(PragTyp_HEADER_VALUE),
FmPragFlg: libc.Uint8FromInt32(libc.Int32FromInt32(PragFlg_NoColumns1) | libc.Int32FromInt32(PragFlg_Result0)),
FiArg: uint64(BTREE_APPLICATION_ID),
},
2: {
FzName: __ccgo_ts + 18413,
FePragTyp: uint8(PragTyp_AUTO_VACUUM),
FmPragFlg: libc.Uint8FromInt32(libc.Int32FromInt32(PragFlg_NeedSchema) | libc.Int32FromInt32(PragFlg_Result0) | libc.Int32FromInt32(PragFlg_SchemaReq) | libc.Int32FromInt32(PragFlg_NoColumns1)),
},
3: {
FzName: __ccgo_ts + 18425,
FePragTyp: uint8(PragTyp_FLAG),
FmPragFlg: libc.Uint8FromInt32(libc.Int32FromInt32(PragFlg_Result0) | libc.Int32FromInt32(PragFlg_NoColumns1)),
FiArg: uint64(SQLITE_AutoIndex),
},
4: {
FzName: __ccgo_ts + 18441,
FePragTyp: uint8(PragTyp_BUSY_TIMEOUT),
FmPragFlg: uint8(PragFlg_Result0),
FiPragCName: uint8(56),
FnPragCName: uint8(1),
},
5: {
FzName: __ccgo_ts + 18364,
FePragTyp: uint8(PragTyp_CACHE_SIZE),
FmPragFlg: libc.Uint8FromInt32(libc.Int32FromInt32(PragFlg_NeedSchema) | libc.Int32FromInt32(PragFlg_Result0) | libc.Int32FromInt32(PragFlg_SchemaReq) | libc.Int32FromInt32(PragFlg_NoColumns1)),
},
6: {
FzName: __ccgo_ts + 18454,
FePragTyp: uint8(PragTyp_CACHE_SPILL),
FmPragFlg: libc.Uint8FromInt32(libc.Int32FromInt32(PragFlg_Result0) | libc.Int32FromInt32(PragFlg_SchemaReq) | libc.Int32FromInt32(PragFlg_NoColumns1)),
},
7: {
FzName: __ccgo_ts + 18466,
FePragTyp: uint8(PragTyp_CASE_SENSITIVE_LIKE),
FmPragFlg: uint8(PragFlg_NoColumns),
},
8: {
FzName: __ccgo_ts + 18486,
FePragTyp: uint8(PragTyp_FLAG),
FmPragFlg: libc.Uint8FromInt32(libc.Int32FromInt32(PragFlg_Result0) | libc.Int32FromInt32(PragFlg_NoColumns1)),
FiArg: uint64(SQLITE_CellSizeCk),
},
9: {
FzName: __ccgo_ts + 18502,
FePragTyp: uint8(PragTyp_FLAG),
FmPragFlg: libc.Uint8FromInt32(libc.Int32FromInt32(PragFlg_Result0) | libc.Int32FromInt32(PragFlg_NoColumns1)),
FiArg: uint64(SQLITE_CkptFullFSync),
},
10: {
FzName: __ccgo_ts + 18523,
FePragTyp: uint8(PragTyp_COLLATION_LIST),
FmPragFlg: uint8(PragFlg_Result0),
FiPragCName: uint8(33),
FnPragCName: uint8(2),
},
11: {
FzName: __ccgo_ts + 18538,
FePragTyp: uint8(PragTyp_COMPILE_OPTIONS),
FmPragFlg: uint8(PragFlg_Result0),
},
12: {
FzName: __ccgo_ts + 18554,
FePragTyp: uint8(PragTyp_FLAG),
FmPragFlg: libc.Uint8FromInt32(libc.Int32FromInt32(PragFlg_Result0) | libc.Int32FromInt32(PragFlg_NoColumns1)),
FiArg: libc.Uint64FromInt32(libc.Int32FromInt32(0x00001)) << libc.Int32FromInt32(32),
},
13: {
FzName: __ccgo_ts + 18568,
FePragTyp: uint8(PragTyp_HEADER_VALUE),
FmPragFlg: libc.Uint8FromInt32(libc.Int32FromInt32(PragFlg_ReadOnly) | libc.Int32FromInt32(PragFlg_Result0)),
FiArg: uint64(BTREE_DATA_VERSION),
},
14: {
FzName: __ccgo_ts + 18581,
FePragTyp: uint8(PragTyp_DATABASE_LIST),
FmPragFlg: uint8(PragFlg_Result0),
FiPragCName: uint8(50),
FnPragCName: uint8(3),
},
15: {
FzName: __ccgo_ts + 18595,
FePragTyp: uint8(PragTyp_DEFAULT_CACHE_SIZE),
FmPragFlg: libc.Uint8FromInt32(libc.Int32FromInt32(PragFlg_NeedSchema) | libc.Int32FromInt32(PragFlg_Result0) | libc.Int32FromInt32(PragFlg_SchemaReq) | libc.Int32FromInt32(PragFlg_NoColumns1)),
FiPragCName: uint8(55),
FnPragCName: uint8(1),
},
16: {
FzName: __ccgo_ts + 18614,
FePragTyp: uint8(PragTyp_FLAG),
FmPragFlg: libc.Uint8FromInt32(libc.Int32FromInt32(PragFlg_Result0) | libc.Int32FromInt32(PragFlg_NoColumns1)),
FiArg: uint64(SQLITE_DeferFKs),
},
17: {
FzName: __ccgo_ts + 18633,
FePragTyp: uint8(PragTyp_FLAG),
FmPragFlg: libc.Uint8FromInt32(libc.Int32FromInt32(PragFlg_Result0) | libc.Int32FromInt32(PragFlg_NoColumns1)),
FiArg: uint64(SQLITE_NullCallback),
},
18: {
FzName: __ccgo_ts + 18656,
FePragTyp: uint8(PragTyp_ENCODING),
FmPragFlg: libc.Uint8FromInt32(libc.Int32FromInt32(PragFlg_Result0) | libc.Int32FromInt32(PragFlg_NoColumns1)),
},
19: {
FzName: __ccgo_ts + 18665,
FePragTyp: uint8(PragTyp_FOREIGN_KEY_CHECK),
FmPragFlg: libc.Uint8FromInt32(libc.Int32FromInt32(PragFlg_NeedSchema) | libc.Int32FromInt32(PragFlg_Result0) | libc.Int32FromInt32(PragFlg_Result1) | libc.Int32FromInt32(PragFlg_SchemaOpt)),
FiPragCName: uint8(43),
FnPragCName: uint8(4),
},
20: {
FzName: __ccgo_ts + 18683,
FePragTyp: uint8(PragTyp_FOREIGN_KEY_LIST),
FmPragFlg: libc.Uint8FromInt32(libc.Int32FromInt32(PragFlg_NeedSchema) | libc.Int32FromInt32(PragFlg_Result1) | libc.Int32FromInt32(PragFlg_SchemaOpt)),
FnPragCName: uint8(8),
},
21: {
FzName: __ccgo_ts + 18700,
FePragTyp: uint8(PragTyp_FLAG),
FmPragFlg: libc.Uint8FromInt32(libc.Int32FromInt32(PragFlg_Result0) | libc.Int32FromInt32(PragFlg_NoColumns1)),
FiArg: uint64(SQLITE_ForeignKeys),
},
22: {
FzName: __ccgo_ts + 18713,
FePragTyp: uint8(PragTyp_HEADER_VALUE),
FmPragFlg: libc.Uint8FromInt32(libc.Int32FromInt32(PragFlg_ReadOnly) | libc.Int32FromInt32(PragFlg_Result0)),
},
23: {
FzName: __ccgo_ts + 18728,
FePragTyp: uint8(PragTyp_FLAG),
FmPragFlg: libc.Uint8FromInt32(libc.Int32FromInt32(PragFlg_Result0) | libc.Int32FromInt32(PragFlg_NoColumns1)),
FiArg: uint64(SQLITE_FullColNames),
},
24: {
FzName: __ccgo_ts + 18746,
FePragTyp: uint8(PragTyp_FLAG),
FmPragFlg: libc.Uint8FromInt32(libc.Int32FromInt32(PragFlg_Result0) | libc.Int32FromInt32(PragFlg_NoColumns1)),
FiArg: uint64(SQLITE_FullFSync),
},
25: {
FzName: __ccgo_ts + 18756,
FePragTyp: uint8(PragTyp_FUNCTION_LIST),
FmPragFlg: uint8(PragFlg_Result0),
FiPragCName: uint8(15),
FnPragCName: uint8(6),
},
26: {
FzName: __ccgo_ts + 18770,
FePragTyp: uint8(PragTyp_HARD_HEAP_LIMIT),
FmPragFlg: uint8(PragFlg_Result0),
},
27: {
FzName: __ccgo_ts + 18786,
FePragTyp: uint8(PragTyp_FLAG),
FmPragFlg: libc.Uint8FromInt32(libc.Int32FromInt32(PragFlg_Result0) | libc.Int32FromInt32(PragFlg_NoColumns1)),
FiArg: uint64(SQLITE_IgnoreChecks),
},
28: {
FzName: __ccgo_ts + 18811,
FePragTyp: uint8(PragTyp_INCREMENTAL_VACUUM),
FmPragFlg: libc.Uint8FromInt32(libc.Int32FromInt32(PragFlg_NeedSchema) | libc.Int32FromInt32(PragFlg_NoColumns)),
},
29: {
FzName: __ccgo_ts + 18830,
FePragTyp: uint8(PragTyp_INDEX_INFO),
FmPragFlg: libc.Uint8FromInt32(libc.Int32FromInt32(PragFlg_NeedSchema) | libc.Int32FromInt32(PragFlg_Result1) | libc.Int32FromInt32(PragFlg_SchemaOpt)),
FiPragCName: uint8(27),
FnPragCName: uint8(3),
},
30: {
FzName: __ccgo_ts + 18841,
FePragTyp: uint8(PragTyp_INDEX_LIST),
FmPragFlg: libc.Uint8FromInt32(libc.Int32FromInt32(PragFlg_NeedSchema) | libc.Int32FromInt32(PragFlg_Result1) | libc.Int32FromInt32(PragFlg_SchemaOpt)),
FiPragCName: uint8(33),
FnPragCName: uint8(5),
},
31: {
FzName: __ccgo_ts + 18852,
FePragTyp: uint8(PragTyp_INDEX_INFO),
FmPragFlg: libc.Uint8FromInt32(libc.Int32FromInt32(PragFlg_NeedSchema) | libc.Int32FromInt32(PragFlg_Result1) | libc.Int32FromInt32(PragFlg_SchemaOpt)),
FiPragCName: uint8(27),
FnPragCName: uint8(6),
FiArg: uint64(1),
},
32: {
FzName: __ccgo_ts + 18864,
FePragTyp: uint8(PragTyp_INTEGRITY_CHECK),
FmPragFlg: libc.Uint8FromInt32(libc.Int32FromInt32(PragFlg_NeedSchema) | libc.Int32FromInt32(PragFlg_Result0) | libc.Int32FromInt32(PragFlg_Result1) | libc.Int32FromInt32(PragFlg_SchemaOpt)),
},
33: {
FzName: __ccgo_ts + 18880,
FePragTyp: uint8(PragTyp_JOURNAL_MODE),
FmPragFlg: libc.Uint8FromInt32(libc.Int32FromInt32(PragFlg_NeedSchema) | libc.Int32FromInt32(PragFlg_Result0) | libc.Int32FromInt32(PragFlg_SchemaReq)),
},
34: {
FzName: __ccgo_ts + 18893,
FePragTyp: uint8(PragTyp_JOURNAL_SIZE_LIMIT),
FmPragFlg: libc.Uint8FromInt32(libc.Int32FromInt32(PragFlg_Result0) | libc.Int32FromInt32(PragFlg_SchemaReq)),
},
35: {
FzName: __ccgo_ts + 18912,
FePragTyp: uint8(PragTyp_FLAG),
FmPragFlg: libc.Uint8FromInt32(libc.Int32FromInt32(PragFlg_Result0) | libc.Int32FromInt32(PragFlg_NoColumns1)),
FiArg: uint64(SQLITE_LegacyAlter),
},
36: {
FzName: __ccgo_ts + 18931,
FePragTyp: uint8(PragTyp_LOCK_PROXY_FILE),
FmPragFlg: uint8(PragFlg_NoColumns1),
},
37: {
FzName: __ccgo_ts + 18947,
FePragTyp: uint8(PragTyp_LOCKING_MODE),
FmPragFlg: libc.Uint8FromInt32(libc.Int32FromInt32(PragFlg_Result0) | libc.Int32FromInt32(PragFlg_SchemaReq)),
},
38: {
FzName: __ccgo_ts + 18960,
FePragTyp: uint8(PragTyp_PAGE_COUNT),
FmPragFlg: libc.Uint8FromInt32(libc.Int32FromInt32(PragFlg_NeedSchema) | libc.Int32FromInt32(PragFlg_Result0) | libc.Int32FromInt32(PragFlg_SchemaReq)),
},
39: {
FzName: __ccgo_ts + 18975,
FePragTyp: uint8(PragTyp_MMAP_SIZE),
},
40: {
FzName: __ccgo_ts + 18985,
FePragTyp: uint8(PragTyp_MODULE_LIST),
FmPragFlg: uint8(PragFlg_Result0),
FiPragCName: uint8(9),
FnPragCName: uint8(1),
},
41: {
FzName: __ccgo_ts + 18997,
FePragTyp: uint8(PragTyp_OPTIMIZE),
FmPragFlg: libc.Uint8FromInt32(libc.Int32FromInt32(PragFlg_Result1) | libc.Int32FromInt32(PragFlg_NeedSchema)),
},
42: {
FzName: __ccgo_ts + 19006,
FePragTyp: uint8(PragTyp_PAGE_COUNT),
FmPragFlg: libc.Uint8FromInt32(libc.Int32FromInt32(PragFlg_NeedSchema) | libc.Int32FromInt32(PragFlg_Result0) | libc.Int32FromInt32(PragFlg_SchemaReq)),
},
43: {
FzName: __ccgo_ts + 19017,
FePragTyp: uint8(PragTyp_PAGE_SIZE),
FmPragFlg: libc.Uint8FromInt32(libc.Int32FromInt32(PragFlg_Result0) | libc.Int32FromInt32(PragFlg_SchemaReq) | libc.Int32FromInt32(PragFlg_NoColumns1)),
},
44: {
FzName: __ccgo_ts + 19027,
FePragTyp: uint8(PragTyp_PRAGMA_LIST),
FmPragFlg: uint8(PragFlg_Result0),
FiPragCName: uint8(9),
FnPragCName: uint8(1),
},
45: {
FzName: __ccgo_ts + 19039,
FePragTyp: uint8(PragTyp_FLAG),
FmPragFlg: libc.Uint8FromInt32(libc.Int32FromInt32(PragFlg_Result0) | libc.Int32FromInt32(PragFlg_NoColumns1)),
FiArg: uint64(SQLITE_QueryOnly),
},
46: {
FzName: __ccgo_ts + 19050,
FePragTyp: uint8(PragTyp_INTEGRITY_CHECK),
FmPragFlg: libc.Uint8FromInt32(libc.Int32FromInt32(PragFlg_NeedSchema) | libc.Int32FromInt32(PragFlg_Result0) | libc.Int32FromInt32(PragFlg_Result1) | libc.Int32FromInt32(PragFlg_SchemaOpt)),
},
47: {
FzName: __ccgo_ts + 19062,
FePragTyp: uint8(PragTyp_FLAG),
FmPragFlg: libc.Uint8FromInt32(libc.Int32FromInt32(PragFlg_Result0) | libc.Int32FromInt32(PragFlg_NoColumns1)),
FiArg: libc.Uint64FromInt32(libc.Int32FromInt32(0x00004)) << libc.Int32FromInt32(32),
},
48: {
FzName: __ccgo_ts + 19079,
FePragTyp: uint8(PragTyp_FLAG),
FmPragFlg: libc.Uint8FromInt32(libc.Int32FromInt32(PragFlg_Result0) | libc.Int32FromInt32(PragFlg_NoColumns1)),
FiArg: uint64(SQLITE_RecTriggers),
},
49: {
FzName: __ccgo_ts + 19098,
FePragTyp: uint8(PragTyp_FLAG),
FmPragFlg: libc.Uint8FromInt32(libc.Int32FromInt32(PragFlg_Result0) | libc.Int32FromInt32(PragFlg_NoColumns1)),
FiArg: uint64(SQLITE_ReverseOrder),
},
50: {
FzName: __ccgo_ts + 19124,
FePragTyp: uint8(PragTyp_HEADER_VALUE),
FmPragFlg: libc.Uint8FromInt32(libc.Int32FromInt32(PragFlg_NoColumns1) | libc.Int32FromInt32(PragFlg_Result0)),
FiArg: uint64(BTREE_SCHEMA_VERSION),
},
51: {
FzName: __ccgo_ts + 19139,
FePragTyp: uint8(PragTyp_SECURE_DELETE),
FmPragFlg: uint8(PragFlg_Result0),
},
52: {
FzName: __ccgo_ts + 19153,
FePragTyp: uint8(PragTyp_FLAG),
FmPragFlg: libc.Uint8FromInt32(libc.Int32FromInt32(PragFlg_Result0) | libc.Int32FromInt32(PragFlg_NoColumns1)),
FiArg: uint64(SQLITE_ShortColNames),
},
53: {
FzName: __ccgo_ts + 19172,
FePragTyp: uint8(PragTyp_SHRINK_MEMORY),
FmPragFlg: uint8(PragFlg_NoColumns),
},
54: {
FzName: __ccgo_ts + 19186,
FePragTyp: uint8(PragTyp_SOFT_HEAP_LIMIT),
FmPragFlg: uint8(PragFlg_Result0),
},
55: {
FzName: __ccgo_ts + 19202,
FePragTyp: uint8(PragTyp_SYNCHRONOUS),
FmPragFlg: libc.Uint8FromInt32(libc.Int32FromInt32(PragFlg_NeedSchema) | libc.Int32FromInt32(PragFlg_Result0) | libc.Int32FromInt32(PragFlg_SchemaReq) | libc.Int32FromInt32(PragFlg_NoColumns1)),
},
56: {
FzName: __ccgo_ts + 19214,
FePragTyp: uint8(PragTyp_TABLE_INFO),
FmPragFlg: libc.Uint8FromInt32(libc.Int32FromInt32(PragFlg_NeedSchema) | libc.Int32FromInt32(PragFlg_Result1) | libc.Int32FromInt32(PragFlg_SchemaOpt)),
FiPragCName: uint8(8),
FnPragCName: uint8(6),
},
57: {
FzName: __ccgo_ts + 19225,
FePragTyp: uint8(PragTyp_TABLE_LIST),
FmPragFlg: libc.Uint8FromInt32(libc.Int32FromInt32(PragFlg_NeedSchema) | libc.Int32FromInt32(PragFlg_Result1)),
FiPragCName: uint8(21),
FnPragCName: uint8(6),
},
58: {
FzName: __ccgo_ts + 19236,
FePragTyp: uint8(PragTyp_TABLE_INFO),
FmPragFlg: libc.Uint8FromInt32(libc.Int32FromInt32(PragFlg_NeedSchema) | libc.Int32FromInt32(PragFlg_Result1) | libc.Int32FromInt32(PragFlg_SchemaOpt)),
FiPragCName: uint8(8),
FnPragCName: uint8(7),
FiArg: uint64(1),
},
59: {
FzName: __ccgo_ts + 19248,
FePragTyp: uint8(PragTyp_TEMP_STORE),
FmPragFlg: libc.Uint8FromInt32(libc.Int32FromInt32(PragFlg_Result0) | libc.Int32FromInt32(PragFlg_NoColumns1)),
},
60: {
FzName: __ccgo_ts + 19259,
FePragTyp: uint8(PragTyp_TEMP_STORE_DIRECTORY),
FmPragFlg: uint8(PragFlg_NoColumns1),
},
61: {
FzName: __ccgo_ts + 19280,
FePragTyp: uint8(PragTyp_THREADS),
FmPragFlg: uint8(PragFlg_Result0),
},
62: {
FzName: __ccgo_ts + 19288,
FePragTyp: uint8(PragTyp_FLAG),
FmPragFlg: libc.Uint8FromInt32(libc.Int32FromInt32(PragFlg_Result0) | libc.Int32FromInt32(PragFlg_NoColumns1)),
FiArg: uint64(SQLITE_TrustedSchema),
},
63: {
FzName: __ccgo_ts + 19303,
FePragTyp: uint8(PragTyp_HEADER_VALUE),
FmPragFlg: libc.Uint8FromInt32(libc.Int32FromInt32(PragFlg_NoColumns1) | libc.Int32FromInt32(PragFlg_Result0)),
FiArg: uint64(BTREE_USER_VERSION),
},
64: {
FzName: __ccgo_ts + 19316,
FePragTyp: uint8(PragTyp_WAL_AUTOCHECKPOINT),
},
65: {
FzName: __ccgo_ts + 19335,
FePragTyp: uint8(PragTyp_WAL_CHECKPOINT),
FmPragFlg: uint8(PragFlg_NeedSchema),
FiPragCName: uint8(47),
FnPragCName: uint8(3),
},
66: {
FzName: __ccgo_ts + 19350,
FePragTyp: uint8(PragTyp_FLAG),
FmPragFlg: libc.Uint8FromInt32(libc.Int32FromInt32(PragFlg_Result0) | libc.Int32FromInt32(PragFlg_NoColumns1)),
FiArg: libc.Uint64FromInt32(libc.Int32FromInt32(SQLITE_WriteSchema) | libc.Int32FromInt32(SQLITE_NoSchemaError)),
},
}
/* Number of pragmas: 68 on by default, 78 total. */
/************** End of pragma.h **********************************************/
/************** Continuing where we left off in pragma.c *********************/
/*
** When the 0x10 bit of PRAGMA optimize is set, any ANALYZE commands
** will be run with an analysis_limit set to the lessor of the value of
** the following macro or to the actual analysis_limit if it is non-zero,
** in order to prevent PRAGMA optimize from running for too long.
**
** The value of 2000 is chosen empirically so that the worst-case run-time
** for PRAGMA optimize does not exceed 100 milliseconds against a variety
** of test databases on a RaspberryPI-4 compiled using -Os and without
** -DSQLITE_DEBUG. Of course, your mileage may vary. For the purpose of
** this paragraph, "worst-case" means that ANALYZE ends up being
** run on every table in the database. The worst case typically only
** happens if PRAGMA optimize is run on a database file for which ANALYZE
** has not been previously run and the 0x10000 flag is included so that
** all tables are analyzed. The usual case for PRAGMA optimize is that
** no ANALYZE commands will be run at all, or if any ANALYZE happens it
** will be against a single table, so that expected timing for PRAGMA
** optimize on a PI-4 is more like 1 millisecond or less with the 0x10000
** flag or less than 100 microseconds without the 0x10000 flag.
**
** An analysis limit of 2000 is almost always sufficient for the query
** planner to fully characterize an index. The additional accuracy from
** a larger analysis is not usually helpful.
*/
var _aTable = [3]struct {
FzName uintptr
FzCols uintptr
}{
0: {
FzName: __ccgo_ts + 13181,
FzCols: __ccgo_ts + 13194,
},
1: {
FzName: __ccgo_ts + 13207,
FzCols: __ccgo_ts + 13220,
},
2: {
FzName: __ccgo_ts + 13248,
},
}
/*
** Recommended number of samples for sqlite_stat4
*/
/*
** All default VFSes for unix are contained in the following array.
**
** Note that the sqlite3_vfs.pNext field of the VFS object is modified
** by the SQLite core when the VFS is registered. So the following
** array cannot be const.
*/
var _aVfs = [9]Tsqlite3_vfs{
0: {
FiVersion: int32(3),
FszOsFile: int32(128),
FmxPathname: int32(MAX_PATHNAME),
FzName: __ccgo_ts + 4381,
},
1: {
FiVersion: int32(3),
FszOsFile: int32(128),
FmxPathname: int32(MAX_PATHNAME),
FzName: __ccgo_ts + 4386,
},
2: {
FiVersion: int32(3),
FszOsFile: int32(128),
FmxPathname: int32(MAX_PATHNAME),
FzName: __ccgo_ts + 4396,
},
3: {
FiVersion: int32(3),
FszOsFile: int32(128),
FmxPathname: int32(MAX_PATHNAME),
FzName: __ccgo_ts + 4014,
},
4: {
FiVersion: int32(3),
FszOsFile: int32(128),
FmxPathname: int32(MAX_PATHNAME),
FzName: __ccgo_ts + 4409,
},
5: {
FiVersion: int32(3),
FszOsFile: int32(128),
FmxPathname: int32(MAX_PATHNAME),
FzName: __ccgo_ts + 4420,
},
6: {
FiVersion: int32(3),
FszOsFile: int32(128),
FmxPathname: int32(MAX_PATHNAME),
FzName: __ccgo_ts + 4431,
},
7: {
FiVersion: int32(3),
FszOsFile: int32(128),
FmxPathname: int32(MAX_PATHNAME),
FzName: __ccgo_ts + 4440,
},
8: {
FiVersion: int32(3),
FszOsFile: int32(128),
FmxPathname: int32(MAX_PATHNAME),
FzName: __ccgo_ts + 4449,
},
}
// C documentation
//
// /*
// ** Implementation of the abs() function.
// **
// ** IMP: R-23979-26855 The abs(X) function returns the absolute value of
// ** the numeric argument X.
// */
func _absFunc(tls *libc.TLS, context uintptr, argc int32, argv uintptr) {
var iVal Ti64
var rVal float64
_, _ = iVal, rVal
_ = argc
switch Xsqlite3_value_type(tls, **(**uintptr)(__ccgo_up(argv))) {
case int32(SQLITE_INTEGER):
iVal = Xsqlite3_value_int64(tls, **(**uintptr)(__ccgo_up(argv)))
if iVal < 0 {
if iVal == int64(-libc.Int32FromInt32(1))-(libc.Int64FromUint32(0xffffffff)|libc.Int64FromInt32(0x7fffffff)<= libc.Int32FromUint16((*TMemPage)(unsafe.Pointer(pPage)).FnCell) {
return _sqlite3CorruptError(tls, int32(78371))
}
_getCellInfo(tls, pCur)
aPayload = (*TBtCursor)(unsafe.Pointer(pCur)).Finfo.FpPayload
if libc.Uint64FromInt64(int64(aPayload)-int64((*TMemPage)(unsafe.Pointer(pPage)).FaData)) > uint64((*TBtShared)(unsafe.Pointer(pBt)).FusableSize-uint32((*TBtCursor)(unsafe.Pointer(pCur)).Finfo.FnLocal)) {
/* Trying to read or write past the end of the data is an error. The
** conditional above is really:
** &aPayload[pCur->info.nLocal] > &pPage->aData[pBt->usableSize]
** but is recast into its current form to avoid integer overflow problems
*/
return _sqlite3CorruptError(tls, int32(78386))
}
/* Check if data must be read/written to/from the btree page itself. */
if offset < uint32((*TBtCursor)(unsafe.Pointer(pCur)).Finfo.FnLocal) {
a = libc.Int32FromUint32(amt)
if libc.Uint32FromInt32(a)+offset > uint32((*TBtCursor)(unsafe.Pointer(pCur)).Finfo.FnLocal) {
a = libc.Int32FromUint32(uint32((*TBtCursor)(unsafe.Pointer(pCur)).Finfo.FnLocal) - offset)
}
rc = _copyPayload(tls, aPayload+uintptr(offset), pBuf, a, eOp, (*TMemPage)(unsafe.Pointer(pPage)).FpDbPage)
offset = uint32(0)
pBuf = pBuf + uintptr(a)
amt = amt - libc.Uint32FromInt32(a)
} else {
offset = offset - uint32((*TBtCursor)(unsafe.Pointer(pCur)).Finfo.FnLocal)
}
if rc == SQLITE_OK && amt > uint32(0) {
ovflSize = (*TBtShared)(unsafe.Pointer(pBt)).FusableSize - uint32(4)
**(**TPgno)(__ccgo_up(bp)) = _sqlite3Get4byte(tls, aPayload+uintptr((*TBtCursor)(unsafe.Pointer(pCur)).Finfo.FnLocal))
/* If the BtCursor.aOverflow[] has not been allocated, allocate it now.
**
** The aOverflow[] array is sized at one entry for each overflow page
** in the overflow chain. The page number of the first overflow page is
** stored in aOverflow[0], etc. A value of 0 in the aOverflow[] array
** means "not yet known" (the cache is lazily populated).
*/
if libc.Int32FromUint8((*TBtCursor)(unsafe.Pointer(pCur)).FcurFlags)&int32(BTCF_ValidOvfl) == 0 {
nOvfl = libc.Int64FromUint32((*TBtCursor)(unsafe.Pointer(pCur)).Finfo.FnPayload)
nOvfl = (nOvfl - libc.Int64FromUint16((*TBtCursor)(unsafe.Pointer(pCur)).Finfo.FnLocal) + libc.Int64FromUint32(ovflSize) - int64(1)) / libc.Int64FromUint32(ovflSize)
if (*TBtCursor)(unsafe.Pointer(pCur)).FaOverflow == uintptr(0) || nOvfl*int64(libc.Int32FromInt64(4)) > int64(_sqlite3MallocSize(tls, (*TBtCursor)(unsafe.Pointer(pCur)).FaOverflow)) {
if _sqlite3FaultSim(tls, int32(413)) != 0 {
aNew = uintptr(0)
} else {
aNew = _sqlite3Realloc(tls, (*TBtCursor)(unsafe.Pointer(pCur)).FaOverflow, libc.Uint64FromInt64(nOvfl*int64(2))*uint64(4))
}
if aNew == uintptr(0) {
return int32(SQLITE_NOMEM)
} else {
(*TBtCursor)(unsafe.Pointer(pCur)).FaOverflow = aNew
}
}
libc.X__builtin___memset_chk(tls, (*TBtCursor)(unsafe.Pointer(pCur)).FaOverflow, 0, uint64(libc.Uint64FromInt64(nOvfl)*uint64(4)), ^t__predefined_size_t(0))
v1 = pCur + 1
*(*Tu8)(unsafe.Pointer(v1)) = Tu8(int32(*(*Tu8)(unsafe.Pointer(v1))) | libc.Int32FromInt32(BTCF_ValidOvfl))
} else {
/* Sanity check the validity of the overflow page cache */
/* If the overflow page-list cache has been allocated and the
** entry for the first required overflow page is valid, skip
** directly to it.
*/
if **(**TPgno)(__ccgo_up((*TBtCursor)(unsafe.Pointer(pCur)).FaOverflow + uintptr(offset/ovflSize)*4)) != 0 {
iIdx = libc.Int32FromUint32(offset / ovflSize)
**(**TPgno)(__ccgo_up(bp)) = **(**TPgno)(__ccgo_up((*TBtCursor)(unsafe.Pointer(pCur)).FaOverflow + uintptr(iIdx)*4))
offset = offset % ovflSize
}
}
for **(**TPgno)(__ccgo_up(bp)) != 0 {
/* If required, populate the overflow page-list cache. */
if **(**TPgno)(__ccgo_up(bp)) > (*TBtShared)(unsafe.Pointer(pBt)).FnPage {
return _sqlite3CorruptError(tls, int32(78459))
}
**(**TPgno)(__ccgo_up((*TBtCursor)(unsafe.Pointer(pCur)).FaOverflow + uintptr(iIdx)*4)) = **(**TPgno)(__ccgo_up(bp))
if offset >= ovflSize {
/* The only reason to read this page is to obtain the page
** number for the next page in the overflow chain. The page
** data is not required. So first try to lookup the overflow
** page-list cache, if any, then fall back to the getOverflowPage()
** function.
*/
if **(**TPgno)(__ccgo_up((*TBtCursor)(unsafe.Pointer(pCur)).FaOverflow + uintptr(iIdx+int32(1))*4)) != 0 {
**(**TPgno)(__ccgo_up(bp)) = **(**TPgno)(__ccgo_up((*TBtCursor)(unsafe.Pointer(pCur)).FaOverflow + uintptr(iIdx+int32(1))*4))
} else {
rc = _getOverflowPage(tls, pBt, **(**TPgno)(__ccgo_up(bp)), uintptr(0), bp)
}
offset = offset - ovflSize
} else {
/* Need to read this page properly. It contains some of the
** range of data that is being read (eOp==0) or written (eOp!=0).
*/
a1 = libc.Int32FromUint32(amt)
if libc.Uint32FromInt32(a1)+offset > ovflSize {
a1 = libc.Int32FromUint32(ovflSize - offset)
}
/* If all the following are true:
**
** 1) this is a read operation, and
** 2) data is required from the start of this overflow page, and
** 3) there are no dirty pages in the page-cache
** 4) the database is file-backed, and
** 5) the page is not in the WAL file
** 6) at least 4 bytes have already been read into the output buffer
**
** then data can be read directly from the database file into the
** output buffer, bypassing the page-cache altogether. This speeds
** up loading large records that span many overflow pages.
*/
if eOp == 0 && offset == uint32(0) && _sqlite3PagerDirectReadOk(tls, (*TBtShared)(unsafe.Pointer(pBt)).FpPager, **(**TPgno)(__ccgo_up(bp))) != 0 && pBuf+uintptr(-libc.Int32FromInt32(4)) >= pBufStart {
fd = _sqlite3PagerFile(tls, (*TBtShared)(unsafe.Pointer(pBt)).FpPager)
aWrite = pBuf + uintptr(-libc.Int32FromInt32(4))
/* due to (6) */
libc.X__builtin___memcpy_chk(tls, bp+4, aWrite, uint64(4), ^t__predefined_size_t(0))
rc = _sqlite3OsRead(tls, fd, aWrite, a1+int32(4), libc.Int64FromUint32((*TBtShared)(unsafe.Pointer(pBt)).FpageSize)*libc.Int64FromUint32(**(**TPgno)(__ccgo_up(bp))-libc.Uint32FromInt32(1)))
**(**TPgno)(__ccgo_up(bp)) = _sqlite3Get4byte(tls, aWrite)
libc.X__builtin___memcpy_chk(tls, aWrite, bp+4, uint64(4), ^t__predefined_size_t(0))
} else {
if eOp == 0 {
v2 = int32(PAGER_GET_READONLY)
} else {
v2 = 0
}
rc = _sqlite3PagerGet(tls, (*TBtShared)(unsafe.Pointer(pBt)).FpPager, **(**TPgno)(__ccgo_up(bp)), bp+8, v2)
if rc == SQLITE_OK {
if eOp != 0 && (_sqlite3PagerPageRefcount(tls, **(**uintptr)(__ccgo_up(bp + 8))) != int32(1) || (*TMemPage)(unsafe.Pointer(_sqlite3PagerGetExtra(tls, **(**uintptr)(__ccgo_up(bp + 8))))).FisInit != 0) {
_sqlite3PagerUnref(tls, **(**uintptr)(__ccgo_up(bp + 8)))
return _sqlite3CorruptError(tls, int32(78529))
}
aPayload = _sqlite3PagerGetData(tls, **(**uintptr)(__ccgo_up(bp + 8)))
**(**TPgno)(__ccgo_up(bp)) = _sqlite3Get4byte(tls, aPayload)
rc = _copyPayload(tls, aPayload+uintptr(offset+uint32(4)), pBuf, a1, eOp, **(**uintptr)(__ccgo_up(bp + 8)))
_sqlite3PagerUnref(tls, **(**uintptr)(__ccgo_up(bp + 8)))
offset = uint32(0)
}
}
amt = amt - libc.Uint32FromInt32(a1)
if amt == uint32(0) {
return rc
}
pBuf = pBuf + uintptr(a1)
}
if rc != 0 {
break
}
iIdx = iIdx + 1
}
}
if rc == SQLITE_OK && amt > uint32(0) {
/* Overflow chain ends prematurely */
return _sqlite3CorruptError(tls, int32(78549))
}
return rc
}
// C documentation
//
// /*
// ** Return a human-readable name for a constraint resolution action.
// */
func _actionName(tls *libc.TLS, action Tu8) (r uintptr) {
var zName uintptr
_ = zName
switch libc.Int32FromUint8(action) {
case int32(OE_SetNull):
zName = __ccgo_ts + 19469
case int32(OE_SetDflt):
zName = __ccgo_ts + 19478
case int32(OE_Cascade):
zName = __ccgo_ts + 19490
case int32(OE_Restrict):
zName = __ccgo_ts + 19498
default:
zName = __ccgo_ts + 19507
break
}
return zName
}
// C documentation
//
// /*
// ** Internal SQL function:
// **
// ** sqlite_add_constraint(SQL, CONSTRAINT-TEXT, ICOL)
// **
// ** SQL is a CREATE TABLE statement. Return a modified version of
// ** SQL that adds CONSTRAINT-TEXT at the end of the ICOL-th column
// ** definition. (The left-most column defintion is 0.)
// */
func _addConstraintFunc(tls *libc.TLS, ctx uintptr, NotUsed int32, argv uintptr) {
bp := tls.Alloc(48)
defer tls.Free(48)
var db, zCons, zNew, zSql uintptr
var iCol, ii, nTok int32
var _ /* iOff at bp+0 */ int32
var _ /* t at bp+4 */ int32
_, _, _, _, _, _, _ = db, iCol, ii, nTok, zCons, zNew, zSql
zSql = Xsqlite3_value_text(tls, **(**uintptr)(__ccgo_up(argv)))
zCons = Xsqlite3_value_text(tls, **(**uintptr)(__ccgo_up(argv + 1*8)))
iCol = Xsqlite3_value_int(tls, **(**uintptr)(__ccgo_up(argv + 2*8)))
**(**int32)(__ccgo_up(bp)) = 0
zNew = uintptr(0)
**(**int32)(__ccgo_up(bp + 4)) = 0
_ = NotUsed
if _skipCreateTable(tls, ctx, zSql, bp) != 0 {
return
}
ii = 0
for {
if !(ii <= iCol || iCol < 0 && **(**int32)(__ccgo_up(bp + 4)) != int32(TK_RP)) {
break
}
**(**int32)(__ccgo_up(bp)) = **(**int32)(__ccgo_up(bp)) + _getConstraintToken(tls, zSql+uintptr(**(**int32)(__ccgo_up(bp))), bp+4)
for int32(1) != 0 {
nTok = _getConstraintToken(tls, zSql+uintptr(**(**int32)(__ccgo_up(bp))), bp+4)
if **(**int32)(__ccgo_up(bp + 4)) == int32(TK_COMMA) || **(**int32)(__ccgo_up(bp + 4)) == int32(TK_RP) {
break
}
if **(**int32)(__ccgo_up(bp + 4)) == int32(TK_ILLEGAL) {
Xsqlite3_result_error_code(tls, ctx, _sqlite3CorruptError(tls, int32(123226)))
return
}
**(**int32)(__ccgo_up(bp)) = **(**int32)(__ccgo_up(bp)) + nTok
}
goto _1
_1:
;
ii = ii + 1
}
**(**int32)(__ccgo_up(bp)) = **(**int32)(__ccgo_up(bp)) + _getWhitespace(tls, zSql+uintptr(**(**int32)(__ccgo_up(bp))))
db = Xsqlite3_context_db_handle(tls, ctx)
if iCol < 0 {
zNew = _sqlite3MPrintf(tls, db, __ccgo_ts+12233, libc.VaList(bp+16, **(**int32)(__ccgo_up(bp)), zSql, zCons, zSql+uintptr(**(**int32)(__ccgo_up(bp)))))
} else {
zNew = _sqlite3MPrintf(tls, db, __ccgo_ts+12244, libc.VaList(bp+16, **(**int32)(__ccgo_up(bp)), zSql, zCons, zSql+uintptr(**(**int32)(__ccgo_up(bp)))))
}
Xsqlite3_result_text(tls, ctx, zNew, -int32(1), __ccgo_fp(_sqlite3RowSetClear))
}
// C documentation
//
// /*
// ** Add a new module argument to pTable->u.vtab.azArg[].
// ** The string is not copied - the pointer is stored. The
// ** string will be freed automatically when the table is
// ** deleted.
// */
func _addModuleArgument(tls *libc.TLS, pParse uintptr, pTable uintptr, zArg uintptr) {
bp := tls.Alloc(16)
defer tls.Free(16)
var azModuleArg, db, v2 uintptr
var i, v1 int32
var nBytes Tsqlite3_int64
_, _, _, _, _, _ = azModuleArg, db, i, nBytes, v1, v2
db = (*TParse)(unsafe.Pointer(pParse)).Fdb
nBytes = libc.Int64FromUint64(uint64(8) * libc.Uint64FromInt32(libc.Int32FromInt32(2)+(*(*struct {
FnArg int32
FazArg uintptr
Fp uintptr
})(unsafe.Pointer(pTable + 64))).FnArg))
if (*(*struct {
FnArg int32
FazArg uintptr
Fp uintptr
})(unsafe.Pointer(pTable + 64))).FnArg+int32(3) >= **(**int32)(__ccgo_up(db + 136 + 2*4)) {
_sqlite3ErrorMsg(tls, pParse, __ccgo_ts+14304, libc.VaList(bp+8, (*TTable)(unsafe.Pointer(pTable)).FzName))
}
azModuleArg = _sqlite3DbRealloc(tls, db, (*(*struct {
FnArg int32
FazArg uintptr
Fp uintptr
})(unsafe.Pointer(pTable + 64))).FazArg, libc.Uint64FromInt64(nBytes))
if azModuleArg == uintptr(0) {
_sqlite3DbFree(tls, db, zArg)
} else {
v2 = pTable + 64
v1 = *(*int32)(unsafe.Pointer(v2))
*(*int32)(unsafe.Pointer(v2)) = *(*int32)(unsafe.Pointer(v2)) + 1
i = v1
**(**uintptr)(__ccgo_up(azModuleArg + uintptr(i)*8)) = zArg
**(**uintptr)(__ccgo_up(azModuleArg + uintptr(i+int32(1))*8)) = uintptr(0)
(*(*struct {
FnArg int32
FazArg uintptr
Fp uintptr
})(unsafe.Pointer(pTable + 64))).FazArg = azModuleArg
}
}
// C documentation
//
// /*
// ** This routine checks if there is a RESERVED lock held on the specified
// ** file by this or any other process. If such a lock is held, set *pResOut
// ** to a non-zero value otherwise *pResOut is set to zero. The return value
// ** is set to SQLITE_OK unless an I/O error occurs during lock checking.
// */
func _afpCheckReservedLock(tls *libc.TLS, id uintptr, pResOut uintptr) (r int32) {
var context, pFile uintptr
var lrc, rc, reserved int32
_, _, _, _, _ = context, lrc, pFile, rc, reserved
rc = SQLITE_OK
reserved = 0
pFile = id
context = (*TunixFile)(unsafe.Pointer(pFile)).FlockingContext
if (*TafpLockingContext)(unsafe.Pointer(context)).Freserved != 0 {
**(**int32)(__ccgo_up(pResOut)) = int32(1)
return SQLITE_OK
}
Xsqlite3_mutex_enter(tls, (*TunixInodeInfo)(unsafe.Pointer((*TunixFile)(unsafe.Pointer(pFile)).FpInode)).FpLockMutex)
/* Check if a thread in this process holds such a lock */
if libc.Int32FromUint8((*TunixInodeInfo)(unsafe.Pointer((*TunixFile)(unsafe.Pointer(pFile)).FpInode)).FeFileLock) > int32(SHARED_LOCK) {
reserved = int32(1)
}
/* Otherwise see if some other process holds it.
*/
if !(reserved != 0) {
/* lock the RESERVED byte */
lrc = _afpSetLock(tls, (*TafpLockingContext)(unsafe.Pointer(context)).FdbPath, pFile, libc.Uint64FromInt32(_sqlite3PendingByte+libc.Int32FromInt32(1)), uint64(1), int32(1))
if SQLITE_OK == lrc {
/* if we succeeded in taking the reserved lock, unlock it to restore
** the original state */
lrc = _afpSetLock(tls, (*TafpLockingContext)(unsafe.Pointer(context)).FdbPath, pFile, libc.Uint64FromInt32(_sqlite3PendingByte+libc.Int32FromInt32(1)), uint64(1), 0)
} else {
/* if we failed to get the lock then someone else must have it */
reserved = int32(1)
}
if lrc != SQLITE_OK && lrc != int32(SQLITE_BUSY) {
rc = lrc
}
}
Xsqlite3_mutex_leave(tls, (*TunixInodeInfo)(unsafe.Pointer((*TunixFile)(unsafe.Pointer(pFile)).FpInode)).FpLockMutex)
**(**int32)(__ccgo_up(pResOut)) = reserved
return rc
}
// C documentation
//
// /*
// ** Close a file & cleanup AFP specific locking context
// */
func _afpClose(tls *libc.TLS, id uintptr) (r int32) {
var pFile, pInode uintptr
var rc int32
_, _, _ = pFile, pInode, rc
rc = SQLITE_OK
pFile = id
_afpUnlock(tls, id, NO_LOCK)
_unixEnterMutex(tls)
if (*TunixFile)(unsafe.Pointer(pFile)).FpInode != 0 {
pInode = (*TunixFile)(unsafe.Pointer(pFile)).FpInode
Xsqlite3_mutex_enter(tls, (*TunixInodeInfo)(unsafe.Pointer(pInode)).FpLockMutex)
if (*TunixInodeInfo)(unsafe.Pointer(pInode)).FnLock != 0 {
/* If there are outstanding locks, do not actually close the file just
** yet because that would clear those locks. Instead, add the file
** descriptor to pInode->aPending. It will be automatically closed when
** the last lock is cleared.
*/
_setPendingFd(tls, pFile)
}
Xsqlite3_mutex_leave(tls, (*TunixInodeInfo)(unsafe.Pointer(pInode)).FpLockMutex)
}
_releaseInodeInfo(tls, pFile)
Xsqlite3_free(tls, (*TunixFile)(unsafe.Pointer(pFile)).FlockingContext)
rc = _closeUnixFile(tls, id)
_unixLeaveMutex(tls)
return rc
}
/*
** The code above is the AFP lock implementation. The code is specific
** to MacOSX and does not work on other unix platforms. No alternative
** is available. If you don't compile for a mac, then the "unix-afp"
** VFS is not available.
**
********************* End of the AFP lock implementation **********************
******************************************************************************/
/******************************************************************************
*************************** Begin NFS Locking ********************************/
var _afpIoFinder = uintptr(0)
func _afpIoFinderImpl(tls *libc.TLS, z uintptr, p uintptr) (r uintptr) {
_ = z
_ = p
return uintptr(unsafe.Pointer(&_afpIoMethods))
}
var _afpIoMethods = Tsqlite3_io_methods{
FiVersion: int32(1),
}
// C documentation
//
// /*
// ** Lock the file with the lock specified by parameter eFileLock - one
// ** of the following:
// **
// ** (1) SHARED_LOCK
// ** (2) RESERVED_LOCK
// ** (3) PENDING_LOCK
// ** (4) EXCLUSIVE_LOCK
// **
// ** Sometimes when requesting one lock state, additional lock states
// ** are inserted in between. The locking might fail on one of the later
// ** transitions leaving the lock state different from what it started but
// ** still short of its goal. The following chart shows the allowed
// ** transitions and the inserted intermediate states:
// **
// ** UNLOCKED -> SHARED
// ** SHARED -> RESERVED
// ** SHARED -> (PENDING) -> EXCLUSIVE
// ** RESERVED -> (PENDING) -> EXCLUSIVE
// ** PENDING -> EXCLUSIVE
// **
// ** This routine will only increase a lock. Use the sqlite3OsUnlock()
// ** routine to lower a locking level.
// */
func _afpLock(tls *libc.TLS, id uintptr, eFileLock int32) (r int32) {
var context, pFile, pInode uintptr
var failed, failed1, failed2, lrc1, lrc1Errno, lrc2, rc, v1, v2 int32
var lk, mask int64
var v3 bool
_, _, _, _, _, _, _, _, _, _, _, _, _, _, _ = context, failed, failed1, failed2, lk, lrc1, lrc1Errno, lrc2, mask, pFile, pInode, rc, v1, v2, v3
rc = SQLITE_OK
pFile = id
pInode = (*TunixFile)(unsafe.Pointer(pFile)).FpInode
context = (*TunixFile)(unsafe.Pointer(pFile)).FlockingContext
/* If there is already a lock of this type or more restrictive on the
** unixFile, do nothing. Don't use the afp_end_lock: exit path, as
** unixEnterMutex() hasn't been called yet.
*/
if libc.Int32FromUint8((*TunixFile)(unsafe.Pointer(pFile)).FeFileLock) >= eFileLock {
return SQLITE_OK
}
/* Make sure the locking sequence is correct
** (1) We never move from unlocked to anything higher than shared lock.
** (2) SQLite never explicitly requests a pending lock.
** (3) A shared lock is always held when a reserve lock is requested.
*/
/* This mutex is needed because pFile->pInode is shared across threads
*/
pInode = (*TunixFile)(unsafe.Pointer(pFile)).FpInode
Xsqlite3_mutex_enter(tls, (*TunixInodeInfo)(unsafe.Pointer(pInode)).FpLockMutex)
/* If some thread using this PID has a lock via a different unixFile*
** handle that precludes the requested lock, return BUSY.
*/
if libc.Int32FromUint8((*TunixFile)(unsafe.Pointer(pFile)).FeFileLock) != libc.Int32FromUint8((*TunixInodeInfo)(unsafe.Pointer(pInode)).FeFileLock) && (libc.Int32FromUint8((*TunixInodeInfo)(unsafe.Pointer(pInode)).FeFileLock) >= int32(PENDING_LOCK) || eFileLock > int32(SHARED_LOCK)) {
rc = int32(SQLITE_BUSY)
goto afp_end_lock
}
/* If a SHARED lock is requested, and some thread using this PID already
** has a SHARED or RESERVED lock, then increment reference counts and
** return SQLITE_OK.
*/
if eFileLock == int32(SHARED_LOCK) && (libc.Int32FromUint8((*TunixInodeInfo)(unsafe.Pointer(pInode)).FeFileLock) == int32(SHARED_LOCK) || libc.Int32FromUint8((*TunixInodeInfo)(unsafe.Pointer(pInode)).FeFileLock) == int32(RESERVED_LOCK)) {
(*TunixFile)(unsafe.Pointer(pFile)).FeFileLock = uint8(SHARED_LOCK)
(*TunixInodeInfo)(unsafe.Pointer(pInode)).FnShared = (*TunixInodeInfo)(unsafe.Pointer(pInode)).FnShared + 1
(*TunixInodeInfo)(unsafe.Pointer(pInode)).FnLock = (*TunixInodeInfo)(unsafe.Pointer(pInode)).FnLock + 1
goto afp_end_lock
}
/* A PENDING lock is needed before acquiring a SHARED lock and before
** acquiring an EXCLUSIVE lock. For the SHARED lock, the PENDING will
** be released.
*/
if eFileLock == int32(SHARED_LOCK) || eFileLock == int32(EXCLUSIVE_LOCK) && libc.Int32FromUint8((*TunixFile)(unsafe.Pointer(pFile)).FeFileLock) < int32(PENDING_LOCK) {
failed = _afpSetLock(tls, (*TafpLockingContext)(unsafe.Pointer(context)).FdbPath, pFile, libc.Uint64FromInt32(_sqlite3PendingByte), uint64(1), int32(1))
if failed != 0 {
rc = failed
goto afp_end_lock
}
}
/* If control gets to this point, then actually go ahead and make
** operating system calls for the specified lock.
*/
if eFileLock == int32(SHARED_LOCK) {
lrc1Errno = 0
mask = int64(libc.Int64FromUint32(0xffffffff) | libc.Int64FromInt32(0x7fffffff)< int32(1) {
/* We are trying for an exclusive lock but another thread in this
** same process is still holding a shared lock. */
rc = int32(SQLITE_BUSY)
} else {
/* The request was for a RESERVED or EXCLUSIVE lock. It is
** assumed that there is a SHARED or greater lock on the file
** already.
*/
failed1 = 0
if eFileLock >= int32(RESERVED_LOCK) && libc.Int32FromUint8((*TunixFile)(unsafe.Pointer(pFile)).FeFileLock) < int32(RESERVED_LOCK) {
/* Acquire a RESERVED lock */
failed1 = _afpSetLock(tls, (*TafpLockingContext)(unsafe.Pointer(context)).FdbPath, pFile, libc.Uint64FromInt32(_sqlite3PendingByte+libc.Int32FromInt32(1)), uint64(1), int32(1))
if !(failed1 != 0) {
(*TafpLockingContext)(unsafe.Pointer(context)).Freserved = int32(1)
}
}
if !(failed1 != 0) && eFileLock == int32(EXCLUSIVE_LOCK) {
/* Acquire an EXCLUSIVE lock */
/* Remove the shared lock before trying the range. we'll need to
** reestablish the shared lock if we can't get the afpUnlock
*/
v1 = _afpSetLock(tls, (*TafpLockingContext)(unsafe.Pointer(context)).FdbPath, pFile, libc.Uint64FromInt32(_sqlite3PendingByte+libc.Int32FromInt32(2))+(*TunixInodeInfo)(unsafe.Pointer(pInode)).FsharedByte, uint64(1), 0)
failed1 = v1
if !(v1 != 0) {
failed2 = SQLITE_OK
/* now attempt to get the exclusive lock range */
failed1 = _afpSetLock(tls, (*TafpLockingContext)(unsafe.Pointer(context)).FdbPath, pFile, libc.Uint64FromInt32(_sqlite3PendingByte+libc.Int32FromInt32(2)), uint64(SHARED_SIZE), int32(1))
if v3 = failed1 != 0; v3 {
v1 = _afpSetLock(tls, (*TafpLockingContext)(unsafe.Pointer(context)).FdbPath, pFile, libc.Uint64FromInt32(_sqlite3PendingByte+libc.Int32FromInt32(2))+(*TunixInodeInfo)(unsafe.Pointer(pInode)).FsharedByte, uint64(1), int32(1))
failed2 = v1
}
if v3 && v1 != 0 {
/* Can't reestablish the shared lock. Sqlite can't deal, this is
** a critical I/O error
*/
if failed1&int32(0xff) == int32(SQLITE_IOERR) {
v2 = failed2
} else {
v2 = libc.Int32FromInt32(SQLITE_IOERR) | libc.Int32FromInt32(15)< int32(SHARED_LOCK) {
if libc.Int32FromUint8((*TunixFile)(unsafe.Pointer(pFile)).FeFileLock) == int32(EXCLUSIVE_LOCK) {
rc = _afpSetLock(tls, (*TafpLockingContext)(unsafe.Pointer(context)).FdbPath, pFile, libc.Uint64FromInt32(_sqlite3PendingByte+libc.Int32FromInt32(2)), uint64(SHARED_SIZE), 0)
if rc == SQLITE_OK && (eFileLock == int32(SHARED_LOCK) || (*TunixInodeInfo)(unsafe.Pointer(pInode)).FnShared > int32(1)) {
/* only re-establish the shared lock if necessary */
sharedLockByte = libc.Int32FromUint64(libc.Uint64FromInt32(_sqlite3PendingByte+libc.Int32FromInt32(2)) + (*TunixInodeInfo)(unsafe.Pointer(pInode)).FsharedByte)
rc = _afpSetLock(tls, (*TafpLockingContext)(unsafe.Pointer(context)).FdbPath, pFile, libc.Uint64FromInt32(sharedLockByte), uint64(1), int32(1))
} else {
skipShared = int32(1)
}
}
if rc == SQLITE_OK && libc.Int32FromUint8((*TunixFile)(unsafe.Pointer(pFile)).FeFileLock) >= int32(PENDING_LOCK) {
rc = _afpSetLock(tls, (*TafpLockingContext)(unsafe.Pointer(context)).FdbPath, pFile, libc.Uint64FromInt32(_sqlite3PendingByte), uint64(1), 0)
}
if rc == SQLITE_OK && libc.Int32FromUint8((*TunixFile)(unsafe.Pointer(pFile)).FeFileLock) >= int32(RESERVED_LOCK) && (*TafpLockingContext)(unsafe.Pointer(context)).Freserved != 0 {
rc = _afpSetLock(tls, (*TafpLockingContext)(unsafe.Pointer(context)).FdbPath, pFile, libc.Uint64FromInt32(_sqlite3PendingByte+libc.Int32FromInt32(1)), uint64(1), 0)
if !(rc != 0) {
(*TafpLockingContext)(unsafe.Pointer(context)).Freserved = 0
}
}
if rc == SQLITE_OK && (eFileLock == int32(SHARED_LOCK) || (*TunixInodeInfo)(unsafe.Pointer(pInode)).FnShared > int32(1)) {
(*TunixInodeInfo)(unsafe.Pointer(pInode)).FeFileLock = uint8(SHARED_LOCK)
}
}
if rc == SQLITE_OK && eFileLock == NO_LOCK {
/* Decrement the shared lock counter. Release the lock using an
** OS call only when all threads in this same process have released
** the lock.
*/
sharedLockByte1 = libc.Uint64FromInt32(_sqlite3PendingByte+libc.Int32FromInt32(2)) + (*TunixInodeInfo)(unsafe.Pointer(pInode)).FsharedByte
(*TunixInodeInfo)(unsafe.Pointer(pInode)).FnShared = (*TunixInodeInfo)(unsafe.Pointer(pInode)).FnShared - 1
if (*TunixInodeInfo)(unsafe.Pointer(pInode)).FnShared == 0 {
if !(skipShared != 0) {
rc = _afpSetLock(tls, (*TafpLockingContext)(unsafe.Pointer(context)).FdbPath, pFile, sharedLockByte1, uint64(1), 0)
}
if !(rc != 0) {
(*TunixInodeInfo)(unsafe.Pointer(pInode)).FeFileLock = uint8(NO_LOCK)
(*TunixFile)(unsafe.Pointer(pFile)).FeFileLock = uint8(NO_LOCK)
}
}
if rc == SQLITE_OK {
(*TunixInodeInfo)(unsafe.Pointer(pInode)).FnLock = (*TunixInodeInfo)(unsafe.Pointer(pInode)).FnLock - 1
if (*TunixInodeInfo)(unsafe.Pointer(pInode)).FnLock == 0 {
_closePendingFds(tls, pFile)
}
}
}
Xsqlite3_mutex_leave(tls, (*TunixInodeInfo)(unsafe.Pointer(pInode)).FpLockMutex)
if rc == SQLITE_OK {
(*TunixFile)(unsafe.Pointer(pFile)).FeFileLock = libc.Uint8FromInt32(eFileLock)
}
return rc
}
// C documentation
//
// /*
// ** Convert every pAggInfo->aFunc[].pExpr such that any node within
// ** those expressions that has pAppInfo set is changed into a TK_AGG_COLUMN
// ** opcode.
// */
func _aggregateConvertIndexedExprRefToColumn(tls *libc.TLS, pAggInfo uintptr) {
bp := tls.Alloc(48)
defer tls.Free(48)
var i int32
var _ /* w at bp+0 */ TWalker
_ = i
libc.X__builtin___memset_chk(tls, bp, 0, uint64(48), ^t__predefined_size_t(0))
(**(**TWalker)(__ccgo_up(bp))).FxExprCallback = __ccgo_fp(_aggregateIdxEprRefToColCallback)
i = 0
for {
if !(i < (*TAggInfo)(unsafe.Pointer(pAggInfo)).FnFunc) {
break
}
_sqlite3WalkExpr(tls, bp, (**(**TAggInfo_func)(__ccgo_up((*TAggInfo)(unsafe.Pointer(pAggInfo)).FaFunc + uintptr(i)*32))).FpFExpr)
goto _1
_1:
;
i = i + 1
}
}
// C documentation
//
// /*
// ** Allocate a new page from the database file.
// **
// ** The new page is marked as dirty. (In other words, sqlite3PagerWrite()
// ** has already been called on the new page.) The new page has also
// ** been referenced and the calling routine is responsible for calling
// ** sqlite3PagerUnref() on the new page when it is done.
// **
// ** SQLITE_OK is returned on success. Any other return value indicates
// ** an error. *ppPage is set to NULL in the event of an error.
// **
// ** If the "nearby" parameter is not 0, then an effort is made to
// ** locate a page close to the page number "nearby". This can be used in an
// ** attempt to keep related pages close to each other in the database file,
// ** which in turn can make database access faster.
// **
// ** If the eMode parameter is BTALLOC_EXACT and the nearby page exists
// ** anywhere on the free-list, then it is guaranteed to be returned. If
// ** eMode is BTALLOC_LT then the page returned will be less than or equal
// ** to nearby if any such page exists. If eMode is BTALLOC_ANY then there
// ** are no restrictions on which page is returned.
// */
func _allocateBtreePage(tls *libc.TLS, pBt uintptr, ppPage uintptr, pPgno uintptr, nearby TPgno, eMode Tu8) (r int32) {
bp := tls.Alloc(32)
defer tls.Free(32)
var aData, pPage1, pPrevTrunk uintptr
var bNoContent, d2, dist, noContent, rc, v5 int32
var closest, i, k, n, nSearch, v1 Tu32
var iNewTrunk, iPage, iTrunk, mxPage TPgno
var searchList Tu8
var v2 bool
var _ /* eType at bp+8 */ Tu8
var _ /* pNewTrunk at bp+16 */ uintptr
var _ /* pPg at bp+24 */ uintptr
var _ /* pTrunk at bp+0 */ uintptr
_, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _ = aData, bNoContent, closest, d2, dist, i, iNewTrunk, iPage, iTrunk, k, mxPage, n, nSearch, noContent, pPage1, pPrevTrunk, rc, searchList, v1, v2, v5 /* Number of leaves on the trunk of the freelist */
**(**uintptr)(__ccgo_up(bp)) = uintptr(0)
pPrevTrunk = uintptr(0) /* Total size of the database file */
pPage1 = (*TBtShared)(unsafe.Pointer(pBt)).FpPage1
mxPage = _btreePagecount(tls, pBt)
/* EVIDENCE-OF: R-21003-45125 The 4-byte big-endian integer at offset 36
** stores the total number of pages on the freelist. */
n = _sqlite3Get4byte(tls, (*TMemPage)(unsafe.Pointer(pPage1)).FaData+36)
if n >= mxPage {
return _sqlite3CorruptError(tls, int32(79764))
}
if n > uint32(0) {
searchList = uint8(0) /* If the free-list must be searched for 'nearby' */
nSearch = uint32(0) /* Count of the number of search attempts */
/* If eMode==BTALLOC_EXACT and a query of the pointer-map
** shows that the page 'nearby' is somewhere on the free-list, then
** the entire-list will be searched for that page.
*/
if libc.Int32FromUint8(eMode) == int32(BTALLOC_EXACT) {
if nearby <= mxPage {
rc = _ptrmapGet(tls, pBt, nearby, bp+8, uintptr(0))
if rc != 0 {
return rc
}
if libc.Int32FromUint8(**(**Tu8)(__ccgo_up(bp + 8))) == int32(PTRMAP_FREEPAGE) {
searchList = uint8(1)
}
}
} else {
if libc.Int32FromUint8(eMode) == int32(BTALLOC_LE) {
searchList = uint8(1)
}
}
/* Decrement the free-list count by 1. Set iTrunk to the index of the
** first free-list trunk page. iPrevTrunk is initially 1.
*/
rc = _sqlite3PagerWrite(tls, (*TMemPage)(unsafe.Pointer(pPage1)).FpDbPage)
if rc != 0 {
return rc
}
_sqlite3Put4byte(tls, (*TMemPage)(unsafe.Pointer(pPage1)).FaData+36, n-uint32(1))
/* The code within this loop is run only once if the 'searchList' variable
** is not true. Otherwise, it runs once for each trunk-page on the
** free-list until the page 'nearby' is located (eMode==BTALLOC_EXACT)
** or until a page less than 'nearby' is located (eMode==BTALLOC_LT)
*/
for cond := true; cond; cond = searchList != 0 {
pPrevTrunk = **(**uintptr)(__ccgo_up(bp))
if pPrevTrunk != 0 {
/* EVIDENCE-OF: R-01506-11053 The first integer on a freelist trunk page
** is the page number of the next freelist trunk page in the list or
** zero if this is the last freelist trunk page. */
iTrunk = _sqlite3Get4byte(tls, (*TMemPage)(unsafe.Pointer(pPrevTrunk)).FaData)
} else {
/* EVIDENCE-OF: R-59841-13798 The 4-byte big-endian integer at offset 32
** stores the page number of the first page of the freelist, or zero if
** the freelist is empty. */
iTrunk = _sqlite3Get4byte(tls, (*TMemPage)(unsafe.Pointer(pPage1)).FaData+32)
}
if v2 = iTrunk > mxPage; !v2 {
v1 = nSearch
nSearch = nSearch + 1
}
if v2 || v1 > n {
rc = _sqlite3CorruptError(tls, int32(79820))
} else {
rc = _btreeGetUnusedPage(tls, pBt, iTrunk, bp, 0)
}
if rc != 0 {
**(**uintptr)(__ccgo_up(bp)) = uintptr(0)
goto end_allocate_page
}
/* EVIDENCE-OF: R-13523-04394 The second integer on a freelist trunk page
** is the number of leaf page pointers to follow. */
k = _sqlite3Get4byte(tls, (*TMemPage)(unsafe.Pointer(**(**uintptr)(__ccgo_up(bp)))).FaData+4)
if k == uint32(0) && !(searchList != 0) {
/* The trunk has no leaves and the list is not being searched.
** So extract the trunk page itself and use it as the newly
** allocated page */
rc = _sqlite3PagerWrite(tls, (*TMemPage)(unsafe.Pointer(**(**uintptr)(__ccgo_up(bp)))).FpDbPage)
if rc != 0 {
goto end_allocate_page
}
**(**TPgno)(__ccgo_up(pPgno)) = iTrunk
libc.X__builtin___memcpy_chk(tls, (*TMemPage)(unsafe.Pointer(pPage1)).FaData+32, (*TMemPage)(unsafe.Pointer(**(**uintptr)(__ccgo_up(bp)))).FaData, uint64(4), ^t__predefined_size_t(0))
**(**uintptr)(__ccgo_up(ppPage)) = **(**uintptr)(__ccgo_up(bp))
**(**uintptr)(__ccgo_up(bp)) = uintptr(0)
} else {
if k > (*TBtShared)(unsafe.Pointer(pBt)).FusableSize/libc.Uint32FromInt32(4)-libc.Uint32FromInt32(2) {
/* Value of k is out of range. Database corruption */
rc = _sqlite3CorruptError(tls, int32(79849))
goto end_allocate_page
} else {
if searchList != 0 && (nearby == iTrunk || iTrunk < nearby && libc.Int32FromUint8(eMode) == int32(BTALLOC_LE)) {
/* The list is being searched and this trunk page is the page
** to allocate, regardless of whether it has leaves.
*/
**(**TPgno)(__ccgo_up(pPgno)) = iTrunk
**(**uintptr)(__ccgo_up(ppPage)) = **(**uintptr)(__ccgo_up(bp))
searchList = uint8(0)
rc = _sqlite3PagerWrite(tls, (*TMemPage)(unsafe.Pointer(**(**uintptr)(__ccgo_up(bp)))).FpDbPage)
if rc != 0 {
goto end_allocate_page
}
if k == uint32(0) {
if !(pPrevTrunk != 0) {
libc.X__builtin___memcpy_chk(tls, (*TMemPage)(unsafe.Pointer(pPage1)).FaData+32, (*TMemPage)(unsafe.Pointer(**(**uintptr)(__ccgo_up(bp)))).FaData, uint64(4), ^t__predefined_size_t(0))
} else {
rc = _sqlite3PagerWrite(tls, (*TMemPage)(unsafe.Pointer(pPrevTrunk)).FpDbPage)
if rc != SQLITE_OK {
goto end_allocate_page
}
libc.X__builtin___memcpy_chk(tls, (*TMemPage)(unsafe.Pointer(pPrevTrunk)).FaData, (*TMemPage)(unsafe.Pointer(**(**uintptr)(__ccgo_up(bp)))).FaData, uint64(4), ^t__predefined_size_t(0))
}
} else {
iNewTrunk = _sqlite3Get4byte(tls, (*TMemPage)(unsafe.Pointer(**(**uintptr)(__ccgo_up(bp)))).FaData+8)
if iNewTrunk > mxPage {
rc = _sqlite3CorruptError(tls, int32(79883))
goto end_allocate_page
}
rc = _btreeGetUnusedPage(tls, pBt, iNewTrunk, bp+16, 0)
if rc != SQLITE_OK {
goto end_allocate_page
}
rc = _sqlite3PagerWrite(tls, (*TMemPage)(unsafe.Pointer(**(**uintptr)(__ccgo_up(bp + 16)))).FpDbPage)
if rc != SQLITE_OK {
_releasePage(tls, **(**uintptr)(__ccgo_up(bp + 16)))
goto end_allocate_page
}
libc.X__builtin___memcpy_chk(tls, (*TMemPage)(unsafe.Pointer(**(**uintptr)(__ccgo_up(bp + 16)))).FaData, (*TMemPage)(unsafe.Pointer(**(**uintptr)(__ccgo_up(bp)))).FaData, uint64(4), ^t__predefined_size_t(0))
_sqlite3Put4byte(tls, (*TMemPage)(unsafe.Pointer(**(**uintptr)(__ccgo_up(bp + 16)))).FaData+4, k-uint32(1))
libc.X__builtin___memcpy_chk(tls, (*TMemPage)(unsafe.Pointer(**(**uintptr)(__ccgo_up(bp + 16)))).FaData+8, (*TMemPage)(unsafe.Pointer(**(**uintptr)(__ccgo_up(bp)))).FaData+12, uint64((k-uint32(1))*uint32(4)), ^t__predefined_size_t(0))
_releasePage(tls, **(**uintptr)(__ccgo_up(bp + 16)))
if !(pPrevTrunk != 0) {
_sqlite3Put4byte(tls, (*TMemPage)(unsafe.Pointer(pPage1)).FaData+32, iNewTrunk)
} else {
rc = _sqlite3PagerWrite(tls, (*TMemPage)(unsafe.Pointer(pPrevTrunk)).FpDbPage)
if rc != 0 {
goto end_allocate_page
}
_sqlite3Put4byte(tls, (*TMemPage)(unsafe.Pointer(pPrevTrunk)).FaData, iNewTrunk)
}
}
**(**uintptr)(__ccgo_up(bp)) = uintptr(0)
} else {
if k > uint32(0) {
aData = (*TMemPage)(unsafe.Pointer(**(**uintptr)(__ccgo_up(bp)))).FaData
if nearby > uint32(0) {
closest = uint32(0)
if libc.Int32FromUint8(eMode) == int32(BTALLOC_LE) {
i = uint32(0)
for {
if !(i < k) {
break
}
iPage = _sqlite3Get4byte(tls, aData+uintptr(uint32(8)+i*uint32(4)))
if iPage <= nearby {
closest = i
break
}
goto _3
_3:
;
i = i + 1
}
} else {
dist = _sqlite3AbsInt32(tls, libc.Int32FromUint32(_sqlite3Get4byte(tls, aData+8)-nearby))
i = uint32(1)
for {
if !(i < k) {
break
}
d2 = _sqlite3AbsInt32(tls, libc.Int32FromUint32(_sqlite3Get4byte(tls, aData+uintptr(uint32(8)+i*uint32(4)))-nearby))
if d2 < dist {
closest = i
dist = d2
}
goto _4
_4:
;
i = i + 1
}
}
} else {
closest = uint32(0)
}
iPage = _sqlite3Get4byte(tls, aData+uintptr(uint32(8)+closest*uint32(4)))
if iPage > mxPage || iPage < uint32(2) {
rc = _sqlite3CorruptError(tls, int32(79948))
goto end_allocate_page
}
if !(searchList != 0) || (iPage == nearby || iPage < nearby && libc.Int32FromUint8(eMode) == int32(BTALLOC_LE)) {
**(**TPgno)(__ccgo_up(pPgno)) = iPage
rc = _sqlite3PagerWrite(tls, (*TMemPage)(unsafe.Pointer(**(**uintptr)(__ccgo_up(bp)))).FpDbPage)
if rc != 0 {
goto end_allocate_page
}
if closest < k-uint32(1) {
libc.X__builtin___memcpy_chk(tls, aData+uintptr(uint32(8)+closest*uint32(4)), aData+uintptr(uint32(4)+k*uint32(4)), uint64(4), ^t__predefined_size_t(0))
}
_sqlite3Put4byte(tls, aData+4, k-uint32(1))
if !(_btreeGetHasContent(tls, pBt, **(**TPgno)(__ccgo_up(pPgno))) != 0) {
v5 = int32(PAGER_GET_NOCONTENT)
} else {
v5 = 0
}
noContent = v5
rc = _btreeGetUnusedPage(tls, pBt, **(**TPgno)(__ccgo_up(pPgno)), ppPage, noContent)
if rc == SQLITE_OK {
rc = _sqlite3PagerWrite(tls, (*TMemPage)(unsafe.Pointer(**(**uintptr)(__ccgo_up(ppPage)))).FpDbPage)
if rc != SQLITE_OK {
_releasePage(tls, **(**uintptr)(__ccgo_up(ppPage)))
**(**uintptr)(__ccgo_up(ppPage)) = uintptr(0)
}
}
searchList = uint8(0)
}
}
}
}
}
_releasePage(tls, pPrevTrunk)
pPrevTrunk = uintptr(0)
}
} else {
if 0 == libc.Int32FromUint8((*TBtShared)(unsafe.Pointer(pBt)).FbDoTruncate) {
v5 = int32(PAGER_GET_NOCONTENT)
} else {
v5 = 0
}
/* There are no pages on the freelist, so append a new page to the
** database image.
**
** Normally, new pages allocated by this block can be requested from the
** pager layer with the 'no-content' flag set. This prevents the pager
** from trying to read the pages content from disk. However, if the
** current transaction has already run one or more incremental-vacuum
** steps, then the page we are about to allocate may contain content
** that is required in the event of a rollback. In this case, do
** not set the no-content flag. This causes the pager to load and journal
** the current page content before overwriting it.
**
** Note that the pager will not actually attempt to load or journal
** content for any page that really does lie past the end of the database
** file on disk. So the effects of disabling the no-content optimization
** here are confined to those pages that lie between the end of the
** database image and the end of the database file.
*/
bNoContent = v5
rc = _sqlite3PagerWrite(tls, (*TMemPage)(unsafe.Pointer((*TBtShared)(unsafe.Pointer(pBt)).FpPage1)).FpDbPage)
if rc != 0 {
return rc
}
(*TBtShared)(unsafe.Pointer(pBt)).FnPage = (*TBtShared)(unsafe.Pointer(pBt)).FnPage + 1
if (*TBtShared)(unsafe.Pointer(pBt)).FnPage == libc.Uint32FromInt32(_sqlite3PendingByte)/(*TBtShared)(unsafe.Pointer(pBt)).FpageSize+libc.Uint32FromInt32(1) {
(*TBtShared)(unsafe.Pointer(pBt)).FnPage = (*TBtShared)(unsafe.Pointer(pBt)).FnPage + 1
}
if (*TBtShared)(unsafe.Pointer(pBt)).FautoVacuum != 0 && _ptrmapPageno(tls, pBt, (*TBtShared)(unsafe.Pointer(pBt)).FnPage) == (*TBtShared)(unsafe.Pointer(pBt)).FnPage {
/* If *pPgno refers to a pointer-map page, allocate two new pages
** at the end of the file instead of one. The first allocated page
** becomes a new pointer-map page, the second is used by the caller.
*/
**(**uintptr)(__ccgo_up(bp + 24)) = uintptr(0)
rc = _btreeGetUnusedPage(tls, pBt, (*TBtShared)(unsafe.Pointer(pBt)).FnPage, bp+24, bNoContent)
if rc == SQLITE_OK {
rc = _sqlite3PagerWrite(tls, (*TMemPage)(unsafe.Pointer(**(**uintptr)(__ccgo_up(bp + 24)))).FpDbPage)
_releasePage(tls, **(**uintptr)(__ccgo_up(bp + 24)))
}
if rc != 0 {
return rc
}
(*TBtShared)(unsafe.Pointer(pBt)).FnPage = (*TBtShared)(unsafe.Pointer(pBt)).FnPage + 1
if (*TBtShared)(unsafe.Pointer(pBt)).FnPage == libc.Uint32FromInt32(_sqlite3PendingByte)/(*TBtShared)(unsafe.Pointer(pBt)).FpageSize+libc.Uint32FromInt32(1) {
(*TBtShared)(unsafe.Pointer(pBt)).FnPage = (*TBtShared)(unsafe.Pointer(pBt)).FnPage + 1
}
}
_sqlite3Put4byte(tls, uintptr(28)+(*TMemPage)(unsafe.Pointer((*TBtShared)(unsafe.Pointer(pBt)).FpPage1)).FaData, (*TBtShared)(unsafe.Pointer(pBt)).FnPage)
**(**TPgno)(__ccgo_up(pPgno)) = (*TBtShared)(unsafe.Pointer(pBt)).FnPage
rc = _btreeGetUnusedPage(tls, pBt, **(**TPgno)(__ccgo_up(pPgno)), ppPage, bNoContent)
if rc != 0 {
return rc
}
rc = _sqlite3PagerWrite(tls, (*TMemPage)(unsafe.Pointer(**(**uintptr)(__ccgo_up(ppPage)))).FpDbPage)
if rc != SQLITE_OK {
_releasePage(tls, **(**uintptr)(__ccgo_up(ppPage)))
**(**uintptr)(__ccgo_up(ppPage)) = uintptr(0)
}
}
goto end_allocate_page
end_allocate_page:
;
_releasePage(tls, **(**uintptr)(__ccgo_up(bp)))
_releasePage(tls, pPrevTrunk)
return rc
}
// C documentation
//
// /*
// ** Allocate VdbeCursor number iCur. Return a pointer to it. Return NULL
// ** if we run out of memory.
// */
func _allocateCursor(tls *libc.TLS, p uintptr, iCur int32, nField int32, eCurType Tu8) (r uintptr) {
var nByte Ti64
var pCx, pMem, v1 uintptr
_, _, _, _ = nByte, pCx, pMem, v1
if iCur > 0 {
v1 = (*TVdbe)(unsafe.Pointer(p)).FaMem + uintptr((*TVdbe)(unsafe.Pointer(p)).FnMem-iCur)*56
} else {
v1 = (*TVdbe)(unsafe.Pointer(p)).FaMem
}
/* Find the memory cell that will be used to store the blob of memory
** required for this VdbeCursor structure. It is convenient to use a
** vdbe memory cell to manage the memory allocation required for a
** VdbeCursor structure for the following reasons:
**
** * Sometimes cursor numbers are used for a couple of different
** purposes in a vdbe program. The different uses might require
** different sized allocations. Memory cells provide growable
** allocations.
**
** * When using ENABLE_MEMORY_MANAGEMENT, memory cell buffers can
** be freed lazily via the sqlite3_release_memory() API. This
** minimizes the number of malloc calls made by the system.
**
** The memory cell for cursor 0 is aMem[0]. The rest are allocated from
** the top of the register space. Cursor 1 is at Mem[p->nMem-1].
** Cursor 2 is at Mem[p->nMem-2]. And so forth.
*/
pMem = v1
pCx = uintptr(0)
nByte = libc.Int64FromUint64((uint64(libc.UintptrFromInt32(0)+120)+libc.Uint64FromInt32(7))&libc.Uint64FromInt32(^libc.Int32FromInt32(7)) + libc.Uint64FromInt32(nField+libc.Int32FromInt32(1))*libc.Uint64FromInt64(8))
if libc.Int32FromUint8(eCurType) == CURTYPE_BTREE {
nByte = nByte + int64(_sqlite3BtreeCursorSize(tls))
}
if **(**uintptr)(__ccgo_up((*TVdbe)(unsafe.Pointer(p)).FapCsr + uintptr(iCur)*8)) != 0 { /*OPTIMIZATION-IF-FALSE*/
_sqlite3VdbeFreeCursorNN(tls, p, **(**uintptr)(__ccgo_up((*TVdbe)(unsafe.Pointer(p)).FapCsr + uintptr(iCur)*8)))
**(**uintptr)(__ccgo_up((*TVdbe)(unsafe.Pointer(p)).FapCsr + uintptr(iCur)*8)) = uintptr(0)
}
/* There used to be a call to sqlite3VdbeMemClearAndResize() to make sure
** the pMem used to hold space for the cursor has enough storage available
** in pMem->zMalloc. But for the special case of the aMem[] entries used
** to hold cursors, it is faster to in-line the logic. */
if int64((*TMem)(unsafe.Pointer(pMem)).FszMalloc) < nByte {
if (*TMem)(unsafe.Pointer(pMem)).FszMalloc > 0 {
_sqlite3DbFreeNN(tls, (*TMem)(unsafe.Pointer(pMem)).Fdb, (*TMem)(unsafe.Pointer(pMem)).FzMalloc)
}
v1 = _sqlite3DbMallocRaw(tls, (*TMem)(unsafe.Pointer(pMem)).Fdb, libc.Uint64FromInt64(nByte))
(*TMem)(unsafe.Pointer(pMem)).FzMalloc = v1
(*TMem)(unsafe.Pointer(pMem)).Fz = v1
if (*TMem)(unsafe.Pointer(pMem)).FzMalloc == uintptr(0) {
(*TMem)(unsafe.Pointer(pMem)).FszMalloc = 0
return uintptr(0)
}
(*TMem)(unsafe.Pointer(pMem)).FszMalloc = int32(nByte)
}
v1 = (*TMem)(unsafe.Pointer(pMem)).FzMalloc
pCx = v1
**(**uintptr)(__ccgo_up((*TVdbe)(unsafe.Pointer(p)).FapCsr + uintptr(iCur)*8)) = v1
libc.X__builtin___memset_chk(tls, pCx, 0, uint64(libc.UintptrFromInt32(0)+40), ^t__predefined_size_t(0))
(*TVdbeCursor)(unsafe.Pointer(pCx)).FeCurType = eCurType
(*TVdbeCursor)(unsafe.Pointer(pCx)).FnField = int16(nField)
(*TVdbeCursor)(unsafe.Pointer(pCx)).FaOffset = pCx + 120 + uintptr(nField)*4
if libc.Int32FromUint8(eCurType) == CURTYPE_BTREE {
*(*uintptr)(unsafe.Pointer(pCx + 48)) = (*TMem)(unsafe.Pointer(pMem)).Fz + uintptr((uint64(libc.UintptrFromInt32(0)+120)+libc.Uint64FromInt32(7))&libc.Uint64FromInt32(^libc.Int32FromInt32(7))+libc.Uint64FromInt32(nField+libc.Int32FromInt32(1))*libc.Uint64FromInt64(8))
_sqlite3BtreeCursorZero(tls, *(*uintptr)(unsafe.Pointer(pCx + 48)))
}
return pCx
}
// C documentation
//
// /*
// ** Make sure pBt->pTmpSpace points to an allocation of
// ** MX_CELL_SIZE(pBt) bytes with a 4-byte prefix for a left-child
// ** pointer.
// */
func _allocateTempSpace(tls *libc.TLS, pBt uintptr) (r int32) {
var pCur uintptr
_ = pCur
/* This routine is called only by btreeCursor() when allocating the
** first write cursor for the BtShared object */
(*TBtShared)(unsafe.Pointer(pBt)).FpTmpSpace = _sqlite3PageMalloc(tls, libc.Int32FromUint32((*TBtShared)(unsafe.Pointer(pBt)).FpageSize))
if (*TBtShared)(unsafe.Pointer(pBt)).FpTmpSpace == uintptr(0) {
pCur = (*TBtShared)(unsafe.Pointer(pBt)).FpCursor
(*TBtShared)(unsafe.Pointer(pBt)).FpCursor = (*TBtCursor)(unsafe.Pointer(pCur)).FpNext /* Unlink the cursor */
libc.X__builtin___memset_chk(tls, pCur, 0, uint64(296), ^t__predefined_size_t(0))
return int32(SQLITE_NOMEM)
}
/* One of the uses of pBt->pTmpSpace is to format cells before
** inserting them into a leaf page (function fillInCell()). If
** a cell is less than 4 bytes in size, it is rounded up to 4 bytes
** by the various routines that manipulate binary cells. Which
** can mean that fillInCell() only initializes the first 2 or 3
** bytes of pTmpSpace, but that the first 4 bytes are copied from
** it into a database page. This is not actually a problem, but it
** does cause a valgrind error when the 1 or 2 bytes of uninitialized
** data is passed to system call write(). So to avoid this error,
** zero the first 4 bytes of temp space here.
**
** Also: Provide four bytes of initialized space before the
** beginning of pTmpSpace as an area available to prepend the
** left-child pointer to the beginning of a cell.
*/
libc.X__builtin___memset_chk(tls, (*TBtShared)(unsafe.Pointer(pBt)).FpTmpSpace, 0, uint64(8), ^t__predefined_size_t(0))
**(**uintptr)(__ccgo_up(pBt + 136)) += uintptr(4)
return SQLITE_OK
}
// C documentation
//
// /*
// ** Find a column named pCol in table pTab. If successful, set output
// ** parameter *piCol to the index of the column in the table and return
// ** SQLITE_OK. Otherwise, set *piCol to -1 and return an SQLite error
// ** code.
// */
func _alterFindCol(tls *libc.TLS, pParse uintptr, pTab uintptr, pCol uintptr, piCol uintptr) (r int32) {
bp := tls.Alloc(16)
defer tls.Free(16)
var db, zCol, zDb, zName uintptr
var iCol, rc int32
_, _, _, _, _, _ = db, iCol, rc, zCol, zDb, zName
db = (*TParse)(unsafe.Pointer(pParse)).Fdb
zName = _sqlite3NameFromToken(tls, db, pCol)
rc = int32(SQLITE_NOMEM)
iCol = -int32(1)
if zName != 0 {
iCol = _sqlite3ColumnIndex(tls, pTab, zName)
if iCol < 0 {
_sqlite3ErrorMsg(tls, pParse, __ccgo_ts+12254, libc.VaList(bp+8, zName))
rc = int32(SQLITE_ERROR)
} else {
rc = SQLITE_OK
}
}
if rc == SQLITE_OK {
zDb = (**(**TDb)(__ccgo_up((*Tsqlite3)(unsafe.Pointer(db)).FaDb + uintptr(_sqlite3SchemaToIndex(tls, db, (*TTable)(unsafe.Pointer(pTab)).FpSchema))*32))).FzDbSName
zCol = (**(**TColumn)(__ccgo_up((*TTable)(unsafe.Pointer(pTab)).FaCol + uintptr(iCol)*16))).FzCnName
if _sqlite3AuthCheck(tls, pParse, int32(SQLITE_ALTER_TABLE), zDb, (*TTable)(unsafe.Pointer(pTab)).FzName, zCol) != 0 {
pTab = uintptr(0)
}
}
_sqlite3DbFree(tls, db, zName)
**(**int32)(__ccgo_up(piCol)) = iCol
return rc
}
// C documentation
//
// /*
// ** Buffer pCons, which is nCons bytes in size, contains the text of a
// ** NOT NULL or CHECK constraint that will be inserted into a CREATE TABLE
// ** statement. If successful, this function returns the size of the buffer in
// ** bytes not including any trailing whitespace or "--" style comments. Or,
// ** if an OOM occurs, it returns 0 and sets db->mallocFailed to true.
// **
// ** C-style comments at the end are preserved. "--" style comments are
// ** removed because the comment terminator might be \000, and we are about
// ** to insert the pCons[] text into the middle of a larger string, and that
// ** will have the effect of removing the comment terminator and messing up
// ** the syntax.
// */
func _alterRtrimConstraint(tls *libc.TLS, db uintptr, pCons uintptr, nCons int32) (r int32) {
bp := tls.Alloc(32)
defer tls.Free(32)
var iEnd, iOff, nToken int32
var zTmp uintptr
var _ /* t at bp+0 */ int32
_, _, _, _ = iEnd, iOff, nToken, zTmp
zTmp = _sqlite3MPrintf(tls, db, __ccgo_ts+12394, libc.VaList(bp+16, nCons, pCons))
iOff = 0
iEnd = 0
if zTmp == uintptr(0) {
return 0
}
for int32(1) != 0 {
**(**int32)(__ccgo_up(bp)) = 0
nToken = int32(_sqlite3GetToken(tls, zTmp+uintptr(iOff), bp))
if **(**int32)(__ccgo_up(bp)) == int32(TK_ILLEGAL) {
break
}
if **(**int32)(__ccgo_up(bp)) != int32(TK_SPACE) && (**(**int32)(__ccgo_up(bp)) != int32(TK_COMMENT) || libc.Int32FromUint8(**(**Tu8)(__ccgo_up(zTmp + uintptr(iOff)))) != int32('-')) {
iEnd = iOff + nToken
}
iOff = iOff + nToken
}
_sqlite3DbFree(tls, db, zTmp)
return iEnd
}
// C documentation
//
// /*
// ** This is the xExprCallback for a tree walker. It is used to
// ** implement sqlite3ExprAnalyzeAggregates(). See sqlite3ExprAnalyzeAggregates
// ** for additional information.
// */
func _analyzeAggregate(tls *libc.TLS, pWalker uintptr, pExpr uintptr) (r int32) {
bp := tls.Alloc(96)
defer tls.Free(96)
var enc Tu8
var i, iDataCur, mxTerm, nArg, v5 int32
var pAggInfo, pIEpr, pItem, pItem1, pNC, pOBList, pParse, pSrcList, v7 uintptr
var _ /* tmp at bp+0 */ TExpr
_, _, _, _, _, _, _, _, _, _, _, _, _, _, _ = enc, i, iDataCur, mxTerm, nArg, pAggInfo, pIEpr, pItem, pItem1, pNC, pOBList, pParse, pSrcList, v5, v7
pNC = *(*uintptr)(unsafe.Pointer(pWalker + 40))
pParse = (*TNameContext)(unsafe.Pointer(pNC)).FpParse
pSrcList = (*TNameContext)(unsafe.Pointer(pNC)).FpSrcList
pAggInfo = *(*uintptr)(unsafe.Pointer(pNC + 16))
switch libc.Int32FromUint8((*TExpr)(unsafe.Pointer(pExpr)).Fop) {
default:
if (*TNameContext)(unsafe.Pointer(pNC)).FncFlags&int32(NC_InAggFunc) == 0 {
break
}
if (*TParse)(unsafe.Pointer(pParse)).FpIdxEpr == uintptr(0) {
break
}
pIEpr = (*TParse)(unsafe.Pointer(pParse)).FpIdxEpr
for {
if !(pIEpr != 0) {
break
}
iDataCur = (*TIndexedExpr)(unsafe.Pointer(pIEpr)).FiDataCur
if iDataCur < 0 {
goto _1
}
if _sqlite3ExprCompare(tls, uintptr(0), pExpr, (*TIndexedExpr)(unsafe.Pointer(pIEpr)).FpExpr, iDataCur) == 0 {
break
}
goto _1
_1:
;
pIEpr = (*TIndexedExpr)(unsafe.Pointer(pIEpr)).FpIENext
}
if pIEpr == uintptr(0) {
break
}
if !((*TExpr)(unsafe.Pointer(pExpr)).Fflags&libc.Uint32FromInt32(libc.Int32FromInt32(EP_WinFunc)|libc.Int32FromInt32(EP_Subrtn)) == libc.Uint32FromInt32(0)) {
break
}
i = 0
for {
if !(i < (*TSrcList)(unsafe.Pointer(pSrcList)).FnSrc) {
break
}
if (*(*TSrcItem)(unsafe.Pointer(pSrcList + 8 + uintptr(i)*80))).FiCursor == (*TIndexedExpr)(unsafe.Pointer(pIEpr)).FiDataCur {
break
}
goto _2
_2:
;
i = i + 1
}
if i >= (*TSrcList)(unsafe.Pointer(pSrcList)).FnSrc {
break
}
if (*TExpr)(unsafe.Pointer(pExpr)).FpAggInfo != uintptr(0) {
break
} /* Resolved by outer context */
if (*TParse)(unsafe.Pointer(pParse)).FnErr != 0 {
return int32(WRC_Abort)
}
/* If we reach this point, it means that expression pExpr can be
** translated into a reference to an index column as described by
** pIEpr.
*/
libc.X__builtin___memset_chk(tls, bp, 0, uint64(72), ^t__predefined_size_t(0))
(**(**TExpr)(__ccgo_up(bp))).Fop = uint8(TK_AGG_COLUMN)
(**(**TExpr)(__ccgo_up(bp))).FiTable = (*TIndexedExpr)(unsafe.Pointer(pIEpr)).FiIdxCur
(**(**TExpr)(__ccgo_up(bp))).FiColumn = int16((*TIndexedExpr)(unsafe.Pointer(pIEpr)).FiIdxCol)
_findOrCreateAggInfoColumn(tls, pParse, pAggInfo, bp)
if (*TParse)(unsafe.Pointer(pParse)).FnErr != 0 {
return int32(WRC_Abort)
}
(**(**TAggInfo_col)(__ccgo_up((*TAggInfo)(unsafe.Pointer(pAggInfo)).FaCol + uintptr((**(**TExpr)(__ccgo_up(bp))).FiAgg)*32))).FpCExpr = pExpr
(*TExpr)(unsafe.Pointer(pExpr)).FpAggInfo = pAggInfo
(*TExpr)(unsafe.Pointer(pExpr)).FiAgg = (**(**TExpr)(__ccgo_up(bp))).FiAgg
return int32(WRC_Prune)
case int32(TK_IF_NULL_ROW):
fallthrough
case int32(TK_AGG_COLUMN):
fallthrough
case int32(TK_COLUMN):
/* Check to see if the column is in one of the tables in the FROM
** clause of the aggregate query */
if pSrcList != uintptr(0) {
pItem = pSrcList + 8
i = 0
for {
if !(i < (*TSrcList)(unsafe.Pointer(pSrcList)).FnSrc) {
break
}
if (*TExpr)(unsafe.Pointer(pExpr)).FiTable == (*TSrcItem)(unsafe.Pointer(pItem)).FiCursor {
_findOrCreateAggInfoColumn(tls, pParse, pAggInfo, pExpr)
break
} /* endif pExpr->iTable==pItem->iCursor */
goto _3
_3:
;
i = i + 1
pItem += 80
} /* end loop over pSrcList */
}
return WRC_Continue
case int32(TK_AGG_FUNCTION):
if (*TNameContext)(unsafe.Pointer(pNC)).FncFlags&int32(NC_InAggFunc) == 0 && (*TWalker)(unsafe.Pointer(pWalker)).FwalkerDepth == libc.Int32FromUint8((*TExpr)(unsafe.Pointer(pExpr)).Fop2) && (*TExpr)(unsafe.Pointer(pExpr)).FpAggInfo == uintptr(0) {
/* Check to see if pExpr is a duplicate of another aggregate
** function that is already in the pAggInfo structure
*/
pItem1 = (*TAggInfo)(unsafe.Pointer(pAggInfo)).FaFunc
mxTerm = **(**int32)(__ccgo_up((*TParse)(unsafe.Pointer(pParse)).Fdb + 136 + 2*4))
i = 0
for {
if !(i < (*TAggInfo)(unsafe.Pointer(pAggInfo)).FnFunc) {
break
}
if (*TAggInfo_func)(unsafe.Pointer(pItem1)).FpFExpr == pExpr {
break
}
if _sqlite3ExprCompare(tls, uintptr(0), (*TAggInfo_func)(unsafe.Pointer(pItem1)).FpFExpr, pExpr, -int32(1)) == 0 {
break
}
goto _4
_4:
;
i = i + 1
pItem1 += 32
}
if i > mxTerm {
_sqlite3ErrorMsg(tls, pParse, __ccgo_ts+8962, libc.VaList(bp+80, mxTerm))
i = mxTerm
} else {
if i >= (*TAggInfo)(unsafe.Pointer(pAggInfo)).FnFunc {
/* pExpr is original. Make a new entry in pAggInfo->aFunc[]
*/
enc = (*Tsqlite3)(unsafe.Pointer((*TParse)(unsafe.Pointer(pParse)).Fdb)).Fenc
i = _addAggInfoFunc(tls, (*TParse)(unsafe.Pointer(pParse)).Fdb, pAggInfo)
if i >= 0 {
pItem1 = (*TAggInfo)(unsafe.Pointer(pAggInfo)).FaFunc + uintptr(i)*32
(*TAggInfo_func)(unsafe.Pointer(pItem1)).FpFExpr = pExpr
if *(*uintptr)(unsafe.Pointer(pExpr + 32)) != 0 {
v5 = (*TExprList)(unsafe.Pointer(*(*uintptr)(unsafe.Pointer(pExpr + 32)))).FnExpr
} else {
v5 = 0
}
nArg = v5
(*TAggInfo_func)(unsafe.Pointer(pItem1)).FpFunc = _sqlite3FindFunction(tls, (*TParse)(unsafe.Pointer(pParse)).Fdb, *(*uintptr)(unsafe.Pointer(pExpr + 8)), nArg, enc, uint8(0))
if (*TExpr)(unsafe.Pointer(pExpr)).FpLeft != 0 && (*TFuncDef)(unsafe.Pointer((*TAggInfo_func)(unsafe.Pointer(pItem1)).FpFunc)).FfuncFlags&uint32(SQLITE_FUNC_NEEDCOLL) == uint32(0) {
v7 = pParse + 56
v5 = *(*int32)(unsafe.Pointer(v7))
*(*int32)(unsafe.Pointer(v7)) = *(*int32)(unsafe.Pointer(v7)) + 1
(*TAggInfo_func)(unsafe.Pointer(pItem1)).FiOBTab = v5
pOBList = *(*uintptr)(unsafe.Pointer((*TExpr)(unsafe.Pointer(pExpr)).FpLeft + 32))
if (*TExprList)(unsafe.Pointer(pOBList)).FnExpr == int32(1) && nArg == int32(1) && _sqlite3ExprCompare(tls, uintptr(0), (*(*TExprList_item)(unsafe.Pointer(pOBList + 8))).FpExpr, (*(*TExprList_item)(unsafe.Pointer(*(*uintptr)(unsafe.Pointer(pExpr + 32)) + 8))).FpExpr, 0) == 0 {
(*TAggInfo_func)(unsafe.Pointer(pItem1)).FbOBPayload = uint8(0)
(*TAggInfo_func)(unsafe.Pointer(pItem1)).FbOBUnique = libc.BoolUint8((*TExpr)(unsafe.Pointer(pExpr)).Fflags&libc.Uint32FromInt32(libc.Int32FromInt32(EP_Distinct)) != libc.Uint32FromInt32(0))
} else {
(*TAggInfo_func)(unsafe.Pointer(pItem1)).FbOBPayload = uint8(1)
}
(*TAggInfo_func)(unsafe.Pointer(pItem1)).FbUseSubtype = libc.BoolUint8((*TFuncDef)(unsafe.Pointer((*TAggInfo_func)(unsafe.Pointer(pItem1)).FpFunc)).FfuncFlags&uint32(SQLITE_SUBTYPE) != uint32(0))
} else {
(*TAggInfo_func)(unsafe.Pointer(pItem1)).FiOBTab = -int32(1)
}
if (*TExpr)(unsafe.Pointer(pExpr)).Fflags&libc.Uint32FromInt32(libc.Int32FromInt32(EP_Distinct)) != uint32(0) && !((*TAggInfo_func)(unsafe.Pointer(pItem1)).FbOBUnique != 0) {
v7 = pParse + 56
v5 = *(*int32)(unsafe.Pointer(v7))
*(*int32)(unsafe.Pointer(v7)) = *(*int32)(unsafe.Pointer(v7)) + 1
(*TAggInfo_func)(unsafe.Pointer(pItem1)).FiDistinct = v5
} else {
(*TAggInfo_func)(unsafe.Pointer(pItem1)).FiDistinct = -int32(1)
}
}
}
}
/* Make pExpr point to the appropriate pAggInfo->aFunc[] entry
*/
(*TExpr)(unsafe.Pointer(pExpr)).FiAgg = int16(i)
(*TExpr)(unsafe.Pointer(pExpr)).FpAggInfo = pAggInfo
return int32(WRC_Prune)
} else {
return WRC_Continue
}
}
return WRC_Continue
}
// C documentation
//
// /*
// ** Generate code to do an analysis of all indices associated with
// ** a single table.
// */
func _analyzeOneTable(tls *libc.TLS, pParse uintptr, pTab uintptr, pOnlyIdx uintptr, iStatCur int32, iMem int32, iTab int32) {
var aGotoChng, db, pColl, pIdx, pPk, pStat1, pX, v, zIdxName uintptr
var addrGotoEnd, addrIsNull, addrNext, addrNextRow, doOnce, endDistinctTest, i, iDb, iIdxCur, iTabCur, j, j1, j2, j3, jZeroRows, k, mxCol, nCol, nColTest, nColX, regChng, regCol, regDLt, regEq, regIdxname, regKey, regLt, regNewRowid, regPrev, regRowid, regSample, regSampleRowid, regStat, regStat1, regTabname, regTemp, regTemp2, v1, v2, v3, v4, v5, v6, v7, v8, v9 int32
var needTableCnt, seekOp Tu8
_, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _ = aGotoChng, addrGotoEnd, addrIsNull, addrNext, addrNextRow, db, doOnce, endDistinctTest, i, iDb, iIdxCur, iTabCur, j, j1, j2, j3, jZeroRows, k, mxCol, nCol, nColTest, nColX, needTableCnt, pColl, pIdx, pPk, pStat1, pX, regChng, regCol, regDLt, regEq, regIdxname, regKey, regLt, regNewRowid, regPrev, regRowid, regSample, regSampleRowid, regStat, regStat1, regTabname, regTemp, regTemp2, seekOp, v, zIdxName, v1, v2, v3, v4, v5, v6, v7, v8, v9
db = (*TParse)(unsafe.Pointer(pParse)).Fdb /* Loop counter */
jZeroRows = -int32(1) /* Index of database containing pTab */
needTableCnt = uint8(1)
v1 = iMem
iMem = iMem + 1 /* True to count the table */
regNewRowid = v1
v2 = iMem
iMem = iMem + 1 /* Rowid for the inserted record */
regStat = v2
v3 = iMem
iMem = iMem + 1 /* Register to hold StatAccum object */
regChng = v3
v4 = iMem
iMem = iMem + 1 /* Index of changed index field */
regRowid = v4
v5 = iMem
iMem = iMem + 1 /* Rowid argument passed to stat_push() */
regTemp = v5
v6 = iMem
iMem = iMem + 1 /* Temporary use register */
regTemp2 = v6
v7 = iMem
iMem = iMem + 1 /* Second temporary use register */
regTabname = v7
v8 = iMem
iMem = iMem + 1 /* Register containing table name */
regIdxname = v8
v9 = iMem
iMem = iMem + 1 /* Register containing index name */
regStat1 = v9 /* Value for the stat column of sqlite_stat1 */
regPrev = iMem /* MUST BE LAST (see below) */
doOnce = int32(1) /* Flag for a one-time computation */
pStat1 = uintptr(0)
_sqlite3TouchRegister(tls, pParse, iMem)
v = _sqlite3GetVdbe(tls, pParse)
if v == uintptr(0) || pTab == uintptr(0) {
return
}
if !(libc.Int32FromUint8((*TTable)(unsafe.Pointer(pTab)).FeTabType) == libc.Int32FromInt32(TABTYP_NORM)) {
/* Do not gather statistics on views or virtual tables */
return
}
if Xsqlite3_strlike(tls, __ccgo_ts+13378, (*TTable)(unsafe.Pointer(pTab)).FzName, uint32('\\')) == 0 {
/* Do not gather statistics on system tables */
return
}
iDb = _sqlite3SchemaToIndex(tls, db, (*TTable)(unsafe.Pointer(pTab)).FpSchema)
if _sqlite3AuthCheck(tls, pParse, int32(SQLITE_ANALYZE), (*TTable)(unsafe.Pointer(pTab)).FzName, uintptr(0), (**(**TDb)(__ccgo_up((*Tsqlite3)(unsafe.Pointer(db)).FaDb + uintptr(iDb)*32))).FzDbSName) != 0 {
return
}
if (*Tsqlite3)(unsafe.Pointer(db)).FxPreUpdateCallback != 0 {
pStat1 = _sqlite3DbMallocZero(tls, db, uint64(libc.Uint64FromInt64(120)+libc.Uint64FromInt32(13)))
if pStat1 == uintptr(0) {
return
}
(*TTable)(unsafe.Pointer(pStat1)).FzName = pStat1 + 1*120
libc.X__builtin___memcpy_chk(tls, (*TTable)(unsafe.Pointer(pStat1)).FzName, __ccgo_ts+13181, uint64(13), ^t__predefined_size_t(0))
(*TTable)(unsafe.Pointer(pStat1)).FnCol = int16(3)
(*TTable)(unsafe.Pointer(pStat1)).FiPKey = int16(-int32(1))
_sqlite3VdbeAddOp4(tls, (*TParse)(unsafe.Pointer(pParse)).FpVdbe, int32(OP_Noop), 0, 0, 0, pStat1, -int32(7))
}
/* Establish a read-lock on the table at the shared-cache level.
** Open a read-only cursor on the table. Also allocate a cursor number
** to use for scanning indexes (iIdxCur). No index cursor is opened at
** this time though. */
_sqlite3TableLock(tls, pParse, iDb, (*TTable)(unsafe.Pointer(pTab)).Ftnum, uint8(0), (*TTable)(unsafe.Pointer(pTab)).FzName)
v1 = iTab
iTab = iTab + 1
iTabCur = v1
v1 = iTab
iTab = iTab + 1
iIdxCur = v1
if (*TParse)(unsafe.Pointer(pParse)).FnTab > iTab {
v1 = (*TParse)(unsafe.Pointer(pParse)).FnTab
} else {
v1 = iTab
}
(*TParse)(unsafe.Pointer(pParse)).FnTab = v1
_sqlite3OpenTable(tls, pParse, iTabCur, iDb, pTab, int32(OP_OpenRead))
_sqlite3VdbeLoadString(tls, v, regTabname, (*TTable)(unsafe.Pointer(pTab)).FzName)
pIdx = (*TTable)(unsafe.Pointer(pTab)).FpIndex
for {
if !(pIdx != 0) {
break
} /* Number of columns to test for changes */
if pOnlyIdx != 0 && pOnlyIdx != pIdx {
goto _13
}
if (*TIndex)(unsafe.Pointer(pIdx)).FpPartIdxWhere == uintptr(0) {
needTableCnt = uint8(0)
}
if !((*TTable)(unsafe.Pointer(pTab)).FtabFlags&libc.Uint32FromInt32(TF_WithoutRowid) == libc.Uint32FromInt32(0)) && int32(uint32(*(*uint16)(unsafe.Pointer(pIdx + 100))&0x3>>0)) == int32(SQLITE_IDXTYPE_PRIMARYKEY) {
nCol = libc.Int32FromUint16((*TIndex)(unsafe.Pointer(pIdx)).FnKeyCol)
zIdxName = (*TTable)(unsafe.Pointer(pTab)).FzName
nColTest = nCol - int32(1)
} else {
nCol = libc.Int32FromUint16((*TIndex)(unsafe.Pointer(pIdx)).FnColumn)
zIdxName = (*TIndex)(unsafe.Pointer(pIdx)).FzName
if int32(uint32(*(*uint16)(unsafe.Pointer(pIdx + 100))&0x8>>3)) != 0 {
v1 = libc.Int32FromUint16((*TIndex)(unsafe.Pointer(pIdx)).FnKeyCol) - int32(1)
} else {
v1 = nCol - int32(1)
}
nColTest = v1
}
/* Populate the register containing the index name. */
_sqlite3VdbeLoadString(tls, v, regIdxname, zIdxName)
/*
** Pseudo-code for loop that calls stat_push():
**
** regChng = 0
** Rewind csr
** if eof(csr){
** stat_init() with count = 0;
** goto end_of_scan;
** }
** count()
** stat_init()
** goto chng_addr_0;
**
** next_row:
** regChng = 0
** if( idx(0) != regPrev(0) ) goto chng_addr_0
** regChng = 1
** if( idx(1) != regPrev(1) ) goto chng_addr_1
** ...
** regChng = N
** goto chng_addr_N
**
** chng_addr_0:
** regPrev(0) = idx(0)
** chng_addr_1:
** regPrev(1) = idx(1)
** ...
**
** endDistinctTest:
** regRowid = idx(rowid)
** stat_push(P, regChng, regRowid)
** Next csr
** if !eof(csr) goto next_row;
**
** end_of_scan:
*/
/* Make sure there are enough memory cells allocated to accommodate
** the regPrev array and a trailing rowid (the rowid slot is required
** when building a record to insert into the sample column of
** the sqlite_stat4 table. */
_sqlite3TouchRegister(tls, pParse, regPrev+nColTest)
/* Open a read-only cursor on the index being analyzed. */
_sqlite3VdbeAddOp3(tls, v, int32(OP_OpenRead), iIdxCur, libc.Int32FromUint32((*TIndex)(unsafe.Pointer(pIdx)).Ftnum), iDb)
_sqlite3VdbeSetP4KeyInfo(tls, pParse, pIdx)
/* Implementation of the following:
**
** regChng = 0
** Rewind csr
** if eof(csr){
** stat_init() with count = 0;
** goto end_of_scan;
** }
** count()
** stat_init()
** goto chng_addr_0;
*/
_sqlite3VdbeAddOp2(tls, v, int32(OP_Integer), (*Tsqlite3)(unsafe.Pointer(db)).FnAnalysisLimit, regTemp2)
/* Arguments to stat_init():
** (1) the number of columns in the index including the rowid
** (or for a WITHOUT ROWID table, the number of PK columns),
** (2) the number of columns in the key without the rowid/pk
** (3) estimated number of rows in the index. */
_sqlite3VdbeAddOp2(tls, v, int32(OP_Integer), nCol, regStat+int32(1))
_sqlite3VdbeAddOp2(tls, v, int32(OP_Integer), libc.Int32FromUint16((*TIndex)(unsafe.Pointer(pIdx)).FnKeyCol), regRowid)
_sqlite3VdbeAddOp3(tls, v, int32(OP_Count), iIdxCur, regTemp, libc.BoolInt32((*Tsqlite3)(unsafe.Pointer(db)).FdbOptFlags&libc.Uint32FromInt32(libc.Int32FromInt32(SQLITE_Stat4)) != uint32(0)))
_sqlite3VdbeAddFunctionCall(tls, pParse, 0, regStat+int32(1), regStat, int32(4), uintptr(unsafe.Pointer(&_statInitFuncdef)), 0)
addrGotoEnd = _sqlite3VdbeAddOp1(tls, v, int32(OP_Rewind), iIdxCur)
_sqlite3VdbeAddOp2(tls, v, int32(OP_Integer), 0, regChng)
addrNextRow = _sqlite3VdbeCurrentAddr(tls, v)
if nColTest > 0 {
endDistinctTest = _sqlite3VdbeMakeLabel(tls, pParse) /* Array of jump instruction addresses */
aGotoChng = _sqlite3DbMallocRawNN(tls, db, uint64(uint64(4)*libc.Uint64FromInt32(nColTest)))
if aGotoChng == uintptr(0) {
goto _13
}
/*
** next_row:
** regChng = 0
** if( idx(0) != regPrev(0) ) goto chng_addr_0
** regChng = 1
** if( idx(1) != regPrev(1) ) goto chng_addr_1
** ...
** regChng = N
** goto endDistinctTest
*/
_sqlite3VdbeAddOp0(tls, v, int32(OP_Goto))
addrNextRow = _sqlite3VdbeCurrentAddr(tls, v)
if nColTest == int32(1) && libc.Int32FromUint16((*TIndex)(unsafe.Pointer(pIdx)).FnKeyCol) == int32(1) && libc.Int32FromUint8((*TIndex)(unsafe.Pointer(pIdx)).FonError) != OE_None {
/* For a single-column UNIQUE index, once we have found a non-NULL
** row, we know that all the rest will be distinct, so skip
** subsequent distinctness tests. */
_sqlite3VdbeAddOp2(tls, v, int32(OP_NotNull), regPrev, endDistinctTest)
}
i = 0
for {
if !(i < nColTest) {
break
}
pColl = _sqlite3LocateCollSeq(tls, pParse, **(**uintptr)(__ccgo_up((*TIndex)(unsafe.Pointer(pIdx)).FazColl + uintptr(i)*8)))
_sqlite3VdbeAddOp2(tls, v, int32(OP_Integer), i, regChng)
_sqlite3VdbeAddOp3(tls, v, int32(OP_Column), iIdxCur, i, regTemp)
**(**int32)(__ccgo_up(aGotoChng + uintptr(i)*4)) = _sqlite3VdbeAddOp4(tls, v, int32(OP_Ne), regTemp, 0, regPrev+i, pColl, -int32(2))
_sqlite3VdbeChangeP5(tls, v, uint16(SQLITE_NULLEQ))
goto _15
_15:
;
i = i + 1
}
_sqlite3VdbeAddOp2(tls, v, int32(OP_Integer), nColTest, regChng)
_sqlite3VdbeGoto(tls, v, endDistinctTest)
/*
** chng_addr_0:
** regPrev(0) = idx(0)
** chng_addr_1:
** regPrev(1) = idx(1)
** ...
*/
_sqlite3VdbeJumpHere(tls, v, addrNextRow-int32(1))
i = 0
for {
if !(i < nColTest) {
break
}
_sqlite3VdbeJumpHere(tls, v, **(**int32)(__ccgo_up(aGotoChng + uintptr(i)*4)))
_sqlite3VdbeAddOp3(tls, v, int32(OP_Column), iIdxCur, i, regPrev+i)
goto _16
_16:
;
i = i + 1
}
_sqlite3VdbeResolveLabel(tls, v, endDistinctTest)
_sqlite3DbFree(tls, db, aGotoChng)
}
/*
** chng_addr_N:
** regRowid = idx(rowid) // STAT4 only
** stat_push(P, regChng, regRowid) // 3rd parameter STAT4 only
** Next csr
** if !eof(csr) goto next_row;
*/
if (*Tsqlite3)(unsafe.Pointer(db)).FdbOptFlags&libc.Uint32FromInt32(libc.Int32FromInt32(SQLITE_Stat4)) == uint32(0) {
if (*TTable)(unsafe.Pointer(pTab)).FtabFlags&uint32(TF_WithoutRowid) == uint32(0) {
_sqlite3VdbeAddOp2(tls, v, int32(OP_IdxRowid), iIdxCur, regRowid)
} else {
pPk = _sqlite3PrimaryKeyIndex(tls, (*TIndex)(unsafe.Pointer(pIdx)).FpTable)
regKey = _sqlite3GetTempRange(tls, pParse, libc.Int32FromUint16((*TIndex)(unsafe.Pointer(pPk)).FnKeyCol))
j = 0
for {
if !(j < libc.Int32FromUint16((*TIndex)(unsafe.Pointer(pPk)).FnKeyCol)) {
break
}
k = _sqlite3TableColumnToIndex(tls, pIdx, int32(**(**Ti16)(__ccgo_up((*TIndex)(unsafe.Pointer(pPk)).FaiColumn + uintptr(j)*2))))
_sqlite3VdbeAddOp3(tls, v, int32(OP_Column), iIdxCur, k, regKey+j)
goto _17
_17:
;
j = j + 1
}
_sqlite3VdbeAddOp3(tls, v, int32(OP_MakeRecord), regKey, libc.Int32FromUint16((*TIndex)(unsafe.Pointer(pPk)).FnKeyCol), regRowid)
_sqlite3ReleaseTempRange(tls, pParse, regKey, libc.Int32FromUint16((*TIndex)(unsafe.Pointer(pPk)).FnKeyCol))
}
}
_sqlite3VdbeAddFunctionCall(tls, pParse, int32(1), regStat, regTemp, libc.Int32FromInt32(2)+libc.Int32FromInt32(IsStat4), uintptr(unsafe.Pointer(&_statPushFuncdef)), 0)
if (*Tsqlite3)(unsafe.Pointer(db)).FnAnalysisLimit != 0 {
j1 = _sqlite3VdbeAddOp1(tls, v, int32(OP_IsNull), regTemp)
j2 = _sqlite3VdbeAddOp1(tls, v, int32(OP_If), regTemp)
j3 = _sqlite3VdbeAddOp4Int(tls, v, int32(OP_SeekGT), iIdxCur, 0, regPrev, int32(1))
_sqlite3VdbeJumpHere(tls, v, j1)
_sqlite3VdbeAddOp2(tls, v, int32(OP_Next), iIdxCur, addrNextRow)
_sqlite3VdbeJumpHere(tls, v, j2)
_sqlite3VdbeJumpHere(tls, v, j3)
} else {
_sqlite3VdbeAddOp2(tls, v, int32(OP_Next), iIdxCur, addrNextRow)
}
/* Add the entry to the stat1 table. */
if (*TIndex)(unsafe.Pointer(pIdx)).FpPartIdxWhere != 0 {
/* Partial indexes might get a zero-entry in sqlite_stat1. But
** an empty table is omitted from sqlite_stat1. */
_sqlite3VdbeJumpHere(tls, v, addrGotoEnd)
addrGotoEnd = 0
}
_callStatGet(tls, pParse, regStat, STAT_GET_STAT1, regStat1)
_sqlite3VdbeAddOp4(tls, v, int32(OP_MakeRecord), regTabname, int32(3), regTemp, __ccgo_ts+13388, 0)
_sqlite3VdbeAddOp2(tls, v, int32(OP_NewRowid), iStatCur, regNewRowid)
_sqlite3VdbeAddOp3(tls, v, int32(OP_Insert), iStatCur, regTemp, regNewRowid)
_sqlite3VdbeChangeP4(tls, v, -int32(1), pStat1, -int32(5))
_sqlite3VdbeChangeP5(tls, v, uint16(OPFLAG_APPEND))
/* Add the entries to the stat4 table. */
if (*Tsqlite3)(unsafe.Pointer(db)).FdbOptFlags&libc.Uint32FromInt32(libc.Int32FromInt32(SQLITE_Stat4)) == uint32(0) && (*Tsqlite3)(unsafe.Pointer(db)).FnAnalysisLimit == 0 {
regEq = regStat1
regLt = regStat1 + int32(1)
regDLt = regStat1 + int32(2)
regSample = regStat1 + int32(3)
regCol = regStat1 + int32(4)
regSampleRowid = regCol + nCol
if (*TTable)(unsafe.Pointer(pTab)).FtabFlags&uint32(TF_WithoutRowid) == uint32(0) {
v1 = int32(OP_NotExists)
} else {
v1 = int32(OP_NotFound)
}
seekOp = libc.Uint8FromInt32(v1)
/* No STAT4 data is generated if the number of rows is zero */
if addrGotoEnd == 0 {
_sqlite3VdbeAddOp2(tls, v, int32(OP_Cast), regStat1, int32(SQLITE_AFF_INTEGER))
addrGotoEnd = _sqlite3VdbeAddOp1(tls, v, int32(OP_IfNot), regStat1)
}
if doOnce != 0 {
mxCol = nCol
/* Compute the maximum number of columns in any index */
pX = (*TTable)(unsafe.Pointer(pTab)).FpIndex
for {
if !(pX != 0) {
break
} /* Number of columns in pX */
if !((*TTable)(unsafe.Pointer(pTab)).FtabFlags&libc.Uint32FromInt32(TF_WithoutRowid) == libc.Uint32FromInt32(0)) && int32(uint32(*(*uint16)(unsafe.Pointer(pX + 100))&0x3>>0)) == int32(SQLITE_IDXTYPE_PRIMARYKEY) {
nColX = libc.Int32FromUint16((*TIndex)(unsafe.Pointer(pX)).FnKeyCol)
} else {
nColX = libc.Int32FromUint16((*TIndex)(unsafe.Pointer(pX)).FnColumn)
}
if nColX > mxCol {
mxCol = nColX
}
goto _19
_19:
;
pX = (*TIndex)(unsafe.Pointer(pX)).FpNext
}
/* Allocate space to compute results for the largest index */
_sqlite3TouchRegister(tls, pParse, regCol+mxCol)
doOnce = 0
_sqlite3ClearTempRegCache(tls, pParse) /* tag-20230325-1 */
}
addrNext = _sqlite3VdbeCurrentAddr(tls, v)
_callStatGet(tls, pParse, regStat, int32(STAT_GET_ROWID), regSampleRowid)
addrIsNull = _sqlite3VdbeAddOp1(tls, v, int32(OP_IsNull), regSampleRowid)
_callStatGet(tls, pParse, regStat, int32(STAT_GET_NEQ), regEq)
_callStatGet(tls, pParse, regStat, int32(STAT_GET_NLT), regLt)
_callStatGet(tls, pParse, regStat, int32(STAT_GET_NDLT), regDLt)
_sqlite3VdbeAddOp4Int(tls, v, libc.Int32FromUint8(seekOp), iTabCur, addrNext, regSampleRowid, 0)
i = 0
for {
if !(i < nCol) {
break
}
_sqlite3ExprCodeLoadIndexColumn(tls, pParse, pIdx, iTabCur, i, regCol+i)
goto _20
_20:
;
i = i + 1
}
_sqlite3VdbeAddOp3(tls, v, int32(OP_MakeRecord), regCol, nCol, regSample)
_sqlite3VdbeAddOp3(tls, v, int32(OP_MakeRecord), regTabname, int32(6), regTemp)
_sqlite3VdbeAddOp2(tls, v, int32(OP_NewRowid), iStatCur+int32(1), regNewRowid)
_sqlite3VdbeAddOp3(tls, v, int32(OP_Insert), iStatCur+int32(1), regTemp, regNewRowid)
_sqlite3VdbeAddOp2(tls, v, int32(OP_Goto), int32(1), addrNext) /* P1==1 for end-of-loop */
_sqlite3VdbeJumpHere(tls, v, addrIsNull)
}
/* End of analysis */
if addrGotoEnd != 0 {
_sqlite3VdbeJumpHere(tls, v, addrGotoEnd)
}
goto _13
_13:
;
pIdx = (*TIndex)(unsafe.Pointer(pIdx)).FpNext
}
/* Create a single sqlite_stat1 entry containing NULL as the index
** name and the row count as the content.
*/
if pOnlyIdx == uintptr(0) && needTableCnt != 0 {
_sqlite3VdbeAddOp2(tls, v, int32(OP_Count), iTabCur, regStat1)
jZeroRows = _sqlite3VdbeAddOp1(tls, v, int32(OP_IfNot), regStat1)
_sqlite3VdbeAddOp2(tls, v, int32(OP_Null), 0, regIdxname)
_sqlite3VdbeAddOp4(tls, v, int32(OP_MakeRecord), regTabname, int32(3), regTemp, __ccgo_ts+13388, 0)
_sqlite3VdbeAddOp2(tls, v, int32(OP_NewRowid), iStatCur, regNewRowid)
_sqlite3VdbeAddOp3(tls, v, int32(OP_Insert), iStatCur, regTemp, regNewRowid)
_sqlite3VdbeChangeP5(tls, v, uint16(OPFLAG_APPEND))
_sqlite3VdbeChangeP4(tls, v, -int32(1), pStat1, -int32(5))
_sqlite3VdbeJumpHere(tls, v, jZeroRows)
}
}
// C documentation
//
// /*
// ** Generate code that will do an analysis of a single table in
// ** a database. If pOnlyIdx is not NULL then it is a single index
// ** in pTab that should be analyzed.
// */
func _analyzeTable(tls *libc.TLS, pParse uintptr, pTab uintptr, pOnlyIdx uintptr) {
var iDb, iStatCur int32
_, _ = iDb, iStatCur
iDb = _sqlite3SchemaToIndex(tls, (*TParse)(unsafe.Pointer(pParse)).Fdb, (*TTable)(unsafe.Pointer(pTab)).FpSchema)
_sqlite3BeginWriteOperation(tls, pParse, 0, iDb)
iStatCur = (*TParse)(unsafe.Pointer(pParse)).FnTab
**(**int32)(__ccgo_up(pParse + 56)) += int32(3)
if pOnlyIdx != 0 {
_openStatTable(tls, pParse, iDb, iStatCur, (*TIndex)(unsafe.Pointer(pOnlyIdx)).FzName, __ccgo_ts+13392)
} else {
_openStatTable(tls, pParse, iDb, iStatCur, (*TTable)(unsafe.Pointer(pTab)).FzName, __ccgo_ts+13396)
}
_analyzeOneTable(tls, pParse, pTab, pOnlyIdx, iStatCur, (*TParse)(unsafe.Pointer(pParse)).FnMem+int32(1), (*TParse)(unsafe.Pointer(pParse)).FnTab)
_loadAnalysis(tls, pParse, iDb)
}
// 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(1184)
defer tls.Free(1184)
var got Tssize_t
var zIn, v2 uintptr
var v1 int32
var _ /* buf at bp+0 */ Tstat
var _ /* zLnk at bp+144 */ [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 + 20
*(*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 + 20
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.X__builtin___memcpy_chk(tls, (*TDbPath)(unsafe.Pointer(pPath)).FzOut+uintptr((*TDbPath)(unsafe.Pointer(pPath)).FnUsed), zName, libc.Uint64FromInt32(nName), ^t__predefined_size_t(0))
**(**int32)(__ccgo_up(pPath + 20)) += 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(S_IFMT) == int32(S_IFLNK) {
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+144, libc.Uint64FromInt64(1026)-libc.Uint64FromInt32(2))
if got <= 0 || got >= libc.Int64FromInt64(1026)-libc.Int64FromInt32(2) {
(*TDbPath)(unsafe.Pointer(pPath)).Frc = _unixLogErrorAtLine(tls, _sqlite3CantopenError(tls, int32(47163)), __ccgo_ts+3729, zIn, int32(47163))
return
}
(**(**[1026]int8)(__ccgo_up(bp + 144)))[got] = 0
if int32((**(**[1026]int8)(__ccgo_up(bp + 144)))[0]) == int32('/') {
(*TDbPath)(unsafe.Pointer(pPath)).FnUsed = 0
} else {
**(**int32)(__ccgo_up(pPath + 20)) -= nName + int32(1)
}
_appendAllPathElements(tls, pPath, bp+144)
}
}
}
}
// C documentation
//
// /*
// ** Append text z[] to the end of p[]. Return a pointer to the first
// ** character after then zero terminator on the new text in p[].
// */
func _appendText(tls *libc.TLS, p uintptr, z uintptr) (r uintptr) {
var n Tsize_t
_ = n
n = libc.Xstrlen(tls, z)
libc.X__builtin___memcpy_chk(tls, p, z, n+uint64(1), ^t__predefined_size_t(0))
return p + uintptr(n) + uintptr(1)
}
// C documentation
//
// /*
// ** An SQL user-function registered to do the work of an ATTACH statement. The
// ** three arguments to the function come directly from an attach statement:
// **
// ** ATTACH DATABASE x AS y KEY z
// **
// ** SELECT sqlite_attach(x, y, z)
// **
// ** If the optional "KEY z" syntax is omitted, an SQL NULL is passed as the
// ** third argument.
// **
// ** If the db->init.reopenMemdb flags is set, then instead of attaching a
// ** new database, close the database on db->init.iDb and reopen it as an
// ** empty MemDB.
// */
func _attachFunc(tls *libc.TLS, context uintptr, NotUsed int32, argv uintptr) {
bp := tls.Alloc(64)
defer tls.Free(64)
var aNew, db, pNew, pNewSchema, pPager, zFile, zName uintptr
var i, iDb, rc int32
var _ /* flags at bp+16 */ uint32
var _ /* pNewBt at bp+40 */ uintptr
var _ /* pVfs at bp+32 */ uintptr
var _ /* zErr at bp+8 */ uintptr
var _ /* zErrDyn at bp+24 */ uintptr
var _ /* zPath at bp+0 */ uintptr
_, _, _, _, _, _, _, _, _, _ = aNew, db, i, iDb, pNew, pNewSchema, pPager, rc, zFile, zName
rc = 0
db = Xsqlite3_context_db_handle(tls, context)
**(**uintptr)(__ccgo_up(bp)) = uintptr(0)
**(**uintptr)(__ccgo_up(bp + 8)) = uintptr(0) /* New array of Db pointers */
pNew = uintptr(0) /* Db object for the newly attached database */
**(**uintptr)(__ccgo_up(bp + 24)) = uintptr(0)
_ = NotUsed
zFile = Xsqlite3_value_text(tls, **(**uintptr)(__ccgo_up(argv)))
zName = Xsqlite3_value_text(tls, **(**uintptr)(__ccgo_up(argv + 1*8)))
if zFile == uintptr(0) {
zFile = __ccgo_ts + 1702
}
if zName == uintptr(0) {
zName = __ccgo_ts + 1702
}
if int32(uint32(*(*uint8)(unsafe.Pointer(db + 192 + 8))&0x8>>3)) != 0 {
/* This is not a real ATTACH. Instead, this routine is being called
** from sqlite3_deserialize() to close database db->init.iDb and
** reopen it as a MemDB */
**(**uintptr)(__ccgo_up(bp + 40)) = uintptr(0)
pNew = (*Tsqlite3)(unsafe.Pointer(db)).FaDb + uintptr((*Tsqlite3)(unsafe.Pointer(db)).Finit1.FiDb)*32
if _sqlite3BtreeTxnState(tls, (*TDb)(unsafe.Pointer(pNew)).FpBt) != SQLITE_TXN_NONE || _sqlite3BtreeIsInBackup(tls, (*TDb)(unsafe.Pointer(pNew)).FpBt) != 0 {
rc = int32(SQLITE_BUSY)
goto attach_error
}
**(**uintptr)(__ccgo_up(bp + 32)) = Xsqlite3_vfs_find(tls, __ccgo_ts+4460)
if **(**uintptr)(__ccgo_up(bp + 32)) == uintptr(0) {
return
}
rc = _sqlite3BtreeOpen(tls, **(**uintptr)(__ccgo_up(bp + 32)), __ccgo_ts+13595, db, bp+40, 0, int32(SQLITE_OPEN_MAIN_DB))
if rc == SQLITE_OK {
pNewSchema = _sqlite3SchemaGet(tls, db, **(**uintptr)(__ccgo_up(bp + 40)))
if pNewSchema != 0 {
/* Both the Btree and the new Schema were allocated successfully.
** Close the old db and update the aDb[] slot with the new memdb
** values. */
_sqlite3BtreeClose(tls, (*TDb)(unsafe.Pointer(pNew)).FpBt)
(*TDb)(unsafe.Pointer(pNew)).FpBt = **(**uintptr)(__ccgo_up(bp + 40))
(*TDb)(unsafe.Pointer(pNew)).FpSchema = pNewSchema
} else {
_sqlite3BtreeClose(tls, **(**uintptr)(__ccgo_up(bp + 40)))
rc = int32(SQLITE_NOMEM)
}
}
if rc != 0 {
goto attach_error
}
} else {
/* This is a real ATTACH
**
** Check for the following errors:
**
** * Too many attached databases,
** * Transaction currently open
** * Specified database name already being used.
*/
if (*Tsqlite3)(unsafe.Pointer(db)).FnDb >= **(**int32)(__ccgo_up(db + 136 + 7*4))+int32(2) {
**(**uintptr)(__ccgo_up(bp + 24)) = _sqlite3MPrintf(tls, db, __ccgo_ts+13598, libc.VaList(bp+56, **(**int32)(__ccgo_up(db + 136 + 7*4))))
goto attach_error
}
i = 0
for {
if !(i < (*Tsqlite3)(unsafe.Pointer(db)).FnDb) {
break
}
if _sqlite3DbIsNamed(tls, db, i, zName) != 0 {
**(**uintptr)(__ccgo_up(bp + 24)) = _sqlite3MPrintf(tls, db, __ccgo_ts+13635, libc.VaList(bp+56, zName))
goto attach_error
}
goto _1
_1:
;
i = i + 1
}
/* Allocate the new entry in the db->aDb[] array and initialize the schema
** hash tables.
*/
if (*Tsqlite3)(unsafe.Pointer(db)).FaDb == db+696 {
aNew = _sqlite3DbMallocRawNN(tls, db, uint64(libc.Uint64FromInt64(32)*libc.Uint64FromInt32(3)))
if aNew == uintptr(0) {
return
}
libc.X__builtin___memcpy_chk(tls, aNew, (*Tsqlite3)(unsafe.Pointer(db)).FaDb, libc.Uint64FromInt64(32)*libc.Uint64FromInt32(2), ^t__predefined_size_t(0))
} else {
aNew = _sqlite3DbRealloc(tls, db, (*Tsqlite3)(unsafe.Pointer(db)).FaDb, uint64(32)*libc.Uint64FromInt64(libc.Int64FromInt32(1)+int64((*Tsqlite3)(unsafe.Pointer(db)).FnDb)))
if aNew == uintptr(0) {
return
}
}
(*Tsqlite3)(unsafe.Pointer(db)).FaDb = aNew
pNew = (*Tsqlite3)(unsafe.Pointer(db)).FaDb + uintptr((*Tsqlite3)(unsafe.Pointer(db)).FnDb)*32
libc.X__builtin___memset_chk(tls, pNew, 0, uint64(32), ^t__predefined_size_t(0))
/* Open the database file. If the btree is successfully opened, use
** it to obtain the database schema. At this point the schema may
** or may not be initialized.
*/
**(**uint32)(__ccgo_up(bp + 16)) = (*Tsqlite3)(unsafe.Pointer(db)).FopenFlags
rc = _sqlite3ParseUri(tls, (*Tsqlite3_vfs)(unsafe.Pointer((*Tsqlite3)(unsafe.Pointer(db)).FpVfs)).FzName, zFile, bp+16, bp+32, bp, bp+8)
if rc != SQLITE_OK {
if rc == int32(SQLITE_NOMEM) {
_sqlite3OomFault(tls, db)
}
Xsqlite3_result_error(tls, context, **(**uintptr)(__ccgo_up(bp + 8)), -int32(1))
Xsqlite3_free(tls, **(**uintptr)(__ccgo_up(bp + 8)))
return
}
if (*Tsqlite3)(unsafe.Pointer(db)).Fflags&(libc.Uint64FromInt32(libc.Int32FromInt32(0x00020))<aDb[] array. i.e. put everything back the
** way we found it.
*/
if rc == SQLITE_OK {
_sqlite3BtreeEnterAll(tls, db)
(*Tsqlite3)(unsafe.Pointer(db)).Finit1.FiDb = uint8(0)
**(**Tu32)(__ccgo_up(db + 44)) &= libc.Uint32FromInt32(^libc.Int32FromInt32(DBFLAG_SchemaKnownOk))
if !(int32(uint32(*(*uint8)(unsafe.Pointer(db + 192 + 8))&0x8>>3)) != 0) {
rc = _sqlite3Init(tls, db, bp+24)
}
_sqlite3BtreeLeaveAll(tls, db)
}
if rc != 0 {
if !(int32(uint32(*(*uint8)(unsafe.Pointer(db + 192 + 8))&0x8>>3)) != 0) {
iDb = (*Tsqlite3)(unsafe.Pointer(db)).FnDb - int32(1)
if (**(**TDb)(__ccgo_up((*Tsqlite3)(unsafe.Pointer(db)).FaDb + uintptr(iDb)*32))).FpBt != 0 {
_sqlite3BtreeClose(tls, (**(**TDb)(__ccgo_up((*Tsqlite3)(unsafe.Pointer(db)).FaDb + uintptr(iDb)*32))).FpBt)
(**(**TDb)(__ccgo_up((*Tsqlite3)(unsafe.Pointer(db)).FaDb + uintptr(iDb)*32))).FpBt = uintptr(0)
(**(**TDb)(__ccgo_up((*Tsqlite3)(unsafe.Pointer(db)).FaDb + uintptr(iDb)*32))).FpSchema = uintptr(0)
}
_sqlite3ResetAllSchemasOfConnection(tls, db)
(*Tsqlite3)(unsafe.Pointer(db)).FnDb = iDb
if rc == int32(SQLITE_NOMEM) || rc == libc.Int32FromInt32(SQLITE_IOERR)|libc.Int32FromInt32(12)< */
/*
** If building separately, we will need some setup that is normally
** found in sqliteInt.h
*/
/* Macro to check for 4-byte alignment. Only used inside of assert() */
/* #include */
/* #include */
/* #include */
/* #include */
/* The following macro is used to suppress compiler warnings.
*/
var _azName1 = [3]uintptr{
0: __ccgo_ts + 28190,
1: __ccgo_ts + 5999,
2: __ccgo_ts + 18314,
}
var _azName2 = [5]uintptr{
0: __ccgo_ts + 40989,
1: __ccgo_ts + 37980,
2: __ccgo_ts + 27799,
3: __ccgo_ts + 38675,
4: __ccgo_ts + 13392,
}
var _azOne = [1]uintptr{
0: __ccgo_ts + 11889,
}
var _azSql = [8]uintptr{
0: __ccgo_ts + 28195,
1: __ccgo_ts + 28248,
2: __ccgo_ts + 28293,
3: __ccgo_ts + 28345,
4: __ccgo_ts + 28399,
5: __ccgo_ts + 28444,
6: __ccgo_ts + 28502,
7: __ccgo_ts + 28557,
}
// C documentation
//
// /*
// ** Directories to consider for temp files.
// */
var _azTempDirs = [6]uintptr{
2: __ccgo_ts + 4032,
3: __ccgo_ts + 4041,
4: __ccgo_ts + 4050,
5: __ccgo_ts + 1741,
}
var _azType = [4]uintptr{
0: __ccgo_ts + 6170,
1: __ccgo_ts + 6179,
2: __ccgo_ts + 6186,
3: __ccgo_ts + 6192,
}
var _azType1 = [6]uintptr{
0: __ccgo_ts + 1702,
1: __ccgo_ts + 14722,
2: __ccgo_ts + 14728,
3: __ccgo_ts + 14733,
4: __ccgo_ts + 14738,
5: __ccgo_ts + 14728,
}
var _azType2 = [5]uintptr{
0: __ccgo_ts + 6840,
1: __ccgo_ts + 6835,
2: __ccgo_ts + 8835,
3: __ccgo_ts + 8830,
4: __ccgo_ts + 1688,
}
// C documentation
//
// /*
// ** Parameter zSrcData points to a buffer containing the data for
// ** page iSrcPg from the source database. Copy this data into the
// ** destination database.
// */
func _backupOnePage(tls *libc.TLS, p uintptr, iSrcPg TPgno, zSrcData uintptr, bUpdate int32) (r int32) {
bp := tls.Alloc(16)
defer tls.Free(16)
var iDest TPgno
var iEnd, iOff Ti64
var nCopy, nDestPgsz, nSrcPgsz, rc, v1, v3 int32
var pDestPager, zDestData, zIn, zOut uintptr
var v5 bool
var _ /* pDestPg at bp+0 */ uintptr
_, _, _, _, _, _, _, _, _, _, _, _, _, _ = iDest, iEnd, iOff, nCopy, nDestPgsz, nSrcPgsz, pDestPager, rc, zDestData, zIn, zOut, v1, v3, v5
pDestPager = _sqlite3BtreePager(tls, (*Tsqlite3_backup)(unsafe.Pointer(p)).FpDest)
nSrcPgsz = _sqlite3BtreeGetPageSize(tls, (*Tsqlite3_backup)(unsafe.Pointer(p)).FpSrc)
nDestPgsz = _sqlite3BtreeGetPageSize(tls, (*Tsqlite3_backup)(unsafe.Pointer(p)).FpDest)
if nSrcPgsz < nDestPgsz {
v1 = nSrcPgsz
} else {
v1 = nDestPgsz
}
nCopy = v1
iEnd = libc.Int64FromUint32(iSrcPg) * int64(nSrcPgsz)
rc = SQLITE_OK
/* This loop runs once for each destination page spanned by the source
** page. For each iteration, variable iOff is set to the byte offset
** of the destination page.
*/
iOff = iEnd - int64(nSrcPgsz)
for {
if !(rc == SQLITE_OK && iOff < iEnd) {
break
}
**(**uintptr)(__ccgo_up(bp)) = uintptr(0)
iDest = libc.Uint32FromInt64(iOff/int64(nDestPgsz)) + uint32(1)
if iDest == libc.Uint32FromInt32(_sqlite3PendingByte)/(*TBtShared)(unsafe.Pointer((*TBtree)(unsafe.Pointer((*Tsqlite3_backup)(unsafe.Pointer(p)).FpDest)).FpBt)).FpageSize+libc.Uint32FromInt32(1) {
goto _2
}
v1 = _sqlite3PagerGet(tls, pDestPager, iDest, bp, 0)
rc = v1
if v5 = SQLITE_OK == v1; v5 {
v3 = _sqlite3PagerWrite(tls, **(**uintptr)(__ccgo_up(bp)))
rc = v3
}
if v5 && SQLITE_OK == v3 {
zIn = zSrcData + uintptr(iOff%int64(nSrcPgsz))
zDestData = _sqlite3PagerGetData(tls, **(**uintptr)(__ccgo_up(bp)))
zOut = zDestData + uintptr(iOff%int64(nDestPgsz))
/* Copy the data from the source page into the destination page.
** Then clear the Btree layer MemPage.isInit flag. Both this module
** and the pager code use this trick (clearing the first byte
** of the page 'extra' space to invalidate the Btree layers
** cached parse of the page). MemPage.isInit is marked
** "MUST BE FIRST" for this purpose.
*/
libc.X__builtin___memcpy_chk(tls, zOut, zIn, libc.Uint64FromInt32(nCopy), ^t__predefined_size_t(0))
**(**Tu8)(__ccgo_up(_sqlite3PagerGetExtra(tls, **(**uintptr)(__ccgo_up(bp))))) = uint8(0)
if iOff == 0 && bUpdate == 0 {
_sqlite3Put4byte(tls, zOut+28, _sqlite3BtreeLastPage(tls, (*Tsqlite3_backup)(unsafe.Pointer(p)).FpSrc))
}
}
_sqlite3PagerUnref(tls, **(**uintptr)(__ccgo_up(bp)))
goto _2
_2:
;
iOff = iOff + int64(nDestPgsz)
}
return rc
}
// C documentation
//
// /*
// ** This function is called when the root page of a b-tree structure is
// ** overfull (has one or more overflow pages).
// **
// ** A new child page is allocated and the contents of the current root
// ** page, including overflow cells, are copied into the child. The root
// ** page is then overwritten to make it an empty page with the right-child
// ** pointer pointing to the new page.
// **
// ** Before returning, all pointer-map entries corresponding to pages
// ** that the new child-page now contains pointers to are updated. The
// ** entry corresponding to the new right-child pointer of the root
// ** page is also updated.
// **
// ** If successful, *ppChild is set to contain a reference to the child
// ** page and SQLITE_OK is returned. In this case the caller is required
// ** to call releasePage() on *ppChild exactly once. If an error occurs,
// ** an error code is returned and *ppChild is set to 0.
// */
func _balance_deeper(tls *libc.TLS, pRoot uintptr, ppChild uintptr) (r int32) {
bp := tls.Alloc(32)
defer tls.Free(32)
var pBt uintptr
var _ /* pChild at bp+8 */ uintptr
var _ /* pgnoChild at bp+16 */ TPgno
var _ /* rc at bp+0 */ int32
_ = pBt /* Return value from subprocedures */
**(**uintptr)(__ccgo_up(bp + 8)) = uintptr(0) /* Pointer to a new child page */
**(**TPgno)(__ccgo_up(bp + 16)) = uint32(0) /* Page number of the new child page */
pBt = (*TMemPage)(unsafe.Pointer(pRoot)).FpBt /* The BTree */
/* Make pRoot, the root page of the b-tree, writable. Allocate a new
** page that will become the new right-child of pPage. Copy the contents
** of the node stored on pRoot into the new child page.
*/
**(**int32)(__ccgo_up(bp)) = _sqlite3PagerWrite(tls, (*TMemPage)(unsafe.Pointer(pRoot)).FpDbPage)
if **(**int32)(__ccgo_up(bp)) == SQLITE_OK {
**(**int32)(__ccgo_up(bp)) = _allocateBtreePage(tls, pBt, bp+8, bp+16, (*TMemPage)(unsafe.Pointer(pRoot)).Fpgno, uint8(0))
_copyNodeContent(tls, pRoot, **(**uintptr)(__ccgo_up(bp + 8)), bp)
if (*TBtShared)(unsafe.Pointer(pBt)).FautoVacuum != 0 {
_ptrmapPut(tls, pBt, **(**TPgno)(__ccgo_up(bp + 16)), uint8(PTRMAP_BTREE), (*TMemPage)(unsafe.Pointer(pRoot)).Fpgno, bp)
}
}
if **(**int32)(__ccgo_up(bp)) != 0 {
**(**uintptr)(__ccgo_up(ppChild)) = uintptr(0)
_releasePage(tls, **(**uintptr)(__ccgo_up(bp + 8)))
return **(**int32)(__ccgo_up(bp))
}
/* Copy the overflow cells from pRoot to pChild */
libc.X__builtin___memcpy_chk(tls, **(**uintptr)(__ccgo_up(bp + 8))+28, pRoot+28, uint64((*TMemPage)(unsafe.Pointer(pRoot)).FnOverflow)*uint64(2), ^t__predefined_size_t(0))
libc.X__builtin___memcpy_chk(tls, **(**uintptr)(__ccgo_up(bp + 8))+40, pRoot+40, uint64((*TMemPage)(unsafe.Pointer(pRoot)).FnOverflow)*uint64(8), ^t__predefined_size_t(0))
(*TMemPage)(unsafe.Pointer(**(**uintptr)(__ccgo_up(bp + 8)))).FnOverflow = (*TMemPage)(unsafe.Pointer(pRoot)).FnOverflow
/* Zero the contents of pRoot. Then install pChild as the right-child. */
_zeroPage(tls, pRoot, libc.Int32FromUint8(**(**Tu8)(__ccgo_up((*TMemPage)(unsafe.Pointer(**(**uintptr)(__ccgo_up(bp + 8)))).FaData))) & ^libc.Int32FromInt32(PTF_LEAF))
_sqlite3Put4byte(tls, (*TMemPage)(unsafe.Pointer(pRoot)).FaData+uintptr(libc.Int32FromUint8((*TMemPage)(unsafe.Pointer(pRoot)).FhdrOffset)+int32(8)), **(**TPgno)(__ccgo_up(bp + 16)))
**(**uintptr)(__ccgo_up(ppChild)) = **(**uintptr)(__ccgo_up(bp + 8))
return SQLITE_OK
}
// C documentation
//
// /*
// ** This routine redistributes cells on the iParentIdx'th child of pParent
// ** (hereafter "the page") and up to 2 siblings so that all pages have about the
// ** same amount of free space. Usually a single sibling on either side of the
// ** page are used in the balancing, though both siblings might come from one
// ** side if the page is the first or last child of its parent. If the page
// ** has fewer than 2 siblings (something which can only happen if the page
// ** is a root page or a child of a root page) then all available siblings
// ** participate in the balancing.
// **
// ** The number of siblings of the page might be increased or decreased by
// ** one or two in an effort to keep pages nearly full but not over full.
// **
// ** Note that when this routine is called, some of the cells on the page
// ** might not actually be stored in MemPage.aData[]. This can happen
// ** if the page is overfull. This routine ensures that all cells allocated
// ** to the page and its siblings fit into MemPage.aData[] before returning.
// **
// ** In the course of balancing the page and its siblings, cells may be
// ** inserted into or removed from the parent page (pParent). Doing so
// ** may cause the parent page to become overfull or underfull. If this
// ** happens, it is the responsibility of the caller to invoke the correct
// ** balancing routine to fix this problem (see the balance() routine).
// **
// ** If this routine fails for any reason, it might leave the database
// ** in a corrupted state. So if this routine fails, the database should
// ** be rolled back.
// **
// ** The third argument to this function, aOvflSpace, is a pointer to a
// ** buffer big enough to hold one page. If while inserting cells into the parent
// ** page (pParent) the parent page becomes overfull, this buffer is
// ** used to store the parent's overflow cells. Because this function inserts
// ** a maximum of four divider cells into the parent page, and the maximum
// ** size of a cell stored within an internal node is always less than 1/4
// ** of the page-size, the aOvflSpace[] buffer is guaranteed to be large
// ** enough for all overflow cells.
// **
// ** If aOvflSpace is set to a null pointer, this function returns
// ** SQLITE_NOMEM.
// */
func _balance_nonroot(tls *libc.TLS, pParent uintptr, iParentIdx int32, aOvflSpace uintptr, isRoot int32, bBulk int32) (r1 int32) {
bp := tls.Alloc(208)
defer tls.Free(208)
var aData, aSpace1, p, pBt, pCell, pCell1, pNew1, pNew2, pOld, pOld1, pOld2, pRight, pSrcEnd, pTemp, pTemp1, piCell, piEnd, v17 uintptr
var aPgno [5]TPgno
var apDiv [2]uintptr
var apNew [5]uintptr
var cntNew, cntOld [5]int32
var cntOldNext, d, i, iB, iNew, iNew1, iOff, iOld, iOld1, iOvflSpace, iPg, iSpace1, j, k, leafData, limit, nMaxCells, nNew, nNewCell, nOld, nxDiv, pageFlags, r, sz1, sz2, szD, szLeft, szR, szRight, usableSpace, v1 int32
var fgA, fgB, leafCorrection, maskPage, sz Tu16
var key Tu32
var pgnoA, pgnoB, pgnoTemp TPgno
var szScratch Tu64
var v13, v14 bool
var v18 uint32
var _ /* abDone at bp+60 */ [5]Tu8
var _ /* apOld at bp+8 */ [3]uintptr
var _ /* b at bp+72 */ TCellArray
var _ /* info at bp+184 */ TCellInfo
var _ /* pNew at bp+176 */ uintptr
var _ /* pgno at bp+52 */ TPgno
var _ /* rc at bp+0 */ int32
var _ /* szNew at bp+32 */ [5]int32
_, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _ = aData, aPgno, aSpace1, apDiv, apNew, cntNew, cntOld, cntOldNext, d, fgA, fgB, i, iB, iNew, iNew1, iOff, iOld, iOld1, iOvflSpace, iPg, iSpace1, j, k, key, leafCorrection, leafData, limit, maskPage, nMaxCells, nNew, nNewCell, nOld, nxDiv, p, pBt, pCell, pCell1, pNew1, pNew2, pOld, pOld1, pOld2, pRight, pSrcEnd, pTemp, pTemp1, pageFlags, pgnoA, pgnoB, pgnoTemp, piCell, piEnd, r, sz, sz1, sz2, szD, szLeft, szR, szRight, szScratch, usableSpace, v1, v13, v14, v17, v18 /* The whole database */
nMaxCells = 0 /* Allocated size of apCell, szCell, aFrom. */
nNew = 0 /* Next divider slot in pParent->aCell[] */
**(**int32)(__ccgo_up(bp)) = SQLITE_OK /* Value of pPage->aData[0] */
iSpace1 = 0 /* First unused byte of aSpace1[] */
iOvflSpace = 0 /* Parsed information on cells being balanced */
libc.X__builtin___memset_chk(tls, bp+60, 0, uint64(5), ^t__predefined_size_t(0))
libc.X__builtin___memset_chk(tls, bp+72, 0, libc.Uint64FromInt64(104)-libc.Uint64FromInt64(4), ^t__predefined_size_t(0))
**(**int32)(__ccgo_up(bp + 72 + 80 + uintptr(libc.Int32FromInt32(NB)*libc.Int32FromInt32(2)-libc.Int32FromInt32(1))*4)) = int32(0x7fffffff)
pBt = (*TMemPage)(unsafe.Pointer(pParent)).FpBt
/* At this point pParent may have at most one overflow cell. And if
** this overflow cell is present, it must be the cell with
** index iParentIdx. This scenario comes about when this function
** is called (indirectly) from sqlite3BtreeDelete().
*/
if !(aOvflSpace != 0) {
return int32(SQLITE_NOMEM)
}
/* Find the sibling pages to balance. Also locate the cells in pParent
** that divide the siblings. An attempt is made to find NN siblings on
** either side of pPage. More siblings are taken from one side, however,
** if there are fewer than NN siblings on the other side. If pParent
** has NB or fewer children then all children of pParent are taken.
**
** This loop also drops the divider cells from the parent page. This
** way, the remainder of the function does not have to deal with any
** overflow cells in the parent page, since if any existed they will
** have already been removed.
*/
i = libc.Int32FromUint8((*TMemPage)(unsafe.Pointer(pParent)).FnOverflow) + libc.Int32FromUint16((*TMemPage)(unsafe.Pointer(pParent)).FnCell)
if i < int32(2) {
nxDiv = 0
} else {
if iParentIdx == 0 {
nxDiv = 0
} else {
if iParentIdx == i {
nxDiv = i - int32(2) + bBulk
} else {
nxDiv = iParentIdx - int32(1)
}
}
i = int32(2) - bBulk
}
nOld = i + int32(1)
if i+nxDiv-libc.Int32FromUint8((*TMemPage)(unsafe.Pointer(pParent)).FnOverflow) == libc.Int32FromUint16((*TMemPage)(unsafe.Pointer(pParent)).FnCell) {
pRight = (*TMemPage)(unsafe.Pointer(pParent)).FaData + uintptr(libc.Int32FromUint8((*TMemPage)(unsafe.Pointer(pParent)).FhdrOffset)+int32(8))
} else {
pRight = (*TMemPage)(unsafe.Pointer(pParent)).FaData + uintptr(libc.Int32FromUint16((*TMemPage)(unsafe.Pointer(pParent)).FmaskPage)&(libc.Int32FromUint8(**(**Tu8)(__ccgo_up((*TMemPage)(unsafe.Pointer(pParent)).FaCellIdx + uintptr(int32(2)*(i+nxDiv-libc.Int32FromUint8((*TMemPage)(unsafe.Pointer(pParent)).FnOverflow))))))< 0 {
if limit < libc.Int32FromUint16(**(**Tu16)(__ccgo_up(pOld + 28))) {
**(**int32)(__ccgo_up(bp)) = _sqlite3CorruptError(tls, int32(81691))
goto balance_cleanup
}
limit = libc.Int32FromUint16(**(**Tu16)(__ccgo_up(pOld + 28)))
j = 0
for {
if !(j < limit) {
break
}
**(**uintptr)(__ccgo_up((**(**TCellArray)(__ccgo_up(bp + 72))).FapCell + uintptr((**(**TCellArray)(__ccgo_up(bp + 72))).FnCell)*8)) = aData + uintptr(libc.Int32FromUint16(maskPage)&(libc.Int32FromUint8(**(**Tu8)(__ccgo_up(piCell)))< usableSpace {
if i+int32(1) >= k {
k = i + int32(2)
if k > libc.Int32FromInt32(NB)+libc.Int32FromInt32(2) {
**(**int32)(__ccgo_up(bp)) = _sqlite3CorruptError(tls, int32(81792))
goto balance_cleanup
}
(**(**[5]int32)(__ccgo_up(bp + 32)))[k-int32(1)] = 0
cntNew[k-int32(1)] = (**(**TCellArray)(__ccgo_up(bp + 72))).FnCell
}
sz1 = int32(2) + libc.Int32FromUint16(_cachedCellSize(tls, bp+72, cntNew[i]-int32(1)))
**(**int32)(__ccgo_up(bp + 32 + uintptr(i)*4)) -= sz1
if !(leafData != 0) {
if cntNew[i] < (**(**TCellArray)(__ccgo_up(bp + 72))).FnCell {
sz1 = int32(2) + libc.Int32FromUint16(_cachedCellSize(tls, bp+72, cntNew[i]))
} else {
sz1 = 0
}
}
**(**int32)(__ccgo_up(bp + 32 + uintptr(i+int32(1))*4)) += sz1
cntNew[i] = cntNew[i] - 1
}
for cntNew[i] < (**(**TCellArray)(__ccgo_up(bp + 72))).FnCell {
sz1 = int32(2) + libc.Int32FromUint16(_cachedCellSize(tls, bp+72, cntNew[i]))
if (**(**[5]int32)(__ccgo_up(bp + 32)))[i]+sz1 > usableSpace {
break
}
**(**int32)(__ccgo_up(bp + 32 + uintptr(i)*4)) += sz1
cntNew[i] = cntNew[i] + 1
if !(leafData != 0) {
if cntNew[i] < (**(**TCellArray)(__ccgo_up(bp + 72))).FnCell {
sz1 = int32(2) + libc.Int32FromUint16(_cachedCellSize(tls, bp+72, cntNew[i]))
} else {
sz1 = 0
}
}
**(**int32)(__ccgo_up(bp + 32 + uintptr(i+int32(1))*4)) -= sz1
}
if cntNew[i] >= (**(**TCellArray)(__ccgo_up(bp + 72))).FnCell {
k = i + int32(1)
} else {
if i > 0 {
v1 = cntNew[i-int32(1)]
} else {
v1 = 0
}
if cntNew[i] <= v1 {
**(**int32)(__ccgo_up(bp)) = _sqlite3CorruptError(tls, int32(81825))
goto balance_cleanup
}
}
goto _9
_9:
;
i = i + 1
}
/*
** The packing computed by the previous block is biased toward the siblings
** on the left side (siblings with smaller keys). The left siblings are
** always nearly full, while the right-most sibling might be nearly empty.
** The next block of code attempts to adjust the packing of siblings to
** get a better balance.
**
** This adjustment is more than an optimization. The packing above might
** be so out of balance as to be illegal. For example, the right-most
** sibling might be completely empty. This adjustment is not optional.
*/
i = k - int32(1)
for {
if !(i > 0) {
break
}
szRight = (**(**[5]int32)(__ccgo_up(bp + 32)))[i] /* Size of sibling on the right */
szLeft = (**(**[5]int32)(__ccgo_up(bp + 32)))[i-int32(1)] /* Index of first cell to the left of right sibling */
r = cntNew[i-int32(1)] - int32(1)
d = r + int32(1) - leafData
_cachedCellSize(tls, bp+72, d)
for cond := true; cond; cond = r >= 0 {
szR = libc.Int32FromUint16(_cachedCellSize(tls, bp+72, r))
szD = libc.Int32FromUint16(**(**Tu16)(__ccgo_up((**(**TCellArray)(__ccgo_up(bp + 72))).FszCell + uintptr(d)*2)))
if v14 = szRight != 0; v14 {
if v13 = bBulk != 0; !v13 {
if i == k-int32(1) {
v1 = 0
} else {
v1 = int32(2)
}
}
}
if v14 && (v13 || szRight+szD+int32(2) > szLeft-(szR+v1)) {
break
}
szRight = szRight + (szD + int32(2))
szLeft = szLeft - (szR + int32(2))
cntNew[i-int32(1)] = r
r = r - 1
d = d - 1
}
(**(**[5]int32)(__ccgo_up(bp + 32)))[i] = szRight
(**(**[5]int32)(__ccgo_up(bp + 32)))[i-int32(1)] = szLeft
if i > int32(1) {
v1 = cntNew[i-int32(2)]
} else {
v1 = 0
}
if cntNew[i-int32(1)] <= v1 {
**(**int32)(__ccgo_up(bp)) = _sqlite3CorruptError(tls, int32(81869))
goto balance_cleanup
}
goto _11
_11:
;
i = i - 1
}
/* Sanity check: For a non-corrupt database file one of the following
** must be true:
** (1) We found one or more cells (cntNew[0])>0), or
** (2) pPage is a virtual root page. A virtual root page is when
** the real root page is page 1 and we are the only child of
** that page.
*/
/*
** Allocate k new pages. Reuse old pages where possible.
*/
pageFlags = libc.Int32FromUint8(**(**Tu8)(__ccgo_up((*TMemPage)(unsafe.Pointer((**(**[3]uintptr)(__ccgo_up(bp + 8)))[0])).FaData)))
i = 0
for {
if !(i < k) {
break
}
if i < nOld {
v17 = (**(**[3]uintptr)(__ccgo_up(bp + 8)))[i]
apNew[i] = v17
**(**uintptr)(__ccgo_up(bp + 176)) = v17
(**(**[3]uintptr)(__ccgo_up(bp + 8)))[i] = uintptr(0)
**(**int32)(__ccgo_up(bp)) = _sqlite3PagerWrite(tls, (*TMemPage)(unsafe.Pointer(**(**uintptr)(__ccgo_up(bp + 176)))).FpDbPage)
nNew = nNew + 1
if _sqlite3PagerPageRefcount(tls, (*TMemPage)(unsafe.Pointer(**(**uintptr)(__ccgo_up(bp + 176)))).FpDbPage) != int32(1)+libc.BoolInt32(i == iParentIdx-nxDiv) && **(**int32)(__ccgo_up(bp)) == SQLITE_OK {
**(**int32)(__ccgo_up(bp)) = _sqlite3CorruptError(tls, int32(81902))
}
if **(**int32)(__ccgo_up(bp)) != 0 {
goto balance_cleanup
}
} else {
if bBulk != 0 {
v18 = uint32(1)
} else {
v18 = **(**TPgno)(__ccgo_up(bp + 52))
}
**(**int32)(__ccgo_up(bp)) = _allocateBtreePage(tls, pBt, bp+176, bp+52, v18, uint8(0))
if **(**int32)(__ccgo_up(bp)) != 0 {
goto balance_cleanup
}
_zeroPage(tls, **(**uintptr)(__ccgo_up(bp + 176)), pageFlags)
apNew[i] = **(**uintptr)(__ccgo_up(bp + 176))
nNew = nNew + 1
cntOld[i] = (**(**TCellArray)(__ccgo_up(bp + 72))).FnCell
/* Set the pointer-map entry for the new sibling page. */
if (*TBtShared)(unsafe.Pointer(pBt)).FautoVacuum != 0 {
_ptrmapPut(tls, pBt, (*TMemPage)(unsafe.Pointer(**(**uintptr)(__ccgo_up(bp + 176)))).Fpgno, uint8(PTRMAP_BTREE), (*TMemPage)(unsafe.Pointer(pParent)).Fpgno, bp)
if **(**int32)(__ccgo_up(bp)) != SQLITE_OK {
goto balance_cleanup
}
}
}
goto _16
_16:
;
i = i + 1
}
/*
** Reassign page numbers so that the new pages are in ascending order.
** This helps to keep entries in the disk file in order so that a scan
** of the table is closer to a linear scan through the file. That in turn
** helps the operating system to deliver pages from the disk more rapidly.
**
** An O(N*N) sort algorithm is used, but since N is never more than NB+2
** (5), that is not a performance concern.
**
** When NB==3, this one optimization makes the database about 25% faster
** for large insertions and deletions.
*/
i = 0
for {
if !(i < nNew) {
break
}
aPgno[i] = (*TMemPage)(unsafe.Pointer(apNew[i])).Fpgno
goto _19
_19:
;
i = i + 1
}
i = 0
for {
if !(i < nNew-int32(1)) {
break
}
iB = i
j = i + int32(1)
for {
if !(j < nNew) {
break
}
if (*TMemPage)(unsafe.Pointer(apNew[j])).Fpgno < (*TMemPage)(unsafe.Pointer(apNew[iB])).Fpgno {
iB = j
}
goto _21
_21:
;
j = j + 1
}
/* If apNew[i] has a page number that is bigger than any of the
** subsequence apNew[i] entries, then swap apNew[i] with the subsequent
** entry that has the smallest page number (which we know to be
** entry apNew[iB]).
*/
if iB != i {
pgnoA = (*TMemPage)(unsafe.Pointer(apNew[i])).Fpgno
pgnoB = (*TMemPage)(unsafe.Pointer(apNew[iB])).Fpgno
pgnoTemp = libc.Uint32FromInt32(_sqlite3PendingByte)/(*TBtShared)(unsafe.Pointer(pBt)).FpageSize + uint32(1)
fgA = (*TDbPage)(unsafe.Pointer((*TMemPage)(unsafe.Pointer(apNew[i])).FpDbPage)).Fflags
fgB = (*TDbPage)(unsafe.Pointer((*TMemPage)(unsafe.Pointer(apNew[iB])).FpDbPage)).Fflags
_sqlite3PagerRekey(tls, (*TMemPage)(unsafe.Pointer(apNew[i])).FpDbPage, pgnoTemp, fgB)
_sqlite3PagerRekey(tls, (*TMemPage)(unsafe.Pointer(apNew[iB])).FpDbPage, pgnoA, fgA)
_sqlite3PagerRekey(tls, (*TMemPage)(unsafe.Pointer(apNew[i])).FpDbPage, pgnoB, fgB)
(*TMemPage)(unsafe.Pointer(apNew[i])).Fpgno = pgnoB
(*TMemPage)(unsafe.Pointer(apNew[iB])).Fpgno = pgnoA
}
goto _20
_20:
;
i = i + 1
}
_sqlite3Put4byte(tls, pRight, (*TMemPage)(unsafe.Pointer(apNew[nNew-int32(1)])).Fpgno)
/* If the sibling pages are not leaves, ensure that the right-child pointer
** of the right-most new sibling page is set to the value that was
** originally in the same field of the right-most old sibling page. */
if pageFlags&int32(PTF_LEAF) == 0 && nOld != nNew {
if nNew > nOld {
pOld1 = apNew[nOld-int32(1)]
} else {
pOld1 = (**(**[3]uintptr)(__ccgo_up(bp + 8)))[nOld-int32(1)]
}
libc.X__builtin___memcpy_chk(tls, (*TMemPage)(unsafe.Pointer(apNew[nNew-int32(1)])).FaData+8, (*TMemPage)(unsafe.Pointer(pOld1)).FaData+8, uint64(4), ^t__predefined_size_t(0))
}
/* Make any required updates to pointer map entries associated with
** cells stored on sibling pages following the balance operation. Pointer
** map entries associated with divider cells are set by the insertCell()
** routine. The associated pointer map entries are:
**
** a) if the cell contains a reference to an overflow chain, the
** entry associated with the first page in the overflow chain, and
**
** b) if the sibling pages are not leaves, the child page associated
** with the cell.
**
** If the sibling pages are not leaves, then the pointer map entry
** associated with the right-child of each sibling may also need to be
** updated. This happens below, after the sibling pages have been
** populated, not here.
*/
if (*TBtShared)(unsafe.Pointer(pBt)).FautoVacuum != 0 {
v17 = apNew[0]
pOld2 = v17
pNew1 = v17
cntOldNext = libc.Int32FromUint16((*TMemPage)(unsafe.Pointer(pNew1)).FnCell) + libc.Int32FromUint8((*TMemPage)(unsafe.Pointer(pNew1)).FnOverflow)
iNew = 0
iOld = 0
i = 0
for {
if !(i < (**(**TCellArray)(__ccgo_up(bp + 72))).FnCell) {
break
}
pCell = **(**uintptr)(__ccgo_up((**(**TCellArray)(__ccgo_up(bp + 72))).FapCell + uintptr(i)*8))
for i == cntOldNext {
iOld = iOld + 1
if iOld < nNew {
v17 = apNew[iOld]
} else {
v17 = (**(**[3]uintptr)(__ccgo_up(bp + 8)))[iOld]
}
pOld2 = v17
cntOldNext = cntOldNext + (libc.Int32FromUint16((*TMemPage)(unsafe.Pointer(pOld2)).FnCell) + libc.Int32FromUint8((*TMemPage)(unsafe.Pointer(pOld2)).FnOverflow) + libc.BoolInt32(!(leafData != 0)))
}
if i == cntNew[iNew] {
iNew = iNew + 1
v1 = iNew
pNew1 = apNew[v1]
if !(leafData != 0) {
goto _23
}
}
/* Cell pCell is destined for new sibling page pNew. Originally, it
** was either part of sibling page iOld (possibly an overflow cell),
** or else the divider cell to the left of sibling page iOld. So,
** if sibling page iOld had the same page number as pNew, and if
** pCell really was a part of sibling page iOld (not a divider or
** overflow cell), we can skip updating the pointer map entries. */
if iOld >= nNew || (*TMemPage)(unsafe.Pointer(pNew1)).Fpgno != aPgno[iOld] || !(uint64(pCell) >= uint64((*TMemPage)(unsafe.Pointer(pOld2)).FaData) && uint64(pCell) < uint64((*TMemPage)(unsafe.Pointer(pOld2)).FaDataEnd)) {
if !(leafCorrection != 0) {
_ptrmapPut(tls, pBt, _sqlite3Get4byte(tls, pCell), uint8(PTRMAP_BTREE), (*TMemPage)(unsafe.Pointer(pNew1)).Fpgno, bp)
}
if libc.Int32FromUint16(_cachedCellSize(tls, bp+72, i)) > libc.Int32FromUint16((*TMemPage)(unsafe.Pointer(pNew1)).FminLocal) {
_ptrmapPutOvflPtr(tls, pNew1, pOld2, pCell, bp)
}
if **(**int32)(__ccgo_up(bp)) != 0 {
goto balance_cleanup
}
}
goto _23
_23:
;
i = i + 1
}
}
/* Insert new divider cells into pParent. */
i = 0
for {
if !(i < nNew-int32(1)) {
break
}
pNew2 = apNew[i]
j = cntNew[i]
pCell1 = **(**uintptr)(__ccgo_up((**(**TCellArray)(__ccgo_up(bp + 72))).FapCell + uintptr(j)*8))
sz2 = libc.Int32FromUint16(**(**Tu16)(__ccgo_up((**(**TCellArray)(__ccgo_up(bp + 72))).FszCell + uintptr(j)*2))) + libc.Int32FromUint16(leafCorrection)
pTemp1 = aOvflSpace + uintptr(iOvflSpace)
if !((*TMemPage)(unsafe.Pointer(pNew2)).Fleaf != 0) {
libc.X__builtin___memcpy_chk(tls, (*TMemPage)(unsafe.Pointer(pNew2)).FaData+8, pCell1, uint64(4), ^t__predefined_size_t(0))
} else {
if leafData != 0 {
j = j - 1
(*(*func(*libc.TLS, uintptr, uintptr, uintptr))(unsafe.Pointer(&struct{ uintptr }{(*TMemPage)(unsafe.Pointer(pNew2)).FxParseCell})))(tls, pNew2, **(**uintptr)(__ccgo_up((**(**TCellArray)(__ccgo_up(bp + 72))).FapCell + uintptr(j)*8)), bp+184)
pCell1 = pTemp1
sz2 = int32(4) + _sqlite3PutVarint(tls, pCell1+4, libc.Uint64FromInt64((**(**TCellInfo)(__ccgo_up(bp + 184))).FnKey))
pTemp1 = uintptr(0)
} else {
pCell1 = pCell1 - uintptr(4)
/* Obscure case for non-leaf-data trees: If the cell at pCell was
** previously stored on a leaf node, and its reported size was 4
** bytes, then it may actually be smaller than this
** (see btreeParseCellPtr(), 4 bytes is the minimum size of
** any cell). But it is important to pass the correct size to
** insertCell(), so reparse the cell now.
**
** This can only happen for b-trees used to evaluate "IN (SELECT ...)"
** and WITHOUT ROWID tables with exactly one column which is the
** primary key.
*/
if libc.Int32FromUint16(**(**Tu16)(__ccgo_up((**(**TCellArray)(__ccgo_up(bp + 72))).FszCell + uintptr(j)*2))) == int32(4) {
sz2 = libc.Int32FromUint16((*(*func(*libc.TLS, uintptr, uintptr) Tu16)(unsafe.Pointer(&struct{ uintptr }{(*TMemPage)(unsafe.Pointer(pParent)).FxCellSize})))(tls, pParent, pCell1))
}
}
}
iOvflSpace = iOvflSpace + sz2
k = 0
for {
if !(**(**int32)(__ccgo_up(bp + 72 + 80 + uintptr(k)*4)) <= j) {
break
}
goto _27
_27:
;
k = k + 1
}
pSrcEnd = **(**uintptr)(__ccgo_up(bp + 72 + 32 + uintptr(k)*8))
if uint64(pCell1) < uint64(pSrcEnd) && uint64(pCell1+uintptr(sz2)) > uint64(pSrcEnd) {
**(**int32)(__ccgo_up(bp)) = _sqlite3CorruptError(tls, int32(82108))
goto balance_cleanup
}
**(**int32)(__ccgo_up(bp)) = _insertCell(tls, pParent, nxDiv+i, pCell1, sz2, pTemp1, (*TMemPage)(unsafe.Pointer(pNew2)).Fpgno)
if **(**int32)(__ccgo_up(bp)) != SQLITE_OK {
goto balance_cleanup
}
goto _26
_26:
;
i = i + 1
}
/* Now update the actual sibling pages. The order in which they are updated
** is important, as this code needs to avoid disrupting any page from which
** cells may still to be read. In practice, this means:
**
** (1) If cells are moving left (from apNew[iPg] to apNew[iPg-1])
** then it is not safe to update page apNew[iPg] until after
** the left-hand sibling apNew[iPg-1] has been updated.
**
** (2) If cells are moving right (from apNew[iPg] to apNew[iPg+1])
** then it is not safe to update page apNew[iPg] until after
** the right-hand sibling apNew[iPg+1] has been updated.
**
** If neither of the above apply, the page is safe to update.
**
** The iPg value in the following loop starts at nNew-1 goes down
** to 0, then back up to nNew-1 again, thus making two passes over
** the pages. On the initial downward pass, only condition (1) above
** needs to be tested because (2) will always be true from the previous
** step. On the upward pass, both conditions are always true, so the
** upwards pass simply processes pages that were missed on the downward
** pass.
*/
i = int32(1) - nNew
for {
if !(i < nNew) {
break
}
if i < 0 {
v1 = -i
} else {
v1 = i
}
iPg = v1
if (**(**[5]Tu8)(__ccgo_up(bp + 60)))[iPg] != 0 {
goto _28
} /* Skip pages already processed */
if i >= 0 || cntOld[iPg-int32(1)] >= cntNew[iPg-int32(1)] {
/* Verify condition (1): If cells are moving left, update iPg
** only after iPg-1 has already been updated. */
/* Verify condition (2): If cells are moving right, update iPg
** only after iPg+1 has already been updated. */
if iPg == 0 {
v1 = libc.Int32FromInt32(0)
iOld1 = v1
iNew1 = v1
nNewCell = cntNew[0]
} else {
if iPg < nOld {
v1 = cntOld[iPg-int32(1)] + libc.BoolInt32(!(leafData != 0))
} else {
v1 = (**(**TCellArray)(__ccgo_up(bp + 72))).FnCell
}
iOld1 = v1
iNew1 = cntNew[iPg-int32(1)] + libc.BoolInt32(!(leafData != 0))
nNewCell = cntNew[iPg] - iNew1
}
**(**int32)(__ccgo_up(bp)) = _editPage(tls, apNew[iPg], iOld1, iNew1, nNewCell, bp+72)
if **(**int32)(__ccgo_up(bp)) != 0 {
goto balance_cleanup
}
(**(**[5]Tu8)(__ccgo_up(bp + 60)))[iPg] = (**(**[5]Tu8)(__ccgo_up(bp + 60)))[iPg] + 1
(*TMemPage)(unsafe.Pointer(apNew[iPg])).FnFree = usableSpace - (**(**[5]int32)(__ccgo_up(bp + 32)))[iPg]
}
goto _28
_28:
;
i = i + 1
}
/* All pages have been processed exactly once */
if isRoot != 0 && libc.Int32FromUint16((*TMemPage)(unsafe.Pointer(pParent)).FnCell) == 0 && libc.Int32FromUint8((*TMemPage)(unsafe.Pointer(pParent)).FhdrOffset) <= (*TMemPage)(unsafe.Pointer(apNew[0])).FnFree {
/* The root page of the b-tree now contains no cells. The only sibling
** page is the right-child of the parent. Copy the contents of the
** child page into the parent, decreasing the overall height of the
** b-tree structure by one. This is described as the "balance-shallower"
** sub-algorithm in some documentation.
**
** If this is an auto-vacuum database, the call to copyNodeContent()
** sets all pointer-map entries corresponding to database image pages
** for which the pointer is stored within the content being copied.
**
** It is critical that the child page be defragmented before being
** copied into the parent, because if the parent is page 1 then it will
** by smaller than the child due to the database header, and so all the
** free space needs to be up front.
*/
**(**int32)(__ccgo_up(bp)) = _defragmentPage(tls, apNew[0], -int32(1))
_copyNodeContent(tls, apNew[0], pParent, bp)
_freePage(tls, apNew[0], bp)
} else {
if (*TBtShared)(unsafe.Pointer(pBt)).FautoVacuum != 0 && !(leafCorrection != 0) {
/* Fix the pointer map entries associated with the right-child of each
** sibling page. All other pointer map entries have already been taken
** care of. */
i = 0
for {
if !(i < nNew) {
break
}
key = _sqlite3Get4byte(tls, (*TMemPage)(unsafe.Pointer(apNew[i])).FaData+8)
_ptrmapPut(tls, pBt, key, uint8(PTRMAP_BTREE), (*TMemPage)(unsafe.Pointer(apNew[i])).Fpgno, bp)
goto _32
_32:
;
i = i + 1
}
}
}
/* Free any old pages that were not reused as new pages.
*/
i = nNew
for {
if !(i < nOld) {
break
}
_freePage(tls, (**(**[3]uintptr)(__ccgo_up(bp + 8)))[i], bp)
goto _33
_33:
;
i = i + 1
}
/*
** Cleanup before returning.
*/
goto balance_cleanup
balance_cleanup:
;
_sqlite3DbFree(tls, uintptr(0), (**(**TCellArray)(__ccgo_up(bp + 72))).FapCell)
i = 0
for {
if !(i < nOld) {
break
}
_releasePage(tls, (**(**[3]uintptr)(__ccgo_up(bp + 8)))[i])
goto _34
_34:
;
i = i + 1
}
i = 0
for {
if !(i < nNew) {
break
}
_releasePage(tls, apNew[i])
goto _35
_35:
;
i = i + 1
}
return **(**int32)(__ccgo_up(bp))
}
// C documentation
//
// /*
// ** This function is used by both blob_open() and blob_reopen(). It seeks
// ** the b-tree cursor associated with blob handle p to point to row iRow.
// ** If successful, SQLITE_OK is returned and subsequent calls to
// ** sqlite3_blob_read() or sqlite3_blob_write() access the specified row.
// **
// ** If an error occurs, or if the specified row does not exist or does not
// ** contain a value of type TEXT or BLOB in the column nominated when the
// ** blob handle was opened, then an error code is returned and *pzErr may
// ** be set to point to a buffer containing an error message. It is the
// ** responsibility of the caller to free the error message buffer using
// ** sqlite3DbFree().
// **
// ** If an error does occur, then the b-tree cursor is closed. All subsequent
// ** calls to sqlite3_blob_read(), blob_write() or blob_reopen() will
// ** immediately return SQLITE_ABORT.
// */
func _blobSeekToRow(tls *libc.TLS, p uintptr, iRow Tsqlite3_int64, pzErr uintptr) (r int32) {
bp := tls.Alloc(16)
defer tls.Free(16)
var pC, v, zErr, v2, v3 uintptr
var rc int32
var type1 Tu32
var v1 uint32
_, _, _, _, _, _, _, _ = pC, rc, type1, v, zErr, v1, v2, v3 /* Error code */
zErr = uintptr(0) /* Error message */
v = (*TIncrblob)(unsafe.Pointer(p)).FpStmt
/* Set the value of register r[1] in the SQL statement to integer iRow.
** This is done directly as a performance optimization
*/
_sqlite3VdbeMemSetInt64(tls, (*TVdbe)(unsafe.Pointer(v)).FaMem+1*56, iRow)
/* If the statement has been run before (and is paused at the OP_ResultRow)
** then back it up to the point where it does the OP_NotExists. This could
** have been down with an extra OP_Goto, but simply setting the program
** counter is faster. */
if (*TVdbe)(unsafe.Pointer(v)).Fpc > int32(4) {
(*TVdbe)(unsafe.Pointer(v)).Fpc = int32(4)
rc = _sqlite3VdbeExec(tls, v)
} else {
rc = Xsqlite3_step(tls, (*TIncrblob)(unsafe.Pointer(p)).FpStmt)
}
if rc == int32(SQLITE_ROW) {
pC = **(**uintptr)(__ccgo_up((*TVdbe)(unsafe.Pointer(v)).FapCsr))
if libc.Int32FromUint16((*TVdbeCursor)(unsafe.Pointer(pC)).FnHdrParsed) > libc.Int32FromUint16((*TIncrblob)(unsafe.Pointer(p)).FiCol) {
v1 = *(*Tu32)(unsafe.Pointer(pC + 120 + uintptr((*TIncrblob)(unsafe.Pointer(p)).FiCol)*4))
} else {
v1 = uint32(0)
}
type1 = v1
if type1 < uint32(12) {
if type1 == uint32(0) {
v2 = __ccgo_ts + 1688
} else {
if type1 == uint32(7) {
v3 = __ccgo_ts + 6835
} else {
v3 = __ccgo_ts + 6840
}
v2 = v3
}
zErr = _sqlite3MPrintf(tls, (*TIncrblob)(unsafe.Pointer(p)).Fdb, __ccgo_ts+6848, libc.VaList(bp+8, v2))
rc = int32(SQLITE_ERROR)
Xsqlite3_finalize(tls, (*TIncrblob)(unsafe.Pointer(p)).FpStmt)
(*TIncrblob)(unsafe.Pointer(p)).FpStmt = uintptr(0)
} else {
(*TIncrblob)(unsafe.Pointer(p)).FiOffset = libc.Int32FromUint32(*(*Tu32)(unsafe.Pointer(pC + 120 + uintptr(libc.Int32FromUint16((*TIncrblob)(unsafe.Pointer(p)).FiCol)+int32((*TVdbeCursor)(unsafe.Pointer(pC)).FnField))*4)))
(*TIncrblob)(unsafe.Pointer(p)).FnByte = libc.Int32FromUint32(_sqlite3VdbeSerialTypeLen(tls, type1))
(*TIncrblob)(unsafe.Pointer(p)).FpCsr = *(*uintptr)(unsafe.Pointer(pC + 48))
_sqlite3BtreeIncrblobCursor(tls, (*TIncrblob)(unsafe.Pointer(p)).FpCsr)
}
}
if rc == int32(SQLITE_ROW) {
rc = SQLITE_OK
} else {
if (*TIncrblob)(unsafe.Pointer(p)).FpStmt != 0 {
rc = Xsqlite3_finalize(tls, (*TIncrblob)(unsafe.Pointer(p)).FpStmt)
(*TIncrblob)(unsafe.Pointer(p)).FpStmt = uintptr(0)
if rc == SQLITE_OK {
zErr = _sqlite3MPrintf(tls, (*TIncrblob)(unsafe.Pointer(p)).Fdb, __ccgo_ts+6877, libc.VaList(bp+8, iRow))
rc = int32(SQLITE_ERROR)
} else {
zErr = _sqlite3MPrintf(tls, (*TIncrblob)(unsafe.Pointer(p)).Fdb, __ccgo_ts+3944, libc.VaList(bp+8, Xsqlite3_errmsg(tls, (*TIncrblob)(unsafe.Pointer(p)).Fdb)))
}
}
}
**(**uintptr)(__ccgo_up(pzErr)) = zErr
return rc
}
// C documentation
//
// /* Overwrite content from pX into pDest. Only do the write if the
// ** content is different from what is already there.
// */
func _btreeOverwriteContent(tls *libc.TLS, pPage uintptr, pDest uintptr, pX uintptr, iOffset int32, iAmt int32) (r int32) {
var i, nData, rc, rc1, rc2 int32
_, _, _, _, _ = i, nData, rc, rc1, rc2
nData = (*TBtreePayload)(unsafe.Pointer(pX)).FnData - iOffset
if nData <= 0 {
i = 0
for {
if !(i < iAmt && libc.Int32FromUint8(**(**Tu8)(__ccgo_up(pDest + uintptr(i)))) == 0) {
break
}
goto _1
_1:
;
i = i + 1
}
if i < iAmt {
rc = _sqlite3PagerWrite(tls, (*TMemPage)(unsafe.Pointer(pPage)).FpDbPage)
if rc != 0 {
return rc
}
libc.X__builtin___memset_chk(tls, pDest+uintptr(i), 0, libc.Uint64FromInt32(iAmt-i), ^t__predefined_size_t(0))
}
} else {
if nData < iAmt {
/* Mixed read data and zeros at the end. Make a recursive call
** to write the zeros then fall through to write the real data */
rc1 = _btreeOverwriteContent(tls, pPage, pDest+uintptr(nData), pX, iOffset+nData, iAmt-nData)
if rc1 != 0 {
return rc1
}
iAmt = nData
}
if libc.Xmemcmp(tls, pDest, (*TBtreePayload)(unsafe.Pointer(pX)).FpData+uintptr(iOffset), libc.Uint64FromInt32(iAmt)) != 0 {
rc2 = _sqlite3PagerWrite(tls, (*TMemPage)(unsafe.Pointer(pPage)).FpDbPage)
if rc2 != 0 {
return rc2
}
/* In a corrupt database, it is possible for the source and destination
** buffers to overlap. This is harmless since the database is already
** corrupt but it does cause valgrind and ASAN warnings. So use
** memmove(). */
libc.X__builtin___memmove_chk(tls, pDest, (*TBtreePayload)(unsafe.Pointer(pX)).FpData+uintptr(iOffset), libc.Uint64FromInt32(iAmt), ^t__predefined_size_t(0))
}
}
return SQLITE_OK
}
// C documentation
//
// /*
// ** Check to see if the FROM clause term pFrom has table-valued function
// ** arguments. If it does, leave an error message in pParse and return
// ** non-zero, since pFrom is not allowed to be a table-valued function.
// */
func _cannotBeFunction(tls *libc.TLS, pParse uintptr, pFrom uintptr) (r int32) {
bp := tls.Alloc(16)
defer tls.Free(16)
if int32(*(*uint32)(unsafe.Pointer(pFrom + 24 + 4))&0x8>>3) != 0 {
_sqlite3ErrorMsg(tls, pParse, __ccgo_ts+21427, libc.VaList(bp+8, (*TSrcItem)(unsafe.Pointer(pFrom)).FzName))
return int32(1)
}
return 0
}
// C documentation
//
// /* The RFC-7539 ChaCha20 block function
// */
func _chacha_block(tls *libc.TLS, out uintptr, in uintptr) {
bp := tls.Alloc(64)
defer tls.Free(64)
var i int32
var _ /* x at bp+0 */ [16]Tu32
_ = i
libc.X__builtin___memcpy_chk(tls, bp, in, uint64(64), ^t__predefined_size_t(0))
i = 0
for {
if !(i < int32(10)) {
break
}
**(**Tu32)(__ccgo_up(bp)) += (**(**[16]Tu32)(__ccgo_up(bp)))[int32(4)]
**(**Tu32)(__ccgo_up(bp + 12*4)) ^= (**(**[16]Tu32)(__ccgo_up(bp)))[0]
(**(**[16]Tu32)(__ccgo_up(bp)))[int32(12)] = (**(**[16]Tu32)(__ccgo_up(bp)))[int32(12)]<>(libc.Int32FromInt32(32)-libc.Int32FromInt32(16))
**(**Tu32)(__ccgo_up(bp + 8*4)) += (**(**[16]Tu32)(__ccgo_up(bp)))[int32(12)]
**(**Tu32)(__ccgo_up(bp + 4*4)) ^= (**(**[16]Tu32)(__ccgo_up(bp)))[int32(8)]
(**(**[16]Tu32)(__ccgo_up(bp)))[int32(4)] = (**(**[16]Tu32)(__ccgo_up(bp)))[int32(4)]<>(libc.Int32FromInt32(32)-libc.Int32FromInt32(12))
**(**Tu32)(__ccgo_up(bp)) += (**(**[16]Tu32)(__ccgo_up(bp)))[int32(4)]
**(**Tu32)(__ccgo_up(bp + 12*4)) ^= (**(**[16]Tu32)(__ccgo_up(bp)))[0]
(**(**[16]Tu32)(__ccgo_up(bp)))[int32(12)] = (**(**[16]Tu32)(__ccgo_up(bp)))[int32(12)]<>(libc.Int32FromInt32(32)-libc.Int32FromInt32(8))
**(**Tu32)(__ccgo_up(bp + 8*4)) += (**(**[16]Tu32)(__ccgo_up(bp)))[int32(12)]
**(**Tu32)(__ccgo_up(bp + 4*4)) ^= (**(**[16]Tu32)(__ccgo_up(bp)))[int32(8)]
(**(**[16]Tu32)(__ccgo_up(bp)))[int32(4)] = (**(**[16]Tu32)(__ccgo_up(bp)))[int32(4)]<>(libc.Int32FromInt32(32)-libc.Int32FromInt32(7))
**(**Tu32)(__ccgo_up(bp + 1*4)) += (**(**[16]Tu32)(__ccgo_up(bp)))[int32(5)]
**(**Tu32)(__ccgo_up(bp + 13*4)) ^= (**(**[16]Tu32)(__ccgo_up(bp)))[int32(1)]
(**(**[16]Tu32)(__ccgo_up(bp)))[int32(13)] = (**(**[16]Tu32)(__ccgo_up(bp)))[int32(13)]<>(libc.Int32FromInt32(32)-libc.Int32FromInt32(16))
**(**Tu32)(__ccgo_up(bp + 9*4)) += (**(**[16]Tu32)(__ccgo_up(bp)))[int32(13)]
**(**Tu32)(__ccgo_up(bp + 5*4)) ^= (**(**[16]Tu32)(__ccgo_up(bp)))[int32(9)]
(**(**[16]Tu32)(__ccgo_up(bp)))[int32(5)] = (**(**[16]Tu32)(__ccgo_up(bp)))[int32(5)]<>(libc.Int32FromInt32(32)-libc.Int32FromInt32(12))
**(**Tu32)(__ccgo_up(bp + 1*4)) += (**(**[16]Tu32)(__ccgo_up(bp)))[int32(5)]
**(**Tu32)(__ccgo_up(bp + 13*4)) ^= (**(**[16]Tu32)(__ccgo_up(bp)))[int32(1)]
(**(**[16]Tu32)(__ccgo_up(bp)))[int32(13)] = (**(**[16]Tu32)(__ccgo_up(bp)))[int32(13)]<>(libc.Int32FromInt32(32)-libc.Int32FromInt32(8))
**(**Tu32)(__ccgo_up(bp + 9*4)) += (**(**[16]Tu32)(__ccgo_up(bp)))[int32(13)]
**(**Tu32)(__ccgo_up(bp + 5*4)) ^= (**(**[16]Tu32)(__ccgo_up(bp)))[int32(9)]
(**(**[16]Tu32)(__ccgo_up(bp)))[int32(5)] = (**(**[16]Tu32)(__ccgo_up(bp)))[int32(5)]<>(libc.Int32FromInt32(32)-libc.Int32FromInt32(7))
**(**Tu32)(__ccgo_up(bp + 2*4)) += (**(**[16]Tu32)(__ccgo_up(bp)))[int32(6)]
**(**Tu32)(__ccgo_up(bp + 14*4)) ^= (**(**[16]Tu32)(__ccgo_up(bp)))[int32(2)]
(**(**[16]Tu32)(__ccgo_up(bp)))[int32(14)] = (**(**[16]Tu32)(__ccgo_up(bp)))[int32(14)]<>(libc.Int32FromInt32(32)-libc.Int32FromInt32(16))
**(**Tu32)(__ccgo_up(bp + 10*4)) += (**(**[16]Tu32)(__ccgo_up(bp)))[int32(14)]
**(**Tu32)(__ccgo_up(bp + 6*4)) ^= (**(**[16]Tu32)(__ccgo_up(bp)))[int32(10)]
(**(**[16]Tu32)(__ccgo_up(bp)))[int32(6)] = (**(**[16]Tu32)(__ccgo_up(bp)))[int32(6)]<>(libc.Int32FromInt32(32)-libc.Int32FromInt32(12))
**(**Tu32)(__ccgo_up(bp + 2*4)) += (**(**[16]Tu32)(__ccgo_up(bp)))[int32(6)]
**(**Tu32)(__ccgo_up(bp + 14*4)) ^= (**(**[16]Tu32)(__ccgo_up(bp)))[int32(2)]
(**(**[16]Tu32)(__ccgo_up(bp)))[int32(14)] = (**(**[16]Tu32)(__ccgo_up(bp)))[int32(14)]<>(libc.Int32FromInt32(32)-libc.Int32FromInt32(8))
**(**Tu32)(__ccgo_up(bp + 10*4)) += (**(**[16]Tu32)(__ccgo_up(bp)))[int32(14)]
**(**Tu32)(__ccgo_up(bp + 6*4)) ^= (**(**[16]Tu32)(__ccgo_up(bp)))[int32(10)]
(**(**[16]Tu32)(__ccgo_up(bp)))[int32(6)] = (**(**[16]Tu32)(__ccgo_up(bp)))[int32(6)]<>(libc.Int32FromInt32(32)-libc.Int32FromInt32(7))
**(**Tu32)(__ccgo_up(bp + 3*4)) += (**(**[16]Tu32)(__ccgo_up(bp)))[int32(7)]
**(**Tu32)(__ccgo_up(bp + 15*4)) ^= (**(**[16]Tu32)(__ccgo_up(bp)))[int32(3)]
(**(**[16]Tu32)(__ccgo_up(bp)))[int32(15)] = (**(**[16]Tu32)(__ccgo_up(bp)))[int32(15)]<>(libc.Int32FromInt32(32)-libc.Int32FromInt32(16))
**(**Tu32)(__ccgo_up(bp + 11*4)) += (**(**[16]Tu32)(__ccgo_up(bp)))[int32(15)]
**(**Tu32)(__ccgo_up(bp + 7*4)) ^= (**(**[16]Tu32)(__ccgo_up(bp)))[int32(11)]
(**(**[16]Tu32)(__ccgo_up(bp)))[int32(7)] = (**(**[16]Tu32)(__ccgo_up(bp)))[int32(7)]<>(libc.Int32FromInt32(32)-libc.Int32FromInt32(12))
**(**Tu32)(__ccgo_up(bp + 3*4)) += (**(**[16]Tu32)(__ccgo_up(bp)))[int32(7)]
**(**Tu32)(__ccgo_up(bp + 15*4)) ^= (**(**[16]Tu32)(__ccgo_up(bp)))[int32(3)]
(**(**[16]Tu32)(__ccgo_up(bp)))[int32(15)] = (**(**[16]Tu32)(__ccgo_up(bp)))[int32(15)]<>(libc.Int32FromInt32(32)-libc.Int32FromInt32(8))
**(**Tu32)(__ccgo_up(bp + 11*4)) += (**(**[16]Tu32)(__ccgo_up(bp)))[int32(15)]
**(**Tu32)(__ccgo_up(bp + 7*4)) ^= (**(**[16]Tu32)(__ccgo_up(bp)))[int32(11)]
(**(**[16]Tu32)(__ccgo_up(bp)))[int32(7)] = (**(**[16]Tu32)(__ccgo_up(bp)))[int32(7)]<>(libc.Int32FromInt32(32)-libc.Int32FromInt32(7))
**(**Tu32)(__ccgo_up(bp)) += (**(**[16]Tu32)(__ccgo_up(bp)))[int32(5)]
**(**Tu32)(__ccgo_up(bp + 15*4)) ^= (**(**[16]Tu32)(__ccgo_up(bp)))[0]
(**(**[16]Tu32)(__ccgo_up(bp)))[int32(15)] = (**(**[16]Tu32)(__ccgo_up(bp)))[int32(15)]<>(libc.Int32FromInt32(32)-libc.Int32FromInt32(16))
**(**Tu32)(__ccgo_up(bp + 10*4)) += (**(**[16]Tu32)(__ccgo_up(bp)))[int32(15)]
**(**Tu32)(__ccgo_up(bp + 5*4)) ^= (**(**[16]Tu32)(__ccgo_up(bp)))[int32(10)]
(**(**[16]Tu32)(__ccgo_up(bp)))[int32(5)] = (**(**[16]Tu32)(__ccgo_up(bp)))[int32(5)]<>(libc.Int32FromInt32(32)-libc.Int32FromInt32(12))
**(**Tu32)(__ccgo_up(bp)) += (**(**[16]Tu32)(__ccgo_up(bp)))[int32(5)]
**(**Tu32)(__ccgo_up(bp + 15*4)) ^= (**(**[16]Tu32)(__ccgo_up(bp)))[0]
(**(**[16]Tu32)(__ccgo_up(bp)))[int32(15)] = (**(**[16]Tu32)(__ccgo_up(bp)))[int32(15)]<>(libc.Int32FromInt32(32)-libc.Int32FromInt32(8))
**(**Tu32)(__ccgo_up(bp + 10*4)) += (**(**[16]Tu32)(__ccgo_up(bp)))[int32(15)]
**(**Tu32)(__ccgo_up(bp + 5*4)) ^= (**(**[16]Tu32)(__ccgo_up(bp)))[int32(10)]
(**(**[16]Tu32)(__ccgo_up(bp)))[int32(5)] = (**(**[16]Tu32)(__ccgo_up(bp)))[int32(5)]<>(libc.Int32FromInt32(32)-libc.Int32FromInt32(7))
**(**Tu32)(__ccgo_up(bp + 1*4)) += (**(**[16]Tu32)(__ccgo_up(bp)))[int32(6)]
**(**Tu32)(__ccgo_up(bp + 12*4)) ^= (**(**[16]Tu32)(__ccgo_up(bp)))[int32(1)]
(**(**[16]Tu32)(__ccgo_up(bp)))[int32(12)] = (**(**[16]Tu32)(__ccgo_up(bp)))[int32(12)]<>(libc.Int32FromInt32(32)-libc.Int32FromInt32(16))
**(**Tu32)(__ccgo_up(bp + 11*4)) += (**(**[16]Tu32)(__ccgo_up(bp)))[int32(12)]
**(**Tu32)(__ccgo_up(bp + 6*4)) ^= (**(**[16]Tu32)(__ccgo_up(bp)))[int32(11)]
(**(**[16]Tu32)(__ccgo_up(bp)))[int32(6)] = (**(**[16]Tu32)(__ccgo_up(bp)))[int32(6)]<>(libc.Int32FromInt32(32)-libc.Int32FromInt32(12))
**(**Tu32)(__ccgo_up(bp + 1*4)) += (**(**[16]Tu32)(__ccgo_up(bp)))[int32(6)]
**(**Tu32)(__ccgo_up(bp + 12*4)) ^= (**(**[16]Tu32)(__ccgo_up(bp)))[int32(1)]
(**(**[16]Tu32)(__ccgo_up(bp)))[int32(12)] = (**(**[16]Tu32)(__ccgo_up(bp)))[int32(12)]<>(libc.Int32FromInt32(32)-libc.Int32FromInt32(8))
**(**Tu32)(__ccgo_up(bp + 11*4)) += (**(**[16]Tu32)(__ccgo_up(bp)))[int32(12)]
**(**Tu32)(__ccgo_up(bp + 6*4)) ^= (**(**[16]Tu32)(__ccgo_up(bp)))[int32(11)]
(**(**[16]Tu32)(__ccgo_up(bp)))[int32(6)] = (**(**[16]Tu32)(__ccgo_up(bp)))[int32(6)]<>(libc.Int32FromInt32(32)-libc.Int32FromInt32(7))
**(**Tu32)(__ccgo_up(bp + 2*4)) += (**(**[16]Tu32)(__ccgo_up(bp)))[int32(7)]
**(**Tu32)(__ccgo_up(bp + 13*4)) ^= (**(**[16]Tu32)(__ccgo_up(bp)))[int32(2)]
(**(**[16]Tu32)(__ccgo_up(bp)))[int32(13)] = (**(**[16]Tu32)(__ccgo_up(bp)))[int32(13)]<>(libc.Int32FromInt32(32)-libc.Int32FromInt32(16))
**(**Tu32)(__ccgo_up(bp + 8*4)) += (**(**[16]Tu32)(__ccgo_up(bp)))[int32(13)]
**(**Tu32)(__ccgo_up(bp + 7*4)) ^= (**(**[16]Tu32)(__ccgo_up(bp)))[int32(8)]
(**(**[16]Tu32)(__ccgo_up(bp)))[int32(7)] = (**(**[16]Tu32)(__ccgo_up(bp)))[int32(7)]<>(libc.Int32FromInt32(32)-libc.Int32FromInt32(12))
**(**Tu32)(__ccgo_up(bp + 2*4)) += (**(**[16]Tu32)(__ccgo_up(bp)))[int32(7)]
**(**Tu32)(__ccgo_up(bp + 13*4)) ^= (**(**[16]Tu32)(__ccgo_up(bp)))[int32(2)]
(**(**[16]Tu32)(__ccgo_up(bp)))[int32(13)] = (**(**[16]Tu32)(__ccgo_up(bp)))[int32(13)]<>(libc.Int32FromInt32(32)-libc.Int32FromInt32(8))
**(**Tu32)(__ccgo_up(bp + 8*4)) += (**(**[16]Tu32)(__ccgo_up(bp)))[int32(13)]
**(**Tu32)(__ccgo_up(bp + 7*4)) ^= (**(**[16]Tu32)(__ccgo_up(bp)))[int32(8)]
(**(**[16]Tu32)(__ccgo_up(bp)))[int32(7)] = (**(**[16]Tu32)(__ccgo_up(bp)))[int32(7)]<>(libc.Int32FromInt32(32)-libc.Int32FromInt32(7))
**(**Tu32)(__ccgo_up(bp + 3*4)) += (**(**[16]Tu32)(__ccgo_up(bp)))[int32(4)]
**(**Tu32)(__ccgo_up(bp + 14*4)) ^= (**(**[16]Tu32)(__ccgo_up(bp)))[int32(3)]
(**(**[16]Tu32)(__ccgo_up(bp)))[int32(14)] = (**(**[16]Tu32)(__ccgo_up(bp)))[int32(14)]<>(libc.Int32FromInt32(32)-libc.Int32FromInt32(16))
**(**Tu32)(__ccgo_up(bp + 9*4)) += (**(**[16]Tu32)(__ccgo_up(bp)))[int32(14)]
**(**Tu32)(__ccgo_up(bp + 4*4)) ^= (**(**[16]Tu32)(__ccgo_up(bp)))[int32(9)]
(**(**[16]Tu32)(__ccgo_up(bp)))[int32(4)] = (**(**[16]Tu32)(__ccgo_up(bp)))[int32(4)]<>(libc.Int32FromInt32(32)-libc.Int32FromInt32(12))
**(**Tu32)(__ccgo_up(bp + 3*4)) += (**(**[16]Tu32)(__ccgo_up(bp)))[int32(4)]
**(**Tu32)(__ccgo_up(bp + 14*4)) ^= (**(**[16]Tu32)(__ccgo_up(bp)))[int32(3)]
(**(**[16]Tu32)(__ccgo_up(bp)))[int32(14)] = (**(**[16]Tu32)(__ccgo_up(bp)))[int32(14)]<>(libc.Int32FromInt32(32)-libc.Int32FromInt32(8))
**(**Tu32)(__ccgo_up(bp + 9*4)) += (**(**[16]Tu32)(__ccgo_up(bp)))[int32(14)]
**(**Tu32)(__ccgo_up(bp + 4*4)) ^= (**(**[16]Tu32)(__ccgo_up(bp)))[int32(9)]
(**(**[16]Tu32)(__ccgo_up(bp)))[int32(4)] = (**(**[16]Tu32)(__ccgo_up(bp)))[int32(4)]<>(libc.Int32FromInt32(32)-libc.Int32FromInt32(7))
goto _1
_1:
;
i = i + 1
}
i = 0
for {
if !(i < int32(16)) {
break
}
**(**Tu32)(__ccgo_up(out + uintptr(i)*4)) = (**(**[16]Tu32)(__ccgo_up(bp)))[i] + **(**Tu32)(__ccgo_up(in + uintptr(i)*4))
goto _2
_2:
;
i = i + 1
}
}
// C documentation
//
// /*
// ** Append a message to the error message string.
// */
func _checkAppendMsg(tls *libc.TLS, pCheck uintptr, zFormat uintptr, va uintptr) {
bp := tls.Alloc(32)
defer tls.Free(32)
var ap Tva_list
_ = ap
_checkProgress(tls, pCheck)
if !((*TIntegrityCk)(unsafe.Pointer(pCheck)).FmxErr != 0) {
return
}
(*TIntegrityCk)(unsafe.Pointer(pCheck)).FmxErr = (*TIntegrityCk)(unsafe.Pointer(pCheck)).FmxErr - 1
(*TIntegrityCk)(unsafe.Pointer(pCheck)).FnErr = (*TIntegrityCk)(unsafe.Pointer(pCheck)).FnErr + 1
ap = va
if (*TIntegrityCk)(unsafe.Pointer(pCheck)).FerrMsg.FnChar != 0 {
Xsqlite3_str_append(tls, pCheck+72, __ccgo_ts+4700, int32(1))
}
if (*TIntegrityCk)(unsafe.Pointer(pCheck)).FzPfx != 0 {
Xsqlite3_str_appendf(tls, pCheck+72, (*TIntegrityCk)(unsafe.Pointer(pCheck)).FzPfx, libc.VaList(bp+8, (*TIntegrityCk)(unsafe.Pointer(pCheck)).Fv0, (*TIntegrityCk)(unsafe.Pointer(pCheck)).Fv1, (*TIntegrityCk)(unsafe.Pointer(pCheck)).Fv2))
}
Xsqlite3_str_vappendf(tls, pCheck+72, zFormat, ap)
_ = ap
if libc.Int32FromUint8((*TIntegrityCk)(unsafe.Pointer(pCheck)).FerrMsg.FaccError) == int32(SQLITE_NOMEM) {
_checkOom(tls, pCheck)
}
}
// C documentation
//
// /*
// ** Check the integrity of the freelist or of an overflow page list.
// ** Verify that the number of pages on the list is N.
// */
func _checkList(tls *libc.TLS, pCheck uintptr, isFreeList int32, iPage TPgno, N Tu32) {
bp := tls.Alloc(48)
defer tls.Free(48)
var expected, n Tu32
var i, nErrAtStart int32
var iFreePage TPgno
var pOvflData, v2 uintptr
var _ /* pOvflPage at bp+0 */ uintptr
_, _, _, _, _, _, _ = expected, i, iFreePage, n, nErrAtStart, pOvflData, v2
expected = N
nErrAtStart = (*TIntegrityCk)(unsafe.Pointer(pCheck)).FnErr
for iPage != uint32(0) && (*TIntegrityCk)(unsafe.Pointer(pCheck)).FmxErr != 0 {
if _checkRef(tls, pCheck, iPage) != 0 {
break
}
N = N - 1
if _sqlite3PagerGet(tls, (*TIntegrityCk)(unsafe.Pointer(pCheck)).FpPager, iPage, bp, 0) != 0 {
_checkAppendMsg(tls, pCheck, __ccgo_ts+4833, libc.VaList(bp+16, iPage))
break
}
pOvflData = _sqlite3PagerGetData(tls, **(**uintptr)(__ccgo_up(bp)))
if isFreeList != 0 {
n = _sqlite3Get4byte(tls, pOvflData+4)
if (*TBtShared)(unsafe.Pointer((*TIntegrityCk)(unsafe.Pointer(pCheck)).FpBt)).FautoVacuum != 0 {
_checkPtrmap(tls, pCheck, iPage, uint8(PTRMAP_FREEPAGE), uint32(0))
}
if n > (*TBtShared)(unsafe.Pointer((*TIntegrityCk)(unsafe.Pointer(pCheck)).FpBt)).FusableSize/uint32(4)-uint32(2) {
_checkAppendMsg(tls, pCheck, __ccgo_ts+4855, libc.VaList(bp+16, iPage))
N = N - 1
} else {
i = 0
for {
if !(i < libc.Int32FromUint32(n)) {
break
}
iFreePage = _sqlite3Get4byte(tls, pOvflData+uintptr(int32(8)+i*int32(4)))
if (*TBtShared)(unsafe.Pointer((*TIntegrityCk)(unsafe.Pointer(pCheck)).FpBt)).FautoVacuum != 0 {
_checkPtrmap(tls, pCheck, iFreePage, uint8(PTRMAP_FREEPAGE), uint32(0))
}
_checkRef(tls, pCheck, iFreePage)
goto _1
_1:
;
i = i + 1
}
N = N - n
}
} else {
/* If this database supports auto-vacuum and iPage is not the last
** page in this overflow list, check that the pointer-map entry for
** the following page matches iPage.
*/
if (*TBtShared)(unsafe.Pointer((*TIntegrityCk)(unsafe.Pointer(pCheck)).FpBt)).FautoVacuum != 0 && N > uint32(0) {
i = libc.Int32FromUint32(_sqlite3Get4byte(tls, pOvflData))
_checkPtrmap(tls, pCheck, libc.Uint32FromInt32(i), uint8(PTRMAP_OVERFLOW2), iPage)
}
}
iPage = _sqlite3Get4byte(tls, pOvflData)
_sqlite3PagerUnref(tls, **(**uintptr)(__ccgo_up(bp)))
}
if N != 0 && nErrAtStart == (*TIntegrityCk)(unsafe.Pointer(pCheck)).FnErr {
if isFreeList != 0 {
v2 = __ccgo_ts + 4894
} else {
v2 = __ccgo_ts + 4899
}
_checkAppendMsg(tls, pCheck, __ccgo_ts+4920, libc.VaList(bp+16, v2, expected-N, expected))
}
}
// C documentation
//
// /*
// ** Check that the entry in the pointer-map for page iChild maps to
// ** page iParent, pointer type ptrType. If not, append an error message
// ** to pCheck.
// */
func _checkPtrmap(tls *libc.TLS, pCheck uintptr, iChild TPgno, eType Tu8, iParent TPgno) {
bp := tls.Alloc(64)
defer tls.Free(64)
var rc int32
var _ /* ePtrmapType at bp+0 */ Tu8
var _ /* iPtrmapParent at bp+4 */ TPgno
_ = rc
rc = _ptrmapGet(tls, (*TIntegrityCk)(unsafe.Pointer(pCheck)).FpBt, iChild, bp, bp+4)
if rc != SQLITE_OK {
if rc == int32(SQLITE_NOMEM) || rc == libc.Int32FromInt32(SQLITE_IOERR)|libc.Int32FromInt32(12)<zErrMsg.
// ** Return 1 if there are 2 or more references to the page and 0 if
// ** if this is the first reference to the page.
// **
// ** Also check that the page number is in bounds.
// */
func _checkRef(tls *libc.TLS, pCheck uintptr, iPage TPgno) (r int32) {
bp := tls.Alloc(16)
defer tls.Free(16)
if iPage > (*TIntegrityCk)(unsafe.Pointer(pCheck)).FnCkPage || iPage == uint32(0) {
_checkAppendMsg(tls, pCheck, __ccgo_ts+4702, libc.VaList(bp+8, iPage))
return int32(1)
}
if _getPageReferenced(tls, pCheck, iPage) != 0 {
_checkAppendMsg(tls, pCheck, __ccgo_ts+4725, libc.VaList(bp+8, iPage))
return int32(1)
}
_setPageReferenced(tls, pCheck, iPage)
return 0
}
// C documentation
//
// /*
// ** Do various sanity checks on a single page of a tree. Return
// ** the tree depth. Root pages return 0. Parents of root pages
// ** return 1, and so forth.
// **
// ** These checks are done:
// **
// ** 1. Make sure that cells and freeblocks do not overlap
// ** but combine to completely cover the page.
// ** 2. Make sure integer cell keys are in order.
// ** 3. Check the integrity of overflow pages.
// ** 4. Recursively call checkTreePage on all children.
// ** 5. Verify that the depth of all children is the same.
// */
func _checkTreePage(tls *libc.TLS, pCheck uintptr, iPage TPgno, piMinKey uintptr, _maxKey Ti64) (r int32) {
bp := tls.Alloc(80)
defer tls.Free(80)
*(*Ti64)(unsafe.Pointer(bp)) = _maxKey
var cellStart, d2, depth, doCoverageCheck, hdr, i, j, keyCanBeEqual, nCell, nFrag, pgno, rc, saved_v1, saved_v2, size1, v1 int32
var contentOffset, nPage, pc, prev, size, usableSize Tu32
var data, heap, pBt, pCell, pCellIdx, saved_zPfx uintptr
var pgnoOvfl TPgno
var savedIsInit Tu8
var _ /* info at bp+24 */ TCellInfo
var _ /* pPage at bp+8 */ uintptr
var _ /* x at bp+16 */ Tu32
_, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _ = cellStart, contentOffset, d2, data, depth, doCoverageCheck, hdr, heap, i, j, keyCanBeEqual, nCell, nFrag, nPage, pBt, pCell, pCellIdx, pc, pgno, pgnoOvfl, prev, rc, savedIsInit, saved_v1, saved_v2, saved_zPfx, size, size1, usableSize, v1
**(**uintptr)(__ccgo_up(bp + 8)) = uintptr(0) /* Result code from subroutine call */
depth = -int32(1) /* Number of cells */
doCoverageCheck = int32(1) /* True if cell coverage checking should be done */
keyCanBeEqual = int32(1) /* Offset to the start of the cell content area */
heap = uintptr(0)
prev = uint32(0) /* Next and previous entry on the min-heap */
saved_zPfx = (*TIntegrityCk)(unsafe.Pointer(pCheck)).FzPfx
saved_v1 = libc.Int32FromUint32((*TIntegrityCk)(unsafe.Pointer(pCheck)).Fv1)
saved_v2 = (*TIntegrityCk)(unsafe.Pointer(pCheck)).Fv2
savedIsInit = uint8(0)
/* Check that the page exists
*/
_checkProgress(tls, pCheck)
if (*TIntegrityCk)(unsafe.Pointer(pCheck)).FmxErr == 0 {
goto end_of_check
}
pBt = (*TIntegrityCk)(unsafe.Pointer(pCheck)).FpBt
usableSize = (*TBtShared)(unsafe.Pointer(pBt)).FusableSize
if iPage == uint32(0) {
return 0
}
if _checkRef(tls, pCheck, iPage) != 0 {
return 0
}
(*TIntegrityCk)(unsafe.Pointer(pCheck)).FzPfx = __ccgo_ts + 4946
(*TIntegrityCk)(unsafe.Pointer(pCheck)).Fv1 = iPage
v1 = _btreeGetPage(tls, pBt, iPage, bp+8, 0)
rc = v1
if v1 != 0 {
_checkAppendMsg(tls, pCheck, __ccgo_ts+4964, libc.VaList(bp+56, rc))
if rc == libc.Int32FromInt32(SQLITE_IOERR)|libc.Int32FromInt32(12)<= 0 && (*TIntegrityCk)(unsafe.Pointer(pCheck)).FmxErr != 0) {
break
}
/* Check cell size */
(*TIntegrityCk)(unsafe.Pointer(pCheck)).Fv2 = i
pc = libc.Uint32FromInt32(libc.Int32FromUint8(**(**Tu8)(__ccgo_up(pCellIdx)))< usableSize-uint32(4) {
_checkAppendMsg(tls, pCheck, __ccgo_ts+5118, libc.VaList(bp+56, pc, contentOffset, usableSize-uint32(4)))
doCoverageCheck = 0
goto _4
}
pCell = data + uintptr(pc)
(*(*func(*libc.TLS, uintptr, uintptr, uintptr))(unsafe.Pointer(&struct{ uintptr }{(*TMemPage)(unsafe.Pointer(**(**uintptr)(__ccgo_up(bp + 8)))).FxParseCell})))(tls, **(**uintptr)(__ccgo_up(bp + 8)), pCell, bp+24)
if pc+uint32((**(**TCellInfo)(__ccgo_up(bp + 24))).FnSize) > usableSize {
_checkAppendMsg(tls, pCheck, __ccgo_ts+5148, 0)
doCoverageCheck = 0
goto _4
}
/* Check for integer primary key out of range */
if (*TMemPage)(unsafe.Pointer(**(**uintptr)(__ccgo_up(bp + 8)))).FintKey != 0 {
if keyCanBeEqual != 0 {
v1 = libc.BoolInt32((**(**TCellInfo)(__ccgo_up(bp + 24))).FnKey > **(**Ti64)(__ccgo_up(bp)))
} else {
v1 = libc.BoolInt32((**(**TCellInfo)(__ccgo_up(bp + 24))).FnKey >= **(**Ti64)(__ccgo_up(bp)))
}
if v1 != 0 {
_checkAppendMsg(tls, pCheck, __ccgo_ts+5172, libc.VaList(bp+56, (**(**TCellInfo)(__ccgo_up(bp + 24))).FnKey))
}
**(**Ti64)(__ccgo_up(bp)) = (**(**TCellInfo)(__ccgo_up(bp + 24))).FnKey
keyCanBeEqual = 0 /* Only the first key on the page may ==maxKey */
}
/* Check the content overflow list */
if (**(**TCellInfo)(__ccgo_up(bp + 24))).FnPayload > uint32((**(**TCellInfo)(__ccgo_up(bp + 24))).FnLocal) { /* First page of the overflow chain */
nPage = ((**(**TCellInfo)(__ccgo_up(bp + 24))).FnPayload - uint32((**(**TCellInfo)(__ccgo_up(bp + 24))).FnLocal) + usableSize - uint32(5)) / (usableSize - uint32(4))
pgnoOvfl = _sqlite3Get4byte(tls, pCell+uintptr(libc.Int32FromUint16((**(**TCellInfo)(__ccgo_up(bp + 24))).FnSize)-int32(4)))
if (*TBtShared)(unsafe.Pointer(pBt)).FautoVacuum != 0 {
_checkPtrmap(tls, pCheck, pgnoOvfl, uint8(PTRMAP_OVERFLOW1), iPage)
}
_checkList(tls, pCheck, 0, pgnoOvfl, nPage)
}
if !((*TMemPage)(unsafe.Pointer(**(**uintptr)(__ccgo_up(bp + 8)))).Fleaf != 0) {
/* Check sanity of left child page for internal pages */
pgno = libc.Int32FromUint32(_sqlite3Get4byte(tls, pCell))
if (*TBtShared)(unsafe.Pointer(pBt)).FautoVacuum != 0 {
_checkPtrmap(tls, pCheck, libc.Uint32FromInt32(pgno), uint8(PTRMAP_BTREE), iPage)
}
d2 = _checkTreePage(tls, pCheck, libc.Uint32FromInt32(pgno), bp, **(**Ti64)(__ccgo_up(bp)))
keyCanBeEqual = 0
if d2 != depth {
_checkAppendMsg(tls, pCheck, __ccgo_ts+5196, 0)
depth = d2
}
} else {
/* Populate the coverage-checking heap for leaf pages */
_btreeHeapInsert(tls, heap, pc< 0 {
/* For leaf pages, the min-heap has already been initialized and the
** cells have already been inserted. But for internal pages, that has
** not yet been done, so do it now */
if !((*TMemPage)(unsafe.Pointer(**(**uintptr)(__ccgo_up(bp + 8)))).Fleaf != 0) {
heap = (*TIntegrityCk)(unsafe.Pointer(pCheck)).Fheap
**(**Tu32)(__ccgo_up(heap)) = uint32(0)
i = nCell - int32(1)
for {
if !(i >= 0) {
break
}
pc = libc.Uint32FromInt32(libc.Int32FromUint8(**(**Tu8)(__ccgo_up(data + uintptr(cellStart+i*int32(2)))))< 0 {
/* Enforced by btreeComputeFreeSpace() */
size1 = libc.Int32FromUint8(**(**Tu8)(__ccgo_up(data + uintptr(i+int32(2)))))<= **(**Tu32)(__ccgo_up(bp + 16))>>libc.Int32FromInt32(16) {
_checkAppendMsg(tls, pCheck, __ccgo_ts+5221, libc.VaList(bp+56, **(**Tu32)(__ccgo_up(bp + 16))>>int32(16), iPage))
break
} else {
nFrag = libc.Int32FromUint32(uint32(nFrag) + (**(**Tu32)(__ccgo_up(bp + 16))>>libc.Int32FromInt32(16) - prev&libc.Uint32FromInt32(0xffff) - libc.Uint32FromInt32(1)))
prev = **(**Tu32)(__ccgo_up(bp + 16))
}
}
nFrag = libc.Int32FromUint32(uint32(nFrag) + (usableSize - prev&libc.Uint32FromInt32(0xffff) - libc.Uint32FromInt32(1)))
/* EVIDENCE-OF: R-43263-13491 The total number of bytes in all fragments
** is stored in the fifth field of the b-tree page header.
** EVIDENCE-OF: R-07161-27322 The one-byte integer at offset 7 gives the
** number of fragmented free bytes within the cell content area.
*/
if **(**Tu32)(__ccgo_up(heap)) == uint32(0) && nFrag != libc.Int32FromUint8(**(**Tu8)(__ccgo_up(data + uintptr(hdr+int32(7))))) {
_checkAppendMsg(tls, pCheck, __ccgo_ts+5258, libc.VaList(bp+56, nFrag, libc.Int32FromUint8(**(**Tu8)(__ccgo_up(data + uintptr(hdr+int32(7))))), iPage))
}
}
goto end_of_check
end_of_check:
;
if !(doCoverageCheck != 0) {
(*TMemPage)(unsafe.Pointer(**(**uintptr)(__ccgo_up(bp + 8)))).FisInit = savedIsInit
}
_releasePage(tls, **(**uintptr)(__ccgo_up(bp + 8)))
(*TIntegrityCk)(unsafe.Pointer(pCheck)).FzPfx = saved_zPfx
(*TIntegrityCk)(unsafe.Pointer(pCheck)).Fv1 = libc.Uint32FromInt32(saved_v1)
(*TIntegrityCk)(unsafe.Pointer(pCheck)).Fv2 = saved_v2
return depth + int32(1)
}
// C documentation
//
// /*
// ** This function performs the parts of the "close file" operation
// ** common to all locking schemes. It closes the directory and file
// ** handles, if they are valid, and sets all fields of the unixFile
// ** structure to 0.
// **
// ** It is *not* necessary to hold the mutex when this routine is called,
// ** even on VxWorks. A mutex will be acquired on VxWorks by the
// ** vxworksReleaseFileId() routine.
// */
func _closeUnixFile(tls *libc.TLS, id uintptr) (r int32) {
var pFile uintptr
_ = pFile
pFile = id
_unixUnmapfile(tls, pFile)
if (*TunixFile)(unsafe.Pointer(pFile)).Fh >= 0 {
_robust_close(tls, pFile, (*TunixFile)(unsafe.Pointer(pFile)).Fh, int32(42509))
(*TunixFile)(unsafe.Pointer(pFile)).Fh = -int32(1)
}
Xsqlite3_free(tls, (*TunixFile)(unsafe.Pointer(pFile)).FpPreallocatedUnused)
libc.X__builtin___memset_chk(tls, pFile, 0, uint64(128), ^t__predefined_size_t(0))
return SQLITE_OK
}
// C documentation
//
// /*
// ** This procedure generates VDBE code for a single invocation of either the
// ** sqlite_detach() or sqlite_attach() SQL user functions.
// */
func _codeAttach(tls *libc.TLS, pParse uintptr, type1 int32, pFunc uintptr, pAuthArg uintptr, pFilename uintptr, pDbname uintptr, pKey uintptr) {
bp := tls.Alloc(64)
defer tls.Free(64)
var db, v, zAuthArg uintptr
var rc, regArgs int32
var _ /* sName at bp+0 */ TNameContext
_, _, _, _, _ = db, rc, regArgs, v, zAuthArg
db = (*TParse)(unsafe.Pointer(pParse)).Fdb
if SQLITE_OK != _sqlite3ReadSchema(tls, pParse) {
goto attach_end
}
if (*TParse)(unsafe.Pointer(pParse)).FnErr != 0 {
goto attach_end
}
libc.X__builtin___memset_chk(tls, bp, 0, uint64(56), ^t__predefined_size_t(0))
(**(**TNameContext)(__ccgo_up(bp))).FpParse = pParse
if SQLITE_OK != _resolveAttachExpr(tls, bp, pFilename) || SQLITE_OK != _resolveAttachExpr(tls, bp, pDbname) || SQLITE_OK != _resolveAttachExpr(tls, bp, pKey) {
goto attach_end
}
if pAuthArg != 0 {
if libc.Int32FromUint8((*TExpr)(unsafe.Pointer(pAuthArg)).Fop) == int32(TK_STRING) {
zAuthArg = *(*uintptr)(unsafe.Pointer(pAuthArg + 8))
} else {
zAuthArg = uintptr(0)
}
rc = _sqlite3AuthCheck(tls, pParse, type1, zAuthArg, uintptr(0), uintptr(0))
if rc != SQLITE_OK {
goto attach_end
}
}
v = _sqlite3GetVdbe(tls, pParse)
regArgs = _sqlite3GetTempRange(tls, pParse, int32(4))
_sqlite3ExprCode(tls, pParse, pFilename, regArgs)
_sqlite3ExprCode(tls, pParse, pDbname, regArgs+int32(1))
_sqlite3ExprCode(tls, pParse, pKey, regArgs+int32(2))
if v != 0 {
_sqlite3VdbeAddFunctionCall(tls, pParse, 0, regArgs+int32(3)-int32((*TFuncDef)(unsafe.Pointer(pFunc)).FnArg), regArgs+int32(3), int32((*TFuncDef)(unsafe.Pointer(pFunc)).FnArg), pFunc, 0)
/* Code an OP_Expire. For an ATTACH statement, set P1 to true (expire this
** statement only). For DETACH, set it to false (expire all existing
** statements).
*/
_sqlite3VdbeAddOp1(tls, v, int32(OP_Expire), libc.BoolInt32(type1 == int32(SQLITE_ATTACH)))
}
goto attach_end
attach_end:
;
_sqlite3ExprDelete(tls, db, pFilename)
_sqlite3ExprDelete(tls, db, pDbname)
_sqlite3ExprDelete(tls, db, pKey)
}
// C documentation
//
// /*
// ** Generate an instruction that will put the integer describe by
// ** text z[0..n-1] into register iMem.
// **
// ** Expr.u.zToken is always UTF8 and zero-terminated.
// */
func _codeInteger(tls *libc.TLS, pParse uintptr, pExpr uintptr, negFlag int32, iMem int32) {
bp := tls.Alloc(32)
defer tls.Free(32)
var c, i int32
var v, z, v1 uintptr
var v2 int64
var _ /* value at bp+0 */ Ti64
_, _, _, _, _, _ = c, i, v, z, v1, v2
v = (*TParse)(unsafe.Pointer(pParse)).FpVdbe
if (*TExpr)(unsafe.Pointer(pExpr)).Fflags&uint32(EP_IntValue) != 0 {
i = *(*int32)(unsafe.Pointer(&(*TExpr)(unsafe.Pointer(pExpr)).Fu))
if negFlag != 0 {
i = -i
}
_sqlite3VdbeAddOp2(tls, v, int32(OP_Integer), i, iMem)
} else {
z = *(*uintptr)(unsafe.Pointer(pExpr + 8))
c = _sqlite3DecOrHexToI64(tls, z, bp)
if c == int32(3) && !(negFlag != 0) || c == int32(2) || negFlag != 0 && **(**Ti64)(__ccgo_up(bp)) == int64(-libc.Int32FromInt32(1))-(libc.Int64FromUint32(0xffffffff)|libc.Int64FromInt32(0x7fffffff)<>3)) != 0) {
/* This RETURNING trigger must be for a different statement as
** this statement lacks a RETURNING clause. */
return
}
pReturning = (*(*struct {
FpReturning uintptr
})(unsafe.Pointer(&(*TParse)(unsafe.Pointer(pParse)).Fu1))).FpReturning
if pTrigger != pReturning+16 {
/* This RETURNING trigger is for a different statement */
return
}
libc.X__builtin___memset_chk(tls, bp, 0, uint64(120), ^t__predefined_size_t(0))
libc.X__builtin___memset_chk(tls, bp+120, 0, uint64(88), ^t__predefined_size_t(0))
pFrom = bp + 120
(**(**TSelect)(__ccgo_up(bp))).FpEList = _sqlite3ExprListDup(tls, db, (*TReturning)(unsafe.Pointer(pReturning)).FpReturnEL, 0)
(**(**TSelect)(__ccgo_up(bp))).FpSrc = pFrom
(*TSrcList)(unsafe.Pointer(pFrom)).FnSrc = int32(1)
(*(*TSrcItem)(unsafe.Pointer(pFrom + 8))).FpSTab = pTab
(*(*TSrcItem)(unsafe.Pointer(pFrom + 8))).FzName = (*TTable)(unsafe.Pointer(pTab)).FzName /* tag-20240424-1 */
(*(*TSrcItem)(unsafe.Pointer(pFrom + 8))).FiCursor = -int32(1)
_sqlite3SelectPrep(tls, pParse, bp, uintptr(0))
if (*TParse)(unsafe.Pointer(pParse)).FnErr == 0 {
_sqlite3GenerateColumnNames(tls, pParse, bp)
}
_sqlite3ExprListDelete(tls, db, (**(**TSelect)(__ccgo_up(bp))).FpEList)
pNew = _sqlite3ExpandReturning(tls, pParse, (*TReturning)(unsafe.Pointer(pReturning)).FpReturnEL, pTab)
if (*TParse)(unsafe.Pointer(pParse)).FnErr == 0 {
libc.X__builtin___memset_chk(tls, bp+208, 0, uint64(56), ^t__predefined_size_t(0))
if (*TReturning)(unsafe.Pointer(pReturning)).FnRetCol == 0 {
(*TReturning)(unsafe.Pointer(pReturning)).FnRetCol = (*TExprList)(unsafe.Pointer(pNew)).FnExpr
v2 = pParse + 56
v1 = *(*int32)(unsafe.Pointer(v2))
*(*int32)(unsafe.Pointer(v2)) = *(*int32)(unsafe.Pointer(v2)) + 1
(*TReturning)(unsafe.Pointer(pReturning)).FiRetCur = v1
}
(**(**TNameContext)(__ccgo_up(bp + 208))).FpParse = pParse
*(*int32)(unsafe.Pointer(bp + 208 + 16)) = regIn
(**(**TNameContext)(__ccgo_up(bp + 208))).FncFlags = int32(NC_UBaseReg)
(*TParse)(unsafe.Pointer(pParse)).FeTriggerOp = (*TTrigger)(unsafe.Pointer(pTrigger)).Fop
(*TParse)(unsafe.Pointer(pParse)).FpTriggerTab = pTab
if _sqlite3ResolveExprListNames(tls, bp+208, pNew) == SQLITE_OK && !((*Tsqlite3)(unsafe.Pointer(db)).FmallocFailed != 0) {
nCol = (*TExprList)(unsafe.Pointer(pNew)).FnExpr
reg = (*TParse)(unsafe.Pointer(pParse)).FnMem + int32(1)
_sqlite3ProcessReturningSubqueries(tls, pNew, pTab)
**(**int32)(__ccgo_up(pParse + 60)) += nCol + int32(2)
(*TReturning)(unsafe.Pointer(pReturning)).FiRetReg = reg
i = 0
for {
if !(i < nCol) {
break
}
pCol = (*(*TExprList_item)(unsafe.Pointer(pNew + 8 + uintptr(i)*32))).FpExpr
/* Due to !db->mallocFailed ~9 lines above */
_sqlite3ExprCodeFactorable(tls, pParse, pCol, reg+i)
if int32(_sqlite3ExprAffinity(tls, pCol)) == int32(SQLITE_AFF_REAL) {
_sqlite3VdbeAddOp1(tls, v, int32(OP_RealAffinity), reg+i)
}
goto _3
_3:
;
i = i + 1
}
_sqlite3VdbeAddOp3(tls, v, int32(OP_MakeRecord), reg, i, reg+i)
_sqlite3VdbeAddOp2(tls, v, int32(OP_NewRowid), (*TReturning)(unsafe.Pointer(pReturning)).FiRetCur, reg+i+int32(1))
_sqlite3VdbeAddOp3(tls, v, int32(OP_Insert), (*TReturning)(unsafe.Pointer(pReturning)).FiRetCur, reg+i, reg+i+int32(1))
}
}
_sqlite3ExprListDelete(tls, db, pNew)
(*TParse)(unsafe.Pointer(pParse)).FeTriggerOp = uint8(0)
(*TParse)(unsafe.Pointer(pParse)).FpTriggerTab = uintptr(0)
}
// C documentation
//
// /*
// ** Create and populate a new TriggerPrg object with a sub-program
// ** implementing trigger pTrigger with ON CONFLICT policy orconf.
// */
func _codeRowTrigger(tls *libc.TLS, pParse uintptr, pTrigger uintptr, pTab uintptr, orconf int32) (r uintptr) {
bp := tls.Alloc(496)
defer tls.Free(496)
var db, pPrg, pProgram, pTop, pWhen, v, v2 uintptr
var iEndTrigger, nDepth int32
var _ /* sNC at bp+0 */ TNameContext
var _ /* sSubParse at bp+56 */ TParse
_, _, _, _, _, _, _, _, _ = db, iEndTrigger, nDepth, pPrg, pProgram, pTop, pWhen, v, v2 /* Top level Parse object */
db = (*TParse)(unsafe.Pointer(pParse)).Fdb /* Value to return */
pWhen = uintptr(0) /* Name context for sub-vdbe */
pProgram = uintptr(0) /* Sub-vdbe for trigger program */
iEndTrigger = 0 /* Trigger depth */
/* Ensure that triggers are not chained too deep. This test is linear
** in the chaining depth, but sensible code ought not be chaining
** triggers excessively, so that shouldn't be a problem.
*/
pTop = pParse
nDepth = 0
for {
if !((*TParse)(unsafe.Pointer(pTop)).FpOuterParse != 0) {
break
}
goto _1
_1:
;
pTop = (*TParse)(unsafe.Pointer(pTop)).FpOuterParse
nDepth = nDepth + 1
}
if nDepth >= **(**int32)(__ccgo_up(db + 136 + 10*4)) {
_sqlite3ErrorMsg(tls, pParse, __ccgo_ts+22959, 0)
return uintptr(0)
}
if (*TParse)(unsafe.Pointer(pParse)).FpToplevel != 0 {
v2 = (*TParse)(unsafe.Pointer(pParse)).FpToplevel
} else {
v2 = pParse
}
pTop = v2
/* Allocate the TriggerPrg and SubProgram objects. To ensure that they
** are freed if an error occurs, link them into the Parse.pTriggerPrg
** list of the top-level Parse object sooner rather than later. */
pPrg = _sqlite3DbMallocZero(tls, db, uint64(40))
if !(pPrg != 0) {
return uintptr(0)
}
(*TTriggerPrg)(unsafe.Pointer(pPrg)).FpNext = (*TParse)(unsafe.Pointer(pTop)).FpTriggerPrg
(*TParse)(unsafe.Pointer(pTop)).FpTriggerPrg = pPrg
v2 = _sqlite3DbMallocZero(tls, db, uint64(48))
pProgram = v2
(*TTriggerPrg)(unsafe.Pointer(pPrg)).FpProgram = v2
if !(pProgram != 0) {
return uintptr(0)
}
_sqlite3VdbeLinkSubProgram(tls, (*TParse)(unsafe.Pointer(pTop)).FpVdbe, pProgram)
(*TTriggerPrg)(unsafe.Pointer(pPrg)).FpTrigger = pTrigger
(*TTriggerPrg)(unsafe.Pointer(pPrg)).Forconf = orconf
**(**Tu32)(__ccgo_up(pPrg + 28)) = uint32(0xffffffff)
**(**Tu32)(__ccgo_up(pPrg + 28 + 1*4)) = uint32(0xffffffff)
/* Allocate and populate a new Parse context to use for coding the
** trigger sub-program. */
_sqlite3ParseObjectInit(tls, bp+56, db)
libc.X__builtin___memset_chk(tls, bp, 0, uint64(56), ^t__predefined_size_t(0))
(**(**TNameContext)(__ccgo_up(bp))).FpParse = bp + 56
(**(**TParse)(__ccgo_up(bp + 56))).FpTriggerTab = pTab
(**(**TParse)(__ccgo_up(bp + 56))).FpToplevel = pTop
(**(**TParse)(__ccgo_up(bp + 56))).FzAuthContext = (*TTrigger)(unsafe.Pointer(pTrigger)).FzName
(**(**TParse)(__ccgo_up(bp + 56))).FeTriggerOp = (*TTrigger)(unsafe.Pointer(pTrigger)).Fop
(**(**TParse)(__ccgo_up(bp + 56))).FnQueryLoop = (*TParse)(unsafe.Pointer(pParse)).FnQueryLoop
(**(**TParse)(__ccgo_up(bp + 56))).FprepFlags = (*TParse)(unsafe.Pointer(pParse)).FprepFlags
(**(**TParse)(__ccgo_up(bp + 56))).Foldmask = uint32(0)
(**(**TParse)(__ccgo_up(bp + 56))).Fnewmask = uint32(0)
v = _sqlite3GetVdbe(tls, bp+56)
if v != 0 {
if (*TTrigger)(unsafe.Pointer(pTrigger)).FzName != 0 {
_sqlite3VdbeChangeP4(tls, v, -int32(1), _sqlite3MPrintf(tls, db, __ccgo_ts+22984, libc.VaList(bp+488, (*TTrigger)(unsafe.Pointer(pTrigger)).FzName)), -int32(7))
}
/* If one was specified, code the WHEN clause. If it evaluates to false
** (or NULL) the sub-vdbe is immediately halted by jumping to the
** OP_Halt inserted at the end of the program. */
if (*TTrigger)(unsafe.Pointer(pTrigger)).FpWhen != 0 {
pWhen = _sqlite3ExprDup(tls, db, (*TTrigger)(unsafe.Pointer(pTrigger)).FpWhen, 0)
if libc.Int32FromUint8((*Tsqlite3)(unsafe.Pointer(db)).FmallocFailed) == 0 && SQLITE_OK == _sqlite3ResolveExprNames(tls, bp, pWhen) {
iEndTrigger = _sqlite3VdbeMakeLabel(tls, bp+56)
_sqlite3ExprIfFalse(tls, bp+56, pWhen, iEndTrigger, int32(SQLITE_JUMPIFNULL))
}
_sqlite3ExprDelete(tls, db, pWhen)
}
/* Code the trigger program into the sub-vdbe. */
_codeTriggerProgram(tls, bp+56, (*TTrigger)(unsafe.Pointer(pTrigger)).Fstep_list, orconf)
/* Insert an OP_Halt at the end of the sub-program. */
if iEndTrigger != 0 {
_sqlite3VdbeResolveLabel(tls, v, iEndTrigger)
}
_sqlite3VdbeAddOp0(tls, v, int32(OP_Halt))
_transferParseError(tls, pParse, bp+56)
if (*TParse)(unsafe.Pointer(pParse)).FnErr == 0 {
(*TSubProgram)(unsafe.Pointer(pProgram)).FaOp = _sqlite3VdbeTakeOpArray(tls, v, pProgram+8, pTop+128)
}
(*TSubProgram)(unsafe.Pointer(pProgram)).FnMem = (**(**TParse)(__ccgo_up(bp + 56))).FnMem
(*TSubProgram)(unsafe.Pointer(pProgram)).FnCsr = (**(**TParse)(__ccgo_up(bp + 56))).FnTab
(*TSubProgram)(unsafe.Pointer(pProgram)).Ftoken = pTrigger
**(**Tu32)(__ccgo_up(pPrg + 28)) = (**(**TParse)(__ccgo_up(bp + 56))).Foldmask
**(**Tu32)(__ccgo_up(pPrg + 28 + 1*4)) = (**(**TParse)(__ccgo_up(bp + 56))).Fnewmask
_sqlite3VdbeDelete(tls, v)
} else {
_transferParseError(tls, pParse, bp+56)
}
_sqlite3ParseObjectReset(tls, bp+56)
return pPrg
}
// C documentation
//
// /*
// ** Generate VDBE code for the statements inside the body of a single
// ** trigger.
// */
func _codeTriggerProgram(tls *libc.TLS, pParse uintptr, pStepList uintptr, orconf int32) (r int32) {
bp := tls.Alloc(64)
defer tls.Free(64)
var db, pSelect, pStep, v uintptr
var v2 int32
var _ /* sDest at bp+0 */ TSelectDest
_, _, _, _, _ = db, pSelect, pStep, v, v2
v = (*TParse)(unsafe.Pointer(pParse)).FpVdbe
db = (*TParse)(unsafe.Pointer(pParse)).Fdb
pStep = pStepList
for {
if !(pStep != 0) {
break
}
/* Figure out the ON CONFLICT policy that will be used for this step
** of the trigger program. If the statement that caused this trigger
** to fire had an explicit ON CONFLICT, then use it. Otherwise, use
** the ON CONFLICT policy that was specified as part of the trigger
** step statement. Example:
**
** CREATE TRIGGER AFTER INSERT ON t1 BEGIN;
** INSERT OR REPLACE INTO t2 VALUES(new.a, new.b);
** END;
**
** INSERT INTO t1 ... ; -- insert into t2 uses REPLACE policy
** INSERT OR IGNORE INTO t1 ... ; -- insert into t2 uses IGNORE policy
*/
if orconf == int32(OE_Default) {
v2 = libc.Int32FromUint8((*TTriggerStep)(unsafe.Pointer(pStep)).Forconf)
} else {
v2 = libc.Int32FromUint8(libc.Uint8FromInt32(orconf))
}
(*TParse)(unsafe.Pointer(pParse)).FeOrconf = libc.Uint8FromInt32(v2)
if (*TTriggerStep)(unsafe.Pointer(pStep)).FzSpan != 0 {
_sqlite3VdbeAddOp4(tls, v, int32(OP_Trace), int32(0x7fffffff), int32(1), 0, _sqlite3MPrintf(tls, db, __ccgo_ts+6829, libc.VaList(bp+48, (*TTriggerStep)(unsafe.Pointer(pStep)).FzSpan)), -int32(7))
}
switch libc.Int32FromUint8((*TTriggerStep)(unsafe.Pointer(pStep)).Fop) {
case int32(TK_UPDATE):
_sqlite3Update(tls, pParse, _sqlite3SrcListDup(tls, db, (*TTriggerStep)(unsafe.Pointer(pStep)).FpSrc, 0), _sqlite3ExprListDup(tls, db, (*TTriggerStep)(unsafe.Pointer(pStep)).FpExprList, 0), _sqlite3ExprDup(tls, db, (*TTriggerStep)(unsafe.Pointer(pStep)).FpWhere, 0), libc.Int32FromUint8((*TParse)(unsafe.Pointer(pParse)).FeOrconf), uintptr(0), uintptr(0), uintptr(0))
_sqlite3VdbeAddOp0(tls, v, int32(OP_ResetCount))
case int32(TK_INSERT):
_sqlite3Insert(tls, pParse, _sqlite3SrcListDup(tls, db, (*TTriggerStep)(unsafe.Pointer(pStep)).FpSrc, 0), _sqlite3SelectDup(tls, db, (*TTriggerStep)(unsafe.Pointer(pStep)).FpSelect, 0), _sqlite3IdListDup(tls, db, (*TTriggerStep)(unsafe.Pointer(pStep)).FpIdList), libc.Int32FromUint8((*TParse)(unsafe.Pointer(pParse)).FeOrconf), _sqlite3UpsertDup(tls, db, (*TTriggerStep)(unsafe.Pointer(pStep)).FpUpsert))
_sqlite3VdbeAddOp0(tls, v, int32(OP_ResetCount))
case int32(TK_DELETE):
_sqlite3DeleteFrom(tls, pParse, _sqlite3SrcListDup(tls, db, (*TTriggerStep)(unsafe.Pointer(pStep)).FpSrc, 0), _sqlite3ExprDup(tls, db, (*TTriggerStep)(unsafe.Pointer(pStep)).FpWhere, 0), uintptr(0), uintptr(0))
_sqlite3VdbeAddOp0(tls, v, int32(OP_ResetCount))
default:
pSelect = _sqlite3SelectDup(tls, db, (*TTriggerStep)(unsafe.Pointer(pStep)).FpSelect, 0)
_sqlite3SelectDestInit(tls, bp, int32(SRT_Discard), 0)
_sqlite3Select(tls, pParse, pSelect, bp)
_sqlite3SelectDelete(tls, db, pSelect)
break
}
goto _1
_1:
;
pStep = (*TTriggerStep)(unsafe.Pointer(pStep)).FpNext
}
return 0
}
// C documentation
//
// /*
// ** Expression pExpr is a comparison between two vector values. Compute
// ** the result of the comparison (1, 0, or NULL) and write that
// ** result into register dest.
// **
// ** The caller must satisfy the following preconditions:
// **
// ** if pExpr->op==TK_IS: op==TK_EQ and p5==SQLITE_NULLEQ
// ** if pExpr->op==TK_ISNOT: op==TK_NE and p5==SQLITE_NULLEQ
// ** otherwise: op==pExpr->op and p5==0
// */
func _codeVectorCompare(tls *libc.TLS, pParse uintptr, pExpr uintptr, dest int32, op Tu8, p5 Tu8) {
bp := tls.Alloc(32)
defer tls.Free(32)
var addrCmp, addrDone, i, isCommuted, nLeft, r1, r2, regLeft, regRight int32
var opx Tu8
var pLeft, pRight, v uintptr
var _ /* pL at bp+8 */ uintptr
var _ /* pR at bp+16 */ uintptr
var _ /* regFree1 at bp+0 */ int32
var _ /* regFree2 at bp+4 */ int32
_, _, _, _, _, _, _, _, _, _, _, _, _ = addrCmp, addrDone, i, isCommuted, nLeft, opx, pLeft, pRight, r1, r2, regLeft, regRight, v
v = (*TParse)(unsafe.Pointer(pParse)).FpVdbe
pLeft = (*TExpr)(unsafe.Pointer(pExpr)).FpLeft
pRight = (*TExpr)(unsafe.Pointer(pExpr)).FpRight
nLeft = _sqlite3ExprVectorSize(tls, pLeft)
regLeft = 0
regRight = 0
opx = op
addrCmp = 0
addrDone = _sqlite3VdbeMakeLabel(tls, pParse)
isCommuted = libc.BoolInt32((*TExpr)(unsafe.Pointer(pExpr)).Fflags&libc.Uint32FromInt32(libc.Int32FromInt32(EP_Commuted)) != uint32(0))
if (*TParse)(unsafe.Pointer(pParse)).FnErr != 0 {
return
}
if nLeft != _sqlite3ExprVectorSize(tls, pRight) {
_sqlite3ErrorMsg(tls, pParse, __ccgo_ts+7256, 0)
return
}
if libc.Int32FromUint8(op) == int32(TK_LE) {
opx = uint8(TK_LT)
}
if libc.Int32FromUint8(op) == int32(TK_GE) {
opx = uint8(TK_GT)
}
if libc.Int32FromUint8(op) == int32(TK_NE) {
opx = uint8(TK_EQ)
}
regLeft = _exprCodeSubselect(tls, pParse, pLeft)
regRight = _exprCodeSubselect(tls, pParse, pRight)
_sqlite3VdbeAddOp2(tls, v, int32(OP_Integer), int32(1), dest)
i = 0
for {
if !(int32(1) != 0) {
break
}
**(**int32)(__ccgo_up(bp)) = 0
**(**int32)(__ccgo_up(bp + 4)) = 0
**(**uintptr)(__ccgo_up(bp + 8)) = uintptr(0)
**(**uintptr)(__ccgo_up(bp + 16)) = uintptr(0)
if addrCmp != 0 {
_sqlite3VdbeJumpHere(tls, v, addrCmp)
}
r1 = _exprVectorRegister(tls, pParse, pLeft, i, regLeft, bp+8, bp)
r2 = _exprVectorRegister(tls, pParse, pRight, i, regRight, bp+16, bp+4)
addrCmp = _sqlite3VdbeCurrentAddr(tls, v)
_codeCompare(tls, pParse, **(**uintptr)(__ccgo_up(bp + 8)), **(**uintptr)(__ccgo_up(bp + 16)), libc.Int32FromUint8(opx), r1, r2, addrDone, libc.Int32FromUint8(p5), isCommuted)
_sqlite3ReleaseTempReg(tls, pParse, **(**int32)(__ccgo_up(bp)))
_sqlite3ReleaseTempReg(tls, pParse, **(**int32)(__ccgo_up(bp + 4)))
if (libc.Int32FromUint8(opx) == int32(TK_LT) || libc.Int32FromUint8(opx) == int32(TK_GT)) && i < nLeft-int32(1) {
addrCmp = _sqlite3VdbeAddOp0(tls, v, int32(OP_ElseEq))
}
if libc.Int32FromUint8(p5) == int32(SQLITE_NULLEQ) {
_sqlite3VdbeAddOp2(tls, v, int32(OP_Integer), 0, dest)
} else {
_sqlite3VdbeAddOp3(tls, v, int32(OP_ZeroOrNull), r1, dest, r2)
}
if i == nLeft-int32(1) {
break
}
if libc.Int32FromUint8(opx) == int32(TK_EQ) {
_sqlite3VdbeAddOp2(tls, v, int32(OP_NotNull), dest, addrDone)
} else {
_sqlite3VdbeAddOp2(tls, v, int32(OP_Goto), 0, addrDone)
if i == nLeft-int32(2) {
opx = op
}
}
goto _1
_1:
;
i = i + 1
}
_sqlite3VdbeJumpHere(tls, v, addrCmp)
_sqlite3VdbeResolveLabel(tls, v, addrDone)
if libc.Int32FromUint8(op) == int32(TK_NE) {
_sqlite3VdbeAddOp2(tls, v, int32(OP_Not), dest, dest)
}
}
// C documentation
//
// /*
// ** Return a pointer to a string containing the 'declaration type' of the
// ** expression pExpr. The string may be treated as static by the caller.
// **
// ** The declaration type is the exact datatype definition extracted from the
// ** original CREATE TABLE statement if the expression is a column. The
// ** declaration type for a ROWID field is INTEGER. Exactly when an expression
// ** is considered a column can be complex in the presence of subqueries. The
// ** result-set expression in all of the following SELECT statements is
// ** considered a column by this function.
// **
// ** SELECT col FROM tbl;
// ** SELECT (SELECT col FROM tbl;
// ** SELECT (SELECT col FROM tbl);
// ** SELECT abc FROM (SELECT col AS abc FROM tbl);
// **
// ** The declaration type for any expression other than a column is NULL.
// **
// ** This routine has either 3 or 6 parameters depending on whether or not
// ** the SQLITE_ENABLE_COLUMN_METADATA compile-time option is used.
// */
func _columnTypeImpl(tls *libc.TLS, pNC uintptr, pExpr uintptr, pzOrigDb uintptr, pzOrigTab uintptr, pzOrigCol uintptr) (r uintptr) {
bp := tls.Alloc(144)
defer tls.Free(144)
var iCol, iDb, j int32
var p, p1, pS, pS1, pTab, pTabList, zType uintptr
var _ /* sNC at bp+24 */ TNameContext
var _ /* sNC at bp+80 */ TNameContext
var _ /* zOrigCol at bp+16 */ uintptr
var _ /* zOrigDb at bp+0 */ uintptr
var _ /* zOrigTab at bp+8 */ uintptr
_, _, _, _, _, _, _, _, _, _ = iCol, iDb, j, p, p1, pS, pS1, pTab, pTabList, zType
zType = uintptr(0)
**(**uintptr)(__ccgo_up(bp)) = uintptr(0)
**(**uintptr)(__ccgo_up(bp + 8)) = uintptr(0)
**(**uintptr)(__ccgo_up(bp + 16)) = uintptr(0)
switch libc.Int32FromUint8((*TExpr)(unsafe.Pointer(pExpr)).Fop) {
case int32(TK_COLUMN):
/* The expression is a column. Locate the table the column is being
** extracted from in NameContext.pSrcList. This table may be real
** database table or a subquery.
*/
pTab = uintptr(0) /* Table structure column is extracted from */
pS = uintptr(0) /* Select the column is extracted from */
iCol = int32((*TExpr)(unsafe.Pointer(pExpr)).FiColumn) /* Index of column in pTab */
for pNC != 0 && !(pTab != 0) {
pTabList = (*TNameContext)(unsafe.Pointer(pNC)).FpSrcList
j = 0
for {
if !(j < (*TSrcList)(unsafe.Pointer(pTabList)).FnSrc && (*(*TSrcItem)(unsafe.Pointer(pTabList + 8 + uintptr(j)*80))).FiCursor != (*TExpr)(unsafe.Pointer(pExpr)).FiTable) {
break
}
goto _1
_1:
;
j = j + 1
}
if j < (*TSrcList)(unsafe.Pointer(pTabList)).FnSrc {
pTab = (*(*TSrcItem)(unsafe.Pointer(pTabList + 8 + uintptr(j)*80))).FpSTab
if int32(*(*uint32)(unsafe.Pointer(pTabList + 8 + uintptr(j)*80 + 24 + 4))&0x4>>2) != 0 {
pS = (*TSubquery)(unsafe.Pointer(*(*uintptr)(unsafe.Pointer(pTabList + 8 + uintptr(j)*80 + 72)))).FpSelect
} else {
pS = uintptr(0)
}
} else {
pNC = (*TNameContext)(unsafe.Pointer(pNC)).FpNext
}
}
if pTab == uintptr(0) {
/* At one time, code such as "SELECT new.x" within a trigger would
** cause this condition to run. Since then, we have restructured how
** trigger code is generated and so this condition is no longer
** possible. However, it can still be true for statements like
** the following:
**
** CREATE TABLE t1(col INTEGER);
** SELECT (SELECT t1.col) FROM FROM t1;
**
** when columnType() is called on the expression "t1.col" in the
** sub-select. In this case, set the column type to NULL, even
** though it should really be "INTEGER".
**
** This is not a problem, as the column type of "t1.col" is never
** used. When columnType() is called on the expression
** "(SELECT t1.col)", the correct type is returned (see the TK_SELECT
** branch below. */
break
}
if pS != 0 {
/* The "table" is actually a sub-select or a view in the FROM clause
** of the SELECT statement. Return the declaration type and origin
** data for the result-set column of the sub-select.
*/
if iCol < (*TExprList)(unsafe.Pointer((*TSelect)(unsafe.Pointer(pS)).FpEList)).FnExpr && libc.Bool(libc.Bool(!(libc.Int32FromInt32(ViewCanHaveRowid) != 0)) || iCol >= 0) {
p = (*(*TExprList_item)(unsafe.Pointer((*TSelect)(unsafe.Pointer(pS)).FpEList + 8 + uintptr(iCol)*32))).FpExpr
(**(**TNameContext)(__ccgo_up(bp + 24))).FpSrcList = (*TSelect)(unsafe.Pointer(pS)).FpSrc
(**(**TNameContext)(__ccgo_up(bp + 24))).FpNext = pNC
(**(**TNameContext)(__ccgo_up(bp + 24))).FpParse = (*TNameContext)(unsafe.Pointer(pNC)).FpParse
zType = _columnTypeImpl(tls, bp+24, p, bp, bp+8, bp+16)
}
} else {
/* A real table or a CTE table */
if iCol < 0 {
iCol = int32((*TTable)(unsafe.Pointer(pTab)).FiPKey)
}
if iCol < 0 {
zType = __ccgo_ts + 1176
**(**uintptr)(__ccgo_up(bp + 16)) = __ccgo_ts + 18314
} else {
**(**uintptr)(__ccgo_up(bp + 16)) = (**(**TColumn)(__ccgo_up((*TTable)(unsafe.Pointer(pTab)).FaCol + uintptr(iCol)*16))).FzCnName
zType = _sqlite3ColumnType(tls, (*TTable)(unsafe.Pointer(pTab)).FaCol+uintptr(iCol)*16, uintptr(0))
}
**(**uintptr)(__ccgo_up(bp + 8)) = (*TTable)(unsafe.Pointer(pTab)).FzName
if (*TNameContext)(unsafe.Pointer(pNC)).FpParse != 0 && (*TTable)(unsafe.Pointer(pTab)).FpSchema != 0 {
iDb = _sqlite3SchemaToIndex(tls, (*TParse)(unsafe.Pointer((*TNameContext)(unsafe.Pointer(pNC)).FpParse)).Fdb, (*TTable)(unsafe.Pointer(pTab)).FpSchema)
**(**uintptr)(__ccgo_up(bp)) = (**(**TDb)(__ccgo_up((*Tsqlite3)(unsafe.Pointer((*TParse)(unsafe.Pointer((*TNameContext)(unsafe.Pointer(pNC)).FpParse)).Fdb)).FaDb + uintptr(iDb)*32))).FzDbSName
}
}
case int32(TK_SELECT):
pS1 = *(*uintptr)(unsafe.Pointer(pExpr + 32))
p1 = (*(*TExprList_item)(unsafe.Pointer((*TSelect)(unsafe.Pointer(pS1)).FpEList + 8))).FpExpr
(**(**TNameContext)(__ccgo_up(bp + 80))).FpSrcList = (*TSelect)(unsafe.Pointer(pS1)).FpSrc
(**(**TNameContext)(__ccgo_up(bp + 80))).FpNext = pNC
(**(**TNameContext)(__ccgo_up(bp + 80))).FpParse = (*TNameContext)(unsafe.Pointer(pNC)).FpParse
zType = _columnTypeImpl(tls, bp+80, p1, bp, bp+8, bp+16)
break
}
if pzOrigDb != 0 {
**(**uintptr)(__ccgo_up(pzOrigDb)) = **(**uintptr)(__ccgo_up(bp))
**(**uintptr)(__ccgo_up(pzOrigTab)) = **(**uintptr)(__ccgo_up(bp + 8))
**(**uintptr)(__ccgo_up(pzOrigCol)) = **(**uintptr)(__ccgo_up(bp + 16))
}
return zType
}
// C documentation
//
// /* The core implementation of the CONCAT(...) and CONCAT_WS(SEP,...)
// ** functions.
// **
// ** Return a string value that is the concatenation of all non-null
// ** entries in argv[]. Use zSep as the separator.
// */
func _concatFuncCore(tls *libc.TLS, context uintptr, argc int32, argv uintptr, nSep int32, zSep uintptr) {
var bNotNull, i, k int32
var j, n Ti64
var v, z uintptr
_, _, _, _, _, _, _ = bNotNull, i, j, k, n, v, z
n = 0
bNotNull = 0
i = 0
for {
if !(i < argc) {
break
}
n = n + int64(Xsqlite3_value_bytes(tls, **(**uintptr)(__ccgo_up(argv + uintptr(i)*8))))
goto _1
_1:
;
i = i + 1
}
n = n + int64(argc-libc.Int32FromInt32(1))*int64(nSep)
z = Xsqlite3_malloc64(tls, libc.Uint64FromInt64(n+int64(1)))
if z == uintptr(0) {
Xsqlite3_result_error_nomem(tls, context)
return
}
j = 0
i = 0
for {
if !(i < argc) {
break
}
if Xsqlite3_value_type(tls, **(**uintptr)(__ccgo_up(argv + uintptr(i)*8))) != int32(SQLITE_NULL) {
k = Xsqlite3_value_bytes(tls, **(**uintptr)(__ccgo_up(argv + uintptr(i)*8)))
v = Xsqlite3_value_text(tls, **(**uintptr)(__ccgo_up(argv + uintptr(i)*8)))
if v != uintptr(0) {
if bNotNull != 0 && nSep > 0 {
libc.X__builtin___memcpy_chk(tls, z+uintptr(j), zSep, libc.Uint64FromInt32(nSep), ^t__predefined_size_t(0))
j = j + int64(nSep)
}
libc.X__builtin___memcpy_chk(tls, z+uintptr(j), v, libc.Uint64FromInt32(k), ^t__predefined_size_t(0))
j = j + int64(k)
bNotNull = int32(1)
}
}
goto _2
_2:
;
i = i + 1
}
**(**int8)(__ccgo_up(z + uintptr(j))) = 0
Xsqlite3_result_text64(tls, context, z, libc.Uint64FromInt64(j), __ccgo_fp(Xsqlite3_free), uint8(SQLITE_UTF8_ZT))
}
// 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)*80
pTable = (*TSrcItem)(unsafe.Pointer(pSrc)).FpSTab
pWCEnd = (*TWhereClause)(unsafe.Pointer(pWC)).Fa + uintptr((*TWhereClause)(unsafe.Pointer(pWC)).FnTerm)*56
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 + 32))).FleftColumn
if iCol >= libc.Int32FromUint64(libc.Uint64FromInt64(8)*libc.Uint64FromInt32(8)) {
v2 = libc.Uint64FromInt32(1) << (libc.Int32FromUint64(libc.Uint64FromInt64(8)*libc.Uint64FromInt32(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.Int32FromUint64(libc.Uint64FromInt64(8)*libc.Uint64FromInt32(8))-libc.Int32FromInt32(1) {
extraCols = extraCols | libc.Uint64FromInt32(1)<<(libc.Int32FromUint64(libc.Uint64FromInt64(8)*libc.Uint64FromInt32(8))-libc.Int32FromInt32(1))
break
}
if idxCols&(libc.Uint64FromInt32(1)<= libc.Int32FromUint64(libc.Uint64FromInt64(8)*libc.Uint64FromInt32(8)) {
v2 = libc.Uint64FromInt32(1) << (libc.Int32FromUint64(libc.Uint64FromInt64(8)*libc.Uint64FromInt32(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 + 32))).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)*8)) = 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 += 56
}
/* 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)<>6) != 0 {
pSubq = *(*uintptr)(unsafe.Pointer(pSrc + 72))
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 + 48)) |= 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 + 24 + 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 + 72)))).FregResult, (*TWhereLevel)(unsafe.Pointer(pLevel)).FiIdxCur)
_sqlite3VdbeGoto(tls, v, addrTop)
libc.SetBitFieldPtr32Uint32(pSrc+24+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
//
// /*
// ** Detect compound SELECT statements that use an ORDER BY clause with
// ** an alternative collating sequence.
// **
// ** SELECT ... FROM t1 EXCEPT SELECT ... FROM t2 ORDER BY .. COLLATE ...
// **
// ** These are rewritten as a subquery:
// **
// ** SELECT * FROM (SELECT ... FROM t1 EXCEPT SELECT ... FROM t2)
// ** ORDER BY ... COLLATE ...
// **
// ** This transformation is necessary because the multiSelectByMerge() routine
// ** above that generates the code for a compound SELECT with an ORDER BY clause
// ** uses a merge algorithm that requires the same collating sequence on the
// ** result columns as on the ORDER BY clause. See ticket
// ** http://sqlite.org/src/info/6709574d2a
// **
// ** This transformation is only needed for EXCEPT, INTERSECT, and UNION.
// ** The UNION ALL operator works fine with multiSelectByMerge() even when
// ** there are COLLATE terms in the ORDER BY.
// */
func _convertCompoundSelectToSubquery(tls *libc.TLS, pWalker uintptr, p uintptr) (r int32) {
bp := tls.Alloc(16)
defer tls.Free(16)
var a, db, pNew, pNewSrc, pParse, pX uintptr
var i int32
var _ /* dummy at bp+0 */ TToken
_, _, _, _, _, _, _ = a, db, i, pNew, pNewSrc, pParse, pX
if (*TSelect)(unsafe.Pointer(p)).FpPrior == uintptr(0) {
return WRC_Continue
}
if (*TSelect)(unsafe.Pointer(p)).FpOrderBy == uintptr(0) {
return WRC_Continue
}
pX = p
for {
if !(pX != 0 && (libc.Int32FromUint8((*TSelect)(unsafe.Pointer(pX)).Fop) == int32(TK_ALL) || libc.Int32FromUint8((*TSelect)(unsafe.Pointer(pX)).Fop) == int32(TK_SELECT))) {
break
}
goto _1
_1:
;
pX = (*TSelect)(unsafe.Pointer(pX)).FpPrior
}
if pX == uintptr(0) {
return WRC_Continue
}
a = (*TSelect)(unsafe.Pointer(p)).FpOrderBy + 8
/* If iOrderByCol is already non-zero, then it has already been matched
** to a result column of the SELECT statement. This occurs when the
** SELECT is rewritten for window-functions processing and then passed
** to sqlite3SelectPrep() and similar a second time. The rewriting done
** by this function is not required in this case. */
if *(*Tu16)(unsafe.Pointer(a + 24)) != 0 {
return WRC_Continue
}
i = (*TExprList)(unsafe.Pointer((*TSelect)(unsafe.Pointer(p)).FpOrderBy)).FnExpr - int32(1)
for {
if !(i >= 0) {
break
}
if (*TExpr)(unsafe.Pointer((**(**TExprList_item)(__ccgo_up(a + uintptr(i)*32))).FpExpr)).Fflags&uint32(EP_Collate) != 0 {
break
}
goto _2
_2:
;
i = i - 1
}
if i < 0 {
return WRC_Continue
}
/* If we reach this point, that means the transformation is required. */
pParse = (*TWalker)(unsafe.Pointer(pWalker)).FpParse
db = (*TParse)(unsafe.Pointer(pParse)).Fdb
pNew = _sqlite3DbMallocZero(tls, db, uint64(120))
if pNew == uintptr(0) {
return int32(WRC_Abort)
}
libc.X__builtin___memset_chk(tls, bp, 0, uint64(16), ^t__predefined_size_t(0))
pNewSrc = _sqlite3SrcListAppendFromTerm(tls, pParse, uintptr(0), uintptr(0), uintptr(0), bp, pNew, uintptr(0))
if (*TParse)(unsafe.Pointer(pParse)).FnErr != 0 {
_sqlite3SrcListDelete(tls, db, pNewSrc)
return int32(WRC_Abort)
}
**(**TSelect)(__ccgo_up(pNew)) = **(**TSelect)(__ccgo_up(p))
(*TSelect)(unsafe.Pointer(p)).FpSrc = pNewSrc
(*TSelect)(unsafe.Pointer(p)).FpEList = _sqlite3ExprListAppend(tls, pParse, uintptr(0), _sqlite3Expr(tls, db, int32(TK_ASTERISK), uintptr(0)))
(*TSelect)(unsafe.Pointer(p)).Fop = uint8(TK_SELECT)
(*TSelect)(unsafe.Pointer(p)).FpWhere = uintptr(0)
(*TSelect)(unsafe.Pointer(pNew)).FpGroupBy = uintptr(0)
(*TSelect)(unsafe.Pointer(pNew)).FpHaving = uintptr(0)
(*TSelect)(unsafe.Pointer(pNew)).FpOrderBy = uintptr(0)
(*TSelect)(unsafe.Pointer(p)).FpPrior = uintptr(0)
(*TSelect)(unsafe.Pointer(p)).FpNext = uintptr(0)
(*TSelect)(unsafe.Pointer(p)).FpWith = uintptr(0)
(*TSelect)(unsafe.Pointer(p)).FpWinDefn = uintptr(0)
**(**Tu32)(__ccgo_up(p + 4)) &= ^libc.Uint32FromInt32(SF_Compound)
**(**Tu32)(__ccgo_up(p + 4)) |= uint32(SF_Converted)
(*TSelect)(unsafe.Pointer((*TSelect)(unsafe.Pointer(pNew)).FpPrior)).FpNext = pNew
(*TSelect)(unsafe.Pointer(pNew)).FpLimit = uintptr(0)
return WRC_Continue
}
// C documentation
//
// /*
// ** This function is used to copy the contents of the b-tree node stored
// ** on page pFrom to page pTo. If page pFrom was not a leaf page, then
// ** the pointer-map entries for each child page are updated so that the
// ** parent page stored in the pointer map is page pTo. If pFrom contained
// ** any cells with overflow page pointers, then the corresponding pointer
// ** map entries are also updated so that the parent page is page pTo.
// **
// ** If pFrom is currently carrying any overflow cells (entries in the
// ** MemPage.apOvfl[] array), they are not copied to pTo.
// **
// ** Before returning, page pTo is reinitialized using btreeInitPage().
// **
// ** The performance of this function is not critical. It is only used by
// ** the balance_shallower() and balance_deeper() procedures, neither of
// ** which are called often under normal circumstances.
// */
func _copyNodeContent(tls *libc.TLS, pFrom uintptr, pTo uintptr, pRC uintptr) {
var aFrom, aTo, pBt uintptr
var iData, iFromHdr, iToHdr, rc, v1 int32
_, _, _, _, _, _, _, _ = aFrom, aTo, iData, iFromHdr, iToHdr, pBt, rc, v1
if **(**int32)(__ccgo_up(pRC)) == SQLITE_OK {
pBt = (*TMemPage)(unsafe.Pointer(pFrom)).FpBt
aFrom = (*TMemPage)(unsafe.Pointer(pFrom)).FaData
aTo = (*TMemPage)(unsafe.Pointer(pTo)).FaData
iFromHdr = libc.Int32FromUint8((*TMemPage)(unsafe.Pointer(pFrom)).FhdrOffset)
if (*TMemPage)(unsafe.Pointer(pTo)).Fpgno == uint32(1) {
v1 = int32(100)
} else {
v1 = 0
}
iToHdr = v1
/* Copy the b-tree node content from page pFrom to page pTo. */
iData = libc.Int32FromUint8(**(**Tu8)(__ccgo_up(aFrom + uintptr(iFromHdr+int32(5)))))<>2) == 0 {
return 0
} /* FROM is a subquery */
pSub = (*TSubquery)(unsafe.Pointer(*(*uintptr)(unsafe.Pointer(pFrom + 72)))).FpSelect
if (*TSelect)(unsafe.Pointer(pSub)).FpPrior == uintptr(0) {
return 0
} /* Must be a compound */
if (*TSelect)(unsafe.Pointer(pSub)).FselFlags&uint32(SF_CopyCte) != 0 {
return 0
} /* Not a CTE */
for cond := true; cond; cond = pSub != 0 {
if libc.Int32FromUint8((*TSelect)(unsafe.Pointer(pSub)).Fop) != int32(TK_ALL) && (*TSelect)(unsafe.Pointer(pSub)).FpPrior != 0 {
return 0
} /* Must be UNION ALL */
if (*TSelect)(unsafe.Pointer(pSub)).FpWhere != 0 {
return 0
} /* No WHERE clause */
if (*TSelect)(unsafe.Pointer(pSub)).FpLimit != 0 {
return 0
} /* No LIMIT clause */
if (*TSelect)(unsafe.Pointer(pSub)).FselFlags&libc.Uint32FromInt32(libc.Int32FromInt32(SF_Aggregate)|libc.Int32FromInt32(SF_Distinct)) != 0 {
return 0 /* Not an aggregate nor DISTINCT */
}
/* Due to the previous */
pSub = (*TSelect)(unsafe.Pointer(pSub)).FpPrior /* Repeat over compound */
}
/* If we reach this point then it is OK to perform the transformation */
db = (*TParse)(unsafe.Pointer(pParse)).Fdb
pCount = pExpr
pExpr = uintptr(0)
pSub = _sqlite3SubqueryDetach(tls, db, pFrom)
_sqlite3SrcListDelete(tls, db, (*TSelect)(unsafe.Pointer(p)).FpSrc)
(*TSelect)(unsafe.Pointer(p)).FpSrc = _sqlite3DbMallocZero(tls, (*TParse)(unsafe.Pointer(pParse)).Fdb, uint64(uint64(libc.UintptrFromInt32(0)+8)+libc.Uint64FromInt64(80)))
for pSub != 0 {
pPrior = (*TSelect)(unsafe.Pointer(pSub)).FpPrior
(*TSelect)(unsafe.Pointer(pSub)).FpPrior = uintptr(0)
(*TSelect)(unsafe.Pointer(pSub)).FpNext = uintptr(0)
**(**Tu32)(__ccgo_up(pSub + 4)) |= uint32(SF_Aggregate)
**(**Tu32)(__ccgo_up(pSub + 4)) &= ^libc.Uint32FromInt32(SF_Compound)
(*TSelect)(unsafe.Pointer(pSub)).FnSelectRow = 0
_sqlite3ParserAddCleanup(tls, pParse, __ccgo_fp(_sqlite3ExprListDeleteGeneric), (*TSelect)(unsafe.Pointer(pSub)).FpEList)
if pPrior != 0 {
v1 = _sqlite3ExprDup(tls, db, pCount, 0)
} else {
v1 = pCount
}
pTerm = v1
(*TSelect)(unsafe.Pointer(pSub)).FpEList = _sqlite3ExprListAppend(tls, pParse, uintptr(0), pTerm)
pTerm = _sqlite3PExpr(tls, pParse, int32(TK_SELECT), uintptr(0), uintptr(0))
_sqlite3PExprAddSelect(tls, pParse, pTerm, pSub)
if pExpr == uintptr(0) {
pExpr = pTerm
} else {
pExpr = _sqlite3PExpr(tls, pParse, int32(TK_PLUS), pTerm, pExpr)
}
pSub = pPrior
}
(*(*TExprList_item)(unsafe.Pointer((*TSelect)(unsafe.Pointer(p)).FpEList + 8))).FpExpr = pExpr
**(**Tu32)(__ccgo_up(p + 4)) &= ^libc.Uint32FromInt32(SF_Aggregate)
return int32(1)
}
// C documentation
//
// /*
// ** Create a new aggregate context for p and return a pointer to
// ** its pMem->z element.
// */
func _createAggContext(tls *libc.TLS, p uintptr, nByte int32) (r uintptr) {
var pMem uintptr
_ = pMem
pMem = (*Tsqlite3_context)(unsafe.Pointer(p)).FpMem
if nByte <= 0 {
_sqlite3VdbeMemSetNull(tls, pMem)
(*TMem)(unsafe.Pointer(pMem)).Fz = uintptr(0)
} else {
_sqlite3VdbeMemClearAndResize(tls, pMem, nByte)
(*TMem)(unsafe.Pointer(pMem)).Fflags = uint16(MEM_Agg)
*(*uintptr)(unsafe.Pointer(pMem)) = (*Tsqlite3_context)(unsafe.Pointer(p)).FpFunc
if (*TMem)(unsafe.Pointer(pMem)).Fz != 0 {
libc.X__builtin___memset_chk(tls, (*TMem)(unsafe.Pointer(pMem)).Fz, 0, libc.Uint64FromInt32(nByte), ^t__predefined_size_t(0))
}
}
return (*TMem)(unsafe.Pointer(pMem)).Fz
}
// 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+26441, 0)
return int32(SQLITE_BUSY)
}
_sqlite3ExpirePreparedStatements(tls, db, 0)
/* If collation sequence pColl was created directly by a call to
** sqlite3_create_collation, and not generated by synthCollSeq(),
** then any copies made by synthCollSeq() need to be invalidated.
** Also, collation destructor - CollSeq.xDel() - function may need
** to be called.
*/
if libc.Int32FromUint8((*TCollSeq)(unsafe.Pointer(pColl)).Fenc) & ^libc.Int32FromInt32(SQLITE_UTF16_ALIGNED) == enc2 {
aColl = _sqlite3HashFind(tls, db+648, zName)
j = 0
for {
if !(j < int32(3)) {
break
}
p = aColl + uintptr(j)*40
if libc.Int32FromUint8((*TCollSeq)(unsafe.Pointer(p)).Fenc) == libc.Int32FromUint8((*TCollSeq)(unsafe.Pointer(pColl)).Fenc) {
if (*TCollSeq)(unsafe.Pointer(p)).FxDel != 0 {
(*(*func(*libc.TLS, uintptr))(unsafe.Pointer(&struct{ uintptr }{(*TCollSeq)(unsafe.Pointer(p)).FxDel})))(tls, (*TCollSeq)(unsafe.Pointer(p)).FpUser)
}
(*TCollSeq)(unsafe.Pointer(p)).FxCmp = uintptr(0)
}
goto _1
_1:
;
j = j + 1
}
}
}
pColl = _sqlite3FindCollSeq(tls, db, libc.Uint8FromInt32(enc2), zName, int32(1))
if pColl == uintptr(0) {
return int32(SQLITE_NOMEM)
}
(*TCollSeq)(unsafe.Pointer(pColl)).FxCmp = __ccgo_fp_xCompare
(*TCollSeq)(unsafe.Pointer(pColl)).FpUser = pCtx
(*TCollSeq)(unsafe.Pointer(pColl)).FxDel = __ccgo_fp_xDel
(*TCollSeq)(unsafe.Pointer(pColl)).Fenc = libc.Uint8FromInt32(enc2 | libc.Int32FromUint8(enc)&libc.Int32FromInt32(SQLITE_UTF16_ALIGNED))
_sqlite3Error(tls, db, SQLITE_OK)
return SQLITE_OK
}
// C documentation
//
// /*
// ** 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 += 16
}
n = n + _identLength(tls, (*TTable)(unsafe.Pointer(p)).FzName)
if n < int64(50) {
zSep = __ccgo_ts + 1702
zSep2 = __ccgo_ts + 14694
zEnd = __ccgo_ts + 5605
} else {
zSep = __ccgo_ts + 14696
zSep2 = __ccgo_ts + 14700
zEnd = __ccgo_ts + 14705
}
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.X__builtin___memcpy_chk(tls, zStmt, __ccgo_ts+14708, uint64(13), ^t__predefined_size_t(0))
**(**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.X__builtin___memcpy_chk(tls, zStmt+uintptr(**(**int32)(__ccgo_up(bp))), zSep, libc.Uint64FromInt32(len1), ^t__predefined_size_t(0))
**(**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.X__builtin___memcpy_chk(tls, zStmt+uintptr(**(**int32)(__ccgo_up(bp))), zType, libc.Uint64FromInt32(len1), ^t__predefined_size_t(0))
**(**int32)(__ccgo_up(bp)) = **(**int32)(__ccgo_up(bp)) + len1
goto _3
_3:
;
i = i + 1
pCol += 16
}
len1 = _sqlite3Strlen30(tls, zEnd)
libc.X__builtin___memcpy_chk(tls, zStmt+uintptr(**(**int32)(__ccgo_up(bp))), zEnd, libc.Uint64FromInt32(len1+int32(1)), ^t__predefined_size_t(0))
return zStmt
}
// C documentation
//
// /*
// ** Put the DateTime object into its error state.
// */
func _datetimeError(tls *libc.TLS, p uintptr) {
libc.X__builtin___memset_chk(tls, p, 0, uint64(48), ^t__predefined_size_t(0))
libc.SetBitFieldPtr8Uint32(p+44, libc.Uint32FromInt32(1), 1, 0x2)
}
func _dbReallocFinish(tls *libc.TLS, db uintptr, p uintptr, n Tu64) (r uintptr) {
var pNew uintptr
_ = pNew
pNew = uintptr(0)
if libc.Int32FromUint8((*Tsqlite3)(unsafe.Pointer(db)).FmallocFailed) == 0 {
if _isLookaside(tls, db, p) != 0 {
pNew = _sqlite3DbMallocRawNN(tls, db, n)
if pNew != 0 {
libc.X__builtin___memcpy_chk(tls, pNew, p, libc.Uint64FromInt32(_lookasideMallocSize(tls, db, p)), ^t__predefined_size_t(0))
_sqlite3DbFree(tls, db, p)
}
} else {
pNew = _sqlite3Realloc(tls, p, n)
if !(pNew != 0) {
_sqlite3OomFault(tls, db)
}
}
}
return pNew
}
// C documentation
//
// /*
// ** Connect to or create a dbpagevfs virtual table.
// */
func _dbpageConnect(tls *libc.TLS, db uintptr, pAux uintptr, argc int32, argv uintptr, ppVtab uintptr, pzErr uintptr) (r int32) {
var pTab uintptr
var rc int32
_, _ = pTab, rc
pTab = uintptr(0)
rc = SQLITE_OK
_ = pAux
_ = argc
_ = argv
_ = pzErr
Xsqlite3_vtab_config(tls, db, int32(SQLITE_VTAB_DIRECTONLY), 0)
Xsqlite3_vtab_config(tls, db, int32(SQLITE_VTAB_USES_ALL_SCHEMAS), 0)
rc = Xsqlite3_declare_vtab(tls, db, __ccgo_ts+35391)
if rc == SQLITE_OK {
pTab = Xsqlite3_malloc64(tls, uint64(40))
if pTab == uintptr(0) {
rc = int32(SQLITE_NOMEM)
}
}
if rc == SQLITE_OK {
libc.X__builtin___memset_chk(tls, pTab, 0, uint64(40), ^t__predefined_size_t(0))
(*TDbpageTable)(unsafe.Pointer(pTab)).Fdb = db
}
**(**uintptr)(__ccgo_up(ppVtab)) = pTab
return rc
}
// C documentation
//
// /*
// ** Open a new dbpagevfs cursor.
// */
func _dbpageOpen(tls *libc.TLS, pVTab uintptr, ppCursor uintptr) (r int32) {
var pCsr uintptr
_ = pCsr
pCsr = Xsqlite3_malloc64(tls, uint64(40))
if pCsr == uintptr(0) {
return int32(SQLITE_NOMEM)
} else {
libc.X__builtin___memset_chk(tls, pCsr, 0, uint64(40), ^t__predefined_size_t(0))
(*TDbpageCursor)(unsafe.Pointer(pCsr)).Fbase.FpVtab = pVTab
(*TDbpageCursor)(unsafe.Pointer(pCsr)).Fpgno = uint32(0)
}
**(**uintptr)(__ccgo_up(ppCursor)) = pCsr
return SQLITE_OK
}
func _dbpageUpdate(tls *libc.TLS, pVtab uintptr, argc int32, argv uintptr, pRowid uintptr) (r int32) {
bp := tls.Alloc(32)
defer tls.Free(32)
var aPage, pBt, pData, pPager, pTab, zErr, zSchema uintptr
var iDb, isInsert, rc, szPage, v1 int32
var pgno TPgno
var _ /* pDbPage at bp+0 */ uintptr
_, _, _, _, _, _, _, _, _, _, _, _, _ = aPage, iDb, isInsert, pBt, pData, pPager, pTab, pgno, rc, szPage, zErr, zSchema, v1
pTab = pVtab
**(**uintptr)(__ccgo_up(bp)) = uintptr(0)
rc = SQLITE_OK
zErr = uintptr(0)
_ = pRowid
if (*Tsqlite3)(unsafe.Pointer((*TDbpageTable)(unsafe.Pointer(pTab)).Fdb)).Fflags&uint64(SQLITE_Defensive) != 0 {
zErr = __ccgo_ts + 35458
goto update_fail
}
if argc == int32(1) {
zErr = __ccgo_ts + 35468
goto update_fail
}
if Xsqlite3_value_type(tls, **(**uintptr)(__ccgo_up(argv))) == int32(SQLITE_NULL) {
pgno = libc.Uint32FromInt64(Xsqlite3_value_int64(tls, **(**uintptr)(__ccgo_up(argv + 2*8))))
isInsert = int32(1)
} else {
pgno = libc.Uint32FromInt64(Xsqlite3_value_int64(tls, **(**uintptr)(__ccgo_up(argv))))
if libc.Uint32FromInt32(Xsqlite3_value_int(tls, **(**uintptr)(__ccgo_up(argv + 1*8)))) != pgno {
zErr = __ccgo_ts + 35482
goto update_fail
}
isInsert = 0
}
if Xsqlite3_value_type(tls, **(**uintptr)(__ccgo_up(argv + 4*8))) == int32(SQLITE_NULL) {
iDb = 0
} else {
zSchema = Xsqlite3_value_text(tls, **(**uintptr)(__ccgo_up(argv + 4*8)))
iDb = _sqlite3FindDbName(tls, (*TDbpageTable)(unsafe.Pointer(pTab)).Fdb, zSchema)
if iDb < 0 {
zErr = __ccgo_ts + 35496
goto update_fail
}
}
pBt = (**(**TDb)(__ccgo_up((*Tsqlite3)(unsafe.Pointer((*TDbpageTable)(unsafe.Pointer(pTab)).Fdb)).FaDb + uintptr(iDb)*32))).FpBt
if pgno < uint32(1) || pBt == uintptr(0) {
zErr = __ccgo_ts + 35511
goto update_fail
}
szPage = _sqlite3BtreeGetPageSize(tls, pBt)
if Xsqlite3_value_type(tls, **(**uintptr)(__ccgo_up(argv + 3*8))) != int32(SQLITE_BLOB) || Xsqlite3_value_bytes(tls, **(**uintptr)(__ccgo_up(argv + 3*8))) != szPage {
if Xsqlite3_value_type(tls, **(**uintptr)(__ccgo_up(argv + 3*8))) == int32(SQLITE_NULL) && isInsert != 0 && pgno > uint32(1) {
/* "INSERT INTO dbpage($PGNO,NULL)" causes page number $PGNO and
** all subsequent pages to be deleted. */
(*TDbpageTable)(unsafe.Pointer(pTab)).FiDbTrunc = iDb
(*TDbpageTable)(unsafe.Pointer(pTab)).FpgnoTrunc = pgno - uint32(1)
pgno = uint32(1)
} else {
zErr = __ccgo_ts + 35527
goto update_fail
}
}
if _dbpageBeginTrans(tls, pTab) != SQLITE_OK {
zErr = __ccgo_ts + 35542
goto update_fail
}
pPager = _sqlite3BtreePager(tls, pBt)
rc = _sqlite3PagerGet(tls, pPager, pgno, bp, 0)
if rc == SQLITE_OK {
pData = Xsqlite3_value_blob(tls, **(**uintptr)(__ccgo_up(argv + 3*8)))
v1 = _sqlite3PagerWrite(tls, **(**uintptr)(__ccgo_up(bp)))
rc = v1
if v1 == SQLITE_OK && pData != 0 {
aPage = _sqlite3PagerGetData(tls, **(**uintptr)(__ccgo_up(bp)))
libc.X__builtin___memcpy_chk(tls, aPage, pData, libc.Uint64FromInt32(szPage), ^t__predefined_size_t(0))
(*TDbpageTable)(unsafe.Pointer(pTab)).FpgnoTrunc = uint32(0)
}
}
if rc != SQLITE_OK {
(*TDbpageTable)(unsafe.Pointer(pTab)).FpgnoTrunc = uint32(0)
}
_sqlite3PagerUnref(tls, **(**uintptr)(__ccgo_up(bp)))
return rc
goto update_fail
update_fail:
;
(*TDbpageTable)(unsafe.Pointer(pTab)).FpgnoTrunc = uint32(0)
Xsqlite3_free(tls, (*Tsqlite3_vtab)(unsafe.Pointer(pVtab)).FzErrMsg)
(*Tsqlite3_vtab)(unsafe.Pointer(pVtab)).FzErrMsg = Xsqlite3_mprintf(tls, __ccgo_ts+3944, libc.VaList(bp+16, zErr))
return int32(SQLITE_ERROR)
}
// 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+100, libc.Uint32FromInt32(0), 2, 0x4)
libc.SetBitFieldPtr16Uint32(pIndex+100, libc.Uint32FromInt32(0), 6, 0x40)
for **(**int8)(__ccgo_up(z)) != 0 {
if Xsqlite3_strglob(tls, __ccgo_ts+13400, z) == 0 {
libc.SetBitFieldPtr16Uint32(pIndex+100, libc.Uint32FromInt32(1), 2, 0x4)
} else {
if Xsqlite3_strglob(tls, __ccgo_ts+13411, 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+13421, z) == 0 {
libc.SetBitFieldPtr16Uint32(pIndex+100, 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
//
// /*
// ** Defragment the page given. This routine reorganizes cells within the
// ** page so that there are no free-blocks on the free-block list.
// **
// ** Parameter nMaxFrag is the maximum amount of fragmented space that may be
// ** present in the page after this routine returns.
// **
// ** EVIDENCE-OF: R-44582-60138 SQLite may from time to time reorganize a
// ** b-tree page so that there are no freeblocks or fragment bytes, all
// ** unused bytes are contained in the unallocated space region, and all
// ** cells are packed tightly at the end of the page.
// */
func _defragmentPage(tls *libc.TLS, pPage uintptr, nMaxFrag int32) (r int32) {
var cbrk, cellOffset, hdr, i, iCellFirst, iCellLast, iCellStart, iFree, iFree2, nCell, pc, size, sz, sz2, top, usableSize int32
var data, pAddr, pAddr1, pEnd, src, temp uintptr
_, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _ = cbrk, cellOffset, data, hdr, i, iCellFirst, iCellLast, iCellStart, iFree, iFree2, nCell, pAddr, pAddr1, pEnd, pc, size, src, sz, sz2, temp, top, usableSize /* First cell offset in input */
data = (*TMemPage)(unsafe.Pointer(pPage)).FaData
hdr = libc.Int32FromUint8((*TMemPage)(unsafe.Pointer(pPage)).FhdrOffset)
cellOffset = libc.Int32FromUint16((*TMemPage)(unsafe.Pointer(pPage)).FcellOffset)
nCell = libc.Int32FromUint16((*TMemPage)(unsafe.Pointer(pPage)).FnCell)
iCellFirst = cellOffset + int32(2)*nCell
usableSize = libc.Int32FromUint32((*TBtShared)(unsafe.Pointer((*TMemPage)(unsafe.Pointer(pPage)).FpBt)).FusableSize)
/* This block handles pages with two or fewer free blocks and nMaxFrag
** or fewer fragmented bytes. In this case it is faster to move the
** two (or one) blocks of cells using memmove() and add the required
** offsets to each pointer in the cell-pointer array than it is to
** reconstruct the entire page. */
if libc.Int32FromUint8(**(**uint8)(__ccgo_up(data + uintptr(hdr+int32(7))))) <= nMaxFrag {
iFree = libc.Int32FromUint8(**(**uint8)(__ccgo_up(data + uintptr(hdr+int32(1)))))< usableSize-int32(4) {
return _sqlite3CorruptError(tls, int32(74875))
}
if iFree != 0 {
iFree2 = libc.Int32FromUint8(**(**uint8)(__ccgo_up(data + uintptr(iFree))))< usableSize-int32(4) {
return _sqlite3CorruptError(tls, int32(74878))
}
if 0 == iFree2 || libc.Int32FromUint8(**(**uint8)(__ccgo_up(data + uintptr(iFree2)))) == 0 && libc.Int32FromUint8(**(**uint8)(__ccgo_up(data + uintptr(iFree2+int32(1))))) == 0 {
pEnd = data + uintptr(cellOffset+nCell*int32(2))
sz2 = 0
sz = libc.Int32FromUint8(**(**uint8)(__ccgo_up(data + uintptr(iFree+int32(2)))))<= iFree {
return _sqlite3CorruptError(tls, int32(74886))
}
if iFree2 != 0 {
if iFree+sz > iFree2 {
return _sqlite3CorruptError(tls, int32(74889))
}
sz2 = libc.Int32FromUint8(**(**uint8)(__ccgo_up(data + uintptr(iFree2+int32(2)))))< usableSize {
return _sqlite3CorruptError(tls, int32(74891))
}
libc.X__builtin___memmove_chk(tls, data+uintptr(iFree+sz+sz2), data+uintptr(iFree+sz), libc.Uint64FromInt32(iFree2-(iFree+sz)), ^t__predefined_size_t(0))
sz = sz + sz2
} else {
if iFree+sz > usableSize {
return _sqlite3CorruptError(tls, int32(74895))
}
}
cbrk = top + sz
libc.X__builtin___memmove_chk(tls, data+uintptr(cbrk), data+uintptr(top), libc.Uint64FromInt32(iFree-top), ^t__predefined_size_t(0))
pAddr = data + uintptr(cellOffset)
for {
if !(pAddr < pEnd) {
break
}
pc = libc.Int32FromUint8(**(**Tu8)(__ccgo_up(pAddr)))<> libc.Int32FromInt32(8))
**(**Tu8)(__ccgo_up(pAddr + 1)) = libc.Uint8FromInt32(pc + sz)
} else {
if pc < iFree2 {
**(**Tu8)(__ccgo_up(pAddr)) = libc.Uint8FromInt32((pc + sz2) >> libc.Int32FromInt32(8))
**(**Tu8)(__ccgo_up(pAddr + 1)) = libc.Uint8FromInt32(pc + sz2)
}
}
goto _1
_1:
;
pAddr = pAddr + uintptr(2)
}
goto defragment_out
}
}
}
cbrk = usableSize
iCellLast = usableSize - int32(4)
iCellStart = libc.Int32FromUint8(**(**uint8)(__ccgo_up(data + uintptr(hdr+int32(5)))))< 0 {
temp = _sqlite3PagerTempSpace(tls, (*TBtShared)(unsafe.Pointer((*TMemPage)(unsafe.Pointer(pPage)).FpBt)).FpPager)
libc.X__builtin___memcpy_chk(tls, temp, data, libc.Uint64FromInt32(usableSize), ^t__predefined_size_t(0))
src = temp
i = 0
for {
if !(i < nCell) {
break
} /* The i-th cell pointer */
pAddr1 = data + uintptr(cellOffset+i*int32(2))
pc = libc.Int32FromUint8(**(**Tu8)(__ccgo_up(pAddr1)))< iCellLast {
return _sqlite3CorruptError(tls, int32(74928))
}
size = libc.Int32FromUint16((*(*func(*libc.TLS, uintptr, uintptr) Tu16)(unsafe.Pointer(&struct{ uintptr }{(*TMemPage)(unsafe.Pointer(pPage)).FxCellSize})))(tls, pPage, src+uintptr(pc)))
cbrk = cbrk - size
if cbrk < iCellStart || pc+size > usableSize {
return _sqlite3CorruptError(tls, int32(74934))
}
**(**Tu8)(__ccgo_up(pAddr1)) = libc.Uint8FromInt32(cbrk >> libc.Int32FromInt32(8))
**(**Tu8)(__ccgo_up(pAddr1 + 1)) = libc.Uint8FromInt32(cbrk)
libc.X__builtin___memcpy_chk(tls, data+uintptr(cbrk), src+uintptr(pc), libc.Uint64FromInt32(size), ^t__predefined_size_t(0))
goto _2
_2:
;
i = i + 1
}
}
**(**uint8)(__ccgo_up(data + uintptr(hdr+int32(7)))) = uint8(0)
goto defragment_out
defragment_out:
;
if libc.Int32FromUint8(**(**uint8)(__ccgo_up(data + uintptr(hdr+int32(7)))))+cbrk-iCellFirst != (*TMemPage)(unsafe.Pointer(pPage)).FnFree {
return _sqlite3CorruptError(tls, int32(74948))
}
**(**uint8)(__ccgo_up(data + uintptr(hdr+int32(5)))) = libc.Uint8FromInt32(cbrk >> libc.Int32FromInt32(8))
**(**uint8)(__ccgo_up(data + uintptr(hdr+int32(5)) + 1)) = libc.Uint8FromInt32(cbrk)
**(**uint8)(__ccgo_up(data + uintptr(hdr+int32(1)))) = uint8(0)
**(**uint8)(__ccgo_up(data + uintptr(hdr+int32(2)))) = uint8(0)
libc.X__builtin___memset_chk(tls, data+uintptr(iCellFirst), 0, libc.Uint64FromInt32(cbrk-iCellFirst), ^t__predefined_size_t(0))
return SQLITE_OK
}
// 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+27886)
if pSrc == uintptr(0) {
return int32(SQLITE_ERROR)
}
pInfo = Xsqlite3_malloc64(tls, uint64(112)+uint64((*TRtreeMatchArg)(unsafe.Pointer(pSrc)).FiSize))
if !(pInfo != 0) {
return int32(SQLITE_NOMEM)
}
libc.X__builtin___memset_chk(tls, pInfo, 0, uint64(112), ^t__predefined_size_t(0))
pBlob = pInfo + 1*112
libc.X__builtin___memcpy_chk(tls, pBlob, pSrc, uint64((*TRtreeMatchArg)(unsafe.Pointer(pSrc)).FiSize), ^t__predefined_size_t(0))
(*Tsqlite3_rtree_query_info)(unsafe.Pointer(pInfo)).FpContext = (*TRtreeMatchArg)(unsafe.Pointer(pBlob)).Fcb.FpContext
(*Tsqlite3_rtree_query_info)(unsafe.Pointer(pInfo)).FnParam = (*TRtreeMatchArg)(unsafe.Pointer(pBlob)).FnParam
(*Tsqlite3_rtree_query_info)(unsafe.Pointer(pInfo)).FaParam = pBlob + 56
(*Tsqlite3_rtree_query_info)(unsafe.Pointer(pInfo)).FapSqlParam = (*TRtreeMatchArg)(unsafe.Pointer(pBlob)).FapSqlParam
if (*TRtreeMatchArg)(unsafe.Pointer(pBlob)).Fcb.FxGeom != 0 {
*(*uintptr)(unsafe.Pointer(pCons + 8)) = (*TRtreeMatchArg)(unsafe.Pointer(pBlob)).Fcb.FxGeom
} else {
(*TRtreeConstraint)(unsafe.Pointer(pCons)).Fop = int32(RTREE_QUERY)
*(*uintptr)(unsafe.Pointer(pCons + 8)) = (*TRtreeMatchArg)(unsafe.Pointer(pBlob)).Fcb.FxQueryFunc
}
(*TRtreeConstraint)(unsafe.Pointer(pCons)).FpInfo = pInfo
return SQLITE_OK
}
// C documentation
//
// /*
// ** Write code to erase the table with root-page iTable from database iDb.
// ** Also write code to modify the sqlite_schema table and internal schema
// ** if a root-page of another table is moved by the btree-layer whilst
// ** erasing iTable (this can happen with an auto-vacuum database).
// */
func _destroyRootPage(tls *libc.TLS, pParse uintptr, iTable int32, iDb int32) {
bp := tls.Alloc(48)
defer tls.Free(48)
var r1 int32
var v uintptr
_, _ = r1, v
v = _sqlite3GetVdbe(tls, pParse)
r1 = _sqlite3GetTempReg(tls, pParse)
if iTable < int32(2) {
_sqlite3ErrorMsg(tls, pParse, __ccgo_ts+15217, 0)
}
_sqlite3VdbeAddOp3(tls, v, int32(OP_Destroy), iTable, r1, iDb)
_sqlite3MayAbort(tls, pParse)
/* OP_Destroy stores an in integer r1. If this integer
** is non-zero, then it is the root page number of a table moved to
** location iTable. The following code modifies the sqlite_schema table to
** reflect this.
**
** The "#NNN" in the SQL is a special constant that means whatever value
** is in register NNN. See grammar rules associated with the TK_REGISTER
** token for additional information.
*/
_sqlite3NestedParse(tls, pParse, __ccgo_ts+15232, libc.VaList(bp+8, (**(**TDb)(__ccgo_up((*Tsqlite3)(unsafe.Pointer((*TParse)(unsafe.Pointer(pParse)).Fdb)).FaDb + uintptr(iDb)*32))).FzDbSName, iTable, r1, r1))
_sqlite3ReleaseTempReg(tls, pParse, r1)
}
// 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)*32
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+13790, libc.VaList(bp+136, zName))
goto detach_error
}
if i < int32(2) {
Xsqlite3_snprintf(tls, int32(128), bp, __ccgo_ts+13811, 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+13837, 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*32))).FpSchema + 56)).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))
}
var _detach_func = TFuncDef{
FnArg: int16(1),
FfuncFlags: uint32(SQLITE_UTF8),
FzName: __ccgo_ts + 13859,
}
// C documentation
//
// /*
// ** Disable lookaside memory allocation for objects that might be
// ** shared across database connections.
// */
func _disableLookaside(tls *libc.TLS, pParse uintptr) {
var db uintptr
_ = db
db = (*TParse)(unsafe.Pointer(pParse)).Fdb
(*TParse)(unsafe.Pointer(pParse)).FdisableLookaside = (*TParse)(unsafe.Pointer(pParse)).FdisableLookaside + 1
libc.X__builtin___memset_chk(tls, pParse+256, 0, uint64(32), ^t__predefined_size_t(0))
(*Tsqlite3)(unsafe.Pointer(db)).Flookaside.FbDisable = (*Tsqlite3)(unsafe.Pointer(db)).Flookaside.FbDisable + 1
(*Tsqlite3)(unsafe.Pointer(db)).Flookaside.Fsz = uint16(0)
}
func _disallowAggregatesInOrderByCb(tls *libc.TLS, pWalker uintptr, pExpr uintptr) (r int32) {
bp := tls.Alloc(16)
defer tls.Free(16)
if libc.Int32FromUint8((*TExpr)(unsafe.Pointer(pExpr)).Fop) == int32(TK_AGG_FUNCTION) && (*TExpr)(unsafe.Pointer(pExpr)).FpAggInfo == uintptr(0) {
_sqlite3ErrorMsg(tls, (*TWalker)(unsafe.Pointer(pWalker)).FpParse, __ccgo_ts+24824, libc.VaList(bp+8, *(*uintptr)(unsafe.Pointer(pExpr + 8))))
}
return WRC_Continue
}
// C documentation
//
// /*
// ** Close a file. Make sure the lock has been released before closing.
// */
func _dotlockClose(tls *libc.TLS, id uintptr) (r int32) {
var pFile uintptr
_ = pFile
pFile = id
_dotlockUnlock(tls, id, NO_LOCK)
Xsqlite3_free(tls, (*TunixFile)(unsafe.Pointer(pFile)).FlockingContext)
return _closeUnixFile(tls, id)
}
/****************** End of the dot-file lock implementation *******************
******************************************************************************/
/******************************************************************************
************************** Begin flock Locking ********************************
**
** Use the flock() system call to do file locking.
**
** flock() locking is like dot-file locking in that the various
** fine-grain locking levels supported by SQLite are collapsed into
** a single exclusive lock. In other words, SHARED, RESERVED, and
** PENDING locks are the same thing as an EXCLUSIVE lock. SQLite
** still works when you do this, but concurrency is reduced since
** only a single process can be reading the database at a time.
**
** Omit this section if SQLITE_ENABLE_LOCKING_STYLE is turned off
*/
// C documentation
//
// /*
// ** Remove the i-th cell from pPage. This routine effects pPage only.
// ** The cell content is not freed or deallocated. It is assumed that
// ** the cell content has been copied someplace else. This routine just
// ** removes the reference to the cell from pPage.
// **
// ** "sz" must be the number of bytes in the cell.
// */
func _dropCell(tls *libc.TLS, pPage uintptr, idx int32, sz int32, pRC uintptr) {
var data, ptr uintptr
var hdr, rc int32
var pc Tu32
_, _, _, _, _ = data, hdr, pc, ptr, rc /* Beginning of the header. 0 most pages. 100 page 1 */
if **(**int32)(__ccgo_up(pRC)) != 0 {
return
}
data = (*TMemPage)(unsafe.Pointer(pPage)).FaData
ptr = (*TMemPage)(unsafe.Pointer(pPage)).FaCellIdx + uintptr(int32(2)*idx)
pc = libc.Uint32FromInt32(libc.Int32FromUint8(**(**Tu8)(__ccgo_up(ptr)))< (*TBtShared)(unsafe.Pointer((*TMemPage)(unsafe.Pointer(pPage)).FpBt)).FusableSize {
**(**int32)(__ccgo_up(pRC)) = _sqlite3CorruptError(tls, int32(80515))
return
}
rc = _freeSpace(tls, pPage, libc.Int32FromUint32(pc), sz)
if rc != 0 {
**(**int32)(__ccgo_up(pRC)) = rc
return
}
(*TMemPage)(unsafe.Pointer(pPage)).FnCell = (*TMemPage)(unsafe.Pointer(pPage)).FnCell - 1
if libc.Int32FromUint16((*TMemPage)(unsafe.Pointer(pPage)).FnCell) == 0 {
libc.X__builtin___memset_chk(tls, data+uintptr(hdr+int32(1)), 0, uint64(4), ^t__predefined_size_t(0))
**(**Tu8)(__ccgo_up(data + uintptr(hdr+int32(7)))) = uint8(0)
**(**Tu8)(__ccgo_up(data + uintptr(hdr+int32(5)))) = uint8((*TBtShared)(unsafe.Pointer((*TMemPage)(unsafe.Pointer(pPage)).FpBt)).FusableSize >> libc.Int32FromInt32(8))
**(**Tu8)(__ccgo_up(data + uintptr(hdr+int32(5)) + 1)) = uint8((*TBtShared)(unsafe.Pointer((*TMemPage)(unsafe.Pointer(pPage)).FpBt)).FusableSize)
(*TMemPage)(unsafe.Pointer(pPage)).FnFree = libc.Int32FromUint32((*TBtShared)(unsafe.Pointer((*TMemPage)(unsafe.Pointer(pPage)).FpBt)).FusableSize - uint32((*TMemPage)(unsafe.Pointer(pPage)).FhdrOffset) - uint32((*TMemPage)(unsafe.Pointer(pPage)).FchildPtrSize) - uint32(8))
} else {
libc.X__builtin___memmove_chk(tls, ptr, ptr+uintptr(2), libc.Uint64FromInt32(int32(2)*(libc.Int32FromUint16((*TMemPage)(unsafe.Pointer(pPage)).FnCell)-idx)), ^t__predefined_size_t(0))
**(**Tu8)(__ccgo_up(data + uintptr(hdr+int32(3)))) = libc.Uint8FromInt32(libc.Int32FromUint16((*TMemPage)(unsafe.Pointer(pPage)).FnCell) >> libc.Int32FromInt32(8))
**(**Tu8)(__ccgo_up(data + uintptr(hdr+int32(3)) + 1)) = uint8((*TMemPage)(unsafe.Pointer(pPage)).FnCell)
**(**int32)(__ccgo_up(pPage + 20)) += int32(2)
}
}
// C documentation
//
// /*
// ** The implementation of internal UDF sqlite_drop_column().
// **
// ** Arguments:
// **
// ** argv[0]: An integer - the index of the schema containing the table
// ** argv[1]: CREATE TABLE statement to modify.
// ** argv[2]: An integer - the index of the column to remove.
// **
// ** The value returned is a string containing the CREATE TABLE statement
// ** with column argv[2] removed.
// */
func _dropColumnFunc(tls *libc.TLS, context uintptr, NotUsed int32, argv uintptr) {
bp := tls.Alloc(464)
defer tls.Free(464)
var db, pCol, pEnd, pTab, zDb, zEnd, zNew, zSql uintptr
var iCol, iSchema, rc int32
var xAuth Tsqlite3_xauth
var _ /* eTok at bp+424 */ int32
var _ /* sParse at bp+0 */ TParse
_, _, _, _, _, _, _, _, _, _, _, _ = db, iCol, iSchema, pCol, pEnd, pTab, rc, xAuth, zDb, zEnd, zNew, zSql
db = Xsqlite3_context_db_handle(tls, context)
iSchema = Xsqlite3_value_int(tls, **(**uintptr)(__ccgo_up(argv)))
zSql = Xsqlite3_value_text(tls, **(**uintptr)(__ccgo_up(argv + 1*8)))
iCol = Xsqlite3_value_int(tls, **(**uintptr)(__ccgo_up(argv + 2*8)))
zDb = (**(**TDb)(__ccgo_up((*Tsqlite3)(unsafe.Pointer(db)).FaDb + uintptr(iSchema)*32))).FzDbSName
zNew = uintptr(0)
xAuth = (*Tsqlite3)(unsafe.Pointer(db)).FxAuth
(*Tsqlite3)(unsafe.Pointer(db)).FxAuth = uintptr(0)
_ = NotUsed
rc = _renameParseSql(tls, bp, zDb, db, zSql, libc.BoolInt32(iSchema == int32(1)))
if rc != SQLITE_OK {
goto drop_column_done
}
pTab = (**(**TParse)(__ccgo_up(bp))).FpNewTable
if pTab == uintptr(0) || int32((*TTable)(unsafe.Pointer(pTab)).FnCol) == int32(1) || iCol >= int32((*TTable)(unsafe.Pointer(pTab)).FnCol) {
/* This can happen if the sqlite_schema table is corrupt */
rc = _sqlite3CorruptError(tls, int32(122753))
goto drop_column_done
}
if iCol < int32((*TTable)(unsafe.Pointer(pTab)).FnCol)-int32(1) {
pCol = _renameTokenFind(tls, bp, uintptr(0), (**(**TColumn)(__ccgo_up((*TTable)(unsafe.Pointer(pTab)).FaCol + uintptr(iCol)*16))).FzCnName)
pEnd = _renameTokenFind(tls, bp, uintptr(0), (**(**TColumn)(__ccgo_up((*TTable)(unsafe.Pointer(pTab)).FaCol + uintptr(iCol+int32(1))*16))).FzCnName)
zEnd = (*TRenameToken)(unsafe.Pointer(pEnd)).Ft.Fz
} else {
/* Point pCol->t.z at the "," immediately preceding the definition of
** the column being dropped. To do this, start at the name of the
** previous column, and tokenize until the next ",". */
pCol = _renameTokenFind(tls, bp, uintptr(0), (**(**TColumn)(__ccgo_up((*TTable)(unsafe.Pointer(pTab)).FaCol + uintptr(iCol-int32(1))*16))).FzCnName)
for cond := true; cond; cond = **(**int32)(__ccgo_up(bp + 424)) != int32(TK_COMMA) {
(*TRenameToken)(unsafe.Pointer(pCol)).Ft.Fz += uintptr(_getConstraintToken(tls, (*TRenameToken)(unsafe.Pointer(pCol)).Ft.Fz, bp+424))
}
(*TRenameToken)(unsafe.Pointer(pCol)).Ft.Fz = (*TRenameToken)(unsafe.Pointer(pCol)).Ft.Fz - 1
zEnd = zSql + uintptr((*(*struct {
FaddColOffset int32
FpFKey uintptr
FpDfltList uintptr
})(unsafe.Pointer(pTab + 64))).FaddColOffset)
}
zNew = _sqlite3MPrintf(tls, db, __ccgo_ts+11933, libc.VaList(bp+440, int64((*TRenameToken)(unsafe.Pointer(pCol)).Ft.Fz)-int64(zSql), zSql, zEnd))
Xsqlite3_result_text(tls, context, zNew, -int32(1), uintptr(-libc.Int32FromInt32(1)))
Xsqlite3_free(tls, zNew)
goto drop_column_done
drop_column_done:
;
_renameParseCleanup(tls, bp)
(*Tsqlite3)(unsafe.Pointer(db)).FxAuth = xAuth
if rc != SQLITE_OK {
Xsqlite3_result_error_code(tls, context, rc)
}
}
// C documentation
//
// /*
// ** Internal SQL function sqlite3_drop_constraint(): Given an input
// ** CREATE TABLE statement, return a revised CREATE TABLE statement
// ** with a constraint removed. Two forms, depending on the datatype
// ** of argv[2]:
// **
// ** sqlite_drop_constraint(SQL, INT) -- Omit NOT NULL from the INT-th column
// ** sqlite_drop_constraint(SQL, TEXT) -- OMIT constraint with name TEXT
// **
// ** In the first case, the left-most column is 0.
// */
func _dropConstraintFunc(tls *libc.TLS, ctx uintptr, NotUsed int32, argv uintptr) {
bp := tls.Alloc(64)
defer tls.Free(64)
var db, zCons, zNew, zSpace, zSql uintptr
var iEnd, iNotNull, iStart, ii, nTok int32
var _ /* cmp at bp+8 */ int32
var _ /* iOff at bp+0 */ int32
var _ /* t at bp+4 */ int32
_, _, _, _, _, _, _, _, _, _ = db, iEnd, iNotNull, iStart, ii, nTok, zCons, zNew, zSpace, zSql
zSql = Xsqlite3_value_text(tls, **(**uintptr)(__ccgo_up(argv)))
zCons = uintptr(0)
iNotNull = -int32(1)
**(**int32)(__ccgo_up(bp)) = 0
iStart = 0
iEnd = 0
zNew = uintptr(0)
**(**int32)(__ccgo_up(bp + 4)) = 0
_ = NotUsed
if zSql == uintptr(0) {
return
}
/* Jump past the "CREATE TABLE" bit. */
if _skipCreateTable(tls, ctx, zSql, bp) != 0 {
return
}
if Xsqlite3_value_type(tls, **(**uintptr)(__ccgo_up(argv + 1*8))) == int32(SQLITE_INTEGER) {
iNotNull = Xsqlite3_value_int(tls, **(**uintptr)(__ccgo_up(argv + 1*8)))
} else {
zCons = Xsqlite3_value_text(tls, **(**uintptr)(__ccgo_up(argv + 1*8)))
}
/* Search for the named constraint within column definitions. */
ii = 0
for {
if !(iEnd == 0) {
break
}
/* Now parse the column or table constraint definition. Search
** for the token CONSTRAINT if this is a DROP CONSTRAINT command, or
** NOT in the right column if this is a DROP NOT NULL. */
for int32(1) != 0 {
iStart = **(**int32)(__ccgo_up(bp))
**(**int32)(__ccgo_up(bp)) = **(**int32)(__ccgo_up(bp)) + _getConstraintToken(tls, zSql+uintptr(**(**int32)(__ccgo_up(bp))), bp+4)
if **(**int32)(__ccgo_up(bp + 4)) == int32(TK_CONSTRAINT) && (zCons != 0 || iNotNull == ii) {
/* Check if this is the constraint we are searching for. */
nTok = 0
**(**int32)(__ccgo_up(bp + 8)) = int32(1)
/* Skip past any whitespace. */
**(**int32)(__ccgo_up(bp)) = **(**int32)(__ccgo_up(bp)) + _getWhitespace(tls, zSql+uintptr(**(**int32)(__ccgo_up(bp))))
/* Compare the next token - which may be quoted - with the name of
** the constraint being dropped. */
nTok = _getConstraintToken(tls, zSql+uintptr(**(**int32)(__ccgo_up(bp))), bp+4)
if zCons != 0 {
if _quotedCompare(tls, ctx, **(**int32)(__ccgo_up(bp + 4)), zSql+uintptr(**(**int32)(__ccgo_up(bp))), nTok, zCons, bp+8) != 0 {
return
}
}
**(**int32)(__ccgo_up(bp)) = **(**int32)(__ccgo_up(bp)) + nTok
/* The next token is usually the first token of the constraint
** definition. This is enough to tell the type of the constraint -
** TK_NOT means it is a NOT NULL, TK_CHECK a CHECK constraint etc.
**
** There is also the chance that the next token is TK_CONSTRAINT
** (or TK_DEFAULT or TK_COLLATE), for example if a table has been
** created as follows:
**
** CREATE TABLE t1(cols, CONSTRAINT one CONSTRAINT two NOT NULL);
**
** In this case, allow the "CONSTRAINT one" bit to be dropped by
** this command if that is what is requested, or to advance to
** the next iteration of the loop with &zSql[iOff] still pointing
** to the CONSTRAINT keyword. */
nTok = _getConstraintToken(tls, zSql+uintptr(**(**int32)(__ccgo_up(bp))), bp+4)
if **(**int32)(__ccgo_up(bp + 4)) == int32(TK_CONSTRAINT) || **(**int32)(__ccgo_up(bp + 4)) == int32(TK_DEFAULT) || **(**int32)(__ccgo_up(bp + 4)) == int32(TK_COLLATE) || **(**int32)(__ccgo_up(bp + 4)) == int32(TK_COMMA) || **(**int32)(__ccgo_up(bp + 4)) == int32(TK_RP) || **(**int32)(__ccgo_up(bp + 4)) == int32(TK_GENERATED) || **(**int32)(__ccgo_up(bp + 4)) == int32(TK_AS) {
**(**int32)(__ccgo_up(bp + 4)) = int32(TK_CHECK)
} else {
**(**int32)(__ccgo_up(bp)) = **(**int32)(__ccgo_up(bp)) + nTok
**(**int32)(__ccgo_up(bp)) = **(**int32)(__ccgo_up(bp)) + _getConstraint(tls, zSql+uintptr(**(**int32)(__ccgo_up(bp))))
}
if **(**int32)(__ccgo_up(bp + 8)) == 0 || iNotNull >= 0 && **(**int32)(__ccgo_up(bp + 4)) == int32(TK_NOT) {
if **(**int32)(__ccgo_up(bp + 4)) != int32(TK_NOT) && **(**int32)(__ccgo_up(bp + 4)) != int32(TK_CHECK) {
_errorMPrintf(tls, ctx, __ccgo_ts+12167, libc.VaList(bp+24, zCons))
return
}
iEnd = **(**int32)(__ccgo_up(bp))
break
}
} else {
if **(**int32)(__ccgo_up(bp + 4)) == int32(TK_NOT) && iNotNull == ii {
iEnd = **(**int32)(__ccgo_up(bp)) + _getConstraint(tls, zSql+uintptr(**(**int32)(__ccgo_up(bp))))
break
} else {
if **(**int32)(__ccgo_up(bp + 4)) == int32(TK_RP) || **(**int32)(__ccgo_up(bp + 4)) == int32(TK_ILLEGAL) {
iEnd = -int32(1)
break
} else {
if **(**int32)(__ccgo_up(bp + 4)) == int32(TK_COMMA) {
break
}
}
}
}
}
goto _1
_1:
;
ii = ii + 1
}
/* If the constraint has not been found it is an error. */
if iEnd <= 0 {
if zCons != 0 {
_errorMPrintf(tls, ctx, __ccgo_ts+12201, libc.VaList(bp+24, zCons))
} else {
/* SQLite follows postgres in that a DROP NOT NULL on a column that is
** not NOT NULL is not an error. So just return the original SQL here. */
Xsqlite3_result_text(tls, ctx, zSql, -int32(1), uintptr(-libc.Int32FromInt32(1)))
}
} else {
/* Figure out if an extra space should be inserted after the constraint
** is removed. And if an additional comma preceding the constraint
** should be removed. */
zSpace = __ccgo_ts + 11889
iEnd = iEnd + _getWhitespace(tls, zSql+uintptr(iEnd))
_sqlite3GetToken(tls, zSql+uintptr(iEnd), bp+4)
if **(**int32)(__ccgo_up(bp + 4)) == int32(TK_RP) || **(**int32)(__ccgo_up(bp + 4)) == int32(TK_COMMA) {
zSpace = __ccgo_ts + 1702
if libc.Int32FromUint8(**(**Tu8)(__ccgo_up(zSql + uintptr(iStart-int32(1))))) == int32(',') {
iStart = iStart - 1
}
}
db = Xsqlite3_context_db_handle(tls, ctx)
zNew = _sqlite3MPrintf(tls, db, __ccgo_ts+12224, libc.VaList(bp+24, iStart, zSql, zSpace, zSql+uintptr(iEnd)))
Xsqlite3_result_text(tls, ctx, zNew, -int32(1), __ccgo_fp(_sqlite3RowSetClear))
}
}
// C documentation
//
// /*
// ** pCArray contains pointers to and sizes of all cells in the page being
// ** balanced. The current page, pPg, has pPg->nCell cells starting with
// ** pCArray->apCell[iOld]. After balancing, this page should hold nNew cells
// ** starting at apCell[iNew].
// **
// ** This routine makes the necessary adjustments to pPg so that it contains
// ** the correct cells after being balanced.
// **
// ** The pPg->nFree field is invalid when this function returns. It is the
// ** responsibility of the caller to set it correctly.
// */
func _editPage(tls *libc.TLS, pPg uintptr, iOld int32, iNew int32, nNew int32, pCArray uintptr) (r int32) {
bp := tls.Alloc(16)
defer tls.Free(16)
var aData, pBegin, pCellptr uintptr
var hdr, i, iCell, iNewEnd, iOldEnd, nAdd, nCell, nShift, nTail, v1 int32
var _ /* pData at bp+0 */ uintptr
_, _, _, _, _, _, _, _, _, _, _, _, _ = aData, hdr, i, iCell, iNewEnd, iOldEnd, nAdd, nCell, nShift, nTail, pBegin, pCellptr, v1
aData = (*TMemPage)(unsafe.Pointer(pPg)).FaData
hdr = libc.Int32FromUint8((*TMemPage)(unsafe.Pointer(pPg)).FhdrOffset)
pBegin = (*TMemPage)(unsafe.Pointer(pPg)).FaCellIdx + uintptr(nNew*int32(2))
nCell = libc.Int32FromUint16((*TMemPage)(unsafe.Pointer(pPg)).FnCell)
iOldEnd = iOld + libc.Int32FromUint16((*TMemPage)(unsafe.Pointer(pPg)).FnCell) + libc.Int32FromUint8((*TMemPage)(unsafe.Pointer(pPg)).FnOverflow)
iNewEnd = iNew + nNew
/* Remove cells from the start and end of the page */
if iOld < iNew {
nShift = _pageFreeArray(tls, pPg, iOld, iNew-iOld, pCArray)
if nShift > nCell {
return _sqlite3CorruptError(tls, int32(81125))
}
libc.X__builtin___memmove_chk(tls, (*TMemPage)(unsafe.Pointer(pPg)).FaCellIdx, (*TMemPage)(unsafe.Pointer(pPg)).FaCellIdx+uintptr(nShift*int32(2)), libc.Uint64FromInt32(nCell*int32(2)), ^t__predefined_size_t(0))
nCell = nCell - nShift
}
if iNewEnd < iOldEnd {
nTail = _pageFreeArray(tls, pPg, iNewEnd, iOldEnd-iNewEnd, pCArray)
nCell = nCell - nTail
}
**(**uintptr)(__ccgo_up(bp)) = aData + uintptr(libc.Int32FromUint8(**(**Tu8)(__ccgo_up(aData + uintptr(hdr+int32(5)))))< (*TMemPage)(unsafe.Pointer(pPg)).FaDataEnd {
goto editpage_fail
}
/* Add cells to the start of the page */
if iNew < iOld {
if nNew < iOld-iNew {
v1 = nNew
} else {
v1 = iOld - iNew
}
nAdd = v1
pCellptr = (*TMemPage)(unsafe.Pointer(pPg)).FaCellIdx
libc.X__builtin___memmove_chk(tls, pCellptr+uintptr(nAdd*int32(2)), pCellptr, libc.Uint64FromInt32(nCell*int32(2)), ^t__predefined_size_t(0))
if _pageInsertArray(tls, pPg, pBegin, bp, pCellptr, iNew, nAdd, pCArray) != 0 {
goto editpage_fail
}
nCell = nCell + nAdd
}
/* Add any overflow cells */
i = 0
for {
if !(i < libc.Int32FromUint8((*TMemPage)(unsafe.Pointer(pPg)).FnOverflow)) {
break
}
iCell = iOld + libc.Int32FromUint16(**(**Tu16)(__ccgo_up(pPg + 28 + uintptr(i)*2))) - iNew
if iCell >= 0 && iCell < nNew {
pCellptr = (*TMemPage)(unsafe.Pointer(pPg)).FaCellIdx + uintptr(iCell*int32(2))
if nCell > iCell {
libc.X__builtin___memmove_chk(tls, pCellptr+2, pCellptr, libc.Uint64FromInt32((nCell-iCell)*int32(2)), ^t__predefined_size_t(0))
}
nCell = nCell + 1
_cachedCellSize(tls, pCArray, iCell+iNew)
if _pageInsertArray(tls, pPg, pBegin, bp, pCellptr, iCell+iNew, int32(1), pCArray) != 0 {
goto editpage_fail
}
}
goto _2
_2:
;
i = i + 1
}
/* Append cells to the end of the page */
pCellptr = (*TMemPage)(unsafe.Pointer(pPg)).FaCellIdx + uintptr(nCell*int32(2))
if _pageInsertArray(tls, pPg, pBegin, bp, pCellptr, iNew+nCell, nNew-nCell, pCArray) != 0 {
goto editpage_fail
}
(*TMemPage)(unsafe.Pointer(pPg)).FnCell = libc.Uint16FromInt32(nNew)
(*TMemPage)(unsafe.Pointer(pPg)).FnOverflow = uint8(0)
**(**Tu8)(__ccgo_up(aData + uintptr(hdr+int32(3)))) = libc.Uint8FromInt32(libc.Int32FromUint16((*TMemPage)(unsafe.Pointer(pPg)).FnCell) >> libc.Int32FromInt32(8))
**(**Tu8)(__ccgo_up(aData + uintptr(hdr+int32(3)) + 1)) = uint8((*TMemPage)(unsafe.Pointer(pPg)).FnCell)
**(**Tu8)(__ccgo_up(aData + uintptr(hdr+int32(5)))) = libc.Uint8FromInt64((int64(**(**uintptr)(__ccgo_up(bp))) - int64(aData)) >> libc.Int32FromInt32(8))
**(**Tu8)(__ccgo_up(aData + uintptr(hdr+int32(5)) + 1)) = libc.Uint8FromInt64(int64(**(**uintptr)(__ccgo_up(bp))) - int64(aData))
return SQLITE_OK
goto editpage_fail
editpage_fail:
;
/* Unable to edit this page. Rebuild it from scratch instead. */
if nNew < int32(1) {
return _sqlite3CorruptError(tls, int32(81203))
}
_populateCellCache(tls, pCArray, iNew, nNew)
return _rebuildPage(tls, pCArray, iNew, nNew, pPg)
}
var _encnames = [4]uintptr{
0: __ccgo_ts + 5607,
1: __ccgo_ts + 5609,
2: __ccgo_ts + 5611,
3: __ccgo_ts + 5616,
}
var _encnames1 = [9]struct {
FzName uintptr
Fenc Tu8
}{
0: {
FzName: __ccgo_ts + 20189,
Fenc: uint8(SQLITE_UTF8),
},
1: {
FzName: __ccgo_ts + 20194,
Fenc: uint8(SQLITE_UTF8),
},
2: {
FzName: __ccgo_ts + 20200,
Fenc: uint8(SQLITE_UTF16LE),
},
3: {
FzName: __ccgo_ts + 20209,
Fenc: uint8(SQLITE_UTF16BE),
},
4: {
FzName: __ccgo_ts + 20218,
Fenc: uint8(SQLITE_UTF16LE),
},
5: {
FzName: __ccgo_ts + 20226,
Fenc: uint8(SQLITE_UTF16BE),
},
6: {
FzName: __ccgo_ts + 20234,
},
7: {
FzName: __ccgo_ts + 20241,
},
8: {},
}
// C documentation
//
// /*
// ** The StrAccum "p" is not large enough to accept N new bytes of z[].
// ** So enlarge if first, then do the append.
// **
// ** This is a helper routine to sqlite3_str_append() that does special-case
// ** work (enlarging the buffer) using tail recursion, so that the
// ** sqlite3_str_append() routine can use fast calling semantics.
// */
func _enlargeAndAppend(tls *libc.TLS, p uintptr, z uintptr, N int32) {
N = _sqlite3StrAccumEnlarge(tls, p, int64(N))
if N > 0 {
libc.X__builtin___memcpy_chk(tls, (*TStrAccum)(unsafe.Pointer(p)).FzText+uintptr((*TStrAccum)(unsafe.Pointer(p)).FnChar), z, libc.Uint64FromInt32(N), ^t__predefined_size_t(0))
**(**Tu32)(__ccgo_up(p + 24)) += libc.Uint32FromInt32(N)
}
}
// C documentation
//
// /*
// ** Execute zSql on database db.
// **
// ** If zSql returns rows, then each row will have exactly one
// ** column. (This will only happen if zSql begins with "SELECT".)
// ** Take each row of result and call execSql() again recursively.
// **
// ** The execSqlF() routine does the same thing, except it accepts
// ** a format string as its third argument
// */
func _execSql(tls *libc.TLS, db uintptr, pzErrMsg uintptr, zSql uintptr) (r int32) {
bp := tls.Alloc(16)
defer tls.Free(16)
var rc, v1 int32
var zSubSql uintptr
var _ /* pStmt at bp+0 */ uintptr
_, _, _ = rc, zSubSql, v1
/* printf("SQL: [%s]\n", zSql); fflush(stdout); */
rc = Xsqlite3_prepare_v2(tls, db, zSql, -int32(1), bp, uintptr(0))
if rc != SQLITE_OK {
return rc
}
for {
v1 = Xsqlite3_step(tls, **(**uintptr)(__ccgo_up(bp)))
rc = v1
if !(int32(SQLITE_ROW) == v1) {
break
}
zSubSql = Xsqlite3_column_text(tls, **(**uintptr)(__ccgo_up(bp)), 0)
/* The secondary SQL must be one of CREATE TABLE, CREATE INDEX,
** or INSERT. Historically there have been attacks that first
** corrupt the sqlite_schema.sql field with other kinds of statements
** then run VACUUM to get those statements to execute at inappropriate
** times. */
if zSubSql != 0 && (libc.Xstrncmp(tls, zSubSql, __ccgo_ts+23124, uint64(3)) == 0 || libc.Xstrncmp(tls, zSubSql, __ccgo_ts+23128, uint64(3)) == 0) {
rc = _execSql(tls, db, pzErrMsg, zSubSql)
if rc != SQLITE_OK {
break
}
}
}
if rc == int32(SQLITE_DONE) {
rc = SQLITE_OK
}
if rc != 0 {
_sqlite3SetString(tls, pzErrMsg, db, Xsqlite3_errmsg(tls, db))
}
Xsqlite3_finalize(tls, **(**uintptr)(__ccgo_up(bp)))
return rc
}
// C documentation
//
// /*
// ** Argument pWhere is the WHERE clause belonging to SELECT statement p. This
// ** function attempts to transform expressions of the form:
// **
// ** EXISTS (SELECT ...)
// **
// ** into joins. For example, given
// **
// ** CREATE TABLE sailors(sid INTEGER PRIMARY KEY, name TEXT);
// ** CREATE TABLE reserves(sid INT, day DATE, PRIMARY KEY(sid, day));
// **
// ** SELECT name FROM sailors AS S WHERE EXISTS (
// ** SELECT * FROM reserves AS R WHERE S.sid = R.sid AND R.day = '2022-10-25'
// ** );
// **
// ** the SELECT statement may be transformed as follows:
// **
// ** SELECT name FROM sailors AS S, reserves AS R
// ** WHERE S.sid = R.sid AND R.day = '2022-10-25';
// **
// ** **Approximately**. Really, we have to ensure that the FROM-clause term
// ** that was formerly inside the EXISTS is only executed once. This is handled
// ** by setting the SrcItem.fg.fromExists flag, which then causes code in
// ** the where.c file to exit the corresponding loop after the first successful
// ** match (if any).
// */
func _existsToJoin(tls *libc.TLS, pParse uintptr, p uintptr, pWhere uintptr) {
var aCsrMap, db, pRight, pSub, pSubWhere uintptr
_, _, _, _, _ = aCsrMap, db, pRight, pSub, pSubWhere
if (*TParse)(unsafe.Pointer(pParse)).FnErr == 0 && pWhere != uintptr(0) && !((*TExpr)(unsafe.Pointer(pWhere)).Fflags&libc.Uint32FromInt32(libc.Int32FromInt32(EP_OuterON)|libc.Int32FromInt32(EP_InnerON)) != libc.Uint32FromInt32(0)) && (*TSelect)(unsafe.Pointer(p)).FpSrc != uintptr(0) && (*TSrcList)(unsafe.Pointer((*TSelect)(unsafe.Pointer(p)).FpSrc)).FnSrc < libc.Int32FromUint64(libc.Uint64FromInt64(8)*libc.Uint64FromInt32(8)) && ((*TSelect)(unsafe.Pointer(p)).FpLimit == uintptr(0) || (*TExpr)(unsafe.Pointer((*TSelect)(unsafe.Pointer(p)).FpLimit)).FpRight == uintptr(0)) {
if libc.Int32FromUint8((*TExpr)(unsafe.Pointer(pWhere)).Fop) == int32(TK_AND) {
pRight = (*TExpr)(unsafe.Pointer(pWhere)).FpRight
_existsToJoin(tls, pParse, p, (*TExpr)(unsafe.Pointer(pWhere)).FpLeft)
_existsToJoin(tls, pParse, p, pRight)
} else {
if libc.Int32FromUint8((*TExpr)(unsafe.Pointer(pWhere)).Fop) == int32(TK_EXISTS) {
pSub = *(*uintptr)(unsafe.Pointer(pWhere + 32))
pSubWhere = (*TSelect)(unsafe.Pointer(pSub)).FpWhere
if (*TSrcList)(unsafe.Pointer((*TSelect)(unsafe.Pointer(pSub)).FpSrc)).FnSrc == int32(1) && (*TSelect)(unsafe.Pointer(pSub)).FselFlags&uint32(SF_Aggregate) == uint32(0) && !(int32(*(*uint32)(unsafe.Pointer((*TSelect)(unsafe.Pointer(pSub)).FpSrc + 8 + 24 + 4))&0x4>>2) != 0) && (*TSelect)(unsafe.Pointer(pSub)).FpLimit == uintptr(0) && (*TSelect)(unsafe.Pointer(pSub)).FpPrior == uintptr(0) {
/* Before combining the sub-select with the parent, renumber the
** cursor used by the subselect. This is because the EXISTS expression
** might be a copy of another EXISTS expression from somewhere
** else in the tree, and in this case it is important that it use
** a unique cursor number. */
db = (*TParse)(unsafe.Pointer(pParse)).Fdb
aCsrMap = _sqlite3DbMallocZero(tls, db, uint64(libc.Uint64FromInt32((*TParse)(unsafe.Pointer(pParse)).FnTab+libc.Int32FromInt32(2))*uint64(4)))
if aCsrMap == uintptr(0) {
return
}
**(**int32)(__ccgo_up(aCsrMap)) = (*TParse)(unsafe.Pointer(pParse)).FnTab + int32(1)
_renumberCursors(tls, pParse, pSub, -int32(1), aCsrMap)
_sqlite3DbFree(tls, db, aCsrMap)
libc.X__builtin___memset_chk(tls, pWhere, 0, uint64(72), ^t__predefined_size_t(0))
(*TExpr)(unsafe.Pointer(pWhere)).Fop = uint8(TK_INTEGER)
*(*int32)(unsafe.Pointer(&(*TExpr)(unsafe.Pointer(pWhere)).Fu)) = int32(1)
**(**Tu32)(__ccgo_up(pWhere + 4)) |= libc.Uint32FromInt32(libc.Int32FromInt32(EP_IntValue))
libc.SetBitFieldPtr32Uint32((*TSelect)(unsafe.Pointer(pSub)).FpSrc+8+24+4, libc.Uint32FromInt32(1), 18, 0x40000)
(*TSelect)(unsafe.Pointer(p)).FpSrc = _sqlite3SrcListAppendList(tls, pParse, (*TSelect)(unsafe.Pointer(p)).FpSrc, (*TSelect)(unsafe.Pointer(pSub)).FpSrc)
if pSubWhere != 0 {
(*TSelect)(unsafe.Pointer(p)).FpWhere = _sqlite3PExpr(tls, pParse, int32(TK_AND), (*TSelect)(unsafe.Pointer(p)).FpWhere, pSubWhere)
(*TSelect)(unsafe.Pointer(pSub)).FpWhere = uintptr(0)
}
(*TSelect)(unsafe.Pointer(pSub)).FpSrc = uintptr(0)
_sqlite3ParserAddCleanup(tls, pParse, __ccgo_fp(_sqlite3SelectDeleteGeneric), pSub)
}
}
}
}
}
// C documentation
//
// /*
// ** This routine is a helper for explainIndexRange() below
// **
// ** pStr holds the text of an expression that we are building up one term
// ** at a time. This routine adds a new term to the end of the expression.
// ** Terms are separated by AND so add the "AND" text for second and subsequent
// ** terms only.
// */
func _explainAppendTerm(tls *libc.TLS, pStr uintptr, pIdx uintptr, nTerm int32, iTerm int32, bAnd int32, zOp uintptr) {
var i int32
_ = i
if bAnd != 0 {
Xsqlite3_str_append(tls, pStr, __ccgo_ts+24020, int32(5))
}
if nTerm > int32(1) {
Xsqlite3_str_append(tls, pStr, __ccgo_ts+24026, int32(1))
}
i = 0
for {
if !(i < nTerm) {
break
}
if i != 0 {
Xsqlite3_str_append(tls, pStr, __ccgo_ts+14694, int32(1))
}
Xsqlite3_str_appendall(tls, pStr, _explainIndexColumnName(tls, pIdx, iTerm+i))
goto _1
_1:
;
i = i + 1
}
if nTerm > int32(1) {
Xsqlite3_str_append(tls, pStr, __ccgo_ts+5605, int32(1))
}
Xsqlite3_str_append(tls, pStr, zOp, int32(1))
if nTerm > int32(1) {
Xsqlite3_str_append(tls, pStr, __ccgo_ts+24026, int32(1))
}
i = 0
for {
if !(i < nTerm) {
break
}
if i != 0 {
Xsqlite3_str_append(tls, pStr, __ccgo_ts+14694, int32(1))
}
Xsqlite3_str_append(tls, pStr, __ccgo_ts+5607, int32(1))
goto _2
_2:
;
i = i + 1
}
if nTerm > int32(1) {
Xsqlite3_str_append(tls, pStr, __ccgo_ts+5605, int32(1))
}
}
// C documentation
//
// /*
// ** Return the name of the i-th column of the pIdx index.
// */
func _explainIndexColumnName(tls *libc.TLS, pIdx uintptr, i int32) (r uintptr) {
i = int32(**(**Ti16)(__ccgo_up((*TIndex)(unsafe.Pointer(pIdx)).FaiColumn + uintptr(i)*2)))
if i == -int32(2) {
return __ccgo_ts + 24013
}
if i == -int32(1) {
return __ccgo_ts + 18314
}
return (**(**TColumn)(__ccgo_up((*TTable)(unsafe.Pointer((*TIndex)(unsafe.Pointer(pIdx)).FpTable)).FaCol + uintptr(i)*16))).FzCnName
}
// C documentation
//
// /*
// ** Argument pLevel describes a strategy for scanning table pTab. This
// ** function appends text to pStr that describes the subset of table
// ** rows scanned by the strategy in the form of an SQL expression.
// **
// ** For example, if the query:
// **
// ** SELECT * FROM t1 WHERE a=1 AND b>2;
// **
// ** is run and there is an index on (a, b), then this function returns a
// ** string similar to:
// **
// ** "a=? AND b>?"
// */
func _explainIndexRange(tls *libc.TLS, pStr uintptr, pLoop uintptr) {
bp := tls.Alloc(16)
defer tls.Free(16)
var i, j int32
var nEq, nSkip Tu16
var pIndex, z, v2 uintptr
_, _, _, _, _, _, _ = i, j, nEq, nSkip, pIndex, z, v2
pIndex = (*(*struct {
FnEq Tu16
FnBtm Tu16
FnTop Tu16
FnDistinctCol Tu16
FpIndex uintptr
FpOrderBy uintptr
})(unsafe.Pointer(pLoop + 24))).FpIndex
nEq = (*(*struct {
FnEq Tu16
FnBtm Tu16
FnTop Tu16
FnDistinctCol Tu16
FpIndex uintptr
FpOrderBy uintptr
})(unsafe.Pointer(pLoop + 24))).FnEq
nSkip = (*TWhereLoop)(unsafe.Pointer(pLoop)).FnSkip
if libc.Int32FromUint16(nEq) == 0 && (*TWhereLoop)(unsafe.Pointer(pLoop)).FwsFlags&libc.Uint32FromInt32(libc.Int32FromInt32(WHERE_BTM_LIMIT)|libc.Int32FromInt32(WHERE_TOP_LIMIT)) == uint32(0) {
return
}
Xsqlite3_str_append(tls, pStr, __ccgo_ts+24028, int32(2))
i = 0
for {
if !(i < libc.Int32FromUint16(nEq)) {
break
}
z = _explainIndexColumnName(tls, pIndex, i)
if i != 0 {
Xsqlite3_str_append(tls, pStr, __ccgo_ts+24020, int32(5))
}
if i >= libc.Int32FromUint16(nSkip) {
v2 = __ccgo_ts + 24031
} else {
v2 = __ccgo_ts + 24036
}
Xsqlite3_str_appendf(tls, pStr, v2, libc.VaList(bp+8, z))
goto _1
_1:
;
i = i + 1
}
j = i
if (*TWhereLoop)(unsafe.Pointer(pLoop)).FwsFlags&uint32(WHERE_BTM_LIMIT) != 0 {
_explainAppendTerm(tls, pStr, pIndex, libc.Int32FromUint16((*(*struct {
FnEq Tu16
FnBtm Tu16
FnTop Tu16
FnDistinctCol Tu16
FpIndex uintptr
FpOrderBy uintptr
})(unsafe.Pointer(pLoop + 24))).FnBtm), j, i, __ccgo_ts+24044)
i = int32(1)
}
if (*TWhereLoop)(unsafe.Pointer(pLoop)).FwsFlags&uint32(WHERE_TOP_LIMIT) != 0 {
_explainAppendTerm(tls, pStr, pIndex, libc.Int32FromUint16((*(*struct {
FnEq Tu16
FnBtm Tu16
FnTop Tu16
FnDistinctCol Tu16
FpIndex uintptr
FpOrderBy uintptr
})(unsafe.Pointer(pLoop + 24))).FnTop), j, i, __ccgo_ts+24046)
}
Xsqlite3_str_append(tls, pStr, __ccgo_ts+5605, int32(1))
}
// C documentation
//
// /*
// ** Add a single OP_Explain instruction to the VDBE to explain a simple
// ** count(*) query ("SELECT count(*) FROM pTab").
// */
func _explainSimpleCount(tls *libc.TLS, pParse uintptr, pTab uintptr, pIdx uintptr) {
bp := tls.Alloc(32)
defer tls.Free(32)
var bCover int32
var v1, v2 uintptr
_, _, _ = bCover, v1, v2
if libc.Int32FromUint8((*TParse)(unsafe.Pointer(pParse)).Fexplain) == int32(2) {
bCover = libc.BoolInt32(pIdx != uintptr(0) && ((*TTable)(unsafe.Pointer(pTab)).FtabFlags&uint32(TF_WithoutRowid) == uint32(0) || !(int32(uint32(*(*uint16)(unsafe.Pointer(pIdx + 100))&0x3>>0)) == libc.Int32FromInt32(SQLITE_IDXTYPE_PRIMARYKEY))))
if bCover != 0 {
v1 = __ccgo_ts + 21920
} else {
v1 = __ccgo_ts + 1702
}
if bCover != 0 {
v2 = (*TIndex)(unsafe.Pointer(pIdx)).FzName
} else {
v2 = __ccgo_ts + 1702
}
_sqlite3VdbeExplain(tls, pParse, uint8(0), __ccgo_ts+21943, libc.VaList(bp+8, (*TTable)(unsafe.Pointer(pTab)).FzName, v1, v2))
}
}
// C documentation
//
// /*
// ** Unless an "EXPLAIN QUERY PLAN" command is being processed, this function
// ** is a no-op. Otherwise, it adds a single row of output to the EQP result,
// ** where the caption is of the form:
// **
// ** "USE TEMP B-TREE FOR xxx"
// **
// ** where xxx is one of "DISTINCT", "ORDER BY" or "GROUP BY". Exactly which
// ** is determined by the zUsage argument.
// */
func _explainTempTable(tls *libc.TLS, pParse uintptr, zUsage uintptr) {
bp := tls.Alloc(16)
defer tls.Free(16)
_sqlite3VdbeExplain(tls, pParse, uint8(0), __ccgo_ts+20915, libc.VaList(bp+8, zUsage))
}
/*
** Assign expression b to lvalue a. A second, no-op, version of this macro
** is provided when SQLITE_OMIT_EXPLAIN is defined. This allows the code
** in sqlite3Select() to assign values to structure member variables that
** only exist if SQLITE_OMIT_EXPLAIN is not defined without polluting the
** code with #ifndef directives.
*/
// C documentation
//
// /*
// ** 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 " X" it gets commuted
// ** to the standard form of "X ".
// **
// ** If the expression is of the form "X Y" where both X and Y are
// ** columns, then the original expression is unchanged and a new virtual
// ** term of the form "Y 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(48)
defer tls.Free(48)
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+24 */ [2]int32
var _ /* eOp2 at bp+16 */ uint8
var _ /* isComplete at bp+8 */ int32
var _ /* noCase at bp+12 */ int32
var _ /* pLeft at bp+40 */ uintptr
var _ /* pRight at bp+32 */ 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 + 8)) = 0 /* RHS of LIKE/GLOB ends with wildcard */
**(**int32)(__ccgo_up(bp + 12)) = 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 + 16)) = 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)*56
pMaskSet = pWInfo + 592
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 + 32)))
} else {
(*TWhereTerm)(unsafe.Pointer(pTerm)).FprereqRight = _sqlite3WhereExprListUsage(tls, pMaskSet, *(*uintptr)(unsafe.Pointer(pExpr + 32)))
}
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 + 32)) != uintptr(0) {
prereqAll = _sqlite3WhereExprUsageNN(tls, pMaskSet, pExpr)
} else {
prereqAll = prereqLeft | (*TWhereTerm)(unsafe.Pointer(pTerm)).FprereqRight
}
}
if (*TWhereMaskSet)(unsafe.Pointer(pMaskSet)).FbVarSelect != 0 {
v1 = pTerm + 18
*(*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 + 52)))
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 + 32))).FiField > 0 {
pLeft = (*(*TExprList_item)(unsafe.Pointer(*(*uintptr)(unsafe.Pointer(pLeft + 32)) + 8 + uintptr((*(*struct {
FleftColumn int32
FiField int32
})(unsafe.Pointer(pTerm + 32))).FiField-int32(1))*32))).FpExpr
}
if _exprMightBeIndexed(tls, pSrc, bp+24, pLeft, op) != 0 {
(*TWhereTerm)(unsafe.Pointer(pTerm)).FleftCursor = (**(**[2]int32)(__ccgo_up(bp + 24)))[0]
(*(*struct {
FleftColumn int32
FiField int32
})(unsafe.Pointer(pTerm + 32))).FleftColumn = (**(**[2]int32)(__ccgo_up(bp + 24)))[int32(1)]
(*TWhereTerm)(unsafe.Pointer(pTerm)).FeOperator = libc.Uint16FromInt32(libc.Int32FromUint16(_operatorMask(tls, op)) & libc.Int32FromUint16(opMask))
}
if op == int32(TK_IS) {
v1 = pTerm + 18
*(*Tu16)(unsafe.Pointer(v1)) = Tu16(int32(*(*Tu16)(unsafe.Pointer(v1))) | libc.Int32FromInt32(TERM_IS))
}
if pRight != 0 && _exprMightBeIndexed(tls, pSrc, bp+24, 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)*56
_markTermAsChild(tls, pWC, idxNew, idxTerm)
if op == int32(TK_IS) {
v1 = pNew + 18
*(*Tu16)(unsafe.Pointer(v1)) = Tu16(int32(*(*Tu16)(unsafe.Pointer(v1))) | libc.Int32FromInt32(TERM_IS))
}
pTerm = (*TWhereClause)(unsafe.Pointer(pWC)).Fa + uintptr(idxTerm)*56
v1 = pTerm + 18
*(*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 + 20
*(*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 + 18
*(*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 + 24)))[0]
(*(*struct {
FleftColumn int32
FiField int32
})(unsafe.Pointer(pNew + 32))).FleftColumn = (**(**[2]int32)(__ccgo_up(bp + 24)))[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 + 8531
**(**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 + 32))
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)*32))).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)*56
_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)*56
} 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)*56
(*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 + 32))).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)*56
v1 = pTerm + 18
*(*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+8, bp+12) != 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 + 32)) + 8 + 1*32))).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 + 12)) != 0 && !((*Tsqlite3)(unsafe.Pointer((*TParse)(unsafe.Pointer(pParse)).Fdb)).FmallocFailed != 0) {
v1 = pTerm + 18
*(*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 + 12)) != 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 + 8)) = 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 + 12)) != 0 {
v1 = __ccgo_ts + 24336
} 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)*56
if **(**int32)(__ccgo_up(bp + 8)) != 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)*56
v1 = pTerm + 18
*(*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 + 32))).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 + 32)))).FpPrior == uintptr(0) || (*TSelect)(unsafe.Pointer(*(*uintptr)(unsafe.Pointer(pExpr + 32)))).FselFlags&uint32(SF_Values) != 0) && (*TSelect)(unsafe.Pointer(*(*uintptr)(unsafe.Pointer(pExpr + 32)))).FpWin == uintptr(0) && libc.Int32FromUint8((*TWhereClause)(unsafe.Pointer(pWC)).Fop) == int32(TK_AND) && int64((*TExprList)(unsafe.Pointer((*TSelect)(unsafe.Pointer(*(*uintptr)(unsafe.Pointer(pExpr + 32)))).FpEList)).FnExpr) <= libc.Int64FromInt32(1)<<(libc.Uint64FromInt64(1)*libc.Uint64FromInt32(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)*56 + 32 + 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 + 32)) = uintptr(0)
**(**uintptr)(__ccgo_up(bp + 40)) = uintptr(0)
res = _isAuxiliaryVtabOperator(tls, db, pExpr, bp+16, bp+40, bp+32)
for {
v2 = res
res = res - 1
if !(v2 > 0) {
break
}
prereqExpr = _sqlite3WhereExprUsage(tls, pMaskSet, **(**uintptr)(__ccgo_up(bp + 32)))
prereqColumn = _sqlite3WhereExprUsage(tls, pMaskSet, **(**uintptr)(__ccgo_up(bp + 40)))
if prereqExpr&prereqColumn == uint64(0) {
pNewExpr2 = _sqlite3PExpr(tls, pParse, int32(TK_MATCH), uintptr(0), _sqlite3ExprDup(tls, db, **(**uintptr)(__ccgo_up(bp + 32)), 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 + 52)) = *(*int32)(unsafe.Pointer(pExpr + 52))
}
idxNew5 = _whereClauseInsert(tls, pWC, pNewExpr2, libc.Uint16FromInt32(libc.Int32FromInt32(TERM_VIRTUAL)|libc.Int32FromInt32(TERM_DYNAMIC)))
pNewTerm1 = (*TWhereClause)(unsafe.Pointer(pWC)).Fa + uintptr(idxNew5)*56
(*TWhereTerm)(unsafe.Pointer(pNewTerm1)).FprereqRight = prereqExpr | extraRight
(*TWhereTerm)(unsafe.Pointer(pNewTerm1)).FleftCursor = (*TExpr)(unsafe.Pointer(**(**uintptr)(__ccgo_up(bp + 40)))).FiTable
(*(*struct {
FleftColumn int32
FiField int32
})(unsafe.Pointer(pNewTerm1 + 32))).FleftColumn = int32((*TExpr)(unsafe.Pointer(**(**uintptr)(__ccgo_up(bp + 40)))).FiColumn)
(*TWhereTerm)(unsafe.Pointer(pNewTerm1)).FeOperator = uint16(WO_AUX)
(*TWhereTerm)(unsafe.Pointer(pNewTerm1)).FeMatchOp = **(**uint8)(__ccgo_up(bp + 16))
_markTermAsChild(tls, pWC, idxNew5, idxTerm)
pTerm = (*TWhereClause)(unsafe.Pointer(pWC)).Fa + uintptr(idxTerm)*56
v1 = pTerm + 18
*(*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 + 40))
**(**uintptr)(__ccgo_up(bp + 40)) = **(**uintptr)(__ccgo_up(bp + 32))
**(**uintptr)(__ccgo_up(bp + 32)) = 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)*56
**(**TBitmask)(__ccgo_up(pTerm + 40)) |= extraRight
}
// C documentation
//
// /*
// ** Analyze a term that consists of two or more OR-connected
// ** subterms. So in:
// **
// ** ... WHERE (a=5) AND (b=7 OR c=9 OR d=13) AND (d=13)
// ** ^^^^^^^^^^^^^^^^^^^^
// **
// ** This routine analyzes terms such as the middle term in the above example.
// ** A WhereOrTerm object is computed and attached to the term under
// ** analysis, regardless of the outcome of the analysis. Hence:
// **
// ** WhereTerm.wtFlags |= TERM_ORINFO
// ** WhereTerm.u.pOrInfo = a dynamically allocated WhereOrTerm object
// **
// ** The term being analyzed must have two or more of OR-connected subterms.
// ** A single subterm might be a set of AND-connected sub-subterms.
// ** Examples of terms under analysis:
// **
// ** (A) t1.x=t2.y OR t1.x=t2.z OR t1.y=15 OR t1.z=t3.a+5
// ** (B) x=expr1 OR expr2=x OR x=expr3
// ** (C) t1.x=t2.y OR (t1.x=t2.z AND t1.y=15)
// ** (D) x=expr1 OR (y>11 AND y<22 AND z LIKE '*hello*')
// ** (E) (p.a=1 AND q.b=2 AND r.c=3) OR (p.x=4 AND q.y=5 AND r.z=6)
// ** (F) x>A OR (x=A AND y>=B)
// **
// ** CASE 1:
// **
// ** If all subterms are of the form T.C=expr for some single column of C and
// ** a single table T (as shown in example B above) then create a new virtual
// ** term that is an equivalent IN expression. In other words, if the term
// ** being analyzed is:
// **
// ** x = expr1 OR expr2 = x OR x = expr3
// **
// ** then create a new virtual term like this:
// **
// ** x IN (expr1,expr2,expr3)
// **
// ** CASE 2:
// **
// ** If there are exactly two disjuncts and one side has x>A and the other side
// ** has x=A (for the same x and A) then add a new virtual conjunct term to the
// ** WHERE clause of the form "x>=A". Example:
// **
// ** x>A OR (x=A AND y>B) adds: x>=A
// **
// ** The added conjunct can sometimes be helpful in query planning.
// **
// ** CASE 3:
// **
// ** If all subterms are indexable by a single table T, then set
// **
// ** WhereTerm.eOperator = WO_OR
// ** WhereTerm.u.pOrInfo->indexable |= the cursor number for table T
// **
// ** A subterm is "indexable" if it is of the form
// ** "T.C " where C is any column of table T and
// ** is one of "=", "<", "<=", ">", ">=", "IS NULL", or "IN".
// ** A subterm is also indexable if it is an AND of two or more
// ** subsubterms at least one of which is indexable. Indexable AND
// ** subterms have their eOperator set to WO_AND and they have
// ** u.pAndInfo set to a dynamically allocated WhereAndTerm object.
// **
// ** From another point of view, "indexable" means that the subterm could
// ** potentially be used with an index if an appropriate index exists.
// ** This analysis does not consider whether or not the index exists; that
// ** is decided elsewhere. This analysis only looks at whether subterms
// ** appropriate for indexing exist.
// **
// ** All examples A through E above satisfy case 3. But if a term
// ** also satisfies case 1 (such as B) we know that the optimizer will
// ** always prefer case 1, so in that case we pretend that case 3 is not
// ** satisfied.
// **
// ** It might be the case that multiple tables are indexable. For example,
// ** (E) above is indexable on tables P, Q, and R.
// **
// ** Terms that satisfy case 3 are candidates for lookup by using
// ** separate indices to find rowids for each subterm and composing
// ** the union of all rowids using a RowSet object. This is similar
// ** to "bitmap indices" in other database engines.
// **
// ** OTHERWISE:
// **
// ** If none of cases 1, 2, or 3 apply, then leave the eOperator set to
// ** zero. This term is not useful for search.
// */
func _exprAnalyzeOrTerm(tls *libc.TLS, pSrc uintptr, pWC uintptr, idxTerm int32) {
var affLeft, affRight, i, iColumn, iCursor, iOne, iTwo, idxNew, j, j1, okToChngToIN, v7, v9 int32
var b, b1, chngToIN, indexable TBitmask
var db, pAndInfo, pAndTerm, pAndWC, pDup, pExpr, pLeft, pLeft1, pList, pNew, pOne, pOrInfo, pOrTerm, pOrWc, pOther, pParse, pTerm, pTwo, pWInfo, v1, v2 uintptr
_, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _ = affLeft, affRight, b, b1, chngToIN, db, i, iColumn, iCursor, iOne, iTwo, idxNew, indexable, j, j1, okToChngToIN, pAndInfo, pAndTerm, pAndWC, pDup, pExpr, pLeft, pLeft1, pList, pNew, pOne, pOrInfo, pOrTerm, pOrWc, pOther, pParse, pTerm, pTwo, pWInfo, v1, v2, v7, v9
pWInfo = (*TWhereClause)(unsafe.Pointer(pWC)).FpWInfo /* WHERE clause processing context */
pParse = (*TWhereInfo)(unsafe.Pointer(pWInfo)).FpParse /* Parser context */
db = (*TParse)(unsafe.Pointer(pParse)).Fdb /* Database connection */
pTerm = (*TWhereClause)(unsafe.Pointer(pWC)).Fa + uintptr(idxTerm)*56 /* The term to be analyzed */
pExpr = (*TWhereTerm)(unsafe.Pointer(pTerm)).FpExpr /* Tables that are indexable, satisfying case 2 */
/*
** Break the OR clause into its separate subterms. The subterms are
** stored in a WhereClause structure containing within the WhereOrInfo
** object that is attached to the original OR clause term.
*/
v1 = _sqlite3DbMallocZero(tls, db, uint64(496))
pOrInfo = v1
*(*uintptr)(unsafe.Pointer(pTerm + 32)) = v1
if pOrInfo == uintptr(0) {
return
}
v1 = pTerm + 18
*(*Tu16)(unsafe.Pointer(v1)) = Tu16(int32(*(*Tu16)(unsafe.Pointer(v1))) | libc.Int32FromInt32(TERM_ORINFO))
pOrWc = pOrInfo
libc.X__builtin___memset_chk(tls, pOrWc+40, 0, uint64(448), ^t__predefined_size_t(0))
_sqlite3WhereClauseInit(tls, pOrWc, pWInfo)
_sqlite3WhereSplit(tls, pOrWc, pExpr, uint8(TK_OR))
_sqlite3WhereExprAnalyze(tls, pSrc, pOrWc)
if (*Tsqlite3)(unsafe.Pointer(db)).FmallocFailed != 0 {
return
}
/*
** Compute the set of tables that might satisfy cases 1 or 3.
*/
indexable = ^libc.Uint64FromInt32(0)
chngToIN = ^libc.Uint64FromInt32(0)
i = (*TWhereClause)(unsafe.Pointer(pOrWc)).FnTerm - int32(1)
pOrTerm = (*TWhereClause)(unsafe.Pointer(pOrWc)).Fa
for {
if !(i >= 0 && indexable != 0) {
break
}
if libc.Int32FromUint16((*TWhereTerm)(unsafe.Pointer(pOrTerm)).FeOperator)&int32(WO_SINGLE) == 0 {
chngToIN = uint64(0)
pAndInfo = _sqlite3DbMallocRawNN(tls, db, uint64(488))
if pAndInfo != 0 {
b = uint64(0)
*(*uintptr)(unsafe.Pointer(pOrTerm + 32)) = pAndInfo
v1 = pOrTerm + 18
*(*Tu16)(unsafe.Pointer(v1)) = Tu16(int32(*(*Tu16)(unsafe.Pointer(v1))) | libc.Int32FromInt32(TERM_ANDINFO))
(*TWhereTerm)(unsafe.Pointer(pOrTerm)).FeOperator = uint16(WO_AND)
(*TWhereTerm)(unsafe.Pointer(pOrTerm)).FleftCursor = -int32(1)
pAndWC = pAndInfo
libc.X__builtin___memset_chk(tls, pAndWC+40, 0, uint64(448), ^t__predefined_size_t(0))
_sqlite3WhereClauseInit(tls, pAndWC, (*TWhereClause)(unsafe.Pointer(pWC)).FpWInfo)
_sqlite3WhereSplit(tls, pAndWC, (*TWhereTerm)(unsafe.Pointer(pOrTerm)).FpExpr, uint8(TK_AND))
_sqlite3WhereExprAnalyze(tls, pSrc, pAndWC)
(*TWhereClause)(unsafe.Pointer(pAndWC)).FpOuter = pWC
if !((*Tsqlite3)(unsafe.Pointer(db)).FmallocFailed != 0) {
j = 0
pAndTerm = (*TWhereClause)(unsafe.Pointer(pAndWC)).Fa
for {
if !(j < (*TWhereClause)(unsafe.Pointer(pAndWC)).FnTerm) {
break
}
if _allowedOp(tls, libc.Int32FromUint8((*TExpr)(unsafe.Pointer((*TWhereTerm)(unsafe.Pointer(pAndTerm)).FpExpr)).Fop)) != 0 || libc.Int32FromUint16((*TWhereTerm)(unsafe.Pointer(pAndTerm)).FeOperator) == int32(WO_AUX) {
b = b | _sqlite3WhereGetMask(tls, pWInfo+592, (*TWhereTerm)(unsafe.Pointer(pAndTerm)).FleftCursor)
}
goto _5
_5:
;
j = j + 1
pAndTerm += 56
}
}
indexable = indexable & b
}
} else {
if libc.Int32FromUint16((*TWhereTerm)(unsafe.Pointer(pOrTerm)).FwtFlags)&int32(TERM_COPIED) != 0 {
/* Skip this term for now. We revisit it when we process the
** corresponding TERM_VIRTUAL term */
} else {
b1 = _sqlite3WhereGetMask(tls, pWInfo+592, (*TWhereTerm)(unsafe.Pointer(pOrTerm)).FleftCursor)
if libc.Int32FromUint16((*TWhereTerm)(unsafe.Pointer(pOrTerm)).FwtFlags)&int32(TERM_VIRTUAL) != 0 {
pOther = (*TWhereClause)(unsafe.Pointer(pOrWc)).Fa + uintptr((*TWhereTerm)(unsafe.Pointer(pOrTerm)).FiParent)*56
b1 = b1 | _sqlite3WhereGetMask(tls, pWInfo+592, (*TWhereTerm)(unsafe.Pointer(pOther)).FleftCursor)
}
indexable = indexable & b1
if libc.Int32FromUint16((*TWhereTerm)(unsafe.Pointer(pOrTerm)).FeOperator)&int32(WO_EQ) == 0 {
chngToIN = uint64(0)
} else {
chngToIN = chngToIN & b1
}
}
}
goto _3
_3:
;
i = i - 1
pOrTerm += 56
}
/*
** Record the set of tables that satisfy case 3. The set might be
** empty.
*/
(*TWhereOrInfo)(unsafe.Pointer(pOrInfo)).Findexable = indexable
(*TWhereTerm)(unsafe.Pointer(pTerm)).FeOperator = uint16(WO_OR)
(*TWhereTerm)(unsafe.Pointer(pTerm)).FleftCursor = -int32(1)
if indexable != 0 {
(*TWhereClause)(unsafe.Pointer(pWC)).FhasOr = uint8(1)
}
/* For a two-way OR, attempt to implementation case 2.
*/
if indexable != 0 && (*TWhereClause)(unsafe.Pointer(pOrWc)).FnTerm == int32(2) {
iOne = 0
for {
v7 = iOne
iOne = iOne + 1
v1 = _whereNthSubterm(tls, (*TWhereClause)(unsafe.Pointer(pOrWc)).Fa, v7)
pOne = v1
if !(v1 != uintptr(0)) {
break
}
iTwo = 0
for {
v9 = iTwo
iTwo = iTwo + 1
v2 = _whereNthSubterm(tls, (*TWhereClause)(unsafe.Pointer(pOrWc)).Fa+1*56, v9)
pTwo = v2
if !(v2 != uintptr(0)) {
break
}
_whereCombineDisjuncts(tls, pSrc, pWC, pOne, pTwo)
}
}
}
/*
** chngToIN holds a set of tables that *might* satisfy case 1. But
** we have to do some additional checking to see if case 1 really
** is satisfied.
**
** chngToIN will hold either 0, 1, or 2 bits. The 0-bit case means
** that there is no possibility of transforming the OR clause into an
** IN operator because one or more terms in the OR clause contain
** something other than == on a column in the single table. The 1-bit
** case means that every term of the OR clause is of the form
** "table.column=expr" for some single table. The one bit that is set
** will correspond to the common table. We still need to check to make
** sure the same column is used on all terms. The 2-bit case is when
** the all terms are of the form "table1.column=table2.column". It
** might be possible to form an IN operator with either table1.column
** or table2.column as the LHS if either is common to every term of
** the OR clause.
**
** Note that terms of the form "table.column1=table.column2" (the
** same table on both sizes of the ==) cannot be optimized.
*/
if chngToIN != 0 {
okToChngToIN = 0 /* True if the conversion to IN is valid */
iColumn = -int32(1) /* Column index on lhs of IN operator */
iCursor = -int32(1) /* Table cursor common to all terms */
j1 = 0 /* Loop counter */
/* Search for a table and column that appears on one side or the
** other of the == operator in every subterm. That table and column
** will be recorded in iCursor and iColumn. There might not be any
** such table and column. Set okToChngToIN if an appropriate table
** and column is found but leave okToChngToIN false if not found.
*/
j1 = 0
for {
if !(j1 < int32(2) && !(okToChngToIN != 0)) {
break
}
pLeft = uintptr(0)
pOrTerm = (*TWhereClause)(unsafe.Pointer(pOrWc)).Fa
i = (*TWhereClause)(unsafe.Pointer(pOrWc)).FnTerm - int32(1)
for {
if !(i >= 0) {
break
}
v1 = pOrTerm + 18
*(*Tu16)(unsafe.Pointer(v1)) = Tu16(int32(*(*Tu16)(unsafe.Pointer(v1))) & ^libc.Int32FromInt32(TERM_OK))
if (*TWhereTerm)(unsafe.Pointer(pOrTerm)).FleftCursor == iCursor {
/* This is the 2-bit case and we are on the second iteration and
** current term is from the first iteration. So skip this term. */
goto _11
}
if chngToIN&_sqlite3WhereGetMask(tls, pWInfo+592, (*TWhereTerm)(unsafe.Pointer(pOrTerm)).FleftCursor) == uint64(0) {
/* This term must be of the form t1.a==t2.b where t2 is in the
** chngToIN set but t1 is not. This term will be either preceded
** or followed by an inverted copy (t2.b==t1.a). Skip this term
** and use its inversion. */
goto _11
}
iColumn = (*(*struct {
FleftColumn int32
FiField int32
})(unsafe.Pointer(pOrTerm + 32))).FleftColumn
iCursor = (*TWhereTerm)(unsafe.Pointer(pOrTerm)).FleftCursor
pLeft = (*TExpr)(unsafe.Pointer((*TWhereTerm)(unsafe.Pointer(pOrTerm)).FpExpr)).FpLeft
break
goto _11
_11:
;
i = i - 1
pOrTerm += 56
}
if i < 0 {
/* No candidate table+column was found. This can only occur
** on the second iteration */
break
}
/* We have found a candidate table and column. Check to see if that
** table and column is common to every term in the OR clause */
okToChngToIN = int32(1)
for {
if !(i >= 0 && okToChngToIN != 0) {
break
}
if (*TWhereTerm)(unsafe.Pointer(pOrTerm)).FleftCursor != iCursor {
v1 = pOrTerm + 18
*(*Tu16)(unsafe.Pointer(v1)) = Tu16(int32(*(*Tu16)(unsafe.Pointer(v1))) & ^libc.Int32FromInt32(TERM_OK))
} else {
if (*(*struct {
FleftColumn int32
FiField int32
})(unsafe.Pointer(pOrTerm + 32))).FleftColumn != iColumn || iColumn == -int32(2) && _sqlite3ExprCompare(tls, pParse, (*TExpr)(unsafe.Pointer((*TWhereTerm)(unsafe.Pointer(pOrTerm)).FpExpr)).FpLeft, pLeft, -int32(1)) != 0 {
okToChngToIN = 0
} else {
/* If the right-hand side is also a column, then the affinities
** of both right and left sides must be such that no type
** conversions are required on the right. (Ticket #2249)
*/
affRight = int32(_sqlite3ExprAffinity(tls, (*TExpr)(unsafe.Pointer((*TWhereTerm)(unsafe.Pointer(pOrTerm)).FpExpr)).FpRight))
affLeft = int32(_sqlite3ExprAffinity(tls, (*TExpr)(unsafe.Pointer((*TWhereTerm)(unsafe.Pointer(pOrTerm)).FpExpr)).FpLeft))
if affRight != 0 && affRight != affLeft {
okToChngToIN = 0
} else {
v1 = pOrTerm + 18
*(*Tu16)(unsafe.Pointer(v1)) = Tu16(int32(*(*Tu16)(unsafe.Pointer(v1))) | libc.Int32FromInt32(TERM_OK))
}
}
}
goto _13
_13:
;
i = i - 1
pOrTerm += 56
}
goto _10
_10:
;
j1 = j1 + 1
}
/* At this point, okToChngToIN is true if original pTerm satisfies
** case 1. In that case, construct a new virtual term that is
** pTerm converted into an IN operator.
*/
if okToChngToIN != 0 { /* A transient duplicate expression */
pList = uintptr(0) /* The RHS of the IN operator */
pLeft1 = uintptr(0) /* The complete IN operator */
i = (*TWhereClause)(unsafe.Pointer(pOrWc)).FnTerm - int32(1)
pOrTerm = (*TWhereClause)(unsafe.Pointer(pOrWc)).Fa
for {
if !(i >= 0) {
break
}
if libc.Int32FromUint16((*TWhereTerm)(unsafe.Pointer(pOrTerm)).FwtFlags)&int32(TERM_OK) == 0 {
goto _16
}
pDup = _sqlite3ExprDup(tls, db, (*TExpr)(unsafe.Pointer((*TWhereTerm)(unsafe.Pointer(pOrTerm)).FpExpr)).FpRight, 0)
pList = _sqlite3ExprListAppend(tls, (*TWhereInfo)(unsafe.Pointer(pWInfo)).FpParse, pList, pDup)
pLeft1 = (*TExpr)(unsafe.Pointer((*TWhereTerm)(unsafe.Pointer(pOrTerm)).FpExpr)).FpLeft
goto _16
_16:
;
i = i - 1
pOrTerm += 56
}
pDup = _sqlite3ExprDup(tls, db, pLeft1, 0)
pNew = _sqlite3PExpr(tls, pParse, int32(TK_IN), pDup, uintptr(0))
if pNew != 0 {
_transferJoinMarkings(tls, pNew, pExpr)
*(*uintptr)(unsafe.Pointer(pNew + 32)) = pList
idxNew = _whereClauseInsert(tls, pWC, pNew, libc.Uint16FromInt32(libc.Int32FromInt32(TERM_VIRTUAL)|libc.Int32FromInt32(TERM_DYNAMIC)))
_exprAnalyze(tls, pSrc, pWC, idxNew)
/* pTerm = &pWC->a[idxTerm]; // would be needed if pTerm where reused */
_markTermAsChild(tls, pWC, idxNew, idxTerm)
} else {
_sqlite3ExprListDelete(tls, db, pList)
}
}
}
}
// C documentation
//
// /*
// ** Generate code for a BETWEEN operator.
// **
// ** x BETWEEN y AND z
// **
// ** The above is equivalent to
// **
// ** x>=y AND x<=z
// **
// ** Code it as such, taking care to do the common subexpression
// ** elimination of x.
// **
// ** The xJumpIf parameter determines details:
// **
// ** NULL: Store the boolean result in reg[dest]
// ** sqlite3ExprIfTrue: Jump to dest if true
// ** sqlite3ExprIfFalse: Jump to dest if false
// **
// ** The jumpIfNull parameter is ignored if xJumpIf is NULL.
// */
func _exprCodeBetween(tls *libc.TLS, pParse uintptr, pExpr uintptr, dest int32, __ccgo_fp_xJump uintptr, jumpIfNull int32) {
bp := tls.Alloc(224)
defer tls.Free(224)
var db, pDel uintptr
var _ /* compLeft at bp+72 */ TExpr
var _ /* compRight at bp+144 */ TExpr
var _ /* exprAnd at bp+0 */ TExpr
var _ /* regFree1 at bp+216 */ int32
_, _ = db, pDel /* The x<=z term */
**(**int32)(__ccgo_up(bp + 216)) = 0 /* Temporary use register */
pDel = uintptr(0)
db = (*TParse)(unsafe.Pointer(pParse)).Fdb
libc.X__builtin___memset_chk(tls, bp+72, 0, uint64(72), ^t__predefined_size_t(0))
libc.X__builtin___memset_chk(tls, bp+144, 0, uint64(72), ^t__predefined_size_t(0))
libc.X__builtin___memset_chk(tls, bp, 0, uint64(72), ^t__predefined_size_t(0))
pDel = _sqlite3ExprDup(tls, db, (*TExpr)(unsafe.Pointer(pExpr)).FpLeft, 0)
if libc.Int32FromUint8((*Tsqlite3)(unsafe.Pointer(db)).FmallocFailed) == 0 {
(**(**TExpr)(__ccgo_up(bp))).Fop = uint8(TK_AND)
(**(**TExpr)(__ccgo_up(bp))).FpLeft = bp + 72
(**(**TExpr)(__ccgo_up(bp))).FpRight = bp + 144
(**(**TExpr)(__ccgo_up(bp + 72))).Fop = uint8(TK_GE)
(**(**TExpr)(__ccgo_up(bp + 72))).FpLeft = pDel
(**(**TExpr)(__ccgo_up(bp + 72))).FpRight = (*(*TExprList_item)(unsafe.Pointer(*(*uintptr)(unsafe.Pointer(pExpr + 32)) + 8))).FpExpr
(**(**TExpr)(__ccgo_up(bp + 144))).Fop = uint8(TK_LE)
(**(**TExpr)(__ccgo_up(bp + 144))).FpLeft = pDel
(**(**TExpr)(__ccgo_up(bp + 144))).FpRight = (*(*TExprList_item)(unsafe.Pointer(*(*uintptr)(unsafe.Pointer(pExpr + 32)) + 8 + 1*32))).FpExpr
_sqlite3ExprToRegister(tls, pDel, _exprCodeVector(tls, pParse, pDel, bp+216))
if __ccgo_fp_xJump != 0 {
(*(*func(*libc.TLS, uintptr, uintptr, int32, int32))(unsafe.Pointer(&struct{ uintptr }{__ccgo_fp_xJump})))(tls, pParse, bp, dest, jumpIfNull)
} else {
/* Mark the expression is being from the ON or USING clause of a join
** so that the sqlite3ExprCodeTarget() routine will not attempt to move
** it into the Parse.pConstExpr list. We should use a new bit for this,
** for clarity, but we are out of bits in the Expr.flags field so we
** have to reuse the EP_OuterON bit. Bummer. */
**(**Tu32)(__ccgo_up(pDel + 4)) |= uint32(EP_OuterON)
_sqlite3ExprCodeTarget(tls, pParse, bp, dest)
}
_sqlite3ReleaseTempReg(tls, pParse, **(**int32)(__ccgo_up(bp + 216)))
}
_sqlite3ExprDelete(tls, db, pDel)
/* Ensure adequate test coverage */
}
// 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(80)
defer tls.Free(80)
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)*32))).FpExpr, target)
goto _1
_1:
;
i = i + 1
}
_setDoNotMergeFlagOnCopy(tls, v)
_sqlite3VdbeResolveLabel(tls, v, endCoalesce)
case int32(INLINEFUNC_iif):
libc.X__builtin___memset_chk(tls, bp, 0, uint64(72), ^t__predefined_size_t(0))
(**(**TExpr)(__ccgo_up(bp))).Fop = uint8(TK_CASE)
*(*uintptr)(unsafe.Pointer(bp + 32)) = 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*32))).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*32))).FpExpr, -int32(1)), target)
case int32(INLINEFUNC_implies_nonnull_row):
pA1 = (*(*TExprList_item)(unsafe.Pointer(pFarg + 8 + 1*32))).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 + 8830,
1: __ccgo_ts + 8835,
2: __ccgo_ts + 8840,
3: __ccgo_ts + 6840,
4: __ccgo_ts + 6835,
5: __ccgo_ts + 8848,
}
aff = _sqlite3ExprAffinity(tls, (*(*TExprList_item)(unsafe.Pointer(pFarg + 8))).FpExpr)
if int32(aff) <= int32(SQLITE_AFF_NONE) {
v2 = __ccgo_ts + 8856
} else {
v2 = azAff[int32(aff)-int32(SQLITE_AFF_BLOB)]
}
_sqlite3VdbeLoadString(tls, v, target, v2)
break
}
return target
}
// C documentation
//
// /*
// ** This function is similar to sqlite3ExprDup(), except that if pEdupBuf
// ** is not NULL then it points to memory that can be used to store a copy
// ** of the input Expr p together with its p->u.zToken (if any). pEdupBuf
// ** is updated with the new buffer tail prior to returning.
// */
func _exprDup(tls *libc.TLS, db uintptr, p uintptr, dupFlags int32, pEdupBuf uintptr) (r uintptr) {
bp := tls.Alloc(16)
defer tls.Free(16)
var nAlloc, nNewSize, nToken, v2 int32
var nSize, staticFlag Tu32
var nStructSize uint32
var pNew, zToken, v1 uintptr
var _ /* sEdupBuf at bp+0 */ TEdupBuf
_, _, _, _, _, _, _, _, _, _ = nAlloc, nNewSize, nSize, nStructSize, nToken, pNew, staticFlag, zToken, v1, v2 /* EP_Static if space not obtained from malloc */
nToken = -int32(1) /* Space needed for p->u.zToken. -1 means unknown */
/* Figure out where to write the new Expr structure. */
if pEdupBuf != 0 {
(**(**TEdupBuf)(__ccgo_up(bp))).FzAlloc = (*TEdupBuf)(unsafe.Pointer(pEdupBuf)).FzAlloc
staticFlag = uint32(EP_Static)
} else {
if dupFlags != 0 {
nAlloc = _dupedExprSize(tls, p)
} else {
if !((*TExpr)(unsafe.Pointer(p)).Fflags&libc.Uint32FromInt32(libc.Int32FromInt32(EP_IntValue)) != libc.Uint32FromInt32(0)) && *(*uintptr)(unsafe.Pointer(p + 8)) != 0 {
nToken = libc.Int32FromUint64(libc.Xstrlen(tls, *(*uintptr)(unsafe.Pointer(p + 8)))&uint64(0x3fffffff) + uint64(1))
nAlloc = libc.Int32FromUint64((libc.Uint64FromInt64(72) + libc.Uint64FromInt32(nToken) + libc.Uint64FromInt32(7)) & libc.Uint64FromInt32(^libc.Int32FromInt32(7)))
} else {
nToken = 0
nAlloc = libc.Int32FromUint64((libc.Uint64FromInt64(72) + libc.Uint64FromInt32(7)) & libc.Uint64FromInt32(^libc.Int32FromInt32(7)))
}
}
(**(**TEdupBuf)(__ccgo_up(bp))).FzAlloc = _sqlite3DbMallocRawNN(tls, db, libc.Uint64FromInt32(nAlloc))
staticFlag = uint32(0)
}
pNew = (**(**TEdupBuf)(__ccgo_up(bp))).FzAlloc
if pNew != 0 {
/* Set nNewSize to the size allocated for the structure pointed to
** by pNew. This is either EXPR_FULLSIZE, EXPR_REDUCEDSIZE or
** EXPR_TOKENONLYSIZE. nToken is set to the number of bytes consumed
** by the copy of the p->u.zToken string (if any).
*/
nStructSize = libc.Uint32FromInt32(_dupedExprStructSize(tls, p, dupFlags))
nNewSize = libc.Int32FromUint32(nStructSize & uint32(0xfff))
if nToken < 0 {
if !((*TExpr)(unsafe.Pointer(p)).Fflags&libc.Uint32FromInt32(libc.Int32FromInt32(EP_IntValue)) != libc.Uint32FromInt32(0)) && *(*uintptr)(unsafe.Pointer(p + 8)) != 0 {
nToken = _sqlite3Strlen30(tls, *(*uintptr)(unsafe.Pointer(p + 8))) + int32(1)
} else {
nToken = 0
}
}
if dupFlags != 0 {
libc.X__builtin___memcpy_chk(tls, (**(**TEdupBuf)(__ccgo_up(bp))).FzAlloc, p, libc.Uint64FromInt32(nNewSize), ^t__predefined_size_t(0))
} else {
nSize = libc.Uint32FromInt32(_exprStructSize(tls, p))
libc.X__builtin___memcpy_chk(tls, (**(**TEdupBuf)(__ccgo_up(bp))).FzAlloc, p, uint64(nSize), ^t__predefined_size_t(0))
if uint64(nSize) < uint64(72) {
libc.X__builtin___memset_chk(tls, (**(**TEdupBuf)(__ccgo_up(bp))).FzAlloc+uintptr(nSize), 0, uint64(72)-uint64(nSize), ^t__predefined_size_t(0))
}
nNewSize = int32(72)
}
/* Set the EP_Reduced, EP_TokenOnly, and EP_Static flags appropriately. */
**(**Tu32)(__ccgo_up(pNew + 4)) &= libc.Uint32FromInt32(^(libc.Int32FromInt32(EP_Reduced) | libc.Int32FromInt32(EP_TokenOnly) | libc.Int32FromInt32(EP_Static)))
**(**Tu32)(__ccgo_up(pNew + 4)) |= nStructSize & libc.Uint32FromInt32(libc.Int32FromInt32(EP_Reduced)|libc.Int32FromInt32(EP_TokenOnly))
**(**Tu32)(__ccgo_up(pNew + 4)) |= staticFlag
if dupFlags != 0 {
}
/* Copy the p->u.zToken string, if any. */
if nToken > 0 {
v1 = (**(**TEdupBuf)(__ccgo_up(bp))).FzAlloc + uintptr(nNewSize)
*(*uintptr)(unsafe.Pointer(pNew + 8)) = v1
zToken = v1
libc.X__builtin___memcpy_chk(tls, zToken, *(*uintptr)(unsafe.Pointer(p + 8)), libc.Uint64FromInt32(nToken), ^t__predefined_size_t(0))
nNewSize = nNewSize + nToken
}
(**(**TEdupBuf)(__ccgo_up(bp))).FzAlloc += uintptr((nNewSize + libc.Int32FromInt32(7)) & ^libc.Int32FromInt32(7))
if ((*TExpr)(unsafe.Pointer(p)).Fflags|(*TExpr)(unsafe.Pointer(pNew)).Fflags)&libc.Uint32FromInt32(libc.Int32FromInt32(EP_TokenOnly)|libc.Int32FromInt32(EP_Leaf)) == uint32(0) {
/* Fill in the pNew->x.pSelect or pNew->x.pList member. */
if (*TExpr)(unsafe.Pointer(p)).Fflags&uint32(EP_xIsSelect) != uint32(0) {
*(*uintptr)(unsafe.Pointer(pNew + 32)) = _sqlite3SelectDup(tls, db, *(*uintptr)(unsafe.Pointer(p + 32)), dupFlags)
} else {
if libc.Int32FromUint8((*TExpr)(unsafe.Pointer(p)).Fop) != int32(TK_ORDER) {
v2 = dupFlags
} else {
v2 = 0
}
*(*uintptr)(unsafe.Pointer(pNew + 32)) = _sqlite3ExprListDup(tls, db, *(*uintptr)(unsafe.Pointer(p + 32)), v2)
}
if (*TExpr)(unsafe.Pointer(p)).Fflags&libc.Uint32FromInt32(libc.Int32FromInt32(EP_WinFunc)) != uint32(0) {
*(*uintptr)(unsafe.Pointer(pNew + 64)) = _sqlite3WindowDup(tls, db, pNew, *(*uintptr)(unsafe.Pointer(p + 64)))
}
/* Fill in pNew->pLeft and pNew->pRight. */
if dupFlags != 0 {
if libc.Int32FromUint8((*TExpr)(unsafe.Pointer(p)).Fop) == int32(TK_SELECT_COLUMN) {
(*TExpr)(unsafe.Pointer(pNew)).FpLeft = (*TExpr)(unsafe.Pointer(p)).FpLeft
} else {
if (*TExpr)(unsafe.Pointer(p)).FpLeft != 0 {
v1 = _exprDup(tls, db, (*TExpr)(unsafe.Pointer(p)).FpLeft, int32(EXPRDUP_REDUCE), bp)
} else {
v1 = uintptr(0)
}
(*TExpr)(unsafe.Pointer(pNew)).FpLeft = v1
}
if (*TExpr)(unsafe.Pointer(p)).FpRight != 0 {
v1 = _exprDup(tls, db, (*TExpr)(unsafe.Pointer(p)).FpRight, int32(EXPRDUP_REDUCE), bp)
} else {
v1 = uintptr(0)
}
(*TExpr)(unsafe.Pointer(pNew)).FpRight = v1
} else {
if libc.Int32FromUint8((*TExpr)(unsafe.Pointer(p)).Fop) == int32(TK_SELECT_COLUMN) {
(*TExpr)(unsafe.Pointer(pNew)).FpLeft = (*TExpr)(unsafe.Pointer(p)).FpLeft
} else {
(*TExpr)(unsafe.Pointer(pNew)).FpLeft = _sqlite3ExprDup(tls, db, (*TExpr)(unsafe.Pointer(p)).FpLeft, 0)
}
(*TExpr)(unsafe.Pointer(pNew)).FpRight = _sqlite3ExprDup(tls, db, (*TExpr)(unsafe.Pointer(p)).FpRight, 0)
}
}
}
if pEdupBuf != 0 {
libc.X__builtin___memcpy_chk(tls, pEdupBuf, bp, uint64(8), ^t__predefined_size_t(0))
}
return pNew
}
// C documentation
//
// /*
// ** Return true if the expression contains no non-deterministic SQL
// ** functions. Do not consider non-deterministic SQL functions that are
// ** part of sub-select statements.
// */
func _exprIsDeterministic(tls *libc.TLS, p uintptr) (r int32) {
bp := tls.Alloc(48)
defer tls.Free(48)
var _ /* w at bp+0 */ TWalker
libc.X__builtin___memset_chk(tls, bp, 0, uint64(48), ^t__predefined_size_t(0))
(**(**TWalker)(__ccgo_up(bp))).FeCode = uint16(1)
(**(**TWalker)(__ccgo_up(bp))).FxExprCallback = __ccgo_fp(_exprNodeIsDeterministic)
(**(**TWalker)(__ccgo_up(bp))).FxSelectCallback = __ccgo_fp(_sqlite3SelectWalkFail)
_sqlite3WalkExpr(tls, bp, p)
return libc.Int32FromUint16((**(**TWalker)(__ccgo_up(bp))).FeCode)
}
// 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(144)
defer tls.Free(144)
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)< (**(**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)< 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)<aData
// ** area. pCell might point to some temporary storage. The cell will
// ** be constructed in this temporary area then copied into pPage->aData
// ** later.
// */
func _fillInCell(tls *libc.TLS, pPage uintptr, pCell uintptr, pX uintptr, pnSize uintptr) (r int32) {
bp := tls.Alloc(16)
defer tls.Free(16)
var eType Tu8
var mn, n, nHeader, nPayload, nSrc, spaceLeft, v1 int32
var pBt, pPayload, pPrior, pSrc, pToRelease uintptr
var pgnoPtrmap TPgno
var _ /* pOvfl at bp+8 */ uintptr
var _ /* pgnoOvfl at bp+4 */ TPgno
var _ /* rc at bp+0 */ int32
_, _, _, _, _, _, _, _, _, _, _, _, _, _ = eType, mn, n, nHeader, nPayload, nSrc, pBt, pPayload, pPrior, pSrc, pToRelease, pgnoPtrmap, spaceLeft, v1
/* pPage is not necessarily writeable since pCell might be auxiliary
** buffer space that is separate from the pPage buffer area */
/* Fill in the header. */
nHeader = libc.Int32FromUint8((*TMemPage)(unsafe.Pointer(pPage)).FchildPtrSize)
if (*TMemPage)(unsafe.Pointer(pPage)).FintKey != 0 {
nPayload = (*TBtreePayload)(unsafe.Pointer(pX)).FnData + (*TBtreePayload)(unsafe.Pointer(pX)).FnZero
pSrc = (*TBtreePayload)(unsafe.Pointer(pX)).FpData
nSrc = (*TBtreePayload)(unsafe.Pointer(pX)).FnData
/* fillInCell() only called for leaves */
if libc.Uint32FromInt32(nPayload) < libc.Uint32FromInt32(0x80) {
**(**uint8)(__ccgo_up(pCell + uintptr(nHeader))) = libc.Uint8FromInt32(nPayload)
v1 = libc.Int32FromInt32(1)
} else {
v1 = _sqlite3PutVarint(tls, pCell+uintptr(nHeader), libc.Uint64FromInt32(nPayload))
}
nHeader = nHeader + libc.Int32FromUint8(libc.Uint8FromInt32(v1))
nHeader = nHeader + _sqlite3PutVarint(tls, pCell+uintptr(nHeader), **(**Tu64)(__ccgo_up(pX + 8)))
} else {
v1 = int32((*TBtreePayload)(unsafe.Pointer(pX)).FnKey)
nPayload = v1
nSrc = v1
pSrc = (*TBtreePayload)(unsafe.Pointer(pX)).FpKey
if libc.Uint32FromInt32(nPayload) < libc.Uint32FromInt32(0x80) {
**(**uint8)(__ccgo_up(pCell + uintptr(nHeader))) = libc.Uint8FromInt32(nPayload)
v1 = libc.Int32FromInt32(1)
} else {
v1 = _sqlite3PutVarint(tls, pCell+uintptr(nHeader), libc.Uint64FromInt32(nPayload))
}
nHeader = nHeader + libc.Int32FromUint8(libc.Uint8FromInt32(v1))
}
/* Fill in the payload */
pPayload = pCell + uintptr(nHeader)
if nPayload <= libc.Int32FromUint16((*TMemPage)(unsafe.Pointer(pPage)).FmaxLocal) {
/* This is the common case where everything fits on the btree page
** and no overflow pages are required. */
n = nHeader + nPayload
if n < int32(4) {
n = int32(4)
**(**uint8)(__ccgo_up(pPayload + uintptr(nPayload))) = uint8(0)
}
**(**int32)(__ccgo_up(pnSize)) = n
libc.X__builtin___memcpy_chk(tls, pPayload, pSrc, libc.Uint64FromInt32(nSrc), ^t__predefined_size_t(0))
libc.X__builtin___memset_chk(tls, pPayload+uintptr(nSrc), 0, libc.Uint64FromInt32(nPayload-nSrc), ^t__predefined_size_t(0))
return SQLITE_OK
}
/* If we reach this point, it means that some of the content will need
** to spill onto overflow pages.
*/
mn = libc.Int32FromUint16((*TMemPage)(unsafe.Pointer(pPage)).FminLocal)
n = libc.Int32FromUint32(libc.Uint32FromInt32(mn) + libc.Uint32FromInt32(nPayload-mn)%((*TBtShared)(unsafe.Pointer((*TMemPage)(unsafe.Pointer(pPage)).FpBt)).FusableSize-uint32(4)))
if n > libc.Int32FromUint16((*TMemPage)(unsafe.Pointer(pPage)).FmaxLocal) {
n = mn
}
spaceLeft = n
**(**int32)(__ccgo_up(pnSize)) = n + nHeader + int32(4)
pPrior = pCell + uintptr(nHeader+n)
pToRelease = uintptr(0)
**(**TPgno)(__ccgo_up(bp + 4)) = uint32(0)
pBt = (*TMemPage)(unsafe.Pointer(pPage)).FpBt
/* At this point variables should be set as follows:
**
** nPayload Total payload size in bytes
** pPayload Begin writing payload here
** spaceLeft Space available at pPayload. If nPayload>spaceLeft,
** that means content must spill into overflow pages.
** *pnSize Size of the local cell (not counting overflow pages)
** pPrior Where to write the pgno of the first overflow page
**
** Use a call to btreeParseCellPtr() to verify that the values above
** were computed correctly.
*/
/* Write the payload into the local Cell and any extra into overflow pages */
for int32(1) != 0 {
n = nPayload
if n > spaceLeft {
n = spaceLeft
}
/* If pToRelease is not zero than pPayload points into the data area
** of pToRelease. Make sure pToRelease is still writeable. */
/* If pPayload is part of the data area of pPage, then make sure pPage
** is still writeable */
if nSrc >= n {
libc.X__builtin___memcpy_chk(tls, pPayload, pSrc, libc.Uint64FromInt32(n), ^t__predefined_size_t(0))
} else {
if nSrc > 0 {
n = nSrc
libc.X__builtin___memcpy_chk(tls, pPayload, pSrc, libc.Uint64FromInt32(n), ^t__predefined_size_t(0))
} else {
libc.X__builtin___memset_chk(tls, pPayload, 0, libc.Uint64FromInt32(n), ^t__predefined_size_t(0))
}
}
nPayload = nPayload - n
if nPayload <= 0 {
break
}
pPayload = pPayload + uintptr(n)
pSrc = pSrc + uintptr(n)
nSrc = nSrc - n
spaceLeft = spaceLeft - n
if spaceLeft == 0 {
**(**uintptr)(__ccgo_up(bp + 8)) = uintptr(0)
pgnoPtrmap = **(**TPgno)(__ccgo_up(bp + 4)) /* Overflow page pointer-map entry page */
if (*TBtShared)(unsafe.Pointer(pBt)).FautoVacuum != 0 {
for cond := true; cond; cond = _ptrmapPageno(tls, pBt, **(**TPgno)(__ccgo_up(bp + 4))) == **(**TPgno)(__ccgo_up(bp + 4)) || **(**TPgno)(__ccgo_up(bp + 4)) == libc.Uint32FromInt32(_sqlite3PendingByte)/(*TBtShared)(unsafe.Pointer(pBt)).FpageSize+libc.Uint32FromInt32(1) {
**(**TPgno)(__ccgo_up(bp + 4)) = **(**TPgno)(__ccgo_up(bp + 4)) + 1
}
}
**(**int32)(__ccgo_up(bp)) = _allocateBtreePage(tls, pBt, bp+8, bp+4, **(**TPgno)(__ccgo_up(bp + 4)), uint8(0))
/* If the database supports auto-vacuum, and the second or subsequent
** overflow page is being allocated, add an entry to the pointer-map
** for that page now.
**
** If this is the first overflow page, then write a partial entry
** to the pointer-map. If we write nothing to this pointer-map slot,
** then the optimistic overflow chain processing in clearCell()
** may misinterpret the uninitialized values and delete the
** wrong pages from the database.
*/
if (*TBtShared)(unsafe.Pointer(pBt)).FautoVacuum != 0 && **(**int32)(__ccgo_up(bp)) == SQLITE_OK {
if pgnoPtrmap != 0 {
v1 = int32(PTRMAP_OVERFLOW2)
} else {
v1 = int32(PTRMAP_OVERFLOW1)
}
eType = libc.Uint8FromInt32(v1)
_ptrmapPut(tls, pBt, **(**TPgno)(__ccgo_up(bp + 4)), eType, pgnoPtrmap, bp)
if **(**int32)(__ccgo_up(bp)) != 0 {
_releasePage(tls, **(**uintptr)(__ccgo_up(bp + 8)))
}
}
if **(**int32)(__ccgo_up(bp)) != 0 {
_releasePage(tls, pToRelease)
return **(**int32)(__ccgo_up(bp))
}
/* If pToRelease is not zero than pPrior points into the data area
** of pToRelease. Make sure pToRelease is still writeable. */
/* If pPrior is part of the data area of pPage, then make sure pPage
** is still writeable */
_sqlite3Put4byte(tls, pPrior, **(**TPgno)(__ccgo_up(bp + 4)))
_releasePage(tls, pToRelease)
pToRelease = **(**uintptr)(__ccgo_up(bp + 8))
pPrior = (*TMemPage)(unsafe.Pointer(**(**uintptr)(__ccgo_up(bp + 8)))).FaData
_sqlite3Put4byte(tls, pPrior, uint32(0))
pPayload = (*TMemPage)(unsafe.Pointer(**(**uintptr)(__ccgo_up(bp + 8)))).FaData + 4
spaceLeft = libc.Int32FromUint32((*TBtShared)(unsafe.Pointer(pBt)).FusableSize - uint32(4))
}
}
_releasePage(tls, pToRelease)
return SQLITE_OK
}
// C documentation
//
// /*
// ** Initialize the contents of the unixFile structure pointed to by pId.
// */
func _fillInUnixFile(tls *libc.TLS, pVfs uintptr, h int32, pId uintptr, zFilename uintptr, ctrlFlags int32) (r int32) {
bp := tls.Alloc(16)
defer tls.Free(16)
var nFilename, rc int32
var pCtx, pLockingStyle, pNew, zLockFile, v1, v2 uintptr
_, _, _, _, _, _, _, _ = nFilename, pCtx, pLockingStyle, pNew, rc, zLockFile, v1, v2
pNew = pId
rc = SQLITE_OK
/* No locking occurs in temporary files */
(*TunixFile)(unsafe.Pointer(pNew)).Fh = h
(*TunixFile)(unsafe.Pointer(pNew)).FpVfs = pVfs
(*TunixFile)(unsafe.Pointer(pNew)).FzPath = zFilename
(*TunixFile)(unsafe.Pointer(pNew)).FctrlFlags = uint16(libc.Uint8FromInt32(ctrlFlags))
(*TunixFile)(unsafe.Pointer(pNew)).FmmapSizeMax = _sqlite3Config.FszMmap
if ctrlFlags&int32(UNIXFILE_URI) != 0 {
v1 = zFilename
} else {
v1 = uintptr(0)
}
if Xsqlite3_uri_boolean(tls, v1, __ccgo_ts+4009, int32(SQLITE_POWERSAFE_OVERWRITE)) != 0 {
v2 = pNew + 30
*(*uint16)(unsafe.Pointer(v2)) = uint16(int32(*(*uint16)(unsafe.Pointer(v2))) | libc.Int32FromInt32(UNIXFILE_PSOW))
}
if libc.Xstrcmp(tls, (*Tsqlite3_vfs)(unsafe.Pointer(pVfs)).FzName, __ccgo_ts+4014) == 0 {
v1 = pNew + 30
*(*uint16)(unsafe.Pointer(v1)) = uint16(int32(*(*uint16)(unsafe.Pointer(v1))) | libc.Int32FromInt32(UNIXFILE_EXCL))
}
if ctrlFlags&int32(UNIXFILE_NOLOCK) != 0 {
pLockingStyle = uintptr(unsafe.Pointer(&_nolockIoMethods))
} else {
pLockingStyle = (*(*func(*libc.TLS, uintptr, uintptr) uintptr)(unsafe.Pointer(&struct{ uintptr }{*(*uintptr)(unsafe.Pointer((*Tsqlite3_vfs)(unsafe.Pointer(pVfs)).FpAppData))})))(tls, zFilename, pNew)
/* Cache zFilename in the locking context (AFP and dotlock override) for
** proxyLock activation is possible (remote proxy is based on db name)
** zFilename remains valid until file is closed, to support */
(*TunixFile)(unsafe.Pointer(pNew)).FlockingContext = zFilename
}
if pLockingStyle == uintptr(unsafe.Pointer(&_posixIoMethods)) || pLockingStyle == uintptr(unsafe.Pointer(&_nfsIoMethods)) {
_unixEnterMutex(tls)
rc = _findInodeInfo(tls, pNew, pNew+16)
if rc != SQLITE_OK {
/* If an error occurred in findInodeInfo(), close the file descriptor
** immediately, before releasing the mutex. findInodeInfo() may fail
** in two scenarios:
**
** (a) A call to fstat() failed.
** (b) A malloc failed.
**
** Scenario (b) may only occur if the process is holding no other
** file descriptors open on the same file. If there were other file
** descriptors on this file, then no malloc would be required by
** findInodeInfo(). If this is the case, it is quite safe to close
** handle h - as it is guaranteed that no posix locks will be released
** by doing so.
**
** If scenario (a) caused the error then things are not so safe. The
** implicit assumption here is that if fstat() fails, things are in
** such bad shape that dropping a lock or two doesn't matter much.
*/
_robust_close(tls, pNew, h, int32(46355))
h = -int32(1)
}
_unixLeaveMutex(tls)
} else {
if pLockingStyle == uintptr(unsafe.Pointer(&_afpIoMethods)) {
v1 = Xsqlite3_malloc64(tls, uint64(16))
pCtx = v1
(*TunixFile)(unsafe.Pointer(pNew)).FlockingContext = v1
if pCtx == uintptr(0) {
rc = int32(SQLITE_NOMEM)
} else {
/* NB: zFilename exists and remains valid until the file is closed
** according to requirement F11141. So we do not need to make a
** copy of the filename. */
(*TafpLockingContext)(unsafe.Pointer(pCtx)).FdbPath = zFilename
(*TafpLockingContext)(unsafe.Pointer(pCtx)).Freserved = 0
libc.Xsrandomdev(tls)
_unixEnterMutex(tls)
rc = _findInodeInfo(tls, pNew, pNew+16)
if rc != SQLITE_OK {
Xsqlite3_free(tls, (*TunixFile)(unsafe.Pointer(pNew)).FlockingContext)
_robust_close(tls, pNew, h, int32(46381))
h = -int32(1)
}
_unixLeaveMutex(tls)
}
} else {
if pLockingStyle == uintptr(unsafe.Pointer(&_dotlockIoMethods)) {
nFilename = libc.Int32FromUint64(libc.Xstrlen(tls, zFilename)) + int32(6)
zLockFile = Xsqlite3_malloc64(tls, libc.Uint64FromInt32(nFilename))
if zLockFile == uintptr(0) {
rc = int32(SQLITE_NOMEM)
} else {
Xsqlite3_snprintf(tls, nFilename, zLockFile, __ccgo_ts+4024, libc.VaList(bp+8, zFilename))
}
(*TunixFile)(unsafe.Pointer(pNew)).FlockingContext = zLockFile
}
}
}
_storeLastErrno(tls, pNew, 0)
if rc != SQLITE_OK {
if h >= 0 {
_robust_close(tls, pNew, h, int32(46447))
}
} else {
(*Tsqlite3_file)(unsafe.Pointer(pId)).FpMethods = pLockingStyle
_verifyDbFile(tls, pNew)
}
return rc
}
// C documentation
//
// /*
// ** Return a pointer corresponding to database zDb (i.e. "main", "temp")
// ** in connection handle pDb. If such a database cannot be found, return
// ** a NULL pointer and write an error message to pErrorDb.
// **
// ** If the "temp" database is requested, it may need to be opened by this
// ** function. If an error occurs while doing so, return 0 and write an
// ** error message to pErrorDb.
// */
func _findBtree(tls *libc.TLS, pErrorDb uintptr, pDb uintptr, zDb uintptr) (r uintptr) {
bp := tls.Alloc(448)
defer tls.Free(448)
var i, rc int32
var _ /* sParse at bp+0 */ TParse
_, _ = i, rc
i = _sqlite3FindDbName(tls, pDb, zDb)
if i == int32(1) {
rc = 0
_sqlite3ParseObjectInit(tls, bp, pDb)
if _sqlite3OpenTempDatabase(tls, bp) != 0 {
_sqlite3ErrorWithMsg(tls, pErrorDb, (**(**TParse)(__ccgo_up(bp))).Frc, __ccgo_ts+3944, libc.VaList(bp+432, (**(**TParse)(__ccgo_up(bp))).FzErrMsg))
rc = int32(SQLITE_ERROR)
}
_sqlite3DbFree(tls, pErrorDb, (**(**TParse)(__ccgo_up(bp))).FzErrMsg)
_sqlite3ParseObjectReset(tls, bp)
if rc != 0 {
return uintptr(0)
}
}
if i < 0 {
_sqlite3ErrorWithMsg(tls, pErrorDb, int32(SQLITE_ERROR), __ccgo_ts+5473, libc.VaList(bp+432, zDb))
return uintptr(0)
}
return (**(**TDb)(__ccgo_up((*Tsqlite3)(unsafe.Pointer(pDb)).FaDb + uintptr(i)*32))).FpBt
}
// C documentation
//
// /*
// ** Locate and return an entry from the db.aCollSeq hash table. If the entry
// ** specified by zName and nName is not found and parameter 'create' is
// ** true, then create a new entry. Otherwise return NULL.
// **
// ** Each pointer stored in the sqlite3.aCollSeq hash table contains an
// ** array of three CollSeq structures. The first is the collation sequence
// ** preferred for UTF-8, the second UTF-16le, and the third UTF-16be.
// **
// ** Stored immediately after the three collation sequences is a copy of
// ** the collation sequence name. A pointer to this string is stored in
// ** each collation sequence structure.
// */
func _findCollSeqEntry(tls *libc.TLS, db uintptr, zName uintptr, create int32) (r uintptr) {
var nName int32
var pColl, pDel uintptr
_, _, _ = nName, pColl, pDel
pColl = _sqlite3HashFind(tls, db+648, zName)
if uintptr(0) == pColl && create != 0 {
nName = _sqlite3Strlen30(tls, zName) + int32(1)
pColl = _sqlite3DbMallocZero(tls, db, uint64(libc.Uint64FromInt32(3)*libc.Uint64FromInt64(40)+libc.Uint64FromInt32(nName)))
if pColl != 0 {
pDel = uintptr(0)
(**(**TCollSeq)(__ccgo_up(pColl))).FzName = pColl + 3*40
(**(**TCollSeq)(__ccgo_up(pColl))).Fenc = uint8(SQLITE_UTF8)
(**(**TCollSeq)(__ccgo_up(pColl + 1*40))).FzName = pColl + 3*40
(**(**TCollSeq)(__ccgo_up(pColl + 1*40))).Fenc = uint8(SQLITE_UTF16LE)
(**(**TCollSeq)(__ccgo_up(pColl + 2*40))).FzName = pColl + 3*40
(**(**TCollSeq)(__ccgo_up(pColl + 2*40))).Fenc = uint8(SQLITE_UTF16BE)
libc.X__builtin___memcpy_chk(tls, (**(**TCollSeq)(__ccgo_up(pColl))).FzName, zName, libc.Uint64FromInt32(nName), ^t__predefined_size_t(0))
pDel = _sqlite3HashInsert(tls, db+648, (**(**TCollSeq)(__ccgo_up(pColl))).FzName, pColl)
/* If a malloc() failure occurred in sqlite3HashInsert(), it will
** return the pColl pointer to be deleted (because it wasn't added
** to the hash table).
*/
if pDel != uintptr(0) {
_sqlite3OomFault(tls, db)
_sqlite3DbFree(tls, db, pDel)
pColl = uintptr(0)
}
}
}
return pColl
}
// 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:
**
** "-journal"
** "-wal"
** "-journalNN"
** "-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.X__builtin___memcpy_chk(tls, bp, zPath, libc.Uint64FromInt32(nDb), ^t__predefined_size_t(0))
(**(**[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+4093)
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(160)
defer tls.Free(160)
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)
}
/* On OS X on an msdos filesystem, the inode number is reported
** incorrectly for zero-size files. See ticket #3260. To work
** around this problem (we consider it a bug in OS X, not SQLite)
** we always increase the file size to 1 by writing a single byte
** prior to accessing the inode number. The one byte written is
** an ASCII 'S' character which also happens to be the first byte
** in the header of every SQLite database. In this way, if there
** is a race condition such that another thread has already populated
** the first page of the database, no damage is done.
*/
if (**(**Tstat)(__ccgo_up(bp + 16))).Fst_size == 0 && (*TunixFile)(unsafe.Pointer(pFile)).FfsFlags&uint32(SQLITE_FSFLAGS_IS_MSDOS) != uint32(0) {
for cond := true; cond; cond = rc < 0 && **(**int32)(__ccgo_up(libc.X__error(tls))) == int32(EINTR) {
rc = int32((*(*func(*libc.TLS, int32, uintptr, Tsize_t) Tssize_t)(unsafe.Pointer(&struct{ uintptr }{_aSyscall[int32(11)].FpCurrent})))(tls, fd, __ccgo_ts+3834, uint64(1)))
}
if rc != int32(1) {
_storeLastErrno(tls, pFile, **(**int32)(__ccgo_up(libc.X__error(tls))))
return int32(SQLITE_IOERR)
}
if libc.Xfsync(tls, fd) != 0 {
_storeLastErrno(tls, pFile, **(**int32)(__ccgo_up(libc.X__error(tls))))
return libc.Int32FromInt32(SQLITE_IOERR) | libc.Int32FromInt32(4)<nColumn-1.
// */
func _findOrCreateAggInfoColumn(tls *libc.TLS, pParse uintptr, pAggInfo uintptr, pExpr uintptr) {
bp := tls.Alloc(16)
defer tls.Free(16)
var j, k, mxTerm, n int32
var pCol, pE, pGB, pTerm, v4 uintptr
var v3 Tu32
_, _, _, _, _, _, _, _, _, _ = j, k, mxTerm, n, pCol, pE, pGB, pTerm, v3, v4
mxTerm = **(**int32)(__ccgo_up((*TParse)(unsafe.Pointer(pParse)).Fdb + 136 + 2*4))
pCol = (*TAggInfo)(unsafe.Pointer(pAggInfo)).FaCol
k = 0
for {
if !(k < (*TAggInfo)(unsafe.Pointer(pAggInfo)).FnColumn) {
break
}
if (*TAggInfo_col)(unsafe.Pointer(pCol)).FpCExpr == pExpr {
return
}
if (*TAggInfo_col)(unsafe.Pointer(pCol)).FiTable == (*TExpr)(unsafe.Pointer(pExpr)).FiTable && (*TAggInfo_col)(unsafe.Pointer(pCol)).FiColumn == int32((*TExpr)(unsafe.Pointer(pExpr)).FiColumn) && libc.Int32FromUint8((*TExpr)(unsafe.Pointer(pExpr)).Fop) != int32(TK_IF_NULL_ROW) {
goto fix_up_expr
}
goto _1
_1:
;
k = k + 1
pCol += 32
}
k = _addAggInfoColumn(tls, (*TParse)(unsafe.Pointer(pParse)).Fdb, pAggInfo)
if k < 0 {
/* OOM on resize */
return
}
if k > mxTerm {
_sqlite3ErrorMsg(tls, pParse, __ccgo_ts+8962, libc.VaList(bp+8, mxTerm))
k = mxTerm
}
pCol = (*TAggInfo)(unsafe.Pointer(pAggInfo)).FaCol + uintptr(k)*32
(*TAggInfo_col)(unsafe.Pointer(pCol)).FpTab = *(*uintptr)(unsafe.Pointer(pExpr + 64))
(*TAggInfo_col)(unsafe.Pointer(pCol)).FiTable = (*TExpr)(unsafe.Pointer(pExpr)).FiTable
(*TAggInfo_col)(unsafe.Pointer(pCol)).FiColumn = int32((*TExpr)(unsafe.Pointer(pExpr)).FiColumn)
(*TAggInfo_col)(unsafe.Pointer(pCol)).FiSorterColumn = -int32(1)
(*TAggInfo_col)(unsafe.Pointer(pCol)).FpCExpr = pExpr
if (*TAggInfo)(unsafe.Pointer(pAggInfo)).FpGroupBy != 0 && libc.Int32FromUint8((*TExpr)(unsafe.Pointer(pExpr)).Fop) != int32(TK_IF_NULL_ROW) {
pGB = (*TAggInfo)(unsafe.Pointer(pAggInfo)).FpGroupBy
pTerm = pGB + 8
n = (*TExprList)(unsafe.Pointer(pGB)).FnExpr
j = 0
for {
if !(j < n) {
break
}
pE = (*TExprList_item)(unsafe.Pointer(pTerm)).FpExpr
if libc.Int32FromUint8((*TExpr)(unsafe.Pointer(pE)).Fop) == int32(TK_COLUMN) && (*TExpr)(unsafe.Pointer(pE)).FiTable == (*TExpr)(unsafe.Pointer(pExpr)).FiTable && int32((*TExpr)(unsafe.Pointer(pE)).FiColumn) == int32((*TExpr)(unsafe.Pointer(pExpr)).FiColumn) {
(*TAggInfo_col)(unsafe.Pointer(pCol)).FiSorterColumn = j
break
}
goto _2
_2:
;
j = j + 1
pTerm += 32
}
}
if (*TAggInfo_col)(unsafe.Pointer(pCol)).FiSorterColumn < 0 {
v4 = pAggInfo + 4
v3 = *(*Tu32)(unsafe.Pointer(v4))
*(*Tu32)(unsafe.Pointer(v4)) = *(*Tu32)(unsafe.Pointer(v4)) + 1
(*TAggInfo_col)(unsafe.Pointer(pCol)).FiSorterColumn = libc.Int32FromUint32(v3)
}
goto fix_up_expr
fix_up_expr:
;
(*TExpr)(unsafe.Pointer(pExpr)).FpAggInfo = pAggInfo
if libc.Int32FromUint8((*TExpr)(unsafe.Pointer(pExpr)).Fop) == int32(TK_COLUMN) {
(*TExpr)(unsafe.Pointer(pExpr)).Fop = uint8(TK_AGG_COLUMN)
}
(*TExpr)(unsafe.Pointer(pExpr)).FiAgg = int16(k)
}
// C documentation
//
// /*
// ** Search for an unused file descriptor that was opened on the database
// ** file (not a journal or super-journal file) identified by pathname
// ** zPath with SQLITE_OPEN_XXX flags matching those passed as the second
// ** argument to this function.
// **
// ** Such a file descriptor may exist if a database connection was closed
// ** but the associated file descriptor could not be closed because some
// ** other file descriptor open on the same file is holding a file-lock.
// ** Refer to comments in the unixClose() function and the lengthy comment
// ** describing "Posix Advisory Locking" at the start of this file for
// ** further details. Also, ticket #4018.
// **
// ** If a suitable file descriptor is found, then it is returned. If no
// ** such file descriptor is located, -1 is returned.
// */
func _findReusableFd(tls *libc.TLS, zPath uintptr, flags int32) (r uintptr) {
bp := tls.Alloc(144)
defer tls.Free(144)
var pInode, pUnused, pp uintptr
var _ /* sStat at bp+0 */ Tstat
_, _, _ = pInode, pUnused, pp
pUnused = uintptr(0) /* Results of stat() call */
_unixEnterMutex(tls)
/* A stat() call may fail for various reasons. If this happens, it is
** almost certain that an open() call on the same path will also fail.
** For this reason, if an error occurs in the stat() call here, it is
** ignored and -1 is returned. The caller will try to open a new file
** descriptor on the same path, fail, and return an error to SQLite.
**
** Even if a subsequent open() call does succeed, the consequences of
** not searching for a reusable file descriptor are not dire. */
if _inodeList != uintptr(0) && 0 == (*(*func(*libc.TLS, uintptr, uintptr) int32)(unsafe.Pointer(&struct{ uintptr }{_aSyscall[int32(4)].FpCurrent})))(tls, zPath, bp) {
pInode = _inodeList
for pInode != 0 && ((*TunixInodeInfo)(unsafe.Pointer(pInode)).FfileId.Fdev != (**(**Tstat)(__ccgo_up(bp))).Fst_dev || (*TunixInodeInfo)(unsafe.Pointer(pInode)).FfileId.Fino != (**(**Tstat)(__ccgo_up(bp))).Fst_ino) {
pInode = (*TunixInodeInfo)(unsafe.Pointer(pInode)).FpNext
}
if pInode != 0 {
Xsqlite3_mutex_enter(tls, (*TunixInodeInfo)(unsafe.Pointer(pInode)).FpLockMutex)
flags = flags & (libc.Int32FromInt32(SQLITE_OPEN_READONLY) | libc.Int32FromInt32(SQLITE_OPEN_READWRITE))
pp = pInode + 40
for {
if !(**(**uintptr)(__ccgo_up(pp)) != 0 && (*TUnixUnusedFd)(unsafe.Pointer(**(**uintptr)(__ccgo_up(pp)))).Fflags != flags) {
break
}
goto _1
_1:
;
pp = **(**uintptr)(__ccgo_up(pp)) + 8
}
pUnused = **(**uintptr)(__ccgo_up(pp))
if pUnused != 0 {
**(**uintptr)(__ccgo_up(pp)) = (*TUnixUnusedFd)(unsafe.Pointer(pUnused)).FpNext
}
Xsqlite3_mutex_leave(tls, (*TunixInodeInfo)(unsafe.Pointer(pInode)).FpLockMutex)
}
}
_unixLeaveMutex(tls)
return pUnused
}
// C documentation
//
// /*
// ** Expression callback used by sqlite3FixAAAA() routines.
// */
func _fixExprCb(tls *libc.TLS, p uintptr, pExpr uintptr) (r int32) {
bp := tls.Alloc(16)
defer tls.Free(16)
var pFix uintptr
_ = pFix
pFix = *(*uintptr)(unsafe.Pointer(p + 40))
if !((*TDbFixer)(unsafe.Pointer(pFix)).FbTemp != 0) {
**(**Tu32)(__ccgo_up(pExpr + 4)) |= libc.Uint32FromInt32(libc.Int32FromInt32(EP_FromDDL))
}
if libc.Int32FromUint8((*TExpr)(unsafe.Pointer(pExpr)).Fop) == int32(TK_VARIABLE) {
if (*Tsqlite3)(unsafe.Pointer((*TParse)(unsafe.Pointer((*TDbFixer)(unsafe.Pointer(pFix)).FpParse)).Fdb)).Finit1.Fbusy != 0 {
(*TExpr)(unsafe.Pointer(pExpr)).Fop = uint8(TK_NULL)
} else {
_sqlite3ErrorMsg(tls, (*TDbFixer)(unsafe.Pointer(pFix)).FpParse, __ccgo_ts+13887, libc.VaList(bp+8, (*TDbFixer)(unsafe.Pointer(pFix)).FzType))
return int32(WRC_Abort)
}
}
return WRC_Continue
}
// C documentation
//
// /*
// ** Select callback used by sqlite3FixAAAA() routines.
// */
func _fixSelectCb(tls *libc.TLS, p uintptr, pSelect uintptr) (r int32) {
bp := tls.Alloc(32)
defer tls.Free(32)
var db, pFix, pItem, pList uintptr
var i, iDb int32
_, _, _, _, _, _ = db, i, iDb, pFix, pItem, pList
pFix = *(*uintptr)(unsafe.Pointer(p + 40))
db = (*TParse)(unsafe.Pointer((*TDbFixer)(unsafe.Pointer(pFix)).FpParse)).Fdb
iDb = _sqlite3FindDbName(tls, db, (*TDbFixer)(unsafe.Pointer(pFix)).FzDb)
pList = (*TSelect)(unsafe.Pointer(pSelect)).FpSrc
if pList == uintptr(0) {
return WRC_Continue
}
i = 0
pItem = pList + 8
for {
if !(i < (*TSrcList)(unsafe.Pointer(pList)).FnSrc) {
break
}
if libc.Int32FromUint8((*TDbFixer)(unsafe.Pointer(pFix)).FbTemp) == 0 && int32(*(*uint32)(unsafe.Pointer(pItem + 24 + 4))&0x4>>2) == 0 {
if int32(*(*uint32)(unsafe.Pointer(pItem + 24 + 4))&0x10000>>16) == 0 && *(*uintptr)(unsafe.Pointer(pItem + 72)) != uintptr(0) {
if iDb != _sqlite3FindDbName(tls, db, *(*uintptr)(unsafe.Pointer(pItem + 72))) {
_sqlite3ErrorMsg(tls, (*TDbFixer)(unsafe.Pointer(pFix)).FpParse, __ccgo_ts+13911, libc.VaList(bp+8, (*TDbFixer)(unsafe.Pointer(pFix)).FzType, (*TDbFixer)(unsafe.Pointer(pFix)).FpName, *(*uintptr)(unsafe.Pointer(pItem + 72))))
return int32(WRC_Abort)
}
_sqlite3DbFree(tls, db, *(*uintptr)(unsafe.Pointer(pItem + 72)))
libc.SetBitFieldPtr32Uint32(pItem+24+4, libc.Uint32FromInt32(1), 10, 0x400)
libc.SetBitFieldPtr32Uint32(pItem+24+4, libc.Uint32FromInt32(1), 17, 0x20000)
}
*(*uintptr)(unsafe.Pointer(pItem + 72)) = (*TDbFixer)(unsafe.Pointer(pFix)).FpSchema
libc.SetBitFieldPtr32Uint32(pItem+24+4, libc.Uint32FromInt32(1), 8, 0x100)
libc.SetBitFieldPtr32Uint32(pItem+24+4, libc.Uint32FromInt32(1), 16, 0x10000)
}
if int32(*(*uint32)(unsafe.Pointer(pList + 8 + uintptr(i)*80 + 24 + 4))&0x800>>11) == 0 && _sqlite3WalkExpr(tls, pFix+8, *(*uintptr)(unsafe.Pointer(pList + 8 + uintptr(i)*80 + 64))) != 0 {
return int32(WRC_Abort)
}
goto _1
_1:
;
i = i + 1
pItem += 80
}
if (*TSelect)(unsafe.Pointer(pSelect)).FpWith != 0 {
i = 0
for {
if !(i < (*TWith)(unsafe.Pointer((*TSelect)(unsafe.Pointer(pSelect)).FpWith)).FnCte) {
break
}
if _sqlite3WalkSelect(tls, p, (*(*TCte)(unsafe.Pointer((*TSelect)(unsafe.Pointer(pSelect)).FpWith + 16 + uintptr(i)*48))).FpSelect) != 0 {
return int32(WRC_Abort)
}
goto _2
_2:
;
i = i + 1
}
}
return WRC_Continue
}
// 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(80)
defer tls.Free(80)
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+8 */ uintptr
var _ /* pIdx at bp+0 */ uintptr
var _ /* tFromCol at bp+48 */ TToken
var _ /* tNew at bp+32 */ TToken
var _ /* tOld at bp+16 */ TToken
var _ /* tToCol at bp+64 */ 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 + 45 + uintptr(iAction))))
if (*Tsqlite3)(unsafe.Pointer(db)).Fflags&(libc.Uint64FromInt32(libc.Int32FromInt32(0x00008))< 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+8) != 0 {
return uintptr(0)
}
i = 0
for {
if !(i < (*TFKey)(unsafe.Pointer(pFKey)).FnCol) {
break
}
**(**TToken)(__ccgo_up(bp + 16)) = TToken{
Fz: __ccgo_ts + 7175,
Fn: uint32(3),
} /* Literal "old" token */
**(**TToken)(__ccgo_up(bp + 32)) = TToken{
Fz: __ccgo_ts + 7171,
Fn: uint32(3),
} /* tFromCol = OLD.tToCol */
if **(**uintptr)(__ccgo_up(bp + 8)) != 0 {
v2 = **(**int32)(__ccgo_up(**(**uintptr)(__ccgo_up(bp + 8)) + uintptr(i)*4))
} else {
v2 = (*(*TsColMap)(unsafe.Pointer(pFKey + 64))).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+64, (**(**TColumn)(__ccgo_up((*TTable)(unsafe.Pointer(pTab)).FaCol + uintptr(v2)*16))).FzCnName)
_sqlite3TokenInit(tls, bp+48, (**(**TColumn)(__ccgo_up((*TTable)(unsafe.Pointer((*TFKey)(unsafe.Pointer(pFKey)).FpFrom)).FaCol + uintptr(iFromCol)*16))).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+16, 0), _sqlite3ExprAlloc(tls, db, int32(TK_ID), bp+64, 0)), _sqlite3ExprAlloc(tls, db, int32(TK_ID), bp+48, 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+16, 0), _sqlite3ExprAlloc(tls, db, int32(TK_ID), bp+64, 0)), _sqlite3PExpr(tls, pParse, int32(TK_DOT), _sqlite3ExprAlloc(tls, db, int32(TK_ID), bp+32, 0), _sqlite3ExprAlloc(tls, db, int32(TK_ID), bp+64, 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+32, 0), _sqlite3ExprAlloc(tls, db, int32(TK_ID), bp+64, 0))
} else {
if action == int32(OE_SetDflt) {
pCol = (*TTable)(unsafe.Pointer((*TFKey)(unsafe.Pointer(pFKey)).FpFrom)).FaCol + uintptr(iFromCol)*16
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+48, 0)
}
goto _1
_1:
;
i = i + 1
}
_sqlite3DbFree(tls, db, **(**uintptr)(__ccgo_up(bp + 8)))
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+5740)
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+24+4, libc.Uint32FromInt32(1), 16, 0x10000)
*(*uintptr)(unsafe.Pointer(pItem + 72)) = (*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.Uint64FromInt64(72)+libc.Uint64FromInt64(88)))
if pTrigger != 0 {
v4 = pTrigger + 1*72
(*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 + 72)) = (*TTable)(unsafe.Pointer(pTab)).FpSchema
libc.SetBitFieldPtr32Uint32(pItem1+24+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 + 48 + uintptr(iAction)*8)) = 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
//
// /*
// ** This function is called to generate code executed when a row is deleted
// ** from the parent table of foreign key constraint pFKey and, if pFKey is
// ** deferred, when a row is inserted into the same table. When generating
// ** code for an SQL UPDATE operation, this function may be called twice -
// ** once to "delete" the old row and once to "insert" the new row.
// **
// ** Parameter nIncr is passed -1 when inserting a row (as this may decrease
// ** the number of FK violations in the db) or +1 when deleting one (as this
// ** may increase the number of FK constraint problems).
// **
// ** The code generated by this function scans through the rows in the child
// ** table that correspond to the parent table row being deleted or inserted.
// ** For each child row found, one of the following actions is taken:
// **
// ** Operation | FK type | Action taken
// ** --------------------------------------------------------------------------
// ** DELETE immediate Increment the "immediate constraint counter".
// **
// ** INSERT immediate Decrement the "immediate constraint counter".
// **
// ** DELETE deferred Increment the "deferred constraint counter".
// **
// ** INSERT deferred Decrement the "deferred constraint counter".
// **
// ** These operations are identified in the comment at the top of this file
// ** (fkey.c) as "I.2" and "D.2".
// */
func _fkScanChildren(tls *libc.TLS, pParse uintptr, pSrc uintptr, pTab uintptr, pIdx uintptr, pFKey uintptr, aiCol uintptr, regData int32, nIncr int32) {
bp := tls.Alloc(64)
defer tls.Free(64)
var db, pAll, pEq, pEq1, pLeft, pLeft1, pNe, pRight, pRight1, pWInfo, pWhere, v, zCol uintptr
var i, iFkIfZero, v2 int32
var iCol, iCol1 Ti16
var _ /* sNameContext at bp+0 */ TNameContext
_, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _ = db, i, iCol, iCol1, iFkIfZero, pAll, pEq, pEq1, pLeft, pLeft1, pNe, pRight, pRight1, pWInfo, pWhere, v, zCol, v2
db = (*TParse)(unsafe.Pointer(pParse)).Fdb /* Iterator variable */
pWhere = uintptr(0) /* Context used by sqlite3WhereXXX() */
iFkIfZero = 0 /* Address of OP_FkIfZero */
v = _sqlite3GetVdbe(tls, pParse)
if nIncr < 0 {
iFkIfZero = _sqlite3VdbeAddOp2(tls, v, int32(OP_FkIfZero), libc.Int32FromUint8((*TFKey)(unsafe.Pointer(pFKey)).FisDeferred), 0)
}
/* Create an Expr object representing an SQL expression like:
**
** = AND = ...
**
** The collation sequence used for the comparison should be that of
** the parent key columns. The affinity of the parent key column should
** be applied to each child key value before the comparison takes place.
*/
i = 0
for {
if !(i < (*TFKey)(unsafe.Pointer(pFKey)).FnCol) {
break
} /* Name of column in child table */
if pIdx != 0 {
v2 = int32(**(**Ti16)(__ccgo_up((*TIndex)(unsafe.Pointer(pIdx)).FaiColumn + uintptr(i)*2)))
} else {
v2 = -int32(1)
}
iCol = int16(v2)
pLeft = _exprTableRegister(tls, pParse, pTab, regData, iCol)
if aiCol != 0 {
v2 = **(**int32)(__ccgo_up(aiCol + uintptr(i)*4))
} else {
v2 = (*(*TsColMap)(unsafe.Pointer(pFKey + 64))).FiFrom
}
iCol = int16(v2)
zCol = (**(**TColumn)(__ccgo_up((*TTable)(unsafe.Pointer((*TFKey)(unsafe.Pointer(pFKey)).FpFrom)).FaCol + uintptr(iCol)*16))).FzCnName
pRight = _sqlite3Expr(tls, db, int32(TK_ID), zCol)
pEq = _sqlite3PExpr(tls, pParse, int32(TK_EQ), pLeft, pRight)
pWhere = _sqlite3ExprAnd(tls, pParse, pWhere, pEq)
goto _1
_1:
;
i = i + 1
}
/* If the child table is the same as the parent table, then add terms
** to the WHERE clause that prevent this entry from being scanned.
** The added WHERE clause terms are like this:
**
** $current_rowid!=rowid
** NOT( $current_a==a AND $current_b==b AND ... )
**
** The first form is used for rowid tables. The second form is used
** for WITHOUT ROWID tables. In the second form, the *parent* key is
** (a,b,...). Either the parent or primary key could be used to
** uniquely identify the current row, but the parent key is more convenient
** as the required values have already been loaded into registers
** by the caller.
*/
if pTab == (*TFKey)(unsafe.Pointer(pFKey)).FpFrom && nIncr > 0 { /* Column ref to child table */
if (*TTable)(unsafe.Pointer(pTab)).FtabFlags&uint32(TF_WithoutRowid) == uint32(0) {
pLeft1 = _exprTableRegister(tls, pParse, pTab, regData, int16(-int32(1)))
pRight1 = _exprTableColumn(tls, db, pTab, (*(*TSrcItem)(unsafe.Pointer(pSrc + 8))).FiCursor, int16(-int32(1)))
pNe = _sqlite3PExpr(tls, pParse, int32(TK_NE), pLeft1, pRight1)
} else {
pAll = uintptr(0)
i = 0
for {
if !(i < libc.Int32FromUint16((*TIndex)(unsafe.Pointer(pIdx)).FnKeyCol)) {
break
}
iCol1 = **(**Ti16)(__ccgo_up((*TIndex)(unsafe.Pointer(pIdx)).FaiColumn + uintptr(i)*2))
pLeft1 = _exprTableRegister(tls, pParse, pTab, regData, iCol1)
pRight1 = _sqlite3Expr(tls, db, int32(TK_ID), (**(**TColumn)(__ccgo_up((*TTable)(unsafe.Pointer(pTab)).FaCol + uintptr(iCol1)*16))).FzCnName)
pEq1 = _sqlite3PExpr(tls, pParse, int32(TK_IS), pLeft1, pRight1)
pAll = _sqlite3ExprAnd(tls, pParse, pAll, pEq1)
goto _4
_4:
;
i = i + 1
}
pNe = _sqlite3PExpr(tls, pParse, int32(TK_NOT), pAll, uintptr(0))
}
pWhere = _sqlite3ExprAnd(tls, pParse, pWhere, pNe)
}
/* Resolve the references in the WHERE clause. */
libc.X__builtin___memset_chk(tls, bp, 0, uint64(56), ^t__predefined_size_t(0))
(**(**TNameContext)(__ccgo_up(bp))).FpSrcList = pSrc
(**(**TNameContext)(__ccgo_up(bp))).FpParse = pParse
_sqlite3ResolveExprNames(tls, bp, pWhere)
/* Create VDBE to loop through the entries in pSrc that match the WHERE
** clause. For each row found, increment either the deferred or immediate
** foreign key constraint counter. */
if (*TParse)(unsafe.Pointer(pParse)).FnErr == 0 {
pWInfo = _sqlite3WhereBegin(tls, pParse, pSrc, pWhere, uintptr(0), uintptr(0), uintptr(0), uint16(0), 0)
_sqlite3VdbeAddOp2(tls, v, int32(OP_FkCounter), libc.Int32FromUint8((*TFKey)(unsafe.Pointer(pFKey)).FisDeferred), nIncr)
if pWInfo != 0 {
_sqlite3WhereEnd(tls, pWInfo)
}
}
/* Clean up the WHERE clause constructed above. */
_sqlite3ExprDelete(tls, db, pWhere)
if iFkIfZero != 0 {
_sqlite3VdbeJumpHereOrPopInst(tls, v, iFkIfZero)
}
}
// C documentation
//
// /*
// ** This routine attempts to flatten subqueries as a performance optimization.
// ** This routine returns 1 if it makes changes and 0 if no flattening occurs.
// **
// ** To understand the concept of flattening, consider the following
// ** query:
// **
// ** SELECT a FROM (SELECT x+y AS a FROM t1 WHERE z<100) WHERE a>5
// **
// ** The default way of implementing this query is to execute the
// ** subquery first and store the results in a temporary table, then
// ** run the outer query on that temporary table. This requires two
// ** passes over the data. Furthermore, because the temporary table
// ** has no indices, the WHERE clause on the outer query cannot be
// ** optimized.
// **
// ** This routine attempts to rewrite queries such as the above into
// ** a single flat select, like this:
// **
// ** SELECT x+y AS a FROM t1 WHERE z<100 AND a>5
// **
// ** The code generated for this simplification gives the same result
// ** but only has to scan the data once. And because indices might
// ** exist on the table t1, a complete scan of the data might be
// ** avoided.
// **
// ** Flattening is subject to the following constraints:
// **
// ** (**) We no longer attempt to flatten aggregate subqueries. Was:
// ** The subquery and the outer query cannot both be aggregates.
// **
// ** (**) We no longer attempt to flatten aggregate subqueries. Was:
// ** (2) If the subquery is an aggregate then
// ** (2a) the outer query must not be a join and
// ** (2b) the outer query must not use subqueries
// ** other than the one FROM-clause subquery that is a candidate
// ** for flattening. (This is due to ticket [2f7170d73bf9abf80]
// ** from 2015-02-09.)
// **
// ** (3) If the subquery is the right operand of a LEFT JOIN then
// ** (3a) the subquery may not be a join
// ** (**) Was (3b): "the FROM clause of the subquery may not contain
// ** a virtual table"
// ** (**) Was: "The outer query may not have a GROUP BY." This case
// ** is now managed correctly
// ** (3d) the outer query may not be DISTINCT.
// ** See also (26) for restrictions on RIGHT JOIN.
// **
// ** (4) The subquery can not be DISTINCT.
// **
// ** (**) At one point restrictions (4) and (5) defined a subset of DISTINCT
// ** sub-queries that were excluded from this optimization. Restriction
// ** (4) has since been expanded to exclude all DISTINCT subqueries.
// **
// ** (**) We no longer attempt to flatten aggregate subqueries. Was:
// ** If the subquery is aggregate, the outer query may not be DISTINCT.
// **
// ** (7) The subquery must have a FROM clause. TODO: For subqueries without
// ** A FROM clause, consider adding a FROM clause with the special
// ** table sqlite_once that consists of a single row containing a
// ** single NULL.
// **
// ** (8) If the subquery uses LIMIT then the outer query may not be a join.
// **
// ** (9) If the subquery uses LIMIT then the outer query may not be aggregate.
// **
// ** (**) Restriction (10) was removed from the code on 2005-02-05 but we
// ** accidentally carried the comment forward until 2014-09-15. Original
// ** constraint: "If the subquery is aggregate then the outer query
// ** may not use LIMIT."
// **
// ** (11) The subquery and the outer query may not both have ORDER BY clauses.
// **
// ** (**) Not implemented. Subsumed into restriction (3). Was previously
// ** a separate restriction deriving from ticket #350.
// **
// ** (13) The subquery and outer query may not both use LIMIT.
// **
// ** (14) The subquery may not use OFFSET.
// **
// ** (15) If the outer query is part of a compound select, then the
// ** subquery may not use LIMIT.
// ** (See ticket #2339 and ticket [02a8e81d44]).
// **
// ** (16) If the outer query is aggregate, then the subquery may not
// ** use ORDER BY. (Ticket #2942) This used to not matter
// ** until we introduced the group_concat() function.
// **
// ** (17) If the subquery is a compound select, then
// ** (17a) all compound operators must be a UNION ALL, and
// ** (17b) no terms within the subquery compound may be aggregate
// ** or DISTINCT, and
// ** (17c) every term within the subquery compound must have a FROM clause
// ** (17d) the outer query may not be
// ** (17d1) aggregate, or
// ** (17d2) DISTINCT
// ** (17e) the subquery may not contain window functions, and
// ** (17f) the subquery must not be the RHS of a LEFT JOIN.
// ** (17g) either the subquery is the first element of the outer
// ** query or there are no RIGHT or FULL JOINs in any arm
// ** of the subquery. (This is a duplicate of condition (27b).)
// ** (17h) The corresponding result set expressions in all arms of the
// ** compound must have the same affinity.
// **
// ** The parent and sub-query may contain WHERE clauses. Subject to
// ** rules (11), (13) and (14), they may also contain ORDER BY,
// ** LIMIT and OFFSET clauses. The subquery cannot use any compound
// ** operator other than UNION ALL because all the other compound
// ** operators have an implied DISTINCT which is disallowed by
// ** restriction (4).
// **
// ** Also, each component of the sub-query must return the same number
// ** of result columns. This is actually a requirement for any compound
// ** SELECT statement, but all the code here does is make sure that no
// ** such (illegal) sub-query is flattened. The caller will detect the
// ** syntax error and return a detailed message.
// **
// ** (18) If the sub-query is a compound select, then all terms of the
// ** ORDER BY clause of the parent must be copies of a term returned
// ** by the parent query.
// **
// ** (19) If the subquery uses LIMIT then the outer query may not
// ** have a WHERE clause.
// **
// ** (20) If the sub-query is a compound select, then it must not use
// ** an ORDER BY clause. Ticket #3773. We could relax this constraint
// ** somewhat by saying that the terms of the ORDER BY clause must
// ** appear as unmodified result columns in the outer query. But we
// ** have other optimizations in mind to deal with that case.
// **
// ** (21) If the subquery uses LIMIT then the outer query may not be
// ** DISTINCT. (See ticket [752e1646fc]).
// **
// ** (22) The subquery may not be a recursive CTE.
// **
// ** (23) If the outer query is a recursive CTE, then the sub-query may not be
// ** a compound query. This restriction is because transforming the
// ** parent to a compound query confuses the code that handles
// ** recursive queries in multiSelect().
// **
// ** (**) We no longer attempt to flatten aggregate subqueries. Was:
// ** The subquery may not be an aggregate that uses the built-in min() or
// ** or max() functions. (Without this restriction, a query like:
// ** "SELECT x FROM (SELECT max(y), x FROM t1)" would not necessarily
// ** return the value X for which Y was maximal.)
// **
// ** (25) If either the subquery or the parent query contains a window
// ** function in the select list or ORDER BY clause, flattening
// ** is not attempted.
// **
// ** (26) The subquery may not be the right operand of a RIGHT JOIN.
// ** See also (3) for restrictions on LEFT JOIN.
// **
// ** (27) The subquery may not contain a FULL or RIGHT JOIN unless it
// ** is the first element of the parent query. Two subcases:
// ** (27a) the subquery is not a compound query.
// ** (27b) the subquery is a compound query and the RIGHT JOIN occurs
// ** in any arm of the compound query. (See also (17g).)
// **
// ** (28) The subquery is not a MATERIALIZED CTE. (This is handled
// ** in the caller before ever reaching this routine.)
// **
// **
// ** In this routine, the "p" parameter is a pointer to the outer query.
// ** The subquery is p->pSrc->a[iFrom]. isAgg is true if the outer query
// ** uses aggregates.
// **
// ** If flattening is not attempted, this routine is a no-op and returns 0.
// ** If flattening is attempted this routine returns 1.
// **
// ** All of the expression analysis must occur on both the outer query and
// ** the subquery before this routine runs.
// */
func _flattenSubquery(tls *libc.TLS, pParse uintptr, p uintptr, iFrom int32, isAgg int32) (r int32) {
bp := tls.Alloc(96)
defer tls.Free(96)
var aCsrMap, db, pItem, pItemTab, pLimit, pNew, pOrderBy, pOrderBy1, pParent, pPrior, pSrc, pSub, pSub1, pSubSrc, pSubitem, pTabToDel, pToplevel, pWhere, zSavedAuthContext, v5 uintptr
var i, iNewParent, iParent, ii, isOuterJoin, nSubSrc, v4 int32
var jointype Tu8
var _ /* w at bp+0 */ TWalker
var _ /* x at bp+48 */ TSubstContext
_, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _ = aCsrMap, db, i, iNewParent, iParent, ii, isOuterJoin, jointype, nSubSrc, pItem, pItemTab, pLimit, pNew, pOrderBy, pOrderBy1, pParent, pPrior, pSrc, pSub, pSub1, pSubSrc, pSubitem, pTabToDel, pToplevel, pWhere, zSavedAuthContext, v4, v5
zSavedAuthContext = (*TParse)(unsafe.Pointer(pParse)).FzAuthContext /* VDBE cursor number of the pSub result set temp table */
iNewParent = -int32(1) /* Replacement table for iParent */
isOuterJoin = 0 /* The subquery */
db = (*TParse)(unsafe.Pointer(pParse)).Fdb /* Walker to persist agginfo data */
aCsrMap = uintptr(0)
/* Check to see if flattening is permitted. Return 0 if not.
*/
if (*Tsqlite3)(unsafe.Pointer(db)).FdbOptFlags&libc.Uint32FromInt32(libc.Int32FromInt32(SQLITE_QueryFlattener)) != uint32(0) {
return 0
}
pSrc = (*TSelect)(unsafe.Pointer(p)).FpSrc
pSubitem = pSrc + 8 + uintptr(iFrom)*80
iParent = (*TSrcItem)(unsafe.Pointer(pSubitem)).FiCursor
pSub = (*TSubquery)(unsafe.Pointer(*(*uintptr)(unsafe.Pointer(pSubitem + 72)))).FpSelect
if (*TSelect)(unsafe.Pointer(p)).FpWin != 0 || (*TSelect)(unsafe.Pointer(pSub)).FpWin != 0 {
return 0
} /* Restriction (25) */
pSubSrc = (*TSelect)(unsafe.Pointer(pSub)).FpSrc
/* Prior to version 3.1.2, when LIMIT and OFFSET had to be simple constants,
** not arbitrary expressions, we allowed some combining of LIMIT and OFFSET
** because they could be computed at compile-time. But when LIMIT and OFFSET
** became arbitrary expressions, we were forced to add restrictions (13)
** and (14). */
if (*TSelect)(unsafe.Pointer(pSub)).FpLimit != 0 && (*TSelect)(unsafe.Pointer(p)).FpLimit != 0 {
return 0
} /* Restriction (13) */
if (*TSelect)(unsafe.Pointer(pSub)).FpLimit != 0 && (*TExpr)(unsafe.Pointer((*TSelect)(unsafe.Pointer(pSub)).FpLimit)).FpRight != 0 {
return 0
} /* Restriction (14) */
if (*TSelect)(unsafe.Pointer(p)).FselFlags&uint32(SF_Compound) != uint32(0) && (*TSelect)(unsafe.Pointer(pSub)).FpLimit != 0 {
return 0 /* Restriction (15) */
}
if (*TSrcList)(unsafe.Pointer(pSubSrc)).FnSrc == 0 {
return 0
} /* Restriction (7) */
if (*TSelect)(unsafe.Pointer(pSub)).FselFlags&uint32(SF_Distinct) != 0 {
return 0
} /* Restriction (4) */
if (*TSelect)(unsafe.Pointer(pSub)).FpLimit != 0 && ((*TSrcList)(unsafe.Pointer(pSrc)).FnSrc > int32(1) || isAgg != 0) {
return 0 /* Restrictions (8)(9) */
}
if (*TSelect)(unsafe.Pointer(p)).FpOrderBy != 0 && (*TSelect)(unsafe.Pointer(pSub)).FpOrderBy != 0 {
return 0 /* Restriction (11) */
}
if isAgg != 0 && (*TSelect)(unsafe.Pointer(pSub)).FpOrderBy != 0 {
return 0
} /* Restriction (16) */
if (*TSelect)(unsafe.Pointer(pSub)).FpLimit != 0 && (*TSelect)(unsafe.Pointer(p)).FpWhere != 0 {
return 0
} /* Restriction (19) */
if (*TSelect)(unsafe.Pointer(pSub)).FpLimit != 0 && (*TSelect)(unsafe.Pointer(p)).FselFlags&uint32(SF_Distinct) != uint32(0) {
return 0 /* Restriction (21) */
}
if (*TSelect)(unsafe.Pointer(pSub)).FselFlags&libc.Uint32FromInt32(libc.Int32FromInt32(SF_Recursive)) != 0 {
return 0 /* Restrictions (22) */
}
/*
** If the subquery is the right operand of a LEFT JOIN, then the
** subquery may not be a join itself (3a). Example of why this is not
** allowed:
**
** t1 LEFT OUTER JOIN (t2 JOIN t3)
**
** If we flatten the above, we would get
**
** (t1 LEFT OUTER JOIN t2) JOIN t3
**
** which is not at all the same thing.
**
** See also tickets #306, #350, and #3300.
*/
if libc.Int32FromUint8((*TSrcItem)(unsafe.Pointer(pSubitem)).Ffg.Fjointype)&(libc.Int32FromInt32(JT_OUTER)|libc.Int32FromInt32(JT_LTORJ)) != 0 {
if (*TSrcList)(unsafe.Pointer(pSubSrc)).FnSrc > int32(1) || (*TSelect)(unsafe.Pointer(p)).FselFlags&uint32(SF_Distinct) != uint32(0) || libc.Int32FromUint8((*TSrcItem)(unsafe.Pointer(pSubitem)).Ffg.Fjointype)&int32(JT_RIGHT) != 0 {
return 0
}
isOuterJoin = int32(1)
}
/* True by restriction (7) */
if iFrom > 0 && libc.Int32FromUint8((*(*TSrcItem)(unsafe.Pointer(pSubSrc + 8))).Ffg.Fjointype)&int32(JT_LTORJ) != 0 {
return 0 /* Restriction (27a) */
}
/* Condition (28) is blocked by the caller */
/* Restriction (17): If the sub-query is a compound SELECT, then it must
** use only the UNION ALL operator. And none of the simple select queries
** that make up the compound SELECT are allowed to be aggregate or distinct
** queries.
*/
if (*TSelect)(unsafe.Pointer(pSub)).FpPrior != 0 {
if (*TSelect)(unsafe.Pointer(pSub)).FpOrderBy != 0 {
return 0 /* Restriction (20) */
}
if isAgg != 0 || (*TSelect)(unsafe.Pointer(p)).FselFlags&uint32(SF_Distinct) != uint32(0) || isOuterJoin > 0 {
return 0 /* (17d1), (17d2), or (17f) */
}
pSub1 = pSub
for {
if !(pSub1 != 0) {
break
}
if (*TSelect)(unsafe.Pointer(pSub1)).FselFlags&libc.Uint32FromInt32(libc.Int32FromInt32(SF_Distinct)|libc.Int32FromInt32(SF_Aggregate)) != uint32(0) || (*TSelect)(unsafe.Pointer(pSub1)).FpPrior != 0 && libc.Int32FromUint8((*TSelect)(unsafe.Pointer(pSub1)).Fop) != int32(TK_ALL) || (*TSrcList)(unsafe.Pointer((*TSelect)(unsafe.Pointer(pSub1)).FpSrc)).FnSrc < int32(1) || (*TSelect)(unsafe.Pointer(pSub1)).FpWin != 0 {
return 0
}
if iFrom > 0 && libc.Int32FromUint8((*(*TSrcItem)(unsafe.Pointer((*TSelect)(unsafe.Pointer(pSub1)).FpSrc + 8))).Ffg.Fjointype)&int32(JT_LTORJ) != 0 {
/* Without this restriction, the JT_LTORJ flag would end up being
** omitted on left-hand tables of the right join that is being
** flattened. */
return 0 /* Restrictions (17g), (27b) */
}
goto _1
_1:
;
pSub1 = (*TSelect)(unsafe.Pointer(pSub1)).FpPrior
}
/* Restriction (18). */
if (*TSelect)(unsafe.Pointer(p)).FpOrderBy != 0 {
ii = 0
for {
if !(ii < (*TExprList)(unsafe.Pointer((*TSelect)(unsafe.Pointer(p)).FpOrderBy)).FnExpr) {
break
}
if libc.Int32FromUint16(*(*Tu16)(unsafe.Pointer((*TSelect)(unsafe.Pointer(p)).FpOrderBy + 8 + uintptr(ii)*32 + 24))) == 0 {
return 0
}
goto _2
_2:
;
ii = ii + 1
}
}
/* Restriction (23) */
if (*TSelect)(unsafe.Pointer(p)).FselFlags&uint32(SF_Recursive) != 0 {
return 0
}
/* Restriction (17h) */
if _compoundHasDifferentAffinities(tls, pSub) != 0 {
return 0
}
if (*TSrcList)(unsafe.Pointer(pSrc)).FnSrc > int32(1) {
if (*TParse)(unsafe.Pointer(pParse)).FnSelect > int32(500) {
return 0
}
if (*Tsqlite3)(unsafe.Pointer(db)).FdbOptFlags&libc.Uint32FromInt32(libc.Int32FromInt32(SQLITE_FlttnUnionAll)) != uint32(0) {
return 0
}
aCsrMap = _sqlite3DbMallocZero(tls, db, libc.Uint64FromInt64(int64((*TParse)(unsafe.Pointer(pParse)).FnTab)+libc.Int64FromInt32(1))*uint64(4))
if aCsrMap != 0 {
**(**int32)(__ccgo_up(aCsrMap)) = (*TParse)(unsafe.Pointer(pParse)).FnTab
}
}
}
/***** If we reach this point, flattening is permitted. *****/
/* Authorize the subquery */
(*TParse)(unsafe.Pointer(pParse)).FzAuthContext = (*TSrcItem)(unsafe.Pointer(pSubitem)).FzName
_sqlite3AuthCheck(tls, pParse, int32(SQLITE_SELECT), uintptr(0), uintptr(0), uintptr(0))
(*TParse)(unsafe.Pointer(pParse)).FzAuthContext = zSavedAuthContext
/* Delete the transient structures associated with the subquery */
if int32(*(*uint32)(unsafe.Pointer(pSubitem + 24 + 4))&0x4>>2) != 0 {
pSub1 = _sqlite3SubqueryDetach(tls, db, pSubitem)
} else {
pSub1 = uintptr(0)
}
_sqlite3DbFree(tls, db, (*TSrcItem)(unsafe.Pointer(pSubitem)).FzName)
_sqlite3DbFree(tls, db, (*TSrcItem)(unsafe.Pointer(pSubitem)).FzAlias)
(*TSrcItem)(unsafe.Pointer(pSubitem)).FzName = uintptr(0)
(*TSrcItem)(unsafe.Pointer(pSubitem)).FzAlias = uintptr(0)
/* If the sub-query is a compound SELECT statement, then (by restrictions
** 17 and 18 above) it must be a UNION ALL and the parent query must
** be of the form:
**
** SELECT FROM ()
**
** followed by any ORDER BY, LIMIT and/or OFFSET clauses. This block
** creates N-1 copies of the parent query without any ORDER BY, LIMIT or
** OFFSET clauses and joins them to the left-hand-side of the original
** using UNION ALL operators. In this case N is the number of simple
** select statements in the compound sub-query.
**
** Example:
**
** SELECT a+1 FROM (
** SELECT x FROM tab
** UNION ALL
** SELECT y FROM tab
** UNION ALL
** SELECT abs(z*2) FROM tab2
** ) WHERE a!=5 ORDER BY 1
**
** Transformed into:
**
** SELECT x+1 FROM tab WHERE x+1!=5
** UNION ALL
** SELECT y+1 FROM tab WHERE y+1!=5
** UNION ALL
** SELECT abs(z*2)+1 FROM tab2 WHERE abs(z*2)+1!=5
** ORDER BY 1
**
** We call this the "compound-subquery flattening".
*/
pSub = (*TSelect)(unsafe.Pointer(pSub)).FpPrior
for {
if !(pSub != 0) {
break
}
pOrderBy = (*TSelect)(unsafe.Pointer(p)).FpOrderBy
pLimit = (*TSelect)(unsafe.Pointer(p)).FpLimit
pPrior = (*TSelect)(unsafe.Pointer(p)).FpPrior
pItemTab = (*TSrcItem)(unsafe.Pointer(pSubitem)).FpSTab
(*TSrcItem)(unsafe.Pointer(pSubitem)).FpSTab = uintptr(0)
(*TSelect)(unsafe.Pointer(p)).FpOrderBy = uintptr(0)
(*TSelect)(unsafe.Pointer(p)).FpPrior = uintptr(0)
(*TSelect)(unsafe.Pointer(p)).FpLimit = uintptr(0)
pNew = _sqlite3SelectDup(tls, db, p, 0)
(*TSelect)(unsafe.Pointer(p)).FpLimit = pLimit
(*TSelect)(unsafe.Pointer(p)).FpOrderBy = pOrderBy
(*TSelect)(unsafe.Pointer(p)).Fop = uint8(TK_ALL)
(*TSrcItem)(unsafe.Pointer(pSubitem)).FpSTab = pItemTab
if pNew == uintptr(0) {
(*TSelect)(unsafe.Pointer(p)).FpPrior = pPrior
} else {
v5 = pParse + 132
*(*int32)(unsafe.Pointer(v5)) = *(*int32)(unsafe.Pointer(v5)) + 1
v4 = *(*int32)(unsafe.Pointer(v5))
(*TSelect)(unsafe.Pointer(pNew)).FselId = libc.Uint32FromInt32(v4)
if aCsrMap != 0 && libc.Int32FromUint8((*Tsqlite3)(unsafe.Pointer(db)).FmallocFailed) == 0 {
_renumberCursors(tls, pParse, pNew, iFrom, aCsrMap)
}
(*TSelect)(unsafe.Pointer(pNew)).FpPrior = pPrior
if pPrior != 0 {
(*TSelect)(unsafe.Pointer(pPrior)).FpNext = pNew
}
(*TSelect)(unsafe.Pointer(pNew)).FpNext = p
(*TSelect)(unsafe.Pointer(p)).FpPrior = pNew
}
goto _3
_3:
;
pSub = (*TSelect)(unsafe.Pointer(pSub)).FpPrior
}
_sqlite3DbFree(tls, db, aCsrMap)
if (*Tsqlite3)(unsafe.Pointer(db)).FmallocFailed != 0 {
_sqlite3SrcItemAttachSubquery(tls, pParse, pSubitem, pSub1, 0)
return int32(1)
}
/* Defer deleting the Table object associated with the
** subquery until code generation is
** complete, since there may still exist Expr.pTab entries that
** refer to the subquery even after flattening. Ticket #3346.
**
** pSubitem->pSTab is always non-NULL by test restrictions and tests above.
*/
if (*TSrcItem)(unsafe.Pointer(pSubitem)).FpSTab != uintptr(0) {
pTabToDel = (*TSrcItem)(unsafe.Pointer(pSubitem)).FpSTab
if (*TTable)(unsafe.Pointer(pTabToDel)).FnTabRef == uint32(1) {
if (*TParse)(unsafe.Pointer(pParse)).FpToplevel != 0 {
v5 = (*TParse)(unsafe.Pointer(pParse)).FpToplevel
} else {
v5 = pParse
}
pToplevel = v5
_sqlite3ParserAddCleanup(tls, pToplevel, __ccgo_fp(_sqlite3DeleteTableGeneric), pTabToDel)
} else {
(*TTable)(unsafe.Pointer(pTabToDel)).FnTabRef = (*TTable)(unsafe.Pointer(pTabToDel)).FnTabRef - 1
}
(*TSrcItem)(unsafe.Pointer(pSubitem)).FpSTab = uintptr(0)
}
/* The following loop runs once for each term in a compound-subquery
** flattening (as described above). If we are doing a different kind
** of flattening - a flattening other than a compound-subquery flattening -
** then this loop only runs once.
**
** This loop moves all of the FROM elements of the subquery into the
** the FROM clause of the outer query. Before doing this, remember
** the cursor number for the original outer query FROM element in
** iParent. The iParent cursor will never be used. Subsequent code
** will scan expressions looking for iParent references and replace
** those references with expressions that resolve to the subquery FROM
** elements we are now copying in.
*/
pSub = pSub1
pParent = p
for {
if !(pParent != 0) {
break
}
jointype = (*TSrcItem)(unsafe.Pointer(pSubitem)).Ffg.Fjointype
pSubSrc = (*TSelect)(unsafe.Pointer(pSub)).FpSrc /* FROM clause of subquery */
nSubSrc = (*TSrcList)(unsafe.Pointer(pSubSrc)).FnSrc /* Number of terms in subquery FROM clause */
pSrc = (*TSelect)(unsafe.Pointer(pParent)).FpSrc /* FROM clause of the outer query */
/* The subquery uses a single slot of the FROM clause of the outer
** query. If the subquery has more than one element in its FROM clause,
** then expand the outer query to make space for it to hold all elements
** of the subquery.
**
** Example:
**
** SELECT * FROM tabA, (SELECT * FROM sub1, sub2), tabB;
**
** The outer query has 3 slots in its FROM clause. One slot of the
** outer query (the middle slot) is used by the subquery. The next
** block of code will expand the outer query FROM clause to 4 slots.
** The middle slot is expanded to two slots in order to make space
** for the two elements in the FROM clause of the subquery.
*/
if nSubSrc > int32(1) {
pSrc = _sqlite3SrcListEnlarge(tls, pParse, pSrc, nSubSrc-int32(1), iFrom+int32(1))
if pSrc == uintptr(0) {
break
}
(*TSelect)(unsafe.Pointer(pParent)).FpSrc = pSrc
pSubitem = pSrc + 8 + uintptr(iFrom)*80
}
/* Transfer the FROM clause terms from the subquery into the
** outer query.
*/
iNewParent = (*(*TSrcItem)(unsafe.Pointer(pSubSrc + 8))).FiCursor
i = 0
for {
if !(i < nSubSrc) {
break
}
pItem = pSrc + 8 + uintptr(i+iFrom)*80
if int32(*(*uint32)(unsafe.Pointer(pItem + 24 + 4))&0x800>>11) != 0 {
_sqlite3IdListDelete(tls, db, *(*uintptr)(unsafe.Pointer(pItem + 64)))
}
**(**TSrcItem)(__ccgo_up(pItem)) = *(*TSrcItem)(unsafe.Pointer(pSubSrc + 8 + uintptr(i)*80))
v5 = pItem + 24
*(*Tu8)(unsafe.Pointer(v5)) = Tu8(int32(*(*Tu8)(unsafe.Pointer(v5))) | libc.Int32FromUint8(jointype)&libc.Int32FromInt32(JT_LTORJ))
libc.X__builtin___memset_chk(tls, pSubSrc+8+uintptr(i)*80, 0, uint64(80), ^t__predefined_size_t(0))
goto _8
_8:
;
i = i + 1
}
v5 = pSubitem + 24
*(*Tu8)(unsafe.Pointer(v5)) = Tu8(int32(*(*Tu8)(unsafe.Pointer(v5))) | libc.Int32FromUint8(jointype))
/* Begin substituting subquery result set expressions for
** references to the iParent in the outer query.
**
** Example:
**
** SELECT a+5, b*10 FROM (SELECT x*3 AS a, y+10 AS b FROM t1) WHERE a>b;
** \ \_____________ subquery __________/ /
** \_____________________ outer query ______________________________/
**
** We look at every expression in the outer query and every place we see
** "a" we substitute "x*3" and every place we see "b" we substitute "y+10".
*/
if (*TSelect)(unsafe.Pointer(pSub)).FpOrderBy != 0 {
/* At this point, any non-zero iOrderByCol values indicate that the
** ORDER BY column expression is identical to the iOrderByCol'th
** expression returned by SELECT statement pSub. Since these values
** do not necessarily correspond to columns in SELECT statement pParent,
** zero them before transferring the ORDER BY clause.
**
** Not doing this may cause an error if a subsequent call to this
** function attempts to flatten a compound sub-query into pParent.
** See ticket [d11a6e908f].
*/
pOrderBy1 = (*TSelect)(unsafe.Pointer(pSub)).FpOrderBy
i = 0
for {
if !(i < (*TExprList)(unsafe.Pointer(pOrderBy1)).FnExpr) {
break
}
*(*Tu16)(unsafe.Pointer(pOrderBy1 + 8 + uintptr(i)*32 + 24)) = uint16(0)
goto _11
_11:
;
i = i + 1
}
(*TSelect)(unsafe.Pointer(pParent)).FpOrderBy = pOrderBy1
(*TSelect)(unsafe.Pointer(pSub)).FpOrderBy = uintptr(0)
}
pWhere = (*TSelect)(unsafe.Pointer(pSub)).FpWhere
(*TSelect)(unsafe.Pointer(pSub)).FpWhere = uintptr(0)
if isOuterJoin > 0 {
_sqlite3SetJoinExpr(tls, pWhere, iNewParent, uint32(EP_OuterON))
}
if pWhere != 0 {
if (*TSelect)(unsafe.Pointer(pParent)).FpWhere != 0 {
(*TSelect)(unsafe.Pointer(pParent)).FpWhere = _sqlite3PExpr(tls, pParse, int32(TK_AND), pWhere, (*TSelect)(unsafe.Pointer(pParent)).FpWhere)
} else {
(*TSelect)(unsafe.Pointer(pParent)).FpWhere = pWhere
}
}
if libc.Int32FromUint8((*Tsqlite3)(unsafe.Pointer(db)).FmallocFailed) == 0 {
(**(**TSubstContext)(__ccgo_up(bp + 48))).FpParse = pParse
(**(**TSubstContext)(__ccgo_up(bp + 48))).FiTable = iParent
(**(**TSubstContext)(__ccgo_up(bp + 48))).FiNewTable = iNewParent
(**(**TSubstContext)(__ccgo_up(bp + 48))).FisOuterJoin = isOuterJoin
(**(**TSubstContext)(__ccgo_up(bp + 48))).FnSelDepth = 0
(**(**TSubstContext)(__ccgo_up(bp + 48))).FpEList = (*TSelect)(unsafe.Pointer(pSub)).FpEList
(**(**TSubstContext)(__ccgo_up(bp + 48))).FpCList = _findLeftmostExprlist(tls, pSub)
_substSelect(tls, bp+48, pParent, 0)
}
/* The flattened query is a compound if either the inner or the
** outer query is a compound. */
**(**Tu32)(__ccgo_up(pParent + 4)) |= (*TSelect)(unsafe.Pointer(pSub)).FselFlags & uint32(SF_Compound)
/* restriction (17b) */
/*
** SELECT ... FROM (SELECT ... LIMIT a OFFSET b) LIMIT x OFFSET y;
**
** One is tempted to try to add a and b to combine the limits. But this
** does not work if either limit is negative.
*/
if (*TSelect)(unsafe.Pointer(pSub)).FpLimit != 0 {
(*TSelect)(unsafe.Pointer(pParent)).FpLimit = (*TSelect)(unsafe.Pointer(pSub)).FpLimit
(*TSelect)(unsafe.Pointer(pSub)).FpLimit = uintptr(0)
}
/* Recompute the SrcItem.colUsed masks for the flattened
** tables. */
i = 0
for {
if !(i < nSubSrc) {
break
}
_recomputeColumnsUsed(tls, pParent, pSrc+8+uintptr(i+iFrom)*80)
goto _12
_12:
;
i = i + 1
}
goto _7
_7:
;
pParent = (*TSelect)(unsafe.Pointer(pParent)).FpPrior
pSub = (*TSelect)(unsafe.Pointer(pSub)).FpPrior
}
/* Finally, delete what is left of the subquery and return success.
*/
_sqlite3AggInfoPersistWalkerInit(tls, bp, pParse)
_sqlite3WalkSelect(tls, bp, pSub1)
_sqlite3SelectDelete(tls, db, pSub1)
return int32(1)
}
// C documentation
//
// /*
// ** This routine checks if there is a RESERVED lock held on the specified
// ** file by this or any other process. If such a lock is held, set *pResOut
// ** to a non-zero value otherwise *pResOut is set to zero. The return value
// ** is set to SQLITE_OK unless an I/O error occurs during lock checking.
// */
func _flockCheckReservedLock(tls *libc.TLS, id uintptr, pResOut uintptr) (r int32) {
_ = id
/* The flock VFS only ever takes exclusive locks (see function flockLock).
** Therefore, if this connection is holding any lock at all, no other
** connection may be holding a RESERVED lock. So set *pResOut to 0
** in this case.
**
** Or, this connection may be holding no lock. In that case, set *pResOut to
** 0 as well. The caller will then attempt to take an EXCLUSIVE lock on the
** db in order to roll the hot journal back. If there is another connection
** holding a lock, that attempt will fail and an SQLITE_BUSY returned to
** the user. With other VFS, we try to avoid this, in order to allow a reader
** to proceed while a writer is preparing its transaction. But that won't
** work with the flock VFS - as it always takes EXCLUSIVE locks - so it is
** not a problem in this case. */
**(**int32)(__ccgo_up(pResOut)) = 0
return SQLITE_OK
}
// C documentation
//
// /*
// ** Close a file.
// */
func _flockClose(tls *libc.TLS, id uintptr) (r int32) {
_flockUnlock(tls, id, NO_LOCK)
return _closeUnixFile(tls, id)
}
/******************* End of the flock lock implementation *********************
******************************************************************************/
/******************************************************************************
************************ Begin Named Semaphore Locking ************************
**
** Named semaphore locking is only supported on VxWorks.
**
** Semaphore locking is like dot-lock and flock in that it really only
** supports EXCLUSIVE locking. Only a single process can read or write
** the database file at a time. This reduces potential concurrency, but
** makes the lock implementation much easier.
*/
/*
** Named semaphore locking is only available on VxWorks.
**
*************** End of the named semaphore lock implementation ****************
******************************************************************************/
/******************************************************************************
*************************** Begin AFP Locking *********************************
**
** AFP is the Apple Filing Protocol. AFP is a network filesystem found
** on Apple Macintosh computers - both OS9 and OSX.
**
** Third-party implementations of AFP are available. But this code here
** only works on OSX.
*/
var _flockIoFinder = uintptr(0)
func _flockIoFinderImpl(tls *libc.TLS, z uintptr, p uintptr) (r uintptr) {
_ = z
_ = p
return uintptr(unsafe.Pointer(&_flockIoMethods))
}
var _flockIoMethods = Tsqlite3_io_methods{
FiVersion: int32(1),
}
// C documentation
//
// /*
// ** Lock the file with the lock specified by parameter eFileLock - one
// ** of the following:
// **
// ** (1) SHARED_LOCK
// ** (2) RESERVED_LOCK
// ** (3) PENDING_LOCK
// ** (4) EXCLUSIVE_LOCK
// **
// ** Sometimes when requesting one lock state, additional lock states
// ** are inserted in between. The locking might fail on one of the later
// ** transitions leaving the lock state different from what it started but
// ** still short of its goal. The following chart shows the allowed
// ** transitions and the inserted intermediate states:
// **
// ** UNLOCKED -> SHARED
// ** SHARED -> RESERVED
// ** SHARED -> (PENDING) -> EXCLUSIVE
// ** RESERVED -> (PENDING) -> EXCLUSIVE
// ** PENDING -> EXCLUSIVE
// **
// ** flock() only really support EXCLUSIVE locks. We track intermediate
// ** lock states in the sqlite3_file structure, but all locks SHARED or
// ** above are really EXCLUSIVE locks and exclude all other processes from
// ** access the file.
// **
// ** This routine will only increase a lock. Use the sqlite3OsUnlock()
// ** routine to lower a locking level.
// */
func _flockLock(tls *libc.TLS, id uintptr, eFileLock int32) (r int32) {
var pFile uintptr
var rc, tErrno int32
_, _, _ = pFile, rc, tErrno
rc = SQLITE_OK
pFile = id
/* if we already have a lock, it is exclusive.
** Just adjust level and punt on outta here. */
if libc.Int32FromUint8((*TunixFile)(unsafe.Pointer(pFile)).FeFileLock) > NO_LOCK {
(*TunixFile)(unsafe.Pointer(pFile)).FeFileLock = libc.Uint8FromInt32(eFileLock)
return SQLITE_OK
}
/* grab an exclusive lock */
if _robust_flock(tls, (*TunixFile)(unsafe.Pointer(pFile)).Fh, libc.Int32FromInt32(LOCK_EX)|libc.Int32FromInt32(LOCK_NB)) != 0 {
tErrno = **(**int32)(__ccgo_up(libc.X__error(tls)))
/* didn't get, must be busy */
rc = _sqliteErrorFromPosixError(tls, tErrno, libc.Int32FromInt32(SQLITE_IOERR)|libc.Int32FromInt32(15)< (*TBtShared)(unsafe.Pointer(pBt)).FnPage {
return _sqlite3CorruptError(tls, int32(80075))
}
if pMemPage != 0 {
**(**uintptr)(__ccgo_up(bp + 8)) = pMemPage
_sqlite3PagerRef(tls, (*TMemPage)(unsafe.Pointer(**(**uintptr)(__ccgo_up(bp + 8)))).FpDbPage)
} else {
**(**uintptr)(__ccgo_up(bp + 8)) = _btreePageLookup(tls, pBt, iPage)
}
/* Increment the free page count on pPage1 */
**(**int32)(__ccgo_up(bp + 16)) = _sqlite3PagerWrite(tls, (*TMemPage)(unsafe.Pointer(pPage1)).FpDbPage)
if **(**int32)(__ccgo_up(bp + 16)) != 0 {
goto freepage_out
}
nFree = _sqlite3Get4byte(tls, (*TMemPage)(unsafe.Pointer(pPage1)).FaData+36)
_sqlite3Put4byte(tls, (*TMemPage)(unsafe.Pointer(pPage1)).FaData+36, nFree+uint32(1))
if libc.Int32FromUint16((*TBtShared)(unsafe.Pointer(pBt)).FbtsFlags)&int32(BTS_SECURE_DELETE) != 0 {
/* If the secure_delete option is enabled, then
** always fully overwrite deleted information with zeros.
*/
if v2 = !(**(**uintptr)(__ccgo_up(bp + 8)) != 0); v2 {
v1 = _btreeGetPage(tls, pBt, iPage, bp+8, 0)
**(**int32)(__ccgo_up(bp + 16)) = v1
}
if v4 = v2 && v1 != 0; !v4 {
v3 = _sqlite3PagerWrite(tls, (*TMemPage)(unsafe.Pointer(**(**uintptr)(__ccgo_up(bp + 8)))).FpDbPage)
**(**int32)(__ccgo_up(bp + 16)) = v3
}
if v4 || v3 != 0 {
goto freepage_out
}
libc.X__builtin___memset_chk(tls, (*TMemPage)(unsafe.Pointer(**(**uintptr)(__ccgo_up(bp + 8)))).FaData, 0, uint64((*TBtShared)(unsafe.Pointer((*TMemPage)(unsafe.Pointer(**(**uintptr)(__ccgo_up(bp + 8)))).FpBt)).FpageSize), ^t__predefined_size_t(0))
}
/* If the database supports auto-vacuum, write an entry in the pointer-map
** to indicate that the page is free.
*/
if (*TBtShared)(unsafe.Pointer(pBt)).FautoVacuum != 0 {
_ptrmapPut(tls, pBt, iPage, uint8(PTRMAP_FREEPAGE), uint32(0), bp+16)
if **(**int32)(__ccgo_up(bp + 16)) != 0 {
goto freepage_out
}
}
/* Now manipulate the actual database free-list structure. There are two
** possibilities. If the free-list is currently empty, or if the first
** trunk page in the free-list is full, then this page will become a
** new free-list trunk page. Otherwise, it will become a leaf of the
** first trunk page in the current free-list. This block tests if it
** is possible to add the page as a new free-list leaf.
*/
if nFree != uint32(0) { /* Initial number of leaf cells on trunk page */
iTrunk = _sqlite3Get4byte(tls, (*TMemPage)(unsafe.Pointer(pPage1)).FaData+32)
if iTrunk > _btreePagecount(tls, pBt) {
**(**int32)(__ccgo_up(bp + 16)) = _sqlite3CorruptError(tls, int32(80122))
goto freepage_out
}
**(**int32)(__ccgo_up(bp + 16)) = _btreeGetPage(tls, pBt, iTrunk, bp, 0)
if **(**int32)(__ccgo_up(bp + 16)) != SQLITE_OK {
goto freepage_out
}
nLeaf = _sqlite3Get4byte(tls, (*TMemPage)(unsafe.Pointer(**(**uintptr)(__ccgo_up(bp)))).FaData+4)
if nLeaf > (*TBtShared)(unsafe.Pointer(pBt)).FusableSize/uint32(4)-uint32(2) {
**(**int32)(__ccgo_up(bp + 16)) = _sqlite3CorruptError(tls, int32(80133))
goto freepage_out
}
if nLeaf < (*TBtShared)(unsafe.Pointer(pBt)).FusableSize/uint32(4)-uint32(8) {
/* In this case there is room on the trunk page to insert the page
** being freed as a new leaf.
**
** Note that the trunk page is not really full until it contains
** usableSize/4 - 2 entries, not usableSize/4 - 8 entries as we have
** coded. But due to a coding error in versions of SQLite prior to
** 3.6.0, databases with freelist trunk pages holding more than
** usableSize/4 - 8 entries will be reported as corrupt. In order
** to maintain backwards compatibility with older versions of SQLite,
** we will continue to restrict the number of entries to usableSize/4 - 8
** for now. At some point in the future (once everyone has upgraded
** to 3.6.0 or later) we should consider fixing the conditional above
** to read "usableSize/4-2" instead of "usableSize/4-8".
**
** EVIDENCE-OF: R-19920-11576 However, newer versions of SQLite still
** avoid using the last six entries in the freelist trunk page array in
** order that database files created by newer versions of SQLite can be
** read by older versions of SQLite.
*/
**(**int32)(__ccgo_up(bp + 16)) = _sqlite3PagerWrite(tls, (*TMemPage)(unsafe.Pointer(**(**uintptr)(__ccgo_up(bp)))).FpDbPage)
if **(**int32)(__ccgo_up(bp + 16)) == SQLITE_OK {
_sqlite3Put4byte(tls, (*TMemPage)(unsafe.Pointer(**(**uintptr)(__ccgo_up(bp)))).FaData+4, nLeaf+uint32(1))
_sqlite3Put4byte(tls, (*TMemPage)(unsafe.Pointer(**(**uintptr)(__ccgo_up(bp)))).FaData+uintptr(uint32(8)+nLeaf*uint32(4)), iPage)
if **(**uintptr)(__ccgo_up(bp + 8)) != 0 && libc.Int32FromUint16((*TBtShared)(unsafe.Pointer(pBt)).FbtsFlags)&int32(BTS_SECURE_DELETE) == 0 {
_sqlite3PagerDontWrite(tls, (*TMemPage)(unsafe.Pointer(**(**uintptr)(__ccgo_up(bp + 8)))).FpDbPage)
}
**(**int32)(__ccgo_up(bp + 16)) = _btreeSetHasContent(tls, pBt, iPage)
}
goto freepage_out
}
}
/* If control flows to this point, then it was not possible to add the
** the page being freed as a leaf page of the first trunk in the free-list.
** Possibly because the free-list is empty, or possibly because the
** first trunk in the free-list is full. Either way, the page being freed
** will become the new first trunk page in the free-list.
*/
if v2 = **(**uintptr)(__ccgo_up(bp + 8)) == uintptr(0); v2 {
v1 = _btreeGetPage(tls, pBt, iPage, bp+8, 0)
**(**int32)(__ccgo_up(bp + 16)) = v1
}
if v2 && SQLITE_OK != v1 {
goto freepage_out
}
**(**int32)(__ccgo_up(bp + 16)) = _sqlite3PagerWrite(tls, (*TMemPage)(unsafe.Pointer(**(**uintptr)(__ccgo_up(bp + 8)))).FpDbPage)
if **(**int32)(__ccgo_up(bp + 16)) != SQLITE_OK {
goto freepage_out
}
_sqlite3Put4byte(tls, (*TMemPage)(unsafe.Pointer(**(**uintptr)(__ccgo_up(bp + 8)))).FaData, iTrunk)
_sqlite3Put4byte(tls, (*TMemPage)(unsafe.Pointer(**(**uintptr)(__ccgo_up(bp + 8)))).FaData+4, uint32(0))
_sqlite3Put4byte(tls, (*TMemPage)(unsafe.Pointer(pPage1)).FaData+32, iPage)
goto freepage_out
freepage_out:
;
if **(**uintptr)(__ccgo_up(bp + 8)) != 0 {
(*TMemPage)(unsafe.Pointer(**(**uintptr)(__ccgo_up(bp + 8)))).FisInit = uint8(0)
}
_releasePage(tls, **(**uintptr)(__ccgo_up(bp + 8)))
_releasePage(tls, **(**uintptr)(__ccgo_up(bp)))
return **(**int32)(__ccgo_up(bp + 16))
}
// C documentation
//
// /*
// ** Return a section of the pPage->aData to the freelist.
// ** The first byte of the new free block is pPage->aData[iStart]
// ** and the size of the block is iSize bytes.
// **
// ** Adjacent freeblocks are coalesced.
// **
// ** Even though the freeblock list was checked by btreeComputeFreeSpace(),
// ** that routine will not detect overlap between cells or freeblocks. Nor
// ** does it detect cells or freeblocks that encroach into the reserved bytes
// ** at the end of the page. So do additional corruption checks inside this
// ** routine and return SQLITE_CORRUPT if any problems are found.
// */
func _freeSpace(tls *libc.TLS, pPage uintptr, iStart int32, iSize int32) (r int32) {
var data, pTmp, v2 uintptr
var hdr Tu8
var iEnd, iFreeBlk, iOrigSize, iPtr, iPtrEnd, nFrag, x, v1 int32
_, _, _, _, _, _, _, _, _, _, _, _ = data, hdr, iEnd, iFreeBlk, iOrigSize, iPtr, iPtrEnd, nFrag, pTmp, x, v1, v2 /* Page header size. 0 or 100 */
nFrag = 0 /* Reduction in fragmentation */
iOrigSize = iSize /* Offset to cell content area */
iEnd = iStart + iSize /* First byte past the iStart buffer */
data = (*TMemPage)(unsafe.Pointer(pPage)).FaData /* Temporary ptr into data[] */
/* Minimum cell size is 4 */
/* The list of freeblocks must be in ascending order. Find the
** spot on the list where iStart should be inserted.
*/
hdr = (*TMemPage)(unsafe.Pointer(pPage)).FhdrOffset
iPtr = libc.Int32FromUint8(hdr) + int32(1)
if libc.Int32FromUint8(**(**uint8)(__ccgo_up(data + uintptr(iPtr+int32(1))))) == 0 && libc.Int32FromUint8(**(**uint8)(__ccgo_up(data + uintptr(iPtr)))) == 0 {
iFreeBlk = 0 /* Shortcut for the case when the freelist is empty */
} else {
for {
v1 = libc.Int32FromUint8(**(**uint8)(__ccgo_up(data + uintptr(iPtr))))< libc.Int32FromUint32((*TBtShared)(unsafe.Pointer((*TMemPage)(unsafe.Pointer(pPage)).FpBt)).FusableSize)-int32(4) { /* TH3: corrupt081.100 */
return _sqlite3CorruptError(tls, int32(75179))
}
/* At this point:
** iFreeBlk: First freeblock after iStart, or zero if none
** iPtr: The address of a pointer to iFreeBlk
**
** Check to see if iFreeBlk should be coalesced onto the end of iStart.
*/
if iFreeBlk != 0 && iEnd+int32(3) >= iFreeBlk {
nFrag = iFreeBlk - iEnd
if iEnd > iFreeBlk {
return _sqlite3CorruptError(tls, int32(75191))
}
iEnd = iFreeBlk + (libc.Int32FromUint8(**(**uint8)(__ccgo_up(data + uintptr(iFreeBlk+int32(2)))))< libc.Int32FromUint32((*TBtShared)(unsafe.Pointer((*TMemPage)(unsafe.Pointer(pPage)).FpBt)).FusableSize) {
return _sqlite3CorruptError(tls, int32(75194))
}
iSize = iEnd - iStart
iFreeBlk = libc.Int32FromUint8(**(**uint8)(__ccgo_up(data + uintptr(iFreeBlk))))< libc.Int32FromUint8(hdr)+int32(1) {
iPtrEnd = iPtr + (libc.Int32FromUint8(**(**uint8)(__ccgo_up(data + uintptr(iPtr+int32(2)))))<= iStart {
if iPtrEnd > iStart {
return _sqlite3CorruptError(tls, int32(75207))
}
nFrag = nFrag + (iStart - iPtrEnd)
iSize = iEnd - iPtr
iStart = iPtr
}
}
if nFrag > libc.Int32FromUint8(**(**uint8)(__ccgo_up(data + uintptr(libc.Int32FromUint8(hdr)+int32(7))))) {
return _sqlite3CorruptError(tls, int32(75213))
}
v2 = data + uintptr(libc.Int32FromUint8(hdr)+int32(7))
*(*uint8)(unsafe.Pointer(v2)) = uint8(int32(*(*uint8)(unsafe.Pointer(v2))) - libc.Int32FromUint8(libc.Uint8FromInt32(nFrag)))
}
pTmp = data + uintptr(libc.Int32FromUint8(hdr)+int32(5))
x = libc.Int32FromUint8(**(**Tu8)(__ccgo_up(pTmp)))<> libc.Int32FromInt32(8))
**(**uint8)(__ccgo_up(data + uintptr(libc.Int32FromUint8(hdr)+int32(1)) + 1)) = libc.Uint8FromInt32(iFreeBlk)
**(**uint8)(__ccgo_up(data + uintptr(libc.Int32FromUint8(hdr)+int32(5)))) = libc.Uint8FromInt32(iEnd >> libc.Int32FromInt32(8))
**(**uint8)(__ccgo_up(data + uintptr(libc.Int32FromUint8(hdr)+int32(5)) + 1)) = libc.Uint8FromInt32(iEnd)
} else {
/* Insert the new freeblock into the freelist */
**(**uint8)(__ccgo_up(data + uintptr(iPtr))) = libc.Uint8FromInt32(iStart >> libc.Int32FromInt32(8))
**(**uint8)(__ccgo_up(data + uintptr(iPtr) + 1)) = libc.Uint8FromInt32(iStart)
**(**uint8)(__ccgo_up(data + uintptr(iStart))) = libc.Uint8FromInt32(iFreeBlk >> libc.Int32FromInt32(8))
**(**uint8)(__ccgo_up(data + uintptr(iStart) + 1)) = libc.Uint8FromInt32(iFreeBlk)
**(**uint8)(__ccgo_up(data + uintptr(iStart+int32(2)))) = libc.Uint8FromInt32(libc.Int32FromUint16(libc.Uint16FromInt32(iSize)) >> libc.Int32FromInt32(8))
**(**uint8)(__ccgo_up(data + uintptr(iStart+int32(2)) + 1)) = uint8(libc.Uint16FromInt32(iSize))
}
**(**int32)(__ccgo_up(pPage + 20)) += iOrigSize
return SQLITE_OK
}
// C documentation
//
// /*
// ** Allocate a new segment-id for the structure pStruct. The new segment
// ** id must be between 1 and 65335 inclusive, and must not be used by
// ** any currently existing segment. If a free segment id cannot be found,
// ** SQLITE_FULL is returned.
// **
// ** If an error has already occurred, this function is a no-op. 0 is
// ** returned in this case.
// */
func _fts5AllocateSegid(tls *libc.TLS, p uintptr, pStruct uintptr) (r int32) {
bp := tls.Alloc(256)
defer tls.Free(256)
var i, iId, iLvl, iSeg, iSegid int32
var mask Tu32
var _ /* aUsed at bp+0 */ [63]Tu32
_, _, _, _, _, _ = i, iId, iLvl, iSeg, iSegid, mask
iSegid = 0
if (*TFts5Index)(unsafe.Pointer(p)).Frc == SQLITE_OK {
if (*TFts5Structure)(unsafe.Pointer(pStruct)).FnSegment >= int32(FTS5_MAX_SEGMENT) {
(*TFts5Index)(unsafe.Pointer(p)).Frc = int32(SQLITE_FULL)
} else {
libc.X__builtin___memset_chk(tls, bp, 0, uint64(252), ^t__predefined_size_t(0))
iLvl = 0
for {
if !(iLvl < (*TFts5Structure)(unsafe.Pointer(pStruct)).FnLevel) {
break
}
iSeg = 0
for {
if !(iSeg < (*(*TFts5StructureLevel)(unsafe.Pointer(pStruct + 32 + uintptr(iLvl)*16))).FnSeg) {
break
}
iId = (**(**TFts5StructureSegment)(__ccgo_up((*(*TFts5StructureLevel)(unsafe.Pointer(pStruct + 32 + uintptr(iLvl)*16))).FaSeg + uintptr(iSeg)*56))).FiSegid
if iId <= int32(FTS5_MAX_SEGMENT) && iId > 0 {
**(**Tu32)(__ccgo_up(bp + uintptr((iId-int32(1))/int32(32))*4)) |= libc.Uint32FromInt32(1) << ((iId - int32(1)) % int32(32))
}
goto _2
_2:
;
iSeg = iSeg + 1
}
goto _1
_1:
;
iLvl = iLvl + 1
}
i = 0
for {
if !((**(**[63]Tu32)(__ccgo_up(bp)))[i] == uint32(0xFFFFFFFF)) {
break
}
goto _3
_3:
;
i = i + 1
}
mask = (**(**[63]Tu32)(__ccgo_up(bp)))[i]
iSegid = 0
for {
if !(mask&(libc.Uint32FromInt32(1)< 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"
// ** LIKE against other column: "L"
// ** GLOB against other column: "G"
// ** 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+40105, 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+5637, libc.VaList(bp+8, iCol))
iIdxStr = iIdxStr + libc.Int32FromUint64(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+5637, 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 + 64)) *= 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
//
// /*
// ** Implementation of bm25() function.
// */
func _fts5Bm25Function(tls *libc.TLS, pApi uintptr, pFts uintptr, pCtx uintptr, nVal int32, apVal uintptr) {
bp := tls.Alloc(32)
defer tls.Free(32)
var D, b, k1, score, w, v2 float64
var aFreq uintptr
var i, rc int32
var _ /* ic at bp+16 */ int32
var _ /* io at bp+20 */ int32
var _ /* ip at bp+12 */ int32
var _ /* nInst at bp+8 */ int32
var _ /* nTok at bp+24 */ int32
var _ /* pData at bp+0 */ uintptr
_, _, _, _, _, _, _, _, _ = D, aFreq, b, i, k1, rc, score, w, v2
k1 = float64(1.2) /* Constant "k1" from BM25 formula */
b = float64(0.75) /* Error code */
score = float64(0) /* Iterator variable */
**(**int32)(__ccgo_up(bp + 8)) = 0 /* Value returned by xInstCount() */
D = float64(0) /* Total number of tokens in row */
aFreq = uintptr(0) /* Array of phrase freq. for current row */
/* Calculate the phrase frequency (symbol "f(qi,D)" in the documentation)
** for each phrase in the query for the current row. */
rc = _fts5Bm25GetData(tls, pApi, pFts, bp)
if rc == SQLITE_OK {
aFreq = (*TFts5Bm25Data)(unsafe.Pointer(**(**uintptr)(__ccgo_up(bp)))).FaFreq
libc.X__builtin___memset_chk(tls, aFreq, 0, uint64(8)*libc.Uint64FromInt32((*TFts5Bm25Data)(unsafe.Pointer(**(**uintptr)(__ccgo_up(bp)))).FnPhrase), ^t__predefined_size_t(0))
rc = (*(*func(*libc.TLS, uintptr, uintptr) int32)(unsafe.Pointer(&struct{ uintptr }{(*TFts5ExtensionApi)(unsafe.Pointer(pApi)).FxInstCount})))(tls, pFts, bp+8)
}
i = 0
for {
if !(rc == SQLITE_OK && i < **(**int32)(__ccgo_up(bp + 8))) {
break
}
rc = (*(*func(*libc.TLS, uintptr, int32, uintptr, uintptr, uintptr) int32)(unsafe.Pointer(&struct{ uintptr }{(*TFts5ExtensionApi)(unsafe.Pointer(pApi)).FxInst})))(tls, pFts, i, bp+12, bp+16, bp+20)
if rc == SQLITE_OK {
if nVal > **(**int32)(__ccgo_up(bp + 16)) {
v2 = Xsqlite3_value_double(tls, **(**uintptr)(__ccgo_up(apVal + uintptr(**(**int32)(__ccgo_up(bp + 16)))*8)))
} else {
v2 = float64(1)
}
w = v2
**(**float64)(__ccgo_up(aFreq + uintptr(**(**int32)(__ccgo_up(bp + 12)))*8)) += w
}
goto _1
_1:
;
i = i + 1
}
/* Figure out the total size of the current row in tokens. */
if rc == SQLITE_OK {
rc = (*(*func(*libc.TLS, uintptr, int32, uintptr) int32)(unsafe.Pointer(&struct{ uintptr }{(*TFts5ExtensionApi)(unsafe.Pointer(pApi)).FxColumnSize})))(tls, pFts, -int32(1), bp+24)
D = float64(**(**int32)(__ccgo_up(bp + 24)))
}
/* Determine and return the BM25 score for the current row. Or, if an
** error has occurred, throw an exception. */
if rc == SQLITE_OK {
i = 0
for {
if !(i < (*TFts5Bm25Data)(unsafe.Pointer(**(**uintptr)(__ccgo_up(bp)))).FnPhrase) {
break
}
score = score + float64(**(**float64)(__ccgo_up((*TFts5Bm25Data)(unsafe.Pointer(**(**uintptr)(__ccgo_up(bp)))).FaIDF + uintptr(i)*8))*(float64(**(**float64)(__ccgo_up(aFreq + uintptr(i)*8))*(k1+libc.Float64FromFloat64(1)))/(**(**float64)(__ccgo_up(aFreq + uintptr(i)*8))+float64(k1*(libc.Float64FromInt32(1)-b+float64(b*D)/(*TFts5Bm25Data)(unsafe.Pointer(**(**uintptr)(__ccgo_up(bp)))).Favgdl)))))
goto _3
_3:
;
i = i + 1
}
Xsqlite3_result_double(tls, pCtx, float64(-libc.Float64FromFloat64(1)*score))
} else {
Xsqlite3_result_error_code(tls, pCtx, rc)
}
}
// C documentation
//
// /*
// ** Set *ppData to point to the Fts5Bm25Data object for the current query.
// ** If the object has not already been allocated, allocate and populate it
// ** now.
// */
func _fts5Bm25GetData(tls *libc.TLS, pApi uintptr, pFts uintptr, ppData uintptr) (r int32) {
bp := tls.Alloc(32)
defer tls.Free(32)
var i, nPhrase, rc int32
var idf float64
var nByte Tsqlite3_int64
var p uintptr
var _ /* nHit at bp+16 */ Tsqlite3_int64
var _ /* nRow at bp+0 */ Tsqlite3_int64
var _ /* nToken at bp+8 */ Tsqlite3_int64
_, _, _, _, _, _ = i, idf, nByte, nPhrase, p, rc
rc = SQLITE_OK /* Object to return */
p = (*(*func(*libc.TLS, uintptr, int32) uintptr)(unsafe.Pointer(&struct{ uintptr }{(*TFts5ExtensionApi)(unsafe.Pointer(pApi)).FxGetAuxdata})))(tls, pFts, 0)
if p == uintptr(0) { /* Number of phrases in query */
**(**Tsqlite3_int64)(__ccgo_up(bp)) = 0 /* Number of rows in table */
**(**Tsqlite3_int64)(__ccgo_up(bp + 8)) = 0
/* Allocate the Fts5Bm25Data object */
nPhrase = (*(*func(*libc.TLS, uintptr) int32)(unsafe.Pointer(&struct{ uintptr }{(*TFts5ExtensionApi)(unsafe.Pointer(pApi)).FxPhraseCount})))(tls, pFts)
nByte = libc.Int64FromUint64(uint64(32) + libc.Uint64FromInt32(nPhrase*int32(2))*uint64(8))
p = Xsqlite3_malloc64(tls, libc.Uint64FromInt64(nByte))
if p == uintptr(0) {
rc = int32(SQLITE_NOMEM)
} else {
libc.X__builtin___memset_chk(tls, p, 0, libc.Uint64FromInt64(nByte), ^t__predefined_size_t(0))
(*TFts5Bm25Data)(unsafe.Pointer(p)).FnPhrase = nPhrase
(*TFts5Bm25Data)(unsafe.Pointer(p)).FaIDF = p + 1*32
(*TFts5Bm25Data)(unsafe.Pointer(p)).FaFreq = (*TFts5Bm25Data)(unsafe.Pointer(p)).FaIDF + uintptr(nPhrase)*8
}
/* Calculate the average document length for this FTS5 table */
if rc == SQLITE_OK {
rc = (*(*func(*libc.TLS, uintptr, uintptr) int32)(unsafe.Pointer(&struct{ uintptr }{(*TFts5ExtensionApi)(unsafe.Pointer(pApi)).FxRowCount})))(tls, pFts, bp)
}
if rc == SQLITE_OK {
rc = (*(*func(*libc.TLS, uintptr, int32, uintptr) int32)(unsafe.Pointer(&struct{ uintptr }{(*TFts5ExtensionApi)(unsafe.Pointer(pApi)).FxColumnTotalSize})))(tls, pFts, -int32(1), bp+8)
}
if rc == SQLITE_OK {
(*TFts5Bm25Data)(unsafe.Pointer(p)).Favgdl = float64(**(**Tsqlite3_int64)(__ccgo_up(bp + 8))) / float64(**(**Tsqlite3_int64)(__ccgo_up(bp)))
}
/* Calculate an IDF for each phrase in the query */
i = 0
for {
if !(rc == SQLITE_OK && i < nPhrase) {
break
}
**(**Tsqlite3_int64)(__ccgo_up(bp + 16)) = 0
rc = (*(*func(*libc.TLS, uintptr, int32, uintptr, uintptr) int32)(unsafe.Pointer(&struct{ uintptr }{(*TFts5ExtensionApi)(unsafe.Pointer(pApi)).FxQueryPhrase})))(tls, pFts, i, bp+16, __ccgo_fp(_fts5CountCb))
if rc == SQLITE_OK {
/* Calculate the IDF (Inverse Document Frequency) for phrase i.
** This is done using the standard BM25 formula as found on wikipedia:
**
** IDF = log( (N - nHit + 0.5) / (nHit + 0.5) )
**
** where "N" is the total number of documents in the set and nHit
** is the number that contain at least one instance of the phrase
** under consideration.
**
** The problem with this is that if (N < 2*nHit), the IDF is
** negative. Which is undesirable. So the minimum allowable IDF is
** (1e-6) - roughly the same as a term that appears in just over
** half of set of 5,000,000 documents. */
idf = libc.Xlog(tls, (float64(**(**Tsqlite3_int64)(__ccgo_up(bp))-**(**Tsqlite3_int64)(__ccgo_up(bp + 16)))+float64(0.5))/(float64(**(**Tsqlite3_int64)(__ccgo_up(bp + 16)))+float64(0.5)))
if idf <= float64(0) {
idf = float64(1e-06)
}
**(**float64)(__ccgo_up((*TFts5Bm25Data)(unsafe.Pointer(p)).FaIDF + uintptr(i)*8)) = idf
}
goto _1
_1:
;
i = i + 1
}
if rc != SQLITE_OK {
Xsqlite3_free(tls, p)
} else {
rc = (*(*func(*libc.TLS, uintptr, uintptr, uintptr) int32)(unsafe.Pointer(&struct{ uintptr }{(*TFts5ExtensionApi)(unsafe.Pointer(pApi)).FxSetAuxdata})))(tls, pFts, p, __ccgo_fp(Xsqlite3_free))
}
if rc != SQLITE_OK {
p = uintptr(0)
}
}
**(**uintptr)(__ccgo_up(ppData)) = p
return rc
}
// C documentation
//
// /*
// ** Initialize the iterator object indicated by the final parameter to
// ** iterate through coalesced phrase instances in column iCol.
// */
func _fts5CInstIterInit(tls *libc.TLS, pApi uintptr, pFts uintptr, iCol int32, pIter uintptr) (r int32) {
var rc int32
_ = rc
libc.X__builtin___memset_chk(tls, pIter, 0, uint64(40), ^t__predefined_size_t(0))
(*TCInstIter)(unsafe.Pointer(pIter)).FpApi = pApi
(*TCInstIter)(unsafe.Pointer(pIter)).FpFts = pFts
(*TCInstIter)(unsafe.Pointer(pIter)).FiCol = iCol
rc = (*(*func(*libc.TLS, uintptr, uintptr) int32)(unsafe.Pointer(&struct{ uintptr }{(*TFts5ExtensionApi)(unsafe.Pointer(pApi)).FxInstCount})))(tls, pFts, pIter+24)
if rc == SQLITE_OK {
rc = _fts5CInstIterNext(tls, pIter)
}
return rc
}
// C documentation
//
// /*
// ** If argument pOrig is NULL, or if (*pRc) is set to anything other than
// ** SQLITE_OK when this function is called, NULL is returned.
// **
// ** Otherwise, a copy of (*pOrig) is made into memory obtained from
// ** sqlite3Fts5MallocZero() and a pointer to it returned. If the allocation
// ** fails, (*pRc) is set to SQLITE_NOMEM and NULL is returned.
// */
func _fts5CloneColset(tls *libc.TLS, pRc uintptr, pOrig uintptr) (r uintptr) {
var nByte Tsqlite3_int64
var pRet uintptr
_, _ = nByte, pRet
if pOrig != 0 {
nByte = libc.Int64FromUint64(libc.Uint64FromInt64(8) * libc.Uint64FromInt32(((*TFts5Colset)(unsafe.Pointer(pOrig)).FnCol+libc.Int32FromInt32(2))/libc.Int32FromInt32(2)))
pRet = _sqlite3Fts5MallocZero(tls, pRc, nByte)
if pRet != 0 {
libc.X__builtin___memcpy_chk(tls, pRet, pOrig, libc.Uint64FromInt64(nByte), ^t__predefined_size_t(0))
}
} else {
pRet = uintptr(0)
}
return pRet
}
// C documentation
//
// /*
// ** Gobble up the first bareword or quoted word from the input buffer zIn.
// ** Return a pointer to the character immediately following the last in
// ** the gobbled word if successful, or a NULL pointer otherwise (failed
// ** to find close-quote character).
// **
// ** Before returning, set pzOut to point to a new buffer containing a
// ** nul-terminated, dequoted copy of the gobbled word. If the word was
// ** quoted, *pbQuoted is also set to 1 before returning.
// **
// ** If *pRc is other than SQLITE_OK when this function is called, it is
// ** a no-op (NULL is returned). Otherwise, if an OOM occurs within this
// ** function, *pRc is set to SQLITE_NOMEM before returning. *pRc is *not*
// ** set if a parse error (failed to find close quote) occurs.
// */
func _fts5ConfigGobbleWord(tls *libc.TLS, pRc uintptr, zIn uintptr, pzOut uintptr, pbQuoted uintptr) (r uintptr) {
var ii int32
var nIn Tsqlite3_int64
var zOut, zRet uintptr
_, _, _, _ = ii, nIn, zOut, zRet
zRet = uintptr(0)
nIn = libc.Int64FromUint64(libc.Xstrlen(tls, zIn))
zOut = Xsqlite3_malloc64(tls, libc.Uint64FromInt64(nIn+int64(1)))
**(**int32)(__ccgo_up(pbQuoted)) = 0
**(**uintptr)(__ccgo_up(pzOut)) = uintptr(0)
if zOut == uintptr(0) {
**(**int32)(__ccgo_up(pRc)) = int32(SQLITE_NOMEM)
} else {
libc.X__builtin___memcpy_chk(tls, zOut, zIn, libc.Uint64FromInt64(nIn+libc.Int64FromInt32(1)), ^t__predefined_size_t(0))
if _fts5_isopenquote(tls, **(**int8)(__ccgo_up(zOut))) != 0 {
ii = _fts5Dequote(tls, zOut)
zRet = zIn + uintptr(ii)
**(**int32)(__ccgo_up(pbQuoted)) = int32(1)
} else {
zRet = _fts5ConfigSkipBareword(tls, zIn)
if zRet != 0 {
**(**int8)(__ccgo_up(zOut + uintptr(int64(zRet)-int64(zIn)))) = int8('\000')
}
}
}
if zRet == uintptr(0) {
Xsqlite3_free(tls, zOut)
} else {
**(**uintptr)(__ccgo_up(pzOut)) = zOut
}
return zRet
}
// C documentation
//
// /*
// ** Populate the Fts5Config.zContentExprlist string.
// */
func _fts5ConfigMakeExprlist(tls *libc.TLS, p uintptr) (r int32) {
bp := tls.Alloc(48)
defer tls.Free(48)
var i int32
var _ /* buf at bp+8 */ TFts5Buffer
var _ /* rc at bp+0 */ int32
_ = i
**(**int32)(__ccgo_up(bp)) = SQLITE_OK
**(**TFts5Buffer)(__ccgo_up(bp + 8)) = TFts5Buffer{}
_sqlite3Fts5BufferAppendPrintf(tls, bp, bp+8, __ccgo_ts+38433, libc.VaList(bp+32, (*TFts5Config)(unsafe.Pointer(p)).FzContentRowid))
if (*TFts5Config)(unsafe.Pointer(p)).FeContent != int32(FTS5_CONTENT_NONE) {
i = 0
for {
if !(i < (*TFts5Config)(unsafe.Pointer(p)).FnCol) {
break
}
if (*TFts5Config)(unsafe.Pointer(p)).FeContent == int32(FTS5_CONTENT_EXTERNAL) {
_sqlite3Fts5BufferAppendPrintf(tls, bp, bp+8, __ccgo_ts+38438, libc.VaList(bp+32, **(**uintptr)(__ccgo_up((*TFts5Config)(unsafe.Pointer(p)).FazCol + uintptr(i)*8))))
} else {
if (*TFts5Config)(unsafe.Pointer(p)).FeContent == FTS5_CONTENT_NORMAL || **(**Tu8)(__ccgo_up((*TFts5Config)(unsafe.Pointer(p)).FabUnindexed + uintptr(i))) != 0 {
_sqlite3Fts5BufferAppendPrintf(tls, bp, bp+8, __ccgo_ts+38445, libc.VaList(bp+32, i))
} else {
_sqlite3Fts5BufferAppendPrintf(tls, bp, bp+8, __ccgo_ts+38453, 0)
}
}
goto _1
_1:
;
i = i + 1
}
}
if (*TFts5Config)(unsafe.Pointer(p)).FeContent == FTS5_CONTENT_NORMAL && (*TFts5Config)(unsafe.Pointer(p)).FbLocale != 0 {
i = 0
for {
if !(i < (*TFts5Config)(unsafe.Pointer(p)).FnCol) {
break
}
if libc.Int32FromUint8(**(**Tu8)(__ccgo_up((*TFts5Config)(unsafe.Pointer(p)).FabUnindexed + uintptr(i)))) == 0 {
_sqlite3Fts5BufferAppendPrintf(tls, bp, bp+8, __ccgo_ts+38460, libc.VaList(bp+32, i))
} else {
_sqlite3Fts5BufferAppendPrintf(tls, bp, bp+8, __ccgo_ts+38453, 0)
}
goto _2
_2:
;
i = i + 1
}
}
(*TFts5Config)(unsafe.Pointer(p)).FzContentExprlist = (**(**TFts5Buffer)(__ccgo_up(bp + 8))).Fp
return **(**int32)(__ccgo_up(bp))
}
func _fts5ConfigParseColumn(tls *libc.TLS, p uintptr, zCol uintptr, zArg uintptr, pzErr uintptr, pbUnindexed uintptr) (r int32) {
bp := tls.Alloc(16)
defer tls.Free(16)
var rc, v1 int32
var v2 uintptr
_, _, _ = rc, v1, v2
rc = SQLITE_OK
if 0 == Xsqlite3_stricmp(tls, zCol, __ccgo_ts+38357) || 0 == Xsqlite3_stricmp(tls, zCol, __ccgo_ts+18314) {
**(**uintptr)(__ccgo_up(pzErr)) = Xsqlite3_mprintf(tls, __ccgo_ts+38362, libc.VaList(bp+8, zCol))
rc = int32(SQLITE_ERROR)
} else {
if zArg != 0 {
if 0 == Xsqlite3_stricmp(tls, zArg, __ccgo_ts+38392) {
**(**Tu8)(__ccgo_up((*TFts5Config)(unsafe.Pointer(p)).FabUnindexed + uintptr((*TFts5Config)(unsafe.Pointer(p)).FnCol))) = uint8(1)
**(**int32)(__ccgo_up(pbUnindexed)) = int32(1)
} else {
**(**uintptr)(__ccgo_up(pzErr)) = Xsqlite3_mprintf(tls, __ccgo_ts+38402, libc.VaList(bp+8, zArg))
rc = int32(SQLITE_ERROR)
}
}
}
v2 = p + 32
v1 = *(*int32)(unsafe.Pointer(v2))
*(*int32)(unsafe.Pointer(v2)) = *(*int32)(unsafe.Pointer(v2)) + 1
**(**uintptr)(__ccgo_up((*TFts5Config)(unsafe.Pointer(p)).FazCol + uintptr(v1)*8)) = zCol
return rc
}
// C documentation
//
// /*
// ** 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(96)
defer tls.Free(96)
var azArg, p, p1, p2, pSpace uintptr
var bFirst, nByte, nCmd, nPre, v2 int32
var nArg Tsqlite3_int64
var _ /* aDetail at bp+8 */ [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.Int32FromUint64(libc.Xstrlen(tls, zCmd))
if Xsqlite3_strnicmp(tls, __ccgo_ts+37796, zCmd, nCmd) == 0 {
nByte = libc.Int32FromUint64(libc.Uint64FromInt64(4) * libc.Uint64FromInt32(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+37803, 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+37834, libc.VaList(bp+80, 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+37867, 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+37904, zCmd, nCmd) == 0 {
p1 = zArg
nArg = libc.Int64FromUint64(libc.Xstrlen(tls, zArg) + uint64(1))
azArg = _sqlite3Fts5MallocZero(tls, bp, libc.Int64FromUint64(uint64(libc.Uint64FromInt64(8)+libc.Uint64FromInt32(2))*libc.Uint64FromInt64(nArg)))
if azArg != 0 {
pSpace = azArg + uintptr(nArg)*8
if (*TFts5Config)(unsafe.Pointer(pConfig)).Ft.FazArg != 0 {
**(**uintptr)(__ccgo_up(pzErr)) = Xsqlite3_mprintf(tls, __ccgo_ts+37913, 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.X__builtin___memcpy_chk(tls, pSpace, p2, libc.Uint64FromInt64(int64(p1)-int64(p2)), ^t__predefined_size_t(0))
**(**uintptr)(__ccgo_up(azArg + uintptr(nArg)*8)) = pSpace
_sqlite3Fts5Dequote(tls, pSpace)
pSpace = pSpace + uintptr(int64(p1)-int64(p2)+int64(1))
p1 = _fts5ConfigSkipWhitespace(tls, p1)
}
goto _1
_1:
;
nArg = nArg + 1
}
if p1 == uintptr(0) {
**(**uintptr)(__ccgo_up(pzErr)) = Xsqlite3_mprintf(tls, __ccgo_ts+37946, 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+37980, zCmd, nCmd) == 0 {
if (*TFts5Config)(unsafe.Pointer(pConfig)).FeContent != FTS5_CONTENT_NORMAL {
**(**uintptr)(__ccgo_up(pzErr)) = Xsqlite3_mprintf(tls, __ccgo_ts+37988, 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+38020, libc.VaList(bp+80, (*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+38026, 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+38045, 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+38088, 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+38045, 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+38110, zCmd, nCmd) == 0 {
if (*TFts5Config)(unsafe.Pointer(pConfig)).FzContentRowid != 0 {
**(**uintptr)(__ccgo_up(pzErr)) = Xsqlite3_mprintf(tls, __ccgo_ts+38124, 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+38162, 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+38173, 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+38208, 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+38215, 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+6014, zCmd, nCmd) == 0 {
**(**[4]TFts5Enum)(__ccgo_up(bp + 8)) = [4]TFts5Enum{
0: {
FzName: __ccgo_ts + 8856,
FeVal: int32(FTS5_DETAIL_NONE),
},
1: {
FzName: __ccgo_ts + 19383,
},
2: {
FzName: __ccgo_ts + 38246,
FeVal: int32(FTS5_DETAIL_COLUMNS),
},
3: {},
}
v2 = _fts5ConfigSetEnum(tls, bp+8, zArg, pConfig+116)
**(**int32)(__ccgo_up(bp)) = v2
if v2 != 0 {
**(**uintptr)(__ccgo_up(pzErr)) = Xsqlite3_mprintf(tls, __ccgo_ts+38254, 0)
}
return **(**int32)(__ccgo_up(bp))
}
if Xsqlite3_strnicmp(tls, __ccgo_ts+38285, 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+38295, 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+38329, libc.VaList(bp+80, nCmd, zCmd))
return int32(SQLITE_ERROR)
}
// C documentation
//
// /*
// **
// ** This function is called when the user attempts an UPDATE on a contentless
// ** table. Parameter bRowidModified is true if the UPDATE statement modifies
// ** the rowid value. Parameter apVal[] contains the new values for each user
// ** defined column of the fts5 table. pConfig is the configuration object of the
// ** table being updated (guaranteed to be contentless). The contentless_delete=1
// ** and contentless_unindexed=1 options may or may not be set.
// **
// ** This function returns SQLITE_OK if the UPDATE can go ahead, or an SQLite
// ** error code if it cannot. In this case an error message is also loaded into
// ** pConfig. Output parameter (*pbContent) is set to true if the caller should
// ** update the %_content table only - not the FTS index or any other shadow
// ** table. This occurs when an UPDATE modifies only UNINDEXED columns of the
// ** table.
// **
// ** An UPDATE may proceed if:
// **
// ** * The only columns modified are UNINDEXED columns, or
// **
// ** * The contentless_delete=1 option was specified and all of the indexed
// ** columns (not a subset) have been modified.
// */
func _fts5ContentlessUpdate(tls *libc.TLS, pConfig uintptr, apVal uintptr, bRowidModified int32, pbContent uintptr) (r int32) {
bp := tls.Alloc(32)
defer tls.Free(32)
var bSeenIndex, bSeenIndexNC, ii, rc int32
var v2 uintptr
_, _, _, _, _ = bSeenIndex, bSeenIndexNC, ii, rc, v2
bSeenIndex = 0 /* Have seen modified indexed column */
bSeenIndexNC = 0 /* Have seen unmodified indexed column */
rc = SQLITE_OK
ii = 0
for {
if !(ii < (*TFts5Config)(unsafe.Pointer(pConfig)).FnCol) {
break
}
if libc.Int32FromUint8(**(**Tu8)(__ccgo_up((*TFts5Config)(unsafe.Pointer(pConfig)).FabUnindexed + uintptr(ii)))) == 0 {
if Xsqlite3_value_nochange(tls, **(**uintptr)(__ccgo_up(apVal + uintptr(ii)*8))) != 0 {
bSeenIndexNC = bSeenIndexNC + 1
} else {
bSeenIndex = bSeenIndex + 1
}
}
goto _1
_1:
;
ii = ii + 1
}
if bSeenIndex == 0 && bRowidModified == 0 {
**(**int32)(__ccgo_up(pbContent)) = int32(1)
} else {
if bSeenIndexNC != 0 || (*TFts5Config)(unsafe.Pointer(pConfig)).FbContentlessDelete == 0 {
rc = int32(SQLITE_ERROR)
if (*TFts5Config)(unsafe.Pointer(pConfig)).FbContentlessDelete != 0 {
v2 = __ccgo_ts + 40570
} else {
v2 = __ccgo_ts + 40630
}
_sqlite3Fts5ConfigErrmsg(tls, pConfig, v2, libc.VaList(bp+8, __ccgo_ts+40660, (*TFts5Config)(unsafe.Pointer(pConfig)).FzName))
}
}
return rc
}
// C documentation
//
// /*
// ** Register a new auxiliary function with global context pGlobal.
// */
func _fts5CreateAux(tls *libc.TLS, pApi uintptr, zName uintptr, pUserData uintptr, __ccgo_fp_xFunc Tfts5_extension_function, __ccgo_fp_xDestroy uintptr) (r int32) {
var nByte, nName Tsqlite3_int64
var pAux, pGlobal uintptr
var rc int32
_, _, _, _, _ = nByte, nName, pAux, pGlobal, rc
pGlobal = pApi
rc = Xsqlite3_overload_function(tls, (*TFts5Global)(unsafe.Pointer(pGlobal)).Fdb, zName, -int32(1))
if rc == SQLITE_OK { /* Bytes of space to allocate */
nName = libc.Int64FromUint64(libc.Xstrlen(tls, zName) + uint64(1))
nByte = libc.Int64FromUint64(uint64(48) + libc.Uint64FromInt64(nName))
pAux = Xsqlite3_malloc64(tls, libc.Uint64FromInt64(nByte))
if pAux != 0 {
libc.X__builtin___memset_chk(tls, pAux, 0, libc.Uint64FromInt64(nByte), ^t__predefined_size_t(0))
(*TFts5Auxiliary)(unsafe.Pointer(pAux)).FzFunc = pAux + 1*48
libc.X__builtin___memcpy_chk(tls, (*TFts5Auxiliary)(unsafe.Pointer(pAux)).FzFunc, zName, libc.Uint64FromInt64(nName), ^t__predefined_size_t(0))
(*TFts5Auxiliary)(unsafe.Pointer(pAux)).FpGlobal = pGlobal
(*TFts5Auxiliary)(unsafe.Pointer(pAux)).FpUserData = pUserData
(*TFts5Auxiliary)(unsafe.Pointer(pAux)).FxFunc = __ccgo_fp_xFunc
(*TFts5Auxiliary)(unsafe.Pointer(pAux)).FxDestroy = __ccgo_fp_xDestroy
(*TFts5Auxiliary)(unsafe.Pointer(pAux)).FpNext = (*TFts5Global)(unsafe.Pointer(pGlobal)).FpAux
(*TFts5Global)(unsafe.Pointer(pGlobal)).FpAux = pAux
} else {
rc = int32(SQLITE_NOMEM)
}
}
return rc
}
func _fts5CursorFirstSorted(tls *libc.TLS, pTab uintptr, pCsr uintptr, bDesc int32) (r int32) {
bp := tls.Alloc(64)
defer tls.Free(64)
var nByte Tsqlite3_int64
var nPhrase, rc int32
var pConfig, pSorter, zRank, zRankArgs, v1, v2, v3 uintptr
_, _, _, _, _, _, _, _, _, _ = nByte, nPhrase, pConfig, pSorter, rc, zRank, zRankArgs, v1, v2, v3
pConfig = (*TFts5FullTable)(unsafe.Pointer(pTab)).Fp.FpConfig
zRank = (*TFts5Cursor)(unsafe.Pointer(pCsr)).FzRank
zRankArgs = (*TFts5Cursor)(unsafe.Pointer(pCsr)).FzRankArgs
nPhrase = _sqlite3Fts5ExprPhraseCount(tls, (*TFts5Cursor)(unsafe.Pointer(pCsr)).FpExpr)
nByte = libc.Int64FromUint64(uint64(libc.UintptrFromInt32(0)+24) + libc.Uint64FromInt32((nPhrase+libc.Int32FromInt32(2))/libc.Int32FromInt32(2))*libc.Uint64FromInt64(8))
pSorter = Xsqlite3_malloc64(tls, libc.Uint64FromInt64(nByte))
if pSorter == uintptr(0) {
return int32(SQLITE_NOMEM)
}
libc.X__builtin___memset_chk(tls, pSorter, 0, libc.Uint64FromInt64(nByte), ^t__predefined_size_t(0))
(*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 + 16562
} else {
v1 = __ccgo_ts + 1702
}
if zRankArgs != 0 {
v2 = zRankArgs
} else {
v2 = __ccgo_ts + 1702
}
if bDesc != 0 {
v3 = __ccgo_ts + 40144
} else {
v3 = __ccgo_ts + 40149
}
rc = _fts5PrepareStatement(tls, pSorter, pConfig, __ccgo_ts+40153, libc.VaList(bp+8, (*TFts5Config)(unsafe.Pointer(pConfig)).FzDb, (*TFts5Config)(unsafe.Pointer(pConfig)).FzName, zRank, (*TFts5Config)(unsafe.Pointer(pConfig)).FzName, v1, v2, v3))
(*TFts5Cursor)(unsafe.Pointer(pCsr)).FpSorter = pSorter
if rc == SQLITE_OK {
(*TFts5FullTable)(unsafe.Pointer(pTab)).FpSortCsr = pCsr
rc = _fts5SorterNext(tls, pCsr)
(*TFts5FullTable)(unsafe.Pointer(pTab)).FpSortCsr = uintptr(0)
}
if rc != SQLITE_OK {
Xsqlite3_finalize(tls, (*TFts5Sorter)(unsafe.Pointer(pSorter)).FpStmt)
Xsqlite3_free(tls, pSorter)
(*TFts5Cursor)(unsafe.Pointer(pCsr)).FpSorter = uintptr(0)
}
return rc
}
func _fts5CursorParseRank(tls *libc.TLS, pConfig uintptr, pCsr uintptr, pRank uintptr) (r int32) {
bp := tls.Alloc(32)
defer tls.Free(32)
var rc int32
var z uintptr
var _ /* zRank at bp+0 */ uintptr
var _ /* zRankArgs at bp+8 */ uintptr
_, _ = rc, z
rc = SQLITE_OK
if pRank != 0 {
z = Xsqlite3_value_text(tls, pRank)
**(**uintptr)(__ccgo_up(bp)) = uintptr(0)
**(**uintptr)(__ccgo_up(bp + 8)) = uintptr(0)
if z == uintptr(0) {
if Xsqlite3_value_type(tls, pRank) == int32(SQLITE_NULL) {
rc = int32(SQLITE_ERROR)
}
} else {
rc = _sqlite3Fts5ConfigParseRank(tls, z, bp, bp+8)
}
if rc == SQLITE_OK {
(*TFts5Cursor)(unsafe.Pointer(pCsr)).FzRank = **(**uintptr)(__ccgo_up(bp))
(*TFts5Cursor)(unsafe.Pointer(pCsr)).FzRankArgs = **(**uintptr)(__ccgo_up(bp + 8))
**(**int32)(__ccgo_up(pCsr + 80)) |= int32(FTS5CSR_FREE_ZRANK)
} else {
if rc == int32(SQLITE_ERROR) {
(*Tsqlite3_vtab)(unsafe.Pointer((*TFts5Cursor)(unsafe.Pointer(pCsr)).Fbase.FpVtab)).FzErrMsg = Xsqlite3_mprintf(tls, __ccgo_ts+40273, libc.VaList(bp+24, z))
}
}
} else {
if (*TFts5Config)(unsafe.Pointer(pConfig)).FzRank != 0 {
(*TFts5Cursor)(unsafe.Pointer(pCsr)).FzRank = (*TFts5Config)(unsafe.Pointer(pConfig)).FzRank
(*TFts5Cursor)(unsafe.Pointer(pCsr)).FzRankArgs = (*TFts5Config)(unsafe.Pointer(pConfig)).FzRankArgs
} else {
(*TFts5Cursor)(unsafe.Pointer(pCsr)).FzRank = __ccgo_ts + 37775
(*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+39388, libc.VaList(bp+8, (*TFts5Config)(unsafe.Pointer(pConfig)).FzDb, (*TFts5Config)(unsafe.Pointer(pConfig)).FzName))
if _fts5IndexPrepareStmt(tls, p, p+88, zSql) != 0 {
return
}
}
Xsqlite3_bind_int64(tls, (*TFts5Index)(unsafe.Pointer(p)).FpDeleter, int32(1), iFirst)
Xsqlite3_bind_int64(tls, (*TFts5Index)(unsafe.Pointer(p)).FpDeleter, int32(2), iLast)
Xsqlite3_step(tls, (*TFts5Index)(unsafe.Pointer(p)).FpDeleter)
(*TFts5Index)(unsafe.Pointer(p)).Frc = Xsqlite3_reset(tls, (*TFts5Index)(unsafe.Pointer(p)).FpDeleter)
}
// C documentation
//
// /*
// ** Retrieve a record from the %_data table.
// **
// ** If an error occurs, NULL is returned and an error left in the
// ** Fts5Index object.
// */
func _fts5DataRead(tls *libc.TLS, p uintptr, iRowid Ti64) (r uintptr) {
var aOut, pBlob, pConfig, pRet, v1 uintptr
var nAlloc, nByte, szData Ti64
var rc int32
_, _, _, _, _, _, _, _, _ = aOut, nAlloc, nByte, pBlob, pConfig, pRet, rc, szData, v1
pRet = uintptr(0)
if (*TFts5Index)(unsafe.Pointer(p)).Frc == SQLITE_OK {
rc = SQLITE_OK
if (*TFts5Index)(unsafe.Pointer(p)).FpReader != 0 {
/* This call may return SQLITE_ABORT if there has been a savepoint
** rollback since it was last used. In this case a new blob handle
** is required. */
pBlob = (*TFts5Index)(unsafe.Pointer(p)).FpReader
(*TFts5Index)(unsafe.Pointer(p)).FpReader = uintptr(0)
rc = Xsqlite3_blob_reopen(tls, pBlob, iRowid)
(*TFts5Index)(unsafe.Pointer(p)).FpReader = pBlob
if rc != SQLITE_OK {
_fts5IndexCloseReader(tls, p)
}
if rc == int32(SQLITE_ABORT) {
rc = SQLITE_OK
}
}
/* If the blob handle is not open at this point, open it and seek
** to the requested entry. */
if (*TFts5Index)(unsafe.Pointer(p)).FpReader == uintptr(0) && rc == SQLITE_OK {
pConfig = (*TFts5Index)(unsafe.Pointer(p)).FpConfig
rc = Xsqlite3_blob_open(tls, (*TFts5Config)(unsafe.Pointer(pConfig)).Fdb, (*TFts5Config)(unsafe.Pointer(pConfig)).FzDb, (*TFts5Index)(unsafe.Pointer(p)).FzDataTbl, __ccgo_ts+39331, iRowid, 0, p+72)
}
/* If either of the sqlite3_blob_open() or sqlite3_blob_reopen() calls
** above returned SQLITE_ERROR, return SQLITE_CORRUPT_VTAB instead.
** All the reasons those functions might return SQLITE_ERROR - missing
** table, missing row, non-blob/text in block column - indicate
** backing store corruption. */
if rc == int32(SQLITE_ERROR) {
rc = _fts5IndexCorruptRowid(tls, p, iRowid)
}
if rc == SQLITE_OK {
aOut = uintptr(0) /* Read blob data into this buffer */
nByte = int64(Xsqlite3_blob_bytes(tls, (*TFts5Index)(unsafe.Pointer(p)).FpReader))
szData = libc.Int64FromUint64((libc.Uint64FromInt64(16) + libc.Uint64FromInt32(7)) & libc.Uint64FromInt32(^libc.Int32FromInt32(7)))
nAlloc = szData + nByte + int64(FTS5_DATA_PADDING)
pRet = Xsqlite3_malloc64(tls, libc.Uint64FromInt64(nAlloc))
if pRet != 0 {
(*TFts5Data)(unsafe.Pointer(pRet)).Fnn = int32(nByte)
v1 = pRet + uintptr(szData)
(*TFts5Data)(unsafe.Pointer(pRet)).Fp = v1
aOut = v1
} else {
rc = int32(SQLITE_NOMEM)
}
if rc == SQLITE_OK {
rc = Xsqlite3_blob_read(tls, (*TFts5Index)(unsafe.Pointer(p)).FpReader, aOut, int32(nByte), 0)
}
if rc != SQLITE_OK {
Xsqlite3_free(tls, pRet)
pRet = uintptr(0)
} else {
/* TODO1: Fix this */
**(**Tu8)(__ccgo_up((*TFts5Data)(unsafe.Pointer(pRet)).Fp + uintptr(nByte))) = uint8(0x00)
**(**Tu8)(__ccgo_up((*TFts5Data)(unsafe.Pointer(pRet)).Fp + uintptr(nByte+int64(1)))) = uint8(0x00)
(*TFts5Data)(unsafe.Pointer(pRet)).FszLeaf = libc.Int32FromUint16(_fts5GetU16(tls, (*TFts5Data)(unsafe.Pointer(pRet)).Fp+2))
}
}
(*TFts5Index)(unsafe.Pointer(p)).Frc = rc
(*TFts5Index)(unsafe.Pointer(p)).FnRead = (*TFts5Index)(unsafe.Pointer(p)).FnRead + 1
}
return pRet
}
// C documentation
//
// /*
// ** Remove all records associated with segment iSegid.
// */
func _fts5DataRemoveSegment(tls *libc.TLS, p uintptr, pSeg uintptr) {
bp := tls.Alloc(32)
defer tls.Free(32)
var iFirst, iLast, iTomb1, iTomb2 Ti64
var iSegid int32
var pConfig uintptr
_, _, _, _, _, _ = iFirst, iLast, iSegid, iTomb1, iTomb2, pConfig
iSegid = (*TFts5StructureSegment)(unsafe.Pointer(pSeg)).FiSegid
iFirst = int64(iSegid)<<(libc.Int32FromInt32(FTS5_DATA_PAGE_B)+libc.Int32FromInt32(FTS5_DATA_HEIGHT_B)+libc.Int32FromInt32(FTS5_DATA_DLI_B)) + int64(libc.Int32FromInt32(0))<<(libc.Int32FromInt32(FTS5_DATA_PAGE_B)+libc.Int32FromInt32(FTS5_DATA_HEIGHT_B)) + int64(libc.Int32FromInt32(0))<= 0) {
break
}
pLvl = pIter + 8 + uintptr(i)*32
for _fts5DlidxLvlNext(tls, pLvl) == 0 {
}
(*TFts5DlidxLvl)(unsafe.Pointer(pLvl)).FbEof = 0
if i > 0 {
pChild = pLvl + uintptr(-libc.Int32FromInt32(1))*32
_fts5DataRelease(tls, (*TFts5DlidxLvl)(unsafe.Pointer(pChild)).FpData)
libc.X__builtin___memset_chk(tls, pChild, 0, uint64(32), ^t__predefined_size_t(0))
(*TFts5DlidxLvl)(unsafe.Pointer(pChild)).FpData = _fts5DataRead(tls, p, int64((*TFts5DlidxIter)(unsafe.Pointer(pIter)).FiSegid)<<(libc.Int32FromInt32(FTS5_DATA_PAGE_B)+libc.Int32FromInt32(FTS5_DATA_HEIGHT_B)+libc.Int32FromInt32(FTS5_DATA_DLI_B))+int64(libc.Int32FromInt32(1))<<(libc.Int32FromInt32(FTS5_DATA_PAGE_B)+libc.Int32FromInt32(FTS5_DATA_HEIGHT_B))+int64(i-libc.Int32FromInt32(1))<iLeafOffset is the
** offset of the first byte in the position-list for the entry to
** remove. Immediately before this comes two varints that will also
** need to be removed:
**
** + the rowid or delta rowid value for the entry, and
** + the size of the position list in bytes.
**
** Or, in detail=none mode, there is a single varint prior to
** pSeg->iLeafOffset - the rowid or delta rowid value.
**
** This block sets the following variables:
**
** iStart:
** The offset of the first byte of the rowid or delta-rowid
** value for the doclist entry being removed.
**
** iDelta:
** The value of the rowid or delta-rowid value for the doclist
** entry being removed.
**
** iNextOff:
** The offset of the next entry following the position list
** for the one being removed. If the position list for this
** entry overflows onto the next leaf page, this value will be
** greater than pLeaf->szLeaf.
*/
/* Start-Of-Position-list */
if (*TFts5SegIter)(unsafe.Pointer(pSeg)).FiLeafPgno == (*TFts5SegIter)(unsafe.Pointer(pSeg)).FiTermLeafPgno {
iStart = (*TFts5SegIter)(unsafe.Pointer(pSeg)).FiTermLeafOffset
} else {
iStart = libc.Int32FromUint16(_fts5GetU16(tls, aPg))
}
if iStart > nPg {
_fts5IndexCorruptIdx(tls, p)
Xsqlite3_free(tls, aIdx)
return
}
iSOP = iStart + libc.Int32FromUint8(_sqlite3Fts5GetVarint(tls, aPg+uintptr(iStart), bp))
if bDetailNone != 0 {
for int64(iSOP) < (*TFts5SegIter)(unsafe.Pointer(pSeg)).FiLeafOffset {
if libc.Int32FromUint8(**(**Tu8)(__ccgo_up(aPg + uintptr(iSOP)))) == 0x00 {
iSOP = iSOP + 1
}
if libc.Int32FromUint8(**(**Tu8)(__ccgo_up(aPg + uintptr(iSOP)))) == 0x00 {
iSOP = iSOP + 1
}
iStart = iSOP
iSOP = iStart + libc.Int32FromUint8(_sqlite3Fts5GetVarint(tls, aPg+uintptr(iStart), bp))
}
iNextOff = iSOP
if iNextOff < (*TFts5SegIter)(unsafe.Pointer(pSeg)).FiEndofDoclist && libc.Int32FromUint8(**(**Tu8)(__ccgo_up(aPg + uintptr(iNextOff)))) == 0x00 {
iNextOff = iNextOff + 1
}
if iNextOff < (*TFts5SegIter)(unsafe.Pointer(pSeg)).FiEndofDoclist && libc.Int32FromUint8(**(**Tu8)(__ccgo_up(aPg + uintptr(iNextOff)))) == 0x00 {
iNextOff = iNextOff + 1
}
} else {
**(**int32)(__ccgo_up(bp + 12)) = 0
iSOP = iSOP + _sqlite3Fts5GetVarint32(tls, aPg+uintptr(iSOP), bp+12)
for int64(iSOP) < (*TFts5SegIter)(unsafe.Pointer(pSeg)).FiLeafOffset {
iStart = iSOP + **(**int32)(__ccgo_up(bp + 12))/int32(2)
iSOP = iStart + libc.Int32FromUint8(_sqlite3Fts5GetVarint(tls, aPg+uintptr(iStart), bp))
iSOP = iSOP + _sqlite3Fts5GetVarint32(tls, aPg+uintptr(iSOP), bp+12)
}
iNextOff = iSOP + (*TFts5SegIter)(unsafe.Pointer(pSeg)).FnPos
}
iOff = iStart
/* If the position-list for the entry being removed flows over past
** the end of this page, delete the portion of the position-list on the
** next page and beyond.
**
** Set variable bLastInDoclist to true if this entry happens
** to be the last rowid in the doclist for its term. */
if iNextOff >= iPgIdx {
pgno = (*TFts5SegIter)(unsafe.Pointer(pSeg)).FiLeafPgno + int32(1)
_fts5SecureDeleteOverflow(tls, p, (*TFts5SegIter)(unsafe.Pointer(pSeg)).FpSeg, pgno, bp+8)
iNextOff = iPgIdx
}
if libc.Int32FromUint8((*TFts5SegIter)(unsafe.Pointer(pSeg)).FbDel) == 0 {
if iNextOff != iPgIdx {
/* Loop through the page-footer. If iNextOff (offset of the
** entry following the one we are removing) is equal to the
** offset of a key on this page, then the entry is the last
** in its doclist. */
iKeyOff = 0
iIdx = 0
for {
if !(iIdx < nIdx) {
break
}
**(**Tu32)(__ccgo_up(bp + 16)) = uint32(0)
iIdx = iIdx + _sqlite3Fts5GetVarint32(tls, aIdx+uintptr(iIdx), bp+16)
iKeyOff = libc.Int32FromUint32(uint32(iKeyOff) + **(**Tu32)(__ccgo_up(bp + 16)))
if iKeyOff == iNextOff {
**(**int32)(__ccgo_up(bp + 8)) = int32(1)
}
goto _1
_1:
}
}
/* If this is (a) the first rowid on a page and (b) is not followed by
** another position list on the same page, set the "first-rowid" field
** of the header to 0. */
if libc.Int32FromUint16(_fts5GetU16(tls, aPg)) == iStart && (**(**int32)(__ccgo_up(bp + 8)) != 0 || iNextOff == iPgIdx) {
_fts5PutU16(tls, aPg, uint16(0))
}
}
if (*TFts5SegIter)(unsafe.Pointer(pSeg)).FbDel != 0 {
iOff = iOff + _sqlite3Fts5PutVarint(tls, aPg+uintptr(iOff), **(**Tu64)(__ccgo_up(bp)))
v2 = iOff
iOff = iOff + 1
**(**Tu8)(__ccgo_up(aPg + uintptr(v2))) = uint8(0x01)
} else {
if **(**int32)(__ccgo_up(bp + 8)) == 0 {
if iNextOff != iPgIdx {
**(**Tu64)(__ccgo_up(bp + 24)) = uint64(0)
iNextOff = iNextOff + libc.Int32FromUint8(_sqlite3Fts5GetVarint(tls, aPg+uintptr(iNextOff), bp+24))
iOff = iOff + _sqlite3Fts5PutVarint(tls, aPg+uintptr(iOff), **(**Tu64)(__ccgo_up(bp))+**(**Tu64)(__ccgo_up(bp + 24)))
}
} else {
if (*TFts5SegIter)(unsafe.Pointer(pSeg)).FiLeafPgno == (*TFts5SegIter)(unsafe.Pointer(pSeg)).FiTermLeafPgno && iStart == (*TFts5SegIter)(unsafe.Pointer(pSeg)).FiTermLeafOffset {
/* The entry being removed was the only position list in its
** doclist. Therefore the term needs to be removed as well. */
iKey = 0
iKeyOff1 = 0
/* Set iKeyOff to the offset of the term that will be removed - the
** last offset in the footer that is not greater than iStart. */
iIdx = 0
for {
if !(iIdx < nIdx) {
break
}
**(**Tu32)(__ccgo_up(bp + 32)) = uint32(0)
iIdx = iIdx + _sqlite3Fts5GetVarint32(tls, aIdx+uintptr(iIdx), bp+32)
if libc.Uint32FromInt32(iKeyOff1)+**(**Tu32)(__ccgo_up(bp + 32)) > libc.Uint32FromInt32(iStart) {
break
}
iKeyOff1 = libc.Int32FromUint32(uint32(iKeyOff1) + **(**Tu32)(__ccgo_up(bp + 32)))
goto _3
_3:
;
iKey = iKey + 1
}
/* Set iDelKeyOff to the value of the footer entry to remove from
** the page. */
v2 = iKeyOff1
iOff = v2
iDelKeyOff = v2
if iNextOff != iPgIdx {
/* This is the only position-list associated with the term, and there
** is another term following it on this page. So the subsequent term
** needs to be moved to replace the term associated with the entry
** being removed. */
**(**Tu64)(__ccgo_up(bp + 40)) = uint64(0)
**(**Tu64)(__ccgo_up(bp + 48)) = uint64(0)
**(**Tu64)(__ccgo_up(bp + 56)) = uint64(0)
**(**Tu64)(__ccgo_up(bp + 64)) = uint64(0)
iDelKeyOff = iNextOff
iNextOff = iNextOff + libc.Int32FromUint8(_sqlite3Fts5GetVarint(tls, aPg+uintptr(iNextOff), bp+56))
iNextOff = iNextOff + libc.Int32FromUint8(_sqlite3Fts5GetVarint(tls, aPg+uintptr(iNextOff), bp+64))
if iKey != int32(1) {
iKeyOff1 = iKeyOff1 + libc.Int32FromUint8(_sqlite3Fts5GetVarint(tls, aPg+uintptr(iKeyOff1), bp+40))
}
iKeyOff1 = iKeyOff1 + libc.Int32FromUint8(_sqlite3Fts5GetVarint(tls, aPg+uintptr(iKeyOff1), bp+48))
if **(**Tu64)(__ccgo_up(bp + 40)) < **(**Tu64)(__ccgo_up(bp + 56)) {
v5 = **(**Tu64)(__ccgo_up(bp + 40))
} else {
v5 = **(**Tu64)(__ccgo_up(bp + 56))
}
**(**Tu64)(__ccgo_up(bp + 40)) = v5
**(**Tu64)(__ccgo_up(bp + 48)) = **(**Tu64)(__ccgo_up(bp + 56)) + **(**Tu64)(__ccgo_up(bp + 64)) - **(**Tu64)(__ccgo_up(bp + 40))
if libc.Uint64FromInt32(iKeyOff1)+**(**Tu64)(__ccgo_up(bp + 48)) > libc.Uint64FromInt32(iPgIdx) || libc.Uint64FromInt32(iNextOff)+**(**Tu64)(__ccgo_up(bp + 64)) > libc.Uint64FromInt32(iPgIdx) {
_fts5IndexCorruptIdx(tls, p)
} else {
if iKey != int32(1) {
iOff = iOff + _sqlite3Fts5PutVarint(tls, aPg+uintptr(iOff), **(**Tu64)(__ccgo_up(bp + 40)))
}
iOff = iOff + _sqlite3Fts5PutVarint(tls, aPg+uintptr(iOff), **(**Tu64)(__ccgo_up(bp + 48)))
if **(**Tu64)(__ccgo_up(bp + 56)) > libc.Uint64FromInt32((*TFts5SegIter)(unsafe.Pointer(pSeg)).Fterm.Fn) {
_fts5IndexCorruptIdx(tls, p)
} else {
if **(**Tu64)(__ccgo_up(bp + 56)) > **(**Tu64)(__ccgo_up(bp + 40)) {
libc.X__builtin___memcpy_chk(tls, aPg+uintptr(iOff), (*TFts5SegIter)(unsafe.Pointer(pSeg)).Fterm.Fp+uintptr(**(**Tu64)(__ccgo_up(bp + 40))), uint64(**(**Tu64)(__ccgo_up(bp + 56))-**(**Tu64)(__ccgo_up(bp + 40))), ^t__predefined_size_t(0))
iOff = libc.Int32FromUint64(uint64(iOff) + (**(**Tu64)(__ccgo_up(bp + 56)) - **(**Tu64)(__ccgo_up(bp + 40))))
}
}
libc.X__builtin___memmove_chk(tls, aPg+uintptr(iOff), aPg+uintptr(iNextOff), uint64(**(**Tu64)(__ccgo_up(bp + 64))), ^t__predefined_size_t(0))
iOff = libc.Int32FromUint64(uint64(iOff) + **(**Tu64)(__ccgo_up(bp + 64)))
iNextOff = libc.Int32FromUint64(uint64(iNextOff) + **(**Tu64)(__ccgo_up(bp + 64)))
}
}
} else {
if iStart == int32(4) {
/* The entry being removed may be the only position list in
** its doclist. */
iPgno = (*TFts5SegIter)(unsafe.Pointer(pSeg)).FiLeafPgno - int32(1)
for {
if !(iPgno > (*TFts5SegIter)(unsafe.Pointer(pSeg)).FiTermLeafPgno) {
break
}
pPg = _fts5DataRead(tls, p, 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))<= nTermIdx {
break
}
iTermIdx = iTermIdx + nByte
}
nTermIdx = iTermIdx
if iTermOff > int64((*TFts5Data)(unsafe.Pointer(pTerm)).FszLeaf) {
_fts5IndexCorruptIdx(tls, p)
} else {
libc.X__builtin___memmove_chk(tls, (*TFts5Data)(unsafe.Pointer(pTerm)).Fp+uintptr(iTermOff), (*TFts5Data)(unsafe.Pointer(pTerm)).Fp+uintptr((*TFts5Data)(unsafe.Pointer(pTerm)).FszLeaf), libc.Uint64FromInt32(nTermIdx), ^t__predefined_size_t(0))
_fts5PutU16(tls, (*TFts5Data)(unsafe.Pointer(pTerm)).Fp+2, libc.Uint16FromInt64(iTermOff))
_fts5DataWrite(tls, p, iId, (*TFts5Data)(unsafe.Pointer(pTerm)).Fp, int32(iTermOff+int64(nTermIdx)))
if nTermIdx == 0 {
_fts5SecureDeleteIdxEntry(tls, p, iSegid, (*TFts5SegIter)(unsafe.Pointer(pSeg)).FiTermLeafPgno)
}
}
}
_fts5DataRelease(tls, pTerm)
}
}
}
}
}
/* Assuming no error has occurred, this block does final edits to the
** leaf page before writing it back to disk. Input variables are:
**
** nPg: Total initial size of leaf page.
** iPgIdx: Initial offset of page footer.
**
** iOff: Offset to move data to
** iNextOff: Offset to move data from
*/
if (*TFts5Index)(unsafe.Pointer(p)).Frc == SQLITE_OK {
nMove = nPg - iNextOff /* Number of bytes to move */
nShift = iNextOff - iOff /* Distance to move them */
iPrevKeyOut = 0
iKeyIn = 0
if nMove > 0 {
libc.X__builtin___memmove_chk(tls, aPg+uintptr(iOff), aPg+uintptr(iNextOff), libc.Uint64FromInt32(nMove), ^t__predefined_size_t(0))
}
iPgIdx = iPgIdx - nShift
nPg = iPgIdx
_fts5PutU16(tls, aPg+2, libc.Uint16FromInt32(iPgIdx))
iIdx = 0
for {
if !(iIdx < nIdx) {
break
}
**(**Tu32)(__ccgo_up(bp + 76)) = uint32(0)
iIdx = iIdx + _sqlite3Fts5GetVarint32(tls, aIdx+uintptr(iIdx), bp+76)
iKeyIn = libc.Int32FromUint32(uint32(iKeyIn) + **(**Tu32)(__ccgo_up(bp + 76)))
if iKeyIn != iDelKeyOff {
if iKeyIn > iOff {
v2 = nShift
} else {
v2 = 0
}
iKeyOut = iKeyIn - v2
nPg = nPg + _sqlite3Fts5PutVarint(tls, aPg+uintptr(nPg), libc.Uint64FromInt32(iKeyOut-iPrevKeyOut))
iPrevKeyOut = iKeyOut
}
goto _7
_7:
}
if iPgIdx == nPg && nIdx > 0 && (*TFts5SegIter)(unsafe.Pointer(pSeg)).FiLeafPgno != int32(1) {
_fts5SecureDeleteIdxEntry(tls, p, iSegid, (*TFts5SegIter)(unsafe.Pointer(pSeg)).FiLeafPgno)
}
_fts5DataWrite(tls, p, 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))< 0 {
(*TFts5DoclistIter)(unsafe.Pointer(pIter)).FaPoslist = (*TFts5Buffer)(unsafe.Pointer(pBuf)).Fp
(*TFts5DoclistIter)(unsafe.Pointer(pIter)).FaEof = (*TFts5Buffer)(unsafe.Pointer(pBuf)).Fp + uintptr((*TFts5Buffer)(unsafe.Pointer(pBuf)).Fn)
_fts5DoclistIterNext(tls, pIter)
}
}
// C documentation
//
// /*
// ** Add pSub as a child of p.
// */
func _fts5ExprAddChildren(tls *libc.TLS, p uintptr, pSub uintptr) {
var ii, nByte, v1 int32
var v2 uintptr
_, _, _, _ = ii, nByte, v1, v2
ii = (*TFts5ExprNode)(unsafe.Pointer(p)).FnChild
if (*TFts5ExprNode)(unsafe.Pointer(p)).FeType != int32(FTS5_NOT) && (*TFts5ExprNode)(unsafe.Pointer(pSub)).FeType == (*TFts5ExprNode)(unsafe.Pointer(p)).FeType {
nByte = libc.Int32FromUint64(uint64(8) * libc.Uint64FromInt32((*TFts5ExprNode)(unsafe.Pointer(pSub)).FnChild))
libc.X__builtin___memcpy_chk(tls, p+48+uintptr((*TFts5ExprNode)(unsafe.Pointer(p)).FnChild)*8, pSub+48, libc.Uint64FromInt32(nByte), ^t__predefined_size_t(0))
**(**int32)(__ccgo_up(p + 40)) += (*TFts5ExprNode)(unsafe.Pointer(pSub)).FnChild
Xsqlite3_free(tls, pSub)
} else {
v2 = p + 40
v1 = *(*int32)(unsafe.Pointer(v2))
*(*int32)(unsafe.Pointer(v2)) = *(*int32)(unsafe.Pointer(v2)) + 1
*(*uintptr)(unsafe.Pointer(p + 48 + uintptr(v1)*8)) = pSub
}
for {
if !(ii < (*TFts5ExprNode)(unsafe.Pointer(p)).FnChild) {
break
}
if (*TFts5ExprNode)(unsafe.Pointer(p)).FiHeight > (*TFts5ExprNode)(unsafe.Pointer(*(*uintptr)(unsafe.Pointer(p + 48 + uintptr(ii)*8)))).FiHeight+int32(1) {
v1 = (*TFts5ExprNode)(unsafe.Pointer(p)).FiHeight
} else {
v1 = (*TFts5ExprNode)(unsafe.Pointer(*(*uintptr)(unsafe.Pointer(p + 48 + uintptr(ii)*8)))).FiHeight + int32(1)
}
(*TFts5ExprNode)(unsafe.Pointer(p)).FiHeight = v1
goto _3
_3:
;
ii = ii + 1
}
}
// 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+38936, 0)
return FTS5_EOF
}
goto _1
_1:
;
z2 = z2 + 1
}
(*TFts5Token)(unsafe.Pointer(pToken)).Fn = int32(int64(z2) - int64(z))
default:
if _sqlite3Fts5IsBareword(tls, **(**int8)(__ccgo_up(z))) == 0 {
_sqlite3Fts5ParseError(tls, pParse, __ccgo_ts+38956, 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(int64(z21) - int64(z))
if (*TFts5Token)(unsafe.Pointer(pToken)).Fn == int32(2) && libc.Xmemcmp(tls, (*TFts5Token)(unsafe.Pointer(pToken)).Fp, __ccgo_ts+38987, uint64(2)) == 0 {
tok = int32(FTS5_OR)
}
if (*TFts5Token)(unsafe.Pointer(pToken)).Fn == int32(3) && libc.Xmemcmp(tls, (*TFts5Token)(unsafe.Pointer(pToken)).Fp, __ccgo_ts+38990, uint64(3)) == 0 {
tok = int32(FTS5_NOT)
}
if (*TFts5Token)(unsafe.Pointer(pToken)).Fn == int32(3) && libc.Xmemcmp(tls, (*TFts5Token)(unsafe.Pointer(pToken)).Fp, __ccgo_ts+32799, uint64(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
//
// /*
// ** The near-set object passed as the first argument contains more than
// ** one phrase. All phrases currently point to the same row. The
// ** Fts5ExprPhrase.poslist buffers are populated accordingly. This function
// ** tests if the current row contains instances of each phrase sufficiently
// ** close together to meet the NEAR constraint. Non-zero is returned if it
// ** does, or zero otherwise.
// **
// ** If in/out parameter (*pRc) is set to other than SQLITE_OK when this
// ** function is called, it is a no-op. Or, if an error (e.g. SQLITE_NOMEM)
// ** occurs within this function (*pRc) is set accordingly before returning.
// ** The return value is undefined in both these cases.
// **
// ** If no error occurs and non-zero (a match) is returned, the position-list
// ** of each phrase object is edited to contain only those entries that
// ** meet the constraint before returning.
// */
func _fts5ExprNearIsMatch(tls *libc.TLS, pRc uintptr, pNear uintptr) (r int32) {
bp := tls.Alloc(208)
defer tls.Free(208)
var a, apPhrase, pPos, pPoslist, pWriter uintptr
var bMatch, bRet, i, iAdv int32
var iMax, iMin, iPos Ti64
var nByte Tsqlite3_int64
var _ /* aStatic at bp+0 */ [4]TFts5NearTrimmer
var _ /* rc at bp+192 */ int32
_, _, _, _, _, _, _, _, _, _, _, _, _ = a, apPhrase, bMatch, bRet, i, iAdv, iMax, iMin, iPos, nByte, pPos, pPoslist, pWriter
a = bp
apPhrase = pNear + 24
**(**int32)(__ccgo_up(bp + 192)) = **(**int32)(__ccgo_up(pRc))
/* If the aStatic[] array is not large enough, allocate a large array
** using sqlite3_malloc(). This approach could be improved upon. */
if (*TFts5ExprNearset)(unsafe.Pointer(pNear)).FnPhrase > libc.Int32FromUint64(libc.Uint64FromInt64(192)/libc.Uint64FromInt64(48)) {
nByte = libc.Int64FromUint64(uint64(48) * libc.Uint64FromInt32((*TFts5ExprNearset)(unsafe.Pointer(pNear)).FnPhrase))
a = _sqlite3Fts5MallocZero(tls, bp+192, nByte)
} else {
libc.X__builtin___memset_chk(tls, bp, 0, uint64(192), ^t__predefined_size_t(0))
}
if **(**int32)(__ccgo_up(bp + 192)) != SQLITE_OK {
**(**int32)(__ccgo_up(pRc)) = **(**int32)(__ccgo_up(bp + 192))
return 0
}
/* Initialize a lookahead iterator for each phrase. After passing the
** buffer and buffer size to the lookaside-reader init function, zero
** the phrase poslist buffer. The new poslist for the phrase (containing
** the same entries as the original with some entries removed on account
** of the NEAR constraint) is written over the original even as it is
** being read. This is safe as the entries for the new poslist are a
** subset of the old, so it is not possible for data yet to be read to
** be overwritten. */
i = 0
for {
if !(i < (*TFts5ExprNearset)(unsafe.Pointer(pNear)).FnPhrase) {
break
}
pPoslist = **(**uintptr)(__ccgo_up(apPhrase + uintptr(i)*8)) + 8
_fts5LookaheadReaderInit(tls, (*TFts5Buffer)(unsafe.Pointer(pPoslist)).Fp, (*TFts5Buffer)(unsafe.Pointer(pPoslist)).Fn, a+uintptr(i)*48)
(*TFts5Buffer)(unsafe.Pointer(pPoslist)).Fn = 0
(**(**TFts5NearTrimmer)(__ccgo_up(a + uintptr(i)*48))).FpOut = pPoslist
goto _1
_1:
;
i = i + 1
}
for int32(1) != 0 {
/* This block advances the phrase iterators until they point to a set of
** entries that together comprise a match. */
iMax = (**(**TFts5NearTrimmer)(__ccgo_up(a))).Freader.FiPos
for cond := true; cond; cond = bMatch == 0 {
bMatch = int32(1)
i = 0
for {
if !(i < (*TFts5ExprNearset)(unsafe.Pointer(pNear)).FnPhrase) {
break
}
pPos = a + uintptr(i)*48
iMin = iMax - int64((*TFts5ExprPhrase)(unsafe.Pointer(*(*uintptr)(unsafe.Pointer(pNear + 24 + uintptr(i)*8)))).FnTerm) - int64((*TFts5ExprNearset)(unsafe.Pointer(pNear)).FnNear)
if (*TFts5LookaheadReader)(unsafe.Pointer(pPos)).FiPos < iMin || (*TFts5LookaheadReader)(unsafe.Pointer(pPos)).FiPos > iMax {
bMatch = 0
for (*TFts5LookaheadReader)(unsafe.Pointer(pPos)).FiPos < iMin {
if _fts5LookaheadReaderNext(tls, pPos) != 0 {
goto ismatch_out
}
}
if (*TFts5LookaheadReader)(unsafe.Pointer(pPos)).FiPos > iMax {
iMax = (*TFts5LookaheadReader)(unsafe.Pointer(pPos)).FiPos
}
}
goto _2
_2:
;
i = i + 1
}
}
/* Add an entry to each output position list */
i = 0
for {
if !(i < (*TFts5ExprNearset)(unsafe.Pointer(pNear)).FnPhrase) {
break
}
iPos = (**(**TFts5NearTrimmer)(__ccgo_up(a + uintptr(i)*48))).Freader.FiPos
pWriter = a + uintptr(i)*48 + 32
if (*TFts5Buffer)(unsafe.Pointer((**(**TFts5NearTrimmer)(__ccgo_up(a + uintptr(i)*48))).FpOut)).Fn == 0 || iPos != (*TFts5PoslistWriter)(unsafe.Pointer(pWriter)).FiPrev {
_sqlite3Fts5PoslistSafeAppend(tls, (**(**TFts5NearTrimmer)(__ccgo_up(a + uintptr(i)*48))).FpOut, pWriter, iPos)
}
goto _3
_3:
;
i = i + 1
}
iAdv = 0
iMin = (**(**TFts5NearTrimmer)(__ccgo_up(a))).Freader.FiLookahead
i = 0
for {
if !(i < (*TFts5ExprNearset)(unsafe.Pointer(pNear)).FnPhrase) {
break
}
if (**(**TFts5NearTrimmer)(__ccgo_up(a + uintptr(i)*48))).Freader.FiLookahead < iMin {
iMin = (**(**TFts5NearTrimmer)(__ccgo_up(a + uintptr(i)*48))).Freader.FiLookahead
iAdv = i
}
goto _4
_4:
;
i = i + 1
}
if _fts5LookaheadReaderNext(tls, a+uintptr(iAdv)*48) != 0 {
goto ismatch_out
}
}
goto ismatch_out
ismatch_out:
;
bRet = libc.BoolInt32((*TFts5Buffer)(unsafe.Pointer((**(**TFts5NearTrimmer)(__ccgo_up(a))).FpOut)).Fn > 0)
**(**int32)(__ccgo_up(pRc)) = **(**int32)(__ccgo_up(bp + 192))
if a != bp {
Xsqlite3_free(tls, a)
}
return bRet
return r
}
// C documentation
//
// /*
// ** All individual term iterators in pPhrase are guaranteed to be valid and
// ** pointing to the same rowid when this function is called. This function
// ** checks if the current rowid really is a match, and if so populates
// ** the pPhrase->poslist buffer accordingly. Output parameter *pbMatch
// ** is set to true if this is really a match, or false otherwise.
// **
// ** SQLITE_OK is returned if an error occurs, or an SQLite error code
// ** otherwise. It is not considered an error code if the current rowid is
// ** not a match.
// */
func _fts5ExprPhraseIsMatch(tls *libc.TLS, pNode uintptr, pPhrase uintptr, pbMatch uintptr) (r int32) {
bp := tls.Alloc(176)
defer tls.Free(176)
var aIter, pPos, pTerm uintptr
var bFirst, bFlag, bMatch, i, rc int32
var iAdj, iPos Ti64
var nByte Tsqlite3_int64
var _ /* a at bp+144 */ uintptr
var _ /* aStatic at bp+8 */ [4]TFts5PoslistReader
var _ /* buf at bp+152 */ TFts5Buffer
var _ /* n at bp+136 */ int32
var _ /* writer at bp+0 */ TFts5PoslistWriter
_, _, _, _, _, _, _, _, _, _, _ = aIter, bFirst, bFlag, bMatch, i, iAdj, iPos, nByte, pPos, pTerm, rc
**(**TFts5PoslistWriter)(__ccgo_up(bp)) = TFts5PoslistWriter{}
aIter = bp + 8
rc = SQLITE_OK
bFirst = libc.Int32FromUint8((*(*TFts5ExprTerm)(unsafe.Pointer(pPhrase + 32))).FbFirst)
_sqlite3Fts5BufferZero(tls, pPhrase+8)
/* If the aStatic[] array is not large enough, allocate a large array
** using sqlite3_malloc(). This approach could be improved upon. */
if (*TFts5ExprPhrase)(unsafe.Pointer(pPhrase)).FnTerm > libc.Int32FromUint64(libc.Uint64FromInt64(128)/libc.Uint64FromInt64(32)) {
nByte = libc.Int64FromUint64(uint64(32) * libc.Uint64FromInt32((*TFts5ExprPhrase)(unsafe.Pointer(pPhrase)).FnTerm))
aIter = Xsqlite3_malloc64(tls, libc.Uint64FromInt64(nByte))
if !(aIter != 0) {
return int32(SQLITE_NOMEM)
}
}
libc.X__builtin___memset_chk(tls, aIter, 0, uint64(32)*libc.Uint64FromInt32((*TFts5ExprPhrase)(unsafe.Pointer(pPhrase)).FnTerm), ^t__predefined_size_t(0))
/* Initialize a term iterator for each term in the phrase */
i = 0
for {
if !(i < (*TFts5ExprPhrase)(unsafe.Pointer(pPhrase)).FnTerm) {
break
}
pTerm = pPhrase + 32 + uintptr(i)*40
**(**int32)(__ccgo_up(bp + 136)) = 0
bFlag = 0
**(**uintptr)(__ccgo_up(bp + 144)) = uintptr(0)
if (*TFts5ExprTerm)(unsafe.Pointer(pTerm)).FpSynonym != 0 {
**(**TFts5Buffer)(__ccgo_up(bp + 152)) = TFts5Buffer{}
rc = _fts5ExprSynonymList(tls, pTerm, (*TFts5ExprNode)(unsafe.Pointer(pNode)).FiRowid, bp+152, bp+144, bp+136)
if rc != 0 {
Xsqlite3_free(tls, **(**uintptr)(__ccgo_up(bp + 144)))
goto ismatch_out
}
if **(**uintptr)(__ccgo_up(bp + 144)) == (**(**TFts5Buffer)(__ccgo_up(bp + 152))).Fp {
bFlag = int32(1)
}
} else {
**(**uintptr)(__ccgo_up(bp + 144)) = (*TFts5IndexIter)(unsafe.Pointer((*TFts5ExprTerm)(unsafe.Pointer(pTerm)).FpIter)).FpData
**(**int32)(__ccgo_up(bp + 136)) = (*TFts5IndexIter)(unsafe.Pointer((*TFts5ExprTerm)(unsafe.Pointer(pTerm)).FpIter)).FnData
}
_sqlite3Fts5PoslistReaderInit(tls, **(**uintptr)(__ccgo_up(bp + 144)), **(**int32)(__ccgo_up(bp + 136)), aIter+uintptr(i)*32)
(**(**TFts5PoslistReader)(__ccgo_up(aIter + uintptr(i)*32))).FbFlag = libc.Uint8FromInt32(bFlag)
if (**(**TFts5PoslistReader)(__ccgo_up(aIter + uintptr(i)*32))).FbEof != 0 {
goto ismatch_out
}
goto _1
_1:
;
i = i + 1
}
for int32(1) != 0 {
iPos = (**(**TFts5PoslistReader)(__ccgo_up(aIter))).FiPos
for cond := true; cond; cond = bMatch == 0 {
bMatch = int32(1)
i = 0
for {
if !(i < (*TFts5ExprPhrase)(unsafe.Pointer(pPhrase)).FnTerm) {
break
}
pPos = aIter + uintptr(i)*32
iAdj = iPos + int64(i)
if (*TFts5PoslistReader)(unsafe.Pointer(pPos)).FiPos != iAdj {
bMatch = 0
for (*TFts5PoslistReader)(unsafe.Pointer(pPos)).FiPos < iAdj {
if _sqlite3Fts5PoslistReaderNext(tls, pPos) != 0 {
goto ismatch_out
}
}
if (*TFts5PoslistReader)(unsafe.Pointer(pPos)).FiPos > iAdj {
iPos = (*TFts5PoslistReader)(unsafe.Pointer(pPos)).FiPos - int64(i)
}
}
goto _2
_2:
;
i = i + 1
}
}
/* Append position iPos to the output */
if bFirst == 0 || int32(iPos&libc.Int64FromInt32(0x7FFFFFFF)) == 0 {
rc = _sqlite3Fts5PoslistWriterAppend(tls, pPhrase+8, bp, iPos)
if rc != SQLITE_OK {
goto ismatch_out
}
}
i = 0
for {
if !(i < (*TFts5ExprPhrase)(unsafe.Pointer(pPhrase)).FnTerm) {
break
}
if _sqlite3Fts5PoslistReaderNext(tls, aIter+uintptr(i)*32) != 0 {
goto ismatch_out
}
goto _3
_3:
;
i = i + 1
}
}
goto ismatch_out
ismatch_out:
;
**(**int32)(__ccgo_up(pbMatch)) = libc.BoolInt32((*TFts5ExprPhrase)(unsafe.Pointer(pPhrase)).Fposlist.Fn > 0)
i = 0
for {
if !(i < (*TFts5ExprPhrase)(unsafe.Pointer(pPhrase)).FnTerm) {
break
}
if (**(**TFts5PoslistReader)(__ccgo_up(aIter + uintptr(i)*32))).FbFlag != 0 {
Xsqlite3_free(tls, (**(**TFts5PoslistReader)(__ccgo_up(aIter + uintptr(i)*32))).Fa)
}
goto _4
_4:
;
i = i + 1
}
if aIter != bp+8 {
Xsqlite3_free(tls, aIter)
}
return rc
}
// C documentation
//
// /*
// ** Argument pTerm must be a synonym iterator.
// */
func _fts5ExprSynonymList(tls *libc.TLS, pTerm uintptr, iRowid Ti64, pBuf uintptr, pa uintptr, pn uintptr) (r int32) {
bp := tls.Alloc(144)
defer tls.Free(144)
var aIter, aNew, p, pIter uintptr
var i, nAlloc, nIter, rc int32
var iMin, iPrev Ti64
var nByte Tsqlite3_int64
var _ /* aStatic at bp+0 */ [4]TFts5PoslistReader
var _ /* writer at bp+128 */ TFts5PoslistWriter
_, _, _, _, _, _, _, _, _, _, _ = aIter, aNew, i, iMin, iPrev, nAlloc, nByte, nIter, p, pIter, rc
aIter = bp
nIter = 0
nAlloc = int32(4)
rc = SQLITE_OK
p = pTerm
for {
if !(p != 0) {
break
}
pIter = (*TFts5ExprTerm)(unsafe.Pointer(p)).FpIter
if libc.Int32FromUint8((*TFts5IndexIter)(unsafe.Pointer(pIter)).FbEof) == 0 && (*TFts5IndexIter)(unsafe.Pointer(pIter)).FiRowid == iRowid {
if (*TFts5IndexIter)(unsafe.Pointer(pIter)).FnData == 0 {
goto _1
}
if nIter == nAlloc {
nByte = libc.Int64FromUint64(uint64(32) * libc.Uint64FromInt32(nAlloc) * uint64(2))
aNew = Xsqlite3_malloc64(tls, libc.Uint64FromInt64(nByte))
if aNew == uintptr(0) {
rc = int32(SQLITE_NOMEM)
goto synonym_poslist_out
}
libc.X__builtin___memcpy_chk(tls, aNew, aIter, uint64(32)*libc.Uint64FromInt32(nIter), ^t__predefined_size_t(0))
nAlloc = nAlloc * int32(2)
if aIter != bp {
Xsqlite3_free(tls, aIter)
}
aIter = aNew
}
_sqlite3Fts5PoslistReaderInit(tls, (*TFts5IndexIter)(unsafe.Pointer(pIter)).FpData, (*TFts5IndexIter)(unsafe.Pointer(pIter)).FnData, aIter+uintptr(nIter)*32)
nIter = nIter + 1
}
goto _1
_1:
;
p = (*TFts5ExprTerm)(unsafe.Pointer(p)).FpSynonym
}
if nIter == int32(1) {
**(**uintptr)(__ccgo_up(pa)) = (**(**TFts5PoslistReader)(__ccgo_up(aIter))).Fa
**(**int32)(__ccgo_up(pn)) = (**(**TFts5PoslistReader)(__ccgo_up(aIter))).Fn
} else {
**(**TFts5PoslistWriter)(__ccgo_up(bp + 128)) = TFts5PoslistWriter{}
iPrev = int64(-int32(1))
_sqlite3Fts5BufferZero(tls, pBuf)
for int32(1) != 0 {
iMin = libc.Int64FromUint32(0xffffffff) | libc.Int64FromInt32(0x7fffffff)<= 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 + 8))))) == 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 + 8))+1)
bInternal = int32(1)
} else {
pzErr = pTab + 16
rc = _sqlite3Fts5ExprNew(tls, pConfig, 0, iCol, **(**uintptr)(__ccgo_up(bp + 8)), bp, pzErr)
if rc == SQLITE_OK {
rc = _sqlite3Fts5ExprAnd(tls, pCsr+64, **(**uintptr)(__ccgo_up(bp)))
**(**uintptr)(__ccgo_up(bp)) = uintptr(0)
}
}
if **(**int32)(__ccgo_up(bp + 16)) != 0 {
Xsqlite3_free(tls, **(**uintptr)(__ccgo_up(bp + 8)))
_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)*8)))
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+64, **(**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)*8))
case int32('<'):
pRowidLe = **(**uintptr)(__ccgo_up(apVal + uintptr(i)*8))
default:
pRowidGe = **(**uintptr)(__ccgo_up(apVal + uintptr(i)*8))
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)< 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+40306, libc.VaList(bp+32, (*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+56, pTab+16)
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
}
func _fts5FindRankFunction(tls *libc.TLS, pCsr uintptr) (r int32) {
bp := tls.Alloc(32)
defer tls.Free(32)
var i int32
var nByte Tsqlite3_int64
var pAux, pConfig, pTab, zRank, zRankArgs, zSql uintptr
var _ /* pStmt at bp+8 */ uintptr
var _ /* rc at bp+0 */ int32
_, _, _, _, _, _, _, _ = i, nByte, pAux, pConfig, pTab, zRank, zRankArgs, zSql
pTab = (*TFts5Cursor)(unsafe.Pointer(pCsr)).Fbase.FpVtab
pConfig = (*TFts5FullTable)(unsafe.Pointer(pTab)).Fp.FpConfig
**(**int32)(__ccgo_up(bp)) = SQLITE_OK
pAux = uintptr(0)
zRank = (*TFts5Cursor)(unsafe.Pointer(pCsr)).FzRank
zRankArgs = (*TFts5Cursor)(unsafe.Pointer(pCsr)).FzRankArgs
if zRankArgs != 0 {
zSql = _sqlite3Fts5Mprintf(tls, bp, __ccgo_ts+40242, libc.VaList(bp+24, zRankArgs))
if zSql != 0 {
**(**uintptr)(__ccgo_up(bp + 8)) = uintptr(0)
**(**int32)(__ccgo_up(bp)) = Xsqlite3_prepare_v3(tls, (*TFts5Config)(unsafe.Pointer(pConfig)).Fdb, zSql, -int32(1), uint32(SQLITE_PREPARE_PERSISTENT), bp+8, uintptr(0))
Xsqlite3_free(tls, zSql)
if **(**int32)(__ccgo_up(bp)) == SQLITE_OK {
if int32(SQLITE_ROW) == Xsqlite3_step(tls, **(**uintptr)(__ccgo_up(bp + 8))) {
(*TFts5Cursor)(unsafe.Pointer(pCsr)).FnRankArg = Xsqlite3_column_count(tls, **(**uintptr)(__ccgo_up(bp + 8)))
nByte = libc.Int64FromUint64(uint64(8) * libc.Uint64FromInt32((*TFts5Cursor)(unsafe.Pointer(pCsr)).FnRankArg))
(*TFts5Cursor)(unsafe.Pointer(pCsr)).FapRankArg = _sqlite3Fts5MallocZero(tls, bp, nByte)
if **(**int32)(__ccgo_up(bp)) == SQLITE_OK {
i = 0
for {
if !(i < (*TFts5Cursor)(unsafe.Pointer(pCsr)).FnRankArg) {
break
}
**(**uintptr)(__ccgo_up((*TFts5Cursor)(unsafe.Pointer(pCsr)).FapRankArg + uintptr(i)*8)) = Xsqlite3_column_value(tls, **(**uintptr)(__ccgo_up(bp + 8)), i)
goto _1
_1:
;
i = i + 1
}
}
(*TFts5Cursor)(unsafe.Pointer(pCsr)).FpRankArgStmt = **(**uintptr)(__ccgo_up(bp + 8))
} else {
**(**int32)(__ccgo_up(bp)) = Xsqlite3_finalize(tls, **(**uintptr)(__ccgo_up(bp + 8)))
}
}
}
}
if **(**int32)(__ccgo_up(bp)) == SQLITE_OK {
pAux = _fts5FindAuxiliary(tls, pTab, zRank)
if pAux == uintptr(0) {
(*TFts5FullTable)(unsafe.Pointer(pTab)).Fp.Fbase.FzErrMsg = Xsqlite3_mprintf(tls, __ccgo_ts+40252, libc.VaList(bp+24, zRank))
**(**int32)(__ccgo_up(bp)) = int32(SQLITE_ERROR)
}
}
(*TFts5Cursor)(unsafe.Pointer(pCsr)).FpRank = pAux
return **(**int32)(__ccgo_up(bp))
}
// C documentation
//
// /*
// ** Find a tokenizer. This is the implementation of the
// ** fts5_api.xFindTokenizer() method.
// */
func _fts5FindTokenizer(tls *libc.TLS, pApi uintptr, zName uintptr, ppUserData uintptr, pTokenizer uintptr) (r int32) {
var pMod uintptr
var rc int32
_, _ = pMod, rc
rc = SQLITE_OK
pMod = _fts5LocateTokenizer(tls, pApi, zName)
if pMod != 0 {
if (*TFts5TokenizerModule)(unsafe.Pointer(pMod)).FbV2Native == 0 {
**(**uintptr)(__ccgo_up(ppUserData)) = (*TFts5TokenizerModule)(unsafe.Pointer(pMod)).FpUserData
} else {
**(**uintptr)(__ccgo_up(ppUserData)) = pMod
}
**(**Tfts5_tokenizer)(__ccgo_up(pTokenizer)) = (*TFts5TokenizerModule)(unsafe.Pointer(pMod)).Fx1
} else {
libc.X__builtin___memset_chk(tls, pTokenizer, 0, uint64(24), ^t__predefined_size_t(0))
**(**uintptr)(__ccgo_up(ppUserData)) = uintptr(0)
rc = int32(SQLITE_ERROR)
}
return rc
}
// C documentation
//
// /*
// ** Flush the contents of in-memory hash table iHash to a new level-0
// ** segment on disk. Also update the corresponding structure record.
// **
// ** If an error occurs, set the Fts5Index.rc error code. If an error has
// ** already occurred, this function is a no-op.
// */
func _fts5FlushOneHash(tls *libc.TLS, p uintptr) {
bp := tls.Alloc(192)
defer tls.Free(192)
var bSecureDelete, bTermWritten, eDetail, iOff, iPos, iSegid, n, nCopy, nSpace, pgsz, v1 int32
var iPrev, iRowid Ti64
var iRowidDelta Tu64
var pBuf, pHash, pPgidx, pPoslist, pSeg, v2 uintptr
var _ /* bDel at bp+176 */ int32
var _ /* iDelta at bp+168 */ Tu64
var _ /* nDoclist at bp+160 */ int32
var _ /* nPos at bp+180 */ int32
var _ /* nTerm at bp+144 */ int32
var _ /* pDoclist at bp+152 */ uintptr
var _ /* pStruct at bp+0 */ uintptr
var _ /* pgnoLast at bp+8 */ int32
var _ /* writer at bp+16 */ TFts5SegWriter
var _ /* zTerm at bp+136 */ uintptr
_, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _ = bSecureDelete, bTermWritten, eDetail, iOff, iPos, iPrev, iRowid, iRowidDelta, iSegid, n, nCopy, nSpace, pBuf, pHash, pPgidx, pPoslist, pSeg, pgsz, v1, v2
pHash = (*TFts5Index)(unsafe.Pointer(p)).FpHash
**(**int32)(__ccgo_up(bp + 8)) = 0 /* Last leaf page number in segment */
/* Obtain a reference to the index structure and allocate a new segment-id
** for the new level-0 segment. */
**(**uintptr)(__ccgo_up(bp)) = _fts5StructureRead(tls, p)
_fts5StructureInvalidate(tls, p)
if _sqlite3Fts5HashIsEmpty(tls, pHash) == 0 {
iSegid = _fts5AllocateSegid(tls, p, **(**uintptr)(__ccgo_up(bp)))
if iSegid != 0 {
pgsz = (*TFts5Config)(unsafe.Pointer((*TFts5Index)(unsafe.Pointer(p)).FpConfig)).Fpgsz
eDetail = (*TFts5Config)(unsafe.Pointer((*TFts5Index)(unsafe.Pointer(p)).FpConfig)).FeDetail
bSecureDelete = (*TFts5Config)(unsafe.Pointer((*TFts5Index)(unsafe.Pointer(p)).FpConfig)).FbSecureDelete
_fts5WriteInit(tls, p, bp+16, iSegid)
pBuf = bp + 16 + 8 + 8
pPgidx = bp + 16 + 8 + 24
/* fts5WriteInit() should have initialized the buffers to (most likely)
** the maximum space required. */
/* Begin scanning through hash table entries. This loop runs once for each
** term/doclist currently stored within the hash table. */
if (*TFts5Index)(unsafe.Pointer(p)).Frc == SQLITE_OK {
(*TFts5Index)(unsafe.Pointer(p)).Frc = _sqlite3Fts5HashScanInit(tls, pHash, uintptr(0), 0)
}
for (*TFts5Index)(unsafe.Pointer(p)).Frc == SQLITE_OK && 0 == _sqlite3Fts5HashScanEof(tls, pHash) { /* Size of doclist in bytes */
/* Get the term and doclist for this entry. */
_sqlite3Fts5HashScanEntry(tls, pHash, bp+136, bp+144, bp+152, bp+160)
if bSecureDelete == 0 {
_fts5WriteAppendTerm(tls, p, bp+16, **(**int32)(__ccgo_up(bp + 144)), **(**uintptr)(__ccgo_up(bp + 136)))
if (*TFts5Index)(unsafe.Pointer(p)).Frc != SQLITE_OK {
break
}
}
if !(bSecureDelete != 0) && pgsz >= (*TFts5Buffer)(unsafe.Pointer(pBuf)).Fn+(*TFts5Buffer)(unsafe.Pointer(pPgidx)).Fn+**(**int32)(__ccgo_up(bp + 160))+int32(1) {
/* The entire doclist will fit on the current leaf. */
libc.X__builtin___memcpy_chk(tls, (*TFts5Buffer)(unsafe.Pointer(pBuf)).Fp+uintptr((*TFts5Buffer)(unsafe.Pointer(pBuf)).Fn), **(**uintptr)(__ccgo_up(bp + 152)), libc.Uint64FromInt32(**(**int32)(__ccgo_up(bp + 160))), ^t__predefined_size_t(0))
**(**int32)(__ccgo_up(pBuf + 8)) += **(**int32)(__ccgo_up(bp + 160))
} else {
bTermWritten = libc.BoolInt32(!(bSecureDelete != 0))
iRowid = 0
iPrev = 0
iOff = 0
/* The entire doclist will not fit on this leaf. The following
** loop iterates through the poslists that make up the current
** doclist. */
for (*TFts5Index)(unsafe.Pointer(p)).Frc == SQLITE_OK && iOff < **(**int32)(__ccgo_up(bp + 160)) {
**(**Tu64)(__ccgo_up(bp + 168)) = uint64(0)
iOff = iOff + libc.Int32FromUint8(_sqlite3Fts5GetVarint(tls, **(**uintptr)(__ccgo_up(bp + 152))+uintptr(iOff), bp+168))
iRowid = libc.Int64FromUint64(uint64(iRowid) + **(**Tu64)(__ccgo_up(bp + 168)))
/* If in secure delete mode, and if this entry in the poslist is
** in fact a delete, then edit the existing segments directly
** using fts5FlushSecureDelete(). */
if bSecureDelete != 0 {
if eDetail == int32(FTS5_DETAIL_NONE) {
if iOff < **(**int32)(__ccgo_up(bp + 160)) && libc.Int32FromUint8(**(**Tu8)(__ccgo_up(**(**uintptr)(__ccgo_up(bp + 152)) + uintptr(iOff)))) == 0x00 && !(_fts5FlushSecureDelete(tls, p, **(**uintptr)(__ccgo_up(bp)), **(**uintptr)(__ccgo_up(bp + 136)), **(**int32)(__ccgo_up(bp + 144)), iRowid) != 0) {
iOff = iOff + 1
if iOff < **(**int32)(__ccgo_up(bp + 160)) && libc.Int32FromUint8(**(**Tu8)(__ccgo_up(**(**uintptr)(__ccgo_up(bp + 152)) + uintptr(iOff)))) == 0x00 {
iOff = iOff + 1
**(**int32)(__ccgo_up(bp + 160)) = 0
} else {
continue
}
}
} else {
if libc.Int32FromUint8(**(**Tu8)(__ccgo_up(**(**uintptr)(__ccgo_up(bp + 152)) + uintptr(iOff))))&int32(0x01) != 0 && !(_fts5FlushSecureDelete(tls, p, **(**uintptr)(__ccgo_up(bp)), **(**uintptr)(__ccgo_up(bp + 136)), **(**int32)(__ccgo_up(bp + 144)), iRowid) != 0) {
if (*TFts5Index)(unsafe.Pointer(p)).Frc != SQLITE_OK || libc.Int32FromUint8(**(**Tu8)(__ccgo_up(**(**uintptr)(__ccgo_up(bp + 152)) + uintptr(iOff)))) == int32(0x01) {
iOff = iOff + 1
continue
}
}
}
}
if (*TFts5Index)(unsafe.Pointer(p)).Frc == SQLITE_OK && bTermWritten == 0 {
_fts5WriteAppendTerm(tls, p, bp+16, **(**int32)(__ccgo_up(bp + 144)), **(**uintptr)(__ccgo_up(bp + 136)))
bTermWritten = int32(1)
}
if (**(**TFts5SegWriter)(__ccgo_up(bp + 16))).FbFirstRowidInPage != 0 {
_fts5PutU16(tls, (*TFts5Buffer)(unsafe.Pointer(pBuf)).Fp, libc.Uint16FromInt32((*TFts5Buffer)(unsafe.Pointer(pBuf)).Fn)) /* first rowid on page */
**(**int32)(__ccgo_up(pBuf + 8)) += _sqlite3Fts5PutVarint(tls, (*TFts5Buffer)(unsafe.Pointer(pBuf)).Fp+uintptr((*TFts5Buffer)(unsafe.Pointer(pBuf)).Fn), libc.Uint64FromInt64(iRowid))
(**(**TFts5SegWriter)(__ccgo_up(bp + 16))).FbFirstRowidInPage = uint8(0)
_fts5WriteDlidxAppend(tls, p, bp+16, iRowid)
} else {
iRowidDelta = libc.Uint64FromInt64(iRowid) - libc.Uint64FromInt64(iPrev)
**(**int32)(__ccgo_up(pBuf + 8)) += _sqlite3Fts5PutVarint(tls, (*TFts5Buffer)(unsafe.Pointer(pBuf)).Fp+uintptr((*TFts5Buffer)(unsafe.Pointer(pBuf)).Fn), iRowidDelta)
}
if (*TFts5Index)(unsafe.Pointer(p)).Frc != SQLITE_OK {
break
}
iPrev = iRowid
if eDetail == int32(FTS5_DETAIL_NONE) {
if iOff < **(**int32)(__ccgo_up(bp + 160)) && libc.Int32FromUint8(**(**Tu8)(__ccgo_up(**(**uintptr)(__ccgo_up(bp + 152)) + uintptr(iOff)))) == 0 {
v2 = pBuf + 8
v1 = *(*int32)(unsafe.Pointer(v2))
*(*int32)(unsafe.Pointer(v2)) = *(*int32)(unsafe.Pointer(v2)) + 1
**(**Tu8)(__ccgo_up((*TFts5Buffer)(unsafe.Pointer(pBuf)).Fp + uintptr(v1))) = uint8(0)
iOff = iOff + 1
if iOff < **(**int32)(__ccgo_up(bp + 160)) && libc.Int32FromUint8(**(**Tu8)(__ccgo_up(**(**uintptr)(__ccgo_up(bp + 152)) + uintptr(iOff)))) == 0 {
v2 = pBuf + 8
v1 = *(*int32)(unsafe.Pointer(v2))
*(*int32)(unsafe.Pointer(v2)) = *(*int32)(unsafe.Pointer(v2)) + 1
**(**Tu8)(__ccgo_up((*TFts5Buffer)(unsafe.Pointer(pBuf)).Fp + uintptr(v1))) = uint8(0)
iOff = iOff + 1
}
}
if (*TFts5Buffer)(unsafe.Pointer(pBuf)).Fn+(*TFts5Buffer)(unsafe.Pointer(pPgidx)).Fn >= pgsz {
_fts5WriteFlushLeaf(tls, p, bp+16)
}
} else {
**(**int32)(__ccgo_up(bp + 176)) = 0
**(**int32)(__ccgo_up(bp + 180)) = 0
nCopy = _fts5GetPoslistSize(tls, **(**uintptr)(__ccgo_up(bp + 152))+uintptr(iOff), bp+180, bp+176)
if **(**int32)(__ccgo_up(bp + 176)) != 0 && bSecureDelete != 0 {
_sqlite3Fts5BufferAppendVarint(tls, p+60, pBuf, int64(**(**int32)(__ccgo_up(bp + 180)))*int64(2))
iOff = iOff + nCopy
nCopy = **(**int32)(__ccgo_up(bp + 180))
} else {
nCopy = nCopy + **(**int32)(__ccgo_up(bp + 180))
}
if (*TFts5Buffer)(unsafe.Pointer(pBuf)).Fn+(*TFts5Buffer)(unsafe.Pointer(pPgidx)).Fn+nCopy <= pgsz {
/* The entire poslist will fit on the current leaf. So copy
** it in one go. */
libc.X__builtin___memcpy_chk(tls, (*TFts5Buffer)(unsafe.Pointer(pBuf)).Fp+uintptr((*TFts5Buffer)(unsafe.Pointer(pBuf)).Fn), **(**uintptr)(__ccgo_up(bp + 152))+uintptr(iOff), libc.Uint64FromInt32(nCopy), ^t__predefined_size_t(0))
**(**int32)(__ccgo_up(pBuf + 8)) += nCopy
} else {
/* The entire poslist will not fit on this leaf. So it needs
** to be broken into sections. The only qualification being
** that each varint must be stored contiguously. */
pPoslist = **(**uintptr)(__ccgo_up(bp + 152)) + uintptr(iOff)
iPos = 0
for (*TFts5Index)(unsafe.Pointer(p)).Frc == SQLITE_OK {
nSpace = pgsz - (*TFts5Buffer)(unsafe.Pointer(pBuf)).Fn - (*TFts5Buffer)(unsafe.Pointer(pPgidx)).Fn
n = 0
if nCopy-iPos <= nSpace {
n = nCopy - iPos
} else {
n = _fts5PoslistPrefix(tls, pPoslist+uintptr(iPos), nSpace)
}
libc.X__builtin___memcpy_chk(tls, (*TFts5Buffer)(unsafe.Pointer(pBuf)).Fp+uintptr((*TFts5Buffer)(unsafe.Pointer(pBuf)).Fn), pPoslist+uintptr(iPos), libc.Uint64FromInt32(n), ^t__predefined_size_t(0))
**(**int32)(__ccgo_up(pBuf + 8)) += n
iPos = iPos + n
if (*TFts5Buffer)(unsafe.Pointer(pBuf)).Fn+(*TFts5Buffer)(unsafe.Pointer(pPgidx)).Fn >= pgsz {
_fts5WriteFlushLeaf(tls, p, bp+16)
}
if iPos >= nCopy {
break
}
}
}
iOff = iOff + nCopy
}
}
}
/* TODO2: Doclist terminator written here. */
/* pBuf->p[pBuf->n++] = '\0'; */
if (*TFts5Index)(unsafe.Pointer(p)).Frc == SQLITE_OK {
_sqlite3Fts5HashScanNext(tls, pHash)
}
}
_fts5WriteFinish(tls, p, bp+16, bp+8)
if **(**int32)(__ccgo_up(bp + 8)) > 0 {
/* Update the Fts5Structure. It is written back to the database by the
** fts5StructureRelease() call below. */
if (*TFts5Structure)(unsafe.Pointer(**(**uintptr)(__ccgo_up(bp)))).FnLevel == 0 {
_fts5StructureAddLevel(tls, p+60, bp)
}
_fts5StructureExtendLevel(tls, p+60, **(**uintptr)(__ccgo_up(bp)), 0, int32(1), 0)
if (*TFts5Index)(unsafe.Pointer(p)).Frc == SQLITE_OK {
v2 = **(**uintptr)(__ccgo_up(bp)) + 32 + 4
v1 = *(*int32)(unsafe.Pointer(v2))
*(*int32)(unsafe.Pointer(v2)) = *(*int32)(unsafe.Pointer(v2)) + 1
pSeg = (*(*TFts5StructureLevel)(unsafe.Pointer(**(**uintptr)(__ccgo_up(bp)) + 32))).FaSeg + uintptr(v1)*56
(*TFts5StructureSegment)(unsafe.Pointer(pSeg)).FiSegid = iSegid
(*TFts5StructureSegment)(unsafe.Pointer(pSeg)).FpgnoFirst = int32(1)
(*TFts5StructureSegment)(unsafe.Pointer(pSeg)).FpgnoLast = **(**int32)(__ccgo_up(bp + 8))
if (*TFts5Structure)(unsafe.Pointer(**(**uintptr)(__ccgo_up(bp)))).FnOriginCntr > uint64(0) {
(*TFts5StructureSegment)(unsafe.Pointer(pSeg)).FiOrigin1 = (*TFts5Structure)(unsafe.Pointer(**(**uintptr)(__ccgo_up(bp)))).FnOriginCntr
(*TFts5StructureSegment)(unsafe.Pointer(pSeg)).FiOrigin2 = (*TFts5Structure)(unsafe.Pointer(**(**uintptr)(__ccgo_up(bp)))).FnOriginCntr
(*TFts5StructureSegment)(unsafe.Pointer(pSeg)).FnEntry = libc.Uint64FromInt32((*TFts5Index)(unsafe.Pointer(p)).FnPendingRow)
(*TFts5Structure)(unsafe.Pointer(**(**uintptr)(__ccgo_up(bp)))).FnOriginCntr = (*TFts5Structure)(unsafe.Pointer(**(**uintptr)(__ccgo_up(bp)))).FnOriginCntr + 1
}
(*TFts5Structure)(unsafe.Pointer(**(**uintptr)(__ccgo_up(bp)))).FnSegment = (*TFts5Structure)(unsafe.Pointer(**(**uintptr)(__ccgo_up(bp)))).FnSegment + 1
}
_fts5StructurePromote(tls, p, 0, **(**uintptr)(__ccgo_up(bp)))
}
}
}
_fts5IndexAutomerge(tls, p, bp, **(**int32)(__ccgo_up(bp + 8))+(*TFts5Index)(unsafe.Pointer(p)).FnContentlessDelete)
_fts5IndexCrisismerge(tls, p, bp)
_fts5StructureWrite(tls, p, **(**uintptr)(__ccgo_up(bp)))
_fts5StructureRelease(tls, **(**uintptr)(__ccgo_up(bp)))
}
// C documentation
//
// /*
// ** This is called as part of flushing a delete to disk in 'secure-delete'
// ** mode. It edits the segments within the database described by argument
// ** pStruct to remove the entries for term zTerm, rowid iRowid.
// **
// ** Return SQLITE_OK if successful, or an SQLite error code if an error
// ** has occurred. Any error code is also stored in the Fts5Index handle.
// */
func _fts5FlushSecureDelete(tls *libc.TLS, p uintptr, pStruct uintptr, zTerm uintptr, nTerm int32, iRowid Ti64) (r int32) {
bp := tls.Alloc(48)
defer tls.Free(48)
var f, rc int32
var iThis Ti64
var pConfig, pSeg uintptr
var _ /* pIter at bp+0 */ uintptr
var _ /* pStmt at bp+8 */ uintptr
_, _, _, _, _ = f, iThis, pConfig, pSeg, rc
f = int32(FTS5INDEX_QUERY_SKIPHASH)
**(**uintptr)(__ccgo_up(bp)) = uintptr(0) /* Used to find term instance */
/* If the version number has not been set to SECUREDELETE, do so now. */
if (*TFts5Config)(unsafe.Pointer((*TFts5Index)(unsafe.Pointer(p)).FpConfig)).FiVersion != int32(FTS5_CURRENT_VERSION_SECUREDELETE) {
pConfig = (*TFts5Index)(unsafe.Pointer(p)).FpConfig
**(**uintptr)(__ccgo_up(bp + 8)) = uintptr(0)
_fts5IndexPrepareStmt(tls, p, bp+8, Xsqlite3_mprintf(tls, __ccgo_ts+39835, libc.VaList(bp+24, (*TFts5Config)(unsafe.Pointer(pConfig)).FzDb, (*TFts5Config)(unsafe.Pointer(pConfig)).FzName, int32(FTS5_CURRENT_VERSION_SECUREDELETE))))
if (*TFts5Index)(unsafe.Pointer(p)).Frc == SQLITE_OK {
Xsqlite3_step(tls, **(**uintptr)(__ccgo_up(bp + 8)))
rc = Xsqlite3_finalize(tls, **(**uintptr)(__ccgo_up(bp + 8)))
if (*TFts5Index)(unsafe.Pointer(p)).Frc == SQLITE_OK {
(*TFts5Index)(unsafe.Pointer(p)).Frc = rc
}
(*TFts5Config)(unsafe.Pointer(pConfig)).FiCookie = (*TFts5Config)(unsafe.Pointer(pConfig)).FiCookie + 1
(*TFts5Config)(unsafe.Pointer(pConfig)).FiVersion = int32(FTS5_CURRENT_VERSION_SECUREDELETE)
}
}
_fts5MultiIterNew(tls, p, pStruct, f, uintptr(0), zTerm, nTerm, -int32(1), 0, bp)
if _fts5MultiIterEof(tls, p, **(**uintptr)(__ccgo_up(bp))) == 0 {
iThis = _fts5MultiIterRowid(tls, **(**uintptr)(__ccgo_up(bp)))
if iThis < iRowid {
_fts5MultiIterNextFrom(tls, p, **(**uintptr)(__ccgo_up(bp)), iRowid)
}
if (*TFts5Index)(unsafe.Pointer(p)).Frc == SQLITE_OK && _fts5MultiIterEof(tls, p, **(**uintptr)(__ccgo_up(bp))) == 0 && iRowid == _fts5MultiIterRowid(tls, **(**uintptr)(__ccgo_up(bp))) {
pSeg = **(**uintptr)(__ccgo_up(bp)) + 104 + uintptr((**(**TFts5CResult)(__ccgo_up((*TFts5Iter)(unsafe.Pointer(**(**uintptr)(__ccgo_up(bp)))).FaFirst + 1*4))).FiFirst)*128
_fts5DoSecureDelete(tls, p, pSeg)
}
}
_fts5MultiIterFree(tls, **(**uintptr)(__ccgo_up(bp)))
return (*TFts5Index)(unsafe.Pointer(p)).Frc
}
func _fts5FreeCursorComponents(tls *libc.TLS, pCsr uintptr) {
var eStmt int32
var pData, pNext, pSorter, pTab uintptr
_, _, _, _, _ = eStmt, pData, pNext, pSorter, pTab
pTab = (*TFts5Cursor)(unsafe.Pointer(pCsr)).Fbase.FpVtab
Xsqlite3_free(tls, (*TFts5Cursor)(unsafe.Pointer(pCsr)).FaInstIter)
Xsqlite3_free(tls, (*TFts5Cursor)(unsafe.Pointer(pCsr)).FaInst)
if (*TFts5Cursor)(unsafe.Pointer(pCsr)).FpStmt != 0 {
eStmt = _fts5StmtType(tls, pCsr)
_sqlite3Fts5StorageStmtRelease(tls, (*TFts5FullTable)(unsafe.Pointer(pTab)).FpStorage, eStmt, (*TFts5Cursor)(unsafe.Pointer(pCsr)).FpStmt)
}
if (*TFts5Cursor)(unsafe.Pointer(pCsr)).FpSorter != 0 {
pSorter = (*TFts5Cursor)(unsafe.Pointer(pCsr)).FpSorter
Xsqlite3_finalize(tls, (*TFts5Sorter)(unsafe.Pointer(pSorter)).FpStmt)
Xsqlite3_free(tls, pSorter)
}
if (*TFts5Cursor)(unsafe.Pointer(pCsr)).FePlan != int32(FTS5_PLAN_SOURCE) {
_sqlite3Fts5ExprFree(tls, (*TFts5Cursor)(unsafe.Pointer(pCsr)).FpExpr)
}
pData = (*TFts5Cursor)(unsafe.Pointer(pCsr)).FpAuxdata
for {
if !(pData != 0) {
break
}
pNext = (*TFts5Auxdata)(unsafe.Pointer(pData)).FpNext
if (*TFts5Auxdata)(unsafe.Pointer(pData)).FxDelete != 0 {
(*(*func(*libc.TLS, uintptr))(unsafe.Pointer(&struct{ uintptr }{(*TFts5Auxdata)(unsafe.Pointer(pData)).FxDelete})))(tls, (*TFts5Auxdata)(unsafe.Pointer(pData)).FpPtr)
}
Xsqlite3_free(tls, pData)
goto _1
_1:
;
pData = pNext
}
Xsqlite3_finalize(tls, (*TFts5Cursor)(unsafe.Pointer(pCsr)).FpRankArgStmt)
Xsqlite3_free(tls, (*TFts5Cursor)(unsafe.Pointer(pCsr)).FapRankArg)
if (*TFts5Cursor)(unsafe.Pointer(pCsr)).Fcsrflags&int32(FTS5CSR_FREE_ZRANK) != 0 {
Xsqlite3_free(tls, (*TFts5Cursor)(unsafe.Pointer(pCsr)).FzRank)
Xsqlite3_free(tls, (*TFts5Cursor)(unsafe.Pointer(pCsr)).FzRankArgs)
}
_sqlite3Fts5IndexCloseReader(tls, (*TFts5FullTable)(unsafe.Pointer(pTab)).Fp.FpIndex)
libc.X__builtin___memset_chk(tls, pCsr+32, 0, uint64(184)-libc.Uint64FromInt64(int64(pCsr+32)-int64(pCsr)), ^t__predefined_size_t(0))
}
// C documentation
//
// /*
// ** Implementation of the fts5() function used by clients to obtain the
// ** API pointer.
// */
func _fts5Fts5Func(tls *libc.TLS, pCtx uintptr, nArg int32, apArg uintptr) {
var pGlobal, ppApi uintptr
_, _ = pGlobal, ppApi
pGlobal = Xsqlite3_user_data(tls, pCtx)
_ = nArg
ppApi = Xsqlite3_value_pointer(tls, **(**uintptr)(__ccgo_up(apArg)), __ccgo_ts+40885)
if ppApi != 0 {
**(**uintptr)(__ccgo_up(ppApi)) = pGlobal
}
}
// C documentation
//
// /*
// ** Implementation of fts5_get_locale() function.
// */
func _fts5GetLocaleFunction(tls *libc.TLS, pApi uintptr, pFts uintptr, pCtx uintptr, nVal int32, apVal uintptr) {
bp := tls.Alloc(16)
defer tls.Free(16)
var eType, iCol, rc int32
var z, z1 uintptr
var _ /* nLocale at bp+8 */ int32
var _ /* zLocale at bp+0 */ uintptr
_, _, _, _, _ = eType, iCol, rc, z, z1
iCol = 0
eType = 0
rc = SQLITE_OK
**(**uintptr)(__ccgo_up(bp)) = uintptr(0)
**(**int32)(__ccgo_up(bp + 8)) = 0
/* xColumnLocale() must be available */
if nVal != int32(1) {
z = __ccgo_ts + 37643
Xsqlite3_result_error(tls, pCtx, z, -int32(1))
return
}
eType = Xsqlite3_value_numeric_type(tls, **(**uintptr)(__ccgo_up(apVal)))
if eType != int32(SQLITE_INTEGER) {
z1 = __ccgo_ts + 37699
Xsqlite3_result_error(tls, pCtx, z1, -int32(1))
return
}
iCol = Xsqlite3_value_int(tls, **(**uintptr)(__ccgo_up(apVal)))
if iCol < 0 || iCol >= (*(*func(*libc.TLS, uintptr) int32)(unsafe.Pointer(&struct{ uintptr }{(*TFts5ExtensionApi)(unsafe.Pointer(pApi)).FxColumnCount})))(tls, pFts) {
Xsqlite3_result_error_code(tls, pCtx, int32(SQLITE_RANGE))
return
}
rc = (*(*func(*libc.TLS, uintptr, int32, uintptr, uintptr) int32)(unsafe.Pointer(&struct{ uintptr }{(*TFts5ExtensionApi)(unsafe.Pointer(pApi)).FxColumnLocale})))(tls, pFts, iCol, bp, bp+8)
if rc != SQLITE_OK {
Xsqlite3_result_error_code(tls, pCtx, rc)
return
}
Xsqlite3_result_text(tls, pCtx, **(**uintptr)(__ccgo_up(bp)), **(**int32)(__ccgo_up(bp + 8)), uintptr(-libc.Int32FromInt32(1)))
}
func _fts5HashAddPoslistSize(tls *libc.TLS, pHash uintptr, p uintptr, p2 uintptr) (r int32) {
var nByte, nData, nPos, nRet, nSz, v2 int32
var pPtr, v1 uintptr
_, _, _, _, _, _, _, _ = nByte, nData, nPos, nRet, nSz, pPtr, v1, v2
nRet = 0
if (*TFts5HashEntry)(unsafe.Pointer(p)).FiSzPoslist != 0 {
if p2 != 0 {
v1 = p2
} else {
v1 = p
}
pPtr = v1
nData = (*TFts5HashEntry)(unsafe.Pointer(p)).FnData
if (*TFts5Hash)(unsafe.Pointer(pHash)).FeDetail == int32(FTS5_DETAIL_NONE) {
if (*TFts5HashEntry)(unsafe.Pointer(p)).FbDel != 0 {
v2 = nData
nData = nData + 1
**(**Tu8)(__ccgo_up(pPtr + uintptr(v2))) = uint8(0x00)
if (*TFts5HashEntry)(unsafe.Pointer(p)).FbContent != 0 {
v2 = nData
nData = nData + 1
**(**Tu8)(__ccgo_up(pPtr + uintptr(v2))) = uint8(0x00)
}
}
} else {
nSz = nData - (*TFts5HashEntry)(unsafe.Pointer(p)).FiSzPoslist - int32(1) /* Size in bytes */
nPos = nSz*int32(2) + libc.Int32FromUint8((*TFts5HashEntry)(unsafe.Pointer(p)).FbDel) /* Value of nPos field */
if nPos <= int32(127) {
**(**Tu8)(__ccgo_up(pPtr + uintptr((*TFts5HashEntry)(unsafe.Pointer(p)).FiSzPoslist))) = libc.Uint8FromInt32(nPos)
} else {
nByte = _sqlite3Fts5GetVarintLen(tls, libc.Uint32FromInt32(nPos))
libc.X__builtin___memmove_chk(tls, pPtr+uintptr((*TFts5HashEntry)(unsafe.Pointer(p)).FiSzPoslist+nByte), pPtr+uintptr((*TFts5HashEntry)(unsafe.Pointer(p)).FiSzPoslist+int32(1)), libc.Uint64FromInt32(nSz), ^t__predefined_size_t(0))
_sqlite3Fts5PutVarint(tls, pPtr+uintptr((*TFts5HashEntry)(unsafe.Pointer(p)).FiSzPoslist), libc.Uint64FromInt32(nPos))
nData = nData + (nByte - int32(1))
}
}
nRet = nData - (*TFts5HashEntry)(unsafe.Pointer(p)).FnData
if p2 == uintptr(0) {
(*TFts5HashEntry)(unsafe.Pointer(p)).FiSzPoslist = 0
(*TFts5HashEntry)(unsafe.Pointer(p)).FbDel = uint8(0)
(*TFts5HashEntry)(unsafe.Pointer(p)).FbContent = uint8(0)
(*TFts5HashEntry)(unsafe.Pointer(p)).FnData = nData
}
}
return nRet
}
// C documentation
//
// /*
// ** Link all tokens from hash table iHash into a list in sorted order. The
// ** tokens are not removed from the hash table.
// */
func _fts5HashEntrySort(tls *libc.TLS, pHash uintptr, pTerm uintptr, nTerm int32, ppSorted uintptr) (r int32) {
var ap, pEntry, pIter, pList uintptr
var i, iSlot, nMergeSlot int32
_, _, _, _, _, _, _ = ap, i, iSlot, nMergeSlot, pEntry, pIter, pList
nMergeSlot = int32(32)
**(**uintptr)(__ccgo_up(ppSorted)) = uintptr(0)
ap = Xsqlite3_malloc64(tls, uint64(uint64(8)*libc.Uint64FromInt32(nMergeSlot)))
if !(ap != 0) {
return int32(SQLITE_NOMEM)
}
libc.X__builtin___memset_chk(tls, ap, 0, uint64(8)*libc.Uint64FromInt32(nMergeSlot), ^t__predefined_size_t(0))
iSlot = 0
for {
if !(iSlot < (*TFts5Hash)(unsafe.Pointer(pHash)).FnSlot) {
break
}
pIter = **(**uintptr)(__ccgo_up((*TFts5Hash)(unsafe.Pointer(pHash)).FaSlot + uintptr(iSlot)*8))
for {
if !(pIter != 0) {
break
}
if pTerm == uintptr(0) || (*TFts5HashEntry)(unsafe.Pointer(pIter)).FnKey >= nTerm && 0 == libc.Xmemcmp(tls, pIter+1*48, pTerm, libc.Uint64FromInt32(nTerm)) {
pEntry = pIter
(*TFts5HashEntry)(unsafe.Pointer(pEntry)).FpScanNext = uintptr(0)
i = 0
for {
if !(**(**uintptr)(__ccgo_up(ap + uintptr(i)*8)) != 0) {
break
}
pEntry = _fts5HashEntryMerge(tls, pEntry, **(**uintptr)(__ccgo_up(ap + uintptr(i)*8)))
**(**uintptr)(__ccgo_up(ap + uintptr(i)*8)) = uintptr(0)
goto _3
_3:
;
i = i + 1
}
**(**uintptr)(__ccgo_up(ap + uintptr(i)*8)) = pEntry
}
goto _2
_2:
;
pIter = (*TFts5HashEntry)(unsafe.Pointer(pIter)).FpHashNext
}
goto _1
_1:
;
iSlot = iSlot + 1
}
pList = uintptr(0)
i = 0
for {
if !(i < nMergeSlot) {
break
}
pList = _fts5HashEntryMerge(tls, pList, **(**uintptr)(__ccgo_up(ap + uintptr(i)*8)))
goto _4
_4:
;
i = i + 1
}
Xsqlite3_free(tls, ap)
**(**uintptr)(__ccgo_up(ppSorted)) = pList
return SQLITE_OK
}
// C documentation
//
// /*
// ** Resize the hash table by doubling the number of slots.
// */
func _fts5HashResize(tls *libc.TLS, pHash uintptr) (r int32) {
var apNew, apOld, p uintptr
var i, nNew int32
var iHash uint32
_, _, _, _, _, _ = apNew, apOld, i, iHash, nNew, p
nNew = (*TFts5Hash)(unsafe.Pointer(pHash)).FnSlot * int32(2)
apOld = (*TFts5Hash)(unsafe.Pointer(pHash)).FaSlot
apNew = Xsqlite3_malloc64(tls, uint64(libc.Uint64FromInt32(nNew)*uint64(8)))
if !(apNew != 0) {
return int32(SQLITE_NOMEM)
}
libc.X__builtin___memset_chk(tls, apNew, 0, libc.Uint64FromInt32(nNew)*uint64(8), ^t__predefined_size_t(0))
i = 0
for {
if !(i < (*TFts5Hash)(unsafe.Pointer(pHash)).FnSlot) {
break
}
for **(**uintptr)(__ccgo_up(apOld + uintptr(i)*8)) != 0 {
p = **(**uintptr)(__ccgo_up(apOld + uintptr(i)*8))
**(**uintptr)(__ccgo_up(apOld + uintptr(i)*8)) = (*TFts5HashEntry)(unsafe.Pointer(p)).FpHashNext
iHash = _fts5HashKey(tls, nNew, p+1*48, (*TFts5HashEntry)(unsafe.Pointer(p)).FnKey)
(*TFts5HashEntry)(unsafe.Pointer(p)).FpHashNext = **(**uintptr)(__ccgo_up(apNew + uintptr(iHash)*8))
**(**uintptr)(__ccgo_up(apNew + uintptr(iHash)*8)) = p
}
goto _1
_1:
;
i = i + 1
}
Xsqlite3_free(tls, apOld)
(*TFts5Hash)(unsafe.Pointer(pHash)).FnSlot = nNew
(*TFts5Hash)(unsafe.Pointer(pHash)).FaSlot = apNew
return SQLITE_OK
}
// C documentation
//
// /*
// ** Append text to the HighlightContext output string - p->zOut. Argument
// ** z points to a buffer containing n bytes of text to append. If n is
// ** negative, everything up until the first '\0' is appended to the output.
// **
// ** If *pRc is set to any value other than SQLITE_OK when this function is
// ** called, it is a no-op. If an error (i.e. an OOM condition) is encountered,
// ** *pRc is set to an error code before returning.
// */
func _fts5HighlightAppend(tls *libc.TLS, pRc uintptr, p uintptr, z uintptr, n int32) {
bp := tls.Alloc(32)
defer tls.Free(32)
if **(**int32)(__ccgo_up(pRc)) == SQLITE_OK && z != 0 {
if n < 0 {
n = libc.Int32FromUint64(libc.Xstrlen(tls, z))
}
(*THighlightContext)(unsafe.Pointer(p)).FzOut = Xsqlite3_mprintf(tls, __ccgo_ts+37538, libc.VaList(bp+8, (*THighlightContext)(unsafe.Pointer(p)).FzOut, n, z))
if (*THighlightContext)(unsafe.Pointer(p)).FzOut == uintptr(0) {
**(**int32)(__ccgo_up(pRc)) = int32(SQLITE_NOMEM)
}
}
}
// C documentation
//
// /*
// ** Implementation of highlight() function.
// */
func _fts5HighlightFunction(tls *libc.TLS, pApi uintptr, pFts uintptr, pCtx uintptr, nVal int32, apVal uintptr) {
bp := tls.Alloc(128)
defer tls.Free(128)
var iCol int32
var zErr uintptr
var _ /* ctx at bp+0 */ THighlightContext
var _ /* nLoc at bp+120 */ int32
var _ /* pLoc at bp+112 */ uintptr
var _ /* rc at bp+104 */ int32
_, _ = iCol, zErr
if nVal != int32(3) {
zErr = __ccgo_ts + 37545
Xsqlite3_result_error(tls, pCtx, zErr, -int32(1))
return
}
iCol = Xsqlite3_value_int(tls, **(**uintptr)(__ccgo_up(apVal)))
libc.X__builtin___memset_chk(tls, bp, 0, uint64(104), ^t__predefined_size_t(0))
(**(**THighlightContext)(__ccgo_up(bp))).FzOpen = Xsqlite3_value_text(tls, **(**uintptr)(__ccgo_up(apVal + 1*8)))
(**(**THighlightContext)(__ccgo_up(bp))).FzClose = Xsqlite3_value_text(tls, **(**uintptr)(__ccgo_up(apVal + 2*8)))
(**(**THighlightContext)(__ccgo_up(bp))).FiRangeEnd = -int32(1)
**(**int32)(__ccgo_up(bp + 104)) = (*(*func(*libc.TLS, uintptr, int32, uintptr, uintptr) int32)(unsafe.Pointer(&struct{ uintptr }{(*TFts5ExtensionApi)(unsafe.Pointer(pApi)).FxColumnText})))(tls, pFts, iCol, bp+24, bp+32)
if **(**int32)(__ccgo_up(bp + 104)) == int32(SQLITE_RANGE) {
Xsqlite3_result_text(tls, pCtx, __ccgo_ts+1702, -int32(1), libc.UintptrFromInt32(0))
**(**int32)(__ccgo_up(bp + 104)) = SQLITE_OK
} else {
if (**(**THighlightContext)(__ccgo_up(bp))).FzIn != 0 {
**(**uintptr)(__ccgo_up(bp + 112)) = uintptr(0) /* Locale of column iCol */
**(**int32)(__ccgo_up(bp + 120)) = 0 /* Size of pLoc in bytes */
if **(**int32)(__ccgo_up(bp + 104)) == SQLITE_OK {
**(**int32)(__ccgo_up(bp + 104)) = _fts5CInstIterInit(tls, pApi, pFts, iCol, bp+40)
}
if **(**int32)(__ccgo_up(bp + 104)) == SQLITE_OK {
**(**int32)(__ccgo_up(bp + 104)) = (*(*func(*libc.TLS, uintptr, int32, uintptr, uintptr) int32)(unsafe.Pointer(&struct{ uintptr }{(*TFts5ExtensionApi)(unsafe.Pointer(pApi)).FxColumnLocale})))(tls, pFts, iCol, bp+112, bp+120)
}
if **(**int32)(__ccgo_up(bp + 104)) == SQLITE_OK {
**(**int32)(__ccgo_up(bp + 104)) = (*(*func(*libc.TLS, uintptr, uintptr, int32, uintptr, int32, uintptr, uintptr) int32)(unsafe.Pointer(&struct{ uintptr }{(*TFts5ExtensionApi)(unsafe.Pointer(pApi)).FxTokenize_v2})))(tls, pFts, (**(**THighlightContext)(__ccgo_up(bp))).FzIn, (**(**THighlightContext)(__ccgo_up(bp))).FnIn, **(**uintptr)(__ccgo_up(bp + 112)), **(**int32)(__ccgo_up(bp + 120)), bp, __ccgo_fp(_fts5HighlightCb))
}
if (**(**THighlightContext)(__ccgo_up(bp))).FbOpen != 0 {
_fts5HighlightAppend(tls, bp+104, bp, (**(**THighlightContext)(__ccgo_up(bp))).FzClose, -int32(1))
}
_fts5HighlightAppend(tls, bp+104, bp, (**(**THighlightContext)(__ccgo_up(bp))).FzIn+uintptr((**(**THighlightContext)(__ccgo_up(bp))).FiOff), (**(**THighlightContext)(__ccgo_up(bp))).FnIn-(**(**THighlightContext)(__ccgo_up(bp))).FiOff)
if **(**int32)(__ccgo_up(bp + 104)) == SQLITE_OK {
Xsqlite3_result_text(tls, pCtx, (**(**THighlightContext)(__ccgo_up(bp))).FzOut, -int32(1), uintptr(-libc.Int32FromInt32(1)))
}
Xsqlite3_free(tls, (**(**THighlightContext)(__ccgo_up(bp))).FzOut)
}
}
if **(**int32)(__ccgo_up(bp + 104)) != SQLITE_OK {
Xsqlite3_result_error_code(tls, pCtx, **(**int32)(__ccgo_up(bp + 104)))
}
}
/*
** End of highlight() implementation.
**************************************************************************/
// C documentation
//
// /*
// ** SQL used by fts5SegIterNextInit() to find the page to open.
// */
func _fts5IdxNextStmt(tls *libc.TLS, p uintptr) (r uintptr) {
bp := tls.Alloc(32)
defer tls.Free(32)
var pConfig uintptr
_ = pConfig
if (*TFts5Index)(unsafe.Pointer(p)).FpIdxNextSelect == uintptr(0) {
pConfig = (*TFts5Index)(unsafe.Pointer(p)).FpConfig
_fts5IndexPrepareStmt(tls, p, p+120, Xsqlite3_mprintf(tls, __ccgo_ts+39635, libc.VaList(bp+8, (*TFts5Config)(unsafe.Pointer(pConfig)).FzDb, (*TFts5Config)(unsafe.Pointer(pConfig)).FzName)))
}
return (*TFts5Index)(unsafe.Pointer(p)).FpIdxNextSelect
}
func _fts5IdxSelectStmt(tls *libc.TLS, p uintptr) (r uintptr) {
bp := tls.Alloc(32)
defer tls.Free(32)
var pConfig uintptr
_ = pConfig
if (*TFts5Index)(unsafe.Pointer(p)).FpIdxSelect == uintptr(0) {
pConfig = (*TFts5Index)(unsafe.Pointer(p)).FpConfig
_fts5IndexPrepareStmt(tls, p, p+112, Xsqlite3_mprintf(tls, __ccgo_ts+39551, libc.VaList(bp+8, (*TFts5Config)(unsafe.Pointer(pConfig)).FzDb, (*TFts5Config)(unsafe.Pointer(pConfig)).FzName)))
}
return (*TFts5Index)(unsafe.Pointer(p)).FpIdxSelect
}
func _fts5IndexCorruptIdx(tls *libc.TLS, pIdx uintptr) (r int32) {
bp := tls.Alloc(16)
defer tls.Free(16)
(*TFts5Index)(unsafe.Pointer(pIdx)).Frc = libc.Int32FromInt32(SQLITE_CORRUPT) | libc.Int32FromInt32(1)<base.pData/nData to point to the new position list.
// ** If memory is required for the new position list, use buffer pIter->poslist.
// ** Or, if the new position list is a contiguous subset of the input, set
// ** pIter->base.pData/nData to point directly to it.
// **
// ** This function is a no-op if *pRc is other than SQLITE_OK when it is
// ** called. If an OOM error is encountered, *pRc is set to SQLITE_NOMEM
// ** before returning.
// */
func _fts5IndexExtractColset(tls *libc.TLS, pRc uintptr, pColset uintptr, pPos uintptr, nPos int32, pIter uintptr) {
bp := tls.Alloc(16)
defer tls.Free(16)
var aCopy, p, pEnd, v1 uintptr
var i int32
var v2 bool
var _ /* iCurrent at bp+0 */ int32
_, _, _, _, _, _ = aCopy, i, p, pEnd, v1, v2
if **(**int32)(__ccgo_up(pRc)) == SQLITE_OK {
p = pPos
aCopy = p
pEnd = p + uintptr(nPos) /* One byte past end of position list */
i = 0
**(**int32)(__ccgo_up(bp)) = 0
if (*TFts5Colset)(unsafe.Pointer(pColset)).FnCol > int32(1) && _sqlite3Fts5BufferSize(tls, pRc, pIter+40, libc.Uint32FromInt32(nPos)) != 0 {
return
}
for int32(1) != 0 {
for *(*int32)(unsafe.Pointer(pColset + 4 + uintptr(i)*4)) < **(**int32)(__ccgo_up(bp)) {
i = i + 1
if i == (*TFts5Colset)(unsafe.Pointer(pColset)).FnCol {
(*TFts5Iter)(unsafe.Pointer(pIter)).Fbase.FpData = (*TFts5Iter)(unsafe.Pointer(pIter)).Fposlist.Fp
(*TFts5Iter)(unsafe.Pointer(pIter)).Fbase.FnData = (*TFts5Iter)(unsafe.Pointer(pIter)).Fposlist.Fn
return
}
}
/* Advance pointer p until it points to pEnd or an 0x01 byte that is
** not part of a varint */
for p < pEnd && libc.Int32FromUint8(**(**Tu8)(__ccgo_up(p))) != int32(0x01) {
for {
if v2 = p < pEnd; v2 {
v1 = p
p = p + 1
}
if !(v2 && libc.Int32FromUint8(**(**Tu8)(__ccgo_up(v1)))&int32(0x80) != 0) {
break
}
}
}
if *(*int32)(unsafe.Pointer(pColset + 4 + uintptr(i)*4)) == **(**int32)(__ccgo_up(bp)) {
if (*TFts5Colset)(unsafe.Pointer(pColset)).FnCol == int32(1) {
(*TFts5Iter)(unsafe.Pointer(pIter)).Fbase.FpData = aCopy
(*TFts5Iter)(unsafe.Pointer(pIter)).Fbase.FnData = int32(int64(p) - int64(aCopy))
return
}
libc.X__builtin___memcpy_chk(tls, (*TFts5Buffer)(unsafe.Pointer(pIter+40)).Fp+uintptr((*TFts5Buffer)(unsafe.Pointer(pIter+40)).Fn), aCopy, libc.Uint64FromInt64(int64(p)-int64(aCopy)), ^t__predefined_size_t(0))
v1 = pIter + 40 + 8
*(*int32)(unsafe.Pointer(v1)) = int32(int64(*(*int32)(unsafe.Pointer(v1))) + (int64(p) - int64(aCopy)))
}
if p >= pEnd {
(*TFts5Iter)(unsafe.Pointer(pIter)).Fbase.FpData = (*TFts5Iter)(unsafe.Pointer(pIter)).Fposlist.Fp
(*TFts5Iter)(unsafe.Pointer(pIter)).Fbase.FnData = (*TFts5Iter)(unsafe.Pointer(pIter)).Fposlist.Fn
return
}
v1 = p
p = p + 1
aCopy = v1
v1 = p
p = p + 1
**(**int32)(__ccgo_up(bp)) = libc.Int32FromUint8(**(**Tu8)(__ccgo_up(v1)))
if **(**int32)(__ccgo_up(bp))&int32(0x80) != 0 {
p = p - 1
p = p + uintptr(_sqlite3Fts5GetVarint32(tls, p, bp))
}
}
}
}
func _fts5IndexIntegrityCheckSegment(tls *libc.TLS, p uintptr, pSeg uintptr) {
bp := tls.Alloc(64)
defer tls.Free(64)
var bIdxDlidx, bSecureDelete, iDlidxPrevLeaf, iIdxLeaf, iIdxPrevLeaf, iOff, iPg, iPrevLeaf, iRowidOff, iRowidOff1, iSegid, nIdxTerm, rc2, res, v1, v2, v3 int32
var iDlRowid, iKey, iRow Ti64
var pConfig, pDlidx, pLeaf, zIdxTerm uintptr
var _ /* iRowid at bp+16 */ Ti64
var _ /* nTerm at bp+8 */ int32
var _ /* pStmt at bp+0 */ uintptr
_, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _ = bIdxDlidx, bSecureDelete, iDlRowid, iDlidxPrevLeaf, iIdxLeaf, iIdxPrevLeaf, iKey, iOff, iPg, iPrevLeaf, iRow, iRowidOff, iRowidOff1, iSegid, nIdxTerm, pConfig, pDlidx, pLeaf, rc2, res, zIdxTerm, v1, v2, v3
pConfig = (*TFts5Index)(unsafe.Pointer(p)).FpConfig
bSecureDelete = libc.BoolInt32((*TFts5Config)(unsafe.Pointer(pConfig)).FiVersion == int32(FTS5_CURRENT_VERSION_SECUREDELETE))
**(**uintptr)(__ccgo_up(bp)) = uintptr(0)
iIdxPrevLeaf = (*TFts5StructureSegment)(unsafe.Pointer(pSeg)).FpgnoFirst - int32(1)
iDlidxPrevLeaf = (*TFts5StructureSegment)(unsafe.Pointer(pSeg)).FpgnoLast
if (*TFts5StructureSegment)(unsafe.Pointer(pSeg)).FpgnoFirst == 0 {
return
}
_fts5IndexPrepareStmt(tls, p, bp, Xsqlite3_mprintf(tls, __ccgo_ts+39975, libc.VaList(bp+32, (*TFts5Config)(unsafe.Pointer(pConfig)).FzDb, (*TFts5Config)(unsafe.Pointer(pConfig)).FzName, (*TFts5StructureSegment)(unsafe.Pointer(pSeg)).FiSegid)))
/* Iterate through the b-tree hierarchy. */
for (*TFts5Index)(unsafe.Pointer(p)).Frc == SQLITE_OK && int32(SQLITE_ROW) == Xsqlite3_step(tls, **(**uintptr)(__ccgo_up(bp))) { /* Data for this leaf */
zIdxTerm = Xsqlite3_column_blob(tls, **(**uintptr)(__ccgo_up(bp)), int32(1))
nIdxTerm = Xsqlite3_column_bytes(tls, **(**uintptr)(__ccgo_up(bp)), int32(1))
iIdxLeaf = Xsqlite3_column_int(tls, **(**uintptr)(__ccgo_up(bp)), int32(2))
bIdxDlidx = Xsqlite3_column_int(tls, **(**uintptr)(__ccgo_up(bp)), int32(3))
/* If the leaf in question has already been trimmed from the segment,
** ignore this b-tree entry. Otherwise, load it into memory. */
if iIdxLeaf < (*TFts5StructureSegment)(unsafe.Pointer(pSeg)).FpgnoFirst {
continue
}
iRow = int64((*TFts5StructureSegment)(unsafe.Pointer(pSeg)).FiSegid)<<(libc.Int32FromInt32(FTS5_DATA_PAGE_B)+libc.Int32FromInt32(FTS5_DATA_HEIGHT_B)+libc.Int32FromInt32(FTS5_DATA_DLI_B)) + int64(libc.Int32FromInt32(0))<<(libc.Int32FromInt32(FTS5_DATA_PAGE_B)+libc.Int32FromInt32(FTS5_DATA_HEIGHT_B)) + int64(libc.Int32FromInt32(0))<= iOff || iOff >= (*TFts5Data)(unsafe.Pointer(pLeaf)).FszLeaf {
_fts5IndexCorruptRowid(tls, p, iRow)
} else {
iOff = iOff + _sqlite3Fts5GetVarint32(tls, (*TFts5Data)(unsafe.Pointer(pLeaf)).Fp+uintptr(iOff), bp+8)
if iOff+**(**int32)(__ccgo_up(bp + 8)) > (*TFts5Data)(unsafe.Pointer(pLeaf)).FszLeaf {
_fts5IndexCorruptRowid(tls, p, iRow)
} else {
if **(**int32)(__ccgo_up(bp + 8)) < nIdxTerm {
v2 = **(**int32)(__ccgo_up(bp + 8))
} else {
v2 = nIdxTerm
}
if v2 <= 0 {
v1 = 0
} else {
if **(**int32)(__ccgo_up(bp + 8)) < nIdxTerm {
v3 = **(**int32)(__ccgo_up(bp + 8))
} else {
v3 = nIdxTerm
}
v1 = libc.Xmemcmp(tls, (*TFts5Data)(unsafe.Pointer(pLeaf)).Fp+uintptr(iOff), zIdxTerm, libc.Uint64FromInt32(v3))
}
res = v1
if res == 0 {
res = **(**int32)(__ccgo_up(bp + 8)) - nIdxTerm
}
if res < 0 {
_fts5IndexCorruptRowid(tls, p, iRow)
}
}
}
_fts5IntegrityCheckPgidx(tls, p, iRow, pLeaf)
}
_fts5DataRelease(tls, pLeaf)
if (*TFts5Index)(unsafe.Pointer(p)).Frc != 0 {
break
}
/* Now check that the iter.nEmpty leaves following the current leaf
** (a) exist and (b) contain no terms. */
_fts5IndexIntegrityCheckEmpty(tls, p, pSeg, iIdxPrevLeaf+int32(1), iDlidxPrevLeaf+int32(1), iIdxLeaf-int32(1))
if (*TFts5Index)(unsafe.Pointer(p)).Frc != 0 {
break
}
/* If there is a doclist-index, check that it looks right. */
if bIdxDlidx != 0 {
pDlidx = uintptr(0) /* For iterating through doclist index */
iPrevLeaf = iIdxLeaf
iSegid = (*TFts5StructureSegment)(unsafe.Pointer(pSeg)).FiSegid
iPg = 0
pDlidx = _fts5DlidxIterInit(tls, p, 0, iSegid, iIdxLeaf)
for {
if !(_fts5DlidxIterEof(tls, p, pDlidx) == 0) {
break
}
/* Check any rowid-less pages that occur before the current leaf. */
iPg = iPrevLeaf + int32(1)
for {
if !(iPg < _fts5DlidxIterPgno(tls, pDlidx)) {
break
}
iKey = int64(iSegid)<<(libc.Int32FromInt32(FTS5_DATA_PAGE_B)+libc.Int32FromInt32(FTS5_DATA_HEIGHT_B)+libc.Int32FromInt32(FTS5_DATA_DLI_B)) + int64(libc.Int32FromInt32(0))<<(libc.Int32FromInt32(FTS5_DATA_PAGE_B)+libc.Int32FromInt32(FTS5_DATA_HEIGHT_B)) + int64(libc.Int32FromInt32(0))<= (*TFts5Data)(unsafe.Pointer(pLeaf)).FszLeaf {
_fts5IndexCorruptRowid(tls, p, iKey)
} else {
if bSecureDelete == 0 || iRowidOff1 > 0 {
iDlRowid = _fts5DlidxIterRowid(tls, pDlidx)
_sqlite3Fts5GetVarint(tls, (*TFts5Data)(unsafe.Pointer(pLeaf)).Fp+uintptr(iRowidOff1), bp+16)
if **(**Ti64)(__ccgo_up(bp + 16)) < iDlRowid || bSecureDelete == 0 && **(**Ti64)(__ccgo_up(bp + 16)) != iDlRowid {
_fts5IndexCorruptRowid(tls, p, iKey)
}
}
}
_fts5DataRelease(tls, pLeaf)
}
goto _4
_4:
;
_fts5DlidxIterNext(tls, p, pDlidx)
}
iDlidxPrevLeaf = iPg
_fts5DlidxIterFree(tls, pDlidx)
} else {
iDlidxPrevLeaf = (*TFts5StructureSegment)(unsafe.Pointer(pSeg)).FpgnoLast
/* TODO: Check there is no doclist index */
}
iIdxPrevLeaf = iIdxLeaf
}
rc2 = Xsqlite3_finalize(tls, **(**uintptr)(__ccgo_up(bp)))
if (*TFts5Index)(unsafe.Pointer(p)).Frc == SQLITE_OK {
(*TFts5Index)(unsafe.Pointer(p)).Frc = rc2
}
/* Page iter.iLeaf must now be the rightmost leaf-page in the segment */
}
// C documentation
//
// /*
// **
// */
func _fts5IndexMergeLevel(tls *libc.TLS, p uintptr, ppStruct uintptr, iLvl int32, pnRem uintptr) {
bp := tls.Alloc(160)
defer tls.Free(160)
var bOldest, bTermWritten, eDetail, flags, i, iSegid, nInput, nMove, nPos, nRem, v1 int32
var pLvl, pLvlOut, pOld, pSeg, pSegIter, pStruct, pTerm uintptr
var v4 bool
var _ /* nTerm at bp+144 */ int32
var _ /* pIter at bp+0 */ uintptr
var _ /* term at bp+128 */ TFts5Buffer
var _ /* writer at bp+8 */ TFts5SegWriter
_, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _ = bOldest, bTermWritten, eDetail, flags, i, iSegid, nInput, nMove, nPos, nRem, pLvl, pLvlOut, pOld, pSeg, pSegIter, pStruct, pTerm, v1, v4
pStruct = **(**uintptr)(__ccgo_up(ppStruct))
pLvl = pStruct + 32 + uintptr(iLvl)*16
**(**uintptr)(__ccgo_up(bp)) = uintptr(0)
if pnRem != 0 {
v1 = **(**int32)(__ccgo_up(pnRem))
} else {
v1 = 0
} /* Iterator to read input data */
nRem = v1 /* True if the output segment is the oldest */
eDetail = (*TFts5Config)(unsafe.Pointer((*TFts5Index)(unsafe.Pointer(p)).FpConfig)).FeDetail
flags = int32(FTS5INDEX_QUERY_NOOUTPUT)
bTermWritten = 0 /* True if current term already output */
libc.X__builtin___memset_chk(tls, bp+8, 0, uint64(120), ^t__predefined_size_t(0))
libc.X__builtin___memset_chk(tls, bp+128, 0, uint64(16), ^t__predefined_size_t(0))
if (*TFts5StructureLevel)(unsafe.Pointer(pLvl)).FnMerge != 0 {
pLvlOut = pStruct + 32 + uintptr(iLvl+int32(1))*16
nInput = (*TFts5StructureLevel)(unsafe.Pointer(pLvl)).FnMerge
pSeg = (*TFts5StructureLevel)(unsafe.Pointer(pLvlOut)).FaSeg + uintptr((*TFts5StructureLevel)(unsafe.Pointer(pLvlOut)).FnSeg-int32(1))*56
_fts5WriteInit(tls, p, bp+8, (*TFts5StructureSegment)(unsafe.Pointer(pSeg)).FiSegid)
(**(**TFts5SegWriter)(__ccgo_up(bp + 8))).Fwriter.Fpgno = (*TFts5StructureSegment)(unsafe.Pointer(pSeg)).FpgnoLast + int32(1)
(**(**TFts5SegWriter)(__ccgo_up(bp + 8))).FiBtPage = 0
} else {
iSegid = _fts5AllocateSegid(tls, p, pStruct)
/* Extend the Fts5Structure object as required to ensure the output
** segment exists. */
if iLvl == (*TFts5Structure)(unsafe.Pointer(pStruct)).FnLevel-int32(1) {
_fts5StructureAddLevel(tls, p+60, ppStruct)
pStruct = **(**uintptr)(__ccgo_up(ppStruct))
}
_fts5StructureExtendLevel(tls, p+60, pStruct, iLvl+int32(1), int32(1), 0)
if (*TFts5Index)(unsafe.Pointer(p)).Frc != 0 {
return
}
pLvl = pStruct + 32 + uintptr(iLvl)*16
pLvlOut = pStruct + 32 + uintptr(iLvl+int32(1))*16
_fts5WriteInit(tls, p, bp+8, iSegid)
/* Add the new segment to the output level */
pSeg = (*TFts5StructureLevel)(unsafe.Pointer(pLvlOut)).FaSeg + uintptr((*TFts5StructureLevel)(unsafe.Pointer(pLvlOut)).FnSeg)*56
(*TFts5StructureLevel)(unsafe.Pointer(pLvlOut)).FnSeg = (*TFts5StructureLevel)(unsafe.Pointer(pLvlOut)).FnSeg + 1
(*TFts5StructureSegment)(unsafe.Pointer(pSeg)).FpgnoFirst = int32(1)
(*TFts5StructureSegment)(unsafe.Pointer(pSeg)).FiSegid = iSegid
(*TFts5Structure)(unsafe.Pointer(pStruct)).FnSegment = (*TFts5Structure)(unsafe.Pointer(pStruct)).FnSegment + 1
/* Read input from all segments in the input level */
nInput = (*TFts5StructureLevel)(unsafe.Pointer(pLvl)).FnSeg
/* Set the range of origins that will go into the output segment. */
if (*TFts5Structure)(unsafe.Pointer(pStruct)).FnOriginCntr > uint64(0) {
(*TFts5StructureSegment)(unsafe.Pointer(pSeg)).FiOrigin1 = (**(**TFts5StructureSegment)(__ccgo_up((*TFts5StructureLevel)(unsafe.Pointer(pLvl)).FaSeg))).FiOrigin1
(*TFts5StructureSegment)(unsafe.Pointer(pSeg)).FiOrigin2 = (**(**TFts5StructureSegment)(__ccgo_up((*TFts5StructureLevel)(unsafe.Pointer(pLvl)).FaSeg + uintptr((*TFts5StructureLevel)(unsafe.Pointer(pLvl)).FnSeg-int32(1))*56))).FiOrigin2
}
}
bOldest = libc.BoolInt32((*TFts5StructureLevel)(unsafe.Pointer(pLvlOut)).FnSeg == int32(1) && (*TFts5Structure)(unsafe.Pointer(pStruct)).FnLevel == iLvl+int32(2))
_fts5MultiIterNew(tls, p, pStruct, flags, uintptr(0), uintptr(0), 0, iLvl, nInput, bp)
for {
if !(_fts5MultiIterEof(tls, p, **(**uintptr)(__ccgo_up(bp))) == 0) {
break
}
pSegIter = **(**uintptr)(__ccgo_up(bp)) + 104 + uintptr((**(**TFts5CResult)(__ccgo_up((*TFts5Iter)(unsafe.Pointer(**(**uintptr)(__ccgo_up(bp)))).FaFirst + 1*4))).FiFirst)*128
pTerm = _fts5MultiIterTerm(tls, **(**uintptr)(__ccgo_up(bp)), bp+144)
if v4 = **(**int32)(__ccgo_up(bp + 144)) != (**(**TFts5Buffer)(__ccgo_up(bp + 128))).Fn; !v4 {
if **(**int32)(__ccgo_up(bp + 144)) <= 0 {
v1 = 0
} else {
v1 = libc.Xmemcmp(tls, pTerm, (**(**TFts5Buffer)(__ccgo_up(bp + 128))).Fp, libc.Uint64FromInt32(**(**int32)(__ccgo_up(bp + 144))))
}
}
if v4 || v1 != 0 {
if pnRem != 0 && (**(**TFts5SegWriter)(__ccgo_up(bp + 8))).FnLeafWritten > nRem {
break
}
_sqlite3Fts5BufferSet(tls, p+60, bp+128, **(**int32)(__ccgo_up(bp + 144)), pTerm)
bTermWritten = 0
}
/* Check for key annihilation. */
if (*TFts5SegIter)(unsafe.Pointer(pSegIter)).FnPos == 0 && (bOldest != 0 || libc.Int32FromUint8((*TFts5SegIter)(unsafe.Pointer(pSegIter)).FbDel) == 0) {
goto _2
}
if (*TFts5Index)(unsafe.Pointer(p)).Frc == SQLITE_OK && bTermWritten == 0 {
/* This is a new term. Append a term to the output segment. */
_fts5WriteAppendTerm(tls, p, bp+8, **(**int32)(__ccgo_up(bp + 144)), pTerm)
bTermWritten = int32(1)
}
/* Append the rowid to the output */
/* WRITEPOSLISTSIZE */
_fts5WriteAppendRowid(tls, p, bp+8, _fts5MultiIterRowid(tls, **(**uintptr)(__ccgo_up(bp))))
if eDetail == int32(FTS5_DETAIL_NONE) {
if (*TFts5SegIter)(unsafe.Pointer(pSegIter)).FbDel != 0 {
_sqlite3Fts5BufferAppendVarint(tls, p+60, bp+8+8+8, libc.Int64FromInt32(0))
if (*TFts5SegIter)(unsafe.Pointer(pSegIter)).FnPos > 0 {
_sqlite3Fts5BufferAppendVarint(tls, p+60, bp+8+8+8, libc.Int64FromInt32(0))
}
}
} else {
/* Append the position-list data to the output */
nPos = (*TFts5SegIter)(unsafe.Pointer(pSegIter)).FnPos*int32(2) + libc.Int32FromUint8((*TFts5SegIter)(unsafe.Pointer(pSegIter)).FbDel)
_sqlite3Fts5BufferAppendVarint(tls, p+60, bp+8+8+8, int64(nPos))
_fts5ChunkIterate(tls, p, pSegIter, bp+8, __ccgo_fp(_fts5MergeChunkCallback))
}
goto _2
_2:
;
_fts5MultiIterNext(tls, p, **(**uintptr)(__ccgo_up(bp)), 0, 0)
}
/* Flush the last leaf page to disk. Set the output segment b-tree height
** and last leaf page number at the same time. */
_fts5WriteFinish(tls, p, bp+8, pSeg+8)
if _fts5MultiIterEof(tls, p, **(**uintptr)(__ccgo_up(bp))) != 0 {
/* Remove the redundant segments from the %_data table */
i = 0
for {
if !(i < nInput) {
break
}
pOld = (*TFts5StructureLevel)(unsafe.Pointer(pLvl)).FaSeg + uintptr(i)*56
**(**Tu64)(__ccgo_up(pSeg + 48)) += (*TFts5StructureSegment)(unsafe.Pointer(pOld)).FnEntry - (*TFts5StructureSegment)(unsafe.Pointer(pOld)).FnEntryTombstone
_fts5DataRemoveSegment(tls, p, pOld)
goto _5
_5:
;
i = i + 1
}
/* Remove the redundant segments from the input level */
if (*TFts5StructureLevel)(unsafe.Pointer(pLvl)).FnSeg != nInput {
nMove = libc.Int32FromUint64(libc.Uint64FromInt32((*TFts5StructureLevel)(unsafe.Pointer(pLvl)).FnSeg-nInput) * uint64(56))
libc.X__builtin___memmove_chk(tls, (*TFts5StructureLevel)(unsafe.Pointer(pLvl)).FaSeg, (*TFts5StructureLevel)(unsafe.Pointer(pLvl)).FaSeg+uintptr(nInput)*56, libc.Uint64FromInt32(nMove), ^t__predefined_size_t(0))
}
**(**int32)(__ccgo_up(pStruct + 24)) -= nInput
**(**int32)(__ccgo_up(pLvl + 4)) -= nInput
(*TFts5StructureLevel)(unsafe.Pointer(pLvl)).FnMerge = 0
if (*TFts5StructureSegment)(unsafe.Pointer(pSeg)).FpgnoLast == 0 {
(*TFts5StructureLevel)(unsafe.Pointer(pLvlOut)).FnSeg = (*TFts5StructureLevel)(unsafe.Pointer(pLvlOut)).FnSeg - 1
(*TFts5Structure)(unsafe.Pointer(pStruct)).FnSegment = (*TFts5Structure)(unsafe.Pointer(pStruct)).FnSegment - 1
}
} else {
_fts5TrimSegments(tls, p, **(**uintptr)(__ccgo_up(bp)))
(*TFts5StructureLevel)(unsafe.Pointer(pLvl)).FnMerge = nInput
}
_fts5MultiIterFree(tls, **(**uintptr)(__ccgo_up(bp)))
_sqlite3Fts5BufferFree(tls, bp+128)
if pnRem != 0 {
**(**int32)(__ccgo_up(pnRem)) -= (**(**TFts5SegWriter)(__ccgo_up(bp + 8))).FnLeafWritten
}
}
func _fts5Init(tls *libc.TLS, db uintptr) (r int32) {
var p, pGlobal uintptr
var rc int32
_, _, _ = p, pGlobal, rc
pGlobal = uintptr(0)
pGlobal = Xsqlite3_malloc64(tls, uint64(112))
if pGlobal == uintptr(0) {
rc = int32(SQLITE_NOMEM)
} else {
p = pGlobal
libc.X__builtin___memset_chk(tls, pGlobal, 0, uint64(112), ^t__predefined_size_t(0))
(*TFts5Global)(unsafe.Pointer(pGlobal)).Fdb = db
(*TFts5Global)(unsafe.Pointer(pGlobal)).Fapi.FiVersion = int32(3)
(*TFts5Global)(unsafe.Pointer(pGlobal)).Fapi.FxCreateFunction = __ccgo_fp(_fts5CreateAux)
(*TFts5Global)(unsafe.Pointer(pGlobal)).Fapi.FxCreateTokenizer = __ccgo_fp(_fts5CreateTokenizer)
(*TFts5Global)(unsafe.Pointer(pGlobal)).Fapi.FxFindTokenizer = __ccgo_fp(_fts5FindTokenizer)
(*TFts5Global)(unsafe.Pointer(pGlobal)).Fapi.FxCreateTokenizer_v2 = __ccgo_fp(_fts5CreateTokenizer_v2)
(*TFts5Global)(unsafe.Pointer(pGlobal)).Fapi.FxFindTokenizer_v2 = __ccgo_fp(_fts5FindTokenizer_v2)
/* Initialize pGlobal->aLocaleHdr[] to a 128-bit pseudo-random vector.
** The constants below were generated randomly. */
Xsqlite3_randomness(tls, int32(16), pGlobal+96)
**(**Tu32)(__ccgo_up(pGlobal + 96)) ^= uint32(0xF924976D)
**(**Tu32)(__ccgo_up(pGlobal + 96 + 1*4)) ^= uint32(0x16596E13)
**(**Tu32)(__ccgo_up(pGlobal + 96 + 2*4)) ^= uint32(0x7C80BEAA)
**(**Tu32)(__ccgo_up(pGlobal + 96 + 3*4)) ^= uint32(0x9B03A67F)
rc = Xsqlite3_create_module_v2(tls, db, __ccgo_ts+41105, 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+41105, 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+41110, 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+41125, 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+41137, int32(1), libc.Int32FromInt32(SQLITE_UTF8)|libc.Int32FromInt32(SQLITE_INNOCUOUS)|libc.Int32FromInt32(SQLITE_RESULT_SUBTYPE), p, __ccgo_fp(_fts5InsttokenFunc), uintptr(0), uintptr(0))
}
}
/* If SQLITE_FTS5_ENABLE_TEST_MI is defined, assume that the file
** fts5_test_mi.c is compiled and linked into the executable. And call
** its entry point to enable the matchinfo() demo. */
return rc
}
// C documentation
//
// /*
// ** Run an integrity check on the FTS5 data structures. Return a string
// ** if anything is found amiss. Return a NULL pointer if everything is
// ** OK.
// */
func _fts5IntegrityMethod(tls *libc.TLS, pVtab uintptr, zSchema uintptr, zTabname uintptr, isQuick int32, pzErr uintptr) (r int32) {
bp := tls.Alloc(32)
defer tls.Free(32)
var pTab uintptr
var rc, v1 int32
_, _, _ = pTab, rc, v1
pTab = pVtab
_ = isQuick
(*TFts5Config)(unsafe.Pointer((*TFts5FullTable)(unsafe.Pointer(pTab)).Fp.FpConfig)).FpzErrmsg = pzErr
rc = _sqlite3Fts5StorageIntegrity(tls, (*TFts5FullTable)(unsafe.Pointer(pTab)).FpStorage, 0)
if **(**uintptr)(__ccgo_up(pzErr)) == uintptr(0) && rc != SQLITE_OK {
if rc&int32(0xff) == int32(SQLITE_CORRUPT) {
**(**uintptr)(__ccgo_up(pzErr)) = Xsqlite3_mprintf(tls, __ccgo_ts+40996, libc.VaList(bp+8, zSchema, zTabname))
if **(**uintptr)(__ccgo_up(pzErr)) != 0 {
v1 = SQLITE_OK
} else {
v1 = int32(SQLITE_NOMEM)
}
rc = v1
} else {
**(**uintptr)(__ccgo_up(pzErr)) = Xsqlite3_mprintf(tls, __ccgo_ts+41042, libc.VaList(bp+8, zSchema, zTabname, Xsqlite3_errstr(tls, rc)))
}
} else {
if rc&int32(0xff) == int32(SQLITE_CORRUPT) {
rc = SQLITE_OK
}
}
_sqlite3Fts5IndexCloseReader(tls, (*TFts5FullTable)(unsafe.Pointer(pTab)).Fp.FpIndex)
(*TFts5Config)(unsafe.Pointer((*TFts5FullTable)(unsafe.Pointer(pTab)).Fp.FpConfig)).FpzErrmsg = uintptr(0)
return rc
}
// C documentation
//
// /*
// ** Implementation of fts5_locale(LOCALE, TEXT) function.
// **
// ** If parameter LOCALE is NULL, or a zero-length string, then a copy of
// ** TEXT is returned. Otherwise, both LOCALE and TEXT are interpreted as
// ** text, and the value returned is a blob consisting of:
// **
// ** * The 4 bytes 0x00, 0xE0, 0xB2, 0xEb (FTS5_LOCALE_HEADER).
// ** * The LOCALE, as utf-8 text, followed by
// ** * 0x00, followed by
// ** * The TEXT, as utf-8 text.
// **
// ** There is no final nul-terminator following the TEXT value.
// */
func _fts5LocaleFunc(tls *libc.TLS, pCtx uintptr, nArg int32, apArg uintptr) {
var nBlob, nLocale, nText Ti64
var p, pBlob, pCsr, zLocale, zText, v1 uintptr
_, _, _, _, _, _, _, _, _ = nBlob, nLocale, nText, p, pBlob, pCsr, zLocale, zText, v1
zLocale = uintptr(0)
nLocale = 0
zText = uintptr(0)
nText = 0
_ = nArg
zLocale = Xsqlite3_value_text(tls, **(**uintptr)(__ccgo_up(apArg)))
nLocale = int64(Xsqlite3_value_bytes(tls, **(**uintptr)(__ccgo_up(apArg))))
zText = Xsqlite3_value_text(tls, **(**uintptr)(__ccgo_up(apArg + 1*8)))
nText = int64(Xsqlite3_value_bytes(tls, **(**uintptr)(__ccgo_up(apArg + 1*8))))
if zLocale == uintptr(0) || int32(**(**int8)(__ccgo_up(zLocale))) == int32('\000') {
Xsqlite3_result_text(tls, pCtx, zText, int32(nText), uintptr(-libc.Int32FromInt32(1)))
} else {
p = Xsqlite3_user_data(tls, pCtx)
pBlob = uintptr(0)
pCsr = uintptr(0)
nBlob = 0
nBlob = int64(libc.Int32FromInt64(16)) + nLocale + int64(1) + nText
pBlob = Xsqlite3_malloc64(tls, libc.Uint64FromInt64(nBlob))
if pBlob == uintptr(0) {
Xsqlite3_result_error_nomem(tls, pCtx)
return
}
pCsr = pBlob
libc.X__builtin___memcpy_chk(tls, pCsr, p+96, libc.Uint64FromInt32(libc.Int32FromInt64(16)), ^t__predefined_size_t(0))
pCsr = pCsr + uintptr(libc.Int32FromInt64(16))
libc.X__builtin___memcpy_chk(tls, pCsr, zLocale, libc.Uint64FromInt64(nLocale), ^t__predefined_size_t(0))
pCsr = pCsr + uintptr(nLocale)
v1 = pCsr
pCsr = pCsr + 1
**(**Tu8)(__ccgo_up(v1)) = uint8(0x00)
if zText != 0 {
libc.X__builtin___memcpy_chk(tls, pCsr, zText, libc.Uint64FromInt64(nText), ^t__predefined_size_t(0))
}
Xsqlite3_result_blob(tls, pCtx, pBlob, int32(nBlob), __ccgo_fp(Xsqlite3_free))
}
}
func _fts5LookaheadReaderInit(tls *libc.TLS, a uintptr, n int32, p uintptr) (r int32) {
libc.X__builtin___memset_chk(tls, p, 0, uint64(32), ^t__predefined_size_t(0))
(*TFts5LookaheadReader)(unsafe.Pointer(p)).Fa = a
(*TFts5LookaheadReader)(unsafe.Pointer(p)).Fn = n
_fts5LookaheadReaderNext(tls, p)
return _fts5LookaheadReaderNext(tls, p)
}
// C documentation
//
// /*
// ** Array aBuf[] contains nBuf doclists. These are all merged in with the
// ** doclist in buffer p1.
// */
func _fts5MergePrefixLists(tls *libc.TLS, p uintptr, p1 uintptr, nBuf int32, aBuf uintptr) {
bp := tls.Alloc(1072)
defer tls.Free(1072)
var i, nMerge, nOut, nTail, nTmp int32
var iLastRowid Ti64
var pI, pNext, pSave, pThis, pThis1, pX uintptr
var _ /* aMerger at bp+0 */ [16]TPrefixMerger
var _ /* iPrev at bp+1064 */ Ti64
var _ /* out at bp+1032 */ TFts5Buffer
var _ /* pHead at bp+1024 */ uintptr
var _ /* tmp at bp+1048 */ TFts5Buffer
_, _, _, _, _, _, _, _, _, _, _, _ = i, iLastRowid, nMerge, nOut, nTail, nTmp, pI, pNext, pSave, pThis, pThis1, pX
**(**uintptr)(__ccgo_up(bp + 1024)) = uintptr(0)
nOut = 0
**(**TFts5Buffer)(__ccgo_up(bp + 1032)) = TFts5Buffer{}
**(**TFts5Buffer)(__ccgo_up(bp + 1048)) = TFts5Buffer{}
iLastRowid = 0
/* Initialize a doclist-iterator for each input buffer. Arrange them in
** a linked-list starting at pHead in ascending order of rowid. Avoid
** linking any iterators already at EOF into the linked list at all. */
libc.X__builtin___memset_chk(tls, bp, 0, uint64(64)*libc.Uint64FromInt32(nBuf+libc.Int32FromInt32(1)), ^t__predefined_size_t(0))
**(**uintptr)(__ccgo_up(bp + 1024)) = bp + uintptr(nBuf)*64
_fts5DoclistIterInit(tls, p1, **(**uintptr)(__ccgo_up(bp + 1024)))
i = 0
for {
if !(i < nBuf) {
break
}
_fts5DoclistIterInit(tls, aBuf+uintptr(i)*16, bp+uintptr(i)*64)
_fts5PrefixMergerInsertByRowid(tls, bp+1024, bp+uintptr(i)*64)
nOut = nOut + (**(**TFts5Buffer)(__ccgo_up(aBuf + uintptr(i)*16))).Fn
goto _1
_1:
;
i = i + 1
}
if nOut == 0 {
return
}
nOut = nOut + ((*TFts5Buffer)(unsafe.Pointer(p1)).Fn + int32(9) + int32(10)*nBuf)
/* The maximum size of the output is equal to the sum of the
** input sizes + 1 varint (9 bytes). The extra varint is because if the
** first rowid in one input is a large negative number, and the first in
** the other a non-negative number, the delta for the non-negative
** number will be larger on disk than the literal integer value
** was.
**
** Or, if the input position-lists are corrupt, then the output might
** include up to (nBuf+1) extra 10-byte positions created by interpreting -1
** (the value PoslistNext64() uses for EOF) as a position and appending
** it to the output. This can happen at most once for each input
** position-list, hence (nBuf+1) 10 byte paddings. */
if _sqlite3Fts5BufferSize(tls, p+60, bp+1032, libc.Uint32FromInt32(nOut)) != 0 {
return
}
for **(**uintptr)(__ccgo_up(bp + 1024)) != 0 {
**(**int32)(__ccgo_up(bp + 1032 + 8)) += _sqlite3Fts5PutVarint(tls, (*TFts5Buffer)(unsafe.Pointer(bp+1032)).Fp+uintptr((*TFts5Buffer)(unsafe.Pointer(bp+1032)).Fn), libc.Uint64FromInt64((*TPrefixMerger)(unsafe.Pointer(**(**uintptr)(__ccgo_up(bp + 1024)))).Fiter.FiRowid)-libc.Uint64FromInt64(iLastRowid))
iLastRowid = (*TPrefixMerger)(unsafe.Pointer(**(**uintptr)(__ccgo_up(bp + 1024)))).Fiter.FiRowid
if (*TPrefixMerger)(unsafe.Pointer(**(**uintptr)(__ccgo_up(bp + 1024)))).FpNext != 0 && iLastRowid == (*TPrefixMerger)(unsafe.Pointer((*TPrefixMerger)(unsafe.Pointer(**(**uintptr)(__ccgo_up(bp + 1024)))).FpNext)).Fiter.FiRowid {
/* Merge data from two or more poslists */
**(**Ti64)(__ccgo_up(bp + 1064)) = 0
nTmp = int32(FTS5_DATA_ZERO_PADDING)
nMerge = 0
pSave = **(**uintptr)(__ccgo_up(bp + 1024))
pThis = uintptr(0)
nTail = 0
**(**uintptr)(__ccgo_up(bp + 1024)) = uintptr(0)
for pSave != 0 && (*TPrefixMerger)(unsafe.Pointer(pSave)).Fiter.FiRowid == iLastRowid {
pNext = (*TPrefixMerger)(unsafe.Pointer(pSave)).FpNext
(*TPrefixMerger)(unsafe.Pointer(pSave)).FiOff = 0
(*TPrefixMerger)(unsafe.Pointer(pSave)).FiPos = 0
(*TPrefixMerger)(unsafe.Pointer(pSave)).FaPos = (*TPrefixMerger)(unsafe.Pointer(pSave)).Fiter.FaPoslist + uintptr((*TPrefixMerger)(unsafe.Pointer(pSave)).Fiter.FnSize)
_sqlite3Fts5PoslistNext64(tls, (*TPrefixMerger)(unsafe.Pointer(pSave)).FaPos, (*TPrefixMerger)(unsafe.Pointer(pSave)).Fiter.FnPoslist, pSave+40, pSave+32)
nTmp = nTmp + ((*TPrefixMerger)(unsafe.Pointer(pSave)).Fiter.FnPoslist + int32(10))
nMerge = nMerge + 1
_fts5PrefixMergerInsertByPosition(tls, bp+1024, pSave)
pSave = pNext
}
if **(**uintptr)(__ccgo_up(bp + 1024)) == uintptr(0) || (*TPrefixMerger)(unsafe.Pointer(**(**uintptr)(__ccgo_up(bp + 1024)))).FpNext == uintptr(0) {
_fts5IndexCorruptIdx(tls, p)
break
}
/* See the earlier comment in this function for an explanation of why
** corrupt input position lists might cause the output to consume
** at most nMerge*10 bytes of unexpected space. */
if _sqlite3Fts5BufferSize(tls, p+60, bp+1048, libc.Uint32FromInt32(nTmp+nMerge*int32(10))) != 0 {
break
}
_sqlite3Fts5BufferZero(tls, bp+1048)
pThis = **(**uintptr)(__ccgo_up(bp + 1024))
**(**uintptr)(__ccgo_up(bp + 1024)) = (*TPrefixMerger)(unsafe.Pointer(pThis)).FpNext
_sqlite3Fts5PoslistSafeAppend(tls, bp+1048, bp+1064, (*TPrefixMerger)(unsafe.Pointer(pThis)).FiPos)
_sqlite3Fts5PoslistNext64(tls, (*TPrefixMerger)(unsafe.Pointer(pThis)).FaPos, (*TPrefixMerger)(unsafe.Pointer(pThis)).Fiter.FnPoslist, pThis+40, pThis+32)
_fts5PrefixMergerInsertByPosition(tls, bp+1024, pThis)
for (*TPrefixMerger)(unsafe.Pointer(**(**uintptr)(__ccgo_up(bp + 1024)))).FpNext != 0 {
pThis = **(**uintptr)(__ccgo_up(bp + 1024))
if (*TPrefixMerger)(unsafe.Pointer(pThis)).FiPos != **(**Ti64)(__ccgo_up(bp + 1064)) {
_sqlite3Fts5PoslistSafeAppend(tls, bp+1048, bp+1064, (*TPrefixMerger)(unsafe.Pointer(pThis)).FiPos)
}
_sqlite3Fts5PoslistNext64(tls, (*TPrefixMerger)(unsafe.Pointer(pThis)).FaPos, (*TPrefixMerger)(unsafe.Pointer(pThis)).Fiter.FnPoslist, pThis+40, pThis+32)
**(**uintptr)(__ccgo_up(bp + 1024)) = (*TPrefixMerger)(unsafe.Pointer(pThis)).FpNext
_fts5PrefixMergerInsertByPosition(tls, bp+1024, pThis)
}
if (*TPrefixMerger)(unsafe.Pointer(**(**uintptr)(__ccgo_up(bp + 1024)))).FiPos != **(**Ti64)(__ccgo_up(bp + 1064)) {
_sqlite3Fts5PoslistSafeAppend(tls, bp+1048, bp+1064, (*TPrefixMerger)(unsafe.Pointer(**(**uintptr)(__ccgo_up(bp + 1024)))).FiPos)
}
nTail = (*TPrefixMerger)(unsafe.Pointer(**(**uintptr)(__ccgo_up(bp + 1024)))).Fiter.FnPoslist - (*TPrefixMerger)(unsafe.Pointer(**(**uintptr)(__ccgo_up(bp + 1024)))).FiOff
/* WRITEPOSLISTSIZE */
if (**(**TFts5Buffer)(__ccgo_up(bp + 1048))).Fn+nTail > nTmp-int32(FTS5_DATA_ZERO_PADDING) {
if (*TFts5Index)(unsafe.Pointer(p)).Frc == SQLITE_OK {
_fts5IndexCorruptIdx(tls, p)
}
break
}
**(**int32)(__ccgo_up(bp + 1032 + 8)) += _sqlite3Fts5PutVarint(tls, (*TFts5Buffer)(unsafe.Pointer(bp+1032)).Fp+uintptr((*TFts5Buffer)(unsafe.Pointer(bp+1032)).Fn), libc.Uint64FromInt32(((**(**TFts5Buffer)(__ccgo_up(bp + 1048))).Fn+nTail)*libc.Int32FromInt32(2)))
libc.X__builtin___memcpy_chk(tls, (*TFts5Buffer)(unsafe.Pointer(bp+1032)).Fp+uintptr((*TFts5Buffer)(unsafe.Pointer(bp+1032)).Fn), (**(**TFts5Buffer)(__ccgo_up(bp + 1048))).Fp, libc.Uint64FromInt32((**(**TFts5Buffer)(__ccgo_up(bp + 1048))).Fn), ^t__predefined_size_t(0))
**(**int32)(__ccgo_up(bp + 1032 + 8)) += (**(**TFts5Buffer)(__ccgo_up(bp + 1048))).Fn
if nTail > 0 {
libc.X__builtin___memcpy_chk(tls, (*TFts5Buffer)(unsafe.Pointer(bp+1032)).Fp+uintptr((*TFts5Buffer)(unsafe.Pointer(bp+1032)).Fn), (*TPrefixMerger)(unsafe.Pointer(**(**uintptr)(__ccgo_up(bp + 1024)))).FaPos+uintptr((*TPrefixMerger)(unsafe.Pointer(**(**uintptr)(__ccgo_up(bp + 1024)))).FiOff), libc.Uint64FromInt32(nTail), ^t__predefined_size_t(0))
**(**int32)(__ccgo_up(bp + 1032 + 8)) += nTail
}
**(**uintptr)(__ccgo_up(bp + 1024)) = pSave
i = 0
for {
if !(i < nBuf+int32(1)) {
break
}
pX = bp + uintptr(i)*64
if (*TPrefixMerger)(unsafe.Pointer(pX)).Fiter.FaPoslist != 0 && (*TPrefixMerger)(unsafe.Pointer(pX)).Fiter.FiRowid == iLastRowid {
_fts5DoclistIterNext(tls, pX)
_fts5PrefixMergerInsertByRowid(tls, bp+1024, pX)
}
goto _2
_2:
;
i = i + 1
}
} else {
/* Copy poslist from pHead to output */
pThis1 = **(**uintptr)(__ccgo_up(bp + 1024))
pI = pThis1
libc.X__builtin___memcpy_chk(tls, (*TFts5Buffer)(unsafe.Pointer(bp+1032)).Fp+uintptr((*TFts5Buffer)(unsafe.Pointer(bp+1032)).Fn), (*TFts5DoclistIter)(unsafe.Pointer(pI)).FaPoslist, libc.Uint64FromInt32((*TFts5DoclistIter)(unsafe.Pointer(pI)).FnPoslist+(*TFts5DoclistIter)(unsafe.Pointer(pI)).FnSize), ^t__predefined_size_t(0))
**(**int32)(__ccgo_up(bp + 1032 + 8)) += (*TFts5DoclistIter)(unsafe.Pointer(pI)).FnPoslist + (*TFts5DoclistIter)(unsafe.Pointer(pI)).FnSize
_fts5DoclistIterNext(tls, pI)
**(**uintptr)(__ccgo_up(bp + 1024)) = (*TPrefixMerger)(unsafe.Pointer(pThis1)).FpNext
_fts5PrefixMergerInsertByRowid(tls, bp+1024, pThis1)
}
}
_sqlite3Fts5BufferFree(tls, p1)
_sqlite3Fts5BufferFree(tls, bp+1048)
libc.X__builtin___memset_chk(tls, (**(**TFts5Buffer)(__ccgo_up(bp + 1032))).Fp+uintptr((**(**TFts5Buffer)(__ccgo_up(bp + 1032))).Fn), 0, uint64(FTS5_DATA_ZERO_PADDING), ^t__predefined_size_t(0))
**(**TFts5Buffer)(__ccgo_up(p1)) = **(**TFts5Buffer)(__ccgo_up(bp + 1032))
}
// C documentation
//
// /*
// ** This is the equivalent of fts5MergePrefixLists() for detail=none mode.
// ** In this case the buffers consist of a delta-encoded list of rowids only.
// */
func _fts5MergeRowidLists(tls *libc.TLS, p uintptr, p1 uintptr, nBuf int32, aBuf uintptr) {
bp := tls.Alloc(48)
defer tls.Free(48)
var iOut Ti64
var p2 uintptr
var _ /* i1 at bp+0 */ int32
var _ /* i2 at bp+4 */ int32
var _ /* iRowid1 at bp+8 */ Ti64
var _ /* iRowid2 at bp+16 */ Ti64
var _ /* out at bp+24 */ TFts5Buffer
_, _ = iOut, p2
**(**int32)(__ccgo_up(bp)) = 0
**(**int32)(__ccgo_up(bp + 4)) = 0
**(**Ti64)(__ccgo_up(bp + 8)) = 0
**(**Ti64)(__ccgo_up(bp + 16)) = 0
iOut = 0
p2 = aBuf
_ = nBuf
libc.X__builtin___memset_chk(tls, bp+24, 0, uint64(16), ^t__predefined_size_t(0))
_sqlite3Fts5BufferSize(tls, p+60, bp+24, libc.Uint32FromInt32((*TFts5Buffer)(unsafe.Pointer(p1)).Fn+(*TFts5Buffer)(unsafe.Pointer(p2)).Fn))
if (*TFts5Index)(unsafe.Pointer(p)).Frc != 0 {
return
}
_fts5NextRowid(tls, p1, bp, bp+8)
_fts5NextRowid(tls, p2, bp+4, bp+16)
for **(**int32)(__ccgo_up(bp)) >= 0 || **(**int32)(__ccgo_up(bp + 4)) >= 0 {
if **(**int32)(__ccgo_up(bp)) >= 0 && (**(**int32)(__ccgo_up(bp + 4)) < 0 || **(**Ti64)(__ccgo_up(bp + 8)) < **(**Ti64)(__ccgo_up(bp + 16))) {
**(**int32)(__ccgo_up(bp + 24 + 8)) += _sqlite3Fts5PutVarint(tls, (*TFts5Buffer)(unsafe.Pointer(bp+24)).Fp+uintptr((*TFts5Buffer)(unsafe.Pointer(bp+24)).Fn), libc.Uint64FromInt64(**(**Ti64)(__ccgo_up(bp + 8))-iOut))
iOut = **(**Ti64)(__ccgo_up(bp + 8))
_fts5NextRowid(tls, p1, bp, bp+8)
} else {
**(**int32)(__ccgo_up(bp + 24 + 8)) += _sqlite3Fts5PutVarint(tls, (*TFts5Buffer)(unsafe.Pointer(bp+24)).Fp+uintptr((*TFts5Buffer)(unsafe.Pointer(bp+24)).Fn), libc.Uint64FromInt64(**(**Ti64)(__ccgo_up(bp + 16))-iOut))
iOut = **(**Ti64)(__ccgo_up(bp + 16))
if **(**int32)(__ccgo_up(bp)) >= 0 && **(**Ti64)(__ccgo_up(bp + 8)) == **(**Ti64)(__ccgo_up(bp + 16)) {
_fts5NextRowid(tls, p1, bp, bp+8)
}
_fts5NextRowid(tls, p2, bp+4, bp+16)
}
}
_fts5BufferSwap(tls, bp+24, p1)
_sqlite3Fts5BufferFree(tls, bp+24)
}
// C documentation
//
// /*
// ** This function is used by xCreateTokenizer_v2() and xCreateTokenizer().
// ** It allocates and partially populates a new Fts5TokenizerModule object.
// ** The new object is already linked into the Fts5Global context before
// ** returning.
// **
// ** If successful, SQLITE_OK is returned and a pointer to the new
// ** Fts5TokenizerModule object returned via output parameter (*ppNew). All
// ** that is required is for the caller to fill in the methods in
// ** Fts5TokenizerModule.x1 and x2, and to set Fts5TokenizerModule.bV2Native
// ** as appropriate.
// **
// ** If an error occurs, an SQLite error code is returned and the final value
// ** of (*ppNew) undefined.
// */
func _fts5NewTokenizerModule(tls *libc.TLS, pGlobal uintptr, zName uintptr, pUserData uintptr, __ccgo_fp_xDestroy uintptr, ppNew uintptr) (r int32) {
bp := tls.Alloc(16)
defer tls.Free(16)
var nByte, nName Tsqlite3_int64
var pNew, v1 uintptr
var _ /* rc at bp+0 */ int32
_, _, _, _ = nByte, nName, pNew, v1
**(**int32)(__ccgo_up(bp)) = SQLITE_OK /* Bytes of space to allocate */
nName = libc.Int64FromUint64(libc.Xstrlen(tls, zName) + uint64(1))
nByte = libc.Int64FromUint64(uint64(96) + libc.Uint64FromInt64(nName))
v1 = _sqlite3Fts5MallocZero(tls, bp, nByte)
pNew = v1
**(**uintptr)(__ccgo_up(ppNew)) = v1
if pNew != 0 {
(*TFts5TokenizerModule)(unsafe.Pointer(pNew)).FzName = pNew + 1*96
libc.X__builtin___memcpy_chk(tls, (*TFts5TokenizerModule)(unsafe.Pointer(pNew)).FzName, zName, libc.Uint64FromInt64(nName), ^t__predefined_size_t(0))
(*TFts5TokenizerModule)(unsafe.Pointer(pNew)).FpUserData = pUserData
(*TFts5TokenizerModule)(unsafe.Pointer(pNew)).FxDestroy = __ccgo_fp_xDestroy
(*TFts5TokenizerModule)(unsafe.Pointer(pNew)).FpNext = (*TFts5Global)(unsafe.Pointer(pGlobal)).FpTok
(*TFts5Global)(unsafe.Pointer(pGlobal)).FpTok = pNew
if (*TFts5TokenizerModule)(unsafe.Pointer(pNew)).FpNext == uintptr(0) {
(*TFts5Global)(unsafe.Pointer(pGlobal)).FpDfltTok = pNew
}
}
return **(**int32)(__ccgo_up(bp))
}
// C documentation
//
// /*
// ** Implementation of xOpen method.
// */
func _fts5OpenMethod(tls *libc.TLS, pVTab uintptr, ppCsr uintptr) (r int32) {
var nByte Tsqlite3_int64
var pConfig, pCsr, pGlobal, pTab, v2 uintptr
var rc int32
var v1 Ti64
_, _, _, _, _, _, _, _ = nByte, pConfig, pCsr, pGlobal, pTab, rc, v1, v2
pTab = pVTab
pConfig = (*TFts5FullTable)(unsafe.Pointer(pTab)).Fp.FpConfig
pCsr = uintptr(0) /* Return code */
rc = _fts5NewTransaction(tls, pTab)
if rc == SQLITE_OK {
nByte = libc.Int64FromUint64(uint64(184) + libc.Uint64FromInt32((*TFts5Config)(unsafe.Pointer(pConfig)).FnCol)*uint64(4))
pCsr = Xsqlite3_malloc64(tls, libc.Uint64FromInt64(nByte))
if pCsr != 0 {
pGlobal = (*TFts5FullTable)(unsafe.Pointer(pTab)).FpGlobal
libc.X__builtin___memset_chk(tls, pCsr, 0, libc.Uint64FromInt64(nByte), ^t__predefined_size_t(0))
(*TFts5Cursor)(unsafe.Pointer(pCsr)).FaColumnSize = pCsr + 1*184
(*TFts5Cursor)(unsafe.Pointer(pCsr)).FpNext = (*TFts5Global)(unsafe.Pointer(pGlobal)).FpCsr
(*TFts5Global)(unsafe.Pointer(pGlobal)).FpCsr = pCsr
v2 = pGlobal + 56
*(*Ti64)(unsafe.Pointer(v2)) = *(*Ti64)(unsafe.Pointer(v2)) + 1
v1 = *(*Ti64)(unsafe.Pointer(v2))
(*TFts5Cursor)(unsafe.Pointer(pCsr)).FiCsrId = v1
} else {
rc = int32(SQLITE_NOMEM)
}
}
**(**uintptr)(__ccgo_up(ppCsr)) = pCsr
return rc
}
// C documentation
//
// /*
// ** Callback for tokenizing terms used by ParseTerm().
// */
func _fts5ParseTokenize(tls *libc.TLS, pContext uintptr, tflags int32, pToken uintptr, nToken int32, iUnused1 int32, iUnused2 int32) (r int32) {
bp := tls.Alloc(16)
defer tls.Free(16)
var SZALLOC, nNew, v1 int32
var nByte Tsqlite3_int64
var pCtx, pNew, pPhrase, pSyn, pTerm, v3 uintptr
var _ /* rc at bp+0 */ int32
_, _, _, _, _, _, _, _, _, _ = SZALLOC, nByte, nNew, pCtx, pNew, pPhrase, pSyn, pTerm, v1, v3
**(**int32)(__ccgo_up(bp)) = SQLITE_OK
SZALLOC = int32(8)
pCtx = pContext
pPhrase = (*TTokenCtx)(unsafe.Pointer(pCtx)).FpPhrase
_ = iUnused1
_ = iUnused2
/* If an error has already occurred, this is a no-op */
if (*TTokenCtx)(unsafe.Pointer(pCtx)).Frc != SQLITE_OK {
return (*TTokenCtx)(unsafe.Pointer(pCtx)).Frc
}
if nToken > int32(FTS5_MAX_TOKEN_SIZE) {
nToken = int32(FTS5_MAX_TOKEN_SIZE)
}
if pPhrase != 0 && (*TFts5ExprPhrase)(unsafe.Pointer(pPhrase)).FnTerm > 0 && tflags&int32(FTS5_TOKEN_COLOCATED) != 0 {
nByte = libc.Int64FromUint64(libc.Uint64FromInt64(40) + libc.Uint64FromInt64(16) + libc.Uint64FromInt32(nToken) + uint64(1))
pSyn = Xsqlite3_malloc64(tls, libc.Uint64FromInt64(nByte))
if pSyn == uintptr(0) {
**(**int32)(__ccgo_up(bp)) = int32(SQLITE_NOMEM)
} else {
libc.X__builtin___memset_chk(tls, pSyn, 0, libc.Uint64FromInt64(nByte), ^t__predefined_size_t(0))
(*TFts5ExprTerm)(unsafe.Pointer(pSyn)).FpTerm = pSyn + uintptr(40) + uintptr(16)
v1 = nToken
(*TFts5ExprTerm)(unsafe.Pointer(pSyn)).FnQueryTerm = v1
(*TFts5ExprTerm)(unsafe.Pointer(pSyn)).FnFullTerm = v1
libc.X__builtin___memcpy_chk(tls, (*TFts5ExprTerm)(unsafe.Pointer(pSyn)).FpTerm, pToken, libc.Uint64FromInt32(nToken), ^t__predefined_size_t(0))
if (*TFts5Config)(unsafe.Pointer((*TTokenCtx)(unsafe.Pointer(pCtx)).FpConfig)).FbTokendata != 0 {
(*TFts5ExprTerm)(unsafe.Pointer(pSyn)).FnQueryTerm = libc.Int32FromUint64(libc.Xstrlen(tls, (*TFts5ExprTerm)(unsafe.Pointer(pSyn)).FpTerm))
}
(*TFts5ExprTerm)(unsafe.Pointer(pSyn)).FpSynonym = (*(*TFts5ExprTerm)(unsafe.Pointer(pPhrase + 32 + uintptr((*TFts5ExprPhrase)(unsafe.Pointer(pPhrase)).FnTerm-int32(1))*40))).FpSynonym
(*(*TFts5ExprTerm)(unsafe.Pointer(pPhrase + 32 + uintptr((*TFts5ExprPhrase)(unsafe.Pointer(pPhrase)).FnTerm-int32(1))*40))).FpSynonym = pSyn
}
} else {
if pPhrase == uintptr(0) || (*TFts5ExprPhrase)(unsafe.Pointer(pPhrase)).FnTerm%SZALLOC == 0 {
if pPhrase != 0 {
v1 = (*TFts5ExprPhrase)(unsafe.Pointer(pPhrase)).FnTerm
} else {
v1 = 0
}
nNew = SZALLOC + v1
pNew = Xsqlite3_realloc64(tls, pPhrase, uint64(uint64(libc.UintptrFromInt32(0)+32)+libc.Uint64FromInt32(nNew+libc.Int32FromInt32(1))*libc.Uint64FromInt64(40)))
if pNew == uintptr(0) {
**(**int32)(__ccgo_up(bp)) = int32(SQLITE_NOMEM)
} else {
if pPhrase == uintptr(0) {
libc.X__builtin___memset_chk(tls, pNew, 0, uint64(libc.UintptrFromInt32(0)+32)+libc.Uint64FromInt32(libc.Int32FromInt32(1))*libc.Uint64FromInt64(40), ^t__predefined_size_t(0))
}
v3 = pNew
pPhrase = v3
(*TTokenCtx)(unsafe.Pointer(pCtx)).FpPhrase = v3
(*TFts5ExprPhrase)(unsafe.Pointer(pNew)).FnTerm = nNew - SZALLOC
}
}
if **(**int32)(__ccgo_up(bp)) == SQLITE_OK {
v3 = pPhrase + 24
v1 = *(*int32)(unsafe.Pointer(v3))
*(*int32)(unsafe.Pointer(v3)) = *(*int32)(unsafe.Pointer(v3)) + 1
pTerm = pPhrase + 32 + uintptr(v1)*40
libc.X__builtin___memset_chk(tls, pTerm, 0, uint64(40), ^t__predefined_size_t(0))
(*TFts5ExprTerm)(unsafe.Pointer(pTerm)).FpTerm = _sqlite3Fts5Strndup(tls, bp, pToken, nToken)
v1 = nToken
(*TFts5ExprTerm)(unsafe.Pointer(pTerm)).FnQueryTerm = v1
(*TFts5ExprTerm)(unsafe.Pointer(pTerm)).FnFullTerm = v1
if (*TFts5Config)(unsafe.Pointer((*TTokenCtx)(unsafe.Pointer(pCtx)).FpConfig)).FbTokendata != 0 && **(**int32)(__ccgo_up(bp)) == SQLITE_OK {
(*TFts5ExprTerm)(unsafe.Pointer(pTerm)).FnQueryTerm = libc.Int32FromUint64(libc.Xstrlen(tls, (*TFts5ExprTerm)(unsafe.Pointer(pTerm)).FpTerm))
}
}
}
(*TTokenCtx)(unsafe.Pointer(pCtx)).Frc = **(**int32)(__ccgo_up(bp))
return **(**int32)(__ccgo_up(bp))
}
func _fts5PorterCb(tls *libc.TLS, pCtx uintptr, tflags int32, pToken uintptr, nToken int32, iStart int32, iEnd int32) (r int32) {
bp := tls.Alloc(16)
defer tls.Free(16)
var aBuf, p uintptr
var c int8
var v1 int32
var _ /* nBuf at bp+0 */ int32
_, _, _, _ = aBuf, c, p, v1
p = pCtx
if nToken > int32(FTS5_PORTER_MAX_TOKEN) || nToken < int32(3) {
goto pass_through
}
aBuf = (*TPorterContext)(unsafe.Pointer(p)).FaBuf
**(**int32)(__ccgo_up(bp)) = nToken
libc.X__builtin___memcpy_chk(tls, aBuf, pToken, libc.Uint64FromInt32(**(**int32)(__ccgo_up(bp))), ^t__predefined_size_t(0))
/* Step 1. */
_fts5PorterStep1A(tls, aBuf, bp)
if _fts5PorterStep1B(tls, aBuf, bp) != 0 {
if _fts5PorterStep1B2(tls, aBuf, bp) == 0 {
c = **(**int8)(__ccgo_up(aBuf + uintptr(**(**int32)(__ccgo_up(bp))-int32(1))))
if _fts5PorterIsVowel(tls, c, 0) == 0 && int32(c) != int32('l') && int32(c) != int32('s') && int32(c) != int32('z') && int32(c) == int32(**(**int8)(__ccgo_up(aBuf + uintptr(**(**int32)(__ccgo_up(bp))-int32(2))))) {
**(**int32)(__ccgo_up(bp)) = **(**int32)(__ccgo_up(bp)) - 1
} else {
if _fts5Porter_MEq1(tls, aBuf, **(**int32)(__ccgo_up(bp))) != 0 && _fts5Porter_Ostar(tls, aBuf, **(**int32)(__ccgo_up(bp))) != 0 {
v1 = **(**int32)(__ccgo_up(bp))
**(**int32)(__ccgo_up(bp)) = **(**int32)(__ccgo_up(bp)) + 1
**(**int8)(__ccgo_up(aBuf + uintptr(v1))) = int8('e')
}
}
}
}
/* Step 1C. */
if int32(**(**int8)(__ccgo_up(aBuf + uintptr(**(**int32)(__ccgo_up(bp))-int32(1))))) == int32('y') && _fts5Porter_Vowel(tls, aBuf, **(**int32)(__ccgo_up(bp))-int32(1)) != 0 {
**(**int8)(__ccgo_up(aBuf + uintptr(**(**int32)(__ccgo_up(bp))-int32(1)))) = int8('i')
}
/* Steps 2 through 4. */
_fts5PorterStep2(tls, aBuf, bp)
_fts5PorterStep3(tls, aBuf, bp)
_fts5PorterStep4(tls, aBuf, bp)
/* Step 5a. */
if int32(**(**int8)(__ccgo_up(aBuf + uintptr(**(**int32)(__ccgo_up(bp))-int32(1))))) == int32('e') {
if _fts5Porter_MGt1(tls, aBuf, **(**int32)(__ccgo_up(bp))-int32(1)) != 0 || _fts5Porter_MEq1(tls, aBuf, **(**int32)(__ccgo_up(bp))-int32(1)) != 0 && !(_fts5Porter_Ostar(tls, aBuf, **(**int32)(__ccgo_up(bp))-int32(1)) != 0) {
**(**int32)(__ccgo_up(bp)) = **(**int32)(__ccgo_up(bp)) - 1
}
}
/* Step 5b. */
if **(**int32)(__ccgo_up(bp)) > int32(1) && int32(**(**int8)(__ccgo_up(aBuf + uintptr(**(**int32)(__ccgo_up(bp))-int32(1))))) == int32('l') && int32(**(**int8)(__ccgo_up(aBuf + uintptr(**(**int32)(__ccgo_up(bp))-int32(2))))) == int32('l') && _fts5Porter_MGt1(tls, aBuf, **(**int32)(__ccgo_up(bp))-int32(1)) != 0 {
**(**int32)(__ccgo_up(bp)) = **(**int32)(__ccgo_up(bp)) - 1
}
return (*(*func(*libc.TLS, uintptr, int32, uintptr, int32, int32, int32) int32)(unsafe.Pointer(&struct{ uintptr }{(*TPorterContext)(unsafe.Pointer(p)).FxToken})))(tls, (*TPorterContext)(unsafe.Pointer(p)).FpCtx, tflags, aBuf, **(**int32)(__ccgo_up(bp)), iStart, iEnd)
goto pass_through
pass_through:
;
return (*(*func(*libc.TLS, uintptr, int32, uintptr, int32, int32, int32) int32)(unsafe.Pointer(&struct{ uintptr }{(*TPorterContext)(unsafe.Pointer(p)).FxToken})))(tls, (*TPorterContext)(unsafe.Pointer(p)).FpCtx, tflags, pToken, nToken, iStart, iEnd)
return r
}
// C documentation
//
// /*
// ** Create a "porter" tokenizer.
// */
func _fts5PorterCreate(tls *libc.TLS, pCtx uintptr, azArg uintptr, nArg int32, ppOut uintptr) (r int32) {
bp := tls.Alloc(16)
defer tls.Free(16)
var az2, pApi, pRet, zBase, v2 uintptr
var nArg2, rc, v1 int32
var _ /* pUserdata at bp+0 */ uintptr
var _ /* pV2 at bp+8 */ uintptr
_, _, _, _, _, _, _, _ = az2, nArg2, pApi, pRet, rc, zBase, v1, v2
pApi = pCtx
rc = SQLITE_OK
**(**uintptr)(__ccgo_up(bp)) = uintptr(0)
zBase = __ccgo_ts + 42283
**(**uintptr)(__ccgo_up(bp + 8)) = uintptr(0)
for nArg > 0 {
if Xsqlite3_stricmp(tls, **(**uintptr)(__ccgo_up(azArg)), __ccgo_ts+42293) == 0 {
nArg = nArg - 1
azArg += 8
} else {
zBase = **(**uintptr)(__ccgo_up(azArg))
break
}
}
pRet = Xsqlite3_malloc64(tls, uint64(168))
if pRet != 0 {
libc.X__builtin___memset_chk(tls, pRet, 0, uint64(168), ^t__predefined_size_t(0))
rc = (*(*func(*libc.TLS, uintptr, uintptr, uintptr, uintptr) int32)(unsafe.Pointer(&struct{ uintptr }{(*Tfts5_api)(unsafe.Pointer(pApi)).FxFindTokenizer_v2})))(tls, pApi, zBase, bp, bp+8)
} else {
rc = int32(SQLITE_NOMEM)
}
if rc == SQLITE_OK {
if nArg > 0 {
v1 = nArg - int32(1)
} else {
v1 = 0
}
nArg2 = v1
if nArg2 != 0 {
v2 = azArg + 1*8
} else {
v2 = uintptr(0)
}
az2 = v2
libc.X__builtin___memcpy_chk(tls, pRet, **(**uintptr)(__ccgo_up(bp + 8)), uint64(32), ^t__predefined_size_t(0))
rc = (*(*func(*libc.TLS, uintptr, uintptr, int32, uintptr) int32)(unsafe.Pointer(&struct{ uintptr }{(*TPorterTokenizer)(unsafe.Pointer(pRet)).Ftokenizer_v2.FxCreate})))(tls, **(**uintptr)(__ccgo_up(bp)), az2, nArg2, pRet+32)
}
if rc != SQLITE_OK {
_fts5PorterDelete(tls, pRet)
pRet = uintptr(0)
}
**(**uintptr)(__ccgo_up(ppOut)) = pRet
return rc
}
func _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+42565, aBuf+uintptr(nBuf-int32(3)), uint64(3)) {
if _fts5Porter_MGt0(tls, aBuf, nBuf-int32(3)) != 0 {
libc.X__builtin___memcpy_chk(tls, aBuf+uintptr(nBuf-int32(3)), __ccgo_ts+42569, uint64(2), ^t__predefined_size_t(0))
**(**int32)(__ccgo_up(pnBuf)) = nBuf - int32(3) + int32(2)
}
} else {
if nBuf > int32(2) && 0 == libc.Xmemcmp(tls, __ccgo_ts+42572, aBuf+uintptr(nBuf-int32(2)), uint64(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+42575, aBuf+uintptr(nBuf-int32(3)), uint64(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+42379, aBuf+uintptr(nBuf-int32(2)), uint64(2)) {
libc.X__builtin___memcpy_chk(tls, aBuf+uintptr(nBuf-int32(2)), __ccgo_ts+42359, uint64(3), ^t__predefined_size_t(0))
**(**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+42382, aBuf+uintptr(nBuf-int32(2)), uint64(2)) {
libc.X__builtin___memcpy_chk(tls, aBuf+uintptr(nBuf-int32(2)), __ccgo_ts+42385, uint64(3), ^t__predefined_size_t(0))
**(**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+42389, aBuf+uintptr(nBuf-int32(2)), uint64(2)) {
libc.X__builtin___memcpy_chk(tls, aBuf+uintptr(nBuf-int32(2)), __ccgo_ts+42375, uint64(3), ^t__predefined_size_t(0))
**(**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+42392, aBuf+uintptr(nBuf-int32(7)), uint64(7)) {
if _fts5Porter_MGt0(tls, aBuf, nBuf-int32(7)) != 0 {
libc.X__builtin___memcpy_chk(tls, aBuf+uintptr(nBuf-int32(7)), __ccgo_ts+42359, uint64(3), ^t__predefined_size_t(0))
**(**int32)(__ccgo_up(pnBuf)) = nBuf - int32(7) + int32(3)
}
} else {
if nBuf > int32(6) && 0 == libc.Xmemcmp(tls, __ccgo_ts+42400, aBuf+uintptr(nBuf-int32(6)), uint64(6)) {
if _fts5Porter_MGt0(tls, aBuf, nBuf-int32(6)) != 0 {
libc.X__builtin___memcpy_chk(tls, aBuf+uintptr(nBuf-int32(6)), __ccgo_ts+42407, uint64(4), ^t__predefined_size_t(0))
**(**int32)(__ccgo_up(pnBuf)) = nBuf - int32(6) + int32(4)
}
}
}
case int32('c'):
if nBuf > int32(4) && 0 == libc.Xmemcmp(tls, __ccgo_ts+42412, aBuf+uintptr(nBuf-int32(4)), uint64(4)) {
if _fts5Porter_MGt0(tls, aBuf, nBuf-int32(4)) != 0 {
libc.X__builtin___memcpy_chk(tls, aBuf+uintptr(nBuf-int32(4)), __ccgo_ts+42308, uint64(4), ^t__predefined_size_t(0))
**(**int32)(__ccgo_up(pnBuf)) = nBuf - int32(4) + int32(4)
}
} else {
if nBuf > int32(4) && 0 == libc.Xmemcmp(tls, __ccgo_ts+42417, aBuf+uintptr(nBuf-int32(4)), uint64(4)) {
if _fts5Porter_MGt0(tls, aBuf, nBuf-int32(4)) != 0 {
libc.X__builtin___memcpy_chk(tls, aBuf+uintptr(nBuf-int32(4)), __ccgo_ts+42303, uint64(4), ^t__predefined_size_t(0))
**(**int32)(__ccgo_up(pnBuf)) = nBuf - int32(4) + int32(4)
}
}
}
case int32('e'):
if nBuf > int32(4) && 0 == libc.Xmemcmp(tls, __ccgo_ts+42422, aBuf+uintptr(nBuf-int32(4)), uint64(4)) {
if _fts5Porter_MGt0(tls, aBuf, nBuf-int32(4)) != 0 {
libc.X__builtin___memcpy_chk(tls, aBuf+uintptr(nBuf-int32(4)), __ccgo_ts+42375, uint64(3), ^t__predefined_size_t(0))
**(**int32)(__ccgo_up(pnBuf)) = nBuf - int32(4) + int32(3)
}
}
case int32('g'):
if nBuf > int32(4) && 0 == libc.Xmemcmp(tls, __ccgo_ts+42427, aBuf+uintptr(nBuf-int32(4)), uint64(4)) {
if _fts5Porter_MGt0(tls, aBuf, nBuf-int32(4)) != 0 {
libc.X__builtin___memcpy_chk(tls, aBuf+uintptr(nBuf-int32(4)), __ccgo_ts+17513, uint64(3), ^t__predefined_size_t(0))
**(**int32)(__ccgo_up(pnBuf)) = nBuf - int32(4) + int32(3)
}
}
case int32('l'):
if nBuf > int32(3) && 0 == libc.Xmemcmp(tls, __ccgo_ts+42432, aBuf+uintptr(nBuf-int32(3)), uint64(3)) {
if _fts5Porter_MGt0(tls, aBuf, nBuf-int32(3)) != 0 {
libc.X__builtin___memcpy_chk(tls, aBuf+uintptr(nBuf-int32(3)), __ccgo_ts+42385, uint64(3), ^t__predefined_size_t(0))
**(**int32)(__ccgo_up(pnBuf)) = nBuf - int32(3) + int32(3)
}
} else {
if nBuf > int32(4) && 0 == libc.Xmemcmp(tls, __ccgo_ts+42436, aBuf+uintptr(nBuf-int32(4)), uint64(4)) {
if _fts5Porter_MGt0(tls, aBuf, nBuf-int32(4)) != 0 {
libc.X__builtin___memcpy_chk(tls, aBuf+uintptr(nBuf-int32(4)), __ccgo_ts+42300, uint64(2), ^t__predefined_size_t(0))
**(**int32)(__ccgo_up(pnBuf)) = nBuf - int32(4) + int32(2)
}
} else {
if nBuf > int32(5) && 0 == libc.Xmemcmp(tls, __ccgo_ts+42441, aBuf+uintptr(nBuf-int32(5)), uint64(5)) {
if _fts5Porter_MGt0(tls, aBuf, nBuf-int32(5)) != 0 {
libc.X__builtin___memcpy_chk(tls, aBuf+uintptr(nBuf-int32(5)), __ccgo_ts+42344, uint64(3), ^t__predefined_size_t(0))
**(**int32)(__ccgo_up(pnBuf)) = nBuf - int32(5) + int32(3)
}
} else {
if nBuf > int32(3) && 0 == libc.Xmemcmp(tls, __ccgo_ts+42447, aBuf+uintptr(nBuf-int32(3)), uint64(3)) {
if _fts5Porter_MGt0(tls, aBuf, nBuf-int32(3)) != 0 {
libc.X__builtin___memcpy_chk(tls, aBuf+uintptr(nBuf-int32(3)), __ccgo_ts+42451, uint64(1), ^t__predefined_size_t(0))
**(**int32)(__ccgo_up(pnBuf)) = nBuf - int32(3) + int32(1)
}
} else {
if nBuf > int32(5) && 0 == libc.Xmemcmp(tls, __ccgo_ts+42453, aBuf+uintptr(nBuf-int32(5)), uint64(5)) {
if _fts5Porter_MGt0(tls, aBuf, nBuf-int32(5)) != 0 {
libc.X__builtin___memcpy_chk(tls, aBuf+uintptr(nBuf-int32(5)), __ccgo_ts+42367, uint64(3), ^t__predefined_size_t(0))
**(**int32)(__ccgo_up(pnBuf)) = nBuf - int32(5) + int32(3)
}
}
}
}
}
}
case int32('o'):
if nBuf > int32(7) && 0 == libc.Xmemcmp(tls, __ccgo_ts+42459, aBuf+uintptr(nBuf-int32(7)), uint64(7)) {
if _fts5Porter_MGt0(tls, aBuf, nBuf-int32(7)) != 0 {
libc.X__builtin___memcpy_chk(tls, aBuf+uintptr(nBuf-int32(7)), __ccgo_ts+42375, uint64(3), ^t__predefined_size_t(0))
**(**int32)(__ccgo_up(pnBuf)) = nBuf - int32(7) + int32(3)
}
} else {
if nBuf > int32(5) && 0 == libc.Xmemcmp(tls, __ccgo_ts+42467, aBuf+uintptr(nBuf-int32(5)), uint64(5)) {
if _fts5Porter_MGt0(tls, aBuf, nBuf-int32(5)) != 0 {
libc.X__builtin___memcpy_chk(tls, aBuf+uintptr(nBuf-int32(5)), __ccgo_ts+42359, uint64(3), ^t__predefined_size_t(0))
**(**int32)(__ccgo_up(pnBuf)) = nBuf - int32(5) + int32(3)
}
} else {
if nBuf > int32(4) && 0 == libc.Xmemcmp(tls, __ccgo_ts+42473, aBuf+uintptr(nBuf-int32(4)), uint64(4)) {
if _fts5Porter_MGt0(tls, aBuf, nBuf-int32(4)) != 0 {
libc.X__builtin___memcpy_chk(tls, aBuf+uintptr(nBuf-int32(4)), __ccgo_ts+42359, uint64(3), ^t__predefined_size_t(0))
**(**int32)(__ccgo_up(pnBuf)) = nBuf - int32(4) + int32(3)
}
}
}
}
case int32('s'):
if nBuf > int32(5) && 0 == libc.Xmemcmp(tls, __ccgo_ts+42478, aBuf+uintptr(nBuf-int32(5)), uint64(5)) {
if _fts5Porter_MGt0(tls, aBuf, nBuf-int32(5)) != 0 {
libc.X__builtin___memcpy_chk(tls, aBuf+uintptr(nBuf-int32(5)), __ccgo_ts+42300, uint64(2), ^t__predefined_size_t(0))
**(**int32)(__ccgo_up(pnBuf)) = nBuf - int32(5) + int32(2)
}
} else {
if nBuf > int32(7) && 0 == libc.Xmemcmp(tls, __ccgo_ts+42484, aBuf+uintptr(nBuf-int32(7)), uint64(7)) {
if _fts5Porter_MGt0(tls, aBuf, nBuf-int32(7)) != 0 {
libc.X__builtin___memcpy_chk(tls, aBuf+uintptr(nBuf-int32(7)), __ccgo_ts+42371, uint64(3), ^t__predefined_size_t(0))
**(**int32)(__ccgo_up(pnBuf)) = nBuf - int32(7) + int32(3)
}
} else {
if nBuf > int32(7) && 0 == libc.Xmemcmp(tls, __ccgo_ts+42492, aBuf+uintptr(nBuf-int32(7)), uint64(7)) {
if _fts5Porter_MGt0(tls, aBuf, nBuf-int32(7)) != 0 {
libc.X__builtin___memcpy_chk(tls, aBuf+uintptr(nBuf-int32(7)), __ccgo_ts+42500, uint64(3), ^t__predefined_size_t(0))
**(**int32)(__ccgo_up(pnBuf)) = nBuf - int32(7) + int32(3)
}
} else {
if nBuf > int32(7) && 0 == libc.Xmemcmp(tls, __ccgo_ts+42504, aBuf+uintptr(nBuf-int32(7)), uint64(7)) {
if _fts5Porter_MGt0(tls, aBuf, nBuf-int32(7)) != 0 {
libc.X__builtin___memcpy_chk(tls, aBuf+uintptr(nBuf-int32(7)), __ccgo_ts+42367, uint64(3), ^t__predefined_size_t(0))
**(**int32)(__ccgo_up(pnBuf)) = nBuf - int32(7) + int32(3)
}
}
}
}
}
case int32('t'):
if nBuf > int32(5) && 0 == libc.Xmemcmp(tls, __ccgo_ts+42512, aBuf+uintptr(nBuf-int32(5)), uint64(5)) {
if _fts5Porter_MGt0(tls, aBuf, nBuf-int32(5)) != 0 {
libc.X__builtin___memcpy_chk(tls, aBuf+uintptr(nBuf-int32(5)), __ccgo_ts+42300, uint64(2), ^t__predefined_size_t(0))
**(**int32)(__ccgo_up(pnBuf)) = nBuf - int32(5) + int32(2)
}
} else {
if nBuf > int32(5) && 0 == libc.Xmemcmp(tls, __ccgo_ts+42518, aBuf+uintptr(nBuf-int32(5)), uint64(5)) {
if _fts5Porter_MGt0(tls, aBuf, nBuf-int32(5)) != 0 {
libc.X__builtin___memcpy_chk(tls, aBuf+uintptr(nBuf-int32(5)), __ccgo_ts+42371, uint64(3), ^t__predefined_size_t(0))
**(**int32)(__ccgo_up(pnBuf)) = nBuf - int32(5) + int32(3)
}
} else {
if nBuf > int32(6) && 0 == libc.Xmemcmp(tls, __ccgo_ts+42524, aBuf+uintptr(nBuf-int32(6)), uint64(6)) {
if _fts5Porter_MGt0(tls, aBuf, nBuf-int32(6)) != 0 {
libc.X__builtin___memcpy_chk(tls, aBuf+uintptr(nBuf-int32(6)), __ccgo_ts+42385, uint64(3), ^t__predefined_size_t(0))
**(**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+42531, aBuf+uintptr(nBuf-int32(4)), uint64(4)) {
if _fts5Porter_MGt0(tls, aBuf, nBuf-int32(4)) != 0 {
libc.X__builtin___memcpy_chk(tls, aBuf+uintptr(nBuf-int32(4)), __ccgo_ts+42316, uint64(2), ^t__predefined_size_t(0))
**(**int32)(__ccgo_up(pnBuf)) = nBuf - int32(4) + int32(2)
}
}
case int32('s'):
if nBuf > int32(4) && 0 == libc.Xmemcmp(tls, __ccgo_ts+42536, aBuf+uintptr(nBuf-int32(4)), uint64(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+42541, aBuf+uintptr(nBuf-int32(5)), uint64(5)) {
if _fts5Porter_MGt0(tls, aBuf, nBuf-int32(5)) != 0 {
libc.X__builtin___memcpy_chk(tls, aBuf+uintptr(nBuf-int32(5)), __ccgo_ts+42316, uint64(2), ^t__predefined_size_t(0))
**(**int32)(__ccgo_up(pnBuf)) = nBuf - int32(5) + int32(2)
}
} else {
if nBuf > int32(5) && 0 == libc.Xmemcmp(tls, __ccgo_ts+42547, aBuf+uintptr(nBuf-int32(5)), uint64(5)) {
if _fts5Porter_MGt0(tls, aBuf, nBuf-int32(5)) != 0 {
libc.X__builtin___memcpy_chk(tls, aBuf+uintptr(nBuf-int32(5)), __ccgo_ts+42316, uint64(2), ^t__predefined_size_t(0))
**(**int32)(__ccgo_up(pnBuf)) = nBuf - int32(5) + int32(2)
}
}
}
case int32('u'):
if nBuf > int32(3) && 0 == libc.Xmemcmp(tls, __ccgo_ts+42500, aBuf+uintptr(nBuf-int32(3)), uint64(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+42553, aBuf+uintptr(nBuf-int32(5)), uint64(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+42559, aBuf+uintptr(nBuf-int32(5)), uint64(5)) {
if _fts5Porter_MGt0(tls, aBuf, nBuf-int32(5)) != 0 {
libc.X__builtin___memcpy_chk(tls, aBuf+uintptr(nBuf-int32(5)), __ccgo_ts+42300, uint64(2), ^t__predefined_size_t(0))
**(**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+42300, aBuf+uintptr(nBuf-int32(2)), uint64(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+42303, aBuf+uintptr(nBuf-int32(4)), uint64(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+42308, aBuf+uintptr(nBuf-int32(4)), uint64(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+42313, aBuf+uintptr(nBuf-int32(2)), uint64(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+42316, aBuf+uintptr(nBuf-int32(2)), uint64(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+42319, aBuf+uintptr(nBuf-int32(4)), uint64(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+42324, aBuf+uintptr(nBuf-int32(4)), uint64(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+42329, aBuf+uintptr(nBuf-int32(3)), uint64(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+42333, aBuf+uintptr(nBuf-int32(5)), uint64(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+42339, aBuf+uintptr(nBuf-int32(4)), uint64(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+42344, aBuf+uintptr(nBuf-int32(3)), uint64(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+42348, aBuf+uintptr(nBuf-int32(3)), uint64(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+42352, aBuf+uintptr(nBuf-int32(2)), uint64(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+42355, aBuf+uintptr(nBuf-int32(3)), uint64(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+42359, aBuf+uintptr(nBuf-int32(3)), uint64(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+42363, aBuf+uintptr(nBuf-int32(3)), uint64(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+42367, aBuf+uintptr(nBuf-int32(3)), uint64(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+42371, aBuf+uintptr(nBuf-int32(3)), uint64(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+42375, aBuf+uintptr(nBuf-int32(3)), uint64(3)) {
if _fts5Porter_MGt1(tls, aBuf, nBuf-int32(3)) != 0 {
**(**int32)(__ccgo_up(pnBuf)) = nBuf - int32(3)
}
}
break
}
return ret
}
// C documentation
//
// /*
// ** Return a "position-list blob" corresponding to the current position of
// ** cursor pCsr via sqlite3_result_blob(). A position-list blob contains
// ** the current position-list for each phrase in the query associated with
// ** cursor pCsr.
// **
// ** A position-list blob begins with (nPhrase-1) varints, where nPhrase is
// ** the number of phrases in the query. Following the varints are the
// ** concatenated position lists for each phrase, in order.
// **
// ** The first varint (if it exists) contains the size of the position list
// ** for phrase 0. The second (same disclaimer) contains the size of position
// ** list 1. And so on. There is no size field for the final position list,
// ** as it can be derived from the total size of the blob.
// */
func _fts5PoslistBlob(tls *libc.TLS, pCtx uintptr, pCsr uintptr) (r int32) {
bp := tls.Alloc(80)
defer tls.Free(80)
var i, nByte, nPhrase, nPoslist int32
var _ /* dummy at bp+24 */ uintptr
var _ /* dummy at bp+40 */ uintptr
var _ /* nByte at bp+48 */ int32
var _ /* nPoslist at bp+64 */ int32
var _ /* pPoslist at bp+32 */ uintptr
var _ /* pPoslist at bp+56 */ uintptr
var _ /* rc at bp+0 */ int32
var _ /* val at bp+8 */ TFts5Buffer
_, _, _, _ = i, nByte, nPhrase, nPoslist
**(**int32)(__ccgo_up(bp)) = SQLITE_OK
nPhrase = _sqlite3Fts5ExprPhraseCount(tls, (*TFts5Cursor)(unsafe.Pointer(pCsr)).FpExpr)
libc.X__builtin___memset_chk(tls, bp+8, 0, uint64(16), ^t__predefined_size_t(0))
switch (*TFts5Config)(unsafe.Pointer((*TFts5Table)(unsafe.Pointer((*TFts5Cursor)(unsafe.Pointer(pCsr)).Fbase.FpVtab)).FpConfig)).FeDetail {
case FTS5_DETAIL_FULL:
goto _1
case int32(FTS5_DETAIL_COLUMNS):
goto _2
default:
goto _3
}
goto _4
_1:
;
/* Append the varints */
i = 0
_7:
;
if !(i < nPhrase-int32(1)) {
goto _5
}
nByte = _sqlite3Fts5ExprPoslist(tls, (*TFts5Cursor)(unsafe.Pointer(pCsr)).FpExpr, i, bp+24)
_sqlite3Fts5BufferAppendVarint(tls, bp, bp+8, int64(nByte))
goto _6
_6:
;
i = i + 1
goto _7
goto _5
_5:
;
/* Append the position lists */
i = 0
for {
if !(i < nPhrase) {
break
}
nPoslist = _sqlite3Fts5ExprPoslist(tls, (*TFts5Cursor)(unsafe.Pointer(pCsr)).FpExpr, i, bp+32)
_sqlite3Fts5BufferAppendBlob(tls, bp, bp+8, libc.Uint32FromInt32(nPoslist), **(**uintptr)(__ccgo_up(bp + 32)))
goto _8
_8:
;
i = i + 1
}
goto _4
_2:
;
/* Append the varints */
i = 0
for {
if !(**(**int32)(__ccgo_up(bp)) == SQLITE_OK && i < nPhrase-int32(1)) {
break
}
**(**int32)(__ccgo_up(bp)) = _sqlite3Fts5ExprPhraseCollist(tls, (*TFts5Cursor)(unsafe.Pointer(pCsr)).FpExpr, i, bp+40, bp+48)
_sqlite3Fts5BufferAppendVarint(tls, bp, bp+8, int64(**(**int32)(__ccgo_up(bp + 48))))
goto _9
_9:
;
i = i + 1
}
/* Append the position lists */
i = 0
for {
if !(**(**int32)(__ccgo_up(bp)) == SQLITE_OK && i < nPhrase) {
break
}
**(**int32)(__ccgo_up(bp)) = _sqlite3Fts5ExprPhraseCollist(tls, (*TFts5Cursor)(unsafe.Pointer(pCsr)).FpExpr, i, bp+56, bp+64)
_sqlite3Fts5BufferAppendBlob(tls, bp, bp+8, libc.Uint32FromInt32(**(**int32)(__ccgo_up(bp + 64))), **(**uintptr)(__ccgo_up(bp + 56)))
goto _10
_10:
;
i = i + 1
}
goto _4
_3:
;
goto _4
_4:
;
Xsqlite3_result_blob(tls, pCtx, (**(**TFts5Buffer)(__ccgo_up(bp + 8))).Fp, (**(**TFts5Buffer)(__ccgo_up(bp + 8))).Fn, __ccgo_fp(Xsqlite3_free))
return **(**int32)(__ccgo_up(bp))
}
func _fts5PoslistCallback(tls *libc.TLS, pUnused uintptr, pContext uintptr, pChunk uintptr, nChunk int32) {
_ = pUnused
if nChunk > 0 {
libc.X__builtin___memcpy_chk(tls, (*TFts5Buffer)(unsafe.Pointer(pContext)).Fp+uintptr((*TFts5Buffer)(unsafe.Pointer(pContext)).Fn), pChunk, libc.Uint64FromInt32(nChunk), ^t__predefined_size_t(0))
**(**int32)(__ccgo_up(pContext + 8)) += nChunk
}
}
func _fts5PoslistFilterCallback(tls *libc.TLS, pUnused uintptr, pContext uintptr, pChunk uintptr, nChunk int32) {
bp := tls.Alloc(16)
defer tls.Free(16)
var i, iEnd, iStart, v1 int32
var pCtx uintptr
var _ /* iCol at bp+0 */ int32
var _ /* iCol at bp+4 */ int32
_, _, _, _, _ = i, iEnd, iStart, pCtx, v1
pCtx = pContext
_ = pUnused
if nChunk > 0 {
/* Search through to find the first varint with value 1. This is the
** start of the next columns hits. */
i = 0
iStart = 0
if (*TPoslistCallbackCtx)(unsafe.Pointer(pCtx)).FeState == int32(2) {
v1 = i
i = i + 1
**(**int32)(__ccgo_up(bp)) = libc.Int32FromUint8(**(**Tu8)(__ccgo_up(pChunk + uintptr(v1))))
if **(**int32)(__ccgo_up(bp))&int32(0x80) != 0 {
i = i - 1
i = i + _sqlite3Fts5GetVarint32(tls, pChunk+uintptr(i), bp)
}
if _fts5IndexColsetTest(tls, (*TPoslistCallbackCtx)(unsafe.Pointer(pCtx)).FpColset, **(**int32)(__ccgo_up(bp))) != 0 {
(*TPoslistCallbackCtx)(unsafe.Pointer(pCtx)).FeState = int32(1)
**(**int32)(__ccgo_up((*TPoslistCallbackCtx)(unsafe.Pointer(pCtx)).FpBuf + 8)) += _sqlite3Fts5PutVarint(tls, (*TFts5Buffer)(unsafe.Pointer((*TPoslistCallbackCtx)(unsafe.Pointer(pCtx)).FpBuf)).Fp+uintptr((*TFts5Buffer)(unsafe.Pointer((*TPoslistCallbackCtx)(unsafe.Pointer(pCtx)).FpBuf)).Fn), libc.Uint64FromInt32(libc.Int32FromInt32(1)))
} else {
(*TPoslistCallbackCtx)(unsafe.Pointer(pCtx)).FeState = 0
}
}
for cond := true; cond; cond = i < nChunk {
for i < nChunk && libc.Int32FromUint8(**(**Tu8)(__ccgo_up(pChunk + uintptr(i)))) != int32(0x01) {
iEnd = i + int32(9)
for {
v1 = i
i = i + 1
if !(libc.Int32FromUint8(**(**Tu8)(__ccgo_up(pChunk + uintptr(v1))))&int32(0x80) != 0 && i < iEnd) {
break
}
}
}
if (*TPoslistCallbackCtx)(unsafe.Pointer(pCtx)).FeState != 0 {
libc.X__builtin___memcpy_chk(tls, (*TFts5Buffer)(unsafe.Pointer((*TPoslistCallbackCtx)(unsafe.Pointer(pCtx)).FpBuf)).Fp+uintptr((*TFts5Buffer)(unsafe.Pointer((*TPoslistCallbackCtx)(unsafe.Pointer(pCtx)).FpBuf)).Fn), pChunk+uintptr(iStart), libc.Uint64FromInt32(i-iStart), ^t__predefined_size_t(0))
**(**int32)(__ccgo_up((*TPoslistCallbackCtx)(unsafe.Pointer(pCtx)).FpBuf + 8)) += i - iStart
}
if i < nChunk {
iStart = i
i = i + 1
if i >= nChunk {
(*TPoslistCallbackCtx)(unsafe.Pointer(pCtx)).FeState = int32(2)
} else {
v1 = i
i = i + 1
**(**int32)(__ccgo_up(bp + 4)) = libc.Int32FromUint8(**(**Tu8)(__ccgo_up(pChunk + uintptr(v1))))
if **(**int32)(__ccgo_up(bp + 4))&int32(0x80) != 0 {
i = i - 1
i = i + _sqlite3Fts5GetVarint32(tls, pChunk+uintptr(i), bp+4)
}
(*TPoslistCallbackCtx)(unsafe.Pointer(pCtx)).FeState = _fts5IndexColsetTest(tls, (*TPoslistCallbackCtx)(unsafe.Pointer(pCtx)).FpColset, **(**int32)(__ccgo_up(bp + 4)))
if (*TPoslistCallbackCtx)(unsafe.Pointer(pCtx)).FeState != 0 {
libc.X__builtin___memcpy_chk(tls, (*TFts5Buffer)(unsafe.Pointer((*TPoslistCallbackCtx)(unsafe.Pointer(pCtx)).FpBuf)).Fp+uintptr((*TFts5Buffer)(unsafe.Pointer((*TPoslistCallbackCtx)(unsafe.Pointer(pCtx)).FpBuf)).Fn), pChunk+uintptr(iStart), libc.Uint64FromInt32(i-iStart), ^t__predefined_size_t(0))
**(**int32)(__ccgo_up((*TPoslistCallbackCtx)(unsafe.Pointer(pCtx)).FpBuf + 8)) += i - iStart
iStart = i
}
}
}
}
}
}
// C documentation
//
// /*
// ** Execute the SQL statement:
// **
// ** DELETE FROM %_idx WHERE (segid, (pgno/2)) = ($iSegid, $iPgno);
// **
// ** This is used when a secure-delete operation removes the last term
// ** from a segment leaf page. In that case the %_idx entry is removed
// ** too. This is done to ensure that if all instances of a token are
// ** removed from an fts5 database in secure-delete mode, no trace of
// ** the token itself remains in the database.
// */
func _fts5SecureDeleteIdxEntry(tls *libc.TLS, p uintptr, iSegid int32, iPgno int32) {
bp := tls.Alloc(32)
defer tls.Free(32)
if iPgno != int32(1) {
if (*TFts5Index)(unsafe.Pointer(p)).FpDeleteFromIdx == uintptr(0) {
_fts5IndexPrepareStmt(tls, p, p+136, Xsqlite3_mprintf(tls, __ccgo_ts+39774, 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
//
// /*
// ** This is called when a secure-delete operation removes a position-list
// ** that overflows onto segment page iPgno of segment pSeg. This function
// ** rewrites node iPgno, and possibly one or more of its right-hand peers,
// ** to remove this portion of the position list.
// **
// ** Output variable (*pbLastInDoclist) is set to true if the position-list
// ** removed is followed by a new term or the end-of-segment, or false if
// ** it is followed by another rowid/position list.
// */
func _fts5SecureDeleteOverflow(tls *libc.TLS, p uintptr, pSeg uintptr, iPgno int32, pbLastInDoclist uintptr) {
bp := tls.Alloc(16)
defer tls.Free(16)
var aIdx, aPg, pLeaf uintptr
var bDetailNone, i1, i2, nIdx, nPg, nShift, pgno int32
var iRowid Ti64
var _ /* aEmpty at bp+4 */ [4]Tu8
var _ /* iFirst at bp+8 */ int32
var _ /* iNext at bp+0 */ int32
_, _, _, _, _, _, _, _, _, _, _ = aIdx, aPg, bDetailNone, i1, i2, iRowid, nIdx, nPg, nShift, pLeaf, pgno
bDetailNone = libc.BoolInt32((*TFts5Config)(unsafe.Pointer((*TFts5Index)(unsafe.Pointer(p)).FpConfig)).FeDetail == libc.Int32FromInt32(FTS5_DETAIL_NONE))
pLeaf = uintptr(0)
**(**int32)(__ccgo_up(pbLastInDoclist)) = int32(1)
pgno = iPgno
for {
if !((*TFts5Index)(unsafe.Pointer(p)).Frc == SQLITE_OK && pgno <= (*TFts5StructureSegment)(unsafe.Pointer(pSeg)).FpgnoLast) {
break
}
iRowid = int64((*TFts5StructureSegment)(unsafe.Pointer(pSeg)).FiSegid)<<(libc.Int32FromInt32(FTS5_DATA_PAGE_B)+libc.Int32FromInt32(FTS5_DATA_HEIGHT_B)+libc.Int32FromInt32(FTS5_DATA_DLI_B)) + int64(libc.Int32FromInt32(0))<<(libc.Int32FromInt32(FTS5_DATA_PAGE_B)+libc.Int32FromInt32(FTS5_DATA_HEIGHT_B)) + int64(libc.Int32FromInt32(0))<= (*TFts5Data)(unsafe.Pointer(pLeaf)).FszLeaf || (*TFts5Data)(unsafe.Pointer(pLeaf)).Fnn < (*TFts5Data)(unsafe.Pointer(pLeaf)).FszLeaf || **(**int32)(__ccgo_up(bp)) < int32(4) {
_fts5IndexCorruptRowid(tls, p, iRowid)
break
} else {
nShift = **(**int32)(__ccgo_up(bp)) - int32(4)
nIdx = 0
aIdx = uintptr(0)
/* Unless the current page footer is 0 bytes in size (in which case
** the new page footer will be as well), allocate and populate a
** buffer containing the new page footer. Set stack variables aIdx
** and nIdx accordingly. */
if (*TFts5Data)(unsafe.Pointer(pLeaf)).Fnn > (*TFts5Data)(unsafe.Pointer(pLeaf)).FszLeaf {
**(**int32)(__ccgo_up(bp + 8)) = 0
i1 = (*TFts5Data)(unsafe.Pointer(pLeaf)).FszLeaf
i2 = 0
i1 = i1 + _sqlite3Fts5GetVarint32(tls, aPg+uintptr(i1), bp+8)
if **(**int32)(__ccgo_up(bp + 8)) < **(**int32)(__ccgo_up(bp)) {
_fts5IndexCorruptRowid(tls, p, iRowid)
break
}
aIdx = _sqlite3Fts5MallocZero(tls, p+60, int64((*TFts5Data)(unsafe.Pointer(pLeaf)).Fnn-(*TFts5Data)(unsafe.Pointer(pLeaf)).FszLeaf+int32(2)))
if aIdx == uintptr(0) {
break
}
i2 = _sqlite3Fts5PutVarint(tls, aIdx, libc.Uint64FromInt32(**(**int32)(__ccgo_up(bp + 8))-nShift))
if i1 < (*TFts5Data)(unsafe.Pointer(pLeaf)).Fnn {
libc.X__builtin___memcpy_chk(tls, aIdx+uintptr(i2), aPg+uintptr(i1), libc.Uint64FromInt32((*TFts5Data)(unsafe.Pointer(pLeaf)).Fnn-i1), ^t__predefined_size_t(0))
i2 = i2 + ((*TFts5Data)(unsafe.Pointer(pLeaf)).Fnn - i1)
}
nIdx = i2
}
/* Modify the contents of buffer aPg[]. Set nPg to the new size
** in bytes. The new page is always smaller than the old. */
nPg = (*TFts5Data)(unsafe.Pointer(pLeaf)).FszLeaf - nShift
libc.X__builtin___memmove_chk(tls, aPg+4, aPg+uintptr(int32(4)+nShift), libc.Uint64FromInt32(nPg-int32(4)), ^t__predefined_size_t(0))
_fts5PutU16(tls, aPg+2, libc.Uint16FromInt32(nPg))
if _fts5GetU16(tls, aPg) != 0 {
_fts5PutU16(tls, aPg, uint16(4))
}
if nIdx > 0 {
libc.X__builtin___memcpy_chk(tls, aPg+uintptr(nPg), aIdx, libc.Uint64FromInt32(nIdx), ^t__predefined_size_t(0))
nPg = nPg + nIdx
}
Xsqlite3_free(tls, aIdx)
/* Write the new page to disk and exit the loop */
_fts5DataWrite(tls, p, iRowid, aPg, nPg)
break
}
}
}
goto _1
_1:
;
pgno = pgno + 1
}
_fts5DataRelease(tls, pLeaf)
}
// C documentation
//
// /*
// ** If the cursor requires seeking (bSeekRequired flag is set), seek it.
// ** Return SQLITE_OK if no error occurs, or an SQLite error code otherwise.
// **
// ** If argument bErrormsg is true and an error occurs, an error message may
// ** be left in sqlite3_vtab.zErrMsg.
// */
func _fts5SeekCursor(tls *libc.TLS, pCsr uintptr, bErrormsg int32) (r int32) {
bp := tls.Alloc(32)
defer tls.Free(32)
var eStmt, rc int32
var pTab, pTab1, v1 uintptr
_, _, _, _, _ = eStmt, pTab, pTab1, rc, v1
rc = SQLITE_OK
/* If the cursor does not yet have a statement handle, obtain one now. */
if (*TFts5Cursor)(unsafe.Pointer(pCsr)).FpStmt == uintptr(0) {
pTab = (*TFts5Cursor)(unsafe.Pointer(pCsr)).Fbase.FpVtab
eStmt = _fts5StmtType(tls, pCsr)
if bErrormsg != 0 {
v1 = pTab + 16
} else {
v1 = uintptr(0)
}
rc = _sqlite3Fts5StorageStmt(tls, (*TFts5FullTable)(unsafe.Pointer(pTab)).FpStorage, eStmt, pCsr+56, v1)
}
if rc == SQLITE_OK && (*TFts5Cursor)(unsafe.Pointer(pCsr)).Fcsrflags&int32(FTS5CSR_REQUIRE_CONTENT) != 0 {
pTab1 = (*TFts5Cursor)(unsafe.Pointer(pCsr)).Fbase.FpVtab
Xsqlite3_reset(tls, (*TFts5Cursor)(unsafe.Pointer(pCsr)).FpStmt)
Xsqlite3_bind_int64(tls, (*TFts5Cursor)(unsafe.Pointer(pCsr)).FpStmt, int32(1), _fts5CursorRowid(tls, pCsr))
(*TFts5Config)(unsafe.Pointer((*TFts5Table)(unsafe.Pointer(pTab1)).FpConfig)).FbLock = (*TFts5Config)(unsafe.Pointer((*TFts5Table)(unsafe.Pointer(pTab1)).FpConfig)).FbLock + 1
rc = Xsqlite3_step(tls, (*TFts5Cursor)(unsafe.Pointer(pCsr)).FpStmt)
(*TFts5Config)(unsafe.Pointer((*TFts5Table)(unsafe.Pointer(pTab1)).FpConfig)).FbLock = (*TFts5Config)(unsafe.Pointer((*TFts5Table)(unsafe.Pointer(pTab1)).FpConfig)).FbLock - 1
if rc == int32(SQLITE_ROW) {
rc = SQLITE_OK
**(**int32)(__ccgo_up(pCsr + 80)) &= ^libc.Int32FromInt32(FTS5CSR_REQUIRE_CONTENT)
} else {
rc = Xsqlite3_reset(tls, (*TFts5Cursor)(unsafe.Pointer(pCsr)).FpStmt)
if rc == SQLITE_OK {
rc = libc.Int32FromInt32(SQLITE_CORRUPT) | libc.Int32FromInt32(1)<pLeaf==0) and assume the iterator is
** at EOF already. */
return
}
if (*TFts5Index)(unsafe.Pointer(p)).Frc == SQLITE_OK {
libc.X__builtin___memset_chk(tls, pIter, 0, uint64(128), ^t__predefined_size_t(0))
_fts5SegIterSetNext(tls, p, pIter)
(*TFts5SegIter)(unsafe.Pointer(pIter)).FpSeg = pSeg
(*TFts5SegIter)(unsafe.Pointer(pIter)).FiLeafPgno = (*TFts5StructureSegment)(unsafe.Pointer(pSeg)).FpgnoFirst - int32(1)
for cond := true; cond; cond = (*TFts5Index)(unsafe.Pointer(p)).Frc == SQLITE_OK && (*TFts5SegIter)(unsafe.Pointer(pIter)).FpLeaf != 0 && (*TFts5Data)(unsafe.Pointer((*TFts5SegIter)(unsafe.Pointer(pIter)).FpLeaf)).Fnn == int32(4) {
_fts5SegIterNextPage(tls, p, pIter)
}
}
if (*TFts5Index)(unsafe.Pointer(p)).Frc == SQLITE_OK && (*TFts5SegIter)(unsafe.Pointer(pIter)).FpLeaf != 0 {
(*TFts5SegIter)(unsafe.Pointer(pIter)).FiLeafOffset = int64(4)
(*TFts5SegIter)(unsafe.Pointer(pIter)).FiPgidxOff = (*TFts5Data)(unsafe.Pointer((*TFts5SegIter)(unsafe.Pointer(pIter)).FpLeaf)).FszLeaf + int32(1)
_fts5SegIterLoadTerm(tls, p, pIter, 0)
_fts5SegIterLoadNPos(tls, p, pIter)
_fts5SegIterAllocTombstone(tls, p, pIter)
}
}
// C documentation
//
// /*
// ** This is similar to fts5SegIterSeekInit(), except that it initializes
// ** the segment iterator to point to the first term following the page
// ** with pToken/nToken on it.
// */
func _fts5SegIterNextInit(tls *libc.TLS, p uintptr, pTerm uintptr, nTerm int32, pSeg uintptr, pIter uintptr) {
bp := tls.Alloc(16)
defer tls.Free(16)
var a, pSel uintptr
var bDlidx, iPg int32
var val Ti64
var _ /* iTermOff at bp+0 */ int32
_, _, _, _, _ = a, bDlidx, iPg, pSel, val
iPg = -int32(1) /* Page of segment to open */
bDlidx = 0
pSel = uintptr(0) /* SELECT to find iPg */
pSel = _fts5IdxNextStmt(tls, p)
if pSel != 0 {
Xsqlite3_bind_int(tls, pSel, int32(1), (*TFts5StructureSegment)(unsafe.Pointer(pSeg)).FiSegid)
Xsqlite3_bind_blob(tls, pSel, int32(2), pTerm, nTerm, libc.UintptrFromInt32(0))
if Xsqlite3_step(tls, pSel) == int32(SQLITE_ROW) {
val = Xsqlite3_column_int64(tls, pSel, 0)
iPg = int32(val >> libc.Int32FromInt32(1))
bDlidx = int32(val & libc.Int64FromInt32(0x0001))
}
(*TFts5Index)(unsafe.Pointer(p)).Frc = Xsqlite3_reset(tls, pSel)
Xsqlite3_bind_null(tls, pSel, int32(2))
if (*TFts5Index)(unsafe.Pointer(p)).Frc != 0 {
return
}
}
libc.X__builtin___memset_chk(tls, pIter, 0, uint64(128), ^t__predefined_size_t(0))
(*TFts5SegIter)(unsafe.Pointer(pIter)).FpSeg = pSeg
**(**int32)(__ccgo_up(pIter + 8)) |= int32(FTS5_SEGITER_ONETERM)
if iPg >= 0 {
(*TFts5SegIter)(unsafe.Pointer(pIter)).FiLeafPgno = iPg - int32(1)
_fts5SegIterNextPage(tls, p, pIter)
_fts5SegIterSetNext(tls, p, pIter)
}
if (*TFts5SegIter)(unsafe.Pointer(pIter)).FpLeaf != 0 {
a = (*TFts5Data)(unsafe.Pointer((*TFts5SegIter)(unsafe.Pointer(pIter)).FpLeaf)).Fp
**(**int32)(__ccgo_up(bp)) = 0
(*TFts5SegIter)(unsafe.Pointer(pIter)).FiPgidxOff = (*TFts5Data)(unsafe.Pointer((*TFts5SegIter)(unsafe.Pointer(pIter)).FpLeaf)).FszLeaf
**(**int32)(__ccgo_up(pIter + 64)) += _sqlite3Fts5GetVarint32(tls, a+uintptr((*TFts5SegIter)(unsafe.Pointer(pIter)).FiPgidxOff), bp)
(*TFts5SegIter)(unsafe.Pointer(pIter)).FiLeafOffset = int64(**(**int32)(__ccgo_up(bp)))
_fts5SegIterLoadTerm(tls, p, pIter, 0)
_fts5SegIterLoadNPos(tls, p, pIter)
if bDlidx != 0 {
_fts5SegIterLoadDlidx(tls, p, pIter)
}
}
}
// C documentation
//
// /*
// ** Initialize the object pIter to point to term pTerm/nTerm within segment
// ** pSeg. If there is no such term in the index, the iterator is set to EOF.
// **
// ** If an error occurs, Fts5Index.rc is set to an appropriate error code. If
// ** an error has already occurred when this function is called, it is a no-op.
// */
func _fts5SegIterSeekInit(tls *libc.TLS, p uintptr, pTerm uintptr, nTerm int32, flags int32, pSeg uintptr, pIter uintptr) {
var bDlidx, bGe, iPg int32
var pIdxSelect uintptr
var val Ti64
_, _, _, _, _ = bDlidx, bGe, iPg, pIdxSelect, val
iPg = int32(1)
bGe = flags & int32(FTS5INDEX_QUERY_SCAN)
bDlidx = 0 /* True if there is a doclist-index */
pIdxSelect = uintptr(0)
libc.X__builtin___memset_chk(tls, pIter, 0, uint64(128), ^t__predefined_size_t(0))
(*TFts5SegIter)(unsafe.Pointer(pIter)).FpSeg = pSeg
/* This block sets stack variable iPg to the leaf page number that may
** contain term (pTerm/nTerm), if it is present in the segment. */
pIdxSelect = _fts5IdxSelectStmt(tls, p)
if (*TFts5Index)(unsafe.Pointer(p)).Frc != 0 {
return
}
Xsqlite3_bind_int(tls, pIdxSelect, int32(1), (*TFts5StructureSegment)(unsafe.Pointer(pSeg)).FiSegid)
Xsqlite3_bind_blob(tls, pIdxSelect, int32(2), pTerm, nTerm, libc.UintptrFromInt32(0))
if int32(SQLITE_ROW) == Xsqlite3_step(tls, pIdxSelect) {
val = int64(Xsqlite3_column_int(tls, pIdxSelect, 0))
iPg = int32(val >> libc.Int32FromInt32(1))
bDlidx = int32(val & libc.Int64FromInt32(0x0001))
}
(*TFts5Index)(unsafe.Pointer(p)).Frc = Xsqlite3_reset(tls, pIdxSelect)
Xsqlite3_bind_null(tls, pIdxSelect, int32(2))
if iPg < (*TFts5StructureSegment)(unsafe.Pointer(pSeg)).FpgnoFirst {
iPg = (*TFts5StructureSegment)(unsafe.Pointer(pSeg)).FpgnoFirst
bDlidx = 0
}
(*TFts5SegIter)(unsafe.Pointer(pIter)).FiLeafPgno = iPg - int32(1)
_fts5SegIterNextPage(tls, p, pIter)
if (*TFts5SegIter)(unsafe.Pointer(pIter)).FpLeaf != 0 {
_fts5LeafSeek(tls, p, bGe, pIter, pTerm, nTerm)
}
if (*TFts5Index)(unsafe.Pointer(p)).Frc == SQLITE_OK && (bGe == 0 || flags&int32(FTS5INDEX_QUERY_SCANONETERM) != 0) {
**(**int32)(__ccgo_up(pIter + 8)) |= int32(FTS5_SEGITER_ONETERM)
if (*TFts5SegIter)(unsafe.Pointer(pIter)).FpLeaf != 0 {
if flags&int32(FTS5INDEX_QUERY_DESC) != 0 {
**(**int32)(__ccgo_up(pIter + 8)) |= int32(FTS5_SEGITER_REVERSE)
}
if bDlidx != 0 {
_fts5SegIterLoadDlidx(tls, p, pIter)
}
if flags&int32(FTS5INDEX_QUERY_DESC) != 0 {
_fts5SegIterReverse(tls, p, pIter)
}
}
}
_fts5SegIterSetNext(tls, p, pIter)
if 0 == flags&int32(FTS5INDEX_QUERY_SCANONETERM) {
_fts5SegIterAllocTombstone(tls, p, pIter)
}
/* Either:
**
** 1) an error has occurred, or
** 2) the iterator points to EOF, or
** 3) the iterator points to an entry with term (pTerm/nTerm), or
** 4) the FTS5INDEX_QUERY_SCAN flag was set and the iterator points
** to an entry with a term greater than or equal to (pTerm/nTerm).
*/
}
// C documentation
//
// /*
// ** Iterator pIter currently points to a valid entry (not EOF). This
// ** function appends the position list data for the current entry to
// ** buffer pBuf. It does not make a copy of the position-list size
// ** field.
// */
func _fts5SegiterPoslist(tls *libc.TLS, p uintptr, pSeg uintptr, pColset uintptr, pBuf uintptr) {
bp := tls.Alloc(48)
defer tls.Free(48)
var v1 int32
var _ /* sCtx at bp+0 */ TPoslistCallbackCtx
var _ /* sCtx at bp+24 */ TPoslistOffsetsCtx
_ = v1
if libc.Uint32FromInt32((*TFts5Buffer)(unsafe.Pointer(pBuf)).Fn)+libc.Uint32FromInt32((*TFts5SegIter)(unsafe.Pointer(pSeg)).FnPos+libc.Int32FromInt32(FTS5_DATA_ZERO_PADDING)) <= libc.Uint32FromInt32((*TFts5Buffer)(unsafe.Pointer(pBuf)).FnSpace) {
v1 = 0
} else {
v1 = _sqlite3Fts5BufferSize(tls, p+60, pBuf, libc.Uint32FromInt32((*TFts5SegIter)(unsafe.Pointer(pSeg)).FnPos+int32(FTS5_DATA_ZERO_PADDING)+(*TFts5Buffer)(unsafe.Pointer(pBuf)).Fn))
}
if 0 == v1 {
libc.X__builtin___memset_chk(tls, (*TFts5Buffer)(unsafe.Pointer(pBuf)).Fp+uintptr((*TFts5Buffer)(unsafe.Pointer(pBuf)).Fn+(*TFts5SegIter)(unsafe.Pointer(pSeg)).FnPos), 0, uint64(FTS5_DATA_ZERO_PADDING), ^t__predefined_size_t(0))
if pColset == uintptr(0) {
_fts5ChunkIterate(tls, p, pSeg, pBuf, __ccgo_fp(_fts5PoslistCallback))
} else {
if (*TFts5Config)(unsafe.Pointer((*TFts5Index)(unsafe.Pointer(p)).FpConfig)).FeDetail == FTS5_DETAIL_FULL {
(**(**TPoslistCallbackCtx)(__ccgo_up(bp))).FpBuf = pBuf
(**(**TPoslistCallbackCtx)(__ccgo_up(bp))).FpColset = pColset
(**(**TPoslistCallbackCtx)(__ccgo_up(bp))).FeState = _fts5IndexColsetTest(tls, pColset, 0)
_fts5ChunkIterate(tls, p, pSeg, bp, __ccgo_fp(_fts5PoslistFilterCallback))
} else {
libc.X__builtin___memset_chk(tls, bp+24, 0, uint64(24), ^t__predefined_size_t(0))
(**(**TPoslistOffsetsCtx)(__ccgo_up(bp + 24))).FpBuf = pBuf
(**(**TPoslistOffsetsCtx)(__ccgo_up(bp + 24))).FpColset = pColset
_fts5ChunkIterate(tls, p, pSeg, bp+24, __ccgo_fp(_fts5PoslistOffsetsCallback))
}
}
}
}
func _fts5SetupPrefixIter(tls *libc.TLS, p uintptr, bDesc int32, iIdx int32, pToken uintptr, nToken int32, pColset uintptr, ppIter uintptr) {
bp := tls.Alloc(96)
defer tls.Free(96)
var i, iFree, v3 int32
var pCtx, pData, pStruct uintptr
var _ /* s at bp+0 */ TPrefixSetupCtx
var _ /* s2 at bp+72 */ TTokendataSetupCtx
_, _, _, _, _, _ = i, iFree, pCtx, pData, pStruct, v3
libc.X__builtin___memset_chk(tls, bp, 0, uint64(72), ^t__predefined_size_t(0))
libc.X__builtin___memset_chk(tls, bp+72, 0, uint64(16), ^t__predefined_size_t(0))
(**(**TPrefixSetupCtx)(__ccgo_up(bp))).FnMerge = int32(1)
(**(**TPrefixSetupCtx)(__ccgo_up(bp))).FiLastRowid = 0
(**(**TPrefixSetupCtx)(__ccgo_up(bp))).FnBuf = int32(32)
if iIdx == 0 && (*TFts5Config)(unsafe.Pointer((*TFts5Index)(unsafe.Pointer(p)).FpConfig)).FeDetail == FTS5_DETAIL_FULL && (*TFts5Config)(unsafe.Pointer((*TFts5Index)(unsafe.Pointer(p)).FpConfig)).FbPrefixInsttoken != 0 {
(**(**TPrefixSetupCtx)(__ccgo_up(bp))).FpTokendata = bp + 72
(**(**TTokendataSetupCtx)(__ccgo_up(bp + 72))).FpT = _fts5IdxMalloc(tls, p, libc.Int64FromUint64(uint64(libc.UintptrFromInt32(0)+72)+libc.Uint64FromInt32(libc.Int32FromInt32(1))*libc.Uint64FromInt64(104)))
}
if (*TFts5Config)(unsafe.Pointer((*TFts5Index)(unsafe.Pointer(p)).FpConfig)).FeDetail == int32(FTS5_DETAIL_NONE) {
(**(**TPrefixSetupCtx)(__ccgo_up(bp))).FxMerge = __ccgo_fp(_fts5MergeRowidLists)
(**(**TPrefixSetupCtx)(__ccgo_up(bp))).FxAppend = __ccgo_fp(_fts5AppendRowid)
} else {
(**(**TPrefixSetupCtx)(__ccgo_up(bp))).FnMerge = libc.Int32FromInt32(FTS5_MERGE_NLIST) - libc.Int32FromInt32(1)
(**(**TPrefixSetupCtx)(__ccgo_up(bp))).FnBuf = (**(**TPrefixSetupCtx)(__ccgo_up(bp))).FnMerge * int32(8) /* Sufficient to merge (16^8)==(2^32) lists */
(**(**TPrefixSetupCtx)(__ccgo_up(bp))).FxMerge = __ccgo_fp(_fts5MergePrefixLists)
(**(**TPrefixSetupCtx)(__ccgo_up(bp))).FxAppend = __ccgo_fp(_fts5AppendPoslist)
}
(**(**TPrefixSetupCtx)(__ccgo_up(bp))).FaBuf = _fts5IdxMalloc(tls, p, libc.Int64FromUint64(uint64(16)*libc.Uint64FromInt32((**(**TPrefixSetupCtx)(__ccgo_up(bp))).FnBuf)))
pStruct = _fts5StructureRead(tls, p)
if (*TFts5Index)(unsafe.Pointer(p)).Frc == SQLITE_OK {
pCtx = bp
/* If iIdx is non-zero, then it is the number of a prefix-index for
** prefixes 1 character longer than the prefix being queried for. That
** index contains all the doclists required, except for the one
** corresponding to the prefix itself. That one is extracted from the
** main term index here. */
if iIdx != 0 {
**(**Tu8)(__ccgo_up(pToken)) = uint8('0')
_fts5VisitEntries(tls, p, pColset, pToken, nToken, 0, __ccgo_fp(_prefixIterSetupCb), pCtx)
}
**(**Tu8)(__ccgo_up(pToken)) = libc.Uint8FromInt32(int32('0') + iIdx)
_fts5VisitEntries(tls, p, pColset, pToken, nToken, int32(1), __ccgo_fp(_prefixIterSetupCb), pCtx)
i = 0
for {
if !(i < (**(**TPrefixSetupCtx)(__ccgo_up(bp))).FnBuf) {
break
}
if (*TFts5Index)(unsafe.Pointer(p)).Frc == SQLITE_OK {
(*(*func(*libc.TLS, uintptr, uintptr, int32, uintptr))(unsafe.Pointer(&struct{ uintptr }{(**(**TPrefixSetupCtx)(__ccgo_up(bp))).FxMerge})))(tls, p, bp+48, (**(**TPrefixSetupCtx)(__ccgo_up(bp))).FnMerge, (**(**TPrefixSetupCtx)(__ccgo_up(bp))).FaBuf+uintptr(i)*16)
}
iFree = i
for {
if !(iFree < i+(**(**TPrefixSetupCtx)(__ccgo_up(bp))).FnMerge) {
break
}
_sqlite3Fts5BufferFree(tls, (**(**TPrefixSetupCtx)(__ccgo_up(bp))).FaBuf+uintptr(iFree)*16)
goto _2
_2:
;
iFree = iFree + 1
}
goto _1
_1:
;
i = i + (**(**TPrefixSetupCtx)(__ccgo_up(bp))).FnMerge
}
pData = _fts5IdxMalloc(tls, p, libc.Int64FromUint64(uint64(16)+libc.Uint64FromInt64(int64((**(**TPrefixSetupCtx)(__ccgo_up(bp))).Fdoclist.Fn))+uint64(FTS5_DATA_ZERO_PADDING)))
if pData != 0 {
(*TFts5Data)(unsafe.Pointer(pData)).Fp = pData + 1*16
v3 = (**(**TPrefixSetupCtx)(__ccgo_up(bp))).Fdoclist.Fn
(*TFts5Data)(unsafe.Pointer(pData)).FszLeaf = v3
(*TFts5Data)(unsafe.Pointer(pData)).Fnn = v3
if (**(**TPrefixSetupCtx)(__ccgo_up(bp))).Fdoclist.Fn != 0 {
libc.X__builtin___memcpy_chk(tls, (*TFts5Data)(unsafe.Pointer(pData)).Fp, (**(**TPrefixSetupCtx)(__ccgo_up(bp))).Fdoclist.Fp, libc.Uint64FromInt32((**(**TPrefixSetupCtx)(__ccgo_up(bp))).Fdoclist.Fn), ^t__predefined_size_t(0))
}
_fts5MultiIterNew2(tls, p, pData, bDesc, ppIter)
}
if (*TFts5Index)(unsafe.Pointer(p)).Frc == SQLITE_OK && (**(**TPrefixSetupCtx)(__ccgo_up(bp))).FpTokendata != 0 {
_fts5TokendataIterSortMap(tls, p, (**(**TTokendataSetupCtx)(__ccgo_up(bp + 72))).FpT)
(*TFts5Iter)(unsafe.Pointer(**(**uintptr)(__ccgo_up(ppIter)))).FpTokenDataIter = (**(**TTokendataSetupCtx)(__ccgo_up(bp + 72))).FpT
(**(**TTokendataSetupCtx)(__ccgo_up(bp + 72))).FpT = uintptr(0)
}
}
_fts5TokendataIterDelete(tls, (**(**TTokendataSetupCtx)(__ccgo_up(bp + 72))).FpT)
_sqlite3Fts5BufferFree(tls, bp+48)
_fts5StructureRelease(tls, pStruct)
Xsqlite3_free(tls, (**(**TPrefixSetupCtx)(__ccgo_up(bp))).FaBuf)
}
// C documentation
//
// /*
// ** pIter is a prefix query. This function populates pIter->pTokenDataIter
// ** with an Fts5TokenDataIter object containing mappings for all rows
// ** matched by the query.
// */
func _fts5SetupPrefixIterTokendata(tls *libc.TLS, pIter uintptr, pToken uintptr, nToken int32) (r int32) {
bp := tls.Alloc(32)
defer tls.Free(32)
var p uintptr
var _ /* ctx at bp+16 */ TTokendataSetupCtx
var _ /* token at bp+0 */ TFts5Buffer
_ = p
p = (*TFts5Iter)(unsafe.Pointer(pIter)).FpIndex
**(**TFts5Buffer)(__ccgo_up(bp)) = TFts5Buffer{}
libc.X__builtin___memset_chk(tls, bp+16, 0, uint64(16), ^t__predefined_size_t(0))
if !(libc.Uint32FromInt32((*TFts5Buffer)(unsafe.Pointer(bp)).Fn)+libc.Uint32FromInt32(nToken+libc.Int32FromInt32(1)) <= libc.Uint32FromInt32((*TFts5Buffer)(unsafe.Pointer(bp)).FnSpace)) {
_sqlite3Fts5BufferSize(tls, p+60, bp, libc.Uint32FromInt32(nToken+int32(1)+(*TFts5Buffer)(unsafe.Pointer(bp)).Fn))
}
(**(**TTokendataSetupCtx)(__ccgo_up(bp + 16))).FpT = _sqlite3Fts5MallocZero(tls, p+60, libc.Int64FromUint64(uint64(libc.UintptrFromInt32(0)+72)+libc.Uint64FromInt32(libc.Int32FromInt32(1))*libc.Uint64FromInt64(104)))
if (*TFts5Index)(unsafe.Pointer(p)).Frc == SQLITE_OK {
/* Fill in the token prefix to search for */
**(**Tu8)(__ccgo_up((**(**TFts5Buffer)(__ccgo_up(bp))).Fp)) = uint8('0')
libc.X__builtin___memcpy_chk(tls, (**(**TFts5Buffer)(__ccgo_up(bp))).Fp+1, pToken, libc.Uint64FromInt32(nToken), ^t__predefined_size_t(0))
(**(**TFts5Buffer)(__ccgo_up(bp))).Fn = nToken + int32(1)
_fts5VisitEntries(tls, p, uintptr(0), (**(**TFts5Buffer)(__ccgo_up(bp))).Fp, (**(**TFts5Buffer)(__ccgo_up(bp))).Fn, int32(1), __ccgo_fp(_prefixIterSetupTokendataCb), bp+16)
_fts5TokendataIterSortMap(tls, p, (**(**TTokendataSetupCtx)(__ccgo_up(bp + 16))).FpT)
}
if (*TFts5Index)(unsafe.Pointer(p)).Frc == SQLITE_OK {
(*TFts5Iter)(unsafe.Pointer(pIter)).FpTokenDataIter = (**(**TTokendataSetupCtx)(__ccgo_up(bp + 16))).FpT
} else {
_fts5TokendataIterDelete(tls, (**(**TTokendataSetupCtx)(__ccgo_up(bp + 16))).FpT)
}
_sqlite3Fts5BufferFree(tls, bp)
return _fts5IndexReturn(tls, p)
}
// C documentation
//
// /*
// ** This function sets up an iterator to use for a non-prefix query on a
// ** tokendata=1 table.
// */
func _fts5SetupTokendataIter(tls *libc.TLS, p uintptr, pToken uintptr, nToken int32, pColset uintptr) (r uintptr) {
bp := tls.Alloc(16)
defer tls.Free(16)
var bDone, flags, iLvl, iSeg, iSeg1, ii, ii1 int32
var pII, pIter, pNew, pNewIter, pPrev, pPrevIter, pRet, pSeg, pSet, pSmall, pStruct, v1 uintptr
var _ /* bSeek at bp+0 */ TFts5Buffer
_, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _ = bDone, flags, iLvl, iSeg, iSeg1, ii, ii1, pII, pIter, pNew, pNewIter, pPrev, pPrevIter, pRet, pSeg, pSet, pSmall, pStruct, v1
pRet = uintptr(0)
pSet = uintptr(0)
pStruct = uintptr(0)
flags = libc.Int32FromInt32(FTS5INDEX_QUERY_SCANONETERM) | libc.Int32FromInt32(FTS5INDEX_QUERY_SCAN)
**(**TFts5Buffer)(__ccgo_up(bp)) = TFts5Buffer{}
pSmall = uintptr(0)
_fts5IndexFlush(tls, p)
pStruct = _fts5StructureRead(tls, p)
for (*TFts5Index)(unsafe.Pointer(p)).Frc == SQLITE_OK {
if pSet != 0 {
v1 = *(*uintptr)(unsafe.Pointer(pSet + 72 + uintptr((*TFts5TokenDataIter)(unsafe.Pointer(pSet)).FnIter-int64(1))*8))
} else {
v1 = uintptr(0)
}
pPrev = v1
pNew = uintptr(0)
pNewIter = uintptr(0)
pPrevIter = uintptr(0)
pNew = _fts5MultiIterAlloc(tls, p, (*TFts5Structure)(unsafe.Pointer(pStruct)).FnSegment)
if pSmall != 0 {
_sqlite3Fts5BufferSet(tls, p+60, bp, (*TFts5Buffer)(unsafe.Pointer(pSmall)).Fn, (*TFts5Buffer)(unsafe.Pointer(pSmall)).Fp)
_sqlite3Fts5BufferAppendBlob(tls, p+60, bp, uint32(1), __ccgo_ts+39973)
} else {
_sqlite3Fts5BufferSet(tls, p+60, bp, nToken, pToken)
}
if (*TFts5Index)(unsafe.Pointer(p)).Frc != 0 {
_fts5IterClose(tls, pNew)
break
}
pNewIter = pNew + 104
if pPrev != 0 {
v1 = pPrev + 104
} else {
v1 = uintptr(0)
}
pPrevIter = v1
iLvl = 0
for {
if !(iLvl < (*TFts5Structure)(unsafe.Pointer(pStruct)).FnLevel) {
break
}
iSeg = (*(*TFts5StructureLevel)(unsafe.Pointer(pStruct + 32 + uintptr(iLvl)*16))).FnSeg - int32(1)
for {
if !(iSeg >= 0) {
break
}
pSeg = (*(*TFts5StructureLevel)(unsafe.Pointer(pStruct + 32 + uintptr(iLvl)*16))).FaSeg + uintptr(iSeg)*56
bDone = 0
if pPrevIter != 0 {
if _fts5BufferCompare(tls, pSmall, pPrevIter+96) != 0 {
libc.X__builtin___memcpy_chk(tls, pNewIter, pPrevIter, uint64(128), ^t__predefined_size_t(0))
libc.X__builtin___memset_chk(tls, pPrevIter, 0, uint64(128), ^t__predefined_size_t(0))
bDone = int32(1)
} else {
if (*TFts5SegIter)(unsafe.Pointer(pPrevIter)).FiEndofDoclist > (*TFts5Data)(unsafe.Pointer((*TFts5SegIter)(unsafe.Pointer(pPrevIter)).FpLeaf)).FszLeaf {
_fts5SegIterNextInit(tls, p, (**(**TFts5Buffer)(__ccgo_up(bp))).Fp, (**(**TFts5Buffer)(__ccgo_up(bp))).Fn-int32(1), pSeg, pNewIter)
bDone = int32(1)
}
}
}
if bDone == 0 {
_fts5SegIterSeekInit(tls, p, (**(**TFts5Buffer)(__ccgo_up(bp))).Fp, (**(**TFts5Buffer)(__ccgo_up(bp))).Fn, flags, pSeg, pNewIter)
}
if pPrevIter != 0 {
if (*TFts5SegIter)(unsafe.Pointer(pPrevIter)).FpTombArray != 0 {
(*TFts5SegIter)(unsafe.Pointer(pNewIter)).FpTombArray = (*TFts5SegIter)(unsafe.Pointer(pPrevIter)).FpTombArray
(*TFts5TombstoneArray)(unsafe.Pointer((*TFts5SegIter)(unsafe.Pointer(pNewIter)).FpTombArray)).FnRef = (*TFts5TombstoneArray)(unsafe.Pointer((*TFts5SegIter)(unsafe.Pointer(pNewIter)).FpTombArray)).FnRef + 1
}
} else {
_fts5SegIterAllocTombstone(tls, p, pNewIter)
}
pNewIter += 128
if pPrevIter != 0 {
pPrevIter += 128
}
if (*TFts5Index)(unsafe.Pointer(p)).Frc != 0 {
break
}
goto _4
_4:
;
iSeg = iSeg - 1
}
goto _3
_3:
;
iLvl = iLvl + 1
}
_fts5TokendataSetTermIfEof(tls, pPrev, pSmall)
(*TFts5Iter)(unsafe.Pointer(pNew)).FbSkipEmpty = uint8(1)
(*TFts5Iter)(unsafe.Pointer(pNew)).FpColset = pColset
_fts5IterSetOutputCb(tls, p+60, pNew)
/* Loop through all segments in the new iterator. Find the smallest
** term that any segment-iterator points to. Iterator pNew will be
** used for this term. Also, set any iterator that points to a term that
** does not match pToken/nToken to point to EOF */
pSmall = uintptr(0)
ii = 0
for {
if !(ii < (*TFts5Iter)(unsafe.Pointer(pNew)).FnSeg) {
break
}
pII = pNew + 104 + uintptr(ii)*128
if 0 == _fts5IsTokendataPrefix(tls, pII+96, pToken, nToken) {
_fts5SegIterSetEOF(tls, pII)
}
if (*TFts5SegIter)(unsafe.Pointer(pII)).FpLeaf != 0 && (!(pSmall != 0) || _fts5BufferCompare(tls, pSmall, pII+96) > 0) {
pSmall = pII + 96
}
goto _5
_5:
;
ii = ii + 1
}
/* If pSmall is still NULL at this point, then the new iterator does
** not point to any terms that match the query. So delete it and break
** out of the loop - all required iterators have been collected. */
if pSmall == uintptr(0) {
_fts5IterClose(tls, pNew)
break
}
/* Append this iterator to the set and continue. */
pSet = _fts5AppendTokendataIter(tls, p, pSet, pNew)
}
if (*TFts5Index)(unsafe.Pointer(p)).Frc == SQLITE_OK && pSet != 0 {
ii1 = 0
for {
if !(int64(ii1) < (*TFts5TokenDataIter)(unsafe.Pointer(pSet)).FnIter) {
break
}
pIter = *(*uintptr)(unsafe.Pointer(pSet + 72 + uintptr(ii1)*8))
iSeg1 = 0
for {
if !(iSeg1 < (*TFts5Iter)(unsafe.Pointer(pIter)).FnSeg) {
break
}
(*(*TFts5SegIter)(unsafe.Pointer(pIter + 104 + uintptr(iSeg1)*128))).Fflags |= int32(FTS5_SEGITER_ONETERM)
goto _7
_7:
;
iSeg1 = iSeg1 + 1
}
_fts5MultiIterFinishSetup(tls, p, pIter)
goto _6
_6:
;
ii1 = ii1 + 1
}
}
if (*TFts5Index)(unsafe.Pointer(p)).Frc == SQLITE_OK {
pRet = _fts5MultiIterAlloc(tls, p, 0)
}
if pRet != 0 {
(*TFts5Iter)(unsafe.Pointer(pRet)).FnSeg = 0
(*TFts5Iter)(unsafe.Pointer(pRet)).FpTokenDataIter = pSet
if pSet != 0 {
_fts5IterSetOutputsTokendata(tls, pRet)
} else {
(*TFts5Iter)(unsafe.Pointer(pRet)).Fbase.FbEof = uint8(1)
}
} else {
_fts5TokendataIterDelete(tls, pSet)
}
_fts5StructureRelease(tls, pStruct)
_sqlite3Fts5BufferFree(tls, bp)
return pRet
}
// C documentation
//
// /*
// ** Implementation of snippet() function.
// */
func _fts5SnippetFunction(tls *libc.TLS, pApi uintptr, pFts uintptr, pCtx uintptr, nVal int32, apVal uintptr) {
bp := tls.Alloc(208)
defer tls.Free(208)
var aSeen, zEllips, zErr uintptr
var i, iBestCol, iBestStart, iCol, ii, jj, nBestScore, nCol, nPhrase, v4 int32
var nToken Ti64
var v1, v2, v3 int64
var _ /* ctx at bp+0 */ THighlightContext
var _ /* iAdj at bp+184 */ int32
var _ /* ic at bp+176 */ int32
var _ /* io at bp+180 */ int32
var _ /* ip at bp+172 */ int32
var _ /* nColSize at bp+112 */ int32
var _ /* nDoc at bp+164 */ int32
var _ /* nDocsize at bp+168 */ int32
var _ /* nInst at bp+108 */ int32
var _ /* nLoc at bp+160 */ int32
var _ /* nLoc at bp+200 */ int32
var _ /* nScore at bp+188 */ int32
var _ /* pLoc at bp+152 */ uintptr
var _ /* pLoc at bp+192 */ uintptr
var _ /* rc at bp+104 */ int32
var _ /* sFinder at bp+120 */ TFts5SFinder
_, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _ = aSeen, i, iBestCol, iBestStart, iCol, ii, jj, nBestScore, nCol, nPhrase, nToken, zEllips, zErr, v1, v2, v3, v4
**(**int32)(__ccgo_up(bp + 104)) = SQLITE_OK /* 5th argument to snippet() */
**(**int32)(__ccgo_up(bp + 108)) = 0 /* Column containing best snippet */
iBestStart = 0 /* First token of best snippet */
nBestScore = 0 /* Score of best snippet */
**(**int32)(__ccgo_up(bp + 112)) = 0
if nVal != int32(5) {
zErr = __ccgo_ts + 37595
Xsqlite3_result_error(tls, pCtx, zErr, -int32(1))
return
}
nCol = (*(*func(*libc.TLS, uintptr) int32)(unsafe.Pointer(&struct{ uintptr }{(*TFts5ExtensionApi)(unsafe.Pointer(pApi)).FxColumnCount})))(tls, pFts)
libc.X__builtin___memset_chk(tls, bp, 0, uint64(104), ^t__predefined_size_t(0))
iCol = Xsqlite3_value_int(tls, **(**uintptr)(__ccgo_up(apVal)))
(**(**THighlightContext)(__ccgo_up(bp))).FzOpen = _fts5ValueToText(tls, **(**uintptr)(__ccgo_up(apVal + 1*8)))
(**(**THighlightContext)(__ccgo_up(bp))).FzClose = _fts5ValueToText(tls, **(**uintptr)(__ccgo_up(apVal + 2*8)))
(**(**THighlightContext)(__ccgo_up(bp))).FiRangeEnd = -int32(1)
zEllips = _fts5ValueToText(tls, **(**uintptr)(__ccgo_up(apVal + 3*8)))
if Xsqlite3_value_int64(tls, **(**uintptr)(__ccgo_up(apVal + 4*8))) > int64(libc.Int32FromInt32(0)) {
v2 = Xsqlite3_value_int64(tls, **(**uintptr)(__ccgo_up(apVal + 4*8)))
} else {
v2 = int64(libc.Int32FromInt32(0))
}
if v2 < int64(libc.Int32FromInt32(64)) {
if Xsqlite3_value_int64(tls, **(**uintptr)(__ccgo_up(apVal + 4*8))) > int64(libc.Int32FromInt32(0)) {
v3 = Xsqlite3_value_int64(tls, **(**uintptr)(__ccgo_up(apVal + 4*8)))
} else {
v3 = int64(libc.Int32FromInt32(0))
}
v1 = v3
} else {
v1 = int64(libc.Int32FromInt32(64))
}
nToken = int64(int32(v1))
if iCol >= 0 {
v4 = iCol
} else {
v4 = 0
}
iBestCol = v4
nPhrase = (*(*func(*libc.TLS, uintptr) int32)(unsafe.Pointer(&struct{ uintptr }{(*TFts5ExtensionApi)(unsafe.Pointer(pApi)).FxPhraseCount})))(tls, pFts)
aSeen = Xsqlite3_malloc64(tls, libc.Uint64FromInt32(nPhrase))
if aSeen == uintptr(0) {
**(**int32)(__ccgo_up(bp + 104)) = int32(SQLITE_NOMEM)
}
if **(**int32)(__ccgo_up(bp + 104)) == SQLITE_OK {
**(**int32)(__ccgo_up(bp + 104)) = (*(*func(*libc.TLS, uintptr, uintptr) int32)(unsafe.Pointer(&struct{ uintptr }{(*TFts5ExtensionApi)(unsafe.Pointer(pApi)).FxInstCount})))(tls, pFts, bp+108)
}
libc.X__builtin___memset_chk(tls, bp+120, 0, uint64(32), ^t__predefined_size_t(0))
i = 0
for {
if !(i < nCol) {
break
}
if iCol < 0 || iCol == i {
**(**uintptr)(__ccgo_up(bp + 152)) = uintptr(0) /* Locale of column iCol */
**(**int32)(__ccgo_up(bp + 160)) = 0
(**(**TFts5SFinder)(__ccgo_up(bp + 120))).FiPos = 0
(**(**TFts5SFinder)(__ccgo_up(bp + 120))).FnFirst = 0
**(**int32)(__ccgo_up(bp + 104)) = (*(*func(*libc.TLS, uintptr, int32, uintptr, uintptr) int32)(unsafe.Pointer(&struct{ uintptr }{(*TFts5ExtensionApi)(unsafe.Pointer(pApi)).FxColumnText})))(tls, pFts, i, bp+120+24, bp+164)
if **(**int32)(__ccgo_up(bp + 104)) != SQLITE_OK {
break
}
**(**int32)(__ccgo_up(bp + 104)) = (*(*func(*libc.TLS, uintptr, int32, uintptr, uintptr) int32)(unsafe.Pointer(&struct{ uintptr }{(*TFts5ExtensionApi)(unsafe.Pointer(pApi)).FxColumnLocale})))(tls, pFts, i, bp+152, bp+160)
if **(**int32)(__ccgo_up(bp + 104)) != SQLITE_OK {
break
}
**(**int32)(__ccgo_up(bp + 104)) = (*(*func(*libc.TLS, uintptr, uintptr, int32, uintptr, int32, uintptr, uintptr) int32)(unsafe.Pointer(&struct{ uintptr }{(*TFts5ExtensionApi)(unsafe.Pointer(pApi)).FxTokenize_v2})))(tls, pFts, (**(**TFts5SFinder)(__ccgo_up(bp + 120))).FzDoc, **(**int32)(__ccgo_up(bp + 164)), **(**uintptr)(__ccgo_up(bp + 152)), **(**int32)(__ccgo_up(bp + 160)), bp+120, __ccgo_fp(_fts5SentenceFinderCb))
if **(**int32)(__ccgo_up(bp + 104)) != SQLITE_OK {
break
}
**(**int32)(__ccgo_up(bp + 104)) = (*(*func(*libc.TLS, uintptr, int32, uintptr) int32)(unsafe.Pointer(&struct{ uintptr }{(*TFts5ExtensionApi)(unsafe.Pointer(pApi)).FxColumnSize})))(tls, pFts, i, bp+168)
if **(**int32)(__ccgo_up(bp + 104)) != SQLITE_OK {
break
}
ii = 0
for {
if !(**(**int32)(__ccgo_up(bp + 104)) == SQLITE_OK && ii < **(**int32)(__ccgo_up(bp + 108))) {
break
}
**(**int32)(__ccgo_up(bp + 104)) = (*(*func(*libc.TLS, uintptr, int32, uintptr, uintptr, uintptr) int32)(unsafe.Pointer(&struct{ uintptr }{(*TFts5ExtensionApi)(unsafe.Pointer(pApi)).FxInst})))(tls, pFts, ii, bp+172, bp+176, bp+180)
if **(**int32)(__ccgo_up(bp + 176)) != i {
goto _6
}
if **(**int32)(__ccgo_up(bp + 180)) > **(**int32)(__ccgo_up(bp + 168)) {
**(**int32)(__ccgo_up(bp + 104)) = libc.Int32FromInt32(SQLITE_CORRUPT) | libc.Int32FromInt32(1)< nBestScore {
nBestScore = **(**int32)(__ccgo_up(bp + 188))
iBestCol = i
iBestStart = **(**int32)(__ccgo_up(bp + 184))
**(**int32)(__ccgo_up(bp + 112)) = **(**int32)(__ccgo_up(bp + 168))
}
if **(**int32)(__ccgo_up(bp + 104)) == SQLITE_OK && (**(**TFts5SFinder)(__ccgo_up(bp + 120))).FnFirst != 0 && int64(**(**int32)(__ccgo_up(bp + 168))) > nToken {
jj = 0
for {
if !(jj < (**(**TFts5SFinder)(__ccgo_up(bp + 120))).FnFirst-int32(1)) {
break
}
if **(**int32)(__ccgo_up((**(**TFts5SFinder)(__ccgo_up(bp + 120))).FaFirst + uintptr(jj+int32(1))*4)) > **(**int32)(__ccgo_up(bp + 180)) {
break
}
goto _7
_7:
;
jj = jj + 1
}
if **(**int32)(__ccgo_up((**(**TFts5SFinder)(__ccgo_up(bp + 120))).FaFirst + uintptr(jj)*4)) < **(**int32)(__ccgo_up(bp + 180)) {
libc.X__builtin___memset_chk(tls, aSeen, 0, libc.Uint64FromInt32(nPhrase), ^t__predefined_size_t(0))
**(**int32)(__ccgo_up(bp + 104)) = _fts5SnippetScore(tls, pApi, pFts, **(**int32)(__ccgo_up(bp + 168)), aSeen, i, **(**int32)(__ccgo_up((**(**TFts5SFinder)(__ccgo_up(bp + 120))).FaFirst + uintptr(jj)*4)), int32(nToken), bp+188, uintptr(0))
if **(**int32)(__ccgo_up((**(**TFts5SFinder)(__ccgo_up(bp + 120))).FaFirst + uintptr(jj)*4)) == 0 {
v4 = int32(120)
} else {
v4 = int32(100)
}
**(**int32)(__ccgo_up(bp + 188)) = **(**int32)(__ccgo_up(bp + 188)) + v4
if **(**int32)(__ccgo_up(bp + 104)) == SQLITE_OK && **(**int32)(__ccgo_up(bp + 188)) > nBestScore {
nBestScore = **(**int32)(__ccgo_up(bp + 188))
iBestCol = i
iBestStart = **(**int32)(__ccgo_up((**(**TFts5SFinder)(__ccgo_up(bp + 120))).FaFirst + uintptr(jj)*4))
**(**int32)(__ccgo_up(bp + 112)) = **(**int32)(__ccgo_up(bp + 168))
}
}
}
goto _6
_6:
;
ii = ii + 1
}
}
goto _5
_5:
;
i = i + 1
}
if **(**int32)(__ccgo_up(bp + 104)) == SQLITE_OK {
**(**int32)(__ccgo_up(bp + 104)) = (*(*func(*libc.TLS, uintptr, int32, uintptr, uintptr) int32)(unsafe.Pointer(&struct{ uintptr }{(*TFts5ExtensionApi)(unsafe.Pointer(pApi)).FxColumnText})))(tls, pFts, iBestCol, bp+24, bp+32)
}
if **(**int32)(__ccgo_up(bp + 104)) == SQLITE_OK && **(**int32)(__ccgo_up(bp + 112)) == 0 {
**(**int32)(__ccgo_up(bp + 104)) = (*(*func(*libc.TLS, uintptr, int32, uintptr) int32)(unsafe.Pointer(&struct{ uintptr }{(*TFts5ExtensionApi)(unsafe.Pointer(pApi)).FxColumnSize})))(tls, pFts, iBestCol, bp+112)
}
if (**(**THighlightContext)(__ccgo_up(bp))).FzIn != 0 {
**(**uintptr)(__ccgo_up(bp + 192)) = uintptr(0) /* Locale of column iBestCol */
**(**int32)(__ccgo_up(bp + 200)) = 0 /* Bytes in pLoc */
if **(**int32)(__ccgo_up(bp + 104)) == SQLITE_OK {
**(**int32)(__ccgo_up(bp + 104)) = _fts5CInstIterInit(tls, pApi, pFts, iBestCol, bp+40)
}
(**(**THighlightContext)(__ccgo_up(bp))).FiRangeStart = iBestStart
(**(**THighlightContext)(__ccgo_up(bp))).FiRangeEnd = int32(int64(iBestStart) + nToken - int64(1))
if iBestStart > 0 {
_fts5HighlightAppend(tls, bp+104, bp, zEllips, -int32(1))
}
/* Advance iterator ctx.iter so that it points to the first coalesced
** phrase instance at or following position iBestStart. */
for (**(**THighlightContext)(__ccgo_up(bp))).Fiter.FiStart >= 0 && (**(**THighlightContext)(__ccgo_up(bp))).Fiter.FiStart < iBestStart && **(**int32)(__ccgo_up(bp + 104)) == SQLITE_OK {
**(**int32)(__ccgo_up(bp + 104)) = _fts5CInstIterNext(tls, bp+40)
}
if **(**int32)(__ccgo_up(bp + 104)) == SQLITE_OK {
**(**int32)(__ccgo_up(bp + 104)) = (*(*func(*libc.TLS, uintptr, int32, uintptr, uintptr) int32)(unsafe.Pointer(&struct{ uintptr }{(*TFts5ExtensionApi)(unsafe.Pointer(pApi)).FxColumnLocale})))(tls, pFts, iBestCol, bp+192, bp+200)
}
if **(**int32)(__ccgo_up(bp + 104)) == SQLITE_OK {
**(**int32)(__ccgo_up(bp + 104)) = (*(*func(*libc.TLS, uintptr, uintptr, int32, uintptr, int32, uintptr, uintptr) int32)(unsafe.Pointer(&struct{ uintptr }{(*TFts5ExtensionApi)(unsafe.Pointer(pApi)).FxTokenize_v2})))(tls, pFts, (**(**THighlightContext)(__ccgo_up(bp))).FzIn, (**(**THighlightContext)(__ccgo_up(bp))).FnIn, **(**uintptr)(__ccgo_up(bp + 192)), **(**int32)(__ccgo_up(bp + 200)), bp, __ccgo_fp(_fts5HighlightCb))
}
if (**(**THighlightContext)(__ccgo_up(bp))).FbOpen != 0 {
_fts5HighlightAppend(tls, bp+104, bp, (**(**THighlightContext)(__ccgo_up(bp))).FzClose, -int32(1))
}
if (**(**THighlightContext)(__ccgo_up(bp))).FiRangeEnd >= **(**int32)(__ccgo_up(bp + 112))-int32(1) {
_fts5HighlightAppend(tls, bp+104, bp, (**(**THighlightContext)(__ccgo_up(bp))).FzIn+uintptr((**(**THighlightContext)(__ccgo_up(bp))).FiOff), (**(**THighlightContext)(__ccgo_up(bp))).FnIn-(**(**THighlightContext)(__ccgo_up(bp))).FiOff)
} else {
_fts5HighlightAppend(tls, bp+104, bp, zEllips, -int32(1))
}
}
if **(**int32)(__ccgo_up(bp + 104)) == SQLITE_OK {
Xsqlite3_result_text(tls, pCtx, (**(**THighlightContext)(__ccgo_up(bp))).FzOut, -int32(1), uintptr(-libc.Int32FromInt32(1)))
} else {
Xsqlite3_result_error_code(tls, pCtx, **(**int32)(__ccgo_up(bp + 104)))
}
Xsqlite3_free(tls, (**(**THighlightContext)(__ccgo_up(bp))).FzOut)
Xsqlite3_free(tls, aSeen)
Xsqlite3_free(tls, (**(**TFts5SFinder)(__ccgo_up(bp + 120))).FaFirst)
}
/************************************************************************/
// C documentation
//
// /*
// ** Implementation of fts5_source_id() function.
// */
func _fts5SourceIdFunc(tls *libc.TLS, pCtx uintptr, nArg int32, apUnused uintptr) {
_ = nArg
_ = apUnused
Xsqlite3_result_text(tls, pCtx, __ccgo_ts+40898, -int32(1), uintptr(-libc.Int32FromInt32(1)))
}
// C documentation
//
// /*
// ** This function is called to handle an FTS INSERT command. In other words,
// ** an INSERT statement of the form:
// **
// ** INSERT INTO fts(fts) VALUES($pCmd)
// ** INSERT INTO fts(fts, rank) VALUES($pCmd, $pVal)
// **
// ** Argument pVal is the value assigned to column "fts" by the INSERT
// ** statement. This function returns SQLITE_OK if successful, or an SQLite
// ** error code if an error occurs.
// **
// ** The commands implemented by this function are documented in the "Special
// ** INSERT Directives" section of the documentation. It should be updated if
// ** more commands are added to this function.
// */
func _fts5SpecialInsert(tls *libc.TLS, pTab uintptr, zCmd uintptr, pVal uintptr) (r int32) {
bp := tls.Alloc(16)
defer tls.Free(16)
var bLoadConfig, iArg, nMerge, rc int32
var pConfig uintptr
var _ /* bError at bp+0 */ int32
_, _, _, _, _ = bLoadConfig, iArg, nMerge, pConfig, rc
pConfig = (*TFts5FullTable)(unsafe.Pointer(pTab)).Fp.FpConfig
rc = SQLITE_OK
**(**int32)(__ccgo_up(bp)) = 0
bLoadConfig = 0
if 0 == Xsqlite3_stricmp(tls, __ccgo_ts+40387, zCmd) {
if (*TFts5Config)(unsafe.Pointer(pConfig)).FeContent == FTS5_CONTENT_NORMAL {
_fts5SetVtabError(tls, pTab, __ccgo_ts+40398, 0)
rc = int32(SQLITE_ERROR)
} else {
rc = _sqlite3Fts5StorageDeleteAll(tls, (*TFts5FullTable)(unsafe.Pointer(pTab)).FpStorage)
}
bLoadConfig = int32(1)
} else {
if 0 == Xsqlite3_stricmp(tls, __ccgo_ts+40478, zCmd) {
if _fts5IsContentless(tls, pTab, int32(1)) != 0 {
_fts5SetVtabError(tls, pTab, __ccgo_ts+40486, 0)
rc = int32(SQLITE_ERROR)
} else {
rc = _sqlite3Fts5StorageRebuild(tls, (*TFts5FullTable)(unsafe.Pointer(pTab)).FpStorage)
}
bLoadConfig = int32(1)
} else {
if 0 == Xsqlite3_stricmp(tls, __ccgo_ts+18997, zCmd) {
rc = _sqlite3Fts5StorageOptimize(tls, (*TFts5FullTable)(unsafe.Pointer(pTab)).FpStorage)
} else {
if 0 == Xsqlite3_stricmp(tls, __ccgo_ts+40542, zCmd) {
nMerge = Xsqlite3_value_int(tls, pVal)
rc = _sqlite3Fts5StorageMerge(tls, (*TFts5FullTable)(unsafe.Pointer(pTab)).FpStorage, nMerge)
} else {
if 0 == Xsqlite3_stricmp(tls, __ccgo_ts+40548, zCmd) {
iArg = Xsqlite3_value_int(tls, pVal)
rc = _sqlite3Fts5StorageIntegrity(tls, (*TFts5FullTable)(unsafe.Pointer(pTab)).FpStorage, iArg)
} else {
if 0 == Xsqlite3_stricmp(tls, __ccgo_ts+40564, zCmd) {
rc = _sqlite3Fts5FlushToDisk(tls, pTab)
} else {
rc = _sqlite3Fts5FlushToDisk(tls, pTab)
if rc == SQLITE_OK {
rc = _sqlite3Fts5IndexLoadConfig(tls, (*TFts5FullTable)(unsafe.Pointer(pTab)).Fp.FpIndex)
}
if rc == SQLITE_OK {
rc = _sqlite3Fts5ConfigSetValue(tls, (*TFts5FullTable)(unsafe.Pointer(pTab)).Fp.FpConfig, zCmd, pVal, bp)
}
if rc == SQLITE_OK {
if **(**int32)(__ccgo_up(bp)) != 0 {
rc = int32(SQLITE_ERROR)
} else {
rc = _sqlite3Fts5StorageConfigValue(tls, (*TFts5FullTable)(unsafe.Pointer(pTab)).FpStorage, zCmd, pVal, 0)
}
}
}
}
}
}
}
}
if rc == SQLITE_OK && bLoadConfig != 0 {
(*TFts5Config)(unsafe.Pointer((*TFts5FullTable)(unsafe.Pointer(pTab)).Fp.FpConfig)).FiCookie = (*TFts5Config)(unsafe.Pointer((*TFts5FullTable)(unsafe.Pointer(pTab)).Fp.FpConfig)).FiCookie - 1
rc = _sqlite3Fts5IndexLoadConfig(tls, (*TFts5FullTable)(unsafe.Pointer(pTab)).Fp.FpIndex)
}
return rc
}
// C documentation
//
// /*
// ** Process a "special" query. A special query is identified as one with a
// ** MATCH expression that begins with a '*' character. The remainder of
// ** the text passed to the MATCH operator are used as the special query
// ** parameters.
// */
func _fts5SpecialMatch(tls *libc.TLS, pTab uintptr, pCsr uintptr, zQuery uintptr) (r int32) {
bp := tls.Alloc(32)
defer tls.Free(32)
var n, rc int32
var z uintptr
_, _, _ = n, rc, z
rc = SQLITE_OK /* Return code */
z = zQuery /* Number of bytes in text at z */
for int32(**(**int8)(__ccgo_up(z))) == int32(' ') {
z = z + 1
}
n = 0
for {
if !(**(**int8)(__ccgo_up(z + uintptr(n))) != 0 && int32(**(**int8)(__ccgo_up(z + uintptr(n)))) != int32(' ')) {
break
}
goto _1
_1:
;
n = n + 1
}
(*TFts5Cursor)(unsafe.Pointer(pCsr)).FePlan = int32(FTS5_PLAN_SPECIAL)
if n == int32(5) && 0 == Xsqlite3_strnicmp(tls, __ccgo_ts+40208, z, n) {
(*TFts5Cursor)(unsafe.Pointer(pCsr)).FiSpecial = int64(_sqlite3Fts5IndexReads(tls, (*TFts5FullTable)(unsafe.Pointer(pTab)).Fp.FpIndex))
} else {
if n == int32(2) && 0 == Xsqlite3_strnicmp(tls, __ccgo_ts+5996, z, n) {
(*TFts5Cursor)(unsafe.Pointer(pCsr)).FiSpecial = (*TFts5Cursor)(unsafe.Pointer(pCsr)).FiCsrId
} else {
/* An unrecognized directive. Return an error message. */
(*TFts5FullTable)(unsafe.Pointer(pTab)).Fp.Fbase.FzErrMsg = Xsqlite3_mprintf(tls, __ccgo_ts+40214, libc.VaList(bp+8, n, z))
rc = int32(SQLITE_ERROR)
}
}
return rc
}
func _fts5StorageCount(tls *libc.TLS, p uintptr, zSuffix uintptr, pnRow uintptr) (r int32) {
bp := tls.Alloc(48)
defer tls.Free(48)
var pConfig, zSql uintptr
var rc int32
var _ /* pCnt at bp+0 */ uintptr
_, _, _ = pConfig, rc, zSql
pConfig = (*TFts5Storage)(unsafe.Pointer(p)).FpConfig
zSql = Xsqlite3_mprintf(tls, __ccgo_ts+42191, libc.VaList(bp+16, (*TFts5Config)(unsafe.Pointer(pConfig)).FzDb, (*TFts5Config)(unsafe.Pointer(pConfig)).FzName, zSuffix))
if zSql == uintptr(0) {
rc = int32(SQLITE_NOMEM)
} else {
**(**uintptr)(__ccgo_up(bp)) = uintptr(0)
rc = Xsqlite3_prepare_v2(tls, (*TFts5Config)(unsafe.Pointer(pConfig)).Fdb, zSql, -int32(1), bp, uintptr(0))
if rc == SQLITE_OK {
if int32(SQLITE_ROW) == Xsqlite3_step(tls, **(**uintptr)(__ccgo_up(bp))) {
**(**Ti64)(__ccgo_up(pnRow)) = Xsqlite3_column_int64(tls, **(**uintptr)(__ccgo_up(bp)), 0)
}
rc = Xsqlite3_finalize(tls, **(**uintptr)(__ccgo_up(bp)))
}
}
Xsqlite3_free(tls, zSql)
return rc
}
// C documentation
//
// /*
// ** Prepare the two insert statements - Fts5Storage.pInsertContent and
// ** Fts5Storage.pInsertDocsize - if they have not already been prepared.
// ** Return SQLITE_OK if successful, or an SQLite error code if an error
// ** occurs.
// */
func _fts5StorageGetStmt(tls *libc.TLS, p uintptr, eStmt int32, ppStmt uintptr, pzErrMsg uintptr) (r int32) {
bp := tls.Alloc(64)
defer tls.Free(64)
var azStmt [12]uintptr
var f, i int32
var pC, zBind, zSql, v2 uintptr
var _ /* rc at bp+0 */ int32
_, _, _, _, _, _, _ = azStmt, f, i, pC, zBind, zSql, v2
**(**int32)(__ccgo_up(bp)) = SQLITE_OK
/* If there is no %_docsize table, there should be no requests for
** statements to operate on it. */
if **(**uintptr)(__ccgo_up(p + 48 + uintptr(eStmt)*8)) == uintptr(0) {
azStmt = [12]uintptr{
0: __ccgo_ts + 41152,
1: __ccgo_ts + 41220,
2: __ccgo_ts + 41289,
3: __ccgo_ts + 41289,
4: __ccgo_ts + 41322,
5: __ccgo_ts + 41361,
6: __ccgo_ts + 41401,
7: __ccgo_ts + 41440,
8: __ccgo_ts + 41483,
9: __ccgo_ts + 41522,
10: __ccgo_ts + 41566,
11: __ccgo_ts + 41606,
}
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 + 14694
} else {
v2 = __ccgo_ts + 1702
}
zBind = _sqlite3Fts5Mprintf(tls, bp, __ccgo_ts+41629, 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+41637, 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 + 41644
} 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 + 41647
} 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+48+uintptr(eStmt)*8, uintptr(0))
(*TFts5Config)(unsafe.Pointer((*TFts5Storage)(unsafe.Pointer(p)).FpConfig)).FbLock = (*TFts5Config)(unsafe.Pointer((*TFts5Storage)(unsafe.Pointer(p)).FpConfig)).FbLock - 1
Xsqlite3_free(tls, zSql)
if **(**int32)(__ccgo_up(bp)) != SQLITE_OK && pzErrMsg != 0 {
**(**uintptr)(__ccgo_up(pzErrMsg)) = Xsqlite3_mprintf(tls, __ccgo_ts+3944, libc.VaList(bp+16, Xsqlite3_errmsg(tls, (*TFts5Config)(unsafe.Pointer(pC)).Fdb)))
}
if **(**int32)(__ccgo_up(bp)) == int32(SQLITE_ERROR) && eStmt > int32(FTS5_STMT_LOOKUP2) && eStmt < int32(FTS5_STMT_SCAN) {
/* One of the internal tables - not the %_content table - is missing.
** This counts as a corrupted table. */
**(**int32)(__ccgo_up(bp)) = int32(SQLITE_CORRUPT)
}
}
}
**(**uintptr)(__ccgo_up(ppStmt)) = **(**uintptr)(__ccgo_up(p + 48 + uintptr(eStmt)*8))
Xsqlite3_reset(tls, **(**uintptr)(__ccgo_up(ppStmt)))
return **(**int32)(__ccgo_up(bp))
}
func _fts5StorageRenameOne(tls *libc.TLS, pConfig uintptr, pRc uintptr, zTail uintptr, zName uintptr) {
bp := tls.Alloc(48)
defer tls.Free(48)
if **(**int32)(__ccgo_up(pRc)) == SQLITE_OK {
**(**int32)(__ccgo_up(pRc)) = _fts5ExecPrintf(tls, (*TFts5Config)(unsafe.Pointer(pConfig)).Fdb, uintptr(0), __ccgo_ts+41835, libc.VaList(bp+8, (*TFts5Config)(unsafe.Pointer(pConfig)).FzDb, (*TFts5Config)(unsafe.Pointer(pConfig)).FzName, zTail, zName, zTail))
}
}
// C documentation
//
// /*
// ** Store the current contents of the p->nTotalRow and p->aTotalSize[]
// ** variables in the "averages" record on disk.
// **
// ** Return SQLITE_OK if successful, or an SQLite error code if an error
// ** occurs.
// */
func _fts5StorageSaveTotals(tls *libc.TLS, p uintptr) (r int32) {
bp := tls.Alloc(32)
defer tls.Free(32)
var i, nCol int32
var _ /* buf at bp+0 */ TFts5Buffer
var _ /* rc at bp+16 */ int32
_, _ = i, nCol
nCol = (*TFts5Config)(unsafe.Pointer((*TFts5Storage)(unsafe.Pointer(p)).FpConfig)).FnCol
**(**int32)(__ccgo_up(bp + 16)) = SQLITE_OK
libc.X__builtin___memset_chk(tls, bp, 0, uint64(16), ^t__predefined_size_t(0))
_sqlite3Fts5BufferAppendVarint(tls, bp+16, bp, (*TFts5Storage)(unsafe.Pointer(p)).FnTotalRow)
i = 0
for {
if !(i < nCol) {
break
}
_sqlite3Fts5BufferAppendVarint(tls, bp+16, bp, **(**Ti64)(__ccgo_up((*TFts5Storage)(unsafe.Pointer(p)).FaTotalSize + uintptr(i)*8)))
goto _1
_1:
;
i = i + 1
}
if **(**int32)(__ccgo_up(bp + 16)) == SQLITE_OK {
**(**int32)(__ccgo_up(bp + 16)) = _sqlite3Fts5IndexSetAverages(tls, (*TFts5Storage)(unsafe.Pointer(p)).FpIndex, (**(**TFts5Buffer)(__ccgo_up(bp))).Fp, (**(**TFts5Buffer)(__ccgo_up(bp))).Fn)
}
Xsqlite3_free(tls, (**(**TFts5Buffer)(__ccgo_up(bp))).Fp)
return **(**int32)(__ccgo_up(bp + 16))
}
// C documentation
//
// /*
// ** Add a level to the Fts5Structure.aLevel[] array of structure object
// ** (*ppStruct).
// */
func _fts5StructureAddLevel(tls *libc.TLS, pRc uintptr, ppStruct uintptr) {
var nByte Tsqlite3_int64
var nLevel int32
var pStruct uintptr
_, _, _ = nByte, nLevel, pStruct
_fts5StructureMakeWritable(tls, pRc, ppStruct)
if **(**int32)(__ccgo_up(pRc)) == SQLITE_OK {
pStruct = **(**uintptr)(__ccgo_up(ppStruct))
nLevel = (*TFts5Structure)(unsafe.Pointer(pStruct)).FnLevel
nByte = libc.Int64FromUint64(uint64(libc.UintptrFromInt32(0)+32) + libc.Uint64FromInt32(nLevel+libc.Int32FromInt32(2))*libc.Uint64FromInt64(16))
pStruct = Xsqlite3_realloc64(tls, pStruct, libc.Uint64FromInt64(nByte))
if pStruct != 0 {
libc.X__builtin___memset_chk(tls, pStruct+32+uintptr(nLevel)*16, 0, uint64(16), ^t__predefined_size_t(0))
(*TFts5Structure)(unsafe.Pointer(pStruct)).FnLevel = (*TFts5Structure)(unsafe.Pointer(pStruct)).FnLevel + 1
**(**uintptr)(__ccgo_up(ppStruct)) = pStruct
} else {
**(**int32)(__ccgo_up(pRc)) = int32(SQLITE_NOMEM)
}
}
}
// 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+39477, uint64(4)) {
i = i + int32(4)
bStructureV2 = int32(1)
}
/* Read the total number of levels and segments from the start of the
** structure record. */
i = i + _sqlite3Fts5GetVarint32(tls, pData+uintptr(i), bp+4)
i = i + _sqlite3Fts5GetVarint32(tls, pData+uintptr(i), bp+8)
if **(**int32)(__ccgo_up(bp + 4)) > int32(FTS5_MAX_SEGMENT) || **(**int32)(__ccgo_up(bp + 4)) < 0 || **(**int32)(__ccgo_up(bp + 8)) > int32(FTS5_MAX_SEGMENT) || **(**int32)(__ccgo_up(bp + 8)) < 0 {
return libc.Int32FromInt32(SQLITE_CORRUPT) | libc.Int32FromInt32(1)<= nData {
**(**int32)(__ccgo_up(bp)) = libc.Int32FromInt32(SQLITE_CORRUPT) | libc.Int32FromInt32(1)<= nData {
**(**int32)(__ccgo_up(bp)) = libc.Int32FromInt32(SQLITE_CORRUPT) | libc.Int32FromInt32(1)< (*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)< 0 && (**(**TFts5StructureLevel)(__ccgo_up(pLvl + uintptr(-libc.Int32FromInt32(1))*16))).FnMerge != 0 && **(**int32)(__ccgo_up(bp + 12)) == 0 {
**(**int32)(__ccgo_up(bp)) = libc.Int32FromInt32(SQLITE_CORRUPT) | libc.Int32FromInt32(1)< int32(1) {
nByte = libc.Int64FromUint64(uint64(libc.UintptrFromInt32(0)+32) + libc.Uint64FromInt32((*TFts5Structure)(unsafe.Pointer(p)).FnLevel)*libc.Uint64FromInt64(16))
pNew = _sqlite3Fts5MallocZero(tls, pRc, nByte)
if pNew != 0 {
libc.X__builtin___memcpy_chk(tls, pNew, p, libc.Uint64FromInt64(nByte), ^t__predefined_size_t(0))
i = 0
for {
if !(i < (*TFts5Structure)(unsafe.Pointer(p)).FnLevel) {
break
}
(*(*TFts5StructureLevel)(unsafe.Pointer(pNew + 32 + uintptr(i)*16))).FaSeg = uintptr(0)
goto _1
_1:
;
i = i + 1
}
i = 0
for {
if !(i < (*TFts5Structure)(unsafe.Pointer(p)).FnLevel) {
break
}
pLvl = pNew + 32 + uintptr(i)*16
nByte = libc.Int64FromUint64(uint64(56) * libc.Uint64FromInt32((*(*TFts5StructureLevel)(unsafe.Pointer(pNew + 32 + uintptr(i)*16))).FnSeg))
(*TFts5StructureLevel)(unsafe.Pointer(pLvl)).FaSeg = _sqlite3Fts5MallocZero(tls, pRc, nByte)
if (*TFts5StructureLevel)(unsafe.Pointer(pLvl)).FaSeg == uintptr(0) {
i = 0
for {
if !(i < (*TFts5Structure)(unsafe.Pointer(p)).FnLevel) {
break
}
Xsqlite3_free(tls, (*(*TFts5StructureLevel)(unsafe.Pointer(pNew + 32 + uintptr(i)*16))).FaSeg)
goto _3
_3:
;
i = i + 1
}
Xsqlite3_free(tls, pNew)
return
}
libc.X__builtin___memcpy_chk(tls, (*TFts5StructureLevel)(unsafe.Pointer(pLvl)).FaSeg, (*(*TFts5StructureLevel)(unsafe.Pointer(p + 32 + uintptr(i)*16))).FaSeg, libc.Uint64FromInt64(nByte), ^t__predefined_size_t(0))
goto _2
_2:
;
i = i + 1
}
(*TFts5Structure)(unsafe.Pointer(p)).FnRef = (*TFts5Structure)(unsafe.Pointer(p)).FnRef - 1
(*TFts5Structure)(unsafe.Pointer(pNew)).FnRef = int32(1)
}
**(**uintptr)(__ccgo_up(pp)) = pNew
}
}
// C documentation
//
// /*
// ** Return a copy of index structure pStruct. Except, promote as many
// ** segments as possible to level iPromote. If an OOM occurs, NULL is
// ** returned.
// */
func _fts5StructurePromoteTo(tls *libc.TLS, p uintptr, iPromote int32, szPromote int32, pStruct uintptr) {
var il, is, sz int32
var pLvl, pOut uintptr
_, _, _, _, _ = il, is, pLvl, pOut, sz
pOut = pStruct + 32 + uintptr(iPromote)*16
if (*TFts5StructureLevel)(unsafe.Pointer(pOut)).FnMerge == 0 {
il = iPromote + int32(1)
for {
if !(il < (*TFts5Structure)(unsafe.Pointer(pStruct)).FnLevel) {
break
}
pLvl = pStruct + 32 + uintptr(il)*16
if (*TFts5StructureLevel)(unsafe.Pointer(pLvl)).FnMerge != 0 {
return
}
is = (*TFts5StructureLevel)(unsafe.Pointer(pLvl)).FnSeg - int32(1)
for {
if !(is >= 0) {
break
}
sz = _fts5SegmentSize(tls, (*TFts5StructureLevel)(unsafe.Pointer(pLvl)).FaSeg+uintptr(is)*56)
if sz > szPromote {
return
}
_fts5StructureExtendLevel(tls, p+60, pStruct, iPromote, int32(1), int32(1))
if (*TFts5Index)(unsafe.Pointer(p)).Frc != 0 {
return
}
libc.X__builtin___memcpy_chk(tls, (*TFts5StructureLevel)(unsafe.Pointer(pOut)).FaSeg, (*TFts5StructureLevel)(unsafe.Pointer(pLvl)).FaSeg+uintptr(is)*56, uint64(56), ^t__predefined_size_t(0))
(*TFts5StructureLevel)(unsafe.Pointer(pOut)).FnSeg = (*TFts5StructureLevel)(unsafe.Pointer(pOut)).FnSeg + 1
(*TFts5StructureLevel)(unsafe.Pointer(pLvl)).FnSeg = (*TFts5StructureLevel)(unsafe.Pointer(pLvl)).FnSeg - 1
goto _2
_2:
;
is = is - 1
}
goto _1
_1:
;
il = il + 1
}
}
}
func _fts5StructureReadUncached(tls *libc.TLS, p uintptr) (r uintptr) {
bp := tls.Alloc(32)
defer tls.Free(32)
var pConfig, pData uintptr
var _ /* iCookie at bp+8 */ int32
var _ /* pRet at bp+0 */ uintptr
_, _ = pConfig, pData
**(**uintptr)(__ccgo_up(bp)) = uintptr(0)
pConfig = (*TFts5Index)(unsafe.Pointer(p)).FpConfig
pData = _fts5DataRead(tls, p, int64(FTS5_STRUCTURE_ROWID))
if (*TFts5Index)(unsafe.Pointer(p)).Frc == SQLITE_OK {
/* TODO: Do we need this if the leaf-index is appended? Probably... */
libc.X__builtin___memset_chk(tls, (*TFts5Data)(unsafe.Pointer(pData)).Fp+uintptr((*TFts5Data)(unsafe.Pointer(pData)).Fnn), 0, uint64(FTS5_DATA_PADDING), ^t__predefined_size_t(0))
(*TFts5Index)(unsafe.Pointer(p)).Frc = _fts5StructureDecode(tls, (*TFts5Data)(unsafe.Pointer(pData)).Fp, (*TFts5Data)(unsafe.Pointer(pData)).Fnn, bp+8, bp)
if (*TFts5Index)(unsafe.Pointer(p)).Frc == SQLITE_OK {
if (*TFts5Config)(unsafe.Pointer(pConfig)).Fpgsz == 0 || (*TFts5Config)(unsafe.Pointer(pConfig)).FiCookie != **(**int32)(__ccgo_up(bp + 8)) {
(*TFts5Index)(unsafe.Pointer(p)).Frc = _sqlite3Fts5ConfigLoad(tls, pConfig, **(**int32)(__ccgo_up(bp + 8)))
}
} else {
if (*TFts5Index)(unsafe.Pointer(p)).Frc == libc.Int32FromInt32(SQLITE_CORRUPT)|libc.Int32FromInt32(1)< 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.X__builtin___memset_chk(tls, bp, 0, uint64(16), ^t__predefined_size_t(0))
/* Append the current configuration cookie */
iCookie = (*TFts5Config)(unsafe.Pointer((*TFts5Index)(unsafe.Pointer(p)).FpConfig)).FiCookie
if iCookie < 0 {
iCookie = 0
}
if 0 == _sqlite3Fts5BufferSize(tls, p+60, bp, libc.Uint32FromInt32(nHdr)) {
_sqlite3Fts5Put32(tls, (**(**TFts5Buffer)(__ccgo_up(bp))).Fp, iCookie)
(**(**TFts5Buffer)(__ccgo_up(bp))).Fn = int32(4)
if (*TFts5Structure)(unsafe.Pointer(pStruct)).FnOriginCntr > uint64(0) {
libc.X__builtin___memcpy_chk(tls, (*TFts5Buffer)(unsafe.Pointer(bp)).Fp+uintptr((*TFts5Buffer)(unsafe.Pointer(bp)).Fn), __ccgo_ts+39477, uint64(4), ^t__predefined_size_t(0))
**(**int32)(__ccgo_up(bp + 8)) += int32(4)
}
**(**int32)(__ccgo_up(bp + 8)) += _sqlite3Fts5PutVarint(tls, (*TFts5Buffer)(unsafe.Pointer(bp)).Fp+uintptr((*TFts5Buffer)(unsafe.Pointer(bp)).Fn), libc.Uint64FromInt32((*TFts5Structure)(unsafe.Pointer(pStruct)).FnLevel))
**(**int32)(__ccgo_up(bp + 8)) += _sqlite3Fts5PutVarint(tls, (*TFts5Buffer)(unsafe.Pointer(bp)).Fp+uintptr((*TFts5Buffer)(unsafe.Pointer(bp)).Fn), libc.Uint64FromInt32((*TFts5Structure)(unsafe.Pointer(pStruct)).FnSegment))
**(**int32)(__ccgo_up(bp + 8)) += _sqlite3Fts5PutVarint(tls, (*TFts5Buffer)(unsafe.Pointer(bp)).Fp+uintptr((*TFts5Buffer)(unsafe.Pointer(bp)).Fn), libc.Uint64FromInt64(libc.Int64FromUint64((*TFts5Structure)(unsafe.Pointer(pStruct)).FnWriteCounter)))
}
iLvl = 0
for {
if !(iLvl < (*TFts5Structure)(unsafe.Pointer(pStruct)).FnLevel) {
break
} /* Used to iterate through segments */
pLvl = pStruct + 32 + uintptr(iLvl)*16
_sqlite3Fts5BufferAppendVarint(tls, p+60, bp, int64((*TFts5StructureLevel)(unsafe.Pointer(pLvl)).FnMerge))
_sqlite3Fts5BufferAppendVarint(tls, p+60, bp, int64((*TFts5StructureLevel)(unsafe.Pointer(pLvl)).FnSeg))
iSeg = 0
for {
if !(iSeg < (*TFts5StructureLevel)(unsafe.Pointer(pLvl)).FnSeg) {
break
}
pSeg = (*TFts5StructureLevel)(unsafe.Pointer(pLvl)).FaSeg + uintptr(iSeg)*56
_sqlite3Fts5BufferAppendVarint(tls, p+60, bp, int64((*TFts5StructureSegment)(unsafe.Pointer(pSeg)).FiSegid))
_sqlite3Fts5BufferAppendVarint(tls, p+60, bp, int64((*TFts5StructureSegment)(unsafe.Pointer(pSeg)).FpgnoFirst))
_sqlite3Fts5BufferAppendVarint(tls, p+60, bp, int64((*TFts5StructureSegment)(unsafe.Pointer(pSeg)).FpgnoLast))
if (*TFts5Structure)(unsafe.Pointer(pStruct)).FnOriginCntr > uint64(0) {
_sqlite3Fts5BufferAppendVarint(tls, p+60, bp, libc.Int64FromUint64((*TFts5StructureSegment)(unsafe.Pointer(pSeg)).FiOrigin1))
_sqlite3Fts5BufferAppendVarint(tls, p+60, bp, libc.Int64FromUint64((*TFts5StructureSegment)(unsafe.Pointer(pSeg)).FiOrigin2))
_sqlite3Fts5BufferAppendVarint(tls, p+60, bp, int64((*TFts5StructureSegment)(unsafe.Pointer(pSeg)).FnPgTombstone))
_sqlite3Fts5BufferAppendVarint(tls, p+60, bp, libc.Int64FromUint64((*TFts5StructureSegment)(unsafe.Pointer(pSeg)).FnEntryTombstone))
_sqlite3Fts5BufferAppendVarint(tls, p+60, bp, libc.Int64FromUint64((*TFts5StructureSegment)(unsafe.Pointer(pSeg)).FnEntry))
}
goto _3
_3:
;
iSeg = iSeg + 1
}
goto _2
_2:
;
iLvl = iLvl + 1
}
_fts5DataWrite(tls, p, int64(FTS5_STRUCTURE_ROWID), (**(**TFts5Buffer)(__ccgo_up(bp))).Fp, (**(**TFts5Buffer)(__ccgo_up(bp))).Fn)
_sqlite3Fts5BufferFree(tls, bp)
}
}
// C documentation
//
// /*
// ** Sort the contents of the pT->aMap[] array.
// **
// ** The sorting algorithm requires a malloc(). If this fails, an error code
// ** is left in Fts5Index.rc before returning.
// */
func _fts5TokendataIterSortMap(tls *libc.TLS, p uintptr, pT uintptr) {
var a1, a2, aTmp, tmp uintptr
var i1, n1, n2 int32
var nByte, nHalf Ti64
var v3, v4 int64
_, _, _, _, _, _, _, _, _, _, _ = a1, a2, aTmp, i1, n1, n2, nByte, nHalf, tmp, v3, v4
aTmp = uintptr(0)
nByte = libc.Int64FromUint64(libc.Uint64FromInt64((*TFts5TokenDataIter)(unsafe.Pointer(pT)).FnMap) * uint64(24))
aTmp = _sqlite3Fts5MallocZero(tls, p+60, nByte)
if aTmp != 0 {
a1 = (*TFts5TokenDataIter)(unsafe.Pointer(pT)).FaMap
a2 = aTmp
nHalf = int64(1)
for {
if !(nHalf < (*TFts5TokenDataIter)(unsafe.Pointer(pT)).FnMap) {
break
}
i1 = 0
for {
if !(int64(i1) < (*TFts5TokenDataIter)(unsafe.Pointer(pT)).FnMap) {
break
}
if nHalf < (*TFts5TokenDataIter)(unsafe.Pointer(pT)).FnMap-int64(i1) {
v3 = nHalf
} else {
v3 = (*TFts5TokenDataIter)(unsafe.Pointer(pT)).FnMap - int64(i1)
}
n1 = int32(v3)
if nHalf < (*TFts5TokenDataIter)(unsafe.Pointer(pT)).FnMap-int64(i1)-int64(n1) {
v4 = nHalf
} else {
v4 = (*TFts5TokenDataIter)(unsafe.Pointer(pT)).FnMap - int64(i1) - int64(n1)
}
n2 = int32(v4)
_fts5TokendataMerge(tls, a1+uintptr(i1)*24, n1, a1+uintptr(i1+n1)*24, n2, a2+uintptr(i1)*24)
goto _2
_2:
;
i1 = int32(int64(i1) + nHalf*libc.Int64FromInt32(2))
}
tmp = a1
a1 = a2
a2 = tmp
goto _1
_1:
;
nHalf = nHalf * int64(2)
}
if a1 != (*TFts5TokenDataIter)(unsafe.Pointer(pT)).FaMap {
libc.X__builtin___memcpy_chk(tls, (*TFts5TokenDataIter)(unsafe.Pointer(pT)).FaMap, a1, uint64(libc.Uint64FromInt64((*TFts5TokenDataIter)(unsafe.Pointer(pT)).FnMap)*uint64(24)), ^t__predefined_size_t(0))
}
Xsqlite3_free(tls, aTmp)
}
}
// C documentation
//
// /*
// ** The two input arrays - a1[] and a2[] - are in sorted order. This function
// ** merges the two arrays together and writes the result to output array
// ** aOut[]. aOut[] is guaranteed to be large enough to hold the result.
// **
// ** Duplicate entries are copied into the output. So the size of the output
// ** array is always (n1+n2) entries.
// */
func _fts5TokendataMerge(tls *libc.TLS, a1 uintptr, n1 int32, a2 uintptr, n2 int32, aOut uintptr) {
var i1, i2 int32
var pOut uintptr
_, _, _ = i1, i2, pOut
i1 = 0
i2 = 0
for i1 < n1 || i2 < n2 {
pOut = aOut + uintptr(i1+i2)*24
if i2 >= n2 || i1 < n1 && ((**(**TFts5TokenDataMap)(__ccgo_up(a1 + uintptr(i1)*24))).FiRowid < (**(**TFts5TokenDataMap)(__ccgo_up(a2 + uintptr(i2)*24))).FiRowid || (**(**TFts5TokenDataMap)(__ccgo_up(a1 + uintptr(i1)*24))).FiRowid == (**(**TFts5TokenDataMap)(__ccgo_up(a2 + uintptr(i2)*24))).FiRowid && (**(**TFts5TokenDataMap)(__ccgo_up(a1 + uintptr(i1)*24))).FiPos <= (**(**TFts5TokenDataMap)(__ccgo_up(a2 + uintptr(i2)*24))).FiPos) {
libc.X__builtin___memcpy_chk(tls, pOut, a1+uintptr(i1)*24, uint64(24), ^t__predefined_size_t(0))
i1 = i1 + 1
} else {
libc.X__builtin___memcpy_chk(tls, pOut, a2+uintptr(i2)*24, uint64(24), ^t__predefined_size_t(0))
i2 = i2 + 1
}
}
}
// 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))*8))
if 0 == Xsqlite3_stricmp(tls, **(**uintptr)(__ccgo_up(azArg + uintptr(i)*8)), __ccgo_ts+42579) {
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)*8)), __ccgo_ts+42265) {
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
//
// /*
// ** Trigram tokenizer tokenize routine.
// */
func _fts5TriTokenize(tls *libc.TLS, pTok uintptr, pCtx uintptr, unusedFlags int32, pText uintptr, nText int32, __ccgo_fp_xToken uintptr) (r int32) {
bp := tls.Alloc(32)
defer tls.Free(32)
var aStart [3]int32
var iCode Tu32
var iNext, ii, rc int32
var p, z1, zEof, zIn, zOut, v1 uintptr
var _ /* aBuf at bp+0 */ [32]int8
_, _, _, _, _, _, _, _, _, _, _ = aStart, iCode, iNext, ii, p, rc, z1, zEof, zIn, zOut, v1
p = pTok
rc = SQLITE_OK
zOut = bp
zIn = pText
if zIn != 0 {
v1 = zIn + uintptr(nText)
} else {
v1 = uintptr(0)
}
zEof = v1
iCode = uint32(0) /* Input offset of each character in aBuf[] */
_ = unusedFlags
/* Populate aBuf[] with the characters for the first trigram. */
ii = 0
for {
if !(ii < int32(3)) {
break
}
for cond := true; cond; cond = iCode == uint32(0) {
aStart[ii] = int32(int64(zIn) - int64(pText))
if zIn >= zEof {
return SQLITE_OK
}
v1 = zIn
zIn = zIn + 1
iCode = uint32(**(**uint8)(__ccgo_up(v1)))
if iCode >= uint32(0xc0) {
iCode = uint32(_sqlite3Utf8Trans1[iCode-uint32(0xc0)])
for zIn < zEof && libc.Int32FromUint8(**(**uint8)(__ccgo_up(zIn)))&int32(0xc0) == int32(0x80) {
v1 = zIn
zIn = zIn + 1
iCode = iCode<>libc.Int32FromInt32(6)&libc.Uint32FromInt32(0x1F))))
v1 = zOut
zOut = zOut + 1
**(**int8)(__ccgo_up(v1)) = int8(int32(0x80) + libc.Int32FromUint8(uint8(iCode&libc.Uint32FromInt32(0x3F))))
} else {
if iCode < uint32(0x10000) {
v1 = zOut
zOut = zOut + 1
**(**int8)(__ccgo_up(v1)) = int8(int32(0xE0) + libc.Int32FromUint8(uint8(iCode>>libc.Int32FromInt32(12)&libc.Uint32FromInt32(0x0F))))
v1 = zOut
zOut = zOut + 1
**(**int8)(__ccgo_up(v1)) = int8(int32(0x80) + libc.Int32FromUint8(uint8(iCode>>libc.Int32FromInt32(6)&libc.Uint32FromInt32(0x3F))))
v1 = zOut
zOut = zOut + 1
**(**int8)(__ccgo_up(v1)) = int8(int32(0x80) + libc.Int32FromUint8(uint8(iCode&libc.Uint32FromInt32(0x3F))))
} else {
v1 = zOut
zOut = zOut + 1
**(**int8)(__ccgo_up(v1)) = int8(int32(0xF0) + libc.Int32FromUint8(uint8(iCode>>libc.Int32FromInt32(18)&libc.Uint32FromInt32(0x07))))
v1 = zOut
zOut = zOut + 1
**(**int8)(__ccgo_up(v1)) = int8(int32(0x80) + libc.Int32FromUint8(uint8(iCode>>libc.Int32FromInt32(12)&libc.Uint32FromInt32(0x3F))))
v1 = zOut
zOut = zOut + 1
**(**int8)(__ccgo_up(v1)) = int8(int32(0x80) + libc.Int32FromUint8(uint8(iCode>>libc.Int32FromInt32(6)&libc.Uint32FromInt32(0x3F))))
v1 = zOut
zOut = zOut + 1
**(**int8)(__ccgo_up(v1)) = int8(int32(0x80) + libc.Int32FromUint8(uint8(iCode&libc.Uint32FromInt32(0x3F))))
}
}
}
goto _2
_2:
;
ii = ii + 1
}
/* At the start of each iteration of this loop:
**
** aBuf: Contains 3 characters. The 3 characters of the next trigram.
** zOut: Points to the byte following the last character in aBuf.
** aStart[3]: Contains the byte offset in the input text corresponding
** to the start of each of the three characters in the buffer.
*/
for int32(1) != 0 {
/* Read characters from the input up until the first non-diacritic */
for cond := true; cond; cond = iCode == uint32(0) {
iNext = int32(int64(zIn) - int64(pText))
if zIn >= zEof {
iCode = uint32(0)
break
}
v1 = zIn
zIn = zIn + 1
iCode = uint32(**(**uint8)(__ccgo_up(v1)))
if iCode >= uint32(0xc0) {
iCode = uint32(_sqlite3Utf8Trans1[iCode-uint32(0xc0)])
for zIn < zEof && libc.Int32FromUint8(**(**uint8)(__ccgo_up(zIn)))&int32(0xc0) == int32(0x80) {
v1 = zIn
zIn = zIn + 1
iCode = iCode<= int32(0xc0) {
for libc.Int32FromUint8(libc.Uint8FromInt8(**(**int8)(__ccgo_up(z1))))&int32(0xc0) == int32(0x80) {
z1 = z1 + 1
}
}
libc.X__builtin___memmove_chk(tls, bp, z1, libc.Uint64FromInt64(int64(zOut)-int64(z1)), ^t__predefined_size_t(0))
zOut = zOut - uintptr(int64(z1)-t__predefined_ptrdiff_t(bp))
if iCode < uint32(0x00080) {
v1 = zOut
zOut = zOut + 1
**(**int8)(__ccgo_up(v1)) = libc.Int8FromUint8(uint8(iCode & libc.Uint32FromInt32(0xFF)))
} else {
if iCode < uint32(0x00800) {
v1 = zOut
zOut = zOut + 1
**(**int8)(__ccgo_up(v1)) = int8(int32(0xC0) + libc.Int32FromUint8(uint8(iCode>>libc.Int32FromInt32(6)&libc.Uint32FromInt32(0x1F))))
v1 = zOut
zOut = zOut + 1
**(**int8)(__ccgo_up(v1)) = int8(int32(0x80) + libc.Int32FromUint8(uint8(iCode&libc.Uint32FromInt32(0x3F))))
} else {
if iCode < uint32(0x10000) {
v1 = zOut
zOut = zOut + 1
**(**int8)(__ccgo_up(v1)) = int8(int32(0xE0) + libc.Int32FromUint8(uint8(iCode>>libc.Int32FromInt32(12)&libc.Uint32FromInt32(0x0F))))
v1 = zOut
zOut = zOut + 1
**(**int8)(__ccgo_up(v1)) = int8(int32(0x80) + libc.Int32FromUint8(uint8(iCode>>libc.Int32FromInt32(6)&libc.Uint32FromInt32(0x3F))))
v1 = zOut
zOut = zOut + 1
**(**int8)(__ccgo_up(v1)) = int8(int32(0x80) + libc.Int32FromUint8(uint8(iCode&libc.Uint32FromInt32(0x3F))))
} else {
v1 = zOut
zOut = zOut + 1
**(**int8)(__ccgo_up(v1)) = int8(int32(0xF0) + libc.Int32FromUint8(uint8(iCode>>libc.Int32FromInt32(18)&libc.Uint32FromInt32(0x07))))
v1 = zOut
zOut = zOut + 1
**(**int8)(__ccgo_up(v1)) = int8(int32(0x80) + libc.Int32FromUint8(uint8(iCode>>libc.Int32FromInt32(12)&libc.Uint32FromInt32(0x3F))))
v1 = zOut
zOut = zOut + 1
**(**int8)(__ccgo_up(v1)) = int8(int32(0x80) + libc.Int32FromUint8(uint8(iCode>>libc.Int32FromInt32(6)&libc.Uint32FromInt32(0x3F))))
v1 = zOut
zOut = zOut + 1
**(**int8)(__ccgo_up(v1)) = int8(int32(0x80) + libc.Int32FromUint8(uint8(iCode&libc.Uint32FromInt32(0x3F))))
}
}
}
/* Update the aStart[] array */
aStart[0] = aStart[int32(1)]
aStart[int32(1)] = aStart[int32(2)]
aStart[int32(2)] = iNext
}
return rc
}
// C documentation
//
// /*
// ** Iterator pIter was used to iterate through the input segments of on an
// ** incremental merge operation. This function is called if the incremental
// ** merge step has finished but the input has not been completely exhausted.
// */
func _fts5TrimSegments(tls *libc.TLS, p uintptr, pIter uintptr) {
bp := tls.Alloc(32)
defer tls.Free(32)
var i, iId, iOff, nDiff int32
var iLeafRowid Ti64
var pData, pSeg uintptr
var _ /* aHdr at bp+16 */ [4]Tu8
var _ /* buf at bp+0 */ TFts5Buffer
_, _, _, _, _, _, _ = i, iId, iLeafRowid, iOff, nDiff, pData, pSeg
libc.X__builtin___memset_chk(tls, bp, 0, uint64(16), ^t__predefined_size_t(0))
i = 0
for {
if !(i < (*TFts5Iter)(unsafe.Pointer(pIter)).FnSeg && (*TFts5Index)(unsafe.Pointer(p)).Frc == SQLITE_OK) {
break
}
pSeg = pIter + 104 + uintptr(i)*128
if (*TFts5SegIter)(unsafe.Pointer(pSeg)).FpSeg == uintptr(0) {
/* no-op */
} else {
if (*TFts5SegIter)(unsafe.Pointer(pSeg)).FpLeaf == uintptr(0) {
/* All keys from this input segment have been transfered to the output.
** Set both the first and last page-numbers to 0 to indicate that the
** segment is now empty. */
(*TFts5StructureSegment)(unsafe.Pointer((*TFts5SegIter)(unsafe.Pointer(pSeg)).FpSeg)).FpgnoLast = 0
(*TFts5StructureSegment)(unsafe.Pointer((*TFts5SegIter)(unsafe.Pointer(pSeg)).FpSeg)).FpgnoFirst = 0
} else {
iOff = (*TFts5SegIter)(unsafe.Pointer(pSeg)).FiTermLeafOffset
iId = (*TFts5StructureSegment)(unsafe.Pointer((*TFts5SegIter)(unsafe.Pointer(pSeg)).FpSeg)).FiSegid
**(**[4]Tu8)(__ccgo_up(bp + 16)) = [4]Tu8{}
iLeafRowid = int64(iId)<<(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))< (*TFts5Data)(unsafe.Pointer(pData)).FszLeaf {
/* This can occur if the pages that the segments occupy overlap - if
** a single page has been assigned to more than one segment. In
** this case a prior iteration of this loop may have corrupted the
** segment currently being trimmed. */
_fts5IndexCorruptRowid(tls, p, iLeafRowid)
} else {
_sqlite3Fts5BufferZero(tls, bp)
if !(libc.Uint32FromInt32((*TFts5Buffer)(unsafe.Pointer(bp)).Fn)+libc.Uint32FromInt32((*TFts5Data)(unsafe.Pointer(pData)).Fnn) <= libc.Uint32FromInt32((*TFts5Buffer)(unsafe.Pointer(bp)).FnSpace)) {
_sqlite3Fts5BufferSize(tls, p+60, bp, libc.Uint32FromInt32((*TFts5Data)(unsafe.Pointer(pData)).Fnn+(*TFts5Buffer)(unsafe.Pointer(bp)).Fn))
}
_sqlite3Fts5BufferAppendBlob(tls, p+60, bp, uint32(4), bp+16)
_sqlite3Fts5BufferAppendVarint(tls, p+60, bp, int64((*TFts5SegIter)(unsafe.Pointer(pSeg)).Fterm.Fn))
_sqlite3Fts5BufferAppendBlob(tls, p+60, bp, libc.Uint32FromInt32((*TFts5SegIter)(unsafe.Pointer(pSeg)).Fterm.Fn), (*TFts5SegIter)(unsafe.Pointer(pSeg)).Fterm.Fp)
_sqlite3Fts5BufferAppendBlob(tls, p+60, bp, libc.Uint32FromInt32((*TFts5Data)(unsafe.Pointer(pData)).FszLeaf-iOff), (*TFts5Data)(unsafe.Pointer(pData)).Fp+uintptr(iOff))
if (*TFts5Index)(unsafe.Pointer(p)).Frc == SQLITE_OK {
/* Set the szLeaf field */
_fts5PutU16(tls, (**(**TFts5Buffer)(__ccgo_up(bp))).Fp+2, libc.Uint16FromInt32((**(**TFts5Buffer)(__ccgo_up(bp))).Fn))
}
/* Set up the new page-index array */
_sqlite3Fts5BufferAppendVarint(tls, p+60, bp, libc.Int64FromInt32(4))
if (*TFts5SegIter)(unsafe.Pointer(pSeg)).FiLeafPgno == (*TFts5SegIter)(unsafe.Pointer(pSeg)).FiTermLeafPgno && (*TFts5SegIter)(unsafe.Pointer(pSeg)).FiEndofDoclist < (*TFts5Data)(unsafe.Pointer(pData)).FszLeaf && (*TFts5SegIter)(unsafe.Pointer(pSeg)).FiPgidxOff <= (*TFts5Data)(unsafe.Pointer(pData)).Fnn {
nDiff = (*TFts5Data)(unsafe.Pointer(pData)).FszLeaf - (*TFts5SegIter)(unsafe.Pointer(pSeg)).FiEndofDoclist
_sqlite3Fts5BufferAppendVarint(tls, p+60, bp, int64((**(**TFts5Buffer)(__ccgo_up(bp))).Fn)-int64(1)-int64(nDiff)-int64(4))
_sqlite3Fts5BufferAppendBlob(tls, p+60, bp, libc.Uint32FromInt32((*TFts5Data)(unsafe.Pointer(pData)).Fnn-(*TFts5SegIter)(unsafe.Pointer(pSeg)).FiPgidxOff), (*TFts5Data)(unsafe.Pointer(pData)).Fp+uintptr((*TFts5SegIter)(unsafe.Pointer(pSeg)).FiPgidxOff))
}
(*TFts5StructureSegment)(unsafe.Pointer((*TFts5SegIter)(unsafe.Pointer(pSeg)).FpSeg)).FpgnoFirst = (*TFts5SegIter)(unsafe.Pointer(pSeg)).FiTermLeafPgno
_fts5DataDelete(tls, p, int64(iId)<<(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))< 0 {
aNew = Xsqlite3_realloc64(tls, (*TUnicode61Tokenizer)(unsafe.Pointer(p)).FaiException, uint64(libc.Uint64FromInt32(n+(*TUnicode61Tokenizer)(unsafe.Pointer(p)).FnException)*uint64(4)))
if aNew != 0 {
nNew = (*TUnicode61Tokenizer)(unsafe.Pointer(p)).FnException
zCsr = z
zTerm = z + uintptr(n)
for zCsr < zTerm {
v1 = zCsr
zCsr = zCsr + 1
iCode = uint32(**(**uint8)(__ccgo_up(v1)))
if iCode >= uint32(0xc0) {
iCode = uint32(_sqlite3Utf8Trans1[iCode-uint32(0xc0)])
for zCsr < zTerm && libc.Int32FromUint8(**(**uint8)(__ccgo_up(zCsr)))&int32(0xc0) == int32(0x80) {
v1 = zCsr
zCsr = zCsr + 1
iCode = iCode< iCode {
break
}
goto _3
_3:
;
i = i + 1
}
libc.X__builtin___memmove_chk(tls, aNew+uintptr(i+int32(1))*4, aNew+uintptr(i)*4, libc.Uint64FromInt32(nNew-i)*uint64(4), ^t__predefined_size_t(0))
**(**int32)(__ccgo_up(aNew + uintptr(i)*4)) = libc.Int32FromUint32(iCode)
nNew = nNew + 1
}
}
}
(*TUnicode61Tokenizer)(unsafe.Pointer(p)).FaiException = aNew
(*TUnicode61Tokenizer)(unsafe.Pointer(p)).FnException = nNew
} else {
rc = int32(SQLITE_NOMEM)
}
}
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(192))
if p != 0 {
zCat = __ccgo_ts + 42245
libc.X__builtin___memset_chk(tls, p, 0, uint64(192), ^t__predefined_size_t(0))
(*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.Uint64FromInt32((*TUnicode61Tokenizer)(unsafe.Pointer(p)).FnFold)*uint64(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)*8)), __ccgo_ts+42254) {
zCat = **(**uintptr)(__ccgo_up(azArg + uintptr(i+int32(1))*8))
}
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))*8))
if 0 == Xsqlite3_stricmp(tls, **(**uintptr)(__ccgo_up(azArg + uintptr(i)*8)), __ccgo_ts+42265) {
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)*8)), __ccgo_ts+42223) {
rc = _fts5UnicodeAddExceptions(tls, p, zArg, int32(1))
} else {
if 0 == Xsqlite3_stricmp(tls, **(**uintptr)(__ccgo_up(azArg + uintptr(i)*8)), __ccgo_ts+42234) {
rc = _fts5UnicodeAddExceptions(tls, p, zArg, 0)
} else {
if 0 == Xsqlite3_stricmp(tls, **(**uintptr)(__ccgo_up(azArg + uintptr(i)*8)), __ccgo_ts+42254) {
/* 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
}
func _fts5UnicodeTokenize(tls *libc.TLS, pTokenizer uintptr, pCtx uintptr, iUnused int32, pText uintptr, nText int32, __ccgo_fp_xToken uintptr) (r int32) {
var a, aFold, p, pEnd, zCsr, zOut, zTerm, v3 uintptr
var iCode Tu32
var ie, is, nFold, rc, v7 int32
_, _, _, _, _, _, _, _, _, _, _, _, _, _ = a, aFold, iCode, ie, is, nFold, p, pEnd, rc, zCsr, zOut, zTerm, v3, v7
p = pTokenizer
rc = SQLITE_OK
a = p
zTerm = pText + uintptr(nText)
zCsr = pText
/* Output buffer */
aFold = (*TUnicode61Tokenizer)(unsafe.Pointer(p)).FaFold
nFold = (*TUnicode61Tokenizer)(unsafe.Pointer(p)).FnFold
pEnd = aFold + uintptr(nFold-int32(6))
_ = iUnused
/* Each iteration of this loop gobbles up a contiguous run of separators,
** then the next token. */
_2:
;
if !(rc == SQLITE_OK) {
goto _1
} /* non-ASCII codepoint read from input */
zOut = aFold
/* Skip any separator characters. */
for int32(1) != 0 {
if zCsr >= zTerm {
goto tokenize_done
}
if libc.Int32FromUint8(**(**uint8)(__ccgo_up(zCsr)))&int32(0x80) != 0 {
/* A character outside of the ascii range. Skip past it if it is
** a separator character. Or break out of the loop if it is not. */
is = int32(int64(zCsr) - int64(pText))
v3 = zCsr
zCsr = zCsr + 1
iCode = uint32(**(**uint8)(__ccgo_up(v3)))
if iCode >= uint32(0xc0) {
iCode = uint32(_sqlite3Utf8Trans1[iCode-uint32(0xc0)])
for zCsr < zTerm && libc.Int32FromUint8(**(**uint8)(__ccgo_up(zCsr)))&int32(0xc0) == int32(0x80) {
v3 = zCsr
zCsr = zCsr + 1
iCode = iCode< pEnd {
aFold = Xsqlite3_malloc64(tls, libc.Uint64FromInt64(int64(nFold)*int64(2)))
if aFold == uintptr(0) {
rc = int32(SQLITE_NOMEM)
goto tokenize_done
}
zOut = aFold + uintptr(int64(zOut)-int64((*TUnicode61Tokenizer)(unsafe.Pointer(p)).FaFold))
libc.X__builtin___memcpy_chk(tls, aFold, (*TUnicode61Tokenizer)(unsafe.Pointer(p)).FaFold, libc.Uint64FromInt32(nFold), ^t__predefined_size_t(0))
Xsqlite3_free(tls, (*TUnicode61Tokenizer)(unsafe.Pointer(p)).FaFold)
(*TUnicode61Tokenizer)(unsafe.Pointer(p)).FaFold = aFold
v7 = nFold * libc.Int32FromInt32(2)
nFold = v7
(*TUnicode61Tokenizer)(unsafe.Pointer(p)).FnFold = v7
pEnd = aFold + uintptr(nFold-int32(6))
}
if !(libc.Int32FromUint8(**(**uint8)(__ccgo_up(zCsr)))&int32(0x80) != 0) {
goto _8
}
/* An non-ascii-range character. Fold it into the output buffer if
** it is a token character, or break out of the loop if it is not. */
v3 = zCsr
zCsr = zCsr + 1
iCode = uint32(**(**uint8)(__ccgo_up(v3)))
if iCode >= uint32(0xc0) {
iCode = uint32(_sqlite3Utf8Trans1[iCode-uint32(0xc0)])
for zCsr < zTerm && libc.Int32FromUint8(**(**uint8)(__ccgo_up(zCsr)))&int32(0xc0) == int32(0x80) {
v3 = zCsr
zCsr = zCsr + 1
iCode = iCode<>libc.Int32FromInt32(6)&libc.Uint32FromInt32(0x1F))))
v3 = zOut
zOut = zOut + 1
**(**int8)(__ccgo_up(v3)) = int8(int32(0x80) + libc.Int32FromUint8(uint8(iCode&libc.Uint32FromInt32(0x3F))))
} else {
if iCode < uint32(0x10000) {
v3 = zOut
zOut = zOut + 1
**(**int8)(__ccgo_up(v3)) = int8(int32(0xE0) + libc.Int32FromUint8(uint8(iCode>>libc.Int32FromInt32(12)&libc.Uint32FromInt32(0x0F))))
v3 = zOut
zOut = zOut + 1
**(**int8)(__ccgo_up(v3)) = int8(int32(0x80) + libc.Int32FromUint8(uint8(iCode>>libc.Int32FromInt32(6)&libc.Uint32FromInt32(0x3F))))
v3 = zOut
zOut = zOut + 1
**(**int8)(__ccgo_up(v3)) = int8(int32(0x80) + libc.Int32FromUint8(uint8(iCode&libc.Uint32FromInt32(0x3F))))
} else {
v3 = zOut
zOut = zOut + 1
**(**int8)(__ccgo_up(v3)) = int8(int32(0xF0) + libc.Int32FromUint8(uint8(iCode>>libc.Int32FromInt32(18)&libc.Uint32FromInt32(0x07))))
v3 = zOut
zOut = zOut + 1
**(**int8)(__ccgo_up(v3)) = int8(int32(0x80) + libc.Int32FromUint8(uint8(iCode>>libc.Int32FromInt32(12)&libc.Uint32FromInt32(0x3F))))
v3 = zOut
zOut = zOut + 1
**(**int8)(__ccgo_up(v3)) = int8(int32(0x80) + libc.Int32FromUint8(uint8(iCode>>libc.Int32FromInt32(6)&libc.Uint32FromInt32(0x3F))))
v3 = zOut
zOut = zOut + 1
**(**int8)(__ccgo_up(v3)) = int8(int32(0x80) + libc.Int32FromUint8(uint8(iCode&libc.Uint32FromInt32(0x3F))))
}
}
}
}
goto _13
_12:
;
goto _5
_13:
;
goto _9
_8:
;
if !(libc.Int32FromUint8(**(**uint8)(__ccgo_up(a + uintptr(**(**uint8)(__ccgo_up(zCsr)))))) == 0) {
goto _24
}
/* An ascii-range separator character. End of token. */
goto _5
goto _25
_24:
;
goto ascii_tokenchar
ascii_tokenchar:
;
if libc.Int32FromUint8(**(**uint8)(__ccgo_up(zCsr))) >= int32('A') && libc.Int32FromUint8(**(**uint8)(__ccgo_up(zCsr))) <= int32('Z') {
v3 = zOut
zOut = zOut + 1
**(**int8)(__ccgo_up(v3)) = int8(libc.Int32FromUint8(**(**uint8)(__ccgo_up(zCsr))) + int32(32))
} else {
v3 = zOut
zOut = zOut + 1
**(**int8)(__ccgo_up(v3)) = libc.Int8FromUint8(**(**uint8)(__ccgo_up(zCsr)))
}
zCsr = zCsr + 1
_25:
;
_9:
;
ie = int32(int64(zCsr) - int64(pText))
goto _6
_5:
;
/* 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, aFold, int32(int64(zOut)-int64(aFold)), is, ie)
goto _2
_1:
;
goto tokenize_done
tokenize_done:
;
if rc == int32(SQLITE_DONE) {
rc = SQLITE_OK
}
return rc
}
/**************************************************************************
** Start of porter stemmer implementation.
*/
/* Any tokens larger than this (in bytes) are passed through without
** stemming. */
// C documentation
//
// /*
// ** This function is the implementation of the xUpdate callback used by
// ** FTS3 virtual tables. It is invoked by SQLite each time a row is to be
// ** inserted, updated or deleted.
// **
// ** A delete specifies a single argument - the rowid of the row to remove.
// **
// ** Update and insert operations pass:
// **
// ** 1. The "old" rowid, or NULL.
// ** 2. The "new" rowid.
// ** 3. Values for each of the nCol matchable columns.
// ** 4. Values for the two hidden columns ( and "rank").
// */
func _fts5UpdateMethod(tls *libc.TLS, pVtab uintptr, nArg int32, apVal uintptr, pRowid uintptr) (r int32) {
bp := tls.Alloc(32)
defer tls.Free(32)
var eConflict, eType0, eType1, ii int32
var iDel, iNew, iNew1, iOld Ti64
var pConfig, pStorage, pTab, pVal, z uintptr
var _ /* bContent at bp+4 */ int32
var _ /* rc at bp+0 */ int32
_, _, _, _, _, _, _, _, _, _, _, _, _ = eConflict, eType0, eType1, iDel, iNew, iNew1, iOld, ii, pConfig, pStorage, pTab, pVal, z
pTab = pVtab
pConfig = (*TFts5FullTable)(unsafe.Pointer(pTab)).Fp.FpConfig /* value_type() of apVal[0] */
**(**int32)(__ccgo_up(bp)) = SQLITE_OK /* Return code */
/* A transaction must be open when this is called. */
if (*TFts5Config)(unsafe.Pointer(pConfig)).Fpgsz == 0 {
**(**int32)(__ccgo_up(bp)) = _sqlite3Fts5ConfigLoad(tls, (*TFts5FullTable)(unsafe.Pointer(pTab)).Fp.FpConfig, (*TFts5Config)(unsafe.Pointer((*TFts5FullTable)(unsafe.Pointer(pTab)).Fp.FpConfig)).FiCookie)
if **(**int32)(__ccgo_up(bp)) != SQLITE_OK {
return **(**int32)(__ccgo_up(bp))
}
}
(*TFts5Config)(unsafe.Pointer((*TFts5FullTable)(unsafe.Pointer(pTab)).Fp.FpConfig)).FpzErrmsg = pTab + 16
/* Put any active cursors into REQUIRE_SEEK state. */
_fts5TripCursors(tls, pTab)
eType0 = Xsqlite3_value_type(tls, **(**uintptr)(__ccgo_up(apVal)))
if eType0 == int32(SQLITE_NULL) && Xsqlite3_value_type(tls, **(**uintptr)(__ccgo_up(apVal + uintptr(int32(2)+(*TFts5Config)(unsafe.Pointer(pConfig)).FnCol)*8))) != int32(SQLITE_NULL) {
/* A "special" INSERT op. These are handled separately. */
z = Xsqlite3_value_text(tls, **(**uintptr)(__ccgo_up(apVal + uintptr(int32(2)+(*TFts5Config)(unsafe.Pointer(pConfig)).FnCol)*8)))
if (*TFts5Config)(unsafe.Pointer(pConfig)).FeContent != FTS5_CONTENT_NORMAL && 0 == Xsqlite3_stricmp(tls, __ccgo_ts+19517, z) {
if (*TFts5Config)(unsafe.Pointer(pConfig)).FbContentlessDelete != 0 {
_fts5SetVtabError(tls, pTab, __ccgo_ts+40674, 0)
**(**int32)(__ccgo_up(bp)) = int32(SQLITE_ERROR)
} else {
**(**int32)(__ccgo_up(bp)) = _fts5SpecialDelete(tls, pTab, apVal)
}
} else {
**(**int32)(__ccgo_up(bp)) = _fts5SpecialInsert(tls, pTab, z, **(**uintptr)(__ccgo_up(apVal + uintptr(int32(2)+(*TFts5Config)(unsafe.Pointer(pConfig)).FnCol+int32(1))*8)))
}
} else {
/* A regular INSERT, UPDATE or DELETE statement. The trick here is that
** any conflict on the rowid value must be detected before any
** modifications are made to the database file. There are 4 cases:
**
** 1) DELETE
** 2) UPDATE (rowid not modified)
** 3) UPDATE (rowid modified)
** 4) INSERT
**
** Cases 3 and 4 may violate the rowid constraint.
*/
eConflict = int32(SQLITE_ABORT)
if (*TFts5Config)(unsafe.Pointer(pConfig)).FeContent == FTS5_CONTENT_NORMAL || (*TFts5Config)(unsafe.Pointer(pConfig)).FbContentlessDelete != 0 {
eConflict = Xsqlite3_vtab_on_conflict(tls, (*TFts5Config)(unsafe.Pointer(pConfig)).Fdb)
}
/* DELETE */
if nArg == int32(1) {
/* It is only possible to DELETE from a contentless table if the
** contentless_delete=1 flag is set. */
if _fts5IsContentless(tls, pTab, int32(1)) != 0 && (*TFts5Config)(unsafe.Pointer(pConfig)).FbContentlessDelete == 0 {
_fts5SetVtabError(tls, pTab, __ccgo_ts+40733, libc.VaList(bp+16, (*TFts5Config)(unsafe.Pointer(pConfig)).FzName))
**(**int32)(__ccgo_up(bp)) = int32(SQLITE_ERROR)
} else {
iDel = Xsqlite3_value_int64(tls, **(**uintptr)(__ccgo_up(apVal))) /* Rowid to delete */
**(**int32)(__ccgo_up(bp)) = _sqlite3Fts5StorageDelete(tls, (*TFts5FullTable)(unsafe.Pointer(pTab)).FpStorage, iDel, uintptr(0), 0)
}
} else {
eType1 = Xsqlite3_value_numeric_type(tls, **(**uintptr)(__ccgo_up(apVal + 1*8)))
/* It is an error to write an fts5_locale() value to a table without
** the locale=1 option. */
if (*TFts5Config)(unsafe.Pointer(pConfig)).FbLocale == 0 {
ii = 0
for {
if !(ii < (*TFts5Config)(unsafe.Pointer(pConfig)).FnCol) {
break
}
pVal = **(**uintptr)(__ccgo_up(apVal + uintptr(ii+int32(2))*8))
if _sqlite3Fts5IsLocaleValue(tls, pConfig, pVal) != 0 {
_fts5SetVtabError(tls, pTab, __ccgo_ts+40779, 0)
**(**int32)(__ccgo_up(bp)) = int32(SQLITE_MISMATCH)
goto update_out
}
goto _1
_1:
;
ii = ii + 1
}
}
if eType0 != int32(SQLITE_INTEGER) {
/* An INSERT statement. If the conflict-mode is REPLACE, first remove
** the current entry (if any). */
if eConflict == int32(SQLITE_REPLACE) && eType1 == int32(SQLITE_INTEGER) {
iNew = Xsqlite3_value_int64(tls, **(**uintptr)(__ccgo_up(apVal + 1*8))) /* Rowid to delete */
**(**int32)(__ccgo_up(bp)) = _sqlite3Fts5StorageDelete(tls, (*TFts5FullTable)(unsafe.Pointer(pTab)).FpStorage, iNew, uintptr(0), 0)
}
_fts5StorageInsert(tls, bp, pTab, apVal, pRowid)
} else {
pStorage = (*TFts5FullTable)(unsafe.Pointer(pTab)).FpStorage
iOld = Xsqlite3_value_int64(tls, **(**uintptr)(__ccgo_up(apVal))) /* Old rowid */
iNew1 = Xsqlite3_value_int64(tls, **(**uintptr)(__ccgo_up(apVal + 1*8))) /* New rowid */
**(**int32)(__ccgo_up(bp + 4)) = 0 /* Content only update */
/* If this is a contentless table (including contentless_unindexed=1
** tables), check if the UPDATE may proceed. */
if _fts5IsContentless(tls, pTab, int32(1)) != 0 {
**(**int32)(__ccgo_up(bp)) = _fts5ContentlessUpdate(tls, pConfig, apVal+2*8, libc.BoolInt32(iOld != iNew1), bp+4)
if **(**int32)(__ccgo_up(bp)) != SQLITE_OK {
goto update_out
}
}
if eType1 != int32(SQLITE_INTEGER) {
**(**int32)(__ccgo_up(bp)) = int32(SQLITE_MISMATCH)
} else {
if iOld != iNew1 {
if eConflict == int32(SQLITE_REPLACE) {
**(**int32)(__ccgo_up(bp)) = _sqlite3Fts5StorageDelete(tls, pStorage, iOld, uintptr(0), int32(1))
if **(**int32)(__ccgo_up(bp)) == SQLITE_OK {
**(**int32)(__ccgo_up(bp)) = _sqlite3Fts5StorageDelete(tls, pStorage, iNew1, uintptr(0), 0)
}
_fts5StorageInsert(tls, bp, pTab, apVal, pRowid)
} else {
**(**int32)(__ccgo_up(bp)) = _sqlite3Fts5StorageFindDeleteRow(tls, pStorage, iOld)
if **(**int32)(__ccgo_up(bp)) == SQLITE_OK {
**(**int32)(__ccgo_up(bp)) = _sqlite3Fts5StorageContentInsert(tls, pStorage, 0, apVal, pRowid)
}
if **(**int32)(__ccgo_up(bp)) == SQLITE_OK {
**(**int32)(__ccgo_up(bp)) = _sqlite3Fts5StorageDelete(tls, pStorage, iOld, uintptr(0), 0)
}
if **(**int32)(__ccgo_up(bp)) == SQLITE_OK {
**(**int32)(__ccgo_up(bp)) = _sqlite3Fts5StorageIndexInsert(tls, pStorage, apVal, **(**Tsqlite_int64)(__ccgo_up(pRowid)))
}
}
} else {
if **(**int32)(__ccgo_up(bp + 4)) != 0 {
/* This occurs when an UPDATE on a contentless table affects *only*
** UNINDEXED columns. This is a no-op for contentless_unindexed=0
** tables, or a write to the %_content table only for =1 tables. */
**(**int32)(__ccgo_up(bp)) = _sqlite3Fts5StorageFindDeleteRow(tls, pStorage, iOld)
if **(**int32)(__ccgo_up(bp)) == SQLITE_OK {
**(**int32)(__ccgo_up(bp)) = _sqlite3Fts5StorageContentInsert(tls, pStorage, int32(1), apVal, pRowid)
}
} else {
**(**int32)(__ccgo_up(bp)) = _sqlite3Fts5StorageDelete(tls, pStorage, iOld, uintptr(0), int32(1))
_fts5StorageInsert(tls, bp, pTab, apVal, pRowid)
}
}
}
_sqlite3Fts5StorageReleaseDeleteRow(tls, pStorage)
}
}
}
goto update_out
update_out:
;
_sqlite3Fts5IndexCloseReader(tls, (*TFts5FullTable)(unsafe.Pointer(pTab)).Fp.FpIndex)
(*TFts5Config)(unsafe.Pointer((*TFts5FullTable)(unsafe.Pointer(pTab)).Fp.FpConfig)).FpzErrmsg = uintptr(0)
return **(**int32)(__ccgo_up(bp))
}
// C documentation
//
// /*
// ** This is the xFilter implementation for the virtual table.
// */
func _fts5VocabFilterMethod(tls *libc.TLS, pCursor uintptr, idxNum int32, zUnused uintptr, nUnused int32, apVal uintptr) (r int32) {
var eType, f, iVal, nTerm, rc, v1 int32
var pCsr, pEq, pGe, pIndex, pLe, pTab, zCopy, zTerm uintptr
_, _, _, _, _, _, _, _, _, _, _, _, _, _ = eType, f, iVal, nTerm, pCsr, pEq, pGe, pIndex, pLe, pTab, rc, zCopy, zTerm, v1
pTab = (*Tsqlite3_vtab_cursor)(unsafe.Pointer(pCursor)).FpVtab
pCsr = pCursor
eType = (*TFts5VocabTable)(unsafe.Pointer(pTab)).FeType
rc = SQLITE_OK
iVal = 0
f = int32(FTS5INDEX_QUERY_SCAN)
zTerm = uintptr(0)
nTerm = 0
pEq = uintptr(0)
pGe = uintptr(0)
pLe = uintptr(0)
_ = zUnused
_ = nUnused
_fts5VocabResetCursor(tls, pCsr)
if idxNum&int32(FTS5_VOCAB_TERM_EQ) != 0 {
v1 = iVal
iVal = iVal + 1
pEq = **(**uintptr)(__ccgo_up(apVal + uintptr(v1)*8))
}
if idxNum&int32(FTS5_VOCAB_TERM_GE) != 0 {
v1 = iVal
iVal = iVal + 1
pGe = **(**uintptr)(__ccgo_up(apVal + uintptr(v1)*8))
}
if idxNum&int32(FTS5_VOCAB_TERM_LE) != 0 {
v1 = iVal
iVal = iVal + 1
pLe = **(**uintptr)(__ccgo_up(apVal + uintptr(v1)*8))
}
(*TFts5VocabCursor)(unsafe.Pointer(pCsr)).FcolUsed = idxNum & int32(FTS5_VOCAB_COLUSED_MASK)
if pEq != 0 {
zTerm = Xsqlite3_value_text(tls, pEq)
nTerm = Xsqlite3_value_bytes(tls, pEq)
f = int32(FTS5INDEX_QUERY_NOTOKENDATA)
} else {
if pGe != 0 {
zTerm = Xsqlite3_value_text(tls, pGe)
nTerm = Xsqlite3_value_bytes(tls, pGe)
}
if pLe != 0 {
zCopy = Xsqlite3_value_text(tls, pLe)
if zCopy == uintptr(0) {
zCopy = __ccgo_ts + 1702
}
(*TFts5VocabCursor)(unsafe.Pointer(pCsr)).FnLeTerm = Xsqlite3_value_bytes(tls, pLe)
(*TFts5VocabCursor)(unsafe.Pointer(pCsr)).FzLeTerm = Xsqlite3_malloc64(tls, libc.Uint64FromInt64(int64((*TFts5VocabCursor)(unsafe.Pointer(pCsr)).FnLeTerm)+int64(1)))
if (*TFts5VocabCursor)(unsafe.Pointer(pCsr)).FzLeTerm == uintptr(0) {
rc = int32(SQLITE_NOMEM)
} else {
libc.X__builtin___memcpy_chk(tls, (*TFts5VocabCursor)(unsafe.Pointer(pCsr)).FzLeTerm, zCopy, libc.Uint64FromInt32((*TFts5VocabCursor)(unsafe.Pointer(pCsr)).FnLeTerm+int32(1)), ^t__predefined_size_t(0))
}
}
}
if rc == SQLITE_OK {
pIndex = (*TFts5Table)(unsafe.Pointer((*TFts5VocabCursor)(unsafe.Pointer(pCsr)).FpFts5)).FpIndex
rc = _sqlite3Fts5IndexQuery(tls, pIndex, zTerm, nTerm, f, uintptr(0), pCsr+32)
if rc == SQLITE_OK {
(*TFts5VocabCursor)(unsafe.Pointer(pCsr)).FpStruct = _sqlite3Fts5StructureRef(tls, pIndex)
}
}
if rc == SQLITE_OK && eType == int32(FTS5_VOCAB_INSTANCE) {
rc = _fts5VocabInstanceNewTerm(tls, pCsr)
}
if rc == SQLITE_OK && !((*TFts5VocabCursor)(unsafe.Pointer(pCsr)).FbEof != 0) && (eType != int32(FTS5_VOCAB_INSTANCE) || (*TFts5Config)(unsafe.Pointer((*TFts5Table)(unsafe.Pointer((*TFts5VocabCursor)(unsafe.Pointer(pCsr)).FpFts5)).FpConfig)).FeDetail != int32(FTS5_DETAIL_NONE)) {
rc = _fts5VocabNextMethod(tls, pCursor)
}
return rc
}
// C documentation
//
// /*
// ** This function is the implementation of both the xConnect and xCreate
// ** methods of the FTS3 virtual table.
// **
// ** The argv[] array contains the following:
// **
// ** argv[0] -> module name ("fts5vocab")
// ** argv[1] -> database name
// ** argv[2] -> table name
// **
// ** then:
// **
// ** argv[3] -> name of fts5 table
// ** argv[4] -> type of fts5vocab table
// **
// ** or, for tables in the TEMP schema only.
// **
// ** argv[3] -> name of fts5 tables database
// ** argv[4] -> name of fts5 table
// ** argv[5] -> type of fts5vocab table
// */
func _fts5VocabInitVtab(tls *libc.TLS, db uintptr, pAux uintptr, argc int32, argv uintptr, ppVTab uintptr, pzErr uintptr) (r int32) {
bp := tls.Alloc(16)
defer tls.Free(16)
var azSchema [3]uintptr
var bDb int32
var nByte, nDb, nTab Ti64
var pRet, zDb, zTab, zType, v1, v2, v3 uintptr
var _ /* eType at bp+4 */ int32
var _ /* rc at bp+0 */ int32
_, _, _, _, _, _, _, _, _, _, _, _ = azSchema, bDb, nByte, nDb, nTab, pRet, zDb, zTab, zType, v1, v2, v3
azSchema = [3]uintptr{
0: __ccgo_ts + 42659,
1: __ccgo_ts + 42699,
2: __ccgo_ts + 42734,
}
pRet = uintptr(0)
**(**int32)(__ccgo_up(bp)) = SQLITE_OK
bDb = libc.BoolInt32(argc == int32(6) && libc.Xstrlen(tls, **(**uintptr)(__ccgo_up(argv + 1*8))) == uint64(4) && libc.Xmemcmp(tls, __ccgo_ts+25655, **(**uintptr)(__ccgo_up(argv + 1*8)), uint64(4)) == 0)
if argc != int32(5) && bDb == 0 {
**(**uintptr)(__ccgo_up(pzErr)) = Xsqlite3_mprintf(tls, __ccgo_ts+42777, 0)
**(**int32)(__ccgo_up(bp)) = int32(SQLITE_ERROR)
} else {
if bDb != 0 {
v1 = **(**uintptr)(__ccgo_up(argv + 3*8))
} else {
v1 = **(**uintptr)(__ccgo_up(argv + 1*8))
} /* Bytes of space to allocate */
zDb = v1
if bDb != 0 {
v2 = **(**uintptr)(__ccgo_up(argv + 4*8))
} else {
v2 = **(**uintptr)(__ccgo_up(argv + 3*8))
}
zTab = v2
if bDb != 0 {
v3 = **(**uintptr)(__ccgo_up(argv + 5*8))
} else {
v3 = **(**uintptr)(__ccgo_up(argv + 4*8))
}
zType = v3
nDb = libc.Int64FromUint64(libc.Xstrlen(tls, zDb) + uint64(1))
nTab = libc.Int64FromUint64(libc.Xstrlen(tls, zTab) + uint64(1))
**(**int32)(__ccgo_up(bp + 4)) = 0
**(**int32)(__ccgo_up(bp)) = _fts5VocabTableType(tls, zType, pzErr, bp+4)
if **(**int32)(__ccgo_up(bp)) == SQLITE_OK {
**(**int32)(__ccgo_up(bp)) = Xsqlite3_declare_vtab(tls, db, azSchema[**(**int32)(__ccgo_up(bp + 4))])
}
nByte = libc.Int64FromUint64(uint64(64) + libc.Uint64FromInt64(nDb) + libc.Uint64FromInt64(nTab))
pRet = _sqlite3Fts5MallocZero(tls, bp, nByte)
if pRet != 0 {
(*TFts5VocabTable)(unsafe.Pointer(pRet)).FpGlobal = pAux
(*TFts5VocabTable)(unsafe.Pointer(pRet)).FeType = **(**int32)(__ccgo_up(bp + 4))
(*TFts5VocabTable)(unsafe.Pointer(pRet)).Fdb = db
(*TFts5VocabTable)(unsafe.Pointer(pRet)).FzFts5Tbl = pRet + 1*64
(*TFts5VocabTable)(unsafe.Pointer(pRet)).FzFts5Db = (*TFts5VocabTable)(unsafe.Pointer(pRet)).FzFts5Tbl + uintptr(nTab)
libc.X__builtin___memcpy_chk(tls, (*TFts5VocabTable)(unsafe.Pointer(pRet)).FzFts5Tbl, zTab, libc.Uint64FromInt64(nTab), ^t__predefined_size_t(0))
libc.X__builtin___memcpy_chk(tls, (*TFts5VocabTable)(unsafe.Pointer(pRet)).FzFts5Db, zDb, libc.Uint64FromInt64(nDb), ^t__predefined_size_t(0))
_sqlite3Fts5Dequote(tls, (*TFts5VocabTable)(unsafe.Pointer(pRet)).FzFts5Tbl)
_sqlite3Fts5Dequote(tls, (*TFts5VocabTable)(unsafe.Pointer(pRet)).FzFts5Db)
}
}
**(**uintptr)(__ccgo_up(ppVTab)) = pRet
return **(**int32)(__ccgo_up(bp))
}
// C documentation
//
// /*
// ** Advance the cursor to the next row in the table.
// */
func _fts5VocabNextMethod(tls *libc.TLS, pCursor uintptr) (r int32) {
bp := tls.Alloc(32)
defer tls.Free(32)
var bCmp, eDetail, iCol, ii1, nCmp, nCol, nPos, v2 int32
var pCsr, pPos, pTab, zTerm uintptr
var v3 Ti64
var _ /* iOff at bp+16 */ int32
var _ /* iPos at bp+8 */ Ti64
var _ /* ii at bp+20 */ Tu32
var _ /* nTerm at bp+4 */ int32
var _ /* rc at bp+0 */ int32
_, _, _, _, _, _, _, _, _, _, _, _, _ = bCmp, eDetail, iCol, ii1, nCmp, nCol, nPos, pCsr, pPos, pTab, zTerm, v2, v3
pCsr = pCursor
pTab = (*Tsqlite3_vtab_cursor)(unsafe.Pointer(pCursor)).FpVtab
nCol = (*TFts5Config)(unsafe.Pointer((*TFts5Table)(unsafe.Pointer((*TFts5VocabCursor)(unsafe.Pointer(pCsr)).FpFts5)).FpConfig)).FnCol
**(**int32)(__ccgo_up(bp)) = _sqlite3Fts5StructureTest(tls, (*TFts5Table)(unsafe.Pointer((*TFts5VocabCursor)(unsafe.Pointer(pCsr)).FpFts5)).FpIndex, (*TFts5VocabCursor)(unsafe.Pointer(pCsr)).FpStruct)
if **(**int32)(__ccgo_up(bp)) != SQLITE_OK {
return **(**int32)(__ccgo_up(bp))
}
(*TFts5VocabCursor)(unsafe.Pointer(pCsr)).Frowid = (*TFts5VocabCursor)(unsafe.Pointer(pCsr)).Frowid + 1
if (*TFts5VocabTable)(unsafe.Pointer(pTab)).FeType == int32(FTS5_VOCAB_INSTANCE) {
return _fts5VocabInstanceNext(tls, pCsr)
}
if (*TFts5VocabTable)(unsafe.Pointer(pTab)).FeType == FTS5_VOCAB_COL {
(*TFts5VocabCursor)(unsafe.Pointer(pCsr)).FiCol = (*TFts5VocabCursor)(unsafe.Pointer(pCsr)).FiCol + 1
for {
if !((*TFts5VocabCursor)(unsafe.Pointer(pCsr)).FiCol < nCol) {
break
}
if **(**Ti64)(__ccgo_up((*TFts5VocabCursor)(unsafe.Pointer(pCsr)).FaDoc + uintptr((*TFts5VocabCursor)(unsafe.Pointer(pCsr)).FiCol)*8)) != 0 {
break
}
goto _1
_1:
;
(*TFts5VocabCursor)(unsafe.Pointer(pCsr)).FiCol = (*TFts5VocabCursor)(unsafe.Pointer(pCsr)).FiCol + 1
}
}
if (*TFts5VocabTable)(unsafe.Pointer(pTab)).FeType != FTS5_VOCAB_COL || (*TFts5VocabCursor)(unsafe.Pointer(pCsr)).FiCol >= nCol {
if (*TFts5IndexIter)(unsafe.Pointer((*TFts5VocabCursor)(unsafe.Pointer(pCsr)).FpIter)).FbEof != 0 {
(*TFts5VocabCursor)(unsafe.Pointer(pCsr)).FbEof = int32(1)
} else {
zTerm = _sqlite3Fts5IterTerm(tls, (*TFts5VocabCursor)(unsafe.Pointer(pCsr)).FpIter, bp+4)
if (*TFts5VocabCursor)(unsafe.Pointer(pCsr)).FnLeTerm >= 0 {
if **(**int32)(__ccgo_up(bp + 4)) < (*TFts5VocabCursor)(unsafe.Pointer(pCsr)).FnLeTerm {
v2 = **(**int32)(__ccgo_up(bp + 4))
} else {
v2 = (*TFts5VocabCursor)(unsafe.Pointer(pCsr)).FnLeTerm
}
nCmp = v2
bCmp = libc.Xmemcmp(tls, (*TFts5VocabCursor)(unsafe.Pointer(pCsr)).FzLeTerm, zTerm, libc.Uint64FromInt32(nCmp))
if bCmp < 0 || bCmp == 0 && (*TFts5VocabCursor)(unsafe.Pointer(pCsr)).FnLeTerm < **(**int32)(__ccgo_up(bp + 4)) {
(*TFts5VocabCursor)(unsafe.Pointer(pCsr)).FbEof = int32(1)
return SQLITE_OK
}
}
_sqlite3Fts5BufferSet(tls, bp, pCsr+96, **(**int32)(__ccgo_up(bp + 4)), zTerm)
libc.X__builtin___memset_chk(tls, (*TFts5VocabCursor)(unsafe.Pointer(pCsr)).FaCnt, 0, libc.Uint64FromInt32(nCol)*uint64(8), ^t__predefined_size_t(0))
libc.X__builtin___memset_chk(tls, (*TFts5VocabCursor)(unsafe.Pointer(pCsr)).FaDoc, 0, libc.Uint64FromInt32(nCol)*uint64(8), ^t__predefined_size_t(0))
(*TFts5VocabCursor)(unsafe.Pointer(pCsr)).FiCol = 0
for **(**int32)(__ccgo_up(bp)) == SQLITE_OK {
eDetail = (*TFts5Config)(unsafe.Pointer((*TFts5Table)(unsafe.Pointer((*TFts5VocabCursor)(unsafe.Pointer(pCsr)).FpFts5)).FpConfig)).FeDetail /* Position list */
**(**Ti64)(__ccgo_up(bp + 8)) = 0 /* 64-bit position read from poslist */
**(**int32)(__ccgo_up(bp + 16)) = 0 /* Current offset within position list */
pPos = (*TFts5IndexIter)(unsafe.Pointer((*TFts5VocabCursor)(unsafe.Pointer(pCsr)).FpIter)).FpData
nPos = (*TFts5IndexIter)(unsafe.Pointer((*TFts5VocabCursor)(unsafe.Pointer(pCsr)).FpIter)).FnData
switch (*TFts5VocabTable)(unsafe.Pointer(pTab)).FeType {
case int32(FTS5_VOCAB_ROW):
/* Do not bother counting the number of instances if the "cnt"
** column is not being read (according to colUsed). */
if eDetail == FTS5_DETAIL_FULL && (*TFts5VocabCursor)(unsafe.Pointer(pCsr)).FcolUsed&int32(0x04) != 0 {
for **(**Ti64)(__ccgo_up(bp + 8)) < int64(nPos) {
v3 = **(**Ti64)(__ccgo_up(bp + 8))
**(**Ti64)(__ccgo_up(bp + 8)) = **(**Ti64)(__ccgo_up(bp + 8)) + 1
**(**Tu32)(__ccgo_up(bp + 20)) = uint32(**(**Tu8)(__ccgo_up(pPos + uintptr(v3))))
if **(**Tu32)(__ccgo_up(bp + 20))&uint32(0x80) != 0 {
**(**Ti64)(__ccgo_up(bp + 8)) = **(**Ti64)(__ccgo_up(bp + 8)) - 1
**(**Ti64)(__ccgo_up(bp + 8)) = **(**Ti64)(__ccgo_up(bp + 8)) + int64(_sqlite3Fts5GetVarint32(tls, pPos+uintptr(**(**Ti64)(__ccgo_up(bp + 8))), bp+20))
}
if **(**Tu32)(__ccgo_up(bp + 20)) == uint32(1) {
/* New column in the position list */
v3 = **(**Ti64)(__ccgo_up(bp + 8))
**(**Ti64)(__ccgo_up(bp + 8)) = **(**Ti64)(__ccgo_up(bp + 8)) + 1
**(**Tu32)(__ccgo_up(bp + 20)) = uint32(**(**Tu8)(__ccgo_up(pPos + uintptr(v3))))
if **(**Tu32)(__ccgo_up(bp + 20))&uint32(0x80) != 0 {
**(**Ti64)(__ccgo_up(bp + 8)) = **(**Ti64)(__ccgo_up(bp + 8)) - 1
**(**Ti64)(__ccgo_up(bp + 8)) = **(**Ti64)(__ccgo_up(bp + 8)) + int64(_sqlite3Fts5GetVarint32(tls, pPos+uintptr(**(**Ti64)(__ccgo_up(bp + 8))), bp+20))
}
} else {
/* An instance - increment pCsr->aCnt[] */
**(**Ti64)(__ccgo_up((*TFts5VocabCursor)(unsafe.Pointer(pCsr)).FaCnt)) = **(**Ti64)(__ccgo_up((*TFts5VocabCursor)(unsafe.Pointer(pCsr)).FaCnt)) + 1
}
}
}
**(**Ti64)(__ccgo_up((*TFts5VocabCursor)(unsafe.Pointer(pCsr)).FaDoc)) = **(**Ti64)(__ccgo_up((*TFts5VocabCursor)(unsafe.Pointer(pCsr)).FaDoc)) + 1
case FTS5_VOCAB_COL:
if eDetail == FTS5_DETAIL_FULL {
iCol = -int32(1)
for 0 == _sqlite3Fts5PoslistNext64(tls, pPos, nPos, bp+16, bp+8) {
ii1 = int32(**(**Ti64)(__ccgo_up(bp + 8)) >> libc.Int32FromInt32(32) & libc.Int64FromInt32(0x7FFFFFFF))
if iCol != ii1 {
if ii1 >= nCol {
**(**int32)(__ccgo_up(bp)) = libc.Int32FromInt32(SQLITE_CORRUPT) | libc.Int32FromInt32(1)<= int64(nCol) {
**(**int32)(__ccgo_up(bp)) = libc.Int32FromInt32(SQLITE_CORRUPT) | libc.Int32FromInt32(1)< 0 && libc.Xmemcmp(tls, zTerm, (*TFts5VocabCursor)(unsafe.Pointer(pCsr)).Fterm.Fp, libc.Uint64FromInt32(**(**int32)(__ccgo_up(bp + 4)))) != 0 {
break
}
if (*TFts5IndexIter)(unsafe.Pointer((*TFts5VocabCursor)(unsafe.Pointer(pCsr)).FpIter)).FbEof != 0 {
break
}
}
}
}
}
if **(**int32)(__ccgo_up(bp)) == SQLITE_OK && (*TFts5VocabCursor)(unsafe.Pointer(pCsr)).FbEof == 0 && (*TFts5VocabTable)(unsafe.Pointer(pTab)).FeType == FTS5_VOCAB_COL {
for {
if !((*TFts5VocabCursor)(unsafe.Pointer(pCsr)).FiCol < nCol && **(**Ti64)(__ccgo_up((*TFts5VocabCursor)(unsafe.Pointer(pCsr)).FaDoc + uintptr((*TFts5VocabCursor)(unsafe.Pointer(pCsr)).FiCol)*8)) == 0) {
break
}
goto _5
_5:
;
(*TFts5VocabCursor)(unsafe.Pointer(pCsr)).FiCol = (*TFts5VocabCursor)(unsafe.Pointer(pCsr)).FiCol + 1
}
if (*TFts5VocabCursor)(unsafe.Pointer(pCsr)).FiCol == nCol {
**(**int32)(__ccgo_up(bp)) = libc.Int32FromInt32(SQLITE_CORRUPT) | libc.Int32FromInt32(1)<aDlidx[] array to at least nLvl elements in size.
// ** Any new array elements are zeroed before returning.
// */
func _fts5WriteDlidxGrow(tls *libc.TLS, p uintptr, pWriter uintptr, nLvl int32) (r int32) {
var aDlidx uintptr
var nByte Tsize_t
_, _ = aDlidx, nByte
if (*TFts5Index)(unsafe.Pointer(p)).Frc == SQLITE_OK && nLvl >= (*TFts5SegWriter)(unsafe.Pointer(pWriter)).FnDlidx {
aDlidx = Xsqlite3_realloc64(tls, (*TFts5SegWriter)(unsafe.Pointer(pWriter)).FaDlidx, uint64(uint64(32)*libc.Uint64FromInt32(nLvl)))
if aDlidx == uintptr(0) {
(*TFts5Index)(unsafe.Pointer(p)).Frc = int32(SQLITE_NOMEM)
} else {
nByte = uint64(32) * libc.Uint64FromInt32(nLvl-(*TFts5SegWriter)(unsafe.Pointer(pWriter)).FnDlidx)
libc.X__builtin___memset_chk(tls, aDlidx+uintptr((*TFts5SegWriter)(unsafe.Pointer(pWriter)).FnDlidx)*32, 0, nByte, ^t__predefined_size_t(0))
(*TFts5SegWriter)(unsafe.Pointer(pWriter)).FaDlidx = aDlidx
(*TFts5SegWriter)(unsafe.Pointer(pWriter)).FnDlidx = nLvl
}
}
return (*TFts5Index)(unsafe.Pointer(p)).Frc
}
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.X__builtin___memset_chk(tls, pWriter, 0, uint64(120), ^t__predefined_size_t(0))
(*TFts5SegWriter)(unsafe.Pointer(pWriter)).FiSegid = iSegid
_fts5WriteDlidxGrow(tls, p, pWriter, int32(1))
(*TFts5SegWriter)(unsafe.Pointer(pWriter)).Fwriter.Fpgno = int32(1)
(*TFts5SegWriter)(unsafe.Pointer(pWriter)).FbFirstTermInPage = uint8(1)
(*TFts5SegWriter)(unsafe.Pointer(pWriter)).FiBtPage = int32(1)
/* Grow the two buffers to pgsz + padding bytes in size. */
_sqlite3Fts5BufferSize(tls, p+60, pWriter+8+24, libc.Uint32FromInt32(nBuffer))
_sqlite3Fts5BufferSize(tls, p+60, pWriter+8+8, libc.Uint32FromInt32(nBuffer))
if (*TFts5Index)(unsafe.Pointer(p)).FpIdxWriter == uintptr(0) {
pConfig = (*TFts5Index)(unsafe.Pointer(p)).FpConfig
_fts5IndexPrepareStmt(tls, p, p+96, Xsqlite3_mprintf(tls, __ccgo_ts+39717, 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.X__builtin___memset_chk(tls, (*TFts5SegWriter)(unsafe.Pointer(pWriter)).Fwriter.Fbuf.Fp, 0, uint64(4), ^t__predefined_size_t(0))
(*TFts5SegWriter)(unsafe.Pointer(pWriter)).Fwriter.Fbuf.Fn = int32(4)
/* Bind the current output segment id to the index-writer. This is an
** optimization over binding the same value over and over as rows are
** inserted into %_idx by the current writer. */
Xsqlite3_bind_int(tls, (*TFts5Index)(unsafe.Pointer(p)).FpIdxWriter, int32(1), (*TFts5SegWriter)(unsafe.Pointer(pWriter)).FiSegid)
}
}
// C documentation
//
// /*
// ** The following routine is called if the stack overflows.
// */
func _fts5yyStackOverflow(tls *libc.TLS, fts5yypParser uintptr) {
var pParse uintptr
_ = pParse
pParse = (*Tfts5yyParser)(unsafe.Pointer(fts5yypParser)).FpParse
for (*Tfts5yyParser)(unsafe.Pointer(fts5yypParser)).Ffts5yytos > (*Tfts5yyParser)(unsafe.Pointer(fts5yypParser)).Ffts5yystack {
_fts5yy_pop_parser_stack(tls, fts5yypParser)
}
/* Here code is inserted which will execute if the parser
** stack every overflows */
/******** Begin %stack_overflow code ******************************************/
_sqlite3Fts5ParseError(tls, pParse, __ccgo_ts+37479, 0)
/******** End %stack_overflow code ********************************************/
(*Tfts5yyParser)(unsafe.Pointer(fts5yypParser)).FpParse = pParse /* Suppress warning about unused %extra_argument var */
}
/*
** Print tracing information for a SHIFT action
*/
// C documentation
//
// /*
// ** The following code executes when a syntax error first occurs.
// */
func _fts5yy_syntax_error(tls *libc.TLS, fts5yypParser uintptr, fts5yymajor int32, fts5yyminor TFts5Token) {
bp := tls.Alloc(32)
defer tls.Free(32)
var pParse uintptr
_ = pParse
pParse = (*Tfts5yyParser)(unsafe.Pointer(fts5yypParser)).FpParse
/************ Begin %syntax_error code ****************************************/
_ = fts5yymajor /* Silence a compiler warning */
_sqlite3Fts5ParseError(tls, pParse, __ccgo_ts+37507, libc.VaList(bp+8, fts5yyminor.Fn, fts5yyminor.Fp))
/************ End %syntax_error code ******************************************/
(*Tfts5yyParser)(unsafe.Pointer(fts5yypParser)).FpParse = pParse /* Suppress warning about unused %extra_argument variable */
}
// C documentation
//
// /*
// ** The fsync() system call does not work as advertised on many
// ** unix systems. The following procedure is an attempt to make
// ** it work better.
// **
// ** The SQLITE_NO_SYNC macro disables all fsync()s. This is useful
// ** for testing when we want to run through the test suite quickly.
// ** You are strongly advised *not* to deploy with SQLITE_NO_SYNC
// ** enabled, however, since with SQLITE_NO_SYNC enabled, an OS crash
// ** or power failure will likely corrupt the database file.
// **
// ** SQLite sets the dataOnly flag if the size of the file is unchanged.
// ** The idea behind dataOnly is that it should only write the file content
// ** to disk, not the inode. We only set dataOnly if the file size is
// ** unchanged since the file size is part of the inode. However,
// ** Ted Ts'o tells us that fdatasync() will also write the inode if the
// ** file size has changed. The only real difference between fdatasync()
// ** and fsync(), Ted tells us, is that fdatasync() will not flush the
// ** inode if the mtime or owner or other inode attributes have changed.
// ** We only care about the file size, not the other file attributes, so
// ** as far as SQLite is concerned, an fdatasync() is always adequate.
// ** So, we always use fdatasync() if it is available, regardless of
// ** the value of the dataOnly flag.
// */
func _full_fsync(tls *libc.TLS, fd int32, fullSync int32, dataOnly int32) (r int32) {
bp := tls.Alloc(16)
defer tls.Free(16)
var rc int32
_ = rc
/* The following "ifdef/elif/else/" block has the same structure as
** the one below. It is replicated here solely to avoid cluttering
** up the real code with the UNUSED_PARAMETER() macros.
*/
_ = dataOnly
/* Record the number of times that we do a normal fsync() and
** FULLSYNC. This is used during testing to verify that this procedure
** gets called with the correct arguments.
*/
/* If we compiled with the SQLITE_NO_SYNC flag, then syncing is a
** no-op. But go ahead and call fstat() to validate the file
** descriptor as we need a method to provoke a failure during
** coverage testing.
*/
if fullSync != 0 {
rc = (*(*func(*libc.TLS, int32, int32, uintptr) int32)(unsafe.Pointer(&struct{ uintptr }{_aSyscall[int32(7)].FpCurrent})))(tls, fd, int32(F_FULLFSYNC), libc.VaList(bp+8, 0))
} else {
rc = int32(1)
}
/* If the FULLFSYNC failed, fall back to attempting an fsync().
** It shouldn't be possible for fullfsync to fail on the local
** file system (on OSX), so failure indicates that FULLFSYNC
** isn't supported for this file system. So, attempt an fsync
** and (for now) ignore the overhead of a superfluous fcntl call.
** It'd be better to detect fullfsync support once and avoid
** the fcntl call every time sync is called.
*/
if rc != 0 {
rc = libc.Xfsync(tls, fd)
}
if libc.Bool(OS_VXWORKS != 0) && rc != -int32(1) {
rc = 0
}
return rc
}
// C documentation
//
// /*
// ** Code an output subroutine for a coroutine implementation of a
// ** SELECT statement.
// **
// ** The data to be output is contained in an array of pIn->nSdst registers
// ** starting at register pIn->iSdst. pDest is where the output should
// ** be sent.
// **
// ** regReturn is the number of the register holding the subroutine
// ** return address.
// **
// ** If regPrev>0 then it is the first register in a vector that
// ** records the previous output. mem[regPrev] is a flag that is false
// ** if there has been no previous output. If regPrev>0 then code is
// ** generated to suppress duplicates. pKeyInfo is used for comparing
// ** keys.
// **
// ** If the LIMIT found in p->iLimit is reached, jump immediately to
// ** iBreak.
// */
func _generateOutputSubroutine(tls *libc.TLS, pParse uintptr, p uintptr, pIn uintptr, pDest uintptr, regReturn int32, regPrev int32, pKeyInfo uintptr, iBreak int32) (r int32) {
var addr, addr1, addr2, iContinue, iParm, iParm1, ii, nKey, r1, r11, r12, r2, r21, r3 int32
var pSO, v uintptr
_, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _ = addr, addr1, addr2, iContinue, iParm, iParm1, ii, nKey, pSO, r1, r11, r12, r2, r21, r3, v
v = (*TParse)(unsafe.Pointer(pParse)).FpVdbe
addr = _sqlite3VdbeCurrentAddr(tls, v)
iContinue = _sqlite3VdbeMakeLabel(tls, pParse)
/* Suppress duplicates for UNION, EXCEPT, and INTERSECT
*/
if regPrev != 0 {
addr1 = _sqlite3VdbeAddOp1(tls, v, int32(OP_IfNot), regPrev)
addr2 = _sqlite3VdbeAddOp4(tls, v, int32(OP_Compare), (*TSelectDest)(unsafe.Pointer(pIn)).FiSdst, regPrev+int32(1), (*TSelectDest)(unsafe.Pointer(pIn)).FnSdst, _sqlite3KeyInfoRef(tls, pKeyInfo), -int32(9))
_sqlite3VdbeAddOp3(tls, v, int32(OP_Jump), addr2+int32(2), iContinue, addr2+int32(2))
_sqlite3VdbeJumpHere(tls, v, addr1)
_sqlite3VdbeAddOp3(tls, v, int32(OP_Copy), (*TSelectDest)(unsafe.Pointer(pIn)).FiSdst, regPrev+int32(1), (*TSelectDest)(unsafe.Pointer(pIn)).FnSdst-int32(1))
_sqlite3VdbeAddOp2(tls, v, int32(OP_Integer), int32(1), regPrev)
}
if (*Tsqlite3)(unsafe.Pointer((*TParse)(unsafe.Pointer(pParse)).Fdb)).FmallocFailed != 0 {
return 0
}
/* Suppress the first OFFSET entries if there is an OFFSET clause
*/
_codeOffset(tls, v, (*TSelect)(unsafe.Pointer(p)).FiOffset, iContinue)
switch libc.Int32FromUint8((*TSelectDest)(unsafe.Pointer(pDest)).FeDest) {
/* Store the result as data using a unique key.
*/
case int32(SRT_Fifo):
fallthrough
case int32(SRT_DistFifo):
fallthrough
case int32(SRT_Table):
fallthrough
case int32(SRT_EphemTab):
r1 = _sqlite3GetTempReg(tls, pParse)
r2 = _sqlite3GetTempReg(tls, pParse)
iParm = (*TSelectDest)(unsafe.Pointer(pDest)).FiSDParm
_sqlite3VdbeAddOp3(tls, v, int32(OP_MakeRecord), (*TSelectDest)(unsafe.Pointer(pIn)).FiSdst, (*TSelectDest)(unsafe.Pointer(pIn)).FnSdst, r1)
if libc.Int32FromUint8((*TSelectDest)(unsafe.Pointer(pDest)).FeDest) == int32(SRT_DistFifo) {
/* If the destination is DistFifo, then cursor (iParm+1) is open
** on an ephemeral index that is used to enforce uniqueness on the
** total result. At this point, we are processing the setup portion
** of the recursive CTE using the merge algorithm, so the results are
** guaranteed to be unique anyhow. But we still need to populate the
** (iParm+1) cursor for use by the subsequent recursive phase.
*/
_sqlite3VdbeAddOp4Int(tls, v, int32(OP_IdxInsert), iParm+int32(1), r1, (*TSelectDest)(unsafe.Pointer(pIn)).FiSdst, (*TSelectDest)(unsafe.Pointer(pIn)).FnSdst)
}
_sqlite3VdbeAddOp2(tls, v, int32(OP_NewRowid), iParm, r2)
_sqlite3VdbeAddOp3(tls, v, int32(OP_Insert), iParm, r1, r2)
_sqlite3VdbeChangeP5(tls, v, uint16(OPFLAG_APPEND))
_sqlite3ReleaseTempReg(tls, pParse, r2)
_sqlite3ReleaseTempReg(tls, pParse, r1)
break
/* If any row exist in the result set, record that fact and abort.
*/
fallthrough
case int32(SRT_Exists):
_sqlite3VdbeAddOp2(tls, v, int32(OP_Integer), int32(1), (*TSelectDest)(unsafe.Pointer(pDest)).FiSDParm)
/* The LIMIT clause will terminate the loop for us */
break
/* If we are creating a set for an "expr IN (SELECT ...)".
*/
fallthrough
case int32(SRT_Set):
r11 = _sqlite3GetTempReg(tls, pParse)
_sqlite3VdbeAddOp4(tls, v, int32(OP_MakeRecord), (*TSelectDest)(unsafe.Pointer(pIn)).FiSdst, (*TSelectDest)(unsafe.Pointer(pIn)).FnSdst, r11, (*TSelectDest)(unsafe.Pointer(pDest)).FzAffSdst, (*TSelectDest)(unsafe.Pointer(pIn)).FnSdst)
_sqlite3VdbeAddOp4Int(tls, v, int32(OP_IdxInsert), (*TSelectDest)(unsafe.Pointer(pDest)).FiSDParm, r11, (*TSelectDest)(unsafe.Pointer(pIn)).FiSdst, (*TSelectDest)(unsafe.Pointer(pIn)).FnSdst)
if (*TSelectDest)(unsafe.Pointer(pDest)).FiSDParm2 > 0 {
_sqlite3VdbeAddOp4Int(tls, v, int32(OP_FilterAdd), (*TSelectDest)(unsafe.Pointer(pDest)).FiSDParm2, 0, (*TSelectDest)(unsafe.Pointer(pIn)).FiSdst, (*TSelectDest)(unsafe.Pointer(pIn)).FnSdst)
_sqlite3VdbeExplain(tls, pParse, uint8(0), __ccgo_ts+20862, 0)
}
_sqlite3ReleaseTempReg(tls, pParse, r11)
break
/* If this is a scalar select that is part of an expression, then
** store the results in the appropriate memory cell and break out
** of the scan loop. Note that the select might return multiple columns
** if it is the RHS of a row-value IN operator.
*/
fallthrough
case int32(SRT_Mem):
_sqlite3ExprCodeMove(tls, pParse, (*TSelectDest)(unsafe.Pointer(pIn)).FiSdst, (*TSelectDest)(unsafe.Pointer(pDest)).FiSDParm, (*TSelectDest)(unsafe.Pointer(pIn)).FnSdst)
/* The LIMIT clause will jump out of the loop for us */
break
/* The results are stored in a sequence of registers
** starting at pDest->iSdst. Then the co-routine yields.
*/
fallthrough
case int32(SRT_Coroutine):
if (*TSelectDest)(unsafe.Pointer(pDest)).FiSdst == 0 {
(*TSelectDest)(unsafe.Pointer(pDest)).FiSdst = _sqlite3GetTempRange(tls, pParse, (*TSelectDest)(unsafe.Pointer(pIn)).FnSdst)
(*TSelectDest)(unsafe.Pointer(pDest)).FnSdst = (*TSelectDest)(unsafe.Pointer(pIn)).FnSdst
}
_sqlite3ExprCodeMove(tls, pParse, (*TSelectDest)(unsafe.Pointer(pIn)).FiSdst, (*TSelectDest)(unsafe.Pointer(pDest)).FiSdst, (*TSelectDest)(unsafe.Pointer(pIn)).FnSdst)
_sqlite3VdbeAddOp1(tls, v, int32(OP_Yield), (*TSelectDest)(unsafe.Pointer(pDest)).FiSDParm)
break
/* Write the results into a priority queue that is order according to
** pDest->pOrderBy (in pSO). pDest->iSDParm (in iParm) is the cursor for an
** index with pSO->nExpr+2 columns. Build a key using pSO for the first
** pSO->nExpr columns, then make sure all keys are unique by adding a
** final OP_Sequence column. The last column is the record as a blob.
*/
fallthrough
case int32(SRT_DistQueue):
fallthrough
case int32(SRT_Queue):
iParm1 = (*TSelectDest)(unsafe.Pointer(pDest)).FiSDParm
pSO = (*TSelectDest)(unsafe.Pointer(pDest)).FpOrderBy
nKey = (*TExprList)(unsafe.Pointer(pSO)).FnExpr
r12 = _sqlite3GetTempReg(tls, pParse)
r21 = _sqlite3GetTempRange(tls, pParse, nKey+int32(2))
r3 = r21 + nKey + int32(1)
_sqlite3VdbeAddOp3(tls, v, int32(OP_MakeRecord), (*TSelectDest)(unsafe.Pointer(pIn)).FiSdst, (*TSelectDest)(unsafe.Pointer(pIn)).FnSdst, r3)
if libc.Int32FromUint8((*TSelectDest)(unsafe.Pointer(pDest)).FeDest) == int32(SRT_DistQueue) {
_sqlite3VdbeAddOp2(tls, v, int32(OP_IdxInsert), iParm1+int32(1), r3)
}
ii = 0
for {
if !(ii < nKey) {
break
}
_sqlite3VdbeAddOp2(tls, v, int32(OP_SCopy), (*TSelectDest)(unsafe.Pointer(pIn)).FiSdst+libc.Int32FromUint16(*(*Tu16)(unsafe.Pointer(pSO + 8 + uintptr(ii)*32 + 24)))-int32(1), r21+ii)
goto _1
_1:
;
ii = ii + 1
}
_sqlite3VdbeAddOp2(tls, v, int32(OP_Sequence), iParm1, r21+nKey)
_sqlite3VdbeAddOp3(tls, v, int32(OP_MakeRecord), r21, nKey+int32(2), r12)
_sqlite3VdbeAddOp4Int(tls, v, int32(OP_IdxInsert), iParm1, r12, r21, nKey+int32(2))
_sqlite3ReleaseTempReg(tls, pParse, r12)
_sqlite3ReleaseTempRange(tls, pParse, r21, nKey+int32(2))
break
/* Ignore the output */
fallthrough
case int32(SRT_Discard):
break
/* If none of the above, then the result destination must be
** SRT_Output.
**
** For SRT_Output, results are stored in a sequence of registers.
** Then the OP_ResultRow opcode is used to cause sqlite3_step() to
** return the next row of result.
*/
fallthrough
default:
_sqlite3VdbeAddOp2(tls, v, int32(OP_ResultRow), (*TSelectDest)(unsafe.Pointer(pIn)).FiSdst, (*TSelectDest)(unsafe.Pointer(pIn)).FnSdst)
break
}
/* Jump to the end of the loop if the LIMIT is reached.
*/
if (*TSelect)(unsafe.Pointer(p)).FiLimit != 0 {
_sqlite3VdbeAddOp2(tls, v, int32(OP_DecrJumpZero), (*TSelect)(unsafe.Pointer(p)).FiLimit, iBreak)
}
/* Generate the subroutine return
*/
_sqlite3VdbeResolveLabel(tls, v, iContinue)
_sqlite3VdbeAddOp1(tls, v, int32(OP_Return), regReturn)
return addr
}
// C documentation
//
// /*
// ** If the inner loop was generated using a non-null pOrderBy argument,
// ** then the results were placed in a sorter. After the loop is terminated
// ** we need to run the sorter and output the results. The following
// ** routine generates the code needed to do that.
// */
func _generateSortTail(tls *libc.TLS, pParse uintptr, p uintptr, pSort uintptr, nColumn int32, pDest uintptr) {
bp := tls.Alloc(16)
defer tls.Free(16)
var aOutEx, pOrderBy, v, v1, v3 uintptr
var addr, addrBreak, addrContinue, addrOnce, bSeq, eDest, i, i2, iCol, iParm, iRead, iSortTab, iTab, nKey, nRefKey, r1, regRow, regRowid, regSortOut, v2, v4 int32
_, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _ = aOutEx, addr, addrBreak, addrContinue, addrOnce, bSeq, eDest, i, i2, iCol, iParm, iRead, iSortTab, iTab, nKey, nRefKey, pOrderBy, r1, regRow, regRowid, regSortOut, v, v1, v2, v3, v4
v = (*TParse)(unsafe.Pointer(pParse)).FpVdbe /* The prepared statement */
addrBreak = (*TSortCtx)(unsafe.Pointer(pSort)).FlabelDone /* Jump here to exit loop */
addrContinue = _sqlite3VdbeMakeLabel(tls, pParse) /* Top of output loop. Jump for Next. */
addrOnce = 0
pOrderBy = (*TSortCtx)(unsafe.Pointer(pSort)).FpOrderBy
eDest = libc.Int32FromUint8((*TSelectDest)(unsafe.Pointer(pDest)).FeDest)
iParm = (*TSelectDest)(unsafe.Pointer(pDest)).FiSDParm /* True if sorter record includes seq. no. */
nRefKey = 0
aOutEx = (*TSelect)(unsafe.Pointer(p)).FpEList + 8
nKey = (*TExprList)(unsafe.Pointer(pOrderBy)).FnExpr - (*TSortCtx)(unsafe.Pointer(pSort)).FnOBSat
if (*TSortCtx)(unsafe.Pointer(pSort)).FnOBSat == 0 || nKey == int32(1) {
if (*TSortCtx)(unsafe.Pointer(pSort)).FnOBSat != 0 {
v1 = __ccgo_ts + 20938
} else {
v1 = __ccgo_ts + 1702
}
_sqlite3VdbeExplain(tls, pParse, uint8(0), __ccgo_ts+20952, libc.VaList(bp+8, v1))
} else {
_sqlite3VdbeExplain(tls, pParse, uint8(0), __ccgo_ts+20983, libc.VaList(bp+8, nKey))
}
if (*TSortCtx)(unsafe.Pointer(pSort)).FlabelBkOut != 0 {
_sqlite3VdbeAddOp2(tls, v, int32(OP_Gosub), (*TSortCtx)(unsafe.Pointer(pSort)).FregReturn, (*TSortCtx)(unsafe.Pointer(pSort)).FlabelBkOut)
_sqlite3VdbeGoto(tls, v, addrBreak)
_sqlite3VdbeResolveLabel(tls, v, (*TSortCtx)(unsafe.Pointer(pSort)).FlabelBkOut)
}
iTab = (*TSortCtx)(unsafe.Pointer(pSort)).FiECursor
if eDest == int32(SRT_Output) || eDest == int32(SRT_Coroutine) || eDest == int32(SRT_Mem) {
if eDest == int32(SRT_Mem) && (*TSelect)(unsafe.Pointer(p)).FiOffset != 0 {
_sqlite3VdbeAddOp2(tls, v, int32(OP_Null), 0, (*TSelectDest)(unsafe.Pointer(pDest)).FiSdst)
}
regRowid = 0
regRow = (*TSelectDest)(unsafe.Pointer(pDest)).FiSdst
} else {
regRowid = _sqlite3GetTempReg(tls, pParse)
if eDest == int32(SRT_EphemTab) || eDest == int32(SRT_Table) {
regRow = _sqlite3GetTempReg(tls, pParse)
nColumn = 0
} else {
regRow = _sqlite3GetTempRange(tls, pParse, nColumn)
}
}
if libc.Int32FromUint8((*TSortCtx)(unsafe.Pointer(pSort)).FsortFlags)&int32(SORTFLAG_UseSorter) != 0 {
v1 = pParse + 60
*(*int32)(unsafe.Pointer(v1)) = *(*int32)(unsafe.Pointer(v1)) + 1
v2 = *(*int32)(unsafe.Pointer(v1))
regSortOut = v2
v3 = pParse + 56
v4 = *(*int32)(unsafe.Pointer(v3))
*(*int32)(unsafe.Pointer(v3)) = *(*int32)(unsafe.Pointer(v3)) + 1
iSortTab = v4
if (*TSortCtx)(unsafe.Pointer(pSort)).FlabelBkOut != 0 {
addrOnce = _sqlite3VdbeAddOp0(tls, v, int32(OP_Once))
}
_sqlite3VdbeAddOp3(tls, v, int32(OP_OpenPseudo), iSortTab, regSortOut, nKey+int32(1)+nColumn+nRefKey)
if addrOnce != 0 {
_sqlite3VdbeJumpHere(tls, v, addrOnce)
}
addr = int32(1) + _sqlite3VdbeAddOp2(tls, v, int32(OP_SorterSort), iTab, addrBreak)
_sqlite3VdbeAddOp3(tls, v, int32(OP_SorterData), iTab, regSortOut, iSortTab)
bSeq = 0
} else {
addr = int32(1) + _sqlite3VdbeAddOp2(tls, v, int32(OP_Sort), iTab, addrBreak)
_codeOffset(tls, v, (*TSelect)(unsafe.Pointer(p)).FiOffset, addrContinue)
iSortTab = iTab
bSeq = int32(1)
if (*TSelect)(unsafe.Pointer(p)).FiOffset > 0 {
_sqlite3VdbeAddOp2(tls, v, int32(OP_AddImm), (*TSelect)(unsafe.Pointer(p)).FiLimit, -int32(1))
}
}
i = 0
iCol = nKey + bSeq - libc.Int32FromInt32(1)
for {
if !(i < nColumn) {
break
}
if libc.Int32FromUint16(*(*Tu16)(unsafe.Pointer(aOutEx + uintptr(i)*32 + 24))) == 0 {
iCol = iCol + 1
}
goto _6
_6:
;
i = i + 1
}
i = nColumn - int32(1)
for {
if !(i >= 0) {
break
}
if *(*Tu16)(unsafe.Pointer(aOutEx + uintptr(i)*32 + 24)) != 0 {
iRead = libc.Int32FromUint16(*(*Tu16)(unsafe.Pointer(aOutEx + uintptr(i)*32 + 24))) - int32(1)
} else {
v2 = iCol
iCol = iCol - 1
iRead = v2
}
_sqlite3VdbeAddOp3(tls, v, int32(OP_Column), iSortTab, iRead, regRow+i)
goto _7
_7:
;
i = i - 1
}
switch eDest {
case int32(SRT_Table):
fallthrough
case int32(SRT_EphemTab):
_sqlite3VdbeAddOp3(tls, v, int32(OP_Column), iSortTab, nKey+bSeq, regRow)
_sqlite3VdbeAddOp2(tls, v, int32(OP_NewRowid), iParm, regRowid)
_sqlite3VdbeAddOp3(tls, v, int32(OP_Insert), iParm, regRow, regRowid)
_sqlite3VdbeChangeP5(tls, v, uint16(OPFLAG_APPEND))
case int32(SRT_Set):
_sqlite3VdbeAddOp4(tls, v, int32(OP_MakeRecord), regRow, nColumn, regRowid, (*TSelectDest)(unsafe.Pointer(pDest)).FzAffSdst, nColumn)
_sqlite3VdbeAddOp4Int(tls, v, int32(OP_IdxInsert), iParm, regRowid, regRow, nColumn)
case int32(SRT_Mem):
/* The LIMIT clause will terminate the loop for us */
case int32(SRT_Upfrom):
i2 = (*TSelectDest)(unsafe.Pointer(pDest)).FiSDParm2
r1 = _sqlite3GetTempReg(tls, pParse)
_sqlite3VdbeAddOp3(tls, v, int32(OP_MakeRecord), regRow+libc.BoolInt32(i2 < 0), nColumn-libc.BoolInt32(i2 < 0), r1)
if i2 < 0 {
_sqlite3VdbeAddOp3(tls, v, int32(OP_Insert), iParm, r1, regRow)
} else {
_sqlite3VdbeAddOp4Int(tls, v, int32(OP_IdxInsert), iParm, r1, regRow, i2)
}
default:
if eDest == int32(SRT_Output) {
_sqlite3VdbeAddOp2(tls, v, int32(OP_ResultRow), (*TSelectDest)(unsafe.Pointer(pDest)).FiSdst, nColumn)
} else {
_sqlite3VdbeAddOp1(tls, v, int32(OP_Yield), (*TSelectDest)(unsafe.Pointer(pDest)).FiSDParm)
}
break
}
if regRowid != 0 {
if eDest == int32(SRT_Set) {
_sqlite3ReleaseTempRange(tls, pParse, regRow, nColumn)
} else {
_sqlite3ReleaseTempReg(tls, pParse, regRow)
}
_sqlite3ReleaseTempReg(tls, pParse, regRowid)
}
/* The bottom of the loop
*/
_sqlite3VdbeResolveLabel(tls, v, addrContinue)
if libc.Int32FromUint8((*TSortCtx)(unsafe.Pointer(pSort)).FsortFlags)&int32(SORTFLAG_UseSorter) != 0 {
_sqlite3VdbeAddOp2(tls, v, int32(OP_SorterNext), iTab, addr)
} else {
_sqlite3VdbeAddOp2(tls, v, int32(OP_Next), iTab, addr)
}
if (*TSortCtx)(unsafe.Pointer(pSort)).FregReturn != 0 {
_sqlite3VdbeAddOp1(tls, v, int32(OP_Return), (*TSortCtx)(unsafe.Pointer(pSort)).FregReturn)
}
_sqlite3VdbeResolveLabel(tls, v, addrBreak)
}
// C documentation
//
// /*
// ** This routine generates VDBE code to compute the content of a WITH RECURSIVE
// ** query of the form:
// **
// ** AS ( UNION [ALL] )
// ** \___________/ \_______________/
// ** p->pPrior p
// **
// **
// ** There is exactly one reference to the recursive-table in the FROM clause
// ** of recursive-query, marked with the SrcList->a[].fg.isRecursive flag.
// **
// ** The setup-query runs once to generate an initial set of rows that go
// ** into a Queue table. Rows are extracted from the Queue table one by
// ** one. Each row extracted from Queue is output to pDest. Then the single
// ** extracted row (now in the iCurrent table) becomes the content of the
// ** recursive-table for a recursive-query run. The output of the recursive-query
// ** is added back into the Queue table. Then another row is extracted from Queue
// ** and the iteration continues until the Queue table is empty.
// **
// ** If the compound query operator is UNION then no duplicate rows are ever
// ** inserted into the Queue table. The iDistinct table keeps a copy of all rows
// ** that have ever been inserted into Queue and causes duplicates to be
// ** discarded. If the operator is UNION ALL, then duplicates are allowed.
// **
// ** If the query has an ORDER BY, then entries in the Queue table are kept in
// ** ORDER BY order and the first entry is extracted for each cycle. Without
// ** an ORDER BY, the Queue table is just a FIFO.
// **
// ** If a LIMIT clause is provided, then the iteration stops after LIMIT rows
// ** have been output to pDest. A LIMIT of zero means to output no rows and a
// ** negative LIMIT means to output all rows. If there is also an OFFSET clause
// ** with a positive value, then the first OFFSET outputs are discarded rather
// ** than being sent to pDest. The LIMIT count does not begin until after OFFSET
// ** rows have been skipped.
// */
func _generateWithRecursiveQuery(tls *libc.TLS, pParse uintptr, p uintptr, pDest uintptr) {
bp := tls.Alloc(48)
defer tls.Free(48)
var addrBreak, addrCont, addrTop, eDest, i, iCurrent, iDistinct, iQueue, nCol, rc, regCurrent, regLimit, regOffset, v1 int32
var apColl, pFirstRec, pKeyInfo, pKeyInfo1, pLimit, pOrderBy, pSetup, pSrc, v, v4 uintptr
var _ /* destQueue at bp+0 */ TSelectDest
_, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _ = addrBreak, addrCont, addrTop, apColl, eDest, i, iCurrent, iDistinct, iQueue, nCol, pFirstRec, pKeyInfo, pKeyInfo1, pLimit, pOrderBy, pSetup, pSrc, rc, regCurrent, regLimit, regOffset, v, v1, v4
pSrc = (*TSelect)(unsafe.Pointer(p)).FpSrc /* The FROM clause of the recursive query */
nCol = (*TExprList)(unsafe.Pointer((*TSelect)(unsafe.Pointer(p)).FpEList)).FnExpr /* Number of columns in the recursive table */
v = (*TParse)(unsafe.Pointer(pParse)).FpVdbe /* CONTINUE and BREAK addresses */
iCurrent = 0 /* The Queue table */
iDistinct = 0 /* To ensure unique results if UNION */
eDest = int32(SRT_Fifo) /* Registers used by LIMIT and OFFSET */
if (*TSelect)(unsafe.Pointer(p)).FpWin != 0 {
_sqlite3ErrorMsg(tls, pParse, __ccgo_ts+21090, 0)
return
}
/* Obtain authorization to do a recursive query */
if _sqlite3AuthCheck(tls, pParse, int32(SQLITE_RECURSIVE), uintptr(0), uintptr(0), uintptr(0)) != 0 {
return
}
/* Process the LIMIT and OFFSET clauses, if they exist */
addrBreak = _sqlite3VdbeMakeLabel(tls, pParse)
(*TSelect)(unsafe.Pointer(p)).FnSelectRow = int16(320) /* 4 billion rows */
_computeLimitRegisters(tls, pParse, p, addrBreak)
pLimit = (*TSelect)(unsafe.Pointer(p)).FpLimit
regLimit = (*TSelect)(unsafe.Pointer(p)).FiLimit
regOffset = (*TSelect)(unsafe.Pointer(p)).FiOffset
(*TSelect)(unsafe.Pointer(p)).FpLimit = uintptr(0)
v1 = libc.Int32FromInt32(0)
(*TSelect)(unsafe.Pointer(p)).FiOffset = v1
(*TSelect)(unsafe.Pointer(p)).FiLimit = v1
pOrderBy = (*TSelect)(unsafe.Pointer(p)).FpOrderBy
/* Locate the cursor number of the Current table */
i = 0
for {
if !(i < (*TSrcList)(unsafe.Pointer(pSrc)).FnSrc) {
break
}
if int32(*(*uint32)(unsafe.Pointer(pSrc + 8 + uintptr(i)*80 + 24 + 4))&0x80>>7) != 0 {
iCurrent = (*(*TSrcItem)(unsafe.Pointer(pSrc + 8 + uintptr(i)*80))).FiCursor
break
}
goto _2
_2:
;
i = i + 1
}
/* Allocate cursors numbers for Queue and Distinct. The cursor number for
** the Distinct table must be exactly one greater than Queue in order
** for the SRT_DistFifo and SRT_DistQueue destinations to work. */
v4 = pParse + 56
v1 = *(*int32)(unsafe.Pointer(v4))
*(*int32)(unsafe.Pointer(v4)) = *(*int32)(unsafe.Pointer(v4)) + 1
iQueue = v1
if libc.Int32FromUint8((*TSelect)(unsafe.Pointer(p)).Fop) == int32(TK_UNION) {
if pOrderBy != 0 {
v1 = int32(SRT_DistQueue)
} else {
v1 = int32(SRT_DistFifo)
}
eDest = v1
v4 = pParse + 56
v1 = *(*int32)(unsafe.Pointer(v4))
*(*int32)(unsafe.Pointer(v4)) = *(*int32)(unsafe.Pointer(v4)) + 1
iDistinct = v1
} else {
if pOrderBy != 0 {
v1 = int32(SRT_Queue)
} else {
v1 = int32(SRT_Fifo)
}
eDest = v1
}
_sqlite3SelectDestInit(tls, bp, eDest, iQueue)
/* Allocate cursors for Current, Queue, and Distinct. */
v4 = pParse + 60
*(*int32)(unsafe.Pointer(v4)) = *(*int32)(unsafe.Pointer(v4)) + 1
v1 = *(*int32)(unsafe.Pointer(v4))
regCurrent = v1
_sqlite3VdbeAddOp3(tls, v, int32(OP_OpenPseudo), iCurrent, regCurrent, nCol)
if pOrderBy != 0 {
pKeyInfo = _multiSelectByMergeKeyInfo(tls, pParse, p, int32(1))
_sqlite3VdbeAddOp4(tls, v, int32(OP_OpenEphemeral), iQueue, (*TExprList)(unsafe.Pointer(pOrderBy)).FnExpr+int32(2), 0, pKeyInfo, -int32(9))
(**(**TSelectDest)(__ccgo_up(bp))).FpOrderBy = pOrderBy
} else {
_sqlite3VdbeAddOp2(tls, v, int32(OP_OpenEphemeral), iQueue, nCol)
}
if iDistinct != 0 { /* For looping through pKeyInfo->aColl[] */
nCol = (*TExprList)(unsafe.Pointer((*TSelect)(unsafe.Pointer(p)).FpEList)).FnExpr
pKeyInfo1 = _sqlite3KeyInfoAlloc(tls, (*TParse)(unsafe.Pointer(pParse)).Fdb, nCol, int32(1))
if pKeyInfo1 != 0 {
i = 0
apColl = pKeyInfo1 + 32
for {
if !(i < nCol) {
break
}
**(**uintptr)(__ccgo_up(apColl)) = _multiSelectCollSeq(tls, pParse, p, i)
if uintptr(0) == **(**uintptr)(__ccgo_up(apColl)) {
**(**uintptr)(__ccgo_up(apColl)) = (*Tsqlite3)(unsafe.Pointer((*TParse)(unsafe.Pointer(pParse)).Fdb)).FpDfltColl
}
goto _11
_11:
;
i = i + 1
apColl += 8
}
_sqlite3VdbeAddOp4(tls, v, int32(OP_OpenEphemeral), iDistinct, nCol, 0, pKeyInfo1, -int32(9))
} else {
}
}
/* Detach the ORDER BY clause from the compound SELECT */
(*TSelect)(unsafe.Pointer(p)).FpOrderBy = uintptr(0)
/* Figure out how many elements of the compound SELECT are part of the
** recursive query. Make sure no recursive elements use aggregate
** functions. Mark the recursive elements as UNION ALL even if they
** are really UNION because the distinctness will be enforced by the
** iDistinct table. pFirstRec is left pointing to the left-most
** recursive term of the CTE.
*/
pFirstRec = p
for {
if !(pFirstRec != uintptr(0)) {
break
}
if (*TSelect)(unsafe.Pointer(pFirstRec)).FselFlags&uint32(SF_Aggregate) != 0 {
_sqlite3ErrorMsg(tls, pParse, __ccgo_ts+21139, 0)
goto end_of_recursive_query
}
(*TSelect)(unsafe.Pointer(pFirstRec)).Fop = uint8(TK_ALL)
if (*TSelect)(unsafe.Pointer((*TSelect)(unsafe.Pointer(pFirstRec)).FpPrior)).FselFlags&uint32(SF_Recursive) == uint32(0) {
break
}
goto _12
_12:
;
pFirstRec = (*TSelect)(unsafe.Pointer(pFirstRec)).FpPrior
}
/* Store the results of the setup-query in Queue. */
pSetup = (*TSelect)(unsafe.Pointer(pFirstRec)).FpPrior
(*TSelect)(unsafe.Pointer(pSetup)).FpNext = uintptr(0)
_sqlite3VdbeExplain(tls, pParse, uint8(1), __ccgo_ts+21181, 0)
rc = _sqlite3Select(tls, pParse, pSetup, bp)
(*TSelect)(unsafe.Pointer(pSetup)).FpNext = p
if rc != 0 {
goto end_of_recursive_query
}
/* Find the next row in the Queue and output that row */
addrTop = _sqlite3VdbeAddOp2(tls, v, int32(OP_Rewind), iQueue, addrBreak)
/* Transfer the next row in Queue over to Current */
_sqlite3VdbeAddOp1(tls, v, int32(OP_NullRow), iCurrent) /* To reset column cache */
if pOrderBy != 0 {
_sqlite3VdbeAddOp3(tls, v, int32(OP_Column), iQueue, (*TExprList)(unsafe.Pointer(pOrderBy)).FnExpr+int32(1), regCurrent)
} else {
_sqlite3VdbeAddOp2(tls, v, int32(OP_RowData), iQueue, regCurrent)
}
_sqlite3VdbeAddOp1(tls, v, int32(OP_Delete), iQueue)
/* Output the single row in Current */
addrCont = _sqlite3VdbeMakeLabel(tls, pParse)
_codeOffset(tls, v, regOffset, addrCont)
_selectInnerLoop(tls, pParse, p, iCurrent, uintptr(0), uintptr(0), pDest, addrCont, addrBreak)
if regLimit != 0 {
_sqlite3VdbeAddOp2(tls, v, int32(OP_DecrJumpZero), regLimit, addrBreak)
}
_sqlite3VdbeResolveLabel(tls, v, addrCont)
/* Execute the recursive SELECT taking the single row in Current as
** the value for the recursive-table. Store the results in the Queue.
*/
(*TSelect)(unsafe.Pointer(pFirstRec)).FpPrior = uintptr(0)
_sqlite3VdbeExplain(tls, pParse, uint8(1), __ccgo_ts+21187, 0)
_sqlite3Select(tls, pParse, p, bp)
(*TSelect)(unsafe.Pointer(pFirstRec)).FpPrior = pSetup
/* Keep running the loop until the Queue is empty */
_sqlite3VdbeGoto(tls, v, addrTop)
_sqlite3VdbeResolveLabel(tls, v, addrBreak)
goto end_of_recursive_query
end_of_recursive_query:
;
_sqlite3ExprListDelete(tls, (*TParse)(unsafe.Pointer(pParse)).Fdb, (*TSelect)(unsafe.Pointer(p)).FpOrderBy)
(*TSelect)(unsafe.Pointer(p)).FpOrderBy = pOrderBy
(*TSelect)(unsafe.Pointer(p)).FpLimit = pLimit
return
}
// C documentation
//
// /*
// ** Each call to sqlite3_rtree_geometry_callback() or
// ** sqlite3_rtree_query_callback() creates an ordinary SQLite
// ** scalar function that is implemented by this routine.
// **
// ** All this function does is construct an RtreeMatchArg object that
// ** contains the geometry-checking callback routines and a list of
// ** parameters to this function, then return that RtreeMatchArg object
// ** as a BLOB.
// **
// ** The R-Tree MATCH operator will read the returned BLOB, deserialize
// ** the RtreeMatchArg object, and use the RtreeMatchArg object to figure
// ** out which elements of the R-Tree should be returned by the query.
// */
func _geomCallback(tls *libc.TLS, ctx uintptr, nArg int32, aArg uintptr) {
var i, memErr int32
var nBlob Tsqlite3_int64
var pBlob, pGeomCtx uintptr
_, _, _, _, _ = i, memErr, nBlob, pBlob, pGeomCtx
pGeomCtx = Xsqlite3_user_data(tls, ctx)
memErr = 0
nBlob = libc.Int64FromUint64(uint64(libc.UintptrFromInt32(0)+56) + libc.Uint64FromInt32(nArg)*uint64(8) + libc.Uint64FromInt32(nArg)*uint64(8))
pBlob = Xsqlite3_malloc64(tls, libc.Uint64FromInt64(nBlob))
if !(pBlob != 0) {
Xsqlite3_result_error_nomem(tls, ctx)
} else {
(*TRtreeMatchArg)(unsafe.Pointer(pBlob)).FiSize = libc.Uint32FromInt64(nBlob)
(*TRtreeMatchArg)(unsafe.Pointer(pBlob)).Fcb = **(**TRtreeGeomCallback)(__ccgo_up(pGeomCtx))
(*TRtreeMatchArg)(unsafe.Pointer(pBlob)).FapSqlParam = pBlob + 56 + uintptr(nArg)*8
(*TRtreeMatchArg)(unsafe.Pointer(pBlob)).FnParam = nArg
i = 0
for {
if !(i < nArg) {
break
}
**(**uintptr)(__ccgo_up((*TRtreeMatchArg)(unsafe.Pointer(pBlob)).FapSqlParam + uintptr(i)*8)) = Xsqlite3_value_dup(tls, **(**uintptr)(__ccgo_up(aArg + uintptr(i)*8)))
if **(**uintptr)(__ccgo_up((*TRtreeMatchArg)(unsafe.Pointer(pBlob)).FapSqlParam + uintptr(i)*8)) == uintptr(0) {
memErr = int32(1)
}
*(*TRtreeDValue)(unsafe.Pointer(pBlob + 56 + uintptr(i)*8)) = Xsqlite3_value_double(tls, **(**uintptr)(__ccgo_up(aArg + uintptr(i)*8)))
goto _1
_1:
;
i = i + 1
}
if memErr != 0 {
Xsqlite3_result_error_nomem(tls, ctx)
_rtreeMatchArgFree(tls, pBlob)
} else {
Xsqlite3_result_pointer(tls, ctx, pBlob, __ccgo_ts+27886, __ccgo_fp(_rtreeMatchArgFree))
}
}
}
// C documentation
//
// /*
// ** If pPoly is a polygon, compute its bounding box. Then:
// **
// ** (1) if aCoord!=0 store the bounding box in aCoord, returning NULL
// ** (2) otherwise, compute a GeoPoly for the bounding box and return the
// ** new GeoPoly
// **
// ** If pPoly is NULL but aCoord is not NULL, then compute a new GeoPoly from
// ** the bounding box in aCoord and return a pointer to that GeoPoly.
// */
func _geopolyBBox(tls *libc.TLS, context uintptr, pPoly uintptr, aCoord uintptr, pRc uintptr) (r1 uintptr) {
bp := tls.Alloc(16)
defer tls.Free(16)
var mnX, mnY, mxX, mxY, v3 float32
var p, pOut uintptr
var r float64
var _ /* ii at bp+0 */ int32
_, _, _, _, _, _, _, _ = mnX, mnY, mxX, mxY, p, pOut, r, v3
pOut = uintptr(0)
if pPoly == uintptr(0) && aCoord != uintptr(0) {
p = uintptr(0)
mnX = *(*TRtreeValue)(unsafe.Pointer(aCoord))
mxX = *(*TRtreeValue)(unsafe.Pointer(aCoord + 1*4))
mnY = *(*TRtreeValue)(unsafe.Pointer(aCoord + 2*4))
mxY = *(*TRtreeValue)(unsafe.Pointer(aCoord + 3*4))
goto geopolyBboxFill
} else {
p = _geopolyFuncParam(tls, context, pPoly, pRc)
}
if !(p != 0) {
goto _1
}
v3 = **(**TGeoCoord)(__ccgo_up(p + 8 + uintptr(libc.Int32FromInt32(0)*libc.Int32FromInt32(2))*4))
mxX = v3
mnX = v3
v3 = **(**TGeoCoord)(__ccgo_up(p + 8 + uintptr(libc.Int32FromInt32(0)*libc.Int32FromInt32(2)+libc.Int32FromInt32(1))*4))
mxY = v3
mnY = v3
**(**int32)(__ccgo_up(bp)) = int32(1)
for {
if !(**(**int32)(__ccgo_up(bp)) < (*TGeoPoly)(unsafe.Pointer(p)).FnVertex) {
break
}
r = float64(**(**TGeoCoord)(__ccgo_up(p + 8 + uintptr(**(**int32)(__ccgo_up(bp))*int32(2))*4)))
if r < float64(mnX) {
mnX = float32(r)
} else {
if r > float64(mxX) {
mxX = float32(r)
}
}
r = float64(**(**TGeoCoord)(__ccgo_up(p + 8 + uintptr(**(**int32)(__ccgo_up(bp))*int32(2)+int32(1))*4)))
if r < float64(mnY) {
mnY = float32(r)
} else {
if r > float64(mxY) {
mxY = float32(r)
}
}
goto _5
_5:
;
**(**int32)(__ccgo_up(bp)) = **(**int32)(__ccgo_up(bp)) + 1
}
if pRc != 0 {
**(**int32)(__ccgo_up(pRc)) = SQLITE_OK
}
if !(aCoord == uintptr(0)) {
goto _6
}
goto geopolyBboxFill
geopolyBboxFill:
;
pOut = Xsqlite3_realloc64(tls, p, uint64(libc.Uint64FromInt64(40)+libc.Uint64FromInt64(4)*libc.Uint64FromInt32(2)*libc.Uint64FromInt32(libc.Int32FromInt32(4)-libc.Int32FromInt32(4))))
if pOut == uintptr(0) {
Xsqlite3_free(tls, p)
if context != 0 {
Xsqlite3_result_error_nomem(tls, context)
}
if pRc != 0 {
**(**int32)(__ccgo_up(pRc)) = int32(SQLITE_NOMEM)
}
return uintptr(0)
}
(*TGeoPoly)(unsafe.Pointer(pOut)).FnVertex = int32(4)
**(**int32)(__ccgo_up(bp)) = int32(1)
**(**uint8)(__ccgo_up(pOut + 4)) = **(**uint8)(__ccgo_up(bp))
**(**uint8)(__ccgo_up(pOut + 4 + 1)) = uint8(0)
**(**uint8)(__ccgo_up(pOut + 4 + 2)) = uint8(0)
**(**uint8)(__ccgo_up(pOut + 4 + 3)) = uint8(4)
**(**TGeoCoord)(__ccgo_up(pOut + 8 + uintptr(libc.Int32FromInt32(0)*libc.Int32FromInt32(2))*4)) = mnX
**(**TGeoCoord)(__ccgo_up(pOut + 8 + uintptr(libc.Int32FromInt32(0)*libc.Int32FromInt32(2)+libc.Int32FromInt32(1))*4)) = mnY
**(**TGeoCoord)(__ccgo_up(pOut + 8 + uintptr(libc.Int32FromInt32(1)*libc.Int32FromInt32(2))*4)) = mxX
**(**TGeoCoord)(__ccgo_up(pOut + 8 + uintptr(libc.Int32FromInt32(1)*libc.Int32FromInt32(2)+libc.Int32FromInt32(1))*4)) = mnY
**(**TGeoCoord)(__ccgo_up(pOut + 8 + uintptr(libc.Int32FromInt32(2)*libc.Int32FromInt32(2))*4)) = mxX
**(**TGeoCoord)(__ccgo_up(pOut + 8 + uintptr(libc.Int32FromInt32(2)*libc.Int32FromInt32(2)+libc.Int32FromInt32(1))*4)) = mxY
**(**TGeoCoord)(__ccgo_up(pOut + 8 + uintptr(libc.Int32FromInt32(3)*libc.Int32FromInt32(2))*4)) = mnX
**(**TGeoCoord)(__ccgo_up(pOut + 8 + uintptr(libc.Int32FromInt32(3)*libc.Int32FromInt32(2)+libc.Int32FromInt32(1))*4)) = mxY
goto _7
_6:
;
Xsqlite3_free(tls, p)
*(*TRtreeValue)(unsafe.Pointer(aCoord)) = mnX
*(*TRtreeValue)(unsafe.Pointer(aCoord + 1*4)) = mxX
*(*TRtreeValue)(unsafe.Pointer(aCoord + 2*4)) = mnY
*(*TRtreeValue)(unsafe.Pointer(aCoord + 3*4)) = mxY
_7:
;
goto _2
_1:
;
if aCoord != 0 {
libc.X__builtin___memset_chk(tls, aCoord, 0, libc.Uint64FromInt64(4)*libc.Uint64FromInt32(4), ^t__predefined_size_t(0))
}
_2:
;
return pOut
}
// C documentation
//
// /*
// ** Implementation of the geopoly_group_bbox(X) aggregate SQL function.
// */
func _geopolyBBoxStep(tls *libc.TLS, context uintptr, argc int32, argv uintptr) {
bp := tls.Alloc(32)
defer tls.Free(32)
var pBBox uintptr
var _ /* a at bp+0 */ [4]TRtreeCoord
var _ /* rc at bp+16 */ int32
_ = pBBox
**(**int32)(__ccgo_up(bp + 16)) = SQLITE_OK
_ = argc
_geopolyBBox(tls, context, **(**uintptr)(__ccgo_up(argv)), bp, bp+16)
if **(**int32)(__ccgo_up(bp + 16)) == SQLITE_OK {
pBBox = Xsqlite3_aggregate_context(tls, context, int32(20))
if pBBox == uintptr(0) {
return
}
if libc.AtomicLoadPInt32(pBBox) == 0 {
libc.AtomicStorePInt32(pBBox, int32(1))
libc.X__builtin___memcpy_chk(tls, pBBox+4, bp, libc.Uint64FromInt64(4)*libc.Uint64FromInt32(4), ^t__predefined_size_t(0))
} else {
if *(*TRtreeValue)(unsafe.Pointer(bp)) < *(*TRtreeValue)(unsafe.Pointer(pBBox + 4)) {
**(**TRtreeCoord)(__ccgo_up(pBBox + 4)) = (**(**[4]TRtreeCoord)(__ccgo_up(bp)))[0]
}
if *(*TRtreeValue)(unsafe.Pointer(bp + 1*4)) > *(*TRtreeValue)(unsafe.Pointer(pBBox + 4 + 1*4)) {
**(**TRtreeCoord)(__ccgo_up(pBBox + 4 + 1*4)) = (**(**[4]TRtreeCoord)(__ccgo_up(bp)))[int32(1)]
}
if *(*TRtreeValue)(unsafe.Pointer(bp + 2*4)) < *(*TRtreeValue)(unsafe.Pointer(pBBox + 4 + 2*4)) {
**(**TRtreeCoord)(__ccgo_up(pBBox + 4 + 2*4)) = (**(**[4]TRtreeCoord)(__ccgo_up(bp)))[int32(2)]
}
if *(*TRtreeValue)(unsafe.Pointer(bp + 3*4)) > *(*TRtreeValue)(unsafe.Pointer(pBBox + 4 + 3*4)) {
**(**TRtreeCoord)(__ccgo_up(pBBox + 4 + 3*4)) = (**(**[4]TRtreeCoord)(__ccgo_up(bp)))[int32(3)]
}
}
}
}
// C documentation
//
// /*
// ** Rtree virtual table module xBestIndex method. There are three
// ** table scan strategies to choose from (in order from most to
// ** least desirable):
// **
// ** idxNum idxStr Strategy
// ** ------------------------------------------------
// ** 1 "rowid" Direct lookup by rowid.
// ** 2 "rtree" R-tree overlap query using geopoly_overlap()
// ** 3 "rtree" R-tree within query using geopoly_within()
// ** 4 "fullscan" full-table scan.
// ** ------------------------------------------------
// */
func _geopolyBestIndex(tls *libc.TLS, tab uintptr, pIdxInfo uintptr) (r int32) {
var iFuncTerm, iRowidTerm, idxNum, ii int32
var p uintptr
_, _, _, _, _ = iFuncTerm, iRowidTerm, idxNum, ii, p
iRowidTerm = -int32(1)
iFuncTerm = -int32(1)
idxNum = 0
_ = tab
ii = 0
for {
if !(ii < (*Tsqlite3_index_info)(unsafe.Pointer(pIdxInfo)).FnConstraint) {
break
}
p = (*Tsqlite3_index_info)(unsafe.Pointer(pIdxInfo)).FaConstraint + uintptr(ii)*12
if !((*Tsqlite3_index_constraint)(unsafe.Pointer(p)).Fusable != 0) {
goto _1
}
if (*Tsqlite3_index_constraint)(unsafe.Pointer(p)).FiColumn < 0 && libc.Int32FromUint8((*Tsqlite3_index_constraint)(unsafe.Pointer(p)).Fop) == int32(SQLITE_INDEX_CONSTRAINT_EQ) {
iRowidTerm = ii
break
}
if (*Tsqlite3_index_constraint)(unsafe.Pointer(p)).FiColumn == 0 && libc.Int32FromUint8((*Tsqlite3_index_constraint)(unsafe.Pointer(p)).Fop) >= int32(SQLITE_INDEX_CONSTRAINT_FUNCTION) {
/* p->op==SQLITE_INDEX_CONSTRAINT_FUNCTION for geopoly_overlap()
** p->op==(SQLITE_INDEX_CONTRAINT_FUNCTION+1) for geopoly_within().
** See geopolyFindFunction() */
iFuncTerm = ii
idxNum = libc.Int32FromUint8((*Tsqlite3_index_constraint)(unsafe.Pointer(p)).Fop) - int32(SQLITE_INDEX_CONSTRAINT_FUNCTION) + int32(2)
}
goto _1
_1:
;
ii = ii + 1
}
if iRowidTerm >= 0 {
(*Tsqlite3_index_info)(unsafe.Pointer(pIdxInfo)).FidxNum = int32(1)
(*Tsqlite3_index_info)(unsafe.Pointer(pIdxInfo)).FidxStr = __ccgo_ts + 18314
(**(**Tsqlite3_index_constraint_usage)(__ccgo_up((*Tsqlite3_index_info)(unsafe.Pointer(pIdxInfo)).FaConstraintUsage + uintptr(iRowidTerm)*8))).FargvIndex = int32(1)
(**(**Tsqlite3_index_constraint_usage)(__ccgo_up((*Tsqlite3_index_info)(unsafe.Pointer(pIdxInfo)).FaConstraintUsage + uintptr(iRowidTerm)*8))).Fomit = uint8(1)
(*Tsqlite3_index_info)(unsafe.Pointer(pIdxInfo)).FestimatedCost = float64(30)
(*Tsqlite3_index_info)(unsafe.Pointer(pIdxInfo)).FestimatedRows = int64(1)
(*Tsqlite3_index_info)(unsafe.Pointer(pIdxInfo)).FidxFlags = int32(SQLITE_INDEX_SCAN_UNIQUE)
return SQLITE_OK
}
if iFuncTerm >= 0 {
(*Tsqlite3_index_info)(unsafe.Pointer(pIdxInfo)).FidxNum = idxNum
(*Tsqlite3_index_info)(unsafe.Pointer(pIdxInfo)).FidxStr = __ccgo_ts + 30364
(**(**Tsqlite3_index_constraint_usage)(__ccgo_up((*Tsqlite3_index_info)(unsafe.Pointer(pIdxInfo)).FaConstraintUsage + uintptr(iFuncTerm)*8))).FargvIndex = int32(1)
(**(**Tsqlite3_index_constraint_usage)(__ccgo_up((*Tsqlite3_index_info)(unsafe.Pointer(pIdxInfo)).FaConstraintUsage + uintptr(iFuncTerm)*8))).Fomit = uint8(0)
(*Tsqlite3_index_info)(unsafe.Pointer(pIdxInfo)).FestimatedCost = float64(300)
(*Tsqlite3_index_info)(unsafe.Pointer(pIdxInfo)).FestimatedRows = int64(10)
return SQLITE_OK
}
(*Tsqlite3_index_info)(unsafe.Pointer(pIdxInfo)).FidxNum = int32(4)
(*Tsqlite3_index_info)(unsafe.Pointer(pIdxInfo)).FidxStr = __ccgo_ts + 30370
(*Tsqlite3_index_info)(unsafe.Pointer(pIdxInfo)).FestimatedCost = float64(3e+06)
(*Tsqlite3_index_info)(unsafe.Pointer(pIdxInfo)).FestimatedRows = int64(100000)
return SQLITE_OK
}
// C documentation
//
// /*
// ** GEOPOLY virtual table module xFilter method.
// **
// ** Query plans:
// **
// ** 1 rowid lookup
// ** 2 search for objects overlapping the same bounding box
// ** that contains polygon argv[0]
// ** 3 search for objects overlapping the same bounding box
// ** that contains polygon argv[0]
// ** 4 full table scan
// */
func _geopolyFilter(tls *libc.TLS, pVtabCursor uintptr, idxNum int32, idxStr uintptr, argc int32, argv uintptr) (r int32) {
bp := tls.Alloc(48)
defer tls.Free(48)
var iRowid Ti64
var p, p1, pCsr, pNew, pRtree, v1 uintptr
var _ /* bbox at bp+32 */ [4]TRtreeCoord
var _ /* iCell at bp+12 */ int32
var _ /* iNode at bp+24 */ Ti64
var _ /* pLeaf at bp+16 */ uintptr
var _ /* pRoot at bp+0 */ uintptr
var _ /* rc at bp+8 */ int32
_, _, _, _, _, _, _ = iRowid, p, p1, pCsr, pNew, pRtree, v1
pRtree = (*Tsqlite3_vtab_cursor)(unsafe.Pointer(pVtabCursor)).FpVtab
pCsr = pVtabCursor
**(**uintptr)(__ccgo_up(bp)) = uintptr(0)
**(**int32)(__ccgo_up(bp + 8)) = SQLITE_OK
**(**int32)(__ccgo_up(bp + 12)) = 0
_ = idxStr
_rtreeReference(tls, pRtree)
/* Reset the cursor to the same state as rtreeOpen() leaves it in. */
_resetCursor(tls, pCsr)
(*TRtreeCursor)(unsafe.Pointer(pCsr)).FiStrategy = idxNum
if idxNum == int32(1) { /* Search point for the leaf */
iRowid = Xsqlite3_value_int64(tls, **(**uintptr)(__ccgo_up(argv)))
**(**Ti64)(__ccgo_up(bp + 24)) = 0
**(**int32)(__ccgo_up(bp + 8)) = _findLeafNode(tls, pRtree, iRowid, bp+16, bp+24)
if **(**int32)(__ccgo_up(bp + 8)) == SQLITE_OK && **(**uintptr)(__ccgo_up(bp + 16)) != uintptr(0) {
p = _rtreeSearchPointNew(tls, pCsr, float64(0), uint8(0))
/* Always returns pCsr->sPoint */
**(**uintptr)(__ccgo_up(pCsr + 88)) = **(**uintptr)(__ccgo_up(bp + 16))
(*TRtreeSearchPoint)(unsafe.Pointer(p)).Fid = **(**Ti64)(__ccgo_up(bp + 24))
(*TRtreeSearchPoint)(unsafe.Pointer(p)).FeWithin = uint8(PARTLY_WITHIN)
**(**int32)(__ccgo_up(bp + 8)) = _nodeRowidIndex(tls, pRtree, **(**uintptr)(__ccgo_up(bp + 16)), iRowid, bp+12)
(*TRtreeSearchPoint)(unsafe.Pointer(p)).FiCell = libc.Uint8FromInt32(**(**int32)(__ccgo_up(bp + 12)))
} else {
(*TRtreeCursor)(unsafe.Pointer(pCsr)).FatEOF = uint8(1)
}
} else {
/* Normal case - r-tree scan. Set up the RtreeCursor.aConstraint array
** with the configured constraints.
*/
**(**int32)(__ccgo_up(bp + 8)) = _nodeAcquire(tls, pRtree, int64(1), uintptr(0), bp)
if **(**int32)(__ccgo_up(bp + 8)) == SQLITE_OK && idxNum <= int32(3) {
_geopolyBBox(tls, uintptr(0), **(**uintptr)(__ccgo_up(argv)), bp+32, bp+8)
if **(**int32)(__ccgo_up(bp + 8)) != 0 {
goto geopoly_filter_end
}
v1 = Xsqlite3_malloc(tls, libc.Int32FromUint64(libc.Uint64FromInt64(24)*libc.Uint64FromInt32(4)))
p1 = v1
(*TRtreeCursor)(unsafe.Pointer(pCsr)).FaConstraint = v1
(*TRtreeCursor)(unsafe.Pointer(pCsr)).FnConstraint = int32(4)
if p1 == uintptr(0) {
**(**int32)(__ccgo_up(bp + 8)) = int32(SQLITE_NOMEM)
} else {
libc.X__builtin___memset_chk(tls, (*TRtreeCursor)(unsafe.Pointer(pCsr)).FaConstraint, 0, libc.Uint64FromInt64(24)*libc.Uint64FromInt32(4), ^t__predefined_size_t(0))
libc.X__builtin___memset_chk(tls, pCsr+128, 0, uint64(4)*libc.Uint64FromInt32((*TRtree)(unsafe.Pointer(pRtree)).FiDepth+libc.Int32FromInt32(1)), ^t__predefined_size_t(0))
if idxNum == int32(2) {
/* Overlap query */
(*TRtreeConstraint)(unsafe.Pointer(p1)).Fop = int32('B')
(*TRtreeConstraint)(unsafe.Pointer(p1)).FiCoord = 0
*(*TRtreeDValue)(unsafe.Pointer(p1 + 8)) = float64(*(*TRtreeValue)(unsafe.Pointer(bp + 32 + 1*4)))
p1 += 24
(*TRtreeConstraint)(unsafe.Pointer(p1)).Fop = int32('D')
(*TRtreeConstraint)(unsafe.Pointer(p1)).FiCoord = int32(1)
*(*TRtreeDValue)(unsafe.Pointer(p1 + 8)) = float64(*(*TRtreeValue)(unsafe.Pointer(bp + 32)))
p1 += 24
(*TRtreeConstraint)(unsafe.Pointer(p1)).Fop = int32('B')
(*TRtreeConstraint)(unsafe.Pointer(p1)).FiCoord = int32(2)
*(*TRtreeDValue)(unsafe.Pointer(p1 + 8)) = float64(*(*TRtreeValue)(unsafe.Pointer(bp + 32 + 3*4)))
p1 += 24
(*TRtreeConstraint)(unsafe.Pointer(p1)).Fop = int32('D')
(*TRtreeConstraint)(unsafe.Pointer(p1)).FiCoord = int32(3)
*(*TRtreeDValue)(unsafe.Pointer(p1 + 8)) = float64(*(*TRtreeValue)(unsafe.Pointer(bp + 32 + 2*4)))
} else {
/* Within query */
(*TRtreeConstraint)(unsafe.Pointer(p1)).Fop = int32('D')
(*TRtreeConstraint)(unsafe.Pointer(p1)).FiCoord = 0
*(*TRtreeDValue)(unsafe.Pointer(p1 + 8)) = float64(*(*TRtreeValue)(unsafe.Pointer(bp + 32)))
p1 += 24
(*TRtreeConstraint)(unsafe.Pointer(p1)).Fop = int32('B')
(*TRtreeConstraint)(unsafe.Pointer(p1)).FiCoord = int32(1)
*(*TRtreeDValue)(unsafe.Pointer(p1 + 8)) = float64(*(*TRtreeValue)(unsafe.Pointer(bp + 32 + 1*4)))
p1 += 24
(*TRtreeConstraint)(unsafe.Pointer(p1)).Fop = int32('D')
(*TRtreeConstraint)(unsafe.Pointer(p1)).FiCoord = int32(2)
*(*TRtreeDValue)(unsafe.Pointer(p1 + 8)) = float64(*(*TRtreeValue)(unsafe.Pointer(bp + 32 + 2*4)))
p1 += 24
(*TRtreeConstraint)(unsafe.Pointer(p1)).Fop = int32('B')
(*TRtreeConstraint)(unsafe.Pointer(p1)).FiCoord = int32(3)
*(*TRtreeDValue)(unsafe.Pointer(p1 + 8)) = float64(*(*TRtreeValue)(unsafe.Pointer(bp + 32 + 3*4)))
}
}
}
if **(**int32)(__ccgo_up(bp + 8)) == SQLITE_OK {
pNew = _rtreeSearchPointNew(tls, pCsr, float64(0), libc.Uint8FromInt32((*TRtree)(unsafe.Pointer(pRtree)).FiDepth+libc.Int32FromInt32(1)))
if pNew == uintptr(0) {
**(**int32)(__ccgo_up(bp + 8)) = int32(SQLITE_NOMEM)
goto geopoly_filter_end
}
(*TRtreeSearchPoint)(unsafe.Pointer(pNew)).Fid = int64(1)
(*TRtreeSearchPoint)(unsafe.Pointer(pNew)).FiCell = uint8(0)
(*TRtreeSearchPoint)(unsafe.Pointer(pNew)).FeWithin = uint8(PARTLY_WITHIN)
**(**uintptr)(__ccgo_up(pCsr + 88)) = **(**uintptr)(__ccgo_up(bp))
**(**uintptr)(__ccgo_up(bp)) = uintptr(0)
**(**int32)(__ccgo_up(bp + 8)) = _rtreeStepToLeaf(tls, pCsr)
}
}
goto geopoly_filter_end
geopoly_filter_end:
;
_nodeRelease(tls, pRtree, **(**uintptr)(__ccgo_up(bp)))
_rtreeRelease(tls, pRtree)
return **(**int32)(__ccgo_up(bp + 8))
}
// C documentation
//
// /*
// ** Report that geopoly_overlap() is an overloaded function suitable
// ** for use in xBestIndex.
// */
func _geopolyFindFunction(tls *libc.TLS, pVtab uintptr, nArg int32, zName uintptr, __ccgo_fp_pxFunc uintptr, ppArg uintptr) (r int32) {
_ = pVtab
_ = nArg
if Xsqlite3_stricmp(tls, zName, __ccgo_ts+30419) == 0 {
**(**uintptr)(__ccgo_up(__ccgo_fp_pxFunc)) = __ccgo_fp(_geopolyOverlapFunc)
**(**uintptr)(__ccgo_up(ppArg)) = uintptr(0)
return int32(SQLITE_INDEX_CONSTRAINT_FUNCTION)
}
if Xsqlite3_stricmp(tls, zName, __ccgo_ts+30435) == 0 {
**(**uintptr)(__ccgo_up(__ccgo_fp_pxFunc)) = __ccgo_fp(_geopolyWithinFunc)
**(**uintptr)(__ccgo_up(ppArg)) = uintptr(0)
return libc.Int32FromInt32(SQLITE_INDEX_CONSTRAINT_FUNCTION) + libc.Int32FromInt32(1)
}
return 0
}
// C documentation
//
// /*
// ** Given a function parameter, try to interpret it as a polygon, either
// ** in the binary format or JSON text. Compute a GeoPoly object and
// ** return a pointer to that object. Or if the input is not a well-formed
// ** polygon, put an error message in sqlite3_context and return NULL.
// */
func _geopolyFuncParam(tls *libc.TLS, pCtx uintptr, pVal uintptr, pRc uintptr) (r uintptr) {
bp := tls.Alloc(16)
defer tls.Free(16)
var a, p, zJson, v4 uintptr
var ii, nByte, nVertex, v1 int32
var v2 bool
var _ /* x at bp+0 */ int32
_, _, _, _, _, _, _, _, _ = a, ii, nByte, nVertex, p, zJson, v1, v2, v4
p = uintptr(0)
if v2 = Xsqlite3_value_type(tls, pVal) == int32(SQLITE_BLOB); v2 {
v1 = Xsqlite3_value_bytes(tls, pVal)
nByte = v1
}
if v2 && v1 >= libc.Int32FromUint64(libc.Uint64FromInt32(4)+libc.Uint64FromInt32(6)*libc.Uint64FromInt64(4)) {
a = Xsqlite3_value_blob(tls, pVal)
if a == uintptr(0) {
if pCtx != 0 {
Xsqlite3_result_error_nomem(tls, pCtx)
}
return uintptr(0)
}
nVertex = libc.Int32FromUint8(**(**uint8)(__ccgo_up(a + 1)))< 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+30301, 0)
return int32(SQLITE_ERROR)
}
Xsqlite3_vtab_config(tls, db, int32(SQLITE_VTAB_CONSTRAINT_SUPPORT), libc.VaList(bp+8, int32(1)))
Xsqlite3_vtab_config(tls, db, int32(SQLITE_VTAB_INNOCUOUS), 0)
/* Allocate the sqlite3_vtab structure */
nDb = libc.Int64FromUint64(libc.Xstrlen(tls, **(**uintptr)(__ccgo_up(argv + 1*8))))
nName = libc.Int64FromUint64(libc.Xstrlen(tls, **(**uintptr)(__ccgo_up(argv + 2*8))))
pRtree = Xsqlite3_malloc64(tls, uint64(976)+libc.Uint64FromInt64(nDb)+libc.Uint64FromInt64(nName*int64(2))+uint64(8))
if !(pRtree != 0) {
return int32(SQLITE_NOMEM)
}
libc.X__builtin___memset_chk(tls, pRtree, 0, uint64(uint64(976)+libc.Uint64FromInt64(nDb)+libc.Uint64FromInt64(nName*int64(2))+uint64(8)), ^t__predefined_size_t(0))
(*TRtree)(unsafe.Pointer(pRtree)).FnBusy = uint32(1)
(*TRtree)(unsafe.Pointer(pRtree)).Fbase.FpModule = uintptr(unsafe.Pointer(&_rtreeModule))
(*TRtree)(unsafe.Pointer(pRtree)).FzDb = pRtree + 1*976
(*TRtree)(unsafe.Pointer(pRtree)).FzName = (*TRtree)(unsafe.Pointer(pRtree)).FzDb + uintptr(nDb+int64(1))
(*TRtree)(unsafe.Pointer(pRtree)).FzNodeName = (*TRtree)(unsafe.Pointer(pRtree)).FzName + uintptr(nName+int64(1))
(*TRtree)(unsafe.Pointer(pRtree)).FeCoordType = uint8(RTREE_COORD_REAL32)
(*TRtree)(unsafe.Pointer(pRtree)).FnDim = uint8(2)
(*TRtree)(unsafe.Pointer(pRtree)).FnDim2 = uint8(4)
libc.X__builtin___memcpy_chk(tls, (*TRtree)(unsafe.Pointer(pRtree)).FzDb, **(**uintptr)(__ccgo_up(argv + 1*8)), libc.Uint64FromInt64(nDb), ^t__predefined_size_t(0))
libc.X__builtin___memcpy_chk(tls, (*TRtree)(unsafe.Pointer(pRtree)).FzName, **(**uintptr)(__ccgo_up(argv + 2*8)), libc.Uint64FromInt64(nName), ^t__predefined_size_t(0))
libc.X__builtin___memcpy_chk(tls, (*TRtree)(unsafe.Pointer(pRtree)).FzNodeName, **(**uintptr)(__ccgo_up(argv + 2*8)), libc.Uint64FromInt64(nName), ^t__predefined_size_t(0))
libc.X__builtin___memcpy_chk(tls, (*TRtree)(unsafe.Pointer(pRtree)).FzNodeName+uintptr(nName), __ccgo_ts+29343, uint64(6), ^t__predefined_size_t(0))
/* 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+30338, 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+30360, libc.VaList(bp+8, **(**uintptr)(__ccgo_up(argv + uintptr(ii)*8))))
goto _1
_1:
;
ii = ii + 1
}
Xsqlite3_str_appendf(tls, pSql, __ccgo_ts+29400, 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+3944, libc.VaList(bp+8, Xsqlite3_errmsg(tls, db)))
}
}
Xsqlite3_free(tls, zSql)
if rc != 0 {
goto geopolyInit_fail
}
(*TRtree)(unsafe.Pointer(pRtree)).FnBytesPerCell = libc.Uint8FromInt32(int32(8) + libc.Int32FromUint8((*TRtree)(unsafe.Pointer(pRtree)).FnDim2)*int32(4))
/* Figure out the node size to use. */
rc = _getNodeSize(tls, db, pRtree, isCreate, pzErr)
if rc != 0 {
goto geopolyInit_fail
}
rc = _rtreeSqlInit(tls, pRtree, db, **(**uintptr)(__ccgo_up(argv + 1*8)), **(**uintptr)(__ccgo_up(argv + 2*8)), isCreate)
if rc != 0 {
**(**uintptr)(__ccgo_up(pzErr)) = Xsqlite3_mprintf(tls, __ccgo_ts+3944, libc.VaList(bp+8, Xsqlite3_errmsg(tls, db)))
goto geopolyInit_fail
}
**(**uintptr)(__ccgo_up(ppVtab)) = pRtree
return SQLITE_OK
goto geopolyInit_fail
geopolyInit_fail:
;
if rc == SQLITE_OK {
rc = int32(SQLITE_ERROR)
}
_rtreeRelease(tls, pRtree)
return rc
}
// C documentation
//
// /*
// ** SQL function: geopoly_json(X)
// **
// ** Interpret X as a polygon and render it as a JSON array
// ** of coordinates. Or, if X is not a valid polygon, return NULL.
// */
func _geopolyJsonFunc(tls *libc.TLS, context uintptr, argc int32, argv uintptr) {
bp := tls.Alloc(32)
defer tls.Free(32)
var db, p, x uintptr
var i int32
_, _, _, _ = db, i, p, x
p = _geopolyFuncParam(tls, context, **(**uintptr)(__ccgo_up(argv)), uintptr(0))
_ = argc
if p != 0 {
db = Xsqlite3_context_db_handle(tls, context)
x = Xsqlite3_str_new(tls, db)
Xsqlite3_str_append(tls, x, __ccgo_ts+27065, int32(1))
i = 0
for {
if !(i < (*TGeoPoly)(unsafe.Pointer(p)).FnVertex) {
break
}
Xsqlite3_str_appendf(tls, x, __ccgo_ts+30228, libc.VaList(bp+8, float64(**(**TGeoCoord)(__ccgo_up(p + 8 + uintptr(i*int32(2))*4))), float64(**(**TGeoCoord)(__ccgo_up(p + 8 + uintptr(i*int32(2)+int32(1))*4)))))
goto _1
_1:
;
i = i + 1
}
Xsqlite3_str_appendf(tls, x, __ccgo_ts+30239, libc.VaList(bp+8, float64(**(**TGeoCoord)(__ccgo_up(p + 8 + uintptr(libc.Int32FromInt32(0)*libc.Int32FromInt32(2))*4))), float64(**(**TGeoCoord)(__ccgo_up(p + 8 + uintptr(libc.Int32FromInt32(0)*libc.Int32FromInt32(2)+libc.Int32FromInt32(1))*4)))))
Xsqlite3_result_text(tls, context, Xsqlite3_str_finish(tls, x), -int32(1), __ccgo_fp(Xsqlite3_free))
Xsqlite3_free(tls, p)
}
}
// C documentation
//
// /*
// ** Determine the overlap between two polygons
// */
func _geopolyOverlap(tls *libc.TLS, p1 uintptr, p2 uintptr) (r int32) {
bp := tls.Alloc(16)
defer tls.Free(16)
var iMask, needSort, rc, v1 int32
var nByte, nVertex Tsqlite3_int64
var p, pActive, pPrev, pSeg, pThisEvent, v5 uintptr
var rX, y, v2 float64
var _ /* aOverlap at bp+0 */ [4]uint8
_, _, _, _, _, _, _, _, _, _, _, _, _, _, _ = iMask, nByte, nVertex, needSort, p, pActive, pPrev, pSeg, pThisEvent, rX, rc, y, v1, v2, v5
nVertex = int64((*TGeoPoly)(unsafe.Pointer(p1)).FnVertex + (*TGeoPoly)(unsafe.Pointer(p2)).FnVertex + int32(2))
rc = 0
needSort = 0
pActive = uintptr(0)
nByte = libc.Int64FromUint64(uint64(32)*libc.Uint64FromInt64(nVertex)*uint64(2) + uint64(48)*libc.Uint64FromInt64(nVertex) + uint64(24))
p = Xsqlite3_malloc64(tls, libc.Uint64FromInt64(nByte))
if p == uintptr(0) {
return -int32(1)
}
(*TGeoOverlap)(unsafe.Pointer(p)).FaEvent = p + 1*24
(*TGeoOverlap)(unsafe.Pointer(p)).FaSegment = (*TGeoOverlap)(unsafe.Pointer(p)).FaEvent + uintptr(nVertex*int64(2))*32
v1 = libc.Int32FromInt32(0)
(*TGeoOverlap)(unsafe.Pointer(p)).FnSegment = v1
(*TGeoOverlap)(unsafe.Pointer(p)).FnEvent = v1
_geopolyAddSegments(tls, p, p1, uint8(1))
_geopolyAddSegments(tls, p, p2, uint8(2))
pThisEvent = _geopolySortEventsByX(tls, (*TGeoOverlap)(unsafe.Pointer(p)).FaEvent, (*TGeoOverlap)(unsafe.Pointer(p)).FnEvent)
if pThisEvent != 0 && (*TGeoEvent)(unsafe.Pointer(pThisEvent)).Fx == float64(0) {
v2 = -libc.Float64FromFloat64(1)
} else {
v2 = float64(0)
}
rX = v2
libc.X__builtin___memset_chk(tls, bp, 0, uint64(4), ^t__predefined_size_t(0))
for pThisEvent != 0 {
if (*TGeoEvent)(unsafe.Pointer(pThisEvent)).Fx != rX {
pPrev = uintptr(0)
iMask = 0
rX = (*TGeoEvent)(unsafe.Pointer(pThisEvent)).Fx
if needSort != 0 {
pActive = _geopolySortSegmentsByYAndC(tls, pActive)
needSort = 0
}
pSeg = pActive
for {
if !(pSeg != 0) {
break
}
if pPrev != 0 {
if (*TGeoSegment)(unsafe.Pointer(pPrev)).Fy != (*TGeoSegment)(unsafe.Pointer(pSeg)).Fy {
(**(**[4]uint8)(__ccgo_up(bp)))[iMask] = uint8(1)
}
}
iMask = iMask ^ libc.Int32FromUint8((*TGeoSegment)(unsafe.Pointer(pSeg)).Fside)
pPrev = pSeg
goto _3
_3:
;
pSeg = (*TGeoSegment)(unsafe.Pointer(pSeg)).FpNext
}
pPrev = uintptr(0)
pSeg = pActive
for {
if !(pSeg != 0) {
break
}
y = float64((*TGeoSegment)(unsafe.Pointer(pSeg)).FC*rX) + (*TGeoSegment)(unsafe.Pointer(pSeg)).FB
(*TGeoSegment)(unsafe.Pointer(pSeg)).Fy = y
if pPrev != 0 {
if (*TGeoSegment)(unsafe.Pointer(pPrev)).Fy > (*TGeoSegment)(unsafe.Pointer(pSeg)).Fy && libc.Int32FromUint8((*TGeoSegment)(unsafe.Pointer(pPrev)).Fside) != libc.Int32FromUint8((*TGeoSegment)(unsafe.Pointer(pSeg)).Fside) {
rc = int32(1)
goto geopolyOverlapDone
} else {
if (*TGeoSegment)(unsafe.Pointer(pPrev)).Fy != (*TGeoSegment)(unsafe.Pointer(pSeg)).Fy {
(**(**[4]uint8)(__ccgo_up(bp)))[iMask] = uint8(1)
}
}
}
iMask = iMask ^ libc.Int32FromUint8((*TGeoSegment)(unsafe.Pointer(pSeg)).Fside)
pPrev = pSeg
goto _4
_4:
;
pSeg = (*TGeoSegment)(unsafe.Pointer(pSeg)).FpNext
}
}
if (*TGeoEvent)(unsafe.Pointer(pThisEvent)).FeType == 0 {
/* Add a segment */
pSeg = (*TGeoEvent)(unsafe.Pointer(pThisEvent)).FpSeg
(*TGeoSegment)(unsafe.Pointer(pSeg)).Fy = float64((*TGeoSegment)(unsafe.Pointer(pSeg)).Fy0)
(*TGeoSegment)(unsafe.Pointer(pSeg)).FpNext = pActive
pActive = pSeg
needSort = int32(1)
} else {
/* Remove a segment */
if pActive == (*TGeoEvent)(unsafe.Pointer(pThisEvent)).FpSeg {
if pActive != 0 {
v5 = (*TGeoSegment)(unsafe.Pointer(pActive)).FpNext
} else {
v5 = uintptr(0)
}
pActive = v5
} else {
pSeg = pActive
for {
if !(pSeg != 0) {
break
}
if (*TGeoSegment)(unsafe.Pointer(pSeg)).FpNext == (*TGeoEvent)(unsafe.Pointer(pThisEvent)).FpSeg {
if (*TGeoSegment)(unsafe.Pointer(pSeg)).FpNext != 0 {
v5 = (*TGeoSegment)(unsafe.Pointer((*TGeoSegment)(unsafe.Pointer(pSeg)).FpNext)).FpNext
} else {
v5 = uintptr(0)
}
(*TGeoSegment)(unsafe.Pointer(pSeg)).FpNext = v5
break
}
goto _6
_6:
;
pSeg = (*TGeoSegment)(unsafe.Pointer(pSeg)).FpNext
}
}
}
pThisEvent = (*TGeoEvent)(unsafe.Pointer(pThisEvent)).FpNext
}
if libc.Int32FromUint8((**(**[4]uint8)(__ccgo_up(bp)))[int32(3)]) == 0 {
rc = 0
} else {
if libc.Int32FromUint8((**(**[4]uint8)(__ccgo_up(bp)))[int32(1)]) != 0 && libc.Int32FromUint8((**(**[4]uint8)(__ccgo_up(bp)))[int32(2)]) == 0 {
rc = int32(3)
} else {
if libc.Int32FromUint8((**(**[4]uint8)(__ccgo_up(bp)))[int32(1)]) == 0 && libc.Int32FromUint8((**(**[4]uint8)(__ccgo_up(bp)))[int32(2)]) != 0 {
rc = int32(2)
} else {
if libc.Int32FromUint8((**(**[4]uint8)(__ccgo_up(bp)))[int32(1)]) == 0 && libc.Int32FromUint8((**(**[4]uint8)(__ccgo_up(bp)))[int32(2)]) == 0 {
rc = int32(4)
} else {
rc = int32(1)
}
}
}
}
goto geopolyOverlapDone
geopolyOverlapDone:
;
Xsqlite3_free(tls, p)
return rc
}
// C documentation
//
// /*
// ** If the input is a well-formed JSON array of coordinates with at least
// ** four coordinates and where each coordinate is itself a two-value array,
// ** then convert the JSON into a GeoPoly object and return a pointer to
// ** that object.
// **
// ** If any error occurs, return NULL.
// */
func _geopolyParseJson(tls *libc.TLS, z uintptr, pRc uintptr) (r uintptr) {
bp := tls.Alloc(48)
defer tls.Free(48)
var aNew, pOut, v1 uintptr
var c int8
var ii, rc int32
var v2 bool
var _ /* s at bp+0 */ TGeoParse
var _ /* x at bp+32 */ int32
_, _, _, _, _, _, _ = aNew, c, ii, pOut, rc, v1, v2
rc = SQLITE_OK
libc.X__builtin___memset_chk(tls, bp, 0, uint64(32), ^t__predefined_size_t(0))
(**(**TGeoParse)(__ccgo_up(bp))).Fz = z
if int32(_geopolySkipSpace(tls, bp)) == int32('[') {
(**(**TGeoParse)(__ccgo_up(bp))).Fz = (**(**TGeoParse)(__ccgo_up(bp))).Fz + 1
for int32(_geopolySkipSpace(tls, bp)) == int32('[') {
ii = 0
(**(**TGeoParse)(__ccgo_up(bp))).Fz = (**(**TGeoParse)(__ccgo_up(bp))).Fz + 1
if (**(**TGeoParse)(__ccgo_up(bp))).FnVertex >= (**(**TGeoParse)(__ccgo_up(bp))).FnAlloc {
(**(**TGeoParse)(__ccgo_up(bp))).FnAlloc = (**(**TGeoParse)(__ccgo_up(bp))).FnAlloc*int32(2) + int32(16)
aNew = Xsqlite3_realloc64(tls, (**(**TGeoParse)(__ccgo_up(bp))).Fa, uint64(libc.Uint64FromInt32((**(**TGeoParse)(__ccgo_up(bp))).FnAlloc)*uint64(4)*uint64(2)))
if aNew == uintptr(0) {
rc = int32(SQLITE_NOMEM)
(**(**TGeoParse)(__ccgo_up(bp))).FnErr = (**(**TGeoParse)(__ccgo_up(bp))).FnErr + 1
break
}
(**(**TGeoParse)(__ccgo_up(bp))).Fa = aNew
}
for {
if ii <= int32(1) {
v1 = (**(**TGeoParse)(__ccgo_up(bp))).Fa + uintptr((**(**TGeoParse)(__ccgo_up(bp))).FnVertex*int32(2)+ii)*4
} else {
v1 = uintptr(0)
}
if !(_geopolyParseNumber(tls, bp, v1) != 0) {
break
}
ii = ii + 1
if ii == int32(2) {
(**(**TGeoParse)(__ccgo_up(bp))).FnVertex = (**(**TGeoParse)(__ccgo_up(bp))).FnVertex + 1
}
c = _geopolySkipSpace(tls, bp)
(**(**TGeoParse)(__ccgo_up(bp))).Fz = (**(**TGeoParse)(__ccgo_up(bp))).Fz + 1
if int32(c) == int32(',') {
continue
}
if int32(c) == int32(']') && ii >= int32(2) {
break
}
(**(**TGeoParse)(__ccgo_up(bp))).FnErr = (**(**TGeoParse)(__ccgo_up(bp))).FnErr + 1
rc = int32(SQLITE_ERROR)
goto parse_json_err
}
if int32(_geopolySkipSpace(tls, bp)) == int32(',') {
(**(**TGeoParse)(__ccgo_up(bp))).Fz = (**(**TGeoParse)(__ccgo_up(bp))).Fz + 1
continue
}
break
}
if v2 = int32(_geopolySkipSpace(tls, bp)) == int32(']') && (**(**TGeoParse)(__ccgo_up(bp))).FnVertex >= int32(4) && **(**TGeoCoord)(__ccgo_up((**(**TGeoParse)(__ccgo_up(bp))).Fa)) == **(**TGeoCoord)(__ccgo_up((**(**TGeoParse)(__ccgo_up(bp))).Fa + uintptr((**(**TGeoParse)(__ccgo_up(bp))).FnVertex*int32(2)-int32(2))*4)) && **(**TGeoCoord)(__ccgo_up((**(**TGeoParse)(__ccgo_up(bp))).Fa + 1*4)) == **(**TGeoCoord)(__ccgo_up((**(**TGeoParse)(__ccgo_up(bp))).Fa + uintptr((**(**TGeoParse)(__ccgo_up(bp))).FnVertex*int32(2)-int32(1))*4)); v2 {
(**(**TGeoParse)(__ccgo_up(bp))).Fz = (**(**TGeoParse)(__ccgo_up(bp))).Fz + 1
}
if v2 && int32(_geopolySkipSpace(tls, bp)) == libc.Int32FromInt32(0) {
**(**int32)(__ccgo_up(bp + 32)) = int32(1)
(**(**TGeoParse)(__ccgo_up(bp))).FnVertex = (**(**TGeoParse)(__ccgo_up(bp))).FnVertex - 1 /* Remove the redundant vertex at the end */
pOut = Xsqlite3_malloc64(tls, libc.Uint64FromInt64(40)+uint64(libc.Uint64FromInt64(4)*libc.Uint64FromInt32(2))*libc.Uint64FromInt64(int64((**(**TGeoParse)(__ccgo_up(bp))).FnVertex)-libc.Int64FromInt32(4)))
**(**int32)(__ccgo_up(bp + 32)) = int32(1)
if pOut == uintptr(0) {
goto parse_json_err
}
(*TGeoPoly)(unsafe.Pointer(pOut)).FnVertex = (**(**TGeoParse)(__ccgo_up(bp))).FnVertex
libc.X__builtin___memcpy_chk(tls, pOut+8, (**(**TGeoParse)(__ccgo_up(bp))).Fa, libc.Uint64FromInt32((**(**TGeoParse)(__ccgo_up(bp))).FnVertex*int32(2))*uint64(4), ^t__predefined_size_t(0))
**(**uint8)(__ccgo_up(pOut + 4)) = **(**uint8)(__ccgo_up(bp + 32))
**(**uint8)(__ccgo_up(pOut + 4 + 1)) = libc.Uint8FromInt32((**(**TGeoParse)(__ccgo_up(bp))).FnVertex >> int32(16) & int32(0xff))
**(**uint8)(__ccgo_up(pOut + 4 + 2)) = libc.Uint8FromInt32((**(**TGeoParse)(__ccgo_up(bp))).FnVertex >> int32(8) & int32(0xff))
**(**uint8)(__ccgo_up(pOut + 4 + 3)) = libc.Uint8FromInt32((**(**TGeoParse)(__ccgo_up(bp))).FnVertex & int32(0xff))
Xsqlite3_free(tls, (**(**TGeoParse)(__ccgo_up(bp))).Fa)
if pRc != 0 {
**(**int32)(__ccgo_up(pRc)) = SQLITE_OK
}
return pOut
} else {
(**(**TGeoParse)(__ccgo_up(bp))).FnErr = (**(**TGeoParse)(__ccgo_up(bp))).FnErr + 1
rc = int32(SQLITE_ERROR)
}
}
goto parse_json_err
parse_json_err:
;
if pRc != 0 {
**(**int32)(__ccgo_up(pRc)) = rc
}
Xsqlite3_free(tls, (**(**TGeoParse)(__ccgo_up(bp))).Fa)
return uintptr(0)
}
// C documentation
//
// /*
// ** SQL function: geopoly_svg(X, ....)
// **
// ** Interpret X as a polygon and render it as a SVG .
// ** Additional arguments are added as attributes to the .
// */
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+30250, 0)
i = 0
for {
if !(i < (*TGeoPoly)(unsafe.Pointer(p)).FnVertex) {
break
}
Xsqlite3_str_appendf(tls, x, __ccgo_ts+30268, 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+30276, 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)*8)))
if z != 0 && **(**int8)(__ccgo_up(z)) != 0 {
Xsqlite3_str_appendf(tls, x, __ccgo_ts+30284, libc.VaList(bp+8, z))
}
goto _2
_2:
;
i = i + 1
}
Xsqlite3_str_appendf(tls, x, __ccgo_ts+30288, 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+8 */ TRtreeCell
var _ /* pLeaf at bp+56 */ uintptr
var _ /* rc at bp+0 */ int32
_, _, _, _, _, _, _, _, _, _, _, _, _, _, _ = coordChange, jj, nChange, newRowid, newRowidValid, oldRowid, oldRowidValid, p, pRtree, pUp, rc2, steprc, v1, v3, v4
pRtree = pVtab
**(**int32)(__ccgo_up(bp)) = SQLITE_OK /* True if newRowid is valid */
coordChange = 0 /* Change in coordinates */
if (*TRtree)(unsafe.Pointer(pRtree)).FnNodeRef != 0 {
/* Unable to write to the btree while another cursor is reading from it,
** since the write might do a rebalance which would disrupt the read
** cursor. */
return libc.Int32FromInt32(SQLITE_LOCKED) | libc.Int32FromInt32(2)< int32(1) && Xsqlite3_value_type(tls, **(**uintptr)(__ccgo_up(aData + 1*8))) != int32(SQLITE_NULL))
if newRowidValid != 0 {
v1 = Xsqlite3_value_int64(tls, **(**uintptr)(__ccgo_up(aData + 1*8)))
} else {
v1 = 0
}
newRowid = v1
(**(**TRtreeCell)(__ccgo_up(bp + 8))).FiRowid = newRowid
if nData > int32(1) && (!(oldRowidValid != 0) || !(Xsqlite3_value_nochange(tls, **(**uintptr)(__ccgo_up(aData + 2*8))) != 0) || oldRowid != newRowid) {
_geopolyBBox(tls, uintptr(0), **(**uintptr)(__ccgo_up(aData + 2*8)), bp+8+8, bp)
if **(**int32)(__ccgo_up(bp)) != 0 {
if **(**int32)(__ccgo_up(bp)) == int32(SQLITE_ERROR) {
(*Tsqlite3_vtab)(unsafe.Pointer(pVtab)).FzErrMsg = Xsqlite3_mprintf(tls, __ccgo_ts+30379, 0)
}
goto geopoly_update_end
}
coordChange = int32(1)
/* If a rowid value was supplied, check if it is already present in
** the table. If so, the constraint has failed. */
if newRowidValid != 0 && (!(oldRowidValid != 0) || oldRowid != newRowid) {
Xsqlite3_bind_int64(tls, (*TRtree)(unsafe.Pointer(pRtree)).FpReadRowid, int32(1), (**(**TRtreeCell)(__ccgo_up(bp + 8))).FiRowid)
steprc = Xsqlite3_step(tls, (*TRtree)(unsafe.Pointer(pRtree)).FpReadRowid)
**(**int32)(__ccgo_up(bp)) = Xsqlite3_reset(tls, (*TRtree)(unsafe.Pointer(pRtree)).FpReadRowid)
if int32(SQLITE_ROW) == steprc {
if Xsqlite3_vtab_on_conflict(tls, (*TRtree)(unsafe.Pointer(pRtree)).Fdb) == int32(SQLITE_REPLACE) {
**(**int32)(__ccgo_up(bp)) = _rtreeDeleteRowid(tls, pRtree, (**(**TRtreeCell)(__ccgo_up(bp + 8))).FiRowid)
} else {
**(**int32)(__ccgo_up(bp)) = _rtreeConstraintError(tls, pRtree, 0)
}
}
}
}
/* If aData[0] is not an SQL NULL value, it is the rowid of a
** record to delete from the r-tree table. The following block does
** just that.
*/
if **(**int32)(__ccgo_up(bp)) == SQLITE_OK && (nData == int32(1) || coordChange != 0 && oldRowidValid != 0) {
**(**int32)(__ccgo_up(bp)) = _rtreeDeleteRowid(tls, pRtree, oldRowid)
}
/* If the aData[] array contains more than one element, elements
** (aData[2]..aData[argc-1]) contain a new record to insert into
** the r-tree structure.
*/
if **(**int32)(__ccgo_up(bp)) == SQLITE_OK && nData > int32(1) && coordChange != 0 {
/* Insert the new record into the r-tree */
**(**uintptr)(__ccgo_up(bp + 56)) = uintptr(0)
if !(newRowidValid != 0) {
**(**int32)(__ccgo_up(bp)) = _rtreeNewRowid(tls, pRtree, bp+8)
}
**(**Tsqlite_int64)(__ccgo_up(pRowid)) = (**(**TRtreeCell)(__ccgo_up(bp + 8))).FiRowid
if **(**int32)(__ccgo_up(bp)) == SQLITE_OK {
**(**int32)(__ccgo_up(bp)) = _ChooseLeaf(tls, pRtree, bp+8, 0, bp+56)
}
if **(**int32)(__ccgo_up(bp)) == SQLITE_OK {
**(**int32)(__ccgo_up(bp)) = _rtreeInsertCell(tls, pRtree, **(**uintptr)(__ccgo_up(bp + 56)), bp+8, 0)
rc2 = _nodeRelease(tls, pRtree, **(**uintptr)(__ccgo_up(bp + 56)))
if **(**int32)(__ccgo_up(bp)) == SQLITE_OK {
**(**int32)(__ccgo_up(bp)) = rc2
}
}
}
/* Change the data */
if **(**int32)(__ccgo_up(bp)) == SQLITE_OK && nData > int32(1) {
pUp = (*TRtree)(unsafe.Pointer(pRtree)).FpWriteAux
nChange = 0
Xsqlite3_bind_int64(tls, pUp, int32(1), (**(**TRtreeCell)(__ccgo_up(bp + 8))).FiRowid)
if Xsqlite3_value_nochange(tls, **(**uintptr)(__ccgo_up(aData + 2*8))) != 0 {
Xsqlite3_bind_null(tls, pUp, int32(2))
} else {
p = uintptr(0)
if v4 = Xsqlite3_value_type(tls, **(**uintptr)(__ccgo_up(aData + 2*8))) == int32(SQLITE_TEXT); v4 {
v3 = _geopolyFuncParam(tls, uintptr(0), **(**uintptr)(__ccgo_up(aData + 2*8)), bp)
p = v3
}
if v4 && v3 != uintptr(0) && **(**int32)(__ccgo_up(bp)) == SQLITE_OK {
Xsqlite3_bind_blob(tls, pUp, int32(2), p+4, int32(4)+int32(8)*(*TGeoPoly)(unsafe.Pointer(p)).FnVertex, uintptr(-libc.Int32FromInt32(1)))
} else {
Xsqlite3_bind_value(tls, pUp, int32(2), **(**uintptr)(__ccgo_up(aData + 2*8)))
}
Xsqlite3_free(tls, p)
nChange = int32(1)
}
jj = int32(1)
for {
if !(jj < nData-int32(2)) {
break
}
nChange = nChange + 1
Xsqlite3_bind_value(tls, pUp, jj+int32(2), **(**uintptr)(__ccgo_up(aData + uintptr(jj+int32(2))*8)))
goto _5
_5:
;
jj = jj + 1
}
if nChange != 0 {
Xsqlite3_step(tls, pUp)
**(**int32)(__ccgo_up(bp)) = Xsqlite3_reset(tls, pUp)
}
}
goto geopoly_update_end
geopoly_update_end:
;
_rtreeRelease(tls, pRtree)
return **(**int32)(__ccgo_up(bp))
}
// C documentation
//
// /*
// ** Interpret the given string as an auto-vacuum mode value.
// **
// ** The following strings, "none", "full" and "incremental" are
// ** acceptable, as are their numeric equivalents: 0, 1 and 2 respectively.
// */
func _getAutoVacuum(tls *libc.TLS, z uintptr) (r int32) {
var i, v1 int32
_, _ = i, v1
if 0 == _sqlite3StrICmp(tls, z, __ccgo_ts+8856) {
return BTREE_AUTOVACUUM_NONE
}
if 0 == _sqlite3StrICmp(tls, z, __ccgo_ts+19383) {
return int32(BTREE_AUTOVACUUM_FULL)
}
if 0 == _sqlite3StrICmp(tls, z, __ccgo_ts+19388) {
return int32(BTREE_AUTOVACUUM_INCR)
}
i = _sqlite3Atoi(tls, z)
if i >= 0 && i <= int32(2) {
v1 = i
} else {
v1 = 0
}
return libc.Int32FromUint8(libc.Uint8FromInt32(v1))
}
// C documentation
//
// /*
// ** 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(144)
defer tls.Free(144)
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)<iNodeSize is populated and SQLITE_OK returned.
// ** Otherwise, an SQLite error code is returned.
// **
// ** If this function is being called as part of an xConnect(), then the rtree
// ** table already exists. In this case the node-size is determined by inspecting
// ** the root node of the tree.
// **
// ** Otherwise, for an xCreate(), use 64 bytes less than the database page-size.
// ** This ensures that each node is stored on a single database page. If the
// ** database page-size is so large that more than RTREE_MAXCELLS entries
// ** would fit in a single node, use a smaller node-size.
// */
func _getNodeSize(tls *libc.TLS, db uintptr, pRtree uintptr, isCreate int32, pzErr uintptr) (r int32) {
bp := tls.Alloc(32)
defer tls.Free(32)
var rc int32
var zSql uintptr
var _ /* iPageSize at bp+0 */ int32
_, _ = rc, zSql
if isCreate != 0 {
**(**int32)(__ccgo_up(bp)) = 0
zSql = Xsqlite3_mprintf(tls, __ccgo_ts+29080, libc.VaList(bp+16, (*TRtree)(unsafe.Pointer(pRtree)).FzDb))
rc = _getIntFromStmt(tls, db, zSql, bp)
if rc == SQLITE_OK {
(*TRtree)(unsafe.Pointer(pRtree)).FiNodeSize = **(**int32)(__ccgo_up(bp)) - int32(64)
if int32(4)+libc.Int32FromUint8((*TRtree)(unsafe.Pointer(pRtree)).FnBytesPerCell)*int32(RTREE_MAXCELLS) < (*TRtree)(unsafe.Pointer(pRtree)).FiNodeSize {
(*TRtree)(unsafe.Pointer(pRtree)).FiNodeSize = int32(4) + libc.Int32FromUint8((*TRtree)(unsafe.Pointer(pRtree)).FnBytesPerCell)*int32(RTREE_MAXCELLS)
}
} else {
**(**uintptr)(__ccgo_up(pzErr)) = Xsqlite3_mprintf(tls, __ccgo_ts+3944, libc.VaList(bp+16, Xsqlite3_errmsg(tls, db)))
}
} else {
zSql = Xsqlite3_mprintf(tls, __ccgo_ts+29100, libc.VaList(bp+16, (*TRtree)(unsafe.Pointer(pRtree)).FzDb, (*TRtree)(unsafe.Pointer(pRtree)).FzName))
rc = _getIntFromStmt(tls, db, zSql, pRtree+32)
if rc != SQLITE_OK {
**(**uintptr)(__ccgo_up(pzErr)) = Xsqlite3_mprintf(tls, __ccgo_ts+3944, libc.VaList(bp+16, Xsqlite3_errmsg(tls, db)))
} else {
if (*TRtree)(unsafe.Pointer(pRtree)).FiNodeSize < libc.Int32FromInt32(512)-libc.Int32FromInt32(64) {
rc = libc.Int32FromInt32(SQLITE_CORRUPT) | libc.Int32FromInt32(1)< (*TPager)(unsafe.Pointer(pPager)).FmxPgno {
rc = int32(SQLITE_FULL)
if pgno <= (*TPager)(unsafe.Pointer(pPager)).FdbSize {
_sqlite3PcacheRelease(tls, pPg)
pPg = uintptr(0)
}
goto pager_acquire_err
}
if noContent != 0 {
/* Failure to set the bits in the InJournal bit-vectors is benign.
** It merely means that we might do some extra work to journal a
** page that does not need to be journaled. Nevertheless, be sure
** to test the case where a malloc error occurs while trying to set
** a bit in a bit vector.
*/
_sqlite3BeginBenignMalloc(tls)
if pgno <= (*TPager)(unsafe.Pointer(pPager)).FdbOrigSize {
_sqlite3BitvecSet(tls, (*TPager)(unsafe.Pointer(pPager)).FpInJournal, pgno)
}
_addToSavepointBitvecs(tls, pPager, pgno)
_sqlite3EndBenignMalloc(tls)
}
libc.X__builtin___memset_chk(tls, (*TPgHdr)(unsafe.Pointer(pPg)).FpData, 0, libc.Uint64FromInt64((*TPager)(unsafe.Pointer(pPager)).FpageSize), ^t__predefined_size_t(0))
} else {
**(**Tu32)(__ccgo_up(pPager + 248 + 1*4)) = **(**Tu32)(__ccgo_up(pPager + 248 + 1*4)) + 1
rc = _readDbPage(tls, pPg)
if rc != SQLITE_OK {
goto pager_acquire_err
}
}
}
return SQLITE_OK
goto pager_acquire_err
pager_acquire_err:
;
if pPg != 0 {
_sqlite3PcacheDrop(tls, pPg)
}
_pagerUnlockIfUnused(tls, pPager)
**(**uintptr)(__ccgo_up(ppPage)) = uintptr(0)
return rc
}
// C documentation
//
// /*
// ** Interpret the given string as a temp db location. Return 1 for file
// ** backed temporary databases, 2 for the Red-Black tree in memory database
// ** and 0 to use the compile-time default.
// */
func _getTempStore(tls *libc.TLS, z uintptr) (r int32) {
if int32(**(**int8)(__ccgo_up(z))) >= int32('0') && int32(**(**int8)(__ccgo_up(z))) <= int32('2') {
return int32(**(**int8)(__ccgo_up(z))) - int32('0')
} else {
if _sqlite3StrICmp(tls, z, __ccgo_ts+18343) == 0 {
return int32(1)
} else {
if _sqlite3StrICmp(tls, z, __ccgo_ts+19400) == 0 {
return int32(2)
} else {
return 0
}
}
}
return r
}
func _groupConcatInverse(tls *libc.TLS, context uintptr, argc int32, argv uintptr) {
var nVS int32
var pGCC uintptr
_, _ = nVS, pGCC
_ = argc /* Suppress unused parameter warning */
if Xsqlite3_value_type(tls, **(**uintptr)(__ccgo_up(argv))) == int32(SQLITE_NULL) {
return
}
pGCC = Xsqlite3_aggregate_context(tls, context, int32(48))
/* pGCC is always non-NULL since groupConcatStep() will have always
** run first to initialize it */
if pGCC != 0 { /* Number of characters to remove */
/* Must call sqlite3_value_text() to convert the argument into text prior
** to invoking sqlite3_value_bytes(), in case the text encoding is UTF16 */
Xsqlite3_value_text(tls, **(**uintptr)(__ccgo_up(argv)))
nVS = Xsqlite3_value_bytes(tls, **(**uintptr)(__ccgo_up(argv)))
**(**int32)(__ccgo_up(pGCC + 32)) -= int32(1)
if (*TGroupConcatCtx)(unsafe.Pointer(pGCC)).FpnSepLengths != uintptr(0) {
if (*TGroupConcatCtx)(unsafe.Pointer(pGCC)).FnAccum > 0 {
nVS = nVS + **(**int32)(__ccgo_up((*TGroupConcatCtx)(unsafe.Pointer(pGCC)).FpnSepLengths))
libc.X__builtin___memmove_chk(tls, (*TGroupConcatCtx)(unsafe.Pointer(pGCC)).FpnSepLengths, (*TGroupConcatCtx)(unsafe.Pointer(pGCC)).FpnSepLengths+uintptr(1)*4, libc.Uint64FromInt32((*TGroupConcatCtx)(unsafe.Pointer(pGCC)).FnAccum-libc.Int32FromInt32(1))*uint64(4), ^t__predefined_size_t(0))
}
} else {
/* If removing single accumulated string, harmlessly over-do. */
nVS = nVS + (*TGroupConcatCtx)(unsafe.Pointer(pGCC)).FnFirstSepLength
}
if nVS >= libc.Int32FromUint32((*TGroupConcatCtx)(unsafe.Pointer(pGCC)).Fstr.FnChar) {
(*TGroupConcatCtx)(unsafe.Pointer(pGCC)).Fstr.FnChar = uint32(0)
} else {
(*TGroupConcatCtx)(unsafe.Pointer(pGCC)).Fstr.FnChar -= libc.Uint32FromInt32(nVS)
libc.X__builtin___memmove_chk(tls, (*TGroupConcatCtx)(unsafe.Pointer(pGCC)).Fstr.FzText, (*TGroupConcatCtx)(unsafe.Pointer(pGCC)).Fstr.FzText+uintptr(nVS), uint64((*TGroupConcatCtx)(unsafe.Pointer(pGCC)).Fstr.FnChar), ^t__predefined_size_t(0))
}
if (*TGroupConcatCtx)(unsafe.Pointer(pGCC)).Fstr.FnChar == uint32(0) {
(*TGroupConcatCtx)(unsafe.Pointer(pGCC)).Fstr.FmxAlloc = uint32(0)
Xsqlite3_free(tls, (*TGroupConcatCtx)(unsafe.Pointer(pGCC)).FpnSepLengths)
(*TGroupConcatCtx)(unsafe.Pointer(pGCC)).FpnSepLengths = uintptr(0)
}
}
}
// C documentation
//
// /*
// ** Grow the db->aVTrans[] array so that there is room for at least one
// ** more v-table. Return SQLITE_NOMEM if a malloc fails, or SQLITE_OK otherwise.
// */
func _growVTrans(tls *libc.TLS, db uintptr) (r int32) {
var ARRAY_INCR int32
var aVTrans uintptr
var nBytes Tsqlite3_int64
_, _, _ = ARRAY_INCR, aVTrans, nBytes
ARRAY_INCR = int32(5)
/* Grow the sqlite3.aVTrans array if required */
if (*Tsqlite3)(unsafe.Pointer(db)).FnVTrans%ARRAY_INCR == 0 {
nBytes = libc.Int64FromUint64(uint64(8) * libc.Uint64FromInt64(int64((*Tsqlite3)(unsafe.Pointer(db)).FnVTrans)+int64(ARRAY_INCR)))
aVTrans = _sqlite3DbRealloc(tls, db, (*Tsqlite3)(unsafe.Pointer(db)).FaVTrans, libc.Uint64FromInt64(nBytes))
if !(aVTrans != 0) {
return int32(SQLITE_NOMEM)
}
libc.X__builtin___memset_chk(tls, aVTrans+uintptr((*Tsqlite3)(unsafe.Pointer(db)).FnVTrans)*8, 0, uint64(8)*libc.Uint64FromInt32(ARRAY_INCR), ^t__predefined_size_t(0))
(*Tsqlite3)(unsafe.Pointer(db)).FaVTrans = aVTrans
}
return SQLITE_OK
}
// C documentation
//
// /*
// ** Transfer eligible terms from the HAVING clause of a query, which is
// ** processed after grouping, to the WHERE clause, which is processed before
// ** grouping. For example, the query:
// **
// ** SELECT * FROM WHERE a=? GROUP BY b HAVING b=? AND c=?
// **
// ** can be rewritten as:
// **
// ** SELECT * FROM WHERE a=? AND b=? GROUP BY b HAVING c=?
// **
// ** A term of the HAVING expression is eligible for transfer if it consists
// ** entirely of constants and expressions that are also GROUP BY terms that
// ** use the "BINARY" collation sequence.
// */
func _havingToWhere(tls *libc.TLS, pParse uintptr, p uintptr) {
bp := tls.Alloc(48)
defer tls.Free(48)
var _ /* sWalker at bp+0 */ TWalker
libc.X__builtin___memset_chk(tls, bp, 0, uint64(48), ^t__predefined_size_t(0))
(**(**TWalker)(__ccgo_up(bp))).FpParse = pParse
(**(**TWalker)(__ccgo_up(bp))).FxExprCallback = __ccgo_fp(_havingToWhereExprCb)
*(*uintptr)(unsafe.Pointer(bp + 40)) = p
_sqlite3WalkExpr(tls, bp, (*TSelect)(unsafe.Pointer(p)).FpHaving)
}
func _incrAggFunctionDepth(tls *libc.TLS, pExpr uintptr, N int32) {
bp := tls.Alloc(48)
defer tls.Free(48)
var _ /* w at bp+0 */ TWalker
if N > 0 {
libc.X__builtin___memset_chk(tls, bp, 0, uint64(48), ^t__predefined_size_t(0))
(**(**TWalker)(__ccgo_up(bp))).FxExprCallback = __ccgo_fp(_incrAggDepth)
*(*int32)(unsafe.Pointer(bp + 40)) = N
_sqlite3WalkExpr(tls, bp, pExpr)
}
}
// C documentation
//
// /*
// ** Insert a new cell on pPage at cell index "i". pCell points to the
// ** content of the cell.
// **
// ** If the cell content will fit on the page, then put it there. If it
// ** will not fit, then make a copy of the cell content into pTemp if
// ** pTemp is not null. Regardless of pTemp, allocate a new entry
// ** in pPage->apOvfl[] and make it point to the cell content (either
// ** in pTemp or the original pCell) and also record its index.
// ** Allocating a new entry in pPage->aCell[] implies that
// ** pPage->nOverflow is incremented.
// **
// ** The insertCellFast() routine below works exactly the same as
// ** insertCell() except that it lacks the pTemp and iChild parameters
// ** which are assumed zero. Other than that, the two routines are the
// ** same.
// **
// ** Fixes or enhancements to this routine should be reflected in
// ** insertCellFast()!
// */
func _insertCell(tls *libc.TLS, pPage uintptr, i int32, pCell uintptr, sz int32, pTemp uintptr, iChild TPgno) (r int32) {
bp := tls.Alloc(16)
defer tls.Free(16)
var data, pIns, v2 uintptr
var j, rc int32
var v1 Tu8
var _ /* idx at bp+0 */ int32
var _ /* rc2 at bp+4 */ int32
_, _, _, _, _, _ = data, j, pIns, rc, v1, v2
**(**int32)(__ccgo_up(bp)) = 0 /* The point in pPage->aCellIdx[] where no cell inserted */
if (*TMemPage)(unsafe.Pointer(pPage)).FnOverflow != 0 || sz+int32(2) > (*TMemPage)(unsafe.Pointer(pPage)).FnFree {
if pTemp != 0 {
libc.X__builtin___memcpy_chk(tls, pTemp, pCell, libc.Uint64FromInt32(sz), ^t__predefined_size_t(0))
pCell = pTemp
}
_sqlite3Put4byte(tls, pCell, iChild)
v2 = pPage + 12
v1 = *(*Tu8)(unsafe.Pointer(v2))
*(*Tu8)(unsafe.Pointer(v2)) = *(*Tu8)(unsafe.Pointer(v2)) + 1
j = libc.Int32FromUint8(v1)
/* Comparison against ArraySize-1 since we hold back one extra slot
** as a contingency. In other words, never need more than 3 overflow
** slots but 4 are allocated, just to be safe. */
**(**uintptr)(__ccgo_up(pPage + 40 + uintptr(j)*8)) = pCell
**(**Tu16)(__ccgo_up(pPage + 28 + uintptr(j)*2)) = libc.Uint16FromInt32(i)
/* When multiple overflows occur, they are always sequential and in
** sorted order. This invariants arise because multiple overflows can
** only occur when inserting divider cells into the parent page during
** balancing, and the dividers are adjacent and sorted.
*/
/* Overflows in sorted order */
/* Overflows are sequential */
} else {
rc = _sqlite3PagerWrite(tls, (*TMemPage)(unsafe.Pointer(pPage)).FpDbPage)
if rc != SQLITE_OK {
return rc
}
data = (*TMemPage)(unsafe.Pointer(pPage)).FaData
rc = _allocateSpace(tls, pPage, sz, bp)
if rc != 0 {
return rc
}
/* The allocateSpace() routine guarantees the following properties
** if it returns successfully */
**(**int32)(__ccgo_up(pPage + 20)) -= libc.Int32FromUint16(libc.Uint16FromInt32(libc.Int32FromInt32(2) + sz))
/* In a corrupt database where an entry in the cell index section of
** a btree page has a value of 3 or less, the pCell value might point
** as many as 4 bytes in front of the start of the aData buffer for
** the source page. Make sure this does not cause problems by not
** reading the first 4 bytes */
libc.X__builtin___memcpy_chk(tls, data+uintptr(**(**int32)(__ccgo_up(bp))+int32(4)), pCell+uintptr(4), libc.Uint64FromInt32(sz-int32(4)), ^t__predefined_size_t(0))
_sqlite3Put4byte(tls, data+uintptr(**(**int32)(__ccgo_up(bp))), iChild)
pIns = (*TMemPage)(unsafe.Pointer(pPage)).FaCellIdx + uintptr(i*int32(2))
libc.X__builtin___memmove_chk(tls, pIns+uintptr(2), pIns, libc.Uint64FromInt32(int32(2)*(libc.Int32FromUint16((*TMemPage)(unsafe.Pointer(pPage)).FnCell)-i)), ^t__predefined_size_t(0))
**(**Tu8)(__ccgo_up(pIns)) = libc.Uint8FromInt32(**(**int32)(__ccgo_up(bp)) >> libc.Int32FromInt32(8))
**(**Tu8)(__ccgo_up(pIns + 1)) = libc.Uint8FromInt32(**(**int32)(__ccgo_up(bp)))
(*TMemPage)(unsafe.Pointer(pPage)).FnCell = (*TMemPage)(unsafe.Pointer(pPage)).FnCell + 1
/* increment the cell count */
v2 = data + uintptr(libc.Int32FromUint8((*TMemPage)(unsafe.Pointer(pPage)).FhdrOffset)+int32(4))
*(*Tu8)(unsafe.Pointer(v2)) = *(*Tu8)(unsafe.Pointer(v2)) + 1
v1 = *(*Tu8)(unsafe.Pointer(v2))
if libc.Int32FromUint8(v1) == 0 {
**(**Tu8)(__ccgo_up(data + uintptr(libc.Int32FromUint8((*TMemPage)(unsafe.Pointer(pPage)).FhdrOffset)+int32(3)))) = **(**Tu8)(__ccgo_up(data + uintptr(libc.Int32FromUint8((*TMemPage)(unsafe.Pointer(pPage)).FhdrOffset)+int32(3)))) + 1
}
if (*TBtShared)(unsafe.Pointer((*TMemPage)(unsafe.Pointer(pPage)).FpBt)).FautoVacuum != 0 {
**(**int32)(__ccgo_up(bp + 4)) = SQLITE_OK
/* The cell may contain a pointer to an overflow page. If so, write
** the entry for the overflow page into the pointer map.
*/
_ptrmapPutOvflPtr(tls, pPage, pPage, pCell, bp+4)
if **(**int32)(__ccgo_up(bp + 4)) != 0 {
return **(**int32)(__ccgo_up(bp + 4))
}
}
}
return SQLITE_OK
}
// C documentation
//
// /*
// ** This variant of insertCell() assumes that the pTemp and iChild
// ** parameters are both zero. Use this variant in sqlite3BtreeInsert()
// ** for performance improvement, and also so that this variant is only
// ** called from that one place, and is thus inlined, and thus runs must
// ** faster.
// **
// ** Fixes or enhancements to this routine should be reflected into
// ** the insertCell() routine.
// */
func _insertCellFast(tls *libc.TLS, pPage uintptr, i int32, pCell uintptr, sz int32) (r int32) {
bp := tls.Alloc(16)
defer tls.Free(16)
var data, pIns, v2 uintptr
var j, rc int32
var v1 Tu8
var _ /* idx at bp+0 */ int32
var _ /* rc2 at bp+4 */ int32
_, _, _, _, _, _ = data, j, pIns, rc, v1, v2
**(**int32)(__ccgo_up(bp)) = 0 /* The point in pPage->aCellIdx[] where no cell inserted */
if sz+int32(2) > (*TMemPage)(unsafe.Pointer(pPage)).FnFree {
v2 = pPage + 12
v1 = *(*Tu8)(unsafe.Pointer(v2))
*(*Tu8)(unsafe.Pointer(v2)) = *(*Tu8)(unsafe.Pointer(v2)) + 1
j = libc.Int32FromUint8(v1)
/* Comparison against ArraySize-1 since we hold back one extra slot
** as a contingency. In other words, never need more than 3 overflow
** slots but 4 are allocated, just to be safe. */
**(**uintptr)(__ccgo_up(pPage + 40 + uintptr(j)*8)) = pCell
**(**Tu16)(__ccgo_up(pPage + 28 + uintptr(j)*2)) = libc.Uint16FromInt32(i)
/* When multiple overflows occur, they are always sequential and in
** sorted order. This invariants arise because multiple overflows can
** only occur when inserting divider cells into the parent page during
** balancing, and the dividers are adjacent and sorted.
*/
/* Overflows in sorted order */
/* Overflows are sequential */
} else {
rc = _sqlite3PagerWrite(tls, (*TMemPage)(unsafe.Pointer(pPage)).FpDbPage)
if rc != SQLITE_OK {
return rc
}
data = (*TMemPage)(unsafe.Pointer(pPage)).FaData
rc = _allocateSpace(tls, pPage, sz, bp)
if rc != 0 {
return rc
}
/* The allocateSpace() routine guarantees the following properties
** if it returns successfully */
**(**int32)(__ccgo_up(pPage + 20)) -= libc.Int32FromUint16(libc.Uint16FromInt32(libc.Int32FromInt32(2) + sz))
libc.X__builtin___memcpy_chk(tls, data+uintptr(**(**int32)(__ccgo_up(bp))), pCell, libc.Uint64FromInt32(sz), ^t__predefined_size_t(0))
pIns = (*TMemPage)(unsafe.Pointer(pPage)).FaCellIdx + uintptr(i*int32(2))
libc.X__builtin___memmove_chk(tls, pIns+uintptr(2), pIns, libc.Uint64FromInt32(int32(2)*(libc.Int32FromUint16((*TMemPage)(unsafe.Pointer(pPage)).FnCell)-i)), ^t__predefined_size_t(0))
**(**Tu8)(__ccgo_up(pIns)) = libc.Uint8FromInt32(**(**int32)(__ccgo_up(bp)) >> libc.Int32FromInt32(8))
**(**Tu8)(__ccgo_up(pIns + 1)) = libc.Uint8FromInt32(**(**int32)(__ccgo_up(bp)))
(*TMemPage)(unsafe.Pointer(pPage)).FnCell = (*TMemPage)(unsafe.Pointer(pPage)).FnCell + 1
/* increment the cell count */
v2 = data + uintptr(libc.Int32FromUint8((*TMemPage)(unsafe.Pointer(pPage)).FhdrOffset)+int32(4))
*(*Tu8)(unsafe.Pointer(v2)) = *(*Tu8)(unsafe.Pointer(v2)) + 1
v1 = *(*Tu8)(unsafe.Pointer(v2))
if libc.Int32FromUint8(v1) == 0 {
**(**Tu8)(__ccgo_up(data + uintptr(libc.Int32FromUint8((*TMemPage)(unsafe.Pointer(pPage)).FhdrOffset)+int32(3)))) = **(**Tu8)(__ccgo_up(data + uintptr(libc.Int32FromUint8((*TMemPage)(unsafe.Pointer(pPage)).FhdrOffset)+int32(3)))) + 1
}
if (*TBtShared)(unsafe.Pointer((*TMemPage)(unsafe.Pointer(pPage)).FpBt)).FautoVacuum != 0 {
**(**int32)(__ccgo_up(bp + 4)) = SQLITE_OK
/* The cell may contain a pointer to an overflow page. If so, write
** the entry for the overflow page into the pointer map.
*/
_ptrmapPutOvflPtr(tls, pPage, pPage, pCell, bp+4)
if **(**int32)(__ccgo_up(bp + 4)) != 0 {
return **(**int32)(__ccgo_up(bp + 4))
}
}
}
return SQLITE_OK
}
/*
** The following parameters determine how many adjacent pages get involved
** in a balancing operation. NN is the number of neighbors on either side
** of the page that participate in the balancing operation. NB is the
** total number of pages that participate, including the target page and
** NN neighbors on either side.
**
** The minimum value of NN is 1 (of course). Increasing NN above 1
** (to 2 or 3) gives a modest improvement in SELECT and DELETE performance
** in exchange for a larger degradation in INSERT and UPDATE performance.
** The value of NN appears to give the best results overall.
**
** (Later:) The description above makes it seem as if these values are
** tunable - as if you could change them and recompile and it would all work.
** But that is unlikely. NB has been 3 since the inception of SQLite and
** we have never tested any other value.
*/
// C documentation
//
// /*
// ** Invalidate temp storage, either when the temp storage is changed
// ** from default, or when 'file' and the temp_store_directory has changed
// */
func _invalidateTempStorage(tls *libc.TLS, pParse uintptr) (r int32) {
var db uintptr
_ = db
db = (*TParse)(unsafe.Pointer(pParse)).Fdb
if (**(**TDb)(__ccgo_up((*Tsqlite3)(unsafe.Pointer(db)).FaDb + 1*32))).FpBt != uintptr(0) {
if !((*Tsqlite3)(unsafe.Pointer(db)).FautoCommit != 0) || _sqlite3BtreeTxnState(tls, (**(**TDb)(__ccgo_up((*Tsqlite3)(unsafe.Pointer(db)).FaDb + 1*32))).FpBt) != SQLITE_TXN_NONE {
_sqlite3ErrorMsg(tls, pParse, __ccgo_ts+19407, 0)
return int32(SQLITE_ERROR)
}
_sqlite3BtreeClose(tls, (**(**TDb)(__ccgo_up((*Tsqlite3)(unsafe.Pointer(db)).FaDb + 1*32))).FpBt)
(**(**TDb)(__ccgo_up((*Tsqlite3)(unsafe.Pointer(db)).FaDb + 1*32))).FpBt = uintptr(0)
_sqlite3ResetAllSchemasOfConnection(tls, db)
}
return SQLITE_OK
}
// C documentation
//
// /*
// ** Parameter zName is the name of a table that is about to be altered
// ** (either with ALTER TABLE ... RENAME TO or ALTER TABLE ... ADD COLUMN).
// ** If the table is a system table, this function leaves an error message
// ** in pParse->zErr (system tables may not be altered) and returns non-zero.
// **
// ** Or, if zName is not a system table, zero is returned.
// */
func _isAlterableTable(tls *libc.TLS, pParse uintptr, pTab uintptr) (r int32) {
bp := tls.Alloc(16)
defer tls.Free(16)
if 0 == Xsqlite3_strnicmp(tls, (*TTable)(unsafe.Pointer(pTab)).FzName, __ccgo_ts+7104, int32(7)) || (*TTable)(unsafe.Pointer(pTab)).FtabFlags&uint32(TF_Eponymous) != uint32(0) || (*TTable)(unsafe.Pointer(pTab)).FtabFlags&uint32(TF_Shadow) != uint32(0) && _sqlite3ReadOnlyShadowTables(tls, (*TParse)(unsafe.Pointer(pParse)).Fdb) != 0 {
_sqlite3ErrorMsg(tls, pParse, __ccgo_ts+8991, libc.VaList(bp+8, (*TTable)(unsafe.Pointer(pTab)).FzName))
return int32(1)
}
return 0
}
// C documentation
//
// /*
// ** Return true if the pExpr term from the RETURNING clause argument
// ** list is of the form "*". Raise an error if the terms if of the
// ** form "table.*".
// */
func _isAsteriskTerm(tls *libc.TLS, pParse uintptr, pTerm uintptr) (r int32) {
if libc.Int32FromUint8((*TExpr)(unsafe.Pointer(pTerm)).Fop) == int32(TK_ASTERISK) {
return int32(1)
}
if libc.Int32FromUint8((*TExpr)(unsafe.Pointer(pTerm)).Fop) != int32(TK_DOT) {
return 0
}
if libc.Int32FromUint8((*TExpr)(unsafe.Pointer((*TExpr)(unsafe.Pointer(pTerm)).FpRight)).Fop) != int32(TK_ASTERISK) {
return 0
}
_sqlite3ErrorMsg(tls, pParse, __ccgo_ts+22917, 0)
return int32(1)
}
// C documentation
//
// /*
// ** Process time function arguments. argv[0] is a date-time stamp.
// ** argv[1] and following are modifiers. Parse them all and write
// ** the resulting time into the DateTime structure p. Return 0
// ** on success and 1 if there are any errors.
// **
// ** If there are zero parameters (if even argv[0] is undefined)
// ** then assume a default value of "now" for argv[0].
// */
func _isDate(tls *libc.TLS, context uintptr, argc int32, argv uintptr, p uintptr) (r int32) {
var eType, i, n, v1 int32
var z uintptr
_, _, _, _, _ = eType, i, n, z, v1
libc.X__builtin___memset_chk(tls, p, 0, uint64(48), ^t__predefined_size_t(0))
if argc == 0 {
if !(_sqlite3NotPureFunc(tls, context) != 0) {
return int32(1)
}
return _setDateTimeToCurrent(tls, context, p)
}
v1 = Xsqlite3_value_type(tls, **(**uintptr)(__ccgo_up(argv)))
eType = v1
if v1 == int32(SQLITE_FLOAT) || eType == int32(SQLITE_INTEGER) {
_setRawDateNumber(tls, p, Xsqlite3_value_double(tls, **(**uintptr)(__ccgo_up(argv))))
} else {
z = Xsqlite3_value_text(tls, **(**uintptr)(__ccgo_up(argv)))
if !(z != 0) || _parseDateOrTime(tls, context, z, p) != 0 {
return int32(1)
}
}
i = int32(1)
for {
if !(i < argc) {
break
}
z = Xsqlite3_value_text(tls, **(**uintptr)(__ccgo_up(argv + uintptr(i)*8)))
n = Xsqlite3_value_bytes(tls, **(**uintptr)(__ccgo_up(argv + uintptr(i)*8)))
if z == uintptr(0) || _parseModifier(tls, context, z, n, p, i) != 0 {
return int32(1)
}
goto _2
_2:
;
i = i + 1
}
_computeJD(tls, p)
if int32(uint32(*(*uint8)(unsafe.Pointer(p + 44))&0x2>>1)) != 0 || !(_validJulianDay(tls, (*TDateTime)(unsafe.Pointer(p)).FiJD) != 0) {
return int32(1)
}
if argc == int32(1) && (*TDateTime)(unsafe.Pointer(p)).FvalidYMD != 0 && (*TDateTime)(unsafe.Pointer(p)).FD > int32(28) {
/* Make sure a YYYY-MM-DD is normalized.
** Example: 2023-02-31 -> 2023-03-03 */
(*TDateTime)(unsafe.Pointer(p)).FvalidYMD = 0
}
return 0
}
/*
** The following routines implement the various date and time functions
** of SQLite.
*/
// C documentation
//
// /*
// ** Parameter pTab is the subject of an ALTER TABLE ... RENAME COLUMN
// ** command. This function checks if the table is a view or virtual
// ** table (columns of views or virtual tables may not be renamed). If so,
// ** it loads an error message into pParse and returns non-zero.
// **
// ** Or, if pTab is not a view or virtual table, zero is returned.
// */
func _isRealTable(tls *libc.TLS, pParse uintptr, pTab uintptr, iOp int32) (r int32) {
bp := tls.Alloc(32)
defer tls.Free(32)
var azMsg [3]uintptr
var zType uintptr
_, _ = azMsg, zType
zType = uintptr(0)
if libc.Int32FromUint8((*TTable)(unsafe.Pointer(pTab)).FeTabType) == int32(TABTYP_VIEW) {
zType = __ccgo_ts + 11463
}
if libc.Int32FromUint8((*TTable)(unsafe.Pointer(pTab)).FeTabType) == int32(TABTYP_VTAB) {
zType = __ccgo_ts + 11468
}
if zType != 0 {
azMsg = [3]uintptr{
0: __ccgo_ts + 11482,
1: __ccgo_ts + 11500,
2: __ccgo_ts + 11517,
}
_sqlite3ErrorMsg(tls, pParse, __ccgo_ts+11537, libc.VaList(bp+8, azMsg[iOp], zType, (*TTable)(unsafe.Pointer(pTab)).FzName))
return int32(1)
}
return 0
}
// C documentation
//
// /*
// ** Return TRUE (non-zero) if zTab is a valid name for the schema table pTab.
// */
func _isValidSchemaTableName(tls *libc.TLS, zTab uintptr, pTab uintptr, zDb uintptr) (r int32) {
var zLegacy uintptr
_ = zLegacy
if Xsqlite3_strnicmp(tls, zTab, __ccgo_ts+7104, int32(7)) != 0 {
return 0
}
zLegacy = (*TTable)(unsafe.Pointer(pTab)).FzName
if libc.Xstrcmp(tls, zLegacy+uintptr(7), __ccgo_ts+7112+7) == 0 {
if _sqlite3StrICmp(tls, zTab+uintptr(7), __ccgo_ts+7131+7) == 0 {
return int32(1)
}
if zDb == uintptr(0) {
return 0
}
if _sqlite3StrICmp(tls, zTab+uintptr(7), __ccgo_ts+6632+7) == 0 {
return int32(1)
}
if _sqlite3StrICmp(tls, zTab+uintptr(7), __ccgo_ts+7150+7) == 0 {
return int32(1)
}
} else {
if _sqlite3StrICmp(tls, zTab+uintptr(7), __ccgo_ts+7150+7) == 0 {
return int32(1)
}
}
return 0
}
// 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+56, __ccgo_ts+27336, 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+192, (*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+56, __ccgo_ts+27343, libc.VaList(bp+16, **(**Tu32)(__ccgo_up(bp)), z))
} else {
_jsonPrintf(tls, libc.Int32FromUint32(**(**Tu32)(__ccgo_up(bp))+uint32(2)), p+56, __ccgo_ts+27351, libc.VaList(bp+16, **(**Tu32)(__ccgo_up(bp)), z))
}
}
}
func _jsonAppendRaw(tls *libc.TLS, p uintptr, zIn uintptr, N Tu32) {
if N == uint32(0) {
return
}
if uint64(N)+(*TJsonString)(unsafe.Pointer(p)).FnUsed >= (*TJsonString)(unsafe.Pointer(p)).FnAlloc {
_jsonStringExpandAndAppend(tls, p, zIn, N)
} else {
libc.X__builtin___memcpy_chk(tls, (*TJsonString)(unsafe.Pointer(p)).FzBuf+uintptr((*TJsonString)(unsafe.Pointer(p)).FnUsed), zIn, uint64(N), ^t__predefined_size_t(0))
**(**Tu64)(__ccgo_up(p + 24)) += uint64(N)
}
}
func _jsonAppendRawNZ(tls *libc.TLS, p uintptr, zIn uintptr, N Tu32) {
if uint64(N)+(*TJsonString)(unsafe.Pointer(p)).FnUsed >= (*TJsonString)(unsafe.Pointer(p)).FnAlloc {
_jsonStringExpandAndAppend(tls, p, zIn, N)
} else {
libc.X__builtin___memcpy_chk(tls, (*TJsonString)(unsafe.Pointer(p)).FzBuf+uintptr((*TJsonString)(unsafe.Pointer(p)).FnUsed), zIn, uint64(N), ^t__predefined_size_t(0))
**(**Tu64)(__ccgo_up(p + 24)) += uint64(N)
}
}
// C documentation
//
// /*
// ** Append an sqlite3_value (such as a function parameter) to the JSON
// ** string under construction in p.
// */
func _jsonAppendSqlValue(tls *libc.TLS, p uintptr, pValue uintptr) {
bp := tls.Alloc(96)
defer tls.Free(96)
var n, n1 Tu32
var z, z1 uintptr
var _ /* px at bp+0 */ TJsonParse
_, _, _, _ = n, n1, z, z1
switch Xsqlite3_value_type(tls, pValue) {
case int32(SQLITE_NULL):
_jsonAppendRawNZ(tls, p, __ccgo_ts+1688, uint32(4))
case int32(SQLITE_FLOAT):
_jsonPrintf(tls, int32(100), p, __ccgo_ts+16907, libc.VaList(bp+80, Xsqlite3_value_double(tls, pValue)))
case int32(SQLITE_INTEGER):
z = Xsqlite3_value_text(tls, pValue)
n = libc.Uint32FromInt32(Xsqlite3_value_bytes(tls, pValue))
_jsonAppendRaw(tls, p, z, n)
case int32(SQLITE_TEXT):
z1 = Xsqlite3_value_text(tls, pValue)
n1 = libc.Uint32FromInt32(Xsqlite3_value_bytes(tls, pValue))
if Xsqlite3_value_subtype(tls, pValue) == uint32(JSON_SUBTYPE) {
_jsonAppendRaw(tls, p, z1, n1)
} else {
_jsonAppendString(tls, p, z1, n1)
}
default:
libc.X__builtin___memset_chk(tls, bp, 0, uint64(72), ^t__predefined_size_t(0))
if _jsonArgIsJsonb(tls, pValue, bp) != 0 {
_jsonTranslateBlobToText(tls, bp, uint32(0), p)
} else {
if libc.Int32FromUint8((*TJsonString)(unsafe.Pointer(p)).FeErr) == 0 {
Xsqlite3_result_error(tls, (*TJsonString)(unsafe.Pointer(p)).FpCtx, __ccgo_ts+26824, -int32(1))
(*TJsonString)(unsafe.Pointer(p)).FeErr = uint8(JSTRING_ERR)
_jsonStringReset(tls, p)
}
}
break
}
}
// C documentation
//
// /* Append the N-byte string in zIn to the end of the JsonString string
// ** under construction. Enclose the string in double-quotes ("...") and
// ** escape any double-quotes or backslash characters contained within the
// ** string.
// **
// ** This routine is a high-runner. There is a measurable performance
// ** increase associated with unwinding the jsonIsOk[] loop.
// */
func _jsonAppendString(tls *libc.TLS, p uintptr, zIn uintptr, N Tu32) {
var c Tu8
var k Tu32
var z, v2 uintptr
var v1 Tu64
_, _, _, _, _ = c, k, z, v1, v2
z = zIn
if z == uintptr(0) {
return
}
if uint64(N)+(*TJsonString)(unsafe.Pointer(p)).FnUsed+uint64(2) >= (*TJsonString)(unsafe.Pointer(p)).FnAlloc && _jsonStringGrow(tls, p, N+uint32(2)) != 0 {
return
}
v2 = p + 24
v1 = *(*Tu64)(unsafe.Pointer(v2))
*(*Tu64)(unsafe.Pointer(v2)) = *(*Tu64)(unsafe.Pointer(v2)) + 1
**(**int8)(__ccgo_up((*TJsonString)(unsafe.Pointer(p)).FzBuf + uintptr(v1))) = int8('"')
for int32(1) != 0 {
k = uint32(0)
/* The following while() is the 4-way unwound equivalent of
**
** while( k= N {
for k < N && _jsonIsOk[**(**Tu8)(__ccgo_up(z + uintptr(k)))] != 0 {
k = k + 1
}
break
}
if !(_jsonIsOk[**(**Tu8)(__ccgo_up(z + uintptr(k)))] != 0) {
break
}
if !(_jsonIsOk[**(**Tu8)(__ccgo_up(z + uintptr(k+uint32(1))))] != 0) {
k = k + uint32(1)
break
}
if !(_jsonIsOk[**(**Tu8)(__ccgo_up(z + uintptr(k+uint32(2))))] != 0) {
k = k + uint32(2)
break
}
if !(_jsonIsOk[**(**Tu8)(__ccgo_up(z + uintptr(k+uint32(3))))] != 0) {
k = k + uint32(3)
break
} else {
k = k + uint32(4)
}
}
if k >= N {
if k > uint32(0) {
libc.X__builtin___memcpy_chk(tls, (*TJsonString)(unsafe.Pointer(p)).FzBuf+uintptr((*TJsonString)(unsafe.Pointer(p)).FnUsed), z, uint64(k), ^t__predefined_size_t(0))
**(**Tu64)(__ccgo_up(p + 24)) += uint64(k)
}
break
}
if k > uint32(0) {
libc.X__builtin___memcpy_chk(tls, (*TJsonString)(unsafe.Pointer(p)).FzBuf+uintptr((*TJsonString)(unsafe.Pointer(p)).FnUsed), z, uint64(k), ^t__predefined_size_t(0))
**(**Tu64)(__ccgo_up(p + 24)) += uint64(k)
z = z + uintptr(k)
N = N - k
}
c = **(**Tu8)(__ccgo_up(z))
if libc.Int32FromUint8(c) == int32('"') || libc.Int32FromUint8(c) == int32('\\') {
if (*TJsonString)(unsafe.Pointer(p)).FnUsed+uint64(N)+uint64(3) > (*TJsonString)(unsafe.Pointer(p)).FnAlloc && _jsonStringGrow(tls, p, N+uint32(3)) != 0 {
return
}
v2 = p + 24
v1 = *(*Tu64)(unsafe.Pointer(v2))
*(*Tu64)(unsafe.Pointer(v2)) = *(*Tu64)(unsafe.Pointer(v2)) + 1
**(**int8)(__ccgo_up((*TJsonString)(unsafe.Pointer(p)).FzBuf + uintptr(v1))) = int8('\\')
v2 = p + 24
v1 = *(*Tu64)(unsafe.Pointer(v2))
*(*Tu64)(unsafe.Pointer(v2)) = *(*Tu64)(unsafe.Pointer(v2)) + 1
**(**int8)(__ccgo_up((*TJsonString)(unsafe.Pointer(p)).FzBuf + uintptr(v1))) = libc.Int8FromUint8(c)
} else {
if libc.Int32FromUint8(c) == int32('\'') {
v2 = p + 24
v1 = *(*Tu64)(unsafe.Pointer(v2))
*(*Tu64)(unsafe.Pointer(v2)) = *(*Tu64)(unsafe.Pointer(v2)) + 1
**(**int8)(__ccgo_up((*TJsonString)(unsafe.Pointer(p)).FzBuf + uintptr(v1))) = libc.Int8FromUint8(c)
} else {
if (*TJsonString)(unsafe.Pointer(p)).FnUsed+uint64(N)+uint64(7) > (*TJsonString)(unsafe.Pointer(p)).FnAlloc && _jsonStringGrow(tls, p, N+uint32(7)) != 0 {
return
}
_jsonAppendControlChar(tls, p, c)
}
}
z = z + 1
N = N - 1
}
v2 = p + 24
v1 = *(*Tu64)(unsafe.Pointer(v2))
*(*Tu64)(unsafe.Pointer(v2)) = *(*Tu64)(unsafe.Pointer(v2)) + 1
**(**int8)(__ccgo_up((*TJsonString)(unsafe.Pointer(p)).FzBuf + uintptr(v1))) = int8('"')
}
func _jsonArrayCompute(tls *libc.TLS, ctx uintptr, isFinal int32) {
var flags int32
var pStr uintptr
var v1 Tsqlite3_destructor_type
_, _, _ = flags, pStr, v1
flags = int32(int64(Xsqlite3_user_data(tls, ctx)))
pStr = Xsqlite3_aggregate_context(tls, ctx, 0)
if pStr != 0 {
(*TJsonString)(unsafe.Pointer(pStr)).FpCtx = ctx
_jsonAppendRawNZ(tls, pStr, __ccgo_ts+5660, uint32(2))
_jsonStringTrimOneChar(tls, pStr)
if (*TJsonString)(unsafe.Pointer(pStr)).FeErr != 0 {
_jsonReturnString(tls, pStr, uintptr(0), uintptr(0))
return
} else {
if flags&int32(JSON_BLOB) != 0 {
_jsonReturnStringAsBlob(tls, pStr)
if isFinal != 0 {
if !((*TJsonString)(unsafe.Pointer(pStr)).FbStatic != 0) {
_sqlite3RCStrUnref(tls, (*TJsonString)(unsafe.Pointer(pStr)).FzBuf)
}
} else {
_jsonStringTrimOneChar(tls, pStr)
}
return
} else {
if isFinal != 0 {
if (*TJsonString)(unsafe.Pointer(pStr)).FbStatic != 0 {
v1 = uintptr(-libc.Int32FromInt32(1))
} else {
v1 = __ccgo_fp(_sqlite3RCStrUnref)
}
Xsqlite3_result_text(tls, ctx, (*TJsonString)(unsafe.Pointer(pStr)).FzBuf, libc.Int32FromUint64((*TJsonString)(unsafe.Pointer(pStr)).FnUsed), v1)
(*TJsonString)(unsafe.Pointer(pStr)).FbStatic = uint8(1)
} else {
Xsqlite3_result_text(tls, ctx, (*TJsonString)(unsafe.Pointer(pStr)).FzBuf, libc.Int32FromUint64((*TJsonString)(unsafe.Pointer(pStr)).FnUsed), uintptr(-libc.Int32FromInt32(1)))
_jsonStringTrimOneChar(tls, pStr)
}
}
}
} else {
if flags&int32(JSON_BLOB) != 0 {
Xsqlite3_result_blob(tls, ctx, uintptr(unsafe.Pointer(&_emptyArray)), int32(1), libc.UintptrFromInt32(0))
} else {
Xsqlite3_result_text(tls, ctx, __ccgo_ts+27245, int32(2), libc.UintptrFromInt32(0))
}
}
Xsqlite3_result_subtype(tls, ctx, uint32(JSON_SUBTYPE))
}
// 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*8)))
if zPath == uintptr(0) {
_jsonParseFree(tls, p)
return
}
if int32(**(**int8)(__ccgo_up(zPath))) == int32('$') {
v1 = zPath + uintptr(1)
} else {
v1 = __ccgo_ts + 27063
}
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
//
// /*
// ** Generate a path error.
// **
// ** The specifics of the error are determined by the rc argument.
// **
// ** rc error
// ** ----------------- ----------------------
// ** JSON_LOOKUP_ARRAY "not an array"
// ** JSON_LOOKUP_TOODEEP "JSON nested too deep"
// ** JSON_LOOKUP_ERROR "malformed JSON"
// ** otherwise... "bad JSON path"
// **
// ** If ctx is not NULL then push the error message into ctx and return NULL.
// ** If ctx is NULL, then return the text of the error message.
// */
func _jsonBadPathError(tls *libc.TLS, ctx uintptr, zPath uintptr, rc int32) (r uintptr) {
bp := tls.Alloc(16)
defer tls.Free(16)
var zMsg uintptr
_ = zMsg
if rc == libc.Int32FromUint32(JSON_LOOKUP_NOTARRAY) {
zMsg = Xsqlite3_mprintf(tls, __ccgo_ts+27001, libc.VaList(bp+8, zPath))
} else {
if rc == libc.Int32FromUint32(JSON_LOOKUP_ERROR) {
zMsg = Xsqlite3_mprintf(tls, __ccgo_ts+26853, 0)
} else {
if rc == libc.Int32FromUint32(JSON_LOOKUP_TOODEEP) {
zMsg = Xsqlite3_mprintf(tls, __ccgo_ts+27026, 0)
} else {
zMsg = Xsqlite3_mprintf(tls, __ccgo_ts+27045, libc.VaList(bp+8, zPath))
}
}
}
if ctx == uintptr(0) {
return zMsg
}
if zMsg != 0 {
Xsqlite3_result_error(tls, ctx, zMsg, -int32(1))
Xsqlite3_free(tls, zMsg)
} else {
Xsqlite3_result_error_nomem(tls, ctx)
}
return uintptr(0)
}
// C documentation
//
// /* Append a node type byte together with the payload size and
// ** possibly also the payload.
// **
// ** If aPayload is not NULL, then it is a pointer to the payload which
// ** is also appended. If aPayload is NULL, the pParse->aBlob[] array
// ** is resized (if necessary) so that it is big enough to hold the
// ** payload, but the payload is not appended and pParse->nBlob is left
// ** pointing to where the first byte of payload will eventually be.
// */
func _jsonBlobAppendNode(tls *libc.TLS, pParse uintptr, eType Tu8, szPayload Tu64, aPayload uintptr) {
var a, v1 uintptr
_, _ = a, v1
if uint64((*TJsonParse)(unsafe.Pointer(pParse)).FnBlob)+szPayload+uint64(9) > uint64((*TJsonParse)(unsafe.Pointer(pParse)).FnBlobAlloc) {
_jsonBlobExpandAndAppendNode(tls, pParse, eType, szPayload, aPayload)
return
}
a = (*TJsonParse)(unsafe.Pointer(pParse)).FaBlob + uintptr((*TJsonParse)(unsafe.Pointer(pParse)).FnBlob)
if szPayload <= uint64(11) {
**(**Tu8)(__ccgo_up(a)) = uint8(uint64(eType) | szPayload<> libc.Int32FromInt32(8) & uint64(0xff))
**(**Tu8)(__ccgo_up(a + 2)) = uint8(szPayload & uint64(0xff))
**(**Tu32)(__ccgo_up(pParse + 8)) += uint32(3)
} else {
**(**Tu8)(__ccgo_up(a)) = libc.Uint8FromInt32(libc.Int32FromUint8(eType) | int32(0xe0))
**(**Tu8)(__ccgo_up(a + 1)) = uint8(szPayload >> libc.Int32FromInt32(24) & uint64(0xff))
**(**Tu8)(__ccgo_up(a + 2)) = uint8(szPayload >> libc.Int32FromInt32(16) & uint64(0xff))
**(**Tu8)(__ccgo_up(a + 3)) = uint8(szPayload >> libc.Int32FromInt32(8) & uint64(0xff))
**(**Tu8)(__ccgo_up(a + 4)) = uint8(szPayload & uint64(0xff))
**(**Tu32)(__ccgo_up(pParse + 8)) += uint32(5)
}
}
}
if aPayload != 0 {
v1 = pParse + 8
*(*Tu32)(unsafe.Pointer(v1)) = Tu32(uint64(*(*Tu32)(unsafe.Pointer(v1))) + szPayload)
libc.X__builtin___memcpy_chk(tls, (*TJsonParse)(unsafe.Pointer(pParse)).FaBlob+uintptr(uint64((*TJsonParse)(unsafe.Pointer(pParse)).FnBlob)-szPayload), aPayload, szPayload, ^t__predefined_size_t(0))
}
}
// C documentation
//
// /* Change the payload size for the node at index i to be szPayload.
// */
func _jsonBlobChangePayloadSize(tls *libc.TLS, pParse uintptr, i Tu32, szPayload Tu32) (r int32) {
var a uintptr
var delta int32
var nExtra, nNeeded, szType Tu8
var newSize Tu32
_, _, _, _, _, _ = a, delta, nExtra, nNeeded, newSize, szType
if (*TJsonParse)(unsafe.Pointer(pParse)).Foom != 0 {
return 0
}
a = (*TJsonParse)(unsafe.Pointer(pParse)).FaBlob + uintptr(i)
szType = libc.Uint8FromInt32(libc.Int32FromUint8(**(**Tu8)(__ccgo_up(a))) >> int32(4))
if libc.Int32FromUint8(szType) <= int32(11) {
nExtra = uint8(0)
} else {
if libc.Int32FromUint8(szType) == int32(12) {
nExtra = uint8(1)
} else {
if libc.Int32FromUint8(szType) == int32(13) {
nExtra = uint8(2)
} else {
if libc.Int32FromUint8(szType) == int32(14) {
nExtra = uint8(4)
} else {
nExtra = uint8(8)
}
}
}
}
if szPayload <= uint32(11) {
nNeeded = uint8(0)
} else {
if szPayload <= uint32(0xff) {
nNeeded = uint8(1)
} else {
if szPayload <= uint32(0xffff) {
nNeeded = uint8(2)
} else {
nNeeded = uint8(4)
}
}
}
delta = libc.Int32FromUint8(nNeeded) - libc.Int32FromUint8(nExtra)
if delta != 0 {
newSize = (*TJsonParse)(unsafe.Pointer(pParse)).FnBlob + libc.Uint32FromInt32(delta)
if delta > 0 {
if newSize > (*TJsonParse)(unsafe.Pointer(pParse)).FnBlobAlloc && _jsonBlobExpand(tls, pParse, newSize) != 0 {
return 0 /* OOM error. Error state recorded in pParse->oom. */
}
a = (*TJsonParse)(unsafe.Pointer(pParse)).FaBlob + uintptr(i)
libc.X__builtin___memmove_chk(tls, a+uintptr(int32(1)+delta), a+1, uint64((*TJsonParse)(unsafe.Pointer(pParse)).FnBlob-(i+uint32(1))), ^t__predefined_size_t(0))
} else {
libc.X__builtin___memmove_chk(tls, a+1, a+uintptr(int32(1)-delta), uint64((*TJsonParse)(unsafe.Pointer(pParse)).FnBlob-(i+uint32(1)-libc.Uint32FromInt32(delta))), ^t__predefined_size_t(0))
}
(*TJsonParse)(unsafe.Pointer(pParse)).FnBlob = newSize
}
if libc.Int32FromUint8(nNeeded) == 0 {
**(**Tu8)(__ccgo_up(a)) = uint8(libc.Uint32FromInt32(libc.Int32FromUint8(**(**Tu8)(__ccgo_up(a)))&libc.Int32FromInt32(0x0f)) | szPayload<> libc.Int32FromInt32(8) & uint32(0xff))
**(**Tu8)(__ccgo_up(a + 2)) = uint8(szPayload & uint32(0xff))
} else {
**(**Tu8)(__ccgo_up(a)) = libc.Uint8FromInt32(libc.Int32FromUint8(**(**Tu8)(__ccgo_up(a)))&int32(0x0f) | int32(0xe0))
**(**Tu8)(__ccgo_up(a + 1)) = uint8(szPayload >> libc.Int32FromInt32(24) & uint32(0xff))
**(**Tu8)(__ccgo_up(a + 2)) = uint8(szPayload >> libc.Int32FromInt32(16) & uint32(0xff))
**(**Tu8)(__ccgo_up(a + 3)) = uint8(szPayload >> libc.Int32FromInt32(8) & uint32(0xff))
**(**Tu8)(__ccgo_up(a + 4)) = uint8(szPayload & uint32(0xff))
}
}
}
return delta
}
// C documentation
//
// /*
// ** Modify the JSONB blob at pParse->aBlob by removing nDel bytes of
// ** content beginning at iDel, and replacing them with nIns bytes of
// ** content given by aIns.
// **
// ** nDel may be zero, in which case no bytes are removed. But iDel is
// ** still important as new bytes will be insert beginning at iDel.
// **
// ** aIns may be zero, in which case space is created to hold nIns bytes
// ** beginning at iDel, but that space is uninitialized.
// **
// ** Set pParse->oom if an OOM occurs.
// */
func _jsonBlobEdit(tls *libc.TLS, pParse uintptr, iDel Tu32, nDel Tu32, aIns uintptr, nIns Tu32) {
var d Ti64
var v1 uintptr
_, _ = d, v1
d = libc.Int64FromUint32(nIns) - libc.Int64FromUint32(nDel)
if d < 0 && d >= int64(-libc.Int32FromInt32(8)) && aIns != uintptr(0) && _jsonBlobOverwrite(tls, (*TJsonParse)(unsafe.Pointer(pParse)).FaBlob+uintptr(iDel), aIns, nIns, libc.Uint32FromInt32(int32(-d))) != 0 {
return
}
if d != 0 {
if libc.Int64FromUint32((*TJsonParse)(unsafe.Pointer(pParse)).FnBlob)+d > libc.Int64FromUint32((*TJsonParse)(unsafe.Pointer(pParse)).FnBlobAlloc) {
_jsonBlobExpand(tls, pParse, libc.Uint32FromInt64(libc.Int64FromUint32((*TJsonParse)(unsafe.Pointer(pParse)).FnBlob)+d))
if (*TJsonParse)(unsafe.Pointer(pParse)).Foom != 0 {
return
}
}
libc.X__builtin___memmove_chk(tls, (*TJsonParse)(unsafe.Pointer(pParse)).FaBlob+uintptr(iDel+nIns), (*TJsonParse)(unsafe.Pointer(pParse)).FaBlob+uintptr(iDel+nDel), uint64((*TJsonParse)(unsafe.Pointer(pParse)).FnBlob-(iDel+nDel)), ^t__predefined_size_t(0))
v1 = pParse + 8
*(*Tu32)(unsafe.Pointer(v1)) = Tu32(int64(*(*Tu32)(unsafe.Pointer(v1))) + d)
v1 = pParse + 52
*(*int32)(unsafe.Pointer(v1)) = int32(int64(*(*int32)(unsafe.Pointer(v1))) + d)
}
if nIns != 0 && aIns != 0 {
libc.X__builtin___memcpy_chk(tls, (*TJsonParse)(unsafe.Pointer(pParse)).FaBlob+uintptr(iDel), aIns, uint64(nIns), ^t__predefined_size_t(0))
}
}
// C documentation
//
// /*
// ** If pParse->aBlob is not previously editable (because it is taken
// ** from sqlite3_value_blob(), as indicated by the fact that
// ** pParse->nBlobAlloc==0 and pParse->nBlob>0) then make it editable
// ** by making a copy into space obtained from malloc.
// **
// ** Return true on success. Return false on OOM.
// */
func _jsonBlobMakeEditable(tls *libc.TLS, pParse uintptr, nExtra Tu32) (r int32) {
var aOld uintptr
var nSize Tu32
_, _ = aOld, nSize
if (*TJsonParse)(unsafe.Pointer(pParse)).Foom != 0 {
return 0
}
if (*TJsonParse)(unsafe.Pointer(pParse)).FnBlobAlloc > uint32(0) {
return int32(1)
}
aOld = (*TJsonParse)(unsafe.Pointer(pParse)).FaBlob
nSize = (*TJsonParse)(unsafe.Pointer(pParse)).FnBlob + nExtra
(*TJsonParse)(unsafe.Pointer(pParse)).FaBlob = uintptr(0)
if _jsonBlobExpand(tls, pParse, nSize) != 0 {
return 0
}
libc.X__builtin___memcpy_chk(tls, (*TJsonParse)(unsafe.Pointer(pParse)).FaBlob, aOld, uint64((*TJsonParse)(unsafe.Pointer(pParse)).FnBlob), ^t__predefined_size_t(0))
return int32(1)
}
// C documentation
//
// /*
// ** If the JSONB at aIns[0..nIns-1] can be expanded (by denormalizing the
// ** size field) by d bytes, then write the expansion into aOut[] and
// ** return true. In this way, an overwrite happens without changing the
// ** size of the JSONB, which reduces memcpy() operations and also make it
// ** faster and easier to update the B-Tree entry that contains the JSONB
// ** in the database.
// **
// ** If the expansion of aIns[] by d bytes cannot be (easily) accomplished
// ** then return false.
// **
// ** The d parameter is guaranteed to be between 1 and 8.
// **
// ** This routine is an optimization. A correct answer is obtained if it
// ** always leaves the output unchanged and returns false.
// */
func _jsonBlobOverwrite(tls *libc.TLS, aOut uintptr, aIns uintptr, nIns Tu32, d Tu32) (r int32) {
var i, szPayload Tu32
var szHdr Tu8
_, _, _ = i, szHdr, szPayload /* Size of header before expansion */
if libc.Int32FromUint8(**(**Tu8)(__ccgo_up(aIns)))&int32(0x0f) <= int32(2) {
return 0
} /* Cannot enlarge NULL, true, false */
switch libc.Int32FromUint8(**(**Tu8)(__ccgo_up(aIns))) >> libc.Int32FromInt32(4) {
default: /* aIns[] header size 1 */
if int32(1)<> uint32(8)
}
return int32(1)
}
// C documentation
//
// /*
// ** Insert a new entry into the cache. If the cache is full, expel
// ** the least recently used entry. Return SQLITE_OK on success or a
// ** result code otherwise.
// **
// ** Cache entries are stored in age order, oldest first.
// */
func _jsonCacheInsert(tls *libc.TLS, ctx uintptr, pParse uintptr) (r int32) {
var db, p uintptr
_, _ = db, p
p = Xsqlite3_get_auxdata(tls, ctx, -int32(429938))
if p == uintptr(0) {
db = Xsqlite3_context_db_handle(tls, ctx)
p = _sqlite3DbMallocZero(tls, db, uint64(48))
if p == uintptr(0) {
return int32(SQLITE_NOMEM)
}
(*TJsonCache)(unsafe.Pointer(p)).Fdb = db
Xsqlite3_set_auxdata(tls, ctx, -int32(429938), p, __ccgo_fp(_jsonCacheDeleteGeneric))
p = Xsqlite3_get_auxdata(tls, ctx, -int32(429938))
if p == uintptr(0) {
return int32(SQLITE_NOMEM)
}
}
if (*TJsonCache)(unsafe.Pointer(p)).FnUsed >= int32(JSON_CACHE_SIZE) {
_jsonParseFree(tls, **(**uintptr)(__ccgo_up(p + 16)))
libc.X__builtin___memmove_chk(tls, p+16, p+16+1*8, libc.Uint64FromInt32(libc.Int32FromInt32(JSON_CACHE_SIZE)-libc.Int32FromInt32(1))*libc.Uint64FromInt64(8), ^t__predefined_size_t(0))
(*TJsonCache)(unsafe.Pointer(p)).FnUsed = libc.Int32FromInt32(JSON_CACHE_SIZE) - libc.Int32FromInt32(1)
}
(*TJsonParse)(unsafe.Pointer(pParse)).FeEdit = uint8(0)
(*TJsonParse)(unsafe.Pointer(pParse)).FnJPRef = (*TJsonParse)(unsafe.Pointer(pParse)).FnJPRef + 1
(*TJsonParse)(unsafe.Pointer(pParse)).FbReadOnly = uint8(1)
**(**uintptr)(__ccgo_up(p + 16 + uintptr((*TJsonCache)(unsafe.Pointer(p)).FnUsed)*8)) = pParse
(*TJsonCache)(unsafe.Pointer(p)).FnUsed = (*TJsonCache)(unsafe.Pointer(p)).FnUsed + 1
return SQLITE_OK
}
// C documentation
//
// /*
// ** Search for a cached translation the json text supplied by pArg. Return
// ** the JsonParse object if found. Return NULL if not found.
// **
// ** When a match if found, the matching entry is moved to become the
// ** most-recently used entry if it isn't so already.
// **
// ** The JsonParse object returned still belongs to the Cache and might
// ** be deleted at any moment. If the caller wants the JsonParse to
// ** linger, it needs to increment the nPJRef reference counter.
// */
func _jsonCacheSearch(tls *libc.TLS, ctx uintptr, pArg uintptr) (r uintptr) {
var i, nJson int32
var p, tmp, zJson uintptr
_, _, _, _, _ = i, nJson, p, tmp, zJson
if Xsqlite3_value_type(tls, pArg) != int32(SQLITE_TEXT) {
return uintptr(0)
}
zJson = Xsqlite3_value_text(tls, pArg)
if zJson == uintptr(0) {
return uintptr(0)
}
nJson = Xsqlite3_value_bytes(tls, pArg)
p = Xsqlite3_get_auxdata(tls, ctx, -int32(429938))
if p == uintptr(0) {
return uintptr(0)
}
i = 0
for {
if !(i < (*TJsonCache)(unsafe.Pointer(p)).FnUsed) {
break
}
if (*TJsonParse)(unsafe.Pointer(**(**uintptr)(__ccgo_up(p + 16 + uintptr(i)*8)))).FzJson == zJson {
break
}
goto _1
_1:
;
i = i + 1
}
if i >= (*TJsonCache)(unsafe.Pointer(p)).FnUsed {
i = 0
for {
if !(i < (*TJsonCache)(unsafe.Pointer(p)).FnUsed) {
break
}
if (*TJsonParse)(unsafe.Pointer(**(**uintptr)(__ccgo_up(p + 16 + uintptr(i)*8)))).FnJson != nJson {
goto _2
}
if libc.Xmemcmp(tls, (*TJsonParse)(unsafe.Pointer(**(**uintptr)(__ccgo_up(p + 16 + uintptr(i)*8)))).FzJson, zJson, libc.Uint64FromInt32(nJson)) == 0 {
break
}
goto _2
_2:
;
i = i + 1
}
}
if i < (*TJsonCache)(unsafe.Pointer(p)).FnUsed {
if i < (*TJsonCache)(unsafe.Pointer(p)).FnUsed-int32(1) {
/* Make the matching entry the most recently used entry */
tmp = **(**uintptr)(__ccgo_up(p + 16 + uintptr(i)*8))
libc.X__builtin___memmove_chk(tls, p+16+uintptr(i)*8, p+16+uintptr(i+int32(1))*8, libc.Uint64FromInt32((*TJsonCache)(unsafe.Pointer(p)).FnUsed-i-libc.Int32FromInt32(1))*uint64(8), ^t__predefined_size_t(0))
**(**uintptr)(__ccgo_up(p + 16 + uintptr((*TJsonCache)(unsafe.Pointer(p)).FnUsed-int32(1))*8)) = tmp
i = (*TJsonCache)(unsafe.Pointer(p)).FnUsed - int32(1)
}
return **(**uintptr)(__ccgo_up(p + 16 + uintptr(i)*8))
} else {
return uintptr(0)
}
return r
}
/**************************************************************************
** Utility routines for dealing with JsonString objects
**************************************************************************/
// C documentation
//
// /*
// ** Parse a complete JSON string. Return 0 on success or non-zero if there
// ** are any errors. If an error occurs, free all memory held by pParse,
// ** but not pParse itself.
// **
// ** pParse must be initialized to an empty parse object prior to calling
// ** this routine.
// */
func _jsonConvertTextToBlob(tls *libc.TLS, pParse uintptr, pCtx uintptr) (r int32) {
var i int32
var zJson uintptr
_, _ = i, zJson
zJson = (*TJsonParse)(unsafe.Pointer(pParse)).FzJson
i = _jsonTranslateTextToBlob(tls, pParse, uint32(0))
if (*TJsonParse)(unsafe.Pointer(pParse)).Foom != 0 {
i = -int32(1)
}
if i > 0 {
for _jsonIsSpace[libc.Uint8FromInt8(**(**int8)(__ccgo_up(zJson + uintptr(i))))] != 0 {
i = i + 1
}
if **(**int8)(__ccgo_up(zJson + uintptr(i))) != 0 {
i = i + _json5Whitespace(tls, zJson+uintptr(i))
if **(**int8)(__ccgo_up(zJson + uintptr(i))) != 0 {
if pCtx != 0 {
Xsqlite3_result_error(tls, pCtx, __ccgo_ts+26853, -int32(1))
}
_jsonParseReset(tls, pParse)
return int32(1)
}
(*TJsonParse)(unsafe.Pointer(pParse)).FhasNonstd = uint8(1)
}
}
if i <= 0 {
if pCtx != uintptr(0) {
if (*TJsonParse)(unsafe.Pointer(pParse)).Foom != 0 {
Xsqlite3_result_error_nomem(tls, pCtx)
} else {
Xsqlite3_result_error(tls, pCtx, __ccgo_ts+26853, -int32(1))
}
}
_jsonParseReset(tls, pParse)
return int32(1)
}
return 0
}
// C documentation
//
// /* This helper routine for jsonLookupStep() populates pIns with
// ** binary data that is to be inserted into pParse.
// **
// ** In the common case, pIns just points to pParse->aIns and pParse->nIns.
// ** But if the zPath of the original edit operation includes path elements
// ** that go deeper, additional substructure must be created.
// **
// ** For example:
// **
// ** json_insert('{}', '$.a.b.c', 123);
// **
// ** The search stops at '$.a' But additional substructure must be
// ** created for the ".b.c" part of the patch so that the final result
// ** is: {"a":{"b":{"c"::123}}}. This routine populates pIns with
// ** the binary equivalent of {"b":{"c":123}} so that it can be inserted.
// **
// ** The caller is responsible for resetting pIns when it has finished
// ** using the substructure.
// */
func _jsonCreateEditSubstructure(tls *libc.TLS, pParse uintptr, pIns uintptr, zTail uintptr) (r Tu32) {
var rc int32
var v1 uintptr
_, _ = rc, v1
libc.X__builtin___memset_chk(tls, pIns, 0, uint64(72), ^t__predefined_size_t(0))
(*TJsonParse)(unsafe.Pointer(pIns)).Fdb = (*TJsonParse)(unsafe.Pointer(pParse)).Fdb
if int32(**(**int8)(__ccgo_up(zTail))) == 0 {
/* No substructure. Just insert what is given in pParse. */
(*TJsonParse)(unsafe.Pointer(pIns)).FaBlob = (*TJsonParse)(unsafe.Pointer(pParse)).FaIns
(*TJsonParse)(unsafe.Pointer(pIns)).FnBlob = (*TJsonParse)(unsafe.Pointer(pParse)).FnIns
rc = 0
} else {
/* Construct the binary substructure */
(*TJsonParse)(unsafe.Pointer(pIns)).FnBlob = uint32(1)
(*TJsonParse)(unsafe.Pointer(pIns)).FaBlob = uintptr(unsafe.Pointer(&_emptyObject)) + libc.BoolUintptr(int32(**(**int8)(__ccgo_up(zTail))) == int32('.'))
(*TJsonParse)(unsafe.Pointer(pIns)).FeEdit = (*TJsonParse)(unsafe.Pointer(pParse)).FeEdit
(*TJsonParse)(unsafe.Pointer(pIns)).FnIns = (*TJsonParse)(unsafe.Pointer(pParse)).FnIns
(*TJsonParse)(unsafe.Pointer(pIns)).FaIns = (*TJsonParse)(unsafe.Pointer(pParse)).FaIns
(*TJsonParse)(unsafe.Pointer(pIns)).FiDepth = libc.Uint16FromInt32(libc.Int32FromUint16((*TJsonParse)(unsafe.Pointer(pParse)).FiDepth) + int32(1))
if libc.Int32FromUint16((*TJsonParse)(unsafe.Pointer(pIns)).FiDepth) >= int32(JSON_MAX_DEPTH) {
return uint32(JSON_LOOKUP_TOODEEP)
}
rc = libc.Int32FromUint32(_jsonLookupStep(tls, pIns, uint32(0), zTail, uint32(0)))
(*TJsonParse)(unsafe.Pointer(pParse)).FiDepth = (*TJsonParse)(unsafe.Pointer(pParse)).FiDepth - 1
v1 = pParse + 47
*(*Tu8)(unsafe.Pointer(v1)) = Tu8(int32(*(*Tu8)(unsafe.Pointer(v1))) | libc.Int32FromUint8((*TJsonParse)(unsafe.Pointer(pIns)).Foom))
}
return libc.Uint32FromInt32(rc) /* Error code only */
}
// 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+27253)
if rc == SQLITE_OK {
pNew = _sqlite3DbMallocZero(tls, db, uint64(40))
**(**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.X__builtin___memset_chk(tls, p+192, 0, uint64(72), ^t__predefined_size_t(0))
(*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+192) != 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+192, 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*8)))
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+192, 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+56, 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+56, __ccgo_ts+27357, uint32(1))
}
(*TJsonEachCursor)(unsafe.Pointer(p)).FnParent = uint32(0)
n = _jsonbPayloadSize(tls, p+192, 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+26853, 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_error_position(JSON)
// **
// ** If the argument is NULL, return NULL
// **
// ** If the argument is BLOB, do a full validity check and return non-zero
// ** if the check fails. The return value is the approximate 1-based offset
// ** to the byte of the element that contains the first error.
// **
// ** Otherwise interpret the argument is TEXT (even if it is numeric) and
// ** return the 1-based character position for where the parser first recognized
// ** that the input was not valid JSON, or return 0 if the input text looks
// ** ok. JSON-5 extensions are accepted.
// */
func _jsonErrorFunc(tls *libc.TLS, ctx uintptr, argc int32, argv uintptr) {
bp := tls.Alloc(80)
defer tls.Free(80)
var iErrPos Ti64
var k Tu32
var _ /* s at bp+0 */ TJsonParse
_, _ = iErrPos, k
iErrPos = 0
_ = argc
libc.X__builtin___memset_chk(tls, bp, 0, uint64(72), ^t__predefined_size_t(0))
(**(**TJsonParse)(__ccgo_up(bp))).Fdb = Xsqlite3_context_db_handle(tls, ctx)
if _jsonArgIsJsonb(tls, **(**uintptr)(__ccgo_up(argv)), bp) != 0 {
iErrPos = libc.Int64FromUint32(_jsonbValidityCheck(tls, bp, uint32(0), (**(**TJsonParse)(__ccgo_up(bp))).FnBlob, uint32(1)))
} else {
(**(**TJsonParse)(__ccgo_up(bp))).FzJson = Xsqlite3_value_text(tls, **(**uintptr)(__ccgo_up(argv)))
if (**(**TJsonParse)(__ccgo_up(bp))).FzJson == uintptr(0) {
return
} /* NULL input or OOM */
(**(**TJsonParse)(__ccgo_up(bp))).FnJson = Xsqlite3_value_bytes(tls, **(**uintptr)(__ccgo_up(argv)))
if _jsonConvertTextToBlob(tls, bp, uintptr(0)) != 0 {
if (**(**TJsonParse)(__ccgo_up(bp))).Foom != 0 {
iErrPos = int64(-int32(1))
} else {
/* Because s.oom is false */
k = uint32(0)
for {
if !(k < (**(**TJsonParse)(__ccgo_up(bp))).FiErr && **(**int8)(__ccgo_up((**(**TJsonParse)(__ccgo_up(bp))).FzJson + uintptr(k))) != 0) {
break
}
if int32(**(**int8)(__ccgo_up((**(**TJsonParse)(__ccgo_up(bp))).FzJson + uintptr(k))))&int32(0xc0) != int32(0x80) {
iErrPos = iErrPos + 1
}
goto _1
_1:
;
k = k + 1
}
iErrPos = iErrPos + 1
}
}
}
_jsonParseReset(tls, bp)
if iErrPos < 0 {
Xsqlite3_result_error_nomem(tls, ctx)
} else {
Xsqlite3_result_int64(tls, ctx, iErrPos)
}
}
// 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(144)
defer tls.Free(144)
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(int64(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)*8)))
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)*8))) == int32(SQLITE_INTEGER) {
_jsonAppendRawNZ(tls, bp, __ccgo_ts+27065, uint32(1))
if int32(**(**int8)(__ccgo_up(zPath))) == int32('-') {
_jsonAppendRawNZ(tls, bp, __ccgo_ts+27067, uint32(1))
}
_jsonAppendRaw(tls, bp, zPath, libc.Uint32FromInt32(nPath))
_jsonAppendRawNZ(tls, bp, __ccgo_ts+5660, 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+27069, uint32(2))
_jsonAppendRaw(tls, bp, zPath, libc.Uint32FromInt32(nPath))
_jsonAppendRawNZ(tls, bp, __ccgo_ts+27072, 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.X__builtin___memset_chk(tls, pParse, 0, uint64(72), ^t__predefined_size_t(0))
(*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+26824, -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+26853, -int32(1))
_sqlite3DbFree(tls, (*TJsonParse)(unsafe.Pointer(pParse)).Fdb, (*TJsonParse)(unsafe.Pointer(pParse)).FaBlob)
libc.X__builtin___memset_chk(tls, pParse, 0, uint64(72), ^t__predefined_size_t(0))
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+26958)
} 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+26951)
} 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
//
// /*
// ** This method works for both json_group_array() and json_group_object().
// ** It works by removing the first element of the group by searching forward
// ** to the first comma (",") that is not within a string and deleting all
// ** text through that comma.
// */
func _jsonGroupInverse(tls *libc.TLS, ctx uintptr, argc int32, argv uintptr) {
var c, v2 int8
var i uint32
var inStr, nNest int32
var pStr, z uintptr
var v3 bool
_, _, _, _, _, _, _, _ = c, i, inStr, nNest, pStr, z, v2, v3
inStr = 0
nNest = 0
_ = argc
_ = argv
pStr = Xsqlite3_aggregate_context(tls, ctx, 0)
/* pStr is always non-NULL since jsonArrayStep() or jsonObjectStep() will
** always have been called to initialize it */
if !(pStr != 0) {
return
}
z = (*TJsonString)(unsafe.Pointer(pStr)).FzBuf
i = uint32(1)
for {
if v3 = uint64(i) < (*TJsonString)(unsafe.Pointer(pStr)).FnUsed; v3 {
v2 = **(**int8)(__ccgo_up(z + uintptr(i)))
c = v2
}
if !(v3 && (int32(v2) != int32(',') || inStr != 0 || nNest != 0)) {
break
}
if int32(c) == int32('"') {
inStr = libc.BoolInt32(!(inStr != 0))
} else {
if int32(c) == int32('\\') {
i = i + 1
} else {
if !(inStr != 0) {
if int32(c) == int32('{') || int32(c) == int32('[') {
nNest = nNest + 1
}
if int32(c) == int32('}') || int32(c) == int32(']') {
nNest = nNest - 1
}
}
}
}
goto _1
_1:
;
i = i + 1
}
if uint64(i) < (*TJsonString)(unsafe.Pointer(pStr)).FnUsed {
**(**Tu64)(__ccgo_up(pStr + 24)) -= uint64(i)
libc.X__builtin___memmove_chk(tls, z+1, z+uintptr(i+uint32(1)), (*TJsonString)(unsafe.Pointer(pStr)).FnUsed-uint64(1), ^t__predefined_size_t(0))
**(**int8)(__ccgo_up(z + uintptr((*TJsonString)(unsafe.Pointer(pStr)).FnUsed))) = 0
} else {
(*TJsonString)(unsafe.Pointer(pStr)).FnUsed = uint64(1)
}
}
// 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(224)
defer tls.Free(224)
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+80 */ TJsonParse
var _ /* sz at bp+0 */ Tu32
var _ /* v at bp+152 */ TJsonParse
var _ /* v at bp+8 */ 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('\\'), uint64(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 + 44
*(*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+26998, zPath+uintptr(i)) != 0 {
return uint32(JSON_LOOKUP_NOTARRAY)
}
libc.X__builtin___memset_chk(tls, bp+80, 0, uint64(72), ^t__predefined_size_t(0))
(**(**TJsonParse)(__ccgo_up(bp + 80))).Fdb = (*TJsonParse)(unsafe.Pointer(pParse)).Fdb
if rawKey != 0 {
v5 = int32(JSONB_TEXTRAW)
} else {
v5 = int32(JSONB_TEXT5)
}
_jsonBlobAppendNode(tls, bp+80, libc.Uint8FromInt32(v5), uint64(nKey), uintptr(0))
v4 = pParse + 47
*(*Tu8)(unsafe.Pointer(v4)) = Tu8(int32(*(*Tu8)(unsafe.Pointer(v4))) | libc.Int32FromUint8((**(**TJsonParse)(__ccgo_up(bp + 80))).Foom))
rc = _jsonCreateEditSubstructure(tls, pParse, bp+8, zPath+uintptr(i))
if !(rc >= libc.Uint32FromUint32(JSON_LOOKUP_PATHERROR)) && _jsonBlobMakeEditable(tls, pParse, (**(**TJsonParse)(__ccgo_up(bp + 80))).FnBlob+nKey+(**(**TJsonParse)(__ccgo_up(bp + 8))).FnBlob) != 0 {
nIns = (**(**TJsonParse)(__ccgo_up(bp + 80))).FnBlob + nKey + (**(**TJsonParse)(__ccgo_up(bp + 8))).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.X__builtin___memcpy_chk(tls, (*TJsonParse)(unsafe.Pointer(pParse)).FaBlob+uintptr(j), (**(**TJsonParse)(__ccgo_up(bp + 80))).FaBlob, uint64((**(**TJsonParse)(__ccgo_up(bp + 80))).FnBlob), ^t__predefined_size_t(0))
k = j + (**(**TJsonParse)(__ccgo_up(bp + 80))).FnBlob
libc.X__builtin___memcpy_chk(tls, (*TJsonParse)(unsafe.Pointer(pParse)).FaBlob+uintptr(k), zKey, uint64(nKey), ^t__predefined_size_t(0))
k = k + nKey
libc.X__builtin___memcpy_chk(tls, (*TJsonParse)(unsafe.Pointer(pParse)).FaBlob+uintptr(k), (**(**TJsonParse)(__ccgo_up(bp + 8))).FaBlob, uint64((**(**TJsonParse)(__ccgo_up(bp + 8))).FnBlob), ^t__predefined_size_t(0))
if (*TJsonParse)(unsafe.Pointer(pParse)).Fdelta != 0 {
_jsonAfterEditSizeAdjust(tls, pParse, iRoot)
}
}
}
_jsonParseReset(tls, bp+8)
_jsonParseReset(tls, bp+80)
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 + 44
*(*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+152, zPath+uintptr(i+uint32(1)))
if !(rc >= libc.Uint32FromUint32(JSON_LOOKUP_PATHERROR)) && _jsonBlobMakeEditable(tls, pParse, (**(**TJsonParse)(__ccgo_up(bp + 152))).FnBlob) != 0 {
_jsonBlobEdit(tls, pParse, j, uint32(0), (**(**TJsonParse)(__ccgo_up(bp + 152))).FaBlob, (**(**TJsonParse)(__ccgo_up(bp + 152))).FnBlob)
}
_jsonParseReset(tls, bp+152)
if (*TJsonParse)(unsafe.Pointer(pParse)).Fdelta != 0 {
_jsonAfterEditSizeAdjust(tls, pParse, iRoot)
}
return rc
}
} else {
return uint32(JSON_LOOKUP_PATHERROR)
}
}
return uint32(JSON_LOOKUP_NOTFOUND)
}
// C documentation
//
// /*
// ** RFC-7396 MergePatch for two JSONB blobs.
// **
// ** pTarget is the target. pPatch is the patch. The target is updated
// ** in place. The patch is read-only.
// **
// ** The original RFC-7396 algorithm is this:
// **
// ** define MergePatch(Target, Patch):
// ** if Patch is an Object:
// ** if Target is not an Object:
// ** Target = {} # Ignore the contents and set it to an empty Object
// ** for each Name/Value pair in Patch:
// ** if Value is null:
// ** if Name exists in Target:
// ** remove the Name/Value pair from Target
// ** else:
// ** Target[Name] = MergePatch(Target[Name], Value)
// ** return Target
// ** else:
// ** return Patch
// **
// ** Here is an equivalent algorithm restructured to show the actual
// ** implementation:
// **
// ** 01 define MergePatch(Target, Patch):
// ** 02 if Patch is not an Object:
// ** 03 return Patch
// ** 04 else: // if Patch is an Object
// ** 05 if Target is not an Object:
// ** 06 Target = {}
// ** 07 for each Name/Value pair in Patch:
// ** 08 if Name exists in Target:
// ** 09 if Value is null:
// ** 10 remove the Name/Value pair from Target
// ** 11 else
// ** 12 Target[name] = MergePatch(Target[Name], Value)
// ** 13 else if Value is not NULL:
// ** 14 if Value is not an Object:
// ** 15 Target[name] = Value
// ** 16 else:
// ** 17 Target[name] = MergePatch('{}',value)
// ** 18 return Target
// ** |
// ** ^---- Line numbers referenced in comments in the implementation
// */
func _jsonMergePatch(tls *libc.TLS, pTarget uintptr, iTarget Tu32, pPatch uintptr, iPatch Tu32, iDepth Tu32) (r int32) {
bp := tls.Alloc(32)
defer tls.Free(32)
var ePLabel, eTLabel, x Tu8
var iPCursor, iPEnd, iPLabel, iPValue, iTCursor, iTEnd, iTEndBE, iTLabel, iTStart, iTValue, n, nPLabel, nPValue, nTLabel, nTValue, szNew, szPatch, szTarget Tu32
var isEqual, rc, rc1, savedDelta, savedDelta1, v1 int32
var _ /* sz at bp+0 */ Tu32
var _ /* szPLabel at bp+12 */ Tu32
var _ /* szPValue at bp+16 */ Tu32
var _ /* szTLabel at bp+4 */ Tu32
var _ /* szTValue at bp+8 */ Tu32
_, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _ = ePLabel, eTLabel, iPCursor, iPEnd, iPLabel, iPValue, iTCursor, iTEnd, iTEndBE, iTLabel, iTStart, iTValue, isEqual, n, nPLabel, nPValue, nTLabel, nTValue, rc, rc1, savedDelta, savedDelta1, szNew, szPatch, szTarget, x, v1
**(**Tu32)(__ccgo_up(bp)) = uint32(0) /* Node type of the target label */
iTLabel = uint32(0) /* Index of the label */
nTLabel = uint32(0) /* Header size in bytes for the target label */
**(**Tu32)(__ccgo_up(bp + 4)) = uint32(0) /* Size of the target label payload */
iTValue = uint32(0) /* Index of the target value */
nTValue = uint32(0) /* Header size of the target value */
**(**Tu32)(__ccgo_up(bp + 8)) = uint32(0) /* Payload size of the patch value */
x = libc.Uint8FromInt32(libc.Int32FromUint8(**(**Tu8)(__ccgo_up((*TJsonParse)(unsafe.Pointer(pPatch)).FaBlob + uintptr(iPatch)))) & int32(0x0f))
if libc.Int32FromUint8(x) != int32(JSONB_OBJECT) { /* Total size of the target, header+payload */
n = _jsonbPayloadSize(tls, pPatch, iPatch, bp)
szPatch = n + **(**Tu32)(__ccgo_up(bp))
**(**Tu32)(__ccgo_up(bp)) = uint32(0)
n = _jsonbPayloadSize(tls, pTarget, iTarget, bp)
szTarget = n + **(**Tu32)(__ccgo_up(bp))
_jsonBlobEdit(tls, pTarget, iTarget, szTarget, (*TJsonParse)(unsafe.Pointer(pPatch)).FaBlob+uintptr(iPatch), szPatch)
if (*TJsonParse)(unsafe.Pointer(pTarget)).Foom != 0 {
v1 = int32(JSON_MERGE_OOM)
} else {
v1 = JSON_MERGE_OK
}
return v1 /* Line 03 */
}
x = libc.Uint8FromInt32(libc.Int32FromUint8(**(**Tu8)(__ccgo_up((*TJsonParse)(unsafe.Pointer(pTarget)).FaBlob + uintptr(iTarget)))) & int32(0x0f))
if libc.Int32FromUint8(x) != int32(JSONB_OBJECT) { /* Algorithm line 05 */
n = _jsonbPayloadSize(tls, pTarget, iTarget, bp)
_jsonBlobEdit(tls, pTarget, iTarget+n, **(**Tu32)(__ccgo_up(bp)), uintptr(0), uint32(0))
x = **(**Tu8)(__ccgo_up((*TJsonParse)(unsafe.Pointer(pTarget)).FaBlob + uintptr(iTarget)))
**(**Tu8)(__ccgo_up((*TJsonParse)(unsafe.Pointer(pTarget)).FaBlob + uintptr(iTarget))) = libc.Uint8FromInt32(libc.Int32FromUint8(x)&int32(0xf0) | int32(JSONB_OBJECT))
}
n = _jsonbPayloadSize(tls, pPatch, iPatch, bp)
if n == uint32(0) {
return int32(JSON_MERGE_BADPATCH)
}
iPCursor = iPatch + n
iPEnd = iPCursor + **(**Tu32)(__ccgo_up(bp))
n = _jsonbPayloadSize(tls, pTarget, iTarget, bp)
if n == uint32(0) {
return int32(JSON_MERGE_BADTARGET)
}
iTStart = iTarget + n
iTEndBE = iTStart + **(**Tu32)(__ccgo_up(bp))
for iPCursor < iPEnd { /* Algorithm line 07 */
iPLabel = iPCursor
ePLabel = libc.Uint8FromInt32(libc.Int32FromUint8(**(**Tu8)(__ccgo_up((*TJsonParse)(unsafe.Pointer(pPatch)).FaBlob + uintptr(iPCursor)))) & int32(0x0f))
if libc.Int32FromUint8(ePLabel) < int32(JSONB_TEXT) || libc.Int32FromUint8(ePLabel) > int32(JSONB_TEXTRAW) {
return int32(JSON_MERGE_BADPATCH)
}
nPLabel = _jsonbPayloadSize(tls, pPatch, iPCursor, bp+12)
if nPLabel == uint32(0) {
return int32(JSON_MERGE_BADPATCH)
}
iPValue = iPCursor + nPLabel + **(**Tu32)(__ccgo_up(bp + 12))
if iPValue >= iPEnd {
return int32(JSON_MERGE_BADPATCH)
}
nPValue = _jsonbPayloadSize(tls, pPatch, iPValue, bp+16)
if nPValue == uint32(0) {
return int32(JSON_MERGE_BADPATCH)
}
iPCursor = iPValue + nPValue + **(**Tu32)(__ccgo_up(bp + 16))
if iPCursor > iPEnd {
return int32(JSON_MERGE_BADPATCH)
}
iTCursor = iTStart
iTEnd = iTEndBE + libc.Uint32FromInt32((*TJsonParse)(unsafe.Pointer(pTarget)).Fdelta)
for iTCursor < iTEnd { /* true if the patch and target labels match */
iTLabel = iTCursor
eTLabel = libc.Uint8FromInt32(libc.Int32FromUint8(**(**Tu8)(__ccgo_up((*TJsonParse)(unsafe.Pointer(pTarget)).FaBlob + uintptr(iTCursor)))) & int32(0x0f))
if libc.Int32FromUint8(eTLabel) < int32(JSONB_TEXT) || libc.Int32FromUint8(eTLabel) > int32(JSONB_TEXTRAW) {
return int32(JSON_MERGE_BADTARGET)
}
nTLabel = _jsonbPayloadSize(tls, pTarget, iTCursor, bp+4)
if nTLabel == uint32(0) {
return int32(JSON_MERGE_BADTARGET)
}
iTValue = iTLabel + nTLabel + **(**Tu32)(__ccgo_up(bp + 4))
if iTValue >= iTEnd {
return int32(JSON_MERGE_BADTARGET)
}
nTValue = _jsonbPayloadSize(tls, pTarget, iTValue, bp+8)
if nTValue == uint32(0) {
return int32(JSON_MERGE_BADTARGET)
}
if iTValue+nTValue+**(**Tu32)(__ccgo_up(bp + 8)) > iTEnd {
return int32(JSON_MERGE_BADTARGET)
}
isEqual = _jsonLabelCompare(tls, (*TJsonParse)(unsafe.Pointer(pPatch)).FaBlob+uintptr(iPLabel+nPLabel), **(**Tu32)(__ccgo_up(bp + 12)), libc.BoolInt32(libc.Int32FromUint8(ePLabel) == int32(JSONB_TEXT) || libc.Int32FromUint8(ePLabel) == int32(JSONB_TEXTRAW)), (*TJsonParse)(unsafe.Pointer(pTarget)).FaBlob+uintptr(iTLabel+nTLabel), **(**Tu32)(__ccgo_up(bp + 4)), libc.BoolInt32(libc.Int32FromUint8(eTLabel) == int32(JSONB_TEXT) || libc.Int32FromUint8(eTLabel) == int32(JSONB_TEXTRAW)))
if isEqual != 0 {
break
}
iTCursor = iTValue + nTValue + **(**Tu32)(__ccgo_up(bp + 8))
}
x = libc.Uint8FromInt32(libc.Int32FromUint8(**(**Tu8)(__ccgo_up((*TJsonParse)(unsafe.Pointer(pPatch)).FaBlob + uintptr(iPValue)))) & int32(0x0f))
if iTCursor < iTEnd {
/* A match was found. Algorithm line 08 */
if libc.Int32FromUint8(x) == 0 {
/* Patch value is NULL. Algorithm line 09 */
_jsonBlobEdit(tls, pTarget, iTLabel, nTLabel+**(**Tu32)(__ccgo_up(bp + 4))+nTValue+**(**Tu32)(__ccgo_up(bp + 8)), uintptr(0), uint32(0))
/* vvvvvv----- No OOM on a delete-only edit */
if (*TJsonParse)(unsafe.Pointer(pTarget)).Foom != 0 {
return int32(JSON_MERGE_OOM)
}
} else {
savedDelta = (*TJsonParse)(unsafe.Pointer(pTarget)).Fdelta
(*TJsonParse)(unsafe.Pointer(pTarget)).Fdelta = 0
if iDepth >= uint32(JSON_MAX_DEPTH) {
return int32(JSON_MERGE_TOODEEP)
}
rc = _jsonMergePatch(tls, pTarget, iTValue, pPatch, iPValue, iDepth+uint32(1))
if rc != 0 {
return rc
}
**(**int32)(__ccgo_up(pTarget + 52)) += savedDelta
}
} else {
if libc.Int32FromUint8(x) > 0 { /* Algorithm line 13 */
/* No match and patch value is not NULL */
szNew = **(**Tu32)(__ccgo_up(bp + 12)) + nPLabel
if libc.Int32FromUint8(**(**Tu8)(__ccgo_up((*TJsonParse)(unsafe.Pointer(pPatch)).FaBlob + uintptr(iPValue))))&int32(0x0f) != int32(JSONB_OBJECT) { /* Line 14 */
_jsonBlobEdit(tls, pTarget, iTEnd, uint32(0), uintptr(0), **(**Tu32)(__ccgo_up(bp + 16))+nPValue+szNew)
if (*TJsonParse)(unsafe.Pointer(pTarget)).Foom != 0 {
return int32(JSON_MERGE_OOM)
}
libc.X__builtin___memcpy_chk(tls, (*TJsonParse)(unsafe.Pointer(pTarget)).FaBlob+uintptr(iTEnd), (*TJsonParse)(unsafe.Pointer(pPatch)).FaBlob+uintptr(iPLabel), uint64(szNew), ^t__predefined_size_t(0))
libc.X__builtin___memcpy_chk(tls, (*TJsonParse)(unsafe.Pointer(pTarget)).FaBlob+uintptr(iTEnd+szNew), (*TJsonParse)(unsafe.Pointer(pPatch)).FaBlob+uintptr(iPValue), uint64(**(**Tu32)(__ccgo_up(bp + 16))+nPValue), ^t__predefined_size_t(0))
} else {
_jsonBlobEdit(tls, pTarget, iTEnd, uint32(0), uintptr(0), szNew+uint32(1))
if (*TJsonParse)(unsafe.Pointer(pTarget)).Foom != 0 {
return int32(JSON_MERGE_OOM)
}
libc.X__builtin___memcpy_chk(tls, (*TJsonParse)(unsafe.Pointer(pTarget)).FaBlob+uintptr(iTEnd), (*TJsonParse)(unsafe.Pointer(pPatch)).FaBlob+uintptr(iPLabel), uint64(szNew), ^t__predefined_size_t(0))
**(**Tu8)(__ccgo_up((*TJsonParse)(unsafe.Pointer(pTarget)).FaBlob + uintptr(iTEnd+szNew))) = uint8(0x00)
savedDelta1 = (*TJsonParse)(unsafe.Pointer(pTarget)).Fdelta
(*TJsonParse)(unsafe.Pointer(pTarget)).Fdelta = 0
if iDepth >= uint32(JSON_MAX_DEPTH) {
return int32(JSON_MERGE_TOODEEP)
}
rc1 = _jsonMergePatch(tls, pTarget, iTEnd+szNew, pPatch, iPValue, iDepth+uint32(1))
if rc1 != 0 {
return rc1
}
**(**int32)(__ccgo_up(pTarget + 52)) += savedDelta1
}
}
}
}
if (*TJsonParse)(unsafe.Pointer(pTarget)).Fdelta != 0 {
_jsonAfterEditSizeAdjust(tls, pTarget, iTarget)
}
if (*TJsonParse)(unsafe.Pointer(pTarget)).Foom != 0 {
v1 = int32(JSON_MERGE_OOM)
} else {
v1 = JSON_MERGE_OK
}
return v1
}
func _jsonObjectCompute(tls *libc.TLS, ctx uintptr, isFinal int32) {
bp := tls.Alloc(144)
defer tls.Free(144)
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(int64(Xsqlite3_user_data(tls, ctx)))
pStr = Xsqlite3_aggregate_context(tls, ctx, 0)
if pStr != 0 {
pOgStr = pStr
_jsonAppendRawNZ(tls, pOgStr, __ccgo_ts+27248, 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+27250, 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(144)
defer tls.Free(144)
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+27074, -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)*8))) != int32(SQLITE_TEXT) {
Xsqlite3_result_error(tls, ctx, __ccgo_ts+27125, -int32(1))
_jsonStringReset(tls, bp)
return
}
_jsonAppendSeparator(tls, bp)
z = Xsqlite3_value_text(tls, **(**uintptr)(__ccgo_up(argv + uintptr(i)*8)))
n = libc.Uint32FromInt32(Xsqlite3_value_bytes(tls, **(**uintptr)(__ccgo_up(argv + uintptr(i)*8))))
_jsonAppendString(tls, bp, z, n)
_jsonAppendChar(tls, bp, int8(':'))
_jsonAppendSqlValue(tls, bp, **(**uintptr)(__ccgo_up(argv + uintptr(i+int32(1))*8)))
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(136))
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*8)))
} else {
**(**int8)(__ccgo_up((*TJsonString)(unsafe.Pointer(pStr)).FzBuf)) = int8('@')
_jsonAppendRawNZ(tls, pStr, __ccgo_ts+27063, 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(72))
if p == uintptr(0) {
goto json_pfa_oom
}
libc.X__builtin___memset_chk(tls, p, 0, uint64(72), ^t__predefined_size_t(0))
(*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.X__builtin___memcpy_chk(tls, (*TJsonParse)(unsafe.Pointer(p)).FaBlob, (*TJsonParse)(unsafe.Pointer(pFromCache)).FaBlob, uint64(nBlob), ^t__predefined_size_t(0))
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.X__builtin___memcpy_chk(tls, zNew, (*TJsonParse)(unsafe.Pointer(p)).FzJson, libc.Uint64FromInt32((*TJsonParse)(unsafe.Pointer(p)).FnJson), ^t__predefined_size_t(0))
(*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+26853, -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
//
// /*
// ** Implementation of the json_mergepatch(JSON1,JSON2) function. Return a JSON
// ** object that is the result of running the RFC 7396 MergePatch() algorithm
// ** on the two arguments.
// */
func _jsonPatchFunc(tls *libc.TLS, ctx uintptr, argc int32, argv uintptr) {
var pPatch, pTarget uintptr
var rc int32
_, _, _ = pPatch, pTarget, rc /* Result code */
_ = argc
pTarget = _jsonParseFuncArg(tls, ctx, **(**uintptr)(__ccgo_up(argv)), uint32(JSON_EDITABLE))
if pTarget == uintptr(0) {
return
}
pPatch = _jsonParseFuncArg(tls, ctx, **(**uintptr)(__ccgo_up(argv + 1*8)), uint32(0))
if pPatch != 0 {
rc = _jsonMergePatch(tls, pTarget, uint32(0), pPatch, uint32(0), uint32(0))
if rc == JSON_MERGE_OK {
_jsonReturnParse(tls, ctx, pTarget)
} else {
if rc == int32(JSON_MERGE_OOM) {
Xsqlite3_result_error_nomem(tls, ctx)
} else {
if rc == int32(JSON_MERGE_TOODEEP) {
Xsqlite3_result_error(tls, ctx, __ccgo_ts+26803, -int32(1))
} else {
Xsqlite3_result_error(tls, ctx, __ccgo_ts+26853, -int32(1))
}
}
}
_jsonParseFree(tls, pPatch)
}
_jsonParseFree(tls, pTarget)
}
// C documentation
//
// /*
// ** json_pretty(JSON)
// ** json_pretty(JSON, INDENT)
// **
// ** Return text that is a pretty-printed rendering of the input JSON.
// ** If the argument is not valid JSON, return NULL.
// **
// ** The INDENT argument is text that is used for indentation. If omitted,
// ** it defaults to four spaces (the same as PostgreSQL).
// */
func _jsonPrettyFunc(tls *libc.TLS, ctx uintptr, argc int32, argv uintptr) {
bp := tls.Alloc(176)
defer tls.Free(176)
var v1 uintptr
var v2 bool
var _ /* s at bp+0 */ TJsonString
var _ /* x at bp+136 */ TJsonPretty
_, _ = v1, v2 /* Pretty printing context */
libc.X__builtin___memset_chk(tls, bp+136, 0, uint64(32), ^t__predefined_size_t(0))
(**(**TJsonPretty)(__ccgo_up(bp + 136))).FpParse = _jsonParseFuncArg(tls, ctx, **(**uintptr)(__ccgo_up(argv)), uint32(0))
if (**(**TJsonPretty)(__ccgo_up(bp + 136))).FpParse == uintptr(0) {
return
}
(**(**TJsonPretty)(__ccgo_up(bp + 136))).FpOut = bp
_jsonStringInit(tls, bp, ctx)
if v2 = argc == int32(1); !v2 {
v1 = Xsqlite3_value_text(tls, **(**uintptr)(__ccgo_up(argv + 1*8)))
(**(**TJsonPretty)(__ccgo_up(bp + 136))).FzIndent = v1
}
if v2 || v1 == uintptr(0) {
(**(**TJsonPretty)(__ccgo_up(bp + 136))).FzIndent = __ccgo_ts + 27183
(**(**TJsonPretty)(__ccgo_up(bp + 136))).FszIndent = uint32(4)
} else {
(**(**TJsonPretty)(__ccgo_up(bp + 136))).FszIndent = uint32(libc.Xstrlen(tls, (**(**TJsonPretty)(__ccgo_up(bp + 136))).FzIndent))
}
_jsonTranslateBlobToPrettyText(tls, bp+136, uint32(0))
_jsonReturnString(tls, bp, uintptr(0), uintptr(0))
_jsonParseFree(tls, (**(**TJsonPretty)(__ccgo_up(bp + 136))).FpParse)
}
// C documentation
//
// /*
// ** json_replace(JSON, PATH, VALUE, ...)
// **
// ** Replace the value at PATH with VALUE. If PATH does not already exist,
// ** this routine is a no-op. If JSON or PATH is malformed, throw an error.
// */
func _jsonReplaceFunc(tls *libc.TLS, ctx uintptr, argc int32, argv uintptr) {
if argc < int32(1) {
return
}
if argc&int32(1) == 0 {
_jsonWrongNumArgs(tls, ctx, __ccgo_ts+17416)
return
}
_jsonInsertIntoBlob(tls, ctx, argc, argv, int32(JEDIT_REPL))
}
// 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+26853, -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(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(int64(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+26853, -int32(1))
return
}
// C documentation
//
// /* Make the text in p (which is probably a generated JSON text string)
// ** the result of the SQL function.
// **
// ** The JsonString is reset.
// **
// ** If pParse and ctx are both non-NULL, then the SQL string in p is
// ** loaded into the zJson field of the pParse object as a RCStr and the
// ** pParse is added to the cache.
// */
func _jsonReturnString(tls *libc.TLS, p uintptr, pParse uintptr, ctx uintptr) {
var flags, rc int32
_, _ = flags, rc
_jsonStringTerminate(tls, p)
if libc.Int32FromUint8((*TJsonString)(unsafe.Pointer(p)).FeErr) == 0 {
flags = int32(int64(Xsqlite3_user_data(tls, (*TJsonString)(unsafe.Pointer(p)).FpCtx)))
if flags&int32(JSON_BLOB) != 0 {
_jsonReturnStringAsBlob(tls, p)
} else {
if (*TJsonString)(unsafe.Pointer(p)).FbStatic != 0 {
Xsqlite3_result_text64(tls, (*TJsonString)(unsafe.Pointer(p)).FpCtx, (*TJsonString)(unsafe.Pointer(p)).FzBuf, (*TJsonString)(unsafe.Pointer(p)).FnUsed, uintptr(-libc.Int32FromInt32(1)), uint8(SQLITE_UTF8))
} else {
if pParse != 0 && libc.Int32FromUint8((*TJsonParse)(unsafe.Pointer(pParse)).FbJsonIsRCStr) == 0 && (*TJsonParse)(unsafe.Pointer(pParse)).FnBlobAlloc > uint32(0) {
(*TJsonParse)(unsafe.Pointer(pParse)).FzJson = _sqlite3RCStrRef(tls, (*TJsonString)(unsafe.Pointer(p)).FzBuf)
(*TJsonParse)(unsafe.Pointer(pParse)).FnJson = libc.Int32FromUint64((*TJsonString)(unsafe.Pointer(p)).FnUsed)
(*TJsonParse)(unsafe.Pointer(pParse)).FbJsonIsRCStr = uint8(1)
rc = _jsonCacheInsert(tls, ctx, pParse)
if rc == int32(SQLITE_NOMEM) {
Xsqlite3_result_error_nomem(tls, ctx)
_jsonStringReset(tls, p)
return
}
}
Xsqlite3_result_text64(tls, (*TJsonString)(unsafe.Pointer(p)).FpCtx, _sqlite3RCStrRef(tls, (*TJsonString)(unsafe.Pointer(p)).FzBuf), (*TJsonString)(unsafe.Pointer(p)).FnUsed, __ccgo_fp(_sqlite3RCStrUnref), uint8(SQLITE_UTF8))
}
}
} else {
if libc.Int32FromUint8((*TJsonString)(unsafe.Pointer(p)).FeErr)&int32(JSTRING_OOM) != 0 {
Xsqlite3_result_error_nomem(tls, (*TJsonString)(unsafe.Pointer(p)).FpCtx)
} else {
if libc.Int32FromUint8((*TJsonString)(unsafe.Pointer(p)).FeErr)&int32(JSTRING_TOODEEP) != 0 {
/* error already in p->pCtx */
} else {
if libc.Int32FromUint8((*TJsonString)(unsafe.Pointer(p)).FeErr)&int32(JSTRING_MALFORMED) != 0 {
Xsqlite3_result_error(tls, (*TJsonString)(unsafe.Pointer(p)).FpCtx, __ccgo_ts+26853, -int32(1))
}
}
}
}
_jsonStringReset(tls, p)
}
/**************************************************************************
** Utility routines for dealing with JsonParse objects
**************************************************************************/
// C documentation
//
// /*
// ** The input string pStr is a well-formed JSON text string. Convert
// ** this into the JSONB format and make it the return value of the
// ** SQL function.
// */
func _jsonReturnStringAsBlob(tls *libc.TLS, pStr uintptr) {
bp := tls.Alloc(80)
defer tls.Free(80)
var _ /* px at bp+0 */ TJsonParse
libc.X__builtin___memset_chk(tls, bp, 0, uint64(72), ^t__predefined_size_t(0))
(**(**TJsonParse)(__ccgo_up(bp))).FzJson = (*TJsonString)(unsafe.Pointer(pStr)).FzBuf
(**(**TJsonParse)(__ccgo_up(bp))).FnJson = libc.Int32FromUint64((*TJsonString)(unsafe.Pointer(pStr)).FnUsed)
(**(**TJsonParse)(__ccgo_up(bp))).Fdb = Xsqlite3_context_db_handle(tls, (*TJsonString)(unsafe.Pointer(pStr)).FpCtx)
_jsonTranslateTextToBlob(tls, bp, uint32(0))
if (**(**TJsonParse)(__ccgo_up(bp))).Foom != 0 {
_sqlite3DbFree(tls, (**(**TJsonParse)(__ccgo_up(bp))).Fdb, (**(**TJsonParse)(__ccgo_up(bp))).FaBlob)
Xsqlite3_result_error_nomem(tls, (*TJsonString)(unsafe.Pointer(pStr)).FpCtx)
} else {
Xsqlite3_result_blob(tls, (*TJsonString)(unsafe.Pointer(pStr)).FpCtx, (**(**TJsonParse)(__ccgo_up(bp))).FaBlob, libc.Int32FromUint32((**(**TJsonParse)(__ccgo_up(bp))).FnBlob), __ccgo_fp(_sqlite3RowSetClear))
}
}
// C documentation
//
// /*
// ** Convert a JSON BLOB into text and make that text the return value
// ** of an SQL function.
// */
func _jsonReturnTextJsonFromBlob(tls *libc.TLS, ctx uintptr, aBlob uintptr, nBlob Tu32) {
bp := tls.Alloc(208)
defer tls.Free(208)
var _ /* s at bp+72 */ TJsonString
var _ /* x at bp+0 */ TJsonParse
if aBlob == uintptr(0) {
return
}
libc.X__builtin___memset_chk(tls, bp, 0, uint64(72), ^t__predefined_size_t(0))
(**(**TJsonParse)(__ccgo_up(bp))).FaBlob = aBlob
(**(**TJsonParse)(__ccgo_up(bp))).FnBlob = nBlob
_jsonStringInit(tls, bp+72, ctx)
_jsonTranslateBlobToText(tls, bp, uint32(0), bp+72)
_jsonReturnString(tls, bp+72, uintptr(0), uintptr(0))
}
// C documentation
//
// /* Append N bytes from zIn onto the end of the JsonString string.
// */
func _jsonStringExpandAndAppend(tls *libc.TLS, p uintptr, zIn uintptr, N Tu32) {
if _jsonStringGrow(tls, p, N) != 0 {
return
}
libc.X__builtin___memcpy_chk(tls, (*TJsonString)(unsafe.Pointer(p)).FzBuf+uintptr((*TJsonString)(unsafe.Pointer(p)).FnUsed), zIn, uint64(N), ^t__predefined_size_t(0))
**(**Tu64)(__ccgo_up(p + 24)) += uint64(N)
}
// C documentation
//
// /* Enlarge pJson->zBuf so that it can hold at least N more bytes.
// ** Return zero on success. Return non-zero on an OOM error
// */
func _jsonStringGrow(tls *libc.TLS, p uintptr, N Tu32) (r int32) {
var nTotal Tu64
var zNew, v2 uintptr
var v1 uint64
_, _, _, _ = nTotal, zNew, v1, v2
if uint64(N) < (*TJsonString)(unsafe.Pointer(p)).FnAlloc {
v1 = (*TJsonString)(unsafe.Pointer(p)).FnAlloc * uint64(2)
} else {
v1 = (*TJsonString)(unsafe.Pointer(p)).FnAlloc + uint64(N) + uint64(10)
}
nTotal = v1
if (*TJsonString)(unsafe.Pointer(p)).FbStatic != 0 {
if (*TJsonString)(unsafe.Pointer(p)).FeErr != 0 {
return int32(1)
}
zNew = _sqlite3RCStrNew(tls, nTotal)
if zNew == uintptr(0) {
_jsonStringOom(tls, p)
return int32(SQLITE_NOMEM)
}
libc.X__builtin___memcpy_chk(tls, zNew, (*TJsonString)(unsafe.Pointer(p)).FzBuf, (*TJsonString)(unsafe.Pointer(p)).FnUsed, ^t__predefined_size_t(0))
(*TJsonString)(unsafe.Pointer(p)).FzBuf = zNew
(*TJsonString)(unsafe.Pointer(p)).FbStatic = uint8(0)
} else {
(*TJsonString)(unsafe.Pointer(p)).FzBuf = _sqlite3RCStrResize(tls, (*TJsonString)(unsafe.Pointer(p)).FzBuf, nTotal)
if (*TJsonString)(unsafe.Pointer(p)).FzBuf == uintptr(0) {
v2 = p + 33
*(*Tu8)(unsafe.Pointer(v2)) = Tu8(int32(*(*Tu8)(unsafe.Pointer(v2))) | libc.Int32FromInt32(JSTRING_OOM))
_jsonStringZero(tls, p)
return int32(SQLITE_NOMEM)
}
}
(*TJsonString)(unsafe.Pointer(p)).FnAlloc = nTotal
return SQLITE_OK
}
// C documentation
//
// /* Report JSON nested too deep
// */
func _jsonStringTooDeep(tls *libc.TLS, p uintptr) {
var v1 uintptr
_ = v1
v1 = p + 33
*(*Tu8)(unsafe.Pointer(v1)) = Tu8(int32(*(*Tu8)(unsafe.Pointer(v1))) | libc.Int32FromInt32(JSTRING_TOODEEP))
Xsqlite3_result_error(tls, (*TJsonString)(unsafe.Pointer(p)).FpCtx, __ccgo_ts+26803, -int32(1))
_jsonStringReset(tls, p)
}
// 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 + 33
*(*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+26992, 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 + 33
*(*Tu8)(unsafe.Pointer(v1)) = Tu8(int32(*(*Tu8)(unsafe.Pointer(v1))) | libc.Int32FromInt32(JSTRING_MALFORMED))
break
}
_jsonAppendRawNZ(tls, pOut, __ccgo_ts+26995, uint32(2))
j = _jsonTranslateBlobToPrettyText(tls, pPretty, j)
if j >= iEnd {
break
}
_jsonAppendRawNZ(tls, pOut, __ccgo_ts+26992, 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 + 33
*(*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+8526, uint32(4))
return i + uint32(1)
_4:
;
_jsonAppendRawNZ(tls, pOut, __ccgo_ts+8531, 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 + 33
*(*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 + 26872
} else {
v1 = __ccgo_ts + 13352
}
_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.X__builtin___memcpy_chk(tls, (*TJsonString)(unsafe.Pointer(pOut)).FzBuf+uintptr((*TJsonString)(unsafe.Pointer(pOut)).FnUsed)+uintptr(1), (*TJsonParse)(unsafe.Pointer(pParse)).FaBlob+uintptr(i+n), uint64(**(**Tu32)(__ccgo_up(bp))), ^t__predefined_size_t(0))
**(**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 + 24)) += 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+26970, 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 + 33
*(*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+26973, uint32(6))
case int32('x'):
if sz2 < uint32(4) {
v1 = pOut + 33
*(*Tu8)(unsafe.Pointer(v1)) = Tu8(int32(*(*Tu8)(unsafe.Pointer(v1))) | libc.Int32FromInt32(JSTRING_MALFORMED))
sz2 = uint32(2)
break
}
_jsonAppendRawNZ(tls, pOut, __ccgo_ts+26980, 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+26985, 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 + 33
*(*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 + 44
*(*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 + 33
*(*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 + 44
*(*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 + 33
*(*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 + 33
*(*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 + 44
*(*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) + uint32(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 + 44
*(*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) + uint32(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+8526, uint64(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+8531, uint64(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+26868, 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+26951)
} else {
_jsonBlobAppendNode(tls, pParse, uint8(JSONB_FLOAT), uint64(5), __ccgo_ts+26958)
}
if Xsqlite3_strnicmp(tls, z+uintptr(i+uint32(4)), __ccgo_ts+26964, 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) + uint32(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, uint64(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 !(uint64(k1) < libc.Uint64FromInt64(120)/libc.Uint64FromInt64(24)) {
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+26958)
} 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
//
// /*
// ** json_valid(JSON)
// ** json_valid(JSON, FLAGS)
// **
// ** Check the JSON argument to see if it is well-formed. The FLAGS argument
// ** encodes the various constraints on what is meant by "well-formed":
// **
// ** 0x01 Canonical RFC-8259 JSON text
// ** 0x02 JSON text with optional JSON-5 extensions
// ** 0x04 Superficially appears to be JSONB
// ** 0x08 Strictly well-formed JSONB
// **
// ** If the FLAGS argument is omitted, it defaults to 1. Useful values for
// ** FLAGS include:
// **
// ** 1 Strict canonical JSON text
// ** 2 JSON text perhaps with JSON-5 extensions
// ** 4 Superficially appears to be JSONB
// ** 5 Canonical JSON text or superficial JSONB
// ** 6 JSON-5 text or superficial JSONB
// ** 8 Strict JSONB
// ** 9 Canonical JSON text or strict JSONB
// ** 10 JSON-5 text or strict JSONB
// **
// ** Other flag combinations are redundant. For example, every canonical
// ** JSON text is also well-formed JSON-5 text, so FLAG values 2 and 3
// ** are the same. Similarly, any input that passes a strict JSONB validation
// ** will also pass the superficial validation so 12 through 15 are the same
// ** as 8 through 11 respectively.
// **
// ** This routine runs in linear time to validate text and when doing strict
// ** JSONB validation. Superficial JSONB validation is constant time,
// ** assuming the BLOB is already in memory. The performance advantage
// ** of superficial JSONB validation is why that option is provided.
// ** Application developers can choose to do fast superficial validation or
// ** slower strict validation, according to their specific needs.
// **
// ** Only the lower four bits of the FLAGS argument are currently used.
// ** Higher bits are reserved for future expansion. To facilitate
// ** compatibility, the current implementation raises an error if any bit
// ** in FLAGS is set other than the lower four bits.
// **
// ** The original circa 2015 implementation of the JSON routines in
// ** SQLite only supported canonical RFC-8259 JSON text and the json_valid()
// ** function only accepted one argument. That is why the default value
// ** for the FLAGS argument is 1, since FLAGS=1 causes this routine to only
// ** recognize canonical RFC-8259 JSON text as valid. The extra FLAGS
// ** argument was added when the JSON routines were extended to support
// ** JSON5-like extensions and binary JSONB stored in BLOBs.
// **
// ** Return Values:
// **
// ** * Raise an error if FLAGS is outside the range of 1 to 15.
// ** * Return NULL if the input is NULL
// ** * Return 1 if the input is well-formed.
// ** * Return 0 if the input is not well-formed.
// */
func _jsonValidFunc(tls *libc.TLS, ctx uintptr, argc int32, argv uintptr) {
bp := tls.Alloc(144)
defer tls.Free(144)
var f Ti64
var flags, res Tu8
var p uintptr
var _ /* px at bp+72 */ TJsonParse
var _ /* py at bp+0 */ TJsonParse
_, _, _, _ = f, flags, p, res /* The parse */
flags = uint8(1)
res = uint8(0)
if argc == int32(2) {
f = Xsqlite3_value_int64(tls, **(**uintptr)(__ccgo_up(argv + 1*8)))
if f < int64(1) || f > int64(15) {
Xsqlite3_result_error(tls, ctx, __ccgo_ts+27188, -int32(1))
return
}
flags = libc.Uint8FromInt64(f & int64(0x0f))
}
switch Xsqlite3_value_type(tls, **(**uintptr)(__ccgo_up(argv))) {
case int32(SQLITE_NULL):
return
case int32(SQLITE_BLOB):
libc.X__builtin___memset_chk(tls, bp, 0, uint64(72), ^t__predefined_size_t(0))
if _jsonArgIsJsonb(tls, **(**uintptr)(__ccgo_up(argv)), bp) != 0 {
if libc.Int32FromUint8(flags)&int32(0x04) != 0 {
/* Superficial checking only - accomplished by the
** jsonArgIsJsonb() call above. */
res = uint8(1)
} else {
if libc.Int32FromUint8(flags)&int32(0x08) != 0 {
/* Strict checking. Check by translating BLOB->TEXT->BLOB. If
** no errors occur, call that a "strict check". */
res = libc.BoolUint8(uint32(0) == _jsonbValidityCheck(tls, bp, uint32(0), (**(**TJsonParse)(__ccgo_up(bp))).FnBlob, uint32(1)))
}
}
break
}
/* Fall through into interpreting the input as text. See note
** above at tag-20240123-a. */
fallthrough
default:
if libc.Int32FromUint8(flags)&int32(0x3) == 0 {
break
}
libc.X__builtin___memset_chk(tls, bp+72, 0, uint64(72), ^t__predefined_size_t(0))
p = _jsonParseFuncArg(tls, ctx, **(**uintptr)(__ccgo_up(argv)), uint32(JSON_KEEPERROR))
if p != 0 {
if (*TJsonParse)(unsafe.Pointer(p)).Foom != 0 {
Xsqlite3_result_error_nomem(tls, ctx)
} else {
if (*TJsonParse)(unsafe.Pointer(p)).FnErr != 0 {
/* no-op */
} else {
if libc.Int32FromUint8(flags)&int32(0x02) != 0 || libc.Int32FromUint8((*TJsonParse)(unsafe.Pointer(p)).FhasNonstd) == 0 {
res = uint8(1)
}
}
}
_jsonParseFree(tls, p)
} else {
Xsqlite3_result_error_nomem(tls, ctx)
}
break
}
Xsqlite3_result_int(tls, ctx, libc.Int32FromUint8(res))
}
// C documentation
//
// /*
// ** Report the wrong number of arguments for json_insert(), json_replace()
// ** or json_set().
// */
func _jsonWrongNumArgs(tls *libc.TLS, pCtx uintptr, zFuncName uintptr) {
bp := tls.Alloc(16)
defer tls.Free(16)
var zMsg uintptr
_ = zMsg
zMsg = Xsqlite3_mprintf(tls, __ccgo_ts+26899, libc.VaList(bp+8, zFuncName))
Xsqlite3_result_error(tls, pCtx, zMsg, -int32(1))
Xsqlite3_free(tls, zMsg)
}
/****************************************************************************
** Utility routines for dealing with the binary BLOB representation of JSON
****************************************************************************/
// C documentation
//
// /* Human-readable names for the JSONB values. The index for each
// ** string must correspond to the JSONB_* integer above.
// */
var _jsonbType = [17]uintptr{
0: __ccgo_ts + 1688,
1: __ccgo_ts + 8526,
2: __ccgo_ts + 8531,
3: __ccgo_ts + 6840,
4: __ccgo_ts + 6840,
5: __ccgo_ts + 6835,
6: __ccgo_ts + 6835,
7: __ccgo_ts + 8835,
8: __ccgo_ts + 8835,
9: __ccgo_ts + 8835,
10: __ccgo_ts + 8835,
11: __ccgo_ts + 26790,
12: __ccgo_ts + 26796,
13: __ccgo_ts + 1702,
14: __ccgo_ts + 1702,
15: __ccgo_ts + 1702,
16: __ccgo_ts + 1702,
}
// C documentation
//
// /*
// ** Check a single element of the JSONB in pParse for validity.
// **
// ** The element to be checked starts at offset i and must end at on the
// ** last byte before iEnd.
// **
// ** Return 0 if everything is correct. Return the 1-based byte offset of the
// ** error if a problem is detected. (In other words, if the error is at offset
// ** 0, return 1).
// */
func _jsonbValidityCheck(tls *libc.TLS, pParse uintptr, i Tu32, iEnd Tu32, iDepth Tu32) (r Tu32) {
bp := tls.Alloc(16)
defer tls.Free(16)
var cnt, j, k, n, sub, sub1, szC Tu32
var seen, x Tu8
var z uintptr
var v1 uint32
var _ /* c at bp+4 */ Tu32
var _ /* sz at bp+0 */ Tu32
_, _, _, _, _, _, _, _, _, _, _ = cnt, j, k, n, seen, sub, sub1, szC, x, z, v1
if iDepth > uint32(JSON_MAX_DEPTH) {
return i + uint32(1)
}
**(**Tu32)(__ccgo_up(bp)) = uint32(0)
n = _jsonbPayloadSize(tls, pParse, i, bp)
if n == uint32(0) {
return i + uint32(1)
} /* Checked by caller */
if i+n+**(**Tu32)(__ccgo_up(bp)) != iEnd {
return i + uint32(1)
} /* Checked by caller */
z = (*TJsonParse)(unsafe.Pointer(pParse)).FaBlob
x = libc.Uint8FromInt32(libc.Int32FromUint8(**(**Tu8)(__ccgo_up(z + uintptr(i)))) & int32(0x0f))
switch libc.Int32FromUint8(x) {
case JSONB_NULL:
fallthrough
case int32(JSONB_TRUE):
fallthrough
case int32(JSONB_FALSE):
if n+**(**Tu32)(__ccgo_up(bp)) == uint32(1) {
v1 = uint32(0)
} else {
v1 = i + uint32(1)
}
return v1
case int32(JSONB_INT):
if **(**Tu32)(__ccgo_up(bp)) < uint32(1) {
return i + uint32(1)
}
j = i + n
if libc.Int32FromUint8(**(**Tu8)(__ccgo_up(z + uintptr(j)))) == int32('-') {
j = j + 1
if **(**Tu32)(__ccgo_up(bp)) < uint32(2) {
return i + uint32(1)
}
}
k = i + n + **(**Tu32)(__ccgo_up(bp))
for j < k {
if libc.Int32FromUint8(_sqlite3CtypeMap[**(**Tu8)(__ccgo_up(z + uintptr(j)))])&int32(0x04) != 0 {
j = j + 1
} else {
return j + uint32(1)
}
}
return uint32(0)
case int32(JSONB_INT5):
if **(**Tu32)(__ccgo_up(bp)) < uint32(3) {
return i + uint32(1)
}
j = i + n
if libc.Int32FromUint8(**(**Tu8)(__ccgo_up(z + uintptr(j)))) == int32('-') {
if **(**Tu32)(__ccgo_up(bp)) < uint32(4) {
return i + uint32(1)
}
j = j + 1
}
if libc.Int32FromUint8(**(**Tu8)(__ccgo_up(z + uintptr(j)))) != int32('0') {
return i + uint32(1)
}
if libc.Int32FromUint8(**(**Tu8)(__ccgo_up(z + uintptr(j+uint32(1))))) != int32('x') && libc.Int32FromUint8(**(**Tu8)(__ccgo_up(z + uintptr(j+uint32(1))))) != int32('X') {
return j + uint32(2)
}
j = j + uint32(2)
k = i + n + **(**Tu32)(__ccgo_up(bp))
for j < k {
if libc.Int32FromUint8(_sqlite3CtypeMap[**(**Tu8)(__ccgo_up(z + uintptr(j)))])&int32(0x08) != 0 {
j = j + 1
} else {
return j + uint32(1)
}
}
return uint32(0)
case int32(JSONB_FLOAT):
fallthrough
case int32(JSONB_FLOAT5):
seen = uint8(0) /* 0: initial. 1: '.' seen 2: 'e' seen */
if **(**Tu32)(__ccgo_up(bp)) < uint32(2) {
return i + uint32(1)
}
j = i + n
k = j + **(**Tu32)(__ccgo_up(bp))
if libc.Int32FromUint8(**(**Tu8)(__ccgo_up(z + uintptr(j)))) == int32('-') {
j = j + 1
if **(**Tu32)(__ccgo_up(bp)) < uint32(3) {
return i + uint32(1)
}
}
if libc.Int32FromUint8(**(**Tu8)(__ccgo_up(z + uintptr(j)))) == int32('.') {
if libc.Int32FromUint8(x) == int32(JSONB_FLOAT) {
return j + uint32(1)
}
if !(libc.Int32FromUint8(_sqlite3CtypeMap[**(**Tu8)(__ccgo_up(z + uintptr(j+uint32(1))))])&libc.Int32FromInt32(0x04) != 0) {
return j + uint32(1)
}
j = j + uint32(2)
seen = uint8(1)
} else {
if libc.Int32FromUint8(**(**Tu8)(__ccgo_up(z + uintptr(j)))) == int32('0') && libc.Int32FromUint8(x) == int32(JSONB_FLOAT) {
if j+uint32(3) > k {
return j + uint32(1)
}
if libc.Int32FromUint8(**(**Tu8)(__ccgo_up(z + uintptr(j+uint32(1))))) != int32('.') && libc.Int32FromUint8(**(**Tu8)(__ccgo_up(z + uintptr(j+uint32(1))))) != int32('e') && libc.Int32FromUint8(**(**Tu8)(__ccgo_up(z + uintptr(j+uint32(1))))) != int32('E') {
return j + uint32(1)
}
j = j + 1
}
}
for {
if !(j < k) {
break
}
if libc.Int32FromUint8(_sqlite3CtypeMap[**(**Tu8)(__ccgo_up(z + uintptr(j)))])&int32(0x04) != 0 {
goto _2
}
if libc.Int32FromUint8(**(**Tu8)(__ccgo_up(z + uintptr(j)))) == int32('.') {
if libc.Int32FromUint8(seen) > 0 {
return j + uint32(1)
}
if libc.Int32FromUint8(x) == int32(JSONB_FLOAT) && (j == k-uint32(1) || !(libc.Int32FromUint8(_sqlite3CtypeMap[**(**Tu8)(__ccgo_up(z + uintptr(j+uint32(1))))])&libc.Int32FromInt32(0x04) != 0)) {
return j + uint32(1)
}
seen = uint8(1)
goto _2
}
if libc.Int32FromUint8(**(**Tu8)(__ccgo_up(z + uintptr(j)))) == int32('e') || libc.Int32FromUint8(**(**Tu8)(__ccgo_up(z + uintptr(j)))) == int32('E') {
if libc.Int32FromUint8(seen) == int32(2) {
return j + uint32(1)
}
if j == k-uint32(1) {
return j + uint32(1)
}
if libc.Int32FromUint8(**(**Tu8)(__ccgo_up(z + uintptr(j+uint32(1))))) == int32('+') || libc.Int32FromUint8(**(**Tu8)(__ccgo_up(z + uintptr(j+uint32(1))))) == int32('-') {
j = j + 1
if j == k-uint32(1) {
return j + uint32(1)
}
}
seen = uint8(2)
goto _2
}
return j + uint32(1)
goto _2
_2:
;
j = j + 1
}
if libc.Int32FromUint8(seen) == 0 {
return i + uint32(1)
}
return uint32(0)
case int32(JSONB_TEXT):
j = i + n
k = j + **(**Tu32)(__ccgo_up(bp))
for j < k {
if !(_jsonIsOk[**(**Tu8)(__ccgo_up(z + uintptr(j)))] != 0) && libc.Int32FromUint8(**(**Tu8)(__ccgo_up(z + uintptr(j)))) != int32('\'') {
return j + uint32(1)
}
j = j + 1
}
return uint32(0)
case int32(JSONB_TEXTJ):
fallthrough
case int32(JSONB_TEXT5):
j = i + n
k = j + **(**Tu32)(__ccgo_up(bp))
for j < k {
if !(_jsonIsOk[**(**Tu8)(__ccgo_up(z + uintptr(j)))] != 0) && libc.Int32FromUint8(**(**Tu8)(__ccgo_up(z + uintptr(j)))) != int32('\'') {
if libc.Int32FromUint8(**(**Tu8)(__ccgo_up(z + uintptr(j)))) == int32('"') {
if libc.Int32FromUint8(x) == int32(JSONB_TEXTJ) {
return j + uint32(1)
}
} else {
if libc.Int32FromUint8(**(**Tu8)(__ccgo_up(z + uintptr(j)))) <= int32(0x1f) {
/* Control characters in JSON5 string literals are ok */
if libc.Int32FromUint8(x) == int32(JSONB_TEXTJ) {
return j + uint32(1)
}
} else {
if libc.Int32FromUint8(**(**Tu8)(__ccgo_up(z + uintptr(j)))) != int32('\\') || j+uint32(1) >= k {
return j + uint32(1)
} else {
if libc.Xstrchr(tls, __ccgo_ts+26942, libc.Int32FromUint8(**(**Tu8)(__ccgo_up(z + uintptr(j+uint32(1)))))) != uintptr(0) {
j = j + 1
} else {
if libc.Int32FromUint8(**(**Tu8)(__ccgo_up(z + uintptr(j+uint32(1))))) == int32('u') {
if j+uint32(5) >= k {
return j + uint32(1)
}
if !(_jsonIs4Hex(tls, z+uintptr(j+uint32(2))) != 0) {
return j + uint32(1)
}
j = j + 1
} else {
if libc.Int32FromUint8(x) != int32(JSONB_TEXT5) {
return j + uint32(1)
} else {
**(**Tu32)(__ccgo_up(bp + 4)) = uint32(0)
szC = _jsonUnescapeOneChar(tls, z+uintptr(j), k-j, bp+4)
if **(**Tu32)(__ccgo_up(bp + 4)) == uint32(JSON_INVALID_CHAR) {
return j + uint32(1)
}
j = j + (szC - uint32(1))
}
}
}
}
}
}
}
j = j + 1
}
return uint32(0)
case int32(JSONB_TEXTRAW):
return uint32(0)
case int32(JSONB_ARRAY):
j = i + n
k = j + **(**Tu32)(__ccgo_up(bp))
for j < k {
**(**Tu32)(__ccgo_up(bp)) = uint32(0)
n = _jsonbPayloadSize(tls, pParse, j, bp)
if n == uint32(0) {
return j + uint32(1)
}
if j+n+**(**Tu32)(__ccgo_up(bp)) > k {
return j + uint32(1)
}
sub = _jsonbValidityCheck(tls, pParse, j, j+n+**(**Tu32)(__ccgo_up(bp)), iDepth+uint32(1))
if sub != 0 {
return sub
}
j = j + (n + **(**Tu32)(__ccgo_up(bp)))
}
return uint32(0)
case int32(JSONB_OBJECT):
cnt = uint32(0)
j = i + n
k = j + **(**Tu32)(__ccgo_up(bp))
for j < k {
**(**Tu32)(__ccgo_up(bp)) = uint32(0)
n = _jsonbPayloadSize(tls, pParse, j, bp)
if n == uint32(0) {
return j + uint32(1)
}
if j+n+**(**Tu32)(__ccgo_up(bp)) > k {
return j + uint32(1)
}
if cnt&uint32(1) == uint32(0) {
x = libc.Uint8FromInt32(libc.Int32FromUint8(**(**Tu8)(__ccgo_up(z + uintptr(j)))) & int32(0x0f))
if libc.Int32FromUint8(x) < int32(JSONB_TEXT) || libc.Int32FromUint8(x) > int32(JSONB_TEXTRAW) {
return j + uint32(1)
}
}
sub1 = _jsonbValidityCheck(tls, pParse, j, j+n+**(**Tu32)(__ccgo_up(bp)), iDepth+uint32(1))
if sub1 != 0 {
return sub1
}
cnt = cnt + 1
j = j + (n + **(**Tu32)(__ccgo_up(bp)))
}
if cnt&uint32(1) != uint32(0) {
return j + uint32(1)
}
return uint32(0)
default:
return i + uint32(1)
}
return r
}
const _kGUARD_EXC_CV_NOTIFICATION_PORT_REQ = 1048584
const _kGUARD_EXC_DESCRIPTOR_VIOLATION = 67
const _kGUARD_EXC_DESTROY = 1
const _kGUARD_EXC_EXCEPTION_BEHAVIOR_ENFORCE = 6
const _kGUARD_EXC_IMMOVABLE = 32
const _kGUARD_EXC_IMMOVABLE_NON_FATAL = 4194304
const _kGUARD_EXC_INCORRECT_GUARD = 16
const _kGUARD_EXC_INVALID_ARGUMENT = 2048
const _kGUARD_EXC_INVALID_MPO_ENTITLEMENT = 66
const _kGUARD_EXC_INVALID_NAME = 512
const _kGUARD_EXC_INVALID_NOTIFICATION_PORT = 1048582
const _kGUARD_EXC_INVALID_NOTIFICATION_REQ = 65
const _kGUARD_EXC_INVALID_OPTIONS = 3
const _kGUARD_EXC_INVALID_RIGHT = 256
const _kGUARD_EXC_INVALID_VALUE = 1024
const _kGUARD_EXC_KERN_FAILURE = 16384
const _kGUARD_EXC_KERN_NO_SPACE = 8192
const _kGUARD_EXC_KERN_RESOURCE = 32768
const _kGUARD_EXC_KOBJECT_REPLY_PORT_SEMANTICS = 9
const _kGUARD_EXC_MACH_EXC_THREAD_SET_STATE = 1048583
const _kGUARD_EXC_MOD_REFS = 2
const _kGUARD_EXC_MOD_REFS_NON_FATAL = 2097152
const _kGUARD_EXC_MOVE_WEAK_REPLY_PORT = 1048580
const _kGUARD_EXC_MSG_FILTERED = 128
const _kGUARD_EXC_NONE = 0
const _kGUARD_EXC_OOL_PORT_ARRAY_CREATION = 1048579
const _kGUARD_EXC_RCV_GUARDED_DESC = 1048576
const _kGUARD_EXC_RCV_INVALID_NAME = 524288
const _kGUARD_EXC_REPLY_PORT_SINGLE_SO_RIGHT = 1048581
const _kGUARD_EXC_REQUIRE_REPLY_PORT_SEMANTICS = 10
const _kGUARD_EXC_RIGHT_EXISTS = 4096
const _kGUARD_EXC_SEND_INVALID_REPLY = 65536
const _kGUARD_EXC_SEND_INVALID_RIGHT = 262144
const _kGUARD_EXC_SEND_INVALID_VOUCHER = 131072
const _kGUARD_EXC_SERVICE_PORT_VIOLATION_FATAL = 7
const _kGUARD_EXC_SERVICE_PORT_VIOLATION_NON_FATAL = 1048577
const _kGUARD_EXC_SET_CONTEXT = 4
const _kGUARD_EXC_STRICT_REPLY = 64
const _kGUARD_EXC_THREAD_SET_STATE = 5
const _kGUARD_EXC_UNGUARDED = 8
const _kGUARD_EXC_WEAK_REPLY_PORT = 1048578
// C documentation
//
// /*
// ** Implementation of the like() SQL function. This function implements
// ** the built-in LIKE operator. The first argument to the function is the
// ** pattern and the second argument is the string. So, the SQL statements:
// **
// ** A LIKE B
// **
// ** is implemented as like(B,A).
// **
// ** This same function (with a different compareInfo structure) computes
// ** the GLOB operator.
// */
func _likeFunc(tls *libc.TLS, context uintptr, argc int32, argv uintptr) {
bp := tls.Alloc(16)
defer tls.Free(16)
var db, pInfo, zA, zB uintptr
var escape Tu32
var nPat int32
var _ /* backupInfo at bp+0 */ TcompareInfo
var _ /* zEsc at bp+8 */ uintptr
_, _, _, _, _, _ = db, escape, nPat, pInfo, zA, zB
db = Xsqlite3_context_db_handle(tls, context)
pInfo = Xsqlite3_user_data(tls, context)
if Xsqlite3_value_type(tls, **(**uintptr)(__ccgo_up(argv))) == int32(SQLITE_BLOB) || Xsqlite3_value_type(tls, **(**uintptr)(__ccgo_up(argv + 1*8))) == int32(SQLITE_BLOB) {
Xsqlite3_result_int(tls, context, 0)
return
}
/* Limit the length of the LIKE or GLOB pattern to avoid problems
** of deep recursion and N*N behavior in patternCompare().
*/
nPat = Xsqlite3_value_bytes(tls, **(**uintptr)(__ccgo_up(argv)))
if nPat > **(**int32)(__ccgo_up(db + 136 + 8*4)) {
Xsqlite3_result_error(tls, context, __ccgo_ts+16829, -int32(1))
return
}
if argc == int32(3) {
/* The escape character string must consist of a single UTF-8 character.
** Otherwise, return an error.
*/
**(**uintptr)(__ccgo_up(bp + 8)) = Xsqlite3_value_text(tls, **(**uintptr)(__ccgo_up(argv + 2*8)))
if **(**uintptr)(__ccgo_up(bp + 8)) == uintptr(0) {
return
}
if _sqlite3Utf8CharLen(tls, **(**uintptr)(__ccgo_up(bp + 8)), -int32(1)) != int32(1) {
Xsqlite3_result_error(tls, context, __ccgo_ts+16862, -int32(1))
return
}
escape = _sqlite3Utf8Read(tls, bp+8)
if escape == uint32((*TcompareInfo)(unsafe.Pointer(pInfo)).FmatchAll) || escape == uint32((*TcompareInfo)(unsafe.Pointer(pInfo)).FmatchOne) {
libc.X__builtin___memcpy_chk(tls, bp, pInfo, uint64(4), ^t__predefined_size_t(0))
pInfo = bp
if escape == uint32((*TcompareInfo)(unsafe.Pointer(pInfo)).FmatchAll) {
(*TcompareInfo)(unsafe.Pointer(pInfo)).FmatchAll = uint8(0)
}
if escape == uint32((*TcompareInfo)(unsafe.Pointer(pInfo)).FmatchOne) {
(*TcompareInfo)(unsafe.Pointer(pInfo)).FmatchOne = uint8(0)
}
}
} else {
escape = uint32((*TcompareInfo)(unsafe.Pointer(pInfo)).FmatchSet)
}
zB = Xsqlite3_value_text(tls, **(**uintptr)(__ccgo_up(argv)))
zA = Xsqlite3_value_text(tls, **(**uintptr)(__ccgo_up(argv + 1*8)))
if zA != 0 && zB != 0 {
Xsqlite3_result_int(tls, context, libc.BoolInt32(_patternCompare(tls, zB, zA, pInfo, escape) == SQLITE_MATCH))
}
}
// C documentation
//
// /*
// ** A function that loads a shared-library extension then returns NULL.
// */
func _loadExt(tls *libc.TLS, context uintptr, argc int32, argv uintptr) {
bp := tls.Alloc(16)
defer tls.Free(16)
var db, zFile, zProc uintptr
var _ /* zErrMsg at bp+0 */ uintptr
_, _, _ = db, zFile, zProc
zFile = Xsqlite3_value_text(tls, **(**uintptr)(__ccgo_up(argv)))
db = Xsqlite3_context_db_handle(tls, context)
**(**uintptr)(__ccgo_up(bp)) = uintptr(0)
/* Disallow the load_extension() SQL function unless the SQLITE_LoadExtFunc
** flag is set. See the sqlite3_enable_load_extension() API.
*/
if (*Tsqlite3)(unsafe.Pointer(db)).Fflags&uint64(SQLITE_LoadExtFunc) == uint64(0) {
Xsqlite3_result_error(tls, context, __ccgo_ts+14019, -int32(1))
return
}
if argc == int32(2) {
zProc = Xsqlite3_value_text(tls, **(**uintptr)(__ccgo_up(argv + 1*8)))
} else {
zProc = uintptr(0)
}
if zFile != 0 && Xsqlite3_load_extension(tls, db, zFile, zProc, bp) != 0 {
Xsqlite3_result_error(tls, context, **(**uintptr)(__ccgo_up(bp)), -int32(1))
Xsqlite3_free(tls, **(**uintptr)(__ccgo_up(bp)))
}
}
// C documentation
//
// /*
// ** Load content from the sqlite_stat4 table into
// ** the Index.aSample[] arrays of all indices.
// */
func _loadStat4(tls *libc.TLS, db uintptr, zDb uintptr) (r int32) {
var pStat4, v1 uintptr
var rc int32
var v2 bool
_, _, _, _ = pStat4, rc, v1, v2
rc = SQLITE_OK
if v2 = (*Tsqlite3)(unsafe.Pointer(db)).FdbOptFlags&libc.Uint32FromInt32(libc.Int32FromInt32(SQLITE_Stat4)) == uint32(0); v2 {
v1 = _sqlite3FindTable(tls, db, __ccgo_ts+13207, zDb)
pStat4 = v1
}
if v2 && v1 != uintptr(0) && libc.Int32FromUint8((*TTable)(unsafe.Pointer(pStat4)).FeTabType) == TABTYP_NORM {
rc = _loadStatTbl(tls, db, __ccgo_ts+13433, __ccgo_ts+13502, zDb)
}
return rc
}
// C documentation
//
// /*
// ** Load the content from either the sqlite_stat4
// ** into the relevant Index.aSample[] arrays.
// **
// ** Arguments zSql1 and zSql2 must point to SQL statements that return
// ** data equivalent to the following:
// **
// ** zSql1: SELECT idx,count(*) FROM %Q.sqlite_stat4 GROUP BY idx
// ** zSql2: SELECT idx,neq,nlt,ndlt,sample FROM %Q.sqlite_stat4
// **
// ** where %Q is replaced with the database name before the SQL is executed.
// */
func _loadStatTbl(tls *libc.TLS, db uintptr, zSql1 uintptr, zSql2 uintptr, zDb uintptr) (r int32) {
bp := tls.Alloc(32)
defer tls.Free(32)
var i, nByte Ti64
var nCol, nIdxCol, nSample, rc int32
var pIdx, pIdx1, pPrevIdx, pPtr, pSample, pSpace, zIndex, zIndex1, zSql uintptr
var _ /* pStmt at bp+0 */ uintptr
_, _, _, _, _, _, _, _, _, _, _, _, _, _, _ = i, nByte, nCol, nIdxCol, nSample, pIdx, pIdx1, pPrevIdx, pPtr, pSample, pSpace, rc, zIndex, zIndex1, zSql /* Result codes from subroutines */
**(**uintptr)(__ccgo_up(bp)) = uintptr(0) /* Text of the SQL statement */
pPrevIdx = uintptr(0) /* A slot in pIdx->aSample[] */
zSql = _sqlite3MPrintf(tls, db, zSql1, libc.VaList(bp+16, zDb))
if !(zSql != 0) {
return int32(SQLITE_NOMEM)
}
rc = Xsqlite3_prepare(tls, db, zSql, -int32(1), bp, uintptr(0))
_sqlite3DbFree(tls, db, zSql)
if rc != 0 {
return rc
}
for Xsqlite3_step(tls, **(**uintptr)(__ccgo_up(bp))) == int32(SQLITE_ROW) {
nIdxCol = int32(1) /* Available memory as a u8 for easier manipulation */
zIndex = Xsqlite3_column_text(tls, **(**uintptr)(__ccgo_up(bp)), 0)
if zIndex == uintptr(0) {
continue
}
nSample = Xsqlite3_column_int(tls, **(**uintptr)(__ccgo_up(bp)), int32(1))
pIdx = _findIndexOrPrimaryKey(tls, db, zIndex, zDb)
if pIdx == uintptr(0) {
continue
}
if (*TIndex)(unsafe.Pointer(pIdx)).FaSample != uintptr(0) {
/* The same index appears in sqlite_stat4 under multiple names */
continue
}
if !((*TTable)(unsafe.Pointer((*TIndex)(unsafe.Pointer(pIdx)).FpTable)).FtabFlags&libc.Uint32FromInt32(TF_WithoutRowid) == libc.Uint32FromInt32(0)) && int32(uint32(*(*uint16)(unsafe.Pointer(pIdx + 100))&0x3>>0)) == int32(SQLITE_IDXTYPE_PRIMARYKEY) {
nIdxCol = libc.Int32FromUint16((*TIndex)(unsafe.Pointer(pIdx)).FnKeyCol)
} else {
nIdxCol = libc.Int32FromUint16((*TIndex)(unsafe.Pointer(pIdx)).FnColumn)
}
(*TIndex)(unsafe.Pointer(pIdx)).FnSampleCol = nIdxCol
(*TIndex)(unsafe.Pointer(pIdx)).FmxSample = nSample
nByte = (libc.Int64FromInt64(40)*int64(nSample) + libc.Int64FromInt32(7)) & int64(^libc.Int32FromInt32(7))
nByte = nByte + libc.Int64FromInt64(8)*int64(nIdxCol)*int64(3)*int64(nSample)
nByte = nByte + int64(nIdxCol)*libc.Int64FromInt64(8) /* Space for Index.aAvgEq[] */
(*TIndex)(unsafe.Pointer(pIdx)).FaSample = _sqlite3DbMallocZero(tls, db, libc.Uint64FromInt64(nByte))
if (*TIndex)(unsafe.Pointer(pIdx)).FaSample == uintptr(0) {
Xsqlite3_finalize(tls, **(**uintptr)(__ccgo_up(bp)))
return int32(SQLITE_NOMEM)
}
pPtr = (*TIndex)(unsafe.Pointer(pIdx)).FaSample
pPtr = pPtr + uintptr((int64(nSample)*libc.Int64FromInt64(40)+libc.Int64FromInt32(7))&int64(^libc.Int32FromInt32(7)))
pSpace = pPtr
(*TIndex)(unsafe.Pointer(pIdx)).FaAvgEq = pSpace
pSpace = pSpace + uintptr(nIdxCol)*8
**(**Tu32)(__ccgo_up((*TIndex)(unsafe.Pointer(pIdx)).FpTable + 48)) |= uint32(TF_HasStat4)
i = 0
for {
if !(i < int64(nSample)) {
break
}
(**(**TIndexSample)(__ccgo_up((*TIndex)(unsafe.Pointer(pIdx)).FaSample + uintptr(i)*40))).FanEq = pSpace
pSpace = pSpace + uintptr(nIdxCol)*8
(**(**TIndexSample)(__ccgo_up((*TIndex)(unsafe.Pointer(pIdx)).FaSample + uintptr(i)*40))).FanLt = pSpace
pSpace = pSpace + uintptr(nIdxCol)*8
(**(**TIndexSample)(__ccgo_up((*TIndex)(unsafe.Pointer(pIdx)).FaSample + uintptr(i)*40))).FanDLt = pSpace
pSpace = pSpace + uintptr(nIdxCol)*8
goto _1
_1:
;
i = i + 1
}
}
rc = Xsqlite3_finalize(tls, **(**uintptr)(__ccgo_up(bp)))
if rc != 0 {
return rc
}
zSql = _sqlite3MPrintf(tls, db, zSql2, libc.VaList(bp+16, zDb))
if !(zSql != 0) {
return int32(SQLITE_NOMEM)
}
rc = Xsqlite3_prepare(tls, db, zSql, -int32(1), bp, uintptr(0))
_sqlite3DbFree(tls, db, zSql)
if rc != 0 {
return rc
}
for Xsqlite3_step(tls, **(**uintptr)(__ccgo_up(bp))) == int32(SQLITE_ROW) { /* Pointer to the index object */
nCol = int32(1) /* Number of columns in index */
zIndex1 = Xsqlite3_column_text(tls, **(**uintptr)(__ccgo_up(bp)), 0)
if zIndex1 == uintptr(0) {
continue
}
pIdx1 = _findIndexOrPrimaryKey(tls, db, zIndex1, zDb)
if pIdx1 == uintptr(0) {
continue
}
if (*TIndex)(unsafe.Pointer(pIdx1)).FnSample >= (*TIndex)(unsafe.Pointer(pIdx1)).FmxSample {
/* Too many slots used because the same index appears in
** sqlite_stat4 using multiple names */
continue
}
/* This next condition is true if data has already been loaded from
** the sqlite_stat4 table. */
nCol = (*TIndex)(unsafe.Pointer(pIdx1)).FnSampleCol
if pIdx1 != pPrevIdx {
_initAvgEq(tls, pPrevIdx)
pPrevIdx = pIdx1
}
pSample = (*TIndex)(unsafe.Pointer(pIdx1)).FaSample + uintptr((*TIndex)(unsafe.Pointer(pIdx1)).FnSample)*40
_decodeIntArray(tls, Xsqlite3_column_text(tls, **(**uintptr)(__ccgo_up(bp)), int32(1)), nCol, (*TIndexSample)(unsafe.Pointer(pSample)).FanEq, uintptr(0), uintptr(0))
_decodeIntArray(tls, Xsqlite3_column_text(tls, **(**uintptr)(__ccgo_up(bp)), int32(2)), nCol, (*TIndexSample)(unsafe.Pointer(pSample)).FanLt, uintptr(0), uintptr(0))
_decodeIntArray(tls, Xsqlite3_column_text(tls, **(**uintptr)(__ccgo_up(bp)), int32(3)), nCol, (*TIndexSample)(unsafe.Pointer(pSample)).FanDLt, uintptr(0), uintptr(0))
/* Take a copy of the sample. Add 8 extra 0x00 bytes the end of the buffer.
** This is in case the sample record is corrupted. In that case, the
** sqlite3VdbeRecordCompare() may read up to two varints past the
** end of the allocated buffer before it realizes it is dealing with
** a corrupt record. Or it might try to read a large integer from the
** buffer. In any case, eight 0x00 bytes prevents this from causing
** a buffer overread. */
(*TIndexSample)(unsafe.Pointer(pSample)).Fn = Xsqlite3_column_bytes(tls, **(**uintptr)(__ccgo_up(bp)), int32(4))
(*TIndexSample)(unsafe.Pointer(pSample)).Fp = _sqlite3DbMallocZero(tls, db, libc.Uint64FromInt32((*TIndexSample)(unsafe.Pointer(pSample)).Fn+int32(8)))
if (*TIndexSample)(unsafe.Pointer(pSample)).Fp == uintptr(0) {
Xsqlite3_finalize(tls, **(**uintptr)(__ccgo_up(bp)))
return int32(SQLITE_NOMEM)
}
if (*TIndexSample)(unsafe.Pointer(pSample)).Fn != 0 {
libc.X__builtin___memcpy_chk(tls, (*TIndexSample)(unsafe.Pointer(pSample)).Fp, Xsqlite3_column_blob(tls, **(**uintptr)(__ccgo_up(bp)), int32(4)), libc.Uint64FromInt32((*TIndexSample)(unsafe.Pointer(pSample)).Fn), ^t__predefined_size_t(0))
}
(*TIndex)(unsafe.Pointer(pIdx1)).FnSample = (*TIndex)(unsafe.Pointer(pIdx1)).FnSample + 1
}
rc = Xsqlite3_finalize(tls, **(**uintptr)(__ccgo_up(bp)))
if rc == SQLITE_OK {
_initAvgEq(tls, pPrevIdx)
}
return rc
}
// C documentation
//
// /*
// ** Get a reference to pPage1 of the database file. This will
// ** also acquire a readlock on that file.
// **
// ** SQLITE_OK is returned on success. If the file is not a
// ** well-formed database file, then SQLITE_CORRUPT is returned.
// ** SQLITE_BUSY is returned if the database is locked. SQLITE_NOMEM
// ** is returned if we run out of memory.
// */
func _lockBtree(tls *libc.TLS, pBt uintptr) (r int32) {
bp := tls.Alloc(16)
defer tls.Free(16)
var nPage, pageSize, usableSize Tu32
var page1, v1 uintptr
var rc, v4 int32
var _ /* isOpen at bp+12 */ int32
var _ /* nPageFile at bp+8 */ Tu32
var _ /* pPage1 at bp+0 */ uintptr
_, _, _, _, _, _, _ = nPage, page1, pageSize, rc, usableSize, v1, v4 /* Number of pages in the database */
**(**Tu32)(__ccgo_up(bp + 8)) = uint32(0) /* Number of pages in the database file */
rc = _sqlite3PagerSharedLock(tls, (*TBtShared)(unsafe.Pointer(pBt)).FpPager)
if rc != SQLITE_OK {
return rc
}
rc = _btreeGetPage(tls, pBt, uint32(1), bp, 0)
if rc != SQLITE_OK {
return rc
}
/* Do some checking to help insure the file we opened really is
** a valid database file.
*/
nPage = _sqlite3Get4byte(tls, uintptr(28)+(*TMemPage)(unsafe.Pointer(**(**uintptr)(__ccgo_up(bp)))).FaData)
_sqlite3PagerPagecount(tls, (*TBtShared)(unsafe.Pointer(pBt)).FpPager, bp+8)
if nPage == uint32(0) || libc.Xmemcmp(tls, uintptr(24)+(*TMemPage)(unsafe.Pointer(**(**uintptr)(__ccgo_up(bp)))).FaData, uintptr(92)+(*TMemPage)(unsafe.Pointer(**(**uintptr)(__ccgo_up(bp)))).FaData, uint64(4)) != 0 {
nPage = **(**Tu32)(__ccgo_up(bp + 8))
}
if (*Tsqlite3)(unsafe.Pointer((*TBtShared)(unsafe.Pointer(pBt)).Fdb)).Fflags&uint64(SQLITE_ResetDatabase) != uint64(0) {
nPage = uint32(0)
}
if nPage > uint32(0) {
page1 = (*TMemPage)(unsafe.Pointer(**(**uintptr)(__ccgo_up(bp)))).FaData
rc = int32(SQLITE_NOTADB)
/* EVIDENCE-OF: R-43737-39999 Every valid SQLite database file begins
** with the following 16 bytes (in hex): 53 51 4c 69 74 65 20 66 6f 72 6d
** 61 74 20 33 00. */
if libc.Xmemcmp(tls, page1, uintptr(unsafe.Pointer(&_zMagicHeader)), uint64(16)) != 0 {
goto page1_init_failed
}
if libc.Int32FromUint8(**(**Tu8)(__ccgo_up(page1 + 18))) > int32(2) {
v1 = pBt + 40
*(*Tu16)(unsafe.Pointer(v1)) = Tu16(int32(*(*Tu16)(unsafe.Pointer(v1))) | libc.Int32FromInt32(BTS_READ_ONLY))
}
if libc.Int32FromUint8(**(**Tu8)(__ccgo_up(page1 + 19))) > int32(2) {
goto page1_init_failed
}
/* If the read version is set to 2, this database should be accessed
** in WAL mode. If the log is not already open, open it now. Then
** return SQLITE_OK and return without populating BtShared.pPage1.
** The caller detects this and calls this function again. This is
** required as the version of page 1 currently in the page1 buffer
** may not be the latest version - there may be a newer one in the log
** file.
*/
if libc.Int32FromUint8(**(**Tu8)(__ccgo_up(page1 + 19))) == int32(2) && libc.Int32FromUint16((*TBtShared)(unsafe.Pointer(pBt)).FbtsFlags)&int32(BTS_NO_WAL) == 0 {
**(**int32)(__ccgo_up(bp + 12)) = 0
rc = _sqlite3PagerOpenWal(tls, (*TBtShared)(unsafe.Pointer(pBt)).FpPager, bp+12)
if rc != SQLITE_OK {
goto page1_init_failed
} else {
if **(**int32)(__ccgo_up(bp + 12)) == 0 {
_releasePageOne(tls, **(**uintptr)(__ccgo_up(bp)))
return SQLITE_OK
}
}
rc = int32(SQLITE_NOTADB)
} else {
}
/* EVIDENCE-OF: R-15465-20813 The maximum and minimum embedded payload
** fractions and the leaf payload fraction values must be 64, 32, and 32.
**
** The original design allowed these amounts to vary, but as of
** version 3.6.0, we require them to be fixed.
*/
if libc.Xmemcmp(tls, page1+21, __ccgo_ts+4696, uint64(3)) != 0 {
goto page1_init_failed
}
/* EVIDENCE-OF: R-51873-39618 The page size for a database file is
** determined by the 2-byte integer located at an offset of 16 bytes from
** the beginning of the database file. */
pageSize = libc.Uint32FromInt32(libc.Int32FromUint8(**(**Tu8)(__ccgo_up(page1 + 16)))< uint32(SQLITE_MAX_PAGE_SIZE) || pageSize <= uint32(256) {
goto page1_init_failed
}
/* EVIDENCE-OF: R-59310-51205 The "reserved space" size in the 1-byte
** integer at offset 20 is the number of bytes of space at the end of
** each page to reserve for extensions.
**
** EVIDENCE-OF: R-37497-42412 The size of the reserved region is
** determined by the one-byte unsigned integer found at an offset of 20
** into the database file header. */
usableSize = pageSize - uint32(**(**Tu8)(__ccgo_up(page1 + 20)))
if pageSize != (*TBtShared)(unsafe.Pointer(pBt)).FpageSize {
/* After reading the first page of the database assuming a page size
** of BtShared.pageSize, we have discovered that the page-size is
** actually pageSize. Unlock the database, leave pBt->pPage1 at
** zero and return SQLITE_OK. The caller will call this function
** again with the correct page-size.
*/
_releasePageOne(tls, **(**uintptr)(__ccgo_up(bp)))
(*TBtShared)(unsafe.Pointer(pBt)).FusableSize = usableSize
(*TBtShared)(unsafe.Pointer(pBt)).FpageSize = pageSize
v1 = pBt + 40
*(*Tu16)(unsafe.Pointer(v1)) = Tu16(int32(*(*Tu16)(unsafe.Pointer(v1))) | libc.Int32FromInt32(BTS_PAGESIZE_FIXED))
_freeTempSpace(tls, pBt)
rc = _sqlite3PagerSetPagesize(tls, (*TBtShared)(unsafe.Pointer(pBt)).FpPager, pBt+52, libc.Int32FromUint32(pageSize-usableSize))
return rc
}
if nPage > **(**Tu32)(__ccgo_up(bp + 8)) {
if _sqlite3WritableSchema(tls, (*TBtShared)(unsafe.Pointer(pBt)).Fdb) == 0 {
rc = _sqlite3CorruptError(tls, int32(76633))
goto page1_init_failed
} else {
nPage = **(**Tu32)(__ccgo_up(bp + 8))
}
}
/* EVIDENCE-OF: R-28312-64704 However, the usable size is not allowed to
** be less than 480. In other words, if the page size is 512, then the
** reserved space size cannot exceed 32. */
if usableSize < uint32(480) {
goto page1_init_failed
}
v1 = pBt + 40
*(*Tu16)(unsafe.Pointer(v1)) = Tu16(int32(*(*Tu16)(unsafe.Pointer(v1))) | libc.Int32FromInt32(BTS_PAGESIZE_FIXED))
(*TBtShared)(unsafe.Pointer(pBt)).FpageSize = pageSize
(*TBtShared)(unsafe.Pointer(pBt)).FusableSize = usableSize
if _sqlite3Get4byte(tls, page1+uintptr(libc.Int32FromInt32(36)+libc.Int32FromInt32(4)*libc.Int32FromInt32(4))) != 0 {
v4 = int32(1)
} else {
v4 = 0
}
(*TBtShared)(unsafe.Pointer(pBt)).FautoVacuum = libc.Uint8FromInt32(v4)
if _sqlite3Get4byte(tls, page1+uintptr(libc.Int32FromInt32(36)+libc.Int32FromInt32(7)*libc.Int32FromInt32(4))) != 0 {
v4 = int32(1)
} else {
v4 = 0
}
(*TBtShared)(unsafe.Pointer(pBt)).FincrVacuum = libc.Uint8FromInt32(v4)
}
/* maxLocal is the maximum amount of payload to store locally for
** a cell. Make sure it is small enough so that at least minFanout
** cells can will fit on one page. We assume a 10-byte page header.
** Besides the payload, the cell must store:
** 2-byte pointer to the cell
** 4-byte child pointer
** 9-byte nKey value
** 4-byte nData value
** 4-byte overflow page pointer
** So a cell consists of a 2-byte pointer, a header which is as much as
** 17 bytes long, 0 to N bytes of payload, and an optional 4 byte overflow
** page pointer.
*/
(*TBtShared)(unsafe.Pointer(pBt)).FmaxLocal = uint16(((*TBtShared)(unsafe.Pointer(pBt)).FusableSize-libc.Uint32FromInt32(12))*libc.Uint32FromInt32(64)/libc.Uint32FromInt32(255) - libc.Uint32FromInt32(23))
(*TBtShared)(unsafe.Pointer(pBt)).FminLocal = uint16(((*TBtShared)(unsafe.Pointer(pBt)).FusableSize-libc.Uint32FromInt32(12))*libc.Uint32FromInt32(32)/libc.Uint32FromInt32(255) - libc.Uint32FromInt32(23))
(*TBtShared)(unsafe.Pointer(pBt)).FmaxLeaf = uint16((*TBtShared)(unsafe.Pointer(pBt)).FusableSize - libc.Uint32FromInt32(35))
(*TBtShared)(unsafe.Pointer(pBt)).FminLeaf = uint16(((*TBtShared)(unsafe.Pointer(pBt)).FusableSize-libc.Uint32FromInt32(12))*libc.Uint32FromInt32(32)/libc.Uint32FromInt32(255) - libc.Uint32FromInt32(23))
if libc.Int32FromUint16((*TBtShared)(unsafe.Pointer(pBt)).FmaxLocal) > int32(127) {
(*TBtShared)(unsafe.Pointer(pBt)).Fmax1bytePayload = uint8(127)
} else {
(*TBtShared)(unsafe.Pointer(pBt)).Fmax1bytePayload = uint8((*TBtShared)(unsafe.Pointer(pBt)).FmaxLocal)
}
(*TBtShared)(unsafe.Pointer(pBt)).FpPage1 = **(**uintptr)(__ccgo_up(bp))
(*TBtShared)(unsafe.Pointer(pBt)).FnPage = nPage
return SQLITE_OK
goto page1_init_failed
page1_init_failed:
;
_releasePageOne(tls, **(**uintptr)(__ccgo_up(bp)))
(*TBtShared)(unsafe.Pointer(pBt)).FpPage1 = uintptr(0)
return rc
}
// C documentation
//
// /*
// ** 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(64)
defer tls.Free(64)
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+8 */ 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)*32))).FzDbSName, zDb) == 0 {
pSchema = (**(**TDb)(__ccgo_up((*Tsqlite3)(unsafe.Pointer(db)).FaDb + uintptr(i)*32))).FpSchema
break
}
goto _1
_1:
;
i = i + 1
}
if i == (*Tsqlite3)(unsafe.Pointer(db)).FnDb && _sqlite3StrICmp(tls, __ccgo_ts+7164, 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 + 24 + 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 + 72)))).FpSelect
pEList = (*TSelect)(unsafe.Pointer(pSel)).FpEList
j = 0
for {
if !(j < (*TExprList)(unsafe.Pointer(pEList)).FnExpr) {
break
}
**(**int32)(__ccgo_up(bp + 8)) = 0 /* True if possible rowid match */
if !(_sqlite3MatchEName(tls, pEList+8+uintptr(j)*32, zCol, zTab, zDb, bp+8) != 0) {
goto _3
}
if **(**int32)(__ccgo_up(bp + 8)) == 0 {
if cnt > 0 {
if int32(*(*uint32)(unsafe.Pointer(pItem + 24 + 4))&0x800>>11) == 0 || _sqlite3IdListIndex(tls, *(*uintptr)(unsafe.Pointer(pItem + 64)), 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)*32+16+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)*32 + 16 + 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+7169) != 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+64)
}
}
j = _sqlite3ColumnIndex(tls, pTab, zCol)
if j >= 0 {
if cnt > 0 {
if int32(*(*uint32)(unsafe.Pointer(pItem + 24 + 4))&0x800>>11) == 0 || _sqlite3IdListIndex(tls, *(*uintptr)(unsafe.Pointer(pItem + 64)), 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 + 24 + 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 += 80
}
if pMatch != 0 {
(*TExpr)(unsafe.Pointer(pExpr)).FiTable = (*TSrcItem)(unsafe.Pointer(pMatch)).FiCursor
*(*uintptr)(unsafe.Pointer(pExpr + 64)) = (*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(*(*uintptr)(unsafe.Pointer(pExpr + 64)))).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 + 40))&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+7171, 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+7175, 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 + 16))
if pUpsert != 0 && _sqlite3StrICmp(tls, __ccgo_ts+7179, 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)
*(*uintptr)(unsafe.Pointer(pExpr + 64)) = pTab
eNewExprOp = int32(TK_COLUMN)
} else {
(*TExpr)(unsafe.Pointer(pExpr)).FiTable = (*TUpsert)(unsafe.Pointer(*(*uintptr)(unsafe.Pointer(pNC + 16)))).FregData + int32(_sqlite3TableColumnToStorage(tls, pTab, int16(iCol)))
eNewExprOp = int32(TK_REGISTER)
}
} else {
*(*uintptr)(unsafe.Pointer(pExpr + 64)) = pTab
if int32(Tbft(*(*uint16)(unsafe.Pointer(pParse + 40))&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(&(*TNameContext)(unsafe.Pointer(pNC)).FuNC)) + (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 + 248)) |= v5
} else {
if iCol >= int32(32) {
v5 = uint32(0xffffffff)
} else {
v5 = libc.Uint32FromInt32(1) << iCol
}
**(**Tu32)(__ccgo_up(pParse + 252)) |= 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 + 24 + 4))&0x4000>>14) != 0) {
cnt = cntTab
if int32(*(*uint32)(unsafe.Pointer(pMatch + 24 + 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 + 16))
j = 0
for {
if !(j < (*TExprList)(unsafe.Pointer(pEList)).FnExpr) {
break
}
zAs = (*(*TExprList_item)(unsafe.Pointer(pEList + 8 + uintptr(j)*32))).FzEName
if int32(uint32(*(*uint16)(unsafe.Pointer(pEList + 8 + uintptr(j)*32 + 16 + 4))&0x3>>0)) == ENAME_NAME && Xsqlite3_stricmp(tls, zAs, zCol) == 0 {
pOrig = (*(*TExprList_item)(unsafe.Pointer(pEList + 8 + uintptr(j)*32))).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+7188, libc.VaList(bp+24, 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+7219, libc.VaList(bp+24, zAs))
return int32(WRC_Abort)
}
if _sqlite3ExprVectorSize(tls, pOrig) != int32(1) {
_sqlite3ErrorMsg(tls, pParse, __ccgo_ts+7256, 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+7274, libc.VaList(bp+24, zCol))
(*TExpr)(unsafe.Pointer(pExpr)).Fop = uint8(TK_STRING)
libc.X__builtin___memset_chk(tls, pExpr+64, 0, uint64(8), ^t__predefined_size_t(0))
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 + 7309
*(*uintptr)(unsafe.Pointer(pExpr + 32)) = **(**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 + 7318
} else {
v8 = __ccgo_ts + 7333
}
zErr = v8
if zDb != 0 {
_sqlite3ErrorMsg(tls, pParse, __ccgo_ts+7355, libc.VaList(bp+24, zErr, zDb, zTab, zCol))
} else {
if zTab != 0 {
_sqlite3ErrorMsg(tls, pParse, __ccgo_ts+7368, libc.VaList(bp+24, 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+7378, libc.VaList(bp+24, zErr, zCol))
} else {
_sqlite3ErrorMsg(tls, pParse, __ccgo_ts+7439, libc.VaList(bp+24, zErr, zCol))
}
}
}
_sqlite3RecordErrorOffsetOfExpr(tls, (*TParse)(unsafe.Pointer(pParse)).Fdb, pExpr)
libc.SetBitFieldPtr16Uint32(pParse+40, 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 + 40)) |= _sqlite3ExprColUsed(tls, pExpr)
} else {
libc.SetBitFieldPtr32Uint32(pMatch+24+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
}
type _mach_port_guard_exception_codes = int32
// C documentation
//
// /*
// ** Tag the given column as being part of the PRIMARY KEY
// */
func _makeColumnPartOfPrimaryKey(tls *libc.TLS, pParse uintptr, pCol uintptr) {
var v1 uintptr
_ = v1
v1 = pCol + 14
*(*Tu16)(unsafe.Pointer(v1)) = Tu16(int32(*(*Tu16)(unsafe.Pointer(v1))) | libc.Int32FromInt32(COLFLAG_PRIMKEY))
if libc.Int32FromUint16((*TColumn)(unsafe.Pointer(pCol)).FcolFlags)&int32(COLFLAG_GENERATED) != 0 {
_sqlite3ErrorMsg(tls, pParse, __ccgo_ts+14456, 0)
}
}
// C documentation
//
// /*
// ** File control method. For custom operations on an memdb-file.
// */
func _memdbFileControl(tls *libc.TLS, pFile uintptr, op int32, pArg uintptr) (r int32) {
bp := tls.Alloc(32)
defer tls.Free(32)
var iLimit Tsqlite3_int64
var p uintptr
var rc int32
_, _, _ = iLimit, p, rc
p = (*TMemFile)(unsafe.Pointer(pFile)).FpStore
rc = int32(SQLITE_NOTFOUND)
_memdbEnter(tls, p)
if op == int32(SQLITE_FCNTL_VFSNAME) {
**(**uintptr)(__ccgo_up(pArg)) = Xsqlite3_mprintf(tls, __ccgo_ts+4466, libc.VaList(bp+8, (*TMemStore)(unsafe.Pointer(p)).FaData, (*TMemStore)(unsafe.Pointer(p)).Fsz))
rc = SQLITE_OK
}
if op == int32(SQLITE_FCNTL_SIZE_LIMIT) {
iLimit = **(**Tsqlite3_int64)(__ccgo_up(pArg))
if iLimit < (*TMemStore)(unsafe.Pointer(p)).Fsz {
if iLimit < 0 {
iLimit = (*TMemStore)(unsafe.Pointer(p)).FszMax
} else {
iLimit = (*TMemStore)(unsafe.Pointer(p)).Fsz
}
}
(*TMemStore)(unsafe.Pointer(p)).FszMax = iLimit
**(**Tsqlite3_int64)(__ccgo_up(pArg)) = iLimit
rc = SQLITE_OK
}
_memdbLeave(tls, p)
return rc
}
// C documentation
//
// /*
// ** Open an mem file handle.
// */
func _memdbOpen(tls *libc.TLS, pVfs uintptr, zName uintptr, pFd uintptr, flags int32, pOutFlags uintptr) (r int32) {
var apNew, p, pFile, pVfsMutex, v3 uintptr
var i, szName, v2 int32
_, _, _, _, _, _, _, _ = apNew, i, p, pFile, pVfsMutex, szName, v2, v3
pFile = pFd
p = uintptr(0)
_ = pVfs
libc.X__builtin___memset_chk(tls, pFile, 0, uint64(24), ^t__predefined_size_t(0))
szName = _sqlite3Strlen30(tls, zName)
if szName > int32(1) && (int32(**(**int8)(__ccgo_up(zName))) == int32('/') || int32(**(**int8)(__ccgo_up(zName))) == int32('\\')) {
pVfsMutex = _sqlite3MutexAlloc(tls, int32(SQLITE_MUTEX_STATIC_VFS1))
Xsqlite3_mutex_enter(tls, pVfsMutex)
i = 0
for {
if !(i < _memdb_g.FnMemStore) {
break
}
if libc.Xstrcmp(tls, (*TMemStore)(unsafe.Pointer(**(**uintptr)(__ccgo_up(_memdb_g.FapMemStore + uintptr(i)*8)))).FzFName, zName) == 0 {
p = **(**uintptr)(__ccgo_up(_memdb_g.FapMemStore + uintptr(i)*8))
break
}
goto _1
_1:
;
i = i + 1
}
if p == uintptr(0) {
p = _sqlite3Malloc(tls, uint64(72)+libc.Uint64FromInt64(int64(szName))+uint64(3))
if p == uintptr(0) {
Xsqlite3_mutex_leave(tls, pVfsMutex)
return int32(SQLITE_NOMEM)
}
apNew = _sqlite3Realloc(tls, _memdb_g.FapMemStore, uint64(8)*libc.Uint64FromInt64(libc.Int64FromInt32(1)+int64(_memdb_g.FnMemStore)))
if apNew == uintptr(0) {
Xsqlite3_free(tls, p)
Xsqlite3_mutex_leave(tls, pVfsMutex)
return int32(SQLITE_NOMEM)
}
v3 = uintptr(unsafe.Pointer(&_memdb_g))
v2 = *(*int32)(unsafe.Pointer(v3))
*(*int32)(unsafe.Pointer(v3)) = *(*int32)(unsafe.Pointer(v3)) + 1
**(**uintptr)(__ccgo_up(apNew + uintptr(v2)*8)) = p
_memdb_g.FapMemStore = apNew
libc.X__builtin___memset_chk(tls, p, 0, uint64(72), ^t__predefined_size_t(0))
(*TMemStore)(unsafe.Pointer(p)).FmFlags = libc.Uint32FromInt32(libc.Int32FromInt32(SQLITE_DESERIALIZE_RESIZEABLE) | libc.Int32FromInt32(SQLITE_DESERIALIZE_FREEONCLOSE))
(*TMemStore)(unsafe.Pointer(p)).FszMax = _sqlite3Config.FmxMemdbSize
(*TMemStore)(unsafe.Pointer(p)).FzFName = p + 1*72
libc.X__builtin___memcpy_chk(tls, (*TMemStore)(unsafe.Pointer(p)).FzFName, zName, libc.Uint64FromInt32(szName+int32(1)), ^t__predefined_size_t(0))
(*TMemStore)(unsafe.Pointer(p)).FpMutex = Xsqlite3_mutex_alloc(tls, SQLITE_MUTEX_FAST)
if (*TMemStore)(unsafe.Pointer(p)).FpMutex == uintptr(0) {
_memdb_g.FnMemStore = _memdb_g.FnMemStore - 1
Xsqlite3_free(tls, p)
Xsqlite3_mutex_leave(tls, pVfsMutex)
return int32(SQLITE_NOMEM)
}
(*TMemStore)(unsafe.Pointer(p)).FnRef = int32(1)
_memdbEnter(tls, p)
} else {
_memdbEnter(tls, p)
(*TMemStore)(unsafe.Pointer(p)).FnRef = (*TMemStore)(unsafe.Pointer(p)).FnRef + 1
}
Xsqlite3_mutex_leave(tls, pVfsMutex)
} else {
p = _sqlite3Malloc(tls, uint64(72))
if p == uintptr(0) {
return int32(SQLITE_NOMEM)
}
libc.X__builtin___memset_chk(tls, p, 0, uint64(72), ^t__predefined_size_t(0))
(*TMemStore)(unsafe.Pointer(p)).FmFlags = libc.Uint32FromInt32(libc.Int32FromInt32(SQLITE_DESERIALIZE_RESIZEABLE) | libc.Int32FromInt32(SQLITE_DESERIALIZE_FREEONCLOSE))
(*TMemStore)(unsafe.Pointer(p)).FszMax = _sqlite3Config.FmxMemdbSize
}
(*TMemFile)(unsafe.Pointer(pFile)).FpStore = p
if pOutFlags != uintptr(0) {
**(**int32)(__ccgo_up(pOutFlags)) = flags | int32(SQLITE_OPEN_MEMORY)
}
(*Tsqlite3_file)(unsafe.Pointer(pFd)).FpMethods = uintptr(unsafe.Pointer(&_memdb_io_methods))
_memdbLeave(tls, p)
return SQLITE_OK
}
// C documentation
//
// /*
// ** Read data from an memdb-file.
// */
func _memdbRead(tls *libc.TLS, pFile uintptr, zBuf uintptr, iAmt int32, iOfst Tsqlite_int64) (r int32) {
var p uintptr
_ = p
p = (*TMemFile)(unsafe.Pointer(pFile)).FpStore
_memdbEnter(tls, p)
if iOfst+int64(iAmt) > (*TMemStore)(unsafe.Pointer(p)).Fsz {
libc.X__builtin___memset_chk(tls, zBuf, 0, libc.Uint64FromInt32(iAmt), ^t__predefined_size_t(0))
if iOfst < (*TMemStore)(unsafe.Pointer(p)).Fsz {
libc.X__builtin___memcpy_chk(tls, zBuf, (*TMemStore)(unsafe.Pointer(p)).FaData+uintptr(iOfst), libc.Uint64FromInt64((*TMemStore)(unsafe.Pointer(p)).Fsz-iOfst), ^t__predefined_size_t(0))
}
_memdbLeave(tls, p)
return libc.Int32FromInt32(SQLITE_IOERR) | libc.Int32FromInt32(2)< (*TMemStore)(unsafe.Pointer(p)).Fsz {
if v2 = iOfst+int64(iAmt) > (*TMemStore)(unsafe.Pointer(p)).FszAlloc; v2 {
v1 = _memdbEnlarge(tls, p, iOfst+int64(iAmt))
rc = v1
}
if v2 && v1 != SQLITE_OK {
_memdbLeave(tls, p)
return rc
}
if iOfst > (*TMemStore)(unsafe.Pointer(p)).Fsz {
libc.X__builtin___memset_chk(tls, (*TMemStore)(unsafe.Pointer(p)).FaData+uintptr((*TMemStore)(unsafe.Pointer(p)).Fsz), 0, libc.Uint64FromInt64(iOfst-(*TMemStore)(unsafe.Pointer(p)).Fsz), ^t__predefined_size_t(0))
}
(*TMemStore)(unsafe.Pointer(p)).Fsz = iOfst + int64(iAmt)
}
libc.X__builtin___memcpy_chk(tls, (*TMemStore)(unsafe.Pointer(p)).FaData+uintptr(iOfst), z, libc.Uint64FromInt32(iAmt), ^t__predefined_size_t(0))
_memdbLeave(tls, p)
return SQLITE_OK
}
var _memdb_vfs = Tsqlite3_vfs{
FiVersion: int32(2),
FmxPathname: int32(1024),
FzName: __ccgo_ts + 4460,
}
// C documentation
//
// /*
// ** Flush the contents of memory to a real file on disk.
// */
func _memjrnlCreateFile(tls *libc.TLS, p uintptr) (r int32) {
var copy1 TMemJournal
var iOff Ti64
var nChunk, rc int32
var pIter, pReal uintptr
_, _, _, _, _, _ = copy1, iOff, nChunk, pIter, pReal, rc
pReal = p
copy1 = **(**TMemJournal)(__ccgo_up(p))
libc.X__builtin___memset_chk(tls, p, 0, uint64(80), ^t__predefined_size_t(0))
rc = _sqlite3OsOpen(tls, copy1.FpVfs, copy1.FzJournal, pReal, copy1.Fflags, uintptr(0))
if rc == SQLITE_OK {
nChunk = copy1.FnChunkSize
iOff = 0
pIter = copy1.FpFirst
for {
if !(pIter != 0) {
break
}
if iOff+int64(nChunk) > copy1.Fendpoint.FiOffset {
nChunk = int32(copy1.Fendpoint.FiOffset - iOff)
}
rc = _sqlite3OsWrite(tls, pReal, pIter+8, nChunk, iOff)
if rc != 0 {
break
}
iOff = iOff + int64(nChunk)
goto _1
_1:
;
pIter = (*TFileChunk)(unsafe.Pointer(pIter)).FpNext
}
if rc == SQLITE_OK {
/* No error has occurred. Free the in-memory buffers. */
_memjrnlFreeChunks(tls, copy1.FpFirst)
}
}
if rc != SQLITE_OK {
/* If an error occurred while creating or writing to the file, restore
** the original before returning. This way, SQLite uses the in-memory
** journal data to roll back changes made to the internal page-cache
** before this function was called. */
_sqlite3OsClose(tls, pReal)
**(**TMemJournal)(__ccgo_up(p)) = copy1
}
return rc
}
// C documentation
//
// /*
// ** Read data from the in-memory journal file. This is the implementation
// ** of the sqlite3_vfs.xRead method.
// */
func _memjrnlRead(tls *libc.TLS, pJfd uintptr, zBuf uintptr, iAmt int32, iOfst Tsqlite_int64) (r int32) {
var iChunkOffset, iSpace, nCopy, nRead, v5 int32
var iOff Tsqlite3_int64
var p, pChunk, zOut, v2 uintptr
var v3 bool
var v6 int64
_, _, _, _, _, _, _, _, _, _, _, _ = iChunkOffset, iOff, iSpace, nCopy, nRead, p, pChunk, zOut, v2, v3, v5, v6
p = pJfd
zOut = zBuf
nRead = iAmt
if int64(iAmt)+iOfst > (*TMemJournal)(unsafe.Pointer(p)).Fendpoint.FiOffset {
return libc.Int32FromInt32(SQLITE_IOERR) | libc.Int32FromInt32(2)<= 0; v3 {
v2 = (*TFileChunk)(unsafe.Pointer(pChunk)).FpNext
pChunk = v2
}
if !(v3 && v2 != uintptr(0) && nRead > 0) {
break
}
}
if pChunk != 0 {
v6 = iOfst + int64(iAmt)
} else {
v6 = 0
}
(*TMemJournal)(unsafe.Pointer(p)).Freadpoint.FiOffset = v6
(*TMemJournal)(unsafe.Pointer(p)).Freadpoint.FpChunk = pChunk
return SQLITE_OK
}
// C documentation
//
// /*
// ** Write data to the file.
// */
func _memjrnlWrite(tls *libc.TLS, pJfd uintptr, zBuf uintptr, iAmt int32, iOfst Tsqlite_int64) (r int32) {
var iChunkOffset, iSpace, nWrite, rc, v1 int32
var p, pChunk, pNew, zWrite, v2 uintptr
_, _, _, _, _, _, _, _, _, _ = iChunkOffset, iSpace, nWrite, p, pChunk, pNew, rc, zWrite, v1, v2
p = pJfd
nWrite = iAmt
zWrite = zBuf
/* If the file should be created now, create it and write the new data
** into the file on disk. */
if (*TMemJournal)(unsafe.Pointer(p)).FnSpill > 0 && int64(iAmt)+iOfst > int64((*TMemJournal)(unsafe.Pointer(p)).FnSpill) {
rc = _memjrnlCreateFile(tls, p)
if rc == SQLITE_OK {
rc = _sqlite3OsWrite(tls, pJfd, zBuf, iAmt, iOfst)
}
return rc
} else {
/* An in-memory journal file should only ever be appended to. Random
** access writes are not required. The only exception to this is when
** the in-memory journal is being used by a connection using the
** atomic-write optimization. In this case the first 28 bytes of the
** journal file may be written as part of committing the transaction. */
if iOfst > 0 && iOfst != (*TMemJournal)(unsafe.Pointer(p)).Fendpoint.FiOffset {
_memjrnlTruncate(tls, pJfd, iOfst)
}
if iOfst == 0 && (*TMemJournal)(unsafe.Pointer(p)).FpFirst != 0 {
libc.X__builtin___memcpy_chk(tls, (*TMemJournal)(unsafe.Pointer(p)).FpFirst+8, zBuf, libc.Uint64FromInt32(iAmt), ^t__predefined_size_t(0))
} else {
for nWrite > 0 {
pChunk = (*TMemJournal)(unsafe.Pointer(p)).Fendpoint.FpChunk
iChunkOffset = int32((*TMemJournal)(unsafe.Pointer(p)).Fendpoint.FiOffset % int64((*TMemJournal)(unsafe.Pointer(p)).FnChunkSize))
if nWrite < (*TMemJournal)(unsafe.Pointer(p)).FnChunkSize-iChunkOffset {
v1 = nWrite
} else {
v1 = (*TMemJournal)(unsafe.Pointer(p)).FnChunkSize - iChunkOffset
}
iSpace = v1
if iChunkOffset == 0 {
/* New chunk is required to extend the file. */
pNew = Xsqlite3_malloc(tls, libc.Int32FromUint64(libc.Uint64FromInt64(16)+libc.Uint64FromInt32((*TMemJournal)(unsafe.Pointer(p)).FnChunkSize-libc.Int32FromInt32(8))))
if !(pNew != 0) {
return libc.Int32FromInt32(SQLITE_IOERR) | libc.Int32FromInt32(12)<pPrior. The left query could also be a compound query
// ** in which case this routine will be called recursively.
// **
// ** The results of the total query are to be written into a destination
// ** of type eDest with parameter iParm.
// **
// ** Example 1: Consider a three-way compound SQL statement.
// **
// ** SELECT a FROM t1 UNION SELECT b FROM t2 UNION SELECT c FROM t3
// **
// ** This statement is parsed up as follows:
// **
// ** SELECT c FROM t3
// ** |
// ** `-----> SELECT b FROM t2
// ** |
// ** `------> SELECT a FROM t1
// **
// ** The arrows in the diagram above represent the Select.pPrior pointer.
// ** So if this routine is called with p equal to the t3 query, then
// ** pPrior will be the t2 query. p->op will be TK_UNION in this case.
// **
// ** Notice that because of the way SQLite parses compound SELECTs, the
// ** individual selects always group from left to right.
// */
func _multiSelect(tls *libc.TLS, pParse uintptr, p uintptr, pDest uintptr) (r int32) {
bp := tls.Alloc(48)
defer tls.Free(48)
var addr, rc int32
var db, pDelete, pOne, pPrior, v uintptr
var _ /* dest at bp+0 */ TSelectDest
var _ /* nLimit at bp+40 */ int32
_, _, _, _, _, _, _ = addr, db, pDelete, pOne, pPrior, rc, v
rc = SQLITE_OK /* Alternative data destination */
pDelete = uintptr(0) /* Database connection */
/* Make sure there is no ORDER BY or LIMIT clause on prior SELECTs. Only
** the last (right-most) SELECT in the series may have an ORDER BY or LIMIT.
*/
/* Calling function guarantees this much */
db = (*TParse)(unsafe.Pointer(pParse)).Fdb
pPrior = (*TSelect)(unsafe.Pointer(p)).FpPrior
**(**TSelectDest)(__ccgo_up(bp)) = **(**TSelectDest)(__ccgo_up(pDest))
v = _sqlite3GetVdbe(tls, pParse)
/* The VDBE already created by calling function */
/* Create the destination temporary table if necessary
*/
if libc.Int32FromUint8((**(**TSelectDest)(__ccgo_up(bp))).FeDest) == int32(SRT_EphemTab) {
_sqlite3VdbeAddOp2(tls, v, int32(OP_OpenEphemeral), (**(**TSelectDest)(__ccgo_up(bp))).FiSDParm, (*TExprList)(unsafe.Pointer((*TSelect)(unsafe.Pointer(p)).FpEList)).FnExpr)
(**(**TSelectDest)(__ccgo_up(bp))).FeDest = uint8(SRT_Table)
}
/* Special handling for a compound-select that originates as a VALUES clause.
*/
if (*TSelect)(unsafe.Pointer(p)).FselFlags&uint32(SF_MultiValue) != 0 {
rc = _multiSelectValues(tls, pParse, p, bp)
if rc >= 0 {
goto multi_select_end
}
rc = SQLITE_OK
}
/* Make sure all SELECTs in the statement have the same number of elements
** in their result sets.
*/
if (*TSelect)(unsafe.Pointer(p)).FselFlags&uint32(SF_Recursive) != uint32(0) && _hasAnchor(tls, p) != 0 {
_generateWithRecursiveQuery(tls, pParse, p, bp)
} else {
if (*TSelect)(unsafe.Pointer(p)).FpOrderBy != 0 {
/* If the compound has an ORDER BY clause, then always use the merge
** algorithm. */
return _multiSelectByMerge(tls, pParse, p, pDest)
} else {
if libc.Int32FromUint8((*TSelect)(unsafe.Pointer(p)).Fop) != int32(TK_ALL) {
/* If the compound is EXCEPT, INTERSECT, or UNION (anything other than
** UNION ALL) then also always use the merge algorithm. However, the
** multiSelectByMerge() routine requires that the compound have an
** ORDER BY clause, and it doesn't right now. So invent one first. */
pOne = _sqlite3ExprInt32(tls, db, int32(1))
(*TSelect)(unsafe.Pointer(p)).FpOrderBy = _sqlite3ExprListAppend(tls, pParse, uintptr(0), pOne)
if (*TParse)(unsafe.Pointer(pParse)).FnErr != 0 {
goto multi_select_end
}
*(*Tu16)(unsafe.Pointer((*TSelect)(unsafe.Pointer(p)).FpOrderBy + 8 + 24)) = uint16(1)
return _multiSelectByMerge(tls, pParse, p, pDest)
} else {
/* For a UNION ALL compound without ORDER BY, simply run the left
** query, then run the right query */
addr = 0
**(**int32)(__ccgo_up(bp + 40)) = 0 /* Initialize to suppress harmless compiler warning */
if (*TSelect)(unsafe.Pointer(pPrior)).FpPrior == uintptr(0) {
_sqlite3VdbeExplain(tls, pParse, uint8(1), __ccgo_ts+21225, 0)
_sqlite3VdbeExplain(tls, pParse, uint8(1), __ccgo_ts+21240, 0)
}
(*TSelect)(unsafe.Pointer(pPrior)).FiLimit = (*TSelect)(unsafe.Pointer(p)).FiLimit
(*TSelect)(unsafe.Pointer(pPrior)).FiOffset = (*TSelect)(unsafe.Pointer(p)).FiOffset
(*TSelect)(unsafe.Pointer(pPrior)).FpLimit = _sqlite3ExprDup(tls, db, (*TSelect)(unsafe.Pointer(p)).FpLimit, 0)
rc = _sqlite3Select(tls, pParse, pPrior, bp)
_sqlite3ExprDelete(tls, db, (*TSelect)(unsafe.Pointer(pPrior)).FpLimit)
(*TSelect)(unsafe.Pointer(pPrior)).FpLimit = uintptr(0)
if rc != 0 {
goto multi_select_end
}
(*TSelect)(unsafe.Pointer(p)).FpPrior = uintptr(0)
(*TSelect)(unsafe.Pointer(p)).FiLimit = (*TSelect)(unsafe.Pointer(pPrior)).FiLimit
(*TSelect)(unsafe.Pointer(p)).FiOffset = (*TSelect)(unsafe.Pointer(pPrior)).FiOffset
if (*TSelect)(unsafe.Pointer(p)).FiLimit != 0 {
addr = _sqlite3VdbeAddOp1(tls, v, int32(OP_IfNot), (*TSelect)(unsafe.Pointer(p)).FiLimit)
if (*TSelect)(unsafe.Pointer(p)).FiOffset != 0 {
_sqlite3VdbeAddOp3(tls, v, int32(OP_OffsetLimit), (*TSelect)(unsafe.Pointer(p)).FiLimit, (*TSelect)(unsafe.Pointer(p)).FiOffset+int32(1), (*TSelect)(unsafe.Pointer(p)).FiOffset)
}
}
_sqlite3VdbeExplain(tls, pParse, uint8(1), __ccgo_ts+20882, 0)
rc = _sqlite3Select(tls, pParse, p, bp)
pDelete = (*TSelect)(unsafe.Pointer(p)).FpPrior
(*TSelect)(unsafe.Pointer(p)).FpPrior = pPrior
(*TSelect)(unsafe.Pointer(p)).FnSelectRow = _sqlite3LogEstAdd(tls, (*TSelect)(unsafe.Pointer(p)).FnSelectRow, (*TSelect)(unsafe.Pointer(pPrior)).FnSelectRow)
if (*TSelect)(unsafe.Pointer(p)).FpLimit != 0 && _sqlite3ExprIsInteger(tls, (*TExpr)(unsafe.Pointer((*TSelect)(unsafe.Pointer(p)).FpLimit)).FpLeft, bp+40, pParse) != 0 && **(**int32)(__ccgo_up(bp + 40)) > 0 && int32((*TSelect)(unsafe.Pointer(p)).FnSelectRow) > int32(_sqlite3LogEst(tls, libc.Uint64FromInt32(**(**int32)(__ccgo_up(bp + 40))))) {
(*TSelect)(unsafe.Pointer(p)).FnSelectRow = _sqlite3LogEst(tls, libc.Uint64FromInt32(**(**int32)(__ccgo_up(bp + 40))))
}
if addr != 0 {
_sqlite3VdbeJumpHere(tls, v, addr)
}
if (*TSelect)(unsafe.Pointer(p)).FpNext == uintptr(0) {
_sqlite3VdbeExplainPop(tls, pParse)
}
}
}
}
goto multi_select_end
multi_select_end:
;
(*TSelectDest)(unsafe.Pointer(pDest)).FiSdst = (**(**TSelectDest)(__ccgo_up(bp))).FiSdst
(*TSelectDest)(unsafe.Pointer(pDest)).FnSdst = (**(**TSelectDest)(__ccgo_up(bp))).FnSdst
(*TSelectDest)(unsafe.Pointer(pDest)).FiSDParm2 = (**(**TSelectDest)(__ccgo_up(bp))).FiSDParm2
if pDelete != 0 {
_sqlite3ParserAddCleanup(tls, pParse, __ccgo_fp(_sqlite3SelectDeleteGeneric), pDelete)
}
return rc
}
// C documentation
//
// /*
// ** Generate code for a compound SELECT statement using a merge
// ** algorithm. The compound must have an ORDER BY clause for this
// ** to work.
// **
// ** We assume a query of the following form:
// **
// ** ORDER BY
// **
// ** is one of UNION ALL, UNION, EXCEPT, or INTERSECT. The idea
// ** is to code both and with the ORDER BY clause as
// ** co-routines. Then run the co-routines in parallel and merge the results
// ** into the output. In addition to the two coroutines (called selectA and
// ** selectB) there are 7 subroutines:
// **
// ** outA: Move the output of the selectA coroutine into the output
// ** of the compound query.
// **
// ** outB: Move the output of the selectB coroutine into the output
// ** of the compound query. (Only generated for UNION and
// ** UNION ALL. EXCEPT and INTERSECT never output a row that
// ** appears only in B.)
// **
// ** AltB: Called when there is data from both coroutines and AB.
// **
// ** EofA: Called when data is exhausted from selectA.
// **
// ** EofB: Called when data is exhausted from selectB.
// **
// ** The implementation of the latter five subroutines depend on which
// ** is used:
// **
// **
// ** UNION ALL UNION EXCEPT INTERSECT
// ** ------------- ----------------- -------------- -----------------
// ** AltB: outA, nextA outA, nextA outA, nextA nextA
// **
// ** AeqB: outA, nextA nextA nextA outA, nextA
// **
// ** AgtB: outB, nextB outB, nextB nextB nextB
// **
// ** EofA: outB, nextB outB, nextB halt halt
// **
// ** EofB: outA, nextA outA, nextA outA, nextA halt
// **
// ** In the AltB, AeqB, and AgtB subroutines, an EOF on A following nextA
// ** causes an immediate jump to EofA and an EOF on B following nextB causes
// ** an immediate jump to EofB. Within EofA and EofB, and EOF on entry or
// ** following nextX causes a jump to the end of the select processing.
// **
// ** Duplicate removal in the UNION, EXCEPT, and INTERSECT cases is handled
// ** within the output subroutine. The regPrev register set holds the previously
// ** output value. A comparison is made against this value and the output
// ** is skipped if the next results would be the same as the previous.
// **
// ** The implementation plan is to implement the two coroutines and seven
// ** subroutines first, then put the control logic at the bottom. Like this:
// **
// ** goto Init
// ** coA: coroutine for left query (A)
// ** coB: coroutine for right query (B)
// ** outA: output one row of A
// ** outB: output one row of B (UNION and UNION ALL only)
// ** EofA: ...
// ** EofB: ...
// ** AltB: ...
// ** AeqB: ...
// ** AgtB: ...
// ** Init: initialize coroutine registers
// ** yield coA, on eof goto EofA
// ** yield coB, on eof goto EofB
// ** Cmpr: Compare A, B
// ** Jump AltB, AeqB, AgtB
// ** End: ...
// **
// ** We call AltB, AeqB, AgtB, EofA, and EofB "subroutines" but they are not
// ** actually called using Gosub and they do not Return. EofA and EofB loop
// ** until all data is exhausted then jump to the "end" label. AltB, AeqB,
// ** and AgtB jump to either Cmpr or to one of EofA or EofB.
// */
func _multiSelectByMerge(tls *libc.TLS, pParse uintptr, p uintptr, pDest uintptr) (r int32) {
bp := tls.Alloc(96)
defer tls.Free(96)
var aPermute, db, pItem, pItem1, pKeyDup, pKeyMerge, pNew, pOrderBy, pPrior, pSplit, v, v3 uintptr
var addr1, addrAeqB, addrAgtB, addrAltB, addrEofA, addrEofA_noB, addrEofB, addrOutA, addrOutB, addrSelectA, addrSelectB, bKeep, i, j, labelCmpr, labelEnd, nExpr, nOrderBy, nSelect, op, regAddrA, regAddrB, regLimitA, regLimitB, regOutA, regOutB, regPrev, savedLimit, savedOffset, v4 int32
var _ /* destA at bp+0 */ TSelectDest
var _ /* destB at bp+40 */ TSelectDest
_, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _ = aPermute, addr1, addrAeqB, addrAgtB, addrAltB, addrEofA, addrEofA_noB, addrEofB, addrOutA, addrOutB, addrSelectA, addrSelectB, bKeep, db, i, j, labelCmpr, labelEnd, nExpr, nOrderBy, nSelect, op, pItem, pItem1, pKeyDup, pKeyMerge, pNew, pOrderBy, pPrior, pSplit, regAddrA, regAddrB, regLimitA, regLimitB, regOutA, regOutB, regPrev, savedLimit, savedOffset, v, v3, v4 /* Address of the output-A subroutine */
addrOutB = 0 /* One of TK_ALL, TK_UNION, TK_EXCEPT, TK_INTERSECT */
pKeyDup = uintptr(0) /* Mapping from ORDER BY terms to result set columns */
/* "Managed" code needs this. Ticket #3382. */
db = (*TParse)(unsafe.Pointer(pParse)).Fdb
v = (*TParse)(unsafe.Pointer(pParse)).FpVdbe
/* Already thrown the error if VDBE alloc failed */
labelEnd = _sqlite3VdbeMakeLabel(tls, pParse)
labelCmpr = _sqlite3VdbeMakeLabel(tls, pParse)
/* Patch up the ORDER BY clause
*/
op = libc.Int32FromUint8((*TSelect)(unsafe.Pointer(p)).Fop)
pOrderBy = (*TSelect)(unsafe.Pointer(p)).FpOrderBy
nOrderBy = (*TExprList)(unsafe.Pointer(pOrderBy)).FnExpr
/* For operators other than UNION ALL we have to make sure that
** the ORDER BY clause covers every term of the result set. Add
** terms to the ORDER BY clause as necessary.
*/
if op != int32(TK_ALL) {
i = int32(1)
for {
if !(libc.Int32FromUint8((*Tsqlite3)(unsafe.Pointer(db)).FmallocFailed) == 0 && i <= (*TExprList)(unsafe.Pointer((*TSelect)(unsafe.Pointer(p)).FpEList)).FnExpr) {
break
}
j = 0
pItem = pOrderBy + 8
for {
if !(j < nOrderBy) {
break
}
if libc.Int32FromUint16((*(*struct {
FiOrderByCol Tu16
FiAlias Tu16
})(unsafe.Pointer(pItem + 24))).FiOrderByCol) == i {
break
}
goto _2
_2:
;
j = j + 1
pItem += 32
}
if j == nOrderBy {
pNew = _sqlite3ExprInt32(tls, db, i)
if pNew == uintptr(0) {
return int32(SQLITE_NOMEM)
}
v3 = _sqlite3ExprListAppend(tls, pParse, pOrderBy, pNew)
pOrderBy = v3
(*TSelect)(unsafe.Pointer(p)).FpOrderBy = v3
if pOrderBy != 0 {
v4 = nOrderBy
nOrderBy = nOrderBy + 1
*(*Tu16)(unsafe.Pointer(pOrderBy + 8 + uintptr(v4)*32 + 24)) = libc.Uint16FromInt32(i)
}
}
goto _1
_1:
;
i = i + 1
}
}
/* Compute the comparison permutation and keyinfo that is used with
** the permutation to determine if the next row of results comes
** from selectA or selectB. Also add literal collations to the
** ORDER BY clause terms so that when selectA and selectB are
** evaluated, they use the correct collation.
*/
aPermute = _sqlite3DbMallocRawNN(tls, db, uint64(uint64(4)*libc.Uint64FromInt32(nOrderBy+libc.Int32FromInt32(1))))
if aPermute != 0 {
bKeep = 0
**(**Tu32)(__ccgo_up(aPermute)) = libc.Uint32FromInt32(nOrderBy)
i = int32(1)
pItem1 = pOrderBy + 8
for {
if !(i <= nOrderBy) {
break
}
**(**Tu32)(__ccgo_up(aPermute + uintptr(i)*4)) = libc.Uint32FromInt32(libc.Int32FromUint16((*(*struct {
FiOrderByCol Tu16
FiAlias Tu16
})(unsafe.Pointer(pItem1 + 24))).FiOrderByCol) - int32(1))
if **(**Tu32)(__ccgo_up(aPermute + uintptr(i)*4)) != libc.Uint32FromInt32(i)-uint32(1) {
bKeep = int32(1)
}
goto _5
_5:
;
i = i + 1
pItem1 += 32
}
if bKeep == 0 {
_sqlite3DbFreeNN(tls, db, aPermute)
aPermute = uintptr(0)
}
}
pKeyMerge = _multiSelectByMergeKeyInfo(tls, pParse, p, int32(1))
/* Allocate a range of temporary registers and the KeyInfo needed
** for the logic that removes duplicate result rows when the
** operator is UNION, EXCEPT, or INTERSECT (but not UNION ALL).
*/
if op == int32(TK_ALL) {
regPrev = 0
} else {
nExpr = (*TExprList)(unsafe.Pointer((*TSelect)(unsafe.Pointer(p)).FpEList)).FnExpr
regPrev = (*TParse)(unsafe.Pointer(pParse)).FnMem + int32(1)
**(**int32)(__ccgo_up(pParse + 60)) += nExpr + int32(1)
_sqlite3VdbeAddOp2(tls, v, int32(OP_Integer), 0, regPrev)
pKeyDup = _sqlite3KeyInfoAlloc(tls, db, nExpr, int32(1))
if pKeyDup != 0 {
i = 0
for {
if !(i < nExpr) {
break
}
*(*uintptr)(unsafe.Pointer(pKeyDup + 32 + uintptr(i)*8)) = _multiSelectCollSeq(tls, pParse, p, i)
**(**Tu8)(__ccgo_up((*TKeyInfo)(unsafe.Pointer(pKeyDup)).FaSortFlags + uintptr(i))) = uint8(0)
goto _6
_6:
;
i = i + 1
}
}
}
/* Separate the left and the right query from one another
*/
nSelect = int32(1)
if (op == int32(TK_ALL) || op == int32(TK_UNION)) && (*Tsqlite3)(unsafe.Pointer(db)).FdbOptFlags&libc.Uint32FromInt32(libc.Int32FromInt32(SQLITE_BalancedMerge)) == uint32(0) {
pSplit = p
for {
if !((*TSelect)(unsafe.Pointer(pSplit)).FpPrior != uintptr(0) && libc.Int32FromUint8((*TSelect)(unsafe.Pointer(pSplit)).Fop) == op) {
break
}
nSelect = nSelect + 1
goto _7
_7:
;
pSplit = (*TSelect)(unsafe.Pointer(pSplit)).FpPrior
}
}
if nSelect <= int32(3) {
pSplit = p
} else {
pSplit = p
i = int32(2)
for {
if !(i < nSelect) {
break
}
pSplit = (*TSelect)(unsafe.Pointer(pSplit)).FpPrior
goto _8
_8:
;
i = i + int32(2)
}
}
pPrior = (*TSelect)(unsafe.Pointer(pSplit)).FpPrior
(*TSelect)(unsafe.Pointer(pSplit)).FpPrior = uintptr(0)
(*TSelect)(unsafe.Pointer(pPrior)).FpNext = uintptr(0)
(*TSelect)(unsafe.Pointer(pPrior)).FpOrderBy = _sqlite3ExprListDup(tls, (*TParse)(unsafe.Pointer(pParse)).Fdb, pOrderBy, 0)
_sqlite3ResolveOrderGroupBy(tls, pParse, p, (*TSelect)(unsafe.Pointer(p)).FpOrderBy, __ccgo_ts+8007)
_sqlite3ResolveOrderGroupBy(tls, pParse, pPrior, (*TSelect)(unsafe.Pointer(pPrior)).FpOrderBy, __ccgo_ts+8007)
/* Compute the limit registers */
_computeLimitRegisters(tls, pParse, p, labelEnd)
if (*TSelect)(unsafe.Pointer(p)).FiLimit != 0 && op == int32(TK_ALL) {
v3 = pParse + 60
*(*int32)(unsafe.Pointer(v3)) = *(*int32)(unsafe.Pointer(v3)) + 1
v4 = *(*int32)(unsafe.Pointer(v3))
regLimitA = v4
v3 = pParse + 60
*(*int32)(unsafe.Pointer(v3)) = *(*int32)(unsafe.Pointer(v3)) + 1
v4 = *(*int32)(unsafe.Pointer(v3))
regLimitB = v4
if (*TSelect)(unsafe.Pointer(p)).FiOffset != 0 {
v4 = (*TSelect)(unsafe.Pointer(p)).FiOffset + int32(1)
} else {
v4 = (*TSelect)(unsafe.Pointer(p)).FiLimit
}
_sqlite3VdbeAddOp2(tls, v, int32(OP_Copy), v4, regLimitA)
_sqlite3VdbeAddOp2(tls, v, int32(OP_Copy), regLimitA, regLimitB)
} else {
v4 = libc.Int32FromInt32(0)
regLimitB = v4
regLimitA = v4
}
_sqlite3ExprDelete(tls, db, (*TSelect)(unsafe.Pointer(p)).FpLimit)
(*TSelect)(unsafe.Pointer(p)).FpLimit = uintptr(0)
v3 = pParse + 60
*(*int32)(unsafe.Pointer(v3)) = *(*int32)(unsafe.Pointer(v3)) + 1
v4 = *(*int32)(unsafe.Pointer(v3))
regAddrA = v4
v3 = pParse + 60
*(*int32)(unsafe.Pointer(v3)) = *(*int32)(unsafe.Pointer(v3)) + 1
v4 = *(*int32)(unsafe.Pointer(v3))
regAddrB = v4
v3 = pParse + 60
*(*int32)(unsafe.Pointer(v3)) = *(*int32)(unsafe.Pointer(v3)) + 1
v4 = *(*int32)(unsafe.Pointer(v3))
regOutA = v4
v3 = pParse + 60
*(*int32)(unsafe.Pointer(v3)) = *(*int32)(unsafe.Pointer(v3)) + 1
v4 = *(*int32)(unsafe.Pointer(v3))
regOutB = v4
_sqlite3SelectDestInit(tls, bp, int32(SRT_Coroutine), regAddrA)
_sqlite3SelectDestInit(tls, bp+40, int32(SRT_Coroutine), regAddrB)
_sqlite3VdbeExplain(tls, pParse, uint8(1), __ccgo_ts+21387, libc.VaList(bp+88, _sqlite3SelectOpName(tls, libc.Int32FromUint8((*TSelect)(unsafe.Pointer(p)).Fop))))
/* Generate a coroutine to evaluate the SELECT statement to the
** left of the compound operator - the "A" select.
*/
addrSelectA = _sqlite3VdbeCurrentAddr(tls, v) + int32(1)
addr1 = _sqlite3VdbeAddOp3(tls, v, int32(OP_InitCoroutine), regAddrA, 0, addrSelectA)
(*TSelect)(unsafe.Pointer(pPrior)).FiLimit = regLimitA
_sqlite3VdbeExplain(tls, pParse, uint8(1), __ccgo_ts+21398, 0)
_sqlite3Select(tls, pParse, pPrior, bp)
_sqlite3VdbeEndCoroutine(tls, v, regAddrA)
_sqlite3VdbeJumpHere(tls, v, addr1)
/* Generate a coroutine to evaluate the SELECT statement on
** the right - the "B" select
*/
addrSelectB = _sqlite3VdbeCurrentAddr(tls, v) + int32(1)
addr1 = _sqlite3VdbeAddOp3(tls, v, int32(OP_InitCoroutine), regAddrB, 0, addrSelectB)
savedLimit = (*TSelect)(unsafe.Pointer(p)).FiLimit
savedOffset = (*TSelect)(unsafe.Pointer(p)).FiOffset
(*TSelect)(unsafe.Pointer(p)).FiLimit = regLimitB
(*TSelect)(unsafe.Pointer(p)).FiOffset = 0
_sqlite3VdbeExplain(tls, pParse, uint8(1), __ccgo_ts+21403, 0)
_sqlite3Select(tls, pParse, p, bp+40)
(*TSelect)(unsafe.Pointer(p)).FiLimit = savedLimit
(*TSelect)(unsafe.Pointer(p)).FiOffset = savedOffset
_sqlite3VdbeEndCoroutine(tls, v, regAddrB)
/* Generate a subroutine that outputs the current row of the A
** select as the next output row of the compound select.
*/
addrOutA = _generateOutputSubroutine(tls, pParse, p, bp, pDest, regOutA, regPrev, pKeyDup, labelEnd)
/* Generate a subroutine that outputs the current row of the B
** select as the next output row of the compound select.
*/
if op == int32(TK_ALL) || op == int32(TK_UNION) {
addrOutB = _generateOutputSubroutine(tls, pParse, p, bp+40, pDest, regOutB, regPrev, pKeyDup, labelEnd)
}
_sqlite3KeyInfoUnref(tls, pKeyDup)
/* Generate a subroutine to run when the results from select A
** are exhausted and only data in select B remains.
*/
if op == int32(TK_EXCEPT) || op == int32(TK_INTERSECT) {
v4 = labelEnd
addrEofA = v4
addrEofA_noB = v4
} else {
addrEofA = _sqlite3VdbeAddOp2(tls, v, int32(OP_Gosub), regOutB, addrOutB)
addrEofA_noB = _sqlite3VdbeAddOp2(tls, v, int32(OP_Yield), regAddrB, labelEnd)
_sqlite3VdbeGoto(tls, v, addrEofA)
(*TSelect)(unsafe.Pointer(p)).FnSelectRow = _sqlite3LogEstAdd(tls, (*TSelect)(unsafe.Pointer(p)).FnSelectRow, (*TSelect)(unsafe.Pointer(pPrior)).FnSelectRow)
}
/* Generate a subroutine to run when the results from select B
** are exhausted and only data in select A remains.
*/
if op == int32(TK_INTERSECT) {
addrEofB = addrEofA
if int32((*TSelect)(unsafe.Pointer(p)).FnSelectRow) > int32((*TSelect)(unsafe.Pointer(pPrior)).FnSelectRow) {
(*TSelect)(unsafe.Pointer(p)).FnSelectRow = (*TSelect)(unsafe.Pointer(pPrior)).FnSelectRow
}
} else {
addrEofB = _sqlite3VdbeAddOp2(tls, v, int32(OP_Gosub), regOutA, addrOutA)
_sqlite3VdbeAddOp2(tls, v, int32(OP_Yield), regAddrA, labelEnd)
_sqlite3VdbeGoto(tls, v, addrEofB)
}
/* Generate code to handle the case of AB
*/
addrAgtB = _sqlite3VdbeCurrentAddr(tls, v)
if op == int32(TK_ALL) || op == int32(TK_UNION) {
_sqlite3VdbeAddOp2(tls, v, int32(OP_Gosub), regOutB, addrOutB)
_sqlite3VdbeAddOp2(tls, v, int32(OP_Yield), regAddrB, addrEofB)
_sqlite3VdbeGoto(tls, v, labelCmpr)
} else {
addrAgtB = addrAgtB + 1 /* Just do next-B. Might as well use the next-B call
** in the next code block */
}
/* This code runs once to initialize everything.
*/
_sqlite3VdbeJumpHere(tls, v, addr1)
_sqlite3VdbeAddOp2(tls, v, int32(OP_Yield), regAddrA, addrEofA_noB)
/* v--- Also the A>B case for EXCEPT and INTERSECT */
_sqlite3VdbeAddOp2(tls, v, int32(OP_Yield), regAddrB, addrEofB)
/* Implement the main merge loop
*/
if aPermute != uintptr(0) {
_sqlite3VdbeAddOp4(tls, v, int32(OP_Permutation), 0, 0, 0, aPermute, -int32(15))
}
_sqlite3VdbeResolveLabel(tls, v, labelCmpr)
_sqlite3VdbeAddOp4(tls, v, int32(OP_Compare), (**(**TSelectDest)(__ccgo_up(bp))).FiSdst, (**(**TSelectDest)(__ccgo_up(bp + 40))).FiSdst, nOrderBy, pKeyMerge, -int32(9))
if aPermute != uintptr(0) {
_sqlite3VdbeChangeP5(tls, v, uint16(OPFLAG_PERMUTE))
}
_sqlite3VdbeAddOp3(tls, v, int32(OP_Jump), addrAltB, addrAeqB, addrAgtB)
/* Jump to the this point in order to terminate the query.
*/
_sqlite3VdbeResolveLabel(tls, v, labelEnd)
/* Make arrangements to free the 2nd and subsequent arms of the compound
** after the parse has finished */
if (*TSelect)(unsafe.Pointer(pSplit)).FpPrior != 0 {
_sqlite3ParserAddCleanup(tls, pParse, __ccgo_fp(_sqlite3SelectDeleteGeneric), (*TSelect)(unsafe.Pointer(pSplit)).FpPrior)
}
(*TSelect)(unsafe.Pointer(pSplit)).FpPrior = pPrior
(*TSelect)(unsafe.Pointer(pPrior)).FpNext = pSplit
_sqlite3ExprListDelete(tls, db, (*TSelect)(unsafe.Pointer(pPrior)).FpOrderBy)
(*TSelect)(unsafe.Pointer(pPrior)).FpOrderBy = uintptr(0)
/*** TBD: Insert subroutine calls to close cursors on incomplete
**** subqueries ****/
_sqlite3VdbeExplainPop(tls, pParse)
return libc.BoolInt32((*TParse)(unsafe.Pointer(pParse)).FnErr != 0)
}
// C documentation
//
// /*
// ** Handle the special case of a compound-select that originates from a
// ** VALUES clause. By handling this as a special case, we avoid deep
// ** recursion, and thus do not need to enforce the SQLITE_LIMIT_COMPOUND_SELECT
// ** on a VALUES clause.
// **
// ** Because the Select object originates from a VALUES clause:
// ** (1) There is no LIMIT or OFFSET or else there is a LIMIT of exactly 1
// ** (2) All terms are UNION ALL
// ** (3) There is no ORDER BY clause
// **
// ** The "LIMIT of exactly 1" case of condition (1) comes about when a VALUES
// ** clause occurs within scalar expression (ex: "SELECT (VALUES(1),(2),(3))").
// ** The sqlite3CodeSubselect will have added the LIMIT 1 clause in tht case.
// ** Since the limit is exactly 1, we only need to evaluate the left-most VALUES.
// */
func _multiSelectValues(tls *libc.TLS, pParse uintptr, p uintptr, pDest uintptr) (r int32) {
bp := tls.Alloc(32)
defer tls.Free(32)
var bShowAll, nRow, rc int32
var v1 uintptr
_, _, _, _ = bShowAll, nRow, rc, v1
nRow = int32(1)
rc = 0
bShowAll = libc.BoolInt32((*TSelect)(unsafe.Pointer(p)).FpLimit == uintptr(0))
for cond := true; cond; cond = int32(1) != 0 {
if (*TSelect)(unsafe.Pointer(p)).FpWin != 0 {
return -int32(1)
}
if (*TSelect)(unsafe.Pointer(p)).FpPrior == uintptr(0) {
break
}
p = (*TSelect)(unsafe.Pointer(p)).FpPrior
nRow = nRow + bShowAll
}
if nRow == int32(1) {
v1 = __ccgo_ts + 1702
} else {
v1 = __ccgo_ts + 3834
}
_sqlite3VdbeExplain(tls, pParse, uint8(0), __ccgo_ts+21202, libc.VaList(bp+8, nRow, v1))
for p != 0 {
_selectInnerLoop(tls, pParse, p, -int32(1), uintptr(0), uintptr(0), pDest, int32(1), int32(1))
if !(bShowAll != 0) {
break
}
(*TSelect)(unsafe.Pointer(p)).FnSelectRow = int16(nRow)
p = (*TSelect)(unsafe.Pointer(p)).FpNext
}
return rc
}
// C documentation
//
// /*
// ** If pBt points to an empty file then convert that empty file
// ** into a new empty database by initializing the first page of
// ** the database.
// */
func _newDatabase(tls *libc.TLS, pBt uintptr) (r int32) {
var data, pP1, v1 uintptr
var rc int32
_, _, _, _ = data, pP1, rc, v1
if (*TBtShared)(unsafe.Pointer(pBt)).FnPage > uint32(0) {
return SQLITE_OK
}
pP1 = (*TBtShared)(unsafe.Pointer(pBt)).FpPage1
data = (*TMemPage)(unsafe.Pointer(pP1)).FaData
rc = _sqlite3PagerWrite(tls, (*TMemPage)(unsafe.Pointer(pP1)).FpDbPage)
if rc != 0 {
return rc
}
libc.X__builtin___memcpy_chk(tls, data, uintptr(unsafe.Pointer(&_zMagicHeader)), uint64(16), ^t__predefined_size_t(0))
**(**uint8)(__ccgo_up(data + 16)) = uint8((*TBtShared)(unsafe.Pointer(pBt)).FpageSize >> libc.Int32FromInt32(8) & libc.Uint32FromInt32(0xff))
**(**uint8)(__ccgo_up(data + 17)) = uint8((*TBtShared)(unsafe.Pointer(pBt)).FpageSize >> libc.Int32FromInt32(16) & libc.Uint32FromInt32(0xff))
**(**uint8)(__ccgo_up(data + 18)) = uint8(1)
**(**uint8)(__ccgo_up(data + 19)) = uint8(1)
**(**uint8)(__ccgo_up(data + 20)) = uint8((*TBtShared)(unsafe.Pointer(pBt)).FpageSize - (*TBtShared)(unsafe.Pointer(pBt)).FusableSize)
**(**uint8)(__ccgo_up(data + 21)) = uint8(64)
**(**uint8)(__ccgo_up(data + 22)) = uint8(32)
**(**uint8)(__ccgo_up(data + 23)) = uint8(32)
libc.X__builtin___memset_chk(tls, data+24, 0, libc.Uint64FromInt32(libc.Int32FromInt32(100)-libc.Int32FromInt32(24)), ^t__predefined_size_t(0))
_zeroPage(tls, pP1, libc.Int32FromInt32(PTF_INTKEY)|libc.Int32FromInt32(PTF_LEAF)|libc.Int32FromInt32(PTF_LEAFDATA))
v1 = pBt + 40
*(*Tu16)(unsafe.Pointer(v1)) = Tu16(int32(*(*Tu16)(unsafe.Pointer(v1))) | libc.Int32FromInt32(BTS_PAGESIZE_FIXED))
_sqlite3Put4byte(tls, data+uintptr(libc.Int32FromInt32(36)+libc.Int32FromInt32(4)*libc.Int32FromInt32(4)), uint32((*TBtShared)(unsafe.Pointer(pBt)).FautoVacuum))
_sqlite3Put4byte(tls, data+uintptr(libc.Int32FromInt32(36)+libc.Int32FromInt32(7)*libc.Int32FromInt32(4)), uint32((*TBtShared)(unsafe.Pointer(pBt)).FincrVacuum))
(*TBtShared)(unsafe.Pointer(pBt)).FnPage = uint32(1)
**(**uint8)(__ccgo_up(data + 31)) = uint8(1)
return SQLITE_OK
}
var _nfsIoFinder = uintptr(0)
func _nfsIoFinderImpl(tls *libc.TLS, z uintptr, p uintptr) (r uintptr) {
_ = z
_ = p
return uintptr(unsafe.Pointer(&_nfsIoMethods))
}
// C documentation
//
// /* nfs lockd on OSX 10.3+ doesn't clear write locks when a read lock is set */
var _nfsIoMethods = Tsqlite3_io_methods{
FiVersion: int32(1),
}
// C documentation
//
// /*
// ** Lower the locking level on file descriptor pFile to eFileLock. eFileLock
// ** must be either NO_LOCK or SHARED_LOCK.
// **
// ** If the locking level of the file descriptor is already at or below
// ** the requested locking level, this routine is a no-op.
// */
func _nfsUnlock(tls *libc.TLS, id uintptr, eFileLock int32) (r int32) {
return _posixUnlock(tls, id, eFileLock, int32(1))
}
/*
** The code above is the NFS lock implementation. The code is specific
** to MacOSX and does not work on other unix platforms. No alternative
** is available.
**
********************* End of the NFS lock implementation **********************
******************************************************************************/
/******************************************************************************
**************** Non-locking sqlite3_file methods *****************************
**
** The next division contains implementations for all methods of the
** sqlite3_file object other than the locking methods. The locking
** methods were defined in divisions above (one locking method per
** division). Those methods that are common to all locking modes
** are gather together into this division.
*/
// 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)<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)< ((*TRtree)(unsafe.Pointer(pRtree)).FiNodeSize-int32(4))/libc.Int32FromUint8((*TRtree)(unsafe.Pointer(pRtree)).FnBytesPerCell) {
rc = libc.Int32FromInt32(SQLITE_CORRUPT) | libc.Int32FromInt32(1)<ncFlags values determined by validMask.
// **
// ** static void notValid(
// ** Parse *pParse, // Leave error message here
// ** NameContext *pNC, // The name context
// ** const char *zMsg, // Type of error
// ** int validMask, // Set of contexts for which prohibited
// ** Expr *pExpr // Invalidate this expression on error
// ** ){...}
// **
// ** As an optimization, since the conditional is almost always false
// ** (because errors are rare), the conditional is moved outside of the
// ** function call using a macro.
// */
func _notValidImpl(tls *libc.TLS, pParse uintptr, pNC uintptr, zMsg uintptr, pExpr uintptr, pError uintptr) {
bp := tls.Alloc(32)
defer tls.Free(32)
var zIn uintptr
_ = zIn
zIn = __ccgo_ts + 7446
if (*TNameContext)(unsafe.Pointer(pNC)).FncFlags&int32(NC_IdxExpr) != 0 {
zIn = __ccgo_ts + 7474
} else {
if (*TNameContext)(unsafe.Pointer(pNC)).FncFlags&int32(NC_IsCheck) != 0 {
zIn = __ccgo_ts + 7492
} else {
if (*TNameContext)(unsafe.Pointer(pNC)).FncFlags&int32(NC_GenCol) != 0 {
zIn = __ccgo_ts + 7510
}
}
}
_sqlite3ErrorMsg(tls, pParse, __ccgo_ts+7528, libc.VaList(bp+8, zMsg, zIn))
if pExpr != 0 {
(*TExpr)(unsafe.Pointer(pExpr)).Fop = uint8(TK_NULL)
}
_sqlite3RecordErrorOffsetOfExpr(tls, (*TParse)(unsafe.Pointer(pParse)).Fdb, pError)
}
func _nth_valueStepFunc(tls *libc.TLS, pCtx uintptr, nArg int32, apArg uintptr) {
var fVal float64
var iVal Ti64
var p uintptr
_, _, _ = fVal, iVal, p
p = Xsqlite3_aggregate_context(tls, pCtx, int32(16))
if p != 0 {
switch Xsqlite3_value_numeric_type(tls, **(**uintptr)(__ccgo_up(apArg + 1*8))) {
case int32(SQLITE_INTEGER):
iVal = Xsqlite3_value_int64(tls, **(**uintptr)(__ccgo_up(apArg + 1*8)))
case int32(SQLITE_FLOAT):
fVal = Xsqlite3_value_double(tls, **(**uintptr)(__ccgo_up(apArg + 1*8)))
if float64(int64(fVal)) != fVal {
goto error_out
}
iVal = int64(fVal)
default:
goto error_out
}
if iVal <= 0 {
goto error_out
}
(*TNthValueCtx)(unsafe.Pointer(p)).FnStep = (*TNthValueCtx)(unsafe.Pointer(p)).FnStep + 1
if iVal == (*TNthValueCtx)(unsafe.Pointer(p)).FnStep {
(*TNthValueCtx)(unsafe.Pointer(p)).FpValue = Xsqlite3_value_dup(tls, **(**uintptr)(__ccgo_up(apArg)))
if !((*TNthValueCtx)(unsafe.Pointer(p)).FpValue != 0) {
Xsqlite3_result_error_nomem(tls, pCtx)
}
}
}
_ = nArg
_ = apArg
return
goto error_out
error_out:
;
Xsqlite3_result_error(tls, pCtx, __ccgo_ts+24570, -int32(1))
}
// C documentation
//
// /*
// ** Implementation of ntile(). This assumes that the window frame has
// ** been coerced to:
// **
// ** ROWS CURRENT ROW AND UNBOUNDED FOLLOWING
// */
func _ntileStepFunc(tls *libc.TLS, pCtx uintptr, nArg int32, apArg uintptr) {
var p uintptr
_ = p
_ = nArg
p = Xsqlite3_aggregate_context(tls, pCtx, int32(24))
if p != 0 {
if (*TNtileCtx)(unsafe.Pointer(p)).FnTotal == 0 {
(*TNtileCtx)(unsafe.Pointer(p)).FnParam = Xsqlite3_value_int64(tls, **(**uintptr)(__ccgo_up(apArg)))
if (*TNtileCtx)(unsafe.Pointer(p)).FnParam <= 0 {
Xsqlite3_result_error(tls, pCtx, __ccgo_ts+24626, -int32(1))
}
}
(*TNtileCtx)(unsafe.Pointer(p)).FnTotal = (*TNtileCtx)(unsafe.Pointer(p)).FnTotal + 1
}
}
type _opaque_pthread_attr_t = T_opaque_pthread_attr_t
type _opaque_pthread_cond_t = T_opaque_pthread_cond_t
type _opaque_pthread_condattr_t = T_opaque_pthread_condattr_t
type _opaque_pthread_mutex_t = T_opaque_pthread_mutex_t
type _opaque_pthread_mutexattr_t = T_opaque_pthread_mutexattr_t
type _opaque_pthread_once_t = T_opaque_pthread_once_t
type _opaque_pthread_rwlock_t = T_opaque_pthread_rwlock_t
type _opaque_pthread_rwlockattr_t = T_opaque_pthread_rwlockattr_t
type _opaque_pthread_t = T_opaque_pthread_t
// C documentation
//
// /*
// ** This routine does the work of opening a database on behalf of
// ** sqlite3_open() and sqlite3_open16(). The database filename "zFilename"
// ** is UTF-8 encoded.
// */
func _openDatabase(tls *libc.TLS, zFilename uintptr, ppDb uintptr, _flags uint32, zVfs uintptr) (r int32) {
bp := tls.Alloc(48)
defer tls.Free(48)
*(*uint32)(unsafe.Pointer(bp)) = _flags
var db, v2 uintptr
var i, isThreadsafe, rc int32
var v1 uint32
var _ /* zErrMsg at bp+16 */ uintptr
var _ /* zOpen at bp+8 */ uintptr
_, _, _, _, _, _ = db, i, isThreadsafe, rc, v1, v2 /* True for threadsafe connections */
**(**uintptr)(__ccgo_up(bp + 8)) = uintptr(0) /* Filename argument to pass to BtreeOpen() */
**(**uintptr)(__ccgo_up(bp + 16)) = uintptr(0) /* Loop counter */
**(**uintptr)(__ccgo_up(ppDb)) = uintptr(0)
rc = Xsqlite3_initialize(tls)
if rc != 0 {
return rc
}
if libc.Int32FromUint8(_sqlite3Config.FbCoreMutex) == 0 {
isThreadsafe = 0
} else {
if **(**uint32)(__ccgo_up(bp))&uint32(SQLITE_OPEN_NOMUTEX) != 0 {
isThreadsafe = 0
} else {
if **(**uint32)(__ccgo_up(bp))&uint32(SQLITE_OPEN_FULLMUTEX) != 0 {
isThreadsafe = int32(1)
} else {
isThreadsafe = libc.Int32FromUint8(_sqlite3Config.FbFullMutex)
}
}
}
if **(**uint32)(__ccgo_up(bp))&uint32(SQLITE_OPEN_PRIVATECACHE) != 0 {
**(**uint32)(__ccgo_up(bp)) = **(**uint32)(__ccgo_up(bp)) & libc.Uint32FromInt32(^libc.Int32FromInt32(SQLITE_OPEN_SHAREDCACHE))
} else {
if _sqlite3Config.FsharedCacheEnabled != 0 {
**(**uint32)(__ccgo_up(bp)) = **(**uint32)(__ccgo_up(bp)) | uint32(SQLITE_OPEN_SHAREDCACHE)
}
}
/* Remove harmful bits from the flags parameter
**
** The SQLITE_OPEN_NOMUTEX and SQLITE_OPEN_FULLMUTEX flags were
** dealt with in the previous code block. Besides these, the only
** valid input flags for sqlite3_open_v2() are SQLITE_OPEN_READONLY,
** SQLITE_OPEN_READWRITE, SQLITE_OPEN_CREATE, SQLITE_OPEN_SHAREDCACHE,
** SQLITE_OPEN_PRIVATECACHE, SQLITE_OPEN_EXRESCODE, and some reserved
** bits. Silently mask off all other flags.
*/
**(**uint32)(__ccgo_up(bp)) = **(**uint32)(__ccgo_up(bp)) & libc.Uint32FromInt32(^(libc.Int32FromInt32(SQLITE_OPEN_DELETEONCLOSE) | libc.Int32FromInt32(SQLITE_OPEN_EXCLUSIVE) | libc.Int32FromInt32(SQLITE_OPEN_MAIN_DB) | libc.Int32FromInt32(SQLITE_OPEN_TEMP_DB) | libc.Int32FromInt32(SQLITE_OPEN_TRANSIENT_DB) | libc.Int32FromInt32(SQLITE_OPEN_MAIN_JOURNAL) | libc.Int32FromInt32(SQLITE_OPEN_TEMP_JOURNAL) | libc.Int32FromInt32(SQLITE_OPEN_SUBJOURNAL) | libc.Int32FromInt32(SQLITE_OPEN_SUPER_JOURNAL) | libc.Int32FromInt32(SQLITE_OPEN_NOMUTEX) | libc.Int32FromInt32(SQLITE_OPEN_FULLMUTEX) | libc.Int32FromInt32(SQLITE_OPEN_WAL)))
/* Allocate the sqlite data structure */
db = _sqlite3MallocZero(tls, uint64(864))
if db == uintptr(0) {
goto opendb_out
}
if isThreadsafe != 0 {
(*Tsqlite3)(unsafe.Pointer(db)).Fmutex = _sqlite3MutexAlloc(tls, int32(SQLITE_MUTEX_RECURSIVE))
if (*Tsqlite3)(unsafe.Pointer(db)).Fmutex == uintptr(0) {
Xsqlite3_free(tls, db)
db = uintptr(0)
goto opendb_out
}
if isThreadsafe == 0 {
}
}
Xsqlite3_mutex_enter(tls, (*Tsqlite3)(unsafe.Pointer(db)).Fmutex)
if **(**uint32)(__ccgo_up(bp))&uint32(SQLITE_OPEN_EXRESCODE) != uint32(0) {
v1 = uint32(0xffffffff)
} else {
v1 = uint32(0xff)
}
(*Tsqlite3)(unsafe.Pointer(db)).FerrMask = libc.Int32FromUint32(v1)
(*Tsqlite3)(unsafe.Pointer(db)).FnDb = int32(2)
(*Tsqlite3)(unsafe.Pointer(db)).FeOpenState = uint8(SQLITE_STATE_BUSY)
(*Tsqlite3)(unsafe.Pointer(db)).FaDb = db + 696
(*Tsqlite3)(unsafe.Pointer(db)).Flookaside.FbDisable = uint32(1)
(*Tsqlite3)(unsafe.Pointer(db)).Flookaside.Fsz = uint16(0)
(*Tsqlite3)(unsafe.Pointer(db)).FnFpDigit = uint8(17)
libc.X__builtin___memcpy_chk(tls, db+136, uintptr(unsafe.Pointer(&_aHardLimit)), uint64(52), ^t__predefined_size_t(0))
**(**int32)(__ccgo_up(db + 136 + 11*4)) = SQLITE_DEFAULT_WORKER_THREADS
(*Tsqlite3)(unsafe.Pointer(db)).FautoCommit = uint8(1)
(*Tsqlite3)(unsafe.Pointer(db)).FnextAutovac = int8(-int32(1))
(*Tsqlite3)(unsafe.Pointer(db)).FszMmap = _sqlite3Config.FszMmap
(*Tsqlite3)(unsafe.Pointer(db)).FnextPagesize = 0
(*Tsqlite3)(unsafe.Pointer(db)).Finit1.FazInit = uintptr(unsafe.Pointer(&_sqlite3StdType)) /* Any array of string ptrs will do */
**(**Tu64)(__ccgo_up(db + 48)) |= uint64(libc.Uint32FromInt32(libc.Int32FromInt32(SQLITE_ShortColNames)|libc.Int32FromInt32(SQLITE_EnableTrigger))|libc.Uint32FromUint32(SQLITE_EnableView)|libc.Uint32FromInt32(SQLITE_CacheSpill)) | libc.Uint64FromInt32(libc.Int32FromInt32(0x00010))< 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 uint64
var _ /* bRetry at bp+0 */ int32
_, _, _, _, _, _, _, _, _, _, _ = db, frc, nByte, nRbu, nTarget, p, pCsr, pFd, pState, v1, v2
if zTarget != 0 {
v1 = libc.Xstrlen(tls, zTarget)
} else {
v1 = uint64(0)
}
nTarget = v1
nRbu = libc.Xstrlen(tls, zRbu)
nByte = uint64(416) + nTarget + uint64(1) + nRbu + uint64(1)
p = Xsqlite3_malloc64(tls, nByte)
if p != 0 {
pState = uintptr(0)
/* Create the custom VFS. */
libc.X__builtin___memset_chk(tls, p, 0, uint64(416), ^t__predefined_size_t(0))
Xsqlite3rbu_rename_handler(tls, p, uintptr(0), uintptr(0))
_rbuCreateVfs(tls, p)
/* Open the target, RBU and state databases */
if (*Tsqlite3rbu)(unsafe.Pointer(p)).Frc == SQLITE_OK {
pCsr = p + 1*416
**(**int32)(__ccgo_up(bp)) = 0
if zTarget != 0 {
(*Tsqlite3rbu)(unsafe.Pointer(p)).FzTarget = pCsr
libc.X__builtin___memcpy_chk(tls, (*Tsqlite3rbu)(unsafe.Pointer(p)).FzTarget, zTarget, nTarget+uint64(1), ^t__predefined_size_t(0))
pCsr = pCsr + uintptr(nTarget+uint64(1))
}
(*Tsqlite3rbu)(unsafe.Pointer(p)).FzRbu = pCsr
libc.X__builtin___memcpy_chk(tls, (*Tsqlite3rbu)(unsafe.Pointer(p)).FzRbu, zRbu, nRbu+uint64(1), ^t__predefined_size_t(0))
pCsr = pCsr + uintptr(nRbu+uint64(1))
if zState != 0 {
(*Tsqlite3rbu)(unsafe.Pointer(p)).FzState = _rbuMPrintf(tls, p, __ccgo_ts+3944, 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+34949, 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 + 34981
} else {
v2 = __ccgo_ts + 34988
}
(*Tsqlite3rbu)(unsafe.Pointer(p)).FzErrmsg = Xsqlite3_mprintf(tls, __ccgo_ts+34995, 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+16451, uintptr(0), uintptr(0), p+64)
/* Point the object iterator at the first object */
if (*Tsqlite3rbu)(unsafe.Pointer(p)).Frc == SQLITE_OK {
(*Tsqlite3rbu)(unsafe.Pointer(p)).Frc = _rbuObjIterFirst(tls, p, p+88)
}
/* If the RBU database contains no data_xxx tables, declare the RBU
** update finished. */
if (*Tsqlite3rbu)(unsafe.Pointer(p)).Frc == SQLITE_OK && (*Tsqlite3rbu)(unsafe.Pointer(p)).Fobjiter.FzTbl == uintptr(0) {
(*Tsqlite3rbu)(unsafe.Pointer(p)).Frc = int32(SQLITE_DONE)
(*Tsqlite3rbu)(unsafe.Pointer(p)).FeStage = int32(RBU_STAGE_DONE)
} else {
if (*Tsqlite3rbu)(unsafe.Pointer(p)).Frc == SQLITE_OK && (*TRbuState)(unsafe.Pointer(pState)).FeStage == 0 && (*Tsqlite3rbu)(unsafe.Pointer(p)).FzTarget == uintptr(0) {
_rbuCopyPragma(tls, p, __ccgo_ts+19017)
_rbuCopyPragma(tls, p, __ccgo_ts+18413)
}
/* 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+35027, uintptr(0), uintptr(0), p+64)
}
/* Check if the main database is a zipvfs db. If it is, set the upper
** level pager to use "journal_mode=off". This prevents it from
** generating a large journal using a temp file. */
if (*Tsqlite3rbu)(unsafe.Pointer(p)).Frc == SQLITE_OK {
frc = Xsqlite3_file_control(tls, db, __ccgo_ts+7164, int32(SQLITE_FCNTL_ZIPVFS), uintptr(0))
if frc == SQLITE_OK {
(*Tsqlite3rbu)(unsafe.Pointer(p)).Frc = Xsqlite3_exec(tls, db, __ccgo_ts+35043, uintptr(0), uintptr(0), p+64)
}
}
if (*Tsqlite3rbu)(unsafe.Pointer(p)).Frc == SQLITE_OK {
_rbuSetupOal(tls, p, pState)
}
}
} else {
if (*Tsqlite3rbu)(unsafe.Pointer(p)).FeStage == int32(RBU_STAGE_MOVE) {
/* no-op */
} else {
if (*Tsqlite3rbu)(unsafe.Pointer(p)).FeStage == int32(RBU_STAGE_CKPT) {
if !((*Tsqlite3rbu)(unsafe.Pointer(p)).FzTarget == libc.UintptrFromInt32(0)) && _rbuExclusiveCheckpoint(tls, (*Tsqlite3rbu)(unsafe.Pointer(p)).FdbMain) != 0 {
/* If the rbu_exclusive_checkpoint=1 URI parameter was specified
** and an incremental checkpoint is being resumed, attempt an
** exclusive lock on the db file. If this fails, so be it. */
(*Tsqlite3rbu)(unsafe.Pointer(p)).FeStage = int32(RBU_STAGE_DONE)
_rbuLockDatabase(tls, (*Tsqlite3rbu)(unsafe.Pointer(p)).FdbMain)
(*Tsqlite3rbu)(unsafe.Pointer(p)).FeStage = int32(RBU_STAGE_CKPT)
}
_rbuSetupCheckpoint(tls, p, pState)
} else {
if (*Tsqlite3rbu)(unsafe.Pointer(p)).FeStage == int32(RBU_STAGE_DONE) {
(*Tsqlite3rbu)(unsafe.Pointer(p)).Frc = int32(SQLITE_DONE)
} else {
(*Tsqlite3rbu)(unsafe.Pointer(p)).Frc = int32(SQLITE_CORRUPT)
}
}
}
}
}
_rbuFreeState(tls, pState)
}
return p
}
// C documentation
//
// /*
// ** This routine generates code that opens the sqlite_statN tables.
// ** The sqlite_stat1 table is always relevant. sqlite_stat2 is now
// ** obsolete. sqlite_stat3 and sqlite_stat4 are only opened when
// ** appropriate compile-time options are provided.
// **
// ** If the sqlite_statN tables do not previously exist, it is created.
// **
// ** Argument zWhere may be a pointer to a buffer containing a table name,
// ** or it may be a NULL pointer. If it is not NULL, then all entries in
// ** the sqlite_statN tables associated with the named table are deleted.
// ** If zWhere==0, then code is generated to delete all stat table entries.
// */
func _openStatTable(tls *libc.TLS, pParse uintptr, iDb int32, iStatCur int32, zWhere uintptr, zWhereType uintptr) {
bp := tls.Alloc(48)
defer tls.Free(48)
var aCreateTbl [3]Tu8
var aRoot [3]Tu32
var db, pDb, pStat, v, zTab, v3 uintptr
var i, nToOpen, v1 int32
_, _, _, _, _, _, _, _, _, _, _ = aCreateTbl, aRoot, db, i, nToOpen, pDb, pStat, v, zTab, v1, v3
db = (*TParse)(unsafe.Pointer(pParse)).Fdb
v = _sqlite3GetVdbe(tls, pParse)
if (*Tsqlite3)(unsafe.Pointer(db)).FdbOptFlags&libc.Uint32FromInt32(libc.Int32FromInt32(SQLITE_Stat4)) == uint32(0) {
v1 = int32(2)
} else {
v1 = int32(1)
}
nToOpen = v1
if v == uintptr(0) {
return
}
pDb = (*Tsqlite3)(unsafe.Pointer(db)).FaDb + uintptr(iDb)*32
/* Create new statistic tables if they do not exist, or clear them
** if they do already exist.
*/
i = 0
for {
if !(i < libc.Int32FromUint64(libc.Uint64FromInt64(48)/libc.Uint64FromInt64(16))) {
break
}
zTab = _aTable[i].FzName
aCreateTbl[i] = uint8(0)
v3 = _sqlite3FindTable(tls, db, zTab, (*TDb)(unsafe.Pointer(pDb)).FzDbSName)
pStat = v3
if v3 == uintptr(0) {
if i < nToOpen {
/* The sqlite_statN table does not exist. Create it. Note that a
** side-effect of the CREATE TABLE statement is to leave the rootpage
** of the new table in register pParse->regRoot. This is important
** because the OpenWrite opcode below will be needing it. */
_sqlite3NestedParse(tls, pParse, __ccgo_ts+13261, libc.VaList(bp+8, (*TDb)(unsafe.Pointer(pDb)).FzDbSName, zTab, _aTable[i].FzCols))
aRoot[i] = libc.Uint32FromInt32((*(*struct {
FaddrCrTab int32
FregRowid int32
FregRoot int32
FconstraintName TToken
})(unsafe.Pointer(pParse + 256))).FregRoot)
aCreateTbl[i] = uint8(OPFLAG_P2ISREG)
}
} else {
/* The table already exists. If zWhere is not NULL, delete all entries
** associated with the table zWhere. If zWhere is NULL, delete the
** entire contents of the table. */
aRoot[i] = (*TTable)(unsafe.Pointer(pStat)).Ftnum
_sqlite3TableLock(tls, pParse, iDb, aRoot[i], uint8(1), zTab)
if zWhere != 0 {
_sqlite3NestedParse(tls, pParse, __ccgo_ts+13284, libc.VaList(bp+8, (*TDb)(unsafe.Pointer(pDb)).FzDbSName, zTab, zWhereType, zWhere))
} else {
if (*Tsqlite3)(unsafe.Pointer(db)).FxPreUpdateCallback != 0 {
_sqlite3NestedParse(tls, pParse, __ccgo_ts+13314, libc.VaList(bp+8, (*TDb)(unsafe.Pointer(pDb)).FzDbSName, zTab))
} else {
/* The sqlite_stat[134] table already exists. Delete all rows. */
_sqlite3VdbeAddOp2(tls, v, int32(OP_Clear), libc.Int32FromUint32(aRoot[i]), iDb)
}
}
}
goto _2
_2:
;
i = i + 1
}
/* Open the sqlite_stat[134] tables for writing. */
i = 0
for {
if !(i < nToOpen) {
break
}
_sqlite3VdbeAddOp4Int(tls, v, int32(OP_OpenWrite), iStatCur+i, libc.Int32FromUint32(aRoot[i]), iDb, int32(3))
_sqlite3VdbeChangeP5(tls, v, uint16(aCreateTbl[i]))
goto _4
_4:
;
i = i + 1
}
}
// C documentation
//
// /*
// ** Search the free-list on page pPg for space to store a cell nByte bytes in
// ** size. If one can be found, return a pointer to the space and remove it
// ** from the free-list.
// **
// ** If no suitable space can be found on the free-list, return NULL.
// **
// ** This function may detect corruption within pPg. If corruption is
// ** detected then *pRc is set to SQLITE_CORRUPT and NULL is returned.
// **
// ** Slots on the free list that are between 1 and 3 bytes larger than nByte
// ** will be ignored if adding the extra space to the fragmentation count
// ** causes the fragmentation count to exceed 60.
// */
func _pageFindSlot(tls *libc.TLS, pPg uintptr, nByte int32, pRc uintptr) (r uintptr) {
var aData, pTmp, v2 uintptr
var hdr, iAddr, maxPC, pc, size, x, v1 int32
_, _, _, _, _, _, _, _, _, _ = aData, hdr, iAddr, maxPC, pTmp, pc, size, x, v1, v2
hdr = libc.Int32FromUint8((*TMemPage)(unsafe.Pointer(pPg)).FhdrOffset) /* Offset to page header */
aData = (*TMemPage)(unsafe.Pointer(pPg)).FaData /* Page data */
iAddr = hdr + int32(1) /* Address of ptr to pc */
pTmp = aData + uintptr(iAddr) /* Temporary ptr into aData[] */
pc = libc.Int32FromUint8(**(**Tu8)(__ccgo_up(pTmp)))<= 0 {
if x < int32(4) {
/* EVIDENCE-OF: R-11498-58022 In a well-formed b-tree page, the total
** number of bytes in fragments may not exceed 60. */
if libc.Int32FromUint8(**(**Tu8)(__ccgo_up(aData + uintptr(hdr+int32(7))))) > int32(57) {
return uintptr(0)
}
/* Remove the slot from the free-list. Update the number of
** fragmented bytes within the page. */
libc.X__builtin___memcpy_chk(tls, aData+uintptr(iAddr), aData+uintptr(pc), uint64(2), ^t__predefined_size_t(0))
v2 = aData + uintptr(hdr+int32(7))
*(*Tu8)(unsafe.Pointer(v2)) = Tu8(int32(*(*Tu8)(unsafe.Pointer(v2))) + libc.Int32FromUint8(libc.Uint8FromInt32(x)))
return aData + uintptr(pc)
} else {
if x+pc > maxPC {
/* This slot extends off the end of the usable part of the page */
**(**int32)(__ccgo_up(pRc)) = _sqlite3CorruptError(tls, int32(75005))
return uintptr(0)
} else {
/* The slot remains on the free-list. Reduce its size to account
** for the portion used by the new allocation. */
**(**Tu8)(__ccgo_up(aData + uintptr(pc+int32(2)))) = libc.Uint8FromInt32(x >> libc.Int32FromInt32(8))
**(**Tu8)(__ccgo_up(aData + uintptr(pc+int32(2)) + 1)) = libc.Uint8FromInt32(x)
}
}
return aData + uintptr(pc+x)
}
iAddr = pc
pTmp = aData + uintptr(pc)
pc = libc.Int32FromUint8(**(**Tu8)(__ccgo_up(pTmp)))< maxPC+nByte-int32(4) {
/* The free slot chain extends off the end of the page */
**(**int32)(__ccgo_up(pRc)) = _sqlite3CorruptError(tls, int32(75027))
}
return uintptr(0)
}
// C documentation
//
// /*
// ** The pCArray objects contains pointers to b-tree cells and the cell sizes.
// ** This function attempts to add the cells stored in the array to page pPg.
// ** If it cannot (because the page needs to be defragmented before the cells
// ** will fit), non-zero is returned. Otherwise, if the cells are added
// ** successfully, zero is returned.
// **
// ** Argument pCellptr points to the first entry in the cell-pointer array
// ** (part of page pPg) to populate. After cell apCell[0] is written to the
// ** page body, a 16-bit offset is written to pCellptr. And so on, for each
// ** cell in the array. It is the responsibility of the caller to ensure
// ** that it is safe to overwrite this part of the cell-pointer array.
// **
// ** When this function is called, *ppData points to the start of the
// ** content area on page pPg. If the size of the content area is extended,
// ** *ppData is updated to point to the new start of the content area
// ** before returning.
// **
// ** Finally, argument pBegin points to the byte immediately following the
// ** end of the space required by this page for the cell-pointer area (for
// ** all cells - not just those inserted by the current call). If the content
// ** area must be extended to before this point in order to accommodate all
// ** cells in apCell[], then the cells do not fit and non-zero is returned.
// */
func _pageInsertArray(tls *libc.TLS, pPg uintptr, pBegin uintptr, ppData uintptr, pCellptr uintptr, iFirst int32, nCell int32, pCArray uintptr) (r int32) {
bp := tls.Alloc(16)
defer tls.Free(16)
var aData, pData, pEnd, pSlot, v2 uintptr
var i, iEnd, k, sz int32
var v3 bool
var _ /* rc at bp+0 */ int32
_, _, _, _, _, _, _, _, _, _ = aData, i, iEnd, k, pData, pEnd, pSlot, sz, v2, v3
i = iFirst /* Loop counter - cell index to insert */
aData = (*TMemPage)(unsafe.Pointer(pPg)).FaData /* Complete page */
pData = **(**uintptr)(__ccgo_up(ppData)) /* Content area. A subset of aData[] */
iEnd = iFirst + nCell /* Maximum extent of cell data */
/* Never called on page 1 */
if iEnd <= iFirst {
return 0
}
k = 0
for {
if !(**(**int32)(__ccgo_up(pCArray + 80 + uintptr(k)*4)) <= i) {
break
}
goto _1
_1:
;
k = k + 1
}
pEnd = **(**uintptr)(__ccgo_up(pCArray + 32 + uintptr(k)*8))
for int32(1) != 0 {
sz = libc.Int32FromUint16(**(**Tu16)(__ccgo_up((*TCellArray)(unsafe.Pointer(pCArray)).FszCell + uintptr(i)*2)))
if v3 = libc.Int32FromUint8(**(**Tu8)(__ccgo_up(aData + 1))) == 0 && libc.Int32FromUint8(**(**Tu8)(__ccgo_up(aData + 2))) == 0; !v3 {
v2 = _pageFindSlot(tls, pPg, sz, bp)
pSlot = v2
}
if v3 || v2 == uintptr(0) {
if int64(pData)-int64(pBegin) < int64(sz) {
return int32(1)
}
pData = pData - uintptr(sz)
pSlot = pData
}
/* pSlot and pCArray->apCell[i] will never overlap on a well-formed
** database. But they might for a corrupt database. Hence use memmove()
** since memcpy() sends SIGABORT with overlapping buffers on OpenBSD */
if uint64(**(**uintptr)(__ccgo_up((*TCellArray)(unsafe.Pointer(pCArray)).FapCell + uintptr(i)*8))+uintptr(sz)) > uint64(pEnd) && uint64(**(**uintptr)(__ccgo_up((*TCellArray)(unsafe.Pointer(pCArray)).FapCell + uintptr(i)*8))) < uint64(pEnd) {
_sqlite3CorruptError(tls, int32(81003))
return int32(1)
}
libc.X__builtin___memmove_chk(tls, pSlot, **(**uintptr)(__ccgo_up((*TCellArray)(unsafe.Pointer(pCArray)).FapCell + uintptr(i)*8)), libc.Uint64FromInt32(sz), ^t__predefined_size_t(0))
**(**Tu8)(__ccgo_up(pCellptr)) = libc.Uint8FromInt64((int64(pSlot) - int64(aData)) >> libc.Int32FromInt32(8))
**(**Tu8)(__ccgo_up(pCellptr + 1)) = libc.Uint8FromInt64(int64(pSlot) - int64(aData))
pCellptr = pCellptr + uintptr(2)
i = i + 1
if i >= iEnd {
break
}
if **(**int32)(__ccgo_up(pCArray + 80 + uintptr(k)*4)) <= i {
k = k + 1
pEnd = **(**uintptr)(__ccgo_up(pCArray + 32 + uintptr(k)*8))
}
}
**(**uintptr)(__ccgo_up(ppData)) = pData
return 0
}
// C documentation
//
// /*
// ** Obtain a reference to a memory mapped page object for page number pgno.
// ** The new object will use the pointer pData, obtained from xFetch().
// ** If successful, set *ppPage to point to the new page reference
// ** and return SQLITE_OK. Otherwise, return an SQLite error code and set
// ** *ppPage to zero.
// **
// ** Page references obtained by calling this function should be released
// ** by calling pagerReleaseMapPage().
// */
func _pagerAcquireMapPage(tls *libc.TLS, pPager uintptr, pgno TPgno, pData uintptr, ppPage uintptr) (r int32) {
var p, v1 uintptr
_, _ = p, v1 /* Memory mapped page to return */
if (*TPager)(unsafe.Pointer(pPager)).FpMmapFreelist != 0 {
v1 = (*TPager)(unsafe.Pointer(pPager)).FpMmapFreelist
p = v1
**(**uintptr)(__ccgo_up(ppPage)) = v1
(*TPager)(unsafe.Pointer(pPager)).FpMmapFreelist = (*TPgHdr)(unsafe.Pointer(p)).FpDirty
(*TPgHdr)(unsafe.Pointer(p)).FpDirty = uintptr(0)
libc.X__builtin___memset_chk(tls, (*TPgHdr)(unsafe.Pointer(p)).FpExtra, 0, uint64(8), ^t__predefined_size_t(0))
} else {
v1 = _sqlite3MallocZero(tls, uint64(80)+uint64((*TPager)(unsafe.Pointer(pPager)).FnExtra))
p = v1
**(**uintptr)(__ccgo_up(ppPage)) = v1
if p == uintptr(0) {
_sqlite3OsUnfetch(tls, (*TPager)(unsafe.Pointer(pPager)).Ffd, libc.Int64FromUint32(pgno-libc.Uint32FromInt32(1))*(*TPager)(unsafe.Pointer(pPager)).FpageSize, pData)
return int32(SQLITE_NOMEM)
}
(*TPgHdr)(unsafe.Pointer(p)).FpExtra = p + 1*80
(*TPgHdr)(unsafe.Pointer(p)).Fflags = uint16(PGHDR_MMAP)
(*TPgHdr)(unsafe.Pointer(p)).FnRef = int64(1)
(*TPgHdr)(unsafe.Pointer(p)).FpPager = pPager
}
(*TPgHdr)(unsafe.Pointer(p)).Fpgno = pgno
(*TPgHdr)(unsafe.Pointer(p)).FpData = pData
(*TPager)(unsafe.Pointer(pPager)).FnMmapOut = (*TPager)(unsafe.Pointer(pPager)).FnMmapOut + 1
return SQLITE_OK
}
// 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+4544, uint64(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
//
// /*
// ** Check that there are at least nSavepoint savepoints open. If there are
// ** currently less than nSavepoints open, then open one or more savepoints
// ** to make up the difference. If the number of savepoints is already
// ** equal to nSavepoint, then this function is a no-op.
// **
// ** If a memory allocation fails, SQLITE_NOMEM is returned. If an error
// ** occurs while opening the sub-journal file, then an IO error code is
// ** returned. Otherwise, SQLITE_OK.
// */
func _pagerOpenSavepoint(tls *libc.TLS, pPager uintptr, nSavepoint int32) (r int32) {
var aNew uintptr
var ii, nCurrent, rc int32
_, _, _, _ = aNew, ii, nCurrent, rc
rc = SQLITE_OK /* Return code */
nCurrent = (*TPager)(unsafe.Pointer(pPager)).FnSavepoint /* New Pager.aSavepoint array */
/* Grow the Pager.aSavepoint array using realloc(). Return SQLITE_NOMEM
** if the allocation fails. Otherwise, zero the new portion in case a
** malloc failure occurs while populating it in the for(...) loop below.
*/
aNew = _sqlite3Realloc(tls, (*TPager)(unsafe.Pointer(pPager)).FaSavepoint, uint64(uint64(56)*libc.Uint64FromInt32(nSavepoint)))
if !(aNew != 0) {
return int32(SQLITE_NOMEM)
}
libc.X__builtin___memset_chk(tls, aNew+uintptr(nCurrent)*56, 0, libc.Uint64FromInt32(nSavepoint-nCurrent)*uint64(56), ^t__predefined_size_t(0))
(*TPager)(unsafe.Pointer(pPager)).FaSavepoint = aNew
/* Populate the PagerSavepoint structures just allocated. */
ii = nCurrent
for {
if !(ii < nSavepoint) {
break
}
(**(**TPagerSavepoint)(__ccgo_up(aNew + uintptr(ii)*56))).FnOrig = (*TPager)(unsafe.Pointer(pPager)).FdbSize
if (*Tsqlite3_file)(unsafe.Pointer((*TPager)(unsafe.Pointer(pPager)).Fjfd)).FpMethods != uintptr(0) && (*TPager)(unsafe.Pointer(pPager)).FjournalOff > 0 {
(**(**TPagerSavepoint)(__ccgo_up(aNew + uintptr(ii)*56))).FiOffset = (*TPager)(unsafe.Pointer(pPager)).FjournalOff
} else {
(**(**TPagerSavepoint)(__ccgo_up(aNew + uintptr(ii)*56))).FiOffset = libc.Int64FromUint32((*TPager)(unsafe.Pointer(pPager)).FsectorSize)
}
(**(**TPagerSavepoint)(__ccgo_up(aNew + uintptr(ii)*56))).FiSubRec = (*TPager)(unsafe.Pointer(pPager)).FnSubRec
(**(**TPagerSavepoint)(__ccgo_up(aNew + uintptr(ii)*56))).FpInSavepoint = _sqlite3BitvecCreate(tls, (*TPager)(unsafe.Pointer(pPager)).FdbSize)
(**(**TPagerSavepoint)(__ccgo_up(aNew + uintptr(ii)*56))).FbTruncateOnRelease = int32(1)
if !((**(**TPagerSavepoint)(__ccgo_up(aNew + uintptr(ii)*56))).FpInSavepoint != 0) {
return int32(SQLITE_NOMEM)
}
if (*TPager)(unsafe.Pointer(pPager)).FpWal != uintptr(0) {
_sqlite3WalSavepoint(tls, (*TPager)(unsafe.Pointer(pPager)).FpWal, aNew+uintptr(ii)*56+36)
}
(*TPager)(unsafe.Pointer(pPager)).FnSavepoint = ii + int32(1)
goto _1
_1:
;
ii = ii + 1
}
return rc
}
// C documentation
//
// /*
// ** This routine is called to increment the value of the database file
// ** change-counter, stored as a 4-byte big-endian integer starting at
// ** byte offset 24 of the pager file. The secondary change counter at
// ** 92 is also updated, as is the SQLite version number at offset 96.
// **
// ** But this only happens if the pPager->changeCountDone flag is false.
// ** To avoid excess churning of page 1, the update only happens once.
// ** See also the pager_write_changecounter() routine that does an
// ** unconditional update of the change counters.
// **
// ** If the isDirectMode flag is zero, then this is done by calling
// ** sqlite3PagerWrite() on page 1, then modifying the contents of the
// ** page data. In this case the file will be updated when the current
// ** transaction is committed.
// **
// ** The isDirectMode flag may only be non-zero if the library was compiled
// ** with the SQLITE_ENABLE_ATOMIC_WRITE macro defined. In this case,
// ** if isDirect is non-zero, then the database file is updated directly
// ** by writing an updated version of page 1 using a call to the
// ** sqlite3OsWrite() function.
// */
func _pager_incr_changecounter(tls *libc.TLS, pPager uintptr, isDirectMode int32) (r int32) {
bp := tls.Alloc(16)
defer tls.Free(16)
var pCopy, zBuf uintptr
var rc int32
var _ /* pPgHdr at bp+0 */ uintptr
_, _, _ = pCopy, rc, zBuf
rc = SQLITE_OK
/* Declare and initialize constant integer 'isDirect'. If the
** atomic-write optimization is enabled in this build, then isDirect
** is initialized to the value passed as the isDirectMode parameter
** to this function. Otherwise, it is always set to zero.
**
** The idea is that if the atomic-write optimization is not
** enabled at compile time, the compiler can omit the tests of
** 'isDirect' below, as well as the block enclosed in the
** "if( isDirect )" condition.
*/
_ = isDirectMode
if !((*TPager)(unsafe.Pointer(pPager)).FchangeCountDone != 0) && (*TPager)(unsafe.Pointer(pPager)).FdbSize > uint32(0) { /* Reference to page 1 */
/* Open page 1 of the file for writing. */
rc = _sqlite3PagerGet(tls, pPager, uint32(1), bp, 0)
/* If page one was fetched successfully, and this function is not
** operating in direct-mode, make page 1 writable. When not in
** direct mode, page 1 is always held in cache and hence the PagerGet()
** above is always successful - hence the ALWAYS on rc==SQLITE_OK.
*/
if libc.Bool(!(libc.Int32FromInt32(DIRECT_MODE) != 0)) && rc == SQLITE_OK {
rc = _sqlite3PagerWrite(tls, **(**uintptr)(__ccgo_up(bp)))
}
if rc == SQLITE_OK {
/* Actually do the update of the change counter */
_pager_write_changecounter(tls, **(**uintptr)(__ccgo_up(bp)))
/* If running in direct mode, write the contents of page 1 to the file. */
if DIRECT_MODE != 0 {
zBuf = (*TPgHdr)(unsafe.Pointer(**(**uintptr)(__ccgo_up(bp)))).FpData
if rc == SQLITE_OK {
rc = _sqlite3OsWrite(tls, (*TPager)(unsafe.Pointer(pPager)).Ffd, zBuf, int32((*TPager)(unsafe.Pointer(pPager)).FpageSize), 0)
**(**Tu32)(__ccgo_up(pPager + 248 + 2*4)) = **(**Tu32)(__ccgo_up(pPager + 248 + 2*4)) + 1
}
if rc == SQLITE_OK {
/* Update the pager's copy of the change-counter. Otherwise, the
** next time a read transaction is opened the cache will be
** flushed (as the change-counter values will not match). */
pCopy = zBuf + 24
libc.X__builtin___memcpy_chk(tls, pPager+136, pCopy, uint64(16), ^t__predefined_size_t(0))
(*TPager)(unsafe.Pointer(pPager)).FchangeCountDone = uint8(1)
}
} else {
(*TPager)(unsafe.Pointer(pPager)).FchangeCountDone = uint8(1)
}
}
/* Release the page reference. */
_sqlite3PagerUnref(tls, **(**uintptr)(__ccgo_up(bp)))
}
return rc
}
// C documentation
//
// /*
// ** Playback the journal and thus restore the database file to
// ** the state it was in before we started making changes.
// **
// ** The journal file format is as follows:
// **
// ** (1) 8 byte prefix. A copy of aJournalMagic[].
// ** (2) 4 byte big-endian integer which is the number of valid page records
// ** in the journal. If this value is 0xffffffff, then compute the
// ** number of page records from the journal size.
// ** (3) 4 byte big-endian integer which is the initial value for the
// ** sanity checksum.
// ** (4) 4 byte integer which is the number of pages to truncate the
// ** database to during a rollback.
// ** (5) 4 byte big-endian integer which is the sector size. The header
// ** is this many bytes in size.
// ** (6) 4 byte big-endian integer which is the page size.
// ** (7) zero padding out to the next sector size.
// ** (8) Zero or more pages instances, each as follows:
// ** + 4 byte page number.
// ** + pPager->pageSize bytes of data.
// ** + 4 byte checksum
// **
// ** When we speak of the journal header, we mean the first 7 items above.
// ** Each entry in the journal is an instance of the 8th item.
// **
// ** Call the value from the second bullet "nRec". nRec is the number of
// ** valid page entries in the journal. In most cases, you can compute the
// ** value of nRec from the size of the journal file. But if a power
// ** failure occurred while the journal was being written, it could be the
// ** case that the size of the journal file had already been increased but
// ** the extra entries had not yet made it safely to disk. In such a case,
// ** the value of nRec computed from the file size would be too large. For
// ** that reason, we always use the nRec value in the header.
// **
// ** If the nRec value is 0xffffffff it means that nRec should be computed
// ** from the file size. This value is used when the user selects the
// ** no-sync option for the journal. A power failure could lead to corruption
// ** in this case. But for things like temporary table (which will be
// ** deleted when the power is restored) we don't care.
// **
// ** If the file opened as the journal file is not a well-formed
// ** journal file then all pages up to the first corrupted page are rolled
// ** back (or no pages if the journal header is corrupted). The journal file
// ** is then deleted and SQLITE_OK returned, just as if no corruption had
// ** been encountered.
// **
// ** If an I/O or malloc() error occurs, the journal-file is not deleted
// ** and an error code is returned.
// **
// ** The isHot parameter indicates that we are trying to rollback a journal
// ** that might be a hot journal. Or, it could be that the journal is
// ** preserved because of JOURNALMODE_PERSIST or JOURNALMODE_TRUNCATE.
// ** If the journal really is hot, reset the pager cache prior rolling
// ** back any content. If the journal is merely persistent, no reset is
// ** needed.
// */
func _pager_playback(tls *libc.TLS, pPager uintptr, isHot int32) (r int32) {
bp := tls.Alloc(64)
defer tls.Free(64)
var nPlayback, needPagerReset, rc int32
var pVfs uintptr
var u Tu32
var _ /* mxPg at bp+12 */ TPgno
var _ /* nRec at bp+8 */ Tu32
var _ /* res at bp+16 */ int32
var _ /* savedPageSize at bp+32 */ Tu32
var _ /* szJ at bp+0 */ Ti64
var _ /* zSuper at bp+24 */ uintptr
_, _, _, _, _ = nPlayback, needPagerReset, pVfs, rc, u
pVfs = (*TPager)(unsafe.Pointer(pPager)).FpVfs /* Unsigned loop counter */
**(**TPgno)(__ccgo_up(bp + 12)) = uint32(0) /* Result code of a subroutine */
**(**int32)(__ccgo_up(bp + 16)) = int32(1) /* Value returned by sqlite3OsAccess() */
**(**uintptr)(__ccgo_up(bp + 24)) = uintptr(0) /* True to reset page prior to first page rollback */
nPlayback = 0 /* Total number of pages restored from journal */
**(**Tu32)(__ccgo_up(bp + 32)) = libc.Uint32FromInt64((*TPager)(unsafe.Pointer(pPager)).FpageSize)
/* Figure out how many records are in the journal. Abort early if
** the journal is empty.
*/
rc = _sqlite3OsFileSize(tls, (*TPager)(unsafe.Pointer(pPager)).Fjfd, bp)
if rc != SQLITE_OK {
goto end_playback
}
/* Read the super-journal name from the journal, if it is present.
** If a super-journal file name is specified, but the file is not
** present on disk, then the journal is not hot and does not need to be
** played back.
*/
rc = _readSuperJournal(tls, (*TPager)(unsafe.Pointer(pPager)).Fjfd, libc.Uint64FromInt64(int64(1)+int64((*Tsqlite3_vfs)(unsafe.Pointer((*TPager)(unsafe.Pointer(pPager)).FpVfs)).FmxPathname)), bp+24)
if rc == SQLITE_OK && **(**uintptr)(__ccgo_up(bp + 24)) != 0 {
rc = _sqlite3OsAccess(tls, pVfs, **(**uintptr)(__ccgo_up(bp + 24)), SQLITE_ACCESS_EXISTS, bp+16)
}
if rc != SQLITE_OK || !(**(**int32)(__ccgo_up(bp + 16)) != 0) {
goto end_playback
}
(*TPager)(unsafe.Pointer(pPager)).FjournalOff = 0
needPagerReset = isHot
/* This loop terminates either when a readJournalHdr() or
** pager_playback_one_page() call returns SQLITE_DONE or an IO error
** occurs.
*/
for int32(1) != 0 {
/* Read the next journal header from the journal file. If there are
** not enough bytes left in the journal file for a complete header, or
** it is corrupted, then a process must have failed while writing it.
** This indicates nothing more needs to be rolled back.
*/
rc = _readJournalHdr(tls, pPager, isHot, **(**Ti64)(__ccgo_up(bp)), bp+8, bp+12)
if rc != SQLITE_OK {
if rc == int32(SQLITE_DONE) {
rc = SQLITE_OK
}
goto end_playback
}
/* If nRec is 0xffffffff, then this journal was created by a process
** working in no-sync mode. This means that the rest of the journal
** file consists of pages, there are no more journal headers. Compute
** the value of nRec based on this assumption.
*/
if **(**Tu32)(__ccgo_up(bp + 8)) == uint32(0xffffffff) {
**(**Tu32)(__ccgo_up(bp + 8)) = libc.Uint32FromInt32(int32((**(**Ti64)(__ccgo_up(bp)) - libc.Int64FromUint32((*TPager)(unsafe.Pointer(pPager)).FsectorSize)) / ((*TPager)(unsafe.Pointer(pPager)).FpageSize + libc.Int64FromInt32(8))))
}
/* If nRec is 0 and this rollback is of a transaction created by this
** process and if this is the final header in the journal, then it means
** that this part of the journal was being filled but has not yet been
** synced to disk. Compute the number of pages based on the remaining
** size of the file.
**
** The third term of the test was added to fix ticket #2565.
** When rolling back a hot journal, nRec==0 always means that the next
** chunk of the journal contains zero pages to be rolled back. But
** when doing a ROLLBACK and the nRec==0 chunk is the last chunk in
** the journal, it means that the journal might contain additional
** pages that need to be rolled back and that the number of pages
** should be computed based on the journal file size.
*/
if **(**Tu32)(__ccgo_up(bp + 8)) == uint32(0) && !(isHot != 0) && (*TPager)(unsafe.Pointer(pPager)).FjournalHdr+libc.Int64FromUint32((*TPager)(unsafe.Pointer(pPager)).FsectorSize) == (*TPager)(unsafe.Pointer(pPager)).FjournalOff {
**(**Tu32)(__ccgo_up(bp + 8)) = libc.Uint32FromInt32(int32((**(**Ti64)(__ccgo_up(bp)) - (*TPager)(unsafe.Pointer(pPager)).FjournalOff) / ((*TPager)(unsafe.Pointer(pPager)).FpageSize + libc.Int64FromInt32(8))))
}
/* If this is the first header read from the journal, truncate the
** database file back to its original size.
*/
if (*TPager)(unsafe.Pointer(pPager)).FjournalOff == libc.Int64FromUint32((*TPager)(unsafe.Pointer(pPager)).FsectorSize) {
rc = _pager_truncate(tls, pPager, **(**TPgno)(__ccgo_up(bp + 12)))
if rc != SQLITE_OK {
goto end_playback
}
(*TPager)(unsafe.Pointer(pPager)).FdbSize = **(**TPgno)(__ccgo_up(bp + 12))
if (*TPager)(unsafe.Pointer(pPager)).FmxPgno < **(**TPgno)(__ccgo_up(bp + 12)) {
(*TPager)(unsafe.Pointer(pPager)).FmxPgno = **(**TPgno)(__ccgo_up(bp + 12))
}
}
/* Copy original pages out of the journal and back into the
** database file and/or page cache.
*/
u = uint32(0)
for {
if !(u < **(**Tu32)(__ccgo_up(bp + 8))) {
break
}
if needPagerReset != 0 {
_pager_reset(tls, pPager)
needPagerReset = 0
}
rc = _pager_playback_one_page(tls, pPager, pPager+96, uintptr(0), int32(1), 0)
if rc == SQLITE_OK {
nPlayback = nPlayback + 1
} else {
if rc == int32(SQLITE_DONE) {
(*TPager)(unsafe.Pointer(pPager)).FjournalOff = **(**Ti64)(__ccgo_up(bp))
break
} else {
if rc == libc.Int32FromInt32(SQLITE_IOERR)|libc.Int32FromInt32(2)<= int32(PAGER_WRITER_DBMOD) || libc.Int32FromUint8((*TPager)(unsafe.Pointer(pPager)).FeState) == PAGER_OPEN) {
rc = _sqlite3PagerSync(tls, pPager, uintptr(0))
}
if rc == SQLITE_OK {
rc = _pager_end_transaction(tls, pPager, libc.BoolInt32(**(**uintptr)(__ccgo_up(bp + 24)) != uintptr(0)), 0)
}
if rc == SQLITE_OK && **(**uintptr)(__ccgo_up(bp + 24)) != 0 && **(**int32)(__ccgo_up(bp + 16)) != 0 {
/* If there was a super-journal and this routine will return success,
** see if it is possible to delete the super-journal.
*/
rc = _pager_delsuper(tls, pPager, **(**uintptr)(__ccgo_up(bp + 24)))
}
if isHot != 0 && nPlayback != 0 {
Xsqlite3_log(tls, libc.Int32FromInt32(SQLITE_NOTICE)|libc.Int32FromInt32(2)< (*TPager)(unsafe.Pointer(pPager)).FdbSize || _sqlite3BitvecTest(tls, pDone, **(**TPgno)(__ccgo_up(bp + 8))) != 0 {
return SQLITE_OK
}
if isMainJrnl != 0 {
rc = _read32bits(tls, jfd, **(**Ti64)(__ccgo_up(pOffset))-int64(4), bp+12)
if rc != 0 {
return rc
}
if !(isSavepnt != 0) && _pager_cksum(tls, pPager, aData) != **(**Tu32)(__ccgo_up(bp + 12)) {
return int32(SQLITE_DONE)
}
}
/* If this page has already been played back before during the current
** rollback, then don't bother to play it back again.
*/
if v3 = pDone != 0; v3 {
v2 = _sqlite3BitvecSet(tls, pDone, **(**TPgno)(__ccgo_up(bp + 8)))
rc = v2
}
if v3 && v2 != SQLITE_OK {
return rc
}
/* When playing back page 1, restore the nReserve setting
*/
if **(**TPgno)(__ccgo_up(bp + 8)) == uint32(1) && int32((*TPager)(unsafe.Pointer(pPager)).FnReserve) != libc.Int32FromUint8(**(**Tu8)(__ccgo_up(aData + 20))) {
(*TPager)(unsafe.Pointer(pPager)).FnReserve = libc.Int16FromUint8(**(**Tu8)(__ccgo_up(aData + 20)))
}
/* If the pager is in CACHEMOD state, then there must be a copy of this
** page in the pager cache. In this case just update the pager cache,
** not the database file. The page is left marked dirty in this case.
**
** An exception to the above rule: If the database is in no-sync mode
** and a page is moved during an incremental vacuum then the page may
** not be in the pager cache. Later: if a malloc() or IO error occurs
** during a Movepage() call, then the page may not be in the cache
** either. So the condition described in the above paragraph is not
** assert()able.
**
** If in WRITER_DBMOD, WRITER_FINISHED or OPEN state, then we update the
** pager cache if it exists and the main file. The page is then marked
** not dirty. Since this code is only executed in PAGER_OPEN state for
** a hot-journal rollback, it is guaranteed that the page-cache is empty
** if the pager is in OPEN state.
**
** Ticket #1171: The statement journal might contain page content that is
** different from the page content at the start of the transaction.
** This occurs when a page is changed prior to the start of a statement
** then changed again within the statement. When rolling back such a
** statement we must not write to the original database unless we know
** for certain that original page contents are synced into the main rollback
** journal. Otherwise, a power loss might leave modified data in the
** database file without an entry in the rollback journal that can
** restore the database to its original form. Two conditions must be
** met before writing to the database files. (1) the database must be
** locked. (2) we know that the original page content is fully synced
** in the main journal either because the page is not in cache or else
** the page is marked as needSync==0.
**
** 2008-04-14: When attempting to vacuum a corrupt database file, it
** is possible to fail a statement on a database that does not yet exist.
** Do not attempt to write if database file has never been opened.
*/
if (*TPager)(unsafe.Pointer(pPager)).FpWal != uintptr(0) {
**(**uintptr)(__ccgo_up(bp)) = uintptr(0)
} else {
**(**uintptr)(__ccgo_up(bp)) = _sqlite3PagerLookup(tls, pPager, **(**TPgno)(__ccgo_up(bp + 8)))
}
if isMainJrnl != 0 {
isSynced = libc.BoolInt32((*TPager)(unsafe.Pointer(pPager)).FnoSync != 0 || **(**Ti64)(__ccgo_up(pOffset)) <= (*TPager)(unsafe.Pointer(pPager)).FjournalHdr)
} else {
isSynced = libc.BoolInt32(**(**uintptr)(__ccgo_up(bp)) == uintptr(0) || 0 == libc.Int32FromUint16((*TPgHdr)(unsafe.Pointer(**(**uintptr)(__ccgo_up(bp)))).Fflags)&int32(PGHDR_NEED_SYNC))
}
if (*Tsqlite3_file)(unsafe.Pointer((*TPager)(unsafe.Pointer(pPager)).Ffd)).FpMethods != uintptr(0) && (libc.Int32FromUint8((*TPager)(unsafe.Pointer(pPager)).FeState) >= int32(PAGER_WRITER_DBMOD) || libc.Int32FromUint8((*TPager)(unsafe.Pointer(pPager)).FeState) == PAGER_OPEN) && isSynced != 0 {
ofst = libc.Int64FromUint32(**(**TPgno)(__ccgo_up(bp + 8))-libc.Uint32FromInt32(1)) * (*TPager)(unsafe.Pointer(pPager)).FpageSize
/* Write the data read from the journal back into the database file.
** This is usually safe even for an encrypted database - as the data
** was encrypted before it was written to the journal file. The exception
** is if the data was just read from an in-memory sub-journal. In that
** case it must be encrypted here before it is copied into the database
** file. */
rc = _sqlite3OsWrite(tls, (*TPager)(unsafe.Pointer(pPager)).Ffd, aData, int32((*TPager)(unsafe.Pointer(pPager)).FpageSize), ofst)
if **(**TPgno)(__ccgo_up(bp + 8)) > (*TPager)(unsafe.Pointer(pPager)).FdbFileSize {
(*TPager)(unsafe.Pointer(pPager)).FdbFileSize = **(**TPgno)(__ccgo_up(bp + 8))
}
if (*TPager)(unsafe.Pointer(pPager)).FpBackup != 0 {
_sqlite3BackupUpdate(tls, (*TPager)(unsafe.Pointer(pPager)).FpBackup, **(**TPgno)(__ccgo_up(bp + 8)), aData)
}
} else {
if !(isMainJrnl != 0) && **(**uintptr)(__ccgo_up(bp)) == uintptr(0) {
/* If this is a rollback of a savepoint and data was not written to
** the database and the page is not in-memory, there is a potential
** problem. When the page is next fetched by the b-tree layer, it
** will be read from the database file, which may or may not be
** current.
**
** There are a couple of different ways this can happen. All are quite
** obscure. When running in synchronous mode, this can only happen
** if the page is on the free-list at the start of the transaction, then
** populated, then moved using sqlite3PagerMovepage().
**
** The solution is to add an in-memory page to the cache containing
** the data just read from the sub-journal. Mark the page as dirty
** and if the pager requires a journal-sync, then mark the page as
** requiring a journal-sync before it is written.
*/
v1 = pPager + 25
*(*Tu8)(unsafe.Pointer(v1)) = Tu8(int32(*(*Tu8)(unsafe.Pointer(v1))) | libc.Int32FromInt32(SPILLFLAG_ROLLBACK))
rc = _sqlite3PagerGet(tls, pPager, **(**TPgno)(__ccgo_up(bp + 8)), bp, int32(1))
v1 = pPager + 25
*(*Tu8)(unsafe.Pointer(v1)) = Tu8(int32(*(*Tu8)(unsafe.Pointer(v1))) & ^libc.Int32FromInt32(SPILLFLAG_ROLLBACK))
if rc != SQLITE_OK {
return rc
}
_sqlite3PcacheMakeDirty(tls, **(**uintptr)(__ccgo_up(bp)))
}
}
if **(**uintptr)(__ccgo_up(bp)) != 0 {
pData = (*TPgHdr)(unsafe.Pointer(**(**uintptr)(__ccgo_up(bp)))).FpData
libc.X__builtin___memcpy_chk(tls, pData, aData, libc.Uint64FromInt64((*TPager)(unsafe.Pointer(pPager)).FpageSize), ^t__predefined_size_t(0))
(*(*func(*libc.TLS, uintptr))(unsafe.Pointer(&struct{ uintptr }{(*TPager)(unsafe.Pointer(pPager)).FxReiniter})))(tls, **(**uintptr)(__ccgo_up(bp)))
/* It used to be that sqlite3PcacheMakeClean(pPg) was called here. But
** that call was dangerous and had no detectable benefit since the cache
** is normally cleaned by sqlite3PcacheCleanAll() after rollback and so
** has been removed. */
/* If this was page 1, then restore the value of Pager.dbFileVers.
** Do this before any decoding. */
if **(**TPgno)(__ccgo_up(bp + 8)) == uint32(1) {
libc.X__builtin___memcpy_chk(tls, pPager+136, pData+24, uint64(16), ^t__predefined_size_t(0))
}
_sqlite3PcacheRelease(tls, **(**uintptr)(__ccgo_up(bp)))
}
return rc
}
// C documentation
//
// /*
// ** This function is used to change the actual size of the database
// ** file in the file-system. This only happens when committing a transaction,
// ** or rolling back a transaction (including rolling back a hot-journal).
// **
// ** If the main database file is not open, or the pager is not in either
// ** DBMOD or OPEN state, this function is a no-op. Otherwise, the size
// ** of the file is changed to nPage pages (nPage*pPager->pageSize bytes).
// ** If the file on disk is currently larger than nPage pages, then use the VFS
// ** xTruncate() method to truncate it.
// **
// ** Or, it might be the case that the file on disk is smaller than
// ** nPage pages. Some operating system implementations can get confused if
// ** you try to truncate a file to some size that is larger than it
// ** currently is, so detect this case and write a single zero byte to
// ** the end of the new file instead.
// **
// ** If successful, return SQLITE_OK. If an IO error occurs while modifying
// ** the database file, return the error code to the caller.
// */
func _pager_truncate(tls *libc.TLS, pPager uintptr, nPage TPgno) (r int32) {
bp := tls.Alloc(16)
defer tls.Free(16)
var pTmp uintptr
var rc, szPage int32
var _ /* currentSize at bp+0 */ Ti64
var _ /* newSize at bp+8 */ Ti64
_, _, _ = pTmp, rc, szPage
rc = SQLITE_OK
if (*Tsqlite3_file)(unsafe.Pointer((*TPager)(unsafe.Pointer(pPager)).Ffd)).FpMethods != uintptr(0) && (libc.Int32FromUint8((*TPager)(unsafe.Pointer(pPager)).FeState) >= int32(PAGER_WRITER_DBMOD) || libc.Int32FromUint8((*TPager)(unsafe.Pointer(pPager)).FeState) == PAGER_OPEN) {
szPage = int32((*TPager)(unsafe.Pointer(pPager)).FpageSize)
/* TODO: Is it safe to use Pager.dbFileSize here? */
rc = _sqlite3OsFileSize(tls, (*TPager)(unsafe.Pointer(pPager)).Ffd, bp)
**(**Ti64)(__ccgo_up(bp + 8)) = int64(szPage) * libc.Int64FromUint32(nPage)
if rc == SQLITE_OK && **(**Ti64)(__ccgo_up(bp)) != **(**Ti64)(__ccgo_up(bp + 8)) {
if **(**Ti64)(__ccgo_up(bp)) > **(**Ti64)(__ccgo_up(bp + 8)) {
rc = _sqlite3OsTruncate(tls, (*TPager)(unsafe.Pointer(pPager)).Ffd, **(**Ti64)(__ccgo_up(bp + 8)))
} else {
if **(**Ti64)(__ccgo_up(bp))+int64(szPage) <= **(**Ti64)(__ccgo_up(bp + 8)) {
pTmp = (*TPager)(unsafe.Pointer(pPager)).FpTmpSpace
libc.X__builtin___memset_chk(tls, pTmp, 0, libc.Uint64FromInt32(szPage), ^t__predefined_size_t(0))
_sqlite3OsFileControlHint(tls, (*TPager)(unsafe.Pointer(pPager)).Ffd, int32(SQLITE_FCNTL_SIZE_HINT), bp+8)
rc = _sqlite3OsWrite(tls, (*TPager)(unsafe.Pointer(pPager)).Ffd, pTmp, szPage, **(**Ti64)(__ccgo_up(bp + 8))-int64(szPage))
}
}
if rc == SQLITE_OK {
(*TPager)(unsafe.Pointer(pPager)).FdbFileSize = nPage
}
}
}
return rc
}
// C documentation
//
// /*
// ** The argument is the first in a linked list of dirty pages connected
// ** by the PgHdr.pDirty pointer. This function writes each one of the
// ** in-memory pages in the list to the database file. The argument may
// ** be NULL, representing an empty list. In this case this function is
// ** a no-op.
// **
// ** The pager must hold at least a RESERVED lock when this function
// ** is called. Before writing anything to the database file, this lock
// ** is upgraded to an EXCLUSIVE lock. If the lock cannot be obtained,
// ** SQLITE_BUSY is returned and no data is written to the database file.
// **
// ** If the pager is a temp-file pager and the actual file-system file
// ** is not yet open, it is created and opened before any data is
// ** written out.
// **
// ** Once the lock has been upgraded and, if necessary, the file opened,
// ** the pages are written out to the database file in list order. Writing
// ** a page is skipped if it meets either of the following criteria:
// **
// ** * The page number is greater than Pager.dbSize, or
// ** * The PGHDR_DONT_WRITE flag is set on the page.
// **
// ** If writing out a page causes the database file to grow, Pager.dbFileSize
// ** is updated accordingly. If page 1 is written out, then the value cached
// ** in Pager.dbFileVers[] is updated to match the new value stored in
// ** the database file.
// **
// ** If everything is successful, SQLITE_OK is returned. If an IO error
// ** occurs, an IO error code is returned. Or, if the EXCLUSIVE lock cannot
// ** be obtained, SQLITE_BUSY is returned.
// */
func _pager_write_pagelist(tls *libc.TLS, pPager uintptr, pList uintptr) (r int32) {
bp := tls.Alloc(16)
defer tls.Free(16)
var offset Ti64
var pData uintptr
var pgno TPgno
var rc int32
var _ /* szFile at bp+0 */ Tsqlite3_int64
_, _, _, _ = offset, pData, pgno, rc
rc = SQLITE_OK /* Return code */
/* This function is only called for rollback pagers in WRITER_DBMOD state. */
/* If the file is a temp-file has not yet been opened, open it now. It
** is not possible for rc to be other than SQLITE_OK if this branch
** is taken, as pager_wait_on_lock() is a no-op for temp-files.
*/
if !((*Tsqlite3_file)(unsafe.Pointer((*TPager)(unsafe.Pointer(pPager)).Ffd)).FpMethods != libc.UintptrFromInt32(0)) {
rc = _pagerOpentemp(tls, pPager, (*TPager)(unsafe.Pointer(pPager)).Ffd, libc.Int32FromUint32((*TPager)(unsafe.Pointer(pPager)).FvfsFlags))
}
/* Before the first write, give the VFS a hint of what the final
** file size will be.
*/
if rc == SQLITE_OK && (*TPager)(unsafe.Pointer(pPager)).FdbHintSize < (*TPager)(unsafe.Pointer(pPager)).FdbSize && ((*TPgHdr)(unsafe.Pointer(pList)).FpDirty != 0 || (*TPgHdr)(unsafe.Pointer(pList)).Fpgno > (*TPager)(unsafe.Pointer(pPager)).FdbHintSize) {
**(**Tsqlite3_int64)(__ccgo_up(bp)) = (*TPager)(unsafe.Pointer(pPager)).FpageSize * libc.Int64FromUint32((*TPager)(unsafe.Pointer(pPager)).FdbSize)
_sqlite3OsFileControlHint(tls, (*TPager)(unsafe.Pointer(pPager)).Ffd, int32(SQLITE_FCNTL_SIZE_HINT), bp)
(*TPager)(unsafe.Pointer(pPager)).FdbHintSize = (*TPager)(unsafe.Pointer(pPager)).FdbSize
}
for rc == SQLITE_OK && pList != 0 {
pgno = (*TPgHdr)(unsafe.Pointer(pList)).Fpgno
/* If there are dirty pages in the page cache with page numbers greater
** than Pager.dbSize, this means sqlite3PagerTruncateImage() was called to
** make the file smaller (presumably by auto-vacuum code). Do not write
** any such pages to the file.
**
** Also, do not write out any page that has the PGHDR_DONT_WRITE flag
** set (set by sqlite3PagerDontWrite()).
*/
if pgno <= (*TPager)(unsafe.Pointer(pPager)).FdbSize && 0 == libc.Int32FromUint16((*TPgHdr)(unsafe.Pointer(pList)).Fflags)&int32(PGHDR_DONT_WRITE) {
offset = libc.Int64FromUint32(pgno-libc.Uint32FromInt32(1)) * (*TPager)(unsafe.Pointer(pPager)).FpageSize /* Data to write */
if (*TPgHdr)(unsafe.Pointer(pList)).Fpgno == uint32(1) {
_pager_write_changecounter(tls, pList)
}
pData = (*TPgHdr)(unsafe.Pointer(pList)).FpData
/* Write out the page data. */
rc = _sqlite3OsWrite(tls, (*TPager)(unsafe.Pointer(pPager)).Ffd, pData, int32((*TPager)(unsafe.Pointer(pPager)).FpageSize), offset)
/* If page 1 was just written, update Pager.dbFileVers to match
** the value now stored in the database file. If writing this
** page caused the database file to grow, update dbFileSize.
*/
if pgno == uint32(1) {
libc.X__builtin___memcpy_chk(tls, pPager+136, pData+24, uint64(16), ^t__predefined_size_t(0))
}
if pgno > (*TPager)(unsafe.Pointer(pPager)).FdbFileSize {
(*TPager)(unsafe.Pointer(pPager)).FdbFileSize = pgno
}
**(**Tu32)(__ccgo_up(pPager + 248 + 2*4)) = **(**Tu32)(__ccgo_up(pPager + 248 + 2*4)) + 1
/* Update any backup objects copying the contents of this pager. */
_sqlite3BackupUpdate(tls, (*TPager)(unsafe.Pointer(pPager)).FpBackup, pgno, (*TPgHdr)(unsafe.Pointer(pList)).FpData)
} else {
}
pList = (*TPgHdr)(unsafe.Pointer(pList)).FpDirty
}
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+80 */ 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.X__builtin___memset_chk(tls, bp+8, 0, uint64(48), ^t__predefined_size_t(0))
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.X__builtin___memset_chk(tls, p, 0, uint64(48), ^t__predefined_size_t(0))
(*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.X__builtin___memset_chk(tls, bp+80, 0, uint64(48), ^t__predefined_size_t(0))
if _parseHhMmSs(tls, z2, bp+80) != 0 {
break
}
_computeJD(tls, bp+80)
(**(**TDateTime)(__ccgo_up(bp + 80))).FiJD -= int64(43200000)
day = (**(**TDateTime)(__ccgo_up(bp + 80))).FiJD / int64(86400000)
(**(**TDateTime)(__ccgo_up(bp + 80))).FiJD -= day * int64(86400000)
if int32(z0) == int32('-') {
(**(**TDateTime)(__ccgo_up(bp + 80))).FiJD = -(**(**TDateTime)(__ccgo_up(bp + 80))).FiJD
}
_computeJD(tls, p)
_clearYMD_HMS_TZ(tls, p)
**(**Tsqlite3_int64)(__ccgo_up(p)) += (**(**TDateTime)(__ccgo_up(bp + 80))).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.Int32FromUint64(libc.Uint64FromInt64(96)/libc.Uint64FromInt64(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
//
// /* Add a single new term to an ExprList that is used to store a
// ** list of identifiers. Report an error if the ID list contains
// ** a COLLATE clause or an ASC or DESC keyword, except ignore the
// ** error while parsing a legacy schema.
// */
func _parserAddExprIdListTerm(tls *libc.TLS, pParse uintptr, pPrior uintptr, pIdToken uintptr, hasCollate int32, sortOrder int32) (r uintptr) {
bp := tls.Alloc(32)
defer tls.Free(32)
var p uintptr
_ = p
p = _sqlite3ExprListAppend(tls, pParse, pPrior, uintptr(0))
if (hasCollate != 0 || sortOrder != -int32(1)) && libc.Int32FromUint8((*Tsqlite3)(unsafe.Pointer((*TParse)(unsafe.Pointer(pParse)).Fdb)).Finit1.Fbusy) == 0 {
_sqlite3ErrorMsg(tls, pParse, __ccgo_ts+25336, libc.VaList(bp+8, (*TToken)(unsafe.Pointer(pIdToken)).Fn, (*TToken)(unsafe.Pointer(pIdToken)).Fz))
}
_sqlite3ExprListSetName(tls, pParse, p, pIdToken, int32(1))
return p
}
/**************** End of %include directives **********************************/
/* These constants specify the various numeric values for terminal symbols.
***************** Begin token definitions *************************************/
/**************** End token definitions ***************************************/
// C documentation
//
// /*
// ** For a compound SELECT statement, make sure p->pPrior->pNext==p for
// ** all elements in the list. And make sure list length does not exceed
// ** SQLITE_LIMIT_COMPOUND_SELECT.
// */
func _parserDoubleLinkSelect(tls *libc.TLS, pParse uintptr, p uintptr) {
bp := tls.Alloc(32)
defer tls.Free(32)
var cnt, mxSelect, v2 int32
var pLoop, pNext, v1 uintptr
var v3 bool
_, _, _, _, _, _, _ = cnt, mxSelect, pLoop, pNext, v1, v2, v3
if (*TSelect)(unsafe.Pointer(p)).FpPrior != 0 {
pNext = uintptr(0)
pLoop = p
cnt = int32(1)
for int32(1) != 0 {
(*TSelect)(unsafe.Pointer(pLoop)).FpNext = pNext
**(**Tu32)(__ccgo_up(pLoop + 4)) |= uint32(SF_Compound)
pNext = pLoop
pLoop = (*TSelect)(unsafe.Pointer(pLoop)).FpPrior
if pLoop == uintptr(0) {
break
}
cnt = cnt + 1
if (*TSelect)(unsafe.Pointer(pLoop)).FpOrderBy != 0 || (*TSelect)(unsafe.Pointer(pLoop)).FpLimit != 0 {
if (*TSelect)(unsafe.Pointer(pLoop)).FpOrderBy != uintptr(0) {
v1 = __ccgo_ts + 25245
} else {
v1 = __ccgo_ts + 25254
}
_sqlite3ErrorMsg(tls, pParse, __ccgo_ts+25260, libc.VaList(bp+8, v1, _sqlite3SelectOpName(tls, libc.Int32FromUint8((*TSelect)(unsafe.Pointer(pNext)).Fop))))
break
}
}
if v3 = (*TSelect)(unsafe.Pointer(p)).FselFlags&libc.Uint32FromInt32(libc.Int32FromInt32(SF_MultiValue)|libc.Int32FromInt32(SF_Values)) == uint32(0); v3 {
v2 = **(**int32)(__ccgo_up((*TParse)(unsafe.Pointer(pParse)).Fdb + 136 + 4*4))
mxSelect = v2
}
if v3 && v2 > 0 && cnt > mxSelect {
_sqlite3ErrorMsg(tls, pParse, __ccgo_ts+25302, 0)
}
}
}
// C documentation
//
// /*
// ** Generate a syntax error
// */
func _parserSyntaxError(tls *libc.TLS, pParse uintptr, p uintptr) {
bp := tls.Alloc(16)
defer tls.Free(16)
_sqlite3ErrorMsg(tls, pParse, __ccgo_ts+25221, libc.VaList(bp+8, p))
}
// C documentation
//
// /*
// ** Implementation of the sqlite3_pcache.xInit method.
// */
func _pcache1Init(tls *libc.TLS, NotUsed uintptr) (r int32) {
_ = NotUsed
libc.X__builtin___memset_chk(tls, uintptr(unsafe.Pointer(&_pcache1_g)), 0, uint64(144), ^t__predefined_size_t(0))
/*
** The pcache1.separateCache variable is true if each PCache has its own
** private PGroup (mode-1). pcache1.separateCache is false if the single
** PGroup in pcache1.grp is used for all page caches (mode-2).
**
** * Always use a unified cache (mode-2) if ENABLE_MEMORY_MANAGEMENT
**
** * Use a unified cache in single-threaded applications that have
** configured a start-time buffer for use as page-cache memory using
** sqlite3_config(SQLITE_CONFIG_PAGECACHE, pBuf, sz, N) with non-NULL
** pBuf argument.
**
** * Otherwise use separate caches (mode-1)
*/
_pcache1_g.FseparateCache = 0
if _sqlite3Config.FbCoreMutex != 0 {
_pcache1_g.Fgrp.Fmutex = _sqlite3MutexAlloc(tls, int32(SQLITE_MUTEX_STATIC_LRU))
_pcache1_g.Fmutex = _sqlite3MutexAlloc(tls, int32(SQLITE_MUTEX_STATIC_PMEM))
}
if _pcache1_g.FseparateCache != 0 && _sqlite3Config.FnPage != 0 && _sqlite3Config.FpPage == uintptr(0) {
_pcache1_g.FnInitPage = _sqlite3Config.FnPage
} else {
_pcache1_g.FnInitPage = 0
}
_pcache1_g.Fgrp.FmxPinned = uint32(10)
libc.AtomicStorePInt32(uintptr(unsafe.Pointer(&_pcache1_g))+80, int32(1))
return SQLITE_OK
}
// C documentation
//
// /*
// ** Implementation of the sqlite3_pcache.xShutdown method.
// ** Note that the static mutex allocated in xInit does
// ** not need to be freed.
// */
func _pcache1Shutdown(tls *libc.TLS, NotUsed uintptr) {
_ = NotUsed
libc.X__builtin___memset_chk(tls, uintptr(unsafe.Pointer(&_pcache1_g)), 0, uint64(144), ^t__predefined_size_t(0))
}
// C documentation
//
// /*
// ** This is a helper routine for sqlite3PcacheFetchFinish()
// **
// ** In the uncommon case where the page being fetched has not been
// ** initialized, this routine is invoked to do the initialization.
// ** This routine is broken out into a separate function since it
// ** requires extra stack manipulation that can be avoided in the common
// ** case.
// */
func _pcacheFetchFinishWithInit(tls *libc.TLS, pCache uintptr, pgno TPgno, pPage uintptr) (r uintptr) {
var pPgHdr uintptr
_ = pPgHdr
pPgHdr = (*Tsqlite3_pcache_page)(unsafe.Pointer(pPage)).FpExtra
libc.X__builtin___memset_chk(tls, pPgHdr+32, 0, libc.Uint64FromInt64(80)-uint64(libc.UintptrFromInt32(0)+32), ^t__predefined_size_t(0))
(*TPgHdr)(unsafe.Pointer(pPgHdr)).FpPage = pPage
(*TPgHdr)(unsafe.Pointer(pPgHdr)).FpData = (*Tsqlite3_pcache_page)(unsafe.Pointer(pPage)).FpBuf
(*TPgHdr)(unsafe.Pointer(pPgHdr)).FpExtra = pPgHdr + 1*80
libc.X__builtin___memset_chk(tls, (*TPgHdr)(unsafe.Pointer(pPgHdr)).FpExtra, 0, uint64(8), ^t__predefined_size_t(0))
(*TPgHdr)(unsafe.Pointer(pPgHdr)).FpCache = pCache
(*TPgHdr)(unsafe.Pointer(pPgHdr)).Fpgno = pgno
(*TPgHdr)(unsafe.Pointer(pPgHdr)).Fflags = uint16(PGHDR_CLEAN)
return _sqlite3PcacheFetchFinish(tls, pCache, pgno, pPage)
}
// C documentation
//
// /*
// ** Sort the list of pages in ascending order by pgno. Pages are
// ** connected by pDirty pointers. The pDirtyPrev pointers are
// ** corrupted by this sort.
// **
// ** Since there cannot be more than 2^31 distinct pages in a database,
// ** there cannot be more than 31 buckets required by the merge sorter.
// ** One extra bucket is added to catch overflow in case something
// ** ever changes to make the previous sentence incorrect.
// */
func _pcacheSortDirtyList(tls *libc.TLS, pIn uintptr) (r uintptr) {
bp := tls.Alloc(256)
defer tls.Free(256)
var i int32
var p, v3 uintptr
var _ /* a at bp+0 */ [32]uintptr
_, _, _ = i, p, v3
libc.X__builtin___memset_chk(tls, bp, 0, uint64(256), ^t__predefined_size_t(0))
for pIn != 0 {
p = pIn
pIn = (*TPgHdr)(unsafe.Pointer(p)).FpDirty
(*TPgHdr)(unsafe.Pointer(p)).FpDirty = uintptr(0)
i = 0
for {
if !(i < libc.Int32FromInt32(N_SORT_BUCKET)-libc.Int32FromInt32(1)) {
break
}
if (**(**[32]uintptr)(__ccgo_up(bp)))[i] == uintptr(0) {
(**(**[32]uintptr)(__ccgo_up(bp)))[i] = p
break
} else {
p = _pcacheMergeDirtyList(tls, (**(**[32]uintptr)(__ccgo_up(bp)))[i], p)
(**(**[32]uintptr)(__ccgo_up(bp)))[i] = uintptr(0)
}
goto _1
_1:
;
i = i + 1
}
if i == libc.Int32FromInt32(N_SORT_BUCKET)-libc.Int32FromInt32(1) {
/* To get here, there need to be 2^(N_SORT_BUCKET) elements in
** the input list. But that is impossible.
*/
(**(**[32]uintptr)(__ccgo_up(bp)))[i] = _pcacheMergeDirtyList(tls, (**(**[32]uintptr)(__ccgo_up(bp)))[i], p)
}
}
p = (**(**[32]uintptr)(__ccgo_up(bp)))[0]
i = int32(1)
for {
if !(i < int32(N_SORT_BUCKET)) {
break
}
if (**(**[32]uintptr)(__ccgo_up(bp)))[i] == uintptr(0) {
goto _2
}
if p != 0 {
v3 = _pcacheMergeDirtyList(tls, p, (**(**[32]uintptr)(__ccgo_up(bp)))[i])
} else {
v3 = (**(**[32]uintptr)(__ccgo_up(bp)))[i]
}
p = v3
goto _2
_2:
;
i = i + 1
}
return p
}
// C documentation
//
// /*
// ** Lower the locking level on file descriptor pFile to eFileLock. eFileLock
// ** must be either NO_LOCK or SHARED_LOCK.
// **
// ** If the locking level of the file descriptor is already at or below
// ** the requested locking level, this routine is a no-op.
// **
// ** If handleNFSUnlock is true, then on downgrading an EXCLUSIVE_LOCK to SHARED
// ** the byte range is divided into 2 parts and the first part is unlocked then
// ** set to a read lock, then the other part is simply unlocked. This works
// ** around a bug in BSD NFS lockd (also seen on MacOSX 10.3+) that fails to
// ** remove the write lock on a region when a read lock is set.
// */
func _posixUnlock(tls *libc.TLS, id uintptr, eFileLock int32, handleNFSUnlock int32) (r int32) {
bp := tls.Alloc(32)
defer tls.Free(32)
var divSize, v1 Toff_t
var pFile, pInode uintptr
var rc, tErrno int32
var _ /* lock at bp+0 */ Tflock
_, _, _, _, _, _ = divSize, pFile, pInode, rc, tErrno, v1
pFile = id
rc = SQLITE_OK
if libc.Int32FromUint8((*TunixFile)(unsafe.Pointer(pFile)).FeFileLock) <= eFileLock {
return SQLITE_OK
}
pInode = (*TunixFile)(unsafe.Pointer(pFile)).FpInode
Xsqlite3_mutex_enter(tls, (*TunixInodeInfo)(unsafe.Pointer(pInode)).FpLockMutex)
if libc.Int32FromUint8((*TunixFile)(unsafe.Pointer(pFile)).FeFileLock) > int32(SHARED_LOCK) {
/* downgrading to a shared lock on NFS involves clearing the write lock
** before establishing the readlock - to avoid a race condition we downgrade
** the lock in 2 blocks, so that part of the range will be covered by a
** write lock until the rest is covered by a read lock:
** 1: [WWWWW]
** 2: [....W]
** 3: [RRRRW]
** 4: [RRRR.]
*/
if eFileLock == int32(SHARED_LOCK) {
if handleNFSUnlock != 0 { /* Error code from system call errors */
divSize = int64(libc.Int32FromInt32(SHARED_SIZE) - libc.Int32FromInt32(1))
(**(**Tflock)(__ccgo_up(bp))).Fl_type = int16(F_UNLCK)
(**(**Tflock)(__ccgo_up(bp))).Fl_whence = SEEK_SET
(**(**Tflock)(__ccgo_up(bp))).Fl_start = int64(_sqlite3PendingByte + libc.Int32FromInt32(2))
(**(**Tflock)(__ccgo_up(bp))).Fl_len = divSize
if _unixFileLock(tls, pFile, bp) == -int32(1) {
tErrno = **(**int32)(__ccgo_up(libc.X__error(tls)))
rc = libc.Int32FromInt32(SQLITE_IOERR) | libc.Int32FromInt32(8)< upr {
v1 = uintptr(0)
} else {
v1 = uintptr(unsafe.Pointer(&_aPragmaName)) + uintptr(mid)*24
}
return v1
}
// 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+32 */ [200]int8
_, _, _, _, _, _ = cSep, i, j, pPragma, pTab, rc
pPragma = pAux
pTab = uintptr(0)
cSep = int8('(')
_ = argc
_ = argv
_sqlite3StrAccumInit(tls, bp, uintptr(0), bp+32, int32(200), 0)
Xsqlite3_str_appendall(tls, bp, __ccgo_ts+20303)
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+20318, libc.VaList(bp+240, 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+20325, libc.VaList(bp+240, (*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+20331)
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+20343)
j = j + 1
}
Xsqlite3_str_append(tls, bp, __ccgo_ts+5605, int32(1))
_sqlite3StrAccumFinish(tls, bp)
rc = Xsqlite3_declare_vtab(tls, db, bp+32)
if rc == SQLITE_OK {
pTab = Xsqlite3_malloc(tls, int32(48))
if pTab == uintptr(0) {
rc = int32(SQLITE_NOMEM)
} else {
libc.X__builtin___memset_chk(tls, pTab, 0, uint64(48), ^t__predefined_size_t(0))
(*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+3944, libc.VaList(bp+240, 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)*8)))
if zText != 0 {
**(**uintptr)(__ccgo_up(pCsr + 24 + uintptr(j)*8)) = Xsqlite3_mprintf(tls, __ccgo_ts+3944, libc.VaList(bp+40, zText))
if **(**uintptr)(__ccgo_up(pCsr + 24 + uintptr(j)*8)) == uintptr(0) {
return int32(SQLITE_NOMEM)
}
}
goto _2
_2:
;
i = i + 1
j = j + 1
}
_sqlite3StrAccumInit(tls, bp, uintptr(0), uintptr(0), 0, **(**int32)(__ccgo_up((*TPragmaVtab)(unsafe.Pointer(pTab)).Fdb + 136 + 1*4)))
Xsqlite3_str_appendall(tls, bp, __ccgo_ts+20358)
if **(**uintptr)(__ccgo_up(pCsr + 24 + 1*8)) != 0 {
Xsqlite3_str_appendf(tls, bp, __ccgo_ts+20366, libc.VaList(bp+40, **(**uintptr)(__ccgo_up(pCsr + 24 + 1*8))))
}
Xsqlite3_str_appendall(tls, bp, (*TPragmaName)(unsafe.Pointer((*TPragmaVtab)(unsafe.Pointer(pTab)).FpName)).FzName)
if **(**uintptr)(__ccgo_up(pCsr + 24)) != 0 {
Xsqlite3_str_appendf(tls, bp, __ccgo_ts+20370, libc.VaList(bp+40, **(**uintptr)(__ccgo_up(pCsr + 24))))
}
zSql = _sqlite3StrAccumFinish(tls, bp)
if zSql == uintptr(0) {
return int32(SQLITE_NOMEM)
}
rc = Xsqlite3_prepare_v2(tls, (*TPragmaVtab)(unsafe.Pointer(pTab)).Fdb, zSql, -int32(1), pCsr+8, uintptr(0))
Xsqlite3_free(tls, zSql)
if rc != SQLITE_OK {
(*TPragmaVtab)(unsafe.Pointer(pTab)).Fbase.FzErrMsg = Xsqlite3_mprintf(tls, __ccgo_ts+3944, libc.VaList(bp+40, Xsqlite3_errmsg(tls, (*TPragmaVtab)(unsafe.Pointer(pTab)).Fdb)))
return rc
}
return _pragmaVtabNext(tls, pVtabCursor)
}
// C documentation
//
// /* Create a new cursor for the pragma virtual table */
func _pragmaVtabOpen(tls *libc.TLS, pVtab uintptr, ppCursor uintptr) (r int32) {
var pCsr uintptr
_ = pCsr
pCsr = Xsqlite3_malloc(tls, int32(40))
if pCsr == uintptr(0) {
return int32(SQLITE_NOMEM)
}
libc.X__builtin___memset_chk(tls, pCsr, 0, uint64(40), ^t__predefined_size_t(0))
(*TPragmaVtabCursor)(unsafe.Pointer(pCsr)).Fbase.FpVtab = pVtab
**(**uintptr)(__ccgo_up(ppCursor)) = pCsr
return SQLITE_OK
}
// C documentation
//
// /*
// ** The WHERE-clause constant propagation optimization.
// **
// ** If the WHERE clause contains terms of the form COLUMN=CONSTANT or
// ** CONSTANT=COLUMN that are top-level AND-connected terms that are not
// ** part of a ON clause from a LEFT JOIN, then throughout the query
// ** replace all other occurrences of COLUMN with CONSTANT.
// **
// ** For example, the query:
// **
// ** SELECT * FROM t1, t2, t3 WHERE t1.a=39 AND t2.b=t1.a AND t3.c=t2.b
// **
// ** Is transformed into
// **
// ** SELECT * FROM t1, t2, t3 WHERE t1.a=39 AND t2.b=39 AND t3.c=39
// **
// ** Return true if any transformations where made and false if not.
// **
// ** Implementation note: Constant propagation is tricky due to affinity
// ** and collating sequence interactions. Consider this example:
// **
// ** CREATE TABLE t1(a INT,b TEXT);
// ** INSERT INTO t1 VALUES(123,'0123');
// ** SELECT * FROM t1 WHERE a=123 AND b=a;
// ** SELECT * FROM t1 WHERE a=123 AND b=123;
// **
// ** The two SELECT statements above should return different answers. b=a
// ** is always true because the comparison uses numeric affinity, but b=123
// ** is false because it uses text affinity and '0123' is not the same as '123'.
// ** To work around this, the expression tree is not actually changed from
// ** "b=a" to "b=123" but rather the "a" in "b=a" is tagged with EP_FixedCol
// ** and the "123" value is hung off of the pLeft pointer. Code generator
// ** routines know to generate the constant "123" instead of looking up the
// ** column value. Also, to avoid collation problems, this optimization is
// ** only attempted if the "a=123" term uses the default BINARY collation.
// **
// ** 2021-05-25 forum post 6a06202608: Another troublesome case is...
// **
// ** CREATE TABLE t1(x);
// ** INSERT INTO t1 VALUES(10.0);
// ** SELECT 1 FROM t1 WHERE x=10 AND x LIKE 10;
// **
// ** The query should return no rows, because the t1.x value is '10.0' not '10'
// ** and '10.0' is not LIKE '10'. But if we are not careful, the first WHERE
// ** term "x=10" will cause the second WHERE term to become "10 LIKE 10",
// ** resulting in a false positive. To avoid this, constant propagation for
// ** columns with BLOB affinity is only allowed if the constant is used with
// ** operators ==, <=, <, >=, >, or IS in a way that will cause the correct
// ** type conversions to occur. See logic associated with the bHasAffBlob flag
// ** for details.
// */
func _propagateConstants(tls *libc.TLS, pParse uintptr, p uintptr) (r int32) {
bp := tls.Alloc(96)
defer tls.Free(96)
var nChng int32
var _ /* w at bp+40 */ TWalker
var _ /* x at bp+0 */ TWhereConst
_ = nChng
nChng = 0
(**(**TWhereConst)(__ccgo_up(bp))).FpParse = pParse
(**(**TWhereConst)(__ccgo_up(bp))).FpOomFault = (*TParse)(unsafe.Pointer(pParse)).Fdb + 103
for cond := true; cond; cond = (**(**TWhereConst)(__ccgo_up(bp))).FnChng != 0 {
(**(**TWhereConst)(__ccgo_up(bp))).FnConst = 0
(**(**TWhereConst)(__ccgo_up(bp))).FnChng = 0
(**(**TWhereConst)(__ccgo_up(bp))).FapExpr = uintptr(0)
(**(**TWhereConst)(__ccgo_up(bp))).FbHasAffBlob = 0
if (*TSelect)(unsafe.Pointer(p)).FpSrc != uintptr(0) && (*TSrcList)(unsafe.Pointer((*TSelect)(unsafe.Pointer(p)).FpSrc)).FnSrc > 0 && libc.Int32FromUint8((*(*TSrcItem)(unsafe.Pointer((*TSelect)(unsafe.Pointer(p)).FpSrc + 8))).Ffg.Fjointype)&int32(JT_LTORJ) != 0 {
/* Do not propagate constants on any ON clause if there is a
** RIGHT JOIN anywhere in the query */
(**(**TWhereConst)(__ccgo_up(bp))).FmExcludeOn = libc.Uint32FromInt32(libc.Int32FromInt32(EP_InnerON) | libc.Int32FromInt32(EP_OuterON))
} else {
/* Do not propagate constants through the ON clause of a LEFT JOIN */
(**(**TWhereConst)(__ccgo_up(bp))).FmExcludeOn = uint32(EP_OuterON)
}
_findConstInWhere(tls, bp, (*TSelect)(unsafe.Pointer(p)).FpWhere)
if (**(**TWhereConst)(__ccgo_up(bp))).FnConst != 0 {
libc.X__builtin___memset_chk(tls, bp+40, 0, uint64(48), ^t__predefined_size_t(0))
(**(**TWalker)(__ccgo_up(bp + 40))).FpParse = pParse
(**(**TWalker)(__ccgo_up(bp + 40))).FxExprCallback = __ccgo_fp(_propagateConstantExprRewrite)
(**(**TWalker)(__ccgo_up(bp + 40))).FxSelectCallback = __ccgo_fp(_sqlite3SelectWalkNoop)
(**(**TWalker)(__ccgo_up(bp + 40))).FxSelectCallback2 = uintptr(0)
(**(**TWalker)(__ccgo_up(bp + 40))).FwalkerDepth = 0
*(*uintptr)(unsafe.Pointer(bp + 40 + 40)) = bp
_sqlite3WalkExpr(tls, bp+40, (*TSelect)(unsafe.Pointer(p)).FpWhere)
_sqlite3DbFree(tls, (*TParse)(unsafe.Pointer((**(**TWhereConst)(__ccgo_up(bp))).FpParse)).Fdb, (**(**TWhereConst)(__ccgo_up(bp))).FapExpr)
nChng = nChng + (**(**TWhereConst)(__ccgo_up(bp))).FnChng
}
}
return nChng
}
// C documentation
//
// /*
// ** Takes an open conch file, copies the contents to a new path and then moves
// ** it back. The newly created file's file descriptor is assigned to the
// ** conch file structure and finally the original conch file descriptor is
// ** closed. Returns zero if successful.
// */
func _proxyBreakConchLock(tls *libc.TLS, pFile uintptr, myHostID uintptr) (r int32) {
bp := tls.Alloc(2160)
defer tls.Free(2160)
var cPath, conchFile, pCtx uintptr
var fd, rc int32
var pathLen, readLen Tsize_t
var _ /* buf at bp+1024 */ [1041]int8
var _ /* errmsg at bp+2065 */ [64]int8
var _ /* tPath at bp+0 */ [1024]int8
_, _, _, _, _, _, _ = cPath, conchFile, fd, pCtx, pathLen, rc, readLen
pCtx = (*TunixFile)(unsafe.Pointer(pFile)).FlockingContext
conchFile = (*TproxyLockingContext)(unsafe.Pointer(pCtx)).FconchFile
cPath = (*TproxyLockingContext)(unsafe.Pointer(pCtx)).FconchFilePath
readLen = uint64(0)
pathLen = uint64(0)
**(**[64]int8)(__ccgo_up(bp + 2065)) = [64]int8{}
fd = -int32(1)
rc = -int32(1)
_ = myHostID
/* create a new path by replace the trailing '-conch' with '-break' */
pathLen = libc.Xstrlcpy(tls, bp, cPath, uint64(PATH_MAX))
if pathLen > uint64(PATH_MAX) || pathLen < uint64(6) || libc.Xstrlcpy(tls, bp+uintptr(pathLen-uint64(5)), __ccgo_ts+4186, uint64(6)) != uint64(5) {
Xsqlite3_snprintf(tls, int32(64), bp+2065, __ccgo_ts+4192, libc.VaList(bp+2144, libc.Int32FromUint64(pathLen)))
goto end_breaklock
}
/* read the conch content */
readLen = libc.Uint64FromInt64((*(*func(*libc.TLS, int32, uintptr, Tsize_t, Toff_t) Tssize_t)(unsafe.Pointer(&struct{ uintptr }{_aSyscall[int32(9)].FpCurrent})))(tls, (*TunixFile)(unsafe.Pointer(conchFile)).Fh, bp+1024, libc.Uint64FromInt32(libc.Int32FromInt32(PROXY_HEADERLEN)+libc.Int32FromInt32(PROXY_HOSTIDLEN)+libc.Int32FromInt32(PATH_MAX)), 0))
if readLen < libc.Uint64FromInt32(libc.Int32FromInt32(PROXY_HEADERLEN)+libc.Int32FromInt32(PROXY_HOSTIDLEN)) {
Xsqlite3_snprintf(tls, int32(64), bp+2065, __ccgo_ts+4212, libc.VaList(bp+2144, libc.Int32FromUint64(readLen)))
goto end_breaklock
}
/* write it out to the temporary break file */
fd = _robust_open(tls, bp, libc.Int32FromInt32(O_RDWR)|libc.Int32FromInt32(O_CREAT)|libc.Int32FromInt32(O_EXCL)|libc.Int32FromInt32(O_NOFOLLOW), uint16(0))
if fd < 0 {
Xsqlite3_snprintf(tls, int32(64), bp+2065, __ccgo_ts+4232, libc.VaList(bp+2144, **(**int32)(__ccgo_up(libc.X__error(tls)))))
goto end_breaklock
}
if (*(*func(*libc.TLS, int32, uintptr, Tsize_t, Toff_t) Tssize_t)(unsafe.Pointer(&struct{ uintptr }{_aSyscall[int32(12)].FpCurrent})))(tls, fd, bp+1024, readLen, 0) != libc.Int64FromUint64(readLen) {
Xsqlite3_snprintf(tls, int32(64), bp+2065, __ccgo_ts+4251, libc.VaList(bp+2144, **(**int32)(__ccgo_up(libc.X__error(tls)))))
goto end_breaklock
}
if libc.Xrename(tls, bp, cPath) != 0 {
Xsqlite3_snprintf(tls, int32(64), bp+2065, __ccgo_ts+4269, libc.VaList(bp+2144, **(**int32)(__ccgo_up(libc.X__error(tls)))))
goto end_breaklock
}
rc = 0
libc.Xfprintf(tls, libc.X__stderrp, __ccgo_ts+4288, libc.VaList(bp+2144, cPath))
_robust_close(tls, pFile, (*TunixFile)(unsafe.Pointer(conchFile)).Fh, int32(47890))
(*TunixFile)(unsafe.Pointer(conchFile)).Fh = fd
(*TunixFile)(unsafe.Pointer(conchFile)).FopenFlags = libc.Int32FromInt32(O_RDWR) | libc.Int32FromInt32(O_CREAT)
goto end_breaklock
end_breaklock:
;
if rc != 0 {
if fd >= 0 {
(*(*func(*libc.TLS, uintptr) int32)(unsafe.Pointer(&struct{ uintptr }{_aSyscall[int32(16)].FpCurrent})))(tls, bp)
_robust_close(tls, pFile, fd, int32(47898))
}
libc.Xfprintf(tls, libc.X__stderrp, __ccgo_ts+4312, libc.VaList(bp+2144, cPath, bp+2065))
}
return rc
}
// C documentation
//
// /*
// ** This routine checks if there is a RESERVED lock held on the specified
// ** file by this or any other process. If such a lock is held, set *pResOut
// ** to a non-zero value otherwise *pResOut is set to zero. The return value
// ** is set to SQLITE_OK unless an I/O error occurs during lock checking.
// */
func _proxyCheckReservedLock(tls *libc.TLS, id uintptr, pResOut uintptr) (r int32) {
var pCtx, pFile, proxy uintptr
var rc int32
_, _, _, _ = pCtx, pFile, proxy, rc
pFile = id
rc = _proxyTakeConch(tls, pFile)
if rc == SQLITE_OK {
pCtx = (*TunixFile)(unsafe.Pointer(pFile)).FlockingContext
if (*TproxyLockingContext)(unsafe.Pointer(pCtx)).FconchHeld > 0 {
proxy = (*TproxyLockingContext)(unsafe.Pointer(pCtx)).FlockProxy
return (*(*func(*libc.TLS, uintptr, uintptr) int32)(unsafe.Pointer(&struct{ uintptr }{(*Tsqlite3_io_methods)(unsafe.Pointer((*TunixFile)(unsafe.Pointer(proxy)).FpMethod)).FxCheckReservedLock})))(tls, proxy, pResOut)
} else { /* conchHeld < 0 is lockless */
pResOut = uintptr(0)
}
}
return rc
}
// C documentation
//
// /*
// ** Close a file that uses proxy locks.
// */
func _proxyClose(tls *libc.TLS, id uintptr) (r int32) {
var conchFile, lockProxy, pCtx, pFile uintptr
var rc int32
_, _, _, _, _ = conchFile, lockProxy, pCtx, pFile, rc
if id != 0 {
pFile = id
pCtx = (*TunixFile)(unsafe.Pointer(pFile)).FlockingContext
lockProxy = (*TproxyLockingContext)(unsafe.Pointer(pCtx)).FlockProxy
conchFile = (*TproxyLockingContext)(unsafe.Pointer(pCtx)).FconchFile
rc = SQLITE_OK
if lockProxy != 0 {
rc = (*(*func(*libc.TLS, uintptr, int32) int32)(unsafe.Pointer(&struct{ uintptr }{(*Tsqlite3_io_methods)(unsafe.Pointer((*TunixFile)(unsafe.Pointer(lockProxy)).FpMethod)).FxUnlock})))(tls, lockProxy, NO_LOCK)
if rc != 0 {
return rc
}
rc = (*(*func(*libc.TLS, uintptr) int32)(unsafe.Pointer(&struct{ uintptr }{(*Tsqlite3_io_methods)(unsafe.Pointer((*TunixFile)(unsafe.Pointer(lockProxy)).FpMethod)).FxClose})))(tls, lockProxy)
if rc != 0 {
return rc
}
Xsqlite3_free(tls, lockProxy)
(*TproxyLockingContext)(unsafe.Pointer(pCtx)).FlockProxy = uintptr(0)
}
if conchFile != 0 {
if (*TproxyLockingContext)(unsafe.Pointer(pCtx)).FconchHeld != 0 {
rc = _proxyReleaseConch(tls, pFile)
if rc != 0 {
return rc
}
}
rc = (*(*func(*libc.TLS, uintptr) int32)(unsafe.Pointer(&struct{ uintptr }{(*Tsqlite3_io_methods)(unsafe.Pointer((*TunixFile)(unsafe.Pointer(conchFile)).FpMethod)).FxClose})))(tls, conchFile)
if rc != 0 {
return rc
}
Xsqlite3_free(tls, conchFile)
}
_sqlite3DbFree(tls, uintptr(0), (*TproxyLockingContext)(unsafe.Pointer(pCtx)).FlockProxyPath)
Xsqlite3_free(tls, (*TproxyLockingContext)(unsafe.Pointer(pCtx)).FconchFilePath)
_sqlite3DbFree(tls, uintptr(0), (*TproxyLockingContext)(unsafe.Pointer(pCtx)).FdbPath)
/* restore the original locking context and pMethod then close it */
(*TunixFile)(unsafe.Pointer(pFile)).FlockingContext = (*TproxyLockingContext)(unsafe.Pointer(pCtx)).FoldLockingContext
(*TunixFile)(unsafe.Pointer(pFile)).FpMethod = (*TproxyLockingContext)(unsafe.Pointer(pCtx)).FpOldMethod
Xsqlite3_free(tls, pCtx)
return (*(*func(*libc.TLS, uintptr) int32)(unsafe.Pointer(&struct{ uintptr }{(*Tsqlite3_io_methods)(unsafe.Pointer((*TunixFile)(unsafe.Pointer(pFile)).FpMethod)).FxClose})))(tls, id)
}
return SQLITE_OK
}
/*
** The proxy locking style is intended for use with AFP filesystems.
** And since AFP is only supported on MacOSX, the proxy locking is also
** restricted to MacOSX.
**
**
******************* End of the proxy lock implementation **********************
******************************************************************************/
// C documentation
//
// /* Take the requested lock on the conch file and break a stale lock if the
// ** host id matches.
// */
func _proxyConchLock(tls *libc.TLS, pFile uintptr, myHostID uintptr, lockType int32) (r int32) {
bp := tls.Alloc(1216)
defer tls.Free(1216)
var conchFile, pCtx uintptr
var len1, nTries, rc int32
var _ /* buf at bp+16 */ Tstat
var _ /* conchModTime at bp+0 */ Ttimespec
var _ /* tBuf at bp+160 */ [1041]int8
_, _, _, _, _ = conchFile, len1, nTries, pCtx, rc
pCtx = (*TunixFile)(unsafe.Pointer(pFile)).FlockingContext
conchFile = (*TproxyLockingContext)(unsafe.Pointer(pCtx)).FconchFile
rc = SQLITE_OK
nTries = 0
libc.X__builtin___memset_chk(tls, bp, 0, uint64(16), ^t__predefined_size_t(0))
for cond := true; cond; cond = rc == int32(SQLITE_BUSY) && nTries < int32(3) {
rc = (*(*func(*libc.TLS, uintptr, int32) int32)(unsafe.Pointer(&struct{ uintptr }{(*Tsqlite3_io_methods)(unsafe.Pointer((*TunixFile)(unsafe.Pointer(conchFile)).FpMethod)).FxLock})))(tls, conchFile, lockType)
nTries = nTries + 1
if rc == int32(SQLITE_BUSY) {
if (*(*func(*libc.TLS, int32, uintptr) int32)(unsafe.Pointer(&struct{ uintptr }{_aSyscall[int32(5)].FpCurrent})))(tls, (*TunixFile)(unsafe.Pointer(conchFile)).Fh, bp+16) != 0 {
_storeLastErrno(tls, pFile, **(**int32)(__ccgo_up(libc.X__error(tls))))
return libc.Int32FromInt32(SQLITE_IOERR) | libc.Int32FromInt32(15)< libc.Int32FromInt32(PROXY_HEADERLEN)+libc.Int32FromInt32(PROXY_HOSTIDLEN) && int32((**(**[1041]int8)(__ccgo_up(bp + 160)))[0]) == int32(libc.Int8FromInt32(PROXY_CONCHVERSION)) {
/* don't break the lock if the host id doesn't match */
if 0 != libc.Xmemcmp(tls, bp+160+1, myHostID, uint64(PROXY_HOSTIDLEN)) {
return int32(SQLITE_BUSY)
}
} else {
/* don't break the lock on short read or a version mismatch */
return int32(SQLITE_BUSY)
}
_unixSleep(tls, uintptr(0), int32(10000000)) /* wait 10 sec and try the lock again */
continue
}
if 0 == _proxyBreakConchLock(tls, pFile, myHostID) {
rc = SQLITE_OK
if lockType == int32(EXCLUSIVE_LOCK) {
rc = (*(*func(*libc.TLS, uintptr, int32) int32)(unsafe.Pointer(&struct{ uintptr }{(*Tsqlite3_io_methods)(unsafe.Pointer((*TunixFile)(unsafe.Pointer(conchFile)).FpMethod)).FxLock})))(tls, conchFile, int32(SHARED_LOCK))
}
if !(rc != 0) {
rc = (*(*func(*libc.TLS, uintptr, int32) int32)(unsafe.Pointer(&struct{ uintptr }{(*Tsqlite3_io_methods)(unsafe.Pointer((*TunixFile)(unsafe.Pointer(conchFile)).FpMethod)).FxLock})))(tls, conchFile, lockType)
}
}
}
}
return rc
}
// C documentation
//
// /*
// ** Given the name of a database file, compute the name of its conch file.
// ** Store the conch filename in memory obtained from sqlite3_malloc64().
// ** Make *pConchPath point to the new name. Return SQLITE_OK on success
// ** or SQLITE_NOMEM if unable to obtain memory.
// **
// ** The caller is responsible for ensuring that the allocated memory
// ** space is eventually freed.
// **
// ** *pConchPath is set to NULL if a memory allocation error occurs.
// */
func _proxyCreateConchPathname(tls *libc.TLS, dbPath uintptr, pConchPath uintptr) (r int32) {
var conchPath, v1 uintptr
var i, len1 int32
_, _, _, _ = conchPath, i, len1, v1 /* Loop counter */
len1 = libc.Int32FromUint64(libc.Xstrlen(tls, dbPath)) /* buffer in which to construct conch name */
/* Allocate space for the conch filename and initialize the name to
** the name of the original database file. */
v1 = Xsqlite3_malloc64(tls, libc.Uint64FromInt32(len1+int32(8)))
conchPath = v1
**(**uintptr)(__ccgo_up(pConchPath)) = v1
if conchPath == uintptr(0) {
return int32(SQLITE_NOMEM)
}
libc.X__builtin___memcpy_chk(tls, conchPath, dbPath, libc.Uint64FromInt32(len1+int32(1)), ^t__predefined_size_t(0))
/* now insert a "." before the last / character */
i = len1 - int32(1)
for {
if !(i >= 0) {
break
}
if int32(**(**int8)(__ccgo_up(conchPath + uintptr(i)))) == int32('/') {
i = i + 1
break
}
goto _2
_2:
;
i = i - 1
}
**(**int8)(__ccgo_up(conchPath + uintptr(i))) = int8('.')
for i < len1 {
**(**int8)(__ccgo_up(conchPath + uintptr(i+int32(1)))) = **(**int8)(__ccgo_up(dbPath + uintptr(i)))
i = i + 1
}
/* append the "-conch" suffix to the file */
libc.X__builtin___memcpy_chk(tls, conchPath+uintptr(i+int32(1)), __ccgo_ts+4350, uint64(7), ^t__predefined_size_t(0))
return SQLITE_OK
}
// C documentation
//
// /*
// ** Creates the lock file and any missing directories in lockPath
// */
func _proxyCreateLockPath(tls *libc.TLS, lockPath uintptr) (r int32) {
bp := tls.Alloc(1024)
defer tls.Free(1024)
var err, i, len1, start int32
var _ /* buf at bp+0 */ [1024]int8
_, _, _, _ = err, i, len1, start
start = 0
/* try to create all the intermediate directories */
len1 = libc.Int32FromUint64(libc.Xstrlen(tls, lockPath))
(**(**[1024]int8)(__ccgo_up(bp)))[0] = **(**int8)(__ccgo_up(lockPath))
i = int32(1)
for {
if !(i < len1) {
break
}
if int32(**(**int8)(__ccgo_up(lockPath + uintptr(i)))) == int32('/') && i-start > 0 {
/* only mkdir if leaf dir != "." or "/" or ".." */
if i-start > int32(2) || i-start == int32(1) && int32((**(**[1024]int8)(__ccgo_up(bp)))[start]) != int32('.') && int32((**(**[1024]int8)(__ccgo_up(bp)))[start]) != int32('/') || i-start == int32(2) && int32((**(**[1024]int8)(__ccgo_up(bp)))[start]) != int32('.') && int32((**(**[1024]int8)(__ccgo_up(bp)))[start+int32(1)]) != int32('.') {
(**(**[1024]int8)(__ccgo_up(bp)))[i] = int8('\000')
if (*(*func(*libc.TLS, uintptr, Tmode_t) int32)(unsafe.Pointer(&struct{ uintptr }{_aSyscall[int32(18)].FpCurrent})))(tls, bp, uint16(SQLITE_DEFAULT_PROXYDIR_PERMISSIONS)) != 0 {
err = **(**int32)(__ccgo_up(libc.X__error(tls)))
if err != int32(EEXIST) {
return err
}
}
}
start = i + int32(1)
}
(**(**[1024]int8)(__ccgo_up(bp)))[i] = **(**int8)(__ccgo_up(lockPath + uintptr(i)))
goto _1
_1:
;
i = i + 1
}
return 0
}
// C documentation
//
// /*
// ** Create a new VFS file descriptor (stored in memory obtained from
// ** sqlite3_malloc) and open the file named "path" in the file descriptor.
// **
// ** The caller is responsible not only for closing the file descriptor
// ** but also for freeing the memory associated with the file descriptor.
// */
func _proxyCreateUnixFile(tls *libc.TLS, path uintptr, ppFile uintptr, islockfile int32) (r int32) {
bp := tls.Alloc(176)
defer tls.Free(176)
var fd, openFlags, rc, terrno int32
var pNew, pUnused uintptr
var _ /* dummyVfs at bp+0 */ Tsqlite3_vfs
_, _, _, _, _, _ = fd, openFlags, pNew, pUnused, rc, terrno
fd = -int32(1)
rc = SQLITE_OK
openFlags = libc.Int32FromInt32(O_RDWR) | libc.Int32FromInt32(O_CREAT) | libc.Int32FromInt32(O_NOFOLLOW)
terrno = 0
pUnused = libc.UintptrFromInt32(0)
/* 1. first try to open/create the file
** 2. if that fails, and this is a lock file (not-conch), try creating
** the parent directories and then try again.
** 3. if that fails, try to open the file read-only
** otherwise return BUSY (if lock file) or CANTOPEN for the conch file
*/
pUnused = _findReusableFd(tls, path, openFlags)
if pUnused != 0 {
fd = (*TUnixUnusedFd)(unsafe.Pointer(pUnused)).Ffd
} else {
pUnused = Xsqlite3_malloc64(tls, uint64(16))
if !(pUnused != 0) {
return int32(SQLITE_NOMEM)
}
}
if fd < 0 {
fd = _robust_open(tls, path, openFlags, uint16(0))
terrno = **(**int32)(__ccgo_up(libc.X__error(tls)))
if fd < 0 && **(**int32)(__ccgo_up(libc.X__error(tls))) == int32(ENOENT) && islockfile != 0 {
if _proxyCreateLockPath(tls, path) == SQLITE_OK {
fd = _robust_open(tls, path, openFlags, uint16(0))
}
}
}
if fd < 0 {
openFlags = libc.Int32FromInt32(O_RDONLY) | libc.Int32FromInt32(O_NOFOLLOW)
fd = _robust_open(tls, path, openFlags, uint16(0))
terrno = **(**int32)(__ccgo_up(libc.X__error(tls)))
}
if fd < 0 {
if islockfile != 0 {
return int32(SQLITE_BUSY)
}
switch terrno {
case int32(EACCES):
return int32(SQLITE_PERM)
case int32(EIO):
return libc.Int32FromInt32(SQLITE_IOERR) | libc.Int32FromInt32(15)< SHARED
// ** SHARED -> RESERVED
// ** SHARED -> (PENDING) -> EXCLUSIVE
// ** RESERVED -> (PENDING) -> EXCLUSIVE
// ** PENDING -> EXCLUSIVE
// **
// ** This routine will only increase a lock. Use the sqlite3OsUnlock()
// ** routine to lower a locking level.
// */
func _proxyLock(tls *libc.TLS, id uintptr, eFileLock int32) (r int32) {
var pCtx, pFile, proxy uintptr
var rc int32
_, _, _, _ = pCtx, pFile, proxy, rc
pFile = id
rc = _proxyTakeConch(tls, pFile)
if rc == SQLITE_OK {
pCtx = (*TunixFile)(unsafe.Pointer(pFile)).FlockingContext
if (*TproxyLockingContext)(unsafe.Pointer(pCtx)).FconchHeld > 0 {
proxy = (*TproxyLockingContext)(unsafe.Pointer(pCtx)).FlockProxy
rc = (*(*func(*libc.TLS, uintptr, int32) int32)(unsafe.Pointer(&struct{ uintptr }{(*Tsqlite3_io_methods)(unsafe.Pointer((*TunixFile)(unsafe.Pointer(proxy)).FpMethod)).FxLock})))(tls, proxy, eFileLock)
(*TunixFile)(unsafe.Pointer(pFile)).FeFileLock = (*TunixFile)(unsafe.Pointer(proxy)).FeFileLock
} else {
/* conchHeld < 0 is lockless */
}
}
return rc
}
// C documentation
//
// /*
// ** If pFile holds a lock on a conch file, then release that lock.
// */
func _proxyReleaseConch(tls *libc.TLS, pFile uintptr) (r int32) {
var conchFile, pCtx uintptr
var rc int32
_, _, _ = conchFile, pCtx, rc
rc = SQLITE_OK /* Name of the conch file */
pCtx = (*TunixFile)(unsafe.Pointer(pFile)).FlockingContext
conchFile = (*TproxyLockingContext)(unsafe.Pointer(pCtx)).FconchFile
if (*TproxyLockingContext)(unsafe.Pointer(pCtx)).FconchHeld > 0 {
rc = (*(*func(*libc.TLS, uintptr, int32) int32)(unsafe.Pointer(&struct{ uintptr }{(*Tsqlite3_io_methods)(unsafe.Pointer((*TunixFile)(unsafe.Pointer(conchFile)).FpMethod)).FxUnlock})))(tls, conchFile, NO_LOCK)
}
(*TproxyLockingContext)(unsafe.Pointer(pCtx)).FconchHeld = 0
return rc
}
// C documentation
//
// /* Takes the conch by taking a shared lock and read the contents conch, if
// ** lockPath is non-NULL, the host ID and lock file path must match. A NULL
// ** lockPath means that the lockPath in the conch file will be used if the
// ** host IDs match, or a new lock path will be generated automatically
// ** and written to the conch file.
// */
func _proxyTakeConch(tls *libc.TLS, pFile uintptr) (r int32) {
bp := tls.Alloc(3280)
defer tls.Free(3280)
var afpCtx, conchFile, pCtx, path, tempLockPath, v4 uintptr
var cmode Tmode_t
var createConch, err, fd, forceNewLockPath, hostIdMatch, rc, readLen, tryOldLockPath, writeSize int32
var pathLen Tsize_t
var _ /* buf at bp+3128 */ Tstat
var _ /* lockPath at bp+1061 */ [1024]int8
var _ /* myHostID at bp+0 */ Tuuid_t
var _ /* pError at bp+16 */ int32
var _ /* readBuf at bp+20 */ [1041]int8
var _ /* writeBuffer at bp+2085 */ [1041]int8
_, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _ = afpCtx, cmode, conchFile, createConch, err, fd, forceNewLockPath, hostIdMatch, pCtx, path, pathLen, rc, readLen, tempLockPath, tryOldLockPath, writeSize, v4
pCtx = (*TunixFile)(unsafe.Pointer(pFile)).FlockingContext
if (*TproxyLockingContext)(unsafe.Pointer(pCtx)).FconchHeld != 0 {
return SQLITE_OK
} else {
conchFile = (*TproxyLockingContext)(unsafe.Pointer(pCtx)).FconchFile
**(**int32)(__ccgo_up(bp + 16)) = 0
tempLockPath = libc.UintptrFromInt32(0)
rc = SQLITE_OK
createConch = 0
hostIdMatch = 0
readLen = 0
tryOldLockPath = 0
forceNewLockPath = 0
rc = _proxyGetHostID(tls, bp, bp+16)
if rc&int32(0xff) == int32(SQLITE_IOERR) {
_storeLastErrno(tls, pFile, **(**int32)(__ccgo_up(bp + 16)))
goto end_takeconch
}
rc = _proxyConchLock(tls, pFile, bp, int32(SHARED_LOCK))
if rc != SQLITE_OK {
goto end_takeconch
}
/* read the existing conch file */
readLen = _seekAndRead(tls, conchFile, 0, bp+20, libc.Int32FromInt32(PROXY_HEADERLEN)+libc.Int32FromInt32(PROXY_HOSTIDLEN)+libc.Int32FromInt32(PATH_MAX))
if readLen < 0 {
/* I/O error: lastErrno set by seekAndRead */
_storeLastErrno(tls, pFile, (*TunixFile)(unsafe.Pointer(conchFile)).FlastErrno)
rc = libc.Int32FromInt32(SQLITE_IOERR) | libc.Int32FromInt32(1)<= uint64(PATH_MAX) {
pathLen = libc.Uint64FromInt32(libc.Int32FromInt32(PATH_MAX) - libc.Int32FromInt32(1))
}
libc.X__builtin___memcpy_chk(tls, bp+1061, bp+20+uintptr(libc.Int32FromInt32(PROXY_HEADERLEN)+libc.Int32FromInt32(PROXY_HOSTIDLEN)), pathLen, ^t__predefined_size_t(0))
(**(**[1024]int8)(__ccgo_up(bp + 1061)))[pathLen] = 0
tempLockPath = bp + 1061
tryOldLockPath = int32(1)
/* create a copy of the lock path if the conch is taken */
goto end_takeconch
}
} else {
if hostIdMatch != 0 && !(libc.Xstrncmp(tls, (*TproxyLockingContext)(unsafe.Pointer(pCtx)).FlockProxyPath, bp+20+uintptr(libc.Int32FromInt32(PROXY_HEADERLEN)+libc.Int32FromInt32(PROXY_HOSTIDLEN)), libc.Uint64FromInt32(readLen-(libc.Int32FromInt32(PROXY_HEADERLEN)+libc.Int32FromInt32(PROXY_HOSTIDLEN)))) != 0) {
/* conch host and lock path match */
goto end_takeconch
}
}
}
/* if the conch isn't writable and doesn't match, we can't take it */
if (*TunixFile)(unsafe.Pointer(conchFile)).FopenFlags&int32(O_RDWR) == 0 {
rc = int32(SQLITE_BUSY)
goto end_takeconch
}
/* either the conch didn't match or we need to create a new one */
if !((*TproxyLockingContext)(unsafe.Pointer(pCtx)).FlockProxyPath != 0) {
_proxyGetLockPath(tls, (*TproxyLockingContext)(unsafe.Pointer(pCtx)).FdbPath, bp+1061, uint64(PATH_MAX))
tempLockPath = bp + 1061
/* create a copy of the lock path _only_ if the conch is taken */
}
/* update conch with host and path (this will fail if other process
** has a shared lock already), if the host id matches, use the big
** stick.
*/
libc.Xfutimes(tls, (*TunixFile)(unsafe.Pointer(conchFile)).Fh, libc.UintptrFromInt32(0))
if hostIdMatch != 0 && !(createConch != 0) {
if (*TunixFile)(unsafe.Pointer(conchFile)).FpInode != 0 && (*TunixInodeInfo)(unsafe.Pointer((*TunixFile)(unsafe.Pointer(conchFile)).FpInode)).FnShared > int32(1) {
/* We are trying for an exclusive lock but another thread in this
** same process is still holding a shared lock. */
rc = int32(SQLITE_BUSY)
} else {
rc = _proxyConchLock(tls, pFile, bp, int32(EXCLUSIVE_LOCK))
}
} else {
rc = _proxyConchLock(tls, pFile, bp, int32(EXCLUSIVE_LOCK))
}
if rc == SQLITE_OK {
writeSize = 0
(**(**[1041]int8)(__ccgo_up(bp + 2085)))[0] = libc.Int8FromInt32(PROXY_CONCHVERSION)
libc.X__builtin___memcpy_chk(tls, bp+2085+1, bp, uint64(PROXY_HOSTIDLEN), ^t__predefined_size_t(0))
if (*TproxyLockingContext)(unsafe.Pointer(pCtx)).FlockProxyPath != libc.UintptrFromInt32(0) {
libc.Xstrlcpy(tls, bp+2085+uintptr(libc.Int32FromInt32(PROXY_HEADERLEN)+libc.Int32FromInt32(PROXY_HOSTIDLEN)), (*TproxyLockingContext)(unsafe.Pointer(pCtx)).FlockProxyPath, uint64(PATH_MAX))
} else {
libc.Xstrlcpy(tls, bp+2085+uintptr(libc.Int32FromInt32(PROXY_HEADERLEN)+libc.Int32FromInt32(PROXY_HOSTIDLEN)), tempLockPath, uint64(PATH_MAX))
}
writeSize = libc.Int32FromUint64(libc.Uint64FromInt32(libc.Int32FromInt32(PROXY_HEADERLEN)+libc.Int32FromInt32(PROXY_HOSTIDLEN)) + libc.Xstrlen(tls, bp+2085+uintptr(libc.Int32FromInt32(PROXY_HEADERLEN)+libc.Int32FromInt32(PROXY_HOSTIDLEN))))
_robust_ftruncate(tls, (*TunixFile)(unsafe.Pointer(conchFile)).Fh, int64(writeSize))
rc = _unixWrite(tls, conchFile, bp+2085, writeSize, 0)
_full_fsync(tls, (*TunixFile)(unsafe.Pointer(conchFile)).Fh, 0, 0)
/* If we created a new conch file (not just updated the contents of a
** valid conch file), try to match the permissions of the database
*/
if rc == SQLITE_OK && createConch != 0 {
err = (*(*func(*libc.TLS, int32, uintptr) int32)(unsafe.Pointer(&struct{ uintptr }{_aSyscall[int32(5)].FpCurrent})))(tls, (*TunixFile)(unsafe.Pointer(pFile)).Fh, bp+3128)
if err == 0 {
cmode = libc.Uint16FromInt32(libc.Int32FromUint16((**(**Tstat)(__ccgo_up(bp + 3128))).Fst_mode) & (libc.Int32FromInt32(S_IRUSR) | libc.Int32FromInt32(S_IWUSR) | libc.Int32FromInt32(S_IRGRP) | libc.Int32FromInt32(S_IWGRP) | libc.Int32FromInt32(S_IROTH) | libc.Int32FromInt32(S_IWOTH)))
/* try to match the database file R/W permissions, ignore failure */
(*(*func(*libc.TLS, int32, Tmode_t) int32)(unsafe.Pointer(&struct{ uintptr }{_aSyscall[int32(14)].FpCurrent})))(tls, (*TunixFile)(unsafe.Pointer(conchFile)).Fh, cmode)
}
}
}
(*(*func(*libc.TLS, uintptr, int32) int32)(unsafe.Pointer(&struct{ uintptr }{(*Tsqlite3_io_methods)(unsafe.Pointer((*TunixFile)(unsafe.Pointer(conchFile)).FpMethod)).FxUnlock})))(tls, conchFile, int32(SHARED_LOCK))
goto end_takeconch
end_takeconch:
;
if rc == SQLITE_OK && (*TunixFile)(unsafe.Pointer(pFile)).FopenFlags != 0 {
if (*TunixFile)(unsafe.Pointer(pFile)).Fh >= 0 {
_robust_close(tls, pFile, (*TunixFile)(unsafe.Pointer(pFile)).Fh, int32(48151))
}
(*TunixFile)(unsafe.Pointer(pFile)).Fh = -int32(1)
fd = _robust_open(tls, (*TproxyLockingContext)(unsafe.Pointer(pCtx)).FdbPath, (*TunixFile)(unsafe.Pointer(pFile)).FopenFlags, uint16(0))
if fd >= 0 {
(*TunixFile)(unsafe.Pointer(pFile)).Fh = fd
} else {
rc = _sqlite3CantopenError(tls, int32(48159)) /* SQLITE_BUSY? proxyTakeConch called
during locking */
}
}
if rc == SQLITE_OK && !((*TproxyLockingContext)(unsafe.Pointer(pCtx)).FlockProxy != 0) {
if tempLockPath != 0 {
v4 = tempLockPath
} else {
v4 = (*TproxyLockingContext)(unsafe.Pointer(pCtx)).FlockProxyPath
}
path = v4
rc = _proxyCreateUnixFile(tls, path, pCtx+16, int32(1))
if rc != SQLITE_OK && rc != int32(SQLITE_NOMEM) && tryOldLockPath != 0 {
/* we couldn't create the proxy lock file with the old lock file path
** so try again via auto-naming
*/
forceNewLockPath = int32(1)
tryOldLockPath = 0
goto _2 /* go back to the do {} while start point, try again */
}
}
if rc == SQLITE_OK {
/* Need to make a copy of path if we extracted the value
** from the conch file or the path was allocated on the stack
*/
if tempLockPath != 0 {
(*TproxyLockingContext)(unsafe.Pointer(pCtx)).FlockProxyPath = _sqlite3DbStrDup(tls, uintptr(0), tempLockPath)
if !((*TproxyLockingContext)(unsafe.Pointer(pCtx)).FlockProxyPath != 0) {
rc = int32(SQLITE_NOMEM)
}
}
}
if rc == SQLITE_OK {
(*TproxyLockingContext)(unsafe.Pointer(pCtx)).FconchHeld = int32(1)
if (*TunixFile)(unsafe.Pointer((*TproxyLockingContext)(unsafe.Pointer(pCtx)).FlockProxy)).FpMethod == uintptr(unsafe.Pointer(&_afpIoMethods)) {
afpCtx = (*TunixFile)(unsafe.Pointer((*TproxyLockingContext)(unsafe.Pointer(pCtx)).FlockProxy)).FlockingContext
(*TafpLockingContext)(unsafe.Pointer(afpCtx)).FdbPath = (*TproxyLockingContext)(unsafe.Pointer(pCtx)).FlockProxyPath
}
} else {
(*(*func(*libc.TLS, uintptr, int32) int32)(unsafe.Pointer(&struct{ uintptr }{(*Tsqlite3_io_methods)(unsafe.Pointer((*TunixFile)(unsafe.Pointer(conchFile)).FpMethod)).FxUnlock})))(tls, conchFile, NO_LOCK)
}
return rc
goto _2
_2:
;
if int32(1) != 0 {
goto _3
}
goto _1
_1:
/* in case we need to retry the :auto: lock file -
** we should never get here except via the 'continue' call. */
}
return r
}
// C documentation
//
// /*
// ** Takes an already filled in unix file and alters it so all file locking
// ** will be performed on the local proxy lock file. The following fields
// ** are preserved in the locking context so that they can be restored and
// ** the unix structure properly cleaned up at close time:
// ** ->lockingContext
// ** ->pMethod
// */
func _proxyTransformUnixFile(tls *libc.TLS, pFile uintptr, path uintptr) (r int32) {
bp := tls.Alloc(3344)
defer tls.Free(3344)
var err, goLockless, rc int32
var lockPath, pCtx uintptr
var _ /* conchInfo at bp+3200 */ Tstat
var _ /* dbPath at bp+0 */ [1025]int8
var _ /* fsInfo at bp+1032 */ Tstatfs
_, _, _, _, _ = err, goLockless, lockPath, pCtx, rc /* Name of the database file */
lockPath = libc.UintptrFromInt32(0)
rc = SQLITE_OK
if libc.Int32FromUint8((*TunixFile)(unsafe.Pointer(pFile)).FeFileLock) != NO_LOCK {
return int32(SQLITE_BUSY)
}
_proxyGetDbPathForUnixFile(tls, pFile, bp)
if !(path != 0) || int32(**(**int8)(__ccgo_up(path))) == int32('\000') || !(libc.Xstrcmp(tls, path, __ccgo_ts+4139) != 0) {
lockPath = libc.UintptrFromInt32(0)
} else {
lockPath = path
}
pCtx = Xsqlite3_malloc64(tls, uint64(64))
if pCtx == uintptr(0) {
return int32(SQLITE_NOMEM)
}
libc.X__builtin___memset_chk(tls, pCtx, 0, uint64(64), ^t__predefined_size_t(0))
rc = _proxyCreateConchPathname(tls, bp, pCtx+8)
if rc == SQLITE_OK {
rc = _proxyCreateUnixFile(tls, (*TproxyLockingContext)(unsafe.Pointer(pCtx)).FconchFilePath, pCtx, 0)
if rc == int32(SQLITE_CANTOPEN) && (*TunixFile)(unsafe.Pointer(pFile)).FopenFlags&int32(O_RDWR) == 0 {
goLockless = 0
if (*(*func(*libc.TLS, uintptr, uintptr) int32)(unsafe.Pointer(&struct{ uintptr }{_aSyscall[int32(4)].FpCurrent})))(tls, (*TproxyLockingContext)(unsafe.Pointer(pCtx)).FconchFilePath, bp+3200) == -int32(1) {
err = **(**int32)(__ccgo_up(libc.X__error(tls)))
if err == int32(ENOENT) && libc.Xstatfs(tls, bp, bp+1032) != -int32(1) {
goLockless = libc.BoolInt32((**(**Tstatfs)(__ccgo_up(bp + 1032))).Ff_flags&uint32(MNT_RDONLY) == uint32(MNT_RDONLY))
}
}
if goLockless != 0 {
(*TproxyLockingContext)(unsafe.Pointer(pCtx)).FconchHeld = -int32(1) /* read only FS/ lockless */
rc = SQLITE_OK
}
}
}
if rc == SQLITE_OK && lockPath != 0 {
(*TproxyLockingContext)(unsafe.Pointer(pCtx)).FlockProxyPath = _sqlite3DbStrDup(tls, uintptr(0), lockPath)
}
if rc == SQLITE_OK {
(*TproxyLockingContext)(unsafe.Pointer(pCtx)).FdbPath = _sqlite3DbStrDup(tls, uintptr(0), bp)
if (*TproxyLockingContext)(unsafe.Pointer(pCtx)).FdbPath == libc.UintptrFromInt32(0) {
rc = int32(SQLITE_NOMEM)
}
}
if rc == SQLITE_OK {
/* all memory is allocated, proxys are created and assigned,
** switch the locking context and pMethod then return.
*/
(*TproxyLockingContext)(unsafe.Pointer(pCtx)).FoldLockingContext = (*TunixFile)(unsafe.Pointer(pFile)).FlockingContext
(*TunixFile)(unsafe.Pointer(pFile)).FlockingContext = pCtx
(*TproxyLockingContext)(unsafe.Pointer(pCtx)).FpOldMethod = (*TunixFile)(unsafe.Pointer(pFile)).FpMethod
(*TunixFile)(unsafe.Pointer(pFile)).FpMethod = uintptr(unsafe.Pointer(&_proxyIoMethods))
} else {
if (*TproxyLockingContext)(unsafe.Pointer(pCtx)).FconchFile != 0 {
(*(*func(*libc.TLS, uintptr) int32)(unsafe.Pointer(&struct{ uintptr }{(*Tsqlite3_io_methods)(unsafe.Pointer((*TunixFile)(unsafe.Pointer((*TproxyLockingContext)(unsafe.Pointer(pCtx)).FconchFile)).FpMethod)).FxClose})))(tls, (*TproxyLockingContext)(unsafe.Pointer(pCtx)).FconchFile)
Xsqlite3_free(tls, (*TproxyLockingContext)(unsafe.Pointer(pCtx)).FconchFile)
}
_sqlite3DbFree(tls, uintptr(0), (*TproxyLockingContext)(unsafe.Pointer(pCtx)).FlockProxyPath)
Xsqlite3_free(tls, (*TproxyLockingContext)(unsafe.Pointer(pCtx)).FconchFilePath)
Xsqlite3_free(tls, pCtx)
}
return rc
}
// C documentation
//
// /*
// ** Lower the locking level on file descriptor pFile to eFileLock. eFileLock
// ** must be either NO_LOCK or SHARED_LOCK.
// **
// ** If the locking level of the file descriptor is already at or below
// ** the requested locking level, this routine is a no-op.
// */
func _proxyUnlock(tls *libc.TLS, id uintptr, eFileLock int32) (r int32) {
var pCtx, pFile, proxy uintptr
var rc int32
_, _, _, _ = pCtx, pFile, proxy, rc
pFile = id
rc = _proxyTakeConch(tls, pFile)
if rc == SQLITE_OK {
pCtx = (*TunixFile)(unsafe.Pointer(pFile)).FlockingContext
if (*TproxyLockingContext)(unsafe.Pointer(pCtx)).FconchHeld > 0 {
proxy = (*TproxyLockingContext)(unsafe.Pointer(pCtx)).FlockProxy
rc = (*(*func(*libc.TLS, uintptr, int32) int32)(unsafe.Pointer(&struct{ uintptr }{(*Tsqlite3_io_methods)(unsafe.Pointer((*TunixFile)(unsafe.Pointer(proxy)).FpMethod)).FxUnlock})))(tls, proxy, eFileLock)
(*TunixFile)(unsafe.Pointer(pFile)).FeFileLock = (*TunixFile)(unsafe.Pointer(proxy)).FeFileLock
} else {
/* conchHeld < 0 is lockless */
}
}
return rc
}
// C documentation
//
// /*
// ** Generate code that will push the record in registers regData
// ** through regData+nData-1 onto the sorter.
// */
func _pushOntoSorter(tls *libc.TLS, pParse uintptr, pSort uintptr, pSelect uintptr, regData int32, regOrigData int32, nData int32, nPrefixReg int32) {
var addrFirst, addrJmp, bSeq, iCsr, iLimit, iSkip, nBase, nExpr, nKey, nOBSat, op, regBase, regPrevKey, regRecord, v1 int32
var pKI, pOp, v, v4 uintptr
_, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _ = addrFirst, addrJmp, bSeq, iCsr, iLimit, iSkip, nBase, nExpr, nKey, nOBSat, op, pKI, pOp, regBase, regPrevKey, regRecord, v, v1, v4
v = (*TParse)(unsafe.Pointer(pParse)).FpVdbe /* Stmt under construction */
bSeq = libc.BoolInt32(libc.Int32FromUint8((*TSortCtx)(unsafe.Pointer(pSort)).FsortFlags)&int32(SORTFLAG_UseSorter) == 0)
nExpr = (*TExprList)(unsafe.Pointer((*TSortCtx)(unsafe.Pointer(pSort)).FpOrderBy)).FnExpr /* No. of ORDER BY terms */
nBase = nExpr + bSeq + nData /* Regs for sorter record */
regRecord = 0 /* Assembled sorter record */
nOBSat = (*TSortCtx)(unsafe.Pointer(pSort)).FnOBSat /* LIMIT counter */
iSkip = 0 /* End of the sorter insert loop */
/* Three cases:
** (1) The data to be sorted has already been packed into a Record
** by a prior OP_MakeRecord. In this case nData==1 and regData
** will be completely unrelated to regOrigData.
** (2) All output columns are included in the sort record. In that
** case regData==regOrigData.
** (3) Some output columns are omitted from the sort record due to
** the SQLITE_ENABLE_SORTER_REFERENCES optimization, or due to the
** SQLITE_ECEL_OMITREF optimization, or due to the
** SortCtx.pDeferredRowLoad optimization. In any of these cases
** regOrigData is 0 to prevent this routine from trying to copy
** values that might not yet exist.
*/
if nPrefixReg != 0 {
regBase = regData - nPrefixReg
} else {
regBase = (*TParse)(unsafe.Pointer(pParse)).FnMem + int32(1)
**(**int32)(__ccgo_up(pParse + 60)) += nBase
}
if (*TSelect)(unsafe.Pointer(pSelect)).FiOffset != 0 {
v1 = (*TSelect)(unsafe.Pointer(pSelect)).FiOffset + int32(1)
} else {
v1 = (*TSelect)(unsafe.Pointer(pSelect)).FiLimit
}
iLimit = v1
(*TSortCtx)(unsafe.Pointer(pSort)).FlabelDone = _sqlite3VdbeMakeLabel(tls, pParse)
if regOrigData != 0 {
v1 = int32(SQLITE_ECEL_REF)
} else {
v1 = 0
}
_sqlite3ExprCodeExprList(tls, pParse, (*TSortCtx)(unsafe.Pointer(pSort)).FpOrderBy, regBase, regOrigData, libc.Uint8FromInt32(int32(SQLITE_ECEL_DUP)|v1))
if bSeq != 0 {
_sqlite3VdbeAddOp2(tls, v, int32(OP_Sequence), (*TSortCtx)(unsafe.Pointer(pSort)).FiECursor, regBase+nExpr)
}
if nPrefixReg == 0 && nData > 0 {
_sqlite3ExprCodeMove(tls, pParse, regData, regBase+nExpr+bSeq, nData)
}
if nOBSat > 0 { /* Original KeyInfo on the sorter table */
regRecord = _makeSorterRecord(tls, pParse, pSort, pSelect, regBase, nBase)
regPrevKey = (*TParse)(unsafe.Pointer(pParse)).FnMem + int32(1)
**(**int32)(__ccgo_up(pParse + 60)) += (*TSortCtx)(unsafe.Pointer(pSort)).FnOBSat
nKey = nExpr - (*TSortCtx)(unsafe.Pointer(pSort)).FnOBSat + bSeq
if bSeq != 0 {
addrFirst = _sqlite3VdbeAddOp1(tls, v, int32(OP_IfNot), regBase+nExpr)
} else {
addrFirst = _sqlite3VdbeAddOp1(tls, v, int32(OP_SequenceTest), (*TSortCtx)(unsafe.Pointer(pSort)).FiECursor)
}
_sqlite3VdbeAddOp3(tls, v, int32(OP_Compare), regPrevKey, regBase, (*TSortCtx)(unsafe.Pointer(pSort)).FnOBSat)
pOp = _sqlite3VdbeGetOp(tls, v, (*TSortCtx)(unsafe.Pointer(pSort)).FaddrSortIndex)
if (*Tsqlite3)(unsafe.Pointer((*TParse)(unsafe.Pointer(pParse)).Fdb)).FmallocFailed != 0 {
return
}
(*TVdbeOp)(unsafe.Pointer(pOp)).Fp2 = nKey + nData
pKI = *(*uintptr)(unsafe.Pointer(pOp + 16))
libc.X__builtin___memset_chk(tls, (*TKeyInfo)(unsafe.Pointer(pKI)).FaSortFlags, 0, uint64((*TKeyInfo)(unsafe.Pointer(pKI)).FnKeyField), ^t__predefined_size_t(0)) /* Makes OP_Jump testable */
_sqlite3VdbeChangeP4(tls, v, -int32(1), pKI, -int32(9))
*(*uintptr)(unsafe.Pointer(pOp + 16)) = _sqlite3KeyInfoFromExprList(tls, pParse, (*TSortCtx)(unsafe.Pointer(pSort)).FpOrderBy, nOBSat, libc.Int32FromUint16((*TKeyInfo)(unsafe.Pointer(pKI)).FnAllField)-libc.Int32FromUint16((*TKeyInfo)(unsafe.Pointer(pKI)).FnKeyField)-int32(1))
pOp = uintptr(0) /* Ensure pOp not used after sqlite3VdbeAddOp3() */
addrJmp = _sqlite3VdbeCurrentAddr(tls, v)
_sqlite3VdbeAddOp3(tls, v, int32(OP_Jump), addrJmp+int32(1), 0, addrJmp+int32(1))
(*TSortCtx)(unsafe.Pointer(pSort)).FlabelBkOut = _sqlite3VdbeMakeLabel(tls, pParse)
v4 = pParse + 60
*(*int32)(unsafe.Pointer(v4)) = *(*int32)(unsafe.Pointer(v4)) + 1
v1 = *(*int32)(unsafe.Pointer(v4))
(*TSortCtx)(unsafe.Pointer(pSort)).FregReturn = v1
_sqlite3VdbeAddOp2(tls, v, int32(OP_Gosub), (*TSortCtx)(unsafe.Pointer(pSort)).FregReturn, (*TSortCtx)(unsafe.Pointer(pSort)).FlabelBkOut)
_sqlite3VdbeAddOp1(tls, v, int32(OP_ResetSorter), (*TSortCtx)(unsafe.Pointer(pSort)).FiECursor)
if iLimit != 0 {
_sqlite3VdbeAddOp2(tls, v, int32(OP_IfNot), iLimit, (*TSortCtx)(unsafe.Pointer(pSort)).FlabelDone)
}
_sqlite3VdbeJumpHere(tls, v, addrFirst)
_sqlite3ExprCodeMove(tls, pParse, regBase, regPrevKey, (*TSortCtx)(unsafe.Pointer(pSort)).FnOBSat)
_sqlite3VdbeJumpHere(tls, v, addrJmp)
}
if iLimit != 0 {
/* At this point the values for the new sorter entry are stored
** in an array of registers. They need to be composed into a record
** and inserted into the sorter if either (a) there are currently
** less than LIMIT+OFFSET items or (b) the new record is smaller than
** the largest record currently in the sorter. If (b) is true and there
** are already LIMIT+OFFSET items in the sorter, delete the largest
** entry before inserting the new one. This way there are never more
** than LIMIT+OFFSET items in the sorter.
**
** If the new record does not need to be inserted into the sorter,
** jump to the next iteration of the loop. If the pSort->labelOBLopt
** value is not zero, then it is a label of where to jump. Otherwise,
** just bypass the row insert logic. See the header comment on the
** sqlite3WhereOrderByLimitOptLabel() function for additional info.
*/
iCsr = (*TSortCtx)(unsafe.Pointer(pSort)).FiECursor
_sqlite3VdbeAddOp2(tls, v, int32(OP_IfNotZero), iLimit, _sqlite3VdbeCurrentAddr(tls, v)+int32(4))
_sqlite3VdbeAddOp2(tls, v, int32(OP_Last), iCsr, 0)
iSkip = _sqlite3VdbeAddOp4Int(tls, v, int32(OP_IdxLE), iCsr, 0, regBase+nOBSat, nExpr-nOBSat)
_sqlite3VdbeAddOp1(tls, v, int32(OP_Delete), iCsr)
}
if regRecord == 0 {
regRecord = _makeSorterRecord(tls, pParse, pSort, pSelect, regBase, nBase)
}
if libc.Int32FromUint8((*TSortCtx)(unsafe.Pointer(pSort)).FsortFlags)&int32(SORTFLAG_UseSorter) != 0 {
op = int32(OP_SorterInsert)
} else {
op = int32(OP_IdxInsert)
}
_sqlite3VdbeAddOp4Int(tls, v, op, (*TSortCtx)(unsafe.Pointer(pSort)).FiECursor, regRecord, regBase+nOBSat, nBase-nOBSat)
if iSkip != 0 {
if (*TSortCtx)(unsafe.Pointer(pSort)).FlabelOBLopt != 0 {
v1 = (*TSortCtx)(unsafe.Pointer(pSort)).FlabelOBLopt
} else {
v1 = _sqlite3VdbeCurrentAddr(tls, v)
}
_sqlite3VdbeChangeP2(tls, v, iSkip, v1)
}
}
// C documentation
//
// /*
// ** Compare two constraint names.
// **
// ** Summary: *pRes := zQuote != zCmp
// **
// ** Details:
// ** Compare the (possibly quoted) constraint name zQuote[0..nQuote-1]
// ** against zCmp[]. Write zero into *pRes if they are the same and
// ** non-zero if they differ. Normally return SQLITE_OK, except if there
// ** is an OOM, set the OOM error condition on ctx and return SQLITE_NOMEM.
// */
func _quotedCompare(tls *libc.TLS, ctx uintptr, t int32, zQuote uintptr, nQuote int32, zCmp uintptr, pRes uintptr) (r int32) {
var zCopy uintptr
_ = zCopy
zCopy = uintptr(0) /* De-quoted, zero-terminated copy of zQuote[] */
if t == int32(TK_ILLEGAL) {
**(**int32)(__ccgo_up(pRes)) = int32(1)
return SQLITE_OK
}
zCopy = _sqlite3MallocZero(tls, libc.Uint64FromInt32(nQuote+int32(1)))
if zCopy == uintptr(0) {
Xsqlite3_result_error_nomem(tls, ctx)
return int32(SQLITE_NOMEM)
}
libc.X__builtin___memcpy_chk(tls, zCopy, zQuote, libc.Uint64FromInt32(nQuote), ^t__predefined_size_t(0))
_sqlite3Dequote(tls, zCopy)
**(**int32)(__ccgo_up(pRes)) = Xsqlite3_stricmp(tls, zCopy, zCmp)
Xsqlite3_free(tls, zCopy)
return SQLITE_OK
}
// C documentation
//
// /*
// ** The SELECT statement iterating through the keys for the current object
// ** (p->objiter.pSelect) currently points to a valid row. However, there
// ** is something wrong with the rbu_control value in the rbu_control value
// ** stored in the (p->nCol+1)'th column. Set the error code and error message
// ** of the RBU handle to something reflecting this.
// */
func _rbuBadControlError(tls *libc.TLS, p uintptr) {
(*Tsqlite3rbu)(unsafe.Pointer(p)).Frc = int32(SQLITE_ERROR)
(*Tsqlite3rbu)(unsafe.Pointer(p)).FzErrmsg = Xsqlite3_mprintf(tls, __ccgo_ts+32137, 0)
}
// C documentation
//
// /*
// ** The second argument passed to this function is the name of a PRAGMA
// ** setting - "page_size", "auto_vacuum", "user_version" or "application_id".
// ** This function executes the following on sqlite3rbu.dbRbu:
// **
// ** "PRAGMA main.$zPragma"
// **
// ** where $zPragma is the string passed as the second argument, then
// ** on sqlite3rbu.dbMain:
// **
// ** "PRAGMA main.$zPragma = $val"
// **
// ** where $val is the value returned by the first PRAGMA invocation.
// **
// ** In short, it copies the value of the specified PRAGMA setting from
// ** dbRbu to dbMain.
// */
func _rbuCopyPragma(tls *libc.TLS, p uintptr, zPragma uintptr) {
bp := tls.Alloc(32)
defer tls.Free(32)
var _ /* pPragma at bp+0 */ uintptr
if (*Tsqlite3rbu)(unsafe.Pointer(p)).Frc == SQLITE_OK {
**(**uintptr)(__ccgo_up(bp)) = uintptr(0)
(*Tsqlite3rbu)(unsafe.Pointer(p)).Frc = _prepareFreeAndCollectError(tls, (*Tsqlite3rbu)(unsafe.Pointer(p)).FdbRbu, bp, p+64, Xsqlite3_mprintf(tls, __ccgo_ts+34366, libc.VaList(bp+16, zPragma)))
if (*Tsqlite3rbu)(unsafe.Pointer(p)).Frc == SQLITE_OK && int32(SQLITE_ROW) == Xsqlite3_step(tls, **(**uintptr)(__ccgo_up(bp))) {
(*Tsqlite3rbu)(unsafe.Pointer(p)).Frc = _rbuMPrintfExec(tls, p, (*Tsqlite3rbu)(unsafe.Pointer(p)).FdbMain, __ccgo_ts+34381, libc.VaList(bp+16, zPragma, Xsqlite3_column_int(tls, **(**uintptr)(__ccgo_up(bp)), 0)))
}
_rbuFinalize(tls, p, **(**uintptr)(__ccgo_up(bp)))
}
}
// C documentation
//
// /*
// ** If an error has already occurred when this function is called, it
// ** immediately returns zero (without doing any work). Or, if an error
// ** occurs during the execution of this function, it sets the error code
// ** in the sqlite3rbu object indicated by the first argument and returns
// ** zero.
// **
// ** The iterator passed as the second argument is guaranteed to point to
// ** a table (not an index) when this function is called. This function
// ** attempts to create any imposter table required to write to the main
// ** table b-tree of the table before returning. Non-zero is returned if
// ** an imposter table are created, or zero otherwise.
// **
// ** An imposter table is required in all cases except RBU_PK_VTAB. Only
// ** virtual tables are written to directly. The imposter table has the
// ** same schema as the actual target table (less any UNIQUE constraints).
// ** More precisely, the "same schema" means the same columns, types,
// ** collation sequences. For tables that do not have an external PRIMARY
// ** KEY, it also means the same PRIMARY KEY declaration.
// */
func _rbuCreateImposterTable(tls *libc.TLS, p uintptr, pIter uintptr) {
bp := tls.Alloc(80)
defer tls.Free(80)
var iCol, tnum int32
var zCol, zComma, zPk, zPk1, zSql, v2 uintptr
var _ /* zColl at bp+0 */ uintptr
_, _, _, _, _, _, _, _ = iCol, tnum, zCol, zComma, zPk, zPk1, zSql, v2
if (*Tsqlite3rbu)(unsafe.Pointer(p)).Frc == SQLITE_OK && (*TRbuObjIter)(unsafe.Pointer(pIter)).FeType != int32(RBU_PK_VTAB) {
tnum = (*TRbuObjIter)(unsafe.Pointer(pIter)).FiTnum
zComma = __ccgo_ts + 1702
zSql = uintptr(0)
Xsqlite3_test_control(tls, int32(SQLITE_TESTCTRL_IMPOSTER), libc.VaList(bp+16, (*Tsqlite3rbu)(unsafe.Pointer(p)).FdbMain, __ccgo_ts+7164, 0, int32(1)))
iCol = 0
for {
if !((*Tsqlite3rbu)(unsafe.Pointer(p)).Frc == SQLITE_OK && iCol < (*TRbuObjIter)(unsafe.Pointer(pIter)).FnTblCol) {
break
}
zPk = __ccgo_ts + 1702
zCol = **(**uintptr)(__ccgo_up((*TRbuObjIter)(unsafe.Pointer(pIter)).FazTblCol + uintptr(iCol)*8))
**(**uintptr)(__ccgo_up(bp)) = uintptr(0)
(*Tsqlite3rbu)(unsafe.Pointer(p)).Frc = Xsqlite3_table_column_metadata(tls, (*Tsqlite3rbu)(unsafe.Pointer(p)).FdbMain, __ccgo_ts+7164, (*TRbuObjIter)(unsafe.Pointer(pIter)).FzTbl, zCol, uintptr(0), bp, uintptr(0), uintptr(0), uintptr(0))
if (*TRbuObjIter)(unsafe.Pointer(pIter)).FeType == int32(RBU_PK_IPK) && **(**Tu8)(__ccgo_up((*TRbuObjIter)(unsafe.Pointer(pIter)).FabTblPk + uintptr(iCol))) != 0 {
/* If the target table column is an "INTEGER PRIMARY KEY", add
** "PRIMARY KEY" to the imposter table column declaration. */
zPk = __ccgo_ts + 32417
}
if **(**Tu8)(__ccgo_up((*TRbuObjIter)(unsafe.Pointer(pIter)).FabNotNull + uintptr(iCol))) != 0 {
v2 = __ccgo_ts + 32430
} else {
v2 = __ccgo_ts + 1702
}
zSql = _rbuMPrintf(tls, p, __ccgo_ts+32440, libc.VaList(bp+16, zSql, zComma, zCol, **(**uintptr)(__ccgo_up((*TRbuObjIter)(unsafe.Pointer(pIter)).FazTblType + uintptr(iCol)*8)), zPk, **(**uintptr)(__ccgo_up(bp)), v2))
zComma = __ccgo_ts + 16562
goto _1
_1:
;
iCol = iCol + 1
}
if (*TRbuObjIter)(unsafe.Pointer(pIter)).FeType == int32(RBU_PK_WITHOUT_ROWID) {
zPk1 = _rbuWithoutRowidPK(tls, p, pIter)
if zPk1 != 0 {
zSql = _rbuMPrintf(tls, p, __ccgo_ts+32467, libc.VaList(bp+16, zSql, zPk1))
}
}
Xsqlite3_test_control(tls, int32(SQLITE_TESTCTRL_IMPOSTER), libc.VaList(bp+16, (*Tsqlite3rbu)(unsafe.Pointer(p)).FdbMain, __ccgo_ts+7164, int32(1), tnum))
if (*TRbuObjIter)(unsafe.Pointer(pIter)).FeType == int32(RBU_PK_WITHOUT_ROWID) {
v2 = __ccgo_ts + 32474
} else {
v2 = __ccgo_ts + 1702
}
_rbuMPrintfExec(tls, p, (*Tsqlite3rbu)(unsafe.Pointer(p)).FdbMain, __ccgo_ts+32489, libc.VaList(bp+16, (*TRbuObjIter)(unsafe.Pointer(pIter)).FzTbl, zSql, v2))
Xsqlite3_test_control(tls, int32(SQLITE_TESTCTRL_IMPOSTER), libc.VaList(bp+16, (*Tsqlite3rbu)(unsafe.Pointer(p)).FdbMain, __ccgo_ts+7164, 0, 0))
}
}
// C documentation
//
// /*
// ** This function creates the second imposter table used when writing to
// ** a table b-tree where the table has an external primary key. If the
// ** iterator passed as the second argument does not currently point to
// ** a table (not index) with an external primary key, this function is a
// ** no-op.
// **
// ** Assuming the iterator does point to a table with an external PK, this
// ** function creates a WITHOUT ROWID imposter table named "rbu_imposter2"
// ** used to access that PK index. For example, if the target table is
// ** declared as follows:
// **
// ** CREATE TABLE t1(a, b TEXT, c REAL, PRIMARY KEY(b, c));
// **
// ** then the imposter table schema is:
// **
// ** CREATE TABLE rbu_imposter2(c1 TEXT, c2 REAL, id INTEGER) WITHOUT ROWID;
// **
// */
func _rbuCreateImposterTable2(tls *libc.TLS, p uintptr, pIter uintptr) {
bp := tls.Alloc(64)
defer tls.Free(64)
var bDesc, bKey, iCid, tnum int32
var zCollate, zCols, zComma, zIdx, zPk, v1 uintptr
var _ /* pQuery at bp+0 */ uintptr
var _ /* pXInfo at bp+8 */ uintptr
_, _, _, _, _, _, _, _, _, _ = bDesc, bKey, iCid, tnum, zCollate, zCols, zComma, zIdx, zPk, v1
if (*Tsqlite3rbu)(unsafe.Pointer(p)).Frc == SQLITE_OK && (*TRbuObjIter)(unsafe.Pointer(pIter)).FeType == int32(RBU_PK_EXTERNAL) {
tnum = (*TRbuObjIter)(unsafe.Pointer(pIter)).FiPkTnum /* Root page of PK index */
**(**uintptr)(__ccgo_up(bp)) = uintptr(0) /* SELECT name ... WHERE rootpage = $tnum */
zIdx = uintptr(0) /* Name of PK index */
**(**uintptr)(__ccgo_up(bp + 8)) = uintptr(0) /* PRAGMA main.index_xinfo = $zIdx */
zComma = __ccgo_ts + 1702
zCols = uintptr(0) /* Used to build up list of table cols */
zPk = uintptr(0) /* Used to build up table PK declaration */
/* Figure out the name of the primary key index for the current table.
** This is needed for the argument to "PRAGMA index_xinfo". Set
** zIdx to point to a nul-terminated string containing this name. */
(*Tsqlite3rbu)(unsafe.Pointer(p)).Frc = _prepareAndCollectError(tls, (*Tsqlite3rbu)(unsafe.Pointer(p)).FdbMain, bp, p+64, __ccgo_ts+32258)
if (*Tsqlite3rbu)(unsafe.Pointer(p)).Frc == SQLITE_OK {
Xsqlite3_bind_int(tls, **(**uintptr)(__ccgo_up(bp)), int32(1), tnum)
if int32(SQLITE_ROW) == Xsqlite3_step(tls, **(**uintptr)(__ccgo_up(bp))) {
zIdx = Xsqlite3_column_text(tls, **(**uintptr)(__ccgo_up(bp)), 0)
}
}
if zIdx != 0 {
(*Tsqlite3rbu)(unsafe.Pointer(p)).Frc = _prepareFreeAndCollectError(tls, (*Tsqlite3rbu)(unsafe.Pointer(p)).FdbMain, bp+8, p+64, Xsqlite3_mprintf(tls, __ccgo_ts+31410, libc.VaList(bp+24, zIdx)))
}
_rbuFinalize(tls, p, **(**uintptr)(__ccgo_up(bp)))
for (*Tsqlite3rbu)(unsafe.Pointer(p)).Frc == SQLITE_OK && int32(SQLITE_ROW) == Xsqlite3_step(tls, **(**uintptr)(__ccgo_up(bp + 8))) {
bKey = Xsqlite3_column_int(tls, **(**uintptr)(__ccgo_up(bp + 8)), int32(5))
if bKey != 0 {
iCid = Xsqlite3_column_int(tls, **(**uintptr)(__ccgo_up(bp + 8)), int32(1))
bDesc = Xsqlite3_column_int(tls, **(**uintptr)(__ccgo_up(bp + 8)), int32(3))
zCollate = Xsqlite3_column_text(tls, **(**uintptr)(__ccgo_up(bp + 8)), int32(4))
zCols = _rbuMPrintf(tls, p, __ccgo_ts+32308, libc.VaList(bp+24, zCols, zComma, iCid, **(**uintptr)(__ccgo_up((*TRbuObjIter)(unsafe.Pointer(pIter)).FazTblType + uintptr(iCid)*8)), zCollate))
if bDesc != 0 {
v1 = __ccgo_ts + 31650
} else {
v1 = __ccgo_ts + 1702
}
zPk = _rbuMPrintf(tls, p, __ccgo_ts+32330, libc.VaList(bp+24, zPk, zComma, iCid, v1))
zComma = __ccgo_ts + 16562
}
}
zCols = _rbuMPrintf(tls, p, __ccgo_ts+32340, libc.VaList(bp+24, zCols))
_rbuFinalize(tls, p, **(**uintptr)(__ccgo_up(bp + 8)))
Xsqlite3_test_control(tls, int32(SQLITE_TESTCTRL_IMPOSTER), libc.VaList(bp+24, (*Tsqlite3rbu)(unsafe.Pointer(p)).FdbMain, __ccgo_ts+7164, int32(1), tnum))
_rbuMPrintfExec(tls, p, (*Tsqlite3rbu)(unsafe.Pointer(p)).FdbMain, __ccgo_ts+32355, libc.VaList(bp+24, zCols, zPk))
Xsqlite3_test_control(tls, int32(SQLITE_TESTCTRL_IMPOSTER), libc.VaList(bp+24, (*Tsqlite3rbu)(unsafe.Pointer(p)).FdbMain, __ccgo_ts+7164, 0, 0))
}
}
// C documentation
//
// /*
// ** The RBU handle passed as the only argument has just been opened and
// ** the state database is empty. If this RBU handle was opened for an
// ** RBU vacuum operation, create the schema in the target db.
// */
func _rbuCreateTargetSchema(tls *libc.TLS, p uintptr) {
bp := tls.Alloc(16)
defer tls.Free(16)
var i int32
var zSql uintptr
var _ /* pInsert at bp+8 */ uintptr
var _ /* pSql at bp+0 */ uintptr
_, _ = i, zSql
**(**uintptr)(__ccgo_up(bp)) = uintptr(0)
**(**uintptr)(__ccgo_up(bp + 8)) = uintptr(0)
(*Tsqlite3rbu)(unsafe.Pointer(p)).Frc = Xsqlite3_exec(tls, (*Tsqlite3rbu)(unsafe.Pointer(p)).FdbMain, __ccgo_ts+34401, uintptr(0), uintptr(0), p+64)
if (*Tsqlite3rbu)(unsafe.Pointer(p)).Frc == SQLITE_OK {
(*Tsqlite3rbu)(unsafe.Pointer(p)).Frc = _prepareAndCollectError(tls, (*Tsqlite3rbu)(unsafe.Pointer(p)).FdbRbu, bp, p+64, __ccgo_ts+34426)
}
for (*Tsqlite3rbu)(unsafe.Pointer(p)).Frc == SQLITE_OK && Xsqlite3_step(tls, **(**uintptr)(__ccgo_up(bp))) == int32(SQLITE_ROW) {
zSql = Xsqlite3_column_text(tls, **(**uintptr)(__ccgo_up(bp)), 0)
(*Tsqlite3rbu)(unsafe.Pointer(p)).Frc = Xsqlite3_exec(tls, (*Tsqlite3rbu)(unsafe.Pointer(p)).FdbMain, zSql, uintptr(0), uintptr(0), p+64)
}
_rbuFinalize(tls, p, **(**uintptr)(__ccgo_up(bp)))
if (*Tsqlite3rbu)(unsafe.Pointer(p)).Frc != SQLITE_OK {
return
}
if (*Tsqlite3rbu)(unsafe.Pointer(p)).Frc == SQLITE_OK {
(*Tsqlite3rbu)(unsafe.Pointer(p)).Frc = _prepareAndCollectError(tls, (*Tsqlite3rbu)(unsafe.Pointer(p)).FdbRbu, bp, p+64, __ccgo_ts+34534)
}
if (*Tsqlite3rbu)(unsafe.Pointer(p)).Frc == SQLITE_OK {
(*Tsqlite3rbu)(unsafe.Pointer(p)).Frc = _prepareAndCollectError(tls, (*Tsqlite3rbu)(unsafe.Pointer(p)).FdbMain, bp+8, p+64, __ccgo_ts+34599)
}
for (*Tsqlite3rbu)(unsafe.Pointer(p)).Frc == SQLITE_OK && Xsqlite3_step(tls, **(**uintptr)(__ccgo_up(bp))) == int32(SQLITE_ROW) {
i = 0
for {
if !(i < int32(5)) {
break
}
Xsqlite3_bind_value(tls, **(**uintptr)(__ccgo_up(bp + 8)), i+int32(1), Xsqlite3_column_value(tls, **(**uintptr)(__ccgo_up(bp)), i))
goto _1
_1:
;
i = i + 1
}
Xsqlite3_step(tls, **(**uintptr)(__ccgo_up(bp + 8)))
(*Tsqlite3rbu)(unsafe.Pointer(p)).Frc = Xsqlite3_reset(tls, **(**uintptr)(__ccgo_up(bp + 8)))
}
if (*Tsqlite3rbu)(unsafe.Pointer(p)).Frc == SQLITE_OK {
(*Tsqlite3rbu)(unsafe.Pointer(p)).Frc = Xsqlite3_exec(tls, (*Tsqlite3rbu)(unsafe.Pointer(p)).FdbMain, __ccgo_ts+34643, uintptr(0), uintptr(0), p+64)
}
_rbuFinalize(tls, p, **(**uintptr)(__ccgo_up(bp)))
_rbuFinalize(tls, p, **(**uintptr)(__ccgo_up(bp + 8)))
}
// C documentation
//
// /*
// ** Allocate a private rbu VFS for the rbu handle passed as the only
// ** argument. This VFS will be used unless the call to sqlite3rbu_open()
// ** specified a URI with a vfs=? option in place of a target database
// ** file name.
// */
func _rbuCreateVfs(tls *libc.TLS, p uintptr) {
bp := tls.Alloc(96)
defer tls.Free(96)
var pVfs uintptr
var _ /* rnd at bp+0 */ int32
var _ /* zRnd at bp+4 */ [64]int8
_ = pVfs
Xsqlite3_randomness(tls, int32(4), bp)
Xsqlite3_snprintf(tls, int32(64), bp+4, __ccgo_ts+34721, libc.VaList(bp+80, **(**int32)(__ccgo_up(bp))))
(*Tsqlite3rbu)(unsafe.Pointer(p)).Frc = Xsqlite3rbu_create_vfs(tls, bp+4, uintptr(0))
if (*Tsqlite3rbu)(unsafe.Pointer(p)).Frc == SQLITE_OK {
pVfs = Xsqlite3_vfs_find(tls, bp+4)
(*Tsqlite3rbu)(unsafe.Pointer(p)).FzVfsName = (*Tsqlite3_vfs)(unsafe.Pointer(pVfs)).FzName
(*Trbu_vfs)(unsafe.Pointer(pVfs)).FpRbu = p
}
}
// C documentation
//
// /*
// ** If there is a "*-oal" file in the file-system corresponding to the
// ** target database in the file-system, delete it. If an error occurs,
// ** leave an error code and error message in the rbu handle.
// */
func _rbuDeleteOalFile(tls *libc.TLS, p uintptr) {
bp := tls.Alloc(32)
defer tls.Free(32)
var zOal uintptr
var _ /* pVfs at bp+0 */ uintptr
_ = zOal
zOal = _rbuMPrintf(tls, p, __ccgo_ts+34143, libc.VaList(bp+16, (*Tsqlite3rbu)(unsafe.Pointer(p)).FzTarget))
if zOal != 0 {
**(**uintptr)(__ccgo_up(bp)) = uintptr(0)
Xsqlite3_file_control(tls, (*Tsqlite3rbu)(unsafe.Pointer(p)).FdbMain, __ccgo_ts+7164, int32(SQLITE_FCNTL_VFS_POINTER), bp)
(*(*func(*libc.TLS, uintptr, uintptr, int32) int32)(unsafe.Pointer(&struct{ uintptr }{(*Tsqlite3_vfs)(unsafe.Pointer(**(**uintptr)(__ccgo_up(bp)))).FxDelete})))(tls, **(**uintptr)(__ccgo_up(bp)), zOal, 0)
Xsqlite3_free(tls, zOal)
}
}
// C documentation
//
// /*
// ** Apply a delta.
// **
// ** The output buffer should be big enough to hold the whole output
// ** file and a NUL terminator at the end. The delta_output_size()
// ** routine will determine this size for you.
// **
// ** The delta string should be null-terminated. But the delta string
// ** may contain embedded NUL characters (if the input and output are
// ** binary files) so we also have to pass in the length of the delta in
// ** the lenDelta parameter.
// **
// ** This function returns the size of the output file in bytes (excluding
// ** the final NUL terminator character). Except, if the delta string is
// ** malformed or intended for use with a source file other than zSrc,
// ** then this routine returns -1.
// **
// ** Refer to the delta_create() documentation above for a description
// ** of the delta file format.
// */
func _rbuDeltaApply(tls *libc.TLS, zSrc uintptr, lenSrc int32, _zDelta uintptr, _lenDelta int32, zOut uintptr) (r int32) {
bp := tls.Alloc(16)
defer tls.Free(16)
*(*uintptr)(unsafe.Pointer(bp)) = _zDelta
*(*int32)(unsafe.Pointer(bp + 8)) = _lenDelta
var cnt, limit, ofst, total uint32
_, _, _, _ = cnt, limit, ofst, total
total = uint32(0)
limit = _rbuDeltaGetInt(tls, bp, bp+8)
if **(**int32)(__ccgo_up(bp + 8)) <= 0 || int32(**(**int8)(__ccgo_up(**(**uintptr)(__ccgo_up(bp))))) != int32('\n') {
/* ERROR: size integer not terminated by "\n" */
return -int32(1)
}
**(**uintptr)(__ccgo_up(bp)) = **(**uintptr)(__ccgo_up(bp)) + 1
**(**int32)(__ccgo_up(bp + 8)) = **(**int32)(__ccgo_up(bp + 8)) - 1
for **(**int8)(__ccgo_up(**(**uintptr)(__ccgo_up(bp)))) != 0 && **(**int32)(__ccgo_up(bp + 8)) > 0 {
cnt = _rbuDeltaGetInt(tls, bp, bp+8)
if **(**int32)(__ccgo_up(bp + 8)) <= 0 {
return -int32(1)
}
switch int32(**(**int8)(__ccgo_up(**(**uintptr)(__ccgo_up(bp))))) {
case int32('@'):
**(**uintptr)(__ccgo_up(bp)) = **(**uintptr)(__ccgo_up(bp)) + 1
**(**int32)(__ccgo_up(bp + 8)) = **(**int32)(__ccgo_up(bp + 8)) - 1
ofst = _rbuDeltaGetInt(tls, bp, bp+8)
if **(**int32)(__ccgo_up(bp + 8)) > 0 || int32(**(**int8)(__ccgo_up(**(**uintptr)(__ccgo_up(bp))))) != int32(',') {
/* ERROR: copy command not terminated by ',' */
return -int32(1)
}
**(**uintptr)(__ccgo_up(bp)) = **(**uintptr)(__ccgo_up(bp)) + 1
**(**int32)(__ccgo_up(bp + 8)) = **(**int32)(__ccgo_up(bp + 8)) - 1
total = total + cnt
if total > limit {
/* ERROR: copy exceeds output file size */
return -int32(1)
}
if uint64(ofst)+uint64(cnt) > libc.Uint64FromInt32(lenSrc) {
/* ERROR: copy extends past end of input */
return -int32(1)
}
libc.X__builtin___memcpy_chk(tls, zOut, zSrc+uintptr(ofst), uint64(cnt), ^t__predefined_size_t(0))
zOut = zOut + uintptr(cnt)
case int32(':'):
**(**uintptr)(__ccgo_up(bp)) = **(**uintptr)(__ccgo_up(bp)) + 1
**(**int32)(__ccgo_up(bp + 8)) = **(**int32)(__ccgo_up(bp + 8)) - 1
total = total + cnt
if total > limit {
/* ERROR: insert command gives an output larger than predicted */
return -int32(1)
}
if libc.Int64FromUint32(cnt) > int64(**(**int32)(__ccgo_up(bp + 8))) {
/* ERROR: insert count exceeds size of delta */
return -int32(1)
}
libc.X__builtin___memcpy_chk(tls, zOut, **(**uintptr)(__ccgo_up(bp)), uint64(cnt), ^t__predefined_size_t(0))
zOut = zOut + uintptr(cnt)
**(**uintptr)(__ccgo_up(bp)) = **(**uintptr)(__ccgo_up(bp)) + uintptr(cnt)
**(**int32)(__ccgo_up(bp + 8)) = libc.Int32FromUint32(uint32(**(**int32)(__ccgo_up(bp + 8))) - cnt)
case int32(';'):
**(**uintptr)(__ccgo_up(bp)) = **(**uintptr)(__ccgo_up(bp)) + 1
**(**int32)(__ccgo_up(bp + 8)) = **(**int32)(__ccgo_up(bp + 8)) - 1
**(**int8)(__ccgo_up(zOut)) = 0
if total != limit {
/* ERROR: generated size does not match predicted size */
return -int32(1)
}
return libc.Int32FromUint32(total)
default:
/* ERROR: unknown delta operator */
return -int32(1)
}
}
/* ERROR: unterminated delta */
return -int32(1)
}
// 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 !(uint64(i) < nErrmsg-uint64(8)) {
break
}
if libc.Xmemcmp(tls, (*Tsqlite3rbu)(unsafe.Pointer(p)).FzErrmsg+uintptr(i), __ccgo_ts+33090, uint64(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.X__builtin___memmove_chk(tls, (*Tsqlite3rbu)(unsafe.Pointer(p)).FzErrmsg+uintptr(i), (*Tsqlite3rbu)(unsafe.Pointer(p)).FzErrmsg+uintptr(i+libc.Uint32FromInt32(nDel)), nErrmsg+uint64(1)-uint64(i)-libc.Uint64FromInt32(nDel), ^t__predefined_size_t(0))
nErrmsg = nErrmsg - libc.Uint64FromInt32(nDel)
}
goto _1
_1:
;
i = i + 1
}
}
}
// C documentation
//
// /*
// ** Return true if the database handle passed as the only argument
// ** was opened with the rbu_exclusive_checkpoint=1 URI parameter
// ** specified. Or false otherwise.
// */
func _rbuExclusiveCheckpoint(tls *libc.TLS, db uintptr) (r int32) {
var zUri uintptr
_ = zUri
zUri = Xsqlite3_db_filename(tls, db, uintptr(0))
return Xsqlite3_uri_boolean(tls, zUri, __ccgo_ts+34118, 0)
}
// C documentation
//
// /*
// ** Implementation of SQL scalar function rbu_fossil_delta().
// **
// ** This function applies a fossil delta patch to a blob. Exactly two
// ** arguments must be passed to this function. The first is the blob to
// ** patch and the second the patch to apply. If no error occurs, this
// ** function returns the patched blob.
// */
func _rbuFossilDeltaFunc(tls *libc.TLS, context uintptr, argc int32, argv uintptr) {
var aDelta, aOrig, aOut uintptr
var nDelta, nOrig, nOut, nOut2 int32
_, _, _, _, _, _, _ = aDelta, aOrig, aOut, nDelta, nOrig, nOut, nOut2
_ = argc
nOrig = Xsqlite3_value_bytes(tls, **(**uintptr)(__ccgo_up(argv)))
aOrig = Xsqlite3_value_blob(tls, **(**uintptr)(__ccgo_up(argv)))
nDelta = Xsqlite3_value_bytes(tls, **(**uintptr)(__ccgo_up(argv + 1*8)))
aDelta = Xsqlite3_value_blob(tls, **(**uintptr)(__ccgo_up(argv + 1*8)))
/* Figure out the size of the output */
nOut = _rbuDeltaOutputSize(tls, aDelta, nDelta)
if nOut < 0 {
Xsqlite3_result_error(tls, context, __ccgo_ts+30662, -int32(1))
return
}
aOut = Xsqlite3_malloc64(tls, libc.Uint64FromInt64(int64(nOut)+int64(1)))
if aOut == uintptr(0) {
Xsqlite3_result_error_nomem(tls, context)
} else {
nOut2 = _rbuDeltaApply(tls, aOrig, nOrig, aDelta, nDelta, aOut)
if nOut2 != nOut {
Xsqlite3_free(tls, aOut)
Xsqlite3_result_error(tls, context, __ccgo_ts+30662, -int32(1))
} else {
Xsqlite3_result_blob(tls, context, aOut, nOut, __ccgo_fp(Xsqlite3_free))
}
}
}
// C documentation
//
// /*
// ** Set output variable *ppStmt to point to an UPDATE statement that may
// ** be used to update the imposter table for the main table b-tree of the
// ** table object that pIter currently points to, assuming that the
// ** rbu_control column of the data_xyz table contains zMask.
// **
// ** If the zMask string does not specify any columns to update, then this
// ** is not an error. Output variable *ppStmt is set to NULL in this case.
// */
func _rbuGetUpdateStmt(tls *libc.TLS, p uintptr, pIter uintptr, zMask uintptr, ppStmt uintptr) (r int32) {
bp := tls.Alloc(48)
defer tls.Free(48)
var nUp int32
var pUp, pp, zPrefix, zSet, zUpdate, zWhere uintptr
_, _, _, _, _, _, _ = nUp, pUp, pp, zPrefix, zSet, zUpdate, zWhere
pUp = uintptr(0)
nUp = 0
/* In case an error occurs */
**(**uintptr)(__ccgo_up(ppStmt)) = uintptr(0)
/* Search for an existing statement. If one is found, shift it to the front
** of the LRU queue and return immediately. Otherwise, leave nUp pointing
** to the number of statements currently in the cache and pUp to the
** last object in the list. */
pp = pIter + 184
for {
if !(**(**uintptr)(__ccgo_up(pp)) != 0) {
break
}
pUp = **(**uintptr)(__ccgo_up(pp))
if libc.Xstrcmp(tls, (*TRbuUpdateStmt)(unsafe.Pointer(pUp)).FzMask, zMask) == 0 {
**(**uintptr)(__ccgo_up(pp)) = (*TRbuUpdateStmt)(unsafe.Pointer(pUp)).FpNext
(*TRbuUpdateStmt)(unsafe.Pointer(pUp)).FpNext = (*TRbuObjIter)(unsafe.Pointer(pIter)).FpRbuUpdate
(*TRbuObjIter)(unsafe.Pointer(pIter)).FpRbuUpdate = pUp
**(**uintptr)(__ccgo_up(ppStmt)) = (*TRbuUpdateStmt)(unsafe.Pointer(pUp)).FpUpdate
return SQLITE_OK
}
nUp = nUp + 1
goto _1
_1:
;
pp = **(**uintptr)(__ccgo_up(pp)) + 16
}
if nUp >= int32(SQLITE_RBU_UPDATE_CACHESIZE) {
pp = pIter + 184
for {
if !(**(**uintptr)(__ccgo_up(pp)) != pUp) {
break
}
goto _2
_2:
;
pp = **(**uintptr)(__ccgo_up(pp)) + 16
}
**(**uintptr)(__ccgo_up(pp)) = uintptr(0)
Xsqlite3_finalize(tls, (*TRbuUpdateStmt)(unsafe.Pointer(pUp)).FpUpdate)
(*TRbuUpdateStmt)(unsafe.Pointer(pUp)).FpUpdate = uintptr(0)
} else {
pUp = _rbuMalloc(tls, p, libc.Int64FromUint64(uint64(24)+libc.Uint64FromInt32((*TRbuObjIter)(unsafe.Pointer(pIter)).FnTblCol)+uint64(1)))
}
if pUp != 0 {
zWhere = _rbuObjIterGetWhere(tls, p, pIter)
zSet = _rbuObjIterGetSetlist(tls, p, pIter, zMask)
zUpdate = uintptr(0)
(*TRbuUpdateStmt)(unsafe.Pointer(pUp)).FzMask = pUp + 1*24
libc.X__builtin___memcpy_chk(tls, (*TRbuUpdateStmt)(unsafe.Pointer(pUp)).FzMask, zMask, libc.Uint64FromInt32((*TRbuObjIter)(unsafe.Pointer(pIter)).FnTblCol), ^t__predefined_size_t(0))
(*TRbuUpdateStmt)(unsafe.Pointer(pUp)).FpNext = (*TRbuObjIter)(unsafe.Pointer(pIter)).FpRbuUpdate
(*TRbuObjIter)(unsafe.Pointer(pIter)).FpRbuUpdate = pUp
if zSet != 0 {
zPrefix = __ccgo_ts + 1702
if (*TRbuObjIter)(unsafe.Pointer(pIter)).FeType != int32(RBU_PK_VTAB) {
zPrefix = __ccgo_ts + 33090
}
zUpdate = Xsqlite3_mprintf(tls, __ccgo_ts+33751, libc.VaList(bp+8, zPrefix, (*TRbuObjIter)(unsafe.Pointer(pIter)).FzTbl, zSet, zWhere))
(*Tsqlite3rbu)(unsafe.Pointer(p)).Frc = _prepareFreeAndCollectError(tls, (*Tsqlite3rbu)(unsafe.Pointer(p)).FdbMain, pUp+8, p+64, zUpdate)
**(**uintptr)(__ccgo_up(ppStmt)) = (*TRbuUpdateStmt)(unsafe.Pointer(pUp)).FpUpdate
}
Xsqlite3_free(tls, zWhere)
Xsqlite3_free(tls, zSet)
}
return (*Tsqlite3rbu)(unsafe.Pointer(p)).Frc
}
// C documentation
//
// /*
// ** Increment the schema cookie of the main database opened by p->dbMain.
// **
// ** Or, if this is an RBU vacuum, set the schema cookie of the main db
// ** opened by p->dbMain to one more than the schema cookie of the main
// ** db opened by p->dbRbu.
// */
func _rbuIncrSchemaCookie(tls *libc.TLS, p uintptr) {
bp := tls.Alloc(32)
defer tls.Free(32)
var dbread, v1 uintptr
var iCookie int32
var _ /* pStmt at bp+0 */ uintptr
_, _, _ = dbread, iCookie, v1
if (*Tsqlite3rbu)(unsafe.Pointer(p)).Frc == SQLITE_OK {
if (*Tsqlite3rbu)(unsafe.Pointer(p)).FzTarget == uintptr(0) {
v1 = (*Tsqlite3rbu)(unsafe.Pointer(p)).FdbRbu
} else {
v1 = (*Tsqlite3rbu)(unsafe.Pointer(p)).FdbMain
}
dbread = v1
iCookie = int32(1000000)
(*Tsqlite3rbu)(unsafe.Pointer(p)).Frc = _prepareAndCollectError(tls, dbread, bp, p+64, __ccgo_ts+34157)
if (*Tsqlite3rbu)(unsafe.Pointer(p)).Frc == SQLITE_OK {
/* Coverage: it may be that this sqlite3_step() cannot fail. There
** is already a transaction open, so the prepared statement cannot
** throw an SQLITE_SCHEMA exception. The only database page the
** statement reads is page 1, which is guaranteed to be in the cache.
** And no memory allocations are required. */
if int32(SQLITE_ROW) == Xsqlite3_step(tls, **(**uintptr)(__ccgo_up(bp))) {
iCookie = Xsqlite3_column_int(tls, **(**uintptr)(__ccgo_up(bp)), 0)
}
_rbuFinalize(tls, p, **(**uintptr)(__ccgo_up(bp)))
}
if (*Tsqlite3rbu)(unsafe.Pointer(p)).Frc == SQLITE_OK {
_rbuMPrintfExec(tls, p, (*Tsqlite3rbu)(unsafe.Pointer(p)).FdbMain, __ccgo_ts+34179, libc.VaList(bp+16, iCookie+int32(1)))
}
}
}
// C documentation
//
// /*
// ** This user-defined SQL function is invoked with a single argument - the
// ** name of a table expected to appear in the target database. It returns
// ** the number of auxilliary indexes on the table.
// */
func _rbuIndexCntFunc(tls *libc.TLS, pCtx uintptr, nVal int32, apVal uintptr) {
bp := tls.Alloc(32)
defer tls.Free(32)
var db, p, v1 uintptr
var nIndex, rc int32
var _ /* pStmt at bp+0 */ uintptr
var _ /* zErrmsg at bp+8 */ uintptr
_, _, _, _, _ = db, nIndex, p, rc, v1
p = Xsqlite3_user_data(tls, pCtx)
**(**uintptr)(__ccgo_up(bp)) = uintptr(0)
**(**uintptr)(__ccgo_up(bp + 8)) = uintptr(0)
if (*Tsqlite3rbu)(unsafe.Pointer(p)).FzTarget == uintptr(0) {
v1 = (*Tsqlite3rbu)(unsafe.Pointer(p)).FdbRbu
} else {
v1 = (*Tsqlite3rbu)(unsafe.Pointer(p)).FdbMain
}
db = v1
_ = nVal
rc = _prepareFreeAndCollectError(tls, db, bp, bp+8, Xsqlite3_mprintf(tls, __ccgo_ts+34732, libc.VaList(bp+24, Xsqlite3_value_text(tls, **(**uintptr)(__ccgo_up(apVal))))))
if rc != SQLITE_OK {
Xsqlite3_result_error(tls, pCtx, **(**uintptr)(__ccgo_up(bp + 8)), -int32(1))
} else {
nIndex = 0
if int32(SQLITE_ROW) == Xsqlite3_step(tls, **(**uintptr)(__ccgo_up(bp))) {
nIndex = Xsqlite3_column_int(tls, **(**uintptr)(__ccgo_up(bp)), 0)
}
rc = Xsqlite3_finalize(tls, **(**uintptr)(__ccgo_up(bp)))
if rc == SQLITE_OK {
Xsqlite3_result_int(tls, pCtx, nIndex)
} else {
Xsqlite3_result_error(tls, pCtx, Xsqlite3_errmsg(tls, db), -int32(1))
}
}
Xsqlite3_free(tls, **(**uintptr)(__ccgo_up(bp + 8)))
}
// C documentation
//
// /*
// ** If the RBU database contains the rbu_count table, use it to initialize
// ** the sqlite3rbu.nPhaseOneStep variable. The schema of the rbu_count table
// ** is assumed to contain the same columns as:
// **
// ** CREATE TABLE rbu_count(tbl TEXT PRIMARY KEY, cnt INTEGER) WITHOUT ROWID;
// **
// ** There should be one row in the table for each data_xxx table in the
// ** database. The 'tbl' column should contain the name of a data_xxx table,
// ** and the cnt column the number of rows it contains.
// **
// ** sqlite3rbu.nPhaseOneStep is initialized to the sum of (1 + nIndex) * cnt
// ** for all rows in the rbu_count table, where nIndex is the number of
// ** indexes on the corresponding target database table.
// */
func _rbuInitPhaseOneSteps(tls *libc.TLS, p uintptr) {
bp := tls.Alloc(16)
defer tls.Free(16)
var bExists int32
var _ /* pStmt at bp+0 */ uintptr
_ = bExists
if (*Tsqlite3rbu)(unsafe.Pointer(p)).Frc == SQLITE_OK {
**(**uintptr)(__ccgo_up(bp)) = uintptr(0)
bExists = 0 /* True if rbu_count exists */
(*Tsqlite3rbu)(unsafe.Pointer(p)).FnPhaseOneStep = int64(-int32(1))
(*Tsqlite3rbu)(unsafe.Pointer(p)).Frc = Xsqlite3_create_function(tls, (*Tsqlite3rbu)(unsafe.Pointer(p)).FdbRbu, __ccgo_ts+34804, int32(1), int32(SQLITE_UTF8), p, __ccgo_fp(_rbuIndexCntFunc), uintptr(0), uintptr(0))
/* Check for the rbu_count table. If it does not exist, or if an error
** occurs, nPhaseOneStep will be left set to -1. */
if (*Tsqlite3rbu)(unsafe.Pointer(p)).Frc == SQLITE_OK {
(*Tsqlite3rbu)(unsafe.Pointer(p)).Frc = _prepareAndCollectError(tls, (*Tsqlite3rbu)(unsafe.Pointer(p)).FdbRbu, bp, p+64, __ccgo_ts+34818)
}
if (*Tsqlite3rbu)(unsafe.Pointer(p)).Frc == SQLITE_OK {
if int32(SQLITE_ROW) == Xsqlite3_step(tls, **(**uintptr)(__ccgo_up(bp))) {
bExists = int32(1)
}
(*Tsqlite3rbu)(unsafe.Pointer(p)).Frc = Xsqlite3_finalize(tls, **(**uintptr)(__ccgo_up(bp)))
}
if (*Tsqlite3rbu)(unsafe.Pointer(p)).Frc == SQLITE_OK && bExists != 0 {
(*Tsqlite3rbu)(unsafe.Pointer(p)).Frc = _prepareAndCollectError(tls, (*Tsqlite3rbu)(unsafe.Pointer(p)).FdbRbu, bp, p+64, __ccgo_ts+34875)
if (*Tsqlite3rbu)(unsafe.Pointer(p)).Frc == SQLITE_OK {
if int32(SQLITE_ROW) == Xsqlite3_step(tls, **(**uintptr)(__ccgo_up(bp))) {
(*Tsqlite3rbu)(unsafe.Pointer(p)).FnPhaseOneStep = Xsqlite3_column_int64(tls, **(**uintptr)(__ccgo_up(bp)), 0)
}
(*Tsqlite3rbu)(unsafe.Pointer(p)).Frc = Xsqlite3_finalize(tls, **(**uintptr)(__ccgo_up(bp)))
}
}
}
}
// C documentation
//
// /*
// ** Allocate an RbuState object and load the contents of the rbu_state
// ** table into it. Return a pointer to the new object. It is the
// ** responsibility of the caller to eventually free the object using
// ** sqlite3_free().
// **
// ** If an error occurs, leave an error code and message in the rbu handle
// ** and return NULL.
// */
func _rbuLoadState(tls *libc.TLS, p uintptr) (r uintptr) {
bp := tls.Alloc(32)
defer tls.Free(32)
var pRet uintptr
var rc2 int32
var _ /* pStmt at bp+0 */ uintptr
var _ /* rc at bp+8 */ int32
_, _ = pRet, rc2
pRet = uintptr(0)
**(**uintptr)(__ccgo_up(bp)) = uintptr(0)
pRet = _rbuMalloc(tls, p, int64(80))
if pRet == uintptr(0) {
return uintptr(0)
}
**(**int32)(__ccgo_up(bp + 8)) = _prepareFreeAndCollectError(tls, (*Tsqlite3rbu)(unsafe.Pointer(p)).FdbRbu, bp, p+64, Xsqlite3_mprintf(tls, __ccgo_ts+33781, libc.VaList(bp+24, p+48)))
for **(**int32)(__ccgo_up(bp + 8)) == SQLITE_OK && int32(SQLITE_ROW) == Xsqlite3_step(tls, **(**uintptr)(__ccgo_up(bp))) {
switch Xsqlite3_column_int(tls, **(**uintptr)(__ccgo_up(bp)), 0) {
case int32(RBU_STATE_STAGE):
(*TRbuState)(unsafe.Pointer(pRet)).FeStage = Xsqlite3_column_int(tls, **(**uintptr)(__ccgo_up(bp)), int32(1))
if (*TRbuState)(unsafe.Pointer(pRet)).FeStage != int32(RBU_STAGE_OAL) && (*TRbuState)(unsafe.Pointer(pRet)).FeStage != int32(RBU_STAGE_MOVE) && (*TRbuState)(unsafe.Pointer(pRet)).FeStage != int32(RBU_STAGE_CKPT) {
(*Tsqlite3rbu)(unsafe.Pointer(p)).Frc = int32(SQLITE_CORRUPT)
}
case int32(RBU_STATE_TBL):
(*TRbuState)(unsafe.Pointer(pRet)).FzTbl = _rbuStrndup(tls, Xsqlite3_column_text(tls, **(**uintptr)(__ccgo_up(bp)), int32(1)), bp+8)
case int32(RBU_STATE_IDX):
(*TRbuState)(unsafe.Pointer(pRet)).FzIdx = _rbuStrndup(tls, Xsqlite3_column_text(tls, **(**uintptr)(__ccgo_up(bp)), int32(1)), bp+8)
case int32(RBU_STATE_ROW):
(*TRbuState)(unsafe.Pointer(pRet)).FnRow = Xsqlite3_column_int(tls, **(**uintptr)(__ccgo_up(bp)), int32(1))
case int32(RBU_STATE_PROGRESS):
(*TRbuState)(unsafe.Pointer(pRet)).FnProgress = Xsqlite3_column_int64(tls, **(**uintptr)(__ccgo_up(bp)), int32(1))
case int32(RBU_STATE_CKPT):
(*TRbuState)(unsafe.Pointer(pRet)).FiWalCksum = Xsqlite3_column_int64(tls, **(**uintptr)(__ccgo_up(bp)), int32(1))
case int32(RBU_STATE_COOKIE):
(*TRbuState)(unsafe.Pointer(pRet)).FiCookie = libc.Uint32FromInt64(Xsqlite3_column_int64(tls, **(**uintptr)(__ccgo_up(bp)), int32(1)))
case int32(RBU_STATE_OALSZ):
(*TRbuState)(unsafe.Pointer(pRet)).FiOalSz = Xsqlite3_column_int64(tls, **(**uintptr)(__ccgo_up(bp)), int32(1))
case int32(RBU_STATE_PHASEONESTEP):
(*TRbuState)(unsafe.Pointer(pRet)).FnPhaseOneStep = Xsqlite3_column_int64(tls, **(**uintptr)(__ccgo_up(bp)), int32(1))
case int32(RBU_STATE_DATATBL):
(*TRbuState)(unsafe.Pointer(pRet)).FzDataTbl = _rbuStrndup(tls, Xsqlite3_column_text(tls, **(**uintptr)(__ccgo_up(bp)), int32(1)), bp+8)
default:
**(**int32)(__ccgo_up(bp + 8)) = int32(SQLITE_CORRUPT)
break
}
}
rc2 = Xsqlite3_finalize(tls, **(**uintptr)(__ccgo_up(bp)))
if **(**int32)(__ccgo_up(bp + 8)) == SQLITE_OK {
**(**int32)(__ccgo_up(bp + 8)) = rc2
}
(*Tsqlite3rbu)(unsafe.Pointer(p)).Frc = **(**int32)(__ccgo_up(bp + 8))
return pRet
}
// C documentation
//
// /*
// ** Take an EXCLUSIVE lock on the database file. Return SQLITE_OK if
// ** successful, or an SQLite error code otherwise.
// */
func _rbuLockDatabase(tls *libc.TLS, db uintptr) (r int32) {
bp := tls.Alloc(16)
defer tls.Free(16)
var rc int32
var _ /* fd at bp+0 */ uintptr
_ = rc
rc = SQLITE_OK
**(**uintptr)(__ccgo_up(bp)) = uintptr(0)
Xsqlite3_file_control(tls, db, __ccgo_ts+7164, int32(RBU_ZIPVFS_CTRL_FILE_POINTER), bp)
if **(**uintptr)(__ccgo_up(bp)) != 0 {
Xsqlite3_file_control(tls, db, __ccgo_ts+7164, int32(SQLITE_FCNTL_FILE_POINTER), bp)
rc = (*(*func(*libc.TLS, uintptr, int32) int32)(unsafe.Pointer(&struct{ uintptr }{(*Tsqlite3_io_methods)(unsafe.Pointer((*Tsqlite3_file)(unsafe.Pointer(**(**uintptr)(__ccgo_up(bp)))).FpMethods)).FxLock})))(tls, **(**uintptr)(__ccgo_up(bp)), int32(SQLITE_LOCK_SHARED))
if rc == SQLITE_OK {
rc = (*(*func(*libc.TLS, uintptr, int32) int32)(unsafe.Pointer(&struct{ uintptr }{(*Tsqlite3_io_methods)(unsafe.Pointer((*Tsqlite3_file)(unsafe.Pointer(**(**uintptr)(__ccgo_up(bp)))).FpMethods)).FxUnlock})))(tls, **(**uintptr)(__ccgo_up(bp)), SQLITE_LOCK_NONE)
}
Xsqlite3_file_control(tls, db, __ccgo_ts+7164, int32(RBU_ZIPVFS_CTRL_FILE_POINTER), bp)
} else {
Xsqlite3_file_control(tls, db, __ccgo_ts+7164, int32(SQLITE_FCNTL_FILE_POINTER), bp)
}
if rc == SQLITE_OK && (*Tsqlite3_file)(unsafe.Pointer(**(**uintptr)(__ccgo_up(bp)))).FpMethods != 0 {
rc = (*(*func(*libc.TLS, uintptr, int32) int32)(unsafe.Pointer(&struct{ uintptr }{(*Tsqlite3_io_methods)(unsafe.Pointer((*Tsqlite3_file)(unsafe.Pointer(**(**uintptr)(__ccgo_up(bp)))).FpMethods)).FxLock})))(tls, **(**uintptr)(__ccgo_up(bp)), int32(SQLITE_LOCK_SHARED))
if rc == SQLITE_OK {
rc = (*(*func(*libc.TLS, uintptr, int32) int32)(unsafe.Pointer(&struct{ uintptr }{(*Tsqlite3_io_methods)(unsafe.Pointer((*Tsqlite3_file)(unsafe.Pointer(**(**uintptr)(__ccgo_up(bp)))).FpMethods)).FxLock})))(tls, **(**uintptr)(__ccgo_up(bp)), int32(SQLITE_LOCK_EXCLUSIVE))
}
}
return rc
}
// C documentation
//
// /*
// ** Attempt to allocate and return a pointer to a zeroed block of nByte
// ** bytes.
// **
// ** If an error (i.e. an OOM condition) occurs, return NULL and leave an
// ** error code in the rbu handle passed as the first argument. Or, if an
// ** error has already occurred when this function is called, return NULL
// ** immediately without attempting the allocation or modifying the stored
// ** error code.
// */
func _rbuMalloc(tls *libc.TLS, p uintptr, nByte Tsqlite3_int64) (r uintptr) {
var pRet uintptr
_ = pRet
pRet = uintptr(0)
if (*Tsqlite3rbu)(unsafe.Pointer(p)).Frc == SQLITE_OK {
pRet = Xsqlite3_malloc64(tls, libc.Uint64FromInt64(nByte))
if pRet == uintptr(0) {
(*Tsqlite3rbu)(unsafe.Pointer(p)).Frc = int32(SQLITE_NOMEM)
} else {
libc.X__builtin___memset_chk(tls, pRet, 0, libc.Uint64FromInt64(nByte), ^t__predefined_size_t(0))
}
}
return pRet
}
// C documentation
//
// /*
// ** Allocate and return an RBU handle with all fields zeroed except for the
// ** error code, which is set to SQLITE_MISUSE.
// */
func _rbuMisuseError(tls *libc.TLS) (r uintptr) {
var pRet uintptr
_ = pRet
pRet = Xsqlite3_malloc64(tls, uint64(416))
if pRet != 0 {
libc.X__builtin___memset_chk(tls, pRet, 0, uint64(416), ^t__predefined_size_t(0))
(*Tsqlite3rbu)(unsafe.Pointer(pRet)).Frc = int32(SQLITE_MISUSE)
}
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+7164)
zMove = zBase
if (*Tsqlite3rbu)(unsafe.Pointer(p)).FzTarget == uintptr(0) {
zMove = Xsqlite3_db_filename(tls, (*Tsqlite3rbu)(unsafe.Pointer(p)).FdbRbu, __ccgo_ts+7164)
}
zOal = Xsqlite3_mprintf(tls, __ccgo_ts+34143, libc.VaList(bp+8, zMove))
zWal = Xsqlite3_mprintf(tls, __ccgo_ts+34150, libc.VaList(bp+8, zMove))
if zWal == uintptr(0) || zOal == uintptr(0) {
(*Tsqlite3rbu)(unsafe.Pointer(p)).Frc = int32(SQLITE_NOMEM)
} else {
/* Move the *-oal file to *-wal. At this point connection p->db is
** holding a SHARED lock on the target database file (because it is
** in WAL mode). So no other connection may be writing the db.
**
** In order to ensure that there are no database readers, an EXCLUSIVE
** lock is obtained here before the *-oal is moved to *-wal.
*/
dbMain = uintptr(0)
_rbuFileSuffix3(tls, zBase, zWal)
_rbuFileSuffix3(tls, zBase, zOal)
/* Re-open the databases. */
_rbuObjIterFinalize(tls, p+88)
Xsqlite3_close(tls, (*Tsqlite3rbu)(unsafe.Pointer(p)).FdbRbu)
Xsqlite3_close(tls, (*Tsqlite3rbu)(unsafe.Pointer(p)).FdbMain)
(*Tsqlite3rbu)(unsafe.Pointer(p)).FdbMain = uintptr(0)
(*Tsqlite3rbu)(unsafe.Pointer(p)).FdbRbu = uintptr(0)
dbMain = _rbuOpenDbhandle(tls, p, (*Tsqlite3rbu)(unsafe.Pointer(p)).FzTarget, int32(1))
if dbMain != 0 {
(*Tsqlite3rbu)(unsafe.Pointer(p)).Frc = _rbuLockDatabase(tls, dbMain)
}
if (*Tsqlite3rbu)(unsafe.Pointer(p)).Frc == SQLITE_OK {
(*Tsqlite3rbu)(unsafe.Pointer(p)).Frc = (*(*func(*libc.TLS, uintptr, uintptr, uintptr) int32)(unsafe.Pointer(&struct{ uintptr }{(*Tsqlite3rbu)(unsafe.Pointer(p)).FxRename})))(tls, (*Tsqlite3rbu)(unsafe.Pointer(p)).FpRenameArg, zOal, zWal)
}
if (*Tsqlite3rbu)(unsafe.Pointer(p)).Frc != SQLITE_OK || (*Tsqlite3rbu)(unsafe.Pointer(p)).FzTarget == uintptr(0) || _rbuExclusiveCheckpoint(tls, dbMain) == 0 {
Xsqlite3_close(tls, dbMain)
dbMain = uintptr(0)
}
if (*Tsqlite3rbu)(unsafe.Pointer(p)).Frc == SQLITE_OK {
_rbuOpenDatabase(tls, p, dbMain, uintptr(0))
_rbuSetupCheckpoint(tls, p, uintptr(0))
}
}
Xsqlite3_free(tls, zWal)
Xsqlite3_free(tls, zOal)
}
// C documentation
//
// /*
// ** This is a helper function for rbuObjIterCacheTableInfo(). It populates
// ** the pIter->abIndexed[] array.
// */
func _rbuObjIterCacheIndexedCols(tls *libc.TLS, p uintptr, pIter uintptr) {
bp := tls.Alloc(32)
defer tls.Free(32)
var bIndex, bPartial, iCid int32
var zIdx uintptr
var _ /* pList at bp+0 */ uintptr
var _ /* pXInfo at bp+8 */ uintptr
_, _, _, _ = bIndex, bPartial, iCid, zIdx
**(**uintptr)(__ccgo_up(bp)) = uintptr(0)
bIndex = 0
if (*Tsqlite3rbu)(unsafe.Pointer(p)).Frc == SQLITE_OK {
libc.X__builtin___memcpy_chk(tls, (*TRbuObjIter)(unsafe.Pointer(pIter)).FabIndexed, (*TRbuObjIter)(unsafe.Pointer(pIter)).FabTblPk, uint64(1)*libc.Uint64FromInt32((*TRbuObjIter)(unsafe.Pointer(pIter)).FnTblCol), ^t__predefined_size_t(0))
(*Tsqlite3rbu)(unsafe.Pointer(p)).Frc = _prepareFreeAndCollectError(tls, (*Tsqlite3rbu)(unsafe.Pointer(p)).FdbMain, bp, p+64, Xsqlite3_mprintf(tls, __ccgo_ts+31382, libc.VaList(bp+24, (*TRbuObjIter)(unsafe.Pointer(pIter)).FzTbl)))
}
(*TRbuObjIter)(unsafe.Pointer(pIter)).FnIndex = 0
for (*Tsqlite3rbu)(unsafe.Pointer(p)).Frc == SQLITE_OK && int32(SQLITE_ROW) == Xsqlite3_step(tls, **(**uintptr)(__ccgo_up(bp))) {
zIdx = Xsqlite3_column_text(tls, **(**uintptr)(__ccgo_up(bp)), int32(1))
bPartial = Xsqlite3_column_int(tls, **(**uintptr)(__ccgo_up(bp)), int32(4))
**(**uintptr)(__ccgo_up(bp + 8)) = uintptr(0)
if zIdx == uintptr(0) {
break
}
if bPartial != 0 {
libc.X__builtin___memset_chk(tls, (*TRbuObjIter)(unsafe.Pointer(pIter)).FabIndexed, int32(0x01), uint64(1)*libc.Uint64FromInt32((*TRbuObjIter)(unsafe.Pointer(pIter)).FnTblCol), ^t__predefined_size_t(0))
}
(*Tsqlite3rbu)(unsafe.Pointer(p)).Frc = _prepareFreeAndCollectError(tls, (*Tsqlite3rbu)(unsafe.Pointer(p)).FdbMain, bp+8, p+64, Xsqlite3_mprintf(tls, __ccgo_ts+31410, libc.VaList(bp+24, zIdx)))
for (*Tsqlite3rbu)(unsafe.Pointer(p)).Frc == SQLITE_OK && int32(SQLITE_ROW) == Xsqlite3_step(tls, **(**uintptr)(__ccgo_up(bp + 8))) {
iCid = Xsqlite3_column_int(tls, **(**uintptr)(__ccgo_up(bp + 8)), int32(1))
if iCid >= 0 {
**(**Tu8)(__ccgo_up((*TRbuObjIter)(unsafe.Pointer(pIter)).FabIndexed + uintptr(iCid))) = uint8(1)
}
if iCid == -int32(2) {
libc.X__builtin___memset_chk(tls, (*TRbuObjIter)(unsafe.Pointer(pIter)).FabIndexed, int32(0x01), uint64(1)*libc.Uint64FromInt32((*TRbuObjIter)(unsafe.Pointer(pIter)).FnTblCol), ^t__predefined_size_t(0))
}
}
_rbuFinalize(tls, p, **(**uintptr)(__ccgo_up(bp + 8)))
bIndex = int32(1)
(*TRbuObjIter)(unsafe.Pointer(pIter)).FnIndex = (*TRbuObjIter)(unsafe.Pointer(pIter)).FnIndex + 1
}
if (*TRbuObjIter)(unsafe.Pointer(pIter)).FeType == int32(RBU_PK_WITHOUT_ROWID) {
/* "PRAGMA index_list" includes the main PK b-tree */
(*TRbuObjIter)(unsafe.Pointer(pIter)).FnIndex = (*TRbuObjIter)(unsafe.Pointer(pIter)).FnIndex - 1
}
_rbuFinalize(tls, p, **(**uintptr)(__ccgo_up(bp)))
if bIndex == 0 {
(*TRbuObjIter)(unsafe.Pointer(pIter)).FabIndexed = uintptr(0)
}
}
// C documentation
//
// /*
// ** If they are not already populated, populate the pIter->azTblCol[],
// ** pIter->abTblPk[], pIter->nTblCol and pIter->bRowid variables according to
// ** the table (not index) that the iterator currently points to.
// **
// ** Return SQLITE_OK if successful, or an SQLite error code otherwise. If
// ** an error does occur, an error code and error message are also left in
// ** the RBU handle.
// */
func _rbuObjIterCacheTableInfo(tls *libc.TLS, p uintptr, pIter uintptr) (r int32) {
bp := tls.Alloc(48)
defer tls.Free(48)
var bNotNull, bRbuRowid, i, iOrder, iPk, nCol, t, v2 int32
var t1, zCopy, zName, zName1, zType, v3 uintptr
var _ /* iTnum at bp+8 */ int32
var _ /* pStmt at bp+0 */ uintptr
_, _, _, _, _, _, _, _, _, _, _, _, _, _ = bNotNull, bRbuRowid, i, iOrder, iPk, nCol, t, t1, zCopy, zName, zName1, zType, v2, v3
if (*TRbuObjIter)(unsafe.Pointer(pIter)).FazTblCol == uintptr(0) {
**(**uintptr)(__ccgo_up(bp)) = uintptr(0)
nCol = 0 /* for() loop iterator variable */
bRbuRowid = 0 /* If input table has column "rbu_rowid" */
iOrder = 0
**(**int32)(__ccgo_up(bp + 8)) = 0
/* Figure out the type of table this step will deal with. */
_rbuTableType(tls, p, (*TRbuObjIter)(unsafe.Pointer(pIter)).FzTbl, pIter+72, bp+8, pIter+108)
if (*Tsqlite3rbu)(unsafe.Pointer(p)).Frc == SQLITE_OK && (*TRbuObjIter)(unsafe.Pointer(pIter)).FeType == RBU_PK_NOTABLE {
(*Tsqlite3rbu)(unsafe.Pointer(p)).Frc = int32(SQLITE_ERROR)
(*Tsqlite3rbu)(unsafe.Pointer(p)).FzErrmsg = Xsqlite3_mprintf(tls, __ccgo_ts+21734, libc.VaList(bp+24, (*TRbuObjIter)(unsafe.Pointer(pIter)).FzTbl))
}
if (*Tsqlite3rbu)(unsafe.Pointer(p)).Frc != 0 {
return (*Tsqlite3rbu)(unsafe.Pointer(p)).Frc
}
if (*TRbuObjIter)(unsafe.Pointer(pIter)).FzIdx == uintptr(0) {
(*TRbuObjIter)(unsafe.Pointer(pIter)).FiTnum = **(**int32)(__ccgo_up(bp + 8))
}
/* Populate the azTblCol[] and nTblCol variables based on the columns
** of the input table. Ignore any input table columns that begin with
** "rbu_". */
(*Tsqlite3rbu)(unsafe.Pointer(p)).Frc = _prepareFreeAndCollectError(tls, (*Tsqlite3rbu)(unsafe.Pointer(p)).FdbRbu, bp, p+64, Xsqlite3_mprintf(tls, __ccgo_ts+31439, libc.VaList(bp+24, (*TRbuObjIter)(unsafe.Pointer(pIter)).FzDataTbl)))
if (*Tsqlite3rbu)(unsafe.Pointer(p)).Frc == SQLITE_OK {
nCol = Xsqlite3_column_count(tls, **(**uintptr)(__ccgo_up(bp)))
_rbuAllocateIterArrays(tls, p, pIter, nCol)
}
i = 0
for {
if !((*Tsqlite3rbu)(unsafe.Pointer(p)).Frc == SQLITE_OK && i < nCol) {
break
}
zName = Xsqlite3_column_name(tls, **(**uintptr)(__ccgo_up(bp)), i)
if Xsqlite3_strnicmp(tls, __ccgo_ts+31458, zName, int32(4)) != 0 {
zCopy = _rbuStrndup(tls, zName, p+56)
**(**int32)(__ccgo_up((*TRbuObjIter)(unsafe.Pointer(pIter)).FaiSrcOrder + uintptr((*TRbuObjIter)(unsafe.Pointer(pIter)).FnTblCol)*4)) = (*TRbuObjIter)(unsafe.Pointer(pIter)).FnTblCol
v3 = pIter + 16
v2 = *(*int32)(unsafe.Pointer(v3))
*(*int32)(unsafe.Pointer(v3)) = *(*int32)(unsafe.Pointer(v3)) + 1
**(**uintptr)(__ccgo_up((*TRbuObjIter)(unsafe.Pointer(pIter)).FazTblCol + uintptr(v2)*8)) = zCopy
} else {
if 0 == Xsqlite3_stricmp(tls, __ccgo_ts+31463, zName) {
bRbuRowid = int32(1)
}
}
goto _1
_1:
;
i = i + 1
}
Xsqlite3_finalize(tls, **(**uintptr)(__ccgo_up(bp)))
**(**uintptr)(__ccgo_up(bp)) = uintptr(0)
if (*Tsqlite3rbu)(unsafe.Pointer(p)).Frc == SQLITE_OK && libc.BoolInt32((*Tsqlite3rbu)(unsafe.Pointer(p)).FzTarget == uintptr(0)) == 0 && bRbuRowid != libc.BoolInt32((*TRbuObjIter)(unsafe.Pointer(pIter)).FeType == int32(RBU_PK_VTAB) || (*TRbuObjIter)(unsafe.Pointer(pIter)).FeType == int32(RBU_PK_NONE)) {
(*Tsqlite3rbu)(unsafe.Pointer(p)).Frc = int32(SQLITE_ERROR)
if bRbuRowid != 0 {
v3 = __ccgo_ts + 31473
} else {
v3 = __ccgo_ts + 31486
}
(*Tsqlite3rbu)(unsafe.Pointer(p)).FzErrmsg = Xsqlite3_mprintf(tls, __ccgo_ts+31495, libc.VaList(bp+24, (*TRbuObjIter)(unsafe.Pointer(pIter)).FzDataTbl, v3))
}
/* Check that all non-HIDDEN columns in the destination table are also
** present in the input table. Populate the abTblPk[], azTblType[] and
** aiTblOrder[] arrays at the same time. */
if (*Tsqlite3rbu)(unsafe.Pointer(p)).Frc == SQLITE_OK {
(*Tsqlite3rbu)(unsafe.Pointer(p)).Frc = _prepareFreeAndCollectError(tls, (*Tsqlite3rbu)(unsafe.Pointer(p)).FdbMain, bp, p+64, Xsqlite3_mprintf(tls, __ccgo_ts+31524, libc.VaList(bp+24, (*TRbuObjIter)(unsafe.Pointer(pIter)).FzTbl)))
}
for (*Tsqlite3rbu)(unsafe.Pointer(p)).Frc == SQLITE_OK && int32(SQLITE_ROW) == Xsqlite3_step(tls, **(**uintptr)(__ccgo_up(bp))) {
zName1 = Xsqlite3_column_text(tls, **(**uintptr)(__ccgo_up(bp)), int32(1))
if zName1 == uintptr(0) {
break
} /* An OOM - finalize() below returns S_NOMEM */
i = iOrder
for {
if !(i < (*TRbuObjIter)(unsafe.Pointer(pIter)).FnTblCol) {
break
}
if 0 == libc.Xstrcmp(tls, zName1, **(**uintptr)(__ccgo_up((*TRbuObjIter)(unsafe.Pointer(pIter)).FazTblCol + uintptr(i)*8))) {
break
}
goto _5
_5:
;
i = i + 1
}
if i == (*TRbuObjIter)(unsafe.Pointer(pIter)).FnTblCol {
(*Tsqlite3rbu)(unsafe.Pointer(p)).Frc = int32(SQLITE_ERROR)
(*Tsqlite3rbu)(unsafe.Pointer(p)).FzErrmsg = Xsqlite3_mprintf(tls, __ccgo_ts+31546, libc.VaList(bp+24, (*TRbuObjIter)(unsafe.Pointer(pIter)).FzDataTbl, zName1))
} else {
iPk = Xsqlite3_column_int(tls, **(**uintptr)(__ccgo_up(bp)), int32(5))
bNotNull = Xsqlite3_column_int(tls, **(**uintptr)(__ccgo_up(bp)), int32(3))
zType = Xsqlite3_column_text(tls, **(**uintptr)(__ccgo_up(bp)), int32(2))
if i != iOrder {
t = **(**int32)(__ccgo_up((*TRbuObjIter)(unsafe.Pointer(pIter)).FaiSrcOrder + uintptr(i)*4))
**(**int32)(__ccgo_up((*TRbuObjIter)(unsafe.Pointer(pIter)).FaiSrcOrder + uintptr(i)*4)) = **(**int32)(__ccgo_up((*TRbuObjIter)(unsafe.Pointer(pIter)).FaiSrcOrder + uintptr(iOrder)*4))
**(**int32)(__ccgo_up((*TRbuObjIter)(unsafe.Pointer(pIter)).FaiSrcOrder + uintptr(iOrder)*4)) = t
t1 = **(**uintptr)(__ccgo_up((*TRbuObjIter)(unsafe.Pointer(pIter)).FazTblCol + uintptr(i)*8))
**(**uintptr)(__ccgo_up((*TRbuObjIter)(unsafe.Pointer(pIter)).FazTblCol + uintptr(i)*8)) = **(**uintptr)(__ccgo_up((*TRbuObjIter)(unsafe.Pointer(pIter)).FazTblCol + uintptr(iOrder)*8))
**(**uintptr)(__ccgo_up((*TRbuObjIter)(unsafe.Pointer(pIter)).FazTblCol + uintptr(iOrder)*8)) = t1
}
**(**uintptr)(__ccgo_up((*TRbuObjIter)(unsafe.Pointer(pIter)).FazTblType + uintptr(iOrder)*8)) = _rbuStrndup(tls, zType, p+56)
**(**Tu8)(__ccgo_up((*TRbuObjIter)(unsafe.Pointer(pIter)).FabTblPk + uintptr(iOrder))) = libc.Uint8FromInt32(iPk)
**(**Tu8)(__ccgo_up((*TRbuObjIter)(unsafe.Pointer(pIter)).FabNotNull + uintptr(iOrder))) = libc.BoolUint8(libc.Uint8FromInt32(bNotNull) != 0 || iPk != 0)
iOrder = iOrder + 1
}
}
_rbuFinalize(tls, p, **(**uintptr)(__ccgo_up(bp)))
_rbuObjIterCacheIndexedCols(tls, p, pIter)
}
return (*Tsqlite3rbu)(unsafe.Pointer(p)).Frc
}
// C documentation
//
// /*
// ** Clean up any resources allocated as part of the iterator object passed
// ** as the only argument.
// */
func _rbuObjIterFinalize(tls *libc.TLS, pIter uintptr) {
_rbuObjIterClearStatements(tls, pIter)
Xsqlite3_finalize(tls, (*TRbuObjIter)(unsafe.Pointer(pIter)).FpTblIter)
Xsqlite3_finalize(tls, (*TRbuObjIter)(unsafe.Pointer(pIter)).FpIdxIter)
_rbuObjIterFreeCols(tls, pIter)
libc.X__builtin___memset_chk(tls, pIter, 0, uint64(192), ^t__predefined_size_t(0))
}
// C documentation
//
// /*
// ** Initialize the iterator structure passed as the second argument.
// **
// ** If no error occurs, SQLITE_OK is returned and the iterator is left
// ** pointing to the first entry. Otherwise, an error code and message is
// ** left in the RBU handle passed as the first argument. A copy of the
// ** error code is returned.
// */
func _rbuObjIterFirst(tls *libc.TLS, p uintptr, pIter uintptr) (r int32) {
bp := tls.Alloc(16)
defer tls.Free(16)
var rc int32
var v1 uintptr
_, _ = rc, v1
libc.X__builtin___memset_chk(tls, pIter, 0, uint64(192), ^t__predefined_size_t(0))
if (*Tsqlite3rbu)(unsafe.Pointer(p)).FzTarget == uintptr(0) {
v1 = __ccgo_ts + 30854
} else {
v1 = __ccgo_ts + 1702
}
rc = _prepareFreeAndCollectError(tls, (*Tsqlite3rbu)(unsafe.Pointer(p)).FdbRbu, pIter, p+64, Xsqlite3_mprintf(tls, __ccgo_ts+30895, libc.VaList(bp+8, v1)))
if rc == SQLITE_OK {
rc = _prepareAndCollectError(tls, (*Tsqlite3rbu)(unsafe.Pointer(p)).FdbMain, pIter+8, p+64, __ccgo_ts+31045)
}
(*TRbuObjIter)(unsafe.Pointer(pIter)).FbCleanup = int32(1)
(*Tsqlite3rbu)(unsafe.Pointer(p)).Frc = rc
return _rbuObjIterNext(tls, p, pIter)
}
// C documentation
//
// /*
// ** This function constructs and returns a pointer to a nul-terminated
// ** string containing some SQL clause or list based on one or more of the
// ** column names currently stored in the pIter->azTblCol[] array.
// */
func _rbuObjIterGetCollist(tls *libc.TLS, p uintptr, pIter uintptr) (r uintptr) {
bp := tls.Alloc(32)
defer tls.Free(32)
var i int32
var z, zList, zSep uintptr
_, _, _, _ = i, z, zList, zSep
zList = uintptr(0)
zSep = __ccgo_ts + 1702
i = 0
for {
if !(i < (*TRbuObjIter)(unsafe.Pointer(pIter)).FnTblCol) {
break
}
z = **(**uintptr)(__ccgo_up((*TRbuObjIter)(unsafe.Pointer(pIter)).FazTblCol + uintptr(i)*8))
zList = _rbuMPrintf(tls, p, __ccgo_ts+31573, libc.VaList(bp+8, zList, zSep, z))
zSep = __ccgo_ts + 16562
goto _1
_1:
;
i = i + 1
}
return zList
}
// C documentation
//
// /*
// ** This function is used to create a SELECT list (the list of SQL
// ** expressions that follows a SELECT keyword) for a SELECT statement
// ** used to read from an data_xxx or rbu_tmp_xxx table while updating the
// ** index object currently indicated by the iterator object passed as the
// ** second argument. A "PRAGMA index_xinfo = " statement is used
// ** to obtain the required information.
// **
// ** If the index is of the following form:
// **
// ** CREATE INDEX i1 ON t1(c, b COLLATE nocase);
// **
// ** and "t1" is a table with an explicit INTEGER PRIMARY KEY column
// ** "ipk", the returned string is:
// **
// ** "`c` COLLATE 'BINARY', `b` COLLATE 'NOCASE', `ipk` COLLATE 'BINARY'"
// **
// ** As well as the returned string, three other malloc'd strings are
// ** returned via output parameters. As follows:
// **
// ** pzImposterCols: ...
// ** pzImposterPk: ...
// ** pzWhere: ...
// */
func _rbuObjIterGetIndexCols(tls *libc.TLS, p uintptr, pIter uintptr, pzImposterCols uintptr, pzImposterPk uintptr, pzWhere uintptr, pnBind uintptr) (r uintptr) {
bp := tls.Alloc(64)
defer tls.Free(64)
var bDesc, i, iCid, iSeq, nBind, rc, rc2 int32
var zAnd, zCol, zCollate, zCom, zImpCols, zImpPK, zOrder, zRet, zType, zWhere, v2 uintptr
var _ /* pXInfo at bp+0 */ uintptr
_, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _ = bDesc, i, iCid, iSeq, nBind, rc, rc2, zAnd, zCol, zCollate, zCom, zImpCols, zImpPK, zOrder, zRet, zType, zWhere, v2
rc = (*Tsqlite3rbu)(unsafe.Pointer(p)).Frc /* sqlite3_finalize() return code */
zRet = uintptr(0) /* String to return */
zImpCols = uintptr(0) /* String to return via *pzImposterCols */
zImpPK = uintptr(0) /* String to return via *pzImposterPK */
zWhere = uintptr(0) /* String to return via *pzWhere */
nBind = 0 /* Value to return via *pnBind */
zCom = __ccgo_ts + 1702 /* Set to ", " later on */
zAnd = __ccgo_ts + 1702 /* Set to " AND " later on */
**(**uintptr)(__ccgo_up(bp)) = uintptr(0) /* PRAGMA index_xinfo = ? */
if rc == SQLITE_OK {
rc = _prepareFreeAndCollectError(tls, (*Tsqlite3rbu)(unsafe.Pointer(p)).FdbMain, bp, p+64, Xsqlite3_mprintf(tls, __ccgo_ts+31410, libc.VaList(bp+16, (*TRbuObjIter)(unsafe.Pointer(pIter)).FzIdx)))
}
for rc == SQLITE_OK && int32(SQLITE_ROW) == Xsqlite3_step(tls, **(**uintptr)(__ccgo_up(bp))) {
iCid = Xsqlite3_column_int(tls, **(**uintptr)(__ccgo_up(bp)), int32(1))
bDesc = Xsqlite3_column_int(tls, **(**uintptr)(__ccgo_up(bp)), int32(3))
zCollate = Xsqlite3_column_text(tls, **(**uintptr)(__ccgo_up(bp)), int32(4))
zCol = uintptr(0)
if iCid == -int32(2) {
iSeq = Xsqlite3_column_int(tls, **(**uintptr)(__ccgo_up(bp)), 0)
zRet = Xsqlite3_mprintf(tls, __ccgo_ts+31892, libc.VaList(bp+16, zRet, zCom, (**(**TRbuSpan)(__ccgo_up((*TRbuObjIter)(unsafe.Pointer(pIter)).FaIdxCol + uintptr(iSeq)*16))).FnSpan, (**(**TRbuSpan)(__ccgo_up((*TRbuObjIter)(unsafe.Pointer(pIter)).FaIdxCol + uintptr(iSeq)*16))).FzSpan, zCollate))
zType = __ccgo_ts + 1702
} else {
if iCid < 0 {
/* An integer primary key. If the table has an explicit IPK, use
** its name. Otherwise, use "rbu_rowid". */
if (*TRbuObjIter)(unsafe.Pointer(pIter)).FeType == int32(RBU_PK_IPK) {
i = 0
for {
if !(libc.Int32FromUint8(**(**Tu8)(__ccgo_up((*TRbuObjIter)(unsafe.Pointer(pIter)).FabTblPk + uintptr(i)))) == 0) {
break
}
goto _1
_1:
;
i = i + 1
}
zCol = **(**uintptr)(__ccgo_up((*TRbuObjIter)(unsafe.Pointer(pIter)).FazTblCol + uintptr(i)*8))
} else {
if (*Tsqlite3rbu)(unsafe.Pointer(p)).FzTarget == uintptr(0) {
zCol = __ccgo_ts + 31733
} else {
zCol = __ccgo_ts + 31463
}
}
zType = __ccgo_ts + 1176
} else {
zCol = **(**uintptr)(__ccgo_up((*TRbuObjIter)(unsafe.Pointer(pIter)).FazTblCol + uintptr(iCid)*8))
zType = **(**uintptr)(__ccgo_up((*TRbuObjIter)(unsafe.Pointer(pIter)).FazTblType + uintptr(iCid)*8))
}
zRet = Xsqlite3_mprintf(tls, __ccgo_ts+31914, libc.VaList(bp+16, zRet, zCom, zCol, zCollate))
}
if (*TRbuObjIter)(unsafe.Pointer(pIter)).FbUnique == 0 || Xsqlite3_column_int(tls, **(**uintptr)(__ccgo_up(bp)), int32(5)) != 0 {
if bDesc != 0 {
v2 = __ccgo_ts + 31650
} else {
v2 = __ccgo_ts + 1702
}
zOrder = v2
zImpPK = Xsqlite3_mprintf(tls, __ccgo_ts+31934, libc.VaList(bp+16, zImpPK, zCom, nBind, zCol, zOrder))
}
zImpCols = Xsqlite3_mprintf(tls, __ccgo_ts+31955, libc.VaList(bp+16, zImpCols, zCom, nBind, zCol, zType, zCollate))
zWhere = Xsqlite3_mprintf(tls, __ccgo_ts+31988, libc.VaList(bp+16, zWhere, zAnd, nBind, zCol))
if zRet == uintptr(0) || zImpPK == uintptr(0) || zImpCols == uintptr(0) || zWhere == uintptr(0) {
rc = int32(SQLITE_NOMEM)
}
zCom = __ccgo_ts + 16562
zAnd = __ccgo_ts + 24020
nBind = nBind + 1
}
rc2 = Xsqlite3_finalize(tls, **(**uintptr)(__ccgo_up(bp)))
if rc == SQLITE_OK {
rc = rc2
}
if rc != SQLITE_OK {
Xsqlite3_free(tls, zRet)
Xsqlite3_free(tls, zImpCols)
Xsqlite3_free(tls, zImpPK)
Xsqlite3_free(tls, zWhere)
zRet = uintptr(0)
zImpCols = uintptr(0)
zImpPK = uintptr(0)
zWhere = uintptr(0)
(*Tsqlite3rbu)(unsafe.Pointer(p)).Frc = rc
}
**(**uintptr)(__ccgo_up(pzImposterCols)) = zImpCols
**(**uintptr)(__ccgo_up(pzImposterPk)) = zImpPK
**(**uintptr)(__ccgo_up(pzWhere)) = zWhere
**(**int32)(__ccgo_up(pnBind)) = nBind
return zRet
}
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+8 */ int32
_, _, _, _, _, _, _, _, _, _, _, _, _ = aIdxCol, c, i, iIdxCol, nIdxAlloc, nParen, nSpan, nSpan1, rc2, zRet, zSql, v1, v3
**(**uintptr)(__ccgo_up(bp)) = uintptr(0)
**(**int32)(__ccgo_up(bp + 8)) = (*Tsqlite3rbu)(unsafe.Pointer(p)).Frc
zRet = uintptr(0)
if **(**int32)(__ccgo_up(bp + 8)) == SQLITE_OK {
**(**int32)(__ccgo_up(bp + 8)) = _prepareAndCollectError(tls, (*Tsqlite3rbu)(unsafe.Pointer(p)).FdbMain, bp, p+64, __ccgo_ts+32578)
}
if **(**int32)(__ccgo_up(bp + 8)) == SQLITE_OK {
**(**int32)(__ccgo_up(bp + 8)) = 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 + 8)) == 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+8)
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.Uint64FromInt32(nIdxAlloc)*uint64(16)+libc.Uint64FromInt32(16)*libc.Uint64FromInt64(16)))
if aIdxCol == uintptr(0) {
**(**int32)(__ccgo_up(bp + 8)) = 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 = int32(t__predefined_ptrdiff_t(zSql+uintptr(i)) - int64((**(**TRbuSpan)(__ccgo_up((*TRbuObjIter)(unsafe.Pointer(pIter)).FaIdxCol + uintptr(iIdxCol)*16))).FzSpan))
v3 = iIdxCol
iIdxCol = iIdxCol + 1
(**(**TRbuSpan)(__ccgo_up((*TRbuObjIter)(unsafe.Pointer(pIter)).FaIdxCol + uintptr(v3)*16))).FnSpan = nSpan
i = i + 1
break
}
} else {
if int32(c) == int32(',') && nParen == int32(1) {
nSpan1 = int32(t__predefined_ptrdiff_t(zSql+uintptr(i)) - int64((**(**TRbuSpan)(__ccgo_up((*TRbuObjIter)(unsafe.Pointer(pIter)).FaIdxCol + uintptr(iIdxCol)*16))).FzSpan))
v3 = iIdxCol
iIdxCol = iIdxCol + 1
(**(**TRbuSpan)(__ccgo_up((*TRbuObjIter)(unsafe.Pointer(pIter)).FaIdxCol + uintptr(v3)*16))).FnSpan = nSpan1
(**(**TRbuSpan)(__ccgo_up((*TRbuObjIter)(unsafe.Pointer(pIter)).FaIdxCol + uintptr(iIdxCol)*16))).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+8)
}
(*TRbuObjIter)(unsafe.Pointer(pIter)).FnIdxCol = iIdxCol
}
}
rc2 = Xsqlite3_finalize(tls, **(**uintptr)(__ccgo_up(bp)))
if **(**int32)(__ccgo_up(bp + 8)) == SQLITE_OK {
**(**int32)(__ccgo_up(bp + 8)) = rc2
}
}
(*Tsqlite3rbu)(unsafe.Pointer(p)).Frc = **(**int32)(__ccgo_up(bp + 8))
return zRet
}
// C documentation
//
// /*
// ** Assuming the current table columns are "a", "b" and "c", and the zObj
// ** paramter is passed "old", return a string of the form:
// **
// ** "old.a, old.b, old.b"
// **
// ** With the column names escaped.
// **
// ** For tables with implicit rowids - RBU_PK_EXTERNAL and RBU_PK_NONE, append
// ** the text ", old._rowid_" to the returned value.
// */
func _rbuObjIterGetOldlist(tls *libc.TLS, p uintptr, pIter uintptr, zObj uintptr) (r uintptr) {
bp := tls.Alloc(48)
defer tls.Free(48)
var i int32
var zCol, zList, zS uintptr
_, _, _, _ = i, zCol, zList, zS
zList = uintptr(0)
if (*Tsqlite3rbu)(unsafe.Pointer(p)).Frc == SQLITE_OK && (*TRbuObjIter)(unsafe.Pointer(pIter)).FabIndexed != 0 {
zS = __ccgo_ts + 1702
i = 0
for {
if !(i < (*TRbuObjIter)(unsafe.Pointer(pIter)).FnTblCol) {
break
}
if **(**Tu8)(__ccgo_up((*TRbuObjIter)(unsafe.Pointer(pIter)).FabIndexed + uintptr(i))) != 0 {
zCol = **(**uintptr)(__ccgo_up((*TRbuObjIter)(unsafe.Pointer(pIter)).FazTblCol + uintptr(i)*8))
zList = Xsqlite3_mprintf(tls, __ccgo_ts+32012, libc.VaList(bp+8, zList, zS, zObj, zCol))
} else {
zList = Xsqlite3_mprintf(tls, __ccgo_ts+32024, libc.VaList(bp+8, zList, zS))
}
zS = __ccgo_ts + 16562
if zList == uintptr(0) {
(*Tsqlite3rbu)(unsafe.Pointer(p)).Frc = int32(SQLITE_NOMEM)
break
}
goto _1
_1:
;
i = i + 1
}
/* For a table with implicit rowids, append "old._rowid_" to the list. */
if (*TRbuObjIter)(unsafe.Pointer(pIter)).FeType == int32(RBU_PK_EXTERNAL) || (*TRbuObjIter)(unsafe.Pointer(pIter)).FeType == int32(RBU_PK_NONE) {
zList = _rbuMPrintf(tls, p, __ccgo_ts+32033, libc.VaList(bp+8, zList, zObj))
}
}
return zList
}
// C documentation
//
// /*
// ** Return a comma separated list of the quoted PRIMARY KEY column names,
// ** in order, for the current table. Before each column name, add the text
// ** zPre. After each column name, add the zPost text. Use zSeparator as
// ** the separator text (usually ", ").
// */
func _rbuObjIterGetPkList(tls *libc.TLS, p uintptr, pIter uintptr, zPre uintptr, zSeparator uintptr, zPost uintptr) (r uintptr) {
bp := tls.Alloc(48)
defer tls.Free(48)
var i, iPk int32
var zCol, zRet, zSep uintptr
_, _, _, _, _ = i, iPk, zCol, zRet, zSep
iPk = int32(1)
zRet = uintptr(0)
zSep = __ccgo_ts + 1702
for int32(1) != 0 {
i = 0
for {
if !(i < (*TRbuObjIter)(unsafe.Pointer(pIter)).FnTblCol) {
break
}
if libc.Int32FromUint8(**(**Tu8)(__ccgo_up((*TRbuObjIter)(unsafe.Pointer(pIter)).FabTblPk + uintptr(i)))) == iPk {
zCol = **(**uintptr)(__ccgo_up((*TRbuObjIter)(unsafe.Pointer(pIter)).FazTblCol + uintptr(i)*8))
zRet = _rbuMPrintf(tls, p, __ccgo_ts+31582, libc.VaList(bp+8, zRet, zSep, zPre, zCol, zPost))
zSep = zSeparator
break
}
goto _1
_1:
;
i = i + 1
}
if i == (*TRbuObjIter)(unsafe.Pointer(pIter)).FnTblCol {
break
}
iPk = iPk + 1
}
return zRet
}
// C documentation
//
// /*
// ** Return 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.Int32FromUint64(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+32124, libc.VaList(bp+8, zList, zSep, **(**uintptr)(__ccgo_up((*TRbuObjIter)(unsafe.Pointer(pIter)).FazTblCol + uintptr(i)*8)), i+int32(1)))
zSep = __ccgo_ts + 16562
} else {
if int32(c) == int32('d') {
zList = _rbuMPrintf(tls, p, __ccgo_ts+32163, libc.VaList(bp+8, zList, zSep, **(**uintptr)(__ccgo_up((*TRbuObjIter)(unsafe.Pointer(pIter)).FazTblCol + uintptr(i)*8)), **(**uintptr)(__ccgo_up((*TRbuObjIter)(unsafe.Pointer(pIter)).FazTblCol + uintptr(i)*8)), i+int32(1)))
zSep = __ccgo_ts + 16562
} else {
if int32(c) == int32('f') {
zList = _rbuMPrintf(tls, p, __ccgo_ts+32193, libc.VaList(bp+8, zList, zSep, **(**uintptr)(__ccgo_up((*TRbuObjIter)(unsafe.Pointer(pIter)).FazTblCol + uintptr(i)*8)), **(**uintptr)(__ccgo_up((*TRbuObjIter)(unsafe.Pointer(pIter)).FazTblCol + uintptr(i)*8)), i+int32(1)))
zSep = __ccgo_ts + 16562
}
}
}
goto _1
_1:
;
i = i + 1
}
}
}
return zList
}
// C documentation
//
// /*
// ** Return an expression that can be used in a WHERE clause to match the
// ** primary key of the current table. For example, if the table is:
// **
// ** CREATE TABLE t1(a, b, c, PRIMARY KEY(b, c));
// **
// ** Return the string:
// **
// ** "b = ?1 AND c = ?2"
// */
func _rbuObjIterGetWhere(tls *libc.TLS, p uintptr, pIter uintptr) (r uintptr) {
bp := tls.Alloc(48)
defer tls.Free(48)
var i, i1 int32
var zCol, zList, zSep, zSep1 uintptr
_, _, _, _, _, _ = i, i1, zCol, zList, zSep, zSep1
zList = uintptr(0)
if (*TRbuObjIter)(unsafe.Pointer(pIter)).FeType == int32(RBU_PK_VTAB) || (*TRbuObjIter)(unsafe.Pointer(pIter)).FeType == int32(RBU_PK_NONE) {
zList = _rbuMPrintf(tls, p, __ccgo_ts+32048, libc.VaList(bp+8, (*TRbuObjIter)(unsafe.Pointer(pIter)).FnTblCol+int32(1)))
} else {
if (*TRbuObjIter)(unsafe.Pointer(pIter)).FeType == int32(RBU_PK_EXTERNAL) {
zSep = __ccgo_ts + 1702
i = 0
for {
if !(i < (*TRbuObjIter)(unsafe.Pointer(pIter)).FnTblCol) {
break
}
if **(**Tu8)(__ccgo_up((*TRbuObjIter)(unsafe.Pointer(pIter)).FabTblPk + uintptr(i))) != 0 {
zList = _rbuMPrintf(tls, p, __ccgo_ts+32062, libc.VaList(bp+8, zList, zSep, i, i+int32(1)))
zSep = __ccgo_ts + 24020
}
goto _1
_1:
;
i = i + 1
}
zList = _rbuMPrintf(tls, p, __ccgo_ts+32074, libc.VaList(bp+8, zList))
} else {
zSep1 = __ccgo_ts + 1702
i1 = 0
for {
if !(i1 < (*TRbuObjIter)(unsafe.Pointer(pIter)).FnTblCol) {
break
}
if **(**Tu8)(__ccgo_up((*TRbuObjIter)(unsafe.Pointer(pIter)).FabTblPk + uintptr(i1))) != 0 {
zCol = **(**uintptr)(__ccgo_up((*TRbuObjIter)(unsafe.Pointer(pIter)).FazTblCol + uintptr(i1)*8))
zList = _rbuMPrintf(tls, p, __ccgo_ts+32124, libc.VaList(bp+8, zList, zSep1, zCol, i1+int32(1)))
zSep1 = __ccgo_ts + 24020
}
goto _2
_2:
;
i1 = i1 + 1
}
}
}
return zList
}
// C documentation
//
// /*
// ** Advance the iterator to the next position.
// **
// ** If no error occurs, SQLITE_OK is returned and the iterator is left
// ** pointing to the next entry. Otherwise, an error code and message is
// ** left in the RBU handle passed as the first argument. A copy of the
// ** error code is returned.
// */
func _rbuObjIterNext(tls *libc.TLS, p uintptr, pIter uintptr) (r int32) {
var pIdx uintptr
var rc, v1 int32
_, _, _ = pIdx, rc, v1
rc = (*Tsqlite3rbu)(unsafe.Pointer(p)).Frc
if rc == SQLITE_OK {
/* Free any SQLite statements used while processing the previous object */
_rbuObjIterClearStatements(tls, pIter)
if (*TRbuObjIter)(unsafe.Pointer(pIter)).FzIdx == uintptr(0) {
rc = Xsqlite3_exec(tls, (*Tsqlite3rbu)(unsafe.Pointer(p)).FdbMain, __ccgo_ts+30683, uintptr(0), uintptr(0), p+64)
}
if rc == SQLITE_OK {
if (*TRbuObjIter)(unsafe.Pointer(pIter)).FbCleanup != 0 {
_rbuObjIterFreeCols(tls, pIter)
(*TRbuObjIter)(unsafe.Pointer(pIter)).FbCleanup = 0
rc = Xsqlite3_step(tls, (*TRbuObjIter)(unsafe.Pointer(pIter)).FpTblIter)
if rc != int32(SQLITE_ROW) {
rc = _resetAndCollectError(tls, (*TRbuObjIter)(unsafe.Pointer(pIter)).FpTblIter, p+64)
(*TRbuObjIter)(unsafe.Pointer(pIter)).FzTbl = uintptr(0)
(*TRbuObjIter)(unsafe.Pointer(pIter)).FzDataTbl = uintptr(0)
} else {
(*TRbuObjIter)(unsafe.Pointer(pIter)).FzTbl = Xsqlite3_column_text(tls, (*TRbuObjIter)(unsafe.Pointer(pIter)).FpTblIter, 0)
(*TRbuObjIter)(unsafe.Pointer(pIter)).FzDataTbl = Xsqlite3_column_text(tls, (*TRbuObjIter)(unsafe.Pointer(pIter)).FpTblIter, int32(1))
if (*TRbuObjIter)(unsafe.Pointer(pIter)).FzDataTbl != 0 && (*TRbuObjIter)(unsafe.Pointer(pIter)).FzTbl != 0 {
v1 = SQLITE_OK
} else {
v1 = int32(SQLITE_NOMEM)
}
rc = v1
}
} else {
if (*TRbuObjIter)(unsafe.Pointer(pIter)).FzIdx == uintptr(0) {
pIdx = (*TRbuObjIter)(unsafe.Pointer(pIter)).FpIdxIter
rc = Xsqlite3_bind_text(tls, pIdx, int32(1), (*TRbuObjIter)(unsafe.Pointer(pIter)).FzTbl, -int32(1), libc.UintptrFromInt32(0))
}
if rc == SQLITE_OK {
rc = Xsqlite3_step(tls, (*TRbuObjIter)(unsafe.Pointer(pIter)).FpIdxIter)
if rc != int32(SQLITE_ROW) {
rc = _resetAndCollectError(tls, (*TRbuObjIter)(unsafe.Pointer(pIter)).FpIdxIter, p+64)
(*TRbuObjIter)(unsafe.Pointer(pIter)).FbCleanup = int32(1)
(*TRbuObjIter)(unsafe.Pointer(pIter)).FzIdx = uintptr(0)
} else {
(*TRbuObjIter)(unsafe.Pointer(pIter)).FzIdx = Xsqlite3_column_text(tls, (*TRbuObjIter)(unsafe.Pointer(pIter)).FpIdxIter, 0)
(*TRbuObjIter)(unsafe.Pointer(pIter)).FiTnum = Xsqlite3_column_int(tls, (*TRbuObjIter)(unsafe.Pointer(pIter)).FpIdxIter, int32(1))
(*TRbuObjIter)(unsafe.Pointer(pIter)).FbUnique = Xsqlite3_column_int(tls, (*TRbuObjIter)(unsafe.Pointer(pIter)).FpIdxIter, int32(2))
if (*TRbuObjIter)(unsafe.Pointer(pIter)).FzIdx != 0 {
v1 = SQLITE_OK
} else {
v1 = int32(SQLITE_NOMEM)
}
rc = v1
}
}
}
}
}
if rc != SQLITE_OK {
_rbuObjIterFinalize(tls, pIter)
(*Tsqlite3rbu)(unsafe.Pointer(p)).Frc = rc
}
return rc
}
// C documentation
//
// /*
// ** Ensure that the SQLite statement handles required to update the
// ** target database object currently indicated by the iterator passed
// ** as the second argument are available.
// */
func _rbuObjIterPrepareAll(tls *libc.TLS, p uintptr, pIter uintptr, nOffset int32) (r int32) {
bp := tls.Alloc(128)
defer tls.Free(128)
var bRbuRowid, tnum int32
var pz, zBind, zBindings, zCollist, zIdx, zLimit, zNewlist, zOldlist, zOrder, zPart, zRbuRowid, zRbuRowid1, zSql, zStart, zStart1, zTbl, zTbl1, zWhere1, zWrite, v1, v2, v3 uintptr
var _ /* nBind at bp+24 */ int32
var _ /* zImposterCols at bp+0 */ uintptr
var _ /* zImposterPK at bp+8 */ uintptr
var _ /* zWhere at bp+16 */ uintptr
_, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _ = bRbuRowid, pz, tnum, zBind, zBindings, zCollist, zIdx, zLimit, zNewlist, zOldlist, zOrder, zPart, zRbuRowid, zRbuRowid1, zSql, zStart, zStart1, zTbl, zTbl1, zWhere1, zWrite, v1, v2, v3
if (*TRbuObjIter)(unsafe.Pointer(pIter)).FpSelect == uintptr(0) && _rbuObjIterCacheTableInfo(tls, p, pIter) == SQLITE_OK {
tnum = (*TRbuObjIter)(unsafe.Pointer(pIter)).FiTnum
zCollist = uintptr(0) /* List of indexed columns */
pz = p + 64
zIdx = (*TRbuObjIter)(unsafe.Pointer(pIter)).FzIdx
zLimit = uintptr(0)
if nOffset != 0 {
zLimit = Xsqlite3_mprintf(tls, __ccgo_ts+32644, libc.VaList(bp+40, nOffset))
if !(zLimit != 0) {
(*Tsqlite3rbu)(unsafe.Pointer(p)).Frc = int32(SQLITE_NOMEM)
}
}
if zIdx != 0 {
zTbl = (*TRbuObjIter)(unsafe.Pointer(pIter)).FzTbl
**(**uintptr)(__ccgo_up(bp)) = uintptr(0) /* Columns for imposter table */
**(**uintptr)(__ccgo_up(bp + 8)) = uintptr(0) /* Primary key declaration for imposter */
**(**uintptr)(__ccgo_up(bp + 16)) = uintptr(0) /* WHERE clause on PK columns */
zBind = uintptr(0)
zPart = uintptr(0)
**(**int32)(__ccgo_up(bp + 24)) = 0
zPart = _rbuObjIterGetIndexWhere(tls, p, pIter)
zCollist = _rbuObjIterGetIndexCols(tls, p, pIter, bp, bp+8, bp+16, bp+24)
zBind = _rbuObjIterGetBindlist(tls, p, **(**int32)(__ccgo_up(bp + 24)))
/* Create the imposter table used to write to this index. */
Xsqlite3_test_control(tls, int32(SQLITE_TESTCTRL_IMPOSTER), libc.VaList(bp+40, (*Tsqlite3rbu)(unsafe.Pointer(p)).FdbMain, __ccgo_ts+7164, 0, int32(1)))
Xsqlite3_test_control(tls, int32(SQLITE_TESTCTRL_IMPOSTER), libc.VaList(bp+40, (*Tsqlite3rbu)(unsafe.Pointer(p)).FdbMain, __ccgo_ts+7164, int32(1), tnum))
_rbuMPrintfExec(tls, p, (*Tsqlite3rbu)(unsafe.Pointer(p)).FdbMain, __ccgo_ts+32664, libc.VaList(bp+40, zTbl, **(**uintptr)(__ccgo_up(bp)), **(**uintptr)(__ccgo_up(bp + 8))))
Xsqlite3_test_control(tls, int32(SQLITE_TESTCTRL_IMPOSTER), libc.VaList(bp+40, (*Tsqlite3rbu)(unsafe.Pointer(p)).FdbMain, __ccgo_ts+7164, 0, 0))
/* Create the statement to insert index entries */
(*TRbuObjIter)(unsafe.Pointer(pIter)).FnCol = **(**int32)(__ccgo_up(bp + 24))
if (*Tsqlite3rbu)(unsafe.Pointer(p)).Frc == SQLITE_OK {
(*Tsqlite3rbu)(unsafe.Pointer(p)).Frc = _prepareFreeAndCollectError(tls, (*Tsqlite3rbu)(unsafe.Pointer(p)).FdbMain, pIter+136, p+64, Xsqlite3_mprintf(tls, __ccgo_ts+32729, libc.VaList(bp+40, zTbl, zBind)))
}
/* And to delete index entries */
if libc.BoolInt32((*Tsqlite3rbu)(unsafe.Pointer(p)).FzTarget == uintptr(0)) == 0 && (*Tsqlite3rbu)(unsafe.Pointer(p)).Frc == SQLITE_OK {
(*Tsqlite3rbu)(unsafe.Pointer(p)).Frc = _prepareFreeAndCollectError(tls, (*Tsqlite3rbu)(unsafe.Pointer(p)).FdbMain, pIter+144, p+64, Xsqlite3_mprintf(tls, __ccgo_ts+32765, libc.VaList(bp+40, zTbl, **(**uintptr)(__ccgo_up(bp + 16)))))
}
/* Create the SELECT statement to read keys in sorted order */
if (*Tsqlite3rbu)(unsafe.Pointer(p)).Frc == SQLITE_OK {
if (*Tsqlite3rbu)(unsafe.Pointer(p)).FzTarget == uintptr(0) {
zStart = uintptr(0)
if nOffset != 0 {
zStart = _rbuVacuumIndexStart(tls, p, pIter)
if zStart != 0 {
Xsqlite3_free(tls, zLimit)
zLimit = uintptr(0)
}
}
if zStart != 0 {
if zPart != 0 {
v2 = __ccgo_ts + 32799
} else {
v2 = __ccgo_ts + 32803
}
v1 = v2
} else {
v1 = __ccgo_ts + 1702
}
zSql = Xsqlite3_mprintf(tls, __ccgo_ts+32809, libc.VaList(bp+40, zCollist, (*TRbuObjIter)(unsafe.Pointer(pIter)).FzDataTbl, zPart, v1, zStart, zCollist, zLimit))
Xsqlite3_free(tls, zStart)
} else {
if (*TRbuObjIter)(unsafe.Pointer(pIter)).FeType == int32(RBU_PK_EXTERNAL) || (*TRbuObjIter)(unsafe.Pointer(pIter)).FeType == int32(RBU_PK_NONE) {
zSql = Xsqlite3_mprintf(tls, __ccgo_ts+32870, libc.VaList(bp+40, zCollist, p+48, (*TRbuObjIter)(unsafe.Pointer(pIter)).FzDataTbl, zPart, zCollist, zLimit))
} else {
if zPart != 0 {
v1 = __ccgo_ts + 32799
} else {
v1 = __ccgo_ts + 32803
}
zSql = Xsqlite3_mprintf(tls, __ccgo_ts+32931, libc.VaList(bp+40, zCollist, p+48, (*TRbuObjIter)(unsafe.Pointer(pIter)).FzDataTbl, zPart, zCollist, (*TRbuObjIter)(unsafe.Pointer(pIter)).FzDataTbl, zPart, v1, zCollist, zLimit))
}
}
if (*Tsqlite3rbu)(unsafe.Pointer(p)).Frc == SQLITE_OK {
(*Tsqlite3rbu)(unsafe.Pointer(p)).Frc = _prepareFreeAndCollectError(tls, (*Tsqlite3rbu)(unsafe.Pointer(p)).FdbRbu, pIter+128, pz, zSql)
} else {
Xsqlite3_free(tls, zSql)
}
}
Xsqlite3_free(tls, **(**uintptr)(__ccgo_up(bp)))
Xsqlite3_free(tls, **(**uintptr)(__ccgo_up(bp + 8)))
Xsqlite3_free(tls, **(**uintptr)(__ccgo_up(bp + 16)))
Xsqlite3_free(tls, zBind)
Xsqlite3_free(tls, zPart)
} else {
bRbuRowid = libc.BoolInt32((*TRbuObjIter)(unsafe.Pointer(pIter)).FeType == int32(RBU_PK_VTAB) || (*TRbuObjIter)(unsafe.Pointer(pIter)).FeType == int32(RBU_PK_NONE) || (*TRbuObjIter)(unsafe.Pointer(pIter)).FeType == int32(RBU_PK_EXTERNAL) && (*Tsqlite3rbu)(unsafe.Pointer(p)).FzTarget == uintptr(0))
zTbl1 = (*TRbuObjIter)(unsafe.Pointer(pIter)).FzTbl /* Imposter table name */
zBindings = _rbuObjIterGetBindlist(tls, p, (*TRbuObjIter)(unsafe.Pointer(pIter)).FnTblCol+bRbuRowid)
zWhere1 = _rbuObjIterGetWhere(tls, p, pIter)
zOldlist = _rbuObjIterGetOldlist(tls, p, pIter, __ccgo_ts+7175)
zNewlist = _rbuObjIterGetOldlist(tls, p, pIter, __ccgo_ts+7171)
zCollist = _rbuObjIterGetCollist(tls, p, pIter)
(*TRbuObjIter)(unsafe.Pointer(pIter)).FnCol = (*TRbuObjIter)(unsafe.Pointer(pIter)).FnTblCol
/* Create the imposter table or tables (if required). */
_rbuCreateImposterTable(tls, p, pIter)
_rbuCreateImposterTable2(tls, p, pIter)
if (*TRbuObjIter)(unsafe.Pointer(pIter)).FeType == int32(RBU_PK_VTAB) {
v1 = __ccgo_ts + 1702
} else {
v1 = __ccgo_ts + 33090
}
zWrite = v1
/* Create the INSERT statement to write to the target PK b-tree */
if (*Tsqlite3rbu)(unsafe.Pointer(p)).Frc == SQLITE_OK {
if bRbuRowid != 0 {
v1 = __ccgo_ts + 33099
} else {
v1 = __ccgo_ts + 1702
}
(*Tsqlite3rbu)(unsafe.Pointer(p)).Frc = _prepareFreeAndCollectError(tls, (*Tsqlite3rbu)(unsafe.Pointer(p)).FdbMain, pIter+136, pz, Xsqlite3_mprintf(tls, __ccgo_ts+33109, libc.VaList(bp+40, zWrite, zTbl1, zCollist, v1, zBindings)))
}
/* Create the DELETE statement to write to the target PK b-tree.
** Because it only performs INSERT operations, this is not required for
** an rbu vacuum handle. */
if libc.BoolInt32((*Tsqlite3rbu)(unsafe.Pointer(p)).FzTarget == uintptr(0)) == 0 && (*Tsqlite3rbu)(unsafe.Pointer(p)).Frc == SQLITE_OK {
(*Tsqlite3rbu)(unsafe.Pointer(p)).Frc = _prepareFreeAndCollectError(tls, (*Tsqlite3rbu)(unsafe.Pointer(p)).FdbMain, pIter+144, pz, Xsqlite3_mprintf(tls, __ccgo_ts+33145, libc.VaList(bp+40, zWrite, zTbl1, zWhere1)))
}
if libc.BoolInt32((*Tsqlite3rbu)(unsafe.Pointer(p)).FzTarget == uintptr(0)) == 0 && (*TRbuObjIter)(unsafe.Pointer(pIter)).FabIndexed != 0 {
zRbuRowid = __ccgo_ts + 1702
if (*TRbuObjIter)(unsafe.Pointer(pIter)).FeType == int32(RBU_PK_EXTERNAL) || (*TRbuObjIter)(unsafe.Pointer(pIter)).FeType == int32(RBU_PK_NONE) {
zRbuRowid = __ccgo_ts + 33173
}
/* Create the rbu_tmp_xxx table and the triggers to populate it. */
if (*TRbuObjIter)(unsafe.Pointer(pIter)).FeType == int32(RBU_PK_EXTERNAL) {
v1 = __ccgo_ts + 33185
} else {
v1 = __ccgo_ts + 1702
}
_rbuMPrintfExec(tls, p, (*Tsqlite3rbu)(unsafe.Pointer(p)).FdbRbu, __ccgo_ts+33202, libc.VaList(bp+40, p+48, (*TRbuObjIter)(unsafe.Pointer(pIter)).FzDataTbl, v1, (*TRbuObjIter)(unsafe.Pointer(pIter)).FzDataTbl))
_rbuMPrintfExec(tls, p, (*Tsqlite3rbu)(unsafe.Pointer(p)).FdbMain, __ccgo_ts+33278, libc.VaList(bp+40, zWrite, zTbl1, zOldlist, zWrite, zTbl1, zOldlist, zWrite, zTbl1, zNewlist))
if (*TRbuObjIter)(unsafe.Pointer(pIter)).FeType == int32(RBU_PK_EXTERNAL) || (*TRbuObjIter)(unsafe.Pointer(pIter)).FeType == int32(RBU_PK_NONE) {
_rbuMPrintfExec(tls, p, (*Tsqlite3rbu)(unsafe.Pointer(p)).FdbMain, __ccgo_ts+33577, libc.VaList(bp+40, zWrite, zTbl1, zNewlist))
}
_rbuObjIterPrepareTmpInsert(tls, p, pIter, zCollist, zRbuRowid)
}
/* Create the SELECT statement to read keys from data_xxx */
if (*Tsqlite3rbu)(unsafe.Pointer(p)).Frc == SQLITE_OK {
zRbuRowid1 = __ccgo_ts + 1702
zStart1 = uintptr(0)
zOrder = uintptr(0)
if bRbuRowid != 0 {
if (*Tsqlite3rbu)(unsafe.Pointer(p)).FzTarget == uintptr(0) {
v1 = __ccgo_ts + 33676
} else {
v1 = __ccgo_ts + 33686
}
zRbuRowid1 = v1
}
if (*Tsqlite3rbu)(unsafe.Pointer(p)).FzTarget == uintptr(0) {
if nOffset != 0 {
zStart1 = _rbuVacuumTableStart(tls, p, pIter, bRbuRowid, zWrite)
if zStart1 != 0 {
Xsqlite3_free(tls, zLimit)
zLimit = uintptr(0)
}
}
if bRbuRowid != 0 {
zOrder = _rbuMPrintf(tls, p, __ccgo_ts+31733, 0)
} else {
zOrder = _rbuObjIterGetPkList(tls, p, pIter, __ccgo_ts+1702, __ccgo_ts+16562, __ccgo_ts+1702)
}
}
if (*Tsqlite3rbu)(unsafe.Pointer(p)).Frc == SQLITE_OK {
if (*Tsqlite3rbu)(unsafe.Pointer(p)).FzTarget == uintptr(0) {
v1 = __ccgo_ts + 33697
} else {
v1 = __ccgo_ts + 1702
}
if zStart1 != 0 {
v2 = zStart1
} else {
v2 = __ccgo_ts + 1702
}
if zOrder != 0 {
v3 = __ccgo_ts + 25245
} else {
v3 = __ccgo_ts + 1702
}
(*Tsqlite3rbu)(unsafe.Pointer(p)).Frc = _prepareFreeAndCollectError(tls, (*Tsqlite3rbu)(unsafe.Pointer(p)).FdbRbu, pIter+128, pz, Xsqlite3_mprintf(tls, __ccgo_ts+33703, libc.VaList(bp+40, zCollist, v1, zRbuRowid1, (*TRbuObjIter)(unsafe.Pointer(pIter)).FzDataTbl, v2, v3, zOrder, zLimit)))
}
Xsqlite3_free(tls, zStart1)
Xsqlite3_free(tls, zOrder)
}
Xsqlite3_free(tls, zWhere1)
Xsqlite3_free(tls, zOldlist)
Xsqlite3_free(tls, zNewlist)
Xsqlite3_free(tls, zBindings)
}
Xsqlite3_free(tls, zCollist)
Xsqlite3_free(tls, zLimit)
}
return (*Tsqlite3rbu)(unsafe.Pointer(p)).Frc
}
// C documentation
//
// /*
// ** Prepare a statement used to insert rows into the "rbu_tmp_xxx" table.
// ** Specifically a statement of the form:
// **
// ** INSERT INTO rbu_tmp_xxx VALUES(?, ?, ? ...);
// **
// ** The number of bound variables is equal to the number of columns in
// ** the target table, plus one (for the rbu_control column), plus one more
// ** (for the rbu_rowid column) if the target table is an implicit IPK or
// ** virtual table.
// */
func _rbuObjIterPrepareTmpInsert(tls *libc.TLS, p uintptr, pIter uintptr, zCollist uintptr, zRbuRowid uintptr) {
bp := tls.Alloc(48)
defer tls.Free(48)
var bRbuRowid int32
var zBind uintptr
_, _ = bRbuRowid, zBind
bRbuRowid = libc.BoolInt32((*TRbuObjIter)(unsafe.Pointer(pIter)).FeType == int32(RBU_PK_EXTERNAL) || (*TRbuObjIter)(unsafe.Pointer(pIter)).FeType == int32(RBU_PK_NONE))
zBind = _rbuObjIterGetBindlist(tls, p, (*TRbuObjIter)(unsafe.Pointer(pIter)).FnTblCol+int32(1)+bRbuRowid)
if zBind != 0 {
(*Tsqlite3rbu)(unsafe.Pointer(p)).Frc = _prepareFreeAndCollectError(tls, (*Tsqlite3rbu)(unsafe.Pointer(p)).FdbRbu, pIter+152, p+64, Xsqlite3_mprintf(tls, __ccgo_ts+32521, libc.VaList(bp+8, p+48, (*TRbuObjIter)(unsafe.Pointer(pIter)).FzDataTbl, zCollist, zRbuRowid, zBind)))
}
}
// 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+7164, 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+7164)
(*Tsqlite3rbu)(unsafe.Pointer(p)).FzState = _rbuMPrintf(tls, p, __ccgo_ts+33811, 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+33839, libc.VaList(bp+8, (*Tsqlite3rbu)(unsafe.Pointer(p)).FzState))
libc.X__builtin___memcpy_chk(tls, p+48, __ccgo_ts+3565, uint64(4), ^t__predefined_size_t(0))
} else {
libc.X__builtin___memcpy_chk(tls, p+48, __ccgo_ts+7164, uint64(4), ^t__predefined_size_t(0))
}
/* If it has not already been created, create the rbu_state table */
_rbuMPrintfExec(tls, p, (*Tsqlite3rbu)(unsafe.Pointer(p)).FdbRbu, __ccgo_ts+33857, libc.VaList(bp+8, p+48))
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+7164, 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+33923, 0)
} else {
zExtra = uintptr(0)
if libc.Xstrlen(tls, (*Tsqlite3rbu)(unsafe.Pointer(p)).FzRbu) >= uint64(5) && 0 == libc.Xmemcmp(tls, __ccgo_ts+26509, (*Tsqlite3rbu)(unsafe.Pointer(p)).FzRbu, uint64(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 + 33955
}
if zExtra == uintptr(0) {
v2 = __ccgo_ts + 1702
} else {
v2 = zExtra
}
zTarget = Xsqlite3_mprintf(tls, __ccgo_ts+33957, libc.VaList(bp+8, Xsqlite3_db_filename(tls, (*Tsqlite3rbu)(unsafe.Pointer(p)).FdbRbu, __ccgo_ts+7164), 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+33989, -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+34004, 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+34021, -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+7164, int32(SQLITE_FCNTL_RBU), p)
}
_rbuMPrintfExec(tls, p, (*Tsqlite3rbu)(unsafe.Pointer(p)).FdbMain, __ccgo_ts+34037, 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+7164, 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+34065, 0)
}
}
// C documentation
//
// /*
// ** Update the contents of the rbu_state table within the rbu database. The
// ** value stored in the RBU_STATE_STAGE column is eStage. All other values
// ** are determined by inspecting the rbu handle passed as the first argument.
// */
func _rbuSaveState(tls *libc.TLS, p uintptr, eStage int32) {
bp := tls.Alloc(192)
defer tls.Free(192)
var pFd, v1 uintptr
var rc int32
var _ /* pInsert at bp+0 */ uintptr
_, _, _ = pFd, rc, v1
if (*Tsqlite3rbu)(unsafe.Pointer(p)).Frc == SQLITE_OK || (*Tsqlite3rbu)(unsafe.Pointer(p)).Frc == int32(SQLITE_DONE) {
**(**uintptr)(__ccgo_up(bp)) = uintptr(0)
if (*Tsqlite3rbu)(unsafe.Pointer(p)).FzTarget == uintptr(0) {
v1 = (*Tsqlite3rbu)(unsafe.Pointer(p)).FpRbuFd
} else {
v1 = (*Tsqlite3rbu)(unsafe.Pointer(p)).FpTargetFd
}
pFd = v1
rc = _prepareFreeAndCollectError(tls, (*Tsqlite3rbu)(unsafe.Pointer(p)).FdbRbu, bp, p+64, Xsqlite3_mprintf(tls, __ccgo_ts+34206, libc.VaList(bp+16, p+48, int32(RBU_STATE_STAGE), eStage, int32(RBU_STATE_TBL), (*Tsqlite3rbu)(unsafe.Pointer(p)).Fobjiter.FzTbl, int32(RBU_STATE_IDX), (*Tsqlite3rbu)(unsafe.Pointer(p)).Fobjiter.FzIdx, int32(RBU_STATE_ROW), (*Tsqlite3rbu)(unsafe.Pointer(p)).FnStep, int32(RBU_STATE_PROGRESS), (*Tsqlite3rbu)(unsafe.Pointer(p)).FnProgress, int32(RBU_STATE_CKPT), (*Tsqlite3rbu)(unsafe.Pointer(p)).FiWalCksum, int32(RBU_STATE_COOKIE), libc.Int64FromUint32((*Trbu_file)(unsafe.Pointer(pFd)).FiCookie), int32(RBU_STATE_OALSZ), (*Tsqlite3rbu)(unsafe.Pointer(p)).FiOalSz, int32(RBU_STATE_PHASEONESTEP), (*Tsqlite3rbu)(unsafe.Pointer(p)).FnPhaseOneStep, int32(RBU_STATE_DATATBL), (*Tsqlite3rbu)(unsafe.Pointer(p)).Fobjiter.FzDataTbl)))
if rc == SQLITE_OK {
Xsqlite3_step(tls, **(**uintptr)(__ccgo_up(bp)))
rc = Xsqlite3_finalize(tls, **(**uintptr)(__ccgo_up(bp)))
}
if rc != SQLITE_OK {
(*Tsqlite3rbu)(unsafe.Pointer(p)).Frc = rc
}
}
}
// C documentation
//
// /*
// ** This function is called as part of initializing or reinitializing an
// ** incremental checkpoint.
// **
// ** It populates the sqlite3rbu.aFrame[] array with the set of
// ** (wal frame -> db page) copy operations required to checkpoint the
// ** current wal file, and obtains the set of shm locks required to safely
// ** perform the copy operations directly on the file-system.
// **
// ** If argument pState is not NULL, then the incremental checkpoint is
// ** being resumed. In this case, if the checksum of the wal-index-header
// ** following recovery is not the same as the checksum saved in the RbuState
// ** object, then the rbu handle is set to DONE state. This occurs if some
// ** other client appends a transaction to the wal file in the middle of
// ** an incremental checkpoint.
// */
func _rbuSetupCheckpoint(tls *libc.TLS, p uintptr, pState uintptr) {
var nSectorSize, rc2, v1 int32
var pDb, pWal uintptr
_, _, _, _, _ = nSectorSize, pDb, pWal, rc2, v1
/* If pState is NULL, then the wal file may not have been opened and
** recovered. Running a read-statement here to ensure that doing so
** does not interfere with the "capture" process below. */
if pState == uintptr(0) {
(*Tsqlite3rbu)(unsafe.Pointer(p)).FeStage = 0
if (*Tsqlite3rbu)(unsafe.Pointer(p)).Frc == SQLITE_OK {
(*Tsqlite3rbu)(unsafe.Pointer(p)).Frc = Xsqlite3_exec(tls, (*Tsqlite3rbu)(unsafe.Pointer(p)).FdbMain, __ccgo_ts+34037, uintptr(0), uintptr(0), uintptr(0))
}
}
/* Assuming no error has occurred, run a "restart" checkpoint with the
** sqlite3rbu.eStage variable set to CAPTURE. This turns on the following
** special behaviour in the rbu VFS:
**
** * If the exclusive shm WRITER or READ0 lock cannot be obtained,
** the checkpoint fails with SQLITE_BUSY (normally SQLite would
** proceed with running a passive checkpoint instead of failing).
**
** * Attempts to read from the *-wal file or write to the database file
** do not perform any IO. Instead, the frame/page combinations that
** would be read/written are recorded in the sqlite3rbu.aFrame[]
** array.
**
** * Calls to xShmLock(UNLOCK) to release the exclusive shm WRITER,
** READ0 and CHECKPOINT locks taken as part of the checkpoint are
** no-ops. These locks will not be released until the connection
** is closed.
**
** * Attempting to xSync() the database file causes an SQLITE_NOTICE
** error.
**
** As a result, unless an error (i.e. OOM or SQLITE_BUSY) occurs, the
** checkpoint below fails with SQLITE_NOTICE, and leaves the aFrame[]
** array populated with a set of (frame -> page) mappings. Because the
** WRITER, CHECKPOINT and READ0 locks are still held, it is safe to copy
** data from the wal file into the database file according to the
** contents of aFrame[].
*/
if (*Tsqlite3rbu)(unsafe.Pointer(p)).Frc == SQLITE_OK {
(*Tsqlite3rbu)(unsafe.Pointer(p)).FeStage = int32(RBU_STAGE_CAPTURE)
rc2 = Xsqlite3_exec(tls, (*Tsqlite3rbu)(unsafe.Pointer(p)).FdbMain, __ccgo_ts+34083, uintptr(0), uintptr(0), uintptr(0))
if rc2 != int32(SQLITE_NOTICE) {
(*Tsqlite3rbu)(unsafe.Pointer(p)).Frc = rc2
}
}
if (*Tsqlite3rbu)(unsafe.Pointer(p)).Frc == SQLITE_OK && (*Tsqlite3rbu)(unsafe.Pointer(p)).FnFrame > 0 {
(*Tsqlite3rbu)(unsafe.Pointer(p)).FeStage = int32(RBU_STAGE_CKPT)
if pState != 0 {
v1 = (*TRbuState)(unsafe.Pointer(pState)).FnRow
} else {
v1 = 0
}
(*Tsqlite3rbu)(unsafe.Pointer(p)).FnStep = v1
(*Tsqlite3rbu)(unsafe.Pointer(p)).FaBuf = _rbuMalloc(tls, p, int64((*Tsqlite3rbu)(unsafe.Pointer(p)).Fpgsz))
(*Tsqlite3rbu)(unsafe.Pointer(p)).FiWalCksum = _rbuShmChecksum(tls, p)
}
if (*Tsqlite3rbu)(unsafe.Pointer(p)).Frc == SQLITE_OK {
if (*Tsqlite3rbu)(unsafe.Pointer(p)).FnFrame == 0 || pState != 0 && (*TRbuState)(unsafe.Pointer(pState)).FiWalCksum != (*Tsqlite3rbu)(unsafe.Pointer(p)).FiWalCksum {
(*Tsqlite3rbu)(unsafe.Pointer(p)).Frc = int32(SQLITE_DONE)
(*Tsqlite3rbu)(unsafe.Pointer(p)).FeStage = int32(RBU_STAGE_DONE)
} else {
pDb = (*Trbu_file)(unsafe.Pointer((*Tsqlite3rbu)(unsafe.Pointer(p)).FpTargetFd)).FpReal
pWal = (*Trbu_file)(unsafe.Pointer((*Trbu_file)(unsafe.Pointer((*Tsqlite3rbu)(unsafe.Pointer(p)).FpTargetFd)).FpWalFd)).FpReal
nSectorSize = (*(*func(*libc.TLS, uintptr) int32)(unsafe.Pointer(&struct{ uintptr }{(*Tsqlite3_io_methods)(unsafe.Pointer((*Tsqlite3_file)(unsafe.Pointer(pDb)).FpMethods)).FxSectorSize})))(tls, pDb)
if nSectorSize > (*Tsqlite3rbu)(unsafe.Pointer(p)).Fpgsz {
(*Tsqlite3rbu)(unsafe.Pointer(p)).FnPagePerSector = nSectorSize / (*Tsqlite3rbu)(unsafe.Pointer(p)).Fpgsz
} else {
(*Tsqlite3rbu)(unsafe.Pointer(p)).FnPagePerSector = int32(1)
}
/* Call xSync() on the wal file. This causes SQLite to sync the
** directory in which the target database and the wal file reside, in
** case it has not been synced since the rename() call in
** rbuMoveOalFile(). */
(*Tsqlite3rbu)(unsafe.Pointer(p)).Frc = (*(*func(*libc.TLS, uintptr, int32) int32)(unsafe.Pointer(&struct{ uintptr }{(*Tsqlite3_io_methods)(unsafe.Pointer((*Tsqlite3_file)(unsafe.Pointer(pWal)).FpMethods)).FxSync})))(tls, pWal, int32(SQLITE_SYNC_NORMAL))
}
}
}
// C documentation
//
// /*
// ** This function is called as part of sqlite3rbu_open() when initializing
// ** an rbu handle in OAL stage. If the rbu update has not started (i.e.
// ** the rbu_state table was empty) it is a no-op. Otherwise, it arranges
// ** things so that the next call to sqlite3rbu_step() continues on from
// ** where the previous rbu handle left off.
// **
// ** If an error occurs, an error code and error message are left in the
// ** rbu handle passed as the first argument.
// */
func _rbuSetupOal(tls *libc.TLS, p uintptr, pState uintptr) {
var pIter uintptr
var rc int32
_, _ = pIter, rc
if (*TRbuState)(unsafe.Pointer(pState)).FzTbl != 0 {
pIter = p + 88
rc = SQLITE_OK
for rc == SQLITE_OK && (*TRbuObjIter)(unsafe.Pointer(pIter)).FzTbl != 0 && ((*TRbuObjIter)(unsafe.Pointer(pIter)).FbCleanup != 0 || _rbuStrCompare(tls, (*TRbuObjIter)(unsafe.Pointer(pIter)).FzIdx, (*TRbuState)(unsafe.Pointer(pState)).FzIdx) != 0 || (*TRbuState)(unsafe.Pointer(pState)).FzDataTbl == uintptr(0) && _rbuStrCompare(tls, (*TRbuObjIter)(unsafe.Pointer(pIter)).FzTbl, (*TRbuState)(unsafe.Pointer(pState)).FzTbl) != 0 || (*TRbuState)(unsafe.Pointer(pState)).FzDataTbl != 0 && _rbuStrCompare(tls, (*TRbuObjIter)(unsafe.Pointer(pIter)).FzDataTbl, (*TRbuState)(unsafe.Pointer(pState)).FzDataTbl) != 0) {
rc = _rbuObjIterNext(tls, p, pIter)
}
if rc == SQLITE_OK && !((*TRbuObjIter)(unsafe.Pointer(pIter)).FzTbl != 0) {
rc = int32(SQLITE_ERROR)
(*Tsqlite3rbu)(unsafe.Pointer(p)).FzErrmsg = Xsqlite3_mprintf(tls, __ccgo_ts+34696, 0)
}
if rc == SQLITE_OK {
(*Tsqlite3rbu)(unsafe.Pointer(p)).FnStep = (*TRbuState)(unsafe.Pointer(pState)).FnRow
rc = _rbuObjIterPrepareAll(tls, p, p+88, (*Tsqlite3rbu)(unsafe.Pointer(p)).FnStep)
}
(*Tsqlite3rbu)(unsafe.Pointer(p)).Frc = rc
}
}
// C documentation
//
// /*
// ** Argument eType must be one of RBU_INSERT, RBU_DELETE, RBU_IDX_INSERT or
// ** RBU_IDX_DELETE. This function performs the work of a single
// ** sqlite3rbu_step() call for the type of operation specified by eType.
// */
func _rbuStepOneOp(tls *libc.TLS, p uintptr, eType int32) {
var i int32
var pIter, pVal, pWriter uintptr
_, _, _, _ = i, pIter, pVal, pWriter
pIter = p + 88
/* If this is a delete, decrement nPhaseOneStep by nIndex. If the DELETE
** statement below does actually delete a row, nPhaseOneStep will be
** incremented by the same amount when SQL function rbu_tmp_insert()
** is invoked by the trigger. */
if eType == int32(RBU_DELETE) {
**(**Ti64)(__ccgo_up(p + 312)) -= int64((*Tsqlite3rbu)(unsafe.Pointer(p)).Fobjiter.FnIndex)
}
if eType == int32(RBU_IDX_DELETE) || eType == int32(RBU_DELETE) {
pWriter = (*TRbuObjIter)(unsafe.Pointer(pIter)).FpDelete
} else {
pWriter = (*TRbuObjIter)(unsafe.Pointer(pIter)).FpInsert
}
i = 0
for {
if !(i < (*TRbuObjIter)(unsafe.Pointer(pIter)).FnCol) {
break
}
/* If this is an INSERT into a table b-tree and the table has an
** explicit INTEGER PRIMARY KEY, check that this is not an attempt
** to write a NULL into the IPK column. That is not permitted. */
if eType == int32(RBU_INSERT) && (*TRbuObjIter)(unsafe.Pointer(pIter)).FzIdx == uintptr(0) && (*TRbuObjIter)(unsafe.Pointer(pIter)).FeType == int32(RBU_PK_IPK) && **(**Tu8)(__ccgo_up((*TRbuObjIter)(unsafe.Pointer(pIter)).FabTblPk + uintptr(i))) != 0 && Xsqlite3_column_type(tls, (*TRbuObjIter)(unsafe.Pointer(pIter)).FpSelect, i) == int32(SQLITE_NULL) {
(*Tsqlite3rbu)(unsafe.Pointer(p)).Frc = int32(SQLITE_MISMATCH)
(*Tsqlite3rbu)(unsafe.Pointer(p)).FzErrmsg = Xsqlite3_mprintf(tls, __ccgo_ts+26066, 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 , rbu_control, rbu_rowid FROM ....
**
** Hence column_value(pIter->nCol+1).
*/
pVal = Xsqlite3_column_value(tls, (*TRbuObjIter)(unsafe.Pointer(pIter)).FpSelect, (*TRbuObjIter)(unsafe.Pointer(pIter)).FnCol+int32(1))
(*Tsqlite3rbu)(unsafe.Pointer(p)).Frc = Xsqlite3_bind_value(tls, pWriter, (*TRbuObjIter)(unsafe.Pointer(pIter)).FnCol+int32(1), pVal)
}
}
if (*Tsqlite3rbu)(unsafe.Pointer(p)).Frc == SQLITE_OK {
Xsqlite3_step(tls, pWriter)
(*Tsqlite3rbu)(unsafe.Pointer(p)).Frc = _resetAndCollectError(tls, pWriter, p+64)
}
}
// C documentation
//
// /*
// ** The first argument must be a nul-terminated string. This function
// ** returns a copy of the string in memory obtained from sqlite3_malloc().
// ** It is the responsibility of the caller to eventually free this memory
// ** using sqlite3_free().
// **
// ** If an OOM condition is encountered when attempting to allocate memory,
// ** output variable (*pRc) is set to SQLITE_NOMEM before returning. Otherwise,
// ** if the allocation succeeds, (*pRc) is left unchanged.
// */
func _rbuStrndup(tls *libc.TLS, zStr uintptr, pRc uintptr) (r uintptr) {
var nCopy Tsize_t
var zRet uintptr
_, _ = nCopy, zRet
zRet = uintptr(0)
if **(**int32)(__ccgo_up(pRc)) == SQLITE_OK {
if zStr != 0 {
nCopy = libc.Xstrlen(tls, zStr) + uint64(1)
zRet = Xsqlite3_malloc64(tls, nCopy)
if zRet != 0 {
libc.X__builtin___memcpy_chk(tls, zRet, zStr, nCopy, ^t__predefined_size_t(0))
} else {
**(**int32)(__ccgo_up(pRc)) = int32(SQLITE_NOMEM)
}
}
}
return zRet
}
// C documentation
//
// /* Determine the type of a table.
// **
// ** peType is of type (int*), a pointer to an output parameter of type
// ** (int). This call sets the output parameter as follows, depending
// ** on the type of the table specified by parameters dbName and zTbl.
// **
// ** RBU_PK_NOTABLE: No such table.
// ** RBU_PK_NONE: Table has an implicit rowid.
// ** RBU_PK_IPK: Table has an explicit IPK column.
// ** RBU_PK_EXTERNAL: Table has an external PK index.
// ** RBU_PK_WITHOUT_ROWID: Table is WITHOUT ROWID.
// ** RBU_PK_VTAB: Table is a virtual table.
// **
// ** Argument *piPk is also of type (int*), and also points to an output
// ** parameter. Unless the table has an external primary key index
// ** (i.e. unless *peType is set to 3), then *piPk is set to zero. Or,
// ** if the table does have an external primary key index, then *piPk
// ** is set to the root page number of the primary key index before
// ** returning.
// **
// ** ALGORITHM:
// **
// ** if( no entry exists in sqlite_schema ){
// ** return RBU_PK_NOTABLE
// ** }else if( sql for the entry starts with "CREATE VIRTUAL" ){
// ** return RBU_PK_VTAB
// ** }else if( "PRAGMA index_list()" for the table contains a "pk" index ){
// ** if( the index that is the pk exists in sqlite_schema ){
// ** *piPK = rootpage of that index.
// ** return RBU_PK_EXTERNAL
// ** }else{
// ** return RBU_PK_WITHOUT_ROWID
// ** }
// ** }else if( "PRAGMA table_info()" lists one or more "pk" columns ){
// ** return RBU_PK_IPK
// ** }else{
// ** return RBU_PK_NONE
// ** }
// */
func _rbuTableType(tls *libc.TLS, p uintptr, zTab uintptr, peType uintptr, piTnum uintptr, piPk uintptr) {
bp := tls.Alloc(48)
defer tls.Free(48)
var i uint32
var zIdx, zOrig uintptr
var _ /* aStmt at bp+0 */ [4]uintptr
_, _, _ = i, zIdx, zOrig
/*
** 0) SELECT count(*) FROM sqlite_schema where name=%Q AND IsVirtual(%Q)
** 1) PRAGMA index_list = ?
** 2) SELECT count(*) FROM sqlite_schema where name=%Q
** 3) PRAGMA table_info = ?
*/
**(**[4]uintptr)(__ccgo_up(bp)) = [4]uintptr{}
**(**int32)(__ccgo_up(peType)) = RBU_PK_NOTABLE
**(**int32)(__ccgo_up(piPk)) = 0
(*Tsqlite3rbu)(unsafe.Pointer(p)).Frc = _prepareFreeAndCollectError(tls, (*Tsqlite3rbu)(unsafe.Pointer(p)).FdbMain, bp, p+64, Xsqlite3_mprintf(tls, __ccgo_ts+31170, libc.VaList(bp+40, zTab)))
if (*Tsqlite3rbu)(unsafe.Pointer(p)).Frc != SQLITE_OK || Xsqlite3_step(tls, (**(**[4]uintptr)(__ccgo_up(bp)))[0]) != int32(SQLITE_ROW) {
/* Either an error, or no such table. */
goto rbuTableType_end
}
if Xsqlite3_column_int(tls, (**(**[4]uintptr)(__ccgo_up(bp)))[0], 0) != 0 {
**(**int32)(__ccgo_up(peType)) = int32(RBU_PK_VTAB) /* virtual table */
goto rbuTableType_end
}
**(**int32)(__ccgo_up(piTnum)) = Xsqlite3_column_int(tls, (**(**[4]uintptr)(__ccgo_up(bp)))[0], int32(1))
(*Tsqlite3rbu)(unsafe.Pointer(p)).Frc = _prepareFreeAndCollectError(tls, (*Tsqlite3rbu)(unsafe.Pointer(p)).FdbMain, bp+1*8, p+64, Xsqlite3_mprintf(tls, __ccgo_ts+31289, libc.VaList(bp+40, zTab)))
if (*Tsqlite3rbu)(unsafe.Pointer(p)).Frc != 0 {
goto rbuTableType_end
}
for Xsqlite3_step(tls, (**(**[4]uintptr)(__ccgo_up(bp)))[int32(1)]) == int32(SQLITE_ROW) {
zOrig = Xsqlite3_column_text(tls, (**(**[4]uintptr)(__ccgo_up(bp)))[int32(1)], int32(3))
zIdx = Xsqlite3_column_text(tls, (**(**[4]uintptr)(__ccgo_up(bp)))[int32(1)], int32(1))
if zOrig != 0 && zIdx != 0 && libc.Int32FromUint8(**(**Tu8)(__ccgo_up(zOrig))) == int32('p') {
(*Tsqlite3rbu)(unsafe.Pointer(p)).Frc = _prepareFreeAndCollectError(tls, (*Tsqlite3rbu)(unsafe.Pointer(p)).FdbMain, bp+2*8, p+64, Xsqlite3_mprintf(tls, __ccgo_ts+31310, libc.VaList(bp+40, zIdx)))
if (*Tsqlite3rbu)(unsafe.Pointer(p)).Frc == SQLITE_OK {
if Xsqlite3_step(tls, (**(**[4]uintptr)(__ccgo_up(bp)))[int32(2)]) == int32(SQLITE_ROW) {
**(**int32)(__ccgo_up(piPk)) = Xsqlite3_column_int(tls, (**(**[4]uintptr)(__ccgo_up(bp)))[int32(2)], 0)
**(**int32)(__ccgo_up(peType)) = int32(RBU_PK_EXTERNAL)
} else {
**(**int32)(__ccgo_up(peType)) = int32(RBU_PK_WITHOUT_ROWID)
}
}
goto rbuTableType_end
}
}
(*Tsqlite3rbu)(unsafe.Pointer(p)).Frc = _prepareFreeAndCollectError(tls, (*Tsqlite3rbu)(unsafe.Pointer(p)).FdbMain, bp+3*8, p+64, Xsqlite3_mprintf(tls, __ccgo_ts+31361, libc.VaList(bp+40, zTab)))
if (*Tsqlite3rbu)(unsafe.Pointer(p)).Frc == SQLITE_OK {
for Xsqlite3_step(tls, (**(**[4]uintptr)(__ccgo_up(bp)))[int32(3)]) == int32(SQLITE_ROW) {
if Xsqlite3_column_int(tls, (**(**[4]uintptr)(__ccgo_up(bp)))[int32(3)], int32(5)) > 0 {
**(**int32)(__ccgo_up(peType)) = int32(RBU_PK_IPK) /* explicit IPK column */
goto rbuTableType_end
}
}
**(**int32)(__ccgo_up(peType)) = int32(RBU_PK_NONE)
}
goto rbuTableType_end
rbuTableType_end:
;
i = uint32(0)
for {
if !(uint64(i) < libc.Uint64FromInt64(32)/libc.Uint64FromInt64(8)) {
break
}
_rbuFinalize(tls, p, (**(**[4]uintptr)(__ccgo_up(bp)))[i])
goto _1
_1:
;
i = i + 1
}
}
// C documentation
//
// /*
// ** 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]_
// **
// ** where is any sequence of 1 or more characters, 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*8))) {
Xsqlite3_result_text(tls, pCtx, zIn, -int32(1), libc.UintptrFromInt32(0))
}
} else {
if libc.Xstrlen(tls, zIn) > uint64(4) && libc.Xmemcmp(tls, __ccgo_ts+27799, zIn, uint64(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+8 */ 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+64, Xsqlite3_mprintf(tls, __ccgo_ts+31410, libc.VaList(bp+24, (*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)*8))
} else {
zCol = __ccgo_ts + 31733
}
} else {
zCol = **(**uintptr)(__ccgo_up((*TRbuObjIter)(unsafe.Pointer(pIter)).FazTblCol + uintptr(iCid)*8))
}
zLhs = _rbuMPrintf(tls, p, __ccgo_ts+31741, libc.VaList(bp+24, zLhs, zSep, zCol, zCollate))
zOrder = _rbuMPrintf(tls, p, __ccgo_ts+31762, libc.VaList(bp+24, zOrder, zSep, iCol, zCol, zCollate))
zSelect = _rbuMPrintf(tls, p, __ccgo_ts+31798, libc.VaList(bp+24, zSelect, zSep, iCol, zCol))
zSep = __ccgo_ts + 16562
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 + 8)) = uintptr(0)
(*Tsqlite3rbu)(unsafe.Pointer(p)).Frc = _prepareFreeAndCollectError(tls, (*Tsqlite3rbu)(unsafe.Pointer(p)).FdbMain, bp+8, p+64, Xsqlite3_mprintf(tls, __ccgo_ts+31825, libc.VaList(bp+24, 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 + 8))) {
zSep = __ccgo_ts + 1702
iCol = 0
for {
if !(iCol < (*TRbuObjIter)(unsafe.Pointer(pIter)).FnCol) {
break
}
zQuoted = Xsqlite3_column_text(tls, **(**uintptr)(__ccgo_up(bp + 8)), 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+31873, libc.VaList(bp+24, zVector, zSep, zQuoted))
zSep = __ccgo_ts + 16562
goto _2
_2:
;
iCol = iCol + 1
}
if !(bFailed != 0) {
zRet = _rbuMPrintf(tls, p, __ccgo_ts+31880, libc.VaList(bp+24, zLhs, zVector))
}
}
_rbuFinalize(tls, p, **(**uintptr)(__ccgo_up(bp + 8)))
}
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
//
// /*
// ** This function is called as part of restarting an RBU vacuum within
// ** stage 1 of the process (while the *-oal file is being built) while
// ** updating a table (not an index). The table may be a rowid table or
// ** a WITHOUT ROWID table. It queries the target database to find the
// ** largest key that has already been written to the target table and
// ** constructs a WHERE clause that can be used to extract the remaining
// ** rows from the source table. For a rowid table, the WHERE clause
// ** is of the form:
// **
// ** "WHERE _rowid_ > ?"
// **
// ** and for WITHOUT ROWID tables:
// **
// ** "WHERE (key1, key2) > (?, ?)"
// **
// ** Instead of "?" placeholders, the actual WHERE clauses created by
// ** this function contain literal SQL values.
// */
func _rbuVacuumTableStart(tls *libc.TLS, p uintptr, pIter uintptr, bRowid int32, zWrite uintptr) (r uintptr) {
bp := tls.Alloc(48)
defer tls.Free(48)
var iMax Tsqlite3_int64
var zList, zOrder, zRet, zSelect, zVal uintptr
var _ /* pMax at bp+0 */ uintptr
_, _, _, _, _, _ = iMax, zList, zOrder, zRet, zSelect, zVal
**(**uintptr)(__ccgo_up(bp)) = uintptr(0)
zRet = uintptr(0)
if bRowid != 0 {
(*Tsqlite3rbu)(unsafe.Pointer(p)).Frc = _prepareFreeAndCollectError(tls, (*Tsqlite3rbu)(unsafe.Pointer(p)).FdbMain, bp, p+64, Xsqlite3_mprintf(tls, __ccgo_ts+31595, libc.VaList(bp+16, zWrite, (*TRbuObjIter)(unsafe.Pointer(pIter)).FzTbl)))
if (*Tsqlite3rbu)(unsafe.Pointer(p)).Frc == SQLITE_OK && int32(SQLITE_ROW) == Xsqlite3_step(tls, **(**uintptr)(__ccgo_up(bp))) {
iMax = Xsqlite3_column_int64(tls, **(**uintptr)(__ccgo_up(bp)), 0)
zRet = _rbuMPrintf(tls, p, __ccgo_ts+31627, libc.VaList(bp+16, iMax))
}
_rbuFinalize(tls, p, **(**uintptr)(__ccgo_up(bp)))
} else {
zOrder = _rbuObjIterGetPkList(tls, p, pIter, __ccgo_ts+1702, __ccgo_ts+16562, __ccgo_ts+31650)
zSelect = _rbuObjIterGetPkList(tls, p, pIter, __ccgo_ts+31656, __ccgo_ts+31663, __ccgo_ts+5605)
zList = _rbuObjIterGetPkList(tls, p, pIter, __ccgo_ts+1702, __ccgo_ts+16562, __ccgo_ts+1702)
if (*Tsqlite3rbu)(unsafe.Pointer(p)).Frc == SQLITE_OK {
(*Tsqlite3rbu)(unsafe.Pointer(p)).Frc = _prepareFreeAndCollectError(tls, (*Tsqlite3rbu)(unsafe.Pointer(p)).FdbMain, bp, p+64, Xsqlite3_mprintf(tls, __ccgo_ts+31671, libc.VaList(bp+16, zSelect, zWrite, (*TRbuObjIter)(unsafe.Pointer(pIter)).FzTbl, zOrder)))
if (*Tsqlite3rbu)(unsafe.Pointer(p)).Frc == SQLITE_OK && int32(SQLITE_ROW) == Xsqlite3_step(tls, **(**uintptr)(__ccgo_up(bp))) {
zVal = Xsqlite3_column_text(tls, **(**uintptr)(__ccgo_up(bp)), 0)
zRet = _rbuMPrintf(tls, p, __ccgo_ts+31713, libc.VaList(bp+16, zList, zVal))
}
_rbuFinalize(tls, p, **(**uintptr)(__ccgo_up(bp)))
}
Xsqlite3_free(tls, zOrder)
Xsqlite3_free(tls, zSelect)
Xsqlite3_free(tls, zList)
}
return zRet
}
// C documentation
//
// /*
// ** File control method. For custom operations on an rbuVfs-file.
// */
func _rbuVfsFileControl(tls *libc.TLS, pFile uintptr, op int32, pArg uintptr) (r int32) {
bp := tls.Alloc(32)
defer tls.Free(32)
var p, pRbu, pRbu1, pRbuVfs, xControl, zIn, zOut uintptr
var rc int32
var _ /* dummy at bp+0 */ uintptr
_, _, _, _, _, _, _, _ = p, pRbu, pRbu1, pRbuVfs, rc, xControl, zIn, zOut
p = pFile
xControl = (*Tsqlite3_io_methods)(unsafe.Pointer((*Tsqlite3_file)(unsafe.Pointer((*Trbu_file)(unsafe.Pointer(p)).FpReal)).FpMethods)).FxFileControl
if op == int32(SQLITE_FCNTL_RBU) {
pRbu = pArg
/* First try to find another RBU vfs lower down in the vfs stack. If
** one is found, this vfs will operate in pass-through mode. The lower
** level vfs will do the special RBU handling. */
rc = (*(*func(*libc.TLS, uintptr, int32, uintptr) int32)(unsafe.Pointer(&struct{ uintptr }{xControl})))(tls, (*Trbu_file)(unsafe.Pointer(p)).FpReal, op, pArg)
if rc == int32(SQLITE_NOTFOUND) {
/* Now search for a zipvfs instance lower down in the VFS stack. If
** one is found, this is an error. */
**(**uintptr)(__ccgo_up(bp)) = uintptr(0)
rc = (*(*func(*libc.TLS, uintptr, int32, uintptr) int32)(unsafe.Pointer(&struct{ uintptr }{xControl})))(tls, (*Trbu_file)(unsafe.Pointer(p)).FpReal, int32(SQLITE_FCNTL_ZIPVFS), bp)
if rc == SQLITE_OK {
rc = int32(SQLITE_ERROR)
(*Tsqlite3rbu)(unsafe.Pointer(pRbu)).FzErrmsg = Xsqlite3_mprintf(tls, __ccgo_ts+35102, 0)
} else {
if rc == int32(SQLITE_NOTFOUND) {
(*Tsqlite3rbu)(unsafe.Pointer(pRbu)).FpTargetFd = p
(*Trbu_file)(unsafe.Pointer(p)).FpRbu = pRbu
_rbuMainlistAdd(tls, p)
if (*Trbu_file)(unsafe.Pointer(p)).FpWalFd != 0 {
(*Trbu_file)(unsafe.Pointer((*Trbu_file)(unsafe.Pointer(p)).FpWalFd)).FpRbu = pRbu
}
rc = SQLITE_OK
}
}
}
return rc
} else {
if op == int32(SQLITE_FCNTL_RBUCNT) {
pRbu1 = pArg
(*Tsqlite3rbu)(unsafe.Pointer(pRbu1)).FnRbu = (*Tsqlite3rbu)(unsafe.Pointer(pRbu1)).FnRbu + 1
(*Tsqlite3rbu)(unsafe.Pointer(pRbu1)).FpRbuFd = p
(*Trbu_file)(unsafe.Pointer(p)).FbNolock = uint8(1)
}
}
rc = (*(*func(*libc.TLS, uintptr, int32, uintptr) int32)(unsafe.Pointer(&struct{ uintptr }{xControl})))(tls, (*Trbu_file)(unsafe.Pointer(p)).FpReal, op, pArg)
if rc == SQLITE_OK && op == int32(SQLITE_FCNTL_VFSNAME) {
pRbuVfs = (*Trbu_file)(unsafe.Pointer(p)).FpRbuVfs
zIn = **(**uintptr)(__ccgo_up(pArg))
zOut = Xsqlite3_mprintf(tls, __ccgo_ts+35125, libc.VaList(bp+16, (*Trbu_vfs)(unsafe.Pointer(pRbuVfs)).Fbase.FzName, zIn))
**(**uintptr)(__ccgo_up(pArg)) = zOut
if zOut == uintptr(0) {
rc = int32(SQLITE_NOMEM)
}
}
return rc
}
// C documentation
//
// /*
// ** 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.X__builtin___memset_chk(tls, pFd, 0, uint64(104), ^t__predefined_size_t(0))
(*Trbu_file)(unsafe.Pointer(pFd)).FpReal = pFd + 1*104
(*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+7164)
zOpen = Xsqlite3_filename_wal(tls, zOpen)
}
nOpen = libc.Xstrlen(tls, zOpen)
**(**int8)(__ccgo_up(zOpen + uintptr(nOpen-uint64(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+35136, 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
//
// /*
// ** Read data from an rbuVfs-file.
// */
func _rbuVfsRead(tls *libc.TLS, pFile uintptr, zBuf uintptr, iAmt int32, iOfst Tsqlite_int64) (r int32) {
var aBuf, p, pBuf, pFd, pRbu uintptr
var iRoot Tu32
var rc, v1 int32
_, _, _, _, _, _, _, _ = aBuf, iRoot, p, pBuf, pFd, pRbu, rc, v1
p = pFile
pRbu = (*Trbu_file)(unsafe.Pointer(p)).FpRbu
if pRbu != 0 && (*Tsqlite3rbu)(unsafe.Pointer(pRbu)).FeStage == int32(RBU_STAGE_CAPTURE) {
rc = _rbuCaptureWalRead(tls, (*Trbu_file)(unsafe.Pointer(p)).FpRbu, iOfst, iAmt)
} else {
if pRbu != 0 && (*Tsqlite3rbu)(unsafe.Pointer(pRbu)).FeStage == int32(RBU_STAGE_OAL) && (*Trbu_file)(unsafe.Pointer(p)).FopenFlags&int32(SQLITE_OPEN_WAL) != 0 && iOfst >= (*Tsqlite3rbu)(unsafe.Pointer(pRbu)).FiOalSz {
rc = SQLITE_OK
libc.X__builtin___memset_chk(tls, zBuf, 0, libc.Uint64FromInt32(iAmt), ^t__predefined_size_t(0))
} else {
rc = (*(*func(*libc.TLS, uintptr, uintptr, int32, Tsqlite3_int64) int32)(unsafe.Pointer(&struct{ uintptr }{(*Tsqlite3_io_methods)(unsafe.Pointer((*Tsqlite3_file)(unsafe.Pointer((*Trbu_file)(unsafe.Pointer(p)).FpReal)).FpMethods)).FxRead})))(tls, (*Trbu_file)(unsafe.Pointer(p)).FpReal, zBuf, iAmt, iOfst)
/* If this is being called to read the first page of the target
** database as part of an rbu vacuum operation, synthesize the
** contents of the first page if it does not yet exist. Otherwise,
** SQLite will not check for a *-wal file. */
if pRbu != 0 && (*Tsqlite3rbu)(unsafe.Pointer(pRbu)).FzTarget == uintptr(0) && rc == libc.Int32FromInt32(SQLITE_IOERR)|libc.Int32FromInt32(2)< int32(100) {
libc.X__builtin___memset_chk(tls, aBuf+100, 0, libc.Uint64FromInt32(iAmt-int32(100)), ^t__predefined_size_t(0))
_rbuPutU16(tls, aBuf+105, libc.Uint16FromInt32(iAmt&int32(0xFFFF)))
**(**Tu8)(__ccgo_up(aBuf + 100)) = uint8(0x0D)
}
}
}
}
if rc == SQLITE_OK && iOfst == 0 && (*Trbu_file)(unsafe.Pointer(p)).FopenFlags&int32(SQLITE_OPEN_MAIN_DB) != 0 {
/* These look like magic numbers. But they are stable, as they are part
** of the definition of the SQLite file format, which may not change. */
pBuf = zBuf
(*Trbu_file)(unsafe.Pointer(p)).FiCookie = _rbuGetU32(tls, pBuf+24)
(*Trbu_file)(unsafe.Pointer(p)).FiWriteVer = **(**Tu8)(__ccgo_up(pBuf + 19))
}
}
return rc
}
// C documentation
//
// /*
// ** Obtain a pointer to a mapping of a single 32KiB page of the *-shm file.
// */
func _rbuVfsShmMap(tls *libc.TLS, pFile uintptr, iRegion int32, szRegion int32, isWrite int32, pp uintptr) (r int32) {
var apNew, p, pNew uintptr
var eStage, rc, v1 int32
var nByte Tsqlite3_int64
_, _, _, _, _, _, _ = apNew, eStage, nByte, p, pNew, rc, v1
p = pFile
rc = SQLITE_OK
if (*Trbu_file)(unsafe.Pointer(p)).FpRbu != 0 {
v1 = (*Tsqlite3rbu)(unsafe.Pointer((*Trbu_file)(unsafe.Pointer(p)).FpRbu)).FeStage
} else {
v1 = 0
}
eStage = v1
/* If not in RBU_STAGE_OAL, allow this call to pass through. Or, if this
** rbu is in the RBU_STAGE_OAL state, use heap memory for *-shm space
** instead of a file on disk. */
if eStage == int32(RBU_STAGE_OAL) {
nByte = libc.Int64FromUint64(libc.Uint64FromInt32(iRegion+libc.Int32FromInt32(1)) * uint64(8))
apNew = Xsqlite3_realloc64(tls, (*Trbu_file)(unsafe.Pointer(p)).FapShm, libc.Uint64FromInt64(nByte))
/* This is an RBU connection that uses its own heap memory for the
** pages of the *-shm file. Since no other process can have run
** recovery, the connection must request *-shm pages in order
** from start to finish. */
if apNew == uintptr(0) {
rc = int32(SQLITE_NOMEM)
} else {
libc.X__builtin___memset_chk(tls, apNew+uintptr((*Trbu_file)(unsafe.Pointer(p)).FnShm)*8, 0, uint64(8)*libc.Uint64FromInt32(libc.Int32FromInt32(1)+iRegion-(*Trbu_file)(unsafe.Pointer(p)).FnShm), ^t__predefined_size_t(0))
(*Trbu_file)(unsafe.Pointer(p)).FapShm = apNew
(*Trbu_file)(unsafe.Pointer(p)).FnShm = iRegion + int32(1)
}
if rc == SQLITE_OK {
pNew = Xsqlite3_malloc64(tls, libc.Uint64FromInt32(szRegion))
if pNew == uintptr(0) {
rc = int32(SQLITE_NOMEM)
} else {
libc.X__builtin___memset_chk(tls, pNew, 0, libc.Uint64FromInt32(szRegion), ^t__predefined_size_t(0))
**(**uintptr)(__ccgo_up((*Trbu_file)(unsafe.Pointer(p)).FapShm + uintptr(iRegion)*8)) = pNew
}
}
if rc == SQLITE_OK {
**(**uintptr)(__ccgo_up(pp)) = **(**uintptr)(__ccgo_up((*Trbu_file)(unsafe.Pointer(p)).FapShm + uintptr(iRegion)*8))
} else {
**(**uintptr)(__ccgo_up(pp)) = uintptr(0)
}
} else {
rc = (*(*func(*libc.TLS, uintptr, int32, int32, int32, uintptr) int32)(unsafe.Pointer(&struct{ uintptr }{(*Tsqlite3_io_methods)(unsafe.Pointer((*Tsqlite3_file)(unsafe.Pointer((*Trbu_file)(unsafe.Pointer(p)).FpReal)).FpMethods)).FxShmMap})))(tls, (*Trbu_file)(unsafe.Pointer(p)).FpReal, iRegion, szRegion, isWrite, pp)
}
return rc
}
// C documentation
//
// /*
// ** The iterator currently points to a table (not index) of type
// ** RBU_PK_WITHOUT_ROWID. This function creates the PRIMARY KEY
// ** declaration for the corresponding imposter table. For example,
// ** if the iterator points to a table created as:
// **
// ** CREATE TABLE t1(a, b, c, PRIMARY KEY(b, a DESC)) WITHOUT ROWID
// **
// ** this function returns:
// **
// ** PRIMARY KEY("b", "a" DESC)
// */
func _rbuWithoutRowidPK(tls *libc.TLS, p uintptr, pIter uintptr) (r uintptr) {
bp := tls.Alloc(64)
defer tls.Free(64)
var z, zCol, zDesc, zIdx, zOrig, zSep, v1 uintptr
var _ /* pXInfo at bp+8 */ uintptr
var _ /* pXList at bp+0 */ uintptr
_, _, _, _, _, _, _ = z, zCol, zDesc, zIdx, zOrig, zSep, v1
z = uintptr(0)
if (*Tsqlite3rbu)(unsafe.Pointer(p)).Frc == SQLITE_OK {
zSep = __ccgo_ts + 32230
**(**uintptr)(__ccgo_up(bp)) = uintptr(0) /* PRAGMA index_list = (pIter->zTbl) */
**(**uintptr)(__ccgo_up(bp + 8)) = uintptr(0) /* PRAGMA index_xinfo = */
(*Tsqlite3rbu)(unsafe.Pointer(p)).Frc = _prepareFreeAndCollectError(tls, (*Tsqlite3rbu)(unsafe.Pointer(p)).FdbMain, bp, p+64, Xsqlite3_mprintf(tls, __ccgo_ts+31382, libc.VaList(bp+24, (*TRbuObjIter)(unsafe.Pointer(pIter)).FzTbl)))
for (*Tsqlite3rbu)(unsafe.Pointer(p)).Frc == SQLITE_OK && int32(SQLITE_ROW) == Xsqlite3_step(tls, **(**uintptr)(__ccgo_up(bp))) {
zOrig = Xsqlite3_column_text(tls, **(**uintptr)(__ccgo_up(bp)), int32(3))
if zOrig != 0 && libc.Xstrcmp(tls, zOrig, __ccgo_ts+18202) == 0 {
zIdx = Xsqlite3_column_text(tls, **(**uintptr)(__ccgo_up(bp)), int32(1))
if zIdx != 0 {
(*Tsqlite3rbu)(unsafe.Pointer(p)).Frc = _prepareFreeAndCollectError(tls, (*Tsqlite3rbu)(unsafe.Pointer(p)).FdbMain, bp+8, p+64, Xsqlite3_mprintf(tls, __ccgo_ts+31410, libc.VaList(bp+24, zIdx)))
}
break
}
}
_rbuFinalize(tls, p, **(**uintptr)(__ccgo_up(bp)))
for (*Tsqlite3rbu)(unsafe.Pointer(p)).Frc == SQLITE_OK && int32(SQLITE_ROW) == Xsqlite3_step(tls, **(**uintptr)(__ccgo_up(bp + 8))) {
if Xsqlite3_column_int(tls, **(**uintptr)(__ccgo_up(bp + 8)), int32(5)) != 0 {
/* int iCid = sqlite3_column_int(pXInfo, 0); */
zCol = Xsqlite3_column_text(tls, **(**uintptr)(__ccgo_up(bp + 8)), int32(2))
if Xsqlite3_column_int(tls, **(**uintptr)(__ccgo_up(bp + 8)), int32(3)) != 0 {
v1 = __ccgo_ts + 31650
} else {
v1 = __ccgo_ts + 1702
}
zDesc = v1
z = _rbuMPrintf(tls, p, __ccgo_ts+32243, libc.VaList(bp+24, z, zSep, zCol, zDesc))
zSep = __ccgo_ts + 16562
}
}
z = _rbuMPrintf(tls, p, __ccgo_ts+32254, libc.VaList(bp+24, z))
_rbuFinalize(tls, p, **(**uintptr)(__ccgo_up(bp + 8)))
}
return z
}
// C documentation
//
// /*
// ** Read the content for page pPg out of the database file (or out of
// ** the WAL if that is where the most recent copy if found) into
// ** pPg->pData. A shared lock or greater must be held on the database
// ** file before this function is called.
// **
// ** If page 1 is read, then the value of Pager.dbFileVers[] is set to
// ** the value read from the database file.
// **
// ** If an IO error occurs, then the IO error is returned to the caller.
// ** Otherwise, SQLITE_OK is returned.
// */
func _readDbPage(tls *libc.TLS, pPg uintptr) (r int32) {
bp := tls.Alloc(16)
defer tls.Free(16)
var dbFileVers, pPager uintptr
var iOffset Ti64
var rc int32
var _ /* iFrame at bp+0 */ Tu32
_, _, _, _ = dbFileVers, iOffset, pPager, rc
pPager = (*TPgHdr)(unsafe.Pointer(pPg)).FpPager /* Pager object associated with page pPg */
rc = SQLITE_OK /* Return code */
**(**Tu32)(__ccgo_up(bp)) = uint32(0) /* Frame of WAL containing pgno */
if (*TPager)(unsafe.Pointer(pPager)).FpWal != uintptr(0) {
rc = _sqlite3WalFindFrame(tls, (*TPager)(unsafe.Pointer(pPager)).FpWal, (*TPgHdr)(unsafe.Pointer(pPg)).Fpgno, bp)
if rc != 0 {
return rc
}
}
if **(**Tu32)(__ccgo_up(bp)) != 0 {
rc = _sqlite3WalReadFrame(tls, (*TPager)(unsafe.Pointer(pPager)).FpWal, **(**Tu32)(__ccgo_up(bp)), int32((*TPager)(unsafe.Pointer(pPager)).FpageSize), (*TPgHdr)(unsafe.Pointer(pPg)).FpData)
} else {
iOffset = libc.Int64FromUint32((*TPgHdr)(unsafe.Pointer(pPg)).Fpgno-libc.Uint32FromInt32(1)) * (*TPager)(unsafe.Pointer(pPager)).FpageSize
rc = _sqlite3OsRead(tls, (*TPager)(unsafe.Pointer(pPager)).Ffd, (*TPgHdr)(unsafe.Pointer(pPg)).FpData, int32((*TPager)(unsafe.Pointer(pPager)).FpageSize), iOffset)
if rc == libc.Int32FromInt32(SQLITE_IOERR)|libc.Int32FromInt32(2)<dbFileVers[] with all 0xff bytes should suffice.
**
** For an encrypted database, the situation is more complex: bytes
** 24..39 of the database are white noise. But the probability of
** white noise equaling 16 bytes of 0xff is vanishingly small so
** we should still be ok.
*/
libc.X__builtin___memset_chk(tls, pPager+136, int32(0xff), uint64(16), ^t__predefined_size_t(0))
} else {
dbFileVers = (*TPgHdr)(unsafe.Pointer(pPg)).FpData + 24
libc.X__builtin___memcpy_chk(tls, pPager+136, dbFileVers, uint64(16), ^t__predefined_size_t(0))
}
}
return rc
}
// C documentation
//
// /*
// ** Array apCell[] contains pointers to nCell b-tree page cells. The
// ** szCell[] array contains the size in bytes of each cell. This function
// ** replaces the current contents of page pPg with the contents of the cell
// ** array.
// **
// ** Some of the cells in apCell[] may currently be stored in pPg. This
// ** function works around problems caused by this by making a copy of any
// ** such cells before overwriting the page data.
// **
// ** The MemPage.nFree field is invalidated by this function. It is the
// ** responsibility of the caller to set it correctly.
// */
func _rebuildPage(tls *libc.TLS, pCArray uintptr, iFirst int32, nCell int32, pPg uintptr) (r int32) {
var aData, pCell, pCellptr, pData, pEnd, pSrcEnd, pTmp uintptr
var hdr, i, iEnd, k, usableSize int32
var j Tu32
var sz Tu16
_, _, _, _, _, _, _, _, _, _, _, _, _, _ = aData, hdr, i, iEnd, j, k, pCell, pCellptr, pData, pEnd, pSrcEnd, pTmp, sz, usableSize
hdr = libc.Int32FromUint8((*TMemPage)(unsafe.Pointer(pPg)).FhdrOffset) /* Offset of header on pPg */
aData = (*TMemPage)(unsafe.Pointer(pPg)).FaData /* Pointer to data for pPg */
usableSize = libc.Int32FromUint32((*TBtShared)(unsafe.Pointer((*TMemPage)(unsafe.Pointer(pPg)).FpBt)).FusableSize)
pEnd = aData + uintptr(usableSize)
i = iFirst /* Start of cell content area */
iEnd = i + nCell /* Loop terminator */
pCellptr = (*TMemPage)(unsafe.Pointer(pPg)).FaCellIdx
pTmp = _sqlite3PagerTempSpace(tls, (*TBtShared)(unsafe.Pointer((*TMemPage)(unsafe.Pointer(pPg)).FpBt)).FpPager) /* Current pCArray->apEnd[k] value */
j = libc.Uint32FromInt32(libc.Int32FromUint8(**(**Tu8)(__ccgo_up(aData + uintptr(hdr+int32(5)))))< libc.Uint32FromInt32(usableSize) {
j = uint32(0)
}
libc.X__builtin___memcpy_chk(tls, pTmp+uintptr(j), aData+uintptr(j), uint64(libc.Uint32FromInt32(usableSize)-j), ^t__predefined_size_t(0))
k = 0
for {
if !(**(**int32)(__ccgo_up(pCArray + 80 + uintptr(k)*4)) <= i) {
break
}
goto _1
_1:
;
k = k + 1
}
pSrcEnd = **(**uintptr)(__ccgo_up(pCArray + 32 + uintptr(k)*8))
pData = pEnd
for int32(1) != 0 {
pCell = **(**uintptr)(__ccgo_up((*TCellArray)(unsafe.Pointer(pCArray)).FapCell + uintptr(i)*8))
sz = **(**Tu16)(__ccgo_up((*TCellArray)(unsafe.Pointer(pCArray)).FszCell + uintptr(i)*2))
if uint64(pCell) >= uint64(aData+uintptr(j)) && uint64(pCell) < uint64(pEnd) {
if uint64(pCell+uintptr(sz)) > uint64(pEnd) {
return _sqlite3CorruptError(tls, int32(80905))
}
pCell = pTmp + uintptr(int64(pCell)-int64(aData))
} else {
if uint64(pCell+uintptr(sz)) > uint64(pSrcEnd) && uint64(pCell) < uint64(pSrcEnd) {
return _sqlite3CorruptError(tls, int32(80910))
}
}
pData = pData - uintptr(sz)
**(**Tu8)(__ccgo_up(pCellptr)) = libc.Uint8FromInt64((int64(pData) - int64(aData)) >> libc.Int32FromInt32(8))
**(**Tu8)(__ccgo_up(pCellptr + 1)) = libc.Uint8FromInt64(int64(pData) - int64(aData))
pCellptr = pCellptr + uintptr(2)
if pData < pCellptr {
return _sqlite3CorruptError(tls, int32(80916))
}
libc.X__builtin___memmove_chk(tls, pData, pCell, uint64(sz), ^t__predefined_size_t(0))
i = i + 1
if i >= iEnd {
break
}
if **(**int32)(__ccgo_up(pCArray + 80 + uintptr(k)*4)) <= i {
k = k + 1
pSrcEnd = **(**uintptr)(__ccgo_up(pCArray + 32 + uintptr(k)*8))
}
}
/* The pPg->nFree field is now set incorrectly. The caller will fix it. */
(*TMemPage)(unsafe.Pointer(pPg)).FnCell = libc.Uint16FromInt32(nCell)
(*TMemPage)(unsafe.Pointer(pPg)).FnOverflow = uint8(0)
**(**Tu8)(__ccgo_up(aData + uintptr(hdr+int32(1)))) = libc.Uint8FromInt32(libc.Int32FromInt32(0) >> libc.Int32FromInt32(8))
**(**Tu8)(__ccgo_up(aData + uintptr(hdr+int32(1)) + 1)) = libc.Uint8FromInt32(libc.Int32FromInt32(0))
**(**Tu8)(__ccgo_up(aData + uintptr(hdr+int32(3)))) = libc.Uint8FromInt32(libc.Int32FromUint16((*TMemPage)(unsafe.Pointer(pPg)).FnCell) >> libc.Int32FromInt32(8))
**(**Tu8)(__ccgo_up(aData + uintptr(hdr+int32(3)) + 1)) = uint8((*TMemPage)(unsafe.Pointer(pPg)).FnCell)
**(**Tu8)(__ccgo_up(aData + uintptr(hdr+int32(5)))) = libc.Uint8FromInt64((int64(pData) - int64(aData)) >> libc.Int32FromInt32(8))
**(**Tu8)(__ccgo_up(aData + uintptr(hdr+int32(5)) + 1)) = libc.Uint8FromInt64(int64(pData) - int64(aData))
**(**Tu8)(__ccgo_up(aData + uintptr(hdr+int32(7)))) = uint8(0x00)
return SQLITE_OK
}
func _recomputeColumnsUsed(tls *libc.TLS, pSelect uintptr, pSrcItem uintptr) {
bp := tls.Alloc(48)
defer tls.Free(48)
var _ /* w at bp+0 */ TWalker
if (*TSrcItem)(unsafe.Pointer(pSrcItem)).FpSTab == uintptr(0) {
return
}
libc.X__builtin___memset_chk(tls, bp, 0, uint64(48), ^t__predefined_size_t(0))
(**(**TWalker)(__ccgo_up(bp))).FxExprCallback = __ccgo_fp(_recomputeColumnsUsedExpr)
(**(**TWalker)(__ccgo_up(bp))).FxSelectCallback = __ccgo_fp(_sqlite3SelectWalkNoop)
*(*uintptr)(unsafe.Pointer(bp + 40)) = pSrcItem
(*TSrcItem)(unsafe.Pointer(pSrcItem)).FcolUsed = uint64(0)
_sqlite3WalkSelect(tls, bp, pSelect)
}
// C documentation
//
// /* Resize the hash table so that it contains "new_size" buckets.
// **
// ** The hash table might fail to resize if sqlite3_malloc() fails or
// ** if the new size is the same as the prior size.
// ** Return TRUE if the resize occurs and false if not.
// */
func _rehash(tls *libc.TLS, pH uintptr, new_size uint32) (r int32) {
var elem, new_ht, next_elem uintptr
var v1 uint32
_, _, _, _ = elem, new_ht, next_elem, v1 /* For looping over existing elements */
if uint64(new_size)*uint64(16) > uint64(SQLITE_MALLOC_SOFT_LIMIT) {
new_size = uint32(libc.Uint64FromInt32(SQLITE_MALLOC_SOFT_LIMIT) / libc.Uint64FromInt64(16))
}
if new_size == (*THash)(unsafe.Pointer(pH)).Fhtsize {
return 0
}
/* The inability to allocates space for a larger hash table is
** a performance hit but it is not a fatal error. So mark the
** allocation as a benign. Use sqlite3Malloc()/memset(0) instead of
** sqlite3MallocZero() to make the allocation, as sqlite3MallocZero()
** only zeroes the requested number of bytes whereas this module will
** use the actual amount of space allocated for the hash table (which
** may be larger than the requested amount).
*/
_sqlite3BeginBenignMalloc(tls)
new_ht = _sqlite3Malloc(tls, uint64(new_size)*uint64(16))
_sqlite3EndBenignMalloc(tls)
if new_ht == uintptr(0) {
return 0
}
Xsqlite3_free(tls, (*THash)(unsafe.Pointer(pH)).Fht)
(*THash)(unsafe.Pointer(pH)).Fht = new_ht
v1 = uint32(libc.Uint64FromInt32(_sqlite3MallocSize(tls, new_ht)) / libc.Uint64FromInt64(16))
new_size = v1
(*THash)(unsafe.Pointer(pH)).Fhtsize = v1
libc.X__builtin___memset_chk(tls, new_ht, 0, uint64(new_size)*uint64(16), ^t__predefined_size_t(0))
elem = (*THash)(unsafe.Pointer(pH)).Ffirst
(*THash)(unsafe.Pointer(pH)).Ffirst = libc.UintptrFromInt32(0)
for {
if !(elem != 0) {
break
}
next_elem = (*THashElem)(unsafe.Pointer(elem)).Fnext
_insertElement(tls, pH, new_ht+uintptr((*THashElem)(unsafe.Pointer(elem)).Fh%new_size)*16, elem)
goto _2
_2:
;
elem = next_elem
}
return int32(1)
}
// C documentation
//
// /*
// ** SQL function:
// **
// ** sqlite_rename_column(SQL,TYPE,OBJ,DB,TABLE,COL,NEWNAME,QUOTE,TEMP)
// **
// ** 0. zSql: SQL statement to rewrite
// ** 1. type: Type of object ("table", "view" etc.)
// ** 2. object: Name of object
// ** 3. Database: Database name (e.g. "main")
// ** 4. Table: Table name
// ** 5. iCol: Index of column to rename
// ** 6. zNew: New column name
// ** 7. bQuote: Non-zero if the new column name should be quoted.
// ** 8. bTemp: True if zSql comes from temp schema
// **
// ** Do a column rename operation on the CREATE statement given in zSql.
// ** The iCol-th column (left-most is 0) of table zTable is renamed from zCol
// ** into zNew. The name should be quoted if bQuote is true.
// **
// ** This function is used internally by the ALTER TABLE RENAME COLUMN command.
// ** It is only accessible to SQL created using sqlite3NestedParse(). It is
// ** not reachable from ordinary SQL passed into sqlite3_prepare() unless the
// ** SQLITE_TESTCTRL_INTERNAL_FUNCTIONS test setting is enabled.
// */
func _renameColumnFunc(tls *libc.TLS, context uintptr, NotUsed int32, argv uintptr) {
bp := tls.Alloc(512)
defer tls.Free(512)
var bFKOnly, bQuote, bTemp, i, iCol, rc, v1 int32
var db, pExpr, pFKey, pIdx, pSelect, pStep, pTab, pTarget, pUpsertSet, zDb, zNew, zOld, zSql, zTable uintptr
var xAuth Tsqlite3_xauth
var _ /* sCtx at bp+0 */ TRenameCtx
var _ /* sParse at bp+32 */ TParse
var _ /* sWalker at bp+456 */ TWalker
_, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _ = bFKOnly, bQuote, bTemp, db, i, iCol, pExpr, pFKey, pIdx, pSelect, pStep, pTab, pTarget, pUpsertSet, rc, xAuth, zDb, zNew, zOld, zSql, zTable, v1
db = Xsqlite3_context_db_handle(tls, context)
zSql = Xsqlite3_value_text(tls, **(**uintptr)(__ccgo_up(argv)))
zDb = Xsqlite3_value_text(tls, **(**uintptr)(__ccgo_up(argv + 3*8)))
zTable = Xsqlite3_value_text(tls, **(**uintptr)(__ccgo_up(argv + 4*8)))
iCol = Xsqlite3_value_int(tls, **(**uintptr)(__ccgo_up(argv + 5*8)))
zNew = Xsqlite3_value_text(tls, **(**uintptr)(__ccgo_up(argv + 6*8)))
bQuote = Xsqlite3_value_int(tls, **(**uintptr)(__ccgo_up(argv + 7*8)))
bTemp = Xsqlite3_value_int(tls, **(**uintptr)(__ccgo_up(argv + 8*8)))
xAuth = (*Tsqlite3)(unsafe.Pointer(db)).FxAuth
_ = NotUsed
if zSql == uintptr(0) {
return
}
if zTable == uintptr(0) {
return
}
if zNew == uintptr(0) {
return
}
if iCol < 0 {
return
}
_sqlite3BtreeEnterAll(tls, db)
pTab = _sqlite3FindTable(tls, db, zTable, zDb)
if pTab == uintptr(0) || iCol >= int32((*TTable)(unsafe.Pointer(pTab)).FnCol) {
_sqlite3BtreeLeaveAll(tls, db)
return
}
zOld = (**(**TColumn)(__ccgo_up((*TTable)(unsafe.Pointer(pTab)).FaCol + uintptr(iCol)*16))).FzCnName
libc.X__builtin___memset_chk(tls, bp, 0, uint64(32), ^t__predefined_size_t(0))
if iCol == int32((*TTable)(unsafe.Pointer(pTab)).FiPKey) {
v1 = -int32(1)
} else {
v1 = iCol
}
(**(**TRenameCtx)(__ccgo_up(bp))).FiCol = v1
(*Tsqlite3)(unsafe.Pointer(db)).FxAuth = uintptr(0)
rc = _renameParseSql(tls, bp+32, zDb, db, zSql, bTemp)
/* Find tokens that need to be replaced. */
libc.X__builtin___memset_chk(tls, bp+456, 0, uint64(48), ^t__predefined_size_t(0))
(**(**TWalker)(__ccgo_up(bp + 456))).FpParse = bp + 32
(**(**TWalker)(__ccgo_up(bp + 456))).FxExprCallback = __ccgo_fp(_renameColumnExprCb)
(**(**TWalker)(__ccgo_up(bp + 456))).FxSelectCallback = __ccgo_fp(_renameColumnSelectCb)
*(*uintptr)(unsafe.Pointer(bp + 456 + 40)) = bp
(**(**TRenameCtx)(__ccgo_up(bp))).FpTab = pTab
if rc != SQLITE_OK {
goto renameColumnFunc_done
}
if (**(**TParse)(__ccgo_up(bp + 32))).FpNewTable != 0 {
if libc.Int32FromUint8((*TTable)(unsafe.Pointer((**(**TParse)(__ccgo_up(bp + 32))).FpNewTable)).FeTabType) == int32(TABTYP_VIEW) {
pSelect = (*(*struct {
FpSelect uintptr
})(unsafe.Pointer(&(*TTable)(unsafe.Pointer((**(**TParse)(__ccgo_up(bp + 32))).FpNewTable)).Fu))).FpSelect
**(**Tu32)(__ccgo_up(pSelect + 4)) &= ^libc.Uint32FromInt32(SF_View)
(**(**TParse)(__ccgo_up(bp + 32))).Frc = SQLITE_OK
_sqlite3SelectPrep(tls, bp+32, pSelect, uintptr(0))
if (*Tsqlite3)(unsafe.Pointer(db)).FmallocFailed != 0 {
v1 = int32(SQLITE_NOMEM)
} else {
v1 = (**(**TParse)(__ccgo_up(bp + 32))).Frc
}
rc = v1
if rc == SQLITE_OK {
_sqlite3WalkSelect(tls, bp+456, pSelect)
}
if rc != SQLITE_OK {
goto renameColumnFunc_done
}
} else {
if libc.Int32FromUint8((*TTable)(unsafe.Pointer((**(**TParse)(__ccgo_up(bp + 32))).FpNewTable)).FeTabType) == TABTYP_NORM {
/* A regular table */
bFKOnly = Xsqlite3_stricmp(tls, zTable, (*TTable)(unsafe.Pointer((**(**TParse)(__ccgo_up(bp + 32))).FpNewTable)).FzName)
(**(**TRenameCtx)(__ccgo_up(bp))).FpTab = (**(**TParse)(__ccgo_up(bp + 32))).FpNewTable
if bFKOnly == 0 {
if iCol < int32((*TTable)(unsafe.Pointer((**(**TParse)(__ccgo_up(bp + 32))).FpNewTable)).FnCol) {
_renameTokenFind(tls, bp+32, bp, (**(**TColumn)(__ccgo_up((*TTable)(unsafe.Pointer((**(**TParse)(__ccgo_up(bp + 32))).FpNewTable)).FaCol + uintptr(iCol)*16))).FzCnName)
}
if (**(**TRenameCtx)(__ccgo_up(bp))).FiCol < 0 {
_renameTokenFind(tls, bp+32, bp, (**(**TParse)(__ccgo_up(bp + 32))).FpNewTable+52)
}
_sqlite3WalkExprList(tls, bp+456, (*TTable)(unsafe.Pointer((**(**TParse)(__ccgo_up(bp + 32))).FpNewTable)).FpCheck)
pIdx = (*TTable)(unsafe.Pointer((**(**TParse)(__ccgo_up(bp + 32))).FpNewTable)).FpIndex
for {
if !(pIdx != 0) {
break
}
_sqlite3WalkExprList(tls, bp+456, (*TIndex)(unsafe.Pointer(pIdx)).FaColExpr)
goto _3
_3:
;
pIdx = (*TIndex)(unsafe.Pointer(pIdx)).FpNext
}
pIdx = (**(**TParse)(__ccgo_up(bp + 32))).FpNewIndex
for {
if !(pIdx != 0) {
break
}
_sqlite3WalkExprList(tls, bp+456, (*TIndex)(unsafe.Pointer(pIdx)).FaColExpr)
goto _4
_4:
;
pIdx = (*TIndex)(unsafe.Pointer(pIdx)).FpNext
}
i = 0
for {
if !(i < int32((*TTable)(unsafe.Pointer((**(**TParse)(__ccgo_up(bp + 32))).FpNewTable)).FnCol)) {
break
}
pExpr = _sqlite3ColumnExpr(tls, (**(**TParse)(__ccgo_up(bp + 32))).FpNewTable, (*TTable)(unsafe.Pointer((**(**TParse)(__ccgo_up(bp + 32))).FpNewTable)).FaCol+uintptr(i)*16)
_sqlite3WalkExpr(tls, bp+456, pExpr)
goto _5
_5:
;
i = i + 1
}
}
pFKey = (*(*struct {
FaddColOffset int32
FpFKey uintptr
FpDfltList uintptr
})(unsafe.Pointer((**(**TParse)(__ccgo_up(bp + 32))).FpNewTable + 64))).FpFKey
for {
if !(pFKey != 0) {
break
}
i = 0
for {
if !(i < (*TFKey)(unsafe.Pointer(pFKey)).FnCol) {
break
}
if bFKOnly == 0 && (*(*TsColMap)(unsafe.Pointer(pFKey + 64 + uintptr(i)*16))).FiFrom == iCol {
_renameTokenFind(tls, bp+32, bp, pFKey+64+uintptr(i)*16)
}
if 0 == Xsqlite3_stricmp(tls, (*TFKey)(unsafe.Pointer(pFKey)).FzTo, zTable) && 0 == Xsqlite3_stricmp(tls, (*(*TsColMap)(unsafe.Pointer(pFKey + 64 + uintptr(i)*16))).FzCol, zOld) {
_renameTokenFind(tls, bp+32, bp, (*(*TsColMap)(unsafe.Pointer(pFKey + 64 + uintptr(i)*16))).FzCol)
}
goto _7
_7:
;
i = i + 1
}
goto _6
_6:
;
pFKey = (*TFKey)(unsafe.Pointer(pFKey)).FpNextFrom
}
}
}
} else {
if (**(**TParse)(__ccgo_up(bp + 32))).FpNewIndex != 0 {
_sqlite3WalkExprList(tls, bp+456, (*TIndex)(unsafe.Pointer((**(**TParse)(__ccgo_up(bp + 32))).FpNewIndex)).FaColExpr)
_sqlite3WalkExpr(tls, bp+456, (*TIndex)(unsafe.Pointer((**(**TParse)(__ccgo_up(bp + 32))).FpNewIndex)).FpPartIdxWhere)
} else {
rc = _renameResolveTrigger(tls, bp+32)
if rc != SQLITE_OK {
goto renameColumnFunc_done
}
pStep = (*TTrigger)(unsafe.Pointer((**(**TParse)(__ccgo_up(bp + 32))).FpNewTrigger)).Fstep_list
for {
if !(pStep != 0) {
break
}
if (*TTriggerStep)(unsafe.Pointer(pStep)).FpSrc != 0 {
pTarget = _sqlite3LocateTableItem(tls, bp+32, uint32(0), (*TTriggerStep)(unsafe.Pointer(pStep)).FpSrc+8)
if pTarget == pTab {
if (*TTriggerStep)(unsafe.Pointer(pStep)).FpUpsert != 0 {
pUpsertSet = (*TUpsert)(unsafe.Pointer((*TTriggerStep)(unsafe.Pointer(pStep)).FpUpsert)).FpUpsertSet
_renameColumnElistNames(tls, bp+32, bp, pUpsertSet, zOld)
}
_renameColumnIdlistNames(tls, bp+32, bp, (*TTriggerStep)(unsafe.Pointer(pStep)).FpIdList, zOld)
_renameColumnElistNames(tls, bp+32, bp, (*TTriggerStep)(unsafe.Pointer(pStep)).FpExprList, zOld)
}
}
goto _8
_8:
;
pStep = (*TTriggerStep)(unsafe.Pointer(pStep)).FpNext
}
/* Find tokens to edit in UPDATE OF clause */
if (**(**TParse)(__ccgo_up(bp + 32))).FpTriggerTab == pTab {
_renameColumnIdlistNames(tls, bp+32, bp, (*TTrigger)(unsafe.Pointer((**(**TParse)(__ccgo_up(bp + 32))).FpNewTrigger)).FpColumns, zOld)
}
/* Find tokens to edit in various expressions and selects */
_renameWalkTrigger(tls, bp+456, (**(**TParse)(__ccgo_up(bp + 32))).FpNewTrigger)
}
}
rc = _renameEditSql(tls, context, bp, zSql, zNew, bQuote)
goto renameColumnFunc_done
renameColumnFunc_done:
;
if rc != SQLITE_OK {
if rc == int32(SQLITE_ERROR) && _sqlite3WritableSchema(tls, db) != 0 {
Xsqlite3_result_value(tls, context, **(**uintptr)(__ccgo_up(argv)))
} else {
if (**(**TParse)(__ccgo_up(bp + 32))).FzErrMsg != 0 {
_renameColumnParseError(tls, context, __ccgo_ts+1702, **(**uintptr)(__ccgo_up(argv + 1*8)), **(**uintptr)(__ccgo_up(argv + 2*8)), bp+32)
} else {
Xsqlite3_result_error_code(tls, context, rc)
}
}
}
_renameParseCleanup(tls, bp+32)
_renameTokenFree(tls, db, (**(**TRenameCtx)(__ccgo_up(bp))).FpList)
(*Tsqlite3)(unsafe.Pointer(db)).FxAuth = xAuth
_sqlite3BtreeLeaveAll(tls, db)
}
// C documentation
//
// /*
// ** An error occurred while parsing or otherwise processing a database
// ** object (either pParse->pNewTable, pNewIndex or pNewTrigger) as part of an
// ** ALTER TABLE RENAME COLUMN program. The error message emitted by the
// ** sub-routine is currently stored in pParse->zErrMsg. This function
// ** adds context to the error message and then stores it in pCtx.
// */
func _renameColumnParseError(tls *libc.TLS, pCtx uintptr, zWhen uintptr, pType uintptr, pObject uintptr, pParse uintptr) {
bp := tls.Alloc(48)
defer tls.Free(48)
var zErr, zN, zT, v1 uintptr
_, _, _, _ = zErr, zN, zT, v1
zT = Xsqlite3_value_text(tls, pType)
zN = Xsqlite3_value_text(tls, pObject)
if **(**int8)(__ccgo_up(zWhen)) != 0 {
v1 = __ccgo_ts + 11889
} else {
v1 = __ccgo_ts + 1702
}
zErr = _sqlite3MPrintf(tls, (*TParse)(unsafe.Pointer(pParse)).Fdb, __ccgo_ts+11891, libc.VaList(bp+8, zT, zN, v1, zWhen, (*TParse)(unsafe.Pointer(pParse)).FzErrMsg))
Xsqlite3_result_error(tls, pCtx, zErr, -int32(1))
_sqlite3DbFree(tls, (*TParse)(unsafe.Pointer(pParse)).Fdb, zErr)
}
// 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+11922, 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.X__builtin___memcpy_chk(tls, zOut, zSql, libc.Uint64FromInt64(nSql), ^t__predefined_size_t(0))
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.X__builtin___memcpy_chk(tls, zBuf1, (*TRenameToken)(unsafe.Pointer(pBest)).Ft.Fz, uint64((*TRenameToken)(unsafe.Pointer(pBest)).Ft.Fn), ^t__predefined_size_t(0))
**(**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 + 11889
} else {
v1 = __ccgo_ts + 1702
}
Xsqlite3_snprintf(tls, int32(nSql*libc.Int64FromInt32(2)), zBuf2, __ccgo_ts+11928, libc.VaList(bp+8, zBuf1, v1))
zReplace = zBuf2
nReplace = int64(_sqlite3Strlen30(tls, zReplace))
}
iOff = int32(int64((*TRenameToken)(unsafe.Pointer(pBest)).Ft.Fz) - int64(zSql))
if libc.Int64FromUint32((*TRenameToken)(unsafe.Pointer(pBest)).Ft.Fn) != nReplace {
libc.X__builtin___memmove_chk(tls, zOut+uintptr(int64(iOff)+nReplace), zOut+uintptr(libc.Uint32FromInt32(iOff)+(*TRenameToken)(unsafe.Pointer(pBest)).Ft.Fn), libc.Uint64FromInt64(nOut-libc.Int64FromUint32(libc.Uint32FromInt32(iOff)+(*TRenameToken)(unsafe.Pointer(pBest)).Ft.Fn)), ^t__predefined_size_t(0))
nOut = nOut + (nReplace - libc.Int64FromUint32((*TRenameToken)(unsafe.Pointer(pBest)).Ft.Fn))
**(**int8)(__ccgo_up(zOut + uintptr(nOut))) = int8('\000')
}
libc.X__builtin___memcpy_chk(tls, zOut+uintptr(iOff), zReplace, libc.Uint64FromInt64(nReplace), ^t__predefined_size_t(0))
_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
//
// /*
// ** Generate VM code to replace any double-quoted strings (but not double-quoted
// ** identifiers) within the "sql" column of the sqlite_schema table in
// ** database zDb with their single-quoted equivalents. If argument bTemp is
// ** not true, similarly update all SQL statements in the sqlite_schema table
// ** of the temp db.
// */
func _renameFixQuotes(tls *libc.TLS, pParse uintptr, zDb uintptr, bTemp int32) {
bp := tls.Alloc(32)
defer tls.Free(32)
_sqlite3NestedParse(tls, pParse, __ccgo_ts+9368, libc.VaList(bp+8, zDb, zDb))
if bTemp == 0 {
_sqlite3NestedParse(tls, pParse, __ccgo_ts+9515, 0)
}
}
// C documentation
//
// /*
// ** Parse the SQL statement zSql using Parse object (*p). The Parse object
// ** is initialized by this function before it is used.
// */
func _renameParseSql(tls *libc.TLS, p uintptr, zDb uintptr, db uintptr, zSql uintptr, bTemp int32) (r int32) {
var flags Tu64
var iDb, rc int32
_, _, _ = flags, iDb, rc
_sqlite3ParseObjectInit(tls, p, db)
if zSql == uintptr(0) {
return int32(SQLITE_NOMEM)
}
if Xsqlite3_strnicmp(tls, zSql, __ccgo_ts+11914, int32(7)) != 0 {
return _sqlite3CorruptError(tls, int32(121717))
}
if bTemp != 0 {
(*Tsqlite3)(unsafe.Pointer(db)).Finit1.FiDb = uint8(1)
} else {
iDb = _sqlite3FindDbName(tls, db, zDb)
(*Tsqlite3)(unsafe.Pointer(db)).Finit1.FiDb = libc.Uint8FromInt32(iDb)
}
(*TParse)(unsafe.Pointer(p)).FeParseMode = uint8(PARSE_MODE_RENAME)
(*TParse)(unsafe.Pointer(p)).Fdb = db
(*TParse)(unsafe.Pointer(p)).FnQueryLoop = int16(1)
flags = (*Tsqlite3)(unsafe.Pointer(db)).Fflags
**(**Tu64)(__ccgo_up(db + 48)) |= libc.Uint64FromInt32(libc.Int32FromInt32(0x00040)) << libc.Int32FromInt32(32)
rc = _sqlite3RunParser(tls, p, zSql)
(*Tsqlite3)(unsafe.Pointer(db)).Fflags = flags
if (*Tsqlite3)(unsafe.Pointer(db)).FmallocFailed != 0 {
rc = int32(SQLITE_NOMEM)
}
if rc == SQLITE_OK && ((*TParse)(unsafe.Pointer(p)).FpNewTable == uintptr(0) && (*TParse)(unsafe.Pointer(p)).FpNewIndex == uintptr(0) && (*TParse)(unsafe.Pointer(p)).FpNewTrigger == uintptr(0)) {
rc = _sqlite3CorruptError(tls, int32(121738))
}
(*Tsqlite3)(unsafe.Pointer(db)).Finit1.FiDb = uint8(0)
return rc
}
// C documentation
//
// /* SQL function: sqlite_rename_quotefix(DB,SQL)
// **
// ** Rewrite the DDL statement "SQL" so that any string literals that use
// ** double-quotes use single quotes instead.
// **
// ** Two arguments must be passed:
// **
// ** 0: Database name ("main", "temp" etc.).
// ** 1: SQL statement to edit.
// **
// ** The returned value is the modified SQL statement. For example, given
// ** the database schema:
// **
// ** CREATE TABLE t1(a, b, c);
// **
// ** SELECT sqlite_rename_quotefix('main',
// ** 'CREATE VIEW v1 AS SELECT "a", "string" FROM t1'
// ** );
// **
// ** returns the string:
// **
// ** CREATE VIEW v1 AS SELECT "a", 'string' FROM t1
// **
// ** If there is a error in the input SQL, then raise an error, except
// ** if PRAGMA writable_schema=ON, then just return the input string
// ** unmodified following an error.
// */
func _renameQuotefixFunc(tls *libc.TLS, context uintptr, NotUsed int32, argv uintptr) {
bp := tls.Alloc(512)
defer tls.Free(512)
var db, pSelect, zDb, zInput uintptr
var i, rc, v1 int32
var xAuth Tsqlite3_xauth
var _ /* sCtx at bp+424 */ TRenameCtx
var _ /* sParse at bp+0 */ TParse
var _ /* sWalker at bp+456 */ TWalker
_, _, _, _, _, _, _, _ = db, i, pSelect, rc, xAuth, zDb, zInput, v1
db = Xsqlite3_context_db_handle(tls, context)
zDb = Xsqlite3_value_text(tls, **(**uintptr)(__ccgo_up(argv)))
zInput = Xsqlite3_value_text(tls, **(**uintptr)(__ccgo_up(argv + 1*8)))
xAuth = (*Tsqlite3)(unsafe.Pointer(db)).FxAuth
(*Tsqlite3)(unsafe.Pointer(db)).FxAuth = uintptr(0)
_sqlite3BtreeEnterAll(tls, db)
_ = NotUsed
if zDb != 0 && zInput != 0 {
rc = _renameParseSql(tls, bp, zDb, db, zInput, 0)
if rc == SQLITE_OK {
/* Walker to find tokens that need to be replaced. */
libc.X__builtin___memset_chk(tls, bp+424, 0, uint64(32), ^t__predefined_size_t(0))
libc.X__builtin___memset_chk(tls, bp+456, 0, uint64(48), ^t__predefined_size_t(0))
(**(**TWalker)(__ccgo_up(bp + 456))).FpParse = bp
(**(**TWalker)(__ccgo_up(bp + 456))).FxExprCallback = __ccgo_fp(_renameQuotefixExprCb)
(**(**TWalker)(__ccgo_up(bp + 456))).FxSelectCallback = __ccgo_fp(_renameColumnSelectCb)
*(*uintptr)(unsafe.Pointer(bp + 456 + 40)) = bp + 424
if (**(**TParse)(__ccgo_up(bp))).FpNewTable != 0 {
if libc.Int32FromUint8((*TTable)(unsafe.Pointer((**(**TParse)(__ccgo_up(bp))).FpNewTable)).FeTabType) == int32(TABTYP_VIEW) {
pSelect = (*(*struct {
FpSelect uintptr
})(unsafe.Pointer(&(*TTable)(unsafe.Pointer((**(**TParse)(__ccgo_up(bp))).FpNewTable)).Fu))).FpSelect
**(**Tu32)(__ccgo_up(pSelect + 4)) &= ^libc.Uint32FromInt32(SF_View)
(**(**TParse)(__ccgo_up(bp))).Frc = SQLITE_OK
_sqlite3SelectPrep(tls, bp, pSelect, uintptr(0))
if (*Tsqlite3)(unsafe.Pointer(db)).FmallocFailed != 0 {
v1 = int32(SQLITE_NOMEM)
} else {
v1 = (**(**TParse)(__ccgo_up(bp))).Frc
}
rc = v1
if rc == SQLITE_OK {
_sqlite3WalkSelect(tls, bp+456, pSelect)
}
} else {
_sqlite3WalkExprList(tls, bp+456, (*TTable)(unsafe.Pointer((**(**TParse)(__ccgo_up(bp))).FpNewTable)).FpCheck)
i = 0
for {
if !(i < int32((*TTable)(unsafe.Pointer((**(**TParse)(__ccgo_up(bp))).FpNewTable)).FnCol)) {
break
}
_sqlite3WalkExpr(tls, bp+456, _sqlite3ColumnExpr(tls, (**(**TParse)(__ccgo_up(bp))).FpNewTable, (*TTable)(unsafe.Pointer((**(**TParse)(__ccgo_up(bp))).FpNewTable)).FaCol+uintptr(i)*16))
goto _2
_2:
;
i = i + 1
}
}
} else {
if (**(**TParse)(__ccgo_up(bp))).FpNewIndex != 0 {
_sqlite3WalkExprList(tls, bp+456, (*TIndex)(unsafe.Pointer((**(**TParse)(__ccgo_up(bp))).FpNewIndex)).FaColExpr)
_sqlite3WalkExpr(tls, bp+456, (*TIndex)(unsafe.Pointer((**(**TParse)(__ccgo_up(bp))).FpNewIndex)).FpPartIdxWhere)
} else {
rc = _renameResolveTrigger(tls, bp)
if rc == SQLITE_OK {
_renameWalkTrigger(tls, bp+456, (**(**TParse)(__ccgo_up(bp))).FpNewTrigger)
}
}
}
if rc == SQLITE_OK {
rc = _renameEditSql(tls, context, bp+424, zInput, uintptr(0), 0)
}
_renameTokenFree(tls, db, (**(**TRenameCtx)(__ccgo_up(bp + 424))).FpList)
}
if rc != SQLITE_OK {
if _sqlite3WritableSchema(tls, db) != 0 && rc == int32(SQLITE_ERROR) {
Xsqlite3_result_value(tls, context, **(**uintptr)(__ccgo_up(argv + 1*8)))
} else {
Xsqlite3_result_error_code(tls, context, rc)
}
}
_renameParseCleanup(tls, bp)
}
(*Tsqlite3)(unsafe.Pointer(db)).FxAuth = xAuth
_sqlite3BtreeLeaveAll(tls, db)
}
// C documentation
//
// /*
// ** Resolve all symbols in the trigger at pParse->pNewTrigger, assuming
// ** it was read from the schema of database zDb. Return SQLITE_OK if
// ** successful. Otherwise, return an SQLite error code and leave an error
// ** message in the Parse object.
// */
func _renameResolveTrigger(tls *libc.TLS, pParse uintptr) (r int32) {
bp := tls.Alloc(64)
defer tls.Free(64)
var db, p, pNew, pSel, pSrc, pStep, pUpsert, pUpsertSet uintptr
var i, rc, v2 int32
var _ /* sNC at bp+0 */ TNameContext
_, _, _, _, _, _, _, _, _, _, _ = db, i, p, pNew, pSel, pSrc, pStep, pUpsert, pUpsertSet, rc, v2
db = (*TParse)(unsafe.Pointer(pParse)).Fdb
pNew = (*TParse)(unsafe.Pointer(pParse)).FpNewTrigger
rc = SQLITE_OK
libc.X__builtin___memset_chk(tls, bp, 0, uint64(56), ^t__predefined_size_t(0))
(**(**TNameContext)(__ccgo_up(bp))).FpParse = pParse
(*TParse)(unsafe.Pointer(pParse)).FpTriggerTab = _sqlite3FindTable(tls, db, (*TTrigger)(unsafe.Pointer(pNew)).Ftable, (**(**TDb)(__ccgo_up((*Tsqlite3)(unsafe.Pointer(db)).FaDb + uintptr(_sqlite3SchemaToIndex(tls, db, (*TTrigger)(unsafe.Pointer(pNew)).FpTabSchema))*32))).FzDbSName)
(*TParse)(unsafe.Pointer(pParse)).FeTriggerOp = (*TTrigger)(unsafe.Pointer(pNew)).Fop
/* ALWAYS() because if the table of the trigger does not exist, the
** error would have been hit before this point */
if (*TParse)(unsafe.Pointer(pParse)).FpTriggerTab != 0 {
rc = libc.BoolInt32(_sqlite3ViewGetColumnNames(tls, pParse, (*TParse)(unsafe.Pointer(pParse)).FpTriggerTab) != 0)
}
/* Resolve symbols in WHEN clause */
if rc == SQLITE_OK && (*TTrigger)(unsafe.Pointer(pNew)).FpWhen != 0 {
rc = _sqlite3ResolveExprNames(tls, bp, (*TTrigger)(unsafe.Pointer(pNew)).FpWhen)
}
pStep = (*TTrigger)(unsafe.Pointer(pNew)).Fstep_list
for {
if !(rc == SQLITE_OK && pStep != 0) {
break
}
if (*TTriggerStep)(unsafe.Pointer(pStep)).FpSelect != 0 {
_sqlite3SelectPrep(tls, pParse, (*TTriggerStep)(unsafe.Pointer(pStep)).FpSelect, bp)
if (*TParse)(unsafe.Pointer(pParse)).FnErr != 0 {
rc = (*TParse)(unsafe.Pointer(pParse)).Frc
}
}
if rc == SQLITE_OK && (*TTriggerStep)(unsafe.Pointer(pStep)).FpSrc != 0 {
pSrc = _sqlite3SrcListDup(tls, db, (*TTriggerStep)(unsafe.Pointer(pStep)).FpSrc, 0)
if pSrc != 0 {
pSel = _sqlite3SelectNew(tls, pParse, (*TTriggerStep)(unsafe.Pointer(pStep)).FpExprList, pSrc, uintptr(0), uintptr(0), uintptr(0), uintptr(0), uint32(0), uintptr(0))
if pSel == uintptr(0) {
(*TTriggerStep)(unsafe.Pointer(pStep)).FpExprList = uintptr(0)
pSrc = uintptr(0)
rc = int32(SQLITE_NOMEM)
} else {
/* pStep->pExprList contains an expression-list used for an UPDATE
** statement. So the a[].zEName values are the RHS of the
** " = " clauses of the UPDATE statement. So, before
** running SelectPrep(), change all the eEName values in
** pStep->pExprList to ENAME_SPAN (from their current value of
** ENAME_NAME). This is to prevent any ids in ON() clauses that are
** part of pSrc from being incorrectly resolved against the
** a[].zEName values as if they were column aliases. */
_renameSetENames(tls, (*TTriggerStep)(unsafe.Pointer(pStep)).FpExprList, int32(ENAME_SPAN))
_sqlite3SelectPrep(tls, pParse, pSel, uintptr(0))
_renameSetENames(tls, (*TTriggerStep)(unsafe.Pointer(pStep)).FpExprList, ENAME_NAME)
if (*TParse)(unsafe.Pointer(pParse)).FnErr != 0 {
v2 = int32(SQLITE_ERROR)
} else {
v2 = SQLITE_OK
}
rc = v2
if (*TTriggerStep)(unsafe.Pointer(pStep)).FpExprList != 0 {
(*TSelect)(unsafe.Pointer(pSel)).FpEList = uintptr(0)
}
(*TSelect)(unsafe.Pointer(pSel)).FpSrc = uintptr(0)
_sqlite3SelectDelete(tls, db, pSel)
}
if (*TTriggerStep)(unsafe.Pointer(pStep)).FpSrc != 0 {
i = 0
for {
if !(i < (*TSrcList)(unsafe.Pointer((*TTriggerStep)(unsafe.Pointer(pStep)).FpSrc)).FnSrc && rc == SQLITE_OK) {
break
}
p = (*TTriggerStep)(unsafe.Pointer(pStep)).FpSrc + 8 + uintptr(i)*80
if int32(*(*uint32)(unsafe.Pointer(p + 24 + 4))&0x4>>2) != 0 {
_sqlite3SelectPrep(tls, pParse, (*TSubquery)(unsafe.Pointer(*(*uintptr)(unsafe.Pointer(p + 72)))).FpSelect, uintptr(0))
}
goto _3
_3:
;
i = i + 1
}
}
if (*Tsqlite3)(unsafe.Pointer(db)).FmallocFailed != 0 {
rc = int32(SQLITE_NOMEM)
}
(**(**TNameContext)(__ccgo_up(bp))).FpSrcList = pSrc
if rc == SQLITE_OK && (*TTriggerStep)(unsafe.Pointer(pStep)).FpWhere != 0 {
rc = _sqlite3ResolveExprNames(tls, bp, (*TTriggerStep)(unsafe.Pointer(pStep)).FpWhere)
}
if rc == SQLITE_OK {
rc = _sqlite3ResolveExprListNames(tls, bp, (*TTriggerStep)(unsafe.Pointer(pStep)).FpExprList)
}
if (*TTriggerStep)(unsafe.Pointer(pStep)).FpUpsert != 0 && rc == SQLITE_OK {
pUpsert = (*TTriggerStep)(unsafe.Pointer(pStep)).FpUpsert
(*TUpsert)(unsafe.Pointer(pUpsert)).FpUpsertSrc = pSrc
*(*uintptr)(unsafe.Pointer(bp + 16)) = pUpsert
(**(**TNameContext)(__ccgo_up(bp))).FncFlags = int32(NC_UUpsert)
rc = _sqlite3ResolveExprListNames(tls, bp, (*TUpsert)(unsafe.Pointer(pUpsert)).FpUpsertTarget)
if rc == SQLITE_OK {
pUpsertSet = (*TUpsert)(unsafe.Pointer(pUpsert)).FpUpsertSet
rc = _sqlite3ResolveExprListNames(tls, bp, pUpsertSet)
}
if rc == SQLITE_OK {
rc = _sqlite3ResolveExprNames(tls, bp, (*TUpsert)(unsafe.Pointer(pUpsert)).FpUpsertWhere)
}
if rc == SQLITE_OK {
rc = _sqlite3ResolveExprNames(tls, bp, (*TUpsert)(unsafe.Pointer(pUpsert)).FpUpsertTargetWhere)
}
(**(**TNameContext)(__ccgo_up(bp))).FncFlags = 0
}
(**(**TNameContext)(__ccgo_up(bp))).FpSrcList = uintptr(0)
_sqlite3SrcListDelete(tls, db, pSrc)
} else {
rc = int32(SQLITE_NOMEM)
}
}
goto _1
_1:
;
pStep = (*TTriggerStep)(unsafe.Pointer(pStep)).FpNext
}
return rc
}
// C documentation
//
// /*
// ** This C function implements an SQL user function that is used by SQL code
// ** generated by the ALTER TABLE ... RENAME command to modify the definition
// ** of any foreign key constraints that use the table being renamed as the
// ** parent table. It is passed three arguments:
// **
// ** 0: The database containing the table being renamed.
// ** 1. type: Type of object ("table", "view" etc.)
// ** 2. object: Name of object
// ** 3: The complete text of the schema statement being modified,
// ** 4: The old name of the table being renamed, and
// ** 5: The new name of the table being renamed.
// ** 6: True if the schema statement comes from the temp db.
// **
// ** It returns the new schema statement. For example:
// **
// ** sqlite_rename_table('main', 'CREATE TABLE t1(a REFERENCES t2)','t2','t3',0)
// ** -> 'CREATE TABLE t1(a REFERENCES t3)'
// */
func _renameTableFunc(tls *libc.TLS, context uintptr, NotUsed int32, argv uintptr) {
bp := tls.Alloc(560)
defer tls.Free(560)
var bQuote, bTemp, i, isLegacy, rc int32
var db, pFKey, pItem, pSelect, pStep, pTab, pTrigger, zDb, zInput, zNew, zOld uintptr
var xAuth Tsqlite3_xauth
var _ /* sCtx at bp+424 */ TRenameCtx
var _ /* sNC at bp+504 */ TNameContext
var _ /* sParse at bp+0 */ TParse
var _ /* sWalker at bp+456 */ TWalker
_, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _ = bQuote, bTemp, db, i, isLegacy, pFKey, pItem, pSelect, pStep, pTab, pTrigger, rc, xAuth, zDb, zInput, zNew, zOld
db = Xsqlite3_context_db_handle(tls, context)
zDb = Xsqlite3_value_text(tls, **(**uintptr)(__ccgo_up(argv)))
zInput = Xsqlite3_value_text(tls, **(**uintptr)(__ccgo_up(argv + 3*8)))
zOld = Xsqlite3_value_text(tls, **(**uintptr)(__ccgo_up(argv + 4*8)))
zNew = Xsqlite3_value_text(tls, **(**uintptr)(__ccgo_up(argv + 5*8)))
bTemp = Xsqlite3_value_int(tls, **(**uintptr)(__ccgo_up(argv + 6*8)))
_ = NotUsed
if zInput != 0 && zOld != 0 && zNew != 0 {
bQuote = int32(1)
xAuth = (*Tsqlite3)(unsafe.Pointer(db)).FxAuth
(*Tsqlite3)(unsafe.Pointer(db)).FxAuth = uintptr(0)
_sqlite3BtreeEnterAll(tls, db)
libc.X__builtin___memset_chk(tls, bp+424, 0, uint64(32), ^t__predefined_size_t(0))
(**(**TRenameCtx)(__ccgo_up(bp + 424))).FpTab = _sqlite3FindTable(tls, db, zOld, zDb)
libc.X__builtin___memset_chk(tls, bp+456, 0, uint64(48), ^t__predefined_size_t(0))
(**(**TWalker)(__ccgo_up(bp + 456))).FpParse = bp
(**(**TWalker)(__ccgo_up(bp + 456))).FxExprCallback = __ccgo_fp(_renameTableExprCb)
(**(**TWalker)(__ccgo_up(bp + 456))).FxSelectCallback = __ccgo_fp(_renameTableSelectCb)
*(*uintptr)(unsafe.Pointer(bp + 456 + 40)) = bp + 424
rc = _renameParseSql(tls, bp, zDb, db, zInput, bTemp)
if rc == SQLITE_OK {
isLegacy = libc.Int32FromUint64((*Tsqlite3)(unsafe.Pointer(db)).Fflags & libc.Uint64FromInt32(SQLITE_LegacyAlter))
if (**(**TParse)(__ccgo_up(bp))).FpNewTable != 0 {
pTab = (**(**TParse)(__ccgo_up(bp))).FpNewTable
if libc.Int32FromUint8((*TTable)(unsafe.Pointer(pTab)).FeTabType) == int32(TABTYP_VIEW) {
if isLegacy == 0 {
pSelect = (*(*struct {
FpSelect uintptr
})(unsafe.Pointer(&(*TTable)(unsafe.Pointer(pTab)).Fu))).FpSelect
libc.X__builtin___memset_chk(tls, bp+504, 0, uint64(56), ^t__predefined_size_t(0))
(**(**TNameContext)(__ccgo_up(bp + 504))).FpParse = bp
**(**Tu32)(__ccgo_up(pSelect + 4)) &= ^libc.Uint32FromInt32(SF_View)
_sqlite3SelectPrep(tls, bp, (*(*struct {
FpSelect uintptr
})(unsafe.Pointer(&(*TTable)(unsafe.Pointer(pTab)).Fu))).FpSelect, bp+504)
if (**(**TParse)(__ccgo_up(bp))).FnErr != 0 {
rc = (**(**TParse)(__ccgo_up(bp))).Frc
} else {
_sqlite3WalkSelect(tls, bp+456, (*(*struct {
FpSelect uintptr
})(unsafe.Pointer(&(*TTable)(unsafe.Pointer(pTab)).Fu))).FpSelect)
}
}
} else {
/* Modify any FK definitions to point to the new table. */
if (isLegacy == 0 || (*Tsqlite3)(unsafe.Pointer(db)).Fflags&uint64(SQLITE_ForeignKeys) != 0) && !(libc.Int32FromUint8((*TTable)(unsafe.Pointer(pTab)).FeTabType) == libc.Int32FromInt32(TABTYP_VTAB)) {
pFKey = (*(*struct {
FaddColOffset int32
FpFKey uintptr
FpDfltList uintptr
})(unsafe.Pointer(pTab + 64))).FpFKey
for {
if !(pFKey != 0) {
break
}
if Xsqlite3_stricmp(tls, (*TFKey)(unsafe.Pointer(pFKey)).FzTo, zOld) == 0 {
_renameTokenFind(tls, bp, bp+424, (*TFKey)(unsafe.Pointer(pFKey)).FzTo)
}
goto _1
_1:
;
pFKey = (*TFKey)(unsafe.Pointer(pFKey)).FpNextFrom
}
}
/* If this is the table being altered, fix any table refs in CHECK
** expressions. Also update the name that appears right after the
** "CREATE [VIRTUAL] TABLE" bit. */
if Xsqlite3_stricmp(tls, zOld, (*TTable)(unsafe.Pointer(pTab)).FzName) == 0 {
(**(**TRenameCtx)(__ccgo_up(bp + 424))).FpTab = pTab
if isLegacy == 0 {
_sqlite3WalkExprList(tls, bp+456, (*TTable)(unsafe.Pointer(pTab)).FpCheck)
}
_renameTokenFind(tls, bp, bp+424, (*TTable)(unsafe.Pointer(pTab)).FzName)
}
}
} else {
if (**(**TParse)(__ccgo_up(bp))).FpNewIndex != 0 {
_renameTokenFind(tls, bp, bp+424, (*TIndex)(unsafe.Pointer((**(**TParse)(__ccgo_up(bp))).FpNewIndex)).FzName)
if isLegacy == 0 {
_sqlite3WalkExpr(tls, bp+456, (*TIndex)(unsafe.Pointer((**(**TParse)(__ccgo_up(bp))).FpNewIndex)).FpPartIdxWhere)
}
} else {
pTrigger = (**(**TParse)(__ccgo_up(bp))).FpNewTrigger
if 0 == Xsqlite3_stricmp(tls, (*TTrigger)(unsafe.Pointer((**(**TParse)(__ccgo_up(bp))).FpNewTrigger)).Ftable, zOld) && (*TTable)(unsafe.Pointer((**(**TRenameCtx)(__ccgo_up(bp + 424))).FpTab)).FpSchema == (*TTrigger)(unsafe.Pointer(pTrigger)).FpTabSchema {
_renameTokenFind(tls, bp, bp+424, (*TTrigger)(unsafe.Pointer((**(**TParse)(__ccgo_up(bp))).FpNewTrigger)).Ftable)
}
if isLegacy == 0 {
rc = _renameResolveTrigger(tls, bp)
if rc == SQLITE_OK {
_renameWalkTrigger(tls, bp+456, pTrigger)
pStep = (*TTrigger)(unsafe.Pointer(pTrigger)).Fstep_list
for {
if !(pStep != 0) {
break
}
if (*TTriggerStep)(unsafe.Pointer(pStep)).FpSrc != 0 {
i = 0
for {
if !(i < (*TSrcList)(unsafe.Pointer((*TTriggerStep)(unsafe.Pointer(pStep)).FpSrc)).FnSrc) {
break
}
pItem = (*TTriggerStep)(unsafe.Pointer(pStep)).FpSrc + 8 + uintptr(i)*80
if 0 == Xsqlite3_stricmp(tls, (*TSrcItem)(unsafe.Pointer(pItem)).FzName, zOld) {
_renameTokenFind(tls, bp, bp+424, (*TSrcItem)(unsafe.Pointer(pItem)).FzName)
}
goto _3
_3:
;
i = i + 1
}
}
goto _2
_2:
;
pStep = (*TTriggerStep)(unsafe.Pointer(pStep)).FpNext
}
}
}
}
}
}
if rc == SQLITE_OK {
rc = _renameEditSql(tls, context, bp+424, zInput, zNew, bQuote)
}
if rc != SQLITE_OK {
if rc == int32(SQLITE_ERROR) && _sqlite3WritableSchema(tls, db) != 0 {
Xsqlite3_result_value(tls, context, **(**uintptr)(__ccgo_up(argv + 3*8)))
} else {
if (**(**TParse)(__ccgo_up(bp))).FzErrMsg != 0 {
_renameColumnParseError(tls, context, __ccgo_ts+1702, **(**uintptr)(__ccgo_up(argv + 1*8)), **(**uintptr)(__ccgo_up(argv + 2*8)), bp)
} else {
Xsqlite3_result_error_code(tls, context, rc)
}
}
}
_renameParseCleanup(tls, bp)
_renameTokenFree(tls, db, (**(**TRenameCtx)(__ccgo_up(bp + 424))).FpList)
_sqlite3BtreeLeaveAll(tls, db)
(*Tsqlite3)(unsafe.Pointer(db)).FxAuth = xAuth
}
return
}
// C documentation
//
// /* Function: sqlite_rename_test(DB,SQL,TYPE,NAME,ISTEMP,WHEN,DQS)
// **
// ** An SQL user function that checks that there are no parse or symbol
// ** resolution problems in a CREATE TRIGGER|TABLE|VIEW|INDEX statement.
// ** After an ALTER TABLE .. RENAME operation is performed and the schema
// ** reloaded, this function is called on each SQL statement in the schema
// ** to ensure that it is still usable.
// **
// ** 0: Database name ("main", "temp" etc.).
// ** 1: SQL statement.
// ** 2: Object type ("view", "table", "trigger" or "index").
// ** 3: Object name.
// ** 4: True if object is from temp schema.
// ** 5: "when" part of error message.
// ** 6: True to disable the DQS quirk when parsing SQL.
// **
// ** The return value is computed as follows:
// **
// ** A. If an error is seen and not in PRAGMA writable_schema=ON mode,
// ** then raise the error.
// ** B. Else if a trigger is created and the the table that the trigger is
// ** attached to is in database zDb, then return 1.
// ** C. Otherwise return NULL.
// */
func _renameTableTest(tls *libc.TLS, context uintptr, NotUsed int32, argv uintptr) {
bp := tls.Alloc(480)
defer tls.Free(480)
var bNoDQS, bTemp, i1, i2, isLegacy, rc int32
var db, zDb, zInput, zWhen uintptr
var flags Tu64
var xAuth Tsqlite3_xauth
var _ /* sNC at bp+424 */ TNameContext
var _ /* sParse at bp+0 */ TParse
_, _, _, _, _, _, _, _, _, _, _, _ = bNoDQS, bTemp, db, flags, i1, i2, isLegacy, rc, xAuth, zDb, zInput, zWhen
db = Xsqlite3_context_db_handle(tls, context)
zDb = Xsqlite3_value_text(tls, **(**uintptr)(__ccgo_up(argv)))
zInput = Xsqlite3_value_text(tls, **(**uintptr)(__ccgo_up(argv + 1*8)))
bTemp = Xsqlite3_value_int(tls, **(**uintptr)(__ccgo_up(argv + 4*8)))
isLegacy = libc.Int32FromUint64((*Tsqlite3)(unsafe.Pointer(db)).Fflags & libc.Uint64FromInt32(SQLITE_LegacyAlter))
zWhen = Xsqlite3_value_text(tls, **(**uintptr)(__ccgo_up(argv + 5*8)))
bNoDQS = Xsqlite3_value_int(tls, **(**uintptr)(__ccgo_up(argv + 6*8)))
xAuth = (*Tsqlite3)(unsafe.Pointer(db)).FxAuth
(*Tsqlite3)(unsafe.Pointer(db)).FxAuth = uintptr(0)
_ = NotUsed
if zDb != 0 && zInput != 0 {
flags = (*Tsqlite3)(unsafe.Pointer(db)).Fflags
if bNoDQS != 0 {
**(**Tu64)(__ccgo_up(db + 48)) &= libc.Uint64FromInt32(^(libc.Int32FromInt32(SQLITE_DqsDML) | libc.Int32FromInt32(SQLITE_DqsDDL)))
}
rc = _renameParseSql(tls, bp, zDb, db, zInput, bTemp)
(*Tsqlite3)(unsafe.Pointer(db)).Fflags = flags
if rc == SQLITE_OK {
if isLegacy == 0 && (**(**TParse)(__ccgo_up(bp))).FpNewTable != 0 && libc.Int32FromUint8((*TTable)(unsafe.Pointer((**(**TParse)(__ccgo_up(bp))).FpNewTable)).FeTabType) == int32(TABTYP_VIEW) {
libc.X__builtin___memset_chk(tls, bp+424, 0, uint64(56), ^t__predefined_size_t(0))
(**(**TNameContext)(__ccgo_up(bp + 424))).FpParse = bp
_sqlite3SelectPrep(tls, bp, (*(*struct {
FpSelect uintptr
})(unsafe.Pointer(&(*TTable)(unsafe.Pointer((**(**TParse)(__ccgo_up(bp))).FpNewTable)).Fu))).FpSelect, bp+424)
if (**(**TParse)(__ccgo_up(bp))).FnErr != 0 {
rc = (**(**TParse)(__ccgo_up(bp))).Frc
}
} else {
if (**(**TParse)(__ccgo_up(bp))).FpNewTrigger != 0 {
if isLegacy == 0 {
rc = _renameResolveTrigger(tls, bp)
}
if rc == SQLITE_OK {
i1 = _sqlite3SchemaToIndex(tls, db, (*TTrigger)(unsafe.Pointer((**(**TParse)(__ccgo_up(bp))).FpNewTrigger)).FpTabSchema)
i2 = _sqlite3FindDbName(tls, db, zDb)
if i1 == i2 {
/* Handle output case B */
Xsqlite3_result_int(tls, context, int32(1))
}
}
}
}
}
if rc != SQLITE_OK && zWhen != 0 && !(_sqlite3WritableSchema(tls, db) != 0) {
/* Output case A */
_renameColumnParseError(tls, context, zWhen, **(**uintptr)(__ccgo_up(argv + 2*8)), **(**uintptr)(__ccgo_up(argv + 3*8)), bp)
}
_renameParseCleanup(tls, bp)
}
(*Tsqlite3)(unsafe.Pointer(db)).FxAuth = xAuth
}
// C documentation
//
// /*
// ** Generate code to verify that the schemas of database zDb and, if
// ** bTemp is not true, database "temp", can still be parsed. This is
// ** called at the end of the generation of an ALTER TABLE ... RENAME ...
// ** statement to ensure that the operation has not rendered any schema
// ** objects unusable.
// */
func _renameTestSchema(tls *libc.TLS, pParse uintptr, zDb uintptr, bTemp int32, zWhen uintptr, bNoDQS int32) {
bp := tls.Alloc(48)
defer tls.Free(48)
libc.SetBitFieldPtr16Uint32(pParse+40, libc.Uint32FromInt32(1), 5, 0x20)
_sqlite3NestedParse(tls, pParse, __ccgo_ts+9019, libc.VaList(bp+8, zDb, zDb, bTemp, zWhen, bNoDQS))
if bTemp == 0 {
_sqlite3NestedParse(tls, pParse, __ccgo_ts+9194, libc.VaList(bp+8, zDb, zWhen, bNoDQS))
}
}
// C documentation
//
// /*
// ** Iterate through the Select objects that are part of WITH clauses attached
// ** to select statement pSelect.
// */
func _renameWalkWith(tls *libc.TLS, pWalker uintptr, pSelect uintptr) {
bp := tls.Alloc(64)
defer tls.Free(64)
var i int32
var p, pCopy, pParse, pWith uintptr
var _ /* sNC at bp+0 */ TNameContext
_, _, _, _, _ = i, p, pCopy, pParse, pWith
pWith = (*TSelect)(unsafe.Pointer(pSelect)).FpWith
if pWith != 0 {
pParse = (*TWalker)(unsafe.Pointer(pWalker)).FpParse
pCopy = uintptr(0)
if (*TSelect)(unsafe.Pointer((*(*TCte)(unsafe.Pointer(pWith + 16))).FpSelect)).FselFlags&uint32(SF_Expanded) == uint32(0) {
/* Push a copy of the With object onto the with-stack. We use a copy
** here as the original will be expanded and resolved (flags SF_Expanded
** and SF_Resolved) below. And the parser code that uses the with-stack
** fails if the Select objects on it have already been expanded and
** resolved. */
pCopy = _sqlite3WithDup(tls, (*TParse)(unsafe.Pointer(pParse)).Fdb, pWith)
pCopy = _sqlite3WithPush(tls, pParse, pCopy, uint8(1))
}
i = 0
for {
if !(i < (*TWith)(unsafe.Pointer(pWith)).FnCte) {
break
}
p = (*(*TCte)(unsafe.Pointer(pWith + 16 + uintptr(i)*48))).FpSelect
libc.X__builtin___memset_chk(tls, bp, 0, uint64(56), ^t__predefined_size_t(0))
(**(**TNameContext)(__ccgo_up(bp))).FpParse = pParse
if pCopy != 0 {
_sqlite3SelectPrep(tls, (**(**TNameContext)(__ccgo_up(bp))).FpParse, p, bp)
}
if (*Tsqlite3)(unsafe.Pointer((*TParse)(unsafe.Pointer((**(**TNameContext)(__ccgo_up(bp))).FpParse)).Fdb)).FmallocFailed != 0 {
return
}
_sqlite3WalkSelect(tls, pWalker, p)
_sqlite3RenameExprlistUnmap(tls, pParse, (*(*TCte)(unsafe.Pointer(pWith + 16 + uintptr(i)*48))).FpCols)
goto _1
_1:
;
i = i + 1
}
if pCopy != 0 && (*TParse)(unsafe.Pointer(pParse)).FpWith == pCopy {
(*TParse)(unsafe.Pointer(pParse)).FpWith = (*TWith)(unsafe.Pointer(pCopy)).FpOuter
}
}
}
// C documentation
//
// /*
// ** Assign a new cursor number to each cursor in the FROM clause (Select.pSrc)
// ** of the SELECT statement passed as the second argument, and to each
// ** cursor in the FROM clause of any FROM clause sub-selects, recursively.
// ** Except, do not assign a new cursor number to the iExcept'th element in
// ** the FROM clause of (*p). Update all expressions and other references
// ** to refer to the new cursor numbers.
// **
// ** Argument aCsrMap is an array that may be used for temporary working
// ** space. Two guarantees are made by the caller:
// **
// ** * the array is larger than the largest cursor number used within the
// ** select statement passed as an argument, and
// **
// ** * the array entries for all cursor numbers that do *not* appear in
// ** FROM clauses of the select statement as described above are
// ** initialized to zero.
// */
func _renumberCursors(tls *libc.TLS, pParse uintptr, p uintptr, iExcept int32, aCsrMap uintptr) {
bp := tls.Alloc(48)
defer tls.Free(48)
var _ /* w at bp+0 */ TWalker
_srclistRenumberCursors(tls, pParse, aCsrMap, (*TSelect)(unsafe.Pointer(p)).FpSrc, iExcept)
libc.X__builtin___memset_chk(tls, bp, 0, uint64(48), ^t__predefined_size_t(0))
*(*uintptr)(unsafe.Pointer(bp + 40)) = aCsrMap
(**(**TWalker)(__ccgo_up(bp))).FxExprCallback = __ccgo_fp(_renumberCursorsCb)
(**(**TWalker)(__ccgo_up(bp))).FxSelectCallback = __ccgo_fp(_sqlite3SelectWalkNoop)
_sqlite3WalkSelect(tls, bp, p)
}
// C documentation
//
// /*
// ** The replace() function. Three arguments are all strings: call
// ** them A, B, and C. The result is also a string which is derived
// ** from A by replacing every occurrence of B with C. The match
// ** must be exact. Collating sequences are not used.
// */
func _replaceFunc(tls *libc.TLS, context uintptr, argc int32, argv uintptr) {
var cntExpand uint32
var db, zOld, zOut, zPattern, zRep, zStr uintptr
var i, j, loopLimit, nPattern, nRep, nStr, v2, v3 int32
var nOut Ti64
_, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _ = cntExpand, db, i, j, loopLimit, nOut, nPattern, nRep, nStr, zOld, zOut, zPattern, zRep, zStr, v2, v3 /* Number zOut expansions */
db = Xsqlite3_context_db_handle(tls, context)
_ = argc
zStr = Xsqlite3_value_text(tls, **(**uintptr)(__ccgo_up(argv)))
if zStr == uintptr(0) {
return
}
nStr = Xsqlite3_value_bytes(tls, **(**uintptr)(__ccgo_up(argv)))
/* No encoding change */
zPattern = Xsqlite3_value_text(tls, **(**uintptr)(__ccgo_up(argv + 1*8)))
if zPattern == uintptr(0) {
return
}
if libc.Int32FromUint8(**(**uint8)(__ccgo_up(zPattern))) == 0 {
Xsqlite3_result_text(tls, context, zStr, nStr, uintptr(-libc.Int32FromInt32(1)))
return
}
nPattern = Xsqlite3_value_bytes(tls, **(**uintptr)(__ccgo_up(argv + 1*8)))
/* No encoding change */
zRep = Xsqlite3_value_text(tls, **(**uintptr)(__ccgo_up(argv + 2*8)))
if zRep == uintptr(0) {
return
}
nRep = Xsqlite3_value_bytes(tls, **(**uintptr)(__ccgo_up(argv + 2*8)))
nOut = int64(nStr + int32(1))
zOut = _contextMalloc(tls, context, nOut)
if zOut == uintptr(0) {
return
}
loopLimit = nStr - nPattern
cntExpand = uint32(0)
v2 = libc.Int32FromInt32(0)
j = v2
i = v2
for {
if !(i <= loopLimit) {
break
}
if libc.Int32FromUint8(**(**uint8)(__ccgo_up(zStr + uintptr(i)))) != libc.Int32FromUint8(**(**uint8)(__ccgo_up(zPattern))) || libc.Xmemcmp(tls, zStr+uintptr(i), zPattern, libc.Uint64FromInt32(nPattern)) != 0 {
v3 = j
j = j + 1
**(**uint8)(__ccgo_up(zOut + uintptr(v3))) = **(**uint8)(__ccgo_up(zStr + uintptr(i)))
} else {
if nRep > nPattern {
nOut = nOut + int64(nRep-nPattern)
if nOut-int64(1) > int64(**(**int32)(__ccgo_up(db + 136))) {
Xsqlite3_result_error_toobig(tls, context)
Xsqlite3_free(tls, zOut)
return
}
cntExpand = cntExpand + 1
if cntExpand&(cntExpand-uint32(1)) == uint32(0) {
zOld = zOut
zOut = _sqlite3Realloc(tls, zOut, libc.Uint64FromInt64(int64(int32(nOut))+(nOut-int64(nStr)-int64(1))))
if zOut == uintptr(0) {
Xsqlite3_result_error_nomem(tls, context)
Xsqlite3_free(tls, zOld)
return
}
}
}
libc.X__builtin___memcpy_chk(tls, zOut+uintptr(j), zRep, libc.Uint64FromInt32(nRep), ^t__predefined_size_t(0))
j = j + nRep
i = i + (nPattern - int32(1))
}
goto _1
_1:
;
i = i + 1
}
libc.X__builtin___memcpy_chk(tls, zOut+uintptr(j), zStr+uintptr(i), libc.Uint64FromInt32(nStr-i), ^t__predefined_size_t(0))
j = j + (nStr - i)
**(**uint8)(__ccgo_up(zOut + uintptr(j))) = uint8(0)
Xsqlite3_result_text(tls, context, zOut, j, __ccgo_fp(Xsqlite3_free))
}
// C documentation
//
// /*
// ** Reset the aggregate accumulator.
// **
// ** The aggregate accumulator is a set of memory cells that hold
// ** intermediate results while calculating an aggregate. This
// ** routine generates code that stores NULLs in all of those memory
// ** cells.
// */
func _resetAccumulator(tls *libc.TLS, pParse uintptr, pAggInfo uintptr) {
bp := tls.Alloc(16)
defer tls.Free(16)
var i, nExtra, nReg int32
var pE, pFunc, pKeyInfo, pKeyInfo1, pOBList, v uintptr
_, _, _, _, _, _, _, _, _ = i, nExtra, nReg, pE, pFunc, pKeyInfo, pKeyInfo1, pOBList, v
v = (*TParse)(unsafe.Pointer(pParse)).FpVdbe
nReg = (*TAggInfo)(unsafe.Pointer(pAggInfo)).FnFunc + (*TAggInfo)(unsafe.Pointer(pAggInfo)).FnColumn
if nReg == 0 {
return
}
if (*TParse)(unsafe.Pointer(pParse)).FnErr != 0 {
return
}
_sqlite3VdbeAddOp3(tls, v, int32(OP_Null), 0, (*TAggInfo)(unsafe.Pointer(pAggInfo)).FiFirstReg, (*TAggInfo)(unsafe.Pointer(pAggInfo)).FiFirstReg+nReg-int32(1))
pFunc = (*TAggInfo)(unsafe.Pointer(pAggInfo)).FaFunc
i = libc.Int32FromInt32(0)
for {
if !(i < (*TAggInfo)(unsafe.Pointer(pAggInfo)).FnFunc) {
break
}
if (*TAggInfo_func)(unsafe.Pointer(pFunc)).FiDistinct >= 0 {
pE = (*TAggInfo_func)(unsafe.Pointer(pFunc)).FpFExpr
if *(*uintptr)(unsafe.Pointer(pE + 32)) == uintptr(0) || (*TExprList)(unsafe.Pointer(*(*uintptr)(unsafe.Pointer(pE + 32)))).FnExpr != int32(1) {
_sqlite3ErrorMsg(tls, pParse, __ccgo_ts+21803, 0)
(*TAggInfo_func)(unsafe.Pointer(pFunc)).FiDistinct = -int32(1)
} else {
pKeyInfo = _sqlite3KeyInfoFromExprList(tls, pParse, *(*uintptr)(unsafe.Pointer(pE + 32)), 0, 0)
(*TAggInfo_func)(unsafe.Pointer(pFunc)).FiDistAddr = _sqlite3VdbeAddOp4(tls, v, int32(OP_OpenEphemeral), (*TAggInfo_func)(unsafe.Pointer(pFunc)).FiDistinct, 0, 0, pKeyInfo, -int32(9))
_sqlite3VdbeExplain(tls, pParse, uint8(0), __ccgo_ts+21854, libc.VaList(bp+8, (*TFuncDef)(unsafe.Pointer((*TAggInfo_func)(unsafe.Pointer(pFunc)).FpFunc)).FzName))
}
}
if (*TAggInfo_func)(unsafe.Pointer(pFunc)).FiOBTab >= 0 {
nExtra = 0
pOBList = *(*uintptr)(unsafe.Pointer((*TExpr)(unsafe.Pointer((*TAggInfo_func)(unsafe.Pointer(pFunc)).FpFExpr)).FpLeft + 32))
if !((*TAggInfo_func)(unsafe.Pointer(pFunc)).FbOBUnique != 0) {
nExtra = nExtra + 1 /* One extra column for the OP_Sequence */
}
if (*TAggInfo_func)(unsafe.Pointer(pFunc)).FbOBPayload != 0 {
/* extra columns for the function arguments */
nExtra = nExtra + (*TExprList)(unsafe.Pointer(*(*uintptr)(unsafe.Pointer((*TAggInfo_func)(unsafe.Pointer(pFunc)).FpFExpr + 32)))).FnExpr
}
if (*TAggInfo_func)(unsafe.Pointer(pFunc)).FbUseSubtype != 0 {
nExtra = nExtra + (*TExprList)(unsafe.Pointer(*(*uintptr)(unsafe.Pointer((*TAggInfo_func)(unsafe.Pointer(pFunc)).FpFExpr + 32)))).FnExpr
}
pKeyInfo1 = _sqlite3KeyInfoFromExprList(tls, pParse, pOBList, 0, nExtra)
if !((*TAggInfo_func)(unsafe.Pointer(pFunc)).FbOBUnique != 0) && (*TParse)(unsafe.Pointer(pParse)).FnErr == 0 {
(*TKeyInfo)(unsafe.Pointer(pKeyInfo1)).FnKeyField = (*TKeyInfo)(unsafe.Pointer(pKeyInfo1)).FnKeyField + 1
}
_sqlite3VdbeAddOp4(tls, v, int32(OP_OpenEphemeral), (*TAggInfo_func)(unsafe.Pointer(pFunc)).FiOBTab, (*TExprList)(unsafe.Pointer(pOBList)).FnExpr+nExtra, 0, pKeyInfo1, -int32(9))
_sqlite3VdbeExplain(tls, pParse, uint8(0), __ccgo_ts+21887, libc.VaList(bp+8, (*TFuncDef)(unsafe.Pointer((*TAggInfo_func)(unsafe.Pointer(pFunc)).FpFunc)).FzName))
}
goto _1
_1:
;
i = i + 1
pFunc += 32
}
}
// C documentation
//
// /*
// ** Reset a cursor back to its initial state.
// */
func _resetCursor(tls *libc.TLS, pCsr uintptr) {
var i, ii int32
var pInfo, pRtree, pStmt uintptr
_, _, _, _, _ = i, ii, pInfo, pRtree, pStmt
pRtree = (*TRtreeCursor)(unsafe.Pointer(pCsr)).Fbase.FpVtab
if (*TRtreeCursor)(unsafe.Pointer(pCsr)).FaConstraint != 0 { /* Used to iterate through constraint array */
i = 0
for {
if !(i < (*TRtreeCursor)(unsafe.Pointer(pCsr)).FnConstraint) {
break
}
pInfo = (**(**TRtreeConstraint)(__ccgo_up((*TRtreeCursor)(unsafe.Pointer(pCsr)).FaConstraint + uintptr(i)*24))).FpInfo
if pInfo != 0 {
if (*Tsqlite3_rtree_query_info)(unsafe.Pointer(pInfo)).FxDelUser != 0 {
(*(*func(*libc.TLS, uintptr))(unsafe.Pointer(&struct{ uintptr }{(*Tsqlite3_rtree_query_info)(unsafe.Pointer(pInfo)).FxDelUser})))(tls, (*Tsqlite3_rtree_query_info)(unsafe.Pointer(pInfo)).FpUser)
}
Xsqlite3_free(tls, pInfo)
}
goto _1
_1:
;
i = i + 1
}
Xsqlite3_free(tls, (*TRtreeCursor)(unsafe.Pointer(pCsr)).FaConstraint)
(*TRtreeCursor)(unsafe.Pointer(pCsr)).FaConstraint = uintptr(0)
}
ii = 0
for {
if !(ii < int32(RTREE_CACHE_SZ)) {
break
}
_nodeRelease(tls, pRtree, **(**uintptr)(__ccgo_up(pCsr + 88 + uintptr(ii)*8)))
goto _2
_2:
;
ii = ii + 1
}
Xsqlite3_free(tls, (*TRtreeCursor)(unsafe.Pointer(pCsr)).FaPoint)
pStmt = (*TRtreeCursor)(unsafe.Pointer(pCsr)).FpReadAux
libc.X__builtin___memset_chk(tls, pCsr, 0, uint64(296), ^t__predefined_size_t(0))
(*TRtreeCursor)(unsafe.Pointer(pCsr)).Fbase.FpVtab = pRtree
(*TRtreeCursor)(unsafe.Pointer(pCsr)).FpReadAux = pStmt
/* The following will only fail if the previous sqlite3_step() call failed,
** in which case the error has already been caught. This statement never
** encounters an error within an sqlite3_column_xxx() function, as it
** calls sqlite3_column_value(), which does not use malloc(). So it is safe
** to ignore the error code here. */
Xsqlite3_reset(tls, pStmt)
}
// C documentation
//
// /*
// ** Resize an Index object to hold N columns total. Return SQLITE_OK
// ** on success and SQLITE_NOMEM on an OOM error.
// */
func _resizeIndexObject(tls *libc.TLS, pParse uintptr, pIdx uintptr, N int32) (r int32) {
var db, zExtra uintptr
var nByte Tu64
_, _, _ = db, nByte, zExtra
if libc.Int32FromUint16((*TIndex)(unsafe.Pointer(pIdx)).FnColumn) >= N {
return SQLITE_OK
}
db = (*TParse)(unsafe.Pointer(pParse)).Fdb
nByte = uint64(libc.Uint64FromInt64(8)+libc.Uint64FromInt64(2)+libc.Uint64FromInt64(2)+libc.Uint64FromInt32(1)) * libc.Uint64FromInt32(N)
zExtra = _sqlite3DbMallocZero(tls, db, nByte)
if zExtra == uintptr(0) {
return int32(SQLITE_NOMEM)
}
libc.X__builtin___memcpy_chk(tls, zExtra, (*TIndex)(unsafe.Pointer(pIdx)).FazColl, uint64(8)*uint64((*TIndex)(unsafe.Pointer(pIdx)).FnColumn), ^t__predefined_size_t(0))
(*TIndex)(unsafe.Pointer(pIdx)).FazColl = zExtra
zExtra = zExtra + uintptr(uint64(8)*libc.Uint64FromInt32(N))
libc.X__builtin___memcpy_chk(tls, zExtra, (*TIndex)(unsafe.Pointer(pIdx)).FaiRowLogEst, uint64(2)*libc.Uint64FromInt32(libc.Int32FromUint16((*TIndex)(unsafe.Pointer(pIdx)).FnKeyCol)+libc.Int32FromInt32(1)), ^t__predefined_size_t(0))
(*TIndex)(unsafe.Pointer(pIdx)).FaiRowLogEst = zExtra
zExtra = zExtra + uintptr(uint64(2)*libc.Uint64FromInt32(N))
libc.X__builtin___memcpy_chk(tls, zExtra, (*TIndex)(unsafe.Pointer(pIdx)).FaiColumn, uint64(2)*uint64((*TIndex)(unsafe.Pointer(pIdx)).FnColumn), ^t__predefined_size_t(0))
(*TIndex)(unsafe.Pointer(pIdx)).FaiColumn = zExtra
zExtra = zExtra + uintptr(uint64(2)*libc.Uint64FromInt32(N))
libc.X__builtin___memcpy_chk(tls, zExtra, (*TIndex)(unsafe.Pointer(pIdx)).FaSortOrder, uint64((*TIndex)(unsafe.Pointer(pIdx)).FnColumn), ^t__predefined_size_t(0))
(*TIndex)(unsafe.Pointer(pIdx)).FaSortOrder = zExtra
(*TIndex)(unsafe.Pointer(pIdx)).FnColumn = libc.Uint16FromInt32(N) /* See tag-20250221-1 above for proof of safety */
libc.SetBitFieldPtr16Uint32(pIdx+100, libc.Uint32FromInt32(1), 4, 0x10)
return SQLITE_OK
}
// C documentation
//
// /*
// ** Turn the pExpr expression into an alias for the iCol-th column of the
// ** result set in pEList.
// **
// ** If the reference is followed by a COLLATE operator, then make sure
// ** the COLLATE operator is preserved. For example:
// **
// ** SELECT a+b, c+d FROM t1 ORDER BY 1 COLLATE nocase;
// **
// ** Should be transformed into:
// **
// ** SELECT a+b, c+d FROM t1 ORDER BY (a+b) COLLATE nocase;
// **
// ** The nSubquery parameter specifies how many levels of subquery the
// ** alias is removed from the original expression. The usual value is
// ** zero but it might be more if the alias is contained within a subquery
// ** of the original expression. The Expr.op2 field of TK_AGG_FUNCTION
// ** structures must be increased by the nSubquery amount.
// */
func _resolveAlias(tls *libc.TLS, pParse uintptr, pEList uintptr, iCol int32, pExpr uintptr, nSubquery int32) {
bp := tls.Alloc(80)
defer tls.Free(80)
var db, pDup, pOrig uintptr
var _ /* temp at bp+0 */ TExpr
_, _, _ = db, pDup, pOrig /* The database connection */
pOrig = (*(*TExprList_item)(unsafe.Pointer(pEList + 8 + uintptr(iCol)*32))).FpExpr
if (*TExpr)(unsafe.Pointer(pExpr)).FpAggInfo != 0 {
return
}
db = (*TParse)(unsafe.Pointer(pParse)).Fdb
pDup = _sqlite3ExprDup(tls, db, pOrig, 0)
if (*Tsqlite3)(unsafe.Pointer(db)).FmallocFailed != 0 {
_sqlite3ExprDelete(tls, db, pDup)
pDup = uintptr(0)
} else {
_incrAggFunctionDepth(tls, pDup, nSubquery)
if libc.Int32FromUint8((*TExpr)(unsafe.Pointer(pExpr)).Fop) == int32(TK_COLLATE) {
pDup = _sqlite3ExprAddCollateString(tls, pParse, pDup, *(*uintptr)(unsafe.Pointer(pExpr + 8)))
}
libc.X__builtin___memcpy_chk(tls, bp, pDup, uint64(72), ^t__predefined_size_t(0))
libc.X__builtin___memcpy_chk(tls, pDup, pExpr, uint64(72), ^t__predefined_size_t(0))
libc.X__builtin___memcpy_chk(tls, pExpr, bp, uint64(72), ^t__predefined_size_t(0))
if (*TExpr)(unsafe.Pointer(pExpr)).Fflags&libc.Uint32FromInt32(libc.Int32FromInt32(EP_WinFunc)) != uint32(0) {
if *(*uintptr)(unsafe.Pointer(pExpr + 64)) != uintptr(0) {
(*TWindow)(unsafe.Pointer(*(*uintptr)(unsafe.Pointer(pExpr + 64)))).FpOwner = pExpr
}
}
_sqlite3ExprDeferredDelete(tls, pParse, pDup)
}
}
// C documentation
//
// /*
// ** Analyze the ORDER BY clause in a compound SELECT statement. Modify
// ** each term of the ORDER BY clause is a constant integer between 1
// ** and N where N is the number of columns in the compound SELECT.
// **
// ** ORDER BY terms that are already an integer between 1 and N are
// ** unmodified. ORDER BY terms that are integers outside the range of
// ** 1 through N generate an error. ORDER BY terms that are expressions
// ** are matched against result set expressions of compound SELECT
// ** beginning with the left-most SELECT and working toward the right.
// ** At the first match, the ORDER BY expression is transformed into
// ** the integer column number.
// **
// ** Return the number of errors seen.
// */
func _resolveCompoundOrderBy(tls *libc.TLS, pParse uintptr, pSelect uintptr) (r int32) {
bp := tls.Alloc(32)
defer tls.Free(32)
var db, pDup, pE, pEList, pItem, pNew, pOrderBy, pParent uintptr
var i, moreToDo int32
var _ /* iCol at bp+0 */ int32
_, _, _, _, _, _, _, _, _, _ = db, i, moreToDo, pDup, pE, pEList, pItem, pNew, pOrderBy, pParent
moreToDo = int32(1)
pOrderBy = (*TSelect)(unsafe.Pointer(pSelect)).FpOrderBy
if pOrderBy == uintptr(0) {
return 0
}
db = (*TParse)(unsafe.Pointer(pParse)).Fdb
if (*TExprList)(unsafe.Pointer(pOrderBy)).FnExpr > **(**int32)(__ccgo_up(db + 136 + 2*4)) {
_sqlite3ErrorMsg(tls, pParse, __ccgo_ts+7973, 0)
return int32(1)
}
i = 0
for {
if !(i < (*TExprList)(unsafe.Pointer(pOrderBy)).FnExpr) {
break
}
libc.SetBitFieldPtr16Uint32(pOrderBy+8+uintptr(i)*32+16+4, libc.Uint32FromInt32(0), 2, 0x4)
goto _1
_1:
;
i = i + 1
}
(*TSelect)(unsafe.Pointer(pSelect)).FpNext = uintptr(0)
for (*TSelect)(unsafe.Pointer(pSelect)).FpPrior != 0 {
(*TSelect)(unsafe.Pointer((*TSelect)(unsafe.Pointer(pSelect)).FpPrior)).FpNext = pSelect
pSelect = (*TSelect)(unsafe.Pointer(pSelect)).FpPrior
}
for pSelect != 0 && moreToDo != 0 {
moreToDo = 0
pEList = (*TSelect)(unsafe.Pointer(pSelect)).FpEList
i = 0
pItem = pOrderBy + 8
for {
if !(i < (*TExprList)(unsafe.Pointer(pOrderBy)).FnExpr) {
break
}
**(**int32)(__ccgo_up(bp)) = -int32(1)
if int32(uint32(*(*uint16)(unsafe.Pointer(pItem + 16 + 4))&0x4>>2)) != 0 {
goto _2
}
pE = _sqlite3ExprSkipCollateAndLikely(tls, (*TExprList_item)(unsafe.Pointer(pItem)).FpExpr)
if pE == uintptr(0) {
goto _2
}
if _sqlite3ExprIsInteger(tls, pE, bp, uintptr(0)) != 0 {
if **(**int32)(__ccgo_up(bp)) <= 0 || **(**int32)(__ccgo_up(bp)) > (*TExprList)(unsafe.Pointer(pEList)).FnExpr {
_resolveOutOfRangeError(tls, pParse, __ccgo_ts+8007, i+int32(1), (*TExprList)(unsafe.Pointer(pEList)).FnExpr, pE)
return int32(1)
}
} else {
**(**int32)(__ccgo_up(bp)) = _resolveAsName(tls, pParse, pEList, pE)
if **(**int32)(__ccgo_up(bp)) == 0 {
/* Now test if expression pE matches one of the values returned
** by pSelect. In the usual case this is done by duplicating the
** expression, resolving any symbols in it, and then comparing
** it against each expression returned by the SELECT statement.
** Once the comparisons are finished, the duplicate expression
** is deleted.
**
** If this is running as part of an ALTER TABLE operation and
** the symbols resolve successfully, also resolve the symbols in the
** actual expression. This allows the code in alter.c to modify
** column references within the ORDER BY expression as required. */
pDup = _sqlite3ExprDup(tls, db, pE, 0)
if !((*Tsqlite3)(unsafe.Pointer(db)).FmallocFailed != 0) {
**(**int32)(__ccgo_up(bp)) = _resolveOrderByTermToExprList(tls, pParse, pSelect, pDup)
if libc.Int32FromUint8((*TParse)(unsafe.Pointer(pParse)).FeParseMode) >= int32(PARSE_MODE_RENAME) && **(**int32)(__ccgo_up(bp)) > 0 {
_resolveOrderByTermToExprList(tls, pParse, pSelect, pE)
}
}
_sqlite3ExprDelete(tls, db, pDup)
}
}
if **(**int32)(__ccgo_up(bp)) > 0 {
/* Convert the ORDER BY term into an integer column number iCol,
** taking care to preserve the COLLATE clause if it exists. */
if !(libc.Int32FromUint8((*TParse)(unsafe.Pointer(pParse)).FeParseMode) >= libc.Int32FromInt32(PARSE_MODE_RENAME)) {
pNew = _sqlite3ExprInt32(tls, db, **(**int32)(__ccgo_up(bp)))
if pNew == uintptr(0) {
return int32(1)
}
if (*TExprList_item)(unsafe.Pointer(pItem)).FpExpr == pE {
(*TExprList_item)(unsafe.Pointer(pItem)).FpExpr = pNew
} else {
pParent = (*TExprList_item)(unsafe.Pointer(pItem)).FpExpr
for libc.Int32FromUint8((*TExpr)(unsafe.Pointer((*TExpr)(unsafe.Pointer(pParent)).FpLeft)).Fop) == int32(TK_COLLATE) {
pParent = (*TExpr)(unsafe.Pointer(pParent)).FpLeft
}
(*TExpr)(unsafe.Pointer(pParent)).FpLeft = pNew
}
_sqlite3ExprDelete(tls, db, pE)
(*(*struct {
FiOrderByCol Tu16
FiAlias Tu16
})(unsafe.Pointer(pItem + 24))).FiOrderByCol = libc.Uint16FromInt32(**(**int32)(__ccgo_up(bp)))
}
libc.SetBitFieldPtr16Uint32(pItem+16+4, libc.Uint32FromInt32(1), 2, 0x4)
} else {
moreToDo = int32(1)
}
goto _2
_2:
;
i = i + 1
pItem += 32
}
pSelect = (*TSelect)(unsafe.Pointer(pSelect)).FpNext
}
i = 0
for {
if !(i < (*TExprList)(unsafe.Pointer(pOrderBy)).FnExpr) {
break
}
if int32(uint32(*(*uint16)(unsafe.Pointer(pOrderBy + 8 + uintptr(i)*32 + 16 + 4))&0x4>>2)) == 0 {
_sqlite3ErrorMsg(tls, pParse, __ccgo_ts+8013, 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 + 40))
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)
*(*uintptr)(unsafe.Pointer(pExpr + 64)) = (*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.Int32FromUint64(libc.Uint64FromInt64(32)/libc.Uint64FromInt64(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(&(*TExpr)(unsafe.Pointer(pExpr)).Fu)) = 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.Int32FromUint64(libc.Uint64FromInt64(32)/libc.Uint64FromInt64(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+7548, 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+64, 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(pExpr + 64)))).FeFrmType) != int32(TK_FILTER) {
v4 = *(*uintptr)(unsafe.Pointer(pExpr + 64))
} else {
v4 = uintptr(0)
}
pWin = v4
pList = *(*uintptr)(unsafe.Pointer(pExpr + 32))
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*32))).FpExpr)
if (*TExpr)(unsafe.Pointer(pExpr)).FiTable < 0 {
_sqlite3ErrorMsg(tls, pParse, __ccgo_ts+7565, 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+7629, 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+7665, 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+7693, 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 + 7736
} else {
zType = __ccgo_ts + 7743
}
_sqlite3ErrorMsg(tls, pParse, __ccgo_ts+7753, 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+7781, 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+7803, 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+7847, 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 + 40)) &= ^(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 + 32)))
}
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 + 40)) |= 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(pExpr + 64)))).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 + 40
*(*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 + 40)) |= 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+40, libc.Uint32FromInt32(1), 4, 0x10)
}
if (*TNameContext)(unsafe.Pointer(pNC)).FncFlags&int32(NC_SelfRef) != 0 {
_notValidImpl(tls, pParse, pNC, __ccgo_ts+7895, pExpr, pExpr)
} else {
_sqlite3WalkSelect(tls, pWalker, *(*uintptr)(unsafe.Pointer(pExpr + 32)))
}
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 + 32)) + 4)) |= uint32(SF_Correlated)
}
**(**int32)(__ccgo_up(pNC + 40)) |= 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+7906, 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 + 32)) + 8))).FpExpr)
if nRight == nLeft {
nRight = _sqlite3ExprVectorSize(tls, (*(*TExprList_item)(unsafe.Pointer(*(*uintptr)(unsafe.Pointer(pExpr + 32)) + 8 + 1*32))).FpExpr)
}
} else {
nRight = _sqlite3ExprVectorSize(tls, (*TExpr)(unsafe.Pointer(pExpr)).FpRight)
}
if nLeft != nRight {
_sqlite3ErrorMsg(tls, pParse, __ccgo_ts+7256, 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
//
// /*
// ** This function checks if argument pFrom refers to a CTE declared by
// ** a WITH clause on the stack currently maintained by the parser (on the
// ** pParse->pWith linked list). And if currently processing a CTE
// ** CTE expression, through routine checks to see if the reference is
// ** a recursive reference to the CTE.
// **
// ** If pFrom matches a CTE according to either of these two above, pFrom->pSTab
// ** and other fields are populated accordingly.
// **
// ** Return 0 if no match is found.
// ** Return 1 if a match is found.
// ** Return 2 if an error condition is detected.
// */
func _resolveFromTermToCte(tls *libc.TLS, pParse uintptr, pWalker uintptr, pFrom uintptr) (r int32) {
bp := tls.Alloc(48)
defer tls.Free(48)
var bMayRecursive, i, iRecTab, rc, v3 int32
var db, pCte, pCteUse, pEList, pItem, pLeft, pRecTerm, pSavedWith, pSel, pSrc, pTab, v1 uintptr
var _ /* pWith at bp+0 */ uintptr
_, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _ = bMayRecursive, db, i, iRecTab, pCte, pCteUse, pEList, pItem, pLeft, pRecTerm, pSavedWith, pSel, pSrc, pTab, rc, v1, v3 /* The matching WITH */
if (*TParse)(unsafe.Pointer(pParse)).FpWith == uintptr(0) {
/* There are no WITH clauses in the stack. No match is possible */
return 0
}
if (*TParse)(unsafe.Pointer(pParse)).FnErr != 0 {
/* Prior errors might have left pParse->pWith in a goofy state, so
** go no further. */
return 0
}
if int32(*(*uint32)(unsafe.Pointer(pFrom + 24 + 4))&0x10000>>16) == 0 && *(*uintptr)(unsafe.Pointer(pFrom + 72)) != uintptr(0) {
/* The FROM term contains a schema qualifier (ex: main.t1) and so
** it cannot possibly be a CTE reference. */
return 0
}
if int32(*(*uint32)(unsafe.Pointer(pFrom + 24 + 4))&0x400>>10) != 0 {
/* The FROM term is specifically excluded from matching a CTE.
** (1) It is part of a trigger that used to have zDatabase but had
** zDatabase removed by sqlite3FixTriggerStep().
** (2) This is the first term in the FROM clause of an UPDATE.
*/
return 0
}
pCte = _searchWith(tls, (*TParse)(unsafe.Pointer(pParse)).FpWith, pFrom, bp)
if pCte != 0 {
db = (*TParse)(unsafe.Pointer(pParse)).Fdb /* Initial value of pParse->pWith */
iRecTab = -int32(1)
/* If pCte->zCteErr is non-NULL at this point, then this is an illegal
** recursive reference to CTE pCte. Leave an error in pParse and return
** early. If pCte->zCteErr is NULL, then this is not a recursive reference.
** In this case, proceed. */
if (*TCte)(unsafe.Pointer(pCte)).FzCteErr != 0 {
_sqlite3ErrorMsg(tls, pParse, (*TCte)(unsafe.Pointer(pCte)).FzCteErr, libc.VaList(bp+16, (*TCte)(unsafe.Pointer(pCte)).FzName))
return int32(2)
}
if _cannotBeFunction(tls, pParse, pFrom) != 0 {
return int32(2)
}
pTab = _sqlite3DbMallocZero(tls, db, uint64(120))
if pTab == uintptr(0) {
return int32(2)
}
pCteUse = (*TCte)(unsafe.Pointer(pCte)).FpUse
if pCteUse == uintptr(0) {
v1 = _sqlite3DbMallocZero(tls, db, uint64(20))
pCteUse = v1
(*TCte)(unsafe.Pointer(pCte)).FpUse = v1
if pCteUse == uintptr(0) || _sqlite3ParserAddCleanup(tls, pParse, __ccgo_fp(_sqlite3DbFree), pCteUse) == uintptr(0) {
_sqlite3DbFree(tls, db, pTab)
return int32(2)
}
(*TCteUse)(unsafe.Pointer(pCteUse)).FeM10d = (*TCte)(unsafe.Pointer(pCte)).FeM10d
}
(*TSrcItem)(unsafe.Pointer(pFrom)).FpSTab = pTab
(*TTable)(unsafe.Pointer(pTab)).FnTabRef = uint32(1)
(*TTable)(unsafe.Pointer(pTab)).FzName = _sqlite3DbStrDup(tls, db, (*TCte)(unsafe.Pointer(pCte)).FzName)
(*TTable)(unsafe.Pointer(pTab)).FiPKey = int16(-int32(1))
(*TTable)(unsafe.Pointer(pTab)).FnRowLogEst = int16(200)
**(**Tu32)(__ccgo_up(pTab + 48)) |= libc.Uint32FromInt32(libc.Int32FromInt32(TF_Ephemeral) | libc.Int32FromInt32(TF_NoVisibleRowid))
_sqlite3SrcItemAttachSubquery(tls, pParse, pFrom, (*TCte)(unsafe.Pointer(pCte)).FpSelect, int32(1))
if (*Tsqlite3)(unsafe.Pointer(db)).FmallocFailed != 0 {
return int32(2)
}
pSel = (*TSubquery)(unsafe.Pointer(*(*uintptr)(unsafe.Pointer(pFrom + 72)))).FpSelect
**(**Tu32)(__ccgo_up(pSel + 4)) |= uint32(SF_CopyCte)
if int32(*(*uint32)(unsafe.Pointer(pFrom + 24 + 4))&0x2>>1) != 0 {
_sqlite3ErrorMsg(tls, pParse, __ccgo_ts+21450, libc.VaList(bp+16, *(*uintptr)(unsafe.Pointer(pFrom + 48))))
return int32(2)
}
libc.SetBitFieldPtr32Uint32(pFrom+24+4, libc.Uint32FromInt32(1), 9, 0x200)
*(*uintptr)(unsafe.Pointer(pFrom + 56)) = pCteUse
(*TCteUse)(unsafe.Pointer(pCteUse)).FnUse = (*TCteUse)(unsafe.Pointer(pCteUse)).FnUse + 1
/* Check if this is a recursive CTE. */
pRecTerm = pSel
bMayRecursive = libc.BoolInt32(libc.Int32FromUint8((*TSelect)(unsafe.Pointer(pSel)).Fop) == int32(TK_ALL) || libc.Int32FromUint8((*TSelect)(unsafe.Pointer(pSel)).Fop) == int32(TK_UNION))
for bMayRecursive != 0 && libc.Int32FromUint8((*TSelect)(unsafe.Pointer(pRecTerm)).Fop) == libc.Int32FromUint8((*TSelect)(unsafe.Pointer(pSel)).Fop) {
pSrc = (*TSelect)(unsafe.Pointer(pRecTerm)).FpSrc
i = 0
for {
if !(i < (*TSrcList)(unsafe.Pointer(pSrc)).FnSrc) {
break
}
pItem = pSrc + 8 + uintptr(i)*80
if (*TSrcItem)(unsafe.Pointer(pItem)).FzName != uintptr(0) && !(int32(*(*uint32)(unsafe.Pointer(pItem + 24 + 4))&0x20000>>17) != 0) && !(int32(*(*uint32)(unsafe.Pointer(pItem + 24 + 4))&0x4>>2) != 0) && (int32(*(*uint32)(unsafe.Pointer(pItem + 24 + 4))&0x10000>>16) != 0 || *(*uintptr)(unsafe.Pointer(pItem + 72)) == uintptr(0)) && 0 == _sqlite3StrICmp(tls, (*TSrcItem)(unsafe.Pointer(pItem)).FzName, (*TCte)(unsafe.Pointer(pCte)).FzName) {
(*TSrcItem)(unsafe.Pointer(pItem)).FpSTab = pTab
(*TTable)(unsafe.Pointer(pTab)).FnTabRef = (*TTable)(unsafe.Pointer(pTab)).FnTabRef + 1
libc.SetBitFieldPtr32Uint32(pItem+24+4, libc.Uint32FromInt32(1), 7, 0x80)
if (*TSelect)(unsafe.Pointer(pRecTerm)).FselFlags&uint32(SF_Recursive) != 0 {
_sqlite3ErrorMsg(tls, pParse, __ccgo_ts+21470, libc.VaList(bp+16, (*TCte)(unsafe.Pointer(pCte)).FzName))
return int32(2)
}
**(**Tu32)(__ccgo_up(pRecTerm + 4)) |= uint32(SF_Recursive)
if iRecTab < 0 {
v1 = pParse + 56
v3 = *(*int32)(unsafe.Pointer(v1))
*(*int32)(unsafe.Pointer(v1)) = *(*int32)(unsafe.Pointer(v1)) + 1
iRecTab = v3
}
(*TSrcItem)(unsafe.Pointer(pItem)).FiCursor = iRecTab
}
goto _2
_2:
;
i = i + 1
}
if (*TSelect)(unsafe.Pointer(pRecTerm)).FselFlags&uint32(SF_Recursive) == uint32(0) {
break
}
pRecTerm = (*TSelect)(unsafe.Pointer(pRecTerm)).FpPrior
}
(*TCte)(unsafe.Pointer(pCte)).FzCteErr = __ccgo_ts + 21513
pSavedWith = (*TParse)(unsafe.Pointer(pParse)).FpWith
(*TParse)(unsafe.Pointer(pParse)).FpWith = **(**uintptr)(__ccgo_up(bp))
if (*TSelect)(unsafe.Pointer(pSel)).FselFlags&uint32(SF_Recursive) != 0 {
(*TSelect)(unsafe.Pointer(pRecTerm)).FpWith = (*TSelect)(unsafe.Pointer(pSel)).FpWith
rc = _sqlite3WalkSelect(tls, pWalker, pRecTerm)
(*TSelect)(unsafe.Pointer(pRecTerm)).FpWith = uintptr(0)
if rc != 0 {
(*TParse)(unsafe.Pointer(pParse)).FpWith = pSavedWith
return int32(2)
}
} else {
if _sqlite3WalkSelect(tls, pWalker, pSel) != 0 {
(*TParse)(unsafe.Pointer(pParse)).FpWith = pSavedWith
return int32(2)
}
}
(*TParse)(unsafe.Pointer(pParse)).FpWith = **(**uintptr)(__ccgo_up(bp))
pLeft = pSel
for {
if !((*TSelect)(unsafe.Pointer(pLeft)).FpPrior != 0) {
break
}
goto _5
_5:
;
pLeft = (*TSelect)(unsafe.Pointer(pLeft)).FpPrior
}
pEList = (*TSelect)(unsafe.Pointer(pLeft)).FpEList
if (*TCte)(unsafe.Pointer(pCte)).FpCols != 0 {
if pEList != 0 && (*TExprList)(unsafe.Pointer(pEList)).FnExpr != (*TExprList)(unsafe.Pointer((*TCte)(unsafe.Pointer(pCte)).FpCols)).FnExpr {
_sqlite3ErrorMsg(tls, pParse, __ccgo_ts+21536, libc.VaList(bp+16, (*TCte)(unsafe.Pointer(pCte)).FzName, (*TExprList)(unsafe.Pointer(pEList)).FnExpr, (*TExprList)(unsafe.Pointer((*TCte)(unsafe.Pointer(pCte)).FpCols)).FnExpr))
(*TParse)(unsafe.Pointer(pParse)).FpWith = pSavedWith
return int32(2)
}
pEList = (*TCte)(unsafe.Pointer(pCte)).FpCols
}
_sqlite3ColumnsFromExprList(tls, pParse, pEList, pTab+54, pTab+8)
if bMayRecursive != 0 {
if (*TSelect)(unsafe.Pointer(pSel)).FselFlags&uint32(SF_Recursive) != 0 {
(*TCte)(unsafe.Pointer(pCte)).FzCteErr = __ccgo_ts + 21574
} else {
(*TCte)(unsafe.Pointer(pCte)).FzCteErr = __ccgo_ts + 21608
}
_sqlite3WalkSelect(tls, pWalker, pSel)
}
(*TCte)(unsafe.Pointer(pCte)).FzCteErr = uintptr(0)
(*TParse)(unsafe.Pointer(pParse)).FpWith = pSavedWith
return int32(1) /* Success */
}
return 0 /* No match */
}
// C documentation
//
// /*
// ** pE is a pointer to an expression which is a single term in the
// ** ORDER BY of a compound SELECT. The expression has not been
// ** name resolved.
// **
// ** At the point this routine is called, we already know that the
// ** ORDER BY term is not an integer index into the result set. That
// ** case is handled by the calling routine.
// **
// ** Attempt to match pE against result set columns in the left-most
// ** SELECT statement. Return the index i of the matching column,
// ** as an indication to the caller that it should sort by the i-th column.
// ** The left-most column is 1. In other words, the value returned is the
// ** same integer value that would be used in the SQL statement to indicate
// ** the column.
// **
// ** If there is no match, return 0. Return -1 if an error occurs.
// */
func _resolveOrderByTermToExprList(tls *libc.TLS, pParse uintptr, pSelect uintptr, pE uintptr) (r int32) {
bp := tls.Alloc(64)
defer tls.Free(64)
var db, pEList uintptr
var i, rc int32
var savedSuppErr Tu8
var _ /* nc at bp+0 */ TNameContext
_, _, _, _, _ = db, i, pEList, rc, savedSuppErr /* Saved value of db->suppressErr */
pEList = (*TSelect)(unsafe.Pointer(pSelect)).FpEList
/* Resolve all names in the ORDER BY term expression
*/
libc.X__builtin___memset_chk(tls, bp, 0, uint64(56), ^t__predefined_size_t(0))
(**(**TNameContext)(__ccgo_up(bp))).FpParse = pParse
(**(**TNameContext)(__ccgo_up(bp))).FpSrcList = (*TSelect)(unsafe.Pointer(pSelect)).FpSrc
*(*uintptr)(unsafe.Pointer(bp + 16)) = pEList
(**(**TNameContext)(__ccgo_up(bp))).FncFlags = libc.Int32FromInt32(NC_AllowAgg) | libc.Int32FromInt32(NC_UEList) | libc.Int32FromInt32(NC_NoSelect)
(**(**TNameContext)(__ccgo_up(bp))).FnNcErr = 0
db = (*TParse)(unsafe.Pointer(pParse)).Fdb
savedSuppErr = (*Tsqlite3)(unsafe.Pointer(db)).FsuppressErr
(*Tsqlite3)(unsafe.Pointer(db)).FsuppressErr = uint8(1)
rc = _sqlite3ResolveExprNames(tls, bp, pE)
(*Tsqlite3)(unsafe.Pointer(db)).FsuppressErr = savedSuppErr
if rc != 0 {
return 0
}
/* Try to match the ORDER BY expression against an expression
** in the result set. Return an 1-based index of the matching
** result-set entry.
*/
i = 0
for {
if !(i < (*TExprList)(unsafe.Pointer(pEList)).FnExpr) {
break
}
if _sqlite3ExprCompare(tls, uintptr(0), (*(*TExprList_item)(unsafe.Pointer(pEList + 8 + uintptr(i)*32))).FpExpr, pE, -int32(1)) < int32(2) {
return i + int32(1)
}
goto _1
_1:
;
i = i + 1
}
/* If no match, return 0. */
return 0
}
// C documentation
//
// /*
// ** Generate an ORDER BY or GROUP BY term out-of-range error.
// */
func _resolveOutOfRangeError(tls *libc.TLS, pParse uintptr, zType uintptr, i int32, mx int32, pError uintptr) {
bp := tls.Alloc(32)
defer tls.Free(32)
_sqlite3ErrorMsg(tls, pParse, __ccgo_ts+7917, libc.VaList(bp+8, i, zType, mx))
_sqlite3RecordErrorOffsetOfExpr(tls, (*TParse)(unsafe.Pointer(pParse)).Fdb, pError)
}
// C documentation
//
// /*
// ** Resolve names in the SELECT statement p and all of its descendants.
// */
func _resolveSelectStep(tls *libc.TLS, pWalker uintptr, p uintptr) (r int32) {
bp := tls.Alloc(64)
defer tls.Free(64)
var db, pGroupBy, pItem, pItem1, pItem2, pLeftmost, pOuterNC, pParse, pSub, pSub1, pWin, zSavedContext uintptr
var i, isCompound, nCompound, nRef, v1 int32
var _ /* sNC at bp+0 */ TNameContext
_, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _ = db, i, isCompound, nCompound, nRef, pGroupBy, pItem, pItem1, pItem2, pLeftmost, pOuterNC, pParse, pSub, pSub1, pWin, zSavedContext, v1 /* Database connection */
if (*TSelect)(unsafe.Pointer(p)).FselFlags&uint32(SF_Resolved) != 0 {
return int32(WRC_Prune)
}
pOuterNC = *(*uintptr)(unsafe.Pointer(pWalker + 40))
pParse = (*TWalker)(unsafe.Pointer(pWalker)).FpParse
db = (*TParse)(unsafe.Pointer(pParse)).Fdb
/* Normally sqlite3SelectExpand() will be called first and will have
** already expanded this SELECT. However, if this is a subquery within
** an expression, sqlite3ResolveExprNames() will be called without a
** prior call to sqlite3SelectExpand(). When that happens, let
** sqlite3SelectPrep() do all of the processing for this SELECT.
** sqlite3SelectPrep() will invoke both sqlite3SelectExpand() and
** this routine in the correct order.
*/
if (*TSelect)(unsafe.Pointer(p)).FselFlags&uint32(SF_Expanded) == uint32(0) {
_sqlite3SelectPrep(tls, pParse, p, pOuterNC)
if (*TParse)(unsafe.Pointer(pParse)).FnErr != 0 {
v1 = int32(WRC_Abort)
} else {
v1 = int32(WRC_Prune)
}
return v1
}
isCompound = libc.BoolInt32((*TSelect)(unsafe.Pointer(p)).FpPrior != uintptr(0))
nCompound = 0
pLeftmost = p
for p != 0 {
**(**Tu32)(__ccgo_up(p + 4)) |= uint32(SF_Resolved)
/* Resolve the expressions in the LIMIT and OFFSET clauses. These
** are not allowed to refer to any names, so pass an empty NameContext.
*/
libc.X__builtin___memset_chk(tls, bp, 0, uint64(56), ^t__predefined_size_t(0))
(**(**TNameContext)(__ccgo_up(bp))).FpParse = pParse
(**(**TNameContext)(__ccgo_up(bp))).FpWinSelect = p
if _sqlite3ResolveExprNames(tls, bp, (*TSelect)(unsafe.Pointer(p)).FpLimit) != 0 {
return int32(WRC_Abort)
}
/* If the SF_Converted flags is set, then this Select object was
** was created by the convertCompoundSelectToSubquery() function.
** In this case the ORDER BY clause (p->pOrderBy) should be resolved
** as if it were part of the sub-query, not the parent. This block
** moves the pOrderBy down to the sub-query. It will be moved back
** after the names have been resolved. */
if (*TSelect)(unsafe.Pointer(p)).FselFlags&uint32(SF_Converted) != 0 {
pSub = (*TSubquery)(unsafe.Pointer(*(*uintptr)(unsafe.Pointer((*TSelect)(unsafe.Pointer(p)).FpSrc + 8 + 72)))).FpSelect
(*TSelect)(unsafe.Pointer(pSub)).FpOrderBy = (*TSelect)(unsafe.Pointer(p)).FpOrderBy
(*TSelect)(unsafe.Pointer(p)).FpOrderBy = uintptr(0)
}
/* Recursively resolve names in all subqueries in the FROM clause
*/
if pOuterNC != 0 {
(*TNameContext)(unsafe.Pointer(pOuterNC)).FnNestedSelect = (*TNameContext)(unsafe.Pointer(pOuterNC)).FnNestedSelect + 1
}
i = 0
for {
if !(i < (*TSrcList)(unsafe.Pointer((*TSelect)(unsafe.Pointer(p)).FpSrc)).FnSrc) {
break
}
pItem = (*TSelect)(unsafe.Pointer(p)).FpSrc + 8 + uintptr(i)*80
/* Test of tag-20240424-1*/
if int32(*(*uint32)(unsafe.Pointer(pItem + 24 + 4))&0x4>>2) != 0 && (*TSelect)(unsafe.Pointer((*TSubquery)(unsafe.Pointer(*(*uintptr)(unsafe.Pointer(pItem + 72)))).FpSelect)).FselFlags&uint32(SF_Resolved) == uint32(0) {
if pOuterNC != 0 {
v1 = (*TNameContext)(unsafe.Pointer(pOuterNC)).FnRef
} else {
v1 = 0
}
nRef = v1
zSavedContext = (*TParse)(unsafe.Pointer(pParse)).FzAuthContext
if (*TSrcItem)(unsafe.Pointer(pItem)).FzName != 0 {
(*TParse)(unsafe.Pointer(pParse)).FzAuthContext = (*TSrcItem)(unsafe.Pointer(pItem)).FzName
}
_sqlite3ResolveSelectNames(tls, pParse, (*TSubquery)(unsafe.Pointer(*(*uintptr)(unsafe.Pointer(pItem + 72)))).FpSelect, pOuterNC)
(*TParse)(unsafe.Pointer(pParse)).FzAuthContext = zSavedContext
if (*TParse)(unsafe.Pointer(pParse)).FnErr != 0 {
return int32(WRC_Abort)
}
/* If the number of references to the outer context changed when
** expressions in the sub-select were resolved, the sub-select
** is correlated. It is not required to check the refcount on any
** but the innermost outer context object, as lookupName() increments
** the refcount on all contexts between the current one and the
** context containing the column when it resolves a name. */
if pOuterNC != 0 {
libc.SetBitFieldPtr32Uint32(pItem+24+4, libc.BoolUint32((*TNameContext)(unsafe.Pointer(pOuterNC)).FnRef > nRef), 4, 0x10)
}
}
goto _2
_2:
;
i = i + 1
}
if pOuterNC != 0 && (*TNameContext)(unsafe.Pointer(pOuterNC)).FnNestedSelect > uint32(0) {
(*TNameContext)(unsafe.Pointer(pOuterNC)).FnNestedSelect = (*TNameContext)(unsafe.Pointer(pOuterNC)).FnNestedSelect - 1
}
/* Set up the local name-context to pass to sqlite3ResolveExprNames() to
** resolve the result-set expression list.
*/
(**(**TNameContext)(__ccgo_up(bp))).FncFlags = libc.Int32FromInt32(NC_AllowAgg) | libc.Int32FromInt32(NC_AllowWin)
(**(**TNameContext)(__ccgo_up(bp))).FpSrcList = (*TSelect)(unsafe.Pointer(p)).FpSrc
(**(**TNameContext)(__ccgo_up(bp))).FpNext = pOuterNC
/* Resolve names in the result set. */
if _sqlite3ResolveExprListNames(tls, bp, (*TSelect)(unsafe.Pointer(p)).FpEList) != 0 {
return int32(WRC_Abort)
}
(**(**TNameContext)(__ccgo_up(bp))).FncFlags &= ^libc.Int32FromInt32(NC_AllowWin)
/* If there are no aggregate functions in the result-set, and no GROUP BY
** expression, do not allow aggregates in any of the other expressions.
*/
pGroupBy = (*TSelect)(unsafe.Pointer(p)).FpGroupBy
if pGroupBy != 0 || (**(**TNameContext)(__ccgo_up(bp))).FncFlags&int32(NC_HasAgg) != 0 {
**(**Tu32)(__ccgo_up(p + 4)) |= libc.Uint32FromInt32(int32(SF_Aggregate) | (**(**TNameContext)(__ccgo_up(bp))).FncFlags&(libc.Int32FromInt32(NC_MinMaxAgg)|libc.Int32FromInt32(NC_OrderAgg)))
} else {
(**(**TNameContext)(__ccgo_up(bp))).FncFlags &= ^libc.Int32FromInt32(NC_AllowAgg)
}
/* Add the output column list to the name-context before parsing the
** other expressions in the SELECT statement. This is so that
** expressions in the WHERE clause (etc.) can refer to expressions by
** aliases in the result set.
**
** Minor point: If this is the case, then the expression will be
** re-evaluated for each reference to it.
*/
*(*uintptr)(unsafe.Pointer(bp + 16)) = (*TSelect)(unsafe.Pointer(p)).FpEList
(**(**TNameContext)(__ccgo_up(bp))).FncFlags |= int32(NC_UEList)
if (*TSelect)(unsafe.Pointer(p)).FpHaving != 0 {
if (*TSelect)(unsafe.Pointer(p)).FselFlags&uint32(SF_Aggregate) == uint32(0) {
_sqlite3ErrorMsg(tls, pParse, __ccgo_ts+8105, 0)
return int32(WRC_Abort)
}
if _sqlite3ResolveExprNames(tls, bp, (*TSelect)(unsafe.Pointer(p)).FpHaving) != 0 {
return int32(WRC_Abort)
}
}
(**(**TNameContext)(__ccgo_up(bp))).FncFlags |= int32(NC_Where)
if _sqlite3ResolveExprNames(tls, bp, (*TSelect)(unsafe.Pointer(p)).FpWhere) != 0 {
return int32(WRC_Abort)
}
(**(**TNameContext)(__ccgo_up(bp))).FncFlags &= ^libc.Int32FromInt32(NC_Where)
/* Resolve names in table-valued-function arguments */
i = 0
for {
if !(i < (*TSrcList)(unsafe.Pointer((*TSelect)(unsafe.Pointer(p)).FpSrc)).FnSrc) {
break
}
pItem1 = (*TSelect)(unsafe.Pointer(p)).FpSrc + 8 + uintptr(i)*80
if int32(*(*uint32)(unsafe.Pointer(pItem1 + 24 + 4))&0x8>>3) != 0 && _sqlite3ResolveExprListNames(tls, bp, *(*uintptr)(unsafe.Pointer(pItem1 + 48))) != 0 {
return int32(WRC_Abort)
}
goto _4
_4:
;
i = i + 1
}
if libc.Int32FromUint8((*TParse)(unsafe.Pointer(pParse)).FeParseMode) >= int32(PARSE_MODE_RENAME) {
pWin = (*TSelect)(unsafe.Pointer(p)).FpWinDefn
for {
if !(pWin != 0) {
break
}
if _sqlite3ResolveExprListNames(tls, bp, (*TWindow)(unsafe.Pointer(pWin)).FpOrderBy) != 0 || _sqlite3ResolveExprListNames(tls, bp, (*TWindow)(unsafe.Pointer(pWin)).FpPartition) != 0 {
return int32(WRC_Abort)
}
goto _5
_5:
;
pWin = (*TWindow)(unsafe.Pointer(pWin)).FpNextWin
}
}
(**(**TNameContext)(__ccgo_up(bp))).FncFlags |= libc.Int32FromInt32(NC_AllowAgg) | libc.Int32FromInt32(NC_AllowWin)
/* If this is a converted compound query, move the ORDER BY clause from
** the sub-query back to the parent query. At this point each term
** within the ORDER BY clause has been transformed to an integer value.
** These integers will be replaced by copies of the corresponding result
** set expressions by the call to resolveOrderGroupBy() below. */
if (*TSelect)(unsafe.Pointer(p)).FselFlags&uint32(SF_Converted) != 0 {
pSub1 = (*TSubquery)(unsafe.Pointer(*(*uintptr)(unsafe.Pointer((*TSelect)(unsafe.Pointer(p)).FpSrc + 8 + 72)))).FpSelect
(*TSelect)(unsafe.Pointer(p)).FpOrderBy = (*TSelect)(unsafe.Pointer(pSub1)).FpOrderBy
(*TSelect)(unsafe.Pointer(pSub1)).FpOrderBy = uintptr(0)
}
/* Process the ORDER BY clause for singleton SELECT statements.
** The ORDER BY clause for compounds SELECT statements is handled
** below, after all of the result-sets for all of the elements of
** the compound have been resolved.
**
** If there is an ORDER BY clause on a term of a compound-select other
** than the right-most term, then that is a syntax error. But the error
** is not detected until much later, and so we need to go ahead and
** resolve those symbols on the incorrect ORDER BY for consistency.
*/
if (*TSelect)(unsafe.Pointer(p)).FpOrderBy != uintptr(0) && isCompound <= nCompound && _resolveOrderGroupBy(tls, bp, p, (*TSelect)(unsafe.Pointer(p)).FpOrderBy, __ccgo_ts+8007) != 0 {
return int32(WRC_Abort)
}
if (*Tsqlite3)(unsafe.Pointer(db)).FmallocFailed != 0 {
return int32(WRC_Abort)
}
(**(**TNameContext)(__ccgo_up(bp))).FncFlags &= ^libc.Int32FromInt32(NC_AllowWin)
/* Resolve the GROUP BY clause. At the same time, make sure
** the GROUP BY clause does not contain aggregate functions.
*/
if pGroupBy != 0 {
if _resolveOrderGroupBy(tls, bp, p, pGroupBy, __ccgo_ts+8144) != 0 || (*Tsqlite3)(unsafe.Pointer(db)).FmallocFailed != 0 {
return int32(WRC_Abort)
}
i = 0
pItem2 = pGroupBy + 8
for {
if !(i < (*TExprList)(unsafe.Pointer(pGroupBy)).FnExpr) {
break
}
if (*TExpr)(unsafe.Pointer((*TExprList_item)(unsafe.Pointer(pItem2)).FpExpr)).Fflags&libc.Uint32FromInt32(libc.Int32FromInt32(EP_Agg)) != uint32(0) {
_sqlite3ErrorMsg(tls, pParse, __ccgo_ts+8150, 0)
return int32(WRC_Abort)
}
goto _6
_6:
;
i = i + 1
pItem2 += 32
}
}
/* If this is part of a compound SELECT, check that it has the right
** number of expressions in the select list. */
if (*TSelect)(unsafe.Pointer(p)).FpNext != 0 && (*TExprList)(unsafe.Pointer((*TSelect)(unsafe.Pointer(p)).FpEList)).FnExpr != (*TExprList)(unsafe.Pointer((*TSelect)(unsafe.Pointer((*TSelect)(unsafe.Pointer(p)).FpNext)).FpEList)).FnExpr {
_sqlite3SelectWrongNumTermsError(tls, pParse, (*TSelect)(unsafe.Pointer(p)).FpNext)
return int32(WRC_Abort)
}
/* If the SELECT statement contains ON clauses that were moved into
** the WHERE clause, go through and verify that none of the terms
** in the ON clauses reference tables to the right of the ON clause. */
if (*TSelect)(unsafe.Pointer(p)).FselFlags&uint32(SF_OnToWhere) != 0 {
_sqlite3SelectCheckOnClauses(tls, pParse, p)
if (*TParse)(unsafe.Pointer(pParse)).FnErr != 0 {
return int32(WRC_Abort)
}
}
/* Advance to the next term of the compound
*/
p = (*TSelect)(unsafe.Pointer(p)).FpPrior
nCompound = nCompound + 1
}
/* Resolve the ORDER BY on a compound SELECT after all terms of
** the compound have been resolved.
*/
if isCompound != 0 && _resolveCompoundOrderBy(tls, pParse, pLeftmost) != 0 {
return int32(WRC_Abort)
}
return int32(WRC_Prune)
}
// C documentation
//
// /*
// ** Retry flock() calls that fail with EINTR
// */
func _robust_flock(tls *libc.TLS, fd int32, op int32) (r int32) {
var rc int32
_ = rc
for cond := true; cond; cond = rc < 0 && **(**int32)(__ccgo_up(libc.X__error(tls))) == int32(EINTR) {
rc = libc.Xflock(tls, fd, op)
}
return rc
}
// C documentation
//
// /*
// ** Invoke open(). Do so multiple times, until it either succeeds or
// ** fails for some reason other than EINTR.
// **
// ** If the file creation mode "m" is 0 then set it to the default for
// ** SQLite. The default is SQLITE_DEFAULT_FILE_PERMISSIONS (normally
// ** 0644) as modified by the system umask. If m is not 0, then
// ** make the file creation mode be exactly m ignoring the umask.
// **
// ** The m parameter will be non-zero only when creating -wal, -journal,
// ** and -shm files. We want those files to have *exactly* the same
// ** permissions as their original database, unadulterated by the umask.
// ** In that way, if a database file is -rw-rw-rw or -rw-rw-r-, and a
// ** transaction crashes and leaves behind hot journals, then any
// ** process that is able to write to the database will also be able to
// ** recover the hot journals.
// */
func _robust_open(tls *libc.TLS, z uintptr, f int32, m Tmode_t) (r int32) {
bp := tls.Alloc(176)
defer tls.Free(176)
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+152, 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
//
// /*
// ** Implementation of the round() function
// */
func _roundFunc(tls *libc.TLS, context uintptr, argc int32, argv uintptr) {
bp := tls.Alloc(32)
defer tls.Free(32)
var n Ti64
var zBuf uintptr
var v1 float64
var _ /* r at bp+0 */ float64
_, _, _ = n, zBuf, v1
n = 0
if argc == int32(2) {
if int32(SQLITE_NULL) == Xsqlite3_value_type(tls, **(**uintptr)(__ccgo_up(argv + 1*8))) {
return
}
n = Xsqlite3_value_int64(tls, **(**uintptr)(__ccgo_up(argv + 1*8)))
if n > int64(30) {
n = int64(30)
}
if n < 0 {
n = 0
}
}
if Xsqlite3_value_type(tls, **(**uintptr)(__ccgo_up(argv))) == int32(SQLITE_NULL) {
return
}
**(**float64)(__ccgo_up(bp)) = Xsqlite3_value_double(tls, **(**uintptr)(__ccgo_up(argv)))
/* If Y==0 and X will fit in a 64-bit int,
** handle the rounding directly,
** otherwise use printf.
*/
if **(**float64)(__ccgo_up(bp)) < -libc.Float64FromFloat64(4.503599627370496e+15) || **(**float64)(__ccgo_up(bp)) > +libc.Float64FromFloat64(4.503599627370496e+15) {
/* The value has no fractional part so there is nothing to round */
} else {
if n == 0 {
if **(**float64)(__ccgo_up(bp)) < libc.Float64FromInt32(0) {
v1 = -libc.Float64FromFloat64(0.5)
} else {
v1 = +libc.Float64FromFloat64(0.5)
}
**(**float64)(__ccgo_up(bp)) = float64(int64(**(**float64)(__ccgo_up(bp)) + v1))
} else {
zBuf = Xsqlite3_mprintf(tls, __ccgo_ts+16823, libc.VaList(bp+16, int32(n), **(**float64)(__ccgo_up(bp))))
if zBuf == uintptr(0) {
Xsqlite3_result_error_nomem(tls, context)
return
}
_sqlite3AtoF(tls, zBuf, bp)
Xsqlite3_free(tls, zBuf)
}
}
Xsqlite3_result_double(tls, context, **(**float64)(__ccgo_up(bp)))
}
// C documentation
//
// /*
// ** Sort all elements on the list of RowSetEntry objects into order of
// ** increasing v.
// */
func _rowSetEntrySort(tls *libc.TLS, pIn uintptr) (r uintptr) {
bp := tls.Alloc(320)
defer tls.Free(320)
var i uint32
var pNext, v3 uintptr
var _ /* aBucket at bp+0 */ [40]uintptr
_, _, _ = i, pNext, v3
libc.X__builtin___memset_chk(tls, bp, 0, uint64(320), ^t__predefined_size_t(0))
for pIn != 0 {
pNext = (*TRowSetEntry)(unsafe.Pointer(pIn)).FpRight
(*TRowSetEntry)(unsafe.Pointer(pIn)).FpRight = uintptr(0)
i = uint32(0)
for {
if !((**(**[40]uintptr)(__ccgo_up(bp)))[i] != 0) {
break
}
pIn = _rowSetEntryMerge(tls, (**(**[40]uintptr)(__ccgo_up(bp)))[i], pIn)
(**(**[40]uintptr)(__ccgo_up(bp)))[i] = uintptr(0)
goto _1
_1:
;
i = i + 1
}
(**(**[40]uintptr)(__ccgo_up(bp)))[i] = pIn
pIn = pNext
}
pIn = (**(**[40]uintptr)(__ccgo_up(bp)))[0]
i = uint32(1)
for {
if !(uint64(i) < libc.Uint64FromInt64(320)/libc.Uint64FromInt64(8)) {
break
}
if (**(**[40]uintptr)(__ccgo_up(bp)))[i] == uintptr(0) {
goto _2
}
if pIn != 0 {
v3 = _rowSetEntryMerge(tls, pIn, (**(**[40]uintptr)(__ccgo_up(bp)))[i])
} else {
v3 = (**(**[40]uintptr)(__ccgo_up(bp)))[i]
}
pIn = v3
goto _2
_2:
;
i = i + 1
}
return pIn
}
// C documentation
//
// /*
// ** Rtree virtual table module xBestIndex method. There are three
// ** table scan strategies to choose from (in order from most to
// ** least desirable):
// **
// ** idxNum idxStr Strategy
// ** ------------------------------------------------
// ** 1 Unused Direct lookup by rowid.
// ** 2 See below R-tree query or full-table scan.
// ** ------------------------------------------------
// **
// ** If strategy 1 is used, then idxStr is not meaningful. If strategy
// ** 2 is used, idxStr is formatted to contain 2 bytes for each
// ** constraint used. The first two bytes of idxStr correspond to
// ** the constraint in sqlite3_index_info.aConstraintUsage[] with
// ** (argvIndex==1) etc.
// **
// ** The first of each pair of bytes in idxStr identifies the constraint
// ** operator as follows:
// **
// ** Operator Byte Value
// ** ----------------------
// ** = 0x41 ('A')
// ** <= 0x42 ('B')
// ** < 0x43 ('C')
// ** >= 0x44 ('D')
// ** > 0x45 ('E')
// ** MATCH 0x46 ('F')
// ** ----------------------
// **
// ** The second of each pair of bytes identifies the coordinate column
// ** to which the constraint applies. The leftmost coordinate column
// ** is 'a', the second from the left 'b' etc.
// */
func _rtreeBestIndex(tls *libc.TLS, tab uintptr, pIdxInfo uintptr) (r int32) {
bp := tls.Alloc(48)
defer tls.Free(48)
var bMatch, iIdx, ii, jj, rc, v4 int32
var doOmit, op Tu8
var nRow Ti64
var p, pRtree uintptr
var _ /* zIdxStr at bp+0 */ [41]int8
_, _, _, _, _, _, _, _, _, _, _ = bMatch, doOmit, iIdx, ii, jj, nRow, op, p, pRtree, rc, v4
pRtree = tab
rc = SQLITE_OK
bMatch = 0 /* Estimated rows returned by this scan */
iIdx = 0
libc.X__builtin___memset_chk(tls, bp, 0, uint64(41), ^t__predefined_size_t(0))
/* Check if there exists a MATCH constraint - even an unusable one. If there
** is, do not consider the lookup-by-rowid plan as using such a plan would
** require the VDBE to evaluate the MATCH constraint, which is not currently
** possible. */
ii = 0
for {
if !(ii < (*Tsqlite3_index_info)(unsafe.Pointer(pIdxInfo)).FnConstraint) {
break
}
if libc.Int32FromUint8((**(**Tsqlite3_index_constraint)(__ccgo_up((*Tsqlite3_index_info)(unsafe.Pointer(pIdxInfo)).FaConstraint + uintptr(ii)*12))).Fop) == int32(SQLITE_INDEX_CONSTRAINT_MATCH) {
bMatch = int32(1)
}
goto _1
_1:
;
ii = ii + 1
}
ii = 0
for {
if !(ii < (*Tsqlite3_index_info)(unsafe.Pointer(pIdxInfo)).FnConstraint && iIdx < libc.Int32FromUint64(libc.Uint64FromInt64(41)-libc.Uint64FromInt32(1))) {
break
}
p = (*Tsqlite3_index_info)(unsafe.Pointer(pIdxInfo)).FaConstraint + uintptr(ii)*12
if bMatch == 0 && (*Tsqlite3_index_constraint)(unsafe.Pointer(p)).Fusable != 0 && (*Tsqlite3_index_constraint)(unsafe.Pointer(p)).FiColumn <= 0 && libc.Int32FromUint8((*Tsqlite3_index_constraint)(unsafe.Pointer(p)).Fop) == int32(SQLITE_INDEX_CONSTRAINT_EQ) {
jj = 0
for {
if !(jj < ii) {
break
}
(**(**Tsqlite3_index_constraint_usage)(__ccgo_up((*Tsqlite3_index_info)(unsafe.Pointer(pIdxInfo)).FaConstraintUsage + uintptr(jj)*8))).FargvIndex = 0
(**(**Tsqlite3_index_constraint_usage)(__ccgo_up((*Tsqlite3_index_info)(unsafe.Pointer(pIdxInfo)).FaConstraintUsage + uintptr(jj)*8))).Fomit = uint8(0)
goto _3
_3:
;
jj = jj + 1
}
(*Tsqlite3_index_info)(unsafe.Pointer(pIdxInfo)).FidxNum = int32(1)
(**(**Tsqlite3_index_constraint_usage)(__ccgo_up((*Tsqlite3_index_info)(unsafe.Pointer(pIdxInfo)).FaConstraintUsage + uintptr(ii)*8))).FargvIndex = int32(1)
(**(**Tsqlite3_index_constraint_usage)(__ccgo_up((*Tsqlite3_index_info)(unsafe.Pointer(pIdxInfo)).FaConstraintUsage + uintptr(jj)*8))).Fomit = uint8(1)
/* This strategy involves a two rowid lookups on an B-Tree structures
** and then a linear search of an R-Tree node. This should be
** considered almost as quick as a direct rowid lookup (for which
** sqlite uses an internal cost of 0.0). It is expected to return
** a single row.
*/
(*Tsqlite3_index_info)(unsafe.Pointer(pIdxInfo)).FestimatedCost = float64(30)
(*Tsqlite3_index_info)(unsafe.Pointer(pIdxInfo)).FestimatedRows = int64(1)
(*Tsqlite3_index_info)(unsafe.Pointer(pIdxInfo)).FidxFlags = int32(SQLITE_INDEX_SCAN_UNIQUE)
return SQLITE_OK
}
if (*Tsqlite3_index_constraint)(unsafe.Pointer(p)).Fusable != 0 && ((*Tsqlite3_index_constraint)(unsafe.Pointer(p)).FiColumn > 0 && (*Tsqlite3_index_constraint)(unsafe.Pointer(p)).FiColumn <= libc.Int32FromUint8((*TRtree)(unsafe.Pointer(pRtree)).FnDim2) || libc.Int32FromUint8((*Tsqlite3_index_constraint)(unsafe.Pointer(p)).Fop) == int32(SQLITE_INDEX_CONSTRAINT_MATCH)) {
doOmit = uint8(1)
switch libc.Int32FromUint8((*Tsqlite3_index_constraint)(unsafe.Pointer(p)).Fop) {
case int32(SQLITE_INDEX_CONSTRAINT_EQ):
op = uint8(RTREE_EQ)
doOmit = uint8(0)
case int32(SQLITE_INDEX_CONSTRAINT_GT):
op = uint8(RTREE_GT)
doOmit = uint8(0)
case int32(SQLITE_INDEX_CONSTRAINT_LE):
op = uint8(RTREE_LE)
case int32(SQLITE_INDEX_CONSTRAINT_LT):
op = uint8(RTREE_LT)
doOmit = uint8(0)
case int32(SQLITE_INDEX_CONSTRAINT_GE):
op = uint8(RTREE_GE)
case int32(SQLITE_INDEX_CONSTRAINT_MATCH):
op = uint8(RTREE_MATCH)
default:
op = uint8(0)
break
}
if op != 0 {
v4 = iIdx
iIdx = iIdx + 1
(**(**[41]int8)(__ccgo_up(bp)))[v4] = libc.Int8FromUint8(op)
v4 = iIdx
iIdx = iIdx + 1
(**(**[41]int8)(__ccgo_up(bp)))[v4] = int8((*Tsqlite3_index_constraint)(unsafe.Pointer(p)).FiColumn - libc.Int32FromInt32(1) + libc.Int32FromUint8('0'))
(**(**Tsqlite3_index_constraint_usage)(__ccgo_up((*Tsqlite3_index_info)(unsafe.Pointer(pIdxInfo)).FaConstraintUsage + uintptr(ii)*8))).FargvIndex = iIdx / int32(2)
(**(**Tsqlite3_index_constraint_usage)(__ccgo_up((*Tsqlite3_index_info)(unsafe.Pointer(pIdxInfo)).FaConstraintUsage + uintptr(ii)*8))).Fomit = doOmit
}
}
goto _2
_2:
;
ii = ii + 1
}
(*Tsqlite3_index_info)(unsafe.Pointer(pIdxInfo)).FidxNum = int32(2)
(*Tsqlite3_index_info)(unsafe.Pointer(pIdxInfo)).FneedToFreeIdxStr = int32(1)
if iIdx > 0 {
(*Tsqlite3_index_info)(unsafe.Pointer(pIdxInfo)).FidxStr = Xsqlite3_malloc(tls, iIdx+int32(1))
if (*Tsqlite3_index_info)(unsafe.Pointer(pIdxInfo)).FidxStr == uintptr(0) {
return int32(SQLITE_NOMEM)
}
libc.X__builtin___memcpy_chk(tls, (*Tsqlite3_index_info)(unsafe.Pointer(pIdxInfo)).FidxStr, bp, libc.Uint64FromInt32(iIdx+int32(1)), ^t__predefined_size_t(0))
}
nRow = (*TRtree)(unsafe.Pointer(pRtree)).FnRowEst >> (iIdx / int32(2))
(*Tsqlite3_index_info)(unsafe.Pointer(pIdxInfo)).FestimatedCost = float64(libc.Float64FromFloat64(6) * float64(nRow))
(*Tsqlite3_index_info)(unsafe.Pointer(pIdxInfo)).FestimatedRows = nRow
return rc
}
// C documentation
//
// /*
// ** The second and subsequent arguments to this function are a printf()
// ** style format string and arguments. This function formats the string and
// ** appends it to the report being accumulated in pCheck.
// */
func _rtreeCheckAppendMsg(tls *libc.TLS, pCheck uintptr, zFmt uintptr, va uintptr) {
bp := tls.Alloc(32)
defer tls.Free(32)
var ap Tva_list
var z, v1 uintptr
_, _, _ = ap, z, v1
ap = va
if (*TRtreeCheck)(unsafe.Pointer(pCheck)).Frc == SQLITE_OK && (*TRtreeCheck)(unsafe.Pointer(pCheck)).FnErr < int32(RTREE_CHECK_MAX_ERROR) {
z = Xsqlite3_vmprintf(tls, zFmt, ap)
if z == uintptr(0) {
(*TRtreeCheck)(unsafe.Pointer(pCheck)).Frc = int32(SQLITE_NOMEM)
} else {
if (*TRtreeCheck)(unsafe.Pointer(pCheck)).FzReport != 0 {
v1 = __ccgo_ts + 4700
} else {
v1 = __ccgo_ts + 1702
}
(*TRtreeCheck)(unsafe.Pointer(pCheck)).FzReport = Xsqlite3_mprintf(tls, __ccgo_ts+29446, libc.VaList(bp+8, (*TRtreeCheck)(unsafe.Pointer(pCheck)).FzReport, v1, z))
if (*TRtreeCheck)(unsafe.Pointer(pCheck)).FzReport == uintptr(0) {
(*TRtreeCheck)(unsafe.Pointer(pCheck)).Frc = int32(SQLITE_NOMEM)
}
}
(*TRtreeCheck)(unsafe.Pointer(pCheck)).FnErr = (*TRtreeCheck)(unsafe.Pointer(pCheck)).FnErr + 1
}
_ = ap
}
// C documentation
//
// /*
// ** Argument pCell points to an array of coordinates stored on an rtree page.
// ** This function checks that the coordinates are internally consistent (no
// ** x1>x2 conditions) and adds an error message to the RtreeCheck object
// ** if they are not.
// **
// ** Additionally, if pParent is not NULL, then it is assumed to point to
// ** the array of coordinates on the parent page that bound the page
// ** containing pCell. In this case it is also verified that the two
// ** sets of coordinates are mutually consistent and an error message added
// ** to the RtreeCheck object if they are not.
// */
func _rtreeCheckCellCoord(tls *libc.TLS, pCheck uintptr, iNode Ti64, iCell int32, pCell uintptr, pParent uintptr) {
bp := tls.Alloc(48)
defer tls.Free(48)
var i, v2, v3 int32
var v5 bool
var _ /* c1 at bp+0 */ TRtreeCoord
var _ /* c2 at bp+4 */ TRtreeCoord
var _ /* p1 at bp+8 */ TRtreeCoord
var _ /* p2 at bp+12 */ TRtreeCoord
_, _, _, _ = i, v2, v3, v5
i = 0
for {
if !(i < (*TRtreeCheck)(unsafe.Pointer(pCheck)).FnDim) {
break
}
_readCoord(tls, pCell+uintptr(libc.Int32FromInt32(4)*libc.Int32FromInt32(2)*i), bp)
_readCoord(tls, pCell+uintptr(int32(4)*(int32(2)*i+int32(1))), bp+4)
/* printf("%e, %e\n", c1.u.f, c2.u.f); */
if (*TRtreeCheck)(unsafe.Pointer(pCheck)).FbInt != 0 {
v2 = libc.BoolInt32(*(*int32)(unsafe.Pointer(bp)) > *(*int32)(unsafe.Pointer(bp + 4)))
} else {
v2 = libc.BoolInt32(*(*TRtreeValue)(unsafe.Pointer(bp)) > *(*TRtreeValue)(unsafe.Pointer(bp + 4)))
}
if v2 != 0 {
_rtreeCheckAppendMsg(tls, pCheck, __ccgo_ts+29752, libc.VaList(bp+24, i, iCell, iNode))
}
if pParent != 0 {
_readCoord(tls, pParent+uintptr(libc.Int32FromInt32(4)*libc.Int32FromInt32(2)*i), bp+8)
_readCoord(tls, pParent+uintptr(int32(4)*(int32(2)*i+int32(1))), bp+12)
if (*TRtreeCheck)(unsafe.Pointer(pCheck)).FbInt != 0 {
v2 = libc.BoolInt32(*(*int32)(unsafe.Pointer(bp)) < *(*int32)(unsafe.Pointer(bp + 8)))
} else {
v2 = libc.BoolInt32(*(*TRtreeValue)(unsafe.Pointer(bp)) < *(*TRtreeValue)(unsafe.Pointer(bp + 8)))
}
if v5 = v2 != 0; !v5 {
if (*TRtreeCheck)(unsafe.Pointer(pCheck)).FbInt != 0 {
v3 = libc.BoolInt32(*(*int32)(unsafe.Pointer(bp + 4)) > *(*int32)(unsafe.Pointer(bp + 12)))
} else {
v3 = libc.BoolInt32(*(*TRtreeValue)(unsafe.Pointer(bp + 4)) > *(*TRtreeValue)(unsafe.Pointer(bp + 12)))
}
}
if v5 || v3 != 0 {
_rtreeCheckAppendMsg(tls, pCheck, __ccgo_ts+29800, libc.VaList(bp+24, i, iCell, iNode))
}
}
goto _1
_1:
;
i = i + 1
}
}
// C documentation
//
// /*
// ** The second argument to this function must be either "_rowid" or
// ** "_parent". This function checks that the number of entries in the
// ** %_rowid or %_parent table is exactly nExpect. If not, it adds
// ** an error message to the report in the RtreeCheck object indicated
// ** by the first argument.
// */
func _rtreeCheckCount(tls *libc.TLS, pCheck uintptr, zTbl uintptr, nExpect Ti64) {
bp := tls.Alloc(32)
defer tls.Free(32)
var nActual Ti64
var pCount uintptr
_, _ = nActual, pCount
if (*TRtreeCheck)(unsafe.Pointer(pCheck)).Frc == SQLITE_OK {
pCount = _rtreeCheckPrepare(tls, pCheck, __ccgo_ts+29986, libc.VaList(bp+8, (*TRtreeCheck)(unsafe.Pointer(pCheck)).FzDb, (*TRtreeCheck)(unsafe.Pointer(pCheck)).FzTab, zTbl))
if pCount != 0 {
if Xsqlite3_step(tls, pCount) == int32(SQLITE_ROW) {
nActual = Xsqlite3_column_int64(tls, pCount, 0)
if nActual != nExpect {
_rtreeCheckAppendMsg(tls, pCheck, __ccgo_ts+30017, libc.VaList(bp+8, zTbl, nExpect, nActual))
}
}
(*TRtreeCheck)(unsafe.Pointer(pCheck)).Frc = Xsqlite3_finalize(tls, pCount)
}
}
}
// C documentation
//
// /*
// ** This function is a no-op if there is already an error code stored
// ** in the RtreeCheck object indicated by the first argument. NULL is
// ** returned in this case.
// **
// ** Otherwise, the contents of rtree table node iNode are loaded from
// ** the database and copied into a buffer obtained from sqlite3_malloc().
// ** If no error occurs, a pointer to the buffer is returned and (*pnNode)
// ** is set to the size of the buffer in bytes.
// **
// ** Or, if an error does occur, NULL is returned and an error code left
// ** in the RtreeCheck object. The final value of *pnNode is undefined in
// ** this case.
// */
func _rtreeCheckGetNode(tls *libc.TLS, pCheck uintptr, iNode Ti64, pnNode uintptr) (r uintptr) {
bp := tls.Alloc(32)
defer tls.Free(32)
var nNode int32
var pNode, pRet uintptr
_, _, _ = nNode, pNode, pRet
pRet = uintptr(0) /* Return value */
if (*TRtreeCheck)(unsafe.Pointer(pCheck)).Frc == SQLITE_OK && (*TRtreeCheck)(unsafe.Pointer(pCheck)).FpGetNode == uintptr(0) {
(*TRtreeCheck)(unsafe.Pointer(pCheck)).FpGetNode = _rtreeCheckPrepare(tls, pCheck, __ccgo_ts+29453, libc.VaList(bp+8, (*TRtreeCheck)(unsafe.Pointer(pCheck)).FzDb, (*TRtreeCheck)(unsafe.Pointer(pCheck)).FzTab))
}
if (*TRtreeCheck)(unsafe.Pointer(pCheck)).Frc == SQLITE_OK {
Xsqlite3_bind_int64(tls, (*TRtreeCheck)(unsafe.Pointer(pCheck)).FpGetNode, int32(1), iNode)
if Xsqlite3_step(tls, (*TRtreeCheck)(unsafe.Pointer(pCheck)).FpGetNode) == int32(SQLITE_ROW) {
nNode = Xsqlite3_column_bytes(tls, (*TRtreeCheck)(unsafe.Pointer(pCheck)).FpGetNode, 0)
pNode = Xsqlite3_column_blob(tls, (*TRtreeCheck)(unsafe.Pointer(pCheck)).FpGetNode, 0)
pRet = Xsqlite3_malloc64(tls, libc.Uint64FromInt32(nNode))
if pRet == uintptr(0) {
(*TRtreeCheck)(unsafe.Pointer(pCheck)).Frc = int32(SQLITE_NOMEM)
} else {
libc.X__builtin___memcpy_chk(tls, pRet, pNode, libc.Uint64FromInt32(nNode), ^t__predefined_size_t(0))
**(**int32)(__ccgo_up(pnNode)) = nNode
}
}
_rtreeCheckReset(tls, pCheck, (*TRtreeCheck)(unsafe.Pointer(pCheck)).FpGetNode)
if (*TRtreeCheck)(unsafe.Pointer(pCheck)).Frc == SQLITE_OK && pRet == uintptr(0) {
_rtreeCheckAppendMsg(tls, pCheck, __ccgo_ts+29498, libc.VaList(bp+8, iNode))
}
}
return pRet
}
// C documentation
//
// /*
// ** This function is used to check that the %_parent (if bLeaf==0) or %_rowid
// ** (if bLeaf==1) table contains a specified entry. The schemas of the
// ** two tables are:
// **
// ** CREATE TABLE %_parent(nodeno INTEGER PRIMARY KEY, parentnode INTEGER)
// ** CREATE TABLE %_rowid(rowid INTEGER PRIMARY KEY, nodeno INTEGER, ...)
// **
// ** In both cases, this function checks that there exists an entry with
// ** IPK value iKey and the second column set to iVal.
// **
// */
func _rtreeCheckMapping(tls *libc.TLS, pCheck uintptr, bLeaf int32, iKey Ti64, iVal Ti64) {
bp := tls.Alloc(48)
defer tls.Free(48)
var azSql [2]uintptr
var ii Ti64
var pStmt, v1 uintptr
var rc int32
_, _, _, _, _ = azSql, ii, pStmt, rc, v1
azSql = [2]uintptr{
0: __ccgo_ts + 29530,
1: __ccgo_ts + 29584,
}
if **(**uintptr)(__ccgo_up(pCheck + 40 + uintptr(bLeaf)*8)) == uintptr(0) {
**(**uintptr)(__ccgo_up(pCheck + 40 + uintptr(bLeaf)*8)) = _rtreeCheckPrepare(tls, pCheck, azSql[bLeaf], libc.VaList(bp+8, (*TRtreeCheck)(unsafe.Pointer(pCheck)).FzDb, (*TRtreeCheck)(unsafe.Pointer(pCheck)).FzTab))
}
if (*TRtreeCheck)(unsafe.Pointer(pCheck)).Frc != SQLITE_OK {
return
}
pStmt = **(**uintptr)(__ccgo_up(pCheck + 40 + uintptr(bLeaf)*8))
Xsqlite3_bind_int64(tls, pStmt, int32(1), iKey)
rc = Xsqlite3_step(tls, pStmt)
if rc == int32(SQLITE_DONE) {
if bLeaf != 0 {
v1 = __ccgo_ts + 29632
} else {
v1 = __ccgo_ts + 29640
}
_rtreeCheckAppendMsg(tls, pCheck, __ccgo_ts+29649, libc.VaList(bp+8, iKey, iVal, v1))
} else {
if rc == int32(SQLITE_ROW) {
ii = Xsqlite3_column_int64(tls, pStmt, 0)
if ii != iVal {
if bLeaf != 0 {
v1 = __ccgo_ts + 29632
} else {
v1 = __ccgo_ts + 29640
}
_rtreeCheckAppendMsg(tls, pCheck, __ccgo_ts+29694, libc.VaList(bp+8, iKey, ii, v1, iKey, iVal))
}
}
}
_rtreeCheckReset(tls, pCheck, pStmt)
}
// C documentation
//
// /*
// ** Run rtreecheck() checks on node iNode, which is at depth iDepth within
// ** the r-tree structure. Argument aParent points to the array of coordinates
// ** that bound node iNode on the parent node.
// **
// ** If any problems are discovered, an error message is appended to the
// ** report accumulated in the RtreeCheck object.
// */
func _rtreeCheckNode(tls *libc.TLS, pCheck uintptr, iDepth int32, aParent uintptr, iNode Ti64) {
bp := tls.Alloc(48)
defer tls.Free(48)
var aNode, pCell uintptr
var i, nCell int32
var iVal Ti64
var _ /* nNode at bp+0 */ int32
_, _, _, _, _ = aNode, i, iVal, nCell, pCell
aNode = uintptr(0)
**(**int32)(__ccgo_up(bp)) = 0
aNode = _rtreeCheckGetNode(tls, pCheck, iNode, bp)
if aNode != 0 {
if **(**int32)(__ccgo_up(bp)) < int32(4) {
_rtreeCheckAppendMsg(tls, pCheck, __ccgo_ts+29867, libc.VaList(bp+16, iNode, **(**int32)(__ccgo_up(bp))))
} else { /* Used to iterate through cells */
if aParent == uintptr(0) {
iDepth = _readInt16(tls, aNode)
if iDepth > int32(RTREE_MAX_DEPTH) {
_rtreeCheckAppendMsg(tls, pCheck, __ccgo_ts+29901, libc.VaList(bp+16, iDepth))
Xsqlite3_free(tls, aNode)
return
}
}
nCell = _readInt16(tls, aNode+2)
if int32(4)+nCell*(int32(8)+(*TRtreeCheck)(unsafe.Pointer(pCheck)).FnDim*int32(2)*int32(4)) > **(**int32)(__ccgo_up(bp)) {
_rtreeCheckAppendMsg(tls, pCheck, __ccgo_ts+29931, libc.VaList(bp+16, iNode, nCell, **(**int32)(__ccgo_up(bp))))
} else {
i = 0
for {
if !(i < nCell) {
break
}
pCell = aNode + uintptr(int32(4)+i*(int32(8)+(*TRtreeCheck)(unsafe.Pointer(pCheck)).FnDim*int32(2)*int32(4)))
iVal = _readInt64(tls, pCell)
_rtreeCheckCellCoord(tls, pCheck, iNode, i, pCell+8, aParent)
if iDepth > 0 {
_rtreeCheckMapping(tls, pCheck, 0, iVal, iNode)
_rtreeCheckNode(tls, pCheck, iDepth-int32(1), pCell+8, iVal)
(*TRtreeCheck)(unsafe.Pointer(pCheck)).FnNonLeaf = (*TRtreeCheck)(unsafe.Pointer(pCheck)).FnNonLeaf + 1
} else {
_rtreeCheckMapping(tls, pCheck, int32(1), iVal, iNode)
(*TRtreeCheck)(unsafe.Pointer(pCheck)).FnLeaf = (*TRtreeCheck)(unsafe.Pointer(pCheck)).FnLeaf + 1
}
goto _1
_1:
;
i = i + 1
}
}
}
Xsqlite3_free(tls, aNode)
}
}
// C documentation
//
// /*
// ** This function does the bulk of the work for the rtree integrity-check.
// ** It is called by rtreecheck(), which is the SQL function implementation.
// */
func _rtreeCheckTable(tls *libc.TLS, db uintptr, zDb uintptr, zTab uintptr, pzReport uintptr) (r int32) {
bp := tls.Alloc(112)
defer tls.Free(112)
var nAux, rc int32
var pStmt uintptr
var _ /* check at bp+0 */ TRtreeCheck
_, _, _ = nAux, pStmt, rc /* Common context for various routines */
pStmt = uintptr(0) /* Used to find column count of rtree table */
nAux = 0 /* Number of extra columns. */
/* Initialize the context object */
libc.X__builtin___memset_chk(tls, bp, 0, uint64(88), ^t__predefined_size_t(0))
(**(**TRtreeCheck)(__ccgo_up(bp))).Fdb = db
(**(**TRtreeCheck)(__ccgo_up(bp))).FzDb = zDb
(**(**TRtreeCheck)(__ccgo_up(bp))).FzTab = zTab
/* Find the number of auxiliary columns */
pStmt = _rtreeCheckPrepare(tls, bp, __ccgo_ts+30084, libc.VaList(bp+96, zDb, zTab))
if pStmt != 0 {
nAux = Xsqlite3_column_count(tls, pStmt) - int32(2)
Xsqlite3_finalize(tls, pStmt)
} else {
if (**(**TRtreeCheck)(__ccgo_up(bp))).Frc != int32(SQLITE_NOMEM) {
(**(**TRtreeCheck)(__ccgo_up(bp))).Frc = SQLITE_OK
}
}
/* Find number of dimensions in the rtree table. */
pStmt = _rtreeCheckPrepare(tls, bp, __ccgo_ts+27900, libc.VaList(bp+96, zDb, zTab))
if pStmt != 0 {
(**(**TRtreeCheck)(__ccgo_up(bp))).FnDim = (Xsqlite3_column_count(tls, pStmt) - int32(1) - nAux) / int32(2)
if (**(**TRtreeCheck)(__ccgo_up(bp))).FnDim < int32(1) {
_rtreeCheckAppendMsg(tls, bp, __ccgo_ts+30112, 0)
} else {
if int32(SQLITE_ROW) == Xsqlite3_step(tls, pStmt) {
(**(**TRtreeCheck)(__ccgo_up(bp))).FbInt = libc.BoolInt32(Xsqlite3_column_type(tls, pStmt, int32(1)) == int32(SQLITE_INTEGER))
}
}
rc = Xsqlite3_finalize(tls, pStmt)
if rc != int32(SQLITE_CORRUPT) {
(**(**TRtreeCheck)(__ccgo_up(bp))).Frc = rc
}
}
/* Do the actual integrity-check */
if (**(**TRtreeCheck)(__ccgo_up(bp))).FnDim >= int32(1) {
if (**(**TRtreeCheck)(__ccgo_up(bp))).Frc == SQLITE_OK {
_rtreeCheckNode(tls, bp, 0, uintptr(0), int64(1))
}
_rtreeCheckCount(tls, bp, __ccgo_ts+30143, int64((**(**TRtreeCheck)(__ccgo_up(bp))).FnLeaf))
_rtreeCheckCount(tls, bp, __ccgo_ts+30150, int64((**(**TRtreeCheck)(__ccgo_up(bp))).FnNonLeaf))
}
/* Finalize SQL statements used by the integrity-check */
Xsqlite3_finalize(tls, (**(**TRtreeCheck)(__ccgo_up(bp))).FpGetNode)
Xsqlite3_finalize(tls, **(**uintptr)(__ccgo_up(bp + 40)))
Xsqlite3_finalize(tls, **(**uintptr)(__ccgo_up(bp + 40 + 1*8)))
**(**uintptr)(__ccgo_up(pzReport)) = (**(**TRtreeCheck)(__ccgo_up(bp))).FzReport
return (**(**TRtreeCheck)(__ccgo_up(bp))).Frc
}
// C documentation
//
// /*
// ** A constraint has failed while inserting a row into an rtree table.
// ** Assuming no OOM error occurs, this function sets the error message
// ** (at pRtree->base.zErrMsg) to an appropriate value and returns
// ** SQLITE_CONSTRAINT.
// **
// ** Parameter iCol is the index of the leftmost column involved in the
// ** constraint failure. If it is 0, then the constraint that failed is
// ** the unique constraint on the id column. Otherwise, it is the rtree
// ** (c1<=c2) constraint on columns iCol and iCol+1 that has failed.
// **
// ** If an OOM occurs, SQLITE_NOMEM is returned instead of SQLITE_CONSTRAINT.
// */
func _rtreeConstraintError(tls *libc.TLS, pRtree uintptr, iCol int32) (r int32) {
bp := tls.Alloc(48)
defer tls.Free(48)
var rc, v1 int32
var zCol, zCol1, zCol2, zSql uintptr
var _ /* pStmt at bp+0 */ uintptr
_, _, _, _, _, _ = rc, zCol, zCol1, zCol2, zSql, v1
**(**uintptr)(__ccgo_up(bp)) = uintptr(0)
zSql = Xsqlite3_mprintf(tls, __ccgo_ts+27900, libc.VaList(bp+16, (*TRtree)(unsafe.Pointer(pRtree)).FzDb, (*TRtree)(unsafe.Pointer(pRtree)).FzName))
if zSql != 0 {
rc = Xsqlite3_prepare_v2(tls, (*TRtree)(unsafe.Pointer(pRtree)).Fdb, zSql, -int32(1), bp, uintptr(0))
} else {
rc = int32(SQLITE_NOMEM)
}
Xsqlite3_free(tls, zSql)
if rc == SQLITE_OK {
if iCol == 0 {
zCol = Xsqlite3_column_name(tls, **(**uintptr)(__ccgo_up(bp)), 0)
(*TRtree)(unsafe.Pointer(pRtree)).Fbase.FzErrMsg = Xsqlite3_mprintf(tls, __ccgo_ts+27920, libc.VaList(bp+16, (*TRtree)(unsafe.Pointer(pRtree)).FzName, zCol))
} else {
zCol1 = Xsqlite3_column_name(tls, **(**uintptr)(__ccgo_up(bp)), iCol)
zCol2 = Xsqlite3_column_name(tls, **(**uintptr)(__ccgo_up(bp)), iCol+int32(1))
(*TRtree)(unsafe.Pointer(pRtree)).Fbase.FzErrMsg = Xsqlite3_mprintf(tls, __ccgo_ts+27952, libc.VaList(bp+16, (*TRtree)(unsafe.Pointer(pRtree)).FzName, zCol1, zCol2))
}
}
Xsqlite3_finalize(tls, **(**uintptr)(__ccgo_up(bp)))
if rc == SQLITE_OK {
v1 = int32(SQLITE_CONSTRAINT)
} else {
v1 = rc
}
return v1
}
// C documentation
//
// /*
// ** Rtree virtual table module xDestroy method.
// */
func _rtreeDestroy(tls *libc.TLS, pVtab uintptr) (r int32) {
bp := tls.Alloc(64)
defer tls.Free(64)
var pRtree, zCreate uintptr
var rc int32
_, _, _ = pRtree, rc, zCreate
pRtree = pVtab
zCreate = Xsqlite3_mprintf(tls, __ccgo_ts+27804, libc.VaList(bp+8, (*TRtree)(unsafe.Pointer(pRtree)).FzDb, (*TRtree)(unsafe.Pointer(pRtree)).FzName, (*TRtree)(unsafe.Pointer(pRtree)).FzDb, (*TRtree)(unsafe.Pointer(pRtree)).FzName, (*TRtree)(unsafe.Pointer(pRtree)).FzDb, (*TRtree)(unsafe.Pointer(pRtree)).FzName))
if !(zCreate != 0) {
rc = int32(SQLITE_NOMEM)
} else {
_nodeBlobReset(tls, pRtree)
rc = Xsqlite3_exec(tls, (*TRtree)(unsafe.Pointer(pRtree)).Fdb, zCreate, uintptr(0), uintptr(0), uintptr(0))
Xsqlite3_free(tls, zCreate)
}
if rc == SQLITE_OK {
_rtreeRelease(tls, pRtree)
}
return rc
}
// C documentation
//
// /*
// ** Rtree virtual table module xFilter method.
// */
func _rtreeFilter(tls *libc.TLS, pVtabCursor uintptr, idxNum int32, idxStr uintptr, argc int32, argv uintptr) (r int32) {
bp := tls.Alloc(32)
defer tls.Free(32)
var eType, eType1, ii, rc int32
var iRowid Ti64
var iVal Tsqlite3_int64
var p, p1, pCsr, pNew, pRtree uintptr
var _ /* iCell at bp+8 */ int32
var _ /* iNode at bp+24 */ Ti64
var _ /* pLeaf at bp+16 */ uintptr
var _ /* pRoot at bp+0 */ uintptr
_, _, _, _, _, _, _, _, _, _, _ = eType, eType1, iRowid, iVal, ii, p, p1, pCsr, pNew, pRtree, rc
pRtree = (*Tsqlite3_vtab_cursor)(unsafe.Pointer(pVtabCursor)).FpVtab
pCsr = pVtabCursor
**(**uintptr)(__ccgo_up(bp)) = uintptr(0)
rc = SQLITE_OK
**(**int32)(__ccgo_up(bp + 8)) = 0
_rtreeReference(tls, pRtree)
/* Reset the cursor to the same state as rtreeOpen() leaves it in. */
_resetCursor(tls, pCsr)
(*TRtreeCursor)(unsafe.Pointer(pCsr)).FiStrategy = idxNum
if idxNum == int32(1) { /* Search point for the leaf */
iRowid = Xsqlite3_value_int64(tls, **(**uintptr)(__ccgo_up(argv)))
**(**Ti64)(__ccgo_up(bp + 24)) = 0
eType = Xsqlite3_value_numeric_type(tls, **(**uintptr)(__ccgo_up(argv)))
if eType == int32(SQLITE_INTEGER) || eType == int32(SQLITE_FLOAT) && 0 == _sqlite3IntFloatCompare(tls, iRowid, Xsqlite3_value_double(tls, **(**uintptr)(__ccgo_up(argv)))) {
rc = _findLeafNode(tls, pRtree, iRowid, bp+16, bp+24)
} else {
rc = SQLITE_OK
**(**uintptr)(__ccgo_up(bp + 16)) = uintptr(0)
}
if rc == SQLITE_OK && **(**uintptr)(__ccgo_up(bp + 16)) != uintptr(0) {
p = _rtreeSearchPointNew(tls, pCsr, float64(0), uint8(0))
/* Always returns pCsr->sPoint */
**(**uintptr)(__ccgo_up(pCsr + 88)) = **(**uintptr)(__ccgo_up(bp + 16))
(*TRtreeSearchPoint)(unsafe.Pointer(p)).Fid = **(**Ti64)(__ccgo_up(bp + 24))
(*TRtreeSearchPoint)(unsafe.Pointer(p)).FeWithin = uint8(PARTLY_WITHIN)
rc = _nodeRowidIndex(tls, pRtree, **(**uintptr)(__ccgo_up(bp + 16)), iRowid, bp+8)
(*TRtreeSearchPoint)(unsafe.Pointer(p)).FiCell = libc.Uint8FromInt32(**(**int32)(__ccgo_up(bp + 8)))
} else {
(*TRtreeCursor)(unsafe.Pointer(pCsr)).FatEOF = uint8(1)
}
} else {
/* Normal case - r-tree scan. Set up the RtreeCursor.aConstraint array
** with the configured constraints.
*/
rc = _nodeAcquire(tls, pRtree, int64(1), uintptr(0), bp)
if rc == SQLITE_OK && argc > 0 {
(*TRtreeCursor)(unsafe.Pointer(pCsr)).FaConstraint = Xsqlite3_malloc64(tls, uint64(uint64(24)*libc.Uint64FromInt32(argc)))
(*TRtreeCursor)(unsafe.Pointer(pCsr)).FnConstraint = argc
if !((*TRtreeCursor)(unsafe.Pointer(pCsr)).FaConstraint != 0) {
rc = int32(SQLITE_NOMEM)
} else {
libc.X__builtin___memset_chk(tls, (*TRtreeCursor)(unsafe.Pointer(pCsr)).FaConstraint, 0, uint64(24)*libc.Uint64FromInt32(argc), ^t__predefined_size_t(0))
libc.X__builtin___memset_chk(tls, pCsr+128, 0, uint64(4)*libc.Uint64FromInt32((*TRtree)(unsafe.Pointer(pRtree)).FiDepth+libc.Int32FromInt32(1)), ^t__predefined_size_t(0))
ii = 0
for {
if !(ii < argc) {
break
}
p1 = (*TRtreeCursor)(unsafe.Pointer(pCsr)).FaConstraint + uintptr(ii)*24
eType1 = Xsqlite3_value_numeric_type(tls, **(**uintptr)(__ccgo_up(argv + uintptr(ii)*8)))
(*TRtreeConstraint)(unsafe.Pointer(p1)).Fop = int32(**(**int8)(__ccgo_up(idxStr + uintptr(ii*int32(2)))))
(*TRtreeConstraint)(unsafe.Pointer(p1)).FiCoord = int32(**(**int8)(__ccgo_up(idxStr + uintptr(ii*int32(2)+int32(1))))) - int32('0')
if (*TRtreeConstraint)(unsafe.Pointer(p1)).Fop >= int32(RTREE_MATCH) {
/* A MATCH operator. The right-hand-side must be a blob that
** can be cast into an RtreeMatchArg object. One created using
** an sqlite3_rtree_geometry_callback() SQL user function.
*/
rc = _deserializeGeometry(tls, **(**uintptr)(__ccgo_up(argv + uintptr(ii)*8)), p1)
if rc != SQLITE_OK {
break
}
(*Tsqlite3_rtree_query_info)(unsafe.Pointer((*TRtreeConstraint)(unsafe.Pointer(p1)).FpInfo)).FnCoord = libc.Int32FromUint8((*TRtree)(unsafe.Pointer(pRtree)).FnDim2)
(*Tsqlite3_rtree_query_info)(unsafe.Pointer((*TRtreeConstraint)(unsafe.Pointer(p1)).FpInfo)).FanQueue = pCsr + 128
(*Tsqlite3_rtree_query_info)(unsafe.Pointer((*TRtreeConstraint)(unsafe.Pointer(p1)).FpInfo)).FmxLevel = (*TRtree)(unsafe.Pointer(pRtree)).FiDepth + int32(1)
} else {
if eType1 == int32(SQLITE_INTEGER) {
iVal = Xsqlite3_value_int64(tls, **(**uintptr)(__ccgo_up(argv + uintptr(ii)*8)))
*(*TRtreeDValue)(unsafe.Pointer(p1 + 8)) = float64(iVal)
if iVal >= libc.Int64FromInt32(1)<bPoint was FALSE */
return int32(SQLITE_NOMEM)
}
(*TRtreeSearchPoint)(unsafe.Pointer(pNew)).Fid = int64(1)
(*TRtreeSearchPoint)(unsafe.Pointer(pNew)).FiCell = uint8(0)
(*TRtreeSearchPoint)(unsafe.Pointer(pNew)).FeWithin = uint8(PARTLY_WITHIN)
**(**uintptr)(__ccgo_up(pCsr + 88)) = **(**uintptr)(__ccgo_up(bp))
**(**uintptr)(__ccgo_up(bp)) = uintptr(0)
rc = _rtreeStepToLeaf(tls, pCsr)
}
}
_nodeRelease(tls, pRtree, **(**uintptr)(__ccgo_up(bp)))
_rtreeRelease(tls, pRtree)
return rc
}
// 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 + 29192,
2: __ccgo_ts + 29235,
3: __ccgo_ts + 29270,
4: __ccgo_ts + 29306,
}
if argc < int32(6) || argc > libc.Int32FromInt32(RTREE_MAX_AUX_COLUMN)+libc.Int32FromInt32(3) {
**(**uintptr)(__ccgo_up(pzErr)) = Xsqlite3_mprintf(tls, __ccgo_ts+3944, 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.Int32FromUint64(libc.Xstrlen(tls, **(**uintptr)(__ccgo_up(argv + 1*8))))
nName = libc.Int32FromUint64(libc.Xstrlen(tls, **(**uintptr)(__ccgo_up(argv + 2*8))))
pRtree = Xsqlite3_malloc64(tls, uint64(uint64(976)+libc.Uint64FromInt32(nDb)+libc.Uint64FromInt32(nName*int32(2))+uint64(8)))
if !(pRtree != 0) {
return int32(SQLITE_NOMEM)
}
libc.X__builtin___memset_chk(tls, pRtree, 0, uint64(976)+libc.Uint64FromInt32(nDb)+libc.Uint64FromInt32(nName*int32(2))+uint64(8), ^t__predefined_size_t(0))
(*TRtree)(unsafe.Pointer(pRtree)).FnBusy = uint32(1)
(*TRtree)(unsafe.Pointer(pRtree)).Fbase.FpModule = uintptr(unsafe.Pointer(&_rtreeModule))
(*TRtree)(unsafe.Pointer(pRtree)).FzDb = pRtree + 1*976
(*TRtree)(unsafe.Pointer(pRtree)).FzName = (*TRtree)(unsafe.Pointer(pRtree)).FzDb + uintptr(nDb+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.X__builtin___memcpy_chk(tls, (*TRtree)(unsafe.Pointer(pRtree)).FzDb, **(**uintptr)(__ccgo_up(argv + 1*8)), libc.Uint64FromInt32(nDb), ^t__predefined_size_t(0))
libc.X__builtin___memcpy_chk(tls, (*TRtree)(unsafe.Pointer(pRtree)).FzName, **(**uintptr)(__ccgo_up(argv + 2*8)), libc.Uint64FromInt32(nName), ^t__predefined_size_t(0))
libc.X__builtin___memcpy_chk(tls, (*TRtree)(unsafe.Pointer(pRtree)).FzNodeName, **(**uintptr)(__ccgo_up(argv + 2*8)), libc.Uint64FromInt32(nName), ^t__predefined_size_t(0))
libc.X__builtin___memcpy_chk(tls, (*TRtree)(unsafe.Pointer(pRtree)).FzNodeName+uintptr(nName), __ccgo_ts+29343, uint64(6), ^t__predefined_size_t(0))
/* 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+29349, libc.VaList(bp+8, _rtreeTokenLength(tls, **(**uintptr)(__ccgo_up(argv + 3*8))), **(**uintptr)(__ccgo_up(argv + 3*8))))
ii = int32(4)
for {
if !(ii < argc) {
break
}
zArg = **(**uintptr)(__ccgo_up(argv + uintptr(ii)*8))
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+29373, 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+29400, 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+3944, 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+3944, 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+3944, 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*8)), **(**uintptr)(__ccgo_up(argv + 2*8)), isCreate)
if rc != 0 {
**(**uintptr)(__ccgo_up(pzErr)) = Xsqlite3_mprintf(tls, __ccgo_ts+3944, 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
}
// C documentation
//
// /*
// ** Implementation of the xIntegrity method for Rtree.
// */
func _rtreeIntegrity(tls *libc.TLS, pVtab uintptr, zSchema uintptr, zName uintptr, isQuick int32, pzErr uintptr) (r int32) {
bp := tls.Alloc(32)
defer tls.Free(32)
var pRtree uintptr
var rc int32
_, _ = pRtree, rc
pRtree = pVtab
_ = zSchema
_ = zName
_ = isQuick
rc = _rtreeCheckTable(tls, (*TRtree)(unsafe.Pointer(pRtree)).Fdb, (*TRtree)(unsafe.Pointer(pRtree)).FzDb, (*TRtree)(unsafe.Pointer(pRtree)).FzName, pzErr)
if rc == SQLITE_OK && **(**uintptr)(__ccgo_up(pzErr)) != 0 {
**(**uintptr)(__ccgo_up(pzErr)) = Xsqlite3_mprintf(tls, __ccgo_ts+30158, libc.VaList(bp+8, (*TRtree)(unsafe.Pointer(pRtree)).FzDb, (*TRtree)(unsafe.Pointer(pRtree)).FzName, **(**uintptr)(__ccgo_up(pzErr))))
if **(**uintptr)(__ccgo_up(pzErr)) == uintptr(0) {
rc = int32(SQLITE_NOMEM)
}
}
return rc
}
// C documentation
//
// /*
// ** Check the leaf RTree cell given by pCellData against constraint p.
// ** If this constraint is not satisfied, set *peWithin to NOT_WITHIN.
// ** If the constraint is satisfied, leave *peWithin unchanged.
// **
// ** The constraint is of the form: xN op $val
// **
// ** The op is given by p->op. The xN is p->iCoord-th coordinate in
// ** pCellData. $val is given by p->u.rValue.
// */
func _rtreeLeafConstraint(tls *libc.TLS, p uintptr, eInt int32, pCellData uintptr, peWithin uintptr) {
bp := tls.Alloc(16)
defer tls.Free(16)
var xN TRtreeDValue
var v1 Tsqlite3_rtree_dbl
var _ /* c at bp+0 */ TRtreeCoord
_, _ = xN, v1 /* Coordinate value converted to a double */
pCellData = pCellData + uintptr(int32(8)+(*TRtreeConstraint)(unsafe.Pointer(p)).FiCoord*int32(4))
libc.X__builtin___memcpy_chk(tls, bp, pCellData, uint64(4), ^t__predefined_size_t(0))
*(*Tu32)(unsafe.Pointer(bp)) = *(*Tu32)(unsafe.Pointer(bp))>>libc.Int32FromInt32(24)&uint32(0xff) | *(*Tu32)(unsafe.Pointer(bp))>>libc.Int32FromInt32(8)&uint32(0xff00) | *(*Tu32)(unsafe.Pointer(bp))&uint32(0xff)<= *(*TRtreeDValue)(unsafe.Pointer(p + 8)) {
return
}
case int32(RTREE_GT):
if xN > *(*TRtreeDValue)(unsafe.Pointer(p + 8)) {
return
}
default:
if xN == *(*TRtreeDValue)(unsafe.Pointer(p + 8)) {
return
}
break
}
**(**int32)(__ccgo_up(peWithin)) = NOT_WITHIN
}
// C documentation
//
// /*
// ** Check the internal RTree node given by pCellData against constraint p.
// ** If this constraint cannot be satisfied by any child within the node,
// ** set *peWithin to NOT_WITHIN.
// */
func _rtreeNonleafConstraint(tls *libc.TLS, p uintptr, eInt int32, pCellData uintptr, peWithin uintptr) {
bp := tls.Alloc(16)
defer tls.Free(16)
var val, v1 Tsqlite3_rtree_dbl
var _ /* c at bp+0 */ TRtreeCoord
var _ /* c at bp+12 */ TRtreeCoord
var _ /* c at bp+4 */ TRtreeCoord
var _ /* c at bp+8 */ TRtreeCoord
_, _ = val, v1 /* Coordinate value convert to a double */
/* p->iCoord might point to either a lower or upper bound coordinate
** in a coordinate pair. But make pCellData point to the lower bound.
*/
pCellData = pCellData + uintptr(int32(8)+int32(4)*((*TRtreeConstraint)(unsafe.Pointer(p)).FiCoord&int32(0xfe)))
switch (*TRtreeConstraint)(unsafe.Pointer(p)).Fop {
case int32(RTREE_TRUE):
return /* Always satisfied */
case int32(RTREE_FALSE):
case int32(RTREE_EQ):
libc.X__builtin___memcpy_chk(tls, bp, pCellData, uint64(4), ^t__predefined_size_t(0))
*(*Tu32)(unsafe.Pointer(bp)) = *(*Tu32)(unsafe.Pointer(bp))>>libc.Int32FromInt32(24)&uint32(0xff) | *(*Tu32)(unsafe.Pointer(bp))>>libc.Int32FromInt32(8)&uint32(0xff00) | *(*Tu32)(unsafe.Pointer(bp))&uint32(0xff)<= val {
pCellData = pCellData + uintptr(4)
libc.X__builtin___memcpy_chk(tls, bp+4, pCellData, uint64(4), ^t__predefined_size_t(0))
*(*Tu32)(unsafe.Pointer(bp + 4)) = *(*Tu32)(unsafe.Pointer(bp + 4))>>libc.Int32FromInt32(24)&uint32(0xff) | *(*Tu32)(unsafe.Pointer(bp + 4))>>libc.Int32FromInt32(8)&uint32(0xff00) | *(*Tu32)(unsafe.Pointer(bp + 4))&uint32(0xff)<>libc.Int32FromInt32(24)&uint32(0xff) | *(*Tu32)(unsafe.Pointer(bp + 8))>>libc.Int32FromInt32(8)&uint32(0xff00) | *(*Tu32)(unsafe.Pointer(bp + 8))&uint32(0xff)<= val {
return
}
default:
pCellData = pCellData + uintptr(4)
libc.X__builtin___memcpy_chk(tls, bp+12, pCellData, uint64(4), ^t__predefined_size_t(0))
*(*Tu32)(unsafe.Pointer(bp + 12)) = *(*Tu32)(unsafe.Pointer(bp + 12))>>libc.Int32FromInt32(24)&uint32(0xff) | *(*Tu32)(unsafe.Pointer(bp + 12))>>libc.Int32FromInt32(8)&uint32(0xff00) | *(*Tu32)(unsafe.Pointer(bp + 12))&uint32(0xff)<nRowEst variable with an estimate
// ** of the number of rows in the virtual table. If possible, this is based
// ** on sqlite_stat1 data. Otherwise, use RTREE_DEFAULT_ROWEST.
// */
func _rtreeQueryStat1(tls *libc.TLS, db uintptr, pRtree uintptr) (r int32) {
bp := tls.Alloc(32)
defer tls.Free(32)
var nRow Ti64
var rc, v1 int32
var zFmt, zSql uintptr
var v2 int64
var _ /* p at bp+0 */ uintptr
_, _, _, _, _, _ = nRow, rc, zFmt, zSql, v1, v2
zFmt = __ccgo_ts + 28134
nRow = int64(RTREE_MIN_ROWEST)
rc = Xsqlite3_table_column_metadata(tls, db, (*TRtree)(unsafe.Pointer(pRtree)).FzDb, __ccgo_ts+13181, uintptr(0), uintptr(0), uintptr(0), uintptr(0), uintptr(0), uintptr(0))
if rc != SQLITE_OK {
(*TRtree)(unsafe.Pointer(pRtree)).FnRowEst = int64(RTREE_DEFAULT_ROWEST)
if rc == int32(SQLITE_ERROR) {
v1 = SQLITE_OK
} else {
v1 = rc
}
return v1
}
zSql = Xsqlite3_mprintf(tls, zFmt, libc.VaList(bp+16, (*TRtree)(unsafe.Pointer(pRtree)).FzDb, (*TRtree)(unsafe.Pointer(pRtree)).FzName))
if zSql == uintptr(0) {
rc = int32(SQLITE_NOMEM)
} else {
rc = Xsqlite3_prepare_v2(tls, db, zSql, -int32(1), bp, uintptr(0))
if rc == SQLITE_OK {
if Xsqlite3_step(tls, **(**uintptr)(__ccgo_up(bp))) == int32(SQLITE_ROW) {
nRow = Xsqlite3_column_int64(tls, **(**uintptr)(__ccgo_up(bp)), 0)
}
rc = Xsqlite3_finalize(tls, **(**uintptr)(__ccgo_up(bp)))
}
Xsqlite3_free(tls, zSql)
}
if nRow > int64(libc.Int32FromInt32(RTREE_MIN_ROWEST)) {
v2 = nRow
} else {
v2 = int64(libc.Int32FromInt32(RTREE_MIN_ROWEST))
}
(*TRtree)(unsafe.Pointer(pRtree)).FnRowEst = v2
return rc
}
// C documentation
//
// /*
// ** The xRename method for rtree module virtual tables.
// */
func _rtreeRename(tls *libc.TLS, pVtab uintptr, zNewName uintptr) (r int32) {
bp := tls.Alloc(80)
defer tls.Free(80)
var pRtree, zSql uintptr
var rc int32
_, _, _ = pRtree, rc, zSql
pRtree = pVtab
rc = int32(SQLITE_NOMEM)
zSql = Xsqlite3_mprintf(tls, __ccgo_ts+27989, libc.VaList(bp+8, (*TRtree)(unsafe.Pointer(pRtree)).FzDb, (*TRtree)(unsafe.Pointer(pRtree)).FzName, zNewName, (*TRtree)(unsafe.Pointer(pRtree)).FzDb, (*TRtree)(unsafe.Pointer(pRtree)).FzName, zNewName, (*TRtree)(unsafe.Pointer(pRtree)).FzDb, (*TRtree)(unsafe.Pointer(pRtree)).FzName, zNewName))
if zSql != 0 {
_nodeBlobReset(tls, pRtree)
rc = Xsqlite3_exec(tls, (*TRtree)(unsafe.Pointer(pRtree)).Fdb, zSql, uintptr(0), uintptr(0), uintptr(0))
Xsqlite3_free(tls, zSql)
}
return rc
}
func _rtreeSqlInit(tls *libc.TLS, pRtree uintptr, db uintptr, zDb uintptr, zPrefix uintptr, isCreate int32) (r int32) {
bp := tls.Alloc(32)
defer tls.Free(32)
var appStmt [8]uintptr
var f, i, ii, ii1, rc int32
var p, p1, zCreate, zFormat, zSql, zSql1 uintptr
_, _, _, _, _, _, _, _, _, _, _, _ = appStmt, f, i, ii, ii1, p, p1, rc, zCreate, zFormat, zSql, zSql1
rc = SQLITE_OK
f = libc.Int32FromInt32(SQLITE_PREPARE_PERSISTENT) | libc.Int32FromInt32(SQLITE_PREPARE_NO_VTAB)
(*TRtree)(unsafe.Pointer(pRtree)).Fdb = db
if isCreate != 0 {
p = Xsqlite3_str_new(tls, db)
Xsqlite3_str_appendf(tls, p, __ccgo_ts+28604, 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+28666, libc.VaList(bp+8, ii))
goto _1
_1:
;
ii = ii + 1
}
Xsqlite3_str_appendf(tls, p, __ccgo_ts+28671, libc.VaList(bp+8, zDb, zPrefix))
Xsqlite3_str_appendf(tls, p, __ccgo_ts+28735, libc.VaList(bp+8, zDb, zPrefix))
Xsqlite3_str_appendf(tls, p, __ccgo_ts+28805, libc.VaList(bp+8, zDb, zPrefix, (*TRtree)(unsafe.Pointer(pRtree)).FiNodeSize))
zCreate = Xsqlite3_str_finish(tls, p)
if !(zCreate != 0) {
return int32(SQLITE_NOMEM)
}
rc = Xsqlite3_exec(tls, db, zCreate, uintptr(0), uintptr(0), uintptr(0))
Xsqlite3_free(tls, zCreate)
if rc != SQLITE_OK {
return rc
}
}
appStmt[0] = pRtree + 128
appStmt[int32(1)] = pRtree + 136
appStmt[int32(2)] = pRtree + 144
appStmt[int32(3)] = pRtree + 152
appStmt[int32(4)] = pRtree + 160
appStmt[int32(5)] = pRtree + 168
appStmt[int32(6)] = pRtree + 176
appStmt[int32(7)] = pRtree + 184
rc = _rtreeQueryStat1(tls, db, pRtree)
i = 0
for {
if !(i < int32(N_STATEMENT) && rc == SQLITE_OK) {
break
}
if i != int32(3) || libc.Int32FromUint16((*TRtree)(unsafe.Pointer(pRtree)).FnAux) == 0 {
zFormat = _azSql[i]
} else {
/* An UPSERT is very slightly slower than REPLACE, but it is needed
** if there are auxiliary columns */
zFormat = __ccgo_ts + 28854
}
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+28962, 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+29007, 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+14694, int32(1))
}
if ii1 < libc.Int32FromUint8((*TRtree)(unsafe.Pointer(pRtree)).FnAuxNotNull) {
Xsqlite3_str_appendf(tls, p1, __ccgo_ts+29034, libc.VaList(bp+8, ii1, ii1+int32(2), ii1))
} else {
Xsqlite3_str_appendf(tls, p1, __ccgo_ts+29056, libc.VaList(bp+8, ii1, ii1+int32(2)))
}
goto _3
_3:
;
ii1 = ii1 + 1
}
Xsqlite3_str_appendf(tls, p1, __ccgo_ts+29064, 0)
zSql1 = Xsqlite3_str_finish(tls, p1)
if zSql1 == uintptr(0) {
rc = int32(SQLITE_NOMEM)
} else {
rc = Xsqlite3_prepare_v3(tls, db, zSql1, -int32(1), libc.Uint32FromInt32(f), pRtree+192, uintptr(0))
Xsqlite3_free(tls, zSql1)
}
}
}
return rc
}
// C documentation
//
// /*
// ** The xUpdate method for rtree module virtual tables.
// */
func _rtreeUpdate(tls *libc.TLS, pVtab uintptr, nData int32, aData uintptr, pRowid uintptr) (r int32) {
bp := tls.Alloc(64)
defer tls.Free(64)
var bHaveRowid, ii, jj, nn, rc, rc2, steprc int32
var pRtree, pUp uintptr
var _ /* cell at bp+0 */ TRtreeCell
var _ /* pLeaf at bp+48 */ uintptr
_, _, _, _, _, _, _, _, _ = bHaveRowid, ii, jj, nn, pRtree, pUp, rc, rc2, steprc
pRtree = pVtab
rc = SQLITE_OK /* New cell to insert if nData>1 */
bHaveRowid = 0 /* Set to 1 after new rowid is determined */
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)<=x1" constraint.
**
** In the first case, if the conflict-handling mode is REPLACE, then
** the conflicting row can be removed before proceeding. In the second
** case, SQLITE_CONSTRAINT must be returned regardless of the
** conflict-handling mode specified by the user.
*/
if nData > int32(1) {
nn = nData - int32(4)
if nn > libc.Int32FromUint8((*TRtree)(unsafe.Pointer(pRtree)).FnDim2) {
nn = libc.Int32FromUint8((*TRtree)(unsafe.Pointer(pRtree)).FnDim2)
}
/* Populate the cell.aCoord[] array. The first coordinate is aData[3].
**
** NB: nData can only be less than nDim*2+3 if the rtree is mis-declared
** with "column" that are interpreted as table constraints.
** Example: CREATE VIRTUAL TABLE bad USING rtree(x,y,CHECK(y>5));
** This problem was discovered after years of use, so we silently ignore
** these kinds of misdeclared tables to avoid breaking any legacy.
*/
if libc.Int32FromUint8((*TRtree)(unsafe.Pointer(pRtree)).FeCoordType) == RTREE_COORD_REAL32 {
ii = 0
for {
if !(ii < nn) {
break
}
*(*TRtreeValue)(unsafe.Pointer(bp + 8 + uintptr(ii)*4)) = _rtreeValueDown(tls, **(**uintptr)(__ccgo_up(aData + uintptr(ii+int32(3))*8)))
*(*TRtreeValue)(unsafe.Pointer(bp + 8 + uintptr(ii+int32(1))*4)) = _rtreeValueUp(tls, **(**uintptr)(__ccgo_up(aData + uintptr(ii+int32(4))*8)))
if *(*TRtreeValue)(unsafe.Pointer(bp + 8 + uintptr(ii)*4)) > *(*TRtreeValue)(unsafe.Pointer(bp + 8 + uintptr(ii+int32(1))*4)) {
rc = _rtreeConstraintError(tls, pRtree, ii+int32(1))
goto constraint
}
goto _1
_1:
;
ii = ii + int32(2)
}
} else {
ii = 0
for {
if !(ii < nn) {
break
}
*(*int32)(unsafe.Pointer(bp + 8 + uintptr(ii)*4)) = Xsqlite3_value_int(tls, **(**uintptr)(__ccgo_up(aData + uintptr(ii+int32(3))*8)))
*(*int32)(unsafe.Pointer(bp + 8 + uintptr(ii+int32(1))*4)) = Xsqlite3_value_int(tls, **(**uintptr)(__ccgo_up(aData + uintptr(ii+int32(4))*8)))
if *(*int32)(unsafe.Pointer(bp + 8 + uintptr(ii)*4)) > *(*int32)(unsafe.Pointer(bp + 8 + uintptr(ii+int32(1))*4)) {
rc = _rtreeConstraintError(tls, pRtree, ii+int32(1))
goto constraint
}
goto _2
_2:
;
ii = ii + int32(2)
}
}
/* If a rowid value was supplied, check if it is already present in
** the table. If so, the constraint has failed. */
if Xsqlite3_value_type(tls, **(**uintptr)(__ccgo_up(aData + 2*8))) != int32(SQLITE_NULL) {
(**(**TRtreeCell)(__ccgo_up(bp))).FiRowid = Xsqlite3_value_int64(tls, **(**uintptr)(__ccgo_up(aData + 2*8)))
if Xsqlite3_value_type(tls, **(**uintptr)(__ccgo_up(aData))) == int32(SQLITE_NULL) || Xsqlite3_value_int64(tls, **(**uintptr)(__ccgo_up(aData))) != (**(**TRtreeCell)(__ccgo_up(bp))).FiRowid {
Xsqlite3_bind_int64(tls, (*TRtree)(unsafe.Pointer(pRtree)).FpReadRowid, int32(1), (**(**TRtreeCell)(__ccgo_up(bp))).FiRowid)
steprc = Xsqlite3_step(tls, (*TRtree)(unsafe.Pointer(pRtree)).FpReadRowid)
rc = 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) {
rc = _rtreeDeleteRowid(tls, pRtree, (**(**TRtreeCell)(__ccgo_up(bp))).FiRowid)
} else {
rc = _rtreeConstraintError(tls, pRtree, 0)
goto constraint
}
}
}
bHaveRowid = int32(1)
}
}
/* 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 Xsqlite3_value_type(tls, **(**uintptr)(__ccgo_up(aData))) != int32(SQLITE_NULL) {
rc = _rtreeDeleteRowid(tls, pRtree, Xsqlite3_value_int64(tls, **(**uintptr)(__ccgo_up(aData))))
}
/* 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 rc == SQLITE_OK && nData > int32(1) {
/* Insert the new record into the r-tree */
**(**uintptr)(__ccgo_up(bp + 48)) = uintptr(0)
/* Figure out the rowid of the new row. */
if bHaveRowid == 0 {
rc = _rtreeNewRowid(tls, pRtree, bp)
}
**(**Tsqlite_int64)(__ccgo_up(pRowid)) = (**(**TRtreeCell)(__ccgo_up(bp))).FiRowid
if rc == SQLITE_OK {
rc = _ChooseLeaf(tls, pRtree, bp, 0, bp+48)
}
if rc == SQLITE_OK {
rc = _rtreeInsertCell(tls, pRtree, **(**uintptr)(__ccgo_up(bp + 48)), bp, 0)
rc2 = _nodeRelease(tls, pRtree, **(**uintptr)(__ccgo_up(bp + 48)))
if rc == SQLITE_OK {
rc = rc2
}
}
if rc == SQLITE_OK && (*TRtree)(unsafe.Pointer(pRtree)).FnAux != 0 {
pUp = (*TRtree)(unsafe.Pointer(pRtree)).FpWriteAux
Xsqlite3_bind_int64(tls, pUp, int32(1), **(**Tsqlite_int64)(__ccgo_up(pRowid)))
jj = 0
for {
if !(jj < libc.Int32FromUint16((*TRtree)(unsafe.Pointer(pRtree)).FnAux)) {
break
}
Xsqlite3_bind_value(tls, pUp, jj+int32(2), **(**uintptr)(__ccgo_up(aData + uintptr(libc.Int32FromUint8((*TRtree)(unsafe.Pointer(pRtree)).FnDim2)+int32(3)+jj)*8)))
goto _3
_3:
;
jj = jj + 1
}
Xsqlite3_step(tls, pUp)
rc = Xsqlite3_reset(tls, pUp)
}
}
goto constraint
constraint:
;
_rtreeRelease(tls, pRtree)
return rc
}
// C documentation
//
// /*
// ** Usage:
// **
// ** rtreecheck();
// ** rtreecheck(, );
// **
// ** Invoking this SQL function runs an integrity-check on the named rtree
// ** table. The integrity-check verifies the following:
// **
// ** 1. For each cell in the r-tree structure (%_node table), that:
// **
// ** a) for each dimension, (coord1 <= coord2).
// **
// ** b) unless the cell is on the root node, that the cell is bounded
// ** by the parent cell on the parent node.
// **
// ** c) for leaf nodes, that there is an entry in the %_rowid
// ** table corresponding to the cell's rowid value that
// ** points to the correct node.
// **
// ** d) for cells on non-leaf nodes, that there is an entry in the
// ** %_parent table mapping from the cell's child node to the
// ** node that it resides on.
// **
// ** 2. That there are the same number of entries in the %_rowid table
// ** as there are leaf cells in the r-tree structure, and that there
// ** is a leaf cell that corresponds to each entry in the %_rowid table.
// **
// ** 3. That there are the same number of entries in the %_parent table
// ** as there are non-leaf cells in the r-tree structure, and that
// ** there is a non-leaf cell that corresponds to each entry in the
// ** %_parent table.
// */
func _rtreecheck(tls *libc.TLS, ctx uintptr, nArg int32, apArg uintptr) {
bp := tls.Alloc(16)
defer tls.Free(16)
var rc int32
var zDb, zTab, v1 uintptr
var _ /* zReport at bp+0 */ uintptr
_, _, _, _ = rc, zDb, zTab, v1
if nArg != int32(1) && nArg != int32(2) {
Xsqlite3_result_error(tls, ctx, __ccgo_ts+30177, -int32(1))
} else {
**(**uintptr)(__ccgo_up(bp)) = uintptr(0)
zDb = Xsqlite3_value_text(tls, **(**uintptr)(__ccgo_up(apArg)))
if nArg == int32(1) {
zTab = zDb
zDb = __ccgo_ts + 7164
} else {
zTab = Xsqlite3_value_text(tls, **(**uintptr)(__ccgo_up(apArg + 1*8)))
}
rc = _rtreeCheckTable(tls, Xsqlite3_context_db_handle(tls, ctx), zDb, zTab, bp)
if rc == SQLITE_OK {
if **(**uintptr)(__ccgo_up(bp)) != 0 {
v1 = **(**uintptr)(__ccgo_up(bp))
} else {
v1 = __ccgo_ts + 20186
}
Xsqlite3_result_text(tls, ctx, v1, -int32(1), uintptr(-libc.Int32FromInt32(1)))
} else {
Xsqlite3_result_error_code(tls, ctx, rc)
}
Xsqlite3_free(tls, **(**uintptr)(__ccgo_up(bp)))
}
}
/* Conditionally include the geopoly code */
/************** Include geopoly.c in the middle of rtree.c *******************/
/************** Begin file geopoly.c *****************************************/
/*
** 2018-05-25
**
** The author disclaims copyright to this source code. In place of
** a legal notice, here is a blessing:
**
** May you do good and not evil.
** May you find forgiveness for yourself and forgive others.
** May you share freely, never taking more than you give.
**
******************************************************************************
**
** This file implements an alternative R-Tree virtual table that
** uses polygons to express the boundaries of 2-dimensional objects.
**
** This file is #include-ed onto the end of "rtree.c" so that it has
** access to all of the R-Tree internals.
*/
/* #include */
/* Enable -DGEOPOLY_ENABLE_DEBUG for debugging facilities */
/* Character class routines */
/* Use the SQLite core versions if this routine is part of the
** SQLite amalgamation */
// C documentation
//
// /* This routine implements an SQL function that returns the "depth" parameter
// ** from the front of a blob that is an r-tree node. For example:
// **
// ** SELECT rtreedepth(data) FROM rt_node WHERE nodeno=1;
// **
// ** The depth value is 0 for all nodes other than the root node, and the root
// ** node always has nodeno=1, so the example above is the primary use for this
// ** routine. This routine is intended for testing and analysis only.
// */
func _rtreedepth(tls *libc.TLS, ctx uintptr, nArg int32, apArg uintptr) {
var zBlob uintptr
_ = zBlob
_ = nArg
if Xsqlite3_value_type(tls, **(**uintptr)(__ccgo_up(apArg))) != int32(SQLITE_BLOB) || Xsqlite3_value_bytes(tls, **(**uintptr)(__ccgo_up(apArg))) < int32(2) {
Xsqlite3_result_error(tls, ctx, __ccgo_ts+29413, -int32(1))
} else {
zBlob = Xsqlite3_value_blob(tls, **(**uintptr)(__ccgo_up(apArg)))
if zBlob != 0 {
Xsqlite3_result_int(tls, ctx, _readInt16(tls, zBlob))
} else {
Xsqlite3_result_error_nomem(tls, ctx)
}
}
}
// C documentation
//
// /*
// ** Implementation of a scalar function that decodes r-tree nodes to
// ** human readable strings. This can be used for debugging and analysis.
// **
// ** The scalar function takes two arguments: (1) the number of dimensions
// ** to the rtree (between 1 and 5, inclusive) and (2) a blob of data containing
// ** an r-tree node. For a two-dimensional r-tree structure called "rt", to
// ** deserialize all nodes, a statement like:
// **
// ** SELECT rtreenode(2, data) FROM rt_node;
// **
// ** The human readable string takes the form of a Tcl list with one
// ** entry for each cell in the r-tree node. Each entry is itself a
// ** list, containing the 8-byte rowid/pageno followed by the
// ** *2 coordinates.
// */
func _rtreenode(tls *libc.TLS, ctx uintptr, nArg int32, apArg uintptr) {
bp := tls.Alloc(1088)
defer tls.Free(1088)
var errCode, ii, jj, nData int32
var pOut uintptr
var _ /* cell at bp+1016 */ TRtreeCell
var _ /* node at bp+0 */ TRtreeNode
var _ /* tree at bp+40 */ TRtree
_, _, _, _, _ = errCode, ii, jj, nData, pOut
_ = nArg
libc.X__builtin___memset_chk(tls, bp, 0, uint64(40), ^t__predefined_size_t(0))
libc.X__builtin___memset_chk(tls, bp+40, 0, uint64(976), ^t__predefined_size_t(0))
(**(**TRtree)(__ccgo_up(bp + 40))).FnDim = libc.Uint8FromInt32(Xsqlite3_value_int(tls, **(**uintptr)(__ccgo_up(apArg))))
if libc.Int32FromUint8((**(**TRtree)(__ccgo_up(bp + 40))).FnDim) < int32(1) || libc.Int32FromUint8((**(**TRtree)(__ccgo_up(bp + 40))).FnDim) > int32(5) {
return
}
(**(**TRtree)(__ccgo_up(bp + 40))).FnDim2 = libc.Uint8FromInt32(libc.Int32FromUint8((**(**TRtree)(__ccgo_up(bp + 40))).FnDim) * int32(2))
(**(**TRtree)(__ccgo_up(bp + 40))).FnBytesPerCell = libc.Uint8FromInt32(int32(8) + int32(8)*libc.Int32FromUint8((**(**TRtree)(__ccgo_up(bp + 40))).FnDim))
(**(**TRtreeNode)(__ccgo_up(bp))).FzData = Xsqlite3_value_blob(tls, **(**uintptr)(__ccgo_up(apArg + 1*8)))
if (**(**TRtreeNode)(__ccgo_up(bp))).FzData == uintptr(0) {
return
}
nData = Xsqlite3_value_bytes(tls, **(**uintptr)(__ccgo_up(apArg + 1*8)))
if nData < int32(4) {
return
}
if nData < int32(4)+_readInt16(tls, (*TRtreeNode)(unsafe.Pointer(bp)).FzData+2)*libc.Int32FromUint8((**(**TRtree)(__ccgo_up(bp + 40))).FnBytesPerCell) {
return
}
pOut = Xsqlite3_str_new(tls, uintptr(0))
ii = 0
for {
if !(ii < _readInt16(tls, (*TRtreeNode)(unsafe.Pointer(bp)).FzData+2)) {
break
}
_nodeGetCell(tls, bp+40, bp, ii, bp+1016)
if ii > 0 {
Xsqlite3_str_append(tls, pOut, __ccgo_ts+11889, int32(1))
}
Xsqlite3_str_appendf(tls, pOut, __ccgo_ts+29403, libc.VaList(bp+1072, (**(**TRtreeCell)(__ccgo_up(bp + 1016))).FiRowid))
jj = 0
for {
if !(jj < libc.Int32FromUint8((**(**TRtree)(__ccgo_up(bp + 40))).FnDim2)) {
break
}
Xsqlite3_str_appendf(tls, pOut, __ccgo_ts+29409, libc.VaList(bp+1072, float64(*(*TRtreeValue)(unsafe.Pointer(bp + 1016 + 8 + uintptr(jj)*4)))))
goto _2
_2:
;
jj = jj + 1
}
Xsqlite3_str_append(tls, pOut, __ccgo_ts+27248, 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
//
// /*
// ** Copy the contents of object (*pFrom) into (*pTo).
// */
func _sampleCopy(tls *libc.TLS, p uintptr, pTo uintptr, pFrom uintptr) {
(*TStatSample)(unsafe.Pointer(pTo)).FisPSample = (*TStatSample)(unsafe.Pointer(pFrom)).FisPSample
(*TStatSample)(unsafe.Pointer(pTo)).FiCol = (*TStatSample)(unsafe.Pointer(pFrom)).FiCol
(*TStatSample)(unsafe.Pointer(pTo)).FiHash = (*TStatSample)(unsafe.Pointer(pFrom)).FiHash
libc.X__builtin___memcpy_chk(tls, (*TStatSample)(unsafe.Pointer(pTo)).FanEq, (*TStatSample)(unsafe.Pointer(pFrom)).FanEq, uint64(8)*libc.Uint64FromInt32((*TStatAccum)(unsafe.Pointer(p)).FnCol), ^t__predefined_size_t(0))
libc.X__builtin___memcpy_chk(tls, (*TStatSample)(unsafe.Pointer(pTo)).FanLt, (*TStatSample)(unsafe.Pointer(pFrom)).FanLt, uint64(8)*libc.Uint64FromInt32((*TStatAccum)(unsafe.Pointer(p)).FnCol), ^t__predefined_size_t(0))
libc.X__builtin___memcpy_chk(tls, (*TStatSample)(unsafe.Pointer(pTo)).FanDLt, (*TStatSample)(unsafe.Pointer(pFrom)).FanDLt, uint64(8)*libc.Uint64FromInt32((*TStatAccum)(unsafe.Pointer(p)).FnCol), ^t__predefined_size_t(0))
if (*TStatSample)(unsafe.Pointer(pFrom)).FnRowid != 0 {
_sampleSetRowid(tls, (*TStatAccum)(unsafe.Pointer(p)).Fdb, pTo, libc.Int32FromUint32((*TStatSample)(unsafe.Pointer(pFrom)).FnRowid), *(*uintptr)(unsafe.Pointer(pFrom + 24)))
} else {
_sampleSetRowidInt64(tls, (*TStatAccum)(unsafe.Pointer(p)).Fdb, pTo, *(*Ti64)(unsafe.Pointer(pFrom + 24)))
}
}
// C documentation
//
// /*
// ** Copy the contents of sample *pNew into the p->a[] array. If necessary,
// ** remove the least desirable sample from p->a[] to make room.
// */
func _sampleInsert(tls *libc.TLS, p uintptr, pNew uintptr, nEqZero int32) {
var anDLt, anEq, anLt, pMin, pOld, pSample, pUpgrade uintptr
var i, iMin int32
_, _, _, _, _, _, _, _, _ = anDLt, anEq, anLt, i, iMin, pMin, pOld, pSample, pUpgrade
pSample = uintptr(0)
/* StatAccum.nMaxEqZero is set to the maximum number of leading 0
** values in the anEq[] array of any sample in StatAccum.a[]. In
** other words, if nMaxEqZero is n, then it is guaranteed that there
** are no samples with StatSample.anEq[m]==0 for (m>=n). */
if nEqZero > (*TStatAccum)(unsafe.Pointer(p)).FnMaxEqZero {
(*TStatAccum)(unsafe.Pointer(p)).FnMaxEqZero = nEqZero
}
if libc.Int32FromUint8((*TStatSample)(unsafe.Pointer(pNew)).FisPSample) == 0 {
pUpgrade = uintptr(0)
/* This sample is being added because the prefix that ends in column
** iCol occurs many times in the table. However, if we have already
** added a sample that shares this prefix, there is no need to add
** this one. Instead, upgrade the priority of the highest priority
** existing sample that shares this prefix. */
i = (*TStatAccum)(unsafe.Pointer(p)).FnSample - int32(1)
for {
if !(i >= 0) {
break
}
pOld = (*TStatAccum)(unsafe.Pointer(p)).Fa + uintptr(i)*48
if **(**TtRowcnt)(__ccgo_up((*TStatSample)(unsafe.Pointer(pOld)).FanEq + uintptr((*TStatSample)(unsafe.Pointer(pNew)).FiCol)*8)) == uint64(0) {
if (*TStatSample)(unsafe.Pointer(pOld)).FisPSample != 0 {
return
}
if pUpgrade == uintptr(0) || _sampleIsBetter(tls, p, pOld, pUpgrade) != 0 {
pUpgrade = pOld
}
}
goto _1
_1:
;
i = i - 1
}
if pUpgrade != 0 {
(*TStatSample)(unsafe.Pointer(pUpgrade)).FiCol = (*TStatSample)(unsafe.Pointer(pNew)).FiCol
**(**TtRowcnt)(__ccgo_up((*TStatSample)(unsafe.Pointer(pUpgrade)).FanEq + uintptr((*TStatSample)(unsafe.Pointer(pUpgrade)).FiCol)*8)) = **(**TtRowcnt)(__ccgo_up((*TStatSample)(unsafe.Pointer(pNew)).FanEq + uintptr((*TStatSample)(unsafe.Pointer(pUpgrade)).FiCol)*8))
goto find_new_min
}
}
/* If necessary, remove sample iMin to make room for the new sample. */
if (*TStatAccum)(unsafe.Pointer(p)).FnSample >= (*TStatAccum)(unsafe.Pointer(p)).FmxSample {
pMin = (*TStatAccum)(unsafe.Pointer(p)).Fa + uintptr((*TStatAccum)(unsafe.Pointer(p)).FiMin)*48
anEq = (*TStatSample)(unsafe.Pointer(pMin)).FanEq
anLt = (*TStatSample)(unsafe.Pointer(pMin)).FanLt
anDLt = (*TStatSample)(unsafe.Pointer(pMin)).FanDLt
_sampleClear(tls, (*TStatAccum)(unsafe.Pointer(p)).Fdb, pMin)
libc.X__builtin___memmove_chk(tls, pMin, pMin+1*48, uint64(48)*libc.Uint64FromInt32((*TStatAccum)(unsafe.Pointer(p)).FnSample-(*TStatAccum)(unsafe.Pointer(p)).FiMin-libc.Int32FromInt32(1)), ^t__predefined_size_t(0))
pSample = (*TStatAccum)(unsafe.Pointer(p)).Fa + uintptr((*TStatAccum)(unsafe.Pointer(p)).FnSample-int32(1))*48
(*TStatSample)(unsafe.Pointer(pSample)).FnRowid = uint32(0)
(*TStatSample)(unsafe.Pointer(pSample)).FanEq = anEq
(*TStatSample)(unsafe.Pointer(pSample)).FanDLt = anDLt
(*TStatSample)(unsafe.Pointer(pSample)).FanLt = anLt
(*TStatAccum)(unsafe.Pointer(p)).FnSample = (*TStatAccum)(unsafe.Pointer(p)).FmxSample - int32(1)
}
/* The "rows less-than" for the rowid column must be greater than that
** for the last sample in the p->a[] array. Otherwise, the samples would
** be out of order. */
/* Insert the new sample */
pSample = (*TStatAccum)(unsafe.Pointer(p)).Fa + uintptr((*TStatAccum)(unsafe.Pointer(p)).FnSample)*48
_sampleCopy(tls, p, pSample, pNew)
(*TStatAccum)(unsafe.Pointer(p)).FnSample = (*TStatAccum)(unsafe.Pointer(p)).FnSample + 1
/* Zero the first nEqZero entries in the anEq[] array. */
libc.X__builtin___memset_chk(tls, (*TStatSample)(unsafe.Pointer(pSample)).FanEq, 0, uint64(8)*libc.Uint64FromInt32(nEqZero), ^t__predefined_size_t(0))
goto find_new_min
find_new_min:
;
if (*TStatAccum)(unsafe.Pointer(p)).FnSample >= (*TStatAccum)(unsafe.Pointer(p)).FmxSample {
iMin = -int32(1)
i = 0
for {
if !(i < (*TStatAccum)(unsafe.Pointer(p)).FmxSample) {
break
}
if (**(**TStatSample)(__ccgo_up((*TStatAccum)(unsafe.Pointer(p)).Fa + uintptr(i)*48))).FisPSample != 0 {
goto _2
}
if iMin < 0 || _sampleIsBetter(tls, p, (*TStatAccum)(unsafe.Pointer(p)).Fa+uintptr(iMin)*48, (*TStatAccum)(unsafe.Pointer(p)).Fa+uintptr(i)*48) != 0 {
iMin = i
}
goto _2
_2:
;
i = i + 1
}
(*TStatAccum)(unsafe.Pointer(p)).FiMin = iMin
}
}
// C documentation
//
// /* Initialize the BLOB value of a ROWID
// */
func _sampleSetRowid(tls *libc.TLS, db uintptr, p uintptr, n int32, pData uintptr) {
if (*TStatSample)(unsafe.Pointer(p)).FnRowid != 0 {
_sqlite3DbFree(tls, db, *(*uintptr)(unsafe.Pointer(p + 24)))
}
*(*uintptr)(unsafe.Pointer(p + 24)) = _sqlite3DbMallocRawNN(tls, db, libc.Uint64FromInt32(n))
if *(*uintptr)(unsafe.Pointer(p + 24)) != 0 {
(*TStatSample)(unsafe.Pointer(p)).FnRowid = libc.Uint32FromInt32(n)
libc.X__builtin___memcpy_chk(tls, *(*uintptr)(unsafe.Pointer(p + 24)), pData, libc.Uint64FromInt32(n), ^t__predefined_size_t(0))
} else {
(*TStatSample)(unsafe.Pointer(p)).FnRowid = uint32(0)
}
}
// C documentation
//
// /*
// ** The cursor passed as the only argument must point to a valid entry
// ** when this function is called (i.e. have eState==CURSOR_VALID). This
// ** function saves the current cursor key in variables pCur->nKey and
// ** pCur->pKey. SQLITE_OK is returned if successful or an SQLite error
// ** code otherwise.
// **
// ** If the cursor is open on an intkey table, then the integer key
// ** (the rowid) is stored in pCur->nKey and pCur->pKey is left set to
// ** NULL. If the cursor is open on a non-intkey table, then pCur->pKey is
// ** set to point to a malloced buffer pCur->nKey bytes in size containing
// ** the key.
// */
func _saveCursorKey(tls *libc.TLS, pCur uintptr) (r int32) {
var pKey uintptr
var rc int32
_, _ = pKey, rc
rc = SQLITE_OK
if (*TBtCursor)(unsafe.Pointer(pCur)).FcurIntKey != 0 {
/* Only the rowid is required for a table btree */
(*TBtCursor)(unsafe.Pointer(pCur)).FnKey = _sqlite3BtreeIntegerKey(tls, pCur)
} else {
(*TBtCursor)(unsafe.Pointer(pCur)).FnKey = libc.Int64FromUint32(_sqlite3BtreePayloadSize(tls, pCur))
pKey = _sqlite3Malloc(tls, libc.Uint64FromInt64((*TBtCursor)(unsafe.Pointer(pCur)).FnKey+int64(9)+int64(8)))
if pKey != 0 {
rc = _sqlite3BtreePayload(tls, pCur, uint32(0), libc.Uint32FromInt32(int32((*TBtCursor)(unsafe.Pointer(pCur)).FnKey)), pKey)
if rc == SQLITE_OK {
libc.X__builtin___memset_chk(tls, pKey+uintptr((*TBtCursor)(unsafe.Pointer(pCur)).FnKey), 0, libc.Uint64FromInt32(libc.Int32FromInt32(9)+libc.Int32FromInt32(8)), ^t__predefined_size_t(0))
(*TBtCursor)(unsafe.Pointer(pCur)).FpKey = pKey
} else {
Xsqlite3_free(tls, pKey)
}
} else {
rc = int32(SQLITE_NOMEM)
}
}
return rc
}
// C documentation
//
// /*
// ** Seek to the offset passed as the second argument, then read cnt
// ** bytes into pBuf. Return the number of bytes actually read.
// **
// ** To avoid stomping the errno value on a failed read the lastErrno value
// ** is set before returning.
// */
func _seekAndRead(tls *libc.TLS, id uintptr, offset Tsqlite3_int64, pBuf uintptr, cnt int32) (r int32) {
var got, prior int32
_, _ = got, prior
prior = 0
for cond := true; cond; cond = got > 0 {
got = int32((*(*func(*libc.TLS, int32, uintptr, Tsize_t, Toff_t) Tssize_t)(unsafe.Pointer(&struct{ uintptr }{_aSyscall[int32(9)].FpCurrent})))(tls, (*TunixFile)(unsafe.Pointer(id)).Fh, pBuf, libc.Uint64FromInt32(cnt), offset))
if got == cnt {
break
}
if got < 0 {
if **(**int32)(__ccgo_up(libc.X__error(tls))) == int32(EINTR) {
got = int32(1)
continue
}
prior = 0
_storeLastErrno(tls, id, **(**int32)(__ccgo_up(libc.X__error(tls))))
break
} else {
if got > 0 {
cnt = cnt - got
offset = offset + int64(got)
prior = prior + got
pBuf = uintptr(got) + pBuf
}
}
}
return got + prior
}
// C documentation
//
// /*
// ** Attempt to seek the file-descriptor passed as the first argument to
// ** absolute offset iOff, then attempt to write nBuf bytes of data from
// ** pBuf to it. If an error occurs, return -1 and set *piErrno. Otherwise,
// ** return the actual number of bytes written (which may be less than
// ** nBuf).
// */
func _seekAndWriteFd(tls *libc.TLS, fd int32, iOff Ti64, pBuf uintptr, nBuf int32, piErrno uintptr) (r int32) {
var rc int32
_ = rc
rc = 0 /* Value returned by system call */
nBuf = nBuf & int32(0x1ffff)
for cond := true; cond; cond = rc < 0 && **(**int32)(__ccgo_up(libc.X__error(tls))) == int32(EINTR) {
rc = int32((*(*func(*libc.TLS, int32, uintptr, Tsize_t, Toff_t) Tssize_t)(unsafe.Pointer(&struct{ uintptr }{_aSyscall[int32(12)].FpCurrent})))(tls, fd, pBuf, libc.Uint64FromInt32(nBuf), iOff))
}
if rc < 0 {
**(**int32)(__ccgo_up(piErrno)) = **(**int32)(__ccgo_up(libc.X__error(tls)))
}
return rc
}
// C documentation
//
// /*
// ** The xExpr callback for the search of invalid ON clause terms.
// */
func _selectCheckOnClausesExpr(tls *libc.TLS, pWalker uintptr, pExpr uintptr) (r int32) {
bp := tls.Alloc(16)
defer tls.Free(16)
var iTab, ii, nSrc int32
var pCtx, pSrc, v2 uintptr
_, _, _, _, _, _ = iTab, ii, nSrc, pCtx, pSrc, v2
pCtx = *(*uintptr)(unsafe.Pointer(pWalker + 40))
/* Check if pExpr is root or near-root of an ON clause constraint that needs
** to be checked to ensure that it does not refer to tables in its FROM
** clause to the right of itself. i.e. it is either:
**
** + an ON clause on an OUTER join, or
** + an ON clause on an INNER join within a FROM that features at
** least one RIGHT or FULL join.
*/
if (*TExpr)(unsafe.Pointer(pExpr)).Fflags&libc.Uint32FromInt32(libc.Int32FromInt32(EP_OuterON)) != uint32(0) || (*TExpr)(unsafe.Pointer(pExpr)).Fflags&libc.Uint32FromInt32(libc.Int32FromInt32(EP_InnerON)) != uint32(0) && libc.Int32FromUint8((*(*TSrcItem)(unsafe.Pointer((*TCheckOnCtx)(unsafe.Pointer(pCtx)).FpSrc + 8))).Ffg.Fjointype)&int32(JT_LTORJ) != 0 {
/* If CheckOnCtx.iJoin is already set, then fall through and process
** this expression node as normal. Or, if CheckOnCtx.iJoin is still 0,
** set it to the cursor number of the RHS of the join to which this
** ON expression was attached and then iterate through the entire
** expression. */
if (*TCheckOnCtx)(unsafe.Pointer(pCtx)).FiJoin == 0 {
(*TCheckOnCtx)(unsafe.Pointer(pCtx)).FiJoin = *(*int32)(unsafe.Pointer(pExpr + 52))
_sqlite3WalkExprNN(tls, pWalker, pExpr)
(*TCheckOnCtx)(unsafe.Pointer(pCtx)).FiJoin = 0
return int32(WRC_Prune)
}
}
if libc.Int32FromUint8((*TExpr)(unsafe.Pointer(pExpr)).Fop) == int32(TK_COLUMN) {
/* A column expression. Find the SrcList (if any) to which it refers.
** Then, if CheckOnCtx.iJoin indicates that this expression is part of an
** ON clause from that SrcList (i.e. if iJoin is non-zero), check that it
** does not refer to a table to the right of CheckOnCtx.iJoin. */
for cond := true; cond; cond = pCtx != 0 {
pSrc = (*TCheckOnCtx)(unsafe.Pointer(pCtx)).FpSrc
nSrc = (*TSrcList)(unsafe.Pointer(pSrc)).FnSrc
iTab = (*TExpr)(unsafe.Pointer(pExpr)).FiTable
ii = 0
for {
if !(ii < nSrc && (*(*TSrcItem)(unsafe.Pointer(pSrc + 8 + uintptr(ii)*80))).FiCursor != iTab) {
break
}
goto _1
_1:
;
ii = ii + 1
}
if ii < nSrc {
if (*TCheckOnCtx)(unsafe.Pointer(pCtx)).FiJoin != 0 && iTab > (*TCheckOnCtx)(unsafe.Pointer(pCtx)).FiJoin {
if (*TCheckOnCtx)(unsafe.Pointer(pCtx)).FbFuncArg != 0 {
v2 = __ccgo_ts + 21955
} else {
v2 = __ccgo_ts + 21979
}
_sqlite3ErrorMsg(tls, (*TWalker)(unsafe.Pointer(pWalker)).FpParse, __ccgo_ts+21989, libc.VaList(bp+8, v2))
return int32(WRC_Abort)
}
break
}
pCtx = (*TCheckOnCtx)(unsafe.Pointer(pCtx)).FpParent
}
}
return WRC_Continue
}
// C documentation
//
// /*
// ** The xSelect callback for the search of invalid ON clause terms.
// */
func _selectCheckOnClausesSelect(tls *libc.TLS, pWalker uintptr, pSelect uintptr) (r int32) {
bp := tls.Alloc(32)
defer tls.Free(32)
var pCtx uintptr
var _ /* sCtx at bp+0 */ TCheckOnCtx
_ = pCtx
pCtx = *(*uintptr)(unsafe.Pointer(pWalker + 40))
if (*TSelect)(unsafe.Pointer(pSelect)).FpSrc == (*TCheckOnCtx)(unsafe.Pointer(pCtx)).FpSrc || (*TSrcList)(unsafe.Pointer((*TSelect)(unsafe.Pointer(pSelect)).FpSrc)).FnSrc == 0 {
return WRC_Continue
} else {
libc.X__builtin___memset_chk(tls, bp, 0, uint64(24), ^t__predefined_size_t(0))
(**(**TCheckOnCtx)(__ccgo_up(bp))).FpSrc = (*TSelect)(unsafe.Pointer(pSelect)).FpSrc
(**(**TCheckOnCtx)(__ccgo_up(bp))).FpParent = pCtx
*(*uintptr)(unsafe.Pointer(pWalker + 40)) = bp
_sqlite3WalkSelect(tls, pWalker, pSelect)
*(*uintptr)(unsafe.Pointer(pWalker + 40)) = pCtx
**(**Tu32)(__ccgo_up(pSelect + 4)) &= libc.Uint32FromInt32(^libc.Int32FromInt32(SF_OnToWhere))
return int32(WRC_Prune)
}
return r
}
// C documentation
//
// /*
// ** This routine is a Walker callback for "expanding" a SELECT statement.
// ** "Expanding" means to do the following:
// **
// ** (1) Make sure VDBE cursor numbers have been assigned to every
// ** element of the FROM clause.
// **
// ** (2) Fill in the pTabList->a[].pTab fields in the SrcList that
// ** defines FROM clause. When views appear in the FROM clause,
// ** fill pTabList->a[].pSelect with a copy of the SELECT statement
// ** that implements the view. A copy is made of the view's SELECT
// ** statement so that we can freely modify or delete that statement
// ** without worrying about messing up the persistent representation
// ** of the view.
// **
// ** (3) Add terms to the WHERE clause to accommodate the NATURAL keyword
// ** on joins and the ON and USING clause of joins.
// **
// ** (4) Scan the list of columns in the result set (pEList) looking
// ** for instances of the "*" operator or the TABLE.* operator.
// ** If found, expand each "*" to be every column in every table
// ** and TABLE.* to be every column in TABLE.
// **
// */
func _selectExpander(tls *libc.TLS, pWalker uintptr, p uintptr) (r int32) {
bp := tls.Alloc(32)
defer tls.Free(32)
var a, db, pE, pEList, pExpr, pFrom, pLeft, pNestedFrom, pNew, pParse, pRight, pSel, pTab, pTab1, pTabList, pUsing, pX, pX1, zName, zSchemaName, zTName, zTabName, zUName, v2 uintptr
var eCodeOrig Tu8
var elistFlags Tu32
var flags, i, iDb, iErrOfst, ii, j, k, longNames, nAdd, rc, tableSeen, v1 int32
var nCol Ti16
var selFlags Tu16
_, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _ = a, db, eCodeOrig, elistFlags, flags, i, iDb, iErrOfst, ii, j, k, longNames, nAdd, nCol, pE, pEList, pExpr, pFrom, pLeft, pNestedFrom, pNew, pParse, pRight, pSel, pTab, pTab1, pTabList, pUsing, pX, pX1, rc, selFlags, tableSeen, zName, zSchemaName, zTName, zTabName, zUName, v1, v2
pParse = (*TWalker)(unsafe.Pointer(pWalker)).FpParse
db = (*TParse)(unsafe.Pointer(pParse)).Fdb
selFlags = uint16((*TSelect)(unsafe.Pointer(p)).FselFlags)
elistFlags = uint32(0)
**(**Tu32)(__ccgo_up(p + 4)) |= uint32(SF_Expanded)
if (*Tsqlite3)(unsafe.Pointer(db)).FmallocFailed != 0 {
return int32(WRC_Abort)
}
if libc.Int32FromUint16(selFlags)&int32(SF_Expanded) != 0 {
return int32(WRC_Prune)
}
if (*TWalker)(unsafe.Pointer(pWalker)).FeCode != 0 {
/* Renumber selId because it has been copied from a view */
v2 = pParse + 132
*(*int32)(unsafe.Pointer(v2)) = *(*int32)(unsafe.Pointer(v2)) + 1
v1 = *(*int32)(unsafe.Pointer(v2))
(*TSelect)(unsafe.Pointer(p)).FselId = libc.Uint32FromInt32(v1)
}
pTabList = (*TSelect)(unsafe.Pointer(p)).FpSrc
pEList = (*TSelect)(unsafe.Pointer(p)).FpEList
if (*TParse)(unsafe.Pointer(pParse)).FpWith != 0 && (*TSelect)(unsafe.Pointer(p)).FselFlags&uint32(SF_View) != 0 {
if (*TSelect)(unsafe.Pointer(p)).FpWith == uintptr(0) {
(*TSelect)(unsafe.Pointer(p)).FpWith = _sqlite3DbMallocZero(tls, db, uint64(uint64(libc.UintptrFromInt32(0)+16)+libc.Uint64FromInt32(libc.Int32FromInt32(1))*libc.Uint64FromInt64(48)))
if (*TSelect)(unsafe.Pointer(p)).FpWith == uintptr(0) {
return int32(WRC_Abort)
}
}
(*TWith)(unsafe.Pointer((*TSelect)(unsafe.Pointer(p)).FpWith)).FbView = int32(1)
}
_sqlite3WithPush(tls, pParse, (*TSelect)(unsafe.Pointer(p)).FpWith, uint8(0))
/* Make sure cursor numbers have been assigned to all entries in
** the FROM clause of the SELECT statement.
*/
_sqlite3SrcListAssignCursors(tls, pParse, pTabList)
/* Look up every table named in the FROM clause of the select. If
** an entry of the FROM clause is a subquery instead of a table or view,
** then create a transient table structure to describe the subquery.
*/
i = 0
pFrom = pTabList + 8
for {
if !(i < (*TSrcList)(unsafe.Pointer(pTabList)).FnSrc) {
break
}
if (*TSrcItem)(unsafe.Pointer(pFrom)).FpSTab != 0 {
goto _3
}
if (*TSrcItem)(unsafe.Pointer(pFrom)).FzName == uintptr(0) {
pSel = (*TSubquery)(unsafe.Pointer(*(*uintptr)(unsafe.Pointer(pFrom + 72)))).FpSelect
/* A sub-query in the FROM clause of a SELECT */
if _sqlite3WalkSelect(tls, pWalker, pSel) != 0 {
return int32(WRC_Abort)
}
if _sqlite3ExpandSubquery(tls, pParse, pFrom) != 0 {
return int32(WRC_Abort)
}
} else {
v1 = _resolveFromTermToCte(tls, pParse, pWalker, pFrom)
rc = v1
if v1 != 0 {
if rc > int32(1) {
return int32(WRC_Abort)
}
pTab = (*TSrcItem)(unsafe.Pointer(pFrom)).FpSTab
} else {
/* An ordinary table or view name in the FROM clause */
v2 = _sqlite3LocateTableItem(tls, pParse, uint32(0), pFrom)
pTab = v2
(*TSrcItem)(unsafe.Pointer(pFrom)).FpSTab = v2
if pTab == uintptr(0) {
return int32(WRC_Abort)
}
if (*TTable)(unsafe.Pointer(pTab)).FnTabRef >= uint32(0xffff) {
_sqlite3ErrorMsg(tls, pParse, __ccgo_ts+21650, libc.VaList(bp+8, (*TTable)(unsafe.Pointer(pTab)).FzName))
(*TSrcItem)(unsafe.Pointer(pFrom)).FpSTab = uintptr(0)
return int32(WRC_Abort)
}
(*TTable)(unsafe.Pointer(pTab)).FnTabRef = (*TTable)(unsafe.Pointer(pTab)).FnTabRef + 1
if !(libc.Int32FromUint8((*TTable)(unsafe.Pointer(pTab)).FeTabType) == libc.Int32FromInt32(TABTYP_VTAB)) && _cannotBeFunction(tls, pParse, pFrom) != 0 {
return int32(WRC_Abort)
}
if !(libc.Int32FromUint8((*TTable)(unsafe.Pointer(pTab)).FeTabType) == libc.Int32FromInt32(TABTYP_NORM)) {
eCodeOrig = uint8((*TWalker)(unsafe.Pointer(pWalker)).FeCode)
if _sqlite3ViewGetColumnNames(tls, pParse, pTab) != 0 {
return int32(WRC_Abort)
}
if libc.Int32FromUint8((*TTable)(unsafe.Pointer(pTab)).FeTabType) == int32(TABTYP_VIEW) {
if (*Tsqlite3)(unsafe.Pointer(db)).Fflags&uint64(SQLITE_EnableView) == uint64(0) && (*TTable)(unsafe.Pointer(pTab)).FpSchema != (**(**TDb)(__ccgo_up((*Tsqlite3)(unsafe.Pointer(db)).FaDb + 1*32))).FpSchema {
_sqlite3ErrorMsg(tls, pParse, __ccgo_ts+21689, libc.VaList(bp+8, (*TTable)(unsafe.Pointer(pTab)).FzName))
}
_sqlite3SrcItemAttachSubquery(tls, pParse, pFrom, (*(*struct {
FpSelect uintptr
})(unsafe.Pointer(&(*TTable)(unsafe.Pointer(pTab)).Fu))).FpSelect, int32(1))
} else {
if libc.Int32FromUint8((*TTable)(unsafe.Pointer(pTab)).FeTabType) == int32(TABTYP_VTAB) && (int32(*(*uint32)(unsafe.Pointer(pFrom + 24 + 4))&0x100>>8) != 0 || libc.Int32FromUint8((*TParse)(unsafe.Pointer(pParse)).FprepFlags)&int32(SQLITE_PREPARE_FROM_DDL) != 0) && (*(*struct {
FnArg int32
FazArg uintptr
Fp uintptr
})(unsafe.Pointer(pTab + 64))).Fp != uintptr(0) && libc.Int32FromUint8((*TVTable)(unsafe.Pointer((*(*struct {
FnArg int32
FazArg uintptr
Fp uintptr
})(unsafe.Pointer(pTab + 64))).Fp)).FeVtabRisk) > libc.BoolInt32((*Tsqlite3)(unsafe.Pointer(db)).Fflags&uint64(SQLITE_TrustedSchema) != uint64(0)) {
_sqlite3ErrorMsg(tls, pParse, __ccgo_ts+16693, libc.VaList(bp+8, (*TTable)(unsafe.Pointer(pTab)).FzName))
}
}
nCol = (*TTable)(unsafe.Pointer(pTab)).FnCol
(*TTable)(unsafe.Pointer(pTab)).FnCol = int16(-int32(1))
(*TWalker)(unsafe.Pointer(pWalker)).FeCode = uint16(1) /* Turn on Select.selId renumbering */
if int32(*(*uint32)(unsafe.Pointer(pFrom + 24 + 4))&0x4>>2) != 0 {
_sqlite3WalkSelect(tls, pWalker, (*TSubquery)(unsafe.Pointer(*(*uintptr)(unsafe.Pointer(pFrom + 72)))).FpSelect)
}
(*TWalker)(unsafe.Pointer(pWalker)).FeCode = uint16(eCodeOrig)
(*TTable)(unsafe.Pointer(pTab)).FnCol = nCol
}
}
}
/* Locate the index named by the INDEXED BY clause, if any. */
if int32(*(*uint32)(unsafe.Pointer(pFrom + 24 + 4))&0x2>>1) != 0 && _sqlite3IndexedByLookup(tls, pParse, pFrom) != 0 {
return int32(WRC_Abort)
}
goto _3
_3:
;
i = i + 1
pFrom += 80
}
/* Process NATURAL keywords, and ON and USING clauses of joins.
*/
if (*TParse)(unsafe.Pointer(pParse)).FnErr != 0 || _sqlite3ProcessJoin(tls, pParse, p) != 0 {
return int32(WRC_Abort)
}
/* For every "*" that occurs in the column list, insert the names of
** all columns in all tables. And for every TABLE.* insert the names
** of all columns in TABLE. The parser inserted a special expression
** with the TK_ASTERISK operator for each "*" that it found in the column
** list. The following code just has to locate the TK_ASTERISK
** expressions and expand each one to the list of all columns in
** all tables.
**
** The first loop just checks to see if there are any "*" operators
** that need expanding.
*/
k = 0
for {
if !(k < (*TExprList)(unsafe.Pointer(pEList)).FnExpr) {
break
}
pE = (*(*TExprList_item)(unsafe.Pointer(pEList + 8 + uintptr(k)*32))).FpExpr
if libc.Int32FromUint8((*TExpr)(unsafe.Pointer(pE)).Fop) == int32(TK_ASTERISK) {
break
}
if libc.Int32FromUint8((*TExpr)(unsafe.Pointer(pE)).Fop) == int32(TK_DOT) && libc.Int32FromUint8((*TExpr)(unsafe.Pointer((*TExpr)(unsafe.Pointer(pE)).FpRight)).Fop) == int32(TK_ASTERISK) {
break
}
elistFlags = elistFlags | (*TExpr)(unsafe.Pointer(pE)).Fflags
goto _6
_6:
;
k = k + 1
}
if k < (*TExprList)(unsafe.Pointer(pEList)).FnExpr {
/*
** If we get here it means the result set contains one or more "*"
** operators that need to be expanded. Loop through each expression
** in the result set and expand them one by one.
*/
a = pEList + 8
pNew = uintptr(0)
flags = libc.Int32FromUint64((*Tsqlite3)(unsafe.Pointer((*TParse)(unsafe.Pointer(pParse)).Fdb)).Fflags)
longNames = libc.BoolInt32(flags&int32(SQLITE_FullColNames) != 0 && flags&int32(SQLITE_ShortColNames) == 0)
k = 0
for {
if !(k < (*TExprList)(unsafe.Pointer(pEList)).FnExpr) {
break
}
pE = (**(**TExprList_item)(__ccgo_up(a + uintptr(k)*32))).FpExpr
elistFlags = elistFlags | (*TExpr)(unsafe.Pointer(pE)).Fflags
pRight = (*TExpr)(unsafe.Pointer(pE)).FpRight
if libc.Int32FromUint8((*TExpr)(unsafe.Pointer(pE)).Fop) != int32(TK_ASTERISK) && (libc.Int32FromUint8((*TExpr)(unsafe.Pointer(pE)).Fop) != int32(TK_DOT) || libc.Int32FromUint8((*TExpr)(unsafe.Pointer(pRight)).Fop) != int32(TK_ASTERISK)) {
/* This particular expression does not need to be expanded.
*/
pNew = _sqlite3ExprListAppend(tls, pParse, pNew, (**(**TExprList_item)(__ccgo_up(a + uintptr(k)*32))).FpExpr)
if pNew != 0 {
(*(*TExprList_item)(unsafe.Pointer(pNew + 8 + uintptr((*TExprList)(unsafe.Pointer(pNew)).FnExpr-int32(1))*32))).FzEName = (**(**TExprList_item)(__ccgo_up(a + uintptr(k)*32))).FzEName
libc.SetBitFieldPtr16Uint32(pNew+8+uintptr((*TExprList)(unsafe.Pointer(pNew)).FnExpr-int32(1))*32+16+4, libc.Uint32FromInt32(int32(uint32(*(*uint16)(unsafe.Pointer(a + uintptr(k)*32 + 16 + 4))&0x3>>0))), 0, 0x3)
(**(**TExprList_item)(__ccgo_up(a + uintptr(k)*32))).FzEName = uintptr(0)
}
(**(**TExprList_item)(__ccgo_up(a + uintptr(k)*32))).FpExpr = uintptr(0)
} else {
/* This expression is a "*" or a "TABLE.*" and needs to be
** expanded. */
tableSeen = 0 /* Set to 1 when TABLE matches */
zTName = uintptr(0)
if libc.Int32FromUint8((*TExpr)(unsafe.Pointer(pE)).Fop) == int32(TK_DOT) {
zTName = *(*uintptr)(unsafe.Pointer((*TExpr)(unsafe.Pointer(pE)).FpLeft + 8))
iErrOfst = *(*int32)(unsafe.Pointer((*TExpr)(unsafe.Pointer(pE)).FpRight + 52))
} else {
iErrOfst = *(*int32)(unsafe.Pointer(pE + 52))
}
i = 0
pFrom = pTabList + 8
for {
if !(i < (*TSrcList)(unsafe.Pointer(pTabList)).FnSrc) {
break
} /* Number of cols including rowid */
pTab1 = (*TSrcItem)(unsafe.Pointer(pFrom)).FpSTab /* AS name for this data source */
zSchemaName = uintptr(0) /* USING clause for pFrom[1] */
v2 = (*TSrcItem)(unsafe.Pointer(pFrom)).FzAlias
zTabName = v2
if v2 == uintptr(0) {
zTabName = (*TTable)(unsafe.Pointer(pTab1)).FzName
}
if (*Tsqlite3)(unsafe.Pointer(db)).FmallocFailed != 0 {
break
}
if int32(*(*uint32)(unsafe.Pointer(pFrom + 24 + 4))&0x4000>>14) != 0 {
pNestedFrom = (*TSelect)(unsafe.Pointer((*TSubquery)(unsafe.Pointer(*(*uintptr)(unsafe.Pointer(pFrom + 72)))).FpSelect)).FpEList
} else {
if zTName != 0 && _sqlite3StrICmp(tls, zTName, zTabName) != 0 {
goto _8
}
pNestedFrom = uintptr(0)
iDb = _sqlite3SchemaToIndex(tls, db, (*TTable)(unsafe.Pointer(pTab1)).FpSchema)
if iDb >= 0 {
v2 = (**(**TDb)(__ccgo_up((*Tsqlite3)(unsafe.Pointer(db)).FaDb + uintptr(iDb)*32))).FzDbSName
} else {
v2 = __ccgo_ts + 7169
}
zSchemaName = v2
}
if i+int32(1) < (*TSrcList)(unsafe.Pointer(pTabList)).FnSrc && int32(*(*uint32)(unsafe.Pointer(pFrom + 1*80 + 24 + 4))&0x800>>11) != 0 && libc.Int32FromUint16(selFlags)&int32(SF_NestedFrom) != 0 {
pUsing = *(*uintptr)(unsafe.Pointer(pFrom + 1*80 + 64))
ii = 0
for {
if !(ii < (*TIdList)(unsafe.Pointer(pUsing)).FnId) {
break
}
zUName = (*(*TIdList_item)(unsafe.Pointer(pUsing + 8 + uintptr(ii)*8))).FzName
pRight = _sqlite3Expr(tls, db, int32(TK_ID), zUName)
_sqlite3ExprSetErrorOffset(tls, pRight, iErrOfst)
pNew = _sqlite3ExprListAppend(tls, pParse, pNew, pRight)
if pNew != 0 {
pX = pNew + 8 + uintptr((*TExprList)(unsafe.Pointer(pNew)).FnExpr-int32(1))*32
(*TExprList_item)(unsafe.Pointer(pX)).FzEName = _sqlite3MPrintf(tls, db, __ccgo_ts+21720, libc.VaList(bp+8, zUName))
libc.SetBitFieldPtr16Uint32(pX+16+4, libc.Uint32FromInt32(ENAME_TAB), 0, 0x3)
libc.SetBitFieldPtr16Uint32(pX+16+4, libc.Uint32FromInt32(1), 7, 0x80)
}
goto _11
_11:
;
ii = ii + 1
}
} else {
pUsing = uintptr(0)
}
nAdd = int32((*TTable)(unsafe.Pointer(pTab1)).FnCol)
if (*TTable)(unsafe.Pointer(pTab1)).FtabFlags&uint32(TF_NoVisibleRowid) == uint32(0) && libc.Int32FromUint16(selFlags)&int32(SF_NestedFrom) != 0 {
nAdd = nAdd + 1
}
j = 0
for {
if !(j < nAdd) {
break
} /* Newly added ExprList term */
if j == int32((*TTable)(unsafe.Pointer(pTab1)).FnCol) {
zName = _sqlite3RowidAlias(tls, pTab1)
if zName == uintptr(0) {
goto _12
}
} else {
zName = (**(**TColumn)(__ccgo_up((*TTable)(unsafe.Pointer(pTab1)).FaCol + uintptr(j)*16))).FzCnName
/* If pTab is actually an SF_NestedFrom sub-select, do not
** expand any ENAME_ROWID columns. */
if pNestedFrom != 0 && int32(uint32(*(*uint16)(unsafe.Pointer(pNestedFrom + 8 + uintptr(j)*32 + 16 + 4))&0x3>>0)) == int32(ENAME_ROWID) {
goto _12
}
if zTName != 0 && pNestedFrom != 0 && _sqlite3MatchEName(tls, pNestedFrom+8+uintptr(j)*32, uintptr(0), zTName, uintptr(0), uintptr(0)) == 0 {
goto _12
}
/* If a column is marked as 'hidden', omit it from the expanded
** result-set list unless the SELECT has the SF_IncludeHidden
** bit set.
*/
if (*TSelect)(unsafe.Pointer(p)).FselFlags&uint32(SF_IncludeHidden) == uint32(0) && libc.Int32FromUint16((*TColumn)(unsafe.Pointer((*TTable)(unsafe.Pointer(pTab1)).FaCol+uintptr(j)*16)).FcolFlags)&int32(COLFLAG_HIDDEN) != 0 {
goto _12
}
if libc.Int32FromUint16((**(**TColumn)(__ccgo_up((*TTable)(unsafe.Pointer(pTab1)).FaCol + uintptr(j)*16))).FcolFlags)&int32(COLFLAG_NOEXPAND) != 0 && zTName == uintptr(0) && libc.Int32FromUint16(selFlags)&int32(SF_NestedFrom) == 0 {
goto _12
}
}
tableSeen = int32(1)
if i > 0 && zTName == uintptr(0) && libc.Int32FromUint16(selFlags)&int32(SF_NestedFrom) == 0 {
if int32(*(*uint32)(unsafe.Pointer(pFrom + 24 + 4))&0x800>>11) != 0 && _sqlite3IdListIndex(tls, *(*uintptr)(unsafe.Pointer(pFrom + 64)), zName) >= 0 {
/* In a join with a USING clause, omit columns in the
** using clause from the table on the right. */
goto _12
}
}
pRight = _sqlite3Expr(tls, db, int32(TK_ID), zName)
if (*TSrcList)(unsafe.Pointer(pTabList)).FnSrc > int32(1) && (libc.Int32FromUint8((*TSrcItem)(unsafe.Pointer(pFrom)).Ffg.Fjointype)&int32(JT_LTORJ) == 0 || libc.Int32FromUint16(selFlags)&int32(SF_NestedFrom) != 0 || !(_inAnyUsingClause(tls, zName, pFrom, (*TSrcList)(unsafe.Pointer(pTabList)).FnSrc-i-int32(1)) != 0)) || libc.Int32FromUint8((*TParse)(unsafe.Pointer(pParse)).FeParseMode) >= int32(PARSE_MODE_RENAME) {
pLeft = _sqlite3Expr(tls, db, int32(TK_ID), zTabName)
pExpr = _sqlite3PExpr(tls, pParse, int32(TK_DOT), pLeft, pRight)
if libc.Int32FromUint8((*TParse)(unsafe.Pointer(pParse)).FeParseMode) >= int32(PARSE_MODE_RENAME) && (*TExpr)(unsafe.Pointer(pE)).FpLeft != 0 {
_sqlite3RenameTokenRemap(tls, pParse, pLeft, (*TExpr)(unsafe.Pointer(pE)).FpLeft)
}
if zSchemaName != 0 {
pLeft = _sqlite3Expr(tls, db, int32(TK_ID), zSchemaName)
pExpr = _sqlite3PExpr(tls, pParse, int32(TK_DOT), pLeft, pExpr)
}
} else {
pExpr = pRight
}
_sqlite3ExprSetErrorOffset(tls, pExpr, iErrOfst)
pNew = _sqlite3ExprListAppend(tls, pParse, pNew, pExpr)
if pNew == uintptr(0) {
break /* OOM */
}
pX1 = pNew + 8 + uintptr((*TExprList)(unsafe.Pointer(pNew)).FnExpr-int32(1))*32
if libc.Int32FromUint16(selFlags)&int32(SF_NestedFrom) != 0 && !(libc.Int32FromUint8((*TParse)(unsafe.Pointer(pParse)).FeParseMode) >= libc.Int32FromInt32(PARSE_MODE_RENAME)) {
if pNestedFrom != 0 && libc.Bool(libc.Bool(!(libc.Int32FromInt32(ViewCanHaveRowid) != 0)) || j < (*TExprList)(unsafe.Pointer(pNestedFrom)).FnExpr) {
(*TExprList_item)(unsafe.Pointer(pX1)).FzEName = _sqlite3DbStrDup(tls, db, (*(*TExprList_item)(unsafe.Pointer(pNestedFrom + 8 + uintptr(j)*32))).FzEName)
} else {
(*TExprList_item)(unsafe.Pointer(pX1)).FzEName = _sqlite3MPrintf(tls, db, __ccgo_ts+21725, libc.VaList(bp+8, zSchemaName, zTabName, zName))
}
if j == int32((*TTable)(unsafe.Pointer(pTab1)).FnCol) {
v1 = int32(ENAME_ROWID)
} else {
v1 = int32(ENAME_TAB)
}
libc.SetBitFieldPtr16Uint32(pX1+16+4, libc.Uint32FromInt32(v1), 0, 0x3)
if int32(*(*uint32)(unsafe.Pointer(pFrom + 24 + 4))&0x800>>11) != 0 && _sqlite3IdListIndex(tls, *(*uintptr)(unsafe.Pointer(pFrom + 64)), zName) >= 0 || pUsing != 0 && _sqlite3IdListIndex(tls, pUsing, zName) >= 0 || j < int32((*TTable)(unsafe.Pointer(pTab1)).FnCol) && libc.Int32FromUint16((**(**TColumn)(__ccgo_up((*TTable)(unsafe.Pointer(pTab1)).FaCol + uintptr(j)*16))).FcolFlags)&int32(COLFLAG_NOEXPAND) != 0 {
libc.SetBitFieldPtr16Uint32(pX1+16+4, libc.Uint32FromInt32(1), 8, 0x100)
}
} else {
if longNames != 0 {
(*TExprList_item)(unsafe.Pointer(pX1)).FzEName = _sqlite3MPrintf(tls, db, __ccgo_ts+13980, libc.VaList(bp+8, zTabName, zName))
libc.SetBitFieldPtr16Uint32(pX1+16+4, libc.Uint32FromInt32(ENAME_NAME), 0, 0x3)
} else {
(*TExprList_item)(unsafe.Pointer(pX1)).FzEName = _sqlite3DbStrDup(tls, db, zName)
libc.SetBitFieldPtr16Uint32(pX1+16+4, libc.Uint32FromInt32(ENAME_NAME), 0, 0x3)
}
}
goto _12
_12:
;
j = j + 1
}
goto _8
_8:
;
i = i + 1
pFrom += 80
}
if !(tableSeen != 0) {
if zTName != 0 {
_sqlite3ErrorMsg(tls, pParse, __ccgo_ts+21734, libc.VaList(bp+8, zTName))
} else {
_sqlite3ErrorMsg(tls, pParse, __ccgo_ts+21752, 0)
}
}
}
goto _7
_7:
;
k = k + 1
}
_sqlite3ExprListDelete(tls, db, pEList)
(*TSelect)(unsafe.Pointer(p)).FpEList = pNew
}
if (*TSelect)(unsafe.Pointer(p)).FpEList != 0 {
if (*TExprList)(unsafe.Pointer((*TSelect)(unsafe.Pointer(p)).FpEList)).FnExpr > **(**int32)(__ccgo_up(db + 136 + 2*4)) {
_sqlite3ErrorMsg(tls, pParse, __ccgo_ts+21772, 0)
return int32(WRC_Abort)
}
if elistFlags&libc.Uint32FromInt32(libc.Int32FromInt32(EP_HasFunc)|libc.Int32FromInt32(EP_Subquery)) != uint32(0) {
**(**Tu32)(__ccgo_up(p + 4)) |= uint32(SF_ComplexResult)
}
}
return WRC_Continue
}
// C documentation
//
// /*
// ** This routine generates the code for the inside of the inner loop
// ** of a SELECT.
// **
// ** If srcTab is negative, then the p->pEList expressions
// ** are evaluated in order to get the data for this row. If srcTab is
// ** zero or more, then data is pulled from srcTab and p->pEList is used only
// ** to get the number of columns and the collation sequence for each column.
// */
func _selectInnerLoop(tls *libc.TLS, pParse uintptr, p uintptr, srcTab int32, pSort uintptr, pDistinct uintptr, pDest uintptr, iContinue int32, iBreak int32) {
bp := tls.Alloc(16)
defer tls.Free(16)
var addr, addrTest, eDest, eType, hasDistinct, i, i2, iParm, iTab, j, nKey, nPrefixReg, nResultCol, r1, r11, r12, r13, r2, r21, r3, regOrig, regResult, v1 int32
var ecelFlags Tu8
var pEList, pSO, v uintptr
var _ /* sRowLoadInfo at bp+0 */ TRowLoadInfo
_, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _ = addr, addrTest, eDest, eType, ecelFlags, hasDistinct, i, i2, iParm, iTab, j, nKey, nPrefixReg, nResultCol, pEList, pSO, r1, r11, r12, r13, r2, r21, r3, regOrig, regResult, v, v1
v = (*TParse)(unsafe.Pointer(pParse)).FpVdbe /* True if the DISTINCT keyword is present */
eDest = libc.Int32FromUint8((*TSelectDest)(unsafe.Pointer(pDest)).FeDest) /* How to dispose of results */
iParm = (*TSelectDest)(unsafe.Pointer(pDest)).FiSDParm /* Number of result columns */
nPrefixReg = 0 /* Start of memory holding full result (or 0) */
if pDistinct != 0 {
v1 = libc.Int32FromUint8((*TDistinctCtx)(unsafe.Pointer(pDistinct)).FeTnctType)
} else {
v1 = WHERE_DISTINCT_NOOP
}
hasDistinct = v1
if pSort != 0 && (*TSortCtx)(unsafe.Pointer(pSort)).FpOrderBy == uintptr(0) {
pSort = uintptr(0)
}
if pSort == uintptr(0) && !(hasDistinct != 0) {
_codeOffset(tls, v, (*TSelect)(unsafe.Pointer(p)).FiOffset, iContinue)
}
/* Pull the requested columns.
*/
nResultCol = (*TExprList)(unsafe.Pointer((*TSelect)(unsafe.Pointer(p)).FpEList)).FnExpr
if (*TSelectDest)(unsafe.Pointer(pDest)).FiSdst == 0 {
if pSort != 0 {
nPrefixReg = (*TExprList)(unsafe.Pointer((*TSortCtx)(unsafe.Pointer(pSort)).FpOrderBy)).FnExpr
if !(libc.Int32FromUint8((*TSortCtx)(unsafe.Pointer(pSort)).FsortFlags)&libc.Int32FromInt32(SORTFLAG_UseSorter) != 0) {
nPrefixReg = nPrefixReg + 1
}
**(**int32)(__ccgo_up(pParse + 60)) += nPrefixReg
}
(*TSelectDest)(unsafe.Pointer(pDest)).FiSdst = (*TParse)(unsafe.Pointer(pParse)).FnMem + int32(1)
**(**int32)(__ccgo_up(pParse + 60)) += nResultCol
} else {
if (*TSelectDest)(unsafe.Pointer(pDest)).FiSdst+nResultCol > (*TParse)(unsafe.Pointer(pParse)).FnMem {
/* This is an error condition that can result, for example, when a SELECT
** on the right-hand side of an INSERT contains more result columns than
** there are columns in the table on the left. The error will be caught
** and reported later. But we need to make sure enough memory is allocated
** to avoid other spurious errors in the meantime. */
**(**int32)(__ccgo_up(pParse + 60)) += nResultCol
}
}
(*TSelectDest)(unsafe.Pointer(pDest)).FnSdst = nResultCol
v1 = (*TSelectDest)(unsafe.Pointer(pDest)).FiSdst
regResult = v1
regOrig = v1
if srcTab >= 0 {
i = 0
for {
if !(i < nResultCol) {
break
}
_sqlite3VdbeAddOp3(tls, v, int32(OP_Column), srcTab, i, regResult+i)
goto _3
_3:
;
i = i + 1
}
} else {
if eDest != int32(SRT_Exists) {
if eDest == int32(SRT_Mem) || eDest == int32(SRT_Output) || eDest == int32(SRT_Coroutine) {
ecelFlags = uint8(SQLITE_ECEL_DUP)
} else {
ecelFlags = uint8(0)
}
if pSort != 0 && hasDistinct == 0 && eDest != int32(SRT_EphemTab) && eDest != int32(SRT_Table) {
/* For each expression in p->pEList that is a copy of an expression in
** the ORDER BY clause (pSort->pOrderBy), set the associated
** iOrderByCol value to one more than the index of the ORDER BY
** expression within the sort-key that pushOntoSorter() will generate.
** This allows the p->pEList field to be omitted from the sorted record,
** saving space and CPU cycles. */
ecelFlags = libc.Uint8FromInt32(int32(ecelFlags) | (libc.Int32FromInt32(SQLITE_ECEL_OMITREF) | libc.Int32FromInt32(SQLITE_ECEL_REF)))
i = (*TSortCtx)(unsafe.Pointer(pSort)).FnOBSat
for {
if !(i < (*TExprList)(unsafe.Pointer((*TSortCtx)(unsafe.Pointer(pSort)).FpOrderBy)).FnExpr) {
break
}
v1 = libc.Int32FromUint16(*(*Tu16)(unsafe.Pointer((*TSortCtx)(unsafe.Pointer(pSort)).FpOrderBy + 8 + uintptr(i)*32 + 24)))
j = v1
if v1 > 0 {
*(*Tu16)(unsafe.Pointer((*TSelect)(unsafe.Pointer(p)).FpEList + 8 + uintptr(j-int32(1))*32 + 24)) = libc.Uint16FromInt32(i + int32(1) - (*TSortCtx)(unsafe.Pointer(pSort)).FnOBSat)
}
goto _4
_4:
;
i = i + 1
}
/* Adjust nResultCol to account for columns that are omitted
** from the sorter by the optimizations in this branch */
pEList = (*TSelect)(unsafe.Pointer(p)).FpEList
i = 0
for {
if !(i < (*TExprList)(unsafe.Pointer(pEList)).FnExpr) {
break
}
if libc.Int32FromUint16(*(*Tu16)(unsafe.Pointer(pEList + 8 + uintptr(i)*32 + 24))) > 0 {
nResultCol = nResultCol - 1
regOrig = 0
}
goto _6
_6:
;
i = i + 1
}
}
(**(**TRowLoadInfo)(__ccgo_up(bp))).FregResult = regResult
(**(**TRowLoadInfo)(__ccgo_up(bp))).FecelFlags = ecelFlags
if (*TSelect)(unsafe.Pointer(p)).FiLimit != 0 && libc.Int32FromUint8(ecelFlags)&int32(SQLITE_ECEL_OMITREF) != 0 && nPrefixReg > 0 {
(*TSortCtx)(unsafe.Pointer(pSort)).FpDeferredRowLoad = bp
regOrig = 0
} else {
_innerLoopLoadRow(tls, pParse, p, bp)
}
}
}
/* If the DISTINCT keyword was present on the SELECT statement
** and this row has been seen before, then do not make this row
** part of the result.
*/
if hasDistinct != 0 {
eType = libc.Int32FromUint8((*TDistinctCtx)(unsafe.Pointer(pDistinct)).FeTnctType)
iTab = (*TDistinctCtx)(unsafe.Pointer(pDistinct)).FtabTnct
iTab = _codeDistinct(tls, pParse, eType, iTab, iContinue, (*TSelect)(unsafe.Pointer(p)).FpEList, regResult)
_fixDistinctOpenEph(tls, pParse, eType, iTab, (*TDistinctCtx)(unsafe.Pointer(pDistinct)).FaddrTnct)
if pSort == uintptr(0) {
_codeOffset(tls, v, (*TSelect)(unsafe.Pointer(p)).FiOffset, iContinue)
}
}
switch eDest {
/* Store the result as data using a unique key.
*/
case int32(SRT_Fifo):
fallthrough
case int32(SRT_DistFifo):
fallthrough
case int32(SRT_Table):
fallthrough
case int32(SRT_EphemTab):
r1 = _sqlite3GetTempRange(tls, pParse, nPrefixReg+int32(1))
_sqlite3VdbeAddOp3(tls, v, int32(OP_MakeRecord), regResult, nResultCol, r1+nPrefixReg)
if eDest == int32(SRT_DistFifo) {
/* If the destination is DistFifo, then cursor (iParm+1) is open
** on an ephemeral index. If the current row is already present
** in the index, do not write it to the output. If not, add the
** current row to the index and proceed with writing it to the
** output table as well. */
addr = _sqlite3VdbeCurrentAddr(tls, v) + int32(4)
_sqlite3VdbeAddOp4Int(tls, v, int32(OP_Found), iParm+int32(1), addr, r1, 0)
_sqlite3VdbeAddOp4Int(tls, v, int32(OP_IdxInsert), iParm+int32(1), r1, regResult, nResultCol)
}
if pSort != 0 {
_pushOntoSorter(tls, pParse, pSort, p, r1+nPrefixReg, regOrig, int32(1), nPrefixReg)
} else {
r2 = _sqlite3GetTempReg(tls, pParse)
_sqlite3VdbeAddOp2(tls, v, int32(OP_NewRowid), iParm, r2)
_sqlite3VdbeAddOp3(tls, v, int32(OP_Insert), iParm, r1, r2)
_sqlite3VdbeChangeP5(tls, v, uint16(OPFLAG_APPEND))
_sqlite3ReleaseTempReg(tls, pParse, r2)
}
_sqlite3ReleaseTempRange(tls, pParse, r1, nPrefixReg+int32(1))
case int32(SRT_Upfrom):
if pSort != 0 {
_pushOntoSorter(tls, pParse, pSort, p, regResult, regOrig, nResultCol, nPrefixReg)
} else {
i2 = (*TSelectDest)(unsafe.Pointer(pDest)).FiSDParm2
r11 = _sqlite3GetTempReg(tls, pParse)
/* If the UPDATE FROM join is an aggregate that matches no rows, it
** might still be trying to return one row, because that is what
** aggregates do. Don't record that empty row in the output table. */
_sqlite3VdbeAddOp2(tls, v, int32(OP_IsNull), regResult, iBreak)
_sqlite3VdbeAddOp3(tls, v, int32(OP_MakeRecord), regResult+libc.BoolInt32(i2 < 0), nResultCol-libc.BoolInt32(i2 < 0), r11)
if i2 < 0 {
_sqlite3VdbeAddOp3(tls, v, int32(OP_Insert), iParm, r11, regResult)
} else {
_sqlite3VdbeAddOp4Int(tls, v, int32(OP_IdxInsert), iParm, r11, regResult, i2)
}
}
break
/* If we are creating a set for an "expr IN (SELECT ...)" construct,
** then there should be a single item on the stack. Write this
** item into the set table with bogus data.
*/
fallthrough
case int32(SRT_Set):
if pSort != 0 {
/* At first glance you would think we could optimize out the
** ORDER BY in this case since the order of entries in the set
** does not matter. But there might be a LIMIT clause, in which
** case the order does matter */
_pushOntoSorter(tls, pParse, pSort, p, regResult, regOrig, nResultCol, nPrefixReg)
(*TSelectDest)(unsafe.Pointer(pDest)).FiSDParm2 = 0 /* Signal that any Bloom filter is unpopulated */
} else {
r12 = _sqlite3GetTempReg(tls, pParse)
_sqlite3VdbeAddOp4(tls, v, int32(OP_MakeRecord), regResult, nResultCol, r12, (*TSelectDest)(unsafe.Pointer(pDest)).FzAffSdst, nResultCol)
_sqlite3VdbeAddOp4Int(tls, v, int32(OP_IdxInsert), iParm, r12, regResult, nResultCol)
if (*TSelectDest)(unsafe.Pointer(pDest)).FiSDParm2 != 0 {
_sqlite3VdbeAddOp4Int(tls, v, int32(OP_FilterAdd), (*TSelectDest)(unsafe.Pointer(pDest)).FiSDParm2, 0, regResult, nResultCol)
_sqlite3VdbeExplain(tls, pParse, uint8(0), __ccgo_ts+20862, 0)
}
_sqlite3ReleaseTempReg(tls, pParse, r12)
}
break
/* If any row exist in the result set, record that fact and abort.
*/
fallthrough
case int32(SRT_Exists):
_sqlite3VdbeAddOp2(tls, v, int32(OP_Integer), int32(1), iParm)
/* The LIMIT clause will terminate the loop for us */
break
/* If this is a scalar select that is part of an expression, then
** store the results in the appropriate memory cell or array of
** memory cells and break out of the scan loop.
*/
fallthrough
case int32(SRT_Mem):
if pSort != 0 {
_pushOntoSorter(tls, pParse, pSort, p, regResult, regOrig, nResultCol, nPrefixReg)
(*TSelectDest)(unsafe.Pointer(pDest)).FiSDParm = regResult
} else {
if regResult != iParm {
/* This occurs in cases where the SELECT had both a DISTINCT and
** an OFFSET clause. */
_sqlite3VdbeAddOp3(tls, v, int32(OP_Copy), regResult, iParm, nResultCol-int32(1))
}
/* The LIMIT clause will jump out of the loop for us */
}
case int32(SRT_Coroutine): /* Send data to a co-routine */
fallthrough
case int32(SRT_Output): /* Return the results */
if pSort != 0 {
_pushOntoSorter(tls, pParse, pSort, p, regResult, regOrig, nResultCol, nPrefixReg)
} else {
if eDest == int32(SRT_Coroutine) {
_sqlite3VdbeAddOp1(tls, v, int32(OP_Yield), (*TSelectDest)(unsafe.Pointer(pDest)).FiSDParm)
} else {
_sqlite3VdbeAddOp2(tls, v, int32(OP_ResultRow), regResult, nResultCol)
}
}
break
/* Write the results into a priority queue that is order according to
** pDest->pOrderBy (in pSO). pDest->iSDParm (in iParm) is the cursor for an
** index with pSO->nExpr+2 columns. Build a key using pSO for the first
** pSO->nExpr columns, then make sure all keys are unique by adding a
** final OP_Sequence column. The last column is the record as a blob.
*/
fallthrough
case int32(SRT_DistQueue):
fallthrough
case int32(SRT_Queue):
addrTest = 0
pSO = (*TSelectDest)(unsafe.Pointer(pDest)).FpOrderBy
nKey = (*TExprList)(unsafe.Pointer(pSO)).FnExpr
r13 = _sqlite3GetTempReg(tls, pParse)
r21 = _sqlite3GetTempRange(tls, pParse, nKey+int32(2))
r3 = r21 + nKey + int32(1)
if eDest == int32(SRT_DistQueue) {
/* If the destination is DistQueue, then cursor (iParm+1) is open
** on a second ephemeral index that holds all values every previously
** added to the queue. */
addrTest = _sqlite3VdbeAddOp4Int(tls, v, int32(OP_Found), iParm+int32(1), 0, regResult, nResultCol)
}
_sqlite3VdbeAddOp3(tls, v, int32(OP_MakeRecord), regResult, nResultCol, r3)
if eDest == int32(SRT_DistQueue) {
_sqlite3VdbeAddOp2(tls, v, int32(OP_IdxInsert), iParm+int32(1), r3)
_sqlite3VdbeChangeP5(tls, v, uint16(OPFLAG_USESEEKRESULT))
}
i = 0
for {
if !(i < nKey) {
break
}
_sqlite3VdbeAddOp2(tls, v, int32(OP_SCopy), regResult+libc.Int32FromUint16(*(*Tu16)(unsafe.Pointer(pSO + 8 + uintptr(i)*32 + 24)))-int32(1), r21+i)
goto _7
_7:
;
i = i + 1
}
_sqlite3VdbeAddOp2(tls, v, int32(OP_Sequence), iParm, r21+nKey)
_sqlite3VdbeAddOp3(tls, v, int32(OP_MakeRecord), r21, nKey+int32(2), r13)
_sqlite3VdbeAddOp4Int(tls, v, int32(OP_IdxInsert), iParm, r13, r21, nKey+int32(2))
if addrTest != 0 {
_sqlite3VdbeJumpHere(tls, v, addrTest)
}
_sqlite3ReleaseTempReg(tls, pParse, r13)
_sqlite3ReleaseTempRange(tls, pParse, r21, nKey+int32(2))
break
/* Discard the results. This is used for SELECT statements inside
** the body of a TRIGGER. The purpose of such selects is to call
** user-defined functions that have side effects. We do not care
** about the actual results of the select.
*/
fallthrough
default:
break
}
/* Jump to the end of the loop if the LIMIT is reached. Except, if
** there is a sorter, in which case the sorter has already limited
** the output for us.
*/
if pSort == uintptr(0) && (*TSelect)(unsafe.Pointer(p)).FiLimit != 0 {
_sqlite3VdbeAddOp2(tls, v, int32(OP_DecrJumpZero), (*TSelect)(unsafe.Pointer(p)).FiLimit, iBreak)
}
}
// C documentation
//
// /*
// ** Iterate through each expression in expression-list pEList. For each:
// **
// ** * TK_COLUMN,
// ** * aggregate function, or
// ** * window function with a Window object that is not a member of the
// ** Window list passed as the second argument (pWin).
// **
// ** Append the node to output expression-list (*ppSub). And replace it
// ** with a TK_COLUMN that reads the (N-1)th element of table
// ** pWin->iEphCsr, where N is the number of elements in (*ppSub) after
// ** appending the new one.
// */
func _selectWindowRewriteEList(tls *libc.TLS, pParse uintptr, pWin uintptr, pSrc uintptr, pEList uintptr, pTab uintptr, ppSub uintptr) {
bp := tls.Alloc(96)
defer tls.Free(96)
var _ /* sRewrite at bp+48 */ TWindowRewrite
var _ /* sWalker at bp+0 */ TWalker
libc.X__builtin___memset_chk(tls, bp, 0, uint64(48), ^t__predefined_size_t(0))
libc.X__builtin___memset_chk(tls, bp+48, 0, uint64(40), ^t__predefined_size_t(0))
(**(**TWindowRewrite)(__ccgo_up(bp + 48))).FpSub = **(**uintptr)(__ccgo_up(ppSub))
(**(**TWindowRewrite)(__ccgo_up(bp + 48))).FpWin = pWin
(**(**TWindowRewrite)(__ccgo_up(bp + 48))).FpSrc = pSrc
(**(**TWindowRewrite)(__ccgo_up(bp + 48))).FpTab = pTab
(**(**TWalker)(__ccgo_up(bp))).FpParse = pParse
(**(**TWalker)(__ccgo_up(bp))).FxExprCallback = __ccgo_fp(_selectWindowRewriteExprCb)
(**(**TWalker)(__ccgo_up(bp))).FxSelectCallback = __ccgo_fp(_selectWindowRewriteSelectCb)
*(*uintptr)(unsafe.Pointer(bp + 40)) = bp + 48
_sqlite3WalkExprList(tls, bp, pEList)
**(**uintptr)(__ccgo_up(ppSub)) = (**(**TWindowRewrite)(__ccgo_up(bp + 48))).FpSub
}
// C documentation
//
// /*
// ** Callback function used by selectWindowRewriteEList(). If necessary,
// ** this function appends to the output expression-list and updates
// ** expression (*ppExpr) in place.
// */
func _selectWindowRewriteExprCb(tls *libc.TLS, pWalker uintptr, pExpr uintptr) (r int32) {
var f, i, i1, iCol, nSrc, v4 int32
var p, pDup, pParse, pWin uintptr
_, _, _, _, _, _, _, _, _, _ = f, i, i1, iCol, nSrc, p, pDup, pParse, pWin, v4
p = *(*uintptr)(unsafe.Pointer(pWalker + 40))
pParse = (*TWalker)(unsafe.Pointer(pWalker)).FpParse
/* If this function is being called from within a scalar sub-select
** that used by the SELECT statement being processed, only process
** TK_COLUMN expressions that refer to it (the outer SELECT). Do
** not process aggregates or window functions at all, as they belong
** to the scalar sub-select. */
if (*TWindowRewrite)(unsafe.Pointer(p)).FpSubSelect != 0 {
if libc.Int32FromUint8((*TExpr)(unsafe.Pointer(pExpr)).Fop) != int32(TK_COLUMN) {
return WRC_Continue
} else {
nSrc = (*TSrcList)(unsafe.Pointer((*TWindowRewrite)(unsafe.Pointer(p)).FpSrc)).FnSrc
i = 0
for {
if !(i < nSrc) {
break
}
if (*TExpr)(unsafe.Pointer(pExpr)).FiTable == (*(*TSrcItem)(unsafe.Pointer((*TWindowRewrite)(unsafe.Pointer(p)).FpSrc + 8 + uintptr(i)*80))).FiCursor {
break
}
goto _1
_1:
;
i = i + 1
}
if i == nSrc {
return WRC_Continue
}
}
}
switch libc.Int32FromUint8((*TExpr)(unsafe.Pointer(pExpr)).Fop) {
case int32(TK_FUNCTION):
if !((*TExpr)(unsafe.Pointer(pExpr)).Fflags&libc.Uint32FromInt32(libc.Int32FromInt32(EP_WinFunc)) != libc.Uint32FromInt32(0)) {
break
} else {
pWin = (*TWindowRewrite)(unsafe.Pointer(p)).FpWin
for {
if !(pWin != 0) {
break
}
if *(*uintptr)(unsafe.Pointer(pExpr + 64)) == pWin {
return int32(WRC_Prune)
}
goto _2
_2:
;
pWin = (*TWindow)(unsafe.Pointer(pWin)).FpNextWin
}
}
fallthrough
case int32(TK_IF_NULL_ROW):
fallthrough
case int32(TK_AGG_FUNCTION):
fallthrough
case int32(TK_COLUMN):
iCol = -int32(1)
if (*Tsqlite3)(unsafe.Pointer((*TParse)(unsafe.Pointer(pParse)).Fdb)).FmallocFailed != 0 {
return int32(WRC_Abort)
}
if (*TWindowRewrite)(unsafe.Pointer(p)).FpSub != 0 {
i1 = 0
for {
if !(i1 < (*TExprList)(unsafe.Pointer((*TWindowRewrite)(unsafe.Pointer(p)).FpSub)).FnExpr) {
break
}
if 0 == _sqlite3ExprCompare(tls, uintptr(0), (*(*TExprList_item)(unsafe.Pointer((*TWindowRewrite)(unsafe.Pointer(p)).FpSub + 8 + uintptr(i1)*32))).FpExpr, pExpr, -int32(1)) {
iCol = i1
break
}
goto _3
_3:
;
i1 = i1 + 1
}
}
if iCol < 0 {
pDup = _sqlite3ExprDup(tls, (*TParse)(unsafe.Pointer(pParse)).Fdb, pExpr, 0)
if pDup != 0 && libc.Int32FromUint8((*TExpr)(unsafe.Pointer(pDup)).Fop) == int32(TK_AGG_FUNCTION) {
(*TExpr)(unsafe.Pointer(pDup)).Fop = uint8(TK_FUNCTION)
}
(*TWindowRewrite)(unsafe.Pointer(p)).FpSub = _sqlite3ExprListAppend(tls, pParse, (*TWindowRewrite)(unsafe.Pointer(p)).FpSub, pDup)
}
if (*TWindowRewrite)(unsafe.Pointer(p)).FpSub != 0 {
f = libc.Int32FromUint32((*TExpr)(unsafe.Pointer(pExpr)).Fflags & uint32(EP_Collate))
**(**Tu32)(__ccgo_up(pExpr + 4)) |= libc.Uint32FromInt32(libc.Int32FromInt32(EP_Static))
_sqlite3ExprDelete(tls, (*TParse)(unsafe.Pointer(pParse)).Fdb, pExpr)
**(**Tu32)(__ccgo_up(pExpr + 4)) &= ^libc.Uint32FromInt32(libc.Int32FromInt32(EP_Static))
libc.X__builtin___memset_chk(tls, pExpr, 0, uint64(72), ^t__predefined_size_t(0))
(*TExpr)(unsafe.Pointer(pExpr)).Fop = uint8(TK_COLUMN)
if iCol < 0 {
v4 = (*TExprList)(unsafe.Pointer((*TWindowRewrite)(unsafe.Pointer(p)).FpSub)).FnExpr - int32(1)
} else {
v4 = iCol
}
(*TExpr)(unsafe.Pointer(pExpr)).FiColumn = int16(v4)
(*TExpr)(unsafe.Pointer(pExpr)).FiTable = (*TWindow)(unsafe.Pointer((*TWindowRewrite)(unsafe.Pointer(p)).FpWin)).FiEphCsr
*(*uintptr)(unsafe.Pointer(pExpr + 64)) = (*TWindowRewrite)(unsafe.Pointer(p)).FpTab
(*TExpr)(unsafe.Pointer(pExpr)).Fflags = libc.Uint32FromInt32(f)
}
if (*Tsqlite3)(unsafe.Pointer((*TParse)(unsafe.Pointer(pParse)).Fdb)).FmallocFailed != 0 {
return int32(WRC_Abort)
}
default: /* no-op */
break
}
return WRC_Continue
}
// C documentation
//
// /*
// ** Deserialize the data blob pointed to by buf as serial type serial_type
// ** and store the result in pMem.
// **
// ** This function is implemented as two separate routines for performance.
// ** The few cases that require local variables are broken out into a separate
// ** routine so that in most cases the overhead of moving the stack pointer
// ** is avoided.
// */
func _serialGet(tls *libc.TLS, buf uintptr, serial_type Tu32, pMem uintptr) {
bp := tls.Alloc(16)
defer tls.Free(16)
var y Tu32
var v1 int32
var _ /* x at bp+0 */ Tu64
_, _ = y, v1
**(**Tu64)(__ccgo_up(bp)) = uint64(uint32(**(**uint8)(__ccgo_up(buf)))< 0 && 0 == _sessionBufferGrow(tls, p, int64(nBlob), pRc) {
libc.X__builtin___memcpy_chk(tls, (*TSessionBuffer)(unsafe.Pointer(p)).FaBuf+uintptr((*TSessionBuffer)(unsafe.Pointer(p)).FnBuf), aBlob, libc.Uint64FromInt32(nBlob), ^t__predefined_size_t(0))
**(**int32)(__ccgo_up(p + 8)) += nBlob
}
}
// 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.Int32FromUint64(libc.Uint64FromInt64(24)-libc.Uint64FromInt32(1)), bp, __ccgo_ts+5637, libc.VaList(bp+32, iVal))
_sessionAppendStr(tls, p, bp, pRc)
}
// C documentation
//
// /*
// ** This function is called when rebasing a local UPDATE change against one
// ** or more remote UPDATE changes. The aRec/nRec buffer contains the current
// ** old.* and new.* records for the change. The rebase buffer (a single
// ** record) is in aChange/nChange. The rebased change is appended to buffer
// ** pBuf.
// **
// ** Rebasing the UPDATE involves:
// **
// ** * Removing any changes to fields for which the corresponding field
// ** in the rebase buffer is set to "replaced" (type 0xFF). If this
// ** means the UPDATE change updates no fields, nothing is appended
// ** to the output buffer.
// **
// ** * For each field modified by the local change for which the
// ** corresponding field in the rebase buffer is not "undefined" (0x00)
// ** or "replaced" (0xFF), the old.* value is replaced by the value
// ** in the rebase buffer.
// */
func _sessionAppendPartialUpdate(tls *libc.TLS, pBuf uintptr, pIter uintptr, aRec uintptr, nRec int32, aChange uintptr, nChange int32, pRc uintptr) {
var a1, a2, pOut, v1 uintptr
var bData, i, n1, n11, n2, n21 int32
_, _, _, _, _, _, _, _, _, _ = a1, a2, bData, i, n1, n11, n2, n21, pOut, v1
_sessionBufferGrow(tls, pBuf, libc.Int64FromInt32(2)+int64(nRec)+int64(nChange), pRc)
if **(**int32)(__ccgo_up(pRc)) == SQLITE_OK {
bData = 0
pOut = (*TSessionBuffer)(unsafe.Pointer(pBuf)).FaBuf + uintptr((*TSessionBuffer)(unsafe.Pointer(pBuf)).FnBuf)
a1 = aRec
a2 = aChange
v1 = pOut
pOut = pOut + 1
**(**Tu8)(__ccgo_up(v1)) = uint8(SQLITE_UPDATE)
v1 = pOut
pOut = pOut + 1
**(**Tu8)(__ccgo_up(v1)) = libc.Uint8FromInt32((*Tsqlite3_changeset_iter)(unsafe.Pointer(pIter)).FbIndirect)
i = 0
for {
if !(i < (*Tsqlite3_changeset_iter)(unsafe.Pointer(pIter)).FnCol) {
break
}
n1 = _sessionSerialLen(tls, a1)
n2 = _sessionSerialLen(tls, a2)
if **(**Tu8)(__ccgo_up((*Tsqlite3_changeset_iter)(unsafe.Pointer(pIter)).FabPK + uintptr(i))) != 0 || libc.Int32FromUint8(**(**Tu8)(__ccgo_up(a2))) == 0 {
if !(**(**Tu8)(__ccgo_up((*Tsqlite3_changeset_iter)(unsafe.Pointer(pIter)).FabPK + uintptr(i))) != 0) && **(**Tu8)(__ccgo_up(a1)) != 0 {
bData = int32(1)
}
libc.X__builtin___memcpy_chk(tls, pOut, a1, libc.Uint64FromInt32(n1), ^t__predefined_size_t(0))
pOut = pOut + uintptr(n1)
} else {
if libc.Int32FromUint8(**(**Tu8)(__ccgo_up(a2))) != int32(0xFF) && **(**Tu8)(__ccgo_up(a1)) != 0 {
bData = int32(1)
libc.X__builtin___memcpy_chk(tls, pOut, a2, libc.Uint64FromInt32(n2), ^t__predefined_size_t(0))
pOut = pOut + uintptr(n2)
} else {
v1 = pOut
pOut = pOut + 1
**(**Tu8)(__ccgo_up(v1)) = uint8('\000')
}
}
a1 = a1 + uintptr(n1)
a2 = a2 + uintptr(n2)
goto _3
_3:
;
i = i + 1
}
if bData != 0 {
a2 = aChange
i = 0
for {
if !(i < (*Tsqlite3_changeset_iter)(unsafe.Pointer(pIter)).FnCol) {
break
}
n11 = _sessionSerialLen(tls, a1)
n21 = _sessionSerialLen(tls, a2)
if **(**Tu8)(__ccgo_up((*Tsqlite3_changeset_iter)(unsafe.Pointer(pIter)).FabPK + uintptr(i))) != 0 || libc.Int32FromUint8(**(**Tu8)(__ccgo_up(a2))) != int32(0xFF) {
libc.X__builtin___memcpy_chk(tls, pOut, a1, libc.Uint64FromInt32(n11), ^t__predefined_size_t(0))
pOut = pOut + uintptr(n11)
} else {
v1 = pOut
pOut = pOut + 1
**(**Tu8)(__ccgo_up(v1)) = uint8('\000')
}
a1 = a1 + uintptr(n11)
a2 = a2 + uintptr(n21)
goto _5
_5:
;
i = i + 1
}
(*TSessionBuffer)(unsafe.Pointer(pBuf)).FnBuf = int32(int64(pOut) - int64((*TSessionBuffer)(unsafe.Pointer(pBuf)).FaBuf))
}
}
}
// C documentation
//
// /*
// ** Buffers a1 and a2 must both contain a sessions module record nCol
// ** fields in size. This function appends an nCol sessions module
// ** record to buffer pBuf that is a copy of a1, except that for
// ** each field that is undefined in a1[], swap in the field from a2[].
// */
func _sessionAppendRecordMerge(tls *libc.TLS, pBuf uintptr, nCol int32, a1 uintptr, n1 int32, a2 uintptr, n2 int32, pRc uintptr) {
var a1Eof, a2Eof, pOut uintptr
var i, nn1, nn2, v2, v3 int32
_, _, _, _, _, _, _, _ = a1Eof, a2Eof, i, nn1, nn2, pOut, v2, v3
a1Eof = a1 + uintptr(n1)
a2Eof = a2 + uintptr(n2)
_sessionBufferGrow(tls, pBuf, int64(n1)+int64(n2), pRc)
if **(**int32)(__ccgo_up(pRc)) == SQLITE_OK {
pOut = (*TSessionBuffer)(unsafe.Pointer(pBuf)).FaBuf + uintptr((*TSessionBuffer)(unsafe.Pointer(pBuf)).FnBuf)
i = 0
for {
if !(i < nCol) {
break
}
if a1 < a1Eof {
v2 = _sessionSerialLen(tls, a1)
} else {
v2 = 0
}
nn1 = v2
if a2 < a2Eof {
v3 = _sessionSerialLen(tls, a2)
} else {
v3 = 0
}
nn2 = v3
if nn1 == 0 || nn2 > 0 && (libc.Int32FromUint8(**(**Tu8)(__ccgo_up(a1))) == 0 || libc.Int32FromUint8(**(**Tu8)(__ccgo_up(a1))) == int32(0xFF)) {
libc.X__builtin___memcpy_chk(tls, pOut, a2, libc.Uint64FromInt32(nn2), ^t__predefined_size_t(0))
pOut = pOut + uintptr(nn2)
} else {
libc.X__builtin___memcpy_chk(tls, pOut, a1, libc.Uint64FromInt32(nn1), ^t__predefined_size_t(0))
pOut = pOut + uintptr(nn1)
}
a1 = a1 + uintptr(nn1)
a2 = a2 + uintptr(nn2)
goto _1
_1:
;
i = i + 1
}
(*TSessionBuffer)(unsafe.Pointer(pBuf)).FnBuf = int32(int64(pOut) - int64((*TSessionBuffer)(unsafe.Pointer(pBuf)).FaBuf))
}
}
// C documentation
//
// /*
// ** This function is a no-op if *pRc is other than SQLITE_OK when it is
// ** called. Otherwise, append a string to the buffer. All bytes in the string
// ** up to (but not including) the nul-terminator are written to the buffer.
// **
// ** If an OOM condition is encountered, set *pRc to SQLITE_NOMEM before
// ** returning.
// */
func _sessionAppendStr(tls *libc.TLS, p uintptr, zStr uintptr, pRc uintptr) {
var nStr int32
_ = nStr
nStr = _sqlite3Strlen30(tls, zStr)
if 0 == _sessionBufferGrow(tls, p, int64(nStr)+int64(1), pRc) {
libc.X__builtin___memcpy_chk(tls, (*TSessionBuffer)(unsafe.Pointer(p)).FaBuf+uintptr((*TSessionBuffer)(unsafe.Pointer(p)).FnBuf), zStr, libc.Uint64FromInt32(nStr), ^t__predefined_size_t(0))
**(**int32)(__ccgo_up(p + 8)) += nStr
**(**Tu8)(__ccgo_up((*TSessionBuffer)(unsafe.Pointer(p)).FaBuf + uintptr((*TSessionBuffer)(unsafe.Pointer(p)).FnBuf))) = uint8(0x00)
}
}
// C documentation
//
// /*
// **
// ** This function appends an update change to the buffer (see the comments
// ** under "CHANGESET FORMAT" at the top of the file). An update change
// ** consists of:
// **
// ** 1 byte: SQLITE_UPDATE (0x17)
// ** n bytes: old.* record (see RECORD FORMAT)
// ** m bytes: new.* record (see RECORD FORMAT)
// **
// ** The SessionChange object passed as the third argument contains the
// ** values that were stored in the row when the session began (the old.*
// ** values). The statement handle passed as the second argument points
// ** at the current version of the row (the new.* values).
// **
// ** If all of the old.* values are equal to their corresponding new.* value
// ** (i.e. nothing has changed), then no data at all is appended to the buffer.
// **
// ** Otherwise, the old.* record contains all primary key values and the
// ** original values of any fields that have been modified. The new.* record
// ** contains the new values of only those fields that have been modified.
// */
func _sessionAppendUpdate(tls *libc.TLS, pBuf uintptr, bPatchset int32, pStmt uintptr, p uintptr, abPK uintptr) (r int32) {
bp := tls.Alloc(48)
defer tls.Free(48)
var bChanged, bNoop, eType, i, nAdvance, nHdr, nRewind int32
var pCsr uintptr
var _ /* buf2 at bp+8 */ TSessionBuffer
var _ /* dVal at bp+32 */ float64
var _ /* iVal at bp+24 */ Tsqlite3_int64
var _ /* n at bp+40 */ int32
var _ /* rc at bp+0 */ int32
_, _, _, _, _, _, _, _ = bChanged, bNoop, eType, i, nAdvance, nHdr, nRewind, pCsr
**(**int32)(__ccgo_up(bp)) = SQLITE_OK
**(**TSessionBuffer)(__ccgo_up(bp + 8)) = TSessionBuffer{} /* Buffer to accumulate new.* record in */
bNoop = int32(1) /* Set to zero if any values are modified */
nRewind = (*TSessionBuffer)(unsafe.Pointer(pBuf)).FnBuf /* Used to iterate through columns */
pCsr = (*TSessionChange)(unsafe.Pointer(p)).FaRecord /* Used to iterate through old.* values */
_sessionAppendByte(tls, pBuf, uint8(SQLITE_UPDATE), bp)
_sessionAppendByte(tls, pBuf, (*TSessionChange)(unsafe.Pointer(p)).FbIndirect, bp)
i = 0
for {
if !(i < Xsqlite3_column_count(tls, pStmt)) {
break
}
bChanged = 0
eType = libc.Int32FromUint8(**(**Tu8)(__ccgo_up(pCsr)))
switch eType {
case int32(SQLITE_NULL):
nAdvance = int32(1)
if Xsqlite3_column_type(tls, pStmt, i) != int32(SQLITE_NULL) {
bChanged = int32(1)
}
case int32(SQLITE_FLOAT):
fallthrough
case int32(SQLITE_INTEGER):
nAdvance = int32(9)
if eType == Xsqlite3_column_type(tls, pStmt, i) {
**(**Tsqlite3_int64)(__ccgo_up(bp + 24)) = _sessionGetI64(tls, pCsr+1)
if eType == int32(SQLITE_INTEGER) {
if **(**Tsqlite3_int64)(__ccgo_up(bp + 24)) == Xsqlite3_column_int64(tls, pStmt, i) {
break
}
} else {
libc.X__builtin___memcpy_chk(tls, bp+32, bp+24, uint64(8), ^t__predefined_size_t(0))
if **(**float64)(__ccgo_up(bp + 32)) == Xsqlite3_column_double(tls, pStmt, i) {
break
}
}
}
bChanged = int32(1)
default:
nHdr = int32(1) + _sessionVarintGet(tls, pCsr+1, bp+40)
nAdvance = nHdr + **(**int32)(__ccgo_up(bp + 40))
if eType == Xsqlite3_column_type(tls, pStmt, i) && **(**int32)(__ccgo_up(bp + 40)) == Xsqlite3_column_bytes(tls, pStmt, i) && (**(**int32)(__ccgo_up(bp + 40)) == 0 || 0 == libc.Xmemcmp(tls, pCsr+uintptr(nHdr), Xsqlite3_column_blob(tls, pStmt, i), libc.Uint64FromInt32(**(**int32)(__ccgo_up(bp + 40))))) {
break
}
bChanged = int32(1)
}
/* If at least one field has been modified, this is not a no-op. */
if bChanged != 0 {
bNoop = 0
}
/* Add a field to the old.* record. This is omitted if this module is
** currently generating a patchset. */
if bPatchset == 0 {
if bChanged != 0 || **(**Tu8)(__ccgo_up(abPK + uintptr(i))) != 0 {
_sessionAppendBlob(tls, pBuf, pCsr, nAdvance, bp)
} else {
_sessionAppendByte(tls, pBuf, uint8(0), bp)
}
}
/* Add a field to the new.* record. Or the only record if currently
** generating a patchset. */
if bChanged != 0 || bPatchset != 0 && **(**Tu8)(__ccgo_up(abPK + uintptr(i))) != 0 {
_sessionAppendCol(tls, bp+8, pStmt, i, bp)
} else {
_sessionAppendByte(tls, bp+8, uint8(0), bp)
}
pCsr = pCsr + uintptr(nAdvance)
goto _1
_1:
;
i = i + 1
}
if bNoop != 0 {
(*TSessionBuffer)(unsafe.Pointer(pBuf)).FnBuf = nRewind
} else {
_sessionAppendBlob(tls, pBuf, (**(**TSessionBuffer)(__ccgo_up(bp + 8))).FaBuf, (**(**TSessionBuffer)(__ccgo_up(bp + 8))).FnBuf, bp)
}
Xsqlite3_free(tls, (**(**TSessionBuffer)(__ccgo_up(bp + 8))).FaBuf)
return **(**int32)(__ccgo_up(bp))
}
// C documentation
//
// /*
// ** Attempt to apply the change that the iterator passed as the first argument
// ** currently points to to the database. If a conflict is encountered, invoke
// ** the conflict handler callback.
// **
// ** The difference between this function and sessionApplyOne() is that this
// ** function handles the case where the conflict-handler is invoked and
// ** returns SQLITE_CHANGESET_REPLACE - indicating that the change should be
// ** retried in some manner.
// */
func _sessionApplyOneWithRetry(tls *libc.TLS, db uintptr, pIter uintptr, pApply uintptr, __ccgo_fp_xConflict uintptr, pCtx uintptr) (r int32) {
bp := tls.Alloc(16)
defer tls.Free(16)
var rc int32
var _ /* bReplace at bp+0 */ int32
var _ /* bRetry at bp+4 */ int32
_ = rc
**(**int32)(__ccgo_up(bp)) = 0
**(**int32)(__ccgo_up(bp + 4)) = 0
rc = _sessionApplyOneOp(tls, pIter, pApply, __ccgo_fp_xConflict, pCtx, bp, bp+4)
if rc == SQLITE_OK {
/* If the bRetry flag is set, the change has not been applied due to an
** SQLITE_CHANGESET_DATA problem (i.e. this is an UPDATE or DELETE and
** a row with the correct PK is present in the db, but one or more other
** fields do not contain the expected values) and the conflict handler
** returned SQLITE_CHANGESET_REPLACE. In this case retry the operation,
** but pass NULL as the final argument so that sessionApplyOneOp() ignores
** the SQLITE_CHANGESET_DATA problem. */
if **(**int32)(__ccgo_up(bp + 4)) != 0 {
rc = _sessionApplyOneOp(tls, pIter, pApply, __ccgo_fp_xConflict, pCtx, uintptr(0), uintptr(0))
} else {
if **(**int32)(__ccgo_up(bp)) != 0 {
rc = Xsqlite3_exec(tls, db, __ccgo_ts+36716, uintptr(0), uintptr(0), uintptr(0))
if rc == SQLITE_OK {
rc = _sessionBindRow(tls, pIter, __ccgo_fp(Xsqlite3changeset_new), (*TSessionApplyCtx)(unsafe.Pointer(pApply)).FnCol, (*TSessionApplyCtx)(unsafe.Pointer(pApply)).FabPK, (*TSessionApplyCtx)(unsafe.Pointer(pApply)).FpDelete)
Xsqlite3_bind_int(tls, (*TSessionApplyCtx)(unsafe.Pointer(pApply)).FpDelete, (*TSessionApplyCtx)(unsafe.Pointer(pApply)).FnCol+int32(1), int32(1))
}
if rc == SQLITE_OK {
Xsqlite3_step(tls, (*TSessionApplyCtx)(unsafe.Pointer(pApply)).FpDelete)
rc = Xsqlite3_reset(tls, (*TSessionApplyCtx)(unsafe.Pointer(pApply)).FpDelete)
}
if rc == SQLITE_OK {
rc = _sessionApplyOneOp(tls, pIter, pApply, __ccgo_fp_xConflict, pCtx, uintptr(0), uintptr(0))
}
if rc == SQLITE_OK {
rc = Xsqlite3_exec(tls, db, __ccgo_ts+36737, uintptr(0), uintptr(0), uintptr(0))
}
}
}
}
return rc
}
// C documentation
//
// /*
// ** This function is called to merge two changes to the same row together as
// ** part of an sqlite3changeset_concat() operation. A new change object is
// ** allocated and a pointer to it stored in *ppNew.
// **
// ** Because they have been vetted by sqlite3changegroup_add() or similar,
// ** both the aRec[] change and the pExist change are safe to use without
// ** checking for buffer overflows.
// */
func _sessionChangeMerge(tls *libc.TLS, pTab uintptr, bRebase int32, bPatchset int32, pExist uintptr, op2 int32, bIndirect int32, aRec uintptr, nRec int32, ppNew uintptr) (r int32) {
bp := tls.Alloc(32)
defer tls.Free(32)
var a1, a2, aExist, pIn, pNew, pOut, pOut1, v2 uintptr
var i, i1, n1, n2, nIn, op1, rc int32
var nByte, nByte1 Tsqlite3_int64
var _ /* a1 at bp+16 */ uintptr
var _ /* a1 at bp+8 */ uintptr
var _ /* a2 at bp+24 */ uintptr
var _ /* aCsr at bp+0 */ uintptr
_, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _ = a1, a2, aExist, i, i1, n1, n2, nByte, nByte1, nIn, op1, pIn, pNew, pOut, pOut1, rc, v2
pNew = uintptr(0)
rc = SQLITE_OK
if !(pExist != 0) {
pNew = Xsqlite3_malloc64(tls, uint64(uint64(32)+libc.Uint64FromInt32(nRec)))
if !(pNew != 0) {
return int32(SQLITE_NOMEM)
}
libc.X__builtin___memset_chk(tls, pNew, 0, uint64(32), ^t__predefined_size_t(0))
(*TSessionChange)(unsafe.Pointer(pNew)).Fop = libc.Uint8FromInt32(op2)
(*TSessionChange)(unsafe.Pointer(pNew)).FbIndirect = libc.Uint8FromInt32(bIndirect)
(*TSessionChange)(unsafe.Pointer(pNew)).FaRecord = pNew + 1*32
if bIndirect == 0 || bRebase == 0 {
(*TSessionChange)(unsafe.Pointer(pNew)).FnRecord = nRec
libc.X__builtin___memcpy_chk(tls, (*TSessionChange)(unsafe.Pointer(pNew)).FaRecord, aRec, libc.Uint64FromInt32(nRec), ^t__predefined_size_t(0))
} else {
pIn = aRec
pOut = (*TSessionChange)(unsafe.Pointer(pNew)).FaRecord
i = 0
for {
if !(i < (*TSessionTable)(unsafe.Pointer(pTab)).FnCol) {
break
}
nIn = _sessionSerialLen(tls, pIn)
if libc.Int32FromUint8(**(**Tu8)(__ccgo_up(pIn))) == 0 {
v2 = pOut
pOut = pOut + 1
**(**Tu8)(__ccgo_up(v2)) = uint8(0)
} else {
if libc.Int32FromUint8(**(**Tu8)(__ccgo_up((*TSessionTable)(unsafe.Pointer(pTab)).FabPK + uintptr(i)))) == 0 {
v2 = pOut
pOut = pOut + 1
**(**Tu8)(__ccgo_up(v2)) = uint8(0xFF)
} else {
libc.X__builtin___memcpy_chk(tls, pOut, pIn, libc.Uint64FromInt32(nIn), ^t__predefined_size_t(0))
pOut = pOut + uintptr(nIn)
}
}
pIn = pIn + uintptr(nIn)
goto _1
_1:
;
i = i + 1
}
(*TSessionChange)(unsafe.Pointer(pNew)).FnRecord = int32(int64(pOut) - int64((*TSessionChange)(unsafe.Pointer(pNew)).FaRecord))
}
} else {
if bRebase != 0 {
if libc.Int32FromUint8((*TSessionChange)(unsafe.Pointer(pExist)).Fop) == int32(SQLITE_DELETE) && (*TSessionChange)(unsafe.Pointer(pExist)).FbIndirect != 0 {
**(**uintptr)(__ccgo_up(ppNew)) = pExist
} else {
nByte = libc.Int64FromUint64(libc.Uint64FromInt32(nRec+(*TSessionChange)(unsafe.Pointer(pExist)).FnRecord) + uint64(32))
pNew = Xsqlite3_malloc64(tls, libc.Uint64FromInt64(nByte))
if pNew == uintptr(0) {
rc = int32(SQLITE_NOMEM)
} else {
a1 = (*TSessionChange)(unsafe.Pointer(pExist)).FaRecord
a2 = aRec
libc.X__builtin___memset_chk(tls, pNew, 0, libc.Uint64FromInt64(nByte), ^t__predefined_size_t(0))
(*TSessionChange)(unsafe.Pointer(pNew)).FbIndirect = libc.BoolUint8(bIndirect != 0 || (*TSessionChange)(unsafe.Pointer(pExist)).FbIndirect != 0)
(*TSessionChange)(unsafe.Pointer(pNew)).Fop = libc.Uint8FromInt32(op2)
v2 = pNew + 1*32
(*TSessionChange)(unsafe.Pointer(pNew)).FaRecord = v2
pOut1 = v2
i1 = 0
for {
if !(i1 < (*TSessionTable)(unsafe.Pointer(pTab)).FnCol) {
break
}
n1 = _sessionSerialLen(tls, a1)
n2 = _sessionSerialLen(tls, a2)
if libc.Int32FromUint8(**(**Tu8)(__ccgo_up(a1))) == int32(0xFF) || libc.Int32FromUint8(**(**Tu8)(__ccgo_up((*TSessionTable)(unsafe.Pointer(pTab)).FabPK + uintptr(i1)))) == 0 && bIndirect != 0 {
v2 = pOut1
pOut1 = pOut1 + 1
**(**Tu8)(__ccgo_up(v2)) = uint8(0xFF)
} else {
if libc.Int32FromUint8(**(**Tu8)(__ccgo_up(a2))) == 0 {
libc.X__builtin___memcpy_chk(tls, pOut1, a1, libc.Uint64FromInt32(n1), ^t__predefined_size_t(0))
pOut1 = pOut1 + uintptr(n1)
} else {
libc.X__builtin___memcpy_chk(tls, pOut1, a2, libc.Uint64FromInt32(n2), ^t__predefined_size_t(0))
pOut1 = pOut1 + uintptr(n2)
}
}
a1 = a1 + uintptr(n1)
a2 = a2 + uintptr(n2)
goto _5
_5:
;
i1 = i1 + 1
}
(*TSessionChange)(unsafe.Pointer(pNew)).FnRecord = int32(int64(pOut1) - int64((*TSessionChange)(unsafe.Pointer(pNew)).FaRecord))
}
Xsqlite3_free(tls, pExist)
}
} else {
op1 = libc.Int32FromUint8((*TSessionChange)(unsafe.Pointer(pExist)).Fop)
/*
** op1=INSERT, op2=INSERT -> Unsupported. Discard op2.
** op1=INSERT, op2=UPDATE -> INSERT.
** op1=INSERT, op2=DELETE -> (none)
**
** op1=UPDATE, op2=INSERT -> Unsupported. Discard op2.
** op1=UPDATE, op2=UPDATE -> UPDATE.
** op1=UPDATE, op2=DELETE -> DELETE.
**
** op1=DELETE, op2=INSERT -> UPDATE.
** op1=DELETE, op2=UPDATE -> Unsupported. Discard op2.
** op1=DELETE, op2=DELETE -> Unsupported. Discard op2.
*/
if op1 == int32(SQLITE_INSERT) && op2 == int32(SQLITE_INSERT) || op1 == int32(SQLITE_UPDATE) && op2 == int32(SQLITE_INSERT) || op1 == int32(SQLITE_DELETE) && op2 == int32(SQLITE_UPDATE) || op1 == int32(SQLITE_DELETE) && op2 == int32(SQLITE_DELETE) {
pNew = pExist
} else {
if op1 == int32(SQLITE_INSERT) && op2 == int32(SQLITE_DELETE) {
Xsqlite3_free(tls, pExist)
} else {
aExist = (*TSessionChange)(unsafe.Pointer(pExist)).FaRecord
/* Allocate a new SessionChange object. Ensure that the aRecord[]
** buffer of the new object is large enough to hold any record that
** may be generated by combining the input records. */
nByte1 = libc.Int64FromUint64(uint64(32) + libc.Uint64FromInt32((*TSessionChange)(unsafe.Pointer(pExist)).FnRecord) + libc.Uint64FromInt32(nRec))
pNew = Xsqlite3_malloc64(tls, libc.Uint64FromInt64(nByte1))
if !(pNew != 0) {
Xsqlite3_free(tls, pExist)
return int32(SQLITE_NOMEM)
}
libc.X__builtin___memset_chk(tls, pNew, 0, uint64(32), ^t__predefined_size_t(0))
(*TSessionChange)(unsafe.Pointer(pNew)).FbIndirect = libc.BoolUint8(bIndirect != 0 && (*TSessionChange)(unsafe.Pointer(pExist)).FbIndirect != 0)
v2 = pNew + 1*32
(*TSessionChange)(unsafe.Pointer(pNew)).FaRecord = v2
**(**uintptr)(__ccgo_up(bp)) = v2
if op1 == int32(SQLITE_INSERT) { /* INSERT + UPDATE */
**(**uintptr)(__ccgo_up(bp + 8)) = aRec
(*TSessionChange)(unsafe.Pointer(pNew)).Fop = uint8(SQLITE_INSERT)
if bPatchset == 0 {
_sessionSkipRecord(tls, bp+8, (*TSessionTable)(unsafe.Pointer(pTab)).FnCol)
}
_sessionMergeRecord(tls, bp, (*TSessionTable)(unsafe.Pointer(pTab)).FnCol, aExist, **(**uintptr)(__ccgo_up(bp + 8)))
} else {
if op1 == int32(SQLITE_DELETE) { /* DELETE + INSERT */
(*TSessionChange)(unsafe.Pointer(pNew)).Fop = uint8(SQLITE_UPDATE)
if bPatchset != 0 {
libc.X__builtin___memcpy_chk(tls, **(**uintptr)(__ccgo_up(bp)), aRec, libc.Uint64FromInt32(nRec), ^t__predefined_size_t(0))
**(**uintptr)(__ccgo_up(bp)) = **(**uintptr)(__ccgo_up(bp)) + uintptr(nRec)
} else {
if 0 == _sessionMergeUpdate(tls, bp, pTab, bPatchset, aExist, uintptr(0), aRec, uintptr(0)) {
Xsqlite3_free(tls, pNew)
pNew = uintptr(0)
}
}
} else {
if op2 == int32(SQLITE_UPDATE) { /* UPDATE + UPDATE */
**(**uintptr)(__ccgo_up(bp + 16)) = aExist
**(**uintptr)(__ccgo_up(bp + 24)) = aRec
if bPatchset == 0 {
_sessionSkipRecord(tls, bp+16, (*TSessionTable)(unsafe.Pointer(pTab)).FnCol)
_sessionSkipRecord(tls, bp+24, (*TSessionTable)(unsafe.Pointer(pTab)).FnCol)
}
(*TSessionChange)(unsafe.Pointer(pNew)).Fop = uint8(SQLITE_UPDATE)
if 0 == _sessionMergeUpdate(tls, bp, pTab, bPatchset, aRec, aExist, **(**uintptr)(__ccgo_up(bp + 16)), **(**uintptr)(__ccgo_up(bp + 24))) {
Xsqlite3_free(tls, pNew)
pNew = uintptr(0)
}
} else { /* UPDATE + DELETE */
(*TSessionChange)(unsafe.Pointer(pNew)).Fop = uint8(SQLITE_DELETE)
if bPatchset != 0 {
libc.X__builtin___memcpy_chk(tls, **(**uintptr)(__ccgo_up(bp)), aRec, libc.Uint64FromInt32(nRec), ^t__predefined_size_t(0))
**(**uintptr)(__ccgo_up(bp)) = **(**uintptr)(__ccgo_up(bp)) + uintptr(nRec)
} else {
_sessionMergeRecord(tls, bp, (*TSessionTable)(unsafe.Pointer(pTab)).FnCol, aRec, aExist)
}
}
}
}
if pNew != 0 {
(*TSessionChange)(unsafe.Pointer(pNew)).FnRecord = int32(int64(**(**uintptr)(__ccgo_up(bp))) - int64((*TSessionChange)(unsafe.Pointer(pNew)).FaRecord))
}
Xsqlite3_free(tls, pExist)
}
}
}
}
**(**uintptr)(__ccgo_up(ppNew)) = pNew
return rc
}
// C documentation
//
// /*
// ** Argument pIter is a changeset iterator that has been initialized, but
// ** not yet passed to sqlite3changeset_next(). This function applies the
// ** changeset to the main database attached to handle "db". The supplied
// ** conflict handler callback is invoked to resolve any conflicts encountered
// ** while applying the change.
// */
func _sessionChangesetApply(tls *libc.TLS, db uintptr, pIter uintptr, __ccgo_fp_xFilter uintptr, __ccgo_fp_xFilterIter uintptr, __ccgo_fp_xConflict uintptr, pCtx uintptr, ppRebase uintptr, pnRebase uintptr, flags int32) (r int32) {
bp := tls.Alloc(368)
defer tls.Free(368)
var bPatchset, i, nMinCol, nTab, rc, rc2, res, schemaMismatch, v2, v3, v4 int32
var savedFlag Tu64
var v5, v7 bool
var _ /* abPK at bp+160 */ uintptr
var _ /* nCol at bp+144 */ int32
var _ /* nFk at bp+168 */ int32
var _ /* notUsed at bp+172 */ int32
var _ /* op at bp+148 */ int32
var _ /* sApply at bp+8 */ TSessionApplyCtx
var _ /* sIter at bp+176 */ Tsqlite3_changeset_iter
var _ /* zNew at bp+152 */ uintptr
var _ /* zTab at bp+0 */ uintptr
_, _, _, _, _, _, _, _, _, _, _, _, _, _ = bPatchset, i, nMinCol, nTab, rc, rc2, res, savedFlag, schemaMismatch, v2, v3, v4, v5, v7
schemaMismatch = 0
rc = SQLITE_OK /* Return code */
**(**uintptr)(__ccgo_up(bp)) = uintptr(0) /* Name of current table */
nTab = 0
savedFlag = (*Tsqlite3)(unsafe.Pointer(db)).Fflags & (libc.Uint64FromInt32(libc.Int32FromInt32(0x00008)) << libc.Int32FromInt32(32))
Xsqlite3_mutex_enter(tls, Xsqlite3_db_mutex(tls, db))
if flags&int32(SQLITE_CHANGESETAPPLY_FKNOACTION) != 0 {
**(**Tu64)(__ccgo_up(db + 48)) |= libc.Uint64FromInt32(libc.Int32FromInt32(0x00008)) << libc.Int32FromInt32(32)
**(**int32)(__ccgo_up((**(**TDb)(__ccgo_up((*Tsqlite3)(unsafe.Pointer(db)).FaDb))).FpSchema)) -= int32(32)
}
(*Tsqlite3_changeset_iter)(unsafe.Pointer(pIter)).Fin.FbNoDiscard = int32(1)
libc.X__builtin___memset_chk(tls, bp+8, 0, uint64(136), ^t__predefined_size_t(0))
(**(**TSessionApplyCtx)(__ccgo_up(bp + 8))).FbRebase = libc.BoolUint8(ppRebase != 0 && pnRebase != 0)
(**(**TSessionApplyCtx)(__ccgo_up(bp + 8))).FbInvertConstraints = libc.BoolInt32(!!(flags&libc.Int32FromInt32(SQLITE_CHANGESETAPPLY_INVERT) != 0))
(**(**TSessionApplyCtx)(__ccgo_up(bp + 8))).FbIgnoreNoop = libc.BoolUint8(!!(flags&libc.Int32FromInt32(SQLITE_CHANGESETAPPLY_IGNORENOOP) != 0))
(**(**TSessionApplyCtx)(__ccgo_up(bp + 8))).FbNoUpdateLoop = libc.BoolUint8(!!(flags&libc.Int32FromInt32(SQLITE_CHANGESETAPPLY_NOUPDATELOOP) != 0))
if flags&int32(SQLITE_CHANGESETAPPLY_NOSAVEPOINT) == 0 {
rc = Xsqlite3_exec(tls, db, __ccgo_ts+36906, uintptr(0), uintptr(0), uintptr(0))
}
if rc == SQLITE_OK {
rc = Xsqlite3_exec(tls, db, __ccgo_ts+36932, uintptr(0), uintptr(0), uintptr(0))
}
for rc == SQLITE_OK && int32(SQLITE_ROW) == Xsqlite3changeset_next(tls, pIter) {
Xsqlite3changeset_op(tls, pIter, bp+152, bp+144, bp+148, uintptr(0))
if **(**uintptr)(__ccgo_up(bp)) == uintptr(0) || Xsqlite3_strnicmp(tls, **(**uintptr)(__ccgo_up(bp + 152)), **(**uintptr)(__ccgo_up(bp)), nTab+int32(1)) != 0 {
rc = _sessionRetryConstraints(tls, db, (*Tsqlite3_changeset_iter)(unsafe.Pointer(pIter)).FbPatchset, **(**uintptr)(__ccgo_up(bp)), bp+8, __ccgo_fp_xConflict, pCtx)
if rc != SQLITE_OK {
break
}
_sessionUpdateFree(tls, bp+8)
Xsqlite3_free(tls, (**(**TSessionApplyCtx)(__ccgo_up(bp + 8))).FazCol) /* cast works around VC++ bug */
Xsqlite3_finalize(tls, (**(**TSessionApplyCtx)(__ccgo_up(bp + 8))).FpDelete)
Xsqlite3_finalize(tls, (**(**TSessionApplyCtx)(__ccgo_up(bp + 8))).FpInsert)
Xsqlite3_finalize(tls, (**(**TSessionApplyCtx)(__ccgo_up(bp + 8))).FpSelect)
(**(**TSessionApplyCtx)(__ccgo_up(bp + 8))).Fdb = db
(**(**TSessionApplyCtx)(__ccgo_up(bp + 8))).FpDelete = uintptr(0)
(**(**TSessionApplyCtx)(__ccgo_up(bp + 8))).FpInsert = uintptr(0)
(**(**TSessionApplyCtx)(__ccgo_up(bp + 8))).FpSelect = uintptr(0)
(**(**TSessionApplyCtx)(__ccgo_up(bp + 8))).FnCol = 0
(**(**TSessionApplyCtx)(__ccgo_up(bp + 8))).FazCol = uintptr(0)
(**(**TSessionApplyCtx)(__ccgo_up(bp + 8))).FabPK = uintptr(0)
(**(**TSessionApplyCtx)(__ccgo_up(bp + 8))).FbStat1 = 0
(**(**TSessionApplyCtx)(__ccgo_up(bp + 8))).FbDeferConstraints = int32(1)
(**(**TSessionApplyCtx)(__ccgo_up(bp + 8))).FbRebaseStarted = uint8(0)
(**(**TSessionApplyCtx)(__ccgo_up(bp + 8))).FbRowid = 0
libc.X__builtin___memset_chk(tls, bp+8+88, 0, uint64(16), ^t__predefined_size_t(0))
/* If an xFilter() callback was specified, invoke it now. If the
** xFilter callback returns zero, skip this table. If it returns
** non-zero, proceed. */
schemaMismatch = libc.BoolInt32(__ccgo_fp_xFilter != 0 && 0 == (*(*func(*libc.TLS, uintptr, uintptr) int32)(unsafe.Pointer(&struct{ uintptr }{__ccgo_fp_xFilter})))(tls, pCtx, **(**uintptr)(__ccgo_up(bp + 152))))
if schemaMismatch != 0 {
**(**uintptr)(__ccgo_up(bp)) = Xsqlite3_mprintf(tls, __ccgo_ts+3944, libc.VaList(bp+336, **(**uintptr)(__ccgo_up(bp + 152))))
if **(**uintptr)(__ccgo_up(bp)) == uintptr(0) {
rc = int32(SQLITE_NOMEM)
break
}
nTab = libc.Int32FromUint64(libc.Xstrlen(tls, **(**uintptr)(__ccgo_up(bp))))
(**(**TSessionApplyCtx)(__ccgo_up(bp + 8))).FazCol = **(**uintptr)(__ccgo_up(bp))
} else {
nMinCol = 0
Xsqlite3changeset_pk(tls, pIter, bp+160, uintptr(0))
rc = _sessionTableInfo(tls, uintptr(0), db, __ccgo_ts+7164, **(**uintptr)(__ccgo_up(bp + 152)), bp+8+32, uintptr(0), bp, bp+8+40, uintptr(0), uintptr(0), bp+8+48, bp+8+124)
if rc != SQLITE_OK {
break
}
i = 0
for {
if !(i < (**(**TSessionApplyCtx)(__ccgo_up(bp + 8))).FnCol) {
break
}
if **(**Tu8)(__ccgo_up((**(**TSessionApplyCtx)(__ccgo_up(bp + 8))).FabPK + uintptr(i))) != 0 {
nMinCol = i + int32(1)
}
goto _1
_1:
;
i = i + 1
}
if (**(**TSessionApplyCtx)(__ccgo_up(bp + 8))).FnCol == 0 {
schemaMismatch = int32(1)
Xsqlite3_log(tls, int32(SQLITE_SCHEMA), __ccgo_ts+36962, libc.VaList(bp+336, **(**uintptr)(__ccgo_up(bp))))
} else {
if (**(**TSessionApplyCtx)(__ccgo_up(bp + 8))).FnCol < **(**int32)(__ccgo_up(bp + 144)) {
schemaMismatch = int32(1)
Xsqlite3_log(tls, int32(SQLITE_SCHEMA), __ccgo_ts+37006, libc.VaList(bp+336, **(**uintptr)(__ccgo_up(bp)), (**(**TSessionApplyCtx)(__ccgo_up(bp + 8))).FnCol, **(**int32)(__ccgo_up(bp + 144))))
} else {
if **(**int32)(__ccgo_up(bp + 144)) < nMinCol || libc.Xmemcmp(tls, (**(**TSessionApplyCtx)(__ccgo_up(bp + 8))).FabPK, **(**uintptr)(__ccgo_up(bp + 160)), libc.Uint64FromInt32(**(**int32)(__ccgo_up(bp + 144)))) != 0 {
schemaMismatch = int32(1)
Xsqlite3_log(tls, int32(SQLITE_SCHEMA), __ccgo_ts+37077, libc.VaList(bp+336, **(**uintptr)(__ccgo_up(bp))))
} else {
(**(**TSessionApplyCtx)(__ccgo_up(bp + 8))).FnCol = **(**int32)(__ccgo_up(bp + 144))
if 0 == Xsqlite3_stricmp(tls, **(**uintptr)(__ccgo_up(bp)), __ccgo_ts+13181) {
v2 = _sessionStat1Sql(tls, db, bp+8)
rc = v2
if v2 != 0 {
break
}
(**(**TSessionApplyCtx)(__ccgo_up(bp + 8))).FbStat1 = int32(1)
} else {
v2 = _sessionSelectRow(tls, db, **(**uintptr)(__ccgo_up(bp)), bp+8)
rc = v2
if v5 = v2 != 0; !v5 {
v3 = _sessionDeleteRow(tls, db, **(**uintptr)(__ccgo_up(bp)), bp+8)
rc = v3
}
if v7 = v5 || v3 != 0; !v7 {
v4 = _sessionInsertRow(tls, db, **(**uintptr)(__ccgo_up(bp)), bp+8)
rc = v4
}
if v7 || v4 != 0 {
break
}
(**(**TSessionApplyCtx)(__ccgo_up(bp + 8))).FbStat1 = 0
}
}
}
}
nTab = _sqlite3Strlen30(tls, **(**uintptr)(__ccgo_up(bp)))
}
}
/* If there is a schema mismatch on the current table, proceed to the
** next change. A log message has already been issued. */
if schemaMismatch != 0 {
continue
}
/* If this is a call to apply_v3(), invoke xFilterIter here. */
if __ccgo_fp_xFilterIter != 0 && 0 == (*(*func(*libc.TLS, uintptr, uintptr) int32)(unsafe.Pointer(&struct{ uintptr }{__ccgo_fp_xFilterIter})))(tls, pCtx, pIter) {
continue
}
rc = _sessionApplyOneWithRetry(tls, db, pIter, bp+8, __ccgo_fp_xConflict, pCtx)
}
bPatchset = (*Tsqlite3_changeset_iter)(unsafe.Pointer(pIter)).FbPatchset
if rc == SQLITE_OK {
rc = Xsqlite3changeset_finalize(tls, pIter)
} else {
Xsqlite3changeset_finalize(tls, pIter)
}
if rc == SQLITE_OK {
rc = _sessionRetryConstraints(tls, db, bPatchset, **(**uintptr)(__ccgo_up(bp)), bp+8, __ccgo_fp_xConflict, pCtx)
}
if rc == SQLITE_OK {
Xsqlite3_db_status(tls, db, int32(SQLITE_DBSTATUS_DEFERRED_FKS), bp+168, bp+172, 0)
if **(**int32)(__ccgo_up(bp + 168)) != 0 {
res = int32(SQLITE_CHANGESET_ABORT)
libc.X__builtin___memset_chk(tls, bp+176, 0, uint64(152), ^t__predefined_size_t(0))
(**(**Tsqlite3_changeset_iter)(__ccgo_up(bp + 176))).FnCol = **(**int32)(__ccgo_up(bp + 168))
res = (*(*func(*libc.TLS, uintptr, int32, uintptr) int32)(unsafe.Pointer(&struct{ uintptr }{__ccgo_fp_xConflict})))(tls, pCtx, int32(SQLITE_CHANGESET_FOREIGN_KEY), bp+176)
if res != SQLITE_CHANGESET_OMIT {
rc = int32(SQLITE_CONSTRAINT)
}
}
}
rc2 = Xsqlite3_exec(tls, db, __ccgo_ts+37137, 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+37167, uintptr(0), uintptr(0), uintptr(0))
}
if rc != SQLITE_OK {
Xsqlite3_exec(tls, db, __ccgo_ts+37191, uintptr(0), uintptr(0), uintptr(0))
Xsqlite3_exec(tls, db, __ccgo_ts+37167, uintptr(0), uintptr(0), uintptr(0))
}
}
if rc == SQLITE_OK && bPatchset == 0 && (**(**TSessionApplyCtx)(__ccgo_up(bp + 8))).FbRebase != 0 {
**(**uintptr)(__ccgo_up(ppRebase)) = (**(**TSessionApplyCtx)(__ccgo_up(bp + 8))).Frebase.FaBuf
**(**int32)(__ccgo_up(pnRebase)) = (**(**TSessionApplyCtx)(__ccgo_up(bp + 8))).Frebase.FnBuf
(**(**TSessionApplyCtx)(__ccgo_up(bp + 8))).Frebase.FaBuf = uintptr(0)
}
_sessionUpdateFree(tls, bp+8)
Xsqlite3_finalize(tls, (**(**TSessionApplyCtx)(__ccgo_up(bp + 8))).FpInsert)
Xsqlite3_finalize(tls, (**(**TSessionApplyCtx)(__ccgo_up(bp + 8))).FpDelete)
Xsqlite3_finalize(tls, (**(**TSessionApplyCtx)(__ccgo_up(bp + 8))).FpSelect)
Xsqlite3_free(tls, (**(**TSessionApplyCtx)(__ccgo_up(bp + 8))).FazCol) /* cast works around VC++ bug */
Xsqlite3_free(tls, (**(**TSessionApplyCtx)(__ccgo_up(bp + 8))).Fconstraints.FaBuf)
Xsqlite3_free(tls, (**(**TSessionApplyCtx)(__ccgo_up(bp + 8))).Frebase.FaBuf)
if flags&int32(SQLITE_CHANGESETAPPLY_FKNOACTION) != 0 && savedFlag == uint64(0) {
**(**Tu64)(__ccgo_up(db + 48)) &= ^(libc.Uint64FromInt32(libc.Int32FromInt32(0x00008)) << libc.Int32FromInt32(32))
**(**int32)(__ccgo_up((**(**TDb)(__ccgo_up((*Tsqlite3)(unsafe.Pointer(db)).FaDb))).FpSchema)) -= int32(32)
}
Xsqlite3_set_errmsg(tls, db, rc, (**(**TSessionApplyCtx)(__ccgo_up(bp + 8))).FzErr)
Xsqlite3_free(tls, (**(**TSessionApplyCtx)(__ccgo_up(bp + 8))).FzErr)
Xsqlite3_mutex_leave(tls, Xsqlite3_db_mutex(tls, db))
return rc
}
// C documentation
//
// /*
// ** Locate or create a SessionTable object that may be used to add the
// ** change currently pointed to by iterator pIter to changegroup pGrp.
// ** If successful, set output variable (*ppTab) to point to the table
// ** object and return SQLITE_OK. Otherwise, if some error occurs, return
// ** an SQLite error code and leave (*ppTab) set to NULL.
// */
func _sessionChangesetFindTable(tls *libc.TLS, pGrp uintptr, zTab uintptr, pIter uintptr, ppTab uintptr) (r int32) {
bp := tls.Alloc(16)
defer tls.Free(16)
var nTab, rc int32
var pTab, ppNew uintptr
var _ /* abPK at bp+0 */ uintptr
var _ /* nCol at bp+8 */ int32
_, _, _, _ = nTab, pTab, ppNew, rc
rc = SQLITE_OK
pTab = uintptr(0)
nTab = libc.Int32FromUint64(libc.Xstrlen(tls, zTab))
**(**uintptr)(__ccgo_up(bp)) = uintptr(0)
**(**int32)(__ccgo_up(bp + 8)) = 0
**(**uintptr)(__ccgo_up(ppTab)) = uintptr(0)
/* Search the list for an existing table */
pTab = (*Tsqlite3_changegroup)(unsafe.Pointer(pGrp)).FpList
for {
if !(pTab != 0) {
break
}
if 0 == Xsqlite3_strnicmp(tls, (*TSessionTable)(unsafe.Pointer(pTab)).FzName, zTab, nTab+int32(1)) {
break
}
goto _1
_1:
;
pTab = (*TSessionTable)(unsafe.Pointer(pTab)).FpNext
}
if pIter != 0 {
Xsqlite3changeset_pk(tls, pIter, bp, bp+8)
} else {
if !(pTab != 0) && !((*Tsqlite3_changegroup)(unsafe.Pointer(pGrp)).Fdb != 0) {
return SQLITE_OK
}
}
/* If one was not found above, create a new table now */
if !(pTab != 0) {
pTab = Xsqlite3_malloc64(tls, uint64(uint64(88)+libc.Uint64FromInt32(**(**int32)(__ccgo_up(bp + 8)))+libc.Uint64FromInt32(nTab)+uint64(1)))
if !(pTab != 0) {
return int32(SQLITE_NOMEM)
}
libc.X__builtin___memset_chk(tls, pTab, 0, uint64(88), ^t__predefined_size_t(0))
(*TSessionTable)(unsafe.Pointer(pTab)).FnCol = **(**int32)(__ccgo_up(bp + 8))
(*TSessionTable)(unsafe.Pointer(pTab)).FabPK = pTab + 1*88
if **(**int32)(__ccgo_up(bp + 8)) > 0 {
libc.X__builtin___memcpy_chk(tls, (*TSessionTable)(unsafe.Pointer(pTab)).FabPK, **(**uintptr)(__ccgo_up(bp)), libc.Uint64FromInt32(**(**int32)(__ccgo_up(bp + 8))), ^t__predefined_size_t(0))
}
(*TSessionTable)(unsafe.Pointer(pTab)).FzName = (*TSessionTable)(unsafe.Pointer(pTab)).FabPK + uintptr(**(**int32)(__ccgo_up(bp + 8)))
libc.X__builtin___memcpy_chk(tls, (*TSessionTable)(unsafe.Pointer(pTab)).FzName, zTab, libc.Uint64FromInt32(nTab+int32(1)), ^t__predefined_size_t(0))
if (*Tsqlite3_changegroup)(unsafe.Pointer(pGrp)).Fdb != 0 {
(*TSessionTable)(unsafe.Pointer(pTab)).FnCol = 0
rc = _sessionInitTable(tls, uintptr(0), pTab, (*Tsqlite3_changegroup)(unsafe.Pointer(pGrp)).Fdb, (*Tsqlite3_changegroup)(unsafe.Pointer(pGrp)).FzDb)
if rc != 0 || (*TSessionTable)(unsafe.Pointer(pTab)).FnCol == 0 {
Xsqlite3_free(tls, (*TSessionTable)(unsafe.Pointer(pTab)).FazCol)
Xsqlite3_free(tls, pTab)
return rc
}
}
/* The new object must be linked on to the end of the list, not
** simply added to the start of it. This is to ensure that the
** tables within the output of sqlite3changegroup_output() are in
** the right order. */
ppNew = pGrp + 8
for {
if !(**(**uintptr)(__ccgo_up(ppNew)) != 0) {
break
}
goto _2
_2:
;
ppNew = **(**uintptr)(__ccgo_up(ppNew))
}
**(**uintptr)(__ccgo_up(ppNew)) = pTab
}
/* Check that the table is compatible. */
if pIter != 0 && !(_sessionChangesetCheckCompat(tls, pTab, **(**int32)(__ccgo_up(bp + 8)), **(**uintptr)(__ccgo_up(bp))) != 0) {
rc = int32(SQLITE_SCHEMA)
}
**(**uintptr)(__ccgo_up(ppTab)) = pTab
return rc
}
func _sessionChangesetInvert(tls *libc.TLS, pInput uintptr, __ccgo_fp_xOutput uintptr, pOut uintptr, pnInverted uintptr, ppInverted uintptr) (r int32) {
bp := tls.Alloc(64)
defer tls.Free(64)
var abPK, apVal, pVal, pVal1, v7 uintptr
var bIndirect, eType2, iCol, nVar, v1 int32
var eType Tu8
var _ /* nByte at bp+48 */ int32
var _ /* nByte at bp+52 */ int32
var _ /* nCol at bp+24 */ int32
var _ /* rc at bp+0 */ int32
var _ /* sOut at bp+8 */ TSessionBuffer
var _ /* sPK at bp+32 */ TSessionBuffer
_, _, _, _, _, _, _, _, _, _, _ = abPK, apVal, bIndirect, eType, eType2, iCol, nVar, pVal, pVal1, v1, v7
**(**int32)(__ccgo_up(bp)) = SQLITE_OK /* Output buffer */
**(**int32)(__ccgo_up(bp + 24)) = 0 /* Number of cols in current table */
abPK = uintptr(0) /* PK array for current table */
apVal = uintptr(0) /* Space for values for UPDATE inversion */
**(**TSessionBuffer)(__ccgo_up(bp + 32)) = TSessionBuffer{} /* PK array for current table */
/* Initialize the output buffer */
libc.X__builtin___memset_chk(tls, bp+8, 0, uint64(16), ^t__predefined_size_t(0))
/* Zero the output variables in case an error occurs. */
if ppInverted != 0 {
**(**uintptr)(__ccgo_up(ppInverted)) = uintptr(0)
**(**int32)(__ccgo_up(pnInverted)) = 0
}
for int32(1) != 0 {
/* Test for EOF. */
v1 = _sessionInputBuffer(tls, pInput, int32(2))
**(**int32)(__ccgo_up(bp)) = v1
if v1 != 0 {
goto finished_invert
}
if (*TSessionInput)(unsafe.Pointer(pInput)).FiNext+int32(1) >= (*TSessionInput)(unsafe.Pointer(pInput)).FnData {
if (*TSessionInput)(unsafe.Pointer(pInput)).FiNext != (*TSessionInput)(unsafe.Pointer(pInput)).FnData {
**(**int32)(__ccgo_up(bp)) = _sqlite3CorruptError(tls, int32(237907))
goto finished_invert
}
break
}
eType = **(**Tu8)(__ccgo_up((*TSessionInput)(unsafe.Pointer(pInput)).FaData + uintptr((*TSessionInput)(unsafe.Pointer(pInput)).FiNext)))
switch libc.Int32FromUint8(eType) {
case int32('T'):
(*TSessionInput)(unsafe.Pointer(pInput)).FiNext = (*TSessionInput)(unsafe.Pointer(pInput)).FiNext + 1
v1 = _sessionChangesetBufferTblhdr(tls, pInput, bp+48)
**(**int32)(__ccgo_up(bp)) = v1
if v1 != 0 {
goto finished_invert
}
nVar = _sessionVarintGet(tls, (*TSessionInput)(unsafe.Pointer(pInput)).FaData+uintptr((*TSessionInput)(unsafe.Pointer(pInput)).FiNext), bp+24)
(**(**TSessionBuffer)(__ccgo_up(bp + 32))).FnBuf = 0
_sessionAppendBlob(tls, bp+32, (*TSessionInput)(unsafe.Pointer(pInput)).FaData+uintptr((*TSessionInput)(unsafe.Pointer(pInput)).FiNext+nVar), **(**int32)(__ccgo_up(bp + 24)), bp)
_sessionAppendByte(tls, bp+8, eType, bp)
_sessionAppendBlob(tls, bp+8, (*TSessionInput)(unsafe.Pointer(pInput)).FaData+uintptr((*TSessionInput)(unsafe.Pointer(pInput)).FiNext), **(**int32)(__ccgo_up(bp + 48)), bp)
if **(**int32)(__ccgo_up(bp)) != 0 {
goto finished_invert
}
**(**int32)(__ccgo_up(pInput + 8)) += **(**int32)(__ccgo_up(bp + 48))
Xsqlite3_free(tls, apVal)
apVal = uintptr(0)
abPK = (**(**TSessionBuffer)(__ccgo_up(bp + 32))).FaBuf
case int32(SQLITE_INSERT):
fallthrough
case int32(SQLITE_DELETE):
bIndirect = libc.Int32FromUint8(**(**Tu8)(__ccgo_up((*TSessionInput)(unsafe.Pointer(pInput)).FaData + uintptr((*TSessionInput)(unsafe.Pointer(pInput)).FiNext+int32(1)))))
if libc.Int32FromUint8(eType) == int32(SQLITE_DELETE) {
v1 = int32(SQLITE_INSERT)
} else {
v1 = int32(SQLITE_DELETE)
}
eType2 = v1
**(**int32)(__ccgo_up(pInput + 8)) += int32(2)
**(**int32)(__ccgo_up(bp)) = _sessionChangesetBufferRecord(tls, pInput, **(**int32)(__ccgo_up(bp + 24)), bp+52)
_sessionAppendByte(tls, bp+8, libc.Uint8FromInt32(eType2), bp)
_sessionAppendByte(tls, bp+8, libc.Uint8FromInt32(bIndirect), bp)
_sessionAppendBlob(tls, bp+8, (*TSessionInput)(unsafe.Pointer(pInput)).FaData+uintptr((*TSessionInput)(unsafe.Pointer(pInput)).FiNext), **(**int32)(__ccgo_up(bp + 52)), bp)
**(**int32)(__ccgo_up(pInput + 8)) += **(**int32)(__ccgo_up(bp + 52))
if **(**int32)(__ccgo_up(bp)) != 0 {
goto finished_invert
}
case int32(SQLITE_UPDATE):
if uintptr(0) == apVal {
apVal = Xsqlite3_malloc64(tls, uint64(uint64(8)*libc.Uint64FromInt32(**(**int32)(__ccgo_up(bp + 24)))*uint64(2)))
if uintptr(0) == apVal {
**(**int32)(__ccgo_up(bp)) = int32(SQLITE_NOMEM)
goto finished_invert
}
libc.X__builtin___memset_chk(tls, apVal, 0, uint64(8)*libc.Uint64FromInt32(**(**int32)(__ccgo_up(bp + 24)))*uint64(2), ^t__predefined_size_t(0))
}
/* Write the header for the new UPDATE change. Same as the original. */
_sessionAppendByte(tls, bp+8, eType, bp)
_sessionAppendByte(tls, bp+8, **(**Tu8)(__ccgo_up((*TSessionInput)(unsafe.Pointer(pInput)).FaData + uintptr((*TSessionInput)(unsafe.Pointer(pInput)).FiNext+int32(1)))), bp)
/* Read the old.* and new.* records for the update change. */
**(**int32)(__ccgo_up(pInput + 8)) += int32(2)
**(**int32)(__ccgo_up(bp)) = _sessionReadRecord(tls, pInput, **(**int32)(__ccgo_up(bp + 24)), uintptr(0), apVal, uintptr(0))
if **(**int32)(__ccgo_up(bp)) == SQLITE_OK {
**(**int32)(__ccgo_up(bp)) = _sessionReadRecord(tls, pInput, **(**int32)(__ccgo_up(bp + 24)), uintptr(0), apVal+uintptr(**(**int32)(__ccgo_up(bp + 24)))*8, uintptr(0))
}
/* Write the new old.* record. Consists of the PK columns from the
** original old.* record, and the other values from the original
** new.* record. */
iCol = 0
for {
if !(iCol < **(**int32)(__ccgo_up(bp + 24))) {
break
}
if **(**Tu8)(__ccgo_up(abPK + uintptr(iCol))) != 0 {
v1 = 0
} else {
v1 = **(**int32)(__ccgo_up(bp + 24))
}
pVal = **(**uintptr)(__ccgo_up(apVal + uintptr(iCol+v1)*8))
_sessionAppendValue(tls, bp+8, pVal, bp)
goto _4
_4:
;
iCol = iCol + 1
}
/* Write the new new.* record. Consists of a copy of all values
** from the original old.* record, except for the PK columns, which
** are set to "undefined". */
iCol = 0
for {
if !(iCol < **(**int32)(__ccgo_up(bp + 24))) {
break
}
if **(**Tu8)(__ccgo_up(abPK + uintptr(iCol))) != 0 {
v7 = uintptr(0)
} else {
v7 = **(**uintptr)(__ccgo_up(apVal + uintptr(iCol)*8))
}
pVal1 = v7
_sessionAppendValue(tls, bp+8, pVal1, bp)
goto _6
_6:
;
iCol = iCol + 1
}
iCol = 0
for {
if !(iCol < **(**int32)(__ccgo_up(bp + 24))*int32(2)) {
break
}
_sqlite3ValueFree(tls, **(**uintptr)(__ccgo_up(apVal + uintptr(iCol)*8)))
goto _8
_8:
;
iCol = iCol + 1
}
libc.X__builtin___memset_chk(tls, apVal, 0, uint64(8)*libc.Uint64FromInt32(**(**int32)(__ccgo_up(bp + 24)))*uint64(2), ^t__predefined_size_t(0))
if **(**int32)(__ccgo_up(bp)) != SQLITE_OK {
goto finished_invert
}
default:
**(**int32)(__ccgo_up(bp)) = _sqlite3CorruptError(tls, int32(238010))
goto finished_invert
}
if __ccgo_fp_xOutput != 0 && (**(**TSessionBuffer)(__ccgo_up(bp + 8))).FnBuf >= _sessions_strm_chunk_size {
**(**int32)(__ccgo_up(bp)) = (*(*func(*libc.TLS, uintptr, uintptr, int32) int32)(unsafe.Pointer(&struct{ uintptr }{__ccgo_fp_xOutput})))(tls, pOut, (**(**TSessionBuffer)(__ccgo_up(bp + 8))).FaBuf, (**(**TSessionBuffer)(__ccgo_up(bp + 8))).FnBuf)
(**(**TSessionBuffer)(__ccgo_up(bp + 8))).FnBuf = 0
if **(**int32)(__ccgo_up(bp)) != SQLITE_OK {
goto finished_invert
}
}
}
if pnInverted != 0 && ppInverted != 0 {
**(**int32)(__ccgo_up(pnInverted)) = (**(**TSessionBuffer)(__ccgo_up(bp + 8))).FnBuf
**(**uintptr)(__ccgo_up(ppInverted)) = (**(**TSessionBuffer)(__ccgo_up(bp + 8))).FaBuf
(**(**TSessionBuffer)(__ccgo_up(bp + 8))).FaBuf = uintptr(0)
} else {
if (**(**TSessionBuffer)(__ccgo_up(bp + 8))).FnBuf > 0 && __ccgo_fp_xOutput != uintptr(0) {
**(**int32)(__ccgo_up(bp)) = (*(*func(*libc.TLS, uintptr, uintptr, int32) int32)(unsafe.Pointer(&struct{ uintptr }{__ccgo_fp_xOutput})))(tls, pOut, (**(**TSessionBuffer)(__ccgo_up(bp + 8))).FaBuf, (**(**TSessionBuffer)(__ccgo_up(bp + 8))).FnBuf)
}
}
goto finished_invert
finished_invert:
;
Xsqlite3_free(tls, (**(**TSessionBuffer)(__ccgo_up(bp + 8))).FaBuf)
Xsqlite3_free(tls, apVal)
Xsqlite3_free(tls, (**(**TSessionBuffer)(__ccgo_up(bp + 32))).FaBuf)
return **(**int32)(__ccgo_up(bp))
}
// C documentation
//
// /*
// ** Advance the changeset iterator to the next change. The differences between
// ** this function and sessionChangesetNext() are that
// **
// ** * If pbEmpty is not NULL and the change is a no-op UPDATE (an UPDATE
// ** that modifies no columns), this function sets (*pbEmpty) to 1.
// **
// ** * If the iterator is configured to skip no-op UPDATEs,
// ** sessionChangesetNext() does that. This function does not.
// */
func _sessionChangesetNextOne(tls *libc.TLS, p uintptr, paRec uintptr, pnRec uintptr, pbNew uintptr, pbEmpty uintptr) (r int32) {
var abPK, apNew, apOld, v10, v3, v6 uintptr
var i, nVal, v2 int32
var op Tu8
_, _, _, _, _, _, _, _, _, _ = abPK, apNew, apOld, i, nVal, op, v10, v2, v3, v6
/* If the iterator is in the error-state, return immediately. */
if (*Tsqlite3_changeset_iter)(unsafe.Pointer(p)).Frc != SQLITE_OK {
return (*Tsqlite3_changeset_iter)(unsafe.Pointer(p)).Frc
}
/* Free the current contents of p->apValue[], if any. */
if (*Tsqlite3_changeset_iter)(unsafe.Pointer(p)).FapValue != 0 {
i = 0
for {
if !(i < (*Tsqlite3_changeset_iter)(unsafe.Pointer(p)).FnCol*int32(2)) {
break
}
_sqlite3ValueFree(tls, **(**uintptr)(__ccgo_up((*Tsqlite3_changeset_iter)(unsafe.Pointer(p)).FapValue + uintptr(i)*8)))
goto _1
_1:
;
i = i + 1
}
libc.X__builtin___memset_chk(tls, (*Tsqlite3_changeset_iter)(unsafe.Pointer(p)).FapValue, 0, uint64(8)*libc.Uint64FromInt32((*Tsqlite3_changeset_iter)(unsafe.Pointer(p)).FnCol)*uint64(2), ^t__predefined_size_t(0))
}
/* Make sure the buffer contains at least 2 bytes of input data, or all
** remaining data if there are less than 2 bytes available. This is
** sufficient either for the 'T' or 'P' byte that begins a new table,
** or for the "op" and "bIndirect" single bytes otherwise. */
(*Tsqlite3_changeset_iter)(unsafe.Pointer(p)).Frc = _sessionInputBuffer(tls, p, int32(2))
if (*Tsqlite3_changeset_iter)(unsafe.Pointer(p)).Frc != SQLITE_OK {
return (*Tsqlite3_changeset_iter)(unsafe.Pointer(p)).Frc
}
(*Tsqlite3_changeset_iter)(unsafe.Pointer(p)).Fin.FiCurrent = (*Tsqlite3_changeset_iter)(unsafe.Pointer(p)).Fin.FiNext
_sessionDiscardData(tls, p)
/* If the iterator is already at the end of the changeset, return DONE. */
if (*Tsqlite3_changeset_iter)(unsafe.Pointer(p)).Fin.FiNext >= (*Tsqlite3_changeset_iter)(unsafe.Pointer(p)).Fin.FnData {
return int32(SQLITE_DONE)
}
v3 = p + 8
v2 = *(*int32)(unsafe.Pointer(v3))
*(*int32)(unsafe.Pointer(v3)) = *(*int32)(unsafe.Pointer(v3)) + 1
op = **(**Tu8)(__ccgo_up((*Tsqlite3_changeset_iter)(unsafe.Pointer(p)).Fin.FaData + uintptr(v2)))
for libc.Int32FromUint8(op) == int32('T') || libc.Int32FromUint8(op) == int32('P') {
if pbNew != 0 {
**(**int32)(__ccgo_up(pbNew)) = int32(1)
}
(*Tsqlite3_changeset_iter)(unsafe.Pointer(p)).FbPatchset = libc.BoolInt32(libc.Int32FromUint8(op) == int32('P'))
if _sessionChangesetReadTblhdr(tls, p) != 0 {
return (*Tsqlite3_changeset_iter)(unsafe.Pointer(p)).Frc
}
v2 = _sessionInputBuffer(tls, p, int32(2))
(*Tsqlite3_changeset_iter)(unsafe.Pointer(p)).Frc = v2
if v2 != 0 {
return (*Tsqlite3_changeset_iter)(unsafe.Pointer(p)).Frc
}
(*Tsqlite3_changeset_iter)(unsafe.Pointer(p)).Fin.FiCurrent = (*Tsqlite3_changeset_iter)(unsafe.Pointer(p)).Fin.FiNext
if (*Tsqlite3_changeset_iter)(unsafe.Pointer(p)).Fin.FiNext >= (*Tsqlite3_changeset_iter)(unsafe.Pointer(p)).Fin.FnData {
return int32(SQLITE_DONE)
}
v3 = p + 8
v2 = *(*int32)(unsafe.Pointer(v3))
*(*int32)(unsafe.Pointer(v3)) = *(*int32)(unsafe.Pointer(v3)) + 1
op = **(**Tu8)(__ccgo_up((*Tsqlite3_changeset_iter)(unsafe.Pointer(p)).Fin.FaData + uintptr(v2)))
}
if (*Tsqlite3_changeset_iter)(unsafe.Pointer(p)).FzTab == uintptr(0) || (*Tsqlite3_changeset_iter)(unsafe.Pointer(p)).FbPatchset != 0 && (*Tsqlite3_changeset_iter)(unsafe.Pointer(p)).FbInvert != 0 {
/* The first record in the changeset is not a table header. Must be a
** corrupt changeset. */
v2 = _sqlite3CorruptError(tls, int32(237587))
(*Tsqlite3_changeset_iter)(unsafe.Pointer(p)).Frc = v2
return v2
}
if libc.Int32FromUint8(op) != int32(SQLITE_UPDATE) && libc.Int32FromUint8(op) != int32(SQLITE_DELETE) && libc.Int32FromUint8(op) != int32(SQLITE_INSERT) || (*Tsqlite3_changeset_iter)(unsafe.Pointer(p)).Fin.FiNext >= (*Tsqlite3_changeset_iter)(unsafe.Pointer(p)).Fin.FnData {
v2 = _sqlite3CorruptError(tls, int32(237593))
(*Tsqlite3_changeset_iter)(unsafe.Pointer(p)).Frc = v2
return v2
}
(*Tsqlite3_changeset_iter)(unsafe.Pointer(p)).Fop = libc.Int32FromUint8(op)
v3 = p + 8
v2 = *(*int32)(unsafe.Pointer(v3))
*(*int32)(unsafe.Pointer(v3)) = *(*int32)(unsafe.Pointer(v3)) + 1
(*Tsqlite3_changeset_iter)(unsafe.Pointer(p)).FbIndirect = libc.Int32FromUint8(**(**Tu8)(__ccgo_up((*Tsqlite3_changeset_iter)(unsafe.Pointer(p)).Fin.FaData + uintptr(v2))))
if paRec != 0 { /* Number of values to buffer */
if (*Tsqlite3_changeset_iter)(unsafe.Pointer(p)).FbPatchset == 0 && libc.Int32FromUint8(op) == int32(SQLITE_UPDATE) {
nVal = (*Tsqlite3_changeset_iter)(unsafe.Pointer(p)).FnCol * int32(2)
} else {
if (*Tsqlite3_changeset_iter)(unsafe.Pointer(p)).FbPatchset != 0 && libc.Int32FromUint8(op) == int32(SQLITE_DELETE) {
nVal = 0
i = 0
for {
if !(i < (*Tsqlite3_changeset_iter)(unsafe.Pointer(p)).FnCol) {
break
}
if **(**Tu8)(__ccgo_up((*Tsqlite3_changeset_iter)(unsafe.Pointer(p)).FabPK + uintptr(i))) != 0 {
nVal = nVal + 1
}
goto _11
_11:
;
i = i + 1
}
} else {
nVal = (*Tsqlite3_changeset_iter)(unsafe.Pointer(p)).FnCol
}
}
(*Tsqlite3_changeset_iter)(unsafe.Pointer(p)).Frc = _sessionChangesetBufferRecord(tls, p, nVal, pnRec)
if (*Tsqlite3_changeset_iter)(unsafe.Pointer(p)).Frc != SQLITE_OK {
return (*Tsqlite3_changeset_iter)(unsafe.Pointer(p)).Frc
}
**(**uintptr)(__ccgo_up(paRec)) = (*Tsqlite3_changeset_iter)(unsafe.Pointer(p)).Fin.FaData + uintptr((*Tsqlite3_changeset_iter)(unsafe.Pointer(p)).Fin.FiNext)
(*Tsqlite3_changeset_iter)(unsafe.Pointer(p)).Fin.FiNext += **(**int32)(__ccgo_up(pnRec))
} else {
if (*Tsqlite3_changeset_iter)(unsafe.Pointer(p)).FbInvert != 0 {
v3 = (*Tsqlite3_changeset_iter)(unsafe.Pointer(p)).FapValue + uintptr((*Tsqlite3_changeset_iter)(unsafe.Pointer(p)).FnCol)*8
} else {
v3 = (*Tsqlite3_changeset_iter)(unsafe.Pointer(p)).FapValue
}
apOld = v3
if (*Tsqlite3_changeset_iter)(unsafe.Pointer(p)).FbInvert != 0 {
v6 = (*Tsqlite3_changeset_iter)(unsafe.Pointer(p)).FapValue
} else {
v6 = (*Tsqlite3_changeset_iter)(unsafe.Pointer(p)).FapValue + uintptr((*Tsqlite3_changeset_iter)(unsafe.Pointer(p)).FnCol)*8
}
apNew = v6
/* If this is an UPDATE or DELETE, read the old.* record. */
if (*Tsqlite3_changeset_iter)(unsafe.Pointer(p)).Fop != int32(SQLITE_INSERT) && ((*Tsqlite3_changeset_iter)(unsafe.Pointer(p)).FbPatchset == 0 || (*Tsqlite3_changeset_iter)(unsafe.Pointer(p)).Fop == int32(SQLITE_DELETE)) {
if (*Tsqlite3_changeset_iter)(unsafe.Pointer(p)).FbPatchset != 0 {
v10 = (*Tsqlite3_changeset_iter)(unsafe.Pointer(p)).FabPK
} else {
v10 = uintptr(0)
}
abPK = v10
(*Tsqlite3_changeset_iter)(unsafe.Pointer(p)).Frc = _sessionReadRecord(tls, p, (*Tsqlite3_changeset_iter)(unsafe.Pointer(p)).FnCol, abPK, apOld, uintptr(0))
if (*Tsqlite3_changeset_iter)(unsafe.Pointer(p)).Frc != SQLITE_OK {
return (*Tsqlite3_changeset_iter)(unsafe.Pointer(p)).Frc
}
}
/* If this is an INSERT or UPDATE, read the new.* record. */
if (*Tsqlite3_changeset_iter)(unsafe.Pointer(p)).Fop != int32(SQLITE_DELETE) {
(*Tsqlite3_changeset_iter)(unsafe.Pointer(p)).Frc = _sessionReadRecord(tls, p, (*Tsqlite3_changeset_iter)(unsafe.Pointer(p)).FnCol, uintptr(0), apNew, pbEmpty)
if (*Tsqlite3_changeset_iter)(unsafe.Pointer(p)).Frc != SQLITE_OK {
return (*Tsqlite3_changeset_iter)(unsafe.Pointer(p)).Frc
}
}
if ((*Tsqlite3_changeset_iter)(unsafe.Pointer(p)).FbPatchset != 0 || (*Tsqlite3_changeset_iter)(unsafe.Pointer(p)).FbInvert != 0) && (*Tsqlite3_changeset_iter)(unsafe.Pointer(p)).Fop == int32(SQLITE_UPDATE) {
/* If this is an UPDATE that is part of a patchset, then all PK and
** modified fields are present in the new.* record. The old.* record
** is currently completely empty. This block shifts the PK fields from
** new.* to old.*, to accommodate the code that reads these arrays. */
i = 0
for {
if !(i < (*Tsqlite3_changeset_iter)(unsafe.Pointer(p)).FnCol) {
break
}
if **(**Tu8)(__ccgo_up((*Tsqlite3_changeset_iter)(unsafe.Pointer(p)).FabPK + uintptr(i))) != 0 {
**(**uintptr)(__ccgo_up((*Tsqlite3_changeset_iter)(unsafe.Pointer(p)).FapValue + uintptr(i)*8)) = **(**uintptr)(__ccgo_up((*Tsqlite3_changeset_iter)(unsafe.Pointer(p)).FapValue + uintptr(i+(*Tsqlite3_changeset_iter)(unsafe.Pointer(p)).FnCol)*8))
if **(**uintptr)(__ccgo_up((*Tsqlite3_changeset_iter)(unsafe.Pointer(p)).FapValue + uintptr(i)*8)) == uintptr(0) {
v2 = _sqlite3CorruptError(tls, int32(237639))
(*Tsqlite3_changeset_iter)(unsafe.Pointer(p)).Frc = v2
return v2
}
**(**uintptr)(__ccgo_up((*Tsqlite3_changeset_iter)(unsafe.Pointer(p)).FapValue + uintptr(i+(*Tsqlite3_changeset_iter)(unsafe.Pointer(p)).FnCol)*8)) = uintptr(0)
}
goto _15
_15:
;
i = i + 1
}
} else {
if (*Tsqlite3_changeset_iter)(unsafe.Pointer(p)).FbInvert != 0 {
if (*Tsqlite3_changeset_iter)(unsafe.Pointer(p)).Fop == int32(SQLITE_INSERT) {
(*Tsqlite3_changeset_iter)(unsafe.Pointer(p)).Fop = int32(SQLITE_DELETE)
} else {
if (*Tsqlite3_changeset_iter)(unsafe.Pointer(p)).Fop == int32(SQLITE_DELETE) {
(*Tsqlite3_changeset_iter)(unsafe.Pointer(p)).Fop = int32(SQLITE_INSERT)
}
}
}
}
/* If this is an UPDATE that is part of a changeset, then check that
** there are no fields in the old.* record that are not (a) PK fields,
** or (b) also present in the new.* record.
**
** Such records are technically corrupt, but the rebaser was at one
** point generating them. Under most circumstances this is benign, but
** can cause spurious SQLITE_RANGE errors when applying the changeset. */
if (*Tsqlite3_changeset_iter)(unsafe.Pointer(p)).FbPatchset == 0 && (*Tsqlite3_changeset_iter)(unsafe.Pointer(p)).Fop == int32(SQLITE_UPDATE) {
i = 0
for {
if !(i < (*Tsqlite3_changeset_iter)(unsafe.Pointer(p)).FnCol) {
break
}
if libc.Int32FromUint8(**(**Tu8)(__ccgo_up((*Tsqlite3_changeset_iter)(unsafe.Pointer(p)).FabPK + uintptr(i)))) == 0 && **(**uintptr)(__ccgo_up((*Tsqlite3_changeset_iter)(unsafe.Pointer(p)).FapValue + uintptr(i+(*Tsqlite3_changeset_iter)(unsafe.Pointer(p)).FnCol)*8)) == uintptr(0) {
_sqlite3ValueFree(tls, **(**uintptr)(__ccgo_up((*Tsqlite3_changeset_iter)(unsafe.Pointer(p)).FapValue + uintptr(i)*8)))
**(**uintptr)(__ccgo_up((*Tsqlite3_changeset_iter)(unsafe.Pointer(p)).FapValue + uintptr(i)*8)) = uintptr(0)
}
goto _17
_17:
;
i = i + 1
}
}
}
return int32(SQLITE_ROW)
}
// C documentation
//
// /*
// ** The input pointer currently points to the second byte of a table-header.
// ** Specifically, to the following:
// **
// ** + number of columns in table (varint)
// ** + array of PK flags (1 byte per column),
// ** + table name (nul terminated).
// **
// ** This function decodes the table-header and populates the p->nCol,
// ** p->zTab and p->abPK[] variables accordingly. The p->apValue[] array is
// ** also allocated or resized according to the new value of p->nCol. The
// ** input pointer is left pointing to the byte following the table header.
// **
// ** If successful, SQLITE_OK is returned. Otherwise, an SQLite error code
// ** is returned and the final values of the various fields enumerated above
// ** are undefined.
// */
func _sessionChangesetReadTblhdr(tls *libc.TLS, p uintptr) (r int32) {
bp := tls.Alloc(16)
defer tls.Free(16)
var iPK Tsize_t
var nByte, nVarint, v2 int32
var v1 uintptr
var _ /* nCopy at bp+4 */ int32
var _ /* rc at bp+0 */ int32
_, _, _, _, _ = iPK, nByte, nVarint, v1, v2
**(**int32)(__ccgo_up(bp)) = _sessionChangesetBufferTblhdr(tls, p, bp+4)
if **(**int32)(__ccgo_up(bp)) == SQLITE_OK {
nVarint = _sessionVarintGet(tls, (*Tsqlite3_changeset_iter)(unsafe.Pointer(p)).Fin.FaData+uintptr((*Tsqlite3_changeset_iter)(unsafe.Pointer(p)).Fin.FiNext), p+120)
if (*Tsqlite3_changeset_iter)(unsafe.Pointer(p)).FnCol > 0 {
**(**int32)(__ccgo_up(bp + 4)) = **(**int32)(__ccgo_up(bp + 4)) - nVarint
(*Tsqlite3_changeset_iter)(unsafe.Pointer(p)).Fin.FiNext += nVarint
nByte = libc.Int32FromUint64(libc.Uint64FromInt32((*Tsqlite3_changeset_iter)(unsafe.Pointer(p)).FnCol)*uint64(8)*uint64(2) + libc.Uint64FromInt32(**(**int32)(__ccgo_up(bp + 4))))
(*Tsqlite3_changeset_iter)(unsafe.Pointer(p)).Ftblhdr.FnBuf = 0
_sessionBufferGrow(tls, p+72, int64(nByte), bp)
} else {
**(**int32)(__ccgo_up(bp)) = _sqlite3CorruptError(tls, int32(237501))
}
}
if **(**int32)(__ccgo_up(bp)) == SQLITE_OK {
iPK = uint64(8) * libc.Uint64FromInt32((*Tsqlite3_changeset_iter)(unsafe.Pointer(p)).FnCol) * uint64(2)
libc.X__builtin___memset_chk(tls, (*Tsqlite3_changeset_iter)(unsafe.Pointer(p)).Ftblhdr.FaBuf, 0, iPK, ^t__predefined_size_t(0))
libc.X__builtin___memcpy_chk(tls, (*Tsqlite3_changeset_iter)(unsafe.Pointer(p)).Ftblhdr.FaBuf+uintptr(iPK), (*Tsqlite3_changeset_iter)(unsafe.Pointer(p)).Fin.FaData+uintptr((*Tsqlite3_changeset_iter)(unsafe.Pointer(p)).Fin.FiNext), libc.Uint64FromInt32(**(**int32)(__ccgo_up(bp + 4))), ^t__predefined_size_t(0))
(*Tsqlite3_changeset_iter)(unsafe.Pointer(p)).Fin.FiNext += **(**int32)(__ccgo_up(bp + 4))
}
(*Tsqlite3_changeset_iter)(unsafe.Pointer(p)).FapValue = (*Tsqlite3_changeset_iter)(unsafe.Pointer(p)).Ftblhdr.FaBuf
if (*Tsqlite3_changeset_iter)(unsafe.Pointer(p)).FapValue == uintptr(0) {
(*Tsqlite3_changeset_iter)(unsafe.Pointer(p)).FabPK = uintptr(0)
(*Tsqlite3_changeset_iter)(unsafe.Pointer(p)).FzTab = uintptr(0)
} else {
(*Tsqlite3_changeset_iter)(unsafe.Pointer(p)).FabPK = (*Tsqlite3_changeset_iter)(unsafe.Pointer(p)).FapValue + uintptr((*Tsqlite3_changeset_iter)(unsafe.Pointer(p)).FnCol*int32(2))*8
if (*Tsqlite3_changeset_iter)(unsafe.Pointer(p)).FabPK != 0 {
v1 = (*Tsqlite3_changeset_iter)(unsafe.Pointer(p)).FabPK + uintptr((*Tsqlite3_changeset_iter)(unsafe.Pointer(p)).FnCol)
} else {
v1 = uintptr(0)
}
(*Tsqlite3_changeset_iter)(unsafe.Pointer(p)).FzTab = v1
}
v2 = **(**int32)(__ccgo_up(bp))
(*Tsqlite3_changeset_iter)(unsafe.Pointer(p)).Frc = v2
return v2
}
// C documentation
//
// /*
// ** Do the work for either sqlite3changeset_start() or start_strm().
// */
func _sessionChangesetStart(tls *libc.TLS, pp uintptr, __ccgo_fp_xInput uintptr, pIn uintptr, nChangeset int32, pChangeset uintptr, bInvert int32, bSkipEmpty int32) (r int32) {
var nByte, v1 int32
var pRet uintptr
_, _, _ = nByte, pRet, v1 /* Number of bytes to allocate for iterator */
/* Zero the output variable in case an error occurs. */
**(**uintptr)(__ccgo_up(pp)) = uintptr(0)
/* Allocate and initialize the iterator structure. */
nByte = int32(152)
pRet = Xsqlite3_malloc(tls, nByte)
if !(pRet != 0) {
return int32(SQLITE_NOMEM)
}
libc.X__builtin___memset_chk(tls, pRet, 0, uint64(152), ^t__predefined_size_t(0))
(*Tsqlite3_changeset_iter)(unsafe.Pointer(pRet)).Fin.FaData = pChangeset
(*Tsqlite3_changeset_iter)(unsafe.Pointer(pRet)).Fin.FnData = nChangeset
(*Tsqlite3_changeset_iter)(unsafe.Pointer(pRet)).Fin.FxInput = __ccgo_fp_xInput
(*Tsqlite3_changeset_iter)(unsafe.Pointer(pRet)).Fin.FpIn = pIn
if __ccgo_fp_xInput != 0 {
v1 = 0
} else {
v1 = int32(1)
}
(*Tsqlite3_changeset_iter)(unsafe.Pointer(pRet)).Fin.FbEof = v1
(*Tsqlite3_changeset_iter)(unsafe.Pointer(pRet)).FbInvert = bInvert
(*Tsqlite3_changeset_iter)(unsafe.Pointer(pRet)).FbSkipEmpty = bSkipEmpty
/* Populate the output variable and return success. */
**(**uintptr)(__ccgo_up(pp)) = pRet
return SQLITE_OK
}
// C documentation
//
// /*
// ** Formulate a statement to DELETE a row from database db. Assuming a table
// ** structure like this:
// **
// ** CREATE TABLE x(a, b, c, d, PRIMARY KEY(a, c));
// **
// ** The DELETE statement looks like this:
// **
// ** DELETE FROM x WHERE a = :1 AND c = :3 AND (:5 OR b IS :2 AND d IS :4)
// **
// ** Variable :5 (nCol+1) is a boolean. It should be set to 0 if we require
// ** matching b and d values, or 1 otherwise. The second case comes up if the
// ** conflict handler is invoked with NOTFOUND and returns CHANGESET_REPLACE.
// **
// ** If successful, SQLITE_OK is returned and SessionApplyCtx.pDelete is left
// ** pointing to the prepared version of the SQL statement.
// */
func _sessionDeleteRow(tls *libc.TLS, db uintptr, zTab uintptr, p uintptr) (r int32) {
bp := tls.Alloc(32)
defer tls.Free(32)
var i, nPk int32
var zSep uintptr
var _ /* buf at bp+8 */ TSessionBuffer
var _ /* rc at bp+0 */ int32
_, _, _ = i, nPk, zSep
zSep = __ccgo_ts + 1702
**(**int32)(__ccgo_up(bp)) = SQLITE_OK
**(**TSessionBuffer)(__ccgo_up(bp + 8)) = TSessionBuffer{}
nPk = 0
_sessionAppendStr(tls, bp+8, __ccgo_ts+36395, bp)
_sessionAppendIdent(tls, bp+8, zTab, bp)
_sessionAppendStr(tls, bp+8, __ccgo_ts+36306, bp)
i = 0
for {
if !(i < (*TSessionApplyCtx)(unsafe.Pointer(p)).FnCol) {
break
}
if **(**Tu8)(__ccgo_up((*TSessionApplyCtx)(unsafe.Pointer(p)).FabPK + uintptr(i))) != 0 {
nPk = nPk + 1
_sessionAppendStr(tls, bp+8, zSep, bp)
_sessionAppendIdent(tls, bp+8, **(**uintptr)(__ccgo_up((*TSessionApplyCtx)(unsafe.Pointer(p)).FazCol + uintptr(i)*8)), bp)
_sessionAppendStr(tls, bp+8, __ccgo_ts+36301, bp)
_sessionAppendInteger(tls, bp+8, i+int32(1), bp)
zSep = __ccgo_ts + 24020
}
goto _1
_1:
;
i = i + 1
}
if nPk < (*TSessionApplyCtx)(unsafe.Pointer(p)).FnCol {
_sessionAppendStr(tls, bp+8, __ccgo_ts+36413, bp)
_sessionAppendInteger(tls, bp+8, (*TSessionApplyCtx)(unsafe.Pointer(p)).FnCol+int32(1), bp)
_sessionAppendStr(tls, bp+8, __ccgo_ts+35825, bp)
zSep = __ccgo_ts + 1702
i = 0
for {
if !(i < (*TSessionApplyCtx)(unsafe.Pointer(p)).FnCol) {
break
}
if !(**(**Tu8)(__ccgo_up((*TSessionApplyCtx)(unsafe.Pointer(p)).FabPK + uintptr(i))) != 0) {
_sessionAppendStr(tls, bp+8, zSep, bp)
_sessionAppendIdent(tls, bp+8, **(**uintptr)(__ccgo_up((*TSessionApplyCtx)(unsafe.Pointer(p)).FazCol + uintptr(i)*8)), bp)
_sessionAppendStr(tls, bp+8, __ccgo_ts+36389, bp)
_sessionAppendInteger(tls, bp+8, i+int32(1), bp)
zSep = __ccgo_ts + 36421
}
goto _2
_2:
;
i = i + 1
}
_sessionAppendStr(tls, bp+8, __ccgo_ts+5605, bp)
}
if **(**int32)(__ccgo_up(bp)) == SQLITE_OK {
**(**int32)(__ccgo_up(bp)) = _sessionPrepare(tls, db, p+8, p+128, (**(**TSessionBuffer)(__ccgo_up(bp + 8))).FaBuf)
}
Xsqlite3_free(tls, (**(**TSessionBuffer)(__ccgo_up(bp + 8))).FaBuf)
return **(**int32)(__ccgo_up(bp))
}
func _sessionDiffFindModified(tls *libc.TLS, pSession uintptr, pTab uintptr, zFrom uintptr, zExpr uintptr) (r int32) {
bp := tls.Alloc(80)
defer tls.Free(80)
var iRowid Ti64
var pDiffCtx, z1, z2, zExpr2, zStmt uintptr
var rc int32
var v1 int64
var _ /* pStmt at bp+0 */ uintptr
_, _, _, _, _, _, _, _ = iRowid, pDiffCtx, rc, z1, z2, zExpr2, zStmt, v1
rc = SQLITE_OK
zExpr2 = _sessionExprCompareOther(tls, (*TSessionTable)(unsafe.Pointer(pTab)).FnCol, (*Tsqlite3_session)(unsafe.Pointer(pSession)).FzDb, zFrom, (*TSessionTable)(unsafe.Pointer(pTab)).FzName, (*TSessionTable)(unsafe.Pointer(pTab)).FazCol, (*TSessionTable)(unsafe.Pointer(pTab)).FabPK)
if zExpr2 == uintptr(0) {
rc = int32(SQLITE_NOMEM)
} else {
z1 = _sessionAllCols(tls, (*Tsqlite3_session)(unsafe.Pointer(pSession)).FzDb, pTab)
z2 = _sessionAllCols(tls, zFrom, pTab)
zStmt = Xsqlite3_mprintf(tls, __ccgo_ts+35939, libc.VaList(bp+16, z1, z2, (*Tsqlite3_session)(unsafe.Pointer(pSession)).FzDb, (*TSessionTable)(unsafe.Pointer(pTab)).FzName, zFrom, (*TSessionTable)(unsafe.Pointer(pTab)).FzName, zExpr, zExpr2))
if zStmt == uintptr(0) || z1 == uintptr(0) || z2 == uintptr(0) {
rc = int32(SQLITE_NOMEM)
} else {
rc = Xsqlite3_prepare_v2(tls, (*Tsqlite3_session)(unsafe.Pointer(pSession)).Fdb, zStmt, -int32(1), bp, uintptr(0))
if rc == SQLITE_OK {
pDiffCtx = (*Tsqlite3_session)(unsafe.Pointer(pSession)).Fhook.FpCtx
(*TSessionDiffCtx)(unsafe.Pointer(pDiffCtx)).FpStmt = **(**uintptr)(__ccgo_up(bp))
(*TSessionDiffCtx)(unsafe.Pointer(pDiffCtx)).FnOldOff = (*TSessionTable)(unsafe.Pointer(pTab)).FnCol
for int32(SQLITE_ROW) == Xsqlite3_step(tls, **(**uintptr)(__ccgo_up(bp))) {
if (*TSessionTable)(unsafe.Pointer(pTab)).FbRowid != 0 {
v1 = Xsqlite3_column_int64(tls, **(**uintptr)(__ccgo_up(bp)), 0)
} else {
v1 = 0
}
iRowid = v1
_sessionPreupdateOneChange(tls, int32(SQLITE_UPDATE), iRowid, pSession, pTab)
}
rc = Xsqlite3_finalize(tls, **(**uintptr)(__ccgo_up(bp)))
}
}
Xsqlite3_free(tls, zStmt)
Xsqlite3_free(tls, z1)
Xsqlite3_free(tls, z2)
}
return rc
}
// C documentation
//
// /*
// ** If the SessionInput object passed as the only argument is a streaming
// ** object and the buffer is full, discard some data to free up space.
// */
func _sessionDiscardData(tls *libc.TLS, pIn uintptr) {
var nMove int32
_ = nMove
if (*TSessionInput)(unsafe.Pointer(pIn)).FxInput != 0 && (*TSessionInput)(unsafe.Pointer(pIn)).FiCurrent >= _sessions_strm_chunk_size {
nMove = (*TSessionInput)(unsafe.Pointer(pIn)).Fbuf.FnBuf - (*TSessionInput)(unsafe.Pointer(pIn)).FiCurrent
if nMove > 0 {
libc.X__builtin___memmove_chk(tls, (*TSessionInput)(unsafe.Pointer(pIn)).Fbuf.FaBuf, (*TSessionInput)(unsafe.Pointer(pIn)).Fbuf.FaBuf+uintptr((*TSessionInput)(unsafe.Pointer(pIn)).FiCurrent), libc.Uint64FromInt32(nMove), ^t__predefined_size_t(0))
}
(*TSessionInput)(unsafe.Pointer(pIn)).Fbuf.FnBuf -= (*TSessionInput)(unsafe.Pointer(pIn)).FiCurrent
**(**int32)(__ccgo_up(pIn + 8)) -= (*TSessionInput)(unsafe.Pointer(pIn)).FiCurrent
(*TSessionInput)(unsafe.Pointer(pIn)).FiCurrent = 0
(*TSessionInput)(unsafe.Pointer(pIn)).FnData = (*TSessionInput)(unsafe.Pointer(pIn)).Fbuf.FnBuf
}
}
func _sessionExprCompareOther(tls *libc.TLS, nCol int32, zDb1 uintptr, zDb2 uintptr, zTab uintptr, azCol uintptr, abPK uintptr) (r uintptr) {
bp := tls.Alloc(80)
defer tls.Free(80)
var bHave, i int32
var zRet, zSep uintptr
_, _, _, _ = bHave, i, zRet, zSep
zSep = __ccgo_ts + 1702
zRet = uintptr(0)
bHave = 0
i = 0
for {
if !(i < nCol) {
break
}
if libc.Int32FromUint8(**(**Tu8)(__ccgo_up(abPK + uintptr(i)))) == 0 {
bHave = int32(1)
zRet = Xsqlite3_mprintf(tls, __ccgo_ts+35784, libc.VaList(bp+8, zRet, zSep, zDb1, zTab, **(**uintptr)(__ccgo_up(azCol + uintptr(i)*8)), zDb2, zTab, **(**uintptr)(__ccgo_up(azCol + uintptr(i)*8))))
zSep = __ccgo_ts + 35825
if zRet == uintptr(0) {
break
}
}
goto _1
_1:
;
i = i + 1
}
if bHave == 0 {
zRet = Xsqlite3_mprintf(tls, __ccgo_ts+1848, 0)
}
return zRet
}
func _sessionExprComparePK(tls *libc.TLS, nCol int32, zDb1 uintptr, zDb2 uintptr, zTab uintptr, azCol uintptr, abPK uintptr) (r uintptr) {
bp := tls.Alloc(80)
defer tls.Free(80)
var i int32
var zRet, zSep uintptr
_, _, _ = i, zRet, zSep
zSep = __ccgo_ts + 1702
zRet = uintptr(0)
i = 0
for {
if !(i < nCol) {
break
}
if **(**Tu8)(__ccgo_up(abPK + uintptr(i))) != 0 {
zRet = Xsqlite3_mprintf(tls, __ccgo_ts+35750, libc.VaList(bp+8, zRet, zSep, zDb1, zTab, **(**uintptr)(__ccgo_up(azCol + uintptr(i)*8)), zDb2, zTab, **(**uintptr)(__ccgo_up(azCol + uintptr(i)*8))))
zSep = __ccgo_ts + 24020
if zRet == uintptr(0) {
break
}
}
goto _1
_1:
;
i = i + 1
}
return zRet
}
// C documentation
//
// /*
// ** Generate either a changeset (if argument bPatchset is zero) or a patchset
// ** (if it is non-zero) based on the current contents of the session object
// ** passed as the first argument.
// **
// ** If no error occurs, SQLITE_OK is returned and the new changeset/patchset
// ** stored in output variables *pnChangeset and *ppChangeset. Or, if an error
// ** occurs, an SQLite error code is returned and both output variables set
// ** to 0.
// */
func _sessionGenerateChangeset(tls *libc.TLS, pSession uintptr, bPatchset int32, __ccgo_fp_xOutput uintptr, pOut uintptr, pnChangeset uintptr, ppChangeset uintptr) (r int32) {
bp := tls.Alloc(32)
defer tls.Free(32)
var db, p, pTab, zName uintptr
var i, iCol, nNoop, nOldCol, nRewind int32
var _ /* buf at bp+0 */ TSessionBuffer
var _ /* pSel at bp+24 */ uintptr
var _ /* rc at bp+16 */ int32
_, _, _, _, _, _, _, _, _ = db, i, iCol, nNoop, nOldCol, nRewind, p, pTab, zName
db = (*Tsqlite3_session)(unsafe.Pointer(pSession)).Fdb /* Used to iterate through attached tables */
**(**TSessionBuffer)(__ccgo_up(bp)) = TSessionBuffer{} /* Return code */
/* Zero the output variables in case an error occurs. If this session
** object is already in the error state (sqlite3_session.rc != SQLITE_OK),
** this call will be a no-op. */
if __ccgo_fp_xOutput == uintptr(0) {
**(**int32)(__ccgo_up(pnChangeset)) = 0
**(**uintptr)(__ccgo_up(ppChangeset)) = uintptr(0)
}
if (*Tsqlite3_session)(unsafe.Pointer(pSession)).Frc != 0 {
return (*Tsqlite3_session)(unsafe.Pointer(pSession)).Frc
}
Xsqlite3_mutex_enter(tls, Xsqlite3_db_mutex(tls, db))
**(**int32)(__ccgo_up(bp + 16)) = Xsqlite3_exec(tls, (*Tsqlite3_session)(unsafe.Pointer(pSession)).Fdb, __ccgo_ts+36244, uintptr(0), uintptr(0), uintptr(0))
if **(**int32)(__ccgo_up(bp + 16)) != SQLITE_OK {
Xsqlite3_mutex_leave(tls, Xsqlite3_db_mutex(tls, db))
return **(**int32)(__ccgo_up(bp + 16))
}
pTab = (*Tsqlite3_session)(unsafe.Pointer(pSession)).FpTable
for {
if !(**(**int32)(__ccgo_up(bp + 16)) == SQLITE_OK && pTab != 0) {
break
}
if (*TSessionTable)(unsafe.Pointer(pTab)).FnEntry != 0 {
zName = (*TSessionTable)(unsafe.Pointer(pTab)).FzName /* Used to iterate through hash buckets */
**(**uintptr)(__ccgo_up(bp + 24)) = uintptr(0) /* SELECT statement to query table pTab */
nRewind = (**(**TSessionBuffer)(__ccgo_up(bp))).FnBuf /* Size of buffer after writing tbl header */
nOldCol = (*TSessionTable)(unsafe.Pointer(pTab)).FnCol
/* Check the table schema is still Ok. */
**(**int32)(__ccgo_up(bp + 16)) = _sessionReinitTable(tls, pSession, pTab)
if **(**int32)(__ccgo_up(bp + 16)) == SQLITE_OK && (*TSessionTable)(unsafe.Pointer(pTab)).FnCol != nOldCol {
**(**int32)(__ccgo_up(bp + 16)) = _sessionUpdateChanges(tls, pSession, pTab)
}
/* Write a table header */
_sessionAppendTableHdr(tls, bp, bPatchset, pTab, bp+16)
/* Build and compile a statement to execute: */
if **(**int32)(__ccgo_up(bp + 16)) == SQLITE_OK {
**(**int32)(__ccgo_up(bp + 16)) = _sessionSelectStmt(tls, db, 0, (*Tsqlite3_session)(unsafe.Pointer(pSession)).FzDb, zName, (*TSessionTable)(unsafe.Pointer(pTab)).FbRowid, (*TSessionTable)(unsafe.Pointer(pTab)).FnCol, (*TSessionTable)(unsafe.Pointer(pTab)).FazCol, (*TSessionTable)(unsafe.Pointer(pTab)).FabPK, bp+24, uintptr(0))
}
nNoop = (**(**TSessionBuffer)(__ccgo_up(bp))).FnBuf
i = 0
for {
if !(i < (*TSessionTable)(unsafe.Pointer(pTab)).FnChange && **(**int32)(__ccgo_up(bp + 16)) == SQLITE_OK) {
break
} /* Used to iterate through changes */
p = **(**uintptr)(__ccgo_up((*TSessionTable)(unsafe.Pointer(pTab)).FapChange + uintptr(i)*8))
for {
if !(**(**int32)(__ccgo_up(bp + 16)) == SQLITE_OK && p != 0) {
break
}
**(**int32)(__ccgo_up(bp + 16)) = _sessionSelectBind(tls, **(**uintptr)(__ccgo_up(bp + 24)), (*TSessionTable)(unsafe.Pointer(pTab)).FnCol, (*TSessionTable)(unsafe.Pointer(pTab)).FabPK, p)
if **(**int32)(__ccgo_up(bp + 16)) != SQLITE_OK {
goto _3
}
if Xsqlite3_step(tls, **(**uintptr)(__ccgo_up(bp + 24))) == int32(SQLITE_ROW) {
if libc.Int32FromUint8((*TSessionChange)(unsafe.Pointer(p)).Fop) == int32(SQLITE_INSERT) {
_sessionAppendByte(tls, bp, uint8(SQLITE_INSERT), bp+16)
_sessionAppendByte(tls, bp, (*TSessionChange)(unsafe.Pointer(p)).FbIndirect, bp+16)
iCol = 0
for {
if !(iCol < (*TSessionTable)(unsafe.Pointer(pTab)).FnCol) {
break
}
_sessionAppendCol(tls, bp, **(**uintptr)(__ccgo_up(bp + 24)), iCol, bp+16)
goto _4
_4:
;
iCol = iCol + 1
}
} else {
**(**int32)(__ccgo_up(bp + 16)) = _sessionAppendUpdate(tls, bp, bPatchset, **(**uintptr)(__ccgo_up(bp + 24)), p, (*TSessionTable)(unsafe.Pointer(pTab)).FabPK)
}
} else {
if libc.Int32FromUint8((*TSessionChange)(unsafe.Pointer(p)).Fop) != int32(SQLITE_INSERT) {
**(**int32)(__ccgo_up(bp + 16)) = _sessionAppendDelete(tls, bp, bPatchset, p, (*TSessionTable)(unsafe.Pointer(pTab)).FnCol, (*TSessionTable)(unsafe.Pointer(pTab)).FabPK)
}
}
if **(**int32)(__ccgo_up(bp + 16)) == SQLITE_OK {
**(**int32)(__ccgo_up(bp + 16)) = Xsqlite3_reset(tls, **(**uintptr)(__ccgo_up(bp + 24)))
}
/* If the buffer is now larger than sessions_strm_chunk_size, pass
** its contents to the xOutput() callback. */
if __ccgo_fp_xOutput != 0 && **(**int32)(__ccgo_up(bp + 16)) == SQLITE_OK && (**(**TSessionBuffer)(__ccgo_up(bp))).FnBuf > nNoop && (**(**TSessionBuffer)(__ccgo_up(bp))).FnBuf > _sessions_strm_chunk_size {
**(**int32)(__ccgo_up(bp + 16)) = (*(*func(*libc.TLS, uintptr, uintptr, int32) int32)(unsafe.Pointer(&struct{ uintptr }{__ccgo_fp_xOutput})))(tls, pOut, (**(**TSessionBuffer)(__ccgo_up(bp))).FaBuf, (**(**TSessionBuffer)(__ccgo_up(bp))).FnBuf)
nNoop = -int32(1)
(**(**TSessionBuffer)(__ccgo_up(bp))).FnBuf = 0
}
goto _3
_3:
;
p = (*TSessionChange)(unsafe.Pointer(p)).FpNext
}
goto _2
_2:
;
i = i + 1
}
Xsqlite3_finalize(tls, **(**uintptr)(__ccgo_up(bp + 24)))
if (**(**TSessionBuffer)(__ccgo_up(bp))).FnBuf == nNoop {
(**(**TSessionBuffer)(__ccgo_up(bp))).FnBuf = nRewind
}
}
goto _1
_1:
;
pTab = (*TSessionTable)(unsafe.Pointer(pTab)).FpNext
}
if **(**int32)(__ccgo_up(bp + 16)) == SQLITE_OK {
if __ccgo_fp_xOutput == uintptr(0) {
**(**int32)(__ccgo_up(pnChangeset)) = (**(**TSessionBuffer)(__ccgo_up(bp))).FnBuf
**(**uintptr)(__ccgo_up(ppChangeset)) = (**(**TSessionBuffer)(__ccgo_up(bp))).FaBuf
(**(**TSessionBuffer)(__ccgo_up(bp))).FaBuf = uintptr(0)
} else {
if (**(**TSessionBuffer)(__ccgo_up(bp))).FnBuf > 0 {
**(**int32)(__ccgo_up(bp + 16)) = (*(*func(*libc.TLS, uintptr, uintptr, int32) int32)(unsafe.Pointer(&struct{ uintptr }{__ccgo_fp_xOutput})))(tls, pOut, (**(**TSessionBuffer)(__ccgo_up(bp))).FaBuf, (**(**TSessionBuffer)(__ccgo_up(bp))).FnBuf)
}
}
}
Xsqlite3_free(tls, (**(**TSessionBuffer)(__ccgo_up(bp))).FaBuf)
Xsqlite3_exec(tls, db, __ccgo_ts+36264, uintptr(0), uintptr(0), uintptr(0))
Xsqlite3_mutex_leave(tls, Xsqlite3_db_mutex(tls, db))
return **(**int32)(__ccgo_up(bp + 16))
}
// C documentation
//
// /*
// ** If required, grow the hash table used to store changes on table pTab
// ** (part of the session pSession). If a fatal OOM error occurs, set the
// ** session object to failed and return SQLITE_ERROR. Otherwise, return
// ** SQLITE_OK.
// **
// ** It is possible that a non-fatal OOM error occurs in this function. In
// ** that case the hash-table does not grow, but SQLITE_OK is returned anyway.
// ** Growing the hash table in this case is a performance optimization only,
// ** it is not required for correct operation.
// */
func _sessionGrowHash(tls *libc.TLS, pSession uintptr, bPatchset int32, pTab uintptr) (r int32) {
var apNew, p, pNext uintptr
var bPkOnly, i, iHash, v1 int32
var nNew Tsqlite3_int64
_, _, _, _, _, _, _, _ = apNew, bPkOnly, i, iHash, nNew, p, pNext, v1
if (*TSessionTable)(unsafe.Pointer(pTab)).FnChange == 0 || (*TSessionTable)(unsafe.Pointer(pTab)).FnEntry >= (*TSessionTable)(unsafe.Pointer(pTab)).FnChange/int32(2) {
if (*TSessionTable)(unsafe.Pointer(pTab)).FnChange != 0 {
v1 = (*TSessionTable)(unsafe.Pointer(pTab)).FnChange
} else {
v1 = int32(128)
}
nNew = int64(2) * int64(v1)
apNew = _sessionMalloc64(tls, pSession, libc.Int64FromUint64(uint64(8)*libc.Uint64FromInt64(nNew)))
if apNew == uintptr(0) {
if (*TSessionTable)(unsafe.Pointer(pTab)).FnChange == 0 {
return int32(SQLITE_ERROR)
}
return SQLITE_OK
}
libc.X__builtin___memset_chk(tls, apNew, 0, uint64(uint64(8)*libc.Uint64FromInt64(nNew)), ^t__predefined_size_t(0))
i = 0
for {
if !(i < (*TSessionTable)(unsafe.Pointer(pTab)).FnChange) {
break
}
p = **(**uintptr)(__ccgo_up((*TSessionTable)(unsafe.Pointer(pTab)).FapChange + uintptr(i)*8))
for {
if !(p != 0) {
break
}
bPkOnly = libc.BoolInt32(libc.Int32FromUint8((*TSessionChange)(unsafe.Pointer(p)).Fop) == int32(SQLITE_DELETE) && bPatchset != 0)
iHash = libc.Int32FromUint32(_sessionChangeHash(tls, pTab, bPkOnly, (*TSessionChange)(unsafe.Pointer(p)).FaRecord, int32(nNew)))
pNext = (*TSessionChange)(unsafe.Pointer(p)).FpNext
(*TSessionChange)(unsafe.Pointer(p)).FpNext = **(**uintptr)(__ccgo_up(apNew + uintptr(iHash)*8))
**(**uintptr)(__ccgo_up(apNew + uintptr(iHash)*8)) = p
goto _3
_3:
;
p = pNext
}
goto _2
_2:
;
i = i + 1
}
_sessionFree(tls, pSession, (*TSessionTable)(unsafe.Pointer(pTab)).FapChange)
(*TSessionTable)(unsafe.Pointer(pTab)).FnChange = int32(nNew)
(*TSessionTable)(unsafe.Pointer(pTab)).FapChange = apNew
}
return SQLITE_OK
}
// C documentation
//
// /*
// ** This function is called to initialize the SessionTable.nCol, azCol[]
// ** abPK[] and azDflt[] members of SessionTable object pTab. If these
// ** fields are already initialized, this function is a no-op.
// **
// ** If an error occurs, an error code is stored in sqlite3_session.rc and
// ** non-zero returned. Or, if no error occurs but the table has no primary
// ** key, sqlite3_session.rc is left set to SQLITE_OK and non-zero returned to
// ** indicate that updates on this table should be ignored. SessionTable.abPK
// ** is set to NULL in this case.
// */
func _sessionInitTable(tls *libc.TLS, pSession uintptr, pTab uintptr, db uintptr, zDb uintptr) (r int32) {
bp := tls.Alloc(16)
defer tls.Free(16)
var i, rc int32
var v1 uintptr
var _ /* abPK at bp+0 */ uintptr
_, _, _ = i, rc, v1
rc = SQLITE_OK
if (*TSessionTable)(unsafe.Pointer(pTab)).FnCol == 0 {
Xsqlite3_free(tls, (*TSessionTable)(unsafe.Pointer(pTab)).FazCol)
(*TSessionTable)(unsafe.Pointer(pTab)).FabPK = uintptr(0)
if pSession == uintptr(0) || (*Tsqlite3_session)(unsafe.Pointer(pSession)).FbImplicitPK != 0 {
v1 = pTab + 28
} else {
v1 = uintptr(0)
}
rc = _sessionTableInfo(tls, pSession, db, zDb, (*TSessionTable)(unsafe.Pointer(pTab)).FzName, pTab+16, pTab+20, uintptr(0), pTab+32, pTab+40, pTab+48, bp, v1)
if rc == SQLITE_OK {
i = 0
for {
if !(i < (*TSessionTable)(unsafe.Pointer(pTab)).FnCol) {
break
}
if **(**Tu8)(__ccgo_up(**(**uintptr)(__ccgo_up(bp)) + uintptr(i))) != 0 {
(*TSessionTable)(unsafe.Pointer(pTab)).FabPK = **(**uintptr)(__ccgo_up(bp))
break
}
goto _2
_2:
;
i = i + 1
}
if 0 == Xsqlite3_stricmp(tls, __ccgo_ts+13181, (*TSessionTable)(unsafe.Pointer(pTab)).FzName) {
(*TSessionTable)(unsafe.Pointer(pTab)).FbStat1 = int32(1)
}
if pSession != 0 && (*Tsqlite3_session)(unsafe.Pointer(pSession)).FbEnableSize != 0 {
v1 = pSession + 64
*(*Ti64)(unsafe.Pointer(v1)) = Ti64(uint64(*(*Ti64)(unsafe.Pointer(v1))) + uint64(libc.Uint64FromInt32(libc.Int32FromInt32(1)+_sessionVarintLen(tls, (*TSessionTable)(unsafe.Pointer(pTab)).FnCol)+(*TSessionTable)(unsafe.Pointer(pTab)).FnCol)+libc.Xstrlen(tls, (*TSessionTable)(unsafe.Pointer(pTab)).FzName)+libc.Uint64FromInt32(1)))
}
}
}
if pSession != 0 {
(*Tsqlite3_session)(unsafe.Pointer(pSession)).Frc = rc
return libc.BoolInt32(rc != 0 || (*TSessionTable)(unsafe.Pointer(pTab)).FabPK == uintptr(0))
}
return rc
}
// C documentation
//
// /*
// ** Formulate and prepare an INSERT statement to add a record to table zTab.
// ** For example:
// **
// ** INSERT INTO main."zTab" VALUES(?1, ?2, ?3 ...);
// **
// ** If successful, SQLITE_OK is returned and SessionApplyCtx.pInsert is left
// ** pointing to the prepared version of the SQL statement.
// */
func _sessionInsertRow(tls *libc.TLS, db uintptr, zTab uintptr, p uintptr) (r int32) {
bp := tls.Alloc(32)
defer tls.Free(32)
var i int32
var _ /* buf at bp+8 */ TSessionBuffer
var _ /* rc at bp+0 */ int32
_ = i
**(**int32)(__ccgo_up(bp)) = SQLITE_OK
**(**TSessionBuffer)(__ccgo_up(bp + 8)) = TSessionBuffer{}
_sessionAppendStr(tls, bp+8, __ccgo_ts+36426, bp)
_sessionAppendIdent(tls, bp+8, zTab, bp)
_sessionAppendStr(tls, bp+8, __ccgo_ts+24026, bp)
i = 0
for {
if !(i < (*TSessionApplyCtx)(unsafe.Pointer(p)).FnCol) {
break
}
if i != 0 {
_sessionAppendStr(tls, bp+8, __ccgo_ts+16562, bp)
}
_sessionAppendIdent(tls, bp+8, **(**uintptr)(__ccgo_up((*TSessionApplyCtx)(unsafe.Pointer(p)).FazCol + uintptr(i)*8)), bp)
goto _1
_1:
;
i = i + 1
}
_sessionAppendStr(tls, bp+8, __ccgo_ts+36444, bp)
i = int32(1)
for {
if !(i < (*TSessionApplyCtx)(unsafe.Pointer(p)).FnCol) {
break
}
_sessionAppendStr(tls, bp+8, __ccgo_ts+36455, bp)
goto _2
_2:
;
i = i + 1
}
_sessionAppendStr(tls, bp+8, __ccgo_ts+5605, bp)
if **(**int32)(__ccgo_up(bp)) == SQLITE_OK {
**(**int32)(__ccgo_up(bp)) = _sessionPrepare(tls, db, p+16, p+128, (**(**TSessionBuffer)(__ccgo_up(bp + 8))).FaBuf)
}
Xsqlite3_free(tls, (**(**TSessionBuffer)(__ccgo_up(bp + 8))).FaBuf)
return **(**int32)(__ccgo_up(bp))
}
// C documentation
//
// /*
// ** Arguments aLeft and aRight both point to buffers containing change
// ** records with nCol columns. This function "merges" the two records into
// ** a single records which is written to the buffer at *paOut. *paOut is
// ** then set to point to one byte after the last byte written before
// ** returning.
// **
// ** The merging of records is done as follows: For each column, if the
// ** aRight record contains a value for the column, copy the value from
// ** their. Otherwise, if aLeft contains a value, copy it. If neither
// ** record contains a value for a given column, then neither does the
// ** output record.
// */
func _sessionMergeRecord(tls *libc.TLS, paOut uintptr, nCol int32, aLeft uintptr, aRight uintptr) {
var a1, a2, aOut uintptr
var iCol, n1, n2 int32
_, _, _, _, _, _ = a1, a2, aOut, iCol, n1, n2
a1 = aLeft /* Cursor used to iterate through aLeft */
a2 = aRight /* Cursor used to iterate through aRight */
aOut = **(**uintptr)(__ccgo_up(paOut)) /* Used to iterate from 0 to nCol */
iCol = 0
for {
if !(iCol < nCol) {
break
}
n1 = _sessionSerialLen(tls, a1)
n2 = _sessionSerialLen(tls, a2)
if **(**Tu8)(__ccgo_up(a2)) != 0 {
libc.X__builtin___memcpy_chk(tls, aOut, a2, libc.Uint64FromInt32(n2), ^t__predefined_size_t(0))
aOut = aOut + uintptr(n2)
} else {
libc.X__builtin___memcpy_chk(tls, aOut, a1, libc.Uint64FromInt32(n1), ^t__predefined_size_t(0))
aOut = aOut + uintptr(n1)
}
a1 = a1 + uintptr(n1)
a2 = a2 + uintptr(n2)
goto _1
_1:
;
iCol = iCol + 1
}
**(**uintptr)(__ccgo_up(paOut)) = aOut
}
// C documentation
//
// /*
// ** This function is used by changeset_concat() to merge two UPDATE changes
// ** on the same row.
// */
func _sessionMergeUpdate(tls *libc.TLS, paOut uintptr, pTab uintptr, bPatchset int32, aOldRecord1 uintptr, aOldRecord2 uintptr, aNewRecord1 uintptr, aNewRecord2 uintptr) (r int32) {
bp := tls.Alloc(48)
defer tls.Free(48)
var aNew, aNew1, aOld, aOld1, aOut, v2 uintptr
var bRequired, i int32
var _ /* aNew1 at bp+16 */ uintptr
var _ /* aNew2 at bp+24 */ uintptr
var _ /* aOld1 at bp+0 */ uintptr
var _ /* aOld2 at bp+8 */ uintptr
var _ /* nNew at bp+36 */ int32
var _ /* nNew at bp+44 */ int32
var _ /* nOld at bp+32 */ int32
var _ /* nOld at bp+40 */ int32
_, _, _, _, _, _, _, _ = aNew, aNew1, aOld, aOld1, aOut, bRequired, i, v2
**(**uintptr)(__ccgo_up(bp)) = aOldRecord1
**(**uintptr)(__ccgo_up(bp + 8)) = aOldRecord2
**(**uintptr)(__ccgo_up(bp + 16)) = aNewRecord1
**(**uintptr)(__ccgo_up(bp + 24)) = aNewRecord2
aOut = **(**uintptr)(__ccgo_up(paOut))
if bPatchset == 0 {
bRequired = 0
/* Write the old.* vector first. */
i = 0
for {
if !(i < (*TSessionTable)(unsafe.Pointer(pTab)).FnCol) {
break
}
aOld = _sessionMergeValue(tls, bp, bp+8, bp+32)
aNew = _sessionMergeValue(tls, bp+16, bp+24, bp+36)
if **(**Tu8)(__ccgo_up((*TSessionTable)(unsafe.Pointer(pTab)).FabPK + uintptr(i))) != 0 || **(**int32)(__ccgo_up(bp + 32)) != **(**int32)(__ccgo_up(bp + 36)) || libc.Xmemcmp(tls, aOld, aNew, libc.Uint64FromInt32(**(**int32)(__ccgo_up(bp + 36)))) != 0 {
if libc.Int32FromUint8(**(**Tu8)(__ccgo_up((*TSessionTable)(unsafe.Pointer(pTab)).FabPK + uintptr(i)))) == 0 {
bRequired = int32(1)
}
libc.X__builtin___memcpy_chk(tls, aOut, aOld, libc.Uint64FromInt32(**(**int32)(__ccgo_up(bp + 32))), ^t__predefined_size_t(0))
aOut = aOut + uintptr(**(**int32)(__ccgo_up(bp + 32)))
} else {
v2 = aOut
aOut = aOut + 1
**(**Tu8)(__ccgo_up(v2)) = uint8('\000')
}
goto _1
_1:
;
i = i + 1
}
if !(bRequired != 0) {
return 0
}
}
/* Write the new.* vector */
**(**uintptr)(__ccgo_up(bp)) = aOldRecord1
**(**uintptr)(__ccgo_up(bp + 8)) = aOldRecord2
**(**uintptr)(__ccgo_up(bp + 16)) = aNewRecord1
**(**uintptr)(__ccgo_up(bp + 24)) = aNewRecord2
i = 0
for {
if !(i < (*TSessionTable)(unsafe.Pointer(pTab)).FnCol) {
break
}
aOld1 = _sessionMergeValue(tls, bp, bp+8, bp+40)
aNew1 = _sessionMergeValue(tls, bp+16, bp+24, bp+44)
if bPatchset == 0 && (**(**Tu8)(__ccgo_up((*TSessionTable)(unsafe.Pointer(pTab)).FabPK + uintptr(i))) != 0 || **(**int32)(__ccgo_up(bp + 40)) == **(**int32)(__ccgo_up(bp + 44)) && 0 == libc.Xmemcmp(tls, aOld1, aNew1, libc.Uint64FromInt32(**(**int32)(__ccgo_up(bp + 44))))) {
v2 = aOut
aOut = aOut + 1
**(**Tu8)(__ccgo_up(v2)) = uint8('\000')
} else {
libc.X__builtin___memcpy_chk(tls, aOut, aNew1, libc.Uint64FromInt32(**(**int32)(__ccgo_up(bp + 44))), ^t__predefined_size_t(0))
aOut = aOut + uintptr(**(**int32)(__ccgo_up(bp + 44)))
}
goto _3
_3:
;
i = i + 1
}
**(**uintptr)(__ccgo_up(paOut)) = aOut
return int32(1)
}
// C documentation
//
// /*
// ** Prepare a statement against database handle db that SELECTs a single
// ** row containing the default values for each column in table pTab. For
// ** example, if pTab is declared as:
// **
// ** CREATE TABLE pTab(a PRIMARY KEY, b DEFAULT 123, c DEFAULT 'abcd');
// **
// ** Then this function prepares and returns the SQL statement:
// **
// ** SELECT NULL, 123, 'abcd';
// */
func _sessionPrepareDfltStmt(tls *libc.TLS, db uintptr, pTab uintptr, ppStmt uintptr) (r int32) {
bp := tls.Alloc(48)
defer tls.Free(48)
var ii int32
var zDflt, zSep, v2 uintptr
var _ /* rc at bp+16 */ int32
var _ /* sql at bp+0 */ TSessionBuffer
_, _, _, _ = ii, zDflt, zSep, v2
**(**TSessionBuffer)(__ccgo_up(bp)) = TSessionBuffer{}
**(**int32)(__ccgo_up(bp + 16)) = SQLITE_OK
zSep = __ccgo_ts + 11889
ii = 0
**(**uintptr)(__ccgo_up(ppStmt)) = uintptr(0)
_sessionAppendPrintf(tls, bp, bp+16, __ccgo_ts+35743, 0)
ii = 0
for {
if !(ii < (*TSessionTable)(unsafe.Pointer(pTab)).FnCol) {
break
}
if **(**uintptr)(__ccgo_up((*TSessionTable)(unsafe.Pointer(pTab)).FazDflt + uintptr(ii)*8)) != 0 {
v2 = **(**uintptr)(__ccgo_up((*TSessionTable)(unsafe.Pointer(pTab)).FazDflt + uintptr(ii)*8))
} else {
v2 = __ccgo_ts + 1703
}
zDflt = v2
_sessionAppendPrintf(tls, bp, bp+16, __ccgo_ts+5575, libc.VaList(bp+32, zSep, zDflt))
zSep = __ccgo_ts + 16562
goto _1
_1:
;
ii = ii + 1
}
if **(**int32)(__ccgo_up(bp + 16)) == SQLITE_OK {
**(**int32)(__ccgo_up(bp + 16)) = Xsqlite3_prepare_v2(tls, db, (**(**TSessionBuffer)(__ccgo_up(bp))).FaBuf, -int32(1), ppStmt, uintptr(0))
}
Xsqlite3_free(tls, (**(**TSessionBuffer)(__ccgo_up(bp))).FaBuf)
return **(**int32)(__ccgo_up(bp + 16))
}
// C documentation
//
// /*
// ** This function is only called from within a pre-update-hook callback.
// ** It determines if the current pre-update-hook change affects the same row
// ** as the change stored in argument pChange. If so, it returns true. Otherwise
// ** if the pre-update-hook does not affect the same row as pChange, it returns
// ** false.
// */
func _sessionPreupdateEqual(tls *libc.TLS, pSession uintptr, iRowid Ti64, pTab uintptr, pChange uintptr, op int32) (r int32) {
bp := tls.Alloc(32)
defer tls.Free(32)
var a, z, v2 uintptr
var eType, iCol, iIdx, rc int32
var _ /* iVal at bp+8 */ Ti64
var _ /* n at bp+24 */ int32
var _ /* pVal at bp+0 */ uintptr
var _ /* rVal at bp+16 */ float64
_, _, _, _, _, _, _ = a, eType, iCol, iIdx, rc, z, v2 /* Used to iterate through columns */
a = (*TSessionChange)(unsafe.Pointer(pChange)).FaRecord /* Cursor used to scan change record */
if (*TSessionTable)(unsafe.Pointer(pTab)).FbRowid != 0 {
if libc.Int32FromUint8(**(**Tu8)(__ccgo_up(a))) != int32(SQLITE_INTEGER) {
return 0
}
return libc.BoolInt32(_sessionGetI64(tls, a+1) == iRowid)
}
iCol = 0
for {
if !(iCol < (*TSessionTable)(unsafe.Pointer(pTab)).FnCol) {
break
}
if !(**(**Tu8)(__ccgo_up((*TSessionTable)(unsafe.Pointer(pTab)).FabPK + uintptr(iCol))) != 0) {
a = a + uintptr(_sessionSerialLen(tls, a))
} else {
v2 = a
a = a + 1 /* Error code from preupdate_new/old */
eType = libc.Int32FromUint8(**(**Tu8)(__ccgo_up(v2))) /* Type of value from change record */
iIdx = **(**int32)(__ccgo_up((*TSessionTable)(unsafe.Pointer(pTab)).FaiIdx + uintptr(iCol)*4))
/* The following calls to preupdate_new() and preupdate_old() can not
** fail. This is because they cache their return values, and by the
** time control flows to here they have already been called once from
** within sessionPreupdateHash(). The first two asserts below verify
** this (that the method has already been called). */
if op == int32(SQLITE_INSERT) {
/* assert( db->pPreUpdate->pNewUnpacked || db->pPreUpdate->aNew ); */
rc = (*(*func(*libc.TLS, uintptr, int32, uintptr) int32)(unsafe.Pointer(&struct{ uintptr }{(*Tsqlite3_session)(unsafe.Pointer(pSession)).Fhook.FxNew})))(tls, (*Tsqlite3_session)(unsafe.Pointer(pSession)).Fhook.FpCtx, iIdx, bp)
} else {
/* assert( db->pPreUpdate->pUnpacked ); */
rc = (*(*func(*libc.TLS, uintptr, int32, uintptr) int32)(unsafe.Pointer(&struct{ uintptr }{(*Tsqlite3_session)(unsafe.Pointer(pSession)).Fhook.FxOld})))(tls, (*Tsqlite3_session)(unsafe.Pointer(pSession)).Fhook.FpCtx, iIdx, bp)
}
_ = rc /* Suppress warning about unused variable */
if Xsqlite3_value_type(tls, **(**uintptr)(__ccgo_up(bp))) != eType {
return 0
}
/* A SessionChange object never has a NULL value in a PK column */
if eType == int32(SQLITE_INTEGER) || eType == int32(SQLITE_FLOAT) {
**(**Ti64)(__ccgo_up(bp + 8)) = _sessionGetI64(tls, a)
a = a + uintptr(8)
if eType == int32(SQLITE_INTEGER) {
if Xsqlite3_value_int64(tls, **(**uintptr)(__ccgo_up(bp))) != **(**Ti64)(__ccgo_up(bp + 8)) {
return 0
}
} else {
libc.X__builtin___memcpy_chk(tls, bp+16, bp+8, uint64(8), ^t__predefined_size_t(0))
if Xsqlite3_value_double(tls, **(**uintptr)(__ccgo_up(bp))) != **(**float64)(__ccgo_up(bp + 16)) {
return 0
}
}
} else {
a = a + uintptr(_sessionVarintGet(tls, a, bp+24))
if Xsqlite3_value_bytes(tls, **(**uintptr)(__ccgo_up(bp))) != **(**int32)(__ccgo_up(bp + 24)) {
return 0
}
if eType == int32(SQLITE_TEXT) {
z = Xsqlite3_value_text(tls, **(**uintptr)(__ccgo_up(bp)))
} else {
z = Xsqlite3_value_blob(tls, **(**uintptr)(__ccgo_up(bp)))
}
if **(**int32)(__ccgo_up(bp + 24)) > 0 && libc.Xmemcmp(tls, a, z, libc.Uint64FromInt32(**(**int32)(__ccgo_up(bp + 24)))) != 0 {
return 0
}
a = a + uintptr(**(**int32)(__ccgo_up(bp + 24)))
}
}
goto _1
_1:
;
iCol = iCol + 1
}
return int32(1)
}
// C documentation
//
// /*
// ** This function may only be called from within a pre-update callback.
// ** It calculates a hash based on the primary key values of the old.* or
// ** new.* row currently available and, assuming no error occurs, writes it to
// ** *piHash before returning. If the primary key contains one or more NULL
// ** values, *pbNullPK is set to true before returning.
// **
// ** If an error occurs, an SQLite error code is returned and the final values
// ** of *piHash asn *pbNullPK are undefined. Otherwise, SQLITE_OK is returned
// ** and the output variables are set as described above.
// */
func _sessionPreupdateHash(tls *libc.TLS, pSession uintptr, iRowid Ti64, pTab uintptr, bNew int32, piHash uintptr, pbNullPK uintptr) (r int32) {
bp := tls.Alloc(32)
defer tls.Free(32)
var eType, i, iIdx, n, rc int32
var h uint32
var z uintptr
var _ /* iVal at bp+8 */ Ti64
var _ /* pVal at bp+0 */ uintptr
var _ /* rVal at bp+16 */ float64
_, _, _, _, _, _, _ = eType, h, i, iIdx, n, rc, z
h = uint32(0) /* Used to iterate through columns */
if (*TSessionTable)(unsafe.Pointer(pTab)).FbRowid != 0 {
h = _sessionHashAppendI64(tls, h, iRowid)
} else {
i = 0
for {
if !(i < (*TSessionTable)(unsafe.Pointer(pTab)).FnCol) {
break
}
if **(**Tu8)(__ccgo_up((*TSessionTable)(unsafe.Pointer(pTab)).FabPK + uintptr(i))) != 0 {
iIdx = **(**int32)(__ccgo_up((*TSessionTable)(unsafe.Pointer(pTab)).FaiIdx + uintptr(i)*4))
if bNew != 0 {
rc = (*(*func(*libc.TLS, uintptr, int32, uintptr) int32)(unsafe.Pointer(&struct{ uintptr }{(*Tsqlite3_session)(unsafe.Pointer(pSession)).Fhook.FxNew})))(tls, (*Tsqlite3_session)(unsafe.Pointer(pSession)).Fhook.FpCtx, iIdx, bp)
} else {
rc = (*(*func(*libc.TLS, uintptr, int32, uintptr) int32)(unsafe.Pointer(&struct{ uintptr }{(*Tsqlite3_session)(unsafe.Pointer(pSession)).Fhook.FxOld})))(tls, (*Tsqlite3_session)(unsafe.Pointer(pSession)).Fhook.FpCtx, iIdx, bp)
}
if rc != SQLITE_OK {
return rc
}
eType = Xsqlite3_value_type(tls, **(**uintptr)(__ccgo_up(bp)))
h = _sessionHashAppendType(tls, h, eType)
if eType == int32(SQLITE_INTEGER) || eType == int32(SQLITE_FLOAT) {
if eType == int32(SQLITE_INTEGER) {
**(**Ti64)(__ccgo_up(bp + 8)) = Xsqlite3_value_int64(tls, **(**uintptr)(__ccgo_up(bp)))
} else {
**(**float64)(__ccgo_up(bp + 16)) = Xsqlite3_value_double(tls, **(**uintptr)(__ccgo_up(bp)))
libc.X__builtin___memcpy_chk(tls, bp+8, bp+16, uint64(8), ^t__predefined_size_t(0))
}
h = _sessionHashAppendI64(tls, h, **(**Ti64)(__ccgo_up(bp + 8)))
} else {
if eType == int32(SQLITE_TEXT) || eType == int32(SQLITE_BLOB) {
if eType == int32(SQLITE_TEXT) {
z = Xsqlite3_value_text(tls, **(**uintptr)(__ccgo_up(bp)))
} else {
z = Xsqlite3_value_blob(tls, **(**uintptr)(__ccgo_up(bp)))
}
n = Xsqlite3_value_bytes(tls, **(**uintptr)(__ccgo_up(bp)))
if !(z != 0) && (eType != int32(SQLITE_BLOB) || n > 0) {
return int32(SQLITE_NOMEM)
}
h = _sessionHashAppendBlob(tls, h, n, z)
} else {
**(**int32)(__ccgo_up(pbNullPK)) = int32(1)
}
}
}
goto _1
_1:
;
i = i + 1
}
}
**(**int32)(__ccgo_up(piHash)) = libc.Int32FromUint32(h % libc.Uint32FromInt32((*TSessionTable)(unsafe.Pointer(pTab)).FnChange))
return SQLITE_OK
}
// C documentation
//
// /*
// ** This function is only called from with a pre-update-hook reporting a
// ** change on table pTab (attached to session pSession). The type of change
// ** (UPDATE, INSERT, DELETE) is specified by the first argument.
// **
// ** Unless one is already present or an error occurs, an entry is added
// ** to the changed-rows hash table associated with table pTab.
// */
func _sessionPreupdateOneChange(tls *libc.TLS, op int32, iRowid Ti64, pSession uintptr, pTab uintptr) {
bp := tls.Alloc(80)
defer tls.Free(80)
var i, iIdx, iIdx1, nExpect, rc int32
var p, pC uintptr
var _ /* bNull at bp+4 */ int32
var _ /* iHash at bp+0 */ int32
var _ /* nByte at bp+56 */ Tsqlite3_int64
var _ /* p at bp+64 */ uintptr
var _ /* p at bp+72 */ uintptr
var _ /* stat1 at bp+8 */ TSessionStat1Ctx
_, _, _, _, _, _, _ = i, iIdx, iIdx1, nExpect, p, pC, rc
**(**int32)(__ccgo_up(bp + 4)) = 0
rc = SQLITE_OK
nExpect = 0
**(**TSessionStat1Ctx)(__ccgo_up(bp + 8)) = TSessionStat1Ctx{}
if (*Tsqlite3_session)(unsafe.Pointer(pSession)).Frc != 0 {
return
}
/* Load table details if required */
if _sessionInitTable(tls, pSession, pTab, (*Tsqlite3_session)(unsafe.Pointer(pSession)).Fdb, (*Tsqlite3_session)(unsafe.Pointer(pSession)).FzDb) != 0 {
return
}
/* Check the number of columns in this xPreUpdate call matches the
** number of columns in the table. */
nExpect = (*(*func(*libc.TLS, uintptr) int32)(unsafe.Pointer(&struct{ uintptr }{(*Tsqlite3_session)(unsafe.Pointer(pSession)).Fhook.FxCount})))(tls, (*Tsqlite3_session)(unsafe.Pointer(pSession)).Fhook.FpCtx)
if (*TSessionTable)(unsafe.Pointer(pTab)).FnTotalCol < nExpect {
if _sessionReinitTable(tls, pSession, pTab) != 0 {
return
}
if _sessionUpdateChanges(tls, pSession, pTab) != 0 {
return
}
}
if (*TSessionTable)(unsafe.Pointer(pTab)).FnTotalCol != nExpect {
(*Tsqlite3_session)(unsafe.Pointer(pSession)).Frc = int32(SQLITE_SCHEMA)
return
}
/* Grow the hash table if required */
if _sessionGrowHash(tls, pSession, 0, pTab) != 0 {
(*Tsqlite3_session)(unsafe.Pointer(pSession)).Frc = int32(SQLITE_NOMEM)
return
}
if (*TSessionTable)(unsafe.Pointer(pTab)).FbStat1 != 0 {
(**(**TSessionStat1Ctx)(__ccgo_up(bp + 8))).Fhook = (*Tsqlite3_session)(unsafe.Pointer(pSession)).Fhook
(**(**TSessionStat1Ctx)(__ccgo_up(bp + 8))).FpSession = pSession
(*Tsqlite3_session)(unsafe.Pointer(pSession)).Fhook.FpCtx = bp + 8
(*Tsqlite3_session)(unsafe.Pointer(pSession)).Fhook.FxNew = __ccgo_fp(_sessionStat1New)
(*Tsqlite3_session)(unsafe.Pointer(pSession)).Fhook.FxOld = __ccgo_fp(_sessionStat1Old)
(*Tsqlite3_session)(unsafe.Pointer(pSession)).Fhook.FxCount = __ccgo_fp(_sessionStat1Count)
(*Tsqlite3_session)(unsafe.Pointer(pSession)).Fhook.FxDepth = __ccgo_fp(_sessionStat1Depth)
if (*Tsqlite3_session)(unsafe.Pointer(pSession)).FpZeroBlob == uintptr(0) {
p = _sqlite3ValueNew(tls, uintptr(0))
if p == uintptr(0) {
rc = int32(SQLITE_NOMEM)
goto error_out
}
_sqlite3ValueSetStr(tls, p, 0, __ccgo_ts+1702, uint8(0), libc.UintptrFromInt32(0))
(*Tsqlite3_session)(unsafe.Pointer(pSession)).FpZeroBlob = p
}
}
/* Calculate the hash-key for this change. If the primary key of the row
** includes a NULL value, exit early. Such changes are ignored by the
** session module. */
rc = _sessionPreupdateHash(tls, pSession, iRowid, pTab, libc.BoolInt32(op == int32(SQLITE_INSERT)), bp, bp+4)
if rc != SQLITE_OK {
goto error_out
}
if **(**int32)(__ccgo_up(bp + 4)) == 0 {
pC = **(**uintptr)(__ccgo_up((*TSessionTable)(unsafe.Pointer(pTab)).FapChange + uintptr(**(**int32)(__ccgo_up(bp)))*8))
for {
if !(pC != 0) {
break
}
if _sessionPreupdateEqual(tls, pSession, iRowid, pTab, pC, op) != 0 {
break
}
goto _1
_1:
;
pC = (*TSessionChange)(unsafe.Pointer(pC)).FpNext
}
if pC == uintptr(0) { /* Used to iterate through columns */
(*TSessionTable)(unsafe.Pointer(pTab)).FnEntry = (*TSessionTable)(unsafe.Pointer(pTab)).FnEntry + 1
/* Figure out how large an allocation is required */
**(**Tsqlite3_int64)(__ccgo_up(bp + 56)) = int64(32)
i = (*TSessionTable)(unsafe.Pointer(pTab)).FbRowid
for {
if !(i < (*TSessionTable)(unsafe.Pointer(pTab)).FnCol) {
break
}
iIdx = **(**int32)(__ccgo_up((*TSessionTable)(unsafe.Pointer(pTab)).FaiIdx + uintptr(i)*4))
**(**uintptr)(__ccgo_up(bp + 64)) = uintptr(0)
if op != int32(SQLITE_INSERT) {
/* This may fail if the column has a non-NULL default and was added
** using ALTER TABLE ADD COLUMN after this record was created. */
rc = (*(*func(*libc.TLS, uintptr, int32, uintptr) int32)(unsafe.Pointer(&struct{ uintptr }{(*Tsqlite3_session)(unsafe.Pointer(pSession)).Fhook.FxOld})))(tls, (*Tsqlite3_session)(unsafe.Pointer(pSession)).Fhook.FpCtx, iIdx, bp+64)
} else {
if **(**Tu8)(__ccgo_up((*TSessionTable)(unsafe.Pointer(pTab)).FabPK + uintptr(i))) != 0 {
(*(*func(*libc.TLS, uintptr, int32, uintptr) int32)(unsafe.Pointer(&struct{ uintptr }{(*Tsqlite3_session)(unsafe.Pointer(pSession)).Fhook.FxNew})))(tls, (*Tsqlite3_session)(unsafe.Pointer(pSession)).Fhook.FpCtx, iIdx, bp+64)
}
}
if rc == SQLITE_OK {
/* This may fail if SQLite value p contains a utf-16 string that must
** be converted to utf-8 and an OOM error occurs while doing so. */
rc = _sessionSerializeValue(tls, uintptr(0), **(**uintptr)(__ccgo_up(bp + 64)), bp+56)
}
if rc != SQLITE_OK {
goto error_out
}
goto _2
_2:
;
i = i + 1
}
if (*TSessionTable)(unsafe.Pointer(pTab)).FbRowid != 0 {
**(**Tsqlite3_int64)(__ccgo_up(bp + 56)) = **(**Tsqlite3_int64)(__ccgo_up(bp + 56)) + int64(9) /* Size of rowid field - an integer */
}
/* Allocate the change object */
pC = _sessionMalloc64(tls, pSession, **(**Tsqlite3_int64)(__ccgo_up(bp + 56)))
if !(pC != 0) {
rc = int32(SQLITE_NOMEM)
goto error_out
} else {
libc.X__builtin___memset_chk(tls, pC, 0, uint64(32), ^t__predefined_size_t(0))
(*TSessionChange)(unsafe.Pointer(pC)).FaRecord = pC + 1*32
}
/* Populate the change object. None of the preupdate_old(),
** preupdate_new() or SerializeValue() calls below may fail as all
** required values and encodings have already been cached in memory.
** It is not possible for an OOM to occur in this block. */
**(**Tsqlite3_int64)(__ccgo_up(bp + 56)) = 0
if (*TSessionTable)(unsafe.Pointer(pTab)).FbRowid != 0 {
**(**Tu8)(__ccgo_up((*TSessionChange)(unsafe.Pointer(pC)).FaRecord)) = uint8(SQLITE_INTEGER)
_sessionPutI64(tls, (*TSessionChange)(unsafe.Pointer(pC)).FaRecord+1, iRowid)
**(**Tsqlite3_int64)(__ccgo_up(bp + 56)) = int64(9)
}
i = (*TSessionTable)(unsafe.Pointer(pTab)).FbRowid
for {
if !(i < (*TSessionTable)(unsafe.Pointer(pTab)).FnCol) {
break
}
**(**uintptr)(__ccgo_up(bp + 72)) = uintptr(0)
iIdx1 = **(**int32)(__ccgo_up((*TSessionTable)(unsafe.Pointer(pTab)).FaiIdx + uintptr(i)*4))
if op != int32(SQLITE_INSERT) {
(*(*func(*libc.TLS, uintptr, int32, uintptr) int32)(unsafe.Pointer(&struct{ uintptr }{(*Tsqlite3_session)(unsafe.Pointer(pSession)).Fhook.FxOld})))(tls, (*Tsqlite3_session)(unsafe.Pointer(pSession)).Fhook.FpCtx, iIdx1, bp+72)
} else {
if **(**Tu8)(__ccgo_up((*TSessionTable)(unsafe.Pointer(pTab)).FabPK + uintptr(i))) != 0 {
(*(*func(*libc.TLS, uintptr, int32, uintptr) int32)(unsafe.Pointer(&struct{ uintptr }{(*Tsqlite3_session)(unsafe.Pointer(pSession)).Fhook.FxNew})))(tls, (*Tsqlite3_session)(unsafe.Pointer(pSession)).Fhook.FpCtx, iIdx1, bp+72)
}
}
_sessionSerializeValue(tls, (*TSessionChange)(unsafe.Pointer(pC)).FaRecord+uintptr(**(**Tsqlite3_int64)(__ccgo_up(bp + 56))), **(**uintptr)(__ccgo_up(bp + 72)), bp+56)
goto _3
_3:
;
i = i + 1
}
/* Add the change to the hash-table */
if (*Tsqlite3_session)(unsafe.Pointer(pSession)).FbIndirect != 0 || (*(*func(*libc.TLS, uintptr) int32)(unsafe.Pointer(&struct{ uintptr }{(*Tsqlite3_session)(unsafe.Pointer(pSession)).Fhook.FxDepth})))(tls, (*Tsqlite3_session)(unsafe.Pointer(pSession)).Fhook.FpCtx) != 0 {
(*TSessionChange)(unsafe.Pointer(pC)).FbIndirect = uint8(1)
}
(*TSessionChange)(unsafe.Pointer(pC)).FnRecordField = libc.Uint16FromInt32((*TSessionTable)(unsafe.Pointer(pTab)).FnCol)
(*TSessionChange)(unsafe.Pointer(pC)).FnRecord = int32(**(**Tsqlite3_int64)(__ccgo_up(bp + 56)))
(*TSessionChange)(unsafe.Pointer(pC)).Fop = libc.Uint8FromInt32(op)
(*TSessionChange)(unsafe.Pointer(pC)).FpNext = **(**uintptr)(__ccgo_up((*TSessionTable)(unsafe.Pointer(pTab)).FapChange + uintptr(**(**int32)(__ccgo_up(bp)))*8))
**(**uintptr)(__ccgo_up((*TSessionTable)(unsafe.Pointer(pTab)).FapChange + uintptr(**(**int32)(__ccgo_up(bp)))*8)) = pC
} else {
if (*TSessionChange)(unsafe.Pointer(pC)).FbIndirect != 0 {
/* If the existing change is considered "indirect", but this current
** change is "direct", mark the change object as direct. */
if (*(*func(*libc.TLS, uintptr) int32)(unsafe.Pointer(&struct{ uintptr }{(*Tsqlite3_session)(unsafe.Pointer(pSession)).Fhook.FxDepth})))(tls, (*Tsqlite3_session)(unsafe.Pointer(pSession)).Fhook.FpCtx) == 0 && (*Tsqlite3_session)(unsafe.Pointer(pSession)).FbIndirect == 0 {
(*TSessionChange)(unsafe.Pointer(pC)).FbIndirect = uint8(0)
}
}
}
if (*Tsqlite3_session)(unsafe.Pointer(pSession)).FbEnableSize != 0 {
rc = _sessionUpdateMaxSize(tls, op, pSession, pTab, pC)
}
}
/* If an error has occurred, mark the session object as failed. */
goto error_out
error_out:
;
if (*TSessionTable)(unsafe.Pointer(pTab)).FbStat1 != 0 {
(*Tsqlite3_session)(unsafe.Pointer(pSession)).Fhook = (**(**TSessionStat1Ctx)(__ccgo_up(bp + 8))).Fhook
}
if rc != SQLITE_OK {
(*Tsqlite3_session)(unsafe.Pointer(pSession)).Frc = rc
}
}
// C documentation
//
// /*
// ** Write a double value to the buffer aBuf[].
// */
func _sessionPutDouble(tls *libc.TLS, aBuf uintptr, _r float64) {
bp := tls.Alloc(16)
defer tls.Free(16)
*(*float64)(unsafe.Pointer(bp)) = _r
var _ /* i at bp+8 */ Tu64
libc.X__builtin___memcpy_chk(tls, bp+8, bp, uint64(8), ^t__predefined_size_t(0))
_sessionPutI64(tls, aBuf, libc.Int64FromUint64(**(**Tu64)(__ccgo_up(bp + 8))))
}
// C documentation
//
// /*
// ** Deserialize a single record from a buffer in memory. See "RECORD FORMAT"
// ** for details.
// **
// ** When this function is called, *paChange points to the start of the record
// ** to deserialize. Assuming no error occurs, *paChange is set to point to
// ** one byte after the end of the same record before this function returns.
// ** If the argument abPK is NULL, then the record contains nCol values. Or,
// ** if abPK is other than NULL, then the record contains only the PK fields
// ** (in other words, it is a patchset DELETE record).
// **
// ** If successful, each element of the apOut[] array (allocated by the caller)
// ** is set to point to an sqlite3_value object containing the value read
// ** from the corresponding position in the record. If that value is not
// ** included in the record (i.e. because the record is part of an UPDATE change
// ** and the field was not modified), the corresponding element of apOut[] is
// ** set to NULL.
// **
// ** It is the responsibility of the caller to free all sqlite_value structures
// ** using sqlite3_free().
// **
// ** If an error occurs, an SQLite error code (e.g. SQLITE_NOMEM) is returned.
// ** The apOut[] array may have been partially populated in this case.
// */
func _sessionReadRecord(tls *libc.TLS, pIn uintptr, nCol int32, abPK uintptr, apOut uintptr, pbEmpty uintptr) (r int32) {
bp := tls.Alloc(32)
defer tls.Free(32)
var aVal, v3 uintptr
var eType, i, nRem, rc, v2 int32
var enc Tu8
var _ /* d at bp+16 */ float64
var _ /* nByte at bp+0 */ int32
var _ /* v at bp+8 */ Tsqlite3_int64
_, _, _, _, _, _, _, _ = aVal, eType, enc, i, nRem, rc, v2, v3 /* Used to iterate through columns */
rc = SQLITE_OK
if pbEmpty != 0 {
**(**int32)(__ccgo_up(pbEmpty)) = int32(1)
}
i = 0
for {
if !(i < nCol && rc == SQLITE_OK) {
break
}
eType = 0 /* Type of value (SQLITE_NULL, TEXT etc.) */
if abPK != 0 && libc.Int32FromUint8(**(**Tu8)(__ccgo_up(abPK + uintptr(i)))) == 0 {
goto _1
}
rc = _sessionInputBuffer(tls, pIn, int32(9))
if rc == SQLITE_OK {
if (*TSessionInput)(unsafe.Pointer(pIn)).FiNext >= (*TSessionInput)(unsafe.Pointer(pIn)).FnData {
rc = _sqlite3CorruptError(tls, int32(237320))
} else {
v3 = pIn + 8
v2 = *(*int32)(unsafe.Pointer(v3))
*(*int32)(unsafe.Pointer(v3)) = *(*int32)(unsafe.Pointer(v3)) + 1
eType = libc.Int32FromUint8(**(**Tu8)(__ccgo_up((*TSessionInput)(unsafe.Pointer(pIn)).FaData + uintptr(v2))))
if eType != 0 {
if pbEmpty != 0 {
**(**int32)(__ccgo_up(pbEmpty)) = 0
}
**(**uintptr)(__ccgo_up(apOut + uintptr(i)*8)) = _sqlite3ValueNew(tls, uintptr(0))
if !(**(**uintptr)(__ccgo_up(apOut + uintptr(i)*8)) != 0) {
rc = int32(SQLITE_NOMEM)
}
}
}
}
if rc == SQLITE_OK {
aVal = (*TSessionInput)(unsafe.Pointer(pIn)).FaData + uintptr((*TSessionInput)(unsafe.Pointer(pIn)).FiNext)
if eType == int32(SQLITE_TEXT) || eType == int32(SQLITE_BLOB) {
nRem = (*TSessionInput)(unsafe.Pointer(pIn)).FnData - (*TSessionInput)(unsafe.Pointer(pIn)).FiNext
**(**int32)(__ccgo_up(pIn + 8)) += _sessionVarintGetSafe(tls, aVal, nRem, bp)
rc = _sessionInputBuffer(tls, pIn, **(**int32)(__ccgo_up(bp)))
if rc == SQLITE_OK {
if **(**int32)(__ccgo_up(bp)) < 0 || **(**int32)(__ccgo_up(bp)) > (*TSessionInput)(unsafe.Pointer(pIn)).FnData-(*TSessionInput)(unsafe.Pointer(pIn)).FiNext {
rc = _sqlite3CorruptError(tls, int32(237341))
} else {
if eType == int32(SQLITE_TEXT) {
v2 = int32(SQLITE_UTF8)
} else {
v2 = 0
}
enc = libc.Uint8FromInt32(v2)
rc = _sessionValueSetStr(tls, **(**uintptr)(__ccgo_up(apOut + uintptr(i)*8)), (*TSessionInput)(unsafe.Pointer(pIn)).FaData+uintptr((*TSessionInput)(unsafe.Pointer(pIn)).FiNext), **(**int32)(__ccgo_up(bp)), enc)
**(**int32)(__ccgo_up(pIn + 8)) += **(**int32)(__ccgo_up(bp))
}
}
}
if eType == int32(SQLITE_INTEGER) || eType == int32(SQLITE_FLOAT) {
if (*TSessionInput)(unsafe.Pointer(pIn)).FnData-(*TSessionInput)(unsafe.Pointer(pIn)).FiNext < int32(8) {
rc = _sqlite3CorruptError(tls, int32(237351))
} else {
**(**Tsqlite3_int64)(__ccgo_up(bp + 8)) = _sessionGetI64(tls, aVal)
if eType == int32(SQLITE_INTEGER) {
_sqlite3VdbeMemSetInt64(tls, **(**uintptr)(__ccgo_up(apOut + uintptr(i)*8)), **(**Tsqlite3_int64)(__ccgo_up(bp + 8)))
} else {
libc.X__builtin___memcpy_chk(tls, bp+16, bp+8, uint64(8), ^t__predefined_size_t(0))
_sqlite3VdbeMemSetDouble(tls, **(**uintptr)(__ccgo_up(apOut + uintptr(i)*8)), **(**float64)(__ccgo_up(bp + 16)))
}
**(**int32)(__ccgo_up(pIn + 8)) += int32(8)
}
}
}
goto _1
_1:
;
i = i + 1
}
return rc
}
// C documentation
//
// /*
// ** pIter is configured to iterate through a changeset. This function rebases
// ** that changeset according to the current configuration of the rebaser
// ** object passed as the first argument. If no error occurs and argument xOutput
// ** is not NULL, then the changeset is returned to the caller by invoking
// ** xOutput zero or more times and SQLITE_OK returned. Or, if xOutput is NULL,
// ** then (*ppOut) is set to point to a buffer containing the rebased changeset
// ** before this function returns. In this case (*pnOut) is set to the size of
// ** the buffer in bytes. It is the responsibility of the caller to eventually
// ** free the (*ppOut) buffer using sqlite3_free().
// **
// ** If an error occurs, an SQLite error code is returned. If ppOut and
// ** pnOut are not NULL, then the two output parameters are set to 0 before
// ** returning.
// */
func _sessionRebase(tls *libc.TLS, p uintptr, pIter uintptr, __ccgo_fp_xOutput uintptr, pOut uintptr, pnOut uintptr, ppOut uintptr) (r int32) {
bp := tls.Alloc(48)
defer tls.Free(48)
var bDone, iHash, v2 int32
var pChange, pTab, zTab uintptr
var _ /* aRec at bp+8 */ uintptr
var _ /* bNew at bp+20 */ int32
var _ /* nRec at bp+16 */ int32
var _ /* pCsr at bp+40 */ uintptr
var _ /* rc at bp+0 */ int32
var _ /* sOut at bp+24 */ TSessionBuffer
_, _, _, _, _, _ = bDone, iHash, pChange, pTab, zTab, v2
**(**int32)(__ccgo_up(bp)) = SQLITE_OK
**(**uintptr)(__ccgo_up(bp + 8)) = uintptr(0)
**(**int32)(__ccgo_up(bp + 16)) = 0
**(**int32)(__ccgo_up(bp + 20)) = 0
pTab = uintptr(0)
**(**TSessionBuffer)(__ccgo_up(bp + 24)) = TSessionBuffer{}
for int32(SQLITE_ROW) == _sessionChangesetNext(tls, pIter, bp+8, bp+16, bp+20) {
pChange = uintptr(0)
bDone = 0
if **(**int32)(__ccgo_up(bp + 20)) != 0 {
zTab = (*Tsqlite3_changeset_iter)(unsafe.Pointer(pIter)).FzTab
pTab = (*Tsqlite3_rebaser)(unsafe.Pointer(p)).Fgrp.FpList
for {
if !(pTab != 0) {
break
}
if 0 == Xsqlite3_stricmp(tls, (*TSessionTable)(unsafe.Pointer(pTab)).FzName, zTab) {
break
}
goto _1
_1:
;
pTab = (*TSessionTable)(unsafe.Pointer(pTab)).FpNext
}
**(**int32)(__ccgo_up(bp + 20)) = 0
/* A patchset may not be rebased */
if (*Tsqlite3_changeset_iter)(unsafe.Pointer(pIter)).FbPatchset != 0 {
**(**int32)(__ccgo_up(bp)) = int32(SQLITE_ERROR)
}
/* Append a table header to the output for this new table */
if (*Tsqlite3_changeset_iter)(unsafe.Pointer(pIter)).FbPatchset != 0 {
v2 = int32('P')
} else {
v2 = int32('T')
}
_sessionAppendByte(tls, bp+24, libc.Uint8FromInt32(v2), bp)
_sessionAppendVarint(tls, bp+24, (*Tsqlite3_changeset_iter)(unsafe.Pointer(pIter)).FnCol, bp)
_sessionAppendBlob(tls, bp+24, (*Tsqlite3_changeset_iter)(unsafe.Pointer(pIter)).FabPK, (*Tsqlite3_changeset_iter)(unsafe.Pointer(pIter)).FnCol, bp)
_sessionAppendBlob(tls, bp+24, (*Tsqlite3_changeset_iter)(unsafe.Pointer(pIter)).FzTab, libc.Int32FromUint64(libc.Xstrlen(tls, (*Tsqlite3_changeset_iter)(unsafe.Pointer(pIter)).FzTab))+int32(1), bp)
}
if pTab != 0 && **(**int32)(__ccgo_up(bp)) == SQLITE_OK {
iHash = libc.Int32FromUint32(_sessionChangeHash(tls, pTab, 0, **(**uintptr)(__ccgo_up(bp + 8)), (*TSessionTable)(unsafe.Pointer(pTab)).FnChange))
pChange = **(**uintptr)(__ccgo_up((*TSessionTable)(unsafe.Pointer(pTab)).FapChange + uintptr(iHash)*8))
for {
if !(pChange != 0) {
break
}
if _sessionChangeEqual(tls, pTab, 0, **(**uintptr)(__ccgo_up(bp + 8)), 0, (*TSessionChange)(unsafe.Pointer(pChange)).FaRecord) != 0 {
break
}
goto _3
_3:
;
pChange = (*TSessionChange)(unsafe.Pointer(pChange)).FpNext
}
}
if pChange != 0 {
switch (*Tsqlite3_changeset_iter)(unsafe.Pointer(pIter)).Fop {
case int32(SQLITE_INSERT):
if libc.Int32FromUint8((*TSessionChange)(unsafe.Pointer(pChange)).Fop) == int32(SQLITE_INSERT) {
bDone = int32(1)
if libc.Int32FromUint8((*TSessionChange)(unsafe.Pointer(pChange)).FbIndirect) == 0 {
_sessionAppendByte(tls, bp+24, uint8(SQLITE_UPDATE), bp)
_sessionAppendByte(tls, bp+24, libc.Uint8FromInt32((*Tsqlite3_changeset_iter)(unsafe.Pointer(pIter)).FbIndirect), bp)
_sessionAppendBlob(tls, bp+24, (*TSessionChange)(unsafe.Pointer(pChange)).FaRecord, (*TSessionChange)(unsafe.Pointer(pChange)).FnRecord, bp)
_sessionAppendBlob(tls, bp+24, **(**uintptr)(__ccgo_up(bp + 8)), **(**int32)(__ccgo_up(bp + 16)), bp)
}
}
case int32(SQLITE_UPDATE):
bDone = int32(1)
if libc.Int32FromUint8((*TSessionChange)(unsafe.Pointer(pChange)).Fop) == int32(SQLITE_DELETE) {
if libc.Int32FromUint8((*TSessionChange)(unsafe.Pointer(pChange)).FbIndirect) == 0 {
**(**uintptr)(__ccgo_up(bp + 40)) = **(**uintptr)(__ccgo_up(bp + 8))
_sessionSkipRecord(tls, bp+40, (*Tsqlite3_changeset_iter)(unsafe.Pointer(pIter)).FnCol)
_sessionAppendByte(tls, bp+24, uint8(SQLITE_INSERT), bp)
_sessionAppendByte(tls, bp+24, libc.Uint8FromInt32((*Tsqlite3_changeset_iter)(unsafe.Pointer(pIter)).FbIndirect), bp)
_sessionAppendRecordMerge(tls, bp+24, (*Tsqlite3_changeset_iter)(unsafe.Pointer(pIter)).FnCol, **(**uintptr)(__ccgo_up(bp + 40)), int32(int64(**(**int32)(__ccgo_up(bp + 16)))-(int64(**(**uintptr)(__ccgo_up(bp + 40)))-int64(**(**uintptr)(__ccgo_up(bp + 8))))), (*TSessionChange)(unsafe.Pointer(pChange)).FaRecord, (*TSessionChange)(unsafe.Pointer(pChange)).FnRecord, bp)
}
} else {
_sessionAppendPartialUpdate(tls, bp+24, pIter, **(**uintptr)(__ccgo_up(bp + 8)), **(**int32)(__ccgo_up(bp + 16)), (*TSessionChange)(unsafe.Pointer(pChange)).FaRecord, (*TSessionChange)(unsafe.Pointer(pChange)).FnRecord, bp)
}
default:
bDone = int32(1)
if libc.Int32FromUint8((*TSessionChange)(unsafe.Pointer(pChange)).Fop) == int32(SQLITE_INSERT) {
_sessionAppendByte(tls, bp+24, uint8(SQLITE_DELETE), bp)
_sessionAppendByte(tls, bp+24, libc.Uint8FromInt32((*Tsqlite3_changeset_iter)(unsafe.Pointer(pIter)).FbIndirect), bp)
_sessionAppendRecordMerge(tls, bp+24, (*Tsqlite3_changeset_iter)(unsafe.Pointer(pIter)).FnCol, (*TSessionChange)(unsafe.Pointer(pChange)).FaRecord, (*TSessionChange)(unsafe.Pointer(pChange)).FnRecord, **(**uintptr)(__ccgo_up(bp + 8)), **(**int32)(__ccgo_up(bp + 16)), bp)
}
break
}
}
if bDone == 0 {
_sessionAppendByte(tls, bp+24, libc.Uint8FromInt32((*Tsqlite3_changeset_iter)(unsafe.Pointer(pIter)).Fop), bp)
_sessionAppendByte(tls, bp+24, libc.Uint8FromInt32((*Tsqlite3_changeset_iter)(unsafe.Pointer(pIter)).FbIndirect), bp)
_sessionAppendBlob(tls, bp+24, **(**uintptr)(__ccgo_up(bp + 8)), **(**int32)(__ccgo_up(bp + 16)), bp)
}
if **(**int32)(__ccgo_up(bp)) == SQLITE_OK && __ccgo_fp_xOutput != 0 && (**(**TSessionBuffer)(__ccgo_up(bp + 24))).FnBuf > _sessions_strm_chunk_size {
**(**int32)(__ccgo_up(bp)) = (*(*func(*libc.TLS, uintptr, uintptr, int32) int32)(unsafe.Pointer(&struct{ uintptr }{__ccgo_fp_xOutput})))(tls, pOut, (**(**TSessionBuffer)(__ccgo_up(bp + 24))).FaBuf, (**(**TSessionBuffer)(__ccgo_up(bp + 24))).FnBuf)
(**(**TSessionBuffer)(__ccgo_up(bp + 24))).FnBuf = 0
}
if **(**int32)(__ccgo_up(bp)) != 0 {
break
}
}
if **(**int32)(__ccgo_up(bp)) != SQLITE_OK {
Xsqlite3_free(tls, (**(**TSessionBuffer)(__ccgo_up(bp + 24))).FaBuf)
libc.X__builtin___memset_chk(tls, bp+24, 0, uint64(16), ^t__predefined_size_t(0))
}
if **(**int32)(__ccgo_up(bp)) == SQLITE_OK {
if __ccgo_fp_xOutput != 0 {
if (**(**TSessionBuffer)(__ccgo_up(bp + 24))).FnBuf > 0 {
**(**int32)(__ccgo_up(bp)) = (*(*func(*libc.TLS, uintptr, uintptr, int32) int32)(unsafe.Pointer(&struct{ uintptr }{__ccgo_fp_xOutput})))(tls, pOut, (**(**TSessionBuffer)(__ccgo_up(bp + 24))).FaBuf, (**(**TSessionBuffer)(__ccgo_up(bp + 24))).FnBuf)
}
} else {
if ppOut != 0 {
**(**uintptr)(__ccgo_up(ppOut)) = (**(**TSessionBuffer)(__ccgo_up(bp + 24))).FaBuf
**(**int32)(__ccgo_up(pnOut)) = (**(**TSessionBuffer)(__ccgo_up(bp + 24))).FnBuf
(**(**TSessionBuffer)(__ccgo_up(bp + 24))).FaBuf = uintptr(0)
}
}
}
Xsqlite3_free(tls, (**(**TSessionBuffer)(__ccgo_up(bp + 24))).FaBuf)
return **(**int32)(__ccgo_up(bp))
}
// C documentation
//
// /*
// ** Retry the changes accumulated in the pApply->constraints buffer. The
// ** pApply->constraints buffer contains all changes to table zTab that
// ** could not be applied due to SQLITE_CONSTRAINT errors. This function
// ** attempts to apply them as follows:
// **
// ** 1) It runs through the buffer and attempts to retry each change,
// ** removing any that are successfully applied from the buffer. This
// ** is repeated until no further progress can be made.
// **
// ** 2) For each UPDATE change in the buffer, try the following in a
// ** savepoint transaction:
// **
// ** a) DELETE the affected row,
// ** b) Attempt step (1) with remaining changes,
// ** c) Attempt to INSERT a row equivalent to the one that would be
// ** created by applying this UPDATE change.
// **
// ** If the INSERT in (c) succeeds, the savepoint is committed and all
// ** successfully applied changes are removed from the buffer. Step (2)
// ** is then repeated.
// **
// ** 3) Once step (2) has been attempted for each UPDATE in the change,
// ** a final attempt is made to apply each remaining change. This time,
// ** if an SQLITE_CONSTRAINT error is encountered, the conflict handler
// ** is invoked and the user has to decide whether to omit the change
// ** or rollback the entire _apply() operation.
// */
func _sessionRetryConstraints(tls *libc.TLS, db uintptr, bPatchset int32, zTab uintptr, pApply uintptr, __ccgo_fp_xConflict uintptr, pCtx uintptr) (r int32) {
bp := tls.Alloc(80)
defer tls.Free(80)
var iSkip, iThis, iUpdate, rc int32
var _ /* app at bp+48 */ TSessionBuffer
var _ /* cons at bp+0 */ TSessionBuffer
var _ /* cons at bp+16 */ TSessionBuffer
var _ /* cons at bp+64 */ TSessionBuffer
var _ /* pInsert at bp+40 */ uintptr
var _ /* pUp at bp+32 */ uintptr
_, _, _, _ = iSkip, iThis, iUpdate, rc
rc = SQLITE_OK
iUpdate = 0
/* Step (1) */
for (*TSessionApplyCtx)(unsafe.Pointer(pApply)).Fconstraints.FnBuf != 0 {
**(**TSessionBuffer)(__ccgo_up(bp)) = (*TSessionApplyCtx)(unsafe.Pointer(pApply)).Fconstraints
libc.X__builtin___memset_chk(tls, pApply+88, 0, uint64(16), ^t__predefined_size_t(0))
rc = _sessionApplyRetryBuffer(tls, bp, -int32(1), db, bPatchset, zTab, pApply, __ccgo_fp_xConflict, pCtx)
Xsqlite3_free(tls, (**(**TSessionBuffer)(__ccgo_up(bp))).FaBuf)
if rc != SQLITE_OK {
break
}
/* If no progress has been made this round, break out of the loop. */
if (*TSessionApplyCtx)(unsafe.Pointer(pApply)).Fconstraints.FnBuf >= (**(**TSessionBuffer)(__ccgo_up(bp))).FnBuf {
break
}
}
/* Step (2) */
for rc == SQLITE_OK && (*TSessionApplyCtx)(unsafe.Pointer(pApply)).Fconstraints.FnBuf != 0 && !((*TSessionApplyCtx)(unsafe.Pointer(pApply)).FbNoUpdateLoop != 0) {
**(**TSessionBuffer)(__ccgo_up(bp + 16)) = TSessionBuffer{}
**(**uintptr)(__ccgo_up(bp + 32)) = uintptr(0)
**(**uintptr)(__ccgo_up(bp + 40)) = uintptr(0)
iSkip = 0
rc = _sessionRetryIterInit(tls, pApply+88, bPatchset, zTab, pApply, bp+32)
if rc == SQLITE_OK {
iThis = -int32(1)
for int32(SQLITE_ROW) == Xsqlite3changeset_next(tls, **(**uintptr)(__ccgo_up(bp + 32))) {
if (*Tsqlite3_changeset_iter)(unsafe.Pointer(**(**uintptr)(__ccgo_up(bp + 32)))).Fop == int32(SQLITE_UPDATE) {
iThis = iThis + 1
}
if iThis == iUpdate {
break
}
iSkip = iSkip + 1
}
if iThis == iUpdate {
rc = Xsqlite3_exec(tls, db, __ccgo_ts+36846, uintptr(0), uintptr(0), uintptr(0))
if rc == SQLITE_OK {
rc = _sessionUpdateToDeleteInsert(tls, db, zTab, pApply, **(**uintptr)(__ccgo_up(bp + 32)), bp+40)
}
}
Xsqlite3changeset_finalize(tls, **(**uintptr)(__ccgo_up(bp + 32)))
if iThis != iUpdate {
break
}
}
if rc == SQLITE_OK {
**(**TSessionBuffer)(__ccgo_up(bp + 16)) = (*TSessionApplyCtx)(unsafe.Pointer(pApply)).Fconstraints
for rc == SQLITE_OK && (*TSessionApplyCtx)(unsafe.Pointer(pApply)).Fconstraints.FnBuf > 0 {
**(**TSessionBuffer)(__ccgo_up(bp + 48)) = (*TSessionApplyCtx)(unsafe.Pointer(pApply)).Fconstraints
libc.X__builtin___memset_chk(tls, pApply+88, 0, uint64(16), ^t__predefined_size_t(0))
rc = _sessionApplyRetryBuffer(tls, bp+48, iSkip, db, bPatchset, zTab, pApply, __ccgo_fp_xConflict, pCtx)
if (**(**TSessionBuffer)(__ccgo_up(bp + 48))).FaBuf != (**(**TSessionBuffer)(__ccgo_up(bp + 16))).FaBuf {
Xsqlite3_free(tls, (**(**TSessionBuffer)(__ccgo_up(bp + 48))).FaBuf)
}
if (*TSessionApplyCtx)(unsafe.Pointer(pApply)).Fconstraints.FnBuf >= (**(**TSessionBuffer)(__ccgo_up(bp + 48))).FnBuf {
break
}
iSkip = -int32(1)
}
}
iUpdate = iUpdate + 1
if rc == SQLITE_OK {
Xsqlite3_step(tls, **(**uintptr)(__ccgo_up(bp + 40)))
rc = Xsqlite3_finalize(tls, **(**uintptr)(__ccgo_up(bp + 40)))
if rc == int32(SQLITE_CONSTRAINT) {
rc = Xsqlite3_exec(tls, db, __ccgo_ts+36866, uintptr(0), uintptr(0), uintptr(0))
Xsqlite3_free(tls, (*TSessionApplyCtx)(unsafe.Pointer(pApply)).Fconstraints.FaBuf)
(*TSessionApplyCtx)(unsafe.Pointer(pApply)).Fconstraints = **(**TSessionBuffer)(__ccgo_up(bp + 16))
libc.X__builtin___memset_chk(tls, bp+16, 0, uint64(16), ^t__predefined_size_t(0))
} else {
if rc == SQLITE_OK {
iUpdate = 0
}
}
if rc == SQLITE_OK {
rc = Xsqlite3_exec(tls, db, __ccgo_ts+36888, uintptr(0), uintptr(0), uintptr(0))
}
} else {
Xsqlite3_finalize(tls, **(**uintptr)(__ccgo_up(bp + 40)))
}
Xsqlite3_free(tls, (**(**TSessionBuffer)(__ccgo_up(bp + 16))).FaBuf)
}
/* Step (3) */
if rc == SQLITE_OK && (*TSessionApplyCtx)(unsafe.Pointer(pApply)).Fconstraints.FnBuf != 0 {
**(**TSessionBuffer)(__ccgo_up(bp + 64)) = (*TSessionApplyCtx)(unsafe.Pointer(pApply)).Fconstraints
libc.X__builtin___memset_chk(tls, pApply+88, 0, uint64(16), ^t__predefined_size_t(0))
(*TSessionApplyCtx)(unsafe.Pointer(pApply)).FbDeferConstraints = 0
rc = _sessionApplyRetryBuffer(tls, bp+64, -int32(1), db, bPatchset, zTab, pApply, __ccgo_fp_xConflict, pCtx)
Xsqlite3_free(tls, (**(**TSessionBuffer)(__ccgo_up(bp + 64))).FaBuf)
}
return rc
}
// C documentation
//
// /*
// ** Create an iterator to iterate through the retry buffer pRetry.
// */
func _sessionRetryIterInit(tls *libc.TLS, pRetry uintptr, bPatchset int32, zTab uintptr, pApply uintptr, ppIter uintptr) (r int32) {
bp := tls.Alloc(16)
defer tls.Free(16)
var nByte Tsize_t
var _ /* pRet at bp+0 */ uintptr
var _ /* rc at bp+8 */ int32
_ = nByte
**(**uintptr)(__ccgo_up(bp)) = uintptr(0)
**(**int32)(__ccgo_up(bp + 8)) = SQLITE_OK
**(**int32)(__ccgo_up(bp + 8)) = _sessionChangesetStart(tls, bp, uintptr(0), uintptr(0), (*TSessionBuffer)(unsafe.Pointer(pRetry)).FnBuf, (*TSessionBuffer)(unsafe.Pointer(pRetry)).FaBuf, (*TSessionApplyCtx)(unsafe.Pointer(pApply)).FbInvertConstraints, int32(1))
if **(**int32)(__ccgo_up(bp + 8)) == SQLITE_OK {
nByte = libc.Uint64FromInt32(int32(2)*(*TSessionApplyCtx)(unsafe.Pointer(pApply)).FnCol) * uint64(8)
(*Tsqlite3_changeset_iter)(unsafe.Pointer(**(**uintptr)(__ccgo_up(bp)))).FbPatchset = bPatchset
(*Tsqlite3_changeset_iter)(unsafe.Pointer(**(**uintptr)(__ccgo_up(bp)))).FzTab = zTab
(*Tsqlite3_changeset_iter)(unsafe.Pointer(**(**uintptr)(__ccgo_up(bp)))).FnCol = (*TSessionApplyCtx)(unsafe.Pointer(pApply)).FnCol
(*Tsqlite3_changeset_iter)(unsafe.Pointer(**(**uintptr)(__ccgo_up(bp)))).FabPK = (*TSessionApplyCtx)(unsafe.Pointer(pApply)).FabPK
_sessionBufferGrow(tls, **(**uintptr)(__ccgo_up(bp))+72, libc.Int64FromUint64(nByte), bp+8)
(*Tsqlite3_changeset_iter)(unsafe.Pointer(**(**uintptr)(__ccgo_up(bp)))).FapValue = (*Tsqlite3_changeset_iter)(unsafe.Pointer(**(**uintptr)(__ccgo_up(bp)))).Ftblhdr.FaBuf
if **(**int32)(__ccgo_up(bp + 8)) == SQLITE_OK {
libc.X__builtin___memset_chk(tls, (*Tsqlite3_changeset_iter)(unsafe.Pointer(**(**uintptr)(__ccgo_up(bp)))).FapValue, 0, nByte, ^t__predefined_size_t(0))
} else {
Xsqlite3changeset_finalize(tls, **(**uintptr)(__ccgo_up(bp)))
**(**uintptr)(__ccgo_up(bp)) = uintptr(0)
}
}
**(**uintptr)(__ccgo_up(ppIter)) = **(**uintptr)(__ccgo_up(bp))
return **(**int32)(__ccgo_up(bp + 8))
}
// C documentation
//
// /*
// ** Bind the PRIMARY KEY values from the change passed in argument pChange
// ** to the SELECT statement passed as the first argument. The SELECT statement
// ** is as prepared by function sessionSelectStmt().
// **
// ** Return SQLITE_OK if all PK values are successfully bound, or an SQLite
// ** error code (e.g. SQLITE_NOMEM) otherwise.
// */
func _sessionSelectBind(tls *libc.TLS, pSelect uintptr, nCol int32, abPK uintptr, pChange uintptr) (r int32) {
bp := tls.Alloc(32)
defer tls.Free(32)
var a, v2 uintptr
var eType, i, rc int32
var iVal Ti64
var _ /* iVal at bp+8 */ Ti64
var _ /* n at bp+16 */ int32
var _ /* n at bp+20 */ int32
var _ /* rVal at bp+0 */ float64
_, _, _, _, _, _ = a, eType, i, iVal, rc, v2
rc = SQLITE_OK
a = (*TSessionChange)(unsafe.Pointer(pChange)).FaRecord
i = 0
for {
if !(i < nCol && rc == SQLITE_OK) {
break
}
v2 = a
a = a + 1
eType = libc.Int32FromUint8(**(**Tu8)(__ccgo_up(v2)))
switch eType {
case 0:
fallthrough
case int32(SQLITE_NULL):
case int32(SQLITE_INTEGER):
if **(**Tu8)(__ccgo_up(abPK + uintptr(i))) != 0 {
iVal = _sessionGetI64(tls, a)
rc = Xsqlite3_bind_int64(tls, pSelect, i+int32(1), iVal)
}
a = a + uintptr(8)
case int32(SQLITE_FLOAT):
if **(**Tu8)(__ccgo_up(abPK + uintptr(i))) != 0 {
**(**Ti64)(__ccgo_up(bp + 8)) = _sessionGetI64(tls, a)
libc.X__builtin___memcpy_chk(tls, bp, bp+8, uint64(8), ^t__predefined_size_t(0))
rc = Xsqlite3_bind_double(tls, pSelect, i+int32(1), **(**float64)(__ccgo_up(bp)))
}
a = a + uintptr(8)
case int32(SQLITE_TEXT):
a = a + uintptr(_sessionVarintGet(tls, a, bp+16))
if **(**Tu8)(__ccgo_up(abPK + uintptr(i))) != 0 {
rc = Xsqlite3_bind_text(tls, pSelect, i+int32(1), a, **(**int32)(__ccgo_up(bp + 16)), uintptr(-libc.Int32FromInt32(1)))
}
a = a + uintptr(**(**int32)(__ccgo_up(bp + 16)))
default:
a = a + uintptr(_sessionVarintGet(tls, a, bp+20))
if **(**Tu8)(__ccgo_up(abPK + uintptr(i))) != 0 {
rc = Xsqlite3_bind_blob(tls, pSelect, i+int32(1), a, **(**int32)(__ccgo_up(bp + 20)), uintptr(-libc.Int32FromInt32(1)))
}
a = a + uintptr(**(**int32)(__ccgo_up(bp + 20)))
break
}
goto _1
_1:
;
i = i + 1
}
return rc
}
func _sessionSelectFindNew(tls *libc.TLS, zDb1 uintptr, zDb2 uintptr, bRowid int32, zTbl uintptr, zExpr uintptr) (r uintptr) {
bp := tls.Alloc(64)
defer tls.Free(64)
var zRet, zSel, v1 uintptr
_, _, _ = zRet, zSel, v1
if bRowid != 0 {
v1 = __ccgo_ts + 35830
} else {
v1 = __ccgo_ts + 7169
}
zSel = v1
zRet = Xsqlite3_mprintf(tls, __ccgo_ts+35841, libc.VaList(bp+8, zSel, zDb1, zTbl, zDb2, zTbl, zExpr))
return zRet
}
// C documentation
//
// /*
// ** Formulate and prepare an SQL statement to query table zTab by primary
// ** key. Assuming the following table structure:
// **
// ** CREATE TABLE x(a, b, c, d, PRIMARY KEY(a, c));
// **
// ** The SELECT statement looks like this:
// **
// ** SELECT * FROM x WHERE a = ?1 AND c = ?3
// **
// ** If successful, SQLITE_OK is returned and SessionApplyCtx.pSelect is left
// ** pointing to the prepared version of the SQL statement.
// */
func _sessionSelectRow(tls *libc.TLS, db uintptr, zTab uintptr, p uintptr) (r int32) {
/* TODO */
return _sessionSelectStmt(tls, db, libc.Int32FromUint8((*TSessionApplyCtx)(unsafe.Pointer(p)).FbIgnoreNoop), __ccgo_ts+7164, zTab, (*TSessionApplyCtx)(unsafe.Pointer(p)).FbRowid, (*TSessionApplyCtx)(unsafe.Pointer(p)).FnCol, (*TSessionApplyCtx)(unsafe.Pointer(p)).FazCol, (*TSessionApplyCtx)(unsafe.Pointer(p)).FabPK, p+24, p+128)
}
// C documentation
//
// /*
// ** Formulate and prepare a SELECT statement to retrieve a row from table
// ** zTab in database zDb based on its primary key. i.e.
// **
// ** SELECT *, FROM zDb.zTab WHERE (pk1, pk2,...) IS (?1, ?2,...)
// **
// ** where is:
// **
// ** 1 AND (?A OR ?1 IS ) AND ...
// **
// ** for each non-pk .
// */
func _sessionSelectStmt(tls *libc.TLS, db uintptr, bIgnoreNoop int32, zDb uintptr, zTab uintptr, bRowid int32, nCol int32, azCol uintptr, abPK uintptr, ppStmt uintptr, pzErrmsg uintptr) (r int32) {
bp := tls.Alloc(128)
defer tls.Free(128)
var i int32
var zSep, zSql, v2 uintptr
var _ /* cols at bp+8 */ TSessionBuffer
var _ /* nooptest at bp+24 */ TSessionBuffer
var _ /* pkfield at bp+40 */ TSessionBuffer
var _ /* pkvar at bp+56 */ TSessionBuffer
var _ /* rc at bp+0 */ int32
_, _, _, _ = i, zSep, zSql, v2
**(**int32)(__ccgo_up(bp)) = SQLITE_OK
zSql = uintptr(0)
zSep = __ccgo_ts + 1702
**(**TSessionBuffer)(__ccgo_up(bp + 8)) = TSessionBuffer{}
**(**TSessionBuffer)(__ccgo_up(bp + 24)) = TSessionBuffer{}
**(**TSessionBuffer)(__ccgo_up(bp + 40)) = TSessionBuffer{}
**(**TSessionBuffer)(__ccgo_up(bp + 56)) = TSessionBuffer{}
_sessionAppendStr(tls, bp+24, __ccgo_ts+36075, bp)
if 0 == Xsqlite3_stricmp(tls, __ccgo_ts+13181, zTab) {
_sessionAppendStr(tls, bp+24, __ccgo_ts+36079, bp)
_sessionAppendStr(tls, bp+40, __ccgo_ts+36103, bp)
_sessionAppendStr(tls, bp+56, __ccgo_ts+36112, bp)
_sessionAppendStr(tls, bp+8, __ccgo_ts+36157, bp)
} else {
i = 0
for {
if !(i < nCol) {
break
}
if (**(**TSessionBuffer)(__ccgo_up(bp + 8))).FnBuf != 0 {
_sessionAppendStr(tls, bp+8, __ccgo_ts+16562, bp)
}
_sessionAppendIdent(tls, bp+8, **(**uintptr)(__ccgo_up(azCol + uintptr(i)*8)), bp)
if **(**Tu8)(__ccgo_up(abPK + uintptr(i))) != 0 {
_sessionAppendStr(tls, bp+40, zSep, bp)
_sessionAppendStr(tls, bp+56, zSep, bp)
zSep = __ccgo_ts + 16562
_sessionAppendIdent(tls, bp+40, **(**uintptr)(__ccgo_up(azCol + uintptr(i)*8)), bp)
_sessionAppendPrintf(tls, bp+56, bp, __ccgo_ts+36171, libc.VaList(bp+80, i+int32(1)))
} else {
_sessionAppendPrintf(tls, bp+24, bp, __ccgo_ts+36175, libc.VaList(bp+80, i+int32(1)+nCol, i+int32(1), zTab, **(**uintptr)(__ccgo_up(azCol + uintptr(i)*8))))
}
goto _1
_1:
;
i = i + 1
}
}
if **(**int32)(__ccgo_up(bp)) == SQLITE_OK {
if bIgnoreNoop != 0 {
v2 = (**(**TSessionBuffer)(__ccgo_up(bp + 24))).FaBuf
} else {
v2 = __ccgo_ts + 1702
}
zSql = Xsqlite3_mprintf(tls, __ccgo_ts+36202, libc.VaList(bp+80, (**(**TSessionBuffer)(__ccgo_up(bp + 8))).FaBuf, v2, zDb, zTab, (**(**TSessionBuffer)(__ccgo_up(bp + 40))).FaBuf, (**(**TSessionBuffer)(__ccgo_up(bp + 56))).FaBuf))
if zSql == uintptr(0) {
**(**int32)(__ccgo_up(bp)) = int32(SQLITE_NOMEM)
}
}
if **(**int32)(__ccgo_up(bp)) == SQLITE_OK {
**(**int32)(__ccgo_up(bp)) = _sessionPrepare(tls, db, ppStmt, pzErrmsg, zSql)
}
Xsqlite3_free(tls, zSql)
Xsqlite3_free(tls, (**(**TSessionBuffer)(__ccgo_up(bp + 24))).FaBuf)
Xsqlite3_free(tls, (**(**TSessionBuffer)(__ccgo_up(bp + 40))).FaBuf)
Xsqlite3_free(tls, (**(**TSessionBuffer)(__ccgo_up(bp + 56))).FaBuf)
Xsqlite3_free(tls, (**(**TSessionBuffer)(__ccgo_up(bp + 8))).FaBuf)
return **(**int32)(__ccgo_up(bp))
}
// C documentation
//
// /*
// ** This function is used to serialize the contents of value pValue (see
// ** comment titled "RECORD FORMAT" above).
// **
// ** If it is non-NULL, the serialized form of the value is written to
// ** buffer aBuf. *pnWrite is set to the number of bytes written before
// ** returning. Or, if aBuf is NULL, the only thing this function does is
// ** set *pnWrite.
// **
// ** If no error occurs, SQLITE_OK is returned. Or, if an OOM error occurs
// ** within a call to sqlite3_value_text() (may fail if the db is utf-16))
// ** SQLITE_NOMEM is returned.
// */
func _sessionSerializeValue(tls *libc.TLS, aBuf uintptr, pValue uintptr, pnWrite uintptr) (r1 int32) {
var eType, n, nByte, nVarint int32
var i Tu64
var r float64
var z uintptr
_, _, _, _, _, _, _ = eType, i, n, nByte, nVarint, r, z /* Size of serialized value in bytes */
if pValue != 0 { /* Value type (SQLITE_NULL, TEXT etc.) */
eType = Xsqlite3_value_type(tls, pValue)
if aBuf != 0 {
**(**Tu8)(__ccgo_up(aBuf)) = libc.Uint8FromInt32(eType)
}
switch eType {
case int32(SQLITE_NULL):
nByte = int32(1)
case int32(SQLITE_INTEGER):
fallthrough
case int32(SQLITE_FLOAT):
if aBuf != 0 {
/* TODO: SQLite does something special to deal with mixed-endian
** floating point values (e.g. ARM7). This code probably should
** too. */
if eType == int32(SQLITE_INTEGER) {
i = libc.Uint64FromInt64(Xsqlite3_value_int64(tls, pValue))
_sessionPutI64(tls, aBuf+1, libc.Int64FromUint64(i))
} else {
r = Xsqlite3_value_double(tls, pValue)
_sessionPutDouble(tls, aBuf+1, r)
}
}
nByte = int32(9)
default:
if eType == int32(SQLITE_TEXT) {
z = Xsqlite3_value_text(tls, pValue)
} else {
z = Xsqlite3_value_blob(tls, pValue)
}
n = Xsqlite3_value_bytes(tls, pValue)
if z == uintptr(0) && (eType != int32(SQLITE_BLOB) || n > 0) {
return int32(SQLITE_NOMEM)
}
nVarint = _sessionVarintLen(tls, n)
if aBuf != 0 {
_sessionVarintPut(tls, aBuf+1, n)
if n > 0 {
libc.X__builtin___memcpy_chk(tls, aBuf+uintptr(nVarint+int32(1)), z, libc.Uint64FromInt32(n), ^t__predefined_size_t(0))
}
}
nByte = int32(1) + nVarint + n
break
}
} else {
nByte = int32(1)
if aBuf != 0 {
**(**Tu8)(__ccgo_up(aBuf)) = uint8('\000')
}
}
if pnWrite != 0 {
**(**Tsqlite3_int64)(__ccgo_up(pnWrite)) += int64(nByte)
}
return SQLITE_OK
}
// C documentation
//
// /*
// ** Prepare statements for applying changes to the sqlite_stat1 table.
// ** These are similar to those created by sessionSelectRow(),
// ** sessionInsertRow(), sessionUpdateRow() and sessionDeleteRow() for
// ** other tables.
// */
func _sessionStat1Sql(tls *libc.TLS, db uintptr, p uintptr) (r int32) {
var rc int32
_ = rc
rc = _sessionSelectRow(tls, db, __ccgo_ts+13181, p)
if rc == SQLITE_OK {
rc = _sessionPrepare(tls, db, p+16, uintptr(0), __ccgo_ts+36459)
}
if rc == SQLITE_OK {
rc = _sessionPrepare(tls, db, p+8, uintptr(0), __ccgo_ts+36572)
}
return rc
}
// C documentation
//
// /*
// ** This function queries the database for the names of the columns of table
// ** zThis, in schema zDb.
// **
// ** Otherwise, if they are not NULL, variable *pnCol is set to the number
// ** of columns in the database table and variable *pzTab is set to point to a
// ** nul-terminated copy of the table name. *pazCol (if not NULL) is set to
// ** point to an array of pointers to column names. And *pabPK (again, if not
// ** NULL) is set to point to an array of booleans - true if the corresponding
// ** column is part of the primary key.
// **
// ** For example, if the table is declared as:
// **
// ** CREATE TABLE tbl1(w, x DEFAULT 'abc', y, z, PRIMARY KEY(w, z));
// **
// ** Then the five output variables are populated as follows:
// **
// ** *pnCol = 4
// ** *pzTab = "tbl1"
// ** *pazCol = {"w", "x", "y", "z"}
// ** *pazDflt = {NULL, 'abc', NULL, NULL}
// ** *pabPK = {1, 0, 0, 1}
// **
// ** All returned buffers are part of the same single allocation, which must
// ** be freed using sqlite3_free() by the caller
// */
func _sessionTableInfo(tls *libc.TLS, pSession uintptr, db uintptr, zDb uintptr, zThis uintptr, pnCol uintptr, pnTotalCol uintptr, pzTab uintptr, pazCol uintptr, pazDflt uintptr, paiIdx uintptr, pabPK uintptr, pbRowid uintptr) (r int32) {
bp := tls.Alloc(32)
defer tls.Free(32)
var abPK, aiIdx, azCol, azDflt, pAlloc, zDflt, zName, zPragma uintptr
var bRowid, i, nDbCol, nDflt, nName1, nThis, rc int32
var nByte Tsqlite3_int64
var nName Tsize_t
var _ /* pStmt at bp+0 */ uintptr
_, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _ = abPK, aiIdx, azCol, azDflt, bRowid, i, nByte, nDbCol, nDflt, nName, nName1, nThis, pAlloc, rc, zDflt, zName, zPragma
nDbCol = 0
pAlloc = uintptr(0)
azCol = uintptr(0)
azDflt = uintptr(0)
abPK = uintptr(0)
aiIdx = uintptr(0)
bRowid = 0 /* Set to true to use rowid as PK */
**(**uintptr)(__ccgo_up(pazCol)) = uintptr(0)
**(**uintptr)(__ccgo_up(pabPK)) = uintptr(0)
**(**int32)(__ccgo_up(pnCol)) = 0
if pnTotalCol != 0 {
**(**int32)(__ccgo_up(pnTotalCol)) = 0
}
if paiIdx != 0 {
**(**uintptr)(__ccgo_up(paiIdx)) = uintptr(0)
}
if pzTab != 0 {
**(**uintptr)(__ccgo_up(pzTab)) = uintptr(0)
}
if pazDflt != 0 {
**(**uintptr)(__ccgo_up(pazDflt)) = uintptr(0)
}
nThis = _sqlite3Strlen30(tls, zThis)
if nThis == int32(12) && 0 == Xsqlite3_stricmp(tls, __ccgo_ts+13181, zThis) {
rc = Xsqlite3_table_column_metadata(tls, db, zDb, zThis, uintptr(0), uintptr(0), uintptr(0), uintptr(0), uintptr(0), uintptr(0))
if rc == SQLITE_OK {
/* For sqlite_stat1, pretend that (tbl,idx) is the PRIMARY KEY. */
zPragma = Xsqlite3_mprintf(tls, __ccgo_ts+35583, 0)
} else {
if rc == int32(SQLITE_ERROR) {
zPragma = Xsqlite3_mprintf(tls, __ccgo_ts+1702, 0)
} else {
return rc
}
}
} else {
zPragma = Xsqlite3_mprintf(tls, __ccgo_ts+35713, libc.VaList(bp+16, zDb, zThis))
}
if !(zPragma != 0) {
return int32(SQLITE_NOMEM)
}
rc = Xsqlite3_prepare_v2(tls, db, zPragma, -int32(1), bp, uintptr(0))
Xsqlite3_free(tls, zPragma)
if rc != SQLITE_OK {
return rc
}
nByte = int64(nThis + int32(1))
bRowid = libc.BoolInt32(pbRowid != uintptr(0))
for int32(SQLITE_ROW) == Xsqlite3_step(tls, **(**uintptr)(__ccgo_up(bp))) {
nByte = nByte + int64(Xsqlite3_column_bytes(tls, **(**uintptr)(__ccgo_up(bp)), int32(1))) /* name */
nByte = nByte + int64(Xsqlite3_column_bytes(tls, **(**uintptr)(__ccgo_up(bp)), int32(4))) /* dflt_value */
if Xsqlite3_column_int(tls, **(**uintptr)(__ccgo_up(bp)), int32(6)) == 0 { /* !hidden */
nDbCol = nDbCol + 1
}
if Xsqlite3_column_int(tls, **(**uintptr)(__ccgo_up(bp)), int32(5)) != 0 {
bRowid = 0
} /* pk */
}
if nDbCol == 0 {
bRowid = 0
}
nDbCol = nDbCol + bRowid
nByte = libc.Int64FromUint64(uint64(nByte) + uint64(libc.Xstrlen(tls, __ccgo_ts+31733)))
rc = Xsqlite3_reset(tls, **(**uintptr)(__ccgo_up(bp)))
if rc == SQLITE_OK {
nByte = libc.Int64FromUint64(uint64(nByte) + uint64(libc.Uint64FromInt32(nDbCol)*(libc.Uint64FromInt64(8)*libc.Uint64FromInt32(2)+libc.Uint64FromInt64(4)+libc.Uint64FromInt64(1)+libc.Uint64FromInt32(1)+libc.Uint64FromInt32(1))))
pAlloc = _sessionMalloc64(tls, pSession, nByte)
if pAlloc == uintptr(0) {
rc = int32(SQLITE_NOMEM)
} else {
libc.X__builtin___memset_chk(tls, pAlloc, 0, libc.Uint64FromInt64(nByte), ^t__predefined_size_t(0))
}
}
if rc == SQLITE_OK {
azCol = pAlloc
azDflt = azCol + uintptr(nDbCol)*8
aiIdx = azDflt + uintptr(nDbCol)*8
abPK = aiIdx + uintptr(nDbCol)*4
pAlloc = abPK + uintptr(nDbCol)
if pzTab != 0 {
libc.X__builtin___memcpy_chk(tls, pAlloc, zThis, libc.Uint64FromInt32(nThis+int32(1)), ^t__predefined_size_t(0))
**(**uintptr)(__ccgo_up(pzTab)) = pAlloc
pAlloc = pAlloc + uintptr(nThis+int32(1))
}
i = 0
if bRowid != 0 {
nName = libc.Xstrlen(tls, __ccgo_ts+31733)
libc.X__builtin___memcpy_chk(tls, pAlloc, __ccgo_ts+31733, nName+uint64(1), ^t__predefined_size_t(0))
**(**uintptr)(__ccgo_up(azCol + uintptr(i)*8)) = pAlloc
pAlloc = pAlloc + uintptr(nName+uint64(1))
**(**Tu8)(__ccgo_up(abPK + uintptr(i))) = uint8(1)
**(**int32)(__ccgo_up(aiIdx + uintptr(i)*4)) = -int32(1)
i = i + 1
}
for int32(SQLITE_ROW) == Xsqlite3_step(tls, **(**uintptr)(__ccgo_up(bp))) {
if Xsqlite3_column_int(tls, **(**uintptr)(__ccgo_up(bp)), int32(6)) == 0 { /* !hidden */
nName1 = Xsqlite3_column_bytes(tls, **(**uintptr)(__ccgo_up(bp)), int32(1))
nDflt = Xsqlite3_column_bytes(tls, **(**uintptr)(__ccgo_up(bp)), int32(4))
zName = Xsqlite3_column_text(tls, **(**uintptr)(__ccgo_up(bp)), int32(1))
zDflt = Xsqlite3_column_text(tls, **(**uintptr)(__ccgo_up(bp)), int32(4))
if zName == uintptr(0) {
break
}
libc.X__builtin___memcpy_chk(tls, pAlloc, zName, libc.Uint64FromInt32(nName1+int32(1)), ^t__predefined_size_t(0))
**(**uintptr)(__ccgo_up(azCol + uintptr(i)*8)) = pAlloc
pAlloc = pAlloc + uintptr(nName1+int32(1))
if zDflt != 0 {
libc.X__builtin___memcpy_chk(tls, pAlloc, zDflt, libc.Uint64FromInt32(nDflt+int32(1)), ^t__predefined_size_t(0))
**(**uintptr)(__ccgo_up(azDflt + uintptr(i)*8)) = pAlloc
pAlloc = pAlloc + uintptr(nDflt+int32(1))
} else {
**(**uintptr)(__ccgo_up(azDflt + uintptr(i)*8)) = uintptr(0)
}
**(**Tu8)(__ccgo_up(abPK + uintptr(i))) = libc.Uint8FromInt32(Xsqlite3_column_int(tls, **(**uintptr)(__ccgo_up(bp)), int32(5)))
**(**int32)(__ccgo_up(aiIdx + uintptr(i)*4)) = Xsqlite3_column_int(tls, **(**uintptr)(__ccgo_up(bp)), 0)
i = i + 1
}
if pnTotalCol != 0 {
**(**int32)(__ccgo_up(pnTotalCol)) = **(**int32)(__ccgo_up(pnTotalCol)) + 1
}
}
rc = Xsqlite3_reset(tls, **(**uintptr)(__ccgo_up(bp)))
}
/* If successful, populate the output variables. Otherwise, zero them and
** free any allocation made. An error code will be returned in this case.
*/
if rc == SQLITE_OK {
**(**uintptr)(__ccgo_up(pazCol)) = azCol
if pazDflt != 0 {
**(**uintptr)(__ccgo_up(pazDflt)) = azDflt
}
**(**uintptr)(__ccgo_up(pabPK)) = abPK
**(**int32)(__ccgo_up(pnCol)) = nDbCol
if paiIdx != 0 {
**(**uintptr)(__ccgo_up(paiIdx)) = aiIdx
}
} else {
_sessionFree(tls, pSession, azCol)
}
if pbRowid != 0 {
**(**int32)(__ccgo_up(pbRowid)) = bRowid
}
Xsqlite3_finalize(tls, **(**uintptr)(__ccgo_up(bp)))
return rc
}
// C documentation
//
// /*
// ** Check if table zTab in the "main" database of db is a WITHOUT ROWID
// ** table.
// **
// ** If no error occurs, return SQLITE_OK and set output variable (*pbWR) to
// ** true if zTab is a WITHOUT ROWID table, or false otherwise. Or, if an
// ** error does occur, return an SQLite error code. The final value of (*pbWR)
// ** is undefined in this case.
// */
func _sessionTableIsWithoutRowid(tls *libc.TLS, db uintptr, zTab uintptr, pbWR uintptr) (r int32) {
bp := tls.Alloc(32)
defer tls.Free(32)
var rc int32
var zSql uintptr
var _ /* pList at bp+0 */ uintptr
_, _ = rc, zSql
**(**uintptr)(__ccgo_up(bp)) = uintptr(0)
zSql = uintptr(0)
rc = SQLITE_OK
zSql = Xsqlite3_mprintf(tls, __ccgo_ts+36756, libc.VaList(bp+16, zTab))
if zSql == uintptr(0) {
rc = int32(SQLITE_NOMEM)
} else {
rc = Xsqlite3_prepare_v2(tls, db, zSql, -int32(1), bp, uintptr(0))
Xsqlite3_free(tls, zSql)
}
if rc == SQLITE_OK {
Xsqlite3_step(tls, **(**uintptr)(__ccgo_up(bp)))
**(**int32)(__ccgo_up(pbWR)) = Xsqlite3_column_int(tls, **(**uintptr)(__ccgo_up(bp)), int32(4))
rc = Xsqlite3_finalize(tls, **(**uintptr)(__ccgo_up(bp)))
}
return rc
}
// C documentation
//
// /*
// ** Find a prepared UPDATE statement suitable for the UPDATE step currently
// ** being visited by the iterator. The UPDATE is of the form:
// **
// ** UPDATE tbl SET col = ?, col2 = ? WHERE pk1 IS ? AND pk2 IS ?
// */
func _sessionUpdateFind(tls *libc.TLS, pIter uintptr, p uintptr, bPatchset int32, ppStmt uintptr) (r int32) {
bp := tls.Alloc(32)
defer tls.Free(32)
var bStat1, ii, nByte, nCol, nU32, nUp int32
var pUp, pp, zSep, zSql uintptr
var _ /* buf at bp+8 */ TSessionBuffer
var _ /* rc at bp+0 */ int32
_, _, _, _, _, _, _, _, _, _ = bStat1, ii, nByte, nCol, nU32, nUp, pUp, pp, zSep, zSql
**(**int32)(__ccgo_up(bp)) = SQLITE_OK
pUp = uintptr(0)
nCol = (*Tsqlite3_changeset_iter)(unsafe.Pointer(pIter)).FnCol
nU32 = ((*Tsqlite3_changeset_iter)(unsafe.Pointer(pIter)).FnCol + int32(33)) / int32(32)
if (*TSessionApplyCtx)(unsafe.Pointer(p)).FaUpdateMask == uintptr(0) {
(*TSessionApplyCtx)(unsafe.Pointer(p)).FaUpdateMask = Xsqlite3_malloc(tls, libc.Int32FromUint64(libc.Uint64FromInt32(nU32)*uint64(4)))
if (*TSessionApplyCtx)(unsafe.Pointer(p)).FaUpdateMask == uintptr(0) {
**(**int32)(__ccgo_up(bp)) = int32(SQLITE_NOMEM)
}
}
if **(**int32)(__ccgo_up(bp)) == SQLITE_OK {
libc.X__builtin___memset_chk(tls, (*TSessionApplyCtx)(unsafe.Pointer(p)).FaUpdateMask, 0, libc.Uint64FromInt32(nU32)*uint64(4), ^t__predefined_size_t(0))
**(**int32)(__ccgo_up(bp)) = int32(SQLITE_CORRUPT)
ii = 0
for {
if !(ii < (*Tsqlite3_changeset_iter)(unsafe.Pointer(pIter)).FnCol) {
break
}
if **(**uintptr)(__ccgo_up((*Tsqlite3_changeset_iter)(unsafe.Pointer(pIter)).FapValue + uintptr((*Tsqlite3_changeset_iter)(unsafe.Pointer(pIter)).FnCol+ii)*8)) != 0 {
**(**Tu32)(__ccgo_up((*TSessionApplyCtx)(unsafe.Pointer(p)).FaUpdateMask + uintptr(ii/int32(32))*4)) |= libc.Uint32FromInt32(libc.Int32FromInt32(1) << (ii % libc.Int32FromInt32(32)))
**(**int32)(__ccgo_up(bp)) = SQLITE_OK
}
goto _1
_1:
;
ii = ii + 1
}
}
if **(**int32)(__ccgo_up(bp)) == SQLITE_OK {
if bPatchset != 0 {
**(**Tu32)(__ccgo_up((*TSessionApplyCtx)(unsafe.Pointer(p)).FaUpdateMask + uintptr(nCol/int32(32))*4)) |= libc.Uint32FromInt32(libc.Int32FromInt32(1) << (nCol % libc.Int32FromInt32(32)))
}
if (*TSessionApplyCtx)(unsafe.Pointer(p)).FpUp != 0 {
nUp = 0
pp = p + 64
for int32(1) != 0 {
nUp = nUp + 1
if 0 == libc.Xmemcmp(tls, (*TSessionApplyCtx)(unsafe.Pointer(p)).FaUpdateMask, (*TSessionUpdate)(unsafe.Pointer(**(**uintptr)(__ccgo_up(pp)))).FaMask, libc.Uint64FromInt32(nU32)*uint64(4)) {
pUp = **(**uintptr)(__ccgo_up(pp))
**(**uintptr)(__ccgo_up(pp)) = (*TSessionUpdate)(unsafe.Pointer(pUp)).FpNext
(*TSessionUpdate)(unsafe.Pointer(pUp)).FpNext = (*TSessionApplyCtx)(unsafe.Pointer(p)).FpUp
(*TSessionApplyCtx)(unsafe.Pointer(p)).FpUp = pUp
break
}
if (*TSessionUpdate)(unsafe.Pointer(**(**uintptr)(__ccgo_up(pp)))).FpNext != 0 {
pp = **(**uintptr)(__ccgo_up(pp)) + 16
} else {
if nUp >= int32(SESSION_UPDATE_CACHE_SZ) {
Xsqlite3_finalize(tls, (*TSessionUpdate)(unsafe.Pointer(**(**uintptr)(__ccgo_up(pp)))).FpStmt)
Xsqlite3_free(tls, **(**uintptr)(__ccgo_up(pp)))
**(**uintptr)(__ccgo_up(pp)) = uintptr(0)
}
break
}
}
}
if pUp == uintptr(0) {
nByte = libc.Int32FromUint64(uint64(24) * libc.Uint64FromInt32(nU32) * uint64(4))
bStat1 = libc.BoolInt32(Xsqlite3_stricmp(tls, (*Tsqlite3_changeset_iter)(unsafe.Pointer(pIter)).FzTab, __ccgo_ts+13181) == 0)
pUp = Xsqlite3_malloc(tls, nByte)
if pUp == uintptr(0) {
**(**int32)(__ccgo_up(bp)) = int32(SQLITE_NOMEM)
} else {
zSep = __ccgo_ts + 1702
libc.X__builtin___memset_chk(tls, bp+8, 0, uint64(16), ^t__predefined_size_t(0))
(*TSessionUpdate)(unsafe.Pointer(pUp)).FaMask = pUp + 1*24
libc.X__builtin___memcpy_chk(tls, (*TSessionUpdate)(unsafe.Pointer(pUp)).FaMask, (*TSessionApplyCtx)(unsafe.Pointer(p)).FaUpdateMask, libc.Uint64FromInt32(nU32)*uint64(4), ^t__predefined_size_t(0))
_sessionAppendStr(tls, bp+8, __ccgo_ts+36282, bp)
_sessionAppendIdent(tls, bp+8, (*Tsqlite3_changeset_iter)(unsafe.Pointer(pIter)).FzTab, bp)
_sessionAppendStr(tls, bp+8, __ccgo_ts+36295, bp)
/* Create the assignments part of the UPDATE */
ii = 0
for {
if !(ii < (*Tsqlite3_changeset_iter)(unsafe.Pointer(pIter)).FnCol) {
break
}
if libc.Int32FromUint8(**(**Tu8)(__ccgo_up((*TSessionApplyCtx)(unsafe.Pointer(p)).FabPK + uintptr(ii)))) == 0 && **(**uintptr)(__ccgo_up((*Tsqlite3_changeset_iter)(unsafe.Pointer(pIter)).FapValue + uintptr((*Tsqlite3_changeset_iter)(unsafe.Pointer(pIter)).FnCol+ii)*8)) != 0 {
_sessionAppendStr(tls, bp+8, zSep, bp)
_sessionAppendIdent(tls, bp+8, **(**uintptr)(__ccgo_up((*TSessionApplyCtx)(unsafe.Pointer(p)).FazCol + uintptr(ii)*8)), bp)
_sessionAppendStr(tls, bp+8, __ccgo_ts+36301, bp)
_sessionAppendInteger(tls, bp+8, ii*int32(2)+int32(1), bp)
zSep = __ccgo_ts + 16562
}
goto _2
_2:
;
ii = ii + 1
}
/* Create the WHERE clause part of the UPDATE */
zSep = __ccgo_ts + 1702
_sessionAppendStr(tls, bp+8, __ccgo_ts+36306, bp)
ii = 0
for {
if !(ii < (*Tsqlite3_changeset_iter)(unsafe.Pointer(pIter)).FnCol) {
break
}
if **(**Tu8)(__ccgo_up((*TSessionApplyCtx)(unsafe.Pointer(p)).FabPK + uintptr(ii))) != 0 || bPatchset == 0 && **(**uintptr)(__ccgo_up((*Tsqlite3_changeset_iter)(unsafe.Pointer(pIter)).FapValue + uintptr(ii)*8)) != 0 {
_sessionAppendStr(tls, bp+8, zSep, bp)
if bStat1 != 0 && ii == int32(1) {
_sessionAppendStr(tls, bp+8, __ccgo_ts+36314, bp)
} else {
_sessionAppendIdent(tls, bp+8, **(**uintptr)(__ccgo_up((*TSessionApplyCtx)(unsafe.Pointer(p)).FazCol + uintptr(ii)*8)), bp)
_sessionAppendStr(tls, bp+8, __ccgo_ts+36389, bp)
_sessionAppendInteger(tls, bp+8, ii*int32(2)+int32(2), bp)
}
zSep = __ccgo_ts + 24020
}
goto _3
_3:
;
ii = ii + 1
}
if **(**int32)(__ccgo_up(bp)) == SQLITE_OK {
zSql = (**(**TSessionBuffer)(__ccgo_up(bp + 8))).FaBuf
**(**int32)(__ccgo_up(bp)) = Xsqlite3_prepare_v2(tls, (*TSessionApplyCtx)(unsafe.Pointer(p)).Fdb, zSql, (**(**TSessionBuffer)(__ccgo_up(bp + 8))).FnBuf, pUp, uintptr(0))
}
if **(**int32)(__ccgo_up(bp)) != SQLITE_OK {
Xsqlite3_free(tls, pUp)
pUp = uintptr(0)
} else {
(*TSessionUpdate)(unsafe.Pointer(pUp)).FpNext = (*TSessionApplyCtx)(unsafe.Pointer(p)).FpUp
(*TSessionApplyCtx)(unsafe.Pointer(p)).FpUp = pUp
}
Xsqlite3_free(tls, (**(**TSessionBuffer)(__ccgo_up(bp + 8))).FaBuf)
}
}
}
if pUp != 0 {
**(**uintptr)(__ccgo_up(ppStmt)) = (*TSessionUpdate)(unsafe.Pointer(pUp)).FpStmt
} else {
**(**uintptr)(__ccgo_up(ppStmt)) = uintptr(0)
}
return **(**int32)(__ccgo_up(bp))
}
func _sessionUpdateMaxSize(tls *libc.TLS, op int32, pSession uintptr, pTab uintptr, pC uintptr) (r int32) {
bp := tls.Alloc(48)
defer tls.Free(48)
var bChanged, eType, iIdx, ii, ii1, nIncr, nOld int32
var pCsr, v3 uintptr
var _ /* dVal at bp+32 */ float64
var _ /* iVal at bp+24 */ Tsqlite3_int64
var _ /* nByte at bp+40 */ int32
var _ /* nNew at bp+0 */ Ti64
var _ /* p at bp+16 */ uintptr
var _ /* p at bp+8 */ uintptr
_, _, _, _, _, _, _, _, _ = bChanged, eType, iIdx, ii, ii1, nIncr, nOld, pCsr, v3
**(**Ti64)(__ccgo_up(bp)) = int64(2)
if libc.Int32FromUint8((*TSessionChange)(unsafe.Pointer(pC)).Fop) == int32(SQLITE_INSERT) {
if (*TSessionTable)(unsafe.Pointer(pTab)).FbRowid != 0 {
**(**Ti64)(__ccgo_up(bp)) = **(**Ti64)(__ccgo_up(bp)) + int64(9)
}
if op != int32(SQLITE_DELETE) {
ii = 0
for {
if !(ii < (*TSessionTable)(unsafe.Pointer(pTab)).FnCol) {
break
}
**(**uintptr)(__ccgo_up(bp + 8)) = uintptr(0)
(*(*func(*libc.TLS, uintptr, int32, uintptr) int32)(unsafe.Pointer(&struct{ uintptr }{(*Tsqlite3_session)(unsafe.Pointer(pSession)).Fhook.FxNew})))(tls, (*Tsqlite3_session)(unsafe.Pointer(pSession)).Fhook.FpCtx, **(**int32)(__ccgo_up((*TSessionTable)(unsafe.Pointer(pTab)).FaiIdx + uintptr(ii)*4)), bp+8)
_sessionSerializeValue(tls, uintptr(0), **(**uintptr)(__ccgo_up(bp + 8)), bp)
goto _1
_1:
;
ii = ii + 1
}
}
} else {
if op == int32(SQLITE_DELETE) {
**(**Ti64)(__ccgo_up(bp)) = **(**Ti64)(__ccgo_up(bp)) + int64((*TSessionChange)(unsafe.Pointer(pC)).FnRecord)
if Xsqlite3_preupdate_blobwrite(tls, (*Tsqlite3_session)(unsafe.Pointer(pSession)).Fdb) >= 0 {
**(**Ti64)(__ccgo_up(bp)) = **(**Ti64)(__ccgo_up(bp)) + int64((*TSessionChange)(unsafe.Pointer(pC)).FnRecord)
}
} else {
pCsr = (*TSessionChange)(unsafe.Pointer(pC)).FaRecord
if (*TSessionTable)(unsafe.Pointer(pTab)).FbRowid != 0 {
**(**Ti64)(__ccgo_up(bp)) = **(**Ti64)(__ccgo_up(bp)) + int64(libc.Int32FromInt32(9)+libc.Int32FromInt32(1))
pCsr = pCsr + uintptr(9)
}
ii1 = (*TSessionTable)(unsafe.Pointer(pTab)).FbRowid
for {
if !(ii1 < (*TSessionTable)(unsafe.Pointer(pTab)).FnCol) {
break
}
bChanged = int32(1)
nOld = 0
iIdx = **(**int32)(__ccgo_up((*TSessionTable)(unsafe.Pointer(pTab)).FaiIdx + uintptr(ii1)*4))
**(**uintptr)(__ccgo_up(bp + 16)) = uintptr(0)
(*(*func(*libc.TLS, uintptr, int32, uintptr) int32)(unsafe.Pointer(&struct{ uintptr }{(*Tsqlite3_session)(unsafe.Pointer(pSession)).Fhook.FxNew})))(tls, (*Tsqlite3_session)(unsafe.Pointer(pSession)).Fhook.FpCtx, iIdx, bp+16)
if **(**uintptr)(__ccgo_up(bp + 16)) == uintptr(0) {
return int32(SQLITE_NOMEM)
}
v3 = pCsr
pCsr = pCsr + 1
eType = libc.Int32FromUint8(**(**Tu8)(__ccgo_up(v3)))
switch eType {
case int32(SQLITE_NULL):
bChanged = libc.BoolInt32(Xsqlite3_value_type(tls, **(**uintptr)(__ccgo_up(bp + 16))) != int32(SQLITE_NULL))
case int32(SQLITE_FLOAT):
fallthrough
case int32(SQLITE_INTEGER):
if eType == Xsqlite3_value_type(tls, **(**uintptr)(__ccgo_up(bp + 16))) {
**(**Tsqlite3_int64)(__ccgo_up(bp + 24)) = _sessionGetI64(tls, pCsr)
if eType == int32(SQLITE_INTEGER) {
bChanged = libc.BoolInt32(**(**Tsqlite3_int64)(__ccgo_up(bp + 24)) != Xsqlite3_value_int64(tls, **(**uintptr)(__ccgo_up(bp + 16))))
} else {
libc.X__builtin___memcpy_chk(tls, bp+32, bp+24, uint64(8), ^t__predefined_size_t(0))
bChanged = libc.BoolInt32(**(**float64)(__ccgo_up(bp + 32)) != Xsqlite3_value_double(tls, **(**uintptr)(__ccgo_up(bp + 16))))
}
}
nOld = int32(8)
pCsr = pCsr + uintptr(8)
default:
nOld = _sessionVarintGet(tls, pCsr, bp+40)
pCsr = pCsr + uintptr(nOld)
nOld = nOld + **(**int32)(__ccgo_up(bp + 40))
if eType == Xsqlite3_value_type(tls, **(**uintptr)(__ccgo_up(bp + 16))) && **(**int32)(__ccgo_up(bp + 40)) == Xsqlite3_value_bytes(tls, **(**uintptr)(__ccgo_up(bp + 16))) && (**(**int32)(__ccgo_up(bp + 40)) == 0 || 0 == libc.Xmemcmp(tls, pCsr, Xsqlite3_value_blob(tls, **(**uintptr)(__ccgo_up(bp + 16))), libc.Uint64FromInt32(**(**int32)(__ccgo_up(bp + 40))))) {
bChanged = 0
}
pCsr = pCsr + uintptr(**(**int32)(__ccgo_up(bp + 40)))
break
}
if bChanged != 0 && **(**Tu8)(__ccgo_up((*TSessionTable)(unsafe.Pointer(pTab)).FabPK + uintptr(ii1))) != 0 {
**(**Ti64)(__ccgo_up(bp)) = int64((*TSessionChange)(unsafe.Pointer(pC)).FnRecord + int32(2))
break
}
if bChanged != 0 {
**(**Ti64)(__ccgo_up(bp)) = **(**Ti64)(__ccgo_up(bp)) + int64(int32(1)+nOld)
_sessionSerializeValue(tls, uintptr(0), **(**uintptr)(__ccgo_up(bp + 16)), bp)
} else {
if **(**Tu8)(__ccgo_up((*TSessionTable)(unsafe.Pointer(pTab)).FabPK + uintptr(ii1))) != 0 {
**(**Ti64)(__ccgo_up(bp)) = **(**Ti64)(__ccgo_up(bp)) + int64(int32(2)+nOld)
} else {
**(**Ti64)(__ccgo_up(bp)) = **(**Ti64)(__ccgo_up(bp)) + int64(2)
}
}
goto _2
_2:
;
ii1 = ii1 + 1
}
}
}
if **(**Ti64)(__ccgo_up(bp)) > int64((*TSessionChange)(unsafe.Pointer(pC)).FnMaxSize) {
nIncr = int32(**(**Ti64)(__ccgo_up(bp)) - int64((*TSessionChange)(unsafe.Pointer(pC)).FnMaxSize))
(*TSessionChange)(unsafe.Pointer(pC)).FnMaxSize = int32(**(**Ti64)(__ccgo_up(bp)))
**(**Ti64)(__ccgo_up(pSession + 64)) += int64(nIncr)
}
return SQLITE_OK
}
// C documentation
//
// /*
// ** Session-change object (*pp) contains an old.* record with fewer than
// ** nCol fields. This function updates it with the default values for
// ** the missing fields.
// */
func _sessionUpdateOneChange(tls *libc.TLS, pSession uintptr, pRc uintptr, pp uintptr, nCol int32, pDflt uintptr) {
var eType, iField, n, n1, n2, nByte, nIncr, v1 int32
var iVal Ti64
var pNew, pOld, z, z1, v2 uintptr
var rVal float64
_, _, _, _, _, _, _, _, _, _, _, _, _, _, _ = eType, iField, iVal, n, n1, n2, nByte, nIncr, pNew, pOld, rVal, z, z1, v1, v2
pOld = **(**uintptr)(__ccgo_up(pp))
for libc.Int32FromUint16((*TSessionChange)(unsafe.Pointer(pOld)).FnRecordField) < nCol {
pNew = uintptr(0)
nByte = 0
nIncr = 0
iField = libc.Int32FromUint16((*TSessionChange)(unsafe.Pointer(pOld)).FnRecordField)
eType = Xsqlite3_column_type(tls, pDflt, iField)
switch eType {
case int32(SQLITE_NULL):
nIncr = int32(1)
case int32(SQLITE_INTEGER):
fallthrough
case int32(SQLITE_FLOAT):
nIncr = int32(9)
default:
n = Xsqlite3_column_bytes(tls, pDflt, iField)
nIncr = int32(1) + _sessionVarintLen(tls, n) + n
break
}
nByte = libc.Int32FromUint64(libc.Uint64FromInt32(nIncr) + (uint64(32) + libc.Uint64FromInt32((*TSessionChange)(unsafe.Pointer(pOld)).FnRecord)))
pNew = _sessionMalloc64(tls, pSession, int64(nByte))
if pNew == uintptr(0) {
**(**int32)(__ccgo_up(pRc)) = int32(SQLITE_NOMEM)
return
} else {
libc.X__builtin___memcpy_chk(tls, pNew, pOld, uint64(32), ^t__predefined_size_t(0))
(*TSessionChange)(unsafe.Pointer(pNew)).FaRecord = pNew + 1*32
libc.X__builtin___memcpy_chk(tls, (*TSessionChange)(unsafe.Pointer(pNew)).FaRecord, (*TSessionChange)(unsafe.Pointer(pOld)).FaRecord, libc.Uint64FromInt32((*TSessionChange)(unsafe.Pointer(pOld)).FnRecord), ^t__predefined_size_t(0))
v2 = pNew + 8
v1 = *(*int32)(unsafe.Pointer(v2))
*(*int32)(unsafe.Pointer(v2)) = *(*int32)(unsafe.Pointer(v2)) + 1
**(**Tu8)(__ccgo_up((*TSessionChange)(unsafe.Pointer(pNew)).FaRecord + uintptr(v1))) = libc.Uint8FromInt32(eType)
switch eType {
case int32(SQLITE_INTEGER):
iVal = Xsqlite3_column_int64(tls, pDflt, iField)
_sessionPutI64(tls, (*TSessionChange)(unsafe.Pointer(pNew)).FaRecord+uintptr((*TSessionChange)(unsafe.Pointer(pNew)).FnRecord), iVal)
**(**int32)(__ccgo_up(pNew + 8)) += int32(8)
case int32(SQLITE_FLOAT):
rVal = Xsqlite3_column_double(tls, pDflt, iField)
_sessionPutDouble(tls, (*TSessionChange)(unsafe.Pointer(pNew)).FaRecord+uintptr((*TSessionChange)(unsafe.Pointer(pNew)).FnRecord), rVal)
**(**int32)(__ccgo_up(pNew + 8)) += int32(8)
case int32(SQLITE_TEXT):
n1 = Xsqlite3_column_bytes(tls, pDflt, iField)
z = Xsqlite3_column_text(tls, pDflt, iField)
**(**int32)(__ccgo_up(pNew + 8)) += _sessionVarintPut(tls, (*TSessionChange)(unsafe.Pointer(pNew)).FaRecord+uintptr((*TSessionChange)(unsafe.Pointer(pNew)).FnRecord), n1)
libc.X__builtin___memcpy_chk(tls, (*TSessionChange)(unsafe.Pointer(pNew)).FaRecord+uintptr((*TSessionChange)(unsafe.Pointer(pNew)).FnRecord), z, libc.Uint64FromInt32(n1), ^t__predefined_size_t(0))
**(**int32)(__ccgo_up(pNew + 8)) += n1
case int32(SQLITE_BLOB):
n2 = Xsqlite3_column_bytes(tls, pDflt, iField)
z1 = Xsqlite3_column_blob(tls, pDflt, iField)
**(**int32)(__ccgo_up(pNew + 8)) += _sessionVarintPut(tls, (*TSessionChange)(unsafe.Pointer(pNew)).FaRecord+uintptr((*TSessionChange)(unsafe.Pointer(pNew)).FnRecord), n2)
libc.X__builtin___memcpy_chk(tls, (*TSessionChange)(unsafe.Pointer(pNew)).FaRecord+uintptr((*TSessionChange)(unsafe.Pointer(pNew)).FnRecord), z1, libc.Uint64FromInt32(n2), ^t__predefined_size_t(0))
**(**int32)(__ccgo_up(pNew + 8)) += n2
default:
break
}
_sessionFree(tls, pSession, pOld)
v2 = pNew
pOld = v2
**(**uintptr)(__ccgo_up(pp)) = v2
(*TSessionChange)(unsafe.Pointer(pNew)).FnRecordField = (*TSessionChange)(unsafe.Pointer(pNew)).FnRecordField + 1
**(**int32)(__ccgo_up(pNew + 4)) += nIncr
if pSession != 0 {
**(**Ti64)(__ccgo_up(pSession + 64)) += int64(nIncr)
}
}
}
}
// C documentation
//
// /*
// ** Iterator pUp points to an UPDATE change. This function deletes the
// ** affected row from the database and creates an INSERT statement that
// ** may be used to reinsert the row as it is after the UPDATE change
// ** has been applied.
// **
// ** If successful, SQLITE_OK is returned and output variable (*ppInsert)
// ** is left pointing to a prepared INSERT statement. It is the responsibility
// ** of the caller to eventually free this statement using sqlite3_finalize().
// ** Or, if an error occurs, an SQLite error code is returned and (*ppInsert)
// ** set to NULL. pApply->zErr may be set to an error message in this case.
// */
func _sessionUpdateToDeleteInsert(tls *libc.TLS, db uintptr, zTab uintptr, pApply uintptr, pUp uintptr, ppInsert uintptr) (r int32) {
bp := tls.Alloc(128)
defer tls.Free(128)
var iCol, ii int32
var pVal, zComma, zComma2, zInsert, zSelect uintptr
var _ /* bWR at bp+20 */ int32
var _ /* cols at bp+24 */ TSessionBuffer
var _ /* insbind at bp+40 */ TSessionBuffer
var _ /* pRet at bp+0 */ uintptr
var _ /* pSelect at bp+8 */ uintptr
var _ /* pkcols at bp+56 */ TSessionBuffer
var _ /* rc at bp+16 */ int32
var _ /* selbind at bp+72 */ TSessionBuffer
_, _, _, _, _, _, _ = iCol, ii, pVal, zComma, zComma2, zInsert, zSelect
**(**uintptr)(__ccgo_up(bp)) = uintptr(0) /* The INSERT statement */
**(**uintptr)(__ccgo_up(bp + 8)) = uintptr(0) /* SELECT to read current values of row */
**(**int32)(__ccgo_up(bp + 16)) = SQLITE_OK
**(**int32)(__ccgo_up(bp + 20)) = 0
**(**int32)(__ccgo_up(bp + 16)) = _sessionTableIsWithoutRowid(tls, db, zTab, bp+20)
if **(**int32)(__ccgo_up(bp + 16)) == SQLITE_OK {
zSelect = uintptr(0)
zInsert = uintptr(0)
**(**TSessionBuffer)(__ccgo_up(bp + 24)) = TSessionBuffer{}
**(**TSessionBuffer)(__ccgo_up(bp + 40)) = TSessionBuffer{}
**(**TSessionBuffer)(__ccgo_up(bp + 56)) = TSessionBuffer{}
**(**TSessionBuffer)(__ccgo_up(bp + 72)) = TSessionBuffer{}
zComma = __ccgo_ts + 1702
zComma2 = __ccgo_ts + 1702
ii = 0
for {
if !(ii < (*TSessionApplyCtx)(unsafe.Pointer(pApply)).FnCol) {
break
}
_sessionAppendStr(tls, bp+24, zComma, bp+16)
_sessionAppendIdent(tls, bp+24, **(**uintptr)(__ccgo_up((*TSessionApplyCtx)(unsafe.Pointer(pApply)).FazCol + uintptr(ii)*8)), bp+16)
_sessionAppendStr(tls, bp+40, zComma, bp+16)
_sessionAppendStr(tls, bp+40, __ccgo_ts+5607, bp+16)
zComma = __ccgo_ts + 16562
if **(**Tu8)(__ccgo_up((*TSessionApplyCtx)(unsafe.Pointer(pApply)).FabPK + uintptr(ii))) != 0 {
_sessionAppendStr(tls, bp+56, zComma2, bp+16)
_sessionAppendIdent(tls, bp+56, **(**uintptr)(__ccgo_up((*TSessionApplyCtx)(unsafe.Pointer(pApply)).FazCol + uintptr(ii)*8)), bp+16)
_sessionAppendStr(tls, bp+72, zComma2, bp+16)
_sessionAppendPrintf(tls, bp+72, bp+16, __ccgo_ts+36171, libc.VaList(bp+96, ii+int32(1)))
zComma2 = __ccgo_ts + 16562
}
goto _1
_1:
;
ii = ii + 1
}
if **(**int32)(__ccgo_up(bp + 20)) == 0 {
_sessionAppendStr(tls, bp+24, zComma, bp+16)
_sessionAppendStr(tls, bp+24, __ccgo_ts+31733, bp+16)
_sessionAppendStr(tls, bp+40, zComma, bp+16)
_sessionAppendStr(tls, bp+40, __ccgo_ts+5607, bp+16)
}
if **(**int32)(__ccgo_up(bp + 16)) == SQLITE_OK {
zSelect = Xsqlite3_mprintf(tls, __ccgo_ts+36779, libc.VaList(bp+96, (**(**TSessionBuffer)(__ccgo_up(bp + 24))).FaBuf, zTab, (**(**TSessionBuffer)(__ccgo_up(bp + 56))).FaBuf, (**(**TSessionBuffer)(__ccgo_up(bp + 72))).FaBuf))
if zSelect == uintptr(0) {
**(**int32)(__ccgo_up(bp + 16)) = int32(SQLITE_NOMEM)
}
}
if **(**int32)(__ccgo_up(bp + 16)) == SQLITE_OK {
zInsert = Xsqlite3_mprintf(tls, __ccgo_ts+36816, libc.VaList(bp+96, zTab, (**(**TSessionBuffer)(__ccgo_up(bp + 24))).FaBuf, (**(**TSessionBuffer)(__ccgo_up(bp + 40))).FaBuf))
if zInsert == uintptr(0) {
**(**int32)(__ccgo_up(bp + 16)) = int32(SQLITE_NOMEM)
}
}
if **(**int32)(__ccgo_up(bp + 16)) == SQLITE_OK {
**(**int32)(__ccgo_up(bp + 16)) = _sessionPrepare(tls, db, bp+8, pApply+128, zSelect)
}
if **(**int32)(__ccgo_up(bp + 16)) == SQLITE_OK {
**(**int32)(__ccgo_up(bp + 16)) = _sessionPrepare(tls, db, bp, pApply+128, zInsert)
}
Xsqlite3_free(tls, zSelect)
Xsqlite3_free(tls, zInsert)
Xsqlite3_free(tls, (**(**TSessionBuffer)(__ccgo_up(bp + 24))).FaBuf)
Xsqlite3_free(tls, (**(**TSessionBuffer)(__ccgo_up(bp + 40))).FaBuf)
Xsqlite3_free(tls, (**(**TSessionBuffer)(__ccgo_up(bp + 56))).FaBuf)
Xsqlite3_free(tls, (**(**TSessionBuffer)(__ccgo_up(bp + 72))).FaBuf)
}
if **(**int32)(__ccgo_up(bp + 16)) == SQLITE_OK {
**(**int32)(__ccgo_up(bp + 16)) = _sessionBindRow(tls, pUp, __ccgo_fp(Xsqlite3changeset_old), (*TSessionApplyCtx)(unsafe.Pointer(pApply)).FnCol, (*TSessionApplyCtx)(unsafe.Pointer(pApply)).FabPK, **(**uintptr)(__ccgo_up(bp + 8)))
}
if **(**int32)(__ccgo_up(bp + 16)) == SQLITE_OK && Xsqlite3_step(tls, **(**uintptr)(__ccgo_up(bp + 8))) == int32(SQLITE_ROW) {
iCol = 0
for {
if !(iCol < (*TSessionApplyCtx)(unsafe.Pointer(pApply)).FnCol) {
break
}
pVal = **(**uintptr)(__ccgo_up((*Tsqlite3_changeset_iter)(unsafe.Pointer(pUp)).FapValue + uintptr(iCol+(*TSessionApplyCtx)(unsafe.Pointer(pApply)).FnCol)*8))
if pVal == uintptr(0) {
pVal = Xsqlite3_column_value(tls, **(**uintptr)(__ccgo_up(bp + 8)), iCol)
}
**(**int32)(__ccgo_up(bp + 16)) = Xsqlite3_bind_value(tls, **(**uintptr)(__ccgo_up(bp)), iCol+int32(1), pVal)
goto _2
_2:
;
iCol = iCol + 1
}
if **(**int32)(__ccgo_up(bp + 20)) == 0 {
Xsqlite3_bind_int64(tls, **(**uintptr)(__ccgo_up(bp)), iCol+int32(1), Xsqlite3_column_int64(tls, **(**uintptr)(__ccgo_up(bp + 8)), iCol))
}
}
_sessionFinalizeStmt(tls, **(**uintptr)(__ccgo_up(bp + 8)), bp+16)
/* Delete the row from the database. */
if **(**int32)(__ccgo_up(bp + 16)) == SQLITE_OK {
**(**int32)(__ccgo_up(bp + 16)) = _sessionBindRow(tls, pUp, __ccgo_fp(Xsqlite3changeset_old), (*TSessionApplyCtx)(unsafe.Pointer(pApply)).FnCol, (*TSessionApplyCtx)(unsafe.Pointer(pApply)).FabPK, (*TSessionApplyCtx)(unsafe.Pointer(pApply)).FpDelete)
Xsqlite3_bind_int(tls, (*TSessionApplyCtx)(unsafe.Pointer(pApply)).FpDelete, (*TSessionApplyCtx)(unsafe.Pointer(pApply)).FnCol+int32(1), int32(1))
}
if **(**int32)(__ccgo_up(bp + 16)) == SQLITE_OK {
Xsqlite3_step(tls, (*TSessionApplyCtx)(unsafe.Pointer(pApply)).FpDelete)
**(**int32)(__ccgo_up(bp + 16)) = Xsqlite3_reset(tls, (*TSessionApplyCtx)(unsafe.Pointer(pApply)).FpDelete)
}
if **(**int32)(__ccgo_up(bp + 16)) != SQLITE_OK {
Xsqlite3_finalize(tls, **(**uintptr)(__ccgo_up(bp)))
**(**uintptr)(__ccgo_up(bp)) = uintptr(0)
}
**(**uintptr)(__ccgo_up(ppInsert)) = **(**uintptr)(__ccgo_up(bp))
return **(**int32)(__ccgo_up(bp + 16))
}
// C documentation
//
// /*
// ** This function sets the value of the sqlite3_value object passed as the
// ** first argument to a copy of the string or blob held in the aData[]
// ** buffer. SQLITE_OK is returned if successful, or SQLITE_NOMEM if an OOM
// ** error occurs.
// */
func _sessionValueSetStr(tls *libc.TLS, pVal uintptr, aData uintptr, nData int32, enc Tu8) (r int32) {
var aCopy uintptr
_ = aCopy
/* In theory this code could just pass SQLITE_TRANSIENT as the final
** argument to sqlite3ValueSetStr() and have the copy created
** automatically. But doing so makes it difficult to detect any OOM
** error. Hence the code to create the copy externally. */
aCopy = Xsqlite3_malloc64(tls, libc.Uint64FromInt64(int64(nData)+int64(1)))
if aCopy == uintptr(0) {
return int32(SQLITE_NOMEM)
}
libc.X__builtin___memcpy_chk(tls, aCopy, aData, libc.Uint64FromInt32(nData), ^t__predefined_size_t(0))
_sqlite3ValueSetStr(tls, pVal, nData, aCopy, enc, __ccgo_fp(Xsqlite3_free))
return SQLITE_OK
}
// C documentation
//
// /*
// ** Read a varint value from buffer aBuf[], size nBuf bytes, into *piVal.
// ** Return the number of bytes read.
// */
func _sessionVarintGetSafe(tls *libc.TLS, aBuf uintptr, nBuf int32, piVal uintptr) (r int32) {
bp := tls.Alloc(16)
defer tls.Free(16)
var aRead uintptr
var v1 int32
var _ /* aCopy at bp+0 */ [9]Tu8
_, _ = aRead, v1
aRead = aBuf
libc.X__builtin___memset_chk(tls, bp, 0, uint64(9), ^t__predefined_size_t(0))
if libc.Uint64FromInt32(nBuf) < uint64(9) {
libc.X__builtin___memcpy_chk(tls, bp, aBuf, libc.Uint64FromInt32(nBuf), ^t__predefined_size_t(0))
aRead = bp
}
if libc.Int32FromUint8(**(**Tu8)(__ccgo_up(aRead))) < libc.Int32FromUint8(libc.Uint8FromInt32(0x80)) {
**(**int32)(__ccgo_up(piVal)) = libc.Int32FromUint32(uint32(**(**Tu8)(__ccgo_up(aRead))))
v1 = libc.Int32FromInt32(1)
} else {
v1 = libc.Int32FromUint8(_sqlite3GetVarint32(tls, aRead, piVal))
}
return libc.Int32FromUint8(libc.Uint8FromInt32(v1))
}
/* Load an unaligned and unsigned 32-bit integer */
// C documentation
//
// /* IMP: R-25361-16150 This function is omitted from SQLite by default. It
// ** is only available if the SQLITE_SOUNDEX compile-time option is used
// ** when SQLite is built.
// */
// /*
// ** Compute the soundex encoding of a word.
// **
// ** IMP: R-59782-00072 The soundex(X) function returns a string that is the
// ** soundex encoding of the string X.
// */
func _soundexFunc(tls *libc.TLS, context uintptr, argc int32, argv uintptr) {
bp := tls.Alloc(16)
defer tls.Free(16)
var code, i, j, v3 int32
var prevcode Tu8
var zIn uintptr
var _ /* zResult at bp+0 */ [8]int8
_, _, _, _, _, _ = code, i, j, prevcode, zIn, v3
zIn = Xsqlite3_value_text(tls, **(**uintptr)(__ccgo_up(argv)))
if zIn == uintptr(0) {
zIn = __ccgo_ts + 1702
}
i = 0
for {
if !(**(**Tu8)(__ccgo_up(zIn + uintptr(i))) != 0 && !(libc.Int32FromUint8(_sqlite3CtypeMap[**(**Tu8)(__ccgo_up(zIn + uintptr(i)))])&libc.Int32FromInt32(0x02) != 0)) {
break
}
goto _1
_1:
;
i = i + 1
}
if **(**Tu8)(__ccgo_up(zIn + uintptr(i))) != 0 {
prevcode = _iCode[libc.Int32FromUint8(**(**Tu8)(__ccgo_up(zIn + uintptr(i))))&int32(0x7f)]
(**(**[8]int8)(__ccgo_up(bp)))[0] = int8(libc.Int32FromUint8(**(**Tu8)(__ccgo_up(zIn + uintptr(i)))) & ^(libc.Int32FromUint8(_sqlite3CtypeMap[**(**Tu8)(__ccgo_up(zIn + uintptr(i)))]) & libc.Int32FromInt32(0x20)))
j = int32(1)
for {
if !(j < int32(4) && **(**Tu8)(__ccgo_up(zIn + uintptr(i))) != 0) {
break
}
code = libc.Int32FromUint8(_iCode[libc.Int32FromUint8(**(**Tu8)(__ccgo_up(zIn + uintptr(i))))&int32(0x7f)])
if code > 0 {
if code != libc.Int32FromUint8(prevcode) {
prevcode = libc.Uint8FromInt32(code)
v3 = j
j = j + 1
(**(**[8]int8)(__ccgo_up(bp)))[v3] = int8(code + int32('0'))
}
} else {
prevcode = uint8(0)
}
goto _2
_2:
;
i = i + 1
}
for j < int32(4) {
v3 = j
j = j + 1
(**(**[8]int8)(__ccgo_up(bp)))[v3] = int8('0')
}
(**(**[8]int8)(__ccgo_up(bp)))[j] = 0
Xsqlite3_result_text(tls, context, bp, int32(4), uintptr(-libc.Int32FromInt32(1)))
} else {
/* IMP: R-64894-50321 The string "?000" is returned if the argument
** is NULL or contains no ASCII alphabetic characters. */
Xsqlite3_result_text(tls, context, __ccgo_ts+16942, int32(4), libc.UintptrFromInt32(0))
}
}
// C documentation
//
// /*
// ** Implementation of the R*-tree variant of SplitNode from Beckman[1990].
// */
func _splitNodeStartree(tls *libc.TLS, pRtree uintptr, aCell uintptr, nCell int32, pLeft uintptr, pRight uintptr, pBboxLeft uintptr, pBboxRight uintptr) (r int32) {
bp := tls.Alloc(96)
defer tls.Free(96)
var aSpare, aaSorted, pBbox, pCell, pTarget, v7, v8 uintptr
var area, fBestArea, fBestMargin, fBestOverlap, margin, overlap TRtreeDValue
var iBestDim, iBestLeft, iBestSplit, ii, jj, kk, nLeft int32
var nByte Tsqlite3_int64
var _ /* left at bp+0 */ TRtreeCell
var _ /* right at bp+48 */ TRtreeCell
_, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _ = aSpare, aaSorted, area, fBestArea, fBestMargin, fBestOverlap, iBestDim, iBestLeft, iBestSplit, ii, jj, kk, margin, nByte, nLeft, overlap, pBbox, pCell, pTarget, v7, v8
iBestDim = 0
iBestSplit = 0
fBestMargin = float64(0)
nByte = libc.Int64FromUint64(libc.Uint64FromInt32(libc.Int32FromUint8((*TRtree)(unsafe.Pointer(pRtree)).FnDim)+libc.Int32FromInt32(1)) * (uint64(8) + libc.Uint64FromInt32(nCell)*uint64(4)))
aaSorted = Xsqlite3_malloc64(tls, libc.Uint64FromInt64(nByte))
if !(aaSorted != 0) {
return int32(SQLITE_NOMEM)
}
aSpare = aaSorted + uintptr((*TRtree)(unsafe.Pointer(pRtree)).FnDim)*8 + uintptr(libc.Int32FromUint8((*TRtree)(unsafe.Pointer(pRtree)).FnDim)*nCell)*4
libc.X__builtin___memset_chk(tls, aaSorted, 0, libc.Uint64FromInt64(nByte), ^t__predefined_size_t(0))
ii = 0
for {
if !(ii < libc.Int32FromUint8((*TRtree)(unsafe.Pointer(pRtree)).FnDim)) {
break
}
**(**uintptr)(__ccgo_up(aaSorted + uintptr(ii)*8)) = aaSorted + uintptr((*TRtree)(unsafe.Pointer(pRtree)).FnDim)*8 + uintptr(ii*nCell)*4
jj = 0
for {
if !(jj < nCell) {
break
}
**(**int32)(__ccgo_up(**(**uintptr)(__ccgo_up(aaSorted + uintptr(ii)*8)) + uintptr(jj)*4)) = jj
goto _2
_2:
;
jj = jj + 1
}
_SortByDimension(tls, pRtree, **(**uintptr)(__ccgo_up(aaSorted + uintptr(ii)*8)), nCell, ii, aCell, aSpare)
goto _1
_1:
;
ii = ii + 1
}
ii = 0
for {
if !(ii < libc.Int32FromUint8((*TRtree)(unsafe.Pointer(pRtree)).FnDim)) {
break
}
margin = float64(0)
fBestOverlap = float64(0)
fBestArea = float64(0)
iBestLeft = 0
nLeft = ((*TRtree)(unsafe.Pointer(pRtree)).FiNodeSize - int32(4)) / libc.Int32FromUint8((*TRtree)(unsafe.Pointer(pRtree)).FnBytesPerCell) / int32(3)
for {
if !(nLeft <= nCell-((*TRtree)(unsafe.Pointer(pRtree)).FiNodeSize-int32(4))/libc.Int32FromUint8((*TRtree)(unsafe.Pointer(pRtree)).FnBytesPerCell)/int32(3)) {
break
}
libc.X__builtin___memcpy_chk(tls, bp, aCell+uintptr(**(**int32)(__ccgo_up(**(**uintptr)(__ccgo_up(aaSorted + uintptr(ii)*8)))))*48, uint64(48), ^t__predefined_size_t(0))
libc.X__builtin___memcpy_chk(tls, bp+48, aCell+uintptr(**(**int32)(__ccgo_up(**(**uintptr)(__ccgo_up(aaSorted + uintptr(ii)*8)) + uintptr(nCell-int32(1))*4)))*48, uint64(48), ^t__predefined_size_t(0))
kk = int32(1)
for {
if !(kk < nCell-int32(1)) {
break
}
if kk < nLeft {
_cellUnion(tls, pRtree, bp, aCell+uintptr(**(**int32)(__ccgo_up(**(**uintptr)(__ccgo_up(aaSorted + uintptr(ii)*8)) + uintptr(kk)*4)))*48)
} else {
_cellUnion(tls, pRtree, bp+48, aCell+uintptr(**(**int32)(__ccgo_up(**(**uintptr)(__ccgo_up(aaSorted + uintptr(ii)*8)) + uintptr(kk)*4)))*48)
}
goto _5
_5:
;
kk = kk + 1
}
margin = margin + _cellMargin(tls, pRtree, bp)
margin = margin + _cellMargin(tls, pRtree, bp+48)
overlap = _cellOverlap(tls, pRtree, bp, bp+48, int32(1))
area = _cellArea(tls, pRtree, bp) + _cellArea(tls, pRtree, bp+48)
if nLeft == ((*TRtree)(unsafe.Pointer(pRtree)).FiNodeSize-int32(4))/libc.Int32FromUint8((*TRtree)(unsafe.Pointer(pRtree)).FnBytesPerCell)/int32(3) || overlap < fBestOverlap || overlap == fBestOverlap && area < fBestArea {
iBestLeft = nLeft
fBestOverlap = overlap
fBestArea = area
}
goto _4
_4:
;
nLeft = nLeft + 1
}
if ii == 0 || margin < fBestMargin {
iBestDim = ii
fBestMargin = margin
iBestSplit = iBestLeft
}
goto _3
_3:
;
ii = ii + 1
}
libc.X__builtin___memcpy_chk(tls, pBboxLeft, aCell+uintptr(**(**int32)(__ccgo_up(**(**uintptr)(__ccgo_up(aaSorted + uintptr(iBestDim)*8)))))*48, uint64(48), ^t__predefined_size_t(0))
libc.X__builtin___memcpy_chk(tls, pBboxRight, aCell+uintptr(**(**int32)(__ccgo_up(**(**uintptr)(__ccgo_up(aaSorted + uintptr(iBestDim)*8)) + uintptr(iBestSplit)*4)))*48, uint64(48), ^t__predefined_size_t(0))
ii = 0
for {
if !(ii < nCell) {
break
}
if ii < iBestSplit {
v7 = pLeft
} else {
v7 = pRight
}
pTarget = v7
if ii < iBestSplit {
v8 = pBboxLeft
} else {
v8 = pBboxRight
}
pBbox = v8
pCell = aCell + uintptr(**(**int32)(__ccgo_up(**(**uintptr)(__ccgo_up(aaSorted + uintptr(iBestDim)*8)) + uintptr(ii)*4)))*48
_nodeInsertCell(tls, pRtree, pTarget, pCell)
_cellUnion(tls, pRtree, pBbox, pCell)
goto _6
_6:
;
ii = ii + 1
}
Xsqlite3_free(tls, aaSorted)
return SQLITE_OK
}
// 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(48)
defer tls.Free(48)
*(*TToken)(unsafe.Pointer(bp)) = _sName
*(*TToken)(unsafe.Pointer(bp + 16)) = _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 + 136 + 2*4)) {
_sqlite3ErrorMsg(tls, pParse, __ccgo_ts+14304, libc.VaList(bp+40, (*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 + 16))).Fn >= uint32(16) && Xsqlite3_strnicmp(tls, (**(**TToken)(__ccgo_up(bp + 16))).Fz+uintptr((**(**TToken)(__ccgo_up(bp + 16))).Fn-libc.Uint32FromInt32(6)), __ccgo_ts+14327, int32(6)) == 0 {
(**(**TToken)(__ccgo_up(bp + 16))).Fn -= uint32(6)
for (**(**TToken)(__ccgo_up(bp + 16))).Fn > uint32(0) && libc.Int32FromUint8(_sqlite3CtypeMap[libc.Uint8FromInt8(**(**int8)(__ccgo_up((**(**TToken)(__ccgo_up(bp + 16))).Fz + uintptr((**(**TToken)(__ccgo_up(bp + 16))).Fn-uint32(1)))))])&int32(0x01) != 0 {
(**(**TToken)(__ccgo_up(bp + 16))).Fn = (**(**TToken)(__ccgo_up(bp + 16))).Fn - 1
}
if (**(**TToken)(__ccgo_up(bp + 16))).Fn >= uint32(9) && Xsqlite3_strnicmp(tls, (**(**TToken)(__ccgo_up(bp + 16))).Fz+uintptr((**(**TToken)(__ccgo_up(bp + 16))).Fn-libc.Uint32FromInt32(9)), __ccgo_ts+14334, int32(9)) == 0 {
(**(**TToken)(__ccgo_up(bp + 16))).Fn -= uint32(9)
for (**(**TToken)(__ccgo_up(bp + 16))).Fn > uint32(0) && libc.Int32FromUint8(_sqlite3CtypeMap[libc.Uint8FromInt8(**(**int8)(__ccgo_up((**(**TToken)(__ccgo_up(bp + 16))).Fz + uintptr((**(**TToken)(__ccgo_up(bp + 16))).Fn-uint32(1)))))])&int32(0x01) != 0 {
(**(**TToken)(__ccgo_up(bp + 16))).Fn = (**(**TToken)(__ccgo_up(bp + 16))).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 + 16))).Fn >= uint32(3) {
_sqlite3DequoteToken(tls, bp+16)
i = 0
for {
if !(i < int32(SQLITE_N_STDTYPE)) {
break
}
if (**(**TToken)(__ccgo_up(bp + 16))).Fn == uint32(_sqlite3StdTypeLen[i]) && Xsqlite3_strnicmp(tls, (**(**TToken)(__ccgo_up(bp + 16))).Fz, _sqlite3StdType[i], libc.Int32FromUint32((**(**TToken)(__ccgo_up(bp + 16))).Fn)) == 0 {
(**(**TToken)(__ccgo_up(bp + 16))).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 + 16))).Fn)+libc.BoolInt64((**(**TToken)(__ccgo_up(bp + 16))).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.X__builtin___memcpy_chk(tls, z, (**(**TToken)(__ccgo_up(bp))).Fz, uint64((**(**TToken)(__ccgo_up(bp))).Fn), ^t__predefined_size_t(0))
**(**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+14344, libc.VaList(bp+40, z))
_sqlite3DbFree(tls, db, z)
return
}
aNew = _sqlite3DbRealloc(tls, db, (*TTable)(unsafe.Pointer(p)).FaCol, libc.Uint64FromInt64(int64((*TTable)(unsafe.Pointer(p)).FnCol)+libc.Int64FromInt32(1))*uint64(16))
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)*16
libc.X__builtin___memset_chk(tls, pCol, 0, uint64(16), ^t__predefined_size_t(0))
(*TColumn)(unsafe.Pointer(pCol)).FzCnName = z
(*TColumn)(unsafe.Pointer(pCol)).FhName = _sqlite3StrIHash(tls, z)
if (**(**TToken)(__ccgo_up(bp + 16))).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+8, uint32(eType), 4, 0xf0)
(*TColumn)(unsafe.Pointer(pCol)).FszEst = szEst
} else {
zType = z + uintptr(_sqlite3Strlen30(tls, z)) + uintptr(1)
libc.X__builtin___memcpy_chk(tls, zType, (**(**TToken)(__ccgo_up(bp + 16))).Fz, uint64((**(**TToken)(__ccgo_up(bp + 16))).Fn), ^t__predefined_size_t(0))
**(**int8)(__ccgo_up(zType + uintptr((**(**TToken)(__ccgo_up(bp + 16))).Fn))) = 0
_sqlite3Dequote(tls, zType)
(*TColumn)(unsafe.Pointer(pCol)).Faffinity = _sqlite3AffinityType(tls, zType, pCol)
v1 = pCol + 14
*(*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(uint64((*TColumn)(unsafe.Pointer(pCol)).FhName) % uint64(16))
**(**Tu8)(__ccgo_up(p + 104 + 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 + 256))).FconstraintName.Fn = uint32(0)
}
// C documentation
//
// /*
// ** The expression is the default value for the most recently added column
// ** of the table currently under construction.
// **
// ** Default value expressions must be constant. Raise an exception if this
// ** is not the case.
// **
// ** This routine is called by the parser while in the middle of
// ** parsing a CREATE TABLE statement.
// */
func _sqlite3AddDefaultValue(tls *libc.TLS, pParse uintptr, pExpr uintptr, zStart uintptr, zEnd uintptr) {
bp := tls.Alloc(96)
defer tls.Free(96)
var db, p, pCol, pDfltExpr uintptr
var isInit int32
var _ /* x at bp+0 */ TExpr
_, _, _, _, _ = db, isInit, p, pCol, pDfltExpr
db = (*TParse)(unsafe.Pointer(pParse)).Fdb
p = (*TParse)(unsafe.Pointer(pParse)).FpNewTable
if p != uintptr(0) {
isInit = libc.BoolInt32((*Tsqlite3)(unsafe.Pointer(db)).Finit1.Fbusy != 0 && libc.Int32FromUint8((*Tsqlite3)(unsafe.Pointer(db)).Finit1.FiDb) != int32(1))
pCol = (*TTable)(unsafe.Pointer(p)).FaCol + uintptr(int32((*TTable)(unsafe.Pointer(p)).FnCol)-int32(1))*16
if !(_sqlite3ExprIsConstantOrFunction(tls, pExpr, libc.Uint8FromInt32(isInit)) != 0) {
_sqlite3ErrorMsg(tls, pParse, __ccgo_ts+14370, libc.VaList(bp+80, (*TColumn)(unsafe.Pointer(pCol)).FzCnName))
} else {
if libc.Int32FromUint16((*TColumn)(unsafe.Pointer(pCol)).FcolFlags)&int32(COLFLAG_GENERATED) != 0 {
_sqlite3ErrorMsg(tls, pParse, __ccgo_ts+14415, 0)
} else {
libc.X__builtin___memset_chk(tls, bp, 0, uint64(72), ^t__predefined_size_t(0))
(**(**TExpr)(__ccgo_up(bp))).Fop = uint8(TK_SPAN)
*(*uintptr)(unsafe.Pointer(bp + 8)) = _sqlite3DbSpanDup(tls, db, zStart, zEnd)
(**(**TExpr)(__ccgo_up(bp))).FpLeft = pExpr
(**(**TExpr)(__ccgo_up(bp))).Fflags = uint32(EP_Skip)
pDfltExpr = _sqlite3ExprDup(tls, db, bp, int32(EXPRDUP_REDUCE))
_sqlite3DbFree(tls, db, *(*uintptr)(unsafe.Pointer(bp + 8)))
_sqlite3ColumnSetExpr(tls, pParse, p, pCol, pDfltExpr)
}
}
}
if libc.Int32FromUint8((*TParse)(unsafe.Pointer(pParse)).FeParseMode) >= int32(PARSE_MODE_RENAME) {
_sqlite3RenameExprUnmap(tls, pParse, pExpr)
}
_sqlite3ExprDelete(tls, db, pExpr)
}
// C documentation
//
// /* Change the most recently parsed column to be a GENERATED ALWAYS AS
// ** column.
// */
func _sqlite3AddGenerated(tls *libc.TLS, pParse uintptr, pExpr uintptr, pType uintptr) {
bp := tls.Alloc(16)
defer tls.Free(16)
var eType Tu8
var pCol, pTab, v1 uintptr
_, _, _, _ = eType, pCol, pTab, v1
eType = uint8(COLFLAG_VIRTUAL)
pTab = (*TParse)(unsafe.Pointer(pParse)).FpNewTable
if pTab == uintptr(0) {
/* generated column in an CREATE TABLE IF NOT EXISTS that already exists */
goto generated_done
}
pCol = (*TTable)(unsafe.Pointer(pTab)).FaCol + uintptr(int32((*TTable)(unsafe.Pointer(pTab)).FnCol)-int32(1))*16
if libc.Int32FromUint8((*TParse)(unsafe.Pointer(pParse)).FeParseMode) == int32(PARSE_MODE_DECLARE_VTAB) {
_sqlite3ErrorMsg(tls, pParse, __ccgo_ts+14605, 0)
goto generated_done
}
if libc.Int32FromUint16((*TColumn)(unsafe.Pointer(pCol)).FiDflt) > 0 {
goto generated_error
}
if pType != 0 {
if (*TToken)(unsafe.Pointer(pType)).Fn == uint32(7) && Xsqlite3_strnicmp(tls, __ccgo_ts+14648, (*TToken)(unsafe.Pointer(pType)).Fz, int32(7)) == 0 {
/* no-op */
} else {
if (*TToken)(unsafe.Pointer(pType)).Fn == uint32(6) && Xsqlite3_strnicmp(tls, __ccgo_ts+14656, (*TToken)(unsafe.Pointer(pType)).Fz, int32(6)) == 0 {
eType = uint8(COLFLAG_STORED)
} else {
goto generated_error
}
}
}
if libc.Int32FromUint8(eType) == int32(COLFLAG_VIRTUAL) {
(*TTable)(unsafe.Pointer(pTab)).FnNVCol = (*TTable)(unsafe.Pointer(pTab)).FnNVCol - 1
}
v1 = pCol + 14
*(*Tu16)(unsafe.Pointer(v1)) = Tu16(int32(*(*Tu16)(unsafe.Pointer(v1))) | libc.Int32FromUint8(eType))
**(**Tu32)(__ccgo_up(pTab + 48)) |= uint32(eType)
if libc.Int32FromUint16((*TColumn)(unsafe.Pointer(pCol)).FcolFlags)&int32(COLFLAG_PRIMKEY) != 0 {
_makeColumnPartOfPrimaryKey(tls, pParse, pCol) /* For the error message */
}
if pExpr != 0 && libc.Int32FromUint8((*TExpr)(unsafe.Pointer(pExpr)).Fop) == int32(TK_ID) {
/* The value of a generated column needs to be a real expression, not
** just a reference to another column, in order for covering index
** optimizations to work correctly. So if the value is not an expression,
** turn it into one by adding a unary "+" operator. */
pExpr = _sqlite3PExpr(tls, pParse, int32(TK_UPLUS), pExpr, uintptr(0))
}
if pExpr != 0 && libc.Int32FromUint8((*TExpr)(unsafe.Pointer(pExpr)).Fop) != int32(TK_RAISE) {
(*TExpr)(unsafe.Pointer(pExpr)).FaffExpr = (*TColumn)(unsafe.Pointer(pCol)).Faffinity
}
_sqlite3ColumnSetExpr(tls, pParse, pTab, pCol, pExpr)
pExpr = uintptr(0)
goto generated_done
goto generated_error
generated_error:
;
_sqlite3ErrorMsg(tls, pParse, __ccgo_ts+14663, libc.VaList(bp+8, (*TColumn)(unsafe.Pointer(pCol)).FzCnName))
goto generated_done
generated_done:
;
_sqlite3ExprDelete(tls, (*TParse)(unsafe.Pointer(pParse)).Fdb, pExpr)
}
// C documentation
//
// /*
// ** Designate the PRIMARY KEY for the table. pList is a list of names
// ** of columns that form the primary key. If pList is NULL, then the
// ** most recently added column of the table is the primary key.
// **
// ** A table can have at most one primary key. If the table already has
// ** a primary key (and this is the second primary key) then create an
// ** error.
// **
// ** If the PRIMARY KEY is on a single column whose datatype is INTEGER,
// ** then we will try to use that column as the rowid. Set the Table.iPKey
// ** field of the table under construction to be the index of the
// ** INTEGER PRIMARY KEY column. Table.iPKey is set to -1 if there is
// ** no INTEGER PRIMARY KEY.
// **
// ** If the key is not an INTEGER PRIMARY KEY, then create a unique
// ** index for the key. No index is created for INTEGER PRIMARY KEYs.
// */
func _sqlite3AddPrimaryKey(tls *libc.TLS, pParse uintptr, pList uintptr, onError int32, autoInc int32, sortOrder int32) {
bp := tls.Alloc(16)
defer tls.Free(16)
var i, iCol, nTerm int32
var pCExpr, pCExpr1, pCol, pTab uintptr
_, _, _, _, _, _, _ = i, iCol, nTerm, pCExpr, pCExpr1, pCol, pTab
pTab = (*TParse)(unsafe.Pointer(pParse)).FpNewTable
pCol = uintptr(0)
iCol = -int32(1)
if pTab == uintptr(0) {
goto primary_key_exit
}
if (*TTable)(unsafe.Pointer(pTab)).FtabFlags&uint32(TF_HasPrimaryKey) != 0 {
_sqlite3ErrorMsg(tls, pParse, __ccgo_ts+14508, libc.VaList(bp+8, (*TTable)(unsafe.Pointer(pTab)).FzName))
goto primary_key_exit
}
**(**Tu32)(__ccgo_up(pTab + 48)) |= uint32(TF_HasPrimaryKey)
if pList == uintptr(0) {
iCol = int32((*TTable)(unsafe.Pointer(pTab)).FnCol) - int32(1)
pCol = (*TTable)(unsafe.Pointer(pTab)).FaCol + uintptr(iCol)*16
_makeColumnPartOfPrimaryKey(tls, pParse, pCol)
nTerm = int32(1)
} else {
nTerm = (*TExprList)(unsafe.Pointer(pList)).FnExpr
i = 0
for {
if !(i < nTerm) {
break
}
pCExpr = _sqlite3ExprSkipCollate(tls, (*(*TExprList_item)(unsafe.Pointer(pList + 8 + uintptr(i)*32))).FpExpr)
_sqlite3StringToId(tls, pCExpr)
if libc.Int32FromUint8((*TExpr)(unsafe.Pointer(pCExpr)).Fop) == int32(TK_ID) {
iCol = _sqlite3ColumnIndex(tls, pTab, *(*uintptr)(unsafe.Pointer(pCExpr + 8)))
if iCol >= 0 {
pCol = (*TTable)(unsafe.Pointer(pTab)).FaCol + uintptr(iCol)*16
_makeColumnPartOfPrimaryKey(tls, pParse, pCol)
}
}
goto _1
_1:
;
i = i + 1
}
}
if nTerm == int32(1) && pCol != 0 && int32(uint32(*(*uint8)(unsafe.Pointer(pCol + 8))&0xf0>>4)) == int32(COLTYPE_INTEGER) && sortOrder != int32(SQLITE_SO_DESC) {
if libc.Int32FromUint8((*TParse)(unsafe.Pointer(pParse)).FeParseMode) >= int32(PARSE_MODE_RENAME) && pList != 0 {
pCExpr1 = _sqlite3ExprSkipCollate(tls, (*(*TExprList_item)(unsafe.Pointer(pList + 8))).FpExpr)
_sqlite3RenameTokenRemap(tls, pParse, pTab+52, pCExpr1)
}
(*TTable)(unsafe.Pointer(pTab)).FiPKey = int16(iCol)
(*TTable)(unsafe.Pointer(pTab)).FkeyConf = libc.Uint8FromInt32(onError)
**(**Tu32)(__ccgo_up(pTab + 48)) |= libc.Uint32FromInt32(autoInc * int32(TF_Autoincrement))
if pList != 0 {
(*TParse)(unsafe.Pointer(pParse)).FiPkSortOrder = (*(*TExprList_item)(unsafe.Pointer(pList + 8))).Ffg.FsortFlags
}
_sqlite3HasExplicitNulls(tls, pParse, pList)
} else {
if autoInc != 0 {
_sqlite3ErrorMsg(tls, pParse, __ccgo_ts+14549, 0)
} else {
_sqlite3CreateIndex(tls, pParse, uintptr(0), uintptr(0), uintptr(0), pList, onError, uintptr(0), uintptr(0), sortOrder, 0, uint8(SQLITE_IDXTYPE_PRIMARYKEY))
pList = uintptr(0)
}
}
goto primary_key_exit
primary_key_exit:
;
_sqlite3ExprListDelete(tls, (*TParse)(unsafe.Pointer(pParse)).Fdb, pList)
return
}
// C documentation
//
// /*
// ** Add the RETURNING clause to the parse currently underway.
// **
// ** This routine creates a special TEMP trigger that will fire for each row
// ** of the DML statement. That TEMP trigger contains a single SELECT
// ** statement with a result set that is the argument of the RETURNING clause.
// ** The trigger has the Trigger.bReturning flag and an opcode of
// ** TK_RETURNING instead of TK_SELECT, so that the trigger code generator
// ** knows to handle it specially. The TEMP trigger is automatically
// ** removed at the end of the parse.
// **
// ** When this routine is called, we do not yet know if the RETURNING clause
// ** is attached to a DELETE, INSERT, or UPDATE, so construct it as a
// ** RETURNING trigger instead. It will then be converted into the appropriate
// ** type on the first call to sqlite3TriggersExist().
// */
func _sqlite3AddReturning(tls *libc.TLS, pParse uintptr, pList uintptr) {
bp := tls.Alloc(16)
defer tls.Free(16)
var db, pHash, pRet uintptr
_, _, _ = db, pHash, pRet
db = (*TParse)(unsafe.Pointer(pParse)).Fdb
if (*TParse)(unsafe.Pointer(pParse)).FpNewTrigger != 0 {
_sqlite3ErrorMsg(tls, pParse, __ccgo_ts+14250, 0)
} else {
}
libc.SetBitFieldPtr16Uint32(pParse+40, libc.Uint32FromInt32(1), 3, 0x8)
pRet = _sqlite3DbMallocZero(tls, db, uint64(232))
if pRet == uintptr(0) {
_sqlite3ExprListDelete(tls, db, pList)
return
}
(*(*struct {
FpReturning uintptr
})(unsafe.Pointer(&(*TParse)(unsafe.Pointer(pParse)).Fu1))).FpReturning = pRet
(*TReturning)(unsafe.Pointer(pRet)).FpParse = pParse
(*TReturning)(unsafe.Pointer(pRet)).FpReturnEL = pList
_sqlite3ParserAddCleanup(tls, pParse, __ccgo_fp(_sqlite3DeleteReturning), pRet)
if (*Tsqlite3)(unsafe.Pointer(db)).FmallocFailed != 0 {
return
}
Xsqlite3_snprintf(tls, int32(40), pRet+188, __ccgo_ts+14284, libc.VaList(bp+8, pParse))
(*TReturning)(unsafe.Pointer(pRet)).FretTrig.FzName = pRet + 188
(*TReturning)(unsafe.Pointer(pRet)).FretTrig.Fop = uint8(TK_RETURNING)
(*TReturning)(unsafe.Pointer(pRet)).FretTrig.Ftr_tm = uint8(TRIGGER_AFTER)
(*TReturning)(unsafe.Pointer(pRet)).FretTrig.FbReturning = uint8(1)
(*TReturning)(unsafe.Pointer(pRet)).FretTrig.FpSchema = (**(**TDb)(__ccgo_up((*Tsqlite3)(unsafe.Pointer(db)).FaDb + 1*32))).FpSchema
(*TReturning)(unsafe.Pointer(pRet)).FretTrig.FpTabSchema = (**(**TDb)(__ccgo_up((*Tsqlite3)(unsafe.Pointer(db)).FaDb + 1*32))).FpSchema
(*TReturning)(unsafe.Pointer(pRet)).FretTrig.Fstep_list = pRet + 88
(*TReturning)(unsafe.Pointer(pRet)).FretTStep.Fop = uint8(TK_RETURNING)
(*TReturning)(unsafe.Pointer(pRet)).FretTStep.FpTrig = pRet + 16
(*TReturning)(unsafe.Pointer(pRet)).FretTStep.FpExprList = pList
pHash = (**(**TDb)(__ccgo_up((*Tsqlite3)(unsafe.Pointer(db)).FaDb + 1*32))).FpSchema + 56
if _sqlite3HashInsert(tls, pHash, pRet+188, pRet+16) == pRet+16 {
_sqlite3OomFault(tls, db)
}
}
// C documentation
//
// /*
// ** Initialize a Walker object so that will persist AggInfo entries referenced
// ** by the tree that is walked.
// */
func _sqlite3AggInfoPersistWalkerInit(tls *libc.TLS, pWalker uintptr, pParse uintptr) {
libc.X__builtin___memset_chk(tls, pWalker, 0, uint64(48), ^t__predefined_size_t(0))
(*TWalker)(unsafe.Pointer(pWalker)).FpParse = pParse
(*TWalker)(unsafe.Pointer(pWalker)).FxExprCallback = __ccgo_fp(_agginfoPersistExprCb)
(*TWalker)(unsafe.Pointer(pWalker)).FxSelectCallback = __ccgo_fp(_sqlite3SelectWalkNoop)
}
// C documentation
//
// /*
// ** Generate bytecode to implement:
// **
// ** ALTER TABLE pSrc ADD [CONSTRAINT pName] CHECK(pExpr)
// **
// ** Any "ON CONFLICT" text that occurs after the "CHECK(...)", up
// ** until pParse->sLastToken, is included as part of the new constraint.
// */
func _sqlite3AlterAddConstraint(tls *libc.TLS, pParse uintptr, pSrc uintptr, pFirst uintptr, pName uintptr, zExpr uintptr, nExpr int32, pExpr uintptr) {
bp := tls.Alloc(64)
defer tls.Free(64)
var nCons, rc int32
var pCons, pTab, zName uintptr
var _ /* iDb at bp+0 */ int32
var _ /* zDb at bp+8 */ uintptr
_, _, _, _, _ = nCons, pCons, pTab, rc, zName
pTab = uintptr(0) /* Table identified by pSrc */
**(**int32)(__ccgo_up(bp)) = 0 /* Which schema does pTab live in */
**(**uintptr)(__ccgo_up(bp + 8)) = uintptr(0) /* Name of the schema in which pTab lives */
pCons = uintptr(0) /* Result from error checking pExpr */
/* Look up the table being altered. */
pTab = _alterFindTable(tls, pParse, pSrc, bp, bp+8, int32(1))
if !(pTab != 0) {
_sqlite3ExprDelete(tls, (*TParse)(unsafe.Pointer(pParse)).Fdb, pExpr)
return
}
/* Verify that the new CHECK constraint does not contain any
** internal-use-only function. Forum post 2026-05-10T01:11:28Z
*/
rc = _sqlite3ResolveSelfReference(tls, pParse, pTab, int32(NC_IsCheck), pExpr, uintptr(0))
_sqlite3ExprDelete(tls, (*TParse)(unsafe.Pointer(pParse)).Fdb, pExpr)
if rc != 0 {
return
}
/* If this new constraint has a name, check that it is not a duplicate of
** an existing constraint. It is an error if it is. */
if pName != 0 {
zName = _sqlite3NameFromToken(tls, (*TParse)(unsafe.Pointer(pParse)).Fdb, pName)
_sqlite3NestedParse(tls, pParse, __ccgo_ts+12631, libc.VaList(bp+24, zName, int32(SQLITE_ERROR), **(**uintptr)(__ccgo_up(bp + 8)), (*TTable)(unsafe.Pointer(pTab)).FzName, zName))
_sqlite3DbFree(tls, (*TParse)(unsafe.Pointer(pParse)).Fdb, zName)
}
/* Search for a constraint violation. Throw an exception if one is found. */
_sqlite3NestedParse(tls, pParse, __ccgo_ts+12796, libc.VaList(bp+24, int32(SQLITE_CONSTRAINT), **(**uintptr)(__ccgo_up(bp + 8)), (*TTable)(unsafe.Pointer(pTab)).FzName, nExpr, zExpr))
/* Edit the SQL for the named table. */
pCons = (*TToken)(unsafe.Pointer(pFirst)).Fz
nCons = _alterRtrimConstraint(tls, (*TParse)(unsafe.Pointer(pParse)).Fdb, pCons, int32(int64((*TParse)(unsafe.Pointer(pParse)).FsLastToken.Fz)-int64(pCons)))
_sqlite3NestedParse(tls, pParse, __ccgo_ts+12876, libc.VaList(bp+24, **(**uintptr)(__ccgo_up(bp + 8)), nCons, pCons, (*TTable)(unsafe.Pointer(pTab)).FzName))
/* Finally, reload the database schema. */
_renameReloadSchema(tls, pParse, **(**int32)(__ccgo_up(bp)), uint16(INITFLAG_AlterDropCons))
}
// C documentation
//
// /*
// ** This function is called by the parser after the table-name in
// ** an "ALTER TABLE ADD" statement is parsed. Argument
// ** pSrc is the full-name of the table being altered.
// **
// ** This routine makes a (partial) copy of the Table structure
// ** for the table being altered and sets Parse.pNewTable to point
// ** to it. Routines called by the parser as the column definition
// ** is parsed (i.e. sqlite3AddColumn()) add the new Column data to
// ** the copy. The copy of the Table structure is deleted by tokenize.c
// ** after parsing is finished.
// **
// ** Routine sqlite3AlterFinishAddColumn() will be called to complete
// ** coding the "ALTER TABLE ... ADD" statement.
// */
func _sqlite3AlterBeginAddColumn(tls *libc.TLS, pParse uintptr, pSrc uintptr) {
bp := tls.Alloc(16)
defer tls.Free(16)
var db, pCol, pNew, pTab uintptr
var i, iDb, nAlloc int32
_, _, _, _, _, _, _ = db, i, iDb, nAlloc, pCol, pNew, pTab
db = (*TParse)(unsafe.Pointer(pParse)).Fdb
/* Look up the table being altered. */
if (*Tsqlite3)(unsafe.Pointer(db)).FmallocFailed != 0 {
goto exit_begin_add_column
}
pTab = _sqlite3LocateTableItem(tls, pParse, uint32(0), pSrc+8)
if !(pTab != 0) {
goto exit_begin_add_column
}
if libc.Int32FromUint8((*TTable)(unsafe.Pointer(pTab)).FeTabType) == int32(TABTYP_VTAB) {
_sqlite3ErrorMsg(tls, pParse, __ccgo_ts+11380, 0)
goto exit_begin_add_column
}
/* Make sure this is not an attempt to ALTER a view. */
if libc.Int32FromUint8((*TTable)(unsafe.Pointer(pTab)).FeTabType) == int32(TABTYP_VIEW) {
_sqlite3ErrorMsg(tls, pParse, __ccgo_ts+11414, 0)
goto exit_begin_add_column
}
if SQLITE_OK != _isAlterableTable(tls, pParse, pTab) {
goto exit_begin_add_column
}
_sqlite3MayAbort(tls, pParse)
iDb = _sqlite3SchemaToIndex(tls, db, (*TTable)(unsafe.Pointer(pTab)).FpSchema)
/* Put a copy of the Table struct in Parse.pNewTable for the
** sqlite3AddColumn() function and friends to modify. But modify
** the name by adding an "sqlite_altertab_" prefix. By adding this
** prefix, we insure that the name will not collide with an existing
** table because user table are not allowed to have the "sqlite_"
** prefix on their name.
*/
pNew = _sqlite3DbMallocZero(tls, db, uint64(120))
if !(pNew != 0) {
goto exit_begin_add_column
}
(*TParse)(unsafe.Pointer(pParse)).FpNewTable = pNew
(*TTable)(unsafe.Pointer(pNew)).FnTabRef = uint32(1)
(*TTable)(unsafe.Pointer(pNew)).FnCol = (*TTable)(unsafe.Pointer(pTab)).FnCol
nAlloc = (int32((*TTable)(unsafe.Pointer(pNew)).FnCol)-int32(1))/int32(8)*int32(8) + int32(8)
(*TTable)(unsafe.Pointer(pNew)).FaCol = _sqlite3DbMallocZero(tls, db, uint64(16)*uint64(libc.Uint32FromInt32(nAlloc)))
(*TTable)(unsafe.Pointer(pNew)).FzName = _sqlite3MPrintf(tls, db, __ccgo_ts+11444, libc.VaList(bp+8, (*TTable)(unsafe.Pointer(pTab)).FzName))
if !((*TTable)(unsafe.Pointer(pNew)).FaCol != 0) || !((*TTable)(unsafe.Pointer(pNew)).FzName != 0) {
goto exit_begin_add_column
}
libc.X__builtin___memcpy_chk(tls, (*TTable)(unsafe.Pointer(pNew)).FaCol, (*TTable)(unsafe.Pointer(pTab)).FaCol, uint64(16)*libc.Uint64FromInt16((*TTable)(unsafe.Pointer(pNew)).FnCol), ^t__predefined_size_t(0))
i = 0
for {
if !(i < int32((*TTable)(unsafe.Pointer(pNew)).FnCol)) {
break
}
pCol = (*TTable)(unsafe.Pointer(pNew)).FaCol + uintptr(i)*16
(*TColumn)(unsafe.Pointer(pCol)).FzCnName = _sqlite3DbStrDup(tls, db, (*TColumn)(unsafe.Pointer(pCol)).FzCnName)
(*TColumn)(unsafe.Pointer(pCol)).FhName = _sqlite3StrIHash(tls, (*TColumn)(unsafe.Pointer(pCol)).FzCnName)
goto _1
_1:
;
i = i + 1
}
(*(*struct {
FaddColOffset int32
FpFKey uintptr
FpDfltList uintptr
})(unsafe.Pointer(pNew + 64))).FpDfltList = _sqlite3ExprListDup(tls, db, (*(*struct {
FaddColOffset int32
FpFKey uintptr
FpDfltList uintptr
})(unsafe.Pointer(pTab + 64))).FpDfltList, 0)
(*TTable)(unsafe.Pointer(pNew)).FpSchema = (**(**TDb)(__ccgo_up((*Tsqlite3)(unsafe.Pointer(db)).FaDb + uintptr(iDb)*32))).FpSchema
(*(*struct {
FaddColOffset int32
FpFKey uintptr
FpDfltList uintptr
})(unsafe.Pointer(pNew + 64))).FaddColOffset = (*(*struct {
FaddColOffset int32
FpFKey uintptr
FpDfltList uintptr
})(unsafe.Pointer(pTab + 64))).FaddColOffset
goto exit_begin_add_column
exit_begin_add_column:
;
_sqlite3SrcListDelete(tls, db, pSrc)
return
}
// C documentation
//
// /*
// ** 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+11555, 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)*16))).FcolFlags)&(libc.Int32FromInt32(COLFLAG_PRIMKEY)|libc.Int32FromInt32(COLFLAG_UNIQUE)) != 0 {
if libc.Int32FromUint16((**(**TColumn)(__ccgo_up((*TTable)(unsafe.Pointer(pTab)).FaCol + uintptr(iCol)*16))).FcolFlags)&int32(COLFLAG_PRIMKEY) != 0 {
v1 = __ccgo_ts + 11940
} else {
v1 = __ccgo_ts + 6179
}
_sqlite3ErrorMsg(tls, pParse, __ccgo_ts+11952, 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+11980, 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)*32))).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+12028, 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+12149, 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)*16))).FcolFlags)&int32(COLFLAG_VIRTUAL) == 0 {
pPk = uintptr(0)
nField = 0
v = _sqlite3GetVdbe(tls, pParse)
v1 = pParse + 56
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 + 60
*(*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 + 60)) += int32((*TTable)(unsafe.Pointer(pTab)).FnCol)
} else {
pPk = _sqlite3PrimaryKeyIndex(tls, pTab)
**(**int32)(__ccgo_up(pParse + 60)) += 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 + 60
*(*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)*16))).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)*16))).Faffinity
if int32(aff) == int32(SQLITE_AFF_REAL) {
(**(**TColumn)(__ccgo_up((*TTable)(unsafe.Pointer(pTab)).FaCol + uintptr(i)*16))).Faffinity = int8(SQLITE_AFF_NUMERIC)
}
_sqlite3ExprCodeGetColumnOfTable(tls, v, pTab, iCur, i, regOut)
(**(**TColumn)(__ccgo_up((*TTable)(unsafe.Pointer(pTab)).FaCol + uintptr(i)*16))).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
//
// /*
// ** Generate bytecode for one of:
// **
// ** (1) ALTER TABLE pSrc DROP CONSTRAINT pCons
// ** (2) ALTER TABLE pSrc ALTER pCol DROP NOT NULL
// **
// ** One of pCons and pCol must be NULL and the other non-null.
// */
func _sqlite3AlterDropConstraint(tls *libc.TLS, pParse uintptr, pSrc uintptr, pCons uintptr, pCol uintptr) {
bp := tls.Alloc(64)
defer tls.Free(64)
var db, pTab, z, zArg uintptr
var _ /* iCol at bp+16 */ int32
var _ /* iDb at bp+0 */ int32
var _ /* zDb at bp+8 */ uintptr
_, _, _, _ = db, pTab, z, zArg
db = (*TParse)(unsafe.Pointer(pParse)).Fdb
pTab = uintptr(0)
**(**int32)(__ccgo_up(bp)) = 0
**(**uintptr)(__ccgo_up(bp + 8)) = uintptr(0)
zArg = uintptr(0)
pTab = _alterFindTable(tls, pParse, pSrc, bp, bp+8, libc.BoolInt32(pCons != uintptr(0)))
if !(pTab != 0) {
return
}
if pCons != 0 {
z = _sqlite3NameFromToken(tls, db, pCons)
zArg = _sqlite3MPrintf(tls, db, __ccgo_ts+12273, libc.VaList(bp+32, z))
_sqlite3DbFree(tls, db, z)
} else {
if _alterFindCol(tls, pParse, pTab, pCol, bp+16) != 0 {
return
}
zArg = _sqlite3MPrintf(tls, db, __ccgo_ts+5637, libc.VaList(bp+32, **(**int32)(__ccgo_up(bp + 16))))
}
/* Edit the SQL for the named table. */
_sqlite3NestedParse(tls, pParse, __ccgo_ts+12276, libc.VaList(bp+32, **(**uintptr)(__ccgo_up(bp + 8)), zArg, (*TTable)(unsafe.Pointer(pTab)).FzName))
_sqlite3DbFree(tls, db, zArg)
/* Finally, reload the database schema. */
_renameReloadSchema(tls, pParse, **(**int32)(__ccgo_up(bp)), uint16(INITFLAG_AlterDropCons))
}
// C documentation
//
// /*
// ** 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)*32))).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))*16
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+10637, 0)
return
}
if (*TTable)(unsafe.Pointer(pNew)).FpIndex != 0 {
_sqlite3ErrorMsg(tls, pParse, __ccgo_ts+10669, 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 + 64))).FpFKey != 0 && pDflt != 0 {
_sqlite3ErrorIfNotEmpty(tls, pParse, zDb, zTab, __ccgo_ts+10696)
}
if int32(uint32(*(*uint8)(unsafe.Pointer(pCol + 8))&0xf>>0)) != 0 && !(pDflt != 0) {
_sqlite3ErrorIfNotEmpty(tls, pParse, zDb, zTab, __ccgo_ts+10755)
}
/* 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+10808)
}
_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+10854)
}
}
/* 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+10881, libc.VaList(bp+16, zDb, (*(*struct {
FaddColOffset int32
FpFKey uintptr
FpDfltList uintptr
})(unsafe.Pointer(pNew + 64))).FaddColOffset, zCol, (*(*struct {
FaddColOffset int32
FpFKey uintptr
FpDfltList uintptr
})(unsafe.Pointer(pNew + 64))).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 + 8))&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+11027, 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)*32))).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+11555, 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+11576, 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+11758, 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+10586, int32(1))
goto exit_rename_column
exit_rename_column:
;
_sqlite3SrcListDelete(tls, db, pSrc)
_sqlite3DbFree(tls, db, zOld)
_sqlite3DbFree(tls, db, zNew)
return
}
// C documentation
//
// /*
// ** Generate code to implement the "ALTER TABLE xxx RENAME TO yyy"
// ** command.
// */
func _sqlite3AlterRenameTable(tls *libc.TLS, pParse uintptr, pSrc uintptr, pName uintptr) {
bp := tls.Alloc(64)
defer tls.Free(64)
var db, pTab, pVTab, v, zDb, zName, zTabName, v2 uintptr
var i, iDb, nTabName, v1 int32
_, _, _, _, _, _, _, _, _, _, _, _ = db, i, iDb, nTabName, pTab, pVTab, v, zDb, zName, zTabName, v1, v2 /* Table being renamed */
zName = uintptr(0) /* NULL-terminated version of pName */
db = (*TParse)(unsafe.Pointer(pParse)).Fdb
pVTab = uintptr(0) /* Non-zero if this is a v-tab with an xRename() */
if (*Tsqlite3)(unsafe.Pointer(db)).FmallocFailed != 0 {
goto exit_rename_table
}
pTab = _sqlite3LocateTableItem(tls, pParse, uint32(0), pSrc+8)
if !(pTab != 0) {
goto exit_rename_table
}
iDb = _sqlite3SchemaToIndex(tls, (*TParse)(unsafe.Pointer(pParse)).Fdb, (*TTable)(unsafe.Pointer(pTab)).FpSchema)
zDb = (**(**TDb)(__ccgo_up((*Tsqlite3)(unsafe.Pointer(db)).FaDb + uintptr(iDb)*32))).FzDbSName
/* Get a NULL terminated version of the new table name. */
zName = _sqlite3NameFromToken(tls, db, pName)
if !(zName != 0) {
goto exit_rename_table
}
/* Check that a table or index named 'zName' does not already exist
** in database iDb. If so, this is an error.
*/
if _sqlite3FindTable(tls, db, zName, zDb) != 0 || _sqlite3FindIndex(tls, db, zName, zDb) != 0 || _sqlite3IsShadowTableOf(tls, db, pTab, zName) != 0 {
_sqlite3ErrorMsg(tls, pParse, __ccgo_ts+9666, libc.VaList(bp+8, zName))
goto exit_rename_table
}
/* Make sure it is not a system table being altered, or a reserved name
** that the table is being renamed to.
*/
if SQLITE_OK != _isAlterableTable(tls, pParse, pTab) {
goto exit_rename_table
}
if SQLITE_OK != _sqlite3CheckObjectName(tls, pParse, zName, __ccgo_ts+9725, zName) {
goto exit_rename_table
}
if libc.Int32FromUint8((*TTable)(unsafe.Pointer(pTab)).FeTabType) == int32(TABTYP_VIEW) {
_sqlite3ErrorMsg(tls, pParse, __ccgo_ts+9731, libc.VaList(bp+8, (*TTable)(unsafe.Pointer(pTab)).FzName))
goto exit_rename_table
}
/* Invoke the authorization callback. */
if _sqlite3AuthCheck(tls, pParse, int32(SQLITE_ALTER_TABLE), zDb, (*TTable)(unsafe.Pointer(pTab)).FzName, uintptr(0)) != 0 {
goto exit_rename_table
}
if _sqlite3ViewGetColumnNames(tls, pParse, pTab) != 0 {
goto exit_rename_table
}
if libc.Int32FromUint8((*TTable)(unsafe.Pointer(pTab)).FeTabType) == int32(TABTYP_VTAB) {
pVTab = _sqlite3GetVTable(tls, db, pTab)
if (*Tsqlite3_module)(unsafe.Pointer((*Tsqlite3_vtab)(unsafe.Pointer((*TVTable)(unsafe.Pointer(pVTab)).FpVtab)).FpModule)).FxRename == uintptr(0) {
pVTab = uintptr(0)
}
}
/* Begin a transaction for database iDb. Then modify the schema cookie
** (since the ALTER TABLE modifies the schema). Call sqlite3MayAbort(),
** as the scalar functions (e.g. sqlite_rename_table()) invoked by the
** nested SQL may raise an exception. */
v = _sqlite3GetVdbe(tls, pParse)
if v == uintptr(0) {
goto exit_rename_table
}
_sqlite3MayAbort(tls, pParse)
/* figure out how many UTF-8 characters are in zName */
zTabName = (*TTable)(unsafe.Pointer(pTab)).FzName
nTabName = _sqlite3Utf8CharLen(tls, zTabName, -int32(1))
/* Rewrite all CREATE TABLE, INDEX, TRIGGER or VIEW statements in
** the schema to use the new table name. */
_sqlite3NestedParse(tls, pParse, __ccgo_ts+9758, libc.VaList(bp+8, zDb, zDb, zTabName, zName, libc.BoolInt32(iDb == int32(1)), zTabName))
/* Update the tbl_name and name columns of the sqlite_schema table
** as required. */
_sqlite3NestedParse(tls, pParse, __ccgo_ts+9942, libc.VaList(bp+8, zDb, zName, zName, zName, nTabName, zTabName))
/* If the sqlite_sequence table exists in this database, then update
** it with the new table name.
*/
if _sqlite3FindTable(tls, db, __ccgo_ts+10247, zDb) != 0 {
_sqlite3NestedParse(tls, pParse, __ccgo_ts+10263, libc.VaList(bp+8, zDb, zName, (*TTable)(unsafe.Pointer(pTab)).FzName))
}
/* If the table being renamed is not itself part of the temp database,
** edit view and trigger definitions within the temp database
** as required. */
if iDb != int32(1) {
_sqlite3NestedParse(tls, pParse, __ccgo_ts+10321, libc.VaList(bp+8, zDb, zTabName, zName, zTabName, zDb, zName))
}
/* If this is a virtual table, invoke the xRename() function if
** one is defined. The xRename() callback will modify the names
** of any resources used by the v-table implementation (including other
** SQLite tables) that are identified by the name of the virtual table.
*/
if pVTab != 0 {
v2 = pParse + 60
*(*int32)(unsafe.Pointer(v2)) = *(*int32)(unsafe.Pointer(v2)) + 1
v1 = *(*int32)(unsafe.Pointer(v2))
i = v1
_sqlite3VdbeLoadString(tls, v, i, zName)
_sqlite3VdbeAddOp4(tls, v, int32(OP_VRename), i, 0, 0, pVTab, -int32(12))
}
_renameReloadSchema(tls, pParse, iDb, uint16(INITFLAG_AlterRename))
_renameTestSchema(tls, pParse, zDb, libc.BoolInt32(iDb == int32(1)), __ccgo_ts+10586, 0)
goto exit_rename_table
exit_rename_table:
;
_sqlite3SrcListDelete(tls, db, pSrc)
_sqlite3DbFree(tls, db, zName)
}
// C documentation
//
// /*
// ** Prepare a statement of the form:
// **
// ** ALTER TABLE pSrc ALTER pCol SET NOT NULL
// */
func _sqlite3AlterSetNotNull(tls *libc.TLS, pParse uintptr, pSrc uintptr, pCol uintptr, pFirst uintptr) {
bp := tls.Alloc(80)
defer tls.Free(80)
var nCons int32
var pCons, pTab uintptr
var _ /* iCol at bp+0 */ int32
var _ /* iDb at bp+4 */ int32
var _ /* zDb at bp+8 */ uintptr
_, _, _ = nCons, pCons, pTab
pTab = uintptr(0)
**(**int32)(__ccgo_up(bp)) = 0
**(**int32)(__ccgo_up(bp + 4)) = 0
**(**uintptr)(__ccgo_up(bp + 8)) = uintptr(0)
pCons = uintptr(0)
nCons = 0
/* Look up the table being altered. */
pTab = _alterFindTable(tls, pParse, pSrc, bp+4, bp+8, 0)
if !(pTab != 0) {
return
}
/* Find the column being altered. */
if _alterFindCol(tls, pParse, pTab, pCol, bp) != 0 {
return
}
/* Find the length in bytes of the constraint definition */
pCons = (*TToken)(unsafe.Pointer(pFirst)).Fz
nCons = _alterRtrimConstraint(tls, (*TParse)(unsafe.Pointer(pParse)).Fdb, pCons, int32(int64((*TParse)(unsafe.Pointer(pParse)).FsLastToken.Fz)-int64(pCons)))
/* Search for a constraint violation. Throw an exception if one is found. */
_sqlite3NestedParse(tls, pParse, __ccgo_ts+12399, libc.VaList(bp+24, int32(SQLITE_CONSTRAINT), **(**uintptr)(__ccgo_up(bp + 8)), (*TTable)(unsafe.Pointer(pTab)).FzName, libc.Int32FromUint32((*TToken)(unsafe.Pointer(pCol)).Fn), (*TToken)(unsafe.Pointer(pCol)).Fz))
/* Edit the SQL for the named table. */
_sqlite3NestedParse(tls, pParse, __ccgo_ts+12480, libc.VaList(bp+24, **(**uintptr)(__ccgo_up(bp + 8)), **(**int32)(__ccgo_up(bp)), nCons, pCons, **(**int32)(__ccgo_up(bp)), (*TTable)(unsafe.Pointer(pTab)).FzName))
/* Finally, reload the database schema. */
_renameReloadSchema(tls, pParse, **(**int32)(__ccgo_up(bp + 4)), uint16(INITFLAG_AlterDropCons))
}
// C documentation
//
// /*
// ** Load the content of the sqlite_stat1 and sqlite_stat4 tables. The
// ** contents of sqlite_stat1 are used to populate the Index.aiRowEst[]
// ** arrays. The contents of sqlite_stat4 are used to populate the
// ** Index.aSample[] arrays.
// **
// ** If the sqlite_stat1 table is not present in the database, SQLITE_ERROR
// ** is returned. In this case, even if SQLITE_ENABLE_STAT4 was defined
// ** during compilation and the sqlite_stat4 table is present, no data is
// ** read from it.
// **
// ** If SQLITE_ENABLE_STAT4 was defined during compilation and the
// ** sqlite_stat4 table is not present in the database, SQLITE_ERROR is
// ** returned. However, in this case, data is read from the sqlite_stat1
// ** table (if it is present) before returning.
// **
// ** If an OOM error occurs, this function always sets db->mallocFailed.
// ** This means if the caller does not care about other errors, the return
// ** code may be ignored.
// */
func _sqlite3AnalysisLoad(tls *libc.TLS, db uintptr, iDb int32) (r int32) {
bp := tls.Alloc(32)
defer tls.Free(32)
var i, pIdx, pIdx1, pIdx2, pSchema, pStat1, pTab, zSql, v3 uintptr
var rc, v5 int32
var _ /* sInfo at bp+0 */ TanalysisInfo
_, _, _, _, _, _, _, _, _, _, _ = i, pIdx, pIdx1, pIdx2, pSchema, pStat1, pTab, rc, zSql, v3, v5
rc = SQLITE_OK
pSchema = (**(**TDb)(__ccgo_up((*Tsqlite3)(unsafe.Pointer(db)).FaDb + uintptr(iDb)*32))).FpSchema
/* Clear any prior statistics */
i = (*THash)(unsafe.Pointer(pSchema + 8)).Ffirst
for {
if !(i != 0) {
break
}
pTab = (*THashElem)(unsafe.Pointer(i)).Fdata
**(**Tu32)(__ccgo_up(pTab + 48)) &= libc.Uint32FromInt32(^libc.Int32FromInt32(TF_HasStat1))
goto _1
_1:
;
i = (*THashElem)(unsafe.Pointer(i)).Fnext
}
i = (*THash)(unsafe.Pointer(pSchema + 32)).Ffirst
for {
if !(i != 0) {
break
}
pIdx = (*THashElem)(unsafe.Pointer(i)).Fdata
libc.SetBitFieldPtr16Uint32(pIdx+100, libc.Uint32FromInt32(0), 7, 0x80)
_sqlite3DeleteIndexSamples(tls, db, pIdx)
(*TIndex)(unsafe.Pointer(pIdx)).FaSample = uintptr(0)
goto _2
_2:
;
i = (*THashElem)(unsafe.Pointer(i)).Fnext
}
/* Load new statistics out of the sqlite_stat1 table */
(**(**TanalysisInfo)(__ccgo_up(bp))).Fdb = db
(**(**TanalysisInfo)(__ccgo_up(bp))).FzDatabase = (**(**TDb)(__ccgo_up((*Tsqlite3)(unsafe.Pointer(db)).FaDb + uintptr(iDb)*32))).FzDbSName
v3 = _sqlite3FindTable(tls, db, __ccgo_ts+13181, (**(**TanalysisInfo)(__ccgo_up(bp))).FzDatabase)
pStat1 = v3
if v3 != 0 && libc.Int32FromUint8((*TTable)(unsafe.Pointer(pStat1)).FeTabType) == TABTYP_NORM {
zSql = _sqlite3MPrintf(tls, db, __ccgo_ts+13554, libc.VaList(bp+24, (**(**TanalysisInfo)(__ccgo_up(bp))).FzDatabase))
if zSql == uintptr(0) {
rc = int32(SQLITE_NOMEM)
} else {
rc = Xsqlite3_exec(tls, db, zSql, __ccgo_fp(_analysisLoader), bp, uintptr(0))
_sqlite3DbFree(tls, db, zSql)
}
}
/* Set appropriate defaults on all indexes not in the sqlite_stat1 table */
i = (*THash)(unsafe.Pointer(pSchema + 32)).Ffirst
for {
if !(i != 0) {
break
}
pIdx1 = (*THashElem)(unsafe.Pointer(i)).Fdata
if !(int32(uint32(*(*uint16)(unsafe.Pointer(pIdx1 + 100))&0x80>>7)) != 0) {
_sqlite3DefaultRowEst(tls, pIdx1)
}
goto _4
_4:
;
i = (*THashElem)(unsafe.Pointer(i)).Fnext
}
/* Load the statistics from the sqlite_stat4 table. */
if rc == SQLITE_OK {
(*Tsqlite3)(unsafe.Pointer(db)).Flookaside.FbDisable = (*Tsqlite3)(unsafe.Pointer(db)).Flookaside.FbDisable + 1
(*Tsqlite3)(unsafe.Pointer(db)).Flookaside.Fsz = uint16(0)
rc = _loadStat4(tls, db, (**(**TanalysisInfo)(__ccgo_up(bp))).FzDatabase)
(*Tsqlite3)(unsafe.Pointer(db)).Flookaside.FbDisable = (*Tsqlite3)(unsafe.Pointer(db)).Flookaside.FbDisable - 1
if (*Tsqlite3)(unsafe.Pointer(db)).Flookaside.FbDisable != 0 {
v5 = 0
} else {
v5 = libc.Int32FromUint16((*Tsqlite3)(unsafe.Pointer(db)).Flookaside.FszTrue)
}
(*Tsqlite3)(unsafe.Pointer(db)).Flookaside.Fsz = libc.Uint16FromInt32(v5)
}
i = (*THash)(unsafe.Pointer(pSchema + 32)).Ffirst
for {
if !(i != 0) {
break
}
pIdx2 = (*THashElem)(unsafe.Pointer(i)).Fdata
Xsqlite3_free(tls, (*TIndex)(unsafe.Pointer(pIdx2)).FaiRowEst)
(*TIndex)(unsafe.Pointer(pIdx2)).FaiRowEst = uintptr(0)
goto _6
_6:
;
i = (*THashElem)(unsafe.Pointer(i)).Fnext
}
if rc == int32(SQLITE_NOMEM) {
_sqlite3OomFault(tls, db)
}
return rc
}
/************** End of analyze.c *********************************************/
/************** Begin file attach.c ******************************************/
/*
** 2003 April 6
**
** The author disclaims copyright to this source code. In place of
** a legal notice, here is a blessing:
**
** May you do good and not evil.
** May you find forgiveness for yourself and forgive others.
** May you share freely, never taking more than you give.
**
*************************************************************************
** This file contains code used to implement the ATTACH and DETACH commands.
*/
/* #include "sqliteInt.h" */
// C documentation
//
// /*
// ** pArray is a pointer to an array of objects. Each object in the
// ** array is szEntry bytes in size. This routine uses sqlite3DbRealloc()
// ** to extend the array so that there is space for a new object at the end.
// **
// ** When this function is called, *pnEntry contains the current size of
// ** the array (in entries - so the allocation is ((*pnEntry) * szEntry) bytes
// ** in total).
// **
// ** If the realloc() is successful (i.e. if no OOM condition occurs), the
// ** space allocated for the new object is zeroed, *pnEntry updated to
// ** reflect the new size of the array and a pointer to the new allocation
// ** returned. *pIdx is set to the index of the new array entry in this case.
// **
// ** Otherwise, if the realloc() fails, *pIdx is set to -1, *pnEntry remains
// ** unchanged and a copy of pArray returned.
// */
func _sqlite3ArrayAllocate(tls *libc.TLS, db uintptr, pArray uintptr, szEntry int32, pnEntry uintptr, pIdx uintptr) (r uintptr) {
var n, sz Tsqlite3_int64
var pNew, z uintptr
var v1 int32
var v2 int64
_, _, _, _, _, _ = n, pNew, sz, z, v1, v2
v1 = **(**int32)(__ccgo_up(pnEntry))
**(**int32)(__ccgo_up(pIdx)) = v1
n = int64(v1)
if n&(n-int64(1)) == 0 {
if n == 0 {
v2 = int64(1)
} else {
v2 = int64(2) * n
}
sz = v2
pNew = _sqlite3DbRealloc(tls, db, pArray, libc.Uint64FromInt64(sz*int64(szEntry)))
if pNew == uintptr(0) {
**(**int32)(__ccgo_up(pIdx)) = -int32(1)
return pArray
}
pArray = pNew
}
z = pArray
libc.X__builtin___memset_chk(tls, z+uintptr(n*int64(szEntry)), 0, libc.Uint64FromInt32(szEntry), ^t__predefined_size_t(0))
**(**int32)(__ccgo_up(pnEntry)) = **(**int32)(__ccgo_up(pnEntry)) + 1
return pArray
}
// C documentation
//
// /*
// ** Do an authorization check using the code and arguments given. Return
// ** either SQLITE_OK (zero) or SQLITE_IGNORE or SQLITE_DENY. If SQLITE_DENY
// ** is returned, then the error count and error message in pParse are
// ** modified appropriately.
// */
func _sqlite3AuthCheck(tls *libc.TLS, pParse uintptr, code int32, zArg1 uintptr, zArg2 uintptr, zArg3 uintptr) (r int32) {
var db uintptr
var rc int32
_, _ = db, rc
db = (*TParse)(unsafe.Pointer(pParse)).Fdb
/* Don't do any authorization checks if the database is initializing
** or if the parser is being invoked from within sqlite3_declare_vtab.
*/
if (*Tsqlite3)(unsafe.Pointer(db)).FxAuth == uintptr(0) || (*Tsqlite3)(unsafe.Pointer(db)).Finit1.Fbusy != 0 || libc.Int32FromUint8((*TParse)(unsafe.Pointer(pParse)).FeParseMode) != PARSE_MODE_NORMAL {
return SQLITE_OK
}
/* EVIDENCE-OF: R-43249-19882 The third through sixth parameters to the
** callback are either NULL pointers or zero-terminated strings that
** contain additional details about the action to be authorized.
**
** The following testcase() macros show that any of the 3rd through 6th
** parameters can be either NULL or a string. */
rc = (*(*func(*libc.TLS, uintptr, int32, uintptr, uintptr, uintptr, uintptr) int32)(unsafe.Pointer(&struct{ uintptr }{(*Tsqlite3)(unsafe.Pointer(db)).FxAuth})))(tls, (*Tsqlite3)(unsafe.Pointer(db)).FpAuthArg, code, zArg1, zArg2, zArg3, (*TParse)(unsafe.Pointer(pParse)).FzAuthContext)
if rc == int32(SQLITE_DENY) {
_sqlite3ErrorMsg(tls, pParse, __ccgo_ts+14019, 0)
(*TParse)(unsafe.Pointer(pParse)).Frc = int32(SQLITE_AUTH)
} else {
if rc != SQLITE_OK && rc != int32(SQLITE_IGNORE) {
rc = int32(SQLITE_DENY)
_sqliteAuthBadReturnCode(tls, pParse)
}
}
return rc
}
// C documentation
//
// /*
// ** The pExpr should be a TK_COLUMN expression. The table referred to
// ** is in pTabList or else it is the NEW or OLD table of a trigger.
// ** Check to see if it is OK to read this particular column.
// **
// ** If the auth function returns SQLITE_IGNORE, change the TK_COLUMN
// ** instruction into a TK_NULL. If the auth function returns SQLITE_DENY,
// ** then generate an error.
// */
func _sqlite3AuthRead(tls *libc.TLS, pParse uintptr, pExpr uintptr, pSchema uintptr, pTabList uintptr) {
var iCol, iDb, iSrc int32
var pTab, zCol uintptr
_, _, _, _, _ = iCol, iDb, iSrc, pTab, zCol
pTab = uintptr(0) /* Index of column in table */
iDb = _sqlite3SchemaToIndex(tls, (*TParse)(unsafe.Pointer(pParse)).Fdb, pSchema)
if iDb < 0 {
/* An attempt to read a column out of a subquery or other
** temporary table. */
return
}
if libc.Int32FromUint8((*TExpr)(unsafe.Pointer(pExpr)).Fop) == int32(TK_TRIGGER) {
pTab = (*TParse)(unsafe.Pointer(pParse)).FpTriggerTab
} else {
iSrc = 0
for {
if !(iSrc < (*TSrcList)(unsafe.Pointer(pTabList)).FnSrc) {
break
}
if (*TExpr)(unsafe.Pointer(pExpr)).FiTable == (*(*TSrcItem)(unsafe.Pointer(pTabList + 8 + uintptr(iSrc)*80))).FiCursor {
pTab = (*(*TSrcItem)(unsafe.Pointer(pTabList + 8 + uintptr(iSrc)*80))).FpSTab
break
}
goto _1
_1:
;
iSrc = iSrc + 1
}
}
iCol = int32((*TExpr)(unsafe.Pointer(pExpr)).FiColumn)
if pTab == uintptr(0) {
return
}
if iCol >= 0 {
zCol = (**(**TColumn)(__ccgo_up((*TTable)(unsafe.Pointer(pTab)).FaCol + uintptr(iCol)*16))).FzCnName
} else {
if int32((*TTable)(unsafe.Pointer(pTab)).FiPKey) >= 0 {
zCol = (**(**TColumn)(__ccgo_up((*TTable)(unsafe.Pointer(pTab)).FaCol + uintptr((*TTable)(unsafe.Pointer(pTab)).FiPKey)*16))).FzCnName
} else {
zCol = __ccgo_ts + 8545
}
}
if int32(SQLITE_IGNORE) == _sqlite3AuthReadCol(tls, pParse, (*TTable)(unsafe.Pointer(pTab)).FzName, zCol, iDb) {
(*TExpr)(unsafe.Pointer(pExpr)).Fop = uint8(TK_NULL)
}
}
// C documentation
//
// /*
// ** Invoke the authorization callback for permission to read column zCol from
// ** table zTab in database zDb. This function assumes that an authorization
// ** callback has been registered (i.e. that sqlite3.xAuth is not NULL).
// **
// ** If SQLITE_IGNORE is returned and pExpr is not NULL, then pExpr is changed
// ** to an SQL NULL expression. Otherwise, if pExpr is NULL, then SQLITE_IGNORE
// ** is treated as SQLITE_DENY. In this case an error is left in pParse.
// */
func _sqlite3AuthReadCol(tls *libc.TLS, pParse uintptr, zTab uintptr, zCol uintptr, iDb int32) (r int32) {
bp := tls.Alloc(32)
defer tls.Free(32)
var db, z, zDb uintptr
var rc int32
_, _, _, _ = db, rc, z, zDb
db = (*TParse)(unsafe.Pointer(pParse)).Fdb /* Database handle */
zDb = (**(**TDb)(__ccgo_up((*Tsqlite3)(unsafe.Pointer(db)).FaDb + uintptr(iDb)*32))).FzDbSName /* Auth callback return code */
if (*Tsqlite3)(unsafe.Pointer(db)).Finit1.Fbusy != 0 {
return SQLITE_OK
}
rc = (*(*func(*libc.TLS, uintptr, int32, uintptr, uintptr, uintptr, uintptr) int32)(unsafe.Pointer(&struct{ uintptr }{(*Tsqlite3)(unsafe.Pointer(db)).FxAuth})))(tls, (*Tsqlite3)(unsafe.Pointer(db)).FpAuthArg, int32(SQLITE_READ), zTab, zCol, zDb, (*TParse)(unsafe.Pointer(pParse)).FzAuthContext)
if rc == int32(SQLITE_DENY) {
z = Xsqlite3_mprintf(tls, __ccgo_ts+13980, libc.VaList(bp+8, zTab, zCol))
if (*Tsqlite3)(unsafe.Pointer(db)).FnDb > int32(2) || iDb != 0 {
z = Xsqlite3_mprintf(tls, __ccgo_ts+13986, libc.VaList(bp+8, zDb, z))
}
_sqlite3ErrorMsg(tls, pParse, __ccgo_ts+13992, libc.VaList(bp+8, z))
(*TParse)(unsafe.Pointer(pParse)).Frc = int32(SQLITE_AUTH)
} else {
if rc != int32(SQLITE_IGNORE) && rc != SQLITE_OK {
_sqliteAuthBadReturnCode(tls, pParse)
}
}
return rc
}
// C documentation
//
// /*
// ** Load all automatic extensions.
// **
// ** If anything goes wrong, set an error in the database connection.
// */
func _sqlite3AutoLoadExtensions(tls *libc.TLS, db uintptr) {
bp := tls.Alloc(32)
defer tls.Free(32)
var go1, rc, v2 int32
var i Tu32
var mutex, pThunk uintptr
var xInit Tsqlite3_loadext_entry
var v3 bool
var _ /* zErrmsg at bp+0 */ uintptr
_, _, _, _, _, _, _, _ = go1, i, mutex, pThunk, rc, xInit, v2, v3
go1 = int32(1)
if _sqlite3Autoext.FnExt == uint32(0) {
/* Common case: early out without every having to acquire a mutex */
return
}
i = uint32(0)
for {
if !(go1 != 0) {
break
}
mutex = _sqlite3MutexAlloc(tls, int32(SQLITE_MUTEX_STATIC_MAIN))
pThunk = uintptr(unsafe.Pointer(&_sqlite3Apis))
Xsqlite3_mutex_enter(tls, mutex)
if i >= _sqlite3Autoext.FnExt {
xInit = uintptr(0)
go1 = 0
} else {
xInit = **(**uintptr)(__ccgo_up(_sqlite3Autoext.FaExt + uintptr(i)*8))
}
Xsqlite3_mutex_leave(tls, mutex)
**(**uintptr)(__ccgo_up(bp)) = uintptr(0)
if v3 = xInit != 0; v3 {
v2 = (*(*func(*libc.TLS, uintptr, uintptr, uintptr) int32)(unsafe.Pointer(&struct{ uintptr }{xInit})))(tls, db, bp, pThunk)
rc = v2
}
if v3 && v2 != 0 {
_sqlite3ErrorWithMsg(tls, db, rc, __ccgo_ts+18092, libc.VaList(bp+16, **(**uintptr)(__ccgo_up(bp))))
go1 = 0
}
Xsqlite3_free(tls, **(**uintptr)(__ccgo_up(bp)))
goto _1
_1:
;
i = i + 1
}
}
/************** End of loadext.c *********************************************/
/************** Begin file pragma.c ******************************************/
/*
** 2003 April 6
**
** The author disclaims copyright to this source code. In place of
** a legal notice, here is a blessing:
**
** May you do good and not evil.
** May you find forgiveness for yourself and forgive others.
** May you share freely, never taking more than you give.
**
*************************************************************************
** This file contains code used to implement the PRAGMA command.
*/
/* #include "sqliteInt.h" */
/***************************************************************************
** The "pragma.h" include file is an automatically generated file that
** that includes the PragType_XXXX macro definitions and the aPragmaName[]
** object. This ensures that the aPragmaName[] table is arranged in
** lexicographical order to facility a binary search of the pragma name.
** Do not edit pragma.h directly. Edit and rerun the script in at
** ../tool/mkpragmatab.tcl. */
/************** Include pragma.h in the middle of pragma.c *******************/
/************** Begin file pragma.h ******************************************/
/* DO NOT EDIT!
** This file is automatically generated by the script at
** ../tool/mkpragmatab.tcl. To update the set of pragmas, edit
** that script and rerun it.
*/
/* The various pragma types */
/* Property flags associated with various pragma. */
// C documentation
//
// /*
// ** Generate VDBE code for a BEGIN statement.
// */
func _sqlite3BeginTransaction(tls *libc.TLS, pParse uintptr, type1 int32) {
var db, pBt, v uintptr
var eTxnType, i int32
_, _, _, _, _ = db, eTxnType, i, pBt, v
db = (*TParse)(unsafe.Pointer(pParse)).Fdb
if _sqlite3AuthCheck(tls, pParse, int32(SQLITE_TRANSACTION), __ccgo_ts+16451, uintptr(0), uintptr(0)) != 0 {
return
}
v = _sqlite3GetVdbe(tls, pParse)
if !(v != 0) {
return
}
if type1 != int32(TK_DEFERRED) {
i = 0
for {
if !(i < (*Tsqlite3)(unsafe.Pointer(db)).FnDb) {
break
}
pBt = (**(**TDb)(__ccgo_up((*Tsqlite3)(unsafe.Pointer(db)).FaDb + uintptr(i)*32))).FpBt
if pBt != 0 && _sqlite3BtreeIsReadonly(tls, pBt) != 0 {
eTxnType = 0 /* Read txn */
} else {
if type1 == int32(TK_EXCLUSIVE) {
eTxnType = int32(2) /* Exclusive txn */
} else {
eTxnType = int32(1) /* Write txn */
}
}
_sqlite3VdbeAddOp2(tls, v, int32(OP_Transaction), i, eTxnType)
_sqlite3VdbeUsesBtree(tls, v, i)
goto _1
_1:
;
i = i + 1
}
}
_sqlite3VdbeAddOp0(tls, v, int32(OP_AutoCommit))
}
// C documentation
//
// /*
// ** This is called by the parser when it sees a CREATE TRIGGER statement
// ** up to the point of the BEGIN before the trigger actions. A Trigger
// ** structure is generated based on the information available and stored
// ** in pParse->pNewTrigger. After the trigger actions have been parsed, the
// ** sqlite3FinishTrigger() function is called to complete the trigger
// ** construction process.
// */
func _sqlite3BeginTrigger(tls *libc.TLS, pParse uintptr, pName1 uintptr, pName2 uintptr, tr_tm int32, op int32, pColumns uintptr, pTableName uintptr, pWhen uintptr, isTemp int32, noErr int32) {
bp := tls.Alloc(128)
defer tls.Free(128)
var code, iDb, iTabDb, v4 int32
var db, pTab, pTrigger, zDb, zDbTrig, zName, v1 uintptr
var _ /* pName at bp+0 */ uintptr
var _ /* sFix at bp+8 */ TDbFixer
_, _, _, _, _, _, _, _, _, _, _ = code, db, iDb, iTabDb, pTab, pTrigger, zDb, zDbTrig, zName, v1, v4
pTrigger = uintptr(0) /* Table that the trigger fires off of */
zName = uintptr(0) /* Name of the trigger */
db = (*TParse)(unsafe.Pointer(pParse)).Fdb /* State vector for the DB fixer */
/* pName1->z might be NULL, but not pName1 itself */
if isTemp != 0 {
/* If TEMP was specified, then the trigger name may not be qualified. */
if (*TToken)(unsafe.Pointer(pName2)).Fn > uint32(0) {
_sqlite3ErrorMsg(tls, pParse, __ccgo_ts+22231, 0)
goto trigger_cleanup
}
iDb = int32(1)
**(**uintptr)(__ccgo_up(bp)) = pName1
} else {
/* Figure out the db that the trigger will be created in */
iDb = _sqlite3TwoPartName(tls, pParse, pName1, pName2, bp)
if iDb < 0 {
goto trigger_cleanup
}
}
if !(pTableName != 0) || (*Tsqlite3)(unsafe.Pointer(db)).FmallocFailed != 0 {
goto trigger_cleanup
}
/* A long-standing parser bug is that this syntax was allowed:
**
** CREATE TRIGGER attached.demo AFTER INSERT ON attached.tab ....
** ^^^^^^^^
**
** To maintain backwards compatibility, ignore the database
** name on pTableName if we are reparsing out of the schema table
*/
if (*Tsqlite3)(unsafe.Pointer(db)).Finit1.Fbusy != 0 && iDb != int32(1) {
_sqlite3DbFree(tls, db, *(*uintptr)(unsafe.Pointer(pTableName + 8 + 72)))
*(*uintptr)(unsafe.Pointer(pTableName + 8 + 72)) = uintptr(0)
}
/* If the trigger name was unqualified, and the table is a temp table,
** then set iDb to 1 to create the trigger in the temporary database.
** If sqlite3SrcListLookup() returns 0, indicating the table does not
** exist, the error is caught by the block below.
*/
pTab = _sqlite3SrcListLookup(tls, pParse, pTableName)
if libc.Int32FromUint8((*Tsqlite3)(unsafe.Pointer(db)).Finit1.Fbusy) == 0 && (*TToken)(unsafe.Pointer(pName2)).Fn == uint32(0) && pTab != 0 && (*TTable)(unsafe.Pointer(pTab)).FpSchema == (**(**TDb)(__ccgo_up((*Tsqlite3)(unsafe.Pointer(db)).FaDb + 1*32))).FpSchema {
iDb = int32(1)
}
/* Ensure the table name matches database name and that the table exists */
if (*Tsqlite3)(unsafe.Pointer(db)).FmallocFailed != 0 {
goto trigger_cleanup
}
_sqlite3FixInit(tls, bp+8, pParse, iDb, __ccgo_ts+22277, **(**uintptr)(__ccgo_up(bp)))
if _sqlite3FixSrcList(tls, bp+8, pTableName) != 0 {
goto trigger_cleanup
}
pTab = _sqlite3SrcListLookup(tls, pParse, pTableName)
if !(pTab != 0) {
/* The table does not exist. */
goto trigger_orphan_error
}
if libc.Int32FromUint8((*TTable)(unsafe.Pointer(pTab)).FeTabType) == int32(TABTYP_VTAB) {
_sqlite3ErrorMsg(tls, pParse, __ccgo_ts+22285, 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+22326, 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+22277, (*TTable)(unsafe.Pointer(pTab)).FzName) != 0 {
goto trigger_cleanup
}
if !(libc.Int32FromUint8((*TParse)(unsafe.Pointer(pParse)).FeParseMode) >= libc.Int32FromInt32(PARSE_MODE_RENAME)) {
if _sqlite3HashFind(tls, (**(**TDb)(__ccgo_up((*Tsqlite3)(unsafe.Pointer(db)).FaDb + uintptr(iDb)*32))).FpSchema+56, zName) != 0 {
if !(noErr != 0) {
_sqlite3ErrorMsg(tls, pParse, __ccgo_ts+22366, libc.VaList(bp+112, **(**uintptr)(__ccgo_up(bp))))
} else {
_sqlite3CodeVerifySchema(tls, pParse, iDb)
}
goto trigger_cleanup
}
}
/* NB: The SQLITE_ALLOW_TRIGGERS_ON_SYSTEM_TABLES compile-time option is
** experimental and unsupported. Do not use it unless understand the
** implications and you cannot get by without this capability. */
/* Do not create a trigger on a system table */
if Xsqlite3_strnicmp(tls, (*TTable)(unsafe.Pointer(pTab)).FzName, __ccgo_ts+7104, int32(7)) == 0 {
_sqlite3ErrorMsg(tls, pParse, __ccgo_ts+22392, 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 + 22430
} else {
v1 = __ccgo_ts + 22437
}
_sqlite3ErrorMsg(tls, pParse, __ccgo_ts+22443, libc.VaList(bp+112, v1, pTableName+8))
goto trigger_orphan_error
}
if !(libc.Int32FromUint8((*TTable)(unsafe.Pointer(pTab)).FeTabType) == libc.Int32FromInt32(TABTYP_VIEW)) && tr_tm == int32(TK_INSTEAD) {
_sqlite3ErrorMsg(tls, pParse, __ccgo_ts+22480, libc.VaList(bp+112, pTableName+8))
goto trigger_orphan_error
}
if !(libc.Int32FromUint8((*TParse)(unsafe.Pointer(pParse)).FeParseMode) >= libc.Int32FromInt32(PARSE_MODE_RENAME)) {
iTabDb = _sqlite3SchemaToIndex(tls, db, (*TTable)(unsafe.Pointer(pTab)).FpSchema)
code = int32(SQLITE_CREATE_TRIGGER)
zDb = (**(**TDb)(__ccgo_up((*Tsqlite3)(unsafe.Pointer(db)).FaDb + uintptr(iTabDb)*32))).FzDbSName
if isTemp != 0 {
v1 = (**(**TDb)(__ccgo_up((*Tsqlite3)(unsafe.Pointer(db)).FaDb + 1*32))).FzDbSName
} else {
v1 = zDb
}
zDbTrig = v1
if iTabDb == int32(1) || isTemp != 0 {
code = int32(SQLITE_CREATE_TEMP_TRIGGER)
}
if _sqlite3AuthCheck(tls, pParse, code, zName, (*TTable)(unsafe.Pointer(pTab)).FzName, zDbTrig) != 0 {
goto trigger_cleanup
}
if libc.Bool(!(libc.Int32FromInt32(OMIT_TEMPDB) != 0)) && iTabDb == int32(1) {
v1 = __ccgo_ts + 7112
} else {
v1 = __ccgo_ts + 6632
}
if _sqlite3AuthCheck(tls, pParse, int32(SQLITE_INSERT), v1, uintptr(0), zDb) != 0 {
goto trigger_cleanup
}
}
/* INSTEAD OF triggers can only appear on views and BEFORE triggers
** cannot appear on views. So we might as well translate every
** INSTEAD OF trigger into a BEFORE trigger. It simplifies code
** elsewhere.
*/
if tr_tm == int32(TK_INSTEAD) {
tr_tm = int32(TK_BEFORE)
}
/* Build the Trigger object */
pTrigger = _sqlite3DbMallocZero(tls, db, uint64(72))
if pTrigger == uintptr(0) {
goto trigger_cleanup
}
(*TTrigger)(unsafe.Pointer(pTrigger)).FzName = zName
zName = uintptr(0)
(*TTrigger)(unsafe.Pointer(pTrigger)).Ftable = _sqlite3DbStrDup(tls, db, (*(*TSrcItem)(unsafe.Pointer(pTableName + 8))).FzName)
(*TTrigger)(unsafe.Pointer(pTrigger)).FpSchema = (**(**TDb)(__ccgo_up((*Tsqlite3)(unsafe.Pointer(db)).FaDb + uintptr(iDb)*32))).FpSchema
(*TTrigger)(unsafe.Pointer(pTrigger)).FpTabSchema = (*TTable)(unsafe.Pointer(pTab)).FpSchema
(*TTrigger)(unsafe.Pointer(pTrigger)).Fop = libc.Uint8FromInt32(op)
if tr_tm == int32(TK_BEFORE) {
v4 = int32(TRIGGER_BEFORE)
} else {
v4 = int32(TRIGGER_AFTER)
}
(*TTrigger)(unsafe.Pointer(pTrigger)).Ftr_tm = libc.Uint8FromInt32(v4)
if libc.Int32FromUint8((*TParse)(unsafe.Pointer(pParse)).FeParseMode) >= int32(PARSE_MODE_RENAME) {
_sqlite3RenameTokenRemap(tls, pParse, (*TTrigger)(unsafe.Pointer(pTrigger)).Ftable, (*(*TSrcItem)(unsafe.Pointer(pTableName + 8))).FzName)
(*TTrigger)(unsafe.Pointer(pTrigger)).FpWhen = pWhen
pWhen = uintptr(0)
} else {
(*TTrigger)(unsafe.Pointer(pTrigger)).FpWhen = _sqlite3ExprDup(tls, db, pWhen, int32(EXPRDUP_REDUCE))
}
(*TTrigger)(unsafe.Pointer(pTrigger)).FpColumns = pColumns
pColumns = uintptr(0)
(*TParse)(unsafe.Pointer(pParse)).FpNewTrigger = pTrigger
goto trigger_cleanup
trigger_cleanup:
;
_sqlite3DbFree(tls, db, zName)
_sqlite3SrcListDelete(tls, db, pTableName)
_sqlite3IdListDelete(tls, db, pColumns)
_sqlite3ExprDelete(tls, db, pWhen)
if !((*TParse)(unsafe.Pointer(pParse)).FpNewTrigger != 0) {
_sqlite3DeleteTrigger(tls, db, pTrigger)
} else {
}
return
goto trigger_orphan_error
trigger_orphan_error:
;
if libc.Int32FromUint8((*Tsqlite3)(unsafe.Pointer(db)).Finit1.FiDb) == int32(1) {
/* Ticket #3810.
** Normally, whenever a table is dropped, all associated triggers are
** dropped too. But if a TEMP trigger is created on a non-TEMP table
** and the table is dropped by a different database connection, the
** trigger is not visible to the database connection that does the
** drop so the trigger cannot be dropped. This results in an
** "orphaned trigger" - a trigger whose associated table is missing.
**
** 2020-11-05 see also https://sqlite.org/forum/forumpost/157dc791df
*/
libc.SetBitFieldPtr8Uint32(db+192+8, libc.Uint32FromInt32(1), 0, 0x1)
}
goto trigger_cleanup
}
// C documentation
//
// /*
// ** Clear the i-th bit.
// **
// ** pBuf must be a pointer to at least BITVEC_SZ bytes of temporary storage
// ** that BitvecClear can use to rebuilt its hash table.
// */
func _sqlite3BitvecClear(tls *libc.TLS, p uintptr, i Tu32, pBuf uintptr) {
var aiValues, v1 uintptr
var bin, h Tu32
var j uint32
_, _, _, _, _ = aiValues, bin, h, j, v1
if p == uintptr(0) {
return
}
i = i - 1
for (*TBitvec)(unsafe.Pointer(p)).FiDivisor != 0 {
bin = i / (*TBitvec)(unsafe.Pointer(p)).FiDivisor
i = i % (*TBitvec)(unsafe.Pointer(p)).FiDivisor
p = **(**uintptr)(__ccgo_up(p + 16 + uintptr(bin)*8))
if !(p != 0) {
return
}
}
if uint64((*TBitvec)(unsafe.Pointer(p)).FiSize) <= (libc.Uint64FromInt32(BITVEC_SZ)-libc.Uint64FromInt32(3)*libc.Uint64FromInt64(4))/libc.Uint64FromInt64(8)*libc.Uint64FromInt64(8)/libc.Uint64FromInt64(1)*libc.Uint64FromInt32(BITVEC_SZELEM) {
v1 = p + 16 + uintptr(i/uint32(BITVEC_SZELEM))
*(*Tu8)(unsafe.Pointer(v1)) = Tu8(int32(*(*Tu8)(unsafe.Pointer(v1))) & ^libc.Int32FromUint8(libc.Uint8FromInt32(libc.Int32FromInt32(1)<<(i&libc.Uint32FromInt32(libc.Int32FromInt32(BITVEC_SZELEM)-libc.Int32FromInt32(1))))))
} else {
aiValues = pBuf
libc.X__builtin___memcpy_chk(tls, aiValues, p+16, uint64(496), ^t__predefined_size_t(0))
libc.X__builtin___memset_chk(tls, p+16, 0, uint64(496), ^t__predefined_size_t(0))
(*TBitvec)(unsafe.Pointer(p)).FnSet = uint32(0)
j = uint32(0)
for {
if !(uint64(j) < (libc.Uint64FromInt32(BITVEC_SZ)-libc.Uint64FromInt32(3)*libc.Uint64FromInt64(4))/libc.Uint64FromInt64(8)*libc.Uint64FromInt64(8)/libc.Uint64FromInt64(4)) {
break
}
if **(**Tu32)(__ccgo_up(aiValues + uintptr(j)*4)) != 0 && **(**Tu32)(__ccgo_up(aiValues + uintptr(j)*4)) != i+uint32(1) {
h = uint32(uint64((**(**Tu32)(__ccgo_up(aiValues + uintptr(j)*4))-libc.Uint32FromInt32(1))*libc.Uint32FromInt32(1)) % ((libc.Uint64FromInt32(BITVEC_SZ) - libc.Uint64FromInt32(3)*libc.Uint64FromInt64(4)) / libc.Uint64FromInt64(8) * libc.Uint64FromInt64(8) / libc.Uint64FromInt64(4)))
(*TBitvec)(unsafe.Pointer(p)).FnSet = (*TBitvec)(unsafe.Pointer(p)).FnSet + 1
for **(**Tu32)(__ccgo_up(p + 16 + uintptr(h)*4)) != 0 {
h = h + 1
if uint64(h) >= (libc.Uint64FromInt32(BITVEC_SZ)-libc.Uint64FromInt32(3)*libc.Uint64FromInt64(4))/libc.Uint64FromInt64(8)*libc.Uint64FromInt64(8)/libc.Uint64FromInt64(4) {
h = uint32(0)
}
}
**(**Tu32)(__ccgo_up(p + 16 + uintptr(h)*4)) = **(**Tu32)(__ccgo_up(aiValues + uintptr(j)*4))
}
goto _2
_2:
;
j = j + 1
}
}
}
// C documentation
//
// /*
// ** Set the i-th bit. Return 0 on success and an error code if
// ** anything goes wrong.
// **
// ** This routine might cause sub-bitmaps to be allocated. Failing
// ** to get the memory needed to hold the sub-bitmap is the only
// ** that can go wrong with an insert, assuming p and i are valid.
// **
// ** The calling function must ensure that p is a valid Bitvec object
// ** and that the value for "i" is within range of the Bitvec object.
// ** Otherwise the behavior is undefined.
// */
func _sqlite3BitvecSet(tls *libc.TLS, p uintptr, i Tu32) (r int32) {
var aiValues, v1 uintptr
var bin, h, v2 Tu32
var j uint32
var rc int32
_, _, _, _, _, _, _ = aiValues, bin, h, j, rc, v1, v2
if p == uintptr(0) {
return SQLITE_OK
}
i = i - 1
for uint64((*TBitvec)(unsafe.Pointer(p)).FiSize) > (libc.Uint64FromInt32(BITVEC_SZ)-libc.Uint64FromInt32(3)*libc.Uint64FromInt64(4))/libc.Uint64FromInt64(8)*libc.Uint64FromInt64(8)/libc.Uint64FromInt64(1)*libc.Uint64FromInt32(BITVEC_SZELEM) && (*TBitvec)(unsafe.Pointer(p)).FiDivisor != 0 {
bin = i / (*TBitvec)(unsafe.Pointer(p)).FiDivisor
i = i % (*TBitvec)(unsafe.Pointer(p)).FiDivisor
if **(**uintptr)(__ccgo_up(p + 16 + uintptr(bin)*8)) == uintptr(0) {
**(**uintptr)(__ccgo_up(p + 16 + uintptr(bin)*8)) = _sqlite3BitvecCreate(tls, (*TBitvec)(unsafe.Pointer(p)).FiDivisor)
if **(**uintptr)(__ccgo_up(p + 16 + uintptr(bin)*8)) == uintptr(0) {
return int32(SQLITE_NOMEM)
}
}
p = **(**uintptr)(__ccgo_up(p + 16 + uintptr(bin)*8))
}
if uint64((*TBitvec)(unsafe.Pointer(p)).FiSize) <= (libc.Uint64FromInt32(BITVEC_SZ)-libc.Uint64FromInt32(3)*libc.Uint64FromInt64(4))/libc.Uint64FromInt64(8)*libc.Uint64FromInt64(8)/libc.Uint64FromInt64(1)*libc.Uint64FromInt32(BITVEC_SZELEM) {
v1 = p + 16 + uintptr(i/uint32(BITVEC_SZELEM))
*(*Tu8)(unsafe.Pointer(v1)) = Tu8(int32(*(*Tu8)(unsafe.Pointer(v1))) | libc.Int32FromInt32(1)<<(i&libc.Uint32FromInt32(libc.Int32FromInt32(BITVEC_SZELEM)-libc.Int32FromInt32(1))))
return SQLITE_OK
}
v2 = i
i = i + 1
h = uint32(uint64(v2*libc.Uint32FromInt32(1)) % ((libc.Uint64FromInt32(BITVEC_SZ) - libc.Uint64FromInt32(3)*libc.Uint64FromInt64(4)) / libc.Uint64FromInt64(8) * libc.Uint64FromInt64(8) / libc.Uint64FromInt64(4)))
/* if there wasn't a hash collision, and this doesn't */
/* completely fill the hash, then just add it without */
/* worrying about sub-dividing and re-hashing. */
if !(**(**Tu32)(__ccgo_up(p + 16 + uintptr(h)*4)) != 0) {
if uint64((*TBitvec)(unsafe.Pointer(p)).FnSet) < (libc.Uint64FromInt32(BITVEC_SZ)-libc.Uint64FromInt32(3)*libc.Uint64FromInt64(4))/libc.Uint64FromInt64(8)*libc.Uint64FromInt64(8)/libc.Uint64FromInt64(4)-libc.Uint64FromInt32(1) {
goto bitvec_set_end
} else {
goto bitvec_set_rehash
}
}
/* there was a collision, check to see if it's already */
/* in hash, if not, try to find a spot for it */
for cond := true; cond; cond = **(**Tu32)(__ccgo_up(p + 16 + uintptr(h)*4)) != 0 {
if **(**Tu32)(__ccgo_up(p + 16 + uintptr(h)*4)) == i {
return SQLITE_OK
}
h = h + 1
if uint64(h) >= (libc.Uint64FromInt32(BITVEC_SZ)-libc.Uint64FromInt32(3)*libc.Uint64FromInt64(4))/libc.Uint64FromInt64(8)*libc.Uint64FromInt64(8)/libc.Uint64FromInt64(4) {
h = uint32(0)
}
}
/* we didn't find it in the hash. h points to the first */
/* available free spot. check to see if this is going to */
/* make our hash too "full". */
goto bitvec_set_rehash
bitvec_set_rehash:
;
if uint64((*TBitvec)(unsafe.Pointer(p)).FnSet) >= (libc.Uint64FromInt32(BITVEC_SZ)-libc.Uint64FromInt32(3)*libc.Uint64FromInt64(4))/libc.Uint64FromInt64(8)*libc.Uint64FromInt64(8)/libc.Uint64FromInt64(4)/libc.Uint64FromInt32(2) {
aiValues = _sqlite3DbMallocRaw(tls, uintptr(0), uint64(496))
if aiValues == uintptr(0) {
return int32(SQLITE_NOMEM)
} else {
libc.X__builtin___memcpy_chk(tls, aiValues, p+16, uint64(496), ^t__predefined_size_t(0))
libc.X__builtin___memset_chk(tls, p+16, 0, uint64(496), ^t__predefined_size_t(0))
(*TBitvec)(unsafe.Pointer(p)).FiDivisor = (*TBitvec)(unsafe.Pointer(p)).FiSize / uint32((libc.Uint64FromInt32(BITVEC_SZ)-libc.Uint64FromInt32(3)*libc.Uint64FromInt64(4))/libc.Uint64FromInt64(8)*libc.Uint64FromInt64(8)/libc.Uint64FromInt64(8))
if (*TBitvec)(unsafe.Pointer(p)).FiSize%uint32((libc.Uint64FromInt32(BITVEC_SZ)-libc.Uint64FromInt32(3)*libc.Uint64FromInt64(4))/libc.Uint64FromInt64(8)*libc.Uint64FromInt64(8)/libc.Uint64FromInt64(8)) != uint32(0) {
(*TBitvec)(unsafe.Pointer(p)).FiDivisor = (*TBitvec)(unsafe.Pointer(p)).FiDivisor + 1
}
if uint64((*TBitvec)(unsafe.Pointer(p)).FiDivisor) < (libc.Uint64FromInt32(BITVEC_SZ)-libc.Uint64FromInt32(3)*libc.Uint64FromInt64(4))/libc.Uint64FromInt64(8)*libc.Uint64FromInt64(8)/libc.Uint64FromInt64(1)*libc.Uint64FromInt32(BITVEC_SZELEM) {
(*TBitvec)(unsafe.Pointer(p)).FiDivisor = uint32((libc.Uint64FromInt32(BITVEC_SZ) - libc.Uint64FromInt32(3)*libc.Uint64FromInt64(4)) / libc.Uint64FromInt64(8) * libc.Uint64FromInt64(8) / libc.Uint64FromInt64(1) * libc.Uint64FromInt32(BITVEC_SZELEM))
}
rc = _sqlite3BitvecSet(tls, p, i)
j = uint32(0)
for {
if !(uint64(j) < (libc.Uint64FromInt32(BITVEC_SZ)-libc.Uint64FromInt32(3)*libc.Uint64FromInt64(4))/libc.Uint64FromInt64(8)*libc.Uint64FromInt64(8)/libc.Uint64FromInt64(4)) {
break
}
if **(**Tu32)(__ccgo_up(aiValues + uintptr(j)*4)) != 0 {
rc = rc | _sqlite3BitvecSet(tls, p, **(**Tu32)(__ccgo_up(aiValues + uintptr(j)*4)))
}
goto _3
_3:
;
j = j + 1
}
_sqlite3DbFree(tls, uintptr(0), aiValues)
return rc
}
}
goto bitvec_set_end
bitvec_set_end:
;
(*TBitvec)(unsafe.Pointer(p)).FnSet = (*TBitvec)(unsafe.Pointer(p)).FnSet + 1
**(**Tu32)(__ccgo_up(p + 16 + uintptr(h)*4)) = i
return SQLITE_OK
}
// C documentation
//
// /*
// ** Copy the complete content of pBtFrom into pBtTo. A transaction
// ** must be active for both files.
// **
// ** The size of file pTo may be reduced by this operation. If anything
// ** goes wrong, the transaction on pTo is rolled back. If successful, the
// ** transaction is committed before returning.
// */
func _sqlite3BtreeCopyFile(tls *libc.TLS, pTo uintptr, pFrom uintptr) (r int32) {
bp := tls.Alloc(96)
defer tls.Free(96)
var pFd, v1 uintptr
var rc int32
var _ /* b at bp+0 */ Tsqlite3_backup
var _ /* nByte at bp+80 */ Ti64
_, _, _ = pFd, rc, v1
_sqlite3BtreeEnter(tls, pTo)
_sqlite3BtreeEnter(tls, pFrom)
pFd = _sqlite3PagerFile(tls, _sqlite3BtreePager(tls, pTo))
if (*Tsqlite3_file)(unsafe.Pointer(pFd)).FpMethods != 0 {
**(**Ti64)(__ccgo_up(bp + 80)) = int64(_sqlite3BtreeGetPageSize(tls, pFrom)) * libc.Int64FromUint32(_sqlite3BtreeLastPage(tls, pFrom))
rc = _sqlite3OsFileControl(tls, pFd, int32(SQLITE_FCNTL_OVERWRITE), bp+80)
if rc == int32(SQLITE_NOTFOUND) {
rc = SQLITE_OK
}
if rc != 0 {
goto copy_finished
}
}
/* Set up an sqlite3_backup object. sqlite3_backup.pDestDb must be set
** to 0. This is used by the implementations of sqlite3_backup_step()
** and sqlite3_backup_finish() to detect that they are being called
** from this function, not directly by the user.
*/
libc.X__builtin___memset_chk(tls, bp, 0, uint64(80), ^t__predefined_size_t(0))
(**(**Tsqlite3_backup)(__ccgo_up(bp))).FpSrcDb = (*TBtree)(unsafe.Pointer(pFrom)).Fdb
(**(**Tsqlite3_backup)(__ccgo_up(bp))).FpSrc = pFrom
(**(**Tsqlite3_backup)(__ccgo_up(bp))).FpDest = pTo
(**(**Tsqlite3_backup)(__ccgo_up(bp))).FiNext = uint32(1)
/* 0x7FFFFFFF is the hard limit for the number of pages in a database
** file. By passing this as the number of pages to copy to
** sqlite3_backup_step(), we can guarantee that the copy finishes
** within a single call (unless an error occurs). The assert() statement
** checks this assumption - (p->rc) should be set to either SQLITE_DONE
** or an error code. */
Xsqlite3_backup_step(tls, bp, int32(0x7FFFFFFF))
rc = Xsqlite3_backup_finish(tls, bp)
if rc == SQLITE_OK {
v1 = (*TBtree)(unsafe.Pointer(pTo)).FpBt + 40
*(*Tu16)(unsafe.Pointer(v1)) = Tu16(int32(*(*Tu16)(unsafe.Pointer(v1))) & ^libc.Int32FromInt32(BTS_PAGESIZE_FIXED))
} else {
_sqlite3PagerClearCache(tls, _sqlite3BtreePager(tls, (**(**Tsqlite3_backup)(__ccgo_up(bp))).FpDest))
}
goto copy_finished
copy_finished:
;
_sqlite3BtreeLeave(tls, pFrom)
_sqlite3BtreeLeave(tls, pTo)
return rc
}
/************** End of backup.c **********************************************/
/************** Begin file vdbemem.c *****************************************/
/*
** 2004 May 26
**
** 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 use to manipulate "Mem" structure. A "Mem"
** stores a single value in the VDBE. Mem is an opaque structure visible
** only within the VDBE. Interface routines refer to a Mem using the
** name sqlite_value
*/
/* #include "sqliteInt.h" */
/* #include "vdbeInt.h" */
/* True if X is a power of two. 0 is considered a power of two here.
** In other words, return true if X has at most one bit set.
*/
// C documentation
//
// /*
// ** Initialize memory that will be converted into a BtCursor object.
// **
// ** The simple approach here would be to memset() the entire object
// ** to zero. But it turns out that the apPage[] and aiIdx[] arrays
// ** do not need to be zeroed and they are large, so we can save a lot
// ** of run-time by skipping the initialization of those elements.
// */
func _sqlite3BtreeCursorZero(tls *libc.TLS, p uintptr) {
libc.X__builtin___memset_chk(tls, p, 0, uint64(libc.UintptrFromInt32(0)+32), ^t__predefined_size_t(0))
}
// C documentation
//
// /* Move the cursor so that it points to an entry in an index table
// ** near the key pIdxKey. Return a success code.
// **
// ** If an exact match is not found, then the cursor is always
// ** left pointing at a leaf page which would hold the entry if it
// ** were present. The cursor might point to an entry that comes
// ** before or after the key.
// **
// ** An integer is written into *pRes which is the result of
// ** comparing the key with the entry to which the cursor is
// ** pointing. The meaning of the integer written into
// ** *pRes is as follows:
// **
// ** *pRes<0 The cursor is left pointing at an entry that
// ** is smaller than pIdxKey or if the table is empty
// ** and the cursor is therefore left point to nothing.
// **
// ** *pRes==0 The cursor is left pointing at an entry that
// ** exactly matches pIdxKey.
// **
// ** *pRes>0 The cursor is left pointing at an entry that
// ** is larger than pIdxKey.
// **
// ** The pIdxKey->eqSeen field is set to 1 if there
// ** exists an entry in the table that exactly matches pIdxKey.
// */
func _sqlite3BtreeIndexMoveto(tls *libc.TLS, pCur uintptr, pIdxKey uintptr, pRes uintptr) (r int32) {
var c, c1, idx, lwr, nCell, nOverrun, rc, upr, v1 int32
var chldPg TPgno
var pCell, pCellBody, pCellKey, pPage, v3 uintptr
var xRecordCompare TRecordCompare
var v10 Ti8
var v2 bool
_, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _ = c, c1, chldPg, idx, lwr, nCell, nOverrun, pCell, pCellBody, pCellKey, pPage, rc, upr, xRecordCompare, v1, v10, v2, v3
xRecordCompare = _sqlite3VdbeFindCompare(tls, pIdxKey)
(*TUnpackedRecord)(unsafe.Pointer(pIdxKey)).FerrCode = uint8(0)
/* Check to see if we can skip a lot of work. Two cases:
**
** (1) If the cursor is already pointing to the very last cell
** in the table and the pIdxKey search key is greater than or
** equal to that last cell, then no movement is required.
**
** (2) If the cursor is on the last page of the table and the first
** cell on that last page is less than or equal to the pIdxKey
** search key, then we can start the search on the current page
** without needing to go back to root.
*/
if libc.Int32FromUint8((*TBtCursor)(unsafe.Pointer(pCur)).FeState) == CURSOR_VALID && (*TMemPage)(unsafe.Pointer((*TBtCursor)(unsafe.Pointer(pCur)).FpPage)).Fleaf != 0 && _cursorOnLastPage(tls, pCur) != 0 {
if v2 = libc.Int32FromUint16((*TBtCursor)(unsafe.Pointer(pCur)).Fix) == libc.Int32FromUint16((*TMemPage)(unsafe.Pointer((*TBtCursor)(unsafe.Pointer(pCur)).FpPage)).FnCell)-int32(1); v2 {
v1 = _indexCellCompare(tls, (*TBtCursor)(unsafe.Pointer(pCur)).FpPage, libc.Int32FromUint16((*TBtCursor)(unsafe.Pointer(pCur)).Fix), pIdxKey, xRecordCompare)
c = v1
}
if v2 && v1 <= 0 && libc.Int32FromUint8((*TUnpackedRecord)(unsafe.Pointer(pIdxKey)).FerrCode) == SQLITE_OK {
**(**int32)(__ccgo_up(pRes)) = c
return SQLITE_OK /* Cursor already pointing at the correct spot */
}
if int32((*TBtCursor)(unsafe.Pointer(pCur)).FiPage) > 0 && _indexCellCompare(tls, (*TBtCursor)(unsafe.Pointer(pCur)).FpPage, 0, pIdxKey, xRecordCompare) <= 0 && libc.Int32FromUint8((*TUnpackedRecord)(unsafe.Pointer(pIdxKey)).FerrCode) == SQLITE_OK {
v3 = pCur + 1
*(*Tu8)(unsafe.Pointer(v3)) = Tu8(int32(*(*Tu8)(unsafe.Pointer(v3))) & ^(libc.Int32FromInt32(BTCF_ValidOvfl) | libc.Int32FromInt32(BTCF_AtLast)))
if !((*TMemPage)(unsafe.Pointer((*TBtCursor)(unsafe.Pointer(pCur)).FpPage)).FisInit != 0) {
return _sqlite3CorruptError(tls, int32(79316))
}
goto bypass_moveto_root /* Start search on the current page */
}
(*TUnpackedRecord)(unsafe.Pointer(pIdxKey)).FerrCode = uint8(SQLITE_OK)
}
rc = _moveToRoot(tls, pCur)
if rc != 0 {
if rc == int32(SQLITE_EMPTY) {
**(**int32)(__ccgo_up(pRes)) = -int32(1)
return SQLITE_OK
}
return rc
}
goto bypass_moveto_root
bypass_moveto_root:
;
for {
pPage = (*TBtCursor)(unsafe.Pointer(pCur)).FpPage /* Pointer to current cell in pPage */
/* pPage->nCell must be greater than zero. If this is the root-page
** the cursor would have been INVALID above and this for(;;) loop
** not run. If this is not the root-page, then the moveToChild() routine
** would have already detected db corruption. Similarly, pPage must
** be the right kind (index or table) of b-tree page. Otherwise
** a moveToChild() or moveToRoot() call would have detected corruption. */
lwr = 0
upr = libc.Int32FromUint16((*TMemPage)(unsafe.Pointer(pPage)).FnCell) - int32(1)
idx = upr >> int32(1) /* idx = (lwr+upr)/2; */
for { /* Size of the pCell cell in bytes */
pCell = (*TMemPage)(unsafe.Pointer(pPage)).FaDataOfst + uintptr(libc.Int32FromUint16((*TMemPage)(unsafe.Pointer(pPage)).FmaskPage)&(libc.Int32FromUint8(**(**Tu8)(__ccgo_up((*TMemPage)(unsafe.Pointer(pPage)).FaCellIdx + uintptr(int32(2)*idx))))<= (*TMemPage)(unsafe.Pointer(pPage)).FaDataEnd {
rc = _sqlite3CorruptError(tls, int32(79375))
goto moveto_index_finish
}
c1 = (*(*func(*libc.TLS, int32, uintptr, uintptr) int32)(unsafe.Pointer(&struct{ uintptr }{xRecordCompare})))(tls, nCell, pCell+1, pIdxKey)
} else {
if v2 = !(libc.Int32FromUint8(**(**Tu8)(__ccgo_up(pCell + 1)))&libc.Int32FromInt32(0x80) != 0); v2 {
v1 = nCell&libc.Int32FromInt32(0x7f)< (*TBtShared)(unsafe.Pointer((*TBtCursor)(unsafe.Pointer(pCur)).FpBt)).FnPage {
rc = _sqlite3CorruptError(tls, int32(79406))
goto moveto_index_finish
}
pCellKey = _sqlite3Malloc(tls, libc.Uint64FromInt32(nCell)+libc.Uint64FromInt32(nOverrun))
if pCellKey == uintptr(0) {
rc = int32(SQLITE_NOMEM)
goto moveto_index_finish
}
(*TBtCursor)(unsafe.Pointer(pCur)).Fix = libc.Uint16FromInt32(idx)
rc = _accessPayload(tls, pCur, uint32(0), libc.Uint32FromInt32(nCell), pCellKey, 0)
libc.X__builtin___memset_chk(tls, pCellKey+uintptr(nCell), 0, libc.Uint64FromInt32(nOverrun), ^t__predefined_size_t(0)) /* Fix uninit warnings */
v3 = pCur + 1
*(*Tu8)(unsafe.Pointer(v3)) = Tu8(int32(*(*Tu8)(unsafe.Pointer(v3))) & ^libc.Int32FromInt32(BTCF_ValidOvfl))
if rc != 0 {
Xsqlite3_free(tls, pCellKey)
goto moveto_index_finish
}
c1 = _sqlite3VdbeRecordCompare(tls, nCell, pCellKey, pIdxKey)
Xsqlite3_free(tls, pCellKey)
}
}
if c1 < 0 {
lwr = idx + int32(1)
} else {
if c1 > 0 {
upr = idx - int32(1)
} else {
**(**int32)(__ccgo_up(pRes)) = 0
rc = SQLITE_OK
(*TBtCursor)(unsafe.Pointer(pCur)).Fix = libc.Uint16FromInt32(idx)
if (*TUnpackedRecord)(unsafe.Pointer(pIdxKey)).FerrCode != 0 {
rc = _sqlite3CorruptError(tls, int32(79438))
}
goto moveto_index_finish
}
}
if lwr > upr {
break
}
idx = (lwr + upr) >> int32(1) /* idx = (lwr+upr)/2 */
goto _5
_5:
}
if (*TMemPage)(unsafe.Pointer(pPage)).Fleaf != 0 {
(*TBtCursor)(unsafe.Pointer(pCur)).Fix = libc.Uint16FromInt32(idx)
**(**int32)(__ccgo_up(pRes)) = c1
rc = SQLITE_OK
goto moveto_index_finish
}
if lwr >= libc.Int32FromUint16((*TMemPage)(unsafe.Pointer(pPage)).FnCell) {
chldPg = _sqlite3Get4byte(tls, (*TMemPage)(unsafe.Pointer(pPage)).FaData+uintptr(libc.Int32FromUint8((*TMemPage)(unsafe.Pointer(pPage)).FhdrOffset)+int32(8)))
} else {
chldPg = _sqlite3Get4byte(tls, (*TMemPage)(unsafe.Pointer(pPage)).FaData+uintptr(libc.Int32FromUint16((*TMemPage)(unsafe.Pointer(pPage)).FmaskPage)&(libc.Int32FromUint8(**(**Tu8)(__ccgo_up((*TMemPage)(unsafe.Pointer(pPage)).FaCellIdx + uintptr(int32(2)*lwr))))<ix = (u16)lwr;
** rc = moveToChild(pCur, chldPg);
** if( rc ) break;
*/
(*TBtCursor)(unsafe.Pointer(pCur)).Finfo.FnSize = uint16(0)
v3 = pCur + 1
*(*Tu8)(unsafe.Pointer(v3)) = Tu8(int32(*(*Tu8)(unsafe.Pointer(v3))) & ^(libc.Int32FromInt32(BTCF_ValidNKey) | libc.Int32FromInt32(BTCF_ValidOvfl)))
if int32((*TBtCursor)(unsafe.Pointer(pCur)).FiPage) >= libc.Int32FromInt32(BTCURSOR_MAX_DEPTH)-libc.Int32FromInt32(1) {
return _sqlite3CorruptError(tls, int32(79469))
}
**(**Tu16)(__ccgo_up(pCur + 88 + uintptr((*TBtCursor)(unsafe.Pointer(pCur)).FiPage)*2)) = libc.Uint16FromInt32(lwr)
**(**uintptr)(__ccgo_up(pCur + 144 + uintptr((*TBtCursor)(unsafe.Pointer(pCur)).FiPage)*8)) = (*TBtCursor)(unsafe.Pointer(pCur)).FpPage
(*TBtCursor)(unsafe.Pointer(pCur)).Fix = uint16(0)
(*TBtCursor)(unsafe.Pointer(pCur)).FiPage = (*TBtCursor)(unsafe.Pointer(pCur)).FiPage + 1
rc = _getAndInitPage(tls, (*TBtCursor)(unsafe.Pointer(pCur)).FpBt, chldPg, pCur+136, libc.Int32FromUint8((*TBtCursor)(unsafe.Pointer(pCur)).FcurPagerFlags))
if rc == SQLITE_OK && (libc.Int32FromUint16((*TMemPage)(unsafe.Pointer((*TBtCursor)(unsafe.Pointer(pCur)).FpPage)).FnCell) < int32(1) || libc.Int32FromUint8((*TMemPage)(unsafe.Pointer((*TBtCursor)(unsafe.Pointer(pCur)).FpPage)).FintKey) != libc.Int32FromUint8((*TBtCursor)(unsafe.Pointer(pCur)).FcurIntKey)) {
_releasePage(tls, (*TBtCursor)(unsafe.Pointer(pCur)).FpPage)
rc = _sqlite3CorruptError(tls, int32(79480))
}
if rc != 0 {
v3 = pCur + 84
*(*Ti8)(unsafe.Pointer(v3)) = *(*Ti8)(unsafe.Pointer(v3)) - 1
v10 = *(*Ti8)(unsafe.Pointer(v3))
(*TBtCursor)(unsafe.Pointer(pCur)).FpPage = **(**uintptr)(__ccgo_up(pCur + 144 + uintptr(v10)*8))
break
}
/*
***** End of in-lined moveToChild() call */
goto _4
_4:
}
goto moveto_index_finish
moveto_index_finish:
;
(*TBtCursor)(unsafe.Pointer(pCur)).Finfo.FnSize = uint16(0)
return rc
}
// C documentation
//
// /*
// ** Insert a new record into the BTree. The content of the new record
// ** is described by the pX object. The pCur cursor is used only to
// ** define what table the record should be inserted into, and is left
// ** pointing at a random location.
// **
// ** For a table btree (used for rowid tables), only the pX.nKey value of
// ** the key is used. The pX.pKey value must be NULL. The pX.nKey is the
// ** rowid or INTEGER PRIMARY KEY of the row. The pX.nData,pData,nZero fields
// ** hold the content of the row.
// **
// ** For an index btree (used for indexes and WITHOUT ROWID tables), the
// ** key is an arbitrary byte sequence stored in pX.pKey,nKey. The
// ** pX.pData,nData,nZero fields must be zero.
// **
// ** If the seekResult parameter is non-zero, then a successful call to
// ** sqlite3BtreeIndexMoveto() to seek cursor pCur to (pKey,nKey) has already
// ** been performed. In other words, if seekResult!=0 then the cursor
// ** is currently pointing to a cell that will be adjacent to the cell
// ** to be inserted. If seekResult<0 then pCur points to a cell that is
// ** smaller then (pKey,nKey). If seekResult>0 then pCur points to a cell
// ** that is larger than (pKey,nKey).
// **
// ** If seekResult==0, that means pCur is pointing at some unknown location.
// ** In that case, this routine must seek the cursor to the correct insertion
// ** point for (pKey,nKey) before doing the insertion. For index btrees,
// ** if pX->nMem is non-zero, then pX->aMem contains pointers to the unpacked
// ** key values and pX->aMem can be used instead of pX->pKey to avoid having
// ** to decode the key.
// */
func _sqlite3BtreeInsert(tls *libc.TLS, pCur uintptr, pX uintptr, flags int32, seekResult int32) (r int32) {
bp := tls.Alloc(160)
defer tls.Free(160)
var idx int32
var newCell, oldCell, p, pPage, v1 uintptr
var ovfl TPgno
var v2 Tu16
var _ /* info at bp+104 */ TCellInfo
var _ /* info at bp+128 */ TCellInfo
var _ /* loc at bp+4 */ int32
var _ /* r at bp+16 */ TUnpackedRecord
var _ /* rc at bp+0 */ int32
var _ /* szNew at bp+8 */ int32
var _ /* x2 at bp+56 */ TBtreePayload
_, _, _, _, _, _, _, _ = idx, newCell, oldCell, ovfl, p, pPage, v1, v2
**(**int32)(__ccgo_up(bp + 4)) = seekResult /* -1: before desired location +1: after */
**(**int32)(__ccgo_up(bp + 8)) = 0
p = (*TBtCursor)(unsafe.Pointer(pCur)).FpBtree
newCell = uintptr(0)
/* Save the positions of any other cursors open on this table.
**
** In some cases, the call to btreeMoveto() below is a no-op. For
** example, when inserting data into a table with auto-generated integer
** keys, the VDBE layer invokes sqlite3BtreeLast() to figure out the
** integer key to use. It then calls this function to actually insert the
** data into the intkey B-Tree. In this case btreeMoveto() recognizes
** that the cursor is already where it needs to be and returns without
** doing any work. To avoid thwarting these optimizations, it is important
** not to clear the cursor here.
*/
if libc.Int32FromUint8((*TBtCursor)(unsafe.Pointer(pCur)).FcurFlags)&int32(BTCF_Multiple) != 0 {
**(**int32)(__ccgo_up(bp)) = _saveAllCursors(tls, (*TBtree)(unsafe.Pointer(p)).FpBt, (*TBtCursor)(unsafe.Pointer(pCur)).FpgnoRoot, pCur)
if **(**int32)(__ccgo_up(bp)) != 0 {
return **(**int32)(__ccgo_up(bp))
}
if **(**int32)(__ccgo_up(bp + 4)) != 0 && int32((*TBtCursor)(unsafe.Pointer(pCur)).FiPage) < 0 {
/* This can only happen if the schema is corrupt such that there is more
** than one table or index with the same root page as used by the cursor.
** Which can only happen if the SQLITE_NoSchemaError flag was set when
** the schema was loaded. This cannot be asserted though, as a user might
** set the flag, load the schema, and then unset the flag. */
return _sqlite3CorruptError(tls, int32(82673))
}
}
/* Ensure that the cursor is not in the CURSOR_FAULT state and that it
** points to a valid cell.
*/
if libc.Int32FromUint8((*TBtCursor)(unsafe.Pointer(pCur)).FeState) >= int32(CURSOR_REQUIRESEEK) {
**(**int32)(__ccgo_up(bp)) = _moveToRoot(tls, pCur)
if **(**int32)(__ccgo_up(bp)) != 0 && **(**int32)(__ccgo_up(bp)) != int32(SQLITE_EMPTY) {
return **(**int32)(__ccgo_up(bp))
}
}
/* Assert that the caller has been consistent. If this cursor was opened
** expecting an index b-tree, then the caller should be inserting blob
** keys with no associated data. If the cursor was opened expecting an
** intkey table, the caller should be inserting integer keys with a
** blob of associated data. */
if (*TBtCursor)(unsafe.Pointer(pCur)).FpKeyInfo == uintptr(0) {
/* If this is an insert into a table b-tree, invalidate any incrblob
** cursors open on the row being replaced */
if (*TBtree)(unsafe.Pointer(p)).FhasIncrblobCur != 0 {
_invalidateIncrblobCursors(tls, p, (*TBtCursor)(unsafe.Pointer(pCur)).FpgnoRoot, (*TBtreePayload)(unsafe.Pointer(pX)).FnKey, 0)
}
/* If BTREE_SAVEPOSITION is set, the cursor must already be pointing
** to a row with the same key as the new entry being inserted.
*/
/* On the other hand, BTREE_SAVEPOSITION==0 does not imply
** that the cursor is not pointing to a row to be overwritten.
** So do a complete check.
*/
if libc.Int32FromUint8((*TBtCursor)(unsafe.Pointer(pCur)).FcurFlags)&int32(BTCF_ValidNKey) != 0 && (*TBtreePayload)(unsafe.Pointer(pX)).FnKey == (*TBtCursor)(unsafe.Pointer(pCur)).Finfo.FnKey {
/* The cursor is pointing to the entry that is to be
** overwritten */
if libc.Int32FromUint16((*TBtCursor)(unsafe.Pointer(pCur)).Finfo.FnSize) != 0 && (*TBtCursor)(unsafe.Pointer(pCur)).Finfo.FnPayload == libc.Uint32FromInt32((*TBtreePayload)(unsafe.Pointer(pX)).FnData)+libc.Uint32FromInt32((*TBtreePayload)(unsafe.Pointer(pX)).FnZero) {
/* New entry is the same size as the old. Do an overwrite */
return _btreeOverwriteCell(tls, pCur, pX)
}
} else {
if **(**int32)(__ccgo_up(bp + 4)) == 0 {
/* The cursor is *not* pointing to the cell to be overwritten, nor
** to an adjacent cell. Move the cursor so that it is pointing either
** to the cell to be overwritten or an adjacent cell.
*/
**(**int32)(__ccgo_up(bp)) = _sqlite3BtreeTableMoveto(tls, pCur, (*TBtreePayload)(unsafe.Pointer(pX)).FnKey, libc.BoolInt32(flags&int32(BTREE_APPEND) != 0), bp+4)
if **(**int32)(__ccgo_up(bp)) != 0 {
return **(**int32)(__ccgo_up(bp))
}
}
}
} else {
/* This is an index or a WITHOUT ROWID table */
/* If BTREE_SAVEPOSITION is set, the cursor must already be pointing
** to a row with the same key as the new entry being inserted.
*/
/* If the cursor is not already pointing either to the cell to be
** overwritten, or if a new cell is being inserted, if the cursor is
** not pointing to an immediately adjacent cell, then move the cursor
** so that it does.
*/
if **(**int32)(__ccgo_up(bp + 4)) == 0 && flags&int32(BTREE_SAVEPOSITION) == 0 {
if (*TBtreePayload)(unsafe.Pointer(pX)).FnMem != 0 {
(**(**TUnpackedRecord)(__ccgo_up(bp + 16))).FpKeyInfo = (*TBtCursor)(unsafe.Pointer(pCur)).FpKeyInfo
(**(**TUnpackedRecord)(__ccgo_up(bp + 16))).FaMem = (*TBtreePayload)(unsafe.Pointer(pX)).FaMem
(**(**TUnpackedRecord)(__ccgo_up(bp + 16))).FnField = (*TBtreePayload)(unsafe.Pointer(pX)).FnMem
(**(**TUnpackedRecord)(__ccgo_up(bp + 16))).Fdefault_rc = 0
(**(**TUnpackedRecord)(__ccgo_up(bp + 16))).FeqSeen = uint8(0)
**(**int32)(__ccgo_up(bp)) = _sqlite3BtreeIndexMoveto(tls, pCur, bp+16, bp+4)
} else {
**(**int32)(__ccgo_up(bp)) = _btreeMoveto(tls, pCur, (*TBtreePayload)(unsafe.Pointer(pX)).FpKey, (*TBtreePayload)(unsafe.Pointer(pX)).FnKey, libc.BoolInt32(flags&int32(BTREE_APPEND) != 0), bp+4)
}
if **(**int32)(__ccgo_up(bp)) != 0 {
return **(**int32)(__ccgo_up(bp))
}
}
/* If the cursor is currently pointing to an entry to be overwritten
** and the new content is the same as as the old, then use the
** overwrite optimization.
*/
if **(**int32)(__ccgo_up(bp + 4)) == 0 {
_getCellInfo(tls, pCur)
if (*TBtCursor)(unsafe.Pointer(pCur)).Finfo.FnKey == (*TBtreePayload)(unsafe.Pointer(pX)).FnKey {
(**(**TBtreePayload)(__ccgo_up(bp + 56))).FpData = (*TBtreePayload)(unsafe.Pointer(pX)).FpKey
(**(**TBtreePayload)(__ccgo_up(bp + 56))).FnData = int32((*TBtreePayload)(unsafe.Pointer(pX)).FnKey)
(**(**TBtreePayload)(__ccgo_up(bp + 56))).FnZero = 0
return _btreeOverwriteCell(tls, pCur, bp+56)
}
}
}
pPage = (*TBtCursor)(unsafe.Pointer(pCur)).FpPage
if (*TMemPage)(unsafe.Pointer(pPage)).FnFree < 0 {
if libc.Int32FromUint8((*TBtCursor)(unsafe.Pointer(pCur)).FeState) > int32(CURSOR_INVALID) {
/* ^^^^^--- due to the moveToRoot() call above */
**(**int32)(__ccgo_up(bp)) = _sqlite3CorruptError(tls, int32(82796))
} else {
**(**int32)(__ccgo_up(bp)) = _btreeComputeFreeSpace(tls, pPage)
}
if **(**int32)(__ccgo_up(bp)) != 0 {
return **(**int32)(__ccgo_up(bp))
}
}
newCell = (*TBtShared)(unsafe.Pointer((*TBtree)(unsafe.Pointer(p)).FpBt)).FpTmpSpace
if flags&int32(BTREE_PREFORMAT) != 0 {
**(**int32)(__ccgo_up(bp)) = SQLITE_OK
**(**int32)(__ccgo_up(bp + 8)) = (*TBtShared)(unsafe.Pointer((*TBtree)(unsafe.Pointer(p)).FpBt)).FnPreformatSize
if **(**int32)(__ccgo_up(bp + 8)) < int32(4) {
**(**int32)(__ccgo_up(bp + 8)) = int32(4)
**(**uint8)(__ccgo_up(newCell + 3)) = uint8(0)
}
if (*TBtShared)(unsafe.Pointer((*TBtree)(unsafe.Pointer(p)).FpBt)).FautoVacuum != 0 && **(**int32)(__ccgo_up(bp + 8)) > libc.Int32FromUint16((*TMemPage)(unsafe.Pointer(pPage)).FmaxLocal) {
(*(*func(*libc.TLS, uintptr, uintptr, uintptr))(unsafe.Pointer(&struct{ uintptr }{(*TMemPage)(unsafe.Pointer(pPage)).FxParseCell})))(tls, pPage, newCell, bp+104)
if (**(**TCellInfo)(__ccgo_up(bp + 104))).FnPayload != uint32((**(**TCellInfo)(__ccgo_up(bp + 104))).FnLocal) {
ovfl = _sqlite3Get4byte(tls, newCell+uintptr(**(**int32)(__ccgo_up(bp + 8))-int32(4)))
_ptrmapPut(tls, (*TBtree)(unsafe.Pointer(p)).FpBt, ovfl, uint8(PTRMAP_OVERFLOW1), (*TMemPage)(unsafe.Pointer(pPage)).Fpgno, bp)
if **(**int32)(__ccgo_up(bp)) != 0 {
goto end_insert
}
}
}
} else {
**(**int32)(__ccgo_up(bp)) = _fillInCell(tls, pPage, newCell, pX, bp+8)
if **(**int32)(__ccgo_up(bp)) != 0 {
goto end_insert
}
}
idx = libc.Int32FromUint16((*TBtCursor)(unsafe.Pointer(pCur)).Fix)
(*TBtCursor)(unsafe.Pointer(pCur)).Finfo.FnSize = uint16(0)
if **(**int32)(__ccgo_up(bp + 4)) == 0 {
if idx >= libc.Int32FromUint16((*TMemPage)(unsafe.Pointer(pPage)).FnCell) {
return _sqlite3CorruptError(tls, int32(82838))
}
**(**int32)(__ccgo_up(bp)) = _sqlite3PagerWrite(tls, (*TMemPage)(unsafe.Pointer(pPage)).FpDbPage)
if **(**int32)(__ccgo_up(bp)) != 0 {
goto end_insert
}
oldCell = (*TMemPage)(unsafe.Pointer(pPage)).FaData + uintptr(libc.Int32FromUint16((*TMemPage)(unsafe.Pointer(pPage)).FmaskPage)&(libc.Int32FromUint8(**(**Tu8)(__ccgo_up((*TMemPage)(unsafe.Pointer(pPage)).FaCellIdx + uintptr(int32(2)*idx))))< (*TMemPage)(unsafe.Pointer(pPage)).FaDataEnd {
return _sqlite3CorruptError(tls, int32(82868))
}
libc.X__builtin___memcpy_chk(tls, oldCell, newCell, libc.Uint64FromInt32(**(**int32)(__ccgo_up(bp + 8))), ^t__predefined_size_t(0))
return SQLITE_OK
}
_dropCell(tls, pPage, idx, libc.Int32FromUint16((**(**TCellInfo)(__ccgo_up(bp + 128))).FnSize), bp)
if **(**int32)(__ccgo_up(bp)) != 0 {
goto end_insert
}
} else {
if **(**int32)(__ccgo_up(bp + 4)) < 0 && libc.Int32FromUint16((*TMemPage)(unsafe.Pointer(pPage)).FnCell) > 0 {
v1 = pCur + 86
*(*Tu16)(unsafe.Pointer(v1)) = *(*Tu16)(unsafe.Pointer(v1)) + 1
v2 = *(*Tu16)(unsafe.Pointer(v1))
idx = libc.Int32FromUint16(v2)
v1 = pCur + 1
*(*Tu8)(unsafe.Pointer(v1)) = Tu8(int32(*(*Tu8)(unsafe.Pointer(v1))) & ^(libc.Int32FromInt32(BTCF_ValidNKey) | libc.Int32FromInt32(BTCF_ValidOvfl)))
} else {
}
}
**(**int32)(__ccgo_up(bp)) = _insertCellFast(tls, pPage, idx, newCell, **(**int32)(__ccgo_up(bp + 8)))
/* If no error has occurred and pPage has an overflow cell, call balance()
** to redistribute the cells within the tree. Since balance() may move
** the cursor, zero the BtCursor.info.nSize and BTCF_ValidNKey
** variables.
**
** Previous versions of SQLite called moveToRoot() to move the cursor
** back to the root page as balance() used to invalidate the contents
** of BtCursor.apPage[] and BtCursor.aiIdx[]. Instead of doing that,
** set the cursor state to "invalid". This makes common insert operations
** slightly faster.
**
** There is a subtle but important optimization here too. When inserting
** multiple records into an intkey b-tree using a single cursor (as can
** happen while processing an "INSERT INTO ... SELECT" statement), it
** is advantageous to leave the cursor pointing to the last entry in
** the b-tree if possible. If the cursor is left pointing to the last
** entry in the table, and the next row inserted has an integer key
** larger than the largest existing key, it is possible to insert the
** row without seeking the cursor. This can be a big performance boost.
*/
if (*TMemPage)(unsafe.Pointer(pPage)).FnOverflow != 0 {
v1 = pCur + 1
*(*Tu8)(unsafe.Pointer(v1)) = Tu8(int32(*(*Tu8)(unsafe.Pointer(v1))) & ^(libc.Int32FromInt32(BTCF_ValidNKey) | libc.Int32FromInt32(BTCF_ValidOvfl)))
**(**int32)(__ccgo_up(bp)) = _balance(tls, pCur)
/* Must make sure nOverflow is reset to zero even if the balance()
** fails. Internal data structure corruption will result otherwise.
** Also, set the cursor state to invalid. This stops saveCursorPosition()
** from trying to save the current position of the cursor. */
(*TMemPage)(unsafe.Pointer((*TBtCursor)(unsafe.Pointer(pCur)).FpPage)).FnOverflow = uint8(0)
(*TBtCursor)(unsafe.Pointer(pCur)).FeState = uint8(CURSOR_INVALID)
if flags&int32(BTREE_SAVEPOSITION) != 0 && **(**int32)(__ccgo_up(bp)) == SQLITE_OK {
_btreeReleaseAllCursorPages(tls, pCur)
if (*TBtCursor)(unsafe.Pointer(pCur)).FpKeyInfo != 0 {
(*TBtCursor)(unsafe.Pointer(pCur)).FpKey = _sqlite3Malloc(tls, libc.Uint64FromInt64((*TBtreePayload)(unsafe.Pointer(pX)).FnKey))
if (*TBtCursor)(unsafe.Pointer(pCur)).FpKey == uintptr(0) {
**(**int32)(__ccgo_up(bp)) = int32(SQLITE_NOMEM)
} else {
libc.X__builtin___memcpy_chk(tls, (*TBtCursor)(unsafe.Pointer(pCur)).FpKey, (*TBtreePayload)(unsafe.Pointer(pX)).FpKey, libc.Uint64FromInt64((*TBtreePayload)(unsafe.Pointer(pX)).FnKey), ^t__predefined_size_t(0))
}
}
(*TBtCursor)(unsafe.Pointer(pCur)).FeState = uint8(CURSOR_REQUIRESEEK)
(*TBtCursor)(unsafe.Pointer(pCur)).FnKey = (*TBtreePayload)(unsafe.Pointer(pX)).FnKey
}
}
goto end_insert
end_insert:
;
return **(**int32)(__ccgo_up(bp))
return r
}
// 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(272)
defer tls.Free(272)
var bCkFreelist, bPartial int32
var i, mx, mxInHdr TPgno
var pBt uintptr
var savedDbFlags Tu64
var _ /* notUsed at bp+232 */ Ti64
var _ /* sCheck at bp+0 */ TIntegrityCk
var _ /* zErr at bp+128 */ [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.X__builtin___memset_chk(tls, bp, 0, uint64(128), ^t__predefined_size_t(0))
(**(**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+72, uintptr(0), bp+128, 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 + 5310
_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+5321, libc.VaList(bp+248, mx, mxInHdr))
}
} else {
if _sqlite3Get4byte(tls, (*TMemPage)(unsafe.Pointer((*TBtShared)(unsafe.Pointer(pBt)).FpPage1)).FaData+64) != uint32(0) {
_checkAppendMsg(tls, bp, __ccgo_ts+5366, 0)
}
}
}
**(**Tu64)(__ccgo_up((*TBtShared)(unsafe.Pointer(pBt)).Fdb + 48)) &= ^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+232, libc.Int64FromUint32(0xffffffff)|libc.Int64FromInt32(0x7fffffff)< 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.X__builtin___memcpy_chk(tls, zFullPathname, zFilename, libc.Uint64FromInt32(nFilename), ^t__predefined_size_t(0))
} else {
rc = _sqlite3OsFullPathname(tls, pVfs, zFilename, nFullPathname, zFullPathname)
if rc != 0 {
if rc == libc.Int32FromInt32(SQLITE_OK)|libc.Int32FromInt32(2)<= 0) {
break
}
pExisting = (**(**TDb)(__ccgo_up((*Tsqlite3)(unsafe.Pointer(db)).FaDb + uintptr(iDb)*32))).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.X__builtin___memset_chk(tls, bp+16, 0, uint64(8), ^t__predefined_size_t(0))
pBt = _sqlite3MallocZero(tls, uint64(152))
if pBt == uintptr(0) {
rc = int32(SQLITE_NOMEM)
goto btree_open_out
}
rc = _sqlite3PagerOpen(tls, pVfs, pBt, zFilename, int32(136), 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 + 40
*(*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)])< 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 + 40
*(*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+52, 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)*32))).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 uint64((*TBtree)(unsafe.Pointer(p)).FpBt) < uint64((*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 && uint64((*TBtree)(unsafe.Pointer((*TBtree)(unsafe.Pointer(pSib)).FpNext)).FpBt) < uint64((*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+8)
}
}
if mutexOpen != 0 {
Xsqlite3_mutex_leave(tls, mutexOpen)
}
return rc
}
// C documentation
//
// /*
// ** This function is used as part of copying the current row from cursor
// ** pSrc into cursor pDest. If the cursors are open on intkey tables, then
// ** parameter iKey is used as the rowid value when the record is copied
// ** into pDest. Otherwise, the record is copied verbatim.
// **
// ** This function does not actually write the new value to cursor pDest.
// ** Instead, it creates and populates any required overflow pages and
// ** writes the data for the new cell into the BtShared.pTmpSpace buffer
// ** for the destination database. The size of the cell, in bytes, is left
// ** in BtShared.nPreformatSize. The caller completes the insertion by
// ** calling sqlite3BtreeInsert() with the BTREE_PREFORMAT flag specified.
// **
// ** SQLITE_OK is returned if successful, or an SQLite error code otherwise.
// */
func _sqlite3BtreeTransferRow(tls *libc.TLS, pDest uintptr, pSrc uintptr, iKey Ti64) (r int32) {
bp := tls.Alloc(32)
defer tls.Free(32)
var aIn, aOut, pBt, pPageOut, pPgnoOut, pSrcPager, v1 uintptr
var nCopy int32
var nIn, nOut, nRem Tu32
var ovflIn TPgno
var v2 uint32
var _ /* pNew at bp+24 */ uintptr
var _ /* pPageIn at bp+8 */ uintptr
var _ /* pgnoNew at bp+16 */ TPgno
var _ /* rc at bp+0 */ int32
_, _, _, _, _, _, _, _, _, _, _, _, _ = aIn, aOut, nCopy, nIn, nOut, nRem, ovflIn, pBt, pPageOut, pPgnoOut, pSrcPager, v1, v2
pBt = (*TBtCursor)(unsafe.Pointer(pDest)).FpBt
aOut = (*TBtShared)(unsafe.Pointer(pBt)).FpTmpSpace /* Bytes of data still to copy */
_getCellInfo(tls, pSrc)
if (*TBtCursor)(unsafe.Pointer(pSrc)).Finfo.FnPayload < uint32(0x80) {
v1 = aOut
aOut = aOut + 1
**(**Tu8)(__ccgo_up(v1)) = uint8((*TBtCursor)(unsafe.Pointer(pSrc)).Finfo.FnPayload)
} else {
aOut = aOut + uintptr(_sqlite3PutVarint(tls, aOut, uint64((*TBtCursor)(unsafe.Pointer(pSrc)).Finfo.FnPayload)))
}
if (*TBtCursor)(unsafe.Pointer(pDest)).FpKeyInfo == uintptr(0) {
aOut = aOut + uintptr(_sqlite3PutVarint(tls, aOut, libc.Uint64FromInt64(iKey)))
}
nIn = uint32((*TBtCursor)(unsafe.Pointer(pSrc)).Finfo.FnLocal)
aIn = (*TBtCursor)(unsafe.Pointer(pSrc)).Finfo.FpPayload
if aIn+uintptr(nIn) > (*TMemPage)(unsafe.Pointer((*TBtCursor)(unsafe.Pointer(pSrc)).FpPage)).FaDataEnd {
return _sqlite3CorruptError(tls, int32(82970))
}
nRem = (*TBtCursor)(unsafe.Pointer(pSrc)).Finfo.FnPayload
if nIn == nRem && nIn < uint32((*TMemPage)(unsafe.Pointer((*TBtCursor)(unsafe.Pointer(pDest)).FpPage)).FmaxLocal) {
libc.X__builtin___memcpy_chk(tls, aOut, aIn, uint64(nIn), ^t__predefined_size_t(0))
(*TBtShared)(unsafe.Pointer(pBt)).FnPreformatSize = libc.Int32FromUint32(nIn + libc.Uint32FromInt32(int32(int64(aOut)-int64((*TBtShared)(unsafe.Pointer(pBt)).FpTmpSpace))))
return SQLITE_OK
} else {
**(**int32)(__ccgo_up(bp)) = SQLITE_OK
pSrcPager = (*TBtShared)(unsafe.Pointer((*TBtCursor)(unsafe.Pointer(pSrc)).FpBt)).FpPager
pPgnoOut = uintptr(0)
ovflIn = uint32(0)
**(**uintptr)(__ccgo_up(bp + 8)) = uintptr(0)
pPageOut = uintptr(0) /* Size of output buffer aOut[] */
nOut = libc.Uint32FromInt32(_btreePayloadToLocal(tls, (*TBtCursor)(unsafe.Pointer(pDest)).FpPage, libc.Int64FromUint32((*TBtCursor)(unsafe.Pointer(pSrc)).Finfo.FnPayload)))
(*TBtShared)(unsafe.Pointer(pBt)).FnPreformatSize = libc.Int32FromUint32(nOut) + int32(int64(aOut)-int64((*TBtShared)(unsafe.Pointer(pBt)).FpTmpSpace))
if nOut < (*TBtCursor)(unsafe.Pointer(pSrc)).Finfo.FnPayload {
pPgnoOut = aOut + uintptr(nOut)
**(**int32)(__ccgo_up(pBt + 144)) += int32(4)
}
if nRem > nIn {
if aIn+uintptr(nIn)+uintptr(4) > (*TMemPage)(unsafe.Pointer((*TBtCursor)(unsafe.Pointer(pSrc)).FpPage)).FaDataEnd {
return _sqlite3CorruptError(tls, int32(82995))
}
ovflIn = _sqlite3Get4byte(tls, (*TBtCursor)(unsafe.Pointer(pSrc)).Finfo.FpPayload+uintptr(nIn))
}
for cond := true; cond; cond = nRem > uint32(0) && **(**int32)(__ccgo_up(bp)) == SQLITE_OK {
nRem = nRem - nOut
for cond := true; cond; cond = **(**int32)(__ccgo_up(bp)) == SQLITE_OK && nOut > uint32(0) {
if nIn > uint32(0) {
if nOut < nIn {
v2 = nOut
} else {
v2 = nIn
}
nCopy = libc.Int32FromUint32(v2)
libc.X__builtin___memcpy_chk(tls, aOut, aIn, libc.Uint64FromInt32(nCopy), ^t__predefined_size_t(0))
nOut = nOut - libc.Uint32FromInt32(nCopy)
nIn = nIn - libc.Uint32FromInt32(nCopy)
aOut = aOut + uintptr(nCopy)
aIn = aIn + uintptr(nCopy)
}
if nOut > uint32(0) {
_sqlite3PagerUnref(tls, **(**uintptr)(__ccgo_up(bp + 8)))
**(**uintptr)(__ccgo_up(bp + 8)) = uintptr(0)
**(**int32)(__ccgo_up(bp)) = _sqlite3PagerGet(tls, pSrcPager, ovflIn, bp+8, int32(PAGER_GET_READONLY))
if **(**int32)(__ccgo_up(bp)) == SQLITE_OK {
aIn = _sqlite3PagerGetData(tls, **(**uintptr)(__ccgo_up(bp + 8)))
ovflIn = _sqlite3Get4byte(tls, aIn)
aIn = aIn + uintptr(4)
nIn = (*TBtShared)(unsafe.Pointer((*TBtCursor)(unsafe.Pointer(pSrc)).FpBt)).FusableSize - uint32(4)
}
}
}
if **(**int32)(__ccgo_up(bp)) == SQLITE_OK && nRem > uint32(0) && pPgnoOut != 0 {
**(**TPgno)(__ccgo_up(bp + 16)) = uint32(0) /* Prevent harmless static-analyzer warning */
**(**uintptr)(__ccgo_up(bp + 24)) = uintptr(0)
**(**int32)(__ccgo_up(bp)) = _allocateBtreePage(tls, pBt, bp+24, bp+16, uint32(0), uint8(0))
_sqlite3Put4byte(tls, pPgnoOut, **(**TPgno)(__ccgo_up(bp + 16)))
if (*TBtShared)(unsafe.Pointer(pBt)).FautoVacuum != 0 && pPageOut != 0 {
_ptrmapPut(tls, pBt, **(**TPgno)(__ccgo_up(bp + 16)), uint8(PTRMAP_OVERFLOW2), (*TMemPage)(unsafe.Pointer(pPageOut)).Fpgno, bp)
}
_releasePage(tls, pPageOut)
pPageOut = **(**uintptr)(__ccgo_up(bp + 24))
if pPageOut != 0 {
pPgnoOut = (*TMemPage)(unsafe.Pointer(pPageOut)).FaData
_sqlite3Put4byte(tls, pPgnoOut, uint32(0))
aOut = pPgnoOut + 4
if (*TBtShared)(unsafe.Pointer(pBt)).FusableSize-uint32(4) < nRem {
v2 = (*TBtShared)(unsafe.Pointer(pBt)).FusableSize - uint32(4)
} else {
v2 = nRem
}
nOut = v2
}
}
}
_releasePage(tls, pPageOut)
_sqlite3PagerUnref(tls, **(**uintptr)(__ccgo_up(bp + 8)))
return **(**int32)(__ccgo_up(bp))
}
return r
}
func _sqlite3CantopenError(tls *libc.TLS, lineno int32) (r int32) {
return _sqlite3ReportError(tls, int32(SQLITE_CANTOPEN), lineno, __ccgo_ts+26714)
}
// C documentation
//
// /*
// ** This routine is used to check if the UTF-8 string zName is a legal
// ** unqualified name for a new schema object (table, index, view or
// ** trigger). All names are legal except those that begin with the string
// ** "sqlite_" (in upper, lower or mixed case). This portion of the namespace
// ** is reserved for internal use.
// **
// ** When parsing the sqlite_schema table, this routine also checks to
// ** make sure the "type", "name", and "tbl_name" columns are consistent
// ** with the SQL.
// */
func _sqlite3CheckObjectName(tls *libc.TLS, pParse uintptr, zName uintptr, zType uintptr, zTblName uintptr) (r int32) {
bp := tls.Alloc(16)
defer tls.Free(16)
var db uintptr
_ = db
db = (*TParse)(unsafe.Pointer(pParse)).Fdb
if _sqlite3WritableSchema(tls, db) != 0 || int32(uint32(*(*uint8)(unsafe.Pointer(db + 192 + 8))&0x6>>1)) != 0 || !(_sqlite3Config.FbExtraSchemaChecks != 0) {
/* Skip these error checks for writable_schema=ON */
return SQLITE_OK
}
if (*Tsqlite3)(unsafe.Pointer(db)).Finit1.Fbusy != 0 {
if Xsqlite3_stricmp(tls, zType, **(**uintptr)(__ccgo_up((*Tsqlite3)(unsafe.Pointer(db)).Finit1.FazInit))) != 0 || Xsqlite3_stricmp(tls, zName, **(**uintptr)(__ccgo_up((*Tsqlite3)(unsafe.Pointer(db)).Finit1.FazInit + 1*8))) != 0 || Xsqlite3_stricmp(tls, zTblName, **(**uintptr)(__ccgo_up((*Tsqlite3)(unsafe.Pointer(db)).Finit1.FazInit + 2*8))) != 0 {
_sqlite3ErrorMsg(tls, pParse, __ccgo_ts+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+7104, int32(7)) || _sqlite3ReadOnlyShadowTables(tls, db) != 0 && _sqlite3ShadowTableName(tls, db, zName) != 0 {
_sqlite3ErrorMsg(tls, pParse, __ccgo_ts+14111, 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)*32))).FzDbSName
i = int32(1)
for {
if !(i <= int32(4)) {
break
}
Xsqlite3_snprintf(tls, int32(24), bp, __ccgo_ts+15299, libc.VaList(bp+32, i))
if _sqlite3FindTable(tls, (*TParse)(unsafe.Pointer(pParse)).Fdb, bp, zDbName) != 0 {
_sqlite3NestedParse(tls, pParse, __ccgo_ts+13284, libc.VaList(bp+32, zDbName, bp, zType, zName))
}
goto _1
_1:
;
i = i + 1
}
}
// C documentation
//
// /*
// ** Close an existing SQLite database
// */
func _sqlite3Close(tls *libc.TLS, db uintptr, forceZombie int32) (r int32) {
var p uintptr
_ = p
if !(db != 0) {
/* EVIDENCE-OF: R-63257-11740 Calling sqlite3_close() or
** sqlite3_close_v2() with a NULL pointer argument is a harmless no-op. */
return SQLITE_OK
}
if !(_sqlite3SafetyCheckSickOrOk(tls, db) != 0) {
return _sqlite3MisuseError(tls, int32(188636))
}
Xsqlite3_mutex_enter(tls, (*Tsqlite3)(unsafe.Pointer(db)).Fmutex)
if libc.Int32FromUint8((*Tsqlite3)(unsafe.Pointer(db)).FmTrace)&int32(SQLITE_TRACE_CLOSE) != 0 {
(*(*func(*libc.TLS, Tu32, uintptr, uintptr, uintptr) int32)(unsafe.Pointer(&struct{ uintptr }{*(*uintptr)(unsafe.Pointer(&(*Tsqlite3)(unsafe.Pointer(db)).Ftrace))})))(tls, uint32(SQLITE_TRACE_CLOSE), (*Tsqlite3)(unsafe.Pointer(db)).FpTraceArg, db, uintptr(0))
}
/* Force xDisconnect calls on all virtual tables */
_disconnectAllVtab(tls, db)
/* If a transaction is open, the disconnectAllVtab() call above
** will not have called the xDisconnect() method on any virtual
** tables in the db->aVTrans[] array. The following sqlite3VtabRollback()
** call will do so. We need to do this before the check for active
** SQL statements below, as the v-table implementation may be storing
** some prepared statements internally.
*/
_sqlite3VtabRollback(tls, db)
/* Legacy behavior (sqlite3_close() behavior) is to return
** SQLITE_BUSY if the connection can not be closed immediately.
*/
if !(forceZombie != 0) && _connectionIsBusy(tls, db) != 0 {
_sqlite3ErrorWithMsg(tls, db, int32(SQLITE_BUSY), __ccgo_ts+25682, 0)
Xsqlite3_mutex_leave(tls, (*Tsqlite3)(unsafe.Pointer(db)).Fmutex)
return int32(SQLITE_BUSY)
}
for (*Tsqlite3)(unsafe.Pointer(db)).FpDbData != 0 {
p = (*Tsqlite3)(unsafe.Pointer(db)).FpDbData
(*Tsqlite3)(unsafe.Pointer(db)).FpDbData = (*TDbClientData)(unsafe.Pointer(p)).FpNext
if (*TDbClientData)(unsafe.Pointer(p)).FxDestructor != 0 {
(*(*func(*libc.TLS, uintptr))(unsafe.Pointer(&struct{ uintptr }{(*TDbClientData)(unsafe.Pointer(p)).FxDestructor})))(tls, (*TDbClientData)(unsafe.Pointer(p)).FpData)
}
Xsqlite3_free(tls, p)
}
/* Convert the connection into a zombie and then close it.
*/
(*Tsqlite3)(unsafe.Pointer(db)).FeOpenState = uint8(SQLITE_STATE_ZOMBIE)
_sqlite3LeaveMutexAndCloseZombie(tls, db)
return SQLITE_OK
}
// C documentation
//
// /*
// ** Generate code to drop a table.
// */
func _sqlite3CodeDropTable(tls *libc.TLS, pParse uintptr, pTab uintptr, iDb int32, isView int32) {
bp := tls.Alloc(32)
defer tls.Free(32)
var db, pDb, pTrigger, v uintptr
_, _, _, _ = db, pDb, pTrigger, v
db = (*TParse)(unsafe.Pointer(pParse)).Fdb
pDb = (*Tsqlite3)(unsafe.Pointer(db)).FaDb + uintptr(iDb)*32
v = _sqlite3GetVdbe(tls, pParse)
_sqlite3BeginWriteOperation(tls, pParse, int32(1), iDb)
if libc.Int32FromUint8((*TTable)(unsafe.Pointer(pTab)).FeTabType) == int32(TABTYP_VTAB) {
_sqlite3VdbeAddOp0(tls, v, int32(OP_VBegin))
}
/* Drop all triggers associated with the table being dropped. Code
** is generated to remove entries from sqlite_schema and/or
** sqlite_temp_schema if required.
*/
pTrigger = _sqlite3TriggerList(tls, pParse, pTab)
for pTrigger != 0 {
_sqlite3DropTriggerPtr(tls, pParse, pTrigger)
pTrigger = (*TTrigger)(unsafe.Pointer(pTrigger)).FpNext
}
/* Remove any entries of the sqlite_sequence table associated with
** the table being dropped. This is done before the table is dropped
** at the btree level, in case the sqlite_sequence table needs to
** move as a result of the drop (can happen in auto-vacuum mode).
*/
if (*TTable)(unsafe.Pointer(pTab)).FtabFlags&uint32(TF_Autoincrement) != 0 {
_sqlite3NestedParse(tls, pParse, __ccgo_ts+15313, libc.VaList(bp+8, (*TDb)(unsafe.Pointer(pDb)).FzDbSName, (*TTable)(unsafe.Pointer(pTab)).FzName))
}
/* Drop all entries in the schema table that refer to the
** table. The program name loops through the schema table and deletes
** every row that refers to a table of the same name as the one being
** dropped. Triggers are handled separately because a trigger can be
** created in the temp database that refers to a table in another
** database.
*/
_sqlite3NestedParse(tls, pParse, __ccgo_ts+15358, libc.VaList(bp+8, (*TDb)(unsafe.Pointer(pDb)).FzDbSName, (*TTable)(unsafe.Pointer(pTab)).FzName))
if !(isView != 0) && !(libc.Int32FromUint8((*TTable)(unsafe.Pointer(pTab)).FeTabType) == libc.Int32FromInt32(TABTYP_VTAB)) {
_destroyTable(tls, pParse, pTab)
}
/* Remove the table entry from SQLite's internal schema and modify
** the schema cookie.
*/
if libc.Int32FromUint8((*TTable)(unsafe.Pointer(pTab)).FeTabType) == int32(TABTYP_VTAB) {
_sqlite3VdbeAddOp4(tls, v, int32(OP_VDestroy), iDb, 0, 0, (*TTable)(unsafe.Pointer(pTab)).FzName, 0)
_sqlite3MayAbort(tls, pParse)
}
_sqlite3VdbeAddOp4(tls, v, int32(OP_DropTable), iDb, 0, 0, (*TTable)(unsafe.Pointer(pTab)).FzName, 0)
_sqlite3ChangeCookie(tls, pParse, iDb)
_sqliteViewResetAll(tls, db, iDb)
}
// 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(80)
defer tls.Free(80)
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+40 */ 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 + 32)))).FselFlags&uint32(SF_All) == uint32(0) {
pSig = _sqlite3DbMallocRawNN(tls, (*TParse)(unsafe.Pointer(pParse)).Fdb, uint64(32))
if pSig != 0 {
(*TSubrtnSig)(unsafe.Pointer(pSig)).FselId = libc.Int32FromUint32((*TSelect)(unsafe.Pointer(*(*uintptr)(unsafe.Pointer(pExpr + 32)))).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+8677, libc.VaList(bp+56, (*TSelect)(unsafe.Pointer(*(*uintptr)(unsafe.Pointer(pExpr + 32)))).FselId))
}
_sqlite3VdbeAddOp2(tls, v, int32(OP_Gosub), (*(*struct {
FiAddr int32
FregReturn int32
})(unsafe.Pointer(pExpr + 64))).FregReturn, (*(*struct {
FiAddr int32
FregReturn int32
})(unsafe.Pointer(pExpr + 64))).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 + 60
*(*int32)(unsafe.Pointer(v2)) = *(*int32)(unsafe.Pointer(v2)) + 1
v1 = *(*int32)(unsafe.Pointer(v2))
(*(*struct {
FiAddr int32
FregReturn int32
})(unsafe.Pointer(pExpr + 64))).FregReturn = v1
(*(*struct {
FiAddr int32
FregReturn int32
})(unsafe.Pointer(pExpr + 64))).FiAddr = _sqlite3VdbeAddOp2(tls, v, int32(OP_BeginSubrtn), 0, (*(*struct {
FiAddr int32
FregReturn int32
})(unsafe.Pointer(pExpr + 64))).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 + 64))).FiAddr
(*TSubrtnSig)(unsafe.Pointer(pSig)).FregReturn = (*(*struct {
FiAddr int32
FregReturn int32
})(unsafe.Pointer(pExpr + 64))).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 + 32))
pEList = (*TSelect)(unsafe.Pointer(pSelect)).FpEList
if addrOnce != 0 {
v2 = __ccgo_ts + 1702
} else {
v2 = __ccgo_ts + 8700
}
_sqlite3VdbeExplain(tls, pParse, uint8(1), __ccgo_ts+8712, libc.VaList(bp+56, 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 + 60
*(*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 + 32 + uintptr(i)*8)) = _sqlite3BinaryCompareCollSeq(tls, pParse, p, (*(*TExprList_item)(unsafe.Pointer(pEList + 8 + uintptr(i)*32))).FpExpr)
goto _7
_7:
;
i = i + 1
}
}
} else {
if *(*uintptr)(unsafe.Pointer(pExpr + 32)) != uintptr(0) {
pList = *(*uintptr)(unsafe.Pointer(pExpr + 32))
**(**int8)(__ccgo_up(bp + 40)) = _sqlite3ExprAffinity(tls, pLeft)
if int32(**(**int8)(__ccgo_up(bp + 40))) <= int32(SQLITE_AFF_NONE) {
**(**int8)(__ccgo_up(bp + 40)) = int8(SQLITE_AFF_BLOB)
} else {
if int32(**(**int8)(__ccgo_up(bp + 40))) == int32(SQLITE_AFF_REAL) {
**(**int8)(__ccgo_up(bp + 40)) = int8(SQLITE_AFF_NUMERIC)
}
}
if pKeyInfo != 0 {
*(*uintptr)(unsafe.Pointer(pKeyInfo + 32)) = _sqlite3ExprCollSeq(tls, pParse, (*TExpr)(unsafe.Pointer(pExpr)).FpLeft)
}
/* Loop through each expression in . */
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+40, int32(1))
_sqlite3VdbeAddOp4Int(tls, v, int32(OP_IdxInsert), iTab, r2, r1, int32(1))
goto _8
_8:
;
i1 = i1 - 1
pItem += 32
}
_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 + 64))).FregReturn, (*(*struct {
FiAddr int32
FregReturn int32
})(unsafe.Pointer(pExpr + 64))).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 + 32))
/* 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+8731, libc.VaList(bp+48, (*TSelect)(unsafe.Pointer(pSel)).FselId))
_sqlite3VdbeAddOp2(tls, v, int32(OP_Gosub), (*(*struct {
FiAddr int32
FregReturn int32
})(unsafe.Pointer(pExpr + 64))).FregReturn, (*(*struct {
FiAddr int32
FregReturn int32
})(unsafe.Pointer(pExpr + 64))).FiAddr)
return (*TExpr)(unsafe.Pointer(pExpr)).FiTable
}
/* Begin coding the subroutine */
**(**Tu32)(__ccgo_up(pExpr + 4)) |= libc.Uint32FromInt32(libc.Int32FromInt32(EP_Subrtn))
v2 = pParse + 60
*(*int32)(unsafe.Pointer(v2)) = *(*int32)(unsafe.Pointer(v2)) + 1
v1 = *(*int32)(unsafe.Pointer(v2))
(*(*struct {
FiAddr int32
FregReturn int32
})(unsafe.Pointer(pExpr + 64))).FregReturn = v1
(*(*struct {
FiAddr int32
FregReturn int32
})(unsafe.Pointer(pExpr + 64))).FiAddr = _sqlite3VdbeAddOp2(tls, v, int32(OP_BeginSubrtn), 0, (*(*struct {
FiAddr int32
FregReturn int32
})(unsafe.Pointer(pExpr + 64))).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 + 8700
}
_sqlite3VdbeExplain(tls, pParse, uint8(1), __ccgo_ts+8749, libc.VaList(bp+48, 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 + 60)) += 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 + 60)) += 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(&(*TExpr)(unsafe.Pointer(pLeft)).Fu)) != int32(1) && *(*int32)(unsafe.Pointer(&(*TExpr)(unsafe.Pointer(pLeft)).Fu)) != 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 + 64))).FregReturn, (*(*struct {
FiAddr int32
FregReturn int32
})(unsafe.Pointer(pExpr + 64))).FiAddr, int32(1))
_sqlite3ClearTempRegCache(tls, pParse)
return rReg
}
// C documentation
//
// /*
// ** Look through the list of open database files in db->aDb[] and if
// ** any have been closed, remove them from the list. Reallocate the
// ** db->aDb[] structure to a smaller size, if possible.
// **
// ** Entry 0 (the "main" database) and entry 1 (the "temp" database)
// ** are never candidates for being collapsed.
// */
func _sqlite3CollapseDatabaseArray(tls *libc.TLS, db uintptr) {
var i, j, v2 int32
var pDb uintptr
_, _, _, _ = i, j, pDb, v2
v2 = libc.Int32FromInt32(2)
j = v2
i = v2
for {
if !(i < (*Tsqlite3)(unsafe.Pointer(db)).FnDb) {
break
}
pDb = (*Tsqlite3)(unsafe.Pointer(db)).FaDb + uintptr(i)*32
if (*TDb)(unsafe.Pointer(pDb)).FpBt == uintptr(0) {
_sqlite3DbFree(tls, db, (*TDb)(unsafe.Pointer(pDb)).FzDbSName)
(*TDb)(unsafe.Pointer(pDb)).FzDbSName = uintptr(0)
goto _1
}
if j < i {
**(**TDb)(__ccgo_up((*Tsqlite3)(unsafe.Pointer(db)).FaDb + uintptr(j)*32)) = **(**TDb)(__ccgo_up((*Tsqlite3)(unsafe.Pointer(db)).FaDb + uintptr(i)*32))
}
j = j + 1
goto _1
_1:
;
i = i + 1
}
(*Tsqlite3)(unsafe.Pointer(db)).FnDb = j
if (*Tsqlite3)(unsafe.Pointer(db)).FnDb <= int32(2) && (*Tsqlite3)(unsafe.Pointer(db)).FaDb != db+696 {
libc.X__builtin___memcpy_chk(tls, db+696, (*Tsqlite3)(unsafe.Pointer(db)).FaDb, libc.Uint64FromInt32(2)*libc.Uint64FromInt64(32), ^t__predefined_size_t(0))
_sqlite3DbFree(tls, db, (*Tsqlite3)(unsafe.Pointer(db)).FaDb)
(*Tsqlite3)(unsafe.Pointer(db)).FaDb = db + 696
}
}
// C documentation
//
// /*
// ** Set the collating sequence name for a column.
// */
func _sqlite3ColumnSetColl(tls *libc.TLS, db uintptr, pCol uintptr, zColl uintptr) {
var n, nColl Ti64
var zNew, v1 uintptr
_, _, _, _ = n, nColl, zNew, v1
n = int64(_sqlite3Strlen30(tls, (*TColumn)(unsafe.Pointer(pCol)).FzCnName) + int32(1))
if libc.Int32FromUint16((*TColumn)(unsafe.Pointer(pCol)).FcolFlags)&int32(COLFLAG_HASTYPE) != 0 {
n = n + int64(_sqlite3Strlen30(tls, (*TColumn)(unsafe.Pointer(pCol)).FzCnName+uintptr(n))+int32(1))
}
nColl = int64(_sqlite3Strlen30(tls, zColl) + int32(1))
zNew = _sqlite3DbRealloc(tls, db, (*TColumn)(unsafe.Pointer(pCol)).FzCnName, libc.Uint64FromInt64(nColl+n))
if zNew != 0 {
(*TColumn)(unsafe.Pointer(pCol)).FzCnName = zNew
libc.X__builtin___memcpy_chk(tls, (*TColumn)(unsafe.Pointer(pCol)).FzCnName+uintptr(n), zColl, libc.Uint64FromInt64(nColl), ^t__predefined_size_t(0))
v1 = pCol + 14
*(*Tu16)(unsafe.Pointer(v1)) = Tu16(int32(*(*Tu16)(unsafe.Pointer(v1))) | libc.Int32FromInt32(COLFLAG_HASCOLL))
}
}
// 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+8 */ 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+8)
if pEList != 0 {
nCol = (*TExprList)(unsafe.Pointer(pEList)).FnExpr
aCol = _sqlite3DbMallocZero(tls, db, uint64(uint64(16)*libc.Uint64FromInt32(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)*32
/* 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 + 16 + 4))&0x3>>0)) == ENAME_NAME {
/* If the column contains an "AS " phrase, use 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) && *(*uintptr)(unsafe.Pointer(pColExpr + 64)) != uintptr(0) {
/* For columns use the column name name */
iCol = int32((*TExpr)(unsafe.Pointer(pColExpr)).FiColumn)
pTab = *(*uintptr)(unsafe.Pointer(pColExpr + 64))
if iCol < 0 {
iCol = int32((*TTable)(unsafe.Pointer(pTab)).FiPKey)
}
if iCol >= 0 {
v2 = (**(**TColumn)(__ccgo_up((*TTable)(unsafe.Pointer(pTab)).FaCol + uintptr(iCol)*16))).FzCnName
} else {
v2 = __ccgo_ts + 18314
}
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+21029, libc.VaList(bp+40, 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+8, zName)
pCollide = v2
}
if !(v5 && v2 != uintptr(0)) {
break
}
if int32(uint32(*(*uint16)(unsafe.Pointer(pCollide + 16 + 4))&0x80>>7)) != 0 {
v3 = pCol + 14
*(*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+21038, libc.VaList(bp+40, 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 + 16 + 4))&0x100>>8)) != 0 {
v2 = pCol + 14
*(*Tu16)(unsafe.Pointer(v2)) = Tu16(int32(*(*Tu16)(unsafe.Pointer(v2))) | libc.Int32FromInt32(COLFLAG_NOEXPAND))
}
if zName != 0 && _sqlite3HashInsert(tls, bp+8, zName, pX) == pX {
_sqlite3OomFault(tls, db)
}
goto _1
_1:
;
i = i + 1
pCol += 16
}
_sqlite3HashClear(tls, bp+8)
if (*TParse)(unsafe.Pointer(pParse)).FnErr != 0 {
j = 0
for {
if !(j < i) {
break
}
_sqlite3DbFree(tls, db, (**(**TColumn)(__ccgo_up(aCol + uintptr(j)*16))).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(64)
defer tls.Free(64)
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)*16))).FcolFlags)&int32(COLFLAG_VIRTUAL) != 0 {
goto _1
}
if libc.Int32FromUint16((**(**TColumn)(__ccgo_up((*TTable)(unsafe.Pointer(pTab)).FaCol + uintptr(ii)*16))).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)*16))).FcolFlags)&int32(COLFLAG_GENERATED) != 0 {
v4 = (*TTable)(unsafe.Pointer(pTab)).FaCol + uintptr(i)*16 + 14
*(*Tu16)(unsafe.Pointer(v4)) = Tu16(int32(*(*Tu16)(unsafe.Pointer(v4))) | libc.Int32FromInt32(COLFLAG_NOTAVAIL))
}
goto _3
_3:
;
i = i + 1
}
*(*uintptr)(unsafe.Pointer(bp + 40)) = 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)*16
if libc.Int32FromUint16((*TColumn)(unsafe.Pointer(pCol)).FcolFlags)&int32(COLFLAG_NOTAVAIL) != 0 {
v4 = pCol + 14
*(*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 + 14
*(*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 + 14
*(*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+8800, libc.VaList(bp+56, (*TColumn)(unsafe.Pointer(pRedo)).FzCnName))
}
(*TParse)(unsafe.Pointer(pParse)).FiSelfTab = 0
}
// C documentation
//
// /*
// ** This function is called when
// ** the transaction opened by database db has just finished. Locks held
// ** by database connection db have been released.
// **
// ** This function loops through each entry in the blocked connections
// ** list and does the following:
// **
// ** 1) If the sqlite3.pBlockingConnection member of a list entry is
// ** set to db, then set pBlockingConnection=0.
// **
// ** 2) If the sqlite3.pUnlockConnection member of a list entry is
// ** set to db, then invoke the configured unlock-notify callback and
// ** set pUnlockConnection=0.
// **
// ** 3) If the two steps above mean that pBlockingConnection==0 and
// ** pUnlockConnection==0, remove the entry from the blocked connections
// ** list.
// */
func _sqlite3ConnectionUnlocked(tls *libc.TLS, db uintptr) {
bp := tls.Alloc(128)
defer tls.Free(128)
var aArg, aDyn, p, pNew, pp, xUnlockNotify, v2 uintptr
var nArg, v3 int32
var _ /* aStatic at bp+0 */ [16]uintptr
_, _, _, _, _, _, _, _, _ = aArg, aDyn, nArg, p, pNew, pp, xUnlockNotify, v2, v3
xUnlockNotify = uintptr(0) /* Unlock-notify cb to invoke */
nArg = 0 /* Arguments to the unlock callback */
aDyn = uintptr(0) /* Starter space for aArg[]. No malloc required */
aArg = bp
_enterMutex(tls) /* Enter STATIC_MAIN mutex */
/* This loop runs once for each entry in the blocked-connections list. */
pp = uintptr(unsafe.Pointer(&_sqlite3BlockedList))
for {
if !(**(**uintptr)(__ccgo_up(pp)) != 0) {
break
}
p = **(**uintptr)(__ccgo_up(pp))
/* Step 1. */
if (*Tsqlite3)(unsafe.Pointer(p)).FpBlockingConnection == db {
(*Tsqlite3)(unsafe.Pointer(p)).FpBlockingConnection = uintptr(0)
}
/* Step 2. */
if (*Tsqlite3)(unsafe.Pointer(p)).FpUnlockConnection == db {
if (*Tsqlite3)(unsafe.Pointer(p)).FxUnlockNotify != xUnlockNotify && nArg != 0 {
(*(*func(*libc.TLS, uintptr, int32))(unsafe.Pointer(&struct{ uintptr }{xUnlockNotify})))(tls, aArg, nArg)
nArg = 0
}
_sqlite3BeginBenignMalloc(tls)
if !(aDyn != 0) && nArg == libc.Int32FromUint64(libc.Uint64FromInt64(128)/libc.Uint64FromInt64(8)) || aDyn != 0 && nArg == libc.Int32FromUint64(libc.Uint64FromInt32(_sqlite3MallocSize(tls, aDyn))/libc.Uint64FromInt64(8)) {
/* The aArg[] array needs to grow. */
pNew = _sqlite3Malloc(tls, uint64(libc.Uint64FromInt32(nArg)*uint64(8)*uint64(2)))
if pNew != 0 {
libc.X__builtin___memcpy_chk(tls, pNew, aArg, libc.Uint64FromInt32(nArg)*uint64(8), ^t__predefined_size_t(0))
Xsqlite3_free(tls, aDyn)
v2 = pNew
aArg = v2
aDyn = v2
} else {
/* This occurs when the array of context pointers that need to
** be passed to the unlock-notify callback is larger than the
** aStatic[] array allocated on the stack and the attempt to
** allocate a larger array from the heap has failed.
**
** This is a difficult situation to handle. Returning an error
** code to the caller is insufficient, as even if an error code
** is returned the transaction on connection db will still be
** closed and the unlock-notify callbacks on blocked connections
** will go unissued. This might cause the application to wait
** indefinitely for an unlock-notify callback that will never
** arrive.
**
** Instead, invoke the unlock-notify callback with the context
** array already accumulated. We can then clear the array and
** begin accumulating any further context pointers without
** requiring any dynamic allocation. This is sub-optimal because
** it means that instead of one callback with a large array of
** context pointers the application will receive two or more
** callbacks with smaller arrays of context pointers, which will
** reduce the applications ability to prioritize multiple
** connections. But it is the best that can be done under the
** circumstances.
*/
(*(*func(*libc.TLS, uintptr, int32))(unsafe.Pointer(&struct{ uintptr }{xUnlockNotify})))(tls, aArg, nArg)
nArg = 0
}
}
_sqlite3EndBenignMalloc(tls)
v3 = nArg
nArg = nArg + 1
**(**uintptr)(__ccgo_up(aArg + uintptr(v3)*8)) = (*Tsqlite3)(unsafe.Pointer(p)).FpUnlockArg
xUnlockNotify = (*Tsqlite3)(unsafe.Pointer(p)).FxUnlockNotify
(*Tsqlite3)(unsafe.Pointer(p)).FpUnlockConnection = uintptr(0)
(*Tsqlite3)(unsafe.Pointer(p)).FxUnlockNotify = uintptr(0)
(*Tsqlite3)(unsafe.Pointer(p)).FpUnlockArg = uintptr(0)
}
/* Step 3. */
if (*Tsqlite3)(unsafe.Pointer(p)).FpBlockingConnection == uintptr(0) && (*Tsqlite3)(unsafe.Pointer(p)).FpUnlockConnection == uintptr(0) {
/* Remove connection p from the blocked connections list. */
**(**uintptr)(__ccgo_up(pp)) = (*Tsqlite3)(unsafe.Pointer(p)).FpNextBlocked
(*Tsqlite3)(unsafe.Pointer(p)).FpNextBlocked = uintptr(0)
} else {
pp = p + 856
}
goto _1
_1:
}
if nArg != 0 {
(*(*func(*libc.TLS, uintptr, int32))(unsafe.Pointer(&struct{ uintptr }{xUnlockNotify})))(tls, aArg, nArg)
}
Xsqlite3_free(tls, aDyn)
_leaveMutex(tls) /* Leave STATIC_MAIN mutex */
}
func _sqlite3CorruptError(tls *libc.TLS, lineno int32) (r int32) {
return _sqlite3ReportError(tls, int32(SQLITE_CORRUPT), lineno, __ccgo_ts+26687)
}
// 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+15519, libc.VaList(bp+8, (**(**TColumn)(__ccgo_up((*TTable)(unsafe.Pointer(p)).FaCol + uintptr(iCol)*16))).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+15582, 0)
goto fk_end
} else {
nCol = (*TExprList)(unsafe.Pointer(pFromCol)).FnExpr
}
}
nByte = libc.Int64FromUint64(uint64(libc.UintptrFromInt32(0)+64) + libc.Uint64FromInt32(nCol)*uint64(16) + uint64((*TToken)(unsafe.Pointer(pTo)).Fn) + uint64(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)*32))).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 + 64))).FpFKey
z = pFKey + 64 + uintptr(nCol)*16
(*TFKey)(unsafe.Pointer(pFKey)).FzTo = z
if libc.Int32FromUint8((*TParse)(unsafe.Pointer(pParse)).FeParseMode) >= int32(PARSE_MODE_RENAME) {
_sqlite3RenameTokenMap(tls, pParse, z, pTo)
}
libc.X__builtin___memcpy_chk(tls, z, (*TToken)(unsafe.Pointer(pTo)).Fz, uint64((*TToken)(unsafe.Pointer(pTo)).Fn), ^t__predefined_size_t(0))
**(**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 + 64))).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)*16))).FzCnName, (*(*TExprList_item)(unsafe.Pointer(pFromCol + 8 + uintptr(i)*32))).FzEName) == 0 {
(*(*TsColMap)(unsafe.Pointer(pFKey + 64 + uintptr(i)*16))).FiFrom = j
break
}
goto _3
_3:
;
j = j + 1
}
if j >= int32((*TTable)(unsafe.Pointer(p)).FnCol) {
_sqlite3ErrorMsg(tls, pParse, __ccgo_ts+15676, libc.VaList(bp+8, (*(*TExprList_item)(unsafe.Pointer(pFromCol + 8 + uintptr(i)*32))).FzEName))
goto fk_end
}
if libc.Int32FromUint8((*TParse)(unsafe.Pointer(pParse)).FeParseMode) >= int32(PARSE_MODE_RENAME) {
_sqlite3RenameTokenRemap(tls, pParse, pFKey+64+uintptr(i)*16, (*(*TExprList_item)(unsafe.Pointer(pFromCol + 8 + uintptr(i)*32))).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)*32))).FzEName)
(*(*TsColMap)(unsafe.Pointer(pFKey + 64 + uintptr(i)*16))).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)*32))).FzEName)
}
libc.X__builtin___memcpy_chk(tls, z, (*(*TExprList_item)(unsafe.Pointer(pToCol + 8 + uintptr(i)*32))).FzEName, libc.Uint64FromInt32(n), ^t__predefined_size_t(0))
**(**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 + 45)) = libc.Uint8FromInt32(flags & libc.Int32FromInt32(0xff)) /* ON DELETE action */
**(**Tu8)(__ccgo_up(pFKey + 45 + 1)) = libc.Uint8FromInt32(flags >> libc.Int32FromInt32(8) & libc.Int32FromInt32(0xff)) /* ON UPDATE action */
pNextTo = _sqlite3HashInsert(tls, (*TTable)(unsafe.Pointer(p)).FpSchema+80, (*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 + 64))).FpFKey = pFKey
pFKey = uintptr(0)
goto fk_end
fk_end:
;
_sqlite3DbFree(tls, db, pFKey)
_sqlite3ExprListDelete(tls, db, pFromCol)
_sqlite3ExprListDelete(tls, db, pToCol)
}
// C documentation
//
// /*
// ** This function is exactly the same as sqlite3_create_function(), except
// ** that it is designed to be called by internal code. The difference is
// ** that if a malloc() fails in sqlite3_create_function(), an error code
// ** is returned and the mallocFailed flag cleared.
// */
func _sqlite3CreateFunc(tls *libc.TLS, db uintptr, zFunctionName uintptr, nArg int32, enc int32, pUserData uintptr, __ccgo_fp_xSFunc uintptr, __ccgo_fp_xStep uintptr, __ccgo_fp_xFinal uintptr, __ccgo_fp_xValue uintptr, __ccgo_fp_xInverse uintptr, pDestructor uintptr) (r int32) {
var extraFlags, rc int32
var p, v1 uintptr
_, _, _, _ = extraFlags, p, rc, v1
if zFunctionName == uintptr(0) || __ccgo_fp_xSFunc != uintptr(0) && __ccgo_fp_xFinal != uintptr(0) || libc.BoolInt32(__ccgo_fp_xFinal == uintptr(0)) != libc.BoolInt32(__ccgo_fp_xStep == uintptr(0)) || libc.BoolInt32(__ccgo_fp_xValue == uintptr(0)) != libc.BoolInt32(__ccgo_fp_xInverse == uintptr(0)) || (nArg < -int32(1) || nArg > int32(SQLITE_MAX_FUNCTION_ARG)) || int32(255) < _sqlite3Strlen30(tls, zFunctionName) {
return _sqlite3MisuseError(tls, int32(189333))
}
extraFlags = enc & (libc.Int32FromInt32(SQLITE_DETERMINISTIC) | libc.Int32FromInt32(SQLITE_DIRECTONLY) | libc.Int32FromInt32(SQLITE_SUBTYPE) | libc.Int32FromInt32(SQLITE_INNOCUOUS) | libc.Int32FromInt32(SQLITE_RESULT_SUBTYPE) | libc.Int32FromInt32(SQLITE_SELFORDER1))
enc = enc & (libc.Int32FromInt32(SQLITE_FUNC_ENCMASK) | libc.Int32FromInt32(SQLITE_ANY))
/* The SQLITE_INNOCUOUS flag is the same bit as SQLITE_FUNC_UNSAFE. But
** the meaning is inverted. So flip the bit. */
extraFlags = extraFlags ^ int32(SQLITE_FUNC_UNSAFE) /* tag-20230109-1 */
/* If SQLITE_UTF16 is specified as the encoding type, transform this
** to one of SQLITE_UTF16LE or SQLITE_UTF16BE using the
** SQLITE_UTF16NATIVE macro. SQLITE_UTF16 is not used internally.
**
** If SQLITE_ANY is specified, add three versions of the function
** to the hash table.
*/
switch enc {
case int32(SQLITE_UTF16):
enc = int32(SQLITE_UTF16LE)
case int32(SQLITE_ANY):
rc = _sqlite3CreateFunc(tls, db, zFunctionName, nArg, int32(SQLITE_UTF8)|extraFlags^int32(SQLITE_FUNC_UNSAFE), pUserData, __ccgo_fp_xSFunc, __ccgo_fp_xStep, __ccgo_fp_xFinal, __ccgo_fp_xValue, __ccgo_fp_xInverse, pDestructor)
if rc == SQLITE_OK {
rc = _sqlite3CreateFunc(tls, db, zFunctionName, nArg, int32(SQLITE_UTF16LE)|extraFlags^int32(SQLITE_FUNC_UNSAFE), pUserData, __ccgo_fp_xSFunc, __ccgo_fp_xStep, __ccgo_fp_xFinal, __ccgo_fp_xValue, __ccgo_fp_xInverse, pDestructor)
}
if rc != SQLITE_OK {
return rc
}
enc = int32(SQLITE_UTF16BE)
case int32(SQLITE_UTF8):
fallthrough
case int32(SQLITE_UTF16LE):
fallthrough
case int32(SQLITE_UTF16BE):
default:
enc = int32(SQLITE_UTF8)
break
}
/* Check if an existing function is being overridden or deleted. If so,
** and there are active VMs, then return SQLITE_BUSY. If a function
** is being overridden/deleted but there are no active VMs, allow the
** operation to continue but invalidate all precompiled statements.
*/
p = _sqlite3FindFunction(tls, db, zFunctionName, nArg, libc.Uint8FromInt32(enc), uint8(0))
if p != 0 && (*TFuncDef)(unsafe.Pointer(p)).FfuncFlags&uint32(SQLITE_FUNC_ENCMASK) == libc.Uint32FromInt32(enc) && int32((*TFuncDef)(unsafe.Pointer(p)).FnArg) == nArg {
if (*Tsqlite3)(unsafe.Pointer(db)).FnVdbeActive != 0 {
_sqlite3ErrorWithMsg(tls, db, int32(SQLITE_BUSY), __ccgo_ts+26306, 0)
return int32(SQLITE_BUSY)
} else {
_sqlite3ExpirePreparedStatements(tls, db, 0)
}
} else {
if __ccgo_fp_xSFunc == uintptr(0) && __ccgo_fp_xFinal == uintptr(0) {
/* Trying to delete a function that does not exist. This is a no-op.
** https://sqlite.org/forum/forumpost/726219164b */
return SQLITE_OK
}
}
p = _sqlite3FindFunction(tls, db, zFunctionName, nArg, libc.Uint8FromInt32(enc), uint8(1))
if !(p != 0) {
return int32(SQLITE_NOMEM)
}
/* If an older version of the function with a configured destructor is
** being replaced invoke the destructor function here. */
_functionDestroy(tls, db, p)
if pDestructor != 0 {
(*TFuncDestructor)(unsafe.Pointer(pDestructor)).FnRef = (*TFuncDestructor)(unsafe.Pointer(pDestructor)).FnRef + 1
}
*(*uintptr)(unsafe.Pointer(p + 64)) = pDestructor
(*TFuncDef)(unsafe.Pointer(p)).FfuncFlags = (*TFuncDef)(unsafe.Pointer(p)).FfuncFlags&uint32(SQLITE_FUNC_ENCMASK) | libc.Uint32FromInt32(extraFlags)
if __ccgo_fp_xSFunc != 0 {
v1 = __ccgo_fp_xSFunc
} else {
v1 = __ccgo_fp_xStep
}
(*TFuncDef)(unsafe.Pointer(p)).FxSFunc = v1
(*TFuncDef)(unsafe.Pointer(p)).FxFinalize = __ccgo_fp_xFinal
(*TFuncDef)(unsafe.Pointer(p)).FxValue = __ccgo_fp_xValue
(*TFuncDef)(unsafe.Pointer(p)).FxInverse = __ccgo_fp_xInverse
(*TFuncDef)(unsafe.Pointer(p)).FpUserData = pUserData
(*TFuncDef)(unsafe.Pointer(p)).FnArg = libc.Int16FromUint16(libc.Uint16FromInt32(nArg))
return SQLITE_OK
}
// C documentation
//
// /*
// ** 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(176)
defer tls.Free(176)
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+96 */ uintptr
var _ /* prevCol at bp+112 */ TToken
var _ /* sFix at bp+0 */ TDbFixer
var _ /* zExtra at bp+104 */ 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 + 96)) = uintptr(0) /* For looping over pList */
nExtra = 0 /* Number of extra columns needed */
**(**uintptr)(__ccgo_up(bp + 104)) = 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+96)
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*32))).FpSchema {
iDb = int32(1)
}
}
_sqlite3FixInit(tls, bp, pParse, iDb, __ccgo_ts+15761, **(**uintptr)(__ccgo_up(bp + 96)))
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)*32))).FpSchema != (*TTable)(unsafe.Pointer(pTab)).FpSchema {
_sqlite3ErrorMsg(tls, pParse, __ccgo_ts+15767, libc.VaList(bp+136, (*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)*32
if Xsqlite3_strnicmp(tls, (*TTable)(unsafe.Pointer(pTab)).FzName, __ccgo_ts+7104, int32(7)) == 0 && libc.Int32FromUint8((*Tsqlite3)(unsafe.Pointer(db)).Finit1.Fbusy) == 0 && pTblName != uintptr(0) {
_sqlite3ErrorMsg(tls, pParse, __ccgo_ts+15817, libc.VaList(bp+136, (*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+15845, 0)
goto exit_create_index
}
if libc.Int32FromUint8((*TTable)(unsafe.Pointer(pTab)).FeTabType) == int32(TABTYP_VTAB) {
_sqlite3ErrorMsg(tls, pParse, __ccgo_ts+15870, 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 + 96)) != 0 {
zName = _sqlite3NameFromToken(tls, db, **(**uintptr)(__ccgo_up(bp + 96)))
if zName == uintptr(0) {
goto exit_create_index
}
if SQLITE_OK != _sqlite3CheckObjectName(tls, pParse, zName, __ccgo_ts+15761, (*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+15904, libc.VaList(bp+136, 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+15938, libc.VaList(bp+136, 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+15962, libc.VaList(bp+136, (*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 + 7112
} else {
v2 = __ccgo_ts + 6632
}
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))*16
v2 = pCol + 14
*(*Tu16)(unsafe.Pointer(v2)) = Tu16(int32(*(*Tu16)(unsafe.Pointer(v2))) | libc.Int32FromInt32(COLFLAG_UNIQUE))
_sqlite3TokenInit(tls, bp+112, (*TColumn)(unsafe.Pointer(pCol)).FzCnName)
pList = _sqlite3ExprListAppend(tls, pParse, uintptr(0), _sqlite3ExprAlloc(tls, db, int32(TK_ID), bp+112, 0))
if pList == uintptr(0) {
goto exit_create_index
}
_sqlite3ExprListSetSortOrder(tls, pList, sortOrder, -int32(1))
} else {
_sqlite3ExprListCheckLength(tls, pParse, pList, __ccgo_ts+15761)
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)*32))).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+104)
if (*Tsqlite3)(unsafe.Pointer(db)).FmallocFailed != 0 {
goto exit_create_index
}
(*TIndex)(unsafe.Pointer(pIndex)).FzName = **(**uintptr)(__ccgo_up(bp + 104))
**(**uintptr)(__ccgo_up(bp + 104)) = **(**uintptr)(__ccgo_up(bp + 104)) + uintptr(nName+int32(1))
libc.X__builtin___memcpy_chk(tls, (*TIndex)(unsafe.Pointer(pIndex)).FzName, zName, libc.Uint64FromInt32(nName+int32(1)), ^t__predefined_size_t(0))
(*TIndex)(unsafe.Pointer(pIndex)).FpTable = pTab
(*TIndex)(unsafe.Pointer(pIndex)).FonError = libc.Uint8FromInt32(onError)
libc.SetBitFieldPtr16Uint32(pIndex+100, libc.BoolUint32(onError != libc.Int32FromInt32(OE_None)), 3, 0x8)
libc.SetBitFieldPtr16Uint32(pIndex+100, uint32(idxType), 0, 0x3)
(*TIndex)(unsafe.Pointer(pIndex)).FpSchema = (**(**TDb)(__ccgo_up((*Tsqlite3)(unsafe.Pointer(db)).FaDb + uintptr(iDb)*32))).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+15985, 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+100, libc.Uint32FromInt32(0), 3, 0x8)
libc.SetBitFieldPtr16Uint32(pIndex+100, 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)*16 + 8))&0xf>>0)) == 0 {
libc.SetBitFieldPtr16Uint32(pIndex+100, libc.Uint32FromInt32(0), 3, 0x8)
}
if libc.Int32FromUint16((**(**TColumn)(__ccgo_up((*TTable)(unsafe.Pointer(pTab)).FaCol + uintptr(j)*16))).FcolFlags)&int32(COLFLAG_VIRTUAL) != 0 {
libc.SetBitFieldPtr16Uint32(pIndex+100, libc.Uint32FromInt32(1), 10, 0x400)
libc.SetBitFieldPtr16Uint32(pIndex+100, 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.X__builtin___memcpy_chk(tls, **(**uintptr)(__ccgo_up(bp + 104)), zColl, libc.Uint64FromInt32(nColl), ^t__predefined_size_t(0))
zColl = **(**uintptr)(__ccgo_up(bp + 104))
**(**uintptr)(__ccgo_up(bp + 104)) = **(**uintptr)(__ccgo_up(bp + 104)) + uintptr(nColl)
nExtra = nExtra - nColl
} else {
if j >= 0 {
zColl = _sqlite3ColumnColl(tls, (*TTable)(unsafe.Pointer(pTab)).FaCol+uintptr(j)*16)
}
}
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)*8)) = 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 += 32
}
/* 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)*8)) = **(**uintptr)(__ccgo_up((*TIndex)(unsafe.Pointer(pPk)).FazColl + uintptr(j)*8))
**(**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)*8)) = 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+100, 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+100, 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)*8))
z2 = **(**uintptr)(__ccgo_up((*TIndex)(unsafe.Pointer(pIndex)).FazColl + uintptr(k)*8))
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+16046, libc.VaList(bp+136, 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+100, 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+16088, 0)
(*TParse)(unsafe.Pointer(pParse)).Frc = _sqlite3CorruptError(tls, int32(130930))
goto exit_create_index
}
}
p = _sqlite3HashInsert(tls, (*TIndex)(unsafe.Pointer(pIndex)).FpSchema+32, (*TIndex)(unsafe.Pointer(pIndex)).FzName, pIndex)
if p != 0 {
/* Malloc must have failed */
_sqlite3OomFault(tls, db)
goto exit_create_index
}
**(**Tu32)(__ccgo_up(db + 44)) |= uint32(DBFLAG_SchemaChange)
} else {
if (*TTable)(unsafe.Pointer(pTab)).FtabFlags&uint32(TF_WithoutRowid) == uint32(0) || pTblName != uintptr(0) {
v2 = pParse + 60
*(*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(int64((*TParse)(unsafe.Pointer(pParse)).FsLastToken.Fz)-int64((*TToken)(unsafe.Pointer(**(**uintptr)(__ccgo_up(bp + 96)))).Fz))) + (*TParse)(unsafe.Pointer(pParse)).FsLastToken.Fn)
if int32(**(**int8)(__ccgo_up((*TToken)(unsafe.Pointer(**(**uintptr)(__ccgo_up(bp + 96)))).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 + 16105
}
zStmt = _sqlite3MPrintf(tls, db, __ccgo_ts+16113, libc.VaList(bp+136, v2, n1, (*TToken)(unsafe.Pointer(**(**uintptr)(__ccgo_up(bp + 96)))).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+16133, libc.VaList(bp+136, (**(**TDb)(__ccgo_up((*Tsqlite3)(unsafe.Pointer(db)).FaDb + uintptr(iDb)*32))).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+16192, libc.VaList(bp+136, (*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 + 16
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 + 40
}
break
goto _14
_14:
;
ppFrom = pThis + 40
}
}
_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(128)
defer tls.Free(128)
var db, p, z uintptr
var iDb, n int32
var _ /* pName at bp+112 */ uintptr
var _ /* sEnd at bp+0 */ TToken
var _ /* sFix at bp+16 */ TDbFixer
_, _, _, _, _ = db, iDb, n, p, z
**(**uintptr)(__ccgo_up(bp + 112)) = uintptr(0)
db = (*TParse)(unsafe.Pointer(pParse)).Fdb
if int32((*TParse)(unsafe.Pointer(pParse)).FnVar) > 0 {
_sqlite3ErrorMsg(tls, pParse, __ccgo_ts+15151, 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 + 48)) |= uint32(TF_NoVisibleRowid) /* Never allow rowid in view */
_sqlite3TwoPartName(tls, pParse, pName1, pName2, bp+112)
iDb = _sqlite3SchemaToIndex(tls, db, (*TTable)(unsafe.Pointer(p)).FpSchema)
_sqlite3FixInit(tls, bp+16, pParse, iDb, __ccgo_ts+11463, **(**uintptr)(__ccgo_up(bp + 112)))
if _sqlite3FixSelect(tls, bp+16, 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(int64((**(**TToken)(__ccgo_up(bp))).Fz) - int64((*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
//
// /*
// ** Return true if zName points to a name that may be used to refer to
// ** database iDb attached to handle db.
// */
func _sqlite3DbIsNamed(tls *libc.TLS, db uintptr, iDb int32, zName uintptr) (r int32) {
return libc.BoolInt32(_sqlite3StrICmp(tls, (**(**TDb)(__ccgo_up((*Tsqlite3)(unsafe.Pointer(db)).FaDb + uintptr(iDb)*32))).FzDbSName, zName) == 0 || iDb == 0 && _sqlite3StrICmp(tls, __ccgo_ts+7164, zName) == 0)
}
// C documentation
//
// /*
// ** Allocate and zero memory. If the allocation fails, make
// ** the mallocFailed flag in the connection pointer.
// */
func _sqlite3DbMallocZero(tls *libc.TLS, db uintptr, n Tu64) (r uintptr) {
var p uintptr
_ = p
p = _sqlite3DbMallocRaw(tls, db, n)
if p != 0 {
libc.X__builtin___memset_chk(tls, p, 0, n, ^t__predefined_size_t(0))
}
return p
}
// C documentation
//
// /*
// ** Make a copy of a string in memory obtained from sqliteMalloc(). These
// ** functions call sqlite3MallocRaw() directly instead of sqliteMalloc(). This
// ** is because when memory debugging is turned on, these two functions are
// ** called via macros that record the current file and line number in the
// ** ThreadData structure.
// */
func _sqlite3DbStrDup(tls *libc.TLS, db uintptr, z uintptr) (r uintptr) {
var n Tsize_t
var zNew uintptr
_, _ = n, zNew
if z == uintptr(0) {
return uintptr(0)
}
n = libc.Xstrlen(tls, z) + uint64(1)
zNew = _sqlite3DbMallocRaw(tls, db, n)
if zNew != 0 {
libc.X__builtin___memcpy_chk(tls, zNew, z, n, ^t__predefined_size_t(0))
}
return zNew
}
func _sqlite3DbStrNDup(tls *libc.TLS, db uintptr, z uintptr, n Tu64) (r uintptr) {
var zNew, v1 uintptr
_, _ = zNew, v1
if z != 0 {
v1 = _sqlite3DbMallocRawNN(tls, db, n+uint64(1))
} else {
v1 = uintptr(0)
}
zNew = v1
if zNew != 0 {
libc.X__builtin___memcpy_chk(tls, zNew, z, n, ^t__predefined_size_t(0))
**(**int8)(__ccgo_up(zNew + uintptr(n))) = 0
}
return zNew
}
// C documentation
//
// /*
// ** Invoke this routine to register the "dbpage" virtual table module
// */
func _sqlite3DbpageRegister(tls *libc.TLS, db uintptr) (r int32) {
return Xsqlite3_create_module(tls, db, __ccgo_ts+35569, uintptr(unsafe.Pointer(&_dbpage_module)), uintptr(0))
}
// C documentation
//
// /*
// ** Invoke this routine to register the "dbstat" virtual table module
// */
func _sqlite3DbstatRegister(tls *libc.TLS, db uintptr) (r int32) {
return Xsqlite3_create_module(tls, db, __ccgo_ts+35384, uintptr(unsafe.Pointer(&_dbstat_module)), uintptr(0))
}
// 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.X__builtin___memcpy_chk(tls, pOut, bp, uint64(8), ^t__predefined_size_t(0))
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.Int32FromUint64(libc.Uint64FromInt32(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
//
// /*
// ** Fill the Index.aiRowEst[] array with default information - information
// ** to be used when we have not run the ANALYZE command.
// **
// ** aiRowEst[0] is supposed to contain the number of elements in the index.
// ** Since we do not know, guess 1 million. aiRowEst[1] is an estimate of the
// ** number of rows in the table that match any particular value of the
// ** first column of the index. aiRowEst[2] is an estimate of the number
// ** of rows that match any particular combination of the first 2 columns
// ** of the index. And so forth. It must always be the case that
// *
// ** aiRowEst[N]<=aiRowEst[N-1]
// ** aiRowEst[N]>=1
// **
// ** Apart from that, we have little to go on besides intuition as to
// ** how aiRowEst[] should be initialized. The numbers generated here
// ** are based on typical values found in actual indices.
// */
func _sqlite3DefaultRowEst(tls *libc.TLS, pIdx uintptr) {
var a uintptr
var i, nCopy, v1 int32
var x, v2 TLogEst
_, _, _, _, _, _ = a, i, nCopy, x, v1, v2
a = (*TIndex)(unsafe.Pointer(pIdx)).FaiRowLogEst
if libc.Int32FromUint64(libc.Uint64FromInt64(10)/libc.Uint64FromInt64(2)) < libc.Int32FromUint16((*TIndex)(unsafe.Pointer(pIdx)).FnKeyCol) {
v1 = libc.Int32FromUint64(libc.Uint64FromInt64(10) / libc.Uint64FromInt64(2))
} else {
v1 = libc.Int32FromUint16((*TIndex)(unsafe.Pointer(pIdx)).FnKeyCol)
}
nCopy = v1
/* Indexes with default row estimates should not have stat1 data */
/* Set the first entry (number of rows in the index) to the estimated
** number of rows in the table, or half the number of rows in the table
** for a partial index.
**
** 2020-05-27: If some of the stat data is coming from the sqlite_stat1
** table but other parts we are having to guess at, then do not let the
** estimated number of rows in the table be less than 1000 (LogEst 99).
** Failure to do this can cause the indexes for which we do not have
** stat1 data to be ignored by the query planner.
*/
x = (*TTable)(unsafe.Pointer((*TIndex)(unsafe.Pointer(pIdx)).FpTable)).FnRowLogEst
if int32(x) < int32(99) {
v2 = libc.Int16FromInt32(99)
x = v2
(*TTable)(unsafe.Pointer((*TIndex)(unsafe.Pointer(pIdx)).FpTable)).FnRowLogEst = v2
}
if (*TIndex)(unsafe.Pointer(pIdx)).FpPartIdxWhere != uintptr(0) {
x = int16(int32(x) - libc.Int32FromInt32(10))
}
**(**TLogEst)(__ccgo_up(a)) = x
/* Estimate that a[1] is 10, a[2] is 9, a[3] is 8, a[4] is 7, a[5] is
** 6 and each subsequent value (if any) is 5. */
libc.X__builtin___memcpy_chk(tls, a+1*2, uintptr(unsafe.Pointer(&_aVal)), libc.Uint64FromInt32(nCopy)*uint64(2), ^t__predefined_size_t(0))
i = nCopy + int32(1)
for {
if !(i <= libc.Int32FromUint16((*TIndex)(unsafe.Pointer(pIdx)).FnKeyCol)) {
break
}
**(**TLogEst)(__ccgo_up(a + uintptr(i)*2)) = int16(23)
goto _3
_3:
;
i = i + 1
}
if libc.Int32FromUint8((*TIndex)(unsafe.Pointer(pIdx)).FonError) != OE_None {
**(**TLogEst)(__ccgo_up(a + uintptr((*TIndex)(unsafe.Pointer(pIdx)).FnKeyCol)*2)) = 0
}
}
// C documentation
//
// /*
// ** Generate code for a DELETE FROM statement.
// **
// ** DELETE FROM table_wxyz WHERE a<5 AND b NOT NULL;
// ** \________/ \________________/
// ** pTabList pWhere
// */
func _sqlite3DeleteFrom(tls *libc.TLS, pParse uintptr, pTabList uintptr, pWhere uintptr, pOrderBy uintptr, pLimit uintptr) {
bp := tls.Alloc(96)
defer tls.Free(96)
var aToOpen, db, pIdx, pPk, pTab, pTrigger, pVTab, pWInfo, v, v3 uintptr
var addrBypass, addrEphOpen, addrLoop, bComplex, count, eOnePass, i, iAddrOnce, iDb, iEphCur, iKey, iPk, iRowSet, iTabCur, isView, memCnt, nIdx, rcauth, v1, v2 int32
var nKey, nPk Ti16
var wcf Tu16
var _ /* aiCurOnePass at bp+80 */ [2]int32
var _ /* iDataCur at bp+0 */ int32
var _ /* iIdxCur at bp+4 */ int32
var _ /* sContext at bp+8 */ TAuthContext
var _ /* sNC at bp+24 */ TNameContext
_, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _ = aToOpen, addrBypass, addrEphOpen, addrLoop, bComplex, count, db, eOnePass, i, iAddrOnce, iDb, iEphCur, iKey, iPk, iRowSet, iTabCur, isView, memCnt, nIdx, nKey, nPk, pIdx, pPk, pTab, pTrigger, pVTab, pWInfo, rcauth, v, wcf, v1, v2, v3 /* Cursor number for the table */
**(**int32)(__ccgo_up(bp)) = 0 /* VDBE cursor for the canonical data source */
**(**int32)(__ccgo_up(bp + 4)) = 0 /* Database number */
memCnt = 0 /* The write cursors opened by WHERE_ONEPASS */
aToOpen = uintptr(0) /* The PRIMARY KEY index on the table */
iPk = 0 /* First of nPk registers holding PRIMARY KEY value */
nPk = int16(1) /* Number of memory cells in the row key */
iEphCur = 0 /* Ephemeral table holding all primary key values */
iRowSet = 0 /* Register for rowset of rows to delete */
addrBypass = 0 /* Address of jump over the delete logic */
addrLoop = 0 /* Top of the delete loop */
addrEphOpen = 0 /* List of table triggers, if required */
libc.X__builtin___memset_chk(tls, bp+8, 0, uint64(16), ^t__predefined_size_t(0))
db = (*TParse)(unsafe.Pointer(pParse)).Fdb
if (*TParse)(unsafe.Pointer(pParse)).FnErr != 0 {
goto delete_from_cleanup
}
/* Locate the table which we want to delete. This table has to be
** put in an SrcList structure because some of the subroutines we
** will be calling are designed to work with multiple tables and expect
** an SrcList* parameter instead of just a Table* parameter.
*/
pTab = _sqlite3SrcListLookup(tls, pParse, pTabList)
if pTab == uintptr(0) {
goto delete_from_cleanup
}
/* Figure out if we have any triggers and if the table being
** deleted from is a view
*/
pTrigger = _sqlite3TriggersExist(tls, pParse, pTab, int32(TK_DELETE), uintptr(0), uintptr(0))
isView = libc.BoolInt32(libc.Int32FromUint8((*TTable)(unsafe.Pointer(pTab)).FeTabType) == int32(TABTYP_VIEW))
bComplex = libc.BoolInt32(pTrigger != 0 || _sqlite3FkRequired(tls, pParse, pTab, uintptr(0), 0) != 0)
/* If pTab is really a view, make sure it has been initialized.
*/
if _sqlite3ViewGetColumnNames(tls, pParse, pTab) != 0 {
goto delete_from_cleanup
}
if _sqlite3IsReadOnly(tls, pParse, pTab, pTrigger) != 0 {
goto delete_from_cleanup
}
iDb = _sqlite3SchemaToIndex(tls, db, (*TTable)(unsafe.Pointer(pTab)).FpSchema)
rcauth = _sqlite3AuthCheck(tls, pParse, int32(SQLITE_DELETE), (*TTable)(unsafe.Pointer(pTab)).FzName, uintptr(0), (**(**TDb)(__ccgo_up((*Tsqlite3)(unsafe.Pointer(db)).FaDb + uintptr(iDb)*32))).FzDbSName)
if rcauth == int32(SQLITE_DENY) {
goto delete_from_cleanup
}
/* Assign cursor numbers to the table and all its indices.
*/
v3 = pParse + 56
v2 = *(*int32)(unsafe.Pointer(v3))
*(*int32)(unsafe.Pointer(v3)) = *(*int32)(unsafe.Pointer(v3)) + 1
v1 = v2
(*(*TSrcItem)(unsafe.Pointer(pTabList + 8))).FiCursor = v1
iTabCur = v1
nIdx = 0
pIdx = (*TTable)(unsafe.Pointer(pTab)).FpIndex
for {
if !(pIdx != 0) {
break
}
(*TParse)(unsafe.Pointer(pParse)).FnTab = (*TParse)(unsafe.Pointer(pParse)).FnTab + 1
goto _4
_4:
;
pIdx = (*TIndex)(unsafe.Pointer(pIdx)).FpNext
nIdx = nIdx + 1
}
/* Start the view context
*/
if isView != 0 {
_sqlite3AuthContextPush(tls, pParse, bp+8, (*TTable)(unsafe.Pointer(pTab)).FzName)
}
/* Begin generating code.
*/
v = _sqlite3GetVdbe(tls, pParse)
if v == uintptr(0) {
goto delete_from_cleanup
}
if libc.Int32FromUint8((*TParse)(unsafe.Pointer(pParse)).Fnested) == 0 {
_sqlite3VdbeCountChanges(tls, v)
}
_sqlite3BeginWriteOperation(tls, pParse, bComplex, iDb)
/* If we are trying to delete from a view, realize that view into
** an ephemeral table.
*/
if isView != 0 {
_sqlite3MaterializeView(tls, pParse, pTab, pWhere, pOrderBy, pLimit, iTabCur)
v1 = iTabCur
**(**int32)(__ccgo_up(bp + 4)) = v1
**(**int32)(__ccgo_up(bp)) = v1
pOrderBy = uintptr(0)
pLimit = uintptr(0)
}
/* Resolve the column names in the WHERE clause.
*/
libc.X__builtin___memset_chk(tls, bp+24, 0, uint64(56), ^t__predefined_size_t(0))
(**(**TNameContext)(__ccgo_up(bp + 24))).FpParse = pParse
(**(**TNameContext)(__ccgo_up(bp + 24))).FpSrcList = pTabList
if _sqlite3ResolveExprNames(tls, bp+24, pWhere) != 0 {
goto delete_from_cleanup
}
/* Initialize the counter of the number of rows deleted, if
** we are counting rows.
*/
if (*Tsqlite3)(unsafe.Pointer(db)).Fflags&(libc.Uint64FromInt32(libc.Int32FromInt32(0x00001))<>3)) != 0) {
v3 = pParse + 60
*(*int32)(unsafe.Pointer(v3)) = *(*int32)(unsafe.Pointer(v3)) + 1
v1 = *(*int32)(unsafe.Pointer(v3))
memCnt = v1
_sqlite3VdbeAddOp2(tls, v, int32(OP_Integer), 0, memCnt)
}
/* Special case: A DELETE without a WHERE clause deletes everything.
** It is easier just to erase the whole table. Prior to version 3.6.5,
** this optimization caused the row change count (the value returned by
** API function sqlite3_count_changes) to be set incorrectly.
**
** The "rcauth==SQLITE_OK" terms is the
** IMPLEMENTATION-OF: R-17228-37124 If the action code is SQLITE_DELETE and
** the callback returns SQLITE_IGNORE then the DELETE operation proceeds but
** the truncate optimization is disabled and all rows are deleted
** individually.
*/
if rcauth == SQLITE_OK && pWhere == uintptr(0) && !(bComplex != 0) && !(libc.Int32FromUint8((*TTable)(unsafe.Pointer(pTab)).FeTabType) == libc.Int32FromInt32(TABTYP_VTAB)) && (*Tsqlite3)(unsafe.Pointer(db)).FxPreUpdateCallback == uintptr(0) {
_sqlite3TableLock(tls, pParse, iDb, (*TTable)(unsafe.Pointer(pTab)).Ftnum, uint8(1), (*TTable)(unsafe.Pointer(pTab)).FzName)
if (*TTable)(unsafe.Pointer(pTab)).FtabFlags&uint32(TF_WithoutRowid) == uint32(0) {
if memCnt != 0 {
v1 = memCnt
} else {
v1 = -int32(1)
}
_sqlite3VdbeAddOp4(tls, v, int32(OP_Clear), libc.Int32FromUint32((*TTable)(unsafe.Pointer(pTab)).Ftnum), iDb, v1, (*TTable)(unsafe.Pointer(pTab)).FzName, -int32(1))
}
pIdx = (*TTable)(unsafe.Pointer(pTab)).FpIndex
for {
if !(pIdx != 0) {
break
}
if int32(uint32(*(*uint16)(unsafe.Pointer(pIdx + 100))&0x3>>0)) == int32(SQLITE_IDXTYPE_PRIMARYKEY) && !((*TTable)(unsafe.Pointer(pTab)).FtabFlags&libc.Uint32FromInt32(TF_WithoutRowid) == libc.Uint32FromInt32(0)) {
if memCnt != 0 {
v1 = memCnt
} else {
v1 = -int32(1)
}
_sqlite3VdbeAddOp3(tls, v, int32(OP_Clear), libc.Int32FromUint32((*TIndex)(unsafe.Pointer(pIdx)).Ftnum), iDb, v1)
} else {
_sqlite3VdbeAddOp2(tls, v, int32(OP_Clear), libc.Int32FromUint32((*TIndex)(unsafe.Pointer(pIdx)).Ftnum), iDb)
}
goto _9
_9:
;
pIdx = (*TIndex)(unsafe.Pointer(pIdx)).FpNext
}
} else {
wcf = libc.Uint16FromInt32(libc.Int32FromInt32(WHERE_ONEPASS_DESIRED) | libc.Int32FromInt32(WHERE_DUPLICATES_OK))
if (**(**TNameContext)(__ccgo_up(bp + 24))).FncFlags&int32(NC_Subquery) != 0 {
bComplex = int32(1)
}
if bComplex != 0 {
v1 = 0
} else {
v1 = int32(WHERE_ONEPASS_MULTIROW)
}
wcf = libc.Uint16FromInt32(int32(wcf) | v1)
if (*TTable)(unsafe.Pointer(pTab)).FtabFlags&uint32(TF_WithoutRowid) == uint32(0) {
/* For a rowid table, initialize the RowSet to an empty set */
pPk = uintptr(0)
v3 = pParse + 60
*(*int32)(unsafe.Pointer(v3)) = *(*int32)(unsafe.Pointer(v3)) + 1
v1 = *(*int32)(unsafe.Pointer(v3))
iRowSet = v1
_sqlite3VdbeAddOp2(tls, v, int32(OP_Null), 0, iRowSet)
} else {
/* For a WITHOUT ROWID table, create an ephemeral table used to
** hold all primary keys for rows to be deleted. */
pPk = _sqlite3PrimaryKeyIndex(tls, pTab)
nPk = libc.Int16FromUint16((*TIndex)(unsafe.Pointer(pPk)).FnKeyCol)
iPk = (*TParse)(unsafe.Pointer(pParse)).FnMem + int32(1)
**(**int32)(__ccgo_up(pParse + 60)) += int32(nPk)
v3 = pParse + 56
v1 = *(*int32)(unsafe.Pointer(v3))
*(*int32)(unsafe.Pointer(v3)) = *(*int32)(unsafe.Pointer(v3)) + 1
iEphCur = v1
addrEphOpen = _sqlite3VdbeAddOp2(tls, v, int32(OP_OpenEphemeral), iEphCur, int32(nPk))
_sqlite3VdbeSetP4KeyInfo(tls, pParse, pPk)
}
/* Construct a query to find the rowid or primary key for every row
** to be deleted, based on the WHERE clause. Set variable eOnePass
** to indicate the strategy used to implement this delete:
**
** ONEPASS_OFF: Two-pass approach - use a FIFO for rowids/PK values.
** ONEPASS_SINGLE: One-pass approach - at most one row deleted.
** ONEPASS_MULTI: One-pass approach - any number of rows may be deleted.
*/
pWInfo = _sqlite3WhereBegin(tls, pParse, pTabList, pWhere, uintptr(0), uintptr(0), uintptr(0), wcf, iTabCur+int32(1))
if pWInfo == uintptr(0) {
goto delete_from_cleanup
}
eOnePass = _sqlite3WhereOkOnePass(tls, pWInfo, bp+80)
if eOnePass != int32(ONEPASS_SINGLE) {
_sqlite3MultiWrite(tls, pParse)
}
if _sqlite3WhereUsesDeferredSeek(tls, pWInfo) != 0 {
_sqlite3VdbeAddOp1(tls, v, int32(OP_FinishSeek), iTabCur)
}
/* Keep track of the number of rows to be deleted */
if memCnt != 0 {
_sqlite3VdbeAddOp2(tls, v, int32(OP_AddImm), memCnt, int32(1))
}
/* Extract the rowid or primary key for the current row */
if pPk != 0 {
i = 0
for {
if !(i < int32(nPk)) {
break
}
_sqlite3ExprCodeGetColumnOfTable(tls, v, pTab, iTabCur, int32(**(**Ti16)(__ccgo_up((*TIndex)(unsafe.Pointer(pPk)).FaiColumn + uintptr(i)*2))), iPk+i)
goto _16
_16:
;
i = i + 1
}
iKey = iPk
} else {
v3 = pParse + 60
*(*int32)(unsafe.Pointer(v3)) = *(*int32)(unsafe.Pointer(v3)) + 1
v1 = *(*int32)(unsafe.Pointer(v3))
iKey = v1
_sqlite3ExprCodeGetColumnOfTable(tls, v, pTab, iTabCur, -int32(1), iKey)
}
if eOnePass != ONEPASS_OFF {
/* For ONEPASS, no need to store the rowid/primary-key. There is only
** one, so just keep it in its register(s) and fall through to the
** delete code. */
nKey = nPk /* OP_Found will use an unpacked key */
aToOpen = _sqlite3DbMallocRawNN(tls, db, libc.Uint64FromInt32(nIdx+int32(2)))
if aToOpen == uintptr(0) {
_sqlite3WhereEnd(tls, pWInfo)
goto delete_from_cleanup
}
libc.X__builtin___memset_chk(tls, aToOpen, int32(1), libc.Uint64FromInt32(nIdx+int32(1)), ^t__predefined_size_t(0))
**(**Tu8)(__ccgo_up(aToOpen + uintptr(nIdx+int32(1)))) = uint8(0)
if (**(**[2]int32)(__ccgo_up(bp + 80)))[0] >= 0 {
**(**Tu8)(__ccgo_up(aToOpen + uintptr((**(**[2]int32)(__ccgo_up(bp + 80)))[0]-iTabCur))) = uint8(0)
}
if (**(**[2]int32)(__ccgo_up(bp + 80)))[int32(1)] >= 0 {
**(**Tu8)(__ccgo_up(aToOpen + uintptr((**(**[2]int32)(__ccgo_up(bp + 80)))[int32(1)]-iTabCur))) = uint8(0)
}
if addrEphOpen != 0 {
_sqlite3VdbeChangeToNoop(tls, v, addrEphOpen)
}
addrBypass = _sqlite3VdbeMakeLabel(tls, pParse)
} else {
if pPk != 0 {
/* Add the PK key for this row to the temporary table */
v3 = pParse + 60
*(*int32)(unsafe.Pointer(v3)) = *(*int32)(unsafe.Pointer(v3)) + 1
v1 = *(*int32)(unsafe.Pointer(v3))
iKey = v1
nKey = 0 /* Zero tells OP_Found to use a composite key */
_sqlite3VdbeAddOp4(tls, v, int32(OP_MakeRecord), iPk, int32(nPk), iKey, _sqlite3IndexAffinityStr(tls, (*TParse)(unsafe.Pointer(pParse)).Fdb, pPk), int32(nPk))
_sqlite3VdbeAddOp4Int(tls, v, int32(OP_IdxInsert), iEphCur, iKey, iPk, int32(nPk))
} else {
/* Add the rowid of the row to be deleted to the RowSet */
nKey = int16(1) /* OP_DeferredSeek always uses a single rowid */
_sqlite3VdbeAddOp2(tls, v, int32(OP_RowSetAdd), iRowSet, iKey)
}
_sqlite3WhereEnd(tls, pWInfo)
}
/* Unless this is a view, open cursors for the table we are
** deleting from and all its indices. If this is a view, then the
** only effect this statement has is to fire the INSTEAD OF
** triggers.
*/
if !(isView != 0) {
iAddrOnce = 0
if eOnePass == int32(ONEPASS_MULTI) {
iAddrOnce = _sqlite3VdbeAddOp0(tls, v, int32(OP_Once))
}
_sqlite3OpenTableAndIndices(tls, pParse, pTab, int32(OP_OpenWrite), uint8(OPFLAG_FORDELETE), iTabCur, aToOpen, bp, bp+4)
if eOnePass == int32(ONEPASS_MULTI) {
_sqlite3VdbeJumpHereOrPopInst(tls, v, iAddrOnce)
}
}
/* Set up a loop over the rowids/primary-keys that were found in the
** where-clause loop above.
*/
if eOnePass != ONEPASS_OFF {
/* OP_Found will use an unpacked key */
if !(libc.Int32FromUint8((*TTable)(unsafe.Pointer(pTab)).FeTabType) == libc.Int32FromInt32(TABTYP_VTAB)) && **(**Tu8)(__ccgo_up(aToOpen + uintptr(**(**int32)(__ccgo_up(bp))-iTabCur))) != 0 {
_sqlite3VdbeAddOp4Int(tls, v, int32(OP_NotFound), **(**int32)(__ccgo_up(bp)), addrBypass, iKey, int32(nKey))
}
} else {
if pPk != 0 {
addrLoop = _sqlite3VdbeAddOp1(tls, v, int32(OP_Rewind), iEphCur)
if libc.Int32FromUint8((*TTable)(unsafe.Pointer(pTab)).FeTabType) == int32(TABTYP_VTAB) {
_sqlite3VdbeAddOp3(tls, v, int32(OP_Column), iEphCur, 0, iKey)
} else {
_sqlite3VdbeAddOp2(tls, v, int32(OP_RowData), iEphCur, iKey)
}
/* OP_Found will use a composite key */
} else {
addrLoop = _sqlite3VdbeAddOp3(tls, v, int32(OP_RowSetRead), iRowSet, 0, iKey)
}
}
/* Delete the row */
if libc.Int32FromUint8((*TTable)(unsafe.Pointer(pTab)).FeTabType) == int32(TABTYP_VTAB) {
pVTab = _sqlite3GetVTable(tls, db, pTab)
_sqlite3VtabMakeWritable(tls, pParse, pTab)
_sqlite3MayAbort(tls, pParse)
if eOnePass == int32(ONEPASS_SINGLE) {
_sqlite3VdbeAddOp1(tls, v, int32(OP_Close), iTabCur)
if (*TParse)(unsafe.Pointer(pParse)).FpToplevel == uintptr(0) {
(*TParse)(unsafe.Pointer(pParse)).FisMultiWrite = uint8(0)
}
}
_sqlite3VdbeAddOp4(tls, v, int32(OP_VUpdate), 0, int32(1), iKey, pVTab, -int32(12))
_sqlite3VdbeChangeP5(tls, v, uint16(OE_Abort))
} else {
count = libc.BoolInt32(libc.Int32FromUint8((*TParse)(unsafe.Pointer(pParse)).Fnested) == 0) /* True to count changes */
_sqlite3GenerateRowDelete(tls, pParse, pTab, pTrigger, **(**int32)(__ccgo_up(bp)), **(**int32)(__ccgo_up(bp + 4)), iKey, nKey, libc.Uint8FromInt32(count), uint8(OE_Default), libc.Uint8FromInt32(eOnePass), (**(**[2]int32)(__ccgo_up(bp + 80)))[int32(1)])
}
/* End of the loop over all rowids/primary-keys. */
if eOnePass != ONEPASS_OFF {
_sqlite3VdbeResolveLabel(tls, v, addrBypass)
_sqlite3WhereEnd(tls, pWInfo)
} else {
if pPk != 0 {
_sqlite3VdbeAddOp2(tls, v, int32(OP_Next), iEphCur, addrLoop+int32(1))
_sqlite3VdbeJumpHere(tls, v, addrLoop)
} else {
_sqlite3VdbeGoto(tls, v, addrLoop)
_sqlite3VdbeJumpHere(tls, v, addrLoop)
}
}
} /* End non-truncate path */
/* Update the sqlite_sequence table by storing the content of the
** maximum rowid counter values recorded while inserting into
** autoincrement tables.
*/
if libc.Int32FromUint8((*TParse)(unsafe.Pointer(pParse)).Fnested) == 0 && (*TParse)(unsafe.Pointer(pParse)).FpTriggerTab == uintptr(0) {
_sqlite3AutoincrementEnd(tls, pParse)
}
/* Return the number of rows that were deleted. If this routine is
** generating code because of a call to sqlite3NestedParse(), do not
** invoke the callback function.
*/
if memCnt != 0 {
_sqlite3CodeChangeCount(tls, v, memCnt, __ccgo_ts+16793)
}
goto delete_from_cleanup
delete_from_cleanup:
;
_sqlite3AuthContextPop(tls, bp+8)
_sqlite3SrcListDelete(tls, db, pTabList)
_sqlite3ExprDelete(tls, db, pWhere)
if aToOpen != 0 {
_sqlite3DbNNFreeNN(tls, db, aToOpen)
}
return
}
/* Make sure "isView" and other macros defined above are undefined. Otherwise
** they may interfere with compilation of other functions in this file
** (or in another file, if this file becomes part of the amalgamation). */
// C documentation
//
// /*
// ** This routine will drop an existing named index. This routine
// ** implements the DROP INDEX statement.
// */
func _sqlite3DropIndex(tls *libc.TLS, pParse uintptr, pName uintptr, ifExists int32) {
bp := tls.Alloc(32)
defer tls.Free(32)
var code, iDb int32
var db, pIndex, pTab, v, zDb, zTab, v1 uintptr
_, _, _, _, _, _, _, _, _ = code, db, iDb, pIndex, pTab, v, zDb, zTab, v1
db = (*TParse)(unsafe.Pointer(pParse)).Fdb
if (*Tsqlite3)(unsafe.Pointer(db)).FmallocFailed != 0 {
goto exit_drop_index
}
/* Never called with prior non-OOM errors */
if SQLITE_OK != _sqlite3ReadSchema(tls, pParse) {
goto exit_drop_index
}
pIndex = _sqlite3FindIndex(tls, db, (*(*TSrcItem)(unsafe.Pointer(pName + 8))).FzName, *(*uintptr)(unsafe.Pointer(pName + 8 + 72)))
if pIndex == uintptr(0) {
if !(ifExists != 0) {
_sqlite3ErrorMsg(tls, pParse, __ccgo_ts+16219, libc.VaList(bp+8, pName+8))
} else {
_sqlite3CodeVerifyNamedSchema(tls, pParse, *(*uintptr)(unsafe.Pointer(pName + 8 + 72)))
_sqlite3ForceNotReadOnly(tls, pParse)
}
libc.SetBitFieldPtr16Uint32(pParse+40, libc.Uint32FromInt32(1), 8, 0x100)
goto exit_drop_index
}
if int32(uint32(*(*uint16)(unsafe.Pointer(pIndex + 100))&0x3>>0)) != SQLITE_IDXTYPE_APPDEF {
_sqlite3ErrorMsg(tls, pParse, __ccgo_ts+16237, libc.VaList(bp+8, 0))
goto exit_drop_index
}
iDb = _sqlite3SchemaToIndex(tls, db, (*TIndex)(unsafe.Pointer(pIndex)).FpSchema)
code = int32(SQLITE_DROP_INDEX)
pTab = (*TIndex)(unsafe.Pointer(pIndex)).FpTable
zDb = (**(**TDb)(__ccgo_up((*Tsqlite3)(unsafe.Pointer(db)).FaDb + uintptr(iDb)*32))).FzDbSName
if libc.Bool(!(libc.Int32FromInt32(OMIT_TEMPDB) != 0)) && iDb == int32(1) {
v1 = __ccgo_ts + 7112
} else {
v1 = __ccgo_ts + 6632
}
zTab = v1
if _sqlite3AuthCheck(tls, pParse, int32(SQLITE_DELETE), zTab, uintptr(0), zDb) != 0 {
goto exit_drop_index
}
if libc.Bool(!(libc.Int32FromInt32(OMIT_TEMPDB) != 0)) && iDb == int32(1) {
code = int32(SQLITE_DROP_TEMP_INDEX)
}
if _sqlite3AuthCheck(tls, pParse, code, (*TIndex)(unsafe.Pointer(pIndex)).FzName, (*TTable)(unsafe.Pointer(pTab)).FzName, zDb) != 0 {
goto exit_drop_index
}
/* Generate code to remove the index and from the schema table */
v = _sqlite3GetVdbe(tls, pParse)
if v != 0 {
_sqlite3BeginWriteOperation(tls, pParse, int32(1), iDb)
_sqlite3NestedParse(tls, pParse, __ccgo_ts+16310, libc.VaList(bp+8, (**(**TDb)(__ccgo_up((*Tsqlite3)(unsafe.Pointer(db)).FaDb + uintptr(iDb)*32))).FzDbSName, (*TIndex)(unsafe.Pointer(pIndex)).FzName))
_sqlite3ClearStatTables(tls, pParse, iDb, __ccgo_ts+13392, (*TIndex)(unsafe.Pointer(pIndex)).FzName)
_sqlite3ChangeCookie(tls, pParse, iDb)
_destroyRootPage(tls, pParse, libc.Int32FromUint32((*TIndex)(unsafe.Pointer(pIndex)).Ftnum), iDb)
_sqlite3VdbeAddOp4(tls, v, int32(OP_DropIndex), iDb, 0, 0, (*TIndex)(unsafe.Pointer(pIndex)).FzName, 0)
}
goto exit_drop_index
exit_drop_index:
;
_sqlite3SrcListDelete(tls, db, pName)
}
// C documentation
//
// /*
// ** This routine is called to do the work of a DROP TABLE statement.
// ** pName is the name of the table to be dropped.
// */
func _sqlite3DropTable(tls *libc.TLS, pParse uintptr, pName uintptr, isView int32, noErr int32) {
bp := tls.Alloc(16)
defer tls.Free(16)
var code, iDb int32
var db, pTab, v, zArg2, zDb, zTab, v1 uintptr
_, _, _, _, _, _, _, _, _ = code, db, iDb, pTab, v, zArg2, zDb, zTab, v1
db = (*TParse)(unsafe.Pointer(pParse)).Fdb
if (*Tsqlite3)(unsafe.Pointer(db)).FmallocFailed != 0 {
goto exit_drop_table
}
if _sqlite3ReadSchema(tls, pParse) != 0 {
goto exit_drop_table
}
if noErr != 0 {
(*Tsqlite3)(unsafe.Pointer(db)).FsuppressErr = (*Tsqlite3)(unsafe.Pointer(db)).FsuppressErr + 1
}
pTab = _sqlite3LocateTableItem(tls, pParse, libc.Uint32FromInt32(isView), pName+8)
if noErr != 0 {
(*Tsqlite3)(unsafe.Pointer(db)).FsuppressErr = (*Tsqlite3)(unsafe.Pointer(db)).FsuppressErr - 1
}
if pTab == uintptr(0) {
if noErr != 0 {
_sqlite3CodeVerifyNamedSchema(tls, pParse, *(*uintptr)(unsafe.Pointer(pName + 8 + 72)))
_sqlite3ForceNotReadOnly(tls, pParse)
}
goto exit_drop_table
}
iDb = _sqlite3SchemaToIndex(tls, db, (*TTable)(unsafe.Pointer(pTab)).FpSchema)
/* If pTab is a virtual table, call ViewGetColumnNames() to ensure
** it is initialized.
*/
if libc.Int32FromUint8((*TTable)(unsafe.Pointer(pTab)).FeTabType) == int32(TABTYP_VTAB) && _sqlite3ViewGetColumnNames(tls, pParse, pTab) != 0 {
goto exit_drop_table
}
if libc.Bool(!(libc.Int32FromInt32(OMIT_TEMPDB) != 0)) && iDb == int32(1) {
v1 = __ccgo_ts + 7112
} else {
v1 = __ccgo_ts + 6632
}
zTab = v1
zDb = (**(**TDb)(__ccgo_up((*Tsqlite3)(unsafe.Pointer(db)).FaDb + uintptr(iDb)*32))).FzDbSName
zArg2 = uintptr(0)
if _sqlite3AuthCheck(tls, pParse, int32(SQLITE_DELETE), zTab, uintptr(0), zDb) != 0 {
goto exit_drop_table
}
if isView != 0 {
if libc.Bool(!(libc.Int32FromInt32(OMIT_TEMPDB) != 0)) && iDb == int32(1) {
code = int32(SQLITE_DROP_TEMP_VIEW)
} else {
code = int32(SQLITE_DROP_VIEW)
}
} else {
if libc.Int32FromUint8((*TTable)(unsafe.Pointer(pTab)).FeTabType) == int32(TABTYP_VTAB) {
code = int32(SQLITE_DROP_VTABLE)
zArg2 = (*TModule)(unsafe.Pointer((*TVTable)(unsafe.Pointer(_sqlite3GetVTable(tls, db, pTab))).FpMod)).FzName
} else {
if libc.Bool(!(libc.Int32FromInt32(OMIT_TEMPDB) != 0)) && iDb == int32(1) {
code = int32(SQLITE_DROP_TEMP_TABLE)
} else {
code = int32(SQLITE_DROP_TABLE)
}
}
}
if _sqlite3AuthCheck(tls, pParse, code, (*TTable)(unsafe.Pointer(pTab)).FzName, zArg2, zDb) != 0 {
goto exit_drop_table
}
if _sqlite3AuthCheck(tls, pParse, int32(SQLITE_DELETE), (*TTable)(unsafe.Pointer(pTab)).FzName, uintptr(0), zDb) != 0 {
goto exit_drop_table
}
if _tableMayNotBeDropped(tls, db, pTab) != 0 {
_sqlite3ErrorMsg(tls, pParse, __ccgo_ts+15425, libc.VaList(bp+8, (*TTable)(unsafe.Pointer(pTab)).FzName))
goto exit_drop_table
}
/* Ensure DROP TABLE is not used on a view, and DROP VIEW is not used
** on a table.
*/
if isView != 0 && !(libc.Int32FromUint8((*TTable)(unsafe.Pointer(pTab)).FeTabType) == libc.Int32FromInt32(TABTYP_VIEW)) {
_sqlite3ErrorMsg(tls, pParse, __ccgo_ts+15453, libc.VaList(bp+8, (*TTable)(unsafe.Pointer(pTab)).FzName))
goto exit_drop_table
}
if !(isView != 0) && libc.Int32FromUint8((*TTable)(unsafe.Pointer(pTab)).FeTabType) == int32(TABTYP_VIEW) {
_sqlite3ErrorMsg(tls, pParse, __ccgo_ts+15487, libc.VaList(bp+8, (*TTable)(unsafe.Pointer(pTab)).FzName))
goto exit_drop_table
}
/* Generate code to remove the table from the schema table
** on disk.
*/
v = _sqlite3GetVdbe(tls, pParse)
if v != 0 {
_sqlite3BeginWriteOperation(tls, pParse, int32(1), iDb)
if !(isView != 0) {
_sqlite3ClearStatTables(tls, pParse, iDb, __ccgo_ts+13396, (*TTable)(unsafe.Pointer(pTab)).FzName)
_sqlite3FkDropTable(tls, pParse, pName, pTab)
}
_sqlite3CodeDropTable(tls, pParse, pTab, iDb, isView)
}
goto exit_drop_table
exit_drop_table:
;
_sqlite3SrcListDelete(tls, db, pName)
}
// C documentation
//
// /*
// ** This function is called to drop a trigger from the database schema.
// **
// ** This may be called directly from the parser and therefore identifies
// ** the trigger by name. The sqlite3DropTriggerPtr() routine does the
// ** same job as this routine except it takes a pointer to the trigger
// ** instead of the trigger name.
// **/
func _sqlite3DropTrigger(tls *libc.TLS, pParse uintptr, pName uintptr, noErr int32) {
bp := tls.Alloc(16)
defer tls.Free(16)
var db, pTrigger, zDb, zName uintptr
var i, j, v2 int32
_, _, _, _, _, _, _ = db, i, j, pTrigger, zDb, zName, v2
pTrigger = uintptr(0)
db = (*TParse)(unsafe.Pointer(pParse)).Fdb
if (*Tsqlite3)(unsafe.Pointer(db)).FmallocFailed != 0 {
goto drop_trigger_cleanup
}
if SQLITE_OK != _sqlite3ReadSchema(tls, pParse) {
goto drop_trigger_cleanup
}
zDb = *(*uintptr)(unsafe.Pointer(pName + 8 + 72))
zName = (*(*TSrcItem)(unsafe.Pointer(pName + 8))).FzName
i = OMIT_TEMPDB
for {
if !(i < (*Tsqlite3)(unsafe.Pointer(db)).FnDb) {
break
}
if i < int32(2) {
v2 = i ^ int32(1)
} else {
v2 = i
}
j = v2 /* Search TEMP before MAIN */
if zDb != 0 && _sqlite3DbIsNamed(tls, db, j, zDb) == 0 {
goto _1
}
pTrigger = _sqlite3HashFind(tls, (**(**TDb)(__ccgo_up((*Tsqlite3)(unsafe.Pointer(db)).FaDb + uintptr(j)*32))).FpSchema+56, zName)
if pTrigger != 0 {
break
}
goto _1
_1:
;
i = i + 1
}
if !(pTrigger != 0) {
if !(noErr != 0) {
_sqlite3ErrorMsg(tls, pParse, __ccgo_ts+22773, libc.VaList(bp+8, pName+8))
} else {
_sqlite3CodeVerifyNamedSchema(tls, pParse, zDb)
}
libc.SetBitFieldPtr16Uint32(pParse+40, libc.Uint32FromInt32(1), 8, 0x100)
goto drop_trigger_cleanup
}
_sqlite3DropTriggerPtr(tls, pParse, pTrigger)
goto drop_trigger_cleanup
drop_trigger_cleanup:
;
_sqlite3SrcListDelete(tls, db, pName)
}
// C documentation
//
// /*
// ** Drop a trigger given a pointer to that trigger.
// */
func _sqlite3DropTriggerPtr(tls *libc.TLS, pParse uintptr, pTrigger uintptr) {
bp := tls.Alloc(32)
defer tls.Free(32)
var code, iDb int32
var db, pTable, v, zDb, zTab, v1 uintptr
_, _, _, _, _, _, _, _ = code, db, iDb, pTable, v, zDb, zTab, v1
db = (*TParse)(unsafe.Pointer(pParse)).Fdb
iDb = _sqlite3SchemaToIndex(tls, (*TParse)(unsafe.Pointer(pParse)).Fdb, (*TTrigger)(unsafe.Pointer(pTrigger)).FpSchema)
pTable = _tableOfTrigger(tls, pTrigger)
if pTable != 0 {
code = int32(SQLITE_DROP_TRIGGER)
zDb = (**(**TDb)(__ccgo_up((*Tsqlite3)(unsafe.Pointer(db)).FaDb + uintptr(iDb)*32))).FzDbSName
if libc.Bool(!(libc.Int32FromInt32(OMIT_TEMPDB) != 0)) && iDb == int32(1) {
v1 = __ccgo_ts + 7112
} else {
v1 = __ccgo_ts + 6632
}
zTab = v1
if iDb == int32(1) {
code = int32(SQLITE_DROP_TEMP_TRIGGER)
}
if _sqlite3AuthCheck(tls, pParse, code, (*TTrigger)(unsafe.Pointer(pTrigger)).FzName, (*TTable)(unsafe.Pointer(pTable)).FzName, zDb) != 0 || _sqlite3AuthCheck(tls, pParse, int32(SQLITE_DELETE), zTab, uintptr(0), zDb) != 0 {
return
}
}
/* Generate code to destroy the database record of the trigger.
*/
v1 = _sqlite3GetVdbe(tls, pParse)
v = v1
if v1 != uintptr(0) {
_sqlite3NestedParse(tls, pParse, __ccgo_ts+22793, libc.VaList(bp+8, (**(**TDb)(__ccgo_up((*Tsqlite3)(unsafe.Pointer(db)).FaDb + uintptr(iDb)*32))).FzDbSName, (*TTrigger)(unsafe.Pointer(pTrigger)).FzName))
_sqlite3ChangeCookie(tls, pParse, iDb)
_sqlite3VdbeAddOp4(tls, v, int32(OP_DropTrigger), iDb, 0, 0, (*TTrigger)(unsafe.Pointer(pTrigger)).FzName, 0)
}
}
// C documentation
//
// /*
// ** 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(112)
defer tls.Free(112)
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 + 48)) |= 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 + 48)) |= 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 + 48)) |= uint32(TF_Strict)
ii = 0
for {
if !(ii < int32((*TTable)(unsafe.Pointer(p)).FnCol)) {
break
}
pCol = (*TTable)(unsafe.Pointer(p)).FaCol + uintptr(ii)*16
if int32(uint32(*(*uint8)(unsafe.Pointer(pCol + 8))&0xf0>>4)) == COLTYPE_CUSTOM {
if libc.Int32FromUint16((*TColumn)(unsafe.Pointer(pCol)).FcolFlags)&int32(COLFLAG_HASTYPE) != 0 {
_sqlite3ErrorMsg(tls, pParse, __ccgo_ts+14744, libc.VaList(bp+48, (*TTable)(unsafe.Pointer(p)).FzName, (*TColumn)(unsafe.Pointer(pCol)).FzCnName, _sqlite3ColumnType(tls, pCol, __ccgo_ts+1702)))
} else {
_sqlite3ErrorMsg(tls, pParse, __ccgo_ts+14777, libc.VaList(bp+48, (*TTable)(unsafe.Pointer(p)).FzName, (*TColumn)(unsafe.Pointer(pCol)).FzCnName))
}
return
} else {
if int32(uint32(*(*uint8)(unsafe.Pointer(pCol + 8))&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 + 8))&0xf>>0)) == OE_None {
libc.SetBitFieldPtr8Uint32(pCol+8, libc.Uint32FromInt32(OE_Abort), 0, 0xf)
**(**Tu32)(__ccgo_up(p + 48)) |= 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+14804, 0)
return
}
if (*TTable)(unsafe.Pointer(p)).FtabFlags&uint32(TF_HasPrimaryKey) == uint32(0) {
_sqlite3ErrorMsg(tls, pParse, __ccgo_ts+14854, libc.VaList(bp+48, (*TTable)(unsafe.Pointer(p)).FzName))
return
}
**(**Tu32)(__ccgo_up(p + 48)) |= 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)*16))).FcolFlags)
if colFlags&uint32(COLFLAG_GENERATED) != uint32(0) {
pX = _sqlite3ColumnExpr(tls, p, (*TTable)(unsafe.Pointer(p)).FaCol+uintptr(ii1)*16)
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)*16, _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+14886, 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 + 9725
zType2 = __ccgo_ts + 14930
} else {
/* A view */
zType = __ccgo_ts + 11463
zType2 = __ccgo_ts + 14936
}
/* 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 + 56
v4 = *(*int32)(unsafe.Pointer(v5))
*(*int32)(unsafe.Pointer(v5)) = *(*int32)(unsafe.Pointer(v5)) + 1
iCsr = v4
v5 = pParse + 60
*(*int32)(unsafe.Pointer(v5)) = *(*int32)(unsafe.Pointer(v5)) + 1
v4 = *(*int32)(unsafe.Pointer(v5))
regYield = v4
v5 = pParse + 60
*(*int32)(unsafe.Pointer(v5)) = *(*int32)(unsafe.Pointer(v5)) + 1
v4 = *(*int32)(unsafe.Pointer(v5))
regRec = v4
v5 = pParse + 60
*(*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 + 256))).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 + 288
} else {
v5 = pEnd
}
pEnd2 = v5
n = int32(int64((*TToken)(unsafe.Pointer(pEnd2)).Fz) - int64((*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+14941, libc.VaList(bp+48, 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+14956, libc.VaList(bp+48, (**(**TDb)(__ccgo_up((*Tsqlite3)(unsafe.Pointer(db)).FaDb + uintptr(iDb)*32))).FzDbSName, zType, (*TTable)(unsafe.Pointer(p)).FzName, (*TTable)(unsafe.Pointer(p)).FzName, (*(*struct {
FaddrCrTab int32
FregRowid int32
FregRoot int32
FconstraintName TToken
})(unsafe.Pointer(pParse + 256))).FregRoot, zStmt, (*(*struct {
FaddrCrTab int32
FregRowid int32
FregRoot int32
FconstraintName TToken
})(unsafe.Pointer(pParse + 256))).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)*32
if (*TSchema)(unsafe.Pointer((*TDb)(unsafe.Pointer(pDb)).FpSchema)).FpSeqTab == uintptr(0) {
_sqlite3NestedParse(tls, pParse, __ccgo_ts+15054, libc.VaList(bp+48, (*TDb)(unsafe.Pointer(pDb)).FzDbSName))
}
}
/* Reparse everything to update our internal data structures */
_sqlite3VdbeAddParseSchemaOp(tls, v, iDb, _sqlite3MPrintf(tls, db, __ccgo_ts+15096, libc.VaList(bp+48, (*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+15130, libc.VaList(bp+48, (**(**TDb)(__ccgo_up((*Tsqlite3)(unsafe.Pointer(db)).FaDb + uintptr(iDb)*32))).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 + 44)) |= 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+10247) == 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 + 64))).FaddColOffset = int32(13) + int32(int64((*TToken)(unsafe.Pointer(pCons)).Fz)-int64((*TParse)(unsafe.Pointer(pParse)).FsNameToken.Fz))
}
}
// C documentation
//
// /*
// ** Generate VDBE code for a COMMIT or ROLLBACK statement.
// ** Code for ROLLBACK is generated if eType==TK_ROLLBACK. Otherwise
// ** code is generated for a COMMIT.
// */
func _sqlite3EndTransaction(tls *libc.TLS, pParse uintptr, eType int32) {
var isRollback int32
var v, v1 uintptr
_, _, _ = isRollback, v, v1
isRollback = libc.BoolInt32(eType == int32(TK_ROLLBACK))
if isRollback != 0 {
v1 = __ccgo_ts + 16457
} else {
v1 = __ccgo_ts + 16466
}
if _sqlite3AuthCheck(tls, pParse, int32(SQLITE_TRANSACTION), v1, uintptr(0), uintptr(0)) != 0 {
return
}
v = _sqlite3GetVdbe(tls, pParse)
if v != 0 {
_sqlite3VdbeAddOp2(tls, v, int32(OP_AutoCommit), int32(1), isRollback)
}
}
// C documentation
//
// /*
// ** Return a static string that describes the kind of error specified in the
// ** argument.
// */
func _sqlite3ErrStr(tls *libc.TLS, rc int32) (r uintptr) {
var zErr uintptr
_ = zErr
zErr = __ccgo_ts + 26225
switch rc {
case libc.Int32FromInt32(SQLITE_ABORT) | libc.Int32FromInt32(2)<= 0 && rc < libc.Int32FromUint64(libc.Uint64FromInt64(232)/libc.Uint64FromInt64(8)) && _aMsg[rc] != uintptr(0) {
zErr = _aMsg[rc]
}
break
}
return zErr
}
// C documentation
//
// /*
// ** Write code that will raise an error if the table described by
// ** zDb and zTab is not empty.
// */
func _sqlite3ErrorIfNotEmpty(tls *libc.TLS, pParse uintptr, zDb uintptr, zTab uintptr, zErr uintptr) {
bp := tls.Alloc(32)
defer tls.Free(32)
_sqlite3NestedParse(tls, pParse, __ccgo_ts+10599, libc.VaList(bp+8, zErr, zDb, zTab))
}
// C documentation
//
// /*
// ** The SrcItem structure passed as the second argument represents a
// ** sub-query in the FROM clause of a SELECT statement. This function
// ** allocates and populates the SrcItem.pTab object. If successful,
// ** SQLITE_OK is returned. Otherwise, if an OOM error is encountered,
// ** SQLITE_NOMEM.
// */
func _sqlite3ExpandSubquery(tls *libc.TLS, pParse uintptr, pFrom uintptr) (r int32) {
bp := tls.Alloc(16)
defer tls.Free(16)
var pSel, pTab, v1 uintptr
var v2 int32
_, _, _, _ = pSel, pTab, v1, v2
pSel = (*TSubquery)(unsafe.Pointer(*(*uintptr)(unsafe.Pointer(pFrom + 72)))).FpSelect
v1 = _sqlite3DbMallocZero(tls, (*TParse)(unsafe.Pointer(pParse)).Fdb, uint64(120))
pTab = v1
(*TSrcItem)(unsafe.Pointer(pFrom)).FpSTab = v1
if pTab == uintptr(0) {
return int32(SQLITE_NOMEM)
}
(*TTable)(unsafe.Pointer(pTab)).FnTabRef = uint32(1)
if (*TSrcItem)(unsafe.Pointer(pFrom)).FzAlias != 0 {
(*TTable)(unsafe.Pointer(pTab)).FzName = _sqlite3DbStrDup(tls, (*TParse)(unsafe.Pointer(pParse)).Fdb, (*TSrcItem)(unsafe.Pointer(pFrom)).FzAlias)
} else {
(*TTable)(unsafe.Pointer(pTab)).FzName = _sqlite3MPrintf(tls, (*TParse)(unsafe.Pointer(pParse)).Fdb, __ccgo_ts+21646, libc.VaList(bp+8, pFrom))
}
for (*TSelect)(unsafe.Pointer(pSel)).FpPrior != 0 {
pSel = (*TSelect)(unsafe.Pointer(pSel)).FpPrior
}
_sqlite3ColumnsFromExprList(tls, pParse, (*TSelect)(unsafe.Pointer(pSel)).FpEList, pTab+54, pTab+8)
(*TTable)(unsafe.Pointer(pTab)).FiPKey = int16(-int32(1))
(*TTable)(unsafe.Pointer(pTab)).FeTabType = uint8(TABTYP_VIEW)
(*TTable)(unsafe.Pointer(pTab)).FnRowLogEst = int16(200)
/* The usual case - do not allow ROWID on a subquery */
**(**Tu32)(__ccgo_up(pTab + 48)) |= libc.Uint32FromInt32(libc.Int32FromInt32(TF_Ephemeral) | libc.Int32FromInt32(TF_NoVisibleRowid))
if (*TParse)(unsafe.Pointer(pParse)).FnErr != 0 {
v2 = int32(SQLITE_ERROR)
} else {
v2 = SQLITE_OK
}
return v2
}
// C documentation
//
// /*
// ** Attach an ORDER BY clause to a function call.
// **
// ** functionname( arguments ORDER BY sortlist )
// ** \_____________________/ \______/
// ** pExpr pOrderBy
// **
// ** The ORDER BY clause is inserted into a new Expr node of type TK_ORDER
// ** and added to the Expr.pLeft field of the parent TK_FUNCTION node.
// */
func _sqlite3ExprAddFunctionOrderBy(tls *libc.TLS, pParse uintptr, pExpr uintptr, pOrderBy uintptr) {
var db, pOB uintptr
_, _ = db, pOB
db = (*TParse)(unsafe.Pointer(pParse)).Fdb
if pOrderBy == uintptr(0) {
return
}
if pExpr == uintptr(0) {
_sqlite3ExprListDelete(tls, db, pOrderBy)
return
}
if *(*uintptr)(unsafe.Pointer(pExpr + 32)) == uintptr(0) || (*TExprList)(unsafe.Pointer(*(*uintptr)(unsafe.Pointer(pExpr + 32)))).FnExpr == 0 {
/* Ignore ORDER BY on zero-argument aggregates */
_sqlite3ParserAddCleanup(tls, pParse, __ccgo_fp(_sqlite3ExprListDeleteGeneric), pOrderBy)
return
}
if (*TExpr)(unsafe.Pointer(pExpr)).Fflags&libc.Uint32FromInt32(libc.Int32FromInt32(EP_WinFunc)) != uint32(0) && libc.Int32FromUint8((*TWindow)(unsafe.Pointer(*(*uintptr)(unsafe.Pointer(pExpr + 64)))).FeFrmType) != int32(TK_FILTER) {
_sqlite3ExprOrderByAggregateError(tls, pParse, pExpr)
_sqlite3ExprListDelete(tls, db, pOrderBy)
return
}
if (*TExprList)(unsafe.Pointer(pOrderBy)).FnExpr > **(**int32)(__ccgo_up(db + 136 + 2*4)) {
_sqlite3ErrorMsg(tls, pParse, __ccgo_ts+7973, 0)
_sqlite3ExprListDelete(tls, db, pOrderBy)
return
}
pOB = _sqlite3ExprAlloc(tls, db, int32(TK_ORDER), uintptr(0), 0)
if pOB == uintptr(0) {
_sqlite3ExprListDelete(tls, db, pOrderBy)
return
}
*(*uintptr)(unsafe.Pointer(pOB + 32)) = pOrderBy
(*TExpr)(unsafe.Pointer(pExpr)).FpLeft = pOB
**(**Tu32)(__ccgo_up(pOB + 4)) |= libc.Uint32FromInt32(libc.Int32FromInt32(EP_FullSize))
}
// C documentation
//
// /*
// ** This routine is the core allocator for Expr nodes.
// **
// ** Construct a new expression node and return a pointer to it. Memory
// ** for this node and for the pToken argument is a single allocation
// ** obtained from sqlite3DbMalloc(). The calling function
// ** is responsible for making sure the node eventually gets freed.
// **
// ** If dequote is true, then the token (if it exists) is dequoted.
// ** If dequote is false, no dequoting is performed. The deQuote
// ** parameter is ignored if pToken is NULL or if the token does not
// ** appear to be quoted. If the quotes were of the form "..." (double-quotes)
// ** then the EP_DblQuoted flag is set on the expression node.
// **
// ** Special case (tag-20240227-a): If op==TK_INTEGER and pToken points to
// ** a string that can be translated into a 32-bit integer, then the token is
// ** not stored in u.zToken. Instead, the integer values is written
// ** into u.iValue and the EP_IntValue flag is set. No extra storage
// ** is allocated to hold the integer text and the dequote flag is ignored.
// ** See also tag-20240227-b.
// */
func _sqlite3ExprAlloc(tls *libc.TLS, db uintptr, op int32, pToken uintptr, dequote int32) (r uintptr) {
var nExtra int32
var pNew uintptr
var v1 uint32
_, _, _ = nExtra, pNew, v1
if pToken != 0 {
v1 = (*TToken)(unsafe.Pointer(pToken)).Fn + uint32(1)
} else {
v1 = uint32(0)
}
nExtra = libc.Int32FromUint32(v1)
pNew = _sqlite3DbMallocRawNN(tls, db, uint64(uint64(72)+libc.Uint64FromInt32(nExtra)))
if pNew != 0 {
libc.X__builtin___memset_chk(tls, pNew, 0, uint64(72), ^t__predefined_size_t(0))
(*TExpr)(unsafe.Pointer(pNew)).Fop = libc.Uint8FromInt32(op)
(*TExpr)(unsafe.Pointer(pNew)).FiAgg = int16(-int32(1))
if nExtra != 0 {
*(*uintptr)(unsafe.Pointer(pNew + 8)) = pNew + 1*72
if (*TToken)(unsafe.Pointer(pToken)).Fn != 0 {
libc.X__builtin___memcpy_chk(tls, *(*uintptr)(unsafe.Pointer(pNew + 8)), (*TToken)(unsafe.Pointer(pToken)).Fz, uint64((*TToken)(unsafe.Pointer(pToken)).Fn), ^t__predefined_size_t(0))
}
**(**int8)(__ccgo_up(*(*uintptr)(unsafe.Pointer(pNew + 8)) + uintptr((*TToken)(unsafe.Pointer(pToken)).Fn))) = 0
if dequote != 0 && libc.Int32FromUint8(_sqlite3CtypeMap[libc.Uint8FromInt8(**(**int8)(__ccgo_up(*(*uintptr)(unsafe.Pointer(pNew + 8)))))])&int32(0x80) != 0 {
_sqlite3DequoteExpr(tls, pNew)
}
}
(*TExpr)(unsafe.Pointer(pNew)).FnHeight = int32(1)
}
return pNew
}
// 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 + 304
*(*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 + 136 + 9*4))) {
_sqlite3ErrorMsg(tls, pParse, __ccgo_ts+8407, libc.VaList(bp+16, **(**int32)(__ccgo_up(db + 136 + 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 + 304
*(*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 + 136 + 9*4)) {
_sqlite3ErrorMsg(tls, pParse, __ccgo_ts+8450, 0)
_sqlite3RecordErrorOffsetOfExpr(tls, (*TParse)(unsafe.Pointer(pParse)).Fdb, pExpr)
}
}
// C documentation
//
// /*
// ** Return TRUE if expression pExpr is able to return a subtype.
// **
// ** A TRUE return does not guarantee that a subtype will be returned.
// ** It only indicates that a subtype return is possible. False positives
// ** are acceptable as they only disable an optimization. False negatives,
// ** on the other hand, can lead to incorrect answers.
// */
func _sqlite3ExprCanReturnSubtype(tls *libc.TLS, pParse uintptr, pExpr uintptr) (r int32) {
bp := tls.Alloc(48)
defer tls.Free(48)
var _ /* w at bp+0 */ TWalker
libc.X__builtin___memset_chk(tls, bp, 0, uint64(48), ^t__predefined_size_t(0))
(**(**TWalker)(__ccgo_up(bp))).FpParse = pParse
(**(**TWalker)(__ccgo_up(bp))).FxExprCallback = __ccgo_fp(_exprNodeCanReturnSubtype)
_sqlite3WalkExpr(tls, bp, pExpr)
return libc.Int32FromUint16((**(**TWalker)(__ccgo_up(bp))).FeCode)
}
// C documentation
//
// /*
// ** Check that argument nHeight is less than or equal to the maximum
// ** expression depth allowed. If it is not, leave an error message in
// ** pParse.
// */
func _sqlite3ExprCheckHeight(tls *libc.TLS, pParse uintptr, nHeight int32) (r int32) {
bp := tls.Alloc(16)
defer tls.Free(16)
var mxHeight, rc int32
_, _ = mxHeight, rc
rc = SQLITE_OK
mxHeight = **(**int32)(__ccgo_up((*TParse)(unsafe.Pointer(pParse)).Fdb + 136 + 3*4))
if nHeight > mxHeight {
_sqlite3ErrorMsg(tls, pParse, __ccgo_ts+8209, libc.VaList(bp+8, mxHeight))
rc = int32(SQLITE_ERROR)
}
return rc
}
// C documentation
//
// /*
// ** Generate code to extract the value of the iCol-th column of a table.
// */
func _sqlite3ExprCodeGetColumnOfTable(tls *libc.TLS, v uintptr, pTab uintptr, iTabCur int32, iCol int32, regOut int32) {
bp := tls.Alloc(16)
defer tls.Free(16)
var op, savedSelfTab, x int32
var pCol, pParse, v1 uintptr
_, _, _, _, _, _ = op, pCol, pParse, savedSelfTab, x, v1
if iCol < 0 || iCol == int32((*TTable)(unsafe.Pointer(pTab)).FiPKey) {
_sqlite3VdbeAddOp2(tls, v, int32(OP_Rowid), iTabCur, regOut)
} else {
if libc.Int32FromUint8((*TTable)(unsafe.Pointer(pTab)).FeTabType) == int32(TABTYP_VTAB) {
op = int32(OP_VColumn)
x = iCol
} else {
v1 = (*TTable)(unsafe.Pointer(pTab)).FaCol + uintptr(iCol)*16
pCol = v1
if libc.Int32FromUint16((*TColumn)(unsafe.Pointer(v1)).FcolFlags)&int32(COLFLAG_VIRTUAL) != 0 {
pParse = _sqlite3VdbeParser(tls, v)
if libc.Int32FromUint16((*TColumn)(unsafe.Pointer(pCol)).FcolFlags)&int32(COLFLAG_BUSY) != 0 {
_sqlite3ErrorMsg(tls, pParse, __ccgo_ts+8800, libc.VaList(bp+8, (*TColumn)(unsafe.Pointer(pCol)).FzCnName))
} else {
savedSelfTab = (*TParse)(unsafe.Pointer(pParse)).FiSelfTab
v1 = pCol + 14
*(*Tu16)(unsafe.Pointer(v1)) = Tu16(int32(*(*Tu16)(unsafe.Pointer(v1))) | libc.Int32FromInt32(COLFLAG_BUSY))
(*TParse)(unsafe.Pointer(pParse)).FiSelfTab = iTabCur + int32(1)
_sqlite3ExprCodeGeneratedColumn(tls, pParse, pTab, pCol, regOut)
(*TParse)(unsafe.Pointer(pParse)).FiSelfTab = savedSelfTab
v1 = pCol + 14
*(*Tu16)(unsafe.Pointer(v1)) = Tu16(int32(*(*Tu16)(unsafe.Pointer(v1))) & ^libc.Int32FromInt32(COLFLAG_BUSY))
}
return
} else {
if !((*TTable)(unsafe.Pointer(pTab)).FtabFlags&libc.Uint32FromInt32(TF_WithoutRowid) == libc.Uint32FromInt32(0)) {
x = _sqlite3TableColumnToIndex(tls, _sqlite3PrimaryKeyIndex(tls, pTab), iCol)
op = int32(OP_Column)
} else {
x = int32(_sqlite3TableColumnToStorage(tls, pTab, int16(iCol)))
op = int32(OP_Column)
}
}
}
_sqlite3VdbeAddOp3(tls, v, op, iTabCur, x, regOut)
_sqlite3ColumnDefault(tls, v, pTab, iCol, regOut)
}
}
// C documentation
//
// /*
// ** 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(192)
defer tls.Free(192)
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+88 */ 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)*32
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)*16))).Faffinity) == int32(SQLITE_AFF_REAL) {
_sqlite3VdbeAddOp1(tls, v, int32(OP_RealAffinity), target)
}
}
}
return target
} else {
if *(*uintptr)(unsafe.Pointer(pExpr + 64)) == 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, *(*uintptr)(unsafe.Pointer(pExpr + 64)), 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 = *(*uintptr)(unsafe.Pointer(pExpr + 64))
if iCol < 0 {
return -int32(1) - (*TParse)(unsafe.Pointer(pParse)).FiSelfTab
}
pCol1 = (*TTable)(unsafe.Pointer(pTab1)).FaCol + uintptr(iCol)*16
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+8800, libc.VaList(bp+168, (*TColumn)(unsafe.Pointer(pCol1)).FzCnName))
return 0
}
v3 = pCol1 + 14
*(*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 + 14
*(*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, *(*uintptr)(unsafe.Pointer(pExpr + 64)), 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+8861, libc.VaList(bp+168, 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(pExpr + 64)))).FregResult
}
if int32(Tbft(*(*uint16)(unsafe.Pointer(pParse + 40))&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 + 32))
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+8888, libc.VaList(bp+168, pExpr))
break
}
if (*TFuncDef)(unsafe.Pointer(pDef)).FfuncFlags&uint32(SQLITE_FUNC_INLINE) != uint32(0) && pFarg != uintptr(0) {
return _exprCodeInlineFunction(tls, pParse, pFarg, int32(int64((*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)*32))).FpExpr) != 0 {
constMask = constMask | libc.Uint32FromInt32(1)<= 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*32))).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 + 32)))).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+8473, libc.VaList(bp+168, (*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 = *(*uintptr)(unsafe.Pointer(pExpr + 64))
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)*16))).Faffinity) == int32(SQLITE_AFF_REAL) {
_sqlite3VdbeAddOp1(tls, v, int32(OP_RealAffinity), target)
}
case int32(TK_VECTOR):
_sqlite3ErrorMsg(tls, pParse, __ccgo_ts+7256, 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 + 40)) & 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)*32))).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+40, libc.Uint32FromInt32(0), 7, 0x80) /* note (1) above */
_sqlite3ExprCode(tls, pParse, (*TExpr)(unsafe.Pointer(pExpr)).FpLeft, target)
libc.SetBitFieldPtr16Uint32(pParse+40, 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 + 32))
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.X__builtin___memset_chk(tls, bp+88, 0, uint64(72), ^t__predefined_size_t(0))
(**(**TExpr)(__ccgo_up(bp + 88))).Fop = uint8(TK_EQ)
(**(**TExpr)(__ccgo_up(bp + 88))).FpLeft = pDel
pTest = bp + 88
/* 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 + 88))).FpRight = (**(**TExprList_item)(__ccgo_up(aListelem + uintptr(i1)*32))).FpExpr
} else {
pTest = (**(**TExprList_item)(__ccgo_up(aListelem + uintptr(i1)*32))).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))*32))).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))*32))).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+8912, 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)< **(**int32)(__ccgo_up((*TParse)(unsafe.Pointer(pParse)).Fdb + 136 + 6*4)) && !((*TParse)(unsafe.Pointer(pParse)).Fnested != 0) {
_sqlite3ErrorMsg(tls, pParse, __ccgo_ts+8303, libc.VaList(bp+8, pToken))
}
*(*uintptr)(unsafe.Pointer(pNew + 32)) = pList
**(**Tu32)(__ccgo_up(pNew + 4)) |= libc.Uint32FromInt32(libc.Int32FromInt32(EP_HasFunc))
_sqlite3ExprSetHeightAndFlags(tls, pParse, pNew)
if eDistinct == int32(SF_Distinct) {
**(**Tu32)(__ccgo_up(pNew + 4)) |= libc.Uint32FromInt32(libc.Int32FromInt32(EP_Distinct))
}
return pNew
}
// C documentation
//
// /*
// ** Check to see if a function is usable according to current access
// ** rules:
// **
// ** SQLITE_FUNC_DIRECT - Only usable from top-level SQL
// **
// ** SQLITE_FUNC_UNSAFE - Usable if TRUSTED_SCHEMA or from
// ** top-level SQL
// **
// ** If the function is not usable, create an error.
// */
func _sqlite3ExprFunctionUsable(tls *libc.TLS, pParse uintptr, pExpr uintptr, pDef uintptr) {
bp := tls.Alloc(16)
defer tls.Free(16)
if (*TExpr)(unsafe.Pointer(pExpr)).Fflags&libc.Uint32FromInt32(libc.Int32FromInt32(EP_FromDDL)) != uint32(0) || libc.Int32FromUint8((*TParse)(unsafe.Pointer(pParse)).FprepFlags)&int32(SQLITE_PREPARE_FROM_DDL) != 0 {
if (*TFuncDef)(unsafe.Pointer(pDef)).FfuncFlags&uint32(SQLITE_FUNC_DIRECT) != uint32(0) || (*Tsqlite3)(unsafe.Pointer((*TParse)(unsafe.Pointer(pParse)).Fdb)).Fflags&uint64(SQLITE_TrustedSchema) == uint64(0) {
/* Functions prohibited in triggers and views if:
** (1) tagged with SQLITE_DIRECTONLY
** (2) not tagged with SQLITE_INNOCUOUS (which means it
** is tagged with SQLITE_FUNC_UNSAFE) and
** SQLITE_DBCONFIG_TRUSTED_SCHEMA is off (meaning
** that the schema is possibly tainted).
*/
_sqlite3ErrorMsg(tls, pParse, __ccgo_ts+8387, libc.VaList(bp+8, pExpr))
}
}
}
// C documentation
//
// /*
// ** Allocate an expression for a 32-bit signed integer literal.
// */
func _sqlite3ExprInt32(tls *libc.TLS, db uintptr, iVal int32) (r uintptr) {
var pNew uintptr
var v1 int32
_, _ = pNew, v1
pNew = _sqlite3DbMallocRawNN(tls, db, uint64(72))
if pNew != 0 {
libc.X__builtin___memset_chk(tls, pNew, 0, uint64(72), ^t__predefined_size_t(0))
(*TExpr)(unsafe.Pointer(pNew)).Fop = uint8(TK_INTEGER)
(*TExpr)(unsafe.Pointer(pNew)).FiAgg = int16(-int32(1))
if iVal != 0 {
v1 = int32(EP_IsTrue)
} else {
v1 = int32(EP_IsFalse)
}
(*TExpr)(unsafe.Pointer(pNew)).Fflags = libc.Uint32FromInt32(libc.Int32FromInt32(EP_IntValue) | libc.Int32FromInt32(EP_Leaf) | v1)
*(*int32)(unsafe.Pointer(&(*TExpr)(unsafe.Pointer(pNew)).Fu)) = iVal
(*TExpr)(unsafe.Pointer(pNew)).FnHeight = int32(1)
}
return pNew
}
// C documentation
//
// /*
// ** pColumns and pExpr form a vector assignment which is part of the SET
// ** clause of an UPDATE statement. Like this:
// **
// ** (a,b,c) = (expr1,expr2,expr3)
// ** Or: (a,b,c) = (SELECT x,y,z FROM ....)
// **
// ** For each term of the vector assignment, append new entries to the
// ** expression list pList. In the case of a subquery on the RHS, append
// ** TK_SELECT_COLUMN expressions.
// */
func _sqlite3ExprListAppendVector(tls *libc.TLS, pParse uintptr, pList uintptr, pColumns uintptr, pExpr uintptr) (r uintptr) {
bp := tls.Alloc(32)
defer tls.Free(32)
var db, pFirst, pSubExpr uintptr
var i, iFirst, n, v1 int32
var v3 bool
_, _, _, _, _, _, _, _ = db, i, iFirst, n, pFirst, pSubExpr, v1, v3
db = (*TParse)(unsafe.Pointer(pParse)).Fdb
if pList != 0 {
v1 = (*TExprList)(unsafe.Pointer(pList)).FnExpr
} else {
v1 = 0
}
iFirst = v1
/* pColumns can only be NULL due to an OOM but an OOM will cause an
** exit prior to this routine being invoked */
if pColumns == uintptr(0) {
goto vector_append_error
}
if pExpr == uintptr(0) {
goto vector_append_error
}
/* If the RHS is a vector, then we can immediately check to see that
** the size of the RHS and LHS match. But if the RHS is a SELECT,
** wildcards ("*") in the result set of the SELECT must be expanded before
** we can do the size check, so defer the size check until code generation.
*/
if v3 = libc.Int32FromUint8((*TExpr)(unsafe.Pointer(pExpr)).Fop) != int32(TK_SELECT); v3 {
v1 = _sqlite3ExprVectorSize(tls, pExpr)
n = v1
}
if v3 && (*TIdList)(unsafe.Pointer(pColumns)).FnId != v1 {
_sqlite3ErrorMsg(tls, pParse, __ccgo_ts+8473, libc.VaList(bp+8, (*TIdList)(unsafe.Pointer(pColumns)).FnId, n))
goto vector_append_error
}
i = 0
for {
if !(i < (*TIdList)(unsafe.Pointer(pColumns)).FnId) {
break
}
pSubExpr = _sqlite3ExprForVectorField(tls, pParse, pExpr, i, (*TIdList)(unsafe.Pointer(pColumns)).FnId)
if pSubExpr == uintptr(0) {
goto _4
}
pList = _sqlite3ExprListAppend(tls, pParse, pList, pSubExpr)
if pList != 0 {
(*(*TExprList_item)(unsafe.Pointer(pList + 8 + uintptr((*TExprList)(unsafe.Pointer(pList)).FnExpr-int32(1))*32))).FzEName = (*(*TIdList_item)(unsafe.Pointer(pColumns + 8 + uintptr(i)*8))).FzName
(*(*TIdList_item)(unsafe.Pointer(pColumns + 8 + uintptr(i)*8))).FzName = uintptr(0)
}
goto _4
_4:
;
i = i + 1
}
if !((*Tsqlite3)(unsafe.Pointer(db)).FmallocFailed != 0) && libc.Int32FromUint8((*TExpr)(unsafe.Pointer(pExpr)).Fop) == int32(TK_SELECT) && pList != uintptr(0) {
pFirst = (*(*TExprList_item)(unsafe.Pointer(pList + 8 + uintptr(iFirst)*32))).FpExpr
/* Store the SELECT statement in pRight so it will be deleted when
** sqlite3ExprListDelete() is called */
(*TExpr)(unsafe.Pointer(pFirst)).FpRight = pExpr
pExpr = uintptr(0)
/* Remember the size of the LHS in iTable so that we can check that
** the RHS and LHS sizes match during code generation. */
(*TExpr)(unsafe.Pointer(pFirst)).FiTable = (*TIdList)(unsafe.Pointer(pColumns)).FnId
}
goto vector_append_error
vector_append_error:
;
_sqlite3ExprUnmapAndDelete(tls, pParse, pExpr)
_sqlite3IdListDelete(tls, db, pColumns)
return pList
}
// C documentation
//
// /*
// ** If the expression list pEList contains more than iLimit elements,
// ** leave an error message in pParse.
// */
func _sqlite3ExprListCheckLength(tls *libc.TLS, pParse uintptr, pEList uintptr, zObject uintptr) {
bp := tls.Alloc(16)
defer tls.Free(16)
var mx int32
_ = mx
mx = **(**int32)(__ccgo_up((*TParse)(unsafe.Pointer(pParse)).Fdb + 136 + 2*4))
if pEList != 0 && (*TExprList)(unsafe.Pointer(pEList)).FnExpr > mx {
_sqlite3ErrorMsg(tls, pParse, __ccgo_ts+8503, libc.VaList(bp+8, zObject))
}
}
// C documentation
//
// /*
// ** Expression list pEList is a list of vector values. This function
// ** converts the contents of pEList to a VALUES(...) Select statement
// ** returning 1 row for each element of the list. For example, the
// ** expression list:
// **
// ** ( (1,2), (3,4) (5,6) )
// **
// ** is translated to the equivalent of:
// **
// ** VALUES(1,2), (3,4), (5,6)
// **
// ** Each of the vector values in pEList must contain exactly nElem terms.
// ** If a list element that is not a vector or does not contain nElem terms,
// ** an error message is left in pParse.
// **
// ** This is used as part of processing IN(...) expressions with a list
// ** of vectors on the RHS. e.g. "... IN ((1,2), (3,4), (5,6))".
// */
func _sqlite3ExprListToValues(tls *libc.TLS, pParse uintptr, nElem int32, pEList uintptr) (r uintptr) {
bp := tls.Alloc(32)
defer tls.Free(32)
var ii, nExprElem int32
var pExpr, pRet, pSel, v2 uintptr
_, _, _, _, _, _ = ii, nExprElem, pExpr, pRet, pSel, v2
pRet = uintptr(0)
ii = 0
for {
if !(ii < (*TExprList)(unsafe.Pointer(pEList)).FnExpr) {
break
}
pExpr = (*(*TExprList_item)(unsafe.Pointer(pEList + 8 + uintptr(ii)*32))).FpExpr
if libc.Int32FromUint8((*TExpr)(unsafe.Pointer(pExpr)).Fop) == int32(TK_VECTOR) {
nExprElem = (*TExprList)(unsafe.Pointer(*(*uintptr)(unsafe.Pointer(pExpr + 32)))).FnExpr
} else {
nExprElem = int32(1)
}
if nExprElem != nElem {
if nExprElem > int32(1) {
v2 = __ccgo_ts + 8257
} else {
v2 = __ccgo_ts + 1702
}
_sqlite3ErrorMsg(tls, pParse, __ccgo_ts+8259, libc.VaList(bp+8, nExprElem, v2, nElem))
break
}
pSel = _sqlite3SelectNew(tls, pParse, *(*uintptr)(unsafe.Pointer(pExpr + 32)), uintptr(0), uintptr(0), uintptr(0), uintptr(0), uintptr(0), uint32(SF_Values), uintptr(0))
*(*uintptr)(unsafe.Pointer(pExpr + 32)) = uintptr(0)
if pSel != 0 {
if pRet != 0 {
(*TSelect)(unsafe.Pointer(pSel)).Fop = uint8(TK_ALL)
(*TSelect)(unsafe.Pointer(pSel)).FpPrior = pRet
}
pRet = pSel
}
goto _1
_1:
;
ii = ii + 1
}
if pRet != 0 && (*TSelect)(unsafe.Pointer(pRet)).FpPrior != 0 {
**(**Tu32)(__ccgo_up(pRet + 4)) |= uint32(SF_MultiValue)
}
_sqlite3ExprListDelete(tls, (*TParse)(unsafe.Pointer(pParse)).Fdb, pEList)
return pRet
}
// C documentation
//
// /*
// ** Make arrangements to invoke OP_Null on a range of registers
// ** during initialization.
// */
func _sqlite3ExprNullRegisterRange(tls *libc.TLS, pParse uintptr, iReg int32, nReg int32) {
bp := tls.Alloc(80)
defer tls.Free(80)
var okConstFactor Tu8
var _ /* t at bp+0 */ TExpr
_ = okConstFactor
okConstFactor = libc.Uint8FromInt32(int32(Tbft(*(*uint16)(unsafe.Pointer(pParse + 40)) & 0x80 >> 7)))
libc.X__builtin___memset_chk(tls, bp, 0, uint64(72), ^t__predefined_size_t(0))
(**(**TExpr)(__ccgo_up(bp))).Fop = uint8(TK_NULLS)
*(*int32)(unsafe.Pointer(bp + 64)) = nReg
libc.SetBitFieldPtr16Uint32(pParse+40, libc.Uint32FromInt32(1), 7, 0x80)
_sqlite3ExprCodeRunJustOnce(tls, pParse, bp, iReg)
libc.SetBitFieldPtr16Uint32(pParse+40, uint32(okConstFactor), 7, 0x80)
}
// C documentation
//
// /*
// ** Report an error when attempting to use an ORDER BY clause within
// ** the arguments of a non-aggregate function.
// */
func _sqlite3ExprOrderByAggregateError(tls *libc.TLS, pParse uintptr, p uintptr) {
bp := tls.Alloc(16)
defer tls.Free(16)
_sqlite3ErrorMsg(tls, pParse, __ccgo_ts+8337, libc.VaList(bp+8, p))
}
// C documentation
//
// /*
// ** pExpr is a CHECK constraint on a row that is being UPDATE-ed. The
// ** only columns that are modified by the UPDATE are those for which
// ** aiChng[i]>=0, and also the ROWID is modified if chngRowid is true.
// **
// ** Return true if CHECK constraint pExpr uses any of the
// ** changing columns (or the rowid if it is changing). In other words,
// ** return true if this CHECK constraint must be validated for
// ** the new row in the UPDATE statement.
// **
// ** 2018-09-15: pExpr might also be an expression for an index-on-expressions.
// ** The operation of this routine is the same - return true if an only if
// ** the expression uses one or more of columns identified by the second and
// ** third arguments.
// */
func _sqlite3ExprReferencesUpdatedColumn(tls *libc.TLS, pExpr uintptr, aiChng uintptr, chngRowid int32) (r int32) {
bp := tls.Alloc(48)
defer tls.Free(48)
var v1 uintptr
var _ /* w at bp+0 */ TWalker
_ = v1
libc.X__builtin___memset_chk(tls, bp, 0, uint64(48), ^t__predefined_size_t(0))
(**(**TWalker)(__ccgo_up(bp))).FeCode = uint16(0)
(**(**TWalker)(__ccgo_up(bp))).FxExprCallback = __ccgo_fp(_checkConstraintExprNode)
*(*uintptr)(unsafe.Pointer(bp + 40)) = aiChng
_sqlite3WalkExpr(tls, bp, pExpr)
if !(chngRowid != 0) {
v1 = bp + 36
*(*Tu16)(unsafe.Pointer(v1)) = Tu16(int32(*(*Tu16)(unsafe.Pointer(v1))) & ^libc.Int32FromInt32(CKCNSTRNT_ROWID))
}
return libc.BoolInt32(libc.Int32FromUint16((**(**TWalker)(__ccgo_up(bp))).FeCode) != 0)
}
// C documentation
//
// /*
// ** Parameter zName points to a nul-terminated buffer containing the name
// ** of a database ("main", "temp" or the name of an attached db). This
// ** function returns the index of the named database in db->aDb[], or
// ** -1 if the named db cannot be found.
// */
func _sqlite3FindDbName(tls *libc.TLS, db uintptr, zName uintptr) (r int32) {
var i int32
var pDb uintptr
_, _ = i, pDb
i = -int32(1) /* Database number */
if zName != 0 {
i = (*Tsqlite3)(unsafe.Pointer(db)).FnDb - int32(1)
pDb = (*Tsqlite3)(unsafe.Pointer(db)).FaDb + uintptr(i)*32
for {
if !(i >= 0) {
break
}
if 0 == Xsqlite3_stricmp(tls, (*TDb)(unsafe.Pointer(pDb)).FzDbSName, zName) {
break
}
/* "main" is always an acceptable alias for the primary database
** even if it has been renamed using SQLITE_DBCONFIG_MAINDBNAME. */
if i == 0 && 0 == Xsqlite3_stricmp(tls, __ccgo_ts+7164, zName) {
break
}
goto _1
_1:
;
i = i - 1
pDb -= 32
}
}
return i
}
// C documentation
//
// /*
// ** Locate a user function given a name, a number of arguments and a flag
// ** indicating whether the function prefers UTF-16 over UTF-8. Return a
// ** pointer to the FuncDef structure that defines that function, or return
// ** NULL if the function does not exist.
// **
// ** If the createFlag argument is true, then a new (blank) FuncDef
// ** structure is created and liked into the "db" structure if a
// ** no matching function previously existed.
// **
// ** If nArg is -2, then the first valid function found is returned. A
// ** function is valid if xSFunc is non-zero. The nArg==(-2)
// ** case is used to see if zName is a valid function name for some number
// ** of arguments. If nArg is -2, then createFlag must be 0.
// **
// ** If createFlag is false, then a function with the required name and
// ** number of arguments may be returned even if the eTextRep flag does not
// ** match that requested.
// */
func _sqlite3FindFunction(tls *libc.TLS, db uintptr, zName uintptr, nArg int32, enc Tu8, createFlag Tu8) (r uintptr) {
var bestScore, h, nName, score, score1 int32
var p, pBest, pOther, z, v1 uintptr
var v2 bool
_, _, _, _, _, _, _, _, _, _, _ = bestScore, h, nName, p, pBest, pOther, score, score1, z, v1, v2 /* Iterator variable */
pBest = uintptr(0) /* Best match found so far */
bestScore = 0 /* Length of the name */
nName = _sqlite3Strlen30(tls, zName)
/* First search for a match amongst the application-defined functions.
*/
p = _sqlite3HashFind(tls, db+624, zName)
for p != 0 {
score = _matchQuality(tls, p, nArg, enc)
if score > bestScore {
pBest = p
bestScore = score
}
p = (*TFuncDef)(unsafe.Pointer(p)).FpNext
}
/* If no match is found, search the built-in functions.
**
** If the DBFLAG_PreferBuiltin flag is set, then search the built-in
** functions even if a prior app-defined function was found. And give
** priority to built-in functions.
**
** Except, if createFlag is true, that means that we are trying to
** install a new function. Whatever FuncDef structure is returned it will
** have fields overwritten with new information appropriate for the
** new function. But the FuncDefs for built-in functions are read-only.
** So we must not search for built-ins when creating a new function.
*/
if !(createFlag != 0) && (pBest == uintptr(0) || (*Tsqlite3)(unsafe.Pointer(db)).FmDbFlags&uint32(DBFLAG_PreferBuiltin) != uint32(0)) {
bestScore = 0
h = (libc.Int32FromUint8(_sqlite3UpperToLower[libc.Uint8FromInt8(**(**int8)(__ccgo_up(zName)))]) + nName) % int32(SQLITE_FUNC_HASH_SZ)
p = _sqlite3FunctionSearch(tls, h, zName)
for p != 0 {
score1 = _matchQuality(tls, p, nArg, enc)
if score1 > bestScore {
pBest = p
bestScore = score1
}
p = (*TFuncDef)(unsafe.Pointer(p)).FpNext
}
}
/* If the createFlag parameter is true and the search did not reveal an
** exact match for the name, number of arguments and encoding, then add a
** new entry to the hash table and return it.
*/
if v2 = createFlag != 0 && bestScore < int32(FUNC_PERFECT_MATCH); v2 {
v1 = _sqlite3DbMallocZero(tls, db, uint64(uint64(72)+libc.Uint64FromInt32(nName)+uint64(1)))
pBest = v1
}
if v2 && v1 != uintptr(0) {
(*TFuncDef)(unsafe.Pointer(pBest)).FzName = pBest + 1*72
(*TFuncDef)(unsafe.Pointer(pBest)).FnArg = libc.Int16FromUint16(libc.Uint16FromInt32(nArg))
(*TFuncDef)(unsafe.Pointer(pBest)).FfuncFlags = uint32(enc)
libc.X__builtin___memcpy_chk(tls, pBest+1*72, zName, libc.Uint64FromInt32(nName+int32(1)), ^t__predefined_size_t(0))
z = (*TFuncDef)(unsafe.Pointer(pBest)).FzName
for {
if !(**(**Tu8)(__ccgo_up(z)) != 0) {
break
}
**(**Tu8)(__ccgo_up(z)) = _sqlite3UpperToLower[**(**Tu8)(__ccgo_up(z))]
goto _3
_3:
;
z = z + 1
}
pOther = _sqlite3HashInsert(tls, db+624, (*TFuncDef)(unsafe.Pointer(pBest)).FzName, pBest)
if pOther == pBest {
_sqlite3DbFree(tls, db, pBest)
_sqlite3OomFault(tls, db)
return uintptr(0)
} else {
(*TFuncDef)(unsafe.Pointer(pBest)).FpNext = pOther
}
}
if pBest != 0 && ((*TFuncDef)(unsafe.Pointer(pBest)).FxSFunc != 0 || createFlag != 0) {
return pBest
}
return uintptr(0)
}
// 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 , ... FROM
// **
// ** 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 is a single INTEGER PRIMARY KEY column or an
// ** index can be found with the specified 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 + 56
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 + 32)))).FpEList
i = 0
for {
if !(i < (*TExprList)(unsafe.Pointer(pEList)).FnExpr) {
break
}
if _sqlite3ExprCanBeNull(tls, (*(*TExprList_item)(unsafe.Pointer(pEList + 8 + uintptr(i)*32))).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 . */
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+8555, 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)*32))).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.Int32FromUint64(libc.Uint64FromInt64(8)*libc.Uint64FromInt32(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)*32))).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)*8))) != 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)<= (*Tsqlite3)(unsafe.Pointer(db)).FnDb {
/* No match against the official names. But always match "main"
** to schema 0 as a legacy fallback. */
if _sqlite3StrICmp(tls, zDatabase, __ccgo_ts+7164) == 0 {
i = 0
} else {
return uintptr(0)
}
}
p = _sqlite3HashFind(tls, (**(**TDb)(__ccgo_up((*Tsqlite3)(unsafe.Pointer(db)).FaDb + uintptr(i)*32))).FpSchema+8, zName)
if p == uintptr(0) && Xsqlite3_strnicmp(tls, zName, __ccgo_ts+7104, int32(7)) == 0 {
if i == int32(1) {
if _sqlite3StrICmp(tls, zName+uintptr(7), __ccgo_ts+7131+7) == 0 || _sqlite3StrICmp(tls, zName+uintptr(7), __ccgo_ts+7150+7) == 0 || _sqlite3StrICmp(tls, zName+uintptr(7), __ccgo_ts+6632+7) == 0 {
p = _sqlite3HashFind(tls, (**(**TDb)(__ccgo_up((*Tsqlite3)(unsafe.Pointer(db)).FaDb + 1*32))).FpSchema+8, __ccgo_ts+7112)
}
} else {
if _sqlite3StrICmp(tls, zName+uintptr(7), __ccgo_ts+7150+7) == 0 {
p = _sqlite3HashFind(tls, (**(**TDb)(__ccgo_up((*Tsqlite3)(unsafe.Pointer(db)).FaDb + uintptr(i)*32))).FpSchema+8, __ccgo_ts+6632)
}
}
}
} else {
/* Match against TEMP first */
p = _sqlite3HashFind(tls, (**(**TDb)(__ccgo_up((*Tsqlite3)(unsafe.Pointer(db)).FaDb + 1*32))).FpSchema+8, zName)
if p != 0 {
return p
}
/* The main database is second */
p = _sqlite3HashFind(tls, (**(**TDb)(__ccgo_up((*Tsqlite3)(unsafe.Pointer(db)).FaDb))).FpSchema+8, zName)
if p != 0 {
return p
}
/* Attached databases are in order of attachment */
i = int32(2)
for {
if !(i < (*Tsqlite3)(unsafe.Pointer(db)).FnDb) {
break
}
p = _sqlite3HashFind(tls, (**(**TDb)(__ccgo_up((*Tsqlite3)(unsafe.Pointer(db)).FaDb + uintptr(i)*32))).FpSchema+8, zName)
if p != 0 {
break
}
goto _2
_2:
;
i = i + 1
}
if p == uintptr(0) && Xsqlite3_strnicmp(tls, zName, __ccgo_ts+7104, int32(7)) == 0 {
if _sqlite3StrICmp(tls, zName+uintptr(7), __ccgo_ts+7150+7) == 0 {
p = _sqlite3HashFind(tls, (**(**TDb)(__ccgo_up((*Tsqlite3)(unsafe.Pointer(db)).FaDb))).FpSchema+8, __ccgo_ts+6632)
} else {
if _sqlite3StrICmp(tls, zName+uintptr(7), __ccgo_ts+7131+7) == 0 {
p = _sqlite3HashFind(tls, (**(**TDb)(__ccgo_up((*Tsqlite3)(unsafe.Pointer(db)).FaDb + 1*32))).FpSchema+8, __ccgo_ts+7112)
}
}
}
}
return p
}
// C documentation
//
// /*
// ** This routine is called after all of the trigger actions have been parsed
// ** in order to complete the process of building the trigger.
// */
func _sqlite3FinishTrigger(tls *libc.TLS, pParse uintptr, pStepList uintptr, pAll uintptr) {
bp := tls.Alloc(160)
defer tls.Free(160)
var db, pHash, pLink, pStep, pTab, pTrig, v, z, zName uintptr
var iDb int32
var _ /* nameToken at bp+96 */ TToken
var _ /* sFix at bp+0 */ TDbFixer
_, _, _, _, _, _, _, _, _, _ = db, iDb, pHash, pLink, pStep, pTab, pTrig, v, z, zName
pTrig = (*TParse)(unsafe.Pointer(pParse)).FpNewTrigger /* Name of trigger */
db = (*TParse)(unsafe.Pointer(pParse)).Fdb /* Trigger name for error reporting */
(*TParse)(unsafe.Pointer(pParse)).FpNewTrigger = uintptr(0)
if (*TParse)(unsafe.Pointer(pParse)).FnErr != 0 || !(pTrig != 0) {
goto triggerfinish_cleanup
}
zName = (*TTrigger)(unsafe.Pointer(pTrig)).FzName
iDb = _sqlite3SchemaToIndex(tls, (*TParse)(unsafe.Pointer(pParse)).Fdb, (*TTrigger)(unsafe.Pointer(pTrig)).FpSchema)
(*TTrigger)(unsafe.Pointer(pTrig)).Fstep_list = pStepList
for pStepList != 0 {
(*TTriggerStep)(unsafe.Pointer(pStepList)).FpTrig = pTrig
pStepList = (*TTriggerStep)(unsafe.Pointer(pStepList)).FpNext
}
_sqlite3TokenInit(tls, bp+96, (*TTrigger)(unsafe.Pointer(pTrig)).FzName)
_sqlite3FixInit(tls, bp, pParse, iDb, __ccgo_ts+22277, bp+96)
if _sqlite3FixTriggerStep(tls, bp, (*TTrigger)(unsafe.Pointer(pTrig)).Fstep_list) != 0 || _sqlite3FixExpr(tls, bp, (*TTrigger)(unsafe.Pointer(pTrig)).FpWhen) != 0 {
goto triggerfinish_cleanup
}
if libc.Int32FromUint8((*TParse)(unsafe.Pointer(pParse)).FeParseMode) >= int32(PARSE_MODE_RENAME) {
(*TParse)(unsafe.Pointer(pParse)).FpNewTrigger = pTrig
pTrig = uintptr(0)
} else {
/* if we are not initializing,
** build the sqlite_schema entry
*/
if !((*Tsqlite3)(unsafe.Pointer(db)).Finit1.Fbusy != 0) {
/* If this is a new CREATE TABLE statement, and if shadow tables
** are read-only, and the trigger makes a change to a shadow table,
** then raise an error - do not allow the trigger to be created. */
if _sqlite3ReadOnlyShadowTables(tls, db) != 0 {
pStep = (*TTrigger)(unsafe.Pointer(pTrig)).Fstep_list
for {
if !(pStep != 0) {
break
}
if (*TTriggerStep)(unsafe.Pointer(pStep)).FpSrc != uintptr(0) && _sqlite3ShadowTableName(tls, db, (*(*TSrcItem)(unsafe.Pointer((*TTriggerStep)(unsafe.Pointer(pStep)).FpSrc + 8))).FzName) != 0 {
_sqlite3ErrorMsg(tls, pParse, __ccgo_ts+22526, libc.VaList(bp+120, (*TTrigger)(unsafe.Pointer(pTrig)).FzName, (*(*TSrcItem)(unsafe.Pointer((*TTriggerStep)(unsafe.Pointer(pStep)).FpSrc + 8))).FzName))
goto triggerfinish_cleanup
}
goto _1
_1:
;
pStep = (*TTriggerStep)(unsafe.Pointer(pStep)).FpNext
}
}
/* Make an entry in the sqlite_schema table */
v = _sqlite3GetVdbe(tls, pParse)
if v == uintptr(0) {
goto triggerfinish_cleanup
}
_sqlite3BeginWriteOperation(tls, pParse, 0, iDb)
z = _sqlite3DbStrNDup(tls, db, (*TToken)(unsafe.Pointer(pAll)).Fz, uint64((*TToken)(unsafe.Pointer(pAll)).Fn))
_sqlite3NestedParse(tls, pParse, __ccgo_ts+22574, libc.VaList(bp+120, (**(**TDb)(__ccgo_up((*Tsqlite3)(unsafe.Pointer(db)).FaDb + uintptr(iDb)*32))).FzDbSName, zName, (*TTrigger)(unsafe.Pointer(pTrig)).Ftable, z))
_sqlite3DbFree(tls, db, z)
_sqlite3ChangeCookie(tls, pParse, iDb)
_sqlite3VdbeAddParseSchemaOp(tls, v, iDb, _sqlite3MPrintf(tls, db, __ccgo_ts+22649, libc.VaList(bp+120, zName)), uint16(0))
}
}
if (*Tsqlite3)(unsafe.Pointer(db)).Finit1.Fbusy != 0 {
pLink = pTrig
pHash = (**(**TDb)(__ccgo_up((*Tsqlite3)(unsafe.Pointer(db)).FaDb + uintptr(iDb)*32))).FpSchema + 56
pTrig = _sqlite3HashInsert(tls, pHash, zName, pTrig)
if pTrig != 0 {
_sqlite3OomFault(tls, db)
} else {
if (*TTrigger)(unsafe.Pointer(pLink)).FpSchema == (*TTrigger)(unsafe.Pointer(pLink)).FpTabSchema {
pTab = _sqlite3HashFind(tls, (*TTrigger)(unsafe.Pointer(pLink)).FpTabSchema+8, (*TTrigger)(unsafe.Pointer(pLink)).Ftable)
(*TTrigger)(unsafe.Pointer(pLink)).FpNext = (*TTable)(unsafe.Pointer(pTab)).FpTrigger
(*TTable)(unsafe.Pointer(pTab)).FpTrigger = pLink
}
}
}
goto triggerfinish_cleanup
triggerfinish_cleanup:
;
_sqlite3DeleteTrigger(tls, db, pTrig)
_sqlite3DeleteTriggerStep(tls, db, pStepList)
}
// C documentation
//
// /*
// ** The following set of routines walk through the parse tree and assign
// ** a specific database to all table references where the database name
// ** was left unspecified in the original SQL statement. The pFix structure
// ** must have been initialized by a prior call to sqlite3FixInit().
// **
// ** These routines are used to make sure that an index, trigger, or
// ** view in one database does not refer to objects in a different database.
// ** (Exception: indices, triggers, and views in the TEMP database are
// ** allowed to refer to anything.) If a reference is explicitly made
// ** to an object in a different database, an error message is added to
// ** pParse->zErrMsg and these routines return non-zero. If everything
// ** checks out, these routines return 0.
// */
func _sqlite3FixSrcList(tls *libc.TLS, pFix uintptr, pList uintptr) (r int32) {
bp := tls.Alloc(128)
defer tls.Free(128)
var res int32
var _ /* s at bp+0 */ TSelect
_ = res
res = 0
if pList != 0 {
libc.X__builtin___memset_chk(tls, bp, 0, uint64(120), ^t__predefined_size_t(0))
(**(**TSelect)(__ccgo_up(bp))).FpSrc = pList
res = _sqlite3WalkSelect(tls, pFix+8, bp)
}
return res
}
// C documentation
//
// /*
// ** A foreign key constraint requires that the key columns in the parent
// ** table are collectively subject to a UNIQUE or PRIMARY KEY constraint.
// ** Given that pParent is the parent table for foreign key constraint pFKey,
// ** search the schema for a unique index on the parent key columns.
// **
// ** If successful, zero is returned. If the parent key is an INTEGER PRIMARY
// ** KEY column, then output variable *ppIdx is set to NULL. Otherwise, *ppIdx
// ** is set to point to the unique index.
// **
// ** If the parent key consists of a single column (the foreign key constraint
// ** is not a composite foreign key), output variable *paiCol is set to NULL.
// ** Otherwise, it is set to point to an allocated array of size N, where
// ** N is the number of columns in the parent key. The first element of the
// ** array is the index of the child table column that is mapped by the FK
// ** constraint to the parent table column stored in the left-most column
// ** of index *ppIdx. The second element of the array is the index of the
// ** child table column that corresponds to the second left-most column of
// ** *ppIdx, and so on.
// **
// ** If the required index cannot be found, either because:
// **
// ** 1) The named parent key columns do not exist, or
// **
// ** 2) The named parent key columns do exist, but are not subject to a
// ** UNIQUE or PRIMARY KEY constraint, or
// **
// ** 3) No parent key columns were provided explicitly as part of the
// ** foreign key definition, and the parent table does not have a
// ** PRIMARY KEY, or
// **
// ** 4) No parent key columns were provided explicitly as part of the
// ** foreign key definition, and the PRIMARY KEY of the parent table
// ** consists of a different number of columns to the child key in
// ** the child table.
// **
// ** then non-zero is returned, and a "foreign key mismatch" error loaded
// ** into pParse. If an OOM error occurs, non-zero is returned and the
// ** pParse->db->mallocFailed flag is set.
// */
func _sqlite3FkLocateIndex(tls *libc.TLS, pParse uintptr, pParent uintptr, pFKey uintptr, ppIdx uintptr, paiCol uintptr) (r int32) {
bp := tls.Alloc(32)
defer tls.Free(32)
var aiCol, pIdx, zDfltColl, zIdxCol, zKey uintptr
var i, i1, j, nCol int32
var iCol Ti16
_, _, _, _, _, _, _, _, _, _ = aiCol, i, i1, iCol, j, nCol, pIdx, zDfltColl, zIdxCol, zKey
pIdx = uintptr(0) /* Value to return via *ppIdx */
aiCol = uintptr(0) /* Value to return via *paiCol */
nCol = (*TFKey)(unsafe.Pointer(pFKey)).FnCol /* Number of columns in parent key */
zKey = (*(*TsColMap)(unsafe.Pointer(pFKey + 64))).FzCol /* Name of left-most parent key column */
/* The caller is responsible for zeroing output parameters. */
/* If this is a non-composite (single column) foreign key, check if it
** maps to the INTEGER PRIMARY KEY of table pParent. If so, leave *ppIdx
** and *paiCol set to zero and return early.
**
** Otherwise, for a composite foreign key (more than one column), allocate
** space for the aiCol array (returned via output parameter *paiCol).
** Non-composite foreign keys do not require the aiCol array.
*/
if nCol == int32(1) {
/* The FK maps to the IPK if any of the following are true:
**
** 1) There is an INTEGER PRIMARY KEY column and the FK is implicitly
** mapped to the primary key of table pParent, or
** 2) The FK is explicitly mapped to a column declared as INTEGER
** PRIMARY KEY.
*/
if int32((*TTable)(unsafe.Pointer(pParent)).FiPKey) >= 0 {
if !(zKey != 0) {
return 0
}
if !(_sqlite3StrICmp(tls, (**(**TColumn)(__ccgo_up((*TTable)(unsafe.Pointer(pParent)).FaCol + uintptr((*TTable)(unsafe.Pointer(pParent)).FiPKey)*16))).FzCnName, zKey) != 0) {
return 0
}
}
} else {
if paiCol != 0 {
aiCol = _sqlite3DbMallocRawNN(tls, (*TParse)(unsafe.Pointer(pParse)).Fdb, uint64(libc.Uint64FromInt32(nCol)*uint64(4)))
if !(aiCol != 0) {
return int32(1)
}
**(**uintptr)(__ccgo_up(paiCol)) = aiCol
}
}
pIdx = (*TTable)(unsafe.Pointer(pParent)).FpIndex
for {
if !(pIdx != 0) {
break
}
if libc.Int32FromUint16((*TIndex)(unsafe.Pointer(pIdx)).FnKeyCol) == nCol && libc.Int32FromUint8((*TIndex)(unsafe.Pointer(pIdx)).FonError) != OE_None && (*TIndex)(unsafe.Pointer(pIdx)).FpPartIdxWhere == uintptr(0) {
/* pIdx is a UNIQUE index (or a PRIMARY KEY) and has the right number
** of columns. If each indexed column corresponds to a foreign key
** column of pFKey, then this index is a winner. */
if zKey == uintptr(0) {
/* If zKey is NULL, then this foreign key is implicitly mapped to
** the PRIMARY KEY of table pParent. The PRIMARY KEY index may be
** identified by the test. */
if int32(uint32(*(*uint16)(unsafe.Pointer(pIdx + 100))&0x3>>0)) == int32(SQLITE_IDXTYPE_PRIMARYKEY) {
if aiCol != 0 {
i = 0
for {
if !(i < nCol) {
break
}
**(**int32)(__ccgo_up(aiCol + uintptr(i)*4)) = (*(*TsColMap)(unsafe.Pointer(pFKey + 64 + uintptr(i)*16))).FiFrom
goto _2
_2:
;
i = i + 1
}
}
break
}
} else {
i1 = 0
for {
if !(i1 < nCol) {
break
}
iCol = **(**Ti16)(__ccgo_up((*TIndex)(unsafe.Pointer(pIdx)).FaiColumn + uintptr(i1)*2)) /* Name of indexed column */
if int32(iCol) < 0 {
break
} /* No foreign keys against expression indexes */
/* If the index uses a collation sequence that is different from
** the default collation sequence for the column, this index is
** unusable. Bail out early in this case. */
zDfltColl = _sqlite3ColumnColl(tls, (*TTable)(unsafe.Pointer(pParent)).FaCol+uintptr(iCol)*16)
if !(zDfltColl != 0) {
zDfltColl = uintptr(unsafe.Pointer(&_sqlite3StrBINARY))
}
if _sqlite3StrICmp(tls, **(**uintptr)(__ccgo_up((*TIndex)(unsafe.Pointer(pIdx)).FazColl + uintptr(i1)*8)), zDfltColl) != 0 {
break
}
zIdxCol = (**(**TColumn)(__ccgo_up((*TTable)(unsafe.Pointer(pParent)).FaCol + uintptr(iCol)*16))).FzCnName
j = 0
for {
if !(j < nCol) {
break
}
if _sqlite3StrICmp(tls, (*(*TsColMap)(unsafe.Pointer(pFKey + 64 + uintptr(j)*16))).FzCol, zIdxCol) == 0 {
if aiCol != 0 {
**(**int32)(__ccgo_up(aiCol + uintptr(i1)*4)) = (*(*TsColMap)(unsafe.Pointer(pFKey + 64 + uintptr(j)*16))).FiFrom
}
break
}
goto _4
_4:
;
j = j + 1
}
if j == nCol {
break
}
goto _3
_3:
;
i1 = i1 + 1
}
if i1 == nCol {
break
} /* pIdx is usable */
}
}
goto _1
_1:
;
pIdx = (*TIndex)(unsafe.Pointer(pIdx)).FpNext
}
if !(pIdx != 0) {
if !(int32(Tbft(*(*uint16)(unsafe.Pointer(pParse + 40))&0x1>>0)) != 0) {
_sqlite3ErrorMsg(tls, pParse, __ccgo_ts+17648, libc.VaList(bp+8, (*TTable)(unsafe.Pointer((*TFKey)(unsafe.Pointer(pFKey)).FpFrom)).FzName, (*TFKey)(unsafe.Pointer(pFKey)).FzTo))
}
_sqlite3DbFree(tls, (*TParse)(unsafe.Pointer(pParse)).Fdb, aiCol)
return int32(1)
}
**(**uintptr)(__ccgo_up(ppIdx)) = pIdx
return 0
}
// C documentation
//
// /*
// ** Return an IEEE754 floating point value that approximates d*pow(10,p).
// **
// ** The (current) algorithm is adapted from the work of Ross Cox at
// ** https://github.com/rsc/fpfmt
// */
func _sqlite3Fp10Convert2(tls *libc.TLS, d Tu64, p int32) (r float64) {
bp := tls.Alloc(32)
defer tls.Free(32)
var adj, b, e, lp, s int32
var hi, pwr10h, sticky, u, x Tu64
var mid1, mid2 Tu32
var _ /* lo at bp+8 */ Tu64
var _ /* m at bp+16 */ Tu64
var _ /* pwr10l at bp+0 */ Tu32
var _ /* r at bp+24 */ float64
_, _, _, _, _, _, _, _, _, _, _, _ = adj, b, e, hi, lp, mid1, mid2, pwr10h, s, sticky, u, x
if p < -int32(348) {
return float64(0)
}
if p > +libc.Int32FromInt32(347) {
return float64(libc.X__builtin_huge_valf(tls))
}
b = int32(64) - _countLeadingZeros(tls, d)
lp = _pwr10to2(tls, p)
e = int32(53) - b - lp
if e > int32(1074) {
if e >= int32(1130) {
return float64(0)
}
e = int32(1074)
}
s = -(e - (int32(64) - b) + lp + int32(3))
pwr10h = _powerOfTen(tls, p, bp)
if **(**Tu32)(__ccgo_up(bp)) != uint32(0) {
pwr10h = pwr10h + 1
**(**Tu32)(__ccgo_up(bp)) = ^**(**Tu32)(__ccgo_up(bp))
}
x = d << (int32(64) - b)
hi = _sqlite3Multiply128(tls, x, pwr10h, bp+8)
mid1 = uint32(**(**Tu64)(__ccgo_up(bp + 8)) >> int32(32))
sticky = uint64(1)
if hi&(libc.Uint64FromInt32(1)<> int32(32))
sticky = libc.BoolUint64(mid1-mid2 > libc.Uint32FromInt32(1))
hi = hi - libc.BoolUint64(mid1 < mid2)
}
u = hi>>s | sticky
adj = libc.BoolInt32(u >= libc.Uint64FromInt32(1)<>adj | u&uint64(1)
e = e - adj
}
**(**Tu64)(__ccgo_up(bp + 16)) = (u + uint64(1) + u>>libc.Int32FromInt32(2)&uint64(1)) >> int32(2)
if e <= -int32(972) {
return float64(libc.X__builtin_huge_valf(tls))
}
if **(**Tu64)(__ccgo_up(bp + 16))&(libc.Uint64FromInt32(1)<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.X__builtin___memcpy_chk(tls, bp+8, bp, uint64(8), ^t__predefined_size_t(0))
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 + 16
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))<= 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 + 16
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
}
func _sqlite3Fts5AuxInit(tls *libc.TLS, pApi uintptr) (r int32) {
var aBuiltin [4]struct {
FzFunc uintptr
FpUserData uintptr
FxFunc Tfts5_extension_function
FxDestroy uintptr
}
var i, rc int32
_, _, _ = aBuiltin, i, rc
aBuiltin = [4]struct {
FzFunc uintptr
FpUserData uintptr
FxFunc Tfts5_extension_function
FxDestroy uintptr
}{
0: {
FzFunc: __ccgo_ts + 37757,
FxFunc: __ccgo_fp(_fts5SnippetFunction),
},
1: {
FzFunc: __ccgo_ts + 37765,
FxFunc: __ccgo_fp(_fts5HighlightFunction),
},
2: {
FzFunc: __ccgo_ts + 37775,
FxFunc: __ccgo_fp(_fts5Bm25Function),
},
3: {
FzFunc: __ccgo_ts + 37780,
FxFunc: __ccgo_fp(_fts5GetLocaleFunction),
},
}
rc = SQLITE_OK /* To iterate through builtin functions */
i = 0
for {
if !(rc == SQLITE_OK && i < libc.Int32FromUint64(libc.Uint64FromInt64(128)/libc.Uint64FromInt64(32))) {
break
}
rc = (*(*func(*libc.TLS, uintptr, uintptr, uintptr, Tfts5_extension_function, uintptr) int32)(unsafe.Pointer(&struct{ uintptr }{(*Tfts5_api)(unsafe.Pointer(pApi)).FxCreateFunction})))(tls, pApi, aBuiltin[i].FzFunc, aBuiltin[i].FpUserData, aBuiltin[i].FxFunc, aBuiltin[i].FxDestroy)
goto _1
_1:
;
i = i + 1
}
return rc
}
/*
** 2014 May 31
**
** The author disclaims copyright to this source code. In place of
** a legal notice, here is a blessing:
**
** May you do good and not evil.
** May you find forgiveness for yourself and forgive others.
** May you share freely, never taking more than you give.
**
******************************************************************************
*/
/* #include "fts5Int.h" */
// C documentation
//
// /*
// ** Append buffer nData/pData to buffer pBuf. If an OOM error occurs, set
// ** the error code in p. If an error has already occurred when this function
// ** is called, it is a no-op.
// */
func _sqlite3Fts5BufferAppendBlob(tls *libc.TLS, pRc uintptr, pBuf uintptr, nData Tu32, pData uintptr) {
var v1 int32
var v2 uintptr
_, _ = v1, v2
if nData != 0 {
if libc.Uint32FromInt32((*TFts5Buffer)(unsafe.Pointer(pBuf)).Fn)+nData <= libc.Uint32FromInt32((*TFts5Buffer)(unsafe.Pointer(pBuf)).FnSpace) {
v1 = 0
} else {
v1 = _sqlite3Fts5BufferSize(tls, pRc, pBuf, nData+libc.Uint32FromInt32((*TFts5Buffer)(unsafe.Pointer(pBuf)).Fn))
}
if v1 != 0 {
return
}
libc.X__builtin___memcpy_chk(tls, (*TFts5Buffer)(unsafe.Pointer(pBuf)).Fp+uintptr((*TFts5Buffer)(unsafe.Pointer(pBuf)).Fn), pData, uint64(nData), ^t__predefined_size_t(0))
v2 = pBuf + 8
*(*int32)(unsafe.Pointer(v2)) = int32(uint32(*(*int32)(unsafe.Pointer(v2))) + nData)
}
}
// C documentation
//
// /*
// ** Free any buffer allocated by pBuf. Zero the structure before returning.
// */
func _sqlite3Fts5BufferFree(tls *libc.TLS, pBuf uintptr) {
Xsqlite3_free(tls, (*TFts5Buffer)(unsafe.Pointer(pBuf)).Fp)
libc.X__builtin___memset_chk(tls, pBuf, 0, uint64(16), ^t__predefined_size_t(0))
}
// C documentation
//
// /*
// ** Call sqlite3_declare_vtab() based on the contents of the configuration
// ** object passed as the only argument. Return SQLITE_OK if successful, or
// ** an SQLite error code if an error occurs.
// */
func _sqlite3Fts5ConfigDeclareVtab(tls *libc.TLS, pConfig uintptr) (r int32) {
bp := tls.Alloc(48)
defer tls.Free(48)
var i int32
var zSep, zSql, v2 uintptr
var _ /* rc at bp+0 */ int32
_, _, _, _ = i, zSep, zSql, v2
**(**int32)(__ccgo_up(bp)) = SQLITE_OK
zSql = _sqlite3Fts5Mprintf(tls, bp, __ccgo_ts+38694, 0)
i = 0
for {
if !(zSql != 0 && i < (*TFts5Config)(unsafe.Pointer(pConfig)).FnCol) {
break
}
if i == 0 {
v2 = __ccgo_ts + 1702
} else {
v2 = __ccgo_ts + 16562
}
zSep = v2
zSql = _sqlite3Fts5Mprintf(tls, bp, __ccgo_ts+38710, libc.VaList(bp+16, zSql, zSep, **(**uintptr)(__ccgo_up((*TFts5Config)(unsafe.Pointer(pConfig)).FazCol + uintptr(i)*8))))
goto _1
_1:
;
i = i + 1
}
zSql = _sqlite3Fts5Mprintf(tls, bp, __ccgo_ts+38717, libc.VaList(bp+16, zSql, (*TFts5Config)(unsafe.Pointer(pConfig)).FzName, __ccgo_ts+38357))
if zSql != 0 {
**(**int32)(__ccgo_up(bp)) = Xsqlite3_declare_vtab(tls, (*TFts5Config)(unsafe.Pointer(pConfig)).Fdb, zSql)
Xsqlite3_free(tls, zSql)
}
return **(**int32)(__ccgo_up(bp))
}
// C documentation
//
// /*
// ** Load the contents of the %_config table into memory.
// */
func _sqlite3Fts5ConfigLoad(tls *libc.TLS, pConfig uintptr, iCookie int32) (r int32) {
bp := tls.Alloc(48)
defer tls.Free(48)
var iVersion int32
var pVal, zK, zSelect, zSql uintptr
var _ /* bDummy at bp+12 */ int32
var _ /* p at bp+0 */ uintptr
var _ /* rc at bp+8 */ int32
_, _, _, _, _ = iVersion, pVal, zK, zSelect, zSql
zSelect = __ccgo_ts + 38825
**(**uintptr)(__ccgo_up(bp)) = uintptr(0)
**(**int32)(__ccgo_up(bp + 8)) = SQLITE_OK
iVersion = 0
/* Set default values */
(*TFts5Config)(unsafe.Pointer(pConfig)).Fpgsz = int32(FTS5_DEFAULT_PAGE_SIZE)
(*TFts5Config)(unsafe.Pointer(pConfig)).FnAutomerge = int32(FTS5_DEFAULT_AUTOMERGE)
(*TFts5Config)(unsafe.Pointer(pConfig)).FnUsermerge = int32(FTS5_DEFAULT_USERMERGE)
(*TFts5Config)(unsafe.Pointer(pConfig)).FnCrisisMerge = int32(FTS5_DEFAULT_CRISISMERGE)
(*TFts5Config)(unsafe.Pointer(pConfig)).FnHashSize = libc.Int32FromInt32(1024) * libc.Int32FromInt32(1024)
(*TFts5Config)(unsafe.Pointer(pConfig)).FnDeleteMerge = int32(FTS5_DEFAULT_DELETE_AUTOMERGE)
zSql = _sqlite3Fts5Mprintf(tls, bp+8, zSelect, libc.VaList(bp+24, (*TFts5Config)(unsafe.Pointer(pConfig)).FzDb, (*TFts5Config)(unsafe.Pointer(pConfig)).FzName))
if zSql != 0 {
**(**int32)(__ccgo_up(bp + 8)) = Xsqlite3_prepare_v2(tls, (*TFts5Config)(unsafe.Pointer(pConfig)).Fdb, zSql, -int32(1), bp, uintptr(0))
Xsqlite3_free(tls, zSql)
}
if **(**int32)(__ccgo_up(bp + 8)) == SQLITE_OK {
for int32(SQLITE_ROW) == Xsqlite3_step(tls, **(**uintptr)(__ccgo_up(bp))) {
zK = Xsqlite3_column_text(tls, **(**uintptr)(__ccgo_up(bp)), 0)
pVal = Xsqlite3_column_value(tls, **(**uintptr)(__ccgo_up(bp)), int32(1))
if 0 == Xsqlite3_stricmp(tls, zK, __ccgo_ts+38857) {
iVersion = Xsqlite3_value_int(tls, pVal)
} else {
**(**int32)(__ccgo_up(bp + 12)) = 0
_sqlite3Fts5ConfigSetValue(tls, pConfig, zK, pVal, bp+12)
}
}
**(**int32)(__ccgo_up(bp + 8)) = Xsqlite3_finalize(tls, **(**uintptr)(__ccgo_up(bp)))
}
if **(**int32)(__ccgo_up(bp + 8)) == SQLITE_OK && iVersion != int32(FTS5_CURRENT_VERSION) && iVersion != int32(FTS5_CURRENT_VERSION_SECUREDELETE) {
**(**int32)(__ccgo_up(bp + 8)) = int32(SQLITE_ERROR)
_sqlite3Fts5ConfigErrmsg(tls, pConfig, __ccgo_ts+38865, libc.VaList(bp+24, iVersion, int32(FTS5_CURRENT_VERSION), int32(FTS5_CURRENT_VERSION_SECUREDELETE)))
} else {
(*TFts5Config)(unsafe.Pointer(pConfig)).FiVersion = iVersion
}
if **(**int32)(__ccgo_up(bp + 8)) == SQLITE_OK {
(*TFts5Config)(unsafe.Pointer(pConfig)).FiCookie = iCookie
}
return **(**int32)(__ccgo_up(bp + 8))
}
// 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+28 */ int32
var _ /* bMustBeCol at bp+24 */ int32
var _ /* bUnindexed at bp+4 */ int32
var _ /* rc at bp+0 */ int32
var _ /* zOne at bp+8 */ uintptr
var _ /* zTwo at bp+16 */ 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(256))
pRet = v1
**(**uintptr)(__ccgo_up(ppOut)) = v1
if pRet == uintptr(0) {
return int32(SQLITE_NOMEM)
}
libc.X__builtin___memset_chk(tls, pRet, 0, uint64(256), ^t__predefined_size_t(0))
(*TFts5Config)(unsafe.Pointer(pRet)).FpGlobal = pGlobal
(*TFts5Config)(unsafe.Pointer(pRet)).Fdb = db
(*TFts5Config)(unsafe.Pointer(pRet)).FiCookie = -int32(1)
nByte = libc.Int64FromUint64(libc.Uint64FromInt32(nArg) * (libc.Uint64FromInt64(8) + libc.Uint64FromInt64(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)*8
} else {
v1 = uintptr(0)
}
(*TFts5Config)(unsafe.Pointer(pRet)).FabUnindexed = v1
(*TFts5Config)(unsafe.Pointer(pRet)).FzDb = _sqlite3Fts5Strndup(tls, bp, **(**uintptr)(__ccgo_up(azArg + 1*8)), -int32(1))
(*TFts5Config)(unsafe.Pointer(pRet)).FzName = _sqlite3Fts5Strndup(tls, bp, **(**uintptr)(__ccgo_up(azArg + 2*8)), -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+38357) == 0 {
**(**uintptr)(__ccgo_up(pzErr)) = Xsqlite3_mprintf(tls, __ccgo_ts+38468, libc.VaList(bp+40, (*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)*8))
**(**uintptr)(__ccgo_up(bp + 8)) = uintptr(0)
**(**uintptr)(__ccgo_up(bp + 16)) = uintptr(0)
bOption = 0
**(**int32)(__ccgo_up(bp + 24)) = 0
z = _fts5ConfigGobbleWord(tls, bp, zOrig, bp+8, bp+24)
z = _fts5ConfigSkipWhitespace(tls, z)
if z != 0 && int32(**(**int8)(__ccgo_up(z))) == int32('=') {
bOption = int32(1)
z = z + 1
if **(**int32)(__ccgo_up(bp + 24)) != 0 {
z = uintptr(0)
}
}
z = _fts5ConfigSkipWhitespace(tls, z)
if z != 0 && **(**int8)(__ccgo_up(z)) != 0 {
z = _fts5ConfigGobbleWord(tls, bp, z, bp+16, bp+28)
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+38497, libc.VaList(bp+40, 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 + 16)) != 0 {
v2 = **(**uintptr)(__ccgo_up(bp + 16))
} 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 + 16)), 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 + 16)))
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+38517, 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+38567, 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+38622, 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 + 37980
} 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 + 37980
} else {
if (*TFts5Config)(unsafe.Pointer(pRet)).FbColumnsize != 0 {
zTail = __ccgo_ts + 38675
}
}
}
if zTail != 0 {
(*TFts5Config)(unsafe.Pointer(pRet)).FzContent = _sqlite3Fts5Mprintf(tls, bp, __ccgo_ts+38683, libc.VaList(bp+40, (*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+18314, -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
//
// /*
// ** Parameter zIn contains a rank() function specification. The format of
// ** this is:
// **
// ** + Bareword (function name)
// ** + Open parenthesis - "("
// ** + Zero or more SQL literals in a comma separated list
// ** + Close parenthesis - ")"
// */
func _sqlite3Fts5ConfigParseRank(tls *libc.TLS, zIn uintptr, pzRank uintptr, pzRankArgs uintptr) (r int32) {
bp := tls.Alloc(16)
defer tls.Free(16)
var p, pArgs, pRank, zRank, zRankArgs uintptr
var _ /* rc at bp+0 */ int32
_, _, _, _, _ = p, pArgs, pRank, zRank, zRankArgs
p = zIn
zRank = uintptr(0)
zRankArgs = uintptr(0)
**(**int32)(__ccgo_up(bp)) = SQLITE_OK
**(**uintptr)(__ccgo_up(pzRank)) = uintptr(0)
**(**uintptr)(__ccgo_up(pzRankArgs)) = uintptr(0)
if p == uintptr(0) {
**(**int32)(__ccgo_up(bp)) = int32(SQLITE_ERROR)
} else {
p = _fts5ConfigSkipWhitespace(tls, p)
pRank = p
p = _fts5ConfigSkipBareword(tls, p)
if p != 0 {
zRank = _sqlite3Fts5MallocZero(tls, bp, int64(uintptr(1)+p)-int64(pRank))
if zRank != 0 {
libc.X__builtin___memcpy_chk(tls, zRank, pRank, libc.Uint64FromInt64(int64(p)-int64(pRank)), ^t__predefined_size_t(0))
}
} else {
**(**int32)(__ccgo_up(bp)) = int32(SQLITE_ERROR)
}
if **(**int32)(__ccgo_up(bp)) == SQLITE_OK {
p = _fts5ConfigSkipWhitespace(tls, p)
if int32(**(**int8)(__ccgo_up(p))) != int32('(') {
**(**int32)(__ccgo_up(bp)) = int32(SQLITE_ERROR)
}
p = p + 1
}
if **(**int32)(__ccgo_up(bp)) == SQLITE_OK {
p = _fts5ConfigSkipWhitespace(tls, p)
pArgs = p
if int32(**(**int8)(__ccgo_up(p))) != int32(')') {
p = _fts5ConfigSkipArgs(tls, p)
if p == uintptr(0) {
**(**int32)(__ccgo_up(bp)) = int32(SQLITE_ERROR)
} else {
zRankArgs = _sqlite3Fts5MallocZero(tls, bp, int64(uintptr(1)+p)-int64(pArgs))
if zRankArgs != 0 {
libc.X__builtin___memcpy_chk(tls, zRankArgs, pArgs, libc.Uint64FromInt64(int64(p)-int64(pArgs)), ^t__predefined_size_t(0))
}
}
}
}
}
if **(**int32)(__ccgo_up(bp)) != SQLITE_OK {
Xsqlite3_free(tls, zRank)
} else {
**(**uintptr)(__ccgo_up(pzRank)) = zRank
**(**uintptr)(__ccgo_up(pzRankArgs)) = zRankArgs
}
return **(**int32)(__ccgo_up(bp))
}
func _sqlite3Fts5ConfigSetValue(tls *libc.TLS, pConfig uintptr, zKey uintptr, pVal uintptr, pbBadkey uintptr) (r int32) {
bp := tls.Alloc(16)
defer tls.Free(16)
var bVal, bVal1, nAutomerge, nCrisisMerge, nHashSize, nUsermerge, nVal, pgsz, rc, v1 int32
var zIn uintptr
var _ /* zRank at bp+0 */ uintptr
var _ /* zRankArgs at bp+8 */ uintptr
_, _, _, _, _, _, _, _, _, _, _ = bVal, bVal1, nAutomerge, nCrisisMerge, nHashSize, nUsermerge, nVal, pgsz, rc, zIn, v1
rc = SQLITE_OK
if 0 == Xsqlite3_stricmp(tls, zKey, __ccgo_ts+38743) {
pgsz = 0
if int32(SQLITE_INTEGER) == Xsqlite3_value_numeric_type(tls, pVal) {
pgsz = Xsqlite3_value_int(tls, pVal)
}
if pgsz < int32(32) || pgsz > libc.Int32FromInt32(64)*libc.Int32FromInt32(1024) {
**(**int32)(__ccgo_up(pbBadkey)) = int32(1)
} else {
(*TFts5Config)(unsafe.Pointer(pConfig)).Fpgsz = pgsz
}
} else {
if 0 == Xsqlite3_stricmp(tls, zKey, __ccgo_ts+38748) {
nHashSize = -int32(1)
if int32(SQLITE_INTEGER) == Xsqlite3_value_numeric_type(tls, pVal) {
nHashSize = Xsqlite3_value_int(tls, pVal)
}
if nHashSize <= 0 {
**(**int32)(__ccgo_up(pbBadkey)) = int32(1)
} else {
(*TFts5Config)(unsafe.Pointer(pConfig)).FnHashSize = nHashSize
}
} else {
if 0 == Xsqlite3_stricmp(tls, zKey, __ccgo_ts+38757) {
nAutomerge = -int32(1)
if int32(SQLITE_INTEGER) == Xsqlite3_value_numeric_type(tls, pVal) {
nAutomerge = Xsqlite3_value_int(tls, pVal)
}
if nAutomerge < 0 || nAutomerge > int32(64) {
**(**int32)(__ccgo_up(pbBadkey)) = int32(1)
} else {
if nAutomerge == int32(1) {
nAutomerge = int32(FTS5_DEFAULT_AUTOMERGE)
}
(*TFts5Config)(unsafe.Pointer(pConfig)).FnAutomerge = nAutomerge
}
} else {
if 0 == Xsqlite3_stricmp(tls, zKey, __ccgo_ts+38767) {
nUsermerge = -int32(1)
if int32(SQLITE_INTEGER) == Xsqlite3_value_numeric_type(tls, pVal) {
nUsermerge = Xsqlite3_value_int(tls, pVal)
}
if nUsermerge < int32(2) || nUsermerge > int32(16) {
**(**int32)(__ccgo_up(pbBadkey)) = int32(1)
} else {
(*TFts5Config)(unsafe.Pointer(pConfig)).FnUsermerge = nUsermerge
}
} else {
if 0 == Xsqlite3_stricmp(tls, zKey, __ccgo_ts+38777) {
nCrisisMerge = -int32(1)
if int32(SQLITE_INTEGER) == Xsqlite3_value_numeric_type(tls, pVal) {
nCrisisMerge = Xsqlite3_value_int(tls, pVal)
}
if nCrisisMerge < 0 {
**(**int32)(__ccgo_up(pbBadkey)) = int32(1)
} else {
if nCrisisMerge <= int32(1) {
nCrisisMerge = int32(FTS5_DEFAULT_CRISISMERGE)
}
if nCrisisMerge >= int32(FTS5_MAX_SEGMENT) {
nCrisisMerge = libc.Int32FromInt32(FTS5_MAX_SEGMENT) - libc.Int32FromInt32(1)
}
(*TFts5Config)(unsafe.Pointer(pConfig)).FnCrisisMerge = nCrisisMerge
}
} else {
if 0 == Xsqlite3_stricmp(tls, zKey, __ccgo_ts+38789) {
nVal = -int32(1)
if int32(SQLITE_INTEGER) == Xsqlite3_value_numeric_type(tls, pVal) {
nVal = Xsqlite3_value_int(tls, pVal)
} else {
**(**int32)(__ccgo_up(pbBadkey)) = int32(1)
}
if nVal < 0 {
nVal = int32(FTS5_DEFAULT_DELETE_AUTOMERGE)
}
if nVal > int32(100) {
nVal = 0
}
(*TFts5Config)(unsafe.Pointer(pConfig)).FnDeleteMerge = nVal
} else {
if 0 == Xsqlite3_stricmp(tls, zKey, __ccgo_ts+38357) {
zIn = Xsqlite3_value_text(tls, pVal)
rc = _sqlite3Fts5ConfigParseRank(tls, zIn, bp, bp+8)
if rc == SQLITE_OK {
Xsqlite3_free(tls, (*TFts5Config)(unsafe.Pointer(pConfig)).FzRank)
Xsqlite3_free(tls, (*TFts5Config)(unsafe.Pointer(pConfig)).FzRankArgs)
(*TFts5Config)(unsafe.Pointer(pConfig)).FzRank = **(**uintptr)(__ccgo_up(bp))
(*TFts5Config)(unsafe.Pointer(pConfig)).FzRankArgs = **(**uintptr)(__ccgo_up(bp + 8))
} else {
if rc == int32(SQLITE_ERROR) {
rc = SQLITE_OK
**(**int32)(__ccgo_up(pbBadkey)) = int32(1)
}
}
} else {
if 0 == Xsqlite3_stricmp(tls, zKey, __ccgo_ts+38801) {
bVal = -int32(1)
if int32(SQLITE_INTEGER) == Xsqlite3_value_numeric_type(tls, pVal) {
bVal = Xsqlite3_value_int(tls, pVal)
}
if bVal < 0 {
**(**int32)(__ccgo_up(pbBadkey)) = int32(1)
} else {
if bVal != 0 {
v1 = int32(1)
} else {
v1 = 0
}
(*TFts5Config)(unsafe.Pointer(pConfig)).FbSecureDelete = v1
}
} else {
if 0 == Xsqlite3_stricmp(tls, zKey, __ccgo_ts+38815) {
bVal1 = -int32(1)
if int32(SQLITE_INTEGER) == Xsqlite3_value_numeric_type(tls, pVal) {
bVal1 = Xsqlite3_value_int(tls, pVal)
}
if bVal1 < 0 {
**(**int32)(__ccgo_up(pbBadkey)) = int32(1)
} else {
if bVal1 != 0 {
v1 = int32(1)
} else {
v1 = 0
}
(*TFts5Config)(unsafe.Pointer(pConfig)).FbPrefixInsttoken = v1
}
} else {
**(**int32)(__ccgo_up(pbBadkey)) = int32(1)
}
}
}
}
}
}
}
}
}
return rc
}
// C documentation
//
// /*
// ** Create the shadow table named zPost, with definition zDefn. Return
// ** SQLITE_OK if successful, or an SQLite error code otherwise.
// */
func _sqlite3Fts5CreateTable(tls *libc.TLS, pConfig uintptr, zPost uintptr, zDefn uintptr, bWithout int32, pzErr uintptr) (r int32) {
bp := tls.Alloc(64)
defer tls.Free(64)
var rc int32
var v1 uintptr
var _ /* zErr at bp+0 */ uintptr
_, _ = rc, v1
**(**uintptr)(__ccgo_up(bp)) = uintptr(0)
if bWithout != 0 {
v1 = __ccgo_ts + 32474
} else {
v1 = __ccgo_ts + 1702
}
rc = _fts5ExecPrintf(tls, (*TFts5Config)(unsafe.Pointer(pConfig)).Fdb, bp, __ccgo_ts+41877, libc.VaList(bp+16, (*TFts5Config)(unsafe.Pointer(pConfig)).FzDb, (*TFts5Config)(unsafe.Pointer(pConfig)).FzName, zPost, zDefn, v1))
if **(**uintptr)(__ccgo_up(bp)) != 0 {
**(**uintptr)(__ccgo_up(pzErr)) = Xsqlite3_mprintf(tls, __ccgo_ts+41907, libc.VaList(bp+16, (*TFts5Config)(unsafe.Pointer(pConfig)).FzName, zPost, **(**uintptr)(__ccgo_up(bp))))
Xsqlite3_free(tls, **(**uintptr)(__ccgo_up(bp)))
}
return rc
}
// C documentation
//
// /*
// ** Drop all shadow tables. Return SQLITE_OK if successful or an SQLite error
// ** code otherwise.
// */
func _sqlite3Fts5DropAll(tls *libc.TLS, pConfig uintptr) (r int32) {
bp := tls.Alloc(64)
defer tls.Free(64)
var rc int32
_ = rc
rc = _fts5ExecPrintf(tls, (*TFts5Config)(unsafe.Pointer(pConfig)).Fdb, uintptr(0), __ccgo_ts+41655, libc.VaList(bp+8, (*TFts5Config)(unsafe.Pointer(pConfig)).FzDb, (*TFts5Config)(unsafe.Pointer(pConfig)).FzName, (*TFts5Config)(unsafe.Pointer(pConfig)).FzDb, (*TFts5Config)(unsafe.Pointer(pConfig)).FzName, (*TFts5Config)(unsafe.Pointer(pConfig)).FzDb, (*TFts5Config)(unsafe.Pointer(pConfig)).FzName))
if rc == SQLITE_OK && (*TFts5Config)(unsafe.Pointer(pConfig)).FbColumnsize != 0 {
rc = _fts5ExecPrintf(tls, (*TFts5Config)(unsafe.Pointer(pConfig)).Fdb, uintptr(0), __ccgo_ts+41759, libc.VaList(bp+8, (*TFts5Config)(unsafe.Pointer(pConfig)).FzDb, (*TFts5Config)(unsafe.Pointer(pConfig)).FzName))
}
if rc == SQLITE_OK && (*TFts5Config)(unsafe.Pointer(pConfig)).FeContent == FTS5_CONTENT_NORMAL {
rc = _fts5ExecPrintf(tls, (*TFts5Config)(unsafe.Pointer(pConfig)).Fdb, uintptr(0), __ccgo_ts+41797, libc.VaList(bp+8, (*TFts5Config)(unsafe.Pointer(pConfig)).FzDb, (*TFts5Config)(unsafe.Pointer(pConfig)).FzName))
}
return rc
}
func _sqlite3Fts5ExprAnd(tls *libc.TLS, pp1 uintptr, p2 uintptr) (r int32) {
bp := tls.Alloc(48)
defer tls.Free(48)
var ap, p1 uintptr
var i, nPhrase int32
var _ /* sParse at bp+0 */ TFts5Parse
_, _, _, _ = ap, i, nPhrase, p1
libc.X__builtin___memset_chk(tls, bp, 0, uint64(48), ^t__predefined_size_t(0))
if **(**uintptr)(__ccgo_up(pp1)) != 0 && p2 != 0 {
p1 = **(**uintptr)(__ccgo_up(pp1))
nPhrase = (*TFts5Expr)(unsafe.Pointer(p1)).FnPhrase + (*TFts5Expr)(unsafe.Pointer(p2)).FnPhrase
(*TFts5Expr)(unsafe.Pointer(p1)).FpRoot = _sqlite3Fts5ParseNode(tls, bp, int32(FTS5_AND), (*TFts5Expr)(unsafe.Pointer(p1)).FpRoot, (*TFts5Expr)(unsafe.Pointer(p2)).FpRoot, uintptr(0))
(*TFts5Expr)(unsafe.Pointer(p2)).FpRoot = uintptr(0)
if (**(**TFts5Parse)(__ccgo_up(bp))).Frc == SQLITE_OK {
ap = Xsqlite3_realloc64(tls, (*TFts5Expr)(unsafe.Pointer(p1)).FapExprPhrase, uint64(libc.Uint64FromInt32(nPhrase)*uint64(8)))
if ap == uintptr(0) {
(**(**TFts5Parse)(__ccgo_up(bp))).Frc = int32(SQLITE_NOMEM)
} else {
libc.X__builtin___memmove_chk(tls, ap+uintptr((*TFts5Expr)(unsafe.Pointer(p2)).FnPhrase)*8, ap, libc.Uint64FromInt32((*TFts5Expr)(unsafe.Pointer(p1)).FnPhrase)*uint64(8), ^t__predefined_size_t(0))
i = 0
for {
if !(i < (*TFts5Expr)(unsafe.Pointer(p2)).FnPhrase) {
break
}
**(**uintptr)(__ccgo_up(ap + uintptr(i)*8)) = **(**uintptr)(__ccgo_up((*TFts5Expr)(unsafe.Pointer(p2)).FapExprPhrase + uintptr(i)*8))
goto _1
_1:
;
i = i + 1
}
(*TFts5Expr)(unsafe.Pointer(p1)).FnPhrase = nPhrase
(*TFts5Expr)(unsafe.Pointer(p1)).FapExprPhrase = ap
}
}
Xsqlite3_free(tls, (*TFts5Expr)(unsafe.Pointer(p2)).FapExprPhrase)
Xsqlite3_free(tls, p2)
} else {
if p2 != 0 {
**(**uintptr)(__ccgo_up(pp1)) = p2
}
}
return (**(**TFts5Parse)(__ccgo_up(bp))).Frc
}
// C documentation
//
// /*
// ** Clear the position lists associated with all phrases in the expression
// ** passed as the first argument. Argument bLive is true if the expression
// ** might be pointing to a real entry, otherwise it has just been reset.
// **
// ** At present this function is only used for detail=col and detail=none
// ** fts5 tables. This implies that all phrases must be at most 1 token
// ** in size, as phrase matches are not supported without detail=full.
// */
func _sqlite3Fts5ExprClearPoslists(tls *libc.TLS, pExpr uintptr, bLive int32) (r uintptr) {
var i int32
var pBuf, pNode, pRet uintptr
_, _, _, _ = i, pBuf, pNode, pRet
pRet = Xsqlite3_malloc64(tls, uint64(uint64(16)*libc.Uint64FromInt32((*TFts5Expr)(unsafe.Pointer(pExpr)).FnPhrase)))
if pRet != 0 {
libc.X__builtin___memset_chk(tls, pRet, 0, uint64(16)*libc.Uint64FromInt32((*TFts5Expr)(unsafe.Pointer(pExpr)).FnPhrase), ^t__predefined_size_t(0))
i = 0
for {
if !(i < (*TFts5Expr)(unsafe.Pointer(pExpr)).FnPhrase) {
break
}
pBuf = **(**uintptr)(__ccgo_up((*TFts5Expr)(unsafe.Pointer(pExpr)).FapExprPhrase + uintptr(i)*8)) + 8
pNode = (*TFts5ExprPhrase)(unsafe.Pointer(**(**uintptr)(__ccgo_up((*TFts5Expr)(unsafe.Pointer(pExpr)).FapExprPhrase + uintptr(i)*8)))).FpNode
if bLive != 0 && ((*TFts5Buffer)(unsafe.Pointer(pBuf)).Fn == 0 || (*TFts5ExprNode)(unsafe.Pointer(pNode)).FiRowid != (*TFts5ExprNode)(unsafe.Pointer((*TFts5Expr)(unsafe.Pointer(pExpr)).FpRoot)).FiRowid || (*TFts5ExprNode)(unsafe.Pointer(pNode)).FbEof != 0) {
(**(**TFts5PoslistPopulator)(__ccgo_up(pRet + uintptr(i)*16))).FbMiss = int32(1)
} else {
(*TFts5Buffer)(unsafe.Pointer(pBuf)).Fn = 0
}
goto _1
_1:
;
i = i + 1
}
}
return pRet
}
// C documentation
//
// /*
// ** Create a new FTS5 expression by cloning phrase iPhrase of the
// ** expression passed as the second argument.
// */
func _sqlite3Fts5ExprClonePhrase(tls *libc.TLS, pExpr uintptr, iPhrase int32, ppNew uintptr) (r int32) {
bp := tls.Alloc(32)
defer tls.Free(32)
var i, tflags int32
var nByte Tsqlite3_int64
var p, pColset, pColsetOrig, pNew, pOrig uintptr
var _ /* rc at bp+0 */ int32
var _ /* sCtx at bp+8 */ TTokenCtx
_, _, _, _, _, _, _, _ = i, nByte, p, pColset, pColsetOrig, pNew, pOrig, tflags
**(**int32)(__ccgo_up(bp)) = SQLITE_OK /* Return code */
pOrig = uintptr(0) /* The phrase extracted from pExpr */
pNew = uintptr(0) /* Expression to return via *ppNew */
**(**TTokenCtx)(__ccgo_up(bp + 8)) = TTokenCtx{} /* Context object for fts5ParseTokenize */
if !(pExpr != 0) || iPhrase < 0 || iPhrase >= (*TFts5Expr)(unsafe.Pointer(pExpr)).FnPhrase {
**(**int32)(__ccgo_up(bp)) = int32(SQLITE_RANGE)
} else {
pOrig = **(**uintptr)(__ccgo_up((*TFts5Expr)(unsafe.Pointer(pExpr)).FapExprPhrase + uintptr(iPhrase)*8))
pNew = _sqlite3Fts5MallocZero(tls, bp, int64(40))
}
if **(**int32)(__ccgo_up(bp)) == SQLITE_OK {
(*TFts5Expr)(unsafe.Pointer(pNew)).FapExprPhrase = _sqlite3Fts5MallocZero(tls, bp, int64(8))
}
if **(**int32)(__ccgo_up(bp)) == SQLITE_OK {
(*TFts5Expr)(unsafe.Pointer(pNew)).FpRoot = _sqlite3Fts5MallocZero(tls, bp, libc.Int64FromUint64(uint64(libc.UintptrFromInt32(0)+48)+libc.Uint64FromInt32(libc.Int32FromInt32(1))*libc.Uint64FromInt64(8)))
}
if **(**int32)(__ccgo_up(bp)) == SQLITE_OK {
(*TFts5ExprNode)(unsafe.Pointer((*TFts5Expr)(unsafe.Pointer(pNew)).FpRoot)).FpNear = _sqlite3Fts5MallocZero(tls, bp, libc.Int64FromUint64(uint64(libc.UintptrFromInt32(0)+24)+libc.Uint64FromInt32(libc.Int32FromInt32(2))*libc.Uint64FromInt64(8)))
}
if **(**int32)(__ccgo_up(bp)) == SQLITE_OK && pOrig != uintptr(0) {
pColsetOrig = (*TFts5ExprNearset)(unsafe.Pointer((*TFts5ExprNode)(unsafe.Pointer((*TFts5ExprPhrase)(unsafe.Pointer(pOrig)).FpNode)).FpNear)).FpColset
if pColsetOrig != 0 {
nByte = libc.Int64FromUint64(libc.Uint64FromInt64(8) * libc.Uint64FromInt32(((*TFts5Colset)(unsafe.Pointer(pColsetOrig)).FnCol+libc.Int32FromInt32(2))/libc.Int32FromInt32(2)))
pColset = _sqlite3Fts5MallocZero(tls, bp, nByte)
if pColset != 0 {
libc.X__builtin___memcpy_chk(tls, pColset, pColsetOrig, libc.Uint64FromInt64(nByte), ^t__predefined_size_t(0))
}
(*TFts5ExprNearset)(unsafe.Pointer((*TFts5ExprNode)(unsafe.Pointer((*TFts5Expr)(unsafe.Pointer(pNew)).FpRoot)).FpNear)).FpColset = pColset
}
}
if **(**int32)(__ccgo_up(bp)) == SQLITE_OK {
if (*TFts5ExprPhrase)(unsafe.Pointer(pOrig)).FnTerm != 0 { /* Used to iterate through phrase terms */
(**(**TTokenCtx)(__ccgo_up(bp + 8))).FpConfig = (*TFts5Expr)(unsafe.Pointer(pExpr)).FpConfig
i = 0
for {
if !(**(**int32)(__ccgo_up(bp)) == SQLITE_OK && i < (*TFts5ExprPhrase)(unsafe.Pointer(pOrig)).FnTerm) {
break
}
tflags = 0
p = pOrig + 32 + uintptr(i)*40
for {
if !(p != 0 && **(**int32)(__ccgo_up(bp)) == SQLITE_OK) {
break
}
**(**int32)(__ccgo_up(bp)) = _fts5ParseTokenize(tls, bp+8, tflags, (*TFts5ExprTerm)(unsafe.Pointer(p)).FpTerm, (*TFts5ExprTerm)(unsafe.Pointer(p)).FnFullTerm, 0, 0)
tflags = int32(FTS5_TOKEN_COLOCATED)
goto _2
_2:
;
p = (*TFts5ExprTerm)(unsafe.Pointer(p)).FpSynonym
}
if **(**int32)(__ccgo_up(bp)) == SQLITE_OK {
(*(*TFts5ExprTerm)(unsafe.Pointer((**(**TTokenCtx)(__ccgo_up(bp + 8))).FpPhrase + 32 + uintptr(i)*40))).FbPrefix = (*(*TFts5ExprTerm)(unsafe.Pointer(pOrig + 32 + uintptr(i)*40))).FbPrefix
(*(*TFts5ExprTerm)(unsafe.Pointer((**(**TTokenCtx)(__ccgo_up(bp + 8))).FpPhrase + 32 + uintptr(i)*40))).FbFirst = (*(*TFts5ExprTerm)(unsafe.Pointer(pOrig + 32 + uintptr(i)*40))).FbFirst
}
goto _1
_1:
;
i = i + 1
}
} else {
/* This happens when parsing a token or quoted phrase that contains
** no token characters at all. (e.g ... MATCH '""'). */
(**(**TTokenCtx)(__ccgo_up(bp + 8))).FpPhrase = _sqlite3Fts5MallocZero(tls, bp, libc.Int64FromUint64(uint64(libc.UintptrFromInt32(0)+32)+libc.Uint64FromInt32(libc.Int32FromInt32(1))*libc.Uint64FromInt64(40)))
}
}
if **(**int32)(__ccgo_up(bp)) == SQLITE_OK && (**(**TTokenCtx)(__ccgo_up(bp + 8))).FpPhrase != 0 {
/* All the allocations succeeded. Put the expression object together. */
(*TFts5Expr)(unsafe.Pointer(pNew)).FpIndex = (*TFts5Expr)(unsafe.Pointer(pExpr)).FpIndex
(*TFts5Expr)(unsafe.Pointer(pNew)).FpConfig = (*TFts5Expr)(unsafe.Pointer(pExpr)).FpConfig
(*TFts5Expr)(unsafe.Pointer(pNew)).FnPhrase = int32(1)
**(**uintptr)(__ccgo_up((*TFts5Expr)(unsafe.Pointer(pNew)).FapExprPhrase)) = (**(**TTokenCtx)(__ccgo_up(bp + 8))).FpPhrase
*(*uintptr)(unsafe.Pointer((*TFts5ExprNode)(unsafe.Pointer((*TFts5Expr)(unsafe.Pointer(pNew)).FpRoot)).FpNear + 24)) = (**(**TTokenCtx)(__ccgo_up(bp + 8))).FpPhrase
(*TFts5ExprNearset)(unsafe.Pointer((*TFts5ExprNode)(unsafe.Pointer((*TFts5Expr)(unsafe.Pointer(pNew)).FpRoot)).FpNear)).FnPhrase = int32(1)
(*TFts5ExprPhrase)(unsafe.Pointer((**(**TTokenCtx)(__ccgo_up(bp + 8))).FpPhrase)).FpNode = (*TFts5Expr)(unsafe.Pointer(pNew)).FpRoot
if (*TFts5ExprPhrase)(unsafe.Pointer(pOrig)).FnTerm == int32(1) && (*(*TFts5ExprTerm)(unsafe.Pointer(pOrig + 32))).FpSynonym == uintptr(0) && libc.Int32FromUint8((*(*TFts5ExprTerm)(unsafe.Pointer(pOrig + 32))).FbFirst) == 0 {
(*TFts5ExprNode)(unsafe.Pointer((*TFts5Expr)(unsafe.Pointer(pNew)).FpRoot)).FeType = int32(FTS5_TERM)
(*TFts5ExprNode)(unsafe.Pointer((*TFts5Expr)(unsafe.Pointer(pNew)).FpRoot)).FxNext = __ccgo_fp(_fts5ExprNodeNext_TERM)
} else {
(*TFts5ExprNode)(unsafe.Pointer((*TFts5Expr)(unsafe.Pointer(pNew)).FpRoot)).FeType = int32(FTS5_STRING)
(*TFts5ExprNode)(unsafe.Pointer((*TFts5Expr)(unsafe.Pointer(pNew)).FpRoot)).FxNext = __ccgo_fp(_fts5ExprNodeNext_STRING)
}
} else {
_sqlite3Fts5ExprFree(tls, pNew)
_fts5ExprPhraseFree(tls, (**(**TTokenCtx)(__ccgo_up(bp + 8))).FpPhrase)
pNew = uintptr(0)
}
**(**uintptr)(__ccgo_up(ppNew)) = pNew
return **(**int32)(__ccgo_up(bp))
}
func _sqlite3Fts5ExprNew(tls *libc.TLS, pConfig uintptr, bPhraseToAnd int32, iCol int32, zExpr uintptr, ppNew uintptr, pzErr uintptr) (r int32) {
bp := tls.Alloc(80)
defer tls.Free(80)
var n, t int32
var pColset, pEngine, pNew, v1 uintptr
var _ /* sParse at bp+0 */ TFts5Parse
var _ /* token at bp+48 */ TFts5Token
var _ /* z at bp+64 */ uintptr
_, _, _, _, _, _ = n, pColset, pEngine, pNew, t, v1
**(**uintptr)(__ccgo_up(bp + 64)) = zExpr
**(**uintptr)(__ccgo_up(ppNew)) = uintptr(0)
**(**uintptr)(__ccgo_up(pzErr)) = uintptr(0)
libc.X__builtin___memset_chk(tls, bp, 0, uint64(48), ^t__predefined_size_t(0))
(**(**TFts5Parse)(__ccgo_up(bp))).FbPhraseToAnd = bPhraseToAnd
pEngine = _sqlite3Fts5ParserAlloc(tls, __ccgo_fp(_fts5ParseAlloc))
if pEngine == uintptr(0) {
return int32(SQLITE_NOMEM)
}
(**(**TFts5Parse)(__ccgo_up(bp))).FpConfig = pConfig
for cond := true; cond; cond = (**(**TFts5Parse)(__ccgo_up(bp))).Frc == SQLITE_OK && t != FTS5_EOF {
t = _fts5ExprGetToken(tls, bp, bp+64, bp+48)
_sqlite3Fts5Parser(tls, pEngine, t, **(**TFts5Token)(__ccgo_up(bp + 48)), bp)
}
_sqlite3Fts5ParserFree(tls, pEngine, __ccgo_fp(_fts5ParseFree))
/* If the LHS of the MATCH expression was a user column, apply the
** implicit column-filter. */
if (**(**TFts5Parse)(__ccgo_up(bp))).Frc == SQLITE_OK && iCol < (*TFts5Config)(unsafe.Pointer(pConfig)).FnCol {
n = libc.Int32FromUint64(libc.Uint64FromInt64(8) * libc.Uint64FromInt32((libc.Int32FromInt32(1)+libc.Int32FromInt32(2))/libc.Int32FromInt32(2)))
pColset = _sqlite3Fts5MallocZero(tls, bp+16, int64(n))
if pColset != 0 {
(*TFts5Colset)(unsafe.Pointer(pColset)).FnCol = int32(1)
*(*int32)(unsafe.Pointer(pColset + 4)) = iCol
_sqlite3Fts5ParseSetColset(tls, bp, (**(**TFts5Parse)(__ccgo_up(bp))).FpExpr, pColset)
}
}
if (**(**TFts5Parse)(__ccgo_up(bp))).Frc == SQLITE_OK {
v1 = Xsqlite3_malloc64(tls, uint64(40))
pNew = v1
**(**uintptr)(__ccgo_up(ppNew)) = v1
if pNew == uintptr(0) {
(**(**TFts5Parse)(__ccgo_up(bp))).Frc = int32(SQLITE_NOMEM)
_sqlite3Fts5ParseNodeFree(tls, (**(**TFts5Parse)(__ccgo_up(bp))).FpExpr)
} else {
(*TFts5Expr)(unsafe.Pointer(pNew)).FpRoot = (**(**TFts5Parse)(__ccgo_up(bp))).FpExpr
(*TFts5Expr)(unsafe.Pointer(pNew)).FpIndex = uintptr(0)
(*TFts5Expr)(unsafe.Pointer(pNew)).FpConfig = pConfig
(*TFts5Expr)(unsafe.Pointer(pNew)).FapExprPhrase = (**(**TFts5Parse)(__ccgo_up(bp))).FapPhrase
(*TFts5Expr)(unsafe.Pointer(pNew)).FnPhrase = (**(**TFts5Parse)(__ccgo_up(bp))).FnPhrase
(*TFts5Expr)(unsafe.Pointer(pNew)).FbDesc = 0
(**(**TFts5Parse)(__ccgo_up(bp))).FapPhrase = uintptr(0)
}
} else {
_sqlite3Fts5ParseNodeFree(tls, (**(**TFts5Parse)(__ccgo_up(bp))).FpExpr)
}
Xsqlite3_free(tls, (**(**TFts5Parse)(__ccgo_up(bp))).FapPhrase)
if uintptr(0) == **(**uintptr)(__ccgo_up(pzErr)) {
**(**uintptr)(__ccgo_up(pzErr)) = (**(**TFts5Parse)(__ccgo_up(bp))).FzErr
} else {
Xsqlite3_free(tls, (**(**TFts5Parse)(__ccgo_up(bp))).FzErr)
}
return (**(**TFts5Parse)(__ccgo_up(bp))).Frc
}
// C documentation
//
// /*
// ** Empty (but do not delete) a hash table.
// */
func _sqlite3Fts5HashClear(tls *libc.TLS, pHash uintptr) {
var i int32
var pNext, pSlot uintptr
_, _, _ = i, pNext, pSlot
i = 0
for {
if !(i < (*TFts5Hash)(unsafe.Pointer(pHash)).FnSlot) {
break
}
pSlot = **(**uintptr)(__ccgo_up((*TFts5Hash)(unsafe.Pointer(pHash)).FaSlot + uintptr(i)*8))
for {
if !(pSlot != 0) {
break
}
pNext = (*TFts5HashEntry)(unsafe.Pointer(pSlot)).FpHashNext
Xsqlite3_free(tls, pSlot)
goto _2
_2:
;
pSlot = pNext
}
goto _1
_1:
;
i = i + 1
}
libc.X__builtin___memset_chk(tls, (*TFts5Hash)(unsafe.Pointer(pHash)).FaSlot, 0, libc.Uint64FromInt32((*TFts5Hash)(unsafe.Pointer(pHash)).FnSlot)*uint64(8), ^t__predefined_size_t(0))
(*TFts5Hash)(unsafe.Pointer(pHash)).FnEntry = 0
}
// C documentation
//
// /*
// ** Allocate a new hash table.
// */
func _sqlite3Fts5HashNew(tls *libc.TLS, pConfig uintptr, ppNew uintptr, pnByte uintptr) (r int32) {
var nByte Tsqlite3_int64
var pNew, v1 uintptr
var rc int32
_, _, _, _ = nByte, pNew, rc, v1
rc = SQLITE_OK
v1 = Xsqlite3_malloc64(tls, uint64(40))
pNew = v1
**(**uintptr)(__ccgo_up(ppNew)) = v1
if pNew == uintptr(0) {
rc = int32(SQLITE_NOMEM)
} else {
libc.X__builtin___memset_chk(tls, pNew, 0, uint64(40), ^t__predefined_size_t(0))
(*TFts5Hash)(unsafe.Pointer(pNew)).FpnByte = pnByte
(*TFts5Hash)(unsafe.Pointer(pNew)).FeDetail = (*TFts5Config)(unsafe.Pointer(pConfig)).FeDetail
(*TFts5Hash)(unsafe.Pointer(pNew)).FnSlot = int32(1024)
nByte = libc.Int64FromUint64(uint64(8) * libc.Uint64FromInt32((*TFts5Hash)(unsafe.Pointer(pNew)).FnSlot))
(*TFts5Hash)(unsafe.Pointer(pNew)).FaSlot = Xsqlite3_malloc64(tls, libc.Uint64FromInt64(nByte))
if (*TFts5Hash)(unsafe.Pointer(pNew)).FaSlot == uintptr(0) {
Xsqlite3_free(tls, pNew)
**(**uintptr)(__ccgo_up(ppNew)) = uintptr(0)
rc = int32(SQLITE_NOMEM)
} else {
libc.X__builtin___memset_chk(tls, (*TFts5Hash)(unsafe.Pointer(pNew)).FaSlot, 0, libc.Uint64FromInt64(nByte), ^t__predefined_size_t(0))
}
}
return rc
}
// C documentation
//
// /*
// ** Query the hash table for a doclist associated with term pTerm/nTerm.
// */
func _sqlite3Fts5HashQuery(tls *libc.TLS, pHash uintptr, nPre int32, pTerm uintptr, nTerm int32, ppOut uintptr, pnDoclist uintptr) (r int32) {
var iHash uint32
var nHashPre, nList int32
var p, pFaux, pRet, zKey, v2 uintptr
_, _, _, _, _, _, _, _ = iHash, nHashPre, nList, p, pFaux, pRet, zKey, v2
iHash = _fts5HashKey(tls, (*TFts5Hash)(unsafe.Pointer(pHash)).FnSlot, pTerm, nTerm)
zKey = uintptr(0)
p = **(**uintptr)(__ccgo_up((*TFts5Hash)(unsafe.Pointer(pHash)).FaSlot + uintptr(iHash)*8))
for {
if !(p != 0) {
break
}
zKey = p + 1*48
if nTerm == (*TFts5HashEntry)(unsafe.Pointer(p)).FnKey && libc.Xmemcmp(tls, zKey, pTerm, libc.Uint64FromInt32(nTerm)) == 0 {
break
}
goto _1
_1:
;
p = (*TFts5HashEntry)(unsafe.Pointer(p)).FpHashNext
}
if p != 0 {
nHashPre = libc.Int32FromUint64(uint64(48) + libc.Uint64FromInt32(nTerm))
nList = (*TFts5HashEntry)(unsafe.Pointer(p)).FnData - nHashPre
v2 = Xsqlite3_malloc64(tls, libc.Uint64FromInt32(nPre+nList+int32(10)))
**(**uintptr)(__ccgo_up(ppOut)) = v2
pRet = v2
if pRet != 0 {
pFaux = pRet + uintptr(nPre-nHashPre)
libc.X__builtin___memcpy_chk(tls, pRet+uintptr(nPre), p+uintptr(nHashPre), libc.Uint64FromInt32(nList), ^t__predefined_size_t(0))
nList = nList + _fts5HashAddPoslistSize(tls, pHash, p, pFaux)
**(**int32)(__ccgo_up(pnDoclist)) = nList
} else {
**(**int32)(__ccgo_up(pnDoclist)) = 0
return int32(SQLITE_NOMEM)
}
} else {
**(**uintptr)(__ccgo_up(ppOut)) = uintptr(0)
**(**int32)(__ccgo_up(pnDoclist)) = 0
}
return SQLITE_OK
}
// C documentation
//
// /*
// ** Add an entry to the in-memory hash table. The key is the concatenation
// ** of bByte and (pToken/nToken). The value is (iRowid/iCol/iPos).
// **
// ** (bByte || pToken) -> (iRowid,iCol,iPos)
// **
// ** Or, if iCol is negative, then the value is a delete marker.
// */
func _sqlite3Fts5HashWrite(tls *libc.TLS, pHash uintptr, iRowid Ti64, iCol int32, iPos int32, bByte int8, pToken uintptr, nToken int32) (r int32) {
var bNew, nIncr, rc, v2 int32
var iDiff Tu64
var iHash uint32
var nByte, nNew Tsqlite3_int64
var p, pNew, pPtr, pp, zKey, zKey1, v6 uintptr
_, _, _, _, _, _, _, _, _, _, _, _, _, _, _ = bNew, iDiff, iHash, nByte, nIncr, nNew, p, pNew, pPtr, pp, rc, zKey, zKey1, v2, v6
nIncr = 0 /* If non-delete entry should be written */
bNew = libc.BoolInt32((*TFts5Hash)(unsafe.Pointer(pHash)).FeDetail == FTS5_DETAIL_FULL)
/* Attempt to locate an existing hash entry */
iHash = _fts5HashKey2(tls, (*TFts5Hash)(unsafe.Pointer(pHash)).FnSlot, libc.Uint8FromInt8(bByte), pToken, nToken)
p = **(**uintptr)(__ccgo_up((*TFts5Hash)(unsafe.Pointer(pHash)).FaSlot + uintptr(iHash)*8))
for {
if !(p != 0) {
break
}
zKey = p + 1*48
if int32(**(**int8)(__ccgo_up(zKey))) == int32(bByte) && (*TFts5HashEntry)(unsafe.Pointer(p)).FnKey == nToken+int32(1) && libc.Xmemcmp(tls, zKey+1, pToken, libc.Uint64FromInt32(nToken)) == 0 {
break
}
goto _1
_1:
;
p = (*TFts5HashEntry)(unsafe.Pointer(p)).FpHashNext
}
/* If an existing hash entry cannot be found, create a new one. */
if p == uintptr(0) {
nByte = libc.Int64FromUint64(uint64(48) + libc.Uint64FromInt32(nToken+libc.Int32FromInt32(1)) + uint64(1) + uint64(64))
if nByte < int64(128) {
nByte = int64(128)
}
/* Grow the Fts5Hash.aSlot[] array if necessary. */
if (*TFts5Hash)(unsafe.Pointer(pHash)).FnEntry*int32(2) >= (*TFts5Hash)(unsafe.Pointer(pHash)).FnSlot {
rc = _fts5HashResize(tls, pHash)
if rc != SQLITE_OK {
return rc
}
iHash = _fts5HashKey2(tls, (*TFts5Hash)(unsafe.Pointer(pHash)).FnSlot, libc.Uint8FromInt8(bByte), pToken, nToken)
}
/* Allocate new Fts5HashEntry and add it to the hash table. */
p = Xsqlite3_malloc64(tls, libc.Uint64FromInt64(nByte))
if !(p != 0) {
return int32(SQLITE_NOMEM)
}
libc.X__builtin___memset_chk(tls, p, 0, uint64(48), ^t__predefined_size_t(0))
(*TFts5HashEntry)(unsafe.Pointer(p)).FnAlloc = int32(nByte)
zKey1 = p + 1*48
**(**int8)(__ccgo_up(zKey1)) = bByte
libc.X__builtin___memcpy_chk(tls, zKey1+1, pToken, libc.Uint64FromInt32(nToken), ^t__predefined_size_t(0))
(*TFts5HashEntry)(unsafe.Pointer(p)).FnKey = nToken + int32(1)
**(**int8)(__ccgo_up(zKey1 + uintptr(nToken+int32(1)))) = int8('\000')
(*TFts5HashEntry)(unsafe.Pointer(p)).FnData = libc.Int32FromUint64(libc.Uint64FromInt32(nToken+int32(1)) + uint64(48))
(*TFts5HashEntry)(unsafe.Pointer(p)).FpHashNext = **(**uintptr)(__ccgo_up((*TFts5Hash)(unsafe.Pointer(pHash)).FaSlot + uintptr(iHash)*8))
**(**uintptr)(__ccgo_up((*TFts5Hash)(unsafe.Pointer(pHash)).FaSlot + uintptr(iHash)*8)) = p
(*TFts5Hash)(unsafe.Pointer(pHash)).FnEntry = (*TFts5Hash)(unsafe.Pointer(pHash)).FnEntry + 1
/* Add the first rowid field to the hash-entry */
**(**int32)(__ccgo_up(p + 24)) += _sqlite3Fts5PutVarint(tls, p+uintptr((*TFts5HashEntry)(unsafe.Pointer(p)).FnData), libc.Uint64FromInt64(iRowid))
(*TFts5HashEntry)(unsafe.Pointer(p)).FiRowid = iRowid
(*TFts5HashEntry)(unsafe.Pointer(p)).FiSzPoslist = (*TFts5HashEntry)(unsafe.Pointer(p)).FnData
if (*TFts5Hash)(unsafe.Pointer(pHash)).FeDetail != int32(FTS5_DETAIL_NONE) {
**(**int32)(__ccgo_up(p + 24)) += int32(1)
if (*TFts5Hash)(unsafe.Pointer(pHash)).FeDetail == FTS5_DETAIL_FULL {
v2 = 0
} else {
v2 = -int32(1)
}
(*TFts5HashEntry)(unsafe.Pointer(p)).FiCol = int16(v2)
}
} else {
/* Appending to an existing hash-entry. Check that there is enough
** space to append the largest possible new entry. Worst case scenario
** is:
**
** + 9 bytes for a new rowid,
** + 4 byte reserved for the "poslist size" varint.
** + 1 byte for a "new column" byte,
** + 3 bytes for a new column number (16-bit max) as a varint,
** + 5 bytes for the new position offset (32-bit max).
*/
if (*TFts5HashEntry)(unsafe.Pointer(p)).FnAlloc-(*TFts5HashEntry)(unsafe.Pointer(p)).FnData < libc.Int32FromInt32(9)+libc.Int32FromInt32(4)+libc.Int32FromInt32(1)+libc.Int32FromInt32(3)+libc.Int32FromInt32(5) {
nNew = int64((*TFts5HashEntry)(unsafe.Pointer(p)).FnAlloc * int32(2))
pNew = Xsqlite3_realloc64(tls, p, libc.Uint64FromInt64(nNew))
if pNew == uintptr(0) {
return int32(SQLITE_NOMEM)
}
(*TFts5HashEntry)(unsafe.Pointer(pNew)).FnAlloc = int32(nNew)
pp = (*TFts5Hash)(unsafe.Pointer(pHash)).FaSlot + uintptr(iHash)*8
for {
if !(**(**uintptr)(__ccgo_up(pp)) != p) {
break
}
goto _3
_3:
;
pp = **(**uintptr)(__ccgo_up(pp))
}
**(**uintptr)(__ccgo_up(pp)) = pNew
p = pNew
}
nIncr = nIncr - (*TFts5HashEntry)(unsafe.Pointer(p)).FnData
}
pPtr = p
/* If this is a new rowid, append the 4-byte size field for the previous
** entry, and the new rowid for this entry. */
if iRowid != (*TFts5HashEntry)(unsafe.Pointer(p)).FiRowid {
iDiff = libc.Uint64FromInt64(iRowid) - libc.Uint64FromInt64((*TFts5HashEntry)(unsafe.Pointer(p)).FiRowid)
_fts5HashAddPoslistSize(tls, pHash, p, uintptr(0))
**(**int32)(__ccgo_up(p + 24)) += _sqlite3Fts5PutVarint(tls, pPtr+uintptr((*TFts5HashEntry)(unsafe.Pointer(p)).FnData), iDiff)
(*TFts5HashEntry)(unsafe.Pointer(p)).FiRowid = iRowid
bNew = int32(1)
(*TFts5HashEntry)(unsafe.Pointer(p)).FiSzPoslist = (*TFts5HashEntry)(unsafe.Pointer(p)).FnData
if (*TFts5Hash)(unsafe.Pointer(pHash)).FeDetail != int32(FTS5_DETAIL_NONE) {
**(**int32)(__ccgo_up(p + 24)) += int32(1)
if (*TFts5Hash)(unsafe.Pointer(pHash)).FeDetail == FTS5_DETAIL_FULL {
v2 = 0
} else {
v2 = -int32(1)
}
(*TFts5HashEntry)(unsafe.Pointer(p)).FiCol = int16(v2)
(*TFts5HashEntry)(unsafe.Pointer(p)).FiPos = 0
}
}
if iCol >= 0 {
if (*TFts5Hash)(unsafe.Pointer(pHash)).FeDetail == int32(FTS5_DETAIL_NONE) {
(*TFts5HashEntry)(unsafe.Pointer(p)).FbContent = uint8(1)
} else {
/* Append a new column value, if necessary */
if iCol != int32((*TFts5HashEntry)(unsafe.Pointer(p)).FiCol) {
if (*TFts5Hash)(unsafe.Pointer(pHash)).FeDetail == FTS5_DETAIL_FULL {
v6 = p + 24
v2 = *(*int32)(unsafe.Pointer(v6))
*(*int32)(unsafe.Pointer(v6)) = *(*int32)(unsafe.Pointer(v6)) + 1
**(**Tu8)(__ccgo_up(pPtr + uintptr(v2))) = uint8(0x01)
**(**int32)(__ccgo_up(p + 24)) += _sqlite3Fts5PutVarint(tls, pPtr+uintptr((*TFts5HashEntry)(unsafe.Pointer(p)).FnData), libc.Uint64FromInt32(iCol))
(*TFts5HashEntry)(unsafe.Pointer(p)).FiCol = int16(iCol)
(*TFts5HashEntry)(unsafe.Pointer(p)).FiPos = 0
} else {
bNew = int32(1)
v2 = iCol
iPos = v2
(*TFts5HashEntry)(unsafe.Pointer(p)).FiCol = int16(v2)
}
}
/* Append the new position offset, if necessary */
if bNew != 0 {
**(**int32)(__ccgo_up(p + 24)) += _sqlite3Fts5PutVarint(tls, pPtr+uintptr((*TFts5HashEntry)(unsafe.Pointer(p)).FnData), libc.Uint64FromInt32(iPos-(*TFts5HashEntry)(unsafe.Pointer(p)).FiPos+int32(2)))
(*TFts5HashEntry)(unsafe.Pointer(p)).FiPos = iPos
}
}
} else {
/* This is a delete. Set the delete flag. */
(*TFts5HashEntry)(unsafe.Pointer(p)).FbDel = uint8(1)
}
nIncr = nIncr + (*TFts5HashEntry)(unsafe.Pointer(p)).FnData
**(**int32)(__ccgo_up((*TFts5Hash)(unsafe.Pointer(pHash)).FpnByte)) += nIncr
return SQLITE_OK
}
// C documentation
//
// /*
// ** Read and decode the "averages" record from the database.
// **
// ** Parameter anSize must point to an array of size nCol, where nCol is
// ** the number of user defined columns in the FTS table.
// */
func _sqlite3Fts5IndexGetAverages(tls *libc.TLS, p uintptr, pnRow uintptr, anSize uintptr) (r int32) {
var i, iCol, nCol int32
var pData uintptr
_, _, _, _ = i, iCol, nCol, pData
nCol = (*TFts5Config)(unsafe.Pointer((*TFts5Index)(unsafe.Pointer(p)).FpConfig)).FnCol
**(**Ti64)(__ccgo_up(pnRow)) = 0
libc.X__builtin___memset_chk(tls, anSize, 0, uint64(8)*libc.Uint64FromInt32(nCol), ^t__predefined_size_t(0))
pData = _fts5DataRead(tls, p, int64(FTS5_AVERAGES_ROWID))
if (*TFts5Index)(unsafe.Pointer(p)).Frc == SQLITE_OK && (*TFts5Data)(unsafe.Pointer(pData)).Fnn != 0 {
i = 0
i = i + libc.Int32FromUint8(_sqlite3Fts5GetVarint(tls, (*TFts5Data)(unsafe.Pointer(pData)).Fp+uintptr(i), pnRow))
iCol = 0
for {
if !(i < (*TFts5Data)(unsafe.Pointer(pData)).Fnn && iCol < nCol) {
break
}
i = i + libc.Int32FromUint8(_sqlite3Fts5GetVarint(tls, (*TFts5Data)(unsafe.Pointer(pData)).Fp+uintptr(i), anSize+uintptr(iCol)*8))
goto _1
_1:
;
iCol = iCol + 1
}
}
_fts5DataRelease(tls, pData)
return _fts5IndexReturn(tls, p)
}
// C documentation
//
// /*
// ** Run internal checks to ensure that the FTS index (a) is internally
// ** consistent and (b) contains entries for which the XOR of the checksums
// ** as calculated by sqlite3Fts5IndexEntryCksum() is cksum.
// **
// ** Return SQLITE_CORRUPT if any of the internal checks fail, or if the
// ** checksum does not match. Return SQLITE_OK if all checks pass without
// ** error, or some other SQLite error code if another error (e.g. OOM)
// ** occurs.
// */
func _sqlite3Fts5IndexIntegrityCheck(tls *libc.TLS, p uintptr, cksum Tu64, bUseCksum int32) (r int32) {
bp := tls.Alloc(64)
defer tls.Free(64)
var cksum2 Tu64
var eDetail, flags, iCol, iLvl, iSeg, iTokOff int32
var iRowid Ti64
var pSeg, pStruct, z uintptr
var _ /* iOff at bp+40 */ int32
var _ /* iPos at bp+32 */ Ti64
var _ /* n at bp+24 */ int32
var _ /* pIter at bp+16 */ uintptr
var _ /* poslist at bp+0 */ TFts5Buffer
_, _, _, _, _, _, _, _, _, _, _ = cksum2, eDetail, flags, iCol, iLvl, iRowid, iSeg, iTokOff, pSeg, pStruct, z
eDetail = (*TFts5Config)(unsafe.Pointer((*TFts5Index)(unsafe.Pointer(p)).FpConfig)).FeDetail
cksum2 = uint64(0) /* Checksum based on contents of indexes */
**(**TFts5Buffer)(__ccgo_up(bp)) = TFts5Buffer{}
flags = int32(FTS5INDEX_QUERY_NOOUTPUT)
/* Load the FTS index structure */
pStruct = _fts5StructureRead(tls, p)
if pStruct == uintptr(0) {
return _fts5IndexReturn(tls, p)
}
/* Check that the internal nodes of each segment match the leaves */
iLvl = 0
for {
if !(iLvl < (*TFts5Structure)(unsafe.Pointer(pStruct)).FnLevel) {
break
}
iSeg = 0
for {
if !(iSeg < (*(*TFts5StructureLevel)(unsafe.Pointer(pStruct + 32 + uintptr(iLvl)*16))).FnSeg) {
break
}
pSeg = (*(*TFts5StructureLevel)(unsafe.Pointer(pStruct + 32 + uintptr(iLvl)*16))).FaSeg + uintptr(iSeg)*56
_fts5IndexIntegrityCheckSegment(tls, p, pSeg)
goto _2
_2:
;
iSeg = iSeg + 1
}
goto _1
_1:
;
iLvl = iLvl + 1
}
/* The cksum argument passed to this function is a checksum calculated
** based on all expected entries in the FTS index (including prefix index
** entries). This block checks that a checksum calculated based on the
** actual contents of FTS index is identical.
**
** Two versions of the same checksum are calculated. The first (stack
** variable cksum2) based on entries extracted from the full-text index
** while doing a linear scan of each individual index in turn.
**
** As each term visited by the linear scans, a separate query for the
** same term is performed. cksum3 is calculated based on the entries
** extracted by these queries.
*/
_fts5MultiIterNew(tls, p, pStruct, flags, uintptr(0), uintptr(0), 0, -int32(1), 0, bp+16)
for {
if !(_fts5MultiIterEof(tls, p, **(**uintptr)(__ccgo_up(bp + 16))) == 0) {
break
} /* Size of term in bytes */
**(**Ti64)(__ccgo_up(bp + 32)) = 0 /* Position read from poslist */
**(**int32)(__ccgo_up(bp + 40)) = 0 /* Offset within poslist */
iRowid = _fts5MultiIterRowid(tls, **(**uintptr)(__ccgo_up(bp + 16)))
z = _fts5MultiIterTerm(tls, **(**uintptr)(__ccgo_up(bp + 16)), bp+24)
/* If this is a new term, query for it. Update cksum3 with the results. */
if (*TFts5Index)(unsafe.Pointer(p)).Frc != 0 {
break
}
if eDetail == int32(FTS5_DETAIL_NONE) {
if 0 == _fts5MultiIterIsEmpty(tls, p, **(**uintptr)(__ccgo_up(bp + 16))) {
cksum2 = cksum2 ^ _sqlite3Fts5IndexEntryCksum(tls, iRowid, 0, 0, -int32(1), z, **(**int32)(__ccgo_up(bp + 24)))
}
} else {
(**(**TFts5Buffer)(__ccgo_up(bp))).Fn = 0
_fts5SegiterPoslist(tls, p, **(**uintptr)(__ccgo_up(bp + 16))+104+uintptr((**(**TFts5CResult)(__ccgo_up((*TFts5Iter)(unsafe.Pointer(**(**uintptr)(__ccgo_up(bp + 16)))).FaFirst + 1*4))).FiFirst)*128, uintptr(0), bp)
_sqlite3Fts5BufferAppendBlob(tls, p+60, bp, uint32(4), __ccgo_ts+40061)
for 0 == _sqlite3Fts5PoslistNext64(tls, (**(**TFts5Buffer)(__ccgo_up(bp))).Fp, (**(**TFts5Buffer)(__ccgo_up(bp))).Fn, bp+40, bp+32) {
iCol = int32(**(**Ti64)(__ccgo_up(bp + 32)) >> libc.Int32FromInt32(32) & libc.Int64FromInt32(0x7FFFFFFF))
iTokOff = int32(**(**Ti64)(__ccgo_up(bp + 32)) & libc.Int64FromInt32(0x7FFFFFFF))
cksum2 = cksum2 ^ _sqlite3Fts5IndexEntryCksum(tls, iRowid, iCol, iTokOff, -int32(1), z, **(**int32)(__ccgo_up(bp + 24)))
}
}
goto _3
_3:
;
_fts5MultiIterNext(tls, p, **(**uintptr)(__ccgo_up(bp + 16)), 0, 0)
}
_fts5MultiIterFree(tls, **(**uintptr)(__ccgo_up(bp + 16)))
if (*TFts5Index)(unsafe.Pointer(p)).Frc == SQLITE_OK && bUseCksum != 0 && cksum != cksum2 {
(*TFts5Index)(unsafe.Pointer(p)).Frc = libc.Int32FromInt32(SQLITE_CORRUPT) | libc.Int32FromInt32(1)< 0 {
libc.X__builtin___memcpy_chk(tls, (**(**TFts5Buffer)(__ccgo_up(bp + 8))).Fp+1, pToken, libc.Uint64FromInt32(nToken), ^t__predefined_size_t(0))
}
/* The NOTOKENDATA flag is set when each token in a tokendata=1 table
** should be treated individually, instead of merging all those with
** a common prefix into a single entry. This is used, for example, by
** queries performed as part of an integrity-check, or by the fts5vocab
** module. */
if flags&(libc.Int32FromInt32(FTS5INDEX_QUERY_NOTOKENDATA)|libc.Int32FromInt32(FTS5INDEX_QUERY_SCAN)) != 0 {
bTokendata = 0
}
/* Figure out which index to search and set iIdx accordingly. If this
** is a prefix query for which there is no prefix index, set iIdx to
** greater than pConfig->nPrefix to indicate that the query will be
** satisfied by scanning multiple terms in the main index.
**
** If the QUERY_TEST_NOIDX flag was specified, then this must be a
** prefix-query. Instead of using a prefix-index (if one exists),
** evaluate the prefix query using the main FTS index. This is used
** for internal sanity checking by the integrity-check in debug
** mode only. */
if flags&int32(FTS5INDEX_QUERY_PREFIX) != 0 {
nChar = _fts5IndexCharlen(tls, pToken, nToken)
iIdx = int32(1)
for {
if !(iIdx <= (*TFts5Config)(unsafe.Pointer(pConfig)).FnPrefix) {
break
}
nIdxChar = **(**int32)(__ccgo_up((*TFts5Config)(unsafe.Pointer(pConfig)).FaPrefix + uintptr(iIdx-int32(1))*4))
if nIdxChar == nChar {
break
}
if nIdxChar == nChar+int32(1) {
iPrefixIdx = iIdx
}
goto _1
_1:
;
iIdx = iIdx + 1
}
}
if bTokendata != 0 && iIdx == 0 {
**(**Tu8)(__ccgo_up((**(**TFts5Buffer)(__ccgo_up(bp + 8))).Fp)) = uint8('0')
**(**uintptr)(__ccgo_up(bp)) = _fts5SetupTokendataIter(tls, p, (**(**TFts5Buffer)(__ccgo_up(bp + 8))).Fp, nToken+int32(1), pColset)
} else {
if iIdx <= (*TFts5Config)(unsafe.Pointer(pConfig)).FnPrefix {
/* Straight index lookup */
pStruct = _fts5StructureRead(tls, p)
**(**Tu8)(__ccgo_up((**(**TFts5Buffer)(__ccgo_up(bp + 8))).Fp)) = libc.Uint8FromInt32(libc.Int32FromUint8('0') + iIdx)
if pStruct != 0 {
_fts5MultiIterNew(tls, p, pStruct, flags|int32(FTS5INDEX_QUERY_SKIPEMPTY), pColset, (**(**TFts5Buffer)(__ccgo_up(bp + 8))).Fp, nToken+int32(1), -int32(1), 0, bp)
_fts5StructureRelease(tls, pStruct)
}
} else {
/* Scan multiple terms in the main index for a prefix query. */
bDesc = libc.BoolInt32(flags&int32(FTS5INDEX_QUERY_DESC) != 0)
_fts5SetupPrefixIter(tls, p, bDesc, iPrefixIdx, (**(**TFts5Buffer)(__ccgo_up(bp + 8))).Fp, nToken+int32(1), pColset, bp)
if **(**uintptr)(__ccgo_up(bp)) == uintptr(0) {
} else {
_fts5IterSetOutputCb(tls, p+60, **(**uintptr)(__ccgo_up(bp)))
if (*TFts5Index)(unsafe.Pointer(p)).Frc == SQLITE_OK {
pSeg = **(**uintptr)(__ccgo_up(bp)) + 104 + uintptr((**(**TFts5CResult)(__ccgo_up((*TFts5Iter)(unsafe.Pointer(**(**uintptr)(__ccgo_up(bp)))).FaFirst + 1*4))).FiFirst)*128
if (*TFts5SegIter)(unsafe.Pointer(pSeg)).FpLeaf != 0 {
(*(*func(*libc.TLS, uintptr, uintptr))(unsafe.Pointer(&struct{ uintptr }{(*TFts5Iter)(unsafe.Pointer(**(**uintptr)(__ccgo_up(bp)))).FxSetOutputs})))(tls, **(**uintptr)(__ccgo_up(bp)), pSeg)
}
}
}
}
}
if (*TFts5Index)(unsafe.Pointer(p)).Frc != 0 {
_fts5IterClose(tls, **(**uintptr)(__ccgo_up(bp)))
**(**uintptr)(__ccgo_up(bp)) = uintptr(0)
_fts5IndexCloseReader(tls, p)
}
**(**uintptr)(__ccgo_up(ppIter)) = **(**uintptr)(__ccgo_up(bp))
_sqlite3Fts5BufferFree(tls, bp+8)
}
return _fts5IndexReturn(tls, p)
}
// C documentation
//
// /*
// ** The %_data table is completely empty when this function is called. This
// ** function populates it with the initial structure objects for each index,
// ** and the initial version of the "averages" record (a zero-byte blob).
// */
func _sqlite3Fts5IndexReinit(tls *libc.TLS, p uintptr) (r int32) {
bp := tls.Alloc(48)
defer tls.Free(48)
var pTmp uintptr
var _ /* uFts at bp+0 */ struct {
FtmpSpace [0][48]Tu8
FsFts TFts5Structure
F__ccgo_pad2 [16]byte
}
_ = pTmp
_fts5StructureInvalidate(tls, p)
_fts5IndexDiscardData(tls, p)
pTmp = bp
libc.X__builtin___memset_chk(tls, bp, 0, uint64(48), ^t__predefined_size_t(0))
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
//
// /*
// ** Set the 32-bit cookie value stored at the start of all structure
// ** records to the value passed as the second argument.
// **
// ** Return SQLITE_OK if successful, or an SQLite error code if an error
// ** occurs.
// */
func _sqlite3Fts5IndexSetCookie(tls *libc.TLS, p uintptr, iNew int32) (r int32) {
bp := tls.Alloc(16)
defer tls.Free(16)
var pConfig uintptr
var rc int32
var _ /* aCookie at bp+0 */ [4]Tu8
var _ /* pBlob at bp+8 */ uintptr
_, _ = pConfig, rc /* Return code */
pConfig = (*TFts5Index)(unsafe.Pointer(p)).FpConfig /* Binary representation of iNew */
**(**uintptr)(__ccgo_up(bp + 8)) = uintptr(0)
_sqlite3Fts5Put32(tls, bp, iNew)
rc = Xsqlite3_blob_open(tls, (*TFts5Config)(unsafe.Pointer(pConfig)).Fdb, (*TFts5Config)(unsafe.Pointer(pConfig)).FzDb, (*TFts5Index)(unsafe.Pointer(p)).FzDataTbl, __ccgo_ts+39331, int64(FTS5_STRUCTURE_ROWID), int32(1), bp+8)
if rc == SQLITE_OK {
Xsqlite3_blob_write(tls, **(**uintptr)(__ccgo_up(bp + 8)), bp, int32(4), 0)
rc = Xsqlite3_blob_close(tls, **(**uintptr)(__ccgo_up(bp + 8)))
}
return rc
}
// C documentation
//
// /*
// ** Attempt to instantiate the tokenizer.
// */
func _sqlite3Fts5LoadTokenizer(tls *libc.TLS, pConfig uintptr) (r int32) {
bp := tls.Alloc(16)
defer tls.Free(16)
var azArg, pMod, xCreate, v1 uintptr
var nArg, rc, v3 int32
_, _, _, _, _, _, _ = azArg, nArg, pMod, rc, xCreate, v1, v3
azArg = (*TFts5Config)(unsafe.Pointer(pConfig)).Ft.FazArg
nArg = (*TFts5Config)(unsafe.Pointer(pConfig)).Ft.FnArg
pMod = uintptr(0)
rc = SQLITE_OK
if nArg == 0 {
v1 = uintptr(0)
} else {
v1 = **(**uintptr)(__ccgo_up(azArg))
}
pMod = _fts5LocateTokenizer(tls, (*TFts5Config)(unsafe.Pointer(pConfig)).FpGlobal, v1)
if pMod == uintptr(0) {
rc = int32(SQLITE_ERROR)
_sqlite3Fts5ConfigErrmsg(tls, pConfig, __ccgo_ts+40832, libc.VaList(bp+8, **(**uintptr)(__ccgo_up(azArg))))
} else {
xCreate = uintptr(0)
if (*TFts5TokenizerModule)(unsafe.Pointer(pMod)).FbV2Native != 0 {
xCreate = (*TFts5TokenizerModule)(unsafe.Pointer(pMod)).Fx2.FxCreate
(*TFts5Config)(unsafe.Pointer(pConfig)).Ft.FpApi2 = pMod + 48
} else {
(*TFts5Config)(unsafe.Pointer(pConfig)).Ft.FpApi1 = pMod + 24
xCreate = (*TFts5TokenizerModule)(unsafe.Pointer(pMod)).Fx1.FxCreate
}
if azArg != 0 {
v1 = azArg + 1*8
} else {
v1 = uintptr(0)
}
if nArg != 0 {
v3 = nArg - int32(1)
} else {
v3 = 0
}
rc = (*(*func(*libc.TLS, uintptr, uintptr, int32, uintptr) int32)(unsafe.Pointer(&struct{ uintptr }{xCreate})))(tls, (*TFts5TokenizerModule)(unsafe.Pointer(pMod)).FpUserData, v1, v3, pConfig+128)
if rc != SQLITE_OK {
if rc != int32(SQLITE_NOMEM) {
_sqlite3Fts5ConfigErrmsg(tls, pConfig, __ccgo_ts+40854, 0)
}
} else {
if (*TFts5TokenizerModule)(unsafe.Pointer(pMod)).FbV2Native == 0 {
(*TFts5Config)(unsafe.Pointer(pConfig)).Ft.FePattern = _sqlite3Fts5TokenizerPattern(tls, (*TFts5TokenizerModule)(unsafe.Pointer(pMod)).Fx1.FxCreate, (*TFts5Config)(unsafe.Pointer(pConfig)).Ft.FpTok)
}
}
}
if rc != SQLITE_OK {
(*TFts5Config)(unsafe.Pointer(pConfig)).Ft.FpApi1 = uintptr(0)
(*TFts5Config)(unsafe.Pointer(pConfig)).Ft.FpApi2 = uintptr(0)
(*TFts5Config)(unsafe.Pointer(pConfig)).Ft.FpTok = uintptr(0)
}
return rc
}
func _sqlite3Fts5MallocZero(tls *libc.TLS, pRc uintptr, nByte Tsqlite3_int64) (r uintptr) {
var pRet uintptr
_ = pRet
pRet = uintptr(0)
if **(**int32)(__ccgo_up(pRc)) == SQLITE_OK {
pRet = Xsqlite3_malloc64(tls, libc.Uint64FromInt64(nByte))
if pRet == uintptr(0) {
if nByte > 0 {
**(**int32)(__ccgo_up(pRc)) = int32(SQLITE_NOMEM)
}
} else {
libc.X__builtin___memset_chk(tls, pRet, 0, libc.Uint64FromInt64(nByte), ^t__predefined_size_t(0))
}
}
return pRet
}
func _sqlite3Fts5ParseColset(tls *libc.TLS, pParse uintptr, pColset uintptr, p uintptr) (r uintptr) {
bp := tls.Alloc(16)
defer tls.Free(16)
var iCol int32
var pConfig, pRet, z uintptr
_, _, _, _ = iCol, pConfig, pRet, z
pRet = uintptr(0) /* Dequoted copy of token p */
z = _sqlite3Fts5Strndup(tls, pParse+16, (*TFts5Token)(unsafe.Pointer(p)).Fp, (*TFts5Token)(unsafe.Pointer(p)).Fn)
if (*TFts5Parse)(unsafe.Pointer(pParse)).Frc == SQLITE_OK {
pConfig = (*TFts5Parse)(unsafe.Pointer(pParse)).FpConfig
_sqlite3Fts5Dequote(tls, z)
iCol = 0
for {
if !(iCol < (*TFts5Config)(unsafe.Pointer(pConfig)).FnCol) {
break
}
if 0 == Xsqlite3_stricmp(tls, **(**uintptr)(__ccgo_up((*TFts5Config)(unsafe.Pointer(pConfig)).FazCol + uintptr(iCol)*8)), z) {
break
}
goto _1
_1:
;
iCol = iCol + 1
}
if iCol == (*TFts5Config)(unsafe.Pointer(pConfig)).FnCol {
_sqlite3Fts5ParseError(tls, pParse, __ccgo_ts+12254, libc.VaList(bp+8, z))
} else {
pRet = _fts5ParseColset(tls, pParse, pColset, iCol)
}
Xsqlite3_free(tls, z)
}
if pRet == uintptr(0) {
Xsqlite3_free(tls, pColset)
}
return pRet
}
func _sqlite3Fts5ParseImplicitAnd(tls *libc.TLS, pParse uintptr, pLeft uintptr, pRight uintptr) (r uintptr) {
var ap, pPrev, pRet uintptr
_, _, _ = ap, pPrev, pRet
pRet = uintptr(0)
if (*TFts5Parse)(unsafe.Pointer(pParse)).Frc != 0 {
_sqlite3Fts5ParseNodeFree(tls, pLeft)
_sqlite3Fts5ParseNodeFree(tls, pRight)
} else {
if (*TFts5ExprNode)(unsafe.Pointer(pLeft)).FeType == int32(FTS5_AND) {
pPrev = *(*uintptr)(unsafe.Pointer(pLeft + 48 + uintptr((*TFts5ExprNode)(unsafe.Pointer(pLeft)).FnChild-int32(1))*8))
} else {
pPrev = pLeft
}
if (*TFts5ExprNode)(unsafe.Pointer(pRight)).FeType == FTS5_EOF {
_sqlite3Fts5ParseNodeFree(tls, pRight)
pRet = pLeft
(*TFts5Parse)(unsafe.Pointer(pParse)).FnPhrase = (*TFts5Parse)(unsafe.Pointer(pParse)).FnPhrase - 1
} else {
if (*TFts5ExprNode)(unsafe.Pointer(pPrev)).FeType == FTS5_EOF {
if pPrev == pLeft {
pRet = pRight
} else {
*(*uintptr)(unsafe.Pointer(pLeft + 48 + uintptr((*TFts5ExprNode)(unsafe.Pointer(pLeft)).FnChild-int32(1))*8)) = pRight
pRet = pLeft
}
ap = (*TFts5Parse)(unsafe.Pointer(pParse)).FapPhrase + uintptr((*TFts5Parse)(unsafe.Pointer(pParse)).FnPhrase-int32(1)-(*TFts5ExprNearset)(unsafe.Pointer((*TFts5ExprNode)(unsafe.Pointer(pRight)).FpNear)).FnPhrase)*8
libc.X__builtin___memmove_chk(tls, ap, ap+1*8, uint64(8)*libc.Uint64FromInt32((*TFts5ExprNearset)(unsafe.Pointer((*TFts5ExprNode)(unsafe.Pointer(pRight)).FpNear)).FnPhrase), ^t__predefined_size_t(0))
(*TFts5Parse)(unsafe.Pointer(pParse)).FnPhrase = (*TFts5Parse)(unsafe.Pointer(pParse)).FnPhrase - 1
_sqlite3Fts5ParseNodeFree(tls, pPrev)
} else {
pRet = _sqlite3Fts5ParseNode(tls, pParse, int32(FTS5_AND), pLeft, pRight, uintptr(0))
}
}
}
return pRet
}
// C documentation
//
// /*
// ** Token pTok has appeared in a MATCH expression where the NEAR operator
// ** is expected. If token pTok does not contain "NEAR", store an error
// ** in the pParse object.
// */
func _sqlite3Fts5ParseNear(tls *libc.TLS, pParse uintptr, pTok uintptr) {
bp := tls.Alloc(32)
defer tls.Free(32)
if (*TFts5Token)(unsafe.Pointer(pTok)).Fn != int32(4) || libc.Xmemcmp(tls, __ccgo_ts+38994, (*TFts5Token)(unsafe.Pointer(pTok)).Fp, uint64(4)) != 0 {
_sqlite3Fts5ParseError(tls, pParse, __ccgo_ts+37507, libc.VaList(bp+8, (*TFts5Token)(unsafe.Pointer(pTok)).Fn, (*TFts5Token)(unsafe.Pointer(pTok)).Fp))
}
}
// C documentation
//
// /*
// ** If argument pNear is NULL, then a new Fts5ExprNearset object is allocated
// ** and populated with pPhrase. Or, if pNear is not NULL, phrase pPhrase is
// ** appended to it and the results returned.
// **
// ** If an OOM error occurs, both the pNear and pPhrase objects are freed and
// ** NULL returned.
// */
func _sqlite3Fts5ParseNearset(tls *libc.TLS, pParse uintptr, pNear uintptr, pPhrase uintptr) (r uintptr) {
var SZALLOC, nNew, v1 int32
var nByte, nByte1 Tsqlite3_int64
var pLast, pRet, v2 uintptr
_, _, _, _, _, _, _, _ = SZALLOC, nByte, nByte1, nNew, pLast, pRet, v1, v2
SZALLOC = int32(8)
pRet = uintptr(0)
if (*TFts5Parse)(unsafe.Pointer(pParse)).Frc == SQLITE_OK {
if pNear == uintptr(0) {
nByte = libc.Int64FromUint64(uint64(libc.UintptrFromInt32(0)+24) + libc.Uint64FromInt32(SZALLOC+libc.Int32FromInt32(1))*libc.Uint64FromInt64(8))
pRet = Xsqlite3_malloc64(tls, libc.Uint64FromInt64(nByte))
if pRet == uintptr(0) {
(*TFts5Parse)(unsafe.Pointer(pParse)).Frc = int32(SQLITE_NOMEM)
} else {
libc.X__builtin___memset_chk(tls, pRet, 0, libc.Uint64FromInt64(nByte), ^t__predefined_size_t(0))
}
} else {
if (*TFts5ExprNearset)(unsafe.Pointer(pNear)).FnPhrase%SZALLOC == 0 {
nNew = (*TFts5ExprNearset)(unsafe.Pointer(pNear)).FnPhrase + SZALLOC
nByte1 = libc.Int64FromUint64(uint64(libc.UintptrFromInt32(0)+24) + libc.Uint64FromInt32(nNew+libc.Int32FromInt32(1))*libc.Uint64FromInt64(8))
pRet = Xsqlite3_realloc64(tls, pNear, libc.Uint64FromInt64(nByte1))
if pRet == uintptr(0) {
(*TFts5Parse)(unsafe.Pointer(pParse)).Frc = int32(SQLITE_NOMEM)
}
} else {
pRet = pNear
}
}
}
if pRet == uintptr(0) {
_sqlite3Fts5ParseNearsetFree(tls, pNear)
_sqlite3Fts5ParsePhraseFree(tls, pPhrase)
} else {
if (*TFts5ExprNearset)(unsafe.Pointer(pRet)).FnPhrase > 0 {
pLast = *(*uintptr)(unsafe.Pointer(pRet + 24 + uintptr((*TFts5ExprNearset)(unsafe.Pointer(pRet)).FnPhrase-int32(1))*8))
if (*TFts5ExprPhrase)(unsafe.Pointer(pPhrase)).FnTerm == 0 {
_fts5ExprPhraseFree(tls, pPhrase)
(*TFts5ExprNearset)(unsafe.Pointer(pRet)).FnPhrase = (*TFts5ExprNearset)(unsafe.Pointer(pRet)).FnPhrase - 1
(*TFts5Parse)(unsafe.Pointer(pParse)).FnPhrase = (*TFts5Parse)(unsafe.Pointer(pParse)).FnPhrase - 1
pPhrase = pLast
} else {
if (*TFts5ExprPhrase)(unsafe.Pointer(pLast)).FnTerm == 0 {
_fts5ExprPhraseFree(tls, pLast)
**(**uintptr)(__ccgo_up((*TFts5Parse)(unsafe.Pointer(pParse)).FapPhrase + uintptr((*TFts5Parse)(unsafe.Pointer(pParse)).FnPhrase-int32(2))*8)) = pPhrase
(*TFts5Parse)(unsafe.Pointer(pParse)).FnPhrase = (*TFts5Parse)(unsafe.Pointer(pParse)).FnPhrase - 1
(*TFts5ExprNearset)(unsafe.Pointer(pRet)).FnPhrase = (*TFts5ExprNearset)(unsafe.Pointer(pRet)).FnPhrase - 1
}
}
}
v2 = pRet + 16
v1 = *(*int32)(unsafe.Pointer(v2))
*(*int32)(unsafe.Pointer(v2)) = *(*int32)(unsafe.Pointer(v2)) + 1
*(*uintptr)(unsafe.Pointer(pRet + 24 + uintptr(v1)*8)) = pPhrase
}
return pRet
}
// C documentation
//
// /*
// ** Allocate and return a new expression object. If anything goes wrong (i.e.
// ** OOM error), leave an error code in pParse and return NULL.
// */
func _sqlite3Fts5ParseNode(tls *libc.TLS, pParse uintptr, eType int32, pLeft uintptr, pRight uintptr, pNear uintptr) (r uintptr) {
bp := tls.Alloc(16)
defer tls.Free(16)
var iPhrase, nChild int32
var nByte Tsqlite3_int64
var pPhrase, pRet, v2 uintptr
_, _, _, _, _, _ = iPhrase, nByte, nChild, pPhrase, pRet, v2
pRet = uintptr(0)
if (*TFts5Parse)(unsafe.Pointer(pParse)).Frc == SQLITE_OK {
nChild = 0 /* Bytes of space to allocate for this node */
if eType == int32(FTS5_STRING) && pNear == uintptr(0) {
return uintptr(0)
}
if eType != int32(FTS5_STRING) && pLeft == uintptr(0) {
return pRight
}
if eType != int32(FTS5_STRING) && pRight == uintptr(0) {
return pLeft
}
if eType == int32(FTS5_STRING) && (*TFts5Parse)(unsafe.Pointer(pParse)).FbPhraseToAnd != 0 && (*TFts5ExprPhrase)(unsafe.Pointer(*(*uintptr)(unsafe.Pointer(pNear + 24)))).FnTerm > int32(1) {
pRet = _fts5ParsePhraseToAnd(tls, pParse, pNear)
} else {
if eType == int32(FTS5_NOT) {
nChild = int32(2)
} else {
if eType == int32(FTS5_AND) || eType == int32(FTS5_OR) {
nChild = int32(2)
if (*TFts5ExprNode)(unsafe.Pointer(pLeft)).FeType == eType {
nChild = nChild + ((*TFts5ExprNode)(unsafe.Pointer(pLeft)).FnChild - int32(1))
}
if (*TFts5ExprNode)(unsafe.Pointer(pRight)).FeType == eType {
nChild = nChild + ((*TFts5ExprNode)(unsafe.Pointer(pRight)).FnChild - int32(1))
}
}
}
nByte = libc.Int64FromUint64(uint64(libc.UintptrFromInt32(0)+48) + libc.Uint64FromInt32(nChild)*libc.Uint64FromInt64(8))
pRet = _sqlite3Fts5MallocZero(tls, pParse+16, nByte)
if pRet != 0 {
(*TFts5ExprNode)(unsafe.Pointer(pRet)).FeType = eType
(*TFts5ExprNode)(unsafe.Pointer(pRet)).FpNear = pNear
_fts5ExprAssignXNext(tls, pRet)
if eType == int32(FTS5_STRING) {
iPhrase = 0
for {
if !(iPhrase < (*TFts5ExprNearset)(unsafe.Pointer(pNear)).FnPhrase) {
break
}
(*TFts5ExprPhrase)(unsafe.Pointer(*(*uintptr)(unsafe.Pointer(pNear + 24 + uintptr(iPhrase)*8)))).FpNode = pRet
if (*TFts5ExprPhrase)(unsafe.Pointer(*(*uintptr)(unsafe.Pointer(pNear + 24 + uintptr(iPhrase)*8)))).FnTerm == 0 {
(*TFts5ExprNode)(unsafe.Pointer(pRet)).FxNext = uintptr(0)
(*TFts5ExprNode)(unsafe.Pointer(pRet)).FeType = FTS5_EOF
}
goto _1
_1:
;
iPhrase = iPhrase + 1
}
if (*TFts5Config)(unsafe.Pointer((*TFts5Parse)(unsafe.Pointer(pParse)).FpConfig)).FeDetail != FTS5_DETAIL_FULL {
pPhrase = *(*uintptr)(unsafe.Pointer(pNear + 24))
if (*TFts5ExprNearset)(unsafe.Pointer(pNear)).FnPhrase != int32(1) || (*TFts5ExprPhrase)(unsafe.Pointer(pPhrase)).FnTerm > int32(1) || (*TFts5ExprPhrase)(unsafe.Pointer(pPhrase)).FnTerm > 0 && (*(*TFts5ExprTerm)(unsafe.Pointer(pPhrase + 32))).FbFirst != 0 {
if (*TFts5ExprNearset)(unsafe.Pointer(pNear)).FnPhrase == int32(1) {
v2 = __ccgo_ts + 39081
} else {
v2 = __ccgo_ts + 38994
}
_sqlite3Fts5ParseError(tls, pParse, __ccgo_ts+39088, 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+39138, libc.VaList(bp+8, int32(SQLITE_FTS5_MAX_EXPR_DEPTH)))
_sqlite3Fts5ParseNodeFree(tls, pRet)
pRet = uintptr(0)
}
}
}
}
}
if pRet == uintptr(0) {
_sqlite3Fts5ParseNodeFree(tls, pLeft)
_sqlite3Fts5ParseNodeFree(tls, pRight)
_sqlite3Fts5ParseNearsetFree(tls, pNear)
}
return pRet
}
// C documentation
//
// /*
// ** Apply colset pColset to expression node pExpr and all of its descendents.
// */
func _sqlite3Fts5ParseSetColset(tls *libc.TLS, pParse uintptr, pExpr uintptr, pColset uintptr) {
bp := tls.Alloc(16)
defer tls.Free(16)
var _ /* pFree at bp+0 */ uintptr
**(**uintptr)(__ccgo_up(bp)) = pColset
if (*TFts5Config)(unsafe.Pointer((*TFts5Parse)(unsafe.Pointer(pParse)).FpConfig)).FeDetail == int32(FTS5_DETAIL_NONE) {
_sqlite3Fts5ParseError(tls, pParse, __ccgo_ts+39028, 0)
} else {
_fts5ParseSetColset(tls, pParse, pExpr, pColset, bp)
}
Xsqlite3_free(tls, **(**uintptr)(__ccgo_up(bp)))
}
func _sqlite3Fts5ParseSetDistance(tls *libc.TLS, pParse uintptr, pNear uintptr, p uintptr) {
bp := tls.Alloc(32)
defer tls.Free(32)
var c int8
var i, nNear int32
_, _, _ = c, i, nNear
if pNear != 0 {
nNear = 0
if (*TFts5Token)(unsafe.Pointer(p)).Fn != 0 {
i = 0
for {
if !(i < (*TFts5Token)(unsafe.Pointer(p)).Fn) {
break
}
c = **(**int8)(__ccgo_up((*TFts5Token)(unsafe.Pointer(p)).Fp + uintptr(i)))
if int32(c) < int32('0') || int32(c) > int32('9') {
_sqlite3Fts5ParseError(tls, pParse, __ccgo_ts+38999, libc.VaList(bp+8, (*TFts5Token)(unsafe.Pointer(p)).Fn, (*TFts5Token)(unsafe.Pointer(p)).Fp))
return
}
if nNear < int32(214748363) {
nNear = nNear*int32(10) + (int32(**(**int8)(__ccgo_up((*TFts5Token)(unsafe.Pointer(p)).Fp + uintptr(i)))) - int32('0'))
}
/* ^^^^^^^^^^^^^^^--- Prevent integer overflow */
goto _1
_1:
;
i = i + 1
}
} else {
nNear = int32(FTS5_DEFAULT_NEARDIST)
}
(*TFts5ExprNearset)(unsafe.Pointer(pNear)).FnNear = nNear
}
}
// C documentation
//
// /*
// ** This function is called by the parser to process a string token. The
// ** string may or may not be quoted. In any case it is tokenized and a
// ** phrase object consisting of all tokens returned.
// */
func _sqlite3Fts5ParseTerm(tls *libc.TLS, pParse uintptr, pAppend uintptr, pToken uintptr, bPrefix int32) (r uintptr) {
bp := tls.Alloc(32)
defer tls.Free(32)
var flags, n, rc, v1 int32
var pConfig uintptr
var v3 bool
var _ /* sCtx at bp+0 */ TTokenCtx
var _ /* z at bp+24 */ uintptr
_, _, _, _, _, _ = flags, n, pConfig, rc, v1, v3
pConfig = (*TFts5Parse)(unsafe.Pointer(pParse)).FpConfig /* Tokenize return code */
**(**uintptr)(__ccgo_up(bp + 24)) = uintptr(0)
libc.X__builtin___memset_chk(tls, bp, 0, uint64(24), ^t__predefined_size_t(0))
(**(**TTokenCtx)(__ccgo_up(bp))).FpPhrase = pAppend
(**(**TTokenCtx)(__ccgo_up(bp))).FpConfig = pConfig
rc = _fts5ParseStringFromToken(tls, pToken, bp+24)
if rc == SQLITE_OK {
if bPrefix != 0 {
v1 = int32(FTS5_TOKENIZE_PREFIX)
} else {
v1 = 0
}
flags = int32(FTS5_TOKENIZE_QUERY) | v1
_sqlite3Fts5Dequote(tls, **(**uintptr)(__ccgo_up(bp + 24)))
n = libc.Int32FromUint64(libc.Xstrlen(tls, **(**uintptr)(__ccgo_up(bp + 24))))
rc = _sqlite3Fts5Tokenize(tls, pConfig, flags, **(**uintptr)(__ccgo_up(bp + 24)), n, bp, __ccgo_fp(_fts5ParseTokenize))
}
Xsqlite3_free(tls, **(**uintptr)(__ccgo_up(bp + 24)))
if v3 = rc != 0; !v3 {
v1 = (**(**TTokenCtx)(__ccgo_up(bp))).Frc
rc = v1
}
if v3 || v1 != 0 {
(*TFts5Parse)(unsafe.Pointer(pParse)).Frc = rc
_fts5ExprPhraseFree(tls, (**(**TTokenCtx)(__ccgo_up(bp))).FpPhrase)
(**(**TTokenCtx)(__ccgo_up(bp))).FpPhrase = uintptr(0)
} else {
if pAppend == uintptr(0) {
if _parseGrowPhraseArray(tls, pParse) != 0 {
_fts5ExprPhraseFree(tls, (**(**TTokenCtx)(__ccgo_up(bp))).FpPhrase)
return uintptr(0)
}
(*TFts5Parse)(unsafe.Pointer(pParse)).FnPhrase = (*TFts5Parse)(unsafe.Pointer(pParse)).FnPhrase + 1
}
if (**(**TTokenCtx)(__ccgo_up(bp))).FpPhrase == uintptr(0) {
/* This happens when parsing a token or quoted phrase that contains
** no token characters at all. (e.g ... MATCH '""'). */
(**(**TTokenCtx)(__ccgo_up(bp))).FpPhrase = _sqlite3Fts5MallocZero(tls, pParse+16, libc.Int64FromUint64(uint64(libc.UintptrFromInt32(0)+32)+libc.Uint64FromInt32(libc.Int32FromInt32(1))*libc.Uint64FromInt64(40)))
} else {
if (*TFts5ExprPhrase)(unsafe.Pointer((**(**TTokenCtx)(__ccgo_up(bp))).FpPhrase)).FnTerm != 0 {
(*(*TFts5ExprTerm)(unsafe.Pointer((**(**TTokenCtx)(__ccgo_up(bp))).FpPhrase + 32 + uintptr((*TFts5ExprPhrase)(unsafe.Pointer((**(**TTokenCtx)(__ccgo_up(bp))).FpPhrase)).FnTerm-int32(1))*40))).FbPrefix = libc.Uint8FromInt32(bPrefix)
}
}
**(**uintptr)(__ccgo_up((*TFts5Parse)(unsafe.Pointer(pParse)).FapPhrase + uintptr((*TFts5Parse)(unsafe.Pointer(pParse)).FnPhrase-int32(1))*8)) = (**(**TTokenCtx)(__ccgo_up(bp))).FpPhrase
}
return (**(**TTokenCtx)(__ccgo_up(bp))).FpPhrase
}
// 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) 2002-2017 Apple Inc. All rights reserved.
*
* @APPLE_LICENSE_HEADER_START@
*
* The contents of this file constitute Original Code as defined in and
* are subject to the Apple Public Source License Version 1.1 (the
* "License"). You may not use this file except in compliance with the
* License. Please obtain a copy of the License at
* http://www.apple.com/publicsource and read it before using this file.
*
* This Original Code and all software distributed under the License are
* distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY KIND, EITHER
* EXPRESS OR IMPLIED, AND APPLE HEREBY DISCLAIMS ALL SUCH WARRANTIES,
* INCLUDING WITHOUT LIMITATION, ANY WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE OR NON-INFRINGEMENT. Please see the
* License for the specific language governing rights and limitations
* under the License.
*
* @APPLE_LICENSE_HEADER_END@
*/
func _sqlite3Fts5PoslistReaderInit(tls *libc.TLS, a uintptr, n int32, pIter uintptr) (r int32) {
libc.X__builtin___memset_chk(tls, pIter, 0, uint64(32), ^t__predefined_size_t(0))
(*TFts5PoslistReader)(unsafe.Pointer(pIter)).Fa = a
(*TFts5PoslistReader)(unsafe.Pointer(pIter)).Fn = n
_sqlite3Fts5PoslistReaderNext(tls, pIter)
return libc.Int32FromUint8((*TFts5PoslistReader)(unsafe.Pointer(pIter)).FbEof)
}
// C documentation
//
// /*
// ** Delete all entries in the FTS5 index.
// */
func _sqlite3Fts5StorageDeleteAll(tls *libc.TLS, p uintptr) (r int32) {
bp := tls.Alloc(48)
defer tls.Free(48)
var pConfig uintptr
var rc int32
_, _ = pConfig, rc
pConfig = (*TFts5Storage)(unsafe.Pointer(p)).FpConfig
(*TFts5Storage)(unsafe.Pointer(p)).FbTotalsValid = 0
/* Delete the contents of the %_data and %_docsize tables. */
rc = _fts5ExecPrintf(tls, (*TFts5Config)(unsafe.Pointer(pConfig)).Fdb, uintptr(0), __ccgo_ts+42083, libc.VaList(bp+8, (*TFts5Config)(unsafe.Pointer(pConfig)).FzDb, (*TFts5Config)(unsafe.Pointer(pConfig)).FzName, (*TFts5Config)(unsafe.Pointer(pConfig)).FzDb, (*TFts5Config)(unsafe.Pointer(pConfig)).FzName))
if rc == SQLITE_OK && (*TFts5Config)(unsafe.Pointer(pConfig)).FbColumnsize != 0 {
rc = _fts5ExecPrintf(tls, (*TFts5Config)(unsafe.Pointer(pConfig)).Fdb, uintptr(0), __ccgo_ts+42133, libc.VaList(bp+8, (*TFts5Config)(unsafe.Pointer(pConfig)).FzDb, (*TFts5Config)(unsafe.Pointer(pConfig)).FzName))
}
if rc == SQLITE_OK && (*TFts5Config)(unsafe.Pointer(pConfig)).FeContent == int32(FTS5_CONTENT_UNINDEXED) {
rc = _fts5ExecPrintf(tls, (*TFts5Config)(unsafe.Pointer(pConfig)).Fdb, uintptr(0), __ccgo_ts+42162, libc.VaList(bp+8, (*TFts5Config)(unsafe.Pointer(pConfig)).FzDb, (*TFts5Config)(unsafe.Pointer(pConfig)).FzName))
}
/* Reinitialize the %_data table. This call creates the initial structure
** and averages records. */
if rc == SQLITE_OK {
rc = _sqlite3Fts5IndexReinit(tls, (*TFts5Storage)(unsafe.Pointer(p)).FpIndex)
}
if rc == SQLITE_OK {
rc = _sqlite3Fts5StorageConfigValue(tls, p, __ccgo_ts+38857, uintptr(0), int32(FTS5_CURRENT_VERSION))
}
return rc
}
// C documentation
//
// /*
// ** Insert new entries into the FTS index and %_docsize table.
// */
func _sqlite3Fts5StorageIndexInsert(tls *libc.TLS, p uintptr, apVal uintptr, iRowid Ti64) (r int32) {
bp := tls.Alloc(80)
defer tls.Free(80)
var iCol int32
var pConfig, pVal uintptr
var _ /* buf at bp+24 */ TFts5Buffer
var _ /* ctx at bp+8 */ TFts5InsertCtx
var _ /* nLoc at bp+56 */ int32
var _ /* nText at bp+40 */ int32
var _ /* pLoc at bp+64 */ uintptr
var _ /* pText at bp+48 */ uintptr
var _ /* rc at bp+0 */ int32
_, _, _ = iCol, pConfig, pVal
pConfig = (*TFts5Storage)(unsafe.Pointer(p)).FpConfig
**(**int32)(__ccgo_up(bp)) = SQLITE_OK /* Buffer used to build up %_docsize blob */
libc.X__builtin___memset_chk(tls, bp+24, 0, uint64(16), ^t__predefined_size_t(0))
(**(**TFts5InsertCtx)(__ccgo_up(bp + 8))).FpStorage = p
**(**int32)(__ccgo_up(bp)) = _fts5StorageLoadTotals(tls, p, int32(1))
if **(**int32)(__ccgo_up(bp)) == SQLITE_OK {
**(**int32)(__ccgo_up(bp)) = _sqlite3Fts5IndexBeginWrite(tls, (*TFts5Storage)(unsafe.Pointer(p)).FpIndex, 0, iRowid)
}
(**(**TFts5InsertCtx)(__ccgo_up(bp + 8))).FiCol = 0
for {
if !(**(**int32)(__ccgo_up(bp)) == SQLITE_OK && (**(**TFts5InsertCtx)(__ccgo_up(bp + 8))).FiCol < (*TFts5Config)(unsafe.Pointer(pConfig)).FnCol) {
break
}
(**(**TFts5InsertCtx)(__ccgo_up(bp + 8))).FszCol = 0
if libc.Int32FromUint8(**(**Tu8)(__ccgo_up((*TFts5Config)(unsafe.Pointer(pConfig)).FabUnindexed + uintptr((**(**TFts5InsertCtx)(__ccgo_up(bp + 8))).FiCol)))) == 0 {
**(**int32)(__ccgo_up(bp + 40)) = 0 /* Size of pText in bytes */
**(**uintptr)(__ccgo_up(bp + 48)) = uintptr(0) /* Pointer to buffer containing text value */
**(**int32)(__ccgo_up(bp + 56)) = 0 /* Size of pText in bytes */
**(**uintptr)(__ccgo_up(bp + 64)) = uintptr(0) /* Pointer to buffer containing text value */
pVal = **(**uintptr)(__ccgo_up(apVal + uintptr((**(**TFts5InsertCtx)(__ccgo_up(bp + 8))).FiCol+int32(2))*8))
if (*TFts5Storage)(unsafe.Pointer(p)).FpSavedRow != 0 && Xsqlite3_value_nochange(tls, pVal) != 0 {
pVal = Xsqlite3_column_value(tls, (*TFts5Storage)(unsafe.Pointer(p)).FpSavedRow, (**(**TFts5InsertCtx)(__ccgo_up(bp + 8))).FiCol+int32(1))
if (*TFts5Config)(unsafe.Pointer(pConfig)).FeContent == FTS5_CONTENT_NORMAL && (*TFts5Config)(unsafe.Pointer(pConfig)).FbLocale != 0 {
iCol = (**(**TFts5InsertCtx)(__ccgo_up(bp + 8))).FiCol + int32(1) + (*TFts5Config)(unsafe.Pointer(pConfig)).FnCol
**(**uintptr)(__ccgo_up(bp + 64)) = Xsqlite3_column_text(tls, (*TFts5Storage)(unsafe.Pointer(p)).FpSavedRow, iCol)
**(**int32)(__ccgo_up(bp + 56)) = Xsqlite3_column_bytes(tls, (*TFts5Storage)(unsafe.Pointer(p)).FpSavedRow, iCol)
}
} else {
pVal = **(**uintptr)(__ccgo_up(apVal + uintptr((**(**TFts5InsertCtx)(__ccgo_up(bp + 8))).FiCol+int32(2))*8))
}
if (*TFts5Config)(unsafe.Pointer(pConfig)).FbLocale != 0 && _sqlite3Fts5IsLocaleValue(tls, pConfig, pVal) != 0 {
**(**int32)(__ccgo_up(bp)) = _sqlite3Fts5DecodeLocaleValue(tls, pVal, bp+48, bp+40, bp+64, bp+56)
} else {
**(**uintptr)(__ccgo_up(bp + 48)) = Xsqlite3_value_text(tls, pVal)
**(**int32)(__ccgo_up(bp + 40)) = Xsqlite3_value_bytes(tls, pVal)
}
if **(**int32)(__ccgo_up(bp)) == SQLITE_OK {
_sqlite3Fts5SetLocale(tls, pConfig, **(**uintptr)(__ccgo_up(bp + 64)), **(**int32)(__ccgo_up(bp + 56)))
**(**int32)(__ccgo_up(bp)) = _sqlite3Fts5Tokenize(tls, pConfig, int32(FTS5_TOKENIZE_DOCUMENT), **(**uintptr)(__ccgo_up(bp + 48)), **(**int32)(__ccgo_up(bp + 40)), bp+8, __ccgo_fp(_fts5StorageInsertCallback))
_sqlite3Fts5ClearLocale(tls, pConfig)
}
}
_sqlite3Fts5BufferAppendVarint(tls, bp, bp+24, int64((**(**TFts5InsertCtx)(__ccgo_up(bp + 8))).FszCol))
**(**Ti64)(__ccgo_up((*TFts5Storage)(unsafe.Pointer(p)).FaTotalSize + uintptr((**(**TFts5InsertCtx)(__ccgo_up(bp + 8))).FiCol)*8)) += int64((**(**TFts5InsertCtx)(__ccgo_up(bp + 8))).FszCol)
goto _1
_1:
;
(**(**TFts5InsertCtx)(__ccgo_up(bp + 8))).FiCol = (**(**TFts5InsertCtx)(__ccgo_up(bp + 8))).FiCol + 1
}
(*TFts5Storage)(unsafe.Pointer(p)).FnTotalRow = (*TFts5Storage)(unsafe.Pointer(p)).FnTotalRow + 1
/* Write the %_docsize record */
if **(**int32)(__ccgo_up(bp)) == SQLITE_OK {
**(**int32)(__ccgo_up(bp)) = _fts5StorageInsertDocsize(tls, p, iRowid, bp+24)
}
Xsqlite3_free(tls, (**(**TFts5Buffer)(__ccgo_up(bp + 24))).Fp)
return **(**int32)(__ccgo_up(bp))
}
// C documentation
//
// /*
// ** Check that the contents of the FTS index match that of the %_content
// ** table. Return SQLITE_OK if they do, or SQLITE_CORRUPT if not. Return
// ** some other SQLite error code if an error occurs while attempting to
// ** determine this.
// */
func _sqlite3Fts5StorageIntegrity(tls *libc.TLS, p uintptr, iArg int32) (r int32) {
bp := tls.Alloc(96)
defer tls.Free(96)
var aColSize, aTotalSize, pConfig, pVal uintptr
var bUseCksum, i, i1, iCol, rc, rc2 int32
var _ /* ctx at bp+0 */ TFts5IntegrityCtx
var _ /* nLoc at bp+72 */ int32
var _ /* nRow at bp+80 */ Ti64
var _ /* nRow at bp+88 */ Ti64
var _ /* nText at bp+56 */ int32
var _ /* pLoc at bp+64 */ uintptr
var _ /* pScan at bp+40 */ uintptr
var _ /* pText at bp+48 */ uintptr
_, _, _, _, _, _, _, _, _, _ = aColSize, aTotalSize, bUseCksum, i, i1, iCol, pConfig, pVal, rc, rc2
pConfig = (*TFts5Storage)(unsafe.Pointer(p)).FpConfig
rc = SQLITE_OK
libc.X__builtin___memset_chk(tls, bp, 0, uint64(40), ^t__predefined_size_t(0))
(**(**TFts5IntegrityCtx)(__ccgo_up(bp))).FpConfig = (*TFts5Storage)(unsafe.Pointer(p)).FpConfig
aTotalSize = Xsqlite3_malloc64(tls, uint64(libc.Uint64FromInt32((*TFts5Config)(unsafe.Pointer(pConfig)).FnCol)*(libc.Uint64FromInt64(4)+libc.Uint64FromInt64(8))))
if !(aTotalSize != 0) {
return int32(SQLITE_NOMEM)
}
aColSize = aTotalSize + uintptr((*TFts5Config)(unsafe.Pointer(pConfig)).FnCol)*8
libc.X__builtin___memset_chk(tls, aTotalSize, 0, uint64(8)*libc.Uint64FromInt32((*TFts5Config)(unsafe.Pointer(pConfig)).FnCol), ^t__predefined_size_t(0))
bUseCksum = libc.BoolInt32((*TFts5Config)(unsafe.Pointer(pConfig)).FeContent == FTS5_CONTENT_NORMAL || (*TFts5Config)(unsafe.Pointer(pConfig)).FeContent == int32(FTS5_CONTENT_EXTERNAL) && iArg != 0)
if bUseCksum != 0 {
/* Generate the expected index checksum based on the contents of the
** %_content table. This block stores the checksum in ctx.cksum. */
rc = _fts5StorageGetStmt(tls, p, int32(FTS5_STMT_SCAN), bp+40, uintptr(0))
if rc == SQLITE_OK {
for int32(SQLITE_ROW) == Xsqlite3_step(tls, **(**uintptr)(__ccgo_up(bp + 40))) {
(**(**TFts5IntegrityCtx)(__ccgo_up(bp))).FiRowid = Xsqlite3_column_int64(tls, **(**uintptr)(__ccgo_up(bp + 40)), 0)
(**(**TFts5IntegrityCtx)(__ccgo_up(bp))).FszCol = 0
if (*TFts5Config)(unsafe.Pointer(pConfig)).FbColumnsize != 0 {
rc = _sqlite3Fts5StorageDocsize(tls, p, (**(**TFts5IntegrityCtx)(__ccgo_up(bp))).FiRowid, aColSize)
}
if rc == SQLITE_OK && (*TFts5Config)(unsafe.Pointer(pConfig)).FeDetail == int32(FTS5_DETAIL_NONE) {
rc = _sqlite3Fts5TermsetNew(tls, bp+24)
}
i = 0
for {
if !(rc == SQLITE_OK && i < (*TFts5Config)(unsafe.Pointer(pConfig)).FnCol) {
break
}
if libc.Int32FromUint8(**(**Tu8)(__ccgo_up((*TFts5Config)(unsafe.Pointer(pConfig)).FabUnindexed + uintptr(i)))) == 0 {
**(**uintptr)(__ccgo_up(bp + 48)) = uintptr(0)
**(**int32)(__ccgo_up(bp + 56)) = 0
**(**uintptr)(__ccgo_up(bp + 64)) = uintptr(0)
**(**int32)(__ccgo_up(bp + 72)) = 0
pVal = Xsqlite3_column_value(tls, **(**uintptr)(__ccgo_up(bp + 40)), i+int32(1))
if (*TFts5Config)(unsafe.Pointer(pConfig)).FeContent == int32(FTS5_CONTENT_EXTERNAL) && _sqlite3Fts5IsLocaleValue(tls, pConfig, pVal) != 0 {
rc = _sqlite3Fts5DecodeLocaleValue(tls, pVal, bp+48, bp+56, bp+64, bp+72)
} else {
if (*TFts5Config)(unsafe.Pointer(pConfig)).FeContent == FTS5_CONTENT_NORMAL && (*TFts5Config)(unsafe.Pointer(pConfig)).FbLocale != 0 {
iCol = i + int32(1) + (*TFts5Config)(unsafe.Pointer(pConfig)).FnCol
**(**uintptr)(__ccgo_up(bp + 64)) = Xsqlite3_column_text(tls, **(**uintptr)(__ccgo_up(bp + 40)), iCol)
**(**int32)(__ccgo_up(bp + 72)) = Xsqlite3_column_bytes(tls, **(**uintptr)(__ccgo_up(bp + 40)), iCol)
}
**(**uintptr)(__ccgo_up(bp + 48)) = Xsqlite3_value_text(tls, pVal)
**(**int32)(__ccgo_up(bp + 56)) = Xsqlite3_value_bytes(tls, pVal)
}
(**(**TFts5IntegrityCtx)(__ccgo_up(bp))).FiCol = i
(**(**TFts5IntegrityCtx)(__ccgo_up(bp))).FszCol = 0
if rc == SQLITE_OK && (*TFts5Config)(unsafe.Pointer(pConfig)).FeDetail == int32(FTS5_DETAIL_COLUMNS) {
rc = _sqlite3Fts5TermsetNew(tls, bp+24)
}
if rc == SQLITE_OK {
_sqlite3Fts5SetLocale(tls, pConfig, **(**uintptr)(__ccgo_up(bp + 64)), **(**int32)(__ccgo_up(bp + 72)))
rc = _sqlite3Fts5Tokenize(tls, pConfig, int32(FTS5_TOKENIZE_DOCUMENT), **(**uintptr)(__ccgo_up(bp + 48)), **(**int32)(__ccgo_up(bp + 56)), bp, __ccgo_fp(_fts5StorageIntegrityCallback))
_sqlite3Fts5ClearLocale(tls, pConfig)
}
/* If this is not a columnsize=0 database, check that the number
** of tokens in the value matches the aColSize[] value read from
** the %_docsize table. */
if rc == SQLITE_OK && (*TFts5Config)(unsafe.Pointer(pConfig)).FbColumnsize != 0 && (**(**TFts5IntegrityCtx)(__ccgo_up(bp))).FszCol != **(**int32)(__ccgo_up(aColSize + uintptr(i)*4)) {
rc = libc.Int32FromInt32(SQLITE_CORRUPT) | libc.Int32FromInt32(1)<= 0) {
break
}
hash = hash< */
// C documentation
//
// /*
// ** Return true if the tokenizer described by p->azArg[] is the trigram
// ** tokenizer. This tokenizer needs to be loaded before xBestIndex is
// ** called for the first time in order to correctly handle LIKE/GLOB.
// */
func _sqlite3Fts5TokenizerPreload(tls *libc.TLS, p uintptr) (r int32) {
return libc.BoolInt32((*TFts5TokenizerConfig)(unsafe.Pointer(p)).FnArg >= int32(1) && 0 == Xsqlite3_stricmp(tls, **(**uintptr)(__ccgo_up((*TFts5TokenizerConfig)(unsafe.Pointer(p)).FazArg)), __ccgo_ts+42594))
}
func _sqlite3Fts5VocabInit(tls *libc.TLS, pGlobal uintptr, db uintptr) (r int32) {
var p uintptr
_ = p
p = pGlobal
return Xsqlite3_create_module_v2(tls, db, __ccgo_ts+42918, uintptr(unsafe.Pointer(&_fts5Vocab)), p, uintptr(0))
}
// C documentation
//
// /*
// ** Compute the column names for a SELECT statement.
// **
// ** The only guarantee that SQLite makes about column names is that if the
// ** column has an AS clause assigning it a name, that will be the name used.
// ** That is the only documented guarantee. However, countless applications
// ** developed over the years have made baseless assumptions about column names
// ** and will break if those assumptions changes. Hence, use extreme caution
// ** when modifying this routine to avoid breaking legacy.
// **
// ** See Also: sqlite3ColumnsFromExprList()
// **
// ** The PRAGMA short_column_names and PRAGMA full_column_names settings are
// ** deprecated. The default setting is short=ON, full=OFF. 99.9% of all
// ** applications should operate this way. Nevertheless, we need to support the
// ** other modes for legacy:
// **
// ** short=OFF, full=OFF: Column name is the text of the expression has it
// ** originally appears in the SELECT statement. In
// ** other words, the zSpan of the result expression.
// **
// ** short=ON, full=OFF: (This is the default setting). If the result
// ** refers directly to a table column, then the
// ** result column name is just the table column
// ** name: COLUMN. Otherwise use zSpan.
// **
// ** full=ON, short=ANY: If the result refers directly to a table column,
// ** then the result column name with the table name
// ** prefix, ex: TABLE.COLUMN. Otherwise use zSpan.
// */
func _sqlite3GenerateColumnNames(tls *libc.TLS, pParse uintptr, pSelect uintptr) {
bp := tls.Alloc(32)
defer tls.Free(32)
var db, p, pEList, pTab, pTabList, v, z, zCol, zName, zName1, v2 uintptr
var fullName, i, iCol, srcName int32
_, _, _, _, _, _, _, _, _, _, _, _, _, _, _ = db, fullName, i, iCol, p, pEList, pTab, pTabList, srcName, v, z, zCol, zName, zName1, v2
v = (*TParse)(unsafe.Pointer(pParse)).FpVdbe
db = (*TParse)(unsafe.Pointer(pParse)).Fdb /* COLUMN or TABLE.COLUMN if no AS clause and is direct */
if int32(Tbft(*(*uint16)(unsafe.Pointer(pParse + 40))&0x20>>5)) != 0 {
return
}
/* Column names are determined by the left-most term of a compound select */
for (*TSelect)(unsafe.Pointer(pSelect)).FpPrior != 0 {
pSelect = (*TSelect)(unsafe.Pointer(pSelect)).FpPrior
}
pTabList = (*TSelect)(unsafe.Pointer(pSelect)).FpSrc
pEList = (*TSelect)(unsafe.Pointer(pSelect)).FpEList
libc.SetBitFieldPtr16Uint32(pParse+40, libc.Uint32FromInt32(1), 5, 0x20)
fullName = libc.BoolInt32((*Tsqlite3)(unsafe.Pointer(db)).Fflags&uint64(SQLITE_FullColNames) != uint64(0))
srcName = libc.BoolInt32((*Tsqlite3)(unsafe.Pointer(db)).Fflags&uint64(SQLITE_ShortColNames) != uint64(0) || fullName != 0)
_sqlite3VdbeSetNumCols(tls, v, (*TExprList)(unsafe.Pointer(pEList)).FnExpr)
i = 0
for {
if !(i < (*TExprList)(unsafe.Pointer(pEList)).FnExpr) {
break
}
p = (*(*TExprList_item)(unsafe.Pointer(pEList + 8 + uintptr(i)*32))).FpExpr
/* Agg processing has not run yet */
/* Covering idx not yet coded */
if (*(*TExprList_item)(unsafe.Pointer(pEList + 8 + uintptr(i)*32))).FzEName != 0 && int32(uint32(*(*uint16)(unsafe.Pointer(pEList + 8 + uintptr(i)*32 + 16 + 4))&0x3>>0)) == ENAME_NAME {
/* An AS clause always takes first priority */
zName = (*(*TExprList_item)(unsafe.Pointer(pEList + 8 + uintptr(i)*32))).FzEName
_sqlite3VdbeSetColName(tls, v, i, COLNAME_NAME, zName, uintptr(-libc.Int32FromInt32(1)))
} else {
if srcName != 0 && libc.Int32FromUint8((*TExpr)(unsafe.Pointer(p)).Fop) == int32(TK_COLUMN) {
iCol = int32((*TExpr)(unsafe.Pointer(p)).FiColumn)
pTab = *(*uintptr)(unsafe.Pointer(p + 64))
if iCol < 0 {
iCol = int32((*TTable)(unsafe.Pointer(pTab)).FiPKey)
}
if iCol < 0 {
zCol = __ccgo_ts + 18314
} else {
zCol = (**(**TColumn)(__ccgo_up((*TTable)(unsafe.Pointer(pTab)).FaCol + uintptr(iCol)*16))).FzCnName
}
if fullName != 0 {
zName1 = uintptr(0)
zName1 = _sqlite3MPrintf(tls, db, __ccgo_ts+13980, libc.VaList(bp+8, (*TTable)(unsafe.Pointer(pTab)).FzName, zCol))
_sqlite3VdbeSetColName(tls, v, i, COLNAME_NAME, zName1, __ccgo_fp(_sqlite3RowSetClear))
} else {
_sqlite3VdbeSetColName(tls, v, i, COLNAME_NAME, zCol, uintptr(-libc.Int32FromInt32(1)))
}
} else {
z = (*(*TExprList_item)(unsafe.Pointer(pEList + 8 + uintptr(i)*32))).FzEName
if z == uintptr(0) {
v2 = _sqlite3MPrintf(tls, db, __ccgo_ts+21029, libc.VaList(bp+8, i+int32(1)))
} else {
v2 = _sqlite3DbStrDup(tls, db, z)
}
z = v2
_sqlite3VdbeSetColName(tls, v, i, COLNAME_NAME, z, __ccgo_fp(_sqlite3RowSetClear))
}
}
goto _1
_1:
;
i = i + 1
}
_generateColumnTypes(tls, pParse, pTabList, pEList)
}
// C documentation
//
// /*
// ** Generate code to do constraint checks prior to an INSERT or an UPDATE
// ** on table pTab.
// **
// ** The regNewData parameter is the first register in a range that contains
// ** the data to be inserted or the data after the update. There will be
// ** pTab->nCol+1 registers in this range. The first register (the one
// ** that regNewData points to) will contain the new rowid, or NULL in the
// ** case of a WITHOUT ROWID table. The second register in the range will
// ** contain the content of the first table column. The third register will
// ** contain the content of the second table column. And so forth.
// **
// ** The regOldData parameter is similar to regNewData except that it contains
// ** the data prior to an UPDATE rather than afterwards. regOldData is zero
// ** for an INSERT. This routine can distinguish between UPDATE and INSERT by
// ** checking regOldData for zero.
// **
// ** For an UPDATE, the pkChng boolean is true if the true primary key (the
// ** rowid for a normal table or the PRIMARY KEY for a WITHOUT ROWID table)
// ** might be modified by the UPDATE. If pkChng is false, then the key of
// ** the iDataCur content table is guaranteed to be unchanged by the UPDATE.
// **
// ** For an INSERT, the pkChng boolean indicates whether or not the rowid
// ** was explicitly specified as part of the INSERT statement. If pkChng
// ** is zero, it means that the either rowid is computed automatically or
// ** that the table is a WITHOUT ROWID table and has no rowid. On an INSERT,
// ** pkChng will only be true if the INSERT statement provides an integer
// ** value for either the rowid column or its INTEGER PRIMARY KEY alias.
// **
// ** The code generated by this routine will store new index entries into
// ** registers identified by aRegIdx[]. No index entry is created for
// ** indices where aRegIdx[i]==0. The order of indices in aRegIdx[] is
// ** the same as the order of indices on the linked list of indices
// ** at pTab->pIndex.
// **
// ** (2019-05-07) The generated code also creates a new record for the
// ** main table, if pTab is a rowid table, and stores that record in the
// ** register identified by aRegIdx[nIdx] - in other words in the first
// ** entry of aRegIdx[] past the last index. It is important that the
// ** record be generated during constraint checks to avoid affinity changes
// ** to the register content that occur after constraint checks but before
// ** the new record is inserted.
// **
// ** The caller must have already opened writeable cursors on the main
// ** table and all applicable indices (that is to say, all indices for which
// ** aRegIdx[] is not zero). iDataCur is the cursor for the main table when
// ** inserting or updating a rowid table, or the cursor for the PRIMARY KEY
// ** index when operating on a WITHOUT ROWID table. iIdxCur is the cursor
// ** for the first index in the pTab->pIndex list. Cursors for other indices
// ** are at iIdxCur+N for the N-th element of the pTab->pIndex list.
// **
// ** This routine also generates code to check constraints. NOT NULL,
// ** CHECK, and UNIQUE constraints are all checked. If a constraint fails,
// ** then the appropriate action is performed. There are five possible
// ** actions: ROLLBACK, ABORT, FAIL, REPLACE, and IGNORE.
// **
// ** Constraint type Action What Happens
// ** --------------- ---------- ----------------------------------------
// ** any ROLLBACK The current transaction is rolled back and
// ** sqlite3_step() returns immediately with a
// ** return code of SQLITE_CONSTRAINT.
// **
// ** any ABORT Back out changes from the current command
// ** only (do not do a complete rollback) then
// ** cause sqlite3_step() to return immediately
// ** with SQLITE_CONSTRAINT.
// **
// ** any FAIL Sqlite3_step() returns immediately with a
// ** return code of SQLITE_CONSTRAINT. The
// ** transaction is not rolled back and any
// ** changes to prior rows are retained.
// **
// ** any IGNORE The attempt in insert or update the current
// ** row is skipped, without throwing an error.
// ** Processing continues with the next row.
// ** (There is an immediate jump to ignoreDest.)
// **
// ** NOT NULL REPLACE The NULL value is replace by the default
// ** value for that column. If the default value
// ** is NULL, the action is the same as ABORT.
// **
// ** UNIQUE REPLACE The other row that conflicts with the row
// ** being inserted is removed.
// **
// ** CHECK REPLACE Illegal. The results in an exception.
// **
// ** Which action to take is determined by the overrideError parameter.
// ** Or if overrideError==OE_Default, then the pParse->onError parameter
// ** is used. Or if pParse->onError==OE_Default then the onError value
// ** for the constraint is used.
// */
func _sqlite3GenerateConstraintChecks(tls *libc.TLS, pParse uintptr, pTab uintptr, aRegIdx uintptr, iDataCur int32, iIdxCur int32, regNewData int32, regOldData int32, pkChng Tu8, overrideError Tu8, ignoreDest int32, pbMayReplace uintptr, aiChng uintptr, pUpsert uintptr) {
bp := tls.Alloc(80)
defer tls.Free(80)
var addr1, addrBypass, addrConflictCk, addrJump, addrRecheck, addrRowidOk, addrUniqueOk, allOk, b2ndPass, i, iField, iReg, iThisCur, ipkBottom, ipkTop, isGenerated, jj, lblRecheckOk, nCol, nConflictCk, nGenerated, nIdx, nPkField, nReplaceTrig, nSeenReplace, onError, op, p2, regCmp, regIdx, regR, regRec, regTrigCnt, seenReplace, upsertIpkDelay, upsertIpkReturn, x, x1, v2 int32
var bAffinityDone, isUpdate Tu8
var bUsed, db, p4, pCheck, pCol, pCopy, pExpr, pIdx, pPk, pTerm, pTrigger, pUpsertClause, v, zMsg, zName, zP4, v8 uintptr
var nByte Tu64
var _ /* ix at bp+0 */ int32
var _ /* sIdxIter at bp+8 */ TIndexIterator
var _ /* x at bp+32 */ TVdbeOp
_, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _ = addr1, addrBypass, addrConflictCk, addrJump, addrRecheck, addrRowidOk, addrUniqueOk, allOk, b2ndPass, bAffinityDone, bUsed, db, i, iField, iReg, iThisCur, ipkBottom, ipkTop, isGenerated, isUpdate, jj, lblRecheckOk, nByte, nCol, nConflictCk, nGenerated, nIdx, nPkField, nReplaceTrig, nSeenReplace, onError, op, p2, p4, pCheck, pCol, pCopy, pExpr, pIdx, pPk, pTerm, pTrigger, pUpsertClause, regCmp, regIdx, regR, regRec, regTrigCnt, seenReplace, upsertIpkDelay, upsertIpkReturn, v, x, x1, zMsg, zName, zP4, v2, v8 /* Pointer to one of the indices */
pPk = uintptr(0) /* Conflict resolution strategy */
seenReplace = 0 /* Number of fields in PRIMARY KEY. 1 for ROWID tables */
pUpsertClause = uintptr(0) /* True if this is an UPDATE operation */
bAffinityDone = uint8(0) /* True if the OP_Affinity operation has been run */
upsertIpkReturn = 0 /* Address of Goto at end of IPK uniqueness check */
upsertIpkDelay = 0 /* Address of Goto to bypass initial IPK check */
ipkTop = 0 /* Top of the IPK uniqueness check */
ipkBottom = 0 /* Register used to count replace trigger invocations */
addrRecheck = 0 /* Jump here to recheck all uniqueness constraints */
lblRecheckOk = 0 /* List of DELETE triggers on the table pTab */
nReplaceTrig = 0 /* Index iterator */
isUpdate = libc.BoolUint8(regOldData != 0)
db = (*TParse)(unsafe.Pointer(pParse)).Fdb
v = (*TParse)(unsafe.Pointer(pParse)).FpVdbe
/* This table is not a VIEW */
nCol = int32((*TTable)(unsafe.Pointer(pTab)).FnCol)
/* pPk is the PRIMARY KEY index for WITHOUT ROWID tables and NULL for
** normal rowid tables. nPkField is the number of key fields in the
** pPk index or 1 for a rowid table. In other words, nPkField is the
** number of fields in the true primary key of the table. */
if (*TTable)(unsafe.Pointer(pTab)).FtabFlags&uint32(TF_WithoutRowid) == uint32(0) {
pPk = uintptr(0)
nPkField = int32(1)
} else {
pPk = _sqlite3PrimaryKeyIndex(tls, pTab)
nPkField = libc.Int32FromUint16((*TIndex)(unsafe.Pointer(pPk)).FnKeyCol)
}
/* Record that this module has started */
/* Test all NOT NULL constraints.
*/
if (*TTable)(unsafe.Pointer(pTab)).FtabFlags&uint32(TF_HasNotNull) != 0 {
b2ndPass = 0 /* True if currently running 2nd pass */
nSeenReplace = 0 /* Number of ON CONFLICT REPLACE operations */
nGenerated = 0 /* Number of generated columns with NOT NULL */
for int32(1) != 0 { /* Make 2 passes over columns. Exit loop via "break" */
i = 0
for {
if !(i < nCol) {
break
} /* Register holding column value */
pCol = (*TTable)(unsafe.Pointer(pTab)).FaCol + uintptr(i)*16 /* non-zero if column is generated */
onError = int32(uint32(*(*uint8)(unsafe.Pointer(pCol + 8)) & 0xf >> 0))
if onError == OE_None {
goto _1
} /* No NOT NULL on this column */
if i == int32((*TTable)(unsafe.Pointer(pTab)).FiPKey) {
goto _1 /* ROWID is never NULL */
}
isGenerated = libc.Int32FromUint16((*TColumn)(unsafe.Pointer(pCol)).FcolFlags) & int32(COLFLAG_GENERATED)
if isGenerated != 0 && !(b2ndPass != 0) {
nGenerated = nGenerated + 1
goto _1 /* Generated columns processed on 2nd pass */
}
if aiChng != 0 && **(**int32)(__ccgo_up(aiChng + uintptr(i)*4)) < 0 && !(isGenerated != 0) {
/* Do not check NOT NULL on columns that do not change */
goto _1
}
if libc.Int32FromUint8(overrideError) != int32(OE_Default) {
onError = libc.Int32FromUint8(overrideError)
} else {
if onError == int32(OE_Default) {
onError = int32(OE_Abort)
}
}
if onError == int32(OE_Replace) {
if b2ndPass != 0 || libc.Int32FromUint16((*TColumn)(unsafe.Pointer(pCol)).FiDflt) == 0 {
onError = int32(OE_Abort)
} else {
}
} else {
if b2ndPass != 0 && !(isGenerated != 0) {
goto _1
}
}
iReg = int32(_sqlite3TableColumnToStorage(tls, pTab, int16(i))) + regNewData + int32(1)
switch onError {
case int32(OE_Replace):
addr1 = _sqlite3VdbeAddOp1(tls, v, int32(OP_NotNull), iReg)
nSeenReplace = nSeenReplace + 1
_sqlite3ExprCodeCopy(tls, pParse, _sqlite3ColumnExpr(tls, pTab, pCol), iReg)
_sqlite3VdbeJumpHere(tls, v, addr1)
case int32(OE_Abort):
_sqlite3MayAbort(tls, pParse)
fallthrough
case int32(OE_Rollback):
fallthrough
case int32(OE_Fail):
zMsg = _sqlite3MPrintf(tls, db, __ccgo_ts+13980, libc.VaList(bp+64, (*TTable)(unsafe.Pointer(pTab)).FzName, (*TColumn)(unsafe.Pointer(pCol)).FzCnName))
_sqlite3VdbeAddOp3(tls, v, int32(OP_HaltIfNull), libc.Int32FromInt32(SQLITE_CONSTRAINT)|libc.Int32FromInt32(5)< 0 && (*TTable)(unsafe.Pointer(pTab)).FtabFlags&uint32(TF_HasGenerated) != uint32(0) {
/* If any NOT NULL ON CONFLICT REPLACE constraints fired on the
** first pass, recomputed values for all generated columns, as
** those values might depend on columns affected by the REPLACE.
*/
_sqlite3ComputeGeneratedColumns(tls, pParse, regNewData+int32(1), pTab)
}
} /* end of 2-pass loop */
} /* end if( has-not-null-constraints ) */
/* Test all CHECK constraints
*/
if (*TTable)(unsafe.Pointer(pTab)).FpCheck != 0 && (*Tsqlite3)(unsafe.Pointer(db)).Fflags&uint64(SQLITE_IgnoreChecks) == uint64(0) {
pCheck = (*TTable)(unsafe.Pointer(pTab)).FpCheck
(*TParse)(unsafe.Pointer(pParse)).FiSelfTab = -(regNewData + int32(1))
if libc.Int32FromUint8(overrideError) != int32(OE_Default) {
v2 = libc.Int32FromUint8(overrideError)
} else {
v2 = int32(OE_Abort)
}
onError = v2
i = 0
for {
if !(i < (*TExprList)(unsafe.Pointer(pCheck)).FnExpr) {
break
}
pExpr = (*(*TExprList_item)(unsafe.Pointer(pCheck + 8 + uintptr(i)*32))).FpExpr
if aiChng != 0 && !(_sqlite3ExprReferencesUpdatedColumn(tls, pExpr, aiChng, libc.Int32FromUint8(pkChng)) != 0) {
/* The check constraints do not reference any of the columns being
** updated so there is no point it verifying the check constraint */
goto _3
}
if libc.Int32FromUint8(bAffinityDone) == 0 {
_sqlite3TableAffinity(tls, v, pTab, regNewData+int32(1))
bAffinityDone = uint8(1)
}
allOk = _sqlite3VdbeMakeLabel(tls, pParse)
pCopy = _sqlite3ExprDup(tls, db, pExpr, 0)
if !((*Tsqlite3)(unsafe.Pointer(db)).FmallocFailed != 0) {
_sqlite3ExprIfTrue(tls, pParse, pCopy, allOk, int32(SQLITE_JUMPIFNULL))
}
_sqlite3ExprDelete(tls, db, pCopy)
if onError == int32(OE_Ignore) {
_sqlite3VdbeGoto(tls, v, ignoreDest)
} else {
zName = (*(*TExprList_item)(unsafe.Pointer(pCheck + 8 + uintptr(i)*32))).FzEName
if onError == int32(OE_Replace) {
onError = int32(OE_Abort)
} /* IMP: R-26383-51744 */
_sqlite3HaltConstraint(tls, pParse, libc.Int32FromInt32(SQLITE_CONSTRAINT)|libc.Int32FromInt32(1)<>0)) == int32(SQLITE_IDXTYPE_PRIMARYKEY) {
v2 = regIdx
} else {
v2 = regR
}
regCmp = v2
i = 0
for {
if !(i < libc.Int32FromUint16((*TIndex)(unsafe.Pointer(pPk)).FnKeyCol)) {
break
}
p4 = _sqlite3LocateCollSeq(tls, pParse, **(**uintptr)(__ccgo_up((*TIndex)(unsafe.Pointer(pPk)).FazColl + uintptr(i)*8)))
x1 = int32(**(**Ti16)(__ccgo_up((*TIndex)(unsafe.Pointer(pPk)).FaiColumn + uintptr(i)*2)))
if i == libc.Int32FromUint16((*TIndex)(unsafe.Pointer(pPk)).FnKeyCol)-int32(1) {
addrJump = addrUniqueOk
op = int32(OP_Eq)
}
x1 = int32(_sqlite3TableColumnToStorage(tls, pTab, int16(x1)))
_sqlite3VdbeAddOp4(tls, v, op, regOldData+int32(1)+x1, addrJump, regCmp+i, p4, -int32(2))
_sqlite3VdbeChangeP5(tls, v, uint16(SQLITE_NOTNULL))
goto _14
_14:
;
i = i + 1
}
}
}
}
/* Generate code that executes if the new index entry is not unique */
switch onError {
case int32(OE_Rollback):
fallthrough
case int32(OE_Abort):
fallthrough
case int32(OE_Fail):
_sqlite3UniqueConstraint(tls, pParse, onError, pIdx)
case int32(OE_Update):
_sqlite3UpsertDoUpdate(tls, pParse, pUpsert, pTab, pIdx, iIdxCur+**(**int32)(__ccgo_up(bp)))
fallthrough
case int32(OE_Ignore):
_sqlite3VdbeGoto(tls, v, ignoreDest)
default: /* Number of opcodes in conflict check logic */
nConflictCk = _sqlite3VdbeCurrentAddr(tls, v) - addrConflictCk
if regTrigCnt != 0 {
_sqlite3MultiWrite(tls, pParse)
nReplaceTrig = nReplaceTrig + 1
}
if pTrigger != 0 && isUpdate != 0 {
_sqlite3VdbeAddOp1(tls, v, int32(OP_CursorLock), iDataCur)
}
if pIdx == pPk {
v2 = int32(ONEPASS_SINGLE)
} else {
v2 = ONEPASS_OFF
}
_sqlite3GenerateRowDelete(tls, pParse, pTab, pTrigger, iDataCur, iIdxCur, regR, int16(nPkField), uint8(0), uint8(OE_Replace), libc.Uint8FromInt32(v2), iThisCur)
if pTrigger != 0 && isUpdate != 0 {
_sqlite3VdbeAddOp1(tls, v, int32(OP_CursorUnlock), iDataCur)
}
if regTrigCnt != 0 { /* Jump destination to bypass recheck logic */
_sqlite3VdbeAddOp2(tls, v, int32(OP_AddImm), regTrigCnt, int32(1)) /* incr trigger cnt */
addrBypass = _sqlite3VdbeAddOp0(tls, v, int32(OP_Goto)) /* Bypass recheck */
/* Here we insert code that will be invoked after all constraint
** checks have run, if and only if one or more replace triggers
** fired. */
_sqlite3VdbeResolveLabel(tls, v, lblRecheckOk)
lblRecheckOk = _sqlite3VdbeMakeLabel(tls, pParse)
if (*TIndex)(unsafe.Pointer(pIdx)).FpPartIdxWhere != 0 {
/* Bypass the recheck if this partial index is not defined
** for the current row */
_sqlite3VdbeAddOp2(tls, v, int32(OP_IsNull), regIdx-int32(1), lblRecheckOk)
}
/* Copy the constraint check code from above, except change
** the constraint-ok jump destination to be the address of
** the next retest block */
for nConflictCk > 0 { /* Conflict check opcode to copy */
/* The sqlite3VdbeAddOp4() call might reallocate the opcode array.
** Hence, make a complete copy of the opcode, rather than using
** a pointer to the opcode. */
**(**TVdbeOp)(__ccgo_up(bp + 32)) = **(**TVdbeOp)(__ccgo_up(_sqlite3VdbeGetOp(tls, v, addrConflictCk)))
if libc.Int32FromUint8((**(**TVdbeOp)(__ccgo_up(bp + 32))).Fopcode) != int32(OP_IdxRowid) {
if libc.Int32FromUint8(_sqlite3OpcodeProperty[(**(**TVdbeOp)(__ccgo_up(bp + 32))).Fopcode])&int32(OPFLG_JUMP) != 0 {
p2 = lblRecheckOk
} else {
p2 = (**(**TVdbeOp)(__ccgo_up(bp + 32))).Fp2
}
if int32((**(**TVdbeOp)(__ccgo_up(bp + 32))).Fp4type) == -int32(3) {
v8 = uintptr(int64(*(*int32)(unsafe.Pointer(bp + 32 + 16))))
} else {
v8 = *(*uintptr)(unsafe.Pointer(bp + 32 + 16))
}
zP4 = v8
_sqlite3VdbeAddOp4(tls, v, libc.Int32FromUint8((**(**TVdbeOp)(__ccgo_up(bp + 32))).Fopcode), (**(**TVdbeOp)(__ccgo_up(bp + 32))).Fp1, p2, (**(**TVdbeOp)(__ccgo_up(bp + 32))).Fp3, zP4, int32((**(**TVdbeOp)(__ccgo_up(bp + 32))).Fp4type))
_sqlite3VdbeChangeP5(tls, v, (**(**TVdbeOp)(__ccgo_up(bp + 32))).Fp5)
}
nConflictCk = nConflictCk - 1
addrConflictCk = addrConflictCk + 1
}
/* If the retest fails, issue an abort */
_sqlite3UniqueConstraint(tls, pParse, int32(OE_Abort), pIdx)
_sqlite3VdbeJumpHere(tls, v, addrBypass) /* Terminate the recheck bypass */
}
seenReplace = int32(1)
break
}
_sqlite3VdbeResolveLabel(tls, v, addrUniqueOk)
if regR != regIdx {
_sqlite3ReleaseTempRange(tls, pParse, regR, nPkField)
}
if pUpsertClause != 0 && upsertIpkReturn != 0 && _sqlite3UpsertNextIsIPK(tls, pUpsertClause) != 0 {
_sqlite3VdbeGoto(tls, v, upsertIpkDelay+int32(1))
_sqlite3VdbeJumpHere(tls, v, upsertIpkReturn)
upsertIpkReturn = 0
}
goto _9
_9:
;
pIdx = _indexIteratorNext(tls, bp+8, bp)
}
/* If the IPK constraint is a REPLACE, run it last */
if ipkTop != 0 {
_sqlite3VdbeGoto(tls, v, ipkTop)
_sqlite3VdbeJumpHere(tls, v, ipkBottom)
}
/* Recheck all uniqueness constraints after replace triggers have run */
if nReplaceTrig != 0 {
_sqlite3VdbeAddOp2(tls, v, int32(OP_IfNot), regTrigCnt, lblRecheckOk)
if !(pPk != 0) {
if isUpdate != 0 {
_sqlite3VdbeAddOp3(tls, v, int32(OP_Eq), regNewData, addrRecheck, regOldData)
_sqlite3VdbeChangeP5(tls, v, uint16(SQLITE_NOTNULL))
}
_sqlite3VdbeAddOp3(tls, v, int32(OP_NotExists), iDataCur, addrRecheck, regNewData)
_sqlite3RowidConstraint(tls, pParse, int32(OE_Abort), pTab)
} else {
_sqlite3VdbeGoto(tls, v, addrRecheck)
}
_sqlite3VdbeResolveLabel(tls, v, lblRecheckOk)
}
/* Generate the table record */
if (*TTable)(unsafe.Pointer(pTab)).FtabFlags&uint32(TF_WithoutRowid) == uint32(0) {
regRec = **(**int32)(__ccgo_up(aRegIdx + uintptr(**(**int32)(__ccgo_up(bp)))*4))
_sqlite3VdbeAddOp3(tls, v, int32(OP_MakeRecord), regNewData+int32(1), int32((*TTable)(unsafe.Pointer(pTab)).FnNVCol), regRec)
if !(bAffinityDone != 0) {
_sqlite3TableAffinity(tls, v, pTab, 0)
}
}
**(**int32)(__ccgo_up(pbMayReplace)) = seenReplace
}
// C documentation
//
// /*
// ** This routine generates VDBE code that causes a single row of a
// ** single table to be deleted. Both the original table entry and
// ** all indices are removed.
// **
// ** Preconditions:
// **
// ** 1. iDataCur is an open cursor on the btree that is the canonical data
// ** store for the table. (This will be either the table itself,
// ** in the case of a rowid table, or the PRIMARY KEY index in the case
// ** of a WITHOUT ROWID table.)
// **
// ** 2. Read/write cursors for all indices of pTab must be open as
// ** cursor number iIdxCur+i for the i-th index.
// **
// ** 3. The primary key for the row to be deleted must be stored in a
// ** sequence of nPk memory cells starting at iPk. If nPk==0 that means
// ** that a search record formed from OP_MakeRecord is contained in the
// ** single memory location iPk.
// **
// ** eMode:
// ** Parameter eMode may be passed either ONEPASS_OFF (0), ONEPASS_SINGLE, or
// ** ONEPASS_MULTI. If eMode is not ONEPASS_OFF, then the cursor
// ** iDataCur already points to the row to delete. If eMode is ONEPASS_OFF
// ** then this function must seek iDataCur to the entry identified by iPk
// ** and nPk before reading from it.
// **
// ** If eMode is ONEPASS_MULTI, then this call is being made as part
// ** of a ONEPASS delete that affects multiple rows. In this case, if
// ** iIdxNoSeek is a valid cursor number (>=0) and is not the same as
// ** iDataCur, then its position should be preserved following the delete
// ** operation. Or, if iIdxNoSeek is not a valid cursor number, the
// ** position of iDataCur should be preserved instead.
// **
// ** iIdxNoSeek:
// ** If iIdxNoSeek is a valid cursor number (>=0) not equal to iDataCur,
// ** then it identifies an index cursor (from within array of cursors
// ** starting at iIdxCur) that already points to the index entry to be deleted.
// ** Except, this optimization is disabled if there are BEFORE triggers since
// ** the trigger body might have moved the cursor.
// */
func _sqlite3GenerateRowDelete(tls *libc.TLS, pParse uintptr, pTab uintptr, pTrigger uintptr, iDataCur int32, iIdxCur int32, iPk int32, nPk Ti16, count Tu8, onconf Tu8, eMode Tu8, iIdxNoSeek int32) {
var addrStart, iCol, iLabel, iOld, kk, v1 int32
var mask Tu32
var opSeek, p5 Tu8
var v uintptr
_, _, _, _, _, _, _, _, _, _ = addrStart, iCol, iLabel, iOld, kk, mask, opSeek, p5, v, v1
v = (*TParse)(unsafe.Pointer(pParse)).FpVdbe /* Vdbe */
iOld = 0 /* Seek opcode */
/* Vdbe is guaranteed to have been allocated by this stage. */
/* Seek cursor iCur to the row to delete. If this row no longer exists
** (this can happen if a trigger program has already deleted it), do
** not attempt to delete it or fire any DELETE triggers. */
iLabel = _sqlite3VdbeMakeLabel(tls, pParse)
if (*TTable)(unsafe.Pointer(pTab)).FtabFlags&uint32(TF_WithoutRowid) == uint32(0) {
v1 = int32(OP_NotExists)
} else {
v1 = int32(OP_NotFound)
}
opSeek = libc.Uint8FromInt32(v1)
if libc.Int32FromUint8(eMode) == ONEPASS_OFF {
_sqlite3VdbeAddOp4Int(tls, v, libc.Int32FromUint8(opSeek), iDataCur, iLabel, iPk, int32(nPk))
}
/* If there are any triggers to fire, allocate a range of registers to
** use for the old.* references in the triggers. */
if _sqlite3FkRequired(tls, pParse, pTab, uintptr(0), 0) != 0 || pTrigger != 0 { /* Start of BEFORE trigger programs */
/* TODO: Could use temporary registers here. Also could attempt to
** avoid copying the contents of the rowid register. */
mask = _sqlite3TriggerColmask(tls, pParse, pTrigger, uintptr(0), 0, libc.Int32FromInt32(TRIGGER_BEFORE)|libc.Int32FromInt32(TRIGGER_AFTER), pTab, libc.Int32FromUint8(onconf))
mask = mask | _sqlite3FkOldmask(tls, pParse, pTab)
iOld = (*TParse)(unsafe.Pointer(pParse)).FnMem + int32(1)
**(**int32)(__ccgo_up(pParse + 60)) += int32(1) + int32((*TTable)(unsafe.Pointer(pTab)).FnCol)
/* Populate the OLD.* pseudo-table register array. These values will be
** used by any BEFORE and AFTER triggers that exist. */
_sqlite3VdbeAddOp2(tls, v, int32(OP_Copy), iPk, iOld)
iCol = 0
for {
if !(iCol < int32((*TTable)(unsafe.Pointer(pTab)).FnCol)) {
break
}
if mask == uint32(0xffffffff) || iCol <= int32(31) && mask&(libc.Uint32FromInt32(1)<= 0 && iIdxNoSeek != iDataCur {
_sqlite3VdbeAddOp1(tls, v, int32(OP_Delete), iIdxNoSeek)
}
if libc.Int32FromUint8(eMode) == int32(ONEPASS_MULTI) {
p5 = libc.Uint8FromInt32(int32(p5) | libc.Int32FromInt32(OPFLAG_SAVEPOSITION))
}
_sqlite3VdbeChangeP5(tls, v, uint16(p5))
}
/* Do any ON CASCADE, SET NULL or SET DEFAULT operations required to
** handle rows (possibly in other tables) that refer via a foreign key
** to the row just deleted. */
_sqlite3FkActions(tls, pParse, pTab, uintptr(0), iOld, uintptr(0), 0)
/* Invoke AFTER DELETE trigger programs. */
if pTrigger != 0 {
_sqlite3CodeRowTrigger(tls, pParse, pTrigger, int32(TK_DELETE), uintptr(0), int32(TRIGGER_AFTER), pTab, iOld, libc.Int32FromUint8(onconf), iLabel)
}
/* Jump here if the row had already been deleted before any BEFORE
** trigger programs were invoked. Or if a trigger program throws a
** RAISE(IGNORE) exception. */
_sqlite3VdbeResolveLabel(tls, v, iLabel)
}
// C documentation
//
// /*
// ** This function is responsible for invoking the collation factory callback
// ** or substituting a collation sequence of a different encoding when the
// ** requested collation sequence is not available in the desired encoding.
// **
// ** If it is not NULL, then pColl must point to the database native encoding
// ** collation sequence with name zName, length nName.
// **
// ** The return value is either the collation sequence to be used in database
// ** db for collation type name zName, length nName, or NULL, if no collation
// ** sequence can be found. If no collation is found, leave an error message.
// **
// ** See also: sqlite3LocateCollSeq(), sqlite3FindCollSeq()
// */
func _sqlite3GetCollSeq(tls *libc.TLS, pParse uintptr, enc Tu8, pColl uintptr, zName uintptr) (r uintptr) {
bp := tls.Alloc(16)
defer tls.Free(16)
var db, p uintptr
_, _ = db, p
db = (*TParse)(unsafe.Pointer(pParse)).Fdb
p = pColl
if !(p != 0) {
p = _sqlite3FindCollSeq(tls, db, enc, zName, 0)
}
if !(p != 0) || !((*TCollSeq)(unsafe.Pointer(p)).FxCmp != 0) {
/* No collation sequence of this type for this encoding is registered.
** Call the collation factory to see if it can supply us with one.
*/
_callCollNeeded(tls, db, libc.Int32FromUint8(enc), zName)
p = _sqlite3FindCollSeq(tls, db, enc, zName, 0)
}
if p != 0 && !((*TCollSeq)(unsafe.Pointer(p)).FxCmp != 0) && _synthCollSeq(tls, db, p) != 0 {
p = uintptr(0)
}
if p == uintptr(0) {
_sqlite3ErrorMsg(tls, pParse, __ccgo_ts+16662, libc.VaList(bp+8, zName))
(*TParse)(unsafe.Pointer(pParse)).Frc = libc.Int32FromInt32(SQLITE_ERROR) | libc.Int32FromInt32(1)<= 0 && c <= int32(9)) {
break
}
v = v*int64(10) + int64(c)
goto _2
_2:
;
i = i + 1
}
/* The longest decimal representation of a 32 bit integer is 10 digits:
**
** 1234567890
** 2^31 -> 2147483648
*/
if i > int32(10) {
return 0
}
if v-int64(neg) > int64(2147483647) {
return 0
}
if neg != 0 {
v = -v
}
**(**int32)(__ccgo_up(pValue)) = int32(v)
return int32(1)
}
// C documentation
//
// /*
// ** If expression list pList contains an expression that was parsed with
// ** an explicit "NULLS FIRST" or "NULLS LAST" clause, leave an error in
// ** pParse and return non-zero. Otherwise, return zero.
// */
func _sqlite3HasExplicitNulls(tls *libc.TLS, pParse uintptr, pList uintptr) (r int32) {
bp := tls.Alloc(16)
defer tls.Free(16)
var i int32
var sf Tu8
var v2 uintptr
_, _, _ = i, sf, v2
if pList != 0 {
i = 0
for {
if !(i < (*TExprList)(unsafe.Pointer(pList)).FnExpr) {
break
}
if int32(uint32(*(*uint16)(unsafe.Pointer(pList + 8 + uintptr(i)*32 + 16 + 4))&0x20>>5)) != 0 {
sf = (*(*TExprList_item)(unsafe.Pointer(pList + 8 + uintptr(i)*32))).Ffg.FsortFlags
if libc.Int32FromUint8(sf) == 0 || libc.Int32FromUint8(sf) == int32(3) {
v2 = __ccgo_ts + 15722
} else {
v2 = __ccgo_ts + 15728
}
_sqlite3ErrorMsg(tls, pParse, __ccgo_ts+15733, libc.VaList(bp+8, v2))
return int32(1)
}
goto _1
_1:
;
i = i + 1
}
}
return 0
}
// C documentation
//
// /*
// ** If the source-list item passed as an argument was augmented with an
// ** INDEXED BY clause, then try to locate the specified index. If there
// ** was such a clause and the named index cannot be found, return
// ** SQLITE_ERROR and leave an error in pParse. Otherwise, populate
// ** pFrom->pIndex and return SQLITE_OK.
// */
func _sqlite3IndexedByLookup(tls *libc.TLS, pParse uintptr, pFrom uintptr) (r int32) {
bp := tls.Alloc(32)
defer tls.Free(32)
var pIdx, pTab, zIndexedBy uintptr
_, _, _ = pIdx, pTab, zIndexedBy
pTab = (*TSrcItem)(unsafe.Pointer(pFrom)).FpSTab
zIndexedBy = *(*uintptr)(unsafe.Pointer(pFrom + 48))
pIdx = (*TTable)(unsafe.Pointer(pTab)).FpIndex
for {
if !(pIdx != 0 && _sqlite3StrICmp(tls, (*TIndex)(unsafe.Pointer(pIdx)).FzName, zIndexedBy) != 0) {
break
}
goto _1
_1:
;
pIdx = (*TIndex)(unsafe.Pointer(pIdx)).FpNext
}
if !(pIdx != 0) {
_sqlite3ErrorMsg(tls, pParse, __ccgo_ts+21409, libc.VaList(bp+8, zIndexedBy, 0))
libc.SetBitFieldPtr16Uint32(pParse+40, libc.Uint32FromInt32(1), 8, 0x100)
return int32(SQLITE_ERROR)
}
*(*uintptr)(unsafe.Pointer(pFrom + 56)) = pIdx
return SQLITE_OK
}
// C documentation
//
// /*
// ** 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 + 44)) |= 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*8)) == uintptr(0) {
_corruptSchema(tls, pData, argv, uintptr(0))
} else {
if **(**uintptr)(__ccgo_up(argv + 4*8)) != 0 && int32('c') == libc.Int32FromUint8(_sqlite3UpperToLower[libc.Uint8FromInt8(**(**int8)(__ccgo_up(**(**uintptr)(__ccgo_up(argv + 4*8)))))]) && int32('r') == libc.Int32FromUint8(_sqlite3UpperToLower[libc.Uint8FromInt8(**(**int8)(__ccgo_up(**(**uintptr)(__ccgo_up(argv + 4*8)) + 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*8)), db+192) == 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+16088)
}
}
libc.SetBitFieldPtr8Uint32(db+192+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*8)), -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 + 192 + 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*8)) == uintptr(0) || **(**uintptr)(__ccgo_up(argv + 4*8)) != uintptr(0) && int32(**(**int8)(__ccgo_up(**(**uintptr)(__ccgo_up(argv + 4*8))))) != 0 {
_corruptSchema(tls, pData, argv, uintptr(0))
} else {
pIndex = _sqlite3FindIndex(tls, db, **(**uintptr)(__ccgo_up(argv + 1*8)), (**(**TDb)(__ccgo_up((*Tsqlite3)(unsafe.Pointer(db)).FaDb + uintptr(iDb)*32))).FzDbSName)
if pIndex == uintptr(0) {
_corruptSchema(tls, pData, argv, __ccgo_ts+20487)
} else {
if _sqlite3GetUInt32(tls, **(**uintptr)(__ccgo_up(argv + 3*8)), pIndex+88) == 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+16088)
}
}
}
}
}
}
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(144)
defer tls.Free(144)
var encoding Tu8
var i, mask, openedTransaction, rc, size int32
var pDb, zSchemaTabName, zSql, v1, v2 uintptr
var xAuth Tsqlite3_xauth
var _ /* azArg at bp+0 */ [6]uintptr
var _ /* initData at bp+72 */ TInitData
var _ /* meta at bp+48 */ [5]int32
_, _, _, _, _, _, _, _, _, _, _, _ = encoding, i, mask, openedTransaction, pDb, rc, size, xAuth, zSchemaTabName, zSql, v1, v2
openedTransaction = 0
mask = libc.Int32FromUint32((*Tsqlite3)(unsafe.Pointer(db)).FmDbFlags&libc.Uint32FromInt32(DBFLAG_EncodingFixed) | libc.Uint32FromInt32(^libc.Int32FromInt32(DBFLAG_EncodingFixed)))
(*Tsqlite3)(unsafe.Pointer(db)).Finit1.Fbusy = uint8(1)
/* Construct the in-memory representation schema tables (sqlite_schema or
** sqlite_temp_schema) by invoking the parser directly. The appropriate
** table name will be inserted automatically by the parser so we can just
** use the abbreviation "x" here. The parser will also automatically tag
** the schema table as read-only. */
(**(**[6]uintptr)(__ccgo_up(bp)))[0] = __ccgo_ts + 9725
if libc.Bool(!(libc.Int32FromInt32(OMIT_TEMPDB) != 0)) && iDb == int32(1) {
v2 = __ccgo_ts + 7112
} else {
v2 = __ccgo_ts + 6632
}
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 + 20500
(**(**[6]uintptr)(__ccgo_up(bp)))[int32(4)] = __ccgo_ts + 20502
(**(**[6]uintptr)(__ccgo_up(bp)))[int32(5)] = uintptr(0)
(**(**TInitData)(__ccgo_up(bp + 72))).Fdb = db
(**(**TInitData)(__ccgo_up(bp + 72))).FiDb = iDb
(**(**TInitData)(__ccgo_up(bp + 72))).Frc = SQLITE_OK
(**(**TInitData)(__ccgo_up(bp + 72))).FpzErrMsg = pzErrMsg
(**(**TInitData)(__ccgo_up(bp + 72))).FmInitFlags = mFlags
(**(**TInitData)(__ccgo_up(bp + 72))).FnInitRow = uint32(0)
(**(**TInitData)(__ccgo_up(bp + 72))).FmxPage = uint32(0)
_sqlite3InitCallback(tls, bp+72, int32(5), bp, uintptr(0))
**(**Tu32)(__ccgo_up(db + 44)) &= libc.Uint32FromInt32(mask)
if (**(**TInitData)(__ccgo_up(bp + 72))).Frc != 0 {
rc = (**(**TInitData)(__ccgo_up(bp + 72))).Frc
goto error_out
}
/* Create a cursor to hold the database open
*/
pDb = (*Tsqlite3)(unsafe.Pointer(db)).FaDb + uintptr(iDb)*32
if (*TDb)(unsafe.Pointer(pDb)).FpBt == uintptr(0) {
v1 = (**(**TDb)(__ccgo_up((*Tsqlite3)(unsafe.Pointer(db)).FaDb + 1*32))).FpSchema + 114
*(*Tu16)(unsafe.Pointer(v1)) = Tu16(int32(*(*Tu16)(unsafe.Pointer(v1))) | libc.Int32FromInt32(DB_SchemaLoaded))
rc = SQLITE_OK
goto error_out
}
/* If there is not already a read-only (or read-write) transaction opened
** on the b-tree database, open one now. If a transaction is opened, it
** will be closed before this function returns. */
_sqlite3BtreeEnter(tls, (*TDb)(unsafe.Pointer(pDb)).FpBt)
if _sqlite3BtreeTxnState(tls, (*TDb)(unsafe.Pointer(pDb)).FpBt) == SQLITE_TXN_NONE {
rc = _sqlite3BtreeBeginTrans(tls, (*TDb)(unsafe.Pointer(pDb)).FpBt, 0, uintptr(0))
if rc != SQLITE_OK {
_sqlite3SetString(tls, pzErrMsg, db, _sqlite3ErrStr(tls, rc))
goto initone_error_out
}
openedTransaction = int32(1)
}
/* Get the database meta information.
**
** Meta values are as follows:
** meta[0] Schema cookie. Changes with each schema change.
** meta[1] File format of schema layer.
** meta[2] Size of the page cache.
** meta[3] Largest rootpage (auto/incr_vacuum mode)
** meta[4] Db text encoding. 1:UTF-8 2:UTF-16LE 3:UTF-16BE
** meta[5] User version
** meta[6] Incremental vacuum mode
** meta[7] unused
** meta[8] unused
** meta[9] unused
**
** Note: The #defined SQLITE_UTF* symbols in sqliteInt.h correspond to
** the possible values of meta[4].
*/
i = 0
for {
if !(i < libc.Int32FromUint64(libc.Uint64FromInt64(20)/libc.Uint64FromInt64(4))) {
break
}
_sqlite3BtreeGetMeta(tls, (*TDb)(unsafe.Pointer(pDb)).FpBt, i+int32(1), bp+48+uintptr(i)*4)
goto _4
_4:
;
i = i + 1
}
if (*Tsqlite3)(unsafe.Pointer(db)).Fflags&uint64(SQLITE_ResetDatabase) != uint64(0) {
libc.X__builtin___memset_chk(tls, bp+48, 0, uint64(20), ^t__predefined_size_t(0))
}
(*TSchema)(unsafe.Pointer((*TDb)(unsafe.Pointer(pDb)).FpSchema)).Fschema_cookie = (**(**[5]int32)(__ccgo_up(bp + 48)))[libc.Int32FromInt32(BTREE_SCHEMA_VERSION)-libc.Int32FromInt32(1)]
/* If opening a non-empty database, check the text encoding. For the
** main database, set sqlite3.enc to the encoding of the main database.
** For an attached db, it is an error if the encoding is not the same
** as sqlite3.enc.
*/
if (**(**[5]int32)(__ccgo_up(bp + 48)))[libc.Int32FromInt32(BTREE_TEXT_ENCODING)-libc.Int32FromInt32(1)] != 0 { /* text encoding */
if iDb == 0 && (*Tsqlite3)(unsafe.Pointer(db)).FmDbFlags&uint32(DBFLAG_EncodingFixed) == uint32(0) {
/* If opening the main database, set ENC(db). */
encoding = libc.Uint8FromInt32(libc.Int32FromUint8(libc.Uint8FromInt32((**(**[5]int32)(__ccgo_up(bp + 48)))[libc.Int32FromInt32(BTREE_TEXT_ENCODING)-libc.Int32FromInt32(1)])) & int32(3))
if libc.Int32FromUint8(encoding) == 0 {
encoding = uint8(SQLITE_UTF8)
}
_sqlite3SetTextEncoding(tls, db, encoding)
} else {
/* If opening an attached database, the encoding much match ENC(db) */
if (**(**[5]int32)(__ccgo_up(bp + 48)))[libc.Int32FromInt32(BTREE_TEXT_ENCODING)-libc.Int32FromInt32(1)]&int32(3) != libc.Int32FromUint8((*Tsqlite3)(unsafe.Pointer(db)).Fenc) {
_sqlite3SetString(tls, pzErrMsg, db, __ccgo_ts+13694)
rc = int32(SQLITE_ERROR)
goto initone_error_out
}
}
}
(*TSchema)(unsafe.Pointer((*TDb)(unsafe.Pointer(pDb)).FpSchema)).Fenc = (*Tsqlite3)(unsafe.Pointer(db)).Fenc
if (*TSchema)(unsafe.Pointer((*TDb)(unsafe.Pointer(pDb)).FpSchema)).Fcache_size == 0 {
size = _sqlite3AbsInt32(tls, (**(**[5]int32)(__ccgo_up(bp + 48)))[libc.Int32FromInt32(BTREE_DEFAULT_CACHE_SIZE)-libc.Int32FromInt32(1)])
if size == 0 {
size = -int32(2000)
}
(*TSchema)(unsafe.Pointer((*TDb)(unsafe.Pointer(pDb)).FpSchema)).Fcache_size = size
_sqlite3BtreeSetCacheSize(tls, (*TDb)(unsafe.Pointer(pDb)).FpBt, (*TSchema)(unsafe.Pointer((*TDb)(unsafe.Pointer(pDb)).FpSchema)).Fcache_size)
}
/*
** file_format==1 Version 3.0.0.
** file_format==2 Version 3.1.3. // ALTER TABLE ADD COLUMN
** file_format==3 Version 3.1.4. // ditto but with non-NULL defaults
** file_format==4 Version 3.3.0. // DESC indices. Boolean constants
*/
(*TSchema)(unsafe.Pointer((*TDb)(unsafe.Pointer(pDb)).FpSchema)).Ffile_format = libc.Uint8FromInt32((**(**[5]int32)(__ccgo_up(bp + 48)))[libc.Int32FromInt32(BTREE_FILE_FORMAT)-libc.Int32FromInt32(1)])
if libc.Int32FromUint8((*TSchema)(unsafe.Pointer((*TDb)(unsafe.Pointer(pDb)).FpSchema)).Ffile_format) == 0 {
(*TSchema)(unsafe.Pointer((*TDb)(unsafe.Pointer(pDb)).FpSchema)).Ffile_format = uint8(1)
}
if libc.Int32FromUint8((*TSchema)(unsafe.Pointer((*TDb)(unsafe.Pointer(pDb)).FpSchema)).Ffile_format) > int32(SQLITE_MAX_FILE_FORMAT) {
_sqlite3SetString(tls, pzErrMsg, db, __ccgo_ts+20574)
rc = int32(SQLITE_ERROR)
goto initone_error_out
}
/* Ticket #2804: When we open a database in the newer file format,
** clear the legacy_file_format pragma flag so that a VACUUM will
** not downgrade the database and thus invalidate any descending
** indices that the user might have created.
*/
if iDb == 0 && (**(**[5]int32)(__ccgo_up(bp + 48)))[libc.Int32FromInt32(BTREE_FILE_FORMAT)-libc.Int32FromInt32(1)] >= int32(4) {
**(**Tu64)(__ccgo_up(db + 48)) &= ^libc.Uint64FromInt32(SQLITE_LegacyFileFmt)
}
/* Read the schema information out of the schema tables
*/
(**(**TInitData)(__ccgo_up(bp + 72))).FmxPage = _sqlite3BtreeLastPage(tls, (*TDb)(unsafe.Pointer(pDb)).FpBt)
zSql = _sqlite3MPrintf(tls, db, __ccgo_ts+20598, libc.VaList(bp+120, (**(**TDb)(__ccgo_up((*Tsqlite3)(unsafe.Pointer(db)).FaDb + uintptr(iDb)*32))).FzDbSName, zSchemaTabName))
xAuth = (*Tsqlite3)(unsafe.Pointer(db)).FxAuth
(*Tsqlite3)(unsafe.Pointer(db)).FxAuth = uintptr(0)
rc = Xsqlite3_exec(tls, db, zSql, __ccgo_fp(_sqlite3InitCallback), bp+72, uintptr(0))
(*Tsqlite3)(unsafe.Pointer(db)).FxAuth = xAuth
if rc == SQLITE_OK {
rc = (**(**TInitData)(__ccgo_up(bp + 72))).Frc
}
_sqlite3DbFree(tls, db, zSql)
if rc == SQLITE_OK {
_sqlite3AnalysisLoad(tls, db, iDb)
}
if (*Tsqlite3)(unsafe.Pointer(db)).FmallocFailed != 0 {
rc = int32(SQLITE_NOMEM)
_sqlite3ResetAllSchemasOfConnection(tls, db)
pDb = (*Tsqlite3)(unsafe.Pointer(db)).FaDb + uintptr(iDb)*32
} else {
if rc == SQLITE_OK || (*Tsqlite3)(unsafe.Pointer(db)).Fflags&uint64(SQLITE_NoSchemaError) != 0 && rc != int32(SQLITE_NOMEM) {
/* Hack: If the SQLITE_NoSchemaError flag is set, then consider
** the schema loaded, even if errors (other than OOM) occurred. In
** this situation the current sqlite3_prepare() operation will fail,
** but the following one will attempt to compile the supplied statement
** against whatever subset of the schema was loaded before the error
** occurred.
**
** The primary purpose of this is to allow access to the sqlite_schema
** table even when its contents have been corrupted.
*/
v1 = (**(**TDb)(__ccgo_up((*Tsqlite3)(unsafe.Pointer(db)).FaDb + uintptr(iDb)*32))).FpSchema + 114
*(*Tu16)(unsafe.Pointer(v1)) = Tu16(int32(*(*Tu16)(unsafe.Pointer(v1))) | libc.Int32FromInt32(DB_SchemaLoaded))
rc = SQLITE_OK
}
}
/* Jump here for an error that occurs after successfully allocating
** curMain and calling sqlite3BtreeEnter(). For an error that occurs
** before that point, jump to error_out.
*/
goto initone_error_out
initone_error_out:
;
if openedTransaction != 0 {
_sqlite3BtreeCommit(tls, (*TDb)(unsafe.Pointer(pDb)).FpBt)
}
_sqlite3BtreeLeave(tls, (*TDb)(unsafe.Pointer(pDb)).FpBt)
goto error_out
error_out:
;
if rc != 0 {
if rc == int32(SQLITE_NOMEM) || rc == libc.Int32FromInt32(SQLITE_IOERR)|libc.Int32FromInt32(12)< and its indices
// ** put VALUES clause expressions into registers
// ** write the resulting record into
// ** cleanup
// **
// ** The three remaining templates assume the statement is of the form
// **
// ** INSERT INTO SELECT ...
// **
// ** If the SELECT clause is of the restricted form "SELECT * FROM " -
// ** in other words if the SELECT pulls all columns from a single table
// ** and there is no WHERE or LIMIT or GROUP BY or ORDER BY clauses, and
// ** if and are distinct tables but have identical
// ** schemas, including all the same indices, then a special optimization
// ** is invoked that copies raw records from over to .
// ** See the xferOptimization() function for the implementation of this
// ** template. This is the 2nd template.
// **
// ** open a write cursor to
// ** open read cursor on
// ** transfer all records in over to
// ** close cursors
// ** foreach index on
// ** open a write cursor on the index
// ** open a read cursor on the corresponding index
// ** transfer all records from the read to the write cursors
// ** close cursors
// ** end foreach
// **
// ** The 3rd template is for when the second template does not apply
// ** and the SELECT clause does not read from at any time.
// ** The generated code follows this template:
// **
// ** X <- A
// ** goto B
// ** A: setup for the SELECT
// ** loop over the rows in the SELECT
// ** load values into registers R..R+n
// ** yield X
// ** end loop
// ** cleanup after the SELECT
// ** end-coroutine X
// ** B: open write cursor to and its indices
// ** C: yield X, at EOF goto D
// ** insert the select result into from R..R+n
// ** goto C
// ** D: cleanup
// **
// ** The 4th template is used if the insert statement takes its
// ** values from a SELECT but the data is being inserted into a table
// ** that is also read as part of the SELECT. In the third form,
// ** we have to use an intermediate table to store the results of
// ** the select. The template is like this:
// **
// ** X <- A
// ** goto B
// ** A: setup for the SELECT
// ** loop over the tables in the SELECT
// ** load value into register R..R+n
// ** yield X
// ** end loop
// ** cleanup after the SELECT
// ** end co-routine R
// ** B: open temp table
// ** L: yield X, at EOF goto M
// ** insert row from R..R+n into temp table
// ** goto L
// ** M: open write cursor to and its indices
// ** rewind temp table
// ** C: loop over rows of intermediate table
// ** transfer values form intermediate table into
// ** end loop
// ** D: cleanup
// */
func _sqlite3Insert(tls *libc.TLS, pParse uintptr, pTabList uintptr, pSelect uintptr, pColumn uintptr, onError int32, pUpsert uintptr) {
bp := tls.Alloc(160)
defer tls.Free(160)
var aRegIdx, aTabColMap, db, pIdx, pIpk, pItem, pList, pNx, pSubq, pTab, pTrigger, pVTab, pX, v, v5 uintptr
var addr1, addr11, addrCont, addrInsTop, addrL, addrTop, bUseSeek, endOfLoop, i, iDb, iRegStore, ipkColumn, isView, j, k, nColumn, nHidden, nIdx, rc, regAutoinc, regCols, regData, regFromSelect, regIns, regRec, regRowCount, regRowid, regTempRowid, regYield, srcTab, y, v1 int32
var appendFlag, bIdListInOrder, useTempTable, withoutRowid Tu8
var colFlags, v20 Tu32
var _ /* dest at bp+8 */ TSelectDest
var _ /* iDataCur at bp+0 */ int32
var _ /* iIdxCur at bp+4 */ int32
var _ /* isReplace at bp+112 */ int32
var _ /* sNC at bp+56 */ TNameContext
var _ /* tmask at bp+48 */ int32
_, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _ = aRegIdx, aTabColMap, addr1, addr11, addrCont, addrInsTop, addrL, addrTop, appendFlag, bIdListInOrder, bUseSeek, colFlags, db, endOfLoop, i, iDb, iRegStore, ipkColumn, isView, j, k, nColumn, nHidden, nIdx, pIdx, pIpk, pItem, pList, pNx, pSubq, pTab, pTrigger, pVTab, pX, rc, regAutoinc, regCols, regData, regFromSelect, regIns, regRec, regRowCount, regRowid, regTempRowid, regYield, srcTab, useTempTable, v, withoutRowid, y, v1, v20, v5 /* Number of columns in the data */
nHidden = 0 /* Number of hidden columns if TABLE is virtual */
**(**int32)(__ccgo_up(bp)) = 0 /* VDBE cursor that is the main data repository */
**(**int32)(__ccgo_up(bp + 4)) = 0 /* First index cursor */
ipkColumn = -int32(1) /* Label for the end of the insertion loop */
srcTab = 0 /* Data comes from this temporary cursor if >=0 */
addrInsTop = 0 /* Jump to label "D" */
addrCont = 0 /* Index of database holding TABLE */
useTempTable = uint8(0) /* Store SELECT results in intermediate table */
appendFlag = uint8(0) /* True if IDLIST is in table order */
pList = uintptr(0) /* Register in which to store next column */
/* Register allocations */
regFromSelect = 0 /* Base register for data coming from SELECT */
regAutoinc = 0 /* Register holding the AUTOINCREMENT counter */
regRowCount = 0 /* register holding first column to insert */
aRegIdx = uintptr(0) /* One register allocated to each index */
aTabColMap = uintptr(0) /* Mask of trigger times */
db = (*TParse)(unsafe.Pointer(pParse)).Fdb
if (*TParse)(unsafe.Pointer(pParse)).FnErr != 0 {
goto insert_cleanup
}
(**(**TSelectDest)(__ccgo_up(bp + 8))).FiSDParm = 0 /* Suppress a harmless compiler warning */
/* If the Select object is really just a simple VALUES() list with a
** single row (the common case) then keep that one row of values
** and discard the other (unused) parts of the pSelect object
*/
if pSelect != 0 && (*TSelect)(unsafe.Pointer(pSelect)).FselFlags&uint32(SF_Values) != uint32(0) && (*TSelect)(unsafe.Pointer(pSelect)).FpPrior == uintptr(0) {
pList = (*TSelect)(unsafe.Pointer(pSelect)).FpEList
(*TSelect)(unsafe.Pointer(pSelect)).FpEList = uintptr(0)
_sqlite3SelectDelete(tls, db, pSelect)
pSelect = uintptr(0)
}
/* Locate the table into which we will be inserting new information.
*/
pTab = _sqlite3SrcListLookup(tls, pParse, pTabList)
if pTab == uintptr(0) {
goto insert_cleanup
}
iDb = _sqlite3SchemaToIndex(tls, db, (*TTable)(unsafe.Pointer(pTab)).FpSchema)
if _sqlite3AuthCheck(tls, pParse, int32(SQLITE_INSERT), (*TTable)(unsafe.Pointer(pTab)).FzName, uintptr(0), (**(**TDb)(__ccgo_up((*Tsqlite3)(unsafe.Pointer(db)).FaDb + uintptr(iDb)*32))).FzDbSName) != 0 {
goto insert_cleanup
}
withoutRowid = libc.BoolUint8(!((*TTable)(unsafe.Pointer(pTab)).FtabFlags&libc.Uint32FromInt32(TF_WithoutRowid) == libc.Uint32FromInt32(0)))
/* Figure out if we have any triggers and if the table being
** inserted into is a view
*/
pTrigger = _sqlite3TriggersExist(tls, pParse, pTab, int32(TK_INSERT), uintptr(0), bp+48)
isView = libc.BoolInt32(libc.Int32FromUint8((*TTable)(unsafe.Pointer(pTab)).FeTabType) == int32(TABTYP_VIEW))
/* If pTab is really a view, make sure it has been initialized.
** ViewGetColumnNames() is a no-op if pTab is not a view.
*/
if _sqlite3ViewGetColumnNames(tls, pParse, pTab) != 0 {
goto insert_cleanup
}
/* Cannot insert into a read-only table.
*/
if _sqlite3IsReadOnly(tls, pParse, pTab, pTrigger) != 0 {
goto insert_cleanup
}
/* Allocate a VDBE
*/
v = _sqlite3GetVdbe(tls, pParse)
if v == uintptr(0) {
goto insert_cleanup
}
if libc.Int32FromUint8((*TParse)(unsafe.Pointer(pParse)).Fnested) == 0 {
_sqlite3VdbeCountChanges(tls, v)
}
_sqlite3BeginWriteOperation(tls, pParse, libc.BoolInt32(pSelect != 0 || pTrigger != 0), iDb)
/* If the statement is of the form
**
** INSERT INTO