#ifndef EDUWIN_H
#define EDUWIN_H

/*
 * eduwin -- simple Windows GUI framework
 * auto-generated by pub.py
 * DO NOT EDIT THIS FILE DIRECTLY.
 */

#ifndef EDUWIN_COMMON_H
#define EDUWIN_COMMON_H

#define WIN32_LEAN_AND_MEAN
#include <windows.h>
#include <commctrl.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <stdarg.h>
#include <math.h>
#include <time.h>

/* ── Public types used by canvas/sprite API ── */
typedef struct { float X, Y; } PointF;
typedef struct { float X, Y, Width, Height; } RectF;

#endif

#ifndef SQLITE3_H
#define SQLITE3_H
#include <stdarg.h>     

#ifdef __cplusplus
extern "C" {
#endif

#ifndef SQLITE_EXTERN
# define SQLITE_EXTERN extern
#endif
#ifndef SQLITE_API
# define SQLITE_API
#endif
#ifndef SQLITE_CDECL
# define SQLITE_CDECL
#endif
#ifndef SQLITE_APICALL
# define SQLITE_APICALL
#endif
#ifndef SQLITE_STDCALL
# define SQLITE_STDCALL SQLITE_APICALL
#endif
#ifndef SQLITE_CALLBACK
# define SQLITE_CALLBACK
#endif
#ifndef SQLITE_SYSAPI
# define SQLITE_SYSAPI
#endif

#define SQLITE_DEPRECATED
#define SQLITE_EXPERIMENTAL

#ifdef SQLITE_VERSION
# undef SQLITE_VERSION
#endif
#ifdef SQLITE_VERSION_NUMBER
# undef SQLITE_VERSION_NUMBER
#endif

#define SQLITE_VERSION        "3.53.1"
#define SQLITE_VERSION_NUMBER 3053001
#define SQLITE_SOURCE_ID      "2026-05-05 10:34:17 c88b22011a54b4f6fbd149e9f8e4de77658ce58143a1af0e3785e4e6475127e9"
#define SQLITE_SCM_BRANCH     "branch-3.53"
#define SQLITE_SCM_TAGS       "release version-3.53.1"
#define SQLITE_SCM_DATETIME   "2026-05-05T10:34:17.344Z"

SQLITE_API SQLITE_EXTERN const char sqlite3_version[];
SQLITE_API const char *sqlite3_libversion(void);
SQLITE_API const char *sqlite3_sourceid(void);
SQLITE_API int sqlite3_libversion_number(void);

#ifndef SQLITE_OMIT_COMPILEOPTION_DIAGS
SQLITE_API int sqlite3_compileoption_used(const char *zOptName);
SQLITE_API const char *sqlite3_compileoption_get(int N);
#else
# define sqlite3_compileoption_used(X) 0
# define sqlite3_compileoption_get(X)  ((void*)0)
#endif

SQLITE_API int sqlite3_threadsafe(void);

typedef struct sqlite3 sqlite3;

#ifdef SQLITE_INT64_TYPE
  typedef SQLITE_INT64_TYPE sqlite_int64;
# ifdef SQLITE_UINT64_TYPE
    typedef SQLITE_UINT64_TYPE sqlite_uint64;
# else
    typedef unsigned SQLITE_INT64_TYPE sqlite_uint64;
# endif
#elif defined(_MSC_VER) || defined(__BORLANDC__)
  typedef __int64 sqlite_int64;
  typedef unsigned __int64 sqlite_uint64;
#else
  typedef long long int sqlite_int64;
  typedef unsigned long long int sqlite_uint64;
#endif
typedef sqlite_int64 sqlite3_int64;
typedef sqlite_uint64 sqlite3_uint64;

#ifdef SQLITE_OMIT_FLOATING_POINT
# define double sqlite3_int64
#endif

SQLITE_API int sqlite3_close(sqlite3*);
SQLITE_API int sqlite3_close_v2(sqlite3*);

typedef int (*sqlite3_callback)(void*,int,char**, char**);

SQLITE_API int sqlite3_exec(
  sqlite3*,                                  
  const char *sql,                           
  int (*callback)(void*,int,char**,char**),  
  void *,                                    
  char **errmsg                              
);

#define SQLITE_OK           0   

#define SQLITE_ERROR        1   
#define SQLITE_INTERNAL     2   
#define SQLITE_PERM         3   
#define SQLITE_ABORT        4   
#define SQLITE_BUSY         5   
#define SQLITE_LOCKED       6   
#define SQLITE_NOMEM        7   
#define SQLITE_READONLY     8   
#define SQLITE_INTERRUPT    9   
#define SQLITE_IOERR       10   
#define SQLITE_CORRUPT     11   
#define SQLITE_NOTFOUND    12   
#define SQLITE_FULL        13   
#define SQLITE_CANTOPEN    14   
#define SQLITE_PROTOCOL    15   
#define SQLITE_EMPTY       16   
#define SQLITE_SCHEMA      17   
#define SQLITE_TOOBIG      18   
#define SQLITE_CONSTRAINT  19   
#define SQLITE_MISMATCH    20   
#define SQLITE_MISUSE      21   
#define SQLITE_NOLFS       22   
#define SQLITE_AUTH        23   
#define SQLITE_FORMAT      24   
#define SQLITE_RANGE       25   
#define SQLITE_NOTADB      26   
#define SQLITE_NOTICE      27   
#define SQLITE_WARNING     28   
#define SQLITE_ROW         100  
#define SQLITE_DONE        101  

#define SQLITE_ERROR_MISSING_COLLSEQ   (SQLITE_ERROR | (1<<8))
#define SQLITE_ERROR_RETRY             (SQLITE_ERROR | (2<<8))
#define SQLITE_ERROR_SNAPSHOT          (SQLITE_ERROR | (3<<8))
#define SQLITE_ERROR_RESERVESIZE       (SQLITE_ERROR | (4<<8))
#define SQLITE_ERROR_KEY               (SQLITE_ERROR | (5<<8))
#define SQLITE_ERROR_UNABLE            (SQLITE_ERROR | (6<<8))
#define SQLITE_IOERR_READ              (SQLITE_IOERR | (1<<8))
#define SQLITE_IOERR_SHORT_READ        (SQLITE_IOERR | (2<<8))
#define SQLITE_IOERR_WRITE             (SQLITE_IOERR | (3<<8))
#define SQLITE_IOERR_FSYNC             (SQLITE_IOERR | (4<<8))
#define SQLITE_IOERR_DIR_FSYNC         (SQLITE_IOERR | (5<<8))
#define SQLITE_IOERR_TRUNCATE          (SQLITE_IOERR | (6<<8))
#define SQLITE_IOERR_FSTAT             (SQLITE_IOERR | (7<<8))
#define SQLITE_IOERR_UNLOCK            (SQLITE_IOERR | (8<<8))
#define SQLITE_IOERR_RDLOCK            (SQLITE_IOERR | (9<<8))
#define SQLITE_IOERR_DELETE            (SQLITE_IOERR | (10<<8))
#define SQLITE_IOERR_BLOCKED           (SQLITE_IOERR | (11<<8))
#define SQLITE_IOERR_NOMEM             (SQLITE_IOERR | (12<<8))
#define SQLITE_IOERR_ACCESS            (SQLITE_IOERR | (13<<8))
#define SQLITE_IOERR_CHECKRESERVEDLOCK (SQLITE_IOERR | (14<<8))
#define SQLITE_IOERR_LOCK              (SQLITE_IOERR | (15<<8))
#define SQLITE_IOERR_CLOSE             (SQLITE_IOERR | (16<<8))
#define SQLITE_IOERR_DIR_CLOSE         (SQLITE_IOERR | (17<<8))
#define SQLITE_IOERR_SHMOPEN           (SQLITE_IOERR | (18<<8))
#define SQLITE_IOERR_SHMSIZE           (SQLITE_IOERR | (19<<8))
#define SQLITE_IOERR_SHMLOCK           (SQLITE_IOERR | (20<<8))
#define SQLITE_IOERR_SHMMAP            (SQLITE_IOERR | (21<<8))
#define SQLITE_IOERR_SEEK              (SQLITE_IOERR | (22<<8))
#define SQLITE_IOERR_DELETE_NOENT      (SQLITE_IOERR | (23<<8))
#define SQLITE_IOERR_MMAP              (SQLITE_IOERR | (24<<8))
#define SQLITE_IOERR_GETTEMPPATH       (SQLITE_IOERR | (25<<8))
#define SQLITE_IOERR_CONVPATH          (SQLITE_IOERR | (26<<8))
#define SQLITE_IOERR_VNODE             (SQLITE_IOERR | (27<<8))
#define SQLITE_IOERR_AUTH              (SQLITE_IOERR | (28<<8))
#define SQLITE_IOERR_BEGIN_ATOMIC      (SQLITE_IOERR | (29<<8))
#define SQLITE_IOERR_COMMIT_ATOMIC     (SQLITE_IOERR | (30<<8))
#define SQLITE_IOERR_ROLLBACK_ATOMIC   (SQLITE_IOERR | (31<<8))
#define SQLITE_IOERR_DATA              (SQLITE_IOERR | (32<<8))
#define SQLITE_IOERR_CORRUPTFS         (SQLITE_IOERR | (33<<8))
#define SQLITE_IOERR_IN_PAGE           (SQLITE_IOERR | (34<<8))
#define SQLITE_IOERR_BADKEY            (SQLITE_IOERR | (35<<8))
#define SQLITE_IOERR_CODEC             (SQLITE_IOERR | (36<<8))
#define SQLITE_LOCKED_SHAREDCACHE      (SQLITE_LOCKED |  (1<<8))
#define SQLITE_LOCKED_VTAB             (SQLITE_LOCKED |  (2<<8))
#define SQLITE_BUSY_RECOVERY           (SQLITE_BUSY   |  (1<<8))
#define SQLITE_BUSY_SNAPSHOT           (SQLITE_BUSY   |  (2<<8))
#define SQLITE_BUSY_TIMEOUT            (SQLITE_BUSY   |  (3<<8))
#define SQLITE_CANTOPEN_NOTEMPDIR      (SQLITE_CANTOPEN | (1<<8))
#define SQLITE_CANTOPEN_ISDIR          (SQLITE_CANTOPEN | (2<<8))
#define SQLITE_CANTOPEN_FULLPATH       (SQLITE_CANTOPEN | (3<<8))
#define SQLITE_CANTOPEN_CONVPATH       (SQLITE_CANTOPEN | (4<<8))
#define SQLITE_CANTOPEN_DIRTYWAL       (SQLITE_CANTOPEN | (5<<8)) 
#define SQLITE_CANTOPEN_SYMLINK        (SQLITE_CANTOPEN | (6<<8))
#define SQLITE_CORRUPT_VTAB            (SQLITE_CORRUPT | (1<<8))
#define SQLITE_CORRUPT_SEQUENCE        (SQLITE_CORRUPT | (2<<8))
#define SQLITE_CORRUPT_INDEX           (SQLITE_CORRUPT | (3<<8))
#define SQLITE_READONLY_RECOVERY       (SQLITE_READONLY | (1<<8))
#define SQLITE_READONLY_CANTLOCK       (SQLITE_READONLY | (2<<8))
#define SQLITE_READONLY_ROLLBACK       (SQLITE_READONLY | (3<<8))
#define SQLITE_READONLY_DBMOVED        (SQLITE_READONLY | (4<<8))
#define SQLITE_READONLY_CANTINIT       (SQLITE_READONLY | (5<<8))
#define SQLITE_READONLY_DIRECTORY      (SQLITE_READONLY | (6<<8))
#define SQLITE_ABORT_ROLLBACK          (SQLITE_ABORT | (2<<8))
#define SQLITE_CONSTRAINT_CHECK        (SQLITE_CONSTRAINT | (1<<8))
#define SQLITE_CONSTRAINT_COMMITHOOK   (SQLITE_CONSTRAINT | (2<<8))
#define SQLITE_CONSTRAINT_FOREIGNKEY   (SQLITE_CONSTRAINT | (3<<8))
#define SQLITE_CONSTRAINT_FUNCTION     (SQLITE_CONSTRAINT | (4<<8))
#define SQLITE_CONSTRAINT_NOTNULL      (SQLITE_CONSTRAINT | (5<<8))
#define SQLITE_CONSTRAINT_PRIMARYKEY   (SQLITE_CONSTRAINT | (6<<8))
#define SQLITE_CONSTRAINT_TRIGGER      (SQLITE_CONSTRAINT | (7<<8))
#define SQLITE_CONSTRAINT_UNIQUE       (SQLITE_CONSTRAINT | (8<<8))
#define SQLITE_CONSTRAINT_VTAB         (SQLITE_CONSTRAINT | (9<<8))
#define SQLITE_CONSTRAINT_ROWID        (SQLITE_CONSTRAINT |(10<<8))
#define SQLITE_CONSTRAINT_PINNED       (SQLITE_CONSTRAINT |(11<<8))
#define SQLITE_CONSTRAINT_DATATYPE     (SQLITE_CONSTRAINT |(12<<8))
#define SQLITE_NOTICE_RECOVER_WAL      (SQLITE_NOTICE | (1<<8))
#define SQLITE_NOTICE_RECOVER_ROLLBACK (SQLITE_NOTICE | (2<<8))
#define SQLITE_NOTICE_RBU              (SQLITE_NOTICE | (3<<8))
#define SQLITE_WARNING_AUTOINDEX       (SQLITE_WARNING | (1<<8))
#define SQLITE_AUTH_USER               (SQLITE_AUTH | (1<<8))
#define SQLITE_OK_LOAD_PERMANENTLY     (SQLITE_OK | (1<<8))
#define SQLITE_OK_SYMLINK              (SQLITE_OK | (2<<8)) 

#define SQLITE_OPEN_READONLY         0x00000001  
#define SQLITE_OPEN_READWRITE        0x00000002  
#define SQLITE_OPEN_CREATE           0x00000004  
#define SQLITE_OPEN_DELETEONCLOSE    0x00000008  
#define SQLITE_OPEN_EXCLUSIVE        0x00000010  
#define SQLITE_OPEN_AUTOPROXY        0x00000020  
#define SQLITE_OPEN_URI              0x00000040  
#define SQLITE_OPEN_MEMORY           0x00000080  
#define SQLITE_OPEN_MAIN_DB          0x00000100  
#define SQLITE_OPEN_TEMP_DB          0x00000200  
#define SQLITE_OPEN_TRANSIENT_DB     0x00000400  
#define SQLITE_OPEN_MAIN_JOURNAL     0x00000800  
#define SQLITE_OPEN_TEMP_JOURNAL     0x00001000  
#define SQLITE_OPEN_SUBJOURNAL       0x00002000  
#define SQLITE_OPEN_SUPER_JOURNAL    0x00004000  
#define SQLITE_OPEN_NOMUTEX          0x00008000  
#define SQLITE_OPEN_FULLMUTEX        0x00010000  
#define SQLITE_OPEN_SHAREDCACHE      0x00020000  
#define SQLITE_OPEN_PRIVATECACHE     0x00040000  
#define SQLITE_OPEN_WAL              0x00080000  
#define SQLITE_OPEN_NOFOLLOW         0x01000000  
#define SQLITE_OPEN_EXRESCODE        0x02000000  

#define SQLITE_OPEN_MASTER_JOURNAL   0x00004000  

#define SQLITE_IOCAP_ATOMIC                 0x00000001
#define SQLITE_IOCAP_ATOMIC512              0x00000002
#define SQLITE_IOCAP_ATOMIC1K               0x00000004
#define SQLITE_IOCAP_ATOMIC2K               0x00000008
#define SQLITE_IOCAP_ATOMIC4K               0x00000010
#define SQLITE_IOCAP_ATOMIC8K               0x00000020
#define SQLITE_IOCAP_ATOMIC16K              0x00000040
#define SQLITE_IOCAP_ATOMIC32K              0x00000080
#define SQLITE_IOCAP_ATOMIC64K              0x00000100
#define SQLITE_IOCAP_SAFE_APPEND            0x00000200
#define SQLITE_IOCAP_SEQUENTIAL             0x00000400
#define SQLITE_IOCAP_UNDELETABLE_WHEN_OPEN  0x00000800
#define SQLITE_IOCAP_POWERSAFE_OVERWRITE    0x00001000
#define SQLITE_IOCAP_IMMUTABLE              0x00002000
#define SQLITE_IOCAP_BATCH_ATOMIC           0x00004000
#define SQLITE_IOCAP_SUBPAGE_READ           0x00008000

#define SQLITE_LOCK_NONE          0       
#define SQLITE_LOCK_SHARED        1       
#define SQLITE_LOCK_RESERVED      2       
#define SQLITE_LOCK_PENDING       3       
#define SQLITE_LOCK_EXCLUSIVE     4       

#define SQLITE_SYNC_NORMAL        0x00002
#define SQLITE_SYNC_FULL          0x00003
#define SQLITE_SYNC_DATAONLY      0x00010

typedef struct sqlite3_file sqlite3_file;
struct sqlite3_file {
  const struct sqlite3_io_methods *pMethods;  
};

typedef struct sqlite3_io_methods sqlite3_io_methods;
struct sqlite3_io_methods {
  int iVersion;
  int (*xClose)(sqlite3_file*);
  int (*xRead)(sqlite3_file*, void*, int iAmt, sqlite3_int64 iOfst);
  int (*xWrite)(sqlite3_file*, const void*, int iAmt, sqlite3_int64 iOfst);
  int (*xTruncate)(sqlite3_file*, sqlite3_int64 size);
  int (*xSync)(sqlite3_file*, int flags);
  int (*xFileSize)(sqlite3_file*, sqlite3_int64 *pSize);
  int (*xLock)(sqlite3_file*, int);
  int (*xUnlock)(sqlite3_file*, int);
  int (*xCheckReservedLock)(sqlite3_file*, int *pResOut);
  int (*xFileControl)(sqlite3_file*, int op, void *pArg);
  int (*xSectorSize)(sqlite3_file*);
  int (*xDeviceCharacteristics)(sqlite3_file*);
  
  int (*xShmMap)(sqlite3_file*, int iPg, int pgsz, int, void volatile**);
  int (*xShmLock)(sqlite3_file*, int offset, int n, int flags);
  void (*xShmBarrier)(sqlite3_file*);
  int (*xShmUnmap)(sqlite3_file*, int deleteFlag);
  
  int (*xFetch)(sqlite3_file*, sqlite3_int64 iOfst, int iAmt, void **pp);
  int (*xUnfetch)(sqlite3_file*, sqlite3_int64 iOfst, void *p);
  
  
};

#define SQLITE_FCNTL_LOCKSTATE               1
#define SQLITE_FCNTL_GET_LOCKPROXYFILE       2
#define SQLITE_FCNTL_SET_LOCKPROXYFILE       3
#define SQLITE_FCNTL_LAST_ERRNO              4
#define SQLITE_FCNTL_SIZE_HINT               5
#define SQLITE_FCNTL_CHUNK_SIZE              6
#define SQLITE_FCNTL_FILE_POINTER            7
#define SQLITE_FCNTL_SYNC_OMITTED            8
#define SQLITE_FCNTL_WIN32_AV_RETRY          9
#define SQLITE_FCNTL_PERSIST_WAL            10
#define SQLITE_FCNTL_OVERWRITE              11
#define SQLITE_FCNTL_VFSNAME                12
#define SQLITE_FCNTL_POWERSAFE_OVERWRITE    13
#define SQLITE_FCNTL_PRAGMA                 14
#define SQLITE_FCNTL_BUSYHANDLER            15
#define SQLITE_FCNTL_TEMPFILENAME           16
#define SQLITE_FCNTL_MMAP_SIZE              18
#define SQLITE_FCNTL_TRACE                  19
#define SQLITE_FCNTL_HAS_MOVED              20
#define SQLITE_FCNTL_SYNC                   21
#define SQLITE_FCNTL_COMMIT_PHASETWO        22
#define SQLITE_FCNTL_WIN32_SET_HANDLE       23
#define SQLITE_FCNTL_WAL_BLOCK              24
#define SQLITE_FCNTL_ZIPVFS                 25
#define SQLITE_FCNTL_RBU                    26
#define SQLITE_FCNTL_VFS_POINTER            27
#define SQLITE_FCNTL_JOURNAL_POINTER        28
#define SQLITE_FCNTL_WIN32_GET_HANDLE       29
#define SQLITE_FCNTL_PDB                    30
#define SQLITE_FCNTL_BEGIN_ATOMIC_WRITE     31
#define SQLITE_FCNTL_COMMIT_ATOMIC_WRITE    32
#define SQLITE_FCNTL_ROLLBACK_ATOMIC_WRITE  33
#define SQLITE_FCNTL_LOCK_TIMEOUT           34
#define SQLITE_FCNTL_DATA_VERSION           35
#define SQLITE_FCNTL_SIZE_LIMIT             36
#define SQLITE_FCNTL_CKPT_DONE              37
#define SQLITE_FCNTL_RESERVE_BYTES          38
#define SQLITE_FCNTL_CKPT_START             39
#define SQLITE_FCNTL_EXTERNAL_READER        40
#define SQLITE_FCNTL_CKSM_FILE              41
#define SQLITE_FCNTL_RESET_CACHE            42
#define SQLITE_FCNTL_NULL_IO                43
#define SQLITE_FCNTL_BLOCK_ON_CONNECT       44
#define SQLITE_FCNTL_FILESTAT               45

#define SQLITE_GET_LOCKPROXYFILE      SQLITE_FCNTL_GET_LOCKPROXYFILE
#define SQLITE_SET_LOCKPROXYFILE      SQLITE_FCNTL_SET_LOCKPROXYFILE
#define SQLITE_LAST_ERRNO             SQLITE_FCNTL_LAST_ERRNO

typedef struct sqlite3_mutex sqlite3_mutex;

typedef struct sqlite3_api_routines sqlite3_api_routines;

typedef const char *sqlite3_filename;

typedef struct sqlite3_vfs sqlite3_vfs;
typedef void (*sqlite3_syscall_ptr)(void);
struct sqlite3_vfs {
  int iVersion;            
  int szOsFile;            
  int mxPathname;          
  sqlite3_vfs *pNext;      
  const char *zName;       
  void *pAppData;          
  int (*xOpen)(sqlite3_vfs*, sqlite3_filename zName, sqlite3_file*,
               int flags, int *pOutFlags);
  int (*xDelete)(sqlite3_vfs*, const char *zName, int syncDir);
  int (*xAccess)(sqlite3_vfs*, const char *zName, int flags, int *pResOut);
  int (*xFullPathname)(sqlite3_vfs*, const char *zName, int nOut, char *zOut);
  void *(*xDlOpen)(sqlite3_vfs*, const char *zFilename);
  void (*xDlError)(sqlite3_vfs*, int nByte, char *zErrMsg);
  void (*(*xDlSym)(sqlite3_vfs*,void*, const char *zSymbol))(void);
  void (*xDlClose)(sqlite3_vfs*, void*);
  int (*xRandomness)(sqlite3_vfs*, int nByte, char *zOut);
  int (*xSleep)(sqlite3_vfs*, int microseconds);
  int (*xCurrentTime)(sqlite3_vfs*, double*);
  int (*xGetLastError)(sqlite3_vfs*, int, char *);
  
  int (*xCurrentTimeInt64)(sqlite3_vfs*, sqlite3_int64*);
  
  int (*xSetSystemCall)(sqlite3_vfs*, const char *zName, sqlite3_syscall_ptr);
  sqlite3_syscall_ptr (*xGetSystemCall)(sqlite3_vfs*, const char *zName);
  const char *(*xNextSystemCall)(sqlite3_vfs*, const char *zName);
  
};

#define SQLITE_ACCESS_EXISTS    0
#define SQLITE_ACCESS_READWRITE 1   
#define SQLITE_ACCESS_READ      2   

#define SQLITE_SHM_UNLOCK       1
#define SQLITE_SHM_LOCK         2
#define SQLITE_SHM_SHARED       4
#define SQLITE_SHM_EXCLUSIVE    8

#define SQLITE_SHM_NLOCK        8

SQLITE_API int sqlite3_initialize(void);
SQLITE_API int sqlite3_shutdown(void);
SQLITE_API int sqlite3_os_init(void);
SQLITE_API int sqlite3_os_end(void);

SQLITE_API int sqlite3_config(int, ...);

SQLITE_API int sqlite3_db_config(sqlite3*, int op, ...);

typedef struct sqlite3_mem_methods sqlite3_mem_methods;
struct sqlite3_mem_methods {
  void *(*xMalloc)(int);         
  void (*xFree)(void*);          
  void *(*xRealloc)(void*,int);  
  int (*xSize)(void*);           
  int (*xRoundup)(int);          
  int (*xInit)(void*);           
  void (*xShutdown)(void*);      
  void *pAppData;                
};

#define SQLITE_CONFIG_SINGLETHREAD         1  
#define SQLITE_CONFIG_MULTITHREAD          2  
#define SQLITE_CONFIG_SERIALIZED           3  
#define SQLITE_CONFIG_MALLOC               4  
#define SQLITE_CONFIG_GETMALLOC            5  
#define SQLITE_CONFIG_SCRATCH              6  
#define SQLITE_CONFIG_PAGECACHE            7  
#define SQLITE_CONFIG_HEAP                 8  
#define SQLITE_CONFIG_MEMSTATUS            9  
#define SQLITE_CONFIG_MUTEX               10  
#define SQLITE_CONFIG_GETMUTEX            11  

#define SQLITE_CONFIG_LOOKASIDE           13  
#define SQLITE_CONFIG_PCACHE              14  
#define SQLITE_CONFIG_GETPCACHE           15  
#define SQLITE_CONFIG_LOG                 16  
#define SQLITE_CONFIG_URI                 17  
#define SQLITE_CONFIG_PCACHE2             18  
#define SQLITE_CONFIG_GETPCACHE2          19  
#define SQLITE_CONFIG_COVERING_INDEX_SCAN 20  
#define SQLITE_CONFIG_SQLLOG              21  
#define SQLITE_CONFIG_MMAP_SIZE           22  
#define SQLITE_CONFIG_WIN32_HEAPSIZE      23  
#define SQLITE_CONFIG_PCACHE_HDRSZ        24  
#define SQLITE_CONFIG_PMASZ               25  
#define SQLITE_CONFIG_STMTJRNL_SPILL      26  
#define SQLITE_CONFIG_SMALL_MALLOC        27  
#define SQLITE_CONFIG_SORTERREF_SIZE      28  
#define SQLITE_CONFIG_MEMDB_MAXSIZE       29  
#define SQLITE_CONFIG_ROWID_IN_VIEW       30  

#define SQLITE_DBCONFIG_MAINDBNAME            1000 
#define SQLITE_DBCONFIG_LOOKASIDE             1001 
#define SQLITE_DBCONFIG_ENABLE_FKEY           1002 
#define SQLITE_DBCONFIG_ENABLE_TRIGGER        1003 
#define SQLITE_DBCONFIG_ENABLE_FTS3_TOKENIZER 1004 
#define SQLITE_DBCONFIG_ENABLE_LOAD_EXTENSION 1005 
#define SQLITE_DBCONFIG_NO_CKPT_ON_CLOSE      1006 
#define SQLITE_DBCONFIG_ENABLE_QPSG           1007 
#define SQLITE_DBCONFIG_TRIGGER_EQP           1008 
#define SQLITE_DBCONFIG_RESET_DATABASE        1009 
#define SQLITE_DBCONFIG_DEFENSIVE             1010 
#define SQLITE_DBCONFIG_WRITABLE_SCHEMA       1011 
#define SQLITE_DBCONFIG_LEGACY_ALTER_TABLE    1012 
#define SQLITE_DBCONFIG_DQS_DML               1013 
#define SQLITE_DBCONFIG_DQS_DDL               1014 
#define SQLITE_DBCONFIG_ENABLE_VIEW           1015 
#define SQLITE_DBCONFIG_LEGACY_FILE_FORMAT    1016 
#define SQLITE_DBCONFIG_TRUSTED_SCHEMA        1017 
#define SQLITE_DBCONFIG_STMT_SCANSTATUS       1018 
#define SQLITE_DBCONFIG_REVERSE_SCANORDER     1019 
#define SQLITE_DBCONFIG_ENABLE_ATTACH_CREATE  1020 
#define SQLITE_DBCONFIG_ENABLE_ATTACH_WRITE   1021 
#define SQLITE_DBCONFIG_ENABLE_COMMENTS       1022 
#define SQLITE_DBCONFIG_FP_DIGITS             1023 
#define SQLITE_DBCONFIG_MAX                   1023 

SQLITE_API int sqlite3_extended_result_codes(sqlite3*, int onoff);

SQLITE_API sqlite3_int64 sqlite3_last_insert_rowid(sqlite3*);

SQLITE_API void sqlite3_set_last_insert_rowid(sqlite3*,sqlite3_int64);

SQLITE_API int sqlite3_changes(sqlite3*);
SQLITE_API sqlite3_int64 sqlite3_changes64(sqlite3*);

SQLITE_API int sqlite3_total_changes(sqlite3*);
SQLITE_API sqlite3_int64 sqlite3_total_changes64(sqlite3*);

SQLITE_API void sqlite3_interrupt(sqlite3*);
SQLITE_API int sqlite3_is_interrupted(sqlite3*);

SQLITE_API int sqlite3_complete(const char *sql);
SQLITE_API int sqlite3_complete16(const void *sql);

SQLITE_API int sqlite3_busy_handler(sqlite3*,int(*)(void*,int),void*);

SQLITE_API int sqlite3_busy_timeout(sqlite3*, int ms);

SQLITE_API int sqlite3_setlk_timeout(sqlite3*, int ms, int flags);

#define SQLITE_SETLK_BLOCK_ON_CONNECT 0x01

SQLITE_API int sqlite3_get_table(
  sqlite3 *db,          
  const char *zSql,     
  char ***pazResult,    
  int *pnRow,           
  int *pnColumn,        
  char **pzErrmsg       
);
SQLITE_API void sqlite3_free_table(char **result);

SQLITE_API char *sqlite3_mprintf(const char*,...);
SQLITE_API char *sqlite3_vmprintf(const char*, va_list);
SQLITE_API char *sqlite3_snprintf(int,char*,const char*, ...);
SQLITE_API char *sqlite3_vsnprintf(int,char*,const char*, va_list);

SQLITE_API void *sqlite3_malloc(int);
SQLITE_API void *sqlite3_malloc64(sqlite3_uint64);
SQLITE_API void *sqlite3_realloc(void*, int);
SQLITE_API void *sqlite3_realloc64(void*, sqlite3_uint64);
SQLITE_API void sqlite3_free(void*);
SQLITE_API sqlite3_uint64 sqlite3_msize(void*);

SQLITE_API sqlite3_int64 sqlite3_memory_used(void);
SQLITE_API sqlite3_int64 sqlite3_memory_highwater(int resetFlag);

SQLITE_API void sqlite3_randomness(int N, void *P);

SQLITE_API int sqlite3_set_authorizer(
  sqlite3*,
  int (*xAuth)(void*,int,const char*,const char*,const char*,const char*),
  void *pUserData
);

#define SQLITE_DENY   1   
#define SQLITE_IGNORE 2   

#define SQLITE_CREATE_INDEX          1   
#define SQLITE_CREATE_TABLE          2   
#define SQLITE_CREATE_TEMP_INDEX     3   
#define SQLITE_CREATE_TEMP_TABLE     4   
#define SQLITE_CREATE_TEMP_TRIGGER   5   
#define SQLITE_CREATE_TEMP_VIEW      6   
#define SQLITE_CREATE_TRIGGER        7   
#define SQLITE_CREATE_VIEW           8   
#define SQLITE_DELETE                9   
#define SQLITE_DROP_INDEX           10   
#define SQLITE_DROP_TABLE           11   
#define SQLITE_DROP_TEMP_INDEX      12   
#define SQLITE_DROP_TEMP_TABLE      13   
#define SQLITE_DROP_TEMP_TRIGGER    14   
#define SQLITE_DROP_TEMP_VIEW       15   
#define SQLITE_DROP_TRIGGER         16   
#define SQLITE_DROP_VIEW            17   
#define SQLITE_INSERT               18   
#define SQLITE_PRAGMA               19   
#define SQLITE_READ                 20   
#define SQLITE_SELECT               21   
#define SQLITE_TRANSACTION          22   
#define SQLITE_UPDATE               23   
#define SQLITE_ATTACH               24   
#define SQLITE_DETACH               25   
#define SQLITE_ALTER_TABLE          26   
#define SQLITE_REINDEX              27   
#define SQLITE_ANALYZE              28   
#define SQLITE_CREATE_VTABLE        29   
#define SQLITE_DROP_VTABLE          30   
#define SQLITE_FUNCTION             31   
#define SQLITE_SAVEPOINT            32   
#define SQLITE_COPY                  0   
#define SQLITE_RECURSIVE            33   

SQLITE_API SQLITE_DEPRECATED void *sqlite3_trace(sqlite3*,
   void(*xTrace)(void*,const char*), void*);
SQLITE_API SQLITE_DEPRECATED void *sqlite3_profile(sqlite3*,
   void(*xProfile)(void*,const char*,sqlite3_uint64), void*);

#define SQLITE_TRACE_STMT       0x01
#define SQLITE_TRACE_PROFILE    0x02
#define SQLITE_TRACE_ROW        0x04
#define SQLITE_TRACE_CLOSE      0x08

SQLITE_API int sqlite3_trace_v2(
  sqlite3*,
  unsigned uMask,
  int(*xCallback)(unsigned,void*,void*,void*),
  void *pCtx
);

SQLITE_API void sqlite3_progress_handler(sqlite3*, int, int(*)(void*), void*);

SQLITE_API int sqlite3_open(
  const char *filename,   
  sqlite3 **ppDb          
);
SQLITE_API int sqlite3_open16(
  const void *filename,   
  sqlite3 **ppDb          
);
SQLITE_API int sqlite3_open_v2(
  const char *filename,   
  sqlite3 **ppDb,         
  int flags,              
  const char *zVfs        
);

SQLITE_API const char *sqlite3_uri_parameter(sqlite3_filename z, const char *zParam);
SQLITE_API int sqlite3_uri_boolean(sqlite3_filename z, const char *zParam, int bDefault);
SQLITE_API sqlite3_int64 sqlite3_uri_int64(sqlite3_filename, const char*, sqlite3_int64);
SQLITE_API const char *sqlite3_uri_key(sqlite3_filename z, int N);

SQLITE_API const char *sqlite3_filename_database(sqlite3_filename);
SQLITE_API const char *sqlite3_filename_journal(sqlite3_filename);
SQLITE_API const char *sqlite3_filename_wal(sqlite3_filename);

SQLITE_API sqlite3_file *sqlite3_database_file_object(const char*);

SQLITE_API sqlite3_filename sqlite3_create_filename(
  const char *zDatabase,
  const char *zJournal,
  const char *zWal,
  int nParam,
  const char **azParam
);
SQLITE_API void sqlite3_free_filename(sqlite3_filename);

SQLITE_API int sqlite3_errcode(sqlite3 *db);
SQLITE_API int sqlite3_extended_errcode(sqlite3 *db);
SQLITE_API const char *sqlite3_errmsg(sqlite3*);
SQLITE_API const void *sqlite3_errmsg16(sqlite3*);
SQLITE_API const char *sqlite3_errstr(int);
SQLITE_API int sqlite3_error_offset(sqlite3 *db);

SQLITE_API int sqlite3_set_errmsg(sqlite3 *db, int errcode, const char *zErrMsg);

typedef struct sqlite3_stmt sqlite3_stmt;

SQLITE_API int sqlite3_limit(sqlite3*, int id, int newVal);

#define SQLITE_LIMIT_LENGTH                    0
#define SQLITE_LIMIT_SQL_LENGTH                1
#define SQLITE_LIMIT_COLUMN                    2
#define SQLITE_LIMIT_EXPR_DEPTH                3
#define SQLITE_LIMIT_COMPOUND_SELECT           4
#define SQLITE_LIMIT_VDBE_OP                   5
#define SQLITE_LIMIT_FUNCTION_ARG              6
#define SQLITE_LIMIT_ATTACHED                  7
#define SQLITE_LIMIT_LIKE_PATTERN_LENGTH       8
#define SQLITE_LIMIT_VARIABLE_NUMBER           9
#define SQLITE_LIMIT_TRIGGER_DEPTH            10
#define SQLITE_LIMIT_WORKER_THREADS           11
#define SQLITE_LIMIT_PARSER_DEPTH             12

#define SQLITE_PREPARE_PERSISTENT              0x01
#define SQLITE_PREPARE_NORMALIZE               0x02
#define SQLITE_PREPARE_NO_VTAB                 0x04
#define SQLITE_PREPARE_DONT_LOG                0x10
#define SQLITE_PREPARE_FROM_DDL                0x20

SQLITE_API int sqlite3_prepare(
  sqlite3 *db,            
  const char *zSql,       
  int nByte,              
  sqlite3_stmt **ppStmt,  
  const char **pzTail     
);
SQLITE_API int sqlite3_prepare_v2(
  sqlite3 *db,            
  const char *zSql,       
  int nByte,              
  sqlite3_stmt **ppStmt,  
  const char **pzTail     
);
SQLITE_API int sqlite3_prepare_v3(
  sqlite3 *db,            
  const char *zSql,       
  int nByte,              
  unsigned int prepFlags, 
  sqlite3_stmt **ppStmt,  
  const char **pzTail     
);
SQLITE_API int sqlite3_prepare16(
  sqlite3 *db,            
  const void *zSql,       
  int nByte,              
  sqlite3_stmt **ppStmt,  
  const void **pzTail     
);
SQLITE_API int sqlite3_prepare16_v2(
  sqlite3 *db,            
  const void *zSql,       
  int nByte,              
  sqlite3_stmt **ppStmt,  
  const void **pzTail     
);
SQLITE_API int sqlite3_prepare16_v3(
  sqlite3 *db,            
  const void *zSql,       
  int nByte,              
  unsigned int prepFlags, 
  sqlite3_stmt **ppStmt,  
  const void **pzTail     
);

SQLITE_API const char *sqlite3_sql(sqlite3_stmt *pStmt);
SQLITE_API char *sqlite3_expanded_sql(sqlite3_stmt *pStmt);
#ifdef SQLITE_ENABLE_NORMALIZE
SQLITE_API const char *sqlite3_normalized_sql(sqlite3_stmt *pStmt);
#endif

SQLITE_API int sqlite3_stmt_readonly(sqlite3_stmt *pStmt);

SQLITE_API int sqlite3_stmt_isexplain(sqlite3_stmt *pStmt);

SQLITE_API int sqlite3_stmt_explain(sqlite3_stmt *pStmt, int eMode);

SQLITE_API int sqlite3_stmt_busy(sqlite3_stmt*);

typedef struct sqlite3_value sqlite3_value;

typedef struct sqlite3_context sqlite3_context;

SQLITE_API int sqlite3_bind_blob(sqlite3_stmt*, int, const void*, int n, void(*)(void*));
SQLITE_API int sqlite3_bind_blob64(sqlite3_stmt*, int, const void*, sqlite3_uint64,
                        void(*)(void*));
SQLITE_API int sqlite3_bind_double(sqlite3_stmt*, int, double);
SQLITE_API int sqlite3_bind_int(sqlite3_stmt*, int, int);
SQLITE_API int sqlite3_bind_int64(sqlite3_stmt*, int, sqlite3_int64);
SQLITE_API int sqlite3_bind_null(sqlite3_stmt*, int);
SQLITE_API int sqlite3_bind_text(sqlite3_stmt*,int,const char*,int,void(*)(void*));
SQLITE_API int sqlite3_bind_text16(sqlite3_stmt*, int, const void*, int, void(*)(void*));
SQLITE_API int sqlite3_bind_text64(sqlite3_stmt*, int, const char*, sqlite3_uint64,
                         void(*)(void*), unsigned char encoding);
SQLITE_API int sqlite3_bind_value(sqlite3_stmt*, int, const sqlite3_value*);
SQLITE_API int sqlite3_bind_pointer(sqlite3_stmt*, int, void*, const char*,void(*)(void*));
SQLITE_API int sqlite3_bind_zeroblob(sqlite3_stmt*, int, int n);
SQLITE_API int sqlite3_bind_zeroblob64(sqlite3_stmt*, int, sqlite3_uint64);

SQLITE_API int sqlite3_bind_parameter_count(sqlite3_stmt*);

SQLITE_API const char *sqlite3_bind_parameter_name(sqlite3_stmt*, int);

SQLITE_API int sqlite3_bind_parameter_index(sqlite3_stmt*, const char *zName);

SQLITE_API int sqlite3_clear_bindings(sqlite3_stmt*);

SQLITE_API int sqlite3_column_count(sqlite3_stmt *pStmt);

SQLITE_API const char *sqlite3_column_name(sqlite3_stmt*, int N);
SQLITE_API const void *sqlite3_column_name16(sqlite3_stmt*, int N);

SQLITE_API const char *sqlite3_column_database_name(sqlite3_stmt*,int);
SQLITE_API const void *sqlite3_column_database_name16(sqlite3_stmt*,int);
SQLITE_API const char *sqlite3_column_table_name(sqlite3_stmt*,int);
SQLITE_API const void *sqlite3_column_table_name16(sqlite3_stmt*,int);
SQLITE_API const char *sqlite3_column_origin_name(sqlite3_stmt*,int);
SQLITE_API const void *sqlite3_column_origin_name16(sqlite3_stmt*,int);

SQLITE_API const char *sqlite3_column_decltype(sqlite3_stmt*,int);
SQLITE_API const void *sqlite3_column_decltype16(sqlite3_stmt*,int);

SQLITE_API int sqlite3_step(sqlite3_stmt*);

SQLITE_API int sqlite3_data_count(sqlite3_stmt *pStmt);

#define SQLITE_INTEGER  1
#define SQLITE_FLOAT    2
#define SQLITE_BLOB     4
#define SQLITE_NULL     5
#ifdef SQLITE_TEXT
# undef SQLITE_TEXT
#else
# define SQLITE_TEXT     3
#endif
#define SQLITE3_TEXT     3

SQLITE_API const void *sqlite3_column_blob(sqlite3_stmt*, int iCol);
SQLITE_API double sqlite3_column_double(sqlite3_stmt*, int iCol);
SQLITE_API int sqlite3_column_int(sqlite3_stmt*, int iCol);
SQLITE_API sqlite3_int64 sqlite3_column_int64(sqlite3_stmt*, int iCol);
SQLITE_API const unsigned char *sqlite3_column_text(sqlite3_stmt*, int iCol);
SQLITE_API const void *sqlite3_column_text16(sqlite3_stmt*, int iCol);
SQLITE_API sqlite3_value *sqlite3_column_value(sqlite3_stmt*, int iCol);
SQLITE_API int sqlite3_column_bytes(sqlite3_stmt*, int iCol);
SQLITE_API int sqlite3_column_bytes16(sqlite3_stmt*, int iCol);
SQLITE_API int sqlite3_column_type(sqlite3_stmt*, int iCol);

SQLITE_API int sqlite3_finalize(sqlite3_stmt *pStmt);

SQLITE_API int sqlite3_reset(sqlite3_stmt *pStmt);

SQLITE_API int sqlite3_create_function(
  sqlite3 *db,
  const char *zFunctionName,
  int nArg,
  int eTextRep,
  void *pApp,
  void (*xFunc)(sqlite3_context*,int,sqlite3_value**),
  void (*xStep)(sqlite3_context*,int,sqlite3_value**),
  void (*xFinal)(sqlite3_context*)
);
SQLITE_API int sqlite3_create_function16(
  sqlite3 *db,
  const void *zFunctionName,
  int nArg,
  int eTextRep,
  void *pApp,
  void (*xFunc)(sqlite3_context*,int,sqlite3_value**),
  void (*xStep)(sqlite3_context*,int,sqlite3_value**),
  void (*xFinal)(sqlite3_context*)
);
SQLITE_API int sqlite3_create_function_v2(
  sqlite3 *db,
  const char *zFunctionName,
  int nArg,
  int eTextRep,
  void *pApp,
  void (*xFunc)(sqlite3_context*,int,sqlite3_value**),
  void (*xStep)(sqlite3_context*,int,sqlite3_value**),
  void (*xFinal)(sqlite3_context*),
  void(*xDestroy)(void*)
);
SQLITE_API int sqlite3_create_window_function(
  sqlite3 *db,
  const char *zFunctionName,
  int nArg,
  int eTextRep,
  void *pApp,
  void (*xStep)(sqlite3_context*,int,sqlite3_value**),
  void (*xFinal)(sqlite3_context*),
  void (*xValue)(sqlite3_context*),
  void (*xInverse)(sqlite3_context*,int,sqlite3_value**),
  void(*xDestroy)(void*)
);

#define SQLITE_UTF8           1    
#define SQLITE_UTF16LE        2    
#define SQLITE_UTF16BE        3    
#define SQLITE_UTF16          4    
#define SQLITE_ANY            5    
#define SQLITE_UTF16_ALIGNED  8    
#define SQLITE_UTF8_ZT       16    

#define SQLITE_DETERMINISTIC    0x000000800
#define SQLITE_DIRECTONLY       0x000080000
#define SQLITE_SUBTYPE          0x000100000
#define SQLITE_INNOCUOUS        0x000200000
#define SQLITE_RESULT_SUBTYPE   0x001000000
#define SQLITE_SELFORDER1       0x002000000

#ifndef SQLITE_OMIT_DEPRECATED
SQLITE_API SQLITE_DEPRECATED int sqlite3_aggregate_count(sqlite3_context*);
SQLITE_API SQLITE_DEPRECATED int sqlite3_expired(sqlite3_stmt*);
SQLITE_API SQLITE_DEPRECATED int sqlite3_transfer_bindings(sqlite3_stmt*, sqlite3_stmt*);
SQLITE_API SQLITE_DEPRECATED int sqlite3_global_recover(void);
SQLITE_API SQLITE_DEPRECATED void sqlite3_thread_cleanup(void);
SQLITE_API SQLITE_DEPRECATED int sqlite3_memory_alarm(void(*)(void*,sqlite3_int64,int),
                      void*,sqlite3_int64);
#endif

SQLITE_API const void *sqlite3_value_blob(sqlite3_value*);
SQLITE_API double sqlite3_value_double(sqlite3_value*);
SQLITE_API int sqlite3_value_int(sqlite3_value*);
SQLITE_API sqlite3_int64 sqlite3_value_int64(sqlite3_value*);
SQLITE_API void *sqlite3_value_pointer(sqlite3_value*, const char*);
SQLITE_API const unsigned char *sqlite3_value_text(sqlite3_value*);
SQLITE_API const void *sqlite3_value_text16(sqlite3_value*);
SQLITE_API const void *sqlite3_value_text16le(sqlite3_value*);
SQLITE_API const void *sqlite3_value_text16be(sqlite3_value*);
SQLITE_API int sqlite3_value_bytes(sqlite3_value*);
SQLITE_API int sqlite3_value_bytes16(sqlite3_value*);
SQLITE_API int sqlite3_value_type(sqlite3_value*);
SQLITE_API int sqlite3_value_numeric_type(sqlite3_value*);
SQLITE_API int sqlite3_value_nochange(sqlite3_value*);
SQLITE_API int sqlite3_value_frombind(sqlite3_value*);

SQLITE_API int sqlite3_value_encoding(sqlite3_value*);

SQLITE_API unsigned int sqlite3_value_subtype(sqlite3_value*);

SQLITE_API sqlite3_value *sqlite3_value_dup(const sqlite3_value*);
SQLITE_API void sqlite3_value_free(sqlite3_value*);

SQLITE_API void *sqlite3_aggregate_context(sqlite3_context*, int nBytes);

SQLITE_API void *sqlite3_user_data(sqlite3_context*);

SQLITE_API sqlite3 *sqlite3_context_db_handle(sqlite3_context*);

SQLITE_API void *sqlite3_get_auxdata(sqlite3_context*, int N);
SQLITE_API void sqlite3_set_auxdata(sqlite3_context*, int N, void*, void (*)(void*));

SQLITE_API void *sqlite3_get_clientdata(sqlite3*,const char*);
SQLITE_API int sqlite3_set_clientdata(sqlite3*, const char*, void*, void(*)(void*));

typedef void (*sqlite3_destructor_type)(void*);
#define SQLITE_STATIC      ((sqlite3_destructor_type)0)
#define SQLITE_TRANSIENT   ((sqlite3_destructor_type)-1)

SQLITE_API void sqlite3_result_blob(sqlite3_context*, const void*, int, void(*)(void*));
SQLITE_API void sqlite3_result_blob64(sqlite3_context*,const void*,
                           sqlite3_uint64,void(*)(void*));
SQLITE_API void sqlite3_result_double(sqlite3_context*, double);
SQLITE_API void sqlite3_result_error(sqlite3_context*, const char*, int);
SQLITE_API void sqlite3_result_error16(sqlite3_context*, const void*, int);
SQLITE_API void sqlite3_result_error_toobig(sqlite3_context*);
SQLITE_API void sqlite3_result_error_nomem(sqlite3_context*);
SQLITE_API void sqlite3_result_error_code(sqlite3_context*, int);
SQLITE_API void sqlite3_result_int(sqlite3_context*, int);
SQLITE_API void sqlite3_result_int64(sqlite3_context*, sqlite3_int64);
SQLITE_API void sqlite3_result_null(sqlite3_context*);
SQLITE_API void sqlite3_result_text(sqlite3_context*, const char*, int, void(*)(void*));
SQLITE_API void sqlite3_result_text64(sqlite3_context*, const char *z, sqlite3_uint64 n,
                           void(*)(void*), unsigned char encoding);
SQLITE_API void sqlite3_result_text16(sqlite3_context*, const void*, int, void(*)(void*));
SQLITE_API void sqlite3_result_text16le(sqlite3_context*, const void*, int,void(*)(void*));
SQLITE_API void sqlite3_result_text16be(sqlite3_context*, const void*, int,void(*)(void*));
SQLITE_API void sqlite3_result_value(sqlite3_context*, sqlite3_value*);
SQLITE_API void sqlite3_result_pointer(sqlite3_context*, void*,const char*,void(*)(void*));
SQLITE_API void sqlite3_result_zeroblob(sqlite3_context*, int n);
SQLITE_API int sqlite3_result_zeroblob64(sqlite3_context*, sqlite3_uint64 n);

SQLITE_API void sqlite3_result_subtype(sqlite3_context*,unsigned int);

SQLITE_API int sqlite3_create_collation(
  sqlite3*,
  const char *zName,
  int eTextRep,
  void *pArg,
  int(*xCompare)(void*,int,const void*,int,const void*)
);
SQLITE_API int sqlite3_create_collation_v2(
  sqlite3*,
  const char *zName,
  int eTextRep,
  void *pArg,
  int(*xCompare)(void*,int,const void*,int,const void*),
  void(*xDestroy)(void*)
);
SQLITE_API int sqlite3_create_collation16(
  sqlite3*,
  const void *zName,
  int eTextRep,
  void *pArg,
  int(*xCompare)(void*,int,const void*,int,const void*)
);

SQLITE_API int sqlite3_collation_needed(
  sqlite3*,
  void*,
  void(*)(void*,sqlite3*,int eTextRep,const char*)
);
SQLITE_API int sqlite3_collation_needed16(
  sqlite3*,
  void*,
  void(*)(void*,sqlite3*,int eTextRep,const void*)
);

#ifdef SQLITE_ENABLE_CEROD

SQLITE_API void sqlite3_activate_cerod(
  const char *zPassPhrase        
);
#endif

SQLITE_API int sqlite3_sleep(int);

SQLITE_API SQLITE_EXTERN char *sqlite3_temp_directory;

SQLITE_API SQLITE_EXTERN char *sqlite3_data_directory;

SQLITE_API int sqlite3_win32_set_directory(
  unsigned long type, 
  void *zValue        
);
SQLITE_API int sqlite3_win32_set_directory8(unsigned long type, const char *zValue);
SQLITE_API int sqlite3_win32_set_directory16(unsigned long type, const void *zValue);

#define SQLITE_WIN32_DATA_DIRECTORY_TYPE  1
#define SQLITE_WIN32_TEMP_DIRECTORY_TYPE  2

SQLITE_API int sqlite3_get_autocommit(sqlite3*);

SQLITE_API sqlite3 *sqlite3_db_handle(sqlite3_stmt*);

SQLITE_API const char *sqlite3_db_name(sqlite3 *db, int N);

SQLITE_API sqlite3_filename sqlite3_db_filename(sqlite3 *db, const char *zDbName);

SQLITE_API int sqlite3_db_readonly(sqlite3 *db, const char *zDbName);

SQLITE_API int sqlite3_txn_state(sqlite3*,const char *zSchema);

#define SQLITE_TXN_NONE  0
#define SQLITE_TXN_READ  1
#define SQLITE_TXN_WRITE 2

SQLITE_API sqlite3_stmt *sqlite3_next_stmt(sqlite3 *pDb, sqlite3_stmt *pStmt);

SQLITE_API void *sqlite3_commit_hook(sqlite3*, int(*)(void*), void*);
SQLITE_API void *sqlite3_rollback_hook(sqlite3*, void(*)(void *), void*);

SQLITE_API int sqlite3_autovacuum_pages(
  sqlite3 *db,
  unsigned int(*)(void*,const char*,unsigned int,unsigned int,unsigned int),
  void*,
  void(*)(void*)
);

SQLITE_API void *sqlite3_update_hook(
  sqlite3*,
  void(*)(void *,int ,char const *,char const *,sqlite3_int64),
  void*
);

SQLITE_API int sqlite3_enable_shared_cache(int);

SQLITE_API int sqlite3_release_memory(int);

SQLITE_API int sqlite3_db_release_memory(sqlite3*);

SQLITE_API sqlite3_int64 sqlite3_soft_heap_limit64(sqlite3_int64 N);
SQLITE_API sqlite3_int64 sqlite3_hard_heap_limit64(sqlite3_int64 N);

SQLITE_API SQLITE_DEPRECATED void sqlite3_soft_heap_limit(int N);

SQLITE_API int sqlite3_table_column_metadata(
  sqlite3 *db,                
  const char *zDbName,        
  const char *zTableName,     
  const char *zColumnName,    
  char const **pzDataType,    
  char const **pzCollSeq,     
  int *pNotNull,              
  int *pPrimaryKey,           
  int *pAutoinc               
);

SQLITE_API int sqlite3_load_extension(
  sqlite3 *db,          
  const char *zFile,    
  const char *zProc,    
  char **pzErrMsg       
);

SQLITE_API int sqlite3_enable_load_extension(sqlite3 *db, int onoff);

SQLITE_API int sqlite3_auto_extension(void(*xEntryPoint)(void));

SQLITE_API int sqlite3_cancel_auto_extension(void(*xEntryPoint)(void));

SQLITE_API void sqlite3_reset_auto_extension(void);

typedef struct sqlite3_vtab sqlite3_vtab;
typedef struct sqlite3_index_info sqlite3_index_info;
typedef struct sqlite3_vtab_cursor sqlite3_vtab_cursor;
typedef struct sqlite3_module sqlite3_module;

struct sqlite3_module {
  int iVersion;
  int (*xCreate)(sqlite3*, void *pAux,
               int argc, const char *const*argv,
               sqlite3_vtab **ppVTab, char**);
  int (*xConnect)(sqlite3*, void *pAux,
               int argc, const char *const*argv,
               sqlite3_vtab **ppVTab, char**);
  int (*xBestIndex)(sqlite3_vtab *pVTab, sqlite3_index_info*);
  int (*xDisconnect)(sqlite3_vtab *pVTab);
  int (*xDestroy)(sqlite3_vtab *pVTab);
  int (*xOpen)(sqlite3_vtab *pVTab, sqlite3_vtab_cursor **ppCursor);
  int (*xClose)(sqlite3_vtab_cursor*);
  int (*xFilter)(sqlite3_vtab_cursor*, int idxNum, const char *idxStr,
                int argc, sqlite3_value **argv);
  int (*xNext)(sqlite3_vtab_cursor*);
  int (*xEof)(sqlite3_vtab_cursor*);
  int (*xColumn)(sqlite3_vtab_cursor*, sqlite3_context*, int);
  int (*xRowid)(sqlite3_vtab_cursor*, sqlite3_int64 *pRowid);
  int (*xUpdate)(sqlite3_vtab *, int, sqlite3_value **, sqlite3_int64 *);
  int (*xBegin)(sqlite3_vtab *pVTab);
  int (*xSync)(sqlite3_vtab *pVTab);
  int (*xCommit)(sqlite3_vtab *pVTab);
  int (*xRollback)(sqlite3_vtab *pVTab);
  int (*xFindFunction)(sqlite3_vtab *pVtab, int nArg, const char *zName,
                       void (**pxFunc)(sqlite3_context*,int,sqlite3_value**),
                       void **ppArg);
  int (*xRename)(sqlite3_vtab *pVtab, const char *zNew);
  
  int (*xSavepoint)(sqlite3_vtab *pVTab, int);
  int (*xRelease)(sqlite3_vtab *pVTab, int);
  int (*xRollbackTo)(sqlite3_vtab *pVTab, int);
  
  int (*xShadowName)(const char*);
  
  int (*xIntegrity)(sqlite3_vtab *pVTab, const char *zSchema,
                    const char *zTabName, int mFlags, char **pzErr);
};

struct sqlite3_index_info {
  
  int nConstraint;           
  struct sqlite3_index_constraint {
     int iColumn;              
     unsigned char op;         
     unsigned char usable;     
     int iTermOffset;          
  } *aConstraint;            
  int nOrderBy;              
  struct sqlite3_index_orderby {
     int iColumn;              
     unsigned char desc;       
  } *aOrderBy;               
  
  struct sqlite3_index_constraint_usage {
    int argvIndex;           
    unsigned char omit;      
  } *aConstraintUsage;
  int idxNum;                
  char *idxStr;              
  int needToFreeIdxStr;      
  int orderByConsumed;       
  double estimatedCost;           
  
  sqlite3_int64 estimatedRows;    
  
  int idxFlags;              
  
  sqlite3_uint64 colUsed;    
};

#define SQLITE_INDEX_SCAN_UNIQUE 0x00000001 
#define SQLITE_INDEX_SCAN_HEX    0x00000002 
                                            

#define SQLITE_INDEX_CONSTRAINT_EQ          2
#define SQLITE_INDEX_CONSTRAINT_GT          4
#define SQLITE_INDEX_CONSTRAINT_LE          8
#define SQLITE_INDEX_CONSTRAINT_LT         16
#define SQLITE_INDEX_CONSTRAINT_GE         32
#define SQLITE_INDEX_CONSTRAINT_MATCH      64
#define SQLITE_INDEX_CONSTRAINT_LIKE       65
#define SQLITE_INDEX_CONSTRAINT_GLOB       66
#define SQLITE_INDEX_CONSTRAINT_REGEXP     67
#define SQLITE_INDEX_CONSTRAINT_NE         68
#define SQLITE_INDEX_CONSTRAINT_ISNOT      69
#define SQLITE_INDEX_CONSTRAINT_ISNOTNULL  70
#define SQLITE_INDEX_CONSTRAINT_ISNULL     71
#define SQLITE_INDEX_CONSTRAINT_IS         72
#define SQLITE_INDEX_CONSTRAINT_LIMIT      73
#define SQLITE_INDEX_CONSTRAINT_OFFSET     74
#define SQLITE_INDEX_CONSTRAINT_FUNCTION  150

SQLITE_API int sqlite3_create_module(
  sqlite3 *db,               
  const char *zName,         
  const sqlite3_module *p,   
  void *pClientData          
);
SQLITE_API int sqlite3_create_module_v2(
  sqlite3 *db,               
  const char *zName,         
  const sqlite3_module *p,   
  void *pClientData,         
  void(*xDestroy)(void*)     
);

SQLITE_API int sqlite3_drop_modules(
  sqlite3 *db,                
  const char **azKeep         
);

struct sqlite3_vtab {
  const sqlite3_module *pModule;  
  int nRef;                       
  char *zErrMsg;                  
  
};

struct sqlite3_vtab_cursor {
  sqlite3_vtab *pVtab;      
  
};

SQLITE_API int sqlite3_declare_vtab(sqlite3*, const char *zSQL);

SQLITE_API int sqlite3_overload_function(sqlite3*, const char *zFuncName, int nArg);

typedef struct sqlite3_blob sqlite3_blob;

SQLITE_API int sqlite3_blob_open(
  sqlite3*,
  const char *zDb,
  const char *zTable,
  const char *zColumn,
  sqlite3_int64 iRow,
  int flags,
  sqlite3_blob **ppBlob
);

SQLITE_API int sqlite3_blob_reopen(sqlite3_blob *, sqlite3_int64);

SQLITE_API int sqlite3_blob_close(sqlite3_blob *);

SQLITE_API int sqlite3_blob_bytes(sqlite3_blob *);

SQLITE_API int sqlite3_blob_read(sqlite3_blob *, void *Z, int N, int iOffset);

SQLITE_API int sqlite3_blob_write(sqlite3_blob *, const void *z, int n, int iOffset);

SQLITE_API sqlite3_vfs *sqlite3_vfs_find(const char *zVfsName);
SQLITE_API int sqlite3_vfs_register(sqlite3_vfs*, int makeDflt);
SQLITE_API int sqlite3_vfs_unregister(sqlite3_vfs*);

SQLITE_API sqlite3_mutex *sqlite3_mutex_alloc(int);
SQLITE_API void sqlite3_mutex_free(sqlite3_mutex*);
SQLITE_API void sqlite3_mutex_enter(sqlite3_mutex*);
SQLITE_API int sqlite3_mutex_try(sqlite3_mutex*);
SQLITE_API void sqlite3_mutex_leave(sqlite3_mutex*);

typedef struct sqlite3_mutex_methods sqlite3_mutex_methods;
struct sqlite3_mutex_methods {
  int (*xMutexInit)(void);
  int (*xMutexEnd)(void);
  sqlite3_mutex *(*xMutexAlloc)(int);
  void (*xMutexFree)(sqlite3_mutex *);
  void (*xMutexEnter)(sqlite3_mutex *);
  int (*xMutexTry)(sqlite3_mutex *);
  void (*xMutexLeave)(sqlite3_mutex *);
  int (*xMutexHeld)(sqlite3_mutex *);
  int (*xMutexNotheld)(sqlite3_mutex *);
};

#ifndef NDEBUG
SQLITE_API int sqlite3_mutex_held(sqlite3_mutex*);
SQLITE_API int sqlite3_mutex_notheld(sqlite3_mutex*);
#endif

#define SQLITE_MUTEX_FAST             0
#define SQLITE_MUTEX_RECURSIVE        1
#define SQLITE_MUTEX_STATIC_MAIN      2
#define SQLITE_MUTEX_STATIC_MEM       3  
#define SQLITE_MUTEX_STATIC_MEM2      4  
#define SQLITE_MUTEX_STATIC_OPEN      4  
#define SQLITE_MUTEX_STATIC_PRNG      5  
#define SQLITE_MUTEX_STATIC_LRU       6  
#define SQLITE_MUTEX_STATIC_LRU2      7  
#define SQLITE_MUTEX_STATIC_PMEM      7  
#define SQLITE_MUTEX_STATIC_APP1      8  
#define SQLITE_MUTEX_STATIC_APP2      9  
#define SQLITE_MUTEX_STATIC_APP3     10  
#define SQLITE_MUTEX_STATIC_VFS1     11  
#define SQLITE_MUTEX_STATIC_VFS2     12  
#define SQLITE_MUTEX_STATIC_VFS3     13  

#define SQLITE_MUTEX_STATIC_MASTER    2

SQLITE_API sqlite3_mutex *sqlite3_db_mutex(sqlite3*);

SQLITE_API int sqlite3_file_control(sqlite3*, const char *zDbName, int op, void*);

SQLITE_API int sqlite3_test_control(int op, ...);

#define SQLITE_TESTCTRL_FIRST                    5
#define SQLITE_TESTCTRL_PRNG_SAVE                5
#define SQLITE_TESTCTRL_PRNG_RESTORE             6
#define SQLITE_TESTCTRL_PRNG_RESET               7  
#define SQLITE_TESTCTRL_FK_NO_ACTION             7
#define SQLITE_TESTCTRL_BITVEC_TEST              8
#define SQLITE_TESTCTRL_FAULT_INSTALL            9
#define SQLITE_TESTCTRL_BENIGN_MALLOC_HOOKS     10
#define SQLITE_TESTCTRL_PENDING_BYTE            11
#define SQLITE_TESTCTRL_ASSERT                  12
#define SQLITE_TESTCTRL_ALWAYS                  13
#define SQLITE_TESTCTRL_RESERVE                 14  
#define SQLITE_TESTCTRL_JSON_SELFCHECK          14
#define SQLITE_TESTCTRL_OPTIMIZATIONS           15
#define SQLITE_TESTCTRL_ISKEYWORD               16  
#define SQLITE_TESTCTRL_GETOPT                  16
#define SQLITE_TESTCTRL_SCRATCHMALLOC           17  
#define SQLITE_TESTCTRL_INTERNAL_FUNCTIONS      17
#define SQLITE_TESTCTRL_LOCALTIME_FAULT         18
#define SQLITE_TESTCTRL_EXPLAIN_STMT            19  
#define SQLITE_TESTCTRL_ONCE_RESET_THRESHOLD    19
#define SQLITE_TESTCTRL_NEVER_CORRUPT           20
#define SQLITE_TESTCTRL_VDBE_COVERAGE           21
#define SQLITE_TESTCTRL_BYTEORDER               22
#define SQLITE_TESTCTRL_ISINIT                  23
#define SQLITE_TESTCTRL_SORTER_MMAP             24
#define SQLITE_TESTCTRL_IMPOSTER                25
#define SQLITE_TESTCTRL_PARSER_COVERAGE         26
#define SQLITE_TESTCTRL_RESULT_INTREAL          27
#define SQLITE_TESTCTRL_PRNG_SEED               28
#define SQLITE_TESTCTRL_EXTRA_SCHEMA_CHECKS     29
#define SQLITE_TESTCTRL_SEEK_COUNT              30
#define SQLITE_TESTCTRL_TRACEFLAGS              31
#define SQLITE_TESTCTRL_TUNE                    32
#define SQLITE_TESTCTRL_LOGEST                  33
#define SQLITE_TESTCTRL_USELONGDOUBLE           34  
#define SQLITE_TESTCTRL_ATOF                    34
#define SQLITE_TESTCTRL_LAST                    34  

SQLITE_API int sqlite3_keyword_count(void);
SQLITE_API int sqlite3_keyword_name(int,const char**,int*);
SQLITE_API int sqlite3_keyword_check(const char*,int);

typedef struct sqlite3_str sqlite3_str;

SQLITE_API sqlite3_str *sqlite3_str_new(sqlite3*);

SQLITE_API char *sqlite3_str_finish(sqlite3_str*);
SQLITE_API void sqlite3_str_free(sqlite3_str*);

SQLITE_API void sqlite3_str_appendf(sqlite3_str*, const char *zFormat, ...);
SQLITE_API void sqlite3_str_vappendf(sqlite3_str*, const char *zFormat, va_list);
SQLITE_API void sqlite3_str_append(sqlite3_str*, const char *zIn, int N);
SQLITE_API void sqlite3_str_appendall(sqlite3_str*, const char *zIn);
SQLITE_API void sqlite3_str_appendchar(sqlite3_str*, int N, char C);
SQLITE_API void sqlite3_str_reset(sqlite3_str*);
SQLITE_API void sqlite3_str_truncate(sqlite3_str*,int N);

SQLITE_API int sqlite3_str_errcode(sqlite3_str*);
SQLITE_API int sqlite3_str_length(sqlite3_str*);
SQLITE_API char *sqlite3_str_value(sqlite3_str*);

SQLITE_API int sqlite3_status(int op, int *pCurrent, int *pHighwater, int resetFlag);
SQLITE_API int sqlite3_status64(
  int op,
  sqlite3_int64 *pCurrent,
  sqlite3_int64 *pHighwater,
  int resetFlag
);

#define SQLITE_STATUS_MEMORY_USED          0
#define SQLITE_STATUS_PAGECACHE_USED       1
#define SQLITE_STATUS_PAGECACHE_OVERFLOW   2
#define SQLITE_STATUS_SCRATCH_USED         3  
#define SQLITE_STATUS_SCRATCH_OVERFLOW     4  
#define SQLITE_STATUS_MALLOC_SIZE          5
#define SQLITE_STATUS_PARSER_STACK         6
#define SQLITE_STATUS_PAGECACHE_SIZE       7
#define SQLITE_STATUS_SCRATCH_SIZE         8  
#define SQLITE_STATUS_MALLOC_COUNT         9

SQLITE_API int sqlite3_db_status(sqlite3*, int op, int *pCur, int *pHiwtr, int resetFlg);
SQLITE_API int sqlite3_db_status64(sqlite3*,int,sqlite3_int64*,sqlite3_int64*,int);

#define SQLITE_DBSTATUS_LOOKASIDE_USED       0
#define SQLITE_DBSTATUS_CACHE_USED           1
#define SQLITE_DBSTATUS_SCHEMA_USED          2
#define SQLITE_DBSTATUS_STMT_USED            3
#define SQLITE_DBSTATUS_LOOKASIDE_HIT        4
#define SQLITE_DBSTATUS_LOOKASIDE_MISS_SIZE  5
#define SQLITE_DBSTATUS_LOOKASIDE_MISS_FULL  6
#define SQLITE_DBSTATUS_CACHE_HIT            7
#define SQLITE_DBSTATUS_CACHE_MISS           8
#define SQLITE_DBSTATUS_CACHE_WRITE          9
#define SQLITE_DBSTATUS_DEFERRED_FKS        10
#define SQLITE_DBSTATUS_CACHE_USED_SHARED   11
#define SQLITE_DBSTATUS_CACHE_SPILL         12
#define SQLITE_DBSTATUS_TEMPBUF_SPILL       13
#define SQLITE_DBSTATUS_MAX                 13   

SQLITE_API int sqlite3_stmt_status(sqlite3_stmt*, int op,int resetFlg);

#define SQLITE_STMTSTATUS_FULLSCAN_STEP     1
#define SQLITE_STMTSTATUS_SORT              2
#define SQLITE_STMTSTATUS_AUTOINDEX         3
#define SQLITE_STMTSTATUS_VM_STEP           4
#define SQLITE_STMTSTATUS_REPREPARE         5
#define SQLITE_STMTSTATUS_RUN               6
#define SQLITE_STMTSTATUS_FILTER_MISS       7
#define SQLITE_STMTSTATUS_FILTER_HIT        8
#define SQLITE_STMTSTATUS_MEMUSED           99

typedef struct sqlite3_pcache sqlite3_pcache;

typedef struct sqlite3_pcache_page sqlite3_pcache_page;
struct sqlite3_pcache_page {
  void *pBuf;        
  void *pExtra;      
};

typedef struct sqlite3_pcache_methods2 sqlite3_pcache_methods2;
struct sqlite3_pcache_methods2 {
  int iVersion;
  void *pArg;
  int (*xInit)(void*);
  void (*xShutdown)(void*);
  sqlite3_pcache *(*xCreate)(int szPage, int szExtra, int bPurgeable);
  void (*xCachesize)(sqlite3_pcache*, int nCachesize);
  int (*xPagecount)(sqlite3_pcache*);
  sqlite3_pcache_page *(*xFetch)(sqlite3_pcache*, unsigned key, int createFlag);
  void (*xUnpin)(sqlite3_pcache*, sqlite3_pcache_page*, int discard);
  void (*xRekey)(sqlite3_pcache*, sqlite3_pcache_page*,
      unsigned oldKey, unsigned newKey);
  void (*xTruncate)(sqlite3_pcache*, unsigned iLimit);
  void (*xDestroy)(sqlite3_pcache*);
  void (*xShrink)(sqlite3_pcache*);
};

typedef struct sqlite3_pcache_methods sqlite3_pcache_methods;
struct sqlite3_pcache_methods {
  void *pArg;
  int (*xInit)(void*);
  void (*xShutdown)(void*);
  sqlite3_pcache *(*xCreate)(int szPage, int bPurgeable);
  void (*xCachesize)(sqlite3_pcache*, int nCachesize);
  int (*xPagecount)(sqlite3_pcache*);
  void *(*xFetch)(sqlite3_pcache*, unsigned key, int createFlag);
  void (*xUnpin)(sqlite3_pcache*, void*, int discard);
  void (*xRekey)(sqlite3_pcache*, void*, unsigned oldKey, unsigned newKey);
  void (*xTruncate)(sqlite3_pcache*, unsigned iLimit);
  void (*xDestroy)(sqlite3_pcache*);
};

typedef struct sqlite3_backup sqlite3_backup;

SQLITE_API sqlite3_backup *sqlite3_backup_init(
  sqlite3 *pDest,                        
  const char *zDestName,                 
  sqlite3 *pSource,                      
  const char *zSourceName                
);
SQLITE_API int sqlite3_backup_step(sqlite3_backup *p, int nPage);
SQLITE_API int sqlite3_backup_finish(sqlite3_backup *p);
SQLITE_API int sqlite3_backup_remaining(sqlite3_backup *p);
SQLITE_API int sqlite3_backup_pagecount(sqlite3_backup *p);

SQLITE_API int sqlite3_unlock_notify(
  sqlite3 *pBlocked,                          
  void (*xNotify)(void **apArg, int nArg),    
  void *pNotifyArg                            
);

SQLITE_API int sqlite3_stricmp(const char *, const char *);
SQLITE_API int sqlite3_strnicmp(const char *, const char *, int);

SQLITE_API int sqlite3_strglob(const char *zGlob, const char *zStr);

SQLITE_API int sqlite3_strlike(const char *zGlob, const char *zStr, unsigned int cEsc);

SQLITE_API void sqlite3_log(int iErrCode, const char *zFormat, ...);

SQLITE_API void *sqlite3_wal_hook(
  sqlite3*,
  int(*)(void *,sqlite3*,const char*,int),
  void*
);

SQLITE_API int sqlite3_wal_autocheckpoint(sqlite3 *db, int N);

SQLITE_API int sqlite3_wal_checkpoint(sqlite3 *db, const char *zDb);

SQLITE_API int sqlite3_wal_checkpoint_v2(
  sqlite3 *db,                    
  const char *zDb,                
  int eMode,                      
  int *pnLog,                     
  int *pnCkpt                     
);

#define SQLITE_CHECKPOINT_NOOP    -1  
#define SQLITE_CHECKPOINT_PASSIVE  0  
#define SQLITE_CHECKPOINT_FULL     1  
#define SQLITE_CHECKPOINT_RESTART  2  
#define SQLITE_CHECKPOINT_TRUNCATE 3  

SQLITE_API int sqlite3_vtab_config(sqlite3*, int op, ...);

#define SQLITE_VTAB_CONSTRAINT_SUPPORT 1
#define SQLITE_VTAB_INNOCUOUS          2
#define SQLITE_VTAB_DIRECTONLY         3
#define SQLITE_VTAB_USES_ALL_SCHEMAS   4

SQLITE_API int sqlite3_vtab_on_conflict(sqlite3 *);

SQLITE_API int sqlite3_vtab_nochange(sqlite3_context*);

SQLITE_API const char *sqlite3_vtab_collation(sqlite3_index_info*,int);

SQLITE_API int sqlite3_vtab_distinct(sqlite3_index_info*);

SQLITE_API int sqlite3_vtab_in(sqlite3_index_info*, int iCons, int bHandle);

SQLITE_API int sqlite3_vtab_in_first(sqlite3_value *pVal, sqlite3_value **ppOut);
SQLITE_API int sqlite3_vtab_in_next(sqlite3_value *pVal, sqlite3_value **ppOut);

SQLITE_API int sqlite3_vtab_rhs_value(sqlite3_index_info*, int, sqlite3_value **ppVal);

#define SQLITE_ROLLBACK 1

#define SQLITE_FAIL     3

#define SQLITE_REPLACE  5

#define SQLITE_SCANSTAT_NLOOP    0
#define SQLITE_SCANSTAT_NVISIT   1
#define SQLITE_SCANSTAT_EST      2
#define SQLITE_SCANSTAT_NAME     3
#define SQLITE_SCANSTAT_EXPLAIN  4
#define SQLITE_SCANSTAT_SELECTID 5
#define SQLITE_SCANSTAT_PARENTID 6
#define SQLITE_SCANSTAT_NCYCLE   7

SQLITE_API int sqlite3_stmt_scanstatus(
  sqlite3_stmt *pStmt,      
  int idx,                  
  int iScanStatusOp,        
  void *pOut                
);
SQLITE_API int sqlite3_stmt_scanstatus_v2(
  sqlite3_stmt *pStmt,      
  int idx,                  
  int iScanStatusOp,        
  int flags,                
  void *pOut                
);

#define SQLITE_SCANSTAT_COMPLEX 0x0001

SQLITE_API void sqlite3_stmt_scanstatus_reset(sqlite3_stmt*);

SQLITE_API int sqlite3_db_cacheflush(sqlite3*);

#if defined(SQLITE_ENABLE_PREUPDATE_HOOK)
SQLITE_API void *sqlite3_preupdate_hook(
  sqlite3 *db,
  void(*xPreUpdate)(
    void *pCtx,                   
    sqlite3 *db,                  
    int op,                       
    char const *zDb,              
    char const *zName,            
    sqlite3_int64 iKey1,          
    sqlite3_int64 iKey2           
  ),
  void*
);
SQLITE_API int sqlite3_preupdate_old(sqlite3 *, int, sqlite3_value **);
SQLITE_API int sqlite3_preupdate_count(sqlite3 *);
SQLITE_API int sqlite3_preupdate_depth(sqlite3 *);
SQLITE_API int sqlite3_preupdate_new(sqlite3 *, int, sqlite3_value **);
SQLITE_API int sqlite3_preupdate_blobwrite(sqlite3 *);
#endif

SQLITE_API int sqlite3_system_errno(sqlite3*);

typedef struct sqlite3_snapshot {
  unsigned char hidden[48];
} sqlite3_snapshot;

SQLITE_API int sqlite3_snapshot_get(
  sqlite3 *db,
  const char *zSchema,
  sqlite3_snapshot **ppSnapshot
);

SQLITE_API int sqlite3_snapshot_open(
  sqlite3 *db,
  const char *zSchema,
  sqlite3_snapshot *pSnapshot
);

SQLITE_API void sqlite3_snapshot_free(sqlite3_snapshot*);

SQLITE_API int sqlite3_snapshot_cmp(
  sqlite3_snapshot *p1,
  sqlite3_snapshot *p2
);

SQLITE_API int sqlite3_snapshot_recover(sqlite3 *db, const char *zDb);

SQLITE_API unsigned char *sqlite3_serialize(
  sqlite3 *db,           
  const char *zSchema,   
  sqlite3_int64 *piSize, 
  unsigned int mFlags    
);

#define SQLITE_SERIALIZE_NOCOPY 0x001   

SQLITE_API int sqlite3_deserialize(
  sqlite3 *db,            
  const char *zSchema,    
  unsigned char *pData,   
  sqlite3_int64 szDb,     
  sqlite3_int64 szBuf,    
  unsigned mFlags         
);

#define SQLITE_DESERIALIZE_FREEONCLOSE 1 
#define SQLITE_DESERIALIZE_RESIZEABLE  2 
#define SQLITE_DESERIALIZE_READONLY    4 

SQLITE_API int sqlite3_carray_bind_v2(
  sqlite3_stmt *pStmt,        
  int i,                      
  void *aData,                
  int nData,                  
  int mFlags,                 
  void (*xDel)(void*),        
  void *pDel                  
);
SQLITE_API int sqlite3_carray_bind(
  sqlite3_stmt *pStmt,        
  int i,                      
  void *aData,                
  int nData,                  
  int mFlags,                 
  void (*xDel)(void*)         
);

#define SQLITE_CARRAY_INT32     0    
#define SQLITE_CARRAY_INT64     1    
#define SQLITE_CARRAY_DOUBLE    2    
#define SQLITE_CARRAY_TEXT      3    
#define SQLITE_CARRAY_BLOB      4    

#define CARRAY_INT32     0    
#define CARRAY_INT64     1    
#define CARRAY_DOUBLE    2    
#define CARRAY_TEXT      3    
#define CARRAY_BLOB      4    

#ifdef SQLITE_OMIT_FLOATING_POINT
# undef double
#endif

#if defined(__wasi__)
# undef SQLITE_WASI
# define SQLITE_WASI 1
# ifndef SQLITE_OMIT_LOAD_EXTENSION
#  define SQLITE_OMIT_LOAD_EXTENSION
# endif
# ifndef SQLITE_THREADSAFE
#  define SQLITE_THREADSAFE 0
# endif
#endif

#ifdef __cplusplus
}  
#endif

