sqlite3.h 251 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610161116121613161416151616161716181619162016211622162316241625162616271628162916301631163216331634163516361637163816391640164116421643164416451646164716481649165016511652165316541655165616571658165916601661166216631664166516661667166816691670167116721673167416751676167716781679168016811682168316841685168616871688168916901691169216931694169516961697169816991700170117021703170417051706170717081709171017111712171317141715171617171718171917201721172217231724172517261727172817291730173117321733173417351736173717381739174017411742174317441745174617471748174917501751175217531754175517561757175817591760176117621763176417651766176717681769177017711772177317741775177617771778177917801781178217831784178517861787178817891790179117921793179417951796179717981799180018011802180318041805180618071808180918101811181218131814181518161817181818191820182118221823182418251826182718281829183018311832183318341835183618371838183918401841184218431844184518461847184818491850185118521853185418551856185718581859186018611862186318641865186618671868186918701871187218731874187518761877187818791880188118821883188418851886188718881889189018911892189318941895189618971898189919001901190219031904190519061907190819091910191119121913191419151916191719181919192019211922192319241925192619271928192919301931193219331934193519361937193819391940194119421943194419451946194719481949195019511952195319541955195619571958195919601961196219631964196519661967196819691970197119721973197419751976197719781979198019811982198319841985198619871988198919901991199219931994199519961997199819992000200120022003200420052006200720082009201020112012201320142015201620172018201920202021202220232024202520262027202820292030203120322033203420352036203720382039204020412042204320442045204620472048204920502051205220532054205520562057205820592060206120622063206420652066206720682069207020712072207320742075207620772078207920802081208220832084208520862087208820892090209120922093209420952096209720982099210021012102210321042105210621072108210921102111211221132114211521162117211821192120212121222123212421252126212721282129213021312132213321342135213621372138213921402141214221432144214521462147214821492150215121522153215421552156215721582159216021612162216321642165216621672168216921702171217221732174217521762177217821792180218121822183218421852186218721882189219021912192219321942195219621972198219922002201220222032204220522062207220822092210221122122213221422152216221722182219222022212222222322242225222622272228222922302231223222332234223522362237223822392240224122422243224422452246224722482249225022512252225322542255225622572258225922602261226222632264226522662267226822692270227122722273227422752276227722782279228022812282228322842285228622872288228922902291229222932294229522962297229822992300230123022303230423052306230723082309231023112312231323142315231623172318231923202321232223232324232523262327232823292330233123322333233423352336233723382339234023412342234323442345234623472348234923502351235223532354235523562357235823592360236123622363236423652366236723682369237023712372237323742375237623772378237923802381238223832384238523862387238823892390239123922393239423952396239723982399240024012402240324042405240624072408240924102411241224132414241524162417241824192420242124222423242424252426242724282429243024312432243324342435243624372438243924402441244224432444244524462447244824492450245124522453245424552456245724582459246024612462246324642465246624672468246924702471247224732474247524762477247824792480248124822483248424852486248724882489249024912492249324942495249624972498249925002501250225032504250525062507250825092510251125122513251425152516251725182519252025212522252325242525252625272528252925302531253225332534253525362537253825392540254125422543254425452546254725482549255025512552255325542555255625572558255925602561256225632564256525662567256825692570257125722573257425752576257725782579258025812582258325842585258625872588258925902591259225932594259525962597259825992600260126022603260426052606260726082609261026112612261326142615261626172618261926202621262226232624262526262627262826292630263126322633263426352636263726382639264026412642264326442645264626472648264926502651265226532654265526562657265826592660266126622663266426652666266726682669267026712672267326742675267626772678267926802681268226832684268526862687268826892690269126922693269426952696269726982699270027012702270327042705270627072708270927102711271227132714271527162717271827192720272127222723272427252726272727282729273027312732273327342735273627372738273927402741274227432744274527462747274827492750275127522753275427552756275727582759276027612762276327642765276627672768276927702771277227732774277527762777277827792780278127822783278427852786278727882789279027912792279327942795279627972798279928002801280228032804280528062807280828092810281128122813281428152816281728182819282028212822282328242825282628272828282928302831283228332834283528362837283828392840284128422843284428452846284728482849285028512852285328542855285628572858285928602861286228632864286528662867286828692870287128722873287428752876287728782879288028812882288328842885288628872888288928902891289228932894289528962897289828992900290129022903290429052906290729082909291029112912291329142915291629172918291929202921292229232924292529262927292829292930293129322933293429352936293729382939294029412942294329442945294629472948294929502951295229532954295529562957295829592960296129622963296429652966296729682969297029712972297329742975297629772978297929802981298229832984298529862987298829892990299129922993299429952996299729982999300030013002300330043005300630073008300930103011301230133014301530163017301830193020302130223023302430253026302730283029303030313032303330343035303630373038303930403041304230433044304530463047304830493050305130523053305430553056305730583059306030613062306330643065306630673068306930703071307230733074307530763077307830793080308130823083308430853086308730883089309030913092309330943095309630973098309931003101310231033104310531063107310831093110311131123113311431153116311731183119312031213122312331243125312631273128312931303131313231333134313531363137313831393140314131423143314431453146314731483149315031513152315331543155315631573158315931603161316231633164316531663167316831693170317131723173317431753176317731783179318031813182318331843185318631873188318931903191319231933194319531963197319831993200320132023203320432053206320732083209321032113212321332143215321632173218321932203221322232233224322532263227322832293230323132323233323432353236323732383239324032413242324332443245324632473248324932503251325232533254325532563257325832593260326132623263326432653266326732683269327032713272327332743275327632773278327932803281328232833284328532863287328832893290329132923293329432953296329732983299330033013302330333043305330633073308330933103311331233133314331533163317331833193320332133223323332433253326332733283329333033313332333333343335333633373338333933403341334233433344334533463347334833493350335133523353335433553356335733583359336033613362336333643365336633673368336933703371337233733374337533763377337833793380338133823383338433853386338733883389339033913392339333943395339633973398339934003401340234033404340534063407340834093410341134123413341434153416341734183419342034213422342334243425342634273428342934303431343234333434343534363437343834393440344134423443344434453446344734483449345034513452345334543455345634573458345934603461346234633464346534663467346834693470347134723473347434753476347734783479348034813482348334843485348634873488348934903491349234933494349534963497349834993500350135023503350435053506350735083509351035113512351335143515351635173518351935203521352235233524352535263527352835293530353135323533353435353536353735383539354035413542354335443545354635473548354935503551355235533554355535563557355835593560356135623563356435653566356735683569357035713572357335743575357635773578357935803581358235833584358535863587358835893590359135923593359435953596359735983599360036013602360336043605360636073608360936103611361236133614361536163617361836193620362136223623362436253626362736283629363036313632363336343635363636373638363936403641364236433644364536463647364836493650365136523653365436553656365736583659366036613662366336643665366636673668366936703671367236733674367536763677367836793680368136823683368436853686368736883689369036913692369336943695369636973698369937003701370237033704370537063707370837093710371137123713371437153716371737183719372037213722372337243725372637273728372937303731373237333734373537363737373837393740374137423743374437453746374737483749375037513752375337543755375637573758375937603761376237633764376537663767376837693770377137723773377437753776377737783779378037813782378337843785378637873788378937903791379237933794379537963797379837993800380138023803380438053806380738083809381038113812381338143815381638173818381938203821382238233824382538263827382838293830383138323833383438353836383738383839384038413842384338443845384638473848384938503851385238533854385538563857385838593860386138623863386438653866386738683869387038713872387338743875387638773878387938803881388238833884388538863887388838893890389138923893389438953896389738983899390039013902390339043905390639073908390939103911391239133914391539163917391839193920392139223923392439253926392739283929393039313932393339343935393639373938393939403941394239433944394539463947394839493950395139523953395439553956395739583959396039613962396339643965396639673968396939703971397239733974397539763977397839793980398139823983398439853986398739883989399039913992399339943995399639973998399940004001400240034004400540064007400840094010401140124013401440154016401740184019402040214022402340244025402640274028402940304031403240334034403540364037403840394040404140424043404440454046404740484049405040514052405340544055405640574058405940604061406240634064406540664067406840694070407140724073407440754076407740784079408040814082408340844085408640874088408940904091409240934094409540964097409840994100410141024103410441054106410741084109411041114112411341144115411641174118411941204121412241234124412541264127412841294130413141324133413441354136413741384139414041414142414341444145414641474148414941504151415241534154415541564157415841594160416141624163416441654166416741684169417041714172417341744175417641774178417941804181418241834184418541864187418841894190419141924193419441954196419741984199420042014202420342044205420642074208420942104211421242134214421542164217421842194220422142224223422442254226422742284229423042314232423342344235423642374238423942404241424242434244424542464247424842494250425142524253425442554256425742584259426042614262426342644265426642674268426942704271427242734274427542764277427842794280428142824283428442854286428742884289429042914292429342944295429642974298429943004301430243034304430543064307430843094310431143124313431443154316431743184319432043214322432343244325432643274328432943304331433243334334433543364337433843394340434143424343434443454346434743484349435043514352435343544355435643574358435943604361436243634364436543664367436843694370437143724373437443754376437743784379438043814382438343844385438643874388438943904391439243934394439543964397439843994400440144024403440444054406440744084409441044114412441344144415441644174418441944204421442244234424442544264427442844294430443144324433443444354436443744384439444044414442444344444445444644474448444944504451445244534454445544564457445844594460446144624463446444654466446744684469447044714472447344744475447644774478447944804481448244834484448544864487448844894490449144924493449444954496449744984499450045014502450345044505450645074508450945104511451245134514451545164517451845194520452145224523452445254526452745284529453045314532453345344535453645374538453945404541454245434544454545464547454845494550455145524553455445554556455745584559456045614562456345644565456645674568456945704571457245734574457545764577457845794580458145824583458445854586458745884589459045914592459345944595459645974598459946004601460246034604460546064607460846094610461146124613461446154616461746184619462046214622462346244625462646274628462946304631463246334634463546364637463846394640464146424643464446454646464746484649465046514652465346544655465646574658465946604661466246634664466546664667466846694670467146724673467446754676467746784679468046814682468346844685468646874688468946904691469246934694469546964697469846994700470147024703470447054706470747084709471047114712471347144715471647174718471947204721472247234724472547264727472847294730473147324733473447354736473747384739474047414742474347444745474647474748474947504751475247534754475547564757475847594760476147624763476447654766476747684769477047714772477347744775477647774778477947804781478247834784478547864787478847894790479147924793479447954796479747984799480048014802480348044805480648074808480948104811481248134814481548164817481848194820482148224823482448254826482748284829483048314832483348344835483648374838483948404841484248434844484548464847484848494850485148524853485448554856485748584859486048614862486348644865486648674868486948704871487248734874487548764877487848794880488148824883488448854886488748884889489048914892489348944895489648974898489949004901490249034904490549064907490849094910491149124913491449154916491749184919492049214922492349244925492649274928492949304931493249334934493549364937493849394940494149424943494449454946494749484949495049514952495349544955495649574958495949604961496249634964496549664967496849694970497149724973497449754976497749784979498049814982498349844985498649874988498949904991499249934994499549964997499849995000500150025003500450055006500750085009501050115012501350145015501650175018501950205021502250235024502550265027502850295030503150325033503450355036503750385039504050415042504350445045504650475048504950505051505250535054505550565057505850595060506150625063506450655066506750685069507050715072507350745075507650775078507950805081508250835084508550865087508850895090509150925093509450955096509750985099510051015102510351045105510651075108510951105111511251135114511551165117511851195120512151225123512451255126512751285129513051315132513351345135513651375138513951405141514251435144514551465147514851495150515151525153515451555156515751585159516051615162516351645165516651675168516951705171517251735174517551765177517851795180518151825183518451855186518751885189519051915192519351945195519651975198519952005201520252035204520552065207520852095210521152125213521452155216521752185219522052215222522352245225522652275228522952305231523252335234523552365237523852395240524152425243524452455246524752485249525052515252525352545255525652575258525952605261526252635264526552665267526852695270527152725273527452755276527752785279528052815282528352845285528652875288528952905291529252935294529552965297529852995300530153025303530453055306530753085309531053115312531353145315531653175318531953205321532253235324532553265327532853295330533153325333533453355336533753385339534053415342534353445345534653475348534953505351535253535354535553565357535853595360536153625363536453655366536753685369537053715372537353745375537653775378537953805381538253835384538553865387538853895390539153925393539453955396539753985399540054015402540354045405540654075408540954105411541254135414541554165417541854195420542154225423542454255426542754285429543054315432543354345435543654375438543954405441544254435444544554465447544854495450545154525453545454555456545754585459546054615462546354645465546654675468546954705471547254735474547554765477547854795480548154825483548454855486548754885489
  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 to make minor changes if
  22. ** 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 suppose 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. ** @(#) $Id: sqlite3.h 1135 2012-04-10 09:55:16Z fujihiro $
  34. */
  35. #ifndef _SQLITE3_H_
  36. #define _SQLITE3_H_
  37. #include <stdarg.h> /* Needed for the definition of va_list */
  38. /*
  39. ** Make sure we can call this stuff from C++.
  40. */
  41. #ifdef __cplusplus
  42. extern "C" {
  43. #endif
  44. /*
  45. ** Add the ability to override 'extern'
  46. */
  47. #ifndef SQLITE_EXTERN
  48. # define SQLITE_EXTERN extern
  49. #endif
  50. /*
  51. ** These no-op macros are used in front of interfaces to mark those
  52. ** interfaces as either deprecated or experimental. New applications
  53. ** should not use deprecated intrfaces - they are support for backwards
  54. ** compatibility only. Application writers should be aware that
  55. ** experimental interfaces are subject to change in point releases.
  56. **
  57. ** These macros used to resolve to various kinds of compiler magic that
  58. ** would generate warning messages when they were used. But that
  59. ** compiler magic ended up generating such a flurry of bug reports
  60. ** that we have taken it all out and gone back to using simple
  61. ** noop macros.
  62. */
  63. #define SQLITE_DEPRECATED
  64. #define SQLITE_EXPERIMENTAL
  65. /*
  66. ** Ensure these symbols were not defined by some previous header file.
  67. */
  68. #ifdef SQLITE_VERSION
  69. # undef SQLITE_VERSION
  70. #endif
  71. #ifdef SQLITE_VERSION_NUMBER
  72. # undef SQLITE_VERSION_NUMBER
  73. #endif
  74. /*
  75. ** CAPI3REF: Compile-Time Library Version Numbers {H10010} <S60100>
  76. **
  77. ** The SQLITE_VERSION and SQLITE_VERSION_NUMBER #defines in
  78. ** the sqlite3.h file specify the version of SQLite with which
  79. ** that header file is associated.
  80. **
  81. ** The "version" of SQLite is a string of the form "X.Y.Z".
  82. ** The phrase "alpha" or "beta" might be appended after the Z.
  83. ** The X value is major version number always 3 in SQLite3.
  84. ** The X value only changes when backwards compatibility is
  85. ** broken and we intend to never break backwards compatibility.
  86. ** The Y value is the minor version number and only changes when
  87. ** there are major feature enhancements that are forwards compatible
  88. ** but not backwards compatible.
  89. ** The Z value is the release number and is incremented with
  90. ** each release but resets back to 0 whenever Y is incremented.
  91. **
  92. ** See also: [sqlite3_libversion()] and [sqlite3_libversion_number()].
  93. **
  94. ** Requirements: [H10011] [H10014]
  95. */
  96. #define SQLITE_VERSION "3.6.12"
  97. #define SQLITE_VERSION_NUMBER 3006012
  98. /*
  99. ** CAPI3REF: Run-Time Library Version Numbers {H10020} <S60100>
  100. ** KEYWORDS: sqlite3_version
  101. **
  102. ** These features provide the same information as the [SQLITE_VERSION]
  103. ** and [SQLITE_VERSION_NUMBER] #defines in the header, but are associated
  104. ** with the library instead of the header file. Cautious programmers might
  105. ** include a check in their application to verify that
  106. ** sqlite3_libversion_number() always returns the value
  107. ** [SQLITE_VERSION_NUMBER].
  108. **
  109. ** The sqlite3_libversion() function returns the same information as is
  110. ** in the sqlite3_version[] string constant. The function is provided
  111. ** for use in DLLs since DLL users usually do not have direct access to string
  112. ** constants within the DLL.
  113. **
  114. ** Requirements: [H10021] [H10022] [H10023]
  115. */
  116. SQLITE_EXTERN const char sqlite3_version[];
  117. const char *sqlite3_libversion(void);
  118. int sqlite3_libversion_number(void);
  119. /*
  120. ** CAPI3REF: Test To See If The Library Is Threadsafe {H10100} <S60100>
  121. **
  122. ** SQLite can be compiled with or without mutexes. When
  123. ** the [SQLITE_THREADSAFE] C preprocessor macro 1 or 2, mutexes
  124. ** are enabled and SQLite is threadsafe. When the
  125. ** [SQLITE_THREADSAFE] macro is 0,
  126. ** the mutexes are omitted. Without the mutexes, it is not safe
  127. ** to use SQLite concurrently from more than one thread.
  128. **
  129. ** Enabling mutexes incurs a measurable performance penalty.
  130. ** So if speed is of utmost importance, it makes sense to disable
  131. ** the mutexes. But for maximum safety, mutexes should be enabled.
  132. ** The default behavior is for mutexes to be enabled.
  133. **
  134. ** This interface can be used by a program to make sure that the
  135. ** version of SQLite that it is linking against was compiled with
  136. ** the desired setting of the [SQLITE_THREADSAFE] macro.
  137. **
  138. ** This interface only reports on the compile-time mutex setting
  139. ** of the [SQLITE_THREADSAFE] flag. If SQLite is compiled with
  140. ** SQLITE_THREADSAFE=1 then mutexes are enabled by default but
  141. ** can be fully or partially disabled using a call to [sqlite3_config()]
  142. ** with the verbs [SQLITE_CONFIG_SINGLETHREAD], [SQLITE_CONFIG_MULTITHREAD],
  143. ** or [SQLITE_CONFIG_MUTEX]. The return value of this function shows
  144. ** only the default compile-time setting, not any run-time changes
  145. ** to that setting.
  146. **
  147. ** See the [threading mode] documentation for additional information.
  148. **
  149. ** Requirements: [H10101] [H10102]
  150. */
  151. int sqlite3_threadsafe(void);
  152. /*
  153. ** CAPI3REF: Database Connection Handle {H12000} <S40200>
  154. ** KEYWORDS: {database connection} {database connections}
  155. **
  156. ** Each open SQLite database is represented by a pointer to an instance of
  157. ** the opaque structure named "sqlite3". It is useful to think of an sqlite3
  158. ** pointer as an object. The [sqlite3_open()], [sqlite3_open16()], and
  159. ** [sqlite3_open_v2()] interfaces are its constructors, and [sqlite3_close()]
  160. ** is its destructor. There are many other interfaces (such as
  161. ** [sqlite3_prepare_v2()], [sqlite3_create_function()], and
  162. ** [sqlite3_busy_timeout()] to name but three) that are methods on an
  163. ** sqlite3 object.
  164. */
  165. typedef struct sqlite3 sqlite3;
  166. /*
  167. ** CAPI3REF: 64-Bit Integer Types {H10200} <S10110>
  168. ** KEYWORDS: sqlite_int64 sqlite_uint64
  169. **
  170. ** Because there is no cross-platform way to specify 64-bit integer types
  171. ** SQLite includes typedefs for 64-bit signed and unsigned integers.
  172. **
  173. ** The sqlite3_int64 and sqlite3_uint64 are the preferred type definitions.
  174. ** The sqlite_int64 and sqlite_uint64 types are supported for backwards
  175. ** compatibility only.
  176. **
  177. ** Requirements: [H10201] [H10202]
  178. */
  179. #ifdef SQLITE_INT64_TYPE
  180. typedef SQLITE_INT64_TYPE sqlite_int64;
  181. typedef unsigned SQLITE_INT64_TYPE sqlite_uint64;
  182. #elif defined(_MSC_VER) || defined(__BORLANDC__)
  183. typedef __int64 sqlite_int64;
  184. typedef unsigned __int64 sqlite_uint64;
  185. #else
  186. typedef long long int sqlite_int64;
  187. typedef unsigned long long int sqlite_uint64;
  188. #endif
  189. typedef sqlite_int64 sqlite3_int64;
  190. typedef sqlite_uint64 sqlite3_uint64;
  191. /*
  192. ** If compiling for a processor that lacks floating point support,
  193. ** substitute integer for floating-point.
  194. */
  195. #ifdef SQLITE_OMIT_FLOATING_POINT
  196. # define double sqlite3_int64
  197. #endif
  198. /*
  199. ** CAPI3REF: Closing A Database Connection {H12010} <S30100><S40200>
  200. **
  201. ** This routine is the destructor for the [sqlite3] object.
  202. **
  203. ** Applications should [sqlite3_finalize | finalize] all [prepared statements]
  204. ** and [sqlite3_blob_close | close] all [BLOB handles] associated with
  205. ** the [sqlite3] object prior to attempting to close the object.
  206. ** The [sqlite3_next_stmt()] interface can be used to locate all
  207. ** [prepared statements] associated with a [database connection] if desired.
  208. ** Typical code might look like this:
  209. **
  210. ** <blockquote><pre>
  211. ** sqlite3_stmt *pStmt;
  212. ** while( (pStmt = sqlite3_next_stmt(db, 0))!=0 ){
  213. ** &nbsp; sqlite3_finalize(pStmt);
  214. ** }
  215. ** </pre></blockquote>
  216. **
  217. ** If [sqlite3_close()] is invoked while a transaction is open,
  218. ** the transaction is automatically rolled back.
  219. **
  220. ** The C parameter to [sqlite3_close(C)] must be either a NULL
  221. ** pointer or an [sqlite3] object pointer obtained
  222. ** from [sqlite3_open()], [sqlite3_open16()], or
  223. ** [sqlite3_open_v2()], and not previously closed.
  224. **
  225. ** Requirements:
  226. ** [H12011] [H12012] [H12013] [H12014] [H12015] [H12019]
  227. */
  228. int sqlite3_close(sqlite3 *);
  229. /*
  230. ** The type for a callback function.
  231. ** This is legacy and deprecated. It is included for historical
  232. ** compatibility and is not documented.
  233. */
  234. typedef int (*sqlite3_callback)(void*,int,char**, char**);
  235. /*
  236. ** CAPI3REF: One-Step Query Execution Interface {H12100} <S10000>
  237. **
  238. ** The sqlite3_exec() interface is a convenient way of running one or more
  239. ** SQL statements without having to write a lot of C code. The UTF-8 encoded
  240. ** SQL statements are passed in as the second parameter to sqlite3_exec().
  241. ** The statements are evaluated one by one until either an error or
  242. ** an interrupt is encountered, or until they are all done. The 3rd parameter
  243. ** is an optional callback that is invoked once for each row of any query
  244. ** results produced by the SQL statements. The 5th parameter tells where
  245. ** to write any error messages.
  246. **
  247. ** The error message passed back through the 5th parameter is held
  248. ** in memory obtained from [sqlite3_malloc()]. To avoid a memory leak,
  249. ** the calling application should call [sqlite3_free()] on any error
  250. ** message returned through the 5th parameter when it has finished using
  251. ** the error message.
  252. **
  253. ** If the SQL statement in the 2nd parameter is NULL or an empty string
  254. ** or a string containing only whitespace and comments, then no SQL
  255. ** statements are evaluated and the database is not changed.
  256. **
  257. ** The sqlite3_exec() interface is implemented in terms of
  258. ** [sqlite3_prepare_v2()], [sqlite3_step()], and [sqlite3_finalize()].
  259. ** The sqlite3_exec() routine does nothing to the database that cannot be done
  260. ** by [sqlite3_prepare_v2()], [sqlite3_step()], and [sqlite3_finalize()].
  261. **
  262. ** The first parameter to [sqlite3_exec()] must be an valid and open
  263. ** [database connection].
  264. **
  265. ** The database connection must not be closed while
  266. ** [sqlite3_exec()] is running.
  267. **
  268. ** The calling function should use [sqlite3_free()] to free
  269. ** the memory that *errmsg is left pointing at once the error
  270. ** message is no longer needed.
  271. **
  272. ** The SQL statement text in the 2nd parameter to [sqlite3_exec()]
  273. ** must remain unchanged while [sqlite3_exec()] is running.
  274. **
  275. ** Requirements:
  276. ** [H12101] [H12102] [H12104] [H12105] [H12107] [H12110] [H12113] [H12116]
  277. ** [H12119] [H12122] [H12125] [H12131] [H12134] [H12137] [H12138]
  278. */
  279. int sqlite3_exec(
  280. sqlite3*, /* An open database */
  281. const char *sql, /* SQL to be evaluated */
  282. int (*callback)(void*,int,char**,char**), /* Callback function */
  283. void *, /* 1st argument to callback */
  284. char **errmsg /* Error msg written here */
  285. );
  286. /*
  287. ** CAPI3REF: Result Codes {H10210} <S10700>
  288. ** KEYWORDS: SQLITE_OK {error code} {error codes}
  289. ** KEYWORDS: {result code} {result codes}
  290. **
  291. ** Many SQLite functions return an integer result code from the set shown
  292. ** here in order to indicates success or failure.
  293. **
  294. ** New error codes may be added in future versions of SQLite.
  295. **
  296. ** See also: [SQLITE_IOERR_READ | extended result codes]
  297. */
  298. #define SQLITE_OK 0 /* Successful result */
  299. /* beginning-of-error-codes */
  300. #define SQLITE_ERROR 1 /* SQL error or missing database */
  301. #define SQLITE_INTERNAL 2 /* Internal logic error in SQLite */
  302. #define SQLITE_PERM 3 /* Access permission denied */
  303. #define SQLITE_ABORT 4 /* Callback routine requested an abort */
  304. #define SQLITE_BUSY 5 /* The database file is locked */
  305. #define SQLITE_LOCKED 6 /* A table in the database is locked */
  306. #define SQLITE_NOMEM 7 /* A malloc() failed */
  307. #define SQLITE_READONLY 8 /* Attempt to write a readonly database */
  308. #define SQLITE_INTERRUPT 9 /* Operation terminated by sqlite3_interrupt()*/
  309. #define SQLITE_IOERR 10 /* Some kind of disk I/O error occurred */
  310. #define SQLITE_CORRUPT 11 /* The database disk image is malformed */
  311. #define SQLITE_NOTFOUND 12 /* NOT USED. Table or record not found */
  312. #define SQLITE_FULL 13 /* Insertion failed because database is full */
  313. #define SQLITE_CANTOPEN 14 /* Unable to open the database file */
  314. #define SQLITE_PROTOCOL 15 /* NOT USED. Database lock protocol error */
  315. #define SQLITE_EMPTY 16 /* Database is empty */
  316. #define SQLITE_SCHEMA 17 /* The database schema changed */
  317. #define SQLITE_TOOBIG 18 /* String or BLOB exceeds size limit */
  318. #define SQLITE_CONSTRAINT 19 /* Abort due to constraint violation */
  319. #define SQLITE_MISMATCH 20 /* Data type mismatch */
  320. #define SQLITE_MISUSE 21 /* Library used incorrectly */
  321. #define SQLITE_NOLFS 22 /* Uses OS features not supported on host */
  322. #define SQLITE_AUTH 23 /* Authorization denied */
  323. #define SQLITE_FORMAT 24 /* Auxiliary database format error */
  324. #define SQLITE_RANGE 25 /* 2nd parameter to sqlite3_bind out of range */
  325. #define SQLITE_NOTADB 26 /* File opened that is not a database file */
  326. #define SQLITE_ROW 100 /* sqlite3_step() has another row ready */
  327. #define SQLITE_DONE 101 /* sqlite3_step() has finished executing */
  328. /* end-of-error-codes */
  329. /*
  330. ** CAPI3REF: Extended Result Codes {H10220} <S10700>
  331. ** KEYWORDS: {extended error code} {extended error codes}
  332. ** KEYWORDS: {extended result code} {extended result codes}
  333. **
  334. ** In its default configuration, SQLite API routines return one of 26 integer
  335. ** [SQLITE_OK | result codes]. However, experience has shown that many of
  336. ** these result codes are too coarse-grained. They do not provide as
  337. ** much information about problems as programmers might like. In an effort to
  338. ** address this, newer versions of SQLite (version 3.3.8 and later) include
  339. ** support for additional result codes that provide more detailed information
  340. ** about errors. The extended result codes are enabled or disabled
  341. ** on a per database connection basis using the
  342. ** [sqlite3_extended_result_codes()] API.
  343. **
  344. ** Some of the available extended result codes are listed here.
  345. ** One may expect the number of extended result codes will be expand
  346. ** over time. Software that uses extended result codes should expect
  347. ** to see new result codes in future releases of SQLite.
  348. **
  349. ** The SQLITE_OK result code will never be extended. It will always
  350. ** be exactly zero.
  351. */
  352. #define SQLITE_IOERR_READ (SQLITE_IOERR | (1<<8))
  353. #define SQLITE_IOERR_SHORT_READ (SQLITE_IOERR | (2<<8))
  354. #define SQLITE_IOERR_WRITE (SQLITE_IOERR | (3<<8))
  355. #define SQLITE_IOERR_FSYNC (SQLITE_IOERR | (4<<8))
  356. #define SQLITE_IOERR_DIR_FSYNC (SQLITE_IOERR | (5<<8))
  357. #define SQLITE_IOERR_TRUNCATE (SQLITE_IOERR | (6<<8))
  358. #define SQLITE_IOERR_FSTAT (SQLITE_IOERR | (7<<8))
  359. #define SQLITE_IOERR_UNLOCK (SQLITE_IOERR | (8<<8))
  360. #define SQLITE_IOERR_RDLOCK (SQLITE_IOERR | (9<<8))
  361. #define SQLITE_IOERR_DELETE (SQLITE_IOERR | (10<<8))
  362. #define SQLITE_IOERR_BLOCKED (SQLITE_IOERR | (11<<8))
  363. #define SQLITE_IOERR_NOMEM (SQLITE_IOERR | (12<<8))
  364. #define SQLITE_IOERR_ACCESS (SQLITE_IOERR | (13<<8))
  365. #define SQLITE_IOERR_CHECKRESERVEDLOCK (SQLITE_IOERR | (14<<8))
  366. #define SQLITE_IOERR_LOCK (SQLITE_IOERR | (15<<8))
  367. #define SQLITE_IOERR_CLOSE (SQLITE_IOERR | (16<<8))
  368. #define SQLITE_IOERR_DIR_CLOSE (SQLITE_IOERR | (17<<8))
  369. #define SQLITE_LOCKED_SHAREDCACHE (SQLITE_LOCKED | (1<<8) )
  370. /*
  371. ** CAPI3REF: Flags For File Open Operations {H10230} <H11120> <H12700>
  372. **
  373. ** These bit values are intended for use in the
  374. ** 3rd parameter to the [sqlite3_open_v2()] interface and
  375. ** in the 4th parameter to the xOpen method of the
  376. ** [sqlite3_vfs] object.
  377. */
  378. #define SQLITE_OPEN_READONLY 0x00000001
  379. #define SQLITE_OPEN_READWRITE 0x00000002
  380. #define SQLITE_OPEN_CREATE 0x00000004
  381. #define SQLITE_OPEN_DELETEONCLOSE 0x00000008
  382. #define SQLITE_OPEN_EXCLUSIVE 0x00000010
  383. #define SQLITE_OPEN_AUTOPROXY 0x00000020
  384. #define SQLITE_OPEN_MAIN_DB 0x00000100
  385. #define SQLITE_OPEN_TEMP_DB 0x00000200
  386. #define SQLITE_OPEN_TRANSIENT_DB 0x00000400
  387. #define SQLITE_OPEN_MAIN_JOURNAL 0x00000800
  388. #define SQLITE_OPEN_TEMP_JOURNAL 0x00001000
  389. #define SQLITE_OPEN_SUBJOURNAL 0x00002000
  390. #define SQLITE_OPEN_MASTER_JOURNAL 0x00004000
  391. #define SQLITE_OPEN_NOMUTEX 0x00008000
  392. #define SQLITE_OPEN_FULLMUTEX 0x00010000
  393. /*
  394. ** CAPI3REF: Device Characteristics {H10240} <H11120>
  395. **
  396. ** The xDeviceCapabilities method of the [sqlite3_io_methods]
  397. ** object returns an integer which is a vector of the these
  398. ** bit values expressing I/O characteristics of the mass storage
  399. ** device that holds the file that the [sqlite3_io_methods]
  400. ** refers to.
  401. **
  402. ** The SQLITE_IOCAP_ATOMIC property means that all writes of
  403. ** any size are atomic. The SQLITE_IOCAP_ATOMICnnn values
  404. ** mean that writes of blocks that are nnn bytes in size and
  405. ** are aligned to an address which is an integer multiple of
  406. ** nnn are atomic. The SQLITE_IOCAP_SAFE_APPEND value means
  407. ** that when data is appended to a file, the data is appended
  408. ** first then the size of the file is extended, never the other
  409. ** way around. The SQLITE_IOCAP_SEQUENTIAL property means that
  410. ** information is written to disk in the same order as calls
  411. ** to xWrite().
  412. */
  413. #define SQLITE_IOCAP_ATOMIC 0x00000001
  414. #define SQLITE_IOCAP_ATOMIC512 0x00000002
  415. #define SQLITE_IOCAP_ATOMIC1K 0x00000004
  416. #define SQLITE_IOCAP_ATOMIC2K 0x00000008
  417. #define SQLITE_IOCAP_ATOMIC4K 0x00000010
  418. #define SQLITE_IOCAP_ATOMIC8K 0x00000020
  419. #define SQLITE_IOCAP_ATOMIC16K 0x00000040
  420. #define SQLITE_IOCAP_ATOMIC32K 0x00000080
  421. #define SQLITE_IOCAP_ATOMIC64K 0x00000100
  422. #define SQLITE_IOCAP_SAFE_APPEND 0x00000200
  423. #define SQLITE_IOCAP_SEQUENTIAL 0x00000400
  424. /*
  425. ** CAPI3REF: File Locking Levels {H10250} <H11120> <H11310>
  426. **
  427. ** SQLite uses one of these integer values as the second
  428. ** argument to calls it makes to the xLock() and xUnlock() methods
  429. ** of an [sqlite3_io_methods] object.
  430. */
  431. #define SQLITE_LOCK_NONE 0
  432. #define SQLITE_LOCK_SHARED 1
  433. #define SQLITE_LOCK_RESERVED 2
  434. #define SQLITE_LOCK_PENDING 3
  435. #define SQLITE_LOCK_EXCLUSIVE 4
  436. /*
  437. ** CAPI3REF: Synchronization Type Flags {H10260} <H11120>
  438. **
  439. ** When SQLite invokes the xSync() method of an
  440. ** [sqlite3_io_methods] object it uses a combination of
  441. ** these integer values as the second argument.
  442. **
  443. ** When the SQLITE_SYNC_DATAONLY flag is used, it means that the
  444. ** sync operation only needs to flush data to mass storage. Inode
  445. ** information need not be flushed. The SQLITE_SYNC_NORMAL flag means
  446. ** to use normal fsync() semantics. The SQLITE_SYNC_FULL flag means
  447. ** to use Mac OS X style fullsync instead of fsync().
  448. */
  449. #define SQLITE_SYNC_NORMAL 0x00002
  450. #define SQLITE_SYNC_FULL 0x00003
  451. #define SQLITE_SYNC_DATAONLY 0x00010
  452. /*
  453. ** CAPI3REF: OS Interface Open File Handle {H11110} <S20110>
  454. **
  455. ** An [sqlite3_file] object represents an open file in the OS
  456. ** interface layer. Individual OS interface implementations will
  457. ** want to subclass this object by appending additional fields
  458. ** for their own use. The pMethods entry is a pointer to an
  459. ** [sqlite3_io_methods] object that defines methods for performing
  460. ** I/O operations on the open file.
  461. */
  462. typedef struct sqlite3_file sqlite3_file;
  463. struct sqlite3_file {
  464. const struct sqlite3_io_methods *pMethods; /* Methods for an open file */
  465. };
  466. /*
  467. ** CAPI3REF: OS Interface File Virtual Methods Object {H11120} <S20110>
  468. **
  469. ** Every file opened by the [sqlite3_vfs] xOpen method populates an
  470. ** [sqlite3_file] object (or, more commonly, a subclass of the
  471. ** [sqlite3_file] object) with a pointer to an instance of this object.
  472. ** This object defines the methods used to perform various operations
  473. ** against the open file represented by the [sqlite3_file] object.
  474. **
  475. ** The flags argument to xSync may be one of [SQLITE_SYNC_NORMAL] or
  476. ** [SQLITE_SYNC_FULL]. The first choice is the normal fsync().
  477. ** The second choice is a Mac OS X style fullsync. The [SQLITE_SYNC_DATAONLY]
  478. ** flag may be ORed in to indicate that only the data of the file
  479. ** and not its inode needs to be synced.
  480. **
  481. ** The integer values to xLock() and xUnlock() are one of
  482. ** <ul>
  483. ** <li> [SQLITE_LOCK_NONE],
  484. ** <li> [SQLITE_LOCK_SHARED],
  485. ** <li> [SQLITE_LOCK_RESERVED],
  486. ** <li> [SQLITE_LOCK_PENDING], or
  487. ** <li> [SQLITE_LOCK_EXCLUSIVE].
  488. ** </ul>
  489. ** xLock() increases the lock. xUnlock() decreases the lock.
  490. ** The xCheckReservedLock() method checks whether any database connection,
  491. ** either in this process or in some other process, is holding a RESERVED,
  492. ** PENDING, or EXCLUSIVE lock on the file. It returns true
  493. ** if such a lock exists and false otherwise.
  494. **
  495. ** The xFileControl() method is a generic interface that allows custom
  496. ** VFS implementations to directly control an open file using the
  497. ** [sqlite3_file_control()] interface. The second "op" argument is an
  498. ** integer opcode. The third argument is a generic pointer intended to
  499. ** point to a structure that may contain arguments or space in which to
  500. ** write return values. Potential uses for xFileControl() might be
  501. ** functions to enable blocking locks with timeouts, to change the
  502. ** locking strategy (for example to use dot-file locks), to inquire
  503. ** about the status of a lock, or to break stale locks. The SQLite
  504. ** core reserves all opcodes less than 100 for its own use.
  505. ** A [SQLITE_FCNTL_LOCKSTATE | list of opcodes] less than 100 is available.
  506. ** Applications that define a custom xFileControl method should use opcodes
  507. ** greater than 100 to avoid conflicts.
  508. **
  509. ** The xSectorSize() method returns the sector size of the
  510. ** device that underlies the file. The sector size is the
  511. ** minimum write that can be performed without disturbing
  512. ** other bytes in the file. The xDeviceCharacteristics()
  513. ** method returns a bit vector describing behaviors of the
  514. ** underlying device:
  515. **
  516. ** <ul>
  517. ** <li> [SQLITE_IOCAP_ATOMIC]
  518. ** <li> [SQLITE_IOCAP_ATOMIC512]
  519. ** <li> [SQLITE_IOCAP_ATOMIC1K]
  520. ** <li> [SQLITE_IOCAP_ATOMIC2K]
  521. ** <li> [SQLITE_IOCAP_ATOMIC4K]
  522. ** <li> [SQLITE_IOCAP_ATOMIC8K]
  523. ** <li> [SQLITE_IOCAP_ATOMIC16K]
  524. ** <li> [SQLITE_IOCAP_ATOMIC32K]
  525. ** <li> [SQLITE_IOCAP_ATOMIC64K]
  526. ** <li> [SQLITE_IOCAP_SAFE_APPEND]
  527. ** <li> [SQLITE_IOCAP_SEQUENTIAL]
  528. ** </ul>
  529. **
  530. ** The SQLITE_IOCAP_ATOMIC property means that all writes of
  531. ** any size are atomic. The SQLITE_IOCAP_ATOMICnnn values
  532. ** mean that writes of blocks that are nnn bytes in size and
  533. ** are aligned to an address which is an integer multiple of
  534. ** nnn are atomic. The SQLITE_IOCAP_SAFE_APPEND value means
  535. ** that when data is appended to a file, the data is appended
  536. ** first then the size of the file is extended, never the other
  537. ** way around. The SQLITE_IOCAP_SEQUENTIAL property means that
  538. ** information is written to disk in the same order as calls
  539. ** to xWrite().
  540. **
  541. ** If xRead() returns SQLITE_IOERR_SHORT_READ it must also fill
  542. ** in the unread portions of the buffer with zeros. A VFS that
  543. ** fails to zero-fill short reads might seem to work. However,
  544. ** failure to zero-fill short reads will eventually lead to
  545. ** database corruption.
  546. */
  547. typedef struct sqlite3_io_methods sqlite3_io_methods;
  548. struct sqlite3_io_methods {
  549. int iVersion;
  550. int (*xClose)(sqlite3_file*);
  551. int (*xRead)(sqlite3_file*, void*, int iAmt, sqlite3_int64 iOfst);
  552. int (*xWrite)(sqlite3_file*, const void*, int iAmt, sqlite3_int64 iOfst);
  553. int (*xTruncate)(sqlite3_file*, sqlite3_int64 size);
  554. int (*xSync)(sqlite3_file*, int flags);
  555. int (*xFileSize)(sqlite3_file*, sqlite3_int64 *pSize);
  556. int (*xLock)(sqlite3_file*, int);
  557. int (*xUnlock)(sqlite3_file*, int);
  558. int (*xCheckReservedLock)(sqlite3_file*, int *pResOut);
  559. int (*xFileControl)(sqlite3_file*, int op, void *pArg);
  560. int (*xSectorSize)(sqlite3_file*);
  561. int (*xDeviceCharacteristics)(sqlite3_file*);
  562. /* Additional methods may be added in future releases */
  563. };
  564. /*
  565. ** CAPI3REF: Standard File Control Opcodes {H11310} <S30800>
  566. **
  567. ** These integer constants are opcodes for the xFileControl method
  568. ** of the [sqlite3_io_methods] object and for the [sqlite3_file_control()]
  569. ** interface.
  570. **
  571. ** The [SQLITE_FCNTL_LOCKSTATE] opcode is used for debugging. This
  572. ** opcode causes the xFileControl method to write the current state of
  573. ** the lock (one of [SQLITE_LOCK_NONE], [SQLITE_LOCK_SHARED],
  574. ** [SQLITE_LOCK_RESERVED], [SQLITE_LOCK_PENDING], or [SQLITE_LOCK_EXCLUSIVE])
  575. ** into an integer that the pArg argument points to. This capability
  576. ** is used during testing and only needs to be supported when SQLITE_TEST
  577. ** is defined.
  578. */
  579. #define SQLITE_FCNTL_LOCKSTATE 1
  580. #define SQLITE_GET_LOCKPROXYFILE 2
  581. #define SQLITE_SET_LOCKPROXYFILE 3
  582. #define SQLITE_LAST_ERRNO 4
  583. /*
  584. ** CAPI3REF: Mutex Handle {H17110} <S20130>
  585. **
  586. ** The mutex module within SQLite defines [sqlite3_mutex] to be an
  587. ** abstract type for a mutex object. The SQLite core never looks
  588. ** at the internal representation of an [sqlite3_mutex]. It only
  589. ** deals with pointers to the [sqlite3_mutex] object.
  590. **
  591. ** Mutexes are created using [sqlite3_mutex_alloc()].
  592. */
  593. typedef struct sqlite3_mutex sqlite3_mutex;
  594. /*
  595. ** CAPI3REF: OS Interface Object {H11140} <S20100>
  596. **
  597. ** An instance of the sqlite3_vfs object defines the interface between
  598. ** the SQLite core and the underlying operating system. The "vfs"
  599. ** in the name of the object stands for "virtual file system".
  600. **
  601. ** The value of the iVersion field is initially 1 but may be larger in
  602. ** future versions of SQLite. Additional fields may be appended to this
  603. ** object when the iVersion value is increased. Note that the structure
  604. ** of the sqlite3_vfs object changes in the transaction between
  605. ** SQLite version 3.5.9 and 3.6.0 and yet the iVersion field was not
  606. ** modified.
  607. **
  608. ** The szOsFile field is the size of the subclassed [sqlite3_file]
  609. ** structure used by this VFS. mxPathname is the maximum length of
  610. ** a pathname in this VFS.
  611. **
  612. ** Registered sqlite3_vfs objects are kept on a linked list formed by
  613. ** the pNext pointer. The [sqlite3_vfs_register()]
  614. ** and [sqlite3_vfs_unregister()] interfaces manage this list
  615. ** in a thread-safe way. The [sqlite3_vfs_find()] interface
  616. ** searches the list. Neither the application code nor the VFS
  617. ** implementation should use the pNext pointer.
  618. **
  619. ** The pNext field is the only field in the sqlite3_vfs
  620. ** structure that SQLite will ever modify. SQLite will only access
  621. ** or modify this field while holding a particular static mutex.
  622. ** The application should never modify anything within the sqlite3_vfs
  623. ** object once the object has been registered.
  624. **
  625. ** The zName field holds the name of the VFS module. The name must
  626. ** be unique across all VFS modules.
  627. **
  628. ** SQLite will guarantee that the zFilename parameter to xOpen
  629. ** is either a NULL pointer or string obtained
  630. ** from xFullPathname(). SQLite further guarantees that
  631. ** the string will be valid and unchanged until xClose() is
  632. ** called. Because of the previous sentense,
  633. ** the [sqlite3_file] can safely store a pointer to the
  634. ** filename if it needs to remember the filename for some reason.
  635. ** If the zFilename parameter is xOpen is a NULL pointer then xOpen
  636. ** must invite its own temporary name for the file. Whenever the
  637. ** xFilename parameter is NULL it will also be the case that the
  638. ** flags parameter will include [SQLITE_OPEN_DELETEONCLOSE].
  639. **
  640. ** The flags argument to xOpen() includes all bits set in
  641. ** the flags argument to [sqlite3_open_v2()]. Or if [sqlite3_open()]
  642. ** or [sqlite3_open16()] is used, then flags includes at least
  643. ** [SQLITE_OPEN_READWRITE] | [SQLITE_OPEN_CREATE].
  644. ** If xOpen() opens a file read-only then it sets *pOutFlags to
  645. ** include [SQLITE_OPEN_READONLY]. Other bits in *pOutFlags may be set.
  646. **
  647. ** SQLite will also add one of the following flags to the xOpen()
  648. ** call, depending on the object being opened:
  649. **
  650. ** <ul>
  651. ** <li> [SQLITE_OPEN_MAIN_DB]
  652. ** <li> [SQLITE_OPEN_MAIN_JOURNAL]
  653. ** <li> [SQLITE_OPEN_TEMP_DB]
  654. ** <li> [SQLITE_OPEN_TEMP_JOURNAL]
  655. ** <li> [SQLITE_OPEN_TRANSIENT_DB]
  656. ** <li> [SQLITE_OPEN_SUBJOURNAL]
  657. ** <li> [SQLITE_OPEN_MASTER_JOURNAL]
  658. ** </ul>
  659. **
  660. ** The file I/O implementation can use the object type flags to
  661. ** change the way it deals with files. For example, an application
  662. ** that does not care about crash recovery or rollback might make
  663. ** the open of a journal file a no-op. Writes to this journal would
  664. ** also be no-ops, and any attempt to read the journal would return
  665. ** SQLITE_IOERR. Or the implementation might recognize that a database
  666. ** file will be doing page-aligned sector reads and writes in a random
  667. ** order and set up its I/O subsystem accordingly.
  668. **
  669. ** SQLite might also add one of the following flags to the xOpen method:
  670. **
  671. ** <ul>
  672. ** <li> [SQLITE_OPEN_DELETEONCLOSE]
  673. ** <li> [SQLITE_OPEN_EXCLUSIVE]
  674. ** </ul>
  675. **
  676. ** The [SQLITE_OPEN_DELETEONCLOSE] flag means the file should be
  677. ** deleted when it is closed. The [SQLITE_OPEN_DELETEONCLOSE]
  678. ** will be set for TEMP databases, journals and for subjournals.
  679. **
  680. ** The [SQLITE_OPEN_EXCLUSIVE] flag means the file should be opened
  681. ** for exclusive access. This flag is set for all files except
  682. ** for the main database file.
  683. **
  684. ** At least szOsFile bytes of memory are allocated by SQLite
  685. ** to hold the [sqlite3_file] structure passed as the third
  686. ** argument to xOpen. The xOpen method does not have to
  687. ** allocate the structure; it should just fill it in.
  688. **
  689. ** The flags argument to xAccess() may be [SQLITE_ACCESS_EXISTS]
  690. ** to test for the existence of a file, or [SQLITE_ACCESS_READWRITE] to
  691. ** test whether a file is readable and writable, or [SQLITE_ACCESS_READ]
  692. ** to test whether a file is at least readable. The file can be a
  693. ** directory.
  694. **
  695. ** SQLite will always allocate at least mxPathname+1 bytes for the
  696. ** output buffer xFullPathname. The exact size of the output buffer
  697. ** is also passed as a parameter to both methods. If the output buffer
  698. ** is not large enough, [SQLITE_CANTOPEN] should be returned. Since this is
  699. ** handled as a fatal error by SQLite, vfs implementations should endeavor
  700. ** to prevent this by setting mxPathname to a sufficiently large value.
  701. **
  702. ** The xRandomness(), xSleep(), and xCurrentTime() interfaces
  703. ** are not strictly a part of the filesystem, but they are
  704. ** included in the VFS structure for completeness.
  705. ** The xRandomness() function attempts to return nBytes bytes
  706. ** of good-quality randomness into zOut. The return value is
  707. ** the actual number of bytes of randomness obtained.
  708. ** The xSleep() method causes the calling thread to sleep for at
  709. ** least the number of microseconds given. The xCurrentTime()
  710. ** method returns a Julian Day Number for the current date and time.
  711. **
  712. */
  713. typedef struct sqlite3_vfs sqlite3_vfs;
  714. struct sqlite3_vfs {
  715. int iVersion; /* Structure version number */
  716. int szOsFile; /* Size of subclassed sqlite3_file */
  717. int mxPathname; /* Maximum file pathname length */
  718. sqlite3_vfs *pNext; /* Next registered VFS */
  719. const char *zName; /* Name of this virtual file system */
  720. void *pAppData; /* Pointer to application-specific data */
  721. int (*xOpen)(sqlite3_vfs*, const char *zName, sqlite3_file*,
  722. int flags, int *pOutFlags);
  723. int (*xDelete)(sqlite3_vfs*, const char *zName, int syncDir);
  724. int (*xAccess)(sqlite3_vfs*, const char *zName, int flags, int *pResOut);
  725. int (*xFullPathname)(sqlite3_vfs*, const char *zName, int nOut, char *zOut);
  726. void *(*xDlOpen)(sqlite3_vfs*, const char *zFilename);
  727. void (*xDlError)(sqlite3_vfs*, int nByte, char *zErrMsg);
  728. void (*(*xDlSym)(sqlite3_vfs*,void*, const char *zSymbol))(void);
  729. void (*xDlClose)(sqlite3_vfs*, void*);
  730. int (*xRandomness)(sqlite3_vfs*, int nByte, char *zOut);
  731. int (*xSleep)(sqlite3_vfs*, int microseconds);
  732. int (*xCurrentTime)(sqlite3_vfs*, double*);
  733. int (*xGetLastError)(sqlite3_vfs*, int, char *);
  734. /* New fields may be appended in figure versions. The iVersion
  735. ** value will increment whenever this happens. */
  736. };
  737. /*
  738. ** CAPI3REF: Flags for the xAccess VFS method {H11190} <H11140>
  739. **
  740. ** These integer constants can be used as the third parameter to
  741. ** the xAccess method of an [sqlite3_vfs] object. {END} They determine
  742. ** what kind of permissions the xAccess method is looking for.
  743. ** With SQLITE_ACCESS_EXISTS, the xAccess method
  744. ** simply checks whether the file exists.
  745. ** With SQLITE_ACCESS_READWRITE, the xAccess method
  746. ** checks whether the file is both readable and writable.
  747. ** With SQLITE_ACCESS_READ, the xAccess method
  748. ** checks whether the file is readable.
  749. */
  750. #define SQLITE_ACCESS_EXISTS 0
  751. #define SQLITE_ACCESS_READWRITE 1
  752. #define SQLITE_ACCESS_READ 2
  753. /*
  754. ** CAPI3REF: Initialize The SQLite Library {H10130} <S20000><S30100>
  755. **
  756. ** The sqlite3_initialize() routine initializes the
  757. ** SQLite library. The sqlite3_shutdown() routine
  758. ** deallocates any resources that were allocated by sqlite3_initialize().
  759. **
  760. ** A call to sqlite3_initialize() is an "effective" call if it is
  761. ** the first time sqlite3_initialize() is invoked during the lifetime of
  762. ** the process, or if it is the first time sqlite3_initialize() is invoked
  763. ** following a call to sqlite3_shutdown(). Only an effective call
  764. ** of sqlite3_initialize() does any initialization. All other calls
  765. ** are harmless no-ops.
  766. **
  767. ** Among other things, sqlite3_initialize() shall invoke
  768. ** sqlite3_os_init(). Similarly, sqlite3_shutdown()
  769. ** shall invoke sqlite3_os_end().
  770. **
  771. ** The sqlite3_initialize() routine returns [SQLITE_OK] on success.
  772. ** If for some reason, sqlite3_initialize() is unable to initialize
  773. ** the library (perhaps it is unable to allocate a needed resource such
  774. ** as a mutex) it returns an [error code] other than [SQLITE_OK].
  775. **
  776. ** The sqlite3_initialize() routine is called internally by many other
  777. ** SQLite interfaces so that an application usually does not need to
  778. ** invoke sqlite3_initialize() directly. For example, [sqlite3_open()]
  779. ** calls sqlite3_initialize() so the SQLite library will be automatically
  780. ** initialized when [sqlite3_open()] is called if it has not be initialized
  781. ** already. However, if SQLite is compiled with the [SQLITE_OMIT_AUTOINIT]
  782. ** compile-time option, then the automatic calls to sqlite3_initialize()
  783. ** are omitted and the application must call sqlite3_initialize() directly
  784. ** prior to using any other SQLite interface. For maximum portability,
  785. ** it is recommended that applications always invoke sqlite3_initialize()
  786. ** directly prior to using any other SQLite interface. Future releases
  787. ** of SQLite may require this. In other words, the behavior exhibited
  788. ** when SQLite is compiled with [SQLITE_OMIT_AUTOINIT] might become the
  789. ** default behavior in some future release of SQLite.
  790. **
  791. ** The sqlite3_os_init() routine does operating-system specific
  792. ** initialization of the SQLite library. The sqlite3_os_end()
  793. ** routine undoes the effect of sqlite3_os_init(). Typical tasks
  794. ** performed by these routines include allocation or deallocation
  795. ** of static resources, initialization of global variables,
  796. ** setting up a default [sqlite3_vfs] module, or setting up
  797. ** a default configuration using [sqlite3_config()].
  798. **
  799. ** The application should never invoke either sqlite3_os_init()
  800. ** or sqlite3_os_end() directly. The application should only invoke
  801. ** sqlite3_initialize() and sqlite3_shutdown(). The sqlite3_os_init()
  802. ** interface is called automatically by sqlite3_initialize() and
  803. ** sqlite3_os_end() is called by sqlite3_shutdown(). Appropriate
  804. ** implementations for sqlite3_os_init() and sqlite3_os_end()
  805. ** are built into SQLite when it is compiled for unix, windows, or os/2.
  806. ** When built for other platforms (using the [SQLITE_OS_OTHER=1] compile-time
  807. ** option) the application must supply a suitable implementation for
  808. ** sqlite3_os_init() and sqlite3_os_end(). An application-supplied
  809. ** implementation of sqlite3_os_init() or sqlite3_os_end()
  810. ** must return [SQLITE_OK] on success and some other [error code] upon
  811. ** failure.
  812. */
  813. int sqlite3_initialize(void);
  814. int sqlite3_shutdown(void);
  815. int sqlite3_os_init(void);
  816. int sqlite3_os_end(void);
  817. /*
  818. ** CAPI3REF: Configuring The SQLite Library {H14100} <S20000><S30200>
  819. ** EXPERIMENTAL
  820. **
  821. ** The sqlite3_config() interface is used to make global configuration
  822. ** changes to SQLite in order to tune SQLite to the specific needs of
  823. ** the application. The default configuration is recommended for most
  824. ** applications and so this routine is usually not necessary. It is
  825. ** provided to support rare applications with unusual needs.
  826. **
  827. ** The sqlite3_config() interface is not threadsafe. The application
  828. ** must insure that no other SQLite interfaces are invoked by other
  829. ** threads while sqlite3_config() is running. Furthermore, sqlite3_config()
  830. ** may only be invoked prior to library initialization using
  831. ** [sqlite3_initialize()] or after shutdown by [sqlite3_shutdown()].
  832. ** Note, however, that sqlite3_config() can be called as part of the
  833. ** implementation of an application-defined [sqlite3_os_init()].
  834. **
  835. ** The first argument to sqlite3_config() is an integer
  836. ** [SQLITE_CONFIG_SINGLETHREAD | configuration option] that determines
  837. ** what property of SQLite is to be configured. Subsequent arguments
  838. ** vary depending on the [SQLITE_CONFIG_SINGLETHREAD | configuration option]
  839. ** in the first argument.
  840. **
  841. ** When a configuration option is set, sqlite3_config() returns [SQLITE_OK].
  842. ** If the option is unknown or SQLite is unable to set the option
  843. ** then this routine returns a non-zero [error code].
  844. **
  845. ** Requirements:
  846. ** [H14103] [H14106] [H14120] [H14123] [H14126] [H14129] [H14132] [H14135]
  847. ** [H14138] [H14141] [H14144] [H14147] [H14150] [H14153] [H14156] [H14159]
  848. ** [H14162] [H14165] [H14168]
  849. */
  850. SQLITE_EXPERIMENTAL int sqlite3_config(int, ...);
  851. /*
  852. ** CAPI3REF: Configure database connections {H14200} <S20000>
  853. ** EXPERIMENTAL
  854. **
  855. ** The sqlite3_db_config() interface is used to make configuration
  856. ** changes to a [database connection]. The interface is similar to
  857. ** [sqlite3_config()] except that the changes apply to a single
  858. ** [database connection] (specified in the first argument). The
  859. ** sqlite3_db_config() interface can only be used immediately after
  860. ** the database connection is created using [sqlite3_open()],
  861. ** [sqlite3_open16()], or [sqlite3_open_v2()].
  862. **
  863. ** The second argument to sqlite3_db_config(D,V,...) is the
  864. ** configuration verb - an integer code that indicates what
  865. ** aspect of the [database connection] is being configured.
  866. ** The only choice for this value is [SQLITE_DBCONFIG_LOOKASIDE].
  867. ** New verbs are likely to be added in future releases of SQLite.
  868. ** Additional arguments depend on the verb.
  869. **
  870. ** Requirements:
  871. ** [H14203] [H14206] [H14209] [H14212] [H14215]
  872. */
  873. SQLITE_EXPERIMENTAL int sqlite3_db_config(sqlite3*, int op, ...);
  874. /*
  875. ** CAPI3REF: Memory Allocation Routines {H10155} <S20120>
  876. ** EXPERIMENTAL
  877. **
  878. ** An instance of this object defines the interface between SQLite
  879. ** and low-level memory allocation routines.
  880. **
  881. ** This object is used in only one place in the SQLite interface.
  882. ** A pointer to an instance of this object is the argument to
  883. ** [sqlite3_config()] when the configuration option is
  884. ** [SQLITE_CONFIG_MALLOC]. By creating an instance of this object
  885. ** and passing it to [sqlite3_config()] during configuration, an
  886. ** application can specify an alternative memory allocation subsystem
  887. ** for SQLite to use for all of its dynamic memory needs.
  888. **
  889. ** Note that SQLite comes with a built-in memory allocator that is
  890. ** perfectly adequate for the overwhelming majority of applications
  891. ** and that this object is only useful to a tiny minority of applications
  892. ** with specialized memory allocation requirements. This object is
  893. ** also used during testing of SQLite in order to specify an alternative
  894. ** memory allocator that simulates memory out-of-memory conditions in
  895. ** order to verify that SQLite recovers gracefully from such
  896. ** conditions.
  897. **
  898. ** The xMalloc, xFree, and xRealloc methods must work like the
  899. ** malloc(), free(), and realloc() functions from the standard library.
  900. **
  901. ** xSize should return the allocated size of a memory allocation
  902. ** previously obtained from xMalloc or xRealloc. The allocated size
  903. ** is always at least as big as the requested size but may be larger.
  904. **
  905. ** The xRoundup method returns what would be the allocated size of
  906. ** a memory allocation given a particular requested size. Most memory
  907. ** allocators round up memory allocations at least to the next multiple
  908. ** of 8. Some allocators round up to a larger multiple or to a power of 2.
  909. **
  910. ** The xInit method initializes the memory allocator. (For example,
  911. ** it might allocate any require mutexes or initialize internal data
  912. ** structures. The xShutdown method is invoked (indirectly) by
  913. ** [sqlite3_shutdown()] and should deallocate any resources acquired
  914. ** by xInit. The pAppData pointer is used as the only parameter to
  915. ** xInit and xShutdown.
  916. */
  917. typedef struct sqlite3_mem_methods sqlite3_mem_methods;
  918. struct sqlite3_mem_methods {
  919. void *(*xMalloc)(int); /* Memory allocation function */
  920. void (*xFree)(void*); /* Free a prior allocation */
  921. void *(*xRealloc)(void*,int); /* Resize an allocation */
  922. int (*xSize)(void*); /* Return the size of an allocation */
  923. int (*xRoundup)(int); /* Round up request size to allocation size */
  924. int (*xInit)(void*); /* Initialize the memory allocator */
  925. void (*xShutdown)(void*); /* Deinitialize the memory allocator */
  926. void *pAppData; /* Argument to xInit() and xShutdown() */
  927. };
  928. /*
  929. ** CAPI3REF: Configuration Options {H10160} <S20000>
  930. ** EXPERIMENTAL
  931. **
  932. ** These constants are the available integer configuration options that
  933. ** can be passed as the first argument to the [sqlite3_config()] interface.
  934. **
  935. ** New configuration options may be added in future releases of SQLite.
  936. ** Existing configuration options might be discontinued. Applications
  937. ** should check the return code from [sqlite3_config()] to make sure that
  938. ** the call worked. The [sqlite3_config()] interface will return a
  939. ** non-zero [error code] if a discontinued or unsupported configuration option
  940. ** is invoked.
  941. **
  942. ** <dl>
  943. ** <dt>SQLITE_CONFIG_SINGLETHREAD</dt>
  944. ** <dd>There are no arguments to this option. This option disables
  945. ** all mutexing and puts SQLite into a mode where it can only be used
  946. ** by a single thread.</dd>
  947. **
  948. ** <dt>SQLITE_CONFIG_MULTITHREAD</dt>
  949. ** <dd>There are no arguments to this option. This option disables
  950. ** mutexing on [database connection] and [prepared statement] objects.
  951. ** The application is responsible for serializing access to
  952. ** [database connections] and [prepared statements]. But other mutexes
  953. ** are enabled so that SQLite will be safe to use in a multi-threaded
  954. ** environment as long as no two threads attempt to use the same
  955. ** [database connection] at the same time. See the [threading mode]
  956. ** documentation for additional information.</dd>
  957. **
  958. ** <dt>SQLITE_CONFIG_SERIALIZED</dt>
  959. ** <dd>There are no arguments to this option. This option enables
  960. ** all mutexes including the recursive
  961. ** mutexes on [database connection] and [prepared statement] objects.
  962. ** In this mode (which is the default when SQLite is compiled with
  963. ** [SQLITE_THREADSAFE=1]) the SQLite library will itself serialize access
  964. ** to [database connections] and [prepared statements] so that the
  965. ** application is free to use the same [database connection] or the
  966. ** same [prepared statement] in different threads at the same time.
  967. ** See the [threading mode] documentation for additional information.</dd>
  968. **
  969. ** <dt>SQLITE_CONFIG_MALLOC</dt>
  970. ** <dd>This option takes a single argument which is a pointer to an
  971. ** instance of the [sqlite3_mem_methods] structure. The argument specifies
  972. ** alternative low-level memory allocation routines to be used in place of
  973. ** the memory allocation routines built into SQLite.</dd>
  974. **
  975. ** <dt>SQLITE_CONFIG_GETMALLOC</dt>
  976. ** <dd>This option takes a single argument which is a pointer to an
  977. ** instance of the [sqlite3_mem_methods] structure. The [sqlite3_mem_methods]
  978. ** structure is filled with the currently defined memory allocation routines.
  979. ** This option can be used to overload the default memory allocation
  980. ** routines with a wrapper that simulations memory allocation failure or
  981. ** tracks memory usage, for example.</dd>
  982. **
  983. ** <dt>SQLITE_CONFIG_MEMSTATUS</dt>
  984. ** <dd>This option takes single argument of type int, interpreted as a
  985. ** boolean, which enables or disables the collection of memory allocation
  986. ** statistics. When disabled, the following SQLite interfaces become
  987. ** non-operational:
  988. ** <ul>
  989. ** <li> [sqlite3_memory_used()]
  990. ** <li> [sqlite3_memory_highwater()]
  991. ** <li> [sqlite3_soft_heap_limit()]
  992. ** <li> [sqlite3_status()]
  993. ** </ul>
  994. ** </dd>
  995. **
  996. ** <dt>SQLITE_CONFIG_SCRATCH</dt>
  997. ** <dd>This option specifies a static memory buffer that SQLite can use for
  998. ** scratch memory. There are three arguments: A pointer to the memory, the
  999. ** size of each scratch buffer (sz), and the number of buffers (N). The sz
  1000. ** argument must be a multiple of 16. The sz parameter should be a few bytes
  1001. ** larger than the actual scratch space required due internal overhead.
  1002. ** The first
  1003. ** argument should point to an allocation of at least sz*N bytes of memory.
  1004. ** SQLite will use no more than one scratch buffer at once per thread, so
  1005. ** N should be set to the expected maximum number of threads. The sz
  1006. ** parameter should be 6 times the size of the largest database page size.
  1007. ** Scratch buffers are used as part of the btree balance operation. If
  1008. ** The btree balancer needs additional memory beyond what is provided by
  1009. ** scratch buffers or if no scratch buffer space is specified, then SQLite
  1010. ** goes to [sqlite3_malloc()] to obtain the memory it needs.</dd>
  1011. **
  1012. ** <dt>SQLITE_CONFIG_PAGECACHE</dt>
  1013. ** <dd>This option specifies a static memory buffer that SQLite can use for
  1014. ** the database page cache with the default page cache implemenation.
  1015. ** This configuration should not be used if an application-define page
  1016. ** cache implementation is loaded using the SQLITE_CONFIG_PCACHE option.
  1017. ** There are three arguments to this option: A pointer to the
  1018. ** memory, the size of each page buffer (sz), and the number of pages (N).
  1019. ** The sz argument must be a power of two between 512 and 32768. The first
  1020. ** argument should point to an allocation of at least sz*N bytes of memory.
  1021. ** SQLite will use the memory provided by the first argument to satisfy its
  1022. ** memory needs for the first N pages that it adds to cache. If additional
  1023. ** page cache memory is needed beyond what is provided by this option, then
  1024. ** SQLite goes to [sqlite3_malloc()] for the additional storage space.
  1025. ** The implementation might use one or more of the N buffers to hold
  1026. ** memory accounting information. </dd>
  1027. **
  1028. ** <dt>SQLITE_CONFIG_HEAP</dt>
  1029. ** <dd>This option specifies a static memory buffer that SQLite will use
  1030. ** for all of its dynamic memory allocation needs beyond those provided
  1031. ** for by [SQLITE_CONFIG_SCRATCH] and [SQLITE_CONFIG_PAGECACHE].
  1032. ** There are three arguments: A pointer to the memory, the number of
  1033. ** bytes in the memory buffer, and the minimum allocation size. If
  1034. ** the first pointer (the memory pointer) is NULL, then SQLite reverts
  1035. ** to using its default memory allocator (the system malloc() implementation),
  1036. ** undoing any prior invocation of [SQLITE_CONFIG_MALLOC]. If the
  1037. ** memory pointer is not NULL and either [SQLITE_ENABLE_MEMSYS3] or
  1038. ** [SQLITE_ENABLE_MEMSYS5] are defined, then the alternative memory
  1039. ** allocator is engaged to handle all of SQLites memory allocation needs.</dd>
  1040. **
  1041. ** <dt>SQLITE_CONFIG_MUTEX</dt>
  1042. ** <dd>This option takes a single argument which is a pointer to an
  1043. ** instance of the [sqlite3_mutex_methods] structure. The argument specifies
  1044. ** alternative low-level mutex routines to be used in place
  1045. ** the mutex routines built into SQLite.</dd>
  1046. **
  1047. ** <dt>SQLITE_CONFIG_GETMUTEX</dt>
  1048. ** <dd>This option takes a single argument which is a pointer to an
  1049. ** instance of the [sqlite3_mutex_methods] structure. The
  1050. ** [sqlite3_mutex_methods]
  1051. ** structure is filled with the currently defined mutex routines.
  1052. ** This option can be used to overload the default mutex allocation
  1053. ** routines with a wrapper used to track mutex usage for performance
  1054. ** profiling or testing, for example.</dd>
  1055. **
  1056. ** <dt>SQLITE_CONFIG_LOOKASIDE</dt>
  1057. ** <dd>This option takes two arguments that determine the default
  1058. ** memory allcation lookaside optimization. The first argument is the
  1059. ** size of each lookaside buffer slot and the second is the number of
  1060. ** slots allocated to each database connection.</dd>
  1061. **
  1062. ** <dt>SQLITE_CONFIG_PCACHE</dt>
  1063. ** <dd>This option takes a single argument which is a pointer to
  1064. ** an [sqlite3_pcache_methods] object. This object specifies the interface
  1065. ** to a custom page cache implementation. SQLite makes a copy of the
  1066. ** object and uses it for page cache memory allocations.</dd>
  1067. **
  1068. ** <dt>SQLITE_CONFIG_GETPCACHE</dt>
  1069. ** <dd>This option takes a single argument which is a pointer to an
  1070. ** [sqlite3_pcache_methods] object. SQLite copies of the current
  1071. ** page cache implementation into that object.</dd>
  1072. **
  1073. ** </dl>
  1074. */
  1075. #define SQLITE_CONFIG_SINGLETHREAD 1 /* nil */
  1076. #define SQLITE_CONFIG_MULTITHREAD 2 /* nil */
  1077. #define SQLITE_CONFIG_SERIALIZED 3 /* nil */
  1078. #define SQLITE_CONFIG_MALLOC 4 /* sqlite3_mem_methods* */
  1079. #define SQLITE_CONFIG_GETMALLOC 5 /* sqlite3_mem_methods* */
  1080. #define SQLITE_CONFIG_SCRATCH 6 /* void*, int sz, int N */
  1081. #define SQLITE_CONFIG_PAGECACHE 7 /* void*, int sz, int N */
  1082. #define SQLITE_CONFIG_HEAP 8 /* void*, int nByte, int min */
  1083. #define SQLITE_CONFIG_MEMSTATUS 9 /* boolean */
  1084. #define SQLITE_CONFIG_MUTEX 10 /* sqlite3_mutex_methods* */
  1085. #define SQLITE_CONFIG_GETMUTEX 11 /* sqlite3_mutex_methods* */
  1086. /* previously SQLITE_CONFIG_CHUNKALLOC 12 which is now unused. */
  1087. #define SQLITE_CONFIG_LOOKASIDE 13 /* int int */
  1088. #define SQLITE_CONFIG_PCACHE 14 /* sqlite3_pcache_methods* */
  1089. #define SQLITE_CONFIG_GETPCACHE 15 /* sqlite3_pcache_methods* */
  1090. /*
  1091. ** CAPI3REF: Configuration Options {H10170} <S20000>
  1092. ** EXPERIMENTAL
  1093. **
  1094. ** These constants are the available integer configuration options that
  1095. ** can be passed as the second argument to the [sqlite3_db_config()] interface.
  1096. **
  1097. ** New configuration options may be added in future releases of SQLite.
  1098. ** Existing configuration options might be discontinued. Applications
  1099. ** should check the return code from [sqlite3_db_config()] to make sure that
  1100. ** the call worked. The [sqlite3_db_config()] interface will return a
  1101. ** non-zero [error code] if a discontinued or unsupported configuration option
  1102. ** is invoked.
  1103. **
  1104. ** <dl>
  1105. ** <dt>SQLITE_DBCONFIG_LOOKASIDE</dt>
  1106. ** <dd>This option takes three additional arguments that determine the
  1107. ** [lookaside memory allocator] configuration for the [database connection].
  1108. ** The first argument (the third parameter to [sqlite3_db_config()] is a
  1109. ** pointer to a memory buffer to use for lookaside memory. The first
  1110. ** argument may be NULL in which case SQLite will allocate the lookaside
  1111. ** buffer itself using [sqlite3_malloc()]. The second argument is the
  1112. ** size of each lookaside buffer slot and the third argument is the number of
  1113. ** slots. The size of the buffer in the first argument must be greater than
  1114. ** or equal to the product of the second and third arguments.</dd>
  1115. **
  1116. ** </dl>
  1117. */
  1118. #define SQLITE_DBCONFIG_LOOKASIDE 1001 /* void* int int */
  1119. /*
  1120. ** CAPI3REF: Enable Or Disable Extended Result Codes {H12200} <S10700>
  1121. **
  1122. ** The sqlite3_extended_result_codes() routine enables or disables the
  1123. ** [extended result codes] feature of SQLite. The extended result
  1124. ** codes are disabled by default for historical compatibility considerations.
  1125. **
  1126. ** Requirements:
  1127. ** [H12201] [H12202]
  1128. */
  1129. int sqlite3_extended_result_codes(sqlite3*, int onoff);
  1130. /*
  1131. ** CAPI3REF: Last Insert Rowid {H12220} <S10700>
  1132. **
  1133. ** Each entry in an SQLite table has a unique 64-bit signed
  1134. ** integer key called the [ROWID | "rowid"]. The rowid is always available
  1135. ** as an undeclared column named ROWID, OID, or _ROWID_ as long as those
  1136. ** names are not also used by explicitly declared columns. If
  1137. ** the table has a column of type [INTEGER PRIMARY KEY] then that column
  1138. ** is another alias for the rowid.
  1139. **
  1140. ** This routine returns the [rowid] of the most recent
  1141. ** successful [INSERT] into the database from the [database connection]
  1142. ** in the first argument. If no successful [INSERT]s
  1143. ** have ever occurred on that database connection, zero is returned.
  1144. **
  1145. ** If an [INSERT] occurs within a trigger, then the [rowid] of the inserted
  1146. ** row is returned by this routine as long as the trigger is running.
  1147. ** But once the trigger terminates, the value returned by this routine
  1148. ** reverts to the last value inserted before the trigger fired.
  1149. **
  1150. ** An [INSERT] that fails due to a constraint violation is not a
  1151. ** successful [INSERT] and does not change the value returned by this
  1152. ** routine. Thus INSERT OR FAIL, INSERT OR IGNORE, INSERT OR ROLLBACK,
  1153. ** and INSERT OR ABORT make no changes to the return value of this
  1154. ** routine when their insertion fails. When INSERT OR REPLACE
  1155. ** encounters a constraint violation, it does not fail. The
  1156. ** INSERT continues to completion after deleting rows that caused
  1157. ** the constraint problem so INSERT OR REPLACE will always change
  1158. ** the return value of this interface.
  1159. **
  1160. ** For the purposes of this routine, an [INSERT] is considered to
  1161. ** be successful even if it is subsequently rolled back.
  1162. **
  1163. ** Requirements:
  1164. ** [H12221] [H12223]
  1165. **
  1166. ** If a separate thread performs a new [INSERT] on the same
  1167. ** database connection while the [sqlite3_last_insert_rowid()]
  1168. ** function is running and thus changes the last insert [rowid],
  1169. ** then the value returned by [sqlite3_last_insert_rowid()] is
  1170. ** unpredictable and might not equal either the old or the new
  1171. ** last insert [rowid].
  1172. */
  1173. sqlite3_int64 sqlite3_last_insert_rowid(sqlite3*);
  1174. /*
  1175. ** CAPI3REF: Count The Number Of Rows Modified {H12240} <S10600>
  1176. **
  1177. ** This function returns the number of database rows that were changed
  1178. ** or inserted or deleted by the most recently completed SQL statement
  1179. ** on the [database connection] specified by the first parameter.
  1180. ** Only changes that are directly specified by the [INSERT], [UPDATE],
  1181. ** or [DELETE] statement are counted. Auxiliary changes caused by
  1182. ** triggers are not counted. Use the [sqlite3_total_changes()] function
  1183. ** to find the total number of changes including changes caused by triggers.
  1184. **
  1185. ** A "row change" is a change to a single row of a single table
  1186. ** caused by an INSERT, DELETE, or UPDATE statement. Rows that
  1187. ** are changed as side effects of REPLACE constraint resolution,
  1188. ** rollback, ABORT processing, DROP TABLE, or by any other
  1189. ** mechanisms do not count as direct row changes.
  1190. **
  1191. ** A "trigger context" is a scope of execution that begins and
  1192. ** ends with the script of a trigger. Most SQL statements are
  1193. ** evaluated outside of any trigger. This is the "top level"
  1194. ** trigger context. If a trigger fires from the top level, a
  1195. ** new trigger context is entered for the duration of that one
  1196. ** trigger. Subtriggers create subcontexts for their duration.
  1197. **
  1198. ** Calling [sqlite3_exec()] or [sqlite3_step()] recursively does
  1199. ** not create a new trigger context.
  1200. **
  1201. ** This function returns the number of direct row changes in the
  1202. ** most recent INSERT, UPDATE, or DELETE statement within the same
  1203. ** trigger context.
  1204. **
  1205. ** Thus, when called from the top level, this function returns the
  1206. ** number of changes in the most recent INSERT, UPDATE, or DELETE
  1207. ** that also occurred at the top level. Within the body of a trigger,
  1208. ** the sqlite3_changes() interface can be called to find the number of
  1209. ** changes in the most recently completed INSERT, UPDATE, or DELETE
  1210. ** statement within the body of the same trigger.
  1211. ** However, the number returned does not include changes
  1212. ** caused by subtriggers since those have their own context.
  1213. **
  1214. ** SQLite implements the command "DELETE FROM table" without a WHERE clause
  1215. ** by dropping and recreating the table. Doing so is much faster than going
  1216. ** through and deleting individual elements from the table. Because of this
  1217. ** optimization, the deletions in "DELETE FROM table" are not row changes and
  1218. ** will not be counted by the sqlite3_changes() or [sqlite3_total_changes()]
  1219. ** functions, regardless of the number of elements that were originally
  1220. ** in the table. To get an accurate count of the number of rows deleted, use
  1221. ** "DELETE FROM table WHERE 1" instead. Or recompile using the
  1222. ** [SQLITE_OMIT_TRUNCATE_OPTIMIZATION] compile-time option to disable the
  1223. ** optimization on all queries.
  1224. **
  1225. ** Requirements:
  1226. ** [H12241] [H12243]
  1227. **
  1228. ** If a separate thread makes changes on the same database connection
  1229. ** while [sqlite3_changes()] is running then the value returned
  1230. ** is unpredictable and not meaningful.
  1231. */
  1232. int sqlite3_changes(sqlite3*);
  1233. /*
  1234. ** CAPI3REF: Total Number Of Rows Modified {H12260} <S10600>
  1235. **
  1236. ** This function returns the number of row changes caused by INSERT,
  1237. ** UPDATE or DELETE statements since the [database connection] was opened.
  1238. ** The count includes all changes from all trigger contexts. However,
  1239. ** the count does not include changes used to implement REPLACE constraints,
  1240. ** do rollbacks or ABORT processing, or DROP table processing.
  1241. ** The changes are counted as soon as the statement that makes them is
  1242. ** completed (when the statement handle is passed to [sqlite3_reset()] or
  1243. ** [sqlite3_finalize()]).
  1244. **
  1245. ** SQLite implements the command "DELETE FROM table" without a WHERE clause
  1246. ** by dropping and recreating the table. (This is much faster than going
  1247. ** through and deleting individual elements from the table.) Because of this
  1248. ** optimization, the deletions in "DELETE FROM table" are not row changes and
  1249. ** will not be counted by the sqlite3_changes() or [sqlite3_total_changes()]
  1250. ** functions, regardless of the number of elements that were originally
  1251. ** in the table. To get an accurate count of the number of rows deleted, use
  1252. ** "DELETE FROM table WHERE 1" instead. Or recompile using the
  1253. ** [SQLITE_OMIT_TRUNCATE_OPTIMIZATION] compile-time option to disable the
  1254. ** optimization on all queries.
  1255. **
  1256. ** See also the [sqlite3_changes()] interface.
  1257. **
  1258. ** Requirements:
  1259. ** [H12261] [H12263]
  1260. **
  1261. ** If a separate thread makes changes on the same database connection
  1262. ** while [sqlite3_total_changes()] is running then the value
  1263. ** returned is unpredictable and not meaningful.
  1264. */
  1265. int sqlite3_total_changes(sqlite3*);
  1266. /*
  1267. ** CAPI3REF: Interrupt A Long-Running Query {H12270} <S30500>
  1268. **
  1269. ** This function causes any pending database operation to abort and
  1270. ** return at its earliest opportunity. This routine is typically
  1271. ** called in response to a user action such as pressing "Cancel"
  1272. ** or Ctrl-C where the user wants a long query operation to halt
  1273. ** immediately.
  1274. **
  1275. ** It is safe to call this routine from a thread different from the
  1276. ** thread that is currently running the database operation. But it
  1277. ** is not safe to call this routine with a [database connection] that
  1278. ** is closed or might close before sqlite3_interrupt() returns.
  1279. **
  1280. ** If an SQL operation is very nearly finished at the time when
  1281. ** sqlite3_interrupt() is called, then it might not have an opportunity
  1282. ** to be interrupted and might continue to completion.
  1283. **
  1284. ** An SQL operation that is interrupted will return [SQLITE_INTERRUPT].
  1285. ** If the interrupted SQL operation is an INSERT, UPDATE, or DELETE
  1286. ** that is inside an explicit transaction, then the entire transaction
  1287. ** will be rolled back automatically.
  1288. **
  1289. ** A call to sqlite3_interrupt() has no effect on SQL statements
  1290. ** that are started after sqlite3_interrupt() returns.
  1291. **
  1292. ** Requirements:
  1293. ** [H12271] [H12272]
  1294. **
  1295. ** If the database connection closes while [sqlite3_interrupt()]
  1296. ** is running then bad things will likely happen.
  1297. */
  1298. void sqlite3_interrupt(sqlite3*);
  1299. /*
  1300. ** CAPI3REF: Determine If An SQL Statement Is Complete {H10510} <S70200>
  1301. **
  1302. ** These routines are useful for command-line input to determine if the
  1303. ** currently entered text seems to form complete a SQL statement or
  1304. ** if additional input is needed before sending the text into
  1305. ** SQLite for parsing. These routines return true if the input string
  1306. ** appears to be a complete SQL statement. A statement is judged to be
  1307. ** complete if it ends with a semicolon token and is not a fragment of a
  1308. ** CREATE TRIGGER statement. Semicolons that are embedded within
  1309. ** string literals or quoted identifier names or comments are not
  1310. ** independent tokens (they are part of the token in which they are
  1311. ** embedded) and thus do not count as a statement terminator.
  1312. **
  1313. ** These routines do not parse the SQL statements thus
  1314. ** will not detect syntactically incorrect SQL.
  1315. **
  1316. ** Requirements: [H10511] [H10512]
  1317. **
  1318. ** The input to [sqlite3_complete()] must be a zero-terminated
  1319. ** UTF-8 string.
  1320. **
  1321. ** The input to [sqlite3_complete16()] must be a zero-terminated
  1322. ** UTF-16 string in native byte order.
  1323. */
  1324. int sqlite3_complete(const char *sql);
  1325. int sqlite3_complete16(const void *sql);
  1326. /*
  1327. ** CAPI3REF: Register A Callback To Handle SQLITE_BUSY Errors {H12310} <S40400>
  1328. **
  1329. ** This routine sets a callback function that might be invoked whenever
  1330. ** an attempt is made to open a database table that another thread
  1331. ** or process has locked.
  1332. **
  1333. ** If the busy callback is NULL, then [SQLITE_BUSY] or [SQLITE_IOERR_BLOCKED]
  1334. ** is returned immediately upon encountering the lock. If the busy callback
  1335. ** is not NULL, then the callback will be invoked with two arguments.
  1336. **
  1337. ** The first argument to the handler is a copy of the void* pointer which
  1338. ** is the third argument to sqlite3_busy_handler(). The second argument to
  1339. ** the handler callback is the number of times that the busy handler has
  1340. ** been invoked for this locking event. If the
  1341. ** busy callback returns 0, then no additional attempts are made to
  1342. ** access the database and [SQLITE_BUSY] or [SQLITE_IOERR_BLOCKED] is returned.
  1343. ** If the callback returns non-zero, then another attempt
  1344. ** is made to open the database for reading and the cycle repeats.
  1345. **
  1346. ** The presence of a busy handler does not guarantee that it will be invoked
  1347. ** when there is lock contention. If SQLite determines that invoking the busy
  1348. ** handler could result in a deadlock, it will go ahead and return [SQLITE_BUSY]
  1349. ** or [SQLITE_IOERR_BLOCKED] instead of invoking the busy handler.
  1350. ** Consider a scenario where one process is holding a read lock that
  1351. ** it is trying to promote to a reserved lock and
  1352. ** a second process is holding a reserved lock that it is trying
  1353. ** to promote to an exclusive lock. The first process cannot proceed
  1354. ** because it is blocked by the second and the second process cannot
  1355. ** proceed because it is blocked by the first. If both processes
  1356. ** invoke the busy handlers, neither will make any progress. Therefore,
  1357. ** SQLite returns [SQLITE_BUSY] for the first process, hoping that this
  1358. ** will induce the first process to release its read lock and allow
  1359. ** the second process to proceed.
  1360. **
  1361. ** The default busy callback is NULL.
  1362. **
  1363. ** The [SQLITE_BUSY] error is converted to [SQLITE_IOERR_BLOCKED]
  1364. ** when SQLite is in the middle of a large transaction where all the
  1365. ** changes will not fit into the in-memory cache. SQLite will
  1366. ** already hold a RESERVED lock on the database file, but it needs
  1367. ** to promote this lock to EXCLUSIVE so that it can spill cache
  1368. ** pages into the database file without harm to concurrent
  1369. ** readers. If it is unable to promote the lock, then the in-memory
  1370. ** cache will be left in an inconsistent state and so the error
  1371. ** code is promoted from the relatively benign [SQLITE_BUSY] to
  1372. ** the more severe [SQLITE_IOERR_BLOCKED]. This error code promotion
  1373. ** forces an automatic rollback of the changes. See the
  1374. ** <a href="/cvstrac/wiki?p=CorruptionFollowingBusyError">
  1375. ** CorruptionFollowingBusyError</a> wiki page for a discussion of why
  1376. ** this is important.
  1377. **
  1378. ** There can only be a single busy handler defined for each
  1379. ** [database connection]. Setting a new busy handler clears any
  1380. ** previously set handler. Note that calling [sqlite3_busy_timeout()]
  1381. ** will also set or clear the busy handler.
  1382. **
  1383. ** The busy callback should not take any actions which modify the
  1384. ** database connection that invoked the busy handler. Any such actions
  1385. ** result in undefined behavior.
  1386. **
  1387. ** Requirements:
  1388. ** [H12311] [H12312] [H12314] [H12316] [H12318]
  1389. **
  1390. ** A busy handler must not close the database connection
  1391. ** or [prepared statement] that invoked the busy handler.
  1392. */
  1393. int sqlite3_busy_handler(sqlite3*, int(*)(void*,int), void*);
  1394. /*
  1395. ** CAPI3REF: Set A Busy Timeout {H12340} <S40410>
  1396. **
  1397. ** This routine sets a [sqlite3_busy_handler | busy handler] that sleeps
  1398. ** for a specified amount of time when a table is locked. The handler
  1399. ** will sleep multiple times until at least "ms" milliseconds of sleeping
  1400. ** have accumulated. {H12343} After "ms" milliseconds of sleeping,
  1401. ** the handler returns 0 which causes [sqlite3_step()] to return
  1402. ** [SQLITE_BUSY] or [SQLITE_IOERR_BLOCKED].
  1403. **
  1404. ** Calling this routine with an argument less than or equal to zero
  1405. ** turns off all busy handlers.
  1406. **
  1407. ** There can only be a single busy handler for a particular
  1408. ** [database connection] any any given moment. If another busy handler
  1409. ** was defined (using [sqlite3_busy_handler()]) prior to calling
  1410. ** this routine, that other busy handler is cleared.
  1411. **
  1412. ** Requirements:
  1413. ** [H12341] [H12343] [H12344]
  1414. */
  1415. int sqlite3_busy_timeout(sqlite3*, int ms);
  1416. /*
  1417. ** CAPI3REF: Convenience Routines For Running Queries {H12370} <S10000>
  1418. **
  1419. ** Definition: A <b>result table</b> is memory data structure created by the
  1420. ** [sqlite3_get_table()] interface. A result table records the
  1421. ** complete query results from one or more queries.
  1422. **
  1423. ** The table conceptually has a number of rows and columns. But
  1424. ** these numbers are not part of the result table itself. These
  1425. ** numbers are obtained separately. Let N be the number of rows
  1426. ** and M be the number of columns.
  1427. **
  1428. ** A result table is an array of pointers to zero-terminated UTF-8 strings.
  1429. ** There are (N+1)*M elements in the array. The first M pointers point
  1430. ** to zero-terminated strings that contain the names of the columns.
  1431. ** The remaining entries all point to query results. NULL values result
  1432. ** in NULL pointers. All other values are in their UTF-8 zero-terminated
  1433. ** string representation as returned by [sqlite3_column_text()].
  1434. **
  1435. ** A result table might consist of one or more memory allocations.
  1436. ** It is not safe to pass a result table directly to [sqlite3_free()].
  1437. ** A result table should be deallocated using [sqlite3_free_table()].
  1438. **
  1439. ** As an example of the result table format, suppose a query result
  1440. ** is as follows:
  1441. **
  1442. ** <blockquote><pre>
  1443. ** Name | Age
  1444. ** -----------------------
  1445. ** Alice | 43
  1446. ** Bob | 28
  1447. ** Cindy | 21
  1448. ** </pre></blockquote>
  1449. **
  1450. ** There are two column (M==2) and three rows (N==3). Thus the
  1451. ** result table has 8 entries. Suppose the result table is stored
  1452. ** in an array names azResult. Then azResult holds this content:
  1453. **
  1454. ** <blockquote><pre>
  1455. ** azResult&#91;0] = "Name";
  1456. ** azResult&#91;1] = "Age";
  1457. ** azResult&#91;2] = "Alice";
  1458. ** azResult&#91;3] = "43";
  1459. ** azResult&#91;4] = "Bob";
  1460. ** azResult&#91;5] = "28";
  1461. ** azResult&#91;6] = "Cindy";
  1462. ** azResult&#91;7] = "21";
  1463. ** </pre></blockquote>
  1464. **
  1465. ** The sqlite3_get_table() function evaluates one or more
  1466. ** semicolon-separated SQL statements in the zero-terminated UTF-8
  1467. ** string of its 2nd parameter. It returns a result table to the
  1468. ** pointer given in its 3rd parameter.
  1469. **
  1470. ** After the calling function has finished using the result, it should
  1471. ** pass the pointer to the result table to sqlite3_free_table() in order to
  1472. ** release the memory that was malloced. Because of the way the
  1473. ** [sqlite3_malloc()] happens within sqlite3_get_table(), the calling
  1474. ** function must not try to call [sqlite3_free()] directly. Only
  1475. ** [sqlite3_free_table()] is able to release the memory properly and safely.
  1476. **
  1477. ** The sqlite3_get_table() interface is implemented as a wrapper around
  1478. ** [sqlite3_exec()]. The sqlite3_get_table() routine does not have access
  1479. ** to any internal data structures of SQLite. It uses only the public
  1480. ** interface defined here. As a consequence, errors that occur in the
  1481. ** wrapper layer outside of the internal [sqlite3_exec()] call are not
  1482. ** reflected in subsequent calls to [sqlite3_errcode()] or [sqlite3_errmsg()].
  1483. **
  1484. ** Requirements:
  1485. ** [H12371] [H12373] [H12374] [H12376] [H12379] [H12382]
  1486. */
  1487. int sqlite3_get_table(
  1488. sqlite3 *db, /* An open database */
  1489. const char *zSql, /* SQL to be evaluated */
  1490. char ***pazResult, /* Results of the query */
  1491. int *pnRow, /* Number of result rows written here */
  1492. int *pnColumn, /* Number of result columns written here */
  1493. char **pzErrmsg /* Error msg written here */
  1494. );
  1495. void sqlite3_free_table(char **result);
  1496. /*
  1497. ** CAPI3REF: Formatted String Printing Functions {H17400} <S70000><S20000>
  1498. **
  1499. ** These routines are workalikes of the "printf()" family of functions
  1500. ** from the standard C library.
  1501. **
  1502. ** The sqlite3_mprintf() and sqlite3_vmprintf() routines write their
  1503. ** results into memory obtained from [sqlite3_malloc()].
  1504. ** The strings returned by these two routines should be
  1505. ** released by [sqlite3_free()]. Both routines return a
  1506. ** NULL pointer if [sqlite3_malloc()] is unable to allocate enough
  1507. ** memory to hold the resulting string.
  1508. **
  1509. ** In sqlite3_snprintf() routine is similar to "snprintf()" from
  1510. ** the standard C library. The result is written into the
  1511. ** buffer supplied as the second parameter whose size is given by
  1512. ** the first parameter. Note that the order of the
  1513. ** first two parameters is reversed from snprintf(). This is an
  1514. ** historical accident that cannot be fixed without breaking
  1515. ** backwards compatibility. Note also that sqlite3_snprintf()
  1516. ** returns a pointer to its buffer instead of the number of
  1517. ** characters actually written into the buffer. We admit that
  1518. ** the number of characters written would be a more useful return
  1519. ** value but we cannot change the implementation of sqlite3_snprintf()
  1520. ** now without breaking compatibility.
  1521. **
  1522. ** As long as the buffer size is greater than zero, sqlite3_snprintf()
  1523. ** guarantees that the buffer is always zero-terminated. The first
  1524. ** parameter "n" is the total size of the buffer, including space for
  1525. ** the zero terminator. So the longest string that can be completely
  1526. ** written will be n-1 characters.
  1527. **
  1528. ** These routines all implement some additional formatting
  1529. ** options that are useful for constructing SQL statements.
  1530. ** All of the usual printf() formatting options apply. In addition, there
  1531. ** is are "%q", "%Q", and "%z" options.
  1532. **
  1533. ** The %q option works like %s in that it substitutes a null-terminated
  1534. ** string from the argument list. But %q also doubles every '\'' character.
  1535. ** %q is designed for use inside a string literal. By doubling each '\''
  1536. ** character it escapes that character and allows it to be inserted into
  1537. ** the string.
  1538. **
  1539. ** For example, assume the string variable zText contains text as follows:
  1540. **
  1541. ** <blockquote><pre>
  1542. ** char *zText = "It's a happy day!";
  1543. ** </pre></blockquote>
  1544. **
  1545. ** One can use this text in an SQL statement as follows:
  1546. **
  1547. ** <blockquote><pre>
  1548. ** char *zSQL = sqlite3_mprintf("INSERT INTO table VALUES('%q')", zText);
  1549. ** sqlite3_exec(db, zSQL, 0, 0, 0);
  1550. ** sqlite3_free(zSQL);
  1551. ** </pre></blockquote>
  1552. **
  1553. ** Because the %q format string is used, the '\'' character in zText
  1554. ** is escaped and the SQL generated is as follows:
  1555. **
  1556. ** <blockquote><pre>
  1557. ** INSERT INTO table1 VALUES('It''s a happy day!')
  1558. ** </pre></blockquote>
  1559. **
  1560. ** This is correct. Had we used %s instead of %q, the generated SQL
  1561. ** would have looked like this:
  1562. **
  1563. ** <blockquote><pre>
  1564. ** INSERT INTO table1 VALUES('It's a happy day!');
  1565. ** </pre></blockquote>
  1566. **
  1567. ** This second example is an SQL syntax error. As a general rule you should
  1568. ** always use %q instead of %s when inserting text into a string literal.
  1569. **
  1570. ** The %Q option works like %q except it also adds single quotes around
  1571. ** the outside of the total string. Additionally, if the parameter in the
  1572. ** argument list is a NULL pointer, %Q substitutes the text "NULL" (without
  1573. ** single quotes) in place of the %Q option. So, for example, one could say:
  1574. **
  1575. ** <blockquote><pre>
  1576. ** char *zSQL = sqlite3_mprintf("INSERT INTO table VALUES(%Q)", zText);
  1577. ** sqlite3_exec(db, zSQL, 0, 0, 0);
  1578. ** sqlite3_free(zSQL);
  1579. ** </pre></blockquote>
  1580. **
  1581. ** The code above will render a correct SQL statement in the zSQL
  1582. ** variable even if the zText variable is a NULL pointer.
  1583. **
  1584. ** The "%z" formatting option works exactly like "%s" with the
  1585. ** addition that after the string has been read and copied into
  1586. ** the result, [sqlite3_free()] is called on the input string. {END}
  1587. **
  1588. ** Requirements:
  1589. ** [H17403] [H17406] [H17407]
  1590. */
  1591. char *sqlite3_mprintf(const char*,...);
  1592. char *sqlite3_vmprintf(const char*, va_list);
  1593. char *sqlite3_snprintf(int,char*,const char*, ...);
  1594. /*
  1595. ** CAPI3REF: Memory Allocation Subsystem {H17300} <S20000>
  1596. **
  1597. ** The SQLite core uses these three routines for all of its own
  1598. ** internal memory allocation needs. "Core" in the previous sentence
  1599. ** does not include operating-system specific VFS implementation. The
  1600. ** Windows VFS uses native malloc() and free() for some operations.
  1601. **
  1602. ** The sqlite3_malloc() routine returns a pointer to a block
  1603. ** of memory at least N bytes in length, where N is the parameter.
  1604. ** If sqlite3_malloc() is unable to obtain sufficient free
  1605. ** memory, it returns a NULL pointer. If the parameter N to
  1606. ** sqlite3_malloc() is zero or negative then sqlite3_malloc() returns
  1607. ** a NULL pointer.
  1608. **
  1609. ** Calling sqlite3_free() with a pointer previously returned
  1610. ** by sqlite3_malloc() or sqlite3_realloc() releases that memory so
  1611. ** that it might be reused. The sqlite3_free() routine is
  1612. ** a no-op if is called with a NULL pointer. Passing a NULL pointer
  1613. ** to sqlite3_free() is harmless. After being freed, memory
  1614. ** should neither be read nor written. Even reading previously freed
  1615. ** memory might result in a segmentation fault or other severe error.
  1616. ** Memory corruption, a segmentation fault, or other severe error
  1617. ** might result if sqlite3_free() is called with a non-NULL pointer that
  1618. ** was not obtained from sqlite3_malloc() or sqlite3_realloc().
  1619. **
  1620. ** The sqlite3_realloc() interface attempts to resize a
  1621. ** prior memory allocation to be at least N bytes, where N is the
  1622. ** second parameter. The memory allocation to be resized is the first
  1623. ** parameter. If the first parameter to sqlite3_realloc()
  1624. ** is a NULL pointer then its behavior is identical to calling
  1625. ** sqlite3_malloc(N) where N is the second parameter to sqlite3_realloc().
  1626. ** If the second parameter to sqlite3_realloc() is zero or
  1627. ** negative then the behavior is exactly the same as calling
  1628. ** sqlite3_free(P) where P is the first parameter to sqlite3_realloc().
  1629. ** sqlite3_realloc() returns a pointer to a memory allocation
  1630. ** of at least N bytes in size or NULL if sufficient memory is unavailable.
  1631. ** If M is the size of the prior allocation, then min(N,M) bytes
  1632. ** of the prior allocation are copied into the beginning of buffer returned
  1633. ** by sqlite3_realloc() and the prior allocation is freed.
  1634. ** If sqlite3_realloc() returns NULL, then the prior allocation
  1635. ** is not freed.
  1636. **
  1637. ** The memory returned by sqlite3_malloc() and sqlite3_realloc()
  1638. ** is always aligned to at least an 8 byte boundary. {END}
  1639. **
  1640. ** The default implementation of the memory allocation subsystem uses
  1641. ** the malloc(), realloc() and free() provided by the standard C library.
  1642. ** {H17382} However, if SQLite is compiled with the
  1643. ** SQLITE_MEMORY_SIZE=<i>NNN</i> C preprocessor macro (where <i>NNN</i>
  1644. ** is an integer), then SQLite create a static array of at least
  1645. ** <i>NNN</i> bytes in size and uses that array for all of its dynamic
  1646. ** memory allocation needs. {END} Additional memory allocator options
  1647. ** may be added in future releases.
  1648. **
  1649. ** In SQLite version 3.5.0 and 3.5.1, it was possible to define
  1650. ** the SQLITE_OMIT_MEMORY_ALLOCATION which would cause the built-in
  1651. ** implementation of these routines to be omitted. That capability
  1652. ** is no longer provided. Only built-in memory allocators can be used.
  1653. **
  1654. ** The Windows OS interface layer calls
  1655. ** the system malloc() and free() directly when converting
  1656. ** filenames between the UTF-8 encoding used by SQLite
  1657. ** and whatever filename encoding is used by the particular Windows
  1658. ** installation. Memory allocation errors are detected, but
  1659. ** they are reported back as [SQLITE_CANTOPEN] or
  1660. ** [SQLITE_IOERR] rather than [SQLITE_NOMEM].
  1661. **
  1662. ** Requirements:
  1663. ** [H17303] [H17304] [H17305] [H17306] [H17310] [H17312] [H17315] [H17318]
  1664. ** [H17321] [H17322] [H17323]
  1665. **
  1666. ** The pointer arguments to [sqlite3_free()] and [sqlite3_realloc()]
  1667. ** must be either NULL or else pointers obtained from a prior
  1668. ** invocation of [sqlite3_malloc()] or [sqlite3_realloc()] that have
  1669. ** not yet been released.
  1670. **
  1671. ** The application must not read or write any part of
  1672. ** a block of memory after it has been released using
  1673. ** [sqlite3_free()] or [sqlite3_realloc()].
  1674. */
  1675. void *sqlite3_malloc(int);
  1676. void *sqlite3_realloc(void*, int);
  1677. void sqlite3_free(void*);
  1678. /*
  1679. ** CAPI3REF: Memory Allocator Statistics {H17370} <S30210>
  1680. **
  1681. ** SQLite provides these two interfaces for reporting on the status
  1682. ** of the [sqlite3_malloc()], [sqlite3_free()], and [sqlite3_realloc()]
  1683. ** routines, which form the built-in memory allocation subsystem.
  1684. **
  1685. ** Requirements:
  1686. ** [H17371] [H17373] [H17374] [H17375]
  1687. */
  1688. sqlite3_int64 sqlite3_memory_used(void);
  1689. sqlite3_int64 sqlite3_memory_highwater(int resetFlag);
  1690. /*
  1691. ** CAPI3REF: Pseudo-Random Number Generator {H17390} <S20000>
  1692. **
  1693. ** SQLite contains a high-quality pseudo-random number generator (PRNG) used to
  1694. ** select random [ROWID | ROWIDs] when inserting new records into a table that
  1695. ** already uses the largest possible [ROWID]. The PRNG is also used for
  1696. ** the build-in random() and randomblob() SQL functions. This interface allows
  1697. ** applications to access the same PRNG for other purposes.
  1698. **
  1699. ** A call to this routine stores N bytes of randomness into buffer P.
  1700. **
  1701. ** The first time this routine is invoked (either internally or by
  1702. ** the application) the PRNG is seeded using randomness obtained
  1703. ** from the xRandomness method of the default [sqlite3_vfs] object.
  1704. ** On all subsequent invocations, the pseudo-randomness is generated
  1705. ** internally and without recourse to the [sqlite3_vfs] xRandomness
  1706. ** method.
  1707. **
  1708. ** Requirements:
  1709. ** [H17392]
  1710. */
  1711. void sqlite3_randomness(int N, void *P);
  1712. /*
  1713. ** CAPI3REF: Compile-Time Authorization Callbacks {H12500} <S70100>
  1714. **
  1715. ** This routine registers a authorizer callback with a particular
  1716. ** [database connection], supplied in the first argument.
  1717. ** The authorizer callback is invoked as SQL statements are being compiled
  1718. ** by [sqlite3_prepare()] or its variants [sqlite3_prepare_v2()],
  1719. ** [sqlite3_prepare16()] and [sqlite3_prepare16_v2()]. At various
  1720. ** points during the compilation process, as logic is being created
  1721. ** to perform various actions, the authorizer callback is invoked to
  1722. ** see if those actions are allowed. The authorizer callback should
  1723. ** return [SQLITE_OK] to allow the action, [SQLITE_IGNORE] to disallow the
  1724. ** specific action but allow the SQL statement to continue to be
  1725. ** compiled, or [SQLITE_DENY] to cause the entire SQL statement to be
  1726. ** rejected with an error. If the authorizer callback returns
  1727. ** any value other than [SQLITE_IGNORE], [SQLITE_OK], or [SQLITE_DENY]
  1728. ** then the [sqlite3_prepare_v2()] or equivalent call that triggered
  1729. ** the authorizer will fail with an error message.
  1730. **
  1731. ** When the callback returns [SQLITE_OK], that means the operation
  1732. ** requested is ok. When the callback returns [SQLITE_DENY], the
  1733. ** [sqlite3_prepare_v2()] or equivalent call that triggered the
  1734. ** authorizer will fail with an error message explaining that
  1735. ** access is denied. If the authorizer code is [SQLITE_READ]
  1736. ** and the callback returns [SQLITE_IGNORE] then the
  1737. ** [prepared statement] statement is constructed to substitute
  1738. ** a NULL value in place of the table column that would have
  1739. ** been read if [SQLITE_OK] had been returned. The [SQLITE_IGNORE]
  1740. ** return can be used to deny an untrusted user access to individual
  1741. ** columns of a table.
  1742. **
  1743. ** The first parameter to the authorizer callback is a copy of the third
  1744. ** parameter to the sqlite3_set_authorizer() interface. The second parameter
  1745. ** to the callback is an integer [SQLITE_COPY | action code] that specifies
  1746. ** the particular action to be authorized. The third through sixth parameters
  1747. ** to the callback are zero-terminated strings that contain additional
  1748. ** details about the action to be authorized.
  1749. **
  1750. ** An authorizer is used when [sqlite3_prepare | preparing]
  1751. ** SQL statements from an untrusted source, to ensure that the SQL statements
  1752. ** do not try to access data they are not allowed to see, or that they do not
  1753. ** try to execute malicious statements that damage the database. For
  1754. ** example, an application may allow a user to enter arbitrary
  1755. ** SQL queries for evaluation by a database. But the application does
  1756. ** not want the user to be able to make arbitrary changes to the
  1757. ** database. An authorizer could then be put in place while the
  1758. ** user-entered SQL is being [sqlite3_prepare | prepared] that
  1759. ** disallows everything except [SELECT] statements.
  1760. **
  1761. ** Applications that need to process SQL from untrusted sources
  1762. ** might also consider lowering resource limits using [sqlite3_limit()]
  1763. ** and limiting database size using the [max_page_count] [PRAGMA]
  1764. ** in addition to using an authorizer.
  1765. **
  1766. ** Only a single authorizer can be in place on a database connection
  1767. ** at a time. Each call to sqlite3_set_authorizer overrides the
  1768. ** previous call. Disable the authorizer by installing a NULL callback.
  1769. ** The authorizer is disabled by default.
  1770. **
  1771. ** The authorizer callback must not do anything that will modify
  1772. ** the database connection that invoked the authorizer callback.
  1773. ** Note that [sqlite3_prepare_v2()] and [sqlite3_step()] both modify their
  1774. ** database connections for the meaning of "modify" in this paragraph.
  1775. **
  1776. ** When [sqlite3_prepare_v2()] is used to prepare a statement, the
  1777. ** statement might be reprepared during [sqlite3_step()] due to a
  1778. ** schema change. Hence, the application should ensure that the
  1779. ** correct authorizer callback remains in place during the [sqlite3_step()].
  1780. **
  1781. ** Note that the authorizer callback is invoked only during
  1782. ** [sqlite3_prepare()] or its variants. Authorization is not
  1783. ** performed during statement evaluation in [sqlite3_step()].
  1784. **
  1785. ** Requirements:
  1786. ** [H12501] [H12502] [H12503] [H12504] [H12505] [H12506] [H12507] [H12510]
  1787. ** [H12511] [H12512] [H12520] [H12521] [H12522]
  1788. */
  1789. int sqlite3_set_authorizer(
  1790. sqlite3*,
  1791. int (*xAuth)(void*,int,const char*,const char*,const char*,const char*),
  1792. void *pUserData
  1793. );
  1794. /*
  1795. ** CAPI3REF: Authorizer Return Codes {H12590} <H12500>
  1796. **
  1797. ** The [sqlite3_set_authorizer | authorizer callback function] must
  1798. ** return either [SQLITE_OK] or one of these two constants in order
  1799. ** to signal SQLite whether or not the action is permitted. See the
  1800. ** [sqlite3_set_authorizer | authorizer documentation] for additional
  1801. ** information.
  1802. */
  1803. #define SQLITE_DENY 1 /* Abort the SQL statement with an error */
  1804. #define SQLITE_IGNORE 2 /* Don't allow access, but don't generate an error */
  1805. /*
  1806. ** CAPI3REF: Authorizer Action Codes {H12550} <H12500>
  1807. **
  1808. ** The [sqlite3_set_authorizer()] interface registers a callback function
  1809. ** that is invoked to authorize certain SQL statement actions. The
  1810. ** second parameter to the callback is an integer code that specifies
  1811. ** what action is being authorized. These are the integer action codes that
  1812. ** the authorizer callback may be passed.
  1813. **
  1814. ** These action code values signify what kind of operation is to be
  1815. ** authorized. The 3rd and 4th parameters to the authorization
  1816. ** callback function will be parameters or NULL depending on which of these
  1817. ** codes is used as the second parameter. The 5th parameter to the
  1818. ** authorizer callback is the name of the database ("main", "temp",
  1819. ** etc.) if applicable. The 6th parameter to the authorizer callback
  1820. ** is the name of the inner-most trigger or view that is responsible for
  1821. ** the access attempt or NULL if this access attempt is directly from
  1822. ** top-level SQL code.
  1823. **
  1824. ** Requirements:
  1825. ** [H12551] [H12552] [H12553] [H12554]
  1826. */
  1827. /******************************************* 3rd ************ 4th ***********/
  1828. #define SQLITE_CREATE_INDEX 1 /* Index Name Table Name */
  1829. #define SQLITE_CREATE_TABLE 2 /* Table Name NULL */
  1830. #define SQLITE_CREATE_TEMP_INDEX 3 /* Index Name Table Name */
  1831. #define SQLITE_CREATE_TEMP_TABLE 4 /* Table Name NULL */
  1832. #define SQLITE_CREATE_TEMP_TRIGGER 5 /* Trigger Name Table Name */
  1833. #define SQLITE_CREATE_TEMP_VIEW 6 /* View Name NULL */
  1834. #define SQLITE_CREATE_TRIGGER 7 /* Trigger Name Table Name */
  1835. #define SQLITE_CREATE_VIEW 8 /* View Name NULL */
  1836. #define SQLITE_DELETE 9 /* Table Name NULL */
  1837. #define SQLITE_DROP_INDEX 10 /* Index Name Table Name */
  1838. #define SQLITE_DROP_TABLE 11 /* Table Name NULL */
  1839. #define SQLITE_DROP_TEMP_INDEX 12 /* Index Name Table Name */
  1840. #define SQLITE_DROP_TEMP_TABLE 13 /* Table Name NULL */
  1841. #define SQLITE_DROP_TEMP_TRIGGER 14 /* Trigger Name Table Name */
  1842. #define SQLITE_DROP_TEMP_VIEW 15 /* View Name NULL */
  1843. #define SQLITE_DROP_TRIGGER 16 /* Trigger Name Table Name */
  1844. #define SQLITE_DROP_VIEW 17 /* View Name NULL */
  1845. #define SQLITE_INSERT 18 /* Table Name NULL */
  1846. #define SQLITE_PRAGMA 19 /* Pragma Name 1st arg or NULL */
  1847. #define SQLITE_READ 20 /* Table Name Column Name */
  1848. #define SQLITE_SELECT 21 /* NULL NULL */
  1849. #define SQLITE_TRANSACTION 22 /* Operation NULL */
  1850. #define SQLITE_UPDATE 23 /* Table Name Column Name */
  1851. #define SQLITE_ATTACH 24 /* Filename NULL */
  1852. #define SQLITE_DETACH 25 /* Database Name NULL */
  1853. #define SQLITE_ALTER_TABLE 26 /* Database Name Table Name */
  1854. #define SQLITE_REINDEX 27 /* Index Name NULL */
  1855. #define SQLITE_ANALYZE 28 /* Table Name NULL */
  1856. #define SQLITE_CREATE_VTABLE 29 /* Table Name Module Name */
  1857. #define SQLITE_DROP_VTABLE 30 /* Table Name Module Name */
  1858. #define SQLITE_FUNCTION 31 /* NULL Function Name */
  1859. #define SQLITE_SAVEPOINT 32 /* Operation Savepoint Name */
  1860. #define SQLITE_COPY 0 /* No longer used */
  1861. /*
  1862. ** CAPI3REF: Tracing And Profiling Functions {H12280} <S60400>
  1863. ** EXPERIMENTAL
  1864. **
  1865. ** These routines register callback functions that can be used for
  1866. ** tracing and profiling the execution of SQL statements.
  1867. **
  1868. ** The callback function registered by sqlite3_trace() is invoked at
  1869. ** various times when an SQL statement is being run by [sqlite3_step()].
  1870. ** The callback returns a UTF-8 rendering of the SQL statement text
  1871. ** as the statement first begins executing. Additional callbacks occur
  1872. ** as each triggered subprogram is entered. The callbacks for triggers
  1873. ** contain a UTF-8 SQL comment that identifies the trigger.
  1874. **
  1875. ** The callback function registered by sqlite3_profile() is invoked
  1876. ** as each SQL statement finishes. The profile callback contains
  1877. ** the original statement text and an estimate of wall-clock time
  1878. ** of how long that statement took to run.
  1879. **
  1880. ** Requirements:
  1881. ** [H12281] [H12282] [H12283] [H12284] [H12285] [H12287] [H12288] [H12289]
  1882. ** [H12290]
  1883. */
  1884. SQLITE_EXPERIMENTAL void *sqlite3_trace(sqlite3*, void(*xTrace)(void*,const char*), void*);
  1885. SQLITE_EXPERIMENTAL void *sqlite3_profile(sqlite3*,
  1886. void(*xProfile)(void*,const char*,sqlite3_uint64), void*);
  1887. /*
  1888. ** CAPI3REF: Query Progress Callbacks {H12910} <S60400>
  1889. **
  1890. ** This routine configures a callback function - the
  1891. ** progress callback - that is invoked periodically during long
  1892. ** running calls to [sqlite3_exec()], [sqlite3_step()] and
  1893. ** [sqlite3_get_table()]. An example use for this
  1894. ** interface is to keep a GUI updated during a large query.
  1895. **
  1896. ** If the progress callback returns non-zero, the operation is
  1897. ** interrupted. This feature can be used to implement a
  1898. ** "Cancel" button on a GUI progress dialog box.
  1899. **
  1900. ** The progress handler must not do anything that will modify
  1901. ** the database connection that invoked the progress handler.
  1902. ** Note that [sqlite3_prepare_v2()] and [sqlite3_step()] both modify their
  1903. ** database connections for the meaning of "modify" in this paragraph.
  1904. **
  1905. ** Requirements:
  1906. ** [H12911] [H12912] [H12913] [H12914] [H12915] [H12916] [H12917] [H12918]
  1907. **
  1908. */
  1909. void sqlite3_progress_handler(sqlite3*, int, int(*)(void*), void*);
  1910. /*
  1911. ** CAPI3REF: Opening A New Database Connection {H12700} <S40200>
  1912. **
  1913. ** These routines open an SQLite database file whose name is given by the
  1914. ** filename argument. The filename argument is interpreted as UTF-8 for
  1915. ** sqlite3_open() and sqlite3_open_v2() and as UTF-16 in the native byte
  1916. ** order for sqlite3_open16(). A [database connection] handle is usually
  1917. ** returned in *ppDb, even if an error occurs. The only exception is that
  1918. ** if SQLite is unable to allocate memory to hold the [sqlite3] object,
  1919. ** a NULL will be written into *ppDb instead of a pointer to the [sqlite3]
  1920. ** object. If the database is opened (and/or created) successfully, then
  1921. ** [SQLITE_OK] is returned. Otherwise an [error code] is returned. The
  1922. ** [sqlite3_errmsg()] or [sqlite3_errmsg16()] routines can be used to obtain
  1923. ** an English language description of the error.
  1924. **
  1925. ** The default encoding for the database will be UTF-8 if
  1926. ** sqlite3_open() or sqlite3_open_v2() is called and
  1927. ** UTF-16 in the native byte order if sqlite3_open16() is used.
  1928. **
  1929. ** Whether or not an error occurs when it is opened, resources
  1930. ** associated with the [database connection] handle should be released by
  1931. ** passing it to [sqlite3_close()] when it is no longer required.
  1932. **
  1933. ** The sqlite3_open_v2() interface works like sqlite3_open()
  1934. ** except that it accepts two additional parameters for additional control
  1935. ** over the new database connection. The flags parameter can take one of
  1936. ** the following three values, optionally combined with the
  1937. ** [SQLITE_OPEN_NOMUTEX] or [SQLITE_OPEN_FULLMUTEX] flags:
  1938. **
  1939. ** <dl>
  1940. ** <dt>[SQLITE_OPEN_READONLY]</dt>
  1941. ** <dd>The database is opened in read-only mode. If the database does not
  1942. ** already exist, an error is returned.</dd>
  1943. **
  1944. ** <dt>[SQLITE_OPEN_READWRITE]</dt>
  1945. ** <dd>The database is opened for reading and writing if possible, or reading
  1946. ** only if the file is write protected by the operating system. In either
  1947. ** case the database must already exist, otherwise an error is returned.</dd>
  1948. **
  1949. ** <dt>[SQLITE_OPEN_READWRITE] | [SQLITE_OPEN_CREATE]</dt>
  1950. ** <dd>The database is opened for reading and writing, and is creates it if
  1951. ** it does not already exist. This is the behavior that is always used for
  1952. ** sqlite3_open() and sqlite3_open16().</dd>
  1953. ** </dl>
  1954. **
  1955. ** If the 3rd parameter to sqlite3_open_v2() is not one of the
  1956. ** combinations shown above or one of the combinations shown above combined
  1957. ** with the [SQLITE_OPEN_NOMUTEX] or [SQLITE_OPEN_FULLMUTEX] flags,
  1958. ** then the behavior is undefined.
  1959. **
  1960. ** If the [SQLITE_OPEN_NOMUTEX] flag is set, then the database connection
  1961. ** opens in the multi-thread [threading mode] as long as the single-thread
  1962. ** mode has not been set at compile-time or start-time. If the
  1963. ** [SQLITE_OPEN_FULLMUTEX] flag is set then the database connection opens
  1964. ** in the serialized [threading mode] unless single-thread was
  1965. ** previously selected at compile-time or start-time.
  1966. **
  1967. ** If the filename is ":memory:", then a private, temporary in-memory database
  1968. ** is created for the connection. This in-memory database will vanish when
  1969. ** the database connection is closed. Future versions of SQLite might
  1970. ** make use of additional special filenames that begin with the ":" character.
  1971. ** It is recommended that when a database filename actually does begin with
  1972. ** a ":" character you should prefix the filename with a pathname such as
  1973. ** "./" to avoid ambiguity.
  1974. **
  1975. ** If the filename is an empty string, then a private, temporary
  1976. ** on-disk database will be created. This private database will be
  1977. ** automatically deleted as soon as the database connection is closed.
  1978. **
  1979. ** The fourth parameter to sqlite3_open_v2() is the name of the
  1980. ** [sqlite3_vfs] object that defines the operating system interface that
  1981. ** the new database connection should use. If the fourth parameter is
  1982. ** a NULL pointer then the default [sqlite3_vfs] object is used.
  1983. **
  1984. ** <b>Note to Windows users:</b> The encoding used for the filename argument
  1985. ** of sqlite3_open() and sqlite3_open_v2() must be UTF-8, not whatever
  1986. ** codepage is currently defined. Filenames containing international
  1987. ** characters must be converted to UTF-8 prior to passing them into
  1988. ** sqlite3_open() or sqlite3_open_v2().
  1989. **
  1990. ** Requirements:
  1991. ** [H12701] [H12702] [H12703] [H12704] [H12706] [H12707] [H12709] [H12711]
  1992. ** [H12712] [H12713] [H12714] [H12717] [H12719] [H12721] [H12723]
  1993. */
  1994. int sqlite3_open(
  1995. const char *filename, /* Database filename (UTF-8) */
  1996. sqlite3 **ppDb /* OUT: SQLite db handle */
  1997. );
  1998. int sqlite3_open16(
  1999. const void *filename, /* Database filename (UTF-16) */
  2000. sqlite3 **ppDb /* OUT: SQLite db handle */
  2001. );
  2002. int sqlite3_open_v2(
  2003. const char *filename, /* Database filename (UTF-8) */
  2004. sqlite3 **ppDb, /* OUT: SQLite db handle */
  2005. int flags, /* Flags */
  2006. const char *zVfs /* Name of VFS module to use */
  2007. );
  2008. /*
  2009. ** CAPI3REF: Error Codes And Messages {H12800} <S60200>
  2010. **
  2011. ** The sqlite3_errcode() interface returns the numeric [result code] or
  2012. ** [extended result code] for the most recent failed sqlite3_* API call
  2013. ** associated with a [database connection]. If a prior API call failed
  2014. ** but the most recent API call succeeded, the return value from
  2015. ** sqlite3_errcode() is undefined. The sqlite3_extended_errcode()
  2016. ** interface is the same except that it always returns the
  2017. ** [extended result code] even when extended result codes are
  2018. ** disabled.
  2019. **
  2020. ** The sqlite3_errmsg() and sqlite3_errmsg16() return English-language
  2021. ** text that describes the error, as either UTF-8 or UTF-16 respectively.
  2022. ** Memory to hold the error message string is managed internally.
  2023. ** The application does not need to worry about freeing the result.
  2024. ** However, the error string might be overwritten or deallocated by
  2025. ** subsequent calls to other SQLite interface functions.
  2026. **
  2027. ** When the serialized [threading mode] is in use, it might be the
  2028. ** case that a second error occurs on a separate thread in between
  2029. ** the time of the first error and the call to these interfaces.
  2030. ** When that happens, the second error will be reported since these
  2031. ** interfaces always report the most recent result. To avoid
  2032. ** this, each thread can obtain exclusive use of the [database connection] D
  2033. ** by invoking [sqlite3_mutex_enter]([sqlite3_db_mutex](D)) before beginning
  2034. ** to use D and invoking [sqlite3_mutex_leave]([sqlite3_db_mutex](D)) after
  2035. ** all calls to the interfaces listed here are completed.
  2036. **
  2037. ** If an interface fails with SQLITE_MISUSE, that means the interface
  2038. ** was invoked incorrectly by the application. In that case, the
  2039. ** error code and message may or may not be set.
  2040. **
  2041. ** Requirements:
  2042. ** [H12801] [H12802] [H12803] [H12807] [H12808] [H12809]
  2043. */
  2044. int sqlite3_errcode(sqlite3 *db);
  2045. int sqlite3_extended_errcode(sqlite3 *db);
  2046. const char *sqlite3_errmsg(sqlite3*);
  2047. const void *sqlite3_errmsg16(sqlite3*);
  2048. /*
  2049. ** CAPI3REF: SQL Statement Object {H13000} <H13010>
  2050. ** KEYWORDS: {prepared statement} {prepared statements}
  2051. **
  2052. ** An instance of this object represents a single SQL statement.
  2053. ** This object is variously known as a "prepared statement" or a
  2054. ** "compiled SQL statement" or simply as a "statement".
  2055. **
  2056. ** The life of a statement object goes something like this:
  2057. **
  2058. ** <ol>
  2059. ** <li> Create the object using [sqlite3_prepare_v2()] or a related
  2060. ** function.
  2061. ** <li> Bind values to [host parameters] using the sqlite3_bind_*()
  2062. ** interfaces.
  2063. ** <li> Run the SQL by calling [sqlite3_step()] one or more times.
  2064. ** <li> Reset the statement using [sqlite3_reset()] then go back
  2065. ** to step 2. Do this zero or more times.
  2066. ** <li> Destroy the object using [sqlite3_finalize()].
  2067. ** </ol>
  2068. **
  2069. ** Refer to documentation on individual methods above for additional
  2070. ** information.
  2071. */
  2072. typedef struct sqlite3_stmt sqlite3_stmt;
  2073. /*
  2074. ** CAPI3REF: Run-time Limits {H12760} <S20600>
  2075. **
  2076. ** This interface allows the size of various constructs to be limited
  2077. ** on a connection by connection basis. The first parameter is the
  2078. ** [database connection] whose limit is to be set or queried. The
  2079. ** second parameter is one of the [limit categories] that define a
  2080. ** class of constructs to be size limited. The third parameter is the
  2081. ** new limit for that construct. The function returns the old limit.
  2082. **
  2083. ** If the new limit is a negative number, the limit is unchanged.
  2084. ** For the limit category of SQLITE_LIMIT_XYZ there is a
  2085. ** [limits | hard upper bound]
  2086. ** set by a compile-time C preprocessor macro named
  2087. ** [limits | SQLITE_MAX_XYZ].
  2088. ** (The "_LIMIT_" in the name is changed to "_MAX_".)
  2089. ** Attempts to increase a limit above its hard upper bound are
  2090. ** silently truncated to the hard upper limit.
  2091. **
  2092. ** Run time limits are intended for use in applications that manage
  2093. ** both their own internal database and also databases that are controlled
  2094. ** by untrusted external sources. An example application might be a
  2095. ** web browser that has its own databases for storing history and
  2096. ** separate databases controlled by JavaScript applications downloaded
  2097. ** off the Internet. The internal databases can be given the
  2098. ** large, default limits. Databases managed by external sources can
  2099. ** be given much smaller limits designed to prevent a denial of service
  2100. ** attack. Developers might also want to use the [sqlite3_set_authorizer()]
  2101. ** interface to further control untrusted SQL. The size of the database
  2102. ** created by an untrusted script can be contained using the
  2103. ** [max_page_count] [PRAGMA].
  2104. **
  2105. ** New run-time limit categories may be added in future releases.
  2106. **
  2107. ** Requirements:
  2108. ** [H12762] [H12766] [H12769]
  2109. */
  2110. int sqlite3_limit(sqlite3*, int id, int newVal);
  2111. /*
  2112. ** CAPI3REF: Run-Time Limit Categories {H12790} <H12760>
  2113. ** KEYWORDS: {limit category} {limit categories}
  2114. **
  2115. ** These constants define various performance limits
  2116. ** that can be lowered at run-time using [sqlite3_limit()].
  2117. ** The synopsis of the meanings of the various limits is shown below.
  2118. ** Additional information is available at [limits | Limits in SQLite].
  2119. **
  2120. ** <dl>
  2121. ** <dt>SQLITE_LIMIT_LENGTH</dt>
  2122. ** <dd>The maximum size of any string or BLOB or table row.<dd>
  2123. **
  2124. ** <dt>SQLITE_LIMIT_SQL_LENGTH</dt>
  2125. ** <dd>The maximum length of an SQL statement.</dd>
  2126. **
  2127. ** <dt>SQLITE_LIMIT_COLUMN</dt>
  2128. ** <dd>The maximum number of columns in a table definition or in the
  2129. ** result set of a [SELECT] or the maximum number of columns in an index
  2130. ** or in an ORDER BY or GROUP BY clause.</dd>
  2131. **
  2132. ** <dt>SQLITE_LIMIT_EXPR_DEPTH</dt>
  2133. ** <dd>The maximum depth of the parse tree on any expression.</dd>
  2134. **
  2135. ** <dt>SQLITE_LIMIT_COMPOUND_SELECT</dt>
  2136. ** <dd>The maximum number of terms in a compound SELECT statement.</dd>
  2137. **
  2138. ** <dt>SQLITE_LIMIT_VDBE_OP</dt>
  2139. ** <dd>The maximum number of instructions in a virtual machine program
  2140. ** used to implement an SQL statement.</dd>
  2141. **
  2142. ** <dt>SQLITE_LIMIT_FUNCTION_ARG</dt>
  2143. ** <dd>The maximum number of arguments on a function.</dd>
  2144. **
  2145. ** <dt>SQLITE_LIMIT_ATTACHED</dt>
  2146. ** <dd>The maximum number of [ATTACH | attached databases].</dd>
  2147. **
  2148. ** <dt>SQLITE_LIMIT_LIKE_PATTERN_LENGTH</dt>
  2149. ** <dd>The maximum length of the pattern argument to the [LIKE] or
  2150. ** [GLOB] operators.</dd>
  2151. **
  2152. ** <dt>SQLITE_LIMIT_VARIABLE_NUMBER</dt>
  2153. ** <dd>The maximum number of variables in an SQL statement that can
  2154. ** be bound.</dd>
  2155. ** </dl>
  2156. */
  2157. #define SQLITE_LIMIT_LENGTH 0
  2158. #define SQLITE_LIMIT_SQL_LENGTH 1
  2159. #define SQLITE_LIMIT_COLUMN 2
  2160. #define SQLITE_LIMIT_EXPR_DEPTH 3
  2161. #define SQLITE_LIMIT_COMPOUND_SELECT 4
  2162. #define SQLITE_LIMIT_VDBE_OP 5
  2163. #define SQLITE_LIMIT_FUNCTION_ARG 6
  2164. #define SQLITE_LIMIT_ATTACHED 7
  2165. #define SQLITE_LIMIT_LIKE_PATTERN_LENGTH 8
  2166. #define SQLITE_LIMIT_VARIABLE_NUMBER 9
  2167. /*
  2168. ** CAPI3REF: Compiling An SQL Statement {H13010} <S10000>
  2169. ** KEYWORDS: {SQL statement compiler}
  2170. **
  2171. ** To execute an SQL query, it must first be compiled into a byte-code
  2172. ** program using one of these routines.
  2173. **
  2174. ** The first argument, "db", is a [database connection] obtained from a
  2175. ** prior call to [sqlite3_open()], [sqlite3_open_v2()] or [sqlite3_open16()].
  2176. **
  2177. ** The second argument, "zSql", is the statement to be compiled, encoded
  2178. ** as either UTF-8 or UTF-16. The sqlite3_prepare() and sqlite3_prepare_v2()
  2179. ** interfaces use UTF-8, and sqlite3_prepare16() and sqlite3_prepare16_v2()
  2180. ** use UTF-16.
  2181. **
  2182. ** If the nByte argument is less than zero, then zSql is read up to the
  2183. ** first zero terminator. If nByte is non-negative, then it is the maximum
  2184. ** number of bytes read from zSql. When nByte is non-negative, the
  2185. ** zSql string ends at either the first '\000' or '\u0000' character or
  2186. ** the nByte-th byte, whichever comes first. If the caller knows
  2187. ** that the supplied string is nul-terminated, then there is a small
  2188. ** performance advantage to be gained by passing an nByte parameter that
  2189. ** is equal to the number of bytes in the input string <i>including</i>
  2190. ** the nul-terminator bytes.
  2191. **
  2192. ** *pzTail is made to point to the first byte past the end of the
  2193. ** first SQL statement in zSql. These routines only compile the first
  2194. ** statement in zSql, so *pzTail is left pointing to what remains
  2195. ** uncompiled.
  2196. **
  2197. ** *ppStmt is left pointing to a compiled [prepared statement] that can be
  2198. ** executed using [sqlite3_step()]. If there is an error, *ppStmt is set
  2199. ** to NULL. If the input text contains no SQL (if the input is an empty
  2200. ** string or a comment) then *ppStmt is set to NULL.
  2201. ** {A13018} The calling procedure is responsible for deleting the compiled
  2202. ** SQL statement using [sqlite3_finalize()] after it has finished with it.
  2203. **
  2204. ** On success, [SQLITE_OK] is returned, otherwise an [error code] is returned.
  2205. **
  2206. ** The sqlite3_prepare_v2() and sqlite3_prepare16_v2() interfaces are
  2207. ** recommended for all new programs. The two older interfaces are retained
  2208. ** for backwards compatibility, but their use is discouraged.
  2209. ** In the "v2" interfaces, the prepared statement
  2210. ** that is returned (the [sqlite3_stmt] object) contains a copy of the
  2211. ** original SQL text. This causes the [sqlite3_step()] interface to
  2212. ** behave a differently in two ways:
  2213. **
  2214. ** <ol>
  2215. ** <li>
  2216. ** If the database schema changes, instead of returning [SQLITE_SCHEMA] as it
  2217. ** always used to do, [sqlite3_step()] will automatically recompile the SQL
  2218. ** statement and try to run it again. If the schema has changed in
  2219. ** a way that makes the statement no longer valid, [sqlite3_step()] will still
  2220. ** return [SQLITE_SCHEMA]. But unlike the legacy behavior, [SQLITE_SCHEMA] is
  2221. ** now a fatal error. Calling [sqlite3_prepare_v2()] again will not make the
  2222. ** error go away. Note: use [sqlite3_errmsg()] to find the text
  2223. ** of the parsing error that results in an [SQLITE_SCHEMA] return.
  2224. ** </li>
  2225. **
  2226. ** <li>
  2227. ** When an error occurs, [sqlite3_step()] will return one of the detailed
  2228. ** [error codes] or [extended error codes]. The legacy behavior was that
  2229. ** [sqlite3_step()] would only return a generic [SQLITE_ERROR] result code
  2230. ** and you would have to make a second call to [sqlite3_reset()] in order
  2231. ** to find the underlying cause of the problem. With the "v2" prepare
  2232. ** interfaces, the underlying reason for the error is returned immediately.
  2233. ** </li>
  2234. ** </ol>
  2235. **
  2236. ** Requirements:
  2237. ** [H13011] [H13012] [H13013] [H13014] [H13015] [H13016] [H13019] [H13021]
  2238. **
  2239. */
  2240. int sqlite3_prepare(
  2241. sqlite3 *db, /* Database handle */
  2242. const char *zSql, /* SQL statement, UTF-8 encoded */
  2243. int nByte, /* Maximum length of zSql in bytes. */
  2244. sqlite3_stmt **ppStmt, /* OUT: Statement handle */
  2245. const char **pzTail /* OUT: Pointer to unused portion of zSql */
  2246. );
  2247. int sqlite3_prepare_v2(
  2248. sqlite3 *db, /* Database handle */
  2249. const char *zSql, /* SQL statement, UTF-8 encoded */
  2250. int nByte, /* Maximum length of zSql in bytes. */
  2251. sqlite3_stmt **ppStmt, /* OUT: Statement handle */
  2252. const char **pzTail /* OUT: Pointer to unused portion of zSql */
  2253. );
  2254. int sqlite3_prepare16(
  2255. sqlite3 *db, /* Database handle */
  2256. const void *zSql, /* SQL statement, UTF-16 encoded */
  2257. int nByte, /* Maximum length of zSql in bytes. */
  2258. sqlite3_stmt **ppStmt, /* OUT: Statement handle */
  2259. const void **pzTail /* OUT: Pointer to unused portion of zSql */
  2260. );
  2261. int sqlite3_prepare16_v2(
  2262. sqlite3 *db, /* Database handle */
  2263. const void *zSql, /* SQL statement, UTF-16 encoded */
  2264. int nByte, /* Maximum length of zSql in bytes. */
  2265. sqlite3_stmt **ppStmt, /* OUT: Statement handle */
  2266. const void **pzTail /* OUT: Pointer to unused portion of zSql */
  2267. );
  2268. /*
  2269. ** CAPI3REF: Retrieving Statement SQL {H13100} <H13000>
  2270. **
  2271. ** This interface can be used to retrieve a saved copy of the original
  2272. ** SQL text used to create a [prepared statement] if that statement was
  2273. ** compiled using either [sqlite3_prepare_v2()] or [sqlite3_prepare16_v2()].
  2274. **
  2275. ** Requirements:
  2276. ** [H13101] [H13102] [H13103]
  2277. */
  2278. const char *sqlite3_sql(sqlite3_stmt *pStmt);
  2279. /*
  2280. ** CAPI3REF: Dynamically Typed Value Object {H15000} <S20200>
  2281. ** KEYWORDS: {protected sqlite3_value} {unprotected sqlite3_value}
  2282. **
  2283. ** SQLite uses the sqlite3_value object to represent all values
  2284. ** that can be stored in a database table. SQLite uses dynamic typing
  2285. ** for the values it stores. Values stored in sqlite3_value objects
  2286. ** can be integers, floating point values, strings, BLOBs, or NULL.
  2287. **
  2288. ** An sqlite3_value object may be either "protected" or "unprotected".
  2289. ** Some interfaces require a protected sqlite3_value. Other interfaces
  2290. ** will accept either a protected or an unprotected sqlite3_value.
  2291. ** Every interface that accepts sqlite3_value arguments specifies
  2292. ** whether or not it requires a protected sqlite3_value.
  2293. **
  2294. ** The terms "protected" and "unprotected" refer to whether or not
  2295. ** a mutex is held. A internal mutex is held for a protected
  2296. ** sqlite3_value object but no mutex is held for an unprotected
  2297. ** sqlite3_value object. If SQLite is compiled to be single-threaded
  2298. ** (with [SQLITE_THREADSAFE=0] and with [sqlite3_threadsafe()] returning 0)
  2299. ** or if SQLite is run in one of reduced mutex modes
  2300. ** [SQLITE_CONFIG_SINGLETHREAD] or [SQLITE_CONFIG_MULTITHREAD]
  2301. ** then there is no distinction between protected and unprotected
  2302. ** sqlite3_value objects and they can be used interchangeably. However,
  2303. ** for maximum code portability it is recommended that applications
  2304. ** still make the distinction between between protected and unprotected
  2305. ** sqlite3_value objects even when not strictly required.
  2306. **
  2307. ** The sqlite3_value objects that are passed as parameters into the
  2308. ** implementation of [application-defined SQL functions] are protected.
  2309. ** The sqlite3_value object returned by
  2310. ** [sqlite3_column_value()] is unprotected.
  2311. ** Unprotected sqlite3_value objects may only be used with
  2312. ** [sqlite3_result_value()] and [sqlite3_bind_value()].
  2313. ** The [sqlite3_value_blob | sqlite3_value_type()] family of
  2314. ** interfaces require protected sqlite3_value objects.
  2315. */
  2316. typedef struct Mem sqlite3_value;
  2317. /*
  2318. ** CAPI3REF: SQL Function Context Object {H16001} <S20200>
  2319. **
  2320. ** The context in which an SQL function executes is stored in an
  2321. ** sqlite3_context object. A pointer to an sqlite3_context object
  2322. ** is always first parameter to [application-defined SQL functions].
  2323. ** The application-defined SQL function implementation will pass this
  2324. ** pointer through into calls to [sqlite3_result_int | sqlite3_result()],
  2325. ** [sqlite3_aggregate_context()], [sqlite3_user_data()],
  2326. ** [sqlite3_context_db_handle()], [sqlite3_get_auxdata()],
  2327. ** and/or [sqlite3_set_auxdata()].
  2328. */
  2329. typedef struct sqlite3_context sqlite3_context;
  2330. /*
  2331. ** CAPI3REF: Binding Values To Prepared Statements {H13500} <S70300>
  2332. ** KEYWORDS: {host parameter} {host parameters} {host parameter name}
  2333. ** KEYWORDS: {SQL parameter} {SQL parameters} {parameter binding}
  2334. **
  2335. ** In the SQL strings input to [sqlite3_prepare_v2()] and its variants,
  2336. ** literals may be replaced by a [parameter] in one of these forms:
  2337. **
  2338. ** <ul>
  2339. ** <li> ?
  2340. ** <li> ?NNN
  2341. ** <li> :VVV
  2342. ** <li> @VVV
  2343. ** <li> $VVV
  2344. ** </ul>
  2345. **
  2346. ** In the parameter forms shown above NNN is an integer literal,
  2347. ** and VVV is an alpha-numeric parameter name. The values of these
  2348. ** parameters (also called "host parameter names" or "SQL parameters")
  2349. ** can be set using the sqlite3_bind_*() routines defined here.
  2350. **
  2351. ** The first argument to the sqlite3_bind_*() routines is always
  2352. ** a pointer to the [sqlite3_stmt] object returned from
  2353. ** [sqlite3_prepare_v2()] or its variants.
  2354. **
  2355. ** The second argument is the index of the SQL parameter to be set.
  2356. ** The leftmost SQL parameter has an index of 1. When the same named
  2357. ** SQL parameter is used more than once, second and subsequent
  2358. ** occurrences have the same index as the first occurrence.
  2359. ** The index for named parameters can be looked up using the
  2360. ** [sqlite3_bind_parameter_index()] API if desired. The index
  2361. ** for "?NNN" parameters is the value of NNN.
  2362. ** The NNN value must be between 1 and the [sqlite3_limit()]
  2363. ** parameter [SQLITE_LIMIT_VARIABLE_NUMBER] (default value: 999).
  2364. **
  2365. ** The third argument is the value to bind to the parameter.
  2366. **
  2367. ** In those routines that have a fourth argument, its value is the
  2368. ** number of bytes in the parameter. To be clear: the value is the
  2369. ** number of <u>bytes</u> in the value, not the number of characters.
  2370. ** If the fourth parameter is negative, the length of the string is
  2371. ** the number of bytes up to the first zero terminator.
  2372. **
  2373. ** The fifth argument to sqlite3_bind_blob(), sqlite3_bind_text(), and
  2374. ** sqlite3_bind_text16() is a destructor used to dispose of the BLOB or
  2375. ** string after SQLite has finished with it. If the fifth argument is
  2376. ** the special value [SQLITE_STATIC], then SQLite assumes that the
  2377. ** information is in static, unmanaged space and does not need to be freed.
  2378. ** If the fifth argument has the value [SQLITE_TRANSIENT], then
  2379. ** SQLite makes its own private copy of the data immediately, before
  2380. ** the sqlite3_bind_*() routine returns.
  2381. **
  2382. ** The sqlite3_bind_zeroblob() routine binds a BLOB of length N that
  2383. ** is filled with zeroes. A zeroblob uses a fixed amount of memory
  2384. ** (just an integer to hold its size) while it is being processed.
  2385. ** Zeroblobs are intended to serve as placeholders for BLOBs whose
  2386. ** content is later written using
  2387. ** [sqlite3_blob_open | incremental BLOB I/O] routines.
  2388. ** A negative value for the zeroblob results in a zero-length BLOB.
  2389. **
  2390. ** The sqlite3_bind_*() routines must be called after
  2391. ** [sqlite3_prepare_v2()] (and its variants) or [sqlite3_reset()] and
  2392. ** before [sqlite3_step()].
  2393. ** Bindings are not cleared by the [sqlite3_reset()] routine.
  2394. ** Unbound parameters are interpreted as NULL.
  2395. **
  2396. ** These routines return [SQLITE_OK] on success or an error code if
  2397. ** anything goes wrong. [SQLITE_RANGE] is returned if the parameter
  2398. ** index is out of range. [SQLITE_NOMEM] is returned if malloc() fails.
  2399. ** [SQLITE_MISUSE] might be returned if these routines are called on a
  2400. ** virtual machine that is the wrong state or which has already been finalized.
  2401. ** Detection of misuse is unreliable. Applications should not depend
  2402. ** on SQLITE_MISUSE returns. SQLITE_MISUSE is intended to indicate a
  2403. ** a logic error in the application. Future versions of SQLite might
  2404. ** panic rather than return SQLITE_MISUSE.
  2405. **
  2406. ** See also: [sqlite3_bind_parameter_count()],
  2407. ** [sqlite3_bind_parameter_name()], and [sqlite3_bind_parameter_index()].
  2408. **
  2409. ** Requirements:
  2410. ** [H13506] [H13509] [H13512] [H13515] [H13518] [H13521] [H13524] [H13527]
  2411. ** [H13530] [H13533] [H13536] [H13539] [H13542] [H13545] [H13548] [H13551]
  2412. **
  2413. */
  2414. int sqlite3_bind_blob(sqlite3_stmt*, int, const void*, int n, void(*)(void*));
  2415. int sqlite3_bind_double(sqlite3_stmt*, int, double);
  2416. int sqlite3_bind_int(sqlite3_stmt*, int, int);
  2417. int sqlite3_bind_int64(sqlite3_stmt*, int, sqlite3_int64);
  2418. int sqlite3_bind_null(sqlite3_stmt*, int);
  2419. int sqlite3_bind_text(sqlite3_stmt*, int, const char*, int n, void(*)(void*));
  2420. int sqlite3_bind_text16(sqlite3_stmt*, int, const void*, int, void(*)(void*));
  2421. int sqlite3_bind_value(sqlite3_stmt*, int, const sqlite3_value*);
  2422. int sqlite3_bind_zeroblob(sqlite3_stmt*, int, int n);
  2423. /*
  2424. ** CAPI3REF: Number Of SQL Parameters {H13600} <S70300>
  2425. **
  2426. ** This routine can be used to find the number of [SQL parameters]
  2427. ** in a [prepared statement]. SQL parameters are tokens of the
  2428. ** form "?", "?NNN", ":AAA", "$AAA", or "@AAA" that serve as
  2429. ** placeholders for values that are [sqlite3_bind_blob | bound]
  2430. ** to the parameters at a later time.
  2431. **
  2432. ** This routine actually returns the index of the largest (rightmost)
  2433. ** parameter. For all forms except ?NNN, this will correspond to the
  2434. ** number of unique parameters. If parameters of the ?NNN are used,
  2435. ** there may be gaps in the list.
  2436. **
  2437. ** See also: [sqlite3_bind_blob|sqlite3_bind()],
  2438. ** [sqlite3_bind_parameter_name()], and
  2439. ** [sqlite3_bind_parameter_index()].
  2440. **
  2441. ** Requirements:
  2442. ** [H13601]
  2443. */
  2444. int sqlite3_bind_parameter_count(sqlite3_stmt*);
  2445. /*
  2446. ** CAPI3REF: Name Of A Host Parameter {H13620} <S70300>
  2447. **
  2448. ** This routine returns a pointer to the name of the n-th
  2449. ** [SQL parameter] in a [prepared statement].
  2450. ** SQL parameters of the form "?NNN" or ":AAA" or "@AAA" or "$AAA"
  2451. ** have a name which is the string "?NNN" or ":AAA" or "@AAA" or "$AAA"
  2452. ** respectively.
  2453. ** In other words, the initial ":" or "$" or "@" or "?"
  2454. ** is included as part of the name.
  2455. ** Parameters of the form "?" without a following integer have no name
  2456. ** and are also referred to as "anonymous parameters".
  2457. **
  2458. ** The first host parameter has an index of 1, not 0.
  2459. **
  2460. ** If the value n is out of range or if the n-th parameter is
  2461. ** nameless, then NULL is returned. The returned string is
  2462. ** always in UTF-8 encoding even if the named parameter was
  2463. ** originally specified as UTF-16 in [sqlite3_prepare16()] or
  2464. ** [sqlite3_prepare16_v2()].
  2465. **
  2466. ** See also: [sqlite3_bind_blob|sqlite3_bind()],
  2467. ** [sqlite3_bind_parameter_count()], and
  2468. ** [sqlite3_bind_parameter_index()].
  2469. **
  2470. ** Requirements:
  2471. ** [H13621]
  2472. */
  2473. const char *sqlite3_bind_parameter_name(sqlite3_stmt*, int);
  2474. /*
  2475. ** CAPI3REF: Index Of A Parameter With A Given Name {H13640} <S70300>
  2476. **
  2477. ** Return the index of an SQL parameter given its name. The
  2478. ** index value returned is suitable for use as the second
  2479. ** parameter to [sqlite3_bind_blob|sqlite3_bind()]. A zero
  2480. ** is returned if no matching parameter is found. The parameter
  2481. ** name must be given in UTF-8 even if the original statement
  2482. ** was prepared from UTF-16 text using [sqlite3_prepare16_v2()].
  2483. **
  2484. ** See also: [sqlite3_bind_blob|sqlite3_bind()],
  2485. ** [sqlite3_bind_parameter_count()], and
  2486. ** [sqlite3_bind_parameter_index()].
  2487. **
  2488. ** Requirements:
  2489. ** [H13641]
  2490. */
  2491. int sqlite3_bind_parameter_index(sqlite3_stmt*, const char *zName);
  2492. /*
  2493. ** CAPI3REF: Reset All Bindings On A Prepared Statement {H13660} <S70300>
  2494. **
  2495. ** Contrary to the intuition of many, [sqlite3_reset()] does not reset
  2496. ** the [sqlite3_bind_blob | bindings] on a [prepared statement].
  2497. ** Use this routine to reset all host parameters to NULL.
  2498. **
  2499. ** Requirements:
  2500. ** [H13661]
  2501. */
  2502. int sqlite3_clear_bindings(sqlite3_stmt*);
  2503. /*
  2504. ** CAPI3REF: Number Of Columns In A Result Set {H13710} <S10700>
  2505. **
  2506. ** Return the number of columns in the result set returned by the
  2507. ** [prepared statement]. This routine returns 0 if pStmt is an SQL
  2508. ** statement that does not return data (for example an [UPDATE]).
  2509. **
  2510. ** Requirements:
  2511. ** [H13711]
  2512. */
  2513. int sqlite3_column_count(sqlite3_stmt *pStmt);
  2514. /*
  2515. ** CAPI3REF: Column Names In A Result Set {H13720} <S10700>
  2516. **
  2517. ** These routines return the name assigned to a particular column
  2518. ** in the result set of a [SELECT] statement. The sqlite3_column_name()
  2519. ** interface returns a pointer to a zero-terminated UTF-8 string
  2520. ** and sqlite3_column_name16() returns a pointer to a zero-terminated
  2521. ** UTF-16 string. The first parameter is the [prepared statement]
  2522. ** that implements the [SELECT] statement. The second parameter is the
  2523. ** column number. The leftmost column is number 0.
  2524. **
  2525. ** The returned string pointer is valid until either the [prepared statement]
  2526. ** is destroyed by [sqlite3_finalize()] or until the next call to
  2527. ** sqlite3_column_name() or sqlite3_column_name16() on the same column.
  2528. **
  2529. ** If sqlite3_malloc() fails during the processing of either routine
  2530. ** (for example during a conversion from UTF-8 to UTF-16) then a
  2531. ** NULL pointer is returned.
  2532. **
  2533. ** The name of a result column is the value of the "AS" clause for
  2534. ** that column, if there is an AS clause. If there is no AS clause
  2535. ** then the name of the column is unspecified and may change from
  2536. ** one release of SQLite to the next.
  2537. **
  2538. ** Requirements:
  2539. ** [H13721] [H13723] [H13724] [H13725] [H13726] [H13727]
  2540. */
  2541. const char *sqlite3_column_name(sqlite3_stmt*, int N);
  2542. const void *sqlite3_column_name16(sqlite3_stmt*, int N);
  2543. /*
  2544. ** CAPI3REF: Source Of Data In A Query Result {H13740} <S10700>
  2545. **
  2546. ** These routines provide a means to determine what column of what
  2547. ** table in which database a result of a [SELECT] statement comes from.
  2548. ** The name of the database or table or column can be returned as
  2549. ** either a UTF-8 or UTF-16 string. The _database_ routines return
  2550. ** the database name, the _table_ routines return the table name, and
  2551. ** the origin_ routines return the column name.
  2552. ** The returned string is valid until the [prepared statement] is destroyed
  2553. ** using [sqlite3_finalize()] or until the same information is requested
  2554. ** again in a different encoding.
  2555. **
  2556. ** The names returned are the original un-aliased names of the
  2557. ** database, table, and column.
  2558. **
  2559. ** The first argument to the following calls is a [prepared statement].
  2560. ** These functions return information about the Nth column returned by
  2561. ** the statement, where N is the second function argument.
  2562. **
  2563. ** If the Nth column returned by the statement is an expression or
  2564. ** subquery and is not a column value, then all of these functions return
  2565. ** NULL. These routine might also return NULL if a memory allocation error
  2566. ** occurs. Otherwise, they return the name of the attached database, table
  2567. ** and column that query result column was extracted from.
  2568. **
  2569. ** As with all other SQLite APIs, those postfixed with "16" return
  2570. ** UTF-16 encoded strings, the other functions return UTF-8. {END}
  2571. **
  2572. ** These APIs are only available if the library was compiled with the
  2573. ** [SQLITE_ENABLE_COLUMN_METADATA] C-preprocessor symbol defined.
  2574. **
  2575. ** {A13751}
  2576. ** If two or more threads call one or more of these routines against the same
  2577. ** prepared statement and column at the same time then the results are
  2578. ** undefined.
  2579. **
  2580. ** Requirements:
  2581. ** [H13741] [H13742] [H13743] [H13744] [H13745] [H13746] [H13748]
  2582. **
  2583. ** If two or more threads call one or more
  2584. ** [sqlite3_column_database_name | column metadata interfaces]
  2585. ** for the same [prepared statement] and result column
  2586. ** at the same time then the results are undefined.
  2587. */
  2588. const char *sqlite3_column_database_name(sqlite3_stmt*,int);
  2589. const void *sqlite3_column_database_name16(sqlite3_stmt*,int);
  2590. const char *sqlite3_column_table_name(sqlite3_stmt*,int);
  2591. const void *sqlite3_column_table_name16(sqlite3_stmt*,int);
  2592. const char *sqlite3_column_origin_name(sqlite3_stmt*,int);
  2593. const void *sqlite3_column_origin_name16(sqlite3_stmt*,int);
  2594. /*
  2595. ** CAPI3REF: Declared Datatype Of A Query Result {H13760} <S10700>
  2596. **
  2597. ** The first parameter is a [prepared statement].
  2598. ** If this statement is a [SELECT] statement and the Nth column of the
  2599. ** returned result set of that [SELECT] is a table column (not an
  2600. ** expression or subquery) then the declared type of the table
  2601. ** column is returned. If the Nth column of the result set is an
  2602. ** expression or subquery, then a NULL pointer is returned.
  2603. ** The returned string is always UTF-8 encoded. {END}
  2604. **
  2605. ** For example, given the database schema:
  2606. **
  2607. ** CREATE TABLE t1(c1 VARIANT);
  2608. **
  2609. ** and the following statement to be compiled:
  2610. **
  2611. ** SELECT c1 + 1, c1 FROM t1;
  2612. **
  2613. ** this routine would return the string "VARIANT" for the second result
  2614. ** column (i==1), and a NULL pointer for the first result column (i==0).
  2615. **
  2616. ** SQLite uses dynamic run-time typing. So just because a column
  2617. ** is declared to contain a particular type does not mean that the
  2618. ** data stored in that column is of the declared type. SQLite is
  2619. ** strongly typed, but the typing is dynamic not static. Type
  2620. ** is associated with individual values, not with the containers
  2621. ** used to hold those values.
  2622. **
  2623. ** Requirements:
  2624. ** [H13761] [H13762] [H13763]
  2625. */
  2626. const char *sqlite3_column_decltype(sqlite3_stmt*,int);
  2627. const void *sqlite3_column_decltype16(sqlite3_stmt*,int);
  2628. /*
  2629. ** CAPI3REF: Evaluate An SQL Statement {H13200} <S10000>
  2630. **
  2631. ** After a [prepared statement] has been prepared using either
  2632. ** [sqlite3_prepare_v2()] or [sqlite3_prepare16_v2()] or one of the legacy
  2633. ** interfaces [sqlite3_prepare()] or [sqlite3_prepare16()], this function
  2634. ** must be called one or more times to evaluate the statement.
  2635. **
  2636. ** The details of the behavior of the sqlite3_step() interface depend
  2637. ** on whether the statement was prepared using the newer "v2" interface
  2638. ** [sqlite3_prepare_v2()] and [sqlite3_prepare16_v2()] or the older legacy
  2639. ** interface [sqlite3_prepare()] and [sqlite3_prepare16()]. The use of the
  2640. ** new "v2" interface is recommended for new applications but the legacy
  2641. ** interface will continue to be supported.
  2642. **
  2643. ** In the legacy interface, the return value will be either [SQLITE_BUSY],
  2644. ** [SQLITE_DONE], [SQLITE_ROW], [SQLITE_ERROR], or [SQLITE_MISUSE].
  2645. ** With the "v2" interface, any of the other [result codes] or
  2646. ** [extended result codes] might be returned as well.
  2647. **
  2648. ** [SQLITE_BUSY] means that the database engine was unable to acquire the
  2649. ** database locks it needs to do its job. If the statement is a [COMMIT]
  2650. ** or occurs outside of an explicit transaction, then you can retry the
  2651. ** statement. If the statement is not a [COMMIT] and occurs within a
  2652. ** explicit transaction then you should rollback the transaction before
  2653. ** continuing.
  2654. **
  2655. ** [SQLITE_DONE] means that the statement has finished executing
  2656. ** successfully. sqlite3_step() should not be called again on this virtual
  2657. ** machine without first calling [sqlite3_reset()] to reset the virtual
  2658. ** machine back to its initial state.
  2659. **
  2660. ** If the SQL statement being executed returns any data, then [SQLITE_ROW]
  2661. ** is returned each time a new row of data is ready for processing by the
  2662. ** caller. The values may be accessed using the [column access functions].
  2663. ** sqlite3_step() is called again to retrieve the next row of data.
  2664. **
  2665. ** [SQLITE_ERROR] means that a run-time error (such as a constraint
  2666. ** violation) has occurred. sqlite3_step() should not be called again on
  2667. ** the VM. More information may be found by calling [sqlite3_errmsg()].
  2668. ** With the legacy interface, a more specific error code (for example,
  2669. ** [SQLITE_INTERRUPT], [SQLITE_SCHEMA], [SQLITE_CORRUPT], and so forth)
  2670. ** can be obtained by calling [sqlite3_reset()] on the
  2671. ** [prepared statement]. In the "v2" interface,
  2672. ** the more specific error code is returned directly by sqlite3_step().
  2673. **
  2674. ** [SQLITE_MISUSE] means that the this routine was called inappropriately.
  2675. ** Perhaps it was called on a [prepared statement] that has
  2676. ** already been [sqlite3_finalize | finalized] or on one that had
  2677. ** previously returned [SQLITE_ERROR] or [SQLITE_DONE]. Or it could
  2678. ** be the case that the same database connection is being used by two or
  2679. ** more threads at the same moment in time.
  2680. **
  2681. ** <b>Goofy Interface Alert:</b> In the legacy interface, the sqlite3_step()
  2682. ** API always returns a generic error code, [SQLITE_ERROR], following any
  2683. ** error other than [SQLITE_BUSY] and [SQLITE_MISUSE]. You must call
  2684. ** [sqlite3_reset()] or [sqlite3_finalize()] in order to find one of the
  2685. ** specific [error codes] that better describes the error.
  2686. ** We admit that this is a goofy design. The problem has been fixed
  2687. ** with the "v2" interface. If you prepare all of your SQL statements
  2688. ** using either [sqlite3_prepare_v2()] or [sqlite3_prepare16_v2()] instead
  2689. ** of the legacy [sqlite3_prepare()] and [sqlite3_prepare16()] interfaces,
  2690. ** then the more specific [error codes] are returned directly
  2691. ** by sqlite3_step(). The use of the "v2" interface is recommended.
  2692. **
  2693. ** Requirements:
  2694. ** [H13202] [H15304] [H15306] [H15308] [H15310]
  2695. */
  2696. int sqlite3_step(sqlite3_stmt*);
  2697. /*
  2698. ** CAPI3REF: Number of columns in a result set {H13770} <S10700>
  2699. **
  2700. ** Returns the number of values in the current row of the result set.
  2701. **
  2702. ** Requirements:
  2703. ** [H13771] [H13772]
  2704. */
  2705. int sqlite3_data_count(sqlite3_stmt *pStmt);
  2706. /*
  2707. ** CAPI3REF: Fundamental Datatypes {H10265} <S10110><S10120>
  2708. ** KEYWORDS: SQLITE_TEXT
  2709. **
  2710. ** {H10266} Every value in SQLite has one of five fundamental datatypes:
  2711. **
  2712. ** <ul>
  2713. ** <li> 64-bit signed integer
  2714. ** <li> 64-bit IEEE floating point number
  2715. ** <li> string
  2716. ** <li> BLOB
  2717. ** <li> NULL
  2718. ** </ul> {END}
  2719. **
  2720. ** These constants are codes for each of those types.
  2721. **
  2722. ** Note that the SQLITE_TEXT constant was also used in SQLite version 2
  2723. ** for a completely different meaning. Software that links against both
  2724. ** SQLite version 2 and SQLite version 3 should use SQLITE3_TEXT, not
  2725. ** SQLITE_TEXT.
  2726. */
  2727. #define SQLITE_INTEGER 1
  2728. #define SQLITE_FLOAT 2
  2729. #define SQLITE_BLOB 4
  2730. #define SQLITE_NULL 5
  2731. #ifdef SQLITE_TEXT
  2732. # undef SQLITE_TEXT
  2733. #else
  2734. # define SQLITE_TEXT 3
  2735. #endif
  2736. #define SQLITE3_TEXT 3
  2737. /*
  2738. ** CAPI3REF: Result Values From A Query {H13800} <S10700>
  2739. ** KEYWORDS: {column access functions}
  2740. **
  2741. ** These routines form the "result set query" interface.
  2742. **
  2743. ** These routines return information about a single column of the current
  2744. ** result row of a query. In every case the first argument is a pointer
  2745. ** to the [prepared statement] that is being evaluated (the [sqlite3_stmt*]
  2746. ** that was returned from [sqlite3_prepare_v2()] or one of its variants)
  2747. ** and the second argument is the index of the column for which information
  2748. ** should be returned. The leftmost column of the result set has the index 0.
  2749. **
  2750. ** If the SQL statement does not currently point to a valid row, or if the
  2751. ** column index is out of range, the result is undefined.
  2752. ** These routines may only be called when the most recent call to
  2753. ** [sqlite3_step()] has returned [SQLITE_ROW] and neither
  2754. ** [sqlite3_reset()] nor [sqlite3_finalize()] have been called subsequently.
  2755. ** If any of these routines are called after [sqlite3_reset()] or
  2756. ** [sqlite3_finalize()] or after [sqlite3_step()] has returned
  2757. ** something other than [SQLITE_ROW], the results are undefined.
  2758. ** If [sqlite3_step()] or [sqlite3_reset()] or [sqlite3_finalize()]
  2759. ** are called from a different thread while any of these routines
  2760. ** are pending, then the results are undefined.
  2761. **
  2762. ** The sqlite3_column_type() routine returns the
  2763. ** [SQLITE_INTEGER | datatype code] for the initial data type
  2764. ** of the result column. The returned value is one of [SQLITE_INTEGER],
  2765. ** [SQLITE_FLOAT], [SQLITE_TEXT], [SQLITE_BLOB], or [SQLITE_NULL]. The value
  2766. ** returned by sqlite3_column_type() is only meaningful if no type
  2767. ** conversions have occurred as described below. After a type conversion,
  2768. ** the value returned by sqlite3_column_type() is undefined. Future
  2769. ** versions of SQLite may change the behavior of sqlite3_column_type()
  2770. ** following a type conversion.
  2771. **
  2772. ** If the result is a BLOB or UTF-8 string then the sqlite3_column_bytes()
  2773. ** routine returns the number of bytes in that BLOB or string.
  2774. ** If the result is a UTF-16 string, then sqlite3_column_bytes() converts
  2775. ** the string to UTF-8 and then returns the number of bytes.
  2776. ** If the result is a numeric value then sqlite3_column_bytes() uses
  2777. ** [sqlite3_snprintf()] to convert that value to a UTF-8 string and returns
  2778. ** the number of bytes in that string.
  2779. ** The value returned does not include the zero terminator at the end
  2780. ** of the string. For clarity: the value returned is the number of
  2781. ** bytes in the string, not the number of characters.
  2782. **
  2783. ** Strings returned by sqlite3_column_text() and sqlite3_column_text16(),
  2784. ** even empty strings, are always zero terminated. The return
  2785. ** value from sqlite3_column_blob() for a zero-length BLOB is an arbitrary
  2786. ** pointer, possibly even a NULL pointer.
  2787. **
  2788. ** The sqlite3_column_bytes16() routine is similar to sqlite3_column_bytes()
  2789. ** but leaves the result in UTF-16 in native byte order instead of UTF-8.
  2790. ** The zero terminator is not included in this count.
  2791. **
  2792. ** The object returned by [sqlite3_column_value()] is an
  2793. ** [unprotected sqlite3_value] object. An unprotected sqlite3_value object
  2794. ** may only be used with [sqlite3_bind_value()] and [sqlite3_result_value()].
  2795. ** If the [unprotected sqlite3_value] object returned by
  2796. ** [sqlite3_column_value()] is used in any other way, including calls
  2797. ** to routines like [sqlite3_value_int()], [sqlite3_value_text()],
  2798. ** or [sqlite3_value_bytes()], then the behavior is undefined.
  2799. **
  2800. ** These routines attempt to convert the value where appropriate. For
  2801. ** example, if the internal representation is FLOAT and a text result
  2802. ** is requested, [sqlite3_snprintf()] is used internally to perform the
  2803. ** conversion automatically. The following table details the conversions
  2804. ** that are applied:
  2805. **
  2806. ** <blockquote>
  2807. ** <table border="1">
  2808. ** <tr><th> Internal<br>Type <th> Requested<br>Type <th> Conversion
  2809. **
  2810. ** <tr><td> NULL <td> INTEGER <td> Result is 0
  2811. ** <tr><td> NULL <td> FLOAT <td> Result is 0.0
  2812. ** <tr><td> NULL <td> TEXT <td> Result is NULL pointer
  2813. ** <tr><td> NULL <td> BLOB <td> Result is NULL pointer
  2814. ** <tr><td> INTEGER <td> FLOAT <td> Convert from integer to float
  2815. ** <tr><td> INTEGER <td> TEXT <td> ASCII rendering of the integer
  2816. ** <tr><td> INTEGER <td> BLOB <td> Same as INTEGER->TEXT
  2817. ** <tr><td> FLOAT <td> INTEGER <td> Convert from float to integer
  2818. ** <tr><td> FLOAT <td> TEXT <td> ASCII rendering of the float
  2819. ** <tr><td> FLOAT <td> BLOB <td> Same as FLOAT->TEXT
  2820. ** <tr><td> TEXT <td> INTEGER <td> Use atoi()
  2821. ** <tr><td> TEXT <td> FLOAT <td> Use atof()
  2822. ** <tr><td> TEXT <td> BLOB <td> No change
  2823. ** <tr><td> BLOB <td> INTEGER <td> Convert to TEXT then use atoi()
  2824. ** <tr><td> BLOB <td> FLOAT <td> Convert to TEXT then use atof()
  2825. ** <tr><td> BLOB <td> TEXT <td> Add a zero terminator if needed
  2826. ** </table>
  2827. ** </blockquote>
  2828. **
  2829. ** The table above makes reference to standard C library functions atoi()
  2830. ** and atof(). SQLite does not really use these functions. It has its
  2831. ** own equivalent internal routines. The atoi() and atof() names are
  2832. ** used in the table for brevity and because they are familiar to most
  2833. ** C programmers.
  2834. **
  2835. ** Note that when type conversions occur, pointers returned by prior
  2836. ** calls to sqlite3_column_blob(), sqlite3_column_text(), and/or
  2837. ** sqlite3_column_text16() may be invalidated.
  2838. ** Type conversions and pointer invalidations might occur
  2839. ** in the following cases:
  2840. **
  2841. ** <ul>
  2842. ** <li> The initial content is a BLOB and sqlite3_column_text() or
  2843. ** sqlite3_column_text16() is called. A zero-terminator might
  2844. ** need to be added to the string.</li>
  2845. ** <li> The initial content is UTF-8 text and sqlite3_column_bytes16() or
  2846. ** sqlite3_column_text16() is called. The content must be converted
  2847. ** to UTF-16.</li>
  2848. ** <li> The initial content is UTF-16 text and sqlite3_column_bytes() or
  2849. ** sqlite3_column_text() is called. The content must be converted
  2850. ** to UTF-8.</li>
  2851. ** </ul>
  2852. **
  2853. ** Conversions between UTF-16be and UTF-16le are always done in place and do
  2854. ** not invalidate a prior pointer, though of course the content of the buffer
  2855. ** that the prior pointer points to will have been modified. Other kinds
  2856. ** of conversion are done in place when it is possible, but sometimes they
  2857. ** are not possible and in those cases prior pointers are invalidated.
  2858. **
  2859. ** The safest and easiest to remember policy is to invoke these routines
  2860. ** in one of the following ways:
  2861. **
  2862. ** <ul>
  2863. ** <li>sqlite3_column_text() followed by sqlite3_column_bytes()</li>
  2864. ** <li>sqlite3_column_blob() followed by sqlite3_column_bytes()</li>
  2865. ** <li>sqlite3_column_text16() followed by sqlite3_column_bytes16()</li>
  2866. ** </ul>
  2867. **
  2868. ** In other words, you should call sqlite3_column_text(),
  2869. ** sqlite3_column_blob(), or sqlite3_column_text16() first to force the result
  2870. ** into the desired format, then invoke sqlite3_column_bytes() or
  2871. ** sqlite3_column_bytes16() to find the size of the result. Do not mix calls
  2872. ** to sqlite3_column_text() or sqlite3_column_blob() with calls to
  2873. ** sqlite3_column_bytes16(), and do not mix calls to sqlite3_column_text16()
  2874. ** with calls to sqlite3_column_bytes().
  2875. **
  2876. ** The pointers returned are valid until a type conversion occurs as
  2877. ** described above, or until [sqlite3_step()] or [sqlite3_reset()] or
  2878. ** [sqlite3_finalize()] is called. The memory space used to hold strings
  2879. ** and BLOBs is freed automatically. Do <b>not</b> pass the pointers returned
  2880. ** [sqlite3_column_blob()], [sqlite3_column_text()], etc. into
  2881. ** [sqlite3_free()].
  2882. **
  2883. ** If a memory allocation error occurs during the evaluation of any
  2884. ** of these routines, a default value is returned. The default value
  2885. ** is either the integer 0, the floating point number 0.0, or a NULL
  2886. ** pointer. Subsequent calls to [sqlite3_errcode()] will return
  2887. ** [SQLITE_NOMEM].
  2888. **
  2889. ** Requirements:
  2890. ** [H13803] [H13806] [H13809] [H13812] [H13815] [H13818] [H13821] [H13824]
  2891. ** [H13827] [H13830]
  2892. */
  2893. const void *sqlite3_column_blob(sqlite3_stmt*, int iCol);
  2894. int sqlite3_column_bytes(sqlite3_stmt*, int iCol);
  2895. int sqlite3_column_bytes16(sqlite3_stmt*, int iCol);
  2896. double sqlite3_column_double(sqlite3_stmt*, int iCol);
  2897. int sqlite3_column_int(sqlite3_stmt*, int iCol);
  2898. sqlite3_int64 sqlite3_column_int64(sqlite3_stmt*, int iCol);
  2899. const unsigned char *sqlite3_column_text(sqlite3_stmt*, int iCol);
  2900. const void *sqlite3_column_text16(sqlite3_stmt*, int iCol);
  2901. int sqlite3_column_type(sqlite3_stmt*, int iCol);
  2902. sqlite3_value *sqlite3_column_value(sqlite3_stmt*, int iCol);
  2903. /*
  2904. ** CAPI3REF: Destroy A Prepared Statement Object {H13300} <S70300><S30100>
  2905. **
  2906. ** The sqlite3_finalize() function is called to delete a [prepared statement].
  2907. ** If the statement was executed successfully or not executed at all, then
  2908. ** SQLITE_OK is returned. If execution of the statement failed then an
  2909. ** [error code] or [extended error code] is returned.
  2910. **
  2911. ** This routine can be called at any point during the execution of the
  2912. ** [prepared statement]. If the virtual machine has not
  2913. ** completed execution when this routine is called, that is like
  2914. ** encountering an error or an [sqlite3_interrupt | interrupt].
  2915. ** Incomplete updates may be rolled back and transactions canceled,
  2916. ** depending on the circumstances, and the
  2917. ** [error code] returned will be [SQLITE_ABORT].
  2918. **
  2919. ** Requirements:
  2920. ** [H11302] [H11304]
  2921. */
  2922. int sqlite3_finalize(sqlite3_stmt *pStmt);
  2923. /*
  2924. ** CAPI3REF: Reset A Prepared Statement Object {H13330} <S70300>
  2925. **
  2926. ** The sqlite3_reset() function is called to reset a [prepared statement]
  2927. ** object back to its initial state, ready to be re-executed.
  2928. ** Any SQL statement variables that had values bound to them using
  2929. ** the [sqlite3_bind_blob | sqlite3_bind_*() API] retain their values.
  2930. ** Use [sqlite3_clear_bindings()] to reset the bindings.
  2931. **
  2932. ** {H11332} The [sqlite3_reset(S)] interface resets the [prepared statement] S
  2933. ** back to the beginning of its program.
  2934. **
  2935. ** {H11334} If the most recent call to [sqlite3_step(S)] for the
  2936. ** [prepared statement] S returned [SQLITE_ROW] or [SQLITE_DONE],
  2937. ** or if [sqlite3_step(S)] has never before been called on S,
  2938. ** then [sqlite3_reset(S)] returns [SQLITE_OK].
  2939. **
  2940. ** {H11336} If the most recent call to [sqlite3_step(S)] for the
  2941. ** [prepared statement] S indicated an error, then
  2942. ** [sqlite3_reset(S)] returns an appropriate [error code].
  2943. **
  2944. ** {H11338} The [sqlite3_reset(S)] interface does not change the values
  2945. ** of any [sqlite3_bind_blob|bindings] on the [prepared statement] S.
  2946. */
  2947. int sqlite3_reset(sqlite3_stmt *pStmt);
  2948. /*
  2949. ** CAPI3REF: Create Or Redefine SQL Functions {H16100} <S20200>
  2950. ** KEYWORDS: {function creation routines}
  2951. ** KEYWORDS: {application-defined SQL function}
  2952. ** KEYWORDS: {application-defined SQL functions}
  2953. **
  2954. ** These two functions (collectively known as "function creation routines")
  2955. ** are used to add SQL functions or aggregates or to redefine the behavior
  2956. ** of existing SQL functions or aggregates. The only difference between the
  2957. ** two is that the second parameter, the name of the (scalar) function or
  2958. ** aggregate, is encoded in UTF-8 for sqlite3_create_function() and UTF-16
  2959. ** for sqlite3_create_function16().
  2960. **
  2961. ** The first parameter is the [database connection] to which the SQL
  2962. ** function is to be added. If a single program uses more than one database
  2963. ** connection internally, then SQL functions must be added individually to
  2964. ** each database connection.
  2965. **
  2966. ** The second parameter is the name of the SQL function to be created or
  2967. ** redefined. The length of the name is limited to 255 bytes, exclusive of
  2968. ** the zero-terminator. Note that the name length limit is in bytes, not
  2969. ** characters. Any attempt to create a function with a longer name
  2970. ** will result in [SQLITE_ERROR] being returned.
  2971. **
  2972. ** The third parameter (nArg)
  2973. ** is the number of arguments that the SQL function or
  2974. ** aggregate takes. If this parameter is negative, then the SQL function or
  2975. ** aggregate may take any number of arguments.
  2976. **
  2977. ** The fourth parameter, eTextRep, specifies what
  2978. ** [SQLITE_UTF8 | text encoding] this SQL function prefers for
  2979. ** its parameters. Any SQL function implementation should be able to work
  2980. ** work with UTF-8, UTF-16le, or UTF-16be. But some implementations may be
  2981. ** more efficient with one encoding than another. It is allowed to
  2982. ** invoke sqlite3_create_function() or sqlite3_create_function16() multiple
  2983. ** times with the same function but with different values of eTextRep.
  2984. ** When multiple implementations of the same function are available, SQLite
  2985. ** will pick the one that involves the least amount of data conversion.
  2986. ** If there is only a single implementation which does not care what text
  2987. ** encoding is used, then the fourth argument should be [SQLITE_ANY].
  2988. **
  2989. ** The fifth parameter is an arbitrary pointer. The implementation of the
  2990. ** function can gain access to this pointer using [sqlite3_user_data()].
  2991. **
  2992. ** The seventh, eighth and ninth parameters, xFunc, xStep and xFinal, are
  2993. ** pointers to C-language functions that implement the SQL function or
  2994. ** aggregate. A scalar SQL function requires an implementation of the xFunc
  2995. ** callback only, NULL pointers should be passed as the xStep and xFinal
  2996. ** parameters. An aggregate SQL function requires an implementation of xStep
  2997. ** and xFinal and NULL should be passed for xFunc. To delete an existing
  2998. ** SQL function or aggregate, pass NULL for all three function callbacks.
  2999. **
  3000. ** It is permitted to register multiple implementations of the same
  3001. ** functions with the same name but with either differing numbers of
  3002. ** arguments or differing preferred text encodings. SQLite will use
  3003. ** the implementation most closely matches the way in which the
  3004. ** SQL function is used. A function implementation with a non-negative
  3005. ** nArg parameter is a better match than a function implementation with
  3006. ** a negative nArg. A function where the preferred text encoding
  3007. ** matches the database encoding is a better
  3008. ** match than a function where the encoding is different.
  3009. ** A function where the encoding difference is between UTF16le and UTF16be
  3010. ** is a closer match than a function where the encoding difference is
  3011. ** between UTF8 and UTF16.
  3012. **
  3013. ** Built-in functions may be overloaded by new application-defined functions.
  3014. ** The first application-defined function with a given name overrides all
  3015. ** built-in functions in the same [database connection] with the same name.
  3016. ** Subsequent application-defined functions of the same name only override
  3017. ** prior application-defined functions that are an exact match for the
  3018. ** number of parameters and preferred encoding.
  3019. **
  3020. ** An application-defined function is permitted to call other
  3021. ** SQLite interfaces. However, such calls must not
  3022. ** close the database connection nor finalize or reset the prepared
  3023. ** statement in which the function is running.
  3024. **
  3025. ** Requirements:
  3026. ** [H16103] [H16106] [H16109] [H16112] [H16118] [H16121] [H16124] [H16127]
  3027. ** [H16130] [H16133] [H16136] [H16139] [H16142]
  3028. */
  3029. int sqlite3_create_function(
  3030. sqlite3 *db,
  3031. const char *zFunctionName,
  3032. int nArg,
  3033. int eTextRep,
  3034. void *pApp,
  3035. void (*xFunc)(sqlite3_context*,int,sqlite3_value**),
  3036. void (*xStep)(sqlite3_context*,int,sqlite3_value**),
  3037. void (*xFinal)(sqlite3_context*)
  3038. );
  3039. int sqlite3_create_function16(
  3040. sqlite3 *db,
  3041. const void *zFunctionName,
  3042. int nArg,
  3043. int eTextRep,
  3044. void *pApp,
  3045. void (*xFunc)(sqlite3_context*,int,sqlite3_value**),
  3046. void (*xStep)(sqlite3_context*,int,sqlite3_value**),
  3047. void (*xFinal)(sqlite3_context*)
  3048. );
  3049. /*
  3050. ** CAPI3REF: Text Encodings {H10267} <S50200> <H16100>
  3051. **
  3052. ** These constant define integer codes that represent the various
  3053. ** text encodings supported by SQLite.
  3054. */
  3055. #define SQLITE_UTF8 1
  3056. #define SQLITE_UTF16LE 2
  3057. #define SQLITE_UTF16BE 3
  3058. #define SQLITE_UTF16 4 /* Use native byte order */
  3059. #define SQLITE_ANY 5 /* sqlite3_create_function only */
  3060. #define SQLITE_UTF16_ALIGNED 8 /* sqlite3_create_collation only */
  3061. /*
  3062. ** CAPI3REF: Deprecated Functions
  3063. ** DEPRECATED
  3064. **
  3065. ** These functions are [deprecated]. In order to maintain
  3066. ** backwards compatibility with older code, these functions continue
  3067. ** to be supported. However, new applications should avoid
  3068. ** the use of these functions. To help encourage people to avoid
  3069. ** using these functions, we are not going to tell you what they do.
  3070. */
  3071. #ifndef SQLITE_OMIT_DEPRECATED
  3072. SQLITE_DEPRECATED int sqlite3_aggregate_count(sqlite3_context*);
  3073. SQLITE_DEPRECATED int sqlite3_expired(sqlite3_stmt*);
  3074. SQLITE_DEPRECATED int sqlite3_transfer_bindings(sqlite3_stmt*, sqlite3_stmt*);
  3075. SQLITE_DEPRECATED int sqlite3_global_recover(void);
  3076. SQLITE_DEPRECATED void sqlite3_thread_cleanup(void);
  3077. SQLITE_DEPRECATED int sqlite3_memory_alarm(void(*)(void*,sqlite3_int64,int),void*,sqlite3_int64);
  3078. #endif
  3079. /*
  3080. ** CAPI3REF: Obtaining SQL Function Parameter Values {H15100} <S20200>
  3081. **
  3082. ** The C-language implementation of SQL functions and aggregates uses
  3083. ** this set of interface routines to access the parameter values on
  3084. ** the function or aggregate.
  3085. **
  3086. ** The xFunc (for scalar functions) or xStep (for aggregates) parameters
  3087. ** to [sqlite3_create_function()] and [sqlite3_create_function16()]
  3088. ** define callbacks that implement the SQL functions and aggregates.
  3089. ** The 4th parameter to these callbacks is an array of pointers to
  3090. ** [protected sqlite3_value] objects. There is one [sqlite3_value] object for
  3091. ** each parameter to the SQL function. These routines are used to
  3092. ** extract values from the [sqlite3_value] objects.
  3093. **
  3094. ** These routines work only with [protected sqlite3_value] objects.
  3095. ** Any attempt to use these routines on an [unprotected sqlite3_value]
  3096. ** object results in undefined behavior.
  3097. **
  3098. ** These routines work just like the corresponding [column access functions]
  3099. ** except that these routines take a single [protected sqlite3_value] object
  3100. ** pointer instead of a [sqlite3_stmt*] pointer and an integer column number.
  3101. **
  3102. ** The sqlite3_value_text16() interface extracts a UTF-16 string
  3103. ** in the native byte-order of the host machine. The
  3104. ** sqlite3_value_text16be() and sqlite3_value_text16le() interfaces
  3105. ** extract UTF-16 strings as big-endian and little-endian respectively.
  3106. **
  3107. ** The sqlite3_value_numeric_type() interface attempts to apply
  3108. ** numeric affinity to the value. This means that an attempt is
  3109. ** made to convert the value to an integer or floating point. If
  3110. ** such a conversion is possible without loss of information (in other
  3111. ** words, if the value is a string that looks like a number)
  3112. ** then the conversion is performed. Otherwise no conversion occurs.
  3113. ** The [SQLITE_INTEGER | datatype] after conversion is returned.
  3114. **
  3115. ** Please pay particular attention to the fact that the pointer returned
  3116. ** from [sqlite3_value_blob()], [sqlite3_value_text()], or
  3117. ** [sqlite3_value_text16()] can be invalidated by a subsequent call to
  3118. ** [sqlite3_value_bytes()], [sqlite3_value_bytes16()], [sqlite3_value_text()],
  3119. ** or [sqlite3_value_text16()].
  3120. **
  3121. ** These routines must be called from the same thread as
  3122. ** the SQL function that supplied the [sqlite3_value*] parameters.
  3123. **
  3124. ** Requirements:
  3125. ** [H15103] [H15106] [H15109] [H15112] [H15115] [H15118] [H15121] [H15124]
  3126. ** [H15127] [H15130] [H15133] [H15136]
  3127. */
  3128. const void *sqlite3_value_blob(sqlite3_value*);
  3129. int sqlite3_value_bytes(sqlite3_value*);
  3130. int sqlite3_value_bytes16(sqlite3_value*);
  3131. double sqlite3_value_double(sqlite3_value*);
  3132. int sqlite3_value_int(sqlite3_value*);
  3133. sqlite3_int64 sqlite3_value_int64(sqlite3_value*);
  3134. const unsigned char *sqlite3_value_text(sqlite3_value*);
  3135. const void *sqlite3_value_text16(sqlite3_value*);
  3136. const void *sqlite3_value_text16le(sqlite3_value*);
  3137. const void *sqlite3_value_text16be(sqlite3_value*);
  3138. int sqlite3_value_type(sqlite3_value*);
  3139. int sqlite3_value_numeric_type(sqlite3_value*);
  3140. /*
  3141. ** CAPI3REF: Obtain Aggregate Function Context {H16210} <S20200>
  3142. **
  3143. ** The implementation of aggregate SQL functions use this routine to allocate
  3144. ** a structure for storing their state.
  3145. **
  3146. ** The first time the sqlite3_aggregate_context() routine is called for a
  3147. ** particular aggregate, SQLite allocates nBytes of memory, zeroes out that
  3148. ** memory, and returns a pointer to it. On second and subsequent calls to
  3149. ** sqlite3_aggregate_context() for the same aggregate function index,
  3150. ** the same buffer is returned. The implementation of the aggregate can use
  3151. ** the returned buffer to accumulate data.
  3152. **
  3153. ** SQLite automatically frees the allocated buffer when the aggregate
  3154. ** query concludes.
  3155. **
  3156. ** The first parameter should be a copy of the
  3157. ** [sqlite3_context | SQL function context] that is the first parameter
  3158. ** to the callback routine that implements the aggregate function.
  3159. **
  3160. ** This routine must be called from the same thread in which
  3161. ** the aggregate SQL function is running.
  3162. **
  3163. ** Requirements:
  3164. ** [H16211] [H16213] [H16215] [H16217]
  3165. */
  3166. void *sqlite3_aggregate_context(sqlite3_context*, int nBytes);
  3167. /*
  3168. ** CAPI3REF: User Data For Functions {H16240} <S20200>
  3169. **
  3170. ** The sqlite3_user_data() interface returns a copy of
  3171. ** the pointer that was the pUserData parameter (the 5th parameter)
  3172. ** of the [sqlite3_create_function()]
  3173. ** and [sqlite3_create_function16()] routines that originally
  3174. ** registered the application defined function. {END}
  3175. **
  3176. ** This routine must be called from the same thread in which
  3177. ** the application-defined function is running.
  3178. **
  3179. ** Requirements:
  3180. ** [H16243]
  3181. */
  3182. void *sqlite3_user_data(sqlite3_context*);
  3183. /*
  3184. ** CAPI3REF: Database Connection For Functions {H16250} <S60600><S20200>
  3185. **
  3186. ** The sqlite3_context_db_handle() interface returns a copy of
  3187. ** the pointer to the [database connection] (the 1st parameter)
  3188. ** of the [sqlite3_create_function()]
  3189. ** and [sqlite3_create_function16()] routines that originally
  3190. ** registered the application defined function.
  3191. **
  3192. ** Requirements:
  3193. ** [H16253]
  3194. */
  3195. sqlite3 *sqlite3_context_db_handle(sqlite3_context*);
  3196. /*
  3197. ** CAPI3REF: Function Auxiliary Data {H16270} <S20200>
  3198. **
  3199. ** The following two functions may be used by scalar SQL functions to
  3200. ** associate metadata with argument values. If the same value is passed to
  3201. ** multiple invocations of the same SQL function during query execution, under
  3202. ** some circumstances the associated metadata may be preserved. This may
  3203. ** be used, for example, to add a regular-expression matching scalar
  3204. ** function. The compiled version of the regular expression is stored as
  3205. ** metadata associated with the SQL value passed as the regular expression
  3206. ** pattern. The compiled regular expression can be reused on multiple
  3207. ** invocations of the same function so that the original pattern string
  3208. ** does not need to be recompiled on each invocation.
  3209. **
  3210. ** The sqlite3_get_auxdata() interface returns a pointer to the metadata
  3211. ** associated by the sqlite3_set_auxdata() function with the Nth argument
  3212. ** value to the application-defined function. If no metadata has been ever
  3213. ** been set for the Nth argument of the function, or if the corresponding
  3214. ** function parameter has changed since the meta-data was set,
  3215. ** then sqlite3_get_auxdata() returns a NULL pointer.
  3216. **
  3217. ** The sqlite3_set_auxdata() interface saves the metadata
  3218. ** pointed to by its 3rd parameter as the metadata for the N-th
  3219. ** argument of the application-defined function. Subsequent
  3220. ** calls to sqlite3_get_auxdata() might return this data, if it has
  3221. ** not been destroyed.
  3222. ** If it is not NULL, SQLite will invoke the destructor
  3223. ** function given by the 4th parameter to sqlite3_set_auxdata() on
  3224. ** the metadata when the corresponding function parameter changes
  3225. ** or when the SQL statement completes, whichever comes first.
  3226. **
  3227. ** SQLite is free to call the destructor and drop metadata on any
  3228. ** parameter of any function at any time. The only guarantee is that
  3229. ** the destructor will be called before the metadata is dropped.
  3230. **
  3231. ** In practice, metadata is preserved between function calls for
  3232. ** expressions that are constant at compile time. This includes literal
  3233. ** values and SQL variables.
  3234. **
  3235. ** These routines must be called from the same thread in which
  3236. ** the SQL function is running.
  3237. **
  3238. ** Requirements:
  3239. ** [H16272] [H16274] [H16276] [H16277] [H16278] [H16279]
  3240. */
  3241. void *sqlite3_get_auxdata(sqlite3_context*, int N);
  3242. void sqlite3_set_auxdata(sqlite3_context*, int N, void*, void (*)(void*));
  3243. /*
  3244. ** CAPI3REF: Constants Defining Special Destructor Behavior {H10280} <S30100>
  3245. **
  3246. ** These are special values for the destructor that is passed in as the
  3247. ** final argument to routines like [sqlite3_result_blob()]. If the destructor
  3248. ** argument is SQLITE_STATIC, it means that the content pointer is constant
  3249. ** and will never change. It does not need to be destroyed. The
  3250. ** SQLITE_TRANSIENT value means that the content will likely change in
  3251. ** the near future and that SQLite should make its own private copy of
  3252. ** the content before returning.
  3253. **
  3254. ** The typedef is necessary to work around problems in certain
  3255. ** C++ compilers. See ticket #2191.
  3256. */
  3257. typedef void (*sqlite3_destructor_type)(void*);
  3258. #define SQLITE_STATIC ((sqlite3_destructor_type)0)
  3259. #define SQLITE_TRANSIENT ((sqlite3_destructor_type)-1)
  3260. /*
  3261. ** CAPI3REF: Setting The Result Of An SQL Function {H16400} <S20200>
  3262. **
  3263. ** These routines are used by the xFunc or xFinal callbacks that
  3264. ** implement SQL functions and aggregates. See
  3265. ** [sqlite3_create_function()] and [sqlite3_create_function16()]
  3266. ** for additional information.
  3267. **
  3268. ** These functions work very much like the [parameter binding] family of
  3269. ** functions used to bind values to host parameters in prepared statements.
  3270. ** Refer to the [SQL parameter] documentation for additional information.
  3271. **
  3272. ** The sqlite3_result_blob() interface sets the result from
  3273. ** an application-defined function to be the BLOB whose content is pointed
  3274. ** to by the second parameter and which is N bytes long where N is the
  3275. ** third parameter.
  3276. **
  3277. ** The sqlite3_result_zeroblob() interfaces set the result of
  3278. ** the application-defined function to be a BLOB containing all zero
  3279. ** bytes and N bytes in size, where N is the value of the 2nd parameter.
  3280. **
  3281. ** The sqlite3_result_double() interface sets the result from
  3282. ** an application-defined function to be a floating point value specified
  3283. ** by its 2nd argument.
  3284. **
  3285. ** The sqlite3_result_error() and sqlite3_result_error16() functions
  3286. ** cause the implemented SQL function to throw an exception.
  3287. ** SQLite uses the string pointed to by the
  3288. ** 2nd parameter of sqlite3_result_error() or sqlite3_result_error16()
  3289. ** as the text of an error message. SQLite interprets the error
  3290. ** message string from sqlite3_result_error() as UTF-8. SQLite
  3291. ** interprets the string from sqlite3_result_error16() as UTF-16 in native
  3292. ** byte order. If the third parameter to sqlite3_result_error()
  3293. ** or sqlite3_result_error16() is negative then SQLite takes as the error
  3294. ** message all text up through the first zero character.
  3295. ** If the third parameter to sqlite3_result_error() or
  3296. ** sqlite3_result_error16() is non-negative then SQLite takes that many
  3297. ** bytes (not characters) from the 2nd parameter as the error message.
  3298. ** The sqlite3_result_error() and sqlite3_result_error16()
  3299. ** routines make a private copy of the error message text before
  3300. ** they return. Hence, the calling function can deallocate or
  3301. ** modify the text after they return without harm.
  3302. ** The sqlite3_result_error_code() function changes the error code
  3303. ** returned by SQLite as a result of an error in a function. By default,
  3304. ** the error code is SQLITE_ERROR. A subsequent call to sqlite3_result_error()
  3305. ** or sqlite3_result_error16() resets the error code to SQLITE_ERROR.
  3306. **
  3307. ** The sqlite3_result_toobig() interface causes SQLite to throw an error
  3308. ** indicating that a string or BLOB is to long to represent.
  3309. **
  3310. ** The sqlite3_result_nomem() interface causes SQLite to throw an error
  3311. ** indicating that a memory allocation failed.
  3312. **
  3313. ** The sqlite3_result_int() interface sets the return value
  3314. ** of the application-defined function to be the 32-bit signed integer
  3315. ** value given in the 2nd argument.
  3316. ** The sqlite3_result_int64() interface sets the return value
  3317. ** of the application-defined function to be the 64-bit signed integer
  3318. ** value given in the 2nd argument.
  3319. **
  3320. ** The sqlite3_result_null() interface sets the return value
  3321. ** of the application-defined function to be NULL.
  3322. **
  3323. ** The sqlite3_result_text(), sqlite3_result_text16(),
  3324. ** sqlite3_result_text16le(), and sqlite3_result_text16be() interfaces
  3325. ** set the return value of the application-defined function to be
  3326. ** a text string which is represented as UTF-8, UTF-16 native byte order,
  3327. ** UTF-16 little endian, or UTF-16 big endian, respectively.
  3328. ** SQLite takes the text result from the application from
  3329. ** the 2nd parameter of the sqlite3_result_text* interfaces.
  3330. ** If the 3rd parameter to the sqlite3_result_text* interfaces
  3331. ** is negative, then SQLite takes result text from the 2nd parameter
  3332. ** through the first zero character.
  3333. ** If the 3rd parameter to the sqlite3_result_text* interfaces
  3334. ** is non-negative, then as many bytes (not characters) of the text
  3335. ** pointed to by the 2nd parameter are taken as the application-defined
  3336. ** function result.
  3337. ** If the 4th parameter to the sqlite3_result_text* interfaces
  3338. ** or sqlite3_result_blob is a non-NULL pointer, then SQLite calls that
  3339. ** function as the destructor on the text or BLOB result when it has
  3340. ** finished using that result.
  3341. ** If the 4th parameter to the sqlite3_result_text* interfaces or
  3342. ** sqlite3_result_blob is the special constant SQLITE_STATIC, then SQLite
  3343. ** assumes that the text or BLOB result is in constant space and does not
  3344. ** copy the it or call a destructor when it has finished using that result.
  3345. ** If the 4th parameter to the sqlite3_result_text* interfaces
  3346. ** or sqlite3_result_blob is the special constant SQLITE_TRANSIENT
  3347. ** then SQLite makes a copy of the result into space obtained from
  3348. ** from [sqlite3_malloc()] before it returns.
  3349. **
  3350. ** The sqlite3_result_value() interface sets the result of
  3351. ** the application-defined function to be a copy the
  3352. ** [unprotected sqlite3_value] object specified by the 2nd parameter. The
  3353. ** sqlite3_result_value() interface makes a copy of the [sqlite3_value]
  3354. ** so that the [sqlite3_value] specified in the parameter may change or
  3355. ** be deallocated after sqlite3_result_value() returns without harm.
  3356. ** A [protected sqlite3_value] object may always be used where an
  3357. ** [unprotected sqlite3_value] object is required, so either
  3358. ** kind of [sqlite3_value] object can be used with this interface.
  3359. **
  3360. ** If these routines are called from within the different thread
  3361. ** than the one containing the application-defined function that received
  3362. ** the [sqlite3_context] pointer, the results are undefined.
  3363. **
  3364. ** Requirements:
  3365. ** [H16403] [H16406] [H16409] [H16412] [H16415] [H16418] [H16421] [H16424]
  3366. ** [H16427] [H16430] [H16433] [H16436] [H16439] [H16442] [H16445] [H16448]
  3367. ** [H16451] [H16454] [H16457] [H16460] [H16463]
  3368. */
  3369. void sqlite3_result_blob(sqlite3_context*, const void*, int, void(*)(void*));
  3370. void sqlite3_result_double(sqlite3_context*, double);
  3371. void sqlite3_result_error(sqlite3_context*, const char*, int);
  3372. void sqlite3_result_error16(sqlite3_context*, const void*, int);
  3373. void sqlite3_result_error_toobig(sqlite3_context*);
  3374. void sqlite3_result_error_nomem(sqlite3_context*);
  3375. void sqlite3_result_error_code(sqlite3_context*, int);
  3376. void sqlite3_result_int(sqlite3_context*, int);
  3377. void sqlite3_result_int64(sqlite3_context*, sqlite3_int64);
  3378. void sqlite3_result_null(sqlite3_context*);
  3379. void sqlite3_result_text(sqlite3_context*, const char*, int, void(*)(void*));
  3380. void sqlite3_result_text16(sqlite3_context*, const void*, int, void(*)(void*));
  3381. void sqlite3_result_text16le(sqlite3_context*, const void*, int,void(*)(void*));
  3382. void sqlite3_result_text16be(sqlite3_context*, const void*, int,void(*)(void*));
  3383. void sqlite3_result_value(sqlite3_context*, sqlite3_value*);
  3384. void sqlite3_result_zeroblob(sqlite3_context*, int n);
  3385. /*
  3386. ** CAPI3REF: Define New Collating Sequences {H16600} <S20300>
  3387. **
  3388. ** These functions are used to add new collation sequences to the
  3389. ** [database connection] specified as the first argument.
  3390. **
  3391. ** The name of the new collation sequence is specified as a UTF-8 string
  3392. ** for sqlite3_create_collation() and sqlite3_create_collation_v2()
  3393. ** and a UTF-16 string for sqlite3_create_collation16(). In all cases
  3394. ** the name is passed as the second function argument.
  3395. **
  3396. ** The third argument may be one of the constants [SQLITE_UTF8],
  3397. ** [SQLITE_UTF16LE] or [SQLITE_UTF16BE], indicating that the user-supplied
  3398. ** routine expects to be passed pointers to strings encoded using UTF-8,
  3399. ** UTF-16 little-endian, or UTF-16 big-endian, respectively. The
  3400. ** third argument might also be [SQLITE_UTF16_ALIGNED] to indicate that
  3401. ** the routine expects pointers to 16-bit word aligned strings
  3402. ** of UTF-16 in the native byte order of the host computer.
  3403. **
  3404. ** A pointer to the user supplied routine must be passed as the fifth
  3405. ** argument. If it is NULL, this is the same as deleting the collation
  3406. ** sequence (so that SQLite cannot call it anymore).
  3407. ** Each time the application supplied function is invoked, it is passed
  3408. ** as its first parameter a copy of the void* passed as the fourth argument
  3409. ** to sqlite3_create_collation() or sqlite3_create_collation16().
  3410. **
  3411. ** The remaining arguments to the application-supplied routine are two strings,
  3412. ** each represented by a (length, data) pair and encoded in the encoding
  3413. ** that was passed as the third argument when the collation sequence was
  3414. ** registered. {END} The application defined collation routine should
  3415. ** return negative, zero or positive if the first string is less than,
  3416. ** equal to, or greater than the second string. i.e. (STRING1 - STRING2).
  3417. **
  3418. ** The sqlite3_create_collation_v2() works like sqlite3_create_collation()
  3419. ** except that it takes an extra argument which is a destructor for
  3420. ** the collation. The destructor is called when the collation is
  3421. ** destroyed and is passed a copy of the fourth parameter void* pointer
  3422. ** of the sqlite3_create_collation_v2().
  3423. ** Collations are destroyed when they are overridden by later calls to the
  3424. ** collation creation functions or when the [database connection] is closed
  3425. ** using [sqlite3_close()].
  3426. **
  3427. ** Requirements:
  3428. ** [H16603] [H16604] [H16606] [H16609] [H16612] [H16615] [H16618] [H16621]
  3429. ** [H16624] [H16627] [H16630]
  3430. */
  3431. int sqlite3_create_collation(
  3432. sqlite3*,
  3433. const char *zName,
  3434. int eTextRep,
  3435. void*,
  3436. int(*xCompare)(void*,int,const void*,int,const void*)
  3437. );
  3438. int sqlite3_create_collation_v2(
  3439. sqlite3*,
  3440. const char *zName,
  3441. int eTextRep,
  3442. void*,
  3443. int(*xCompare)(void*,int,const void*,int,const void*),
  3444. void(*xDestroy)(void*)
  3445. );
  3446. int sqlite3_create_collation16(
  3447. sqlite3*,
  3448. const void *zName,
  3449. int eTextRep,
  3450. void*,
  3451. int(*xCompare)(void*,int,const void*,int,const void*)
  3452. );
  3453. /*
  3454. ** CAPI3REF: Collation Needed Callbacks {H16700} <S20300>
  3455. **
  3456. ** To avoid having to register all collation sequences before a database
  3457. ** can be used, a single callback function may be registered with the
  3458. ** [database connection] to be called whenever an undefined collation
  3459. ** sequence is required.
  3460. **
  3461. ** If the function is registered using the sqlite3_collation_needed() API,
  3462. ** then it is passed the names of undefined collation sequences as strings
  3463. ** encoded in UTF-8. {H16703} If sqlite3_collation_needed16() is used,
  3464. ** the names are passed as UTF-16 in machine native byte order.
  3465. ** A call to either function replaces any existing callback.
  3466. **
  3467. ** When the callback is invoked, the first argument passed is a copy
  3468. ** of the second argument to sqlite3_collation_needed() or
  3469. ** sqlite3_collation_needed16(). The second argument is the database
  3470. ** connection. The third argument is one of [SQLITE_UTF8], [SQLITE_UTF16BE],
  3471. ** or [SQLITE_UTF16LE], indicating the most desirable form of the collation
  3472. ** sequence function required. The fourth parameter is the name of the
  3473. ** required collation sequence.
  3474. **
  3475. ** The callback function should register the desired collation using
  3476. ** [sqlite3_create_collation()], [sqlite3_create_collation16()], or
  3477. ** [sqlite3_create_collation_v2()].
  3478. **
  3479. ** Requirements:
  3480. ** [H16702] [H16704] [H16706]
  3481. */
  3482. int sqlite3_collation_needed(
  3483. sqlite3*,
  3484. void*,
  3485. void(*)(void*,sqlite3*,int eTextRep,const char*)
  3486. );
  3487. int sqlite3_collation_needed16(
  3488. sqlite3*,
  3489. void*,
  3490. void(*)(void*,sqlite3*,int eTextRep,const void*)
  3491. );
  3492. /*
  3493. ** Specify the key for an encrypted database. This routine should be
  3494. ** called right after sqlite3_open().
  3495. **
  3496. ** The code to implement this API is not available in the public release
  3497. ** of SQLite.
  3498. */
  3499. int sqlite3_key(
  3500. sqlite3 *db, /* Database to be rekeyed */
  3501. const void *pKey, int nKey /* The key */
  3502. );
  3503. /*
  3504. ** Change the key on an open database. If the current database is not
  3505. ** encrypted, this routine will encrypt it. If pNew==0 or nNew==0, the
  3506. ** database is decrypted.
  3507. **
  3508. ** The code to implement this API is not available in the public release
  3509. ** of SQLite.
  3510. */
  3511. int sqlite3_rekey(
  3512. sqlite3 *db, /* Database to be rekeyed */
  3513. const void *pKey, int nKey /* The new key */
  3514. );
  3515. /*
  3516. ** CAPI3REF: Suspend Execution For A Short Time {H10530} <S40410>
  3517. **
  3518. ** The sqlite3_sleep() function causes the current thread to suspend execution
  3519. ** for at least a number of milliseconds specified in its parameter.
  3520. **
  3521. ** If the operating system does not support sleep requests with
  3522. ** millisecond time resolution, then the time will be rounded up to
  3523. ** the nearest second. The number of milliseconds of sleep actually
  3524. ** requested from the operating system is returned.
  3525. **
  3526. ** SQLite implements this interface by calling the xSleep()
  3527. ** method of the default [sqlite3_vfs] object.
  3528. **
  3529. ** Requirements: [H10533] [H10536]
  3530. */
  3531. int sqlite3_sleep(int);
  3532. /*
  3533. ** CAPI3REF: Name Of The Folder Holding Temporary Files {H10310} <S20000>
  3534. **
  3535. ** If this global variable is made to point to a string which is
  3536. ** the name of a folder (a.k.a. directory), then all temporary files
  3537. ** created by SQLite will be placed in that directory. If this variable
  3538. ** is a NULL pointer, then SQLite performs a search for an appropriate
  3539. ** temporary file directory.
  3540. **
  3541. ** It is not safe to modify this variable once a [database connection]
  3542. ** has been opened. It is intended that this variable be set once
  3543. ** as part of process initialization and before any SQLite interface
  3544. ** routines have been call and remain unchanged thereafter.
  3545. */
  3546. SQLITE_EXTERN char *sqlite3_temp_directory;
  3547. /*
  3548. ** CAPI3REF: Test For Auto-Commit Mode {H12930} <S60200>
  3549. ** KEYWORDS: {autocommit mode}
  3550. **
  3551. ** The sqlite3_get_autocommit() interface returns non-zero or
  3552. ** zero if the given database connection is or is not in autocommit mode,
  3553. ** respectively. Autocommit mode is on by default.
  3554. ** Autocommit mode is disabled by a [BEGIN] statement.
  3555. ** Autocommit mode is re-enabled by a [COMMIT] or [ROLLBACK].
  3556. **
  3557. ** If certain kinds of errors occur on a statement within a multi-statement
  3558. ** transaction (errors including [SQLITE_FULL], [SQLITE_IOERR],
  3559. ** [SQLITE_NOMEM], [SQLITE_BUSY], and [SQLITE_INTERRUPT]) then the
  3560. ** transaction might be rolled back automatically. The only way to
  3561. ** find out whether SQLite automatically rolled back the transaction after
  3562. ** an error is to use this function.
  3563. **
  3564. ** If another thread changes the autocommit status of the database
  3565. ** connection while this routine is running, then the return value
  3566. ** is undefined.
  3567. **
  3568. ** Requirements: [H12931] [H12932] [H12933] [H12934]
  3569. */
  3570. int sqlite3_get_autocommit(sqlite3*);
  3571. /*
  3572. ** CAPI3REF: Find The Database Handle Of A Prepared Statement {H13120} <S60600>
  3573. **
  3574. ** The sqlite3_db_handle interface returns the [database connection] handle
  3575. ** to which a [prepared statement] belongs. The [database connection]
  3576. ** returned by sqlite3_db_handle is the same [database connection] that was the first argument
  3577. ** to the [sqlite3_prepare_v2()] call (or its variants) that was used to
  3578. ** create the statement in the first place.
  3579. **
  3580. ** Requirements: [H13123]
  3581. */
  3582. sqlite3 *sqlite3_db_handle(sqlite3_stmt*);
  3583. /*
  3584. ** CAPI3REF: Find the next prepared statement {H13140} <S60600>
  3585. **
  3586. ** This interface returns a pointer to the next [prepared statement] after
  3587. ** pStmt associated with the [database connection] pDb. If pStmt is NULL
  3588. ** then this interface returns a pointer to the first prepared statement
  3589. ** associated with the database connection pDb. If no prepared statement
  3590. ** satisfies the conditions of this routine, it returns NULL.
  3591. **
  3592. ** The [database connection] pointer D in a call to
  3593. ** [sqlite3_next_stmt(D,S)] must refer to an open database
  3594. ** connection and in particular must not be a NULL pointer.
  3595. **
  3596. ** Requirements: [H13143] [H13146] [H13149] [H13152]
  3597. */
  3598. sqlite3_stmt *sqlite3_next_stmt(sqlite3 *pDb, sqlite3_stmt *pStmt);
  3599. /*
  3600. ** CAPI3REF: Commit And Rollback Notification Callbacks {H12950} <S60400>
  3601. **
  3602. ** The sqlite3_commit_hook() interface registers a callback
  3603. ** function to be invoked whenever a transaction is committed.
  3604. ** Any callback set by a previous call to sqlite3_commit_hook()
  3605. ** for the same database connection is overridden.
  3606. ** The sqlite3_rollback_hook() interface registers a callback
  3607. ** function to be invoked whenever a transaction is committed.
  3608. ** Any callback set by a previous call to sqlite3_commit_hook()
  3609. ** for the same database connection is overridden.
  3610. ** The pArg argument is passed through to the callback.
  3611. ** If the callback on a commit hook function returns non-zero,
  3612. ** then the commit is converted into a rollback.
  3613. **
  3614. ** If another function was previously registered, its
  3615. ** pArg value is returned. Otherwise NULL is returned.
  3616. **
  3617. ** The callback implementation must not do anything that will modify
  3618. ** the database connection that invoked the callback. Any actions
  3619. ** to modify the database connection must be deferred until after the
  3620. ** completion of the [sqlite3_step()] call that triggered the commit
  3621. ** or rollback hook in the first place.
  3622. ** Note that [sqlite3_prepare_v2()] and [sqlite3_step()] both modify their
  3623. ** database connections for the meaning of "modify" in this paragraph.
  3624. **
  3625. ** Registering a NULL function disables the callback.
  3626. **
  3627. ** For the purposes of this API, a transaction is said to have been
  3628. ** rolled back if an explicit "ROLLBACK" statement is executed, or
  3629. ** an error or constraint causes an implicit rollback to occur.
  3630. ** The rollback callback is not invoked if a transaction is
  3631. ** automatically rolled back because the database connection is closed.
  3632. ** The rollback callback is not invoked if a transaction is
  3633. ** rolled back because a commit callback returned non-zero.
  3634. ** <todo> Check on this </todo>
  3635. **
  3636. ** Requirements:
  3637. ** [H12951] [H12952] [H12953] [H12954] [H12955]
  3638. ** [H12961] [H12962] [H12963] [H12964]
  3639. */
  3640. void *sqlite3_commit_hook(sqlite3*, int(*)(void*), void*);
  3641. void *sqlite3_rollback_hook(sqlite3*, void(*)(void *), void*);
  3642. /*
  3643. ** CAPI3REF: Data Change Notification Callbacks {H12970} <S60400>
  3644. **
  3645. ** The sqlite3_update_hook() interface registers a callback function
  3646. ** with the [database connection] identified by the first argument
  3647. ** to be invoked whenever a row is updated, inserted or deleted.
  3648. ** Any callback set by a previous call to this function
  3649. ** for the same database connection is overridden.
  3650. **
  3651. ** The second argument is a pointer to the function to invoke when a
  3652. ** row is updated, inserted or deleted.
  3653. ** The first argument to the callback is a copy of the third argument
  3654. ** to sqlite3_update_hook().
  3655. ** The second callback argument is one of [SQLITE_INSERT], [SQLITE_DELETE],
  3656. ** or [SQLITE_UPDATE], depending on the operation that caused the callback
  3657. ** to be invoked.
  3658. ** The third and fourth arguments to the callback contain pointers to the
  3659. ** database and table name containing the affected row.
  3660. ** The final callback parameter is the [rowid] of the row.
  3661. ** In the case of an update, this is the [rowid] after the update takes place.
  3662. **
  3663. ** The update hook is not invoked when internal system tables are
  3664. ** modified (i.e. sqlite_master and sqlite_sequence).
  3665. **
  3666. ** The update hook implementation must not do anything that will modify
  3667. ** the database connection that invoked the update hook. Any actions
  3668. ** to modify the database connection must be deferred until after the
  3669. ** completion of the [sqlite3_step()] call that triggered the update hook.
  3670. ** Note that [sqlite3_prepare_v2()] and [sqlite3_step()] both modify their
  3671. ** database connections for the meaning of "modify" in this paragraph.
  3672. **
  3673. ** If another function was previously registered, its pArg value
  3674. ** is returned. Otherwise NULL is returned.
  3675. **
  3676. ** Requirements:
  3677. ** [H12971] [H12973] [H12975] [H12977] [H12979] [H12981] [H12983] [H12986]
  3678. */
  3679. void *sqlite3_update_hook(
  3680. sqlite3*,
  3681. void(*)(void *,int ,char const *,char const *,sqlite3_int64),
  3682. void*
  3683. );
  3684. /*
  3685. ** CAPI3REF: Enable Or Disable Shared Pager Cache {H10330} <S30900>
  3686. ** KEYWORDS: {shared cache} {shared cache mode}
  3687. **
  3688. ** This routine enables or disables the sharing of the database cache
  3689. ** and schema data structures between [database connection | connections]
  3690. ** to the same database. Sharing is enabled if the argument is true
  3691. ** and disabled if the argument is false.
  3692. **
  3693. ** Cache sharing is enabled and disabled for an entire process.
  3694. ** This is a change as of SQLite version 3.5.0. In prior versions of SQLite,
  3695. ** sharing was enabled or disabled for each thread separately.
  3696. **
  3697. ** The cache sharing mode set by this interface effects all subsequent
  3698. ** calls to [sqlite3_open()], [sqlite3_open_v2()], and [sqlite3_open16()].
  3699. ** Existing database connections continue use the sharing mode
  3700. ** that was in effect at the time they were opened.
  3701. **
  3702. ** Virtual tables cannot be used with a shared cache. When shared
  3703. ** cache is enabled, the [sqlite3_create_module()] API used to register
  3704. ** virtual tables will always return an error.
  3705. **
  3706. ** This routine returns [SQLITE_OK] if shared cache was enabled or disabled
  3707. ** successfully. An [error code] is returned otherwise.
  3708. **
  3709. ** Shared cache is disabled by default. But this might change in
  3710. ** future releases of SQLite. Applications that care about shared
  3711. ** cache setting should set it explicitly.
  3712. **
  3713. ** See Also: [SQLite Shared-Cache Mode]
  3714. **
  3715. ** Requirements: [H10331] [H10336] [H10337] [H10339]
  3716. */
  3717. int sqlite3_enable_shared_cache(int);
  3718. /*
  3719. ** CAPI3REF: Attempt To Free Heap Memory {H17340} <S30220>
  3720. **
  3721. ** The sqlite3_release_memory() interface attempts to free N bytes
  3722. ** of heap memory by deallocating non-essential memory allocations
  3723. ** held by the database library. {END} Memory used to cache database
  3724. ** pages to improve performance is an example of non-essential memory.
  3725. ** sqlite3_release_memory() returns the number of bytes actually freed,
  3726. ** which might be more or less than the amount requested.
  3727. **
  3728. ** Requirements: [H17341] [H17342]
  3729. */
  3730. int sqlite3_release_memory(int);
  3731. /*
  3732. ** CAPI3REF: Impose A Limit On Heap Size {H17350} <S30220>
  3733. **
  3734. ** The sqlite3_soft_heap_limit() interface places a "soft" limit
  3735. ** on the amount of heap memory that may be allocated by SQLite.
  3736. ** If an internal allocation is requested that would exceed the
  3737. ** soft heap limit, [sqlite3_release_memory()] is invoked one or
  3738. ** more times to free up some space before the allocation is performed.
  3739. **
  3740. ** The limit is called "soft", because if [sqlite3_release_memory()]
  3741. ** cannot free sufficient memory to prevent the limit from being exceeded,
  3742. ** the memory is allocated anyway and the current operation proceeds.
  3743. **
  3744. ** A negative or zero value for N means that there is no soft heap limit and
  3745. ** [sqlite3_release_memory()] will only be called when memory is exhausted.
  3746. ** The default value for the soft heap limit is zero.
  3747. **
  3748. ** SQLite makes a best effort to honor the soft heap limit.
  3749. ** But if the soft heap limit cannot be honored, execution will
  3750. ** continue without error or notification. This is why the limit is
  3751. ** called a "soft" limit. It is advisory only.
  3752. **
  3753. ** Prior to SQLite version 3.5.0, this routine only constrained the memory
  3754. ** allocated by a single thread - the same thread in which this routine
  3755. ** runs. Beginning with SQLite version 3.5.0, the soft heap limit is
  3756. ** applied to all threads. The value specified for the soft heap limit
  3757. ** is an upper bound on the total memory allocation for all threads. In
  3758. ** version 3.5.0 there is no mechanism for limiting the heap usage for
  3759. ** individual threads.
  3760. **
  3761. ** Requirements:
  3762. ** [H16351] [H16352] [H16353] [H16354] [H16355] [H16358]
  3763. */
  3764. void sqlite3_soft_heap_limit(int);
  3765. /*
  3766. ** CAPI3REF: Extract Metadata About A Column Of A Table {H12850} <S60300>
  3767. **
  3768. ** This routine returns metadata about a specific column of a specific
  3769. ** database table accessible using the [database connection] handle
  3770. ** passed as the first function argument.
  3771. **
  3772. ** The column is identified by the second, third and fourth parameters to
  3773. ** this function. The second parameter is either the name of the database
  3774. ** (i.e. "main", "temp" or an attached database) containing the specified
  3775. ** table or NULL. If it is NULL, then all attached databases are searched
  3776. ** for the table using the same algorithm used by the database engine to
  3777. ** resolve unqualified table references.
  3778. **
  3779. ** The third and fourth parameters to this function are the table and column
  3780. ** name of the desired column, respectively. Neither of these parameters
  3781. ** may be NULL.
  3782. **
  3783. ** Metadata is returned by writing to the memory locations passed as the 5th
  3784. ** and subsequent parameters to this function. Any of these arguments may be
  3785. ** NULL, in which case the corresponding element of metadata is omitted.
  3786. **
  3787. ** <blockquote>
  3788. ** <table border="1">
  3789. ** <tr><th> Parameter <th> Output<br>Type <th> Description
  3790. **
  3791. ** <tr><td> 5th <td> const char* <td> Data type
  3792. ** <tr><td> 6th <td> const char* <td> Name of default collation sequence
  3793. ** <tr><td> 7th <td> int <td> True if column has a NOT NULL constraint
  3794. ** <tr><td> 8th <td> int <td> True if column is part of the PRIMARY KEY
  3795. ** <tr><td> 9th <td> int <td> True if column is [AUTOINCREMENT]
  3796. ** </table>
  3797. ** </blockquote>
  3798. **
  3799. ** The memory pointed to by the character pointers returned for the
  3800. ** declaration type and collation sequence is valid only until the next
  3801. ** call to any SQLite API function.
  3802. **
  3803. ** If the specified table is actually a view, an [error code] is returned.
  3804. **
  3805. ** If the specified column is "rowid", "oid" or "_rowid_" and an
  3806. ** [INTEGER PRIMARY KEY] column has been explicitly declared, then the output
  3807. ** parameters are set for the explicitly declared column. If there is no
  3808. ** explicitly declared [INTEGER PRIMARY KEY] column, then the output
  3809. ** parameters are set as follows:
  3810. **
  3811. ** <pre>
  3812. ** data type: "INTEGER"
  3813. ** collation sequence: "BINARY"
  3814. ** not null: 0
  3815. ** primary key: 1
  3816. ** auto increment: 0
  3817. ** </pre>
  3818. **
  3819. ** This function may load one or more schemas from database files. If an
  3820. ** error occurs during this process, or if the requested table or column
  3821. ** cannot be found, an [error code] is returned and an error message left
  3822. ** in the [database connection] (to be retrieved using sqlite3_errmsg()).
  3823. **
  3824. ** This API is only available if the library was compiled with the
  3825. ** [SQLITE_ENABLE_COLUMN_METADATA] C-preprocessor symbol defined.
  3826. */
  3827. int sqlite3_table_column_metadata(
  3828. sqlite3 *db, /* Connection handle */
  3829. const char *zDbName, /* Database name or NULL */
  3830. const char *zTableName, /* Table name */
  3831. const char *zColumnName, /* Column name */
  3832. char const **pzDataType, /* OUTPUT: Declared data type */
  3833. char const **pzCollSeq, /* OUTPUT: Collation sequence name */
  3834. int *pNotNull, /* OUTPUT: True if NOT NULL constraint exists */
  3835. int *pPrimaryKey, /* OUTPUT: True if column part of PK */
  3836. int *pAutoinc /* OUTPUT: True if column is auto-increment */
  3837. );
  3838. /*
  3839. ** CAPI3REF: Load An Extension {H12600} <S20500>
  3840. **
  3841. ** This interface loads an SQLite extension library from the named file.
  3842. **
  3843. ** {H12601} The sqlite3_load_extension() interface attempts to load an
  3844. ** SQLite extension library contained in the file zFile.
  3845. **
  3846. ** {H12602} The entry point is zProc.
  3847. **
  3848. ** {H12603} zProc may be 0, in which case the name of the entry point
  3849. ** defaults to "sqlite3_extension_init".
  3850. **
  3851. ** {H12604} The sqlite3_load_extension() interface shall return
  3852. ** [SQLITE_OK] on success and [SQLITE_ERROR] if something goes wrong.
  3853. **
  3854. ** {H12605} If an error occurs and pzErrMsg is not 0, then the
  3855. ** [sqlite3_load_extension()] interface shall attempt to
  3856. ** fill *pzErrMsg with error message text stored in memory
  3857. ** obtained from [sqlite3_malloc()]. {END} The calling function
  3858. ** should free this memory by calling [sqlite3_free()].
  3859. **
  3860. ** {H12606} Extension loading must be enabled using
  3861. ** [sqlite3_enable_load_extension()] prior to calling this API,
  3862. ** otherwise an error will be returned.
  3863. */
  3864. int sqlite3_load_extension(
  3865. sqlite3 *db, /* Load the extension into this database connection */
  3866. const char *zFile, /* Name of the shared library containing extension */
  3867. const char *zProc, /* Entry point. Derived from zFile if 0 */
  3868. char **pzErrMsg /* Put error message here if not 0 */
  3869. );
  3870. /*
  3871. ** CAPI3REF: Enable Or Disable Extension Loading {H12620} <S20500>
  3872. **
  3873. ** So as not to open security holes in older applications that are
  3874. ** unprepared to deal with extension loading, and as a means of disabling
  3875. ** extension loading while evaluating user-entered SQL, the following API
  3876. ** is provided to turn the [sqlite3_load_extension()] mechanism on and off.
  3877. **
  3878. ** Extension loading is off by default. See ticket #1863.
  3879. **
  3880. ** {H12621} Call the sqlite3_enable_load_extension() routine with onoff==1
  3881. ** to turn extension loading on and call it with onoff==0 to turn
  3882. ** it back off again.
  3883. **
  3884. ** {H12622} Extension loading is off by default.
  3885. */
  3886. int sqlite3_enable_load_extension(sqlite3 *db, int onoff);
  3887. /*
  3888. ** CAPI3REF: Automatically Load An Extensions {H12640} <S20500>
  3889. **
  3890. ** This API can be invoked at program startup in order to register
  3891. ** one or more statically linked extensions that will be available
  3892. ** to all new [database connections]. {END}
  3893. **
  3894. ** This routine stores a pointer to the extension in an array that is
  3895. ** obtained from [sqlite3_malloc()]. If you run a memory leak checker
  3896. ** on your program and it reports a leak because of this array, invoke
  3897. ** [sqlite3_reset_auto_extension()] prior to shutdown to free the memory.
  3898. **
  3899. ** {H12641} This function registers an extension entry point that is
  3900. ** automatically invoked whenever a new [database connection]
  3901. ** is opened using [sqlite3_open()], [sqlite3_open16()],
  3902. ** or [sqlite3_open_v2()].
  3903. **
  3904. ** {H12642} Duplicate extensions are detected so calling this routine
  3905. ** multiple times with the same extension is harmless.
  3906. **
  3907. ** {H12643} This routine stores a pointer to the extension in an array
  3908. ** that is obtained from [sqlite3_malloc()].
  3909. **
  3910. ** {H12644} Automatic extensions apply across all threads.
  3911. */
  3912. int sqlite3_auto_extension(void (*xEntryPoint)(void));
  3913. /*
  3914. ** CAPI3REF: Reset Automatic Extension Loading {H12660} <S20500>
  3915. **
  3916. ** This function disables all previously registered automatic
  3917. ** extensions. {END} It undoes the effect of all prior
  3918. ** [sqlite3_auto_extension()] calls.
  3919. **
  3920. ** {H12661} This function disables all previously registered
  3921. ** automatic extensions.
  3922. **
  3923. ** {H12662} This function disables automatic extensions in all threads.
  3924. */
  3925. void sqlite3_reset_auto_extension(void);
  3926. /*
  3927. ****** EXPERIMENTAL - subject to change without notice **************
  3928. **
  3929. ** The interface to the virtual-table mechanism is currently considered
  3930. ** to be experimental. The interface might change in incompatible ways.
  3931. ** If this is a problem for you, do not use the interface at this time.
  3932. **
  3933. ** When the virtual-table mechanism stabilizes, we will declare the
  3934. ** interface fixed, support it indefinitely, and remove this comment.
  3935. */
  3936. /*
  3937. ** Structures used by the virtual table interface
  3938. */
  3939. typedef struct sqlite3_vtab sqlite3_vtab;
  3940. typedef struct sqlite3_index_info sqlite3_index_info;
  3941. typedef struct sqlite3_vtab_cursor sqlite3_vtab_cursor;
  3942. typedef struct sqlite3_module sqlite3_module;
  3943. /*
  3944. ** CAPI3REF: Virtual Table Object {H18000} <S20400>
  3945. ** KEYWORDS: sqlite3_module
  3946. ** EXPERIMENTAL
  3947. **
  3948. ** A module is a class of virtual tables. Each module is defined
  3949. ** by an instance of the following structure. This structure consists
  3950. ** mostly of methods for the module.
  3951. **
  3952. ** This interface is experimental and is subject to change or
  3953. ** removal in future releases of SQLite.
  3954. */
  3955. struct sqlite3_module {
  3956. int iVersion;
  3957. int (*xCreate)(sqlite3*, void *pAux,
  3958. int argc, const char *const*argv,
  3959. sqlite3_vtab **ppVTab, char**);
  3960. int (*xConnect)(sqlite3*, void *pAux,
  3961. int argc, const char *const*argv,
  3962. sqlite3_vtab **ppVTab, char**);
  3963. int (*xBestIndex)(sqlite3_vtab *pVTab, sqlite3_index_info*);
  3964. int (*xDisconnect)(sqlite3_vtab *pVTab);
  3965. int (*xDestroy)(sqlite3_vtab *pVTab);
  3966. int (*xOpen)(sqlite3_vtab *pVTab, sqlite3_vtab_cursor **ppCursor);
  3967. int (*xClose)(sqlite3_vtab_cursor*);
  3968. int (*xFilter)(sqlite3_vtab_cursor*, int idxNum, const char *idxStr,
  3969. int argc, sqlite3_value **argv);
  3970. int (*xNext)(sqlite3_vtab_cursor*);
  3971. int (*xEof)(sqlite3_vtab_cursor*);
  3972. int (*xColumn)(sqlite3_vtab_cursor*, sqlite3_context*, int);
  3973. int (*xRowid)(sqlite3_vtab_cursor*, sqlite3_int64 *pRowid);
  3974. int (*xUpdate)(sqlite3_vtab *, int, sqlite3_value **, sqlite3_int64 *);
  3975. int (*xBegin)(sqlite3_vtab *pVTab);
  3976. int (*xSync)(sqlite3_vtab *pVTab);
  3977. int (*xCommit)(sqlite3_vtab *pVTab);
  3978. int (*xRollback)(sqlite3_vtab *pVTab);
  3979. int (*xFindFunction)(sqlite3_vtab *pVtab, int nArg, const char *zName,
  3980. void (**pxFunc)(sqlite3_context*,int,sqlite3_value**),
  3981. void **ppArg);
  3982. int (*xRename)(sqlite3_vtab *pVtab, const char *zNew);
  3983. };
  3984. /*
  3985. ** CAPI3REF: Virtual Table Indexing Information {H18100} <S20400>
  3986. ** KEYWORDS: sqlite3_index_info
  3987. ** EXPERIMENTAL
  3988. **
  3989. ** The sqlite3_index_info structure and its substructures is used to
  3990. ** pass information into and receive the reply from the xBestIndex
  3991. ** method of an sqlite3_module. The fields under **Inputs** are the
  3992. ** inputs to xBestIndex and are read-only. xBestIndex inserts its
  3993. ** results into the **Outputs** fields.
  3994. **
  3995. ** The aConstraint[] array records WHERE clause constraints of the form:
  3996. **
  3997. ** <pre>column OP expr</pre>
  3998. **
  3999. ** where OP is =, &lt;, &lt;=, &gt;, or &gt;=. The particular operator is
  4000. ** stored in aConstraint[].op. The index of the column is stored in
  4001. ** aConstraint[].iColumn. aConstraint[].usable is TRUE if the
  4002. ** expr on the right-hand side can be evaluated (and thus the constraint
  4003. ** is usable) and false if it cannot.
  4004. **
  4005. ** The optimizer automatically inverts terms of the form "expr OP column"
  4006. ** and makes other simplifications to the WHERE clause in an attempt to
  4007. ** get as many WHERE clause terms into the form shown above as possible.
  4008. ** The aConstraint[] array only reports WHERE clause terms in the correct
  4009. ** form that refer to the particular virtual table being queried.
  4010. **
  4011. ** Information about the ORDER BY clause is stored in aOrderBy[].
  4012. ** Each term of aOrderBy records a column of the ORDER BY clause.
  4013. **
  4014. ** The xBestIndex method must fill aConstraintUsage[] with information
  4015. ** about what parameters to pass to xFilter. If argvIndex>0 then
  4016. ** the right-hand side of the corresponding aConstraint[] is evaluated
  4017. ** and becomes the argvIndex-th entry in argv. If aConstraintUsage[].omit
  4018. ** is true, then the constraint is assumed to be fully handled by the
  4019. ** virtual table and is not checked again by SQLite.
  4020. **
  4021. ** The idxNum and idxPtr values are recorded and passed into xFilter.
  4022. ** sqlite3_free() is used to free idxPtr if needToFreeIdxPtr is true.
  4023. **
  4024. ** The orderByConsumed means that output from xFilter will occur in
  4025. ** the correct order to satisfy the ORDER BY clause so that no separate
  4026. ** sorting step is required.
  4027. **
  4028. ** The estimatedCost value is an estimate of the cost of doing the
  4029. ** particular lookup. A full scan of a table with N entries should have
  4030. ** a cost of N. A binary search of a table of N entries should have a
  4031. ** cost of approximately log(N).
  4032. **
  4033. ** This interface is experimental and is subject to change or
  4034. ** removal in future releases of SQLite.
  4035. */
  4036. struct sqlite3_index_info {
  4037. /* Inputs */
  4038. int nConstraint; /* Number of entries in aConstraint */
  4039. struct sqlite3_index_constraint {
  4040. int iColumn; /* Column on left-hand side of constraint */
  4041. unsigned char op; /* Constraint operator */
  4042. unsigned char usable; /* True if this constraint is usable */
  4043. int iTermOffset; /* Used internally - xBestIndex should ignore */
  4044. } *aConstraint; /* Table of WHERE clause constraints */
  4045. int nOrderBy; /* Number of terms in the ORDER BY clause */
  4046. struct sqlite3_index_orderby {
  4047. int iColumn; /* Column number */
  4048. unsigned char desc; /* True for DESC. False for ASC. */
  4049. } *aOrderBy; /* The ORDER BY clause */
  4050. /* Outputs */
  4051. struct sqlite3_index_constraint_usage {
  4052. int argvIndex; /* if >0, constraint is part of argv to xFilter */
  4053. unsigned char omit; /* Do not code a test for this constraint */
  4054. } *aConstraintUsage;
  4055. int idxNum; /* Number used to identify the index */
  4056. char *idxStr; /* String, possibly obtained from sqlite3_malloc */
  4057. int needToFreeIdxStr; /* Free idxStr using sqlite3_free() if true */
  4058. int orderByConsumed; /* True if output is already ordered */
  4059. double estimatedCost; /* Estimated cost of using this index */
  4060. };
  4061. #define SQLITE_INDEX_CONSTRAINT_EQ 2
  4062. #define SQLITE_INDEX_CONSTRAINT_GT 4
  4063. #define SQLITE_INDEX_CONSTRAINT_LE 8
  4064. #define SQLITE_INDEX_CONSTRAINT_LT 16
  4065. #define SQLITE_INDEX_CONSTRAINT_GE 32
  4066. #define SQLITE_INDEX_CONSTRAINT_MATCH 64
  4067. /*
  4068. ** CAPI3REF: Register A Virtual Table Implementation {H18200} <S20400>
  4069. ** EXPERIMENTAL
  4070. **
  4071. ** This routine is used to register a new module name with a
  4072. ** [database connection]. Module names must be registered before
  4073. ** creating new virtual tables on the module, or before using
  4074. ** preexisting virtual tables of the module.
  4075. **
  4076. ** This interface is experimental and is subject to change or
  4077. ** removal in future releases of SQLite.
  4078. */
  4079. SQLITE_EXPERIMENTAL int sqlite3_create_module(
  4080. sqlite3 *db, /* SQLite connection to register module with */
  4081. const char *zName, /* Name of the module */
  4082. const sqlite3_module *, /* Methods for the module */
  4083. void * /* Client data for xCreate/xConnect */
  4084. );
  4085. /*
  4086. ** CAPI3REF: Register A Virtual Table Implementation {H18210} <S20400>
  4087. ** EXPERIMENTAL
  4088. **
  4089. ** This routine is identical to the [sqlite3_create_module()] method above,
  4090. ** except that it allows a destructor function to be specified. It is
  4091. ** even more experimental than the rest of the virtual tables API.
  4092. */
  4093. SQLITE_EXPERIMENTAL int sqlite3_create_module_v2(
  4094. sqlite3 *db, /* SQLite connection to register module with */
  4095. const char *zName, /* Name of the module */
  4096. const sqlite3_module *, /* Methods for the module */
  4097. void *, /* Client data for xCreate/xConnect */
  4098. void(*xDestroy)(void*) /* Module destructor function */
  4099. );
  4100. /*
  4101. ** CAPI3REF: Virtual Table Instance Object {H18010} <S20400>
  4102. ** KEYWORDS: sqlite3_vtab
  4103. ** EXPERIMENTAL
  4104. **
  4105. ** Every module implementation uses a subclass of the following structure
  4106. ** to describe a particular instance of the module. Each subclass will
  4107. ** be tailored to the specific needs of the module implementation.
  4108. ** The purpose of this superclass is to define certain fields that are
  4109. ** common to all module implementations.
  4110. **
  4111. ** Virtual tables methods can set an error message by assigning a
  4112. ** string obtained from [sqlite3_mprintf()] to zErrMsg. The method should
  4113. ** take care that any prior string is freed by a call to [sqlite3_free()]
  4114. ** prior to assigning a new string to zErrMsg. After the error message
  4115. ** is delivered up to the client application, the string will be automatically
  4116. ** freed by sqlite3_free() and the zErrMsg field will be zeroed. Note
  4117. ** that sqlite3_mprintf() and sqlite3_free() are used on the zErrMsg field
  4118. ** since virtual tables are commonly implemented in loadable extensions which
  4119. ** do not have access to sqlite3MPrintf() or sqlite3Free().
  4120. **
  4121. ** This interface is experimental and is subject to change or
  4122. ** removal in future releases of SQLite.
  4123. */
  4124. struct sqlite3_vtab {
  4125. const sqlite3_module *pModule; /* The module for this virtual table */
  4126. int nRef; /* Used internally */
  4127. char *zErrMsg; /* Error message from sqlite3_mprintf() */
  4128. /* Virtual table implementations will typically add additional fields */
  4129. };
  4130. /*
  4131. ** CAPI3REF: Virtual Table Cursor Object {H18020} <S20400>
  4132. ** KEYWORDS: sqlite3_vtab_cursor
  4133. ** EXPERIMENTAL
  4134. **
  4135. ** Every module implementation uses a subclass of the following structure
  4136. ** to describe cursors that point into the virtual table and are used
  4137. ** to loop through the virtual table. Cursors are created using the
  4138. ** xOpen method of the module. Each module implementation will define
  4139. ** the content of a cursor structure to suit its own needs.
  4140. **
  4141. ** This superclass exists in order to define fields of the cursor that
  4142. ** are common to all implementations.
  4143. **
  4144. ** This interface is experimental and is subject to change or
  4145. ** removal in future releases of SQLite.
  4146. */
  4147. struct sqlite3_vtab_cursor {
  4148. sqlite3_vtab *pVtab; /* Virtual table of this cursor */
  4149. /* Virtual table implementations will typically add additional fields */
  4150. };
  4151. /*
  4152. ** CAPI3REF: Declare The Schema Of A Virtual Table {H18280} <S20400>
  4153. ** EXPERIMENTAL
  4154. **
  4155. ** The xCreate and xConnect methods of a module use the following API
  4156. ** to declare the format (the names and datatypes of the columns) of
  4157. ** the virtual tables they implement.
  4158. **
  4159. ** This interface is experimental and is subject to change or
  4160. ** removal in future releases of SQLite.
  4161. */
  4162. SQLITE_EXPERIMENTAL int sqlite3_declare_vtab(sqlite3*, const char *zCreateTable);
  4163. /*
  4164. ** CAPI3REF: Overload A Function For A Virtual Table {H18300} <S20400>
  4165. ** EXPERIMENTAL
  4166. **
  4167. ** Virtual tables can provide alternative implementations of functions
  4168. ** using the xFindFunction method. But global versions of those functions
  4169. ** must exist in order to be overloaded.
  4170. **
  4171. ** This API makes sure a global version of a function with a particular
  4172. ** name and number of parameters exists. If no such function exists
  4173. ** before this API is called, a new function is created. The implementation
  4174. ** of the new function always causes an exception to be thrown. So
  4175. ** the new function is not good for anything by itself. Its only
  4176. ** purpose is to be a placeholder function that can be overloaded
  4177. ** by virtual tables.
  4178. **
  4179. ** This API should be considered part of the virtual table interface,
  4180. ** which is experimental and subject to change.
  4181. */
  4182. SQLITE_EXPERIMENTAL int sqlite3_overload_function(sqlite3*, const char *zFuncName, int nArg);
  4183. /*
  4184. ** The interface to the virtual-table mechanism defined above (back up
  4185. ** to a comment remarkably similar to this one) is currently considered
  4186. ** to be experimental. The interface might change in incompatible ways.
  4187. ** If this is a problem for you, do not use the interface at this time.
  4188. **
  4189. ** When the virtual-table mechanism stabilizes, we will declare the
  4190. ** interface fixed, support it indefinitely, and remove this comment.
  4191. **
  4192. ****** EXPERIMENTAL - subject to change without notice **************
  4193. */
  4194. /*
  4195. ** CAPI3REF: A Handle To An Open BLOB {H17800} <S30230>
  4196. ** KEYWORDS: {BLOB handle} {BLOB handles}
  4197. **
  4198. ** An instance of this object represents an open BLOB on which
  4199. ** [sqlite3_blob_open | incremental BLOB I/O] can be performed.
  4200. ** Objects of this type are created by [sqlite3_blob_open()]
  4201. ** and destroyed by [sqlite3_blob_close()].
  4202. ** The [sqlite3_blob_read()] and [sqlite3_blob_write()] interfaces
  4203. ** can be used to read or write small subsections of the BLOB.
  4204. ** The [sqlite3_blob_bytes()] interface returns the size of the BLOB in bytes.
  4205. */
  4206. typedef struct sqlite3_blob sqlite3_blob;
  4207. /*
  4208. ** CAPI3REF: Open A BLOB For Incremental I/O {H17810} <S30230>
  4209. **
  4210. ** This interfaces opens a [BLOB handle | handle] to the BLOB located
  4211. ** in row iRow, column zColumn, table zTable in database zDb;
  4212. ** in other words, the same BLOB that would be selected by:
  4213. **
  4214. ** <pre>
  4215. ** SELECT zColumn FROM zDb.zTable WHERE [rowid] = iRow;
  4216. ** </pre> {END}
  4217. **
  4218. ** If the flags parameter is non-zero, the the BLOB is opened for read
  4219. ** and write access. If it is zero, the BLOB is opened for read access.
  4220. **
  4221. ** Note that the database name is not the filename that contains
  4222. ** the database but rather the symbolic name of the database that
  4223. ** is assigned when the database is connected using [ATTACH].
  4224. ** For the main database file, the database name is "main".
  4225. ** For TEMP tables, the database name is "temp".
  4226. **
  4227. ** On success, [SQLITE_OK] is returned and the new [BLOB handle] is written
  4228. ** to *ppBlob. Otherwise an [error code] is returned and any value written
  4229. ** to *ppBlob should not be used by the caller.
  4230. ** This function sets the [database connection] error code and message
  4231. ** accessible via [sqlite3_errcode()] and [sqlite3_errmsg()].
  4232. **
  4233. ** If the row that a BLOB handle points to is modified by an
  4234. ** [UPDATE], [DELETE], or by [ON CONFLICT] side-effects
  4235. ** then the BLOB handle is marked as "expired".
  4236. ** This is true if any column of the row is changed, even a column
  4237. ** other than the one the BLOB handle is open on.
  4238. ** Calls to [sqlite3_blob_read()] and [sqlite3_blob_write()] for
  4239. ** a expired BLOB handle fail with an return code of [SQLITE_ABORT].
  4240. ** Changes written into a BLOB prior to the BLOB expiring are not
  4241. ** rollback by the expiration of the BLOB. Such changes will eventually
  4242. ** commit if the transaction continues to completion.
  4243. **
  4244. ** Requirements:
  4245. ** [H17813] [H17814] [H17816] [H17819] [H17821] [H17824]
  4246. */
  4247. int sqlite3_blob_open(
  4248. sqlite3*,
  4249. const char *zDb,
  4250. const char *zTable,
  4251. const char *zColumn,
  4252. sqlite3_int64 iRow,
  4253. int flags,
  4254. sqlite3_blob **ppBlob
  4255. );
  4256. /*
  4257. ** CAPI3REF: Close A BLOB Handle {H17830} <S30230>
  4258. **
  4259. ** Closes an open [BLOB handle].
  4260. **
  4261. ** Closing a BLOB shall cause the current transaction to commit
  4262. ** if there are no other BLOBs, no pending prepared statements, and the
  4263. ** database connection is in [autocommit mode].
  4264. ** If any writes were made to the BLOB, they might be held in cache
  4265. ** until the close operation if they will fit. {END}
  4266. **
  4267. ** Closing the BLOB often forces the changes
  4268. ** out to disk and so if any I/O errors occur, they will likely occur
  4269. ** at the time when the BLOB is closed. {H17833} Any errors that occur during
  4270. ** closing are reported as a non-zero return value.
  4271. **
  4272. ** The BLOB is closed unconditionally. Even if this routine returns
  4273. ** an error code, the BLOB is still closed.
  4274. **
  4275. ** Requirements:
  4276. ** [H17833] [H17836] [H17839]
  4277. */
  4278. int sqlite3_blob_close(sqlite3_blob *);
  4279. /*
  4280. ** CAPI3REF: Return The Size Of An Open BLOB {H17840} <S30230>
  4281. **
  4282. ** Returns the size in bytes of the BLOB accessible via the open
  4283. ** []BLOB handle] in its only argument.
  4284. **
  4285. ** Requirements:
  4286. ** [H17843]
  4287. */
  4288. int sqlite3_blob_bytes(sqlite3_blob *);
  4289. /*
  4290. ** CAPI3REF: Read Data From A BLOB Incrementally {H17850} <S30230>
  4291. **
  4292. ** This function is used to read data from an open [BLOB handle] into a
  4293. ** caller-supplied buffer. N bytes of data are copied into buffer Z
  4294. ** from the open BLOB, starting at offset iOffset.
  4295. **
  4296. ** If offset iOffset is less than N bytes from the end of the BLOB,
  4297. ** [SQLITE_ERROR] is returned and no data is read. If N or iOffset is
  4298. ** less than zero, [SQLITE_ERROR] is returned and no data is read.
  4299. **
  4300. ** An attempt to read from an expired [BLOB handle] fails with an
  4301. ** error code of [SQLITE_ABORT].
  4302. **
  4303. ** On success, SQLITE_OK is returned.
  4304. ** Otherwise, an [error code] or an [extended error code] is returned.
  4305. **
  4306. ** Requirements:
  4307. ** [H17853] [H17856] [H17859] [H17862] [H17863] [H17865] [H17868]
  4308. */
  4309. int sqlite3_blob_read(sqlite3_blob *, void *Z, int N, int iOffset);
  4310. /*
  4311. ** CAPI3REF: Write Data Into A BLOB Incrementally {H17870} <S30230>
  4312. **
  4313. ** This function is used to write data into an open [BLOB handle] from a
  4314. ** caller-supplied buffer. N bytes of data are copied from the buffer Z
  4315. ** into the open BLOB, starting at offset iOffset.
  4316. **
  4317. ** If the [BLOB handle] passed as the first argument was not opened for
  4318. ** writing (the flags parameter to [sqlite3_blob_open()] was zero),
  4319. ** this function returns [SQLITE_READONLY].
  4320. **
  4321. ** This function may only modify the contents of the BLOB; it is
  4322. ** not possible to increase the size of a BLOB using this API.
  4323. ** If offset iOffset is less than N bytes from the end of the BLOB,
  4324. ** [SQLITE_ERROR] is returned and no data is written. If N is
  4325. ** less than zero [SQLITE_ERROR] is returned and no data is written.
  4326. **
  4327. ** An attempt to write to an expired [BLOB handle] fails with an
  4328. ** error code of [SQLITE_ABORT]. Writes to the BLOB that occurred
  4329. ** before the [BLOB handle] expired are not rolled back by the
  4330. ** expiration of the handle, though of course those changes might
  4331. ** have been overwritten by the statement that expired the BLOB handle
  4332. ** or by other independent statements.
  4333. **
  4334. ** On success, SQLITE_OK is returned.
  4335. ** Otherwise, an [error code] or an [extended error code] is returned.
  4336. **
  4337. ** Requirements:
  4338. ** [H17873] [H17874] [H17875] [H17876] [H17877] [H17879] [H17882] [H17885]
  4339. ** [H17888]
  4340. */
  4341. int sqlite3_blob_write(sqlite3_blob *, const void *z, int n, int iOffset);
  4342. /*
  4343. ** CAPI3REF: Virtual File System Objects {H11200} <S20100>
  4344. **
  4345. ** A virtual filesystem (VFS) is an [sqlite3_vfs] object
  4346. ** that SQLite uses to interact
  4347. ** with the underlying operating system. Most SQLite builds come with a
  4348. ** single default VFS that is appropriate for the host computer.
  4349. ** New VFSes can be registered and existing VFSes can be unregistered.
  4350. ** The following interfaces are provided.
  4351. **
  4352. ** The sqlite3_vfs_find() interface returns a pointer to a VFS given its name.
  4353. ** Names are case sensitive.
  4354. ** Names are zero-terminated UTF-8 strings.
  4355. ** If there is no match, a NULL pointer is returned.
  4356. ** If zVfsName is NULL then the default VFS is returned.
  4357. **
  4358. ** New VFSes are registered with sqlite3_vfs_register().
  4359. ** Each new VFS becomes the default VFS if the makeDflt flag is set.
  4360. ** The same VFS can be registered multiple times without injury.
  4361. ** To make an existing VFS into the default VFS, register it again
  4362. ** with the makeDflt flag set. If two different VFSes with the
  4363. ** same name are registered, the behavior is undefined. If a
  4364. ** VFS is registered with a name that is NULL or an empty string,
  4365. ** then the behavior is undefined.
  4366. **
  4367. ** Unregister a VFS with the sqlite3_vfs_unregister() interface.
  4368. ** If the default VFS is unregistered, another VFS is chosen as
  4369. ** the default. The choice for the new VFS is arbitrary.
  4370. **
  4371. ** Requirements:
  4372. ** [H11203] [H11206] [H11209] [H11212] [H11215] [H11218]
  4373. */
  4374. sqlite3_vfs *sqlite3_vfs_find(const char *zVfsName);
  4375. int sqlite3_vfs_register(sqlite3_vfs*, int makeDflt);
  4376. int sqlite3_vfs_unregister(sqlite3_vfs*);
  4377. /*
  4378. ** CAPI3REF: Mutexes {H17000} <S20000>
  4379. **
  4380. ** The SQLite core uses these routines for thread
  4381. ** synchronization. Though they are intended for internal
  4382. ** use by SQLite, code that links against SQLite is
  4383. ** permitted to use any of these routines.
  4384. **
  4385. ** The SQLite source code contains multiple implementations
  4386. ** of these mutex routines. An appropriate implementation
  4387. ** is selected automatically at compile-time. The following
  4388. ** implementations are available in the SQLite core:
  4389. **
  4390. ** <ul>
  4391. ** <li> SQLITE_MUTEX_OS2
  4392. ** <li> SQLITE_MUTEX_PTHREAD
  4393. ** <li> SQLITE_MUTEX_W32
  4394. ** <li> SQLITE_MUTEX_NOOP
  4395. ** </ul>
  4396. **
  4397. ** The SQLITE_MUTEX_NOOP implementation is a set of routines
  4398. ** that does no real locking and is appropriate for use in
  4399. ** a single-threaded application. The SQLITE_MUTEX_OS2,
  4400. ** SQLITE_MUTEX_PTHREAD, and SQLITE_MUTEX_W32 implementations
  4401. ** are appropriate for use on OS/2, Unix, and Windows.
  4402. **
  4403. ** If SQLite is compiled with the SQLITE_MUTEX_APPDEF preprocessor
  4404. ** macro defined (with "-DSQLITE_MUTEX_APPDEF=1"), then no mutex
  4405. ** implementation is included with the library. In this case the
  4406. ** application must supply a custom mutex implementation using the
  4407. ** [SQLITE_CONFIG_MUTEX] option of the sqlite3_config() function
  4408. ** before calling sqlite3_initialize() or any other public sqlite3_
  4409. ** function that calls sqlite3_initialize().
  4410. **
  4411. ** {H17011} The sqlite3_mutex_alloc() routine allocates a new
  4412. ** mutex and returns a pointer to it. {H17012} If it returns NULL
  4413. ** that means that a mutex could not be allocated. {H17013} SQLite
  4414. ** will unwind its stack and return an error. {H17014} The argument
  4415. ** to sqlite3_mutex_alloc() is one of these integer constants:
  4416. **
  4417. ** <ul>
  4418. ** <li> SQLITE_MUTEX_FAST
  4419. ** <li> SQLITE_MUTEX_RECURSIVE
  4420. ** <li> SQLITE_MUTEX_STATIC_MASTER
  4421. ** <li> SQLITE_MUTEX_STATIC_MEM
  4422. ** <li> SQLITE_MUTEX_STATIC_MEM2
  4423. ** <li> SQLITE_MUTEX_STATIC_PRNG
  4424. ** <li> SQLITE_MUTEX_STATIC_LRU
  4425. ** <li> SQLITE_MUTEX_STATIC_LRU2
  4426. ** </ul>
  4427. **
  4428. ** {H17015} The first two constants cause sqlite3_mutex_alloc() to create
  4429. ** a new mutex. The new mutex is recursive when SQLITE_MUTEX_RECURSIVE
  4430. ** is used but not necessarily so when SQLITE_MUTEX_FAST is used. {END}
  4431. ** The mutex implementation does not need to make a distinction
  4432. ** between SQLITE_MUTEX_RECURSIVE and SQLITE_MUTEX_FAST if it does
  4433. ** not want to. {H17016} But SQLite will only request a recursive mutex in
  4434. ** cases where it really needs one. {END} If a faster non-recursive mutex
  4435. ** implementation is available on the host platform, the mutex subsystem
  4436. ** might return such a mutex in response to SQLITE_MUTEX_FAST.
  4437. **
  4438. ** {H17017} The other allowed parameters to sqlite3_mutex_alloc() each return
  4439. ** a pointer to a static preexisting mutex. {END} Four static mutexes are
  4440. ** used by the current version of SQLite. Future versions of SQLite
  4441. ** may add additional static mutexes. Static mutexes are for internal
  4442. ** use by SQLite only. Applications that use SQLite mutexes should
  4443. ** use only the dynamic mutexes returned by SQLITE_MUTEX_FAST or
  4444. ** SQLITE_MUTEX_RECURSIVE.
  4445. **
  4446. ** {H17018} Note that if one of the dynamic mutex parameters (SQLITE_MUTEX_FAST
  4447. ** or SQLITE_MUTEX_RECURSIVE) is used then sqlite3_mutex_alloc()
  4448. ** returns a different mutex on every call. {H17034} But for the static
  4449. ** mutex types, the same mutex is returned on every call that has
  4450. ** the same type number.
  4451. **
  4452. ** {H17019} The sqlite3_mutex_free() routine deallocates a previously
  4453. ** allocated dynamic mutex. {H17020} SQLite is careful to deallocate every
  4454. ** dynamic mutex that it allocates. {A17021} The dynamic mutexes must not be in
  4455. ** use when they are deallocated. {A17022} Attempting to deallocate a static
  4456. ** mutex results in undefined behavior. {H17023} SQLite never deallocates
  4457. ** a static mutex. {END}
  4458. **
  4459. ** The sqlite3_mutex_enter() and sqlite3_mutex_try() routines attempt
  4460. ** to enter a mutex. {H17024} If another thread is already within the mutex,
  4461. ** sqlite3_mutex_enter() will block and sqlite3_mutex_try() will return
  4462. ** SQLITE_BUSY. {H17025} The sqlite3_mutex_try() interface returns [SQLITE_OK]
  4463. ** upon successful entry. {H17026} Mutexes created using
  4464. ** SQLITE_MUTEX_RECURSIVE can be entered multiple times by the same thread.
  4465. ** {H17027} In such cases the,
  4466. ** mutex must be exited an equal number of times before another thread
  4467. ** can enter. {A17028} If the same thread tries to enter any other
  4468. ** kind of mutex more than once, the behavior is undefined.
  4469. ** {H17029} SQLite will never exhibit
  4470. ** such behavior in its own use of mutexes.
  4471. **
  4472. ** Some systems (for example, Windows 95) do not support the operation
  4473. ** implemented by sqlite3_mutex_try(). On those systems, sqlite3_mutex_try()
  4474. ** will always return SQLITE_BUSY. {H17030} The SQLite core only ever uses
  4475. ** sqlite3_mutex_try() as an optimization so this is acceptable behavior.
  4476. **
  4477. ** {H17031} The sqlite3_mutex_leave() routine exits a mutex that was
  4478. ** previously entered by the same thread. {A17032} The behavior
  4479. ** is undefined if the mutex is not currently entered by the
  4480. ** calling thread or is not currently allocated. {H17033} SQLite will
  4481. ** never do either. {END}
  4482. **
  4483. ** If the argument to sqlite3_mutex_enter(), sqlite3_mutex_try(), or
  4484. ** sqlite3_mutex_leave() is a NULL pointer, then all three routines
  4485. ** behave as no-ops.
  4486. **
  4487. ** See also: [sqlite3_mutex_held()] and [sqlite3_mutex_notheld()].
  4488. */
  4489. sqlite3_mutex *sqlite3_mutex_alloc(int);
  4490. void sqlite3_mutex_free(sqlite3_mutex*);
  4491. void sqlite3_mutex_enter(sqlite3_mutex*);
  4492. int sqlite3_mutex_try(sqlite3_mutex*);
  4493. void sqlite3_mutex_leave(sqlite3_mutex*);
  4494. /*
  4495. ** CAPI3REF: Mutex Methods Object {H17120} <S20130>
  4496. ** EXPERIMENTAL
  4497. **
  4498. ** An instance of this structure defines the low-level routines
  4499. ** used to allocate and use mutexes.
  4500. **
  4501. ** Usually, the default mutex implementations provided by SQLite are
  4502. ** sufficient, however the user has the option of substituting a custom
  4503. ** implementation for specialized deployments or systems for which SQLite
  4504. ** does not provide a suitable implementation. In this case, the user
  4505. ** creates and populates an instance of this structure to pass
  4506. ** to sqlite3_config() along with the [SQLITE_CONFIG_MUTEX] option.
  4507. ** Additionally, an instance of this structure can be used as an
  4508. ** output variable when querying the system for the current mutex
  4509. ** implementation, using the [SQLITE_CONFIG_GETMUTEX] option.
  4510. **
  4511. ** The xMutexInit method defined by this structure is invoked as
  4512. ** part of system initialization by the sqlite3_initialize() function.
  4513. ** {H17001} The xMutexInit routine shall be called by SQLite once for each
  4514. ** effective call to [sqlite3_initialize()].
  4515. **
  4516. ** The xMutexEnd method defined by this structure is invoked as
  4517. ** part of system shutdown by the sqlite3_shutdown() function. The
  4518. ** implementation of this method is expected to release all outstanding
  4519. ** resources obtained by the mutex methods implementation, especially
  4520. ** those obtained by the xMutexInit method. {H17003} The xMutexEnd()
  4521. ** interface shall be invoked once for each call to [sqlite3_shutdown()].
  4522. **
  4523. ** The remaining seven methods defined by this structure (xMutexAlloc,
  4524. ** xMutexFree, xMutexEnter, xMutexTry, xMutexLeave, xMutexHeld and
  4525. ** xMutexNotheld) implement the following interfaces (respectively):
  4526. **
  4527. ** <ul>
  4528. ** <li> [sqlite3_mutex_alloc()] </li>
  4529. ** <li> [sqlite3_mutex_free()] </li>
  4530. ** <li> [sqlite3_mutex_enter()] </li>
  4531. ** <li> [sqlite3_mutex_try()] </li>
  4532. ** <li> [sqlite3_mutex_leave()] </li>
  4533. ** <li> [sqlite3_mutex_held()] </li>
  4534. ** <li> [sqlite3_mutex_notheld()] </li>
  4535. ** </ul>
  4536. **
  4537. ** The only difference is that the public sqlite3_XXX functions enumerated
  4538. ** above silently ignore any invocations that pass a NULL pointer instead
  4539. ** of a valid mutex handle. The implementations of the methods defined
  4540. ** by this structure are not required to handle this case, the results
  4541. ** of passing a NULL pointer instead of a valid mutex handle are undefined
  4542. ** (i.e. it is acceptable to provide an implementation that segfaults if
  4543. ** it is passed a NULL pointer).
  4544. */
  4545. typedef struct sqlite3_mutex_methods sqlite3_mutex_methods;
  4546. struct sqlite3_mutex_methods {
  4547. int (*xMutexInit)(void);
  4548. int (*xMutexEnd)(void);
  4549. sqlite3_mutex *(*xMutexAlloc)(int);
  4550. void (*xMutexFree)(sqlite3_mutex *);
  4551. void (*xMutexEnter)(sqlite3_mutex *);
  4552. int (*xMutexTry)(sqlite3_mutex *);
  4553. void (*xMutexLeave)(sqlite3_mutex *);
  4554. int (*xMutexHeld)(sqlite3_mutex *);
  4555. int (*xMutexNotheld)(sqlite3_mutex *);
  4556. };
  4557. /*
  4558. ** CAPI3REF: Mutex Verification Routines {H17080} <S20130> <S30800>
  4559. **
  4560. ** The sqlite3_mutex_held() and sqlite3_mutex_notheld() routines
  4561. ** are intended for use inside assert() statements. {H17081} The SQLite core
  4562. ** never uses these routines except inside an assert() and applications
  4563. ** are advised to follow the lead of the core. {H17082} The core only
  4564. ** provides implementations for these routines when it is compiled
  4565. ** with the SQLITE_DEBUG flag. {A17087} External mutex implementations
  4566. ** are only required to provide these routines if SQLITE_DEBUG is
  4567. ** defined and if NDEBUG is not defined.
  4568. **
  4569. ** {H17083} These routines should return true if the mutex in their argument
  4570. ** is held or not held, respectively, by the calling thread.
  4571. **
  4572. ** {X17084} The implementation is not required to provided versions of these
  4573. ** routines that actually work. If the implementation does not provide working
  4574. ** versions of these routines, it should at least provide stubs that always
  4575. ** return true so that one does not get spurious assertion failures.
  4576. **
  4577. ** {H17085} If the argument to sqlite3_mutex_held() is a NULL pointer then
  4578. ** the routine should return 1. {END} This seems counter-intuitive since
  4579. ** clearly the mutex cannot be held if it does not exist. But the
  4580. ** the reason the mutex does not exist is because the build is not
  4581. ** using mutexes. And we do not want the assert() containing the
  4582. ** call to sqlite3_mutex_held() to fail, so a non-zero return is
  4583. ** the appropriate thing to do. {H17086} The sqlite3_mutex_notheld()
  4584. ** interface should also return 1 when given a NULL pointer.
  4585. */
  4586. int sqlite3_mutex_held(sqlite3_mutex*);
  4587. int sqlite3_mutex_notheld(sqlite3_mutex*);
  4588. /*
  4589. ** CAPI3REF: Mutex Types {H17001} <H17000>
  4590. **
  4591. ** The [sqlite3_mutex_alloc()] interface takes a single argument
  4592. ** which is one of these integer constants.
  4593. **
  4594. ** The set of static mutexes may change from one SQLite release to the
  4595. ** next. Applications that override the built-in mutex logic must be
  4596. ** prepared to accommodate additional static mutexes.
  4597. */
  4598. #define SQLITE_MUTEX_FAST 0
  4599. #define SQLITE_MUTEX_RECURSIVE 1
  4600. #define SQLITE_MUTEX_STATIC_MASTER 2
  4601. #define SQLITE_MUTEX_STATIC_MEM 3 /* sqlite3_malloc() */
  4602. #define SQLITE_MUTEX_STATIC_MEM2 4 /* NOT USED */
  4603. #define SQLITE_MUTEX_STATIC_OPEN 4 /* sqlite3BtreeOpen() */
  4604. #define SQLITE_MUTEX_STATIC_PRNG 5 /* sqlite3_random() */
  4605. #define SQLITE_MUTEX_STATIC_LRU 6 /* lru page list */
  4606. #define SQLITE_MUTEX_STATIC_LRU2 7 /* lru page list */
  4607. /*
  4608. ** CAPI3REF: Retrieve the mutex for a database connection {H17002} <H17000>
  4609. **
  4610. ** This interface returns a pointer the [sqlite3_mutex] object that
  4611. ** serializes access to the [database connection] given in the argument
  4612. ** when the [threading mode] is Serialized.
  4613. ** If the [threading mode] is Single-thread or Multi-thread then this
  4614. ** routine returns a NULL pointer.
  4615. */
  4616. sqlite3_mutex *sqlite3_db_mutex(sqlite3*);
  4617. /*
  4618. ** CAPI3REF: Low-Level Control Of Database Files {H11300} <S30800>
  4619. **
  4620. ** {H11301} The [sqlite3_file_control()] interface makes a direct call to the
  4621. ** xFileControl method for the [sqlite3_io_methods] object associated
  4622. ** with a particular database identified by the second argument. {H11302} The
  4623. ** name of the database is the name assigned to the database by the
  4624. ** <a href="lang_attach.html">ATTACH</a> SQL command that opened the
  4625. ** database. {H11303} To control the main database file, use the name "main"
  4626. ** or a NULL pointer. {H11304} The third and fourth parameters to this routine
  4627. ** are passed directly through to the second and third parameters of
  4628. ** the xFileControl method. {H11305} The return value of the xFileControl
  4629. ** method becomes the return value of this routine.
  4630. **
  4631. ** {H11306} If the second parameter (zDbName) does not match the name of any
  4632. ** open database file, then SQLITE_ERROR is returned. {H11307} This error
  4633. ** code is not remembered and will not be recalled by [sqlite3_errcode()]
  4634. ** or [sqlite3_errmsg()]. {A11308} The underlying xFileControl method might
  4635. ** also return SQLITE_ERROR. {A11309} There is no way to distinguish between
  4636. ** an incorrect zDbName and an SQLITE_ERROR return from the underlying
  4637. ** xFileControl method. {END}
  4638. **
  4639. ** See also: [SQLITE_FCNTL_LOCKSTATE]
  4640. */
  4641. int sqlite3_file_control(sqlite3*, const char *zDbName, int op, void*);
  4642. /*
  4643. ** CAPI3REF: Testing Interface {H11400} <S30800>
  4644. **
  4645. ** The sqlite3_test_control() interface is used to read out internal
  4646. ** state of SQLite and to inject faults into SQLite for testing
  4647. ** purposes. The first parameter is an operation code that determines
  4648. ** the number, meaning, and operation of all subsequent parameters.
  4649. **
  4650. ** This interface is not for use by applications. It exists solely
  4651. ** for verifying the correct operation of the SQLite library. Depending
  4652. ** on how the SQLite library is compiled, this interface might not exist.
  4653. **
  4654. ** The details of the operation codes, their meanings, the parameters
  4655. ** they take, and what they do are all subject to change without notice.
  4656. ** Unlike most of the SQLite API, this function is not guaranteed to
  4657. ** operate consistently from one release to the next.
  4658. */
  4659. int sqlite3_test_control(int op, ...);
  4660. /*
  4661. ** CAPI3REF: Testing Interface Operation Codes {H11410} <H11400>
  4662. **
  4663. ** These constants are the valid operation code parameters used
  4664. ** as the first argument to [sqlite3_test_control()].
  4665. **
  4666. ** These parameters and their meanings are subject to change
  4667. ** without notice. These values are for testing purposes only.
  4668. ** Applications should not use any of these parameters or the
  4669. ** [sqlite3_test_control()] interface.
  4670. */
  4671. #define SQLITE_TESTCTRL_PRNG_SAVE 5
  4672. #define SQLITE_TESTCTRL_PRNG_RESTORE 6
  4673. #define SQLITE_TESTCTRL_PRNG_RESET 7
  4674. #define SQLITE_TESTCTRL_BITVEC_TEST 8
  4675. #define SQLITE_TESTCTRL_FAULT_INSTALL 9
  4676. #define SQLITE_TESTCTRL_BENIGN_MALLOC_HOOKS 10
  4677. #define SQLITE_TESTCTRL_PENDING_BYTE 11
  4678. /*
  4679. ** CAPI3REF: SQLite Runtime Status {H17200} <S60200>
  4680. ** EXPERIMENTAL
  4681. **
  4682. ** This interface is used to retrieve runtime status information
  4683. ** about the preformance of SQLite, and optionally to reset various
  4684. ** highwater marks. The first argument is an integer code for
  4685. ** the specific parameter to measure. Recognized integer codes
  4686. ** are of the form [SQLITE_STATUS_MEMORY_USED | SQLITE_STATUS_...].
  4687. ** The current value of the parameter is returned into *pCurrent.
  4688. ** The highest recorded value is returned in *pHighwater. If the
  4689. ** resetFlag is true, then the highest record value is reset after
  4690. ** *pHighwater is written. Some parameters do not record the highest
  4691. ** value. For those parameters
  4692. ** nothing is written into *pHighwater and the resetFlag is ignored.
  4693. ** Other parameters record only the highwater mark and not the current
  4694. ** value. For these latter parameters nothing is written into *pCurrent.
  4695. **
  4696. ** This routine returns SQLITE_OK on success and a non-zero
  4697. ** [error code] on failure.
  4698. **
  4699. ** This routine is threadsafe but is not atomic. This routine can
  4700. ** called while other threads are running the same or different SQLite
  4701. ** interfaces. However the values returned in *pCurrent and
  4702. ** *pHighwater reflect the status of SQLite at different points in time
  4703. ** and it is possible that another thread might change the parameter
  4704. ** in between the times when *pCurrent and *pHighwater are written.
  4705. **
  4706. ** See also: [sqlite3_db_status()]
  4707. */
  4708. SQLITE_EXPERIMENTAL int sqlite3_status(int op, int *pCurrent, int *pHighwater, int resetFlag);
  4709. /*
  4710. ** CAPI3REF: Status Parameters {H17250} <H17200>
  4711. ** EXPERIMENTAL
  4712. **
  4713. ** These integer constants designate various run-time status parameters
  4714. ** that can be returned by [sqlite3_status()].
  4715. **
  4716. ** <dl>
  4717. ** <dt>SQLITE_STATUS_MEMORY_USED</dt>
  4718. ** <dd>This parameter is the current amount of memory checked out
  4719. ** using [sqlite3_malloc()], either directly or indirectly. The
  4720. ** figure includes calls made to [sqlite3_malloc()] by the application
  4721. ** and internal memory usage by the SQLite library. Scratch memory
  4722. ** controlled by [SQLITE_CONFIG_SCRATCH] and auxiliary page-cache
  4723. ** memory controlled by [SQLITE_CONFIG_PAGECACHE] is not included in
  4724. ** this parameter. The amount returned is the sum of the allocation
  4725. ** sizes as reported by the xSize method in [sqlite3_mem_methods].</dd>
  4726. **
  4727. ** <dt>SQLITE_STATUS_MALLOC_SIZE</dt>
  4728. ** <dd>This parameter records the largest memory allocation request
  4729. ** handed to [sqlite3_malloc()] or [sqlite3_realloc()] (or their
  4730. ** internal equivalents). Only the value returned in the
  4731. ** *pHighwater parameter to [sqlite3_status()] is of interest.
  4732. ** The value written into the *pCurrent parameter is undefined.</dd>
  4733. **
  4734. ** <dt>SQLITE_STATUS_PAGECACHE_USED</dt>
  4735. ** <dd>This parameter returns the number of pages used out of the
  4736. ** [pagecache memory allocator] that was configured using
  4737. ** [SQLITE_CONFIG_PAGECACHE]. The
  4738. ** value returned is in pages, not in bytes.</dd>
  4739. **
  4740. ** <dt>SQLITE_STATUS_PAGECACHE_OVERFLOW</dt>
  4741. ** <dd>This parameter returns the number of bytes of page cache
  4742. ** allocation which could not be statisfied by the [SQLITE_CONFIG_PAGECACHE]
  4743. ** buffer and where forced to overflow to [sqlite3_malloc()]. The
  4744. ** returned value includes allocations that overflowed because they
  4745. ** where too large (they were larger than the "sz" parameter to
  4746. ** [SQLITE_CONFIG_PAGECACHE]) and allocations that overflowed because
  4747. ** no space was left in the page cache.</dd>
  4748. **
  4749. ** <dt>SQLITE_STATUS_PAGECACHE_SIZE</dt>
  4750. ** <dd>This parameter records the largest memory allocation request
  4751. ** handed to [pagecache memory allocator]. Only the value returned in the
  4752. ** *pHighwater parameter to [sqlite3_status()] is of interest.
  4753. ** The value written into the *pCurrent parameter is undefined.</dd>
  4754. **
  4755. ** <dt>SQLITE_STATUS_SCRATCH_USED</dt>
  4756. ** <dd>This parameter returns the number of allocations used out of the
  4757. ** [scratch memory allocator] configured using
  4758. ** [SQLITE_CONFIG_SCRATCH]. The value returned is in allocations, not
  4759. ** in bytes. Since a single thread may only have one scratch allocation
  4760. ** outstanding at time, this parameter also reports the number of threads
  4761. ** using scratch memory at the same time.</dd>
  4762. **
  4763. ** <dt>SQLITE_STATUS_SCRATCH_OVERFLOW</dt>
  4764. ** <dd>This parameter returns the number of bytes of scratch memory
  4765. ** allocation which could not be statisfied by the [SQLITE_CONFIG_SCRATCH]
  4766. ** buffer and where forced to overflow to [sqlite3_malloc()]. The values
  4767. ** returned include overflows because the requested allocation was too
  4768. ** larger (that is, because the requested allocation was larger than the
  4769. ** "sz" parameter to [SQLITE_CONFIG_SCRATCH]) and because no scratch buffer
  4770. ** slots were available.
  4771. ** </dd>
  4772. **
  4773. ** <dt>SQLITE_STATUS_SCRATCH_SIZE</dt>
  4774. ** <dd>This parameter records the largest memory allocation request
  4775. ** handed to [scratch memory allocator]. Only the value returned in the
  4776. ** *pHighwater parameter to [sqlite3_status()] is of interest.
  4777. ** The value written into the *pCurrent parameter is undefined.</dd>
  4778. **
  4779. ** <dt>SQLITE_STATUS_PARSER_STACK</dt>
  4780. ** <dd>This parameter records the deepest parser stack. It is only
  4781. ** meaningful if SQLite is compiled with [YYTRACKMAXSTACKDEPTH].</dd>
  4782. ** </dl>
  4783. **
  4784. ** New status parameters may be added from time to time.
  4785. */
  4786. #define SQLITE_STATUS_MEMORY_USED 0
  4787. #define SQLITE_STATUS_PAGECACHE_USED 1
  4788. #define SQLITE_STATUS_PAGECACHE_OVERFLOW 2
  4789. #define SQLITE_STATUS_SCRATCH_USED 3
  4790. #define SQLITE_STATUS_SCRATCH_OVERFLOW 4
  4791. #define SQLITE_STATUS_MALLOC_SIZE 5
  4792. #define SQLITE_STATUS_PARSER_STACK 6
  4793. #define SQLITE_STATUS_PAGECACHE_SIZE 7
  4794. #define SQLITE_STATUS_SCRATCH_SIZE 8
  4795. /*
  4796. ** CAPI3REF: Database Connection Status {H17500} <S60200>
  4797. ** EXPERIMENTAL
  4798. **
  4799. ** This interface is used to retrieve runtime status information
  4800. ** about a single [database connection]. The first argument is the
  4801. ** database connection object to be interrogated. The second argument
  4802. ** is the parameter to interrogate. Currently, the only allowed value
  4803. ** for the second parameter is [SQLITE_DBSTATUS_LOOKASIDE_USED].
  4804. ** Additional options will likely appear in future releases of SQLite.
  4805. **
  4806. ** The current value of the requested parameter is written into *pCur
  4807. ** and the highest instantaneous value is written into *pHiwtr. If
  4808. ** the resetFlg is true, then the highest instantaneous value is
  4809. ** reset back down to the current value.
  4810. **
  4811. ** See also: [sqlite3_status()] and [sqlite3_stmt_status()].
  4812. */
  4813. SQLITE_EXPERIMENTAL int sqlite3_db_status(sqlite3*, int op, int *pCur, int *pHiwtr, int resetFlg);
  4814. /*
  4815. ** CAPI3REF: Status Parameters for database connections {H17520} <H17500>
  4816. ** EXPERIMENTAL
  4817. **
  4818. ** Status verbs for [sqlite3_db_status()].
  4819. **
  4820. ** <dl>
  4821. ** <dt>SQLITE_DBSTATUS_LOOKASIDE_USED</dt>
  4822. ** <dd>This parameter returns the number of lookaside memory slots currently
  4823. ** checked out.</dd>
  4824. ** </dl>
  4825. */
  4826. #define SQLITE_DBSTATUS_LOOKASIDE_USED 0
  4827. /*
  4828. ** CAPI3REF: Prepared Statement Status {H17550} <S60200>
  4829. ** EXPERIMENTAL
  4830. **
  4831. ** Each prepared statement maintains various
  4832. ** [SQLITE_STMTSTATUS_SORT | counters] that measure the number
  4833. ** of times it has performed specific operations. These counters can
  4834. ** be used to monitor the performance characteristics of the prepared
  4835. ** statements. For example, if the number of table steps greatly exceeds
  4836. ** the number of table searches or result rows, that would tend to indicate
  4837. ** that the prepared statement is using a full table scan rather than
  4838. ** an index.
  4839. **
  4840. ** This interface is used to retrieve and reset counter values from
  4841. ** a [prepared statement]. The first argument is the prepared statement
  4842. ** object to be interrogated. The second argument
  4843. ** is an integer code for a specific [SQLITE_STMTSTATUS_SORT | counter]
  4844. ** to be interrogated.
  4845. ** The current value of the requested counter is returned.
  4846. ** If the resetFlg is true, then the counter is reset to zero after this
  4847. ** interface call returns.
  4848. **
  4849. ** See also: [sqlite3_status()] and [sqlite3_db_status()].
  4850. */
  4851. SQLITE_EXPERIMENTAL int sqlite3_stmt_status(sqlite3_stmt*, int op,int resetFlg);
  4852. /*
  4853. ** CAPI3REF: Status Parameters for prepared statements {H17570} <H17550>
  4854. ** EXPERIMENTAL
  4855. **
  4856. ** These preprocessor macros define integer codes that name counter
  4857. ** values associated with the [sqlite3_stmt_status()] interface.
  4858. ** The meanings of the various counters are as follows:
  4859. **
  4860. ** <dl>
  4861. ** <dt>SQLITE_STMTSTATUS_FULLSCAN_STEP</dt>
  4862. ** <dd>This is the number of times that SQLite has stepped forward in
  4863. ** a table as part of a full table scan. Large numbers for this counter
  4864. ** may indicate opportunities for performance improvement through
  4865. ** careful use of indices.</dd>
  4866. **
  4867. ** <dt>SQLITE_STMTSTATUS_SORT</dt>
  4868. ** <dd>This is the number of sort operations that have occurred.
  4869. ** A non-zero value in this counter may indicate an opportunity to
  4870. ** improvement performance through careful use of indices.</dd>
  4871. **
  4872. ** </dl>
  4873. */
  4874. #define SQLITE_STMTSTATUS_FULLSCAN_STEP 1
  4875. #define SQLITE_STMTSTATUS_SORT 2
  4876. /*
  4877. ** CAPI3REF: Custom Page Cache Object
  4878. ** EXPERIMENTAL
  4879. **
  4880. ** The sqlite3_pcache type is opaque. It is implemented by
  4881. ** the pluggable module. The SQLite core has no knowledge of
  4882. ** its size or internal structure and never deals with the
  4883. ** sqlite3_pcache object except by holding and passing pointers
  4884. ** to the object.
  4885. **
  4886. ** See [sqlite3_pcache_methods] for additional information.
  4887. */
  4888. typedef struct sqlite3_pcache sqlite3_pcache;
  4889. /*
  4890. ** CAPI3REF: Application Defined Page Cache.
  4891. ** EXPERIMENTAL
  4892. **
  4893. ** The [sqlite3_config]([SQLITE_CONFIG_PCACHE], ...) interface can
  4894. ** register an alternative page cache implementation by passing in an
  4895. ** instance of the sqlite3_pcache_methods structure. The majority of the
  4896. ** heap memory used by sqlite is used by the page cache to cache data read
  4897. ** from, or ready to be written to, the database file. By implementing a
  4898. ** custom page cache using this API, an application can control more
  4899. ** precisely the amount of memory consumed by sqlite, the way in which
  4900. ** said memory is allocated and released, and the policies used to
  4901. ** determine exactly which parts of a database file are cached and for
  4902. ** how long.
  4903. **
  4904. ** The contents of the structure are copied to an internal buffer by sqlite
  4905. ** within the call to [sqlite3_config].
  4906. **
  4907. ** The xInit() method is called once for each call to [sqlite3_initialize()]
  4908. ** (usually only once during the lifetime of the process). It is passed
  4909. ** a copy of the sqlite3_pcache_methods.pArg value. It can be used to set
  4910. ** up global structures and mutexes required by the custom page cache
  4911. ** implementation. The xShutdown() method is called from within
  4912. ** [sqlite3_shutdown()], if the application invokes this API. It can be used
  4913. ** to clean up any outstanding resources before process shutdown, if required.
  4914. **
  4915. ** The xCreate() method is used to construct a new cache instance. The
  4916. ** first parameter, szPage, is the size in bytes of the pages that must
  4917. ** be allocated by the cache. szPage will not be a power of two. The
  4918. ** second argument, bPurgeable, is true if the cache being created will
  4919. ** be used to cache database pages read from a file stored on disk, or
  4920. ** false if it is used for an in-memory database. The cache implementation
  4921. ** does not have to do anything special based on the value of bPurgeable,
  4922. ** it is purely advisory.
  4923. **
  4924. ** The xCachesize() method may be called at any time by SQLite to set the
  4925. ** suggested maximum cache-size (number of pages stored by) the cache
  4926. ** instance passed as the first argument. This is the value configured using
  4927. ** the SQLite "[PRAGMA cache_size]" command. As with the bPurgeable parameter,
  4928. ** the implementation is not required to do anything special with this
  4929. ** value, it is advisory only.
  4930. **
  4931. ** The xPagecount() method should return the number of pages currently
  4932. ** stored in the cache supplied as an argument.
  4933. **
  4934. ** The xFetch() method is used to fetch a page and return a pointer to it.
  4935. ** A 'page', in this context, is a buffer of szPage bytes aligned at an
  4936. ** 8-byte boundary. The page to be fetched is determined by the key. The
  4937. ** mimimum key value is 1. After it has been retrieved using xFetch, the page
  4938. ** is considered to be pinned.
  4939. **
  4940. ** If the requested page is already in the page cache, then a pointer to
  4941. ** the cached buffer should be returned with its contents intact. If the
  4942. ** page is not already in the cache, then the expected behaviour of the
  4943. ** cache is determined by the value of the createFlag parameter passed
  4944. ** to xFetch, according to the following table:
  4945. **
  4946. ** <table border=1 width=85% align=center>
  4947. ** <tr><th>createFlag<th>Expected Behaviour
  4948. ** <tr><td>0<td>NULL should be returned. No new cache entry is created.
  4949. ** <tr><td>1<td>If createFlag is set to 1, this indicates that
  4950. ** SQLite is holding pinned pages that can be unpinned
  4951. ** by writing their contents to the database file (a
  4952. ** relatively expensive operation). In this situation the
  4953. ** cache implementation has two choices: it can return NULL,
  4954. ** in which case SQLite will attempt to unpin one or more
  4955. ** pages before re-requesting the same page, or it can
  4956. ** allocate a new page and return a pointer to it. If a new
  4957. ** page is allocated, then the first sizeof(void*) bytes of
  4958. ** it (at least) must be zeroed before it is returned.
  4959. ** <tr><td>2<td>If createFlag is set to 2, then SQLite is not holding any
  4960. ** pinned pages associated with the specific cache passed
  4961. ** as the first argument to xFetch() that can be unpinned. The
  4962. ** cache implementation should attempt to allocate a new
  4963. ** cache entry and return a pointer to it. Again, the first
  4964. ** sizeof(void*) bytes of the page should be zeroed before
  4965. ** it is returned. If the xFetch() method returns NULL when
  4966. ** createFlag==2, SQLite assumes that a memory allocation
  4967. ** failed and returns SQLITE_NOMEM to the user.
  4968. ** </table>
  4969. **
  4970. ** xUnpin() is called by SQLite with a pointer to a currently pinned page
  4971. ** as its second argument. If the third parameter, discard, is non-zero,
  4972. ** then the page should be evicted from the cache. In this case SQLite
  4973. ** assumes that the next time the page is retrieved from the cache using
  4974. ** the xFetch() method, it will be zeroed. If the discard parameter is
  4975. ** zero, then the page is considered to be unpinned. The cache implementation
  4976. ** may choose to reclaim (free or recycle) unpinned pages at any time.
  4977. ** SQLite assumes that next time the page is retrieved from the cache
  4978. ** it will either be zeroed, or contain the same data that it did when it
  4979. ** was unpinned.
  4980. **
  4981. ** The cache is not required to perform any reference counting. A single
  4982. ** call to xUnpin() unpins the page regardless of the number of prior calls
  4983. ** to xFetch().
  4984. **
  4985. ** The xRekey() method is used to change the key value associated with the
  4986. ** page passed as the second argument from oldKey to newKey. If the cache
  4987. ** previously contains an entry associated with newKey, it should be
  4988. ** discarded. Any prior cache entry associated with newKey is guaranteed not
  4989. ** to be pinned.
  4990. **
  4991. ** When SQLite calls the xTruncate() method, the cache must discard all
  4992. ** existing cache entries with page numbers (keys) greater than or equal
  4993. ** to the value of the iLimit parameter passed to xTruncate(). If any
  4994. ** of these pages are pinned, they are implicitly unpinned, meaning that
  4995. ** they can be safely discarded.
  4996. **
  4997. ** The xDestroy() method is used to delete a cache allocated by xCreate().
  4998. ** All resources associated with the specified cache should be freed. After
  4999. ** calling the xDestroy() method, SQLite considers the [sqlite3_pcache*]
  5000. ** handle invalid, and will not use it with any other sqlite3_pcache_methods
  5001. ** functions.
  5002. */
  5003. typedef struct sqlite3_pcache_methods sqlite3_pcache_methods;
  5004. struct sqlite3_pcache_methods {
  5005. void *pArg;
  5006. int (*xInit)(void*);
  5007. void (*xShutdown)(void*);
  5008. sqlite3_pcache *(*xCreate)(int szPage, int bPurgeable);
  5009. void (*xCachesize)(sqlite3_pcache*, int nCachesize);
  5010. int (*xPagecount)(sqlite3_pcache*);
  5011. void *(*xFetch)(sqlite3_pcache*, unsigned key, int createFlag);
  5012. void (*xUnpin)(sqlite3_pcache*, void*, int discard);
  5013. void (*xRekey)(sqlite3_pcache*, void*, unsigned oldKey, unsigned newKey);
  5014. void (*xTruncate)(sqlite3_pcache*, unsigned iLimit);
  5015. void (*xDestroy)(sqlite3_pcache*);
  5016. };
  5017. /*
  5018. ** CAPI3REF: Online Backup Object
  5019. ** EXPERIMENTAL
  5020. **
  5021. ** The sqlite3_backup object records state information about an ongoing
  5022. ** online backup operation. The sqlite3_backup object is created by
  5023. ** a call to [sqlite3_backup_init()] and is destroyed by a call to
  5024. ** [sqlite3_backup_finish()].
  5025. **
  5026. ** See Also: [Using the SQLite Online Backup API]
  5027. */
  5028. typedef struct sqlite3_backup sqlite3_backup;
  5029. /*
  5030. ** CAPI3REF: Online Backup API.
  5031. ** EXPERIMENTAL
  5032. **
  5033. ** This API is used to overwrite the contents of one database with that
  5034. ** of another. It is useful either for creating backups of databases or
  5035. ** for copying in-memory databases to or from persistent files.
  5036. **
  5037. ** See Also: [Using the SQLite Online Backup API]
  5038. **
  5039. ** Exclusive access is required to the destination database for the
  5040. ** duration of the operation. However the source database is only
  5041. ** read-locked while it is actually being read, it is not locked
  5042. ** continuously for the entire operation. Thus, the backup may be
  5043. ** performed on a live database without preventing other users from
  5044. ** writing to the database for an extended period of time.
  5045. **
  5046. ** To perform a backup operation:
  5047. ** <ol>
  5048. ** <li><b>sqlite3_backup_init()</b> is called once to initialize the
  5049. ** backup,
  5050. ** <li><b>sqlite3_backup_step()</b> is called one or more times to transfer
  5051. ** the data between the two databases, and finally
  5052. ** <li><b>sqlite3_backup_finish()</b> is called to release all resources
  5053. ** associated with the backup operation.
  5054. ** </ol>
  5055. ** There should be exactly one call to sqlite3_backup_finish() for each
  5056. ** successful call to sqlite3_backup_init().
  5057. **
  5058. ** <b>sqlite3_backup_init()</b>
  5059. **
  5060. ** The first two arguments passed to [sqlite3_backup_init()] are the database
  5061. ** handle associated with the destination database and the database name
  5062. ** used to attach the destination database to the handle. The database name
  5063. ** is "main" for the main database, "temp" for the temporary database, or
  5064. ** the name specified as part of the [ATTACH] statement if the destination is
  5065. ** an attached database. The third and fourth arguments passed to
  5066. ** sqlite3_backup_init() identify the [database connection]
  5067. ** and database name used
  5068. ** to access the source database. The values passed for the source and
  5069. ** destination [database connection] parameters must not be the same.
  5070. **
  5071. ** If an error occurs within sqlite3_backup_init(), then NULL is returned
  5072. ** and an error code and error message written into the [database connection]
  5073. ** passed as the first argument. They may be retrieved using the
  5074. ** [sqlite3_errcode()], [sqlite3_errmsg()], and [sqlite3_errmsg16()] functions.
  5075. ** Otherwise, if successful, a pointer to an [sqlite3_backup] object is
  5076. ** returned. This pointer may be used with the sqlite3_backup_step() and
  5077. ** sqlite3_backup_finish() functions to perform the specified backup
  5078. ** operation.
  5079. **
  5080. ** <b>sqlite3_backup_step()</b>
  5081. **
  5082. ** Function [sqlite3_backup_step()] is used to copy up to nPage pages between
  5083. ** the source and destination databases, where nPage is the value of the
  5084. ** second parameter passed to sqlite3_backup_step(). If nPage is a negative
  5085. ** value, all remaining source pages are copied. If the required pages are
  5086. ** succesfully copied, but there are still more pages to copy before the
  5087. ** backup is complete, it returns [SQLITE_OK]. If no error occured and there
  5088. ** are no more pages to copy, then [SQLITE_DONE] is returned. If an error
  5089. ** occurs, then an SQLite error code is returned. As well as [SQLITE_OK] and
  5090. ** [SQLITE_DONE], a call to sqlite3_backup_step() may return [SQLITE_READONLY],
  5091. ** [SQLITE_NOMEM], [SQLITE_BUSY], [SQLITE_LOCKED], or an
  5092. ** [SQLITE_IOERR_ACCESS | SQLITE_IOERR_XXX] extended error code.
  5093. **
  5094. ** As well as the case where the destination database file was opened for
  5095. ** read-only access, sqlite3_backup_step() may return [SQLITE_READONLY] if
  5096. ** the destination is an in-memory database with a different page size
  5097. ** from the source database.
  5098. **
  5099. ** If sqlite3_backup_step() cannot obtain a required file-system lock, then
  5100. ** the [sqlite3_busy_handler | busy-handler function]
  5101. ** is invoked (if one is specified). If the
  5102. ** busy-handler returns non-zero before the lock is available, then
  5103. ** [SQLITE_BUSY] is returned to the caller. In this case the call to
  5104. ** sqlite3_backup_step() can be retried later. If the source
  5105. ** [database connection]
  5106. ** is being used to write to the source database when sqlite3_backup_step()
  5107. ** is called, then [SQLITE_LOCKED] is returned immediately. Again, in this
  5108. ** case the call to sqlite3_backup_step() can be retried later on. If
  5109. ** [SQLITE_IOERR_ACCESS | SQLITE_IOERR_XXX], [SQLITE_NOMEM], or
  5110. ** [SQLITE_READONLY] is returned, then
  5111. ** there is no point in retrying the call to sqlite3_backup_step(). These
  5112. ** errors are considered fatal. At this point the application must accept
  5113. ** that the backup operation has failed and pass the backup operation handle
  5114. ** to the sqlite3_backup_finish() to release associated resources.
  5115. **
  5116. ** Following the first call to sqlite3_backup_step(), an exclusive lock is
  5117. ** obtained on the destination file. It is not released until either
  5118. ** sqlite3_backup_finish() is called or the backup operation is complete
  5119. ** and sqlite3_backup_step() returns [SQLITE_DONE]. Additionally, each time
  5120. ** a call to sqlite3_backup_step() is made a [shared lock] is obtained on
  5121. ** the source database file. This lock is released before the
  5122. ** sqlite3_backup_step() call returns. Because the source database is not
  5123. ** locked between calls to sqlite3_backup_step(), it may be modified mid-way
  5124. ** through the backup procedure. If the source database is modified by an
  5125. ** external process or via a database connection other than the one being
  5126. ** used by the backup operation, then the backup will be transparently
  5127. ** restarted by the next call to sqlite3_backup_step(). If the source
  5128. ** database is modified by the using the same database connection as is used
  5129. ** by the backup operation, then the backup database is transparently
  5130. ** updated at the same time.
  5131. **
  5132. ** <b>sqlite3_backup_finish()</b>
  5133. **
  5134. ** Once sqlite3_backup_step() has returned [SQLITE_DONE], or when the
  5135. ** application wishes to abandon the backup operation, the [sqlite3_backup]
  5136. ** object should be passed to sqlite3_backup_finish(). This releases all
  5137. ** resources associated with the backup operation. If sqlite3_backup_step()
  5138. ** has not yet returned [SQLITE_DONE], then any active write-transaction on the
  5139. ** destination database is rolled back. The [sqlite3_backup] object is invalid
  5140. ** and may not be used following a call to sqlite3_backup_finish().
  5141. **
  5142. ** The value returned by sqlite3_backup_finish is [SQLITE_OK] if no error
  5143. ** occurred, regardless or whether or not sqlite3_backup_step() was called
  5144. ** a sufficient number of times to complete the backup operation. Or, if
  5145. ** an out-of-memory condition or IO error occured during a call to
  5146. ** sqlite3_backup_step() then [SQLITE_NOMEM] or an
  5147. ** [SQLITE_IOERR_ACCESS | SQLITE_IOERR_XXX] error code
  5148. ** is returned. In this case the error code and an error message are
  5149. ** written to the destination [database connection].
  5150. **
  5151. ** A return of [SQLITE_BUSY] or [SQLITE_LOCKED] from sqlite3_backup_step() is
  5152. ** not a permanent error and does not affect the return value of
  5153. ** sqlite3_backup_finish().
  5154. **
  5155. ** <b>sqlite3_backup_remaining(), sqlite3_backup_pagecount()</b>
  5156. **
  5157. ** Each call to sqlite3_backup_step() sets two values stored internally
  5158. ** by an [sqlite3_backup] object. The number of pages still to be backed
  5159. ** up, which may be queried by sqlite3_backup_remaining(), and the total
  5160. ** number of pages in the source database file, which may be queried by
  5161. ** sqlite3_backup_pagecount().
  5162. **
  5163. ** The values returned by these functions are only updated by
  5164. ** sqlite3_backup_step(). If the source database is modified during a backup
  5165. ** operation, then the values are not updated to account for any extra
  5166. ** pages that need to be updated or the size of the source database file
  5167. ** changing.
  5168. **
  5169. ** <b>Concurrent Usage of Database Handles</b>
  5170. **
  5171. ** The source [database connection] may be used by the application for other
  5172. ** purposes while a backup operation is underway or being initialized.
  5173. ** If SQLite is compiled and configured to support threadsafe database
  5174. ** connections, then the source database connection may be used concurrently
  5175. ** from within other threads.
  5176. **
  5177. ** However, the application must guarantee that the destination database
  5178. ** connection handle is not passed to any other API (by any thread) after
  5179. ** sqlite3_backup_init() is called and before the corresponding call to
  5180. ** sqlite3_backup_finish(). Unfortunately SQLite does not currently check
  5181. ** for this, if the application does use the destination [database connection]
  5182. ** for some other purpose during a backup operation, things may appear to
  5183. ** work correctly but in fact be subtly malfunctioning. Use of the
  5184. ** destination database connection while a backup is in progress might
  5185. ** also cause a mutex deadlock.
  5186. **
  5187. ** Furthermore, if running in [shared cache mode], the application must
  5188. ** guarantee that the shared cache used by the destination database
  5189. ** is not accessed while the backup is running. In practice this means
  5190. ** that the application must guarantee that the file-system file being
  5191. ** backed up to is not accessed by any connection within the process,
  5192. ** not just the specific connection that was passed to sqlite3_backup_init().
  5193. **
  5194. ** The [sqlite3_backup] object itself is partially threadsafe. Multiple
  5195. ** threads may safely make multiple concurrent calls to sqlite3_backup_step().
  5196. ** However, the sqlite3_backup_remaining() and sqlite3_backup_pagecount()
  5197. ** APIs are not strictly speaking threadsafe. If they are invoked at the
  5198. ** same time as another thread is invoking sqlite3_backup_step() it is
  5199. ** possible that they return invalid values.
  5200. */
  5201. sqlite3_backup *sqlite3_backup_init(
  5202. sqlite3 *pDest, /* Destination database handle */
  5203. const char *zDestName, /* Destination database name */
  5204. sqlite3 *pSource, /* Source database handle */
  5205. const char *zSourceName /* Source database name */
  5206. );
  5207. int sqlite3_backup_step(sqlite3_backup *p, int nPage);
  5208. int sqlite3_backup_finish(sqlite3_backup *p);
  5209. int sqlite3_backup_remaining(sqlite3_backup *p);
  5210. int sqlite3_backup_pagecount(sqlite3_backup *p);
  5211. /*
  5212. ** CAPI3REF: Unlock Notification
  5213. ** EXPERIMENTAL
  5214. **
  5215. ** When running in shared-cache mode, a database operation may fail with
  5216. ** an [SQLITE_LOCKED] error if the required locks on the shared-cache or
  5217. ** individual tables within the shared-cache cannot be obtained. See
  5218. ** [SQLite Shared-Cache Mode] for a description of shared-cache locking.
  5219. ** This API may be used to register a callback that SQLite will invoke
  5220. ** when the connection currently holding the required lock relinquishes it.
  5221. ** This API is only available if the library was compiled with the
  5222. ** [SQLITE_ENABLE_UNLOCK_NOTIFY] C-preprocessor symbol defined.
  5223. **
  5224. ** See Also: [Using the SQLite Unlock Notification Feature].
  5225. **
  5226. ** Shared-cache locks are released when a database connection concludes
  5227. ** its current transaction, either by committing it or rolling it back.
  5228. **
  5229. ** When a connection (known as the blocked connection) fails to obtain a
  5230. ** shared-cache lock and SQLITE_LOCKED is returned to the caller, the
  5231. ** identity of the database connection (the blocking connection) that
  5232. ** has locked the required resource is stored internally. After an
  5233. ** application receives an SQLITE_LOCKED error, it may call the
  5234. ** sqlite3_unlock_notify() method with the blocked connection handle as
  5235. ** the first argument to register for a callback that will be invoked
  5236. ** when the blocking connections current transaction is concluded. The
  5237. ** callback is invoked from within the [sqlite3_step] or [sqlite3_close]
  5238. ** call that concludes the blocking connections transaction.
  5239. **
  5240. ** If sqlite3_unlock_notify() is called in a multi-threaded application,
  5241. ** there is a chance that the blocking connection will have already
  5242. ** concluded its transaction by the time sqlite3_unlock_notify() is invoked.
  5243. ** If this happens, then the specified callback is invoked immediately,
  5244. ** from within the call to sqlite3_unlock_notify().
  5245. **
  5246. ** If the blocked connection is attempting to obtain a write-lock on a
  5247. ** shared-cache table, and more than one other connection currently holds
  5248. ** a read-lock on the same table, then SQLite arbitrarily selects one of
  5249. ** the other connections to use as the blocking connection.
  5250. **
  5251. ** There may be at most one unlock-notify callback registered by a
  5252. ** blocked connection. If sqlite3_unlock_notify() is called when the
  5253. ** blocked connection already has a registered unlock-notify callback,
  5254. ** then the new callback replaces the old. If sqlite3_unlock_notify() is
  5255. ** called with a NULL pointer as its second argument, then any existing
  5256. ** unlock-notify callback is cancelled. The blocked connections
  5257. ** unlock-notify callback may also be canceled by closing the blocked
  5258. ** connection using [sqlite3_close()].
  5259. **
  5260. ** The unlock-notify callback is not reentrant. If an application invokes
  5261. ** any sqlite3_xxx API functions from within an unlock-notify callback, a
  5262. ** crash or deadlock may be the result.
  5263. **
  5264. ** Unless deadlock is detected (see below), sqlite3_unlock_notify() always
  5265. ** returns SQLITE_OK.
  5266. **
  5267. ** <b>Callback Invocation Details</b>
  5268. **
  5269. ** When an unlock-notify callback is registered, the application provides a
  5270. ** single void* pointer that is passed to the callback when it is invoked.
  5271. ** However, the signature of the callback function allows SQLite to pass
  5272. ** it an array of void* context pointers. The first argument passed to
  5273. ** an unlock-notify callback is a pointer to an array of void* pointers,
  5274. ** and the second is the number of entries in the array.
  5275. **
  5276. ** When a blocking connections transaction is concluded, there may be
  5277. ** more than one blocked connection that has registered for an unlock-notify
  5278. ** callback. If two or more such blocked connections have specified the
  5279. ** same callback function, then instead of invoking the callback function
  5280. ** multiple times, it is invoked once with the set of void* context pointers
  5281. ** specified by the blocked connections bundled together into an array.
  5282. ** This gives the application an opportunity to prioritize any actions
  5283. ** related to the set of unblocked database connections.
  5284. **
  5285. ** <b>Deadlock Detection</b>
  5286. **
  5287. ** Assuming that after registering for an unlock-notify callback a
  5288. ** database waits for the callback to be issued before taking any further
  5289. ** action (a reasonable assumption), then using this API may cause the
  5290. ** application to deadlock. For example, if connection X is waiting for
  5291. ** connection Y's transaction to be concluded, and similarly connection
  5292. ** Y is waiting on connection X's transaction, then neither connection
  5293. ** will proceed and the system may remain deadlocked indefinitely.
  5294. **
  5295. ** To avoid this scenario, the sqlite3_unlock_notify() performs deadlock
  5296. ** detection. If a given call to sqlite3_unlock_notify() would put the
  5297. ** system in a deadlocked state, then SQLITE_LOCKED is returned and no
  5298. ** unlock-notify callback is registered. The system is said to be in
  5299. ** a deadlocked state if connection A has registered for an unlock-notify
  5300. ** callback on the conclusion of connection B's transaction, and connection
  5301. ** B has itself registered for an unlock-notify callback when connection
  5302. ** A's transaction is concluded. Indirect deadlock is also detected, so
  5303. ** the system is also considered to be deadlocked if connection B has
  5304. ** registered for an unlock-notify callback on the conclusion of connection
  5305. ** C's transaction, where connection C is waiting on connection A. Any
  5306. ** number of levels of indirection are allowed.
  5307. **
  5308. ** <b>The "DROP TABLE" Exception</b>
  5309. **
  5310. ** When a call to [sqlite3_step()] returns SQLITE_LOCKED, it is almost
  5311. ** always appropriate to call sqlite3_unlock_notify(). There is however,
  5312. ** one exception. When executing a "DROP TABLE" or "DROP INDEX" statement,
  5313. ** SQLite checks if there are any currently executing SELECT statements
  5314. ** that belong to the same connection. If there are, SQLITE_LOCKED is
  5315. ** returned. In this case there is no "blocking connection", so invoking
  5316. ** sqlite3_unlock_notify() results in the unlock-notify callback being
  5317. ** invoked immediately. If the application then re-attempts the "DROP TABLE"
  5318. ** or "DROP INDEX" query, an infinite loop might be the result.
  5319. **
  5320. ** One way around this problem is to check the extended error code returned
  5321. ** by an sqlite3_step() call. If there is a blocking connection, then the
  5322. ** extended error code is set to SQLITE_LOCKED_SHAREDCACHE. Otherwise, in
  5323. ** the special "DROP TABLE/INDEX" case, the extended error code is just
  5324. ** SQLITE_LOCKED.
  5325. */
  5326. int sqlite3_unlock_notify(
  5327. sqlite3 *pBlocked, /* Waiting connection */
  5328. void (*xNotify)(void **apArg, int nArg), /* Callback function to invoke */
  5329. void *pNotifyArg /* Argument to pass to xNotify */
  5330. );
  5331. /*
  5332. ** Undo the hack that converts floating point types to integer for
  5333. ** builds on processors without floating point support.
  5334. */
  5335. #ifdef SQLITE_OMIT_FLOATING_POINT
  5336. # undef double
  5337. #endif
  5338. #ifdef __cplusplus
  5339. } /* End of the 'extern "C"' block */
  5340. #endif
  5341. #endif