sqlite3-binding.h 624 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666166716681669167016711672167316741675167616771678167916801681168216831684168516861687168816891690169116921693169416951696169716981699170017011702170317041705170617071708170917101711171217131714171517161717171817191720172117221723172417251726172717281729173017311732173317341735173617371738173917401741174217431744174517461747174817491750175117521753175417551756175717581759176017611762176317641765176617671768176917701771177217731774177517761777177817791780178117821783178417851786178717881789179017911792179317941795179617971798179918001801180218031804180518061807180818091810181118121813181418151816181718181819182018211822182318241825182618271828182918301831183218331834183518361837183818391840184118421843184418451846184718481849185018511852185318541855185618571858185918601861186218631864186518661867186818691870187118721873187418751876187718781879188018811882188318841885188618871888188918901891189218931894189518961897189818991900190119021903190419051906190719081909191019111912191319141915191619171918191919201921192219231924192519261927192819291930193119321933193419351936193719381939194019411942194319441945194619471948194919501951195219531954195519561957195819591960196119621963196419651966196719681969197019711972197319741975197619771978197919801981198219831984198519861987198819891990199119921993199419951996199719981999200020012002200320042005200620072008200920102011201220132014201520162017201820192020202120222023202420252026202720282029203020312032203320342035203620372038203920402041204220432044204520462047204820492050205120522053205420552056205720582059206020612062206320642065206620672068206920702071207220732074207520762077207820792080208120822083208420852086208720882089209020912092209320942095209620972098209921002101210221032104210521062107210821092110211121122113211421152116211721182119212021212122212321242125212621272128212921302131213221332134213521362137213821392140214121422143214421452146214721482149215021512152215321542155215621572158215921602161216221632164216521662167216821692170217121722173217421752176217721782179218021812182218321842185218621872188218921902191219221932194219521962197219821992200220122022203220422052206220722082209221022112212221322142215221622172218221922202221222222232224222522262227222822292230223122322233223422352236223722382239224022412242224322442245224622472248224922502251225222532254225522562257225822592260226122622263226422652266226722682269227022712272227322742275227622772278227922802281228222832284228522862287228822892290229122922293229422952296229722982299230023012302230323042305230623072308230923102311231223132314231523162317231823192320232123222323232423252326232723282329233023312332233323342335233623372338233923402341234223432344234523462347234823492350235123522353235423552356235723582359236023612362236323642365236623672368236923702371237223732374237523762377237823792380238123822383238423852386238723882389239023912392239323942395239623972398239924002401240224032404240524062407240824092410241124122413241424152416241724182419242024212422242324242425242624272428242924302431243224332434243524362437243824392440244124422443244424452446244724482449245024512452245324542455245624572458245924602461246224632464246524662467246824692470247124722473247424752476247724782479248024812482248324842485248624872488248924902491249224932494249524962497249824992500250125022503250425052506250725082509251025112512251325142515251625172518251925202521252225232524252525262527252825292530253125322533253425352536253725382539254025412542254325442545254625472548254925502551255225532554255525562557255825592560256125622563256425652566256725682569257025712572257325742575257625772578257925802581258225832584258525862587258825892590259125922593259425952596259725982599260026012602260326042605260626072608260926102611261226132614261526162617261826192620262126222623262426252626262726282629263026312632263326342635263626372638263926402641264226432644264526462647264826492650265126522653265426552656265726582659266026612662266326642665266626672668266926702671267226732674267526762677267826792680268126822683268426852686268726882689269026912692269326942695269626972698269927002701270227032704270527062707270827092710271127122713271427152716271727182719272027212722272327242725272627272728272927302731273227332734273527362737273827392740274127422743274427452746274727482749275027512752275327542755275627572758275927602761276227632764276527662767276827692770277127722773277427752776277727782779278027812782278327842785278627872788278927902791279227932794279527962797279827992800280128022803280428052806280728082809281028112812281328142815281628172818281928202821282228232824282528262827282828292830283128322833283428352836283728382839284028412842284328442845284628472848284928502851285228532854285528562857285828592860286128622863286428652866286728682869287028712872287328742875287628772878287928802881288228832884288528862887288828892890289128922893289428952896289728982899290029012902290329042905290629072908290929102911291229132914291529162917291829192920292129222923292429252926292729282929293029312932293329342935293629372938293929402941294229432944294529462947294829492950295129522953295429552956295729582959296029612962296329642965296629672968296929702971297229732974297529762977297829792980298129822983298429852986298729882989299029912992299329942995299629972998299930003001300230033004300530063007300830093010301130123013301430153016301730183019302030213022302330243025302630273028302930303031303230333034303530363037303830393040304130423043304430453046304730483049305030513052305330543055305630573058305930603061306230633064306530663067306830693070307130723073307430753076307730783079308030813082308330843085308630873088308930903091309230933094309530963097309830993100310131023103310431053106310731083109311031113112311331143115311631173118311931203121312231233124312531263127312831293130313131323133313431353136313731383139314031413142314331443145314631473148314931503151315231533154315531563157315831593160316131623163316431653166316731683169317031713172317331743175317631773178317931803181318231833184318531863187318831893190319131923193319431953196319731983199320032013202320332043205320632073208320932103211321232133214321532163217321832193220322132223223322432253226322732283229323032313232323332343235323632373238323932403241324232433244324532463247324832493250325132523253325432553256325732583259326032613262326332643265326632673268326932703271327232733274327532763277327832793280328132823283328432853286328732883289329032913292329332943295329632973298329933003301330233033304330533063307330833093310331133123313331433153316331733183319332033213322332333243325332633273328332933303331333233333334333533363337333833393340334133423343334433453346334733483349335033513352335333543355335633573358335933603361336233633364336533663367336833693370337133723373337433753376337733783379338033813382338333843385338633873388338933903391339233933394339533963397339833993400340134023403340434053406340734083409341034113412341334143415341634173418341934203421342234233424342534263427342834293430343134323433343434353436343734383439344034413442344334443445344634473448344934503451345234533454345534563457345834593460346134623463346434653466346734683469347034713472347334743475347634773478347934803481348234833484348534863487348834893490349134923493349434953496349734983499350035013502350335043505350635073508350935103511351235133514351535163517351835193520352135223523352435253526352735283529353035313532353335343535353635373538353935403541354235433544354535463547354835493550355135523553355435553556355735583559356035613562356335643565356635673568356935703571357235733574357535763577357835793580358135823583358435853586358735883589359035913592359335943595359635973598359936003601360236033604360536063607360836093610361136123613361436153616361736183619362036213622362336243625362636273628362936303631363236333634363536363637363836393640364136423643364436453646364736483649365036513652365336543655365636573658365936603661366236633664366536663667366836693670367136723673367436753676367736783679368036813682368336843685368636873688368936903691369236933694369536963697369836993700370137023703370437053706370737083709371037113712371337143715371637173718371937203721372237233724372537263727372837293730373137323733373437353736373737383739374037413742374337443745374637473748374937503751375237533754375537563757375837593760376137623763376437653766376737683769377037713772377337743775377637773778377937803781378237833784378537863787378837893790379137923793379437953796379737983799380038013802380338043805380638073808380938103811381238133814381538163817381838193820382138223823382438253826382738283829383038313832383338343835383638373838383938403841384238433844384538463847384838493850385138523853385438553856385738583859386038613862386338643865386638673868386938703871387238733874387538763877387838793880388138823883388438853886388738883889389038913892389338943895389638973898389939003901390239033904390539063907390839093910391139123913391439153916391739183919392039213922392339243925392639273928392939303931393239333934393539363937393839393940394139423943394439453946394739483949395039513952395339543955395639573958395939603961396239633964396539663967396839693970397139723973397439753976397739783979398039813982398339843985398639873988398939903991399239933994399539963997399839994000400140024003400440054006400740084009401040114012401340144015401640174018401940204021402240234024402540264027402840294030403140324033403440354036403740384039404040414042404340444045404640474048404940504051405240534054405540564057405840594060406140624063406440654066406740684069407040714072407340744075407640774078407940804081408240834084408540864087408840894090409140924093409440954096409740984099410041014102410341044105410641074108410941104111411241134114411541164117411841194120412141224123412441254126412741284129413041314132413341344135413641374138413941404141414241434144414541464147414841494150415141524153415441554156415741584159416041614162416341644165416641674168416941704171417241734174417541764177417841794180418141824183418441854186418741884189419041914192419341944195419641974198419942004201420242034204420542064207420842094210421142124213421442154216421742184219422042214222422342244225422642274228422942304231423242334234423542364237423842394240424142424243424442454246424742484249425042514252425342544255425642574258425942604261426242634264426542664267426842694270427142724273427442754276427742784279428042814282428342844285428642874288428942904291429242934294429542964297429842994300430143024303430443054306430743084309431043114312431343144315431643174318431943204321432243234324432543264327432843294330433143324333433443354336433743384339434043414342434343444345434643474348434943504351435243534354435543564357435843594360436143624363436443654366436743684369437043714372437343744375437643774378437943804381438243834384438543864387438843894390439143924393439443954396439743984399440044014402440344044405440644074408440944104411441244134414441544164417441844194420442144224423442444254426442744284429443044314432443344344435443644374438443944404441444244434444444544464447444844494450445144524453445444554456445744584459446044614462446344644465446644674468446944704471447244734474447544764477447844794480448144824483448444854486448744884489449044914492449344944495449644974498449945004501450245034504450545064507450845094510451145124513451445154516451745184519452045214522452345244525452645274528452945304531453245334534453545364537453845394540454145424543454445454546454745484549455045514552455345544555455645574558455945604561456245634564456545664567456845694570457145724573457445754576457745784579458045814582458345844585458645874588458945904591459245934594459545964597459845994600460146024603460446054606460746084609461046114612461346144615461646174618461946204621462246234624462546264627462846294630463146324633463446354636463746384639464046414642464346444645464646474648464946504651465246534654465546564657465846594660466146624663466446654666466746684669467046714672467346744675467646774678467946804681468246834684468546864687468846894690469146924693469446954696469746984699470047014702470347044705470647074708470947104711471247134714471547164717471847194720472147224723472447254726472747284729473047314732473347344735473647374738473947404741474247434744474547464747474847494750475147524753475447554756475747584759476047614762476347644765476647674768476947704771477247734774477547764777477847794780478147824783478447854786478747884789479047914792479347944795479647974798479948004801480248034804480548064807480848094810481148124813481448154816481748184819482048214822482348244825482648274828482948304831483248334834483548364837483848394840484148424843484448454846484748484849485048514852485348544855485648574858485948604861486248634864486548664867486848694870487148724873487448754876487748784879488048814882488348844885488648874888488948904891489248934894489548964897489848994900490149024903490449054906490749084909491049114912491349144915491649174918491949204921492249234924492549264927492849294930493149324933493449354936493749384939494049414942494349444945494649474948494949504951495249534954495549564957495849594960496149624963496449654966496749684969497049714972497349744975497649774978497949804981498249834984498549864987498849894990499149924993499449954996499749984999500050015002500350045005500650075008500950105011501250135014501550165017501850195020502150225023502450255026502750285029503050315032503350345035503650375038503950405041504250435044504550465047504850495050505150525053505450555056505750585059506050615062506350645065506650675068506950705071507250735074507550765077507850795080508150825083508450855086508750885089509050915092509350945095509650975098509951005101510251035104510551065107510851095110511151125113511451155116511751185119512051215122512351245125512651275128512951305131513251335134513551365137513851395140514151425143514451455146514751485149515051515152515351545155515651575158515951605161516251635164516551665167516851695170517151725173517451755176517751785179518051815182518351845185518651875188518951905191519251935194519551965197519851995200520152025203520452055206520752085209521052115212521352145215521652175218521952205221522252235224522552265227522852295230523152325233523452355236523752385239524052415242524352445245524652475248524952505251525252535254525552565257525852595260526152625263526452655266526752685269527052715272527352745275527652775278527952805281528252835284528552865287528852895290529152925293529452955296529752985299530053015302530353045305530653075308530953105311531253135314531553165317531853195320532153225323532453255326532753285329533053315332533353345335533653375338533953405341534253435344534553465347534853495350535153525353535453555356535753585359536053615362536353645365536653675368536953705371537253735374537553765377537853795380538153825383538453855386538753885389539053915392539353945395539653975398539954005401540254035404540554065407540854095410541154125413541454155416541754185419542054215422542354245425542654275428542954305431543254335434543554365437543854395440544154425443544454455446544754485449545054515452545354545455545654575458545954605461546254635464546554665467546854695470547154725473547454755476547754785479548054815482548354845485548654875488548954905491549254935494549554965497549854995500550155025503550455055506550755085509551055115512551355145515551655175518551955205521552255235524552555265527552855295530553155325533553455355536553755385539554055415542554355445545554655475548554955505551555255535554555555565557555855595560556155625563556455655566556755685569557055715572557355745575557655775578557955805581558255835584558555865587558855895590559155925593559455955596559755985599560056015602560356045605560656075608560956105611561256135614561556165617561856195620562156225623562456255626562756285629563056315632563356345635563656375638563956405641564256435644564556465647564856495650565156525653565456555656565756585659566056615662566356645665566656675668566956705671567256735674567556765677567856795680568156825683568456855686568756885689569056915692569356945695569656975698569957005701570257035704570557065707570857095710571157125713571457155716571757185719572057215722572357245725572657275728572957305731573257335734573557365737573857395740574157425743574457455746574757485749575057515752575357545755575657575758575957605761576257635764576557665767576857695770577157725773577457755776577757785779578057815782578357845785578657875788578957905791579257935794579557965797579857995800580158025803580458055806580758085809581058115812581358145815581658175818581958205821582258235824582558265827582858295830583158325833583458355836583758385839584058415842584358445845584658475848584958505851585258535854585558565857585858595860586158625863586458655866586758685869587058715872587358745875587658775878587958805881588258835884588558865887588858895890589158925893589458955896589758985899590059015902590359045905590659075908590959105911591259135914591559165917591859195920592159225923592459255926592759285929593059315932593359345935593659375938593959405941594259435944594559465947594859495950595159525953595459555956595759585959596059615962596359645965596659675968596959705971597259735974597559765977597859795980598159825983598459855986598759885989599059915992599359945995599659975998599960006001600260036004600560066007600860096010601160126013601460156016601760186019602060216022602360246025602660276028602960306031603260336034603560366037603860396040604160426043604460456046604760486049605060516052605360546055605660576058605960606061606260636064606560666067606860696070607160726073607460756076607760786079608060816082608360846085608660876088608960906091609260936094609560966097609860996100610161026103610461056106610761086109611061116112611361146115611661176118611961206121612261236124612561266127612861296130613161326133613461356136613761386139614061416142614361446145614661476148614961506151615261536154615561566157615861596160616161626163616461656166616761686169617061716172617361746175617661776178617961806181618261836184618561866187618861896190619161926193619461956196619761986199620062016202620362046205620662076208620962106211621262136214621562166217621862196220622162226223622462256226622762286229623062316232623362346235623662376238623962406241624262436244624562466247624862496250625162526253625462556256625762586259626062616262626362646265626662676268626962706271627262736274627562766277627862796280628162826283628462856286628762886289629062916292629362946295629662976298629963006301630263036304630563066307630863096310631163126313631463156316631763186319632063216322632363246325632663276328632963306331633263336334633563366337633863396340634163426343634463456346634763486349635063516352635363546355635663576358635963606361636263636364636563666367636863696370637163726373637463756376637763786379638063816382638363846385638663876388638963906391639263936394639563966397639863996400640164026403640464056406640764086409641064116412641364146415641664176418641964206421642264236424642564266427642864296430643164326433643464356436643764386439644064416442644364446445644664476448644964506451645264536454645564566457645864596460646164626463646464656466646764686469647064716472647364746475647664776478647964806481648264836484648564866487648864896490649164926493649464956496649764986499650065016502650365046505650665076508650965106511651265136514651565166517651865196520652165226523652465256526652765286529653065316532653365346535653665376538653965406541654265436544654565466547654865496550655165526553655465556556655765586559656065616562656365646565656665676568656965706571657265736574657565766577657865796580658165826583658465856586658765886589659065916592659365946595659665976598659966006601660266036604660566066607660866096610661166126613661466156616661766186619662066216622662366246625662666276628662966306631663266336634663566366637663866396640664166426643664466456646664766486649665066516652665366546655665666576658665966606661666266636664666566666667666866696670667166726673667466756676667766786679668066816682668366846685668666876688668966906691669266936694669566966697669866996700670167026703670467056706670767086709671067116712671367146715671667176718671967206721672267236724672567266727672867296730673167326733673467356736673767386739674067416742674367446745674667476748674967506751675267536754675567566757675867596760676167626763676467656766676767686769677067716772677367746775677667776778677967806781678267836784678567866787678867896790679167926793679467956796679767986799680068016802680368046805680668076808680968106811681268136814681568166817681868196820682168226823682468256826682768286829683068316832683368346835683668376838683968406841684268436844684568466847684868496850685168526853685468556856685768586859686068616862686368646865686668676868686968706871687268736874687568766877687868796880688168826883688468856886688768886889689068916892689368946895689668976898689969006901690269036904690569066907690869096910691169126913691469156916691769186919692069216922692369246925692669276928692969306931693269336934693569366937693869396940694169426943694469456946694769486949695069516952695369546955695669576958695969606961696269636964696569666967696869696970697169726973697469756976697769786979698069816982698369846985698669876988698969906991699269936994699569966997699869997000700170027003700470057006700770087009701070117012701370147015701670177018701970207021702270237024702570267027702870297030703170327033703470357036703770387039704070417042704370447045704670477048704970507051705270537054705570567057705870597060706170627063706470657066706770687069707070717072707370747075707670777078707970807081708270837084708570867087708870897090709170927093709470957096709770987099710071017102710371047105710671077108710971107111711271137114711571167117711871197120712171227123712471257126712771287129713071317132713371347135713671377138713971407141714271437144714571467147714871497150715171527153715471557156715771587159716071617162716371647165716671677168716971707171717271737174717571767177717871797180718171827183718471857186718771887189719071917192719371947195719671977198719972007201720272037204720572067207720872097210721172127213721472157216721772187219722072217222722372247225722672277228722972307231723272337234723572367237723872397240724172427243724472457246724772487249725072517252725372547255725672577258725972607261726272637264726572667267726872697270727172727273727472757276727772787279728072817282728372847285728672877288728972907291729272937294729572967297729872997300730173027303730473057306730773087309731073117312731373147315731673177318731973207321732273237324732573267327732873297330733173327333733473357336733773387339734073417342734373447345734673477348734973507351735273537354735573567357735873597360736173627363736473657366736773687369737073717372737373747375737673777378737973807381738273837384738573867387738873897390739173927393739473957396739773987399740074017402740374047405740674077408740974107411741274137414741574167417741874197420742174227423742474257426742774287429743074317432743374347435743674377438743974407441744274437444744574467447744874497450745174527453745474557456745774587459746074617462746374647465746674677468746974707471747274737474747574767477747874797480748174827483748474857486748774887489749074917492749374947495749674977498749975007501750275037504750575067507750875097510751175127513751475157516751775187519752075217522752375247525752675277528752975307531753275337534753575367537753875397540754175427543754475457546754775487549755075517552755375547555755675577558755975607561756275637564756575667567756875697570757175727573757475757576757775787579758075817582758375847585758675877588758975907591759275937594759575967597759875997600760176027603760476057606760776087609761076117612761376147615761676177618761976207621762276237624762576267627762876297630763176327633763476357636763776387639764076417642764376447645764676477648764976507651765276537654765576567657765876597660766176627663766476657666766776687669767076717672767376747675767676777678767976807681768276837684768576867687768876897690769176927693769476957696769776987699770077017702770377047705770677077708770977107711771277137714771577167717771877197720772177227723772477257726772777287729773077317732773377347735773677377738773977407741774277437744774577467747774877497750775177527753775477557756775777587759776077617762776377647765776677677768776977707771777277737774777577767777777877797780778177827783778477857786778777887789779077917792779377947795779677977798779978007801780278037804780578067807780878097810781178127813781478157816781778187819782078217822782378247825782678277828782978307831783278337834783578367837783878397840784178427843784478457846784778487849785078517852785378547855785678577858785978607861786278637864786578667867786878697870787178727873787478757876787778787879788078817882788378847885788678877888788978907891789278937894789578967897789878997900790179027903790479057906790779087909791079117912791379147915791679177918791979207921792279237924792579267927792879297930793179327933793479357936793779387939794079417942794379447945794679477948794979507951795279537954795579567957795879597960796179627963796479657966796779687969797079717972797379747975797679777978797979807981798279837984798579867987798879897990799179927993799479957996799779987999800080018002800380048005800680078008800980108011801280138014801580168017801880198020802180228023802480258026802780288029803080318032803380348035803680378038803980408041804280438044804580468047804880498050805180528053805480558056805780588059806080618062806380648065806680678068806980708071807280738074807580768077807880798080808180828083808480858086808780888089809080918092809380948095809680978098809981008101810281038104810581068107810881098110811181128113811481158116811781188119812081218122812381248125812681278128812981308131813281338134813581368137813881398140814181428143814481458146814781488149815081518152815381548155815681578158815981608161816281638164816581668167816881698170817181728173817481758176817781788179818081818182818381848185818681878188818981908191819281938194819581968197819881998200820182028203820482058206820782088209821082118212821382148215821682178218821982208221822282238224822582268227822882298230823182328233823482358236823782388239824082418242824382448245824682478248824982508251825282538254825582568257825882598260826182628263826482658266826782688269827082718272827382748275827682778278827982808281828282838284828582868287828882898290829182928293829482958296829782988299830083018302830383048305830683078308830983108311831283138314831583168317831883198320832183228323832483258326832783288329833083318332833383348335833683378338833983408341834283438344834583468347834883498350835183528353835483558356835783588359836083618362836383648365836683678368836983708371837283738374837583768377837883798380838183828383838483858386838783888389839083918392839383948395839683978398839984008401840284038404840584068407840884098410841184128413841484158416841784188419842084218422842384248425842684278428842984308431843284338434843584368437843884398440844184428443844484458446844784488449845084518452845384548455845684578458845984608461846284638464846584668467846884698470847184728473847484758476847784788479848084818482848384848485848684878488848984908491849284938494849584968497849884998500850185028503850485058506850785088509851085118512851385148515851685178518851985208521852285238524852585268527852885298530853185328533853485358536853785388539854085418542854385448545854685478548854985508551855285538554855585568557855885598560856185628563856485658566856785688569857085718572857385748575857685778578857985808581858285838584858585868587858885898590859185928593859485958596859785988599860086018602860386048605860686078608860986108611861286138614861586168617861886198620862186228623862486258626862786288629863086318632863386348635863686378638863986408641864286438644864586468647864886498650865186528653865486558656865786588659866086618662866386648665866686678668866986708671867286738674867586768677867886798680868186828683868486858686868786888689869086918692869386948695869686978698869987008701870287038704870587068707870887098710871187128713871487158716871787188719872087218722872387248725872687278728872987308731873287338734873587368737873887398740874187428743874487458746874787488749875087518752875387548755875687578758875987608761876287638764876587668767876887698770877187728773877487758776877787788779878087818782878387848785878687878788878987908791879287938794879587968797879887998800880188028803880488058806880788088809881088118812881388148815881688178818881988208821882288238824882588268827882888298830883188328833883488358836883788388839884088418842884388448845884688478848884988508851885288538854885588568857885888598860886188628863886488658866886788688869887088718872887388748875887688778878887988808881888288838884888588868887888888898890889188928893889488958896889788988899890089018902890389048905890689078908890989108911891289138914891589168917891889198920892189228923892489258926892789288929893089318932893389348935893689378938893989408941894289438944894589468947894889498950895189528953895489558956895789588959896089618962896389648965896689678968896989708971897289738974897589768977897889798980898189828983898489858986898789888989899089918992899389948995899689978998899990009001900290039004900590069007900890099010901190129013901490159016901790189019902090219022902390249025902690279028902990309031903290339034903590369037903890399040904190429043904490459046904790489049905090519052905390549055905690579058905990609061906290639064906590669067906890699070907190729073907490759076907790789079908090819082908390849085908690879088908990909091909290939094909590969097909890999100910191029103910491059106910791089109911091119112911391149115911691179118911991209121912291239124912591269127912891299130913191329133913491359136913791389139914091419142914391449145914691479148914991509151915291539154915591569157915891599160916191629163916491659166916791689169917091719172917391749175917691779178917991809181918291839184918591869187918891899190919191929193919491959196919791989199920092019202920392049205920692079208920992109211921292139214921592169217921892199220922192229223922492259226922792289229923092319232923392349235923692379238923992409241924292439244924592469247924892499250925192529253925492559256925792589259926092619262926392649265926692679268926992709271927292739274927592769277927892799280928192829283928492859286928792889289929092919292929392949295929692979298929993009301930293039304930593069307930893099310931193129313931493159316931793189319932093219322932393249325932693279328932993309331933293339334933593369337933893399340934193429343934493459346934793489349935093519352935393549355935693579358935993609361936293639364936593669367936893699370937193729373937493759376937793789379938093819382938393849385938693879388938993909391939293939394939593969397939893999400940194029403940494059406940794089409941094119412941394149415941694179418941994209421942294239424942594269427942894299430943194329433943494359436943794389439944094419442944394449445944694479448944994509451945294539454945594569457945894599460946194629463946494659466946794689469947094719472947394749475947694779478947994809481948294839484948594869487948894899490949194929493949494959496949794989499950095019502950395049505950695079508950995109511951295139514951595169517951895199520952195229523952495259526952795289529953095319532953395349535953695379538953995409541954295439544954595469547954895499550955195529553955495559556955795589559956095619562956395649565956695679568956995709571957295739574957595769577957895799580958195829583958495859586958795889589959095919592959395949595959695979598959996009601960296039604960596069607960896099610961196129613961496159616961796189619962096219622962396249625962696279628962996309631963296339634963596369637963896399640964196429643964496459646964796489649965096519652965396549655965696579658965996609661966296639664966596669667966896699670967196729673967496759676967796789679968096819682968396849685968696879688968996909691969296939694969596969697969896999700970197029703970497059706970797089709971097119712971397149715971697179718971997209721972297239724972597269727972897299730973197329733973497359736973797389739974097419742974397449745974697479748974997509751975297539754975597569757975897599760976197629763976497659766976797689769977097719772977397749775977697779778977997809781978297839784978597869787978897899790979197929793979497959796979797989799980098019802980398049805980698079808980998109811981298139814981598169817981898199820982198229823982498259826982798289829983098319832983398349835983698379838983998409841984298439844984598469847984898499850985198529853985498559856985798589859986098619862986398649865986698679868986998709871987298739874987598769877987898799880988198829883988498859886988798889889989098919892989398949895989698979898989999009901990299039904990599069907990899099910991199129913991499159916991799189919992099219922992399249925992699279928992999309931993299339934993599369937993899399940994199429943994499459946994799489949995099519952995399549955995699579958995999609961996299639964996599669967996899699970997199729973997499759976997799789979998099819982998399849985998699879988998999909991999299939994999599969997999899991000010001100021000310004100051000610007100081000910010100111001210013100141001510016100171001810019100201002110022100231002410025100261002710028100291003010031100321003310034100351003610037100381003910040100411004210043100441004510046100471004810049100501005110052100531005410055100561005710058100591006010061100621006310064100651006610067100681006910070100711007210073100741007510076100771007810079100801008110082100831008410085100861008710088100891009010091100921009310094100951009610097100981009910100101011010210103101041010510106101071010810109101101011110112101131011410115101161011710118101191012010121101221012310124101251012610127101281012910130101311013210133101341013510136101371013810139101401014110142101431014410145101461014710148101491015010151101521015310154101551015610157101581015910160101611016210163101641016510166101671016810169101701017110172101731017410175101761017710178101791018010181101821018310184101851018610187101881018910190101911019210193101941019510196101971019810199102001020110202102031020410205102061020710208102091021010211102121021310214102151021610217102181021910220102211022210223102241022510226102271022810229102301023110232102331023410235102361023710238102391024010241102421024310244102451024610247102481024910250102511025210253102541025510256102571025810259102601026110262102631026410265102661026710268102691027010271102721027310274102751027610277102781027910280102811028210283102841028510286102871028810289102901029110292102931029410295102961029710298102991030010301103021030310304103051030610307103081030910310103111031210313103141031510316103171031810319103201032110322103231032410325103261032710328103291033010331103321033310334103351033610337103381033910340103411034210343103441034510346103471034810349103501035110352103531035410355103561035710358103591036010361103621036310364103651036610367103681036910370103711037210373103741037510376103771037810379103801038110382103831038410385103861038710388103891039010391103921039310394103951039610397103981039910400104011040210403104041040510406104071040810409104101041110412104131041410415104161041710418104191042010421104221042310424104251042610427104281042910430104311043210433104341043510436104371043810439104401044110442104431044410445104461044710448104491045010451104521045310454104551045610457104581045910460104611046210463104641046510466104671046810469104701047110472104731047410475104761047710478104791048010481104821048310484104851048610487104881048910490104911049210493104941049510496104971049810499105001050110502105031050410505105061050710508105091051010511105121051310514105151051610517105181051910520105211052210523105241052510526105271052810529105301053110532105331053410535105361053710538105391054010541105421054310544105451054610547105481054910550105511055210553105541055510556105571055810559105601056110562105631056410565105661056710568105691057010571105721057310574105751057610577105781057910580105811058210583105841058510586105871058810589105901059110592105931059410595105961059710598105991060010601106021060310604106051060610607106081060910610106111061210613106141061510616106171061810619106201062110622106231062410625106261062710628106291063010631106321063310634106351063610637106381063910640106411064210643106441064510646106471064810649106501065110652106531065410655106561065710658106591066010661106621066310664106651066610667106681066910670106711067210673106741067510676106771067810679106801068110682106831068410685106861068710688106891069010691106921069310694106951069610697106981069910700107011070210703107041070510706107071070810709107101071110712107131071410715107161071710718107191072010721107221072310724107251072610727107281072910730107311073210733107341073510736107371073810739107401074110742107431074410745107461074710748107491075010751107521075310754107551075610757107581075910760107611076210763107641076510766107671076810769107701077110772107731077410775107761077710778107791078010781107821078310784107851078610787107881078910790107911079210793107941079510796107971079810799108001080110802108031080410805108061080710808108091081010811108121081310814108151081610817108181081910820108211082210823108241082510826108271082810829108301083110832108331083410835108361083710838108391084010841108421084310844108451084610847108481084910850108511085210853108541085510856108571085810859108601086110862108631086410865108661086710868108691087010871108721087310874108751087610877108781087910880108811088210883108841088510886108871088810889108901089110892108931089410895108961089710898108991090010901109021090310904109051090610907109081090910910109111091210913109141091510916109171091810919109201092110922109231092410925109261092710928109291093010931109321093310934109351093610937109381093910940109411094210943109441094510946109471094810949109501095110952109531095410955109561095710958109591096010961109621096310964109651096610967109681096910970109711097210973109741097510976109771097810979109801098110982109831098410985109861098710988109891099010991109921099310994109951099610997109981099911000110011100211003110041100511006110071100811009110101101111012110131101411015110161101711018110191102011021110221102311024110251102611027110281102911030110311103211033110341103511036110371103811039110401104111042110431104411045110461104711048110491105011051110521105311054110551105611057110581105911060110611106211063110641106511066110671106811069110701107111072110731107411075110761107711078110791108011081110821108311084110851108611087110881108911090110911109211093110941109511096110971109811099111001110111102111031110411105111061110711108111091111011111111121111311114111151111611117111181111911120111211112211123111241112511126111271112811129111301113111132111331113411135111361113711138111391114011141111421114311144111451114611147111481114911150111511115211153111541115511156111571115811159111601116111162111631116411165111661116711168111691117011171111721117311174111751117611177111781117911180111811118211183111841118511186111871118811189111901119111192111931119411195111961119711198111991120011201112021120311204112051120611207112081120911210112111121211213112141121511216112171121811219112201122111222112231122411225112261122711228112291123011231112321123311234112351123611237112381123911240112411124211243112441124511246112471124811249112501125111252112531125411255112561125711258112591126011261112621126311264112651126611267112681126911270112711127211273112741127511276112771127811279112801128111282112831128411285112861128711288112891129011291112921129311294112951129611297112981129911300113011130211303113041130511306113071130811309113101131111312113131131411315113161131711318113191132011321113221132311324113251132611327113281132911330113311133211333113341133511336113371133811339113401134111342113431134411345113461134711348113491135011351113521135311354113551135611357113581135911360113611136211363113641136511366113671136811369113701137111372113731137411375113761137711378113791138011381113821138311384113851138611387113881138911390113911139211393113941139511396113971139811399114001140111402114031140411405114061140711408114091141011411114121141311414114151141611417114181141911420114211142211423114241142511426114271142811429114301143111432114331143411435114361143711438114391144011441114421144311444114451144611447114481144911450114511145211453114541145511456114571145811459114601146111462114631146411465114661146711468114691147011471114721147311474114751147611477114781147911480114811148211483114841148511486114871148811489114901149111492114931149411495114961149711498114991150011501115021150311504115051150611507115081150911510115111151211513115141151511516115171151811519115201152111522115231152411525115261152711528115291153011531115321153311534115351153611537115381153911540115411154211543115441154511546115471154811549115501155111552115531155411555115561155711558115591156011561115621156311564115651156611567115681156911570115711157211573115741157511576115771157811579115801158111582115831158411585115861158711588115891159011591115921159311594115951159611597115981159911600116011160211603116041160511606116071160811609116101161111612116131161411615116161161711618116191162011621116221162311624116251162611627116281162911630116311163211633116341163511636116371163811639116401164111642116431164411645116461164711648116491165011651116521165311654116551165611657116581165911660116611166211663116641166511666116671166811669116701167111672116731167411675116761167711678116791168011681116821168311684116851168611687116881168911690116911169211693116941169511696116971169811699117001170111702117031170411705117061170711708117091171011711117121171311714117151171611717117181171911720117211172211723117241172511726117271172811729117301173111732117331173411735117361173711738117391174011741117421174311744117451174611747117481174911750117511175211753117541175511756117571175811759117601176111762117631176411765117661176711768117691177011771117721177311774117751177611777117781177911780117811178211783117841178511786117871178811789117901179111792117931179411795117961179711798117991180011801118021180311804118051180611807118081180911810118111181211813118141181511816118171181811819118201182111822118231182411825118261182711828118291183011831118321183311834118351183611837118381183911840118411184211843118441184511846118471184811849118501185111852118531185411855118561185711858118591186011861118621186311864118651186611867118681186911870118711187211873118741187511876118771187811879118801188111882118831188411885118861188711888118891189011891118921189311894118951189611897118981189911900119011190211903119041190511906119071190811909119101191111912119131191411915119161191711918119191192011921119221192311924119251192611927119281192911930119311193211933119341193511936119371193811939119401194111942119431194411945119461194711948119491195011951119521195311954119551195611957119581195911960119611196211963119641196511966119671196811969119701197111972119731197411975119761197711978119791198011981119821198311984119851198611987119881198911990119911199211993119941199511996119971199811999120001200112002120031200412005120061200712008120091201012011120121201312014120151201612017120181201912020120211202212023120241202512026120271202812029120301203112032120331203412035120361203712038120391204012041120421204312044120451204612047120481204912050120511205212053120541205512056120571205812059120601206112062120631206412065120661206712068120691207012071120721207312074120751207612077120781207912080120811208212083120841208512086120871208812089120901209112092120931209412095120961209712098120991210012101121021210312104121051210612107121081210912110121111211212113121141211512116121171211812119121201212112122121231212412125121261212712128121291213012131121321213312134121351213612137121381213912140121411214212143121441214512146121471214812149121501215112152121531215412155121561215712158121591216012161121621216312164121651216612167121681216912170121711217212173121741217512176121771217812179121801218112182121831218412185121861218712188121891219012191121921219312194121951219612197121981219912200122011220212203122041220512206122071220812209122101221112212122131221412215122161221712218122191222012221122221222312224122251222612227122281222912230122311223212233122341223512236122371223812239122401224112242122431224412245122461224712248122491225012251122521225312254122551225612257122581225912260122611226212263122641226512266122671226812269122701227112272122731227412275122761227712278122791228012281122821228312284122851228612287122881228912290122911229212293122941229512296122971229812299123001230112302123031230412305123061230712308123091231012311123121231312314123151231612317123181231912320123211232212323123241232512326123271232812329123301233112332123331233412335123361233712338123391234012341123421234312344123451234612347123481234912350123511235212353123541235512356123571235812359123601236112362123631236412365123661236712368123691237012371123721237312374123751237612377123781237912380123811238212383123841238512386123871238812389123901239112392123931239412395123961239712398123991240012401124021240312404124051240612407124081240912410124111241212413124141241512416124171241812419124201242112422124231242412425124261242712428124291243012431124321243312434124351243612437124381243912440124411244212443124441244512446124471244812449124501245112452124531245412455124561245712458124591246012461124621246312464124651246612467124681246912470124711247212473124741247512476124771247812479124801248112482124831248412485124861248712488124891249012491124921249312494124951249612497124981249912500125011250212503125041250512506125071250812509125101251112512125131251412515125161251712518125191252012521125221252312524125251252612527125281252912530125311253212533125341253512536125371253812539125401254112542125431254412545125461254712548125491255012551125521255312554125551255612557125581255912560125611256212563125641256512566125671256812569125701257112572125731257412575125761257712578125791258012581125821258312584125851258612587125881258912590125911259212593125941259512596125971259812599126001260112602126031260412605126061260712608126091261012611126121261312614126151261612617126181261912620126211262212623126241262512626126271262812629126301263112632126331263412635126361263712638126391264012641126421264312644126451264612647126481264912650126511265212653126541265512656126571265812659126601266112662126631266412665126661266712668126691267012671126721267312674126751267612677126781267912680126811268212683126841268512686126871268812689126901269112692126931269412695126961269712698126991270012701127021270312704127051270612707127081270912710127111271212713127141271512716127171271812719127201272112722127231272412725127261272712728127291273012731127321273312734127351273612737127381273912740127411274212743127441274512746127471274812749127501275112752127531275412755127561275712758127591276012761127621276312764127651276612767127681276912770127711277212773127741277512776127771277812779127801278112782127831278412785127861278712788127891279012791127921279312794127951279612797127981279912800128011280212803128041280512806128071280812809128101281112812128131281412815128161281712818128191282012821128221282312824128251282612827128281282912830128311283212833128341283512836128371283812839128401284112842128431284412845128461284712848128491285012851128521285312854128551285612857128581285912860128611286212863128641286512866128671286812869128701287112872128731287412875128761287712878128791288012881128821288312884128851288612887128881288912890128911289212893128941289512896128971289812899129001290112902129031290412905129061290712908129091291012911129121291312914129151291612917129181291912920129211292212923129241292512926129271292812929129301293112932129331293412935129361293712938129391294012941129421294312944129451294612947129481294912950129511295212953129541295512956129571295812959129601296112962129631296412965129661296712968129691297012971129721297312974129751297612977129781297912980129811298212983129841298512986129871298812989129901299112992129931299412995129961299712998129991300013001130021300313004130051300613007130081300913010130111301213013130141301513016130171301813019130201302113022130231302413025130261302713028130291303013031130321303313034130351303613037130381303913040130411304213043130441304513046130471304813049130501305113052130531305413055130561305713058130591306013061130621306313064130651306613067130681306913070130711307213073130741307513076130771307813079130801308113082130831308413085130861308713088130891309013091130921309313094130951309613097130981309913100131011310213103131041310513106131071310813109131101311113112131131311413115131161311713118131191312013121131221312313124131251312613127131281312913130131311313213133131341313513136131371313813139131401314113142131431314413145131461314713148131491315013151131521315313154131551315613157131581315913160131611316213163131641316513166131671316813169131701317113172131731317413175131761317713178131791318013181131821318313184131851318613187131881318913190131911319213193131941319513196131971319813199132001320113202132031320413205132061320713208132091321013211132121321313214132151321613217132181321913220132211322213223132241322513226132271322813229132301323113232132331323413235132361323713238132391324013241132421324313244132451324613247132481324913250132511325213253132541325513256132571325813259132601326113262132631326413265132661326713268132691327013271132721327313274132751327613277132781327913280132811328213283132841328513286132871328813289132901329113292132931329413295132961329713298132991330013301133021330313304133051330613307133081330913310133111331213313133141331513316133171331813319133201332113322133231332413325133261332713328133291333013331133321333313334133351333613337133381333913340133411334213343133441334513346133471334813349133501335113352133531335413355133561335713358
  1. #ifndef USE_LIBSQLITE3
  2. /*
  3. ** 2001-09-15
  4. **
  5. ** The author disclaims copyright to this source code. In place of
  6. ** a legal notice, here is a blessing:
  7. **
  8. ** May you do good and not evil.
  9. ** May you find forgiveness for yourself and forgive others.
  10. ** May you share freely, never taking more than you give.
  11. **
  12. *************************************************************************
  13. ** This header file defines the interface that the SQLite library
  14. ** presents to client programs. If a C-function, structure, datatype,
  15. ** or constant definition does not appear in this file, then it is
  16. ** not a published API of SQLite, is subject to change without
  17. ** notice, and should not be referenced by programs that use SQLite.
  18. **
  19. ** Some of the definitions that are in this file are marked as
  20. ** "experimental". Experimental interfaces are normally new
  21. ** features recently added to SQLite. We do not anticipate changes
  22. ** to experimental interfaces but reserve the right to make minor changes
  23. ** if experience from use "in the wild" suggest such changes are prudent.
  24. **
  25. ** The official C-language API documentation for SQLite is derived
  26. ** from comments in this file. This file is the authoritative source
  27. ** on how SQLite interfaces are supposed to operate.
  28. **
  29. ** The name of this file under configuration management is "sqlite.h.in".
  30. ** The makefile makes some minor changes to this file (such as inserting
  31. ** the version number) and changes its name to "sqlite3.h" as
  32. ** part of the build process.
  33. */
  34. #ifndef SQLITE3_H
  35. #define SQLITE3_H
  36. #include <stdarg.h> /* Needed for the definition of va_list */
  37. /*
  38. ** Make sure we can call this stuff from C++.
  39. */
  40. #ifdef __cplusplus
  41. extern "C" {
  42. #endif
  43. /*
  44. ** Facilitate override of interface linkage and calling conventions.
  45. ** Be aware that these macros may not be used within this particular
  46. ** translation of the amalgamation and its associated header file.
  47. **
  48. ** The SQLITE_EXTERN and SQLITE_API macros are used to instruct the
  49. ** compiler that the target identifier should have external linkage.
  50. **
  51. ** The SQLITE_CDECL macro is used to set the calling convention for
  52. ** public functions that accept a variable number of arguments.
  53. **
  54. ** The SQLITE_APICALL macro is used to set the calling convention for
  55. ** public functions that accept a fixed number of arguments.
  56. **
  57. ** The SQLITE_STDCALL macro is no longer used and is now deprecated.
  58. **
  59. ** The SQLITE_CALLBACK macro is used to set the calling convention for
  60. ** function pointers.
  61. **
  62. ** The SQLITE_SYSAPI macro is used to set the calling convention for
  63. ** functions provided by the operating system.
  64. **
  65. ** Currently, the SQLITE_CDECL, SQLITE_APICALL, SQLITE_CALLBACK, and
  66. ** SQLITE_SYSAPI macros are used only when building for environments
  67. ** that require non-default calling conventions.
  68. */
  69. #ifndef SQLITE_EXTERN
  70. # define SQLITE_EXTERN extern
  71. #endif
  72. #ifndef SQLITE_API
  73. # define SQLITE_API
  74. #endif
  75. #ifndef SQLITE_CDECL
  76. # define SQLITE_CDECL
  77. #endif
  78. #ifndef SQLITE_APICALL
  79. # define SQLITE_APICALL
  80. #endif
  81. #ifndef SQLITE_STDCALL
  82. # define SQLITE_STDCALL SQLITE_APICALL
  83. #endif
  84. #ifndef SQLITE_CALLBACK
  85. # define SQLITE_CALLBACK
  86. #endif
  87. #ifndef SQLITE_SYSAPI
  88. # define SQLITE_SYSAPI
  89. #endif
  90. /*
  91. ** These no-op macros are used in front of interfaces to mark those
  92. ** interfaces as either deprecated or experimental. New applications
  93. ** should not use deprecated interfaces - they are supported for backwards
  94. ** compatibility only. Application writers should be aware that
  95. ** experimental interfaces are subject to change in point releases.
  96. **
  97. ** These macros used to resolve to various kinds of compiler magic that
  98. ** would generate warning messages when they were used. But that
  99. ** compiler magic ended up generating such a flurry of bug reports
  100. ** that we have taken it all out and gone back to using simple
  101. ** noop macros.
  102. */
  103. #define SQLITE_DEPRECATED
  104. #define SQLITE_EXPERIMENTAL
  105. /*
  106. ** Ensure these symbols were not defined by some previous header file.
  107. */
  108. #ifdef SQLITE_VERSION
  109. # undef SQLITE_VERSION
  110. #endif
  111. #ifdef SQLITE_VERSION_NUMBER
  112. # undef SQLITE_VERSION_NUMBER
  113. #endif
  114. /*
  115. ** CAPI3REF: Compile-Time Library Version Numbers
  116. **
  117. ** ^(The [SQLITE_VERSION] C preprocessor macro in the sqlite3.h header
  118. ** evaluates to a string literal that is the SQLite version in the
  119. ** format "X.Y.Z" where X is the major version number (always 3 for
  120. ** SQLite3) and Y is the minor version number and Z is the release number.)^
  121. ** ^(The [SQLITE_VERSION_NUMBER] C preprocessor macro resolves to an integer
  122. ** with the value (X*1000000 + Y*1000 + Z) where X, Y, and Z are the same
  123. ** numbers used in [SQLITE_VERSION].)^
  124. ** The SQLITE_VERSION_NUMBER for any given release of SQLite will also
  125. ** be larger than the release from which it is derived. Either Y will
  126. ** be held constant and Z will be incremented or else Y will be incremented
  127. ** and Z will be reset to zero.
  128. **
  129. ** Since [version 3.6.18] ([dateof:3.6.18]),
  130. ** SQLite source code has been stored in the
  131. ** <a href="http://www.fossil-scm.org/">Fossil configuration management
  132. ** system</a>. ^The SQLITE_SOURCE_ID macro evaluates to
  133. ** a string which identifies a particular check-in of SQLite
  134. ** within its configuration management system. ^The SQLITE_SOURCE_ID
  135. ** string contains the date and time of the check-in (UTC) and a SHA1
  136. ** or SHA3-256 hash of the entire source tree. If the source code has
  137. ** been edited in any way since it was last checked in, then the last
  138. ** four hexadecimal digits of the hash may be modified.
  139. **
  140. ** See also: [sqlite3_libversion()],
  141. ** [sqlite3_libversion_number()], [sqlite3_sourceid()],
  142. ** [sqlite_version()] and [sqlite_source_id()].
  143. */
  144. #define SQLITE_VERSION "3.44.0"
  145. #define SQLITE_VERSION_NUMBER 3044000
  146. #define SQLITE_SOURCE_ID "2023-11-01 11:23:50 17129ba1ff7f0daf37100ee82d507aef7827cf38de1866e2633096ae6ad81301"
  147. /*
  148. ** CAPI3REF: Run-Time Library Version Numbers
  149. ** KEYWORDS: sqlite3_version sqlite3_sourceid
  150. **
  151. ** These interfaces provide the same information as the [SQLITE_VERSION],
  152. ** [SQLITE_VERSION_NUMBER], and [SQLITE_SOURCE_ID] C preprocessor macros
  153. ** but are associated with the library instead of the header file. ^(Cautious
  154. ** programmers might include assert() statements in their application to
  155. ** verify that values returned by these interfaces match the macros in
  156. ** the header, and thus ensure that the application is
  157. ** compiled with matching library and header files.
  158. **
  159. ** <blockquote><pre>
  160. ** assert( sqlite3_libversion_number()==SQLITE_VERSION_NUMBER );
  161. ** assert( strncmp(sqlite3_sourceid(),SQLITE_SOURCE_ID,80)==0 );
  162. ** assert( strcmp(sqlite3_libversion(),SQLITE_VERSION)==0 );
  163. ** </pre></blockquote>)^
  164. **
  165. ** ^The sqlite3_version[] string constant contains the text of [SQLITE_VERSION]
  166. ** macro. ^The sqlite3_libversion() function returns a pointer to the
  167. ** to the sqlite3_version[] string constant. The sqlite3_libversion()
  168. ** function is provided for use in DLLs since DLL users usually do not have
  169. ** direct access to string constants within the DLL. ^The
  170. ** sqlite3_libversion_number() function returns an integer equal to
  171. ** [SQLITE_VERSION_NUMBER]. ^(The sqlite3_sourceid() function returns
  172. ** a pointer to a string constant whose value is the same as the
  173. ** [SQLITE_SOURCE_ID] C preprocessor macro. Except if SQLite is built
  174. ** using an edited copy of [the amalgamation], then the last four characters
  175. ** of the hash might be different from [SQLITE_SOURCE_ID].)^
  176. **
  177. ** See also: [sqlite_version()] and [sqlite_source_id()].
  178. */
  179. SQLITE_API SQLITE_EXTERN const char sqlite3_version[];
  180. SQLITE_API const char *sqlite3_libversion(void);
  181. SQLITE_API const char *sqlite3_sourceid(void);
  182. SQLITE_API int sqlite3_libversion_number(void);
  183. /*
  184. ** CAPI3REF: Run-Time Library Compilation Options Diagnostics
  185. **
  186. ** ^The sqlite3_compileoption_used() function returns 0 or 1
  187. ** indicating whether the specified option was defined at
  188. ** compile time. ^The SQLITE_ prefix may be omitted from the
  189. ** option name passed to sqlite3_compileoption_used().
  190. **
  191. ** ^The sqlite3_compileoption_get() function allows iterating
  192. ** over the list of options that were defined at compile time by
  193. ** returning the N-th compile time option string. ^If N is out of range,
  194. ** sqlite3_compileoption_get() returns a NULL pointer. ^The SQLITE_
  195. ** prefix is omitted from any strings returned by
  196. ** sqlite3_compileoption_get().
  197. **
  198. ** ^Support for the diagnostic functions sqlite3_compileoption_used()
  199. ** and sqlite3_compileoption_get() may be omitted by specifying the
  200. ** [SQLITE_OMIT_COMPILEOPTION_DIAGS] option at compile time.
  201. **
  202. ** See also: SQL functions [sqlite_compileoption_used()] and
  203. ** [sqlite_compileoption_get()] and the [compile_options pragma].
  204. */
  205. #ifndef SQLITE_OMIT_COMPILEOPTION_DIAGS
  206. SQLITE_API int sqlite3_compileoption_used(const char *zOptName);
  207. SQLITE_API const char *sqlite3_compileoption_get(int N);
  208. #else
  209. # define sqlite3_compileoption_used(X) 0
  210. # define sqlite3_compileoption_get(X) ((void*)0)
  211. #endif
  212. /*
  213. ** CAPI3REF: Test To See If The Library Is Threadsafe
  214. **
  215. ** ^The sqlite3_threadsafe() function returns zero if and only if
  216. ** SQLite was compiled with mutexing code omitted due to the
  217. ** [SQLITE_THREADSAFE] compile-time option being set to 0.
  218. **
  219. ** SQLite can be compiled with or without mutexes. When
  220. ** the [SQLITE_THREADSAFE] C preprocessor macro is 1 or 2, mutexes
  221. ** are enabled and SQLite is threadsafe. When the
  222. ** [SQLITE_THREADSAFE] macro is 0,
  223. ** the mutexes are omitted. Without the mutexes, it is not safe
  224. ** to use SQLite concurrently from more than one thread.
  225. **
  226. ** Enabling mutexes incurs a measurable performance penalty.
  227. ** So if speed is of utmost importance, it makes sense to disable
  228. ** the mutexes. But for maximum safety, mutexes should be enabled.
  229. ** ^The default behavior is for mutexes to be enabled.
  230. **
  231. ** This interface can be used by an application to make sure that the
  232. ** version of SQLite that it is linking against was compiled with
  233. ** the desired setting of the [SQLITE_THREADSAFE] macro.
  234. **
  235. ** This interface only reports on the compile-time mutex setting
  236. ** of the [SQLITE_THREADSAFE] flag. If SQLite is compiled with
  237. ** SQLITE_THREADSAFE=1 or =2 then mutexes are enabled by default but
  238. ** can be fully or partially disabled using a call to [sqlite3_config()]
  239. ** with the verbs [SQLITE_CONFIG_SINGLETHREAD], [SQLITE_CONFIG_MULTITHREAD],
  240. ** or [SQLITE_CONFIG_SERIALIZED]. ^(The return value of the
  241. ** sqlite3_threadsafe() function shows only the compile-time setting of
  242. ** thread safety, not any run-time changes to that setting made by
  243. ** sqlite3_config(). In other words, the return value from sqlite3_threadsafe()
  244. ** is unchanged by calls to sqlite3_config().)^
  245. **
  246. ** See the [threading mode] documentation for additional information.
  247. */
  248. SQLITE_API int sqlite3_threadsafe(void);
  249. /*
  250. ** CAPI3REF: Database Connection Handle
  251. ** KEYWORDS: {database connection} {database connections}
  252. **
  253. ** Each open SQLite database is represented by a pointer to an instance of
  254. ** the opaque structure named "sqlite3". It is useful to think of an sqlite3
  255. ** pointer as an object. The [sqlite3_open()], [sqlite3_open16()], and
  256. ** [sqlite3_open_v2()] interfaces are its constructors, and [sqlite3_close()]
  257. ** and [sqlite3_close_v2()] are its destructors. There are many other
  258. ** interfaces (such as
  259. ** [sqlite3_prepare_v2()], [sqlite3_create_function()], and
  260. ** [sqlite3_busy_timeout()] to name but three) that are methods on an
  261. ** sqlite3 object.
  262. */
  263. typedef struct sqlite3 sqlite3;
  264. /*
  265. ** CAPI3REF: 64-Bit Integer Types
  266. ** KEYWORDS: sqlite_int64 sqlite_uint64
  267. **
  268. ** Because there is no cross-platform way to specify 64-bit integer types
  269. ** SQLite includes typedefs for 64-bit signed and unsigned integers.
  270. **
  271. ** The sqlite3_int64 and sqlite3_uint64 are the preferred type definitions.
  272. ** The sqlite_int64 and sqlite_uint64 types are supported for backwards
  273. ** compatibility only.
  274. **
  275. ** ^The sqlite3_int64 and sqlite_int64 types can store integer values
  276. ** between -9223372036854775808 and +9223372036854775807 inclusive. ^The
  277. ** sqlite3_uint64 and sqlite_uint64 types can store integer values
  278. ** between 0 and +18446744073709551615 inclusive.
  279. */
  280. #ifdef SQLITE_INT64_TYPE
  281. typedef SQLITE_INT64_TYPE sqlite_int64;
  282. # ifdef SQLITE_UINT64_TYPE
  283. typedef SQLITE_UINT64_TYPE sqlite_uint64;
  284. # else
  285. typedef unsigned SQLITE_INT64_TYPE sqlite_uint64;
  286. # endif
  287. #elif defined(_MSC_VER) || defined(__BORLANDC__)
  288. typedef __int64 sqlite_int64;
  289. typedef unsigned __int64 sqlite_uint64;
  290. #else
  291. typedef long long int sqlite_int64;
  292. typedef unsigned long long int sqlite_uint64;
  293. #endif
  294. typedef sqlite_int64 sqlite3_int64;
  295. typedef sqlite_uint64 sqlite3_uint64;
  296. /*
  297. ** If compiling for a processor that lacks floating point support,
  298. ** substitute integer for floating-point.
  299. */
  300. #ifdef SQLITE_OMIT_FLOATING_POINT
  301. # define double sqlite3_int64
  302. #endif
  303. /*
  304. ** CAPI3REF: Closing A Database Connection
  305. ** DESTRUCTOR: sqlite3
  306. **
  307. ** ^The sqlite3_close() and sqlite3_close_v2() routines are destructors
  308. ** for the [sqlite3] object.
  309. ** ^Calls to sqlite3_close() and sqlite3_close_v2() return [SQLITE_OK] if
  310. ** the [sqlite3] object is successfully destroyed and all associated
  311. ** resources are deallocated.
  312. **
  313. ** Ideally, applications should [sqlite3_finalize | finalize] all
  314. ** [prepared statements], [sqlite3_blob_close | close] all [BLOB handles], and
  315. ** [sqlite3_backup_finish | finish] all [sqlite3_backup] objects associated
  316. ** with the [sqlite3] object prior to attempting to close the object.
  317. ** ^If the database connection is associated with unfinalized prepared
  318. ** statements, BLOB handlers, and/or unfinished sqlite3_backup objects then
  319. ** sqlite3_close() will leave the database connection open and return
  320. ** [SQLITE_BUSY]. ^If sqlite3_close_v2() is called with unfinalized prepared
  321. ** statements, unclosed BLOB handlers, and/or unfinished sqlite3_backups,
  322. ** it returns [SQLITE_OK] regardless, but instead of deallocating the database
  323. ** connection immediately, it marks the database connection as an unusable
  324. ** "zombie" and makes arrangements to automatically deallocate the database
  325. ** connection after all prepared statements are finalized, all BLOB handles
  326. ** are closed, and all backups have finished. The sqlite3_close_v2() interface
  327. ** is intended for use with host languages that are garbage collected, and
  328. ** where the order in which destructors are called is arbitrary.
  329. **
  330. ** ^If an [sqlite3] object is destroyed while a transaction is open,
  331. ** the transaction is automatically rolled back.
  332. **
  333. ** The C parameter to [sqlite3_close(C)] and [sqlite3_close_v2(C)]
  334. ** must be either a NULL
  335. ** pointer or an [sqlite3] object pointer obtained
  336. ** from [sqlite3_open()], [sqlite3_open16()], or
  337. ** [sqlite3_open_v2()], and not previously closed.
  338. ** ^Calling sqlite3_close() or sqlite3_close_v2() with a NULL pointer
  339. ** argument is a harmless no-op.
  340. */
  341. SQLITE_API int sqlite3_close(sqlite3*);
  342. SQLITE_API int sqlite3_close_v2(sqlite3*);
  343. /*
  344. ** The type for a callback function.
  345. ** This is legacy and deprecated. It is included for historical
  346. ** compatibility and is not documented.
  347. */
  348. typedef int (*sqlite3_callback)(void*,int,char**, char**);
  349. /*
  350. ** CAPI3REF: One-Step Query Execution Interface
  351. ** METHOD: sqlite3
  352. **
  353. ** The sqlite3_exec() interface is a convenience wrapper around
  354. ** [sqlite3_prepare_v2()], [sqlite3_step()], and [sqlite3_finalize()],
  355. ** that allows an application to run multiple statements of SQL
  356. ** without having to use a lot of C code.
  357. **
  358. ** ^The sqlite3_exec() interface runs zero or more UTF-8 encoded,
  359. ** semicolon-separate SQL statements passed into its 2nd argument,
  360. ** in the context of the [database connection] passed in as its 1st
  361. ** argument. ^If the callback function of the 3rd argument to
  362. ** sqlite3_exec() is not NULL, then it is invoked for each result row
  363. ** coming out of the evaluated SQL statements. ^The 4th argument to
  364. ** sqlite3_exec() is relayed through to the 1st argument of each
  365. ** callback invocation. ^If the callback pointer to sqlite3_exec()
  366. ** is NULL, then no callback is ever invoked and result rows are
  367. ** ignored.
  368. **
  369. ** ^If an error occurs while evaluating the SQL statements passed into
  370. ** sqlite3_exec(), then execution of the current statement stops and
  371. ** subsequent statements are skipped. ^If the 5th parameter to sqlite3_exec()
  372. ** is not NULL then any error message is written into memory obtained
  373. ** from [sqlite3_malloc()] and passed back through the 5th parameter.
  374. ** To avoid memory leaks, the application should invoke [sqlite3_free()]
  375. ** on error message strings returned through the 5th parameter of
  376. ** sqlite3_exec() after the error message string is no longer needed.
  377. ** ^If the 5th parameter to sqlite3_exec() is not NULL and no errors
  378. ** occur, then sqlite3_exec() sets the pointer in its 5th parameter to
  379. ** NULL before returning.
  380. **
  381. ** ^If an sqlite3_exec() callback returns non-zero, the sqlite3_exec()
  382. ** routine returns SQLITE_ABORT without invoking the callback again and
  383. ** without running any subsequent SQL statements.
  384. **
  385. ** ^The 2nd argument to the sqlite3_exec() callback function is the
  386. ** number of columns in the result. ^The 3rd argument to the sqlite3_exec()
  387. ** callback is an array of pointers to strings obtained as if from
  388. ** [sqlite3_column_text()], one for each column. ^If an element of a
  389. ** result row is NULL then the corresponding string pointer for the
  390. ** sqlite3_exec() callback is a NULL pointer. ^The 4th argument to the
  391. ** sqlite3_exec() callback is an array of pointers to strings where each
  392. ** entry represents the name of corresponding result column as obtained
  393. ** from [sqlite3_column_name()].
  394. **
  395. ** ^If the 2nd parameter to sqlite3_exec() is a NULL pointer, a pointer
  396. ** to an empty string, or a pointer that contains only whitespace and/or
  397. ** SQL comments, then no SQL statements are evaluated and the database
  398. ** is not changed.
  399. **
  400. ** Restrictions:
  401. **
  402. ** <ul>
  403. ** <li> The application must ensure that the 1st parameter to sqlite3_exec()
  404. ** is a valid and open [database connection].
  405. ** <li> The application must not close the [database connection] specified by
  406. ** the 1st parameter to sqlite3_exec() while sqlite3_exec() is running.
  407. ** <li> The application must not modify the SQL statement text passed into
  408. ** the 2nd parameter of sqlite3_exec() while sqlite3_exec() is running.
  409. ** </ul>
  410. */
  411. SQLITE_API int sqlite3_exec(
  412. sqlite3*, /* An open database */
  413. const char *sql, /* SQL to be evaluated */
  414. int (*callback)(void*,int,char**,char**), /* Callback function */
  415. void *, /* 1st argument to callback */
  416. char **errmsg /* Error msg written here */
  417. );
  418. /*
  419. ** CAPI3REF: Result Codes
  420. ** KEYWORDS: {result code definitions}
  421. **
  422. ** Many SQLite functions return an integer result code from the set shown
  423. ** here in order to indicate success or failure.
  424. **
  425. ** New error codes may be added in future versions of SQLite.
  426. **
  427. ** See also: [extended result code definitions]
  428. */
  429. #define SQLITE_OK 0 /* Successful result */
  430. /* beginning-of-error-codes */
  431. #define SQLITE_ERROR 1 /* Generic error */
  432. #define SQLITE_INTERNAL 2 /* Internal logic error in SQLite */
  433. #define SQLITE_PERM 3 /* Access permission denied */
  434. #define SQLITE_ABORT 4 /* Callback routine requested an abort */
  435. #define SQLITE_BUSY 5 /* The database file is locked */
  436. #define SQLITE_LOCKED 6 /* A table in the database is locked */
  437. #define SQLITE_NOMEM 7 /* A malloc() failed */
  438. #define SQLITE_READONLY 8 /* Attempt to write a readonly database */
  439. #define SQLITE_INTERRUPT 9 /* Operation terminated by sqlite3_interrupt()*/
  440. #define SQLITE_IOERR 10 /* Some kind of disk I/O error occurred */
  441. #define SQLITE_CORRUPT 11 /* The database disk image is malformed */
  442. #define SQLITE_NOTFOUND 12 /* Unknown opcode in sqlite3_file_control() */
  443. #define SQLITE_FULL 13 /* Insertion failed because database is full */
  444. #define SQLITE_CANTOPEN 14 /* Unable to open the database file */
  445. #define SQLITE_PROTOCOL 15 /* Database lock protocol error */
  446. #define SQLITE_EMPTY 16 /* Internal use only */
  447. #define SQLITE_SCHEMA 17 /* The database schema changed */
  448. #define SQLITE_TOOBIG 18 /* String or BLOB exceeds size limit */
  449. #define SQLITE_CONSTRAINT 19 /* Abort due to constraint violation */
  450. #define SQLITE_MISMATCH 20 /* Data type mismatch */
  451. #define SQLITE_MISUSE 21 /* Library used incorrectly */
  452. #define SQLITE_NOLFS 22 /* Uses OS features not supported on host */
  453. #define SQLITE_AUTH 23 /* Authorization denied */
  454. #define SQLITE_FORMAT 24 /* Not used */
  455. #define SQLITE_RANGE 25 /* 2nd parameter to sqlite3_bind out of range */
  456. #define SQLITE_NOTADB 26 /* File opened that is not a database file */
  457. #define SQLITE_NOTICE 27 /* Notifications from sqlite3_log() */
  458. #define SQLITE_WARNING 28 /* Warnings from sqlite3_log() */
  459. #define SQLITE_ROW 100 /* sqlite3_step() has another row ready */
  460. #define SQLITE_DONE 101 /* sqlite3_step() has finished executing */
  461. /* end-of-error-codes */
  462. /*
  463. ** CAPI3REF: Extended Result Codes
  464. ** KEYWORDS: {extended result code definitions}
  465. **
  466. ** In its default configuration, SQLite API routines return one of 30 integer
  467. ** [result codes]. However, experience has shown that many of
  468. ** these result codes are too coarse-grained. They do not provide as
  469. ** much information about problems as programmers might like. In an effort to
  470. ** address this, newer versions of SQLite (version 3.3.8 [dateof:3.3.8]
  471. ** and later) include
  472. ** support for additional result codes that provide more detailed information
  473. ** about errors. These [extended result codes] are enabled or disabled
  474. ** on a per database connection basis using the
  475. ** [sqlite3_extended_result_codes()] API. Or, the extended code for
  476. ** the most recent error can be obtained using
  477. ** [sqlite3_extended_errcode()].
  478. */
  479. #define SQLITE_ERROR_MISSING_COLLSEQ (SQLITE_ERROR | (1<<8))
  480. #define SQLITE_ERROR_RETRY (SQLITE_ERROR | (2<<8))
  481. #define SQLITE_ERROR_SNAPSHOT (SQLITE_ERROR | (3<<8))
  482. #define SQLITE_IOERR_READ (SQLITE_IOERR | (1<<8))
  483. #define SQLITE_IOERR_SHORT_READ (SQLITE_IOERR | (2<<8))
  484. #define SQLITE_IOERR_WRITE (SQLITE_IOERR | (3<<8))
  485. #define SQLITE_IOERR_FSYNC (SQLITE_IOERR | (4<<8))
  486. #define SQLITE_IOERR_DIR_FSYNC (SQLITE_IOERR | (5<<8))
  487. #define SQLITE_IOERR_TRUNCATE (SQLITE_IOERR | (6<<8))
  488. #define SQLITE_IOERR_FSTAT (SQLITE_IOERR | (7<<8))
  489. #define SQLITE_IOERR_UNLOCK (SQLITE_IOERR | (8<<8))
  490. #define SQLITE_IOERR_RDLOCK (SQLITE_IOERR | (9<<8))
  491. #define SQLITE_IOERR_DELETE (SQLITE_IOERR | (10<<8))
  492. #define SQLITE_IOERR_BLOCKED (SQLITE_IOERR | (11<<8))
  493. #define SQLITE_IOERR_NOMEM (SQLITE_IOERR | (12<<8))
  494. #define SQLITE_IOERR_ACCESS (SQLITE_IOERR | (13<<8))
  495. #define SQLITE_IOERR_CHECKRESERVEDLOCK (SQLITE_IOERR | (14<<8))
  496. #define SQLITE_IOERR_LOCK (SQLITE_IOERR | (15<<8))
  497. #define SQLITE_IOERR_CLOSE (SQLITE_IOERR | (16<<8))
  498. #define SQLITE_IOERR_DIR_CLOSE (SQLITE_IOERR | (17<<8))
  499. #define SQLITE_IOERR_SHMOPEN (SQLITE_IOERR | (18<<8))
  500. #define SQLITE_IOERR_SHMSIZE (SQLITE_IOERR | (19<<8))
  501. #define SQLITE_IOERR_SHMLOCK (SQLITE_IOERR | (20<<8))
  502. #define SQLITE_IOERR_SHMMAP (SQLITE_IOERR | (21<<8))
  503. #define SQLITE_IOERR_SEEK (SQLITE_IOERR | (22<<8))
  504. #define SQLITE_IOERR_DELETE_NOENT (SQLITE_IOERR | (23<<8))
  505. #define SQLITE_IOERR_MMAP (SQLITE_IOERR | (24<<8))
  506. #define SQLITE_IOERR_GETTEMPPATH (SQLITE_IOERR | (25<<8))
  507. #define SQLITE_IOERR_CONVPATH (SQLITE_IOERR | (26<<8))
  508. #define SQLITE_IOERR_VNODE (SQLITE_IOERR | (27<<8))
  509. #define SQLITE_IOERR_AUTH (SQLITE_IOERR | (28<<8))
  510. #define SQLITE_IOERR_BEGIN_ATOMIC (SQLITE_IOERR | (29<<8))
  511. #define SQLITE_IOERR_COMMIT_ATOMIC (SQLITE_IOERR | (30<<8))
  512. #define SQLITE_IOERR_ROLLBACK_ATOMIC (SQLITE_IOERR | (31<<8))
  513. #define SQLITE_IOERR_DATA (SQLITE_IOERR | (32<<8))
  514. #define SQLITE_IOERR_CORRUPTFS (SQLITE_IOERR | (33<<8))
  515. #define SQLITE_IOERR_IN_PAGE (SQLITE_IOERR | (34<<8))
  516. #define SQLITE_LOCKED_SHAREDCACHE (SQLITE_LOCKED | (1<<8))
  517. #define SQLITE_LOCKED_VTAB (SQLITE_LOCKED | (2<<8))
  518. #define SQLITE_BUSY_RECOVERY (SQLITE_BUSY | (1<<8))
  519. #define SQLITE_BUSY_SNAPSHOT (SQLITE_BUSY | (2<<8))
  520. #define SQLITE_BUSY_TIMEOUT (SQLITE_BUSY | (3<<8))
  521. #define SQLITE_CANTOPEN_NOTEMPDIR (SQLITE_CANTOPEN | (1<<8))
  522. #define SQLITE_CANTOPEN_ISDIR (SQLITE_CANTOPEN | (2<<8))
  523. #define SQLITE_CANTOPEN_FULLPATH (SQLITE_CANTOPEN | (3<<8))
  524. #define SQLITE_CANTOPEN_CONVPATH (SQLITE_CANTOPEN | (4<<8))
  525. #define SQLITE_CANTOPEN_DIRTYWAL (SQLITE_CANTOPEN | (5<<8)) /* Not Used */
  526. #define SQLITE_CANTOPEN_SYMLINK (SQLITE_CANTOPEN | (6<<8))
  527. #define SQLITE_CORRUPT_VTAB (SQLITE_CORRUPT | (1<<8))
  528. #define SQLITE_CORRUPT_SEQUENCE (SQLITE_CORRUPT | (2<<8))
  529. #define SQLITE_CORRUPT_INDEX (SQLITE_CORRUPT | (3<<8))
  530. #define SQLITE_READONLY_RECOVERY (SQLITE_READONLY | (1<<8))
  531. #define SQLITE_READONLY_CANTLOCK (SQLITE_READONLY | (2<<8))
  532. #define SQLITE_READONLY_ROLLBACK (SQLITE_READONLY | (3<<8))
  533. #define SQLITE_READONLY_DBMOVED (SQLITE_READONLY | (4<<8))
  534. #define SQLITE_READONLY_CANTINIT (SQLITE_READONLY | (5<<8))
  535. #define SQLITE_READONLY_DIRECTORY (SQLITE_READONLY | (6<<8))
  536. #define SQLITE_ABORT_ROLLBACK (SQLITE_ABORT | (2<<8))
  537. #define SQLITE_CONSTRAINT_CHECK (SQLITE_CONSTRAINT | (1<<8))
  538. #define SQLITE_CONSTRAINT_COMMITHOOK (SQLITE_CONSTRAINT | (2<<8))
  539. #define SQLITE_CONSTRAINT_FOREIGNKEY (SQLITE_CONSTRAINT | (3<<8))
  540. #define SQLITE_CONSTRAINT_FUNCTION (SQLITE_CONSTRAINT | (4<<8))
  541. #define SQLITE_CONSTRAINT_NOTNULL (SQLITE_CONSTRAINT | (5<<8))
  542. #define SQLITE_CONSTRAINT_PRIMARYKEY (SQLITE_CONSTRAINT | (6<<8))
  543. #define SQLITE_CONSTRAINT_TRIGGER (SQLITE_CONSTRAINT | (7<<8))
  544. #define SQLITE_CONSTRAINT_UNIQUE (SQLITE_CONSTRAINT | (8<<8))
  545. #define SQLITE_CONSTRAINT_VTAB (SQLITE_CONSTRAINT | (9<<8))
  546. #define SQLITE_CONSTRAINT_ROWID (SQLITE_CONSTRAINT |(10<<8))
  547. #define SQLITE_CONSTRAINT_PINNED (SQLITE_CONSTRAINT |(11<<8))
  548. #define SQLITE_CONSTRAINT_DATATYPE (SQLITE_CONSTRAINT |(12<<8))
  549. #define SQLITE_NOTICE_RECOVER_WAL (SQLITE_NOTICE | (1<<8))
  550. #define SQLITE_NOTICE_RECOVER_ROLLBACK (SQLITE_NOTICE | (2<<8))
  551. #define SQLITE_NOTICE_RBU (SQLITE_NOTICE | (3<<8))
  552. #define SQLITE_WARNING_AUTOINDEX (SQLITE_WARNING | (1<<8))
  553. #define SQLITE_AUTH_USER (SQLITE_AUTH | (1<<8))
  554. #define SQLITE_OK_LOAD_PERMANENTLY (SQLITE_OK | (1<<8))
  555. #define SQLITE_OK_SYMLINK (SQLITE_OK | (2<<8)) /* internal use only */
  556. /*
  557. ** CAPI3REF: Flags For File Open Operations
  558. **
  559. ** These bit values are intended for use in the
  560. ** 3rd parameter to the [sqlite3_open_v2()] interface and
  561. ** in the 4th parameter to the [sqlite3_vfs.xOpen] method.
  562. **
  563. ** Only those flags marked as "Ok for sqlite3_open_v2()" may be
  564. ** used as the third argument to the [sqlite3_open_v2()] interface.
  565. ** The other flags have historically been ignored by sqlite3_open_v2(),
  566. ** though future versions of SQLite might change so that an error is
  567. ** raised if any of the disallowed bits are passed into sqlite3_open_v2().
  568. ** Applications should not depend on the historical behavior.
  569. **
  570. ** Note in particular that passing the SQLITE_OPEN_EXCLUSIVE flag into
  571. ** [sqlite3_open_v2()] does *not* cause the underlying database file
  572. ** to be opened using O_EXCL. Passing SQLITE_OPEN_EXCLUSIVE into
  573. ** [sqlite3_open_v2()] has historically be a no-op and might become an
  574. ** error in future versions of SQLite.
  575. */
  576. #define SQLITE_OPEN_READONLY 0x00000001 /* Ok for sqlite3_open_v2() */
  577. #define SQLITE_OPEN_READWRITE 0x00000002 /* Ok for sqlite3_open_v2() */
  578. #define SQLITE_OPEN_CREATE 0x00000004 /* Ok for sqlite3_open_v2() */
  579. #define SQLITE_OPEN_DELETEONCLOSE 0x00000008 /* VFS only */
  580. #define SQLITE_OPEN_EXCLUSIVE 0x00000010 /* VFS only */
  581. #define SQLITE_OPEN_AUTOPROXY 0x00000020 /* VFS only */
  582. #define SQLITE_OPEN_URI 0x00000040 /* Ok for sqlite3_open_v2() */
  583. #define SQLITE_OPEN_MEMORY 0x00000080 /* Ok for sqlite3_open_v2() */
  584. #define SQLITE_OPEN_MAIN_DB 0x00000100 /* VFS only */
  585. #define SQLITE_OPEN_TEMP_DB 0x00000200 /* VFS only */
  586. #define SQLITE_OPEN_TRANSIENT_DB 0x00000400 /* VFS only */
  587. #define SQLITE_OPEN_MAIN_JOURNAL 0x00000800 /* VFS only */
  588. #define SQLITE_OPEN_TEMP_JOURNAL 0x00001000 /* VFS only */
  589. #define SQLITE_OPEN_SUBJOURNAL 0x00002000 /* VFS only */
  590. #define SQLITE_OPEN_SUPER_JOURNAL 0x00004000 /* VFS only */
  591. #define SQLITE_OPEN_NOMUTEX 0x00008000 /* Ok for sqlite3_open_v2() */
  592. #define SQLITE_OPEN_FULLMUTEX 0x00010000 /* Ok for sqlite3_open_v2() */
  593. #define SQLITE_OPEN_SHAREDCACHE 0x00020000 /* Ok for sqlite3_open_v2() */
  594. #define SQLITE_OPEN_PRIVATECACHE 0x00040000 /* Ok for sqlite3_open_v2() */
  595. #define SQLITE_OPEN_WAL 0x00080000 /* VFS only */
  596. #define SQLITE_OPEN_NOFOLLOW 0x01000000 /* Ok for sqlite3_open_v2() */
  597. #define SQLITE_OPEN_EXRESCODE 0x02000000 /* Extended result codes */
  598. /* Reserved: 0x00F00000 */
  599. /* Legacy compatibility: */
  600. #define SQLITE_OPEN_MASTER_JOURNAL 0x00004000 /* VFS only */
  601. /*
  602. ** CAPI3REF: Device Characteristics
  603. **
  604. ** The xDeviceCharacteristics method of the [sqlite3_io_methods]
  605. ** object returns an integer which is a vector of these
  606. ** bit values expressing I/O characteristics of the mass storage
  607. ** device that holds the file that the [sqlite3_io_methods]
  608. ** refers to.
  609. **
  610. ** The SQLITE_IOCAP_ATOMIC property means that all writes of
  611. ** any size are atomic. The SQLITE_IOCAP_ATOMICnnn values
  612. ** mean that writes of blocks that are nnn bytes in size and
  613. ** are aligned to an address which is an integer multiple of
  614. ** nnn are atomic. The SQLITE_IOCAP_SAFE_APPEND value means
  615. ** that when data is appended to a file, the data is appended
  616. ** first then the size of the file is extended, never the other
  617. ** way around. The SQLITE_IOCAP_SEQUENTIAL property means that
  618. ** information is written to disk in the same order as calls
  619. ** to xWrite(). The SQLITE_IOCAP_POWERSAFE_OVERWRITE property means that
  620. ** after reboot following a crash or power loss, the only bytes in a
  621. ** file that were written at the application level might have changed
  622. ** and that adjacent bytes, even bytes within the same sector are
  623. ** guaranteed to be unchanged. The SQLITE_IOCAP_UNDELETABLE_WHEN_OPEN
  624. ** flag indicates that a file cannot be deleted when open. The
  625. ** SQLITE_IOCAP_IMMUTABLE flag indicates that the file is on
  626. ** read-only media and cannot be changed even by processes with
  627. ** elevated privileges.
  628. **
  629. ** The SQLITE_IOCAP_BATCH_ATOMIC property means that the underlying
  630. ** filesystem supports doing multiple write operations atomically when those
  631. ** write operations are bracketed by [SQLITE_FCNTL_BEGIN_ATOMIC_WRITE] and
  632. ** [SQLITE_FCNTL_COMMIT_ATOMIC_WRITE].
  633. */
  634. #define SQLITE_IOCAP_ATOMIC 0x00000001
  635. #define SQLITE_IOCAP_ATOMIC512 0x00000002
  636. #define SQLITE_IOCAP_ATOMIC1K 0x00000004
  637. #define SQLITE_IOCAP_ATOMIC2K 0x00000008
  638. #define SQLITE_IOCAP_ATOMIC4K 0x00000010
  639. #define SQLITE_IOCAP_ATOMIC8K 0x00000020
  640. #define SQLITE_IOCAP_ATOMIC16K 0x00000040
  641. #define SQLITE_IOCAP_ATOMIC32K 0x00000080
  642. #define SQLITE_IOCAP_ATOMIC64K 0x00000100
  643. #define SQLITE_IOCAP_SAFE_APPEND 0x00000200
  644. #define SQLITE_IOCAP_SEQUENTIAL 0x00000400
  645. #define SQLITE_IOCAP_UNDELETABLE_WHEN_OPEN 0x00000800
  646. #define SQLITE_IOCAP_POWERSAFE_OVERWRITE 0x00001000
  647. #define SQLITE_IOCAP_IMMUTABLE 0x00002000
  648. #define SQLITE_IOCAP_BATCH_ATOMIC 0x00004000
  649. /*
  650. ** CAPI3REF: File Locking Levels
  651. **
  652. ** SQLite uses one of these integer values as the second
  653. ** argument to calls it makes to the xLock() and xUnlock() methods
  654. ** of an [sqlite3_io_methods] object. These values are ordered from
  655. ** lest restrictive to most restrictive.
  656. **
  657. ** The argument to xLock() is always SHARED or higher. The argument to
  658. ** xUnlock is either SHARED or NONE.
  659. */
  660. #define SQLITE_LOCK_NONE 0 /* xUnlock() only */
  661. #define SQLITE_LOCK_SHARED 1 /* xLock() or xUnlock() */
  662. #define SQLITE_LOCK_RESERVED 2 /* xLock() only */
  663. #define SQLITE_LOCK_PENDING 3 /* xLock() only */
  664. #define SQLITE_LOCK_EXCLUSIVE 4 /* xLock() only */
  665. /*
  666. ** CAPI3REF: Synchronization Type Flags
  667. **
  668. ** When SQLite invokes the xSync() method of an
  669. ** [sqlite3_io_methods] object it uses a combination of
  670. ** these integer values as the second argument.
  671. **
  672. ** When the SQLITE_SYNC_DATAONLY flag is used, it means that the
  673. ** sync operation only needs to flush data to mass storage. Inode
  674. ** information need not be flushed. If the lower four bits of the flag
  675. ** equal SQLITE_SYNC_NORMAL, that means to use normal fsync() semantics.
  676. ** If the lower four bits equal SQLITE_SYNC_FULL, that means
  677. ** to use Mac OS X style fullsync instead of fsync().
  678. **
  679. ** Do not confuse the SQLITE_SYNC_NORMAL and SQLITE_SYNC_FULL flags
  680. ** with the [PRAGMA synchronous]=NORMAL and [PRAGMA synchronous]=FULL
  681. ** settings. The [synchronous pragma] determines when calls to the
  682. ** xSync VFS method occur and applies uniformly across all platforms.
  683. ** The SQLITE_SYNC_NORMAL and SQLITE_SYNC_FULL flags determine how
  684. ** energetic or rigorous or forceful the sync operations are and
  685. ** only make a difference on Mac OSX for the default SQLite code.
  686. ** (Third-party VFS implementations might also make the distinction
  687. ** between SQLITE_SYNC_NORMAL and SQLITE_SYNC_FULL, but among the
  688. ** operating systems natively supported by SQLite, only Mac OSX
  689. ** cares about the difference.)
  690. */
  691. #define SQLITE_SYNC_NORMAL 0x00002
  692. #define SQLITE_SYNC_FULL 0x00003
  693. #define SQLITE_SYNC_DATAONLY 0x00010
  694. /*
  695. ** CAPI3REF: OS Interface Open File Handle
  696. **
  697. ** An [sqlite3_file] object represents an open file in the
  698. ** [sqlite3_vfs | OS interface layer]. Individual OS interface
  699. ** implementations will
  700. ** want to subclass this object by appending additional fields
  701. ** for their own use. The pMethods entry is a pointer to an
  702. ** [sqlite3_io_methods] object that defines methods for performing
  703. ** I/O operations on the open file.
  704. */
  705. typedef struct sqlite3_file sqlite3_file;
  706. struct sqlite3_file {
  707. const struct sqlite3_io_methods *pMethods; /* Methods for an open file */
  708. };
  709. /*
  710. ** CAPI3REF: OS Interface File Virtual Methods Object
  711. **
  712. ** Every file opened by the [sqlite3_vfs.xOpen] method populates an
  713. ** [sqlite3_file] object (or, more commonly, a subclass of the
  714. ** [sqlite3_file] object) with a pointer to an instance of this object.
  715. ** This object defines the methods used to perform various operations
  716. ** against the open file represented by the [sqlite3_file] object.
  717. **
  718. ** If the [sqlite3_vfs.xOpen] method sets the sqlite3_file.pMethods element
  719. ** to a non-NULL pointer, then the sqlite3_io_methods.xClose method
  720. ** may be invoked even if the [sqlite3_vfs.xOpen] reported that it failed. The
  721. ** only way to prevent a call to xClose following a failed [sqlite3_vfs.xOpen]
  722. ** is for the [sqlite3_vfs.xOpen] to set the sqlite3_file.pMethods element
  723. ** to NULL.
  724. **
  725. ** The flags argument to xSync may be one of [SQLITE_SYNC_NORMAL] or
  726. ** [SQLITE_SYNC_FULL]. The first choice is the normal fsync().
  727. ** The second choice is a Mac OS X style fullsync. The [SQLITE_SYNC_DATAONLY]
  728. ** flag may be ORed in to indicate that only the data of the file
  729. ** and not its inode needs to be synced.
  730. **
  731. ** The integer values to xLock() and xUnlock() are one of
  732. ** <ul>
  733. ** <li> [SQLITE_LOCK_NONE],
  734. ** <li> [SQLITE_LOCK_SHARED],
  735. ** <li> [SQLITE_LOCK_RESERVED],
  736. ** <li> [SQLITE_LOCK_PENDING], or
  737. ** <li> [SQLITE_LOCK_EXCLUSIVE].
  738. ** </ul>
  739. ** xLock() upgrades the database file lock. In other words, xLock() moves the
  740. ** database file lock in the direction NONE toward EXCLUSIVE. The argument to
  741. ** xLock() is always on of SHARED, RESERVED, PENDING, or EXCLUSIVE, never
  742. ** SQLITE_LOCK_NONE. If the database file lock is already at or above the
  743. ** requested lock, then the call to xLock() is a no-op.
  744. ** xUnlock() downgrades the database file lock to either SHARED or NONE.
  745. * If the lock is already at or below the requested lock state, then the call
  746. ** to xUnlock() is a no-op.
  747. ** The xCheckReservedLock() method checks whether any database connection,
  748. ** either in this process or in some other process, is holding a RESERVED,
  749. ** PENDING, or EXCLUSIVE lock on the file. It returns true
  750. ** if such a lock exists and false otherwise.
  751. **
  752. ** The xFileControl() method is a generic interface that allows custom
  753. ** VFS implementations to directly control an open file using the
  754. ** [sqlite3_file_control()] interface. The second "op" argument is an
  755. ** integer opcode. The third argument is a generic pointer intended to
  756. ** point to a structure that may contain arguments or space in which to
  757. ** write return values. Potential uses for xFileControl() might be
  758. ** functions to enable blocking locks with timeouts, to change the
  759. ** locking strategy (for example to use dot-file locks), to inquire
  760. ** about the status of a lock, or to break stale locks. The SQLite
  761. ** core reserves all opcodes less than 100 for its own use.
  762. ** A [file control opcodes | list of opcodes] less than 100 is available.
  763. ** Applications that define a custom xFileControl method should use opcodes
  764. ** greater than 100 to avoid conflicts. VFS implementations should
  765. ** return [SQLITE_NOTFOUND] for file control opcodes that they do not
  766. ** recognize.
  767. **
  768. ** The xSectorSize() method returns the sector size of the
  769. ** device that underlies the file. The sector size is the
  770. ** minimum write that can be performed without disturbing
  771. ** other bytes in the file. The xDeviceCharacteristics()
  772. ** method returns a bit vector describing behaviors of the
  773. ** underlying device:
  774. **
  775. ** <ul>
  776. ** <li> [SQLITE_IOCAP_ATOMIC]
  777. ** <li> [SQLITE_IOCAP_ATOMIC512]
  778. ** <li> [SQLITE_IOCAP_ATOMIC1K]
  779. ** <li> [SQLITE_IOCAP_ATOMIC2K]
  780. ** <li> [SQLITE_IOCAP_ATOMIC4K]
  781. ** <li> [SQLITE_IOCAP_ATOMIC8K]
  782. ** <li> [SQLITE_IOCAP_ATOMIC16K]
  783. ** <li> [SQLITE_IOCAP_ATOMIC32K]
  784. ** <li> [SQLITE_IOCAP_ATOMIC64K]
  785. ** <li> [SQLITE_IOCAP_SAFE_APPEND]
  786. ** <li> [SQLITE_IOCAP_SEQUENTIAL]
  787. ** <li> [SQLITE_IOCAP_UNDELETABLE_WHEN_OPEN]
  788. ** <li> [SQLITE_IOCAP_POWERSAFE_OVERWRITE]
  789. ** <li> [SQLITE_IOCAP_IMMUTABLE]
  790. ** <li> [SQLITE_IOCAP_BATCH_ATOMIC]
  791. ** </ul>
  792. **
  793. ** The SQLITE_IOCAP_ATOMIC property means that all writes of
  794. ** any size are atomic. The SQLITE_IOCAP_ATOMICnnn values
  795. ** mean that writes of blocks that are nnn bytes in size and
  796. ** are aligned to an address which is an integer multiple of
  797. ** nnn are atomic. The SQLITE_IOCAP_SAFE_APPEND value means
  798. ** that when data is appended to a file, the data is appended
  799. ** first then the size of the file is extended, never the other
  800. ** way around. The SQLITE_IOCAP_SEQUENTIAL property means that
  801. ** information is written to disk in the same order as calls
  802. ** to xWrite().
  803. **
  804. ** If xRead() returns SQLITE_IOERR_SHORT_READ it must also fill
  805. ** in the unread portions of the buffer with zeros. A VFS that
  806. ** fails to zero-fill short reads might seem to work. However,
  807. ** failure to zero-fill short reads will eventually lead to
  808. ** database corruption.
  809. */
  810. typedef struct sqlite3_io_methods sqlite3_io_methods;
  811. struct sqlite3_io_methods {
  812. int iVersion;
  813. int (*xClose)(sqlite3_file*);
  814. int (*xRead)(sqlite3_file*, void*, int iAmt, sqlite3_int64 iOfst);
  815. int (*xWrite)(sqlite3_file*, const void*, int iAmt, sqlite3_int64 iOfst);
  816. int (*xTruncate)(sqlite3_file*, sqlite3_int64 size);
  817. int (*xSync)(sqlite3_file*, int flags);
  818. int (*xFileSize)(sqlite3_file*, sqlite3_int64 *pSize);
  819. int (*xLock)(sqlite3_file*, int);
  820. int (*xUnlock)(sqlite3_file*, int);
  821. int (*xCheckReservedLock)(sqlite3_file*, int *pResOut);
  822. int (*xFileControl)(sqlite3_file*, int op, void *pArg);
  823. int (*xSectorSize)(sqlite3_file*);
  824. int (*xDeviceCharacteristics)(sqlite3_file*);
  825. /* Methods above are valid for version 1 */
  826. int (*xShmMap)(sqlite3_file*, int iPg, int pgsz, int, void volatile**);
  827. int (*xShmLock)(sqlite3_file*, int offset, int n, int flags);
  828. void (*xShmBarrier)(sqlite3_file*);
  829. int (*xShmUnmap)(sqlite3_file*, int deleteFlag);
  830. /* Methods above are valid for version 2 */
  831. int (*xFetch)(sqlite3_file*, sqlite3_int64 iOfst, int iAmt, void **pp);
  832. int (*xUnfetch)(sqlite3_file*, sqlite3_int64 iOfst, void *p);
  833. /* Methods above are valid for version 3 */
  834. /* Additional methods may be added in future releases */
  835. };
  836. /*
  837. ** CAPI3REF: Standard File Control Opcodes
  838. ** KEYWORDS: {file control opcodes} {file control opcode}
  839. **
  840. ** These integer constants are opcodes for the xFileControl method
  841. ** of the [sqlite3_io_methods] object and for the [sqlite3_file_control()]
  842. ** interface.
  843. **
  844. ** <ul>
  845. ** <li>[[SQLITE_FCNTL_LOCKSTATE]]
  846. ** The [SQLITE_FCNTL_LOCKSTATE] opcode is used for debugging. This
  847. ** opcode causes the xFileControl method to write the current state of
  848. ** the lock (one of [SQLITE_LOCK_NONE], [SQLITE_LOCK_SHARED],
  849. ** [SQLITE_LOCK_RESERVED], [SQLITE_LOCK_PENDING], or [SQLITE_LOCK_EXCLUSIVE])
  850. ** into an integer that the pArg argument points to.
  851. ** This capability is only available if SQLite is compiled with [SQLITE_DEBUG].
  852. **
  853. ** <li>[[SQLITE_FCNTL_SIZE_HINT]]
  854. ** The [SQLITE_FCNTL_SIZE_HINT] opcode is used by SQLite to give the VFS
  855. ** layer a hint of how large the database file will grow to be during the
  856. ** current transaction. This hint is not guaranteed to be accurate but it
  857. ** is often close. The underlying VFS might choose to preallocate database
  858. ** file space based on this hint in order to help writes to the database
  859. ** file run faster.
  860. **
  861. ** <li>[[SQLITE_FCNTL_SIZE_LIMIT]]
  862. ** The [SQLITE_FCNTL_SIZE_LIMIT] opcode is used by in-memory VFS that
  863. ** implements [sqlite3_deserialize()] to set an upper bound on the size
  864. ** of the in-memory database. The argument is a pointer to a [sqlite3_int64].
  865. ** If the integer pointed to is negative, then it is filled in with the
  866. ** current limit. Otherwise the limit is set to the larger of the value
  867. ** of the integer pointed to and the current database size. The integer
  868. ** pointed to is set to the new limit.
  869. **
  870. ** <li>[[SQLITE_FCNTL_CHUNK_SIZE]]
  871. ** The [SQLITE_FCNTL_CHUNK_SIZE] opcode is used to request that the VFS
  872. ** extends and truncates the database file in chunks of a size specified
  873. ** by the user. The fourth argument to [sqlite3_file_control()] should
  874. ** point to an integer (type int) containing the new chunk-size to use
  875. ** for the nominated database. Allocating database file space in large
  876. ** chunks (say 1MB at a time), may reduce file-system fragmentation and
  877. ** improve performance on some systems.
  878. **
  879. ** <li>[[SQLITE_FCNTL_FILE_POINTER]]
  880. ** The [SQLITE_FCNTL_FILE_POINTER] opcode is used to obtain a pointer
  881. ** to the [sqlite3_file] object associated with a particular database
  882. ** connection. See also [SQLITE_FCNTL_JOURNAL_POINTER].
  883. **
  884. ** <li>[[SQLITE_FCNTL_JOURNAL_POINTER]]
  885. ** The [SQLITE_FCNTL_JOURNAL_POINTER] opcode is used to obtain a pointer
  886. ** to the [sqlite3_file] object associated with the journal file (either
  887. ** the [rollback journal] or the [write-ahead log]) for a particular database
  888. ** connection. See also [SQLITE_FCNTL_FILE_POINTER].
  889. **
  890. ** <li>[[SQLITE_FCNTL_SYNC_OMITTED]]
  891. ** No longer in use.
  892. **
  893. ** <li>[[SQLITE_FCNTL_SYNC]]
  894. ** The [SQLITE_FCNTL_SYNC] opcode is generated internally by SQLite and
  895. ** sent to the VFS immediately before the xSync method is invoked on a
  896. ** database file descriptor. Or, if the xSync method is not invoked
  897. ** because the user has configured SQLite with
  898. ** [PRAGMA synchronous | PRAGMA synchronous=OFF] it is invoked in place
  899. ** of the xSync method. In most cases, the pointer argument passed with
  900. ** this file-control is NULL. However, if the database file is being synced
  901. ** as part of a multi-database commit, the argument points to a nul-terminated
  902. ** string containing the transactions super-journal file name. VFSes that
  903. ** do not need this signal should silently ignore this opcode. Applications
  904. ** should not call [sqlite3_file_control()] with this opcode as doing so may
  905. ** disrupt the operation of the specialized VFSes that do require it.
  906. **
  907. ** <li>[[SQLITE_FCNTL_COMMIT_PHASETWO]]
  908. ** The [SQLITE_FCNTL_COMMIT_PHASETWO] opcode is generated internally by SQLite
  909. ** and sent to the VFS after a transaction has been committed immediately
  910. ** but before the database is unlocked. VFSes that do not need this signal
  911. ** should silently ignore this opcode. Applications should not call
  912. ** [sqlite3_file_control()] with this opcode as doing so may disrupt the
  913. ** operation of the specialized VFSes that do require it.
  914. **
  915. ** <li>[[SQLITE_FCNTL_WIN32_AV_RETRY]]
  916. ** ^The [SQLITE_FCNTL_WIN32_AV_RETRY] opcode is used to configure automatic
  917. ** retry counts and intervals for certain disk I/O operations for the
  918. ** windows [VFS] in order to provide robustness in the presence of
  919. ** anti-virus programs. By default, the windows VFS will retry file read,
  920. ** file write, and file delete operations up to 10 times, with a delay
  921. ** of 25 milliseconds before the first retry and with the delay increasing
  922. ** by an additional 25 milliseconds with each subsequent retry. This
  923. ** opcode allows these two values (10 retries and 25 milliseconds of delay)
  924. ** to be adjusted. The values are changed for all database connections
  925. ** within the same process. The argument is a pointer to an array of two
  926. ** integers where the first integer is the new retry count and the second
  927. ** integer is the delay. If either integer is negative, then the setting
  928. ** is not changed but instead the prior value of that setting is written
  929. ** into the array entry, allowing the current retry settings to be
  930. ** interrogated. The zDbName parameter is ignored.
  931. **
  932. ** <li>[[SQLITE_FCNTL_PERSIST_WAL]]
  933. ** ^The [SQLITE_FCNTL_PERSIST_WAL] opcode is used to set or query the
  934. ** persistent [WAL | Write Ahead Log] setting. By default, the auxiliary
  935. ** write ahead log ([WAL file]) and shared memory
  936. ** files used for transaction control
  937. ** are automatically deleted when the latest connection to the database
  938. ** closes. Setting persistent WAL mode causes those files to persist after
  939. ** close. Persisting the files is useful when other processes that do not
  940. ** have write permission on the directory containing the database file want
  941. ** to read the database file, as the WAL and shared memory files must exist
  942. ** in order for the database to be readable. The fourth parameter to
  943. ** [sqlite3_file_control()] for this opcode should be a pointer to an integer.
  944. ** That integer is 0 to disable persistent WAL mode or 1 to enable persistent
  945. ** WAL mode. If the integer is -1, then it is overwritten with the current
  946. ** WAL persistence setting.
  947. **
  948. ** <li>[[SQLITE_FCNTL_POWERSAFE_OVERWRITE]]
  949. ** ^The [SQLITE_FCNTL_POWERSAFE_OVERWRITE] opcode is used to set or query the
  950. ** persistent "powersafe-overwrite" or "PSOW" setting. The PSOW setting
  951. ** determines the [SQLITE_IOCAP_POWERSAFE_OVERWRITE] bit of the
  952. ** xDeviceCharacteristics methods. The fourth parameter to
  953. ** [sqlite3_file_control()] for this opcode should be a pointer to an integer.
  954. ** That integer is 0 to disable zero-damage mode or 1 to enable zero-damage
  955. ** mode. If the integer is -1, then it is overwritten with the current
  956. ** zero-damage mode setting.
  957. **
  958. ** <li>[[SQLITE_FCNTL_OVERWRITE]]
  959. ** ^The [SQLITE_FCNTL_OVERWRITE] opcode is invoked by SQLite after opening
  960. ** a write transaction to indicate that, unless it is rolled back for some
  961. ** reason, the entire database file will be overwritten by the current
  962. ** transaction. This is used by VACUUM operations.
  963. **
  964. ** <li>[[SQLITE_FCNTL_VFSNAME]]
  965. ** ^The [SQLITE_FCNTL_VFSNAME] opcode can be used to obtain the names of
  966. ** all [VFSes] in the VFS stack. The names are of all VFS shims and the
  967. ** final bottom-level VFS are written into memory obtained from
  968. ** [sqlite3_malloc()] and the result is stored in the char* variable
  969. ** that the fourth parameter of [sqlite3_file_control()] points to.
  970. ** The caller is responsible for freeing the memory when done. As with
  971. ** all file-control actions, there is no guarantee that this will actually
  972. ** do anything. Callers should initialize the char* variable to a NULL
  973. ** pointer in case this file-control is not implemented. This file-control
  974. ** is intended for diagnostic use only.
  975. **
  976. ** <li>[[SQLITE_FCNTL_VFS_POINTER]]
  977. ** ^The [SQLITE_FCNTL_VFS_POINTER] opcode finds a pointer to the top-level
  978. ** [VFSes] currently in use. ^(The argument X in
  979. ** sqlite3_file_control(db,SQLITE_FCNTL_VFS_POINTER,X) must be
  980. ** of type "[sqlite3_vfs] **". This opcodes will set *X
  981. ** to a pointer to the top-level VFS.)^
  982. ** ^When there are multiple VFS shims in the stack, this opcode finds the
  983. ** upper-most shim only.
  984. **
  985. ** <li>[[SQLITE_FCNTL_PRAGMA]]
  986. ** ^Whenever a [PRAGMA] statement is parsed, an [SQLITE_FCNTL_PRAGMA]
  987. ** file control is sent to the open [sqlite3_file] object corresponding
  988. ** to the database file to which the pragma statement refers. ^The argument
  989. ** to the [SQLITE_FCNTL_PRAGMA] file control is an array of
  990. ** pointers to strings (char**) in which the second element of the array
  991. ** is the name of the pragma and the third element is the argument to the
  992. ** pragma or NULL if the pragma has no argument. ^The handler for an
  993. ** [SQLITE_FCNTL_PRAGMA] file control can optionally make the first element
  994. ** of the char** argument point to a string obtained from [sqlite3_mprintf()]
  995. ** or the equivalent and that string will become the result of the pragma or
  996. ** the error message if the pragma fails. ^If the
  997. ** [SQLITE_FCNTL_PRAGMA] file control returns [SQLITE_NOTFOUND], then normal
  998. ** [PRAGMA] processing continues. ^If the [SQLITE_FCNTL_PRAGMA]
  999. ** file control returns [SQLITE_OK], then the parser assumes that the
  1000. ** VFS has handled the PRAGMA itself and the parser generates a no-op
  1001. ** prepared statement if result string is NULL, or that returns a copy
  1002. ** of the result string if the string is non-NULL.
  1003. ** ^If the [SQLITE_FCNTL_PRAGMA] file control returns
  1004. ** any result code other than [SQLITE_OK] or [SQLITE_NOTFOUND], that means
  1005. ** that the VFS encountered an error while handling the [PRAGMA] and the
  1006. ** compilation of the PRAGMA fails with an error. ^The [SQLITE_FCNTL_PRAGMA]
  1007. ** file control occurs at the beginning of pragma statement analysis and so
  1008. ** it is able to override built-in [PRAGMA] statements.
  1009. **
  1010. ** <li>[[SQLITE_FCNTL_BUSYHANDLER]]
  1011. ** ^The [SQLITE_FCNTL_BUSYHANDLER]
  1012. ** file-control may be invoked by SQLite on the database file handle
  1013. ** shortly after it is opened in order to provide a custom VFS with access
  1014. ** to the connection's busy-handler callback. The argument is of type (void**)
  1015. ** - an array of two (void *) values. The first (void *) actually points
  1016. ** to a function of type (int (*)(void *)). In order to invoke the connection's
  1017. ** busy-handler, this function should be invoked with the second (void *) in
  1018. ** the array as the only argument. If it returns non-zero, then the operation
  1019. ** should be retried. If it returns zero, the custom VFS should abandon the
  1020. ** current operation.
  1021. **
  1022. ** <li>[[SQLITE_FCNTL_TEMPFILENAME]]
  1023. ** ^Applications can invoke the [SQLITE_FCNTL_TEMPFILENAME] file-control
  1024. ** to have SQLite generate a
  1025. ** temporary filename using the same algorithm that is followed to generate
  1026. ** temporary filenames for TEMP tables and other internal uses. The
  1027. ** argument should be a char** which will be filled with the filename
  1028. ** written into memory obtained from [sqlite3_malloc()]. The caller should
  1029. ** invoke [sqlite3_free()] on the result to avoid a memory leak.
  1030. **
  1031. ** <li>[[SQLITE_FCNTL_MMAP_SIZE]]
  1032. ** The [SQLITE_FCNTL_MMAP_SIZE] file control is used to query or set the
  1033. ** maximum number of bytes that will be used for memory-mapped I/O.
  1034. ** The argument is a pointer to a value of type sqlite3_int64 that
  1035. ** is an advisory maximum number of bytes in the file to memory map. The
  1036. ** pointer is overwritten with the old value. The limit is not changed if
  1037. ** the value originally pointed to is negative, and so the current limit
  1038. ** can be queried by passing in a pointer to a negative number. This
  1039. ** file-control is used internally to implement [PRAGMA mmap_size].
  1040. **
  1041. ** <li>[[SQLITE_FCNTL_TRACE]]
  1042. ** The [SQLITE_FCNTL_TRACE] file control provides advisory information
  1043. ** to the VFS about what the higher layers of the SQLite stack are doing.
  1044. ** This file control is used by some VFS activity tracing [shims].
  1045. ** The argument is a zero-terminated string. Higher layers in the
  1046. ** SQLite stack may generate instances of this file control if
  1047. ** the [SQLITE_USE_FCNTL_TRACE] compile-time option is enabled.
  1048. **
  1049. ** <li>[[SQLITE_FCNTL_HAS_MOVED]]
  1050. ** The [SQLITE_FCNTL_HAS_MOVED] file control interprets its argument as a
  1051. ** pointer to an integer and it writes a boolean into that integer depending
  1052. ** on whether or not the file has been renamed, moved, or deleted since it
  1053. ** was first opened.
  1054. **
  1055. ** <li>[[SQLITE_FCNTL_WIN32_GET_HANDLE]]
  1056. ** The [SQLITE_FCNTL_WIN32_GET_HANDLE] opcode can be used to obtain the
  1057. ** underlying native file handle associated with a file handle. This file
  1058. ** control interprets its argument as a pointer to a native file handle and
  1059. ** writes the resulting value there.
  1060. **
  1061. ** <li>[[SQLITE_FCNTL_WIN32_SET_HANDLE]]
  1062. ** The [SQLITE_FCNTL_WIN32_SET_HANDLE] opcode is used for debugging. This
  1063. ** opcode causes the xFileControl method to swap the file handle with the one
  1064. ** pointed to by the pArg argument. This capability is used during testing
  1065. ** and only needs to be supported when SQLITE_TEST is defined.
  1066. **
  1067. ** <li>[[SQLITE_FCNTL_WAL_BLOCK]]
  1068. ** The [SQLITE_FCNTL_WAL_BLOCK] is a signal to the VFS layer that it might
  1069. ** be advantageous to block on the next WAL lock if the lock is not immediately
  1070. ** available. The WAL subsystem issues this signal during rare
  1071. ** circumstances in order to fix a problem with priority inversion.
  1072. ** Applications should <em>not</em> use this file-control.
  1073. **
  1074. ** <li>[[SQLITE_FCNTL_ZIPVFS]]
  1075. ** The [SQLITE_FCNTL_ZIPVFS] opcode is implemented by zipvfs only. All other
  1076. ** VFS should return SQLITE_NOTFOUND for this opcode.
  1077. **
  1078. ** <li>[[SQLITE_FCNTL_RBU]]
  1079. ** The [SQLITE_FCNTL_RBU] opcode is implemented by the special VFS used by
  1080. ** the RBU extension only. All other VFS should return SQLITE_NOTFOUND for
  1081. ** this opcode.
  1082. **
  1083. ** <li>[[SQLITE_FCNTL_BEGIN_ATOMIC_WRITE]]
  1084. ** If the [SQLITE_FCNTL_BEGIN_ATOMIC_WRITE] opcode returns SQLITE_OK, then
  1085. ** the file descriptor is placed in "batch write mode", which
  1086. ** means all subsequent write operations will be deferred and done
  1087. ** atomically at the next [SQLITE_FCNTL_COMMIT_ATOMIC_WRITE]. Systems
  1088. ** that do not support batch atomic writes will return SQLITE_NOTFOUND.
  1089. ** ^Following a successful SQLITE_FCNTL_BEGIN_ATOMIC_WRITE and prior to
  1090. ** the closing [SQLITE_FCNTL_COMMIT_ATOMIC_WRITE] or
  1091. ** [SQLITE_FCNTL_ROLLBACK_ATOMIC_WRITE], SQLite will make
  1092. ** no VFS interface calls on the same [sqlite3_file] file descriptor
  1093. ** except for calls to the xWrite method and the xFileControl method
  1094. ** with [SQLITE_FCNTL_SIZE_HINT].
  1095. **
  1096. ** <li>[[SQLITE_FCNTL_COMMIT_ATOMIC_WRITE]]
  1097. ** The [SQLITE_FCNTL_COMMIT_ATOMIC_WRITE] opcode causes all write
  1098. ** operations since the previous successful call to
  1099. ** [SQLITE_FCNTL_BEGIN_ATOMIC_WRITE] to be performed atomically.
  1100. ** This file control returns [SQLITE_OK] if and only if the writes were
  1101. ** all performed successfully and have been committed to persistent storage.
  1102. ** ^Regardless of whether or not it is successful, this file control takes
  1103. ** the file descriptor out of batch write mode so that all subsequent
  1104. ** write operations are independent.
  1105. ** ^SQLite will never invoke SQLITE_FCNTL_COMMIT_ATOMIC_WRITE without
  1106. ** a prior successful call to [SQLITE_FCNTL_BEGIN_ATOMIC_WRITE].
  1107. **
  1108. ** <li>[[SQLITE_FCNTL_ROLLBACK_ATOMIC_WRITE]]
  1109. ** The [SQLITE_FCNTL_ROLLBACK_ATOMIC_WRITE] opcode causes all write
  1110. ** operations since the previous successful call to
  1111. ** [SQLITE_FCNTL_BEGIN_ATOMIC_WRITE] to be rolled back.
  1112. ** ^This file control takes the file descriptor out of batch write mode
  1113. ** so that all subsequent write operations are independent.
  1114. ** ^SQLite will never invoke SQLITE_FCNTL_ROLLBACK_ATOMIC_WRITE without
  1115. ** a prior successful call to [SQLITE_FCNTL_BEGIN_ATOMIC_WRITE].
  1116. **
  1117. ** <li>[[SQLITE_FCNTL_LOCK_TIMEOUT]]
  1118. ** The [SQLITE_FCNTL_LOCK_TIMEOUT] opcode is used to configure a VFS
  1119. ** to block for up to M milliseconds before failing when attempting to
  1120. ** obtain a file lock using the xLock or xShmLock methods of the VFS.
  1121. ** The parameter is a pointer to a 32-bit signed integer that contains
  1122. ** the value that M is to be set to. Before returning, the 32-bit signed
  1123. ** integer is overwritten with the previous value of M.
  1124. **
  1125. ** <li>[[SQLITE_FCNTL_DATA_VERSION]]
  1126. ** The [SQLITE_FCNTL_DATA_VERSION] opcode is used to detect changes to
  1127. ** a database file. The argument is a pointer to a 32-bit unsigned integer.
  1128. ** The "data version" for the pager is written into the pointer. The
  1129. ** "data version" changes whenever any change occurs to the corresponding
  1130. ** database file, either through SQL statements on the same database
  1131. ** connection or through transactions committed by separate database
  1132. ** connections possibly in other processes. The [sqlite3_total_changes()]
  1133. ** interface can be used to find if any database on the connection has changed,
  1134. ** but that interface responds to changes on TEMP as well as MAIN and does
  1135. ** not provide a mechanism to detect changes to MAIN only. Also, the
  1136. ** [sqlite3_total_changes()] interface responds to internal changes only and
  1137. ** omits changes made by other database connections. The
  1138. ** [PRAGMA data_version] command provides a mechanism to detect changes to
  1139. ** a single attached database that occur due to other database connections,
  1140. ** but omits changes implemented by the database connection on which it is
  1141. ** called. This file control is the only mechanism to detect changes that
  1142. ** happen either internally or externally and that are associated with
  1143. ** a particular attached database.
  1144. **
  1145. ** <li>[[SQLITE_FCNTL_CKPT_START]]
  1146. ** The [SQLITE_FCNTL_CKPT_START] opcode is invoked from within a checkpoint
  1147. ** in wal mode before the client starts to copy pages from the wal
  1148. ** file to the database file.
  1149. **
  1150. ** <li>[[SQLITE_FCNTL_CKPT_DONE]]
  1151. ** The [SQLITE_FCNTL_CKPT_DONE] opcode is invoked from within a checkpoint
  1152. ** in wal mode after the client has finished copying pages from the wal
  1153. ** file to the database file, but before the *-shm file is updated to
  1154. ** record the fact that the pages have been checkpointed.
  1155. **
  1156. ** <li>[[SQLITE_FCNTL_EXTERNAL_READER]]
  1157. ** The EXPERIMENTAL [SQLITE_FCNTL_EXTERNAL_READER] opcode is used to detect
  1158. ** whether or not there is a database client in another process with a wal-mode
  1159. ** transaction open on the database or not. It is only available on unix.The
  1160. ** (void*) argument passed with this file-control should be a pointer to a
  1161. ** value of type (int). The integer value is set to 1 if the database is a wal
  1162. ** mode database and there exists at least one client in another process that
  1163. ** currently has an SQL transaction open on the database. It is set to 0 if
  1164. ** the database is not a wal-mode db, or if there is no such connection in any
  1165. ** other process. This opcode cannot be used to detect transactions opened
  1166. ** by clients within the current process, only within other processes.
  1167. **
  1168. ** <li>[[SQLITE_FCNTL_CKSM_FILE]]
  1169. ** The [SQLITE_FCNTL_CKSM_FILE] opcode is for use internally by the
  1170. ** [checksum VFS shim] only.
  1171. **
  1172. ** <li>[[SQLITE_FCNTL_RESET_CACHE]]
  1173. ** If there is currently no transaction open on the database, and the
  1174. ** database is not a temp db, then the [SQLITE_FCNTL_RESET_CACHE] file-control
  1175. ** purges the contents of the in-memory page cache. If there is an open
  1176. ** transaction, or if the db is a temp-db, this opcode is a no-op, not an error.
  1177. ** </ul>
  1178. */
  1179. #define SQLITE_FCNTL_LOCKSTATE 1
  1180. #define SQLITE_FCNTL_GET_LOCKPROXYFILE 2
  1181. #define SQLITE_FCNTL_SET_LOCKPROXYFILE 3
  1182. #define SQLITE_FCNTL_LAST_ERRNO 4
  1183. #define SQLITE_FCNTL_SIZE_HINT 5
  1184. #define SQLITE_FCNTL_CHUNK_SIZE 6
  1185. #define SQLITE_FCNTL_FILE_POINTER 7
  1186. #define SQLITE_FCNTL_SYNC_OMITTED 8
  1187. #define SQLITE_FCNTL_WIN32_AV_RETRY 9
  1188. #define SQLITE_FCNTL_PERSIST_WAL 10
  1189. #define SQLITE_FCNTL_OVERWRITE 11
  1190. #define SQLITE_FCNTL_VFSNAME 12
  1191. #define SQLITE_FCNTL_POWERSAFE_OVERWRITE 13
  1192. #define SQLITE_FCNTL_PRAGMA 14
  1193. #define SQLITE_FCNTL_BUSYHANDLER 15
  1194. #define SQLITE_FCNTL_TEMPFILENAME 16
  1195. #define SQLITE_FCNTL_MMAP_SIZE 18
  1196. #define SQLITE_FCNTL_TRACE 19
  1197. #define SQLITE_FCNTL_HAS_MOVED 20
  1198. #define SQLITE_FCNTL_SYNC 21
  1199. #define SQLITE_FCNTL_COMMIT_PHASETWO 22
  1200. #define SQLITE_FCNTL_WIN32_SET_HANDLE 23
  1201. #define SQLITE_FCNTL_WAL_BLOCK 24
  1202. #define SQLITE_FCNTL_ZIPVFS 25
  1203. #define SQLITE_FCNTL_RBU 26
  1204. #define SQLITE_FCNTL_VFS_POINTER 27
  1205. #define SQLITE_FCNTL_JOURNAL_POINTER 28
  1206. #define SQLITE_FCNTL_WIN32_GET_HANDLE 29
  1207. #define SQLITE_FCNTL_PDB 30
  1208. #define SQLITE_FCNTL_BEGIN_ATOMIC_WRITE 31
  1209. #define SQLITE_FCNTL_COMMIT_ATOMIC_WRITE 32
  1210. #define SQLITE_FCNTL_ROLLBACK_ATOMIC_WRITE 33
  1211. #define SQLITE_FCNTL_LOCK_TIMEOUT 34
  1212. #define SQLITE_FCNTL_DATA_VERSION 35
  1213. #define SQLITE_FCNTL_SIZE_LIMIT 36
  1214. #define SQLITE_FCNTL_CKPT_DONE 37
  1215. #define SQLITE_FCNTL_RESERVE_BYTES 38
  1216. #define SQLITE_FCNTL_CKPT_START 39
  1217. #define SQLITE_FCNTL_EXTERNAL_READER 40
  1218. #define SQLITE_FCNTL_CKSM_FILE 41
  1219. #define SQLITE_FCNTL_RESET_CACHE 42
  1220. /* deprecated names */
  1221. #define SQLITE_GET_LOCKPROXYFILE SQLITE_FCNTL_GET_LOCKPROXYFILE
  1222. #define SQLITE_SET_LOCKPROXYFILE SQLITE_FCNTL_SET_LOCKPROXYFILE
  1223. #define SQLITE_LAST_ERRNO SQLITE_FCNTL_LAST_ERRNO
  1224. /*
  1225. ** CAPI3REF: Mutex Handle
  1226. **
  1227. ** The mutex module within SQLite defines [sqlite3_mutex] to be an
  1228. ** abstract type for a mutex object. The SQLite core never looks
  1229. ** at the internal representation of an [sqlite3_mutex]. It only
  1230. ** deals with pointers to the [sqlite3_mutex] object.
  1231. **
  1232. ** Mutexes are created using [sqlite3_mutex_alloc()].
  1233. */
  1234. typedef struct sqlite3_mutex sqlite3_mutex;
  1235. /*
  1236. ** CAPI3REF: Loadable Extension Thunk
  1237. **
  1238. ** A pointer to the opaque sqlite3_api_routines structure is passed as
  1239. ** the third parameter to entry points of [loadable extensions]. This
  1240. ** structure must be typedefed in order to work around compiler warnings
  1241. ** on some platforms.
  1242. */
  1243. typedef struct sqlite3_api_routines sqlite3_api_routines;
  1244. /*
  1245. ** CAPI3REF: File Name
  1246. **
  1247. ** Type [sqlite3_filename] is used by SQLite to pass filenames to the
  1248. ** xOpen method of a [VFS]. It may be cast to (const char*) and treated
  1249. ** as a normal, nul-terminated, UTF-8 buffer containing the filename, but
  1250. ** may also be passed to special APIs such as:
  1251. **
  1252. ** <ul>
  1253. ** <li> sqlite3_filename_database()
  1254. ** <li> sqlite3_filename_journal()
  1255. ** <li> sqlite3_filename_wal()
  1256. ** <li> sqlite3_uri_parameter()
  1257. ** <li> sqlite3_uri_boolean()
  1258. ** <li> sqlite3_uri_int64()
  1259. ** <li> sqlite3_uri_key()
  1260. ** </ul>
  1261. */
  1262. typedef const char *sqlite3_filename;
  1263. /*
  1264. ** CAPI3REF: OS Interface Object
  1265. **
  1266. ** An instance of the sqlite3_vfs object defines the interface between
  1267. ** the SQLite core and the underlying operating system. The "vfs"
  1268. ** in the name of the object stands for "virtual file system". See
  1269. ** the [VFS | VFS documentation] for further information.
  1270. **
  1271. ** The VFS interface is sometimes extended by adding new methods onto
  1272. ** the end. Each time such an extension occurs, the iVersion field
  1273. ** is incremented. The iVersion value started out as 1 in
  1274. ** SQLite [version 3.5.0] on [dateof:3.5.0], then increased to 2
  1275. ** with SQLite [version 3.7.0] on [dateof:3.7.0], and then increased
  1276. ** to 3 with SQLite [version 3.7.6] on [dateof:3.7.6]. Additional fields
  1277. ** may be appended to the sqlite3_vfs object and the iVersion value
  1278. ** may increase again in future versions of SQLite.
  1279. ** Note that due to an oversight, the structure
  1280. ** of the sqlite3_vfs object changed in the transition from
  1281. ** SQLite [version 3.5.9] to [version 3.6.0] on [dateof:3.6.0]
  1282. ** and yet the iVersion field was not increased.
  1283. **
  1284. ** The szOsFile field is the size of the subclassed [sqlite3_file]
  1285. ** structure used by this VFS. mxPathname is the maximum length of
  1286. ** a pathname in this VFS.
  1287. **
  1288. ** Registered sqlite3_vfs objects are kept on a linked list formed by
  1289. ** the pNext pointer. The [sqlite3_vfs_register()]
  1290. ** and [sqlite3_vfs_unregister()] interfaces manage this list
  1291. ** in a thread-safe way. The [sqlite3_vfs_find()] interface
  1292. ** searches the list. Neither the application code nor the VFS
  1293. ** implementation should use the pNext pointer.
  1294. **
  1295. ** The pNext field is the only field in the sqlite3_vfs
  1296. ** structure that SQLite will ever modify. SQLite will only access
  1297. ** or modify this field while holding a particular static mutex.
  1298. ** The application should never modify anything within the sqlite3_vfs
  1299. ** object once the object has been registered.
  1300. **
  1301. ** The zName field holds the name of the VFS module. The name must
  1302. ** be unique across all VFS modules.
  1303. **
  1304. ** [[sqlite3_vfs.xOpen]]
  1305. ** ^SQLite guarantees that the zFilename parameter to xOpen
  1306. ** is either a NULL pointer or string obtained
  1307. ** from xFullPathname() with an optional suffix added.
  1308. ** ^If a suffix is added to the zFilename parameter, it will
  1309. ** consist of a single "-" character followed by no more than
  1310. ** 11 alphanumeric and/or "-" characters.
  1311. ** ^SQLite further guarantees that
  1312. ** the string will be valid and unchanged until xClose() is
  1313. ** called. Because of the previous sentence,
  1314. ** the [sqlite3_file] can safely store a pointer to the
  1315. ** filename if it needs to remember the filename for some reason.
  1316. ** If the zFilename parameter to xOpen is a NULL pointer then xOpen
  1317. ** must invent its own temporary name for the file. ^Whenever the
  1318. ** xFilename parameter is NULL it will also be the case that the
  1319. ** flags parameter will include [SQLITE_OPEN_DELETEONCLOSE].
  1320. **
  1321. ** The flags argument to xOpen() includes all bits set in
  1322. ** the flags argument to [sqlite3_open_v2()]. Or if [sqlite3_open()]
  1323. ** or [sqlite3_open16()] is used, then flags includes at least
  1324. ** [SQLITE_OPEN_READWRITE] | [SQLITE_OPEN_CREATE].
  1325. ** If xOpen() opens a file read-only then it sets *pOutFlags to
  1326. ** include [SQLITE_OPEN_READONLY]. Other bits in *pOutFlags may be set.
  1327. **
  1328. ** ^(SQLite will also add one of the following flags to the xOpen()
  1329. ** call, depending on the object being opened:
  1330. **
  1331. ** <ul>
  1332. ** <li> [SQLITE_OPEN_MAIN_DB]
  1333. ** <li> [SQLITE_OPEN_MAIN_JOURNAL]
  1334. ** <li> [SQLITE_OPEN_TEMP_DB]
  1335. ** <li> [SQLITE_OPEN_TEMP_JOURNAL]
  1336. ** <li> [SQLITE_OPEN_TRANSIENT_DB]
  1337. ** <li> [SQLITE_OPEN_SUBJOURNAL]
  1338. ** <li> [SQLITE_OPEN_SUPER_JOURNAL]
  1339. ** <li> [SQLITE_OPEN_WAL]
  1340. ** </ul>)^
  1341. **
  1342. ** The file I/O implementation can use the object type flags to
  1343. ** change the way it deals with files. For example, an application
  1344. ** that does not care about crash recovery or rollback might make
  1345. ** the open of a journal file a no-op. Writes to this journal would
  1346. ** also be no-ops, and any attempt to read the journal would return
  1347. ** SQLITE_IOERR. Or the implementation might recognize that a database
  1348. ** file will be doing page-aligned sector reads and writes in a random
  1349. ** order and set up its I/O subsystem accordingly.
  1350. **
  1351. ** SQLite might also add one of the following flags to the xOpen method:
  1352. **
  1353. ** <ul>
  1354. ** <li> [SQLITE_OPEN_DELETEONCLOSE]
  1355. ** <li> [SQLITE_OPEN_EXCLUSIVE]
  1356. ** </ul>
  1357. **
  1358. ** The [SQLITE_OPEN_DELETEONCLOSE] flag means the file should be
  1359. ** deleted when it is closed. ^The [SQLITE_OPEN_DELETEONCLOSE]
  1360. ** will be set for TEMP databases and their journals, transient
  1361. ** databases, and subjournals.
  1362. **
  1363. ** ^The [SQLITE_OPEN_EXCLUSIVE] flag is always used in conjunction
  1364. ** with the [SQLITE_OPEN_CREATE] flag, which are both directly
  1365. ** analogous to the O_EXCL and O_CREAT flags of the POSIX open()
  1366. ** API. The SQLITE_OPEN_EXCLUSIVE flag, when paired with the
  1367. ** SQLITE_OPEN_CREATE, is used to indicate that file should always
  1368. ** be created, and that it is an error if it already exists.
  1369. ** It is <i>not</i> used to indicate the file should be opened
  1370. ** for exclusive access.
  1371. **
  1372. ** ^At least szOsFile bytes of memory are allocated by SQLite
  1373. ** to hold the [sqlite3_file] structure passed as the third
  1374. ** argument to xOpen. The xOpen method does not have to
  1375. ** allocate the structure; it should just fill it in. Note that
  1376. ** the xOpen method must set the sqlite3_file.pMethods to either
  1377. ** a valid [sqlite3_io_methods] object or to NULL. xOpen must do
  1378. ** this even if the open fails. SQLite expects that the sqlite3_file.pMethods
  1379. ** element will be valid after xOpen returns regardless of the success
  1380. ** or failure of the xOpen call.
  1381. **
  1382. ** [[sqlite3_vfs.xAccess]]
  1383. ** ^The flags argument to xAccess() may be [SQLITE_ACCESS_EXISTS]
  1384. ** to test for the existence of a file, or [SQLITE_ACCESS_READWRITE] to
  1385. ** test whether a file is readable and writable, or [SQLITE_ACCESS_READ]
  1386. ** to test whether a file is at least readable. The SQLITE_ACCESS_READ
  1387. ** flag is never actually used and is not implemented in the built-in
  1388. ** VFSes of SQLite. The file is named by the second argument and can be a
  1389. ** directory. The xAccess method returns [SQLITE_OK] on success or some
  1390. ** non-zero error code if there is an I/O error or if the name of
  1391. ** the file given in the second argument is illegal. If SQLITE_OK
  1392. ** is returned, then non-zero or zero is written into *pResOut to indicate
  1393. ** whether or not the file is accessible.
  1394. **
  1395. ** ^SQLite will always allocate at least mxPathname+1 bytes for the
  1396. ** output buffer xFullPathname. The exact size of the output buffer
  1397. ** is also passed as a parameter to both methods. If the output buffer
  1398. ** is not large enough, [SQLITE_CANTOPEN] should be returned. Since this is
  1399. ** handled as a fatal error by SQLite, vfs implementations should endeavor
  1400. ** to prevent this by setting mxPathname to a sufficiently large value.
  1401. **
  1402. ** The xRandomness(), xSleep(), xCurrentTime(), and xCurrentTimeInt64()
  1403. ** interfaces are not strictly a part of the filesystem, but they are
  1404. ** included in the VFS structure for completeness.
  1405. ** The xRandomness() function attempts to return nBytes bytes
  1406. ** of good-quality randomness into zOut. The return value is
  1407. ** the actual number of bytes of randomness obtained.
  1408. ** The xSleep() method causes the calling thread to sleep for at
  1409. ** least the number of microseconds given. ^The xCurrentTime()
  1410. ** method returns a Julian Day Number for the current date and time as
  1411. ** a floating point value.
  1412. ** ^The xCurrentTimeInt64() method returns, as an integer, the Julian
  1413. ** Day Number multiplied by 86400000 (the number of milliseconds in
  1414. ** a 24-hour day).
  1415. ** ^SQLite will use the xCurrentTimeInt64() method to get the current
  1416. ** date and time if that method is available (if iVersion is 2 or
  1417. ** greater and the function pointer is not NULL) and will fall back
  1418. ** to xCurrentTime() if xCurrentTimeInt64() is unavailable.
  1419. **
  1420. ** ^The xSetSystemCall(), xGetSystemCall(), and xNestSystemCall() interfaces
  1421. ** are not used by the SQLite core. These optional interfaces are provided
  1422. ** by some VFSes to facilitate testing of the VFS code. By overriding
  1423. ** system calls with functions under its control, a test program can
  1424. ** simulate faults and error conditions that would otherwise be difficult
  1425. ** or impossible to induce. The set of system calls that can be overridden
  1426. ** varies from one VFS to another, and from one version of the same VFS to the
  1427. ** next. Applications that use these interfaces must be prepared for any
  1428. ** or all of these interfaces to be NULL or for their behavior to change
  1429. ** from one release to the next. Applications must not attempt to access
  1430. ** any of these methods if the iVersion of the VFS is less than 3.
  1431. */
  1432. typedef struct sqlite3_vfs sqlite3_vfs;
  1433. typedef void (*sqlite3_syscall_ptr)(void);
  1434. struct sqlite3_vfs {
  1435. int iVersion; /* Structure version number (currently 3) */
  1436. int szOsFile; /* Size of subclassed sqlite3_file */
  1437. int mxPathname; /* Maximum file pathname length */
  1438. sqlite3_vfs *pNext; /* Next registered VFS */
  1439. const char *zName; /* Name of this virtual file system */
  1440. void *pAppData; /* Pointer to application-specific data */
  1441. int (*xOpen)(sqlite3_vfs*, sqlite3_filename zName, sqlite3_file*,
  1442. int flags, int *pOutFlags);
  1443. int (*xDelete)(sqlite3_vfs*, const char *zName, int syncDir);
  1444. int (*xAccess)(sqlite3_vfs*, const char *zName, int flags, int *pResOut);
  1445. int (*xFullPathname)(sqlite3_vfs*, const char *zName, int nOut, char *zOut);
  1446. void *(*xDlOpen)(sqlite3_vfs*, const char *zFilename);
  1447. void (*xDlError)(sqlite3_vfs*, int nByte, char *zErrMsg);
  1448. void (*(*xDlSym)(sqlite3_vfs*,void*, const char *zSymbol))(void);
  1449. void (*xDlClose)(sqlite3_vfs*, void*);
  1450. int (*xRandomness)(sqlite3_vfs*, int nByte, char *zOut);
  1451. int (*xSleep)(sqlite3_vfs*, int microseconds);
  1452. int (*xCurrentTime)(sqlite3_vfs*, double*);
  1453. int (*xGetLastError)(sqlite3_vfs*, int, char *);
  1454. /*
  1455. ** The methods above are in version 1 of the sqlite_vfs object
  1456. ** definition. Those that follow are added in version 2 or later
  1457. */
  1458. int (*xCurrentTimeInt64)(sqlite3_vfs*, sqlite3_int64*);
  1459. /*
  1460. ** The methods above are in versions 1 and 2 of the sqlite_vfs object.
  1461. ** Those below are for version 3 and greater.
  1462. */
  1463. int (*xSetSystemCall)(sqlite3_vfs*, const char *zName, sqlite3_syscall_ptr);
  1464. sqlite3_syscall_ptr (*xGetSystemCall)(sqlite3_vfs*, const char *zName);
  1465. const char *(*xNextSystemCall)(sqlite3_vfs*, const char *zName);
  1466. /*
  1467. ** The methods above are in versions 1 through 3 of the sqlite_vfs object.
  1468. ** New fields may be appended in future versions. The iVersion
  1469. ** value will increment whenever this happens.
  1470. */
  1471. };
  1472. /*
  1473. ** CAPI3REF: Flags for the xAccess VFS method
  1474. **
  1475. ** These integer constants can be used as the third parameter to
  1476. ** the xAccess method of an [sqlite3_vfs] object. They determine
  1477. ** what kind of permissions the xAccess method is looking for.
  1478. ** With SQLITE_ACCESS_EXISTS, the xAccess method
  1479. ** simply checks whether the file exists.
  1480. ** With SQLITE_ACCESS_READWRITE, the xAccess method
  1481. ** checks whether the named directory is both readable and writable
  1482. ** (in other words, if files can be added, removed, and renamed within
  1483. ** the directory).
  1484. ** The SQLITE_ACCESS_READWRITE constant is currently used only by the
  1485. ** [temp_store_directory pragma], though this could change in a future
  1486. ** release of SQLite.
  1487. ** With SQLITE_ACCESS_READ, the xAccess method
  1488. ** checks whether the file is readable. The SQLITE_ACCESS_READ constant is
  1489. ** currently unused, though it might be used in a future release of
  1490. ** SQLite.
  1491. */
  1492. #define SQLITE_ACCESS_EXISTS 0
  1493. #define SQLITE_ACCESS_READWRITE 1 /* Used by PRAGMA temp_store_directory */
  1494. #define SQLITE_ACCESS_READ 2 /* Unused */
  1495. /*
  1496. ** CAPI3REF: Flags for the xShmLock VFS method
  1497. **
  1498. ** These integer constants define the various locking operations
  1499. ** allowed by the xShmLock method of [sqlite3_io_methods]. The
  1500. ** following are the only legal combinations of flags to the
  1501. ** xShmLock method:
  1502. **
  1503. ** <ul>
  1504. ** <li> SQLITE_SHM_LOCK | SQLITE_SHM_SHARED
  1505. ** <li> SQLITE_SHM_LOCK | SQLITE_SHM_EXCLUSIVE
  1506. ** <li> SQLITE_SHM_UNLOCK | SQLITE_SHM_SHARED
  1507. ** <li> SQLITE_SHM_UNLOCK | SQLITE_SHM_EXCLUSIVE
  1508. ** </ul>
  1509. **
  1510. ** When unlocking, the same SHARED or EXCLUSIVE flag must be supplied as
  1511. ** was given on the corresponding lock.
  1512. **
  1513. ** The xShmLock method can transition between unlocked and SHARED or
  1514. ** between unlocked and EXCLUSIVE. It cannot transition between SHARED
  1515. ** and EXCLUSIVE.
  1516. */
  1517. #define SQLITE_SHM_UNLOCK 1
  1518. #define SQLITE_SHM_LOCK 2
  1519. #define SQLITE_SHM_SHARED 4
  1520. #define SQLITE_SHM_EXCLUSIVE 8
  1521. /*
  1522. ** CAPI3REF: Maximum xShmLock index
  1523. **
  1524. ** The xShmLock method on [sqlite3_io_methods] may use values
  1525. ** between 0 and this upper bound as its "offset" argument.
  1526. ** The SQLite core will never attempt to acquire or release a
  1527. ** lock outside of this range
  1528. */
  1529. #define SQLITE_SHM_NLOCK 8
  1530. /*
  1531. ** CAPI3REF: Initialize The SQLite Library
  1532. **
  1533. ** ^The sqlite3_initialize() routine initializes the
  1534. ** SQLite library. ^The sqlite3_shutdown() routine
  1535. ** deallocates any resources that were allocated by sqlite3_initialize().
  1536. ** These routines are designed to aid in process initialization and
  1537. ** shutdown on embedded systems. Workstation applications using
  1538. ** SQLite normally do not need to invoke either of these routines.
  1539. **
  1540. ** A call to sqlite3_initialize() is an "effective" call if it is
  1541. ** the first time sqlite3_initialize() is invoked during the lifetime of
  1542. ** the process, or if it is the first time sqlite3_initialize() is invoked
  1543. ** following a call to sqlite3_shutdown(). ^(Only an effective call
  1544. ** of sqlite3_initialize() does any initialization. All other calls
  1545. ** are harmless no-ops.)^
  1546. **
  1547. ** A call to sqlite3_shutdown() is an "effective" call if it is the first
  1548. ** call to sqlite3_shutdown() since the last sqlite3_initialize(). ^(Only
  1549. ** an effective call to sqlite3_shutdown() does any deinitialization.
  1550. ** All other valid calls to sqlite3_shutdown() are harmless no-ops.)^
  1551. **
  1552. ** The sqlite3_initialize() interface is threadsafe, but sqlite3_shutdown()
  1553. ** is not. The sqlite3_shutdown() interface must only be called from a
  1554. ** single thread. All open [database connections] must be closed and all
  1555. ** other SQLite resources must be deallocated prior to invoking
  1556. ** sqlite3_shutdown().
  1557. **
  1558. ** Among other things, ^sqlite3_initialize() will invoke
  1559. ** sqlite3_os_init(). Similarly, ^sqlite3_shutdown()
  1560. ** will invoke sqlite3_os_end().
  1561. **
  1562. ** ^The sqlite3_initialize() routine returns [SQLITE_OK] on success.
  1563. ** ^If for some reason, sqlite3_initialize() is unable to initialize
  1564. ** the library (perhaps it is unable to allocate a needed resource such
  1565. ** as a mutex) it returns an [error code] other than [SQLITE_OK].
  1566. **
  1567. ** ^The sqlite3_initialize() routine is called internally by many other
  1568. ** SQLite interfaces so that an application usually does not need to
  1569. ** invoke sqlite3_initialize() directly. For example, [sqlite3_open()]
  1570. ** calls sqlite3_initialize() so the SQLite library will be automatically
  1571. ** initialized when [sqlite3_open()] is called if it has not be initialized
  1572. ** already. ^However, if SQLite is compiled with the [SQLITE_OMIT_AUTOINIT]
  1573. ** compile-time option, then the automatic calls to sqlite3_initialize()
  1574. ** are omitted and the application must call sqlite3_initialize() directly
  1575. ** prior to using any other SQLite interface. For maximum portability,
  1576. ** it is recommended that applications always invoke sqlite3_initialize()
  1577. ** directly prior to using any other SQLite interface. Future releases
  1578. ** of SQLite may require this. In other words, the behavior exhibited
  1579. ** when SQLite is compiled with [SQLITE_OMIT_AUTOINIT] might become the
  1580. ** default behavior in some future release of SQLite.
  1581. **
  1582. ** The sqlite3_os_init() routine does operating-system specific
  1583. ** initialization of the SQLite library. The sqlite3_os_end()
  1584. ** routine undoes the effect of sqlite3_os_init(). Typical tasks
  1585. ** performed by these routines include allocation or deallocation
  1586. ** of static resources, initialization of global variables,
  1587. ** setting up a default [sqlite3_vfs] module, or setting up
  1588. ** a default configuration using [sqlite3_config()].
  1589. **
  1590. ** The application should never invoke either sqlite3_os_init()
  1591. ** or sqlite3_os_end() directly. The application should only invoke
  1592. ** sqlite3_initialize() and sqlite3_shutdown(). The sqlite3_os_init()
  1593. ** interface is called automatically by sqlite3_initialize() and
  1594. ** sqlite3_os_end() is called by sqlite3_shutdown(). Appropriate
  1595. ** implementations for sqlite3_os_init() and sqlite3_os_end()
  1596. ** are built into SQLite when it is compiled for Unix, Windows, or OS/2.
  1597. ** When [custom builds | built for other platforms]
  1598. ** (using the [SQLITE_OS_OTHER=1] compile-time
  1599. ** option) the application must supply a suitable implementation for
  1600. ** sqlite3_os_init() and sqlite3_os_end(). An application-supplied
  1601. ** implementation of sqlite3_os_init() or sqlite3_os_end()
  1602. ** must return [SQLITE_OK] on success and some other [error code] upon
  1603. ** failure.
  1604. */
  1605. SQLITE_API int sqlite3_initialize(void);
  1606. SQLITE_API int sqlite3_shutdown(void);
  1607. SQLITE_API int sqlite3_os_init(void);
  1608. SQLITE_API int sqlite3_os_end(void);
  1609. /*
  1610. ** CAPI3REF: Configuring The SQLite Library
  1611. **
  1612. ** The sqlite3_config() interface is used to make global configuration
  1613. ** changes to SQLite in order to tune SQLite to the specific needs of
  1614. ** the application. The default configuration is recommended for most
  1615. ** applications and so this routine is usually not necessary. It is
  1616. ** provided to support rare applications with unusual needs.
  1617. **
  1618. ** <b>The sqlite3_config() interface is not threadsafe. The application
  1619. ** must ensure that no other SQLite interfaces are invoked by other
  1620. ** threads while sqlite3_config() is running.</b>
  1621. **
  1622. ** The first argument to sqlite3_config() is an integer
  1623. ** [configuration option] that determines
  1624. ** what property of SQLite is to be configured. Subsequent arguments
  1625. ** vary depending on the [configuration option]
  1626. ** in the first argument.
  1627. **
  1628. ** For most configuration options, the sqlite3_config() interface
  1629. ** may only be invoked prior to library initialization using
  1630. ** [sqlite3_initialize()] or after shutdown by [sqlite3_shutdown()].
  1631. ** The exceptional configuration options that may be invoked at any time
  1632. ** are called "anytime configuration options".
  1633. ** ^If sqlite3_config() is called after [sqlite3_initialize()] and before
  1634. ** [sqlite3_shutdown()] with a first argument that is not an anytime
  1635. ** configuration option, then the sqlite3_config() call will return SQLITE_MISUSE.
  1636. ** Note, however, that ^sqlite3_config() can be called as part of the
  1637. ** implementation of an application-defined [sqlite3_os_init()].
  1638. **
  1639. ** ^When a configuration option is set, sqlite3_config() returns [SQLITE_OK].
  1640. ** ^If the option is unknown or SQLite is unable to set the option
  1641. ** then this routine returns a non-zero [error code].
  1642. */
  1643. SQLITE_API int sqlite3_config(int, ...);
  1644. /*
  1645. ** CAPI3REF: Configure database connections
  1646. ** METHOD: sqlite3
  1647. **
  1648. ** The sqlite3_db_config() interface is used to make configuration
  1649. ** changes to a [database connection]. The interface is similar to
  1650. ** [sqlite3_config()] except that the changes apply to a single
  1651. ** [database connection] (specified in the first argument).
  1652. **
  1653. ** The second argument to sqlite3_db_config(D,V,...) is the
  1654. ** [SQLITE_DBCONFIG_LOOKASIDE | configuration verb] - an integer code
  1655. ** that indicates what aspect of the [database connection] is being configured.
  1656. ** Subsequent arguments vary depending on the configuration verb.
  1657. **
  1658. ** ^Calls to sqlite3_db_config() return SQLITE_OK if and only if
  1659. ** the call is considered successful.
  1660. */
  1661. SQLITE_API int sqlite3_db_config(sqlite3*, int op, ...);
  1662. /*
  1663. ** CAPI3REF: Memory Allocation Routines
  1664. **
  1665. ** An instance of this object defines the interface between SQLite
  1666. ** and low-level memory allocation routines.
  1667. **
  1668. ** This object is used in only one place in the SQLite interface.
  1669. ** A pointer to an instance of this object is the argument to
  1670. ** [sqlite3_config()] when the configuration option is
  1671. ** [SQLITE_CONFIG_MALLOC] or [SQLITE_CONFIG_GETMALLOC].
  1672. ** By creating an instance of this object
  1673. ** and passing it to [sqlite3_config]([SQLITE_CONFIG_MALLOC])
  1674. ** during configuration, an application can specify an alternative
  1675. ** memory allocation subsystem for SQLite to use for all of its
  1676. ** dynamic memory needs.
  1677. **
  1678. ** Note that SQLite comes with several [built-in memory allocators]
  1679. ** that are perfectly adequate for the overwhelming majority of applications
  1680. ** and that this object is only useful to a tiny minority of applications
  1681. ** with specialized memory allocation requirements. This object is
  1682. ** also used during testing of SQLite in order to specify an alternative
  1683. ** memory allocator that simulates memory out-of-memory conditions in
  1684. ** order to verify that SQLite recovers gracefully from such
  1685. ** conditions.
  1686. **
  1687. ** The xMalloc, xRealloc, and xFree methods must work like the
  1688. ** malloc(), realloc() and free() functions from the standard C library.
  1689. ** ^SQLite guarantees that the second argument to
  1690. ** xRealloc is always a value returned by a prior call to xRoundup.
  1691. **
  1692. ** xSize should return the allocated size of a memory allocation
  1693. ** previously obtained from xMalloc or xRealloc. The allocated size
  1694. ** is always at least as big as the requested size but may be larger.
  1695. **
  1696. ** The xRoundup method returns what would be the allocated size of
  1697. ** a memory allocation given a particular requested size. Most memory
  1698. ** allocators round up memory allocations at least to the next multiple
  1699. ** of 8. Some allocators round up to a larger multiple or to a power of 2.
  1700. ** Every memory allocation request coming in through [sqlite3_malloc()]
  1701. ** or [sqlite3_realloc()] first calls xRoundup. If xRoundup returns 0,
  1702. ** that causes the corresponding memory allocation to fail.
  1703. **
  1704. ** The xInit method initializes the memory allocator. For example,
  1705. ** it might allocate any required mutexes or initialize internal data
  1706. ** structures. The xShutdown method is invoked (indirectly) by
  1707. ** [sqlite3_shutdown()] and should deallocate any resources acquired
  1708. ** by xInit. The pAppData pointer is used as the only parameter to
  1709. ** xInit and xShutdown.
  1710. **
  1711. ** SQLite holds the [SQLITE_MUTEX_STATIC_MAIN] mutex when it invokes
  1712. ** the xInit method, so the xInit method need not be threadsafe. The
  1713. ** xShutdown method is only called from [sqlite3_shutdown()] so it does
  1714. ** not need to be threadsafe either. For all other methods, SQLite
  1715. ** holds the [SQLITE_MUTEX_STATIC_MEM] mutex as long as the
  1716. ** [SQLITE_CONFIG_MEMSTATUS] configuration option is turned on (which
  1717. ** it is by default) and so the methods are automatically serialized.
  1718. ** However, if [SQLITE_CONFIG_MEMSTATUS] is disabled, then the other
  1719. ** methods must be threadsafe or else make their own arrangements for
  1720. ** serialization.
  1721. **
  1722. ** SQLite will never invoke xInit() more than once without an intervening
  1723. ** call to xShutdown().
  1724. */
  1725. typedef struct sqlite3_mem_methods sqlite3_mem_methods;
  1726. struct sqlite3_mem_methods {
  1727. void *(*xMalloc)(int); /* Memory allocation function */
  1728. void (*xFree)(void*); /* Free a prior allocation */
  1729. void *(*xRealloc)(void*,int); /* Resize an allocation */
  1730. int (*xSize)(void*); /* Return the size of an allocation */
  1731. int (*xRoundup)(int); /* Round up request size to allocation size */
  1732. int (*xInit)(void*); /* Initialize the memory allocator */
  1733. void (*xShutdown)(void*); /* Deinitialize the memory allocator */
  1734. void *pAppData; /* Argument to xInit() and xShutdown() */
  1735. };
  1736. /*
  1737. ** CAPI3REF: Configuration Options
  1738. ** KEYWORDS: {configuration option}
  1739. **
  1740. ** These constants are the available integer configuration options that
  1741. ** can be passed as the first argument to the [sqlite3_config()] interface.
  1742. **
  1743. ** Most of the configuration options for sqlite3_config()
  1744. ** will only work if invoked prior to [sqlite3_initialize()] or after
  1745. ** [sqlite3_shutdown()]. The few exceptions to this rule are called
  1746. ** "anytime configuration options".
  1747. ** ^Calling [sqlite3_config()] with a first argument that is not an
  1748. ** anytime configuration option in between calls to [sqlite3_initialize()] and
  1749. ** [sqlite3_shutdown()] is a no-op that returns SQLITE_MISUSE.
  1750. **
  1751. ** The set of anytime configuration options can change (by insertions
  1752. ** and/or deletions) from one release of SQLite to the next.
  1753. ** As of SQLite version 3.42.0, the complete set of anytime configuration
  1754. ** options is:
  1755. ** <ul>
  1756. ** <li> SQLITE_CONFIG_LOG
  1757. ** <li> SQLITE_CONFIG_PCACHE_HDRSZ
  1758. ** </ul>
  1759. **
  1760. ** New configuration options may be added in future releases of SQLite.
  1761. ** Existing configuration options might be discontinued. Applications
  1762. ** should check the return code from [sqlite3_config()] to make sure that
  1763. ** the call worked. The [sqlite3_config()] interface will return a
  1764. ** non-zero [error code] if a discontinued or unsupported configuration option
  1765. ** is invoked.
  1766. **
  1767. ** <dl>
  1768. ** [[SQLITE_CONFIG_SINGLETHREAD]] <dt>SQLITE_CONFIG_SINGLETHREAD</dt>
  1769. ** <dd>There are no arguments to this option. ^This option sets the
  1770. ** [threading mode] to Single-thread. In other words, it disables
  1771. ** all mutexing and puts SQLite into a mode where it can only be used
  1772. ** by a single thread. ^If SQLite is compiled with
  1773. ** the [SQLITE_THREADSAFE | SQLITE_THREADSAFE=0] compile-time option then
  1774. ** it is not possible to change the [threading mode] from its default
  1775. ** value of Single-thread and so [sqlite3_config()] will return
  1776. ** [SQLITE_ERROR] if called with the SQLITE_CONFIG_SINGLETHREAD
  1777. ** configuration option.</dd>
  1778. **
  1779. ** [[SQLITE_CONFIG_MULTITHREAD]] <dt>SQLITE_CONFIG_MULTITHREAD</dt>
  1780. ** <dd>There are no arguments to this option. ^This option sets the
  1781. ** [threading mode] to Multi-thread. In other words, it disables
  1782. ** mutexing on [database connection] and [prepared statement] objects.
  1783. ** The application is responsible for serializing access to
  1784. ** [database connections] and [prepared statements]. But other mutexes
  1785. ** are enabled so that SQLite will be safe to use in a multi-threaded
  1786. ** environment as long as no two threads attempt to use the same
  1787. ** [database connection] at the same time. ^If SQLite is compiled with
  1788. ** the [SQLITE_THREADSAFE | SQLITE_THREADSAFE=0] compile-time option then
  1789. ** it is not possible to set the Multi-thread [threading mode] and
  1790. ** [sqlite3_config()] will return [SQLITE_ERROR] if called with the
  1791. ** SQLITE_CONFIG_MULTITHREAD configuration option.</dd>
  1792. **
  1793. ** [[SQLITE_CONFIG_SERIALIZED]] <dt>SQLITE_CONFIG_SERIALIZED</dt>
  1794. ** <dd>There are no arguments to this option. ^This option sets the
  1795. ** [threading mode] to Serialized. In other words, this option enables
  1796. ** all mutexes including the recursive
  1797. ** mutexes on [database connection] and [prepared statement] objects.
  1798. ** In this mode (which is the default when SQLite is compiled with
  1799. ** [SQLITE_THREADSAFE=1]) the SQLite library will itself serialize access
  1800. ** to [database connections] and [prepared statements] so that the
  1801. ** application is free to use the same [database connection] or the
  1802. ** same [prepared statement] in different threads at the same time.
  1803. ** ^If SQLite is compiled with
  1804. ** the [SQLITE_THREADSAFE | SQLITE_THREADSAFE=0] compile-time option then
  1805. ** it is not possible to set the Serialized [threading mode] and
  1806. ** [sqlite3_config()] will return [SQLITE_ERROR] if called with the
  1807. ** SQLITE_CONFIG_SERIALIZED configuration option.</dd>
  1808. **
  1809. ** [[SQLITE_CONFIG_MALLOC]] <dt>SQLITE_CONFIG_MALLOC</dt>
  1810. ** <dd> ^(The SQLITE_CONFIG_MALLOC option takes a single argument which is
  1811. ** a pointer to an instance of the [sqlite3_mem_methods] structure.
  1812. ** The argument specifies
  1813. ** alternative low-level memory allocation routines to be used in place of
  1814. ** the memory allocation routines built into SQLite.)^ ^SQLite makes
  1815. ** its own private copy of the content of the [sqlite3_mem_methods] structure
  1816. ** before the [sqlite3_config()] call returns.</dd>
  1817. **
  1818. ** [[SQLITE_CONFIG_GETMALLOC]] <dt>SQLITE_CONFIG_GETMALLOC</dt>
  1819. ** <dd> ^(The SQLITE_CONFIG_GETMALLOC option takes a single argument which
  1820. ** is a pointer to an instance of the [sqlite3_mem_methods] structure.
  1821. ** The [sqlite3_mem_methods]
  1822. ** structure is filled with the currently defined memory allocation routines.)^
  1823. ** This option can be used to overload the default memory allocation
  1824. ** routines with a wrapper that simulations memory allocation failure or
  1825. ** tracks memory usage, for example. </dd>
  1826. **
  1827. ** [[SQLITE_CONFIG_SMALL_MALLOC]] <dt>SQLITE_CONFIG_SMALL_MALLOC</dt>
  1828. ** <dd> ^The SQLITE_CONFIG_SMALL_MALLOC option takes single argument of
  1829. ** type int, interpreted as a boolean, which if true provides a hint to
  1830. ** SQLite that it should avoid large memory allocations if possible.
  1831. ** SQLite will run faster if it is free to make large memory allocations,
  1832. ** but some application might prefer to run slower in exchange for
  1833. ** guarantees about memory fragmentation that are possible if large
  1834. ** allocations are avoided. This hint is normally off.
  1835. ** </dd>
  1836. **
  1837. ** [[SQLITE_CONFIG_MEMSTATUS]] <dt>SQLITE_CONFIG_MEMSTATUS</dt>
  1838. ** <dd> ^The SQLITE_CONFIG_MEMSTATUS option takes single argument of type int,
  1839. ** interpreted as a boolean, which enables or disables the collection of
  1840. ** memory allocation statistics. ^(When memory allocation statistics are
  1841. ** disabled, the following SQLite interfaces become non-operational:
  1842. ** <ul>
  1843. ** <li> [sqlite3_hard_heap_limit64()]
  1844. ** <li> [sqlite3_memory_used()]
  1845. ** <li> [sqlite3_memory_highwater()]
  1846. ** <li> [sqlite3_soft_heap_limit64()]
  1847. ** <li> [sqlite3_status64()]
  1848. ** </ul>)^
  1849. ** ^Memory allocation statistics are enabled by default unless SQLite is
  1850. ** compiled with [SQLITE_DEFAULT_MEMSTATUS]=0 in which case memory
  1851. ** allocation statistics are disabled by default.
  1852. ** </dd>
  1853. **
  1854. ** [[SQLITE_CONFIG_SCRATCH]] <dt>SQLITE_CONFIG_SCRATCH</dt>
  1855. ** <dd> The SQLITE_CONFIG_SCRATCH option is no longer used.
  1856. ** </dd>
  1857. **
  1858. ** [[SQLITE_CONFIG_PAGECACHE]] <dt>SQLITE_CONFIG_PAGECACHE</dt>
  1859. ** <dd> ^The SQLITE_CONFIG_PAGECACHE option specifies a memory pool
  1860. ** that SQLite can use for the database page cache with the default page
  1861. ** cache implementation.
  1862. ** This configuration option is a no-op if an application-defined page
  1863. ** cache implementation is loaded using the [SQLITE_CONFIG_PCACHE2].
  1864. ** ^There are three arguments to SQLITE_CONFIG_PAGECACHE: A pointer to
  1865. ** 8-byte aligned memory (pMem), the size of each page cache line (sz),
  1866. ** and the number of cache lines (N).
  1867. ** The sz argument should be the size of the largest database page
  1868. ** (a power of two between 512 and 65536) plus some extra bytes for each
  1869. ** page header. ^The number of extra bytes needed by the page header
  1870. ** can be determined using [SQLITE_CONFIG_PCACHE_HDRSZ].
  1871. ** ^It is harmless, apart from the wasted memory,
  1872. ** for the sz parameter to be larger than necessary. The pMem
  1873. ** argument must be either a NULL pointer or a pointer to an 8-byte
  1874. ** aligned block of memory of at least sz*N bytes, otherwise
  1875. ** subsequent behavior is undefined.
  1876. ** ^When pMem is not NULL, SQLite will strive to use the memory provided
  1877. ** to satisfy page cache needs, falling back to [sqlite3_malloc()] if
  1878. ** a page cache line is larger than sz bytes or if all of the pMem buffer
  1879. ** is exhausted.
  1880. ** ^If pMem is NULL and N is non-zero, then each database connection
  1881. ** does an initial bulk allocation for page cache memory
  1882. ** from [sqlite3_malloc()] sufficient for N cache lines if N is positive or
  1883. ** of -1024*N bytes if N is negative, . ^If additional
  1884. ** page cache memory is needed beyond what is provided by the initial
  1885. ** allocation, then SQLite goes to [sqlite3_malloc()] separately for each
  1886. ** additional cache line. </dd>
  1887. **
  1888. ** [[SQLITE_CONFIG_HEAP]] <dt>SQLITE_CONFIG_HEAP</dt>
  1889. ** <dd> ^The SQLITE_CONFIG_HEAP option specifies a static memory buffer
  1890. ** that SQLite will use for all of its dynamic memory allocation needs
  1891. ** beyond those provided for by [SQLITE_CONFIG_PAGECACHE].
  1892. ** ^The SQLITE_CONFIG_HEAP option is only available if SQLite is compiled
  1893. ** with either [SQLITE_ENABLE_MEMSYS3] or [SQLITE_ENABLE_MEMSYS5] and returns
  1894. ** [SQLITE_ERROR] if invoked otherwise.
  1895. ** ^There are three arguments to SQLITE_CONFIG_HEAP:
  1896. ** An 8-byte aligned pointer to the memory,
  1897. ** the number of bytes in the memory buffer, and the minimum allocation size.
  1898. ** ^If the first pointer (the memory pointer) is NULL, then SQLite reverts
  1899. ** to using its default memory allocator (the system malloc() implementation),
  1900. ** undoing any prior invocation of [SQLITE_CONFIG_MALLOC]. ^If the
  1901. ** memory pointer is not NULL then the alternative memory
  1902. ** allocator is engaged to handle all of SQLites memory allocation needs.
  1903. ** The first pointer (the memory pointer) must be aligned to an 8-byte
  1904. ** boundary or subsequent behavior of SQLite will be undefined.
  1905. ** The minimum allocation size is capped at 2**12. Reasonable values
  1906. ** for the minimum allocation size are 2**5 through 2**8.</dd>
  1907. **
  1908. ** [[SQLITE_CONFIG_MUTEX]] <dt>SQLITE_CONFIG_MUTEX</dt>
  1909. ** <dd> ^(The SQLITE_CONFIG_MUTEX option takes a single argument which is a
  1910. ** pointer to an instance of the [sqlite3_mutex_methods] structure.
  1911. ** The argument specifies alternative low-level mutex routines to be used
  1912. ** in place the mutex routines built into SQLite.)^ ^SQLite makes a copy of
  1913. ** the content of the [sqlite3_mutex_methods] structure before the call to
  1914. ** [sqlite3_config()] returns. ^If SQLite is compiled with
  1915. ** the [SQLITE_THREADSAFE | SQLITE_THREADSAFE=0] compile-time option then
  1916. ** the entire mutexing subsystem is omitted from the build and hence calls to
  1917. ** [sqlite3_config()] with the SQLITE_CONFIG_MUTEX configuration option will
  1918. ** return [SQLITE_ERROR].</dd>
  1919. **
  1920. ** [[SQLITE_CONFIG_GETMUTEX]] <dt>SQLITE_CONFIG_GETMUTEX</dt>
  1921. ** <dd> ^(The SQLITE_CONFIG_GETMUTEX option takes a single argument which
  1922. ** is a pointer to an instance of the [sqlite3_mutex_methods] structure. The
  1923. ** [sqlite3_mutex_methods]
  1924. ** structure is filled with the currently defined mutex routines.)^
  1925. ** This option can be used to overload the default mutex allocation
  1926. ** routines with a wrapper used to track mutex usage for performance
  1927. ** profiling or testing, for example. ^If SQLite is compiled with
  1928. ** the [SQLITE_THREADSAFE | SQLITE_THREADSAFE=0] compile-time option then
  1929. ** the entire mutexing subsystem is omitted from the build and hence calls to
  1930. ** [sqlite3_config()] with the SQLITE_CONFIG_GETMUTEX configuration option will
  1931. ** return [SQLITE_ERROR].</dd>
  1932. **
  1933. ** [[SQLITE_CONFIG_LOOKASIDE]] <dt>SQLITE_CONFIG_LOOKASIDE</dt>
  1934. ** <dd> ^(The SQLITE_CONFIG_LOOKASIDE option takes two arguments that determine
  1935. ** the default size of lookaside memory on each [database connection].
  1936. ** The first argument is the
  1937. ** size of each lookaside buffer slot and the second is the number of
  1938. ** slots allocated to each database connection.)^ ^(SQLITE_CONFIG_LOOKASIDE
  1939. ** sets the <i>default</i> lookaside size. The [SQLITE_DBCONFIG_LOOKASIDE]
  1940. ** option to [sqlite3_db_config()] can be used to change the lookaside
  1941. ** configuration on individual connections.)^ </dd>
  1942. **
  1943. ** [[SQLITE_CONFIG_PCACHE2]] <dt>SQLITE_CONFIG_PCACHE2</dt>
  1944. ** <dd> ^(The SQLITE_CONFIG_PCACHE2 option takes a single argument which is
  1945. ** a pointer to an [sqlite3_pcache_methods2] object. This object specifies
  1946. ** the interface to a custom page cache implementation.)^
  1947. ** ^SQLite makes a copy of the [sqlite3_pcache_methods2] object.</dd>
  1948. **
  1949. ** [[SQLITE_CONFIG_GETPCACHE2]] <dt>SQLITE_CONFIG_GETPCACHE2</dt>
  1950. ** <dd> ^(The SQLITE_CONFIG_GETPCACHE2 option takes a single argument which
  1951. ** is a pointer to an [sqlite3_pcache_methods2] object. SQLite copies of
  1952. ** the current page cache implementation into that object.)^ </dd>
  1953. **
  1954. ** [[SQLITE_CONFIG_LOG]] <dt>SQLITE_CONFIG_LOG</dt>
  1955. ** <dd> The SQLITE_CONFIG_LOG option is used to configure the SQLite
  1956. ** global [error log].
  1957. ** (^The SQLITE_CONFIG_LOG option takes two arguments: a pointer to a
  1958. ** function with a call signature of void(*)(void*,int,const char*),
  1959. ** and a pointer to void. ^If the function pointer is not NULL, it is
  1960. ** invoked by [sqlite3_log()] to process each logging event. ^If the
  1961. ** function pointer is NULL, the [sqlite3_log()] interface becomes a no-op.
  1962. ** ^The void pointer that is the second argument to SQLITE_CONFIG_LOG is
  1963. ** passed through as the first parameter to the application-defined logger
  1964. ** function whenever that function is invoked. ^The second parameter to
  1965. ** the logger function is a copy of the first parameter to the corresponding
  1966. ** [sqlite3_log()] call and is intended to be a [result code] or an
  1967. ** [extended result code]. ^The third parameter passed to the logger is
  1968. ** log message after formatting via [sqlite3_snprintf()].
  1969. ** The SQLite logging interface is not reentrant; the logger function
  1970. ** supplied by the application must not invoke any SQLite interface.
  1971. ** In a multi-threaded application, the application-defined logger
  1972. ** function must be threadsafe. </dd>
  1973. **
  1974. ** [[SQLITE_CONFIG_URI]] <dt>SQLITE_CONFIG_URI
  1975. ** <dd>^(The SQLITE_CONFIG_URI option takes a single argument of type int.
  1976. ** If non-zero, then URI handling is globally enabled. If the parameter is zero,
  1977. ** then URI handling is globally disabled.)^ ^If URI handling is globally
  1978. ** enabled, all filenames passed to [sqlite3_open()], [sqlite3_open_v2()],
  1979. ** [sqlite3_open16()] or
  1980. ** specified as part of [ATTACH] commands are interpreted as URIs, regardless
  1981. ** of whether or not the [SQLITE_OPEN_URI] flag is set when the database
  1982. ** connection is opened. ^If it is globally disabled, filenames are
  1983. ** only interpreted as URIs if the SQLITE_OPEN_URI flag is set when the
  1984. ** database connection is opened. ^(By default, URI handling is globally
  1985. ** disabled. The default value may be changed by compiling with the
  1986. ** [SQLITE_USE_URI] symbol defined.)^
  1987. **
  1988. ** [[SQLITE_CONFIG_COVERING_INDEX_SCAN]] <dt>SQLITE_CONFIG_COVERING_INDEX_SCAN
  1989. ** <dd>^The SQLITE_CONFIG_COVERING_INDEX_SCAN option takes a single integer
  1990. ** argument which is interpreted as a boolean in order to enable or disable
  1991. ** the use of covering indices for full table scans in the query optimizer.
  1992. ** ^The default setting is determined
  1993. ** by the [SQLITE_ALLOW_COVERING_INDEX_SCAN] compile-time option, or is "on"
  1994. ** if that compile-time option is omitted.
  1995. ** The ability to disable the use of covering indices for full table scans
  1996. ** is because some incorrectly coded legacy applications might malfunction
  1997. ** when the optimization is enabled. Providing the ability to
  1998. ** disable the optimization allows the older, buggy application code to work
  1999. ** without change even with newer versions of SQLite.
  2000. **
  2001. ** [[SQLITE_CONFIG_PCACHE]] [[SQLITE_CONFIG_GETPCACHE]]
  2002. ** <dt>SQLITE_CONFIG_PCACHE and SQLITE_CONFIG_GETPCACHE
  2003. ** <dd> These options are obsolete and should not be used by new code.
  2004. ** They are retained for backwards compatibility but are now no-ops.
  2005. ** </dd>
  2006. **
  2007. ** [[SQLITE_CONFIG_SQLLOG]]
  2008. ** <dt>SQLITE_CONFIG_SQLLOG
  2009. ** <dd>This option is only available if sqlite is compiled with the
  2010. ** [SQLITE_ENABLE_SQLLOG] pre-processor macro defined. The first argument should
  2011. ** be a pointer to a function of type void(*)(void*,sqlite3*,const char*, int).
  2012. ** The second should be of type (void*). The callback is invoked by the library
  2013. ** in three separate circumstances, identified by the value passed as the
  2014. ** fourth parameter. If the fourth parameter is 0, then the database connection
  2015. ** passed as the second argument has just been opened. The third argument
  2016. ** points to a buffer containing the name of the main database file. If the
  2017. ** fourth parameter is 1, then the SQL statement that the third parameter
  2018. ** points to has just been executed. Or, if the fourth parameter is 2, then
  2019. ** the connection being passed as the second parameter is being closed. The
  2020. ** third parameter is passed NULL In this case. An example of using this
  2021. ** configuration option can be seen in the "test_sqllog.c" source file in
  2022. ** the canonical SQLite source tree.</dd>
  2023. **
  2024. ** [[SQLITE_CONFIG_MMAP_SIZE]]
  2025. ** <dt>SQLITE_CONFIG_MMAP_SIZE
  2026. ** <dd>^SQLITE_CONFIG_MMAP_SIZE takes two 64-bit integer (sqlite3_int64) values
  2027. ** that are the default mmap size limit (the default setting for
  2028. ** [PRAGMA mmap_size]) and the maximum allowed mmap size limit.
  2029. ** ^The default setting can be overridden by each database connection using
  2030. ** either the [PRAGMA mmap_size] command, or by using the
  2031. ** [SQLITE_FCNTL_MMAP_SIZE] file control. ^(The maximum allowed mmap size
  2032. ** will be silently truncated if necessary so that it does not exceed the
  2033. ** compile-time maximum mmap size set by the
  2034. ** [SQLITE_MAX_MMAP_SIZE] compile-time option.)^
  2035. ** ^If either argument to this option is negative, then that argument is
  2036. ** changed to its compile-time default.
  2037. **
  2038. ** [[SQLITE_CONFIG_WIN32_HEAPSIZE]]
  2039. ** <dt>SQLITE_CONFIG_WIN32_HEAPSIZE
  2040. ** <dd>^The SQLITE_CONFIG_WIN32_HEAPSIZE option is only available if SQLite is
  2041. ** compiled for Windows with the [SQLITE_WIN32_MALLOC] pre-processor macro
  2042. ** defined. ^SQLITE_CONFIG_WIN32_HEAPSIZE takes a 32-bit unsigned integer value
  2043. ** that specifies the maximum size of the created heap.
  2044. **
  2045. ** [[SQLITE_CONFIG_PCACHE_HDRSZ]]
  2046. ** <dt>SQLITE_CONFIG_PCACHE_HDRSZ
  2047. ** <dd>^The SQLITE_CONFIG_PCACHE_HDRSZ option takes a single parameter which
  2048. ** is a pointer to an integer and writes into that integer the number of extra
  2049. ** bytes per page required for each page in [SQLITE_CONFIG_PAGECACHE].
  2050. ** The amount of extra space required can change depending on the compiler,
  2051. ** target platform, and SQLite version.
  2052. **
  2053. ** [[SQLITE_CONFIG_PMASZ]]
  2054. ** <dt>SQLITE_CONFIG_PMASZ
  2055. ** <dd>^The SQLITE_CONFIG_PMASZ option takes a single parameter which
  2056. ** is an unsigned integer and sets the "Minimum PMA Size" for the multithreaded
  2057. ** sorter to that integer. The default minimum PMA Size is set by the
  2058. ** [SQLITE_SORTER_PMASZ] compile-time option. New threads are launched
  2059. ** to help with sort operations when multithreaded sorting
  2060. ** is enabled (using the [PRAGMA threads] command) and the amount of content
  2061. ** to be sorted exceeds the page size times the minimum of the
  2062. ** [PRAGMA cache_size] setting and this value.
  2063. **
  2064. ** [[SQLITE_CONFIG_STMTJRNL_SPILL]]
  2065. ** <dt>SQLITE_CONFIG_STMTJRNL_SPILL
  2066. ** <dd>^The SQLITE_CONFIG_STMTJRNL_SPILL option takes a single parameter which
  2067. ** becomes the [statement journal] spill-to-disk threshold.
  2068. ** [Statement journals] are held in memory until their size (in bytes)
  2069. ** exceeds this threshold, at which point they are written to disk.
  2070. ** Or if the threshold is -1, statement journals are always held
  2071. ** exclusively in memory.
  2072. ** Since many statement journals never become large, setting the spill
  2073. ** threshold to a value such as 64KiB can greatly reduce the amount of
  2074. ** I/O required to support statement rollback.
  2075. ** The default value for this setting is controlled by the
  2076. ** [SQLITE_STMTJRNL_SPILL] compile-time option.
  2077. **
  2078. ** [[SQLITE_CONFIG_SORTERREF_SIZE]]
  2079. ** <dt>SQLITE_CONFIG_SORTERREF_SIZE
  2080. ** <dd>The SQLITE_CONFIG_SORTERREF_SIZE option accepts a single parameter
  2081. ** of type (int) - the new value of the sorter-reference size threshold.
  2082. ** Usually, when SQLite uses an external sort to order records according
  2083. ** to an ORDER BY clause, all fields required by the caller are present in the
  2084. ** sorted records. However, if SQLite determines based on the declared type
  2085. ** of a table column that its values are likely to be very large - larger
  2086. ** than the configured sorter-reference size threshold - then a reference
  2087. ** is stored in each sorted record and the required column values loaded
  2088. ** from the database as records are returned in sorted order. The default
  2089. ** value for this option is to never use this optimization. Specifying a
  2090. ** negative value for this option restores the default behavior.
  2091. ** This option is only available if SQLite is compiled with the
  2092. ** [SQLITE_ENABLE_SORTER_REFERENCES] compile-time option.
  2093. **
  2094. ** [[SQLITE_CONFIG_MEMDB_MAXSIZE]]
  2095. ** <dt>SQLITE_CONFIG_MEMDB_MAXSIZE
  2096. ** <dd>The SQLITE_CONFIG_MEMDB_MAXSIZE option accepts a single parameter
  2097. ** [sqlite3_int64] parameter which is the default maximum size for an in-memory
  2098. ** database created using [sqlite3_deserialize()]. This default maximum
  2099. ** size can be adjusted up or down for individual databases using the
  2100. ** [SQLITE_FCNTL_SIZE_LIMIT] [sqlite3_file_control|file-control]. If this
  2101. ** configuration setting is never used, then the default maximum is determined
  2102. ** by the [SQLITE_MEMDB_DEFAULT_MAXSIZE] compile-time option. If that
  2103. ** compile-time option is not set, then the default maximum is 1073741824.
  2104. ** </dl>
  2105. */
  2106. #define SQLITE_CONFIG_SINGLETHREAD 1 /* nil */
  2107. #define SQLITE_CONFIG_MULTITHREAD 2 /* nil */
  2108. #define SQLITE_CONFIG_SERIALIZED 3 /* nil */
  2109. #define SQLITE_CONFIG_MALLOC 4 /* sqlite3_mem_methods* */
  2110. #define SQLITE_CONFIG_GETMALLOC 5 /* sqlite3_mem_methods* */
  2111. #define SQLITE_CONFIG_SCRATCH 6 /* No longer used */
  2112. #define SQLITE_CONFIG_PAGECACHE 7 /* void*, int sz, int N */
  2113. #define SQLITE_CONFIG_HEAP 8 /* void*, int nByte, int min */
  2114. #define SQLITE_CONFIG_MEMSTATUS 9 /* boolean */
  2115. #define SQLITE_CONFIG_MUTEX 10 /* sqlite3_mutex_methods* */
  2116. #define SQLITE_CONFIG_GETMUTEX 11 /* sqlite3_mutex_methods* */
  2117. /* previously SQLITE_CONFIG_CHUNKALLOC 12 which is now unused. */
  2118. #define SQLITE_CONFIG_LOOKASIDE 13 /* int int */
  2119. #define SQLITE_CONFIG_PCACHE 14 /* no-op */
  2120. #define SQLITE_CONFIG_GETPCACHE 15 /* no-op */
  2121. #define SQLITE_CONFIG_LOG 16 /* xFunc, void* */
  2122. #define SQLITE_CONFIG_URI 17 /* int */
  2123. #define SQLITE_CONFIG_PCACHE2 18 /* sqlite3_pcache_methods2* */
  2124. #define SQLITE_CONFIG_GETPCACHE2 19 /* sqlite3_pcache_methods2* */
  2125. #define SQLITE_CONFIG_COVERING_INDEX_SCAN 20 /* int */
  2126. #define SQLITE_CONFIG_SQLLOG 21 /* xSqllog, void* */
  2127. #define SQLITE_CONFIG_MMAP_SIZE 22 /* sqlite3_int64, sqlite3_int64 */
  2128. #define SQLITE_CONFIG_WIN32_HEAPSIZE 23 /* int nByte */
  2129. #define SQLITE_CONFIG_PCACHE_HDRSZ 24 /* int *psz */
  2130. #define SQLITE_CONFIG_PMASZ 25 /* unsigned int szPma */
  2131. #define SQLITE_CONFIG_STMTJRNL_SPILL 26 /* int nByte */
  2132. #define SQLITE_CONFIG_SMALL_MALLOC 27 /* boolean */
  2133. #define SQLITE_CONFIG_SORTERREF_SIZE 28 /* int nByte */
  2134. #define SQLITE_CONFIG_MEMDB_MAXSIZE 29 /* sqlite3_int64 */
  2135. /*
  2136. ** CAPI3REF: Database Connection Configuration Options
  2137. **
  2138. ** These constants are the available integer configuration options that
  2139. ** can be passed as the second argument to the [sqlite3_db_config()] interface.
  2140. **
  2141. ** New configuration options may be added in future releases of SQLite.
  2142. ** Existing configuration options might be discontinued. Applications
  2143. ** should check the return code from [sqlite3_db_config()] to make sure that
  2144. ** the call worked. ^The [sqlite3_db_config()] interface will return a
  2145. ** non-zero [error code] if a discontinued or unsupported configuration option
  2146. ** is invoked.
  2147. **
  2148. ** <dl>
  2149. ** [[SQLITE_DBCONFIG_LOOKASIDE]]
  2150. ** <dt>SQLITE_DBCONFIG_LOOKASIDE</dt>
  2151. ** <dd> ^This option takes three additional arguments that determine the
  2152. ** [lookaside memory allocator] configuration for the [database connection].
  2153. ** ^The first argument (the third parameter to [sqlite3_db_config()] is a
  2154. ** pointer to a memory buffer to use for lookaside memory.
  2155. ** ^The first argument after the SQLITE_DBCONFIG_LOOKASIDE verb
  2156. ** may be NULL in which case SQLite will allocate the
  2157. ** lookaside buffer itself using [sqlite3_malloc()]. ^The second argument is the
  2158. ** size of each lookaside buffer slot. ^The third argument is the number of
  2159. ** slots. The size of the buffer in the first argument must be greater than
  2160. ** or equal to the product of the second and third arguments. The buffer
  2161. ** must be aligned to an 8-byte boundary. ^If the second argument to
  2162. ** SQLITE_DBCONFIG_LOOKASIDE is not a multiple of 8, it is internally
  2163. ** rounded down to the next smaller multiple of 8. ^(The lookaside memory
  2164. ** configuration for a database connection can only be changed when that
  2165. ** connection is not currently using lookaside memory, or in other words
  2166. ** when the "current value" returned by
  2167. ** [sqlite3_db_status](D,[SQLITE_DBSTATUS_LOOKASIDE_USED],...) is zero.
  2168. ** Any attempt to change the lookaside memory configuration when lookaside
  2169. ** memory is in use leaves the configuration unchanged and returns
  2170. ** [SQLITE_BUSY].)^</dd>
  2171. **
  2172. ** [[SQLITE_DBCONFIG_ENABLE_FKEY]]
  2173. ** <dt>SQLITE_DBCONFIG_ENABLE_FKEY</dt>
  2174. ** <dd> ^This option is used to enable or disable the enforcement of
  2175. ** [foreign key constraints]. There should be two additional arguments.
  2176. ** The first argument is an integer which is 0 to disable FK enforcement,
  2177. ** positive to enable FK enforcement or negative to leave FK enforcement
  2178. ** unchanged. The second parameter is a pointer to an integer into which
  2179. ** is written 0 or 1 to indicate whether FK enforcement is off or on
  2180. ** following this call. The second parameter may be a NULL pointer, in
  2181. ** which case the FK enforcement setting is not reported back. </dd>
  2182. **
  2183. ** [[SQLITE_DBCONFIG_ENABLE_TRIGGER]]
  2184. ** <dt>SQLITE_DBCONFIG_ENABLE_TRIGGER</dt>
  2185. ** <dd> ^This option is used to enable or disable [CREATE TRIGGER | triggers].
  2186. ** There should be two additional arguments.
  2187. ** The first argument is an integer which is 0 to disable triggers,
  2188. ** positive to enable triggers or negative to leave the setting unchanged.
  2189. ** The second parameter is a pointer to an integer into which
  2190. ** is written 0 or 1 to indicate whether triggers are disabled or enabled
  2191. ** following this call. The second parameter may be a NULL pointer, in
  2192. ** which case the trigger setting is not reported back.
  2193. **
  2194. ** <p>Originally this option disabled all triggers. ^(However, since
  2195. ** SQLite version 3.35.0, TEMP triggers are still allowed even if
  2196. ** this option is off. So, in other words, this option now only disables
  2197. ** triggers in the main database schema or in the schemas of ATTACH-ed
  2198. ** databases.)^ </dd>
  2199. **
  2200. ** [[SQLITE_DBCONFIG_ENABLE_VIEW]]
  2201. ** <dt>SQLITE_DBCONFIG_ENABLE_VIEW</dt>
  2202. ** <dd> ^This option is used to enable or disable [CREATE VIEW | views].
  2203. ** There should be two additional arguments.
  2204. ** The first argument is an integer which is 0 to disable views,
  2205. ** positive to enable views or negative to leave the setting unchanged.
  2206. ** The second parameter is a pointer to an integer into which
  2207. ** is written 0 or 1 to indicate whether views are disabled or enabled
  2208. ** following this call. The second parameter may be a NULL pointer, in
  2209. ** which case the view setting is not reported back.
  2210. **
  2211. ** <p>Originally this option disabled all views. ^(However, since
  2212. ** SQLite version 3.35.0, TEMP views are still allowed even if
  2213. ** this option is off. So, in other words, this option now only disables
  2214. ** views in the main database schema or in the schemas of ATTACH-ed
  2215. ** databases.)^ </dd>
  2216. **
  2217. ** [[SQLITE_DBCONFIG_ENABLE_FTS3_TOKENIZER]]
  2218. ** <dt>SQLITE_DBCONFIG_ENABLE_FTS3_TOKENIZER</dt>
  2219. ** <dd> ^This option is used to enable or disable the
  2220. ** [fts3_tokenizer()] function which is part of the
  2221. ** [FTS3] full-text search engine extension.
  2222. ** There should be two additional arguments.
  2223. ** The first argument is an integer which is 0 to disable fts3_tokenizer() or
  2224. ** positive to enable fts3_tokenizer() or negative to leave the setting
  2225. ** unchanged.
  2226. ** The second parameter is a pointer to an integer into which
  2227. ** is written 0 or 1 to indicate whether fts3_tokenizer is disabled or enabled
  2228. ** following this call. The second parameter may be a NULL pointer, in
  2229. ** which case the new setting is not reported back. </dd>
  2230. **
  2231. ** [[SQLITE_DBCONFIG_ENABLE_LOAD_EXTENSION]]
  2232. ** <dt>SQLITE_DBCONFIG_ENABLE_LOAD_EXTENSION</dt>
  2233. ** <dd> ^This option is used to enable or disable the [sqlite3_load_extension()]
  2234. ** interface independently of the [load_extension()] SQL function.
  2235. ** The [sqlite3_enable_load_extension()] API enables or disables both the
  2236. ** C-API [sqlite3_load_extension()] and the SQL function [load_extension()].
  2237. ** There should be two additional arguments.
  2238. ** When the first argument to this interface is 1, then only the C-API is
  2239. ** enabled and the SQL function remains disabled. If the first argument to
  2240. ** this interface is 0, then both the C-API and the SQL function are disabled.
  2241. ** If the first argument is -1, then no changes are made to state of either the
  2242. ** C-API or the SQL function.
  2243. ** The second parameter is a pointer to an integer into which
  2244. ** is written 0 or 1 to indicate whether [sqlite3_load_extension()] interface
  2245. ** is disabled or enabled following this call. The second parameter may
  2246. ** be a NULL pointer, in which case the new setting is not reported back.
  2247. ** </dd>
  2248. **
  2249. ** [[SQLITE_DBCONFIG_MAINDBNAME]] <dt>SQLITE_DBCONFIG_MAINDBNAME</dt>
  2250. ** <dd> ^This option is used to change the name of the "main" database
  2251. ** schema. ^The sole argument is a pointer to a constant UTF8 string
  2252. ** which will become the new schema name in place of "main". ^SQLite
  2253. ** does not make a copy of the new main schema name string, so the application
  2254. ** must ensure that the argument passed into this DBCONFIG option is unchanged
  2255. ** until after the database connection closes.
  2256. ** </dd>
  2257. **
  2258. ** [[SQLITE_DBCONFIG_NO_CKPT_ON_CLOSE]]
  2259. ** <dt>SQLITE_DBCONFIG_NO_CKPT_ON_CLOSE</dt>
  2260. ** <dd> Usually, when a database in wal mode is closed or detached from a
  2261. ** database handle, SQLite checks if this will mean that there are now no
  2262. ** connections at all to the database. If so, it performs a checkpoint
  2263. ** operation before closing the connection. This option may be used to
  2264. ** override this behavior. The first parameter passed to this operation
  2265. ** is an integer - positive to disable checkpoints-on-close, or zero (the
  2266. ** default) to enable them, and negative to leave the setting unchanged.
  2267. ** The second parameter is a pointer to an integer
  2268. ** into which is written 0 or 1 to indicate whether checkpoints-on-close
  2269. ** have been disabled - 0 if they are not disabled, 1 if they are.
  2270. ** </dd>
  2271. **
  2272. ** [[SQLITE_DBCONFIG_ENABLE_QPSG]] <dt>SQLITE_DBCONFIG_ENABLE_QPSG</dt>
  2273. ** <dd>^(The SQLITE_DBCONFIG_ENABLE_QPSG option activates or deactivates
  2274. ** the [query planner stability guarantee] (QPSG). When the QPSG is active,
  2275. ** a single SQL query statement will always use the same algorithm regardless
  2276. ** of values of [bound parameters].)^ The QPSG disables some query optimizations
  2277. ** that look at the values of bound parameters, which can make some queries
  2278. ** slower. But the QPSG has the advantage of more predictable behavior. With
  2279. ** the QPSG active, SQLite will always use the same query plan in the field as
  2280. ** was used during testing in the lab.
  2281. ** The first argument to this setting is an integer which is 0 to disable
  2282. ** the QPSG, positive to enable QPSG, or negative to leave the setting
  2283. ** unchanged. The second parameter is a pointer to an integer into which
  2284. ** is written 0 or 1 to indicate whether the QPSG is disabled or enabled
  2285. ** following this call.
  2286. ** </dd>
  2287. **
  2288. ** [[SQLITE_DBCONFIG_TRIGGER_EQP]] <dt>SQLITE_DBCONFIG_TRIGGER_EQP</dt>
  2289. ** <dd> By default, the output of EXPLAIN QUERY PLAN commands does not
  2290. ** include output for any operations performed by trigger programs. This
  2291. ** option is used to set or clear (the default) a flag that governs this
  2292. ** behavior. The first parameter passed to this operation is an integer -
  2293. ** positive to enable output for trigger programs, or zero to disable it,
  2294. ** or negative to leave the setting unchanged.
  2295. ** The second parameter is a pointer to an integer into which is written
  2296. ** 0 or 1 to indicate whether output-for-triggers has been disabled - 0 if
  2297. ** it is not disabled, 1 if it is.
  2298. ** </dd>
  2299. **
  2300. ** [[SQLITE_DBCONFIG_RESET_DATABASE]] <dt>SQLITE_DBCONFIG_RESET_DATABASE</dt>
  2301. ** <dd> Set the SQLITE_DBCONFIG_RESET_DATABASE flag and then run
  2302. ** [VACUUM] in order to reset a database back to an empty database
  2303. ** with no schema and no content. The following process works even for
  2304. ** a badly corrupted database file:
  2305. ** <ol>
  2306. ** <li> If the database connection is newly opened, make sure it has read the
  2307. ** database schema by preparing then discarding some query against the
  2308. ** database, or calling sqlite3_table_column_metadata(), ignoring any
  2309. ** errors. This step is only necessary if the application desires to keep
  2310. ** the database in WAL mode after the reset if it was in WAL mode before
  2311. ** the reset.
  2312. ** <li> sqlite3_db_config(db, SQLITE_DBCONFIG_RESET_DATABASE, 1, 0);
  2313. ** <li> [sqlite3_exec](db, "[VACUUM]", 0, 0, 0);
  2314. ** <li> sqlite3_db_config(db, SQLITE_DBCONFIG_RESET_DATABASE, 0, 0);
  2315. ** </ol>
  2316. ** Because resetting a database is destructive and irreversible, the
  2317. ** process requires the use of this obscure API and multiple steps to
  2318. ** help ensure that it does not happen by accident. Because this
  2319. ** feature must be capable of resetting corrupt databases, and
  2320. ** shutting down virtual tables may require access to that corrupt
  2321. ** storage, the library must abandon any installed virtual tables
  2322. ** without calling their xDestroy() methods.
  2323. **
  2324. ** [[SQLITE_DBCONFIG_DEFENSIVE]] <dt>SQLITE_DBCONFIG_DEFENSIVE</dt>
  2325. ** <dd>The SQLITE_DBCONFIG_DEFENSIVE option activates or deactivates the
  2326. ** "defensive" flag for a database connection. When the defensive
  2327. ** flag is enabled, language features that allow ordinary SQL to
  2328. ** deliberately corrupt the database file are disabled. The disabled
  2329. ** features include but are not limited to the following:
  2330. ** <ul>
  2331. ** <li> The [PRAGMA writable_schema=ON] statement.
  2332. ** <li> The [PRAGMA journal_mode=OFF] statement.
  2333. ** <li> The [PRAGMA schema_version=N] statement.
  2334. ** <li> Writes to the [sqlite_dbpage] virtual table.
  2335. ** <li> Direct writes to [shadow tables].
  2336. ** </ul>
  2337. ** </dd>
  2338. **
  2339. ** [[SQLITE_DBCONFIG_WRITABLE_SCHEMA]] <dt>SQLITE_DBCONFIG_WRITABLE_SCHEMA</dt>
  2340. ** <dd>The SQLITE_DBCONFIG_WRITABLE_SCHEMA option activates or deactivates the
  2341. ** "writable_schema" flag. This has the same effect and is logically equivalent
  2342. ** to setting [PRAGMA writable_schema=ON] or [PRAGMA writable_schema=OFF].
  2343. ** The first argument to this setting is an integer which is 0 to disable
  2344. ** the writable_schema, positive to enable writable_schema, or negative to
  2345. ** leave the setting unchanged. The second parameter is a pointer to an
  2346. ** integer into which is written 0 or 1 to indicate whether the writable_schema
  2347. ** is enabled or disabled following this call.
  2348. ** </dd>
  2349. **
  2350. ** [[SQLITE_DBCONFIG_LEGACY_ALTER_TABLE]]
  2351. ** <dt>SQLITE_DBCONFIG_LEGACY_ALTER_TABLE</dt>
  2352. ** <dd>The SQLITE_DBCONFIG_LEGACY_ALTER_TABLE option activates or deactivates
  2353. ** the legacy behavior of the [ALTER TABLE RENAME] command such it
  2354. ** behaves as it did prior to [version 3.24.0] (2018-06-04). See the
  2355. ** "Compatibility Notice" on the [ALTER TABLE RENAME documentation] for
  2356. ** additional information. This feature can also be turned on and off
  2357. ** using the [PRAGMA legacy_alter_table] statement.
  2358. ** </dd>
  2359. **
  2360. ** [[SQLITE_DBCONFIG_DQS_DML]]
  2361. ** <dt>SQLITE_DBCONFIG_DQS_DML</dt>
  2362. ** <dd>The SQLITE_DBCONFIG_DQS_DML option activates or deactivates
  2363. ** the legacy [double-quoted string literal] misfeature for DML statements
  2364. ** only, that is DELETE, INSERT, SELECT, and UPDATE statements. The
  2365. ** default value of this setting is determined by the [-DSQLITE_DQS]
  2366. ** compile-time option.
  2367. ** </dd>
  2368. **
  2369. ** [[SQLITE_DBCONFIG_DQS_DDL]]
  2370. ** <dt>SQLITE_DBCONFIG_DQS_DDL</dt>
  2371. ** <dd>The SQLITE_DBCONFIG_DQS option activates or deactivates
  2372. ** the legacy [double-quoted string literal] misfeature for DDL statements,
  2373. ** such as CREATE TABLE and CREATE INDEX. The
  2374. ** default value of this setting is determined by the [-DSQLITE_DQS]
  2375. ** compile-time option.
  2376. ** </dd>
  2377. **
  2378. ** [[SQLITE_DBCONFIG_TRUSTED_SCHEMA]]
  2379. ** <dt>SQLITE_DBCONFIG_TRUSTED_SCHEMA</dt>
  2380. ** <dd>The SQLITE_DBCONFIG_TRUSTED_SCHEMA option tells SQLite to
  2381. ** assume that database schemas are untainted by malicious content.
  2382. ** When the SQLITE_DBCONFIG_TRUSTED_SCHEMA option is disabled, SQLite
  2383. ** takes additional defensive steps to protect the application from harm
  2384. ** including:
  2385. ** <ul>
  2386. ** <li> Prohibit the use of SQL functions inside triggers, views,
  2387. ** CHECK constraints, DEFAULT clauses, expression indexes,
  2388. ** partial indexes, or generated columns
  2389. ** unless those functions are tagged with [SQLITE_INNOCUOUS].
  2390. ** <li> Prohibit the use of virtual tables inside of triggers or views
  2391. ** unless those virtual tables are tagged with [SQLITE_VTAB_INNOCUOUS].
  2392. ** </ul>
  2393. ** This setting defaults to "on" for legacy compatibility, however
  2394. ** all applications are advised to turn it off if possible. This setting
  2395. ** can also be controlled using the [PRAGMA trusted_schema] statement.
  2396. ** </dd>
  2397. **
  2398. ** [[SQLITE_DBCONFIG_LEGACY_FILE_FORMAT]]
  2399. ** <dt>SQLITE_DBCONFIG_LEGACY_FILE_FORMAT</dt>
  2400. ** <dd>The SQLITE_DBCONFIG_LEGACY_FILE_FORMAT option activates or deactivates
  2401. ** the legacy file format flag. When activated, this flag causes all newly
  2402. ** created database file to have a schema format version number (the 4-byte
  2403. ** integer found at offset 44 into the database header) of 1. This in turn
  2404. ** means that the resulting database file will be readable and writable by
  2405. ** any SQLite version back to 3.0.0 ([dateof:3.0.0]). Without this setting,
  2406. ** newly created databases are generally not understandable by SQLite versions
  2407. ** prior to 3.3.0 ([dateof:3.3.0]). As these words are written, there
  2408. ** is now scarcely any need to generate database files that are compatible
  2409. ** all the way back to version 3.0.0, and so this setting is of little
  2410. ** practical use, but is provided so that SQLite can continue to claim the
  2411. ** ability to generate new database files that are compatible with version
  2412. ** 3.0.0.
  2413. ** <p>Note that when the SQLITE_DBCONFIG_LEGACY_FILE_FORMAT setting is on,
  2414. ** the [VACUUM] command will fail with an obscure error when attempting to
  2415. ** process a table with generated columns and a descending index. This is
  2416. ** not considered a bug since SQLite versions 3.3.0 and earlier do not support
  2417. ** either generated columns or descending indexes.
  2418. ** </dd>
  2419. **
  2420. ** [[SQLITE_DBCONFIG_STMT_SCANSTATUS]]
  2421. ** <dt>SQLITE_DBCONFIG_STMT_SCANSTATUS</dt>
  2422. ** <dd>The SQLITE_DBCONFIG_STMT_SCANSTATUS option is only useful in
  2423. ** SQLITE_ENABLE_STMT_SCANSTATUS builds. In this case, it sets or clears
  2424. ** a flag that enables collection of the sqlite3_stmt_scanstatus_v2()
  2425. ** statistics. For statistics to be collected, the flag must be set on
  2426. ** the database handle both when the SQL statement is prepared and when it
  2427. ** is stepped. The flag is set (collection of statistics is enabled)
  2428. ** by default. This option takes two arguments: an integer and a pointer to
  2429. ** an integer.. The first argument is 1, 0, or -1 to enable, disable, or
  2430. ** leave unchanged the statement scanstatus option. If the second argument
  2431. ** is not NULL, then the value of the statement scanstatus setting after
  2432. ** processing the first argument is written into the integer that the second
  2433. ** argument points to.
  2434. ** </dd>
  2435. **
  2436. ** [[SQLITE_DBCONFIG_REVERSE_SCANORDER]]
  2437. ** <dt>SQLITE_DBCONFIG_REVERSE_SCANORDER</dt>
  2438. ** <dd>The SQLITE_DBCONFIG_REVERSE_SCANORDER option changes the default order
  2439. ** in which tables and indexes are scanned so that the scans start at the end
  2440. ** and work toward the beginning rather than starting at the beginning and
  2441. ** working toward the end. Setting SQLITE_DBCONFIG_REVERSE_SCANORDER is the
  2442. ** same as setting [PRAGMA reverse_unordered_selects]. This option takes
  2443. ** two arguments which are an integer and a pointer to an integer. The first
  2444. ** argument is 1, 0, or -1 to enable, disable, or leave unchanged the
  2445. ** reverse scan order flag, respectively. If the second argument is not NULL,
  2446. ** then 0 or 1 is written into the integer that the second argument points to
  2447. ** depending on if the reverse scan order flag is set after processing the
  2448. ** first argument.
  2449. ** </dd>
  2450. **
  2451. ** </dl>
  2452. */
  2453. #define SQLITE_DBCONFIG_MAINDBNAME 1000 /* const char* */
  2454. #define SQLITE_DBCONFIG_LOOKASIDE 1001 /* void* int int */
  2455. #define SQLITE_DBCONFIG_ENABLE_FKEY 1002 /* int int* */
  2456. #define SQLITE_DBCONFIG_ENABLE_TRIGGER 1003 /* int int* */
  2457. #define SQLITE_DBCONFIG_ENABLE_FTS3_TOKENIZER 1004 /* int int* */
  2458. #define SQLITE_DBCONFIG_ENABLE_LOAD_EXTENSION 1005 /* int int* */
  2459. #define SQLITE_DBCONFIG_NO_CKPT_ON_CLOSE 1006 /* int int* */
  2460. #define SQLITE_DBCONFIG_ENABLE_QPSG 1007 /* int int* */
  2461. #define SQLITE_DBCONFIG_TRIGGER_EQP 1008 /* int int* */
  2462. #define SQLITE_DBCONFIG_RESET_DATABASE 1009 /* int int* */
  2463. #define SQLITE_DBCONFIG_DEFENSIVE 1010 /* int int* */
  2464. #define SQLITE_DBCONFIG_WRITABLE_SCHEMA 1011 /* int int* */
  2465. #define SQLITE_DBCONFIG_LEGACY_ALTER_TABLE 1012 /* int int* */
  2466. #define SQLITE_DBCONFIG_DQS_DML 1013 /* int int* */
  2467. #define SQLITE_DBCONFIG_DQS_DDL 1014 /* int int* */
  2468. #define SQLITE_DBCONFIG_ENABLE_VIEW 1015 /* int int* */
  2469. #define SQLITE_DBCONFIG_LEGACY_FILE_FORMAT 1016 /* int int* */
  2470. #define SQLITE_DBCONFIG_TRUSTED_SCHEMA 1017 /* int int* */
  2471. #define SQLITE_DBCONFIG_STMT_SCANSTATUS 1018 /* int int* */
  2472. #define SQLITE_DBCONFIG_REVERSE_SCANORDER 1019 /* int int* */
  2473. #define SQLITE_DBCONFIG_MAX 1019 /* Largest DBCONFIG */
  2474. /*
  2475. ** CAPI3REF: Enable Or Disable Extended Result Codes
  2476. ** METHOD: sqlite3
  2477. **
  2478. ** ^The sqlite3_extended_result_codes() routine enables or disables the
  2479. ** [extended result codes] feature of SQLite. ^The extended result
  2480. ** codes are disabled by default for historical compatibility.
  2481. */
  2482. SQLITE_API int sqlite3_extended_result_codes(sqlite3*, int onoff);
  2483. /*
  2484. ** CAPI3REF: Last Insert Rowid
  2485. ** METHOD: sqlite3
  2486. **
  2487. ** ^Each entry in most SQLite tables (except for [WITHOUT ROWID] tables)
  2488. ** has a unique 64-bit signed
  2489. ** integer key called the [ROWID | "rowid"]. ^The rowid is always available
  2490. ** as an undeclared column named ROWID, OID, or _ROWID_ as long as those
  2491. ** names are not also used by explicitly declared columns. ^If
  2492. ** the table has a column of type [INTEGER PRIMARY KEY] then that column
  2493. ** is another alias for the rowid.
  2494. **
  2495. ** ^The sqlite3_last_insert_rowid(D) interface usually returns the [rowid] of
  2496. ** the most recent successful [INSERT] into a rowid table or [virtual table]
  2497. ** on database connection D. ^Inserts into [WITHOUT ROWID] tables are not
  2498. ** recorded. ^If no successful [INSERT]s into rowid tables have ever occurred
  2499. ** on the database connection D, then sqlite3_last_insert_rowid(D) returns
  2500. ** zero.
  2501. **
  2502. ** As well as being set automatically as rows are inserted into database
  2503. ** tables, the value returned by this function may be set explicitly by
  2504. ** [sqlite3_set_last_insert_rowid()]
  2505. **
  2506. ** Some virtual table implementations may INSERT rows into rowid tables as
  2507. ** part of committing a transaction (e.g. to flush data accumulated in memory
  2508. ** to disk). In this case subsequent calls to this function return the rowid
  2509. ** associated with these internal INSERT operations, which leads to
  2510. ** unintuitive results. Virtual table implementations that do write to rowid
  2511. ** tables in this way can avoid this problem by restoring the original
  2512. ** rowid value using [sqlite3_set_last_insert_rowid()] before returning
  2513. ** control to the user.
  2514. **
  2515. ** ^(If an [INSERT] occurs within a trigger then this routine will
  2516. ** return the [rowid] of the inserted row as long as the trigger is
  2517. ** running. Once the trigger program ends, the value returned
  2518. ** by this routine reverts to what it was before the trigger was fired.)^
  2519. **
  2520. ** ^An [INSERT] that fails due to a constraint violation is not a
  2521. ** successful [INSERT] and does not change the value returned by this
  2522. ** routine. ^Thus INSERT OR FAIL, INSERT OR IGNORE, INSERT OR ROLLBACK,
  2523. ** and INSERT OR ABORT make no changes to the return value of this
  2524. ** routine when their insertion fails. ^(When INSERT OR REPLACE
  2525. ** encounters a constraint violation, it does not fail. The
  2526. ** INSERT continues to completion after deleting rows that caused
  2527. ** the constraint problem so INSERT OR REPLACE will always change
  2528. ** the return value of this interface.)^
  2529. **
  2530. ** ^For the purposes of this routine, an [INSERT] is considered to
  2531. ** be successful even if it is subsequently rolled back.
  2532. **
  2533. ** This function is accessible to SQL statements via the
  2534. ** [last_insert_rowid() SQL function].
  2535. **
  2536. ** If a separate thread performs a new [INSERT] on the same
  2537. ** database connection while the [sqlite3_last_insert_rowid()]
  2538. ** function is running and thus changes the last insert [rowid],
  2539. ** then the value returned by [sqlite3_last_insert_rowid()] is
  2540. ** unpredictable and might not equal either the old or the new
  2541. ** last insert [rowid].
  2542. */
  2543. SQLITE_API sqlite3_int64 sqlite3_last_insert_rowid(sqlite3*);
  2544. /*
  2545. ** CAPI3REF: Set the Last Insert Rowid value.
  2546. ** METHOD: sqlite3
  2547. **
  2548. ** The sqlite3_set_last_insert_rowid(D, R) method allows the application to
  2549. ** set the value returned by calling sqlite3_last_insert_rowid(D) to R
  2550. ** without inserting a row into the database.
  2551. */
  2552. SQLITE_API void sqlite3_set_last_insert_rowid(sqlite3*,sqlite3_int64);
  2553. /*
  2554. ** CAPI3REF: Count The Number Of Rows Modified
  2555. ** METHOD: sqlite3
  2556. **
  2557. ** ^These functions return the number of rows modified, inserted or
  2558. ** deleted by the most recently completed INSERT, UPDATE or DELETE
  2559. ** statement on the database connection specified by the only parameter.
  2560. ** The two functions are identical except for the type of the return value
  2561. ** and that if the number of rows modified by the most recent INSERT, UPDATE
  2562. ** or DELETE is greater than the maximum value supported by type "int", then
  2563. ** the return value of sqlite3_changes() is undefined. ^Executing any other
  2564. ** type of SQL statement does not modify the value returned by these functions.
  2565. **
  2566. ** ^Only changes made directly by the INSERT, UPDATE or DELETE statement are
  2567. ** considered - auxiliary changes caused by [CREATE TRIGGER | triggers],
  2568. ** [foreign key actions] or [REPLACE] constraint resolution are not counted.
  2569. **
  2570. ** Changes to a view that are intercepted by
  2571. ** [INSTEAD OF trigger | INSTEAD OF triggers] are not counted. ^The value
  2572. ** returned by sqlite3_changes() immediately after an INSERT, UPDATE or
  2573. ** DELETE statement run on a view is always zero. Only changes made to real
  2574. ** tables are counted.
  2575. **
  2576. ** Things are more complicated if the sqlite3_changes() function is
  2577. ** executed while a trigger program is running. This may happen if the
  2578. ** program uses the [changes() SQL function], or if some other callback
  2579. ** function invokes sqlite3_changes() directly. Essentially:
  2580. **
  2581. ** <ul>
  2582. ** <li> ^(Before entering a trigger program the value returned by
  2583. ** sqlite3_changes() function is saved. After the trigger program
  2584. ** has finished, the original value is restored.)^
  2585. **
  2586. ** <li> ^(Within a trigger program each INSERT, UPDATE and DELETE
  2587. ** statement sets the value returned by sqlite3_changes()
  2588. ** upon completion as normal. Of course, this value will not include
  2589. ** any changes performed by sub-triggers, as the sqlite3_changes()
  2590. ** value will be saved and restored after each sub-trigger has run.)^
  2591. ** </ul>
  2592. **
  2593. ** ^This means that if the changes() SQL function (or similar) is used
  2594. ** by the first INSERT, UPDATE or DELETE statement within a trigger, it
  2595. ** returns the value as set when the calling statement began executing.
  2596. ** ^If it is used by the second or subsequent such statement within a trigger
  2597. ** program, the value returned reflects the number of rows modified by the
  2598. ** previous INSERT, UPDATE or DELETE statement within the same trigger.
  2599. **
  2600. ** If a separate thread makes changes on the same database connection
  2601. ** while [sqlite3_changes()] is running then the value returned
  2602. ** is unpredictable and not meaningful.
  2603. **
  2604. ** See also:
  2605. ** <ul>
  2606. ** <li> the [sqlite3_total_changes()] interface
  2607. ** <li> the [count_changes pragma]
  2608. ** <li> the [changes() SQL function]
  2609. ** <li> the [data_version pragma]
  2610. ** </ul>
  2611. */
  2612. SQLITE_API int sqlite3_changes(sqlite3*);
  2613. SQLITE_API sqlite3_int64 sqlite3_changes64(sqlite3*);
  2614. /*
  2615. ** CAPI3REF: Total Number Of Rows Modified
  2616. ** METHOD: sqlite3
  2617. **
  2618. ** ^These functions return the total number of rows inserted, modified or
  2619. ** deleted by all [INSERT], [UPDATE] or [DELETE] statements completed
  2620. ** since the database connection was opened, including those executed as
  2621. ** part of trigger programs. The two functions are identical except for the
  2622. ** type of the return value and that if the number of rows modified by the
  2623. ** connection exceeds the maximum value supported by type "int", then
  2624. ** the return value of sqlite3_total_changes() is undefined. ^Executing
  2625. ** any other type of SQL statement does not affect the value returned by
  2626. ** sqlite3_total_changes().
  2627. **
  2628. ** ^Changes made as part of [foreign key actions] are included in the
  2629. ** count, but those made as part of REPLACE constraint resolution are
  2630. ** not. ^Changes to a view that are intercepted by INSTEAD OF triggers
  2631. ** are not counted.
  2632. **
  2633. ** The [sqlite3_total_changes(D)] interface only reports the number
  2634. ** of rows that changed due to SQL statement run against database
  2635. ** connection D. Any changes by other database connections are ignored.
  2636. ** To detect changes against a database file from other database
  2637. ** connections use the [PRAGMA data_version] command or the
  2638. ** [SQLITE_FCNTL_DATA_VERSION] [file control].
  2639. **
  2640. ** If a separate thread makes changes on the same database connection
  2641. ** while [sqlite3_total_changes()] is running then the value
  2642. ** returned is unpredictable and not meaningful.
  2643. **
  2644. ** See also:
  2645. ** <ul>
  2646. ** <li> the [sqlite3_changes()] interface
  2647. ** <li> the [count_changes pragma]
  2648. ** <li> the [changes() SQL function]
  2649. ** <li> the [data_version pragma]
  2650. ** <li> the [SQLITE_FCNTL_DATA_VERSION] [file control]
  2651. ** </ul>
  2652. */
  2653. SQLITE_API int sqlite3_total_changes(sqlite3*);
  2654. SQLITE_API sqlite3_int64 sqlite3_total_changes64(sqlite3*);
  2655. /*
  2656. ** CAPI3REF: Interrupt A Long-Running Query
  2657. ** METHOD: sqlite3
  2658. **
  2659. ** ^This function causes any pending database operation to abort and
  2660. ** return at its earliest opportunity. This routine is typically
  2661. ** called in response to a user action such as pressing "Cancel"
  2662. ** or Ctrl-C where the user wants a long query operation to halt
  2663. ** immediately.
  2664. **
  2665. ** ^It is safe to call this routine from a thread different from the
  2666. ** thread that is currently running the database operation. But it
  2667. ** is not safe to call this routine with a [database connection] that
  2668. ** is closed or might close before sqlite3_interrupt() returns.
  2669. **
  2670. ** ^If an SQL operation is very nearly finished at the time when
  2671. ** sqlite3_interrupt() is called, then it might not have an opportunity
  2672. ** to be interrupted and might continue to completion.
  2673. **
  2674. ** ^An SQL operation that is interrupted will return [SQLITE_INTERRUPT].
  2675. ** ^If the interrupted SQL operation is an INSERT, UPDATE, or DELETE
  2676. ** that is inside an explicit transaction, then the entire transaction
  2677. ** will be rolled back automatically.
  2678. **
  2679. ** ^The sqlite3_interrupt(D) call is in effect until all currently running
  2680. ** SQL statements on [database connection] D complete. ^Any new SQL statements
  2681. ** that are started after the sqlite3_interrupt() call and before the
  2682. ** running statement count reaches zero are interrupted as if they had been
  2683. ** running prior to the sqlite3_interrupt() call. ^New SQL statements
  2684. ** that are started after the running statement count reaches zero are
  2685. ** not effected by the sqlite3_interrupt().
  2686. ** ^A call to sqlite3_interrupt(D) that occurs when there are no running
  2687. ** SQL statements is a no-op and has no effect on SQL statements
  2688. ** that are started after the sqlite3_interrupt() call returns.
  2689. **
  2690. ** ^The [sqlite3_is_interrupted(D)] interface can be used to determine whether
  2691. ** or not an interrupt is currently in effect for [database connection] D.
  2692. ** It returns 1 if an interrupt is currently in effect, or 0 otherwise.
  2693. */
  2694. SQLITE_API void sqlite3_interrupt(sqlite3*);
  2695. SQLITE_API int sqlite3_is_interrupted(sqlite3*);
  2696. /*
  2697. ** CAPI3REF: Determine If An SQL Statement Is Complete
  2698. **
  2699. ** These routines are useful during command-line input to determine if the
  2700. ** currently entered text seems to form a complete SQL statement or
  2701. ** if additional input is needed before sending the text into
  2702. ** SQLite for parsing. ^These routines return 1 if the input string
  2703. ** appears to be a complete SQL statement. ^A statement is judged to be
  2704. ** complete if it ends with a semicolon token and is not a prefix of a
  2705. ** well-formed CREATE TRIGGER statement. ^Semicolons that are embedded within
  2706. ** string literals or quoted identifier names or comments are not
  2707. ** independent tokens (they are part of the token in which they are
  2708. ** embedded) and thus do not count as a statement terminator. ^Whitespace
  2709. ** and comments that follow the final semicolon are ignored.
  2710. **
  2711. ** ^These routines return 0 if the statement is incomplete. ^If a
  2712. ** memory allocation fails, then SQLITE_NOMEM is returned.
  2713. **
  2714. ** ^These routines do not parse the SQL statements thus
  2715. ** will not detect syntactically incorrect SQL.
  2716. **
  2717. ** ^(If SQLite has not been initialized using [sqlite3_initialize()] prior
  2718. ** to invoking sqlite3_complete16() then sqlite3_initialize() is invoked
  2719. ** automatically by sqlite3_complete16(). If that initialization fails,
  2720. ** then the return value from sqlite3_complete16() will be non-zero
  2721. ** regardless of whether or not the input SQL is complete.)^
  2722. **
  2723. ** The input to [sqlite3_complete()] must be a zero-terminated
  2724. ** UTF-8 string.
  2725. **
  2726. ** The input to [sqlite3_complete16()] must be a zero-terminated
  2727. ** UTF-16 string in native byte order.
  2728. */
  2729. SQLITE_API int sqlite3_complete(const char *sql);
  2730. SQLITE_API int sqlite3_complete16(const void *sql);
  2731. /*
  2732. ** CAPI3REF: Register A Callback To Handle SQLITE_BUSY Errors
  2733. ** KEYWORDS: {busy-handler callback} {busy handler}
  2734. ** METHOD: sqlite3
  2735. **
  2736. ** ^The sqlite3_busy_handler(D,X,P) routine sets a callback function X
  2737. ** that might be invoked with argument P whenever
  2738. ** an attempt is made to access a database table associated with
  2739. ** [database connection] D when another thread
  2740. ** or process has the table locked.
  2741. ** The sqlite3_busy_handler() interface is used to implement
  2742. ** [sqlite3_busy_timeout()] and [PRAGMA busy_timeout].
  2743. **
  2744. ** ^If the busy callback is NULL, then [SQLITE_BUSY]
  2745. ** is returned immediately upon encountering the lock. ^If the busy callback
  2746. ** is not NULL, then the callback might be invoked with two arguments.
  2747. **
  2748. ** ^The first argument to the busy handler is a copy of the void* pointer which
  2749. ** is the third argument to sqlite3_busy_handler(). ^The second argument to
  2750. ** the busy handler callback is the number of times that the busy handler has
  2751. ** been invoked previously for the same locking event. ^If the
  2752. ** busy callback returns 0, then no additional attempts are made to
  2753. ** access the database and [SQLITE_BUSY] is returned
  2754. ** to the application.
  2755. ** ^If the callback returns non-zero, then another attempt
  2756. ** is made to access the database and the cycle repeats.
  2757. **
  2758. ** The presence of a busy handler does not guarantee that it will be invoked
  2759. ** when there is lock contention. ^If SQLite determines that invoking the busy
  2760. ** handler could result in a deadlock, it will go ahead and return [SQLITE_BUSY]
  2761. ** to the application instead of invoking the
  2762. ** busy handler.
  2763. ** Consider a scenario where one process is holding a read lock that
  2764. ** it is trying to promote to a reserved lock and
  2765. ** a second process is holding a reserved lock that it is trying
  2766. ** to promote to an exclusive lock. The first process cannot proceed
  2767. ** because it is blocked by the second and the second process cannot
  2768. ** proceed because it is blocked by the first. If both processes
  2769. ** invoke the busy handlers, neither will make any progress. Therefore,
  2770. ** SQLite returns [SQLITE_BUSY] for the first process, hoping that this
  2771. ** will induce the first process to release its read lock and allow
  2772. ** the second process to proceed.
  2773. **
  2774. ** ^The default busy callback is NULL.
  2775. **
  2776. ** ^(There can only be a single busy handler defined for each
  2777. ** [database connection]. Setting a new busy handler clears any
  2778. ** previously set handler.)^ ^Note that calling [sqlite3_busy_timeout()]
  2779. ** or evaluating [PRAGMA busy_timeout=N] will change the
  2780. ** busy handler and thus clear any previously set busy handler.
  2781. **
  2782. ** The busy callback should not take any actions which modify the
  2783. ** database connection that invoked the busy handler. In other words,
  2784. ** the busy handler is not reentrant. Any such actions
  2785. ** result in undefined behavior.
  2786. **
  2787. ** A busy handler must not close the database connection
  2788. ** or [prepared statement] that invoked the busy handler.
  2789. */
  2790. SQLITE_API int sqlite3_busy_handler(sqlite3*,int(*)(void*,int),void*);
  2791. /*
  2792. ** CAPI3REF: Set A Busy Timeout
  2793. ** METHOD: sqlite3
  2794. **
  2795. ** ^This routine sets a [sqlite3_busy_handler | busy handler] that sleeps
  2796. ** for a specified amount of time when a table is locked. ^The handler
  2797. ** will sleep multiple times until at least "ms" milliseconds of sleeping
  2798. ** have accumulated. ^After at least "ms" milliseconds of sleeping,
  2799. ** the handler returns 0 which causes [sqlite3_step()] to return
  2800. ** [SQLITE_BUSY].
  2801. **
  2802. ** ^Calling this routine with an argument less than or equal to zero
  2803. ** turns off all busy handlers.
  2804. **
  2805. ** ^(There can only be a single busy handler for a particular
  2806. ** [database connection] at any given moment. If another busy handler
  2807. ** was defined (using [sqlite3_busy_handler()]) prior to calling
  2808. ** this routine, that other busy handler is cleared.)^
  2809. **
  2810. ** See also: [PRAGMA busy_timeout]
  2811. */
  2812. SQLITE_API int sqlite3_busy_timeout(sqlite3*, int ms);
  2813. /*
  2814. ** CAPI3REF: Convenience Routines For Running Queries
  2815. ** METHOD: sqlite3
  2816. **
  2817. ** This is a legacy interface that is preserved for backwards compatibility.
  2818. ** Use of this interface is not recommended.
  2819. **
  2820. ** Definition: A <b>result table</b> is memory data structure created by the
  2821. ** [sqlite3_get_table()] interface. A result table records the
  2822. ** complete query results from one or more queries.
  2823. **
  2824. ** The table conceptually has a number of rows and columns. But
  2825. ** these numbers are not part of the result table itself. These
  2826. ** numbers are obtained separately. Let N be the number of rows
  2827. ** and M be the number of columns.
  2828. **
  2829. ** A result table is an array of pointers to zero-terminated UTF-8 strings.
  2830. ** There are (N+1)*M elements in the array. The first M pointers point
  2831. ** to zero-terminated strings that contain the names of the columns.
  2832. ** The remaining entries all point to query results. NULL values result
  2833. ** in NULL pointers. All other values are in their UTF-8 zero-terminated
  2834. ** string representation as returned by [sqlite3_column_text()].
  2835. **
  2836. ** A result table might consist of one or more memory allocations.
  2837. ** It is not safe to pass a result table directly to [sqlite3_free()].
  2838. ** A result table should be deallocated using [sqlite3_free_table()].
  2839. **
  2840. ** ^(As an example of the result table format, suppose a query result
  2841. ** is as follows:
  2842. **
  2843. ** <blockquote><pre>
  2844. ** Name | Age
  2845. ** -----------------------
  2846. ** Alice | 43
  2847. ** Bob | 28
  2848. ** Cindy | 21
  2849. ** </pre></blockquote>
  2850. **
  2851. ** There are two columns (M==2) and three rows (N==3). Thus the
  2852. ** result table has 8 entries. Suppose the result table is stored
  2853. ** in an array named azResult. Then azResult holds this content:
  2854. **
  2855. ** <blockquote><pre>
  2856. ** azResult&#91;0] = "Name";
  2857. ** azResult&#91;1] = "Age";
  2858. ** azResult&#91;2] = "Alice";
  2859. ** azResult&#91;3] = "43";
  2860. ** azResult&#91;4] = "Bob";
  2861. ** azResult&#91;5] = "28";
  2862. ** azResult&#91;6] = "Cindy";
  2863. ** azResult&#91;7] = "21";
  2864. ** </pre></blockquote>)^
  2865. **
  2866. ** ^The sqlite3_get_table() function evaluates one or more
  2867. ** semicolon-separated SQL statements in the zero-terminated UTF-8
  2868. ** string of its 2nd parameter and returns a result table to the
  2869. ** pointer given in its 3rd parameter.
  2870. **
  2871. ** After the application has finished with the result from sqlite3_get_table(),
  2872. ** it must pass the result table pointer to sqlite3_free_table() in order to
  2873. ** release the memory that was malloced. Because of the way the
  2874. ** [sqlite3_malloc()] happens within sqlite3_get_table(), the calling
  2875. ** function must not try to call [sqlite3_free()] directly. Only
  2876. ** [sqlite3_free_table()] is able to release the memory properly and safely.
  2877. **
  2878. ** The sqlite3_get_table() interface is implemented as a wrapper around
  2879. ** [sqlite3_exec()]. The sqlite3_get_table() routine does not have access
  2880. ** to any internal data structures of SQLite. It uses only the public
  2881. ** interface defined here. As a consequence, errors that occur in the
  2882. ** wrapper layer outside of the internal [sqlite3_exec()] call are not
  2883. ** reflected in subsequent calls to [sqlite3_errcode()] or
  2884. ** [sqlite3_errmsg()].
  2885. */
  2886. SQLITE_API int sqlite3_get_table(
  2887. sqlite3 *db, /* An open database */
  2888. const char *zSql, /* SQL to be evaluated */
  2889. char ***pazResult, /* Results of the query */
  2890. int *pnRow, /* Number of result rows written here */
  2891. int *pnColumn, /* Number of result columns written here */
  2892. char **pzErrmsg /* Error msg written here */
  2893. );
  2894. SQLITE_API void sqlite3_free_table(char **result);
  2895. /*
  2896. ** CAPI3REF: Formatted String Printing Functions
  2897. **
  2898. ** These routines are work-alikes of the "printf()" family of functions
  2899. ** from the standard C library.
  2900. ** These routines understand most of the common formatting options from
  2901. ** the standard library printf()
  2902. ** plus some additional non-standard formats ([%q], [%Q], [%w], and [%z]).
  2903. ** See the [built-in printf()] documentation for details.
  2904. **
  2905. ** ^The sqlite3_mprintf() and sqlite3_vmprintf() routines write their
  2906. ** results into memory obtained from [sqlite3_malloc64()].
  2907. ** The strings returned by these two routines should be
  2908. ** released by [sqlite3_free()]. ^Both routines return a
  2909. ** NULL pointer if [sqlite3_malloc64()] is unable to allocate enough
  2910. ** memory to hold the resulting string.
  2911. **
  2912. ** ^(The sqlite3_snprintf() routine is similar to "snprintf()" from
  2913. ** the standard C library. The result is written into the
  2914. ** buffer supplied as the second parameter whose size is given by
  2915. ** the first parameter. Note that the order of the
  2916. ** first two parameters is reversed from snprintf().)^ This is an
  2917. ** historical accident that cannot be fixed without breaking
  2918. ** backwards compatibility. ^(Note also that sqlite3_snprintf()
  2919. ** returns a pointer to its buffer instead of the number of
  2920. ** characters actually written into the buffer.)^ We admit that
  2921. ** the number of characters written would be a more useful return
  2922. ** value but we cannot change the implementation of sqlite3_snprintf()
  2923. ** now without breaking compatibility.
  2924. **
  2925. ** ^As long as the buffer size is greater than zero, sqlite3_snprintf()
  2926. ** guarantees that the buffer is always zero-terminated. ^The first
  2927. ** parameter "n" is the total size of the buffer, including space for
  2928. ** the zero terminator. So the longest string that can be completely
  2929. ** written will be n-1 characters.
  2930. **
  2931. ** ^The sqlite3_vsnprintf() routine is a varargs version of sqlite3_snprintf().
  2932. **
  2933. ** See also: [built-in printf()], [printf() SQL function]
  2934. */
  2935. SQLITE_API char *sqlite3_mprintf(const char*,...);
  2936. SQLITE_API char *sqlite3_vmprintf(const char*, va_list);
  2937. SQLITE_API char *sqlite3_snprintf(int,char*,const char*, ...);
  2938. SQLITE_API char *sqlite3_vsnprintf(int,char*,const char*, va_list);
  2939. /*
  2940. ** CAPI3REF: Memory Allocation Subsystem
  2941. **
  2942. ** The SQLite core uses these three routines for all of its own
  2943. ** internal memory allocation needs. "Core" in the previous sentence
  2944. ** does not include operating-system specific [VFS] implementation. The
  2945. ** Windows VFS uses native malloc() and free() for some operations.
  2946. **
  2947. ** ^The sqlite3_malloc() routine returns a pointer to a block
  2948. ** of memory at least N bytes in length, where N is the parameter.
  2949. ** ^If sqlite3_malloc() is unable to obtain sufficient free
  2950. ** memory, it returns a NULL pointer. ^If the parameter N to
  2951. ** sqlite3_malloc() is zero or negative then sqlite3_malloc() returns
  2952. ** a NULL pointer.
  2953. **
  2954. ** ^The sqlite3_malloc64(N) routine works just like
  2955. ** sqlite3_malloc(N) except that N is an unsigned 64-bit integer instead
  2956. ** of a signed 32-bit integer.
  2957. **
  2958. ** ^Calling sqlite3_free() with a pointer previously returned
  2959. ** by sqlite3_malloc() or sqlite3_realloc() releases that memory so
  2960. ** that it might be reused. ^The sqlite3_free() routine is
  2961. ** a no-op if is called with a NULL pointer. Passing a NULL pointer
  2962. ** to sqlite3_free() is harmless. After being freed, memory
  2963. ** should neither be read nor written. Even reading previously freed
  2964. ** memory might result in a segmentation fault or other severe error.
  2965. ** Memory corruption, a segmentation fault, or other severe error
  2966. ** might result if sqlite3_free() is called with a non-NULL pointer that
  2967. ** was not obtained from sqlite3_malloc() or sqlite3_realloc().
  2968. **
  2969. ** ^The sqlite3_realloc(X,N) interface attempts to resize a
  2970. ** prior memory allocation X to be at least N bytes.
  2971. ** ^If the X parameter to sqlite3_realloc(X,N)
  2972. ** is a NULL pointer then its behavior is identical to calling
  2973. ** sqlite3_malloc(N).
  2974. ** ^If the N parameter to sqlite3_realloc(X,N) is zero or
  2975. ** negative then the behavior is exactly the same as calling
  2976. ** sqlite3_free(X).
  2977. ** ^sqlite3_realloc(X,N) returns a pointer to a memory allocation
  2978. ** of at least N bytes in size or NULL if insufficient memory is available.
  2979. ** ^If M is the size of the prior allocation, then min(N,M) bytes
  2980. ** of the prior allocation are copied into the beginning of buffer returned
  2981. ** by sqlite3_realloc(X,N) and the prior allocation is freed.
  2982. ** ^If sqlite3_realloc(X,N) returns NULL and N is positive, then the
  2983. ** prior allocation is not freed.
  2984. **
  2985. ** ^The sqlite3_realloc64(X,N) interfaces works the same as
  2986. ** sqlite3_realloc(X,N) except that N is a 64-bit unsigned integer instead
  2987. ** of a 32-bit signed integer.
  2988. **
  2989. ** ^If X is a memory allocation previously obtained from sqlite3_malloc(),
  2990. ** sqlite3_malloc64(), sqlite3_realloc(), or sqlite3_realloc64(), then
  2991. ** sqlite3_msize(X) returns the size of that memory allocation in bytes.
  2992. ** ^The value returned by sqlite3_msize(X) might be larger than the number
  2993. ** of bytes requested when X was allocated. ^If X is a NULL pointer then
  2994. ** sqlite3_msize(X) returns zero. If X points to something that is not
  2995. ** the beginning of memory allocation, or if it points to a formerly
  2996. ** valid memory allocation that has now been freed, then the behavior
  2997. ** of sqlite3_msize(X) is undefined and possibly harmful.
  2998. **
  2999. ** ^The memory returned by sqlite3_malloc(), sqlite3_realloc(),
  3000. ** sqlite3_malloc64(), and sqlite3_realloc64()
  3001. ** is always aligned to at least an 8 byte boundary, or to a
  3002. ** 4 byte boundary if the [SQLITE_4_BYTE_ALIGNED_MALLOC] compile-time
  3003. ** option is used.
  3004. **
  3005. ** The pointer arguments to [sqlite3_free()] and [sqlite3_realloc()]
  3006. ** must be either NULL or else pointers obtained from a prior
  3007. ** invocation of [sqlite3_malloc()] or [sqlite3_realloc()] that have
  3008. ** not yet been released.
  3009. **
  3010. ** The application must not read or write any part of
  3011. ** a block of memory after it has been released using
  3012. ** [sqlite3_free()] or [sqlite3_realloc()].
  3013. */
  3014. SQLITE_API void *sqlite3_malloc(int);
  3015. SQLITE_API void *sqlite3_malloc64(sqlite3_uint64);
  3016. SQLITE_API void *sqlite3_realloc(void*, int);
  3017. SQLITE_API void *sqlite3_realloc64(void*, sqlite3_uint64);
  3018. SQLITE_API void sqlite3_free(void*);
  3019. SQLITE_API sqlite3_uint64 sqlite3_msize(void*);
  3020. /*
  3021. ** CAPI3REF: Memory Allocator Statistics
  3022. **
  3023. ** SQLite provides these two interfaces for reporting on the status
  3024. ** of the [sqlite3_malloc()], [sqlite3_free()], and [sqlite3_realloc()]
  3025. ** routines, which form the built-in memory allocation subsystem.
  3026. **
  3027. ** ^The [sqlite3_memory_used()] routine returns the number of bytes
  3028. ** of memory currently outstanding (malloced but not freed).
  3029. ** ^The [sqlite3_memory_highwater()] routine returns the maximum
  3030. ** value of [sqlite3_memory_used()] since the high-water mark
  3031. ** was last reset. ^The values returned by [sqlite3_memory_used()] and
  3032. ** [sqlite3_memory_highwater()] include any overhead
  3033. ** added by SQLite in its implementation of [sqlite3_malloc()],
  3034. ** but not overhead added by the any underlying system library
  3035. ** routines that [sqlite3_malloc()] may call.
  3036. **
  3037. ** ^The memory high-water mark is reset to the current value of
  3038. ** [sqlite3_memory_used()] if and only if the parameter to
  3039. ** [sqlite3_memory_highwater()] is true. ^The value returned
  3040. ** by [sqlite3_memory_highwater(1)] is the high-water mark
  3041. ** prior to the reset.
  3042. */
  3043. SQLITE_API sqlite3_int64 sqlite3_memory_used(void);
  3044. SQLITE_API sqlite3_int64 sqlite3_memory_highwater(int resetFlag);
  3045. /*
  3046. ** CAPI3REF: Pseudo-Random Number Generator
  3047. **
  3048. ** SQLite contains a high-quality pseudo-random number generator (PRNG) used to
  3049. ** select random [ROWID | ROWIDs] when inserting new records into a table that
  3050. ** already uses the largest possible [ROWID]. The PRNG is also used for
  3051. ** the built-in random() and randomblob() SQL functions. This interface allows
  3052. ** applications to access the same PRNG for other purposes.
  3053. **
  3054. ** ^A call to this routine stores N bytes of randomness into buffer P.
  3055. ** ^The P parameter can be a NULL pointer.
  3056. **
  3057. ** ^If this routine has not been previously called or if the previous
  3058. ** call had N less than one or a NULL pointer for P, then the PRNG is
  3059. ** seeded using randomness obtained from the xRandomness method of
  3060. ** the default [sqlite3_vfs] object.
  3061. ** ^If the previous call to this routine had an N of 1 or more and a
  3062. ** non-NULL P then the pseudo-randomness is generated
  3063. ** internally and without recourse to the [sqlite3_vfs] xRandomness
  3064. ** method.
  3065. */
  3066. SQLITE_API void sqlite3_randomness(int N, void *P);
  3067. /*
  3068. ** CAPI3REF: Compile-Time Authorization Callbacks
  3069. ** METHOD: sqlite3
  3070. ** KEYWORDS: {authorizer callback}
  3071. **
  3072. ** ^This routine registers an authorizer callback with a particular
  3073. ** [database connection], supplied in the first argument.
  3074. ** ^The authorizer callback is invoked as SQL statements are being compiled
  3075. ** by [sqlite3_prepare()] or its variants [sqlite3_prepare_v2()],
  3076. ** [sqlite3_prepare_v3()], [sqlite3_prepare16()], [sqlite3_prepare16_v2()],
  3077. ** and [sqlite3_prepare16_v3()]. ^At various
  3078. ** points during the compilation process, as logic is being created
  3079. ** to perform various actions, the authorizer callback is invoked to
  3080. ** see if those actions are allowed. ^The authorizer callback should
  3081. ** return [SQLITE_OK] to allow the action, [SQLITE_IGNORE] to disallow the
  3082. ** specific action but allow the SQL statement to continue to be
  3083. ** compiled, or [SQLITE_DENY] to cause the entire SQL statement to be
  3084. ** rejected with an error. ^If the authorizer callback returns
  3085. ** any value other than [SQLITE_IGNORE], [SQLITE_OK], or [SQLITE_DENY]
  3086. ** then the [sqlite3_prepare_v2()] or equivalent call that triggered
  3087. ** the authorizer will fail with an error message.
  3088. **
  3089. ** When the callback returns [SQLITE_OK], that means the operation
  3090. ** requested is ok. ^When the callback returns [SQLITE_DENY], the
  3091. ** [sqlite3_prepare_v2()] or equivalent call that triggered the
  3092. ** authorizer will fail with an error message explaining that
  3093. ** access is denied.
  3094. **
  3095. ** ^The first parameter to the authorizer callback is a copy of the third
  3096. ** parameter to the sqlite3_set_authorizer() interface. ^The second parameter
  3097. ** to the callback is an integer [SQLITE_COPY | action code] that specifies
  3098. ** the particular action to be authorized. ^The third through sixth parameters
  3099. ** to the callback are either NULL pointers or zero-terminated strings
  3100. ** that contain additional details about the action to be authorized.
  3101. ** Applications must always be prepared to encounter a NULL pointer in any
  3102. ** of the third through the sixth parameters of the authorization callback.
  3103. **
  3104. ** ^If the action code is [SQLITE_READ]
  3105. ** and the callback returns [SQLITE_IGNORE] then the
  3106. ** [prepared statement] statement is constructed to substitute
  3107. ** a NULL value in place of the table column that would have
  3108. ** been read if [SQLITE_OK] had been returned. The [SQLITE_IGNORE]
  3109. ** return can be used to deny an untrusted user access to individual
  3110. ** columns of a table.
  3111. ** ^When a table is referenced by a [SELECT] but no column values are
  3112. ** extracted from that table (for example in a query like
  3113. ** "SELECT count(*) FROM tab") then the [SQLITE_READ] authorizer callback
  3114. ** is invoked once for that table with a column name that is an empty string.
  3115. ** ^If the action code is [SQLITE_DELETE] and the callback returns
  3116. ** [SQLITE_IGNORE] then the [DELETE] operation proceeds but the
  3117. ** [truncate optimization] is disabled and all rows are deleted individually.
  3118. **
  3119. ** An authorizer is used when [sqlite3_prepare | preparing]
  3120. ** SQL statements from an untrusted source, to ensure that the SQL statements
  3121. ** do not try to access data they are not allowed to see, or that they do not
  3122. ** try to execute malicious statements that damage the database. For
  3123. ** example, an application may allow a user to enter arbitrary
  3124. ** SQL queries for evaluation by a database. But the application does
  3125. ** not want the user to be able to make arbitrary changes to the
  3126. ** database. An authorizer could then be put in place while the
  3127. ** user-entered SQL is being [sqlite3_prepare | prepared] that
  3128. ** disallows everything except [SELECT] statements.
  3129. **
  3130. ** Applications that need to process SQL from untrusted sources
  3131. ** might also consider lowering resource limits using [sqlite3_limit()]
  3132. ** and limiting database size using the [max_page_count] [PRAGMA]
  3133. ** in addition to using an authorizer.
  3134. **
  3135. ** ^(Only a single authorizer can be in place on a database connection
  3136. ** at a time. Each call to sqlite3_set_authorizer overrides the
  3137. ** previous call.)^ ^Disable the authorizer by installing a NULL callback.
  3138. ** The authorizer is disabled by default.
  3139. **
  3140. ** The authorizer callback must not do anything that will modify
  3141. ** the database connection that invoked the authorizer callback.
  3142. ** Note that [sqlite3_prepare_v2()] and [sqlite3_step()] both modify their
  3143. ** database connections for the meaning of "modify" in this paragraph.
  3144. **
  3145. ** ^When [sqlite3_prepare_v2()] is used to prepare a statement, the
  3146. ** statement might be re-prepared during [sqlite3_step()] due to a
  3147. ** schema change. Hence, the application should ensure that the
  3148. ** correct authorizer callback remains in place during the [sqlite3_step()].
  3149. **
  3150. ** ^Note that the authorizer callback is invoked only during
  3151. ** [sqlite3_prepare()] or its variants. Authorization is not
  3152. ** performed during statement evaluation in [sqlite3_step()], unless
  3153. ** as stated in the previous paragraph, sqlite3_step() invokes
  3154. ** sqlite3_prepare_v2() to reprepare a statement after a schema change.
  3155. */
  3156. SQLITE_API int sqlite3_set_authorizer(
  3157. sqlite3*,
  3158. int (*xAuth)(void*,int,const char*,const char*,const char*,const char*),
  3159. void *pUserData
  3160. );
  3161. /*
  3162. ** CAPI3REF: Authorizer Return Codes
  3163. **
  3164. ** The [sqlite3_set_authorizer | authorizer callback function] must
  3165. ** return either [SQLITE_OK] or one of these two constants in order
  3166. ** to signal SQLite whether or not the action is permitted. See the
  3167. ** [sqlite3_set_authorizer | authorizer documentation] for additional
  3168. ** information.
  3169. **
  3170. ** Note that SQLITE_IGNORE is also used as a [conflict resolution mode]
  3171. ** returned from the [sqlite3_vtab_on_conflict()] interface.
  3172. */
  3173. #define SQLITE_DENY 1 /* Abort the SQL statement with an error */
  3174. #define SQLITE_IGNORE 2 /* Don't allow access, but don't generate an error */
  3175. /*
  3176. ** CAPI3REF: Authorizer Action Codes
  3177. **
  3178. ** The [sqlite3_set_authorizer()] interface registers a callback function
  3179. ** that is invoked to authorize certain SQL statement actions. The
  3180. ** second parameter to the callback is an integer code that specifies
  3181. ** what action is being authorized. These are the integer action codes that
  3182. ** the authorizer callback may be passed.
  3183. **
  3184. ** These action code values signify what kind of operation is to be
  3185. ** authorized. The 3rd and 4th parameters to the authorization
  3186. ** callback function will be parameters or NULL depending on which of these
  3187. ** codes is used as the second parameter. ^(The 5th parameter to the
  3188. ** authorizer callback is the name of the database ("main", "temp",
  3189. ** etc.) if applicable.)^ ^The 6th parameter to the authorizer callback
  3190. ** is the name of the inner-most trigger or view that is responsible for
  3191. ** the access attempt or NULL if this access attempt is directly from
  3192. ** top-level SQL code.
  3193. */
  3194. /******************************************* 3rd ************ 4th ***********/
  3195. #define SQLITE_CREATE_INDEX 1 /* Index Name Table Name */
  3196. #define SQLITE_CREATE_TABLE 2 /* Table Name NULL */
  3197. #define SQLITE_CREATE_TEMP_INDEX 3 /* Index Name Table Name */
  3198. #define SQLITE_CREATE_TEMP_TABLE 4 /* Table Name NULL */
  3199. #define SQLITE_CREATE_TEMP_TRIGGER 5 /* Trigger Name Table Name */
  3200. #define SQLITE_CREATE_TEMP_VIEW 6 /* View Name NULL */
  3201. #define SQLITE_CREATE_TRIGGER 7 /* Trigger Name Table Name */
  3202. #define SQLITE_CREATE_VIEW 8 /* View Name NULL */
  3203. #define SQLITE_DELETE 9 /* Table Name NULL */
  3204. #define SQLITE_DROP_INDEX 10 /* Index Name Table Name */
  3205. #define SQLITE_DROP_TABLE 11 /* Table Name NULL */
  3206. #define SQLITE_DROP_TEMP_INDEX 12 /* Index Name Table Name */
  3207. #define SQLITE_DROP_TEMP_TABLE 13 /* Table Name NULL */
  3208. #define SQLITE_DROP_TEMP_TRIGGER 14 /* Trigger Name Table Name */
  3209. #define SQLITE_DROP_TEMP_VIEW 15 /* View Name NULL */
  3210. #define SQLITE_DROP_TRIGGER 16 /* Trigger Name Table Name */
  3211. #define SQLITE_DROP_VIEW 17 /* View Name NULL */
  3212. #define SQLITE_INSERT 18 /* Table Name NULL */
  3213. #define SQLITE_PRAGMA 19 /* Pragma Name 1st arg or NULL */
  3214. #define SQLITE_READ 20 /* Table Name Column Name */
  3215. #define SQLITE_SELECT 21 /* NULL NULL */
  3216. #define SQLITE_TRANSACTION 22 /* Operation NULL */
  3217. #define SQLITE_UPDATE 23 /* Table Name Column Name */
  3218. #define SQLITE_ATTACH 24 /* Filename NULL */
  3219. #define SQLITE_DETACH 25 /* Database Name NULL */
  3220. #define SQLITE_ALTER_TABLE 26 /* Database Name Table Name */
  3221. #define SQLITE_REINDEX 27 /* Index Name NULL */
  3222. #define SQLITE_ANALYZE 28 /* Table Name NULL */
  3223. #define SQLITE_CREATE_VTABLE 29 /* Table Name Module Name */
  3224. #define SQLITE_DROP_VTABLE 30 /* Table Name Module Name */
  3225. #define SQLITE_FUNCTION 31 /* NULL Function Name */
  3226. #define SQLITE_SAVEPOINT 32 /* Operation Savepoint Name */
  3227. #define SQLITE_COPY 0 /* No longer used */
  3228. #define SQLITE_RECURSIVE 33 /* NULL NULL */
  3229. /*
  3230. ** CAPI3REF: Tracing And Profiling Functions
  3231. ** METHOD: sqlite3
  3232. **
  3233. ** These routines are deprecated. Use the [sqlite3_trace_v2()] interface
  3234. ** instead of the routines described here.
  3235. **
  3236. ** These routines register callback functions that can be used for
  3237. ** tracing and profiling the execution of SQL statements.
  3238. **
  3239. ** ^The callback function registered by sqlite3_trace() is invoked at
  3240. ** various times when an SQL statement is being run by [sqlite3_step()].
  3241. ** ^The sqlite3_trace() callback is invoked with a UTF-8 rendering of the
  3242. ** SQL statement text as the statement first begins executing.
  3243. ** ^(Additional sqlite3_trace() callbacks might occur
  3244. ** as each triggered subprogram is entered. The callbacks for triggers
  3245. ** contain a UTF-8 SQL comment that identifies the trigger.)^
  3246. **
  3247. ** The [SQLITE_TRACE_SIZE_LIMIT] compile-time option can be used to limit
  3248. ** the length of [bound parameter] expansion in the output of sqlite3_trace().
  3249. **
  3250. ** ^The callback function registered by sqlite3_profile() is invoked
  3251. ** as each SQL statement finishes. ^The profile callback contains
  3252. ** the original statement text and an estimate of wall-clock time
  3253. ** of how long that statement took to run. ^The profile callback
  3254. ** time is in units of nanoseconds, however the current implementation
  3255. ** is only capable of millisecond resolution so the six least significant
  3256. ** digits in the time are meaningless. Future versions of SQLite
  3257. ** might provide greater resolution on the profiler callback. Invoking
  3258. ** either [sqlite3_trace()] or [sqlite3_trace_v2()] will cancel the
  3259. ** profile callback.
  3260. */
  3261. SQLITE_API SQLITE_DEPRECATED void *sqlite3_trace(sqlite3*,
  3262. void(*xTrace)(void*,const char*), void*);
  3263. SQLITE_API SQLITE_DEPRECATED void *sqlite3_profile(sqlite3*,
  3264. void(*xProfile)(void*,const char*,sqlite3_uint64), void*);
  3265. /*
  3266. ** CAPI3REF: SQL Trace Event Codes
  3267. ** KEYWORDS: SQLITE_TRACE
  3268. **
  3269. ** These constants identify classes of events that can be monitored
  3270. ** using the [sqlite3_trace_v2()] tracing logic. The M argument
  3271. ** to [sqlite3_trace_v2(D,M,X,P)] is an OR-ed combination of one or more of
  3272. ** the following constants. ^The first argument to the trace callback
  3273. ** is one of the following constants.
  3274. **
  3275. ** New tracing constants may be added in future releases.
  3276. **
  3277. ** ^A trace callback has four arguments: xCallback(T,C,P,X).
  3278. ** ^The T argument is one of the integer type codes above.
  3279. ** ^The C argument is a copy of the context pointer passed in as the
  3280. ** fourth argument to [sqlite3_trace_v2()].
  3281. ** The P and X arguments are pointers whose meanings depend on T.
  3282. **
  3283. ** <dl>
  3284. ** [[SQLITE_TRACE_STMT]] <dt>SQLITE_TRACE_STMT</dt>
  3285. ** <dd>^An SQLITE_TRACE_STMT callback is invoked when a prepared statement
  3286. ** first begins running and possibly at other times during the
  3287. ** execution of the prepared statement, such as at the start of each
  3288. ** trigger subprogram. ^The P argument is a pointer to the
  3289. ** [prepared statement]. ^The X argument is a pointer to a string which
  3290. ** is the unexpanded SQL text of the prepared statement or an SQL comment
  3291. ** that indicates the invocation of a trigger. ^The callback can compute
  3292. ** the same text that would have been returned by the legacy [sqlite3_trace()]
  3293. ** interface by using the X argument when X begins with "--" and invoking
  3294. ** [sqlite3_expanded_sql(P)] otherwise.
  3295. **
  3296. ** [[SQLITE_TRACE_PROFILE]] <dt>SQLITE_TRACE_PROFILE</dt>
  3297. ** <dd>^An SQLITE_TRACE_PROFILE callback provides approximately the same
  3298. ** information as is provided by the [sqlite3_profile()] callback.
  3299. ** ^The P argument is a pointer to the [prepared statement] and the
  3300. ** X argument points to a 64-bit integer which is approximately
  3301. ** the number of nanoseconds that the prepared statement took to run.
  3302. ** ^The SQLITE_TRACE_PROFILE callback is invoked when the statement finishes.
  3303. **
  3304. ** [[SQLITE_TRACE_ROW]] <dt>SQLITE_TRACE_ROW</dt>
  3305. ** <dd>^An SQLITE_TRACE_ROW callback is invoked whenever a prepared
  3306. ** statement generates a single row of result.
  3307. ** ^The P argument is a pointer to the [prepared statement] and the
  3308. ** X argument is unused.
  3309. **
  3310. ** [[SQLITE_TRACE_CLOSE]] <dt>SQLITE_TRACE_CLOSE</dt>
  3311. ** <dd>^An SQLITE_TRACE_CLOSE callback is invoked when a database
  3312. ** connection closes.
  3313. ** ^The P argument is a pointer to the [database connection] object
  3314. ** and the X argument is unused.
  3315. ** </dl>
  3316. */
  3317. #define SQLITE_TRACE_STMT 0x01
  3318. #define SQLITE_TRACE_PROFILE 0x02
  3319. #define SQLITE_TRACE_ROW 0x04
  3320. #define SQLITE_TRACE_CLOSE 0x08
  3321. /*
  3322. ** CAPI3REF: SQL Trace Hook
  3323. ** METHOD: sqlite3
  3324. **
  3325. ** ^The sqlite3_trace_v2(D,M,X,P) interface registers a trace callback
  3326. ** function X against [database connection] D, using property mask M
  3327. ** and context pointer P. ^If the X callback is
  3328. ** NULL or if the M mask is zero, then tracing is disabled. The
  3329. ** M argument should be the bitwise OR-ed combination of
  3330. ** zero or more [SQLITE_TRACE] constants.
  3331. **
  3332. ** ^Each call to either sqlite3_trace(D,X,P) or sqlite3_trace_v2(D,M,X,P)
  3333. ** overrides (cancels) all prior calls to sqlite3_trace(D,X,P) or
  3334. ** sqlite3_trace_v2(D,M,X,P) for the [database connection] D. Each
  3335. ** database connection may have at most one trace callback.
  3336. **
  3337. ** ^The X callback is invoked whenever any of the events identified by
  3338. ** mask M occur. ^The integer return value from the callback is currently
  3339. ** ignored, though this may change in future releases. Callback
  3340. ** implementations should return zero to ensure future compatibility.
  3341. **
  3342. ** ^A trace callback is invoked with four arguments: callback(T,C,P,X).
  3343. ** ^The T argument is one of the [SQLITE_TRACE]
  3344. ** constants to indicate why the callback was invoked.
  3345. ** ^The C argument is a copy of the context pointer.
  3346. ** The P and X arguments are pointers whose meanings depend on T.
  3347. **
  3348. ** The sqlite3_trace_v2() interface is intended to replace the legacy
  3349. ** interfaces [sqlite3_trace()] and [sqlite3_profile()], both of which
  3350. ** are deprecated.
  3351. */
  3352. SQLITE_API int sqlite3_trace_v2(
  3353. sqlite3*,
  3354. unsigned uMask,
  3355. int(*xCallback)(unsigned,void*,void*,void*),
  3356. void *pCtx
  3357. );
  3358. /*
  3359. ** CAPI3REF: Query Progress Callbacks
  3360. ** METHOD: sqlite3
  3361. **
  3362. ** ^The sqlite3_progress_handler(D,N,X,P) interface causes the callback
  3363. ** function X to be invoked periodically during long running calls to
  3364. ** [sqlite3_step()] and [sqlite3_prepare()] and similar for
  3365. ** database connection D. An example use for this
  3366. ** interface is to keep a GUI updated during a large query.
  3367. **
  3368. ** ^The parameter P is passed through as the only parameter to the
  3369. ** callback function X. ^The parameter N is the approximate number of
  3370. ** [virtual machine instructions] that are evaluated between successive
  3371. ** invocations of the callback X. ^If N is less than one then the progress
  3372. ** handler is disabled.
  3373. **
  3374. ** ^Only a single progress handler may be defined at one time per
  3375. ** [database connection]; setting a new progress handler cancels the
  3376. ** old one. ^Setting parameter X to NULL disables the progress handler.
  3377. ** ^The progress handler is also disabled by setting N to a value less
  3378. ** than 1.
  3379. **
  3380. ** ^If the progress callback returns non-zero, the operation is
  3381. ** interrupted. This feature can be used to implement a
  3382. ** "Cancel" button on a GUI progress dialog box.
  3383. **
  3384. ** The progress handler callback must not do anything that will modify
  3385. ** the database connection that invoked the progress handler.
  3386. ** Note that [sqlite3_prepare_v2()] and [sqlite3_step()] both modify their
  3387. ** database connections for the meaning of "modify" in this paragraph.
  3388. **
  3389. ** The progress handler callback would originally only be invoked from the
  3390. ** bytecode engine. It still might be invoked during [sqlite3_prepare()]
  3391. ** and similar because those routines might force a reparse of the schema
  3392. ** which involves running the bytecode engine. However, beginning with
  3393. ** SQLite version 3.41.0, the progress handler callback might also be
  3394. ** invoked directly from [sqlite3_prepare()] while analyzing and generating
  3395. ** code for complex queries.
  3396. */
  3397. SQLITE_API void sqlite3_progress_handler(sqlite3*, int, int(*)(void*), void*);
  3398. /*
  3399. ** CAPI3REF: Opening A New Database Connection
  3400. ** CONSTRUCTOR: sqlite3
  3401. **
  3402. ** ^These routines open an SQLite database file as specified by the
  3403. ** filename argument. ^The filename argument is interpreted as UTF-8 for
  3404. ** sqlite3_open() and sqlite3_open_v2() and as UTF-16 in the native byte
  3405. ** order for sqlite3_open16(). ^(A [database connection] handle is usually
  3406. ** returned in *ppDb, even if an error occurs. The only exception is that
  3407. ** if SQLite is unable to allocate memory to hold the [sqlite3] object,
  3408. ** a NULL will be written into *ppDb instead of a pointer to the [sqlite3]
  3409. ** object.)^ ^(If the database is opened (and/or created) successfully, then
  3410. ** [SQLITE_OK] is returned. Otherwise an [error code] is returned.)^ ^The
  3411. ** [sqlite3_errmsg()] or [sqlite3_errmsg16()] routines can be used to obtain
  3412. ** an English language description of the error following a failure of any
  3413. ** of the sqlite3_open() routines.
  3414. **
  3415. ** ^The default encoding will be UTF-8 for databases created using
  3416. ** sqlite3_open() or sqlite3_open_v2(). ^The default encoding for databases
  3417. ** created using sqlite3_open16() will be UTF-16 in the native byte order.
  3418. **
  3419. ** Whether or not an error occurs when it is opened, resources
  3420. ** associated with the [database connection] handle should be released by
  3421. ** passing it to [sqlite3_close()] when it is no longer required.
  3422. **
  3423. ** The sqlite3_open_v2() interface works like sqlite3_open()
  3424. ** except that it accepts two additional parameters for additional control
  3425. ** over the new database connection. ^(The flags parameter to
  3426. ** sqlite3_open_v2() must include, at a minimum, one of the following
  3427. ** three flag combinations:)^
  3428. **
  3429. ** <dl>
  3430. ** ^(<dt>[SQLITE_OPEN_READONLY]</dt>
  3431. ** <dd>The database is opened in read-only mode. If the database does
  3432. ** not already exist, an error is returned.</dd>)^
  3433. **
  3434. ** ^(<dt>[SQLITE_OPEN_READWRITE]</dt>
  3435. ** <dd>The database is opened for reading and writing if possible, or
  3436. ** reading only if the file is write protected by the operating
  3437. ** system. In either case the database must already exist, otherwise
  3438. ** an error is returned. For historical reasons, if opening in
  3439. ** read-write mode fails due to OS-level permissions, an attempt is
  3440. ** made to open it in read-only mode. [sqlite3_db_readonly()] can be
  3441. ** used to determine whether the database is actually
  3442. ** read-write.</dd>)^
  3443. **
  3444. ** ^(<dt>[SQLITE_OPEN_READWRITE] | [SQLITE_OPEN_CREATE]</dt>
  3445. ** <dd>The database is opened for reading and writing, and is created if
  3446. ** it does not already exist. This is the behavior that is always used for
  3447. ** sqlite3_open() and sqlite3_open16().</dd>)^
  3448. ** </dl>
  3449. **
  3450. ** In addition to the required flags, the following optional flags are
  3451. ** also supported:
  3452. **
  3453. ** <dl>
  3454. ** ^(<dt>[SQLITE_OPEN_URI]</dt>
  3455. ** <dd>The filename can be interpreted as a URI if this flag is set.</dd>)^
  3456. **
  3457. ** ^(<dt>[SQLITE_OPEN_MEMORY]</dt>
  3458. ** <dd>The database will be opened as an in-memory database. The database
  3459. ** is named by the "filename" argument for the purposes of cache-sharing,
  3460. ** if shared cache mode is enabled, but the "filename" is otherwise ignored.
  3461. ** </dd>)^
  3462. **
  3463. ** ^(<dt>[SQLITE_OPEN_NOMUTEX]</dt>
  3464. ** <dd>The new database connection will use the "multi-thread"
  3465. ** [threading mode].)^ This means that separate threads are allowed
  3466. ** to use SQLite at the same time, as long as each thread is using
  3467. ** a different [database connection].
  3468. **
  3469. ** ^(<dt>[SQLITE_OPEN_FULLMUTEX]</dt>
  3470. ** <dd>The new database connection will use the "serialized"
  3471. ** [threading mode].)^ This means the multiple threads can safely
  3472. ** attempt to use the same database connection at the same time.
  3473. ** (Mutexes will block any actual concurrency, but in this mode
  3474. ** there is no harm in trying.)
  3475. **
  3476. ** ^(<dt>[SQLITE_OPEN_SHAREDCACHE]</dt>
  3477. ** <dd>The database is opened [shared cache] enabled, overriding
  3478. ** the default shared cache setting provided by
  3479. ** [sqlite3_enable_shared_cache()].)^
  3480. ** The [use of shared cache mode is discouraged] and hence shared cache
  3481. ** capabilities may be omitted from many builds of SQLite. In such cases,
  3482. ** this option is a no-op.
  3483. **
  3484. ** ^(<dt>[SQLITE_OPEN_PRIVATECACHE]</dt>
  3485. ** <dd>The database is opened [shared cache] disabled, overriding
  3486. ** the default shared cache setting provided by
  3487. ** [sqlite3_enable_shared_cache()].)^
  3488. **
  3489. ** [[OPEN_EXRESCODE]] ^(<dt>[SQLITE_OPEN_EXRESCODE]</dt>
  3490. ** <dd>The database connection comes up in "extended result code mode".
  3491. ** In other words, the database behaves has if
  3492. ** [sqlite3_extended_result_codes(db,1)] where called on the database
  3493. ** connection as soon as the connection is created. In addition to setting
  3494. ** the extended result code mode, this flag also causes [sqlite3_open_v2()]
  3495. ** to return an extended result code.</dd>
  3496. **
  3497. ** [[OPEN_NOFOLLOW]] ^(<dt>[SQLITE_OPEN_NOFOLLOW]</dt>
  3498. ** <dd>The database filename is not allowed to contain a symbolic link</dd>
  3499. ** </dl>)^
  3500. **
  3501. ** If the 3rd parameter to sqlite3_open_v2() is not one of the
  3502. ** required combinations shown above optionally combined with other
  3503. ** [SQLITE_OPEN_READONLY | SQLITE_OPEN_* bits]
  3504. ** then the behavior is undefined. Historic versions of SQLite
  3505. ** have silently ignored surplus bits in the flags parameter to
  3506. ** sqlite3_open_v2(), however that behavior might not be carried through
  3507. ** into future versions of SQLite and so applications should not rely
  3508. ** upon it. Note in particular that the SQLITE_OPEN_EXCLUSIVE flag is a no-op
  3509. ** for sqlite3_open_v2(). The SQLITE_OPEN_EXCLUSIVE does *not* cause
  3510. ** the open to fail if the database already exists. The SQLITE_OPEN_EXCLUSIVE
  3511. ** flag is intended for use by the [sqlite3_vfs|VFS interface] only, and not
  3512. ** by sqlite3_open_v2().
  3513. **
  3514. ** ^The fourth parameter to sqlite3_open_v2() is the name of the
  3515. ** [sqlite3_vfs] object that defines the operating system interface that
  3516. ** the new database connection should use. ^If the fourth parameter is
  3517. ** a NULL pointer then the default [sqlite3_vfs] object is used.
  3518. **
  3519. ** ^If the filename is ":memory:", then a private, temporary in-memory database
  3520. ** is created for the connection. ^This in-memory database will vanish when
  3521. ** the database connection is closed. Future versions of SQLite might
  3522. ** make use of additional special filenames that begin with the ":" character.
  3523. ** It is recommended that when a database filename actually does begin with
  3524. ** a ":" character you should prefix the filename with a pathname such as
  3525. ** "./" to avoid ambiguity.
  3526. **
  3527. ** ^If the filename is an empty string, then a private, temporary
  3528. ** on-disk database will be created. ^This private database will be
  3529. ** automatically deleted as soon as the database connection is closed.
  3530. **
  3531. ** [[URI filenames in sqlite3_open()]] <h3>URI Filenames</h3>
  3532. **
  3533. ** ^If [URI filename] interpretation is enabled, and the filename argument
  3534. ** begins with "file:", then the filename is interpreted as a URI. ^URI
  3535. ** filename interpretation is enabled if the [SQLITE_OPEN_URI] flag is
  3536. ** set in the third argument to sqlite3_open_v2(), or if it has
  3537. ** been enabled globally using the [SQLITE_CONFIG_URI] option with the
  3538. ** [sqlite3_config()] method or by the [SQLITE_USE_URI] compile-time option.
  3539. ** URI filename interpretation is turned off
  3540. ** by default, but future releases of SQLite might enable URI filename
  3541. ** interpretation by default. See "[URI filenames]" for additional
  3542. ** information.
  3543. **
  3544. ** URI filenames are parsed according to RFC 3986. ^If the URI contains an
  3545. ** authority, then it must be either an empty string or the string
  3546. ** "localhost". ^If the authority is not an empty string or "localhost", an
  3547. ** error is returned to the caller. ^The fragment component of a URI, if
  3548. ** present, is ignored.
  3549. **
  3550. ** ^SQLite uses the path component of the URI as the name of the disk file
  3551. ** which contains the database. ^If the path begins with a '/' character,
  3552. ** then it is interpreted as an absolute path. ^If the path does not begin
  3553. ** with a '/' (meaning that the authority section is omitted from the URI)
  3554. ** then the path is interpreted as a relative path.
  3555. ** ^(On windows, the first component of an absolute path
  3556. ** is a drive specification (e.g. "C:").)^
  3557. **
  3558. ** [[core URI query parameters]]
  3559. ** The query component of a URI may contain parameters that are interpreted
  3560. ** either by SQLite itself, or by a [VFS | custom VFS implementation].
  3561. ** SQLite and its built-in [VFSes] interpret the
  3562. ** following query parameters:
  3563. **
  3564. ** <ul>
  3565. ** <li> <b>vfs</b>: ^The "vfs" parameter may be used to specify the name of
  3566. ** a VFS object that provides the operating system interface that should
  3567. ** be used to access the database file on disk. ^If this option is set to
  3568. ** an empty string the default VFS object is used. ^Specifying an unknown
  3569. ** VFS is an error. ^If sqlite3_open_v2() is used and the vfs option is
  3570. ** present, then the VFS specified by the option takes precedence over
  3571. ** the value passed as the fourth parameter to sqlite3_open_v2().
  3572. **
  3573. ** <li> <b>mode</b>: ^(The mode parameter may be set to either "ro", "rw",
  3574. ** "rwc", or "memory". Attempting to set it to any other value is
  3575. ** an error)^.
  3576. ** ^If "ro" is specified, then the database is opened for read-only
  3577. ** access, just as if the [SQLITE_OPEN_READONLY] flag had been set in the
  3578. ** third argument to sqlite3_open_v2(). ^If the mode option is set to
  3579. ** "rw", then the database is opened for read-write (but not create)
  3580. ** access, as if SQLITE_OPEN_READWRITE (but not SQLITE_OPEN_CREATE) had
  3581. ** been set. ^Value "rwc" is equivalent to setting both
  3582. ** SQLITE_OPEN_READWRITE and SQLITE_OPEN_CREATE. ^If the mode option is
  3583. ** set to "memory" then a pure [in-memory database] that never reads
  3584. ** or writes from disk is used. ^It is an error to specify a value for
  3585. ** the mode parameter that is less restrictive than that specified by
  3586. ** the flags passed in the third parameter to sqlite3_open_v2().
  3587. **
  3588. ** <li> <b>cache</b>: ^The cache parameter may be set to either "shared" or
  3589. ** "private". ^Setting it to "shared" is equivalent to setting the
  3590. ** SQLITE_OPEN_SHAREDCACHE bit in the flags argument passed to
  3591. ** sqlite3_open_v2(). ^Setting the cache parameter to "private" is
  3592. ** equivalent to setting the SQLITE_OPEN_PRIVATECACHE bit.
  3593. ** ^If sqlite3_open_v2() is used and the "cache" parameter is present in
  3594. ** a URI filename, its value overrides any behavior requested by setting
  3595. ** SQLITE_OPEN_PRIVATECACHE or SQLITE_OPEN_SHAREDCACHE flag.
  3596. **
  3597. ** <li> <b>psow</b>: ^The psow parameter indicates whether or not the
  3598. ** [powersafe overwrite] property does or does not apply to the
  3599. ** storage media on which the database file resides.
  3600. **
  3601. ** <li> <b>nolock</b>: ^The nolock parameter is a boolean query parameter
  3602. ** which if set disables file locking in rollback journal modes. This
  3603. ** is useful for accessing a database on a filesystem that does not
  3604. ** support locking. Caution: Database corruption might result if two
  3605. ** or more processes write to the same database and any one of those
  3606. ** processes uses nolock=1.
  3607. **
  3608. ** <li> <b>immutable</b>: ^The immutable parameter is a boolean query
  3609. ** parameter that indicates that the database file is stored on
  3610. ** read-only media. ^When immutable is set, SQLite assumes that the
  3611. ** database file cannot be changed, even by a process with higher
  3612. ** privilege, and so the database is opened read-only and all locking
  3613. ** and change detection is disabled. Caution: Setting the immutable
  3614. ** property on a database file that does in fact change can result
  3615. ** in incorrect query results and/or [SQLITE_CORRUPT] errors.
  3616. ** See also: [SQLITE_IOCAP_IMMUTABLE].
  3617. **
  3618. ** </ul>
  3619. **
  3620. ** ^Specifying an unknown parameter in the query component of a URI is not an
  3621. ** error. Future versions of SQLite might understand additional query
  3622. ** parameters. See "[query parameters with special meaning to SQLite]" for
  3623. ** additional information.
  3624. **
  3625. ** [[URI filename examples]] <h3>URI filename examples</h3>
  3626. **
  3627. ** <table border="1" align=center cellpadding=5>
  3628. ** <tr><th> URI filenames <th> Results
  3629. ** <tr><td> file:data.db <td>
  3630. ** Open the file "data.db" in the current directory.
  3631. ** <tr><td> file:/home/fred/data.db<br>
  3632. ** file:///home/fred/data.db <br>
  3633. ** file://localhost/home/fred/data.db <br> <td>
  3634. ** Open the database file "/home/fred/data.db".
  3635. ** <tr><td> file://darkstar/home/fred/data.db <td>
  3636. ** An error. "darkstar" is not a recognized authority.
  3637. ** <tr><td style="white-space:nowrap">
  3638. ** file:///C:/Documents%20and%20Settings/fred/Desktop/data.db
  3639. ** <td> Windows only: Open the file "data.db" on fred's desktop on drive
  3640. ** C:. Note that the %20 escaping in this example is not strictly
  3641. ** necessary - space characters can be used literally
  3642. ** in URI filenames.
  3643. ** <tr><td> file:data.db?mode=ro&cache=private <td>
  3644. ** Open file "data.db" in the current directory for read-only access.
  3645. ** Regardless of whether or not shared-cache mode is enabled by
  3646. ** default, use a private cache.
  3647. ** <tr><td> file:/home/fred/data.db?vfs=unix-dotfile <td>
  3648. ** Open file "/home/fred/data.db". Use the special VFS "unix-dotfile"
  3649. ** that uses dot-files in place of posix advisory locking.
  3650. ** <tr><td> file:data.db?mode=readonly <td>
  3651. ** An error. "readonly" is not a valid option for the "mode" parameter.
  3652. ** Use "ro" instead: "file:data.db?mode=ro".
  3653. ** </table>
  3654. **
  3655. ** ^URI hexadecimal escape sequences (%HH) are supported within the path and
  3656. ** query components of a URI. A hexadecimal escape sequence consists of a
  3657. ** percent sign - "%" - followed by exactly two hexadecimal digits
  3658. ** specifying an octet value. ^Before the path or query components of a
  3659. ** URI filename are interpreted, they are encoded using UTF-8 and all
  3660. ** hexadecimal escape sequences replaced by a single byte containing the
  3661. ** corresponding octet. If this process generates an invalid UTF-8 encoding,
  3662. ** the results are undefined.
  3663. **
  3664. ** <b>Note to Windows users:</b> The encoding used for the filename argument
  3665. ** of sqlite3_open() and sqlite3_open_v2() must be UTF-8, not whatever
  3666. ** codepage is currently defined. Filenames containing international
  3667. ** characters must be converted to UTF-8 prior to passing them into
  3668. ** sqlite3_open() or sqlite3_open_v2().
  3669. **
  3670. ** <b>Note to Windows Runtime users:</b> The temporary directory must be set
  3671. ** prior to calling sqlite3_open() or sqlite3_open_v2(). Otherwise, various
  3672. ** features that require the use of temporary files may fail.
  3673. **
  3674. ** See also: [sqlite3_temp_directory]
  3675. */
  3676. SQLITE_API int sqlite3_open(
  3677. const char *filename, /* Database filename (UTF-8) */
  3678. sqlite3 **ppDb /* OUT: SQLite db handle */
  3679. );
  3680. SQLITE_API int sqlite3_open16(
  3681. const void *filename, /* Database filename (UTF-16) */
  3682. sqlite3 **ppDb /* OUT: SQLite db handle */
  3683. );
  3684. SQLITE_API int sqlite3_open_v2(
  3685. const char *filename, /* Database filename (UTF-8) */
  3686. sqlite3 **ppDb, /* OUT: SQLite db handle */
  3687. int flags, /* Flags */
  3688. const char *zVfs /* Name of VFS module to use */
  3689. );
  3690. /*
  3691. ** CAPI3REF: Obtain Values For URI Parameters
  3692. **
  3693. ** These are utility routines, useful to [VFS|custom VFS implementations],
  3694. ** that check if a database file was a URI that contained a specific query
  3695. ** parameter, and if so obtains the value of that query parameter.
  3696. **
  3697. ** The first parameter to these interfaces (hereafter referred to
  3698. ** as F) must be one of:
  3699. ** <ul>
  3700. ** <li> A database filename pointer created by the SQLite core and
  3701. ** passed into the xOpen() method of a VFS implementation, or
  3702. ** <li> A filename obtained from [sqlite3_db_filename()], or
  3703. ** <li> A new filename constructed using [sqlite3_create_filename()].
  3704. ** </ul>
  3705. ** If the F parameter is not one of the above, then the behavior is
  3706. ** undefined and probably undesirable. Older versions of SQLite were
  3707. ** more tolerant of invalid F parameters than newer versions.
  3708. **
  3709. ** If F is a suitable filename (as described in the previous paragraph)
  3710. ** and if P is the name of the query parameter, then
  3711. ** sqlite3_uri_parameter(F,P) returns the value of the P
  3712. ** parameter if it exists or a NULL pointer if P does not appear as a
  3713. ** query parameter on F. If P is a query parameter of F and it
  3714. ** has no explicit value, then sqlite3_uri_parameter(F,P) returns
  3715. ** a pointer to an empty string.
  3716. **
  3717. ** The sqlite3_uri_boolean(F,P,B) routine assumes that P is a boolean
  3718. ** parameter and returns true (1) or false (0) according to the value
  3719. ** of P. The sqlite3_uri_boolean(F,P,B) routine returns true (1) if the
  3720. ** value of query parameter P is one of "yes", "true", or "on" in any
  3721. ** case or if the value begins with a non-zero number. The
  3722. ** sqlite3_uri_boolean(F,P,B) routines returns false (0) if the value of
  3723. ** query parameter P is one of "no", "false", or "off" in any case or
  3724. ** if the value begins with a numeric zero. If P is not a query
  3725. ** parameter on F or if the value of P does not match any of the
  3726. ** above, then sqlite3_uri_boolean(F,P,B) returns (B!=0).
  3727. **
  3728. ** The sqlite3_uri_int64(F,P,D) routine converts the value of P into a
  3729. ** 64-bit signed integer and returns that integer, or D if P does not
  3730. ** exist. If the value of P is something other than an integer, then
  3731. ** zero is returned.
  3732. **
  3733. ** The sqlite3_uri_key(F,N) returns a pointer to the name (not
  3734. ** the value) of the N-th query parameter for filename F, or a NULL
  3735. ** pointer if N is less than zero or greater than the number of query
  3736. ** parameters minus 1. The N value is zero-based so N should be 0 to obtain
  3737. ** the name of the first query parameter, 1 for the second parameter, and
  3738. ** so forth.
  3739. **
  3740. ** If F is a NULL pointer, then sqlite3_uri_parameter(F,P) returns NULL and
  3741. ** sqlite3_uri_boolean(F,P,B) returns B. If F is not a NULL pointer and
  3742. ** is not a database file pathname pointer that the SQLite core passed
  3743. ** into the xOpen VFS method, then the behavior of this routine is undefined
  3744. ** and probably undesirable.
  3745. **
  3746. ** Beginning with SQLite [version 3.31.0] ([dateof:3.31.0]) the input F
  3747. ** parameter can also be the name of a rollback journal file or WAL file
  3748. ** in addition to the main database file. Prior to version 3.31.0, these
  3749. ** routines would only work if F was the name of the main database file.
  3750. ** When the F parameter is the name of the rollback journal or WAL file,
  3751. ** it has access to all the same query parameters as were found on the
  3752. ** main database file.
  3753. **
  3754. ** See the [URI filename] documentation for additional information.
  3755. */
  3756. SQLITE_API const char *sqlite3_uri_parameter(sqlite3_filename z, const char *zParam);
  3757. SQLITE_API int sqlite3_uri_boolean(sqlite3_filename z, const char *zParam, int bDefault);
  3758. SQLITE_API sqlite3_int64 sqlite3_uri_int64(sqlite3_filename, const char*, sqlite3_int64);
  3759. SQLITE_API const char *sqlite3_uri_key(sqlite3_filename z, int N);
  3760. /*
  3761. ** CAPI3REF: Translate filenames
  3762. **
  3763. ** These routines are available to [VFS|custom VFS implementations] for
  3764. ** translating filenames between the main database file, the journal file,
  3765. ** and the WAL file.
  3766. **
  3767. ** If F is the name of an sqlite database file, journal file, or WAL file
  3768. ** passed by the SQLite core into the VFS, then sqlite3_filename_database(F)
  3769. ** returns the name of the corresponding database file.
  3770. **
  3771. ** If F is the name of an sqlite database file, journal file, or WAL file
  3772. ** passed by the SQLite core into the VFS, or if F is a database filename
  3773. ** obtained from [sqlite3_db_filename()], then sqlite3_filename_journal(F)
  3774. ** returns the name of the corresponding rollback journal file.
  3775. **
  3776. ** If F is the name of an sqlite database file, journal file, or WAL file
  3777. ** that was passed by the SQLite core into the VFS, or if F is a database
  3778. ** filename obtained from [sqlite3_db_filename()], then
  3779. ** sqlite3_filename_wal(F) returns the name of the corresponding
  3780. ** WAL file.
  3781. **
  3782. ** In all of the above, if F is not the name of a database, journal or WAL
  3783. ** filename passed into the VFS from the SQLite core and F is not the
  3784. ** return value from [sqlite3_db_filename()], then the result is
  3785. ** undefined and is likely a memory access violation.
  3786. */
  3787. SQLITE_API const char *sqlite3_filename_database(sqlite3_filename);
  3788. SQLITE_API const char *sqlite3_filename_journal(sqlite3_filename);
  3789. SQLITE_API const char *sqlite3_filename_wal(sqlite3_filename);
  3790. /*
  3791. ** CAPI3REF: Database File Corresponding To A Journal
  3792. **
  3793. ** ^If X is the name of a rollback or WAL-mode journal file that is
  3794. ** passed into the xOpen method of [sqlite3_vfs], then
  3795. ** sqlite3_database_file_object(X) returns a pointer to the [sqlite3_file]
  3796. ** object that represents the main database file.
  3797. **
  3798. ** This routine is intended for use in custom [VFS] implementations
  3799. ** only. It is not a general-purpose interface.
  3800. ** The argument sqlite3_file_object(X) must be a filename pointer that
  3801. ** has been passed into [sqlite3_vfs].xOpen method where the
  3802. ** flags parameter to xOpen contains one of the bits
  3803. ** [SQLITE_OPEN_MAIN_JOURNAL] or [SQLITE_OPEN_WAL]. Any other use
  3804. ** of this routine results in undefined and probably undesirable
  3805. ** behavior.
  3806. */
  3807. SQLITE_API sqlite3_file *sqlite3_database_file_object(const char*);
  3808. /*
  3809. ** CAPI3REF: Create and Destroy VFS Filenames
  3810. **
  3811. ** These interfaces are provided for use by [VFS shim] implementations and
  3812. ** are not useful outside of that context.
  3813. **
  3814. ** The sqlite3_create_filename(D,J,W,N,P) allocates memory to hold a version of
  3815. ** database filename D with corresponding journal file J and WAL file W and
  3816. ** with N URI parameters key/values pairs in the array P. The result from
  3817. ** sqlite3_create_filename(D,J,W,N,P) is a pointer to a database filename that
  3818. ** is safe to pass to routines like:
  3819. ** <ul>
  3820. ** <li> [sqlite3_uri_parameter()],
  3821. ** <li> [sqlite3_uri_boolean()],
  3822. ** <li> [sqlite3_uri_int64()],
  3823. ** <li> [sqlite3_uri_key()],
  3824. ** <li> [sqlite3_filename_database()],
  3825. ** <li> [sqlite3_filename_journal()], or
  3826. ** <li> [sqlite3_filename_wal()].
  3827. ** </ul>
  3828. ** If a memory allocation error occurs, sqlite3_create_filename() might
  3829. ** return a NULL pointer. The memory obtained from sqlite3_create_filename(X)
  3830. ** must be released by a corresponding call to sqlite3_free_filename(Y).
  3831. **
  3832. ** The P parameter in sqlite3_create_filename(D,J,W,N,P) should be an array
  3833. ** of 2*N pointers to strings. Each pair of pointers in this array corresponds
  3834. ** to a key and value for a query parameter. The P parameter may be a NULL
  3835. ** pointer if N is zero. None of the 2*N pointers in the P array may be
  3836. ** NULL pointers and key pointers should not be empty strings.
  3837. ** None of the D, J, or W parameters to sqlite3_create_filename(D,J,W,N,P) may
  3838. ** be NULL pointers, though they can be empty strings.
  3839. **
  3840. ** The sqlite3_free_filename(Y) routine releases a memory allocation
  3841. ** previously obtained from sqlite3_create_filename(). Invoking
  3842. ** sqlite3_free_filename(Y) where Y is a NULL pointer is a harmless no-op.
  3843. **
  3844. ** If the Y parameter to sqlite3_free_filename(Y) is anything other
  3845. ** than a NULL pointer or a pointer previously acquired from
  3846. ** sqlite3_create_filename(), then bad things such as heap
  3847. ** corruption or segfaults may occur. The value Y should not be
  3848. ** used again after sqlite3_free_filename(Y) has been called. This means
  3849. ** that if the [sqlite3_vfs.xOpen()] method of a VFS has been called using Y,
  3850. ** then the corresponding [sqlite3_module.xClose() method should also be
  3851. ** invoked prior to calling sqlite3_free_filename(Y).
  3852. */
  3853. SQLITE_API sqlite3_filename sqlite3_create_filename(
  3854. const char *zDatabase,
  3855. const char *zJournal,
  3856. const char *zWal,
  3857. int nParam,
  3858. const char **azParam
  3859. );
  3860. SQLITE_API void sqlite3_free_filename(sqlite3_filename);
  3861. /*
  3862. ** CAPI3REF: Error Codes And Messages
  3863. ** METHOD: sqlite3
  3864. **
  3865. ** ^If the most recent sqlite3_* API call associated with
  3866. ** [database connection] D failed, then the sqlite3_errcode(D) interface
  3867. ** returns the numeric [result code] or [extended result code] for that
  3868. ** API call.
  3869. ** ^The sqlite3_extended_errcode()
  3870. ** interface is the same except that it always returns the
  3871. ** [extended result code] even when extended result codes are
  3872. ** disabled.
  3873. **
  3874. ** The values returned by sqlite3_errcode() and/or
  3875. ** sqlite3_extended_errcode() might change with each API call.
  3876. ** Except, there are some interfaces that are guaranteed to never
  3877. ** change the value of the error code. The error-code preserving
  3878. ** interfaces include the following:
  3879. **
  3880. ** <ul>
  3881. ** <li> sqlite3_errcode()
  3882. ** <li> sqlite3_extended_errcode()
  3883. ** <li> sqlite3_errmsg()
  3884. ** <li> sqlite3_errmsg16()
  3885. ** <li> sqlite3_error_offset()
  3886. ** </ul>
  3887. **
  3888. ** ^The sqlite3_errmsg() and sqlite3_errmsg16() return English-language
  3889. ** text that describes the error, as either UTF-8 or UTF-16 respectively.
  3890. ** (See how SQLite handles [invalid UTF] for exceptions to this rule.)
  3891. ** ^(Memory to hold the error message string is managed internally.
  3892. ** The application does not need to worry about freeing the result.
  3893. ** However, the error string might be overwritten or deallocated by
  3894. ** subsequent calls to other SQLite interface functions.)^
  3895. **
  3896. ** ^The sqlite3_errstr() interface returns the English-language text
  3897. ** that describes the [result code], as UTF-8.
  3898. ** ^(Memory to hold the error message string is managed internally
  3899. ** and must not be freed by the application)^.
  3900. **
  3901. ** ^If the most recent error references a specific token in the input
  3902. ** SQL, the sqlite3_error_offset() interface returns the byte offset
  3903. ** of the start of that token. ^The byte offset returned by
  3904. ** sqlite3_error_offset() assumes that the input SQL is UTF8.
  3905. ** ^If the most recent error does not reference a specific token in the input
  3906. ** SQL, then the sqlite3_error_offset() function returns -1.
  3907. **
  3908. ** When the serialized [threading mode] is in use, it might be the
  3909. ** case that a second error occurs on a separate thread in between
  3910. ** the time of the first error and the call to these interfaces.
  3911. ** When that happens, the second error will be reported since these
  3912. ** interfaces always report the most recent result. To avoid
  3913. ** this, each thread can obtain exclusive use of the [database connection] D
  3914. ** by invoking [sqlite3_mutex_enter]([sqlite3_db_mutex](D)) before beginning
  3915. ** to use D and invoking [sqlite3_mutex_leave]([sqlite3_db_mutex](D)) after
  3916. ** all calls to the interfaces listed here are completed.
  3917. **
  3918. ** If an interface fails with SQLITE_MISUSE, that means the interface
  3919. ** was invoked incorrectly by the application. In that case, the
  3920. ** error code and message may or may not be set.
  3921. */
  3922. SQLITE_API int sqlite3_errcode(sqlite3 *db);
  3923. SQLITE_API int sqlite3_extended_errcode(sqlite3 *db);
  3924. SQLITE_API const char *sqlite3_errmsg(sqlite3*);
  3925. SQLITE_API const void *sqlite3_errmsg16(sqlite3*);
  3926. SQLITE_API const char *sqlite3_errstr(int);
  3927. SQLITE_API int sqlite3_error_offset(sqlite3 *db);
  3928. /*
  3929. ** CAPI3REF: Prepared Statement Object
  3930. ** KEYWORDS: {prepared statement} {prepared statements}
  3931. **
  3932. ** An instance of this object represents a single SQL statement that
  3933. ** has been compiled into binary form and is ready to be evaluated.
  3934. **
  3935. ** Think of each SQL statement as a separate computer program. The
  3936. ** original SQL text is source code. A prepared statement object
  3937. ** is the compiled object code. All SQL must be converted into a
  3938. ** prepared statement before it can be run.
  3939. **
  3940. ** The life-cycle of a prepared statement object usually goes like this:
  3941. **
  3942. ** <ol>
  3943. ** <li> Create the prepared statement object using [sqlite3_prepare_v2()].
  3944. ** <li> Bind values to [parameters] using the sqlite3_bind_*()
  3945. ** interfaces.
  3946. ** <li> Run the SQL by calling [sqlite3_step()] one or more times.
  3947. ** <li> Reset the prepared statement using [sqlite3_reset()] then go back
  3948. ** to step 2. Do this zero or more times.
  3949. ** <li> Destroy the object using [sqlite3_finalize()].
  3950. ** </ol>
  3951. */
  3952. typedef struct sqlite3_stmt sqlite3_stmt;
  3953. /*
  3954. ** CAPI3REF: Run-time Limits
  3955. ** METHOD: sqlite3
  3956. **
  3957. ** ^(This interface allows the size of various constructs to be limited
  3958. ** on a connection by connection basis. The first parameter is the
  3959. ** [database connection] whose limit is to be set or queried. The
  3960. ** second parameter is one of the [limit categories] that define a
  3961. ** class of constructs to be size limited. The third parameter is the
  3962. ** new limit for that construct.)^
  3963. **
  3964. ** ^If the new limit is a negative number, the limit is unchanged.
  3965. ** ^(For each limit category SQLITE_LIMIT_<i>NAME</i> there is a
  3966. ** [limits | hard upper bound]
  3967. ** set at compile-time by a C preprocessor macro called
  3968. ** [limits | SQLITE_MAX_<i>NAME</i>].
  3969. ** (The "_LIMIT_" in the name is changed to "_MAX_".))^
  3970. ** ^Attempts to increase a limit above its hard upper bound are
  3971. ** silently truncated to the hard upper bound.
  3972. **
  3973. ** ^Regardless of whether or not the limit was changed, the
  3974. ** [sqlite3_limit()] interface returns the prior value of the limit.
  3975. ** ^Hence, to find the current value of a limit without changing it,
  3976. ** simply invoke this interface with the third parameter set to -1.
  3977. **
  3978. ** Run-time limits are intended for use in applications that manage
  3979. ** both their own internal database and also databases that are controlled
  3980. ** by untrusted external sources. An example application might be a
  3981. ** web browser that has its own databases for storing history and
  3982. ** separate databases controlled by JavaScript applications downloaded
  3983. ** off the Internet. The internal databases can be given the
  3984. ** large, default limits. Databases managed by external sources can
  3985. ** be given much smaller limits designed to prevent a denial of service
  3986. ** attack. Developers might also want to use the [sqlite3_set_authorizer()]
  3987. ** interface to further control untrusted SQL. The size of the database
  3988. ** created by an untrusted script can be contained using the
  3989. ** [max_page_count] [PRAGMA].
  3990. **
  3991. ** New run-time limit categories may be added in future releases.
  3992. */
  3993. SQLITE_API int sqlite3_limit(sqlite3*, int id, int newVal);
  3994. /*
  3995. ** CAPI3REF: Run-Time Limit Categories
  3996. ** KEYWORDS: {limit category} {*limit categories}
  3997. **
  3998. ** These constants define various performance limits
  3999. ** that can be lowered at run-time using [sqlite3_limit()].
  4000. ** The synopsis of the meanings of the various limits is shown below.
  4001. ** Additional information is available at [limits | Limits in SQLite].
  4002. **
  4003. ** <dl>
  4004. ** [[SQLITE_LIMIT_LENGTH]] ^(<dt>SQLITE_LIMIT_LENGTH</dt>
  4005. ** <dd>The maximum size of any string or BLOB or table row, in bytes.<dd>)^
  4006. **
  4007. ** [[SQLITE_LIMIT_SQL_LENGTH]] ^(<dt>SQLITE_LIMIT_SQL_LENGTH</dt>
  4008. ** <dd>The maximum length of an SQL statement, in bytes.</dd>)^
  4009. **
  4010. ** [[SQLITE_LIMIT_COLUMN]] ^(<dt>SQLITE_LIMIT_COLUMN</dt>
  4011. ** <dd>The maximum number of columns in a table definition or in the
  4012. ** result set of a [SELECT] or the maximum number of columns in an index
  4013. ** or in an ORDER BY or GROUP BY clause.</dd>)^
  4014. **
  4015. ** [[SQLITE_LIMIT_EXPR_DEPTH]] ^(<dt>SQLITE_LIMIT_EXPR_DEPTH</dt>
  4016. ** <dd>The maximum depth of the parse tree on any expression.</dd>)^
  4017. **
  4018. ** [[SQLITE_LIMIT_COMPOUND_SELECT]] ^(<dt>SQLITE_LIMIT_COMPOUND_SELECT</dt>
  4019. ** <dd>The maximum number of terms in a compound SELECT statement.</dd>)^
  4020. **
  4021. ** [[SQLITE_LIMIT_VDBE_OP]] ^(<dt>SQLITE_LIMIT_VDBE_OP</dt>
  4022. ** <dd>The maximum number of instructions in a virtual machine program
  4023. ** used to implement an SQL statement. If [sqlite3_prepare_v2()] or
  4024. ** the equivalent tries to allocate space for more than this many opcodes
  4025. ** in a single prepared statement, an SQLITE_NOMEM error is returned.</dd>)^
  4026. **
  4027. ** [[SQLITE_LIMIT_FUNCTION_ARG]] ^(<dt>SQLITE_LIMIT_FUNCTION_ARG</dt>
  4028. ** <dd>The maximum number of arguments on a function.</dd>)^
  4029. **
  4030. ** [[SQLITE_LIMIT_ATTACHED]] ^(<dt>SQLITE_LIMIT_ATTACHED</dt>
  4031. ** <dd>The maximum number of [ATTACH | attached databases].)^</dd>
  4032. **
  4033. ** [[SQLITE_LIMIT_LIKE_PATTERN_LENGTH]]
  4034. ** ^(<dt>SQLITE_LIMIT_LIKE_PATTERN_LENGTH</dt>
  4035. ** <dd>The maximum length of the pattern argument to the [LIKE] or
  4036. ** [GLOB] operators.</dd>)^
  4037. **
  4038. ** [[SQLITE_LIMIT_VARIABLE_NUMBER]]
  4039. ** ^(<dt>SQLITE_LIMIT_VARIABLE_NUMBER</dt>
  4040. ** <dd>The maximum index number of any [parameter] in an SQL statement.)^
  4041. **
  4042. ** [[SQLITE_LIMIT_TRIGGER_DEPTH]] ^(<dt>SQLITE_LIMIT_TRIGGER_DEPTH</dt>
  4043. ** <dd>The maximum depth of recursion for triggers.</dd>)^
  4044. **
  4045. ** [[SQLITE_LIMIT_WORKER_THREADS]] ^(<dt>SQLITE_LIMIT_WORKER_THREADS</dt>
  4046. ** <dd>The maximum number of auxiliary worker threads that a single
  4047. ** [prepared statement] may start.</dd>)^
  4048. ** </dl>
  4049. */
  4050. #define SQLITE_LIMIT_LENGTH 0
  4051. #define SQLITE_LIMIT_SQL_LENGTH 1
  4052. #define SQLITE_LIMIT_COLUMN 2
  4053. #define SQLITE_LIMIT_EXPR_DEPTH 3
  4054. #define SQLITE_LIMIT_COMPOUND_SELECT 4
  4055. #define SQLITE_LIMIT_VDBE_OP 5
  4056. #define SQLITE_LIMIT_FUNCTION_ARG 6
  4057. #define SQLITE_LIMIT_ATTACHED 7
  4058. #define SQLITE_LIMIT_LIKE_PATTERN_LENGTH 8
  4059. #define SQLITE_LIMIT_VARIABLE_NUMBER 9
  4060. #define SQLITE_LIMIT_TRIGGER_DEPTH 10
  4061. #define SQLITE_LIMIT_WORKER_THREADS 11
  4062. /*
  4063. ** CAPI3REF: Prepare Flags
  4064. **
  4065. ** These constants define various flags that can be passed into
  4066. ** "prepFlags" parameter of the [sqlite3_prepare_v3()] and
  4067. ** [sqlite3_prepare16_v3()] interfaces.
  4068. **
  4069. ** New flags may be added in future releases of SQLite.
  4070. **
  4071. ** <dl>
  4072. ** [[SQLITE_PREPARE_PERSISTENT]] ^(<dt>SQLITE_PREPARE_PERSISTENT</dt>
  4073. ** <dd>The SQLITE_PREPARE_PERSISTENT flag is a hint to the query planner
  4074. ** that the prepared statement will be retained for a long time and
  4075. ** probably reused many times.)^ ^Without this flag, [sqlite3_prepare_v3()]
  4076. ** and [sqlite3_prepare16_v3()] assume that the prepared statement will
  4077. ** be used just once or at most a few times and then destroyed using
  4078. ** [sqlite3_finalize()] relatively soon. The current implementation acts
  4079. ** on this hint by avoiding the use of [lookaside memory] so as not to
  4080. ** deplete the limited store of lookaside memory. Future versions of
  4081. ** SQLite may act on this hint differently.
  4082. **
  4083. ** [[SQLITE_PREPARE_NORMALIZE]] <dt>SQLITE_PREPARE_NORMALIZE</dt>
  4084. ** <dd>The SQLITE_PREPARE_NORMALIZE flag is a no-op. This flag used
  4085. ** to be required for any prepared statement that wanted to use the
  4086. ** [sqlite3_normalized_sql()] interface. However, the
  4087. ** [sqlite3_normalized_sql()] interface is now available to all
  4088. ** prepared statements, regardless of whether or not they use this
  4089. ** flag.
  4090. **
  4091. ** [[SQLITE_PREPARE_NO_VTAB]] <dt>SQLITE_PREPARE_NO_VTAB</dt>
  4092. ** <dd>The SQLITE_PREPARE_NO_VTAB flag causes the SQL compiler
  4093. ** to return an error (error code SQLITE_ERROR) if the statement uses
  4094. ** any virtual tables.
  4095. ** </dl>
  4096. */
  4097. #define SQLITE_PREPARE_PERSISTENT 0x01
  4098. #define SQLITE_PREPARE_NORMALIZE 0x02
  4099. #define SQLITE_PREPARE_NO_VTAB 0x04
  4100. /*
  4101. ** CAPI3REF: Compiling An SQL Statement
  4102. ** KEYWORDS: {SQL statement compiler}
  4103. ** METHOD: sqlite3
  4104. ** CONSTRUCTOR: sqlite3_stmt
  4105. **
  4106. ** To execute an SQL statement, it must first be compiled into a byte-code
  4107. ** program using one of these routines. Or, in other words, these routines
  4108. ** are constructors for the [prepared statement] object.
  4109. **
  4110. ** The preferred routine to use is [sqlite3_prepare_v2()]. The
  4111. ** [sqlite3_prepare()] interface is legacy and should be avoided.
  4112. ** [sqlite3_prepare_v3()] has an extra "prepFlags" option that is used
  4113. ** for special purposes.
  4114. **
  4115. ** The use of the UTF-8 interfaces is preferred, as SQLite currently
  4116. ** does all parsing using UTF-8. The UTF-16 interfaces are provided
  4117. ** as a convenience. The UTF-16 interfaces work by converting the
  4118. ** input text into UTF-8, then invoking the corresponding UTF-8 interface.
  4119. **
  4120. ** The first argument, "db", is a [database connection] obtained from a
  4121. ** prior successful call to [sqlite3_open()], [sqlite3_open_v2()] or
  4122. ** [sqlite3_open16()]. The database connection must not have been closed.
  4123. **
  4124. ** The second argument, "zSql", is the statement to be compiled, encoded
  4125. ** as either UTF-8 or UTF-16. The sqlite3_prepare(), sqlite3_prepare_v2(),
  4126. ** and sqlite3_prepare_v3()
  4127. ** interfaces use UTF-8, and sqlite3_prepare16(), sqlite3_prepare16_v2(),
  4128. ** and sqlite3_prepare16_v3() use UTF-16.
  4129. **
  4130. ** ^If the nByte argument is negative, then zSql is read up to the
  4131. ** first zero terminator. ^If nByte is positive, then it is the
  4132. ** number of bytes read from zSql. ^If nByte is zero, then no prepared
  4133. ** statement is generated.
  4134. ** If the caller knows that the supplied string is nul-terminated, then
  4135. ** there is a small performance advantage to passing an nByte parameter that
  4136. ** is the number of bytes in the input string <i>including</i>
  4137. ** the nul-terminator.
  4138. **
  4139. ** ^If pzTail is not NULL then *pzTail is made to point to the first byte
  4140. ** past the end of the first SQL statement in zSql. These routines only
  4141. ** compile the first statement in zSql, so *pzTail is left pointing to
  4142. ** what remains uncompiled.
  4143. **
  4144. ** ^*ppStmt is left pointing to a compiled [prepared statement] that can be
  4145. ** executed using [sqlite3_step()]. ^If there is an error, *ppStmt is set
  4146. ** to NULL. ^If the input text contains no SQL (if the input is an empty
  4147. ** string or a comment) then *ppStmt is set to NULL.
  4148. ** The calling procedure is responsible for deleting the compiled
  4149. ** SQL statement using [sqlite3_finalize()] after it has finished with it.
  4150. ** ppStmt may not be NULL.
  4151. **
  4152. ** ^On success, the sqlite3_prepare() family of routines return [SQLITE_OK];
  4153. ** otherwise an [error code] is returned.
  4154. **
  4155. ** The sqlite3_prepare_v2(), sqlite3_prepare_v3(), sqlite3_prepare16_v2(),
  4156. ** and sqlite3_prepare16_v3() interfaces are recommended for all new programs.
  4157. ** The older interfaces (sqlite3_prepare() and sqlite3_prepare16())
  4158. ** are retained for backwards compatibility, but their use is discouraged.
  4159. ** ^In the "vX" interfaces, the prepared statement
  4160. ** that is returned (the [sqlite3_stmt] object) contains a copy of the
  4161. ** original SQL text. This causes the [sqlite3_step()] interface to
  4162. ** behave differently in three ways:
  4163. **
  4164. ** <ol>
  4165. ** <li>
  4166. ** ^If the database schema changes, instead of returning [SQLITE_SCHEMA] as it
  4167. ** always used to do, [sqlite3_step()] will automatically recompile the SQL
  4168. ** statement and try to run it again. As many as [SQLITE_MAX_SCHEMA_RETRY]
  4169. ** retries will occur before sqlite3_step() gives up and returns an error.
  4170. ** </li>
  4171. **
  4172. ** <li>
  4173. ** ^When an error occurs, [sqlite3_step()] will return one of the detailed
  4174. ** [error codes] or [extended error codes]. ^The legacy behavior was that
  4175. ** [sqlite3_step()] would only return a generic [SQLITE_ERROR] result code
  4176. ** and the application would have to make a second call to [sqlite3_reset()]
  4177. ** in order to find the underlying cause of the problem. With the "v2" prepare
  4178. ** interfaces, the underlying reason for the error is returned immediately.
  4179. ** </li>
  4180. **
  4181. ** <li>
  4182. ** ^If the specific value bound to a [parameter | host parameter] in the
  4183. ** WHERE clause might influence the choice of query plan for a statement,
  4184. ** then the statement will be automatically recompiled, as if there had been
  4185. ** a schema change, on the first [sqlite3_step()] call following any change
  4186. ** to the [sqlite3_bind_text | bindings] of that [parameter].
  4187. ** ^The specific value of a WHERE-clause [parameter] might influence the
  4188. ** choice of query plan if the parameter is the left-hand side of a [LIKE]
  4189. ** or [GLOB] operator or if the parameter is compared to an indexed column
  4190. ** and the [SQLITE_ENABLE_STAT4] compile-time option is enabled.
  4191. ** </li>
  4192. ** </ol>
  4193. **
  4194. ** <p>^sqlite3_prepare_v3() differs from sqlite3_prepare_v2() only in having
  4195. ** the extra prepFlags parameter, which is a bit array consisting of zero or
  4196. ** more of the [SQLITE_PREPARE_PERSISTENT|SQLITE_PREPARE_*] flags. ^The
  4197. ** sqlite3_prepare_v2() interface works exactly the same as
  4198. ** sqlite3_prepare_v3() with a zero prepFlags parameter.
  4199. */
  4200. SQLITE_API int sqlite3_prepare(
  4201. sqlite3 *db, /* Database handle */
  4202. const char *zSql, /* SQL statement, UTF-8 encoded */
  4203. int nByte, /* Maximum length of zSql in bytes. */
  4204. sqlite3_stmt **ppStmt, /* OUT: Statement handle */
  4205. const char **pzTail /* OUT: Pointer to unused portion of zSql */
  4206. );
  4207. SQLITE_API int sqlite3_prepare_v2(
  4208. sqlite3 *db, /* Database handle */
  4209. const char *zSql, /* SQL statement, UTF-8 encoded */
  4210. int nByte, /* Maximum length of zSql in bytes. */
  4211. sqlite3_stmt **ppStmt, /* OUT: Statement handle */
  4212. const char **pzTail /* OUT: Pointer to unused portion of zSql */
  4213. );
  4214. SQLITE_API int sqlite3_prepare_v3(
  4215. sqlite3 *db, /* Database handle */
  4216. const char *zSql, /* SQL statement, UTF-8 encoded */
  4217. int nByte, /* Maximum length of zSql in bytes. */
  4218. unsigned int prepFlags, /* Zero or more SQLITE_PREPARE_ flags */
  4219. sqlite3_stmt **ppStmt, /* OUT: Statement handle */
  4220. const char **pzTail /* OUT: Pointer to unused portion of zSql */
  4221. );
  4222. SQLITE_API int sqlite3_prepare16(
  4223. sqlite3 *db, /* Database handle */
  4224. const void *zSql, /* SQL statement, UTF-16 encoded */
  4225. int nByte, /* Maximum length of zSql in bytes. */
  4226. sqlite3_stmt **ppStmt, /* OUT: Statement handle */
  4227. const void **pzTail /* OUT: Pointer to unused portion of zSql */
  4228. );
  4229. SQLITE_API int sqlite3_prepare16_v2(
  4230. sqlite3 *db, /* Database handle */
  4231. const void *zSql, /* SQL statement, UTF-16 encoded */
  4232. int nByte, /* Maximum length of zSql in bytes. */
  4233. sqlite3_stmt **ppStmt, /* OUT: Statement handle */
  4234. const void **pzTail /* OUT: Pointer to unused portion of zSql */
  4235. );
  4236. SQLITE_API int sqlite3_prepare16_v3(
  4237. sqlite3 *db, /* Database handle */
  4238. const void *zSql, /* SQL statement, UTF-16 encoded */
  4239. int nByte, /* Maximum length of zSql in bytes. */
  4240. unsigned int prepFlags, /* Zero or more SQLITE_PREPARE_ flags */
  4241. sqlite3_stmt **ppStmt, /* OUT: Statement handle */
  4242. const void **pzTail /* OUT: Pointer to unused portion of zSql */
  4243. );
  4244. /*
  4245. ** CAPI3REF: Retrieving Statement SQL
  4246. ** METHOD: sqlite3_stmt
  4247. **
  4248. ** ^The sqlite3_sql(P) interface returns a pointer to a copy of the UTF-8
  4249. ** SQL text used to create [prepared statement] P if P was
  4250. ** created by [sqlite3_prepare_v2()], [sqlite3_prepare_v3()],
  4251. ** [sqlite3_prepare16_v2()], or [sqlite3_prepare16_v3()].
  4252. ** ^The sqlite3_expanded_sql(P) interface returns a pointer to a UTF-8
  4253. ** string containing the SQL text of prepared statement P with
  4254. ** [bound parameters] expanded.
  4255. ** ^The sqlite3_normalized_sql(P) interface returns a pointer to a UTF-8
  4256. ** string containing the normalized SQL text of prepared statement P. The
  4257. ** semantics used to normalize a SQL statement are unspecified and subject
  4258. ** to change. At a minimum, literal values will be replaced with suitable
  4259. ** placeholders.
  4260. **
  4261. ** ^(For example, if a prepared statement is created using the SQL
  4262. ** text "SELECT $abc,:xyz" and if parameter $abc is bound to integer 2345
  4263. ** and parameter :xyz is unbound, then sqlite3_sql() will return
  4264. ** the original string, "SELECT $abc,:xyz" but sqlite3_expanded_sql()
  4265. ** will return "SELECT 2345,NULL".)^
  4266. **
  4267. ** ^The sqlite3_expanded_sql() interface returns NULL if insufficient memory
  4268. ** is available to hold the result, or if the result would exceed the
  4269. ** the maximum string length determined by the [SQLITE_LIMIT_LENGTH].
  4270. **
  4271. ** ^The [SQLITE_TRACE_SIZE_LIMIT] compile-time option limits the size of
  4272. ** bound parameter expansions. ^The [SQLITE_OMIT_TRACE] compile-time
  4273. ** option causes sqlite3_expanded_sql() to always return NULL.
  4274. **
  4275. ** ^The strings returned by sqlite3_sql(P) and sqlite3_normalized_sql(P)
  4276. ** are managed by SQLite and are automatically freed when the prepared
  4277. ** statement is finalized.
  4278. ** ^The string returned by sqlite3_expanded_sql(P), on the other hand,
  4279. ** is obtained from [sqlite3_malloc()] and must be freed by the application
  4280. ** by passing it to [sqlite3_free()].
  4281. **
  4282. ** ^The sqlite3_normalized_sql() interface is only available if
  4283. ** the [SQLITE_ENABLE_NORMALIZE] compile-time option is defined.
  4284. */
  4285. SQLITE_API const char *sqlite3_sql(sqlite3_stmt *pStmt);
  4286. SQLITE_API char *sqlite3_expanded_sql(sqlite3_stmt *pStmt);
  4287. #ifdef SQLITE_ENABLE_NORMALIZE
  4288. SQLITE_API const char *sqlite3_normalized_sql(sqlite3_stmt *pStmt);
  4289. #endif
  4290. /*
  4291. ** CAPI3REF: Determine If An SQL Statement Writes The Database
  4292. ** METHOD: sqlite3_stmt
  4293. **
  4294. ** ^The sqlite3_stmt_readonly(X) interface returns true (non-zero) if
  4295. ** and only if the [prepared statement] X makes no direct changes to
  4296. ** the content of the database file.
  4297. **
  4298. ** Note that [application-defined SQL functions] or
  4299. ** [virtual tables] might change the database indirectly as a side effect.
  4300. ** ^(For example, if an application defines a function "eval()" that
  4301. ** calls [sqlite3_exec()], then the following SQL statement would
  4302. ** change the database file through side-effects:
  4303. **
  4304. ** <blockquote><pre>
  4305. ** SELECT eval('DELETE FROM t1') FROM t2;
  4306. ** </pre></blockquote>
  4307. **
  4308. ** But because the [SELECT] statement does not change the database file
  4309. ** directly, sqlite3_stmt_readonly() would still return true.)^
  4310. **
  4311. ** ^Transaction control statements such as [BEGIN], [COMMIT], [ROLLBACK],
  4312. ** [SAVEPOINT], and [RELEASE] cause sqlite3_stmt_readonly() to return true,
  4313. ** since the statements themselves do not actually modify the database but
  4314. ** rather they control the timing of when other statements modify the
  4315. ** database. ^The [ATTACH] and [DETACH] statements also cause
  4316. ** sqlite3_stmt_readonly() to return true since, while those statements
  4317. ** change the configuration of a database connection, they do not make
  4318. ** changes to the content of the database files on disk.
  4319. ** ^The sqlite3_stmt_readonly() interface returns true for [BEGIN] since
  4320. ** [BEGIN] merely sets internal flags, but the [BEGIN|BEGIN IMMEDIATE] and
  4321. ** [BEGIN|BEGIN EXCLUSIVE] commands do touch the database and so
  4322. ** sqlite3_stmt_readonly() returns false for those commands.
  4323. **
  4324. ** ^This routine returns false if there is any possibility that the
  4325. ** statement might change the database file. ^A false return does
  4326. ** not guarantee that the statement will change the database file.
  4327. ** ^For example, an UPDATE statement might have a WHERE clause that
  4328. ** makes it a no-op, but the sqlite3_stmt_readonly() result would still
  4329. ** be false. ^Similarly, a CREATE TABLE IF NOT EXISTS statement is a
  4330. ** read-only no-op if the table already exists, but
  4331. ** sqlite3_stmt_readonly() still returns false for such a statement.
  4332. **
  4333. ** ^If prepared statement X is an [EXPLAIN] or [EXPLAIN QUERY PLAN]
  4334. ** statement, then sqlite3_stmt_readonly(X) returns the same value as
  4335. ** if the EXPLAIN or EXPLAIN QUERY PLAN prefix were omitted.
  4336. */
  4337. SQLITE_API int sqlite3_stmt_readonly(sqlite3_stmt *pStmt);
  4338. /*
  4339. ** CAPI3REF: Query The EXPLAIN Setting For A Prepared Statement
  4340. ** METHOD: sqlite3_stmt
  4341. **
  4342. ** ^The sqlite3_stmt_isexplain(S) interface returns 1 if the
  4343. ** prepared statement S is an EXPLAIN statement, or 2 if the
  4344. ** statement S is an EXPLAIN QUERY PLAN.
  4345. ** ^The sqlite3_stmt_isexplain(S) interface returns 0 if S is
  4346. ** an ordinary statement or a NULL pointer.
  4347. */
  4348. SQLITE_API int sqlite3_stmt_isexplain(sqlite3_stmt *pStmt);
  4349. /*
  4350. ** CAPI3REF: Change The EXPLAIN Setting For A Prepared Statement
  4351. ** METHOD: sqlite3_stmt
  4352. **
  4353. ** The sqlite3_stmt_explain(S,E) interface changes the EXPLAIN
  4354. ** setting for [prepared statement] S. If E is zero, then S becomes
  4355. ** a normal prepared statement. If E is 1, then S behaves as if
  4356. ** its SQL text began with "[EXPLAIN]". If E is 2, then S behaves as if
  4357. ** its SQL text began with "[EXPLAIN QUERY PLAN]".
  4358. **
  4359. ** Calling sqlite3_stmt_explain(S,E) might cause S to be reprepared.
  4360. ** SQLite tries to avoid a reprepare, but a reprepare might be necessary
  4361. ** on the first transition into EXPLAIN or EXPLAIN QUERY PLAN mode.
  4362. **
  4363. ** Because of the potential need to reprepare, a call to
  4364. ** sqlite3_stmt_explain(S,E) will fail with SQLITE_ERROR if S cannot be
  4365. ** reprepared because it was created using [sqlite3_prepare()] instead of
  4366. ** the newer [sqlite3_prepare_v2()] or [sqlite3_prepare_v3()] interfaces and
  4367. ** hence has no saved SQL text with which to reprepare.
  4368. **
  4369. ** Changing the explain setting for a prepared statement does not change
  4370. ** the original SQL text for the statement. Hence, if the SQL text originally
  4371. ** began with EXPLAIN or EXPLAIN QUERY PLAN, but sqlite3_stmt_explain(S,0)
  4372. ** is called to convert the statement into an ordinary statement, the EXPLAIN
  4373. ** or EXPLAIN QUERY PLAN keywords will still appear in the sqlite3_sql(S)
  4374. ** output, even though the statement now acts like a normal SQL statement.
  4375. **
  4376. ** This routine returns SQLITE_OK if the explain mode is successfully
  4377. ** changed, or an error code if the explain mode could not be changed.
  4378. ** The explain mode cannot be changed while a statement is active.
  4379. ** Hence, it is good practice to call [sqlite3_reset(S)]
  4380. ** immediately prior to calling sqlite3_stmt_explain(S,E).
  4381. */
  4382. SQLITE_API int sqlite3_stmt_explain(sqlite3_stmt *pStmt, int eMode);
  4383. /*
  4384. ** CAPI3REF: Determine If A Prepared Statement Has Been Reset
  4385. ** METHOD: sqlite3_stmt
  4386. **
  4387. ** ^The sqlite3_stmt_busy(S) interface returns true (non-zero) if the
  4388. ** [prepared statement] S has been stepped at least once using
  4389. ** [sqlite3_step(S)] but has neither run to completion (returned
  4390. ** [SQLITE_DONE] from [sqlite3_step(S)]) nor
  4391. ** been reset using [sqlite3_reset(S)]. ^The sqlite3_stmt_busy(S)
  4392. ** interface returns false if S is a NULL pointer. If S is not a
  4393. ** NULL pointer and is not a pointer to a valid [prepared statement]
  4394. ** object, then the behavior is undefined and probably undesirable.
  4395. **
  4396. ** This interface can be used in combination [sqlite3_next_stmt()]
  4397. ** to locate all prepared statements associated with a database
  4398. ** connection that are in need of being reset. This can be used,
  4399. ** for example, in diagnostic routines to search for prepared
  4400. ** statements that are holding a transaction open.
  4401. */
  4402. SQLITE_API int sqlite3_stmt_busy(sqlite3_stmt*);
  4403. /*
  4404. ** CAPI3REF: Dynamically Typed Value Object
  4405. ** KEYWORDS: {protected sqlite3_value} {unprotected sqlite3_value}
  4406. **
  4407. ** SQLite uses the sqlite3_value object to represent all values
  4408. ** that can be stored in a database table. SQLite uses dynamic typing
  4409. ** for the values it stores. ^Values stored in sqlite3_value objects
  4410. ** can be integers, floating point values, strings, BLOBs, or NULL.
  4411. **
  4412. ** An sqlite3_value object may be either "protected" or "unprotected".
  4413. ** Some interfaces require a protected sqlite3_value. Other interfaces
  4414. ** will accept either a protected or an unprotected sqlite3_value.
  4415. ** Every interface that accepts sqlite3_value arguments specifies
  4416. ** whether or not it requires a protected sqlite3_value. The
  4417. ** [sqlite3_value_dup()] interface can be used to construct a new
  4418. ** protected sqlite3_value from an unprotected sqlite3_value.
  4419. **
  4420. ** The terms "protected" and "unprotected" refer to whether or not
  4421. ** a mutex is held. An internal mutex is held for a protected
  4422. ** sqlite3_value object but no mutex is held for an unprotected
  4423. ** sqlite3_value object. If SQLite is compiled to be single-threaded
  4424. ** (with [SQLITE_THREADSAFE=0] and with [sqlite3_threadsafe()] returning 0)
  4425. ** or if SQLite is run in one of reduced mutex modes
  4426. ** [SQLITE_CONFIG_SINGLETHREAD] or [SQLITE_CONFIG_MULTITHREAD]
  4427. ** then there is no distinction between protected and unprotected
  4428. ** sqlite3_value objects and they can be used interchangeably. However,
  4429. ** for maximum code portability it is recommended that applications
  4430. ** still make the distinction between protected and unprotected
  4431. ** sqlite3_value objects even when not strictly required.
  4432. **
  4433. ** ^The sqlite3_value objects that are passed as parameters into the
  4434. ** implementation of [application-defined SQL functions] are protected.
  4435. ** ^The sqlite3_value objects returned by [sqlite3_vtab_rhs_value()]
  4436. ** are protected.
  4437. ** ^The sqlite3_value object returned by
  4438. ** [sqlite3_column_value()] is unprotected.
  4439. ** Unprotected sqlite3_value objects may only be used as arguments
  4440. ** to [sqlite3_result_value()], [sqlite3_bind_value()], and
  4441. ** [sqlite3_value_dup()].
  4442. ** The [sqlite3_value_blob | sqlite3_value_type()] family of
  4443. ** interfaces require protected sqlite3_value objects.
  4444. */
  4445. typedef struct sqlite3_value sqlite3_value;
  4446. /*
  4447. ** CAPI3REF: SQL Function Context Object
  4448. **
  4449. ** The context in which an SQL function executes is stored in an
  4450. ** sqlite3_context object. ^A pointer to an sqlite3_context object
  4451. ** is always first parameter to [application-defined SQL functions].
  4452. ** The application-defined SQL function implementation will pass this
  4453. ** pointer through into calls to [sqlite3_result_int | sqlite3_result()],
  4454. ** [sqlite3_aggregate_context()], [sqlite3_user_data()],
  4455. ** [sqlite3_context_db_handle()], [sqlite3_get_auxdata()],
  4456. ** and/or [sqlite3_set_auxdata()].
  4457. */
  4458. typedef struct sqlite3_context sqlite3_context;
  4459. /*
  4460. ** CAPI3REF: Binding Values To Prepared Statements
  4461. ** KEYWORDS: {host parameter} {host parameters} {host parameter name}
  4462. ** KEYWORDS: {SQL parameter} {SQL parameters} {parameter binding}
  4463. ** METHOD: sqlite3_stmt
  4464. **
  4465. ** ^(In the SQL statement text input to [sqlite3_prepare_v2()] and its variants,
  4466. ** literals may be replaced by a [parameter] that matches one of following
  4467. ** templates:
  4468. **
  4469. ** <ul>
  4470. ** <li> ?
  4471. ** <li> ?NNN
  4472. ** <li> :VVV
  4473. ** <li> @VVV
  4474. ** <li> $VVV
  4475. ** </ul>
  4476. **
  4477. ** In the templates above, NNN represents an integer literal,
  4478. ** and VVV represents an alphanumeric identifier.)^ ^The values of these
  4479. ** parameters (also called "host parameter names" or "SQL parameters")
  4480. ** can be set using the sqlite3_bind_*() routines defined here.
  4481. **
  4482. ** ^The first argument to the sqlite3_bind_*() routines is always
  4483. ** a pointer to the [sqlite3_stmt] object returned from
  4484. ** [sqlite3_prepare_v2()] or its variants.
  4485. **
  4486. ** ^The second argument is the index of the SQL parameter to be set.
  4487. ** ^The leftmost SQL parameter has an index of 1. ^When the same named
  4488. ** SQL parameter is used more than once, second and subsequent
  4489. ** occurrences have the same index as the first occurrence.
  4490. ** ^The index for named parameters can be looked up using the
  4491. ** [sqlite3_bind_parameter_index()] API if desired. ^The index
  4492. ** for "?NNN" parameters is the value of NNN.
  4493. ** ^The NNN value must be between 1 and the [sqlite3_limit()]
  4494. ** parameter [SQLITE_LIMIT_VARIABLE_NUMBER] (default value: 32766).
  4495. **
  4496. ** ^The third argument is the value to bind to the parameter.
  4497. ** ^If the third parameter to sqlite3_bind_text() or sqlite3_bind_text16()
  4498. ** or sqlite3_bind_blob() is a NULL pointer then the fourth parameter
  4499. ** is ignored and the end result is the same as sqlite3_bind_null().
  4500. ** ^If the third parameter to sqlite3_bind_text() is not NULL, then
  4501. ** it should be a pointer to well-formed UTF8 text.
  4502. ** ^If the third parameter to sqlite3_bind_text16() is not NULL, then
  4503. ** it should be a pointer to well-formed UTF16 text.
  4504. ** ^If the third parameter to sqlite3_bind_text64() is not NULL, then
  4505. ** it should be a pointer to a well-formed unicode string that is
  4506. ** either UTF8 if the sixth parameter is SQLITE_UTF8, or UTF16
  4507. ** otherwise.
  4508. **
  4509. ** [[byte-order determination rules]] ^The byte-order of
  4510. ** UTF16 input text is determined by the byte-order mark (BOM, U+FEFF)
  4511. ** found in first character, which is removed, or in the absence of a BOM
  4512. ** the byte order is the native byte order of the host
  4513. ** machine for sqlite3_bind_text16() or the byte order specified in
  4514. ** the 6th parameter for sqlite3_bind_text64().)^
  4515. ** ^If UTF16 input text contains invalid unicode
  4516. ** characters, then SQLite might change those invalid characters
  4517. ** into the unicode replacement character: U+FFFD.
  4518. **
  4519. ** ^(In those routines that have a fourth argument, its value is the
  4520. ** number of bytes in the parameter. To be clear: the value is the
  4521. ** number of <u>bytes</u> in the value, not the number of characters.)^
  4522. ** ^If the fourth parameter to sqlite3_bind_text() or sqlite3_bind_text16()
  4523. ** is negative, then the length of the string is
  4524. ** the number of bytes up to the first zero terminator.
  4525. ** If the fourth parameter to sqlite3_bind_blob() is negative, then
  4526. ** the behavior is undefined.
  4527. ** If a non-negative fourth parameter is provided to sqlite3_bind_text()
  4528. ** or sqlite3_bind_text16() or sqlite3_bind_text64() then
  4529. ** that parameter must be the byte offset
  4530. ** where the NUL terminator would occur assuming the string were NUL
  4531. ** terminated. If any NUL characters occurs at byte offsets less than
  4532. ** the value of the fourth parameter then the resulting string value will
  4533. ** contain embedded NULs. The result of expressions involving strings
  4534. ** with embedded NULs is undefined.
  4535. **
  4536. ** ^The fifth argument to the BLOB and string binding interfaces controls
  4537. ** or indicates the lifetime of the object referenced by the third parameter.
  4538. ** These three options exist:
  4539. ** ^ (1) A destructor to dispose of the BLOB or string after SQLite has finished
  4540. ** with it may be passed. ^It is called to dispose of the BLOB or string even
  4541. ** if the call to the bind API fails, except the destructor is not called if
  4542. ** the third parameter is a NULL pointer or the fourth parameter is negative.
  4543. ** ^ (2) The special constant, [SQLITE_STATIC], may be passed to indicate that
  4544. ** the application remains responsible for disposing of the object. ^In this
  4545. ** case, the object and the provided pointer to it must remain valid until
  4546. ** either the prepared statement is finalized or the same SQL parameter is
  4547. ** bound to something else, whichever occurs sooner.
  4548. ** ^ (3) The constant, [SQLITE_TRANSIENT], may be passed to indicate that the
  4549. ** object is to be copied prior to the return from sqlite3_bind_*(). ^The
  4550. ** object and pointer to it must remain valid until then. ^SQLite will then
  4551. ** manage the lifetime of its private copy.
  4552. **
  4553. ** ^The sixth argument to sqlite3_bind_text64() must be one of
  4554. ** [SQLITE_UTF8], [SQLITE_UTF16], [SQLITE_UTF16BE], or [SQLITE_UTF16LE]
  4555. ** to specify the encoding of the text in the third parameter. If
  4556. ** the sixth argument to sqlite3_bind_text64() is not one of the
  4557. ** allowed values shown above, or if the text encoding is different
  4558. ** from the encoding specified by the sixth parameter, then the behavior
  4559. ** is undefined.
  4560. **
  4561. ** ^The sqlite3_bind_zeroblob() routine binds a BLOB of length N that
  4562. ** is filled with zeroes. ^A zeroblob uses a fixed amount of memory
  4563. ** (just an integer to hold its size) while it is being processed.
  4564. ** Zeroblobs are intended to serve as placeholders for BLOBs whose
  4565. ** content is later written using
  4566. ** [sqlite3_blob_open | incremental BLOB I/O] routines.
  4567. ** ^A negative value for the zeroblob results in a zero-length BLOB.
  4568. **
  4569. ** ^The sqlite3_bind_pointer(S,I,P,T,D) routine causes the I-th parameter in
  4570. ** [prepared statement] S to have an SQL value of NULL, but to also be
  4571. ** associated with the pointer P of type T. ^D is either a NULL pointer or
  4572. ** a pointer to a destructor function for P. ^SQLite will invoke the
  4573. ** destructor D with a single argument of P when it is finished using
  4574. ** P. The T parameter should be a static string, preferably a string
  4575. ** literal. The sqlite3_bind_pointer() routine is part of the
  4576. ** [pointer passing interface] added for SQLite 3.20.0.
  4577. **
  4578. ** ^If any of the sqlite3_bind_*() routines are called with a NULL pointer
  4579. ** for the [prepared statement] or with a prepared statement for which
  4580. ** [sqlite3_step()] has been called more recently than [sqlite3_reset()],
  4581. ** then the call will return [SQLITE_MISUSE]. If any sqlite3_bind_()
  4582. ** routine is passed a [prepared statement] that has been finalized, the
  4583. ** result is undefined and probably harmful.
  4584. **
  4585. ** ^Bindings are not cleared by the [sqlite3_reset()] routine.
  4586. ** ^Unbound parameters are interpreted as NULL.
  4587. **
  4588. ** ^The sqlite3_bind_* routines return [SQLITE_OK] on success or an
  4589. ** [error code] if anything goes wrong.
  4590. ** ^[SQLITE_TOOBIG] might be returned if the size of a string or BLOB
  4591. ** exceeds limits imposed by [sqlite3_limit]([SQLITE_LIMIT_LENGTH]) or
  4592. ** [SQLITE_MAX_LENGTH].
  4593. ** ^[SQLITE_RANGE] is returned if the parameter
  4594. ** index is out of range. ^[SQLITE_NOMEM] is returned if malloc() fails.
  4595. **
  4596. ** See also: [sqlite3_bind_parameter_count()],
  4597. ** [sqlite3_bind_parameter_name()], and [sqlite3_bind_parameter_index()].
  4598. */
  4599. SQLITE_API int sqlite3_bind_blob(sqlite3_stmt*, int, const void*, int n, void(*)(void*));
  4600. SQLITE_API int sqlite3_bind_blob64(sqlite3_stmt*, int, const void*, sqlite3_uint64,
  4601. void(*)(void*));
  4602. SQLITE_API int sqlite3_bind_double(sqlite3_stmt*, int, double);
  4603. SQLITE_API int sqlite3_bind_int(sqlite3_stmt*, int, int);
  4604. SQLITE_API int sqlite3_bind_int64(sqlite3_stmt*, int, sqlite3_int64);
  4605. SQLITE_API int sqlite3_bind_null(sqlite3_stmt*, int);
  4606. SQLITE_API int sqlite3_bind_text(sqlite3_stmt*,int,const char*,int,void(*)(void*));
  4607. SQLITE_API int sqlite3_bind_text16(sqlite3_stmt*, int, const void*, int, void(*)(void*));
  4608. SQLITE_API int sqlite3_bind_text64(sqlite3_stmt*, int, const char*, sqlite3_uint64,
  4609. void(*)(void*), unsigned char encoding);
  4610. SQLITE_API int sqlite3_bind_value(sqlite3_stmt*, int, const sqlite3_value*);
  4611. SQLITE_API int sqlite3_bind_pointer(sqlite3_stmt*, int, void*, const char*,void(*)(void*));
  4612. SQLITE_API int sqlite3_bind_zeroblob(sqlite3_stmt*, int, int n);
  4613. SQLITE_API int sqlite3_bind_zeroblob64(sqlite3_stmt*, int, sqlite3_uint64);
  4614. /*
  4615. ** CAPI3REF: Number Of SQL Parameters
  4616. ** METHOD: sqlite3_stmt
  4617. **
  4618. ** ^This routine can be used to find the number of [SQL parameters]
  4619. ** in a [prepared statement]. SQL parameters are tokens of the
  4620. ** form "?", "?NNN", ":AAA", "$AAA", or "@AAA" that serve as
  4621. ** placeholders for values that are [sqlite3_bind_blob | bound]
  4622. ** to the parameters at a later time.
  4623. **
  4624. ** ^(This routine actually returns the index of the largest (rightmost)
  4625. ** parameter. For all forms except ?NNN, this will correspond to the
  4626. ** number of unique parameters. If parameters of the ?NNN form are used,
  4627. ** there may be gaps in the list.)^
  4628. **
  4629. ** See also: [sqlite3_bind_blob|sqlite3_bind()],
  4630. ** [sqlite3_bind_parameter_name()], and
  4631. ** [sqlite3_bind_parameter_index()].
  4632. */
  4633. SQLITE_API int sqlite3_bind_parameter_count(sqlite3_stmt*);
  4634. /*
  4635. ** CAPI3REF: Name Of A Host Parameter
  4636. ** METHOD: sqlite3_stmt
  4637. **
  4638. ** ^The sqlite3_bind_parameter_name(P,N) interface returns
  4639. ** the name of the N-th [SQL parameter] in the [prepared statement] P.
  4640. ** ^(SQL parameters of the form "?NNN" or ":AAA" or "@AAA" or "$AAA"
  4641. ** have a name which is the string "?NNN" or ":AAA" or "@AAA" or "$AAA"
  4642. ** respectively.
  4643. ** In other words, the initial ":" or "$" or "@" or "?"
  4644. ** is included as part of the name.)^
  4645. ** ^Parameters of the form "?" without a following integer have no name
  4646. ** and are referred to as "nameless" or "anonymous parameters".
  4647. **
  4648. ** ^The first host parameter has an index of 1, not 0.
  4649. **
  4650. ** ^If the value N is out of range or if the N-th parameter is
  4651. ** nameless, then NULL is returned. ^The returned string is
  4652. ** always in UTF-8 encoding even if the named parameter was
  4653. ** originally specified as UTF-16 in [sqlite3_prepare16()],
  4654. ** [sqlite3_prepare16_v2()], or [sqlite3_prepare16_v3()].
  4655. **
  4656. ** See also: [sqlite3_bind_blob|sqlite3_bind()],
  4657. ** [sqlite3_bind_parameter_count()], and
  4658. ** [sqlite3_bind_parameter_index()].
  4659. */
  4660. SQLITE_API const char *sqlite3_bind_parameter_name(sqlite3_stmt*, int);
  4661. /*
  4662. ** CAPI3REF: Index Of A Parameter With A Given Name
  4663. ** METHOD: sqlite3_stmt
  4664. **
  4665. ** ^Return the index of an SQL parameter given its name. ^The
  4666. ** index value returned is suitable for use as the second
  4667. ** parameter to [sqlite3_bind_blob|sqlite3_bind()]. ^A zero
  4668. ** is returned if no matching parameter is found. ^The parameter
  4669. ** name must be given in UTF-8 even if the original statement
  4670. ** was prepared from UTF-16 text using [sqlite3_prepare16_v2()] or
  4671. ** [sqlite3_prepare16_v3()].
  4672. **
  4673. ** See also: [sqlite3_bind_blob|sqlite3_bind()],
  4674. ** [sqlite3_bind_parameter_count()], and
  4675. ** [sqlite3_bind_parameter_name()].
  4676. */
  4677. SQLITE_API int sqlite3_bind_parameter_index(sqlite3_stmt*, const char *zName);
  4678. /*
  4679. ** CAPI3REF: Reset All Bindings On A Prepared Statement
  4680. ** METHOD: sqlite3_stmt
  4681. **
  4682. ** ^Contrary to the intuition of many, [sqlite3_reset()] does not reset
  4683. ** the [sqlite3_bind_blob | bindings] on a [prepared statement].
  4684. ** ^Use this routine to reset all host parameters to NULL.
  4685. */
  4686. SQLITE_API int sqlite3_clear_bindings(sqlite3_stmt*);
  4687. /*
  4688. ** CAPI3REF: Number Of Columns In A Result Set
  4689. ** METHOD: sqlite3_stmt
  4690. **
  4691. ** ^Return the number of columns in the result set returned by the
  4692. ** [prepared statement]. ^If this routine returns 0, that means the
  4693. ** [prepared statement] returns no data (for example an [UPDATE]).
  4694. ** ^However, just because this routine returns a positive number does not
  4695. ** mean that one or more rows of data will be returned. ^A SELECT statement
  4696. ** will always have a positive sqlite3_column_count() but depending on the
  4697. ** WHERE clause constraints and the table content, it might return no rows.
  4698. **
  4699. ** See also: [sqlite3_data_count()]
  4700. */
  4701. SQLITE_API int sqlite3_column_count(sqlite3_stmt *pStmt);
  4702. /*
  4703. ** CAPI3REF: Column Names In A Result Set
  4704. ** METHOD: sqlite3_stmt
  4705. **
  4706. ** ^These routines return the name assigned to a particular column
  4707. ** in the result set of a [SELECT] statement. ^The sqlite3_column_name()
  4708. ** interface returns a pointer to a zero-terminated UTF-8 string
  4709. ** and sqlite3_column_name16() returns a pointer to a zero-terminated
  4710. ** UTF-16 string. ^The first parameter is the [prepared statement]
  4711. ** that implements the [SELECT] statement. ^The second parameter is the
  4712. ** column number. ^The leftmost column is number 0.
  4713. **
  4714. ** ^The returned string pointer is valid until either the [prepared statement]
  4715. ** is destroyed by [sqlite3_finalize()] or until the statement is automatically
  4716. ** reprepared by the first call to [sqlite3_step()] for a particular run
  4717. ** or until the next call to
  4718. ** sqlite3_column_name() or sqlite3_column_name16() on the same column.
  4719. **
  4720. ** ^If sqlite3_malloc() fails during the processing of either routine
  4721. ** (for example during a conversion from UTF-8 to UTF-16) then a
  4722. ** NULL pointer is returned.
  4723. **
  4724. ** ^The name of a result column is the value of the "AS" clause for
  4725. ** that column, if there is an AS clause. If there is no AS clause
  4726. ** then the name of the column is unspecified and may change from
  4727. ** one release of SQLite to the next.
  4728. */
  4729. SQLITE_API const char *sqlite3_column_name(sqlite3_stmt*, int N);
  4730. SQLITE_API const void *sqlite3_column_name16(sqlite3_stmt*, int N);
  4731. /*
  4732. ** CAPI3REF: Source Of Data In A Query Result
  4733. ** METHOD: sqlite3_stmt
  4734. **
  4735. ** ^These routines provide a means to determine the database, table, and
  4736. ** table column that is the origin of a particular result column in
  4737. ** [SELECT] statement.
  4738. ** ^The name of the database or table or column can be returned as
  4739. ** either a UTF-8 or UTF-16 string. ^The _database_ routines return
  4740. ** the database name, the _table_ routines return the table name, and
  4741. ** the origin_ routines return the column name.
  4742. ** ^The returned string is valid until the [prepared statement] is destroyed
  4743. ** using [sqlite3_finalize()] or until the statement is automatically
  4744. ** reprepared by the first call to [sqlite3_step()] for a particular run
  4745. ** or until the same information is requested
  4746. ** again in a different encoding.
  4747. **
  4748. ** ^The names returned are the original un-aliased names of the
  4749. ** database, table, and column.
  4750. **
  4751. ** ^The first argument to these interfaces is a [prepared statement].
  4752. ** ^These functions return information about the Nth result column returned by
  4753. ** the statement, where N is the second function argument.
  4754. ** ^The left-most column is column 0 for these routines.
  4755. **
  4756. ** ^If the Nth column returned by the statement is an expression or
  4757. ** subquery and is not a column value, then all of these functions return
  4758. ** NULL. ^These routines might also return NULL if a memory allocation error
  4759. ** occurs. ^Otherwise, they return the name of the attached database, table,
  4760. ** or column that query result column was extracted from.
  4761. **
  4762. ** ^As with all other SQLite APIs, those whose names end with "16" return
  4763. ** UTF-16 encoded strings and the other functions return UTF-8.
  4764. **
  4765. ** ^These APIs are only available if the library was compiled with the
  4766. ** [SQLITE_ENABLE_COLUMN_METADATA] C-preprocessor symbol.
  4767. **
  4768. ** If two or more threads call one or more
  4769. ** [sqlite3_column_database_name | column metadata interfaces]
  4770. ** for the same [prepared statement] and result column
  4771. ** at the same time then the results are undefined.
  4772. */
  4773. SQLITE_API const char *sqlite3_column_database_name(sqlite3_stmt*,int);
  4774. SQLITE_API const void *sqlite3_column_database_name16(sqlite3_stmt*,int);
  4775. SQLITE_API const char *sqlite3_column_table_name(sqlite3_stmt*,int);
  4776. SQLITE_API const void *sqlite3_column_table_name16(sqlite3_stmt*,int);
  4777. SQLITE_API const char *sqlite3_column_origin_name(sqlite3_stmt*,int);
  4778. SQLITE_API const void *sqlite3_column_origin_name16(sqlite3_stmt*,int);
  4779. /*
  4780. ** CAPI3REF: Declared Datatype Of A Query Result
  4781. ** METHOD: sqlite3_stmt
  4782. **
  4783. ** ^(The first parameter is a [prepared statement].
  4784. ** If this statement is a [SELECT] statement and the Nth column of the
  4785. ** returned result set of that [SELECT] is a table column (not an
  4786. ** expression or subquery) then the declared type of the table
  4787. ** column is returned.)^ ^If the Nth column of the result set is an
  4788. ** expression or subquery, then a NULL pointer is returned.
  4789. ** ^The returned string is always UTF-8 encoded.
  4790. **
  4791. ** ^(For example, given the database schema:
  4792. **
  4793. ** CREATE TABLE t1(c1 VARIANT);
  4794. **
  4795. ** and the following statement to be compiled:
  4796. **
  4797. ** SELECT c1 + 1, c1 FROM t1;
  4798. **
  4799. ** this routine would return the string "VARIANT" for the second result
  4800. ** column (i==1), and a NULL pointer for the first result column (i==0).)^
  4801. **
  4802. ** ^SQLite uses dynamic run-time typing. ^So just because a column
  4803. ** is declared to contain a particular type does not mean that the
  4804. ** data stored in that column is of the declared type. SQLite is
  4805. ** strongly typed, but the typing is dynamic not static. ^Type
  4806. ** is associated with individual values, not with the containers
  4807. ** used to hold those values.
  4808. */
  4809. SQLITE_API const char *sqlite3_column_decltype(sqlite3_stmt*,int);
  4810. SQLITE_API const void *sqlite3_column_decltype16(sqlite3_stmt*,int);
  4811. /*
  4812. ** CAPI3REF: Evaluate An SQL Statement
  4813. ** METHOD: sqlite3_stmt
  4814. **
  4815. ** After a [prepared statement] has been prepared using any of
  4816. ** [sqlite3_prepare_v2()], [sqlite3_prepare_v3()], [sqlite3_prepare16_v2()],
  4817. ** or [sqlite3_prepare16_v3()] or one of the legacy
  4818. ** interfaces [sqlite3_prepare()] or [sqlite3_prepare16()], this function
  4819. ** must be called one or more times to evaluate the statement.
  4820. **
  4821. ** The details of the behavior of the sqlite3_step() interface depend
  4822. ** on whether the statement was prepared using the newer "vX" interfaces
  4823. ** [sqlite3_prepare_v3()], [sqlite3_prepare_v2()], [sqlite3_prepare16_v3()],
  4824. ** [sqlite3_prepare16_v2()] or the older legacy
  4825. ** interfaces [sqlite3_prepare()] and [sqlite3_prepare16()]. The use of the
  4826. ** new "vX" interface is recommended for new applications but the legacy
  4827. ** interface will continue to be supported.
  4828. **
  4829. ** ^In the legacy interface, the return value will be either [SQLITE_BUSY],
  4830. ** [SQLITE_DONE], [SQLITE_ROW], [SQLITE_ERROR], or [SQLITE_MISUSE].
  4831. ** ^With the "v2" interface, any of the other [result codes] or
  4832. ** [extended result codes] might be returned as well.
  4833. **
  4834. ** ^[SQLITE_BUSY] means that the database engine was unable to acquire the
  4835. ** database locks it needs to do its job. ^If the statement is a [COMMIT]
  4836. ** or occurs outside of an explicit transaction, then you can retry the
  4837. ** statement. If the statement is not a [COMMIT] and occurs within an
  4838. ** explicit transaction then you should rollback the transaction before
  4839. ** continuing.
  4840. **
  4841. ** ^[SQLITE_DONE] means that the statement has finished executing
  4842. ** successfully. sqlite3_step() should not be called again on this virtual
  4843. ** machine without first calling [sqlite3_reset()] to reset the virtual
  4844. ** machine back to its initial state.
  4845. **
  4846. ** ^If the SQL statement being executed returns any data, then [SQLITE_ROW]
  4847. ** is returned each time a new row of data is ready for processing by the
  4848. ** caller. The values may be accessed using the [column access functions].
  4849. ** sqlite3_step() is called again to retrieve the next row of data.
  4850. **
  4851. ** ^[SQLITE_ERROR] means that a run-time error (such as a constraint
  4852. ** violation) has occurred. sqlite3_step() should not be called again on
  4853. ** the VM. More information may be found by calling [sqlite3_errmsg()].
  4854. ** ^With the legacy interface, a more specific error code (for example,
  4855. ** [SQLITE_INTERRUPT], [SQLITE_SCHEMA], [SQLITE_CORRUPT], and so forth)
  4856. ** can be obtained by calling [sqlite3_reset()] on the
  4857. ** [prepared statement]. ^In the "v2" interface,
  4858. ** the more specific error code is returned directly by sqlite3_step().
  4859. **
  4860. ** [SQLITE_MISUSE] means that the this routine was called inappropriately.
  4861. ** Perhaps it was called on a [prepared statement] that has
  4862. ** already been [sqlite3_finalize | finalized] or on one that had
  4863. ** previously returned [SQLITE_ERROR] or [SQLITE_DONE]. Or it could
  4864. ** be the case that the same database connection is being used by two or
  4865. ** more threads at the same moment in time.
  4866. **
  4867. ** For all versions of SQLite up to and including 3.6.23.1, a call to
  4868. ** [sqlite3_reset()] was required after sqlite3_step() returned anything
  4869. ** other than [SQLITE_ROW] before any subsequent invocation of
  4870. ** sqlite3_step(). Failure to reset the prepared statement using
  4871. ** [sqlite3_reset()] would result in an [SQLITE_MISUSE] return from
  4872. ** sqlite3_step(). But after [version 3.6.23.1] ([dateof:3.6.23.1],
  4873. ** sqlite3_step() began
  4874. ** calling [sqlite3_reset()] automatically in this circumstance rather
  4875. ** than returning [SQLITE_MISUSE]. This is not considered a compatibility
  4876. ** break because any application that ever receives an SQLITE_MISUSE error
  4877. ** is broken by definition. The [SQLITE_OMIT_AUTORESET] compile-time option
  4878. ** can be used to restore the legacy behavior.
  4879. **
  4880. ** <b>Goofy Interface Alert:</b> In the legacy interface, the sqlite3_step()
  4881. ** API always returns a generic error code, [SQLITE_ERROR], following any
  4882. ** error other than [SQLITE_BUSY] and [SQLITE_MISUSE]. You must call
  4883. ** [sqlite3_reset()] or [sqlite3_finalize()] in order to find one of the
  4884. ** specific [error codes] that better describes the error.
  4885. ** We admit that this is a goofy design. The problem has been fixed
  4886. ** with the "v2" interface. If you prepare all of your SQL statements
  4887. ** using [sqlite3_prepare_v3()] or [sqlite3_prepare_v2()]
  4888. ** or [sqlite3_prepare16_v2()] or [sqlite3_prepare16_v3()] instead
  4889. ** of the legacy [sqlite3_prepare()] and [sqlite3_prepare16()] interfaces,
  4890. ** then the more specific [error codes] are returned directly
  4891. ** by sqlite3_step(). The use of the "vX" interfaces is recommended.
  4892. */
  4893. SQLITE_API int sqlite3_step(sqlite3_stmt*);
  4894. /*
  4895. ** CAPI3REF: Number of columns in a result set
  4896. ** METHOD: sqlite3_stmt
  4897. **
  4898. ** ^The sqlite3_data_count(P) interface returns the number of columns in the
  4899. ** current row of the result set of [prepared statement] P.
  4900. ** ^If prepared statement P does not have results ready to return
  4901. ** (via calls to the [sqlite3_column_int | sqlite3_column()] family of
  4902. ** interfaces) then sqlite3_data_count(P) returns 0.
  4903. ** ^The sqlite3_data_count(P) routine also returns 0 if P is a NULL pointer.
  4904. ** ^The sqlite3_data_count(P) routine returns 0 if the previous call to
  4905. ** [sqlite3_step](P) returned [SQLITE_DONE]. ^The sqlite3_data_count(P)
  4906. ** will return non-zero if previous call to [sqlite3_step](P) returned
  4907. ** [SQLITE_ROW], except in the case of the [PRAGMA incremental_vacuum]
  4908. ** where it always returns zero since each step of that multi-step
  4909. ** pragma returns 0 columns of data.
  4910. **
  4911. ** See also: [sqlite3_column_count()]
  4912. */
  4913. SQLITE_API int sqlite3_data_count(sqlite3_stmt *pStmt);
  4914. /*
  4915. ** CAPI3REF: Fundamental Datatypes
  4916. ** KEYWORDS: SQLITE_TEXT
  4917. **
  4918. ** ^(Every value in SQLite has one of five fundamental datatypes:
  4919. **
  4920. ** <ul>
  4921. ** <li> 64-bit signed integer
  4922. ** <li> 64-bit IEEE floating point number
  4923. ** <li> string
  4924. ** <li> BLOB
  4925. ** <li> NULL
  4926. ** </ul>)^
  4927. **
  4928. ** These constants are codes for each of those types.
  4929. **
  4930. ** Note that the SQLITE_TEXT constant was also used in SQLite version 2
  4931. ** for a completely different meaning. Software that links against both
  4932. ** SQLite version 2 and SQLite version 3 should use SQLITE3_TEXT, not
  4933. ** SQLITE_TEXT.
  4934. */
  4935. #define SQLITE_INTEGER 1
  4936. #define SQLITE_FLOAT 2
  4937. #define SQLITE_BLOB 4
  4938. #define SQLITE_NULL 5
  4939. #ifdef SQLITE_TEXT
  4940. # undef SQLITE_TEXT
  4941. #else
  4942. # define SQLITE_TEXT 3
  4943. #endif
  4944. #define SQLITE3_TEXT 3
  4945. /*
  4946. ** CAPI3REF: Result Values From A Query
  4947. ** KEYWORDS: {column access functions}
  4948. ** METHOD: sqlite3_stmt
  4949. **
  4950. ** <b>Summary:</b>
  4951. ** <blockquote><table border=0 cellpadding=0 cellspacing=0>
  4952. ** <tr><td><b>sqlite3_column_blob</b><td>&rarr;<td>BLOB result
  4953. ** <tr><td><b>sqlite3_column_double</b><td>&rarr;<td>REAL result
  4954. ** <tr><td><b>sqlite3_column_int</b><td>&rarr;<td>32-bit INTEGER result
  4955. ** <tr><td><b>sqlite3_column_int64</b><td>&rarr;<td>64-bit INTEGER result
  4956. ** <tr><td><b>sqlite3_column_text</b><td>&rarr;<td>UTF-8 TEXT result
  4957. ** <tr><td><b>sqlite3_column_text16</b><td>&rarr;<td>UTF-16 TEXT result
  4958. ** <tr><td><b>sqlite3_column_value</b><td>&rarr;<td>The result as an
  4959. ** [sqlite3_value|unprotected sqlite3_value] object.
  4960. ** <tr><td>&nbsp;<td>&nbsp;<td>&nbsp;
  4961. ** <tr><td><b>sqlite3_column_bytes</b><td>&rarr;<td>Size of a BLOB
  4962. ** or a UTF-8 TEXT result in bytes
  4963. ** <tr><td><b>sqlite3_column_bytes16&nbsp;&nbsp;</b>
  4964. ** <td>&rarr;&nbsp;&nbsp;<td>Size of UTF-16
  4965. ** TEXT in bytes
  4966. ** <tr><td><b>sqlite3_column_type</b><td>&rarr;<td>Default
  4967. ** datatype of the result
  4968. ** </table></blockquote>
  4969. **
  4970. ** <b>Details:</b>
  4971. **
  4972. ** ^These routines return information about a single column of the current
  4973. ** result row of a query. ^In every case the first argument is a pointer
  4974. ** to the [prepared statement] that is being evaluated (the [sqlite3_stmt*]
  4975. ** that was returned from [sqlite3_prepare_v2()] or one of its variants)
  4976. ** and the second argument is the index of the column for which information
  4977. ** should be returned. ^The leftmost column of the result set has the index 0.
  4978. ** ^The number of columns in the result can be determined using
  4979. ** [sqlite3_column_count()].
  4980. **
  4981. ** If the SQL statement does not currently point to a valid row, or if the
  4982. ** column index is out of range, the result is undefined.
  4983. ** These routines may only be called when the most recent call to
  4984. ** [sqlite3_step()] has returned [SQLITE_ROW] and neither
  4985. ** [sqlite3_reset()] nor [sqlite3_finalize()] have been called subsequently.
  4986. ** If any of these routines are called after [sqlite3_reset()] or
  4987. ** [sqlite3_finalize()] or after [sqlite3_step()] has returned
  4988. ** something other than [SQLITE_ROW], the results are undefined.
  4989. ** If [sqlite3_step()] or [sqlite3_reset()] or [sqlite3_finalize()]
  4990. ** are called from a different thread while any of these routines
  4991. ** are pending, then the results are undefined.
  4992. **
  4993. ** The first six interfaces (_blob, _double, _int, _int64, _text, and _text16)
  4994. ** each return the value of a result column in a specific data format. If
  4995. ** the result column is not initially in the requested format (for example,
  4996. ** if the query returns an integer but the sqlite3_column_text() interface
  4997. ** is used to extract the value) then an automatic type conversion is performed.
  4998. **
  4999. ** ^The sqlite3_column_type() routine returns the
  5000. ** [SQLITE_INTEGER | datatype code] for the initial data type
  5001. ** of the result column. ^The returned value is one of [SQLITE_INTEGER],
  5002. ** [SQLITE_FLOAT], [SQLITE_TEXT], [SQLITE_BLOB], or [SQLITE_NULL].
  5003. ** The return value of sqlite3_column_type() can be used to decide which
  5004. ** of the first six interface should be used to extract the column value.
  5005. ** The value returned by sqlite3_column_type() is only meaningful if no
  5006. ** automatic type conversions have occurred for the value in question.
  5007. ** After a type conversion, the result of calling sqlite3_column_type()
  5008. ** is undefined, though harmless. Future
  5009. ** versions of SQLite may change the behavior of sqlite3_column_type()
  5010. ** following a type conversion.
  5011. **
  5012. ** If the result is a BLOB or a TEXT string, then the sqlite3_column_bytes()
  5013. ** or sqlite3_column_bytes16() interfaces can be used to determine the size
  5014. ** of that BLOB or string.
  5015. **
  5016. ** ^If the result is a BLOB or UTF-8 string then the sqlite3_column_bytes()
  5017. ** routine returns the number of bytes in that BLOB or string.
  5018. ** ^If the result is a UTF-16 string, then sqlite3_column_bytes() converts
  5019. ** the string to UTF-8 and then returns the number of bytes.
  5020. ** ^If the result is a numeric value then sqlite3_column_bytes() uses
  5021. ** [sqlite3_snprintf()] to convert that value to a UTF-8 string and returns
  5022. ** the number of bytes in that string.
  5023. ** ^If the result is NULL, then sqlite3_column_bytes() returns zero.
  5024. **
  5025. ** ^If the result is a BLOB or UTF-16 string then the sqlite3_column_bytes16()
  5026. ** routine returns the number of bytes in that BLOB or string.
  5027. ** ^If the result is a UTF-8 string, then sqlite3_column_bytes16() converts
  5028. ** the string to UTF-16 and then returns the number of bytes.
  5029. ** ^If the result is a numeric value then sqlite3_column_bytes16() uses
  5030. ** [sqlite3_snprintf()] to convert that value to a UTF-16 string and returns
  5031. ** the number of bytes in that string.
  5032. ** ^If the result is NULL, then sqlite3_column_bytes16() returns zero.
  5033. **
  5034. ** ^The values returned by [sqlite3_column_bytes()] and
  5035. ** [sqlite3_column_bytes16()] do not include the zero terminators at the end
  5036. ** of the string. ^For clarity: the values returned by
  5037. ** [sqlite3_column_bytes()] and [sqlite3_column_bytes16()] are the number of
  5038. ** bytes in the string, not the number of characters.
  5039. **
  5040. ** ^Strings returned by sqlite3_column_text() and sqlite3_column_text16(),
  5041. ** even empty strings, are always zero-terminated. ^The return
  5042. ** value from sqlite3_column_blob() for a zero-length BLOB is a NULL pointer.
  5043. **
  5044. ** ^Strings returned by sqlite3_column_text16() always have the endianness
  5045. ** which is native to the platform, regardless of the text encoding set
  5046. ** for the database.
  5047. **
  5048. ** <b>Warning:</b> ^The object returned by [sqlite3_column_value()] is an
  5049. ** [unprotected sqlite3_value] object. In a multithreaded environment,
  5050. ** an unprotected sqlite3_value object may only be used safely with
  5051. ** [sqlite3_bind_value()] and [sqlite3_result_value()].
  5052. ** If the [unprotected sqlite3_value] object returned by
  5053. ** [sqlite3_column_value()] is used in any other way, including calls
  5054. ** to routines like [sqlite3_value_int()], [sqlite3_value_text()],
  5055. ** or [sqlite3_value_bytes()], the behavior is not threadsafe.
  5056. ** Hence, the sqlite3_column_value() interface
  5057. ** is normally only useful within the implementation of
  5058. ** [application-defined SQL functions] or [virtual tables], not within
  5059. ** top-level application code.
  5060. **
  5061. ** These routines may attempt to convert the datatype of the result.
  5062. ** ^For example, if the internal representation is FLOAT and a text result
  5063. ** is requested, [sqlite3_snprintf()] is used internally to perform the
  5064. ** conversion automatically. ^(The following table details the conversions
  5065. ** that are applied:
  5066. **
  5067. ** <blockquote>
  5068. ** <table border="1">
  5069. ** <tr><th> Internal<br>Type <th> Requested<br>Type <th> Conversion
  5070. **
  5071. ** <tr><td> NULL <td> INTEGER <td> Result is 0
  5072. ** <tr><td> NULL <td> FLOAT <td> Result is 0.0
  5073. ** <tr><td> NULL <td> TEXT <td> Result is a NULL pointer
  5074. ** <tr><td> NULL <td> BLOB <td> Result is a NULL pointer
  5075. ** <tr><td> INTEGER <td> FLOAT <td> Convert from integer to float
  5076. ** <tr><td> INTEGER <td> TEXT <td> ASCII rendering of the integer
  5077. ** <tr><td> INTEGER <td> BLOB <td> Same as INTEGER->TEXT
  5078. ** <tr><td> FLOAT <td> INTEGER <td> [CAST] to INTEGER
  5079. ** <tr><td> FLOAT <td> TEXT <td> ASCII rendering of the float
  5080. ** <tr><td> FLOAT <td> BLOB <td> [CAST] to BLOB
  5081. ** <tr><td> TEXT <td> INTEGER <td> [CAST] to INTEGER
  5082. ** <tr><td> TEXT <td> FLOAT <td> [CAST] to REAL
  5083. ** <tr><td> TEXT <td> BLOB <td> No change
  5084. ** <tr><td> BLOB <td> INTEGER <td> [CAST] to INTEGER
  5085. ** <tr><td> BLOB <td> FLOAT <td> [CAST] to REAL
  5086. ** <tr><td> BLOB <td> TEXT <td> [CAST] to TEXT, ensure zero terminator
  5087. ** </table>
  5088. ** </blockquote>)^
  5089. **
  5090. ** Note that when type conversions occur, pointers returned by prior
  5091. ** calls to sqlite3_column_blob(), sqlite3_column_text(), and/or
  5092. ** sqlite3_column_text16() may be invalidated.
  5093. ** Type conversions and pointer invalidations might occur
  5094. ** in the following cases:
  5095. **
  5096. ** <ul>
  5097. ** <li> The initial content is a BLOB and sqlite3_column_text() or
  5098. ** sqlite3_column_text16() is called. A zero-terminator might
  5099. ** need to be added to the string.</li>
  5100. ** <li> The initial content is UTF-8 text and sqlite3_column_bytes16() or
  5101. ** sqlite3_column_text16() is called. The content must be converted
  5102. ** to UTF-16.</li>
  5103. ** <li> The initial content is UTF-16 text and sqlite3_column_bytes() or
  5104. ** sqlite3_column_text() is called. The content must be converted
  5105. ** to UTF-8.</li>
  5106. ** </ul>
  5107. **
  5108. ** ^Conversions between UTF-16be and UTF-16le are always done in place and do
  5109. ** not invalidate a prior pointer, though of course the content of the buffer
  5110. ** that the prior pointer references will have been modified. Other kinds
  5111. ** of conversion are done in place when it is possible, but sometimes they
  5112. ** are not possible and in those cases prior pointers are invalidated.
  5113. **
  5114. ** The safest policy is to invoke these routines
  5115. ** in one of the following ways:
  5116. **
  5117. ** <ul>
  5118. ** <li>sqlite3_column_text() followed by sqlite3_column_bytes()</li>
  5119. ** <li>sqlite3_column_blob() followed by sqlite3_column_bytes()</li>
  5120. ** <li>sqlite3_column_text16() followed by sqlite3_column_bytes16()</li>
  5121. ** </ul>
  5122. **
  5123. ** In other words, you should call sqlite3_column_text(),
  5124. ** sqlite3_column_blob(), or sqlite3_column_text16() first to force the result
  5125. ** into the desired format, then invoke sqlite3_column_bytes() or
  5126. ** sqlite3_column_bytes16() to find the size of the result. Do not mix calls
  5127. ** to sqlite3_column_text() or sqlite3_column_blob() with calls to
  5128. ** sqlite3_column_bytes16(), and do not mix calls to sqlite3_column_text16()
  5129. ** with calls to sqlite3_column_bytes().
  5130. **
  5131. ** ^The pointers returned are valid until a type conversion occurs as
  5132. ** described above, or until [sqlite3_step()] or [sqlite3_reset()] or
  5133. ** [sqlite3_finalize()] is called. ^The memory space used to hold strings
  5134. ** and BLOBs is freed automatically. Do not pass the pointers returned
  5135. ** from [sqlite3_column_blob()], [sqlite3_column_text()], etc. into
  5136. ** [sqlite3_free()].
  5137. **
  5138. ** As long as the input parameters are correct, these routines will only
  5139. ** fail if an out-of-memory error occurs during a format conversion.
  5140. ** Only the following subset of interfaces are subject to out-of-memory
  5141. ** errors:
  5142. **
  5143. ** <ul>
  5144. ** <li> sqlite3_column_blob()
  5145. ** <li> sqlite3_column_text()
  5146. ** <li> sqlite3_column_text16()
  5147. ** <li> sqlite3_column_bytes()
  5148. ** <li> sqlite3_column_bytes16()
  5149. ** </ul>
  5150. **
  5151. ** If an out-of-memory error occurs, then the return value from these
  5152. ** routines is the same as if the column had contained an SQL NULL value.
  5153. ** Valid SQL NULL returns can be distinguished from out-of-memory errors
  5154. ** by invoking the [sqlite3_errcode()] immediately after the suspect
  5155. ** return value is obtained and before any
  5156. ** other SQLite interface is called on the same [database connection].
  5157. */
  5158. SQLITE_API const void *sqlite3_column_blob(sqlite3_stmt*, int iCol);
  5159. SQLITE_API double sqlite3_column_double(sqlite3_stmt*, int iCol);
  5160. SQLITE_API int sqlite3_column_int(sqlite3_stmt*, int iCol);
  5161. SQLITE_API sqlite3_int64 sqlite3_column_int64(sqlite3_stmt*, int iCol);
  5162. SQLITE_API const unsigned char *sqlite3_column_text(sqlite3_stmt*, int iCol);
  5163. SQLITE_API const void *sqlite3_column_text16(sqlite3_stmt*, int iCol);
  5164. SQLITE_API sqlite3_value *sqlite3_column_value(sqlite3_stmt*, int iCol);
  5165. SQLITE_API int sqlite3_column_bytes(sqlite3_stmt*, int iCol);
  5166. SQLITE_API int sqlite3_column_bytes16(sqlite3_stmt*, int iCol);
  5167. SQLITE_API int sqlite3_column_type(sqlite3_stmt*, int iCol);
  5168. /*
  5169. ** CAPI3REF: Destroy A Prepared Statement Object
  5170. ** DESTRUCTOR: sqlite3_stmt
  5171. **
  5172. ** ^The sqlite3_finalize() function is called to delete a [prepared statement].
  5173. ** ^If the most recent evaluation of the statement encountered no errors
  5174. ** or if the statement is never been evaluated, then sqlite3_finalize() returns
  5175. ** SQLITE_OK. ^If the most recent evaluation of statement S failed, then
  5176. ** sqlite3_finalize(S) returns the appropriate [error code] or
  5177. ** [extended error code].
  5178. **
  5179. ** ^The sqlite3_finalize(S) routine can be called at any point during
  5180. ** the life cycle of [prepared statement] S:
  5181. ** before statement S is ever evaluated, after
  5182. ** one or more calls to [sqlite3_reset()], or after any call
  5183. ** to [sqlite3_step()] regardless of whether or not the statement has
  5184. ** completed execution.
  5185. **
  5186. ** ^Invoking sqlite3_finalize() on a NULL pointer is a harmless no-op.
  5187. **
  5188. ** The application must finalize every [prepared statement] in order to avoid
  5189. ** resource leaks. It is a grievous error for the application to try to use
  5190. ** a prepared statement after it has been finalized. Any use of a prepared
  5191. ** statement after it has been finalized can result in undefined and
  5192. ** undesirable behavior such as segfaults and heap corruption.
  5193. */
  5194. SQLITE_API int sqlite3_finalize(sqlite3_stmt *pStmt);
  5195. /*
  5196. ** CAPI3REF: Reset A Prepared Statement Object
  5197. ** METHOD: sqlite3_stmt
  5198. **
  5199. ** The sqlite3_reset() function is called to reset a [prepared statement]
  5200. ** object back to its initial state, ready to be re-executed.
  5201. ** ^Any SQL statement variables that had values bound to them using
  5202. ** the [sqlite3_bind_blob | sqlite3_bind_*() API] retain their values.
  5203. ** Use [sqlite3_clear_bindings()] to reset the bindings.
  5204. **
  5205. ** ^The [sqlite3_reset(S)] interface resets the [prepared statement] S
  5206. ** back to the beginning of its program.
  5207. **
  5208. ** ^The return code from [sqlite3_reset(S)] indicates whether or not
  5209. ** the previous evaluation of prepared statement S completed successfully.
  5210. ** ^If [sqlite3_step(S)] has never before been called on S or if
  5211. ** [sqlite3_step(S)] has not been called since the previous call
  5212. ** to [sqlite3_reset(S)], then [sqlite3_reset(S)] will return
  5213. ** [SQLITE_OK].
  5214. **
  5215. ** ^If the most recent call to [sqlite3_step(S)] for the
  5216. ** [prepared statement] S indicated an error, then
  5217. ** [sqlite3_reset(S)] returns an appropriate [error code].
  5218. ** ^The [sqlite3_reset(S)] interface might also return an [error code]
  5219. ** if there were no prior errors but the process of resetting
  5220. ** the prepared statement caused a new error. ^For example, if an
  5221. ** [INSERT] statement with a [RETURNING] clause is only stepped one time,
  5222. ** that one call to [sqlite3_step(S)] might return SQLITE_ROW but
  5223. ** the overall statement might still fail and the [sqlite3_reset(S)] call
  5224. ** might return SQLITE_BUSY if locking constraints prevent the
  5225. ** database change from committing. Therefore, it is important that
  5226. ** applications check the return code from [sqlite3_reset(S)] even if
  5227. ** no prior call to [sqlite3_step(S)] indicated a problem.
  5228. **
  5229. ** ^The [sqlite3_reset(S)] interface does not change the values
  5230. ** of any [sqlite3_bind_blob|bindings] on the [prepared statement] S.
  5231. */
  5232. SQLITE_API int sqlite3_reset(sqlite3_stmt *pStmt);
  5233. /*
  5234. ** CAPI3REF: Create Or Redefine SQL Functions
  5235. ** KEYWORDS: {function creation routines}
  5236. ** METHOD: sqlite3
  5237. **
  5238. ** ^These functions (collectively known as "function creation routines")
  5239. ** are used to add SQL functions or aggregates or to redefine the behavior
  5240. ** of existing SQL functions or aggregates. The only differences between
  5241. ** the three "sqlite3_create_function*" routines are the text encoding
  5242. ** expected for the second parameter (the name of the function being
  5243. ** created) and the presence or absence of a destructor callback for
  5244. ** the application data pointer. Function sqlite3_create_window_function()
  5245. ** is similar, but allows the user to supply the extra callback functions
  5246. ** needed by [aggregate window functions].
  5247. **
  5248. ** ^The first parameter is the [database connection] to which the SQL
  5249. ** function is to be added. ^If an application uses more than one database
  5250. ** connection then application-defined SQL functions must be added
  5251. ** to each database connection separately.
  5252. **
  5253. ** ^The second parameter is the name of the SQL function to be created or
  5254. ** redefined. ^The length of the name is limited to 255 bytes in a UTF-8
  5255. ** representation, exclusive of the zero-terminator. ^Note that the name
  5256. ** length limit is in UTF-8 bytes, not characters nor UTF-16 bytes.
  5257. ** ^Any attempt to create a function with a longer name
  5258. ** will result in [SQLITE_MISUSE] being returned.
  5259. **
  5260. ** ^The third parameter (nArg)
  5261. ** is the number of arguments that the SQL function or
  5262. ** aggregate takes. ^If this parameter is -1, then the SQL function or
  5263. ** aggregate may take any number of arguments between 0 and the limit
  5264. ** set by [sqlite3_limit]([SQLITE_LIMIT_FUNCTION_ARG]). If the third
  5265. ** parameter is less than -1 or greater than 127 then the behavior is
  5266. ** undefined.
  5267. **
  5268. ** ^The fourth parameter, eTextRep, specifies what
  5269. ** [SQLITE_UTF8 | text encoding] this SQL function prefers for
  5270. ** its parameters. The application should set this parameter to
  5271. ** [SQLITE_UTF16LE] if the function implementation invokes
  5272. ** [sqlite3_value_text16le()] on an input, or [SQLITE_UTF16BE] if the
  5273. ** implementation invokes [sqlite3_value_text16be()] on an input, or
  5274. ** [SQLITE_UTF16] if [sqlite3_value_text16()] is used, or [SQLITE_UTF8]
  5275. ** otherwise. ^The same SQL function may be registered multiple times using
  5276. ** different preferred text encodings, with different implementations for
  5277. ** each encoding.
  5278. ** ^When multiple implementations of the same function are available, SQLite
  5279. ** will pick the one that involves the least amount of data conversion.
  5280. **
  5281. ** ^The fourth parameter may optionally be ORed with [SQLITE_DETERMINISTIC]
  5282. ** to signal that the function will always return the same result given
  5283. ** the same inputs within a single SQL statement. Most SQL functions are
  5284. ** deterministic. The built-in [random()] SQL function is an example of a
  5285. ** function that is not deterministic. The SQLite query planner is able to
  5286. ** perform additional optimizations on deterministic functions, so use
  5287. ** of the [SQLITE_DETERMINISTIC] flag is recommended where possible.
  5288. **
  5289. ** ^The fourth parameter may also optionally include the [SQLITE_DIRECTONLY]
  5290. ** flag, which if present prevents the function from being invoked from
  5291. ** within VIEWs, TRIGGERs, CHECK constraints, generated column expressions,
  5292. ** index expressions, or the WHERE clause of partial indexes.
  5293. **
  5294. ** For best security, the [SQLITE_DIRECTONLY] flag is recommended for
  5295. ** all application-defined SQL functions that do not need to be
  5296. ** used inside of triggers, view, CHECK constraints, or other elements of
  5297. ** the database schema. This flags is especially recommended for SQL
  5298. ** functions that have side effects or reveal internal application state.
  5299. ** Without this flag, an attacker might be able to modify the schema of
  5300. ** a database file to include invocations of the function with parameters
  5301. ** chosen by the attacker, which the application will then execute when
  5302. ** the database file is opened and read.
  5303. **
  5304. ** ^(The fifth parameter is an arbitrary pointer. The implementation of the
  5305. ** function can gain access to this pointer using [sqlite3_user_data()].)^
  5306. **
  5307. ** ^The sixth, seventh and eighth parameters passed to the three
  5308. ** "sqlite3_create_function*" functions, xFunc, xStep and xFinal, are
  5309. ** pointers to C-language functions that implement the SQL function or
  5310. ** aggregate. ^A scalar SQL function requires an implementation of the xFunc
  5311. ** callback only; NULL pointers must be passed as the xStep and xFinal
  5312. ** parameters. ^An aggregate SQL function requires an implementation of xStep
  5313. ** and xFinal and NULL pointer must be passed for xFunc. ^To delete an existing
  5314. ** SQL function or aggregate, pass NULL pointers for all three function
  5315. ** callbacks.
  5316. **
  5317. ** ^The sixth, seventh, eighth and ninth parameters (xStep, xFinal, xValue
  5318. ** and xInverse) passed to sqlite3_create_window_function are pointers to
  5319. ** C-language callbacks that implement the new function. xStep and xFinal
  5320. ** must both be non-NULL. xValue and xInverse may either both be NULL, in
  5321. ** which case a regular aggregate function is created, or must both be
  5322. ** non-NULL, in which case the new function may be used as either an aggregate
  5323. ** or aggregate window function. More details regarding the implementation
  5324. ** of aggregate window functions are
  5325. ** [user-defined window functions|available here].
  5326. **
  5327. ** ^(If the final parameter to sqlite3_create_function_v2() or
  5328. ** sqlite3_create_window_function() is not NULL, then it is destructor for
  5329. ** the application data pointer. The destructor is invoked when the function
  5330. ** is deleted, either by being overloaded or when the database connection
  5331. ** closes.)^ ^The destructor is also invoked if the call to
  5332. ** sqlite3_create_function_v2() fails. ^When the destructor callback is
  5333. ** invoked, it is passed a single argument which is a copy of the application
  5334. ** data pointer which was the fifth parameter to sqlite3_create_function_v2().
  5335. **
  5336. ** ^It is permitted to register multiple implementations of the same
  5337. ** functions with the same name but with either differing numbers of
  5338. ** arguments or differing preferred text encodings. ^SQLite will use
  5339. ** the implementation that most closely matches the way in which the
  5340. ** SQL function is used. ^A function implementation with a non-negative
  5341. ** nArg parameter is a better match than a function implementation with
  5342. ** a negative nArg. ^A function where the preferred text encoding
  5343. ** matches the database encoding is a better
  5344. ** match than a function where the encoding is different.
  5345. ** ^A function where the encoding difference is between UTF16le and UTF16be
  5346. ** is a closer match than a function where the encoding difference is
  5347. ** between UTF8 and UTF16.
  5348. **
  5349. ** ^Built-in functions may be overloaded by new application-defined functions.
  5350. **
  5351. ** ^An application-defined function is permitted to call other
  5352. ** SQLite interfaces. However, such calls must not
  5353. ** close the database connection nor finalize or reset the prepared
  5354. ** statement in which the function is running.
  5355. */
  5356. SQLITE_API int sqlite3_create_function(
  5357. sqlite3 *db,
  5358. const char *zFunctionName,
  5359. int nArg,
  5360. int eTextRep,
  5361. void *pApp,
  5362. void (*xFunc)(sqlite3_context*,int,sqlite3_value**),
  5363. void (*xStep)(sqlite3_context*,int,sqlite3_value**),
  5364. void (*xFinal)(sqlite3_context*)
  5365. );
  5366. SQLITE_API int sqlite3_create_function16(
  5367. sqlite3 *db,
  5368. const void *zFunctionName,
  5369. int nArg,
  5370. int eTextRep,
  5371. void *pApp,
  5372. void (*xFunc)(sqlite3_context*,int,sqlite3_value**),
  5373. void (*xStep)(sqlite3_context*,int,sqlite3_value**),
  5374. void (*xFinal)(sqlite3_context*)
  5375. );
  5376. SQLITE_API int sqlite3_create_function_v2(
  5377. sqlite3 *db,
  5378. const char *zFunctionName,
  5379. int nArg,
  5380. int eTextRep,
  5381. void *pApp,
  5382. void (*xFunc)(sqlite3_context*,int,sqlite3_value**),
  5383. void (*xStep)(sqlite3_context*,int,sqlite3_value**),
  5384. void (*xFinal)(sqlite3_context*),
  5385. void(*xDestroy)(void*)
  5386. );
  5387. SQLITE_API int sqlite3_create_window_function(
  5388. sqlite3 *db,
  5389. const char *zFunctionName,
  5390. int nArg,
  5391. int eTextRep,
  5392. void *pApp,
  5393. void (*xStep)(sqlite3_context*,int,sqlite3_value**),
  5394. void (*xFinal)(sqlite3_context*),
  5395. void (*xValue)(sqlite3_context*),
  5396. void (*xInverse)(sqlite3_context*,int,sqlite3_value**),
  5397. void(*xDestroy)(void*)
  5398. );
  5399. /*
  5400. ** CAPI3REF: Text Encodings
  5401. **
  5402. ** These constant define integer codes that represent the various
  5403. ** text encodings supported by SQLite.
  5404. */
  5405. #define SQLITE_UTF8 1 /* IMP: R-37514-35566 */
  5406. #define SQLITE_UTF16LE 2 /* IMP: R-03371-37637 */
  5407. #define SQLITE_UTF16BE 3 /* IMP: R-51971-34154 */
  5408. #define SQLITE_UTF16 4 /* Use native byte order */
  5409. #define SQLITE_ANY 5 /* Deprecated */
  5410. #define SQLITE_UTF16_ALIGNED 8 /* sqlite3_create_collation only */
  5411. /*
  5412. ** CAPI3REF: Function Flags
  5413. **
  5414. ** These constants may be ORed together with the
  5415. ** [SQLITE_UTF8 | preferred text encoding] as the fourth argument
  5416. ** to [sqlite3_create_function()], [sqlite3_create_function16()], or
  5417. ** [sqlite3_create_function_v2()].
  5418. **
  5419. ** <dl>
  5420. ** [[SQLITE_DETERMINISTIC]] <dt>SQLITE_DETERMINISTIC</dt><dd>
  5421. ** The SQLITE_DETERMINISTIC flag means that the new function always gives
  5422. ** the same output when the input parameters are the same.
  5423. ** The [abs|abs() function] is deterministic, for example, but
  5424. ** [randomblob|randomblob()] is not. Functions must
  5425. ** be deterministic in order to be used in certain contexts such as
  5426. ** with the WHERE clause of [partial indexes] or in [generated columns].
  5427. ** SQLite might also optimize deterministic functions by factoring them
  5428. ** out of inner loops.
  5429. ** </dd>
  5430. **
  5431. ** [[SQLITE_DIRECTONLY]] <dt>SQLITE_DIRECTONLY</dt><dd>
  5432. ** The SQLITE_DIRECTONLY flag means that the function may only be invoked
  5433. ** from top-level SQL, and cannot be used in VIEWs or TRIGGERs nor in
  5434. ** schema structures such as [CHECK constraints], [DEFAULT clauses],
  5435. ** [expression indexes], [partial indexes], or [generated columns].
  5436. ** <p>
  5437. ** The SQLITE_DIRECTONLY flag is recommended for any
  5438. ** [application-defined SQL function]
  5439. ** that has side-effects or that could potentially leak sensitive information.
  5440. ** This will prevent attacks in which an application is tricked
  5441. ** into using a database file that has had its schema surreptitiously
  5442. ** modified to invoke the application-defined function in ways that are
  5443. ** harmful.
  5444. ** <p>
  5445. ** Some people say it is good practice to set SQLITE_DIRECTONLY on all
  5446. ** [application-defined SQL functions], regardless of whether or not they
  5447. ** are security sensitive, as doing so prevents those functions from being used
  5448. ** inside of the database schema, and thus ensures that the database
  5449. ** can be inspected and modified using generic tools (such as the [CLI])
  5450. ** that do not have access to the application-defined functions.
  5451. ** </dd>
  5452. **
  5453. ** [[SQLITE_INNOCUOUS]] <dt>SQLITE_INNOCUOUS</dt><dd>
  5454. ** The SQLITE_INNOCUOUS flag means that the function is unlikely
  5455. ** to cause problems even if misused. An innocuous function should have
  5456. ** no side effects and should not depend on any values other than its
  5457. ** input parameters. The [abs|abs() function] is an example of an
  5458. ** innocuous function.
  5459. ** The [load_extension() SQL function] is not innocuous because of its
  5460. ** side effects.
  5461. ** <p> SQLITE_INNOCUOUS is similar to SQLITE_DETERMINISTIC, but is not
  5462. ** exactly the same. The [random|random() function] is an example of a
  5463. ** function that is innocuous but not deterministic.
  5464. ** <p>Some heightened security settings
  5465. ** ([SQLITE_DBCONFIG_TRUSTED_SCHEMA] and [PRAGMA trusted_schema=OFF])
  5466. ** disable the use of SQL functions inside views and triggers and in
  5467. ** schema structures such as [CHECK constraints], [DEFAULT clauses],
  5468. ** [expression indexes], [partial indexes], and [generated columns] unless
  5469. ** the function is tagged with SQLITE_INNOCUOUS. Most built-in functions
  5470. ** are innocuous. Developers are advised to avoid using the
  5471. ** SQLITE_INNOCUOUS flag for application-defined functions unless the
  5472. ** function has been carefully audited and found to be free of potentially
  5473. ** security-adverse side-effects and information-leaks.
  5474. ** </dd>
  5475. **
  5476. ** [[SQLITE_SUBTYPE]] <dt>SQLITE_SUBTYPE</dt><dd>
  5477. ** The SQLITE_SUBTYPE flag indicates to SQLite that a function may call
  5478. ** [sqlite3_value_subtype()] to inspect the sub-types of its arguments.
  5479. ** Specifying this flag makes no difference for scalar or aggregate user
  5480. ** functions. However, if it is not specified for a user-defined window
  5481. ** function, then any sub-types belonging to arguments passed to the window
  5482. ** function may be discarded before the window function is called (i.e.
  5483. ** sqlite3_value_subtype() will always return 0).
  5484. ** </dd>
  5485. ** </dl>
  5486. */
  5487. #define SQLITE_DETERMINISTIC 0x000000800
  5488. #define SQLITE_DIRECTONLY 0x000080000
  5489. #define SQLITE_SUBTYPE 0x000100000
  5490. #define SQLITE_INNOCUOUS 0x000200000
  5491. /*
  5492. ** CAPI3REF: Deprecated Functions
  5493. ** DEPRECATED
  5494. **
  5495. ** These functions are [deprecated]. In order to maintain
  5496. ** backwards compatibility with older code, these functions continue
  5497. ** to be supported. However, new applications should avoid
  5498. ** the use of these functions. To encourage programmers to avoid
  5499. ** these functions, we will not explain what they do.
  5500. */
  5501. #ifndef SQLITE_OMIT_DEPRECATED
  5502. SQLITE_API SQLITE_DEPRECATED int sqlite3_aggregate_count(sqlite3_context*);
  5503. SQLITE_API SQLITE_DEPRECATED int sqlite3_expired(sqlite3_stmt*);
  5504. SQLITE_API SQLITE_DEPRECATED int sqlite3_transfer_bindings(sqlite3_stmt*, sqlite3_stmt*);
  5505. SQLITE_API SQLITE_DEPRECATED int sqlite3_global_recover(void);
  5506. SQLITE_API SQLITE_DEPRECATED void sqlite3_thread_cleanup(void);
  5507. SQLITE_API SQLITE_DEPRECATED int sqlite3_memory_alarm(void(*)(void*,sqlite3_int64,int),
  5508. void*,sqlite3_int64);
  5509. #endif
  5510. /*
  5511. ** CAPI3REF: Obtaining SQL Values
  5512. ** METHOD: sqlite3_value
  5513. **
  5514. ** <b>Summary:</b>
  5515. ** <blockquote><table border=0 cellpadding=0 cellspacing=0>
  5516. ** <tr><td><b>sqlite3_value_blob</b><td>&rarr;<td>BLOB value
  5517. ** <tr><td><b>sqlite3_value_double</b><td>&rarr;<td>REAL value
  5518. ** <tr><td><b>sqlite3_value_int</b><td>&rarr;<td>32-bit INTEGER value
  5519. ** <tr><td><b>sqlite3_value_int64</b><td>&rarr;<td>64-bit INTEGER value
  5520. ** <tr><td><b>sqlite3_value_pointer</b><td>&rarr;<td>Pointer value
  5521. ** <tr><td><b>sqlite3_value_text</b><td>&rarr;<td>UTF-8 TEXT value
  5522. ** <tr><td><b>sqlite3_value_text16</b><td>&rarr;<td>UTF-16 TEXT value in
  5523. ** the native byteorder
  5524. ** <tr><td><b>sqlite3_value_text16be</b><td>&rarr;<td>UTF-16be TEXT value
  5525. ** <tr><td><b>sqlite3_value_text16le</b><td>&rarr;<td>UTF-16le TEXT value
  5526. ** <tr><td>&nbsp;<td>&nbsp;<td>&nbsp;
  5527. ** <tr><td><b>sqlite3_value_bytes</b><td>&rarr;<td>Size of a BLOB
  5528. ** or a UTF-8 TEXT in bytes
  5529. ** <tr><td><b>sqlite3_value_bytes16&nbsp;&nbsp;</b>
  5530. ** <td>&rarr;&nbsp;&nbsp;<td>Size of UTF-16
  5531. ** TEXT in bytes
  5532. ** <tr><td><b>sqlite3_value_type</b><td>&rarr;<td>Default
  5533. ** datatype of the value
  5534. ** <tr><td><b>sqlite3_value_numeric_type&nbsp;&nbsp;</b>
  5535. ** <td>&rarr;&nbsp;&nbsp;<td>Best numeric datatype of the value
  5536. ** <tr><td><b>sqlite3_value_nochange&nbsp;&nbsp;</b>
  5537. ** <td>&rarr;&nbsp;&nbsp;<td>True if the column is unchanged in an UPDATE
  5538. ** against a virtual table.
  5539. ** <tr><td><b>sqlite3_value_frombind&nbsp;&nbsp;</b>
  5540. ** <td>&rarr;&nbsp;&nbsp;<td>True if value originated from a [bound parameter]
  5541. ** </table></blockquote>
  5542. **
  5543. ** <b>Details:</b>
  5544. **
  5545. ** These routines extract type, size, and content information from
  5546. ** [protected sqlite3_value] objects. Protected sqlite3_value objects
  5547. ** are used to pass parameter information into the functions that
  5548. ** implement [application-defined SQL functions] and [virtual tables].
  5549. **
  5550. ** These routines work only with [protected sqlite3_value] objects.
  5551. ** Any attempt to use these routines on an [unprotected sqlite3_value]
  5552. ** is not threadsafe.
  5553. **
  5554. ** ^These routines work just like the corresponding [column access functions]
  5555. ** except that these routines take a single [protected sqlite3_value] object
  5556. ** pointer instead of a [sqlite3_stmt*] pointer and an integer column number.
  5557. **
  5558. ** ^The sqlite3_value_text16() interface extracts a UTF-16 string
  5559. ** in the native byte-order of the host machine. ^The
  5560. ** sqlite3_value_text16be() and sqlite3_value_text16le() interfaces
  5561. ** extract UTF-16 strings as big-endian and little-endian respectively.
  5562. **
  5563. ** ^If [sqlite3_value] object V was initialized
  5564. ** using [sqlite3_bind_pointer(S,I,P,X,D)] or [sqlite3_result_pointer(C,P,X,D)]
  5565. ** and if X and Y are strings that compare equal according to strcmp(X,Y),
  5566. ** then sqlite3_value_pointer(V,Y) will return the pointer P. ^Otherwise,
  5567. ** sqlite3_value_pointer(V,Y) returns a NULL. The sqlite3_bind_pointer()
  5568. ** routine is part of the [pointer passing interface] added for SQLite 3.20.0.
  5569. **
  5570. ** ^(The sqlite3_value_type(V) interface returns the
  5571. ** [SQLITE_INTEGER | datatype code] for the initial datatype of the
  5572. ** [sqlite3_value] object V. The returned value is one of [SQLITE_INTEGER],
  5573. ** [SQLITE_FLOAT], [SQLITE_TEXT], [SQLITE_BLOB], or [SQLITE_NULL].)^
  5574. ** Other interfaces might change the datatype for an sqlite3_value object.
  5575. ** For example, if the datatype is initially SQLITE_INTEGER and
  5576. ** sqlite3_value_text(V) is called to extract a text value for that
  5577. ** integer, then subsequent calls to sqlite3_value_type(V) might return
  5578. ** SQLITE_TEXT. Whether or not a persistent internal datatype conversion
  5579. ** occurs is undefined and may change from one release of SQLite to the next.
  5580. **
  5581. ** ^(The sqlite3_value_numeric_type() interface attempts to apply
  5582. ** numeric affinity to the value. This means that an attempt is
  5583. ** made to convert the value to an integer or floating point. If
  5584. ** such a conversion is possible without loss of information (in other
  5585. ** words, if the value is a string that looks like a number)
  5586. ** then the conversion is performed. Otherwise no conversion occurs.
  5587. ** The [SQLITE_INTEGER | datatype] after conversion is returned.)^
  5588. **
  5589. ** ^Within the [xUpdate] method of a [virtual table], the
  5590. ** sqlite3_value_nochange(X) interface returns true if and only if
  5591. ** the column corresponding to X is unchanged by the UPDATE operation
  5592. ** that the xUpdate method call was invoked to implement and if
  5593. ** and the prior [xColumn] method call that was invoked to extracted
  5594. ** the value for that column returned without setting a result (probably
  5595. ** because it queried [sqlite3_vtab_nochange()] and found that the column
  5596. ** was unchanging). ^Within an [xUpdate] method, any value for which
  5597. ** sqlite3_value_nochange(X) is true will in all other respects appear
  5598. ** to be a NULL value. If sqlite3_value_nochange(X) is invoked anywhere other
  5599. ** than within an [xUpdate] method call for an UPDATE statement, then
  5600. ** the return value is arbitrary and meaningless.
  5601. **
  5602. ** ^The sqlite3_value_frombind(X) interface returns non-zero if the
  5603. ** value X originated from one of the [sqlite3_bind_int|sqlite3_bind()]
  5604. ** interfaces. ^If X comes from an SQL literal value, or a table column,
  5605. ** or an expression, then sqlite3_value_frombind(X) returns zero.
  5606. **
  5607. ** Please pay particular attention to the fact that the pointer returned
  5608. ** from [sqlite3_value_blob()], [sqlite3_value_text()], or
  5609. ** [sqlite3_value_text16()] can be invalidated by a subsequent call to
  5610. ** [sqlite3_value_bytes()], [sqlite3_value_bytes16()], [sqlite3_value_text()],
  5611. ** or [sqlite3_value_text16()].
  5612. **
  5613. ** These routines must be called from the same thread as
  5614. ** the SQL function that supplied the [sqlite3_value*] parameters.
  5615. **
  5616. ** As long as the input parameter is correct, these routines can only
  5617. ** fail if an out-of-memory error occurs during a format conversion.
  5618. ** Only the following subset of interfaces are subject to out-of-memory
  5619. ** errors:
  5620. **
  5621. ** <ul>
  5622. ** <li> sqlite3_value_blob()
  5623. ** <li> sqlite3_value_text()
  5624. ** <li> sqlite3_value_text16()
  5625. ** <li> sqlite3_value_text16le()
  5626. ** <li> sqlite3_value_text16be()
  5627. ** <li> sqlite3_value_bytes()
  5628. ** <li> sqlite3_value_bytes16()
  5629. ** </ul>
  5630. **
  5631. ** If an out-of-memory error occurs, then the return value from these
  5632. ** routines is the same as if the column had contained an SQL NULL value.
  5633. ** Valid SQL NULL returns can be distinguished from out-of-memory errors
  5634. ** by invoking the [sqlite3_errcode()] immediately after the suspect
  5635. ** return value is obtained and before any
  5636. ** other SQLite interface is called on the same [database connection].
  5637. */
  5638. SQLITE_API const void *sqlite3_value_blob(sqlite3_value*);
  5639. SQLITE_API double sqlite3_value_double(sqlite3_value*);
  5640. SQLITE_API int sqlite3_value_int(sqlite3_value*);
  5641. SQLITE_API sqlite3_int64 sqlite3_value_int64(sqlite3_value*);
  5642. SQLITE_API void *sqlite3_value_pointer(sqlite3_value*, const char*);
  5643. SQLITE_API const unsigned char *sqlite3_value_text(sqlite3_value*);
  5644. SQLITE_API const void *sqlite3_value_text16(sqlite3_value*);
  5645. SQLITE_API const void *sqlite3_value_text16le(sqlite3_value*);
  5646. SQLITE_API const void *sqlite3_value_text16be(sqlite3_value*);
  5647. SQLITE_API int sqlite3_value_bytes(sqlite3_value*);
  5648. SQLITE_API int sqlite3_value_bytes16(sqlite3_value*);
  5649. SQLITE_API int sqlite3_value_type(sqlite3_value*);
  5650. SQLITE_API int sqlite3_value_numeric_type(sqlite3_value*);
  5651. SQLITE_API int sqlite3_value_nochange(sqlite3_value*);
  5652. SQLITE_API int sqlite3_value_frombind(sqlite3_value*);
  5653. /*
  5654. ** CAPI3REF: Report the internal text encoding state of an sqlite3_value object
  5655. ** METHOD: sqlite3_value
  5656. **
  5657. ** ^(The sqlite3_value_encoding(X) interface returns one of [SQLITE_UTF8],
  5658. ** [SQLITE_UTF16BE], or [SQLITE_UTF16LE] according to the current text encoding
  5659. ** of the value X, assuming that X has type TEXT.)^ If sqlite3_value_type(X)
  5660. ** returns something other than SQLITE_TEXT, then the return value from
  5661. ** sqlite3_value_encoding(X) is meaningless. ^Calls to
  5662. ** [sqlite3_value_text(X)], [sqlite3_value_text16(X)], [sqlite3_value_text16be(X)],
  5663. ** [sqlite3_value_text16le(X)], [sqlite3_value_bytes(X)], or
  5664. ** [sqlite3_value_bytes16(X)] might change the encoding of the value X and
  5665. ** thus change the return from subsequent calls to sqlite3_value_encoding(X).
  5666. **
  5667. ** This routine is intended for used by applications that test and validate
  5668. ** the SQLite implementation. This routine is inquiring about the opaque
  5669. ** internal state of an [sqlite3_value] object. Ordinary applications should
  5670. ** not need to know what the internal state of an sqlite3_value object is and
  5671. ** hence should not need to use this interface.
  5672. */
  5673. SQLITE_API int sqlite3_value_encoding(sqlite3_value*);
  5674. /*
  5675. ** CAPI3REF: Finding The Subtype Of SQL Values
  5676. ** METHOD: sqlite3_value
  5677. **
  5678. ** The sqlite3_value_subtype(V) function returns the subtype for
  5679. ** an [application-defined SQL function] argument V. The subtype
  5680. ** information can be used to pass a limited amount of context from
  5681. ** one SQL function to another. Use the [sqlite3_result_subtype()]
  5682. ** routine to set the subtype for the return value of an SQL function.
  5683. */
  5684. SQLITE_API unsigned int sqlite3_value_subtype(sqlite3_value*);
  5685. /*
  5686. ** CAPI3REF: Copy And Free SQL Values
  5687. ** METHOD: sqlite3_value
  5688. **
  5689. ** ^The sqlite3_value_dup(V) interface makes a copy of the [sqlite3_value]
  5690. ** object D and returns a pointer to that copy. ^The [sqlite3_value] returned
  5691. ** is a [protected sqlite3_value] object even if the input is not.
  5692. ** ^The sqlite3_value_dup(V) interface returns NULL if V is NULL or if a
  5693. ** memory allocation fails. ^If V is a [pointer value], then the result
  5694. ** of sqlite3_value_dup(V) is a NULL value.
  5695. **
  5696. ** ^The sqlite3_value_free(V) interface frees an [sqlite3_value] object
  5697. ** previously obtained from [sqlite3_value_dup()]. ^If V is a NULL pointer
  5698. ** then sqlite3_value_free(V) is a harmless no-op.
  5699. */
  5700. SQLITE_API sqlite3_value *sqlite3_value_dup(const sqlite3_value*);
  5701. SQLITE_API void sqlite3_value_free(sqlite3_value*);
  5702. /*
  5703. ** CAPI3REF: Obtain Aggregate Function Context
  5704. ** METHOD: sqlite3_context
  5705. **
  5706. ** Implementations of aggregate SQL functions use this
  5707. ** routine to allocate memory for storing their state.
  5708. **
  5709. ** ^The first time the sqlite3_aggregate_context(C,N) routine is called
  5710. ** for a particular aggregate function, SQLite allocates
  5711. ** N bytes of memory, zeroes out that memory, and returns a pointer
  5712. ** to the new memory. ^On second and subsequent calls to
  5713. ** sqlite3_aggregate_context() for the same aggregate function instance,
  5714. ** the same buffer is returned. Sqlite3_aggregate_context() is normally
  5715. ** called once for each invocation of the xStep callback and then one
  5716. ** last time when the xFinal callback is invoked. ^(When no rows match
  5717. ** an aggregate query, the xStep() callback of the aggregate function
  5718. ** implementation is never called and xFinal() is called exactly once.
  5719. ** In those cases, sqlite3_aggregate_context() might be called for the
  5720. ** first time from within xFinal().)^
  5721. **
  5722. ** ^The sqlite3_aggregate_context(C,N) routine returns a NULL pointer
  5723. ** when first called if N is less than or equal to zero or if a memory
  5724. ** allocation error occurs.
  5725. **
  5726. ** ^(The amount of space allocated by sqlite3_aggregate_context(C,N) is
  5727. ** determined by the N parameter on first successful call. Changing the
  5728. ** value of N in any subsequent call to sqlite3_aggregate_context() within
  5729. ** the same aggregate function instance will not resize the memory
  5730. ** allocation.)^ Within the xFinal callback, it is customary to set
  5731. ** N=0 in calls to sqlite3_aggregate_context(C,N) so that no
  5732. ** pointless memory allocations occur.
  5733. **
  5734. ** ^SQLite automatically frees the memory allocated by
  5735. ** sqlite3_aggregate_context() when the aggregate query concludes.
  5736. **
  5737. ** The first parameter must be a copy of the
  5738. ** [sqlite3_context | SQL function context] that is the first parameter
  5739. ** to the xStep or xFinal callback routine that implements the aggregate
  5740. ** function.
  5741. **
  5742. ** This routine must be called from the same thread in which
  5743. ** the aggregate SQL function is running.
  5744. */
  5745. SQLITE_API void *sqlite3_aggregate_context(sqlite3_context*, int nBytes);
  5746. /*
  5747. ** CAPI3REF: User Data For Functions
  5748. ** METHOD: sqlite3_context
  5749. **
  5750. ** ^The sqlite3_user_data() interface returns a copy of
  5751. ** the pointer that was the pUserData parameter (the 5th parameter)
  5752. ** of the [sqlite3_create_function()]
  5753. ** and [sqlite3_create_function16()] routines that originally
  5754. ** registered the application defined function.
  5755. **
  5756. ** This routine must be called from the same thread in which
  5757. ** the application-defined function is running.
  5758. */
  5759. SQLITE_API void *sqlite3_user_data(sqlite3_context*);
  5760. /*
  5761. ** CAPI3REF: Database Connection For Functions
  5762. ** METHOD: sqlite3_context
  5763. **
  5764. ** ^The sqlite3_context_db_handle() interface returns a copy of
  5765. ** the pointer to the [database connection] (the 1st parameter)
  5766. ** of the [sqlite3_create_function()]
  5767. ** and [sqlite3_create_function16()] routines that originally
  5768. ** registered the application defined function.
  5769. */
  5770. SQLITE_API sqlite3 *sqlite3_context_db_handle(sqlite3_context*);
  5771. /*
  5772. ** CAPI3REF: Function Auxiliary Data
  5773. ** METHOD: sqlite3_context
  5774. **
  5775. ** These functions may be used by (non-aggregate) SQL functions to
  5776. ** associate auxiliary data with argument values. If the same argument
  5777. ** value is passed to multiple invocations of the same SQL function during
  5778. ** query execution, under some circumstances the associated auxiliary data
  5779. ** might be preserved. An example of where this might be useful is in a
  5780. ** regular-expression matching function. The compiled version of the regular
  5781. ** expression can be stored as auxiliary data associated with the pattern string.
  5782. ** Then as long as the pattern string remains the same,
  5783. ** the compiled regular expression can be reused on multiple
  5784. ** invocations of the same function.
  5785. **
  5786. ** ^The sqlite3_get_auxdata(C,N) interface returns a pointer to the auxiliary data
  5787. ** associated by the sqlite3_set_auxdata(C,N,P,X) function with the Nth argument
  5788. ** value to the application-defined function. ^N is zero for the left-most
  5789. ** function argument. ^If there is no auxiliary data
  5790. ** associated with the function argument, the sqlite3_get_auxdata(C,N) interface
  5791. ** returns a NULL pointer.
  5792. **
  5793. ** ^The sqlite3_set_auxdata(C,N,P,X) interface saves P as auxiliary data for the
  5794. ** N-th argument of the application-defined function. ^Subsequent
  5795. ** calls to sqlite3_get_auxdata(C,N) return P from the most recent
  5796. ** sqlite3_set_auxdata(C,N,P,X) call if the auxiliary data is still valid or
  5797. ** NULL if the auxiliary data has been discarded.
  5798. ** ^After each call to sqlite3_set_auxdata(C,N,P,X) where X is not NULL,
  5799. ** SQLite will invoke the destructor function X with parameter P exactly
  5800. ** once, when the auxiliary data is discarded.
  5801. ** SQLite is free to discard the auxiliary data at any time, including: <ul>
  5802. ** <li> ^(when the corresponding function parameter changes)^, or
  5803. ** <li> ^(when [sqlite3_reset()] or [sqlite3_finalize()] is called for the
  5804. ** SQL statement)^, or
  5805. ** <li> ^(when sqlite3_set_auxdata() is invoked again on the same
  5806. ** parameter)^, or
  5807. ** <li> ^(during the original sqlite3_set_auxdata() call when a memory
  5808. ** allocation error occurs.)^ </ul>
  5809. **
  5810. ** Note the last bullet in particular. The destructor X in
  5811. ** sqlite3_set_auxdata(C,N,P,X) might be called immediately, before the
  5812. ** sqlite3_set_auxdata() interface even returns. Hence sqlite3_set_auxdata()
  5813. ** should be called near the end of the function implementation and the
  5814. ** function implementation should not make any use of P after
  5815. ** sqlite3_set_auxdata() has been called.
  5816. **
  5817. ** ^(In practice, auxiliary data is preserved between function calls for
  5818. ** function parameters that are compile-time constants, including literal
  5819. ** values and [parameters] and expressions composed from the same.)^
  5820. **
  5821. ** The value of the N parameter to these interfaces should be non-negative.
  5822. ** Future enhancements may make use of negative N values to define new
  5823. ** kinds of function caching behavior.
  5824. **
  5825. ** These routines must be called from the same thread in which
  5826. ** the SQL function is running.
  5827. **
  5828. ** See also: [sqlite3_get_clientdata()] and [sqlite3_set_clientdata()].
  5829. */
  5830. SQLITE_API void *sqlite3_get_auxdata(sqlite3_context*, int N);
  5831. SQLITE_API void sqlite3_set_auxdata(sqlite3_context*, int N, void*, void (*)(void*));
  5832. /*
  5833. ** CAPI3REF: Database Connection Client Data
  5834. ** METHOD: sqlite3
  5835. **
  5836. ** These functions are used to associate one or more named pointers
  5837. ** with a [database connection].
  5838. ** A call to sqlite3_set_clientdata(D,N,P,X) causes the pointer P
  5839. ** to be attached to [database connection] D using name N. Subsequent
  5840. ** calls to sqlite3_get_clientdata(D,N) will return a copy of pointer P
  5841. ** or a NULL pointer if there were no prior calls to
  5842. ** sqlite3_set_clientdata() with the same values of D and N.
  5843. ** Names are compared using strcmp() and are thus case sensitive.
  5844. **
  5845. ** If P and X are both non-NULL, then the destructor X is invoked with
  5846. ** argument P on the first of the following occurrences:
  5847. ** <ul>
  5848. ** <li> An out-of-memory error occurs during the call to
  5849. ** sqlite3_set_clientdata() which attempts to register pointer P.
  5850. ** <li> A subsequent call to sqlite3_set_clientdata(D,N,P,X) is made
  5851. ** with the same D and N parameters.
  5852. ** <li> The database connection closes. SQLite does not make any guarantees
  5853. ** about the order in which destructors are called, only that all
  5854. ** destructors will be called exactly once at some point during the
  5855. ** database connection closing process.
  5856. ** </ul>
  5857. **
  5858. ** SQLite does not do anything with client data other than invoke
  5859. ** destructors on the client data at the appropriate time. The intended
  5860. ** use for client data is to provide a mechanism for wrapper libraries
  5861. ** to store additional information about an SQLite database connection.
  5862. **
  5863. ** There is no limit (other than available memory) on the number of different
  5864. ** client data pointers (with different names) that can be attached to a
  5865. ** single database connection. However, the implementation is optimized
  5866. ** for the case of having only one or two different client data names.
  5867. ** Applications and wrapper libraries are discouraged from using more than
  5868. ** one client data name each.
  5869. **
  5870. ** There is no way to enumerate the client data pointers
  5871. ** associated with a database connection. The N parameter can be thought
  5872. ** of as a secret key such that only code that knows the secret key is able
  5873. ** to access the associated data.
  5874. **
  5875. ** Security Warning: These interfaces should not be exposed in scripting
  5876. ** languages or in other circumstances where it might be possible for an
  5877. ** an attacker to invoke them. Any agent that can invoke these interfaces
  5878. ** can probably also take control of the process.
  5879. **
  5880. ** Database connection client data is only available for SQLite
  5881. ** version 3.44.0 ([dateof:3.44.0]) and later.
  5882. **
  5883. ** See also: [sqlite3_set_auxdata()] and [sqlite3_get_auxdata()].
  5884. */
  5885. SQLITE_API void *sqlite3_get_clientdata(sqlite3*,const char*);
  5886. SQLITE_API int sqlite3_set_clientdata(sqlite3*, const char*, void*, void(*)(void*));
  5887. /*
  5888. ** CAPI3REF: Constants Defining Special Destructor Behavior
  5889. **
  5890. ** These are special values for the destructor that is passed in as the
  5891. ** final argument to routines like [sqlite3_result_blob()]. ^If the destructor
  5892. ** argument is SQLITE_STATIC, it means that the content pointer is constant
  5893. ** and will never change. It does not need to be destroyed. ^The
  5894. ** SQLITE_TRANSIENT value means that the content will likely change in
  5895. ** the near future and that SQLite should make its own private copy of
  5896. ** the content before returning.
  5897. **
  5898. ** The typedef is necessary to work around problems in certain
  5899. ** C++ compilers.
  5900. */
  5901. typedef void (*sqlite3_destructor_type)(void*);
  5902. #define SQLITE_STATIC ((sqlite3_destructor_type)0)
  5903. #define SQLITE_TRANSIENT ((sqlite3_destructor_type)-1)
  5904. /*
  5905. ** CAPI3REF: Setting The Result Of An SQL Function
  5906. ** METHOD: sqlite3_context
  5907. **
  5908. ** These routines are used by the xFunc or xFinal callbacks that
  5909. ** implement SQL functions and aggregates. See
  5910. ** [sqlite3_create_function()] and [sqlite3_create_function16()]
  5911. ** for additional information.
  5912. **
  5913. ** These functions work very much like the [parameter binding] family of
  5914. ** functions used to bind values to host parameters in prepared statements.
  5915. ** Refer to the [SQL parameter] documentation for additional information.
  5916. **
  5917. ** ^The sqlite3_result_blob() interface sets the result from
  5918. ** an application-defined function to be the BLOB whose content is pointed
  5919. ** to by the second parameter and which is N bytes long where N is the
  5920. ** third parameter.
  5921. **
  5922. ** ^The sqlite3_result_zeroblob(C,N) and sqlite3_result_zeroblob64(C,N)
  5923. ** interfaces set the result of the application-defined function to be
  5924. ** a BLOB containing all zero bytes and N bytes in size.
  5925. **
  5926. ** ^The sqlite3_result_double() interface sets the result from
  5927. ** an application-defined function to be a floating point value specified
  5928. ** by its 2nd argument.
  5929. **
  5930. ** ^The sqlite3_result_error() and sqlite3_result_error16() functions
  5931. ** cause the implemented SQL function to throw an exception.
  5932. ** ^SQLite uses the string pointed to by the
  5933. ** 2nd parameter of sqlite3_result_error() or sqlite3_result_error16()
  5934. ** as the text of an error message. ^SQLite interprets the error
  5935. ** message string from sqlite3_result_error() as UTF-8. ^SQLite
  5936. ** interprets the string from sqlite3_result_error16() as UTF-16 using
  5937. ** the same [byte-order determination rules] as [sqlite3_bind_text16()].
  5938. ** ^If the third parameter to sqlite3_result_error()
  5939. ** or sqlite3_result_error16() is negative then SQLite takes as the error
  5940. ** message all text up through the first zero character.
  5941. ** ^If the third parameter to sqlite3_result_error() or
  5942. ** sqlite3_result_error16() is non-negative then SQLite takes that many
  5943. ** bytes (not characters) from the 2nd parameter as the error message.
  5944. ** ^The sqlite3_result_error() and sqlite3_result_error16()
  5945. ** routines make a private copy of the error message text before
  5946. ** they return. Hence, the calling function can deallocate or
  5947. ** modify the text after they return without harm.
  5948. ** ^The sqlite3_result_error_code() function changes the error code
  5949. ** returned by SQLite as a result of an error in a function. ^By default,
  5950. ** the error code is SQLITE_ERROR. ^A subsequent call to sqlite3_result_error()
  5951. ** or sqlite3_result_error16() resets the error code to SQLITE_ERROR.
  5952. **
  5953. ** ^The sqlite3_result_error_toobig() interface causes SQLite to throw an
  5954. ** error indicating that a string or BLOB is too long to represent.
  5955. **
  5956. ** ^The sqlite3_result_error_nomem() interface causes SQLite to throw an
  5957. ** error indicating that a memory allocation failed.
  5958. **
  5959. ** ^The sqlite3_result_int() interface sets the return value
  5960. ** of the application-defined function to be the 32-bit signed integer
  5961. ** value given in the 2nd argument.
  5962. ** ^The sqlite3_result_int64() interface sets the return value
  5963. ** of the application-defined function to be the 64-bit signed integer
  5964. ** value given in the 2nd argument.
  5965. **
  5966. ** ^The sqlite3_result_null() interface sets the return value
  5967. ** of the application-defined function to be NULL.
  5968. **
  5969. ** ^The sqlite3_result_text(), sqlite3_result_text16(),
  5970. ** sqlite3_result_text16le(), and sqlite3_result_text16be() interfaces
  5971. ** set the return value of the application-defined function to be
  5972. ** a text string which is represented as UTF-8, UTF-16 native byte order,
  5973. ** UTF-16 little endian, or UTF-16 big endian, respectively.
  5974. ** ^The sqlite3_result_text64() interface sets the return value of an
  5975. ** application-defined function to be a text string in an encoding
  5976. ** specified by the fifth (and last) parameter, which must be one
  5977. ** of [SQLITE_UTF8], [SQLITE_UTF16], [SQLITE_UTF16BE], or [SQLITE_UTF16LE].
  5978. ** ^SQLite takes the text result from the application from
  5979. ** the 2nd parameter of the sqlite3_result_text* interfaces.
  5980. ** ^If the 3rd parameter to any of the sqlite3_result_text* interfaces
  5981. ** other than sqlite3_result_text64() is negative, then SQLite computes
  5982. ** the string length itself by searching the 2nd parameter for the first
  5983. ** zero character.
  5984. ** ^If the 3rd parameter to the sqlite3_result_text* interfaces
  5985. ** is non-negative, then as many bytes (not characters) of the text
  5986. ** pointed to by the 2nd parameter are taken as the application-defined
  5987. ** function result. If the 3rd parameter is non-negative, then it
  5988. ** must be the byte offset into the string where the NUL terminator would
  5989. ** appear if the string where NUL terminated. If any NUL characters occur
  5990. ** in the string at a byte offset that is less than the value of the 3rd
  5991. ** parameter, then the resulting string will contain embedded NULs and the
  5992. ** result of expressions operating on strings with embedded NULs is undefined.
  5993. ** ^If the 4th parameter to the sqlite3_result_text* interfaces
  5994. ** or sqlite3_result_blob is a non-NULL pointer, then SQLite calls that
  5995. ** function as the destructor on the text or BLOB result when it has
  5996. ** finished using that result.
  5997. ** ^If the 4th parameter to the sqlite3_result_text* interfaces or to
  5998. ** sqlite3_result_blob is the special constant SQLITE_STATIC, then SQLite
  5999. ** assumes that the text or BLOB result is in constant space and does not
  6000. ** copy the content of the parameter nor call a destructor on the content
  6001. ** when it has finished using that result.
  6002. ** ^If the 4th parameter to the sqlite3_result_text* interfaces
  6003. ** or sqlite3_result_blob is the special constant SQLITE_TRANSIENT
  6004. ** then SQLite makes a copy of the result into space obtained
  6005. ** from [sqlite3_malloc()] before it returns.
  6006. **
  6007. ** ^For the sqlite3_result_text16(), sqlite3_result_text16le(), and
  6008. ** sqlite3_result_text16be() routines, and for sqlite3_result_text64()
  6009. ** when the encoding is not UTF8, if the input UTF16 begins with a
  6010. ** byte-order mark (BOM, U+FEFF) then the BOM is removed from the
  6011. ** string and the rest of the string is interpreted according to the
  6012. ** byte-order specified by the BOM. ^The byte-order specified by
  6013. ** the BOM at the beginning of the text overrides the byte-order
  6014. ** specified by the interface procedure. ^So, for example, if
  6015. ** sqlite3_result_text16le() is invoked with text that begins
  6016. ** with bytes 0xfe, 0xff (a big-endian byte-order mark) then the
  6017. ** first two bytes of input are skipped and the remaining input
  6018. ** is interpreted as UTF16BE text.
  6019. **
  6020. ** ^For UTF16 input text to the sqlite3_result_text16(),
  6021. ** sqlite3_result_text16be(), sqlite3_result_text16le(), and
  6022. ** sqlite3_result_text64() routines, if the text contains invalid
  6023. ** UTF16 characters, the invalid characters might be converted
  6024. ** into the unicode replacement character, U+FFFD.
  6025. **
  6026. ** ^The sqlite3_result_value() interface sets the result of
  6027. ** the application-defined function to be a copy of the
  6028. ** [unprotected sqlite3_value] object specified by the 2nd parameter. ^The
  6029. ** sqlite3_result_value() interface makes a copy of the [sqlite3_value]
  6030. ** so that the [sqlite3_value] specified in the parameter may change or
  6031. ** be deallocated after sqlite3_result_value() returns without harm.
  6032. ** ^A [protected sqlite3_value] object may always be used where an
  6033. ** [unprotected sqlite3_value] object is required, so either
  6034. ** kind of [sqlite3_value] object can be used with this interface.
  6035. **
  6036. ** ^The sqlite3_result_pointer(C,P,T,D) interface sets the result to an
  6037. ** SQL NULL value, just like [sqlite3_result_null(C)], except that it
  6038. ** also associates the host-language pointer P or type T with that
  6039. ** NULL value such that the pointer can be retrieved within an
  6040. ** [application-defined SQL function] using [sqlite3_value_pointer()].
  6041. ** ^If the D parameter is not NULL, then it is a pointer to a destructor
  6042. ** for the P parameter. ^SQLite invokes D with P as its only argument
  6043. ** when SQLite is finished with P. The T parameter should be a static
  6044. ** string and preferably a string literal. The sqlite3_result_pointer()
  6045. ** routine is part of the [pointer passing interface] added for SQLite 3.20.0.
  6046. **
  6047. ** If these routines are called from within the different thread
  6048. ** than the one containing the application-defined function that received
  6049. ** the [sqlite3_context] pointer, the results are undefined.
  6050. */
  6051. SQLITE_API void sqlite3_result_blob(sqlite3_context*, const void*, int, void(*)(void*));
  6052. SQLITE_API void sqlite3_result_blob64(sqlite3_context*,const void*,
  6053. sqlite3_uint64,void(*)(void*));
  6054. SQLITE_API void sqlite3_result_double(sqlite3_context*, double);
  6055. SQLITE_API void sqlite3_result_error(sqlite3_context*, const char*, int);
  6056. SQLITE_API void sqlite3_result_error16(sqlite3_context*, const void*, int);
  6057. SQLITE_API void sqlite3_result_error_toobig(sqlite3_context*);
  6058. SQLITE_API void sqlite3_result_error_nomem(sqlite3_context*);
  6059. SQLITE_API void sqlite3_result_error_code(sqlite3_context*, int);
  6060. SQLITE_API void sqlite3_result_int(sqlite3_context*, int);
  6061. SQLITE_API void sqlite3_result_int64(sqlite3_context*, sqlite3_int64);
  6062. SQLITE_API void sqlite3_result_null(sqlite3_context*);
  6063. SQLITE_API void sqlite3_result_text(sqlite3_context*, const char*, int, void(*)(void*));
  6064. SQLITE_API void sqlite3_result_text64(sqlite3_context*, const char*,sqlite3_uint64,
  6065. void(*)(void*), unsigned char encoding);
  6066. SQLITE_API void sqlite3_result_text16(sqlite3_context*, const void*, int, void(*)(void*));
  6067. SQLITE_API void sqlite3_result_text16le(sqlite3_context*, const void*, int,void(*)(void*));
  6068. SQLITE_API void sqlite3_result_text16be(sqlite3_context*, const void*, int,void(*)(void*));
  6069. SQLITE_API void sqlite3_result_value(sqlite3_context*, sqlite3_value*);
  6070. SQLITE_API void sqlite3_result_pointer(sqlite3_context*, void*,const char*,void(*)(void*));
  6071. SQLITE_API void sqlite3_result_zeroblob(sqlite3_context*, int n);
  6072. SQLITE_API int sqlite3_result_zeroblob64(sqlite3_context*, sqlite3_uint64 n);
  6073. /*
  6074. ** CAPI3REF: Setting The Subtype Of An SQL Function
  6075. ** METHOD: sqlite3_context
  6076. **
  6077. ** The sqlite3_result_subtype(C,T) function causes the subtype of
  6078. ** the result from the [application-defined SQL function] with
  6079. ** [sqlite3_context] C to be the value T. Only the lower 8 bits
  6080. ** of the subtype T are preserved in current versions of SQLite;
  6081. ** higher order bits are discarded.
  6082. ** The number of subtype bytes preserved by SQLite might increase
  6083. ** in future releases of SQLite.
  6084. */
  6085. SQLITE_API void sqlite3_result_subtype(sqlite3_context*,unsigned int);
  6086. /*
  6087. ** CAPI3REF: Define New Collating Sequences
  6088. ** METHOD: sqlite3
  6089. **
  6090. ** ^These functions add, remove, or modify a [collation] associated
  6091. ** with the [database connection] specified as the first argument.
  6092. **
  6093. ** ^The name of the collation is a UTF-8 string
  6094. ** for sqlite3_create_collation() and sqlite3_create_collation_v2()
  6095. ** and a UTF-16 string in native byte order for sqlite3_create_collation16().
  6096. ** ^Collation names that compare equal according to [sqlite3_strnicmp()] are
  6097. ** considered to be the same name.
  6098. **
  6099. ** ^(The third argument (eTextRep) must be one of the constants:
  6100. ** <ul>
  6101. ** <li> [SQLITE_UTF8],
  6102. ** <li> [SQLITE_UTF16LE],
  6103. ** <li> [SQLITE_UTF16BE],
  6104. ** <li> [SQLITE_UTF16], or
  6105. ** <li> [SQLITE_UTF16_ALIGNED].
  6106. ** </ul>)^
  6107. ** ^The eTextRep argument determines the encoding of strings passed
  6108. ** to the collating function callback, xCompare.
  6109. ** ^The [SQLITE_UTF16] and [SQLITE_UTF16_ALIGNED] values for eTextRep
  6110. ** force strings to be UTF16 with native byte order.
  6111. ** ^The [SQLITE_UTF16_ALIGNED] value for eTextRep forces strings to begin
  6112. ** on an even byte address.
  6113. **
  6114. ** ^The fourth argument, pArg, is an application data pointer that is passed
  6115. ** through as the first argument to the collating function callback.
  6116. **
  6117. ** ^The fifth argument, xCompare, is a pointer to the collating function.
  6118. ** ^Multiple collating functions can be registered using the same name but
  6119. ** with different eTextRep parameters and SQLite will use whichever
  6120. ** function requires the least amount of data transformation.
  6121. ** ^If the xCompare argument is NULL then the collating function is
  6122. ** deleted. ^When all collating functions having the same name are deleted,
  6123. ** that collation is no longer usable.
  6124. **
  6125. ** ^The collating function callback is invoked with a copy of the pArg
  6126. ** application data pointer and with two strings in the encoding specified
  6127. ** by the eTextRep argument. The two integer parameters to the collating
  6128. ** function callback are the length of the two strings, in bytes. The collating
  6129. ** function must return an integer that is negative, zero, or positive
  6130. ** if the first string is less than, equal to, or greater than the second,
  6131. ** respectively. A collating function must always return the same answer
  6132. ** given the same inputs. If two or more collating functions are registered
  6133. ** to the same collation name (using different eTextRep values) then all
  6134. ** must give an equivalent answer when invoked with equivalent strings.
  6135. ** The collating function must obey the following properties for all
  6136. ** strings A, B, and C:
  6137. **
  6138. ** <ol>
  6139. ** <li> If A==B then B==A.
  6140. ** <li> If A==B and B==C then A==C.
  6141. ** <li> If A&lt;B THEN B&gt;A.
  6142. ** <li> If A&lt;B and B&lt;C then A&lt;C.
  6143. ** </ol>
  6144. **
  6145. ** If a collating function fails any of the above constraints and that
  6146. ** collating function is registered and used, then the behavior of SQLite
  6147. ** is undefined.
  6148. **
  6149. ** ^The sqlite3_create_collation_v2() works like sqlite3_create_collation()
  6150. ** with the addition that the xDestroy callback is invoked on pArg when
  6151. ** the collating function is deleted.
  6152. ** ^Collating functions are deleted when they are overridden by later
  6153. ** calls to the collation creation functions or when the
  6154. ** [database connection] is closed using [sqlite3_close()].
  6155. **
  6156. ** ^The xDestroy callback is <u>not</u> called if the
  6157. ** sqlite3_create_collation_v2() function fails. Applications that invoke
  6158. ** sqlite3_create_collation_v2() with a non-NULL xDestroy argument should
  6159. ** check the return code and dispose of the application data pointer
  6160. ** themselves rather than expecting SQLite to deal with it for them.
  6161. ** This is different from every other SQLite interface. The inconsistency
  6162. ** is unfortunate but cannot be changed without breaking backwards
  6163. ** compatibility.
  6164. **
  6165. ** See also: [sqlite3_collation_needed()] and [sqlite3_collation_needed16()].
  6166. */
  6167. SQLITE_API int sqlite3_create_collation(
  6168. sqlite3*,
  6169. const char *zName,
  6170. int eTextRep,
  6171. void *pArg,
  6172. int(*xCompare)(void*,int,const void*,int,const void*)
  6173. );
  6174. SQLITE_API int sqlite3_create_collation_v2(
  6175. sqlite3*,
  6176. const char *zName,
  6177. int eTextRep,
  6178. void *pArg,
  6179. int(*xCompare)(void*,int,const void*,int,const void*),
  6180. void(*xDestroy)(void*)
  6181. );
  6182. SQLITE_API int sqlite3_create_collation16(
  6183. sqlite3*,
  6184. const void *zName,
  6185. int eTextRep,
  6186. void *pArg,
  6187. int(*xCompare)(void*,int,const void*,int,const void*)
  6188. );
  6189. /*
  6190. ** CAPI3REF: Collation Needed Callbacks
  6191. ** METHOD: sqlite3
  6192. **
  6193. ** ^To avoid having to register all collation sequences before a database
  6194. ** can be used, a single callback function may be registered with the
  6195. ** [database connection] to be invoked whenever an undefined collation
  6196. ** sequence is required.
  6197. **
  6198. ** ^If the function is registered using the sqlite3_collation_needed() API,
  6199. ** then it is passed the names of undefined collation sequences as strings
  6200. ** encoded in UTF-8. ^If sqlite3_collation_needed16() is used,
  6201. ** the names are passed as UTF-16 in machine native byte order.
  6202. ** ^A call to either function replaces the existing collation-needed callback.
  6203. **
  6204. ** ^(When the callback is invoked, the first argument passed is a copy
  6205. ** of the second argument to sqlite3_collation_needed() or
  6206. ** sqlite3_collation_needed16(). The second argument is the database
  6207. ** connection. The third argument is one of [SQLITE_UTF8], [SQLITE_UTF16BE],
  6208. ** or [SQLITE_UTF16LE], indicating the most desirable form of the collation
  6209. ** sequence function required. The fourth parameter is the name of the
  6210. ** required collation sequence.)^
  6211. **
  6212. ** The callback function should register the desired collation using
  6213. ** [sqlite3_create_collation()], [sqlite3_create_collation16()], or
  6214. ** [sqlite3_create_collation_v2()].
  6215. */
  6216. SQLITE_API int sqlite3_collation_needed(
  6217. sqlite3*,
  6218. void*,
  6219. void(*)(void*,sqlite3*,int eTextRep,const char*)
  6220. );
  6221. SQLITE_API int sqlite3_collation_needed16(
  6222. sqlite3*,
  6223. void*,
  6224. void(*)(void*,sqlite3*,int eTextRep,const void*)
  6225. );
  6226. #ifdef SQLITE_ENABLE_CEROD
  6227. /*
  6228. ** Specify the activation key for a CEROD database. Unless
  6229. ** activated, none of the CEROD routines will work.
  6230. */
  6231. SQLITE_API void sqlite3_activate_cerod(
  6232. const char *zPassPhrase /* Activation phrase */
  6233. );
  6234. #endif
  6235. /*
  6236. ** CAPI3REF: Suspend Execution For A Short Time
  6237. **
  6238. ** The sqlite3_sleep() function causes the current thread to suspend execution
  6239. ** for at least a number of milliseconds specified in its parameter.
  6240. **
  6241. ** If the operating system does not support sleep requests with
  6242. ** millisecond time resolution, then the time will be rounded up to
  6243. ** the nearest second. The number of milliseconds of sleep actually
  6244. ** requested from the operating system is returned.
  6245. **
  6246. ** ^SQLite implements this interface by calling the xSleep()
  6247. ** method of the default [sqlite3_vfs] object. If the xSleep() method
  6248. ** of the default VFS is not implemented correctly, or not implemented at
  6249. ** all, then the behavior of sqlite3_sleep() may deviate from the description
  6250. ** in the previous paragraphs.
  6251. **
  6252. ** If a negative argument is passed to sqlite3_sleep() the results vary by
  6253. ** VFS and operating system. Some system treat a negative argument as an
  6254. ** instruction to sleep forever. Others understand it to mean do not sleep
  6255. ** at all. ^In SQLite version 3.42.0 and later, a negative
  6256. ** argument passed into sqlite3_sleep() is changed to zero before it is relayed
  6257. ** down into the xSleep method of the VFS.
  6258. */
  6259. SQLITE_API int sqlite3_sleep(int);
  6260. /*
  6261. ** CAPI3REF: Name Of The Folder Holding Temporary Files
  6262. **
  6263. ** ^(If this global variable is made to point to a string which is
  6264. ** the name of a folder (a.k.a. directory), then all temporary files
  6265. ** created by SQLite when using a built-in [sqlite3_vfs | VFS]
  6266. ** will be placed in that directory.)^ ^If this variable
  6267. ** is a NULL pointer, then SQLite performs a search for an appropriate
  6268. ** temporary file directory.
  6269. **
  6270. ** Applications are strongly discouraged from using this global variable.
  6271. ** It is required to set a temporary folder on Windows Runtime (WinRT).
  6272. ** But for all other platforms, it is highly recommended that applications
  6273. ** neither read nor write this variable. This global variable is a relic
  6274. ** that exists for backwards compatibility of legacy applications and should
  6275. ** be avoided in new projects.
  6276. **
  6277. ** It is not safe to read or modify this variable in more than one
  6278. ** thread at a time. It is not safe to read or modify this variable
  6279. ** if a [database connection] is being used at the same time in a separate
  6280. ** thread.
  6281. ** It is intended that this variable be set once
  6282. ** as part of process initialization and before any SQLite interface
  6283. ** routines have been called and that this variable remain unchanged
  6284. ** thereafter.
  6285. **
  6286. ** ^The [temp_store_directory pragma] may modify this variable and cause
  6287. ** it to point to memory obtained from [sqlite3_malloc]. ^Furthermore,
  6288. ** the [temp_store_directory pragma] always assumes that any string
  6289. ** that this variable points to is held in memory obtained from
  6290. ** [sqlite3_malloc] and the pragma may attempt to free that memory
  6291. ** using [sqlite3_free].
  6292. ** Hence, if this variable is modified directly, either it should be
  6293. ** made NULL or made to point to memory obtained from [sqlite3_malloc]
  6294. ** or else the use of the [temp_store_directory pragma] should be avoided.
  6295. ** Except when requested by the [temp_store_directory pragma], SQLite
  6296. ** does not free the memory that sqlite3_temp_directory points to. If
  6297. ** the application wants that memory to be freed, it must do
  6298. ** so itself, taking care to only do so after all [database connection]
  6299. ** objects have been destroyed.
  6300. **
  6301. ** <b>Note to Windows Runtime users:</b> The temporary directory must be set
  6302. ** prior to calling [sqlite3_open] or [sqlite3_open_v2]. Otherwise, various
  6303. ** features that require the use of temporary files may fail. Here is an
  6304. ** example of how to do this using C++ with the Windows Runtime:
  6305. **
  6306. ** <blockquote><pre>
  6307. ** LPCWSTR zPath = Windows::Storage::ApplicationData::Current->
  6308. ** &nbsp; TemporaryFolder->Path->Data();
  6309. ** char zPathBuf&#91;MAX_PATH + 1&#93;;
  6310. ** memset(zPathBuf, 0, sizeof(zPathBuf));
  6311. ** WideCharToMultiByte(CP_UTF8, 0, zPath, -1, zPathBuf, sizeof(zPathBuf),
  6312. ** &nbsp; NULL, NULL);
  6313. ** sqlite3_temp_directory = sqlite3_mprintf("%s", zPathBuf);
  6314. ** </pre></blockquote>
  6315. */
  6316. SQLITE_API SQLITE_EXTERN char *sqlite3_temp_directory;
  6317. /*
  6318. ** CAPI3REF: Name Of The Folder Holding Database Files
  6319. **
  6320. ** ^(If this global variable is made to point to a string which is
  6321. ** the name of a folder (a.k.a. directory), then all database files
  6322. ** specified with a relative pathname and created or accessed by
  6323. ** SQLite when using a built-in windows [sqlite3_vfs | VFS] will be assumed
  6324. ** to be relative to that directory.)^ ^If this variable is a NULL
  6325. ** pointer, then SQLite assumes that all database files specified
  6326. ** with a relative pathname are relative to the current directory
  6327. ** for the process. Only the windows VFS makes use of this global
  6328. ** variable; it is ignored by the unix VFS.
  6329. **
  6330. ** Changing the value of this variable while a database connection is
  6331. ** open can result in a corrupt database.
  6332. **
  6333. ** It is not safe to read or modify this variable in more than one
  6334. ** thread at a time. It is not safe to read or modify this variable
  6335. ** if a [database connection] is being used at the same time in a separate
  6336. ** thread.
  6337. ** It is intended that this variable be set once
  6338. ** as part of process initialization and before any SQLite interface
  6339. ** routines have been called and that this variable remain unchanged
  6340. ** thereafter.
  6341. **
  6342. ** ^The [data_store_directory pragma] may modify this variable and cause
  6343. ** it to point to memory obtained from [sqlite3_malloc]. ^Furthermore,
  6344. ** the [data_store_directory pragma] always assumes that any string
  6345. ** that this variable points to is held in memory obtained from
  6346. ** [sqlite3_malloc] and the pragma may attempt to free that memory
  6347. ** using [sqlite3_free].
  6348. ** Hence, if this variable is modified directly, either it should be
  6349. ** made NULL or made to point to memory obtained from [sqlite3_malloc]
  6350. ** or else the use of the [data_store_directory pragma] should be avoided.
  6351. */
  6352. SQLITE_API SQLITE_EXTERN char *sqlite3_data_directory;
  6353. /*
  6354. ** CAPI3REF: Win32 Specific Interface
  6355. **
  6356. ** These interfaces are available only on Windows. The
  6357. ** [sqlite3_win32_set_directory] interface is used to set the value associated
  6358. ** with the [sqlite3_temp_directory] or [sqlite3_data_directory] variable, to
  6359. ** zValue, depending on the value of the type parameter. The zValue parameter
  6360. ** should be NULL to cause the previous value to be freed via [sqlite3_free];
  6361. ** a non-NULL value will be copied into memory obtained from [sqlite3_malloc]
  6362. ** prior to being used. The [sqlite3_win32_set_directory] interface returns
  6363. ** [SQLITE_OK] to indicate success, [SQLITE_ERROR] if the type is unsupported,
  6364. ** or [SQLITE_NOMEM] if memory could not be allocated. The value of the
  6365. ** [sqlite3_data_directory] variable is intended to act as a replacement for
  6366. ** the current directory on the sub-platforms of Win32 where that concept is
  6367. ** not present, e.g. WinRT and UWP. The [sqlite3_win32_set_directory8] and
  6368. ** [sqlite3_win32_set_directory16] interfaces behave exactly the same as the
  6369. ** sqlite3_win32_set_directory interface except the string parameter must be
  6370. ** UTF-8 or UTF-16, respectively.
  6371. */
  6372. SQLITE_API int sqlite3_win32_set_directory(
  6373. unsigned long type, /* Identifier for directory being set or reset */
  6374. void *zValue /* New value for directory being set or reset */
  6375. );
  6376. SQLITE_API int sqlite3_win32_set_directory8(unsigned long type, const char *zValue);
  6377. SQLITE_API int sqlite3_win32_set_directory16(unsigned long type, const void *zValue);
  6378. /*
  6379. ** CAPI3REF: Win32 Directory Types
  6380. **
  6381. ** These macros are only available on Windows. They define the allowed values
  6382. ** for the type argument to the [sqlite3_win32_set_directory] interface.
  6383. */
  6384. #define SQLITE_WIN32_DATA_DIRECTORY_TYPE 1
  6385. #define SQLITE_WIN32_TEMP_DIRECTORY_TYPE 2
  6386. /*
  6387. ** CAPI3REF: Test For Auto-Commit Mode
  6388. ** KEYWORDS: {autocommit mode}
  6389. ** METHOD: sqlite3
  6390. **
  6391. ** ^The sqlite3_get_autocommit() interface returns non-zero or
  6392. ** zero if the given database connection is or is not in autocommit mode,
  6393. ** respectively. ^Autocommit mode is on by default.
  6394. ** ^Autocommit mode is disabled by a [BEGIN] statement.
  6395. ** ^Autocommit mode is re-enabled by a [COMMIT] or [ROLLBACK].
  6396. **
  6397. ** If certain kinds of errors occur on a statement within a multi-statement
  6398. ** transaction (errors including [SQLITE_FULL], [SQLITE_IOERR],
  6399. ** [SQLITE_NOMEM], [SQLITE_BUSY], and [SQLITE_INTERRUPT]) then the
  6400. ** transaction might be rolled back automatically. The only way to
  6401. ** find out whether SQLite automatically rolled back the transaction after
  6402. ** an error is to use this function.
  6403. **
  6404. ** If another thread changes the autocommit status of the database
  6405. ** connection while this routine is running, then the return value
  6406. ** is undefined.
  6407. */
  6408. SQLITE_API int sqlite3_get_autocommit(sqlite3*);
  6409. /*
  6410. ** CAPI3REF: Find The Database Handle Of A Prepared Statement
  6411. ** METHOD: sqlite3_stmt
  6412. **
  6413. ** ^The sqlite3_db_handle interface returns the [database connection] handle
  6414. ** to which a [prepared statement] belongs. ^The [database connection]
  6415. ** returned by sqlite3_db_handle is the same [database connection]
  6416. ** that was the first argument
  6417. ** to the [sqlite3_prepare_v2()] call (or its variants) that was used to
  6418. ** create the statement in the first place.
  6419. */
  6420. SQLITE_API sqlite3 *sqlite3_db_handle(sqlite3_stmt*);
  6421. /*
  6422. ** CAPI3REF: Return The Schema Name For A Database Connection
  6423. ** METHOD: sqlite3
  6424. **
  6425. ** ^The sqlite3_db_name(D,N) interface returns a pointer to the schema name
  6426. ** for the N-th database on database connection D, or a NULL pointer of N is
  6427. ** out of range. An N value of 0 means the main database file. An N of 1 is
  6428. ** the "temp" schema. Larger values of N correspond to various ATTACH-ed
  6429. ** databases.
  6430. **
  6431. ** Space to hold the string that is returned by sqlite3_db_name() is managed
  6432. ** by SQLite itself. The string might be deallocated by any operation that
  6433. ** changes the schema, including [ATTACH] or [DETACH] or calls to
  6434. ** [sqlite3_serialize()] or [sqlite3_deserialize()], even operations that
  6435. ** occur on a different thread. Applications that need to
  6436. ** remember the string long-term should make their own copy. Applications that
  6437. ** are accessing the same database connection simultaneously on multiple
  6438. ** threads should mutex-protect calls to this API and should make their own
  6439. ** private copy of the result prior to releasing the mutex.
  6440. */
  6441. SQLITE_API const char *sqlite3_db_name(sqlite3 *db, int N);
  6442. /*
  6443. ** CAPI3REF: Return The Filename For A Database Connection
  6444. ** METHOD: sqlite3
  6445. **
  6446. ** ^The sqlite3_db_filename(D,N) interface returns a pointer to the filename
  6447. ** associated with database N of connection D.
  6448. ** ^If there is no attached database N on the database
  6449. ** connection D, or if database N is a temporary or in-memory database, then
  6450. ** this function will return either a NULL pointer or an empty string.
  6451. **
  6452. ** ^The string value returned by this routine is owned and managed by
  6453. ** the database connection. ^The value will be valid until the database N
  6454. ** is [DETACH]-ed or until the database connection closes.
  6455. **
  6456. ** ^The filename returned by this function is the output of the
  6457. ** xFullPathname method of the [VFS]. ^In other words, the filename
  6458. ** will be an absolute pathname, even if the filename used
  6459. ** to open the database originally was a URI or relative pathname.
  6460. **
  6461. ** If the filename pointer returned by this routine is not NULL, then it
  6462. ** can be used as the filename input parameter to these routines:
  6463. ** <ul>
  6464. ** <li> [sqlite3_uri_parameter()]
  6465. ** <li> [sqlite3_uri_boolean()]
  6466. ** <li> [sqlite3_uri_int64()]
  6467. ** <li> [sqlite3_filename_database()]
  6468. ** <li> [sqlite3_filename_journal()]
  6469. ** <li> [sqlite3_filename_wal()]
  6470. ** </ul>
  6471. */
  6472. SQLITE_API sqlite3_filename sqlite3_db_filename(sqlite3 *db, const char *zDbName);
  6473. /*
  6474. ** CAPI3REF: Determine if a database is read-only
  6475. ** METHOD: sqlite3
  6476. **
  6477. ** ^The sqlite3_db_readonly(D,N) interface returns 1 if the database N
  6478. ** of connection D is read-only, 0 if it is read/write, or -1 if N is not
  6479. ** the name of a database on connection D.
  6480. */
  6481. SQLITE_API int sqlite3_db_readonly(sqlite3 *db, const char *zDbName);
  6482. /*
  6483. ** CAPI3REF: Determine the transaction state of a database
  6484. ** METHOD: sqlite3
  6485. **
  6486. ** ^The sqlite3_txn_state(D,S) interface returns the current
  6487. ** [transaction state] of schema S in database connection D. ^If S is NULL,
  6488. ** then the highest transaction state of any schema on database connection D
  6489. ** is returned. Transaction states are (in order of lowest to highest):
  6490. ** <ol>
  6491. ** <li value="0"> SQLITE_TXN_NONE
  6492. ** <li value="1"> SQLITE_TXN_READ
  6493. ** <li value="2"> SQLITE_TXN_WRITE
  6494. ** </ol>
  6495. ** ^If the S argument to sqlite3_txn_state(D,S) is not the name of
  6496. ** a valid schema, then -1 is returned.
  6497. */
  6498. SQLITE_API int sqlite3_txn_state(sqlite3*,const char *zSchema);
  6499. /*
  6500. ** CAPI3REF: Allowed return values from sqlite3_txn_state()
  6501. ** KEYWORDS: {transaction state}
  6502. **
  6503. ** These constants define the current transaction state of a database file.
  6504. ** ^The [sqlite3_txn_state(D,S)] interface returns one of these
  6505. ** constants in order to describe the transaction state of schema S
  6506. ** in [database connection] D.
  6507. **
  6508. ** <dl>
  6509. ** [[SQLITE_TXN_NONE]] <dt>SQLITE_TXN_NONE</dt>
  6510. ** <dd>The SQLITE_TXN_NONE state means that no transaction is currently
  6511. ** pending.</dd>
  6512. **
  6513. ** [[SQLITE_TXN_READ]] <dt>SQLITE_TXN_READ</dt>
  6514. ** <dd>The SQLITE_TXN_READ state means that the database is currently
  6515. ** in a read transaction. Content has been read from the database file
  6516. ** but nothing in the database file has changed. The transaction state
  6517. ** will advanced to SQLITE_TXN_WRITE if any changes occur and there are
  6518. ** no other conflicting concurrent write transactions. The transaction
  6519. ** state will revert to SQLITE_TXN_NONE following a [ROLLBACK] or
  6520. ** [COMMIT].</dd>
  6521. **
  6522. ** [[SQLITE_TXN_WRITE]] <dt>SQLITE_TXN_WRITE</dt>
  6523. ** <dd>The SQLITE_TXN_WRITE state means that the database is currently
  6524. ** in a write transaction. Content has been written to the database file
  6525. ** but has not yet committed. The transaction state will change to
  6526. ** to SQLITE_TXN_NONE at the next [ROLLBACK] or [COMMIT].</dd>
  6527. */
  6528. #define SQLITE_TXN_NONE 0
  6529. #define SQLITE_TXN_READ 1
  6530. #define SQLITE_TXN_WRITE 2
  6531. /*
  6532. ** CAPI3REF: Find the next prepared statement
  6533. ** METHOD: sqlite3
  6534. **
  6535. ** ^This interface returns a pointer to the next [prepared statement] after
  6536. ** pStmt associated with the [database connection] pDb. ^If pStmt is NULL
  6537. ** then this interface returns a pointer to the first prepared statement
  6538. ** associated with the database connection pDb. ^If no prepared statement
  6539. ** satisfies the conditions of this routine, it returns NULL.
  6540. **
  6541. ** The [database connection] pointer D in a call to
  6542. ** [sqlite3_next_stmt(D,S)] must refer to an open database
  6543. ** connection and in particular must not be a NULL pointer.
  6544. */
  6545. SQLITE_API sqlite3_stmt *sqlite3_next_stmt(sqlite3 *pDb, sqlite3_stmt *pStmt);
  6546. /*
  6547. ** CAPI3REF: Commit And Rollback Notification Callbacks
  6548. ** METHOD: sqlite3
  6549. **
  6550. ** ^The sqlite3_commit_hook() interface registers a callback
  6551. ** function to be invoked whenever a transaction is [COMMIT | committed].
  6552. ** ^Any callback set by a previous call to sqlite3_commit_hook()
  6553. ** for the same database connection is overridden.
  6554. ** ^The sqlite3_rollback_hook() interface registers a callback
  6555. ** function to be invoked whenever a transaction is [ROLLBACK | rolled back].
  6556. ** ^Any callback set by a previous call to sqlite3_rollback_hook()
  6557. ** for the same database connection is overridden.
  6558. ** ^The pArg argument is passed through to the callback.
  6559. ** ^If the callback on a commit hook function returns non-zero,
  6560. ** then the commit is converted into a rollback.
  6561. **
  6562. ** ^The sqlite3_commit_hook(D,C,P) and sqlite3_rollback_hook(D,C,P) functions
  6563. ** return the P argument from the previous call of the same function
  6564. ** on the same [database connection] D, or NULL for
  6565. ** the first call for each function on D.
  6566. **
  6567. ** The commit and rollback hook callbacks are not reentrant.
  6568. ** The callback implementation must not do anything that will modify
  6569. ** the database connection that invoked the callback. Any actions
  6570. ** to modify the database connection must be deferred until after the
  6571. ** completion of the [sqlite3_step()] call that triggered the commit
  6572. ** or rollback hook in the first place.
  6573. ** Note that running any other SQL statements, including SELECT statements,
  6574. ** or merely calling [sqlite3_prepare_v2()] and [sqlite3_step()] will modify
  6575. ** the database connections for the meaning of "modify" in this paragraph.
  6576. **
  6577. ** ^Registering a NULL function disables the callback.
  6578. **
  6579. ** ^When the commit hook callback routine returns zero, the [COMMIT]
  6580. ** operation is allowed to continue normally. ^If the commit hook
  6581. ** returns non-zero, then the [COMMIT] is converted into a [ROLLBACK].
  6582. ** ^The rollback hook is invoked on a rollback that results from a commit
  6583. ** hook returning non-zero, just as it would be with any other rollback.
  6584. **
  6585. ** ^For the purposes of this API, a transaction is said to have been
  6586. ** rolled back if an explicit "ROLLBACK" statement is executed, or
  6587. ** an error or constraint causes an implicit rollback to occur.
  6588. ** ^The rollback callback is not invoked if a transaction is
  6589. ** automatically rolled back because the database connection is closed.
  6590. **
  6591. ** See also the [sqlite3_update_hook()] interface.
  6592. */
  6593. SQLITE_API void *sqlite3_commit_hook(sqlite3*, int(*)(void*), void*);
  6594. SQLITE_API void *sqlite3_rollback_hook(sqlite3*, void(*)(void *), void*);
  6595. /*
  6596. ** CAPI3REF: Autovacuum Compaction Amount Callback
  6597. ** METHOD: sqlite3
  6598. **
  6599. ** ^The sqlite3_autovacuum_pages(D,C,P,X) interface registers a callback
  6600. ** function C that is invoked prior to each autovacuum of the database
  6601. ** file. ^The callback is passed a copy of the generic data pointer (P),
  6602. ** the schema-name of the attached database that is being autovacuumed,
  6603. ** the size of the database file in pages, the number of free pages,
  6604. ** and the number of bytes per page, respectively. The callback should
  6605. ** return the number of free pages that should be removed by the
  6606. ** autovacuum. ^If the callback returns zero, then no autovacuum happens.
  6607. ** ^If the value returned is greater than or equal to the number of
  6608. ** free pages, then a complete autovacuum happens.
  6609. **
  6610. ** <p>^If there are multiple ATTACH-ed database files that are being
  6611. ** modified as part of a transaction commit, then the autovacuum pages
  6612. ** callback is invoked separately for each file.
  6613. **
  6614. ** <p><b>The callback is not reentrant.</b> The callback function should
  6615. ** not attempt to invoke any other SQLite interface. If it does, bad
  6616. ** things may happen, including segmentation faults and corrupt database
  6617. ** files. The callback function should be a simple function that
  6618. ** does some arithmetic on its input parameters and returns a result.
  6619. **
  6620. ** ^The X parameter to sqlite3_autovacuum_pages(D,C,P,X) is an optional
  6621. ** destructor for the P parameter. ^If X is not NULL, then X(P) is
  6622. ** invoked whenever the database connection closes or when the callback
  6623. ** is overwritten by another invocation of sqlite3_autovacuum_pages().
  6624. **
  6625. ** <p>^There is only one autovacuum pages callback per database connection.
  6626. ** ^Each call to the sqlite3_autovacuum_pages() interface overrides all
  6627. ** previous invocations for that database connection. ^If the callback
  6628. ** argument (C) to sqlite3_autovacuum_pages(D,C,P,X) is a NULL pointer,
  6629. ** then the autovacuum steps callback is canceled. The return value
  6630. ** from sqlite3_autovacuum_pages() is normally SQLITE_OK, but might
  6631. ** be some other error code if something goes wrong. The current
  6632. ** implementation will only return SQLITE_OK or SQLITE_MISUSE, but other
  6633. ** return codes might be added in future releases.
  6634. **
  6635. ** <p>If no autovacuum pages callback is specified (the usual case) or
  6636. ** a NULL pointer is provided for the callback,
  6637. ** then the default behavior is to vacuum all free pages. So, in other
  6638. ** words, the default behavior is the same as if the callback function
  6639. ** were something like this:
  6640. **
  6641. ** <blockquote><pre>
  6642. ** &nbsp; unsigned int demonstration_autovac_pages_callback(
  6643. ** &nbsp; void *pClientData,
  6644. ** &nbsp; const char *zSchema,
  6645. ** &nbsp; unsigned int nDbPage,
  6646. ** &nbsp; unsigned int nFreePage,
  6647. ** &nbsp; unsigned int nBytePerPage
  6648. ** &nbsp; ){
  6649. ** &nbsp; return nFreePage;
  6650. ** &nbsp; }
  6651. ** </pre></blockquote>
  6652. */
  6653. SQLITE_API int sqlite3_autovacuum_pages(
  6654. sqlite3 *db,
  6655. unsigned int(*)(void*,const char*,unsigned int,unsigned int,unsigned int),
  6656. void*,
  6657. void(*)(void*)
  6658. );
  6659. /*
  6660. ** CAPI3REF: Data Change Notification Callbacks
  6661. ** METHOD: sqlite3
  6662. **
  6663. ** ^The sqlite3_update_hook() interface registers a callback function
  6664. ** with the [database connection] identified by the first argument
  6665. ** to be invoked whenever a row is updated, inserted or deleted in
  6666. ** a [rowid table].
  6667. ** ^Any callback set by a previous call to this function
  6668. ** for the same database connection is overridden.
  6669. **
  6670. ** ^The second argument is a pointer to the function to invoke when a
  6671. ** row is updated, inserted or deleted in a rowid table.
  6672. ** ^The first argument to the callback is a copy of the third argument
  6673. ** to sqlite3_update_hook().
  6674. ** ^The second callback argument is one of [SQLITE_INSERT], [SQLITE_DELETE],
  6675. ** or [SQLITE_UPDATE], depending on the operation that caused the callback
  6676. ** to be invoked.
  6677. ** ^The third and fourth arguments to the callback contain pointers to the
  6678. ** database and table name containing the affected row.
  6679. ** ^The final callback parameter is the [rowid] of the row.
  6680. ** ^In the case of an update, this is the [rowid] after the update takes place.
  6681. **
  6682. ** ^(The update hook is not invoked when internal system tables are
  6683. ** modified (i.e. sqlite_sequence).)^
  6684. ** ^The update hook is not invoked when [WITHOUT ROWID] tables are modified.
  6685. **
  6686. ** ^In the current implementation, the update hook
  6687. ** is not invoked when conflicting rows are deleted because of an
  6688. ** [ON CONFLICT | ON CONFLICT REPLACE] clause. ^Nor is the update hook
  6689. ** invoked when rows are deleted using the [truncate optimization].
  6690. ** The exceptions defined in this paragraph might change in a future
  6691. ** release of SQLite.
  6692. **
  6693. ** The update hook implementation must not do anything that will modify
  6694. ** the database connection that invoked the update hook. Any actions
  6695. ** to modify the database connection must be deferred until after the
  6696. ** completion of the [sqlite3_step()] call that triggered the update hook.
  6697. ** Note that [sqlite3_prepare_v2()] and [sqlite3_step()] both modify their
  6698. ** database connections for the meaning of "modify" in this paragraph.
  6699. **
  6700. ** ^The sqlite3_update_hook(D,C,P) function
  6701. ** returns the P argument from the previous call
  6702. ** on the same [database connection] D, or NULL for
  6703. ** the first call on D.
  6704. **
  6705. ** See also the [sqlite3_commit_hook()], [sqlite3_rollback_hook()],
  6706. ** and [sqlite3_preupdate_hook()] interfaces.
  6707. */
  6708. SQLITE_API void *sqlite3_update_hook(
  6709. sqlite3*,
  6710. void(*)(void *,int ,char const *,char const *,sqlite3_int64),
  6711. void*
  6712. );
  6713. /*
  6714. ** CAPI3REF: Enable Or Disable Shared Pager Cache
  6715. **
  6716. ** ^(This routine enables or disables the sharing of the database cache
  6717. ** and schema data structures between [database connection | connections]
  6718. ** to the same database. Sharing is enabled if the argument is true
  6719. ** and disabled if the argument is false.)^
  6720. **
  6721. ** This interface is omitted if SQLite is compiled with
  6722. ** [-DSQLITE_OMIT_SHARED_CACHE]. The [-DSQLITE_OMIT_SHARED_CACHE]
  6723. ** compile-time option is recommended because the
  6724. ** [use of shared cache mode is discouraged].
  6725. **
  6726. ** ^Cache sharing is enabled and disabled for an entire process.
  6727. ** This is a change as of SQLite [version 3.5.0] ([dateof:3.5.0]).
  6728. ** In prior versions of SQLite,
  6729. ** sharing was enabled or disabled for each thread separately.
  6730. **
  6731. ** ^(The cache sharing mode set by this interface effects all subsequent
  6732. ** calls to [sqlite3_open()], [sqlite3_open_v2()], and [sqlite3_open16()].
  6733. ** Existing database connections continue to use the sharing mode
  6734. ** that was in effect at the time they were opened.)^
  6735. **
  6736. ** ^(This routine returns [SQLITE_OK] if shared cache was enabled or disabled
  6737. ** successfully. An [error code] is returned otherwise.)^
  6738. **
  6739. ** ^Shared cache is disabled by default. It is recommended that it stay
  6740. ** that way. In other words, do not use this routine. This interface
  6741. ** continues to be provided for historical compatibility, but its use is
  6742. ** discouraged. Any use of shared cache is discouraged. If shared cache
  6743. ** must be used, it is recommended that shared cache only be enabled for
  6744. ** individual database connections using the [sqlite3_open_v2()] interface
  6745. ** with the [SQLITE_OPEN_SHAREDCACHE] flag.
  6746. **
  6747. ** Note: This method is disabled on MacOS X 10.7 and iOS version 5.0
  6748. ** and will always return SQLITE_MISUSE. On those systems,
  6749. ** shared cache mode should be enabled per-database connection via
  6750. ** [sqlite3_open_v2()] with [SQLITE_OPEN_SHAREDCACHE].
  6751. **
  6752. ** This interface is threadsafe on processors where writing a
  6753. ** 32-bit integer is atomic.
  6754. **
  6755. ** See Also: [SQLite Shared-Cache Mode]
  6756. */
  6757. SQLITE_API int sqlite3_enable_shared_cache(int);
  6758. /*
  6759. ** CAPI3REF: Attempt To Free Heap Memory
  6760. **
  6761. ** ^The sqlite3_release_memory() interface attempts to free N bytes
  6762. ** of heap memory by deallocating non-essential memory allocations
  6763. ** held by the database library. Memory used to cache database
  6764. ** pages to improve performance is an example of non-essential memory.
  6765. ** ^sqlite3_release_memory() returns the number of bytes actually freed,
  6766. ** which might be more or less than the amount requested.
  6767. ** ^The sqlite3_release_memory() routine is a no-op returning zero
  6768. ** if SQLite is not compiled with [SQLITE_ENABLE_MEMORY_MANAGEMENT].
  6769. **
  6770. ** See also: [sqlite3_db_release_memory()]
  6771. */
  6772. SQLITE_API int sqlite3_release_memory(int);
  6773. /*
  6774. ** CAPI3REF: Free Memory Used By A Database Connection
  6775. ** METHOD: sqlite3
  6776. **
  6777. ** ^The sqlite3_db_release_memory(D) interface attempts to free as much heap
  6778. ** memory as possible from database connection D. Unlike the
  6779. ** [sqlite3_release_memory()] interface, this interface is in effect even
  6780. ** when the [SQLITE_ENABLE_MEMORY_MANAGEMENT] compile-time option is
  6781. ** omitted.
  6782. **
  6783. ** See also: [sqlite3_release_memory()]
  6784. */
  6785. SQLITE_API int sqlite3_db_release_memory(sqlite3*);
  6786. /*
  6787. ** CAPI3REF: Impose A Limit On Heap Size
  6788. **
  6789. ** These interfaces impose limits on the amount of heap memory that will be
  6790. ** by all database connections within a single process.
  6791. **
  6792. ** ^The sqlite3_soft_heap_limit64() interface sets and/or queries the
  6793. ** soft limit on the amount of heap memory that may be allocated by SQLite.
  6794. ** ^SQLite strives to keep heap memory utilization below the soft heap
  6795. ** limit by reducing the number of pages held in the page cache
  6796. ** as heap memory usages approaches the limit.
  6797. ** ^The soft heap limit is "soft" because even though SQLite strives to stay
  6798. ** below the limit, it will exceed the limit rather than generate
  6799. ** an [SQLITE_NOMEM] error. In other words, the soft heap limit
  6800. ** is advisory only.
  6801. **
  6802. ** ^The sqlite3_hard_heap_limit64(N) interface sets a hard upper bound of
  6803. ** N bytes on the amount of memory that will be allocated. ^The
  6804. ** sqlite3_hard_heap_limit64(N) interface is similar to
  6805. ** sqlite3_soft_heap_limit64(N) except that memory allocations will fail
  6806. ** when the hard heap limit is reached.
  6807. **
  6808. ** ^The return value from both sqlite3_soft_heap_limit64() and
  6809. ** sqlite3_hard_heap_limit64() is the size of
  6810. ** the heap limit prior to the call, or negative in the case of an
  6811. ** error. ^If the argument N is negative
  6812. ** then no change is made to the heap limit. Hence, the current
  6813. ** size of heap limits can be determined by invoking
  6814. ** sqlite3_soft_heap_limit64(-1) or sqlite3_hard_heap_limit(-1).
  6815. **
  6816. ** ^Setting the heap limits to zero disables the heap limiter mechanism.
  6817. **
  6818. ** ^The soft heap limit may not be greater than the hard heap limit.
  6819. ** ^If the hard heap limit is enabled and if sqlite3_soft_heap_limit(N)
  6820. ** is invoked with a value of N that is greater than the hard heap limit,
  6821. ** the soft heap limit is set to the value of the hard heap limit.
  6822. ** ^The soft heap limit is automatically enabled whenever the hard heap
  6823. ** limit is enabled. ^When sqlite3_hard_heap_limit64(N) is invoked and
  6824. ** the soft heap limit is outside the range of 1..N, then the soft heap
  6825. ** limit is set to N. ^Invoking sqlite3_soft_heap_limit64(0) when the
  6826. ** hard heap limit is enabled makes the soft heap limit equal to the
  6827. ** hard heap limit.
  6828. **
  6829. ** The memory allocation limits can also be adjusted using
  6830. ** [PRAGMA soft_heap_limit] and [PRAGMA hard_heap_limit].
  6831. **
  6832. ** ^(The heap limits are not enforced in the current implementation
  6833. ** if one or more of following conditions are true:
  6834. **
  6835. ** <ul>
  6836. ** <li> The limit value is set to zero.
  6837. ** <li> Memory accounting is disabled using a combination of the
  6838. ** [sqlite3_config]([SQLITE_CONFIG_MEMSTATUS],...) start-time option and
  6839. ** the [SQLITE_DEFAULT_MEMSTATUS] compile-time option.
  6840. ** <li> An alternative page cache implementation is specified using
  6841. ** [sqlite3_config]([SQLITE_CONFIG_PCACHE2],...).
  6842. ** <li> The page cache allocates from its own memory pool supplied
  6843. ** by [sqlite3_config]([SQLITE_CONFIG_PAGECACHE],...) rather than
  6844. ** from the heap.
  6845. ** </ul>)^
  6846. **
  6847. ** The circumstances under which SQLite will enforce the heap limits may
  6848. ** changes in future releases of SQLite.
  6849. */
  6850. SQLITE_API sqlite3_int64 sqlite3_soft_heap_limit64(sqlite3_int64 N);
  6851. SQLITE_API sqlite3_int64 sqlite3_hard_heap_limit64(sqlite3_int64 N);
  6852. /*
  6853. ** CAPI3REF: Deprecated Soft Heap Limit Interface
  6854. ** DEPRECATED
  6855. **
  6856. ** This is a deprecated version of the [sqlite3_soft_heap_limit64()]
  6857. ** interface. This routine is provided for historical compatibility
  6858. ** only. All new applications should use the
  6859. ** [sqlite3_soft_heap_limit64()] interface rather than this one.
  6860. */
  6861. SQLITE_API SQLITE_DEPRECATED void sqlite3_soft_heap_limit(int N);
  6862. /*
  6863. ** CAPI3REF: Extract Metadata About A Column Of A Table
  6864. ** METHOD: sqlite3
  6865. **
  6866. ** ^(The sqlite3_table_column_metadata(X,D,T,C,....) routine returns
  6867. ** information about column C of table T in database D
  6868. ** on [database connection] X.)^ ^The sqlite3_table_column_metadata()
  6869. ** interface returns SQLITE_OK and fills in the non-NULL pointers in
  6870. ** the final five arguments with appropriate values if the specified
  6871. ** column exists. ^The sqlite3_table_column_metadata() interface returns
  6872. ** SQLITE_ERROR if the specified column does not exist.
  6873. ** ^If the column-name parameter to sqlite3_table_column_metadata() is a
  6874. ** NULL pointer, then this routine simply checks for the existence of the
  6875. ** table and returns SQLITE_OK if the table exists and SQLITE_ERROR if it
  6876. ** does not. If the table name parameter T in a call to
  6877. ** sqlite3_table_column_metadata(X,D,T,C,...) is NULL then the result is
  6878. ** undefined behavior.
  6879. **
  6880. ** ^The column is identified by the second, third and fourth parameters to
  6881. ** this function. ^(The second parameter is either the name of the database
  6882. ** (i.e. "main", "temp", or an attached database) containing the specified
  6883. ** table or NULL.)^ ^If it is NULL, then all attached databases are searched
  6884. ** for the table using the same algorithm used by the database engine to
  6885. ** resolve unqualified table references.
  6886. **
  6887. ** ^The third and fourth parameters to this function are the table and column
  6888. ** name of the desired column, respectively.
  6889. **
  6890. ** ^Metadata is returned by writing to the memory locations passed as the 5th
  6891. ** and subsequent parameters to this function. ^Any of these arguments may be
  6892. ** NULL, in which case the corresponding element of metadata is omitted.
  6893. **
  6894. ** ^(<blockquote>
  6895. ** <table border="1">
  6896. ** <tr><th> Parameter <th> Output<br>Type <th> Description
  6897. **
  6898. ** <tr><td> 5th <td> const char* <td> Data type
  6899. ** <tr><td> 6th <td> const char* <td> Name of default collation sequence
  6900. ** <tr><td> 7th <td> int <td> True if column has a NOT NULL constraint
  6901. ** <tr><td> 8th <td> int <td> True if column is part of the PRIMARY KEY
  6902. ** <tr><td> 9th <td> int <td> True if column is [AUTOINCREMENT]
  6903. ** </table>
  6904. ** </blockquote>)^
  6905. **
  6906. ** ^The memory pointed to by the character pointers returned for the
  6907. ** declaration type and collation sequence is valid until the next
  6908. ** call to any SQLite API function.
  6909. **
  6910. ** ^If the specified table is actually a view, an [error code] is returned.
  6911. **
  6912. ** ^If the specified column is "rowid", "oid" or "_rowid_" and the table
  6913. ** is not a [WITHOUT ROWID] table and an
  6914. ** [INTEGER PRIMARY KEY] column has been explicitly declared, then the output
  6915. ** parameters are set for the explicitly declared column. ^(If there is no
  6916. ** [INTEGER PRIMARY KEY] column, then the outputs
  6917. ** for the [rowid] are set as follows:
  6918. **
  6919. ** <pre>
  6920. ** data type: "INTEGER"
  6921. ** collation sequence: "BINARY"
  6922. ** not null: 0
  6923. ** primary key: 1
  6924. ** auto increment: 0
  6925. ** </pre>)^
  6926. **
  6927. ** ^This function causes all database schemas to be read from disk and
  6928. ** parsed, if that has not already been done, and returns an error if
  6929. ** any errors are encountered while loading the schema.
  6930. */
  6931. SQLITE_API int sqlite3_table_column_metadata(
  6932. sqlite3 *db, /* Connection handle */
  6933. const char *zDbName, /* Database name or NULL */
  6934. const char *zTableName, /* Table name */
  6935. const char *zColumnName, /* Column name */
  6936. char const **pzDataType, /* OUTPUT: Declared data type */
  6937. char const **pzCollSeq, /* OUTPUT: Collation sequence name */
  6938. int *pNotNull, /* OUTPUT: True if NOT NULL constraint exists */
  6939. int *pPrimaryKey, /* OUTPUT: True if column part of PK */
  6940. int *pAutoinc /* OUTPUT: True if column is auto-increment */
  6941. );
  6942. /*
  6943. ** CAPI3REF: Load An Extension
  6944. ** METHOD: sqlite3
  6945. **
  6946. ** ^This interface loads an SQLite extension library from the named file.
  6947. **
  6948. ** ^The sqlite3_load_extension() interface attempts to load an
  6949. ** [SQLite extension] library contained in the file zFile. If
  6950. ** the file cannot be loaded directly, attempts are made to load
  6951. ** with various operating-system specific extensions added.
  6952. ** So for example, if "samplelib" cannot be loaded, then names like
  6953. ** "samplelib.so" or "samplelib.dylib" or "samplelib.dll" might
  6954. ** be tried also.
  6955. **
  6956. ** ^The entry point is zProc.
  6957. ** ^(zProc may be 0, in which case SQLite will try to come up with an
  6958. ** entry point name on its own. It first tries "sqlite3_extension_init".
  6959. ** If that does not work, it constructs a name "sqlite3_X_init" where the
  6960. ** X is consists of the lower-case equivalent of all ASCII alphabetic
  6961. ** characters in the filename from the last "/" to the first following
  6962. ** "." and omitting any initial "lib".)^
  6963. ** ^The sqlite3_load_extension() interface returns
  6964. ** [SQLITE_OK] on success and [SQLITE_ERROR] if something goes wrong.
  6965. ** ^If an error occurs and pzErrMsg is not 0, then the
  6966. ** [sqlite3_load_extension()] interface shall attempt to
  6967. ** fill *pzErrMsg with error message text stored in memory
  6968. ** obtained from [sqlite3_malloc()]. The calling function
  6969. ** should free this memory by calling [sqlite3_free()].
  6970. **
  6971. ** ^Extension loading must be enabled using
  6972. ** [sqlite3_enable_load_extension()] or
  6973. ** [sqlite3_db_config](db,[SQLITE_DBCONFIG_ENABLE_LOAD_EXTENSION],1,NULL)
  6974. ** prior to calling this API,
  6975. ** otherwise an error will be returned.
  6976. **
  6977. ** <b>Security warning:</b> It is recommended that the
  6978. ** [SQLITE_DBCONFIG_ENABLE_LOAD_EXTENSION] method be used to enable only this
  6979. ** interface. The use of the [sqlite3_enable_load_extension()] interface
  6980. ** should be avoided. This will keep the SQL function [load_extension()]
  6981. ** disabled and prevent SQL injections from giving attackers
  6982. ** access to extension loading capabilities.
  6983. **
  6984. ** See also the [load_extension() SQL function].
  6985. */
  6986. SQLITE_API int sqlite3_load_extension(
  6987. sqlite3 *db, /* Load the extension into this database connection */
  6988. const char *zFile, /* Name of the shared library containing extension */
  6989. const char *zProc, /* Entry point. Derived from zFile if 0 */
  6990. char **pzErrMsg /* Put error message here if not 0 */
  6991. );
  6992. /*
  6993. ** CAPI3REF: Enable Or Disable Extension Loading
  6994. ** METHOD: sqlite3
  6995. **
  6996. ** ^So as not to open security holes in older applications that are
  6997. ** unprepared to deal with [extension loading], and as a means of disabling
  6998. ** [extension loading] while evaluating user-entered SQL, the following API
  6999. ** is provided to turn the [sqlite3_load_extension()] mechanism on and off.
  7000. **
  7001. ** ^Extension loading is off by default.
  7002. ** ^Call the sqlite3_enable_load_extension() routine with onoff==1
  7003. ** to turn extension loading on and call it with onoff==0 to turn
  7004. ** it back off again.
  7005. **
  7006. ** ^This interface enables or disables both the C-API
  7007. ** [sqlite3_load_extension()] and the SQL function [load_extension()].
  7008. ** ^(Use [sqlite3_db_config](db,[SQLITE_DBCONFIG_ENABLE_LOAD_EXTENSION],..)
  7009. ** to enable or disable only the C-API.)^
  7010. **
  7011. ** <b>Security warning:</b> It is recommended that extension loading
  7012. ** be enabled using the [SQLITE_DBCONFIG_ENABLE_LOAD_EXTENSION] method
  7013. ** rather than this interface, so the [load_extension()] SQL function
  7014. ** remains disabled. This will prevent SQL injections from giving attackers
  7015. ** access to extension loading capabilities.
  7016. */
  7017. SQLITE_API int sqlite3_enable_load_extension(sqlite3 *db, int onoff);
  7018. /*
  7019. ** CAPI3REF: Automatically Load Statically Linked Extensions
  7020. **
  7021. ** ^This interface causes the xEntryPoint() function to be invoked for
  7022. ** each new [database connection] that is created. The idea here is that
  7023. ** xEntryPoint() is the entry point for a statically linked [SQLite extension]
  7024. ** that is to be automatically loaded into all new database connections.
  7025. **
  7026. ** ^(Even though the function prototype shows that xEntryPoint() takes
  7027. ** no arguments and returns void, SQLite invokes xEntryPoint() with three
  7028. ** arguments and expects an integer result as if the signature of the
  7029. ** entry point where as follows:
  7030. **
  7031. ** <blockquote><pre>
  7032. ** &nbsp; int xEntryPoint(
  7033. ** &nbsp; sqlite3 *db,
  7034. ** &nbsp; const char **pzErrMsg,
  7035. ** &nbsp; const struct sqlite3_api_routines *pThunk
  7036. ** &nbsp; );
  7037. ** </pre></blockquote>)^
  7038. **
  7039. ** If the xEntryPoint routine encounters an error, it should make *pzErrMsg
  7040. ** point to an appropriate error message (obtained from [sqlite3_mprintf()])
  7041. ** and return an appropriate [error code]. ^SQLite ensures that *pzErrMsg
  7042. ** is NULL before calling the xEntryPoint(). ^SQLite will invoke
  7043. ** [sqlite3_free()] on *pzErrMsg after xEntryPoint() returns. ^If any
  7044. ** xEntryPoint() returns an error, the [sqlite3_open()], [sqlite3_open16()],
  7045. ** or [sqlite3_open_v2()] call that provoked the xEntryPoint() will fail.
  7046. **
  7047. ** ^Calling sqlite3_auto_extension(X) with an entry point X that is already
  7048. ** on the list of automatic extensions is a harmless no-op. ^No entry point
  7049. ** will be called more than once for each database connection that is opened.
  7050. **
  7051. ** See also: [sqlite3_reset_auto_extension()]
  7052. ** and [sqlite3_cancel_auto_extension()]
  7053. */
  7054. SQLITE_API int sqlite3_auto_extension(void(*xEntryPoint)(void));
  7055. /*
  7056. ** CAPI3REF: Cancel Automatic Extension Loading
  7057. **
  7058. ** ^The [sqlite3_cancel_auto_extension(X)] interface unregisters the
  7059. ** initialization routine X that was registered using a prior call to
  7060. ** [sqlite3_auto_extension(X)]. ^The [sqlite3_cancel_auto_extension(X)]
  7061. ** routine returns 1 if initialization routine X was successfully
  7062. ** unregistered and it returns 0 if X was not on the list of initialization
  7063. ** routines.
  7064. */
  7065. SQLITE_API int sqlite3_cancel_auto_extension(void(*xEntryPoint)(void));
  7066. /*
  7067. ** CAPI3REF: Reset Automatic Extension Loading
  7068. **
  7069. ** ^This interface disables all automatic extensions previously
  7070. ** registered using [sqlite3_auto_extension()].
  7071. */
  7072. SQLITE_API void sqlite3_reset_auto_extension(void);
  7073. /*
  7074. ** Structures used by the virtual table interface
  7075. */
  7076. typedef struct sqlite3_vtab sqlite3_vtab;
  7077. typedef struct sqlite3_index_info sqlite3_index_info;
  7078. typedef struct sqlite3_vtab_cursor sqlite3_vtab_cursor;
  7079. typedef struct sqlite3_module sqlite3_module;
  7080. /*
  7081. ** CAPI3REF: Virtual Table Object
  7082. ** KEYWORDS: sqlite3_module {virtual table module}
  7083. **
  7084. ** This structure, sometimes called a "virtual table module",
  7085. ** defines the implementation of a [virtual table].
  7086. ** This structure consists mostly of methods for the module.
  7087. **
  7088. ** ^A virtual table module is created by filling in a persistent
  7089. ** instance of this structure and passing a pointer to that instance
  7090. ** to [sqlite3_create_module()] or [sqlite3_create_module_v2()].
  7091. ** ^The registration remains valid until it is replaced by a different
  7092. ** module or until the [database connection] closes. The content
  7093. ** of this structure must not change while it is registered with
  7094. ** any database connection.
  7095. */
  7096. struct sqlite3_module {
  7097. int iVersion;
  7098. int (*xCreate)(sqlite3*, void *pAux,
  7099. int argc, const char *const*argv,
  7100. sqlite3_vtab **ppVTab, char**);
  7101. int (*xConnect)(sqlite3*, void *pAux,
  7102. int argc, const char *const*argv,
  7103. sqlite3_vtab **ppVTab, char**);
  7104. int (*xBestIndex)(sqlite3_vtab *pVTab, sqlite3_index_info*);
  7105. int (*xDisconnect)(sqlite3_vtab *pVTab);
  7106. int (*xDestroy)(sqlite3_vtab *pVTab);
  7107. int (*xOpen)(sqlite3_vtab *pVTab, sqlite3_vtab_cursor **ppCursor);
  7108. int (*xClose)(sqlite3_vtab_cursor*);
  7109. int (*xFilter)(sqlite3_vtab_cursor*, int idxNum, const char *idxStr,
  7110. int argc, sqlite3_value **argv);
  7111. int (*xNext)(sqlite3_vtab_cursor*);
  7112. int (*xEof)(sqlite3_vtab_cursor*);
  7113. int (*xColumn)(sqlite3_vtab_cursor*, sqlite3_context*, int);
  7114. int (*xRowid)(sqlite3_vtab_cursor*, sqlite3_int64 *pRowid);
  7115. int (*xUpdate)(sqlite3_vtab *, int, sqlite3_value **, sqlite3_int64 *);
  7116. int (*xBegin)(sqlite3_vtab *pVTab);
  7117. int (*xSync)(sqlite3_vtab *pVTab);
  7118. int (*xCommit)(sqlite3_vtab *pVTab);
  7119. int (*xRollback)(sqlite3_vtab *pVTab);
  7120. int (*xFindFunction)(sqlite3_vtab *pVtab, int nArg, const char *zName,
  7121. void (**pxFunc)(sqlite3_context*,int,sqlite3_value**),
  7122. void **ppArg);
  7123. int (*xRename)(sqlite3_vtab *pVtab, const char *zNew);
  7124. /* The methods above are in version 1 of the sqlite_module object. Those
  7125. ** below are for version 2 and greater. */
  7126. int (*xSavepoint)(sqlite3_vtab *pVTab, int);
  7127. int (*xRelease)(sqlite3_vtab *pVTab, int);
  7128. int (*xRollbackTo)(sqlite3_vtab *pVTab, int);
  7129. /* The methods above are in versions 1 and 2 of the sqlite_module object.
  7130. ** Those below are for version 3 and greater. */
  7131. int (*xShadowName)(const char*);
  7132. /* The methods above are in versions 1 through 3 of the sqlite_module object.
  7133. ** Those below are for version 4 and greater. */
  7134. int (*xIntegrity)(sqlite3_vtab *pVTab, const char *zSchema,
  7135. const char *zTabName, int mFlags, char **pzErr);
  7136. };
  7137. /*
  7138. ** CAPI3REF: Virtual Table Indexing Information
  7139. ** KEYWORDS: sqlite3_index_info
  7140. **
  7141. ** The sqlite3_index_info structure and its substructures is used as part
  7142. ** of the [virtual table] interface to
  7143. ** pass information into and receive the reply from the [xBestIndex]
  7144. ** method of a [virtual table module]. The fields under **Inputs** are the
  7145. ** inputs to xBestIndex and are read-only. xBestIndex inserts its
  7146. ** results into the **Outputs** fields.
  7147. **
  7148. ** ^(The aConstraint[] array records WHERE clause constraints of the form:
  7149. **
  7150. ** <blockquote>column OP expr</blockquote>
  7151. **
  7152. ** where OP is =, &lt;, &lt;=, &gt;, or &gt;=.)^ ^(The particular operator is
  7153. ** stored in aConstraint[].op using one of the
  7154. ** [SQLITE_INDEX_CONSTRAINT_EQ | SQLITE_INDEX_CONSTRAINT_ values].)^
  7155. ** ^(The index of the column is stored in
  7156. ** aConstraint[].iColumn.)^ ^(aConstraint[].usable is TRUE if the
  7157. ** expr on the right-hand side can be evaluated (and thus the constraint
  7158. ** is usable) and false if it cannot.)^
  7159. **
  7160. ** ^The optimizer automatically inverts terms of the form "expr OP column"
  7161. ** and makes other simplifications to the WHERE clause in an attempt to
  7162. ** get as many WHERE clause terms into the form shown above as possible.
  7163. ** ^The aConstraint[] array only reports WHERE clause terms that are
  7164. ** relevant to the particular virtual table being queried.
  7165. **
  7166. ** ^Information about the ORDER BY clause is stored in aOrderBy[].
  7167. ** ^Each term of aOrderBy records a column of the ORDER BY clause.
  7168. **
  7169. ** The colUsed field indicates which columns of the virtual table may be
  7170. ** required by the current scan. Virtual table columns are numbered from
  7171. ** zero in the order in which they appear within the CREATE TABLE statement
  7172. ** passed to sqlite3_declare_vtab(). For the first 63 columns (columns 0-62),
  7173. ** the corresponding bit is set within the colUsed mask if the column may be
  7174. ** required by SQLite. If the table has at least 64 columns and any column
  7175. ** to the right of the first 63 is required, then bit 63 of colUsed is also
  7176. ** set. In other words, column iCol may be required if the expression
  7177. ** (colUsed & ((sqlite3_uint64)1 << (iCol>=63 ? 63 : iCol))) evaluates to
  7178. ** non-zero.
  7179. **
  7180. ** The [xBestIndex] method must fill aConstraintUsage[] with information
  7181. ** about what parameters to pass to xFilter. ^If argvIndex>0 then
  7182. ** the right-hand side of the corresponding aConstraint[] is evaluated
  7183. ** and becomes the argvIndex-th entry in argv. ^(If aConstraintUsage[].omit
  7184. ** is true, then the constraint is assumed to be fully handled by the
  7185. ** virtual table and might not be checked again by the byte code.)^ ^(The
  7186. ** aConstraintUsage[].omit flag is an optimization hint. When the omit flag
  7187. ** is left in its default setting of false, the constraint will always be
  7188. ** checked separately in byte code. If the omit flag is change to true, then
  7189. ** the constraint may or may not be checked in byte code. In other words,
  7190. ** when the omit flag is true there is no guarantee that the constraint will
  7191. ** not be checked again using byte code.)^
  7192. **
  7193. ** ^The idxNum and idxStr values are recorded and passed into the
  7194. ** [xFilter] method.
  7195. ** ^[sqlite3_free()] is used to free idxStr if and only if
  7196. ** needToFreeIdxStr is true.
  7197. **
  7198. ** ^The orderByConsumed means that output from [xFilter]/[xNext] will occur in
  7199. ** the correct order to satisfy the ORDER BY clause so that no separate
  7200. ** sorting step is required.
  7201. **
  7202. ** ^The estimatedCost value is an estimate of the cost of a particular
  7203. ** strategy. A cost of N indicates that the cost of the strategy is similar
  7204. ** to a linear scan of an SQLite table with N rows. A cost of log(N)
  7205. ** indicates that the expense of the operation is similar to that of a
  7206. ** binary search on a unique indexed field of an SQLite table with N rows.
  7207. **
  7208. ** ^The estimatedRows value is an estimate of the number of rows that
  7209. ** will be returned by the strategy.
  7210. **
  7211. ** The xBestIndex method may optionally populate the idxFlags field with a
  7212. ** mask of SQLITE_INDEX_SCAN_* flags. Currently there is only one such flag -
  7213. ** SQLITE_INDEX_SCAN_UNIQUE. If the xBestIndex method sets this flag, SQLite
  7214. ** assumes that the strategy may visit at most one row.
  7215. **
  7216. ** Additionally, if xBestIndex sets the SQLITE_INDEX_SCAN_UNIQUE flag, then
  7217. ** SQLite also assumes that if a call to the xUpdate() method is made as
  7218. ** part of the same statement to delete or update a virtual table row and the
  7219. ** implementation returns SQLITE_CONSTRAINT, then there is no need to rollback
  7220. ** any database changes. In other words, if the xUpdate() returns
  7221. ** SQLITE_CONSTRAINT, the database contents must be exactly as they were
  7222. ** before xUpdate was called. By contrast, if SQLITE_INDEX_SCAN_UNIQUE is not
  7223. ** set and xUpdate returns SQLITE_CONSTRAINT, any database changes made by
  7224. ** the xUpdate method are automatically rolled back by SQLite.
  7225. **
  7226. ** IMPORTANT: The estimatedRows field was added to the sqlite3_index_info
  7227. ** structure for SQLite [version 3.8.2] ([dateof:3.8.2]).
  7228. ** If a virtual table extension is
  7229. ** used with an SQLite version earlier than 3.8.2, the results of attempting
  7230. ** to read or write the estimatedRows field are undefined (but are likely
  7231. ** to include crashing the application). The estimatedRows field should
  7232. ** therefore only be used if [sqlite3_libversion_number()] returns a
  7233. ** value greater than or equal to 3008002. Similarly, the idxFlags field
  7234. ** was added for [version 3.9.0] ([dateof:3.9.0]).
  7235. ** It may therefore only be used if
  7236. ** sqlite3_libversion_number() returns a value greater than or equal to
  7237. ** 3009000.
  7238. */
  7239. struct sqlite3_index_info {
  7240. /* Inputs */
  7241. int nConstraint; /* Number of entries in aConstraint */
  7242. struct sqlite3_index_constraint {
  7243. int iColumn; /* Column constrained. -1 for ROWID */
  7244. unsigned char op; /* Constraint operator */
  7245. unsigned char usable; /* True if this constraint is usable */
  7246. int iTermOffset; /* Used internally - xBestIndex should ignore */
  7247. } *aConstraint; /* Table of WHERE clause constraints */
  7248. int nOrderBy; /* Number of terms in the ORDER BY clause */
  7249. struct sqlite3_index_orderby {
  7250. int iColumn; /* Column number */
  7251. unsigned char desc; /* True for DESC. False for ASC. */
  7252. } *aOrderBy; /* The ORDER BY clause */
  7253. /* Outputs */
  7254. struct sqlite3_index_constraint_usage {
  7255. int argvIndex; /* if >0, constraint is part of argv to xFilter */
  7256. unsigned char omit; /* Do not code a test for this constraint */
  7257. } *aConstraintUsage;
  7258. int idxNum; /* Number used to identify the index */
  7259. char *idxStr; /* String, possibly obtained from sqlite3_malloc */
  7260. int needToFreeIdxStr; /* Free idxStr using sqlite3_free() if true */
  7261. int orderByConsumed; /* True if output is already ordered */
  7262. double estimatedCost; /* Estimated cost of using this index */
  7263. /* Fields below are only available in SQLite 3.8.2 and later */
  7264. sqlite3_int64 estimatedRows; /* Estimated number of rows returned */
  7265. /* Fields below are only available in SQLite 3.9.0 and later */
  7266. int idxFlags; /* Mask of SQLITE_INDEX_SCAN_* flags */
  7267. /* Fields below are only available in SQLite 3.10.0 and later */
  7268. sqlite3_uint64 colUsed; /* Input: Mask of columns used by statement */
  7269. };
  7270. /*
  7271. ** CAPI3REF: Virtual Table Scan Flags
  7272. **
  7273. ** Virtual table implementations are allowed to set the
  7274. ** [sqlite3_index_info].idxFlags field to some combination of
  7275. ** these bits.
  7276. */
  7277. #define SQLITE_INDEX_SCAN_UNIQUE 1 /* Scan visits at most 1 row */
  7278. /*
  7279. ** CAPI3REF: Virtual Table Constraint Operator Codes
  7280. **
  7281. ** These macros define the allowed values for the
  7282. ** [sqlite3_index_info].aConstraint[].op field. Each value represents
  7283. ** an operator that is part of a constraint term in the WHERE clause of
  7284. ** a query that uses a [virtual table].
  7285. **
  7286. ** ^The left-hand operand of the operator is given by the corresponding
  7287. ** aConstraint[].iColumn field. ^An iColumn of -1 indicates the left-hand
  7288. ** operand is the rowid.
  7289. ** The SQLITE_INDEX_CONSTRAINT_LIMIT and SQLITE_INDEX_CONSTRAINT_OFFSET
  7290. ** operators have no left-hand operand, and so for those operators the
  7291. ** corresponding aConstraint[].iColumn is meaningless and should not be
  7292. ** used.
  7293. **
  7294. ** All operator values from SQLITE_INDEX_CONSTRAINT_FUNCTION through
  7295. ** value 255 are reserved to represent functions that are overloaded
  7296. ** by the [xFindFunction|xFindFunction method] of the virtual table
  7297. ** implementation.
  7298. **
  7299. ** The right-hand operands for each constraint might be accessible using
  7300. ** the [sqlite3_vtab_rhs_value()] interface. Usually the right-hand
  7301. ** operand is only available if it appears as a single constant literal
  7302. ** in the input SQL. If the right-hand operand is another column or an
  7303. ** expression (even a constant expression) or a parameter, then the
  7304. ** sqlite3_vtab_rhs_value() probably will not be able to extract it.
  7305. ** ^The SQLITE_INDEX_CONSTRAINT_ISNULL and
  7306. ** SQLITE_INDEX_CONSTRAINT_ISNOTNULL operators have no right-hand operand
  7307. ** and hence calls to sqlite3_vtab_rhs_value() for those operators will
  7308. ** always return SQLITE_NOTFOUND.
  7309. **
  7310. ** The collating sequence to be used for comparison can be found using
  7311. ** the [sqlite3_vtab_collation()] interface. For most real-world virtual
  7312. ** tables, the collating sequence of constraints does not matter (for example
  7313. ** because the constraints are numeric) and so the sqlite3_vtab_collation()
  7314. ** interface is not commonly needed.
  7315. */
  7316. #define SQLITE_INDEX_CONSTRAINT_EQ 2
  7317. #define SQLITE_INDEX_CONSTRAINT_GT 4
  7318. #define SQLITE_INDEX_CONSTRAINT_LE 8
  7319. #define SQLITE_INDEX_CONSTRAINT_LT 16
  7320. #define SQLITE_INDEX_CONSTRAINT_GE 32
  7321. #define SQLITE_INDEX_CONSTRAINT_MATCH 64
  7322. #define SQLITE_INDEX_CONSTRAINT_LIKE 65
  7323. #define SQLITE_INDEX_CONSTRAINT_GLOB 66
  7324. #define SQLITE_INDEX_CONSTRAINT_REGEXP 67
  7325. #define SQLITE_INDEX_CONSTRAINT_NE 68
  7326. #define SQLITE_INDEX_CONSTRAINT_ISNOT 69
  7327. #define SQLITE_INDEX_CONSTRAINT_ISNOTNULL 70
  7328. #define SQLITE_INDEX_CONSTRAINT_ISNULL 71
  7329. #define SQLITE_INDEX_CONSTRAINT_IS 72
  7330. #define SQLITE_INDEX_CONSTRAINT_LIMIT 73
  7331. #define SQLITE_INDEX_CONSTRAINT_OFFSET 74
  7332. #define SQLITE_INDEX_CONSTRAINT_FUNCTION 150
  7333. /*
  7334. ** CAPI3REF: Register A Virtual Table Implementation
  7335. ** METHOD: sqlite3
  7336. **
  7337. ** ^These routines are used to register a new [virtual table module] name.
  7338. ** ^Module names must be registered before
  7339. ** creating a new [virtual table] using the module and before using a
  7340. ** preexisting [virtual table] for the module.
  7341. **
  7342. ** ^The module name is registered on the [database connection] specified
  7343. ** by the first parameter. ^The name of the module is given by the
  7344. ** second parameter. ^The third parameter is a pointer to
  7345. ** the implementation of the [virtual table module]. ^The fourth
  7346. ** parameter is an arbitrary client data pointer that is passed through
  7347. ** into the [xCreate] and [xConnect] methods of the virtual table module
  7348. ** when a new virtual table is be being created or reinitialized.
  7349. **
  7350. ** ^The sqlite3_create_module_v2() interface has a fifth parameter which
  7351. ** is a pointer to a destructor for the pClientData. ^SQLite will
  7352. ** invoke the destructor function (if it is not NULL) when SQLite
  7353. ** no longer needs the pClientData pointer. ^The destructor will also
  7354. ** be invoked if the call to sqlite3_create_module_v2() fails.
  7355. ** ^The sqlite3_create_module()
  7356. ** interface is equivalent to sqlite3_create_module_v2() with a NULL
  7357. ** destructor.
  7358. **
  7359. ** ^If the third parameter (the pointer to the sqlite3_module object) is
  7360. ** NULL then no new module is created and any existing modules with the
  7361. ** same name are dropped.
  7362. **
  7363. ** See also: [sqlite3_drop_modules()]
  7364. */
  7365. SQLITE_API int sqlite3_create_module(
  7366. sqlite3 *db, /* SQLite connection to register module with */
  7367. const char *zName, /* Name of the module */
  7368. const sqlite3_module *p, /* Methods for the module */
  7369. void *pClientData /* Client data for xCreate/xConnect */
  7370. );
  7371. SQLITE_API int sqlite3_create_module_v2(
  7372. sqlite3 *db, /* SQLite connection to register module with */
  7373. const char *zName, /* Name of the module */
  7374. const sqlite3_module *p, /* Methods for the module */
  7375. void *pClientData, /* Client data for xCreate/xConnect */
  7376. void(*xDestroy)(void*) /* Module destructor function */
  7377. );
  7378. /*
  7379. ** CAPI3REF: Remove Unnecessary Virtual Table Implementations
  7380. ** METHOD: sqlite3
  7381. **
  7382. ** ^The sqlite3_drop_modules(D,L) interface removes all virtual
  7383. ** table modules from database connection D except those named on list L.
  7384. ** The L parameter must be either NULL or a pointer to an array of pointers
  7385. ** to strings where the array is terminated by a single NULL pointer.
  7386. ** ^If the L parameter is NULL, then all virtual table modules are removed.
  7387. **
  7388. ** See also: [sqlite3_create_module()]
  7389. */
  7390. SQLITE_API int sqlite3_drop_modules(
  7391. sqlite3 *db, /* Remove modules from this connection */
  7392. const char **azKeep /* Except, do not remove the ones named here */
  7393. );
  7394. /*
  7395. ** CAPI3REF: Virtual Table Instance Object
  7396. ** KEYWORDS: sqlite3_vtab
  7397. **
  7398. ** Every [virtual table module] implementation uses a subclass
  7399. ** of this object to describe a particular instance
  7400. ** of the [virtual table]. Each subclass will
  7401. ** be tailored to the specific needs of the module implementation.
  7402. ** The purpose of this superclass is to define certain fields that are
  7403. ** common to all module implementations.
  7404. **
  7405. ** ^Virtual tables methods can set an error message by assigning a
  7406. ** string obtained from [sqlite3_mprintf()] to zErrMsg. The method should
  7407. ** take care that any prior string is freed by a call to [sqlite3_free()]
  7408. ** prior to assigning a new string to zErrMsg. ^After the error message
  7409. ** is delivered up to the client application, the string will be automatically
  7410. ** freed by sqlite3_free() and the zErrMsg field will be zeroed.
  7411. */
  7412. struct sqlite3_vtab {
  7413. const sqlite3_module *pModule; /* The module for this virtual table */
  7414. int nRef; /* Number of open cursors */
  7415. char *zErrMsg; /* Error message from sqlite3_mprintf() */
  7416. /* Virtual table implementations will typically add additional fields */
  7417. };
  7418. /*
  7419. ** CAPI3REF: Virtual Table Cursor Object
  7420. ** KEYWORDS: sqlite3_vtab_cursor {virtual table cursor}
  7421. **
  7422. ** Every [virtual table module] implementation uses a subclass of the
  7423. ** following structure to describe cursors that point into the
  7424. ** [virtual table] and are used
  7425. ** to loop through the virtual table. Cursors are created using the
  7426. ** [sqlite3_module.xOpen | xOpen] method of the module and are destroyed
  7427. ** by the [sqlite3_module.xClose | xClose] method. Cursors are used
  7428. ** by the [xFilter], [xNext], [xEof], [xColumn], and [xRowid] methods
  7429. ** of the module. Each module implementation will define
  7430. ** the content of a cursor structure to suit its own needs.
  7431. **
  7432. ** This superclass exists in order to define fields of the cursor that
  7433. ** are common to all implementations.
  7434. */
  7435. struct sqlite3_vtab_cursor {
  7436. sqlite3_vtab *pVtab; /* Virtual table of this cursor */
  7437. /* Virtual table implementations will typically add additional fields */
  7438. };
  7439. /*
  7440. ** CAPI3REF: Declare The Schema Of A Virtual Table
  7441. **
  7442. ** ^The [xCreate] and [xConnect] methods of a
  7443. ** [virtual table module] call this interface
  7444. ** to declare the format (the names and datatypes of the columns) of
  7445. ** the virtual tables they implement.
  7446. */
  7447. SQLITE_API int sqlite3_declare_vtab(sqlite3*, const char *zSQL);
  7448. /*
  7449. ** CAPI3REF: Overload A Function For A Virtual Table
  7450. ** METHOD: sqlite3
  7451. **
  7452. ** ^(Virtual tables can provide alternative implementations of functions
  7453. ** using the [xFindFunction] method of the [virtual table module].
  7454. ** But global versions of those functions
  7455. ** must exist in order to be overloaded.)^
  7456. **
  7457. ** ^(This API makes sure a global version of a function with a particular
  7458. ** name and number of parameters exists. If no such function exists
  7459. ** before this API is called, a new function is created.)^ ^The implementation
  7460. ** of the new function always causes an exception to be thrown. So
  7461. ** the new function is not good for anything by itself. Its only
  7462. ** purpose is to be a placeholder function that can be overloaded
  7463. ** by a [virtual table].
  7464. */
  7465. SQLITE_API int sqlite3_overload_function(sqlite3*, const char *zFuncName, int nArg);
  7466. /*
  7467. ** CAPI3REF: A Handle To An Open BLOB
  7468. ** KEYWORDS: {BLOB handle} {BLOB handles}
  7469. **
  7470. ** An instance of this object represents an open BLOB on which
  7471. ** [sqlite3_blob_open | incremental BLOB I/O] can be performed.
  7472. ** ^Objects of this type are created by [sqlite3_blob_open()]
  7473. ** and destroyed by [sqlite3_blob_close()].
  7474. ** ^The [sqlite3_blob_read()] and [sqlite3_blob_write()] interfaces
  7475. ** can be used to read or write small subsections of the BLOB.
  7476. ** ^The [sqlite3_blob_bytes()] interface returns the size of the BLOB in bytes.
  7477. */
  7478. typedef struct sqlite3_blob sqlite3_blob;
  7479. /*
  7480. ** CAPI3REF: Open A BLOB For Incremental I/O
  7481. ** METHOD: sqlite3
  7482. ** CONSTRUCTOR: sqlite3_blob
  7483. **
  7484. ** ^(This interfaces opens a [BLOB handle | handle] to the BLOB located
  7485. ** in row iRow, column zColumn, table zTable in database zDb;
  7486. ** in other words, the same BLOB that would be selected by:
  7487. **
  7488. ** <pre>
  7489. ** SELECT zColumn FROM zDb.zTable WHERE [rowid] = iRow;
  7490. ** </pre>)^
  7491. **
  7492. ** ^(Parameter zDb is not the filename that contains the database, but
  7493. ** rather the symbolic name of the database. For attached databases, this is
  7494. ** the name that appears after the AS keyword in the [ATTACH] statement.
  7495. ** For the main database file, the database name is "main". For TEMP
  7496. ** tables, the database name is "temp".)^
  7497. **
  7498. ** ^If the flags parameter is non-zero, then the BLOB is opened for read
  7499. ** and write access. ^If the flags parameter is zero, the BLOB is opened for
  7500. ** read-only access.
  7501. **
  7502. ** ^(On success, [SQLITE_OK] is returned and the new [BLOB handle] is stored
  7503. ** in *ppBlob. Otherwise an [error code] is returned and, unless the error
  7504. ** code is SQLITE_MISUSE, *ppBlob is set to NULL.)^ ^This means that, provided
  7505. ** the API is not misused, it is always safe to call [sqlite3_blob_close()]
  7506. ** on *ppBlob after this function it returns.
  7507. **
  7508. ** This function fails with SQLITE_ERROR if any of the following are true:
  7509. ** <ul>
  7510. ** <li> ^(Database zDb does not exist)^,
  7511. ** <li> ^(Table zTable does not exist within database zDb)^,
  7512. ** <li> ^(Table zTable is a WITHOUT ROWID table)^,
  7513. ** <li> ^(Column zColumn does not exist)^,
  7514. ** <li> ^(Row iRow is not present in the table)^,
  7515. ** <li> ^(The specified column of row iRow contains a value that is not
  7516. ** a TEXT or BLOB value)^,
  7517. ** <li> ^(Column zColumn is part of an index, PRIMARY KEY or UNIQUE
  7518. ** constraint and the blob is being opened for read/write access)^,
  7519. ** <li> ^([foreign key constraints | Foreign key constraints] are enabled,
  7520. ** column zColumn is part of a [child key] definition and the blob is
  7521. ** being opened for read/write access)^.
  7522. ** </ul>
  7523. **
  7524. ** ^Unless it returns SQLITE_MISUSE, this function sets the
  7525. ** [database connection] error code and message accessible via
  7526. ** [sqlite3_errcode()] and [sqlite3_errmsg()] and related functions.
  7527. **
  7528. ** A BLOB referenced by sqlite3_blob_open() may be read using the
  7529. ** [sqlite3_blob_read()] interface and modified by using
  7530. ** [sqlite3_blob_write()]. The [BLOB handle] can be moved to a
  7531. ** different row of the same table using the [sqlite3_blob_reopen()]
  7532. ** interface. However, the column, table, or database of a [BLOB handle]
  7533. ** cannot be changed after the [BLOB handle] is opened.
  7534. **
  7535. ** ^(If the row that a BLOB handle points to is modified by an
  7536. ** [UPDATE], [DELETE], or by [ON CONFLICT] side-effects
  7537. ** then the BLOB handle is marked as "expired".
  7538. ** This is true if any column of the row is changed, even a column
  7539. ** other than the one the BLOB handle is open on.)^
  7540. ** ^Calls to [sqlite3_blob_read()] and [sqlite3_blob_write()] for
  7541. ** an expired BLOB handle fail with a return code of [SQLITE_ABORT].
  7542. ** ^(Changes written into a BLOB prior to the BLOB expiring are not
  7543. ** rolled back by the expiration of the BLOB. Such changes will eventually
  7544. ** commit if the transaction continues to completion.)^
  7545. **
  7546. ** ^Use the [sqlite3_blob_bytes()] interface to determine the size of
  7547. ** the opened blob. ^The size of a blob may not be changed by this
  7548. ** interface. Use the [UPDATE] SQL command to change the size of a
  7549. ** blob.
  7550. **
  7551. ** ^The [sqlite3_bind_zeroblob()] and [sqlite3_result_zeroblob()] interfaces
  7552. ** and the built-in [zeroblob] SQL function may be used to create a
  7553. ** zero-filled blob to read or write using the incremental-blob interface.
  7554. **
  7555. ** To avoid a resource leak, every open [BLOB handle] should eventually
  7556. ** be released by a call to [sqlite3_blob_close()].
  7557. **
  7558. ** See also: [sqlite3_blob_close()],
  7559. ** [sqlite3_blob_reopen()], [sqlite3_blob_read()],
  7560. ** [sqlite3_blob_bytes()], [sqlite3_blob_write()].
  7561. */
  7562. SQLITE_API int sqlite3_blob_open(
  7563. sqlite3*,
  7564. const char *zDb,
  7565. const char *zTable,
  7566. const char *zColumn,
  7567. sqlite3_int64 iRow,
  7568. int flags,
  7569. sqlite3_blob **ppBlob
  7570. );
  7571. /*
  7572. ** CAPI3REF: Move a BLOB Handle to a New Row
  7573. ** METHOD: sqlite3_blob
  7574. **
  7575. ** ^This function is used to move an existing [BLOB handle] so that it points
  7576. ** to a different row of the same database table. ^The new row is identified
  7577. ** by the rowid value passed as the second argument. Only the row can be
  7578. ** changed. ^The database, table and column on which the blob handle is open
  7579. ** remain the same. Moving an existing [BLOB handle] to a new row is
  7580. ** faster than closing the existing handle and opening a new one.
  7581. **
  7582. ** ^(The new row must meet the same criteria as for [sqlite3_blob_open()] -
  7583. ** it must exist and there must be either a blob or text value stored in
  7584. ** the nominated column.)^ ^If the new row is not present in the table, or if
  7585. ** it does not contain a blob or text value, or if another error occurs, an
  7586. ** SQLite error code is returned and the blob handle is considered aborted.
  7587. ** ^All subsequent calls to [sqlite3_blob_read()], [sqlite3_blob_write()] or
  7588. ** [sqlite3_blob_reopen()] on an aborted blob handle immediately return
  7589. ** SQLITE_ABORT. ^Calling [sqlite3_blob_bytes()] on an aborted blob handle
  7590. ** always returns zero.
  7591. **
  7592. ** ^This function sets the database handle error code and message.
  7593. */
  7594. SQLITE_API int sqlite3_blob_reopen(sqlite3_blob *, sqlite3_int64);
  7595. /*
  7596. ** CAPI3REF: Close A BLOB Handle
  7597. ** DESTRUCTOR: sqlite3_blob
  7598. **
  7599. ** ^This function closes an open [BLOB handle]. ^(The BLOB handle is closed
  7600. ** unconditionally. Even if this routine returns an error code, the
  7601. ** handle is still closed.)^
  7602. **
  7603. ** ^If the blob handle being closed was opened for read-write access, and if
  7604. ** the database is in auto-commit mode and there are no other open read-write
  7605. ** blob handles or active write statements, the current transaction is
  7606. ** committed. ^If an error occurs while committing the transaction, an error
  7607. ** code is returned and the transaction rolled back.
  7608. **
  7609. ** Calling this function with an argument that is not a NULL pointer or an
  7610. ** open blob handle results in undefined behavior. ^Calling this routine
  7611. ** with a null pointer (such as would be returned by a failed call to
  7612. ** [sqlite3_blob_open()]) is a harmless no-op. ^Otherwise, if this function
  7613. ** is passed a valid open blob handle, the values returned by the
  7614. ** sqlite3_errcode() and sqlite3_errmsg() functions are set before returning.
  7615. */
  7616. SQLITE_API int sqlite3_blob_close(sqlite3_blob *);
  7617. /*
  7618. ** CAPI3REF: Return The Size Of An Open BLOB
  7619. ** METHOD: sqlite3_blob
  7620. **
  7621. ** ^Returns the size in bytes of the BLOB accessible via the
  7622. ** successfully opened [BLOB handle] in its only argument. ^The
  7623. ** incremental blob I/O routines can only read or overwriting existing
  7624. ** blob content; they cannot change the size of a blob.
  7625. **
  7626. ** This routine only works on a [BLOB handle] which has been created
  7627. ** by a prior successful call to [sqlite3_blob_open()] and which has not
  7628. ** been closed by [sqlite3_blob_close()]. Passing any other pointer in
  7629. ** to this routine results in undefined and probably undesirable behavior.
  7630. */
  7631. SQLITE_API int sqlite3_blob_bytes(sqlite3_blob *);
  7632. /*
  7633. ** CAPI3REF: Read Data From A BLOB Incrementally
  7634. ** METHOD: sqlite3_blob
  7635. **
  7636. ** ^(This function is used to read data from an open [BLOB handle] into a
  7637. ** caller-supplied buffer. N bytes of data are copied into buffer Z
  7638. ** from the open BLOB, starting at offset iOffset.)^
  7639. **
  7640. ** ^If offset iOffset is less than N bytes from the end of the BLOB,
  7641. ** [SQLITE_ERROR] is returned and no data is read. ^If N or iOffset is
  7642. ** less than zero, [SQLITE_ERROR] is returned and no data is read.
  7643. ** ^The size of the blob (and hence the maximum value of N+iOffset)
  7644. ** can be determined using the [sqlite3_blob_bytes()] interface.
  7645. **
  7646. ** ^An attempt to read from an expired [BLOB handle] fails with an
  7647. ** error code of [SQLITE_ABORT].
  7648. **
  7649. ** ^(On success, sqlite3_blob_read() returns SQLITE_OK.
  7650. ** Otherwise, an [error code] or an [extended error code] is returned.)^
  7651. **
  7652. ** This routine only works on a [BLOB handle] which has been created
  7653. ** by a prior successful call to [sqlite3_blob_open()] and which has not
  7654. ** been closed by [sqlite3_blob_close()]. Passing any other pointer in
  7655. ** to this routine results in undefined and probably undesirable behavior.
  7656. **
  7657. ** See also: [sqlite3_blob_write()].
  7658. */
  7659. SQLITE_API int sqlite3_blob_read(sqlite3_blob *, void *Z, int N, int iOffset);
  7660. /*
  7661. ** CAPI3REF: Write Data Into A BLOB Incrementally
  7662. ** METHOD: sqlite3_blob
  7663. **
  7664. ** ^(This function is used to write data into an open [BLOB handle] from a
  7665. ** caller-supplied buffer. N bytes of data are copied from the buffer Z
  7666. ** into the open BLOB, starting at offset iOffset.)^
  7667. **
  7668. ** ^(On success, sqlite3_blob_write() returns SQLITE_OK.
  7669. ** Otherwise, an [error code] or an [extended error code] is returned.)^
  7670. ** ^Unless SQLITE_MISUSE is returned, this function sets the
  7671. ** [database connection] error code and message accessible via
  7672. ** [sqlite3_errcode()] and [sqlite3_errmsg()] and related functions.
  7673. **
  7674. ** ^If the [BLOB handle] passed as the first argument was not opened for
  7675. ** writing (the flags parameter to [sqlite3_blob_open()] was zero),
  7676. ** this function returns [SQLITE_READONLY].
  7677. **
  7678. ** This function may only modify the contents of the BLOB; it is
  7679. ** not possible to increase the size of a BLOB using this API.
  7680. ** ^If offset iOffset is less than N bytes from the end of the BLOB,
  7681. ** [SQLITE_ERROR] is returned and no data is written. The size of the
  7682. ** BLOB (and hence the maximum value of N+iOffset) can be determined
  7683. ** using the [sqlite3_blob_bytes()] interface. ^If N or iOffset are less
  7684. ** than zero [SQLITE_ERROR] is returned and no data is written.
  7685. **
  7686. ** ^An attempt to write to an expired [BLOB handle] fails with an
  7687. ** error code of [SQLITE_ABORT]. ^Writes to the BLOB that occurred
  7688. ** before the [BLOB handle] expired are not rolled back by the
  7689. ** expiration of the handle, though of course those changes might
  7690. ** have been overwritten by the statement that expired the BLOB handle
  7691. ** or by other independent statements.
  7692. **
  7693. ** This routine only works on a [BLOB handle] which has been created
  7694. ** by a prior successful call to [sqlite3_blob_open()] and which has not
  7695. ** been closed by [sqlite3_blob_close()]. Passing any other pointer in
  7696. ** to this routine results in undefined and probably undesirable behavior.
  7697. **
  7698. ** See also: [sqlite3_blob_read()].
  7699. */
  7700. SQLITE_API int sqlite3_blob_write(sqlite3_blob *, const void *z, int n, int iOffset);
  7701. /*
  7702. ** CAPI3REF: Virtual File System Objects
  7703. **
  7704. ** A virtual filesystem (VFS) is an [sqlite3_vfs] object
  7705. ** that SQLite uses to interact
  7706. ** with the underlying operating system. Most SQLite builds come with a
  7707. ** single default VFS that is appropriate for the host computer.
  7708. ** New VFSes can be registered and existing VFSes can be unregistered.
  7709. ** The following interfaces are provided.
  7710. **
  7711. ** ^The sqlite3_vfs_find() interface returns a pointer to a VFS given its name.
  7712. ** ^Names are case sensitive.
  7713. ** ^Names are zero-terminated UTF-8 strings.
  7714. ** ^If there is no match, a NULL pointer is returned.
  7715. ** ^If zVfsName is NULL then the default VFS is returned.
  7716. **
  7717. ** ^New VFSes are registered with sqlite3_vfs_register().
  7718. ** ^Each new VFS becomes the default VFS if the makeDflt flag is set.
  7719. ** ^The same VFS can be registered multiple times without injury.
  7720. ** ^To make an existing VFS into the default VFS, register it again
  7721. ** with the makeDflt flag set. If two different VFSes with the
  7722. ** same name are registered, the behavior is undefined. If a
  7723. ** VFS is registered with a name that is NULL or an empty string,
  7724. ** then the behavior is undefined.
  7725. **
  7726. ** ^Unregister a VFS with the sqlite3_vfs_unregister() interface.
  7727. ** ^(If the default VFS is unregistered, another VFS is chosen as
  7728. ** the default. The choice for the new VFS is arbitrary.)^
  7729. */
  7730. SQLITE_API sqlite3_vfs *sqlite3_vfs_find(const char *zVfsName);
  7731. SQLITE_API int sqlite3_vfs_register(sqlite3_vfs*, int makeDflt);
  7732. SQLITE_API int sqlite3_vfs_unregister(sqlite3_vfs*);
  7733. /*
  7734. ** CAPI3REF: Mutexes
  7735. **
  7736. ** The SQLite core uses these routines for thread
  7737. ** synchronization. Though they are intended for internal
  7738. ** use by SQLite, code that links against SQLite is
  7739. ** permitted to use any of these routines.
  7740. **
  7741. ** The SQLite source code contains multiple implementations
  7742. ** of these mutex routines. An appropriate implementation
  7743. ** is selected automatically at compile-time. The following
  7744. ** implementations are available in the SQLite core:
  7745. **
  7746. ** <ul>
  7747. ** <li> SQLITE_MUTEX_PTHREADS
  7748. ** <li> SQLITE_MUTEX_W32
  7749. ** <li> SQLITE_MUTEX_NOOP
  7750. ** </ul>
  7751. **
  7752. ** The SQLITE_MUTEX_NOOP implementation is a set of routines
  7753. ** that does no real locking and is appropriate for use in
  7754. ** a single-threaded application. The SQLITE_MUTEX_PTHREADS and
  7755. ** SQLITE_MUTEX_W32 implementations are appropriate for use on Unix
  7756. ** and Windows.
  7757. **
  7758. ** If SQLite is compiled with the SQLITE_MUTEX_APPDEF preprocessor
  7759. ** macro defined (with "-DSQLITE_MUTEX_APPDEF=1"), then no mutex
  7760. ** implementation is included with the library. In this case the
  7761. ** application must supply a custom mutex implementation using the
  7762. ** [SQLITE_CONFIG_MUTEX] option of the sqlite3_config() function
  7763. ** before calling sqlite3_initialize() or any other public sqlite3_
  7764. ** function that calls sqlite3_initialize().
  7765. **
  7766. ** ^The sqlite3_mutex_alloc() routine allocates a new
  7767. ** mutex and returns a pointer to it. ^The sqlite3_mutex_alloc()
  7768. ** routine returns NULL if it is unable to allocate the requested
  7769. ** mutex. The argument to sqlite3_mutex_alloc() must one of these
  7770. ** integer constants:
  7771. **
  7772. ** <ul>
  7773. ** <li> SQLITE_MUTEX_FAST
  7774. ** <li> SQLITE_MUTEX_RECURSIVE
  7775. ** <li> SQLITE_MUTEX_STATIC_MAIN
  7776. ** <li> SQLITE_MUTEX_STATIC_MEM
  7777. ** <li> SQLITE_MUTEX_STATIC_OPEN
  7778. ** <li> SQLITE_MUTEX_STATIC_PRNG
  7779. ** <li> SQLITE_MUTEX_STATIC_LRU
  7780. ** <li> SQLITE_MUTEX_STATIC_PMEM
  7781. ** <li> SQLITE_MUTEX_STATIC_APP1
  7782. ** <li> SQLITE_MUTEX_STATIC_APP2
  7783. ** <li> SQLITE_MUTEX_STATIC_APP3
  7784. ** <li> SQLITE_MUTEX_STATIC_VFS1
  7785. ** <li> SQLITE_MUTEX_STATIC_VFS2
  7786. ** <li> SQLITE_MUTEX_STATIC_VFS3
  7787. ** </ul>
  7788. **
  7789. ** ^The first two constants (SQLITE_MUTEX_FAST and SQLITE_MUTEX_RECURSIVE)
  7790. ** cause sqlite3_mutex_alloc() to create
  7791. ** a new mutex. ^The new mutex is recursive when SQLITE_MUTEX_RECURSIVE
  7792. ** is used but not necessarily so when SQLITE_MUTEX_FAST is used.
  7793. ** The mutex implementation does not need to make a distinction
  7794. ** between SQLITE_MUTEX_RECURSIVE and SQLITE_MUTEX_FAST if it does
  7795. ** not want to. SQLite will only request a recursive mutex in
  7796. ** cases where it really needs one. If a faster non-recursive mutex
  7797. ** implementation is available on the host platform, the mutex subsystem
  7798. ** might return such a mutex in response to SQLITE_MUTEX_FAST.
  7799. **
  7800. ** ^The other allowed parameters to sqlite3_mutex_alloc() (anything other
  7801. ** than SQLITE_MUTEX_FAST and SQLITE_MUTEX_RECURSIVE) each return
  7802. ** a pointer to a static preexisting mutex. ^Nine static mutexes are
  7803. ** used by the current version of SQLite. Future versions of SQLite
  7804. ** may add additional static mutexes. Static mutexes are for internal
  7805. ** use by SQLite only. Applications that use SQLite mutexes should
  7806. ** use only the dynamic mutexes returned by SQLITE_MUTEX_FAST or
  7807. ** SQLITE_MUTEX_RECURSIVE.
  7808. **
  7809. ** ^Note that if one of the dynamic mutex parameters (SQLITE_MUTEX_FAST
  7810. ** or SQLITE_MUTEX_RECURSIVE) is used then sqlite3_mutex_alloc()
  7811. ** returns a different mutex on every call. ^For the static
  7812. ** mutex types, the same mutex is returned on every call that has
  7813. ** the same type number.
  7814. **
  7815. ** ^The sqlite3_mutex_free() routine deallocates a previously
  7816. ** allocated dynamic mutex. Attempting to deallocate a static
  7817. ** mutex results in undefined behavior.
  7818. **
  7819. ** ^The sqlite3_mutex_enter() and sqlite3_mutex_try() routines attempt
  7820. ** to enter a mutex. ^If another thread is already within the mutex,
  7821. ** sqlite3_mutex_enter() will block and sqlite3_mutex_try() will return
  7822. ** SQLITE_BUSY. ^The sqlite3_mutex_try() interface returns [SQLITE_OK]
  7823. ** upon successful entry. ^(Mutexes created using
  7824. ** SQLITE_MUTEX_RECURSIVE can be entered multiple times by the same thread.
  7825. ** In such cases, the
  7826. ** mutex must be exited an equal number of times before another thread
  7827. ** can enter.)^ If the same thread tries to enter any mutex other
  7828. ** than an SQLITE_MUTEX_RECURSIVE more than once, the behavior is undefined.
  7829. **
  7830. ** ^(Some systems (for example, Windows 95) do not support the operation
  7831. ** implemented by sqlite3_mutex_try(). On those systems, sqlite3_mutex_try()
  7832. ** will always return SQLITE_BUSY. The SQLite core only ever uses
  7833. ** sqlite3_mutex_try() as an optimization so this is acceptable
  7834. ** behavior.)^
  7835. **
  7836. ** ^The sqlite3_mutex_leave() routine exits a mutex that was
  7837. ** previously entered by the same thread. The behavior
  7838. ** is undefined if the mutex is not currently entered by the
  7839. ** calling thread or is not currently allocated.
  7840. **
  7841. ** ^If the argument to sqlite3_mutex_enter(), sqlite3_mutex_try(),
  7842. ** sqlite3_mutex_leave(), or sqlite3_mutex_free() is a NULL pointer,
  7843. ** then any of the four routines behaves as a no-op.
  7844. **
  7845. ** See also: [sqlite3_mutex_held()] and [sqlite3_mutex_notheld()].
  7846. */
  7847. SQLITE_API sqlite3_mutex *sqlite3_mutex_alloc(int);
  7848. SQLITE_API void sqlite3_mutex_free(sqlite3_mutex*);
  7849. SQLITE_API void sqlite3_mutex_enter(sqlite3_mutex*);
  7850. SQLITE_API int sqlite3_mutex_try(sqlite3_mutex*);
  7851. SQLITE_API void sqlite3_mutex_leave(sqlite3_mutex*);
  7852. /*
  7853. ** CAPI3REF: Mutex Methods Object
  7854. **
  7855. ** An instance of this structure defines the low-level routines
  7856. ** used to allocate and use mutexes.
  7857. **
  7858. ** Usually, the default mutex implementations provided by SQLite are
  7859. ** sufficient, however the application has the option of substituting a custom
  7860. ** implementation for specialized deployments or systems for which SQLite
  7861. ** does not provide a suitable implementation. In this case, the application
  7862. ** creates and populates an instance of this structure to pass
  7863. ** to sqlite3_config() along with the [SQLITE_CONFIG_MUTEX] option.
  7864. ** Additionally, an instance of this structure can be used as an
  7865. ** output variable when querying the system for the current mutex
  7866. ** implementation, using the [SQLITE_CONFIG_GETMUTEX] option.
  7867. **
  7868. ** ^The xMutexInit method defined by this structure is invoked as
  7869. ** part of system initialization by the sqlite3_initialize() function.
  7870. ** ^The xMutexInit routine is called by SQLite exactly once for each
  7871. ** effective call to [sqlite3_initialize()].
  7872. **
  7873. ** ^The xMutexEnd method defined by this structure is invoked as
  7874. ** part of system shutdown by the sqlite3_shutdown() function. The
  7875. ** implementation of this method is expected to release all outstanding
  7876. ** resources obtained by the mutex methods implementation, especially
  7877. ** those obtained by the xMutexInit method. ^The xMutexEnd()
  7878. ** interface is invoked exactly once for each call to [sqlite3_shutdown()].
  7879. **
  7880. ** ^(The remaining seven methods defined by this structure (xMutexAlloc,
  7881. ** xMutexFree, xMutexEnter, xMutexTry, xMutexLeave, xMutexHeld and
  7882. ** xMutexNotheld) implement the following interfaces (respectively):
  7883. **
  7884. ** <ul>
  7885. ** <li> [sqlite3_mutex_alloc()] </li>
  7886. ** <li> [sqlite3_mutex_free()] </li>
  7887. ** <li> [sqlite3_mutex_enter()] </li>
  7888. ** <li> [sqlite3_mutex_try()] </li>
  7889. ** <li> [sqlite3_mutex_leave()] </li>
  7890. ** <li> [sqlite3_mutex_held()] </li>
  7891. ** <li> [sqlite3_mutex_notheld()] </li>
  7892. ** </ul>)^
  7893. **
  7894. ** The only difference is that the public sqlite3_XXX functions enumerated
  7895. ** above silently ignore any invocations that pass a NULL pointer instead
  7896. ** of a valid mutex handle. The implementations of the methods defined
  7897. ** by this structure are not required to handle this case. The results
  7898. ** of passing a NULL pointer instead of a valid mutex handle are undefined
  7899. ** (i.e. it is acceptable to provide an implementation that segfaults if
  7900. ** it is passed a NULL pointer).
  7901. **
  7902. ** The xMutexInit() method must be threadsafe. It must be harmless to
  7903. ** invoke xMutexInit() multiple times within the same process and without
  7904. ** intervening calls to xMutexEnd(). Second and subsequent calls to
  7905. ** xMutexInit() must be no-ops.
  7906. **
  7907. ** xMutexInit() must not use SQLite memory allocation ([sqlite3_malloc()]
  7908. ** and its associates). Similarly, xMutexAlloc() must not use SQLite memory
  7909. ** allocation for a static mutex. ^However xMutexAlloc() may use SQLite
  7910. ** memory allocation for a fast or recursive mutex.
  7911. **
  7912. ** ^SQLite will invoke the xMutexEnd() method when [sqlite3_shutdown()] is
  7913. ** called, but only if the prior call to xMutexInit returned SQLITE_OK.
  7914. ** If xMutexInit fails in any way, it is expected to clean up after itself
  7915. ** prior to returning.
  7916. */
  7917. typedef struct sqlite3_mutex_methods sqlite3_mutex_methods;
  7918. struct sqlite3_mutex_methods {
  7919. int (*xMutexInit)(void);
  7920. int (*xMutexEnd)(void);
  7921. sqlite3_mutex *(*xMutexAlloc)(int);
  7922. void (*xMutexFree)(sqlite3_mutex *);
  7923. void (*xMutexEnter)(sqlite3_mutex *);
  7924. int (*xMutexTry)(sqlite3_mutex *);
  7925. void (*xMutexLeave)(sqlite3_mutex *);
  7926. int (*xMutexHeld)(sqlite3_mutex *);
  7927. int (*xMutexNotheld)(sqlite3_mutex *);
  7928. };
  7929. /*
  7930. ** CAPI3REF: Mutex Verification Routines
  7931. **
  7932. ** The sqlite3_mutex_held() and sqlite3_mutex_notheld() routines
  7933. ** are intended for use inside assert() statements. The SQLite core
  7934. ** never uses these routines except inside an assert() and applications
  7935. ** are advised to follow the lead of the core. The SQLite core only
  7936. ** provides implementations for these routines when it is compiled
  7937. ** with the SQLITE_DEBUG flag. External mutex implementations
  7938. ** are only required to provide these routines if SQLITE_DEBUG is
  7939. ** defined and if NDEBUG is not defined.
  7940. **
  7941. ** These routines should return true if the mutex in their argument
  7942. ** is held or not held, respectively, by the calling thread.
  7943. **
  7944. ** The implementation is not required to provide versions of these
  7945. ** routines that actually work. If the implementation does not provide working
  7946. ** versions of these routines, it should at least provide stubs that always
  7947. ** return true so that one does not get spurious assertion failures.
  7948. **
  7949. ** If the argument to sqlite3_mutex_held() is a NULL pointer then
  7950. ** the routine should return 1. This seems counter-intuitive since
  7951. ** clearly the mutex cannot be held if it does not exist. But
  7952. ** the reason the mutex does not exist is because the build is not
  7953. ** using mutexes. And we do not want the assert() containing the
  7954. ** call to sqlite3_mutex_held() to fail, so a non-zero return is
  7955. ** the appropriate thing to do. The sqlite3_mutex_notheld()
  7956. ** interface should also return 1 when given a NULL pointer.
  7957. */
  7958. #ifndef NDEBUG
  7959. SQLITE_API int sqlite3_mutex_held(sqlite3_mutex*);
  7960. SQLITE_API int sqlite3_mutex_notheld(sqlite3_mutex*);
  7961. #endif
  7962. /*
  7963. ** CAPI3REF: Mutex Types
  7964. **
  7965. ** The [sqlite3_mutex_alloc()] interface takes a single argument
  7966. ** which is one of these integer constants.
  7967. **
  7968. ** The set of static mutexes may change from one SQLite release to the
  7969. ** next. Applications that override the built-in mutex logic must be
  7970. ** prepared to accommodate additional static mutexes.
  7971. */
  7972. #define SQLITE_MUTEX_FAST 0
  7973. #define SQLITE_MUTEX_RECURSIVE 1
  7974. #define SQLITE_MUTEX_STATIC_MAIN 2
  7975. #define SQLITE_MUTEX_STATIC_MEM 3 /* sqlite3_malloc() */
  7976. #define SQLITE_MUTEX_STATIC_MEM2 4 /* NOT USED */
  7977. #define SQLITE_MUTEX_STATIC_OPEN 4 /* sqlite3BtreeOpen() */
  7978. #define SQLITE_MUTEX_STATIC_PRNG 5 /* sqlite3_randomness() */
  7979. #define SQLITE_MUTEX_STATIC_LRU 6 /* lru page list */
  7980. #define SQLITE_MUTEX_STATIC_LRU2 7 /* NOT USED */
  7981. #define SQLITE_MUTEX_STATIC_PMEM 7 /* sqlite3PageMalloc() */
  7982. #define SQLITE_MUTEX_STATIC_APP1 8 /* For use by application */
  7983. #define SQLITE_MUTEX_STATIC_APP2 9 /* For use by application */
  7984. #define SQLITE_MUTEX_STATIC_APP3 10 /* For use by application */
  7985. #define SQLITE_MUTEX_STATIC_VFS1 11 /* For use by built-in VFS */
  7986. #define SQLITE_MUTEX_STATIC_VFS2 12 /* For use by extension VFS */
  7987. #define SQLITE_MUTEX_STATIC_VFS3 13 /* For use by application VFS */
  7988. /* Legacy compatibility: */
  7989. #define SQLITE_MUTEX_STATIC_MASTER 2
  7990. /*
  7991. ** CAPI3REF: Retrieve the mutex for a database connection
  7992. ** METHOD: sqlite3
  7993. **
  7994. ** ^This interface returns a pointer the [sqlite3_mutex] object that
  7995. ** serializes access to the [database connection] given in the argument
  7996. ** when the [threading mode] is Serialized.
  7997. ** ^If the [threading mode] is Single-thread or Multi-thread then this
  7998. ** routine returns a NULL pointer.
  7999. */
  8000. SQLITE_API sqlite3_mutex *sqlite3_db_mutex(sqlite3*);
  8001. /*
  8002. ** CAPI3REF: Low-Level Control Of Database Files
  8003. ** METHOD: sqlite3
  8004. ** KEYWORDS: {file control}
  8005. **
  8006. ** ^The [sqlite3_file_control()] interface makes a direct call to the
  8007. ** xFileControl method for the [sqlite3_io_methods] object associated
  8008. ** with a particular database identified by the second argument. ^The
  8009. ** name of the database is "main" for the main database or "temp" for the
  8010. ** TEMP database, or the name that appears after the AS keyword for
  8011. ** databases that are added using the [ATTACH] SQL command.
  8012. ** ^A NULL pointer can be used in place of "main" to refer to the
  8013. ** main database file.
  8014. ** ^The third and fourth parameters to this routine
  8015. ** are passed directly through to the second and third parameters of
  8016. ** the xFileControl method. ^The return value of the xFileControl
  8017. ** method becomes the return value of this routine.
  8018. **
  8019. ** A few opcodes for [sqlite3_file_control()] are handled directly
  8020. ** by the SQLite core and never invoke the
  8021. ** sqlite3_io_methods.xFileControl method.
  8022. ** ^The [SQLITE_FCNTL_FILE_POINTER] value for the op parameter causes
  8023. ** a pointer to the underlying [sqlite3_file] object to be written into
  8024. ** the space pointed to by the 4th parameter. The
  8025. ** [SQLITE_FCNTL_JOURNAL_POINTER] works similarly except that it returns
  8026. ** the [sqlite3_file] object associated with the journal file instead of
  8027. ** the main database. The [SQLITE_FCNTL_VFS_POINTER] opcode returns
  8028. ** a pointer to the underlying [sqlite3_vfs] object for the file.
  8029. ** The [SQLITE_FCNTL_DATA_VERSION] returns the data version counter
  8030. ** from the pager.
  8031. **
  8032. ** ^If the second parameter (zDbName) does not match the name of any
  8033. ** open database file, then SQLITE_ERROR is returned. ^This error
  8034. ** code is not remembered and will not be recalled by [sqlite3_errcode()]
  8035. ** or [sqlite3_errmsg()]. The underlying xFileControl method might
  8036. ** also return SQLITE_ERROR. There is no way to distinguish between
  8037. ** an incorrect zDbName and an SQLITE_ERROR return from the underlying
  8038. ** xFileControl method.
  8039. **
  8040. ** See also: [file control opcodes]
  8041. */
  8042. SQLITE_API int sqlite3_file_control(sqlite3*, const char *zDbName, int op, void*);
  8043. /*
  8044. ** CAPI3REF: Testing Interface
  8045. **
  8046. ** ^The sqlite3_test_control() interface is used to read out internal
  8047. ** state of SQLite and to inject faults into SQLite for testing
  8048. ** purposes. ^The first parameter is an operation code that determines
  8049. ** the number, meaning, and operation of all subsequent parameters.
  8050. **
  8051. ** This interface is not for use by applications. It exists solely
  8052. ** for verifying the correct operation of the SQLite library. Depending
  8053. ** on how the SQLite library is compiled, this interface might not exist.
  8054. **
  8055. ** The details of the operation codes, their meanings, the parameters
  8056. ** they take, and what they do are all subject to change without notice.
  8057. ** Unlike most of the SQLite API, this function is not guaranteed to
  8058. ** operate consistently from one release to the next.
  8059. */
  8060. SQLITE_API int sqlite3_test_control(int op, ...);
  8061. /*
  8062. ** CAPI3REF: Testing Interface Operation Codes
  8063. **
  8064. ** These constants are the valid operation code parameters used
  8065. ** as the first argument to [sqlite3_test_control()].
  8066. **
  8067. ** These parameters and their meanings are subject to change
  8068. ** without notice. These values are for testing purposes only.
  8069. ** Applications should not use any of these parameters or the
  8070. ** [sqlite3_test_control()] interface.
  8071. */
  8072. #define SQLITE_TESTCTRL_FIRST 5
  8073. #define SQLITE_TESTCTRL_PRNG_SAVE 5
  8074. #define SQLITE_TESTCTRL_PRNG_RESTORE 6
  8075. #define SQLITE_TESTCTRL_PRNG_RESET 7 /* NOT USED */
  8076. #define SQLITE_TESTCTRL_FK_NO_ACTION 7
  8077. #define SQLITE_TESTCTRL_BITVEC_TEST 8
  8078. #define SQLITE_TESTCTRL_FAULT_INSTALL 9
  8079. #define SQLITE_TESTCTRL_BENIGN_MALLOC_HOOKS 10
  8080. #define SQLITE_TESTCTRL_PENDING_BYTE 11
  8081. #define SQLITE_TESTCTRL_ASSERT 12
  8082. #define SQLITE_TESTCTRL_ALWAYS 13
  8083. #define SQLITE_TESTCTRL_RESERVE 14 /* NOT USED */
  8084. #define SQLITE_TESTCTRL_OPTIMIZATIONS 15
  8085. #define SQLITE_TESTCTRL_ISKEYWORD 16 /* NOT USED */
  8086. #define SQLITE_TESTCTRL_SCRATCHMALLOC 17 /* NOT USED */
  8087. #define SQLITE_TESTCTRL_INTERNAL_FUNCTIONS 17
  8088. #define SQLITE_TESTCTRL_LOCALTIME_FAULT 18
  8089. #define SQLITE_TESTCTRL_EXPLAIN_STMT 19 /* NOT USED */
  8090. #define SQLITE_TESTCTRL_ONCE_RESET_THRESHOLD 19
  8091. #define SQLITE_TESTCTRL_NEVER_CORRUPT 20
  8092. #define SQLITE_TESTCTRL_VDBE_COVERAGE 21
  8093. #define SQLITE_TESTCTRL_BYTEORDER 22
  8094. #define SQLITE_TESTCTRL_ISINIT 23
  8095. #define SQLITE_TESTCTRL_SORTER_MMAP 24
  8096. #define SQLITE_TESTCTRL_IMPOSTER 25
  8097. #define SQLITE_TESTCTRL_PARSER_COVERAGE 26
  8098. #define SQLITE_TESTCTRL_RESULT_INTREAL 27
  8099. #define SQLITE_TESTCTRL_PRNG_SEED 28
  8100. #define SQLITE_TESTCTRL_EXTRA_SCHEMA_CHECKS 29
  8101. #define SQLITE_TESTCTRL_SEEK_COUNT 30
  8102. #define SQLITE_TESTCTRL_TRACEFLAGS 31
  8103. #define SQLITE_TESTCTRL_TUNE 32
  8104. #define SQLITE_TESTCTRL_LOGEST 33
  8105. #define SQLITE_TESTCTRL_USELONGDOUBLE 34
  8106. #define SQLITE_TESTCTRL_LAST 34 /* Largest TESTCTRL */
  8107. /*
  8108. ** CAPI3REF: SQL Keyword Checking
  8109. **
  8110. ** These routines provide access to the set of SQL language keywords
  8111. ** recognized by SQLite. Applications can uses these routines to determine
  8112. ** whether or not a specific identifier needs to be escaped (for example,
  8113. ** by enclosing in double-quotes) so as not to confuse the parser.
  8114. **
  8115. ** The sqlite3_keyword_count() interface returns the number of distinct
  8116. ** keywords understood by SQLite.
  8117. **
  8118. ** The sqlite3_keyword_name(N,Z,L) interface finds the N-th keyword and
  8119. ** makes *Z point to that keyword expressed as UTF8 and writes the number
  8120. ** of bytes in the keyword into *L. The string that *Z points to is not
  8121. ** zero-terminated. The sqlite3_keyword_name(N,Z,L) routine returns
  8122. ** SQLITE_OK if N is within bounds and SQLITE_ERROR if not. If either Z
  8123. ** or L are NULL or invalid pointers then calls to
  8124. ** sqlite3_keyword_name(N,Z,L) result in undefined behavior.
  8125. **
  8126. ** The sqlite3_keyword_check(Z,L) interface checks to see whether or not
  8127. ** the L-byte UTF8 identifier that Z points to is a keyword, returning non-zero
  8128. ** if it is and zero if not.
  8129. **
  8130. ** The parser used by SQLite is forgiving. It is often possible to use
  8131. ** a keyword as an identifier as long as such use does not result in a
  8132. ** parsing ambiguity. For example, the statement
  8133. ** "CREATE TABLE BEGIN(REPLACE,PRAGMA,END);" is accepted by SQLite, and
  8134. ** creates a new table named "BEGIN" with three columns named
  8135. ** "REPLACE", "PRAGMA", and "END". Nevertheless, best practice is to avoid
  8136. ** using keywords as identifiers. Common techniques used to avoid keyword
  8137. ** name collisions include:
  8138. ** <ul>
  8139. ** <li> Put all identifier names inside double-quotes. This is the official
  8140. ** SQL way to escape identifier names.
  8141. ** <li> Put identifier names inside &#91;...&#93;. This is not standard SQL,
  8142. ** but it is what SQL Server does and so lots of programmers use this
  8143. ** technique.
  8144. ** <li> Begin every identifier with the letter "Z" as no SQL keywords start
  8145. ** with "Z".
  8146. ** <li> Include a digit somewhere in every identifier name.
  8147. ** </ul>
  8148. **
  8149. ** Note that the number of keywords understood by SQLite can depend on
  8150. ** compile-time options. For example, "VACUUM" is not a keyword if
  8151. ** SQLite is compiled with the [-DSQLITE_OMIT_VACUUM] option. Also,
  8152. ** new keywords may be added to future releases of SQLite.
  8153. */
  8154. SQLITE_API int sqlite3_keyword_count(void);
  8155. SQLITE_API int sqlite3_keyword_name(int,const char**,int*);
  8156. SQLITE_API int sqlite3_keyword_check(const char*,int);
  8157. /*
  8158. ** CAPI3REF: Dynamic String Object
  8159. ** KEYWORDS: {dynamic string}
  8160. **
  8161. ** An instance of the sqlite3_str object contains a dynamically-sized
  8162. ** string under construction.
  8163. **
  8164. ** The lifecycle of an sqlite3_str object is as follows:
  8165. ** <ol>
  8166. ** <li> ^The sqlite3_str object is created using [sqlite3_str_new()].
  8167. ** <li> ^Text is appended to the sqlite3_str object using various
  8168. ** methods, such as [sqlite3_str_appendf()].
  8169. ** <li> ^The sqlite3_str object is destroyed and the string it created
  8170. ** is returned using the [sqlite3_str_finish()] interface.
  8171. ** </ol>
  8172. */
  8173. typedef struct sqlite3_str sqlite3_str;
  8174. /*
  8175. ** CAPI3REF: Create A New Dynamic String Object
  8176. ** CONSTRUCTOR: sqlite3_str
  8177. **
  8178. ** ^The [sqlite3_str_new(D)] interface allocates and initializes
  8179. ** a new [sqlite3_str] object. To avoid memory leaks, the object returned by
  8180. ** [sqlite3_str_new()] must be freed by a subsequent call to
  8181. ** [sqlite3_str_finish(X)].
  8182. **
  8183. ** ^The [sqlite3_str_new(D)] interface always returns a pointer to a
  8184. ** valid [sqlite3_str] object, though in the event of an out-of-memory
  8185. ** error the returned object might be a special singleton that will
  8186. ** silently reject new text, always return SQLITE_NOMEM from
  8187. ** [sqlite3_str_errcode()], always return 0 for
  8188. ** [sqlite3_str_length()], and always return NULL from
  8189. ** [sqlite3_str_finish(X)]. It is always safe to use the value
  8190. ** returned by [sqlite3_str_new(D)] as the sqlite3_str parameter
  8191. ** to any of the other [sqlite3_str] methods.
  8192. **
  8193. ** The D parameter to [sqlite3_str_new(D)] may be NULL. If the
  8194. ** D parameter in [sqlite3_str_new(D)] is not NULL, then the maximum
  8195. ** length of the string contained in the [sqlite3_str] object will be
  8196. ** the value set for [sqlite3_limit](D,[SQLITE_LIMIT_LENGTH]) instead
  8197. ** of [SQLITE_MAX_LENGTH].
  8198. */
  8199. SQLITE_API sqlite3_str *sqlite3_str_new(sqlite3*);
  8200. /*
  8201. ** CAPI3REF: Finalize A Dynamic String
  8202. ** DESTRUCTOR: sqlite3_str
  8203. **
  8204. ** ^The [sqlite3_str_finish(X)] interface destroys the sqlite3_str object X
  8205. ** and returns a pointer to a memory buffer obtained from [sqlite3_malloc64()]
  8206. ** that contains the constructed string. The calling application should
  8207. ** pass the returned value to [sqlite3_free()] to avoid a memory leak.
  8208. ** ^The [sqlite3_str_finish(X)] interface may return a NULL pointer if any
  8209. ** errors were encountered during construction of the string. ^The
  8210. ** [sqlite3_str_finish(X)] interface will also return a NULL pointer if the
  8211. ** string in [sqlite3_str] object X is zero bytes long.
  8212. */
  8213. SQLITE_API char *sqlite3_str_finish(sqlite3_str*);
  8214. /*
  8215. ** CAPI3REF: Add Content To A Dynamic String
  8216. ** METHOD: sqlite3_str
  8217. **
  8218. ** These interfaces add content to an sqlite3_str object previously obtained
  8219. ** from [sqlite3_str_new()].
  8220. **
  8221. ** ^The [sqlite3_str_appendf(X,F,...)] and
  8222. ** [sqlite3_str_vappendf(X,F,V)] interfaces uses the [built-in printf]
  8223. ** functionality of SQLite to append formatted text onto the end of
  8224. ** [sqlite3_str] object X.
  8225. **
  8226. ** ^The [sqlite3_str_append(X,S,N)] method appends exactly N bytes from string S
  8227. ** onto the end of the [sqlite3_str] object X. N must be non-negative.
  8228. ** S must contain at least N non-zero bytes of content. To append a
  8229. ** zero-terminated string in its entirety, use the [sqlite3_str_appendall()]
  8230. ** method instead.
  8231. **
  8232. ** ^The [sqlite3_str_appendall(X,S)] method appends the complete content of
  8233. ** zero-terminated string S onto the end of [sqlite3_str] object X.
  8234. **
  8235. ** ^The [sqlite3_str_appendchar(X,N,C)] method appends N copies of the
  8236. ** single-byte character C onto the end of [sqlite3_str] object X.
  8237. ** ^This method can be used, for example, to add whitespace indentation.
  8238. **
  8239. ** ^The [sqlite3_str_reset(X)] method resets the string under construction
  8240. ** inside [sqlite3_str] object X back to zero bytes in length.
  8241. **
  8242. ** These methods do not return a result code. ^If an error occurs, that fact
  8243. ** is recorded in the [sqlite3_str] object and can be recovered by a
  8244. ** subsequent call to [sqlite3_str_errcode(X)].
  8245. */
  8246. SQLITE_API void sqlite3_str_appendf(sqlite3_str*, const char *zFormat, ...);
  8247. SQLITE_API void sqlite3_str_vappendf(sqlite3_str*, const char *zFormat, va_list);
  8248. SQLITE_API void sqlite3_str_append(sqlite3_str*, const char *zIn, int N);
  8249. SQLITE_API void sqlite3_str_appendall(sqlite3_str*, const char *zIn);
  8250. SQLITE_API void sqlite3_str_appendchar(sqlite3_str*, int N, char C);
  8251. SQLITE_API void sqlite3_str_reset(sqlite3_str*);
  8252. /*
  8253. ** CAPI3REF: Status Of A Dynamic String
  8254. ** METHOD: sqlite3_str
  8255. **
  8256. ** These interfaces return the current status of an [sqlite3_str] object.
  8257. **
  8258. ** ^If any prior errors have occurred while constructing the dynamic string
  8259. ** in sqlite3_str X, then the [sqlite3_str_errcode(X)] method will return
  8260. ** an appropriate error code. ^The [sqlite3_str_errcode(X)] method returns
  8261. ** [SQLITE_NOMEM] following any out-of-memory error, or
  8262. ** [SQLITE_TOOBIG] if the size of the dynamic string exceeds
  8263. ** [SQLITE_MAX_LENGTH], or [SQLITE_OK] if there have been no errors.
  8264. **
  8265. ** ^The [sqlite3_str_length(X)] method returns the current length, in bytes,
  8266. ** of the dynamic string under construction in [sqlite3_str] object X.
  8267. ** ^The length returned by [sqlite3_str_length(X)] does not include the
  8268. ** zero-termination byte.
  8269. **
  8270. ** ^The [sqlite3_str_value(X)] method returns a pointer to the current
  8271. ** content of the dynamic string under construction in X. The value
  8272. ** returned by [sqlite3_str_value(X)] is managed by the sqlite3_str object X
  8273. ** and might be freed or altered by any subsequent method on the same
  8274. ** [sqlite3_str] object. Applications must not used the pointer returned
  8275. ** [sqlite3_str_value(X)] after any subsequent method call on the same
  8276. ** object. ^Applications may change the content of the string returned
  8277. ** by [sqlite3_str_value(X)] as long as they do not write into any bytes
  8278. ** outside the range of 0 to [sqlite3_str_length(X)] and do not read or
  8279. ** write any byte after any subsequent sqlite3_str method call.
  8280. */
  8281. SQLITE_API int sqlite3_str_errcode(sqlite3_str*);
  8282. SQLITE_API int sqlite3_str_length(sqlite3_str*);
  8283. SQLITE_API char *sqlite3_str_value(sqlite3_str*);
  8284. /*
  8285. ** CAPI3REF: SQLite Runtime Status
  8286. **
  8287. ** ^These interfaces are used to retrieve runtime status information
  8288. ** about the performance of SQLite, and optionally to reset various
  8289. ** highwater marks. ^The first argument is an integer code for
  8290. ** the specific parameter to measure. ^(Recognized integer codes
  8291. ** are of the form [status parameters | SQLITE_STATUS_...].)^
  8292. ** ^The current value of the parameter is returned into *pCurrent.
  8293. ** ^The highest recorded value is returned in *pHighwater. ^If the
  8294. ** resetFlag is true, then the highest record value is reset after
  8295. ** *pHighwater is written. ^(Some parameters do not record the highest
  8296. ** value. For those parameters
  8297. ** nothing is written into *pHighwater and the resetFlag is ignored.)^
  8298. ** ^(Other parameters record only the highwater mark and not the current
  8299. ** value. For these latter parameters nothing is written into *pCurrent.)^
  8300. **
  8301. ** ^The sqlite3_status() and sqlite3_status64() routines return
  8302. ** SQLITE_OK on success and a non-zero [error code] on failure.
  8303. **
  8304. ** If either the current value or the highwater mark is too large to
  8305. ** be represented by a 32-bit integer, then the values returned by
  8306. ** sqlite3_status() are undefined.
  8307. **
  8308. ** See also: [sqlite3_db_status()]
  8309. */
  8310. SQLITE_API int sqlite3_status(int op, int *pCurrent, int *pHighwater, int resetFlag);
  8311. SQLITE_API int sqlite3_status64(
  8312. int op,
  8313. sqlite3_int64 *pCurrent,
  8314. sqlite3_int64 *pHighwater,
  8315. int resetFlag
  8316. );
  8317. /*
  8318. ** CAPI3REF: Status Parameters
  8319. ** KEYWORDS: {status parameters}
  8320. **
  8321. ** These integer constants designate various run-time status parameters
  8322. ** that can be returned by [sqlite3_status()].
  8323. **
  8324. ** <dl>
  8325. ** [[SQLITE_STATUS_MEMORY_USED]] ^(<dt>SQLITE_STATUS_MEMORY_USED</dt>
  8326. ** <dd>This parameter is the current amount of memory checked out
  8327. ** using [sqlite3_malloc()], either directly or indirectly. The
  8328. ** figure includes calls made to [sqlite3_malloc()] by the application
  8329. ** and internal memory usage by the SQLite library. Auxiliary page-cache
  8330. ** memory controlled by [SQLITE_CONFIG_PAGECACHE] is not included in
  8331. ** this parameter. The amount returned is the sum of the allocation
  8332. ** sizes as reported by the xSize method in [sqlite3_mem_methods].</dd>)^
  8333. **
  8334. ** [[SQLITE_STATUS_MALLOC_SIZE]] ^(<dt>SQLITE_STATUS_MALLOC_SIZE</dt>
  8335. ** <dd>This parameter records the largest memory allocation request
  8336. ** handed to [sqlite3_malloc()] or [sqlite3_realloc()] (or their
  8337. ** internal equivalents). Only the value returned in the
  8338. ** *pHighwater parameter to [sqlite3_status()] is of interest.
  8339. ** The value written into the *pCurrent parameter is undefined.</dd>)^
  8340. **
  8341. ** [[SQLITE_STATUS_MALLOC_COUNT]] ^(<dt>SQLITE_STATUS_MALLOC_COUNT</dt>
  8342. ** <dd>This parameter records the number of separate memory allocations
  8343. ** currently checked out.</dd>)^
  8344. **
  8345. ** [[SQLITE_STATUS_PAGECACHE_USED]] ^(<dt>SQLITE_STATUS_PAGECACHE_USED</dt>
  8346. ** <dd>This parameter returns the number of pages used out of the
  8347. ** [pagecache memory allocator] that was configured using
  8348. ** [SQLITE_CONFIG_PAGECACHE]. The
  8349. ** value returned is in pages, not in bytes.</dd>)^
  8350. **
  8351. ** [[SQLITE_STATUS_PAGECACHE_OVERFLOW]]
  8352. ** ^(<dt>SQLITE_STATUS_PAGECACHE_OVERFLOW</dt>
  8353. ** <dd>This parameter returns the number of bytes of page cache
  8354. ** allocation which could not be satisfied by the [SQLITE_CONFIG_PAGECACHE]
  8355. ** buffer and where forced to overflow to [sqlite3_malloc()]. The
  8356. ** returned value includes allocations that overflowed because they
  8357. ** where too large (they were larger than the "sz" parameter to
  8358. ** [SQLITE_CONFIG_PAGECACHE]) and allocations that overflowed because
  8359. ** no space was left in the page cache.</dd>)^
  8360. **
  8361. ** [[SQLITE_STATUS_PAGECACHE_SIZE]] ^(<dt>SQLITE_STATUS_PAGECACHE_SIZE</dt>
  8362. ** <dd>This parameter records the largest memory allocation request
  8363. ** handed to the [pagecache memory allocator]. Only the value returned in the
  8364. ** *pHighwater parameter to [sqlite3_status()] is of interest.
  8365. ** The value written into the *pCurrent parameter is undefined.</dd>)^
  8366. **
  8367. ** [[SQLITE_STATUS_SCRATCH_USED]] <dt>SQLITE_STATUS_SCRATCH_USED</dt>
  8368. ** <dd>No longer used.</dd>
  8369. **
  8370. ** [[SQLITE_STATUS_SCRATCH_OVERFLOW]] ^(<dt>SQLITE_STATUS_SCRATCH_OVERFLOW</dt>
  8371. ** <dd>No longer used.</dd>
  8372. **
  8373. ** [[SQLITE_STATUS_SCRATCH_SIZE]] <dt>SQLITE_STATUS_SCRATCH_SIZE</dt>
  8374. ** <dd>No longer used.</dd>
  8375. **
  8376. ** [[SQLITE_STATUS_PARSER_STACK]] ^(<dt>SQLITE_STATUS_PARSER_STACK</dt>
  8377. ** <dd>The *pHighwater parameter records the deepest parser stack.
  8378. ** The *pCurrent value is undefined. The *pHighwater value is only
  8379. ** meaningful if SQLite is compiled with [YYTRACKMAXSTACKDEPTH].</dd>)^
  8380. ** </dl>
  8381. **
  8382. ** New status parameters may be added from time to time.
  8383. */
  8384. #define SQLITE_STATUS_MEMORY_USED 0
  8385. #define SQLITE_STATUS_PAGECACHE_USED 1
  8386. #define SQLITE_STATUS_PAGECACHE_OVERFLOW 2
  8387. #define SQLITE_STATUS_SCRATCH_USED 3 /* NOT USED */
  8388. #define SQLITE_STATUS_SCRATCH_OVERFLOW 4 /* NOT USED */
  8389. #define SQLITE_STATUS_MALLOC_SIZE 5
  8390. #define SQLITE_STATUS_PARSER_STACK 6
  8391. #define SQLITE_STATUS_PAGECACHE_SIZE 7
  8392. #define SQLITE_STATUS_SCRATCH_SIZE 8 /* NOT USED */
  8393. #define SQLITE_STATUS_MALLOC_COUNT 9
  8394. /*
  8395. ** CAPI3REF: Database Connection Status
  8396. ** METHOD: sqlite3
  8397. **
  8398. ** ^This interface is used to retrieve runtime status information
  8399. ** about a single [database connection]. ^The first argument is the
  8400. ** database connection object to be interrogated. ^The second argument
  8401. ** is an integer constant, taken from the set of
  8402. ** [SQLITE_DBSTATUS options], that
  8403. ** determines the parameter to interrogate. The set of
  8404. ** [SQLITE_DBSTATUS options] is likely
  8405. ** to grow in future releases of SQLite.
  8406. **
  8407. ** ^The current value of the requested parameter is written into *pCur
  8408. ** and the highest instantaneous value is written into *pHiwtr. ^If
  8409. ** the resetFlg is true, then the highest instantaneous value is
  8410. ** reset back down to the current value.
  8411. **
  8412. ** ^The sqlite3_db_status() routine returns SQLITE_OK on success and a
  8413. ** non-zero [error code] on failure.
  8414. **
  8415. ** See also: [sqlite3_status()] and [sqlite3_stmt_status()].
  8416. */
  8417. SQLITE_API int sqlite3_db_status(sqlite3*, int op, int *pCur, int *pHiwtr, int resetFlg);
  8418. /*
  8419. ** CAPI3REF: Status Parameters for database connections
  8420. ** KEYWORDS: {SQLITE_DBSTATUS options}
  8421. **
  8422. ** These constants are the available integer "verbs" that can be passed as
  8423. ** the second argument to the [sqlite3_db_status()] interface.
  8424. **
  8425. ** New verbs may be added in future releases of SQLite. Existing verbs
  8426. ** might be discontinued. Applications should check the return code from
  8427. ** [sqlite3_db_status()] to make sure that the call worked.
  8428. ** The [sqlite3_db_status()] interface will return a non-zero error code
  8429. ** if a discontinued or unsupported verb is invoked.
  8430. **
  8431. ** <dl>
  8432. ** [[SQLITE_DBSTATUS_LOOKASIDE_USED]] ^(<dt>SQLITE_DBSTATUS_LOOKASIDE_USED</dt>
  8433. ** <dd>This parameter returns the number of lookaside memory slots currently
  8434. ** checked out.</dd>)^
  8435. **
  8436. ** [[SQLITE_DBSTATUS_LOOKASIDE_HIT]] ^(<dt>SQLITE_DBSTATUS_LOOKASIDE_HIT</dt>
  8437. ** <dd>This parameter returns the number of malloc attempts that were
  8438. ** satisfied using lookaside memory. Only the high-water value is meaningful;
  8439. ** the current value is always zero.)^
  8440. **
  8441. ** [[SQLITE_DBSTATUS_LOOKASIDE_MISS_SIZE]]
  8442. ** ^(<dt>SQLITE_DBSTATUS_LOOKASIDE_MISS_SIZE</dt>
  8443. ** <dd>This parameter returns the number malloc attempts that might have
  8444. ** been satisfied using lookaside memory but failed due to the amount of
  8445. ** memory requested being larger than the lookaside slot size.
  8446. ** Only the high-water value is meaningful;
  8447. ** the current value is always zero.)^
  8448. **
  8449. ** [[SQLITE_DBSTATUS_LOOKASIDE_MISS_FULL]]
  8450. ** ^(<dt>SQLITE_DBSTATUS_LOOKASIDE_MISS_FULL</dt>
  8451. ** <dd>This parameter returns the number malloc attempts that might have
  8452. ** been satisfied using lookaside memory but failed due to all lookaside
  8453. ** memory already being in use.
  8454. ** Only the high-water value is meaningful;
  8455. ** the current value is always zero.)^
  8456. **
  8457. ** [[SQLITE_DBSTATUS_CACHE_USED]] ^(<dt>SQLITE_DBSTATUS_CACHE_USED</dt>
  8458. ** <dd>This parameter returns the approximate number of bytes of heap
  8459. ** memory used by all pager caches associated with the database connection.)^
  8460. ** ^The highwater mark associated with SQLITE_DBSTATUS_CACHE_USED is always 0.
  8461. **
  8462. ** [[SQLITE_DBSTATUS_CACHE_USED_SHARED]]
  8463. ** ^(<dt>SQLITE_DBSTATUS_CACHE_USED_SHARED</dt>
  8464. ** <dd>This parameter is similar to DBSTATUS_CACHE_USED, except that if a
  8465. ** pager cache is shared between two or more connections the bytes of heap
  8466. ** memory used by that pager cache is divided evenly between the attached
  8467. ** connections.)^ In other words, if none of the pager caches associated
  8468. ** with the database connection are shared, this request returns the same
  8469. ** value as DBSTATUS_CACHE_USED. Or, if one or more or the pager caches are
  8470. ** shared, the value returned by this call will be smaller than that returned
  8471. ** by DBSTATUS_CACHE_USED. ^The highwater mark associated with
  8472. ** SQLITE_DBSTATUS_CACHE_USED_SHARED is always 0.
  8473. **
  8474. ** [[SQLITE_DBSTATUS_SCHEMA_USED]] ^(<dt>SQLITE_DBSTATUS_SCHEMA_USED</dt>
  8475. ** <dd>This parameter returns the approximate number of bytes of heap
  8476. ** memory used to store the schema for all databases associated
  8477. ** with the connection - main, temp, and any [ATTACH]-ed databases.)^
  8478. ** ^The full amount of memory used by the schemas is reported, even if the
  8479. ** schema memory is shared with other database connections due to
  8480. ** [shared cache mode] being enabled.
  8481. ** ^The highwater mark associated with SQLITE_DBSTATUS_SCHEMA_USED is always 0.
  8482. **
  8483. ** [[SQLITE_DBSTATUS_STMT_USED]] ^(<dt>SQLITE_DBSTATUS_STMT_USED</dt>
  8484. ** <dd>This parameter returns the approximate number of bytes of heap
  8485. ** and lookaside memory used by all prepared statements associated with
  8486. ** the database connection.)^
  8487. ** ^The highwater mark associated with SQLITE_DBSTATUS_STMT_USED is always 0.
  8488. ** </dd>
  8489. **
  8490. ** [[SQLITE_DBSTATUS_CACHE_HIT]] ^(<dt>SQLITE_DBSTATUS_CACHE_HIT</dt>
  8491. ** <dd>This parameter returns the number of pager cache hits that have
  8492. ** occurred.)^ ^The highwater mark associated with SQLITE_DBSTATUS_CACHE_HIT
  8493. ** is always 0.
  8494. ** </dd>
  8495. **
  8496. ** [[SQLITE_DBSTATUS_CACHE_MISS]] ^(<dt>SQLITE_DBSTATUS_CACHE_MISS</dt>
  8497. ** <dd>This parameter returns the number of pager cache misses that have
  8498. ** occurred.)^ ^The highwater mark associated with SQLITE_DBSTATUS_CACHE_MISS
  8499. ** is always 0.
  8500. ** </dd>
  8501. **
  8502. ** [[SQLITE_DBSTATUS_CACHE_WRITE]] ^(<dt>SQLITE_DBSTATUS_CACHE_WRITE</dt>
  8503. ** <dd>This parameter returns the number of dirty cache entries that have
  8504. ** been written to disk. Specifically, the number of pages written to the
  8505. ** wal file in wal mode databases, or the number of pages written to the
  8506. ** database file in rollback mode databases. Any pages written as part of
  8507. ** transaction rollback or database recovery operations are not included.
  8508. ** If an IO or other error occurs while writing a page to disk, the effect
  8509. ** on subsequent SQLITE_DBSTATUS_CACHE_WRITE requests is undefined.)^ ^The
  8510. ** highwater mark associated with SQLITE_DBSTATUS_CACHE_WRITE is always 0.
  8511. ** </dd>
  8512. **
  8513. ** [[SQLITE_DBSTATUS_CACHE_SPILL]] ^(<dt>SQLITE_DBSTATUS_CACHE_SPILL</dt>
  8514. ** <dd>This parameter returns the number of dirty cache entries that have
  8515. ** been written to disk in the middle of a transaction due to the page
  8516. ** cache overflowing. Transactions are more efficient if they are written
  8517. ** to disk all at once. When pages spill mid-transaction, that introduces
  8518. ** additional overhead. This parameter can be used help identify
  8519. ** inefficiencies that can be resolved by increasing the cache size.
  8520. ** </dd>
  8521. **
  8522. ** [[SQLITE_DBSTATUS_DEFERRED_FKS]] ^(<dt>SQLITE_DBSTATUS_DEFERRED_FKS</dt>
  8523. ** <dd>This parameter returns zero for the current value if and only if
  8524. ** all foreign key constraints (deferred or immediate) have been
  8525. ** resolved.)^ ^The highwater mark is always 0.
  8526. ** </dd>
  8527. ** </dl>
  8528. */
  8529. #define SQLITE_DBSTATUS_LOOKASIDE_USED 0
  8530. #define SQLITE_DBSTATUS_CACHE_USED 1
  8531. #define SQLITE_DBSTATUS_SCHEMA_USED 2
  8532. #define SQLITE_DBSTATUS_STMT_USED 3
  8533. #define SQLITE_DBSTATUS_LOOKASIDE_HIT 4
  8534. #define SQLITE_DBSTATUS_LOOKASIDE_MISS_SIZE 5
  8535. #define SQLITE_DBSTATUS_LOOKASIDE_MISS_FULL 6
  8536. #define SQLITE_DBSTATUS_CACHE_HIT 7
  8537. #define SQLITE_DBSTATUS_CACHE_MISS 8
  8538. #define SQLITE_DBSTATUS_CACHE_WRITE 9
  8539. #define SQLITE_DBSTATUS_DEFERRED_FKS 10
  8540. #define SQLITE_DBSTATUS_CACHE_USED_SHARED 11
  8541. #define SQLITE_DBSTATUS_CACHE_SPILL 12
  8542. #define SQLITE_DBSTATUS_MAX 12 /* Largest defined DBSTATUS */
  8543. /*
  8544. ** CAPI3REF: Prepared Statement Status
  8545. ** METHOD: sqlite3_stmt
  8546. **
  8547. ** ^(Each prepared statement maintains various
  8548. ** [SQLITE_STMTSTATUS counters] that measure the number
  8549. ** of times it has performed specific operations.)^ These counters can
  8550. ** be used to monitor the performance characteristics of the prepared
  8551. ** statements. For example, if the number of table steps greatly exceeds
  8552. ** the number of table searches or result rows, that would tend to indicate
  8553. ** that the prepared statement is using a full table scan rather than
  8554. ** an index.
  8555. **
  8556. ** ^(This interface is used to retrieve and reset counter values from
  8557. ** a [prepared statement]. The first argument is the prepared statement
  8558. ** object to be interrogated. The second argument
  8559. ** is an integer code for a specific [SQLITE_STMTSTATUS counter]
  8560. ** to be interrogated.)^
  8561. ** ^The current value of the requested counter is returned.
  8562. ** ^If the resetFlg is true, then the counter is reset to zero after this
  8563. ** interface call returns.
  8564. **
  8565. ** See also: [sqlite3_status()] and [sqlite3_db_status()].
  8566. */
  8567. SQLITE_API int sqlite3_stmt_status(sqlite3_stmt*, int op,int resetFlg);
  8568. /*
  8569. ** CAPI3REF: Status Parameters for prepared statements
  8570. ** KEYWORDS: {SQLITE_STMTSTATUS counter} {SQLITE_STMTSTATUS counters}
  8571. **
  8572. ** These preprocessor macros define integer codes that name counter
  8573. ** values associated with the [sqlite3_stmt_status()] interface.
  8574. ** The meanings of the various counters are as follows:
  8575. **
  8576. ** <dl>
  8577. ** [[SQLITE_STMTSTATUS_FULLSCAN_STEP]] <dt>SQLITE_STMTSTATUS_FULLSCAN_STEP</dt>
  8578. ** <dd>^This is the number of times that SQLite has stepped forward in
  8579. ** a table as part of a full table scan. Large numbers for this counter
  8580. ** may indicate opportunities for performance improvement through
  8581. ** careful use of indices.</dd>
  8582. **
  8583. ** [[SQLITE_STMTSTATUS_SORT]] <dt>SQLITE_STMTSTATUS_SORT</dt>
  8584. ** <dd>^This is the number of sort operations that have occurred.
  8585. ** A non-zero value in this counter may indicate an opportunity to
  8586. ** improvement performance through careful use of indices.</dd>
  8587. **
  8588. ** [[SQLITE_STMTSTATUS_AUTOINDEX]] <dt>SQLITE_STMTSTATUS_AUTOINDEX</dt>
  8589. ** <dd>^This is the number of rows inserted into transient indices that
  8590. ** were created automatically in order to help joins run faster.
  8591. ** A non-zero value in this counter may indicate an opportunity to
  8592. ** improvement performance by adding permanent indices that do not
  8593. ** need to be reinitialized each time the statement is run.</dd>
  8594. **
  8595. ** [[SQLITE_STMTSTATUS_VM_STEP]] <dt>SQLITE_STMTSTATUS_VM_STEP</dt>
  8596. ** <dd>^This is the number of virtual machine operations executed
  8597. ** by the prepared statement if that number is less than or equal
  8598. ** to 2147483647. The number of virtual machine operations can be
  8599. ** used as a proxy for the total work done by the prepared statement.
  8600. ** If the number of virtual machine operations exceeds 2147483647
  8601. ** then the value returned by this statement status code is undefined.
  8602. **
  8603. ** [[SQLITE_STMTSTATUS_REPREPARE]] <dt>SQLITE_STMTSTATUS_REPREPARE</dt>
  8604. ** <dd>^This is the number of times that the prepare statement has been
  8605. ** automatically regenerated due to schema changes or changes to
  8606. ** [bound parameters] that might affect the query plan.
  8607. **
  8608. ** [[SQLITE_STMTSTATUS_RUN]] <dt>SQLITE_STMTSTATUS_RUN</dt>
  8609. ** <dd>^This is the number of times that the prepared statement has
  8610. ** been run. A single "run" for the purposes of this counter is one
  8611. ** or more calls to [sqlite3_step()] followed by a call to [sqlite3_reset()].
  8612. ** The counter is incremented on the first [sqlite3_step()] call of each
  8613. ** cycle.
  8614. **
  8615. ** [[SQLITE_STMTSTATUS_FILTER_MISS]]
  8616. ** [[SQLITE_STMTSTATUS_FILTER HIT]]
  8617. ** <dt>SQLITE_STMTSTATUS_FILTER_HIT<br>
  8618. ** SQLITE_STMTSTATUS_FILTER_MISS</dt>
  8619. ** <dd>^SQLITE_STMTSTATUS_FILTER_HIT is the number of times that a join
  8620. ** step was bypassed because a Bloom filter returned not-found. The
  8621. ** corresponding SQLITE_STMTSTATUS_FILTER_MISS value is the number of
  8622. ** times that the Bloom filter returned a find, and thus the join step
  8623. ** had to be processed as normal.
  8624. **
  8625. ** [[SQLITE_STMTSTATUS_MEMUSED]] <dt>SQLITE_STMTSTATUS_MEMUSED</dt>
  8626. ** <dd>^This is the approximate number of bytes of heap memory
  8627. ** used to store the prepared statement. ^This value is not actually
  8628. ** a counter, and so the resetFlg parameter to sqlite3_stmt_status()
  8629. ** is ignored when the opcode is SQLITE_STMTSTATUS_MEMUSED.
  8630. ** </dd>
  8631. ** </dl>
  8632. */
  8633. #define SQLITE_STMTSTATUS_FULLSCAN_STEP 1
  8634. #define SQLITE_STMTSTATUS_SORT 2
  8635. #define SQLITE_STMTSTATUS_AUTOINDEX 3
  8636. #define SQLITE_STMTSTATUS_VM_STEP 4
  8637. #define SQLITE_STMTSTATUS_REPREPARE 5
  8638. #define SQLITE_STMTSTATUS_RUN 6
  8639. #define SQLITE_STMTSTATUS_FILTER_MISS 7
  8640. #define SQLITE_STMTSTATUS_FILTER_HIT 8
  8641. #define SQLITE_STMTSTATUS_MEMUSED 99
  8642. /*
  8643. ** CAPI3REF: Custom Page Cache Object
  8644. **
  8645. ** The sqlite3_pcache type is opaque. It is implemented by
  8646. ** the pluggable module. The SQLite core has no knowledge of
  8647. ** its size or internal structure and never deals with the
  8648. ** sqlite3_pcache object except by holding and passing pointers
  8649. ** to the object.
  8650. **
  8651. ** See [sqlite3_pcache_methods2] for additional information.
  8652. */
  8653. typedef struct sqlite3_pcache sqlite3_pcache;
  8654. /*
  8655. ** CAPI3REF: Custom Page Cache Object
  8656. **
  8657. ** The sqlite3_pcache_page object represents a single page in the
  8658. ** page cache. The page cache will allocate instances of this
  8659. ** object. Various methods of the page cache use pointers to instances
  8660. ** of this object as parameters or as their return value.
  8661. **
  8662. ** See [sqlite3_pcache_methods2] for additional information.
  8663. */
  8664. typedef struct sqlite3_pcache_page sqlite3_pcache_page;
  8665. struct sqlite3_pcache_page {
  8666. void *pBuf; /* The content of the page */
  8667. void *pExtra; /* Extra information associated with the page */
  8668. };
  8669. /*
  8670. ** CAPI3REF: Application Defined Page Cache.
  8671. ** KEYWORDS: {page cache}
  8672. **
  8673. ** ^(The [sqlite3_config]([SQLITE_CONFIG_PCACHE2], ...) interface can
  8674. ** register an alternative page cache implementation by passing in an
  8675. ** instance of the sqlite3_pcache_methods2 structure.)^
  8676. ** In many applications, most of the heap memory allocated by
  8677. ** SQLite is used for the page cache.
  8678. ** By implementing a
  8679. ** custom page cache using this API, an application can better control
  8680. ** the amount of memory consumed by SQLite, the way in which
  8681. ** that memory is allocated and released, and the policies used to
  8682. ** determine exactly which parts of a database file are cached and for
  8683. ** how long.
  8684. **
  8685. ** The alternative page cache mechanism is an
  8686. ** extreme measure that is only needed by the most demanding applications.
  8687. ** The built-in page cache is recommended for most uses.
  8688. **
  8689. ** ^(The contents of the sqlite3_pcache_methods2 structure are copied to an
  8690. ** internal buffer by SQLite within the call to [sqlite3_config]. Hence
  8691. ** the application may discard the parameter after the call to
  8692. ** [sqlite3_config()] returns.)^
  8693. **
  8694. ** [[the xInit() page cache method]]
  8695. ** ^(The xInit() method is called once for each effective
  8696. ** call to [sqlite3_initialize()])^
  8697. ** (usually only once during the lifetime of the process). ^(The xInit()
  8698. ** method is passed a copy of the sqlite3_pcache_methods2.pArg value.)^
  8699. ** The intent of the xInit() method is to set up global data structures
  8700. ** required by the custom page cache implementation.
  8701. ** ^(If the xInit() method is NULL, then the
  8702. ** built-in default page cache is used instead of the application defined
  8703. ** page cache.)^
  8704. **
  8705. ** [[the xShutdown() page cache method]]
  8706. ** ^The xShutdown() method is called by [sqlite3_shutdown()].
  8707. ** It can be used to clean up
  8708. ** any outstanding resources before process shutdown, if required.
  8709. ** ^The xShutdown() method may be NULL.
  8710. **
  8711. ** ^SQLite automatically serializes calls to the xInit method,
  8712. ** so the xInit method need not be threadsafe. ^The
  8713. ** xShutdown method is only called from [sqlite3_shutdown()] so it does
  8714. ** not need to be threadsafe either. All other methods must be threadsafe
  8715. ** in multithreaded applications.
  8716. **
  8717. ** ^SQLite will never invoke xInit() more than once without an intervening
  8718. ** call to xShutdown().
  8719. **
  8720. ** [[the xCreate() page cache methods]]
  8721. ** ^SQLite invokes the xCreate() method to construct a new cache instance.
  8722. ** SQLite will typically create one cache instance for each open database file,
  8723. ** though this is not guaranteed. ^The
  8724. ** first parameter, szPage, is the size in bytes of the pages that must
  8725. ** be allocated by the cache. ^szPage will always a power of two. ^The
  8726. ** second parameter szExtra is a number of bytes of extra storage
  8727. ** associated with each page cache entry. ^The szExtra parameter will
  8728. ** a number less than 250. SQLite will use the
  8729. ** extra szExtra bytes on each page to store metadata about the underlying
  8730. ** database page on disk. The value passed into szExtra depends
  8731. ** on the SQLite version, the target platform, and how SQLite was compiled.
  8732. ** ^The third argument to xCreate(), bPurgeable, is true if the cache being
  8733. ** created will be used to cache database pages of a file stored on disk, or
  8734. ** false if it is used for an in-memory database. The cache implementation
  8735. ** does not have to do anything special based with the value of bPurgeable;
  8736. ** it is purely advisory. ^On a cache where bPurgeable is false, SQLite will
  8737. ** never invoke xUnpin() except to deliberately delete a page.
  8738. ** ^In other words, calls to xUnpin() on a cache with bPurgeable set to
  8739. ** false will always have the "discard" flag set to true.
  8740. ** ^Hence, a cache created with bPurgeable false will
  8741. ** never contain any unpinned pages.
  8742. **
  8743. ** [[the xCachesize() page cache method]]
  8744. ** ^(The xCachesize() method may be called at any time by SQLite to set the
  8745. ** suggested maximum cache-size (number of pages stored by) the cache
  8746. ** instance passed as the first argument. This is the value configured using
  8747. ** the SQLite "[PRAGMA cache_size]" command.)^ As with the bPurgeable
  8748. ** parameter, the implementation is not required to do anything with this
  8749. ** value; it is advisory only.
  8750. **
  8751. ** [[the xPagecount() page cache methods]]
  8752. ** The xPagecount() method must return the number of pages currently
  8753. ** stored in the cache, both pinned and unpinned.
  8754. **
  8755. ** [[the xFetch() page cache methods]]
  8756. ** The xFetch() method locates a page in the cache and returns a pointer to
  8757. ** an sqlite3_pcache_page object associated with that page, or a NULL pointer.
  8758. ** The pBuf element of the returned sqlite3_pcache_page object will be a
  8759. ** pointer to a buffer of szPage bytes used to store the content of a
  8760. ** single database page. The pExtra element of sqlite3_pcache_page will be
  8761. ** a pointer to the szExtra bytes of extra storage that SQLite has requested
  8762. ** for each entry in the page cache.
  8763. **
  8764. ** The page to be fetched is determined by the key. ^The minimum key value
  8765. ** is 1. After it has been retrieved using xFetch, the page is considered
  8766. ** to be "pinned".
  8767. **
  8768. ** If the requested page is already in the page cache, then the page cache
  8769. ** implementation must return a pointer to the page buffer with its content
  8770. ** intact. If the requested page is not already in the cache, then the
  8771. ** cache implementation should use the value of the createFlag
  8772. ** parameter to help it determined what action to take:
  8773. **
  8774. ** <table border=1 width=85% align=center>
  8775. ** <tr><th> createFlag <th> Behavior when page is not already in cache
  8776. ** <tr><td> 0 <td> Do not allocate a new page. Return NULL.
  8777. ** <tr><td> 1 <td> Allocate a new page if it easy and convenient to do so.
  8778. ** Otherwise return NULL.
  8779. ** <tr><td> 2 <td> Make every effort to allocate a new page. Only return
  8780. ** NULL if allocating a new page is effectively impossible.
  8781. ** </table>
  8782. **
  8783. ** ^(SQLite will normally invoke xFetch() with a createFlag of 0 or 1. SQLite
  8784. ** will only use a createFlag of 2 after a prior call with a createFlag of 1
  8785. ** failed.)^ In between the xFetch() calls, SQLite may
  8786. ** attempt to unpin one or more cache pages by spilling the content of
  8787. ** pinned pages to disk and synching the operating system disk cache.
  8788. **
  8789. ** [[the xUnpin() page cache method]]
  8790. ** ^xUnpin() is called by SQLite with a pointer to a currently pinned page
  8791. ** as its second argument. If the third parameter, discard, is non-zero,
  8792. ** then the page must be evicted from the cache.
  8793. ** ^If the discard parameter is
  8794. ** zero, then the page may be discarded or retained at the discretion of
  8795. ** page cache implementation. ^The page cache implementation
  8796. ** may choose to evict unpinned pages at any time.
  8797. **
  8798. ** The cache must not perform any reference counting. A single
  8799. ** call to xUnpin() unpins the page regardless of the number of prior calls
  8800. ** to xFetch().
  8801. **
  8802. ** [[the xRekey() page cache methods]]
  8803. ** The xRekey() method is used to change the key value associated with the
  8804. ** page passed as the second argument. If the cache
  8805. ** previously contains an entry associated with newKey, it must be
  8806. ** discarded. ^Any prior cache entry associated with newKey is guaranteed not
  8807. ** to be pinned.
  8808. **
  8809. ** When SQLite calls the xTruncate() method, the cache must discard all
  8810. ** existing cache entries with page numbers (keys) greater than or equal
  8811. ** to the value of the iLimit parameter passed to xTruncate(). If any
  8812. ** of these pages are pinned, they are implicitly unpinned, meaning that
  8813. ** they can be safely discarded.
  8814. **
  8815. ** [[the xDestroy() page cache method]]
  8816. ** ^The xDestroy() method is used to delete a cache allocated by xCreate().
  8817. ** All resources associated with the specified cache should be freed. ^After
  8818. ** calling the xDestroy() method, SQLite considers the [sqlite3_pcache*]
  8819. ** handle invalid, and will not use it with any other sqlite3_pcache_methods2
  8820. ** functions.
  8821. **
  8822. ** [[the xShrink() page cache method]]
  8823. ** ^SQLite invokes the xShrink() method when it wants the page cache to
  8824. ** free up as much of heap memory as possible. The page cache implementation
  8825. ** is not obligated to free any memory, but well-behaved implementations should
  8826. ** do their best.
  8827. */
  8828. typedef struct sqlite3_pcache_methods2 sqlite3_pcache_methods2;
  8829. struct sqlite3_pcache_methods2 {
  8830. int iVersion;
  8831. void *pArg;
  8832. int (*xInit)(void*);
  8833. void (*xShutdown)(void*);
  8834. sqlite3_pcache *(*xCreate)(int szPage, int szExtra, int bPurgeable);
  8835. void (*xCachesize)(sqlite3_pcache*, int nCachesize);
  8836. int (*xPagecount)(sqlite3_pcache*);
  8837. sqlite3_pcache_page *(*xFetch)(sqlite3_pcache*, unsigned key, int createFlag);
  8838. void (*xUnpin)(sqlite3_pcache*, sqlite3_pcache_page*, int discard);
  8839. void (*xRekey)(sqlite3_pcache*, sqlite3_pcache_page*,
  8840. unsigned oldKey, unsigned newKey);
  8841. void (*xTruncate)(sqlite3_pcache*, unsigned iLimit);
  8842. void (*xDestroy)(sqlite3_pcache*);
  8843. void (*xShrink)(sqlite3_pcache*);
  8844. };
  8845. /*
  8846. ** This is the obsolete pcache_methods object that has now been replaced
  8847. ** by sqlite3_pcache_methods2. This object is not used by SQLite. It is
  8848. ** retained in the header file for backwards compatibility only.
  8849. */
  8850. typedef struct sqlite3_pcache_methods sqlite3_pcache_methods;
  8851. struct sqlite3_pcache_methods {
  8852. void *pArg;
  8853. int (*xInit)(void*);
  8854. void (*xShutdown)(void*);
  8855. sqlite3_pcache *(*xCreate)(int szPage, int bPurgeable);
  8856. void (*xCachesize)(sqlite3_pcache*, int nCachesize);
  8857. int (*xPagecount)(sqlite3_pcache*);
  8858. void *(*xFetch)(sqlite3_pcache*, unsigned key, int createFlag);
  8859. void (*xUnpin)(sqlite3_pcache*, void*, int discard);
  8860. void (*xRekey)(sqlite3_pcache*, void*, unsigned oldKey, unsigned newKey);
  8861. void (*xTruncate)(sqlite3_pcache*, unsigned iLimit);
  8862. void (*xDestroy)(sqlite3_pcache*);
  8863. };
  8864. /*
  8865. ** CAPI3REF: Online Backup Object
  8866. **
  8867. ** The sqlite3_backup object records state information about an ongoing
  8868. ** online backup operation. ^The sqlite3_backup object is created by
  8869. ** a call to [sqlite3_backup_init()] and is destroyed by a call to
  8870. ** [sqlite3_backup_finish()].
  8871. **
  8872. ** See Also: [Using the SQLite Online Backup API]
  8873. */
  8874. typedef struct sqlite3_backup sqlite3_backup;
  8875. /*
  8876. ** CAPI3REF: Online Backup API.
  8877. **
  8878. ** The backup API copies the content of one database into another.
  8879. ** It is useful either for creating backups of databases or
  8880. ** for copying in-memory databases to or from persistent files.
  8881. **
  8882. ** See Also: [Using the SQLite Online Backup API]
  8883. **
  8884. ** ^SQLite holds a write transaction open on the destination database file
  8885. ** for the duration of the backup operation.
  8886. ** ^The source database is read-locked only while it is being read;
  8887. ** it is not locked continuously for the entire backup operation.
  8888. ** ^Thus, the backup may be performed on a live source database without
  8889. ** preventing other database connections from
  8890. ** reading or writing to the source database while the backup is underway.
  8891. **
  8892. ** ^(To perform a backup operation:
  8893. ** <ol>
  8894. ** <li><b>sqlite3_backup_init()</b> is called once to initialize the
  8895. ** backup,
  8896. ** <li><b>sqlite3_backup_step()</b> is called one or more times to transfer
  8897. ** the data between the two databases, and finally
  8898. ** <li><b>sqlite3_backup_finish()</b> is called to release all resources
  8899. ** associated with the backup operation.
  8900. ** </ol>)^
  8901. ** There should be exactly one call to sqlite3_backup_finish() for each
  8902. ** successful call to sqlite3_backup_init().
  8903. **
  8904. ** [[sqlite3_backup_init()]] <b>sqlite3_backup_init()</b>
  8905. **
  8906. ** ^The D and N arguments to sqlite3_backup_init(D,N,S,M) are the
  8907. ** [database connection] associated with the destination database
  8908. ** and the database name, respectively.
  8909. ** ^The database name is "main" for the main database, "temp" for the
  8910. ** temporary database, or the name specified after the AS keyword in
  8911. ** an [ATTACH] statement for an attached database.
  8912. ** ^The S and M arguments passed to
  8913. ** sqlite3_backup_init(D,N,S,M) identify the [database connection]
  8914. ** and database name of the source database, respectively.
  8915. ** ^The source and destination [database connections] (parameters S and D)
  8916. ** must be different or else sqlite3_backup_init(D,N,S,M) will fail with
  8917. ** an error.
  8918. **
  8919. ** ^A call to sqlite3_backup_init() will fail, returning NULL, if
  8920. ** there is already a read or read-write transaction open on the
  8921. ** destination database.
  8922. **
  8923. ** ^If an error occurs within sqlite3_backup_init(D,N,S,M), then NULL is
  8924. ** returned and an error code and error message are stored in the
  8925. ** destination [database connection] D.
  8926. ** ^The error code and message for the failed call to sqlite3_backup_init()
  8927. ** can be retrieved using the [sqlite3_errcode()], [sqlite3_errmsg()], and/or
  8928. ** [sqlite3_errmsg16()] functions.
  8929. ** ^A successful call to sqlite3_backup_init() returns a pointer to an
  8930. ** [sqlite3_backup] object.
  8931. ** ^The [sqlite3_backup] object may be used with the sqlite3_backup_step() and
  8932. ** sqlite3_backup_finish() functions to perform the specified backup
  8933. ** operation.
  8934. **
  8935. ** [[sqlite3_backup_step()]] <b>sqlite3_backup_step()</b>
  8936. **
  8937. ** ^Function sqlite3_backup_step(B,N) will copy up to N pages between
  8938. ** the source and destination databases specified by [sqlite3_backup] object B.
  8939. ** ^If N is negative, all remaining source pages are copied.
  8940. ** ^If sqlite3_backup_step(B,N) successfully copies N pages and there
  8941. ** are still more pages to be copied, then the function returns [SQLITE_OK].
  8942. ** ^If sqlite3_backup_step(B,N) successfully finishes copying all pages
  8943. ** from source to destination, then it returns [SQLITE_DONE].
  8944. ** ^If an error occurs while running sqlite3_backup_step(B,N),
  8945. ** then an [error code] is returned. ^As well as [SQLITE_OK] and
  8946. ** [SQLITE_DONE], a call to sqlite3_backup_step() may return [SQLITE_READONLY],
  8947. ** [SQLITE_NOMEM], [SQLITE_BUSY], [SQLITE_LOCKED], or an
  8948. ** [SQLITE_IOERR_ACCESS | SQLITE_IOERR_XXX] extended error code.
  8949. **
  8950. ** ^(The sqlite3_backup_step() might return [SQLITE_READONLY] if
  8951. ** <ol>
  8952. ** <li> the destination database was opened read-only, or
  8953. ** <li> the destination database is using write-ahead-log journaling
  8954. ** and the destination and source page sizes differ, or
  8955. ** <li> the destination database is an in-memory database and the
  8956. ** destination and source page sizes differ.
  8957. ** </ol>)^
  8958. **
  8959. ** ^If sqlite3_backup_step() cannot obtain a required file-system lock, then
  8960. ** the [sqlite3_busy_handler | busy-handler function]
  8961. ** is invoked (if one is specified). ^If the
  8962. ** busy-handler returns non-zero before the lock is available, then
  8963. ** [SQLITE_BUSY] is returned to the caller. ^In this case the call to
  8964. ** sqlite3_backup_step() can be retried later. ^If the source
  8965. ** [database connection]
  8966. ** is being used to write to the source database when sqlite3_backup_step()
  8967. ** is called, then [SQLITE_LOCKED] is returned immediately. ^Again, in this
  8968. ** case the call to sqlite3_backup_step() can be retried later on. ^(If
  8969. ** [SQLITE_IOERR_ACCESS | SQLITE_IOERR_XXX], [SQLITE_NOMEM], or
  8970. ** [SQLITE_READONLY] is returned, then
  8971. ** there is no point in retrying the call to sqlite3_backup_step(). These
  8972. ** errors are considered fatal.)^ The application must accept
  8973. ** that the backup operation has failed and pass the backup operation handle
  8974. ** to the sqlite3_backup_finish() to release associated resources.
  8975. **
  8976. ** ^The first call to sqlite3_backup_step() obtains an exclusive lock
  8977. ** on the destination file. ^The exclusive lock is not released until either
  8978. ** sqlite3_backup_finish() is called or the backup operation is complete
  8979. ** and sqlite3_backup_step() returns [SQLITE_DONE]. ^Every call to
  8980. ** sqlite3_backup_step() obtains a [shared lock] on the source database that
  8981. ** lasts for the duration of the sqlite3_backup_step() call.
  8982. ** ^Because the source database is not locked between calls to
  8983. ** sqlite3_backup_step(), the source database may be modified mid-way
  8984. ** through the backup process. ^If the source database is modified by an
  8985. ** external process or via a database connection other than the one being
  8986. ** used by the backup operation, then the backup will be automatically
  8987. ** restarted by the next call to sqlite3_backup_step(). ^If the source
  8988. ** database is modified by the using the same database connection as is used
  8989. ** by the backup operation, then the backup database is automatically
  8990. ** updated at the same time.
  8991. **
  8992. ** [[sqlite3_backup_finish()]] <b>sqlite3_backup_finish()</b>
  8993. **
  8994. ** When sqlite3_backup_step() has returned [SQLITE_DONE], or when the
  8995. ** application wishes to abandon the backup operation, the application
  8996. ** should destroy the [sqlite3_backup] by passing it to sqlite3_backup_finish().
  8997. ** ^The sqlite3_backup_finish() interfaces releases all
  8998. ** resources associated with the [sqlite3_backup] object.
  8999. ** ^If sqlite3_backup_step() has not yet returned [SQLITE_DONE], then any
  9000. ** active write-transaction on the destination database is rolled back.
  9001. ** The [sqlite3_backup] object is invalid
  9002. ** and may not be used following a call to sqlite3_backup_finish().
  9003. **
  9004. ** ^The value returned by sqlite3_backup_finish is [SQLITE_OK] if no
  9005. ** sqlite3_backup_step() errors occurred, regardless or whether or not
  9006. ** sqlite3_backup_step() completed.
  9007. ** ^If an out-of-memory condition or IO error occurred during any prior
  9008. ** sqlite3_backup_step() call on the same [sqlite3_backup] object, then
  9009. ** sqlite3_backup_finish() returns the corresponding [error code].
  9010. **
  9011. ** ^A return of [SQLITE_BUSY] or [SQLITE_LOCKED] from sqlite3_backup_step()
  9012. ** is not a permanent error and does not affect the return value of
  9013. ** sqlite3_backup_finish().
  9014. **
  9015. ** [[sqlite3_backup_remaining()]] [[sqlite3_backup_pagecount()]]
  9016. ** <b>sqlite3_backup_remaining() and sqlite3_backup_pagecount()</b>
  9017. **
  9018. ** ^The sqlite3_backup_remaining() routine returns the number of pages still
  9019. ** to be backed up at the conclusion of the most recent sqlite3_backup_step().
  9020. ** ^The sqlite3_backup_pagecount() routine returns the total number of pages
  9021. ** in the source database at the conclusion of the most recent
  9022. ** sqlite3_backup_step().
  9023. ** ^(The values returned by these functions are only updated by
  9024. ** sqlite3_backup_step(). If the source database is modified in a way that
  9025. ** changes the size of the source database or the number of pages remaining,
  9026. ** those changes are not reflected in the output of sqlite3_backup_pagecount()
  9027. ** and sqlite3_backup_remaining() until after the next
  9028. ** sqlite3_backup_step().)^
  9029. **
  9030. ** <b>Concurrent Usage of Database Handles</b>
  9031. **
  9032. ** ^The source [database connection] may be used by the application for other
  9033. ** purposes while a backup operation is underway or being initialized.
  9034. ** ^If SQLite is compiled and configured to support threadsafe database
  9035. ** connections, then the source database connection may be used concurrently
  9036. ** from within other threads.
  9037. **
  9038. ** However, the application must guarantee that the destination
  9039. ** [database connection] is not passed to any other API (by any thread) after
  9040. ** sqlite3_backup_init() is called and before the corresponding call to
  9041. ** sqlite3_backup_finish(). SQLite does not currently check to see
  9042. ** if the application incorrectly accesses the destination [database connection]
  9043. ** and so no error code is reported, but the operations may malfunction
  9044. ** nevertheless. Use of the destination database connection while a
  9045. ** backup is in progress might also cause a mutex deadlock.
  9046. **
  9047. ** If running in [shared cache mode], the application must
  9048. ** guarantee that the shared cache used by the destination database
  9049. ** is not accessed while the backup is running. In practice this means
  9050. ** that the application must guarantee that the disk file being
  9051. ** backed up to is not accessed by any connection within the process,
  9052. ** not just the specific connection that was passed to sqlite3_backup_init().
  9053. **
  9054. ** The [sqlite3_backup] object itself is partially threadsafe. Multiple
  9055. ** threads may safely make multiple concurrent calls to sqlite3_backup_step().
  9056. ** However, the sqlite3_backup_remaining() and sqlite3_backup_pagecount()
  9057. ** APIs are not strictly speaking threadsafe. If they are invoked at the
  9058. ** same time as another thread is invoking sqlite3_backup_step() it is
  9059. ** possible that they return invalid values.
  9060. */
  9061. SQLITE_API sqlite3_backup *sqlite3_backup_init(
  9062. sqlite3 *pDest, /* Destination database handle */
  9063. const char *zDestName, /* Destination database name */
  9064. sqlite3 *pSource, /* Source database handle */
  9065. const char *zSourceName /* Source database name */
  9066. );
  9067. SQLITE_API int sqlite3_backup_step(sqlite3_backup *p, int nPage);
  9068. SQLITE_API int sqlite3_backup_finish(sqlite3_backup *p);
  9069. SQLITE_API int sqlite3_backup_remaining(sqlite3_backup *p);
  9070. SQLITE_API int sqlite3_backup_pagecount(sqlite3_backup *p);
  9071. /*
  9072. ** CAPI3REF: Unlock Notification
  9073. ** METHOD: sqlite3
  9074. **
  9075. ** ^When running in shared-cache mode, a database operation may fail with
  9076. ** an [SQLITE_LOCKED] error if the required locks on the shared-cache or
  9077. ** individual tables within the shared-cache cannot be obtained. See
  9078. ** [SQLite Shared-Cache Mode] for a description of shared-cache locking.
  9079. ** ^This API may be used to register a callback that SQLite will invoke
  9080. ** when the connection currently holding the required lock relinquishes it.
  9081. ** ^This API is only available if the library was compiled with the
  9082. ** [SQLITE_ENABLE_UNLOCK_NOTIFY] C-preprocessor symbol defined.
  9083. **
  9084. ** See Also: [Using the SQLite Unlock Notification Feature].
  9085. **
  9086. ** ^Shared-cache locks are released when a database connection concludes
  9087. ** its current transaction, either by committing it or rolling it back.
  9088. **
  9089. ** ^When a connection (known as the blocked connection) fails to obtain a
  9090. ** shared-cache lock and SQLITE_LOCKED is returned to the caller, the
  9091. ** identity of the database connection (the blocking connection) that
  9092. ** has locked the required resource is stored internally. ^After an
  9093. ** application receives an SQLITE_LOCKED error, it may call the
  9094. ** sqlite3_unlock_notify() method with the blocked connection handle as
  9095. ** the first argument to register for a callback that will be invoked
  9096. ** when the blocking connections current transaction is concluded. ^The
  9097. ** callback is invoked from within the [sqlite3_step] or [sqlite3_close]
  9098. ** call that concludes the blocking connection's transaction.
  9099. **
  9100. ** ^(If sqlite3_unlock_notify() is called in a multi-threaded application,
  9101. ** there is a chance that the blocking connection will have already
  9102. ** concluded its transaction by the time sqlite3_unlock_notify() is invoked.
  9103. ** If this happens, then the specified callback is invoked immediately,
  9104. ** from within the call to sqlite3_unlock_notify().)^
  9105. **
  9106. ** ^If the blocked connection is attempting to obtain a write-lock on a
  9107. ** shared-cache table, and more than one other connection currently holds
  9108. ** a read-lock on the same table, then SQLite arbitrarily selects one of
  9109. ** the other connections to use as the blocking connection.
  9110. **
  9111. ** ^(There may be at most one unlock-notify callback registered by a
  9112. ** blocked connection. If sqlite3_unlock_notify() is called when the
  9113. ** blocked connection already has a registered unlock-notify callback,
  9114. ** then the new callback replaces the old.)^ ^If sqlite3_unlock_notify() is
  9115. ** called with a NULL pointer as its second argument, then any existing
  9116. ** unlock-notify callback is canceled. ^The blocked connections
  9117. ** unlock-notify callback may also be canceled by closing the blocked
  9118. ** connection using [sqlite3_close()].
  9119. **
  9120. ** The unlock-notify callback is not reentrant. If an application invokes
  9121. ** any sqlite3_xxx API functions from within an unlock-notify callback, a
  9122. ** crash or deadlock may be the result.
  9123. **
  9124. ** ^Unless deadlock is detected (see below), sqlite3_unlock_notify() always
  9125. ** returns SQLITE_OK.
  9126. **
  9127. ** <b>Callback Invocation Details</b>
  9128. **
  9129. ** When an unlock-notify callback is registered, the application provides a
  9130. ** single void* pointer that is passed to the callback when it is invoked.
  9131. ** However, the signature of the callback function allows SQLite to pass
  9132. ** it an array of void* context pointers. The first argument passed to
  9133. ** an unlock-notify callback is a pointer to an array of void* pointers,
  9134. ** and the second is the number of entries in the array.
  9135. **
  9136. ** When a blocking connection's transaction is concluded, there may be
  9137. ** more than one blocked connection that has registered for an unlock-notify
  9138. ** callback. ^If two or more such blocked connections have specified the
  9139. ** same callback function, then instead of invoking the callback function
  9140. ** multiple times, it is invoked once with the set of void* context pointers
  9141. ** specified by the blocked connections bundled together into an array.
  9142. ** This gives the application an opportunity to prioritize any actions
  9143. ** related to the set of unblocked database connections.
  9144. **
  9145. ** <b>Deadlock Detection</b>
  9146. **
  9147. ** Assuming that after registering for an unlock-notify callback a
  9148. ** database waits for the callback to be issued before taking any further
  9149. ** action (a reasonable assumption), then using this API may cause the
  9150. ** application to deadlock. For example, if connection X is waiting for
  9151. ** connection Y's transaction to be concluded, and similarly connection
  9152. ** Y is waiting on connection X's transaction, then neither connection
  9153. ** will proceed and the system may remain deadlocked indefinitely.
  9154. **
  9155. ** To avoid this scenario, the sqlite3_unlock_notify() performs deadlock
  9156. ** detection. ^If a given call to sqlite3_unlock_notify() would put the
  9157. ** system in a deadlocked state, then SQLITE_LOCKED is returned and no
  9158. ** unlock-notify callback is registered. The system is said to be in
  9159. ** a deadlocked state if connection A has registered for an unlock-notify
  9160. ** callback on the conclusion of connection B's transaction, and connection
  9161. ** B has itself registered for an unlock-notify callback when connection
  9162. ** A's transaction is concluded. ^Indirect deadlock is also detected, so
  9163. ** the system is also considered to be deadlocked if connection B has
  9164. ** registered for an unlock-notify callback on the conclusion of connection
  9165. ** C's transaction, where connection C is waiting on connection A. ^Any
  9166. ** number of levels of indirection are allowed.
  9167. **
  9168. ** <b>The "DROP TABLE" Exception</b>
  9169. **
  9170. ** When a call to [sqlite3_step()] returns SQLITE_LOCKED, it is almost
  9171. ** always appropriate to call sqlite3_unlock_notify(). There is however,
  9172. ** one exception. When executing a "DROP TABLE" or "DROP INDEX" statement,
  9173. ** SQLite checks if there are any currently executing SELECT statements
  9174. ** that belong to the same connection. If there are, SQLITE_LOCKED is
  9175. ** returned. In this case there is no "blocking connection", so invoking
  9176. ** sqlite3_unlock_notify() results in the unlock-notify callback being
  9177. ** invoked immediately. If the application then re-attempts the "DROP TABLE"
  9178. ** or "DROP INDEX" query, an infinite loop might be the result.
  9179. **
  9180. ** One way around this problem is to check the extended error code returned
  9181. ** by an sqlite3_step() call. ^(If there is a blocking connection, then the
  9182. ** extended error code is set to SQLITE_LOCKED_SHAREDCACHE. Otherwise, in
  9183. ** the special "DROP TABLE/INDEX" case, the extended error code is just
  9184. ** SQLITE_LOCKED.)^
  9185. */
  9186. SQLITE_API int sqlite3_unlock_notify(
  9187. sqlite3 *pBlocked, /* Waiting connection */
  9188. void (*xNotify)(void **apArg, int nArg), /* Callback function to invoke */
  9189. void *pNotifyArg /* Argument to pass to xNotify */
  9190. );
  9191. /*
  9192. ** CAPI3REF: String Comparison
  9193. **
  9194. ** ^The [sqlite3_stricmp()] and [sqlite3_strnicmp()] APIs allow applications
  9195. ** and extensions to compare the contents of two buffers containing UTF-8
  9196. ** strings in a case-independent fashion, using the same definition of "case
  9197. ** independence" that SQLite uses internally when comparing identifiers.
  9198. */
  9199. SQLITE_API int sqlite3_stricmp(const char *, const char *);
  9200. SQLITE_API int sqlite3_strnicmp(const char *, const char *, int);
  9201. /*
  9202. ** CAPI3REF: String Globbing
  9203. *
  9204. ** ^The [sqlite3_strglob(P,X)] interface returns zero if and only if
  9205. ** string X matches the [GLOB] pattern P.
  9206. ** ^The definition of [GLOB] pattern matching used in
  9207. ** [sqlite3_strglob(P,X)] is the same as for the "X GLOB P" operator in the
  9208. ** SQL dialect understood by SQLite. ^The [sqlite3_strglob(P,X)] function
  9209. ** is case sensitive.
  9210. **
  9211. ** Note that this routine returns zero on a match and non-zero if the strings
  9212. ** do not match, the same as [sqlite3_stricmp()] and [sqlite3_strnicmp()].
  9213. **
  9214. ** See also: [sqlite3_strlike()].
  9215. */
  9216. SQLITE_API int sqlite3_strglob(const char *zGlob, const char *zStr);
  9217. /*
  9218. ** CAPI3REF: String LIKE Matching
  9219. *
  9220. ** ^The [sqlite3_strlike(P,X,E)] interface returns zero if and only if
  9221. ** string X matches the [LIKE] pattern P with escape character E.
  9222. ** ^The definition of [LIKE] pattern matching used in
  9223. ** [sqlite3_strlike(P,X,E)] is the same as for the "X LIKE P ESCAPE E"
  9224. ** operator in the SQL dialect understood by SQLite. ^For "X LIKE P" without
  9225. ** the ESCAPE clause, set the E parameter of [sqlite3_strlike(P,X,E)] to 0.
  9226. ** ^As with the LIKE operator, the [sqlite3_strlike(P,X,E)] function is case
  9227. ** insensitive - equivalent upper and lower case ASCII characters match
  9228. ** one another.
  9229. **
  9230. ** ^The [sqlite3_strlike(P,X,E)] function matches Unicode characters, though
  9231. ** only ASCII characters are case folded.
  9232. **
  9233. ** Note that this routine returns zero on a match and non-zero if the strings
  9234. ** do not match, the same as [sqlite3_stricmp()] and [sqlite3_strnicmp()].
  9235. **
  9236. ** See also: [sqlite3_strglob()].
  9237. */
  9238. SQLITE_API int sqlite3_strlike(const char *zGlob, const char *zStr, unsigned int cEsc);
  9239. /*
  9240. ** CAPI3REF: Error Logging Interface
  9241. **
  9242. ** ^The [sqlite3_log()] interface writes a message into the [error log]
  9243. ** established by the [SQLITE_CONFIG_LOG] option to [sqlite3_config()].
  9244. ** ^If logging is enabled, the zFormat string and subsequent arguments are
  9245. ** used with [sqlite3_snprintf()] to generate the final output string.
  9246. **
  9247. ** The sqlite3_log() interface is intended for use by extensions such as
  9248. ** virtual tables, collating functions, and SQL functions. While there is
  9249. ** nothing to prevent an application from calling sqlite3_log(), doing so
  9250. ** is considered bad form.
  9251. **
  9252. ** The zFormat string must not be NULL.
  9253. **
  9254. ** To avoid deadlocks and other threading problems, the sqlite3_log() routine
  9255. ** will not use dynamically allocated memory. The log message is stored in
  9256. ** a fixed-length buffer on the stack. If the log message is longer than
  9257. ** a few hundred characters, it will be truncated to the length of the
  9258. ** buffer.
  9259. */
  9260. SQLITE_API void sqlite3_log(int iErrCode, const char *zFormat, ...);
  9261. /*
  9262. ** CAPI3REF: Write-Ahead Log Commit Hook
  9263. ** METHOD: sqlite3
  9264. **
  9265. ** ^The [sqlite3_wal_hook()] function is used to register a callback that
  9266. ** is invoked each time data is committed to a database in wal mode.
  9267. **
  9268. ** ^(The callback is invoked by SQLite after the commit has taken place and
  9269. ** the associated write-lock on the database released)^, so the implementation
  9270. ** may read, write or [checkpoint] the database as required.
  9271. **
  9272. ** ^The first parameter passed to the callback function when it is invoked
  9273. ** is a copy of the third parameter passed to sqlite3_wal_hook() when
  9274. ** registering the callback. ^The second is a copy of the database handle.
  9275. ** ^The third parameter is the name of the database that was written to -
  9276. ** either "main" or the name of an [ATTACH]-ed database. ^The fourth parameter
  9277. ** is the number of pages currently in the write-ahead log file,
  9278. ** including those that were just committed.
  9279. **
  9280. ** The callback function should normally return [SQLITE_OK]. ^If an error
  9281. ** code is returned, that error will propagate back up through the
  9282. ** SQLite code base to cause the statement that provoked the callback
  9283. ** to report an error, though the commit will have still occurred. If the
  9284. ** callback returns [SQLITE_ROW] or [SQLITE_DONE], or if it returns a value
  9285. ** that does not correspond to any valid SQLite error code, the results
  9286. ** are undefined.
  9287. **
  9288. ** A single database handle may have at most a single write-ahead log callback
  9289. ** registered at one time. ^Calling [sqlite3_wal_hook()] replaces any
  9290. ** previously registered write-ahead log callback. ^The return value is
  9291. ** a copy of the third parameter from the previous call, if any, or 0.
  9292. ** ^Note that the [sqlite3_wal_autocheckpoint()] interface and the
  9293. ** [wal_autocheckpoint pragma] both invoke [sqlite3_wal_hook()] and will
  9294. ** overwrite any prior [sqlite3_wal_hook()] settings.
  9295. */
  9296. SQLITE_API void *sqlite3_wal_hook(
  9297. sqlite3*,
  9298. int(*)(void *,sqlite3*,const char*,int),
  9299. void*
  9300. );
  9301. /*
  9302. ** CAPI3REF: Configure an auto-checkpoint
  9303. ** METHOD: sqlite3
  9304. **
  9305. ** ^The [sqlite3_wal_autocheckpoint(D,N)] is a wrapper around
  9306. ** [sqlite3_wal_hook()] that causes any database on [database connection] D
  9307. ** to automatically [checkpoint]
  9308. ** after committing a transaction if there are N or
  9309. ** more frames in the [write-ahead log] file. ^Passing zero or
  9310. ** a negative value as the nFrame parameter disables automatic
  9311. ** checkpoints entirely.
  9312. **
  9313. ** ^The callback registered by this function replaces any existing callback
  9314. ** registered using [sqlite3_wal_hook()]. ^Likewise, registering a callback
  9315. ** using [sqlite3_wal_hook()] disables the automatic checkpoint mechanism
  9316. ** configured by this function.
  9317. **
  9318. ** ^The [wal_autocheckpoint pragma] can be used to invoke this interface
  9319. ** from SQL.
  9320. **
  9321. ** ^Checkpoints initiated by this mechanism are
  9322. ** [sqlite3_wal_checkpoint_v2|PASSIVE].
  9323. **
  9324. ** ^Every new [database connection] defaults to having the auto-checkpoint
  9325. ** enabled with a threshold of 1000 or [SQLITE_DEFAULT_WAL_AUTOCHECKPOINT]
  9326. ** pages. The use of this interface
  9327. ** is only necessary if the default setting is found to be suboptimal
  9328. ** for a particular application.
  9329. */
  9330. SQLITE_API int sqlite3_wal_autocheckpoint(sqlite3 *db, int N);
  9331. /*
  9332. ** CAPI3REF: Checkpoint a database
  9333. ** METHOD: sqlite3
  9334. **
  9335. ** ^(The sqlite3_wal_checkpoint(D,X) is equivalent to
  9336. ** [sqlite3_wal_checkpoint_v2](D,X,[SQLITE_CHECKPOINT_PASSIVE],0,0).)^
  9337. **
  9338. ** In brief, sqlite3_wal_checkpoint(D,X) causes the content in the
  9339. ** [write-ahead log] for database X on [database connection] D to be
  9340. ** transferred into the database file and for the write-ahead log to
  9341. ** be reset. See the [checkpointing] documentation for addition
  9342. ** information.
  9343. **
  9344. ** This interface used to be the only way to cause a checkpoint to
  9345. ** occur. But then the newer and more powerful [sqlite3_wal_checkpoint_v2()]
  9346. ** interface was added. This interface is retained for backwards
  9347. ** compatibility and as a convenience for applications that need to manually
  9348. ** start a callback but which do not need the full power (and corresponding
  9349. ** complication) of [sqlite3_wal_checkpoint_v2()].
  9350. */
  9351. SQLITE_API int sqlite3_wal_checkpoint(sqlite3 *db, const char *zDb);
  9352. /*
  9353. ** CAPI3REF: Checkpoint a database
  9354. ** METHOD: sqlite3
  9355. **
  9356. ** ^(The sqlite3_wal_checkpoint_v2(D,X,M,L,C) interface runs a checkpoint
  9357. ** operation on database X of [database connection] D in mode M. Status
  9358. ** information is written back into integers pointed to by L and C.)^
  9359. ** ^(The M parameter must be a valid [checkpoint mode]:)^
  9360. **
  9361. ** <dl>
  9362. ** <dt>SQLITE_CHECKPOINT_PASSIVE<dd>
  9363. ** ^Checkpoint as many frames as possible without waiting for any database
  9364. ** readers or writers to finish, then sync the database file if all frames
  9365. ** in the log were checkpointed. ^The [busy-handler callback]
  9366. ** is never invoked in the SQLITE_CHECKPOINT_PASSIVE mode.
  9367. ** ^On the other hand, passive mode might leave the checkpoint unfinished
  9368. ** if there are concurrent readers or writers.
  9369. **
  9370. ** <dt>SQLITE_CHECKPOINT_FULL<dd>
  9371. ** ^This mode blocks (it invokes the
  9372. ** [sqlite3_busy_handler|busy-handler callback]) until there is no
  9373. ** database writer and all readers are reading from the most recent database
  9374. ** snapshot. ^It then checkpoints all frames in the log file and syncs the
  9375. ** database file. ^This mode blocks new database writers while it is pending,
  9376. ** but new database readers are allowed to continue unimpeded.
  9377. **
  9378. ** <dt>SQLITE_CHECKPOINT_RESTART<dd>
  9379. ** ^This mode works the same way as SQLITE_CHECKPOINT_FULL with the addition
  9380. ** that after checkpointing the log file it blocks (calls the
  9381. ** [busy-handler callback])
  9382. ** until all readers are reading from the database file only. ^This ensures
  9383. ** that the next writer will restart the log file from the beginning.
  9384. ** ^Like SQLITE_CHECKPOINT_FULL, this mode blocks new
  9385. ** database writer attempts while it is pending, but does not impede readers.
  9386. **
  9387. ** <dt>SQLITE_CHECKPOINT_TRUNCATE<dd>
  9388. ** ^This mode works the same way as SQLITE_CHECKPOINT_RESTART with the
  9389. ** addition that it also truncates the log file to zero bytes just prior
  9390. ** to a successful return.
  9391. ** </dl>
  9392. **
  9393. ** ^If pnLog is not NULL, then *pnLog is set to the total number of frames in
  9394. ** the log file or to -1 if the checkpoint could not run because
  9395. ** of an error or because the database is not in [WAL mode]. ^If pnCkpt is not
  9396. ** NULL,then *pnCkpt is set to the total number of checkpointed frames in the
  9397. ** log file (including any that were already checkpointed before the function
  9398. ** was called) or to -1 if the checkpoint could not run due to an error or
  9399. ** because the database is not in WAL mode. ^Note that upon successful
  9400. ** completion of an SQLITE_CHECKPOINT_TRUNCATE, the log file will have been
  9401. ** truncated to zero bytes and so both *pnLog and *pnCkpt will be set to zero.
  9402. **
  9403. ** ^All calls obtain an exclusive "checkpoint" lock on the database file. ^If
  9404. ** any other process is running a checkpoint operation at the same time, the
  9405. ** lock cannot be obtained and SQLITE_BUSY is returned. ^Even if there is a
  9406. ** busy-handler configured, it will not be invoked in this case.
  9407. **
  9408. ** ^The SQLITE_CHECKPOINT_FULL, RESTART and TRUNCATE modes also obtain the
  9409. ** exclusive "writer" lock on the database file. ^If the writer lock cannot be
  9410. ** obtained immediately, and a busy-handler is configured, it is invoked and
  9411. ** the writer lock retried until either the busy-handler returns 0 or the lock
  9412. ** is successfully obtained. ^The busy-handler is also invoked while waiting for
  9413. ** database readers as described above. ^If the busy-handler returns 0 before
  9414. ** the writer lock is obtained or while waiting for database readers, the
  9415. ** checkpoint operation proceeds from that point in the same way as
  9416. ** SQLITE_CHECKPOINT_PASSIVE - checkpointing as many frames as possible
  9417. ** without blocking any further. ^SQLITE_BUSY is returned in this case.
  9418. **
  9419. ** ^If parameter zDb is NULL or points to a zero length string, then the
  9420. ** specified operation is attempted on all WAL databases [attached] to
  9421. ** [database connection] db. In this case the
  9422. ** values written to output parameters *pnLog and *pnCkpt are undefined. ^If
  9423. ** an SQLITE_BUSY error is encountered when processing one or more of the
  9424. ** attached WAL databases, the operation is still attempted on any remaining
  9425. ** attached databases and SQLITE_BUSY is returned at the end. ^If any other
  9426. ** error occurs while processing an attached database, processing is abandoned
  9427. ** and the error code is returned to the caller immediately. ^If no error
  9428. ** (SQLITE_BUSY or otherwise) is encountered while processing the attached
  9429. ** databases, SQLITE_OK is returned.
  9430. **
  9431. ** ^If database zDb is the name of an attached database that is not in WAL
  9432. ** mode, SQLITE_OK is returned and both *pnLog and *pnCkpt set to -1. ^If
  9433. ** zDb is not NULL (or a zero length string) and is not the name of any
  9434. ** attached database, SQLITE_ERROR is returned to the caller.
  9435. **
  9436. ** ^Unless it returns SQLITE_MISUSE,
  9437. ** the sqlite3_wal_checkpoint_v2() interface
  9438. ** sets the error information that is queried by
  9439. ** [sqlite3_errcode()] and [sqlite3_errmsg()].
  9440. **
  9441. ** ^The [PRAGMA wal_checkpoint] command can be used to invoke this interface
  9442. ** from SQL.
  9443. */
  9444. SQLITE_API int sqlite3_wal_checkpoint_v2(
  9445. sqlite3 *db, /* Database handle */
  9446. const char *zDb, /* Name of attached database (or NULL) */
  9447. int eMode, /* SQLITE_CHECKPOINT_* value */
  9448. int *pnLog, /* OUT: Size of WAL log in frames */
  9449. int *pnCkpt /* OUT: Total number of frames checkpointed */
  9450. );
  9451. /*
  9452. ** CAPI3REF: Checkpoint Mode Values
  9453. ** KEYWORDS: {checkpoint mode}
  9454. **
  9455. ** These constants define all valid values for the "checkpoint mode" passed
  9456. ** as the third parameter to the [sqlite3_wal_checkpoint_v2()] interface.
  9457. ** See the [sqlite3_wal_checkpoint_v2()] documentation for details on the
  9458. ** meaning of each of these checkpoint modes.
  9459. */
  9460. #define SQLITE_CHECKPOINT_PASSIVE 0 /* Do as much as possible w/o blocking */
  9461. #define SQLITE_CHECKPOINT_FULL 1 /* Wait for writers, then checkpoint */
  9462. #define SQLITE_CHECKPOINT_RESTART 2 /* Like FULL but wait for readers */
  9463. #define SQLITE_CHECKPOINT_TRUNCATE 3 /* Like RESTART but also truncate WAL */
  9464. /*
  9465. ** CAPI3REF: Virtual Table Interface Configuration
  9466. **
  9467. ** This function may be called by either the [xConnect] or [xCreate] method
  9468. ** of a [virtual table] implementation to configure
  9469. ** various facets of the virtual table interface.
  9470. **
  9471. ** If this interface is invoked outside the context of an xConnect or
  9472. ** xCreate virtual table method then the behavior is undefined.
  9473. **
  9474. ** In the call sqlite3_vtab_config(D,C,...) the D parameter is the
  9475. ** [database connection] in which the virtual table is being created and
  9476. ** which is passed in as the first argument to the [xConnect] or [xCreate]
  9477. ** method that is invoking sqlite3_vtab_config(). The C parameter is one
  9478. ** of the [virtual table configuration options]. The presence and meaning
  9479. ** of parameters after C depend on which [virtual table configuration option]
  9480. ** is used.
  9481. */
  9482. SQLITE_API int sqlite3_vtab_config(sqlite3*, int op, ...);
  9483. /*
  9484. ** CAPI3REF: Virtual Table Configuration Options
  9485. ** KEYWORDS: {virtual table configuration options}
  9486. ** KEYWORDS: {virtual table configuration option}
  9487. **
  9488. ** These macros define the various options to the
  9489. ** [sqlite3_vtab_config()] interface that [virtual table] implementations
  9490. ** can use to customize and optimize their behavior.
  9491. **
  9492. ** <dl>
  9493. ** [[SQLITE_VTAB_CONSTRAINT_SUPPORT]]
  9494. ** <dt>SQLITE_VTAB_CONSTRAINT_SUPPORT</dt>
  9495. ** <dd>Calls of the form
  9496. ** [sqlite3_vtab_config](db,SQLITE_VTAB_CONSTRAINT_SUPPORT,X) are supported,
  9497. ** where X is an integer. If X is zero, then the [virtual table] whose
  9498. ** [xCreate] or [xConnect] method invoked [sqlite3_vtab_config()] does not
  9499. ** support constraints. In this configuration (which is the default) if
  9500. ** a call to the [xUpdate] method returns [SQLITE_CONSTRAINT], then the entire
  9501. ** statement is rolled back as if [ON CONFLICT | OR ABORT] had been
  9502. ** specified as part of the users SQL statement, regardless of the actual
  9503. ** ON CONFLICT mode specified.
  9504. **
  9505. ** If X is non-zero, then the virtual table implementation guarantees
  9506. ** that if [xUpdate] returns [SQLITE_CONSTRAINT], it will do so before
  9507. ** any modifications to internal or persistent data structures have been made.
  9508. ** If the [ON CONFLICT] mode is ABORT, FAIL, IGNORE or ROLLBACK, SQLite
  9509. ** is able to roll back a statement or database transaction, and abandon
  9510. ** or continue processing the current SQL statement as appropriate.
  9511. ** If the ON CONFLICT mode is REPLACE and the [xUpdate] method returns
  9512. ** [SQLITE_CONSTRAINT], SQLite handles this as if the ON CONFLICT mode
  9513. ** had been ABORT.
  9514. **
  9515. ** Virtual table implementations that are required to handle OR REPLACE
  9516. ** must do so within the [xUpdate] method. If a call to the
  9517. ** [sqlite3_vtab_on_conflict()] function indicates that the current ON
  9518. ** CONFLICT policy is REPLACE, the virtual table implementation should
  9519. ** silently replace the appropriate rows within the xUpdate callback and
  9520. ** return SQLITE_OK. Or, if this is not possible, it may return
  9521. ** SQLITE_CONSTRAINT, in which case SQLite falls back to OR ABORT
  9522. ** constraint handling.
  9523. ** </dd>
  9524. **
  9525. ** [[SQLITE_VTAB_DIRECTONLY]]<dt>SQLITE_VTAB_DIRECTONLY</dt>
  9526. ** <dd>Calls of the form
  9527. ** [sqlite3_vtab_config](db,SQLITE_VTAB_DIRECTONLY) from within the
  9528. ** the [xConnect] or [xCreate] methods of a [virtual table] implementation
  9529. ** prohibits that virtual table from being used from within triggers and
  9530. ** views.
  9531. ** </dd>
  9532. **
  9533. ** [[SQLITE_VTAB_INNOCUOUS]]<dt>SQLITE_VTAB_INNOCUOUS</dt>
  9534. ** <dd>Calls of the form
  9535. ** [sqlite3_vtab_config](db,SQLITE_VTAB_INNOCUOUS) from within the
  9536. ** the [xConnect] or [xCreate] methods of a [virtual table] implementation
  9537. ** identify that virtual table as being safe to use from within triggers
  9538. ** and views. Conceptually, the SQLITE_VTAB_INNOCUOUS tag means that the
  9539. ** virtual table can do no serious harm even if it is controlled by a
  9540. ** malicious hacker. Developers should avoid setting the SQLITE_VTAB_INNOCUOUS
  9541. ** flag unless absolutely necessary.
  9542. ** </dd>
  9543. **
  9544. ** [[SQLITE_VTAB_USES_ALL_SCHEMAS]]<dt>SQLITE_VTAB_USES_ALL_SCHEMAS</dt>
  9545. ** <dd>Calls of the form
  9546. ** [sqlite3_vtab_config](db,SQLITE_VTAB_USES_ALL_SCHEMA) from within the
  9547. ** the [xConnect] or [xCreate] methods of a [virtual table] implementation
  9548. ** instruct the query planner to begin at least a read transaction on
  9549. ** all schemas ("main", "temp", and any ATTACH-ed databases) whenever the
  9550. ** virtual table is used.
  9551. ** </dd>
  9552. ** </dl>
  9553. */
  9554. #define SQLITE_VTAB_CONSTRAINT_SUPPORT 1
  9555. #define SQLITE_VTAB_INNOCUOUS 2
  9556. #define SQLITE_VTAB_DIRECTONLY 3
  9557. #define SQLITE_VTAB_USES_ALL_SCHEMAS 4
  9558. /*
  9559. ** CAPI3REF: Determine The Virtual Table Conflict Policy
  9560. **
  9561. ** This function may only be called from within a call to the [xUpdate] method
  9562. ** of a [virtual table] implementation for an INSERT or UPDATE operation. ^The
  9563. ** value returned is one of [SQLITE_ROLLBACK], [SQLITE_IGNORE], [SQLITE_FAIL],
  9564. ** [SQLITE_ABORT], or [SQLITE_REPLACE], according to the [ON CONFLICT] mode
  9565. ** of the SQL statement that triggered the call to the [xUpdate] method of the
  9566. ** [virtual table].
  9567. */
  9568. SQLITE_API int sqlite3_vtab_on_conflict(sqlite3 *);
  9569. /*
  9570. ** CAPI3REF: Determine If Virtual Table Column Access Is For UPDATE
  9571. **
  9572. ** If the sqlite3_vtab_nochange(X) routine is called within the [xColumn]
  9573. ** method of a [virtual table], then it might return true if the
  9574. ** column is being fetched as part of an UPDATE operation during which the
  9575. ** column value will not change. The virtual table implementation can use
  9576. ** this hint as permission to substitute a return value that is less
  9577. ** expensive to compute and that the corresponding
  9578. ** [xUpdate] method understands as a "no-change" value.
  9579. **
  9580. ** If the [xColumn] method calls sqlite3_vtab_nochange() and finds that
  9581. ** the column is not changed by the UPDATE statement, then the xColumn
  9582. ** method can optionally return without setting a result, without calling
  9583. ** any of the [sqlite3_result_int|sqlite3_result_xxxxx() interfaces].
  9584. ** In that case, [sqlite3_value_nochange(X)] will return true for the
  9585. ** same column in the [xUpdate] method.
  9586. **
  9587. ** The sqlite3_vtab_nochange() routine is an optimization. Virtual table
  9588. ** implementations should continue to give a correct answer even if the
  9589. ** sqlite3_vtab_nochange() interface were to always return false. In the
  9590. ** current implementation, the sqlite3_vtab_nochange() interface does always
  9591. ** returns false for the enhanced [UPDATE FROM] statement.
  9592. */
  9593. SQLITE_API int sqlite3_vtab_nochange(sqlite3_context*);
  9594. /*
  9595. ** CAPI3REF: Determine The Collation For a Virtual Table Constraint
  9596. ** METHOD: sqlite3_index_info
  9597. **
  9598. ** This function may only be called from within a call to the [xBestIndex]
  9599. ** method of a [virtual table]. This function returns a pointer to a string
  9600. ** that is the name of the appropriate collation sequence to use for text
  9601. ** comparisons on the constraint identified by its arguments.
  9602. **
  9603. ** The first argument must be the pointer to the [sqlite3_index_info] object
  9604. ** that is the first parameter to the xBestIndex() method. The second argument
  9605. ** must be an index into the aConstraint[] array belonging to the
  9606. ** sqlite3_index_info structure passed to xBestIndex.
  9607. **
  9608. ** Important:
  9609. ** The first parameter must be the same pointer that is passed into the
  9610. ** xBestMethod() method. The first parameter may not be a pointer to a
  9611. ** different [sqlite3_index_info] object, even an exact copy.
  9612. **
  9613. ** The return value is computed as follows:
  9614. **
  9615. ** <ol>
  9616. ** <li><p> If the constraint comes from a WHERE clause expression that contains
  9617. ** a [COLLATE operator], then the name of the collation specified by
  9618. ** that COLLATE operator is returned.
  9619. ** <li><p> If there is no COLLATE operator, but the column that is the subject
  9620. ** of the constraint specifies an alternative collating sequence via
  9621. ** a [COLLATE clause] on the column definition within the CREATE TABLE
  9622. ** statement that was passed into [sqlite3_declare_vtab()], then the
  9623. ** name of that alternative collating sequence is returned.
  9624. ** <li><p> Otherwise, "BINARY" is returned.
  9625. ** </ol>
  9626. */
  9627. SQLITE_API const char *sqlite3_vtab_collation(sqlite3_index_info*,int);
  9628. /*
  9629. ** CAPI3REF: Determine if a virtual table query is DISTINCT
  9630. ** METHOD: sqlite3_index_info
  9631. **
  9632. ** This API may only be used from within an [xBestIndex|xBestIndex method]
  9633. ** of a [virtual table] implementation. The result of calling this
  9634. ** interface from outside of xBestIndex() is undefined and probably harmful.
  9635. **
  9636. ** ^The sqlite3_vtab_distinct() interface returns an integer between 0 and
  9637. ** 3. The integer returned by sqlite3_vtab_distinct()
  9638. ** gives the virtual table additional information about how the query
  9639. ** planner wants the output to be ordered. As long as the virtual table
  9640. ** can meet the ordering requirements of the query planner, it may set
  9641. ** the "orderByConsumed" flag.
  9642. **
  9643. ** <ol><li value="0"><p>
  9644. ** ^If the sqlite3_vtab_distinct() interface returns 0, that means
  9645. ** that the query planner needs the virtual table to return all rows in the
  9646. ** sort order defined by the "nOrderBy" and "aOrderBy" fields of the
  9647. ** [sqlite3_index_info] object. This is the default expectation. If the
  9648. ** virtual table outputs all rows in sorted order, then it is always safe for
  9649. ** the xBestIndex method to set the "orderByConsumed" flag, regardless of
  9650. ** the return value from sqlite3_vtab_distinct().
  9651. ** <li value="1"><p>
  9652. ** ^(If the sqlite3_vtab_distinct() interface returns 1, that means
  9653. ** that the query planner does not need the rows to be returned in sorted order
  9654. ** as long as all rows with the same values in all columns identified by the
  9655. ** "aOrderBy" field are adjacent.)^ This mode is used when the query planner
  9656. ** is doing a GROUP BY.
  9657. ** <li value="2"><p>
  9658. ** ^(If the sqlite3_vtab_distinct() interface returns 2, that means
  9659. ** that the query planner does not need the rows returned in any particular
  9660. ** order, as long as rows with the same values in all "aOrderBy" columns
  9661. ** are adjacent.)^ ^(Furthermore, only a single row for each particular
  9662. ** combination of values in the columns identified by the "aOrderBy" field
  9663. ** needs to be returned.)^ ^It is always ok for two or more rows with the same
  9664. ** values in all "aOrderBy" columns to be returned, as long as all such rows
  9665. ** are adjacent. ^The virtual table may, if it chooses, omit extra rows
  9666. ** that have the same value for all columns identified by "aOrderBy".
  9667. ** ^However omitting the extra rows is optional.
  9668. ** This mode is used for a DISTINCT query.
  9669. ** <li value="3"><p>
  9670. ** ^(If the sqlite3_vtab_distinct() interface returns 3, that means
  9671. ** that the query planner needs only distinct rows but it does need the
  9672. ** rows to be sorted.)^ ^The virtual table implementation is free to omit
  9673. ** rows that are identical in all aOrderBy columns, if it wants to, but
  9674. ** it is not required to omit any rows. This mode is used for queries
  9675. ** that have both DISTINCT and ORDER BY clauses.
  9676. ** </ol>
  9677. **
  9678. ** ^For the purposes of comparing virtual table output values to see if the
  9679. ** values are same value for sorting purposes, two NULL values are considered
  9680. ** to be the same. In other words, the comparison operator is "IS"
  9681. ** (or "IS NOT DISTINCT FROM") and not "==".
  9682. **
  9683. ** If a virtual table implementation is unable to meet the requirements
  9684. ** specified above, then it must not set the "orderByConsumed" flag in the
  9685. ** [sqlite3_index_info] object or an incorrect answer may result.
  9686. **
  9687. ** ^A virtual table implementation is always free to return rows in any order
  9688. ** it wants, as long as the "orderByConsumed" flag is not set. ^When the
  9689. ** the "orderByConsumed" flag is unset, the query planner will add extra
  9690. ** [bytecode] to ensure that the final results returned by the SQL query are
  9691. ** ordered correctly. The use of the "orderByConsumed" flag and the
  9692. ** sqlite3_vtab_distinct() interface is merely an optimization. ^Careful
  9693. ** use of the sqlite3_vtab_distinct() interface and the "orderByConsumed"
  9694. ** flag might help queries against a virtual table to run faster. Being
  9695. ** overly aggressive and setting the "orderByConsumed" flag when it is not
  9696. ** valid to do so, on the other hand, might cause SQLite to return incorrect
  9697. ** results.
  9698. */
  9699. SQLITE_API int sqlite3_vtab_distinct(sqlite3_index_info*);
  9700. /*
  9701. ** CAPI3REF: Identify and handle IN constraints in xBestIndex
  9702. **
  9703. ** This interface may only be used from within an
  9704. ** [xBestIndex|xBestIndex() method] of a [virtual table] implementation.
  9705. ** The result of invoking this interface from any other context is
  9706. ** undefined and probably harmful.
  9707. **
  9708. ** ^(A constraint on a virtual table of the form
  9709. ** "[IN operator|column IN (...)]" is
  9710. ** communicated to the xBestIndex method as a
  9711. ** [SQLITE_INDEX_CONSTRAINT_EQ] constraint.)^ If xBestIndex wants to use
  9712. ** this constraint, it must set the corresponding
  9713. ** aConstraintUsage[].argvIndex to a positive integer. ^(Then, under
  9714. ** the usual mode of handling IN operators, SQLite generates [bytecode]
  9715. ** that invokes the [xFilter|xFilter() method] once for each value
  9716. ** on the right-hand side of the IN operator.)^ Thus the virtual table
  9717. ** only sees a single value from the right-hand side of the IN operator
  9718. ** at a time.
  9719. **
  9720. ** In some cases, however, it would be advantageous for the virtual
  9721. ** table to see all values on the right-hand of the IN operator all at
  9722. ** once. The sqlite3_vtab_in() interfaces facilitates this in two ways:
  9723. **
  9724. ** <ol>
  9725. ** <li><p>
  9726. ** ^A call to sqlite3_vtab_in(P,N,-1) will return true (non-zero)
  9727. ** if and only if the [sqlite3_index_info|P->aConstraint][N] constraint
  9728. ** is an [IN operator] that can be processed all at once. ^In other words,
  9729. ** sqlite3_vtab_in() with -1 in the third argument is a mechanism
  9730. ** by which the virtual table can ask SQLite if all-at-once processing
  9731. ** of the IN operator is even possible.
  9732. **
  9733. ** <li><p>
  9734. ** ^A call to sqlite3_vtab_in(P,N,F) with F==1 or F==0 indicates
  9735. ** to SQLite that the virtual table does or does not want to process
  9736. ** the IN operator all-at-once, respectively. ^Thus when the third
  9737. ** parameter (F) is non-negative, this interface is the mechanism by
  9738. ** which the virtual table tells SQLite how it wants to process the
  9739. ** IN operator.
  9740. ** </ol>
  9741. **
  9742. ** ^The sqlite3_vtab_in(P,N,F) interface can be invoked multiple times
  9743. ** within the same xBestIndex method call. ^For any given P,N pair,
  9744. ** the return value from sqlite3_vtab_in(P,N,F) will always be the same
  9745. ** within the same xBestIndex call. ^If the interface returns true
  9746. ** (non-zero), that means that the constraint is an IN operator
  9747. ** that can be processed all-at-once. ^If the constraint is not an IN
  9748. ** operator or cannot be processed all-at-once, then the interface returns
  9749. ** false.
  9750. **
  9751. ** ^(All-at-once processing of the IN operator is selected if both of the
  9752. ** following conditions are met:
  9753. **
  9754. ** <ol>
  9755. ** <li><p> The P->aConstraintUsage[N].argvIndex value is set to a positive
  9756. ** integer. This is how the virtual table tells SQLite that it wants to
  9757. ** use the N-th constraint.
  9758. **
  9759. ** <li><p> The last call to sqlite3_vtab_in(P,N,F) for which F was
  9760. ** non-negative had F>=1.
  9761. ** </ol>)^
  9762. **
  9763. ** ^If either or both of the conditions above are false, then SQLite uses
  9764. ** the traditional one-at-a-time processing strategy for the IN constraint.
  9765. ** ^If both conditions are true, then the argvIndex-th parameter to the
  9766. ** xFilter method will be an [sqlite3_value] that appears to be NULL,
  9767. ** but which can be passed to [sqlite3_vtab_in_first()] and
  9768. ** [sqlite3_vtab_in_next()] to find all values on the right-hand side
  9769. ** of the IN constraint.
  9770. */
  9771. SQLITE_API int sqlite3_vtab_in(sqlite3_index_info*, int iCons, int bHandle);
  9772. /*
  9773. ** CAPI3REF: Find all elements on the right-hand side of an IN constraint.
  9774. **
  9775. ** These interfaces are only useful from within the
  9776. ** [xFilter|xFilter() method] of a [virtual table] implementation.
  9777. ** The result of invoking these interfaces from any other context
  9778. ** is undefined and probably harmful.
  9779. **
  9780. ** The X parameter in a call to sqlite3_vtab_in_first(X,P) or
  9781. ** sqlite3_vtab_in_next(X,P) should be one of the parameters to the
  9782. ** xFilter method which invokes these routines, and specifically
  9783. ** a parameter that was previously selected for all-at-once IN constraint
  9784. ** processing use the [sqlite3_vtab_in()] interface in the
  9785. ** [xBestIndex|xBestIndex method]. ^(If the X parameter is not
  9786. ** an xFilter argument that was selected for all-at-once IN constraint
  9787. ** processing, then these routines return [SQLITE_ERROR].)^
  9788. **
  9789. ** ^(Use these routines to access all values on the right-hand side
  9790. ** of the IN constraint using code like the following:
  9791. **
  9792. ** <blockquote><pre>
  9793. ** &nbsp; for(rc=sqlite3_vtab_in_first(pList, &pVal);
  9794. ** &nbsp; rc==SQLITE_OK && pVal;
  9795. ** &nbsp; rc=sqlite3_vtab_in_next(pList, &pVal)
  9796. ** &nbsp; ){
  9797. ** &nbsp; // do something with pVal
  9798. ** &nbsp; }
  9799. ** &nbsp; if( rc!=SQLITE_OK ){
  9800. ** &nbsp; // an error has occurred
  9801. ** &nbsp; }
  9802. ** </pre></blockquote>)^
  9803. **
  9804. ** ^On success, the sqlite3_vtab_in_first(X,P) and sqlite3_vtab_in_next(X,P)
  9805. ** routines return SQLITE_OK and set *P to point to the first or next value
  9806. ** on the RHS of the IN constraint. ^If there are no more values on the
  9807. ** right hand side of the IN constraint, then *P is set to NULL and these
  9808. ** routines return [SQLITE_DONE]. ^The return value might be
  9809. ** some other value, such as SQLITE_NOMEM, in the event of a malfunction.
  9810. **
  9811. ** The *ppOut values returned by these routines are only valid until the
  9812. ** next call to either of these routines or until the end of the xFilter
  9813. ** method from which these routines were called. If the virtual table
  9814. ** implementation needs to retain the *ppOut values for longer, it must make
  9815. ** copies. The *ppOut values are [protected sqlite3_value|protected].
  9816. */
  9817. SQLITE_API int sqlite3_vtab_in_first(sqlite3_value *pVal, sqlite3_value **ppOut);
  9818. SQLITE_API int sqlite3_vtab_in_next(sqlite3_value *pVal, sqlite3_value **ppOut);
  9819. /*
  9820. ** CAPI3REF: Constraint values in xBestIndex()
  9821. ** METHOD: sqlite3_index_info
  9822. **
  9823. ** This API may only be used from within the [xBestIndex|xBestIndex method]
  9824. ** of a [virtual table] implementation. The result of calling this interface
  9825. ** from outside of an xBestIndex method are undefined and probably harmful.
  9826. **
  9827. ** ^When the sqlite3_vtab_rhs_value(P,J,V) interface is invoked from within
  9828. ** the [xBestIndex] method of a [virtual table] implementation, with P being
  9829. ** a copy of the [sqlite3_index_info] object pointer passed into xBestIndex and
  9830. ** J being a 0-based index into P->aConstraint[], then this routine
  9831. ** attempts to set *V to the value of the right-hand operand of
  9832. ** that constraint if the right-hand operand is known. ^If the
  9833. ** right-hand operand is not known, then *V is set to a NULL pointer.
  9834. ** ^The sqlite3_vtab_rhs_value(P,J,V) interface returns SQLITE_OK if
  9835. ** and only if *V is set to a value. ^The sqlite3_vtab_rhs_value(P,J,V)
  9836. ** inteface returns SQLITE_NOTFOUND if the right-hand side of the J-th
  9837. ** constraint is not available. ^The sqlite3_vtab_rhs_value() interface
  9838. ** can return an result code other than SQLITE_OK or SQLITE_NOTFOUND if
  9839. ** something goes wrong.
  9840. **
  9841. ** The sqlite3_vtab_rhs_value() interface is usually only successful if
  9842. ** the right-hand operand of a constraint is a literal value in the original
  9843. ** SQL statement. If the right-hand operand is an expression or a reference
  9844. ** to some other column or a [host parameter], then sqlite3_vtab_rhs_value()
  9845. ** will probably return [SQLITE_NOTFOUND].
  9846. **
  9847. ** ^(Some constraints, such as [SQLITE_INDEX_CONSTRAINT_ISNULL] and
  9848. ** [SQLITE_INDEX_CONSTRAINT_ISNOTNULL], have no right-hand operand. For such
  9849. ** constraints, sqlite3_vtab_rhs_value() always returns SQLITE_NOTFOUND.)^
  9850. **
  9851. ** ^The [sqlite3_value] object returned in *V is a protected sqlite3_value
  9852. ** and remains valid for the duration of the xBestIndex method call.
  9853. ** ^When xBestIndex returns, the sqlite3_value object returned by
  9854. ** sqlite3_vtab_rhs_value() is automatically deallocated.
  9855. **
  9856. ** The "_rhs_" in the name of this routine is an abbreviation for
  9857. ** "Right-Hand Side".
  9858. */
  9859. SQLITE_API int sqlite3_vtab_rhs_value(sqlite3_index_info*, int, sqlite3_value **ppVal);
  9860. /*
  9861. ** CAPI3REF: Conflict resolution modes
  9862. ** KEYWORDS: {conflict resolution mode}
  9863. **
  9864. ** These constants are returned by [sqlite3_vtab_on_conflict()] to
  9865. ** inform a [virtual table] implementation what the [ON CONFLICT] mode
  9866. ** is for the SQL statement being evaluated.
  9867. **
  9868. ** Note that the [SQLITE_IGNORE] constant is also used as a potential
  9869. ** return value from the [sqlite3_set_authorizer()] callback and that
  9870. ** [SQLITE_ABORT] is also a [result code].
  9871. */
  9872. #define SQLITE_ROLLBACK 1
  9873. /* #define SQLITE_IGNORE 2 // Also used by sqlite3_authorizer() callback */
  9874. #define SQLITE_FAIL 3
  9875. /* #define SQLITE_ABORT 4 // Also an error code */
  9876. #define SQLITE_REPLACE 5
  9877. /*
  9878. ** CAPI3REF: Prepared Statement Scan Status Opcodes
  9879. ** KEYWORDS: {scanstatus options}
  9880. **
  9881. ** The following constants can be used for the T parameter to the
  9882. ** [sqlite3_stmt_scanstatus(S,X,T,V)] interface. Each constant designates a
  9883. ** different metric for sqlite3_stmt_scanstatus() to return.
  9884. **
  9885. ** When the value returned to V is a string, space to hold that string is
  9886. ** managed by the prepared statement S and will be automatically freed when
  9887. ** S is finalized.
  9888. **
  9889. ** Not all values are available for all query elements. When a value is
  9890. ** not available, the output variable is set to -1 if the value is numeric,
  9891. ** or to NULL if it is a string (SQLITE_SCANSTAT_NAME).
  9892. **
  9893. ** <dl>
  9894. ** [[SQLITE_SCANSTAT_NLOOP]] <dt>SQLITE_SCANSTAT_NLOOP</dt>
  9895. ** <dd>^The [sqlite3_int64] variable pointed to by the V parameter will be
  9896. ** set to the total number of times that the X-th loop has run.</dd>
  9897. **
  9898. ** [[SQLITE_SCANSTAT_NVISIT]] <dt>SQLITE_SCANSTAT_NVISIT</dt>
  9899. ** <dd>^The [sqlite3_int64] variable pointed to by the V parameter will be set
  9900. ** to the total number of rows examined by all iterations of the X-th loop.</dd>
  9901. **
  9902. ** [[SQLITE_SCANSTAT_EST]] <dt>SQLITE_SCANSTAT_EST</dt>
  9903. ** <dd>^The "double" variable pointed to by the V parameter will be set to the
  9904. ** query planner's estimate for the average number of rows output from each
  9905. ** iteration of the X-th loop. If the query planner's estimates was accurate,
  9906. ** then this value will approximate the quotient NVISIT/NLOOP and the
  9907. ** product of this value for all prior loops with the same SELECTID will
  9908. ** be the NLOOP value for the current loop.
  9909. **
  9910. ** [[SQLITE_SCANSTAT_NAME]] <dt>SQLITE_SCANSTAT_NAME</dt>
  9911. ** <dd>^The "const char *" variable pointed to by the V parameter will be set
  9912. ** to a zero-terminated UTF-8 string containing the name of the index or table
  9913. ** used for the X-th loop.
  9914. **
  9915. ** [[SQLITE_SCANSTAT_EXPLAIN]] <dt>SQLITE_SCANSTAT_EXPLAIN</dt>
  9916. ** <dd>^The "const char *" variable pointed to by the V parameter will be set
  9917. ** to a zero-terminated UTF-8 string containing the [EXPLAIN QUERY PLAN]
  9918. ** description for the X-th loop.
  9919. **
  9920. ** [[SQLITE_SCANSTAT_SELECTID]] <dt>SQLITE_SCANSTAT_SELECTID</dt>
  9921. ** <dd>^The "int" variable pointed to by the V parameter will be set to the
  9922. ** id for the X-th query plan element. The id value is unique within the
  9923. ** statement. The select-id is the same value as is output in the first
  9924. ** column of an [EXPLAIN QUERY PLAN] query.
  9925. **
  9926. ** [[SQLITE_SCANSTAT_PARENTID]] <dt>SQLITE_SCANSTAT_PARENTID</dt>
  9927. ** <dd>The "int" variable pointed to by the V parameter will be set to the
  9928. ** the id of the parent of the current query element, if applicable, or
  9929. ** to zero if the query element has no parent. This is the same value as
  9930. ** returned in the second column of an [EXPLAIN QUERY PLAN] query.
  9931. **
  9932. ** [[SQLITE_SCANSTAT_NCYCLE]] <dt>SQLITE_SCANSTAT_NCYCLE</dt>
  9933. ** <dd>The sqlite3_int64 output value is set to the number of cycles,
  9934. ** according to the processor time-stamp counter, that elapsed while the
  9935. ** query element was being processed. This value is not available for
  9936. ** all query elements - if it is unavailable the output variable is
  9937. ** set to -1.
  9938. ** </dl>
  9939. */
  9940. #define SQLITE_SCANSTAT_NLOOP 0
  9941. #define SQLITE_SCANSTAT_NVISIT 1
  9942. #define SQLITE_SCANSTAT_EST 2
  9943. #define SQLITE_SCANSTAT_NAME 3
  9944. #define SQLITE_SCANSTAT_EXPLAIN 4
  9945. #define SQLITE_SCANSTAT_SELECTID 5
  9946. #define SQLITE_SCANSTAT_PARENTID 6
  9947. #define SQLITE_SCANSTAT_NCYCLE 7
  9948. /*
  9949. ** CAPI3REF: Prepared Statement Scan Status
  9950. ** METHOD: sqlite3_stmt
  9951. **
  9952. ** These interfaces return information about the predicted and measured
  9953. ** performance for pStmt. Advanced applications can use this
  9954. ** interface to compare the predicted and the measured performance and
  9955. ** issue warnings and/or rerun [ANALYZE] if discrepancies are found.
  9956. **
  9957. ** Since this interface is expected to be rarely used, it is only
  9958. ** available if SQLite is compiled using the [SQLITE_ENABLE_STMT_SCANSTATUS]
  9959. ** compile-time option.
  9960. **
  9961. ** The "iScanStatusOp" parameter determines which status information to return.
  9962. ** The "iScanStatusOp" must be one of the [scanstatus options] or the behavior
  9963. ** of this interface is undefined. ^The requested measurement is written into
  9964. ** a variable pointed to by the "pOut" parameter.
  9965. **
  9966. ** The "flags" parameter must be passed a mask of flags. At present only
  9967. ** one flag is defined - SQLITE_SCANSTAT_COMPLEX. If SQLITE_SCANSTAT_COMPLEX
  9968. ** is specified, then status information is available for all elements
  9969. ** of a query plan that are reported by "EXPLAIN QUERY PLAN" output. If
  9970. ** SQLITE_SCANSTAT_COMPLEX is not specified, then only query plan elements
  9971. ** that correspond to query loops (the "SCAN..." and "SEARCH..." elements of
  9972. ** the EXPLAIN QUERY PLAN output) are available. Invoking API
  9973. ** sqlite3_stmt_scanstatus() is equivalent to calling
  9974. ** sqlite3_stmt_scanstatus_v2() with a zeroed flags parameter.
  9975. **
  9976. ** Parameter "idx" identifies the specific query element to retrieve statistics
  9977. ** for. Query elements are numbered starting from zero. A value of -1 may be
  9978. ** to query for statistics regarding the entire query. ^If idx is out of range
  9979. ** - less than -1 or greater than or equal to the total number of query
  9980. ** elements used to implement the statement - a non-zero value is returned and
  9981. ** the variable that pOut points to is unchanged.
  9982. **
  9983. ** See also: [sqlite3_stmt_scanstatus_reset()]
  9984. */
  9985. SQLITE_API int sqlite3_stmt_scanstatus(
  9986. sqlite3_stmt *pStmt, /* Prepared statement for which info desired */
  9987. int idx, /* Index of loop to report on */
  9988. int iScanStatusOp, /* Information desired. SQLITE_SCANSTAT_* */
  9989. void *pOut /* Result written here */
  9990. );
  9991. SQLITE_API int sqlite3_stmt_scanstatus_v2(
  9992. sqlite3_stmt *pStmt, /* Prepared statement for which info desired */
  9993. int idx, /* Index of loop to report on */
  9994. int iScanStatusOp, /* Information desired. SQLITE_SCANSTAT_* */
  9995. int flags, /* Mask of flags defined below */
  9996. void *pOut /* Result written here */
  9997. );
  9998. /*
  9999. ** CAPI3REF: Prepared Statement Scan Status
  10000. ** KEYWORDS: {scan status flags}
  10001. */
  10002. #define SQLITE_SCANSTAT_COMPLEX 0x0001
  10003. /*
  10004. ** CAPI3REF: Zero Scan-Status Counters
  10005. ** METHOD: sqlite3_stmt
  10006. **
  10007. ** ^Zero all [sqlite3_stmt_scanstatus()] related event counters.
  10008. **
  10009. ** This API is only available if the library is built with pre-processor
  10010. ** symbol [SQLITE_ENABLE_STMT_SCANSTATUS] defined.
  10011. */
  10012. SQLITE_API void sqlite3_stmt_scanstatus_reset(sqlite3_stmt*);
  10013. /*
  10014. ** CAPI3REF: Flush caches to disk mid-transaction
  10015. ** METHOD: sqlite3
  10016. **
  10017. ** ^If a write-transaction is open on [database connection] D when the
  10018. ** [sqlite3_db_cacheflush(D)] interface invoked, any dirty
  10019. ** pages in the pager-cache that are not currently in use are written out
  10020. ** to disk. A dirty page may be in use if a database cursor created by an
  10021. ** active SQL statement is reading from it, or if it is page 1 of a database
  10022. ** file (page 1 is always "in use"). ^The [sqlite3_db_cacheflush(D)]
  10023. ** interface flushes caches for all schemas - "main", "temp", and
  10024. ** any [attached] databases.
  10025. **
  10026. ** ^If this function needs to obtain extra database locks before dirty pages
  10027. ** can be flushed to disk, it does so. ^If those locks cannot be obtained
  10028. ** immediately and there is a busy-handler callback configured, it is invoked
  10029. ** in the usual manner. ^If the required lock still cannot be obtained, then
  10030. ** the database is skipped and an attempt made to flush any dirty pages
  10031. ** belonging to the next (if any) database. ^If any databases are skipped
  10032. ** because locks cannot be obtained, but no other error occurs, this
  10033. ** function returns SQLITE_BUSY.
  10034. **
  10035. ** ^If any other error occurs while flushing dirty pages to disk (for
  10036. ** example an IO error or out-of-memory condition), then processing is
  10037. ** abandoned and an SQLite [error code] is returned to the caller immediately.
  10038. **
  10039. ** ^Otherwise, if no error occurs, [sqlite3_db_cacheflush()] returns SQLITE_OK.
  10040. **
  10041. ** ^This function does not set the database handle error code or message
  10042. ** returned by the [sqlite3_errcode()] and [sqlite3_errmsg()] functions.
  10043. */
  10044. SQLITE_API int sqlite3_db_cacheflush(sqlite3*);
  10045. /*
  10046. ** CAPI3REF: The pre-update hook.
  10047. ** METHOD: sqlite3
  10048. **
  10049. ** ^These interfaces are only available if SQLite is compiled using the
  10050. ** [SQLITE_ENABLE_PREUPDATE_HOOK] compile-time option.
  10051. **
  10052. ** ^The [sqlite3_preupdate_hook()] interface registers a callback function
  10053. ** that is invoked prior to each [INSERT], [UPDATE], and [DELETE] operation
  10054. ** on a database table.
  10055. ** ^At most one preupdate hook may be registered at a time on a single
  10056. ** [database connection]; each call to [sqlite3_preupdate_hook()] overrides
  10057. ** the previous setting.
  10058. ** ^The preupdate hook is disabled by invoking [sqlite3_preupdate_hook()]
  10059. ** with a NULL pointer as the second parameter.
  10060. ** ^The third parameter to [sqlite3_preupdate_hook()] is passed through as
  10061. ** the first parameter to callbacks.
  10062. **
  10063. ** ^The preupdate hook only fires for changes to real database tables; the
  10064. ** preupdate hook is not invoked for changes to [virtual tables] or to
  10065. ** system tables like sqlite_sequence or sqlite_stat1.
  10066. **
  10067. ** ^The second parameter to the preupdate callback is a pointer to
  10068. ** the [database connection] that registered the preupdate hook.
  10069. ** ^The third parameter to the preupdate callback is one of the constants
  10070. ** [SQLITE_INSERT], [SQLITE_DELETE], or [SQLITE_UPDATE] to identify the
  10071. ** kind of update operation that is about to occur.
  10072. ** ^(The fourth parameter to the preupdate callback is the name of the
  10073. ** database within the database connection that is being modified. This
  10074. ** will be "main" for the main database or "temp" for TEMP tables or
  10075. ** the name given after the AS keyword in the [ATTACH] statement for attached
  10076. ** databases.)^
  10077. ** ^The fifth parameter to the preupdate callback is the name of the
  10078. ** table that is being modified.
  10079. **
  10080. ** For an UPDATE or DELETE operation on a [rowid table], the sixth
  10081. ** parameter passed to the preupdate callback is the initial [rowid] of the
  10082. ** row being modified or deleted. For an INSERT operation on a rowid table,
  10083. ** or any operation on a WITHOUT ROWID table, the value of the sixth
  10084. ** parameter is undefined. For an INSERT or UPDATE on a rowid table the
  10085. ** seventh parameter is the final rowid value of the row being inserted
  10086. ** or updated. The value of the seventh parameter passed to the callback
  10087. ** function is not defined for operations on WITHOUT ROWID tables, or for
  10088. ** DELETE operations on rowid tables.
  10089. **
  10090. ** ^The sqlite3_preupdate_hook(D,C,P) function returns the P argument from
  10091. ** the previous call on the same [database connection] D, or NULL for
  10092. ** the first call on D.
  10093. **
  10094. ** The [sqlite3_preupdate_old()], [sqlite3_preupdate_new()],
  10095. ** [sqlite3_preupdate_count()], and [sqlite3_preupdate_depth()] interfaces
  10096. ** provide additional information about a preupdate event. These routines
  10097. ** may only be called from within a preupdate callback. Invoking any of
  10098. ** these routines from outside of a preupdate callback or with a
  10099. ** [database connection] pointer that is different from the one supplied
  10100. ** to the preupdate callback results in undefined and probably undesirable
  10101. ** behavior.
  10102. **
  10103. ** ^The [sqlite3_preupdate_count(D)] interface returns the number of columns
  10104. ** in the row that is being inserted, updated, or deleted.
  10105. **
  10106. ** ^The [sqlite3_preupdate_old(D,N,P)] interface writes into P a pointer to
  10107. ** a [protected sqlite3_value] that contains the value of the Nth column of
  10108. ** the table row before it is updated. The N parameter must be between 0
  10109. ** and one less than the number of columns or the behavior will be
  10110. ** undefined. This must only be used within SQLITE_UPDATE and SQLITE_DELETE
  10111. ** preupdate callbacks; if it is used by an SQLITE_INSERT callback then the
  10112. ** behavior is undefined. The [sqlite3_value] that P points to
  10113. ** will be destroyed when the preupdate callback returns.
  10114. **
  10115. ** ^The [sqlite3_preupdate_new(D,N,P)] interface writes into P a pointer to
  10116. ** a [protected sqlite3_value] that contains the value of the Nth column of
  10117. ** the table row after it is updated. The N parameter must be between 0
  10118. ** and one less than the number of columns or the behavior will be
  10119. ** undefined. This must only be used within SQLITE_INSERT and SQLITE_UPDATE
  10120. ** preupdate callbacks; if it is used by an SQLITE_DELETE callback then the
  10121. ** behavior is undefined. The [sqlite3_value] that P points to
  10122. ** will be destroyed when the preupdate callback returns.
  10123. **
  10124. ** ^The [sqlite3_preupdate_depth(D)] interface returns 0 if the preupdate
  10125. ** callback was invoked as a result of a direct insert, update, or delete
  10126. ** operation; or 1 for inserts, updates, or deletes invoked by top-level
  10127. ** triggers; or 2 for changes resulting from triggers called by top-level
  10128. ** triggers; and so forth.
  10129. **
  10130. ** When the [sqlite3_blob_write()] API is used to update a blob column,
  10131. ** the pre-update hook is invoked with SQLITE_DELETE. This is because the
  10132. ** in this case the new values are not available. In this case, when a
  10133. ** callback made with op==SQLITE_DELETE is actually a write using the
  10134. ** sqlite3_blob_write() API, the [sqlite3_preupdate_blobwrite()] returns
  10135. ** the index of the column being written. In other cases, where the
  10136. ** pre-update hook is being invoked for some other reason, including a
  10137. ** regular DELETE, sqlite3_preupdate_blobwrite() returns -1.
  10138. **
  10139. ** See also: [sqlite3_update_hook()]
  10140. */
  10141. #if defined(SQLITE_ENABLE_PREUPDATE_HOOK)
  10142. SQLITE_API void *sqlite3_preupdate_hook(
  10143. sqlite3 *db,
  10144. void(*xPreUpdate)(
  10145. void *pCtx, /* Copy of third arg to preupdate_hook() */
  10146. sqlite3 *db, /* Database handle */
  10147. int op, /* SQLITE_UPDATE, DELETE or INSERT */
  10148. char const *zDb, /* Database name */
  10149. char const *zName, /* Table name */
  10150. sqlite3_int64 iKey1, /* Rowid of row about to be deleted/updated */
  10151. sqlite3_int64 iKey2 /* New rowid value (for a rowid UPDATE) */
  10152. ),
  10153. void*
  10154. );
  10155. SQLITE_API int sqlite3_preupdate_old(sqlite3 *, int, sqlite3_value **);
  10156. SQLITE_API int sqlite3_preupdate_count(sqlite3 *);
  10157. SQLITE_API int sqlite3_preupdate_depth(sqlite3 *);
  10158. SQLITE_API int sqlite3_preupdate_new(sqlite3 *, int, sqlite3_value **);
  10159. SQLITE_API int sqlite3_preupdate_blobwrite(sqlite3 *);
  10160. #endif
  10161. /*
  10162. ** CAPI3REF: Low-level system error code
  10163. ** METHOD: sqlite3
  10164. **
  10165. ** ^Attempt to return the underlying operating system error code or error
  10166. ** number that caused the most recent I/O error or failure to open a file.
  10167. ** The return value is OS-dependent. For example, on unix systems, after
  10168. ** [sqlite3_open_v2()] returns [SQLITE_CANTOPEN], this interface could be
  10169. ** called to get back the underlying "errno" that caused the problem, such
  10170. ** as ENOSPC, EAUTH, EISDIR, and so forth.
  10171. */
  10172. SQLITE_API int sqlite3_system_errno(sqlite3*);
  10173. /*
  10174. ** CAPI3REF: Database Snapshot
  10175. ** KEYWORDS: {snapshot} {sqlite3_snapshot}
  10176. **
  10177. ** An instance of the snapshot object records the state of a [WAL mode]
  10178. ** database for some specific point in history.
  10179. **
  10180. ** In [WAL mode], multiple [database connections] that are open on the
  10181. ** same database file can each be reading a different historical version
  10182. ** of the database file. When a [database connection] begins a read
  10183. ** transaction, that connection sees an unchanging copy of the database
  10184. ** as it existed for the point in time when the transaction first started.
  10185. ** Subsequent changes to the database from other connections are not seen
  10186. ** by the reader until a new read transaction is started.
  10187. **
  10188. ** The sqlite3_snapshot object records state information about an historical
  10189. ** version of the database file so that it is possible to later open a new read
  10190. ** transaction that sees that historical version of the database rather than
  10191. ** the most recent version.
  10192. */
  10193. typedef struct sqlite3_snapshot {
  10194. unsigned char hidden[48];
  10195. } sqlite3_snapshot;
  10196. /*
  10197. ** CAPI3REF: Record A Database Snapshot
  10198. ** CONSTRUCTOR: sqlite3_snapshot
  10199. **
  10200. ** ^The [sqlite3_snapshot_get(D,S,P)] interface attempts to make a
  10201. ** new [sqlite3_snapshot] object that records the current state of
  10202. ** schema S in database connection D. ^On success, the
  10203. ** [sqlite3_snapshot_get(D,S,P)] interface writes a pointer to the newly
  10204. ** created [sqlite3_snapshot] object into *P and returns SQLITE_OK.
  10205. ** If there is not already a read-transaction open on schema S when
  10206. ** this function is called, one is opened automatically.
  10207. **
  10208. ** The following must be true for this function to succeed. If any of
  10209. ** the following statements are false when sqlite3_snapshot_get() is
  10210. ** called, SQLITE_ERROR is returned. The final value of *P is undefined
  10211. ** in this case.
  10212. **
  10213. ** <ul>
  10214. ** <li> The database handle must not be in [autocommit mode].
  10215. **
  10216. ** <li> Schema S of [database connection] D must be a [WAL mode] database.
  10217. **
  10218. ** <li> There must not be a write transaction open on schema S of database
  10219. ** connection D.
  10220. **
  10221. ** <li> One or more transactions must have been written to the current wal
  10222. ** file since it was created on disk (by any connection). This means
  10223. ** that a snapshot cannot be taken on a wal mode database with no wal
  10224. ** file immediately after it is first opened. At least one transaction
  10225. ** must be written to it first.
  10226. ** </ul>
  10227. **
  10228. ** This function may also return SQLITE_NOMEM. If it is called with the
  10229. ** database handle in autocommit mode but fails for some other reason,
  10230. ** whether or not a read transaction is opened on schema S is undefined.
  10231. **
  10232. ** The [sqlite3_snapshot] object returned from a successful call to
  10233. ** [sqlite3_snapshot_get()] must be freed using [sqlite3_snapshot_free()]
  10234. ** to avoid a memory leak.
  10235. **
  10236. ** The [sqlite3_snapshot_get()] interface is only available when the
  10237. ** [SQLITE_ENABLE_SNAPSHOT] compile-time option is used.
  10238. */
  10239. SQLITE_API SQLITE_EXPERIMENTAL int sqlite3_snapshot_get(
  10240. sqlite3 *db,
  10241. const char *zSchema,
  10242. sqlite3_snapshot **ppSnapshot
  10243. );
  10244. /*
  10245. ** CAPI3REF: Start a read transaction on an historical snapshot
  10246. ** METHOD: sqlite3_snapshot
  10247. **
  10248. ** ^The [sqlite3_snapshot_open(D,S,P)] interface either starts a new read
  10249. ** transaction or upgrades an existing one for schema S of
  10250. ** [database connection] D such that the read transaction refers to
  10251. ** historical [snapshot] P, rather than the most recent change to the
  10252. ** database. ^The [sqlite3_snapshot_open()] interface returns SQLITE_OK
  10253. ** on success or an appropriate [error code] if it fails.
  10254. **
  10255. ** ^In order to succeed, the database connection must not be in
  10256. ** [autocommit mode] when [sqlite3_snapshot_open(D,S,P)] is called. If there
  10257. ** is already a read transaction open on schema S, then the database handle
  10258. ** must have no active statements (SELECT statements that have been passed
  10259. ** to sqlite3_step() but not sqlite3_reset() or sqlite3_finalize()).
  10260. ** SQLITE_ERROR is returned if either of these conditions is violated, or
  10261. ** if schema S does not exist, or if the snapshot object is invalid.
  10262. **
  10263. ** ^A call to sqlite3_snapshot_open() will fail to open if the specified
  10264. ** snapshot has been overwritten by a [checkpoint]. In this case
  10265. ** SQLITE_ERROR_SNAPSHOT is returned.
  10266. **
  10267. ** If there is already a read transaction open when this function is
  10268. ** invoked, then the same read transaction remains open (on the same
  10269. ** database snapshot) if SQLITE_ERROR, SQLITE_BUSY or SQLITE_ERROR_SNAPSHOT
  10270. ** is returned. If another error code - for example SQLITE_PROTOCOL or an
  10271. ** SQLITE_IOERR error code - is returned, then the final state of the
  10272. ** read transaction is undefined. If SQLITE_OK is returned, then the
  10273. ** read transaction is now open on database snapshot P.
  10274. **
  10275. ** ^(A call to [sqlite3_snapshot_open(D,S,P)] will fail if the
  10276. ** database connection D does not know that the database file for
  10277. ** schema S is in [WAL mode]. A database connection might not know
  10278. ** that the database file is in [WAL mode] if there has been no prior
  10279. ** I/O on that database connection, or if the database entered [WAL mode]
  10280. ** after the most recent I/O on the database connection.)^
  10281. ** (Hint: Run "[PRAGMA application_id]" against a newly opened
  10282. ** database connection in order to make it ready to use snapshots.)
  10283. **
  10284. ** The [sqlite3_snapshot_open()] interface is only available when the
  10285. ** [SQLITE_ENABLE_SNAPSHOT] compile-time option is used.
  10286. */
  10287. SQLITE_API SQLITE_EXPERIMENTAL int sqlite3_snapshot_open(
  10288. sqlite3 *db,
  10289. const char *zSchema,
  10290. sqlite3_snapshot *pSnapshot
  10291. );
  10292. /*
  10293. ** CAPI3REF: Destroy a snapshot
  10294. ** DESTRUCTOR: sqlite3_snapshot
  10295. **
  10296. ** ^The [sqlite3_snapshot_free(P)] interface destroys [sqlite3_snapshot] P.
  10297. ** The application must eventually free every [sqlite3_snapshot] object
  10298. ** using this routine to avoid a memory leak.
  10299. **
  10300. ** The [sqlite3_snapshot_free()] interface is only available when the
  10301. ** [SQLITE_ENABLE_SNAPSHOT] compile-time option is used.
  10302. */
  10303. SQLITE_API SQLITE_EXPERIMENTAL void sqlite3_snapshot_free(sqlite3_snapshot*);
  10304. /*
  10305. ** CAPI3REF: Compare the ages of two snapshot handles.
  10306. ** METHOD: sqlite3_snapshot
  10307. **
  10308. ** The sqlite3_snapshot_cmp(P1, P2) interface is used to compare the ages
  10309. ** of two valid snapshot handles.
  10310. **
  10311. ** If the two snapshot handles are not associated with the same database
  10312. ** file, the result of the comparison is undefined.
  10313. **
  10314. ** Additionally, the result of the comparison is only valid if both of the
  10315. ** snapshot handles were obtained by calling sqlite3_snapshot_get() since the
  10316. ** last time the wal file was deleted. The wal file is deleted when the
  10317. ** database is changed back to rollback mode or when the number of database
  10318. ** clients drops to zero. If either snapshot handle was obtained before the
  10319. ** wal file was last deleted, the value returned by this function
  10320. ** is undefined.
  10321. **
  10322. ** Otherwise, this API returns a negative value if P1 refers to an older
  10323. ** snapshot than P2, zero if the two handles refer to the same database
  10324. ** snapshot, and a positive value if P1 is a newer snapshot than P2.
  10325. **
  10326. ** This interface is only available if SQLite is compiled with the
  10327. ** [SQLITE_ENABLE_SNAPSHOT] option.
  10328. */
  10329. SQLITE_API SQLITE_EXPERIMENTAL int sqlite3_snapshot_cmp(
  10330. sqlite3_snapshot *p1,
  10331. sqlite3_snapshot *p2
  10332. );
  10333. /*
  10334. ** CAPI3REF: Recover snapshots from a wal file
  10335. ** METHOD: sqlite3_snapshot
  10336. **
  10337. ** If a [WAL file] remains on disk after all database connections close
  10338. ** (either through the use of the [SQLITE_FCNTL_PERSIST_WAL] [file control]
  10339. ** or because the last process to have the database opened exited without
  10340. ** calling [sqlite3_close()]) and a new connection is subsequently opened
  10341. ** on that database and [WAL file], the [sqlite3_snapshot_open()] interface
  10342. ** will only be able to open the last transaction added to the WAL file
  10343. ** even though the WAL file contains other valid transactions.
  10344. **
  10345. ** This function attempts to scan the WAL file associated with database zDb
  10346. ** of database handle db and make all valid snapshots available to
  10347. ** sqlite3_snapshot_open(). It is an error if there is already a read
  10348. ** transaction open on the database, or if the database is not a WAL mode
  10349. ** database.
  10350. **
  10351. ** SQLITE_OK is returned if successful, or an SQLite error code otherwise.
  10352. **
  10353. ** This interface is only available if SQLite is compiled with the
  10354. ** [SQLITE_ENABLE_SNAPSHOT] option.
  10355. */
  10356. SQLITE_API SQLITE_EXPERIMENTAL int sqlite3_snapshot_recover(sqlite3 *db, const char *zDb);
  10357. /*
  10358. ** CAPI3REF: Serialize a database
  10359. **
  10360. ** The sqlite3_serialize(D,S,P,F) interface returns a pointer to memory
  10361. ** that is a serialization of the S database on [database connection] D.
  10362. ** If P is not a NULL pointer, then the size of the database in bytes
  10363. ** is written into *P.
  10364. **
  10365. ** For an ordinary on-disk database file, the serialization is just a
  10366. ** copy of the disk file. For an in-memory database or a "TEMP" database,
  10367. ** the serialization is the same sequence of bytes which would be written
  10368. ** to disk if that database where backed up to disk.
  10369. **
  10370. ** The usual case is that sqlite3_serialize() copies the serialization of
  10371. ** the database into memory obtained from [sqlite3_malloc64()] and returns
  10372. ** a pointer to that memory. The caller is responsible for freeing the
  10373. ** returned value to avoid a memory leak. However, if the F argument
  10374. ** contains the SQLITE_SERIALIZE_NOCOPY bit, then no memory allocations
  10375. ** are made, and the sqlite3_serialize() function will return a pointer
  10376. ** to the contiguous memory representation of the database that SQLite
  10377. ** is currently using for that database, or NULL if the no such contiguous
  10378. ** memory representation of the database exists. A contiguous memory
  10379. ** representation of the database will usually only exist if there has
  10380. ** been a prior call to [sqlite3_deserialize(D,S,...)] with the same
  10381. ** values of D and S.
  10382. ** The size of the database is written into *P even if the
  10383. ** SQLITE_SERIALIZE_NOCOPY bit is set but no contiguous copy
  10384. ** of the database exists.
  10385. **
  10386. ** After the call, if the SQLITE_SERIALIZE_NOCOPY bit had been set,
  10387. ** the returned buffer content will remain accessible and unchanged
  10388. ** until either the next write operation on the connection or when
  10389. ** the connection is closed, and applications must not modify the
  10390. ** buffer. If the bit had been clear, the returned buffer will not
  10391. ** be accessed by SQLite after the call.
  10392. **
  10393. ** A call to sqlite3_serialize(D,S,P,F) might return NULL even if the
  10394. ** SQLITE_SERIALIZE_NOCOPY bit is omitted from argument F if a memory
  10395. ** allocation error occurs.
  10396. **
  10397. ** This interface is omitted if SQLite is compiled with the
  10398. ** [SQLITE_OMIT_DESERIALIZE] option.
  10399. */
  10400. SQLITE_API unsigned char *sqlite3_serialize(
  10401. sqlite3 *db, /* The database connection */
  10402. const char *zSchema, /* Which DB to serialize. ex: "main", "temp", ... */
  10403. sqlite3_int64 *piSize, /* Write size of the DB here, if not NULL */
  10404. unsigned int mFlags /* Zero or more SQLITE_SERIALIZE_* flags */
  10405. );
  10406. /*
  10407. ** CAPI3REF: Flags for sqlite3_serialize
  10408. **
  10409. ** Zero or more of the following constants can be OR-ed together for
  10410. ** the F argument to [sqlite3_serialize(D,S,P,F)].
  10411. **
  10412. ** SQLITE_SERIALIZE_NOCOPY means that [sqlite3_serialize()] will return
  10413. ** a pointer to contiguous in-memory database that it is currently using,
  10414. ** without making a copy of the database. If SQLite is not currently using
  10415. ** a contiguous in-memory database, then this option causes
  10416. ** [sqlite3_serialize()] to return a NULL pointer. SQLite will only be
  10417. ** using a contiguous in-memory database if it has been initialized by a
  10418. ** prior call to [sqlite3_deserialize()].
  10419. */
  10420. #define SQLITE_SERIALIZE_NOCOPY 0x001 /* Do no memory allocations */
  10421. /*
  10422. ** CAPI3REF: Deserialize a database
  10423. **
  10424. ** The sqlite3_deserialize(D,S,P,N,M,F) interface causes the
  10425. ** [database connection] D to disconnect from database S and then
  10426. ** reopen S as an in-memory database based on the serialization contained
  10427. ** in P. The serialized database P is N bytes in size. M is the size of
  10428. ** the buffer P, which might be larger than N. If M is larger than N, and
  10429. ** the SQLITE_DESERIALIZE_READONLY bit is not set in F, then SQLite is
  10430. ** permitted to add content to the in-memory database as long as the total
  10431. ** size does not exceed M bytes.
  10432. **
  10433. ** If the SQLITE_DESERIALIZE_FREEONCLOSE bit is set in F, then SQLite will
  10434. ** invoke sqlite3_free() on the serialization buffer when the database
  10435. ** connection closes. If the SQLITE_DESERIALIZE_RESIZEABLE bit is set, then
  10436. ** SQLite will try to increase the buffer size using sqlite3_realloc64()
  10437. ** if writes on the database cause it to grow larger than M bytes.
  10438. **
  10439. ** Applications must not modify the buffer P or invalidate it before
  10440. ** the database connection D is closed.
  10441. **
  10442. ** The sqlite3_deserialize() interface will fail with SQLITE_BUSY if the
  10443. ** database is currently in a read transaction or is involved in a backup
  10444. ** operation.
  10445. **
  10446. ** It is not possible to deserialized into the TEMP database. If the
  10447. ** S argument to sqlite3_deserialize(D,S,P,N,M,F) is "temp" then the
  10448. ** function returns SQLITE_ERROR.
  10449. **
  10450. ** The deserialized database should not be in [WAL mode]. If the database
  10451. ** is in WAL mode, then any attempt to use the database file will result
  10452. ** in an [SQLITE_CANTOPEN] error. The application can set the
  10453. ** [file format version numbers] (bytes 18 and 19) of the input database P
  10454. ** to 0x01 prior to invoking sqlite3_deserialize(D,S,P,N,M,F) to force the
  10455. ** database file into rollback mode and work around this limitation.
  10456. **
  10457. ** If sqlite3_deserialize(D,S,P,N,M,F) fails for any reason and if the
  10458. ** SQLITE_DESERIALIZE_FREEONCLOSE bit is set in argument F, then
  10459. ** [sqlite3_free()] is invoked on argument P prior to returning.
  10460. **
  10461. ** This interface is omitted if SQLite is compiled with the
  10462. ** [SQLITE_OMIT_DESERIALIZE] option.
  10463. */
  10464. SQLITE_API int sqlite3_deserialize(
  10465. sqlite3 *db, /* The database connection */
  10466. const char *zSchema, /* Which DB to reopen with the deserialization */
  10467. unsigned char *pData, /* The serialized database content */
  10468. sqlite3_int64 szDb, /* Number bytes in the deserialization */
  10469. sqlite3_int64 szBuf, /* Total size of buffer pData[] */
  10470. unsigned mFlags /* Zero or more SQLITE_DESERIALIZE_* flags */
  10471. );
  10472. /*
  10473. ** CAPI3REF: Flags for sqlite3_deserialize()
  10474. **
  10475. ** The following are allowed values for 6th argument (the F argument) to
  10476. ** the [sqlite3_deserialize(D,S,P,N,M,F)] interface.
  10477. **
  10478. ** The SQLITE_DESERIALIZE_FREEONCLOSE means that the database serialization
  10479. ** in the P argument is held in memory obtained from [sqlite3_malloc64()]
  10480. ** and that SQLite should take ownership of this memory and automatically
  10481. ** free it when it has finished using it. Without this flag, the caller
  10482. ** is responsible for freeing any dynamically allocated memory.
  10483. **
  10484. ** The SQLITE_DESERIALIZE_RESIZEABLE flag means that SQLite is allowed to
  10485. ** grow the size of the database using calls to [sqlite3_realloc64()]. This
  10486. ** flag should only be used if SQLITE_DESERIALIZE_FREEONCLOSE is also used.
  10487. ** Without this flag, the deserialized database cannot increase in size beyond
  10488. ** the number of bytes specified by the M parameter.
  10489. **
  10490. ** The SQLITE_DESERIALIZE_READONLY flag means that the deserialized database
  10491. ** should be treated as read-only.
  10492. */
  10493. #define SQLITE_DESERIALIZE_FREEONCLOSE 1 /* Call sqlite3_free() on close */
  10494. #define SQLITE_DESERIALIZE_RESIZEABLE 2 /* Resize using sqlite3_realloc64() */
  10495. #define SQLITE_DESERIALIZE_READONLY 4 /* Database is read-only */
  10496. /*
  10497. ** Undo the hack that converts floating point types to integer for
  10498. ** builds on processors without floating point support.
  10499. */
  10500. #ifdef SQLITE_OMIT_FLOATING_POINT
  10501. # undef double
  10502. #endif
  10503. #if defined(__wasi__)
  10504. # undef SQLITE_WASI
  10505. # define SQLITE_WASI 1
  10506. # undef SQLITE_OMIT_WAL
  10507. # define SQLITE_OMIT_WAL 1/* because it requires shared memory APIs */
  10508. # ifndef SQLITE_OMIT_LOAD_EXTENSION
  10509. # define SQLITE_OMIT_LOAD_EXTENSION
  10510. # endif
  10511. # ifndef SQLITE_THREADSAFE
  10512. # define SQLITE_THREADSAFE 0
  10513. # endif
  10514. #endif
  10515. #ifdef __cplusplus
  10516. } /* End of the 'extern "C"' block */
  10517. #endif
  10518. #endif /* SQLITE3_H */
  10519. /******** Begin file sqlite3rtree.h *********/
  10520. /*
  10521. ** 2010 August 30
  10522. **
  10523. ** The author disclaims copyright to this source code. In place of
  10524. ** a legal notice, here is a blessing:
  10525. **
  10526. ** May you do good and not evil.
  10527. ** May you find forgiveness for yourself and forgive others.
  10528. ** May you share freely, never taking more than you give.
  10529. **
  10530. *************************************************************************
  10531. */
  10532. #ifndef _SQLITE3RTREE_H_
  10533. #define _SQLITE3RTREE_H_
  10534. #ifdef __cplusplus
  10535. extern "C" {
  10536. #endif
  10537. typedef struct sqlite3_rtree_geometry sqlite3_rtree_geometry;
  10538. typedef struct sqlite3_rtree_query_info sqlite3_rtree_query_info;
  10539. /* The double-precision datatype used by RTree depends on the
  10540. ** SQLITE_RTREE_INT_ONLY compile-time option.
  10541. */
  10542. #ifdef SQLITE_RTREE_INT_ONLY
  10543. typedef sqlite3_int64 sqlite3_rtree_dbl;
  10544. #else
  10545. typedef double sqlite3_rtree_dbl;
  10546. #endif
  10547. /*
  10548. ** Register a geometry callback named zGeom that can be used as part of an
  10549. ** R-Tree geometry query as follows:
  10550. **
  10551. ** SELECT ... FROM <rtree> WHERE <rtree col> MATCH $zGeom(... params ...)
  10552. */
  10553. SQLITE_API int sqlite3_rtree_geometry_callback(
  10554. sqlite3 *db,
  10555. const char *zGeom,
  10556. int (*xGeom)(sqlite3_rtree_geometry*, int, sqlite3_rtree_dbl*,int*),
  10557. void *pContext
  10558. );
  10559. /*
  10560. ** A pointer to a structure of the following type is passed as the first
  10561. ** argument to callbacks registered using rtree_geometry_callback().
  10562. */
  10563. struct sqlite3_rtree_geometry {
  10564. void *pContext; /* Copy of pContext passed to s_r_g_c() */
  10565. int nParam; /* Size of array aParam[] */
  10566. sqlite3_rtree_dbl *aParam; /* Parameters passed to SQL geom function */
  10567. void *pUser; /* Callback implementation user data */
  10568. void (*xDelUser)(void *); /* Called by SQLite to clean up pUser */
  10569. };
  10570. /*
  10571. ** Register a 2nd-generation geometry callback named zScore that can be
  10572. ** used as part of an R-Tree geometry query as follows:
  10573. **
  10574. ** SELECT ... FROM <rtree> WHERE <rtree col> MATCH $zQueryFunc(... params ...)
  10575. */
  10576. SQLITE_API int sqlite3_rtree_query_callback(
  10577. sqlite3 *db,
  10578. const char *zQueryFunc,
  10579. int (*xQueryFunc)(sqlite3_rtree_query_info*),
  10580. void *pContext,
  10581. void (*xDestructor)(void*)
  10582. );
  10583. /*
  10584. ** A pointer to a structure of the following type is passed as the
  10585. ** argument to scored geometry callback registered using
  10586. ** sqlite3_rtree_query_callback().
  10587. **
  10588. ** Note that the first 5 fields of this structure are identical to
  10589. ** sqlite3_rtree_geometry. This structure is a subclass of
  10590. ** sqlite3_rtree_geometry.
  10591. */
  10592. struct sqlite3_rtree_query_info {
  10593. void *pContext; /* pContext from when function registered */
  10594. int nParam; /* Number of function parameters */
  10595. sqlite3_rtree_dbl *aParam; /* value of function parameters */
  10596. void *pUser; /* callback can use this, if desired */
  10597. void (*xDelUser)(void*); /* function to free pUser */
  10598. sqlite3_rtree_dbl *aCoord; /* Coordinates of node or entry to check */
  10599. unsigned int *anQueue; /* Number of pending entries in the queue */
  10600. int nCoord; /* Number of coordinates */
  10601. int iLevel; /* Level of current node or entry */
  10602. int mxLevel; /* The largest iLevel value in the tree */
  10603. sqlite3_int64 iRowid; /* Rowid for current entry */
  10604. sqlite3_rtree_dbl rParentScore; /* Score of parent node */
  10605. int eParentWithin; /* Visibility of parent node */
  10606. int eWithin; /* OUT: Visibility */
  10607. sqlite3_rtree_dbl rScore; /* OUT: Write the score here */
  10608. /* The following fields are only available in 3.8.11 and later */
  10609. sqlite3_value **apSqlParam; /* Original SQL values of parameters */
  10610. };
  10611. /*
  10612. ** Allowed values for sqlite3_rtree_query.eWithin and .eParentWithin.
  10613. */
  10614. #define NOT_WITHIN 0 /* Object completely outside of query region */
  10615. #define PARTLY_WITHIN 1 /* Object partially overlaps query region */
  10616. #define FULLY_WITHIN 2 /* Object fully contained within query region */
  10617. #ifdef __cplusplus
  10618. } /* end of the 'extern "C"' block */
  10619. #endif
  10620. #endif /* ifndef _SQLITE3RTREE_H_ */
  10621. /******** End of sqlite3rtree.h *********/
  10622. /******** Begin file sqlite3session.h *********/
  10623. #if !defined(__SQLITESESSION_H_) && defined(SQLITE_ENABLE_SESSION)
  10624. #define __SQLITESESSION_H_ 1
  10625. /*
  10626. ** Make sure we can call this stuff from C++.
  10627. */
  10628. #ifdef __cplusplus
  10629. extern "C" {
  10630. #endif
  10631. /*
  10632. ** CAPI3REF: Session Object Handle
  10633. **
  10634. ** An instance of this object is a [session] that can be used to
  10635. ** record changes to a database.
  10636. */
  10637. typedef struct sqlite3_session sqlite3_session;
  10638. /*
  10639. ** CAPI3REF: Changeset Iterator Handle
  10640. **
  10641. ** An instance of this object acts as a cursor for iterating
  10642. ** over the elements of a [changeset] or [patchset].
  10643. */
  10644. typedef struct sqlite3_changeset_iter sqlite3_changeset_iter;
  10645. /*
  10646. ** CAPI3REF: Create A New Session Object
  10647. ** CONSTRUCTOR: sqlite3_session
  10648. **
  10649. ** Create a new session object attached to database handle db. If successful,
  10650. ** a pointer to the new object is written to *ppSession and SQLITE_OK is
  10651. ** returned. If an error occurs, *ppSession is set to NULL and an SQLite
  10652. ** error code (e.g. SQLITE_NOMEM) is returned.
  10653. **
  10654. ** It is possible to create multiple session objects attached to a single
  10655. ** database handle.
  10656. **
  10657. ** Session objects created using this function should be deleted using the
  10658. ** [sqlite3session_delete()] function before the database handle that they
  10659. ** are attached to is itself closed. If the database handle is closed before
  10660. ** the session object is deleted, then the results of calling any session
  10661. ** module function, including [sqlite3session_delete()] on the session object
  10662. ** are undefined.
  10663. **
  10664. ** Because the session module uses the [sqlite3_preupdate_hook()] API, it
  10665. ** is not possible for an application to register a pre-update hook on a
  10666. ** database handle that has one or more session objects attached. Nor is
  10667. ** it possible to create a session object attached to a database handle for
  10668. ** which a pre-update hook is already defined. The results of attempting
  10669. ** either of these things are undefined.
  10670. **
  10671. ** The session object will be used to create changesets for tables in
  10672. ** database zDb, where zDb is either "main", or "temp", or the name of an
  10673. ** attached database. It is not an error if database zDb is not attached
  10674. ** to the database when the session object is created.
  10675. */
  10676. SQLITE_API int sqlite3session_create(
  10677. sqlite3 *db, /* Database handle */
  10678. const char *zDb, /* Name of db (e.g. "main") */
  10679. sqlite3_session **ppSession /* OUT: New session object */
  10680. );
  10681. /*
  10682. ** CAPI3REF: Delete A Session Object
  10683. ** DESTRUCTOR: sqlite3_session
  10684. **
  10685. ** Delete a session object previously allocated using
  10686. ** [sqlite3session_create()]. Once a session object has been deleted, the
  10687. ** results of attempting to use pSession with any other session module
  10688. ** function are undefined.
  10689. **
  10690. ** Session objects must be deleted before the database handle to which they
  10691. ** are attached is closed. Refer to the documentation for
  10692. ** [sqlite3session_create()] for details.
  10693. */
  10694. SQLITE_API void sqlite3session_delete(sqlite3_session *pSession);
  10695. /*
  10696. ** CAPI3REF: Configure a Session Object
  10697. ** METHOD: sqlite3_session
  10698. **
  10699. ** This method is used to configure a session object after it has been
  10700. ** created. At present the only valid values for the second parameter are
  10701. ** [SQLITE_SESSION_OBJCONFIG_SIZE] and [SQLITE_SESSION_OBJCONFIG_ROWID].
  10702. **
  10703. */
  10704. SQLITE_API int sqlite3session_object_config(sqlite3_session*, int op, void *pArg);
  10705. /*
  10706. ** CAPI3REF: Options for sqlite3session_object_config
  10707. **
  10708. ** The following values may passed as the the 2nd parameter to
  10709. ** sqlite3session_object_config().
  10710. **
  10711. ** <dt>SQLITE_SESSION_OBJCONFIG_SIZE <dd>
  10712. ** This option is used to set, clear or query the flag that enables
  10713. ** the [sqlite3session_changeset_size()] API. Because it imposes some
  10714. ** computational overhead, this API is disabled by default. Argument
  10715. ** pArg must point to a value of type (int). If the value is initially
  10716. ** 0, then the sqlite3session_changeset_size() API is disabled. If it
  10717. ** is greater than 0, then the same API is enabled. Or, if the initial
  10718. ** value is less than zero, no change is made. In all cases the (int)
  10719. ** variable is set to 1 if the sqlite3session_changeset_size() API is
  10720. ** enabled following the current call, or 0 otherwise.
  10721. **
  10722. ** It is an error (SQLITE_MISUSE) to attempt to modify this setting after
  10723. ** the first table has been attached to the session object.
  10724. **
  10725. ** <dt>SQLITE_SESSION_OBJCONFIG_ROWID <dd>
  10726. ** This option is used to set, clear or query the flag that enables
  10727. ** collection of data for tables with no explicit PRIMARY KEY.
  10728. **
  10729. ** Normally, tables with no explicit PRIMARY KEY are simply ignored
  10730. ** by the sessions module. However, if this flag is set, it behaves
  10731. ** as if such tables have a column "_rowid_ INTEGER PRIMARY KEY" inserted
  10732. ** as their leftmost columns.
  10733. **
  10734. ** It is an error (SQLITE_MISUSE) to attempt to modify this setting after
  10735. ** the first table has been attached to the session object.
  10736. */
  10737. #define SQLITE_SESSION_OBJCONFIG_SIZE 1
  10738. #define SQLITE_SESSION_OBJCONFIG_ROWID 2
  10739. /*
  10740. ** CAPI3REF: Enable Or Disable A Session Object
  10741. ** METHOD: sqlite3_session
  10742. **
  10743. ** Enable or disable the recording of changes by a session object. When
  10744. ** enabled, a session object records changes made to the database. When
  10745. ** disabled - it does not. A newly created session object is enabled.
  10746. ** Refer to the documentation for [sqlite3session_changeset()] for further
  10747. ** details regarding how enabling and disabling a session object affects
  10748. ** the eventual changesets.
  10749. **
  10750. ** Passing zero to this function disables the session. Passing a value
  10751. ** greater than zero enables it. Passing a value less than zero is a
  10752. ** no-op, and may be used to query the current state of the session.
  10753. **
  10754. ** The return value indicates the final state of the session object: 0 if
  10755. ** the session is disabled, or 1 if it is enabled.
  10756. */
  10757. SQLITE_API int sqlite3session_enable(sqlite3_session *pSession, int bEnable);
  10758. /*
  10759. ** CAPI3REF: Set Or Clear the Indirect Change Flag
  10760. ** METHOD: sqlite3_session
  10761. **
  10762. ** Each change recorded by a session object is marked as either direct or
  10763. ** indirect. A change is marked as indirect if either:
  10764. **
  10765. ** <ul>
  10766. ** <li> The session object "indirect" flag is set when the change is
  10767. ** made, or
  10768. ** <li> The change is made by an SQL trigger or foreign key action
  10769. ** instead of directly as a result of a users SQL statement.
  10770. ** </ul>
  10771. **
  10772. ** If a single row is affected by more than one operation within a session,
  10773. ** then the change is considered indirect if all operations meet the criteria
  10774. ** for an indirect change above, or direct otherwise.
  10775. **
  10776. ** This function is used to set, clear or query the session object indirect
  10777. ** flag. If the second argument passed to this function is zero, then the
  10778. ** indirect flag is cleared. If it is greater than zero, the indirect flag
  10779. ** is set. Passing a value less than zero does not modify the current value
  10780. ** of the indirect flag, and may be used to query the current state of the
  10781. ** indirect flag for the specified session object.
  10782. **
  10783. ** The return value indicates the final state of the indirect flag: 0 if
  10784. ** it is clear, or 1 if it is set.
  10785. */
  10786. SQLITE_API int sqlite3session_indirect(sqlite3_session *pSession, int bIndirect);
  10787. /*
  10788. ** CAPI3REF: Attach A Table To A Session Object
  10789. ** METHOD: sqlite3_session
  10790. **
  10791. ** If argument zTab is not NULL, then it is the name of a table to attach
  10792. ** to the session object passed as the first argument. All subsequent changes
  10793. ** made to the table while the session object is enabled will be recorded. See
  10794. ** documentation for [sqlite3session_changeset()] for further details.
  10795. **
  10796. ** Or, if argument zTab is NULL, then changes are recorded for all tables
  10797. ** in the database. If additional tables are added to the database (by
  10798. ** executing "CREATE TABLE" statements) after this call is made, changes for
  10799. ** the new tables are also recorded.
  10800. **
  10801. ** Changes can only be recorded for tables that have a PRIMARY KEY explicitly
  10802. ** defined as part of their CREATE TABLE statement. It does not matter if the
  10803. ** PRIMARY KEY is an "INTEGER PRIMARY KEY" (rowid alias) or not. The PRIMARY
  10804. ** KEY may consist of a single column, or may be a composite key.
  10805. **
  10806. ** It is not an error if the named table does not exist in the database. Nor
  10807. ** is it an error if the named table does not have a PRIMARY KEY. However,
  10808. ** no changes will be recorded in either of these scenarios.
  10809. **
  10810. ** Changes are not recorded for individual rows that have NULL values stored
  10811. ** in one or more of their PRIMARY KEY columns.
  10812. **
  10813. ** SQLITE_OK is returned if the call completes without error. Or, if an error
  10814. ** occurs, an SQLite error code (e.g. SQLITE_NOMEM) is returned.
  10815. **
  10816. ** <h3>Special sqlite_stat1 Handling</h3>
  10817. **
  10818. ** As of SQLite version 3.22.0, the "sqlite_stat1" table is an exception to
  10819. ** some of the rules above. In SQLite, the schema of sqlite_stat1 is:
  10820. ** <pre>
  10821. ** &nbsp; CREATE TABLE sqlite_stat1(tbl,idx,stat)
  10822. ** </pre>
  10823. **
  10824. ** Even though sqlite_stat1 does not have a PRIMARY KEY, changes are
  10825. ** recorded for it as if the PRIMARY KEY is (tbl,idx). Additionally, changes
  10826. ** are recorded for rows for which (idx IS NULL) is true. However, for such
  10827. ** rows a zero-length blob (SQL value X'') is stored in the changeset or
  10828. ** patchset instead of a NULL value. This allows such changesets to be
  10829. ** manipulated by legacy implementations of sqlite3changeset_invert(),
  10830. ** concat() and similar.
  10831. **
  10832. ** The sqlite3changeset_apply() function automatically converts the
  10833. ** zero-length blob back to a NULL value when updating the sqlite_stat1
  10834. ** table. However, if the application calls sqlite3changeset_new(),
  10835. ** sqlite3changeset_old() or sqlite3changeset_conflict on a changeset
  10836. ** iterator directly (including on a changeset iterator passed to a
  10837. ** conflict-handler callback) then the X'' value is returned. The application
  10838. ** must translate X'' to NULL itself if required.
  10839. **
  10840. ** Legacy (older than 3.22.0) versions of the sessions module cannot capture
  10841. ** changes made to the sqlite_stat1 table. Legacy versions of the
  10842. ** sqlite3changeset_apply() function silently ignore any modifications to the
  10843. ** sqlite_stat1 table that are part of a changeset or patchset.
  10844. */
  10845. SQLITE_API int sqlite3session_attach(
  10846. sqlite3_session *pSession, /* Session object */
  10847. const char *zTab /* Table name */
  10848. );
  10849. /*
  10850. ** CAPI3REF: Set a table filter on a Session Object.
  10851. ** METHOD: sqlite3_session
  10852. **
  10853. ** The second argument (xFilter) is the "filter callback". For changes to rows
  10854. ** in tables that are not attached to the Session object, the filter is called
  10855. ** to determine whether changes to the table's rows should be tracked or not.
  10856. ** If xFilter returns 0, changes are not tracked. Note that once a table is
  10857. ** attached, xFilter will not be called again.
  10858. */
  10859. SQLITE_API void sqlite3session_table_filter(
  10860. sqlite3_session *pSession, /* Session object */
  10861. int(*xFilter)(
  10862. void *pCtx, /* Copy of third arg to _filter_table() */
  10863. const char *zTab /* Table name */
  10864. ),
  10865. void *pCtx /* First argument passed to xFilter */
  10866. );
  10867. /*
  10868. ** CAPI3REF: Generate A Changeset From A Session Object
  10869. ** METHOD: sqlite3_session
  10870. **
  10871. ** Obtain a changeset containing changes to the tables attached to the
  10872. ** session object passed as the first argument. If successful,
  10873. ** set *ppChangeset to point to a buffer containing the changeset
  10874. ** and *pnChangeset to the size of the changeset in bytes before returning
  10875. ** SQLITE_OK. If an error occurs, set both *ppChangeset and *pnChangeset to
  10876. ** zero and return an SQLite error code.
  10877. **
  10878. ** A changeset consists of zero or more INSERT, UPDATE and/or DELETE changes,
  10879. ** each representing a change to a single row of an attached table. An INSERT
  10880. ** change contains the values of each field of a new database row. A DELETE
  10881. ** contains the original values of each field of a deleted database row. An
  10882. ** UPDATE change contains the original values of each field of an updated
  10883. ** database row along with the updated values for each updated non-primary-key
  10884. ** column. It is not possible for an UPDATE change to represent a change that
  10885. ** modifies the values of primary key columns. If such a change is made, it
  10886. ** is represented in a changeset as a DELETE followed by an INSERT.
  10887. **
  10888. ** Changes are not recorded for rows that have NULL values stored in one or
  10889. ** more of their PRIMARY KEY columns. If such a row is inserted or deleted,
  10890. ** no corresponding change is present in the changesets returned by this
  10891. ** function. If an existing row with one or more NULL values stored in
  10892. ** PRIMARY KEY columns is updated so that all PRIMARY KEY columns are non-NULL,
  10893. ** only an INSERT is appears in the changeset. Similarly, if an existing row
  10894. ** with non-NULL PRIMARY KEY values is updated so that one or more of its
  10895. ** PRIMARY KEY columns are set to NULL, the resulting changeset contains a
  10896. ** DELETE change only.
  10897. **
  10898. ** The contents of a changeset may be traversed using an iterator created
  10899. ** using the [sqlite3changeset_start()] API. A changeset may be applied to
  10900. ** a database with a compatible schema using the [sqlite3changeset_apply()]
  10901. ** API.
  10902. **
  10903. ** Within a changeset generated by this function, all changes related to a
  10904. ** single table are grouped together. In other words, when iterating through
  10905. ** a changeset or when applying a changeset to a database, all changes related
  10906. ** to a single table are processed before moving on to the next table. Tables
  10907. ** are sorted in the same order in which they were attached (or auto-attached)
  10908. ** to the sqlite3_session object. The order in which the changes related to
  10909. ** a single table are stored is undefined.
  10910. **
  10911. ** Following a successful call to this function, it is the responsibility of
  10912. ** the caller to eventually free the buffer that *ppChangeset points to using
  10913. ** [sqlite3_free()].
  10914. **
  10915. ** <h3>Changeset Generation</h3>
  10916. **
  10917. ** Once a table has been attached to a session object, the session object
  10918. ** records the primary key values of all new rows inserted into the table.
  10919. ** It also records the original primary key and other column values of any
  10920. ** deleted or updated rows. For each unique primary key value, data is only
  10921. ** recorded once - the first time a row with said primary key is inserted,
  10922. ** updated or deleted in the lifetime of the session.
  10923. **
  10924. ** There is one exception to the previous paragraph: when a row is inserted,
  10925. ** updated or deleted, if one or more of its primary key columns contain a
  10926. ** NULL value, no record of the change is made.
  10927. **
  10928. ** The session object therefore accumulates two types of records - those
  10929. ** that consist of primary key values only (created when the user inserts
  10930. ** a new record) and those that consist of the primary key values and the
  10931. ** original values of other table columns (created when the users deletes
  10932. ** or updates a record).
  10933. **
  10934. ** When this function is called, the requested changeset is created using
  10935. ** both the accumulated records and the current contents of the database
  10936. ** file. Specifically:
  10937. **
  10938. ** <ul>
  10939. ** <li> For each record generated by an insert, the database is queried
  10940. ** for a row with a matching primary key. If one is found, an INSERT
  10941. ** change is added to the changeset. If no such row is found, no change
  10942. ** is added to the changeset.
  10943. **
  10944. ** <li> For each record generated by an update or delete, the database is
  10945. ** queried for a row with a matching primary key. If such a row is
  10946. ** found and one or more of the non-primary key fields have been
  10947. ** modified from their original values, an UPDATE change is added to
  10948. ** the changeset. Or, if no such row is found in the table, a DELETE
  10949. ** change is added to the changeset. If there is a row with a matching
  10950. ** primary key in the database, but all fields contain their original
  10951. ** values, no change is added to the changeset.
  10952. ** </ul>
  10953. **
  10954. ** This means, amongst other things, that if a row is inserted and then later
  10955. ** deleted while a session object is active, neither the insert nor the delete
  10956. ** will be present in the changeset. Or if a row is deleted and then later a
  10957. ** row with the same primary key values inserted while a session object is
  10958. ** active, the resulting changeset will contain an UPDATE change instead of
  10959. ** a DELETE and an INSERT.
  10960. **
  10961. ** When a session object is disabled (see the [sqlite3session_enable()] API),
  10962. ** it does not accumulate records when rows are inserted, updated or deleted.
  10963. ** This may appear to have some counter-intuitive effects if a single row
  10964. ** is written to more than once during a session. For example, if a row
  10965. ** is inserted while a session object is enabled, then later deleted while
  10966. ** the same session object is disabled, no INSERT record will appear in the
  10967. ** changeset, even though the delete took place while the session was disabled.
  10968. ** Or, if one field of a row is updated while a session is disabled, and
  10969. ** another field of the same row is updated while the session is enabled, the
  10970. ** resulting changeset will contain an UPDATE change that updates both fields.
  10971. */
  10972. SQLITE_API int sqlite3session_changeset(
  10973. sqlite3_session *pSession, /* Session object */
  10974. int *pnChangeset, /* OUT: Size of buffer at *ppChangeset */
  10975. void **ppChangeset /* OUT: Buffer containing changeset */
  10976. );
  10977. /*
  10978. ** CAPI3REF: Return An Upper-limit For The Size Of The Changeset
  10979. ** METHOD: sqlite3_session
  10980. **
  10981. ** By default, this function always returns 0. For it to return
  10982. ** a useful result, the sqlite3_session object must have been configured
  10983. ** to enable this API using sqlite3session_object_config() with the
  10984. ** SQLITE_SESSION_OBJCONFIG_SIZE verb.
  10985. **
  10986. ** When enabled, this function returns an upper limit, in bytes, for the size
  10987. ** of the changeset that might be produced if sqlite3session_changeset() were
  10988. ** called. The final changeset size might be equal to or smaller than the
  10989. ** size in bytes returned by this function.
  10990. */
  10991. SQLITE_API sqlite3_int64 sqlite3session_changeset_size(sqlite3_session *pSession);
  10992. /*
  10993. ** CAPI3REF: Load The Difference Between Tables Into A Session
  10994. ** METHOD: sqlite3_session
  10995. **
  10996. ** If it is not already attached to the session object passed as the first
  10997. ** argument, this function attaches table zTbl in the same manner as the
  10998. ** [sqlite3session_attach()] function. If zTbl does not exist, or if it
  10999. ** does not have a primary key, this function is a no-op (but does not return
  11000. ** an error).
  11001. **
  11002. ** Argument zFromDb must be the name of a database ("main", "temp" etc.)
  11003. ** attached to the same database handle as the session object that contains
  11004. ** a table compatible with the table attached to the session by this function.
  11005. ** A table is considered compatible if it:
  11006. **
  11007. ** <ul>
  11008. ** <li> Has the same name,
  11009. ** <li> Has the same set of columns declared in the same order, and
  11010. ** <li> Has the same PRIMARY KEY definition.
  11011. ** </ul>
  11012. **
  11013. ** If the tables are not compatible, SQLITE_SCHEMA is returned. If the tables
  11014. ** are compatible but do not have any PRIMARY KEY columns, it is not an error
  11015. ** but no changes are added to the session object. As with other session
  11016. ** APIs, tables without PRIMARY KEYs are simply ignored.
  11017. **
  11018. ** This function adds a set of changes to the session object that could be
  11019. ** used to update the table in database zFrom (call this the "from-table")
  11020. ** so that its content is the same as the table attached to the session
  11021. ** object (call this the "to-table"). Specifically:
  11022. **
  11023. ** <ul>
  11024. ** <li> For each row (primary key) that exists in the to-table but not in
  11025. ** the from-table, an INSERT record is added to the session object.
  11026. **
  11027. ** <li> For each row (primary key) that exists in the to-table but not in
  11028. ** the from-table, a DELETE record is added to the session object.
  11029. **
  11030. ** <li> For each row (primary key) that exists in both tables, but features
  11031. ** different non-PK values in each, an UPDATE record is added to the
  11032. ** session.
  11033. ** </ul>
  11034. **
  11035. ** To clarify, if this function is called and then a changeset constructed
  11036. ** using [sqlite3session_changeset()], then after applying that changeset to
  11037. ** database zFrom the contents of the two compatible tables would be
  11038. ** identical.
  11039. **
  11040. ** It an error if database zFrom does not exist or does not contain the
  11041. ** required compatible table.
  11042. **
  11043. ** If the operation is successful, SQLITE_OK is returned. Otherwise, an SQLite
  11044. ** error code. In this case, if argument pzErrMsg is not NULL, *pzErrMsg
  11045. ** may be set to point to a buffer containing an English language error
  11046. ** message. It is the responsibility of the caller to free this buffer using
  11047. ** sqlite3_free().
  11048. */
  11049. SQLITE_API int sqlite3session_diff(
  11050. sqlite3_session *pSession,
  11051. const char *zFromDb,
  11052. const char *zTbl,
  11053. char **pzErrMsg
  11054. );
  11055. /*
  11056. ** CAPI3REF: Generate A Patchset From A Session Object
  11057. ** METHOD: sqlite3_session
  11058. **
  11059. ** The differences between a patchset and a changeset are that:
  11060. **
  11061. ** <ul>
  11062. ** <li> DELETE records consist of the primary key fields only. The
  11063. ** original values of other fields are omitted.
  11064. ** <li> The original values of any modified fields are omitted from
  11065. ** UPDATE records.
  11066. ** </ul>
  11067. **
  11068. ** A patchset blob may be used with up to date versions of all
  11069. ** sqlite3changeset_xxx API functions except for sqlite3changeset_invert(),
  11070. ** which returns SQLITE_CORRUPT if it is passed a patchset. Similarly,
  11071. ** attempting to use a patchset blob with old versions of the
  11072. ** sqlite3changeset_xxx APIs also provokes an SQLITE_CORRUPT error.
  11073. **
  11074. ** Because the non-primary key "old.*" fields are omitted, no
  11075. ** SQLITE_CHANGESET_DATA conflicts can be detected or reported if a patchset
  11076. ** is passed to the sqlite3changeset_apply() API. Other conflict types work
  11077. ** in the same way as for changesets.
  11078. **
  11079. ** Changes within a patchset are ordered in the same way as for changesets
  11080. ** generated by the sqlite3session_changeset() function (i.e. all changes for
  11081. ** a single table are grouped together, tables appear in the order in which
  11082. ** they were attached to the session object).
  11083. */
  11084. SQLITE_API int sqlite3session_patchset(
  11085. sqlite3_session *pSession, /* Session object */
  11086. int *pnPatchset, /* OUT: Size of buffer at *ppPatchset */
  11087. void **ppPatchset /* OUT: Buffer containing patchset */
  11088. );
  11089. /*
  11090. ** CAPI3REF: Test if a changeset has recorded any changes.
  11091. **
  11092. ** Return non-zero if no changes to attached tables have been recorded by
  11093. ** the session object passed as the first argument. Otherwise, if one or
  11094. ** more changes have been recorded, return zero.
  11095. **
  11096. ** Even if this function returns zero, it is possible that calling
  11097. ** [sqlite3session_changeset()] on the session handle may still return a
  11098. ** changeset that contains no changes. This can happen when a row in
  11099. ** an attached table is modified and then later on the original values
  11100. ** are restored. However, if this function returns non-zero, then it is
  11101. ** guaranteed that a call to sqlite3session_changeset() will return a
  11102. ** changeset containing zero changes.
  11103. */
  11104. SQLITE_API int sqlite3session_isempty(sqlite3_session *pSession);
  11105. /*
  11106. ** CAPI3REF: Query for the amount of heap memory used by a session object.
  11107. **
  11108. ** This API returns the total amount of heap memory in bytes currently
  11109. ** used by the session object passed as the only argument.
  11110. */
  11111. SQLITE_API sqlite3_int64 sqlite3session_memory_used(sqlite3_session *pSession);
  11112. /*
  11113. ** CAPI3REF: Create An Iterator To Traverse A Changeset
  11114. ** CONSTRUCTOR: sqlite3_changeset_iter
  11115. **
  11116. ** Create an iterator used to iterate through the contents of a changeset.
  11117. ** If successful, *pp is set to point to the iterator handle and SQLITE_OK
  11118. ** is returned. Otherwise, if an error occurs, *pp is set to zero and an
  11119. ** SQLite error code is returned.
  11120. **
  11121. ** The following functions can be used to advance and query a changeset
  11122. ** iterator created by this function:
  11123. **
  11124. ** <ul>
  11125. ** <li> [sqlite3changeset_next()]
  11126. ** <li> [sqlite3changeset_op()]
  11127. ** <li> [sqlite3changeset_new()]
  11128. ** <li> [sqlite3changeset_old()]
  11129. ** </ul>
  11130. **
  11131. ** It is the responsibility of the caller to eventually destroy the iterator
  11132. ** by passing it to [sqlite3changeset_finalize()]. The buffer containing the
  11133. ** changeset (pChangeset) must remain valid until after the iterator is
  11134. ** destroyed.
  11135. **
  11136. ** Assuming the changeset blob was created by one of the
  11137. ** [sqlite3session_changeset()], [sqlite3changeset_concat()] or
  11138. ** [sqlite3changeset_invert()] functions, all changes within the changeset
  11139. ** that apply to a single table are grouped together. This means that when
  11140. ** an application iterates through a changeset using an iterator created by
  11141. ** this function, all changes that relate to a single table are visited
  11142. ** consecutively. There is no chance that the iterator will visit a change
  11143. ** the applies to table X, then one for table Y, and then later on visit
  11144. ** another change for table X.
  11145. **
  11146. ** The behavior of sqlite3changeset_start_v2() and its streaming equivalent
  11147. ** may be modified by passing a combination of
  11148. ** [SQLITE_CHANGESETSTART_INVERT | supported flags] as the 4th parameter.
  11149. **
  11150. ** Note that the sqlite3changeset_start_v2() API is still <b>experimental</b>
  11151. ** and therefore subject to change.
  11152. */
  11153. SQLITE_API int sqlite3changeset_start(
  11154. sqlite3_changeset_iter **pp, /* OUT: New changeset iterator handle */
  11155. int nChangeset, /* Size of changeset blob in bytes */
  11156. void *pChangeset /* Pointer to blob containing changeset */
  11157. );
  11158. SQLITE_API int sqlite3changeset_start_v2(
  11159. sqlite3_changeset_iter **pp, /* OUT: New changeset iterator handle */
  11160. int nChangeset, /* Size of changeset blob in bytes */
  11161. void *pChangeset, /* Pointer to blob containing changeset */
  11162. int flags /* SESSION_CHANGESETSTART_* flags */
  11163. );
  11164. /*
  11165. ** CAPI3REF: Flags for sqlite3changeset_start_v2
  11166. **
  11167. ** The following flags may passed via the 4th parameter to
  11168. ** [sqlite3changeset_start_v2] and [sqlite3changeset_start_v2_strm]:
  11169. **
  11170. ** <dt>SQLITE_CHANGESETAPPLY_INVERT <dd>
  11171. ** Invert the changeset while iterating through it. This is equivalent to
  11172. ** inverting a changeset using sqlite3changeset_invert() before applying it.
  11173. ** It is an error to specify this flag with a patchset.
  11174. */
  11175. #define SQLITE_CHANGESETSTART_INVERT 0x0002
  11176. /*
  11177. ** CAPI3REF: Advance A Changeset Iterator
  11178. ** METHOD: sqlite3_changeset_iter
  11179. **
  11180. ** This function may only be used with iterators created by the function
  11181. ** [sqlite3changeset_start()]. If it is called on an iterator passed to
  11182. ** a conflict-handler callback by [sqlite3changeset_apply()], SQLITE_MISUSE
  11183. ** is returned and the call has no effect.
  11184. **
  11185. ** Immediately after an iterator is created by sqlite3changeset_start(), it
  11186. ** does not point to any change in the changeset. Assuming the changeset
  11187. ** is not empty, the first call to this function advances the iterator to
  11188. ** point to the first change in the changeset. Each subsequent call advances
  11189. ** the iterator to point to the next change in the changeset (if any). If
  11190. ** no error occurs and the iterator points to a valid change after a call
  11191. ** to sqlite3changeset_next() has advanced it, SQLITE_ROW is returned.
  11192. ** Otherwise, if all changes in the changeset have already been visited,
  11193. ** SQLITE_DONE is returned.
  11194. **
  11195. ** If an error occurs, an SQLite error code is returned. Possible error
  11196. ** codes include SQLITE_CORRUPT (if the changeset buffer is corrupt) or
  11197. ** SQLITE_NOMEM.
  11198. */
  11199. SQLITE_API int sqlite3changeset_next(sqlite3_changeset_iter *pIter);
  11200. /*
  11201. ** CAPI3REF: Obtain The Current Operation From A Changeset Iterator
  11202. ** METHOD: sqlite3_changeset_iter
  11203. **
  11204. ** The pIter argument passed to this function may either be an iterator
  11205. ** passed to a conflict-handler by [sqlite3changeset_apply()], or an iterator
  11206. ** created by [sqlite3changeset_start()]. In the latter case, the most recent
  11207. ** call to [sqlite3changeset_next()] must have returned [SQLITE_ROW]. If this
  11208. ** is not the case, this function returns [SQLITE_MISUSE].
  11209. **
  11210. ** Arguments pOp, pnCol and pzTab may not be NULL. Upon return, three
  11211. ** outputs are set through these pointers:
  11212. **
  11213. ** *pOp is set to one of [SQLITE_INSERT], [SQLITE_DELETE] or [SQLITE_UPDATE],
  11214. ** depending on the type of change that the iterator currently points to;
  11215. **
  11216. ** *pnCol is set to the number of columns in the table affected by the change; and
  11217. **
  11218. ** *pzTab is set to point to a nul-terminated utf-8 encoded string containing
  11219. ** the name of the table affected by the current change. The buffer remains
  11220. ** valid until either sqlite3changeset_next() is called on the iterator
  11221. ** or until the conflict-handler function returns.
  11222. **
  11223. ** If pbIndirect is not NULL, then *pbIndirect is set to true (1) if the change
  11224. ** is an indirect change, or false (0) otherwise. See the documentation for
  11225. ** [sqlite3session_indirect()] for a description of direct and indirect
  11226. ** changes.
  11227. **
  11228. ** If no error occurs, SQLITE_OK is returned. If an error does occur, an
  11229. ** SQLite error code is returned. The values of the output variables may not
  11230. ** be trusted in this case.
  11231. */
  11232. SQLITE_API int sqlite3changeset_op(
  11233. sqlite3_changeset_iter *pIter, /* Iterator object */
  11234. const char **pzTab, /* OUT: Pointer to table name */
  11235. int *pnCol, /* OUT: Number of columns in table */
  11236. int *pOp, /* OUT: SQLITE_INSERT, DELETE or UPDATE */
  11237. int *pbIndirect /* OUT: True for an 'indirect' change */
  11238. );
  11239. /*
  11240. ** CAPI3REF: Obtain The Primary Key Definition Of A Table
  11241. ** METHOD: sqlite3_changeset_iter
  11242. **
  11243. ** For each modified table, a changeset includes the following:
  11244. **
  11245. ** <ul>
  11246. ** <li> The number of columns in the table, and
  11247. ** <li> Which of those columns make up the tables PRIMARY KEY.
  11248. ** </ul>
  11249. **
  11250. ** This function is used to find which columns comprise the PRIMARY KEY of
  11251. ** the table modified by the change that iterator pIter currently points to.
  11252. ** If successful, *pabPK is set to point to an array of nCol entries, where
  11253. ** nCol is the number of columns in the table. Elements of *pabPK are set to
  11254. ** 0x01 if the corresponding column is part of the tables primary key, or
  11255. ** 0x00 if it is not.
  11256. **
  11257. ** If argument pnCol is not NULL, then *pnCol is set to the number of columns
  11258. ** in the table.
  11259. **
  11260. ** If this function is called when the iterator does not point to a valid
  11261. ** entry, SQLITE_MISUSE is returned and the output variables zeroed. Otherwise,
  11262. ** SQLITE_OK is returned and the output variables populated as described
  11263. ** above.
  11264. */
  11265. SQLITE_API int sqlite3changeset_pk(
  11266. sqlite3_changeset_iter *pIter, /* Iterator object */
  11267. unsigned char **pabPK, /* OUT: Array of boolean - true for PK cols */
  11268. int *pnCol /* OUT: Number of entries in output array */
  11269. );
  11270. /*
  11271. ** CAPI3REF: Obtain old.* Values From A Changeset Iterator
  11272. ** METHOD: sqlite3_changeset_iter
  11273. **
  11274. ** The pIter argument passed to this function may either be an iterator
  11275. ** passed to a conflict-handler by [sqlite3changeset_apply()], or an iterator
  11276. ** created by [sqlite3changeset_start()]. In the latter case, the most recent
  11277. ** call to [sqlite3changeset_next()] must have returned SQLITE_ROW.
  11278. ** Furthermore, it may only be called if the type of change that the iterator
  11279. ** currently points to is either [SQLITE_DELETE] or [SQLITE_UPDATE]. Otherwise,
  11280. ** this function returns [SQLITE_MISUSE] and sets *ppValue to NULL.
  11281. **
  11282. ** Argument iVal must be greater than or equal to 0, and less than the number
  11283. ** of columns in the table affected by the current change. Otherwise,
  11284. ** [SQLITE_RANGE] is returned and *ppValue is set to NULL.
  11285. **
  11286. ** If successful, this function sets *ppValue to point to a protected
  11287. ** sqlite3_value object containing the iVal'th value from the vector of
  11288. ** original row values stored as part of the UPDATE or DELETE change and
  11289. ** returns SQLITE_OK. The name of the function comes from the fact that this
  11290. ** is similar to the "old.*" columns available to update or delete triggers.
  11291. **
  11292. ** If some other error occurs (e.g. an OOM condition), an SQLite error code
  11293. ** is returned and *ppValue is set to NULL.
  11294. */
  11295. SQLITE_API int sqlite3changeset_old(
  11296. sqlite3_changeset_iter *pIter, /* Changeset iterator */
  11297. int iVal, /* Column number */
  11298. sqlite3_value **ppValue /* OUT: Old value (or NULL pointer) */
  11299. );
  11300. /*
  11301. ** CAPI3REF: Obtain new.* Values From A Changeset Iterator
  11302. ** METHOD: sqlite3_changeset_iter
  11303. **
  11304. ** The pIter argument passed to this function may either be an iterator
  11305. ** passed to a conflict-handler by [sqlite3changeset_apply()], or an iterator
  11306. ** created by [sqlite3changeset_start()]. In the latter case, the most recent
  11307. ** call to [sqlite3changeset_next()] must have returned SQLITE_ROW.
  11308. ** Furthermore, it may only be called if the type of change that the iterator
  11309. ** currently points to is either [SQLITE_UPDATE] or [SQLITE_INSERT]. Otherwise,
  11310. ** this function returns [SQLITE_MISUSE] and sets *ppValue to NULL.
  11311. **
  11312. ** Argument iVal must be greater than or equal to 0, and less than the number
  11313. ** of columns in the table affected by the current change. Otherwise,
  11314. ** [SQLITE_RANGE] is returned and *ppValue is set to NULL.
  11315. **
  11316. ** If successful, this function sets *ppValue to point to a protected
  11317. ** sqlite3_value object containing the iVal'th value from the vector of
  11318. ** new row values stored as part of the UPDATE or INSERT change and
  11319. ** returns SQLITE_OK. If the change is an UPDATE and does not include
  11320. ** a new value for the requested column, *ppValue is set to NULL and
  11321. ** SQLITE_OK returned. The name of the function comes from the fact that
  11322. ** this is similar to the "new.*" columns available to update or delete
  11323. ** triggers.
  11324. **
  11325. ** If some other error occurs (e.g. an OOM condition), an SQLite error code
  11326. ** is returned and *ppValue is set to NULL.
  11327. */
  11328. SQLITE_API int sqlite3changeset_new(
  11329. sqlite3_changeset_iter *pIter, /* Changeset iterator */
  11330. int iVal, /* Column number */
  11331. sqlite3_value **ppValue /* OUT: New value (or NULL pointer) */
  11332. );
  11333. /*
  11334. ** CAPI3REF: Obtain Conflicting Row Values From A Changeset Iterator
  11335. ** METHOD: sqlite3_changeset_iter
  11336. **
  11337. ** This function should only be used with iterator objects passed to a
  11338. ** conflict-handler callback by [sqlite3changeset_apply()] with either
  11339. ** [SQLITE_CHANGESET_DATA] or [SQLITE_CHANGESET_CONFLICT]. If this function
  11340. ** is called on any other iterator, [SQLITE_MISUSE] is returned and *ppValue
  11341. ** is set to NULL.
  11342. **
  11343. ** Argument iVal must be greater than or equal to 0, and less than the number
  11344. ** of columns in the table affected by the current change. Otherwise,
  11345. ** [SQLITE_RANGE] is returned and *ppValue is set to NULL.
  11346. **
  11347. ** If successful, this function sets *ppValue to point to a protected
  11348. ** sqlite3_value object containing the iVal'th value from the
  11349. ** "conflicting row" associated with the current conflict-handler callback
  11350. ** and returns SQLITE_OK.
  11351. **
  11352. ** If some other error occurs (e.g. an OOM condition), an SQLite error code
  11353. ** is returned and *ppValue is set to NULL.
  11354. */
  11355. SQLITE_API int sqlite3changeset_conflict(
  11356. sqlite3_changeset_iter *pIter, /* Changeset iterator */
  11357. int iVal, /* Column number */
  11358. sqlite3_value **ppValue /* OUT: Value from conflicting row */
  11359. );
  11360. /*
  11361. ** CAPI3REF: Determine The Number Of Foreign Key Constraint Violations
  11362. ** METHOD: sqlite3_changeset_iter
  11363. **
  11364. ** This function may only be called with an iterator passed to an
  11365. ** SQLITE_CHANGESET_FOREIGN_KEY conflict handler callback. In this case
  11366. ** it sets the output variable to the total number of known foreign key
  11367. ** violations in the destination database and returns SQLITE_OK.
  11368. **
  11369. ** In all other cases this function returns SQLITE_MISUSE.
  11370. */
  11371. SQLITE_API int sqlite3changeset_fk_conflicts(
  11372. sqlite3_changeset_iter *pIter, /* Changeset iterator */
  11373. int *pnOut /* OUT: Number of FK violations */
  11374. );
  11375. /*
  11376. ** CAPI3REF: Finalize A Changeset Iterator
  11377. ** METHOD: sqlite3_changeset_iter
  11378. **
  11379. ** This function is used to finalize an iterator allocated with
  11380. ** [sqlite3changeset_start()].
  11381. **
  11382. ** This function should only be called on iterators created using the
  11383. ** [sqlite3changeset_start()] function. If an application calls this
  11384. ** function with an iterator passed to a conflict-handler by
  11385. ** [sqlite3changeset_apply()], [SQLITE_MISUSE] is immediately returned and the
  11386. ** call has no effect.
  11387. **
  11388. ** If an error was encountered within a call to an sqlite3changeset_xxx()
  11389. ** function (for example an [SQLITE_CORRUPT] in [sqlite3changeset_next()] or an
  11390. ** [SQLITE_NOMEM] in [sqlite3changeset_new()]) then an error code corresponding
  11391. ** to that error is returned by this function. Otherwise, SQLITE_OK is
  11392. ** returned. This is to allow the following pattern (pseudo-code):
  11393. **
  11394. ** <pre>
  11395. ** sqlite3changeset_start();
  11396. ** while( SQLITE_ROW==sqlite3changeset_next() ){
  11397. ** // Do something with change.
  11398. ** }
  11399. ** rc = sqlite3changeset_finalize();
  11400. ** if( rc!=SQLITE_OK ){
  11401. ** // An error has occurred
  11402. ** }
  11403. ** </pre>
  11404. */
  11405. SQLITE_API int sqlite3changeset_finalize(sqlite3_changeset_iter *pIter);
  11406. /*
  11407. ** CAPI3REF: Invert A Changeset
  11408. **
  11409. ** This function is used to "invert" a changeset object. Applying an inverted
  11410. ** changeset to a database reverses the effects of applying the uninverted
  11411. ** changeset. Specifically:
  11412. **
  11413. ** <ul>
  11414. ** <li> Each DELETE change is changed to an INSERT, and
  11415. ** <li> Each INSERT change is changed to a DELETE, and
  11416. ** <li> For each UPDATE change, the old.* and new.* values are exchanged.
  11417. ** </ul>
  11418. **
  11419. ** This function does not change the order in which changes appear within
  11420. ** the changeset. It merely reverses the sense of each individual change.
  11421. **
  11422. ** If successful, a pointer to a buffer containing the inverted changeset
  11423. ** is stored in *ppOut, the size of the same buffer is stored in *pnOut, and
  11424. ** SQLITE_OK is returned. If an error occurs, both *pnOut and *ppOut are
  11425. ** zeroed and an SQLite error code returned.
  11426. **
  11427. ** It is the responsibility of the caller to eventually call sqlite3_free()
  11428. ** on the *ppOut pointer to free the buffer allocation following a successful
  11429. ** call to this function.
  11430. **
  11431. ** WARNING/TODO: This function currently assumes that the input is a valid
  11432. ** changeset. If it is not, the results are undefined.
  11433. */
  11434. SQLITE_API int sqlite3changeset_invert(
  11435. int nIn, const void *pIn, /* Input changeset */
  11436. int *pnOut, void **ppOut /* OUT: Inverse of input */
  11437. );
  11438. /*
  11439. ** CAPI3REF: Concatenate Two Changeset Objects
  11440. **
  11441. ** This function is used to concatenate two changesets, A and B, into a
  11442. ** single changeset. The result is a changeset equivalent to applying
  11443. ** changeset A followed by changeset B.
  11444. **
  11445. ** This function combines the two input changesets using an
  11446. ** sqlite3_changegroup object. Calling it produces similar results as the
  11447. ** following code fragment:
  11448. **
  11449. ** <pre>
  11450. ** sqlite3_changegroup *pGrp;
  11451. ** rc = sqlite3_changegroup_new(&pGrp);
  11452. ** if( rc==SQLITE_OK ) rc = sqlite3changegroup_add(pGrp, nA, pA);
  11453. ** if( rc==SQLITE_OK ) rc = sqlite3changegroup_add(pGrp, nB, pB);
  11454. ** if( rc==SQLITE_OK ){
  11455. ** rc = sqlite3changegroup_output(pGrp, pnOut, ppOut);
  11456. ** }else{
  11457. ** *ppOut = 0;
  11458. ** *pnOut = 0;
  11459. ** }
  11460. ** </pre>
  11461. **
  11462. ** Refer to the sqlite3_changegroup documentation below for details.
  11463. */
  11464. SQLITE_API int sqlite3changeset_concat(
  11465. int nA, /* Number of bytes in buffer pA */
  11466. void *pA, /* Pointer to buffer containing changeset A */
  11467. int nB, /* Number of bytes in buffer pB */
  11468. void *pB, /* Pointer to buffer containing changeset B */
  11469. int *pnOut, /* OUT: Number of bytes in output changeset */
  11470. void **ppOut /* OUT: Buffer containing output changeset */
  11471. );
  11472. /*
  11473. ** CAPI3REF: Upgrade the Schema of a Changeset/Patchset
  11474. */
  11475. SQLITE_API int sqlite3changeset_upgrade(
  11476. sqlite3 *db,
  11477. const char *zDb,
  11478. int nIn, const void *pIn, /* Input changeset */
  11479. int *pnOut, void **ppOut /* OUT: Inverse of input */
  11480. );
  11481. /*
  11482. ** CAPI3REF: Changegroup Handle
  11483. **
  11484. ** A changegroup is an object used to combine two or more
  11485. ** [changesets] or [patchsets]
  11486. */
  11487. typedef struct sqlite3_changegroup sqlite3_changegroup;
  11488. /*
  11489. ** CAPI3REF: Create A New Changegroup Object
  11490. ** CONSTRUCTOR: sqlite3_changegroup
  11491. **
  11492. ** An sqlite3_changegroup object is used to combine two or more changesets
  11493. ** (or patchsets) into a single changeset (or patchset). A single changegroup
  11494. ** object may combine changesets or patchsets, but not both. The output is
  11495. ** always in the same format as the input.
  11496. **
  11497. ** If successful, this function returns SQLITE_OK and populates (*pp) with
  11498. ** a pointer to a new sqlite3_changegroup object before returning. The caller
  11499. ** should eventually free the returned object using a call to
  11500. ** sqlite3changegroup_delete(). If an error occurs, an SQLite error code
  11501. ** (i.e. SQLITE_NOMEM) is returned and *pp is set to NULL.
  11502. **
  11503. ** The usual usage pattern for an sqlite3_changegroup object is as follows:
  11504. **
  11505. ** <ul>
  11506. ** <li> It is created using a call to sqlite3changegroup_new().
  11507. **
  11508. ** <li> Zero or more changesets (or patchsets) are added to the object
  11509. ** by calling sqlite3changegroup_add().
  11510. **
  11511. ** <li> The result of combining all input changesets together is obtained
  11512. ** by the application via a call to sqlite3changegroup_output().
  11513. **
  11514. ** <li> The object is deleted using a call to sqlite3changegroup_delete().
  11515. ** </ul>
  11516. **
  11517. ** Any number of calls to add() and output() may be made between the calls to
  11518. ** new() and delete(), and in any order.
  11519. **
  11520. ** As well as the regular sqlite3changegroup_add() and
  11521. ** sqlite3changegroup_output() functions, also available are the streaming
  11522. ** versions sqlite3changegroup_add_strm() and sqlite3changegroup_output_strm().
  11523. */
  11524. SQLITE_API int sqlite3changegroup_new(sqlite3_changegroup **pp);
  11525. /*
  11526. ** CAPI3REF: Add a Schema to a Changegroup
  11527. ** METHOD: sqlite3_changegroup_schema
  11528. **
  11529. ** This method may be used to optionally enforce the rule that the changesets
  11530. ** added to the changegroup handle must match the schema of database zDb
  11531. ** ("main", "temp", or the name of an attached database). If
  11532. ** sqlite3changegroup_add() is called to add a changeset that is not compatible
  11533. ** with the configured schema, SQLITE_SCHEMA is returned and the changegroup
  11534. ** object is left in an undefined state.
  11535. **
  11536. ** A changeset schema is considered compatible with the database schema in
  11537. ** the same way as for sqlite3changeset_apply(). Specifically, for each
  11538. ** table in the changeset, there exists a database table with:
  11539. **
  11540. ** <ul>
  11541. ** <li> The name identified by the changeset, and
  11542. ** <li> at least as many columns as recorded in the changeset, and
  11543. ** <li> the primary key columns in the same position as recorded in
  11544. ** the changeset.
  11545. ** </ul>
  11546. **
  11547. ** The output of the changegroup object always has the same schema as the
  11548. ** database nominated using this function. In cases where changesets passed
  11549. ** to sqlite3changegroup_add() have fewer columns than the corresponding table
  11550. ** in the database schema, these are filled in using the default column
  11551. ** values from the database schema. This makes it possible to combined
  11552. ** changesets that have different numbers of columns for a single table
  11553. ** within a changegroup, provided that they are otherwise compatible.
  11554. */
  11555. SQLITE_API int sqlite3changegroup_schema(sqlite3_changegroup*, sqlite3*, const char *zDb);
  11556. /*
  11557. ** CAPI3REF: Add A Changeset To A Changegroup
  11558. ** METHOD: sqlite3_changegroup
  11559. **
  11560. ** Add all changes within the changeset (or patchset) in buffer pData (size
  11561. ** nData bytes) to the changegroup.
  11562. **
  11563. ** If the buffer contains a patchset, then all prior calls to this function
  11564. ** on the same changegroup object must also have specified patchsets. Or, if
  11565. ** the buffer contains a changeset, so must have the earlier calls to this
  11566. ** function. Otherwise, SQLITE_ERROR is returned and no changes are added
  11567. ** to the changegroup.
  11568. **
  11569. ** Rows within the changeset and changegroup are identified by the values in
  11570. ** their PRIMARY KEY columns. A change in the changeset is considered to
  11571. ** apply to the same row as a change already present in the changegroup if
  11572. ** the two rows have the same primary key.
  11573. **
  11574. ** Changes to rows that do not already appear in the changegroup are
  11575. ** simply copied into it. Or, if both the new changeset and the changegroup
  11576. ** contain changes that apply to a single row, the final contents of the
  11577. ** changegroup depends on the type of each change, as follows:
  11578. **
  11579. ** <table border=1 style="margin-left:8ex;margin-right:8ex">
  11580. ** <tr><th style="white-space:pre">Existing Change </th>
  11581. ** <th style="white-space:pre">New Change </th>
  11582. ** <th>Output Change
  11583. ** <tr><td>INSERT <td>INSERT <td>
  11584. ** The new change is ignored. This case does not occur if the new
  11585. ** changeset was recorded immediately after the changesets already
  11586. ** added to the changegroup.
  11587. ** <tr><td>INSERT <td>UPDATE <td>
  11588. ** The INSERT change remains in the changegroup. The values in the
  11589. ** INSERT change are modified as if the row was inserted by the
  11590. ** existing change and then updated according to the new change.
  11591. ** <tr><td>INSERT <td>DELETE <td>
  11592. ** The existing INSERT is removed from the changegroup. The DELETE is
  11593. ** not added.
  11594. ** <tr><td>UPDATE <td>INSERT <td>
  11595. ** The new change is ignored. This case does not occur if the new
  11596. ** changeset was recorded immediately after the changesets already
  11597. ** added to the changegroup.
  11598. ** <tr><td>UPDATE <td>UPDATE <td>
  11599. ** The existing UPDATE remains within the changegroup. It is amended
  11600. ** so that the accompanying values are as if the row was updated once
  11601. ** by the existing change and then again by the new change.
  11602. ** <tr><td>UPDATE <td>DELETE <td>
  11603. ** The existing UPDATE is replaced by the new DELETE within the
  11604. ** changegroup.
  11605. ** <tr><td>DELETE <td>INSERT <td>
  11606. ** If one or more of the column values in the row inserted by the
  11607. ** new change differ from those in the row deleted by the existing
  11608. ** change, the existing DELETE is replaced by an UPDATE within the
  11609. ** changegroup. Otherwise, if the inserted row is exactly the same
  11610. ** as the deleted row, the existing DELETE is simply discarded.
  11611. ** <tr><td>DELETE <td>UPDATE <td>
  11612. ** The new change is ignored. This case does not occur if the new
  11613. ** changeset was recorded immediately after the changesets already
  11614. ** added to the changegroup.
  11615. ** <tr><td>DELETE <td>DELETE <td>
  11616. ** The new change is ignored. This case does not occur if the new
  11617. ** changeset was recorded immediately after the changesets already
  11618. ** added to the changegroup.
  11619. ** </table>
  11620. **
  11621. ** If the new changeset contains changes to a table that is already present
  11622. ** in the changegroup, then the number of columns and the position of the
  11623. ** primary key columns for the table must be consistent. If this is not the
  11624. ** case, this function fails with SQLITE_SCHEMA. Except, if the changegroup
  11625. ** object has been configured with a database schema using the
  11626. ** sqlite3changegroup_schema() API, then it is possible to combine changesets
  11627. ** with different numbers of columns for a single table, provided that
  11628. ** they are otherwise compatible.
  11629. **
  11630. ** If the input changeset appears to be corrupt and the corruption is
  11631. ** detected, SQLITE_CORRUPT is returned. Or, if an out-of-memory condition
  11632. ** occurs during processing, this function returns SQLITE_NOMEM.
  11633. **
  11634. ** In all cases, if an error occurs the state of the final contents of the
  11635. ** changegroup is undefined. If no error occurs, SQLITE_OK is returned.
  11636. */
  11637. SQLITE_API int sqlite3changegroup_add(sqlite3_changegroup*, int nData, void *pData);
  11638. /*
  11639. ** CAPI3REF: Obtain A Composite Changeset From A Changegroup
  11640. ** METHOD: sqlite3_changegroup
  11641. **
  11642. ** Obtain a buffer containing a changeset (or patchset) representing the
  11643. ** current contents of the changegroup. If the inputs to the changegroup
  11644. ** were themselves changesets, the output is a changeset. Or, if the
  11645. ** inputs were patchsets, the output is also a patchset.
  11646. **
  11647. ** As with the output of the sqlite3session_changeset() and
  11648. ** sqlite3session_patchset() functions, all changes related to a single
  11649. ** table are grouped together in the output of this function. Tables appear
  11650. ** in the same order as for the very first changeset added to the changegroup.
  11651. ** If the second or subsequent changesets added to the changegroup contain
  11652. ** changes for tables that do not appear in the first changeset, they are
  11653. ** appended onto the end of the output changeset, again in the order in
  11654. ** which they are first encountered.
  11655. **
  11656. ** If an error occurs, an SQLite error code is returned and the output
  11657. ** variables (*pnData) and (*ppData) are set to 0. Otherwise, SQLITE_OK
  11658. ** is returned and the output variables are set to the size of and a
  11659. ** pointer to the output buffer, respectively. In this case it is the
  11660. ** responsibility of the caller to eventually free the buffer using a
  11661. ** call to sqlite3_free().
  11662. */
  11663. SQLITE_API int sqlite3changegroup_output(
  11664. sqlite3_changegroup*,
  11665. int *pnData, /* OUT: Size of output buffer in bytes */
  11666. void **ppData /* OUT: Pointer to output buffer */
  11667. );
  11668. /*
  11669. ** CAPI3REF: Delete A Changegroup Object
  11670. ** DESTRUCTOR: sqlite3_changegroup
  11671. */
  11672. SQLITE_API void sqlite3changegroup_delete(sqlite3_changegroup*);
  11673. /*
  11674. ** CAPI3REF: Apply A Changeset To A Database
  11675. **
  11676. ** Apply a changeset or patchset to a database. These functions attempt to
  11677. ** update the "main" database attached to handle db with the changes found in
  11678. ** the changeset passed via the second and third arguments.
  11679. **
  11680. ** The fourth argument (xFilter) passed to these functions is the "filter
  11681. ** callback". If it is not NULL, then for each table affected by at least one
  11682. ** change in the changeset, the filter callback is invoked with
  11683. ** the table name as the second argument, and a copy of the context pointer
  11684. ** passed as the sixth argument as the first. If the "filter callback"
  11685. ** returns zero, then no attempt is made to apply any changes to the table.
  11686. ** Otherwise, if the return value is non-zero or the xFilter argument to
  11687. ** is NULL, all changes related to the table are attempted.
  11688. **
  11689. ** For each table that is not excluded by the filter callback, this function
  11690. ** tests that the target database contains a compatible table. A table is
  11691. ** considered compatible if all of the following are true:
  11692. **
  11693. ** <ul>
  11694. ** <li> The table has the same name as the name recorded in the
  11695. ** changeset, and
  11696. ** <li> The table has at least as many columns as recorded in the
  11697. ** changeset, and
  11698. ** <li> The table has primary key columns in the same position as
  11699. ** recorded in the changeset.
  11700. ** </ul>
  11701. **
  11702. ** If there is no compatible table, it is not an error, but none of the
  11703. ** changes associated with the table are applied. A warning message is issued
  11704. ** via the sqlite3_log() mechanism with the error code SQLITE_SCHEMA. At most
  11705. ** one such warning is issued for each table in the changeset.
  11706. **
  11707. ** For each change for which there is a compatible table, an attempt is made
  11708. ** to modify the table contents according to the UPDATE, INSERT or DELETE
  11709. ** change. If a change cannot be applied cleanly, the conflict handler
  11710. ** function passed as the fifth argument to sqlite3changeset_apply() may be
  11711. ** invoked. A description of exactly when the conflict handler is invoked for
  11712. ** each type of change is below.
  11713. **
  11714. ** Unlike the xFilter argument, xConflict may not be passed NULL. The results
  11715. ** of passing anything other than a valid function pointer as the xConflict
  11716. ** argument are undefined.
  11717. **
  11718. ** Each time the conflict handler function is invoked, it must return one
  11719. ** of [SQLITE_CHANGESET_OMIT], [SQLITE_CHANGESET_ABORT] or
  11720. ** [SQLITE_CHANGESET_REPLACE]. SQLITE_CHANGESET_REPLACE may only be returned
  11721. ** if the second argument passed to the conflict handler is either
  11722. ** SQLITE_CHANGESET_DATA or SQLITE_CHANGESET_CONFLICT. If the conflict-handler
  11723. ** returns an illegal value, any changes already made are rolled back and
  11724. ** the call to sqlite3changeset_apply() returns SQLITE_MISUSE. Different
  11725. ** actions are taken by sqlite3changeset_apply() depending on the value
  11726. ** returned by each invocation of the conflict-handler function. Refer to
  11727. ** the documentation for the three
  11728. ** [SQLITE_CHANGESET_OMIT|available return values] for details.
  11729. **
  11730. ** <dl>
  11731. ** <dt>DELETE Changes<dd>
  11732. ** For each DELETE change, the function checks if the target database
  11733. ** contains a row with the same primary key value (or values) as the
  11734. ** original row values stored in the changeset. If it does, and the values
  11735. ** stored in all non-primary key columns also match the values stored in
  11736. ** the changeset the row is deleted from the target database.
  11737. **
  11738. ** If a row with matching primary key values is found, but one or more of
  11739. ** the non-primary key fields contains a value different from the original
  11740. ** row value stored in the changeset, the conflict-handler function is
  11741. ** invoked with [SQLITE_CHANGESET_DATA] as the second argument. If the
  11742. ** database table has more columns than are recorded in the changeset,
  11743. ** only the values of those non-primary key fields are compared against
  11744. ** the current database contents - any trailing database table columns
  11745. ** are ignored.
  11746. **
  11747. ** If no row with matching primary key values is found in the database,
  11748. ** the conflict-handler function is invoked with [SQLITE_CHANGESET_NOTFOUND]
  11749. ** passed as the second argument.
  11750. **
  11751. ** If the DELETE operation is attempted, but SQLite returns SQLITE_CONSTRAINT
  11752. ** (which can only happen if a foreign key constraint is violated), the
  11753. ** conflict-handler function is invoked with [SQLITE_CHANGESET_CONSTRAINT]
  11754. ** passed as the second argument. This includes the case where the DELETE
  11755. ** operation is attempted because an earlier call to the conflict handler
  11756. ** function returned [SQLITE_CHANGESET_REPLACE].
  11757. **
  11758. ** <dt>INSERT Changes<dd>
  11759. ** For each INSERT change, an attempt is made to insert the new row into
  11760. ** the database. If the changeset row contains fewer fields than the
  11761. ** database table, the trailing fields are populated with their default
  11762. ** values.
  11763. **
  11764. ** If the attempt to insert the row fails because the database already
  11765. ** contains a row with the same primary key values, the conflict handler
  11766. ** function is invoked with the second argument set to
  11767. ** [SQLITE_CHANGESET_CONFLICT].
  11768. **
  11769. ** If the attempt to insert the row fails because of some other constraint
  11770. ** violation (e.g. NOT NULL or UNIQUE), the conflict handler function is
  11771. ** invoked with the second argument set to [SQLITE_CHANGESET_CONSTRAINT].
  11772. ** This includes the case where the INSERT operation is re-attempted because
  11773. ** an earlier call to the conflict handler function returned
  11774. ** [SQLITE_CHANGESET_REPLACE].
  11775. **
  11776. ** <dt>UPDATE Changes<dd>
  11777. ** For each UPDATE change, the function checks if the target database
  11778. ** contains a row with the same primary key value (or values) as the
  11779. ** original row values stored in the changeset. If it does, and the values
  11780. ** stored in all modified non-primary key columns also match the values
  11781. ** stored in the changeset the row is updated within the target database.
  11782. **
  11783. ** If a row with matching primary key values is found, but one or more of
  11784. ** the modified non-primary key fields contains a value different from an
  11785. ** original row value stored in the changeset, the conflict-handler function
  11786. ** is invoked with [SQLITE_CHANGESET_DATA] as the second argument. Since
  11787. ** UPDATE changes only contain values for non-primary key fields that are
  11788. ** to be modified, only those fields need to match the original values to
  11789. ** avoid the SQLITE_CHANGESET_DATA conflict-handler callback.
  11790. **
  11791. ** If no row with matching primary key values is found in the database,
  11792. ** the conflict-handler function is invoked with [SQLITE_CHANGESET_NOTFOUND]
  11793. ** passed as the second argument.
  11794. **
  11795. ** If the UPDATE operation is attempted, but SQLite returns
  11796. ** SQLITE_CONSTRAINT, the conflict-handler function is invoked with
  11797. ** [SQLITE_CHANGESET_CONSTRAINT] passed as the second argument.
  11798. ** This includes the case where the UPDATE operation is attempted after
  11799. ** an earlier call to the conflict handler function returned
  11800. ** [SQLITE_CHANGESET_REPLACE].
  11801. ** </dl>
  11802. **
  11803. ** It is safe to execute SQL statements, including those that write to the
  11804. ** table that the callback related to, from within the xConflict callback.
  11805. ** This can be used to further customize the application's conflict
  11806. ** resolution strategy.
  11807. **
  11808. ** All changes made by these functions are enclosed in a savepoint transaction.
  11809. ** If any other error (aside from a constraint failure when attempting to
  11810. ** write to the target database) occurs, then the savepoint transaction is
  11811. ** rolled back, restoring the target database to its original state, and an
  11812. ** SQLite error code returned.
  11813. **
  11814. ** If the output parameters (ppRebase) and (pnRebase) are non-NULL and
  11815. ** the input is a changeset (not a patchset), then sqlite3changeset_apply_v2()
  11816. ** may set (*ppRebase) to point to a "rebase" that may be used with the
  11817. ** sqlite3_rebaser APIs buffer before returning. In this case (*pnRebase)
  11818. ** is set to the size of the buffer in bytes. It is the responsibility of the
  11819. ** caller to eventually free any such buffer using sqlite3_free(). The buffer
  11820. ** is only allocated and populated if one or more conflicts were encountered
  11821. ** while applying the patchset. See comments surrounding the sqlite3_rebaser
  11822. ** APIs for further details.
  11823. **
  11824. ** The behavior of sqlite3changeset_apply_v2() and its streaming equivalent
  11825. ** may be modified by passing a combination of
  11826. ** [SQLITE_CHANGESETAPPLY_NOSAVEPOINT | supported flags] as the 9th parameter.
  11827. **
  11828. ** Note that the sqlite3changeset_apply_v2() API is still <b>experimental</b>
  11829. ** and therefore subject to change.
  11830. */
  11831. SQLITE_API int sqlite3changeset_apply(
  11832. sqlite3 *db, /* Apply change to "main" db of this handle */
  11833. int nChangeset, /* Size of changeset in bytes */
  11834. void *pChangeset, /* Changeset blob */
  11835. int(*xFilter)(
  11836. void *pCtx, /* Copy of sixth arg to _apply() */
  11837. const char *zTab /* Table name */
  11838. ),
  11839. int(*xConflict)(
  11840. void *pCtx, /* Copy of sixth arg to _apply() */
  11841. int eConflict, /* DATA, MISSING, CONFLICT, CONSTRAINT */
  11842. sqlite3_changeset_iter *p /* Handle describing change and conflict */
  11843. ),
  11844. void *pCtx /* First argument passed to xConflict */
  11845. );
  11846. SQLITE_API int sqlite3changeset_apply_v2(
  11847. sqlite3 *db, /* Apply change to "main" db of this handle */
  11848. int nChangeset, /* Size of changeset in bytes */
  11849. void *pChangeset, /* Changeset blob */
  11850. int(*xFilter)(
  11851. void *pCtx, /* Copy of sixth arg to _apply() */
  11852. const char *zTab /* Table name */
  11853. ),
  11854. int(*xConflict)(
  11855. void *pCtx, /* Copy of sixth arg to _apply() */
  11856. int eConflict, /* DATA, MISSING, CONFLICT, CONSTRAINT */
  11857. sqlite3_changeset_iter *p /* Handle describing change and conflict */
  11858. ),
  11859. void *pCtx, /* First argument passed to xConflict */
  11860. void **ppRebase, int *pnRebase, /* OUT: Rebase data */
  11861. int flags /* SESSION_CHANGESETAPPLY_* flags */
  11862. );
  11863. /*
  11864. ** CAPI3REF: Flags for sqlite3changeset_apply_v2
  11865. **
  11866. ** The following flags may passed via the 9th parameter to
  11867. ** [sqlite3changeset_apply_v2] and [sqlite3changeset_apply_v2_strm]:
  11868. **
  11869. ** <dl>
  11870. ** <dt>SQLITE_CHANGESETAPPLY_NOSAVEPOINT <dd>
  11871. ** Usually, the sessions module encloses all operations performed by
  11872. ** a single call to apply_v2() or apply_v2_strm() in a [SAVEPOINT]. The
  11873. ** SAVEPOINT is committed if the changeset or patchset is successfully
  11874. ** applied, or rolled back if an error occurs. Specifying this flag
  11875. ** causes the sessions module to omit this savepoint. In this case, if the
  11876. ** caller has an open transaction or savepoint when apply_v2() is called,
  11877. ** it may revert the partially applied changeset by rolling it back.
  11878. **
  11879. ** <dt>SQLITE_CHANGESETAPPLY_INVERT <dd>
  11880. ** Invert the changeset before applying it. This is equivalent to inverting
  11881. ** a changeset using sqlite3changeset_invert() before applying it. It is
  11882. ** an error to specify this flag with a patchset.
  11883. **
  11884. ** <dt>SQLITE_CHANGESETAPPLY_IGNORENOOP <dd>
  11885. ** Do not invoke the conflict handler callback for any changes that
  11886. ** would not actually modify the database even if they were applied.
  11887. ** Specifically, this means that the conflict handler is not invoked
  11888. ** for:
  11889. ** <ul>
  11890. ** <li>a delete change if the row being deleted cannot be found,
  11891. ** <li>an update change if the modified fields are already set to
  11892. ** their new values in the conflicting row, or
  11893. ** <li>an insert change if all fields of the conflicting row match
  11894. ** the row being inserted.
  11895. ** </ul>
  11896. **
  11897. ** <dt>SQLITE_CHANGESETAPPLY_FKNOACTION <dd>
  11898. ** If this flag it set, then all foreign key constraints in the target
  11899. ** database behave as if they were declared with "ON UPDATE NO ACTION ON
  11900. ** DELETE NO ACTION", even if they are actually CASCADE, RESTRICT, SET NULL
  11901. ** or SET DEFAULT.
  11902. */
  11903. #define SQLITE_CHANGESETAPPLY_NOSAVEPOINT 0x0001
  11904. #define SQLITE_CHANGESETAPPLY_INVERT 0x0002
  11905. #define SQLITE_CHANGESETAPPLY_IGNORENOOP 0x0004
  11906. #define SQLITE_CHANGESETAPPLY_FKNOACTION 0x0008
  11907. /*
  11908. ** CAPI3REF: Constants Passed To The Conflict Handler
  11909. **
  11910. ** Values that may be passed as the second argument to a conflict-handler.
  11911. **
  11912. ** <dl>
  11913. ** <dt>SQLITE_CHANGESET_DATA<dd>
  11914. ** The conflict handler is invoked with CHANGESET_DATA as the second argument
  11915. ** when processing a DELETE or UPDATE change if a row with the required
  11916. ** PRIMARY KEY fields is present in the database, but one or more other
  11917. ** (non primary-key) fields modified by the update do not contain the
  11918. ** expected "before" values.
  11919. **
  11920. ** The conflicting row, in this case, is the database row with the matching
  11921. ** primary key.
  11922. **
  11923. ** <dt>SQLITE_CHANGESET_NOTFOUND<dd>
  11924. ** The conflict handler is invoked with CHANGESET_NOTFOUND as the second
  11925. ** argument when processing a DELETE or UPDATE change if a row with the
  11926. ** required PRIMARY KEY fields is not present in the database.
  11927. **
  11928. ** There is no conflicting row in this case. The results of invoking the
  11929. ** sqlite3changeset_conflict() API are undefined.
  11930. **
  11931. ** <dt>SQLITE_CHANGESET_CONFLICT<dd>
  11932. ** CHANGESET_CONFLICT is passed as the second argument to the conflict
  11933. ** handler while processing an INSERT change if the operation would result
  11934. ** in duplicate primary key values.
  11935. **
  11936. ** The conflicting row in this case is the database row with the matching
  11937. ** primary key.
  11938. **
  11939. ** <dt>SQLITE_CHANGESET_FOREIGN_KEY<dd>
  11940. ** If foreign key handling is enabled, and applying a changeset leaves the
  11941. ** database in a state containing foreign key violations, the conflict
  11942. ** handler is invoked with CHANGESET_FOREIGN_KEY as the second argument
  11943. ** exactly once before the changeset is committed. If the conflict handler
  11944. ** returns CHANGESET_OMIT, the changes, including those that caused the
  11945. ** foreign key constraint violation, are committed. Or, if it returns
  11946. ** CHANGESET_ABORT, the changeset is rolled back.
  11947. **
  11948. ** No current or conflicting row information is provided. The only function
  11949. ** it is possible to call on the supplied sqlite3_changeset_iter handle
  11950. ** is sqlite3changeset_fk_conflicts().
  11951. **
  11952. ** <dt>SQLITE_CHANGESET_CONSTRAINT<dd>
  11953. ** If any other constraint violation occurs while applying a change (i.e.
  11954. ** a UNIQUE, CHECK or NOT NULL constraint), the conflict handler is
  11955. ** invoked with CHANGESET_CONSTRAINT as the second argument.
  11956. **
  11957. ** There is no conflicting row in this case. The results of invoking the
  11958. ** sqlite3changeset_conflict() API are undefined.
  11959. **
  11960. ** </dl>
  11961. */
  11962. #define SQLITE_CHANGESET_DATA 1
  11963. #define SQLITE_CHANGESET_NOTFOUND 2
  11964. #define SQLITE_CHANGESET_CONFLICT 3
  11965. #define SQLITE_CHANGESET_CONSTRAINT 4
  11966. #define SQLITE_CHANGESET_FOREIGN_KEY 5
  11967. /*
  11968. ** CAPI3REF: Constants Returned By The Conflict Handler
  11969. **
  11970. ** A conflict handler callback must return one of the following three values.
  11971. **
  11972. ** <dl>
  11973. ** <dt>SQLITE_CHANGESET_OMIT<dd>
  11974. ** If a conflict handler returns this value no special action is taken. The
  11975. ** change that caused the conflict is not applied. The session module
  11976. ** continues to the next change in the changeset.
  11977. **
  11978. ** <dt>SQLITE_CHANGESET_REPLACE<dd>
  11979. ** This value may only be returned if the second argument to the conflict
  11980. ** handler was SQLITE_CHANGESET_DATA or SQLITE_CHANGESET_CONFLICT. If this
  11981. ** is not the case, any changes applied so far are rolled back and the
  11982. ** call to sqlite3changeset_apply() returns SQLITE_MISUSE.
  11983. **
  11984. ** If CHANGESET_REPLACE is returned by an SQLITE_CHANGESET_DATA conflict
  11985. ** handler, then the conflicting row is either updated or deleted, depending
  11986. ** on the type of change.
  11987. **
  11988. ** If CHANGESET_REPLACE is returned by an SQLITE_CHANGESET_CONFLICT conflict
  11989. ** handler, then the conflicting row is removed from the database and a
  11990. ** second attempt to apply the change is made. If this second attempt fails,
  11991. ** the original row is restored to the database before continuing.
  11992. **
  11993. ** <dt>SQLITE_CHANGESET_ABORT<dd>
  11994. ** If this value is returned, any changes applied so far are rolled back
  11995. ** and the call to sqlite3changeset_apply() returns SQLITE_ABORT.
  11996. ** </dl>
  11997. */
  11998. #define SQLITE_CHANGESET_OMIT 0
  11999. #define SQLITE_CHANGESET_REPLACE 1
  12000. #define SQLITE_CHANGESET_ABORT 2
  12001. /*
  12002. ** CAPI3REF: Rebasing changesets
  12003. ** EXPERIMENTAL
  12004. **
  12005. ** Suppose there is a site hosting a database in state S0. And that
  12006. ** modifications are made that move that database to state S1 and a
  12007. ** changeset recorded (the "local" changeset). Then, a changeset based
  12008. ** on S0 is received from another site (the "remote" changeset) and
  12009. ** applied to the database. The database is then in state
  12010. ** (S1+"remote"), where the exact state depends on any conflict
  12011. ** resolution decisions (OMIT or REPLACE) made while applying "remote".
  12012. ** Rebasing a changeset is to update it to take those conflict
  12013. ** resolution decisions into account, so that the same conflicts
  12014. ** do not have to be resolved elsewhere in the network.
  12015. **
  12016. ** For example, if both the local and remote changesets contain an
  12017. ** INSERT of the same key on "CREATE TABLE t1(a PRIMARY KEY, b)":
  12018. **
  12019. ** local: INSERT INTO t1 VALUES(1, 'v1');
  12020. ** remote: INSERT INTO t1 VALUES(1, 'v2');
  12021. **
  12022. ** and the conflict resolution is REPLACE, then the INSERT change is
  12023. ** removed from the local changeset (it was overridden). Or, if the
  12024. ** conflict resolution was "OMIT", then the local changeset is modified
  12025. ** to instead contain:
  12026. **
  12027. ** UPDATE t1 SET b = 'v2' WHERE a=1;
  12028. **
  12029. ** Changes within the local changeset are rebased as follows:
  12030. **
  12031. ** <dl>
  12032. ** <dt>Local INSERT<dd>
  12033. ** This may only conflict with a remote INSERT. If the conflict
  12034. ** resolution was OMIT, then add an UPDATE change to the rebased
  12035. ** changeset. Or, if the conflict resolution was REPLACE, add
  12036. ** nothing to the rebased changeset.
  12037. **
  12038. ** <dt>Local DELETE<dd>
  12039. ** This may conflict with a remote UPDATE or DELETE. In both cases the
  12040. ** only possible resolution is OMIT. If the remote operation was a
  12041. ** DELETE, then add no change to the rebased changeset. If the remote
  12042. ** operation was an UPDATE, then the old.* fields of change are updated
  12043. ** to reflect the new.* values in the UPDATE.
  12044. **
  12045. ** <dt>Local UPDATE<dd>
  12046. ** This may conflict with a remote UPDATE or DELETE. If it conflicts
  12047. ** with a DELETE, and the conflict resolution was OMIT, then the update
  12048. ** is changed into an INSERT. Any undefined values in the new.* record
  12049. ** from the update change are filled in using the old.* values from
  12050. ** the conflicting DELETE. Or, if the conflict resolution was REPLACE,
  12051. ** the UPDATE change is simply omitted from the rebased changeset.
  12052. **
  12053. ** If conflict is with a remote UPDATE and the resolution is OMIT, then
  12054. ** the old.* values are rebased using the new.* values in the remote
  12055. ** change. Or, if the resolution is REPLACE, then the change is copied
  12056. ** into the rebased changeset with updates to columns also updated by
  12057. ** the conflicting remote UPDATE removed. If this means no columns would
  12058. ** be updated, the change is omitted.
  12059. ** </dl>
  12060. **
  12061. ** A local change may be rebased against multiple remote changes
  12062. ** simultaneously. If a single key is modified by multiple remote
  12063. ** changesets, they are combined as follows before the local changeset
  12064. ** is rebased:
  12065. **
  12066. ** <ul>
  12067. ** <li> If there has been one or more REPLACE resolutions on a
  12068. ** key, it is rebased according to a REPLACE.
  12069. **
  12070. ** <li> If there have been no REPLACE resolutions on a key, then
  12071. ** the local changeset is rebased according to the most recent
  12072. ** of the OMIT resolutions.
  12073. ** </ul>
  12074. **
  12075. ** Note that conflict resolutions from multiple remote changesets are
  12076. ** combined on a per-field basis, not per-row. This means that in the
  12077. ** case of multiple remote UPDATE operations, some fields of a single
  12078. ** local change may be rebased for REPLACE while others are rebased for
  12079. ** OMIT.
  12080. **
  12081. ** In order to rebase a local changeset, the remote changeset must first
  12082. ** be applied to the local database using sqlite3changeset_apply_v2() and
  12083. ** the buffer of rebase information captured. Then:
  12084. **
  12085. ** <ol>
  12086. ** <li> An sqlite3_rebaser object is created by calling
  12087. ** sqlite3rebaser_create().
  12088. ** <li> The new object is configured with the rebase buffer obtained from
  12089. ** sqlite3changeset_apply_v2() by calling sqlite3rebaser_configure().
  12090. ** If the local changeset is to be rebased against multiple remote
  12091. ** changesets, then sqlite3rebaser_configure() should be called
  12092. ** multiple times, in the same order that the multiple
  12093. ** sqlite3changeset_apply_v2() calls were made.
  12094. ** <li> Each local changeset is rebased by calling sqlite3rebaser_rebase().
  12095. ** <li> The sqlite3_rebaser object is deleted by calling
  12096. ** sqlite3rebaser_delete().
  12097. ** </ol>
  12098. */
  12099. typedef struct sqlite3_rebaser sqlite3_rebaser;
  12100. /*
  12101. ** CAPI3REF: Create a changeset rebaser object.
  12102. ** EXPERIMENTAL
  12103. **
  12104. ** Allocate a new changeset rebaser object. If successful, set (*ppNew) to
  12105. ** point to the new object and return SQLITE_OK. Otherwise, if an error
  12106. ** occurs, return an SQLite error code (e.g. SQLITE_NOMEM) and set (*ppNew)
  12107. ** to NULL.
  12108. */
  12109. SQLITE_API int sqlite3rebaser_create(sqlite3_rebaser **ppNew);
  12110. /*
  12111. ** CAPI3REF: Configure a changeset rebaser object.
  12112. ** EXPERIMENTAL
  12113. **
  12114. ** Configure the changeset rebaser object to rebase changesets according
  12115. ** to the conflict resolutions described by buffer pRebase (size nRebase
  12116. ** bytes), which must have been obtained from a previous call to
  12117. ** sqlite3changeset_apply_v2().
  12118. */
  12119. SQLITE_API int sqlite3rebaser_configure(
  12120. sqlite3_rebaser*,
  12121. int nRebase, const void *pRebase
  12122. );
  12123. /*
  12124. ** CAPI3REF: Rebase a changeset
  12125. ** EXPERIMENTAL
  12126. **
  12127. ** Argument pIn must point to a buffer containing a changeset nIn bytes
  12128. ** in size. This function allocates and populates a buffer with a copy
  12129. ** of the changeset rebased according to the configuration of the
  12130. ** rebaser object passed as the first argument. If successful, (*ppOut)
  12131. ** is set to point to the new buffer containing the rebased changeset and
  12132. ** (*pnOut) to its size in bytes and SQLITE_OK returned. It is the
  12133. ** responsibility of the caller to eventually free the new buffer using
  12134. ** sqlite3_free(). Otherwise, if an error occurs, (*ppOut) and (*pnOut)
  12135. ** are set to zero and an SQLite error code returned.
  12136. */
  12137. SQLITE_API int sqlite3rebaser_rebase(
  12138. sqlite3_rebaser*,
  12139. int nIn, const void *pIn,
  12140. int *pnOut, void **ppOut
  12141. );
  12142. /*
  12143. ** CAPI3REF: Delete a changeset rebaser object.
  12144. ** EXPERIMENTAL
  12145. **
  12146. ** Delete the changeset rebaser object and all associated resources. There
  12147. ** should be one call to this function for each successful invocation
  12148. ** of sqlite3rebaser_create().
  12149. */
  12150. SQLITE_API void sqlite3rebaser_delete(sqlite3_rebaser *p);
  12151. /*
  12152. ** CAPI3REF: Streaming Versions of API functions.
  12153. **
  12154. ** The six streaming API xxx_strm() functions serve similar purposes to the
  12155. ** corresponding non-streaming API functions:
  12156. **
  12157. ** <table border=1 style="margin-left:8ex;margin-right:8ex">
  12158. ** <tr><th>Streaming function<th>Non-streaming equivalent</th>
  12159. ** <tr><td>sqlite3changeset_apply_strm<td>[sqlite3changeset_apply]
  12160. ** <tr><td>sqlite3changeset_apply_strm_v2<td>[sqlite3changeset_apply_v2]
  12161. ** <tr><td>sqlite3changeset_concat_strm<td>[sqlite3changeset_concat]
  12162. ** <tr><td>sqlite3changeset_invert_strm<td>[sqlite3changeset_invert]
  12163. ** <tr><td>sqlite3changeset_start_strm<td>[sqlite3changeset_start]
  12164. ** <tr><td>sqlite3session_changeset_strm<td>[sqlite3session_changeset]
  12165. ** <tr><td>sqlite3session_patchset_strm<td>[sqlite3session_patchset]
  12166. ** </table>
  12167. **
  12168. ** Non-streaming functions that accept changesets (or patchsets) as input
  12169. ** require that the entire changeset be stored in a single buffer in memory.
  12170. ** Similarly, those that return a changeset or patchset do so by returning
  12171. ** a pointer to a single large buffer allocated using sqlite3_malloc().
  12172. ** Normally this is convenient. However, if an application running in a
  12173. ** low-memory environment is required to handle very large changesets, the
  12174. ** large contiguous memory allocations required can become onerous.
  12175. **
  12176. ** In order to avoid this problem, instead of a single large buffer, input
  12177. ** is passed to a streaming API functions by way of a callback function that
  12178. ** the sessions module invokes to incrementally request input data as it is
  12179. ** required. In all cases, a pair of API function parameters such as
  12180. **
  12181. ** <pre>
  12182. ** &nbsp; int nChangeset,
  12183. ** &nbsp; void *pChangeset,
  12184. ** </pre>
  12185. **
  12186. ** Is replaced by:
  12187. **
  12188. ** <pre>
  12189. ** &nbsp; int (*xInput)(void *pIn, void *pData, int *pnData),
  12190. ** &nbsp; void *pIn,
  12191. ** </pre>
  12192. **
  12193. ** Each time the xInput callback is invoked by the sessions module, the first
  12194. ** argument passed is a copy of the supplied pIn context pointer. The second
  12195. ** argument, pData, points to a buffer (*pnData) bytes in size. Assuming no
  12196. ** error occurs the xInput method should copy up to (*pnData) bytes of data
  12197. ** into the buffer and set (*pnData) to the actual number of bytes copied
  12198. ** before returning SQLITE_OK. If the input is completely exhausted, (*pnData)
  12199. ** should be set to zero to indicate this. Or, if an error occurs, an SQLite
  12200. ** error code should be returned. In all cases, if an xInput callback returns
  12201. ** an error, all processing is abandoned and the streaming API function
  12202. ** returns a copy of the error code to the caller.
  12203. **
  12204. ** In the case of sqlite3changeset_start_strm(), the xInput callback may be
  12205. ** invoked by the sessions module at any point during the lifetime of the
  12206. ** iterator. If such an xInput callback returns an error, the iterator enters
  12207. ** an error state, whereby all subsequent calls to iterator functions
  12208. ** immediately fail with the same error code as returned by xInput.
  12209. **
  12210. ** Similarly, streaming API functions that return changesets (or patchsets)
  12211. ** return them in chunks by way of a callback function instead of via a
  12212. ** pointer to a single large buffer. In this case, a pair of parameters such
  12213. ** as:
  12214. **
  12215. ** <pre>
  12216. ** &nbsp; int *pnChangeset,
  12217. ** &nbsp; void **ppChangeset,
  12218. ** </pre>
  12219. **
  12220. ** Is replaced by:
  12221. **
  12222. ** <pre>
  12223. ** &nbsp; int (*xOutput)(void *pOut, const void *pData, int nData),
  12224. ** &nbsp; void *pOut
  12225. ** </pre>
  12226. **
  12227. ** The xOutput callback is invoked zero or more times to return data to
  12228. ** the application. The first parameter passed to each call is a copy of the
  12229. ** pOut pointer supplied by the application. The second parameter, pData,
  12230. ** points to a buffer nData bytes in size containing the chunk of output
  12231. ** data being returned. If the xOutput callback successfully processes the
  12232. ** supplied data, it should return SQLITE_OK to indicate success. Otherwise,
  12233. ** it should return some other SQLite error code. In this case processing
  12234. ** is immediately abandoned and the streaming API function returns a copy
  12235. ** of the xOutput error code to the application.
  12236. **
  12237. ** The sessions module never invokes an xOutput callback with the third
  12238. ** parameter set to a value less than or equal to zero. Other than this,
  12239. ** no guarantees are made as to the size of the chunks of data returned.
  12240. */
  12241. SQLITE_API int sqlite3changeset_apply_strm(
  12242. sqlite3 *db, /* Apply change to "main" db of this handle */
  12243. int (*xInput)(void *pIn, void *pData, int *pnData), /* Input function */
  12244. void *pIn, /* First arg for xInput */
  12245. int(*xFilter)(
  12246. void *pCtx, /* Copy of sixth arg to _apply() */
  12247. const char *zTab /* Table name */
  12248. ),
  12249. int(*xConflict)(
  12250. void *pCtx, /* Copy of sixth arg to _apply() */
  12251. int eConflict, /* DATA, MISSING, CONFLICT, CONSTRAINT */
  12252. sqlite3_changeset_iter *p /* Handle describing change and conflict */
  12253. ),
  12254. void *pCtx /* First argument passed to xConflict */
  12255. );
  12256. SQLITE_API int sqlite3changeset_apply_v2_strm(
  12257. sqlite3 *db, /* Apply change to "main" db of this handle */
  12258. int (*xInput)(void *pIn, void *pData, int *pnData), /* Input function */
  12259. void *pIn, /* First arg for xInput */
  12260. int(*xFilter)(
  12261. void *pCtx, /* Copy of sixth arg to _apply() */
  12262. const char *zTab /* Table name */
  12263. ),
  12264. int(*xConflict)(
  12265. void *pCtx, /* Copy of sixth arg to _apply() */
  12266. int eConflict, /* DATA, MISSING, CONFLICT, CONSTRAINT */
  12267. sqlite3_changeset_iter *p /* Handle describing change and conflict */
  12268. ),
  12269. void *pCtx, /* First argument passed to xConflict */
  12270. void **ppRebase, int *pnRebase,
  12271. int flags
  12272. );
  12273. SQLITE_API int sqlite3changeset_concat_strm(
  12274. int (*xInputA)(void *pIn, void *pData, int *pnData),
  12275. void *pInA,
  12276. int (*xInputB)(void *pIn, void *pData, int *pnData),
  12277. void *pInB,
  12278. int (*xOutput)(void *pOut, const void *pData, int nData),
  12279. void *pOut
  12280. );
  12281. SQLITE_API int sqlite3changeset_invert_strm(
  12282. int (*xInput)(void *pIn, void *pData, int *pnData),
  12283. void *pIn,
  12284. int (*xOutput)(void *pOut, const void *pData, int nData),
  12285. void *pOut
  12286. );
  12287. SQLITE_API int sqlite3changeset_start_strm(
  12288. sqlite3_changeset_iter **pp,
  12289. int (*xInput)(void *pIn, void *pData, int *pnData),
  12290. void *pIn
  12291. );
  12292. SQLITE_API int sqlite3changeset_start_v2_strm(
  12293. sqlite3_changeset_iter **pp,
  12294. int (*xInput)(void *pIn, void *pData, int *pnData),
  12295. void *pIn,
  12296. int flags
  12297. );
  12298. SQLITE_API int sqlite3session_changeset_strm(
  12299. sqlite3_session *pSession,
  12300. int (*xOutput)(void *pOut, const void *pData, int nData),
  12301. void *pOut
  12302. );
  12303. SQLITE_API int sqlite3session_patchset_strm(
  12304. sqlite3_session *pSession,
  12305. int (*xOutput)(void *pOut, const void *pData, int nData),
  12306. void *pOut
  12307. );
  12308. SQLITE_API int sqlite3changegroup_add_strm(sqlite3_changegroup*,
  12309. int (*xInput)(void *pIn, void *pData, int *pnData),
  12310. void *pIn
  12311. );
  12312. SQLITE_API int sqlite3changegroup_output_strm(sqlite3_changegroup*,
  12313. int (*xOutput)(void *pOut, const void *pData, int nData),
  12314. void *pOut
  12315. );
  12316. SQLITE_API int sqlite3rebaser_rebase_strm(
  12317. sqlite3_rebaser *pRebaser,
  12318. int (*xInput)(void *pIn, void *pData, int *pnData),
  12319. void *pIn,
  12320. int (*xOutput)(void *pOut, const void *pData, int nData),
  12321. void *pOut
  12322. );
  12323. /*
  12324. ** CAPI3REF: Configure global parameters
  12325. **
  12326. ** The sqlite3session_config() interface is used to make global configuration
  12327. ** changes to the sessions module in order to tune it to the specific needs
  12328. ** of the application.
  12329. **
  12330. ** The sqlite3session_config() interface is not threadsafe. If it is invoked
  12331. ** while any other thread is inside any other sessions method then the
  12332. ** results are undefined. Furthermore, if it is invoked after any sessions
  12333. ** related objects have been created, the results are also undefined.
  12334. **
  12335. ** The first argument to the sqlite3session_config() function must be one
  12336. ** of the SQLITE_SESSION_CONFIG_XXX constants defined below. The
  12337. ** interpretation of the (void*) value passed as the second parameter and
  12338. ** the effect of calling this function depends on the value of the first
  12339. ** parameter.
  12340. **
  12341. ** <dl>
  12342. ** <dt>SQLITE_SESSION_CONFIG_STRMSIZE<dd>
  12343. ** By default, the sessions module streaming interfaces attempt to input
  12344. ** and output data in approximately 1 KiB chunks. This operand may be used
  12345. ** to set and query the value of this configuration setting. The pointer
  12346. ** passed as the second argument must point to a value of type (int).
  12347. ** If this value is greater than 0, it is used as the new streaming data
  12348. ** chunk size for both input and output. Before returning, the (int) value
  12349. ** pointed to by pArg is set to the final value of the streaming interface
  12350. ** chunk size.
  12351. ** </dl>
  12352. **
  12353. ** This function returns SQLITE_OK if successful, or an SQLite error code
  12354. ** otherwise.
  12355. */
  12356. SQLITE_API int sqlite3session_config(int op, void *pArg);
  12357. /*
  12358. ** CAPI3REF: Values for sqlite3session_config().
  12359. */
  12360. #define SQLITE_SESSION_CONFIG_STRMSIZE 1
  12361. /*
  12362. ** Make sure we can call this stuff from C++.
  12363. */
  12364. #ifdef __cplusplus
  12365. }
  12366. #endif
  12367. #endif /* !defined(__SQLITESESSION_H_) && defined(SQLITE_ENABLE_SESSION) */
  12368. /******** End of sqlite3session.h *********/
  12369. /******** Begin file fts5.h *********/
  12370. /*
  12371. ** 2014 May 31
  12372. **
  12373. ** The author disclaims copyright to this source code. In place of
  12374. ** a legal notice, here is a blessing:
  12375. **
  12376. ** May you do good and not evil.
  12377. ** May you find forgiveness for yourself and forgive others.
  12378. ** May you share freely, never taking more than you give.
  12379. **
  12380. ******************************************************************************
  12381. **
  12382. ** Interfaces to extend FTS5. Using the interfaces defined in this file,
  12383. ** FTS5 may be extended with:
  12384. **
  12385. ** * custom tokenizers, and
  12386. ** * custom auxiliary functions.
  12387. */
  12388. #ifndef _FTS5_H
  12389. #define _FTS5_H
  12390. #ifdef __cplusplus
  12391. extern "C" {
  12392. #endif
  12393. /*************************************************************************
  12394. ** CUSTOM AUXILIARY FUNCTIONS
  12395. **
  12396. ** Virtual table implementations may overload SQL functions by implementing
  12397. ** the sqlite3_module.xFindFunction() method.
  12398. */
  12399. typedef struct Fts5ExtensionApi Fts5ExtensionApi;
  12400. typedef struct Fts5Context Fts5Context;
  12401. typedef struct Fts5PhraseIter Fts5PhraseIter;
  12402. typedef void (*fts5_extension_function)(
  12403. const Fts5ExtensionApi *pApi, /* API offered by current FTS version */
  12404. Fts5Context *pFts, /* First arg to pass to pApi functions */
  12405. sqlite3_context *pCtx, /* Context for returning result/error */
  12406. int nVal, /* Number of values in apVal[] array */
  12407. sqlite3_value **apVal /* Array of trailing arguments */
  12408. );
  12409. struct Fts5PhraseIter {
  12410. const unsigned char *a;
  12411. const unsigned char *b;
  12412. };
  12413. /*
  12414. ** EXTENSION API FUNCTIONS
  12415. **
  12416. ** xUserData(pFts):
  12417. ** Return a copy of the context pointer the extension function was
  12418. ** registered with.
  12419. **
  12420. ** xColumnTotalSize(pFts, iCol, pnToken):
  12421. ** If parameter iCol is less than zero, set output variable *pnToken
  12422. ** to the total number of tokens in the FTS5 table. Or, if iCol is
  12423. ** non-negative but less than the number of columns in the table, return
  12424. ** the total number of tokens in column iCol, considering all rows in
  12425. ** the FTS5 table.
  12426. **
  12427. ** If parameter iCol is greater than or equal to the number of columns
  12428. ** in the table, SQLITE_RANGE is returned. Or, if an error occurs (e.g.
  12429. ** an OOM condition or IO error), an appropriate SQLite error code is
  12430. ** returned.
  12431. **
  12432. ** xColumnCount(pFts):
  12433. ** Return the number of columns in the table.
  12434. **
  12435. ** xColumnSize(pFts, iCol, pnToken):
  12436. ** If parameter iCol is less than zero, set output variable *pnToken
  12437. ** to the total number of tokens in the current row. Or, if iCol is
  12438. ** non-negative but less than the number of columns in the table, set
  12439. ** *pnToken to the number of tokens in column iCol of the current row.
  12440. **
  12441. ** If parameter iCol is greater than or equal to the number of columns
  12442. ** in the table, SQLITE_RANGE is returned. Or, if an error occurs (e.g.
  12443. ** an OOM condition or IO error), an appropriate SQLite error code is
  12444. ** returned.
  12445. **
  12446. ** This function may be quite inefficient if used with an FTS5 table
  12447. ** created with the "columnsize=0" option.
  12448. **
  12449. ** xColumnText:
  12450. ** This function attempts to retrieve the text of column iCol of the
  12451. ** current document. If successful, (*pz) is set to point to a buffer
  12452. ** containing the text in utf-8 encoding, (*pn) is set to the size in bytes
  12453. ** (not characters) of the buffer and SQLITE_OK is returned. Otherwise,
  12454. ** if an error occurs, an SQLite error code is returned and the final values
  12455. ** of (*pz) and (*pn) are undefined.
  12456. **
  12457. ** xPhraseCount:
  12458. ** Returns the number of phrases in the current query expression.
  12459. **
  12460. ** xPhraseSize:
  12461. ** Returns the number of tokens in phrase iPhrase of the query. Phrases
  12462. ** are numbered starting from zero.
  12463. **
  12464. ** xInstCount:
  12465. ** Set *pnInst to the total number of occurrences of all phrases within
  12466. ** the query within the current row. Return SQLITE_OK if successful, or
  12467. ** an error code (i.e. SQLITE_NOMEM) if an error occurs.
  12468. **
  12469. ** This API can be quite slow if used with an FTS5 table created with the
  12470. ** "detail=none" or "detail=column" option. If the FTS5 table is created
  12471. ** with either "detail=none" or "detail=column" and "content=" option
  12472. ** (i.e. if it is a contentless table), then this API always returns 0.
  12473. **
  12474. ** xInst:
  12475. ** Query for the details of phrase match iIdx within the current row.
  12476. ** Phrase matches are numbered starting from zero, so the iIdx argument
  12477. ** should be greater than or equal to zero and smaller than the value
  12478. ** output by xInstCount().
  12479. **
  12480. ** Usually, output parameter *piPhrase is set to the phrase number, *piCol
  12481. ** to the column in which it occurs and *piOff the token offset of the
  12482. ** first token of the phrase. Returns SQLITE_OK if successful, or an error
  12483. ** code (i.e. SQLITE_NOMEM) if an error occurs.
  12484. **
  12485. ** This API can be quite slow if used with an FTS5 table created with the
  12486. ** "detail=none" or "detail=column" option.
  12487. **
  12488. ** xRowid:
  12489. ** Returns the rowid of the current row.
  12490. **
  12491. ** xTokenize:
  12492. ** Tokenize text using the tokenizer belonging to the FTS5 table.
  12493. **
  12494. ** xQueryPhrase(pFts5, iPhrase, pUserData, xCallback):
  12495. ** This API function is used to query the FTS table for phrase iPhrase
  12496. ** of the current query. Specifically, a query equivalent to:
  12497. **
  12498. ** ... FROM ftstable WHERE ftstable MATCH $p ORDER BY rowid
  12499. **
  12500. ** with $p set to a phrase equivalent to the phrase iPhrase of the
  12501. ** current query is executed. Any column filter that applies to
  12502. ** phrase iPhrase of the current query is included in $p. For each
  12503. ** row visited, the callback function passed as the fourth argument
  12504. ** is invoked. The context and API objects passed to the callback
  12505. ** function may be used to access the properties of each matched row.
  12506. ** Invoking Api.xUserData() returns a copy of the pointer passed as
  12507. ** the third argument to pUserData.
  12508. **
  12509. ** If the callback function returns any value other than SQLITE_OK, the
  12510. ** query is abandoned and the xQueryPhrase function returns immediately.
  12511. ** If the returned value is SQLITE_DONE, xQueryPhrase returns SQLITE_OK.
  12512. ** Otherwise, the error code is propagated upwards.
  12513. **
  12514. ** If the query runs to completion without incident, SQLITE_OK is returned.
  12515. ** Or, if some error occurs before the query completes or is aborted by
  12516. ** the callback, an SQLite error code is returned.
  12517. **
  12518. **
  12519. ** xSetAuxdata(pFts5, pAux, xDelete)
  12520. **
  12521. ** Save the pointer passed as the second argument as the extension function's
  12522. ** "auxiliary data". The pointer may then be retrieved by the current or any
  12523. ** future invocation of the same fts5 extension function made as part of
  12524. ** the same MATCH query using the xGetAuxdata() API.
  12525. **
  12526. ** Each extension function is allocated a single auxiliary data slot for
  12527. ** each FTS query (MATCH expression). If the extension function is invoked
  12528. ** more than once for a single FTS query, then all invocations share a
  12529. ** single auxiliary data context.
  12530. **
  12531. ** If there is already an auxiliary data pointer when this function is
  12532. ** invoked, then it is replaced by the new pointer. If an xDelete callback
  12533. ** was specified along with the original pointer, it is invoked at this
  12534. ** point.
  12535. **
  12536. ** The xDelete callback, if one is specified, is also invoked on the
  12537. ** auxiliary data pointer after the FTS5 query has finished.
  12538. **
  12539. ** If an error (e.g. an OOM condition) occurs within this function,
  12540. ** the auxiliary data is set to NULL and an error code returned. If the
  12541. ** xDelete parameter was not NULL, it is invoked on the auxiliary data
  12542. ** pointer before returning.
  12543. **
  12544. **
  12545. ** xGetAuxdata(pFts5, bClear)
  12546. **
  12547. ** Returns the current auxiliary data pointer for the fts5 extension
  12548. ** function. See the xSetAuxdata() method for details.
  12549. **
  12550. ** If the bClear argument is non-zero, then the auxiliary data is cleared
  12551. ** (set to NULL) before this function returns. In this case the xDelete,
  12552. ** if any, is not invoked.
  12553. **
  12554. **
  12555. ** xRowCount(pFts5, pnRow)
  12556. **
  12557. ** This function is used to retrieve the total number of rows in the table.
  12558. ** In other words, the same value that would be returned by:
  12559. **
  12560. ** SELECT count(*) FROM ftstable;
  12561. **
  12562. ** xPhraseFirst()
  12563. ** This function is used, along with type Fts5PhraseIter and the xPhraseNext
  12564. ** method, to iterate through all instances of a single query phrase within
  12565. ** the current row. This is the same information as is accessible via the
  12566. ** xInstCount/xInst APIs. While the xInstCount/xInst APIs are more convenient
  12567. ** to use, this API may be faster under some circumstances. To iterate
  12568. ** through instances of phrase iPhrase, use the following code:
  12569. **
  12570. ** Fts5PhraseIter iter;
  12571. ** int iCol, iOff;
  12572. ** for(pApi->xPhraseFirst(pFts, iPhrase, &iter, &iCol, &iOff);
  12573. ** iCol>=0;
  12574. ** pApi->xPhraseNext(pFts, &iter, &iCol, &iOff)
  12575. ** ){
  12576. ** // An instance of phrase iPhrase at offset iOff of column iCol
  12577. ** }
  12578. **
  12579. ** The Fts5PhraseIter structure is defined above. Applications should not
  12580. ** modify this structure directly - it should only be used as shown above
  12581. ** with the xPhraseFirst() and xPhraseNext() API methods (and by
  12582. ** xPhraseFirstColumn() and xPhraseNextColumn() as illustrated below).
  12583. **
  12584. ** This API can be quite slow if used with an FTS5 table created with the
  12585. ** "detail=none" or "detail=column" option. If the FTS5 table is created
  12586. ** with either "detail=none" or "detail=column" and "content=" option
  12587. ** (i.e. if it is a contentless table), then this API always iterates
  12588. ** through an empty set (all calls to xPhraseFirst() set iCol to -1).
  12589. **
  12590. ** xPhraseNext()
  12591. ** See xPhraseFirst above.
  12592. **
  12593. ** xPhraseFirstColumn()
  12594. ** This function and xPhraseNextColumn() are similar to the xPhraseFirst()
  12595. ** and xPhraseNext() APIs described above. The difference is that instead
  12596. ** of iterating through all instances of a phrase in the current row, these
  12597. ** APIs are used to iterate through the set of columns in the current row
  12598. ** that contain one or more instances of a specified phrase. For example:
  12599. **
  12600. ** Fts5PhraseIter iter;
  12601. ** int iCol;
  12602. ** for(pApi->xPhraseFirstColumn(pFts, iPhrase, &iter, &iCol);
  12603. ** iCol>=0;
  12604. ** pApi->xPhraseNextColumn(pFts, &iter, &iCol)
  12605. ** ){
  12606. ** // Column iCol contains at least one instance of phrase iPhrase
  12607. ** }
  12608. **
  12609. ** This API can be quite slow if used with an FTS5 table created with the
  12610. ** "detail=none" option. If the FTS5 table is created with either
  12611. ** "detail=none" "content=" option (i.e. if it is a contentless table),
  12612. ** then this API always iterates through an empty set (all calls to
  12613. ** xPhraseFirstColumn() set iCol to -1).
  12614. **
  12615. ** The information accessed using this API and its companion
  12616. ** xPhraseFirstColumn() may also be obtained using xPhraseFirst/xPhraseNext
  12617. ** (or xInst/xInstCount). The chief advantage of this API is that it is
  12618. ** significantly more efficient than those alternatives when used with
  12619. ** "detail=column" tables.
  12620. **
  12621. ** xPhraseNextColumn()
  12622. ** See xPhraseFirstColumn above.
  12623. */
  12624. struct Fts5ExtensionApi {
  12625. int iVersion; /* Currently always set to 2 */
  12626. void *(*xUserData)(Fts5Context*);
  12627. int (*xColumnCount)(Fts5Context*);
  12628. int (*xRowCount)(Fts5Context*, sqlite3_int64 *pnRow);
  12629. int (*xColumnTotalSize)(Fts5Context*, int iCol, sqlite3_int64 *pnToken);
  12630. int (*xTokenize)(Fts5Context*,
  12631. const char *pText, int nText, /* Text to tokenize */
  12632. void *pCtx, /* Context passed to xToken() */
  12633. int (*xToken)(void*, int, const char*, int, int, int) /* Callback */
  12634. );
  12635. int (*xPhraseCount)(Fts5Context*);
  12636. int (*xPhraseSize)(Fts5Context*, int iPhrase);
  12637. int (*xInstCount)(Fts5Context*, int *pnInst);
  12638. int (*xInst)(Fts5Context*, int iIdx, int *piPhrase, int *piCol, int *piOff);
  12639. sqlite3_int64 (*xRowid)(Fts5Context*);
  12640. int (*xColumnText)(Fts5Context*, int iCol, const char **pz, int *pn);
  12641. int (*xColumnSize)(Fts5Context*, int iCol, int *pnToken);
  12642. int (*xQueryPhrase)(Fts5Context*, int iPhrase, void *pUserData,
  12643. int(*)(const Fts5ExtensionApi*,Fts5Context*,void*)
  12644. );
  12645. int (*xSetAuxdata)(Fts5Context*, void *pAux, void(*xDelete)(void*));
  12646. void *(*xGetAuxdata)(Fts5Context*, int bClear);
  12647. int (*xPhraseFirst)(Fts5Context*, int iPhrase, Fts5PhraseIter*, int*, int*);
  12648. void (*xPhraseNext)(Fts5Context*, Fts5PhraseIter*, int *piCol, int *piOff);
  12649. int (*xPhraseFirstColumn)(Fts5Context*, int iPhrase, Fts5PhraseIter*, int*);
  12650. void (*xPhraseNextColumn)(Fts5Context*, Fts5PhraseIter*, int *piCol);
  12651. };
  12652. /*
  12653. ** CUSTOM AUXILIARY FUNCTIONS
  12654. *************************************************************************/
  12655. /*************************************************************************
  12656. ** CUSTOM TOKENIZERS
  12657. **
  12658. ** Applications may also register custom tokenizer types. A tokenizer
  12659. ** is registered by providing fts5 with a populated instance of the
  12660. ** following structure. All structure methods must be defined, setting
  12661. ** any member of the fts5_tokenizer struct to NULL leads to undefined
  12662. ** behaviour. The structure methods are expected to function as follows:
  12663. **
  12664. ** xCreate:
  12665. ** This function is used to allocate and initialize a tokenizer instance.
  12666. ** A tokenizer instance is required to actually tokenize text.
  12667. **
  12668. ** The first argument passed to this function is a copy of the (void*)
  12669. ** pointer provided by the application when the fts5_tokenizer object
  12670. ** was registered with FTS5 (the third argument to xCreateTokenizer()).
  12671. ** The second and third arguments are an array of nul-terminated strings
  12672. ** containing the tokenizer arguments, if any, specified following the
  12673. ** tokenizer name as part of the CREATE VIRTUAL TABLE statement used
  12674. ** to create the FTS5 table.
  12675. **
  12676. ** The final argument is an output variable. If successful, (*ppOut)
  12677. ** should be set to point to the new tokenizer handle and SQLITE_OK
  12678. ** returned. If an error occurs, some value other than SQLITE_OK should
  12679. ** be returned. In this case, fts5 assumes that the final value of *ppOut
  12680. ** is undefined.
  12681. **
  12682. ** xDelete:
  12683. ** This function is invoked to delete a tokenizer handle previously
  12684. ** allocated using xCreate(). Fts5 guarantees that this function will
  12685. ** be invoked exactly once for each successful call to xCreate().
  12686. **
  12687. ** xTokenize:
  12688. ** This function is expected to tokenize the nText byte string indicated
  12689. ** by argument pText. pText may or may not be nul-terminated. The first
  12690. ** argument passed to this function is a pointer to an Fts5Tokenizer object
  12691. ** returned by an earlier call to xCreate().
  12692. **
  12693. ** The second argument indicates the reason that FTS5 is requesting
  12694. ** tokenization of the supplied text. This is always one of the following
  12695. ** four values:
  12696. **
  12697. ** <ul><li> <b>FTS5_TOKENIZE_DOCUMENT</b> - A document is being inserted into
  12698. ** or removed from the FTS table. The tokenizer is being invoked to
  12699. ** determine the set of tokens to add to (or delete from) the
  12700. ** FTS index.
  12701. **
  12702. ** <li> <b>FTS5_TOKENIZE_QUERY</b> - A MATCH query is being executed
  12703. ** against the FTS index. The tokenizer is being called to tokenize
  12704. ** a bareword or quoted string specified as part of the query.
  12705. **
  12706. ** <li> <b>(FTS5_TOKENIZE_QUERY | FTS5_TOKENIZE_PREFIX)</b> - Same as
  12707. ** FTS5_TOKENIZE_QUERY, except that the bareword or quoted string is
  12708. ** followed by a "*" character, indicating that the last token
  12709. ** returned by the tokenizer will be treated as a token prefix.
  12710. **
  12711. ** <li> <b>FTS5_TOKENIZE_AUX</b> - The tokenizer is being invoked to
  12712. ** satisfy an fts5_api.xTokenize() request made by an auxiliary
  12713. ** function. Or an fts5_api.xColumnSize() request made by the same
  12714. ** on a columnsize=0 database.
  12715. ** </ul>
  12716. **
  12717. ** For each token in the input string, the supplied callback xToken() must
  12718. ** be invoked. The first argument to it should be a copy of the pointer
  12719. ** passed as the second argument to xTokenize(). The third and fourth
  12720. ** arguments are a pointer to a buffer containing the token text, and the
  12721. ** size of the token in bytes. The 4th and 5th arguments are the byte offsets
  12722. ** of the first byte of and first byte immediately following the text from
  12723. ** which the token is derived within the input.
  12724. **
  12725. ** The second argument passed to the xToken() callback ("tflags") should
  12726. ** normally be set to 0. The exception is if the tokenizer supports
  12727. ** synonyms. In this case see the discussion below for details.
  12728. **
  12729. ** FTS5 assumes the xToken() callback is invoked for each token in the
  12730. ** order that they occur within the input text.
  12731. **
  12732. ** If an xToken() callback returns any value other than SQLITE_OK, then
  12733. ** the tokenization should be abandoned and the xTokenize() method should
  12734. ** immediately return a copy of the xToken() return value. Or, if the
  12735. ** input buffer is exhausted, xTokenize() should return SQLITE_OK. Finally,
  12736. ** if an error occurs with the xTokenize() implementation itself, it
  12737. ** may abandon the tokenization and return any error code other than
  12738. ** SQLITE_OK or SQLITE_DONE.
  12739. **
  12740. ** SYNONYM SUPPORT
  12741. **
  12742. ** Custom tokenizers may also support synonyms. Consider a case in which a
  12743. ** user wishes to query for a phrase such as "first place". Using the
  12744. ** built-in tokenizers, the FTS5 query 'first + place' will match instances
  12745. ** of "first place" within the document set, but not alternative forms
  12746. ** such as "1st place". In some applications, it would be better to match
  12747. ** all instances of "first place" or "1st place" regardless of which form
  12748. ** the user specified in the MATCH query text.
  12749. **
  12750. ** There are several ways to approach this in FTS5:
  12751. **
  12752. ** <ol><li> By mapping all synonyms to a single token. In this case, using
  12753. ** the above example, this means that the tokenizer returns the
  12754. ** same token for inputs "first" and "1st". Say that token is in
  12755. ** fact "first", so that when the user inserts the document "I won
  12756. ** 1st place" entries are added to the index for tokens "i", "won",
  12757. ** "first" and "place". If the user then queries for '1st + place',
  12758. ** the tokenizer substitutes "first" for "1st" and the query works
  12759. ** as expected.
  12760. **
  12761. ** <li> By querying the index for all synonyms of each query term
  12762. ** separately. In this case, when tokenizing query text, the
  12763. ** tokenizer may provide multiple synonyms for a single term
  12764. ** within the document. FTS5 then queries the index for each
  12765. ** synonym individually. For example, faced with the query:
  12766. **
  12767. ** <codeblock>
  12768. ** ... MATCH 'first place'</codeblock>
  12769. **
  12770. ** the tokenizer offers both "1st" and "first" as synonyms for the
  12771. ** first token in the MATCH query and FTS5 effectively runs a query
  12772. ** similar to:
  12773. **
  12774. ** <codeblock>
  12775. ** ... MATCH '(first OR 1st) place'</codeblock>
  12776. **
  12777. ** except that, for the purposes of auxiliary functions, the query
  12778. ** still appears to contain just two phrases - "(first OR 1st)"
  12779. ** being treated as a single phrase.
  12780. **
  12781. ** <li> By adding multiple synonyms for a single term to the FTS index.
  12782. ** Using this method, when tokenizing document text, the tokenizer
  12783. ** provides multiple synonyms for each token. So that when a
  12784. ** document such as "I won first place" is tokenized, entries are
  12785. ** added to the FTS index for "i", "won", "first", "1st" and
  12786. ** "place".
  12787. **
  12788. ** This way, even if the tokenizer does not provide synonyms
  12789. ** when tokenizing query text (it should not - to do so would be
  12790. ** inefficient), it doesn't matter if the user queries for
  12791. ** 'first + place' or '1st + place', as there are entries in the
  12792. ** FTS index corresponding to both forms of the first token.
  12793. ** </ol>
  12794. **
  12795. ** Whether it is parsing document or query text, any call to xToken that
  12796. ** specifies a <i>tflags</i> argument with the FTS5_TOKEN_COLOCATED bit
  12797. ** is considered to supply a synonym for the previous token. For example,
  12798. ** when parsing the document "I won first place", a tokenizer that supports
  12799. ** synonyms would call xToken() 5 times, as follows:
  12800. **
  12801. ** <codeblock>
  12802. ** xToken(pCtx, 0, "i", 1, 0, 1);
  12803. ** xToken(pCtx, 0, "won", 3, 2, 5);
  12804. ** xToken(pCtx, 0, "first", 5, 6, 11);
  12805. ** xToken(pCtx, FTS5_TOKEN_COLOCATED, "1st", 3, 6, 11);
  12806. ** xToken(pCtx, 0, "place", 5, 12, 17);
  12807. **</codeblock>
  12808. **
  12809. ** It is an error to specify the FTS5_TOKEN_COLOCATED flag the first time
  12810. ** xToken() is called. Multiple synonyms may be specified for a single token
  12811. ** by making multiple calls to xToken(FTS5_TOKEN_COLOCATED) in sequence.
  12812. ** There is no limit to the number of synonyms that may be provided for a
  12813. ** single token.
  12814. **
  12815. ** In many cases, method (1) above is the best approach. It does not add
  12816. ** extra data to the FTS index or require FTS5 to query for multiple terms,
  12817. ** so it is efficient in terms of disk space and query speed. However, it
  12818. ** does not support prefix queries very well. If, as suggested above, the
  12819. ** token "first" is substituted for "1st" by the tokenizer, then the query:
  12820. **
  12821. ** <codeblock>
  12822. ** ... MATCH '1s*'</codeblock>
  12823. **
  12824. ** will not match documents that contain the token "1st" (as the tokenizer
  12825. ** will probably not map "1s" to any prefix of "first").
  12826. **
  12827. ** For full prefix support, method (3) may be preferred. In this case,
  12828. ** because the index contains entries for both "first" and "1st", prefix
  12829. ** queries such as 'fi*' or '1s*' will match correctly. However, because
  12830. ** extra entries are added to the FTS index, this method uses more space
  12831. ** within the database.
  12832. **
  12833. ** Method (2) offers a midpoint between (1) and (3). Using this method,
  12834. ** a query such as '1s*' will match documents that contain the literal
  12835. ** token "1st", but not "first" (assuming the tokenizer is not able to
  12836. ** provide synonyms for prefixes). However, a non-prefix query like '1st'
  12837. ** will match against "1st" and "first". This method does not require
  12838. ** extra disk space, as no extra entries are added to the FTS index.
  12839. ** On the other hand, it may require more CPU cycles to run MATCH queries,
  12840. ** as separate queries of the FTS index are required for each synonym.
  12841. **
  12842. ** When using methods (2) or (3), it is important that the tokenizer only
  12843. ** provide synonyms when tokenizing document text (method (3)) or query
  12844. ** text (method (2)), not both. Doing so will not cause any errors, but is
  12845. ** inefficient.
  12846. */
  12847. typedef struct Fts5Tokenizer Fts5Tokenizer;
  12848. typedef struct fts5_tokenizer fts5_tokenizer;
  12849. struct fts5_tokenizer {
  12850. int (*xCreate)(void*, const char **azArg, int nArg, Fts5Tokenizer **ppOut);
  12851. void (*xDelete)(Fts5Tokenizer*);
  12852. int (*xTokenize)(Fts5Tokenizer*,
  12853. void *pCtx,
  12854. int flags, /* Mask of FTS5_TOKENIZE_* flags */
  12855. const char *pText, int nText,
  12856. int (*xToken)(
  12857. void *pCtx, /* Copy of 2nd argument to xTokenize() */
  12858. int tflags, /* Mask of FTS5_TOKEN_* flags */
  12859. const char *pToken, /* Pointer to buffer containing token */
  12860. int nToken, /* Size of token in bytes */
  12861. int iStart, /* Byte offset of token within input text */
  12862. int iEnd /* Byte offset of end of token within input text */
  12863. )
  12864. );
  12865. };
  12866. /* Flags that may be passed as the third argument to xTokenize() */
  12867. #define FTS5_TOKENIZE_QUERY 0x0001
  12868. #define FTS5_TOKENIZE_PREFIX 0x0002
  12869. #define FTS5_TOKENIZE_DOCUMENT 0x0004
  12870. #define FTS5_TOKENIZE_AUX 0x0008
  12871. /* Flags that may be passed by the tokenizer implementation back to FTS5
  12872. ** as the third argument to the supplied xToken callback. */
  12873. #define FTS5_TOKEN_COLOCATED 0x0001 /* Same position as prev. token */
  12874. /*
  12875. ** END OF CUSTOM TOKENIZERS
  12876. *************************************************************************/
  12877. /*************************************************************************
  12878. ** FTS5 EXTENSION REGISTRATION API
  12879. */
  12880. typedef struct fts5_api fts5_api;
  12881. struct fts5_api {
  12882. int iVersion; /* Currently always set to 2 */
  12883. /* Create a new tokenizer */
  12884. int (*xCreateTokenizer)(
  12885. fts5_api *pApi,
  12886. const char *zName,
  12887. void *pUserData,
  12888. fts5_tokenizer *pTokenizer,
  12889. void (*xDestroy)(void*)
  12890. );
  12891. /* Find an existing tokenizer */
  12892. int (*xFindTokenizer)(
  12893. fts5_api *pApi,
  12894. const char *zName,
  12895. void **ppUserData,
  12896. fts5_tokenizer *pTokenizer
  12897. );
  12898. /* Create a new auxiliary function */
  12899. int (*xCreateFunction)(
  12900. fts5_api *pApi,
  12901. const char *zName,
  12902. void *pUserData,
  12903. fts5_extension_function xFunction,
  12904. void (*xDestroy)(void*)
  12905. );
  12906. };
  12907. /*
  12908. ** END OF REGISTRATION API
  12909. *************************************************************************/
  12910. #ifdef __cplusplus
  12911. } /* end of the 'extern "C"' block */
  12912. #endif
  12913. #endif /* _FTS5_H */
  12914. /******** End of fts5.h *********/
  12915. #else // USE_LIBSQLITE3
  12916. // If users really want to link against the system sqlite3 we
  12917. // need to make this file a noop.
  12918. #endif
  12919. /*
  12920. ** 2014-09-08
  12921. **
  12922. ** The author disclaims copyright to this source code. In place of
  12923. ** a legal notice, here is a blessing:
  12924. **
  12925. ** May you do good and not evil.
  12926. ** May you find forgiveness for yourself and forgive others.
  12927. ** May you share freely, never taking more than you give.
  12928. **
  12929. *************************************************************************
  12930. **
  12931. ** This file contains the application interface definitions for the
  12932. ** user-authentication extension feature.
  12933. **
  12934. ** To compile with the user-authentication feature, append this file to
  12935. ** end of an SQLite amalgamation header file ("sqlite3.h"), then add
  12936. ** the SQLITE_USER_AUTHENTICATION compile-time option. See the
  12937. ** user-auth.txt file in the same source directory as this file for
  12938. ** additional information.
  12939. */
  12940. #ifdef SQLITE_USER_AUTHENTICATION
  12941. #ifdef __cplusplus
  12942. extern "C" {
  12943. #endif
  12944. /*
  12945. ** If a database contains the SQLITE_USER table, then the
  12946. ** sqlite3_user_authenticate() interface must be invoked with an
  12947. ** appropriate username and password prior to enable read and write
  12948. ** access to the database.
  12949. **
  12950. ** Return SQLITE_OK on success or SQLITE_ERROR if the username/password
  12951. ** combination is incorrect or unknown.
  12952. **
  12953. ** If the SQLITE_USER table is not present in the database file, then
  12954. ** this interface is a harmless no-op returnning SQLITE_OK.
  12955. */
  12956. int sqlite3_user_authenticate(
  12957. sqlite3 *db, /* The database connection */
  12958. const char *zUsername, /* Username */
  12959. const char *aPW, /* Password or credentials */
  12960. int nPW /* Number of bytes in aPW[] */
  12961. );
  12962. /*
  12963. ** The sqlite3_user_add() interface can be used (by an admin user only)
  12964. ** to create a new user. When called on a no-authentication-required
  12965. ** database, this routine converts the database into an authentication-
  12966. ** required database, automatically makes the added user an
  12967. ** administrator, and logs in the current connection as that user.
  12968. ** The sqlite3_user_add() interface only works for the "main" database, not
  12969. ** for any ATTACH-ed databases. Any call to sqlite3_user_add() by a
  12970. ** non-admin user results in an error.
  12971. */
  12972. int sqlite3_user_add(
  12973. sqlite3 *db, /* Database connection */
  12974. const char *zUsername, /* Username to be added */
  12975. const char *aPW, /* Password or credentials */
  12976. int nPW, /* Number of bytes in aPW[] */
  12977. int isAdmin /* True to give new user admin privilege */
  12978. );
  12979. /*
  12980. ** The sqlite3_user_change() interface can be used to change a users
  12981. ** login credentials or admin privilege. Any user can change their own
  12982. ** login credentials. Only an admin user can change another users login
  12983. ** credentials or admin privilege setting. No user may change their own
  12984. ** admin privilege setting.
  12985. */
  12986. int sqlite3_user_change(
  12987. sqlite3 *db, /* Database connection */
  12988. const char *zUsername, /* Username to change */
  12989. const char *aPW, /* New password or credentials */
  12990. int nPW, /* Number of bytes in aPW[] */
  12991. int isAdmin /* Modified admin privilege for the user */
  12992. );
  12993. /*
  12994. ** The sqlite3_user_delete() interface can be used (by an admin user only)
  12995. ** to delete a user. The currently logged-in user cannot be deleted,
  12996. ** which guarantees that there is always an admin user and hence that
  12997. ** the database cannot be converted into a no-authentication-required
  12998. ** database.
  12999. */
  13000. int sqlite3_user_delete(
  13001. sqlite3 *db, /* Database connection */
  13002. const char *zUsername /* Username to remove */
  13003. );
  13004. #ifdef __cplusplus
  13005. } /* end of the 'extern "C"' block */
  13006. #endif
  13007. #endif /* SQLITE_USER_AUTHENTICATION */