#ifndef _SQLITE3RTREE_H_
#define _SQLITE3RTREE_H_

#ifdef __cplusplus
extern "C" {
#endif

typedef struct sqlite3_rtree_geometry sqlite3_rtree_geometry;
typedef struct sqlite3_rtree_query_info sqlite3_rtree_query_info;

#ifdef SQLITE_RTREE_INT_ONLY
  typedef sqlite3_int64 sqlite3_rtree_dbl;
#else
  typedef double sqlite3_rtree_dbl;
#endif

SQLITE_API int sqlite3_rtree_geometry_callback(
  sqlite3 *db,
  const char *zGeom,
  int (*xGeom)(sqlite3_rtree_geometry*, int, sqlite3_rtree_dbl*,int*),
  void *pContext
);

struct sqlite3_rtree_geometry {
  void *pContext;                 
  int nParam;                     
  sqlite3_rtree_dbl *aParam;      
  void *pUser;                    
  void (*xDelUser)(void *);       
};

SQLITE_API int sqlite3_rtree_query_callback(
  sqlite3 *db,
  const char *zQueryFunc,
  int (*xQueryFunc)(sqlite3_rtree_query_info*),
  void *pContext,
  void (*xDestructor)(void*)
);

struct sqlite3_rtree_query_info {
  void *pContext;                   
  int nParam;                       
  sqlite3_rtree_dbl *aParam;        
  void *pUser;                      
  void (*xDelUser)(void*);          
  sqlite3_rtree_dbl *aCoord;        
  unsigned int *anQueue;            
  int nCoord;                       
  int iLevel;                       
  int mxLevel;                      
  sqlite3_int64 iRowid;             
  sqlite3_rtree_dbl rParentScore;   
  int eParentWithin;                
  int eWithin;                      
  sqlite3_rtree_dbl rScore;         
  
  sqlite3_value **apSqlParam;       
};

#define NOT_WITHIN       0   
#define PARTLY_WITHIN    1   
#define FULLY_WITHIN     2   

#ifdef __cplusplus
}  
#endif

