sqlite3.h 371 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666166716681669167016711672167316741675167616771678167916801681168216831684168516861687168816891690169116921693169416951696169716981699170017011702170317041705170617071708170917101711171217131714171517161717171817191720172117221723172417251726172717281729173017311732173317341735173617371738173917401741174217431744174517461747174817491750175117521753175417551756175717581759176017611762176317641765176617671768176917701771177217731774177517761777177817791780178117821783178417851786178717881789179017911792179317941795179617971798179918001801180218031804180518061807180818091810181118121813181418151816181718181819182018211822182318241825182618271828182918301831183218331834183518361837183818391840184118421843184418451846184718481849185018511852185318541855185618571858185918601861186218631864186518661867186818691870187118721873187418751876187718781879188018811882188318841885188618871888188918901891189218931894189518961897189818991900190119021903190419051906190719081909191019111912191319141915191619171918191919201921192219231924192519261927192819291930193119321933193419351936193719381939194019411942194319441945194619471948194919501951195219531954195519561957195819591960196119621963196419651966196719681969197019711972197319741975197619771978197919801981198219831984198519861987198819891990199119921993199419951996199719981999200020012002200320042005200620072008200920102011201220132014201520162017201820192020202120222023202420252026202720282029203020312032203320342035203620372038203920402041204220432044204520462047204820492050205120522053205420552056205720582059206020612062206320642065206620672068206920702071207220732074207520762077207820792080208120822083208420852086208720882089209020912092209320942095209620972098209921002101210221032104210521062107210821092110211121122113211421152116211721182119212021212122212321242125212621272128212921302131213221332134213521362137213821392140214121422143214421452146214721482149215021512152215321542155215621572158215921602161216221632164216521662167216821692170217121722173217421752176217721782179218021812182218321842185218621872188218921902191219221932194219521962197219821992200220122022203220422052206220722082209221022112212221322142215221622172218221922202221222222232224222522262227222822292230223122322233223422352236223722382239224022412242224322442245224622472248224922502251225222532254225522562257225822592260226122622263226422652266226722682269227022712272227322742275227622772278227922802281228222832284228522862287228822892290229122922293229422952296229722982299230023012302230323042305230623072308230923102311231223132314231523162317231823192320232123222323232423252326232723282329233023312332233323342335233623372338233923402341234223432344234523462347234823492350235123522353235423552356235723582359236023612362236323642365236623672368236923702371237223732374237523762377237823792380238123822383238423852386238723882389239023912392239323942395239623972398239924002401240224032404240524062407240824092410241124122413241424152416241724182419242024212422242324242425242624272428242924302431243224332434243524362437243824392440244124422443244424452446244724482449245024512452245324542455245624572458245924602461246224632464246524662467246824692470247124722473247424752476247724782479248024812482248324842485248624872488248924902491249224932494249524962497249824992500250125022503250425052506250725082509251025112512251325142515251625172518251925202521252225232524252525262527252825292530253125322533253425352536253725382539254025412542254325442545254625472548254925502551255225532554255525562557255825592560256125622563256425652566256725682569257025712572257325742575257625772578257925802581258225832584258525862587258825892590259125922593259425952596259725982599260026012602260326042605260626072608260926102611261226132614261526162617261826192620262126222623262426252626262726282629263026312632263326342635263626372638263926402641264226432644264526462647264826492650265126522653265426552656265726582659266026612662266326642665266626672668266926702671267226732674267526762677267826792680268126822683268426852686268726882689269026912692269326942695269626972698269927002701270227032704270527062707270827092710271127122713271427152716271727182719272027212722272327242725272627272728272927302731273227332734273527362737273827392740274127422743274427452746274727482749275027512752275327542755275627572758275927602761276227632764276527662767276827692770277127722773277427752776277727782779278027812782278327842785278627872788278927902791279227932794279527962797279827992800280128022803280428052806280728082809281028112812281328142815281628172818281928202821282228232824282528262827282828292830283128322833283428352836283728382839284028412842284328442845284628472848284928502851285228532854285528562857285828592860286128622863286428652866286728682869287028712872287328742875287628772878287928802881288228832884288528862887288828892890289128922893289428952896289728982899290029012902290329042905290629072908290929102911291229132914291529162917291829192920292129222923292429252926292729282929293029312932293329342935293629372938293929402941294229432944294529462947294829492950295129522953295429552956295729582959296029612962296329642965296629672968296929702971297229732974297529762977297829792980298129822983298429852986298729882989299029912992299329942995299629972998299930003001300230033004300530063007300830093010301130123013301430153016301730183019302030213022302330243025302630273028302930303031303230333034303530363037303830393040304130423043304430453046304730483049305030513052305330543055305630573058305930603061306230633064306530663067306830693070307130723073307430753076307730783079308030813082308330843085308630873088308930903091309230933094309530963097309830993100310131023103310431053106310731083109311031113112311331143115311631173118311931203121312231233124312531263127312831293130313131323133313431353136313731383139314031413142314331443145314631473148314931503151315231533154315531563157315831593160316131623163316431653166316731683169317031713172317331743175317631773178317931803181318231833184318531863187318831893190319131923193319431953196319731983199320032013202320332043205320632073208320932103211321232133214321532163217321832193220322132223223322432253226322732283229323032313232323332343235323632373238323932403241324232433244324532463247324832493250325132523253325432553256325732583259326032613262326332643265326632673268326932703271327232733274327532763277327832793280328132823283328432853286328732883289329032913292329332943295329632973298329933003301330233033304330533063307330833093310331133123313331433153316331733183319332033213322332333243325332633273328332933303331333233333334333533363337333833393340334133423343334433453346334733483349335033513352335333543355335633573358335933603361336233633364336533663367336833693370337133723373337433753376337733783379338033813382338333843385338633873388338933903391339233933394339533963397339833993400340134023403340434053406340734083409341034113412341334143415341634173418341934203421342234233424342534263427342834293430343134323433343434353436343734383439344034413442344334443445344634473448344934503451345234533454345534563457345834593460346134623463346434653466346734683469347034713472347334743475347634773478347934803481348234833484348534863487348834893490349134923493349434953496349734983499350035013502350335043505350635073508350935103511351235133514351535163517351835193520352135223523352435253526352735283529353035313532353335343535353635373538353935403541354235433544354535463547354835493550355135523553355435553556355735583559356035613562356335643565356635673568356935703571357235733574357535763577357835793580358135823583358435853586358735883589359035913592359335943595359635973598359936003601360236033604360536063607360836093610361136123613361436153616361736183619362036213622362336243625362636273628362936303631363236333634363536363637363836393640364136423643364436453646364736483649365036513652365336543655365636573658365936603661366236633664366536663667366836693670367136723673367436753676367736783679368036813682368336843685368636873688368936903691369236933694369536963697369836993700370137023703370437053706370737083709371037113712371337143715371637173718371937203721372237233724372537263727372837293730373137323733373437353736373737383739374037413742374337443745374637473748374937503751375237533754375537563757375837593760376137623763376437653766376737683769377037713772377337743775377637773778377937803781378237833784378537863787378837893790379137923793379437953796379737983799380038013802380338043805380638073808380938103811381238133814381538163817381838193820382138223823382438253826382738283829383038313832383338343835383638373838383938403841384238433844384538463847384838493850385138523853385438553856385738583859386038613862386338643865386638673868386938703871387238733874387538763877387838793880388138823883388438853886388738883889389038913892389338943895389638973898389939003901390239033904390539063907390839093910391139123913391439153916391739183919392039213922392339243925392639273928392939303931393239333934393539363937393839393940394139423943394439453946394739483949395039513952395339543955395639573958395939603961396239633964396539663967396839693970397139723973397439753976397739783979398039813982398339843985398639873988398939903991399239933994399539963997399839994000400140024003400440054006400740084009401040114012401340144015401640174018401940204021402240234024402540264027402840294030403140324033403440354036403740384039404040414042404340444045404640474048404940504051405240534054405540564057405840594060406140624063406440654066406740684069407040714072407340744075407640774078407940804081408240834084408540864087408840894090409140924093409440954096409740984099410041014102410341044105410641074108410941104111411241134114411541164117411841194120412141224123412441254126412741284129413041314132413341344135413641374138413941404141414241434144414541464147414841494150415141524153415441554156415741584159416041614162416341644165416641674168416941704171417241734174417541764177417841794180418141824183418441854186418741884189419041914192419341944195419641974198419942004201420242034204420542064207420842094210421142124213421442154216421742184219422042214222422342244225422642274228422942304231423242334234423542364237423842394240424142424243424442454246424742484249425042514252425342544255425642574258425942604261426242634264426542664267426842694270427142724273427442754276427742784279428042814282428342844285428642874288428942904291429242934294429542964297429842994300430143024303430443054306430743084309431043114312431343144315431643174318431943204321432243234324432543264327432843294330433143324333433443354336433743384339434043414342434343444345434643474348434943504351435243534354435543564357435843594360436143624363436443654366436743684369437043714372437343744375437643774378437943804381438243834384438543864387438843894390439143924393439443954396439743984399440044014402440344044405440644074408440944104411441244134414441544164417441844194420442144224423442444254426442744284429443044314432443344344435443644374438443944404441444244434444444544464447444844494450445144524453445444554456445744584459446044614462446344644465446644674468446944704471447244734474447544764477447844794480448144824483448444854486448744884489449044914492449344944495449644974498449945004501450245034504450545064507450845094510451145124513451445154516451745184519452045214522452345244525452645274528452945304531453245334534453545364537453845394540454145424543454445454546454745484549455045514552455345544555455645574558455945604561456245634564456545664567456845694570457145724573457445754576457745784579458045814582458345844585458645874588458945904591459245934594459545964597459845994600460146024603460446054606460746084609461046114612461346144615461646174618461946204621462246234624462546264627462846294630463146324633463446354636463746384639464046414642464346444645464646474648464946504651465246534654465546564657465846594660466146624663466446654666466746684669467046714672467346744675467646774678467946804681468246834684468546864687468846894690469146924693469446954696469746984699470047014702470347044705470647074708470947104711471247134714471547164717471847194720472147224723472447254726472747284729473047314732473347344735473647374738473947404741474247434744474547464747474847494750475147524753475447554756475747584759476047614762476347644765476647674768476947704771477247734774477547764777477847794780478147824783478447854786478747884789479047914792479347944795479647974798479948004801480248034804480548064807480848094810481148124813481448154816481748184819482048214822482348244825482648274828482948304831483248334834483548364837483848394840484148424843484448454846484748484849485048514852485348544855485648574858485948604861486248634864486548664867486848694870487148724873487448754876487748784879488048814882488348844885488648874888488948904891489248934894489548964897489848994900490149024903490449054906490749084909491049114912491349144915491649174918491949204921492249234924492549264927492849294930493149324933493449354936493749384939494049414942494349444945494649474948494949504951495249534954495549564957495849594960496149624963496449654966496749684969497049714972497349744975497649774978497949804981498249834984498549864987498849894990499149924993499449954996499749984999500050015002500350045005500650075008500950105011501250135014501550165017501850195020502150225023502450255026502750285029503050315032503350345035503650375038503950405041504250435044504550465047504850495050505150525053505450555056505750585059506050615062506350645065506650675068506950705071507250735074507550765077507850795080508150825083508450855086508750885089509050915092509350945095509650975098509951005101510251035104510551065107510851095110511151125113511451155116511751185119512051215122512351245125512651275128512951305131513251335134513551365137513851395140514151425143514451455146514751485149515051515152515351545155515651575158515951605161516251635164516551665167516851695170517151725173517451755176517751785179518051815182518351845185518651875188518951905191519251935194519551965197519851995200520152025203520452055206520752085209521052115212521352145215521652175218521952205221522252235224522552265227522852295230523152325233523452355236523752385239524052415242524352445245524652475248524952505251525252535254525552565257525852595260526152625263526452655266526752685269527052715272527352745275527652775278527952805281528252835284528552865287528852895290529152925293529452955296529752985299530053015302530353045305530653075308530953105311531253135314531553165317531853195320532153225323532453255326532753285329533053315332533353345335533653375338533953405341534253435344534553465347534853495350535153525353535453555356535753585359536053615362536353645365536653675368536953705371537253735374537553765377537853795380538153825383538453855386538753885389539053915392539353945395539653975398539954005401540254035404540554065407540854095410541154125413541454155416541754185419542054215422542354245425542654275428542954305431543254335434543554365437543854395440544154425443544454455446544754485449545054515452545354545455545654575458545954605461546254635464546554665467546854695470547154725473547454755476547754785479548054815482548354845485548654875488548954905491549254935494549554965497549854995500550155025503550455055506550755085509551055115512551355145515551655175518551955205521552255235524552555265527552855295530553155325533553455355536553755385539554055415542554355445545554655475548554955505551555255535554555555565557555855595560556155625563556455655566556755685569557055715572557355745575557655775578557955805581558255835584558555865587558855895590559155925593559455955596559755985599560056015602560356045605560656075608560956105611561256135614561556165617561856195620562156225623562456255626562756285629563056315632563356345635563656375638563956405641564256435644564556465647564856495650565156525653565456555656565756585659566056615662566356645665566656675668566956705671567256735674567556765677567856795680568156825683568456855686568756885689569056915692569356945695569656975698569957005701570257035704570557065707570857095710571157125713571457155716571757185719572057215722572357245725572657275728572957305731573257335734573557365737573857395740574157425743574457455746574757485749575057515752575357545755575657575758575957605761576257635764576557665767576857695770577157725773577457755776577757785779578057815782578357845785578657875788578957905791579257935794579557965797579857995800580158025803580458055806580758085809581058115812581358145815581658175818581958205821582258235824582558265827582858295830583158325833583458355836583758385839584058415842584358445845584658475848584958505851585258535854585558565857585858595860586158625863586458655866586758685869587058715872587358745875587658775878587958805881588258835884588558865887588858895890589158925893589458955896589758985899590059015902590359045905590659075908590959105911591259135914591559165917591859195920592159225923592459255926592759285929593059315932593359345935593659375938593959405941594259435944594559465947594859495950595159525953595459555956595759585959596059615962596359645965596659675968596959705971597259735974597559765977597859795980598159825983598459855986598759885989599059915992599359945995599659975998599960006001600260036004600560066007600860096010601160126013601460156016601760186019602060216022602360246025602660276028602960306031603260336034603560366037603860396040604160426043604460456046604760486049605060516052605360546055605660576058605960606061606260636064606560666067606860696070607160726073607460756076607760786079608060816082608360846085608660876088608960906091609260936094609560966097609860996100610161026103610461056106610761086109611061116112611361146115611661176118611961206121612261236124612561266127612861296130613161326133613461356136613761386139614061416142614361446145614661476148614961506151615261536154615561566157615861596160616161626163616461656166616761686169617061716172617361746175617661776178617961806181618261836184618561866187618861896190619161926193619461956196619761986199620062016202620362046205620662076208620962106211621262136214621562166217621862196220622162226223622462256226622762286229623062316232623362346235623662376238623962406241624262436244624562466247624862496250625162526253625462556256625762586259626062616262626362646265626662676268626962706271627262736274627562766277627862796280628162826283628462856286628762886289629062916292629362946295629662976298629963006301630263036304630563066307630863096310631163126313631463156316631763186319632063216322632363246325632663276328632963306331633263336334633563366337633863396340634163426343634463456346634763486349635063516352635363546355635663576358635963606361636263636364636563666367636863696370637163726373637463756376637763786379638063816382638363846385638663876388638963906391639263936394639563966397639863996400640164026403640464056406640764086409641064116412641364146415641664176418641964206421642264236424642564266427642864296430643164326433643464356436643764386439644064416442644364446445644664476448644964506451645264536454645564566457645864596460646164626463646464656466646764686469647064716472647364746475647664776478647964806481648264836484648564866487648864896490649164926493649464956496649764986499650065016502650365046505650665076508650965106511651265136514651565166517651865196520652165226523652465256526652765286529653065316532653365346535653665376538653965406541654265436544654565466547654865496550655165526553655465556556655765586559656065616562656365646565656665676568656965706571657265736574657565766577657865796580658165826583658465856586658765886589659065916592659365946595659665976598659966006601660266036604660566066607660866096610661166126613661466156616661766186619662066216622662366246625662666276628662966306631663266336634663566366637663866396640664166426643664466456646664766486649665066516652665366546655665666576658665966606661666266636664666566666667666866696670667166726673667466756676667766786679668066816682668366846685668666876688668966906691669266936694669566966697669866996700670167026703670467056706670767086709671067116712671367146715671667176718671967206721672267236724672567266727672867296730673167326733673467356736673767386739674067416742674367446745674667476748674967506751675267536754675567566757675867596760676167626763676467656766676767686769677067716772677367746775677667776778677967806781678267836784678567866787678867896790679167926793679467956796679767986799680068016802680368046805680668076808680968106811681268136814681568166817681868196820682168226823682468256826682768286829683068316832683368346835683668376838683968406841684268436844684568466847684868496850685168526853685468556856685768586859686068616862686368646865686668676868686968706871687268736874687568766877687868796880688168826883688468856886688768886889689068916892689368946895689668976898689969006901690269036904690569066907690869096910691169126913691469156916691769186919692069216922692369246925692669276928692969306931693269336934693569366937693869396940694169426943694469456946694769486949695069516952695369546955695669576958695969606961696269636964696569666967696869696970697169726973697469756976697769786979698069816982698369846985698669876988698969906991699269936994699569966997699869997000700170027003700470057006700770087009701070117012701370147015701670177018701970207021702270237024702570267027702870297030703170327033703470357036703770387039704070417042704370447045704670477048704970507051705270537054705570567057705870597060706170627063706470657066706770687069707070717072707370747075707670777078707970807081708270837084708570867087708870897090709170927093709470957096709770987099710071017102710371047105710671077108710971107111711271137114711571167117711871197120712171227123712471257126712771287129713071317132713371347135713671377138713971407141714271437144714571467147714871497150715171527153715471557156715771587159716071617162716371647165716671677168716971707171717271737174717571767177717871797180718171827183718471857186718771887189719071917192719371947195719671977198719972007201720272037204720572067207720872097210721172127213721472157216721772187219722072217222722372247225722672277228722972307231723272337234723572367237723872397240724172427243724472457246724772487249725072517252725372547255725672577258725972607261726272637264726572667267726872697270727172727273727472757276727772787279728072817282728372847285728672877288728972907291729272937294729572967297729872997300730173027303730473057306730773087309731073117312731373147315731673177318731973207321732273237324732573267327732873297330733173327333733473357336733773387339734073417342734373447345734673477348734973507351735273537354735573567357735873597360736173627363736473657366736773687369737073717372737373747375737673777378737973807381738273837384738573867387738873897390739173927393739473957396739773987399740074017402740374047405740674077408740974107411741274137414741574167417741874197420742174227423742474257426742774287429743074317432743374347435743674377438743974407441744274437444744574467447744874497450745174527453745474557456745774587459746074617462746374647465746674677468746974707471747274737474747574767477747874797480748174827483748474857486748774887489749074917492749374947495749674977498749975007501750275037504750575067507750875097510751175127513751475157516751775187519752075217522752375247525752675277528752975307531753275337534753575367537753875397540754175427543754475457546754775487549755075517552755375547555755675577558755975607561756275637564756575667567756875697570757175727573757475757576757775787579758075817582758375847585758675877588758975907591759275937594759575967597759875997600760176027603760476057606760776087609761076117612761376147615761676177618761976207621762276237624762576267627762876297630763176327633763476357636763776387639764076417642764376447645764676477648764976507651765276537654765576567657765876597660766176627663766476657666766776687669767076717672767376747675767676777678767976807681768276837684768576867687768876897690769176927693769476957696769776987699770077017702770377047705770677077708770977107711771277137714771577167717771877197720772177227723772477257726772777287729773077317732773377347735773677377738773977407741774277437744774577467747774877497750775177527753775477557756775777587759776077617762776377647765776677677768776977707771777277737774777577767777777877797780778177827783778477857786778777887789779077917792779377947795779677977798779978007801780278037804780578067807780878097810781178127813781478157816781778187819782078217822782378247825782678277828782978307831783278337834783578367837783878397840784178427843784478457846784778487849785078517852785378547855785678577858785978607861
  1. /*
  2. ** 2001 September 15
  3. **
  4. ** The author disclaims copyright to this source code. In place of
  5. ** a legal notice, here is a blessing:
  6. **
  7. ** May you do good and not evil.
  8. ** May you find forgiveness for yourself and forgive others.
  9. ** May you share freely, never taking more than you give.
  10. **
  11. *************************************************************************
  12. ** This header file defines the interface that the SQLite library
  13. ** presents to client programs. If a C-function, structure, datatype,
  14. ** or constant definition does not appear in this file, then it is
  15. ** not a published API of SQLite, is subject to change without
  16. ** notice, and should not be referenced by programs that use SQLite.
  17. **
  18. ** Some of the definitions that are in this file are marked as
  19. ** "experimental". Experimental interfaces are normally new
  20. ** features recently added to SQLite. We do not anticipate changes
  21. ** to experimental interfaces but reserve the right to make minor changes
  22. ** if experience from use "in the wild" suggest such changes are prudent.
  23. **
  24. ** The official C-language API documentation for SQLite is derived
  25. ** from comments in this file. This file is the authoritative source
  26. ** on how SQLite interfaces are supposed to operate.
  27. **
  28. ** The name of this file under configuration management is "sqlite.h.in".
  29. ** The makefile makes some minor changes to this file (such as inserting
  30. ** the version number) and changes its name to "sqlite3.h" as
  31. ** part of the build process.
  32. */
  33. #ifndef _SQLITE3_H_
  34. #define _SQLITE3_H_
  35. #include <stdarg.h> /* Needed for the definition of va_list */
  36. /*
  37. ** Make sure we can call this stuff from C++.
  38. */
  39. #ifdef __cplusplus
  40. extern "C" {
  41. #endif
  42. /*
  43. ** Provide the ability to override linkage features of the interface.
  44. */
  45. #ifndef SQLITE_EXTERN
  46. # define SQLITE_EXTERN extern
  47. #endif
  48. #ifndef SQLITE_API
  49. # define SQLITE_API
  50. #endif
  51. #ifndef SQLITE_CDECL
  52. # define SQLITE_CDECL
  53. #endif
  54. #ifndef SQLITE_STDCALL
  55. # define SQLITE_STDCALL
  56. #endif
  57. /*
  58. ** These no-op macros are used in front of interfaces to mark those
  59. ** interfaces as either deprecated or experimental. New applications
  60. ** should not use deprecated interfaces - they are supported for backwards
  61. ** compatibility only. Application writers should be aware that
  62. ** experimental interfaces are subject to change in point releases.
  63. **
  64. ** These macros used to resolve to various kinds of compiler magic that
  65. ** would generate warning messages when they were used. But that
  66. ** compiler magic ended up generating such a flurry of bug reports
  67. ** that we have taken it all out and gone back to using simple
  68. ** noop macros.
  69. */
  70. #define SQLITE_DEPRECATED
  71. #define SQLITE_EXPERIMENTAL
  72. /*
  73. ** Ensure these symbols were not defined by some previous header file.
  74. */
  75. #ifdef SQLITE_VERSION
  76. # undef SQLITE_VERSION
  77. #endif
  78. #ifdef SQLITE_VERSION_NUMBER
  79. # undef SQLITE_VERSION_NUMBER
  80. #endif
  81. /*
  82. ** CAPI3REF: Compile-Time Library Version Numbers
  83. **
  84. ** ^(The [SQLITE_VERSION] C preprocessor macro in the sqlite3.h header
  85. ** evaluates to a string literal that is the SQLite version in the
  86. ** format "X.Y.Z" where X is the major version number (always 3 for
  87. ** SQLite3) and Y is the minor version number and Z is the release number.)^
  88. ** ^(The [SQLITE_VERSION_NUMBER] C preprocessor macro resolves to an integer
  89. ** with the value (X*1000000 + Y*1000 + Z) where X, Y, and Z are the same
  90. ** numbers used in [SQLITE_VERSION].)^
  91. ** The SQLITE_VERSION_NUMBER for any given release of SQLite will also
  92. ** be larger than the release from which it is derived. Either Y will
  93. ** be held constant and Z will be incremented or else Y will be incremented
  94. ** and Z will be reset to zero.
  95. **
  96. ** Since version 3.6.18, SQLite source code has been stored in the
  97. ** <a href="http://www.fossil-scm.org/">Fossil configuration management
  98. ** system</a>. ^The SQLITE_SOURCE_ID macro evaluates to
  99. ** a string which identifies a particular check-in of SQLite
  100. ** within its configuration management system. ^The SQLITE_SOURCE_ID
  101. ** string contains the date and time of the check-in (UTC) and an SHA1
  102. ** hash of the entire source tree.
  103. **
  104. ** See also: [sqlite3_libversion()],
  105. ** [sqlite3_libversion_number()], [sqlite3_sourceid()],
  106. ** [sqlite_version()] and [sqlite_source_id()].
  107. */
  108. #define SQLITE_VERSION "3.8.11.1"
  109. #define SQLITE_VERSION_NUMBER 3008011
  110. #define SQLITE_SOURCE_ID "2015-07-29 20:00:57 cf538e2783e468bbc25e7cb2a9ee64d3e0e80b2f"
  111. /*
  112. ** CAPI3REF: Run-Time Library Version Numbers
  113. ** KEYWORDS: sqlite3_version, sqlite3_sourceid
  114. **
  115. ** These interfaces provide the same information as the [SQLITE_VERSION],
  116. ** [SQLITE_VERSION_NUMBER], and [SQLITE_SOURCE_ID] C preprocessor macros
  117. ** but are associated with the library instead of the header file. ^(Cautious
  118. ** programmers might include assert() statements in their application to
  119. ** verify that values returned by these interfaces match the macros in
  120. ** the header, and thus insure that the application is
  121. ** compiled with matching library and header files.
  122. **
  123. ** <blockquote><pre>
  124. ** assert( sqlite3_libversion_number()==SQLITE_VERSION_NUMBER );
  125. ** assert( strcmp(sqlite3_sourceid(),SQLITE_SOURCE_ID)==0 );
  126. ** assert( strcmp(sqlite3_libversion(),SQLITE_VERSION)==0 );
  127. ** </pre></blockquote>)^
  128. **
  129. ** ^The sqlite3_version[] string constant contains the text of [SQLITE_VERSION]
  130. ** macro. ^The sqlite3_libversion() function returns a pointer to the
  131. ** to the sqlite3_version[] string constant. The sqlite3_libversion()
  132. ** function is provided for use in DLLs since DLL users usually do not have
  133. ** direct access to string constants within the DLL. ^The
  134. ** sqlite3_libversion_number() function returns an integer equal to
  135. ** [SQLITE_VERSION_NUMBER]. ^The sqlite3_sourceid() function returns
  136. ** a pointer to a string constant whose value is the same as the
  137. ** [SQLITE_SOURCE_ID] C preprocessor macro.
  138. **
  139. ** See also: [sqlite_version()] and [sqlite_source_id()].
  140. */
  141. SQLITE_API SQLITE_EXTERN const char sqlite3_version[];
  142. SQLITE_API const char *SQLITE_STDCALL sqlite3_libversion(void);
  143. SQLITE_API const char *SQLITE_STDCALL sqlite3_sourceid(void);
  144. SQLITE_API int SQLITE_STDCALL sqlite3_libversion_number(void);
  145. /*
  146. ** CAPI3REF: Run-Time Library Compilation Options Diagnostics
  147. **
  148. ** ^The sqlite3_compileoption_used() function returns 0 or 1
  149. ** indicating whether the specified option was defined at
  150. ** compile time. ^The SQLITE_ prefix may be omitted from the
  151. ** option name passed to sqlite3_compileoption_used().
  152. **
  153. ** ^The sqlite3_compileoption_get() function allows iterating
  154. ** over the list of options that were defined at compile time by
  155. ** returning the N-th compile time option string. ^If N is out of range,
  156. ** sqlite3_compileoption_get() returns a NULL pointer. ^The SQLITE_
  157. ** prefix is omitted from any strings returned by
  158. ** sqlite3_compileoption_get().
  159. **
  160. ** ^Support for the diagnostic functions sqlite3_compileoption_used()
  161. ** and sqlite3_compileoption_get() may be omitted by specifying the
  162. ** [SQLITE_OMIT_COMPILEOPTION_DIAGS] option at compile time.
  163. **
  164. ** See also: SQL functions [sqlite_compileoption_used()] and
  165. ** [sqlite_compileoption_get()] and the [compile_options pragma].
  166. */
  167. #ifndef SQLITE_OMIT_COMPILEOPTION_DIAGS
  168. SQLITE_API int SQLITE_STDCALL sqlite3_compileoption_used(const char *zOptName);
  169. SQLITE_API const char *SQLITE_STDCALL sqlite3_compileoption_get(int N);
  170. #endif
  171. /*
  172. ** CAPI3REF: Test To See If The Library Is Threadsafe
  173. **
  174. ** ^The sqlite3_threadsafe() function returns zero if and only if
  175. ** SQLite was compiled with mutexing code omitted due to the
  176. ** [SQLITE_THREADSAFE] compile-time option being set to 0.
  177. **
  178. ** SQLite can be compiled with or without mutexes. When
  179. ** the [SQLITE_THREADSAFE] C preprocessor macro is 1 or 2, mutexes
  180. ** are enabled and SQLite is threadsafe. When the
  181. ** [SQLITE_THREADSAFE] macro is 0,
  182. ** the mutexes are omitted. Without the mutexes, it is not safe
  183. ** to use SQLite concurrently from more than one thread.
  184. **
  185. ** Enabling mutexes incurs a measurable performance penalty.
  186. ** So if speed is of utmost importance, it makes sense to disable
  187. ** the mutexes. But for maximum safety, mutexes should be enabled.
  188. ** ^The default behavior is for mutexes to be enabled.
  189. **
  190. ** This interface can be used by an application to make sure that the
  191. ** version of SQLite that it is linking against was compiled with
  192. ** the desired setting of the [SQLITE_THREADSAFE] macro.
  193. **
  194. ** This interface only reports on the compile-time mutex setting
  195. ** of the [SQLITE_THREADSAFE] flag. If SQLite is compiled with
  196. ** SQLITE_THREADSAFE=1 or =2 then mutexes are enabled by default but
  197. ** can be fully or partially disabled using a call to [sqlite3_config()]
  198. ** with the verbs [SQLITE_CONFIG_SINGLETHREAD], [SQLITE_CONFIG_MULTITHREAD],
  199. ** or [SQLITE_CONFIG_SERIALIZED]. ^(The return value of the
  200. ** sqlite3_threadsafe() function shows only the compile-time setting of
  201. ** thread safety, not any run-time changes to that setting made by
  202. ** sqlite3_config(). In other words, the return value from sqlite3_threadsafe()
  203. ** is unchanged by calls to sqlite3_config().)^
  204. **
  205. ** See the [threading mode] documentation for additional information.
  206. */
  207. SQLITE_API int SQLITE_STDCALL sqlite3_threadsafe(void);
  208. /*
  209. ** CAPI3REF: Database Connection Handle
  210. ** KEYWORDS: {database connection} {database connections}
  211. **
  212. ** Each open SQLite database is represented by a pointer to an instance of
  213. ** the opaque structure named "sqlite3". It is useful to think of an sqlite3
  214. ** pointer as an object. The [sqlite3_open()], [sqlite3_open16()], and
  215. ** [sqlite3_open_v2()] interfaces are its constructors, and [sqlite3_close()]
  216. ** and [sqlite3_close_v2()] are its destructors. There are many other
  217. ** interfaces (such as
  218. ** [sqlite3_prepare_v2()], [sqlite3_create_function()], and
  219. ** [sqlite3_busy_timeout()] to name but three) that are methods on an
  220. ** sqlite3 object.
  221. */
  222. typedef struct sqlite3 sqlite3;
  223. /*
  224. ** CAPI3REF: 64-Bit Integer Types
  225. ** KEYWORDS: sqlite_int64 sqlite_uint64
  226. **
  227. ** Because there is no cross-platform way to specify 64-bit integer types
  228. ** SQLite includes typedefs for 64-bit signed and unsigned integers.
  229. **
  230. ** The sqlite3_int64 and sqlite3_uint64 are the preferred type definitions.
  231. ** The sqlite_int64 and sqlite_uint64 types are supported for backwards
  232. ** compatibility only.
  233. **
  234. ** ^The sqlite3_int64 and sqlite_int64 types can store integer values
  235. ** between -9223372036854775808 and +9223372036854775807 inclusive. ^The
  236. ** sqlite3_uint64 and sqlite_uint64 types can store integer values
  237. ** between 0 and +18446744073709551615 inclusive.
  238. */
  239. #ifdef SQLITE_INT64_TYPE
  240. typedef SQLITE_INT64_TYPE sqlite_int64;
  241. typedef unsigned SQLITE_INT64_TYPE sqlite_uint64;
  242. #elif defined(_MSC_VER) || defined(__BORLANDC__)
  243. typedef __int64 sqlite_int64;
  244. typedef unsigned __int64 sqlite_uint64;
  245. #else
  246. typedef long long int sqlite_int64;
  247. typedef unsigned long long int sqlite_uint64;
  248. #endif
  249. typedef sqlite_int64 sqlite3_int64;
  250. typedef sqlite_uint64 sqlite3_uint64;
  251. /*
  252. ** If compiling for a processor that lacks floating point support,
  253. ** substitute integer for floating-point.
  254. */
  255. #ifdef SQLITE_OMIT_FLOATING_POINT
  256. # define double sqlite3_int64
  257. #endif
  258. /*
  259. ** CAPI3REF: Closing A Database Connection
  260. ** DESTRUCTOR: sqlite3
  261. **
  262. ** ^The sqlite3_close() and sqlite3_close_v2() routines are destructors
  263. ** for the [sqlite3] object.
  264. ** ^Calls to sqlite3_close() and sqlite3_close_v2() return [SQLITE_OK] if
  265. ** the [sqlite3] object is successfully destroyed and all associated
  266. ** resources are deallocated.
  267. **
  268. ** ^If the database connection is associated with unfinalized prepared
  269. ** statements or unfinished sqlite3_backup objects then sqlite3_close()
  270. ** will leave the database connection open and return [SQLITE_BUSY].
  271. ** ^If sqlite3_close_v2() is called with unfinalized prepared statements
  272. ** and/or unfinished sqlite3_backups, then the database connection becomes
  273. ** an unusable "zombie" which will automatically be deallocated when the
  274. ** last prepared statement is finalized or the last sqlite3_backup is
  275. ** finished. The sqlite3_close_v2() interface is intended for use with
  276. ** host languages that are garbage collected, and where the order in which
  277. ** destructors are called is arbitrary.
  278. **
  279. ** Applications should [sqlite3_finalize | finalize] all [prepared statements],
  280. ** [sqlite3_blob_close | close] all [BLOB handles], and
  281. ** [sqlite3_backup_finish | finish] all [sqlite3_backup] objects associated
  282. ** with the [sqlite3] object prior to attempting to close the object. ^If
  283. ** sqlite3_close_v2() is called on a [database connection] that still has
  284. ** outstanding [prepared statements], [BLOB handles], and/or
  285. ** [sqlite3_backup] objects then it returns [SQLITE_OK] and the deallocation
  286. ** of resources is deferred until all [prepared statements], [BLOB handles],
  287. ** and [sqlite3_backup] objects are also destroyed.
  288. **
  289. ** ^If an [sqlite3] object is destroyed while a transaction is open,
  290. ** the transaction is automatically rolled back.
  291. **
  292. ** The C parameter to [sqlite3_close(C)] and [sqlite3_close_v2(C)]
  293. ** must be either a NULL
  294. ** pointer or an [sqlite3] object pointer obtained
  295. ** from [sqlite3_open()], [sqlite3_open16()], or
  296. ** [sqlite3_open_v2()], and not previously closed.
  297. ** ^Calling sqlite3_close() or sqlite3_close_v2() with a NULL pointer
  298. ** argument is a harmless no-op.
  299. */
  300. SQLITE_API int SQLITE_STDCALL sqlite3_close(sqlite3*);
  301. SQLITE_API int SQLITE_STDCALL sqlite3_close_v2(sqlite3*);
  302. /*
  303. ** The type for a callback function.
  304. ** This is legacy and deprecated. It is included for historical
  305. ** compatibility and is not documented.
  306. */
  307. typedef int (*sqlite3_callback)(void*,int,char**, char**);
  308. /*
  309. ** CAPI3REF: One-Step Query Execution Interface
  310. ** METHOD: sqlite3
  311. **
  312. ** The sqlite3_exec() interface is a convenience wrapper around
  313. ** [sqlite3_prepare_v2()], [sqlite3_step()], and [sqlite3_finalize()],
  314. ** that allows an application to run multiple statements of SQL
  315. ** without having to use a lot of C code.
  316. **
  317. ** ^The sqlite3_exec() interface runs zero or more UTF-8 encoded,
  318. ** semicolon-separate SQL statements passed into its 2nd argument,
  319. ** in the context of the [database connection] passed in as its 1st
  320. ** argument. ^If the callback function of the 3rd argument to
  321. ** sqlite3_exec() is not NULL, then it is invoked for each result row
  322. ** coming out of the evaluated SQL statements. ^The 4th argument to
  323. ** sqlite3_exec() is relayed through to the 1st argument of each
  324. ** callback invocation. ^If the callback pointer to sqlite3_exec()
  325. ** is NULL, then no callback is ever invoked and result rows are
  326. ** ignored.
  327. **
  328. ** ^If an error occurs while evaluating the SQL statements passed into
  329. ** sqlite3_exec(), then execution of the current statement stops and
  330. ** subsequent statements are skipped. ^If the 5th parameter to sqlite3_exec()
  331. ** is not NULL then any error message is written into memory obtained
  332. ** from [sqlite3_malloc()] and passed back through the 5th parameter.
  333. ** To avoid memory leaks, the application should invoke [sqlite3_free()]
  334. ** on error message strings returned through the 5th parameter of
  335. ** of sqlite3_exec() after the error message string is no longer needed.
  336. ** ^If the 5th parameter to sqlite3_exec() is not NULL and no errors
  337. ** occur, then sqlite3_exec() sets the pointer in its 5th parameter to
  338. ** NULL before returning.
  339. **
  340. ** ^If an sqlite3_exec() callback returns non-zero, the sqlite3_exec()
  341. ** routine returns SQLITE_ABORT without invoking the callback again and
  342. ** without running any subsequent SQL statements.
  343. **
  344. ** ^The 2nd argument to the sqlite3_exec() callback function is the
  345. ** number of columns in the result. ^The 3rd argument to the sqlite3_exec()
  346. ** callback is an array of pointers to strings obtained as if from
  347. ** [sqlite3_column_text()], one for each column. ^If an element of a
  348. ** result row is NULL then the corresponding string pointer for the
  349. ** sqlite3_exec() callback is a NULL pointer. ^The 4th argument to the
  350. ** sqlite3_exec() callback is an array of pointers to strings where each
  351. ** entry represents the name of corresponding result column as obtained
  352. ** from [sqlite3_column_name()].
  353. **
  354. ** ^If the 2nd parameter to sqlite3_exec() is a NULL pointer, a pointer
  355. ** to an empty string, or a pointer that contains only whitespace and/or
  356. ** SQL comments, then no SQL statements are evaluated and the database
  357. ** is not changed.
  358. **
  359. ** Restrictions:
  360. **
  361. ** <ul>
  362. ** <li> The application must insure that the 1st parameter to sqlite3_exec()
  363. ** is a valid and open [database connection].
  364. ** <li> The application must not close the [database connection] specified by
  365. ** the 1st parameter to sqlite3_exec() while sqlite3_exec() is running.
  366. ** <li> The application must not modify the SQL statement text passed into
  367. ** the 2nd parameter of sqlite3_exec() while sqlite3_exec() is running.
  368. ** </ul>
  369. */
  370. SQLITE_API int SQLITE_STDCALL sqlite3_exec(
  371. sqlite3*, /* An open database */
  372. const char *sql, /* SQL to be evaluated */
  373. int (*callback)(void*,int,char**,char**), /* Callback function */
  374. void *, /* 1st argument to callback */
  375. char **errmsg /* Error msg written here */
  376. );
  377. /*
  378. ** CAPI3REF: Result Codes
  379. ** KEYWORDS: {result code definitions}
  380. **
  381. ** Many SQLite functions return an integer result code from the set shown
  382. ** here in order to indicate success or failure.
  383. **
  384. ** New error codes may be added in future versions of SQLite.
  385. **
  386. ** See also: [extended result code definitions]
  387. */
  388. #define SQLITE_OK 0 /* Successful result */
  389. /* beginning-of-error-codes */
  390. #define SQLITE_ERROR 1 /* SQL error or missing database */
  391. #define SQLITE_INTERNAL 2 /* Internal logic error in SQLite */
  392. #define SQLITE_PERM 3 /* Access permission denied */
  393. #define SQLITE_ABORT 4 /* Callback routine requested an abort */
  394. #define SQLITE_BUSY 5 /* The database file is locked */
  395. #define SQLITE_LOCKED 6 /* A table in the database is locked */
  396. #define SQLITE_NOMEM 7 /* A malloc() failed */
  397. #define SQLITE_READONLY 8 /* Attempt to write a readonly database */
  398. #define SQLITE_INTERRUPT 9 /* Operation terminated by sqlite3_interrupt()*/
  399. #define SQLITE_IOERR 10 /* Some kind of disk I/O error occurred */
  400. #define SQLITE_CORRUPT 11 /* The database disk image is malformed */
  401. #define SQLITE_NOTFOUND 12 /* Unknown opcode in sqlite3_file_control() */
  402. #define SQLITE_FULL 13 /* Insertion failed because database is full */
  403. #define SQLITE_CANTOPEN 14 /* Unable to open the database file */
  404. #define SQLITE_PROTOCOL 15 /* Database lock protocol error */
  405. #define SQLITE_EMPTY 16 /* Database is empty */
  406. #define SQLITE_SCHEMA 17 /* The database schema changed */
  407. #define SQLITE_TOOBIG 18 /* String or BLOB exceeds size limit */
  408. #define SQLITE_CONSTRAINT 19 /* Abort due to constraint violation */
  409. #define SQLITE_MISMATCH 20 /* Data type mismatch */
  410. #define SQLITE_MISUSE 21 /* Library used incorrectly */
  411. #define SQLITE_NOLFS 22 /* Uses OS features not supported on host */
  412. #define SQLITE_AUTH 23 /* Authorization denied */
  413. #define SQLITE_FORMAT 24 /* Auxiliary database format error */
  414. #define SQLITE_RANGE 25 /* 2nd parameter to sqlite3_bind out of range */
  415. #define SQLITE_NOTADB 26 /* File opened that is not a database file */
  416. #define SQLITE_NOTICE 27 /* Notifications from sqlite3_log() */
  417. #define SQLITE_WARNING 28 /* Warnings from sqlite3_log() */
  418. #define SQLITE_ROW 100 /* sqlite3_step() has another row ready */
  419. #define SQLITE_DONE 101 /* sqlite3_step() has finished executing */
  420. /* end-of-error-codes */
  421. /*
  422. ** CAPI3REF: Extended Result Codes
  423. ** KEYWORDS: {extended result code definitions}
  424. **
  425. ** In its default configuration, SQLite API routines return one of 30 integer
  426. ** [result codes]. However, experience has shown that many of
  427. ** these result codes are too coarse-grained. They do not provide as
  428. ** much information about problems as programmers might like. In an effort to
  429. ** address this, newer versions of SQLite (version 3.3.8 and later) include
  430. ** support for additional result codes that provide more detailed information
  431. ** about errors. These [extended result codes] are enabled or disabled
  432. ** on a per database connection basis using the
  433. ** [sqlite3_extended_result_codes()] API. Or, the extended code for
  434. ** the most recent error can be obtained using
  435. ** [sqlite3_extended_errcode()].
  436. */
  437. #define SQLITE_IOERR_READ (SQLITE_IOERR | (1<<8))
  438. #define SQLITE_IOERR_SHORT_READ (SQLITE_IOERR | (2<<8))
  439. #define SQLITE_IOERR_WRITE (SQLITE_IOERR | (3<<8))
  440. #define SQLITE_IOERR_FSYNC (SQLITE_IOERR | (4<<8))
  441. #define SQLITE_IOERR_DIR_FSYNC (SQLITE_IOERR | (5<<8))
  442. #define SQLITE_IOERR_TRUNCATE (SQLITE_IOERR | (6<<8))
  443. #define SQLITE_IOERR_FSTAT (SQLITE_IOERR | (7<<8))
  444. #define SQLITE_IOERR_UNLOCK (SQLITE_IOERR | (8<<8))
  445. #define SQLITE_IOERR_RDLOCK (SQLITE_IOERR | (9<<8))
  446. #define SQLITE_IOERR_DELETE (SQLITE_IOERR | (10<<8))
  447. #define SQLITE_IOERR_BLOCKED (SQLITE_IOERR | (11<<8))
  448. #define SQLITE_IOERR_NOMEM (SQLITE_IOERR | (12<<8))
  449. #define SQLITE_IOERR_ACCESS (SQLITE_IOERR | (13<<8))
  450. #define SQLITE_IOERR_CHECKRESERVEDLOCK (SQLITE_IOERR | (14<<8))
  451. #define SQLITE_IOERR_LOCK (SQLITE_IOERR | (15<<8))
  452. #define SQLITE_IOERR_CLOSE (SQLITE_IOERR | (16<<8))
  453. #define SQLITE_IOERR_DIR_CLOSE (SQLITE_IOERR | (17<<8))
  454. #define SQLITE_IOERR_SHMOPEN (SQLITE_IOERR | (18<<8))
  455. #define SQLITE_IOERR_SHMSIZE (SQLITE_IOERR | (19<<8))
  456. #define SQLITE_IOERR_SHMLOCK (SQLITE_IOERR | (20<<8))
  457. #define SQLITE_IOERR_SHMMAP (SQLITE_IOERR | (21<<8))
  458. #define SQLITE_IOERR_SEEK (SQLITE_IOERR | (22<<8))
  459. #define SQLITE_IOERR_DELETE_NOENT (SQLITE_IOERR | (23<<8))
  460. #define SQLITE_IOERR_MMAP (SQLITE_IOERR | (24<<8))
  461. #define SQLITE_IOERR_GETTEMPPATH (SQLITE_IOERR | (25<<8))
  462. #define SQLITE_IOERR_CONVPATH (SQLITE_IOERR | (26<<8))
  463. #define SQLITE_LOCKED_SHAREDCACHE (SQLITE_LOCKED | (1<<8))
  464. #define SQLITE_BUSY_RECOVERY (SQLITE_BUSY | (1<<8))
  465. #define SQLITE_BUSY_SNAPSHOT (SQLITE_BUSY | (2<<8))
  466. #define SQLITE_CANTOPEN_NOTEMPDIR (SQLITE_CANTOPEN | (1<<8))
  467. #define SQLITE_CANTOPEN_ISDIR (SQLITE_CANTOPEN | (2<<8))
  468. #define SQLITE_CANTOPEN_FULLPATH (SQLITE_CANTOPEN | (3<<8))
  469. #define SQLITE_CANTOPEN_CONVPATH (SQLITE_CANTOPEN | (4<<8))
  470. #define SQLITE_CORRUPT_VTAB (SQLITE_CORRUPT | (1<<8))
  471. #define SQLITE_READONLY_RECOVERY (SQLITE_READONLY | (1<<8))
  472. #define SQLITE_READONLY_CANTLOCK (SQLITE_READONLY | (2<<8))
  473. #define SQLITE_READONLY_ROLLBACK (SQLITE_READONLY | (3<<8))
  474. #define SQLITE_READONLY_DBMOVED (SQLITE_READONLY | (4<<8))
  475. #define SQLITE_ABORT_ROLLBACK (SQLITE_ABORT | (2<<8))
  476. #define SQLITE_CONSTRAINT_CHECK (SQLITE_CONSTRAINT | (1<<8))
  477. #define SQLITE_CONSTRAINT_COMMITHOOK (SQLITE_CONSTRAINT | (2<<8))
  478. #define SQLITE_CONSTRAINT_FOREIGNKEY (SQLITE_CONSTRAINT | (3<<8))
  479. #define SQLITE_CONSTRAINT_FUNCTION (SQLITE_CONSTRAINT | (4<<8))
  480. #define SQLITE_CONSTRAINT_NOTNULL (SQLITE_CONSTRAINT | (5<<8))
  481. #define SQLITE_CONSTRAINT_PRIMARYKEY (SQLITE_CONSTRAINT | (6<<8))
  482. #define SQLITE_CONSTRAINT_TRIGGER (SQLITE_CONSTRAINT | (7<<8))
  483. #define SQLITE_CONSTRAINT_UNIQUE (SQLITE_CONSTRAINT | (8<<8))
  484. #define SQLITE_CONSTRAINT_VTAB (SQLITE_CONSTRAINT | (9<<8))
  485. #define SQLITE_CONSTRAINT_ROWID (SQLITE_CONSTRAINT |(10<<8))
  486. #define SQLITE_NOTICE_RECOVER_WAL (SQLITE_NOTICE | (1<<8))
  487. #define SQLITE_NOTICE_RECOVER_ROLLBACK (SQLITE_NOTICE | (2<<8))
  488. #define SQLITE_WARNING_AUTOINDEX (SQLITE_WARNING | (1<<8))
  489. #define SQLITE_AUTH_USER (SQLITE_AUTH | (1<<8))
  490. /*
  491. ** CAPI3REF: Flags For File Open Operations
  492. **
  493. ** These bit values are intended for use in the
  494. ** 3rd parameter to the [sqlite3_open_v2()] interface and
  495. ** in the 4th parameter to the [sqlite3_vfs.xOpen] method.
  496. */
  497. #define SQLITE_OPEN_READONLY 0x00000001 /* Ok for sqlite3_open_v2() */
  498. #define SQLITE_OPEN_READWRITE 0x00000002 /* Ok for sqlite3_open_v2() */
  499. #define SQLITE_OPEN_CREATE 0x00000004 /* Ok for sqlite3_open_v2() */
  500. #define SQLITE_OPEN_DELETEONCLOSE 0x00000008 /* VFS only */
  501. #define SQLITE_OPEN_EXCLUSIVE 0x00000010 /* VFS only */
  502. #define SQLITE_OPEN_AUTOPROXY 0x00000020 /* VFS only */
  503. #define SQLITE_OPEN_URI 0x00000040 /* Ok for sqlite3_open_v2() */
  504. #define SQLITE_OPEN_MEMORY 0x00000080 /* Ok for sqlite3_open_v2() */
  505. #define SQLITE_OPEN_MAIN_DB 0x00000100 /* VFS only */
  506. #define SQLITE_OPEN_TEMP_DB 0x00000200 /* VFS only */
  507. #define SQLITE_OPEN_TRANSIENT_DB 0x00000400 /* VFS only */
  508. #define SQLITE_OPEN_MAIN_JOURNAL 0x00000800 /* VFS only */
  509. #define SQLITE_OPEN_TEMP_JOURNAL 0x00001000 /* VFS only */
  510. #define SQLITE_OPEN_SUBJOURNAL 0x00002000 /* VFS only */
  511. #define SQLITE_OPEN_MASTER_JOURNAL 0x00004000 /* VFS only */
  512. #define SQLITE_OPEN_NOMUTEX 0x00008000 /* Ok for sqlite3_open_v2() */
  513. #define SQLITE_OPEN_FULLMUTEX 0x00010000 /* Ok for sqlite3_open_v2() */
  514. #define SQLITE_OPEN_SHAREDCACHE 0x00020000 /* Ok for sqlite3_open_v2() */
  515. #define SQLITE_OPEN_PRIVATECACHE 0x00040000 /* Ok for sqlite3_open_v2() */
  516. #define SQLITE_OPEN_WAL 0x00080000 /* VFS only */
  517. /* Reserved: 0x00F00000 */
  518. /*
  519. ** CAPI3REF: Device Characteristics
  520. **
  521. ** The xDeviceCharacteristics method of the [sqlite3_io_methods]
  522. ** object returns an integer which is a vector of these
  523. ** bit values expressing I/O characteristics of the mass storage
  524. ** device that holds the file that the [sqlite3_io_methods]
  525. ** refers to.
  526. **
  527. ** The SQLITE_IOCAP_ATOMIC property means that all writes of
  528. ** any size are atomic. The SQLITE_IOCAP_ATOMICnnn values
  529. ** mean that writes of blocks that are nnn bytes in size and
  530. ** are aligned to an address which is an integer multiple of
  531. ** nnn are atomic. The SQLITE_IOCAP_SAFE_APPEND value means
  532. ** that when data is appended to a file, the data is appended
  533. ** first then the size of the file is extended, never the other
  534. ** way around. The SQLITE_IOCAP_SEQUENTIAL property means that
  535. ** information is written to disk in the same order as calls
  536. ** to xWrite(). The SQLITE_IOCAP_POWERSAFE_OVERWRITE property means that
  537. ** after reboot following a crash or power loss, the only bytes in a
  538. ** file that were written at the application level might have changed
  539. ** and that adjacent bytes, even bytes within the same sector are
  540. ** guaranteed to be unchanged. The SQLITE_IOCAP_UNDELETABLE_WHEN_OPEN
  541. ** flag indicate that a file cannot be deleted when open. The
  542. ** SQLITE_IOCAP_IMMUTABLE flag indicates that the file is on
  543. ** read-only media and cannot be changed even by processes with
  544. ** elevated privileges.
  545. */
  546. #define SQLITE_IOCAP_ATOMIC 0x00000001
  547. #define SQLITE_IOCAP_ATOMIC512 0x00000002
  548. #define SQLITE_IOCAP_ATOMIC1K 0x00000004
  549. #define SQLITE_IOCAP_ATOMIC2K 0x00000008
  550. #define SQLITE_IOCAP_ATOMIC4K 0x00000010
  551. #define SQLITE_IOCAP_ATOMIC8K 0x00000020
  552. #define SQLITE_IOCAP_ATOMIC16K 0x00000040
  553. #define SQLITE_IOCAP_ATOMIC32K 0x00000080
  554. #define SQLITE_IOCAP_ATOMIC64K 0x00000100
  555. #define SQLITE_IOCAP_SAFE_APPEND 0x00000200
  556. #define SQLITE_IOCAP_SEQUENTIAL 0x00000400
  557. #define SQLITE_IOCAP_UNDELETABLE_WHEN_OPEN 0x00000800
  558. #define SQLITE_IOCAP_POWERSAFE_OVERWRITE 0x00001000
  559. #define SQLITE_IOCAP_IMMUTABLE 0x00002000
  560. /*
  561. ** CAPI3REF: File Locking Levels
  562. **
  563. ** SQLite uses one of these integer values as the second
  564. ** argument to calls it makes to the xLock() and xUnlock() methods
  565. ** of an [sqlite3_io_methods] object.
  566. */
  567. #define SQLITE_LOCK_NONE 0
  568. #define SQLITE_LOCK_SHARED 1
  569. #define SQLITE_LOCK_RESERVED 2
  570. #define SQLITE_LOCK_PENDING 3
  571. #define SQLITE_LOCK_EXCLUSIVE 4
  572. /*
  573. ** CAPI3REF: Synchronization Type Flags
  574. **
  575. ** When SQLite invokes the xSync() method of an
  576. ** [sqlite3_io_methods] object it uses a combination of
  577. ** these integer values as the second argument.
  578. **
  579. ** When the SQLITE_SYNC_DATAONLY flag is used, it means that the
  580. ** sync operation only needs to flush data to mass storage. Inode
  581. ** information need not be flushed. If the lower four bits of the flag
  582. ** equal SQLITE_SYNC_NORMAL, that means to use normal fsync() semantics.
  583. ** If the lower four bits equal SQLITE_SYNC_FULL, that means
  584. ** to use Mac OS X style fullsync instead of fsync().
  585. **
  586. ** Do not confuse the SQLITE_SYNC_NORMAL and SQLITE_SYNC_FULL flags
  587. ** with the [PRAGMA synchronous]=NORMAL and [PRAGMA synchronous]=FULL
  588. ** settings. The [synchronous pragma] determines when calls to the
  589. ** xSync VFS method occur and applies uniformly across all platforms.
  590. ** The SQLITE_SYNC_NORMAL and SQLITE_SYNC_FULL flags determine how
  591. ** energetic or rigorous or forceful the sync operations are and
  592. ** only make a difference on Mac OSX for the default SQLite code.
  593. ** (Third-party VFS implementations might also make the distinction
  594. ** between SQLITE_SYNC_NORMAL and SQLITE_SYNC_FULL, but among the
  595. ** operating systems natively supported by SQLite, only Mac OSX
  596. ** cares about the difference.)
  597. */
  598. #define SQLITE_SYNC_NORMAL 0x00002
  599. #define SQLITE_SYNC_FULL 0x00003
  600. #define SQLITE_SYNC_DATAONLY 0x00010
  601. /*
  602. ** CAPI3REF: OS Interface Open File Handle
  603. **
  604. ** An [sqlite3_file] object represents an open file in the
  605. ** [sqlite3_vfs | OS interface layer]. Individual OS interface
  606. ** implementations will
  607. ** want to subclass this object by appending additional fields
  608. ** for their own use. The pMethods entry is a pointer to an
  609. ** [sqlite3_io_methods] object that defines methods for performing
  610. ** I/O operations on the open file.
  611. */
  612. typedef struct sqlite3_file sqlite3_file;
  613. struct sqlite3_file {
  614. const struct sqlite3_io_methods *pMethods; /* Methods for an open file */
  615. };
  616. /*
  617. ** CAPI3REF: OS Interface File Virtual Methods Object
  618. **
  619. ** Every file opened by the [sqlite3_vfs.xOpen] method populates an
  620. ** [sqlite3_file] object (or, more commonly, a subclass of the
  621. ** [sqlite3_file] object) with a pointer to an instance of this object.
  622. ** This object defines the methods used to perform various operations
  623. ** against the open file represented by the [sqlite3_file] object.
  624. **
  625. ** If the [sqlite3_vfs.xOpen] method sets the sqlite3_file.pMethods element
  626. ** to a non-NULL pointer, then the sqlite3_io_methods.xClose method
  627. ** may be invoked even if the [sqlite3_vfs.xOpen] reported that it failed. The
  628. ** only way to prevent a call to xClose following a failed [sqlite3_vfs.xOpen]
  629. ** is for the [sqlite3_vfs.xOpen] to set the sqlite3_file.pMethods element
  630. ** to NULL.
  631. **
  632. ** The flags argument to xSync may be one of [SQLITE_SYNC_NORMAL] or
  633. ** [SQLITE_SYNC_FULL]. The first choice is the normal fsync().
  634. ** The second choice is a Mac OS X style fullsync. The [SQLITE_SYNC_DATAONLY]
  635. ** flag may be ORed in to indicate that only the data of the file
  636. ** and not its inode needs to be synced.
  637. **
  638. ** The integer values to xLock() and xUnlock() are one of
  639. ** <ul>
  640. ** <li> [SQLITE_LOCK_NONE],
  641. ** <li> [SQLITE_LOCK_SHARED],
  642. ** <li> [SQLITE_LOCK_RESERVED],
  643. ** <li> [SQLITE_LOCK_PENDING], or
  644. ** <li> [SQLITE_LOCK_EXCLUSIVE].
  645. ** </ul>
  646. ** xLock() increases the lock. xUnlock() decreases the lock.
  647. ** The xCheckReservedLock() method checks whether any database connection,
  648. ** either in this process or in some other process, is holding a RESERVED,
  649. ** PENDING, or EXCLUSIVE lock on the file. It returns true
  650. ** if such a lock exists and false otherwise.
  651. **
  652. ** The xFileControl() method is a generic interface that allows custom
  653. ** VFS implementations to directly control an open file using the
  654. ** [sqlite3_file_control()] interface. The second "op" argument is an
  655. ** integer opcode. The third argument is a generic pointer intended to
  656. ** point to a structure that may contain arguments or space in which to
  657. ** write return values. Potential uses for xFileControl() might be
  658. ** functions to enable blocking locks with timeouts, to change the
  659. ** locking strategy (for example to use dot-file locks), to inquire
  660. ** about the status of a lock, or to break stale locks. The SQLite
  661. ** core reserves all opcodes less than 100 for its own use.
  662. ** A [file control opcodes | list of opcodes] less than 100 is available.
  663. ** Applications that define a custom xFileControl method should use opcodes
  664. ** greater than 100 to avoid conflicts. VFS implementations should
  665. ** return [SQLITE_NOTFOUND] for file control opcodes that they do not
  666. ** recognize.
  667. **
  668. ** The xSectorSize() method returns the sector size of the
  669. ** device that underlies the file. The sector size is the
  670. ** minimum write that can be performed without disturbing
  671. ** other bytes in the file. The xDeviceCharacteristics()
  672. ** method returns a bit vector describing behaviors of the
  673. ** underlying device:
  674. **
  675. ** <ul>
  676. ** <li> [SQLITE_IOCAP_ATOMIC]
  677. ** <li> [SQLITE_IOCAP_ATOMIC512]
  678. ** <li> [SQLITE_IOCAP_ATOMIC1K]
  679. ** <li> [SQLITE_IOCAP_ATOMIC2K]
  680. ** <li> [SQLITE_IOCAP_ATOMIC4K]
  681. ** <li> [SQLITE_IOCAP_ATOMIC8K]
  682. ** <li> [SQLITE_IOCAP_ATOMIC16K]
  683. ** <li> [SQLITE_IOCAP_ATOMIC32K]
  684. ** <li> [SQLITE_IOCAP_ATOMIC64K]
  685. ** <li> [SQLITE_IOCAP_SAFE_APPEND]
  686. ** <li> [SQLITE_IOCAP_SEQUENTIAL]
  687. ** </ul>
  688. **
  689. ** The SQLITE_IOCAP_ATOMIC property means that all writes of
  690. ** any size are atomic. The SQLITE_IOCAP_ATOMICnnn values
  691. ** mean that writes of blocks that are nnn bytes in size and
  692. ** are aligned to an address which is an integer multiple of
  693. ** nnn are atomic. The SQLITE_IOCAP_SAFE_APPEND value means
  694. ** that when data is appended to a file, the data is appended
  695. ** first then the size of the file is extended, never the other
  696. ** way around. The SQLITE_IOCAP_SEQUENTIAL property means that
  697. ** information is written to disk in the same order as calls
  698. ** to xWrite().
  699. **
  700. ** If xRead() returns SQLITE_IOERR_SHORT_READ it must also fill
  701. ** in the unread portions of the buffer with zeros. A VFS that
  702. ** fails to zero-fill short reads might seem to work. However,
  703. ** failure to zero-fill short reads will eventually lead to
  704. ** database corruption.
  705. */
  706. typedef struct sqlite3_io_methods sqlite3_io_methods;
  707. struct sqlite3_io_methods {
  708. int iVersion;
  709. int (*xClose)(sqlite3_file*);
  710. int (*xRead)(sqlite3_file*, void*, int iAmt, sqlite3_int64 iOfst);
  711. int (*xWrite)(sqlite3_file*, const void*, int iAmt, sqlite3_int64 iOfst);
  712. int (*xTruncate)(sqlite3_file*, sqlite3_int64 size);
  713. int (*xSync)(sqlite3_file*, int flags);
  714. int (*xFileSize)(sqlite3_file*, sqlite3_int64 *pSize);
  715. int (*xLock)(sqlite3_file*, int);
  716. int (*xUnlock)(sqlite3_file*, int);
  717. int (*xCheckReservedLock)(sqlite3_file*, int *pResOut);
  718. int (*xFileControl)(sqlite3_file*, int op, void *pArg);
  719. int (*xSectorSize)(sqlite3_file*);
  720. int (*xDeviceCharacteristics)(sqlite3_file*);
  721. /* Methods above are valid for version 1 */
  722. int (*xShmMap)(sqlite3_file*, int iPg, int pgsz, int, void volatile**);
  723. int (*xShmLock)(sqlite3_file*, int offset, int n, int flags);
  724. void (*xShmBarrier)(sqlite3_file*);
  725. int (*xShmUnmap)(sqlite3_file*, int deleteFlag);
  726. /* Methods above are valid for version 2 */
  727. int (*xFetch)(sqlite3_file*, sqlite3_int64 iOfst, int iAmt, void **pp);
  728. int (*xUnfetch)(sqlite3_file*, sqlite3_int64 iOfst, void *p);
  729. /* Methods above are valid for version 3 */
  730. /* Additional methods may be added in future releases */
  731. };
  732. /*
  733. ** CAPI3REF: Standard File Control Opcodes
  734. ** KEYWORDS: {file control opcodes} {file control opcode}
  735. **
  736. ** These integer constants are opcodes for the xFileControl method
  737. ** of the [sqlite3_io_methods] object and for the [sqlite3_file_control()]
  738. ** interface.
  739. **
  740. ** <ul>
  741. ** <li>[[SQLITE_FCNTL_LOCKSTATE]]
  742. ** The [SQLITE_FCNTL_LOCKSTATE] opcode is used for debugging. This
  743. ** opcode causes the xFileControl method to write the current state of
  744. ** the lock (one of [SQLITE_LOCK_NONE], [SQLITE_LOCK_SHARED],
  745. ** [SQLITE_LOCK_RESERVED], [SQLITE_LOCK_PENDING], or [SQLITE_LOCK_EXCLUSIVE])
  746. ** into an integer that the pArg argument points to. This capability
  747. ** is used during testing and is only available when the SQLITE_TEST
  748. ** compile-time option is used.
  749. **
  750. ** <li>[[SQLITE_FCNTL_SIZE_HINT]]
  751. ** The [SQLITE_FCNTL_SIZE_HINT] opcode is used by SQLite to give the VFS
  752. ** layer a hint of how large the database file will grow to be during the
  753. ** current transaction. This hint is not guaranteed to be accurate but it
  754. ** is often close. The underlying VFS might choose to preallocate database
  755. ** file space based on this hint in order to help writes to the database
  756. ** file run faster.
  757. **
  758. ** <li>[[SQLITE_FCNTL_CHUNK_SIZE]]
  759. ** The [SQLITE_FCNTL_CHUNK_SIZE] opcode is used to request that the VFS
  760. ** extends and truncates the database file in chunks of a size specified
  761. ** by the user. The fourth argument to [sqlite3_file_control()] should
  762. ** point to an integer (type int) containing the new chunk-size to use
  763. ** for the nominated database. Allocating database file space in large
  764. ** chunks (say 1MB at a time), may reduce file-system fragmentation and
  765. ** improve performance on some systems.
  766. **
  767. ** <li>[[SQLITE_FCNTL_FILE_POINTER]]
  768. ** The [SQLITE_FCNTL_FILE_POINTER] opcode is used to obtain a pointer
  769. ** to the [sqlite3_file] object associated with a particular database
  770. ** connection. See the [sqlite3_file_control()] documentation for
  771. ** additional information.
  772. **
  773. ** <li>[[SQLITE_FCNTL_SYNC_OMITTED]]
  774. ** No longer in use.
  775. **
  776. ** <li>[[SQLITE_FCNTL_SYNC]]
  777. ** The [SQLITE_FCNTL_SYNC] opcode is generated internally by SQLite and
  778. ** sent to the VFS immediately before the xSync method is invoked on a
  779. ** database file descriptor. Or, if the xSync method is not invoked
  780. ** because the user has configured SQLite with
  781. ** [PRAGMA synchronous | PRAGMA synchronous=OFF] it is invoked in place
  782. ** of the xSync method. In most cases, the pointer argument passed with
  783. ** this file-control is NULL. However, if the database file is being synced
  784. ** as part of a multi-database commit, the argument points to a nul-terminated
  785. ** string containing the transactions master-journal file name. VFSes that
  786. ** do not need this signal should silently ignore this opcode. Applications
  787. ** should not call [sqlite3_file_control()] with this opcode as doing so may
  788. ** disrupt the operation of the specialized VFSes that do require it.
  789. **
  790. ** <li>[[SQLITE_FCNTL_COMMIT_PHASETWO]]
  791. ** The [SQLITE_FCNTL_COMMIT_PHASETWO] opcode is generated internally by SQLite
  792. ** and sent to the VFS after a transaction has been committed immediately
  793. ** but before the database is unlocked. VFSes that do not need this signal
  794. ** should silently ignore this opcode. Applications should not call
  795. ** [sqlite3_file_control()] with this opcode as doing so may disrupt the
  796. ** operation of the specialized VFSes that do require it.
  797. **
  798. ** <li>[[SQLITE_FCNTL_WIN32_AV_RETRY]]
  799. ** ^The [SQLITE_FCNTL_WIN32_AV_RETRY] opcode is used to configure automatic
  800. ** retry counts and intervals for certain disk I/O operations for the
  801. ** windows [VFS] in order to provide robustness in the presence of
  802. ** anti-virus programs. By default, the windows VFS will retry file read,
  803. ** file write, and file delete operations up to 10 times, with a delay
  804. ** of 25 milliseconds before the first retry and with the delay increasing
  805. ** by an additional 25 milliseconds with each subsequent retry. This
  806. ** opcode allows these two values (10 retries and 25 milliseconds of delay)
  807. ** to be adjusted. The values are changed for all database connections
  808. ** within the same process. The argument is a pointer to an array of two
  809. ** integers where the first integer i the new retry count and the second
  810. ** integer is the delay. If either integer is negative, then the setting
  811. ** is not changed but instead the prior value of that setting is written
  812. ** into the array entry, allowing the current retry settings to be
  813. ** interrogated. The zDbName parameter is ignored.
  814. **
  815. ** <li>[[SQLITE_FCNTL_PERSIST_WAL]]
  816. ** ^The [SQLITE_FCNTL_PERSIST_WAL] opcode is used to set or query the
  817. ** persistent [WAL | Write Ahead Log] setting. By default, the auxiliary
  818. ** write ahead log and shared memory files used for transaction control
  819. ** are automatically deleted when the latest connection to the database
  820. ** closes. Setting persistent WAL mode causes those files to persist after
  821. ** close. Persisting the files is useful when other processes that do not
  822. ** have write permission on the directory containing the database file want
  823. ** to read the database file, as the WAL and shared memory files must exist
  824. ** in order for the database to be readable. The fourth parameter to
  825. ** [sqlite3_file_control()] for this opcode should be a pointer to an integer.
  826. ** That integer is 0 to disable persistent WAL mode or 1 to enable persistent
  827. ** WAL mode. If the integer is -1, then it is overwritten with the current
  828. ** WAL persistence setting.
  829. **
  830. ** <li>[[SQLITE_FCNTL_POWERSAFE_OVERWRITE]]
  831. ** ^The [SQLITE_FCNTL_POWERSAFE_OVERWRITE] opcode is used to set or query the
  832. ** persistent "powersafe-overwrite" or "PSOW" setting. The PSOW setting
  833. ** determines the [SQLITE_IOCAP_POWERSAFE_OVERWRITE] bit of the
  834. ** xDeviceCharacteristics methods. The fourth parameter to
  835. ** [sqlite3_file_control()] for this opcode should be a pointer to an integer.
  836. ** That integer is 0 to disable zero-damage mode or 1 to enable zero-damage
  837. ** mode. If the integer is -1, then it is overwritten with the current
  838. ** zero-damage mode setting.
  839. **
  840. ** <li>[[SQLITE_FCNTL_OVERWRITE]]
  841. ** ^The [SQLITE_FCNTL_OVERWRITE] opcode is invoked by SQLite after opening
  842. ** a write transaction to indicate that, unless it is rolled back for some
  843. ** reason, the entire database file will be overwritten by the current
  844. ** transaction. This is used by VACUUM operations.
  845. **
  846. ** <li>[[SQLITE_FCNTL_VFSNAME]]
  847. ** ^The [SQLITE_FCNTL_VFSNAME] opcode can be used to obtain the names of
  848. ** all [VFSes] in the VFS stack. The names are of all VFS shims and the
  849. ** final bottom-level VFS are written into memory obtained from
  850. ** [sqlite3_malloc()] and the result is stored in the char* variable
  851. ** that the fourth parameter of [sqlite3_file_control()] points to.
  852. ** The caller is responsible for freeing the memory when done. As with
  853. ** all file-control actions, there is no guarantee that this will actually
  854. ** do anything. Callers should initialize the char* variable to a NULL
  855. ** pointer in case this file-control is not implemented. This file-control
  856. ** is intended for diagnostic use only.
  857. **
  858. ** <li>[[SQLITE_FCNTL_PRAGMA]]
  859. ** ^Whenever a [PRAGMA] statement is parsed, an [SQLITE_FCNTL_PRAGMA]
  860. ** file control is sent to the open [sqlite3_file] object corresponding
  861. ** to the database file to which the pragma statement refers. ^The argument
  862. ** to the [SQLITE_FCNTL_PRAGMA] file control is an array of
  863. ** pointers to strings (char**) in which the second element of the array
  864. ** is the name of the pragma and the third element is the argument to the
  865. ** pragma or NULL if the pragma has no argument. ^The handler for an
  866. ** [SQLITE_FCNTL_PRAGMA] file control can optionally make the first element
  867. ** of the char** argument point to a string obtained from [sqlite3_mprintf()]
  868. ** or the equivalent and that string will become the result of the pragma or
  869. ** the error message if the pragma fails. ^If the
  870. ** [SQLITE_FCNTL_PRAGMA] file control returns [SQLITE_NOTFOUND], then normal
  871. ** [PRAGMA] processing continues. ^If the [SQLITE_FCNTL_PRAGMA]
  872. ** file control returns [SQLITE_OK], then the parser assumes that the
  873. ** VFS has handled the PRAGMA itself and the parser generates a no-op
  874. ** prepared statement if result string is NULL, or that returns a copy
  875. ** of the result string if the string is non-NULL.
  876. ** ^If the [SQLITE_FCNTL_PRAGMA] file control returns
  877. ** any result code other than [SQLITE_OK] or [SQLITE_NOTFOUND], that means
  878. ** that the VFS encountered an error while handling the [PRAGMA] and the
  879. ** compilation of the PRAGMA fails with an error. ^The [SQLITE_FCNTL_PRAGMA]
  880. ** file control occurs at the beginning of pragma statement analysis and so
  881. ** it is able to override built-in [PRAGMA] statements.
  882. **
  883. ** <li>[[SQLITE_FCNTL_BUSYHANDLER]]
  884. ** ^The [SQLITE_FCNTL_BUSYHANDLER]
  885. ** file-control may be invoked by SQLite on the database file handle
  886. ** shortly after it is opened in order to provide a custom VFS with access
  887. ** to the connections busy-handler callback. The argument is of type (void **)
  888. ** - an array of two (void *) values. The first (void *) actually points
  889. ** to a function of type (int (*)(void *)). In order to invoke the connections
  890. ** busy-handler, this function should be invoked with the second (void *) in
  891. ** the array as the only argument. If it returns non-zero, then the operation
  892. ** should be retried. If it returns zero, the custom VFS should abandon the
  893. ** current operation.
  894. **
  895. ** <li>[[SQLITE_FCNTL_TEMPFILENAME]]
  896. ** ^Application can invoke the [SQLITE_FCNTL_TEMPFILENAME] file-control
  897. ** to have SQLite generate a
  898. ** temporary filename using the same algorithm that is followed to generate
  899. ** temporary filenames for TEMP tables and other internal uses. The
  900. ** argument should be a char** which will be filled with the filename
  901. ** written into memory obtained from [sqlite3_malloc()]. The caller should
  902. ** invoke [sqlite3_free()] on the result to avoid a memory leak.
  903. **
  904. ** <li>[[SQLITE_FCNTL_MMAP_SIZE]]
  905. ** The [SQLITE_FCNTL_MMAP_SIZE] file control is used to query or set the
  906. ** maximum number of bytes that will be used for memory-mapped I/O.
  907. ** The argument is a pointer to a value of type sqlite3_int64 that
  908. ** is an advisory maximum number of bytes in the file to memory map. The
  909. ** pointer is overwritten with the old value. The limit is not changed if
  910. ** the value originally pointed to is negative, and so the current limit
  911. ** can be queried by passing in a pointer to a negative number. This
  912. ** file-control is used internally to implement [PRAGMA mmap_size].
  913. **
  914. ** <li>[[SQLITE_FCNTL_TRACE]]
  915. ** The [SQLITE_FCNTL_TRACE] file control provides advisory information
  916. ** to the VFS about what the higher layers of the SQLite stack are doing.
  917. ** This file control is used by some VFS activity tracing [shims].
  918. ** The argument is a zero-terminated string. Higher layers in the
  919. ** SQLite stack may generate instances of this file control if
  920. ** the [SQLITE_USE_FCNTL_TRACE] compile-time option is enabled.
  921. **
  922. ** <li>[[SQLITE_FCNTL_HAS_MOVED]]
  923. ** The [SQLITE_FCNTL_HAS_MOVED] file control interprets its argument as a
  924. ** pointer to an integer and it writes a boolean into that integer depending
  925. ** on whether or not the file has been renamed, moved, or deleted since it
  926. ** was first opened.
  927. **
  928. ** <li>[[SQLITE_FCNTL_WIN32_SET_HANDLE]]
  929. ** The [SQLITE_FCNTL_WIN32_SET_HANDLE] opcode is used for debugging. This
  930. ** opcode causes the xFileControl method to swap the file handle with the one
  931. ** pointed to by the pArg argument. This capability is used during testing
  932. ** and only needs to be supported when SQLITE_TEST is defined.
  933. **
  934. ** <li>[[SQLITE_FCNTL_WAL_BLOCK]]
  935. ** The [SQLITE_FCNTL_WAL_BLOCK] is a signal to the VFS layer that it might
  936. ** be advantageous to block on the next WAL lock if the lock is not immediately
  937. ** available. The WAL subsystem issues this signal during rare
  938. ** circumstances in order to fix a problem with priority inversion.
  939. ** Applications should <em>not</em> use this file-control.
  940. **
  941. ** <li>[[SQLITE_FCNTL_ZIPVFS]]
  942. ** The [SQLITE_FCNTL_ZIPVFS] opcode is implemented by zipvfs only. All other
  943. ** VFS should return SQLITE_NOTFOUND for this opcode.
  944. **
  945. ** <li>[[SQLITE_FCNTL_RBU]]
  946. ** The [SQLITE_FCNTL_RBU] opcode is implemented by the special VFS used by
  947. ** the RBU extension only. All other VFS should return SQLITE_NOTFOUND for
  948. ** this opcode.
  949. ** </ul>
  950. */
  951. #define SQLITE_FCNTL_LOCKSTATE 1
  952. #define SQLITE_FCNTL_GET_LOCKPROXYFILE 2
  953. #define SQLITE_FCNTL_SET_LOCKPROXYFILE 3
  954. #define SQLITE_FCNTL_LAST_ERRNO 4
  955. #define SQLITE_FCNTL_SIZE_HINT 5
  956. #define SQLITE_FCNTL_CHUNK_SIZE 6
  957. #define SQLITE_FCNTL_FILE_POINTER 7
  958. #define SQLITE_FCNTL_SYNC_OMITTED 8
  959. #define SQLITE_FCNTL_WIN32_AV_RETRY 9
  960. #define SQLITE_FCNTL_PERSIST_WAL 10
  961. #define SQLITE_FCNTL_OVERWRITE 11
  962. #define SQLITE_FCNTL_VFSNAME 12
  963. #define SQLITE_FCNTL_POWERSAFE_OVERWRITE 13
  964. #define SQLITE_FCNTL_PRAGMA 14
  965. #define SQLITE_FCNTL_BUSYHANDLER 15
  966. #define SQLITE_FCNTL_TEMPFILENAME 16
  967. #define SQLITE_FCNTL_MMAP_SIZE 18
  968. #define SQLITE_FCNTL_TRACE 19
  969. #define SQLITE_FCNTL_HAS_MOVED 20
  970. #define SQLITE_FCNTL_SYNC 21
  971. #define SQLITE_FCNTL_COMMIT_PHASETWO 22
  972. #define SQLITE_FCNTL_WIN32_SET_HANDLE 23
  973. #define SQLITE_FCNTL_WAL_BLOCK 24
  974. #define SQLITE_FCNTL_ZIPVFS 25
  975. #define SQLITE_FCNTL_RBU 26
  976. /* deprecated names */
  977. #define SQLITE_GET_LOCKPROXYFILE SQLITE_FCNTL_GET_LOCKPROXYFILE
  978. #define SQLITE_SET_LOCKPROXYFILE SQLITE_FCNTL_SET_LOCKPROXYFILE
  979. #define SQLITE_LAST_ERRNO SQLITE_FCNTL_LAST_ERRNO
  980. /*
  981. ** CAPI3REF: Mutex Handle
  982. **
  983. ** The mutex module within SQLite defines [sqlite3_mutex] to be an
  984. ** abstract type for a mutex object. The SQLite core never looks
  985. ** at the internal representation of an [sqlite3_mutex]. It only
  986. ** deals with pointers to the [sqlite3_mutex] object.
  987. **
  988. ** Mutexes are created using [sqlite3_mutex_alloc()].
  989. */
  990. typedef struct sqlite3_mutex sqlite3_mutex;
  991. /*
  992. ** CAPI3REF: OS Interface Object
  993. **
  994. ** An instance of the sqlite3_vfs object defines the interface between
  995. ** the SQLite core and the underlying operating system. The "vfs"
  996. ** in the name of the object stands for "virtual file system". See
  997. ** the [VFS | VFS documentation] for further information.
  998. **
  999. ** The value of the iVersion field is initially 1 but may be larger in
  1000. ** future versions of SQLite. Additional fields may be appended to this
  1001. ** object when the iVersion value is increased. Note that the structure
  1002. ** of the sqlite3_vfs object changes in the transaction between
  1003. ** SQLite version 3.5.9 and 3.6.0 and yet the iVersion field was not
  1004. ** modified.
  1005. **
  1006. ** The szOsFile field is the size of the subclassed [sqlite3_file]
  1007. ** structure used by this VFS. mxPathname is the maximum length of
  1008. ** a pathname in this VFS.
  1009. **
  1010. ** Registered sqlite3_vfs objects are kept on a linked list formed by
  1011. ** the pNext pointer. The [sqlite3_vfs_register()]
  1012. ** and [sqlite3_vfs_unregister()] interfaces manage this list
  1013. ** in a thread-safe way. The [sqlite3_vfs_find()] interface
  1014. ** searches the list. Neither the application code nor the VFS
  1015. ** implementation should use the pNext pointer.
  1016. **
  1017. ** The pNext field is the only field in the sqlite3_vfs
  1018. ** structure that SQLite will ever modify. SQLite will only access
  1019. ** or modify this field while holding a particular static mutex.
  1020. ** The application should never modify anything within the sqlite3_vfs
  1021. ** object once the object has been registered.
  1022. **
  1023. ** The zName field holds the name of the VFS module. The name must
  1024. ** be unique across all VFS modules.
  1025. **
  1026. ** [[sqlite3_vfs.xOpen]]
  1027. ** ^SQLite guarantees that the zFilename parameter to xOpen
  1028. ** is either a NULL pointer or string obtained
  1029. ** from xFullPathname() with an optional suffix added.
  1030. ** ^If a suffix is added to the zFilename parameter, it will
  1031. ** consist of a single "-" character followed by no more than
  1032. ** 11 alphanumeric and/or "-" characters.
  1033. ** ^SQLite further guarantees that
  1034. ** the string will be valid and unchanged until xClose() is
  1035. ** called. Because of the previous sentence,
  1036. ** the [sqlite3_file] can safely store a pointer to the
  1037. ** filename if it needs to remember the filename for some reason.
  1038. ** If the zFilename parameter to xOpen is a NULL pointer then xOpen
  1039. ** must invent its own temporary name for the file. ^Whenever the
  1040. ** xFilename parameter is NULL it will also be the case that the
  1041. ** flags parameter will include [SQLITE_OPEN_DELETEONCLOSE].
  1042. **
  1043. ** The flags argument to xOpen() includes all bits set in
  1044. ** the flags argument to [sqlite3_open_v2()]. Or if [sqlite3_open()]
  1045. ** or [sqlite3_open16()] is used, then flags includes at least
  1046. ** [SQLITE_OPEN_READWRITE] | [SQLITE_OPEN_CREATE].
  1047. ** If xOpen() opens a file read-only then it sets *pOutFlags to
  1048. ** include [SQLITE_OPEN_READONLY]. Other bits in *pOutFlags may be set.
  1049. **
  1050. ** ^(SQLite will also add one of the following flags to the xOpen()
  1051. ** call, depending on the object being opened:
  1052. **
  1053. ** <ul>
  1054. ** <li> [SQLITE_OPEN_MAIN_DB]
  1055. ** <li> [SQLITE_OPEN_MAIN_JOURNAL]
  1056. ** <li> [SQLITE_OPEN_TEMP_DB]
  1057. ** <li> [SQLITE_OPEN_TEMP_JOURNAL]
  1058. ** <li> [SQLITE_OPEN_TRANSIENT_DB]
  1059. ** <li> [SQLITE_OPEN_SUBJOURNAL]
  1060. ** <li> [SQLITE_OPEN_MASTER_JOURNAL]
  1061. ** <li> [SQLITE_OPEN_WAL]
  1062. ** </ul>)^
  1063. **
  1064. ** The file I/O implementation can use the object type flags to
  1065. ** change the way it deals with files. For example, an application
  1066. ** that does not care about crash recovery or rollback might make
  1067. ** the open of a journal file a no-op. Writes to this journal would
  1068. ** also be no-ops, and any attempt to read the journal would return
  1069. ** SQLITE_IOERR. Or the implementation might recognize that a database
  1070. ** file will be doing page-aligned sector reads and writes in a random
  1071. ** order and set up its I/O subsystem accordingly.
  1072. **
  1073. ** SQLite might also add one of the following flags to the xOpen method:
  1074. **
  1075. ** <ul>
  1076. ** <li> [SQLITE_OPEN_DELETEONCLOSE]
  1077. ** <li> [SQLITE_OPEN_EXCLUSIVE]
  1078. ** </ul>
  1079. **
  1080. ** The [SQLITE_OPEN_DELETEONCLOSE] flag means the file should be
  1081. ** deleted when it is closed. ^The [SQLITE_OPEN_DELETEONCLOSE]
  1082. ** will be set for TEMP databases and their journals, transient
  1083. ** databases, and subjournals.
  1084. **
  1085. ** ^The [SQLITE_OPEN_EXCLUSIVE] flag is always used in conjunction
  1086. ** with the [SQLITE_OPEN_CREATE] flag, which are both directly
  1087. ** analogous to the O_EXCL and O_CREAT flags of the POSIX open()
  1088. ** API. The SQLITE_OPEN_EXCLUSIVE flag, when paired with the
  1089. ** SQLITE_OPEN_CREATE, is used to indicate that file should always
  1090. ** be created, and that it is an error if it already exists.
  1091. ** It is <i>not</i> used to indicate the file should be opened
  1092. ** for exclusive access.
  1093. **
  1094. ** ^At least szOsFile bytes of memory are allocated by SQLite
  1095. ** to hold the [sqlite3_file] structure passed as the third
  1096. ** argument to xOpen. The xOpen method does not have to
  1097. ** allocate the structure; it should just fill it in. Note that
  1098. ** the xOpen method must set the sqlite3_file.pMethods to either
  1099. ** a valid [sqlite3_io_methods] object or to NULL. xOpen must do
  1100. ** this even if the open fails. SQLite expects that the sqlite3_file.pMethods
  1101. ** element will be valid after xOpen returns regardless of the success
  1102. ** or failure of the xOpen call.
  1103. **
  1104. ** [[sqlite3_vfs.xAccess]]
  1105. ** ^The flags argument to xAccess() may be [SQLITE_ACCESS_EXISTS]
  1106. ** to test for the existence of a file, or [SQLITE_ACCESS_READWRITE] to
  1107. ** test whether a file is readable and writable, or [SQLITE_ACCESS_READ]
  1108. ** to test whether a file is at least readable. The file can be a
  1109. ** directory.
  1110. **
  1111. ** ^SQLite will always allocate at least mxPathname+1 bytes for the
  1112. ** output buffer xFullPathname. The exact size of the output buffer
  1113. ** is also passed as a parameter to both methods. If the output buffer
  1114. ** is not large enough, [SQLITE_CANTOPEN] should be returned. Since this is
  1115. ** handled as a fatal error by SQLite, vfs implementations should endeavor
  1116. ** to prevent this by setting mxPathname to a sufficiently large value.
  1117. **
  1118. ** The xRandomness(), xSleep(), xCurrentTime(), and xCurrentTimeInt64()
  1119. ** interfaces are not strictly a part of the filesystem, but they are
  1120. ** included in the VFS structure for completeness.
  1121. ** The xRandomness() function attempts to return nBytes bytes
  1122. ** of good-quality randomness into zOut. The return value is
  1123. ** the actual number of bytes of randomness obtained.
  1124. ** The xSleep() method causes the calling thread to sleep for at
  1125. ** least the number of microseconds given. ^The xCurrentTime()
  1126. ** method returns a Julian Day Number for the current date and time as
  1127. ** a floating point value.
  1128. ** ^The xCurrentTimeInt64() method returns, as an integer, the Julian
  1129. ** Day Number multiplied by 86400000 (the number of milliseconds in
  1130. ** a 24-hour day).
  1131. ** ^SQLite will use the xCurrentTimeInt64() method to get the current
  1132. ** date and time if that method is available (if iVersion is 2 or
  1133. ** greater and the function pointer is not NULL) and will fall back
  1134. ** to xCurrentTime() if xCurrentTimeInt64() is unavailable.
  1135. **
  1136. ** ^The xSetSystemCall(), xGetSystemCall(), and xNestSystemCall() interfaces
  1137. ** are not used by the SQLite core. These optional interfaces are provided
  1138. ** by some VFSes to facilitate testing of the VFS code. By overriding
  1139. ** system calls with functions under its control, a test program can
  1140. ** simulate faults and error conditions that would otherwise be difficult
  1141. ** or impossible to induce. The set of system calls that can be overridden
  1142. ** varies from one VFS to another, and from one version of the same VFS to the
  1143. ** next. Applications that use these interfaces must be prepared for any
  1144. ** or all of these interfaces to be NULL or for their behavior to change
  1145. ** from one release to the next. Applications must not attempt to access
  1146. ** any of these methods if the iVersion of the VFS is less than 3.
  1147. */
  1148. typedef struct sqlite3_vfs sqlite3_vfs;
  1149. typedef void (*sqlite3_syscall_ptr)(void);
  1150. struct sqlite3_vfs {
  1151. int iVersion; /* Structure version number (currently 3) */
  1152. int szOsFile; /* Size of subclassed sqlite3_file */
  1153. int mxPathname; /* Maximum file pathname length */
  1154. sqlite3_vfs *pNext; /* Next registered VFS */
  1155. const char *zName; /* Name of this virtual file system */
  1156. void *pAppData; /* Pointer to application-specific data */
  1157. int (*xOpen)(sqlite3_vfs*, const char *zName, sqlite3_file*,
  1158. int flags, int *pOutFlags);
  1159. int (*xDelete)(sqlite3_vfs*, const char *zName, int syncDir);
  1160. int (*xAccess)(sqlite3_vfs*, const char *zName, int flags, int *pResOut);
  1161. int (*xFullPathname)(sqlite3_vfs*, const char *zName, int nOut, char *zOut);
  1162. void *(*xDlOpen)(sqlite3_vfs*, const char *zFilename);
  1163. void (*xDlError)(sqlite3_vfs*, int nByte, char *zErrMsg);
  1164. void (*(*xDlSym)(sqlite3_vfs*,void*, const char *zSymbol))(void);
  1165. void (*xDlClose)(sqlite3_vfs*, void*);
  1166. int (*xRandomness)(sqlite3_vfs*, int nByte, char *zOut);
  1167. int (*xSleep)(sqlite3_vfs*, int microseconds);
  1168. int (*xCurrentTime)(sqlite3_vfs*, double*);
  1169. int (*xGetLastError)(sqlite3_vfs*, int, char *);
  1170. /*
  1171. ** The methods above are in version 1 of the sqlite_vfs object
  1172. ** definition. Those that follow are added in version 2 or later
  1173. */
  1174. int (*xCurrentTimeInt64)(sqlite3_vfs*, sqlite3_int64*);
  1175. /*
  1176. ** The methods above are in versions 1 and 2 of the sqlite_vfs object.
  1177. ** Those below are for version 3 and greater.
  1178. */
  1179. int (*xSetSystemCall)(sqlite3_vfs*, const char *zName, sqlite3_syscall_ptr);
  1180. sqlite3_syscall_ptr (*xGetSystemCall)(sqlite3_vfs*, const char *zName);
  1181. const char *(*xNextSystemCall)(sqlite3_vfs*, const char *zName);
  1182. /*
  1183. ** The methods above are in versions 1 through 3 of the sqlite_vfs object.
  1184. ** New fields may be appended in figure versions. The iVersion
  1185. ** value will increment whenever this happens.
  1186. */
  1187. };
  1188. /*
  1189. ** CAPI3REF: Flags for the xAccess VFS method
  1190. **
  1191. ** These integer constants can be used as the third parameter to
  1192. ** the xAccess method of an [sqlite3_vfs] object. They determine
  1193. ** what kind of permissions the xAccess method is looking for.
  1194. ** With SQLITE_ACCESS_EXISTS, the xAccess method
  1195. ** simply checks whether the file exists.
  1196. ** With SQLITE_ACCESS_READWRITE, the xAccess method
  1197. ** checks whether the named directory is both readable and writable
  1198. ** (in other words, if files can be added, removed, and renamed within
  1199. ** the directory).
  1200. ** The SQLITE_ACCESS_READWRITE constant is currently used only by the
  1201. ** [temp_store_directory pragma], though this could change in a future
  1202. ** release of SQLite.
  1203. ** With SQLITE_ACCESS_READ, the xAccess method
  1204. ** checks whether the file is readable. The SQLITE_ACCESS_READ constant is
  1205. ** currently unused, though it might be used in a future release of
  1206. ** SQLite.
  1207. */
  1208. #define SQLITE_ACCESS_EXISTS 0
  1209. #define SQLITE_ACCESS_READWRITE 1 /* Used by PRAGMA temp_store_directory */
  1210. #define SQLITE_ACCESS_READ 2 /* Unused */
  1211. /*
  1212. ** CAPI3REF: Flags for the xShmLock VFS method
  1213. **
  1214. ** These integer constants define the various locking operations
  1215. ** allowed by the xShmLock method of [sqlite3_io_methods]. The
  1216. ** following are the only legal combinations of flags to the
  1217. ** xShmLock method:
  1218. **
  1219. ** <ul>
  1220. ** <li> SQLITE_SHM_LOCK | SQLITE_SHM_SHARED
  1221. ** <li> SQLITE_SHM_LOCK | SQLITE_SHM_EXCLUSIVE
  1222. ** <li> SQLITE_SHM_UNLOCK | SQLITE_SHM_SHARED
  1223. ** <li> SQLITE_SHM_UNLOCK | SQLITE_SHM_EXCLUSIVE
  1224. ** </ul>
  1225. **
  1226. ** When unlocking, the same SHARED or EXCLUSIVE flag must be supplied as
  1227. ** was given on the corresponding lock.
  1228. **
  1229. ** The xShmLock method can transition between unlocked and SHARED or
  1230. ** between unlocked and EXCLUSIVE. It cannot transition between SHARED
  1231. ** and EXCLUSIVE.
  1232. */
  1233. #define SQLITE_SHM_UNLOCK 1
  1234. #define SQLITE_SHM_LOCK 2
  1235. #define SQLITE_SHM_SHARED 4
  1236. #define SQLITE_SHM_EXCLUSIVE 8
  1237. /*
  1238. ** CAPI3REF: Maximum xShmLock index
  1239. **
  1240. ** The xShmLock method on [sqlite3_io_methods] may use values
  1241. ** between 0 and this upper bound as its "offset" argument.
  1242. ** The SQLite core will never attempt to acquire or release a
  1243. ** lock outside of this range
  1244. */
  1245. #define SQLITE_SHM_NLOCK 8
  1246. /*
  1247. ** CAPI3REF: Initialize The SQLite Library
  1248. **
  1249. ** ^The sqlite3_initialize() routine initializes the
  1250. ** SQLite library. ^The sqlite3_shutdown() routine
  1251. ** deallocates any resources that were allocated by sqlite3_initialize().
  1252. ** These routines are designed to aid in process initialization and
  1253. ** shutdown on embedded systems. Workstation applications using
  1254. ** SQLite normally do not need to invoke either of these routines.
  1255. **
  1256. ** A call to sqlite3_initialize() is an "effective" call if it is
  1257. ** the first time sqlite3_initialize() is invoked during the lifetime of
  1258. ** the process, or if it is the first time sqlite3_initialize() is invoked
  1259. ** following a call to sqlite3_shutdown(). ^(Only an effective call
  1260. ** of sqlite3_initialize() does any initialization. All other calls
  1261. ** are harmless no-ops.)^
  1262. **
  1263. ** A call to sqlite3_shutdown() is an "effective" call if it is the first
  1264. ** call to sqlite3_shutdown() since the last sqlite3_initialize(). ^(Only
  1265. ** an effective call to sqlite3_shutdown() does any deinitialization.
  1266. ** All other valid calls to sqlite3_shutdown() are harmless no-ops.)^
  1267. **
  1268. ** The sqlite3_initialize() interface is threadsafe, but sqlite3_shutdown()
  1269. ** is not. The sqlite3_shutdown() interface must only be called from a
  1270. ** single thread. All open [database connections] must be closed and all
  1271. ** other SQLite resources must be deallocated prior to invoking
  1272. ** sqlite3_shutdown().
  1273. **
  1274. ** Among other things, ^sqlite3_initialize() will invoke
  1275. ** sqlite3_os_init(). Similarly, ^sqlite3_shutdown()
  1276. ** will invoke sqlite3_os_end().
  1277. **
  1278. ** ^The sqlite3_initialize() routine returns [SQLITE_OK] on success.
  1279. ** ^If for some reason, sqlite3_initialize() is unable to initialize
  1280. ** the library (perhaps it is unable to allocate a needed resource such
  1281. ** as a mutex) it returns an [error code] other than [SQLITE_OK].
  1282. **
  1283. ** ^The sqlite3_initialize() routine is called internally by many other
  1284. ** SQLite interfaces so that an application usually does not need to
  1285. ** invoke sqlite3_initialize() directly. For example, [sqlite3_open()]
  1286. ** calls sqlite3_initialize() so the SQLite library will be automatically
  1287. ** initialized when [sqlite3_open()] is called if it has not be initialized
  1288. ** already. ^However, if SQLite is compiled with the [SQLITE_OMIT_AUTOINIT]
  1289. ** compile-time option, then the automatic calls to sqlite3_initialize()
  1290. ** are omitted and the application must call sqlite3_initialize() directly
  1291. ** prior to using any other SQLite interface. For maximum portability,
  1292. ** it is recommended that applications always invoke sqlite3_initialize()
  1293. ** directly prior to using any other SQLite interface. Future releases
  1294. ** of SQLite may require this. In other words, the behavior exhibited
  1295. ** when SQLite is compiled with [SQLITE_OMIT_AUTOINIT] might become the
  1296. ** default behavior in some future release of SQLite.
  1297. **
  1298. ** The sqlite3_os_init() routine does operating-system specific
  1299. ** initialization of the SQLite library. The sqlite3_os_end()
  1300. ** routine undoes the effect of sqlite3_os_init(). Typical tasks
  1301. ** performed by these routines include allocation or deallocation
  1302. ** of static resources, initialization of global variables,
  1303. ** setting up a default [sqlite3_vfs] module, or setting up
  1304. ** a default configuration using [sqlite3_config()].
  1305. **
  1306. ** The application should never invoke either sqlite3_os_init()
  1307. ** or sqlite3_os_end() directly. The application should only invoke
  1308. ** sqlite3_initialize() and sqlite3_shutdown(). The sqlite3_os_init()
  1309. ** interface is called automatically by sqlite3_initialize() and
  1310. ** sqlite3_os_end() is called by sqlite3_shutdown(). Appropriate
  1311. ** implementations for sqlite3_os_init() and sqlite3_os_end()
  1312. ** are built into SQLite when it is compiled for Unix, Windows, or OS/2.
  1313. ** When [custom builds | built for other platforms]
  1314. ** (using the [SQLITE_OS_OTHER=1] compile-time
  1315. ** option) the application must supply a suitable implementation for
  1316. ** sqlite3_os_init() and sqlite3_os_end(). An application-supplied
  1317. ** implementation of sqlite3_os_init() or sqlite3_os_end()
  1318. ** must return [SQLITE_OK] on success and some other [error code] upon
  1319. ** failure.
  1320. */
  1321. SQLITE_API int SQLITE_STDCALL sqlite3_initialize(void);
  1322. SQLITE_API int SQLITE_STDCALL sqlite3_shutdown(void);
  1323. SQLITE_API int SQLITE_STDCALL sqlite3_os_init(void);
  1324. SQLITE_API int SQLITE_STDCALL sqlite3_os_end(void);
  1325. /*
  1326. ** CAPI3REF: Configuring The SQLite Library
  1327. **
  1328. ** The sqlite3_config() interface is used to make global configuration
  1329. ** changes to SQLite in order to tune SQLite to the specific needs of
  1330. ** the application. The default configuration is recommended for most
  1331. ** applications and so this routine is usually not necessary. It is
  1332. ** provided to support rare applications with unusual needs.
  1333. **
  1334. ** The sqlite3_config() interface is not threadsafe. The application
  1335. ** must insure that no other SQLite interfaces are invoked by other
  1336. ** threads while sqlite3_config() is running. Furthermore, sqlite3_config()
  1337. ** may only be invoked prior to library initialization using
  1338. ** [sqlite3_initialize()] or after shutdown by [sqlite3_shutdown()].
  1339. ** ^If sqlite3_config() is called after [sqlite3_initialize()] and before
  1340. ** [sqlite3_shutdown()] then it will return SQLITE_MISUSE.
  1341. ** Note, however, that ^sqlite3_config() can be called as part of the
  1342. ** implementation of an application-defined [sqlite3_os_init()].
  1343. **
  1344. ** The first argument to sqlite3_config() is an integer
  1345. ** [configuration option] that determines
  1346. ** what property of SQLite is to be configured. Subsequent arguments
  1347. ** vary depending on the [configuration option]
  1348. ** in the first argument.
  1349. **
  1350. ** ^When a configuration option is set, sqlite3_config() returns [SQLITE_OK].
  1351. ** ^If the option is unknown or SQLite is unable to set the option
  1352. ** then this routine returns a non-zero [error code].
  1353. */
  1354. SQLITE_API int SQLITE_CDECL sqlite3_config(int, ...);
  1355. /*
  1356. ** CAPI3REF: Configure database connections
  1357. ** METHOD: sqlite3
  1358. **
  1359. ** The sqlite3_db_config() interface is used to make configuration
  1360. ** changes to a [database connection]. The interface is similar to
  1361. ** [sqlite3_config()] except that the changes apply to a single
  1362. ** [database connection] (specified in the first argument).
  1363. **
  1364. ** The second argument to sqlite3_db_config(D,V,...) is the
  1365. ** [SQLITE_DBCONFIG_LOOKASIDE | configuration verb] - an integer code
  1366. ** that indicates what aspect of the [database connection] is being configured.
  1367. ** Subsequent arguments vary depending on the configuration verb.
  1368. **
  1369. ** ^Calls to sqlite3_db_config() return SQLITE_OK if and only if
  1370. ** the call is considered successful.
  1371. */
  1372. SQLITE_API int SQLITE_CDECL sqlite3_db_config(sqlite3*, int op, ...);
  1373. /*
  1374. ** CAPI3REF: Memory Allocation Routines
  1375. **
  1376. ** An instance of this object defines the interface between SQLite
  1377. ** and low-level memory allocation routines.
  1378. **
  1379. ** This object is used in only one place in the SQLite interface.
  1380. ** A pointer to an instance of this object is the argument to
  1381. ** [sqlite3_config()] when the configuration option is
  1382. ** [SQLITE_CONFIG_MALLOC] or [SQLITE_CONFIG_GETMALLOC].
  1383. ** By creating an instance of this object
  1384. ** and passing it to [sqlite3_config]([SQLITE_CONFIG_MALLOC])
  1385. ** during configuration, an application can specify an alternative
  1386. ** memory allocation subsystem for SQLite to use for all of its
  1387. ** dynamic memory needs.
  1388. **
  1389. ** Note that SQLite comes with several [built-in memory allocators]
  1390. ** that are perfectly adequate for the overwhelming majority of applications
  1391. ** and that this object is only useful to a tiny minority of applications
  1392. ** with specialized memory allocation requirements. This object is
  1393. ** also used during testing of SQLite in order to specify an alternative
  1394. ** memory allocator that simulates memory out-of-memory conditions in
  1395. ** order to verify that SQLite recovers gracefully from such
  1396. ** conditions.
  1397. **
  1398. ** The xMalloc, xRealloc, and xFree methods must work like the
  1399. ** malloc(), realloc() and free() functions from the standard C library.
  1400. ** ^SQLite guarantees that the second argument to
  1401. ** xRealloc is always a value returned by a prior call to xRoundup.
  1402. **
  1403. ** xSize should return the allocated size of a memory allocation
  1404. ** previously obtained from xMalloc or xRealloc. The allocated size
  1405. ** is always at least as big as the requested size but may be larger.
  1406. **
  1407. ** The xRoundup method returns what would be the allocated size of
  1408. ** a memory allocation given a particular requested size. Most memory
  1409. ** allocators round up memory allocations at least to the next multiple
  1410. ** of 8. Some allocators round up to a larger multiple or to a power of 2.
  1411. ** Every memory allocation request coming in through [sqlite3_malloc()]
  1412. ** or [sqlite3_realloc()] first calls xRoundup. If xRoundup returns 0,
  1413. ** that causes the corresponding memory allocation to fail.
  1414. **
  1415. ** The xInit method initializes the memory allocator. For example,
  1416. ** it might allocate any require mutexes or initialize internal data
  1417. ** structures. The xShutdown method is invoked (indirectly) by
  1418. ** [sqlite3_shutdown()] and should deallocate any resources acquired
  1419. ** by xInit. The pAppData pointer is used as the only parameter to
  1420. ** xInit and xShutdown.
  1421. **
  1422. ** SQLite holds the [SQLITE_MUTEX_STATIC_MASTER] mutex when it invokes
  1423. ** the xInit method, so the xInit method need not be threadsafe. The
  1424. ** xShutdown method is only called from [sqlite3_shutdown()] so it does
  1425. ** not need to be threadsafe either. For all other methods, SQLite
  1426. ** holds the [SQLITE_MUTEX_STATIC_MEM] mutex as long as the
  1427. ** [SQLITE_CONFIG_MEMSTATUS] configuration option is turned on (which
  1428. ** it is by default) and so the methods are automatically serialized.
  1429. ** However, if [SQLITE_CONFIG_MEMSTATUS] is disabled, then the other
  1430. ** methods must be threadsafe or else make their own arrangements for
  1431. ** serialization.
  1432. **
  1433. ** SQLite will never invoke xInit() more than once without an intervening
  1434. ** call to xShutdown().
  1435. */
  1436. typedef struct sqlite3_mem_methods sqlite3_mem_methods;
  1437. struct sqlite3_mem_methods {
  1438. void *(*xMalloc)(int); /* Memory allocation function */
  1439. void (*xFree)(void*); /* Free a prior allocation */
  1440. void *(*xRealloc)(void*,int); /* Resize an allocation */
  1441. int (*xSize)(void*); /* Return the size of an allocation */
  1442. int (*xRoundup)(int); /* Round up request size to allocation size */
  1443. int (*xInit)(void*); /* Initialize the memory allocator */
  1444. void (*xShutdown)(void*); /* Deinitialize the memory allocator */
  1445. void *pAppData; /* Argument to xInit() and xShutdown() */
  1446. };
  1447. /*
  1448. ** CAPI3REF: Configuration Options
  1449. ** KEYWORDS: {configuration option}
  1450. **
  1451. ** These constants are the available integer configuration options that
  1452. ** can be passed as the first argument to the [sqlite3_config()] interface.
  1453. **
  1454. ** New configuration options may be added in future releases of SQLite.
  1455. ** Existing configuration options might be discontinued. Applications
  1456. ** should check the return code from [sqlite3_config()] to make sure that
  1457. ** the call worked. The [sqlite3_config()] interface will return a
  1458. ** non-zero [error code] if a discontinued or unsupported configuration option
  1459. ** is invoked.
  1460. **
  1461. ** <dl>
  1462. ** [[SQLITE_CONFIG_SINGLETHREAD]] <dt>SQLITE_CONFIG_SINGLETHREAD</dt>
  1463. ** <dd>There are no arguments to this option. ^This option sets the
  1464. ** [threading mode] to Single-thread. In other words, it disables
  1465. ** all mutexing and puts SQLite into a mode where it can only be used
  1466. ** by a single thread. ^If SQLite is compiled with
  1467. ** the [SQLITE_THREADSAFE | SQLITE_THREADSAFE=0] compile-time option then
  1468. ** it is not possible to change the [threading mode] from its default
  1469. ** value of Single-thread and so [sqlite3_config()] will return
  1470. ** [SQLITE_ERROR] if called with the SQLITE_CONFIG_SINGLETHREAD
  1471. ** configuration option.</dd>
  1472. **
  1473. ** [[SQLITE_CONFIG_MULTITHREAD]] <dt>SQLITE_CONFIG_MULTITHREAD</dt>
  1474. ** <dd>There are no arguments to this option. ^This option sets the
  1475. ** [threading mode] to Multi-thread. In other words, it disables
  1476. ** mutexing on [database connection] and [prepared statement] objects.
  1477. ** The application is responsible for serializing access to
  1478. ** [database connections] and [prepared statements]. But other mutexes
  1479. ** are enabled so that SQLite will be safe to use in a multi-threaded
  1480. ** environment as long as no two threads attempt to use the same
  1481. ** [database connection] at the same time. ^If SQLite is compiled with
  1482. ** the [SQLITE_THREADSAFE | SQLITE_THREADSAFE=0] compile-time option then
  1483. ** it is not possible to set the Multi-thread [threading mode] and
  1484. ** [sqlite3_config()] will return [SQLITE_ERROR] if called with the
  1485. ** SQLITE_CONFIG_MULTITHREAD configuration option.</dd>
  1486. **
  1487. ** [[SQLITE_CONFIG_SERIALIZED]] <dt>SQLITE_CONFIG_SERIALIZED</dt>
  1488. ** <dd>There are no arguments to this option. ^This option sets the
  1489. ** [threading mode] to Serialized. In other words, this option enables
  1490. ** all mutexes including the recursive
  1491. ** mutexes on [database connection] and [prepared statement] objects.
  1492. ** In this mode (which is the default when SQLite is compiled with
  1493. ** [SQLITE_THREADSAFE=1]) the SQLite library will itself serialize access
  1494. ** to [database connections] and [prepared statements] so that the
  1495. ** application is free to use the same [database connection] or the
  1496. ** same [prepared statement] in different threads at the same time.
  1497. ** ^If SQLite is compiled with
  1498. ** the [SQLITE_THREADSAFE | SQLITE_THREADSAFE=0] compile-time option then
  1499. ** it is not possible to set the Serialized [threading mode] and
  1500. ** [sqlite3_config()] will return [SQLITE_ERROR] if called with the
  1501. ** SQLITE_CONFIG_SERIALIZED configuration option.</dd>
  1502. **
  1503. ** [[SQLITE_CONFIG_MALLOC]] <dt>SQLITE_CONFIG_MALLOC</dt>
  1504. ** <dd> ^(The SQLITE_CONFIG_MALLOC option takes a single argument which is
  1505. ** a pointer to an instance of the [sqlite3_mem_methods] structure.
  1506. ** The argument specifies
  1507. ** alternative low-level memory allocation routines to be used in place of
  1508. ** the memory allocation routines built into SQLite.)^ ^SQLite makes
  1509. ** its own private copy of the content of the [sqlite3_mem_methods] structure
  1510. ** before the [sqlite3_config()] call returns.</dd>
  1511. **
  1512. ** [[SQLITE_CONFIG_GETMALLOC]] <dt>SQLITE_CONFIG_GETMALLOC</dt>
  1513. ** <dd> ^(The SQLITE_CONFIG_GETMALLOC option takes a single argument which
  1514. ** is a pointer to an instance of the [sqlite3_mem_methods] structure.
  1515. ** The [sqlite3_mem_methods]
  1516. ** structure is filled with the currently defined memory allocation routines.)^
  1517. ** This option can be used to overload the default memory allocation
  1518. ** routines with a wrapper that simulations memory allocation failure or
  1519. ** tracks memory usage, for example. </dd>
  1520. **
  1521. ** [[SQLITE_CONFIG_MEMSTATUS]] <dt>SQLITE_CONFIG_MEMSTATUS</dt>
  1522. ** <dd> ^The SQLITE_CONFIG_MEMSTATUS option takes single argument of type int,
  1523. ** interpreted as a boolean, which enables or disables the collection of
  1524. ** memory allocation statistics. ^(When memory allocation statistics are
  1525. ** disabled, the following SQLite interfaces become non-operational:
  1526. ** <ul>
  1527. ** <li> [sqlite3_memory_used()]
  1528. ** <li> [sqlite3_memory_highwater()]
  1529. ** <li> [sqlite3_soft_heap_limit64()]
  1530. ** <li> [sqlite3_status64()]
  1531. ** </ul>)^
  1532. ** ^Memory allocation statistics are enabled by default unless SQLite is
  1533. ** compiled with [SQLITE_DEFAULT_MEMSTATUS]=0 in which case memory
  1534. ** allocation statistics are disabled by default.
  1535. ** </dd>
  1536. **
  1537. ** [[SQLITE_CONFIG_SCRATCH]] <dt>SQLITE_CONFIG_SCRATCH</dt>
  1538. ** <dd> ^The SQLITE_CONFIG_SCRATCH option specifies a static memory buffer
  1539. ** that SQLite can use for scratch memory. ^(There are three arguments
  1540. ** to SQLITE_CONFIG_SCRATCH: A pointer an 8-byte
  1541. ** aligned memory buffer from which the scratch allocations will be
  1542. ** drawn, the size of each scratch allocation (sz),
  1543. ** and the maximum number of scratch allocations (N).)^
  1544. ** The first argument must be a pointer to an 8-byte aligned buffer
  1545. ** of at least sz*N bytes of memory.
  1546. ** ^SQLite will not use more than one scratch buffers per thread.
  1547. ** ^SQLite will never request a scratch buffer that is more than 6
  1548. ** times the database page size.
  1549. ** ^If SQLite needs needs additional
  1550. ** scratch memory beyond what is provided by this configuration option, then
  1551. ** [sqlite3_malloc()] will be used to obtain the memory needed.<p>
  1552. ** ^When the application provides any amount of scratch memory using
  1553. ** SQLITE_CONFIG_SCRATCH, SQLite avoids unnecessary large
  1554. ** [sqlite3_malloc|heap allocations].
  1555. ** This can help [Robson proof|prevent memory allocation failures] due to heap
  1556. ** fragmentation in low-memory embedded systems.
  1557. ** </dd>
  1558. **
  1559. ** [[SQLITE_CONFIG_PAGECACHE]] <dt>SQLITE_CONFIG_PAGECACHE</dt>
  1560. ** <dd> ^The SQLITE_CONFIG_PAGECACHE option specifies a static memory buffer
  1561. ** that SQLite can use for the database page cache with the default page
  1562. ** cache implementation.
  1563. ** This configuration should not be used if an application-define page
  1564. ** cache implementation is loaded using the [SQLITE_CONFIG_PCACHE2]
  1565. ** configuration option.
  1566. ** ^There are three arguments to SQLITE_CONFIG_PAGECACHE: A pointer to
  1567. ** 8-byte aligned
  1568. ** memory, the size of each page buffer (sz), and the number of pages (N).
  1569. ** The sz argument should be the size of the largest database page
  1570. ** (a power of two between 512 and 65536) plus some extra bytes for each
  1571. ** page header. ^The number of extra bytes needed by the page header
  1572. ** can be determined using the [SQLITE_CONFIG_PCACHE_HDRSZ] option
  1573. ** to [sqlite3_config()].
  1574. ** ^It is harmless, apart from the wasted memory,
  1575. ** for the sz parameter to be larger than necessary. The first
  1576. ** argument should pointer to an 8-byte aligned block of memory that
  1577. ** is at least sz*N bytes of memory, otherwise subsequent behavior is
  1578. ** undefined.
  1579. ** ^SQLite will use the memory provided by the first argument to satisfy its
  1580. ** memory needs for the first N pages that it adds to cache. ^If additional
  1581. ** page cache memory is needed beyond what is provided by this option, then
  1582. ** SQLite goes to [sqlite3_malloc()] for the additional storage space.</dd>
  1583. **
  1584. ** [[SQLITE_CONFIG_HEAP]] <dt>SQLITE_CONFIG_HEAP</dt>
  1585. ** <dd> ^The SQLITE_CONFIG_HEAP option specifies a static memory buffer
  1586. ** that SQLite will use for all of its dynamic memory allocation needs
  1587. ** beyond those provided for by [SQLITE_CONFIG_SCRATCH] and
  1588. ** [SQLITE_CONFIG_PAGECACHE].
  1589. ** ^The SQLITE_CONFIG_HEAP option is only available if SQLite is compiled
  1590. ** with either [SQLITE_ENABLE_MEMSYS3] or [SQLITE_ENABLE_MEMSYS5] and returns
  1591. ** [SQLITE_ERROR] if invoked otherwise.
  1592. ** ^There are three arguments to SQLITE_CONFIG_HEAP:
  1593. ** An 8-byte aligned pointer to the memory,
  1594. ** the number of bytes in the memory buffer, and the minimum allocation size.
  1595. ** ^If the first pointer (the memory pointer) is NULL, then SQLite reverts
  1596. ** to using its default memory allocator (the system malloc() implementation),
  1597. ** undoing any prior invocation of [SQLITE_CONFIG_MALLOC]. ^If the
  1598. ** memory pointer is not NULL then the alternative memory
  1599. ** allocator is engaged to handle all of SQLites memory allocation needs.
  1600. ** The first pointer (the memory pointer) must be aligned to an 8-byte
  1601. ** boundary or subsequent behavior of SQLite will be undefined.
  1602. ** The minimum allocation size is capped at 2**12. Reasonable values
  1603. ** for the minimum allocation size are 2**5 through 2**8.</dd>
  1604. **
  1605. ** [[SQLITE_CONFIG_MUTEX]] <dt>SQLITE_CONFIG_MUTEX</dt>
  1606. ** <dd> ^(The SQLITE_CONFIG_MUTEX option takes a single argument which is a
  1607. ** pointer to an instance of the [sqlite3_mutex_methods] structure.
  1608. ** The argument specifies alternative low-level mutex routines to be used
  1609. ** in place the mutex routines built into SQLite.)^ ^SQLite makes a copy of
  1610. ** the content of the [sqlite3_mutex_methods] structure before the call to
  1611. ** [sqlite3_config()] returns. ^If SQLite is compiled with
  1612. ** the [SQLITE_THREADSAFE | SQLITE_THREADSAFE=0] compile-time option then
  1613. ** the entire mutexing subsystem is omitted from the build and hence calls to
  1614. ** [sqlite3_config()] with the SQLITE_CONFIG_MUTEX configuration option will
  1615. ** return [SQLITE_ERROR].</dd>
  1616. **
  1617. ** [[SQLITE_CONFIG_GETMUTEX]] <dt>SQLITE_CONFIG_GETMUTEX</dt>
  1618. ** <dd> ^(The SQLITE_CONFIG_GETMUTEX option takes a single argument which
  1619. ** is a pointer to an instance of the [sqlite3_mutex_methods] structure. The
  1620. ** [sqlite3_mutex_methods]
  1621. ** structure is filled with the currently defined mutex routines.)^
  1622. ** This option can be used to overload the default mutex allocation
  1623. ** routines with a wrapper used to track mutex usage for performance
  1624. ** profiling or testing, for example. ^If SQLite is compiled with
  1625. ** the [SQLITE_THREADSAFE | SQLITE_THREADSAFE=0] compile-time option then
  1626. ** the entire mutexing subsystem is omitted from the build and hence calls to
  1627. ** [sqlite3_config()] with the SQLITE_CONFIG_GETMUTEX configuration option will
  1628. ** return [SQLITE_ERROR].</dd>
  1629. **
  1630. ** [[SQLITE_CONFIG_LOOKASIDE]] <dt>SQLITE_CONFIG_LOOKASIDE</dt>
  1631. ** <dd> ^(The SQLITE_CONFIG_LOOKASIDE option takes two arguments that determine
  1632. ** the default size of lookaside memory on each [database connection].
  1633. ** The first argument is the
  1634. ** size of each lookaside buffer slot and the second is the number of
  1635. ** slots allocated to each database connection.)^ ^(SQLITE_CONFIG_LOOKASIDE
  1636. ** sets the <i>default</i> lookaside size. The [SQLITE_DBCONFIG_LOOKASIDE]
  1637. ** option to [sqlite3_db_config()] can be used to change the lookaside
  1638. ** configuration on individual connections.)^ </dd>
  1639. **
  1640. ** [[SQLITE_CONFIG_PCACHE2]] <dt>SQLITE_CONFIG_PCACHE2</dt>
  1641. ** <dd> ^(The SQLITE_CONFIG_PCACHE2 option takes a single argument which is
  1642. ** a pointer to an [sqlite3_pcache_methods2] object. This object specifies
  1643. ** the interface to a custom page cache implementation.)^
  1644. ** ^SQLite makes a copy of the [sqlite3_pcache_methods2] object.</dd>
  1645. **
  1646. ** [[SQLITE_CONFIG_GETPCACHE2]] <dt>SQLITE_CONFIG_GETPCACHE2</dt>
  1647. ** <dd> ^(The SQLITE_CONFIG_GETPCACHE2 option takes a single argument which
  1648. ** is a pointer to an [sqlite3_pcache_methods2] object. SQLite copies of
  1649. ** the current page cache implementation into that object.)^ </dd>
  1650. **
  1651. ** [[SQLITE_CONFIG_LOG]] <dt>SQLITE_CONFIG_LOG</dt>
  1652. ** <dd> The SQLITE_CONFIG_LOG option is used to configure the SQLite
  1653. ** global [error log].
  1654. ** (^The SQLITE_CONFIG_LOG option takes two arguments: a pointer to a
  1655. ** function with a call signature of void(*)(void*,int,const char*),
  1656. ** and a pointer to void. ^If the function pointer is not NULL, it is
  1657. ** invoked by [sqlite3_log()] to process each logging event. ^If the
  1658. ** function pointer is NULL, the [sqlite3_log()] interface becomes a no-op.
  1659. ** ^The void pointer that is the second argument to SQLITE_CONFIG_LOG is
  1660. ** passed through as the first parameter to the application-defined logger
  1661. ** function whenever that function is invoked. ^The second parameter to
  1662. ** the logger function is a copy of the first parameter to the corresponding
  1663. ** [sqlite3_log()] call and is intended to be a [result code] or an
  1664. ** [extended result code]. ^The third parameter passed to the logger is
  1665. ** log message after formatting via [sqlite3_snprintf()].
  1666. ** The SQLite logging interface is not reentrant; the logger function
  1667. ** supplied by the application must not invoke any SQLite interface.
  1668. ** In a multi-threaded application, the application-defined logger
  1669. ** function must be threadsafe. </dd>
  1670. **
  1671. ** [[SQLITE_CONFIG_URI]] <dt>SQLITE_CONFIG_URI
  1672. ** <dd>^(The SQLITE_CONFIG_URI option takes a single argument of type int.
  1673. ** If non-zero, then URI handling is globally enabled. If the parameter is zero,
  1674. ** then URI handling is globally disabled.)^ ^If URI handling is globally
  1675. ** enabled, all filenames passed to [sqlite3_open()], [sqlite3_open_v2()],
  1676. ** [sqlite3_open16()] or
  1677. ** specified as part of [ATTACH] commands are interpreted as URIs, regardless
  1678. ** of whether or not the [SQLITE_OPEN_URI] flag is set when the database
  1679. ** connection is opened. ^If it is globally disabled, filenames are
  1680. ** only interpreted as URIs if the SQLITE_OPEN_URI flag is set when the
  1681. ** database connection is opened. ^(By default, URI handling is globally
  1682. ** disabled. The default value may be changed by compiling with the
  1683. ** [SQLITE_USE_URI] symbol defined.)^
  1684. **
  1685. ** [[SQLITE_CONFIG_COVERING_INDEX_SCAN]] <dt>SQLITE_CONFIG_COVERING_INDEX_SCAN
  1686. ** <dd>^The SQLITE_CONFIG_COVERING_INDEX_SCAN option takes a single integer
  1687. ** argument which is interpreted as a boolean in order to enable or disable
  1688. ** the use of covering indices for full table scans in the query optimizer.
  1689. ** ^The default setting is determined
  1690. ** by the [SQLITE_ALLOW_COVERING_INDEX_SCAN] compile-time option, or is "on"
  1691. ** if that compile-time option is omitted.
  1692. ** The ability to disable the use of covering indices for full table scans
  1693. ** is because some incorrectly coded legacy applications might malfunction
  1694. ** when the optimization is enabled. Providing the ability to
  1695. ** disable the optimization allows the older, buggy application code to work
  1696. ** without change even with newer versions of SQLite.
  1697. **
  1698. ** [[SQLITE_CONFIG_PCACHE]] [[SQLITE_CONFIG_GETPCACHE]]
  1699. ** <dt>SQLITE_CONFIG_PCACHE and SQLITE_CONFIG_GETPCACHE
  1700. ** <dd> These options are obsolete and should not be used by new code.
  1701. ** They are retained for backwards compatibility but are now no-ops.
  1702. ** </dd>
  1703. **
  1704. ** [[SQLITE_CONFIG_SQLLOG]]
  1705. ** <dt>SQLITE_CONFIG_SQLLOG
  1706. ** <dd>This option is only available if sqlite is compiled with the
  1707. ** [SQLITE_ENABLE_SQLLOG] pre-processor macro defined. The first argument should
  1708. ** be a pointer to a function of type void(*)(void*,sqlite3*,const char*, int).
  1709. ** The second should be of type (void*). The callback is invoked by the library
  1710. ** in three separate circumstances, identified by the value passed as the
  1711. ** fourth parameter. If the fourth parameter is 0, then the database connection
  1712. ** passed as the second argument has just been opened. The third argument
  1713. ** points to a buffer containing the name of the main database file. If the
  1714. ** fourth parameter is 1, then the SQL statement that the third parameter
  1715. ** points to has just been executed. Or, if the fourth parameter is 2, then
  1716. ** the connection being passed as the second parameter is being closed. The
  1717. ** third parameter is passed NULL In this case. An example of using this
  1718. ** configuration option can be seen in the "test_sqllog.c" source file in
  1719. ** the canonical SQLite source tree.</dd>
  1720. **
  1721. ** [[SQLITE_CONFIG_MMAP_SIZE]]
  1722. ** <dt>SQLITE_CONFIG_MMAP_SIZE
  1723. ** <dd>^SQLITE_CONFIG_MMAP_SIZE takes two 64-bit integer (sqlite3_int64) values
  1724. ** that are the default mmap size limit (the default setting for
  1725. ** [PRAGMA mmap_size]) and the maximum allowed mmap size limit.
  1726. ** ^The default setting can be overridden by each database connection using
  1727. ** either the [PRAGMA mmap_size] command, or by using the
  1728. ** [SQLITE_FCNTL_MMAP_SIZE] file control. ^(The maximum allowed mmap size
  1729. ** will be silently truncated if necessary so that it does not exceed the
  1730. ** compile-time maximum mmap size set by the
  1731. ** [SQLITE_MAX_MMAP_SIZE] compile-time option.)^
  1732. ** ^If either argument to this option is negative, then that argument is
  1733. ** changed to its compile-time default.
  1734. **
  1735. ** [[SQLITE_CONFIG_WIN32_HEAPSIZE]]
  1736. ** <dt>SQLITE_CONFIG_WIN32_HEAPSIZE
  1737. ** <dd>^The SQLITE_CONFIG_WIN32_HEAPSIZE option is only available if SQLite is
  1738. ** compiled for Windows with the [SQLITE_WIN32_MALLOC] pre-processor macro
  1739. ** defined. ^SQLITE_CONFIG_WIN32_HEAPSIZE takes a 32-bit unsigned integer value
  1740. ** that specifies the maximum size of the created heap.
  1741. **
  1742. ** [[SQLITE_CONFIG_PCACHE_HDRSZ]]
  1743. ** <dt>SQLITE_CONFIG_PCACHE_HDRSZ
  1744. ** <dd>^The SQLITE_CONFIG_PCACHE_HDRSZ option takes a single parameter which
  1745. ** is a pointer to an integer and writes into that integer the number of extra
  1746. ** bytes per page required for each page in [SQLITE_CONFIG_PAGECACHE].
  1747. ** The amount of extra space required can change depending on the compiler,
  1748. ** target platform, and SQLite version.
  1749. **
  1750. ** [[SQLITE_CONFIG_PMASZ]]
  1751. ** <dt>SQLITE_CONFIG_PMASZ
  1752. ** <dd>^The SQLITE_CONFIG_PMASZ option takes a single parameter which
  1753. ** is an unsigned integer and sets the "Minimum PMA Size" for the multithreaded
  1754. ** sorter to that integer. The default minimum PMA Size is set by the
  1755. ** [SQLITE_SORTER_PMASZ] compile-time option. New threads are launched
  1756. ** to help with sort operations when multithreaded sorting
  1757. ** is enabled (using the [PRAGMA threads] command) and the amount of content
  1758. ** to be sorted exceeds the page size times the minimum of the
  1759. ** [PRAGMA cache_size] setting and this value.
  1760. ** </dl>
  1761. */
  1762. #define SQLITE_CONFIG_SINGLETHREAD 1 /* nil */
  1763. #define SQLITE_CONFIG_MULTITHREAD 2 /* nil */
  1764. #define SQLITE_CONFIG_SERIALIZED 3 /* nil */
  1765. #define SQLITE_CONFIG_MALLOC 4 /* sqlite3_mem_methods* */
  1766. #define SQLITE_CONFIG_GETMALLOC 5 /* sqlite3_mem_methods* */
  1767. #define SQLITE_CONFIG_SCRATCH 6 /* void*, int sz, int N */
  1768. #define SQLITE_CONFIG_PAGECACHE 7 /* void*, int sz, int N */
  1769. #define SQLITE_CONFIG_HEAP 8 /* void*, int nByte, int min */
  1770. #define SQLITE_CONFIG_MEMSTATUS 9 /* boolean */
  1771. #define SQLITE_CONFIG_MUTEX 10 /* sqlite3_mutex_methods* */
  1772. #define SQLITE_CONFIG_GETMUTEX 11 /* sqlite3_mutex_methods* */
  1773. /* previously SQLITE_CONFIG_CHUNKALLOC 12 which is now unused. */
  1774. #define SQLITE_CONFIG_LOOKASIDE 13 /* int int */
  1775. #define SQLITE_CONFIG_PCACHE 14 /* no-op */
  1776. #define SQLITE_CONFIG_GETPCACHE 15 /* no-op */
  1777. #define SQLITE_CONFIG_LOG 16 /* xFunc, void* */
  1778. #define SQLITE_CONFIG_URI 17 /* int */
  1779. #define SQLITE_CONFIG_PCACHE2 18 /* sqlite3_pcache_methods2* */
  1780. #define SQLITE_CONFIG_GETPCACHE2 19 /* sqlite3_pcache_methods2* */
  1781. #define SQLITE_CONFIG_COVERING_INDEX_SCAN 20 /* int */
  1782. #define SQLITE_CONFIG_SQLLOG 21 /* xSqllog, void* */
  1783. #define SQLITE_CONFIG_MMAP_SIZE 22 /* sqlite3_int64, sqlite3_int64 */
  1784. #define SQLITE_CONFIG_WIN32_HEAPSIZE 23 /* int nByte */
  1785. #define SQLITE_CONFIG_PCACHE_HDRSZ 24 /* int *psz */
  1786. #define SQLITE_CONFIG_PMASZ 25 /* unsigned int szPma */
  1787. /*
  1788. ** CAPI3REF: Database Connection Configuration Options
  1789. **
  1790. ** These constants are the available integer configuration options that
  1791. ** can be passed as the second argument to the [sqlite3_db_config()] interface.
  1792. **
  1793. ** New configuration options may be added in future releases of SQLite.
  1794. ** Existing configuration options might be discontinued. Applications
  1795. ** should check the return code from [sqlite3_db_config()] to make sure that
  1796. ** the call worked. ^The [sqlite3_db_config()] interface will return a
  1797. ** non-zero [error code] if a discontinued or unsupported configuration option
  1798. ** is invoked.
  1799. **
  1800. ** <dl>
  1801. ** <dt>SQLITE_DBCONFIG_LOOKASIDE</dt>
  1802. ** <dd> ^This option takes three additional arguments that determine the
  1803. ** [lookaside memory allocator] configuration for the [database connection].
  1804. ** ^The first argument (the third parameter to [sqlite3_db_config()] is a
  1805. ** pointer to a memory buffer to use for lookaside memory.
  1806. ** ^The first argument after the SQLITE_DBCONFIG_LOOKASIDE verb
  1807. ** may be NULL in which case SQLite will allocate the
  1808. ** lookaside buffer itself using [sqlite3_malloc()]. ^The second argument is the
  1809. ** size of each lookaside buffer slot. ^The third argument is the number of
  1810. ** slots. The size of the buffer in the first argument must be greater than
  1811. ** or equal to the product of the second and third arguments. The buffer
  1812. ** must be aligned to an 8-byte boundary. ^If the second argument to
  1813. ** SQLITE_DBCONFIG_LOOKASIDE is not a multiple of 8, it is internally
  1814. ** rounded down to the next smaller multiple of 8. ^(The lookaside memory
  1815. ** configuration for a database connection can only be changed when that
  1816. ** connection is not currently using lookaside memory, or in other words
  1817. ** when the "current value" returned by
  1818. ** [sqlite3_db_status](D,[SQLITE_CONFIG_LOOKASIDE],...) is zero.
  1819. ** Any attempt to change the lookaside memory configuration when lookaside
  1820. ** memory is in use leaves the configuration unchanged and returns
  1821. ** [SQLITE_BUSY].)^</dd>
  1822. **
  1823. ** <dt>SQLITE_DBCONFIG_ENABLE_FKEY</dt>
  1824. ** <dd> ^This option is used to enable or disable the enforcement of
  1825. ** [foreign key constraints]. There should be two additional arguments.
  1826. ** The first argument is an integer which is 0 to disable FK enforcement,
  1827. ** positive to enable FK enforcement or negative to leave FK enforcement
  1828. ** unchanged. The second parameter is a pointer to an integer into which
  1829. ** is written 0 or 1 to indicate whether FK enforcement is off or on
  1830. ** following this call. The second parameter may be a NULL pointer, in
  1831. ** which case the FK enforcement setting is not reported back. </dd>
  1832. **
  1833. ** <dt>SQLITE_DBCONFIG_ENABLE_TRIGGER</dt>
  1834. ** <dd> ^This option is used to enable or disable [CREATE TRIGGER | triggers].
  1835. ** There should be two additional arguments.
  1836. ** The first argument is an integer which is 0 to disable triggers,
  1837. ** positive to enable triggers or negative to leave the setting unchanged.
  1838. ** The second parameter is a pointer to an integer into which
  1839. ** is written 0 or 1 to indicate whether triggers are disabled or enabled
  1840. ** following this call. The second parameter may be a NULL pointer, in
  1841. ** which case the trigger setting is not reported back. </dd>
  1842. **
  1843. ** </dl>
  1844. */
  1845. #define SQLITE_DBCONFIG_LOOKASIDE 1001 /* void* int int */
  1846. #define SQLITE_DBCONFIG_ENABLE_FKEY 1002 /* int int* */
  1847. #define SQLITE_DBCONFIG_ENABLE_TRIGGER 1003 /* int int* */
  1848. /*
  1849. ** CAPI3REF: Enable Or Disable Extended Result Codes
  1850. ** METHOD: sqlite3
  1851. **
  1852. ** ^The sqlite3_extended_result_codes() routine enables or disables the
  1853. ** [extended result codes] feature of SQLite. ^The extended result
  1854. ** codes are disabled by default for historical compatibility.
  1855. */
  1856. SQLITE_API int SQLITE_STDCALL sqlite3_extended_result_codes(sqlite3*, int onoff);
  1857. /*
  1858. ** CAPI3REF: Last Insert Rowid
  1859. ** METHOD: sqlite3
  1860. **
  1861. ** ^Each entry in most SQLite tables (except for [WITHOUT ROWID] tables)
  1862. ** has a unique 64-bit signed
  1863. ** integer key called the [ROWID | "rowid"]. ^The rowid is always available
  1864. ** as an undeclared column named ROWID, OID, or _ROWID_ as long as those
  1865. ** names are not also used by explicitly declared columns. ^If
  1866. ** the table has a column of type [INTEGER PRIMARY KEY] then that column
  1867. ** is another alias for the rowid.
  1868. **
  1869. ** ^The sqlite3_last_insert_rowid(D) interface returns the [rowid] of the
  1870. ** most recent successful [INSERT] into a rowid table or [virtual table]
  1871. ** on database connection D.
  1872. ** ^Inserts into [WITHOUT ROWID] tables are not recorded.
  1873. ** ^If no successful [INSERT]s into rowid tables
  1874. ** have ever occurred on the database connection D,
  1875. ** then sqlite3_last_insert_rowid(D) returns zero.
  1876. **
  1877. ** ^(If an [INSERT] occurs within a trigger or within a [virtual table]
  1878. ** method, then this routine will return the [rowid] of the inserted
  1879. ** row as long as the trigger or virtual table method is running.
  1880. ** But once the trigger or virtual table method ends, the value returned
  1881. ** by this routine reverts to what it was before the trigger or virtual
  1882. ** table method began.)^
  1883. **
  1884. ** ^An [INSERT] that fails due to a constraint violation is not a
  1885. ** successful [INSERT] and does not change the value returned by this
  1886. ** routine. ^Thus INSERT OR FAIL, INSERT OR IGNORE, INSERT OR ROLLBACK,
  1887. ** and INSERT OR ABORT make no changes to the return value of this
  1888. ** routine when their insertion fails. ^(When INSERT OR REPLACE
  1889. ** encounters a constraint violation, it does not fail. The
  1890. ** INSERT continues to completion after deleting rows that caused
  1891. ** the constraint problem so INSERT OR REPLACE will always change
  1892. ** the return value of this interface.)^
  1893. **
  1894. ** ^For the purposes of this routine, an [INSERT] is considered to
  1895. ** be successful even if it is subsequently rolled back.
  1896. **
  1897. ** This function is accessible to SQL statements via the
  1898. ** [last_insert_rowid() SQL function].
  1899. **
  1900. ** If a separate thread performs a new [INSERT] on the same
  1901. ** database connection while the [sqlite3_last_insert_rowid()]
  1902. ** function is running and thus changes the last insert [rowid],
  1903. ** then the value returned by [sqlite3_last_insert_rowid()] is
  1904. ** unpredictable and might not equal either the old or the new
  1905. ** last insert [rowid].
  1906. */
  1907. SQLITE_API sqlite3_int64 SQLITE_STDCALL sqlite3_last_insert_rowid(sqlite3*);
  1908. /*
  1909. ** CAPI3REF: Count The Number Of Rows Modified
  1910. ** METHOD: sqlite3
  1911. **
  1912. ** ^This function returns the number of rows modified, inserted or
  1913. ** deleted by the most recently completed INSERT, UPDATE or DELETE
  1914. ** statement on the database connection specified by the only parameter.
  1915. ** ^Executing any other type of SQL statement does not modify the value
  1916. ** returned by this function.
  1917. **
  1918. ** ^Only changes made directly by the INSERT, UPDATE or DELETE statement are
  1919. ** considered - auxiliary changes caused by [CREATE TRIGGER | triggers],
  1920. ** [foreign key actions] or [REPLACE] constraint resolution are not counted.
  1921. **
  1922. ** Changes to a view that are intercepted by
  1923. ** [INSTEAD OF trigger | INSTEAD OF triggers] are not counted. ^The value
  1924. ** returned by sqlite3_changes() immediately after an INSERT, UPDATE or
  1925. ** DELETE statement run on a view is always zero. Only changes made to real
  1926. ** tables are counted.
  1927. **
  1928. ** Things are more complicated if the sqlite3_changes() function is
  1929. ** executed while a trigger program is running. This may happen if the
  1930. ** program uses the [changes() SQL function], or if some other callback
  1931. ** function invokes sqlite3_changes() directly. Essentially:
  1932. **
  1933. ** <ul>
  1934. ** <li> ^(Before entering a trigger program the value returned by
  1935. ** sqlite3_changes() function is saved. After the trigger program
  1936. ** has finished, the original value is restored.)^
  1937. **
  1938. ** <li> ^(Within a trigger program each INSERT, UPDATE and DELETE
  1939. ** statement sets the value returned by sqlite3_changes()
  1940. ** upon completion as normal. Of course, this value will not include
  1941. ** any changes performed by sub-triggers, as the sqlite3_changes()
  1942. ** value will be saved and restored after each sub-trigger has run.)^
  1943. ** </ul>
  1944. **
  1945. ** ^This means that if the changes() SQL function (or similar) is used
  1946. ** by the first INSERT, UPDATE or DELETE statement within a trigger, it
  1947. ** returns the value as set when the calling statement began executing.
  1948. ** ^If it is used by the second or subsequent such statement within a trigger
  1949. ** program, the value returned reflects the number of rows modified by the
  1950. ** previous INSERT, UPDATE or DELETE statement within the same trigger.
  1951. **
  1952. ** See also the [sqlite3_total_changes()] interface, the
  1953. ** [count_changes pragma], and the [changes() SQL function].
  1954. **
  1955. ** If a separate thread makes changes on the same database connection
  1956. ** while [sqlite3_changes()] is running then the value returned
  1957. ** is unpredictable and not meaningful.
  1958. */
  1959. SQLITE_API int SQLITE_STDCALL sqlite3_changes(sqlite3*);
  1960. /*
  1961. ** CAPI3REF: Total Number Of Rows Modified
  1962. ** METHOD: sqlite3
  1963. **
  1964. ** ^This function returns the total number of rows inserted, modified or
  1965. ** deleted by all [INSERT], [UPDATE] or [DELETE] statements completed
  1966. ** since the database connection was opened, including those executed as
  1967. ** part of trigger programs. ^Executing any other type of SQL statement
  1968. ** does not affect the value returned by sqlite3_total_changes().
  1969. **
  1970. ** ^Changes made as part of [foreign key actions] are included in the
  1971. ** count, but those made as part of REPLACE constraint resolution are
  1972. ** not. ^Changes to a view that are intercepted by INSTEAD OF triggers
  1973. ** are not counted.
  1974. **
  1975. ** See also the [sqlite3_changes()] interface, the
  1976. ** [count_changes pragma], and the [total_changes() SQL function].
  1977. **
  1978. ** If a separate thread makes changes on the same database connection
  1979. ** while [sqlite3_total_changes()] is running then the value
  1980. ** returned is unpredictable and not meaningful.
  1981. */
  1982. SQLITE_API int SQLITE_STDCALL sqlite3_total_changes(sqlite3*);
  1983. /*
  1984. ** CAPI3REF: Interrupt A Long-Running Query
  1985. ** METHOD: sqlite3
  1986. **
  1987. ** ^This function causes any pending database operation to abort and
  1988. ** return at its earliest opportunity. This routine is typically
  1989. ** called in response to a user action such as pressing "Cancel"
  1990. ** or Ctrl-C where the user wants a long query operation to halt
  1991. ** immediately.
  1992. **
  1993. ** ^It is safe to call this routine from a thread different from the
  1994. ** thread that is currently running the database operation. But it
  1995. ** is not safe to call this routine with a [database connection] that
  1996. ** is closed or might close before sqlite3_interrupt() returns.
  1997. **
  1998. ** ^If an SQL operation is very nearly finished at the time when
  1999. ** sqlite3_interrupt() is called, then it might not have an opportunity
  2000. ** to be interrupted and might continue to completion.
  2001. **
  2002. ** ^An SQL operation that is interrupted will return [SQLITE_INTERRUPT].
  2003. ** ^If the interrupted SQL operation is an INSERT, UPDATE, or DELETE
  2004. ** that is inside an explicit transaction, then the entire transaction
  2005. ** will be rolled back automatically.
  2006. **
  2007. ** ^The sqlite3_interrupt(D) call is in effect until all currently running
  2008. ** SQL statements on [database connection] D complete. ^Any new SQL statements
  2009. ** that are started after the sqlite3_interrupt() call and before the
  2010. ** running statements reaches zero are interrupted as if they had been
  2011. ** running prior to the sqlite3_interrupt() call. ^New SQL statements
  2012. ** that are started after the running statement count reaches zero are
  2013. ** not effected by the sqlite3_interrupt().
  2014. ** ^A call to sqlite3_interrupt(D) that occurs when there are no running
  2015. ** SQL statements is a no-op and has no effect on SQL statements
  2016. ** that are started after the sqlite3_interrupt() call returns.
  2017. **
  2018. ** If the database connection closes while [sqlite3_interrupt()]
  2019. ** is running then bad things will likely happen.
  2020. */
  2021. SQLITE_API void SQLITE_STDCALL sqlite3_interrupt(sqlite3*);
  2022. /*
  2023. ** CAPI3REF: Determine If An SQL Statement Is Complete
  2024. **
  2025. ** These routines are useful during command-line input to determine if the
  2026. ** currently entered text seems to form a complete SQL statement or
  2027. ** if additional input is needed before sending the text into
  2028. ** SQLite for parsing. ^These routines return 1 if the input string
  2029. ** appears to be a complete SQL statement. ^A statement is judged to be
  2030. ** complete if it ends with a semicolon token and is not a prefix of a
  2031. ** well-formed CREATE TRIGGER statement. ^Semicolons that are embedded within
  2032. ** string literals or quoted identifier names or comments are not
  2033. ** independent tokens (they are part of the token in which they are
  2034. ** embedded) and thus do not count as a statement terminator. ^Whitespace
  2035. ** and comments that follow the final semicolon are ignored.
  2036. **
  2037. ** ^These routines return 0 if the statement is incomplete. ^If a
  2038. ** memory allocation fails, then SQLITE_NOMEM is returned.
  2039. **
  2040. ** ^These routines do not parse the SQL statements thus
  2041. ** will not detect syntactically incorrect SQL.
  2042. **
  2043. ** ^(If SQLite has not been initialized using [sqlite3_initialize()] prior
  2044. ** to invoking sqlite3_complete16() then sqlite3_initialize() is invoked
  2045. ** automatically by sqlite3_complete16(). If that initialization fails,
  2046. ** then the return value from sqlite3_complete16() will be non-zero
  2047. ** regardless of whether or not the input SQL is complete.)^
  2048. **
  2049. ** The input to [sqlite3_complete()] must be a zero-terminated
  2050. ** UTF-8 string.
  2051. **
  2052. ** The input to [sqlite3_complete16()] must be a zero-terminated
  2053. ** UTF-16 string in native byte order.
  2054. */
  2055. SQLITE_API int SQLITE_STDCALL sqlite3_complete(const char *sql);
  2056. SQLITE_API int SQLITE_STDCALL sqlite3_complete16(const void *sql);
  2057. /*
  2058. ** CAPI3REF: Register A Callback To Handle SQLITE_BUSY Errors
  2059. ** KEYWORDS: {busy-handler callback} {busy handler}
  2060. ** METHOD: sqlite3
  2061. **
  2062. ** ^The sqlite3_busy_handler(D,X,P) routine sets a callback function X
  2063. ** that might be invoked with argument P whenever
  2064. ** an attempt is made to access a database table associated with
  2065. ** [database connection] D when another thread
  2066. ** or process has the table locked.
  2067. ** The sqlite3_busy_handler() interface is used to implement
  2068. ** [sqlite3_busy_timeout()] and [PRAGMA busy_timeout].
  2069. **
  2070. ** ^If the busy callback is NULL, then [SQLITE_BUSY]
  2071. ** is returned immediately upon encountering the lock. ^If the busy callback
  2072. ** is not NULL, then the callback might be invoked with two arguments.
  2073. **
  2074. ** ^The first argument to the busy handler is a copy of the void* pointer which
  2075. ** is the third argument to sqlite3_busy_handler(). ^The second argument to
  2076. ** the busy handler callback is the number of times that the busy handler has
  2077. ** been invoked previously for the same locking event. ^If the
  2078. ** busy callback returns 0, then no additional attempts are made to
  2079. ** access the database and [SQLITE_BUSY] is returned
  2080. ** to the application.
  2081. ** ^If the callback returns non-zero, then another attempt
  2082. ** is made to access the database and the cycle repeats.
  2083. **
  2084. ** The presence of a busy handler does not guarantee that it will be invoked
  2085. ** when there is lock contention. ^If SQLite determines that invoking the busy
  2086. ** handler could result in a deadlock, it will go ahead and return [SQLITE_BUSY]
  2087. ** to the application instead of invoking the
  2088. ** busy handler.
  2089. ** Consider a scenario where one process is holding a read lock that
  2090. ** it is trying to promote to a reserved lock and
  2091. ** a second process is holding a reserved lock that it is trying
  2092. ** to promote to an exclusive lock. The first process cannot proceed
  2093. ** because it is blocked by the second and the second process cannot
  2094. ** proceed because it is blocked by the first. If both processes
  2095. ** invoke the busy handlers, neither will make any progress. Therefore,
  2096. ** SQLite returns [SQLITE_BUSY] for the first process, hoping that this
  2097. ** will induce the first process to release its read lock and allow
  2098. ** the second process to proceed.
  2099. **
  2100. ** ^The default busy callback is NULL.
  2101. **
  2102. ** ^(There can only be a single busy handler defined for each
  2103. ** [database connection]. Setting a new busy handler clears any
  2104. ** previously set handler.)^ ^Note that calling [sqlite3_busy_timeout()]
  2105. ** or evaluating [PRAGMA busy_timeout=N] will change the
  2106. ** busy handler and thus clear any previously set busy handler.
  2107. **
  2108. ** The busy callback should not take any actions which modify the
  2109. ** database connection that invoked the busy handler. In other words,
  2110. ** the busy handler is not reentrant. Any such actions
  2111. ** result in undefined behavior.
  2112. **
  2113. ** A busy handler must not close the database connection
  2114. ** or [prepared statement] that invoked the busy handler.
  2115. */
  2116. SQLITE_API int SQLITE_STDCALL sqlite3_busy_handler(sqlite3*, int(*)(void*,int), void*);
  2117. /*
  2118. ** CAPI3REF: Set A Busy Timeout
  2119. ** METHOD: sqlite3
  2120. **
  2121. ** ^This routine sets a [sqlite3_busy_handler | busy handler] that sleeps
  2122. ** for a specified amount of time when a table is locked. ^The handler
  2123. ** will sleep multiple times until at least "ms" milliseconds of sleeping
  2124. ** have accumulated. ^After at least "ms" milliseconds of sleeping,
  2125. ** the handler returns 0 which causes [sqlite3_step()] to return
  2126. ** [SQLITE_BUSY].
  2127. **
  2128. ** ^Calling this routine with an argument less than or equal to zero
  2129. ** turns off all busy handlers.
  2130. **
  2131. ** ^(There can only be a single busy handler for a particular
  2132. ** [database connection] at any given moment. If another busy handler
  2133. ** was defined (using [sqlite3_busy_handler()]) prior to calling
  2134. ** this routine, that other busy handler is cleared.)^
  2135. **
  2136. ** See also: [PRAGMA busy_timeout]
  2137. */
  2138. SQLITE_API int SQLITE_STDCALL sqlite3_busy_timeout(sqlite3*, int ms);
  2139. /*
  2140. ** CAPI3REF: Convenience Routines For Running Queries
  2141. ** METHOD: sqlite3
  2142. **
  2143. ** This is a legacy interface that is preserved for backwards compatibility.
  2144. ** Use of this interface is not recommended.
  2145. **
  2146. ** Definition: A <b>result table</b> is memory data structure created by the
  2147. ** [sqlite3_get_table()] interface. A result table records the
  2148. ** complete query results from one or more queries.
  2149. **
  2150. ** The table conceptually has a number of rows and columns. But
  2151. ** these numbers are not part of the result table itself. These
  2152. ** numbers are obtained separately. Let N be the number of rows
  2153. ** and M be the number of columns.
  2154. **
  2155. ** A result table is an array of pointers to zero-terminated UTF-8 strings.
  2156. ** There are (N+1)*M elements in the array. The first M pointers point
  2157. ** to zero-terminated strings that contain the names of the columns.
  2158. ** The remaining entries all point to query results. NULL values result
  2159. ** in NULL pointers. All other values are in their UTF-8 zero-terminated
  2160. ** string representation as returned by [sqlite3_column_text()].
  2161. **
  2162. ** A result table might consist of one or more memory allocations.
  2163. ** It is not safe to pass a result table directly to [sqlite3_free()].
  2164. ** A result table should be deallocated using [sqlite3_free_table()].
  2165. **
  2166. ** ^(As an example of the result table format, suppose a query result
  2167. ** is as follows:
  2168. **
  2169. ** <blockquote><pre>
  2170. ** Name | Age
  2171. ** -----------------------
  2172. ** Alice | 43
  2173. ** Bob | 28
  2174. ** Cindy | 21
  2175. ** </pre></blockquote>
  2176. **
  2177. ** There are two column (M==2) and three rows (N==3). Thus the
  2178. ** result table has 8 entries. Suppose the result table is stored
  2179. ** in an array names azResult. Then azResult holds this content:
  2180. **
  2181. ** <blockquote><pre>
  2182. ** azResult&#91;0] = "Name";
  2183. ** azResult&#91;1] = "Age";
  2184. ** azResult&#91;2] = "Alice";
  2185. ** azResult&#91;3] = "43";
  2186. ** azResult&#91;4] = "Bob";
  2187. ** azResult&#91;5] = "28";
  2188. ** azResult&#91;6] = "Cindy";
  2189. ** azResult&#91;7] = "21";
  2190. ** </pre></blockquote>)^
  2191. **
  2192. ** ^The sqlite3_get_table() function evaluates one or more
  2193. ** semicolon-separated SQL statements in the zero-terminated UTF-8
  2194. ** string of its 2nd parameter and returns a result table to the
  2195. ** pointer given in its 3rd parameter.
  2196. **
  2197. ** After the application has finished with the result from sqlite3_get_table(),
  2198. ** it must pass the result table pointer to sqlite3_free_table() in order to
  2199. ** release the memory that was malloced. Because of the way the
  2200. ** [sqlite3_malloc()] happens within sqlite3_get_table(), the calling
  2201. ** function must not try to call [sqlite3_free()] directly. Only
  2202. ** [sqlite3_free_table()] is able to release the memory properly and safely.
  2203. **
  2204. ** The sqlite3_get_table() interface is implemented as a wrapper around
  2205. ** [sqlite3_exec()]. The sqlite3_get_table() routine does not have access
  2206. ** to any internal data structures of SQLite. It uses only the public
  2207. ** interface defined here. As a consequence, errors that occur in the
  2208. ** wrapper layer outside of the internal [sqlite3_exec()] call are not
  2209. ** reflected in subsequent calls to [sqlite3_errcode()] or
  2210. ** [sqlite3_errmsg()].
  2211. */
  2212. SQLITE_API int SQLITE_STDCALL sqlite3_get_table(
  2213. sqlite3 *db, /* An open database */
  2214. const char *zSql, /* SQL to be evaluated */
  2215. char ***pazResult, /* Results of the query */
  2216. int *pnRow, /* Number of result rows written here */
  2217. int *pnColumn, /* Number of result columns written here */
  2218. char **pzErrmsg /* Error msg written here */
  2219. );
  2220. SQLITE_API void SQLITE_STDCALL sqlite3_free_table(char **result);
  2221. /*
  2222. ** CAPI3REF: Formatted String Printing Functions
  2223. **
  2224. ** These routines are work-alikes of the "printf()" family of functions
  2225. ** from the standard C library.
  2226. ** These routines understand most of the common K&R formatting options,
  2227. ** plus some additional non-standard formats, detailed below.
  2228. ** Note that some of the more obscure formatting options from recent
  2229. ** C-library standards are omitted from this implementation.
  2230. **
  2231. ** ^The sqlite3_mprintf() and sqlite3_vmprintf() routines write their
  2232. ** results into memory obtained from [sqlite3_malloc()].
  2233. ** The strings returned by these two routines should be
  2234. ** released by [sqlite3_free()]. ^Both routines return a
  2235. ** NULL pointer if [sqlite3_malloc()] is unable to allocate enough
  2236. ** memory to hold the resulting string.
  2237. **
  2238. ** ^(The sqlite3_snprintf() routine is similar to "snprintf()" from
  2239. ** the standard C library. The result is written into the
  2240. ** buffer supplied as the second parameter whose size is given by
  2241. ** the first parameter. Note that the order of the
  2242. ** first two parameters is reversed from snprintf().)^ This is an
  2243. ** historical accident that cannot be fixed without breaking
  2244. ** backwards compatibility. ^(Note also that sqlite3_snprintf()
  2245. ** returns a pointer to its buffer instead of the number of
  2246. ** characters actually written into the buffer.)^ We admit that
  2247. ** the number of characters written would be a more useful return
  2248. ** value but we cannot change the implementation of sqlite3_snprintf()
  2249. ** now without breaking compatibility.
  2250. **
  2251. ** ^As long as the buffer size is greater than zero, sqlite3_snprintf()
  2252. ** guarantees that the buffer is always zero-terminated. ^The first
  2253. ** parameter "n" is the total size of the buffer, including space for
  2254. ** the zero terminator. So the longest string that can be completely
  2255. ** written will be n-1 characters.
  2256. **
  2257. ** ^The sqlite3_vsnprintf() routine is a varargs version of sqlite3_snprintf().
  2258. **
  2259. ** These routines all implement some additional formatting
  2260. ** options that are useful for constructing SQL statements.
  2261. ** All of the usual printf() formatting options apply. In addition, there
  2262. ** is are "%q", "%Q", "%w" and "%z" options.
  2263. **
  2264. ** ^(The %q option works like %s in that it substitutes a nul-terminated
  2265. ** string from the argument list. But %q also doubles every '\'' character.
  2266. ** %q is designed for use inside a string literal.)^ By doubling each '\''
  2267. ** character it escapes that character and allows it to be inserted into
  2268. ** the string.
  2269. **
  2270. ** For example, assume the string variable zText contains text as follows:
  2271. **
  2272. ** <blockquote><pre>
  2273. ** char *zText = "It's a happy day!";
  2274. ** </pre></blockquote>
  2275. **
  2276. ** One can use this text in an SQL statement as follows:
  2277. **
  2278. ** <blockquote><pre>
  2279. ** char *zSQL = sqlite3_mprintf("INSERT INTO table VALUES('%q')", zText);
  2280. ** sqlite3_exec(db, zSQL, 0, 0, 0);
  2281. ** sqlite3_free(zSQL);
  2282. ** </pre></blockquote>
  2283. **
  2284. ** Because the %q format string is used, the '\'' character in zText
  2285. ** is escaped and the SQL generated is as follows:
  2286. **
  2287. ** <blockquote><pre>
  2288. ** INSERT INTO table1 VALUES('It''s a happy day!')
  2289. ** </pre></blockquote>
  2290. **
  2291. ** This is correct. Had we used %s instead of %q, the generated SQL
  2292. ** would have looked like this:
  2293. **
  2294. ** <blockquote><pre>
  2295. ** INSERT INTO table1 VALUES('It's a happy day!');
  2296. ** </pre></blockquote>
  2297. **
  2298. ** This second example is an SQL syntax error. As a general rule you should
  2299. ** always use %q instead of %s when inserting text into a string literal.
  2300. **
  2301. ** ^(The %Q option works like %q except it also adds single quotes around
  2302. ** the outside of the total string. Additionally, if the parameter in the
  2303. ** argument list is a NULL pointer, %Q substitutes the text "NULL" (without
  2304. ** single quotes).)^ So, for example, one could say:
  2305. **
  2306. ** <blockquote><pre>
  2307. ** char *zSQL = sqlite3_mprintf("INSERT INTO table VALUES(%Q)", zText);
  2308. ** sqlite3_exec(db, zSQL, 0, 0, 0);
  2309. ** sqlite3_free(zSQL);
  2310. ** </pre></blockquote>
  2311. **
  2312. ** The code above will render a correct SQL statement in the zSQL
  2313. ** variable even if the zText variable is a NULL pointer.
  2314. **
  2315. ** ^(The "%w" formatting option is like "%q" except that it expects to
  2316. ** be contained within double-quotes instead of single quotes, and it
  2317. ** escapes the double-quote character instead of the single-quote
  2318. ** character.)^ The "%w" formatting option is intended for safely inserting
  2319. ** table and column names into a constructed SQL statement.
  2320. **
  2321. ** ^(The "%z" formatting option works like "%s" but with the
  2322. ** addition that after the string has been read and copied into
  2323. ** the result, [sqlite3_free()] is called on the input string.)^
  2324. */
  2325. SQLITE_API char *SQLITE_CDECL sqlite3_mprintf(const char*,...);
  2326. SQLITE_API char *SQLITE_STDCALL sqlite3_vmprintf(const char*, va_list);
  2327. SQLITE_API char *SQLITE_CDECL sqlite3_snprintf(int,char*,const char*, ...);
  2328. SQLITE_API char *SQLITE_STDCALL sqlite3_vsnprintf(int,char*,const char*, va_list);
  2329. /*
  2330. ** CAPI3REF: Memory Allocation Subsystem
  2331. **
  2332. ** The SQLite core uses these three routines for all of its own
  2333. ** internal memory allocation needs. "Core" in the previous sentence
  2334. ** does not include operating-system specific VFS implementation. The
  2335. ** Windows VFS uses native malloc() and free() for some operations.
  2336. **
  2337. ** ^The sqlite3_malloc() routine returns a pointer to a block
  2338. ** of memory at least N bytes in length, where N is the parameter.
  2339. ** ^If sqlite3_malloc() is unable to obtain sufficient free
  2340. ** memory, it returns a NULL pointer. ^If the parameter N to
  2341. ** sqlite3_malloc() is zero or negative then sqlite3_malloc() returns
  2342. ** a NULL pointer.
  2343. **
  2344. ** ^The sqlite3_malloc64(N) routine works just like
  2345. ** sqlite3_malloc(N) except that N is an unsigned 64-bit integer instead
  2346. ** of a signed 32-bit integer.
  2347. **
  2348. ** ^Calling sqlite3_free() with a pointer previously returned
  2349. ** by sqlite3_malloc() or sqlite3_realloc() releases that memory so
  2350. ** that it might be reused. ^The sqlite3_free() routine is
  2351. ** a no-op if is called with a NULL pointer. Passing a NULL pointer
  2352. ** to sqlite3_free() is harmless. After being freed, memory
  2353. ** should neither be read nor written. Even reading previously freed
  2354. ** memory might result in a segmentation fault or other severe error.
  2355. ** Memory corruption, a segmentation fault, or other severe error
  2356. ** might result if sqlite3_free() is called with a non-NULL pointer that
  2357. ** was not obtained from sqlite3_malloc() or sqlite3_realloc().
  2358. **
  2359. ** ^The sqlite3_realloc(X,N) interface attempts to resize a
  2360. ** prior memory allocation X to be at least N bytes.
  2361. ** ^If the X parameter to sqlite3_realloc(X,N)
  2362. ** is a NULL pointer then its behavior is identical to calling
  2363. ** sqlite3_malloc(N).
  2364. ** ^If the N parameter to sqlite3_realloc(X,N) is zero or
  2365. ** negative then the behavior is exactly the same as calling
  2366. ** sqlite3_free(X).
  2367. ** ^sqlite3_realloc(X,N) returns a pointer to a memory allocation
  2368. ** of at least N bytes in size or NULL if insufficient memory is available.
  2369. ** ^If M is the size of the prior allocation, then min(N,M) bytes
  2370. ** of the prior allocation are copied into the beginning of buffer returned
  2371. ** by sqlite3_realloc(X,N) and the prior allocation is freed.
  2372. ** ^If sqlite3_realloc(X,N) returns NULL and N is positive, then the
  2373. ** prior allocation is not freed.
  2374. **
  2375. ** ^The sqlite3_realloc64(X,N) interfaces works the same as
  2376. ** sqlite3_realloc(X,N) except that N is a 64-bit unsigned integer instead
  2377. ** of a 32-bit signed integer.
  2378. **
  2379. ** ^If X is a memory allocation previously obtained from sqlite3_malloc(),
  2380. ** sqlite3_malloc64(), sqlite3_realloc(), or sqlite3_realloc64(), then
  2381. ** sqlite3_msize(X) returns the size of that memory allocation in bytes.
  2382. ** ^The value returned by sqlite3_msize(X) might be larger than the number
  2383. ** of bytes requested when X was allocated. ^If X is a NULL pointer then
  2384. ** sqlite3_msize(X) returns zero. If X points to something that is not
  2385. ** the beginning of memory allocation, or if it points to a formerly
  2386. ** valid memory allocation that has now been freed, then the behavior
  2387. ** of sqlite3_msize(X) is undefined and possibly harmful.
  2388. **
  2389. ** ^The memory returned by sqlite3_malloc(), sqlite3_realloc(),
  2390. ** sqlite3_malloc64(), and sqlite3_realloc64()
  2391. ** is always aligned to at least an 8 byte boundary, or to a
  2392. ** 4 byte boundary if the [SQLITE_4_BYTE_ALIGNED_MALLOC] compile-time
  2393. ** option is used.
  2394. **
  2395. ** In SQLite version 3.5.0 and 3.5.1, it was possible to define
  2396. ** the SQLITE_OMIT_MEMORY_ALLOCATION which would cause the built-in
  2397. ** implementation of these routines to be omitted. That capability
  2398. ** is no longer provided. Only built-in memory allocators can be used.
  2399. **
  2400. ** Prior to SQLite version 3.7.10, the Windows OS interface layer called
  2401. ** the system malloc() and free() directly when converting
  2402. ** filenames between the UTF-8 encoding used by SQLite
  2403. ** and whatever filename encoding is used by the particular Windows
  2404. ** installation. Memory allocation errors were detected, but
  2405. ** they were reported back as [SQLITE_CANTOPEN] or
  2406. ** [SQLITE_IOERR] rather than [SQLITE_NOMEM].
  2407. **
  2408. ** The pointer arguments to [sqlite3_free()] and [sqlite3_realloc()]
  2409. ** must be either NULL or else pointers obtained from a prior
  2410. ** invocation of [sqlite3_malloc()] or [sqlite3_realloc()] that have
  2411. ** not yet been released.
  2412. **
  2413. ** The application must not read or write any part of
  2414. ** a block of memory after it has been released using
  2415. ** [sqlite3_free()] or [sqlite3_realloc()].
  2416. */
  2417. SQLITE_API void *SQLITE_STDCALL sqlite3_malloc(int);
  2418. SQLITE_API void *SQLITE_STDCALL sqlite3_malloc64(sqlite3_uint64);
  2419. SQLITE_API void *SQLITE_STDCALL sqlite3_realloc(void*, int);
  2420. SQLITE_API void *SQLITE_STDCALL sqlite3_realloc64(void*, sqlite3_uint64);
  2421. SQLITE_API void SQLITE_STDCALL sqlite3_free(void*);
  2422. SQLITE_API sqlite3_uint64 SQLITE_STDCALL sqlite3_msize(void*);
  2423. /*
  2424. ** CAPI3REF: Memory Allocator Statistics
  2425. **
  2426. ** SQLite provides these two interfaces for reporting on the status
  2427. ** of the [sqlite3_malloc()], [sqlite3_free()], and [sqlite3_realloc()]
  2428. ** routines, which form the built-in memory allocation subsystem.
  2429. **
  2430. ** ^The [sqlite3_memory_used()] routine returns the number of bytes
  2431. ** of memory currently outstanding (malloced but not freed).
  2432. ** ^The [sqlite3_memory_highwater()] routine returns the maximum
  2433. ** value of [sqlite3_memory_used()] since the high-water mark
  2434. ** was last reset. ^The values returned by [sqlite3_memory_used()] and
  2435. ** [sqlite3_memory_highwater()] include any overhead
  2436. ** added by SQLite in its implementation of [sqlite3_malloc()],
  2437. ** but not overhead added by the any underlying system library
  2438. ** routines that [sqlite3_malloc()] may call.
  2439. **
  2440. ** ^The memory high-water mark is reset to the current value of
  2441. ** [sqlite3_memory_used()] if and only if the parameter to
  2442. ** [sqlite3_memory_highwater()] is true. ^The value returned
  2443. ** by [sqlite3_memory_highwater(1)] is the high-water mark
  2444. ** prior to the reset.
  2445. */
  2446. SQLITE_API sqlite3_int64 SQLITE_STDCALL sqlite3_memory_used(void);
  2447. SQLITE_API sqlite3_int64 SQLITE_STDCALL sqlite3_memory_highwater(int resetFlag);
  2448. /*
  2449. ** CAPI3REF: Pseudo-Random Number Generator
  2450. **
  2451. ** SQLite contains a high-quality pseudo-random number generator (PRNG) used to
  2452. ** select random [ROWID | ROWIDs] when inserting new records into a table that
  2453. ** already uses the largest possible [ROWID]. The PRNG is also used for
  2454. ** the build-in random() and randomblob() SQL functions. This interface allows
  2455. ** applications to access the same PRNG for other purposes.
  2456. **
  2457. ** ^A call to this routine stores N bytes of randomness into buffer P.
  2458. ** ^The P parameter can be a NULL pointer.
  2459. **
  2460. ** ^If this routine has not been previously called or if the previous
  2461. ** call had N less than one or a NULL pointer for P, then the PRNG is
  2462. ** seeded using randomness obtained from the xRandomness method of
  2463. ** the default [sqlite3_vfs] object.
  2464. ** ^If the previous call to this routine had an N of 1 or more and a
  2465. ** non-NULL P then the pseudo-randomness is generated
  2466. ** internally and without recourse to the [sqlite3_vfs] xRandomness
  2467. ** method.
  2468. */
  2469. SQLITE_API void SQLITE_STDCALL sqlite3_randomness(int N, void *P);
  2470. /*
  2471. ** CAPI3REF: Compile-Time Authorization Callbacks
  2472. ** METHOD: sqlite3
  2473. **
  2474. ** ^This routine registers an authorizer callback with a particular
  2475. ** [database connection], supplied in the first argument.
  2476. ** ^The authorizer callback is invoked as SQL statements are being compiled
  2477. ** by [sqlite3_prepare()] or its variants [sqlite3_prepare_v2()],
  2478. ** [sqlite3_prepare16()] and [sqlite3_prepare16_v2()]. ^At various
  2479. ** points during the compilation process, as logic is being created
  2480. ** to perform various actions, the authorizer callback is invoked to
  2481. ** see if those actions are allowed. ^The authorizer callback should
  2482. ** return [SQLITE_OK] to allow the action, [SQLITE_IGNORE] to disallow the
  2483. ** specific action but allow the SQL statement to continue to be
  2484. ** compiled, or [SQLITE_DENY] to cause the entire SQL statement to be
  2485. ** rejected with an error. ^If the authorizer callback returns
  2486. ** any value other than [SQLITE_IGNORE], [SQLITE_OK], or [SQLITE_DENY]
  2487. ** then the [sqlite3_prepare_v2()] or equivalent call that triggered
  2488. ** the authorizer will fail with an error message.
  2489. **
  2490. ** When the callback returns [SQLITE_OK], that means the operation
  2491. ** requested is ok. ^When the callback returns [SQLITE_DENY], the
  2492. ** [sqlite3_prepare_v2()] or equivalent call that triggered the
  2493. ** authorizer will fail with an error message explaining that
  2494. ** access is denied.
  2495. **
  2496. ** ^The first parameter to the authorizer callback is a copy of the third
  2497. ** parameter to the sqlite3_set_authorizer() interface. ^The second parameter
  2498. ** to the callback is an integer [SQLITE_COPY | action code] that specifies
  2499. ** the particular action to be authorized. ^The third through sixth parameters
  2500. ** to the callback are zero-terminated strings that contain additional
  2501. ** details about the action to be authorized.
  2502. **
  2503. ** ^If the action code is [SQLITE_READ]
  2504. ** and the callback returns [SQLITE_IGNORE] then the
  2505. ** [prepared statement] statement is constructed to substitute
  2506. ** a NULL value in place of the table column that would have
  2507. ** been read if [SQLITE_OK] had been returned. The [SQLITE_IGNORE]
  2508. ** return can be used to deny an untrusted user access to individual
  2509. ** columns of a table.
  2510. ** ^If the action code is [SQLITE_DELETE] and the callback returns
  2511. ** [SQLITE_IGNORE] then the [DELETE] operation proceeds but the
  2512. ** [truncate optimization] is disabled and all rows are deleted individually.
  2513. **
  2514. ** An authorizer is used when [sqlite3_prepare | preparing]
  2515. ** SQL statements from an untrusted source, to ensure that the SQL statements
  2516. ** do not try to access data they are not allowed to see, or that they do not
  2517. ** try to execute malicious statements that damage the database. For
  2518. ** example, an application may allow a user to enter arbitrary
  2519. ** SQL queries for evaluation by a database. But the application does
  2520. ** not want the user to be able to make arbitrary changes to the
  2521. ** database. An authorizer could then be put in place while the
  2522. ** user-entered SQL is being [sqlite3_prepare | prepared] that
  2523. ** disallows everything except [SELECT] statements.
  2524. **
  2525. ** Applications that need to process SQL from untrusted sources
  2526. ** might also consider lowering resource limits using [sqlite3_limit()]
  2527. ** and limiting database size using the [max_page_count] [PRAGMA]
  2528. ** in addition to using an authorizer.
  2529. **
  2530. ** ^(Only a single authorizer can be in place on a database connection
  2531. ** at a time. Each call to sqlite3_set_authorizer overrides the
  2532. ** previous call.)^ ^Disable the authorizer by installing a NULL callback.
  2533. ** The authorizer is disabled by default.
  2534. **
  2535. ** The authorizer callback must not do anything that will modify
  2536. ** the database connection that invoked the authorizer callback.
  2537. ** Note that [sqlite3_prepare_v2()] and [sqlite3_step()] both modify their
  2538. ** database connections for the meaning of "modify" in this paragraph.
  2539. **
  2540. ** ^When [sqlite3_prepare_v2()] is used to prepare a statement, the
  2541. ** statement might be re-prepared during [sqlite3_step()] due to a
  2542. ** schema change. Hence, the application should ensure that the
  2543. ** correct authorizer callback remains in place during the [sqlite3_step()].
  2544. **
  2545. ** ^Note that the authorizer callback is invoked only during
  2546. ** [sqlite3_prepare()] or its variants. Authorization is not
  2547. ** performed during statement evaluation in [sqlite3_step()], unless
  2548. ** as stated in the previous paragraph, sqlite3_step() invokes
  2549. ** sqlite3_prepare_v2() to reprepare a statement after a schema change.
  2550. */
  2551. SQLITE_API int SQLITE_STDCALL sqlite3_set_authorizer(
  2552. sqlite3*,
  2553. int (*xAuth)(void*,int,const char*,const char*,const char*,const char*),
  2554. void *pUserData
  2555. );
  2556. /*
  2557. ** CAPI3REF: Authorizer Return Codes
  2558. **
  2559. ** The [sqlite3_set_authorizer | authorizer callback function] must
  2560. ** return either [SQLITE_OK] or one of these two constants in order
  2561. ** to signal SQLite whether or not the action is permitted. See the
  2562. ** [sqlite3_set_authorizer | authorizer documentation] for additional
  2563. ** information.
  2564. **
  2565. ** Note that SQLITE_IGNORE is also used as a [conflict resolution mode]
  2566. ** returned from the [sqlite3_vtab_on_conflict()] interface.
  2567. */
  2568. #define SQLITE_DENY 1 /* Abort the SQL statement with an error */
  2569. #define SQLITE_IGNORE 2 /* Don't allow access, but don't generate an error */
  2570. /*
  2571. ** CAPI3REF: Authorizer Action Codes
  2572. **
  2573. ** The [sqlite3_set_authorizer()] interface registers a callback function
  2574. ** that is invoked to authorize certain SQL statement actions. The
  2575. ** second parameter to the callback is an integer code that specifies
  2576. ** what action is being authorized. These are the integer action codes that
  2577. ** the authorizer callback may be passed.
  2578. **
  2579. ** These action code values signify what kind of operation is to be
  2580. ** authorized. The 3rd and 4th parameters to the authorization
  2581. ** callback function will be parameters or NULL depending on which of these
  2582. ** codes is used as the second parameter. ^(The 5th parameter to the
  2583. ** authorizer callback is the name of the database ("main", "temp",
  2584. ** etc.) if applicable.)^ ^The 6th parameter to the authorizer callback
  2585. ** is the name of the inner-most trigger or view that is responsible for
  2586. ** the access attempt or NULL if this access attempt is directly from
  2587. ** top-level SQL code.
  2588. */
  2589. /******************************************* 3rd ************ 4th ***********/
  2590. #define SQLITE_CREATE_INDEX 1 /* Index Name Table Name */
  2591. #define SQLITE_CREATE_TABLE 2 /* Table Name NULL */
  2592. #define SQLITE_CREATE_TEMP_INDEX 3 /* Index Name Table Name */
  2593. #define SQLITE_CREATE_TEMP_TABLE 4 /* Table Name NULL */
  2594. #define SQLITE_CREATE_TEMP_TRIGGER 5 /* Trigger Name Table Name */
  2595. #define SQLITE_CREATE_TEMP_VIEW 6 /* View Name NULL */
  2596. #define SQLITE_CREATE_TRIGGER 7 /* Trigger Name Table Name */
  2597. #define SQLITE_CREATE_VIEW 8 /* View Name NULL */
  2598. #define SQLITE_DELETE 9 /* Table Name NULL */
  2599. #define SQLITE_DROP_INDEX 10 /* Index Name Table Name */
  2600. #define SQLITE_DROP_TABLE 11 /* Table Name NULL */
  2601. #define SQLITE_DROP_TEMP_INDEX 12 /* Index Name Table Name */
  2602. #define SQLITE_DROP_TEMP_TABLE 13 /* Table Name NULL */
  2603. #define SQLITE_DROP_TEMP_TRIGGER 14 /* Trigger Name Table Name */
  2604. #define SQLITE_DROP_TEMP_VIEW 15 /* View Name NULL */
  2605. #define SQLITE_DROP_TRIGGER 16 /* Trigger Name Table Name */
  2606. #define SQLITE_DROP_VIEW 17 /* View Name NULL */
  2607. #define SQLITE_INSERT 18 /* Table Name NULL */
  2608. #define SQLITE_PRAGMA 19 /* Pragma Name 1st arg or NULL */
  2609. #define SQLITE_READ 20 /* Table Name Column Name */
  2610. #define SQLITE_SELECT 21 /* NULL NULL */
  2611. #define SQLITE_TRANSACTION 22 /* Operation NULL */
  2612. #define SQLITE_UPDATE 23 /* Table Name Column Name */
  2613. #define SQLITE_ATTACH 24 /* Filename NULL */
  2614. #define SQLITE_DETACH 25 /* Database Name NULL */
  2615. #define SQLITE_ALTER_TABLE 26 /* Database Name Table Name */
  2616. #define SQLITE_REINDEX 27 /* Index Name NULL */
  2617. #define SQLITE_ANALYZE 28 /* Table Name NULL */
  2618. #define SQLITE_CREATE_VTABLE 29 /* Table Name Module Name */
  2619. #define SQLITE_DROP_VTABLE 30 /* Table Name Module Name */
  2620. #define SQLITE_FUNCTION 31 /* NULL Function Name */
  2621. #define SQLITE_SAVEPOINT 32 /* Operation Savepoint Name */
  2622. #define SQLITE_COPY 0 /* No longer used */
  2623. #define SQLITE_RECURSIVE 33 /* NULL NULL */
  2624. /*
  2625. ** CAPI3REF: Tracing And Profiling Functions
  2626. ** METHOD: sqlite3
  2627. **
  2628. ** These routines register callback functions that can be used for
  2629. ** tracing and profiling the execution of SQL statements.
  2630. **
  2631. ** ^The callback function registered by sqlite3_trace() is invoked at
  2632. ** various times when an SQL statement is being run by [sqlite3_step()].
  2633. ** ^The sqlite3_trace() callback is invoked with a UTF-8 rendering of the
  2634. ** SQL statement text as the statement first begins executing.
  2635. ** ^(Additional sqlite3_trace() callbacks might occur
  2636. ** as each triggered subprogram is entered. The callbacks for triggers
  2637. ** contain a UTF-8 SQL comment that identifies the trigger.)^
  2638. **
  2639. ** The [SQLITE_TRACE_SIZE_LIMIT] compile-time option can be used to limit
  2640. ** the length of [bound parameter] expansion in the output of sqlite3_trace().
  2641. **
  2642. ** ^The callback function registered by sqlite3_profile() is invoked
  2643. ** as each SQL statement finishes. ^The profile callback contains
  2644. ** the original statement text and an estimate of wall-clock time
  2645. ** of how long that statement took to run. ^The profile callback
  2646. ** time is in units of nanoseconds, however the current implementation
  2647. ** is only capable of millisecond resolution so the six least significant
  2648. ** digits in the time are meaningless. Future versions of SQLite
  2649. ** might provide greater resolution on the profiler callback. The
  2650. ** sqlite3_profile() function is considered experimental and is
  2651. ** subject to change in future versions of SQLite.
  2652. */
  2653. SQLITE_API void *SQLITE_STDCALL sqlite3_trace(sqlite3*, void(*xTrace)(void*,const char*), void*);
  2654. SQLITE_API SQLITE_EXPERIMENTAL void *SQLITE_STDCALL sqlite3_profile(sqlite3*,
  2655. void(*xProfile)(void*,const char*,sqlite3_uint64), void*);
  2656. /*
  2657. ** CAPI3REF: Query Progress Callbacks
  2658. ** METHOD: sqlite3
  2659. **
  2660. ** ^The sqlite3_progress_handler(D,N,X,P) interface causes the callback
  2661. ** function X to be invoked periodically during long running calls to
  2662. ** [sqlite3_exec()], [sqlite3_step()] and [sqlite3_get_table()] for
  2663. ** database connection D. An example use for this
  2664. ** interface is to keep a GUI updated during a large query.
  2665. **
  2666. ** ^The parameter P is passed through as the only parameter to the
  2667. ** callback function X. ^The parameter N is the approximate number of
  2668. ** [virtual machine instructions] that are evaluated between successive
  2669. ** invocations of the callback X. ^If N is less than one then the progress
  2670. ** handler is disabled.
  2671. **
  2672. ** ^Only a single progress handler may be defined at one time per
  2673. ** [database connection]; setting a new progress handler cancels the
  2674. ** old one. ^Setting parameter X to NULL disables the progress handler.
  2675. ** ^The progress handler is also disabled by setting N to a value less
  2676. ** than 1.
  2677. **
  2678. ** ^If the progress callback returns non-zero, the operation is
  2679. ** interrupted. This feature can be used to implement a
  2680. ** "Cancel" button on a GUI progress dialog box.
  2681. **
  2682. ** The progress handler callback must not do anything that will modify
  2683. ** the database connection that invoked the progress handler.
  2684. ** Note that [sqlite3_prepare_v2()] and [sqlite3_step()] both modify their
  2685. ** database connections for the meaning of "modify" in this paragraph.
  2686. **
  2687. */
  2688. SQLITE_API void SQLITE_STDCALL sqlite3_progress_handler(sqlite3*, int, int(*)(void*), void*);
  2689. /*
  2690. ** CAPI3REF: Opening A New Database Connection
  2691. ** CONSTRUCTOR: sqlite3
  2692. **
  2693. ** ^These routines open an SQLite database file as specified by the
  2694. ** filename argument. ^The filename argument is interpreted as UTF-8 for
  2695. ** sqlite3_open() and sqlite3_open_v2() and as UTF-16 in the native byte
  2696. ** order for sqlite3_open16(). ^(A [database connection] handle is usually
  2697. ** returned in *ppDb, even if an error occurs. The only exception is that
  2698. ** if SQLite is unable to allocate memory to hold the [sqlite3] object,
  2699. ** a NULL will be written into *ppDb instead of a pointer to the [sqlite3]
  2700. ** object.)^ ^(If the database is opened (and/or created) successfully, then
  2701. ** [SQLITE_OK] is returned. Otherwise an [error code] is returned.)^ ^The
  2702. ** [sqlite3_errmsg()] or [sqlite3_errmsg16()] routines can be used to obtain
  2703. ** an English language description of the error following a failure of any
  2704. ** of the sqlite3_open() routines.
  2705. **
  2706. ** ^The default encoding will be UTF-8 for databases created using
  2707. ** sqlite3_open() or sqlite3_open_v2(). ^The default encoding for databases
  2708. ** created using sqlite3_open16() will be UTF-16 in the native byte order.
  2709. **
  2710. ** Whether or not an error occurs when it is opened, resources
  2711. ** associated with the [database connection] handle should be released by
  2712. ** passing it to [sqlite3_close()] when it is no longer required.
  2713. **
  2714. ** The sqlite3_open_v2() interface works like sqlite3_open()
  2715. ** except that it accepts two additional parameters for additional control
  2716. ** over the new database connection. ^(The flags parameter to
  2717. ** sqlite3_open_v2() can take one of
  2718. ** the following three values, optionally combined with the
  2719. ** [SQLITE_OPEN_NOMUTEX], [SQLITE_OPEN_FULLMUTEX], [SQLITE_OPEN_SHAREDCACHE],
  2720. ** [SQLITE_OPEN_PRIVATECACHE], and/or [SQLITE_OPEN_URI] flags:)^
  2721. **
  2722. ** <dl>
  2723. ** ^(<dt>[SQLITE_OPEN_READONLY]</dt>
  2724. ** <dd>The database is opened in read-only mode. If the database does not
  2725. ** already exist, an error is returned.</dd>)^
  2726. **
  2727. ** ^(<dt>[SQLITE_OPEN_READWRITE]</dt>
  2728. ** <dd>The database is opened for reading and writing if possible, or reading
  2729. ** only if the file is write protected by the operating system. In either
  2730. ** case the database must already exist, otherwise an error is returned.</dd>)^
  2731. **
  2732. ** ^(<dt>[SQLITE_OPEN_READWRITE] | [SQLITE_OPEN_CREATE]</dt>
  2733. ** <dd>The database is opened for reading and writing, and is created if
  2734. ** it does not already exist. This is the behavior that is always used for
  2735. ** sqlite3_open() and sqlite3_open16().</dd>)^
  2736. ** </dl>
  2737. **
  2738. ** If the 3rd parameter to sqlite3_open_v2() is not one of the
  2739. ** combinations shown above optionally combined with other
  2740. ** [SQLITE_OPEN_READONLY | SQLITE_OPEN_* bits]
  2741. ** then the behavior is undefined.
  2742. **
  2743. ** ^If the [SQLITE_OPEN_NOMUTEX] flag is set, then the database connection
  2744. ** opens in the multi-thread [threading mode] as long as the single-thread
  2745. ** mode has not been set at compile-time or start-time. ^If the
  2746. ** [SQLITE_OPEN_FULLMUTEX] flag is set then the database connection opens
  2747. ** in the serialized [threading mode] unless single-thread was
  2748. ** previously selected at compile-time or start-time.
  2749. ** ^The [SQLITE_OPEN_SHAREDCACHE] flag causes the database connection to be
  2750. ** eligible to use [shared cache mode], regardless of whether or not shared
  2751. ** cache is enabled using [sqlite3_enable_shared_cache()]. ^The
  2752. ** [SQLITE_OPEN_PRIVATECACHE] flag causes the database connection to not
  2753. ** participate in [shared cache mode] even if it is enabled.
  2754. **
  2755. ** ^The fourth parameter to sqlite3_open_v2() is the name of the
  2756. ** [sqlite3_vfs] object that defines the operating system interface that
  2757. ** the new database connection should use. ^If the fourth parameter is
  2758. ** a NULL pointer then the default [sqlite3_vfs] object is used.
  2759. **
  2760. ** ^If the filename is ":memory:", then a private, temporary in-memory database
  2761. ** is created for the connection. ^This in-memory database will vanish when
  2762. ** the database connection is closed. Future versions of SQLite might
  2763. ** make use of additional special filenames that begin with the ":" character.
  2764. ** It is recommended that when a database filename actually does begin with
  2765. ** a ":" character you should prefix the filename with a pathname such as
  2766. ** "./" to avoid ambiguity.
  2767. **
  2768. ** ^If the filename is an empty string, then a private, temporary
  2769. ** on-disk database will be created. ^This private database will be
  2770. ** automatically deleted as soon as the database connection is closed.
  2771. **
  2772. ** [[URI filenames in sqlite3_open()]] <h3>URI Filenames</h3>
  2773. **
  2774. ** ^If [URI filename] interpretation is enabled, and the filename argument
  2775. ** begins with "file:", then the filename is interpreted as a URI. ^URI
  2776. ** filename interpretation is enabled if the [SQLITE_OPEN_URI] flag is
  2777. ** set in the fourth argument to sqlite3_open_v2(), or if it has
  2778. ** been enabled globally using the [SQLITE_CONFIG_URI] option with the
  2779. ** [sqlite3_config()] method or by the [SQLITE_USE_URI] compile-time option.
  2780. ** As of SQLite version 3.7.7, URI filename interpretation is turned off
  2781. ** by default, but future releases of SQLite might enable URI filename
  2782. ** interpretation by default. See "[URI filenames]" for additional
  2783. ** information.
  2784. **
  2785. ** URI filenames are parsed according to RFC 3986. ^If the URI contains an
  2786. ** authority, then it must be either an empty string or the string
  2787. ** "localhost". ^If the authority is not an empty string or "localhost", an
  2788. ** error is returned to the caller. ^The fragment component of a URI, if
  2789. ** present, is ignored.
  2790. **
  2791. ** ^SQLite uses the path component of the URI as the name of the disk file
  2792. ** which contains the database. ^If the path begins with a '/' character,
  2793. ** then it is interpreted as an absolute path. ^If the path does not begin
  2794. ** with a '/' (meaning that the authority section is omitted from the URI)
  2795. ** then the path is interpreted as a relative path.
  2796. ** ^(On windows, the first component of an absolute path
  2797. ** is a drive specification (e.g. "C:").)^
  2798. **
  2799. ** [[core URI query parameters]]
  2800. ** The query component of a URI may contain parameters that are interpreted
  2801. ** either by SQLite itself, or by a [VFS | custom VFS implementation].
  2802. ** SQLite and its built-in [VFSes] interpret the
  2803. ** following query parameters:
  2804. **
  2805. ** <ul>
  2806. ** <li> <b>vfs</b>: ^The "vfs" parameter may be used to specify the name of
  2807. ** a VFS object that provides the operating system interface that should
  2808. ** be used to access the database file on disk. ^If this option is set to
  2809. ** an empty string the default VFS object is used. ^Specifying an unknown
  2810. ** VFS is an error. ^If sqlite3_open_v2() is used and the vfs option is
  2811. ** present, then the VFS specified by the option takes precedence over
  2812. ** the value passed as the fourth parameter to sqlite3_open_v2().
  2813. **
  2814. ** <li> <b>mode</b>: ^(The mode parameter may be set to either "ro", "rw",
  2815. ** "rwc", or "memory". Attempting to set it to any other value is
  2816. ** an error)^.
  2817. ** ^If "ro" is specified, then the database is opened for read-only
  2818. ** access, just as if the [SQLITE_OPEN_READONLY] flag had been set in the
  2819. ** third argument to sqlite3_open_v2(). ^If the mode option is set to
  2820. ** "rw", then the database is opened for read-write (but not create)
  2821. ** access, as if SQLITE_OPEN_READWRITE (but not SQLITE_OPEN_CREATE) had
  2822. ** been set. ^Value "rwc" is equivalent to setting both
  2823. ** SQLITE_OPEN_READWRITE and SQLITE_OPEN_CREATE. ^If the mode option is
  2824. ** set to "memory" then a pure [in-memory database] that never reads
  2825. ** or writes from disk is used. ^It is an error to specify a value for
  2826. ** the mode parameter that is less restrictive than that specified by
  2827. ** the flags passed in the third parameter to sqlite3_open_v2().
  2828. **
  2829. ** <li> <b>cache</b>: ^The cache parameter may be set to either "shared" or
  2830. ** "private". ^Setting it to "shared" is equivalent to setting the
  2831. ** SQLITE_OPEN_SHAREDCACHE bit in the flags argument passed to
  2832. ** sqlite3_open_v2(). ^Setting the cache parameter to "private" is
  2833. ** equivalent to setting the SQLITE_OPEN_PRIVATECACHE bit.
  2834. ** ^If sqlite3_open_v2() is used and the "cache" parameter is present in
  2835. ** a URI filename, its value overrides any behavior requested by setting
  2836. ** SQLITE_OPEN_PRIVATECACHE or SQLITE_OPEN_SHAREDCACHE flag.
  2837. **
  2838. ** <li> <b>psow</b>: ^The psow parameter indicates whether or not the
  2839. ** [powersafe overwrite] property does or does not apply to the
  2840. ** storage media on which the database file resides.
  2841. **
  2842. ** <li> <b>nolock</b>: ^The nolock parameter is a boolean query parameter
  2843. ** which if set disables file locking in rollback journal modes. This
  2844. ** is useful for accessing a database on a filesystem that does not
  2845. ** support locking. Caution: Database corruption might result if two
  2846. ** or more processes write to the same database and any one of those
  2847. ** processes uses nolock=1.
  2848. **
  2849. ** <li> <b>immutable</b>: ^The immutable parameter is a boolean query
  2850. ** parameter that indicates that the database file is stored on
  2851. ** read-only media. ^When immutable is set, SQLite assumes that the
  2852. ** database file cannot be changed, even by a process with higher
  2853. ** privilege, and so the database is opened read-only and all locking
  2854. ** and change detection is disabled. Caution: Setting the immutable
  2855. ** property on a database file that does in fact change can result
  2856. ** in incorrect query results and/or [SQLITE_CORRUPT] errors.
  2857. ** See also: [SQLITE_IOCAP_IMMUTABLE].
  2858. **
  2859. ** </ul>
  2860. **
  2861. ** ^Specifying an unknown parameter in the query component of a URI is not an
  2862. ** error. Future versions of SQLite might understand additional query
  2863. ** parameters. See "[query parameters with special meaning to SQLite]" for
  2864. ** additional information.
  2865. **
  2866. ** [[URI filename examples]] <h3>URI filename examples</h3>
  2867. **
  2868. ** <table border="1" align=center cellpadding=5>
  2869. ** <tr><th> URI filenames <th> Results
  2870. ** <tr><td> file:data.db <td>
  2871. ** Open the file "data.db" in the current directory.
  2872. ** <tr><td> file:/home/fred/data.db<br>
  2873. ** file:///home/fred/data.db <br>
  2874. ** file://localhost/home/fred/data.db <br> <td>
  2875. ** Open the database file "/home/fred/data.db".
  2876. ** <tr><td> file://darkstar/home/fred/data.db <td>
  2877. ** An error. "darkstar" is not a recognized authority.
  2878. ** <tr><td style="white-space:nowrap">
  2879. ** file:///C:/Documents%20and%20Settings/fred/Desktop/data.db
  2880. ** <td> Windows only: Open the file "data.db" on fred's desktop on drive
  2881. ** C:. Note that the %20 escaping in this example is not strictly
  2882. ** necessary - space characters can be used literally
  2883. ** in URI filenames.
  2884. ** <tr><td> file:data.db?mode=ro&cache=private <td>
  2885. ** Open file "data.db" in the current directory for read-only access.
  2886. ** Regardless of whether or not shared-cache mode is enabled by
  2887. ** default, use a private cache.
  2888. ** <tr><td> file:/home/fred/data.db?vfs=unix-dotfile <td>
  2889. ** Open file "/home/fred/data.db". Use the special VFS "unix-dotfile"
  2890. ** that uses dot-files in place of posix advisory locking.
  2891. ** <tr><td> file:data.db?mode=readonly <td>
  2892. ** An error. "readonly" is not a valid option for the "mode" parameter.
  2893. ** </table>
  2894. **
  2895. ** ^URI hexadecimal escape sequences (%HH) are supported within the path and
  2896. ** query components of a URI. A hexadecimal escape sequence consists of a
  2897. ** percent sign - "%" - followed by exactly two hexadecimal digits
  2898. ** specifying an octet value. ^Before the path or query components of a
  2899. ** URI filename are interpreted, they are encoded using UTF-8 and all
  2900. ** hexadecimal escape sequences replaced by a single byte containing the
  2901. ** corresponding octet. If this process generates an invalid UTF-8 encoding,
  2902. ** the results are undefined.
  2903. **
  2904. ** <b>Note to Windows users:</b> The encoding used for the filename argument
  2905. ** of sqlite3_open() and sqlite3_open_v2() must be UTF-8, not whatever
  2906. ** codepage is currently defined. Filenames containing international
  2907. ** characters must be converted to UTF-8 prior to passing them into
  2908. ** sqlite3_open() or sqlite3_open_v2().
  2909. **
  2910. ** <b>Note to Windows Runtime users:</b> The temporary directory must be set
  2911. ** prior to calling sqlite3_open() or sqlite3_open_v2(). Otherwise, various
  2912. ** features that require the use of temporary files may fail.
  2913. **
  2914. ** See also: [sqlite3_temp_directory]
  2915. */
  2916. SQLITE_API int SQLITE_STDCALL sqlite3_open(
  2917. const char *filename, /* Database filename (UTF-8) */
  2918. sqlite3 **ppDb /* OUT: SQLite db handle */
  2919. );
  2920. SQLITE_API int SQLITE_STDCALL sqlite3_open16(
  2921. const void *filename, /* Database filename (UTF-16) */
  2922. sqlite3 **ppDb /* OUT: SQLite db handle */
  2923. );
  2924. SQLITE_API int SQLITE_STDCALL sqlite3_open_v2(
  2925. const char *filename, /* Database filename (UTF-8) */
  2926. sqlite3 **ppDb, /* OUT: SQLite db handle */
  2927. int flags, /* Flags */
  2928. const char *zVfs /* Name of VFS module to use */
  2929. );
  2930. /*
  2931. ** CAPI3REF: Obtain Values For URI Parameters
  2932. **
  2933. ** These are utility routines, useful to VFS implementations, that check
  2934. ** to see if a database file was a URI that contained a specific query
  2935. ** parameter, and if so obtains the value of that query parameter.
  2936. **
  2937. ** If F is the database filename pointer passed into the xOpen() method of
  2938. ** a VFS implementation when the flags parameter to xOpen() has one or
  2939. ** more of the [SQLITE_OPEN_URI] or [SQLITE_OPEN_MAIN_DB] bits set and
  2940. ** P is the name of the query parameter, then
  2941. ** sqlite3_uri_parameter(F,P) returns the value of the P
  2942. ** parameter if it exists or a NULL pointer if P does not appear as a
  2943. ** query parameter on F. If P is a query parameter of F
  2944. ** has no explicit value, then sqlite3_uri_parameter(F,P) returns
  2945. ** a pointer to an empty string.
  2946. **
  2947. ** The sqlite3_uri_boolean(F,P,B) routine assumes that P is a boolean
  2948. ** parameter and returns true (1) or false (0) according to the value
  2949. ** of P. The sqlite3_uri_boolean(F,P,B) routine returns true (1) if the
  2950. ** value of query parameter P is one of "yes", "true", or "on" in any
  2951. ** case or if the value begins with a non-zero number. The
  2952. ** sqlite3_uri_boolean(F,P,B) routines returns false (0) if the value of
  2953. ** query parameter P is one of "no", "false", or "off" in any case or
  2954. ** if the value begins with a numeric zero. If P is not a query
  2955. ** parameter on F or if the value of P is does not match any of the
  2956. ** above, then sqlite3_uri_boolean(F,P,B) returns (B!=0).
  2957. **
  2958. ** The sqlite3_uri_int64(F,P,D) routine converts the value of P into a
  2959. ** 64-bit signed integer and returns that integer, or D if P does not
  2960. ** exist. If the value of P is something other than an integer, then
  2961. ** zero is returned.
  2962. **
  2963. ** If F is a NULL pointer, then sqlite3_uri_parameter(F,P) returns NULL and
  2964. ** sqlite3_uri_boolean(F,P,B) returns B. If F is not a NULL pointer and
  2965. ** is not a database file pathname pointer that SQLite passed into the xOpen
  2966. ** VFS method, then the behavior of this routine is undefined and probably
  2967. ** undesirable.
  2968. */
  2969. SQLITE_API const char *SQLITE_STDCALL sqlite3_uri_parameter(const char *zFilename, const char *zParam);
  2970. SQLITE_API int SQLITE_STDCALL sqlite3_uri_boolean(const char *zFile, const char *zParam, int bDefault);
  2971. SQLITE_API sqlite3_int64 SQLITE_STDCALL sqlite3_uri_int64(const char*, const char*, sqlite3_int64);
  2972. /*
  2973. ** CAPI3REF: Error Codes And Messages
  2974. ** METHOD: sqlite3
  2975. **
  2976. ** ^If the most recent sqlite3_* API call associated with
  2977. ** [database connection] D failed, then the sqlite3_errcode(D) interface
  2978. ** returns the numeric [result code] or [extended result code] for that
  2979. ** API call.
  2980. ** If the most recent API call was successful,
  2981. ** then the return value from sqlite3_errcode() is undefined.
  2982. ** ^The sqlite3_extended_errcode()
  2983. ** interface is the same except that it always returns the
  2984. ** [extended result code] even when extended result codes are
  2985. ** disabled.
  2986. **
  2987. ** ^The sqlite3_errmsg() and sqlite3_errmsg16() return English-language
  2988. ** text that describes the error, as either UTF-8 or UTF-16 respectively.
  2989. ** ^(Memory to hold the error message string is managed internally.
  2990. ** The application does not need to worry about freeing the result.
  2991. ** However, the error string might be overwritten or deallocated by
  2992. ** subsequent calls to other SQLite interface functions.)^
  2993. **
  2994. ** ^The sqlite3_errstr() interface returns the English-language text
  2995. ** that describes the [result code], as UTF-8.
  2996. ** ^(Memory to hold the error message string is managed internally
  2997. ** and must not be freed by the application)^.
  2998. **
  2999. ** When the serialized [threading mode] is in use, it might be the
  3000. ** case that a second error occurs on a separate thread in between
  3001. ** the time of the first error and the call to these interfaces.
  3002. ** When that happens, the second error will be reported since these
  3003. ** interfaces always report the most recent result. To avoid
  3004. ** this, each thread can obtain exclusive use of the [database connection] D
  3005. ** by invoking [sqlite3_mutex_enter]([sqlite3_db_mutex](D)) before beginning
  3006. ** to use D and invoking [sqlite3_mutex_leave]([sqlite3_db_mutex](D)) after
  3007. ** all calls to the interfaces listed here are completed.
  3008. **
  3009. ** If an interface fails with SQLITE_MISUSE, that means the interface
  3010. ** was invoked incorrectly by the application. In that case, the
  3011. ** error code and message may or may not be set.
  3012. */
  3013. SQLITE_API int SQLITE_STDCALL sqlite3_errcode(sqlite3 *db);
  3014. SQLITE_API int SQLITE_STDCALL sqlite3_extended_errcode(sqlite3 *db);
  3015. SQLITE_API const char *SQLITE_STDCALL sqlite3_errmsg(sqlite3*);
  3016. SQLITE_API const void *SQLITE_STDCALL sqlite3_errmsg16(sqlite3*);
  3017. SQLITE_API const char *SQLITE_STDCALL sqlite3_errstr(int);
  3018. /*
  3019. ** CAPI3REF: Prepared Statement Object
  3020. ** KEYWORDS: {prepared statement} {prepared statements}
  3021. **
  3022. ** An instance of this object represents a single SQL statement that
  3023. ** has been compiled into binary form and is ready to be evaluated.
  3024. **
  3025. ** Think of each SQL statement as a separate computer program. The
  3026. ** original SQL text is source code. A prepared statement object
  3027. ** is the compiled object code. All SQL must be converted into a
  3028. ** prepared statement before it can be run.
  3029. **
  3030. ** The life-cycle of a prepared statement object usually goes like this:
  3031. **
  3032. ** <ol>
  3033. ** <li> Create the prepared statement object using [sqlite3_prepare_v2()].
  3034. ** <li> Bind values to [parameters] using the sqlite3_bind_*()
  3035. ** interfaces.
  3036. ** <li> Run the SQL by calling [sqlite3_step()] one or more times.
  3037. ** <li> Reset the prepared statement using [sqlite3_reset()] then go back
  3038. ** to step 2. Do this zero or more times.
  3039. ** <li> Destroy the object using [sqlite3_finalize()].
  3040. ** </ol>
  3041. */
  3042. typedef struct sqlite3_stmt sqlite3_stmt;
  3043. /*
  3044. ** CAPI3REF: Run-time Limits
  3045. ** METHOD: sqlite3
  3046. **
  3047. ** ^(This interface allows the size of various constructs to be limited
  3048. ** on a connection by connection basis. The first parameter is the
  3049. ** [database connection] whose limit is to be set or queried. The
  3050. ** second parameter is one of the [limit categories] that define a
  3051. ** class of constructs to be size limited. The third parameter is the
  3052. ** new limit for that construct.)^
  3053. **
  3054. ** ^If the new limit is a negative number, the limit is unchanged.
  3055. ** ^(For each limit category SQLITE_LIMIT_<i>NAME</i> there is a
  3056. ** [limits | hard upper bound]
  3057. ** set at compile-time by a C preprocessor macro called
  3058. ** [limits | SQLITE_MAX_<i>NAME</i>].
  3059. ** (The "_LIMIT_" in the name is changed to "_MAX_".))^
  3060. ** ^Attempts to increase a limit above its hard upper bound are
  3061. ** silently truncated to the hard upper bound.
  3062. **
  3063. ** ^Regardless of whether or not the limit was changed, the
  3064. ** [sqlite3_limit()] interface returns the prior value of the limit.
  3065. ** ^Hence, to find the current value of a limit without changing it,
  3066. ** simply invoke this interface with the third parameter set to -1.
  3067. **
  3068. ** Run-time limits are intended for use in applications that manage
  3069. ** both their own internal database and also databases that are controlled
  3070. ** by untrusted external sources. An example application might be a
  3071. ** web browser that has its own databases for storing history and
  3072. ** separate databases controlled by JavaScript applications downloaded
  3073. ** off the Internet. The internal databases can be given the
  3074. ** large, default limits. Databases managed by external sources can
  3075. ** be given much smaller limits designed to prevent a denial of service
  3076. ** attack. Developers might also want to use the [sqlite3_set_authorizer()]
  3077. ** interface to further control untrusted SQL. The size of the database
  3078. ** created by an untrusted script can be contained using the
  3079. ** [max_page_count] [PRAGMA].
  3080. **
  3081. ** New run-time limit categories may be added in future releases.
  3082. */
  3083. SQLITE_API int SQLITE_STDCALL sqlite3_limit(sqlite3*, int id, int newVal);
  3084. /*
  3085. ** CAPI3REF: Run-Time Limit Categories
  3086. ** KEYWORDS: {limit category} {*limit categories}
  3087. **
  3088. ** These constants define various performance limits
  3089. ** that can be lowered at run-time using [sqlite3_limit()].
  3090. ** The synopsis of the meanings of the various limits is shown below.
  3091. ** Additional information is available at [limits | Limits in SQLite].
  3092. **
  3093. ** <dl>
  3094. ** [[SQLITE_LIMIT_LENGTH]] ^(<dt>SQLITE_LIMIT_LENGTH</dt>
  3095. ** <dd>The maximum size of any string or BLOB or table row, in bytes.<dd>)^
  3096. **
  3097. ** [[SQLITE_LIMIT_SQL_LENGTH]] ^(<dt>SQLITE_LIMIT_SQL_LENGTH</dt>
  3098. ** <dd>The maximum length of an SQL statement, in bytes.</dd>)^
  3099. **
  3100. ** [[SQLITE_LIMIT_COLUMN]] ^(<dt>SQLITE_LIMIT_COLUMN</dt>
  3101. ** <dd>The maximum number of columns in a table definition or in the
  3102. ** result set of a [SELECT] or the maximum number of columns in an index
  3103. ** or in an ORDER BY or GROUP BY clause.</dd>)^
  3104. **
  3105. ** [[SQLITE_LIMIT_EXPR_DEPTH]] ^(<dt>SQLITE_LIMIT_EXPR_DEPTH</dt>
  3106. ** <dd>The maximum depth of the parse tree on any expression.</dd>)^
  3107. **
  3108. ** [[SQLITE_LIMIT_COMPOUND_SELECT]] ^(<dt>SQLITE_LIMIT_COMPOUND_SELECT</dt>
  3109. ** <dd>The maximum number of terms in a compound SELECT statement.</dd>)^
  3110. **
  3111. ** [[SQLITE_LIMIT_VDBE_OP]] ^(<dt>SQLITE_LIMIT_VDBE_OP</dt>
  3112. ** <dd>The maximum number of instructions in a virtual machine program
  3113. ** used to implement an SQL statement. This limit is not currently
  3114. ** enforced, though that might be added in some future release of
  3115. ** SQLite.</dd>)^
  3116. **
  3117. ** [[SQLITE_LIMIT_FUNCTION_ARG]] ^(<dt>SQLITE_LIMIT_FUNCTION_ARG</dt>
  3118. ** <dd>The maximum number of arguments on a function.</dd>)^
  3119. **
  3120. ** [[SQLITE_LIMIT_ATTACHED]] ^(<dt>SQLITE_LIMIT_ATTACHED</dt>
  3121. ** <dd>The maximum number of [ATTACH | attached databases].)^</dd>
  3122. **
  3123. ** [[SQLITE_LIMIT_LIKE_PATTERN_LENGTH]]
  3124. ** ^(<dt>SQLITE_LIMIT_LIKE_PATTERN_LENGTH</dt>
  3125. ** <dd>The maximum length of the pattern argument to the [LIKE] or
  3126. ** [GLOB] operators.</dd>)^
  3127. **
  3128. ** [[SQLITE_LIMIT_VARIABLE_NUMBER]]
  3129. ** ^(<dt>SQLITE_LIMIT_VARIABLE_NUMBER</dt>
  3130. ** <dd>The maximum index number of any [parameter] in an SQL statement.)^
  3131. **
  3132. ** [[SQLITE_LIMIT_TRIGGER_DEPTH]] ^(<dt>SQLITE_LIMIT_TRIGGER_DEPTH</dt>
  3133. ** <dd>The maximum depth of recursion for triggers.</dd>)^
  3134. **
  3135. ** [[SQLITE_LIMIT_WORKER_THREADS]] ^(<dt>SQLITE_LIMIT_WORKER_THREADS</dt>
  3136. ** <dd>The maximum number of auxiliary worker threads that a single
  3137. ** [prepared statement] may start.</dd>)^
  3138. ** </dl>
  3139. */
  3140. #define SQLITE_LIMIT_LENGTH 0
  3141. #define SQLITE_LIMIT_SQL_LENGTH 1
  3142. #define SQLITE_LIMIT_COLUMN 2
  3143. #define SQLITE_LIMIT_EXPR_DEPTH 3
  3144. #define SQLITE_LIMIT_COMPOUND_SELECT 4
  3145. #define SQLITE_LIMIT_VDBE_OP 5
  3146. #define SQLITE_LIMIT_FUNCTION_ARG 6
  3147. #define SQLITE_LIMIT_ATTACHED 7
  3148. #define SQLITE_LIMIT_LIKE_PATTERN_LENGTH 8
  3149. #define SQLITE_LIMIT_VARIABLE_NUMBER 9
  3150. #define SQLITE_LIMIT_TRIGGER_DEPTH 10
  3151. #define SQLITE_LIMIT_WORKER_THREADS 11
  3152. /*
  3153. ** CAPI3REF: Compiling An SQL Statement
  3154. ** KEYWORDS: {SQL statement compiler}
  3155. ** METHOD: sqlite3
  3156. ** CONSTRUCTOR: sqlite3_stmt
  3157. **
  3158. ** To execute an SQL query, it must first be compiled into a byte-code
  3159. ** program using one of these routines.
  3160. **
  3161. ** The first argument, "db", is a [database connection] obtained from a
  3162. ** prior successful call to [sqlite3_open()], [sqlite3_open_v2()] or
  3163. ** [sqlite3_open16()]. The database connection must not have been closed.
  3164. **
  3165. ** The second argument, "zSql", is the statement to be compiled, encoded
  3166. ** as either UTF-8 or UTF-16. The sqlite3_prepare() and sqlite3_prepare_v2()
  3167. ** interfaces use UTF-8, and sqlite3_prepare16() and sqlite3_prepare16_v2()
  3168. ** use UTF-16.
  3169. **
  3170. ** ^If the nByte argument is negative, then zSql is read up to the
  3171. ** first zero terminator. ^If nByte is positive, then it is the
  3172. ** number of bytes read from zSql. ^If nByte is zero, then no prepared
  3173. ** statement is generated.
  3174. ** If the caller knows that the supplied string is nul-terminated, then
  3175. ** there is a small performance advantage to passing an nByte parameter that
  3176. ** is the number of bytes in the input string <i>including</i>
  3177. ** the nul-terminator.
  3178. **
  3179. ** ^If pzTail is not NULL then *pzTail is made to point to the first byte
  3180. ** past the end of the first SQL statement in zSql. These routines only
  3181. ** compile the first statement in zSql, so *pzTail is left pointing to
  3182. ** what remains uncompiled.
  3183. **
  3184. ** ^*ppStmt is left pointing to a compiled [prepared statement] that can be
  3185. ** executed using [sqlite3_step()]. ^If there is an error, *ppStmt is set
  3186. ** to NULL. ^If the input text contains no SQL (if the input is an empty
  3187. ** string or a comment) then *ppStmt is set to NULL.
  3188. ** The calling procedure is responsible for deleting the compiled
  3189. ** SQL statement using [sqlite3_finalize()] after it has finished with it.
  3190. ** ppStmt may not be NULL.
  3191. **
  3192. ** ^On success, the sqlite3_prepare() family of routines return [SQLITE_OK];
  3193. ** otherwise an [error code] is returned.
  3194. **
  3195. ** The sqlite3_prepare_v2() and sqlite3_prepare16_v2() interfaces are
  3196. ** recommended for all new programs. The two older interfaces are retained
  3197. ** for backwards compatibility, but their use is discouraged.
  3198. ** ^In the "v2" interfaces, the prepared statement
  3199. ** that is returned (the [sqlite3_stmt] object) contains a copy of the
  3200. ** original SQL text. This causes the [sqlite3_step()] interface to
  3201. ** behave differently in three ways:
  3202. **
  3203. ** <ol>
  3204. ** <li>
  3205. ** ^If the database schema changes, instead of returning [SQLITE_SCHEMA] as it
  3206. ** always used to do, [sqlite3_step()] will automatically recompile the SQL
  3207. ** statement and try to run it again. As many as [SQLITE_MAX_SCHEMA_RETRY]
  3208. ** retries will occur before sqlite3_step() gives up and returns an error.
  3209. ** </li>
  3210. **
  3211. ** <li>
  3212. ** ^When an error occurs, [sqlite3_step()] will return one of the detailed
  3213. ** [error codes] or [extended error codes]. ^The legacy behavior was that
  3214. ** [sqlite3_step()] would only return a generic [SQLITE_ERROR] result code
  3215. ** and the application would have to make a second call to [sqlite3_reset()]
  3216. ** in order to find the underlying cause of the problem. With the "v2" prepare
  3217. ** interfaces, the underlying reason for the error is returned immediately.
  3218. ** </li>
  3219. **
  3220. ** <li>
  3221. ** ^If the specific value bound to [parameter | host parameter] in the
  3222. ** WHERE clause might influence the choice of query plan for a statement,
  3223. ** then the statement will be automatically recompiled, as if there had been
  3224. ** a schema change, on the first [sqlite3_step()] call following any change
  3225. ** to the [sqlite3_bind_text | bindings] of that [parameter].
  3226. ** ^The specific value of WHERE-clause [parameter] might influence the
  3227. ** choice of query plan if the parameter is the left-hand side of a [LIKE]
  3228. ** or [GLOB] operator or if the parameter is compared to an indexed column
  3229. ** and the [SQLITE_ENABLE_STAT3] compile-time option is enabled.
  3230. ** </li>
  3231. ** </ol>
  3232. */
  3233. SQLITE_API int SQLITE_STDCALL sqlite3_prepare(
  3234. sqlite3 *db, /* Database handle */
  3235. const char *zSql, /* SQL statement, UTF-8 encoded */
  3236. int nByte, /* Maximum length of zSql in bytes. */
  3237. sqlite3_stmt **ppStmt, /* OUT: Statement handle */
  3238. const char **pzTail /* OUT: Pointer to unused portion of zSql */
  3239. );
  3240. SQLITE_API int SQLITE_STDCALL sqlite3_prepare_v2(
  3241. sqlite3 *db, /* Database handle */
  3242. const char *zSql, /* SQL statement, UTF-8 encoded */
  3243. int nByte, /* Maximum length of zSql in bytes. */
  3244. sqlite3_stmt **ppStmt, /* OUT: Statement handle */
  3245. const char **pzTail /* OUT: Pointer to unused portion of zSql */
  3246. );
  3247. SQLITE_API int SQLITE_STDCALL sqlite3_prepare16(
  3248. sqlite3 *db, /* Database handle */
  3249. const void *zSql, /* SQL statement, UTF-16 encoded */
  3250. int nByte, /* Maximum length of zSql in bytes. */
  3251. sqlite3_stmt **ppStmt, /* OUT: Statement handle */
  3252. const void **pzTail /* OUT: Pointer to unused portion of zSql */
  3253. );
  3254. SQLITE_API int SQLITE_STDCALL sqlite3_prepare16_v2(
  3255. sqlite3 *db, /* Database handle */
  3256. const void *zSql, /* SQL statement, UTF-16 encoded */
  3257. int nByte, /* Maximum length of zSql in bytes. */
  3258. sqlite3_stmt **ppStmt, /* OUT: Statement handle */
  3259. const void **pzTail /* OUT: Pointer to unused portion of zSql */
  3260. );
  3261. /*
  3262. ** CAPI3REF: Retrieving Statement SQL
  3263. ** METHOD: sqlite3_stmt
  3264. **
  3265. ** ^This interface can be used to retrieve a saved copy of the original
  3266. ** SQL text used to create a [prepared statement] if that statement was
  3267. ** compiled using either [sqlite3_prepare_v2()] or [sqlite3_prepare16_v2()].
  3268. */
  3269. SQLITE_API const char *SQLITE_STDCALL sqlite3_sql(sqlite3_stmt *pStmt);
  3270. /*
  3271. ** CAPI3REF: Determine If An SQL Statement Writes The Database
  3272. ** METHOD: sqlite3_stmt
  3273. **
  3274. ** ^The sqlite3_stmt_readonly(X) interface returns true (non-zero) if
  3275. ** and only if the [prepared statement] X makes no direct changes to
  3276. ** the content of the database file.
  3277. **
  3278. ** Note that [application-defined SQL functions] or
  3279. ** [virtual tables] might change the database indirectly as a side effect.
  3280. ** ^(For example, if an application defines a function "eval()" that
  3281. ** calls [sqlite3_exec()], then the following SQL statement would
  3282. ** change the database file through side-effects:
  3283. **
  3284. ** <blockquote><pre>
  3285. ** SELECT eval('DELETE FROM t1') FROM t2;
  3286. ** </pre></blockquote>
  3287. **
  3288. ** But because the [SELECT] statement does not change the database file
  3289. ** directly, sqlite3_stmt_readonly() would still return true.)^
  3290. **
  3291. ** ^Transaction control statements such as [BEGIN], [COMMIT], [ROLLBACK],
  3292. ** [SAVEPOINT], and [RELEASE] cause sqlite3_stmt_readonly() to return true,
  3293. ** since the statements themselves do not actually modify the database but
  3294. ** rather they control the timing of when other statements modify the
  3295. ** database. ^The [ATTACH] and [DETACH] statements also cause
  3296. ** sqlite3_stmt_readonly() to return true since, while those statements
  3297. ** change the configuration of a database connection, they do not make
  3298. ** changes to the content of the database files on disk.
  3299. */
  3300. SQLITE_API int SQLITE_STDCALL sqlite3_stmt_readonly(sqlite3_stmt *pStmt);
  3301. /*
  3302. ** CAPI3REF: Determine If A Prepared Statement Has Been Reset
  3303. ** METHOD: sqlite3_stmt
  3304. **
  3305. ** ^The sqlite3_stmt_busy(S) interface returns true (non-zero) if the
  3306. ** [prepared statement] S has been stepped at least once using
  3307. ** [sqlite3_step(S)] but has not run to completion and/or has not
  3308. ** been reset using [sqlite3_reset(S)]. ^The sqlite3_stmt_busy(S)
  3309. ** interface returns false if S is a NULL pointer. If S is not a
  3310. ** NULL pointer and is not a pointer to a valid [prepared statement]
  3311. ** object, then the behavior is undefined and probably undesirable.
  3312. **
  3313. ** This interface can be used in combination [sqlite3_next_stmt()]
  3314. ** to locate all prepared statements associated with a database
  3315. ** connection that are in need of being reset. This can be used,
  3316. ** for example, in diagnostic routines to search for prepared
  3317. ** statements that are holding a transaction open.
  3318. */
  3319. SQLITE_API int SQLITE_STDCALL sqlite3_stmt_busy(sqlite3_stmt*);
  3320. /*
  3321. ** CAPI3REF: Dynamically Typed Value Object
  3322. ** KEYWORDS: {protected sqlite3_value} {unprotected sqlite3_value}
  3323. **
  3324. ** SQLite uses the sqlite3_value object to represent all values
  3325. ** that can be stored in a database table. SQLite uses dynamic typing
  3326. ** for the values it stores. ^Values stored in sqlite3_value objects
  3327. ** can be integers, floating point values, strings, BLOBs, or NULL.
  3328. **
  3329. ** An sqlite3_value object may be either "protected" or "unprotected".
  3330. ** Some interfaces require a protected sqlite3_value. Other interfaces
  3331. ** will accept either a protected or an unprotected sqlite3_value.
  3332. ** Every interface that accepts sqlite3_value arguments specifies
  3333. ** whether or not it requires a protected sqlite3_value. The
  3334. ** [sqlite3_value_dup()] interface can be used to construct a new
  3335. ** protected sqlite3_value from an unprotected sqlite3_value.
  3336. **
  3337. ** The terms "protected" and "unprotected" refer to whether or not
  3338. ** a mutex is held. An internal mutex is held for a protected
  3339. ** sqlite3_value object but no mutex is held for an unprotected
  3340. ** sqlite3_value object. If SQLite is compiled to be single-threaded
  3341. ** (with [SQLITE_THREADSAFE=0] and with [sqlite3_threadsafe()] returning 0)
  3342. ** or if SQLite is run in one of reduced mutex modes
  3343. ** [SQLITE_CONFIG_SINGLETHREAD] or [SQLITE_CONFIG_MULTITHREAD]
  3344. ** then there is no distinction between protected and unprotected
  3345. ** sqlite3_value objects and they can be used interchangeably. However,
  3346. ** for maximum code portability it is recommended that applications
  3347. ** still make the distinction between protected and unprotected
  3348. ** sqlite3_value objects even when not strictly required.
  3349. **
  3350. ** ^The sqlite3_value objects that are passed as parameters into the
  3351. ** implementation of [application-defined SQL functions] are protected.
  3352. ** ^The sqlite3_value object returned by
  3353. ** [sqlite3_column_value()] is unprotected.
  3354. ** Unprotected sqlite3_value objects may only be used with
  3355. ** [sqlite3_result_value()] and [sqlite3_bind_value()].
  3356. ** The [sqlite3_value_blob | sqlite3_value_type()] family of
  3357. ** interfaces require protected sqlite3_value objects.
  3358. */
  3359. typedef struct Mem sqlite3_value;
  3360. /*
  3361. ** CAPI3REF: SQL Function Context Object
  3362. **
  3363. ** The context in which an SQL function executes is stored in an
  3364. ** sqlite3_context object. ^A pointer to an sqlite3_context object
  3365. ** is always first parameter to [application-defined SQL functions].
  3366. ** The application-defined SQL function implementation will pass this
  3367. ** pointer through into calls to [sqlite3_result_int | sqlite3_result()],
  3368. ** [sqlite3_aggregate_context()], [sqlite3_user_data()],
  3369. ** [sqlite3_context_db_handle()], [sqlite3_get_auxdata()],
  3370. ** and/or [sqlite3_set_auxdata()].
  3371. */
  3372. typedef struct sqlite3_context sqlite3_context;
  3373. /*
  3374. ** CAPI3REF: Binding Values To Prepared Statements
  3375. ** KEYWORDS: {host parameter} {host parameters} {host parameter name}
  3376. ** KEYWORDS: {SQL parameter} {SQL parameters} {parameter binding}
  3377. ** METHOD: sqlite3_stmt
  3378. **
  3379. ** ^(In the SQL statement text input to [sqlite3_prepare_v2()] and its variants,
  3380. ** literals may be replaced by a [parameter] that matches one of following
  3381. ** templates:
  3382. **
  3383. ** <ul>
  3384. ** <li> ?
  3385. ** <li> ?NNN
  3386. ** <li> :VVV
  3387. ** <li> @VVV
  3388. ** <li> $VVV
  3389. ** </ul>
  3390. **
  3391. ** In the templates above, NNN represents an integer literal,
  3392. ** and VVV represents an alphanumeric identifier.)^ ^The values of these
  3393. ** parameters (also called "host parameter names" or "SQL parameters")
  3394. ** can be set using the sqlite3_bind_*() routines defined here.
  3395. **
  3396. ** ^The first argument to the sqlite3_bind_*() routines is always
  3397. ** a pointer to the [sqlite3_stmt] object returned from
  3398. ** [sqlite3_prepare_v2()] or its variants.
  3399. **
  3400. ** ^The second argument is the index of the SQL parameter to be set.
  3401. ** ^The leftmost SQL parameter has an index of 1. ^When the same named
  3402. ** SQL parameter is used more than once, second and subsequent
  3403. ** occurrences have the same index as the first occurrence.
  3404. ** ^The index for named parameters can be looked up using the
  3405. ** [sqlite3_bind_parameter_index()] API if desired. ^The index
  3406. ** for "?NNN" parameters is the value of NNN.
  3407. ** ^The NNN value must be between 1 and the [sqlite3_limit()]
  3408. ** parameter [SQLITE_LIMIT_VARIABLE_NUMBER] (default value: 999).
  3409. **
  3410. ** ^The third argument is the value to bind to the parameter.
  3411. ** ^If the third parameter to sqlite3_bind_text() or sqlite3_bind_text16()
  3412. ** or sqlite3_bind_blob() is a NULL pointer then the fourth parameter
  3413. ** is ignored and the end result is the same as sqlite3_bind_null().
  3414. **
  3415. ** ^(In those routines that have a fourth argument, its value is the
  3416. ** number of bytes in the parameter. To be clear: the value is the
  3417. ** number of <u>bytes</u> in the value, not the number of characters.)^
  3418. ** ^If the fourth parameter to sqlite3_bind_text() or sqlite3_bind_text16()
  3419. ** is negative, then the length of the string is
  3420. ** the number of bytes up to the first zero terminator.
  3421. ** If the fourth parameter to sqlite3_bind_blob() is negative, then
  3422. ** the behavior is undefined.
  3423. ** If a non-negative fourth parameter is provided to sqlite3_bind_text()
  3424. ** or sqlite3_bind_text16() or sqlite3_bind_text64() then
  3425. ** that parameter must be the byte offset
  3426. ** where the NUL terminator would occur assuming the string were NUL
  3427. ** terminated. If any NUL characters occur at byte offsets less than
  3428. ** the value of the fourth parameter then the resulting string value will
  3429. ** contain embedded NULs. The result of expressions involving strings
  3430. ** with embedded NULs is undefined.
  3431. **
  3432. ** ^The fifth argument to the BLOB and string binding interfaces
  3433. ** is a destructor used to dispose of the BLOB or
  3434. ** string after SQLite has finished with it. ^The destructor is called
  3435. ** to dispose of the BLOB or string even if the call to bind API fails.
  3436. ** ^If the fifth argument is
  3437. ** the special value [SQLITE_STATIC], then SQLite assumes that the
  3438. ** information is in static, unmanaged space and does not need to be freed.
  3439. ** ^If the fifth argument has the value [SQLITE_TRANSIENT], then
  3440. ** SQLite makes its own private copy of the data immediately, before
  3441. ** the sqlite3_bind_*() routine returns.
  3442. **
  3443. ** ^The sixth argument to sqlite3_bind_text64() must be one of
  3444. ** [SQLITE_UTF8], [SQLITE_UTF16], [SQLITE_UTF16BE], or [SQLITE_UTF16LE]
  3445. ** to specify the encoding of the text in the third parameter. If
  3446. ** the sixth argument to sqlite3_bind_text64() is not one of the
  3447. ** allowed values shown above, or if the text encoding is different
  3448. ** from the encoding specified by the sixth parameter, then the behavior
  3449. ** is undefined.
  3450. **
  3451. ** ^The sqlite3_bind_zeroblob() routine binds a BLOB of length N that
  3452. ** is filled with zeroes. ^A zeroblob uses a fixed amount of memory
  3453. ** (just an integer to hold its size) while it is being processed.
  3454. ** Zeroblobs are intended to serve as placeholders for BLOBs whose
  3455. ** content is later written using
  3456. ** [sqlite3_blob_open | incremental BLOB I/O] routines.
  3457. ** ^A negative value for the zeroblob results in a zero-length BLOB.
  3458. **
  3459. ** ^If any of the sqlite3_bind_*() routines are called with a NULL pointer
  3460. ** for the [prepared statement] or with a prepared statement for which
  3461. ** [sqlite3_step()] has been called more recently than [sqlite3_reset()],
  3462. ** then the call will return [SQLITE_MISUSE]. If any sqlite3_bind_()
  3463. ** routine is passed a [prepared statement] that has been finalized, the
  3464. ** result is undefined and probably harmful.
  3465. **
  3466. ** ^Bindings are not cleared by the [sqlite3_reset()] routine.
  3467. ** ^Unbound parameters are interpreted as NULL.
  3468. **
  3469. ** ^The sqlite3_bind_* routines return [SQLITE_OK] on success or an
  3470. ** [error code] if anything goes wrong.
  3471. ** ^[SQLITE_TOOBIG] might be returned if the size of a string or BLOB
  3472. ** exceeds limits imposed by [sqlite3_limit]([SQLITE_LIMIT_LENGTH]) or
  3473. ** [SQLITE_MAX_LENGTH].
  3474. ** ^[SQLITE_RANGE] is returned if the parameter
  3475. ** index is out of range. ^[SQLITE_NOMEM] is returned if malloc() fails.
  3476. **
  3477. ** See also: [sqlite3_bind_parameter_count()],
  3478. ** [sqlite3_bind_parameter_name()], and [sqlite3_bind_parameter_index()].
  3479. */
  3480. SQLITE_API int SQLITE_STDCALL sqlite3_bind_blob(sqlite3_stmt*, int, const void*, int n, void(*)(void*));
  3481. SQLITE_API int SQLITE_STDCALL sqlite3_bind_blob64(sqlite3_stmt*, int, const void*, sqlite3_uint64,
  3482. void(*)(void*));
  3483. SQLITE_API int SQLITE_STDCALL sqlite3_bind_double(sqlite3_stmt*, int, double);
  3484. SQLITE_API int SQLITE_STDCALL sqlite3_bind_int(sqlite3_stmt*, int, int);
  3485. SQLITE_API int SQLITE_STDCALL sqlite3_bind_int64(sqlite3_stmt*, int, sqlite3_int64);
  3486. SQLITE_API int SQLITE_STDCALL sqlite3_bind_null(sqlite3_stmt*, int);
  3487. SQLITE_API int SQLITE_STDCALL sqlite3_bind_text(sqlite3_stmt*,int,const char*,int,void(*)(void*));
  3488. SQLITE_API int SQLITE_STDCALL sqlite3_bind_text16(sqlite3_stmt*, int, const void*, int, void(*)(void*));
  3489. SQLITE_API int SQLITE_STDCALL sqlite3_bind_text64(sqlite3_stmt*, int, const char*, sqlite3_uint64,
  3490. void(*)(void*), unsigned char encoding);
  3491. SQLITE_API int SQLITE_STDCALL sqlite3_bind_value(sqlite3_stmt*, int, const sqlite3_value*);
  3492. SQLITE_API int SQLITE_STDCALL sqlite3_bind_zeroblob(sqlite3_stmt*, int, int n);
  3493. SQLITE_API int SQLITE_STDCALL sqlite3_bind_zeroblob64(sqlite3_stmt*, int, sqlite3_uint64);
  3494. /*
  3495. ** CAPI3REF: Number Of SQL Parameters
  3496. ** METHOD: sqlite3_stmt
  3497. **
  3498. ** ^This routine can be used to find the number of [SQL parameters]
  3499. ** in a [prepared statement]. SQL parameters are tokens of the
  3500. ** form "?", "?NNN", ":AAA", "$AAA", or "@AAA" that serve as
  3501. ** placeholders for values that are [sqlite3_bind_blob | bound]
  3502. ** to the parameters at a later time.
  3503. **
  3504. ** ^(This routine actually returns the index of the largest (rightmost)
  3505. ** parameter. For all forms except ?NNN, this will correspond to the
  3506. ** number of unique parameters. If parameters of the ?NNN form are used,
  3507. ** there may be gaps in the list.)^
  3508. **
  3509. ** See also: [sqlite3_bind_blob|sqlite3_bind()],
  3510. ** [sqlite3_bind_parameter_name()], and
  3511. ** [sqlite3_bind_parameter_index()].
  3512. */
  3513. SQLITE_API int SQLITE_STDCALL sqlite3_bind_parameter_count(sqlite3_stmt*);
  3514. /*
  3515. ** CAPI3REF: Name Of A Host Parameter
  3516. ** METHOD: sqlite3_stmt
  3517. **
  3518. ** ^The sqlite3_bind_parameter_name(P,N) interface returns
  3519. ** the name of the N-th [SQL parameter] in the [prepared statement] P.
  3520. ** ^(SQL parameters of the form "?NNN" or ":AAA" or "@AAA" or "$AAA"
  3521. ** have a name which is the string "?NNN" or ":AAA" or "@AAA" or "$AAA"
  3522. ** respectively.
  3523. ** In other words, the initial ":" or "$" or "@" or "?"
  3524. ** is included as part of the name.)^
  3525. ** ^Parameters of the form "?" without a following integer have no name
  3526. ** and are referred to as "nameless" or "anonymous parameters".
  3527. **
  3528. ** ^The first host parameter has an index of 1, not 0.
  3529. **
  3530. ** ^If the value N is out of range or if the N-th parameter is
  3531. ** nameless, then NULL is returned. ^The returned string is
  3532. ** always in UTF-8 encoding even if the named parameter was
  3533. ** originally specified as UTF-16 in [sqlite3_prepare16()] or
  3534. ** [sqlite3_prepare16_v2()].
  3535. **
  3536. ** See also: [sqlite3_bind_blob|sqlite3_bind()],
  3537. ** [sqlite3_bind_parameter_count()], and
  3538. ** [sqlite3_bind_parameter_index()].
  3539. */
  3540. SQLITE_API const char *SQLITE_STDCALL sqlite3_bind_parameter_name(sqlite3_stmt*, int);
  3541. /*
  3542. ** CAPI3REF: Index Of A Parameter With A Given Name
  3543. ** METHOD: sqlite3_stmt
  3544. **
  3545. ** ^Return the index of an SQL parameter given its name. ^The
  3546. ** index value returned is suitable for use as the second
  3547. ** parameter to [sqlite3_bind_blob|sqlite3_bind()]. ^A zero
  3548. ** is returned if no matching parameter is found. ^The parameter
  3549. ** name must be given in UTF-8 even if the original statement
  3550. ** was prepared from UTF-16 text using [sqlite3_prepare16_v2()].
  3551. **
  3552. ** See also: [sqlite3_bind_blob|sqlite3_bind()],
  3553. ** [sqlite3_bind_parameter_count()], and
  3554. ** [sqlite3_bind_parameter_index()].
  3555. */
  3556. SQLITE_API int SQLITE_STDCALL sqlite3_bind_parameter_index(sqlite3_stmt*, const char *zName);
  3557. /*
  3558. ** CAPI3REF: Reset All Bindings On A Prepared Statement
  3559. ** METHOD: sqlite3_stmt
  3560. **
  3561. ** ^Contrary to the intuition of many, [sqlite3_reset()] does not reset
  3562. ** the [sqlite3_bind_blob | bindings] on a [prepared statement].
  3563. ** ^Use this routine to reset all host parameters to NULL.
  3564. */
  3565. SQLITE_API int SQLITE_STDCALL sqlite3_clear_bindings(sqlite3_stmt*);
  3566. /*
  3567. ** CAPI3REF: Number Of Columns In A Result Set
  3568. ** METHOD: sqlite3_stmt
  3569. **
  3570. ** ^Return the number of columns in the result set returned by the
  3571. ** [prepared statement]. ^This routine returns 0 if pStmt is an SQL
  3572. ** statement that does not return data (for example an [UPDATE]).
  3573. **
  3574. ** See also: [sqlite3_data_count()]
  3575. */
  3576. SQLITE_API int SQLITE_STDCALL sqlite3_column_count(sqlite3_stmt *pStmt);
  3577. /*
  3578. ** CAPI3REF: Column Names In A Result Set
  3579. ** METHOD: sqlite3_stmt
  3580. **
  3581. ** ^These routines return the name assigned to a particular column
  3582. ** in the result set of a [SELECT] statement. ^The sqlite3_column_name()
  3583. ** interface returns a pointer to a zero-terminated UTF-8 string
  3584. ** and sqlite3_column_name16() returns a pointer to a zero-terminated
  3585. ** UTF-16 string. ^The first parameter is the [prepared statement]
  3586. ** that implements the [SELECT] statement. ^The second parameter is the
  3587. ** column number. ^The leftmost column is number 0.
  3588. **
  3589. ** ^The returned string pointer is valid until either the [prepared statement]
  3590. ** is destroyed by [sqlite3_finalize()] or until the statement is automatically
  3591. ** reprepared by the first call to [sqlite3_step()] for a particular run
  3592. ** or until the next call to
  3593. ** sqlite3_column_name() or sqlite3_column_name16() on the same column.
  3594. **
  3595. ** ^If sqlite3_malloc() fails during the processing of either routine
  3596. ** (for example during a conversion from UTF-8 to UTF-16) then a
  3597. ** NULL pointer is returned.
  3598. **
  3599. ** ^The name of a result column is the value of the "AS" clause for
  3600. ** that column, if there is an AS clause. If there is no AS clause
  3601. ** then the name of the column is unspecified and may change from
  3602. ** one release of SQLite to the next.
  3603. */
  3604. SQLITE_API const char *SQLITE_STDCALL sqlite3_column_name(sqlite3_stmt*, int N);
  3605. SQLITE_API const void *SQLITE_STDCALL sqlite3_column_name16(sqlite3_stmt*, int N);
  3606. /*
  3607. ** CAPI3REF: Source Of Data In A Query Result
  3608. ** METHOD: sqlite3_stmt
  3609. **
  3610. ** ^These routines provide a means to determine the database, table, and
  3611. ** table column that is the origin of a particular result column in
  3612. ** [SELECT] statement.
  3613. ** ^The name of the database or table or column can be returned as
  3614. ** either a UTF-8 or UTF-16 string. ^The _database_ routines return
  3615. ** the database name, the _table_ routines return the table name, and
  3616. ** the origin_ routines return the column name.
  3617. ** ^The returned string is valid until the [prepared statement] is destroyed
  3618. ** using [sqlite3_finalize()] or until the statement is automatically
  3619. ** reprepared by the first call to [sqlite3_step()] for a particular run
  3620. ** or until the same information is requested
  3621. ** again in a different encoding.
  3622. **
  3623. ** ^The names returned are the original un-aliased names of the
  3624. ** database, table, and column.
  3625. **
  3626. ** ^The first argument to these interfaces is a [prepared statement].
  3627. ** ^These functions return information about the Nth result column returned by
  3628. ** the statement, where N is the second function argument.
  3629. ** ^The left-most column is column 0 for these routines.
  3630. **
  3631. ** ^If the Nth column returned by the statement is an expression or
  3632. ** subquery and is not a column value, then all of these functions return
  3633. ** NULL. ^These routine might also return NULL if a memory allocation error
  3634. ** occurs. ^Otherwise, they return the name of the attached database, table,
  3635. ** or column that query result column was extracted from.
  3636. **
  3637. ** ^As with all other SQLite APIs, those whose names end with "16" return
  3638. ** UTF-16 encoded strings and the other functions return UTF-8.
  3639. **
  3640. ** ^These APIs are only available if the library was compiled with the
  3641. ** [SQLITE_ENABLE_COLUMN_METADATA] C-preprocessor symbol.
  3642. **
  3643. ** If two or more threads call one or more of these routines against the same
  3644. ** prepared statement and column at the same time then the results are
  3645. ** undefined.
  3646. **
  3647. ** If two or more threads call one or more
  3648. ** [sqlite3_column_database_name | column metadata interfaces]
  3649. ** for the same [prepared statement] and result column
  3650. ** at the same time then the results are undefined.
  3651. */
  3652. SQLITE_API const char *SQLITE_STDCALL sqlite3_column_database_name(sqlite3_stmt*,int);
  3653. SQLITE_API const void *SQLITE_STDCALL sqlite3_column_database_name16(sqlite3_stmt*,int);
  3654. SQLITE_API const char *SQLITE_STDCALL sqlite3_column_table_name(sqlite3_stmt*,int);
  3655. SQLITE_API const void *SQLITE_STDCALL sqlite3_column_table_name16(sqlite3_stmt*,int);
  3656. SQLITE_API const char *SQLITE_STDCALL sqlite3_column_origin_name(sqlite3_stmt*,int);
  3657. SQLITE_API const void *SQLITE_STDCALL sqlite3_column_origin_name16(sqlite3_stmt*,int);
  3658. /*
  3659. ** CAPI3REF: Declared Datatype Of A Query Result
  3660. ** METHOD: sqlite3_stmt
  3661. **
  3662. ** ^(The first parameter is a [prepared statement].
  3663. ** If this statement is a [SELECT] statement and the Nth column of the
  3664. ** returned result set of that [SELECT] is a table column (not an
  3665. ** expression or subquery) then the declared type of the table
  3666. ** column is returned.)^ ^If the Nth column of the result set is an
  3667. ** expression or subquery, then a NULL pointer is returned.
  3668. ** ^The returned string is always UTF-8 encoded.
  3669. **
  3670. ** ^(For example, given the database schema:
  3671. **
  3672. ** CREATE TABLE t1(c1 VARIANT);
  3673. **
  3674. ** and the following statement to be compiled:
  3675. **
  3676. ** SELECT c1 + 1, c1 FROM t1;
  3677. **
  3678. ** this routine would return the string "VARIANT" for the second result
  3679. ** column (i==1), and a NULL pointer for the first result column (i==0).)^
  3680. **
  3681. ** ^SQLite uses dynamic run-time typing. ^So just because a column
  3682. ** is declared to contain a particular type does not mean that the
  3683. ** data stored in that column is of the declared type. SQLite is
  3684. ** strongly typed, but the typing is dynamic not static. ^Type
  3685. ** is associated with individual values, not with the containers
  3686. ** used to hold those values.
  3687. */
  3688. SQLITE_API const char *SQLITE_STDCALL sqlite3_column_decltype(sqlite3_stmt*,int);
  3689. SQLITE_API const void *SQLITE_STDCALL sqlite3_column_decltype16(sqlite3_stmt*,int);
  3690. /*
  3691. ** CAPI3REF: Evaluate An SQL Statement
  3692. ** METHOD: sqlite3_stmt
  3693. **
  3694. ** After a [prepared statement] has been prepared using either
  3695. ** [sqlite3_prepare_v2()] or [sqlite3_prepare16_v2()] or one of the legacy
  3696. ** interfaces [sqlite3_prepare()] or [sqlite3_prepare16()], this function
  3697. ** must be called one or more times to evaluate the statement.
  3698. **
  3699. ** The details of the behavior of the sqlite3_step() interface depend
  3700. ** on whether the statement was prepared using the newer "v2" interface
  3701. ** [sqlite3_prepare_v2()] and [sqlite3_prepare16_v2()] or the older legacy
  3702. ** interface [sqlite3_prepare()] and [sqlite3_prepare16()]. The use of the
  3703. ** new "v2" interface is recommended for new applications but the legacy
  3704. ** interface will continue to be supported.
  3705. **
  3706. ** ^In the legacy interface, the return value will be either [SQLITE_BUSY],
  3707. ** [SQLITE_DONE], [SQLITE_ROW], [SQLITE_ERROR], or [SQLITE_MISUSE].
  3708. ** ^With the "v2" interface, any of the other [result codes] or
  3709. ** [extended result codes] might be returned as well.
  3710. **
  3711. ** ^[SQLITE_BUSY] means that the database engine was unable to acquire the
  3712. ** database locks it needs to do its job. ^If the statement is a [COMMIT]
  3713. ** or occurs outside of an explicit transaction, then you can retry the
  3714. ** statement. If the statement is not a [COMMIT] and occurs within an
  3715. ** explicit transaction then you should rollback the transaction before
  3716. ** continuing.
  3717. **
  3718. ** ^[SQLITE_DONE] means that the statement has finished executing
  3719. ** successfully. sqlite3_step() should not be called again on this virtual
  3720. ** machine without first calling [sqlite3_reset()] to reset the virtual
  3721. ** machine back to its initial state.
  3722. **
  3723. ** ^If the SQL statement being executed returns any data, then [SQLITE_ROW]
  3724. ** is returned each time a new row of data is ready for processing by the
  3725. ** caller. The values may be accessed using the [column access functions].
  3726. ** sqlite3_step() is called again to retrieve the next row of data.
  3727. **
  3728. ** ^[SQLITE_ERROR] means that a run-time error (such as a constraint
  3729. ** violation) has occurred. sqlite3_step() should not be called again on
  3730. ** the VM. More information may be found by calling [sqlite3_errmsg()].
  3731. ** ^With the legacy interface, a more specific error code (for example,
  3732. ** [SQLITE_INTERRUPT], [SQLITE_SCHEMA], [SQLITE_CORRUPT], and so forth)
  3733. ** can be obtained by calling [sqlite3_reset()] on the
  3734. ** [prepared statement]. ^In the "v2" interface,
  3735. ** the more specific error code is returned directly by sqlite3_step().
  3736. **
  3737. ** [SQLITE_MISUSE] means that the this routine was called inappropriately.
  3738. ** Perhaps it was called on a [prepared statement] that has
  3739. ** already been [sqlite3_finalize | finalized] or on one that had
  3740. ** previously returned [SQLITE_ERROR] or [SQLITE_DONE]. Or it could
  3741. ** be the case that the same database connection is being used by two or
  3742. ** more threads at the same moment in time.
  3743. **
  3744. ** For all versions of SQLite up to and including 3.6.23.1, a call to
  3745. ** [sqlite3_reset()] was required after sqlite3_step() returned anything
  3746. ** other than [SQLITE_ROW] before any subsequent invocation of
  3747. ** sqlite3_step(). Failure to reset the prepared statement using
  3748. ** [sqlite3_reset()] would result in an [SQLITE_MISUSE] return from
  3749. ** sqlite3_step(). But after version 3.6.23.1, sqlite3_step() began
  3750. ** calling [sqlite3_reset()] automatically in this circumstance rather
  3751. ** than returning [SQLITE_MISUSE]. This is not considered a compatibility
  3752. ** break because any application that ever receives an SQLITE_MISUSE error
  3753. ** is broken by definition. The [SQLITE_OMIT_AUTORESET] compile-time option
  3754. ** can be used to restore the legacy behavior.
  3755. **
  3756. ** <b>Goofy Interface Alert:</b> In the legacy interface, the sqlite3_step()
  3757. ** API always returns a generic error code, [SQLITE_ERROR], following any
  3758. ** error other than [SQLITE_BUSY] and [SQLITE_MISUSE]. You must call
  3759. ** [sqlite3_reset()] or [sqlite3_finalize()] in order to find one of the
  3760. ** specific [error codes] that better describes the error.
  3761. ** We admit that this is a goofy design. The problem has been fixed
  3762. ** with the "v2" interface. If you prepare all of your SQL statements
  3763. ** using either [sqlite3_prepare_v2()] or [sqlite3_prepare16_v2()] instead
  3764. ** of the legacy [sqlite3_prepare()] and [sqlite3_prepare16()] interfaces,
  3765. ** then the more specific [error codes] are returned directly
  3766. ** by sqlite3_step(). The use of the "v2" interface is recommended.
  3767. */
  3768. SQLITE_API int SQLITE_STDCALL sqlite3_step(sqlite3_stmt*);
  3769. /*
  3770. ** CAPI3REF: Number of columns in a result set
  3771. ** METHOD: sqlite3_stmt
  3772. **
  3773. ** ^The sqlite3_data_count(P) interface returns the number of columns in the
  3774. ** current row of the result set of [prepared statement] P.
  3775. ** ^If prepared statement P does not have results ready to return
  3776. ** (via calls to the [sqlite3_column_int | sqlite3_column_*()] of
  3777. ** interfaces) then sqlite3_data_count(P) returns 0.
  3778. ** ^The sqlite3_data_count(P) routine also returns 0 if P is a NULL pointer.
  3779. ** ^The sqlite3_data_count(P) routine returns 0 if the previous call to
  3780. ** [sqlite3_step](P) returned [SQLITE_DONE]. ^The sqlite3_data_count(P)
  3781. ** will return non-zero if previous call to [sqlite3_step](P) returned
  3782. ** [SQLITE_ROW], except in the case of the [PRAGMA incremental_vacuum]
  3783. ** where it always returns zero since each step of that multi-step
  3784. ** pragma returns 0 columns of data.
  3785. **
  3786. ** See also: [sqlite3_column_count()]
  3787. */
  3788. SQLITE_API int SQLITE_STDCALL sqlite3_data_count(sqlite3_stmt *pStmt);
  3789. /*
  3790. ** CAPI3REF: Fundamental Datatypes
  3791. ** KEYWORDS: SQLITE_TEXT
  3792. **
  3793. ** ^(Every value in SQLite has one of five fundamental datatypes:
  3794. **
  3795. ** <ul>
  3796. ** <li> 64-bit signed integer
  3797. ** <li> 64-bit IEEE floating point number
  3798. ** <li> string
  3799. ** <li> BLOB
  3800. ** <li> NULL
  3801. ** </ul>)^
  3802. **
  3803. ** These constants are codes for each of those types.
  3804. **
  3805. ** Note that the SQLITE_TEXT constant was also used in SQLite version 2
  3806. ** for a completely different meaning. Software that links against both
  3807. ** SQLite version 2 and SQLite version 3 should use SQLITE3_TEXT, not
  3808. ** SQLITE_TEXT.
  3809. */
  3810. #define SQLITE_INTEGER 1
  3811. #define SQLITE_FLOAT 2
  3812. #define SQLITE_BLOB 4
  3813. #define SQLITE_NULL 5
  3814. #ifdef SQLITE_TEXT
  3815. # undef SQLITE_TEXT
  3816. #else
  3817. # define SQLITE_TEXT 3
  3818. #endif
  3819. #define SQLITE3_TEXT 3
  3820. /*
  3821. ** CAPI3REF: Result Values From A Query
  3822. ** KEYWORDS: {column access functions}
  3823. ** METHOD: sqlite3_stmt
  3824. **
  3825. ** ^These routines return information about a single column of the current
  3826. ** result row of a query. ^In every case the first argument is a pointer
  3827. ** to the [prepared statement] that is being evaluated (the [sqlite3_stmt*]
  3828. ** that was returned from [sqlite3_prepare_v2()] or one of its variants)
  3829. ** and the second argument is the index of the column for which information
  3830. ** should be returned. ^The leftmost column of the result set has the index 0.
  3831. ** ^The number of columns in the result can be determined using
  3832. ** [sqlite3_column_count()].
  3833. **
  3834. ** If the SQL statement does not currently point to a valid row, or if the
  3835. ** column index is out of range, the result is undefined.
  3836. ** These routines may only be called when the most recent call to
  3837. ** [sqlite3_step()] has returned [SQLITE_ROW] and neither
  3838. ** [sqlite3_reset()] nor [sqlite3_finalize()] have been called subsequently.
  3839. ** If any of these routines are called after [sqlite3_reset()] or
  3840. ** [sqlite3_finalize()] or after [sqlite3_step()] has returned
  3841. ** something other than [SQLITE_ROW], the results are undefined.
  3842. ** If [sqlite3_step()] or [sqlite3_reset()] or [sqlite3_finalize()]
  3843. ** are called from a different thread while any of these routines
  3844. ** are pending, then the results are undefined.
  3845. **
  3846. ** ^The sqlite3_column_type() routine returns the
  3847. ** [SQLITE_INTEGER | datatype code] for the initial data type
  3848. ** of the result column. ^The returned value is one of [SQLITE_INTEGER],
  3849. ** [SQLITE_FLOAT], [SQLITE_TEXT], [SQLITE_BLOB], or [SQLITE_NULL]. The value
  3850. ** returned by sqlite3_column_type() is only meaningful if no type
  3851. ** conversions have occurred as described below. After a type conversion,
  3852. ** the value returned by sqlite3_column_type() is undefined. Future
  3853. ** versions of SQLite may change the behavior of sqlite3_column_type()
  3854. ** following a type conversion.
  3855. **
  3856. ** ^If the result is a BLOB or UTF-8 string then the sqlite3_column_bytes()
  3857. ** routine returns the number of bytes in that BLOB or string.
  3858. ** ^If the result is a UTF-16 string, then sqlite3_column_bytes() converts
  3859. ** the string to UTF-8 and then returns the number of bytes.
  3860. ** ^If the result is a numeric value then sqlite3_column_bytes() uses
  3861. ** [sqlite3_snprintf()] to convert that value to a UTF-8 string and returns
  3862. ** the number of bytes in that string.
  3863. ** ^If the result is NULL, then sqlite3_column_bytes() returns zero.
  3864. **
  3865. ** ^If the result is a BLOB or UTF-16 string then the sqlite3_column_bytes16()
  3866. ** routine returns the number of bytes in that BLOB or string.
  3867. ** ^If the result is a UTF-8 string, then sqlite3_column_bytes16() converts
  3868. ** the string to UTF-16 and then returns the number of bytes.
  3869. ** ^If the result is a numeric value then sqlite3_column_bytes16() uses
  3870. ** [sqlite3_snprintf()] to convert that value to a UTF-16 string and returns
  3871. ** the number of bytes in that string.
  3872. ** ^If the result is NULL, then sqlite3_column_bytes16() returns zero.
  3873. **
  3874. ** ^The values returned by [sqlite3_column_bytes()] and
  3875. ** [sqlite3_column_bytes16()] do not include the zero terminators at the end
  3876. ** of the string. ^For clarity: the values returned by
  3877. ** [sqlite3_column_bytes()] and [sqlite3_column_bytes16()] are the number of
  3878. ** bytes in the string, not the number of characters.
  3879. **
  3880. ** ^Strings returned by sqlite3_column_text() and sqlite3_column_text16(),
  3881. ** even empty strings, are always zero-terminated. ^The return
  3882. ** value from sqlite3_column_blob() for a zero-length BLOB is a NULL pointer.
  3883. **
  3884. ** <b>Warning:</b> ^The object returned by [sqlite3_column_value()] is an
  3885. ** [unprotected sqlite3_value] object. In a multithreaded environment,
  3886. ** an unprotected sqlite3_value object may only be used safely with
  3887. ** [sqlite3_bind_value()] and [sqlite3_result_value()].
  3888. ** If the [unprotected sqlite3_value] object returned by
  3889. ** [sqlite3_column_value()] is used in any other way, including calls
  3890. ** to routines like [sqlite3_value_int()], [sqlite3_value_text()],
  3891. ** or [sqlite3_value_bytes()], the behavior is not threadsafe.
  3892. **
  3893. ** These routines attempt to convert the value where appropriate. ^For
  3894. ** example, if the internal representation is FLOAT and a text result
  3895. ** is requested, [sqlite3_snprintf()] is used internally to perform the
  3896. ** conversion automatically. ^(The following table details the conversions
  3897. ** that are applied:
  3898. **
  3899. ** <blockquote>
  3900. ** <table border="1">
  3901. ** <tr><th> Internal<br>Type <th> Requested<br>Type <th> Conversion
  3902. **
  3903. ** <tr><td> NULL <td> INTEGER <td> Result is 0
  3904. ** <tr><td> NULL <td> FLOAT <td> Result is 0.0
  3905. ** <tr><td> NULL <td> TEXT <td> Result is a NULL pointer
  3906. ** <tr><td> NULL <td> BLOB <td> Result is a NULL pointer
  3907. ** <tr><td> INTEGER <td> FLOAT <td> Convert from integer to float
  3908. ** <tr><td> INTEGER <td> TEXT <td> ASCII rendering of the integer
  3909. ** <tr><td> INTEGER <td> BLOB <td> Same as INTEGER->TEXT
  3910. ** <tr><td> FLOAT <td> INTEGER <td> [CAST] to INTEGER
  3911. ** <tr><td> FLOAT <td> TEXT <td> ASCII rendering of the float
  3912. ** <tr><td> FLOAT <td> BLOB <td> [CAST] to BLOB
  3913. ** <tr><td> TEXT <td> INTEGER <td> [CAST] to INTEGER
  3914. ** <tr><td> TEXT <td> FLOAT <td> [CAST] to REAL
  3915. ** <tr><td> TEXT <td> BLOB <td> No change
  3916. ** <tr><td> BLOB <td> INTEGER <td> [CAST] to INTEGER
  3917. ** <tr><td> BLOB <td> FLOAT <td> [CAST] to REAL
  3918. ** <tr><td> BLOB <td> TEXT <td> Add a zero terminator if needed
  3919. ** </table>
  3920. ** </blockquote>)^
  3921. **
  3922. ** Note that when type conversions occur, pointers returned by prior
  3923. ** calls to sqlite3_column_blob(), sqlite3_column_text(), and/or
  3924. ** sqlite3_column_text16() may be invalidated.
  3925. ** Type conversions and pointer invalidations might occur
  3926. ** in the following cases:
  3927. **
  3928. ** <ul>
  3929. ** <li> The initial content is a BLOB and sqlite3_column_text() or
  3930. ** sqlite3_column_text16() is called. A zero-terminator might
  3931. ** need to be added to the string.</li>
  3932. ** <li> The initial content is UTF-8 text and sqlite3_column_bytes16() or
  3933. ** sqlite3_column_text16() is called. The content must be converted
  3934. ** to UTF-16.</li>
  3935. ** <li> The initial content is UTF-16 text and sqlite3_column_bytes() or
  3936. ** sqlite3_column_text() is called. The content must be converted
  3937. ** to UTF-8.</li>
  3938. ** </ul>
  3939. **
  3940. ** ^Conversions between UTF-16be and UTF-16le are always done in place and do
  3941. ** not invalidate a prior pointer, though of course the content of the buffer
  3942. ** that the prior pointer references will have been modified. Other kinds
  3943. ** of conversion are done in place when it is possible, but sometimes they
  3944. ** are not possible and in those cases prior pointers are invalidated.
  3945. **
  3946. ** The safest policy is to invoke these routines
  3947. ** in one of the following ways:
  3948. **
  3949. ** <ul>
  3950. ** <li>sqlite3_column_text() followed by sqlite3_column_bytes()</li>
  3951. ** <li>sqlite3_column_blob() followed by sqlite3_column_bytes()</li>
  3952. ** <li>sqlite3_column_text16() followed by sqlite3_column_bytes16()</li>
  3953. ** </ul>
  3954. **
  3955. ** In other words, you should call sqlite3_column_text(),
  3956. ** sqlite3_column_blob(), or sqlite3_column_text16() first to force the result
  3957. ** into the desired format, then invoke sqlite3_column_bytes() or
  3958. ** sqlite3_column_bytes16() to find the size of the result. Do not mix calls
  3959. ** to sqlite3_column_text() or sqlite3_column_blob() with calls to
  3960. ** sqlite3_column_bytes16(), and do not mix calls to sqlite3_column_text16()
  3961. ** with calls to sqlite3_column_bytes().
  3962. **
  3963. ** ^The pointers returned are valid until a type conversion occurs as
  3964. ** described above, or until [sqlite3_step()] or [sqlite3_reset()] or
  3965. ** [sqlite3_finalize()] is called. ^The memory space used to hold strings
  3966. ** and BLOBs is freed automatically. Do <em>not</em> pass the pointers returned
  3967. ** from [sqlite3_column_blob()], [sqlite3_column_text()], etc. into
  3968. ** [sqlite3_free()].
  3969. **
  3970. ** ^(If a memory allocation error occurs during the evaluation of any
  3971. ** of these routines, a default value is returned. The default value
  3972. ** is either the integer 0, the floating point number 0.0, or a NULL
  3973. ** pointer. Subsequent calls to [sqlite3_errcode()] will return
  3974. ** [SQLITE_NOMEM].)^
  3975. */
  3976. SQLITE_API const void *SQLITE_STDCALL sqlite3_column_blob(sqlite3_stmt*, int iCol);
  3977. SQLITE_API int SQLITE_STDCALL sqlite3_column_bytes(sqlite3_stmt*, int iCol);
  3978. SQLITE_API int SQLITE_STDCALL sqlite3_column_bytes16(sqlite3_stmt*, int iCol);
  3979. SQLITE_API double SQLITE_STDCALL sqlite3_column_double(sqlite3_stmt*, int iCol);
  3980. SQLITE_API int SQLITE_STDCALL sqlite3_column_int(sqlite3_stmt*, int iCol);
  3981. SQLITE_API sqlite3_int64 SQLITE_STDCALL sqlite3_column_int64(sqlite3_stmt*, int iCol);
  3982. SQLITE_API const unsigned char *SQLITE_STDCALL sqlite3_column_text(sqlite3_stmt*, int iCol);
  3983. SQLITE_API const void *SQLITE_STDCALL sqlite3_column_text16(sqlite3_stmt*, int iCol);
  3984. SQLITE_API int SQLITE_STDCALL sqlite3_column_type(sqlite3_stmt*, int iCol);
  3985. SQLITE_API sqlite3_value *SQLITE_STDCALL sqlite3_column_value(sqlite3_stmt*, int iCol);
  3986. /*
  3987. ** CAPI3REF: Destroy A Prepared Statement Object
  3988. ** DESTRUCTOR: sqlite3_stmt
  3989. **
  3990. ** ^The sqlite3_finalize() function is called to delete a [prepared statement].
  3991. ** ^If the most recent evaluation of the statement encountered no errors
  3992. ** or if the statement is never been evaluated, then sqlite3_finalize() returns
  3993. ** SQLITE_OK. ^If the most recent evaluation of statement S failed, then
  3994. ** sqlite3_finalize(S) returns the appropriate [error code] or
  3995. ** [extended error code].
  3996. **
  3997. ** ^The sqlite3_finalize(S) routine can be called at any point during
  3998. ** the life cycle of [prepared statement] S:
  3999. ** before statement S is ever evaluated, after
  4000. ** one or more calls to [sqlite3_reset()], or after any call
  4001. ** to [sqlite3_step()] regardless of whether or not the statement has
  4002. ** completed execution.
  4003. **
  4004. ** ^Invoking sqlite3_finalize() on a NULL pointer is a harmless no-op.
  4005. **
  4006. ** The application must finalize every [prepared statement] in order to avoid
  4007. ** resource leaks. It is a grievous error for the application to try to use
  4008. ** a prepared statement after it has been finalized. Any use of a prepared
  4009. ** statement after it has been finalized can result in undefined and
  4010. ** undesirable behavior such as segfaults and heap corruption.
  4011. */
  4012. SQLITE_API int SQLITE_STDCALL sqlite3_finalize(sqlite3_stmt *pStmt);
  4013. /*
  4014. ** CAPI3REF: Reset A Prepared Statement Object
  4015. ** METHOD: sqlite3_stmt
  4016. **
  4017. ** The sqlite3_reset() function is called to reset a [prepared statement]
  4018. ** object back to its initial state, ready to be re-executed.
  4019. ** ^Any SQL statement variables that had values bound to them using
  4020. ** the [sqlite3_bind_blob | sqlite3_bind_*() API] retain their values.
  4021. ** Use [sqlite3_clear_bindings()] to reset the bindings.
  4022. **
  4023. ** ^The [sqlite3_reset(S)] interface resets the [prepared statement] S
  4024. ** back to the beginning of its program.
  4025. **
  4026. ** ^If the most recent call to [sqlite3_step(S)] for the
  4027. ** [prepared statement] S returned [SQLITE_ROW] or [SQLITE_DONE],
  4028. ** or if [sqlite3_step(S)] has never before been called on S,
  4029. ** then [sqlite3_reset(S)] returns [SQLITE_OK].
  4030. **
  4031. ** ^If the most recent call to [sqlite3_step(S)] for the
  4032. ** [prepared statement] S indicated an error, then
  4033. ** [sqlite3_reset(S)] returns an appropriate [error code].
  4034. **
  4035. ** ^The [sqlite3_reset(S)] interface does not change the values
  4036. ** of any [sqlite3_bind_blob|bindings] on the [prepared statement] S.
  4037. */
  4038. SQLITE_API int SQLITE_STDCALL sqlite3_reset(sqlite3_stmt *pStmt);
  4039. /*
  4040. ** CAPI3REF: Create Or Redefine SQL Functions
  4041. ** KEYWORDS: {function creation routines}
  4042. ** KEYWORDS: {application-defined SQL function}
  4043. ** KEYWORDS: {application-defined SQL functions}
  4044. ** METHOD: sqlite3
  4045. **
  4046. ** ^These functions (collectively known as "function creation routines")
  4047. ** are used to add SQL functions or aggregates or to redefine the behavior
  4048. ** of existing SQL functions or aggregates. The only differences between
  4049. ** these routines are the text encoding expected for
  4050. ** the second parameter (the name of the function being created)
  4051. ** and the presence or absence of a destructor callback for
  4052. ** the application data pointer.
  4053. **
  4054. ** ^The first parameter is the [database connection] to which the SQL
  4055. ** function is to be added. ^If an application uses more than one database
  4056. ** connection then application-defined SQL functions must be added
  4057. ** to each database connection separately.
  4058. **
  4059. ** ^The second parameter is the name of the SQL function to be created or
  4060. ** redefined. ^The length of the name is limited to 255 bytes in a UTF-8
  4061. ** representation, exclusive of the zero-terminator. ^Note that the name
  4062. ** length limit is in UTF-8 bytes, not characters nor UTF-16 bytes.
  4063. ** ^Any attempt to create a function with a longer name
  4064. ** will result in [SQLITE_MISUSE] being returned.
  4065. **
  4066. ** ^The third parameter (nArg)
  4067. ** is the number of arguments that the SQL function or
  4068. ** aggregate takes. ^If this parameter is -1, then the SQL function or
  4069. ** aggregate may take any number of arguments between 0 and the limit
  4070. ** set by [sqlite3_limit]([SQLITE_LIMIT_FUNCTION_ARG]). If the third
  4071. ** parameter is less than -1 or greater than 127 then the behavior is
  4072. ** undefined.
  4073. **
  4074. ** ^The fourth parameter, eTextRep, specifies what
  4075. ** [SQLITE_UTF8 | text encoding] this SQL function prefers for
  4076. ** its parameters. The application should set this parameter to
  4077. ** [SQLITE_UTF16LE] if the function implementation invokes
  4078. ** [sqlite3_value_text16le()] on an input, or [SQLITE_UTF16BE] if the
  4079. ** implementation invokes [sqlite3_value_text16be()] on an input, or
  4080. ** [SQLITE_UTF16] if [sqlite3_value_text16()] is used, or [SQLITE_UTF8]
  4081. ** otherwise. ^The same SQL function may be registered multiple times using
  4082. ** different preferred text encodings, with different implementations for
  4083. ** each encoding.
  4084. ** ^When multiple implementations of the same function are available, SQLite
  4085. ** will pick the one that involves the least amount of data conversion.
  4086. **
  4087. ** ^The fourth parameter may optionally be ORed with [SQLITE_DETERMINISTIC]
  4088. ** to signal that the function will always return the same result given
  4089. ** the same inputs within a single SQL statement. Most SQL functions are
  4090. ** deterministic. The built-in [random()] SQL function is an example of a
  4091. ** function that is not deterministic. The SQLite query planner is able to
  4092. ** perform additional optimizations on deterministic functions, so use
  4093. ** of the [SQLITE_DETERMINISTIC] flag is recommended where possible.
  4094. **
  4095. ** ^(The fifth parameter is an arbitrary pointer. The implementation of the
  4096. ** function can gain access to this pointer using [sqlite3_user_data()].)^
  4097. **
  4098. ** ^The sixth, seventh and eighth parameters, xFunc, xStep and xFinal, are
  4099. ** pointers to C-language functions that implement the SQL function or
  4100. ** aggregate. ^A scalar SQL function requires an implementation of the xFunc
  4101. ** callback only; NULL pointers must be passed as the xStep and xFinal
  4102. ** parameters. ^An aggregate SQL function requires an implementation of xStep
  4103. ** and xFinal and NULL pointer must be passed for xFunc. ^To delete an existing
  4104. ** SQL function or aggregate, pass NULL pointers for all three function
  4105. ** callbacks.
  4106. **
  4107. ** ^(If the ninth parameter to sqlite3_create_function_v2() is not NULL,
  4108. ** then it is destructor for the application data pointer.
  4109. ** The destructor is invoked when the function is deleted, either by being
  4110. ** overloaded or when the database connection closes.)^
  4111. ** ^The destructor is also invoked if the call to
  4112. ** sqlite3_create_function_v2() fails.
  4113. ** ^When the destructor callback of the tenth parameter is invoked, it
  4114. ** is passed a single argument which is a copy of the application data
  4115. ** pointer which was the fifth parameter to sqlite3_create_function_v2().
  4116. **
  4117. ** ^It is permitted to register multiple implementations of the same
  4118. ** functions with the same name but with either differing numbers of
  4119. ** arguments or differing preferred text encodings. ^SQLite will use
  4120. ** the implementation that most closely matches the way in which the
  4121. ** SQL function is used. ^A function implementation with a non-negative
  4122. ** nArg parameter is a better match than a function implementation with
  4123. ** a negative nArg. ^A function where the preferred text encoding
  4124. ** matches the database encoding is a better
  4125. ** match than a function where the encoding is different.
  4126. ** ^A function where the encoding difference is between UTF16le and UTF16be
  4127. ** is a closer match than a function where the encoding difference is
  4128. ** between UTF8 and UTF16.
  4129. **
  4130. ** ^Built-in functions may be overloaded by new application-defined functions.
  4131. **
  4132. ** ^An application-defined function is permitted to call other
  4133. ** SQLite interfaces. However, such calls must not
  4134. ** close the database connection nor finalize or reset the prepared
  4135. ** statement in which the function is running.
  4136. */
  4137. SQLITE_API int SQLITE_STDCALL sqlite3_create_function(
  4138. sqlite3 *db,
  4139. const char *zFunctionName,
  4140. int nArg,
  4141. int eTextRep,
  4142. void *pApp,
  4143. void (*xFunc)(sqlite3_context*,int,sqlite3_value**),
  4144. void (*xStep)(sqlite3_context*,int,sqlite3_value**),
  4145. void (*xFinal)(sqlite3_context*)
  4146. );
  4147. SQLITE_API int SQLITE_STDCALL sqlite3_create_function16(
  4148. sqlite3 *db,
  4149. const void *zFunctionName,
  4150. int nArg,
  4151. int eTextRep,
  4152. void *pApp,
  4153. void (*xFunc)(sqlite3_context*,int,sqlite3_value**),
  4154. void (*xStep)(sqlite3_context*,int,sqlite3_value**),
  4155. void (*xFinal)(sqlite3_context*)
  4156. );
  4157. SQLITE_API int SQLITE_STDCALL sqlite3_create_function_v2(
  4158. sqlite3 *db,
  4159. const char *zFunctionName,
  4160. int nArg,
  4161. int eTextRep,
  4162. void *pApp,
  4163. void (*xFunc)(sqlite3_context*,int,sqlite3_value**),
  4164. void (*xStep)(sqlite3_context*,int,sqlite3_value**),
  4165. void (*xFinal)(sqlite3_context*),
  4166. void(*xDestroy)(void*)
  4167. );
  4168. /*
  4169. ** CAPI3REF: Text Encodings
  4170. **
  4171. ** These constant define integer codes that represent the various
  4172. ** text encodings supported by SQLite.
  4173. */
  4174. #define SQLITE_UTF8 1 /* IMP: R-37514-35566 */
  4175. #define SQLITE_UTF16LE 2 /* IMP: R-03371-37637 */
  4176. #define SQLITE_UTF16BE 3 /* IMP: R-51971-34154 */
  4177. #define SQLITE_UTF16 4 /* Use native byte order */
  4178. #define SQLITE_ANY 5 /* Deprecated */
  4179. #define SQLITE_UTF16_ALIGNED 8 /* sqlite3_create_collation only */
  4180. /*
  4181. ** CAPI3REF: Function Flags
  4182. **
  4183. ** These constants may be ORed together with the
  4184. ** [SQLITE_UTF8 | preferred text encoding] as the fourth argument
  4185. ** to [sqlite3_create_function()], [sqlite3_create_function16()], or
  4186. ** [sqlite3_create_function_v2()].
  4187. */
  4188. #define SQLITE_DETERMINISTIC 0x800
  4189. /*
  4190. ** CAPI3REF: Deprecated Functions
  4191. ** DEPRECATED
  4192. **
  4193. ** These functions are [deprecated]. In order to maintain
  4194. ** backwards compatibility with older code, these functions continue
  4195. ** to be supported. However, new applications should avoid
  4196. ** the use of these functions. To encourage programmers to avoid
  4197. ** these functions, we will not explain what they do.
  4198. */
  4199. #ifndef SQLITE_OMIT_DEPRECATED
  4200. SQLITE_API SQLITE_DEPRECATED int SQLITE_STDCALL sqlite3_aggregate_count(sqlite3_context*);
  4201. SQLITE_API SQLITE_DEPRECATED int SQLITE_STDCALL sqlite3_expired(sqlite3_stmt*);
  4202. SQLITE_API SQLITE_DEPRECATED int SQLITE_STDCALL sqlite3_transfer_bindings(sqlite3_stmt*, sqlite3_stmt*);
  4203. SQLITE_API SQLITE_DEPRECATED int SQLITE_STDCALL sqlite3_global_recover(void);
  4204. SQLITE_API SQLITE_DEPRECATED void SQLITE_STDCALL sqlite3_thread_cleanup(void);
  4205. SQLITE_API SQLITE_DEPRECATED int SQLITE_STDCALL sqlite3_memory_alarm(void(*)(void*,sqlite3_int64,int),
  4206. void*,sqlite3_int64);
  4207. #endif
  4208. /*
  4209. ** CAPI3REF: Obtaining SQL Values
  4210. ** METHOD: sqlite3_value
  4211. **
  4212. ** The C-language implementation of SQL functions and aggregates uses
  4213. ** this set of interface routines to access the parameter values on
  4214. ** the function or aggregate.
  4215. **
  4216. ** The xFunc (for scalar functions) or xStep (for aggregates) parameters
  4217. ** to [sqlite3_create_function()] and [sqlite3_create_function16()]
  4218. ** define callbacks that implement the SQL functions and aggregates.
  4219. ** The 3rd parameter to these callbacks is an array of pointers to
  4220. ** [protected sqlite3_value] objects. There is one [sqlite3_value] object for
  4221. ** each parameter to the SQL function. These routines are used to
  4222. ** extract values from the [sqlite3_value] objects.
  4223. **
  4224. ** These routines work only with [protected sqlite3_value] objects.
  4225. ** Any attempt to use these routines on an [unprotected sqlite3_value]
  4226. ** object results in undefined behavior.
  4227. **
  4228. ** ^These routines work just like the corresponding [column access functions]
  4229. ** except that these routines take a single [protected sqlite3_value] object
  4230. ** pointer instead of a [sqlite3_stmt*] pointer and an integer column number.
  4231. **
  4232. ** ^The sqlite3_value_text16() interface extracts a UTF-16 string
  4233. ** in the native byte-order of the host machine. ^The
  4234. ** sqlite3_value_text16be() and sqlite3_value_text16le() interfaces
  4235. ** extract UTF-16 strings as big-endian and little-endian respectively.
  4236. **
  4237. ** ^(The sqlite3_value_numeric_type() interface attempts to apply
  4238. ** numeric affinity to the value. This means that an attempt is
  4239. ** made to convert the value to an integer or floating point. If
  4240. ** such a conversion is possible without loss of information (in other
  4241. ** words, if the value is a string that looks like a number)
  4242. ** then the conversion is performed. Otherwise no conversion occurs.
  4243. ** The [SQLITE_INTEGER | datatype] after conversion is returned.)^
  4244. **
  4245. ** Please pay particular attention to the fact that the pointer returned
  4246. ** from [sqlite3_value_blob()], [sqlite3_value_text()], or
  4247. ** [sqlite3_value_text16()] can be invalidated by a subsequent call to
  4248. ** [sqlite3_value_bytes()], [sqlite3_value_bytes16()], [sqlite3_value_text()],
  4249. ** or [sqlite3_value_text16()].
  4250. **
  4251. ** These routines must be called from the same thread as
  4252. ** the SQL function that supplied the [sqlite3_value*] parameters.
  4253. */
  4254. SQLITE_API const void *SQLITE_STDCALL sqlite3_value_blob(sqlite3_value*);
  4255. SQLITE_API int SQLITE_STDCALL sqlite3_value_bytes(sqlite3_value*);
  4256. SQLITE_API int SQLITE_STDCALL sqlite3_value_bytes16(sqlite3_value*);
  4257. SQLITE_API double SQLITE_STDCALL sqlite3_value_double(sqlite3_value*);
  4258. SQLITE_API int SQLITE_STDCALL sqlite3_value_int(sqlite3_value*);
  4259. SQLITE_API sqlite3_int64 SQLITE_STDCALL sqlite3_value_int64(sqlite3_value*);
  4260. SQLITE_API const unsigned char *SQLITE_STDCALL sqlite3_value_text(sqlite3_value*);
  4261. SQLITE_API const void *SQLITE_STDCALL sqlite3_value_text16(sqlite3_value*);
  4262. SQLITE_API const void *SQLITE_STDCALL sqlite3_value_text16le(sqlite3_value*);
  4263. SQLITE_API const void *SQLITE_STDCALL sqlite3_value_text16be(sqlite3_value*);
  4264. SQLITE_API int SQLITE_STDCALL sqlite3_value_type(sqlite3_value*);
  4265. SQLITE_API int SQLITE_STDCALL sqlite3_value_numeric_type(sqlite3_value*);
  4266. /*
  4267. ** CAPI3REF: Copy And Free SQL Values
  4268. ** METHOD: sqlite3_value
  4269. **
  4270. ** ^The sqlite3_value_dup(V) interface makes a copy of the [sqlite3_value]
  4271. ** object D and returns a pointer to that copy. ^The [sqlite3_value] returned
  4272. ** is a [protected sqlite3_value] object even if the input is not.
  4273. ** ^The sqlite3_value_dup(V) interface returns NULL if V is NULL or if a
  4274. ** memory allocation fails.
  4275. **
  4276. ** ^The sqlite3_value_free(V) interface frees an [sqlite3_value] object
  4277. ** previously obtained from [sqlite3_value_dup()]. ^If V is a NULL pointer
  4278. ** then sqlite3_value_free(V) is a harmless no-op.
  4279. */
  4280. SQLITE_API SQLITE_EXPERIMENTAL sqlite3_value *SQLITE_STDCALL sqlite3_value_dup(const sqlite3_value*);
  4281. SQLITE_API SQLITE_EXPERIMENTAL void SQLITE_STDCALL sqlite3_value_free(sqlite3_value*);
  4282. /*
  4283. ** CAPI3REF: Obtain Aggregate Function Context
  4284. ** METHOD: sqlite3_context
  4285. **
  4286. ** Implementations of aggregate SQL functions use this
  4287. ** routine to allocate memory for storing their state.
  4288. **
  4289. ** ^The first time the sqlite3_aggregate_context(C,N) routine is called
  4290. ** for a particular aggregate function, SQLite
  4291. ** allocates N of memory, zeroes out that memory, and returns a pointer
  4292. ** to the new memory. ^On second and subsequent calls to
  4293. ** sqlite3_aggregate_context() for the same aggregate function instance,
  4294. ** the same buffer is returned. Sqlite3_aggregate_context() is normally
  4295. ** called once for each invocation of the xStep callback and then one
  4296. ** last time when the xFinal callback is invoked. ^(When no rows match
  4297. ** an aggregate query, the xStep() callback of the aggregate function
  4298. ** implementation is never called and xFinal() is called exactly once.
  4299. ** In those cases, sqlite3_aggregate_context() might be called for the
  4300. ** first time from within xFinal().)^
  4301. **
  4302. ** ^The sqlite3_aggregate_context(C,N) routine returns a NULL pointer
  4303. ** when first called if N is less than or equal to zero or if a memory
  4304. ** allocate error occurs.
  4305. **
  4306. ** ^(The amount of space allocated by sqlite3_aggregate_context(C,N) is
  4307. ** determined by the N parameter on first successful call. Changing the
  4308. ** value of N in subsequent call to sqlite3_aggregate_context() within
  4309. ** the same aggregate function instance will not resize the memory
  4310. ** allocation.)^ Within the xFinal callback, it is customary to set
  4311. ** N=0 in calls to sqlite3_aggregate_context(C,N) so that no
  4312. ** pointless memory allocations occur.
  4313. **
  4314. ** ^SQLite automatically frees the memory allocated by
  4315. ** sqlite3_aggregate_context() when the aggregate query concludes.
  4316. **
  4317. ** The first parameter must be a copy of the
  4318. ** [sqlite3_context | SQL function context] that is the first parameter
  4319. ** to the xStep or xFinal callback routine that implements the aggregate
  4320. ** function.
  4321. **
  4322. ** This routine must be called from the same thread in which
  4323. ** the aggregate SQL function is running.
  4324. */
  4325. SQLITE_API void *SQLITE_STDCALL sqlite3_aggregate_context(sqlite3_context*, int nBytes);
  4326. /*
  4327. ** CAPI3REF: User Data For Functions
  4328. ** METHOD: sqlite3_context
  4329. **
  4330. ** ^The sqlite3_user_data() interface returns a copy of
  4331. ** the pointer that was the pUserData parameter (the 5th parameter)
  4332. ** of the [sqlite3_create_function()]
  4333. ** and [sqlite3_create_function16()] routines that originally
  4334. ** registered the application defined function.
  4335. **
  4336. ** This routine must be called from the same thread in which
  4337. ** the application-defined function is running.
  4338. */
  4339. SQLITE_API void *SQLITE_STDCALL sqlite3_user_data(sqlite3_context*);
  4340. /*
  4341. ** CAPI3REF: Database Connection For Functions
  4342. ** METHOD: sqlite3_context
  4343. **
  4344. ** ^The sqlite3_context_db_handle() interface returns a copy of
  4345. ** the pointer to the [database connection] (the 1st parameter)
  4346. ** of the [sqlite3_create_function()]
  4347. ** and [sqlite3_create_function16()] routines that originally
  4348. ** registered the application defined function.
  4349. */
  4350. SQLITE_API sqlite3 *SQLITE_STDCALL sqlite3_context_db_handle(sqlite3_context*);
  4351. /*
  4352. ** CAPI3REF: Function Auxiliary Data
  4353. ** METHOD: sqlite3_context
  4354. **
  4355. ** These functions may be used by (non-aggregate) SQL functions to
  4356. ** associate metadata with argument values. If the same value is passed to
  4357. ** multiple invocations of the same SQL function during query execution, under
  4358. ** some circumstances the associated metadata may be preserved. An example
  4359. ** of where this might be useful is in a regular-expression matching
  4360. ** function. The compiled version of the regular expression can be stored as
  4361. ** metadata associated with the pattern string.
  4362. ** Then as long as the pattern string remains the same,
  4363. ** the compiled regular expression can be reused on multiple
  4364. ** invocations of the same function.
  4365. **
  4366. ** ^The sqlite3_get_auxdata() interface returns a pointer to the metadata
  4367. ** associated by the sqlite3_set_auxdata() function with the Nth argument
  4368. ** value to the application-defined function. ^If there is no metadata
  4369. ** associated with the function argument, this sqlite3_get_auxdata() interface
  4370. ** returns a NULL pointer.
  4371. **
  4372. ** ^The sqlite3_set_auxdata(C,N,P,X) interface saves P as metadata for the N-th
  4373. ** argument of the application-defined function. ^Subsequent
  4374. ** calls to sqlite3_get_auxdata(C,N) return P from the most recent
  4375. ** sqlite3_set_auxdata(C,N,P,X) call if the metadata is still valid or
  4376. ** NULL if the metadata has been discarded.
  4377. ** ^After each call to sqlite3_set_auxdata(C,N,P,X) where X is not NULL,
  4378. ** SQLite will invoke the destructor function X with parameter P exactly
  4379. ** once, when the metadata is discarded.
  4380. ** SQLite is free to discard the metadata at any time, including: <ul>
  4381. ** <li> when the corresponding function parameter changes, or
  4382. ** <li> when [sqlite3_reset()] or [sqlite3_finalize()] is called for the
  4383. ** SQL statement, or
  4384. ** <li> when sqlite3_set_auxdata() is invoked again on the same parameter, or
  4385. ** <li> during the original sqlite3_set_auxdata() call when a memory
  4386. ** allocation error occurs. </ul>)^
  4387. **
  4388. ** Note the last bullet in particular. The destructor X in
  4389. ** sqlite3_set_auxdata(C,N,P,X) might be called immediately, before the
  4390. ** sqlite3_set_auxdata() interface even returns. Hence sqlite3_set_auxdata()
  4391. ** should be called near the end of the function implementation and the
  4392. ** function implementation should not make any use of P after
  4393. ** sqlite3_set_auxdata() has been called.
  4394. **
  4395. ** ^(In practice, metadata is preserved between function calls for
  4396. ** function parameters that are compile-time constants, including literal
  4397. ** values and [parameters] and expressions composed from the same.)^
  4398. **
  4399. ** These routines must be called from the same thread in which
  4400. ** the SQL function is running.
  4401. */
  4402. SQLITE_API void *SQLITE_STDCALL sqlite3_get_auxdata(sqlite3_context*, int N);
  4403. SQLITE_API void SQLITE_STDCALL sqlite3_set_auxdata(sqlite3_context*, int N, void*, void (*)(void*));
  4404. /*
  4405. ** CAPI3REF: Constants Defining Special Destructor Behavior
  4406. **
  4407. ** These are special values for the destructor that is passed in as the
  4408. ** final argument to routines like [sqlite3_result_blob()]. ^If the destructor
  4409. ** argument is SQLITE_STATIC, it means that the content pointer is constant
  4410. ** and will never change. It does not need to be destroyed. ^The
  4411. ** SQLITE_TRANSIENT value means that the content will likely change in
  4412. ** the near future and that SQLite should make its own private copy of
  4413. ** the content before returning.
  4414. **
  4415. ** The typedef is necessary to work around problems in certain
  4416. ** C++ compilers.
  4417. */
  4418. typedef void (*sqlite3_destructor_type)(void*);
  4419. #define SQLITE_STATIC ((sqlite3_destructor_type)0)
  4420. #define SQLITE_TRANSIENT ((sqlite3_destructor_type)-1)
  4421. /*
  4422. ** CAPI3REF: Setting The Result Of An SQL Function
  4423. ** METHOD: sqlite3_context
  4424. **
  4425. ** These routines are used by the xFunc or xFinal callbacks that
  4426. ** implement SQL functions and aggregates. See
  4427. ** [sqlite3_create_function()] and [sqlite3_create_function16()]
  4428. ** for additional information.
  4429. **
  4430. ** These functions work very much like the [parameter binding] family of
  4431. ** functions used to bind values to host parameters in prepared statements.
  4432. ** Refer to the [SQL parameter] documentation for additional information.
  4433. **
  4434. ** ^The sqlite3_result_blob() interface sets the result from
  4435. ** an application-defined function to be the BLOB whose content is pointed
  4436. ** to by the second parameter and which is N bytes long where N is the
  4437. ** third parameter.
  4438. **
  4439. ** ^The sqlite3_result_zeroblob(C,N) and sqlite3_result_zeroblob64(C,N)
  4440. ** interfaces set the result of the application-defined function to be
  4441. ** a BLOB containing all zero bytes and N bytes in size.
  4442. **
  4443. ** ^The sqlite3_result_double() interface sets the result from
  4444. ** an application-defined function to be a floating point value specified
  4445. ** by its 2nd argument.
  4446. **
  4447. ** ^The sqlite3_result_error() and sqlite3_result_error16() functions
  4448. ** cause the implemented SQL function to throw an exception.
  4449. ** ^SQLite uses the string pointed to by the
  4450. ** 2nd parameter of sqlite3_result_error() or sqlite3_result_error16()
  4451. ** as the text of an error message. ^SQLite interprets the error
  4452. ** message string from sqlite3_result_error() as UTF-8. ^SQLite
  4453. ** interprets the string from sqlite3_result_error16() as UTF-16 in native
  4454. ** byte order. ^If the third parameter to sqlite3_result_error()
  4455. ** or sqlite3_result_error16() is negative then SQLite takes as the error
  4456. ** message all text up through the first zero character.
  4457. ** ^If the third parameter to sqlite3_result_error() or
  4458. ** sqlite3_result_error16() is non-negative then SQLite takes that many
  4459. ** bytes (not characters) from the 2nd parameter as the error message.
  4460. ** ^The sqlite3_result_error() and sqlite3_result_error16()
  4461. ** routines make a private copy of the error message text before
  4462. ** they return. Hence, the calling function can deallocate or
  4463. ** modify the text after they return without harm.
  4464. ** ^The sqlite3_result_error_code() function changes the error code
  4465. ** returned by SQLite as a result of an error in a function. ^By default,
  4466. ** the error code is SQLITE_ERROR. ^A subsequent call to sqlite3_result_error()
  4467. ** or sqlite3_result_error16() resets the error code to SQLITE_ERROR.
  4468. **
  4469. ** ^The sqlite3_result_error_toobig() interface causes SQLite to throw an
  4470. ** error indicating that a string or BLOB is too long to represent.
  4471. **
  4472. ** ^The sqlite3_result_error_nomem() interface causes SQLite to throw an
  4473. ** error indicating that a memory allocation failed.
  4474. **
  4475. ** ^The sqlite3_result_int() interface sets the return value
  4476. ** of the application-defined function to be the 32-bit signed integer
  4477. ** value given in the 2nd argument.
  4478. ** ^The sqlite3_result_int64() interface sets the return value
  4479. ** of the application-defined function to be the 64-bit signed integer
  4480. ** value given in the 2nd argument.
  4481. **
  4482. ** ^The sqlite3_result_null() interface sets the return value
  4483. ** of the application-defined function to be NULL.
  4484. **
  4485. ** ^The sqlite3_result_text(), sqlite3_result_text16(),
  4486. ** sqlite3_result_text16le(), and sqlite3_result_text16be() interfaces
  4487. ** set the return value of the application-defined function to be
  4488. ** a text string which is represented as UTF-8, UTF-16 native byte order,
  4489. ** UTF-16 little endian, or UTF-16 big endian, respectively.
  4490. ** ^The sqlite3_result_text64() interface sets the return value of an
  4491. ** application-defined function to be a text string in an encoding
  4492. ** specified by the fifth (and last) parameter, which must be one
  4493. ** of [SQLITE_UTF8], [SQLITE_UTF16], [SQLITE_UTF16BE], or [SQLITE_UTF16LE].
  4494. ** ^SQLite takes the text result from the application from
  4495. ** the 2nd parameter of the sqlite3_result_text* interfaces.
  4496. ** ^If the 3rd parameter to the sqlite3_result_text* interfaces
  4497. ** is negative, then SQLite takes result text from the 2nd parameter
  4498. ** through the first zero character.
  4499. ** ^If the 3rd parameter to the sqlite3_result_text* interfaces
  4500. ** is non-negative, then as many bytes (not characters) of the text
  4501. ** pointed to by the 2nd parameter are taken as the application-defined
  4502. ** function result. If the 3rd parameter is non-negative, then it
  4503. ** must be the byte offset into the string where the NUL terminator would
  4504. ** appear if the string where NUL terminated. If any NUL characters occur
  4505. ** in the string at a byte offset that is less than the value of the 3rd
  4506. ** parameter, then the resulting string will contain embedded NULs and the
  4507. ** result of expressions operating on strings with embedded NULs is undefined.
  4508. ** ^If the 4th parameter to the sqlite3_result_text* interfaces
  4509. ** or sqlite3_result_blob is a non-NULL pointer, then SQLite calls that
  4510. ** function as the destructor on the text or BLOB result when it has
  4511. ** finished using that result.
  4512. ** ^If the 4th parameter to the sqlite3_result_text* interfaces or to
  4513. ** sqlite3_result_blob is the special constant SQLITE_STATIC, then SQLite
  4514. ** assumes that the text or BLOB result is in constant space and does not
  4515. ** copy the content of the parameter nor call a destructor on the content
  4516. ** when it has finished using that result.
  4517. ** ^If the 4th parameter to the sqlite3_result_text* interfaces
  4518. ** or sqlite3_result_blob is the special constant SQLITE_TRANSIENT
  4519. ** then SQLite makes a copy of the result into space obtained from
  4520. ** from [sqlite3_malloc()] before it returns.
  4521. **
  4522. ** ^The sqlite3_result_value() interface sets the result of
  4523. ** the application-defined function to be a copy of the
  4524. ** [unprotected sqlite3_value] object specified by the 2nd parameter. ^The
  4525. ** sqlite3_result_value() interface makes a copy of the [sqlite3_value]
  4526. ** so that the [sqlite3_value] specified in the parameter may change or
  4527. ** be deallocated after sqlite3_result_value() returns without harm.
  4528. ** ^A [protected sqlite3_value] object may always be used where an
  4529. ** [unprotected sqlite3_value] object is required, so either
  4530. ** kind of [sqlite3_value] object can be used with this interface.
  4531. **
  4532. ** If these routines are called from within the different thread
  4533. ** than the one containing the application-defined function that received
  4534. ** the [sqlite3_context] pointer, the results are undefined.
  4535. */
  4536. SQLITE_API void SQLITE_STDCALL sqlite3_result_blob(sqlite3_context*, const void*, int, void(*)(void*));
  4537. SQLITE_API void SQLITE_STDCALL sqlite3_result_blob64(sqlite3_context*,const void*,
  4538. sqlite3_uint64,void(*)(void*));
  4539. SQLITE_API void SQLITE_STDCALL sqlite3_result_double(sqlite3_context*, double);
  4540. SQLITE_API void SQLITE_STDCALL sqlite3_result_error(sqlite3_context*, const char*, int);
  4541. SQLITE_API void SQLITE_STDCALL sqlite3_result_error16(sqlite3_context*, const void*, int);
  4542. SQLITE_API void SQLITE_STDCALL sqlite3_result_error_toobig(sqlite3_context*);
  4543. SQLITE_API void SQLITE_STDCALL sqlite3_result_error_nomem(sqlite3_context*);
  4544. SQLITE_API void SQLITE_STDCALL sqlite3_result_error_code(sqlite3_context*, int);
  4545. SQLITE_API void SQLITE_STDCALL sqlite3_result_int(sqlite3_context*, int);
  4546. SQLITE_API void SQLITE_STDCALL sqlite3_result_int64(sqlite3_context*, sqlite3_int64);
  4547. SQLITE_API void SQLITE_STDCALL sqlite3_result_null(sqlite3_context*);
  4548. SQLITE_API void SQLITE_STDCALL sqlite3_result_text(sqlite3_context*, const char*, int, void(*)(void*));
  4549. SQLITE_API void SQLITE_STDCALL sqlite3_result_text64(sqlite3_context*, const char*,sqlite3_uint64,
  4550. void(*)(void*), unsigned char encoding);
  4551. SQLITE_API void SQLITE_STDCALL sqlite3_result_text16(sqlite3_context*, const void*, int, void(*)(void*));
  4552. SQLITE_API void SQLITE_STDCALL sqlite3_result_text16le(sqlite3_context*, const void*, int,void(*)(void*));
  4553. SQLITE_API void SQLITE_STDCALL sqlite3_result_text16be(sqlite3_context*, const void*, int,void(*)(void*));
  4554. SQLITE_API void SQLITE_STDCALL sqlite3_result_value(sqlite3_context*, sqlite3_value*);
  4555. SQLITE_API void SQLITE_STDCALL sqlite3_result_zeroblob(sqlite3_context*, int n);
  4556. SQLITE_API int SQLITE_STDCALL sqlite3_result_zeroblob64(sqlite3_context*, sqlite3_uint64 n);
  4557. /*
  4558. ** CAPI3REF: Define New Collating Sequences
  4559. ** METHOD: sqlite3
  4560. **
  4561. ** ^These functions add, remove, or modify a [collation] associated
  4562. ** with the [database connection] specified as the first argument.
  4563. **
  4564. ** ^The name of the collation is a UTF-8 string
  4565. ** for sqlite3_create_collation() and sqlite3_create_collation_v2()
  4566. ** and a UTF-16 string in native byte order for sqlite3_create_collation16().
  4567. ** ^Collation names that compare equal according to [sqlite3_strnicmp()] are
  4568. ** considered to be the same name.
  4569. **
  4570. ** ^(The third argument (eTextRep) must be one of the constants:
  4571. ** <ul>
  4572. ** <li> [SQLITE_UTF8],
  4573. ** <li> [SQLITE_UTF16LE],
  4574. ** <li> [SQLITE_UTF16BE],
  4575. ** <li> [SQLITE_UTF16], or
  4576. ** <li> [SQLITE_UTF16_ALIGNED].
  4577. ** </ul>)^
  4578. ** ^The eTextRep argument determines the encoding of strings passed
  4579. ** to the collating function callback, xCallback.
  4580. ** ^The [SQLITE_UTF16] and [SQLITE_UTF16_ALIGNED] values for eTextRep
  4581. ** force strings to be UTF16 with native byte order.
  4582. ** ^The [SQLITE_UTF16_ALIGNED] value for eTextRep forces strings to begin
  4583. ** on an even byte address.
  4584. **
  4585. ** ^The fourth argument, pArg, is an application data pointer that is passed
  4586. ** through as the first argument to the collating function callback.
  4587. **
  4588. ** ^The fifth argument, xCallback, is a pointer to the collating function.
  4589. ** ^Multiple collating functions can be registered using the same name but
  4590. ** with different eTextRep parameters and SQLite will use whichever
  4591. ** function requires the least amount of data transformation.
  4592. ** ^If the xCallback argument is NULL then the collating function is
  4593. ** deleted. ^When all collating functions having the same name are deleted,
  4594. ** that collation is no longer usable.
  4595. **
  4596. ** ^The collating function callback is invoked with a copy of the pArg
  4597. ** application data pointer and with two strings in the encoding specified
  4598. ** by the eTextRep argument. The collating function must return an
  4599. ** integer that is negative, zero, or positive
  4600. ** if the first string is less than, equal to, or greater than the second,
  4601. ** respectively. A collating function must always return the same answer
  4602. ** given the same inputs. If two or more collating functions are registered
  4603. ** to the same collation name (using different eTextRep values) then all
  4604. ** must give an equivalent answer when invoked with equivalent strings.
  4605. ** The collating function must obey the following properties for all
  4606. ** strings A, B, and C:
  4607. **
  4608. ** <ol>
  4609. ** <li> If A==B then B==A.
  4610. ** <li> If A==B and B==C then A==C.
  4611. ** <li> If A&lt;B THEN B&gt;A.
  4612. ** <li> If A&lt;B and B&lt;C then A&lt;C.
  4613. ** </ol>
  4614. **
  4615. ** If a collating function fails any of the above constraints and that
  4616. ** collating function is registered and used, then the behavior of SQLite
  4617. ** is undefined.
  4618. **
  4619. ** ^The sqlite3_create_collation_v2() works like sqlite3_create_collation()
  4620. ** with the addition that the xDestroy callback is invoked on pArg when
  4621. ** the collating function is deleted.
  4622. ** ^Collating functions are deleted when they are overridden by later
  4623. ** calls to the collation creation functions or when the
  4624. ** [database connection] is closed using [sqlite3_close()].
  4625. **
  4626. ** ^The xDestroy callback is <u>not</u> called if the
  4627. ** sqlite3_create_collation_v2() function fails. Applications that invoke
  4628. ** sqlite3_create_collation_v2() with a non-NULL xDestroy argument should
  4629. ** check the return code and dispose of the application data pointer
  4630. ** themselves rather than expecting SQLite to deal with it for them.
  4631. ** This is different from every other SQLite interface. The inconsistency
  4632. ** is unfortunate but cannot be changed without breaking backwards
  4633. ** compatibility.
  4634. **
  4635. ** See also: [sqlite3_collation_needed()] and [sqlite3_collation_needed16()].
  4636. */
  4637. SQLITE_API int SQLITE_STDCALL sqlite3_create_collation(
  4638. sqlite3*,
  4639. const char *zName,
  4640. int eTextRep,
  4641. void *pArg,
  4642. int(*xCompare)(void*,int,const void*,int,const void*)
  4643. );
  4644. SQLITE_API int SQLITE_STDCALL sqlite3_create_collation_v2(
  4645. sqlite3*,
  4646. const char *zName,
  4647. int eTextRep,
  4648. void *pArg,
  4649. int(*xCompare)(void*,int,const void*,int,const void*),
  4650. void(*xDestroy)(void*)
  4651. );
  4652. SQLITE_API int SQLITE_STDCALL sqlite3_create_collation16(
  4653. sqlite3*,
  4654. const void *zName,
  4655. int eTextRep,
  4656. void *pArg,
  4657. int(*xCompare)(void*,int,const void*,int,const void*)
  4658. );
  4659. /*
  4660. ** CAPI3REF: Collation Needed Callbacks
  4661. ** METHOD: sqlite3
  4662. **
  4663. ** ^To avoid having to register all collation sequences before a database
  4664. ** can be used, a single callback function may be registered with the
  4665. ** [database connection] to be invoked whenever an undefined collation
  4666. ** sequence is required.
  4667. **
  4668. ** ^If the function is registered using the sqlite3_collation_needed() API,
  4669. ** then it is passed the names of undefined collation sequences as strings
  4670. ** encoded in UTF-8. ^If sqlite3_collation_needed16() is used,
  4671. ** the names are passed as UTF-16 in machine native byte order.
  4672. ** ^A call to either function replaces the existing collation-needed callback.
  4673. **
  4674. ** ^(When the callback is invoked, the first argument passed is a copy
  4675. ** of the second argument to sqlite3_collation_needed() or
  4676. ** sqlite3_collation_needed16(). The second argument is the database
  4677. ** connection. The third argument is one of [SQLITE_UTF8], [SQLITE_UTF16BE],
  4678. ** or [SQLITE_UTF16LE], indicating the most desirable form of the collation
  4679. ** sequence function required. The fourth parameter is the name of the
  4680. ** required collation sequence.)^
  4681. **
  4682. ** The callback function should register the desired collation using
  4683. ** [sqlite3_create_collation()], [sqlite3_create_collation16()], or
  4684. ** [sqlite3_create_collation_v2()].
  4685. */
  4686. SQLITE_API int SQLITE_STDCALL sqlite3_collation_needed(
  4687. sqlite3*,
  4688. void*,
  4689. void(*)(void*,sqlite3*,int eTextRep,const char*)
  4690. );
  4691. SQLITE_API int SQLITE_STDCALL sqlite3_collation_needed16(
  4692. sqlite3*,
  4693. void*,
  4694. void(*)(void*,sqlite3*,int eTextRep,const void*)
  4695. );
  4696. #ifdef SQLITE_HAS_CODEC
  4697. /*
  4698. ** Specify the key for an encrypted database. This routine should be
  4699. ** called right after sqlite3_open().
  4700. **
  4701. ** The code to implement this API is not available in the public release
  4702. ** of SQLite.
  4703. */
  4704. SQLITE_API int SQLITE_STDCALL sqlite3_key(
  4705. sqlite3 *db, /* Database to be rekeyed */
  4706. const void *pKey, int nKey /* The key */
  4707. );
  4708. SQLITE_API int SQLITE_STDCALL sqlite3_key_v2(
  4709. sqlite3 *db, /* Database to be rekeyed */
  4710. const char *zDbName, /* Name of the database */
  4711. const void *pKey, int nKey /* The key */
  4712. );
  4713. /*
  4714. ** Change the key on an open database. If the current database is not
  4715. ** encrypted, this routine will encrypt it. If pNew==0 or nNew==0, the
  4716. ** database is decrypted.
  4717. **
  4718. ** The code to implement this API is not available in the public release
  4719. ** of SQLite.
  4720. */
  4721. SQLITE_API int SQLITE_STDCALL sqlite3_rekey(
  4722. sqlite3 *db, /* Database to be rekeyed */
  4723. const void *pKey, int nKey /* The new key */
  4724. );
  4725. SQLITE_API int SQLITE_STDCALL sqlite3_rekey_v2(
  4726. sqlite3 *db, /* Database to be rekeyed */
  4727. const char *zDbName, /* Name of the database */
  4728. const void *pKey, int nKey /* The new key */
  4729. );
  4730. /*
  4731. ** Specify the activation key for a SEE database. Unless
  4732. ** activated, none of the SEE routines will work.
  4733. */
  4734. SQLITE_API void SQLITE_STDCALL sqlite3_activate_see(
  4735. const char *zPassPhrase /* Activation phrase */
  4736. );
  4737. #endif
  4738. #ifdef SQLITE_ENABLE_CEROD
  4739. /*
  4740. ** Specify the activation key for a CEROD database. Unless
  4741. ** activated, none of the CEROD routines will work.
  4742. */
  4743. SQLITE_API void SQLITE_STDCALL sqlite3_activate_cerod(
  4744. const char *zPassPhrase /* Activation phrase */
  4745. );
  4746. #endif
  4747. /*
  4748. ** CAPI3REF: Suspend Execution For A Short Time
  4749. **
  4750. ** The sqlite3_sleep() function causes the current thread to suspend execution
  4751. ** for at least a number of milliseconds specified in its parameter.
  4752. **
  4753. ** If the operating system does not support sleep requests with
  4754. ** millisecond time resolution, then the time will be rounded up to
  4755. ** the nearest second. The number of milliseconds of sleep actually
  4756. ** requested from the operating system is returned.
  4757. **
  4758. ** ^SQLite implements this interface by calling the xSleep()
  4759. ** method of the default [sqlite3_vfs] object. If the xSleep() method
  4760. ** of the default VFS is not implemented correctly, or not implemented at
  4761. ** all, then the behavior of sqlite3_sleep() may deviate from the description
  4762. ** in the previous paragraphs.
  4763. */
  4764. SQLITE_API int SQLITE_STDCALL sqlite3_sleep(int);
  4765. /*
  4766. ** CAPI3REF: Name Of The Folder Holding Temporary Files
  4767. **
  4768. ** ^(If this global variable is made to point to a string which is
  4769. ** the name of a folder (a.k.a. directory), then all temporary files
  4770. ** created by SQLite when using a built-in [sqlite3_vfs | VFS]
  4771. ** will be placed in that directory.)^ ^If this variable
  4772. ** is a NULL pointer, then SQLite performs a search for an appropriate
  4773. ** temporary file directory.
  4774. **
  4775. ** Applications are strongly discouraged from using this global variable.
  4776. ** It is required to set a temporary folder on Windows Runtime (WinRT).
  4777. ** But for all other platforms, it is highly recommended that applications
  4778. ** neither read nor write this variable. This global variable is a relic
  4779. ** that exists for backwards compatibility of legacy applications and should
  4780. ** be avoided in new projects.
  4781. **
  4782. ** It is not safe to read or modify this variable in more than one
  4783. ** thread at a time. It is not safe to read or modify this variable
  4784. ** if a [database connection] is being used at the same time in a separate
  4785. ** thread.
  4786. ** It is intended that this variable be set once
  4787. ** as part of process initialization and before any SQLite interface
  4788. ** routines have been called and that this variable remain unchanged
  4789. ** thereafter.
  4790. **
  4791. ** ^The [temp_store_directory pragma] may modify this variable and cause
  4792. ** it to point to memory obtained from [sqlite3_malloc]. ^Furthermore,
  4793. ** the [temp_store_directory pragma] always assumes that any string
  4794. ** that this variable points to is held in memory obtained from
  4795. ** [sqlite3_malloc] and the pragma may attempt to free that memory
  4796. ** using [sqlite3_free].
  4797. ** Hence, if this variable is modified directly, either it should be
  4798. ** made NULL or made to point to memory obtained from [sqlite3_malloc]
  4799. ** or else the use of the [temp_store_directory pragma] should be avoided.
  4800. ** Except when requested by the [temp_store_directory pragma], SQLite
  4801. ** does not free the memory that sqlite3_temp_directory points to. If
  4802. ** the application wants that memory to be freed, it must do
  4803. ** so itself, taking care to only do so after all [database connection]
  4804. ** objects have been destroyed.
  4805. **
  4806. ** <b>Note to Windows Runtime users:</b> The temporary directory must be set
  4807. ** prior to calling [sqlite3_open] or [sqlite3_open_v2]. Otherwise, various
  4808. ** features that require the use of temporary files may fail. Here is an
  4809. ** example of how to do this using C++ with the Windows Runtime:
  4810. **
  4811. ** <blockquote><pre>
  4812. ** LPCWSTR zPath = Windows::Storage::ApplicationData::Current->
  4813. ** &nbsp; TemporaryFolder->Path->Data();
  4814. ** char zPathBuf&#91;MAX_PATH + 1&#93;;
  4815. ** memset(zPathBuf, 0, sizeof(zPathBuf));
  4816. ** WideCharToMultiByte(CP_UTF8, 0, zPath, -1, zPathBuf, sizeof(zPathBuf),
  4817. ** &nbsp; NULL, NULL);
  4818. ** sqlite3_temp_directory = sqlite3_mprintf("%s", zPathBuf);
  4819. ** </pre></blockquote>
  4820. */
  4821. SQLITE_API SQLITE_EXTERN char *sqlite3_temp_directory;
  4822. /*
  4823. ** CAPI3REF: Name Of The Folder Holding Database Files
  4824. **
  4825. ** ^(If this global variable is made to point to a string which is
  4826. ** the name of a folder (a.k.a. directory), then all database files
  4827. ** specified with a relative pathname and created or accessed by
  4828. ** SQLite when using a built-in windows [sqlite3_vfs | VFS] will be assumed
  4829. ** to be relative to that directory.)^ ^If this variable is a NULL
  4830. ** pointer, then SQLite assumes that all database files specified
  4831. ** with a relative pathname are relative to the current directory
  4832. ** for the process. Only the windows VFS makes use of this global
  4833. ** variable; it is ignored by the unix VFS.
  4834. **
  4835. ** Changing the value of this variable while a database connection is
  4836. ** open can result in a corrupt database.
  4837. **
  4838. ** It is not safe to read or modify this variable in more than one
  4839. ** thread at a time. It is not safe to read or modify this variable
  4840. ** if a [database connection] is being used at the same time in a separate
  4841. ** thread.
  4842. ** It is intended that this variable be set once
  4843. ** as part of process initialization and before any SQLite interface
  4844. ** routines have been called and that this variable remain unchanged
  4845. ** thereafter.
  4846. **
  4847. ** ^The [data_store_directory pragma] may modify this variable and cause
  4848. ** it to point to memory obtained from [sqlite3_malloc]. ^Furthermore,
  4849. ** the [data_store_directory pragma] always assumes that any string
  4850. ** that this variable points to is held in memory obtained from
  4851. ** [sqlite3_malloc] and the pragma may attempt to free that memory
  4852. ** using [sqlite3_free].
  4853. ** Hence, if this variable is modified directly, either it should be
  4854. ** made NULL or made to point to memory obtained from [sqlite3_malloc]
  4855. ** or else the use of the [data_store_directory pragma] should be avoided.
  4856. */
  4857. SQLITE_API SQLITE_EXTERN char *sqlite3_data_directory;
  4858. /*
  4859. ** CAPI3REF: Test For Auto-Commit Mode
  4860. ** KEYWORDS: {autocommit mode}
  4861. ** METHOD: sqlite3
  4862. **
  4863. ** ^The sqlite3_get_autocommit() interface returns non-zero or
  4864. ** zero if the given database connection is or is not in autocommit mode,
  4865. ** respectively. ^Autocommit mode is on by default.
  4866. ** ^Autocommit mode is disabled by a [BEGIN] statement.
  4867. ** ^Autocommit mode is re-enabled by a [COMMIT] or [ROLLBACK].
  4868. **
  4869. ** If certain kinds of errors occur on a statement within a multi-statement
  4870. ** transaction (errors including [SQLITE_FULL], [SQLITE_IOERR],
  4871. ** [SQLITE_NOMEM], [SQLITE_BUSY], and [SQLITE_INTERRUPT]) then the
  4872. ** transaction might be rolled back automatically. The only way to
  4873. ** find out whether SQLite automatically rolled back the transaction after
  4874. ** an error is to use this function.
  4875. **
  4876. ** If another thread changes the autocommit status of the database
  4877. ** connection while this routine is running, then the return value
  4878. ** is undefined.
  4879. */
  4880. SQLITE_API int SQLITE_STDCALL sqlite3_get_autocommit(sqlite3*);
  4881. /*
  4882. ** CAPI3REF: Find The Database Handle Of A Prepared Statement
  4883. ** METHOD: sqlite3_stmt
  4884. **
  4885. ** ^The sqlite3_db_handle interface returns the [database connection] handle
  4886. ** to which a [prepared statement] belongs. ^The [database connection]
  4887. ** returned by sqlite3_db_handle is the same [database connection]
  4888. ** that was the first argument
  4889. ** to the [sqlite3_prepare_v2()] call (or its variants) that was used to
  4890. ** create the statement in the first place.
  4891. */
  4892. SQLITE_API sqlite3 *SQLITE_STDCALL sqlite3_db_handle(sqlite3_stmt*);
  4893. /*
  4894. ** CAPI3REF: Return The Filename For A Database Connection
  4895. ** METHOD: sqlite3
  4896. **
  4897. ** ^The sqlite3_db_filename(D,N) interface returns a pointer to a filename
  4898. ** associated with database N of connection D. ^The main database file
  4899. ** has the name "main". If there is no attached database N on the database
  4900. ** connection D, or if database N is a temporary or in-memory database, then
  4901. ** a NULL pointer is returned.
  4902. **
  4903. ** ^The filename returned by this function is the output of the
  4904. ** xFullPathname method of the [VFS]. ^In other words, the filename
  4905. ** will be an absolute pathname, even if the filename used
  4906. ** to open the database originally was a URI or relative pathname.
  4907. */
  4908. SQLITE_API const char *SQLITE_STDCALL sqlite3_db_filename(sqlite3 *db, const char *zDbName);
  4909. /*
  4910. ** CAPI3REF: Determine if a database is read-only
  4911. ** METHOD: sqlite3
  4912. **
  4913. ** ^The sqlite3_db_readonly(D,N) interface returns 1 if the database N
  4914. ** of connection D is read-only, 0 if it is read/write, or -1 if N is not
  4915. ** the name of a database on connection D.
  4916. */
  4917. SQLITE_API int SQLITE_STDCALL sqlite3_db_readonly(sqlite3 *db, const char *zDbName);
  4918. /*
  4919. ** CAPI3REF: Find the next prepared statement
  4920. ** METHOD: sqlite3
  4921. **
  4922. ** ^This interface returns a pointer to the next [prepared statement] after
  4923. ** pStmt associated with the [database connection] pDb. ^If pStmt is NULL
  4924. ** then this interface returns a pointer to the first prepared statement
  4925. ** associated with the database connection pDb. ^If no prepared statement
  4926. ** satisfies the conditions of this routine, it returns NULL.
  4927. **
  4928. ** The [database connection] pointer D in a call to
  4929. ** [sqlite3_next_stmt(D,S)] must refer to an open database
  4930. ** connection and in particular must not be a NULL pointer.
  4931. */
  4932. SQLITE_API sqlite3_stmt *SQLITE_STDCALL sqlite3_next_stmt(sqlite3 *pDb, sqlite3_stmt *pStmt);
  4933. /*
  4934. ** CAPI3REF: Commit And Rollback Notification Callbacks
  4935. ** METHOD: sqlite3
  4936. **
  4937. ** ^The sqlite3_commit_hook() interface registers a callback
  4938. ** function to be invoked whenever a transaction is [COMMIT | committed].
  4939. ** ^Any callback set by a previous call to sqlite3_commit_hook()
  4940. ** for the same database connection is overridden.
  4941. ** ^The sqlite3_rollback_hook() interface registers a callback
  4942. ** function to be invoked whenever a transaction is [ROLLBACK | rolled back].
  4943. ** ^Any callback set by a previous call to sqlite3_rollback_hook()
  4944. ** for the same database connection is overridden.
  4945. ** ^The pArg argument is passed through to the callback.
  4946. ** ^If the callback on a commit hook function returns non-zero,
  4947. ** then the commit is converted into a rollback.
  4948. **
  4949. ** ^The sqlite3_commit_hook(D,C,P) and sqlite3_rollback_hook(D,C,P) functions
  4950. ** return the P argument from the previous call of the same function
  4951. ** on the same [database connection] D, or NULL for
  4952. ** the first call for each function on D.
  4953. **
  4954. ** The commit and rollback hook callbacks are not reentrant.
  4955. ** The callback implementation must not do anything that will modify
  4956. ** the database connection that invoked the callback. Any actions
  4957. ** to modify the database connection must be deferred until after the
  4958. ** completion of the [sqlite3_step()] call that triggered the commit
  4959. ** or rollback hook in the first place.
  4960. ** Note that running any other SQL statements, including SELECT statements,
  4961. ** or merely calling [sqlite3_prepare_v2()] and [sqlite3_step()] will modify
  4962. ** the database connections for the meaning of "modify" in this paragraph.
  4963. **
  4964. ** ^Registering a NULL function disables the callback.
  4965. **
  4966. ** ^When the commit hook callback routine returns zero, the [COMMIT]
  4967. ** operation is allowed to continue normally. ^If the commit hook
  4968. ** returns non-zero, then the [COMMIT] is converted into a [ROLLBACK].
  4969. ** ^The rollback hook is invoked on a rollback that results from a commit
  4970. ** hook returning non-zero, just as it would be with any other rollback.
  4971. **
  4972. ** ^For the purposes of this API, a transaction is said to have been
  4973. ** rolled back if an explicit "ROLLBACK" statement is executed, or
  4974. ** an error or constraint causes an implicit rollback to occur.
  4975. ** ^The rollback callback is not invoked if a transaction is
  4976. ** automatically rolled back because the database connection is closed.
  4977. **
  4978. ** See also the [sqlite3_update_hook()] interface.
  4979. */
  4980. SQLITE_API void *SQLITE_STDCALL sqlite3_commit_hook(sqlite3*, int(*)(void*), void*);
  4981. SQLITE_API void *SQLITE_STDCALL sqlite3_rollback_hook(sqlite3*, void(*)(void *), void*);
  4982. /*
  4983. ** CAPI3REF: Data Change Notification Callbacks
  4984. ** METHOD: sqlite3
  4985. **
  4986. ** ^The sqlite3_update_hook() interface registers a callback function
  4987. ** with the [database connection] identified by the first argument
  4988. ** to be invoked whenever a row is updated, inserted or deleted in
  4989. ** a rowid table.
  4990. ** ^Any callback set by a previous call to this function
  4991. ** for the same database connection is overridden.
  4992. **
  4993. ** ^The second argument is a pointer to the function to invoke when a
  4994. ** row is updated, inserted or deleted in a rowid table.
  4995. ** ^The first argument to the callback is a copy of the third argument
  4996. ** to sqlite3_update_hook().
  4997. ** ^The second callback argument is one of [SQLITE_INSERT], [SQLITE_DELETE],
  4998. ** or [SQLITE_UPDATE], depending on the operation that caused the callback
  4999. ** to be invoked.
  5000. ** ^The third and fourth arguments to the callback contain pointers to the
  5001. ** database and table name containing the affected row.
  5002. ** ^The final callback parameter is the [rowid] of the row.
  5003. ** ^In the case of an update, this is the [rowid] after the update takes place.
  5004. **
  5005. ** ^(The update hook is not invoked when internal system tables are
  5006. ** modified (i.e. sqlite_master and sqlite_sequence).)^
  5007. ** ^The update hook is not invoked when [WITHOUT ROWID] tables are modified.
  5008. **
  5009. ** ^In the current implementation, the update hook
  5010. ** is not invoked when duplication rows are deleted because of an
  5011. ** [ON CONFLICT | ON CONFLICT REPLACE] clause. ^Nor is the update hook
  5012. ** invoked when rows are deleted using the [truncate optimization].
  5013. ** The exceptions defined in this paragraph might change in a future
  5014. ** release of SQLite.
  5015. **
  5016. ** The update hook implementation must not do anything that will modify
  5017. ** the database connection that invoked the update hook. Any actions
  5018. ** to modify the database connection must be deferred until after the
  5019. ** completion of the [sqlite3_step()] call that triggered the update hook.
  5020. ** Note that [sqlite3_prepare_v2()] and [sqlite3_step()] both modify their
  5021. ** database connections for the meaning of "modify" in this paragraph.
  5022. **
  5023. ** ^The sqlite3_update_hook(D,C,P) function
  5024. ** returns the P argument from the previous call
  5025. ** on the same [database connection] D, or NULL for
  5026. ** the first call on D.
  5027. **
  5028. ** See also the [sqlite3_commit_hook()] and [sqlite3_rollback_hook()]
  5029. ** interfaces.
  5030. */
  5031. SQLITE_API void *SQLITE_STDCALL sqlite3_update_hook(
  5032. sqlite3*,
  5033. void(*)(void *,int ,char const *,char const *,sqlite3_int64),
  5034. void*
  5035. );
  5036. /*
  5037. ** CAPI3REF: Enable Or Disable Shared Pager Cache
  5038. **
  5039. ** ^(This routine enables or disables the sharing of the database cache
  5040. ** and schema data structures between [database connection | connections]
  5041. ** to the same database. Sharing is enabled if the argument is true
  5042. ** and disabled if the argument is false.)^
  5043. **
  5044. ** ^Cache sharing is enabled and disabled for an entire process.
  5045. ** This is a change as of SQLite version 3.5.0. In prior versions of SQLite,
  5046. ** sharing was enabled or disabled for each thread separately.
  5047. **
  5048. ** ^(The cache sharing mode set by this interface effects all subsequent
  5049. ** calls to [sqlite3_open()], [sqlite3_open_v2()], and [sqlite3_open16()].
  5050. ** Existing database connections continue use the sharing mode
  5051. ** that was in effect at the time they were opened.)^
  5052. **
  5053. ** ^(This routine returns [SQLITE_OK] if shared cache was enabled or disabled
  5054. ** successfully. An [error code] is returned otherwise.)^
  5055. **
  5056. ** ^Shared cache is disabled by default. But this might change in
  5057. ** future releases of SQLite. Applications that care about shared
  5058. ** cache setting should set it explicitly.
  5059. **
  5060. ** Note: This method is disabled on MacOS X 10.7 and iOS version 5.0
  5061. ** and will always return SQLITE_MISUSE. On those systems,
  5062. ** shared cache mode should be enabled per-database connection via
  5063. ** [sqlite3_open_v2()] with [SQLITE_OPEN_SHAREDCACHE].
  5064. **
  5065. ** This interface is threadsafe on processors where writing a
  5066. ** 32-bit integer is atomic.
  5067. **
  5068. ** See Also: [SQLite Shared-Cache Mode]
  5069. */
  5070. SQLITE_API int SQLITE_STDCALL sqlite3_enable_shared_cache(int);
  5071. /*
  5072. ** CAPI3REF: Attempt To Free Heap Memory
  5073. **
  5074. ** ^The sqlite3_release_memory() interface attempts to free N bytes
  5075. ** of heap memory by deallocating non-essential memory allocations
  5076. ** held by the database library. Memory used to cache database
  5077. ** pages to improve performance is an example of non-essential memory.
  5078. ** ^sqlite3_release_memory() returns the number of bytes actually freed,
  5079. ** which might be more or less than the amount requested.
  5080. ** ^The sqlite3_release_memory() routine is a no-op returning zero
  5081. ** if SQLite is not compiled with [SQLITE_ENABLE_MEMORY_MANAGEMENT].
  5082. **
  5083. ** See also: [sqlite3_db_release_memory()]
  5084. */
  5085. SQLITE_API int SQLITE_STDCALL sqlite3_release_memory(int);
  5086. /*
  5087. ** CAPI3REF: Free Memory Used By A Database Connection
  5088. ** METHOD: sqlite3
  5089. **
  5090. ** ^The sqlite3_db_release_memory(D) interface attempts to free as much heap
  5091. ** memory as possible from database connection D. Unlike the
  5092. ** [sqlite3_release_memory()] interface, this interface is in effect even
  5093. ** when the [SQLITE_ENABLE_MEMORY_MANAGEMENT] compile-time option is
  5094. ** omitted.
  5095. **
  5096. ** See also: [sqlite3_release_memory()]
  5097. */
  5098. SQLITE_API int SQLITE_STDCALL sqlite3_db_release_memory(sqlite3*);
  5099. /*
  5100. ** CAPI3REF: Impose A Limit On Heap Size
  5101. **
  5102. ** ^The sqlite3_soft_heap_limit64() interface sets and/or queries the
  5103. ** soft limit on the amount of heap memory that may be allocated by SQLite.
  5104. ** ^SQLite strives to keep heap memory utilization below the soft heap
  5105. ** limit by reducing the number of pages held in the page cache
  5106. ** as heap memory usages approaches the limit.
  5107. ** ^The soft heap limit is "soft" because even though SQLite strives to stay
  5108. ** below the limit, it will exceed the limit rather than generate
  5109. ** an [SQLITE_NOMEM] error. In other words, the soft heap limit
  5110. ** is advisory only.
  5111. **
  5112. ** ^The return value from sqlite3_soft_heap_limit64() is the size of
  5113. ** the soft heap limit prior to the call, or negative in the case of an
  5114. ** error. ^If the argument N is negative
  5115. ** then no change is made to the soft heap limit. Hence, the current
  5116. ** size of the soft heap limit can be determined by invoking
  5117. ** sqlite3_soft_heap_limit64() with a negative argument.
  5118. **
  5119. ** ^If the argument N is zero then the soft heap limit is disabled.
  5120. **
  5121. ** ^(The soft heap limit is not enforced in the current implementation
  5122. ** if one or more of following conditions are true:
  5123. **
  5124. ** <ul>
  5125. ** <li> The soft heap limit is set to zero.
  5126. ** <li> Memory accounting is disabled using a combination of the
  5127. ** [sqlite3_config]([SQLITE_CONFIG_MEMSTATUS],...) start-time option and
  5128. ** the [SQLITE_DEFAULT_MEMSTATUS] compile-time option.
  5129. ** <li> An alternative page cache implementation is specified using
  5130. ** [sqlite3_config]([SQLITE_CONFIG_PCACHE2],...).
  5131. ** <li> The page cache allocates from its own memory pool supplied
  5132. ** by [sqlite3_config]([SQLITE_CONFIG_PAGECACHE],...) rather than
  5133. ** from the heap.
  5134. ** </ul>)^
  5135. **
  5136. ** Beginning with SQLite version 3.7.3, the soft heap limit is enforced
  5137. ** regardless of whether or not the [SQLITE_ENABLE_MEMORY_MANAGEMENT]
  5138. ** compile-time option is invoked. With [SQLITE_ENABLE_MEMORY_MANAGEMENT],
  5139. ** the soft heap limit is enforced on every memory allocation. Without
  5140. ** [SQLITE_ENABLE_MEMORY_MANAGEMENT], the soft heap limit is only enforced
  5141. ** when memory is allocated by the page cache. Testing suggests that because
  5142. ** the page cache is the predominate memory user in SQLite, most
  5143. ** applications will achieve adequate soft heap limit enforcement without
  5144. ** the use of [SQLITE_ENABLE_MEMORY_MANAGEMENT].
  5145. **
  5146. ** The circumstances under which SQLite will enforce the soft heap limit may
  5147. ** changes in future releases of SQLite.
  5148. */
  5149. SQLITE_API sqlite3_int64 SQLITE_STDCALL sqlite3_soft_heap_limit64(sqlite3_int64 N);
  5150. /*
  5151. ** CAPI3REF: Deprecated Soft Heap Limit Interface
  5152. ** DEPRECATED
  5153. **
  5154. ** This is a deprecated version of the [sqlite3_soft_heap_limit64()]
  5155. ** interface. This routine is provided for historical compatibility
  5156. ** only. All new applications should use the
  5157. ** [sqlite3_soft_heap_limit64()] interface rather than this one.
  5158. */
  5159. SQLITE_API SQLITE_DEPRECATED void SQLITE_STDCALL sqlite3_soft_heap_limit(int N);
  5160. /*
  5161. ** CAPI3REF: Extract Metadata About A Column Of A Table
  5162. ** METHOD: sqlite3
  5163. **
  5164. ** ^(The sqlite3_table_column_metadata(X,D,T,C,....) routine returns
  5165. ** information about column C of table T in database D
  5166. ** on [database connection] X.)^ ^The sqlite3_table_column_metadata()
  5167. ** interface returns SQLITE_OK and fills in the non-NULL pointers in
  5168. ** the final five arguments with appropriate values if the specified
  5169. ** column exists. ^The sqlite3_table_column_metadata() interface returns
  5170. ** SQLITE_ERROR and if the specified column does not exist.
  5171. ** ^If the column-name parameter to sqlite3_table_column_metadata() is a
  5172. ** NULL pointer, then this routine simply checks for the existance of the
  5173. ** table and returns SQLITE_OK if the table exists and SQLITE_ERROR if it
  5174. ** does not.
  5175. **
  5176. ** ^The column is identified by the second, third and fourth parameters to
  5177. ** this function. ^(The second parameter is either the name of the database
  5178. ** (i.e. "main", "temp", or an attached database) containing the specified
  5179. ** table or NULL.)^ ^If it is NULL, then all attached databases are searched
  5180. ** for the table using the same algorithm used by the database engine to
  5181. ** resolve unqualified table references.
  5182. **
  5183. ** ^The third and fourth parameters to this function are the table and column
  5184. ** name of the desired column, respectively.
  5185. **
  5186. ** ^Metadata is returned by writing to the memory locations passed as the 5th
  5187. ** and subsequent parameters to this function. ^Any of these arguments may be
  5188. ** NULL, in which case the corresponding element of metadata is omitted.
  5189. **
  5190. ** ^(<blockquote>
  5191. ** <table border="1">
  5192. ** <tr><th> Parameter <th> Output<br>Type <th> Description
  5193. **
  5194. ** <tr><td> 5th <td> const char* <td> Data type
  5195. ** <tr><td> 6th <td> const char* <td> Name of default collation sequence
  5196. ** <tr><td> 7th <td> int <td> True if column has a NOT NULL constraint
  5197. ** <tr><td> 8th <td> int <td> True if column is part of the PRIMARY KEY
  5198. ** <tr><td> 9th <td> int <td> True if column is [AUTOINCREMENT]
  5199. ** </table>
  5200. ** </blockquote>)^
  5201. **
  5202. ** ^The memory pointed to by the character pointers returned for the
  5203. ** declaration type and collation sequence is valid until the next
  5204. ** call to any SQLite API function.
  5205. **
  5206. ** ^If the specified table is actually a view, an [error code] is returned.
  5207. **
  5208. ** ^If the specified column is "rowid", "oid" or "_rowid_" and the table
  5209. ** is not a [WITHOUT ROWID] table and an
  5210. ** [INTEGER PRIMARY KEY] column has been explicitly declared, then the output
  5211. ** parameters are set for the explicitly declared column. ^(If there is no
  5212. ** [INTEGER PRIMARY KEY] column, then the outputs
  5213. ** for the [rowid] are set as follows:
  5214. **
  5215. ** <pre>
  5216. ** data type: "INTEGER"
  5217. ** collation sequence: "BINARY"
  5218. ** not null: 0
  5219. ** primary key: 1
  5220. ** auto increment: 0
  5221. ** </pre>)^
  5222. **
  5223. ** ^This function causes all database schemas to be read from disk and
  5224. ** parsed, if that has not already been done, and returns an error if
  5225. ** any errors are encountered while loading the schema.
  5226. */
  5227. SQLITE_API int SQLITE_STDCALL sqlite3_table_column_metadata(
  5228. sqlite3 *db, /* Connection handle */
  5229. const char *zDbName, /* Database name or NULL */
  5230. const char *zTableName, /* Table name */
  5231. const char *zColumnName, /* Column name */
  5232. char const **pzDataType, /* OUTPUT: Declared data type */
  5233. char const **pzCollSeq, /* OUTPUT: Collation sequence name */
  5234. int *pNotNull, /* OUTPUT: True if NOT NULL constraint exists */
  5235. int *pPrimaryKey, /* OUTPUT: True if column part of PK */
  5236. int *pAutoinc /* OUTPUT: True if column is auto-increment */
  5237. );
  5238. /*
  5239. ** CAPI3REF: Load An Extension
  5240. ** METHOD: sqlite3
  5241. **
  5242. ** ^This interface loads an SQLite extension library from the named file.
  5243. **
  5244. ** ^The sqlite3_load_extension() interface attempts to load an
  5245. ** [SQLite extension] library contained in the file zFile. If
  5246. ** the file cannot be loaded directly, attempts are made to load
  5247. ** with various operating-system specific extensions added.
  5248. ** So for example, if "samplelib" cannot be loaded, then names like
  5249. ** "samplelib.so" or "samplelib.dylib" or "samplelib.dll" might
  5250. ** be tried also.
  5251. **
  5252. ** ^The entry point is zProc.
  5253. ** ^(zProc may be 0, in which case SQLite will try to come up with an
  5254. ** entry point name on its own. It first tries "sqlite3_extension_init".
  5255. ** If that does not work, it constructs a name "sqlite3_X_init" where the
  5256. ** X is consists of the lower-case equivalent of all ASCII alphabetic
  5257. ** characters in the filename from the last "/" to the first following
  5258. ** "." and omitting any initial "lib".)^
  5259. ** ^The sqlite3_load_extension() interface returns
  5260. ** [SQLITE_OK] on success and [SQLITE_ERROR] if something goes wrong.
  5261. ** ^If an error occurs and pzErrMsg is not 0, then the
  5262. ** [sqlite3_load_extension()] interface shall attempt to
  5263. ** fill *pzErrMsg with error message text stored in memory
  5264. ** obtained from [sqlite3_malloc()]. The calling function
  5265. ** should free this memory by calling [sqlite3_free()].
  5266. **
  5267. ** ^Extension loading must be enabled using
  5268. ** [sqlite3_enable_load_extension()] prior to calling this API,
  5269. ** otherwise an error will be returned.
  5270. **
  5271. ** See also the [load_extension() SQL function].
  5272. */
  5273. SQLITE_API int SQLITE_STDCALL sqlite3_load_extension(
  5274. sqlite3 *db, /* Load the extension into this database connection */
  5275. const char *zFile, /* Name of the shared library containing extension */
  5276. const char *zProc, /* Entry point. Derived from zFile if 0 */
  5277. char **pzErrMsg /* Put error message here if not 0 */
  5278. );
  5279. /*
  5280. ** CAPI3REF: Enable Or Disable Extension Loading
  5281. ** METHOD: sqlite3
  5282. **
  5283. ** ^So as not to open security holes in older applications that are
  5284. ** unprepared to deal with [extension loading], and as a means of disabling
  5285. ** [extension loading] while evaluating user-entered SQL, the following API
  5286. ** is provided to turn the [sqlite3_load_extension()] mechanism on and off.
  5287. **
  5288. ** ^Extension loading is off by default.
  5289. ** ^Call the sqlite3_enable_load_extension() routine with onoff==1
  5290. ** to turn extension loading on and call it with onoff==0 to turn
  5291. ** it back off again.
  5292. */
  5293. SQLITE_API int SQLITE_STDCALL sqlite3_enable_load_extension(sqlite3 *db, int onoff);
  5294. /*
  5295. ** CAPI3REF: Automatically Load Statically Linked Extensions
  5296. **
  5297. ** ^This interface causes the xEntryPoint() function to be invoked for
  5298. ** each new [database connection] that is created. The idea here is that
  5299. ** xEntryPoint() is the entry point for a statically linked [SQLite extension]
  5300. ** that is to be automatically loaded into all new database connections.
  5301. **
  5302. ** ^(Even though the function prototype shows that xEntryPoint() takes
  5303. ** no arguments and returns void, SQLite invokes xEntryPoint() with three
  5304. ** arguments and expects and integer result as if the signature of the
  5305. ** entry point where as follows:
  5306. **
  5307. ** <blockquote><pre>
  5308. ** &nbsp; int xEntryPoint(
  5309. ** &nbsp; sqlite3 *db,
  5310. ** &nbsp; const char **pzErrMsg,
  5311. ** &nbsp; const struct sqlite3_api_routines *pThunk
  5312. ** &nbsp; );
  5313. ** </pre></blockquote>)^
  5314. **
  5315. ** If the xEntryPoint routine encounters an error, it should make *pzErrMsg
  5316. ** point to an appropriate error message (obtained from [sqlite3_mprintf()])
  5317. ** and return an appropriate [error code]. ^SQLite ensures that *pzErrMsg
  5318. ** is NULL before calling the xEntryPoint(). ^SQLite will invoke
  5319. ** [sqlite3_free()] on *pzErrMsg after xEntryPoint() returns. ^If any
  5320. ** xEntryPoint() returns an error, the [sqlite3_open()], [sqlite3_open16()],
  5321. ** or [sqlite3_open_v2()] call that provoked the xEntryPoint() will fail.
  5322. **
  5323. ** ^Calling sqlite3_auto_extension(X) with an entry point X that is already
  5324. ** on the list of automatic extensions is a harmless no-op. ^No entry point
  5325. ** will be called more than once for each database connection that is opened.
  5326. **
  5327. ** See also: [sqlite3_reset_auto_extension()]
  5328. ** and [sqlite3_cancel_auto_extension()]
  5329. */
  5330. SQLITE_API int SQLITE_STDCALL sqlite3_auto_extension(void (*xEntryPoint)(void));
  5331. /*
  5332. ** CAPI3REF: Cancel Automatic Extension Loading
  5333. **
  5334. ** ^The [sqlite3_cancel_auto_extension(X)] interface unregisters the
  5335. ** initialization routine X that was registered using a prior call to
  5336. ** [sqlite3_auto_extension(X)]. ^The [sqlite3_cancel_auto_extension(X)]
  5337. ** routine returns 1 if initialization routine X was successfully
  5338. ** unregistered and it returns 0 if X was not on the list of initialization
  5339. ** routines.
  5340. */
  5341. SQLITE_API int SQLITE_STDCALL sqlite3_cancel_auto_extension(void (*xEntryPoint)(void));
  5342. /*
  5343. ** CAPI3REF: Reset Automatic Extension Loading
  5344. **
  5345. ** ^This interface disables all automatic extensions previously
  5346. ** registered using [sqlite3_auto_extension()].
  5347. */
  5348. SQLITE_API void SQLITE_STDCALL sqlite3_reset_auto_extension(void);
  5349. /*
  5350. ** The interface to the virtual-table mechanism is currently considered
  5351. ** to be experimental. The interface might change in incompatible ways.
  5352. ** If this is a problem for you, do not use the interface at this time.
  5353. **
  5354. ** When the virtual-table mechanism stabilizes, we will declare the
  5355. ** interface fixed, support it indefinitely, and remove this comment.
  5356. */
  5357. /*
  5358. ** Structures used by the virtual table interface
  5359. */
  5360. typedef struct sqlite3_vtab sqlite3_vtab;
  5361. typedef struct sqlite3_index_info sqlite3_index_info;
  5362. typedef struct sqlite3_vtab_cursor sqlite3_vtab_cursor;
  5363. typedef struct sqlite3_module sqlite3_module;
  5364. /*
  5365. ** CAPI3REF: Virtual Table Object
  5366. ** KEYWORDS: sqlite3_module {virtual table module}
  5367. **
  5368. ** This structure, sometimes called a "virtual table module",
  5369. ** defines the implementation of a [virtual tables].
  5370. ** This structure consists mostly of methods for the module.
  5371. **
  5372. ** ^A virtual table module is created by filling in a persistent
  5373. ** instance of this structure and passing a pointer to that instance
  5374. ** to [sqlite3_create_module()] or [sqlite3_create_module_v2()].
  5375. ** ^The registration remains valid until it is replaced by a different
  5376. ** module or until the [database connection] closes. The content
  5377. ** of this structure must not change while it is registered with
  5378. ** any database connection.
  5379. */
  5380. struct sqlite3_module {
  5381. int iVersion;
  5382. int (*xCreate)(sqlite3*, void *pAux,
  5383. int argc, const char *const*argv,
  5384. sqlite3_vtab **ppVTab, char**);
  5385. int (*xConnect)(sqlite3*, void *pAux,
  5386. int argc, const char *const*argv,
  5387. sqlite3_vtab **ppVTab, char**);
  5388. int (*xBestIndex)(sqlite3_vtab *pVTab, sqlite3_index_info*);
  5389. int (*xDisconnect)(sqlite3_vtab *pVTab);
  5390. int (*xDestroy)(sqlite3_vtab *pVTab);
  5391. int (*xOpen)(sqlite3_vtab *pVTab, sqlite3_vtab_cursor **ppCursor);
  5392. int (*xClose)(sqlite3_vtab_cursor*);
  5393. int (*xFilter)(sqlite3_vtab_cursor*, int idxNum, const char *idxStr,
  5394. int argc, sqlite3_value **argv);
  5395. int (*xNext)(sqlite3_vtab_cursor*);
  5396. int (*xEof)(sqlite3_vtab_cursor*);
  5397. int (*xColumn)(sqlite3_vtab_cursor*, sqlite3_context*, int);
  5398. int (*xRowid)(sqlite3_vtab_cursor*, sqlite3_int64 *pRowid);
  5399. int (*xUpdate)(sqlite3_vtab *, int, sqlite3_value **, sqlite3_int64 *);
  5400. int (*xBegin)(sqlite3_vtab *pVTab);
  5401. int (*xSync)(sqlite3_vtab *pVTab);
  5402. int (*xCommit)(sqlite3_vtab *pVTab);
  5403. int (*xRollback)(sqlite3_vtab *pVTab);
  5404. int (*xFindFunction)(sqlite3_vtab *pVtab, int nArg, const char *zName,
  5405. void (**pxFunc)(sqlite3_context*,int,sqlite3_value**),
  5406. void **ppArg);
  5407. int (*xRename)(sqlite3_vtab *pVtab, const char *zNew);
  5408. /* The methods above are in version 1 of the sqlite_module object. Those
  5409. ** below are for version 2 and greater. */
  5410. int (*xSavepoint)(sqlite3_vtab *pVTab, int);
  5411. int (*xRelease)(sqlite3_vtab *pVTab, int);
  5412. int (*xRollbackTo)(sqlite3_vtab *pVTab, int);
  5413. };
  5414. /*
  5415. ** CAPI3REF: Virtual Table Indexing Information
  5416. ** KEYWORDS: sqlite3_index_info
  5417. **
  5418. ** The sqlite3_index_info structure and its substructures is used as part
  5419. ** of the [virtual table] interface to
  5420. ** pass information into and receive the reply from the [xBestIndex]
  5421. ** method of a [virtual table module]. The fields under **Inputs** are the
  5422. ** inputs to xBestIndex and are read-only. xBestIndex inserts its
  5423. ** results into the **Outputs** fields.
  5424. **
  5425. ** ^(The aConstraint[] array records WHERE clause constraints of the form:
  5426. **
  5427. ** <blockquote>column OP expr</blockquote>
  5428. **
  5429. ** where OP is =, &lt;, &lt;=, &gt;, or &gt;=.)^ ^(The particular operator is
  5430. ** stored in aConstraint[].op using one of the
  5431. ** [SQLITE_INDEX_CONSTRAINT_EQ | SQLITE_INDEX_CONSTRAINT_ values].)^
  5432. ** ^(The index of the column is stored in
  5433. ** aConstraint[].iColumn.)^ ^(aConstraint[].usable is TRUE if the
  5434. ** expr on the right-hand side can be evaluated (and thus the constraint
  5435. ** is usable) and false if it cannot.)^
  5436. **
  5437. ** ^The optimizer automatically inverts terms of the form "expr OP column"
  5438. ** and makes other simplifications to the WHERE clause in an attempt to
  5439. ** get as many WHERE clause terms into the form shown above as possible.
  5440. ** ^The aConstraint[] array only reports WHERE clause terms that are
  5441. ** relevant to the particular virtual table being queried.
  5442. **
  5443. ** ^Information about the ORDER BY clause is stored in aOrderBy[].
  5444. ** ^Each term of aOrderBy records a column of the ORDER BY clause.
  5445. **
  5446. ** The [xBestIndex] method must fill aConstraintUsage[] with information
  5447. ** about what parameters to pass to xFilter. ^If argvIndex>0 then
  5448. ** the right-hand side of the corresponding aConstraint[] is evaluated
  5449. ** and becomes the argvIndex-th entry in argv. ^(If aConstraintUsage[].omit
  5450. ** is true, then the constraint is assumed to be fully handled by the
  5451. ** virtual table and is not checked again by SQLite.)^
  5452. **
  5453. ** ^The idxNum and idxPtr values are recorded and passed into the
  5454. ** [xFilter] method.
  5455. ** ^[sqlite3_free()] is used to free idxPtr if and only if
  5456. ** needToFreeIdxPtr is true.
  5457. **
  5458. ** ^The orderByConsumed means that output from [xFilter]/[xNext] will occur in
  5459. ** the correct order to satisfy the ORDER BY clause so that no separate
  5460. ** sorting step is required.
  5461. **
  5462. ** ^The estimatedCost value is an estimate of the cost of a particular
  5463. ** strategy. A cost of N indicates that the cost of the strategy is similar
  5464. ** to a linear scan of an SQLite table with N rows. A cost of log(N)
  5465. ** indicates that the expense of the operation is similar to that of a
  5466. ** binary search on a unique indexed field of an SQLite table with N rows.
  5467. **
  5468. ** ^The estimatedRows value is an estimate of the number of rows that
  5469. ** will be returned by the strategy.
  5470. **
  5471. ** IMPORTANT: The estimatedRows field was added to the sqlite3_index_info
  5472. ** structure for SQLite version 3.8.2. If a virtual table extension is
  5473. ** used with an SQLite version earlier than 3.8.2, the results of attempting
  5474. ** to read or write the estimatedRows field are undefined (but are likely
  5475. ** to included crashing the application). The estimatedRows field should
  5476. ** therefore only be used if [sqlite3_libversion_number()] returns a
  5477. ** value greater than or equal to 3008002.
  5478. */
  5479. struct sqlite3_index_info {
  5480. /* Inputs */
  5481. int nConstraint; /* Number of entries in aConstraint */
  5482. struct sqlite3_index_constraint {
  5483. int iColumn; /* Column on left-hand side of constraint */
  5484. unsigned char op; /* Constraint operator */
  5485. unsigned char usable; /* True if this constraint is usable */
  5486. int iTermOffset; /* Used internally - xBestIndex should ignore */
  5487. } *aConstraint; /* Table of WHERE clause constraints */
  5488. int nOrderBy; /* Number of terms in the ORDER BY clause */
  5489. struct sqlite3_index_orderby {
  5490. int iColumn; /* Column number */
  5491. unsigned char desc; /* True for DESC. False for ASC. */
  5492. } *aOrderBy; /* The ORDER BY clause */
  5493. /* Outputs */
  5494. struct sqlite3_index_constraint_usage {
  5495. int argvIndex; /* if >0, constraint is part of argv to xFilter */
  5496. unsigned char omit; /* Do not code a test for this constraint */
  5497. } *aConstraintUsage;
  5498. int idxNum; /* Number used to identify the index */
  5499. char *idxStr; /* String, possibly obtained from sqlite3_malloc */
  5500. int needToFreeIdxStr; /* Free idxStr using sqlite3_free() if true */
  5501. int orderByConsumed; /* True if output is already ordered */
  5502. double estimatedCost; /* Estimated cost of using this index */
  5503. /* Fields below are only available in SQLite 3.8.2 and later */
  5504. sqlite3_int64 estimatedRows; /* Estimated number of rows returned */
  5505. };
  5506. /*
  5507. ** CAPI3REF: Virtual Table Constraint Operator Codes
  5508. **
  5509. ** These macros defined the allowed values for the
  5510. ** [sqlite3_index_info].aConstraint[].op field. Each value represents
  5511. ** an operator that is part of a constraint term in the wHERE clause of
  5512. ** a query that uses a [virtual table].
  5513. */
  5514. #define SQLITE_INDEX_CONSTRAINT_EQ 2
  5515. #define SQLITE_INDEX_CONSTRAINT_GT 4
  5516. #define SQLITE_INDEX_CONSTRAINT_LE 8
  5517. #define SQLITE_INDEX_CONSTRAINT_LT 16
  5518. #define SQLITE_INDEX_CONSTRAINT_GE 32
  5519. #define SQLITE_INDEX_CONSTRAINT_MATCH 64
  5520. /*
  5521. ** CAPI3REF: Register A Virtual Table Implementation
  5522. ** METHOD: sqlite3
  5523. **
  5524. ** ^These routines are used to register a new [virtual table module] name.
  5525. ** ^Module names must be registered before
  5526. ** creating a new [virtual table] using the module and before using a
  5527. ** preexisting [virtual table] for the module.
  5528. **
  5529. ** ^The module name is registered on the [database connection] specified
  5530. ** by the first parameter. ^The name of the module is given by the
  5531. ** second parameter. ^The third parameter is a pointer to
  5532. ** the implementation of the [virtual table module]. ^The fourth
  5533. ** parameter is an arbitrary client data pointer that is passed through
  5534. ** into the [xCreate] and [xConnect] methods of the virtual table module
  5535. ** when a new virtual table is be being created or reinitialized.
  5536. **
  5537. ** ^The sqlite3_create_module_v2() interface has a fifth parameter which
  5538. ** is a pointer to a destructor for the pClientData. ^SQLite will
  5539. ** invoke the destructor function (if it is not NULL) when SQLite
  5540. ** no longer needs the pClientData pointer. ^The destructor will also
  5541. ** be invoked if the call to sqlite3_create_module_v2() fails.
  5542. ** ^The sqlite3_create_module()
  5543. ** interface is equivalent to sqlite3_create_module_v2() with a NULL
  5544. ** destructor.
  5545. */
  5546. SQLITE_API int SQLITE_STDCALL sqlite3_create_module(
  5547. sqlite3 *db, /* SQLite connection to register module with */
  5548. const char *zName, /* Name of the module */
  5549. const sqlite3_module *p, /* Methods for the module */
  5550. void *pClientData /* Client data for xCreate/xConnect */
  5551. );
  5552. SQLITE_API int SQLITE_STDCALL sqlite3_create_module_v2(
  5553. sqlite3 *db, /* SQLite connection to register module with */
  5554. const char *zName, /* Name of the module */
  5555. const sqlite3_module *p, /* Methods for the module */
  5556. void *pClientData, /* Client data for xCreate/xConnect */
  5557. void(*xDestroy)(void*) /* Module destructor function */
  5558. );
  5559. /*
  5560. ** CAPI3REF: Virtual Table Instance Object
  5561. ** KEYWORDS: sqlite3_vtab
  5562. **
  5563. ** Every [virtual table module] implementation uses a subclass
  5564. ** of this object to describe a particular instance
  5565. ** of the [virtual table]. Each subclass will
  5566. ** be tailored to the specific needs of the module implementation.
  5567. ** The purpose of this superclass is to define certain fields that are
  5568. ** common to all module implementations.
  5569. **
  5570. ** ^Virtual tables methods can set an error message by assigning a
  5571. ** string obtained from [sqlite3_mprintf()] to zErrMsg. The method should
  5572. ** take care that any prior string is freed by a call to [sqlite3_free()]
  5573. ** prior to assigning a new string to zErrMsg. ^After the error message
  5574. ** is delivered up to the client application, the string will be automatically
  5575. ** freed by sqlite3_free() and the zErrMsg field will be zeroed.
  5576. */
  5577. struct sqlite3_vtab {
  5578. const sqlite3_module *pModule; /* The module for this virtual table */
  5579. int nRef; /* Number of open cursors */
  5580. char *zErrMsg; /* Error message from sqlite3_mprintf() */
  5581. /* Virtual table implementations will typically add additional fields */
  5582. };
  5583. /*
  5584. ** CAPI3REF: Virtual Table Cursor Object
  5585. ** KEYWORDS: sqlite3_vtab_cursor {virtual table cursor}
  5586. **
  5587. ** Every [virtual table module] implementation uses a subclass of the
  5588. ** following structure to describe cursors that point into the
  5589. ** [virtual table] and are used
  5590. ** to loop through the virtual table. Cursors are created using the
  5591. ** [sqlite3_module.xOpen | xOpen] method of the module and are destroyed
  5592. ** by the [sqlite3_module.xClose | xClose] method. Cursors are used
  5593. ** by the [xFilter], [xNext], [xEof], [xColumn], and [xRowid] methods
  5594. ** of the module. Each module implementation will define
  5595. ** the content of a cursor structure to suit its own needs.
  5596. **
  5597. ** This superclass exists in order to define fields of the cursor that
  5598. ** are common to all implementations.
  5599. */
  5600. struct sqlite3_vtab_cursor {
  5601. sqlite3_vtab *pVtab; /* Virtual table of this cursor */
  5602. /* Virtual table implementations will typically add additional fields */
  5603. };
  5604. /*
  5605. ** CAPI3REF: Declare The Schema Of A Virtual Table
  5606. **
  5607. ** ^The [xCreate] and [xConnect] methods of a
  5608. ** [virtual table module] call this interface
  5609. ** to declare the format (the names and datatypes of the columns) of
  5610. ** the virtual tables they implement.
  5611. */
  5612. SQLITE_API int SQLITE_STDCALL sqlite3_declare_vtab(sqlite3*, const char *zSQL);
  5613. /*
  5614. ** CAPI3REF: Overload A Function For A Virtual Table
  5615. ** METHOD: sqlite3
  5616. **
  5617. ** ^(Virtual tables can provide alternative implementations of functions
  5618. ** using the [xFindFunction] method of the [virtual table module].
  5619. ** But global versions of those functions
  5620. ** must exist in order to be overloaded.)^
  5621. **
  5622. ** ^(This API makes sure a global version of a function with a particular
  5623. ** name and number of parameters exists. If no such function exists
  5624. ** before this API is called, a new function is created.)^ ^The implementation
  5625. ** of the new function always causes an exception to be thrown. So
  5626. ** the new function is not good for anything by itself. Its only
  5627. ** purpose is to be a placeholder function that can be overloaded
  5628. ** by a [virtual table].
  5629. */
  5630. SQLITE_API int SQLITE_STDCALL sqlite3_overload_function(sqlite3*, const char *zFuncName, int nArg);
  5631. /*
  5632. ** The interface to the virtual-table mechanism defined above (back up
  5633. ** to a comment remarkably similar to this one) is currently considered
  5634. ** to be experimental. The interface might change in incompatible ways.
  5635. ** If this is a problem for you, do not use the interface at this time.
  5636. **
  5637. ** When the virtual-table mechanism stabilizes, we will declare the
  5638. ** interface fixed, support it indefinitely, and remove this comment.
  5639. */
  5640. /*
  5641. ** CAPI3REF: A Handle To An Open BLOB
  5642. ** KEYWORDS: {BLOB handle} {BLOB handles}
  5643. **
  5644. ** An instance of this object represents an open BLOB on which
  5645. ** [sqlite3_blob_open | incremental BLOB I/O] can be performed.
  5646. ** ^Objects of this type are created by [sqlite3_blob_open()]
  5647. ** and destroyed by [sqlite3_blob_close()].
  5648. ** ^The [sqlite3_blob_read()] and [sqlite3_blob_write()] interfaces
  5649. ** can be used to read or write small subsections of the BLOB.
  5650. ** ^The [sqlite3_blob_bytes()] interface returns the size of the BLOB in bytes.
  5651. */
  5652. typedef struct sqlite3_blob sqlite3_blob;
  5653. /*
  5654. ** CAPI3REF: Open A BLOB For Incremental I/O
  5655. ** METHOD: sqlite3
  5656. ** CONSTRUCTOR: sqlite3_blob
  5657. **
  5658. ** ^(This interfaces opens a [BLOB handle | handle] to the BLOB located
  5659. ** in row iRow, column zColumn, table zTable in database zDb;
  5660. ** in other words, the same BLOB that would be selected by:
  5661. **
  5662. ** <pre>
  5663. ** SELECT zColumn FROM zDb.zTable WHERE [rowid] = iRow;
  5664. ** </pre>)^
  5665. **
  5666. ** ^(Parameter zDb is not the filename that contains the database, but
  5667. ** rather the symbolic name of the database. For attached databases, this is
  5668. ** the name that appears after the AS keyword in the [ATTACH] statement.
  5669. ** For the main database file, the database name is "main". For TEMP
  5670. ** tables, the database name is "temp".)^
  5671. **
  5672. ** ^If the flags parameter is non-zero, then the BLOB is opened for read
  5673. ** and write access. ^If the flags parameter is zero, the BLOB is opened for
  5674. ** read-only access.
  5675. **
  5676. ** ^(On success, [SQLITE_OK] is returned and the new [BLOB handle] is stored
  5677. ** in *ppBlob. Otherwise an [error code] is returned and, unless the error
  5678. ** code is SQLITE_MISUSE, *ppBlob is set to NULL.)^ ^This means that, provided
  5679. ** the API is not misused, it is always safe to call [sqlite3_blob_close()]
  5680. ** on *ppBlob after this function it returns.
  5681. **
  5682. ** This function fails with SQLITE_ERROR if any of the following are true:
  5683. ** <ul>
  5684. ** <li> ^(Database zDb does not exist)^,
  5685. ** <li> ^(Table zTable does not exist within database zDb)^,
  5686. ** <li> ^(Table zTable is a WITHOUT ROWID table)^,
  5687. ** <li> ^(Column zColumn does not exist)^,
  5688. ** <li> ^(Row iRow is not present in the table)^,
  5689. ** <li> ^(The specified column of row iRow contains a value that is not
  5690. ** a TEXT or BLOB value)^,
  5691. ** <li> ^(Column zColumn is part of an index, PRIMARY KEY or UNIQUE
  5692. ** constraint and the blob is being opened for read/write access)^,
  5693. ** <li> ^([foreign key constraints | Foreign key constraints] are enabled,
  5694. ** column zColumn is part of a [child key] definition and the blob is
  5695. ** being opened for read/write access)^.
  5696. ** </ul>
  5697. **
  5698. ** ^Unless it returns SQLITE_MISUSE, this function sets the
  5699. ** [database connection] error code and message accessible via
  5700. ** [sqlite3_errcode()] and [sqlite3_errmsg()] and related functions.
  5701. **
  5702. **
  5703. ** ^(If the row that a BLOB handle points to is modified by an
  5704. ** [UPDATE], [DELETE], or by [ON CONFLICT] side-effects
  5705. ** then the BLOB handle is marked as "expired".
  5706. ** This is true if any column of the row is changed, even a column
  5707. ** other than the one the BLOB handle is open on.)^
  5708. ** ^Calls to [sqlite3_blob_read()] and [sqlite3_blob_write()] for
  5709. ** an expired BLOB handle fail with a return code of [SQLITE_ABORT].
  5710. ** ^(Changes written into a BLOB prior to the BLOB expiring are not
  5711. ** rolled back by the expiration of the BLOB. Such changes will eventually
  5712. ** commit if the transaction continues to completion.)^
  5713. **
  5714. ** ^Use the [sqlite3_blob_bytes()] interface to determine the size of
  5715. ** the opened blob. ^The size of a blob may not be changed by this
  5716. ** interface. Use the [UPDATE] SQL command to change the size of a
  5717. ** blob.
  5718. **
  5719. ** ^The [sqlite3_bind_zeroblob()] and [sqlite3_result_zeroblob()] interfaces
  5720. ** and the built-in [zeroblob] SQL function may be used to create a
  5721. ** zero-filled blob to read or write using the incremental-blob interface.
  5722. **
  5723. ** To avoid a resource leak, every open [BLOB handle] should eventually
  5724. ** be released by a call to [sqlite3_blob_close()].
  5725. */
  5726. SQLITE_API int SQLITE_STDCALL sqlite3_blob_open(
  5727. sqlite3*,
  5728. const char *zDb,
  5729. const char *zTable,
  5730. const char *zColumn,
  5731. sqlite3_int64 iRow,
  5732. int flags,
  5733. sqlite3_blob **ppBlob
  5734. );
  5735. /*
  5736. ** CAPI3REF: Move a BLOB Handle to a New Row
  5737. ** METHOD: sqlite3_blob
  5738. **
  5739. ** ^This function is used to move an existing blob handle so that it points
  5740. ** to a different row of the same database table. ^The new row is identified
  5741. ** by the rowid value passed as the second argument. Only the row can be
  5742. ** changed. ^The database, table and column on which the blob handle is open
  5743. ** remain the same. Moving an existing blob handle to a new row can be
  5744. ** faster than closing the existing handle and opening a new one.
  5745. **
  5746. ** ^(The new row must meet the same criteria as for [sqlite3_blob_open()] -
  5747. ** it must exist and there must be either a blob or text value stored in
  5748. ** the nominated column.)^ ^If the new row is not present in the table, or if
  5749. ** it does not contain a blob or text value, or if another error occurs, an
  5750. ** SQLite error code is returned and the blob handle is considered aborted.
  5751. ** ^All subsequent calls to [sqlite3_blob_read()], [sqlite3_blob_write()] or
  5752. ** [sqlite3_blob_reopen()] on an aborted blob handle immediately return
  5753. ** SQLITE_ABORT. ^Calling [sqlite3_blob_bytes()] on an aborted blob handle
  5754. ** always returns zero.
  5755. **
  5756. ** ^This function sets the database handle error code and message.
  5757. */
  5758. SQLITE_API int SQLITE_STDCALL sqlite3_blob_reopen(sqlite3_blob *, sqlite3_int64);
  5759. /*
  5760. ** CAPI3REF: Close A BLOB Handle
  5761. ** DESTRUCTOR: sqlite3_blob
  5762. **
  5763. ** ^This function closes an open [BLOB handle]. ^(The BLOB handle is closed
  5764. ** unconditionally. Even if this routine returns an error code, the
  5765. ** handle is still closed.)^
  5766. **
  5767. ** ^If the blob handle being closed was opened for read-write access, and if
  5768. ** the database is in auto-commit mode and there are no other open read-write
  5769. ** blob handles or active write statements, the current transaction is
  5770. ** committed. ^If an error occurs while committing the transaction, an error
  5771. ** code is returned and the transaction rolled back.
  5772. **
  5773. ** Calling this function with an argument that is not a NULL pointer or an
  5774. ** open blob handle results in undefined behaviour. ^Calling this routine
  5775. ** with a null pointer (such as would be returned by a failed call to
  5776. ** [sqlite3_blob_open()]) is a harmless no-op. ^Otherwise, if this function
  5777. ** is passed a valid open blob handle, the values returned by the
  5778. ** sqlite3_errcode() and sqlite3_errmsg() functions are set before returning.
  5779. */
  5780. SQLITE_API int SQLITE_STDCALL sqlite3_blob_close(sqlite3_blob *);
  5781. /*
  5782. ** CAPI3REF: Return The Size Of An Open BLOB
  5783. ** METHOD: sqlite3_blob
  5784. **
  5785. ** ^Returns the size in bytes of the BLOB accessible via the
  5786. ** successfully opened [BLOB handle] in its only argument. ^The
  5787. ** incremental blob I/O routines can only read or overwriting existing
  5788. ** blob content; they cannot change the size of a blob.
  5789. **
  5790. ** This routine only works on a [BLOB handle] which has been created
  5791. ** by a prior successful call to [sqlite3_blob_open()] and which has not
  5792. ** been closed by [sqlite3_blob_close()]. Passing any other pointer in
  5793. ** to this routine results in undefined and probably undesirable behavior.
  5794. */
  5795. SQLITE_API int SQLITE_STDCALL sqlite3_blob_bytes(sqlite3_blob *);
  5796. /*
  5797. ** CAPI3REF: Read Data From A BLOB Incrementally
  5798. ** METHOD: sqlite3_blob
  5799. **
  5800. ** ^(This function is used to read data from an open [BLOB handle] into a
  5801. ** caller-supplied buffer. N bytes of data are copied into buffer Z
  5802. ** from the open BLOB, starting at offset iOffset.)^
  5803. **
  5804. ** ^If offset iOffset is less than N bytes from the end of the BLOB,
  5805. ** [SQLITE_ERROR] is returned and no data is read. ^If N or iOffset is
  5806. ** less than zero, [SQLITE_ERROR] is returned and no data is read.
  5807. ** ^The size of the blob (and hence the maximum value of N+iOffset)
  5808. ** can be determined using the [sqlite3_blob_bytes()] interface.
  5809. **
  5810. ** ^An attempt to read from an expired [BLOB handle] fails with an
  5811. ** error code of [SQLITE_ABORT].
  5812. **
  5813. ** ^(On success, sqlite3_blob_read() returns SQLITE_OK.
  5814. ** Otherwise, an [error code] or an [extended error code] is returned.)^
  5815. **
  5816. ** This routine only works on a [BLOB handle] which has been created
  5817. ** by a prior successful call to [sqlite3_blob_open()] and which has not
  5818. ** been closed by [sqlite3_blob_close()]. Passing any other pointer in
  5819. ** to this routine results in undefined and probably undesirable behavior.
  5820. **
  5821. ** See also: [sqlite3_blob_write()].
  5822. */
  5823. SQLITE_API int SQLITE_STDCALL sqlite3_blob_read(sqlite3_blob *, void *Z, int N, int iOffset);
  5824. /*
  5825. ** CAPI3REF: Write Data Into A BLOB Incrementally
  5826. ** METHOD: sqlite3_blob
  5827. **
  5828. ** ^(This function is used to write data into an open [BLOB handle] from a
  5829. ** caller-supplied buffer. N bytes of data are copied from the buffer Z
  5830. ** into the open BLOB, starting at offset iOffset.)^
  5831. **
  5832. ** ^(On success, sqlite3_blob_write() returns SQLITE_OK.
  5833. ** Otherwise, an [error code] or an [extended error code] is returned.)^
  5834. ** ^Unless SQLITE_MISUSE is returned, this function sets the
  5835. ** [database connection] error code and message accessible via
  5836. ** [sqlite3_errcode()] and [sqlite3_errmsg()] and related functions.
  5837. **
  5838. ** ^If the [BLOB handle] passed as the first argument was not opened for
  5839. ** writing (the flags parameter to [sqlite3_blob_open()] was zero),
  5840. ** this function returns [SQLITE_READONLY].
  5841. **
  5842. ** This function may only modify the contents of the BLOB; it is
  5843. ** not possible to increase the size of a BLOB using this API.
  5844. ** ^If offset iOffset is less than N bytes from the end of the BLOB,
  5845. ** [SQLITE_ERROR] is returned and no data is written. The size of the
  5846. ** BLOB (and hence the maximum value of N+iOffset) can be determined
  5847. ** using the [sqlite3_blob_bytes()] interface. ^If N or iOffset are less
  5848. ** than zero [SQLITE_ERROR] is returned and no data is written.
  5849. **
  5850. ** ^An attempt to write to an expired [BLOB handle] fails with an
  5851. ** error code of [SQLITE_ABORT]. ^Writes to the BLOB that occurred
  5852. ** before the [BLOB handle] expired are not rolled back by the
  5853. ** expiration of the handle, though of course those changes might
  5854. ** have been overwritten by the statement that expired the BLOB handle
  5855. ** or by other independent statements.
  5856. **
  5857. ** This routine only works on a [BLOB handle] which has been created
  5858. ** by a prior successful call to [sqlite3_blob_open()] and which has not
  5859. ** been closed by [sqlite3_blob_close()]. Passing any other pointer in
  5860. ** to this routine results in undefined and probably undesirable behavior.
  5861. **
  5862. ** See also: [sqlite3_blob_read()].
  5863. */
  5864. SQLITE_API int SQLITE_STDCALL sqlite3_blob_write(sqlite3_blob *, const void *z, int n, int iOffset);
  5865. /*
  5866. ** CAPI3REF: Virtual File System Objects
  5867. **
  5868. ** A virtual filesystem (VFS) is an [sqlite3_vfs] object
  5869. ** that SQLite uses to interact
  5870. ** with the underlying operating system. Most SQLite builds come with a
  5871. ** single default VFS that is appropriate for the host computer.
  5872. ** New VFSes can be registered and existing VFSes can be unregistered.
  5873. ** The following interfaces are provided.
  5874. **
  5875. ** ^The sqlite3_vfs_find() interface returns a pointer to a VFS given its name.
  5876. ** ^Names are case sensitive.
  5877. ** ^Names are zero-terminated UTF-8 strings.
  5878. ** ^If there is no match, a NULL pointer is returned.
  5879. ** ^If zVfsName is NULL then the default VFS is returned.
  5880. **
  5881. ** ^New VFSes are registered with sqlite3_vfs_register().
  5882. ** ^Each new VFS becomes the default VFS if the makeDflt flag is set.
  5883. ** ^The same VFS can be registered multiple times without injury.
  5884. ** ^To make an existing VFS into the default VFS, register it again
  5885. ** with the makeDflt flag set. If two different VFSes with the
  5886. ** same name are registered, the behavior is undefined. If a
  5887. ** VFS is registered with a name that is NULL or an empty string,
  5888. ** then the behavior is undefined.
  5889. **
  5890. ** ^Unregister a VFS with the sqlite3_vfs_unregister() interface.
  5891. ** ^(If the default VFS is unregistered, another VFS is chosen as
  5892. ** the default. The choice for the new VFS is arbitrary.)^
  5893. */
  5894. SQLITE_API sqlite3_vfs *SQLITE_STDCALL sqlite3_vfs_find(const char *zVfsName);
  5895. SQLITE_API int SQLITE_STDCALL sqlite3_vfs_register(sqlite3_vfs*, int makeDflt);
  5896. SQLITE_API int SQLITE_STDCALL sqlite3_vfs_unregister(sqlite3_vfs*);
  5897. /*
  5898. ** CAPI3REF: Mutexes
  5899. **
  5900. ** The SQLite core uses these routines for thread
  5901. ** synchronization. Though they are intended for internal
  5902. ** use by SQLite, code that links against SQLite is
  5903. ** permitted to use any of these routines.
  5904. **
  5905. ** The SQLite source code contains multiple implementations
  5906. ** of these mutex routines. An appropriate implementation
  5907. ** is selected automatically at compile-time. The following
  5908. ** implementations are available in the SQLite core:
  5909. **
  5910. ** <ul>
  5911. ** <li> SQLITE_MUTEX_PTHREADS
  5912. ** <li> SQLITE_MUTEX_W32
  5913. ** <li> SQLITE_MUTEX_NOOP
  5914. ** </ul>
  5915. **
  5916. ** The SQLITE_MUTEX_NOOP implementation is a set of routines
  5917. ** that does no real locking and is appropriate for use in
  5918. ** a single-threaded application. The SQLITE_MUTEX_PTHREADS and
  5919. ** SQLITE_MUTEX_W32 implementations are appropriate for use on Unix
  5920. ** and Windows.
  5921. **
  5922. ** If SQLite is compiled with the SQLITE_MUTEX_APPDEF preprocessor
  5923. ** macro defined (with "-DSQLITE_MUTEX_APPDEF=1"), then no mutex
  5924. ** implementation is included with the library. In this case the
  5925. ** application must supply a custom mutex implementation using the
  5926. ** [SQLITE_CONFIG_MUTEX] option of the sqlite3_config() function
  5927. ** before calling sqlite3_initialize() or any other public sqlite3_
  5928. ** function that calls sqlite3_initialize().
  5929. **
  5930. ** ^The sqlite3_mutex_alloc() routine allocates a new
  5931. ** mutex and returns a pointer to it. ^The sqlite3_mutex_alloc()
  5932. ** routine returns NULL if it is unable to allocate the requested
  5933. ** mutex. The argument to sqlite3_mutex_alloc() must one of these
  5934. ** integer constants:
  5935. **
  5936. ** <ul>
  5937. ** <li> SQLITE_MUTEX_FAST
  5938. ** <li> SQLITE_MUTEX_RECURSIVE
  5939. ** <li> SQLITE_MUTEX_STATIC_MASTER
  5940. ** <li> SQLITE_MUTEX_STATIC_MEM
  5941. ** <li> SQLITE_MUTEX_STATIC_OPEN
  5942. ** <li> SQLITE_MUTEX_STATIC_PRNG
  5943. ** <li> SQLITE_MUTEX_STATIC_LRU
  5944. ** <li> SQLITE_MUTEX_STATIC_PMEM
  5945. ** <li> SQLITE_MUTEX_STATIC_APP1
  5946. ** <li> SQLITE_MUTEX_STATIC_APP2
  5947. ** <li> SQLITE_MUTEX_STATIC_APP3
  5948. ** </ul>
  5949. **
  5950. ** ^The first two constants (SQLITE_MUTEX_FAST and SQLITE_MUTEX_RECURSIVE)
  5951. ** cause sqlite3_mutex_alloc() to create
  5952. ** a new mutex. ^The new mutex is recursive when SQLITE_MUTEX_RECURSIVE
  5953. ** is used but not necessarily so when SQLITE_MUTEX_FAST is used.
  5954. ** The mutex implementation does not need to make a distinction
  5955. ** between SQLITE_MUTEX_RECURSIVE and SQLITE_MUTEX_FAST if it does
  5956. ** not want to. SQLite will only request a recursive mutex in
  5957. ** cases where it really needs one. If a faster non-recursive mutex
  5958. ** implementation is available on the host platform, the mutex subsystem
  5959. ** might return such a mutex in response to SQLITE_MUTEX_FAST.
  5960. **
  5961. ** ^The other allowed parameters to sqlite3_mutex_alloc() (anything other
  5962. ** than SQLITE_MUTEX_FAST and SQLITE_MUTEX_RECURSIVE) each return
  5963. ** a pointer to a static preexisting mutex. ^Nine static mutexes are
  5964. ** used by the current version of SQLite. Future versions of SQLite
  5965. ** may add additional static mutexes. Static mutexes are for internal
  5966. ** use by SQLite only. Applications that use SQLite mutexes should
  5967. ** use only the dynamic mutexes returned by SQLITE_MUTEX_FAST or
  5968. ** SQLITE_MUTEX_RECURSIVE.
  5969. **
  5970. ** ^Note that if one of the dynamic mutex parameters (SQLITE_MUTEX_FAST
  5971. ** or SQLITE_MUTEX_RECURSIVE) is used then sqlite3_mutex_alloc()
  5972. ** returns a different mutex on every call. ^For the static
  5973. ** mutex types, the same mutex is returned on every call that has
  5974. ** the same type number.
  5975. **
  5976. ** ^The sqlite3_mutex_free() routine deallocates a previously
  5977. ** allocated dynamic mutex. Attempting to deallocate a static
  5978. ** mutex results in undefined behavior.
  5979. **
  5980. ** ^The sqlite3_mutex_enter() and sqlite3_mutex_try() routines attempt
  5981. ** to enter a mutex. ^If another thread is already within the mutex,
  5982. ** sqlite3_mutex_enter() will block and sqlite3_mutex_try() will return
  5983. ** SQLITE_BUSY. ^The sqlite3_mutex_try() interface returns [SQLITE_OK]
  5984. ** upon successful entry. ^(Mutexes created using
  5985. ** SQLITE_MUTEX_RECURSIVE can be entered multiple times by the same thread.
  5986. ** In such cases, the
  5987. ** mutex must be exited an equal number of times before another thread
  5988. ** can enter.)^ If the same thread tries to enter any mutex other
  5989. ** than an SQLITE_MUTEX_RECURSIVE more than once, the behavior is undefined.
  5990. **
  5991. ** ^(Some systems (for example, Windows 95) do not support the operation
  5992. ** implemented by sqlite3_mutex_try(). On those systems, sqlite3_mutex_try()
  5993. ** will always return SQLITE_BUSY. The SQLite core only ever uses
  5994. ** sqlite3_mutex_try() as an optimization so this is acceptable
  5995. ** behavior.)^
  5996. **
  5997. ** ^The sqlite3_mutex_leave() routine exits a mutex that was
  5998. ** previously entered by the same thread. The behavior
  5999. ** is undefined if the mutex is not currently entered by the
  6000. ** calling thread or is not currently allocated.
  6001. **
  6002. ** ^If the argument to sqlite3_mutex_enter(), sqlite3_mutex_try(), or
  6003. ** sqlite3_mutex_leave() is a NULL pointer, then all three routines
  6004. ** behave as no-ops.
  6005. **
  6006. ** See also: [sqlite3_mutex_held()] and [sqlite3_mutex_notheld()].
  6007. */
  6008. SQLITE_API sqlite3_mutex *SQLITE_STDCALL sqlite3_mutex_alloc(int);
  6009. SQLITE_API void SQLITE_STDCALL sqlite3_mutex_free(sqlite3_mutex*);
  6010. SQLITE_API void SQLITE_STDCALL sqlite3_mutex_enter(sqlite3_mutex*);
  6011. SQLITE_API int SQLITE_STDCALL sqlite3_mutex_try(sqlite3_mutex*);
  6012. SQLITE_API void SQLITE_STDCALL sqlite3_mutex_leave(sqlite3_mutex*);
  6013. /*
  6014. ** CAPI3REF: Mutex Methods Object
  6015. **
  6016. ** An instance of this structure defines the low-level routines
  6017. ** used to allocate and use mutexes.
  6018. **
  6019. ** Usually, the default mutex implementations provided by SQLite are
  6020. ** sufficient, however the application has the option of substituting a custom
  6021. ** implementation for specialized deployments or systems for which SQLite
  6022. ** does not provide a suitable implementation. In this case, the application
  6023. ** creates and populates an instance of this structure to pass
  6024. ** to sqlite3_config() along with the [SQLITE_CONFIG_MUTEX] option.
  6025. ** Additionally, an instance of this structure can be used as an
  6026. ** output variable when querying the system for the current mutex
  6027. ** implementation, using the [SQLITE_CONFIG_GETMUTEX] option.
  6028. **
  6029. ** ^The xMutexInit method defined by this structure is invoked as
  6030. ** part of system initialization by the sqlite3_initialize() function.
  6031. ** ^The xMutexInit routine is called by SQLite exactly once for each
  6032. ** effective call to [sqlite3_initialize()].
  6033. **
  6034. ** ^The xMutexEnd method defined by this structure is invoked as
  6035. ** part of system shutdown by the sqlite3_shutdown() function. The
  6036. ** implementation of this method is expected to release all outstanding
  6037. ** resources obtained by the mutex methods implementation, especially
  6038. ** those obtained by the xMutexInit method. ^The xMutexEnd()
  6039. ** interface is invoked exactly once for each call to [sqlite3_shutdown()].
  6040. **
  6041. ** ^(The remaining seven methods defined by this structure (xMutexAlloc,
  6042. ** xMutexFree, xMutexEnter, xMutexTry, xMutexLeave, xMutexHeld and
  6043. ** xMutexNotheld) implement the following interfaces (respectively):
  6044. **
  6045. ** <ul>
  6046. ** <li> [sqlite3_mutex_alloc()] </li>
  6047. ** <li> [sqlite3_mutex_free()] </li>
  6048. ** <li> [sqlite3_mutex_enter()] </li>
  6049. ** <li> [sqlite3_mutex_try()] </li>
  6050. ** <li> [sqlite3_mutex_leave()] </li>
  6051. ** <li> [sqlite3_mutex_held()] </li>
  6052. ** <li> [sqlite3_mutex_notheld()] </li>
  6053. ** </ul>)^
  6054. **
  6055. ** The only difference is that the public sqlite3_XXX functions enumerated
  6056. ** above silently ignore any invocations that pass a NULL pointer instead
  6057. ** of a valid mutex handle. The implementations of the methods defined
  6058. ** by this structure are not required to handle this case, the results
  6059. ** of passing a NULL pointer instead of a valid mutex handle are undefined
  6060. ** (i.e. it is acceptable to provide an implementation that segfaults if
  6061. ** it is passed a NULL pointer).
  6062. **
  6063. ** The xMutexInit() method must be threadsafe. It must be harmless to
  6064. ** invoke xMutexInit() multiple times within the same process and without
  6065. ** intervening calls to xMutexEnd(). Second and subsequent calls to
  6066. ** xMutexInit() must be no-ops.
  6067. **
  6068. ** xMutexInit() must not use SQLite memory allocation ([sqlite3_malloc()]
  6069. ** and its associates). Similarly, xMutexAlloc() must not use SQLite memory
  6070. ** allocation for a static mutex. ^However xMutexAlloc() may use SQLite
  6071. ** memory allocation for a fast or recursive mutex.
  6072. **
  6073. ** ^SQLite will invoke the xMutexEnd() method when [sqlite3_shutdown()] is
  6074. ** called, but only if the prior call to xMutexInit returned SQLITE_OK.
  6075. ** If xMutexInit fails in any way, it is expected to clean up after itself
  6076. ** prior to returning.
  6077. */
  6078. typedef struct sqlite3_mutex_methods sqlite3_mutex_methods;
  6079. struct sqlite3_mutex_methods {
  6080. int (*xMutexInit)(void);
  6081. int (*xMutexEnd)(void);
  6082. sqlite3_mutex *(*xMutexAlloc)(int);
  6083. void (*xMutexFree)(sqlite3_mutex *);
  6084. void (*xMutexEnter)(sqlite3_mutex *);
  6085. int (*xMutexTry)(sqlite3_mutex *);
  6086. void (*xMutexLeave)(sqlite3_mutex *);
  6087. int (*xMutexHeld)(sqlite3_mutex *);
  6088. int (*xMutexNotheld)(sqlite3_mutex *);
  6089. };
  6090. /*
  6091. ** CAPI3REF: Mutex Verification Routines
  6092. **
  6093. ** The sqlite3_mutex_held() and sqlite3_mutex_notheld() routines
  6094. ** are intended for use inside assert() statements. The SQLite core
  6095. ** never uses these routines except inside an assert() and applications
  6096. ** are advised to follow the lead of the core. The SQLite core only
  6097. ** provides implementations for these routines when it is compiled
  6098. ** with the SQLITE_DEBUG flag. External mutex implementations
  6099. ** are only required to provide these routines if SQLITE_DEBUG is
  6100. ** defined and if NDEBUG is not defined.
  6101. **
  6102. ** These routines should return true if the mutex in their argument
  6103. ** is held or not held, respectively, by the calling thread.
  6104. **
  6105. ** The implementation is not required to provide versions of these
  6106. ** routines that actually work. If the implementation does not provide working
  6107. ** versions of these routines, it should at least provide stubs that always
  6108. ** return true so that one does not get spurious assertion failures.
  6109. **
  6110. ** If the argument to sqlite3_mutex_held() is a NULL pointer then
  6111. ** the routine should return 1. This seems counter-intuitive since
  6112. ** clearly the mutex cannot be held if it does not exist. But
  6113. ** the reason the mutex does not exist is because the build is not
  6114. ** using mutexes. And we do not want the assert() containing the
  6115. ** call to sqlite3_mutex_held() to fail, so a non-zero return is
  6116. ** the appropriate thing to do. The sqlite3_mutex_notheld()
  6117. ** interface should also return 1 when given a NULL pointer.
  6118. */
  6119. #ifndef NDEBUG
  6120. SQLITE_API int SQLITE_STDCALL sqlite3_mutex_held(sqlite3_mutex*);
  6121. SQLITE_API int SQLITE_STDCALL sqlite3_mutex_notheld(sqlite3_mutex*);
  6122. #endif
  6123. /*
  6124. ** CAPI3REF: Mutex Types
  6125. **
  6126. ** The [sqlite3_mutex_alloc()] interface takes a single argument
  6127. ** which is one of these integer constants.
  6128. **
  6129. ** The set of static mutexes may change from one SQLite release to the
  6130. ** next. Applications that override the built-in mutex logic must be
  6131. ** prepared to accommodate additional static mutexes.
  6132. */
  6133. #define SQLITE_MUTEX_FAST 0
  6134. #define SQLITE_MUTEX_RECURSIVE 1
  6135. #define SQLITE_MUTEX_STATIC_MASTER 2
  6136. #define SQLITE_MUTEX_STATIC_MEM 3 /* sqlite3_malloc() */
  6137. #define SQLITE_MUTEX_STATIC_MEM2 4 /* NOT USED */
  6138. #define SQLITE_MUTEX_STATIC_OPEN 4 /* sqlite3BtreeOpen() */
  6139. #define SQLITE_MUTEX_STATIC_PRNG 5 /* sqlite3_random() */
  6140. #define SQLITE_MUTEX_STATIC_LRU 6 /* lru page list */
  6141. #define SQLITE_MUTEX_STATIC_LRU2 7 /* NOT USED */
  6142. #define SQLITE_MUTEX_STATIC_PMEM 7 /* sqlite3PageMalloc() */
  6143. #define SQLITE_MUTEX_STATIC_APP1 8 /* For use by application */
  6144. #define SQLITE_MUTEX_STATIC_APP2 9 /* For use by application */
  6145. #define SQLITE_MUTEX_STATIC_APP3 10 /* For use by application */
  6146. #define SQLITE_MUTEX_STATIC_VFS1 11 /* For use by built-in VFS */
  6147. #define SQLITE_MUTEX_STATIC_VFS2 12 /* For use by extension VFS */
  6148. #define SQLITE_MUTEX_STATIC_VFS3 13 /* For use by application VFS */
  6149. /*
  6150. ** CAPI3REF: Retrieve the mutex for a database connection
  6151. ** METHOD: sqlite3
  6152. **
  6153. ** ^This interface returns a pointer the [sqlite3_mutex] object that
  6154. ** serializes access to the [database connection] given in the argument
  6155. ** when the [threading mode] is Serialized.
  6156. ** ^If the [threading mode] is Single-thread or Multi-thread then this
  6157. ** routine returns a NULL pointer.
  6158. */
  6159. SQLITE_API sqlite3_mutex *SQLITE_STDCALL sqlite3_db_mutex(sqlite3*);
  6160. /*
  6161. ** CAPI3REF: Low-Level Control Of Database Files
  6162. ** METHOD: sqlite3
  6163. **
  6164. ** ^The [sqlite3_file_control()] interface makes a direct call to the
  6165. ** xFileControl method for the [sqlite3_io_methods] object associated
  6166. ** with a particular database identified by the second argument. ^The
  6167. ** name of the database is "main" for the main database or "temp" for the
  6168. ** TEMP database, or the name that appears after the AS keyword for
  6169. ** databases that are added using the [ATTACH] SQL command.
  6170. ** ^A NULL pointer can be used in place of "main" to refer to the
  6171. ** main database file.
  6172. ** ^The third and fourth parameters to this routine
  6173. ** are passed directly through to the second and third parameters of
  6174. ** the xFileControl method. ^The return value of the xFileControl
  6175. ** method becomes the return value of this routine.
  6176. **
  6177. ** ^The SQLITE_FCNTL_FILE_POINTER value for the op parameter causes
  6178. ** a pointer to the underlying [sqlite3_file] object to be written into
  6179. ** the space pointed to by the 4th parameter. ^The SQLITE_FCNTL_FILE_POINTER
  6180. ** case is a short-circuit path which does not actually invoke the
  6181. ** underlying sqlite3_io_methods.xFileControl method.
  6182. **
  6183. ** ^If the second parameter (zDbName) does not match the name of any
  6184. ** open database file, then SQLITE_ERROR is returned. ^This error
  6185. ** code is not remembered and will not be recalled by [sqlite3_errcode()]
  6186. ** or [sqlite3_errmsg()]. The underlying xFileControl method might
  6187. ** also return SQLITE_ERROR. There is no way to distinguish between
  6188. ** an incorrect zDbName and an SQLITE_ERROR return from the underlying
  6189. ** xFileControl method.
  6190. **
  6191. ** See also: [SQLITE_FCNTL_LOCKSTATE]
  6192. */
  6193. SQLITE_API int SQLITE_STDCALL sqlite3_file_control(sqlite3*, const char *zDbName, int op, void*);
  6194. /*
  6195. ** CAPI3REF: Testing Interface
  6196. **
  6197. ** ^The sqlite3_test_control() interface is used to read out internal
  6198. ** state of SQLite and to inject faults into SQLite for testing
  6199. ** purposes. ^The first parameter is an operation code that determines
  6200. ** the number, meaning, and operation of all subsequent parameters.
  6201. **
  6202. ** This interface is not for use by applications. It exists solely
  6203. ** for verifying the correct operation of the SQLite library. Depending
  6204. ** on how the SQLite library is compiled, this interface might not exist.
  6205. **
  6206. ** The details of the operation codes, their meanings, the parameters
  6207. ** they take, and what they do are all subject to change without notice.
  6208. ** Unlike most of the SQLite API, this function is not guaranteed to
  6209. ** operate consistently from one release to the next.
  6210. */
  6211. SQLITE_API int SQLITE_CDECL sqlite3_test_control(int op, ...);
  6212. /*
  6213. ** CAPI3REF: Testing Interface Operation Codes
  6214. **
  6215. ** These constants are the valid operation code parameters used
  6216. ** as the first argument to [sqlite3_test_control()].
  6217. **
  6218. ** These parameters and their meanings are subject to change
  6219. ** without notice. These values are for testing purposes only.
  6220. ** Applications should not use any of these parameters or the
  6221. ** [sqlite3_test_control()] interface.
  6222. */
  6223. #define SQLITE_TESTCTRL_FIRST 5
  6224. #define SQLITE_TESTCTRL_PRNG_SAVE 5
  6225. #define SQLITE_TESTCTRL_PRNG_RESTORE 6
  6226. #define SQLITE_TESTCTRL_PRNG_RESET 7
  6227. #define SQLITE_TESTCTRL_BITVEC_TEST 8
  6228. #define SQLITE_TESTCTRL_FAULT_INSTALL 9
  6229. #define SQLITE_TESTCTRL_BENIGN_MALLOC_HOOKS 10
  6230. #define SQLITE_TESTCTRL_PENDING_BYTE 11
  6231. #define SQLITE_TESTCTRL_ASSERT 12
  6232. #define SQLITE_TESTCTRL_ALWAYS 13
  6233. #define SQLITE_TESTCTRL_RESERVE 14
  6234. #define SQLITE_TESTCTRL_OPTIMIZATIONS 15
  6235. #define SQLITE_TESTCTRL_ISKEYWORD 16
  6236. #define SQLITE_TESTCTRL_SCRATCHMALLOC 17
  6237. #define SQLITE_TESTCTRL_LOCALTIME_FAULT 18
  6238. #define SQLITE_TESTCTRL_EXPLAIN_STMT 19 /* NOT USED */
  6239. #define SQLITE_TESTCTRL_NEVER_CORRUPT 20
  6240. #define SQLITE_TESTCTRL_VDBE_COVERAGE 21
  6241. #define SQLITE_TESTCTRL_BYTEORDER 22
  6242. #define SQLITE_TESTCTRL_ISINIT 23
  6243. #define SQLITE_TESTCTRL_SORTER_MMAP 24
  6244. #define SQLITE_TESTCTRL_IMPOSTER 25
  6245. #define SQLITE_TESTCTRL_LAST 25
  6246. /*
  6247. ** CAPI3REF: SQLite Runtime Status
  6248. **
  6249. ** ^These interfaces are used to retrieve runtime status information
  6250. ** about the performance of SQLite, and optionally to reset various
  6251. ** highwater marks. ^The first argument is an integer code for
  6252. ** the specific parameter to measure. ^(Recognized integer codes
  6253. ** are of the form [status parameters | SQLITE_STATUS_...].)^
  6254. ** ^The current value of the parameter is returned into *pCurrent.
  6255. ** ^The highest recorded value is returned in *pHighwater. ^If the
  6256. ** resetFlag is true, then the highest record value is reset after
  6257. ** *pHighwater is written. ^(Some parameters do not record the highest
  6258. ** value. For those parameters
  6259. ** nothing is written into *pHighwater and the resetFlag is ignored.)^
  6260. ** ^(Other parameters record only the highwater mark and not the current
  6261. ** value. For these latter parameters nothing is written into *pCurrent.)^
  6262. **
  6263. ** ^The sqlite3_status() and sqlite3_status64() routines return
  6264. ** SQLITE_OK on success and a non-zero [error code] on failure.
  6265. **
  6266. ** If either the current value or the highwater mark is too large to
  6267. ** be represented by a 32-bit integer, then the values returned by
  6268. ** sqlite3_status() are undefined.
  6269. **
  6270. ** See also: [sqlite3_db_status()]
  6271. */
  6272. SQLITE_API int SQLITE_STDCALL sqlite3_status(int op, int *pCurrent, int *pHighwater, int resetFlag);
  6273. SQLITE_API int SQLITE_STDCALL sqlite3_status64(
  6274. int op,
  6275. sqlite3_int64 *pCurrent,
  6276. sqlite3_int64 *pHighwater,
  6277. int resetFlag
  6278. );
  6279. /*
  6280. ** CAPI3REF: Status Parameters
  6281. ** KEYWORDS: {status parameters}
  6282. **
  6283. ** These integer constants designate various run-time status parameters
  6284. ** that can be returned by [sqlite3_status()].
  6285. **
  6286. ** <dl>
  6287. ** [[SQLITE_STATUS_MEMORY_USED]] ^(<dt>SQLITE_STATUS_MEMORY_USED</dt>
  6288. ** <dd>This parameter is the current amount of memory checked out
  6289. ** using [sqlite3_malloc()], either directly or indirectly. The
  6290. ** figure includes calls made to [sqlite3_malloc()] by the application
  6291. ** and internal memory usage by the SQLite library. Scratch memory
  6292. ** controlled by [SQLITE_CONFIG_SCRATCH] and auxiliary page-cache
  6293. ** memory controlled by [SQLITE_CONFIG_PAGECACHE] is not included in
  6294. ** this parameter. The amount returned is the sum of the allocation
  6295. ** sizes as reported by the xSize method in [sqlite3_mem_methods].</dd>)^
  6296. **
  6297. ** [[SQLITE_STATUS_MALLOC_SIZE]] ^(<dt>SQLITE_STATUS_MALLOC_SIZE</dt>
  6298. ** <dd>This parameter records the largest memory allocation request
  6299. ** handed to [sqlite3_malloc()] or [sqlite3_realloc()] (or their
  6300. ** internal equivalents). Only the value returned in the
  6301. ** *pHighwater parameter to [sqlite3_status()] is of interest.
  6302. ** The value written into the *pCurrent parameter is undefined.</dd>)^
  6303. **
  6304. ** [[SQLITE_STATUS_MALLOC_COUNT]] ^(<dt>SQLITE_STATUS_MALLOC_COUNT</dt>
  6305. ** <dd>This parameter records the number of separate memory allocations
  6306. ** currently checked out.</dd>)^
  6307. **
  6308. ** [[SQLITE_STATUS_PAGECACHE_USED]] ^(<dt>SQLITE_STATUS_PAGECACHE_USED</dt>
  6309. ** <dd>This parameter returns the number of pages used out of the
  6310. ** [pagecache memory allocator] that was configured using
  6311. ** [SQLITE_CONFIG_PAGECACHE]. The
  6312. ** value returned is in pages, not in bytes.</dd>)^
  6313. **
  6314. ** [[SQLITE_STATUS_PAGECACHE_OVERFLOW]]
  6315. ** ^(<dt>SQLITE_STATUS_PAGECACHE_OVERFLOW</dt>
  6316. ** <dd>This parameter returns the number of bytes of page cache
  6317. ** allocation which could not be satisfied by the [SQLITE_CONFIG_PAGECACHE]
  6318. ** buffer and where forced to overflow to [sqlite3_malloc()]. The
  6319. ** returned value includes allocations that overflowed because they
  6320. ** where too large (they were larger than the "sz" parameter to
  6321. ** [SQLITE_CONFIG_PAGECACHE]) and allocations that overflowed because
  6322. ** no space was left in the page cache.</dd>)^
  6323. **
  6324. ** [[SQLITE_STATUS_PAGECACHE_SIZE]] ^(<dt>SQLITE_STATUS_PAGECACHE_SIZE</dt>
  6325. ** <dd>This parameter records the largest memory allocation request
  6326. ** handed to [pagecache memory allocator]. Only the value returned in the
  6327. ** *pHighwater parameter to [sqlite3_status()] is of interest.
  6328. ** The value written into the *pCurrent parameter is undefined.</dd>)^
  6329. **
  6330. ** [[SQLITE_STATUS_SCRATCH_USED]] ^(<dt>SQLITE_STATUS_SCRATCH_USED</dt>
  6331. ** <dd>This parameter returns the number of allocations used out of the
  6332. ** [scratch memory allocator] configured using
  6333. ** [SQLITE_CONFIG_SCRATCH]. The value returned is in allocations, not
  6334. ** in bytes. Since a single thread may only have one scratch allocation
  6335. ** outstanding at time, this parameter also reports the number of threads
  6336. ** using scratch memory at the same time.</dd>)^
  6337. **
  6338. ** [[SQLITE_STATUS_SCRATCH_OVERFLOW]] ^(<dt>SQLITE_STATUS_SCRATCH_OVERFLOW</dt>
  6339. ** <dd>This parameter returns the number of bytes of scratch memory
  6340. ** allocation which could not be satisfied by the [SQLITE_CONFIG_SCRATCH]
  6341. ** buffer and where forced to overflow to [sqlite3_malloc()]. The values
  6342. ** returned include overflows because the requested allocation was too
  6343. ** larger (that is, because the requested allocation was larger than the
  6344. ** "sz" parameter to [SQLITE_CONFIG_SCRATCH]) and because no scratch buffer
  6345. ** slots were available.
  6346. ** </dd>)^
  6347. **
  6348. ** [[SQLITE_STATUS_SCRATCH_SIZE]] ^(<dt>SQLITE_STATUS_SCRATCH_SIZE</dt>
  6349. ** <dd>This parameter records the largest memory allocation request
  6350. ** handed to [scratch memory allocator]. Only the value returned in the
  6351. ** *pHighwater parameter to [sqlite3_status()] is of interest.
  6352. ** The value written into the *pCurrent parameter is undefined.</dd>)^
  6353. **
  6354. ** [[SQLITE_STATUS_PARSER_STACK]] ^(<dt>SQLITE_STATUS_PARSER_STACK</dt>
  6355. ** <dd>This parameter records the deepest parser stack. It is only
  6356. ** meaningful if SQLite is compiled with [YYTRACKMAXSTACKDEPTH].</dd>)^
  6357. ** </dl>
  6358. **
  6359. ** New status parameters may be added from time to time.
  6360. */
  6361. #define SQLITE_STATUS_MEMORY_USED 0
  6362. #define SQLITE_STATUS_PAGECACHE_USED 1
  6363. #define SQLITE_STATUS_PAGECACHE_OVERFLOW 2
  6364. #define SQLITE_STATUS_SCRATCH_USED 3
  6365. #define SQLITE_STATUS_SCRATCH_OVERFLOW 4
  6366. #define SQLITE_STATUS_MALLOC_SIZE 5
  6367. #define SQLITE_STATUS_PARSER_STACK 6
  6368. #define SQLITE_STATUS_PAGECACHE_SIZE 7
  6369. #define SQLITE_STATUS_SCRATCH_SIZE 8
  6370. #define SQLITE_STATUS_MALLOC_COUNT 9
  6371. /*
  6372. ** CAPI3REF: Database Connection Status
  6373. ** METHOD: sqlite3
  6374. **
  6375. ** ^This interface is used to retrieve runtime status information
  6376. ** about a single [database connection]. ^The first argument is the
  6377. ** database connection object to be interrogated. ^The second argument
  6378. ** is an integer constant, taken from the set of
  6379. ** [SQLITE_DBSTATUS options], that
  6380. ** determines the parameter to interrogate. The set of
  6381. ** [SQLITE_DBSTATUS options] is likely
  6382. ** to grow in future releases of SQLite.
  6383. **
  6384. ** ^The current value of the requested parameter is written into *pCur
  6385. ** and the highest instantaneous value is written into *pHiwtr. ^If
  6386. ** the resetFlg is true, then the highest instantaneous value is
  6387. ** reset back down to the current value.
  6388. **
  6389. ** ^The sqlite3_db_status() routine returns SQLITE_OK on success and a
  6390. ** non-zero [error code] on failure.
  6391. **
  6392. ** See also: [sqlite3_status()] and [sqlite3_stmt_status()].
  6393. */
  6394. SQLITE_API int SQLITE_STDCALL sqlite3_db_status(sqlite3*, int op, int *pCur, int *pHiwtr, int resetFlg);
  6395. /*
  6396. ** CAPI3REF: Status Parameters for database connections
  6397. ** KEYWORDS: {SQLITE_DBSTATUS options}
  6398. **
  6399. ** These constants are the available integer "verbs" that can be passed as
  6400. ** the second argument to the [sqlite3_db_status()] interface.
  6401. **
  6402. ** New verbs may be added in future releases of SQLite. Existing verbs
  6403. ** might be discontinued. Applications should check the return code from
  6404. ** [sqlite3_db_status()] to make sure that the call worked.
  6405. ** The [sqlite3_db_status()] interface will return a non-zero error code
  6406. ** if a discontinued or unsupported verb is invoked.
  6407. **
  6408. ** <dl>
  6409. ** [[SQLITE_DBSTATUS_LOOKASIDE_USED]] ^(<dt>SQLITE_DBSTATUS_LOOKASIDE_USED</dt>
  6410. ** <dd>This parameter returns the number of lookaside memory slots currently
  6411. ** checked out.</dd>)^
  6412. **
  6413. ** [[SQLITE_DBSTATUS_LOOKASIDE_HIT]] ^(<dt>SQLITE_DBSTATUS_LOOKASIDE_HIT</dt>
  6414. ** <dd>This parameter returns the number malloc attempts that were
  6415. ** satisfied using lookaside memory. Only the high-water value is meaningful;
  6416. ** the current value is always zero.)^
  6417. **
  6418. ** [[SQLITE_DBSTATUS_LOOKASIDE_MISS_SIZE]]
  6419. ** ^(<dt>SQLITE_DBSTATUS_LOOKASIDE_MISS_SIZE</dt>
  6420. ** <dd>This parameter returns the number malloc attempts that might have
  6421. ** been satisfied using lookaside memory but failed due to the amount of
  6422. ** memory requested being larger than the lookaside slot size.
  6423. ** Only the high-water value is meaningful;
  6424. ** the current value is always zero.)^
  6425. **
  6426. ** [[SQLITE_DBSTATUS_LOOKASIDE_MISS_FULL]]
  6427. ** ^(<dt>SQLITE_DBSTATUS_LOOKASIDE_MISS_FULL</dt>
  6428. ** <dd>This parameter returns the number malloc attempts that might have
  6429. ** been satisfied using lookaside memory but failed due to all lookaside
  6430. ** memory already being in use.
  6431. ** Only the high-water value is meaningful;
  6432. ** the current value is always zero.)^
  6433. **
  6434. ** [[SQLITE_DBSTATUS_CACHE_USED]] ^(<dt>SQLITE_DBSTATUS_CACHE_USED</dt>
  6435. ** <dd>This parameter returns the approximate number of bytes of heap
  6436. ** memory used by all pager caches associated with the database connection.)^
  6437. ** ^The highwater mark associated with SQLITE_DBSTATUS_CACHE_USED is always 0.
  6438. **
  6439. ** [[SQLITE_DBSTATUS_SCHEMA_USED]] ^(<dt>SQLITE_DBSTATUS_SCHEMA_USED</dt>
  6440. ** <dd>This parameter returns the approximate number of bytes of heap
  6441. ** memory used to store the schema for all databases associated
  6442. ** with the connection - main, temp, and any [ATTACH]-ed databases.)^
  6443. ** ^The full amount of memory used by the schemas is reported, even if the
  6444. ** schema memory is shared with other database connections due to
  6445. ** [shared cache mode] being enabled.
  6446. ** ^The highwater mark associated with SQLITE_DBSTATUS_SCHEMA_USED is always 0.
  6447. **
  6448. ** [[SQLITE_DBSTATUS_STMT_USED]] ^(<dt>SQLITE_DBSTATUS_STMT_USED</dt>
  6449. ** <dd>This parameter returns the approximate number of bytes of heap
  6450. ** and lookaside memory used by all prepared statements associated with
  6451. ** the database connection.)^
  6452. ** ^The highwater mark associated with SQLITE_DBSTATUS_STMT_USED is always 0.
  6453. ** </dd>
  6454. **
  6455. ** [[SQLITE_DBSTATUS_CACHE_HIT]] ^(<dt>SQLITE_DBSTATUS_CACHE_HIT</dt>
  6456. ** <dd>This parameter returns the number of pager cache hits that have
  6457. ** occurred.)^ ^The highwater mark associated with SQLITE_DBSTATUS_CACHE_HIT
  6458. ** is always 0.
  6459. ** </dd>
  6460. **
  6461. ** [[SQLITE_DBSTATUS_CACHE_MISS]] ^(<dt>SQLITE_DBSTATUS_CACHE_MISS</dt>
  6462. ** <dd>This parameter returns the number of pager cache misses that have
  6463. ** occurred.)^ ^The highwater mark associated with SQLITE_DBSTATUS_CACHE_MISS
  6464. ** is always 0.
  6465. ** </dd>
  6466. **
  6467. ** [[SQLITE_DBSTATUS_CACHE_WRITE]] ^(<dt>SQLITE_DBSTATUS_CACHE_WRITE</dt>
  6468. ** <dd>This parameter returns the number of dirty cache entries that have
  6469. ** been written to disk. Specifically, the number of pages written to the
  6470. ** wal file in wal mode databases, or the number of pages written to the
  6471. ** database file in rollback mode databases. Any pages written as part of
  6472. ** transaction rollback or database recovery operations are not included.
  6473. ** If an IO or other error occurs while writing a page to disk, the effect
  6474. ** on subsequent SQLITE_DBSTATUS_CACHE_WRITE requests is undefined.)^ ^The
  6475. ** highwater mark associated with SQLITE_DBSTATUS_CACHE_WRITE is always 0.
  6476. ** </dd>
  6477. **
  6478. ** [[SQLITE_DBSTATUS_DEFERRED_FKS]] ^(<dt>SQLITE_DBSTATUS_DEFERRED_FKS</dt>
  6479. ** <dd>This parameter returns zero for the current value if and only if
  6480. ** all foreign key constraints (deferred or immediate) have been
  6481. ** resolved.)^ ^The highwater mark is always 0.
  6482. ** </dd>
  6483. ** </dl>
  6484. */
  6485. #define SQLITE_DBSTATUS_LOOKASIDE_USED 0
  6486. #define SQLITE_DBSTATUS_CACHE_USED 1
  6487. #define SQLITE_DBSTATUS_SCHEMA_USED 2
  6488. #define SQLITE_DBSTATUS_STMT_USED 3
  6489. #define SQLITE_DBSTATUS_LOOKASIDE_HIT 4
  6490. #define SQLITE_DBSTATUS_LOOKASIDE_MISS_SIZE 5
  6491. #define SQLITE_DBSTATUS_LOOKASIDE_MISS_FULL 6
  6492. #define SQLITE_DBSTATUS_CACHE_HIT 7
  6493. #define SQLITE_DBSTATUS_CACHE_MISS 8
  6494. #define SQLITE_DBSTATUS_CACHE_WRITE 9
  6495. #define SQLITE_DBSTATUS_DEFERRED_FKS 10
  6496. #define SQLITE_DBSTATUS_MAX 10 /* Largest defined DBSTATUS */
  6497. /*
  6498. ** CAPI3REF: Prepared Statement Status
  6499. ** METHOD: sqlite3_stmt
  6500. **
  6501. ** ^(Each prepared statement maintains various
  6502. ** [SQLITE_STMTSTATUS counters] that measure the number
  6503. ** of times it has performed specific operations.)^ These counters can
  6504. ** be used to monitor the performance characteristics of the prepared
  6505. ** statements. For example, if the number of table steps greatly exceeds
  6506. ** the number of table searches or result rows, that would tend to indicate
  6507. ** that the prepared statement is using a full table scan rather than
  6508. ** an index.
  6509. **
  6510. ** ^(This interface is used to retrieve and reset counter values from
  6511. ** a [prepared statement]. The first argument is the prepared statement
  6512. ** object to be interrogated. The second argument
  6513. ** is an integer code for a specific [SQLITE_STMTSTATUS counter]
  6514. ** to be interrogated.)^
  6515. ** ^The current value of the requested counter is returned.
  6516. ** ^If the resetFlg is true, then the counter is reset to zero after this
  6517. ** interface call returns.
  6518. **
  6519. ** See also: [sqlite3_status()] and [sqlite3_db_status()].
  6520. */
  6521. SQLITE_API int SQLITE_STDCALL sqlite3_stmt_status(sqlite3_stmt*, int op,int resetFlg);
  6522. /*
  6523. ** CAPI3REF: Status Parameters for prepared statements
  6524. ** KEYWORDS: {SQLITE_STMTSTATUS counter} {SQLITE_STMTSTATUS counters}
  6525. **
  6526. ** These preprocessor macros define integer codes that name counter
  6527. ** values associated with the [sqlite3_stmt_status()] interface.
  6528. ** The meanings of the various counters are as follows:
  6529. **
  6530. ** <dl>
  6531. ** [[SQLITE_STMTSTATUS_FULLSCAN_STEP]] <dt>SQLITE_STMTSTATUS_FULLSCAN_STEP</dt>
  6532. ** <dd>^This is the number of times that SQLite has stepped forward in
  6533. ** a table as part of a full table scan. Large numbers for this counter
  6534. ** may indicate opportunities for performance improvement through
  6535. ** careful use of indices.</dd>
  6536. **
  6537. ** [[SQLITE_STMTSTATUS_SORT]] <dt>SQLITE_STMTSTATUS_SORT</dt>
  6538. ** <dd>^This is the number of sort operations that have occurred.
  6539. ** A non-zero value in this counter may indicate an opportunity to
  6540. ** improvement performance through careful use of indices.</dd>
  6541. **
  6542. ** [[SQLITE_STMTSTATUS_AUTOINDEX]] <dt>SQLITE_STMTSTATUS_AUTOINDEX</dt>
  6543. ** <dd>^This is the number of rows inserted into transient indices that
  6544. ** were created automatically in order to help joins run faster.
  6545. ** A non-zero value in this counter may indicate an opportunity to
  6546. ** improvement performance by adding permanent indices that do not
  6547. ** need to be reinitialized each time the statement is run.</dd>
  6548. **
  6549. ** [[SQLITE_STMTSTATUS_VM_STEP]] <dt>SQLITE_STMTSTATUS_VM_STEP</dt>
  6550. ** <dd>^This is the number of virtual machine operations executed
  6551. ** by the prepared statement if that number is less than or equal
  6552. ** to 2147483647. The number of virtual machine operations can be
  6553. ** used as a proxy for the total work done by the prepared statement.
  6554. ** If the number of virtual machine operations exceeds 2147483647
  6555. ** then the value returned by this statement status code is undefined.
  6556. ** </dd>
  6557. ** </dl>
  6558. */
  6559. #define SQLITE_STMTSTATUS_FULLSCAN_STEP 1
  6560. #define SQLITE_STMTSTATUS_SORT 2
  6561. #define SQLITE_STMTSTATUS_AUTOINDEX 3
  6562. #define SQLITE_STMTSTATUS_VM_STEP 4
  6563. /*
  6564. ** CAPI3REF: Custom Page Cache Object
  6565. **
  6566. ** The sqlite3_pcache type is opaque. It is implemented by
  6567. ** the pluggable module. The SQLite core has no knowledge of
  6568. ** its size or internal structure and never deals with the
  6569. ** sqlite3_pcache object except by holding and passing pointers
  6570. ** to the object.
  6571. **
  6572. ** See [sqlite3_pcache_methods2] for additional information.
  6573. */
  6574. typedef struct sqlite3_pcache sqlite3_pcache;
  6575. /*
  6576. ** CAPI3REF: Custom Page Cache Object
  6577. **
  6578. ** The sqlite3_pcache_page object represents a single page in the
  6579. ** page cache. The page cache will allocate instances of this
  6580. ** object. Various methods of the page cache use pointers to instances
  6581. ** of this object as parameters or as their return value.
  6582. **
  6583. ** See [sqlite3_pcache_methods2] for additional information.
  6584. */
  6585. typedef struct sqlite3_pcache_page sqlite3_pcache_page;
  6586. struct sqlite3_pcache_page {
  6587. void *pBuf; /* The content of the page */
  6588. void *pExtra; /* Extra information associated with the page */
  6589. };
  6590. /*
  6591. ** CAPI3REF: Application Defined Page Cache.
  6592. ** KEYWORDS: {page cache}
  6593. **
  6594. ** ^(The [sqlite3_config]([SQLITE_CONFIG_PCACHE2], ...) interface can
  6595. ** register an alternative page cache implementation by passing in an
  6596. ** instance of the sqlite3_pcache_methods2 structure.)^
  6597. ** In many applications, most of the heap memory allocated by
  6598. ** SQLite is used for the page cache.
  6599. ** By implementing a
  6600. ** custom page cache using this API, an application can better control
  6601. ** the amount of memory consumed by SQLite, the way in which
  6602. ** that memory is allocated and released, and the policies used to
  6603. ** determine exactly which parts of a database file are cached and for
  6604. ** how long.
  6605. **
  6606. ** The alternative page cache mechanism is an
  6607. ** extreme measure that is only needed by the most demanding applications.
  6608. ** The built-in page cache is recommended for most uses.
  6609. **
  6610. ** ^(The contents of the sqlite3_pcache_methods2 structure are copied to an
  6611. ** internal buffer by SQLite within the call to [sqlite3_config]. Hence
  6612. ** the application may discard the parameter after the call to
  6613. ** [sqlite3_config()] returns.)^
  6614. **
  6615. ** [[the xInit() page cache method]]
  6616. ** ^(The xInit() method is called once for each effective
  6617. ** call to [sqlite3_initialize()])^
  6618. ** (usually only once during the lifetime of the process). ^(The xInit()
  6619. ** method is passed a copy of the sqlite3_pcache_methods2.pArg value.)^
  6620. ** The intent of the xInit() method is to set up global data structures
  6621. ** required by the custom page cache implementation.
  6622. ** ^(If the xInit() method is NULL, then the
  6623. ** built-in default page cache is used instead of the application defined
  6624. ** page cache.)^
  6625. **
  6626. ** [[the xShutdown() page cache method]]
  6627. ** ^The xShutdown() method is called by [sqlite3_shutdown()].
  6628. ** It can be used to clean up
  6629. ** any outstanding resources before process shutdown, if required.
  6630. ** ^The xShutdown() method may be NULL.
  6631. **
  6632. ** ^SQLite automatically serializes calls to the xInit method,
  6633. ** so the xInit method need not be threadsafe. ^The
  6634. ** xShutdown method is only called from [sqlite3_shutdown()] so it does
  6635. ** not need to be threadsafe either. All other methods must be threadsafe
  6636. ** in multithreaded applications.
  6637. **
  6638. ** ^SQLite will never invoke xInit() more than once without an intervening
  6639. ** call to xShutdown().
  6640. **
  6641. ** [[the xCreate() page cache methods]]
  6642. ** ^SQLite invokes the xCreate() method to construct a new cache instance.
  6643. ** SQLite will typically create one cache instance for each open database file,
  6644. ** though this is not guaranteed. ^The
  6645. ** first parameter, szPage, is the size in bytes of the pages that must
  6646. ** be allocated by the cache. ^szPage will always a power of two. ^The
  6647. ** second parameter szExtra is a number of bytes of extra storage
  6648. ** associated with each page cache entry. ^The szExtra parameter will
  6649. ** a number less than 250. SQLite will use the
  6650. ** extra szExtra bytes on each page to store metadata about the underlying
  6651. ** database page on disk. The value passed into szExtra depends
  6652. ** on the SQLite version, the target platform, and how SQLite was compiled.
  6653. ** ^The third argument to xCreate(), bPurgeable, is true if the cache being
  6654. ** created will be used to cache database pages of a file stored on disk, or
  6655. ** false if it is used for an in-memory database. The cache implementation
  6656. ** does not have to do anything special based with the value of bPurgeable;
  6657. ** it is purely advisory. ^On a cache where bPurgeable is false, SQLite will
  6658. ** never invoke xUnpin() except to deliberately delete a page.
  6659. ** ^In other words, calls to xUnpin() on a cache with bPurgeable set to
  6660. ** false will always have the "discard" flag set to true.
  6661. ** ^Hence, a cache created with bPurgeable false will
  6662. ** never contain any unpinned pages.
  6663. **
  6664. ** [[the xCachesize() page cache method]]
  6665. ** ^(The xCachesize() method may be called at any time by SQLite to set the
  6666. ** suggested maximum cache-size (number of pages stored by) the cache
  6667. ** instance passed as the first argument. This is the value configured using
  6668. ** the SQLite "[PRAGMA cache_size]" command.)^ As with the bPurgeable
  6669. ** parameter, the implementation is not required to do anything with this
  6670. ** value; it is advisory only.
  6671. **
  6672. ** [[the xPagecount() page cache methods]]
  6673. ** The xPagecount() method must return the number of pages currently
  6674. ** stored in the cache, both pinned and unpinned.
  6675. **
  6676. ** [[the xFetch() page cache methods]]
  6677. ** The xFetch() method locates a page in the cache and returns a pointer to
  6678. ** an sqlite3_pcache_page object associated with that page, or a NULL pointer.
  6679. ** The pBuf element of the returned sqlite3_pcache_page object will be a
  6680. ** pointer to a buffer of szPage bytes used to store the content of a
  6681. ** single database page. The pExtra element of sqlite3_pcache_page will be
  6682. ** a pointer to the szExtra bytes of extra storage that SQLite has requested
  6683. ** for each entry in the page cache.
  6684. **
  6685. ** The page to be fetched is determined by the key. ^The minimum key value
  6686. ** is 1. After it has been retrieved using xFetch, the page is considered
  6687. ** to be "pinned".
  6688. **
  6689. ** If the requested page is already in the page cache, then the page cache
  6690. ** implementation must return a pointer to the page buffer with its content
  6691. ** intact. If the requested page is not already in the cache, then the
  6692. ** cache implementation should use the value of the createFlag
  6693. ** parameter to help it determined what action to take:
  6694. **
  6695. ** <table border=1 width=85% align=center>
  6696. ** <tr><th> createFlag <th> Behavior when page is not already in cache
  6697. ** <tr><td> 0 <td> Do not allocate a new page. Return NULL.
  6698. ** <tr><td> 1 <td> Allocate a new page if it easy and convenient to do so.
  6699. ** Otherwise return NULL.
  6700. ** <tr><td> 2 <td> Make every effort to allocate a new page. Only return
  6701. ** NULL if allocating a new page is effectively impossible.
  6702. ** </table>
  6703. **
  6704. ** ^(SQLite will normally invoke xFetch() with a createFlag of 0 or 1. SQLite
  6705. ** will only use a createFlag of 2 after a prior call with a createFlag of 1
  6706. ** failed.)^ In between the to xFetch() calls, SQLite may
  6707. ** attempt to unpin one or more cache pages by spilling the content of
  6708. ** pinned pages to disk and synching the operating system disk cache.
  6709. **
  6710. ** [[the xUnpin() page cache method]]
  6711. ** ^xUnpin() is called by SQLite with a pointer to a currently pinned page
  6712. ** as its second argument. If the third parameter, discard, is non-zero,
  6713. ** then the page must be evicted from the cache.
  6714. ** ^If the discard parameter is
  6715. ** zero, then the page may be discarded or retained at the discretion of
  6716. ** page cache implementation. ^The page cache implementation
  6717. ** may choose to evict unpinned pages at any time.
  6718. **
  6719. ** The cache must not perform any reference counting. A single
  6720. ** call to xUnpin() unpins the page regardless of the number of prior calls
  6721. ** to xFetch().
  6722. **
  6723. ** [[the xRekey() page cache methods]]
  6724. ** The xRekey() method is used to change the key value associated with the
  6725. ** page passed as the second argument. If the cache
  6726. ** previously contains an entry associated with newKey, it must be
  6727. ** discarded. ^Any prior cache entry associated with newKey is guaranteed not
  6728. ** to be pinned.
  6729. **
  6730. ** When SQLite calls the xTruncate() method, the cache must discard all
  6731. ** existing cache entries with page numbers (keys) greater than or equal
  6732. ** to the value of the iLimit parameter passed to xTruncate(). If any
  6733. ** of these pages are pinned, they are implicitly unpinned, meaning that
  6734. ** they can be safely discarded.
  6735. **
  6736. ** [[the xDestroy() page cache method]]
  6737. ** ^The xDestroy() method is used to delete a cache allocated by xCreate().
  6738. ** All resources associated with the specified cache should be freed. ^After
  6739. ** calling the xDestroy() method, SQLite considers the [sqlite3_pcache*]
  6740. ** handle invalid, and will not use it with any other sqlite3_pcache_methods2
  6741. ** functions.
  6742. **
  6743. ** [[the xShrink() page cache method]]
  6744. ** ^SQLite invokes the xShrink() method when it wants the page cache to
  6745. ** free up as much of heap memory as possible. The page cache implementation
  6746. ** is not obligated to free any memory, but well-behaved implementations should
  6747. ** do their best.
  6748. */
  6749. typedef struct sqlite3_pcache_methods2 sqlite3_pcache_methods2;
  6750. struct sqlite3_pcache_methods2 {
  6751. int iVersion;
  6752. void *pArg;
  6753. int (*xInit)(void*);
  6754. void (*xShutdown)(void*);
  6755. sqlite3_pcache *(*xCreate)(int szPage, int szExtra, int bPurgeable);
  6756. void (*xCachesize)(sqlite3_pcache*, int nCachesize);
  6757. int (*xPagecount)(sqlite3_pcache*);
  6758. sqlite3_pcache_page *(*xFetch)(sqlite3_pcache*, unsigned key, int createFlag);
  6759. void (*xUnpin)(sqlite3_pcache*, sqlite3_pcache_page*, int discard);
  6760. void (*xRekey)(sqlite3_pcache*, sqlite3_pcache_page*,
  6761. unsigned oldKey, unsigned newKey);
  6762. void (*xTruncate)(sqlite3_pcache*, unsigned iLimit);
  6763. void (*xDestroy)(sqlite3_pcache*);
  6764. void (*xShrink)(sqlite3_pcache*);
  6765. };
  6766. /*
  6767. ** This is the obsolete pcache_methods object that has now been replaced
  6768. ** by sqlite3_pcache_methods2. This object is not used by SQLite. It is
  6769. ** retained in the header file for backwards compatibility only.
  6770. */
  6771. typedef struct sqlite3_pcache_methods sqlite3_pcache_methods;
  6772. struct sqlite3_pcache_methods {
  6773. void *pArg;
  6774. int (*xInit)(void*);
  6775. void (*xShutdown)(void*);
  6776. sqlite3_pcache *(*xCreate)(int szPage, int bPurgeable);
  6777. void (*xCachesize)(sqlite3_pcache*, int nCachesize);
  6778. int (*xPagecount)(sqlite3_pcache*);
  6779. void *(*xFetch)(sqlite3_pcache*, unsigned key, int createFlag);
  6780. void (*xUnpin)(sqlite3_pcache*, void*, int discard);
  6781. void (*xRekey)(sqlite3_pcache*, void*, unsigned oldKey, unsigned newKey);
  6782. void (*xTruncate)(sqlite3_pcache*, unsigned iLimit);
  6783. void (*xDestroy)(sqlite3_pcache*);
  6784. };
  6785. /*
  6786. ** CAPI3REF: Online Backup Object
  6787. **
  6788. ** The sqlite3_backup object records state information about an ongoing
  6789. ** online backup operation. ^The sqlite3_backup object is created by
  6790. ** a call to [sqlite3_backup_init()] and is destroyed by a call to
  6791. ** [sqlite3_backup_finish()].
  6792. **
  6793. ** See Also: [Using the SQLite Online Backup API]
  6794. */
  6795. typedef struct sqlite3_backup sqlite3_backup;
  6796. /*
  6797. ** CAPI3REF: Online Backup API.
  6798. **
  6799. ** The backup API copies the content of one database into another.
  6800. ** It is useful either for creating backups of databases or
  6801. ** for copying in-memory databases to or from persistent files.
  6802. **
  6803. ** See Also: [Using the SQLite Online Backup API]
  6804. **
  6805. ** ^SQLite holds a write transaction open on the destination database file
  6806. ** for the duration of the backup operation.
  6807. ** ^The source database is read-locked only while it is being read;
  6808. ** it is not locked continuously for the entire backup operation.
  6809. ** ^Thus, the backup may be performed on a live source database without
  6810. ** preventing other database connections from
  6811. ** reading or writing to the source database while the backup is underway.
  6812. **
  6813. ** ^(To perform a backup operation:
  6814. ** <ol>
  6815. ** <li><b>sqlite3_backup_init()</b> is called once to initialize the
  6816. ** backup,
  6817. ** <li><b>sqlite3_backup_step()</b> is called one or more times to transfer
  6818. ** the data between the two databases, and finally
  6819. ** <li><b>sqlite3_backup_finish()</b> is called to release all resources
  6820. ** associated with the backup operation.
  6821. ** </ol>)^
  6822. ** There should be exactly one call to sqlite3_backup_finish() for each
  6823. ** successful call to sqlite3_backup_init().
  6824. **
  6825. ** [[sqlite3_backup_init()]] <b>sqlite3_backup_init()</b>
  6826. **
  6827. ** ^The D and N arguments to sqlite3_backup_init(D,N,S,M) are the
  6828. ** [database connection] associated with the destination database
  6829. ** and the database name, respectively.
  6830. ** ^The database name is "main" for the main database, "temp" for the
  6831. ** temporary database, or the name specified after the AS keyword in
  6832. ** an [ATTACH] statement for an attached database.
  6833. ** ^The S and M arguments passed to
  6834. ** sqlite3_backup_init(D,N,S,M) identify the [database connection]
  6835. ** and database name of the source database, respectively.
  6836. ** ^The source and destination [database connections] (parameters S and D)
  6837. ** must be different or else sqlite3_backup_init(D,N,S,M) will fail with
  6838. ** an error.
  6839. **
  6840. ** ^A call to sqlite3_backup_init() will fail, returning SQLITE_ERROR, if
  6841. ** there is already a read or read-write transaction open on the
  6842. ** destination database.
  6843. **
  6844. ** ^If an error occurs within sqlite3_backup_init(D,N,S,M), then NULL is
  6845. ** returned and an error code and error message are stored in the
  6846. ** destination [database connection] D.
  6847. ** ^The error code and message for the failed call to sqlite3_backup_init()
  6848. ** can be retrieved using the [sqlite3_errcode()], [sqlite3_errmsg()], and/or
  6849. ** [sqlite3_errmsg16()] functions.
  6850. ** ^A successful call to sqlite3_backup_init() returns a pointer to an
  6851. ** [sqlite3_backup] object.
  6852. ** ^The [sqlite3_backup] object may be used with the sqlite3_backup_step() and
  6853. ** sqlite3_backup_finish() functions to perform the specified backup
  6854. ** operation.
  6855. **
  6856. ** [[sqlite3_backup_step()]] <b>sqlite3_backup_step()</b>
  6857. **
  6858. ** ^Function sqlite3_backup_step(B,N) will copy up to N pages between
  6859. ** the source and destination databases specified by [sqlite3_backup] object B.
  6860. ** ^If N is negative, all remaining source pages are copied.
  6861. ** ^If sqlite3_backup_step(B,N) successfully copies N pages and there
  6862. ** are still more pages to be copied, then the function returns [SQLITE_OK].
  6863. ** ^If sqlite3_backup_step(B,N) successfully finishes copying all pages
  6864. ** from source to destination, then it returns [SQLITE_DONE].
  6865. ** ^If an error occurs while running sqlite3_backup_step(B,N),
  6866. ** then an [error code] is returned. ^As well as [SQLITE_OK] and
  6867. ** [SQLITE_DONE], a call to sqlite3_backup_step() may return [SQLITE_READONLY],
  6868. ** [SQLITE_NOMEM], [SQLITE_BUSY], [SQLITE_LOCKED], or an
  6869. ** [SQLITE_IOERR_ACCESS | SQLITE_IOERR_XXX] extended error code.
  6870. **
  6871. ** ^(The sqlite3_backup_step() might return [SQLITE_READONLY] if
  6872. ** <ol>
  6873. ** <li> the destination database was opened read-only, or
  6874. ** <li> the destination database is using write-ahead-log journaling
  6875. ** and the destination and source page sizes differ, or
  6876. ** <li> the destination database is an in-memory database and the
  6877. ** destination and source page sizes differ.
  6878. ** </ol>)^
  6879. **
  6880. ** ^If sqlite3_backup_step() cannot obtain a required file-system lock, then
  6881. ** the [sqlite3_busy_handler | busy-handler function]
  6882. ** is invoked (if one is specified). ^If the
  6883. ** busy-handler returns non-zero before the lock is available, then
  6884. ** [SQLITE_BUSY] is returned to the caller. ^In this case the call to
  6885. ** sqlite3_backup_step() can be retried later. ^If the source
  6886. ** [database connection]
  6887. ** is being used to write to the source database when sqlite3_backup_step()
  6888. ** is called, then [SQLITE_LOCKED] is returned immediately. ^Again, in this
  6889. ** case the call to sqlite3_backup_step() can be retried later on. ^(If
  6890. ** [SQLITE_IOERR_ACCESS | SQLITE_IOERR_XXX], [SQLITE_NOMEM], or
  6891. ** [SQLITE_READONLY] is returned, then
  6892. ** there is no point in retrying the call to sqlite3_backup_step(). These
  6893. ** errors are considered fatal.)^ The application must accept
  6894. ** that the backup operation has failed and pass the backup operation handle
  6895. ** to the sqlite3_backup_finish() to release associated resources.
  6896. **
  6897. ** ^The first call to sqlite3_backup_step() obtains an exclusive lock
  6898. ** on the destination file. ^The exclusive lock is not released until either
  6899. ** sqlite3_backup_finish() is called or the backup operation is complete
  6900. ** and sqlite3_backup_step() returns [SQLITE_DONE]. ^Every call to
  6901. ** sqlite3_backup_step() obtains a [shared lock] on the source database that
  6902. ** lasts for the duration of the sqlite3_backup_step() call.
  6903. ** ^Because the source database is not locked between calls to
  6904. ** sqlite3_backup_step(), the source database may be modified mid-way
  6905. ** through the backup process. ^If the source database is modified by an
  6906. ** external process or via a database connection other than the one being
  6907. ** used by the backup operation, then the backup will be automatically
  6908. ** restarted by the next call to sqlite3_backup_step(). ^If the source
  6909. ** database is modified by the using the same database connection as is used
  6910. ** by the backup operation, then the backup database is automatically
  6911. ** updated at the same time.
  6912. **
  6913. ** [[sqlite3_backup_finish()]] <b>sqlite3_backup_finish()</b>
  6914. **
  6915. ** When sqlite3_backup_step() has returned [SQLITE_DONE], or when the
  6916. ** application wishes to abandon the backup operation, the application
  6917. ** should destroy the [sqlite3_backup] by passing it to sqlite3_backup_finish().
  6918. ** ^The sqlite3_backup_finish() interfaces releases all
  6919. ** resources associated with the [sqlite3_backup] object.
  6920. ** ^If sqlite3_backup_step() has not yet returned [SQLITE_DONE], then any
  6921. ** active write-transaction on the destination database is rolled back.
  6922. ** The [sqlite3_backup] object is invalid
  6923. ** and may not be used following a call to sqlite3_backup_finish().
  6924. **
  6925. ** ^The value returned by sqlite3_backup_finish is [SQLITE_OK] if no
  6926. ** sqlite3_backup_step() errors occurred, regardless or whether or not
  6927. ** sqlite3_backup_step() completed.
  6928. ** ^If an out-of-memory condition or IO error occurred during any prior
  6929. ** sqlite3_backup_step() call on the same [sqlite3_backup] object, then
  6930. ** sqlite3_backup_finish() returns the corresponding [error code].
  6931. **
  6932. ** ^A return of [SQLITE_BUSY] or [SQLITE_LOCKED] from sqlite3_backup_step()
  6933. ** is not a permanent error and does not affect the return value of
  6934. ** sqlite3_backup_finish().
  6935. **
  6936. ** [[sqlite3_backup_remaining()]] [[sqlite3_backup_pagecount()]]
  6937. ** <b>sqlite3_backup_remaining() and sqlite3_backup_pagecount()</b>
  6938. **
  6939. ** ^The sqlite3_backup_remaining() routine returns the number of pages still
  6940. ** to be backed up at the conclusion of the most recent sqlite3_backup_step().
  6941. ** ^The sqlite3_backup_pagecount() routine returns the total number of pages
  6942. ** in the source database at the conclusion of the most recent
  6943. ** sqlite3_backup_step().
  6944. ** ^(The values returned by these functions are only updated by
  6945. ** sqlite3_backup_step(). If the source database is modified in a way that
  6946. ** changes the size of the source database or the number of pages remaining,
  6947. ** those changes are not reflected in the output of sqlite3_backup_pagecount()
  6948. ** and sqlite3_backup_remaining() until after the next
  6949. ** sqlite3_backup_step().)^
  6950. **
  6951. ** <b>Concurrent Usage of Database Handles</b>
  6952. **
  6953. ** ^The source [database connection] may be used by the application for other
  6954. ** purposes while a backup operation is underway or being initialized.
  6955. ** ^If SQLite is compiled and configured to support threadsafe database
  6956. ** connections, then the source database connection may be used concurrently
  6957. ** from within other threads.
  6958. **
  6959. ** However, the application must guarantee that the destination
  6960. ** [database connection] is not passed to any other API (by any thread) after
  6961. ** sqlite3_backup_init() is called and before the corresponding call to
  6962. ** sqlite3_backup_finish(). SQLite does not currently check to see
  6963. ** if the application incorrectly accesses the destination [database connection]
  6964. ** and so no error code is reported, but the operations may malfunction
  6965. ** nevertheless. Use of the destination database connection while a
  6966. ** backup is in progress might also also cause a mutex deadlock.
  6967. **
  6968. ** If running in [shared cache mode], the application must
  6969. ** guarantee that the shared cache used by the destination database
  6970. ** is not accessed while the backup is running. In practice this means
  6971. ** that the application must guarantee that the disk file being
  6972. ** backed up to is not accessed by any connection within the process,
  6973. ** not just the specific connection that was passed to sqlite3_backup_init().
  6974. **
  6975. ** The [sqlite3_backup] object itself is partially threadsafe. Multiple
  6976. ** threads may safely make multiple concurrent calls to sqlite3_backup_step().
  6977. ** However, the sqlite3_backup_remaining() and sqlite3_backup_pagecount()
  6978. ** APIs are not strictly speaking threadsafe. If they are invoked at the
  6979. ** same time as another thread is invoking sqlite3_backup_step() it is
  6980. ** possible that they return invalid values.
  6981. */
  6982. SQLITE_API sqlite3_backup *SQLITE_STDCALL sqlite3_backup_init(
  6983. sqlite3 *pDest, /* Destination database handle */
  6984. const char *zDestName, /* Destination database name */
  6985. sqlite3 *pSource, /* Source database handle */
  6986. const char *zSourceName /* Source database name */
  6987. );
  6988. SQLITE_API int SQLITE_STDCALL sqlite3_backup_step(sqlite3_backup *p, int nPage);
  6989. SQLITE_API int SQLITE_STDCALL sqlite3_backup_finish(sqlite3_backup *p);
  6990. SQLITE_API int SQLITE_STDCALL sqlite3_backup_remaining(sqlite3_backup *p);
  6991. SQLITE_API int SQLITE_STDCALL sqlite3_backup_pagecount(sqlite3_backup *p);
  6992. /*
  6993. ** CAPI3REF: Unlock Notification
  6994. ** METHOD: sqlite3
  6995. **
  6996. ** ^When running in shared-cache mode, a database operation may fail with
  6997. ** an [SQLITE_LOCKED] error if the required locks on the shared-cache or
  6998. ** individual tables within the shared-cache cannot be obtained. See
  6999. ** [SQLite Shared-Cache Mode] for a description of shared-cache locking.
  7000. ** ^This API may be used to register a callback that SQLite will invoke
  7001. ** when the connection currently holding the required lock relinquishes it.
  7002. ** ^This API is only available if the library was compiled with the
  7003. ** [SQLITE_ENABLE_UNLOCK_NOTIFY] C-preprocessor symbol defined.
  7004. **
  7005. ** See Also: [Using the SQLite Unlock Notification Feature].
  7006. **
  7007. ** ^Shared-cache locks are released when a database connection concludes
  7008. ** its current transaction, either by committing it or rolling it back.
  7009. **
  7010. ** ^When a connection (known as the blocked connection) fails to obtain a
  7011. ** shared-cache lock and SQLITE_LOCKED is returned to the caller, the
  7012. ** identity of the database connection (the blocking connection) that
  7013. ** has locked the required resource is stored internally. ^After an
  7014. ** application receives an SQLITE_LOCKED error, it may call the
  7015. ** sqlite3_unlock_notify() method with the blocked connection handle as
  7016. ** the first argument to register for a callback that will be invoked
  7017. ** when the blocking connections current transaction is concluded. ^The
  7018. ** callback is invoked from within the [sqlite3_step] or [sqlite3_close]
  7019. ** call that concludes the blocking connections transaction.
  7020. **
  7021. ** ^(If sqlite3_unlock_notify() is called in a multi-threaded application,
  7022. ** there is a chance that the blocking connection will have already
  7023. ** concluded its transaction by the time sqlite3_unlock_notify() is invoked.
  7024. ** If this happens, then the specified callback is invoked immediately,
  7025. ** from within the call to sqlite3_unlock_notify().)^
  7026. **
  7027. ** ^If the blocked connection is attempting to obtain a write-lock on a
  7028. ** shared-cache table, and more than one other connection currently holds
  7029. ** a read-lock on the same table, then SQLite arbitrarily selects one of
  7030. ** the other connections to use as the blocking connection.
  7031. **
  7032. ** ^(There may be at most one unlock-notify callback registered by a
  7033. ** blocked connection. If sqlite3_unlock_notify() is called when the
  7034. ** blocked connection already has a registered unlock-notify callback,
  7035. ** then the new callback replaces the old.)^ ^If sqlite3_unlock_notify() is
  7036. ** called with a NULL pointer as its second argument, then any existing
  7037. ** unlock-notify callback is canceled. ^The blocked connections
  7038. ** unlock-notify callback may also be canceled by closing the blocked
  7039. ** connection using [sqlite3_close()].
  7040. **
  7041. ** The unlock-notify callback is not reentrant. If an application invokes
  7042. ** any sqlite3_xxx API functions from within an unlock-notify callback, a
  7043. ** crash or deadlock may be the result.
  7044. **
  7045. ** ^Unless deadlock is detected (see below), sqlite3_unlock_notify() always
  7046. ** returns SQLITE_OK.
  7047. **
  7048. ** <b>Callback Invocation Details</b>
  7049. **
  7050. ** When an unlock-notify callback is registered, the application provides a
  7051. ** single void* pointer that is passed to the callback when it is invoked.
  7052. ** However, the signature of the callback function allows SQLite to pass
  7053. ** it an array of void* context pointers. The first argument passed to
  7054. ** an unlock-notify callback is a pointer to an array of void* pointers,
  7055. ** and the second is the number of entries in the array.
  7056. **
  7057. ** When a blocking connections transaction is concluded, there may be
  7058. ** more than one blocked connection that has registered for an unlock-notify
  7059. ** callback. ^If two or more such blocked connections have specified the
  7060. ** same callback function, then instead of invoking the callback function
  7061. ** multiple times, it is invoked once with the set of void* context pointers
  7062. ** specified by the blocked connections bundled together into an array.
  7063. ** This gives the application an opportunity to prioritize any actions
  7064. ** related to the set of unblocked database connections.
  7065. **
  7066. ** <b>Deadlock Detection</b>
  7067. **
  7068. ** Assuming that after registering for an unlock-notify callback a
  7069. ** database waits for the callback to be issued before taking any further
  7070. ** action (a reasonable assumption), then using this API may cause the
  7071. ** application to deadlock. For example, if connection X is waiting for
  7072. ** connection Y's transaction to be concluded, and similarly connection
  7073. ** Y is waiting on connection X's transaction, then neither connection
  7074. ** will proceed and the system may remain deadlocked indefinitely.
  7075. **
  7076. ** To avoid this scenario, the sqlite3_unlock_notify() performs deadlock
  7077. ** detection. ^If a given call to sqlite3_unlock_notify() would put the
  7078. ** system in a deadlocked state, then SQLITE_LOCKED is returned and no
  7079. ** unlock-notify callback is registered. The system is said to be in
  7080. ** a deadlocked state if connection A has registered for an unlock-notify
  7081. ** callback on the conclusion of connection B's transaction, and connection
  7082. ** B has itself registered for an unlock-notify callback when connection
  7083. ** A's transaction is concluded. ^Indirect deadlock is also detected, so
  7084. ** the system is also considered to be deadlocked if connection B has
  7085. ** registered for an unlock-notify callback on the conclusion of connection
  7086. ** C's transaction, where connection C is waiting on connection A. ^Any
  7087. ** number of levels of indirection are allowed.
  7088. **
  7089. ** <b>The "DROP TABLE" Exception</b>
  7090. **
  7091. ** When a call to [sqlite3_step()] returns SQLITE_LOCKED, it is almost
  7092. ** always appropriate to call sqlite3_unlock_notify(). There is however,
  7093. ** one exception. When executing a "DROP TABLE" or "DROP INDEX" statement,
  7094. ** SQLite checks if there are any currently executing SELECT statements
  7095. ** that belong to the same connection. If there are, SQLITE_LOCKED is
  7096. ** returned. In this case there is no "blocking connection", so invoking
  7097. ** sqlite3_unlock_notify() results in the unlock-notify callback being
  7098. ** invoked immediately. If the application then re-attempts the "DROP TABLE"
  7099. ** or "DROP INDEX" query, an infinite loop might be the result.
  7100. **
  7101. ** One way around this problem is to check the extended error code returned
  7102. ** by an sqlite3_step() call. ^(If there is a blocking connection, then the
  7103. ** extended error code is set to SQLITE_LOCKED_SHAREDCACHE. Otherwise, in
  7104. ** the special "DROP TABLE/INDEX" case, the extended error code is just
  7105. ** SQLITE_LOCKED.)^
  7106. */
  7107. SQLITE_API int SQLITE_STDCALL sqlite3_unlock_notify(
  7108. sqlite3 *pBlocked, /* Waiting connection */
  7109. void (*xNotify)(void **apArg, int nArg), /* Callback function to invoke */
  7110. void *pNotifyArg /* Argument to pass to xNotify */
  7111. );
  7112. /*
  7113. ** CAPI3REF: String Comparison
  7114. **
  7115. ** ^The [sqlite3_stricmp()] and [sqlite3_strnicmp()] APIs allow applications
  7116. ** and extensions to compare the contents of two buffers containing UTF-8
  7117. ** strings in a case-independent fashion, using the same definition of "case
  7118. ** independence" that SQLite uses internally when comparing identifiers.
  7119. */
  7120. SQLITE_API int SQLITE_STDCALL sqlite3_stricmp(const char *, const char *);
  7121. SQLITE_API int SQLITE_STDCALL sqlite3_strnicmp(const char *, const char *, int);
  7122. /*
  7123. ** CAPI3REF: String Globbing
  7124. *
  7125. ** ^The [sqlite3_strglob(P,X)] interface returns zero if string X matches
  7126. ** the glob pattern P, and it returns non-zero if string X does not match
  7127. ** the glob pattern P. ^The definition of glob pattern matching used in
  7128. ** [sqlite3_strglob(P,X)] is the same as for the "X GLOB P" operator in the
  7129. ** SQL dialect used by SQLite. ^The sqlite3_strglob(P,X) function is case
  7130. ** sensitive.
  7131. **
  7132. ** Note that this routine returns zero on a match and non-zero if the strings
  7133. ** do not match, the same as [sqlite3_stricmp()] and [sqlite3_strnicmp()].
  7134. */
  7135. SQLITE_API int SQLITE_STDCALL sqlite3_strglob(const char *zGlob, const char *zStr);
  7136. /*
  7137. ** CAPI3REF: Error Logging Interface
  7138. **
  7139. ** ^The [sqlite3_log()] interface writes a message into the [error log]
  7140. ** established by the [SQLITE_CONFIG_LOG] option to [sqlite3_config()].
  7141. ** ^If logging is enabled, the zFormat string and subsequent arguments are
  7142. ** used with [sqlite3_snprintf()] to generate the final output string.
  7143. **
  7144. ** The sqlite3_log() interface is intended for use by extensions such as
  7145. ** virtual tables, collating functions, and SQL functions. While there is
  7146. ** nothing to prevent an application from calling sqlite3_log(), doing so
  7147. ** is considered bad form.
  7148. **
  7149. ** The zFormat string must not be NULL.
  7150. **
  7151. ** To avoid deadlocks and other threading problems, the sqlite3_log() routine
  7152. ** will not use dynamically allocated memory. The log message is stored in
  7153. ** a fixed-length buffer on the stack. If the log message is longer than
  7154. ** a few hundred characters, it will be truncated to the length of the
  7155. ** buffer.
  7156. */
  7157. SQLITE_API void SQLITE_CDECL sqlite3_log(int iErrCode, const char *zFormat, ...);
  7158. /*
  7159. ** CAPI3REF: Write-Ahead Log Commit Hook
  7160. ** METHOD: sqlite3
  7161. **
  7162. ** ^The [sqlite3_wal_hook()] function is used to register a callback that
  7163. ** is invoked each time data is committed to a database in wal mode.
  7164. **
  7165. ** ^(The callback is invoked by SQLite after the commit has taken place and
  7166. ** the associated write-lock on the database released)^, so the implementation
  7167. ** may read, write or [checkpoint] the database as required.
  7168. **
  7169. ** ^The first parameter passed to the callback function when it is invoked
  7170. ** is a copy of the third parameter passed to sqlite3_wal_hook() when
  7171. ** registering the callback. ^The second is a copy of the database handle.
  7172. ** ^The third parameter is the name of the database that was written to -
  7173. ** either "main" or the name of an [ATTACH]-ed database. ^The fourth parameter
  7174. ** is the number of pages currently in the write-ahead log file,
  7175. ** including those that were just committed.
  7176. **
  7177. ** The callback function should normally return [SQLITE_OK]. ^If an error
  7178. ** code is returned, that error will propagate back up through the
  7179. ** SQLite code base to cause the statement that provoked the callback
  7180. ** to report an error, though the commit will have still occurred. If the
  7181. ** callback returns [SQLITE_ROW] or [SQLITE_DONE], or if it returns a value
  7182. ** that does not correspond to any valid SQLite error code, the results
  7183. ** are undefined.
  7184. **
  7185. ** A single database handle may have at most a single write-ahead log callback
  7186. ** registered at one time. ^Calling [sqlite3_wal_hook()] replaces any
  7187. ** previously registered write-ahead log callback. ^Note that the
  7188. ** [sqlite3_wal_autocheckpoint()] interface and the
  7189. ** [wal_autocheckpoint pragma] both invoke [sqlite3_wal_hook()] and will
  7190. ** those overwrite any prior [sqlite3_wal_hook()] settings.
  7191. */
  7192. SQLITE_API void *SQLITE_STDCALL sqlite3_wal_hook(
  7193. sqlite3*,
  7194. int(*)(void *,sqlite3*,const char*,int),
  7195. void*
  7196. );
  7197. /*
  7198. ** CAPI3REF: Configure an auto-checkpoint
  7199. ** METHOD: sqlite3
  7200. **
  7201. ** ^The [sqlite3_wal_autocheckpoint(D,N)] is a wrapper around
  7202. ** [sqlite3_wal_hook()] that causes any database on [database connection] D
  7203. ** to automatically [checkpoint]
  7204. ** after committing a transaction if there are N or
  7205. ** more frames in the [write-ahead log] file. ^Passing zero or
  7206. ** a negative value as the nFrame parameter disables automatic
  7207. ** checkpoints entirely.
  7208. **
  7209. ** ^The callback registered by this function replaces any existing callback
  7210. ** registered using [sqlite3_wal_hook()]. ^Likewise, registering a callback
  7211. ** using [sqlite3_wal_hook()] disables the automatic checkpoint mechanism
  7212. ** configured by this function.
  7213. **
  7214. ** ^The [wal_autocheckpoint pragma] can be used to invoke this interface
  7215. ** from SQL.
  7216. **
  7217. ** ^Checkpoints initiated by this mechanism are
  7218. ** [sqlite3_wal_checkpoint_v2|PASSIVE].
  7219. **
  7220. ** ^Every new [database connection] defaults to having the auto-checkpoint
  7221. ** enabled with a threshold of 1000 or [SQLITE_DEFAULT_WAL_AUTOCHECKPOINT]
  7222. ** pages. The use of this interface
  7223. ** is only necessary if the default setting is found to be suboptimal
  7224. ** for a particular application.
  7225. */
  7226. SQLITE_API int SQLITE_STDCALL sqlite3_wal_autocheckpoint(sqlite3 *db, int N);
  7227. /*
  7228. ** CAPI3REF: Checkpoint a database
  7229. ** METHOD: sqlite3
  7230. **
  7231. ** ^(The sqlite3_wal_checkpoint(D,X) is equivalent to
  7232. ** [sqlite3_wal_checkpoint_v2](D,X,[SQLITE_CHECKPOINT_PASSIVE],0,0).)^
  7233. **
  7234. ** In brief, sqlite3_wal_checkpoint(D,X) causes the content in the
  7235. ** [write-ahead log] for database X on [database connection] D to be
  7236. ** transferred into the database file and for the write-ahead log to
  7237. ** be reset. See the [checkpointing] documentation for addition
  7238. ** information.
  7239. **
  7240. ** This interface used to be the only way to cause a checkpoint to
  7241. ** occur. But then the newer and more powerful [sqlite3_wal_checkpoint_v2()]
  7242. ** interface was added. This interface is retained for backwards
  7243. ** compatibility and as a convenience for applications that need to manually
  7244. ** start a callback but which do not need the full power (and corresponding
  7245. ** complication) of [sqlite3_wal_checkpoint_v2()].
  7246. */
  7247. SQLITE_API int SQLITE_STDCALL sqlite3_wal_checkpoint(sqlite3 *db, const char *zDb);
  7248. /*
  7249. ** CAPI3REF: Checkpoint a database
  7250. ** METHOD: sqlite3
  7251. **
  7252. ** ^(The sqlite3_wal_checkpoint_v2(D,X,M,L,C) interface runs a checkpoint
  7253. ** operation on database X of [database connection] D in mode M. Status
  7254. ** information is written back into integers pointed to by L and C.)^
  7255. ** ^(The M parameter must be a valid [checkpoint mode]:)^
  7256. **
  7257. ** <dl>
  7258. ** <dt>SQLITE_CHECKPOINT_PASSIVE<dd>
  7259. ** ^Checkpoint as many frames as possible without waiting for any database
  7260. ** readers or writers to finish, then sync the database file if all frames
  7261. ** in the log were checkpointed. ^The [busy-handler callback]
  7262. ** is never invoked in the SQLITE_CHECKPOINT_PASSIVE mode.
  7263. ** ^On the other hand, passive mode might leave the checkpoint unfinished
  7264. ** if there are concurrent readers or writers.
  7265. **
  7266. ** <dt>SQLITE_CHECKPOINT_FULL<dd>
  7267. ** ^This mode blocks (it invokes the
  7268. ** [sqlite3_busy_handler|busy-handler callback]) until there is no
  7269. ** database writer and all readers are reading from the most recent database
  7270. ** snapshot. ^It then checkpoints all frames in the log file and syncs the
  7271. ** database file. ^This mode blocks new database writers while it is pending,
  7272. ** but new database readers are allowed to continue unimpeded.
  7273. **
  7274. ** <dt>SQLITE_CHECKPOINT_RESTART<dd>
  7275. ** ^This mode works the same way as SQLITE_CHECKPOINT_FULL with the addition
  7276. ** that after checkpointing the log file it blocks (calls the
  7277. ** [busy-handler callback])
  7278. ** until all readers are reading from the database file only. ^This ensures
  7279. ** that the next writer will restart the log file from the beginning.
  7280. ** ^Like SQLITE_CHECKPOINT_FULL, this mode blocks new
  7281. ** database writer attempts while it is pending, but does not impede readers.
  7282. **
  7283. ** <dt>SQLITE_CHECKPOINT_TRUNCATE<dd>
  7284. ** ^This mode works the same way as SQLITE_CHECKPOINT_RESTART with the
  7285. ** addition that it also truncates the log file to zero bytes just prior
  7286. ** to a successful return.
  7287. ** </dl>
  7288. **
  7289. ** ^If pnLog is not NULL, then *pnLog is set to the total number of frames in
  7290. ** the log file or to -1 if the checkpoint could not run because
  7291. ** of an error or because the database is not in [WAL mode]. ^If pnCkpt is not
  7292. ** NULL,then *pnCkpt is set to the total number of checkpointed frames in the
  7293. ** log file (including any that were already checkpointed before the function
  7294. ** was called) or to -1 if the checkpoint could not run due to an error or
  7295. ** because the database is not in WAL mode. ^Note that upon successful
  7296. ** completion of an SQLITE_CHECKPOINT_TRUNCATE, the log file will have been
  7297. ** truncated to zero bytes and so both *pnLog and *pnCkpt will be set to zero.
  7298. **
  7299. ** ^All calls obtain an exclusive "checkpoint" lock on the database file. ^If
  7300. ** any other process is running a checkpoint operation at the same time, the
  7301. ** lock cannot be obtained and SQLITE_BUSY is returned. ^Even if there is a
  7302. ** busy-handler configured, it will not be invoked in this case.
  7303. **
  7304. ** ^The SQLITE_CHECKPOINT_FULL, RESTART and TRUNCATE modes also obtain the
  7305. ** exclusive "writer" lock on the database file. ^If the writer lock cannot be
  7306. ** obtained immediately, and a busy-handler is configured, it is invoked and
  7307. ** the writer lock retried until either the busy-handler returns 0 or the lock
  7308. ** is successfully obtained. ^The busy-handler is also invoked while waiting for
  7309. ** database readers as described above. ^If the busy-handler returns 0 before
  7310. ** the writer lock is obtained or while waiting for database readers, the
  7311. ** checkpoint operation proceeds from that point in the same way as
  7312. ** SQLITE_CHECKPOINT_PASSIVE - checkpointing as many frames as possible
  7313. ** without blocking any further. ^SQLITE_BUSY is returned in this case.
  7314. **
  7315. ** ^If parameter zDb is NULL or points to a zero length string, then the
  7316. ** specified operation is attempted on all WAL databases [attached] to
  7317. ** [database connection] db. In this case the
  7318. ** values written to output parameters *pnLog and *pnCkpt are undefined. ^If
  7319. ** an SQLITE_BUSY error is encountered when processing one or more of the
  7320. ** attached WAL databases, the operation is still attempted on any remaining
  7321. ** attached databases and SQLITE_BUSY is returned at the end. ^If any other
  7322. ** error occurs while processing an attached database, processing is abandoned
  7323. ** and the error code is returned to the caller immediately. ^If no error
  7324. ** (SQLITE_BUSY or otherwise) is encountered while processing the attached
  7325. ** databases, SQLITE_OK is returned.
  7326. **
  7327. ** ^If database zDb is the name of an attached database that is not in WAL
  7328. ** mode, SQLITE_OK is returned and both *pnLog and *pnCkpt set to -1. ^If
  7329. ** zDb is not NULL (or a zero length string) and is not the name of any
  7330. ** attached database, SQLITE_ERROR is returned to the caller.
  7331. **
  7332. ** ^Unless it returns SQLITE_MISUSE,
  7333. ** the sqlite3_wal_checkpoint_v2() interface
  7334. ** sets the error information that is queried by
  7335. ** [sqlite3_errcode()] and [sqlite3_errmsg()].
  7336. **
  7337. ** ^The [PRAGMA wal_checkpoint] command can be used to invoke this interface
  7338. ** from SQL.
  7339. */
  7340. SQLITE_API int SQLITE_STDCALL sqlite3_wal_checkpoint_v2(
  7341. sqlite3 *db, /* Database handle */
  7342. const char *zDb, /* Name of attached database (or NULL) */
  7343. int eMode, /* SQLITE_CHECKPOINT_* value */
  7344. int *pnLog, /* OUT: Size of WAL log in frames */
  7345. int *pnCkpt /* OUT: Total number of frames checkpointed */
  7346. );
  7347. /*
  7348. ** CAPI3REF: Checkpoint Mode Values
  7349. ** KEYWORDS: {checkpoint mode}
  7350. **
  7351. ** These constants define all valid values for the "checkpoint mode" passed
  7352. ** as the third parameter to the [sqlite3_wal_checkpoint_v2()] interface.
  7353. ** See the [sqlite3_wal_checkpoint_v2()] documentation for details on the
  7354. ** meaning of each of these checkpoint modes.
  7355. */
  7356. #define SQLITE_CHECKPOINT_PASSIVE 0 /* Do as much as possible w/o blocking */
  7357. #define SQLITE_CHECKPOINT_FULL 1 /* Wait for writers, then checkpoint */
  7358. #define SQLITE_CHECKPOINT_RESTART 2 /* Like FULL but wait for for readers */
  7359. #define SQLITE_CHECKPOINT_TRUNCATE 3 /* Like RESTART but also truncate WAL */
  7360. /*
  7361. ** CAPI3REF: Virtual Table Interface Configuration
  7362. **
  7363. ** This function may be called by either the [xConnect] or [xCreate] method
  7364. ** of a [virtual table] implementation to configure
  7365. ** various facets of the virtual table interface.
  7366. **
  7367. ** If this interface is invoked outside the context of an xConnect or
  7368. ** xCreate virtual table method then the behavior is undefined.
  7369. **
  7370. ** At present, there is only one option that may be configured using
  7371. ** this function. (See [SQLITE_VTAB_CONSTRAINT_SUPPORT].) Further options
  7372. ** may be added in the future.
  7373. */
  7374. SQLITE_API int SQLITE_CDECL sqlite3_vtab_config(sqlite3*, int op, ...);
  7375. /*
  7376. ** CAPI3REF: Virtual Table Configuration Options
  7377. **
  7378. ** These macros define the various options to the
  7379. ** [sqlite3_vtab_config()] interface that [virtual table] implementations
  7380. ** can use to customize and optimize their behavior.
  7381. **
  7382. ** <dl>
  7383. ** <dt>SQLITE_VTAB_CONSTRAINT_SUPPORT
  7384. ** <dd>Calls of the form
  7385. ** [sqlite3_vtab_config](db,SQLITE_VTAB_CONSTRAINT_SUPPORT,X) are supported,
  7386. ** where X is an integer. If X is zero, then the [virtual table] whose
  7387. ** [xCreate] or [xConnect] method invoked [sqlite3_vtab_config()] does not
  7388. ** support constraints. In this configuration (which is the default) if
  7389. ** a call to the [xUpdate] method returns [SQLITE_CONSTRAINT], then the entire
  7390. ** statement is rolled back as if [ON CONFLICT | OR ABORT] had been
  7391. ** specified as part of the users SQL statement, regardless of the actual
  7392. ** ON CONFLICT mode specified.
  7393. **
  7394. ** If X is non-zero, then the virtual table implementation guarantees
  7395. ** that if [xUpdate] returns [SQLITE_CONSTRAINT], it will do so before
  7396. ** any modifications to internal or persistent data structures have been made.
  7397. ** If the [ON CONFLICT] mode is ABORT, FAIL, IGNORE or ROLLBACK, SQLite
  7398. ** is able to roll back a statement or database transaction, and abandon
  7399. ** or continue processing the current SQL statement as appropriate.
  7400. ** If the ON CONFLICT mode is REPLACE and the [xUpdate] method returns
  7401. ** [SQLITE_CONSTRAINT], SQLite handles this as if the ON CONFLICT mode
  7402. ** had been ABORT.
  7403. **
  7404. ** Virtual table implementations that are required to handle OR REPLACE
  7405. ** must do so within the [xUpdate] method. If a call to the
  7406. ** [sqlite3_vtab_on_conflict()] function indicates that the current ON
  7407. ** CONFLICT policy is REPLACE, the virtual table implementation should
  7408. ** silently replace the appropriate rows within the xUpdate callback and
  7409. ** return SQLITE_OK. Or, if this is not possible, it may return
  7410. ** SQLITE_CONSTRAINT, in which case SQLite falls back to OR ABORT
  7411. ** constraint handling.
  7412. ** </dl>
  7413. */
  7414. #define SQLITE_VTAB_CONSTRAINT_SUPPORT 1
  7415. /*
  7416. ** CAPI3REF: Determine The Virtual Table Conflict Policy
  7417. **
  7418. ** This function may only be called from within a call to the [xUpdate] method
  7419. ** of a [virtual table] implementation for an INSERT or UPDATE operation. ^The
  7420. ** value returned is one of [SQLITE_ROLLBACK], [SQLITE_IGNORE], [SQLITE_FAIL],
  7421. ** [SQLITE_ABORT], or [SQLITE_REPLACE], according to the [ON CONFLICT] mode
  7422. ** of the SQL statement that triggered the call to the [xUpdate] method of the
  7423. ** [virtual table].
  7424. */
  7425. SQLITE_API int SQLITE_STDCALL sqlite3_vtab_on_conflict(sqlite3 *);
  7426. /*
  7427. ** CAPI3REF: Conflict resolution modes
  7428. ** KEYWORDS: {conflict resolution mode}
  7429. **
  7430. ** These constants are returned by [sqlite3_vtab_on_conflict()] to
  7431. ** inform a [virtual table] implementation what the [ON CONFLICT] mode
  7432. ** is for the SQL statement being evaluated.
  7433. **
  7434. ** Note that the [SQLITE_IGNORE] constant is also used as a potential
  7435. ** return value from the [sqlite3_set_authorizer()] callback and that
  7436. ** [SQLITE_ABORT] is also a [result code].
  7437. */
  7438. #define SQLITE_ROLLBACK 1
  7439. /* #define SQLITE_IGNORE 2 // Also used by sqlite3_authorizer() callback */
  7440. #define SQLITE_FAIL 3
  7441. /* #define SQLITE_ABORT 4 // Also an error code */
  7442. #define SQLITE_REPLACE 5
  7443. /*
  7444. ** CAPI3REF: Prepared Statement Scan Status Opcodes
  7445. ** KEYWORDS: {scanstatus options}
  7446. **
  7447. ** The following constants can be used for the T parameter to the
  7448. ** [sqlite3_stmt_scanstatus(S,X,T,V)] interface. Each constant designates a
  7449. ** different metric for sqlite3_stmt_scanstatus() to return.
  7450. **
  7451. ** When the value returned to V is a string, space to hold that string is
  7452. ** managed by the prepared statement S and will be automatically freed when
  7453. ** S is finalized.
  7454. **
  7455. ** <dl>
  7456. ** [[SQLITE_SCANSTAT_NLOOP]] <dt>SQLITE_SCANSTAT_NLOOP</dt>
  7457. ** <dd>^The [sqlite3_int64] variable pointed to by the T parameter will be
  7458. ** set to the total number of times that the X-th loop has run.</dd>
  7459. **
  7460. ** [[SQLITE_SCANSTAT_NVISIT]] <dt>SQLITE_SCANSTAT_NVISIT</dt>
  7461. ** <dd>^The [sqlite3_int64] variable pointed to by the T parameter will be set
  7462. ** to the total number of rows examined by all iterations of the X-th loop.</dd>
  7463. **
  7464. ** [[SQLITE_SCANSTAT_EST]] <dt>SQLITE_SCANSTAT_EST</dt>
  7465. ** <dd>^The "double" variable pointed to by the T parameter will be set to the
  7466. ** query planner's estimate for the average number of rows output from each
  7467. ** iteration of the X-th loop. If the query planner's estimates was accurate,
  7468. ** then this value will approximate the quotient NVISIT/NLOOP and the
  7469. ** product of this value for all prior loops with the same SELECTID will
  7470. ** be the NLOOP value for the current loop.
  7471. **
  7472. ** [[SQLITE_SCANSTAT_NAME]] <dt>SQLITE_SCANSTAT_NAME</dt>
  7473. ** <dd>^The "const char *" variable pointed to by the T parameter will be set
  7474. ** to a zero-terminated UTF-8 string containing the name of the index or table
  7475. ** used for the X-th loop.
  7476. **
  7477. ** [[SQLITE_SCANSTAT_EXPLAIN]] <dt>SQLITE_SCANSTAT_EXPLAIN</dt>
  7478. ** <dd>^The "const char *" variable pointed to by the T parameter will be set
  7479. ** to a zero-terminated UTF-8 string containing the [EXPLAIN QUERY PLAN]
  7480. ** description for the X-th loop.
  7481. **
  7482. ** [[SQLITE_SCANSTAT_SELECTID]] <dt>SQLITE_SCANSTAT_SELECT</dt>
  7483. ** <dd>^The "int" variable pointed to by the T parameter will be set to the
  7484. ** "select-id" for the X-th loop. The select-id identifies which query or
  7485. ** subquery the loop is part of. The main query has a select-id of zero.
  7486. ** The select-id is the same value as is output in the first column
  7487. ** of an [EXPLAIN QUERY PLAN] query.
  7488. ** </dl>
  7489. */
  7490. #define SQLITE_SCANSTAT_NLOOP 0
  7491. #define SQLITE_SCANSTAT_NVISIT 1
  7492. #define SQLITE_SCANSTAT_EST 2
  7493. #define SQLITE_SCANSTAT_NAME 3
  7494. #define SQLITE_SCANSTAT_EXPLAIN 4
  7495. #define SQLITE_SCANSTAT_SELECTID 5
  7496. /*
  7497. ** CAPI3REF: Prepared Statement Scan Status
  7498. ** METHOD: sqlite3_stmt
  7499. **
  7500. ** This interface returns information about the predicted and measured
  7501. ** performance for pStmt. Advanced applications can use this
  7502. ** interface to compare the predicted and the measured performance and
  7503. ** issue warnings and/or rerun [ANALYZE] if discrepancies are found.
  7504. **
  7505. ** Since this interface is expected to be rarely used, it is only
  7506. ** available if SQLite is compiled using the [SQLITE_ENABLE_STMT_SCANSTATUS]
  7507. ** compile-time option.
  7508. **
  7509. ** The "iScanStatusOp" parameter determines which status information to return.
  7510. ** The "iScanStatusOp" must be one of the [scanstatus options] or the behavior
  7511. ** of this interface is undefined.
  7512. ** ^The requested measurement is written into a variable pointed to by
  7513. ** the "pOut" parameter.
  7514. ** Parameter "idx" identifies the specific loop to retrieve statistics for.
  7515. ** Loops are numbered starting from zero. ^If idx is out of range - less than
  7516. ** zero or greater than or equal to the total number of loops used to implement
  7517. ** the statement - a non-zero value is returned and the variable that pOut
  7518. ** points to is unchanged.
  7519. **
  7520. ** ^Statistics might not be available for all loops in all statements. ^In cases
  7521. ** where there exist loops with no available statistics, this function behaves
  7522. ** as if the loop did not exist - it returns non-zero and leave the variable
  7523. ** that pOut points to unchanged.
  7524. **
  7525. ** See also: [sqlite3_stmt_scanstatus_reset()]
  7526. */
  7527. SQLITE_API int SQLITE_STDCALL sqlite3_stmt_scanstatus(
  7528. sqlite3_stmt *pStmt, /* Prepared statement for which info desired */
  7529. int idx, /* Index of loop to report on */
  7530. int iScanStatusOp, /* Information desired. SQLITE_SCANSTAT_* */
  7531. void *pOut /* Result written here */
  7532. );
  7533. /*
  7534. ** CAPI3REF: Zero Scan-Status Counters
  7535. ** METHOD: sqlite3_stmt
  7536. **
  7537. ** ^Zero all [sqlite3_stmt_scanstatus()] related event counters.
  7538. **
  7539. ** This API is only available if the library is built with pre-processor
  7540. ** symbol [SQLITE_ENABLE_STMT_SCANSTATUS] defined.
  7541. */
  7542. SQLITE_API void SQLITE_STDCALL sqlite3_stmt_scanstatus_reset(sqlite3_stmt*);
  7543. /*
  7544. ** Undo the hack that converts floating point types to integer for
  7545. ** builds on processors without floating point support.
  7546. */
  7547. #ifdef SQLITE_OMIT_FLOATING_POINT
  7548. # undef double
  7549. #endif
  7550. #ifdef __cplusplus
  7551. } /* End of the 'extern "C"' block */
  7552. #endif
  7553. #endif /* _SQLITE3_H_ */
  7554. /*
  7555. ** 2010 August 30
  7556. **
  7557. ** The author disclaims copyright to this source code. In place of
  7558. ** a legal notice, here is a blessing:
  7559. **
  7560. ** May you do good and not evil.
  7561. ** May you find forgiveness for yourself and forgive others.
  7562. ** May you share freely, never taking more than you give.
  7563. **
  7564. *************************************************************************
  7565. */
  7566. #ifndef _SQLITE3RTREE_H_
  7567. #define _SQLITE3RTREE_H_
  7568. #ifdef __cplusplus
  7569. extern "C" {
  7570. #endif
  7571. typedef struct sqlite3_rtree_geometry sqlite3_rtree_geometry;
  7572. typedef struct sqlite3_rtree_query_info sqlite3_rtree_query_info;
  7573. /* The double-precision datatype used by RTree depends on the
  7574. ** SQLITE_RTREE_INT_ONLY compile-time option.
  7575. */
  7576. #ifdef SQLITE_RTREE_INT_ONLY
  7577. typedef sqlite3_int64 sqlite3_rtree_dbl;
  7578. #else
  7579. typedef double sqlite3_rtree_dbl;
  7580. #endif
  7581. /*
  7582. ** Register a geometry callback named zGeom that can be used as part of an
  7583. ** R-Tree geometry query as follows:
  7584. **
  7585. ** SELECT ... FROM <rtree> WHERE <rtree col> MATCH $zGeom(... params ...)
  7586. */
  7587. SQLITE_API int SQLITE_STDCALL sqlite3_rtree_geometry_callback(
  7588. sqlite3 *db,
  7589. const char *zGeom,
  7590. int (*xGeom)(sqlite3_rtree_geometry*, int, sqlite3_rtree_dbl*,int*),
  7591. void *pContext
  7592. );
  7593. /*
  7594. ** A pointer to a structure of the following type is passed as the first
  7595. ** argument to callbacks registered using rtree_geometry_callback().
  7596. */
  7597. struct sqlite3_rtree_geometry {
  7598. void *pContext; /* Copy of pContext passed to s_r_g_c() */
  7599. int nParam; /* Size of array aParam[] */
  7600. sqlite3_rtree_dbl *aParam; /* Parameters passed to SQL geom function */
  7601. void *pUser; /* Callback implementation user data */
  7602. void (*xDelUser)(void *); /* Called by SQLite to clean up pUser */
  7603. };
  7604. /*
  7605. ** Register a 2nd-generation geometry callback named zScore that can be
  7606. ** used as part of an R-Tree geometry query as follows:
  7607. **
  7608. ** SELECT ... FROM <rtree> WHERE <rtree col> MATCH $zQueryFunc(... params ...)
  7609. */
  7610. SQLITE_API int SQLITE_STDCALL sqlite3_rtree_query_callback(
  7611. sqlite3 *db,
  7612. const char *zQueryFunc,
  7613. int (*xQueryFunc)(sqlite3_rtree_query_info*),
  7614. void *pContext,
  7615. void (*xDestructor)(void*)
  7616. );
  7617. /*
  7618. ** A pointer to a structure of the following type is passed as the
  7619. ** argument to scored geometry callback registered using
  7620. ** sqlite3_rtree_query_callback().
  7621. **
  7622. ** Note that the first 5 fields of this structure are identical to
  7623. ** sqlite3_rtree_geometry. This structure is a subclass of
  7624. ** sqlite3_rtree_geometry.
  7625. */
  7626. struct sqlite3_rtree_query_info {
  7627. void *pContext; /* pContext from when function registered */
  7628. int nParam; /* Number of function parameters */
  7629. sqlite3_rtree_dbl *aParam; /* value of function parameters */
  7630. void *pUser; /* callback can use this, if desired */
  7631. void (*xDelUser)(void*); /* function to free pUser */
  7632. sqlite3_rtree_dbl *aCoord; /* Coordinates of node or entry to check */
  7633. unsigned int *anQueue; /* Number of pending entries in the queue */
  7634. int nCoord; /* Number of coordinates */
  7635. int iLevel; /* Level of current node or entry */
  7636. int mxLevel; /* The largest iLevel value in the tree */
  7637. sqlite3_int64 iRowid; /* Rowid for current entry */
  7638. sqlite3_rtree_dbl rParentScore; /* Score of parent node */
  7639. int eParentWithin; /* Visibility of parent node */
  7640. int eWithin; /* OUT: Visiblity */
  7641. sqlite3_rtree_dbl rScore; /* OUT: Write the score here */
  7642. /* The following fields are only available in 3.8.11 and later */
  7643. sqlite3_value **apSqlParam; /* Original SQL values of parameters */
  7644. };
  7645. /*
  7646. ** Allowed values for sqlite3_rtree_query.eWithin and .eParentWithin.
  7647. */
  7648. #define NOT_WITHIN 0 /* Object completely outside of query region */
  7649. #define PARTLY_WITHIN 1 /* Object partially overlaps query region */
  7650. #define FULLY_WITHIN 2 /* Object fully contained within query region */
  7651. #ifdef __cplusplus
  7652. } /* end of the 'extern "C"' block */
  7653. #endif
  7654. #endif /* ifndef _SQLITE3RTREE_H_ */