#endif  

#if !defined(__SQLITESESSION_H_) && defined(SQLITE_ENABLE_SESSION)
#define __SQLITESESSION_H_ 1

#ifdef __cplusplus
extern "C" {
#endif

typedef struct sqlite3_session sqlite3_session;

typedef struct sqlite3_changeset_iter sqlite3_changeset_iter;

SQLITE_API int sqlite3session_create(
  sqlite3 *db,                    
  const char *zDb,                
  sqlite3_session **ppSession     
);

SQLITE_API void sqlite3session_delete(sqlite3_session *pSession);

SQLITE_API int sqlite3session_object_config(sqlite3_session*, int op, void *pArg);

#define SQLITE_SESSION_OBJCONFIG_SIZE  1
#define SQLITE_SESSION_OBJCONFIG_ROWID 2

SQLITE_API int sqlite3session_enable(sqlite3_session *pSession, int bEnable);

SQLITE_API int sqlite3session_indirect(sqlite3_session *pSession, int bIndirect);

SQLITE_API int sqlite3session_attach(
  sqlite3_session *pSession,      
  const char *zTab                
);

SQLITE_API void sqlite3session_table_filter(
  sqlite3_session *pSession,      
  int(*xFilter)(
    void *pCtx,                   
    const char *zTab              
  ),
  void *pCtx                      
);

SQLITE_API int sqlite3session_changeset(
  sqlite3_session *pSession,      
  int *pnChangeset,               
  void **ppChangeset              
);

SQLITE_API sqlite3_int64 sqlite3session_changeset_size(sqlite3_session *pSession);

SQLITE_API int sqlite3session_diff(
  sqlite3_session *pSession,
  const char *zFromDb,
  const char *zTbl,
  char **pzErrMsg
);

SQLITE_API int sqlite3session_patchset(
  sqlite3_session *pSession,      
  int *pnPatchset,                
  void **ppPatchset               
);

SQLITE_API int sqlite3session_isempty(sqlite3_session *pSession);

SQLITE_API sqlite3_int64 sqlite3session_memory_used(sqlite3_session *pSession);

SQLITE_API int sqlite3changeset_start(
  sqlite3_changeset_iter **pp,    
  int nChangeset,                 
  void *pChangeset                
);
SQLITE_API int sqlite3changeset_start_v2(
  sqlite3_changeset_iter **pp,    
  int nChangeset,                 
  void *pChangeset,               
  int flags                       
);

#define SQLITE_CHANGESETSTART_INVERT        0x0002

SQLITE_API int sqlite3changeset_next(sqlite3_changeset_iter *pIter);

SQLITE_API int sqlite3changeset_op(
  sqlite3_changeset_iter *pIter,  
  const char **pzTab,             
  int *pnCol,                     
  int *pOp,                       
  int *pbIndirect                 
);

SQLITE_API int sqlite3changeset_pk(
  sqlite3_changeset_iter *pIter,  
  unsigned char **pabPK,          
  int *pnCol                      
);

SQLITE_API int sqlite3changeset_old(
  sqlite3_changeset_iter *pIter,  
  int iVal,                       
  sqlite3_value **ppValue         
);

SQLITE_API int sqlite3changeset_new(
  sqlite3_changeset_iter *pIter,  
  int iVal,                       
  sqlite3_value **ppValue         
);

SQLITE_API int sqlite3changeset_conflict(
  sqlite3_changeset_iter *pIter,  
  int iVal,                       
  sqlite3_value **ppValue         
);

SQLITE_API int sqlite3changeset_fk_conflicts(
  sqlite3_changeset_iter *pIter,  
  int *pnOut                      
);

SQLITE_API int sqlite3changeset_finalize(sqlite3_changeset_iter *pIter);

SQLITE_API int sqlite3changeset_invert(
  int nIn, const void *pIn,       
  int *pnOut, void **ppOut        
);

SQLITE_API int sqlite3changeset_concat(
  int nA,                         
  void *pA,                       
  int nB,                         
  void *pB,                       
  int *pnOut,                     
  void **ppOut                    
);

typedef struct sqlite3_changegroup sqlite3_changegroup;

SQLITE_API int sqlite3changegroup_new(sqlite3_changegroup **pp);

SQLITE_API int sqlite3changegroup_schema(sqlite3_changegroup*, sqlite3*, const char *zDb);

SQLITE_API int sqlite3changegroup_add(sqlite3_changegroup*, int nData, void *pData);

SQLITE_API int sqlite3changegroup_add_change(
  sqlite3_changegroup*,
  sqlite3_changeset_iter*
);

SQLITE_API int sqlite3changegroup_output(
  sqlite3_changegroup*,
  int *pnData,                    
  void **ppData                   
);

SQLITE_API void sqlite3changegroup_delete(sqlite3_changegroup*);

SQLITE_API int sqlite3changeset_apply(
  sqlite3 *db,                    
  int nChangeset,                 
  void *pChangeset,               
  int(*xFilter)(
    void *pCtx,                   
    const char *zTab              
  ),
  int(*xConflict)(
    void *pCtx,                   
    int eConflict,                
    sqlite3_changeset_iter *p     
  ),
  void *pCtx                      
);
SQLITE_API int sqlite3changeset_apply_v2(
  sqlite3 *db,                    
  int nChangeset,                 
  void *pChangeset,               
  int(*xFilter)(
    void *pCtx,                   
    const char *zTab              
  ),
  int(*xConflict)(
    void *pCtx,                   
    int eConflict,                
    sqlite3_changeset_iter *p     
  ),
  void *pCtx,                     
  void **ppRebase, int *pnRebase, 
  int flags                       
);
SQLITE_API int sqlite3changeset_apply_v3(
  sqlite3 *db,                    
  int nChangeset,                 
  void *pChangeset,               
  int(*xFilter)(
    void *pCtx,                   
    sqlite3_changeset_iter *p     
  ),
  int(*xConflict)(
    void *pCtx,                   
    int eConflict,                
    sqlite3_changeset_iter *p     
  ),
  void *pCtx,                     
  void **ppRebase, int *pnRebase, 
  int flags                       
);

#define SQLITE_CHANGESETAPPLY_NOSAVEPOINT   0x0001
#define SQLITE_CHANGESETAPPLY_INVERT        0x0002
#define SQLITE_CHANGESETAPPLY_IGNORENOOP    0x0004
#define SQLITE_CHANGESETAPPLY_FKNOACTION    0x0008

#define SQLITE_CHANGESET_DATA        1
#define SQLITE_CHANGESET_NOTFOUND    2
#define SQLITE_CHANGESET_CONFLICT    3
#define SQLITE_CHANGESET_CONSTRAINT  4
#define SQLITE_CHANGESET_FOREIGN_KEY 5

#define SQLITE_CHANGESET_OMIT       0
#define SQLITE_CHANGESET_REPLACE    1
#define SQLITE_CHANGESET_ABORT      2

typedef struct sqlite3_rebaser sqlite3_rebaser;

SQLITE_API int sqlite3rebaser_create(sqlite3_rebaser **ppNew);

SQLITE_API int sqlite3rebaser_configure(
  sqlite3_rebaser*,
  int nRebase, const void *pRebase
);

SQLITE_API int sqlite3rebaser_rebase(
  sqlite3_rebaser*,
  int nIn, const void *pIn,
  int *pnOut, void **ppOut
);

SQLITE_API void sqlite3rebaser_delete(sqlite3_rebaser *p);

SQLITE_API int sqlite3changeset_apply_strm(
  sqlite3 *db,                    
  int (*xInput)(void *pIn, void *pData, int *pnData), 
  void *pIn,                                          
  int(*xFilter)(
    void *pCtx,                   
    const char *zTab              
  ),
  int(*xConflict)(
    void *pCtx,                   
    int eConflict,                
    sqlite3_changeset_iter *p     
  ),
  void *pCtx                      
);
SQLITE_API int sqlite3changeset_apply_v2_strm(
  sqlite3 *db,                    
  int (*xInput)(void *pIn, void *pData, int *pnData), 
  void *pIn,                                          
  int(*xFilter)(
    void *pCtx,                   
    const char *zTab              
  ),
  int(*xConflict)(
    void *pCtx,                   
    int eConflict,                
    sqlite3_changeset_iter *p     
  ),
  void *pCtx,                     
  void **ppRebase, int *pnRebase,
  int flags
);
SQLITE_API int sqlite3changeset_apply_v3_strm(
  sqlite3 *db,                    
  int (*xInput)(void *pIn, void *pData, int *pnData), 
  void *pIn,                                          
  int(*xFilter)(
    void *pCtx,                   
    sqlite3_changeset_iter *p
  ),
  int(*xConflict)(
    void *pCtx,                   
    int eConflict,                
    sqlite3_changeset_iter *p     
  ),
  void *pCtx,                     
  void **ppRebase, int *pnRebase,
  int flags
);
SQLITE_API int sqlite3changeset_concat_strm(
  int (*xInputA)(void *pIn, void *pData, int *pnData),
  void *pInA,
  int (*xInputB)(void *pIn, void *pData, int *pnData),
  void *pInB,
  int (*xOutput)(void *pOut, const void *pData, int nData),
  void *pOut
);
SQLITE_API int sqlite3changeset_invert_strm(
  int (*xInput)(void *pIn, void *pData, int *pnData),
  void *pIn,
  int (*xOutput)(void *pOut, const void *pData, int nData),
  void *pOut
);
SQLITE_API int sqlite3changeset_start_strm(
  sqlite3_changeset_iter **pp,
  int (*xInput)(void *pIn, void *pData, int *pnData),
  void *pIn
);
SQLITE_API int sqlite3changeset_start_v2_strm(
  sqlite3_changeset_iter **pp,
  int (*xInput)(void *pIn, void *pData, int *pnData),
  void *pIn,
  int flags
);
SQLITE_API int sqlite3session_changeset_strm(
  sqlite3_session *pSession,
  int (*xOutput)(void *pOut, const void *pData, int nData),
  void *pOut
);
SQLITE_API int sqlite3session_patchset_strm(
  sqlite3_session *pSession,
  int (*xOutput)(void *pOut, const void *pData, int nData),
  void *pOut
);
SQLITE_API int sqlite3changegroup_add_strm(sqlite3_changegroup*,
    int (*xInput)(void *pIn, void *pData, int *pnData),
    void *pIn
);
SQLITE_API int sqlite3changegroup_output_strm(sqlite3_changegroup*,
    int (*xOutput)(void *pOut, const void *pData, int nData),
    void *pOut
);
SQLITE_API int sqlite3rebaser_rebase_strm(
  sqlite3_rebaser *pRebaser,
  int (*xInput)(void *pIn, void *pData, int *pnData),
  void *pIn,
  int (*xOutput)(void *pOut, const void *pData, int nData),
  void *pOut
);

SQLITE_API int sqlite3session_config(int op, void *pArg);

#define SQLITE_SESSION_CONFIG_STRMSIZE 1

SQLITE_API int sqlite3changegroup_config(sqlite3_changegroup*, int, void *pArg);

#define SQLITE_CHANGEGROUP_CONFIG_PATCHSET 1

SQLITE_API int sqlite3changegroup_change_begin(
  sqlite3_changegroup*,
  int eOp,
  const char *zTab,
  int bIndirect,
  char **pzErr
);

SQLITE_API int sqlite3changegroup_change_int64(
  sqlite3_changegroup*,
  int bNew,
  int iCol,
  sqlite3_int64 iVal
);

SQLITE_API int sqlite3changegroup_change_null(sqlite3_changegroup*, int, int);

SQLITE_API int sqlite3changegroup_change_double(sqlite3_changegroup*, int, int, double);

SQLITE_API int sqlite3changegroup_change_text(
  sqlite3_changegroup*, int, int, const char *pVal, int nVal
);

SQLITE_API int sqlite3changegroup_change_blob(
    sqlite3_changegroup*, int, int, const void *pVal, int nVal
);

SQLITE_API int sqlite3changegroup_change_finish(
  sqlite3_changegroup*,
  int bDiscard,
  char **pzErr
);

#ifdef __cplusplus
}
#endif

#endif  

#ifndef _FTS5_H
#define _FTS5_H

#ifdef __cplusplus
extern "C" {
#endif

typedef struct Fts5ExtensionApi Fts5ExtensionApi;
typedef struct Fts5Context Fts5Context;
typedef struct Fts5PhraseIter Fts5PhraseIter;

typedef void (*fts5_extension_function)(
  const Fts5ExtensionApi *pApi,   
  Fts5Context *pFts,              
  sqlite3_context *pCtx,          
  int nVal,                       
  sqlite3_value **apVal           
);

struct Fts5PhraseIter {
  const unsigned char *a;
  const unsigned char *b;
};

struct Fts5ExtensionApi {
  int iVersion;                   

  void *(*xUserData)(Fts5Context*);

  int (*xColumnCount)(Fts5Context*);
  int (*xRowCount)(Fts5Context*, sqlite3_int64 *pnRow);
  int (*xColumnTotalSize)(Fts5Context*, int iCol, sqlite3_int64 *pnToken);

  int (*xTokenize)(Fts5Context*,
    const char *pText, int nText, 
    void *pCtx,                   
    int (*xToken)(void*, int, const char*, int, int, int)       
  );

  int (*xPhraseCount)(Fts5Context*);
  int (*xPhraseSize)(Fts5Context*, int iPhrase);

  int (*xInstCount)(Fts5Context*, int *pnInst);
  int (*xInst)(Fts5Context*, int iIdx, int *piPhrase, int *piCol, int *piOff);

  sqlite3_int64 (*xRowid)(Fts5Context*);
  int (*xColumnText)(Fts5Context*, int iCol, const char **pz, int *pn);
  int (*xColumnSize)(Fts5Context*, int iCol, int *pnToken);

  int (*xQueryPhrase)(Fts5Context*, int iPhrase, void *pUserData,
    int(*)(const Fts5ExtensionApi*,Fts5Context*,void*)
  );
  int (*xSetAuxdata)(Fts5Context*, void *pAux, void(*xDelete)(void*));
  void *(*xGetAuxdata)(Fts5Context*, int bClear);

  int (*xPhraseFirst)(Fts5Context*, int iPhrase, Fts5PhraseIter*, int*, int*);
  void (*xPhraseNext)(Fts5Context*, Fts5PhraseIter*, int *piCol, int *piOff);

  int (*xPhraseFirstColumn)(Fts5Context*, int iPhrase, Fts5PhraseIter*, int*);
  void (*xPhraseNextColumn)(Fts5Context*, Fts5PhraseIter*, int *piCol);

  
  int (*xQueryToken)(Fts5Context*,
      int iPhrase, int iToken,
      const char **ppToken, int *pnToken
  );
  int (*xInstToken)(Fts5Context*, int iIdx, int iToken, const char**, int*);

  
  int (*xColumnLocale)(Fts5Context*, int iCol, const char **pz, int *pn);
  int (*xTokenize_v2)(Fts5Context*,
    const char *pText, int nText,      
    const char *pLocale, int nLocale,  
    void *pCtx,                        
    int (*xToken)(void*, int, const char*, int, int, int)       
  );
};

typedef struct Fts5Tokenizer Fts5Tokenizer;
typedef struct fts5_tokenizer_v2 fts5_tokenizer_v2;
struct fts5_tokenizer_v2 {
  int iVersion;             

  int (*xCreate)(void*, const char **azArg, int nArg, Fts5Tokenizer **ppOut);
  void (*xDelete)(Fts5Tokenizer*);
  int (*xTokenize)(Fts5Tokenizer*,
      void *pCtx,
      int flags,            
      const char *pText, int nText,
      const char *pLocale, int nLocale,
      int (*xToken)(
        void *pCtx,         
        int tflags,         
        const char *pToken, 
        int nToken,         
        int iStart,         
        int iEnd            
      )
  );
};

typedef struct fts5_tokenizer fts5_tokenizer;
struct fts5_tokenizer {
  int (*xCreate)(void*, const char **azArg, int nArg, Fts5Tokenizer **ppOut);
  void (*xDelete)(Fts5Tokenizer*);
  int (*xTokenize)(Fts5Tokenizer*,
      void *pCtx,
      int flags,            
      const char *pText, int nText,
      int (*xToken)(
        void *pCtx,         
        int tflags,         
        const char *pToken, 
        int nToken,         
        int iStart,         
        int iEnd            
      )
  );
};

#define FTS5_TOKENIZE_QUERY     0x0001
#define FTS5_TOKENIZE_PREFIX    0x0002
#define FTS5_TOKENIZE_DOCUMENT  0x0004
#define FTS5_TOKENIZE_AUX       0x0008

#define FTS5_TOKEN_COLOCATED    0x0001      

typedef struct fts5_api fts5_api;
struct fts5_api {
  int iVersion;                   

  
  int (*xCreateTokenizer)(
    fts5_api *pApi,
    const char *zName,
    void *pUserData,
    fts5_tokenizer *pTokenizer,
    void (*xDestroy)(void*)
  );

  
  int (*xFindTokenizer)(
    fts5_api *pApi,
    const char *zName,
    void **ppUserData,
    fts5_tokenizer *pTokenizer
  );

  
  int (*xCreateFunction)(
    fts5_api *pApi,
    const char *zName,
    void *pUserData,
    fts5_extension_function xFunction,
    void (*xDestroy)(void*)
  );

  

  
  int (*xCreateTokenizer_v2)(
    fts5_api *pApi,
    const char *zName,
    void *pUserData,
    fts5_tokenizer_v2 *pTokenizer,
    void (*xDestroy)(void*)
  );

  
  int (*xFindTokenizer_v2)(
    fts5_api *pApi,
    const char *zName,
    void **ppUserData,
    fts5_tokenizer_v2 **ppTokenizer
  );
};

#ifdef __cplusplus
}  
#endif

#endif 

#endif 


#ifndef cJSON__h
#define cJSON__h

#ifdef __cplusplus
extern "C"
{
#endif

#if !defined(__WINDOWS__) && (defined(WIN32) || defined(WIN64) || defined(_MSC_VER) || defined(_WIN32))
#define __WINDOWS__
#endif

#ifdef __WINDOWS__

#define CJSON_CDECL __cdecl
#define CJSON_STDCALL __stdcall

#if !defined(CJSON_HIDE_SYMBOLS) && !defined(CJSON_IMPORT_SYMBOLS) && !defined(CJSON_EXPORT_SYMBOLS)
#define CJSON_EXPORT_SYMBOLS
#endif

#if defined(CJSON_HIDE_SYMBOLS)
#define CJSON_PUBLIC(type)   type CJSON_STDCALL
#elif defined(CJSON_EXPORT_SYMBOLS)
#define CJSON_PUBLIC(type)   __declspec(dllexport) type CJSON_STDCALL
#elif defined(CJSON_IMPORT_SYMBOLS)
#define CJSON_PUBLIC(type)   __declspec(dllimport) type CJSON_STDCALL
#endif
#else 
#define CJSON_CDECL
#define CJSON_STDCALL

#if (defined(__GNUC__) || defined(__SUNPRO_CC) || defined (__SUNPRO_C)) && defined(CJSON_API_VISIBILITY)
#define CJSON_PUBLIC(type)   __attribute__((visibility("default"))) type
#else
#define CJSON_PUBLIC(type) type
#endif
#endif

#define CJSON_VERSION_MAJOR 1
#define CJSON_VERSION_MINOR 7
#define CJSON_VERSION_PATCH 19

#include <stddef.h>

#define cJSON_Invalid (0)
#define cJSON_False  (1 << 0)
#define cJSON_True   (1 << 1)
#define cJSON_NULL   (1 << 2)
#define cJSON_Number (1 << 3)
#define cJSON_String (1 << 4)
#define cJSON_Array  (1 << 5)
#define cJSON_Object (1 << 6)
#define cJSON_Raw    (1 << 7) 

#define cJSON_IsReference 256
#define cJSON_StringIsConst 512

typedef struct cJSON
{
    
    struct cJSON *next;
    struct cJSON *prev;
    
    struct cJSON *child;

    
    int type;

    
    char *valuestring;
    
    int valueint;
    
    double valuedouble;

    
    char *string;
} cJSON;

typedef struct cJSON_Hooks
{
      
      void *(CJSON_CDECL *malloc_fn)(size_t sz);
      void (CJSON_CDECL *free_fn)(void *ptr);
} cJSON_Hooks;

typedef int cJSON_bool;

#ifndef CJSON_NESTING_LIMIT
#define CJSON_NESTING_LIMIT 1000
#endif

#ifndef CJSON_CIRCULAR_LIMIT
#define CJSON_CIRCULAR_LIMIT 10000
#endif

CJSON_PUBLIC(const char*) cJSON_Version(void);

CJSON_PUBLIC(void) cJSON_InitHooks(cJSON_Hooks* hooks);

CJSON_PUBLIC(cJSON *) cJSON_Parse(const char *value);
CJSON_PUBLIC(cJSON *) cJSON_ParseWithLength(const char *value, size_t buffer_length);

CJSON_PUBLIC(cJSON *) cJSON_ParseWithOpts(const char *value, const char **return_parse_end, cJSON_bool require_null_terminated);
CJSON_PUBLIC(cJSON *) cJSON_ParseWithLengthOpts(const char *value, size_t buffer_length, const char **return_parse_end, cJSON_bool require_null_terminated);

CJSON_PUBLIC(char *) cJSON_Print(const cJSON *item);

CJSON_PUBLIC(char *) cJSON_PrintUnformatted(const cJSON *item);

CJSON_PUBLIC(char *) cJSON_PrintBuffered(const cJSON *item, int prebuffer, cJSON_bool fmt);

CJSON_PUBLIC(cJSON_bool) cJSON_PrintPreallocated(cJSON *item, char *buffer, const int length, const cJSON_bool format);

CJSON_PUBLIC(void) cJSON_Delete(cJSON *item);

CJSON_PUBLIC(int) cJSON_GetArraySize(const cJSON *array);

CJSON_PUBLIC(cJSON *) cJSON_GetArrayItem(const cJSON *array, int index);

CJSON_PUBLIC(cJSON *) cJSON_GetObjectItem(const cJSON * const object, const char * const string);
CJSON_PUBLIC(cJSON *) cJSON_GetObjectItemCaseSensitive(const cJSON * const object, const char * const string);
CJSON_PUBLIC(cJSON_bool) cJSON_HasObjectItem(const cJSON *object, const char *string);

CJSON_PUBLIC(const char *) cJSON_GetErrorPtr(void);

CJSON_PUBLIC(char *) cJSON_GetStringValue(const cJSON * const item);
CJSON_PUBLIC(double) cJSON_GetNumberValue(const cJSON * const item);

CJSON_PUBLIC(cJSON_bool) cJSON_IsInvalid(const cJSON * const item);
CJSON_PUBLIC(cJSON_bool) cJSON_IsFalse(const cJSON * const item);
CJSON_PUBLIC(cJSON_bool) cJSON_IsTrue(const cJSON * const item);
CJSON_PUBLIC(cJSON_bool) cJSON_IsBool(const cJSON * const item);
CJSON_PUBLIC(cJSON_bool) cJSON_IsNull(const cJSON * const item);
CJSON_PUBLIC(cJSON_bool) cJSON_IsNumber(const cJSON * const item);
CJSON_PUBLIC(cJSON_bool) cJSON_IsString(const cJSON * const item);
CJSON_PUBLIC(cJSON_bool) cJSON_IsArray(const cJSON * const item);
CJSON_PUBLIC(cJSON_bool) cJSON_IsObject(const cJSON * const item);
CJSON_PUBLIC(cJSON_bool) cJSON_IsRaw(const cJSON * const item);

CJSON_PUBLIC(cJSON *) cJSON_CreateNull(void);
CJSON_PUBLIC(cJSON *) cJSON_CreateTrue(void);
CJSON_PUBLIC(cJSON *) cJSON_CreateFalse(void);
CJSON_PUBLIC(cJSON *) cJSON_CreateBool(cJSON_bool boolean);
CJSON_PUBLIC(cJSON *) cJSON_CreateNumber(double num);
CJSON_PUBLIC(cJSON *) cJSON_CreateString(const char *string);

CJSON_PUBLIC(cJSON *) cJSON_CreateRaw(const char *raw);
CJSON_PUBLIC(cJSON *) cJSON_CreateArray(void);
CJSON_PUBLIC(cJSON *) cJSON_CreateObject(void);

CJSON_PUBLIC(cJSON *) cJSON_CreateStringReference(const char *string);

CJSON_PUBLIC(cJSON *) cJSON_CreateObjectReference(const cJSON *child);
CJSON_PUBLIC(cJSON *) cJSON_CreateArrayReference(const cJSON *child);

CJSON_PUBLIC(cJSON *) cJSON_CreateIntArray(const int *numbers, int count);
CJSON_PUBLIC(cJSON *) cJSON_CreateFloatArray(const float *numbers, int count);
CJSON_PUBLIC(cJSON *) cJSON_CreateDoubleArray(const double *numbers, int count);
CJSON_PUBLIC(cJSON *) cJSON_CreateStringArray(const char *const *strings, int count);

CJSON_PUBLIC(cJSON_bool) cJSON_AddItemToArray(cJSON *array, cJSON *item);
CJSON_PUBLIC(cJSON_bool) cJSON_AddItemToObject(cJSON *object, const char *string, cJSON *item);

CJSON_PUBLIC(cJSON_bool) cJSON_AddItemToObjectCS(cJSON *object, const char *string, cJSON *item);

CJSON_PUBLIC(cJSON_bool) cJSON_AddItemReferenceToArray(cJSON *array, cJSON *item);
CJSON_PUBLIC(cJSON_bool) cJSON_AddItemReferenceToObject(cJSON *object, const char *string, cJSON *item);

CJSON_PUBLIC(cJSON *) cJSON_DetachItemViaPointer(cJSON *parent, cJSON * const item);
CJSON_PUBLIC(cJSON *) cJSON_DetachItemFromArray(cJSON *array, int which);
CJSON_PUBLIC(void) cJSON_DeleteItemFromArray(cJSON *array, int which);
CJSON_PUBLIC(cJSON *) cJSON_DetachItemFromObject(cJSON *object, const char *string);
CJSON_PUBLIC(cJSON *) cJSON_DetachItemFromObjectCaseSensitive(cJSON *object, const char *string);
CJSON_PUBLIC(void) cJSON_DeleteItemFromObject(cJSON *object, const char *string);
CJSON_PUBLIC(void) cJSON_DeleteItemFromObjectCaseSensitive(cJSON *object, const char *string);

CJSON_PUBLIC(cJSON_bool) cJSON_InsertItemInArray(cJSON *array, int which, cJSON *newitem); 
CJSON_PUBLIC(cJSON_bool) cJSON_ReplaceItemViaPointer(cJSON * const parent, cJSON * const item, cJSON * replacement);
CJSON_PUBLIC(cJSON_bool) cJSON_ReplaceItemInArray(cJSON *array, int which, cJSON *newitem);
CJSON_PUBLIC(cJSON_bool) cJSON_ReplaceItemInObject(cJSON *object,const char *string,cJSON *newitem);
CJSON_PUBLIC(cJSON_bool) cJSON_ReplaceItemInObjectCaseSensitive(cJSON *object,const char *string,cJSON *newitem);

CJSON_PUBLIC(cJSON *) cJSON_Duplicate(const cJSON *item, cJSON_bool recurse);

CJSON_PUBLIC(cJSON_bool) cJSON_Compare(const cJSON * const a, const cJSON * const b, const cJSON_bool case_sensitive);

CJSON_PUBLIC(void) cJSON_Minify(char *json);

CJSON_PUBLIC(cJSON*) cJSON_AddNullToObject(cJSON * const object, const char * const name);
CJSON_PUBLIC(cJSON*) cJSON_AddTrueToObject(cJSON * const object, const char * const name);
CJSON_PUBLIC(cJSON*) cJSON_AddFalseToObject(cJSON * const object, const char * const name);
CJSON_PUBLIC(cJSON*) cJSON_AddBoolToObject(cJSON * const object, const char * const name, const cJSON_bool boolean);
CJSON_PUBLIC(cJSON*) cJSON_AddNumberToObject(cJSON * const object, const char * const name, const double number);
CJSON_PUBLIC(cJSON*) cJSON_AddStringToObject(cJSON * const object, const char * const name, const char * const string);
CJSON_PUBLIC(cJSON*) cJSON_AddRawToObject(cJSON * const object, const char * const name, const char * const raw);
CJSON_PUBLIC(cJSON*) cJSON_AddObjectToObject(cJSON * const object, const char * const name);
CJSON_PUBLIC(cJSON*) cJSON_AddArrayToObject(cJSON * const object, const char * const name);

#define cJSON_SetIntValue(object, number) ((object) ? (object)->valueint = (object)->valuedouble = (number) : (number))

CJSON_PUBLIC(double) cJSON_SetNumberHelper(cJSON *object, double number);
#define cJSON_SetNumberValue(object, number) ((object != NULL) ? cJSON_SetNumberHelper(object, (double)number) : (number))

CJSON_PUBLIC(char*) cJSON_SetValuestring(cJSON *object, const char *valuestring);

#define cJSON_SetBoolValue(object, boolValue) ( \
    (object != NULL && ((object)->type & (cJSON_False|cJSON_True))) ? \
    (object)->type=((object)->type &(~(cJSON_False|cJSON_True)))|((boolValue)?cJSON_True:cJSON_False) : \
    cJSON_Invalid\
)

#define cJSON_ArrayForEach(element, array) for(element = (array != NULL) ? (array)->child : NULL; element != NULL; element = element->next)

CJSON_PUBLIC(void *) cJSON_malloc(size_t size);
CJSON_PUBLIC(void) cJSON_free(void *object);

#ifdef __cplusplus
}
#endif

#endif

#ifdef __cplusplus
extern "C" {
#endif

/* -- App lifecycle -- */
typedef void (*frame_callback_t)(void);
int init_app(void);
void run_app(void);
void run_app_frame(frame_callback_t on_frame);
void quit_app(void);
HWND create_window(const WCHAR *title, int width, int height);
HWND create_hidden_window(int w, int h);
void show_window(HWND win);
void on_window_close(HWND win, int (*callback)(void *), void *data);
void on_window_resize(HWND win, void (*callback)(int w, int h));
void on_mouse_wheel(HWND hwnd, void (*callback)(int delta, void *userdata), void *userdata);
void off_mouse_wheel(HWND hwnd);

/* -- Controls & dialogs -- */
HWND create_button(HWND parent, const WCHAR *text, int x, int y, int w, int h);
void on_button_click(HWND btn, void (*callback)(void *), void *data);

HWND create_label(HWND parent, const WCHAR *text, int x, int y, int w, int h);

HWND create_text(HWND parent, const WCHAR *text, int x, int y, int w, int h);
HWND create_textarea(HWND parent, const WCHAR *text, int x, int y, int w, int h);
HWND create_password(HWND parent, int x, int y, int w, int h);
void set_readonly(HWND hwnd, int readonly);
void set_enable(HWND hwnd, int enable);

HWND create_checkbox(HWND parent, const WCHAR *text, int x, int y, int w, int h);
HWND create_radio(HWND parent, const WCHAR *text, int x, int y, int w, int h);
HWND create_groupbox(HWND parent, const WCHAR *text, int x, int y, int w, int h);
int is_checked(HWND hwnd);
void set_checked(HWND hwnd, int checked);

HWND create_combobox(HWND parent, int x, int y, int w, int h);
void combobox_add_text(HWND combobox, const WCHAR *text);
int combobox_selected_index(HWND combobox);
const WCHAR *combobox_selected_text(HWND combobox);

HWND create_listbox(HWND parent, int x, int y, int w, int h);
void listbox_add_text(HWND listbox, const WCHAR *text);
int listbox_selected_index(HWND listbox);
int listbox_count(HWND listbox);
const WCHAR *listbox_selected_text(HWND listbox);

HWND create_progressbar(HWND parent, int x, int y, int w, int h);
void set_progress(HWND progress, int value);

HWND create_slider(HWND parent, int x, int y, int w, int h);
int slider_get_pos(HWND slider);
void slider_set_pos(HWND slider, int value);

HWND create_scrollbar(HWND parent, int x, int y, int w, int h);
int scrollbar_get_pos(HWND scrollbar);
void scrollbar_set_pos(HWND scrollbar, int pos);

HWND create_spin(HWND parent, int x, int y, int w, int h);
void spin_set_range(HWND spin, int min, int max);
int spin_get_pos(HWND spin);

HWND create_statusbar(HWND parent);
void statusbar_set_text(HWND statusbar, const WCHAR *text);

HWND create_toolbar(HWND parent);
void toolbar_add_button(HWND toolbar, const WCHAR *text);

HWND create_treeview(HWND parent, int x, int y, int w, int h);
HWND treeview_add_text(HWND treeview, const WCHAR *text);
HWND treeview_add_child(HWND treeview, HWND parent_item, const WCHAR *text);
HWND treeview_selected(HWND treeview);
const WCHAR *treeview_selected_text(HWND treeview);
void treeview_delete(HWND treeview, HWND item);
void treeview_set_text(HWND treeview, HWND item, const WCHAR *text);
void treeview_expand(HWND treeview, HWND item);
void treeview_collapse(HWND treeview, HWND item);

HWND create_listview(HWND parent, int x, int y, int w, int h);
void listview_add_column(HWND listview, const WCHAR *text, int width);
HWND listview_add_text(HWND listview, const WCHAR *text);
void listview_set_text(HWND listview, int row, int col, const WCHAR *text);
int listview_count(HWND listview);
int listview_selected_index(HWND listview);
void on_listview_dblclick(HWND listview, void (*callback)(void *), void *data);
void listview_delete_all(HWND listview);
void listview_get_text(HWND listview, int row, int col, WCHAR *buf, int size);

HWND create_tabbar(HWND parent, int x, int y, int w, int h);
void tabbar_add_text(HWND tabbar, const WCHAR *text);
int tabbar_selected_index(HWND tabbar);
void on_tabbar_select(HWND tabbar, void (*callback)(void *), void *data);

HWND create_datepicker(HWND parent, int x, int y, int w, int h);

HWND create_ip_input(HWND parent, int x, int y, int w, int h);
void get_ip(HWND ip_input, int ip[4]);
void set_ip(HWND ip_input, int a, int b, int c, int d);

HWND create_animation(HWND parent, int x, int y, int w, int h);
void play_animation(HWND anim, int res_id);

HWND create_richedit(HWND parent, int x, int y, int w, int h);

int open_file_dialog(HWND parent, WCHAR *buf, int size, const WCHAR *filter);
int save_file_dialog(HWND parent, WCHAR *buf, int size, const WCHAR *filter);
int browse_folder_dialog(HWND parent, WCHAR *buf, int size);

void set_text(HWND hwnd, const WCHAR *text);
const WCHAR *get_text(HWND hwnd);

void alert(const WCHAR *title, const WCHAR *message);
int confirm(const WCHAR *title, const WCHAR *message);
int ask(const WCHAR *title, const WCHAR *message);

void show(HWND hwnd);
void hide(HWND hwnd);
int  is_visible(HWND hwnd);
void move(HWND hwnd, int x, int y);
void set_size(HWND hwnd, int w, int h);
void get_size(HWND hwnd, int *w, int *h);
LONG_PTR get_style(HWND hwnd);
void set_style(HWND hwnd, LONG_PTR style);
LONG_PTR get_attr(HWND hwnd);
void set_attr(HWND hwnd, LONG_PTR attr);

/* -- Menu -- */
HMENU create_main_menu(HWND win);
HMENU add_main_menu(HMENU main, const WCHAR *text);
int add_menu_item(HMENU popup, const WCHAR *text);
void add_menu_separator(HMENU popup);
HMENU add_sub_menu(HMENU parent, const WCHAR *text);
void set_menu_checked(int id, int checked);
void set_menu_enabled(int id, int enabled);
void on_menu_click(int id, void (*callback)(void *), void *data);
int create_sys_menu(HWND win, const WCHAR *text);
void add_sys_separator(HWND win);
HMENU create_context_menu(void);
void show_context_menu(HMENU menu, HWND parent, int x, int y);
void set_menu_shortcut(int id, BYTE vkey, int ctrl, int shift);

/* -- Sound -- */
int play_sound(const WCHAR *filepath);
int play_sound_loop(const WCHAR *filepath);
int stop_sound(void);
int play_beep(int freq, int duration);

/* -- Utilities -- */
const WCHAR *itow(int value);
const WCHAR *ftow(double value);
void str_concat(WCHAR *dest, int size, ...);
void str_format(WCHAR *buf, int size, const WCHAR *fmt, ...);
void str_format_a(char *buf, int size, const char *fmt, ...);
int rand_int(int min, int max);

char *wtou8(const WCHAR *ws);
WCHAR *u8tow(const char *us);

int read_text_file(const WCHAR *filepath, WCHAR *buf, int size);
int write_text_file(const WCHAR *filepath, const WCHAR *text);
int read_bin_file(const WCHAR *filepath, void *buf, int elem_size, int max_count);
int write_bin_file(const WCHAR *filepath, void *buf, int elem_size, int count);

void clipboard_copy(const WCHAR *text);

/* ── Base64 ── */
int base64_decode(const char *in, int in_len, unsigned char *out);

/* ── File I/O ── */
unsigned char *read_bin_file_alloc(const char *path, int *out_len);

void log_info(const WCHAR *text);
void log_warning(const WCHAR *text);
void log_error(const WCHAR *title);
void log_clear(void);

/* ── Process ── */
HANDLE run_process(const WCHAR *exe_path, const WCHAR *cmdline, int show);
int    kill_process(HANDLE proc);
int    kill_process_pid(DWORD pid);
int    wait_process(HANDLE proc);

/* ── System Info ── */
typedef struct {
    WCHAR computer_name[64];
    WCHAR user_name[64];
    WCHAR os_version[64];
    int   cpu_cores;
    WCHAR cpu_name[128];
    unsigned long long mem_total_mb;
    unsigned long long mem_avail_mb;
    WCHAR windows_dir[MAX_PATH];
} sys_info_t;

int get_sys_info(sys_info_t *info);

/* ── Registry ── */
int reg_read_str(HKEY root, const WCHAR *key, const WCHAR *value, WCHAR *buf, int size);
int reg_read_dword(HKEY root, const WCHAR *key, const WCHAR *value, DWORD *out);
int reg_write_str(HKEY root, const WCHAR *key, const WCHAR *value, const WCHAR *data);
int reg_write_dword(HKEY root, const WCHAR *key, const WCHAR *value, DWORD data);
int reg_delete_value(HKEY root, const WCHAR *key, const WCHAR *value);

/* ── Process Enumeration ── */
typedef struct {
    DWORD pid;
    WCHAR name[260];
} process_entry_t;

int enum_processes(process_entry_t **out, int *count);

/* ── Environment ── */
int get_env(const WCHAR *name, WCHAR *buf, int size);
int set_env(const WCHAR *name, const WCHAR *value);

/* ── Special Folders ── */
#define FOLDER_DESKTOP      0
#define FOLDER_DOCUMENTS    1
#define FOLDER_DOWNLOADS    2
#define FOLDER_PICTURES     3
#define FOLDER_MUSIC        4
#define FOLDER_VIDEOS       5
#define FOLDER_APPDATA      6
#define FOLDER_LOCALAPPDATA 7
#define FOLDER_PROGRAMFILES 8
#define FOLDER_STARTUP      9

int get_special_folder(int folder_id, WCHAR *buf, int size);

/* -- Image & Icon -- */
void *load_image_from_file(const WCHAR *filepath, int *width, int *height);
HWND create_image(HWND parent, const WCHAR *filepath, int x, int y, int w, int h);
void set_image(HWND img, const WCHAR *filepath);
HWND create_icon(HWND parent, const WCHAR *filepath, int x, int y, int w, int h);

/* -- Canvas & Sprite -- */
typedef struct Sprite Sprite;
HWND create_canvas(HWND parent, int x, int y, int w, int h);
void canvas_clear(HWND canvas, int r, int g, int b, int a);
void canvas_set_pen(HWND canvas, int r, int g, int b, int a, int width);
void canvas_set_brush(HWND canvas, int r, int g, int b, int a);
void canvas_set_font(HWND canvas, const WCHAR *family, int size);
void canvas_draw_line(HWND canvas, int x1, int y1, int x2, int y2);
void canvas_draw_rect(HWND canvas, int x, int y, int w, int h);
void canvas_fill_rect(HWND canvas, int x, int y, int w, int h);
void canvas_draw_ellipse(HWND canvas, int x, int y, int w, int h);
void canvas_fill_ellipse(HWND canvas, int x, int y, int w, int h);
void canvas_fill_polygon(HWND canvas, const PointF *pts, int count);
void canvas_fill_pie(HWND canvas, int x, int y, int w, int h, float start_angle, float sweep_angle);
void canvas_draw_arc(HWND canvas, int x, int y, int w, int h, float start_angle, float sweep_angle);
void canvas_draw_bezier(HWND canvas, int x1, int y1, int x2, int y2, int x3, int y3, int x4, int y4);
void canvas_draw_path(HWND canvas, void *path);
void canvas_fill_path(HWND canvas, void *path);
void *canvas_create_path(void);
void canvas_add_path_line(void *path, float x1, float y1, float x2, float y2);
void canvas_add_path_arc(void *path, float x, float y, float w, float h, float start_angle, float sweep_angle);
void canvas_add_path_ellipse(void *path, float x, float y, float w, float h);
void canvas_add_path_rect(void *path, float x, float y, float w, float h);
void canvas_close_path(void *path);
void canvas_delete_path(void *path);
void canvas_draw_text(HWND canvas, const WCHAR *text, int x, int y, int r, int g, int b, int a, int size);
void canvas_draw_image(HWND canvas, void *image, int x, int y, int w, int h);
void canvas_save_image(HWND canvas, const WCHAR *filepath);

void canvas_start_timer(HWND canvas, int fps, void (*callback)(void *), void *data);
void canvas_stop_timer(HWND canvas);
int canvas_is_key_down(HWND canvas, int vkey);
void canvas_on_key(HWND canvas, void (*down)(int), void (*up)(int));
void canvas_on_mouse(HWND canvas, void (*move)(int, int), void (*down)(int, int, int), void (*up)(int, int, int));
int canvas_get_mouse_x(HWND canvas);
int canvas_get_mouse_y(HWND canvas);
int canvas_is_mouse_down(HWND canvas, int btn);
int canvas_get_width(HWND canvas);
int canvas_get_height(HWND canvas);
void canvas_clear_rect(HWND canvas, int x, int y, int w, int h, int r, int g, int b, int a);

/* ── Sprite shape types ── */
#define SHAPE_RECT      0   /* 矩形 */
#define SHAPE_ELLIPSE   1   /* 椭圆/圆 */
#define SHAPE_TRIANGLE  2   /* 三角形（朝上） */
#define SHAPE_DIAMOND   3   /* 菱形 */
#define SHAPE_PENTAGON  4   /* 正五边形 */
#define SHAPE_HEXAGON   5   /* 正六边形 */
#define SHAPE_STAR      6   /* 五角星 */
#define SHAPE_ARROW     7   /* 箭头（朝右） */
#define SHAPE_PIE       8   /* 扇形（缺右上角） */

typedef struct SpriteEvent
{
    Sprite *sprite;
    void (*click)(Sprite *, void *);
    void (*down)(Sprite *, void *);
    void (*up)(Sprite *, void *);
    void (*hover)(Sprite *, void *);
    void *data;
    void *ctx;
} SpriteEvent;

struct Sprite
{
    float x, y;
    float w, h;
    float ox, oy;
    float sx, sy;
    float rotation;
    int visible;
    int r, g, b, a;
    void *image;
    void *origin_image;
    int refs;
    int is_owner;
    int shape_type;
    void *canvas;
};

Sprite *sprite_create_from_shape(int type, int w, int h);
Sprite *sprite_create_from_file(const WCHAR *filepath);
Sprite *sprite_create_from_image(void *image);
void sprite_destroy(Sprite *s);
void sprite_set_pos(Sprite *s, float x, float y);
float sprite_get_x(Sprite *s);
float sprite_get_y(Sprite *s);
float sprite_get_w(Sprite *s);
float sprite_get_h(Sprite *s);
float sprite_get_sx(Sprite *s);
float sprite_get_sy(Sprite *s);
void sprite_move(Sprite *s, float dx, float dy);
void sprite_set_scale(Sprite *s, float sx, float sy);
void sprite_set_rotation(Sprite *s, float degrees);
void sprite_set_color(Sprite *s, int r, int g, int b, int a);
void sprite_set_image(Sprite *s, void *image);
Sprite *sprite_clone(Sprite *s);
void sprite_draw(HWND canvas, Sprite *s);
int sprite_collide(Sprite *a, Sprite *b);
int sprite_hit_test(Sprite *s, float px, float py);

void on_sprite_click(HWND canvas, Sprite *s, void (*cb)(Sprite *, void *), void *data);
void on_sprite_down(HWND canvas, Sprite *s, void (*cb)(Sprite *, void *), void *data);
void on_sprite_up(HWND canvas, Sprite *s, void (*cb)(Sprite *, void *), void *data);
void on_sprite_hover(HWND canvas, Sprite *s, void (*cb)(Sprite *, void *), void *data);

/* -- JSON -- */
typedef struct cJSON json_t;

json_t*  json_parse(const char *utf8);
void     json_free(json_t *obj);

int      json_get_int(json_t *obj, const char *key);
double   json_get_double(json_t *obj, const char *key);
const char* json_get_str(json_t *obj, const char *key);
json_t*  json_get_obj(json_t *obj, const char *key);
json_t*  json_get_arr(json_t *obj, const char *key);

int      json_arr_size(json_t *arr);
json_t*  json_arr_get(json_t *arr, int index);

json_t*  json_create_obj(void);
json_t*  json_create_arr(void);
json_t*  json_create_str(const char *val);
json_t*  json_create_num(double val);
void     json_add_int(json_t *obj, const char *key, int val);
void     json_add_double(json_t *obj, const char *key, double val);
void     json_add_str(json_t *obj, const char *key, const char *val);
void     json_add_obj(json_t *obj, const char *key, json_t *val);
void     json_add_arr(json_t *obj, const char *key, json_t *val);
void     json_arr_add(json_t *arr, json_t *item);

char*    json_to_str(json_t *root);
char*    json_to_str_min(json_t *root);

/* -- i18n -- */
void i18n_init(const WCHAR *json_path);
void i18n_set_lang(const char *lang);
const WCHAR *i18n_get_str(const char *id);

/* -- D3D11 PBR 3D -- */
/* ── 数学常量 ── */
#define DX_PI  3.1415926535f
#define DX_TAU 6.2831853071f   /* 2*PI */

/* ── 矩阵（ROW-MAJOR 存储，与 D3DMATRIX / row_major float4x4 一致） ──
 *   m[row*4+col] — 例如 m[0]=_11, m[1]=_12, m[4]=_21, m[12]=_41  */
typedef struct { float m[16]; } dx_mat4;

/* ── 顶点格式：位置 + 法线 + UV + 顶点色 + 蒙皮权重/索引（68B） ── */
typedef struct {
    float x, y, z;          /* 位置      0-11  */
    float nx, ny, nz;       /* 法线      12-23 */
    float u, v;             /* UV        24-31 */
    float r, g, b, a;       /* 颜色      32-47 */
    float weights[4];       /* 关节权重  48-63 */
    unsigned char joints[4];/* 关节索引  64-67 */
} dx_vertex;

/* ── 蒙皮数据 ── */
typedef struct {
    int joint_count;
    int *joint_indices;     /* 关节对应的 mesh 节点索引 */
    dx_mat4 *ibms;          /* 逆绑定矩阵 inverseBindMatrices */
    dx_mat4 *joint_matrices;/* 关节世界矩阵（每帧计算） */
    dx_mat4 *skin_matrices; /* skin = joint * ibm（上传 GPU） */
} dx_skin;

/* ── 动画采样器（关键帧插值） ── */
typedef struct {
    float *times;
    float *values;
    int keyframe_count;
    int comps;              /* 分量数：1/3/4 */
    int interpolation;      /* 0=LINEAR 1=STEP 2=CUBICSPLINE */
} dx_anim_sampler;

/* ── 动画通道（目标节点 + 路径） ── */
typedef struct {
    int target_node;        /* 作用节点索引 */
    int target_path;        /* 0=translation 1=rotation 2=scale 3=weights */
    int sampler;
} dx_anim_channel;

/* ── 动画 ── */
typedef struct {
    char name[64];
    float duration;
    dx_anim_channel *channels;
    int channel_count;
    dx_anim_sampler *samplers;
    int sampler_count;
    float time;             /* 当前播放时间 */
    int loop;
} dx_animation;

/* ── 几何体（顶点/索引数据） ── */
typedef struct {
    void *vb;       /* ID3D11Buffer* 顶点缓冲 */
    void *ib;       /* ID3D11Buffer* 索引缓冲 */
    int icount;     /* 索引数量 */
} dx_geometry;

/* ── 纹理（不透明） ── */
typedef struct dx_texture_t dx_texture;

/* ── 材质（公开结构体，可直接读写字段） ── */
typedef struct {
    float color[4];      /* 基础色（与顶点色×纹理相乘） */
    dx_texture *texture; /* 纹理（可 NULL） */
    float roughness;     /* 粗糙度 0~1 */
    float metalness;     /* 金属度 0~1 */
    int unlit;           /* 无光照模式 */
} dx_material;

/* ── 网格 = 几何体 + 材质 + 变换 + 子节点（层次结构） ── */
typedef struct dx_mesh_s {
    dx_geometry *geometry;  /* 顶点数据（叶节点有，容器节点 NULL） */
    dx_material *material;  /* 材质（可 NULL） */
    float position[3];      /* 平移（局部坐标，相对于父节点） */
    float rotation[3];      /* 旋转（XYZ 欧拉角，弧度，局部） */
    float scale[3];         /* 缩放（局部） */
    int child_count;        /* 子节点数量 */
    struct dx_mesh_s **children;  /* 子节点数组 */
    /* 内部：释放时是否释放 geometry / material（glTF 加载器设置） */
    int owns_geometry;
    int owns_material;
    dx_skin *skin;          /* 蒙皮数据（可 NULL，非蒙皮时用默认权重） */
    dx_animation *anim;     /* 当前播放的动画（可 NULL） */
    int node_index;         /* 节点在树中的索引（用于皮肤关节查找） */
} dx_mesh;

/* ── 生命周期 ── */
int  dx_init(HWND hwnd, int w, int h);
void dx_shutdown(void);
void dx_begin(float r, float g, float b, float a);
void dx_end(void);
void dx_resize(int w, int h);

/* ── 矩阵设置（着色器低层级访问） ── */
void dx_set_world(dx_mat4 world);
void dx_set_view(dx_mat4 view);
void dx_set_projection(dx_mat4 proj);

/* ── 数学辅助（row-major，与 D3DX 矩阵约定一致） ── */
void dx_mat4_identity(dx_mat4 *m);
void dx_mat4_mul(dx_mat4 *out, const dx_mat4 *a, const dx_mat4 *b);
void dx_mat4_rotation_x(dx_mat4 *m, float angle);
void dx_mat4_rotation_y(dx_mat4 *m, float angle);
void dx_mat4_rotation_z(dx_mat4 *m, float angle);
void dx_mat4_translation(dx_mat4 *m, float x, float y, float z);
void dx_mat4_look_at_lh(dx_mat4 *m, const float eye[3],
                        const float at[3], const float up[3]);
void dx_mat4_perspective_fov_lh(dx_mat4 *m, float fov_y,
                                float aspect, float zn, float zf);

/* ── 几何体 ── */
dx_geometry* dx_create_geometry(dx_vertex *verts, int vcount,
                                unsigned short *indices, int icount);
dx_geometry* dx_create_box(float w, float h, float d,
                           float r, float g, float b, float a);
dx_geometry* dx_create_sphere(float radius,
                              float r, float g, float b, float a);
dx_geometry* dx_create_cylinder(float radius, float height,
                                float r, float g, float b, float a);
dx_geometry* dx_create_pyramid(float w, float h, float d,
                               float r, float g, float b, float a);
dx_geometry* dx_create_plane(float w, float h,
                             float r, float g, float b, float a);
void         dx_draw_geometry(dx_geometry *geo, int count,
                              int start_index, int base_vertex);
void         dx_free_geometry(dx_geometry *geo);

/* ── 材质 ── */
dx_material* dx_create_material(void);
void         dx_material_set_color(dx_material *mat,
                                   float r, float g, float b, float a);
void         dx_material_set_texture(dx_material *mat, dx_texture *tex);
void         dx_material_set_roughness(dx_material *mat, float roughness);
void         dx_material_set_metalness(dx_material *mat, float metalness);
void         dx_material_set_unlit(dx_material *mat, int unlit);
void         dx_material_bind(dx_material *mat);
void         dx_free_material(dx_material *mat);

/* ── 网格（Mesh = Geometry + Material + Transform + Children） ── */
dx_mesh* dx_create_mesh(dx_geometry *geo, dx_material *mat);
void     dx_mesh_set_position(dx_mesh *m, float x, float y, float z);
void     dx_mesh_set_rotation(dx_mesh *m, float x, float y, float z);
void     dx_mesh_set_scale(dx_mesh *m, float x, float y, float z);
void     dx_mesh_add_child(dx_mesh *parent, dx_mesh *child);
void     dx_mesh_draw(dx_mesh *m);
void     dx_free_mesh(dx_mesh *m);

/* ── glTF 加载（返回根 Mesh，含子节点层次 + 纹理材质） ── */
dx_mesh* dx_load_gltf(const char *path);

/* ── 蒙皮 ── */
dx_skin*  dx_skin_create(int joint_count);
void      dx_skin_update(dx_mesh *mesh);
void      dx_bind_skin(dx_mesh *m);
void      dx_skin_free(dx_skin *skin);
void      dx_free_skin_and_anim(dx_mesh *m);

/* ── 动画 ── */
void dx_anim_update(dx_animation *anim, float dt);
void dx_anim_play(dx_animation *anim, int loop);

/* ── 光照 ── */
void dx_set_ambient_light(float r, float g, float b, float intensity);
void dx_set_directional_light(float dx, float dy, float dz,
                               float r, float g, float b, float intensity);
void dx_set_point_light(float px, float py, float pz,
                         float r, float g, float b, float intensity,
                         float range);

/* ── 相机封装 ── */
typedef struct {
    float position[3];   /* 相机位置   camera.position */
    float target[3];     /* 观察目标   camera.lookAt */
    float up[3];         /* 上方向 */
    float fov;           /* 视场角 */
    float aspect;        /* 宽高比     width/height */
    float near_z;        /* 近裁剪面 */
    float far_z;         /* 远裁剪面 */
} dx_camera;

void dx_camera_init(dx_camera *cam, float px, float py, float pz, float aspect);
void dx_camera_update(dx_camera *cam);

/* ── 轨道控制（左键旋转/右键平移/滚轮缩放） ── */
typedef struct {
    HWND window;
    float target[3];     /* 环绕目标点 */
    float distance;       /* 当前距离 */
    float theta;          /* 水平角（弧度），自由 */
    float phi;            /* 俯仰角（弧度），0=水平，正=俯视 */
    int action;           /* 0=无 1=旋转 2=平移 */
    int last_x, last_y;
    void *old_wnd_proc;   /* WNDPROC */
} dx_orbit;

void dx_orbit_init(dx_orbit *orb, HWND window,
                   float tx, float ty, float tz, float dist);
void dx_orbit_update(dx_orbit *orb, dx_camera *cam);
void dx_orbit_destroy(dx_orbit *orb);

/* ── 纹理 ── */
dx_texture* dx_create_texture(const char *filename);
dx_texture* dx_create_texture_from_memory(const unsigned char *data, int size);
dx_texture* dx_create_texture_rgba(int w, int h, const unsigned char *rgba);
void        dx_free_texture(dx_texture *tex);
void        dx_bind_texture(dx_texture *tex, int slot);

/* -- Network -- */
/* ── 初始化 / 清理 ── */
int  net_init(void);
void net_cleanup(void);
const char* net_error(void);
void net_free(void *ptr);

/* ── DNS 解析 ── */
int dns_lookup(const char *hostname, char *ip, int ip_size);

/* ── TCP ── */
typedef struct tcp_s tcp_t;
tcp_t* tcp_connect(const char *host, int port);
tcp_t* tcp_listen(int port);
tcp_t* tcp_accept(tcp_t *server);
int  tcp_send(tcp_t *conn, const char *data, int len);
int  tcp_recv(tcp_t *conn, char *buf, int buf_size);
int  tcp_recv_timeout(tcp_t *conn, char *buf, int buf_size, int ms);
char* tcp_peer_addr(tcp_t *conn);
void tcp_close(tcp_t *conn);

/* ── UDP ── */
typedef struct udp_s udp_t;
udp_t* udp_create(int port);
int udp_send(udp_t *sock, const char *host, int port,
                    const char *data, int len);
int udp_recv(udp_t *sock, char *buf, int buf_size,
                    char *src_ip, int *src_port, int timeout_ms);
void udp_close(udp_t *sock);

/* ── HTTP ── */
typedef struct http_s http_t;
http_t* http_get(const char *url);
http_t* http_post(const char *url, const char *body,
                                 const char *content_type,
                                 const char *auth_header);
int  http_status(http_t *resp);
const char* http_body(http_t *resp);
int  http_body_len(http_t *resp);
void http_free(http_t *resp);
char* url_encode(const char *str);

/* ── WebSocket 服务器 ── */
typedef struct ws_server_s ws_server_t;
typedef struct ws_conn_s ws_conn_t;

ws_server_t* ws_server_create(int port);
ws_conn_t*   ws_server_accept(ws_server_t *srv);
void         ws_server_close(ws_server_t *srv);

int  ws_send(ws_conn_t *conn, const char *data, int len);
int  ws_send_bin(ws_conn_t *conn, const char *data, int len);
int  ws_recv(ws_conn_t *conn, char *buf, int buf_size);
int  ws_recv_timeout(ws_conn_t *conn, char *buf, int buf_size, int ms);
void ws_close(ws_conn_t *conn);
int  ws_opcode(ws_conn_t *conn);

/* ── WebSocket Hub (pub/sub 模式，话题驱动) ──
 *
 * 类似 MQTT 的 pub/sub 消息枢纽：
 *   - 客户端连接后获得一个 conn_id
 *   - 客户端可以订阅一个或多个话题 (subscribe)
 *   - 客户端向某话题发布消息 (publish)，所有订阅者（除发送者）都会收到
 *   - 取消订阅 (unsubscribe) 停止接收该话题消息
 *
 * 用法:
 *   ws_hub_t *hub = ws_hub_create(9099);
 *
 *   // 接受连接
 *   int agent = ws_hub_accept(hub, -1);
 *   int js    = ws_hub_accept(hub, -1);
 *
 *   // 订阅话题
 *   ws_hub_subscribe(hub, agent, "agent");      // Agent 只收 "agent" 话题
 *   ws_hub_subscribe(hub, js,    "js");          // JS 只收 "js" 话题
 *
 *   // 消息循环：谁有数据 → publish 到对应话题
 *   while (1) {
 *       int ready = ws_hub_poll(hub, 1000);
 *       if (ready < 0) continue;
 *       char buf[8192];
 *       int len = ws_hub_recv(hub, ready, buf, sizeof(buf), 0);
 *       if (len <= 0) continue;
 *       if (ready == agent)
 *           ws_hub_publish(hub, agent, "js", buf, len);    // Agent→JS
 *       else if (ready == js)
 *           ws_hub_publish(hub, js, "agent", buf, len);    // JS→Agent
 *   }
 */

typedef struct ws_hub_s ws_hub_t;

/* ─── 生命周期 ─── */
ws_hub_t*   ws_hub_create(int port);                       /* 创建 hub，开始监听 */
void        ws_hub_close(ws_hub_t *hub);                   /* 关闭 hub（断开所有连接） */

/* ─── 连接管理 ─── */
int         ws_hub_accept(ws_hub_t *hub, int timeout_ms);  /* 接受新连接，返回 conn_id（-1=超时/错误） */
int         ws_hub_count(ws_hub_t *hub);                   /* 当前连接数 */
int         ws_hub_conn_id(ws_hub_t *hub, int index);      /* 按索引获取 conn_id */
void        ws_hub_disconnect(ws_hub_t *hub, int conn_id); /* 断开指定连接 */

/* ─── 订阅/取消订阅 ─── */
int         ws_hub_subscribe(ws_hub_t *hub, int conn_id,   /* 订阅话题（一个连接可订阅多个话题） */
                              const char *topic);
int         ws_hub_unsubscribe(ws_hub_t *hub, int conn_id, /* 取消订阅 */
                                const char *topic);

/* ─── 发布 ───
 * 向指定话题发送消息，所有订阅了该话题的连接（除 sender_id 外）都会收到。
 * 返回成功接收的连接数。
 */
int         ws_hub_publish(ws_hub_t *hub, int sender_id,
                            const char *topic,
                            const char *data, int len);

/* ─── 接收 ───
 * 从指定连接接收原始消息（不自动路由，由调用者自行处理）。
 */
int         ws_hub_recv(ws_hub_t *hub, int conn_id,
                         char *buf, int buf_size, int timeout_ms);

/* ─── 轮询 ───
 * 返回第一个有数据的 conn_id（-1=超时/无数据）。
 */
int         ws_hub_poll(ws_hub_t *hub, int timeout_ms);

/* -- AI LLM -- */
/* ── 初始化 ── */
void ai_setup(const char *api_key, const char *model, const char *base_url);

/* ── 同步接口 ── */
char* ai_chat(const char *prompt);

/* ── 回调类型 ── */
typedef void (*ai_callback_t)(const char *reply, void *userdata);

/* ── 异步接口 ── */
void ai_chat_async(const char *prompt, ai_callback_t callback, void *userdata);
void ai_chat_async_to_hwnd(HWND hwnd, const char *prompt, void *userdata);
int  ai_handle_async_msg(HWND hwnd, UINT msg, WPARAM wParam, LPARAM lParam,
                                void (*on_result)(const char *reply, void *userdata));

/* ── 资源 ── */
void ai_free(char *ptr);

/* -- Threading -- */
int  thread_init(void);
void thread_cleanup(void);

typedef void (*thread_func_t)(void *arg);
typedef struct thread_s thread_t;
thread_t* thread_run(thread_func_t func, void *arg);
int  thread_join(thread_t *t, int timeout_ms);
void thread_detach(thread_t *t);
DWORD thread_self_id(void);
void thread_sleep(int ms);

void execute_on_main(HWND hwnd, void (*cb)(void *), void *arg);

typedef struct mutex_s mutex_t;
mutex_t* mutex_create(void);
void mutex_lock(mutex_t *m);
int  mutex_trylock(mutex_t *m);
void mutex_unlock(mutex_t *m);
void mutex_free(mutex_t *m);

/* -- WebView2 -- */
int  webview_init(void);
void webview_cleanup(void);

HWND create_webview(HWND parent, int x, int y, int w, int h);
void webview_navigate(HWND hwv, const WCHAR *url);
void webview_load_html(HWND hwv, const WCHAR *html);

typedef void (*webview_ready_fn)(HWND hwv, void *data);
void on_webview_ready(HWND hwv, webview_ready_fn cb, void *data);

typedef void (*webview_message_fn)(HWND hwv, const char *json, void *data);
void on_webview_message(HWND hwv, webview_message_fn cb, void *data);
void webview_post_message(HWND hwv, const char *json);

typedef void (*webview_nav_complete_fn)(HWND hwv, int success, int status_code, void *data);
void on_navigation_completed(HWND hwv, webview_nav_complete_fn cb, void *data);

void webview_back(HWND hwv);
void webview_forward(HWND hwv);
void webview_reload(HWND hwv);

/* ── Bridge — JS 侧自动注入 eduwin.on_message / eduwin.call ── */
void webview_bridge_init(HWND hwv);

typedef void (*webview_bridge_fn)(HWND hwv, const char *func_name, const char *params_json, void *data);
void webview_bridge_register(const char *func_name, webview_bridge_fn cb, void *data);

/* ── Script injection ── */
void webview_execute_script(HWND hwv, const WCHAR *script);                         /* 在当前页面执行 JS（无返回值） */
void webview_add_script_on_doc_create(HWND hwv, const WCHAR *script);              /* 将来创建的每个文档都自动注入 */

/* ── Virtual host — 将本地文件夹映射为虚拟域名，加载外部 HTML/CSS/JS ── */
void webview_set_virtual_host(HWND hwv, const WCHAR *host_name, const WCHAR *folder_path);

/* -- Command Line -- */
/* ── 初始化（自动调 GetCommandLineW + CommandLineToArgvW）── */
void cmd_init(void);

/* ── 查询 ── */
int         cmd_has(const WCHAR *name);           /* 是否有某参数（包括开关和带值） */
const WCHAR *cmd_get(const WCHAR *name);          /* 获取参数值（如 --url 的值） */
const WCHAR *cmd_get_def(const WCHAR *name,       /* 同上，带默认值 */
                          const WCHAR *def);

/* ── 无参开关检测 ── */
int         cmd_is(const WCHAR *name);            /* --headless / --visible */

/* ── 帮助信息 ── */
void cmd_print_help(const WCHAR *desc);            /* 自动从参数注册表生成 */

/* ── 清理（可选，不调也行，进程退出自动回收） ── */
void cmd_cleanup(void);

/* -- LogView -- */
HWND create_logview(HWND parent, int x, int y, int w, int h);
void logview_info(HWND hwnd, const WCHAR *fmt, ...);
void logview_warn(HWND hwnd, const WCHAR *fmt, ...);
void logview_error(HWND hwnd, const WCHAR *fmt, ...);
void logview_clear(HWND hwnd);
void logview_set_max_rows(HWND hwnd, int max_rows);

#ifdef __cplusplus
}
#endif

#endif
