sqlite3.h 247 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666166716681669167016711672167316741675167616771678167916801681168216831684168516861687168816891690169116921693169416951696169716981699170017011702170317041705170617071708170917101711171217131714171517161717171817191720172117221723172417251726172717281729173017311732173317341735173617371738173917401741174217431744174517461747174817491750175117521753175417551756175717581759176017611762176317641765176617671768176917701771177217731774177517761777177817791780178117821783178417851786178717881789179017911792179317941795179617971798179918001801180218031804180518061807180818091810181118121813181418151816181718181819182018211822182318241825182618271828182918301831183218331834183518361837183818391840184118421843184418451846184718481849185018511852185318541855185618571858185918601861186218631864186518661867186818691870187118721873187418751876187718781879188018811882188318841885188618871888188918901891189218931894189518961897189818991900190119021903190419051906190719081909191019111912191319141915191619171918191919201921192219231924192519261927192819291930193119321933193419351936193719381939194019411942194319441945194619471948194919501951195219531954195519561957195819591960196119621963196419651966196719681969197019711972197319741975197619771978197919801981198219831984198519861987198819891990199119921993199419951996199719981999200020012002200320042005200620072008200920102011201220132014201520162017201820192020202120222023202420252026202720282029203020312032203320342035203620372038203920402041204220432044204520462047204820492050205120522053205420552056205720582059206020612062206320642065206620672068206920702071207220732074207520762077207820792080208120822083208420852086208720882089209020912092209320942095209620972098209921002101210221032104210521062107210821092110211121122113211421152116211721182119212021212122212321242125212621272128212921302131213221332134213521362137213821392140214121422143214421452146214721482149215021512152215321542155215621572158215921602161216221632164216521662167216821692170217121722173217421752176217721782179218021812182218321842185218621872188218921902191219221932194219521962197219821992200220122022203220422052206220722082209221022112212221322142215221622172218221922202221222222232224222522262227222822292230223122322233223422352236223722382239224022412242224322442245224622472248224922502251225222532254225522562257225822592260226122622263226422652266226722682269227022712272227322742275227622772278227922802281228222832284228522862287228822892290229122922293229422952296229722982299230023012302230323042305230623072308230923102311231223132314231523162317231823192320232123222323232423252326232723282329233023312332233323342335233623372338233923402341234223432344234523462347234823492350235123522353235423552356235723582359236023612362236323642365236623672368236923702371237223732374237523762377237823792380238123822383238423852386238723882389239023912392239323942395239623972398239924002401240224032404240524062407240824092410241124122413241424152416241724182419242024212422242324242425242624272428242924302431243224332434243524362437243824392440244124422443244424452446244724482449245024512452245324542455245624572458245924602461246224632464246524662467246824692470247124722473247424752476247724782479248024812482248324842485248624872488248924902491249224932494249524962497249824992500250125022503250425052506250725082509251025112512251325142515251625172518251925202521252225232524252525262527252825292530253125322533253425352536253725382539254025412542254325442545254625472548254925502551255225532554255525562557255825592560256125622563256425652566256725682569257025712572257325742575257625772578257925802581258225832584258525862587258825892590259125922593259425952596259725982599260026012602260326042605260626072608260926102611261226132614261526162617261826192620262126222623262426252626262726282629263026312632263326342635263626372638263926402641264226432644264526462647264826492650265126522653265426552656265726582659266026612662266326642665266626672668266926702671267226732674267526762677267826792680268126822683268426852686268726882689269026912692269326942695269626972698269927002701270227032704270527062707270827092710271127122713271427152716271727182719272027212722272327242725272627272728272927302731273227332734273527362737273827392740274127422743274427452746274727482749275027512752275327542755275627572758275927602761276227632764276527662767276827692770277127722773277427752776277727782779278027812782278327842785278627872788278927902791279227932794279527962797279827992800280128022803280428052806280728082809281028112812281328142815281628172818281928202821282228232824282528262827282828292830283128322833283428352836283728382839284028412842284328442845284628472848284928502851285228532854285528562857285828592860286128622863286428652866286728682869287028712872287328742875287628772878287928802881288228832884288528862887288828892890289128922893289428952896289728982899290029012902290329042905290629072908290929102911291229132914291529162917291829192920292129222923292429252926292729282929293029312932293329342935293629372938293929402941294229432944294529462947294829492950295129522953295429552956295729582959296029612962296329642965296629672968296929702971297229732974297529762977297829792980298129822983298429852986298729882989299029912992299329942995299629972998299930003001300230033004300530063007300830093010301130123013301430153016301730183019302030213022302330243025302630273028302930303031303230333034303530363037303830393040304130423043304430453046304730483049305030513052305330543055305630573058305930603061306230633064306530663067306830693070307130723073307430753076307730783079308030813082308330843085308630873088308930903091309230933094309530963097309830993100310131023103310431053106310731083109311031113112311331143115311631173118311931203121312231233124312531263127312831293130313131323133313431353136313731383139314031413142314331443145314631473148314931503151315231533154315531563157315831593160316131623163316431653166316731683169317031713172317331743175317631773178317931803181318231833184318531863187318831893190319131923193319431953196319731983199320032013202320332043205320632073208320932103211321232133214321532163217321832193220322132223223322432253226322732283229323032313232323332343235323632373238323932403241324232433244324532463247324832493250325132523253325432553256325732583259326032613262326332643265326632673268326932703271327232733274327532763277327832793280328132823283328432853286328732883289329032913292329332943295329632973298329933003301330233033304330533063307330833093310331133123313331433153316331733183319332033213322332333243325332633273328332933303331333233333334333533363337333833393340334133423343334433453346334733483349335033513352335333543355335633573358335933603361336233633364336533663367336833693370337133723373337433753376337733783379338033813382338333843385338633873388338933903391339233933394339533963397339833993400340134023403340434053406340734083409341034113412341334143415341634173418341934203421342234233424342534263427342834293430343134323433343434353436343734383439344034413442344334443445344634473448344934503451345234533454345534563457345834593460346134623463346434653466346734683469347034713472347334743475347634773478347934803481348234833484348534863487348834893490349134923493349434953496349734983499350035013502350335043505350635073508350935103511351235133514351535163517351835193520352135223523352435253526352735283529353035313532353335343535353635373538353935403541354235433544354535463547354835493550355135523553355435553556355735583559356035613562356335643565356635673568356935703571357235733574357535763577357835793580358135823583358435853586358735883589359035913592359335943595359635973598359936003601360236033604360536063607360836093610361136123613361436153616361736183619362036213622362336243625362636273628362936303631363236333634363536363637363836393640364136423643364436453646364736483649365036513652365336543655365636573658365936603661366236633664366536663667366836693670367136723673367436753676367736783679368036813682368336843685368636873688368936903691369236933694369536963697369836993700370137023703370437053706370737083709371037113712371337143715371637173718371937203721372237233724372537263727372837293730373137323733373437353736373737383739374037413742374337443745374637473748374937503751375237533754375537563757375837593760376137623763376437653766376737683769377037713772377337743775377637773778377937803781378237833784378537863787378837893790379137923793379437953796379737983799380038013802380338043805380638073808380938103811381238133814381538163817381838193820382138223823382438253826382738283829383038313832383338343835383638373838383938403841384238433844384538463847384838493850385138523853385438553856385738583859386038613862386338643865386638673868386938703871387238733874387538763877387838793880388138823883388438853886388738883889389038913892389338943895389638973898389939003901390239033904390539063907390839093910391139123913391439153916391739183919392039213922392339243925392639273928392939303931393239333934393539363937393839393940394139423943394439453946394739483949395039513952395339543955395639573958395939603961396239633964396539663967396839693970397139723973397439753976397739783979398039813982398339843985398639873988398939903991399239933994399539963997399839994000400140024003400440054006400740084009401040114012401340144015401640174018401940204021402240234024402540264027402840294030403140324033403440354036403740384039404040414042404340444045404640474048404940504051405240534054405540564057405840594060406140624063406440654066406740684069407040714072407340744075407640774078407940804081408240834084408540864087408840894090409140924093409440954096409740984099410041014102410341044105410641074108410941104111411241134114411541164117411841194120412141224123412441254126412741284129413041314132413341344135413641374138413941404141414241434144414541464147414841494150415141524153415441554156415741584159416041614162416341644165416641674168416941704171417241734174417541764177417841794180418141824183418441854186418741884189419041914192419341944195419641974198419942004201420242034204420542064207420842094210421142124213421442154216421742184219422042214222422342244225422642274228422942304231423242334234423542364237423842394240424142424243424442454246424742484249425042514252425342544255425642574258425942604261426242634264426542664267426842694270427142724273427442754276427742784279428042814282428342844285428642874288428942904291429242934294429542964297429842994300430143024303430443054306430743084309431043114312431343144315431643174318431943204321432243234324432543264327432843294330433143324333433443354336433743384339434043414342434343444345434643474348434943504351435243534354435543564357435843594360436143624363436443654366436743684369437043714372437343744375437643774378437943804381438243834384438543864387438843894390439143924393439443954396439743984399440044014402440344044405440644074408440944104411441244134414441544164417441844194420442144224423442444254426442744284429443044314432443344344435443644374438443944404441444244434444444544464447444844494450445144524453445444554456445744584459446044614462446344644465446644674468446944704471447244734474447544764477447844794480448144824483448444854486448744884489449044914492449344944495449644974498449945004501450245034504450545064507450845094510451145124513451445154516451745184519452045214522452345244525452645274528452945304531453245334534453545364537453845394540454145424543454445454546454745484549455045514552455345544555455645574558455945604561456245634564456545664567456845694570457145724573457445754576457745784579458045814582458345844585458645874588458945904591459245934594459545964597459845994600460146024603460446054606460746084609461046114612461346144615461646174618461946204621462246234624462546264627462846294630463146324633463446354636463746384639464046414642464346444645464646474648464946504651465246534654465546564657465846594660466146624663466446654666466746684669467046714672467346744675467646774678467946804681468246834684468546864687468846894690469146924693469446954696469746984699470047014702470347044705470647074708470947104711471247134714471547164717471847194720472147224723472447254726472747284729473047314732473347344735473647374738473947404741474247434744474547464747474847494750475147524753475447554756475747584759476047614762476347644765476647674768476947704771477247734774477547764777477847794780478147824783478447854786478747884789479047914792479347944795479647974798479948004801480248034804480548064807480848094810481148124813481448154816481748184819482048214822482348244825482648274828482948304831483248334834483548364837483848394840484148424843484448454846484748484849485048514852485348544855485648574858485948604861486248634864486548664867486848694870487148724873487448754876487748784879488048814882488348844885488648874888488948904891489248934894489548964897489848994900490149024903490449054906490749084909491049114912491349144915491649174918491949204921492249234924492549264927492849294930493149324933493449354936493749384939494049414942494349444945494649474948494949504951495249534954495549564957495849594960496149624963496449654966496749684969497049714972497349744975497649774978497949804981498249834984498549864987498849894990499149924993499449954996499749984999500050015002500350045005500650075008500950105011501250135014501550165017501850195020502150225023502450255026502750285029503050315032503350345035503650375038503950405041504250435044504550465047504850495050505150525053505450555056505750585059506050615062506350645065506650675068506950705071507250735074507550765077507850795080508150825083508450855086508750885089509050915092509350945095509650975098509951005101510251035104510551065107510851095110511151125113511451155116511751185119512051215122512351245125512651275128512951305131513251335134513551365137513851395140514151425143514451455146514751485149515051515152515351545155515651575158515951605161516251635164516551665167516851695170517151725173517451755176517751785179518051815182518351845185518651875188518951905191519251935194519551965197519851995200520152025203520452055206520752085209521052115212521352145215521652175218521952205221522252235224522552265227522852295230523152325233523452355236523752385239524052415242524352445245524652475248524952505251525252535254525552565257525852595260526152625263526452655266526752685269527052715272527352745275527652775278527952805281528252835284528552865287528852895290529152925293529452955296529752985299530053015302530353045305530653075308530953105311531253135314531553165317531853195320532153225323532453255326532753285329533053315332533353345335533653375338533953405341534253435344534553465347534853495350535153525353535453555356535753585359536053615362536353645365536653675368536953705371537253735374537553765377537853795380538153825383538453855386538753885389539053915392539353945395539653975398539954005401540254035404540554065407540854095410541154125413541454155416541754185419542054215422542354245425542654275428542954305431543254335434543554365437543854395440544154425443544454455446544754485449545054515452545354545455545654575458545954605461546254635464546554665467546854695470547154725473547454755476547754785479548054815482548354845485548654875488548954905491549254935494549554965497549854995500550155025503
  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: sqlite.h.in,v 1.440 2009/04/06 15:55:04 drh Exp $
  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.13"
  97. #define SQLITE_VERSION_NUMBER 3006013
  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_MAIN_DB 0x00000100
  384. #define SQLITE_OPEN_TEMP_DB 0x00000200
  385. #define SQLITE_OPEN_TRANSIENT_DB 0x00000400
  386. #define SQLITE_OPEN_MAIN_JOURNAL 0x00000800
  387. #define SQLITE_OPEN_TEMP_JOURNAL 0x00001000
  388. #define SQLITE_OPEN_SUBJOURNAL 0x00002000
  389. #define SQLITE_OPEN_MASTER_JOURNAL 0x00004000
  390. #define SQLITE_OPEN_NOMUTEX 0x00008000
  391. #define SQLITE_OPEN_FULLMUTEX 0x00010000
  392. /*
  393. ** CAPI3REF: Device Characteristics {H10240} <H11120>
  394. **
  395. ** The xDeviceCapabilities method of the [sqlite3_io_methods]
  396. ** object returns an integer which is a vector of the these
  397. ** bit values expressing I/O characteristics of the mass storage
  398. ** device that holds the file that the [sqlite3_io_methods]
  399. ** refers to.
  400. **
  401. ** The SQLITE_IOCAP_ATOMIC property means that all writes of
  402. ** any size are atomic. The SQLITE_IOCAP_ATOMICnnn values
  403. ** mean that writes of blocks that are nnn bytes in size and
  404. ** are aligned to an address which is an integer multiple of
  405. ** nnn are atomic. The SQLITE_IOCAP_SAFE_APPEND value means
  406. ** that when data is appended to a file, the data is appended
  407. ** first then the size of the file is extended, never the other
  408. ** way around. The SQLITE_IOCAP_SEQUENTIAL property means that
  409. ** information is written to disk in the same order as calls
  410. ** to xWrite().
  411. */
  412. #define SQLITE_IOCAP_ATOMIC 0x00000001
  413. #define SQLITE_IOCAP_ATOMIC512 0x00000002
  414. #define SQLITE_IOCAP_ATOMIC1K 0x00000004
  415. #define SQLITE_IOCAP_ATOMIC2K 0x00000008
  416. #define SQLITE_IOCAP_ATOMIC4K 0x00000010
  417. #define SQLITE_IOCAP_ATOMIC8K 0x00000020
  418. #define SQLITE_IOCAP_ATOMIC16K 0x00000040
  419. #define SQLITE_IOCAP_ATOMIC32K 0x00000080
  420. #define SQLITE_IOCAP_ATOMIC64K 0x00000100
  421. #define SQLITE_IOCAP_SAFE_APPEND 0x00000200
  422. #define SQLITE_IOCAP_SEQUENTIAL 0x00000400
  423. /*
  424. ** CAPI3REF: File Locking Levels {H10250} <H11120> <H11310>
  425. **
  426. ** SQLite uses one of these integer values as the second
  427. ** argument to calls it makes to the xLock() and xUnlock() methods
  428. ** of an [sqlite3_io_methods] object.
  429. */
  430. #define SQLITE_LOCK_NONE 0
  431. #define SQLITE_LOCK_SHARED 1
  432. #define SQLITE_LOCK_RESERVED 2
  433. #define SQLITE_LOCK_PENDING 3
  434. #define SQLITE_LOCK_EXCLUSIVE 4
  435. /*
  436. ** CAPI3REF: Synchronization Type Flags {H10260} <H11120>
  437. **
  438. ** When SQLite invokes the xSync() method of an
  439. ** [sqlite3_io_methods] object it uses a combination of
  440. ** these integer values as the second argument.
  441. **
  442. ** When the SQLITE_SYNC_DATAONLY flag is used, it means that the
  443. ** sync operation only needs to flush data to mass storage. Inode
  444. ** information need not be flushed. If the lower four bits of the flag
  445. ** equal SQLITE_SYNC_NORMAL, that means to use normal fsync() semantics.
  446. ** If the lower four bits equal SQLITE_SYNC_FULL, that 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 successful call to [sqlite3_open()], [sqlite3_open_v2()] or
  2176. ** [sqlite3_open16()]. The database connection must not have been closed.
  2177. **
  2178. ** The second argument, "zSql", is the statement to be compiled, encoded
  2179. ** as either UTF-8 or UTF-16. The sqlite3_prepare() and sqlite3_prepare_v2()
  2180. ** interfaces use UTF-8, and sqlite3_prepare16() and sqlite3_prepare16_v2()
  2181. ** use UTF-16.
  2182. **
  2183. ** If the nByte argument is less than zero, then zSql is read up to the
  2184. ** first zero terminator. If nByte is non-negative, then it is the maximum
  2185. ** number of bytes read from zSql. When nByte is non-negative, the
  2186. ** zSql string ends at either the first '\000' or '\u0000' character or
  2187. ** the nByte-th byte, whichever comes first. If the caller knows
  2188. ** that the supplied string is nul-terminated, then there is a small
  2189. ** performance advantage to be gained by passing an nByte parameter that
  2190. ** is equal to the number of bytes in the input string <i>including</i>
  2191. ** the nul-terminator bytes.
  2192. **
  2193. ** If pzTail is not NULL then *pzTail is made to point to the first byte
  2194. ** past the end of the first SQL statement in zSql. These routines only
  2195. ** compile the first statement in zSql, so *pzTail is left pointing to
  2196. ** what remains uncompiled.
  2197. **
  2198. ** *ppStmt is left pointing to a compiled [prepared statement] that can be
  2199. ** executed using [sqlite3_step()]. If there is an error, *ppStmt is set
  2200. ** to NULL. If the input text contains no SQL (if the input is an empty
  2201. ** string or a comment) then *ppStmt is set to NULL.
  2202. ** The calling procedure is responsible for deleting the compiled
  2203. ** SQL statement using [sqlite3_finalize()] after it has finished with it.
  2204. ** ppStmt may not be NULL.
  2205. **
  2206. ** On success, [SQLITE_OK] is returned, otherwise an [error code] is returned.
  2207. **
  2208. ** The sqlite3_prepare_v2() and sqlite3_prepare16_v2() interfaces are
  2209. ** recommended for all new programs. The two older interfaces are retained
  2210. ** for backwards compatibility, but their use is discouraged.
  2211. ** In the "v2" interfaces, the prepared statement
  2212. ** that is returned (the [sqlite3_stmt] object) contains a copy of the
  2213. ** original SQL text. This causes the [sqlite3_step()] interface to
  2214. ** behave a differently in two ways:
  2215. **
  2216. ** <ol>
  2217. ** <li>
  2218. ** If the database schema changes, instead of returning [SQLITE_SCHEMA] as it
  2219. ** always used to do, [sqlite3_step()] will automatically recompile the SQL
  2220. ** statement and try to run it again. If the schema has changed in
  2221. ** a way that makes the statement no longer valid, [sqlite3_step()] will still
  2222. ** return [SQLITE_SCHEMA]. But unlike the legacy behavior, [SQLITE_SCHEMA] is
  2223. ** now a fatal error. Calling [sqlite3_prepare_v2()] again will not make the
  2224. ** error go away. Note: use [sqlite3_errmsg()] to find the text
  2225. ** of the parsing error that results in an [SQLITE_SCHEMA] return.
  2226. ** </li>
  2227. **
  2228. ** <li>
  2229. ** When an error occurs, [sqlite3_step()] will return one of the detailed
  2230. ** [error codes] or [extended error codes]. The legacy behavior was that
  2231. ** [sqlite3_step()] would only return a generic [SQLITE_ERROR] result code
  2232. ** and you would have to make a second call to [sqlite3_reset()] in order
  2233. ** to find the underlying cause of the problem. With the "v2" prepare
  2234. ** interfaces, the underlying reason for the error is returned immediately.
  2235. ** </li>
  2236. ** </ol>
  2237. **
  2238. ** Requirements:
  2239. ** [H13011] [H13012] [H13013] [H13014] [H13015] [H13016] [H13019] [H13021]
  2240. **
  2241. */
  2242. int sqlite3_prepare(
  2243. sqlite3 *db, /* Database handle */
  2244. const char *zSql, /* SQL statement, UTF-8 encoded */
  2245. int nByte, /* Maximum length of zSql in bytes. */
  2246. sqlite3_stmt **ppStmt, /* OUT: Statement handle */
  2247. const char **pzTail /* OUT: Pointer to unused portion of zSql */
  2248. );
  2249. int sqlite3_prepare_v2(
  2250. sqlite3 *db, /* Database handle */
  2251. const char *zSql, /* SQL statement, UTF-8 encoded */
  2252. int nByte, /* Maximum length of zSql in bytes. */
  2253. sqlite3_stmt **ppStmt, /* OUT: Statement handle */
  2254. const char **pzTail /* OUT: Pointer to unused portion of zSql */
  2255. );
  2256. int sqlite3_prepare16(
  2257. sqlite3 *db, /* Database handle */
  2258. const void *zSql, /* SQL statement, UTF-16 encoded */
  2259. int nByte, /* Maximum length of zSql in bytes. */
  2260. sqlite3_stmt **ppStmt, /* OUT: Statement handle */
  2261. const void **pzTail /* OUT: Pointer to unused portion of zSql */
  2262. );
  2263. int sqlite3_prepare16_v2(
  2264. sqlite3 *db, /* Database handle */
  2265. const void *zSql, /* SQL statement, UTF-16 encoded */
  2266. int nByte, /* Maximum length of zSql in bytes. */
  2267. sqlite3_stmt **ppStmt, /* OUT: Statement handle */
  2268. const void **pzTail /* OUT: Pointer to unused portion of zSql */
  2269. );
  2270. /*
  2271. ** CAPI3REF: Retrieving Statement SQL {H13100} <H13000>
  2272. **
  2273. ** This interface can be used to retrieve a saved copy of the original
  2274. ** SQL text used to create a [prepared statement] if that statement was
  2275. ** compiled using either [sqlite3_prepare_v2()] or [sqlite3_prepare16_v2()].
  2276. **
  2277. ** Requirements:
  2278. ** [H13101] [H13102] [H13103]
  2279. */
  2280. const char *sqlite3_sql(sqlite3_stmt *pStmt);
  2281. /*
  2282. ** CAPI3REF: Dynamically Typed Value Object {H15000} <S20200>
  2283. ** KEYWORDS: {protected sqlite3_value} {unprotected sqlite3_value}
  2284. **
  2285. ** SQLite uses the sqlite3_value object to represent all values
  2286. ** that can be stored in a database table. SQLite uses dynamic typing
  2287. ** for the values it stores. Values stored in sqlite3_value objects
  2288. ** can be integers, floating point values, strings, BLOBs, or NULL.
  2289. **
  2290. ** An sqlite3_value object may be either "protected" or "unprotected".
  2291. ** Some interfaces require a protected sqlite3_value. Other interfaces
  2292. ** will accept either a protected or an unprotected sqlite3_value.
  2293. ** Every interface that accepts sqlite3_value arguments specifies
  2294. ** whether or not it requires a protected sqlite3_value.
  2295. **
  2296. ** The terms "protected" and "unprotected" refer to whether or not
  2297. ** a mutex is held. A internal mutex is held for a protected
  2298. ** sqlite3_value object but no mutex is held for an unprotected
  2299. ** sqlite3_value object. If SQLite is compiled to be single-threaded
  2300. ** (with [SQLITE_THREADSAFE=0] and with [sqlite3_threadsafe()] returning 0)
  2301. ** or if SQLite is run in one of reduced mutex modes
  2302. ** [SQLITE_CONFIG_SINGLETHREAD] or [SQLITE_CONFIG_MULTITHREAD]
  2303. ** then there is no distinction between protected and unprotected
  2304. ** sqlite3_value objects and they can be used interchangeably. However,
  2305. ** for maximum code portability it is recommended that applications
  2306. ** still make the distinction between between protected and unprotected
  2307. ** sqlite3_value objects even when not strictly required.
  2308. **
  2309. ** The sqlite3_value objects that are passed as parameters into the
  2310. ** implementation of [application-defined SQL functions] are protected.
  2311. ** The sqlite3_value object returned by
  2312. ** [sqlite3_column_value()] is unprotected.
  2313. ** Unprotected sqlite3_value objects may only be used with
  2314. ** [sqlite3_result_value()] and [sqlite3_bind_value()].
  2315. ** The [sqlite3_value_blob | sqlite3_value_type()] family of
  2316. ** interfaces require protected sqlite3_value objects.
  2317. */
  2318. typedef struct Mem sqlite3_value;
  2319. /*
  2320. ** CAPI3REF: SQL Function Context Object {H16001} <S20200>
  2321. **
  2322. ** The context in which an SQL function executes is stored in an
  2323. ** sqlite3_context object. A pointer to an sqlite3_context object
  2324. ** is always first parameter to [application-defined SQL functions].
  2325. ** The application-defined SQL function implementation will pass this
  2326. ** pointer through into calls to [sqlite3_result_int | sqlite3_result()],
  2327. ** [sqlite3_aggregate_context()], [sqlite3_user_data()],
  2328. ** [sqlite3_context_db_handle()], [sqlite3_get_auxdata()],
  2329. ** and/or [sqlite3_set_auxdata()].
  2330. */
  2331. typedef struct sqlite3_context sqlite3_context;
  2332. /*
  2333. ** CAPI3REF: Binding Values To Prepared Statements {H13500} <S70300>
  2334. ** KEYWORDS: {host parameter} {host parameters} {host parameter name}
  2335. ** KEYWORDS: {SQL parameter} {SQL parameters} {parameter binding}
  2336. **
  2337. ** In the SQL strings input to [sqlite3_prepare_v2()] and its variants,
  2338. ** literals may be replaced by a [parameter] in one of these forms:
  2339. **
  2340. ** <ul>
  2341. ** <li> ?
  2342. ** <li> ?NNN
  2343. ** <li> :VVV
  2344. ** <li> @VVV
  2345. ** <li> $VVV
  2346. ** </ul>
  2347. **
  2348. ** In the parameter forms shown above NNN is an integer literal,
  2349. ** and VVV is an alpha-numeric parameter name. The values of these
  2350. ** parameters (also called "host parameter names" or "SQL parameters")
  2351. ** can be set using the sqlite3_bind_*() routines defined here.
  2352. **
  2353. ** The first argument to the sqlite3_bind_*() routines is always
  2354. ** a pointer to the [sqlite3_stmt] object returned from
  2355. ** [sqlite3_prepare_v2()] or its variants.
  2356. **
  2357. ** The second argument is the index of the SQL parameter to be set.
  2358. ** The leftmost SQL parameter has an index of 1. When the same named
  2359. ** SQL parameter is used more than once, second and subsequent
  2360. ** occurrences have the same index as the first occurrence.
  2361. ** The index for named parameters can be looked up using the
  2362. ** [sqlite3_bind_parameter_index()] API if desired. The index
  2363. ** for "?NNN" parameters is the value of NNN.
  2364. ** The NNN value must be between 1 and the [sqlite3_limit()]
  2365. ** parameter [SQLITE_LIMIT_VARIABLE_NUMBER] (default value: 999).
  2366. **
  2367. ** The third argument is the value to bind to the parameter.
  2368. **
  2369. ** In those routines that have a fourth argument, its value is the
  2370. ** number of bytes in the parameter. To be clear: the value is the
  2371. ** number of <u>bytes</u> in the value, not the number of characters.
  2372. ** If the fourth parameter is negative, the length of the string is
  2373. ** the number of bytes up to the first zero terminator.
  2374. **
  2375. ** The fifth argument to sqlite3_bind_blob(), sqlite3_bind_text(), and
  2376. ** sqlite3_bind_text16() is a destructor used to dispose of the BLOB or
  2377. ** string after SQLite has finished with it. If the fifth argument is
  2378. ** the special value [SQLITE_STATIC], then SQLite assumes that the
  2379. ** information is in static, unmanaged space and does not need to be freed.
  2380. ** If the fifth argument has the value [SQLITE_TRANSIENT], then
  2381. ** SQLite makes its own private copy of the data immediately, before
  2382. ** the sqlite3_bind_*() routine returns.
  2383. **
  2384. ** The sqlite3_bind_zeroblob() routine binds a BLOB of length N that
  2385. ** is filled with zeroes. A zeroblob uses a fixed amount of memory
  2386. ** (just an integer to hold its size) while it is being processed.
  2387. ** Zeroblobs are intended to serve as placeholders for BLOBs whose
  2388. ** content is later written using
  2389. ** [sqlite3_blob_open | incremental BLOB I/O] routines.
  2390. ** A negative value for the zeroblob results in a zero-length BLOB.
  2391. **
  2392. ** The sqlite3_bind_*() routines must be called after
  2393. ** [sqlite3_prepare_v2()] (and its variants) or [sqlite3_reset()] and
  2394. ** before [sqlite3_step()].
  2395. ** Bindings are not cleared by the [sqlite3_reset()] routine.
  2396. ** Unbound parameters are interpreted as NULL.
  2397. **
  2398. ** These routines return [SQLITE_OK] on success or an error code if
  2399. ** anything goes wrong. [SQLITE_RANGE] is returned if the parameter
  2400. ** index is out of range. [SQLITE_NOMEM] is returned if malloc() fails.
  2401. ** [SQLITE_MISUSE] might be returned if these routines are called on a
  2402. ** virtual machine that is the wrong state or which has already been finalized.
  2403. ** Detection of misuse is unreliable. Applications should not depend
  2404. ** on SQLITE_MISUSE returns. SQLITE_MISUSE is intended to indicate a
  2405. ** a logic error in the application. Future versions of SQLite might
  2406. ** panic rather than return SQLITE_MISUSE.
  2407. **
  2408. ** See also: [sqlite3_bind_parameter_count()],
  2409. ** [sqlite3_bind_parameter_name()], and [sqlite3_bind_parameter_index()].
  2410. **
  2411. ** Requirements:
  2412. ** [H13506] [H13509] [H13512] [H13515] [H13518] [H13521] [H13524] [H13527]
  2413. ** [H13530] [H13533] [H13536] [H13539] [H13542] [H13545] [H13548] [H13551]
  2414. **
  2415. */
  2416. int sqlite3_bind_blob(sqlite3_stmt*, int, const void*, int n, void(*)(void*));
  2417. int sqlite3_bind_double(sqlite3_stmt*, int, double);
  2418. int sqlite3_bind_int(sqlite3_stmt*, int, int);
  2419. int sqlite3_bind_int64(sqlite3_stmt*, int, sqlite3_int64);
  2420. int sqlite3_bind_null(sqlite3_stmt*, int);
  2421. int sqlite3_bind_text(sqlite3_stmt*, int, const char*, int n, void(*)(void*));
  2422. int sqlite3_bind_text16(sqlite3_stmt*, int, const void*, int, void(*)(void*));
  2423. int sqlite3_bind_value(sqlite3_stmt*, int, const sqlite3_value*);
  2424. int sqlite3_bind_zeroblob(sqlite3_stmt*, int, int n);
  2425. /*
  2426. ** CAPI3REF: Number Of SQL Parameters {H13600} <S70300>
  2427. **
  2428. ** This routine can be used to find the number of [SQL parameters]
  2429. ** in a [prepared statement]. SQL parameters are tokens of the
  2430. ** form "?", "?NNN", ":AAA", "$AAA", or "@AAA" that serve as
  2431. ** placeholders for values that are [sqlite3_bind_blob | bound]
  2432. ** to the parameters at a later time.
  2433. **
  2434. ** This routine actually returns the index of the largest (rightmost)
  2435. ** parameter. For all forms except ?NNN, this will correspond to the
  2436. ** number of unique parameters. If parameters of the ?NNN are used,
  2437. ** there may be gaps in the list.
  2438. **
  2439. ** See also: [sqlite3_bind_blob|sqlite3_bind()],
  2440. ** [sqlite3_bind_parameter_name()], and
  2441. ** [sqlite3_bind_parameter_index()].
  2442. **
  2443. ** Requirements:
  2444. ** [H13601]
  2445. */
  2446. int sqlite3_bind_parameter_count(sqlite3_stmt*);
  2447. /*
  2448. ** CAPI3REF: Name Of A Host Parameter {H13620} <S70300>
  2449. **
  2450. ** This routine returns a pointer to the name of the n-th
  2451. ** [SQL parameter] in a [prepared statement].
  2452. ** SQL parameters of the form "?NNN" or ":AAA" or "@AAA" or "$AAA"
  2453. ** have a name which is the string "?NNN" or ":AAA" or "@AAA" or "$AAA"
  2454. ** respectively.
  2455. ** In other words, the initial ":" or "$" or "@" or "?"
  2456. ** is included as part of the name.
  2457. ** Parameters of the form "?" without a following integer have no name
  2458. ** and are also referred to as "anonymous parameters".
  2459. **
  2460. ** The first host parameter has an index of 1, not 0.
  2461. **
  2462. ** If the value n is out of range or if the n-th parameter is
  2463. ** nameless, then NULL is returned. The returned string is
  2464. ** always in UTF-8 encoding even if the named parameter was
  2465. ** originally specified as UTF-16 in [sqlite3_prepare16()] or
  2466. ** [sqlite3_prepare16_v2()].
  2467. **
  2468. ** See also: [sqlite3_bind_blob|sqlite3_bind()],
  2469. ** [sqlite3_bind_parameter_count()], and
  2470. ** [sqlite3_bind_parameter_index()].
  2471. **
  2472. ** Requirements:
  2473. ** [H13621]
  2474. */
  2475. const char *sqlite3_bind_parameter_name(sqlite3_stmt*, int);
  2476. /*
  2477. ** CAPI3REF: Index Of A Parameter With A Given Name {H13640} <S70300>
  2478. **
  2479. ** Return the index of an SQL parameter given its name. The
  2480. ** index value returned is suitable for use as the second
  2481. ** parameter to [sqlite3_bind_blob|sqlite3_bind()]. A zero
  2482. ** is returned if no matching parameter is found. The parameter
  2483. ** name must be given in UTF-8 even if the original statement
  2484. ** was prepared from UTF-16 text using [sqlite3_prepare16_v2()].
  2485. **
  2486. ** See also: [sqlite3_bind_blob|sqlite3_bind()],
  2487. ** [sqlite3_bind_parameter_count()], and
  2488. ** [sqlite3_bind_parameter_index()].
  2489. **
  2490. ** Requirements:
  2491. ** [H13641]
  2492. */
  2493. int sqlite3_bind_parameter_index(sqlite3_stmt*, const char *zName);
  2494. /*
  2495. ** CAPI3REF: Reset All Bindings On A Prepared Statement {H13660} <S70300>
  2496. **
  2497. ** Contrary to the intuition of many, [sqlite3_reset()] does not reset
  2498. ** the [sqlite3_bind_blob | bindings] on a [prepared statement].
  2499. ** Use this routine to reset all host parameters to NULL.
  2500. **
  2501. ** Requirements:
  2502. ** [H13661]
  2503. */
  2504. int sqlite3_clear_bindings(sqlite3_stmt*);
  2505. /*
  2506. ** CAPI3REF: Number Of Columns In A Result Set {H13710} <S10700>
  2507. **
  2508. ** Return the number of columns in the result set returned by the
  2509. ** [prepared statement]. This routine returns 0 if pStmt is an SQL
  2510. ** statement that does not return data (for example an [UPDATE]).
  2511. **
  2512. ** Requirements:
  2513. ** [H13711]
  2514. */
  2515. int sqlite3_column_count(sqlite3_stmt *pStmt);
  2516. /*
  2517. ** CAPI3REF: Column Names In A Result Set {H13720} <S10700>
  2518. **
  2519. ** These routines return the name assigned to a particular column
  2520. ** in the result set of a [SELECT] statement. The sqlite3_column_name()
  2521. ** interface returns a pointer to a zero-terminated UTF-8 string
  2522. ** and sqlite3_column_name16() returns a pointer to a zero-terminated
  2523. ** UTF-16 string. The first parameter is the [prepared statement]
  2524. ** that implements the [SELECT] statement. The second parameter is the
  2525. ** column number. The leftmost column is number 0.
  2526. **
  2527. ** The returned string pointer is valid until either the [prepared statement]
  2528. ** is destroyed by [sqlite3_finalize()] or until the next call to
  2529. ** sqlite3_column_name() or sqlite3_column_name16() on the same column.
  2530. **
  2531. ** If sqlite3_malloc() fails during the processing of either routine
  2532. ** (for example during a conversion from UTF-8 to UTF-16) then a
  2533. ** NULL pointer is returned.
  2534. **
  2535. ** The name of a result column is the value of the "AS" clause for
  2536. ** that column, if there is an AS clause. If there is no AS clause
  2537. ** then the name of the column is unspecified and may change from
  2538. ** one release of SQLite to the next.
  2539. **
  2540. ** Requirements:
  2541. ** [H13721] [H13723] [H13724] [H13725] [H13726] [H13727]
  2542. */
  2543. const char *sqlite3_column_name(sqlite3_stmt*, int N);
  2544. const void *sqlite3_column_name16(sqlite3_stmt*, int N);
  2545. /*
  2546. ** CAPI3REF: Source Of Data In A Query Result {H13740} <S10700>
  2547. **
  2548. ** These routines provide a means to determine what column of what
  2549. ** table in which database a result of a [SELECT] statement comes from.
  2550. ** The name of the database or table or column can be returned as
  2551. ** either a UTF-8 or UTF-16 string. The _database_ routines return
  2552. ** the database name, the _table_ routines return the table name, and
  2553. ** the origin_ routines return the column name.
  2554. ** The returned string is valid until the [prepared statement] is destroyed
  2555. ** using [sqlite3_finalize()] or until the same information is requested
  2556. ** again in a different encoding.
  2557. **
  2558. ** The names returned are the original un-aliased names of the
  2559. ** database, table, and column.
  2560. **
  2561. ** The first argument to the following calls is a [prepared statement].
  2562. ** These functions return information about the Nth column returned by
  2563. ** the statement, where N is the second function argument.
  2564. **
  2565. ** If the Nth column returned by the statement is an expression or
  2566. ** subquery and is not a column value, then all of these functions return
  2567. ** NULL. These routine might also return NULL if a memory allocation error
  2568. ** occurs. Otherwise, they return the name of the attached database, table
  2569. ** and column that query result column was extracted from.
  2570. **
  2571. ** As with all other SQLite APIs, those postfixed with "16" return
  2572. ** UTF-16 encoded strings, the other functions return UTF-8. {END}
  2573. **
  2574. ** These APIs are only available if the library was compiled with the
  2575. ** [SQLITE_ENABLE_COLUMN_METADATA] C-preprocessor symbol defined.
  2576. **
  2577. ** {A13751}
  2578. ** If two or more threads call one or more of these routines against the same
  2579. ** prepared statement and column at the same time then the results are
  2580. ** undefined.
  2581. **
  2582. ** Requirements:
  2583. ** [H13741] [H13742] [H13743] [H13744] [H13745] [H13746] [H13748]
  2584. **
  2585. ** If two or more threads call one or more
  2586. ** [sqlite3_column_database_name | column metadata interfaces]
  2587. ** for the same [prepared statement] and result column
  2588. ** at the same time then the results are undefined.
  2589. */
  2590. const char *sqlite3_column_database_name(sqlite3_stmt*,int);
  2591. const void *sqlite3_column_database_name16(sqlite3_stmt*,int);
  2592. const char *sqlite3_column_table_name(sqlite3_stmt*,int);
  2593. const void *sqlite3_column_table_name16(sqlite3_stmt*,int);
  2594. const char *sqlite3_column_origin_name(sqlite3_stmt*,int);
  2595. const void *sqlite3_column_origin_name16(sqlite3_stmt*,int);
  2596. /*
  2597. ** CAPI3REF: Declared Datatype Of A Query Result {H13760} <S10700>
  2598. **
  2599. ** The first parameter is a [prepared statement].
  2600. ** If this statement is a [SELECT] statement and the Nth column of the
  2601. ** returned result set of that [SELECT] is a table column (not an
  2602. ** expression or subquery) then the declared type of the table
  2603. ** column is returned. If the Nth column of the result set is an
  2604. ** expression or subquery, then a NULL pointer is returned.
  2605. ** The returned string is always UTF-8 encoded. {END}
  2606. **
  2607. ** For example, given the database schema:
  2608. **
  2609. ** CREATE TABLE t1(c1 VARIANT);
  2610. **
  2611. ** and the following statement to be compiled:
  2612. **
  2613. ** SELECT c1 + 1, c1 FROM t1;
  2614. **
  2615. ** this routine would return the string "VARIANT" for the second result
  2616. ** column (i==1), and a NULL pointer for the first result column (i==0).
  2617. **
  2618. ** SQLite uses dynamic run-time typing. So just because a column
  2619. ** is declared to contain a particular type does not mean that the
  2620. ** data stored in that column is of the declared type. SQLite is
  2621. ** strongly typed, but the typing is dynamic not static. Type
  2622. ** is associated with individual values, not with the containers
  2623. ** used to hold those values.
  2624. **
  2625. ** Requirements:
  2626. ** [H13761] [H13762] [H13763]
  2627. */
  2628. const char *sqlite3_column_decltype(sqlite3_stmt*,int);
  2629. const void *sqlite3_column_decltype16(sqlite3_stmt*,int);
  2630. /*
  2631. ** CAPI3REF: Evaluate An SQL Statement {H13200} <S10000>
  2632. **
  2633. ** After a [prepared statement] has been prepared using either
  2634. ** [sqlite3_prepare_v2()] or [sqlite3_prepare16_v2()] or one of the legacy
  2635. ** interfaces [sqlite3_prepare()] or [sqlite3_prepare16()], this function
  2636. ** must be called one or more times to evaluate the statement.
  2637. **
  2638. ** The details of the behavior of the sqlite3_step() interface depend
  2639. ** on whether the statement was prepared using the newer "v2" interface
  2640. ** [sqlite3_prepare_v2()] and [sqlite3_prepare16_v2()] or the older legacy
  2641. ** interface [sqlite3_prepare()] and [sqlite3_prepare16()]. The use of the
  2642. ** new "v2" interface is recommended for new applications but the legacy
  2643. ** interface will continue to be supported.
  2644. **
  2645. ** In the legacy interface, the return value will be either [SQLITE_BUSY],
  2646. ** [SQLITE_DONE], [SQLITE_ROW], [SQLITE_ERROR], or [SQLITE_MISUSE].
  2647. ** With the "v2" interface, any of the other [result codes] or
  2648. ** [extended result codes] might be returned as well.
  2649. **
  2650. ** [SQLITE_BUSY] means that the database engine was unable to acquire the
  2651. ** database locks it needs to do its job. If the statement is a [COMMIT]
  2652. ** or occurs outside of an explicit transaction, then you can retry the
  2653. ** statement. If the statement is not a [COMMIT] and occurs within a
  2654. ** explicit transaction then you should rollback the transaction before
  2655. ** continuing.
  2656. **
  2657. ** [SQLITE_DONE] means that the statement has finished executing
  2658. ** successfully. sqlite3_step() should not be called again on this virtual
  2659. ** machine without first calling [sqlite3_reset()] to reset the virtual
  2660. ** machine back to its initial state.
  2661. **
  2662. ** If the SQL statement being executed returns any data, then [SQLITE_ROW]
  2663. ** is returned each time a new row of data is ready for processing by the
  2664. ** caller. The values may be accessed using the [column access functions].
  2665. ** sqlite3_step() is called again to retrieve the next row of data.
  2666. **
  2667. ** [SQLITE_ERROR] means that a run-time error (such as a constraint
  2668. ** violation) has occurred. sqlite3_step() should not be called again on
  2669. ** the VM. More information may be found by calling [sqlite3_errmsg()].
  2670. ** With the legacy interface, a more specific error code (for example,
  2671. ** [SQLITE_INTERRUPT], [SQLITE_SCHEMA], [SQLITE_CORRUPT], and so forth)
  2672. ** can be obtained by calling [sqlite3_reset()] on the
  2673. ** [prepared statement]. In the "v2" interface,
  2674. ** the more specific error code is returned directly by sqlite3_step().
  2675. **
  2676. ** [SQLITE_MISUSE] means that the this routine was called inappropriately.
  2677. ** Perhaps it was called on a [prepared statement] that has
  2678. ** already been [sqlite3_finalize | finalized] or on one that had
  2679. ** previously returned [SQLITE_ERROR] or [SQLITE_DONE]. Or it could
  2680. ** be the case that the same database connection is being used by two or
  2681. ** more threads at the same moment in time.
  2682. **
  2683. ** <b>Goofy Interface Alert:</b> In the legacy interface, the sqlite3_step()
  2684. ** API always returns a generic error code, [SQLITE_ERROR], following any
  2685. ** error other than [SQLITE_BUSY] and [SQLITE_MISUSE]. You must call
  2686. ** [sqlite3_reset()] or [sqlite3_finalize()] in order to find one of the
  2687. ** specific [error codes] that better describes the error.
  2688. ** We admit that this is a goofy design. The problem has been fixed
  2689. ** with the "v2" interface. If you prepare all of your SQL statements
  2690. ** using either [sqlite3_prepare_v2()] or [sqlite3_prepare16_v2()] instead
  2691. ** of the legacy [sqlite3_prepare()] and [sqlite3_prepare16()] interfaces,
  2692. ** then the more specific [error codes] are returned directly
  2693. ** by sqlite3_step(). The use of the "v2" interface is recommended.
  2694. **
  2695. ** Requirements:
  2696. ** [H13202] [H15304] [H15306] [H15308] [H15310]
  2697. */
  2698. int sqlite3_step(sqlite3_stmt*);
  2699. /*
  2700. ** CAPI3REF: Number of columns in a result set {H13770} <S10700>
  2701. **
  2702. ** Returns the number of values in the current row of the result set.
  2703. **
  2704. ** Requirements:
  2705. ** [H13771] [H13772]
  2706. */
  2707. int sqlite3_data_count(sqlite3_stmt *pStmt);
  2708. /*
  2709. ** CAPI3REF: Fundamental Datatypes {H10265} <S10110><S10120>
  2710. ** KEYWORDS: SQLITE_TEXT
  2711. **
  2712. ** {H10266} Every value in SQLite has one of five fundamental datatypes:
  2713. **
  2714. ** <ul>
  2715. ** <li> 64-bit signed integer
  2716. ** <li> 64-bit IEEE floating point number
  2717. ** <li> string
  2718. ** <li> BLOB
  2719. ** <li> NULL
  2720. ** </ul> {END}
  2721. **
  2722. ** These constants are codes for each of those types.
  2723. **
  2724. ** Note that the SQLITE_TEXT constant was also used in SQLite version 2
  2725. ** for a completely different meaning. Software that links against both
  2726. ** SQLite version 2 and SQLite version 3 should use SQLite3_TEXT, not
  2727. ** SQLITE_TEXT.
  2728. */
  2729. #define SQLITE_INTEGER 1
  2730. #define SQLITE_FLOAT 2
  2731. #define SQLITE_BLOB 4
  2732. #define SQLITE_NULL 5
  2733. #ifdef SQLITE_TEXT
  2734. # undef SQLITE_TEXT
  2735. #else
  2736. # define SQLITE_TEXT 3
  2737. #endif
  2738. #define SQLite3_TEXT 3
  2739. /*
  2740. ** CAPI3REF: Result Values From A Query {H13800} <S10700>
  2741. ** KEYWORDS: {column access functions}
  2742. **
  2743. ** These routines form the "result set query" interface.
  2744. **
  2745. ** These routines return information about a single column of the current
  2746. ** result row of a query. In every case the first argument is a pointer
  2747. ** to the [prepared statement] that is being evaluated (the [sqlite3_stmt*]
  2748. ** that was returned from [sqlite3_prepare_v2()] or one of its variants)
  2749. ** and the second argument is the index of the column for which information
  2750. ** should be returned. The leftmost column of the result set has the index 0.
  2751. **
  2752. ** If the SQL statement does not currently point to a valid row, or if the
  2753. ** column index is out of range, the result is undefined.
  2754. ** These routines may only be called when the most recent call to
  2755. ** [sqlite3_step()] has returned [SQLITE_ROW] and neither
  2756. ** [sqlite3_reset()] nor [sqlite3_finalize()] have been called subsequently.
  2757. ** If any of these routines are called after [sqlite3_reset()] or
  2758. ** [sqlite3_finalize()] or after [sqlite3_step()] has returned
  2759. ** something other than [SQLITE_ROW], the results are undefined.
  2760. ** If [sqlite3_step()] or [sqlite3_reset()] or [sqlite3_finalize()]
  2761. ** are called from a different thread while any of these routines
  2762. ** are pending, then the results are undefined.
  2763. **
  2764. ** The sqlite3_column_type() routine returns the
  2765. ** [SQLITE_INTEGER | datatype code] for the initial data type
  2766. ** of the result column. The returned value is one of [SQLITE_INTEGER],
  2767. ** [SQLITE_FLOAT], [SQLITE_TEXT], [SQLITE_BLOB], or [SQLITE_NULL]. The value
  2768. ** returned by sqlite3_column_type() is only meaningful if no type
  2769. ** conversions have occurred as described below. After a type conversion,
  2770. ** the value returned by sqlite3_column_type() is undefined. Future
  2771. ** versions of SQLite may change the behavior of sqlite3_column_type()
  2772. ** following a type conversion.
  2773. **
  2774. ** If the result is a BLOB or UTF-8 string then the sqlite3_column_bytes()
  2775. ** routine returns the number of bytes in that BLOB or string.
  2776. ** If the result is a UTF-16 string, then sqlite3_column_bytes() converts
  2777. ** the string to UTF-8 and then returns the number of bytes.
  2778. ** If the result is a numeric value then sqlite3_column_bytes() uses
  2779. ** [sqlite3_snprintf()] to convert that value to a UTF-8 string and returns
  2780. ** the number of bytes in that string.
  2781. ** The value returned does not include the zero terminator at the end
  2782. ** of the string. For clarity: the value returned is the number of
  2783. ** bytes in the string, not the number of characters.
  2784. **
  2785. ** Strings returned by sqlite3_column_text() and sqlite3_column_text16(),
  2786. ** even empty strings, are always zero terminated. The return
  2787. ** value from sqlite3_column_blob() for a zero-length BLOB is an arbitrary
  2788. ** pointer, possibly even a NULL pointer.
  2789. **
  2790. ** The sqlite3_column_bytes16() routine is similar to sqlite3_column_bytes()
  2791. ** but leaves the result in UTF-16 in native byte order instead of UTF-8.
  2792. ** The zero terminator is not included in this count.
  2793. **
  2794. ** The object returned by [sqlite3_column_value()] is an
  2795. ** [unprotected sqlite3_value] object. An unprotected sqlite3_value object
  2796. ** may only be used with [sqlite3_bind_value()] and [sqlite3_result_value()].
  2797. ** If the [unprotected sqlite3_value] object returned by
  2798. ** [sqlite3_column_value()] is used in any other way, including calls
  2799. ** to routines like [sqlite3_value_int()], [sqlite3_value_text()],
  2800. ** or [sqlite3_value_bytes()], then the behavior is undefined.
  2801. **
  2802. ** These routines attempt to convert the value where appropriate. For
  2803. ** example, if the internal representation is FLOAT and a text result
  2804. ** is requested, [sqlite3_snprintf()] is used internally to perform the
  2805. ** conversion automatically. The following table details the conversions
  2806. ** that are applied:
  2807. **
  2808. ** <blockquote>
  2809. ** <table border="1">
  2810. ** <tr><th> Internal<br>Type <th> Requested<br>Type <th> Conversion
  2811. **
  2812. ** <tr><td> NULL <td> INTEGER <td> Result is 0
  2813. ** <tr><td> NULL <td> FLOAT <td> Result is 0.0
  2814. ** <tr><td> NULL <td> TEXT <td> Result is NULL pointer
  2815. ** <tr><td> NULL <td> BLOB <td> Result is NULL pointer
  2816. ** <tr><td> INTEGER <td> FLOAT <td> Convert from integer to float
  2817. ** <tr><td> INTEGER <td> TEXT <td> ASCII rendering of the integer
  2818. ** <tr><td> INTEGER <td> BLOB <td> Same as INTEGER->TEXT
  2819. ** <tr><td> FLOAT <td> INTEGER <td> Convert from float to integer
  2820. ** <tr><td> FLOAT <td> TEXT <td> ASCII rendering of the float
  2821. ** <tr><td> FLOAT <td> BLOB <td> Same as FLOAT->TEXT
  2822. ** <tr><td> TEXT <td> INTEGER <td> Use atoi()
  2823. ** <tr><td> TEXT <td> FLOAT <td> Use atof()
  2824. ** <tr><td> TEXT <td> BLOB <td> No change
  2825. ** <tr><td> BLOB <td> INTEGER <td> Convert to TEXT then use atoi()
  2826. ** <tr><td> BLOB <td> FLOAT <td> Convert to TEXT then use atof()
  2827. ** <tr><td> BLOB <td> TEXT <td> Add a zero terminator if needed
  2828. ** </table>
  2829. ** </blockquote>
  2830. **
  2831. ** The table above makes reference to standard C library functions atoi()
  2832. ** and atof(). SQLite does not really use these functions. It has its
  2833. ** own equivalent internal routines. The atoi() and atof() names are
  2834. ** used in the table for brevity and because they are familiar to most
  2835. ** C programmers.
  2836. **
  2837. ** Note that when type conversions occur, pointers returned by prior
  2838. ** calls to sqlite3_column_blob(), sqlite3_column_text(), and/or
  2839. ** sqlite3_column_text16() may be invalidated.
  2840. ** Type conversions and pointer invalidations might occur
  2841. ** in the following cases:
  2842. **
  2843. ** <ul>
  2844. ** <li> The initial content is a BLOB and sqlite3_column_text() or
  2845. ** sqlite3_column_text16() is called. A zero-terminator might
  2846. ** need to be added to the string.</li>
  2847. ** <li> The initial content is UTF-8 text and sqlite3_column_bytes16() or
  2848. ** sqlite3_column_text16() is called. The content must be converted
  2849. ** to UTF-16.</li>
  2850. ** <li> The initial content is UTF-16 text and sqlite3_column_bytes() or
  2851. ** sqlite3_column_text() is called. The content must be converted
  2852. ** to UTF-8.</li>
  2853. ** </ul>
  2854. **
  2855. ** Conversions between UTF-16be and UTF-16le are always done in place and do
  2856. ** not invalidate a prior pointer, though of course the content of the buffer
  2857. ** that the prior pointer points to will have been modified. Other kinds
  2858. ** of conversion are done in place when it is possible, but sometimes they
  2859. ** are not possible and in those cases prior pointers are invalidated.
  2860. **
  2861. ** The safest and easiest to remember policy is to invoke these routines
  2862. ** in one of the following ways:
  2863. **
  2864. ** <ul>
  2865. ** <li>sqlite3_column_text() followed by sqlite3_column_bytes()</li>
  2866. ** <li>sqlite3_column_blob() followed by sqlite3_column_bytes()</li>
  2867. ** <li>sqlite3_column_text16() followed by sqlite3_column_bytes16()</li>
  2868. ** </ul>
  2869. **
  2870. ** In other words, you should call sqlite3_column_text(),
  2871. ** sqlite3_column_blob(), or sqlite3_column_text16() first to force the result
  2872. ** into the desired format, then invoke sqlite3_column_bytes() or
  2873. ** sqlite3_column_bytes16() to find the size of the result. Do not mix calls
  2874. ** to sqlite3_column_text() or sqlite3_column_blob() with calls to
  2875. ** sqlite3_column_bytes16(), and do not mix calls to sqlite3_column_text16()
  2876. ** with calls to sqlite3_column_bytes().
  2877. **
  2878. ** The pointers returned are valid until a type conversion occurs as
  2879. ** described above, or until [sqlite3_step()] or [sqlite3_reset()] or
  2880. ** [sqlite3_finalize()] is called. The memory space used to hold strings
  2881. ** and BLOBs is freed automatically. Do <b>not</b> pass the pointers returned
  2882. ** [sqlite3_column_blob()], [sqlite3_column_text()], etc. into
  2883. ** [sqlite3_free()].
  2884. **
  2885. ** If a memory allocation error occurs during the evaluation of any
  2886. ** of these routines, a default value is returned. The default value
  2887. ** is either the integer 0, the floating point number 0.0, or a NULL
  2888. ** pointer. Subsequent calls to [sqlite3_errcode()] will return
  2889. ** [SQLITE_NOMEM].
  2890. **
  2891. ** Requirements:
  2892. ** [H13803] [H13806] [H13809] [H13812] [H13815] [H13818] [H13821] [H13824]
  2893. ** [H13827] [H13830]
  2894. */
  2895. const void *sqlite3_column_blob(sqlite3_stmt*, int iCol);
  2896. int sqlite3_column_bytes(sqlite3_stmt*, int iCol);
  2897. int sqlite3_column_bytes16(sqlite3_stmt*, int iCol);
  2898. double sqlite3_column_double(sqlite3_stmt*, int iCol);
  2899. int sqlite3_column_int(sqlite3_stmt*, int iCol);
  2900. sqlite3_int64 sqlite3_column_int64(sqlite3_stmt*, int iCol);
  2901. const unsigned char *sqlite3_column_text(sqlite3_stmt*, int iCol);
  2902. const void *sqlite3_column_text16(sqlite3_stmt*, int iCol);
  2903. int sqlite3_column_type(sqlite3_stmt*, int iCol);
  2904. sqlite3_value *sqlite3_column_value(sqlite3_stmt*, int iCol);
  2905. /*
  2906. ** CAPI3REF: Destroy A Prepared Statement Object {H13300} <S70300><S30100>
  2907. **
  2908. ** The sqlite3_finalize() function is called to delete a [prepared statement].
  2909. ** If the statement was executed successfully or not executed at all, then
  2910. ** SQLITE_OK is returned. If execution of the statement failed then an
  2911. ** [error code] or [extended error code] is returned.
  2912. **
  2913. ** This routine can be called at any point during the execution of the
  2914. ** [prepared statement]. If the virtual machine has not
  2915. ** completed execution when this routine is called, that is like
  2916. ** encountering an error or an [sqlite3_interrupt | interrupt].
  2917. ** Incomplete updates may be rolled back and transactions canceled,
  2918. ** depending on the circumstances, and the
  2919. ** [error code] returned will be [SQLITE_ABORT].
  2920. **
  2921. ** Requirements:
  2922. ** [H11302] [H11304]
  2923. */
  2924. int sqlite3_finalize(sqlite3_stmt *pStmt);
  2925. /*
  2926. ** CAPI3REF: Reset A Prepared Statement Object {H13330} <S70300>
  2927. **
  2928. ** The sqlite3_reset() function is called to reset a [prepared statement]
  2929. ** object back to its initial state, ready to be re-executed.
  2930. ** Any SQL statement variables that had values bound to them using
  2931. ** the [sqlite3_bind_blob | sqlite3_bind_*() API] retain their values.
  2932. ** Use [sqlite3_clear_bindings()] to reset the bindings.
  2933. **
  2934. ** {H11332} The [sqlite3_reset(S)] interface resets the [prepared statement] S
  2935. ** back to the beginning of its program.
  2936. **
  2937. ** {H11334} If the most recent call to [sqlite3_step(S)] for the
  2938. ** [prepared statement] S returned [SQLITE_ROW] or [SQLITE_DONE],
  2939. ** or if [sqlite3_step(S)] has never before been called on S,
  2940. ** then [sqlite3_reset(S)] returns [SQLITE_OK].
  2941. **
  2942. ** {H11336} If the most recent call to [sqlite3_step(S)] for the
  2943. ** [prepared statement] S indicated an error, then
  2944. ** [sqlite3_reset(S)] returns an appropriate [error code].
  2945. **
  2946. ** {H11338} The [sqlite3_reset(S)] interface does not change the values
  2947. ** of any [sqlite3_bind_blob|bindings] on the [prepared statement] S.
  2948. */
  2949. int sqlite3_reset(sqlite3_stmt *pStmt);
  2950. /*
  2951. ** CAPI3REF: Create Or Redefine SQL Functions {H16100} <S20200>
  2952. ** KEYWORDS: {function creation routines}
  2953. ** KEYWORDS: {application-defined SQL function}
  2954. ** KEYWORDS: {application-defined SQL functions}
  2955. **
  2956. ** These two functions (collectively known as "function creation routines")
  2957. ** are used to add SQL functions or aggregates or to redefine the behavior
  2958. ** of existing SQL functions or aggregates. The only difference between the
  2959. ** two is that the second parameter, the name of the (scalar) function or
  2960. ** aggregate, is encoded in UTF-8 for sqlite3_create_function() and UTF-16
  2961. ** for sqlite3_create_function16().
  2962. **
  2963. ** The first parameter is the [database connection] to which the SQL
  2964. ** function is to be added. If a single program uses more than one database
  2965. ** connection internally, then SQL functions must be added individually to
  2966. ** each database connection.
  2967. **
  2968. ** The second parameter is the name of the SQL function to be created or
  2969. ** redefined. The length of the name is limited to 255 bytes, exclusive of
  2970. ** the zero-terminator. Note that the name length limit is in bytes, not
  2971. ** characters. Any attempt to create a function with a longer name
  2972. ** will result in [SQLITE_ERROR] being returned.
  2973. **
  2974. ** The third parameter (nArg)
  2975. ** is the number of arguments that the SQL function or
  2976. ** aggregate takes. If this parameter is negative, then the SQL function or
  2977. ** aggregate may take any number of arguments.
  2978. **
  2979. ** The fourth parameter, eTextRep, specifies what
  2980. ** [SQLITE_UTF8 | text encoding] this SQL function prefers for
  2981. ** its parameters. Any SQL function implementation should be able to work
  2982. ** work with UTF-8, UTF-16le, or UTF-16be. But some implementations may be
  2983. ** more efficient with one encoding than another. It is allowed to
  2984. ** invoke sqlite3_create_function() or sqlite3_create_function16() multiple
  2985. ** times with the same function but with different values of eTextRep.
  2986. ** When multiple implementations of the same function are available, SQLite
  2987. ** will pick the one that involves the least amount of data conversion.
  2988. ** If there is only a single implementation which does not care what text
  2989. ** encoding is used, then the fourth argument should be [SQLITE_ANY].
  2990. **
  2991. ** The fifth parameter is an arbitrary pointer. The implementation of the
  2992. ** function can gain access to this pointer using [sqlite3_user_data()].
  2993. **
  2994. ** The seventh, eighth and ninth parameters, xFunc, xStep and xFinal, are
  2995. ** pointers to C-language functions that implement the SQL function or
  2996. ** aggregate. A scalar SQL function requires an implementation of the xFunc
  2997. ** callback only, NULL pointers should be passed as the xStep and xFinal
  2998. ** parameters. An aggregate SQL function requires an implementation of xStep
  2999. ** and xFinal and NULL should be passed for xFunc. To delete an existing
  3000. ** SQL function or aggregate, pass NULL for all three function callbacks.
  3001. **
  3002. ** It is permitted to register multiple implementations of the same
  3003. ** functions with the same name but with either differing numbers of
  3004. ** arguments or differing preferred text encodings. SQLite will use
  3005. ** the implementation most closely matches the way in which the
  3006. ** SQL function is used. A function implementation with a non-negative
  3007. ** nArg parameter is a better match than a function implementation with
  3008. ** a negative nArg. A function where the preferred text encoding
  3009. ** matches the database encoding is a better
  3010. ** match than a function where the encoding is different.
  3011. ** A function where the encoding difference is between UTF16le and UTF16be
  3012. ** is a closer match than a function where the encoding difference is
  3013. ** between UTF8 and UTF16.
  3014. **
  3015. ** Built-in functions may be overloaded by new application-defined functions.
  3016. ** The first application-defined function with a given name overrides all
  3017. ** built-in functions in the same [database connection] with the same name.
  3018. ** Subsequent application-defined functions of the same name only override
  3019. ** prior application-defined functions that are an exact match for the
  3020. ** number of parameters and preferred encoding.
  3021. **
  3022. ** An application-defined function is permitted to call other
  3023. ** SQLite interfaces. However, such calls must not
  3024. ** close the database connection nor finalize or reset the prepared
  3025. ** statement in which the function is running.
  3026. **
  3027. ** Requirements:
  3028. ** [H16103] [H16106] [H16109] [H16112] [H16118] [H16121] [H16124] [H16127]
  3029. ** [H16130] [H16133] [H16136] [H16139] [H16142]
  3030. */
  3031. int sqlite3_create_function(
  3032. sqlite3 *db,
  3033. const char *zFunctionName,
  3034. int nArg,
  3035. int eTextRep,
  3036. void *pApp,
  3037. void (*xFunc)(sqlite3_context*,int,sqlite3_value**),
  3038. void (*xStep)(sqlite3_context*,int,sqlite3_value**),
  3039. void (*xFinal)(sqlite3_context*)
  3040. );
  3041. int sqlite3_create_function16(
  3042. sqlite3 *db,
  3043. const void *zFunctionName,
  3044. int nArg,
  3045. int eTextRep,
  3046. void *pApp,
  3047. void (*xFunc)(sqlite3_context*,int,sqlite3_value**),
  3048. void (*xStep)(sqlite3_context*,int,sqlite3_value**),
  3049. void (*xFinal)(sqlite3_context*)
  3050. );
  3051. /*
  3052. ** CAPI3REF: Text Encodings {H10267} <S50200> <H16100>
  3053. **
  3054. ** These constant define integer codes that represent the various
  3055. ** text encodings supported by SQLite.
  3056. */
  3057. #define SQLITE_UTF8 1
  3058. #define SQLITE_UTF16LE 2
  3059. #define SQLITE_UTF16BE 3
  3060. #define SQLITE_UTF16 4 /* Use native byte order */
  3061. #define SQLITE_ANY 5 /* sqlite3_create_function only */
  3062. #define SQLITE_UTF16_ALIGNED 8 /* sqlite3_create_collation only */
  3063. /*
  3064. ** CAPI3REF: Deprecated Functions
  3065. ** DEPRECATED
  3066. **
  3067. ** These functions are [deprecated]. In order to maintain
  3068. ** backwards compatibility with older code, these functions continue
  3069. ** to be supported. However, new applications should avoid
  3070. ** the use of these functions. To help encourage people to avoid
  3071. ** using these functions, we are not going to tell you what they do.
  3072. */
  3073. #ifndef SQLITE_OMIT_DEPRECATED
  3074. SQLITE_DEPRECATED int sqlite3_aggregate_count(sqlite3_context*);
  3075. SQLITE_DEPRECATED int sqlite3_expired(sqlite3_stmt*);
  3076. SQLITE_DEPRECATED int sqlite3_transfer_bindings(sqlite3_stmt*, sqlite3_stmt*);
  3077. SQLITE_DEPRECATED int sqlite3_global_recover(void);
  3078. SQLITE_DEPRECATED void sqlite3_thread_cleanup(void);
  3079. SQLITE_DEPRECATED int sqlite3_memory_alarm(void(*)(void*,sqlite3_int64,int),void*,sqlite3_int64);
  3080. #endif
  3081. /*
  3082. ** CAPI3REF: Obtaining SQL Function Parameter Values {H15100} <S20200>
  3083. **
  3084. ** The C-language implementation of SQL functions and aggregates uses
  3085. ** this set of interface routines to access the parameter values on
  3086. ** the function or aggregate.
  3087. **
  3088. ** The xFunc (for scalar functions) or xStep (for aggregates) parameters
  3089. ** to [sqlite3_create_function()] and [sqlite3_create_function16()]
  3090. ** define callbacks that implement the SQL functions and aggregates.
  3091. ** The 4th parameter to these callbacks is an array of pointers to
  3092. ** [protected sqlite3_value] objects. There is one [sqlite3_value] object for
  3093. ** each parameter to the SQL function. These routines are used to
  3094. ** extract values from the [sqlite3_value] objects.
  3095. **
  3096. ** These routines work only with [protected sqlite3_value] objects.
  3097. ** Any attempt to use these routines on an [unprotected sqlite3_value]
  3098. ** object results in undefined behavior.
  3099. **
  3100. ** These routines work just like the corresponding [column access functions]
  3101. ** except that these routines take a single [protected sqlite3_value] object
  3102. ** pointer instead of a [sqlite3_stmt*] pointer and an integer column number.
  3103. **
  3104. ** The sqlite3_value_text16() interface extracts a UTF-16 string
  3105. ** in the native byte-order of the host machine. The
  3106. ** sqlite3_value_text16be() and sqlite3_value_text16le() interfaces
  3107. ** extract UTF-16 strings as big-endian and little-endian respectively.
  3108. **
  3109. ** The sqlite3_value_numeric_type() interface attempts to apply
  3110. ** numeric affinity to the value. This means that an attempt is
  3111. ** made to convert the value to an integer or floating point. If
  3112. ** such a conversion is possible without loss of information (in other
  3113. ** words, if the value is a string that looks like a number)
  3114. ** then the conversion is performed. Otherwise no conversion occurs.
  3115. ** The [SQLITE_INTEGER | datatype] after conversion is returned.
  3116. **
  3117. ** Please pay particular attention to the fact that the pointer returned
  3118. ** from [sqlite3_value_blob()], [sqlite3_value_text()], or
  3119. ** [sqlite3_value_text16()] can be invalidated by a subsequent call to
  3120. ** [sqlite3_value_bytes()], [sqlite3_value_bytes16()], [sqlite3_value_text()],
  3121. ** or [sqlite3_value_text16()].
  3122. **
  3123. ** These routines must be called from the same thread as
  3124. ** the SQL function that supplied the [sqlite3_value*] parameters.
  3125. **
  3126. ** Requirements:
  3127. ** [H15103] [H15106] [H15109] [H15112] [H15115] [H15118] [H15121] [H15124]
  3128. ** [H15127] [H15130] [H15133] [H15136]
  3129. */
  3130. const void *sqlite3_value_blob(sqlite3_value*);
  3131. int sqlite3_value_bytes(sqlite3_value*);
  3132. int sqlite3_value_bytes16(sqlite3_value*);
  3133. double sqlite3_value_double(sqlite3_value*);
  3134. int sqlite3_value_int(sqlite3_value*);
  3135. sqlite3_int64 sqlite3_value_int64(sqlite3_value*);
  3136. const unsigned char *sqlite3_value_text(sqlite3_value*);
  3137. const void *sqlite3_value_text16(sqlite3_value*);
  3138. const void *sqlite3_value_text16le(sqlite3_value*);
  3139. const void *sqlite3_value_text16be(sqlite3_value*);
  3140. int sqlite3_value_type(sqlite3_value*);
  3141. int sqlite3_value_numeric_type(sqlite3_value*);
  3142. /*
  3143. ** CAPI3REF: Obtain Aggregate Function Context {H16210} <S20200>
  3144. **
  3145. ** The implementation of aggregate SQL functions use this routine to allocate
  3146. ** a structure for storing their state.
  3147. **
  3148. ** The first time the sqlite3_aggregate_context() routine is called for a
  3149. ** particular aggregate, SQLite allocates nBytes of memory, zeroes out that
  3150. ** memory, and returns a pointer to it. On second and subsequent calls to
  3151. ** sqlite3_aggregate_context() for the same aggregate function index,
  3152. ** the same buffer is returned. The implementation of the aggregate can use
  3153. ** the returned buffer to accumulate data.
  3154. **
  3155. ** SQLite automatically frees the allocated buffer when the aggregate
  3156. ** query concludes.
  3157. **
  3158. ** The first parameter should be a copy of the
  3159. ** [sqlite3_context | SQL function context] that is the first parameter
  3160. ** to the callback routine that implements the aggregate function.
  3161. **
  3162. ** This routine must be called from the same thread in which
  3163. ** the aggregate SQL function is running.
  3164. **
  3165. ** Requirements:
  3166. ** [H16211] [H16213] [H16215] [H16217]
  3167. */
  3168. void *sqlite3_aggregate_context(sqlite3_context*, int nBytes);
  3169. /*
  3170. ** CAPI3REF: User Data For Functions {H16240} <S20200>
  3171. **
  3172. ** The sqlite3_user_data() interface returns a copy of
  3173. ** the pointer that was the pUserData parameter (the 5th parameter)
  3174. ** of the [sqlite3_create_function()]
  3175. ** and [sqlite3_create_function16()] routines that originally
  3176. ** registered the application defined function. {END}
  3177. **
  3178. ** This routine must be called from the same thread in which
  3179. ** the application-defined function is running.
  3180. **
  3181. ** Requirements:
  3182. ** [H16243]
  3183. */
  3184. void *sqlite3_user_data(sqlite3_context*);
  3185. /*
  3186. ** CAPI3REF: Database Connection For Functions {H16250} <S60600><S20200>
  3187. **
  3188. ** The sqlite3_context_db_handle() interface returns a copy of
  3189. ** the pointer to the [database connection] (the 1st parameter)
  3190. ** of the [sqlite3_create_function()]
  3191. ** and [sqlite3_create_function16()] routines that originally
  3192. ** registered the application defined function.
  3193. **
  3194. ** Requirements:
  3195. ** [H16253]
  3196. */
  3197. sqlite3 *sqlite3_context_db_handle(sqlite3_context*);
  3198. /*
  3199. ** CAPI3REF: Function Auxiliary Data {H16270} <S20200>
  3200. **
  3201. ** The following two functions may be used by scalar SQL functions to
  3202. ** associate metadata with argument values. If the same value is passed to
  3203. ** multiple invocations of the same SQL function during query execution, under
  3204. ** some circumstances the associated metadata may be preserved. This may
  3205. ** be used, for example, to add a regular-expression matching scalar
  3206. ** function. The compiled version of the regular expression is stored as
  3207. ** metadata associated with the SQL value passed as the regular expression
  3208. ** pattern. The compiled regular expression can be reused on multiple
  3209. ** invocations of the same function so that the original pattern string
  3210. ** does not need to be recompiled on each invocation.
  3211. **
  3212. ** The sqlite3_get_auxdata() interface returns a pointer to the metadata
  3213. ** associated by the sqlite3_set_auxdata() function with the Nth argument
  3214. ** value to the application-defined function. If no metadata has been ever
  3215. ** been set for the Nth argument of the function, or if the corresponding
  3216. ** function parameter has changed since the meta-data was set,
  3217. ** then sqlite3_get_auxdata() returns a NULL pointer.
  3218. **
  3219. ** The sqlite3_set_auxdata() interface saves the metadata
  3220. ** pointed to by its 3rd parameter as the metadata for the N-th
  3221. ** argument of the application-defined function. Subsequent
  3222. ** calls to sqlite3_get_auxdata() might return this data, if it has
  3223. ** not been destroyed.
  3224. ** If it is not NULL, SQLite will invoke the destructor
  3225. ** function given by the 4th parameter to sqlite3_set_auxdata() on
  3226. ** the metadata when the corresponding function parameter changes
  3227. ** or when the SQL statement completes, whichever comes first.
  3228. **
  3229. ** SQLite is free to call the destructor and drop metadata on any
  3230. ** parameter of any function at any time. The only guarantee is that
  3231. ** the destructor will be called before the metadata is dropped.
  3232. **
  3233. ** In practice, metadata is preserved between function calls for
  3234. ** expressions that are constant at compile time. This includes literal
  3235. ** values and SQL variables.
  3236. **
  3237. ** These routines must be called from the same thread in which
  3238. ** the SQL function is running.
  3239. **
  3240. ** Requirements:
  3241. ** [H16272] [H16274] [H16276] [H16277] [H16278] [H16279]
  3242. */
  3243. void *sqlite3_get_auxdata(sqlite3_context*, int N);
  3244. void sqlite3_set_auxdata(sqlite3_context*, int N, void*, void (*)(void*));
  3245. /*
  3246. ** CAPI3REF: Constants Defining Special Destructor Behavior {H10280} <S30100>
  3247. **
  3248. ** These are special values for the destructor that is passed in as the
  3249. ** final argument to routines like [sqlite3_result_blob()]. If the destructor
  3250. ** argument is SQLITE_STATIC, it means that the content pointer is constant
  3251. ** and will never change. It does not need to be destroyed. The
  3252. ** SQLITE_TRANSIENT value means that the content will likely change in
  3253. ** the near future and that SQLite should make its own private copy of
  3254. ** the content before returning.
  3255. **
  3256. ** The typedef is necessary to work around problems in certain
  3257. ** C++ compilers. See ticket #2191.
  3258. */
  3259. typedef void (*sqlite3_destructor_type)(void*);
  3260. #define SQLITE_STATIC ((sqlite3_destructor_type)0)
  3261. #define SQLITE_TRANSIENT ((sqlite3_destructor_type)-1)
  3262. /*
  3263. ** CAPI3REF: Setting The Result Of An SQL Function {H16400} <S20200>
  3264. **
  3265. ** These routines are used by the xFunc or xFinal callbacks that
  3266. ** implement SQL functions and aggregates. See
  3267. ** [sqlite3_create_function()] and [sqlite3_create_function16()]
  3268. ** for additional information.
  3269. **
  3270. ** These functions work very much like the [parameter binding] family of
  3271. ** functions used to bind values to host parameters in prepared statements.
  3272. ** Refer to the [SQL parameter] documentation for additional information.
  3273. **
  3274. ** The sqlite3_result_blob() interface sets the result from
  3275. ** an application-defined function to be the BLOB whose content is pointed
  3276. ** to by the second parameter and which is N bytes long where N is the
  3277. ** third parameter.
  3278. **
  3279. ** The sqlite3_result_zeroblob() interfaces set the result of
  3280. ** the application-defined function to be a BLOB containing all zero
  3281. ** bytes and N bytes in size, where N is the value of the 2nd parameter.
  3282. **
  3283. ** The sqlite3_result_double() interface sets the result from
  3284. ** an application-defined function to be a floating point value specified
  3285. ** by its 2nd argument.
  3286. **
  3287. ** The sqlite3_result_error() and sqlite3_result_error16() functions
  3288. ** cause the implemented SQL function to throw an exception.
  3289. ** SQLite uses the string pointed to by the
  3290. ** 2nd parameter of sqlite3_result_error() or sqlite3_result_error16()
  3291. ** as the text of an error message. SQLite interprets the error
  3292. ** message string from sqlite3_result_error() as UTF-8. SQLite
  3293. ** interprets the string from sqlite3_result_error16() as UTF-16 in native
  3294. ** byte order. If the third parameter to sqlite3_result_error()
  3295. ** or sqlite3_result_error16() is negative then SQLite takes as the error
  3296. ** message all text up through the first zero character.
  3297. ** If the third parameter to sqlite3_result_error() or
  3298. ** sqlite3_result_error16() is non-negative then SQLite takes that many
  3299. ** bytes (not characters) from the 2nd parameter as the error message.
  3300. ** The sqlite3_result_error() and sqlite3_result_error16()
  3301. ** routines make a private copy of the error message text before
  3302. ** they return. Hence, the calling function can deallocate or
  3303. ** modify the text after they return without harm.
  3304. ** The sqlite3_result_error_code() function changes the error code
  3305. ** returned by SQLite as a result of an error in a function. By default,
  3306. ** the error code is SQLITE_ERROR. A subsequent call to sqlite3_result_error()
  3307. ** or sqlite3_result_error16() resets the error code to SQLITE_ERROR.
  3308. **
  3309. ** The sqlite3_result_toobig() interface causes SQLite to throw an error
  3310. ** indicating that a string or BLOB is to long to represent.
  3311. **
  3312. ** The sqlite3_result_nomem() interface causes SQLite to throw an error
  3313. ** indicating that a memory allocation failed.
  3314. **
  3315. ** The sqlite3_result_int() interface sets the return value
  3316. ** of the application-defined function to be the 32-bit signed integer
  3317. ** value given in the 2nd argument.
  3318. ** The sqlite3_result_int64() interface sets the return value
  3319. ** of the application-defined function to be the 64-bit signed integer
  3320. ** value given in the 2nd argument.
  3321. **
  3322. ** The sqlite3_result_null() interface sets the return value
  3323. ** of the application-defined function to be NULL.
  3324. **
  3325. ** The sqlite3_result_text(), sqlite3_result_text16(),
  3326. ** sqlite3_result_text16le(), and sqlite3_result_text16be() interfaces
  3327. ** set the return value of the application-defined function to be
  3328. ** a text string which is represented as UTF-8, UTF-16 native byte order,
  3329. ** UTF-16 little endian, or UTF-16 big endian, respectively.
  3330. ** SQLite takes the text result from the application from
  3331. ** the 2nd parameter of the sqlite3_result_text* interfaces.
  3332. ** If the 3rd parameter to the sqlite3_result_text* interfaces
  3333. ** is negative, then SQLite takes result text from the 2nd parameter
  3334. ** through the first zero character.
  3335. ** If the 3rd parameter to the sqlite3_result_text* interfaces
  3336. ** is non-negative, then as many bytes (not characters) of the text
  3337. ** pointed to by the 2nd parameter are taken as the application-defined
  3338. ** function result.
  3339. ** If the 4th parameter to the sqlite3_result_text* interfaces
  3340. ** or sqlite3_result_blob is a non-NULL pointer, then SQLite calls that
  3341. ** function as the destructor on the text or BLOB result when it has
  3342. ** finished using that result.
  3343. ** If the 4th parameter to the sqlite3_result_text* interfaces or
  3344. ** sqlite3_result_blob is the special constant SQLITE_STATIC, then SQLite
  3345. ** assumes that the text or BLOB result is in constant space and does not
  3346. ** copy the it or call a destructor when it has finished using that result.
  3347. ** If the 4th parameter to the sqlite3_result_text* interfaces
  3348. ** or sqlite3_result_blob is the special constant SQLITE_TRANSIENT
  3349. ** then SQLite makes a copy of the result into space obtained from
  3350. ** from [sqlite3_malloc()] before it returns.
  3351. **
  3352. ** The sqlite3_result_value() interface sets the result of
  3353. ** the application-defined function to be a copy the
  3354. ** [unprotected sqlite3_value] object specified by the 2nd parameter. The
  3355. ** sqlite3_result_value() interface makes a copy of the [sqlite3_value]
  3356. ** so that the [sqlite3_value] specified in the parameter may change or
  3357. ** be deallocated after sqlite3_result_value() returns without harm.
  3358. ** A [protected sqlite3_value] object may always be used where an
  3359. ** [unprotected sqlite3_value] object is required, so either
  3360. ** kind of [sqlite3_value] object can be used with this interface.
  3361. **
  3362. ** If these routines are called from within the different thread
  3363. ** than the one containing the application-defined function that received
  3364. ** the [sqlite3_context] pointer, the results are undefined.
  3365. **
  3366. ** Requirements:
  3367. ** [H16403] [H16406] [H16409] [H16412] [H16415] [H16418] [H16421] [H16424]
  3368. ** [H16427] [H16430] [H16433] [H16436] [H16439] [H16442] [H16445] [H16448]
  3369. ** [H16451] [H16454] [H16457] [H16460] [H16463]
  3370. */
  3371. void sqlite3_result_blob(sqlite3_context*, const void*, int, void(*)(void*));
  3372. void sqlite3_result_double(sqlite3_context*, double);
  3373. void sqlite3_result_error(sqlite3_context*, const char*, int);
  3374. void sqlite3_result_error16(sqlite3_context*, const void*, int);
  3375. void sqlite3_result_error_toobig(sqlite3_context*);
  3376. void sqlite3_result_error_nomem(sqlite3_context*);
  3377. void sqlite3_result_error_code(sqlite3_context*, int);
  3378. void sqlite3_result_int(sqlite3_context*, int);
  3379. void sqlite3_result_int64(sqlite3_context*, sqlite3_int64);
  3380. void sqlite3_result_null(sqlite3_context*);
  3381. void sqlite3_result_text(sqlite3_context*, const char*, int, void(*)(void*));
  3382. void sqlite3_result_text16(sqlite3_context*, const void*, int, void(*)(void*));
  3383. void sqlite3_result_text16le(sqlite3_context*, const void*, int,void(*)(void*));
  3384. void sqlite3_result_text16be(sqlite3_context*, const void*, int,void(*)(void*));
  3385. void sqlite3_result_value(sqlite3_context*, sqlite3_value*);
  3386. void sqlite3_result_zeroblob(sqlite3_context*, int n);
  3387. /*
  3388. ** CAPI3REF: Define New Collating Sequences {H16600} <S20300>
  3389. **
  3390. ** These functions are used to add new collation sequences to the
  3391. ** [database connection] specified as the first argument.
  3392. **
  3393. ** The name of the new collation sequence is specified as a UTF-8 string
  3394. ** for sqlite3_create_collation() and sqlite3_create_collation_v2()
  3395. ** and a UTF-16 string for sqlite3_create_collation16(). In all cases
  3396. ** the name is passed as the second function argument.
  3397. **
  3398. ** The third argument may be one of the constants [SQLITE_UTF8],
  3399. ** [SQLITE_UTF16LE] or [SQLITE_UTF16BE], indicating that the user-supplied
  3400. ** routine expects to be passed pointers to strings encoded using UTF-8,
  3401. ** UTF-16 little-endian, or UTF-16 big-endian, respectively. The
  3402. ** third argument might also be [SQLITE_UTF16_ALIGNED] to indicate that
  3403. ** the routine expects pointers to 16-bit word aligned strings
  3404. ** of UTF-16 in the native byte order of the host computer.
  3405. **
  3406. ** A pointer to the user supplied routine must be passed as the fifth
  3407. ** argument. If it is NULL, this is the same as deleting the collation
  3408. ** sequence (so that SQLite cannot call it anymore).
  3409. ** Each time the application supplied function is invoked, it is passed
  3410. ** as its first parameter a copy of the void* passed as the fourth argument
  3411. ** to sqlite3_create_collation() or sqlite3_create_collation16().
  3412. **
  3413. ** The remaining arguments to the application-supplied routine are two strings,
  3414. ** each represented by a (length, data) pair and encoded in the encoding
  3415. ** that was passed as the third argument when the collation sequence was
  3416. ** registered. {END} The application defined collation routine should
  3417. ** return negative, zero or positive if the first string is less than,
  3418. ** equal to, or greater than the second string. i.e. (STRING1 - STRING2).
  3419. **
  3420. ** The sqlite3_create_collation_v2() works like sqlite3_create_collation()
  3421. ** except that it takes an extra argument which is a destructor for
  3422. ** the collation. The destructor is called when the collation is
  3423. ** destroyed and is passed a copy of the fourth parameter void* pointer
  3424. ** of the sqlite3_create_collation_v2().
  3425. ** Collations are destroyed when they are overridden by later calls to the
  3426. ** collation creation functions or when the [database connection] is closed
  3427. ** using [sqlite3_close()].
  3428. **
  3429. ** Requirements:
  3430. ** [H16603] [H16604] [H16606] [H16609] [H16612] [H16615] [H16618] [H16621]
  3431. ** [H16624] [H16627] [H16630]
  3432. */
  3433. int sqlite3_create_collation(
  3434. sqlite3*,
  3435. const char *zName,
  3436. int eTextRep,
  3437. void*,
  3438. int(*xCompare)(void*,int,const void*,int,const void*)
  3439. );
  3440. int sqlite3_create_collation_v2(
  3441. sqlite3*,
  3442. const char *zName,
  3443. int eTextRep,
  3444. void*,
  3445. int(*xCompare)(void*,int,const void*,int,const void*),
  3446. void(*xDestroy)(void*)
  3447. );
  3448. int sqlite3_create_collation16(
  3449. sqlite3*,
  3450. const void *zName,
  3451. int eTextRep,
  3452. void*,
  3453. int(*xCompare)(void*,int,const void*,int,const void*)
  3454. );
  3455. /*
  3456. ** CAPI3REF: Collation Needed Callbacks {H16700} <S20300>
  3457. **
  3458. ** To avoid having to register all collation sequences before a database
  3459. ** can be used, a single callback function may be registered with the
  3460. ** [database connection] to be called whenever an undefined collation
  3461. ** sequence is required.
  3462. **
  3463. ** If the function is registered using the sqlite3_collation_needed() API,
  3464. ** then it is passed the names of undefined collation sequences as strings
  3465. ** encoded in UTF-8. {H16703} If sqlite3_collation_needed16() is used,
  3466. ** the names are passed as UTF-16 in machine native byte order.
  3467. ** A call to either function replaces any existing callback.
  3468. **
  3469. ** When the callback is invoked, the first argument passed is a copy
  3470. ** of the second argument to sqlite3_collation_needed() or
  3471. ** sqlite3_collation_needed16(). The second argument is the database
  3472. ** connection. The third argument is one of [SQLITE_UTF8], [SQLITE_UTF16BE],
  3473. ** or [SQLITE_UTF16LE], indicating the most desirable form of the collation
  3474. ** sequence function required. The fourth parameter is the name of the
  3475. ** required collation sequence.
  3476. **
  3477. ** The callback function should register the desired collation using
  3478. ** [sqlite3_create_collation()], [sqlite3_create_collation16()], or
  3479. ** [sqlite3_create_collation_v2()].
  3480. **
  3481. ** Requirements:
  3482. ** [H16702] [H16704] [H16706]
  3483. */
  3484. int sqlite3_collation_needed(
  3485. sqlite3*,
  3486. void*,
  3487. void(*)(void*,sqlite3*,int eTextRep,const char*)
  3488. );
  3489. int sqlite3_collation_needed16(
  3490. sqlite3*,
  3491. void*,
  3492. void(*)(void*,sqlite3*,int eTextRep,const void*)
  3493. );
  3494. /*
  3495. ** Specify the key for an encrypted database. This routine should be
  3496. ** called right after sqlite3_open().
  3497. **
  3498. ** The code to implement this API is not available in the public release
  3499. ** of SQLite.
  3500. */
  3501. int sqlite3_key(
  3502. sqlite3 *db, /* Database to be rekeyed */
  3503. const void *pKey, int nKey /* The key */
  3504. );
  3505. /*
  3506. ** Change the key on an open database. If the current database is not
  3507. ** encrypted, this routine will encrypt it. If pNew==0 or nNew==0, the
  3508. ** database is decrypted.
  3509. **
  3510. ** The code to implement this API is not available in the public release
  3511. ** of SQLite.
  3512. */
  3513. int sqlite3_rekey(
  3514. sqlite3 *db, /* Database to be rekeyed */
  3515. const void *pKey, int nKey /* The new key */
  3516. );
  3517. /*
  3518. ** CAPI3REF: Suspend Execution For A Short Time {H10530} <S40410>
  3519. **
  3520. ** The sqlite3_sleep() function causes the current thread to suspend execution
  3521. ** for at least a number of milliseconds specified in its parameter.
  3522. **
  3523. ** If the operating system does not support sleep requests with
  3524. ** millisecond time resolution, then the time will be rounded up to
  3525. ** the nearest second. The number of milliseconds of sleep actually
  3526. ** requested from the operating system is returned.
  3527. **
  3528. ** SQLite implements this interface by calling the xSleep()
  3529. ** method of the default [sqlite3_vfs] object.
  3530. **
  3531. ** Requirements: [H10533] [H10536]
  3532. */
  3533. int sqlite3_sleep(int);
  3534. /*
  3535. ** CAPI3REF: Name Of The Folder Holding Temporary Files {H10310} <S20000>
  3536. **
  3537. ** If this global variable is made to point to a string which is
  3538. ** the name of a folder (a.k.a. directory), then all temporary files
  3539. ** created by SQLite will be placed in that directory. If this variable
  3540. ** is a NULL pointer, then SQLite performs a search for an appropriate
  3541. ** temporary file directory.
  3542. **
  3543. ** It is not safe to read or modify this variable in more than one
  3544. ** thread at a time. It is not safe to read or modify this variable
  3545. ** if a [database connection] is being used at the same time in a separate
  3546. ** thread.
  3547. ** It is intended that this variable be set once
  3548. ** as part of process initialization and before any SQLite interface
  3549. ** routines have been called and that this variable remain unchanged
  3550. ** thereafter.
  3551. **
  3552. ** The [temp_store_directory pragma] may modify this variable and cause
  3553. ** it to point to memory obtained from [sqlite3_malloc]. Furthermore,
  3554. ** the [temp_store_directory pragma] always assumes that any string
  3555. ** that this variable points to is held in memory obtained from
  3556. ** [sqlite3_malloc] and the pragma may attempt to free that memory
  3557. ** using [sqlite3_free].
  3558. ** Hence, if this variable is modified directly, either it should be
  3559. ** made NULL or made to point to memory obtained from [sqlite3_malloc]
  3560. ** or else the use of the [temp_store_directory pragma] should be avoided.
  3561. */
  3562. SQLITE_EXTERN char *sqlite3_temp_directory;
  3563. /*
  3564. ** CAPI3REF: Test For Auto-Commit Mode {H12930} <S60200>
  3565. ** KEYWORDS: {autocommit mode}
  3566. **
  3567. ** The sqlite3_get_autocommit() interface returns non-zero or
  3568. ** zero if the given database connection is or is not in autocommit mode,
  3569. ** respectively. Autocommit mode is on by default.
  3570. ** Autocommit mode is disabled by a [BEGIN] statement.
  3571. ** Autocommit mode is re-enabled by a [COMMIT] or [ROLLBACK].
  3572. **
  3573. ** If certain kinds of errors occur on a statement within a multi-statement
  3574. ** transaction (errors including [SQLITE_FULL], [SQLITE_IOERR],
  3575. ** [SQLITE_NOMEM], [SQLITE_BUSY], and [SQLITE_INTERRUPT]) then the
  3576. ** transaction might be rolled back automatically. The only way to
  3577. ** find out whether SQLite automatically rolled back the transaction after
  3578. ** an error is to use this function.
  3579. **
  3580. ** If another thread changes the autocommit status of the database
  3581. ** connection while this routine is running, then the return value
  3582. ** is undefined.
  3583. **
  3584. ** Requirements: [H12931] [H12932] [H12933] [H12934]
  3585. */
  3586. int sqlite3_get_autocommit(sqlite3*);
  3587. /*
  3588. ** CAPI3REF: Find The Database Handle Of A Prepared Statement {H13120} <S60600>
  3589. **
  3590. ** The sqlite3_db_handle interface returns the [database connection] handle
  3591. ** to which a [prepared statement] belongs. The [database connection]
  3592. ** returned by sqlite3_db_handle is the same [database connection] that was the first argument
  3593. ** to the [sqlite3_prepare_v2()] call (or its variants) that was used to
  3594. ** create the statement in the first place.
  3595. **
  3596. ** Requirements: [H13123]
  3597. */
  3598. sqlite3 *sqlite3_db_handle(sqlite3_stmt*);
  3599. /*
  3600. ** CAPI3REF: Find the next prepared statement {H13140} <S60600>
  3601. **
  3602. ** This interface returns a pointer to the next [prepared statement] after
  3603. ** pStmt associated with the [database connection] pDb. If pStmt is NULL
  3604. ** then this interface returns a pointer to the first prepared statement
  3605. ** associated with the database connection pDb. If no prepared statement
  3606. ** satisfies the conditions of this routine, it returns NULL.
  3607. **
  3608. ** The [database connection] pointer D in a call to
  3609. ** [sqlite3_next_stmt(D,S)] must refer to an open database
  3610. ** connection and in particular must not be a NULL pointer.
  3611. **
  3612. ** Requirements: [H13143] [H13146] [H13149] [H13152]
  3613. */
  3614. sqlite3_stmt *sqlite3_next_stmt(sqlite3 *pDb, sqlite3_stmt *pStmt);
  3615. /*
  3616. ** CAPI3REF: Commit And Rollback Notification Callbacks {H12950} <S60400>
  3617. **
  3618. ** The sqlite3_commit_hook() interface registers a callback
  3619. ** function to be invoked whenever a transaction is committed.
  3620. ** Any callback set by a previous call to sqlite3_commit_hook()
  3621. ** for the same database connection is overridden.
  3622. ** The sqlite3_rollback_hook() interface registers a callback
  3623. ** function to be invoked whenever a transaction is committed.
  3624. ** Any callback set by a previous call to sqlite3_commit_hook()
  3625. ** for the same database connection is overridden.
  3626. ** The pArg argument is passed through to the callback.
  3627. ** If the callback on a commit hook function returns non-zero,
  3628. ** then the commit is converted into a rollback.
  3629. **
  3630. ** If another function was previously registered, its
  3631. ** pArg value is returned. Otherwise NULL is returned.
  3632. **
  3633. ** The callback implementation must not do anything that will modify
  3634. ** the database connection that invoked the callback. Any actions
  3635. ** to modify the database connection must be deferred until after the
  3636. ** completion of the [sqlite3_step()] call that triggered the commit
  3637. ** or rollback hook in the first place.
  3638. ** Note that [sqlite3_prepare_v2()] and [sqlite3_step()] both modify their
  3639. ** database connections for the meaning of "modify" in this paragraph.
  3640. **
  3641. ** Registering a NULL function disables the callback.
  3642. **
  3643. ** For the purposes of this API, a transaction is said to have been
  3644. ** rolled back if an explicit "ROLLBACK" statement is executed, or
  3645. ** an error or constraint causes an implicit rollback to occur.
  3646. ** The rollback callback is not invoked if a transaction is
  3647. ** automatically rolled back because the database connection is closed.
  3648. ** The rollback callback is not invoked if a transaction is
  3649. ** rolled back because a commit callback returned non-zero.
  3650. ** <todo> Check on this </todo>
  3651. **
  3652. ** Requirements:
  3653. ** [H12951] [H12952] [H12953] [H12954] [H12955]
  3654. ** [H12961] [H12962] [H12963] [H12964]
  3655. */
  3656. void *sqlite3_commit_hook(sqlite3*, int(*)(void*), void*);
  3657. void *sqlite3_rollback_hook(sqlite3*, void(*)(void *), void*);
  3658. /*
  3659. ** CAPI3REF: Data Change Notification Callbacks {H12970} <S60400>
  3660. **
  3661. ** The sqlite3_update_hook() interface registers a callback function
  3662. ** with the [database connection] identified by the first argument
  3663. ** to be invoked whenever a row is updated, inserted or deleted.
  3664. ** Any callback set by a previous call to this function
  3665. ** for the same database connection is overridden.
  3666. **
  3667. ** The second argument is a pointer to the function to invoke when a
  3668. ** row is updated, inserted or deleted.
  3669. ** The first argument to the callback is a copy of the third argument
  3670. ** to sqlite3_update_hook().
  3671. ** The second callback argument is one of [SQLITE_INSERT], [SQLITE_DELETE],
  3672. ** or [SQLITE_UPDATE], depending on the operation that caused the callback
  3673. ** to be invoked.
  3674. ** The third and fourth arguments to the callback contain pointers to the
  3675. ** database and table name containing the affected row.
  3676. ** The final callback parameter is the [rowid] of the row.
  3677. ** In the case of an update, this is the [rowid] after the update takes place.
  3678. **
  3679. ** The update hook is not invoked when internal system tables are
  3680. ** modified (i.e. sqlite_master and sqlite_sequence).
  3681. **
  3682. ** The update hook implementation must not do anything that will modify
  3683. ** the database connection that invoked the update hook. Any actions
  3684. ** to modify the database connection must be deferred until after the
  3685. ** completion of the [sqlite3_step()] call that triggered the update hook.
  3686. ** Note that [sqlite3_prepare_v2()] and [sqlite3_step()] both modify their
  3687. ** database connections for the meaning of "modify" in this paragraph.
  3688. **
  3689. ** If another function was previously registered, its pArg value
  3690. ** is returned. Otherwise NULL is returned.
  3691. **
  3692. ** Requirements:
  3693. ** [H12971] [H12973] [H12975] [H12977] [H12979] [H12981] [H12983] [H12986]
  3694. */
  3695. void *sqlite3_update_hook(
  3696. sqlite3*,
  3697. void(*)(void *,int ,char const *,char const *,sqlite3_int64),
  3698. void*
  3699. );
  3700. /*
  3701. ** CAPI3REF: Enable Or Disable Shared Pager Cache {H10330} <S30900>
  3702. ** KEYWORDS: {shared cache} {shared cache mode}
  3703. **
  3704. ** This routine enables or disables the sharing of the database cache
  3705. ** and schema data structures between [database connection | connections]
  3706. ** to the same database. Sharing is enabled if the argument is true
  3707. ** and disabled if the argument is false.
  3708. **
  3709. ** Cache sharing is enabled and disabled for an entire process.
  3710. ** This is a change as of SQLite version 3.5.0. In prior versions of SQLite,
  3711. ** sharing was enabled or disabled for each thread separately.
  3712. **
  3713. ** The cache sharing mode set by this interface effects all subsequent
  3714. ** calls to [sqlite3_open()], [sqlite3_open_v2()], and [sqlite3_open16()].
  3715. ** Existing database connections continue use the sharing mode
  3716. ** that was in effect at the time they were opened.
  3717. **
  3718. ** Virtual tables cannot be used with a shared cache. When shared
  3719. ** cache is enabled, the [sqlite3_create_module()] API used to register
  3720. ** virtual tables will always return an error.
  3721. **
  3722. ** This routine returns [SQLITE_OK] if shared cache was enabled or disabled
  3723. ** successfully. An [error code] is returned otherwise.
  3724. **
  3725. ** Shared cache is disabled by default. But this might change in
  3726. ** future releases of SQLite. Applications that care about shared
  3727. ** cache setting should set it explicitly.
  3728. **
  3729. ** See Also: [SQLite Shared-Cache Mode]
  3730. **
  3731. ** Requirements: [H10331] [H10336] [H10337] [H10339]
  3732. */
  3733. int sqlite3_enable_shared_cache(int);
  3734. /*
  3735. ** CAPI3REF: Attempt To Free Heap Memory {H17340} <S30220>
  3736. **
  3737. ** The sqlite3_release_memory() interface attempts to free N bytes
  3738. ** of heap memory by deallocating non-essential memory allocations
  3739. ** held by the database library. {END} Memory used to cache database
  3740. ** pages to improve performance is an example of non-essential memory.
  3741. ** sqlite3_release_memory() returns the number of bytes actually freed,
  3742. ** which might be more or less than the amount requested.
  3743. **
  3744. ** Requirements: [H17341] [H17342]
  3745. */
  3746. int sqlite3_release_memory(int);
  3747. /*
  3748. ** CAPI3REF: Impose A Limit On Heap Size {H17350} <S30220>
  3749. **
  3750. ** The sqlite3_soft_heap_limit() interface places a "soft" limit
  3751. ** on the amount of heap memory that may be allocated by SQLite.
  3752. ** If an internal allocation is requested that would exceed the
  3753. ** soft heap limit, [sqlite3_release_memory()] is invoked one or
  3754. ** more times to free up some space before the allocation is performed.
  3755. **
  3756. ** The limit is called "soft", because if [sqlite3_release_memory()]
  3757. ** cannot free sufficient memory to prevent the limit from being exceeded,
  3758. ** the memory is allocated anyway and the current operation proceeds.
  3759. **
  3760. ** A negative or zero value for N means that there is no soft heap limit and
  3761. ** [sqlite3_release_memory()] will only be called when memory is exhausted.
  3762. ** The default value for the soft heap limit is zero.
  3763. **
  3764. ** SQLite makes a best effort to honor the soft heap limit.
  3765. ** But if the soft heap limit cannot be honored, execution will
  3766. ** continue without error or notification. This is why the limit is
  3767. ** called a "soft" limit. It is advisory only.
  3768. **
  3769. ** Prior to SQLite version 3.5.0, this routine only constrained the memory
  3770. ** allocated by a single thread - the same thread in which this routine
  3771. ** runs. Beginning with SQLite version 3.5.0, the soft heap limit is
  3772. ** applied to all threads. The value specified for the soft heap limit
  3773. ** is an upper bound on the total memory allocation for all threads. In
  3774. ** version 3.5.0 there is no mechanism for limiting the heap usage for
  3775. ** individual threads.
  3776. **
  3777. ** Requirements:
  3778. ** [H16351] [H16352] [H16353] [H16354] [H16355] [H16358]
  3779. */
  3780. void sqlite3_soft_heap_limit(int);
  3781. /*
  3782. ** CAPI3REF: Extract Metadata About A Column Of A Table {H12850} <S60300>
  3783. **
  3784. ** This routine returns metadata about a specific column of a specific
  3785. ** database table accessible using the [database connection] handle
  3786. ** passed as the first function argument.
  3787. **
  3788. ** The column is identified by the second, third and fourth parameters to
  3789. ** this function. The second parameter is either the name of the database
  3790. ** (i.e. "main", "temp" or an attached database) containing the specified
  3791. ** table or NULL. If it is NULL, then all attached databases are searched
  3792. ** for the table using the same algorithm used by the database engine to
  3793. ** resolve unqualified table references.
  3794. **
  3795. ** The third and fourth parameters to this function are the table and column
  3796. ** name of the desired column, respectively. Neither of these parameters
  3797. ** may be NULL.
  3798. **
  3799. ** Metadata is returned by writing to the memory locations passed as the 5th
  3800. ** and subsequent parameters to this function. Any of these arguments may be
  3801. ** NULL, in which case the corresponding element of metadata is omitted.
  3802. **
  3803. ** <blockquote>
  3804. ** <table border="1">
  3805. ** <tr><th> Parameter <th> Output<br>Type <th> Description
  3806. **
  3807. ** <tr><td> 5th <td> const char* <td> Data type
  3808. ** <tr><td> 6th <td> const char* <td> Name of default collation sequence
  3809. ** <tr><td> 7th <td> int <td> True if column has a NOT NULL constraint
  3810. ** <tr><td> 8th <td> int <td> True if column is part of the PRIMARY KEY
  3811. ** <tr><td> 9th <td> int <td> True if column is [AUTOINCREMENT]
  3812. ** </table>
  3813. ** </blockquote>
  3814. **
  3815. ** The memory pointed to by the character pointers returned for the
  3816. ** declaration type and collation sequence is valid only until the next
  3817. ** call to any SQLite API function.
  3818. **
  3819. ** If the specified table is actually a view, an [error code] is returned.
  3820. **
  3821. ** If the specified column is "rowid", "oid" or "_rowid_" and an
  3822. ** [INTEGER PRIMARY KEY] column has been explicitly declared, then the output
  3823. ** parameters are set for the explicitly declared column. If there is no
  3824. ** explicitly declared [INTEGER PRIMARY KEY] column, then the output
  3825. ** parameters are set as follows:
  3826. **
  3827. ** <pre>
  3828. ** data type: "INTEGER"
  3829. ** collation sequence: "BINARY"
  3830. ** not null: 0
  3831. ** primary key: 1
  3832. ** auto increment: 0
  3833. ** </pre>
  3834. **
  3835. ** This function may load one or more schemas from database files. If an
  3836. ** error occurs during this process, or if the requested table or column
  3837. ** cannot be found, an [error code] is returned and an error message left
  3838. ** in the [database connection] (to be retrieved using sqlite3_errmsg()).
  3839. **
  3840. ** This API is only available if the library was compiled with the
  3841. ** [SQLITE_ENABLE_COLUMN_METADATA] C-preprocessor symbol defined.
  3842. */
  3843. int sqlite3_table_column_metadata(
  3844. sqlite3 *db, /* Connection handle */
  3845. const char *zDbName, /* Database name or NULL */
  3846. const char *zTableName, /* Table name */
  3847. const char *zColumnName, /* Column name */
  3848. char const **pzDataType, /* OUTPUT: Declared data type */
  3849. char const **pzCollSeq, /* OUTPUT: Collation sequence name */
  3850. int *pNotNull, /* OUTPUT: True if NOT NULL constraint exists */
  3851. int *pPrimaryKey, /* OUTPUT: True if column part of PK */
  3852. int *pAutoinc /* OUTPUT: True if column is auto-increment */
  3853. );
  3854. /*
  3855. ** CAPI3REF: Load An Extension {H12600} <S20500>
  3856. **
  3857. ** This interface loads an SQLite extension library from the named file.
  3858. **
  3859. ** {H12601} The sqlite3_load_extension() interface attempts to load an
  3860. ** SQLite extension library contained in the file zFile.
  3861. **
  3862. ** {H12602} The entry point is zProc.
  3863. **
  3864. ** {H12603} zProc may be 0, in which case the name of the entry point
  3865. ** defaults to "sqlite3_extension_init".
  3866. **
  3867. ** {H12604} The sqlite3_load_extension() interface shall return
  3868. ** [SQLITE_OK] on success and [SQLITE_ERROR] if something goes wrong.
  3869. **
  3870. ** {H12605} If an error occurs and pzErrMsg is not 0, then the
  3871. ** [sqlite3_load_extension()] interface shall attempt to
  3872. ** fill *pzErrMsg with error message text stored in memory
  3873. ** obtained from [sqlite3_malloc()]. {END} The calling function
  3874. ** should free this memory by calling [sqlite3_free()].
  3875. **
  3876. ** {H12606} Extension loading must be enabled using
  3877. ** [sqlite3_enable_load_extension()] prior to calling this API,
  3878. ** otherwise an error will be returned.
  3879. */
  3880. int sqlite3_load_extension(
  3881. sqlite3 *db, /* Load the extension into this database connection */
  3882. const char *zFile, /* Name of the shared library containing extension */
  3883. const char *zProc, /* Entry point. Derived from zFile if 0 */
  3884. char **pzErrMsg /* Put error message here if not 0 */
  3885. );
  3886. /*
  3887. ** CAPI3REF: Enable Or Disable Extension Loading {H12620} <S20500>
  3888. **
  3889. ** So as not to open security holes in older applications that are
  3890. ** unprepared to deal with extension loading, and as a means of disabling
  3891. ** extension loading while evaluating user-entered SQL, the following API
  3892. ** is provided to turn the [sqlite3_load_extension()] mechanism on and off.
  3893. **
  3894. ** Extension loading is off by default. See ticket #1863.
  3895. **
  3896. ** {H12621} Call the sqlite3_enable_load_extension() routine with onoff==1
  3897. ** to turn extension loading on and call it with onoff==0 to turn
  3898. ** it back off again.
  3899. **
  3900. ** {H12622} Extension loading is off by default.
  3901. */
  3902. int sqlite3_enable_load_extension(sqlite3 *db, int onoff);
  3903. /*
  3904. ** CAPI3REF: Automatically Load An Extensions {H12640} <S20500>
  3905. **
  3906. ** This API can be invoked at program startup in order to register
  3907. ** one or more statically linked extensions that will be available
  3908. ** to all new [database connections]. {END}
  3909. **
  3910. ** This routine stores a pointer to the extension in an array that is
  3911. ** obtained from [sqlite3_malloc()]. If you run a memory leak checker
  3912. ** on your program and it reports a leak because of this array, invoke
  3913. ** [sqlite3_reset_auto_extension()] prior to shutdown to free the memory.
  3914. **
  3915. ** {H12641} This function registers an extension entry point that is
  3916. ** automatically invoked whenever a new [database connection]
  3917. ** is opened using [sqlite3_open()], [sqlite3_open16()],
  3918. ** or [sqlite3_open_v2()].
  3919. **
  3920. ** {H12642} Duplicate extensions are detected so calling this routine
  3921. ** multiple times with the same extension is harmless.
  3922. **
  3923. ** {H12643} This routine stores a pointer to the extension in an array
  3924. ** that is obtained from [sqlite3_malloc()].
  3925. **
  3926. ** {H12644} Automatic extensions apply across all threads.
  3927. */
  3928. int sqlite3_auto_extension(void (*xEntryPoint)(void));
  3929. /*
  3930. ** CAPI3REF: Reset Automatic Extension Loading {H12660} <S20500>
  3931. **
  3932. ** This function disables all previously registered automatic
  3933. ** extensions. {END} It undoes the effect of all prior
  3934. ** [sqlite3_auto_extension()] calls.
  3935. **
  3936. ** {H12661} This function disables all previously registered
  3937. ** automatic extensions.
  3938. **
  3939. ** {H12662} This function disables automatic extensions in all threads.
  3940. */
  3941. void sqlite3_reset_auto_extension(void);
  3942. /*
  3943. ****** EXPERIMENTAL - subject to change without notice **************
  3944. **
  3945. ** The interface to the virtual-table mechanism is currently considered
  3946. ** to be experimental. The interface might change in incompatible ways.
  3947. ** If this is a problem for you, do not use the interface at this time.
  3948. **
  3949. ** When the virtual-table mechanism stabilizes, we will declare the
  3950. ** interface fixed, support it indefinitely, and remove this comment.
  3951. */
  3952. /*
  3953. ** Structures used by the virtual table interface
  3954. */
  3955. typedef struct sqlite3_vtab sqlite3_vtab;
  3956. typedef struct sqlite3_index_info sqlite3_index_info;
  3957. typedef struct sqlite3_vtab_cursor sqlite3_vtab_cursor;
  3958. typedef struct sqlite3_module sqlite3_module;
  3959. /*
  3960. ** CAPI3REF: Virtual Table Object {H18000} <S20400>
  3961. ** KEYWORDS: sqlite3_module
  3962. ** EXPERIMENTAL
  3963. **
  3964. ** A module is a class of virtual tables. Each module is defined
  3965. ** by an instance of the following structure. This structure consists
  3966. ** mostly of methods for the module.
  3967. **
  3968. ** This interface is experimental and is subject to change or
  3969. ** removal in future releases of SQLite.
  3970. */
  3971. struct sqlite3_module {
  3972. int iVersion;
  3973. int (*xCreate)(sqlite3*, void *pAux,
  3974. int argc, const char *const*argv,
  3975. sqlite3_vtab **ppVTab, char**);
  3976. int (*xConnect)(sqlite3*, void *pAux,
  3977. int argc, const char *const*argv,
  3978. sqlite3_vtab **ppVTab, char**);
  3979. int (*xBestIndex)(sqlite3_vtab *pVTab, sqlite3_index_info*);
  3980. int (*xDisconnect)(sqlite3_vtab *pVTab);
  3981. int (*xDestroy)(sqlite3_vtab *pVTab);
  3982. int (*xOpen)(sqlite3_vtab *pVTab, sqlite3_vtab_cursor **ppCursor);
  3983. int (*xClose)(sqlite3_vtab_cursor*);
  3984. int (*xFilter)(sqlite3_vtab_cursor*, int idxNum, const char *idxStr,
  3985. int argc, sqlite3_value **argv);
  3986. int (*xNext)(sqlite3_vtab_cursor*);
  3987. int (*xEof)(sqlite3_vtab_cursor*);
  3988. int (*xColumn)(sqlite3_vtab_cursor*, sqlite3_context*, int);
  3989. int (*xRowid)(sqlite3_vtab_cursor*, sqlite3_int64 *pRowid);
  3990. int (*xUpdate)(sqlite3_vtab *, int, sqlite3_value **, sqlite3_int64 *);
  3991. int (*xBegin)(sqlite3_vtab *pVTab);
  3992. int (*xSync)(sqlite3_vtab *pVTab);
  3993. int (*xCommit)(sqlite3_vtab *pVTab);
  3994. int (*xRollback)(sqlite3_vtab *pVTab);
  3995. int (*xFindFunction)(sqlite3_vtab *pVtab, int nArg, const char *zName,
  3996. void (**pxFunc)(sqlite3_context*,int,sqlite3_value**),
  3997. void **ppArg);
  3998. int (*xRename)(sqlite3_vtab *pVtab, const char *zNew);
  3999. };
  4000. /*
  4001. ** CAPI3REF: Virtual Table Indexing Information {H18100} <S20400>
  4002. ** KEYWORDS: sqlite3_index_info
  4003. ** EXPERIMENTAL
  4004. **
  4005. ** The sqlite3_index_info structure and its substructures is used to
  4006. ** pass information into and receive the reply from the xBestIndex
  4007. ** method of an sqlite3_module. The fields under **Inputs** are the
  4008. ** inputs to xBestIndex and are read-only. xBestIndex inserts its
  4009. ** results into the **Outputs** fields.
  4010. **
  4011. ** The aConstraint[] array records WHERE clause constraints of the form:
  4012. **
  4013. ** <pre>column OP expr</pre>
  4014. **
  4015. ** where OP is =, &lt;, &lt;=, &gt;, or &gt;=. The particular operator is
  4016. ** stored in aConstraint[].op. The index of the column is stored in
  4017. ** aConstraint[].iColumn. aConstraint[].usable is TRUE if the
  4018. ** expr on the right-hand side can be evaluated (and thus the constraint
  4019. ** is usable) and false if it cannot.
  4020. **
  4021. ** The optimizer automatically inverts terms of the form "expr OP column"
  4022. ** and makes other simplifications to the WHERE clause in an attempt to
  4023. ** get as many WHERE clause terms into the form shown above as possible.
  4024. ** The aConstraint[] array only reports WHERE clause terms in the correct
  4025. ** form that refer to the particular virtual table being queried.
  4026. **
  4027. ** Information about the ORDER BY clause is stored in aOrderBy[].
  4028. ** Each term of aOrderBy records a column of the ORDER BY clause.
  4029. **
  4030. ** The xBestIndex method must fill aConstraintUsage[] with information
  4031. ** about what parameters to pass to xFilter. If argvIndex>0 then
  4032. ** the right-hand side of the corresponding aConstraint[] is evaluated
  4033. ** and becomes the argvIndex-th entry in argv. If aConstraintUsage[].omit
  4034. ** is true, then the constraint is assumed to be fully handled by the
  4035. ** virtual table and is not checked again by SQLite.
  4036. **
  4037. ** The idxNum and idxPtr values are recorded and passed into xFilter.
  4038. ** sqlite3_free() is used to free idxPtr if needToFreeIdxPtr is true.
  4039. **
  4040. ** The orderByConsumed means that output from xFilter will occur in
  4041. ** the correct order to satisfy the ORDER BY clause so that no separate
  4042. ** sorting step is required.
  4043. **
  4044. ** The estimatedCost value is an estimate of the cost of doing the
  4045. ** particular lookup. A full scan of a table with N entries should have
  4046. ** a cost of N. A binary search of a table of N entries should have a
  4047. ** cost of approximately log(N).
  4048. **
  4049. ** This interface is experimental and is subject to change or
  4050. ** removal in future releases of SQLite.
  4051. */
  4052. struct sqlite3_index_info {
  4053. /* Inputs */
  4054. int nConstraint; /* Number of entries in aConstraint */
  4055. struct sqlite3_index_constraint {
  4056. int iColumn; /* Column on left-hand side of constraint */
  4057. unsigned char op; /* Constraint operator */
  4058. unsigned char usable; /* True if this constraint is usable */
  4059. int iTermOffset; /* Used internally - xBestIndex should ignore */
  4060. } *aConstraint; /* Table of WHERE clause constraints */
  4061. int nOrderBy; /* Number of terms in the ORDER BY clause */
  4062. struct sqlite3_index_orderby {
  4063. int iColumn; /* Column number */
  4064. unsigned char desc; /* True for DESC. False for ASC. */
  4065. } *aOrderBy; /* The ORDER BY clause */
  4066. /* Outputs */
  4067. struct sqlite3_index_constraint_usage {
  4068. int argvIndex; /* if >0, constraint is part of argv to xFilter */
  4069. unsigned char omit; /* Do not code a test for this constraint */
  4070. } *aConstraintUsage;
  4071. int idxNum; /* Number used to identify the index */
  4072. char *idxStr; /* String, possibly obtained from sqlite3_malloc */
  4073. int needToFreeIdxStr; /* Free idxStr using sqlite3_free() if true */
  4074. int orderByConsumed; /* True if output is already ordered */
  4075. double estimatedCost; /* Estimated cost of using this index */
  4076. };
  4077. #define SQLITE_INDEX_CONSTRAINT_EQ 2
  4078. #define SQLITE_INDEX_CONSTRAINT_GT 4
  4079. #define SQLITE_INDEX_CONSTRAINT_LE 8
  4080. #define SQLITE_INDEX_CONSTRAINT_LT 16
  4081. #define SQLITE_INDEX_CONSTRAINT_GE 32
  4082. #define SQLITE_INDEX_CONSTRAINT_MATCH 64
  4083. /*
  4084. ** CAPI3REF: Register A Virtual Table Implementation {H18200} <S20400>
  4085. ** EXPERIMENTAL
  4086. **
  4087. ** This routine is used to register a new module name with a
  4088. ** [database connection]. Module names must be registered before
  4089. ** creating new virtual tables on the module, or before using
  4090. ** preexisting virtual tables of the module.
  4091. **
  4092. ** This interface is experimental and is subject to change or
  4093. ** removal in future releases of SQLite.
  4094. */
  4095. SQLITE_EXPERIMENTAL int sqlite3_create_module(
  4096. sqlite3 *db, /* SQLite connection to register module with */
  4097. const char *zName, /* Name of the module */
  4098. const sqlite3_module *, /* Methods for the module */
  4099. void * /* Client data for xCreate/xConnect */
  4100. );
  4101. /*
  4102. ** CAPI3REF: Register A Virtual Table Implementation {H18210} <S20400>
  4103. ** EXPERIMENTAL
  4104. **
  4105. ** This routine is identical to the [sqlite3_create_module()] method above,
  4106. ** except that it allows a destructor function to be specified. It is
  4107. ** even more experimental than the rest of the virtual tables API.
  4108. */
  4109. SQLITE_EXPERIMENTAL int sqlite3_create_module_v2(
  4110. sqlite3 *db, /* SQLite connection to register module with */
  4111. const char *zName, /* Name of the module */
  4112. const sqlite3_module *, /* Methods for the module */
  4113. void *, /* Client data for xCreate/xConnect */
  4114. void(*xDestroy)(void*) /* Module destructor function */
  4115. );
  4116. /*
  4117. ** CAPI3REF: Virtual Table Instance Object {H18010} <S20400>
  4118. ** KEYWORDS: sqlite3_vtab
  4119. ** EXPERIMENTAL
  4120. **
  4121. ** Every module implementation uses a subclass of the following structure
  4122. ** to describe a particular instance of the module. Each subclass will
  4123. ** be tailored to the specific needs of the module implementation.
  4124. ** The purpose of this superclass is to define certain fields that are
  4125. ** common to all module implementations.
  4126. **
  4127. ** Virtual tables methods can set an error message by assigning a
  4128. ** string obtained from [sqlite3_mprintf()] to zErrMsg. The method should
  4129. ** take care that any prior string is freed by a call to [sqlite3_free()]
  4130. ** prior to assigning a new string to zErrMsg. After the error message
  4131. ** is delivered up to the client application, the string will be automatically
  4132. ** freed by sqlite3_free() and the zErrMsg field will be zeroed. Note
  4133. ** that sqlite3_mprintf() and sqlite3_free() are used on the zErrMsg field
  4134. ** since virtual tables are commonly implemented in loadable extensions which
  4135. ** do not have access to sqlite3MPrintf() or sqlite3Free().
  4136. **
  4137. ** This interface is experimental and is subject to change or
  4138. ** removal in future releases of SQLite.
  4139. */
  4140. struct sqlite3_vtab {
  4141. const sqlite3_module *pModule; /* The module for this virtual table */
  4142. int nRef; /* Used internally */
  4143. char *zErrMsg; /* Error message from sqlite3_mprintf() */
  4144. /* Virtual table implementations will typically add additional fields */
  4145. };
  4146. /*
  4147. ** CAPI3REF: Virtual Table Cursor Object {H18020} <S20400>
  4148. ** KEYWORDS: sqlite3_vtab_cursor
  4149. ** EXPERIMENTAL
  4150. **
  4151. ** Every module implementation uses a subclass of the following structure
  4152. ** to describe cursors that point into the virtual table and are used
  4153. ** to loop through the virtual table. Cursors are created using the
  4154. ** xOpen method of the module. Each module implementation will define
  4155. ** the content of a cursor structure to suit its own needs.
  4156. **
  4157. ** This superclass exists in order to define fields of the cursor that
  4158. ** are common to all implementations.
  4159. **
  4160. ** This interface is experimental and is subject to change or
  4161. ** removal in future releases of SQLite.
  4162. */
  4163. struct sqlite3_vtab_cursor {
  4164. sqlite3_vtab *pVtab; /* Virtual table of this cursor */
  4165. /* Virtual table implementations will typically add additional fields */
  4166. };
  4167. /*
  4168. ** CAPI3REF: Declare The Schema Of A Virtual Table {H18280} <S20400>
  4169. ** EXPERIMENTAL
  4170. **
  4171. ** The xCreate and xConnect methods of a module use the following API
  4172. ** to declare the format (the names and datatypes of the columns) of
  4173. ** the virtual tables they implement.
  4174. **
  4175. ** This interface is experimental and is subject to change or
  4176. ** removal in future releases of SQLite.
  4177. */
  4178. SQLITE_EXPERIMENTAL int sqlite3_declare_vtab(sqlite3*, const char *zCreateTable);
  4179. /*
  4180. ** CAPI3REF: Overload A Function For A Virtual Table {H18300} <S20400>
  4181. ** EXPERIMENTAL
  4182. **
  4183. ** Virtual tables can provide alternative implementations of functions
  4184. ** using the xFindFunction method. But global versions of those functions
  4185. ** must exist in order to be overloaded.
  4186. **
  4187. ** This API makes sure a global version of a function with a particular
  4188. ** name and number of parameters exists. If no such function exists
  4189. ** before this API is called, a new function is created. The implementation
  4190. ** of the new function always causes an exception to be thrown. So
  4191. ** the new function is not good for anything by itself. Its only
  4192. ** purpose is to be a placeholder function that can be overloaded
  4193. ** by virtual tables.
  4194. **
  4195. ** This API should be considered part of the virtual table interface,
  4196. ** which is experimental and subject to change.
  4197. */
  4198. SQLITE_EXPERIMENTAL int sqlite3_overload_function(sqlite3*, const char *zFuncName, int nArg);
  4199. /*
  4200. ** The interface to the virtual-table mechanism defined above (back up
  4201. ** to a comment remarkably similar to this one) is currently considered
  4202. ** to be experimental. The interface might change in incompatible ways.
  4203. ** If this is a problem for you, do not use the interface at this time.
  4204. **
  4205. ** When the virtual-table mechanism stabilizes, we will declare the
  4206. ** interface fixed, support it indefinitely, and remove this comment.
  4207. **
  4208. ****** EXPERIMENTAL - subject to change without notice **************
  4209. */
  4210. /*
  4211. ** CAPI3REF: A Handle To An Open BLOB {H17800} <S30230>
  4212. ** KEYWORDS: {BLOB handle} {BLOB handles}
  4213. **
  4214. ** An instance of this object represents an open BLOB on which
  4215. ** [sqlite3_blob_open | incremental BLOB I/O] can be performed.
  4216. ** Objects of this type are created by [sqlite3_blob_open()]
  4217. ** and destroyed by [sqlite3_blob_close()].
  4218. ** The [sqlite3_blob_read()] and [sqlite3_blob_write()] interfaces
  4219. ** can be used to read or write small subsections of the BLOB.
  4220. ** The [sqlite3_blob_bytes()] interface returns the size of the BLOB in bytes.
  4221. */
  4222. typedef struct sqlite3_blob sqlite3_blob;
  4223. /*
  4224. ** CAPI3REF: Open A BLOB For Incremental I/O {H17810} <S30230>
  4225. **
  4226. ** This interfaces opens a [BLOB handle | handle] to the BLOB located
  4227. ** in row iRow, column zColumn, table zTable in database zDb;
  4228. ** in other words, the same BLOB that would be selected by:
  4229. **
  4230. ** <pre>
  4231. ** SELECT zColumn FROM zDb.zTable WHERE [rowid] = iRow;
  4232. ** </pre> {END}
  4233. **
  4234. ** If the flags parameter is non-zero, the the BLOB is opened for read
  4235. ** and write access. If it is zero, the BLOB is opened for read access.
  4236. **
  4237. ** Note that the database name is not the filename that contains
  4238. ** the database but rather the symbolic name of the database that
  4239. ** is assigned when the database is connected using [ATTACH].
  4240. ** For the main database file, the database name is "main".
  4241. ** For TEMP tables, the database name is "temp".
  4242. **
  4243. ** On success, [SQLITE_OK] is returned and the new [BLOB handle] is written
  4244. ** to *ppBlob. Otherwise an [error code] is returned and any value written
  4245. ** to *ppBlob should not be used by the caller.
  4246. ** This function sets the [database connection] error code and message
  4247. ** accessible via [sqlite3_errcode()] and [sqlite3_errmsg()].
  4248. **
  4249. ** If the row that a BLOB handle points to is modified by an
  4250. ** [UPDATE], [DELETE], or by [ON CONFLICT] side-effects
  4251. ** then the BLOB handle is marked as "expired".
  4252. ** This is true if any column of the row is changed, even a column
  4253. ** other than the one the BLOB handle is open on.
  4254. ** Calls to [sqlite3_blob_read()] and [sqlite3_blob_write()] for
  4255. ** a expired BLOB handle fail with an return code of [SQLITE_ABORT].
  4256. ** Changes written into a BLOB prior to the BLOB expiring are not
  4257. ** rollback by the expiration of the BLOB. Such changes will eventually
  4258. ** commit if the transaction continues to completion.
  4259. **
  4260. ** Requirements:
  4261. ** [H17813] [H17814] [H17816] [H17819] [H17821] [H17824]
  4262. */
  4263. int sqlite3_blob_open(
  4264. sqlite3*,
  4265. const char *zDb,
  4266. const char *zTable,
  4267. const char *zColumn,
  4268. sqlite3_int64 iRow,
  4269. int flags,
  4270. sqlite3_blob **ppBlob
  4271. );
  4272. /*
  4273. ** CAPI3REF: Close A BLOB Handle {H17830} <S30230>
  4274. **
  4275. ** Closes an open [BLOB handle].
  4276. **
  4277. ** Closing a BLOB shall cause the current transaction to commit
  4278. ** if there are no other BLOBs, no pending prepared statements, and the
  4279. ** database connection is in [autocommit mode].
  4280. ** If any writes were made to the BLOB, they might be held in cache
  4281. ** until the close operation if they will fit. {END}
  4282. **
  4283. ** Closing the BLOB often forces the changes
  4284. ** out to disk and so if any I/O errors occur, they will likely occur
  4285. ** at the time when the BLOB is closed. {H17833} Any errors that occur during
  4286. ** closing are reported as a non-zero return value.
  4287. **
  4288. ** The BLOB is closed unconditionally. Even if this routine returns
  4289. ** an error code, the BLOB is still closed.
  4290. **
  4291. ** Requirements:
  4292. ** [H17833] [H17836] [H17839]
  4293. */
  4294. int sqlite3_blob_close(sqlite3_blob *);
  4295. /*
  4296. ** CAPI3REF: Return The Size Of An Open BLOB {H17840} <S30230>
  4297. **
  4298. ** Returns the size in bytes of the BLOB accessible via the open
  4299. ** []BLOB handle] in its only argument.
  4300. **
  4301. ** Requirements:
  4302. ** [H17843]
  4303. */
  4304. int sqlite3_blob_bytes(sqlite3_blob *);
  4305. /*
  4306. ** CAPI3REF: Read Data From A BLOB Incrementally {H17850} <S30230>
  4307. **
  4308. ** This function is used to read data from an open [BLOB handle] into a
  4309. ** caller-supplied buffer. N bytes of data are copied into buffer Z
  4310. ** from the open BLOB, starting at offset iOffset.
  4311. **
  4312. ** If offset iOffset is less than N bytes from the end of the BLOB,
  4313. ** [SQLITE_ERROR] is returned and no data is read. If N or iOffset is
  4314. ** less than zero, [SQLITE_ERROR] is returned and no data is read.
  4315. **
  4316. ** An attempt to read from an expired [BLOB handle] fails with an
  4317. ** error code of [SQLITE_ABORT].
  4318. **
  4319. ** On success, SQLITE_OK is returned.
  4320. ** Otherwise, an [error code] or an [extended error code] is returned.
  4321. **
  4322. ** Requirements:
  4323. ** [H17853] [H17856] [H17859] [H17862] [H17863] [H17865] [H17868]
  4324. */
  4325. int sqlite3_blob_read(sqlite3_blob *, void *Z, int N, int iOffset);
  4326. /*
  4327. ** CAPI3REF: Write Data Into A BLOB Incrementally {H17870} <S30230>
  4328. **
  4329. ** This function is used to write data into an open [BLOB handle] from a
  4330. ** caller-supplied buffer. N bytes of data are copied from the buffer Z
  4331. ** into the open BLOB, starting at offset iOffset.
  4332. **
  4333. ** If the [BLOB handle] passed as the first argument was not opened for
  4334. ** writing (the flags parameter to [sqlite3_blob_open()] was zero),
  4335. ** this function returns [SQLITE_READONLY].
  4336. **
  4337. ** This function may only modify the contents of the BLOB; it is
  4338. ** not possible to increase the size of a BLOB using this API.
  4339. ** If offset iOffset is less than N bytes from the end of the BLOB,
  4340. ** [SQLITE_ERROR] is returned and no data is written. If N is
  4341. ** less than zero [SQLITE_ERROR] is returned and no data is written.
  4342. **
  4343. ** An attempt to write to an expired [BLOB handle] fails with an
  4344. ** error code of [SQLITE_ABORT]. Writes to the BLOB that occurred
  4345. ** before the [BLOB handle] expired are not rolled back by the
  4346. ** expiration of the handle, though of course those changes might
  4347. ** have been overwritten by the statement that expired the BLOB handle
  4348. ** or by other independent statements.
  4349. **
  4350. ** On success, SQLITE_OK is returned.
  4351. ** Otherwise, an [error code] or an [extended error code] is returned.
  4352. **
  4353. ** Requirements:
  4354. ** [H17873] [H17874] [H17875] [H17876] [H17877] [H17879] [H17882] [H17885]
  4355. ** [H17888]
  4356. */
  4357. int sqlite3_blob_write(sqlite3_blob *, const void *z, int n, int iOffset);
  4358. /*
  4359. ** CAPI3REF: Virtual File System Objects {H11200} <S20100>
  4360. **
  4361. ** A virtual filesystem (VFS) is an [sqlite3_vfs] object
  4362. ** that SQLite uses to interact
  4363. ** with the underlying operating system. Most SQLite builds come with a
  4364. ** single default VFS that is appropriate for the host computer.
  4365. ** New VFSes can be registered and existing VFSes can be unregistered.
  4366. ** The following interfaces are provided.
  4367. **
  4368. ** The sqlite3_vfs_find() interface returns a pointer to a VFS given its name.
  4369. ** Names are case sensitive.
  4370. ** Names are zero-terminated UTF-8 strings.
  4371. ** If there is no match, a NULL pointer is returned.
  4372. ** If zVfsName is NULL then the default VFS is returned.
  4373. **
  4374. ** New VFSes are registered with sqlite3_vfs_register().
  4375. ** Each new VFS becomes the default VFS if the makeDflt flag is set.
  4376. ** The same VFS can be registered multiple times without injury.
  4377. ** To make an existing VFS into the default VFS, register it again
  4378. ** with the makeDflt flag set. If two different VFSes with the
  4379. ** same name are registered, the behavior is undefined. If a
  4380. ** VFS is registered with a name that is NULL or an empty string,
  4381. ** then the behavior is undefined.
  4382. **
  4383. ** Unregister a VFS with the sqlite3_vfs_unregister() interface.
  4384. ** If the default VFS is unregistered, another VFS is chosen as
  4385. ** the default. The choice for the new VFS is arbitrary.
  4386. **
  4387. ** Requirements:
  4388. ** [H11203] [H11206] [H11209] [H11212] [H11215] [H11218]
  4389. */
  4390. sqlite3_vfs *sqlite3_vfs_find(const char *zVfsName);
  4391. int sqlite3_vfs_register(sqlite3_vfs*, int makeDflt);
  4392. int sqlite3_vfs_unregister(sqlite3_vfs*);
  4393. /*
  4394. ** CAPI3REF: Mutexes {H17000} <S20000>
  4395. **
  4396. ** The SQLite core uses these routines for thread
  4397. ** synchronization. Though they are intended for internal
  4398. ** use by SQLite, code that links against SQLite is
  4399. ** permitted to use any of these routines.
  4400. **
  4401. ** The SQLite source code contains multiple implementations
  4402. ** of these mutex routines. An appropriate implementation
  4403. ** is selected automatically at compile-time. The following
  4404. ** implementations are available in the SQLite core:
  4405. **
  4406. ** <ul>
  4407. ** <li> SQLITE_MUTEX_OS2
  4408. ** <li> SQLITE_MUTEX_PTHREAD
  4409. ** <li> SQLITE_MUTEX_W32
  4410. ** <li> SQLITE_MUTEX_NOOP
  4411. ** </ul>
  4412. **
  4413. ** The SQLITE_MUTEX_NOOP implementation is a set of routines
  4414. ** that does no real locking and is appropriate for use in
  4415. ** a single-threaded application. The SQLITE_MUTEX_OS2,
  4416. ** SQLITE_MUTEX_PTHREAD, and SQLITE_MUTEX_W32 implementations
  4417. ** are appropriate for use on OS/2, Unix, and Windows.
  4418. **
  4419. ** If SQLite is compiled with the SQLITE_MUTEX_APPDEF preprocessor
  4420. ** macro defined (with "-DSQLITE_MUTEX_APPDEF=1"), then no mutex
  4421. ** implementation is included with the library. In this case the
  4422. ** application must supply a custom mutex implementation using the
  4423. ** [SQLITE_CONFIG_MUTEX] option of the sqlite3_config() function
  4424. ** before calling sqlite3_initialize() or any other public sqlite3_
  4425. ** function that calls sqlite3_initialize().
  4426. **
  4427. ** {H17011} The sqlite3_mutex_alloc() routine allocates a new
  4428. ** mutex and returns a pointer to it. {H17012} If it returns NULL
  4429. ** that means that a mutex could not be allocated. {H17013} SQLite
  4430. ** will unwind its stack and return an error. {H17014} The argument
  4431. ** to sqlite3_mutex_alloc() is one of these integer constants:
  4432. **
  4433. ** <ul>
  4434. ** <li> SQLITE_MUTEX_FAST
  4435. ** <li> SQLITE_MUTEX_RECURSIVE
  4436. ** <li> SQLITE_MUTEX_STATIC_MASTER
  4437. ** <li> SQLITE_MUTEX_STATIC_MEM
  4438. ** <li> SQLITE_MUTEX_STATIC_MEM2
  4439. ** <li> SQLITE_MUTEX_STATIC_PRNG
  4440. ** <li> SQLITE_MUTEX_STATIC_LRU
  4441. ** <li> SQLITE_MUTEX_STATIC_LRU2
  4442. ** </ul>
  4443. **
  4444. ** {H17015} The first two constants cause sqlite3_mutex_alloc() to create
  4445. ** a new mutex. The new mutex is recursive when SQLITE_MUTEX_RECURSIVE
  4446. ** is used but not necessarily so when SQLITE_MUTEX_FAST is used. {END}
  4447. ** The mutex implementation does not need to make a distinction
  4448. ** between SQLITE_MUTEX_RECURSIVE and SQLITE_MUTEX_FAST if it does
  4449. ** not want to. {H17016} But SQLite will only request a recursive mutex in
  4450. ** cases where it really needs one. {END} If a faster non-recursive mutex
  4451. ** implementation is available on the host platform, the mutex subsystem
  4452. ** might return such a mutex in response to SQLITE_MUTEX_FAST.
  4453. **
  4454. ** {H17017} The other allowed parameters to sqlite3_mutex_alloc() each return
  4455. ** a pointer to a static preexisting mutex. {END} Four static mutexes are
  4456. ** used by the current version of SQLite. Future versions of SQLite
  4457. ** may add additional static mutexes. Static mutexes are for internal
  4458. ** use by SQLite only. Applications that use SQLite mutexes should
  4459. ** use only the dynamic mutexes returned by SQLITE_MUTEX_FAST or
  4460. ** SQLITE_MUTEX_RECURSIVE.
  4461. **
  4462. ** {H17018} Note that if one of the dynamic mutex parameters (SQLITE_MUTEX_FAST
  4463. ** or SQLITE_MUTEX_RECURSIVE) is used then sqlite3_mutex_alloc()
  4464. ** returns a different mutex on every call. {H17034} But for the static
  4465. ** mutex types, the same mutex is returned on every call that has
  4466. ** the same type number.
  4467. **
  4468. ** {H17019} The sqlite3_mutex_free() routine deallocates a previously
  4469. ** allocated dynamic mutex. {H17020} SQLite is careful to deallocate every
  4470. ** dynamic mutex that it allocates. {A17021} The dynamic mutexes must not be in
  4471. ** use when they are deallocated. {A17022} Attempting to deallocate a static
  4472. ** mutex results in undefined behavior. {H17023} SQLite never deallocates
  4473. ** a static mutex. {END}
  4474. **
  4475. ** The sqlite3_mutex_enter() and sqlite3_mutex_try() routines attempt
  4476. ** to enter a mutex. {H17024} If another thread is already within the mutex,
  4477. ** sqlite3_mutex_enter() will block and sqlite3_mutex_try() will return
  4478. ** SQLITE_BUSY. {H17025} The sqlite3_mutex_try() interface returns [SQLITE_OK]
  4479. ** upon successful entry. {H17026} Mutexes created using
  4480. ** SQLITE_MUTEX_RECURSIVE can be entered multiple times by the same thread.
  4481. ** {H17027} In such cases the,
  4482. ** mutex must be exited an equal number of times before another thread
  4483. ** can enter. {A17028} If the same thread tries to enter any other
  4484. ** kind of mutex more than once, the behavior is undefined.
  4485. ** {H17029} SQLite will never exhibit
  4486. ** such behavior in its own use of mutexes.
  4487. **
  4488. ** Some systems (for example, Windows 95) do not support the operation
  4489. ** implemented by sqlite3_mutex_try(). On those systems, sqlite3_mutex_try()
  4490. ** will always return SQLITE_BUSY. {H17030} The SQLite core only ever uses
  4491. ** sqlite3_mutex_try() as an optimization so this is acceptable behavior.
  4492. **
  4493. ** {H17031} The sqlite3_mutex_leave() routine exits a mutex that was
  4494. ** previously entered by the same thread. {A17032} The behavior
  4495. ** is undefined if the mutex is not currently entered by the
  4496. ** calling thread or is not currently allocated. {H17033} SQLite will
  4497. ** never do either. {END}
  4498. **
  4499. ** If the argument to sqlite3_mutex_enter(), sqlite3_mutex_try(), or
  4500. ** sqlite3_mutex_leave() is a NULL pointer, then all three routines
  4501. ** behave as no-ops.
  4502. **
  4503. ** See also: [sqlite3_mutex_held()] and [sqlite3_mutex_notheld()].
  4504. */
  4505. sqlite3_mutex *sqlite3_mutex_alloc(int);
  4506. void sqlite3_mutex_free(sqlite3_mutex*);
  4507. void sqlite3_mutex_enter(sqlite3_mutex*);
  4508. int sqlite3_mutex_try(sqlite3_mutex*);
  4509. void sqlite3_mutex_leave(sqlite3_mutex*);
  4510. /*
  4511. ** CAPI3REF: Mutex Methods Object {H17120} <S20130>
  4512. ** EXPERIMENTAL
  4513. **
  4514. ** An instance of this structure defines the low-level routines
  4515. ** used to allocate and use mutexes.
  4516. **
  4517. ** Usually, the default mutex implementations provided by SQLite are
  4518. ** sufficient, however the user has the option of substituting a custom
  4519. ** implementation for specialized deployments or systems for which SQLite
  4520. ** does not provide a suitable implementation. In this case, the user
  4521. ** creates and populates an instance of this structure to pass
  4522. ** to sqlite3_config() along with the [SQLITE_CONFIG_MUTEX] option.
  4523. ** Additionally, an instance of this structure can be used as an
  4524. ** output variable when querying the system for the current mutex
  4525. ** implementation, using the [SQLITE_CONFIG_GETMUTEX] option.
  4526. **
  4527. ** The xMutexInit method defined by this structure is invoked as
  4528. ** part of system initialization by the sqlite3_initialize() function.
  4529. ** {H17001} The xMutexInit routine shall be called by SQLite once for each
  4530. ** effective call to [sqlite3_initialize()].
  4531. **
  4532. ** The xMutexEnd method defined by this structure is invoked as
  4533. ** part of system shutdown by the sqlite3_shutdown() function. The
  4534. ** implementation of this method is expected to release all outstanding
  4535. ** resources obtained by the mutex methods implementation, especially
  4536. ** those obtained by the xMutexInit method. {H17003} The xMutexEnd()
  4537. ** interface shall be invoked once for each call to [sqlite3_shutdown()].
  4538. **
  4539. ** The remaining seven methods defined by this structure (xMutexAlloc,
  4540. ** xMutexFree, xMutexEnter, xMutexTry, xMutexLeave, xMutexHeld and
  4541. ** xMutexNotheld) implement the following interfaces (respectively):
  4542. **
  4543. ** <ul>
  4544. ** <li> [sqlite3_mutex_alloc()] </li>
  4545. ** <li> [sqlite3_mutex_free()] </li>
  4546. ** <li> [sqlite3_mutex_enter()] </li>
  4547. ** <li> [sqlite3_mutex_try()] </li>
  4548. ** <li> [sqlite3_mutex_leave()] </li>
  4549. ** <li> [sqlite3_mutex_held()] </li>
  4550. ** <li> [sqlite3_mutex_notheld()] </li>
  4551. ** </ul>
  4552. **
  4553. ** The only difference is that the public sqlite3_XXX functions enumerated
  4554. ** above silently ignore any invocations that pass a NULL pointer instead
  4555. ** of a valid mutex handle. The implementations of the methods defined
  4556. ** by this structure are not required to handle this case, the results
  4557. ** of passing a NULL pointer instead of a valid mutex handle are undefined
  4558. ** (i.e. it is acceptable to provide an implementation that segfaults if
  4559. ** it is passed a NULL pointer).
  4560. */
  4561. typedef struct sqlite3_mutex_methods sqlite3_mutex_methods;
  4562. struct sqlite3_mutex_methods {
  4563. int (*xMutexInit)(void);
  4564. int (*xMutexEnd)(void);
  4565. sqlite3_mutex *(*xMutexAlloc)(int);
  4566. void (*xMutexFree)(sqlite3_mutex *);
  4567. void (*xMutexEnter)(sqlite3_mutex *);
  4568. int (*xMutexTry)(sqlite3_mutex *);
  4569. void (*xMutexLeave)(sqlite3_mutex *);
  4570. int (*xMutexHeld)(sqlite3_mutex *);
  4571. int (*xMutexNotheld)(sqlite3_mutex *);
  4572. };
  4573. /*
  4574. ** CAPI3REF: Mutex Verification Routines {H17080} <S20130> <S30800>
  4575. **
  4576. ** The sqlite3_mutex_held() and sqlite3_mutex_notheld() routines
  4577. ** are intended for use inside assert() statements. {H17081} The SQLite core
  4578. ** never uses these routines except inside an assert() and applications
  4579. ** are advised to follow the lead of the core. {H17082} The core only
  4580. ** provides implementations for these routines when it is compiled
  4581. ** with the SQLITE_DEBUG flag. {A17087} External mutex implementations
  4582. ** are only required to provide these routines if SQLITE_DEBUG is
  4583. ** defined and if NDEBUG is not defined.
  4584. **
  4585. ** {H17083} These routines should return true if the mutex in their argument
  4586. ** is held or not held, respectively, by the calling thread.
  4587. **
  4588. ** {X17084} The implementation is not required to provided versions of these
  4589. ** routines that actually work. If the implementation does not provide working
  4590. ** versions of these routines, it should at least provide stubs that always
  4591. ** return true so that one does not get spurious assertion failures.
  4592. **
  4593. ** {H17085} If the argument to sqlite3_mutex_held() is a NULL pointer then
  4594. ** the routine should return 1. {END} This seems counter-intuitive since
  4595. ** clearly the mutex cannot be held if it does not exist. But the
  4596. ** the reason the mutex does not exist is because the build is not
  4597. ** using mutexes. And we do not want the assert() containing the
  4598. ** call to sqlite3_mutex_held() to fail, so a non-zero return is
  4599. ** the appropriate thing to do. {H17086} The sqlite3_mutex_notheld()
  4600. ** interface should also return 1 when given a NULL pointer.
  4601. */
  4602. int sqlite3_mutex_held(sqlite3_mutex*);
  4603. int sqlite3_mutex_notheld(sqlite3_mutex*);
  4604. /*
  4605. ** CAPI3REF: Mutex Types {H17001} <H17000>
  4606. **
  4607. ** The [sqlite3_mutex_alloc()] interface takes a single argument
  4608. ** which is one of these integer constants.
  4609. **
  4610. ** The set of static mutexes may change from one SQLite release to the
  4611. ** next. Applications that override the built-in mutex logic must be
  4612. ** prepared to accommodate additional static mutexes.
  4613. */
  4614. #define SQLITE_MUTEX_FAST 0
  4615. #define SQLITE_MUTEX_RECURSIVE 1
  4616. #define SQLITE_MUTEX_STATIC_MASTER 2
  4617. #define SQLITE_MUTEX_STATIC_MEM 3 /* sqlite3_malloc() */
  4618. #define SQLITE_MUTEX_STATIC_MEM2 4 /* NOT USED */
  4619. #define SQLITE_MUTEX_STATIC_OPEN 4 /* sqlite3BtreeOpen() */
  4620. #define SQLITE_MUTEX_STATIC_PRNG 5 /* sqlite3_random() */
  4621. #define SQLITE_MUTEX_STATIC_LRU 6 /* lru page list */
  4622. #define SQLITE_MUTEX_STATIC_LRU2 7 /* lru page list */
  4623. /*
  4624. ** CAPI3REF: Retrieve the mutex for a database connection {H17002} <H17000>
  4625. **
  4626. ** This interface returns a pointer the [sqlite3_mutex] object that
  4627. ** serializes access to the [database connection] given in the argument
  4628. ** when the [threading mode] is Serialized.
  4629. ** If the [threading mode] is Single-thread or Multi-thread then this
  4630. ** routine returns a NULL pointer.
  4631. */
  4632. sqlite3_mutex *sqlite3_db_mutex(sqlite3*);
  4633. /*
  4634. ** CAPI3REF: Low-Level Control Of Database Files {H11300} <S30800>
  4635. **
  4636. ** {H11301} The [sqlite3_file_control()] interface makes a direct call to the
  4637. ** xFileControl method for the [sqlite3_io_methods] object associated
  4638. ** with a particular database identified by the second argument. {H11302} The
  4639. ** name of the database is the name assigned to the database by the
  4640. ** <a href="lang_attach.html">ATTACH</a> SQL command that opened the
  4641. ** database. {H11303} To control the main database file, use the name "main"
  4642. ** or a NULL pointer. {H11304} The third and fourth parameters to this routine
  4643. ** are passed directly through to the second and third parameters of
  4644. ** the xFileControl method. {H11305} The return value of the xFileControl
  4645. ** method becomes the return value of this routine.
  4646. **
  4647. ** {H11306} If the second parameter (zDbName) does not match the name of any
  4648. ** open database file, then SQLITE_ERROR is returned. {H11307} This error
  4649. ** code is not remembered and will not be recalled by [sqlite3_errcode()]
  4650. ** or [sqlite3_errmsg()]. {A11308} The underlying xFileControl method might
  4651. ** also return SQLITE_ERROR. {A11309} There is no way to distinguish between
  4652. ** an incorrect zDbName and an SQLITE_ERROR return from the underlying
  4653. ** xFileControl method. {END}
  4654. **
  4655. ** See also: [SQLITE_FCNTL_LOCKSTATE]
  4656. */
  4657. int sqlite3_file_control(sqlite3*, const char *zDbName, int op, void*);
  4658. /*
  4659. ** CAPI3REF: Testing Interface {H11400} <S30800>
  4660. **
  4661. ** The sqlite3_test_control() interface is used to read out internal
  4662. ** state of SQLite and to inject faults into SQLite for testing
  4663. ** purposes. The first parameter is an operation code that determines
  4664. ** the number, meaning, and operation of all subsequent parameters.
  4665. **
  4666. ** This interface is not for use by applications. It exists solely
  4667. ** for verifying the correct operation of the SQLite library. Depending
  4668. ** on how the SQLite library is compiled, this interface might not exist.
  4669. **
  4670. ** The details of the operation codes, their meanings, the parameters
  4671. ** they take, and what they do are all subject to change without notice.
  4672. ** Unlike most of the SQLite API, this function is not guaranteed to
  4673. ** operate consistently from one release to the next.
  4674. */
  4675. int sqlite3_test_control(int op, ...);
  4676. /*
  4677. ** CAPI3REF: Testing Interface Operation Codes {H11410} <H11400>
  4678. **
  4679. ** These constants are the valid operation code parameters used
  4680. ** as the first argument to [sqlite3_test_control()].
  4681. **
  4682. ** These parameters and their meanings are subject to change
  4683. ** without notice. These values are for testing purposes only.
  4684. ** Applications should not use any of these parameters or the
  4685. ** [sqlite3_test_control()] interface.
  4686. */
  4687. #define SQLITE_TESTCTRL_PRNG_SAVE 5
  4688. #define SQLITE_TESTCTRL_PRNG_RESTORE 6
  4689. #define SQLITE_TESTCTRL_PRNG_RESET 7
  4690. #define SQLITE_TESTCTRL_BITVEC_TEST 8
  4691. #define SQLITE_TESTCTRL_FAULT_INSTALL 9
  4692. #define SQLITE_TESTCTRL_BENIGN_MALLOC_HOOKS 10
  4693. #define SQLITE_TESTCTRL_PENDING_BYTE 11
  4694. /*
  4695. ** CAPI3REF: SQLite Runtime Status {H17200} <S60200>
  4696. ** EXPERIMENTAL
  4697. **
  4698. ** This interface is used to retrieve runtime status information
  4699. ** about the preformance of SQLite, and optionally to reset various
  4700. ** highwater marks. The first argument is an integer code for
  4701. ** the specific parameter to measure. Recognized integer codes
  4702. ** are of the form [SQLITE_STATUS_MEMORY_USED | SQLITE_STATUS_...].
  4703. ** The current value of the parameter is returned into *pCurrent.
  4704. ** The highest recorded value is returned in *pHighwater. If the
  4705. ** resetFlag is true, then the highest record value is reset after
  4706. ** *pHighwater is written. Some parameters do not record the highest
  4707. ** value. For those parameters
  4708. ** nothing is written into *pHighwater and the resetFlag is ignored.
  4709. ** Other parameters record only the highwater mark and not the current
  4710. ** value. For these latter parameters nothing is written into *pCurrent.
  4711. **
  4712. ** This routine returns SQLITE_OK on success and a non-zero
  4713. ** [error code] on failure.
  4714. **
  4715. ** This routine is threadsafe but is not atomic. This routine can
  4716. ** called while other threads are running the same or different SQLite
  4717. ** interfaces. However the values returned in *pCurrent and
  4718. ** *pHighwater reflect the status of SQLite at different points in time
  4719. ** and it is possible that another thread might change the parameter
  4720. ** in between the times when *pCurrent and *pHighwater are written.
  4721. **
  4722. ** See also: [sqlite3_db_status()]
  4723. */
  4724. SQLITE_EXPERIMENTAL int sqlite3_status(int op, int *pCurrent, int *pHighwater, int resetFlag);
  4725. /*
  4726. ** CAPI3REF: Status Parameters {H17250} <H17200>
  4727. ** EXPERIMENTAL
  4728. **
  4729. ** These integer constants designate various run-time status parameters
  4730. ** that can be returned by [sqlite3_status()].
  4731. **
  4732. ** <dl>
  4733. ** <dt>SQLITE_STATUS_MEMORY_USED</dt>
  4734. ** <dd>This parameter is the current amount of memory checked out
  4735. ** using [sqlite3_malloc()], either directly or indirectly. The
  4736. ** figure includes calls made to [sqlite3_malloc()] by the application
  4737. ** and internal memory usage by the SQLite library. Scratch memory
  4738. ** controlled by [SQLITE_CONFIG_SCRATCH] and auxiliary page-cache
  4739. ** memory controlled by [SQLITE_CONFIG_PAGECACHE] is not included in
  4740. ** this parameter. The amount returned is the sum of the allocation
  4741. ** sizes as reported by the xSize method in [sqlite3_mem_methods].</dd>
  4742. **
  4743. ** <dt>SQLITE_STATUS_MALLOC_SIZE</dt>
  4744. ** <dd>This parameter records the largest memory allocation request
  4745. ** handed to [sqlite3_malloc()] or [sqlite3_realloc()] (or their
  4746. ** internal equivalents). Only the value returned in the
  4747. ** *pHighwater parameter to [sqlite3_status()] is of interest.
  4748. ** The value written into the *pCurrent parameter is undefined.</dd>
  4749. **
  4750. ** <dt>SQLITE_STATUS_PAGECACHE_USED</dt>
  4751. ** <dd>This parameter returns the number of pages used out of the
  4752. ** [pagecache memory allocator] that was configured using
  4753. ** [SQLITE_CONFIG_PAGECACHE]. The
  4754. ** value returned is in pages, not in bytes.</dd>
  4755. **
  4756. ** <dt>SQLITE_STATUS_PAGECACHE_OVERFLOW</dt>
  4757. ** <dd>This parameter returns the number of bytes of page cache
  4758. ** allocation which could not be statisfied by the [SQLITE_CONFIG_PAGECACHE]
  4759. ** buffer and where forced to overflow to [sqlite3_malloc()]. The
  4760. ** returned value includes allocations that overflowed because they
  4761. ** where too large (they were larger than the "sz" parameter to
  4762. ** [SQLITE_CONFIG_PAGECACHE]) and allocations that overflowed because
  4763. ** no space was left in the page cache.</dd>
  4764. **
  4765. ** <dt>SQLITE_STATUS_PAGECACHE_SIZE</dt>
  4766. ** <dd>This parameter records the largest memory allocation request
  4767. ** handed to [pagecache memory allocator]. Only the value returned in the
  4768. ** *pHighwater parameter to [sqlite3_status()] is of interest.
  4769. ** The value written into the *pCurrent parameter is undefined.</dd>
  4770. **
  4771. ** <dt>SQLITE_STATUS_SCRATCH_USED</dt>
  4772. ** <dd>This parameter returns the number of allocations used out of the
  4773. ** [scratch memory allocator] configured using
  4774. ** [SQLITE_CONFIG_SCRATCH]. The value returned is in allocations, not
  4775. ** in bytes. Since a single thread may only have one scratch allocation
  4776. ** outstanding at time, this parameter also reports the number of threads
  4777. ** using scratch memory at the same time.</dd>
  4778. **
  4779. ** <dt>SQLITE_STATUS_SCRATCH_OVERFLOW</dt>
  4780. ** <dd>This parameter returns the number of bytes of scratch memory
  4781. ** allocation which could not be statisfied by the [SQLITE_CONFIG_SCRATCH]
  4782. ** buffer and where forced to overflow to [sqlite3_malloc()]. The values
  4783. ** returned include overflows because the requested allocation was too
  4784. ** larger (that is, because the requested allocation was larger than the
  4785. ** "sz" parameter to [SQLITE_CONFIG_SCRATCH]) and because no scratch buffer
  4786. ** slots were available.
  4787. ** </dd>
  4788. **
  4789. ** <dt>SQLITE_STATUS_SCRATCH_SIZE</dt>
  4790. ** <dd>This parameter records the largest memory allocation request
  4791. ** handed to [scratch memory allocator]. Only the value returned in the
  4792. ** *pHighwater parameter to [sqlite3_status()] is of interest.
  4793. ** The value written into the *pCurrent parameter is undefined.</dd>
  4794. **
  4795. ** <dt>SQLITE_STATUS_PARSER_STACK</dt>
  4796. ** <dd>This parameter records the deepest parser stack. It is only
  4797. ** meaningful if SQLite is compiled with [YYTRACKMAXSTACKDEPTH].</dd>
  4798. ** </dl>
  4799. **
  4800. ** New status parameters may be added from time to time.
  4801. */
  4802. #define SQLITE_STATUS_MEMORY_USED 0
  4803. #define SQLITE_STATUS_PAGECACHE_USED 1
  4804. #define SQLITE_STATUS_PAGECACHE_OVERFLOW 2
  4805. #define SQLITE_STATUS_SCRATCH_USED 3
  4806. #define SQLITE_STATUS_SCRATCH_OVERFLOW 4
  4807. #define SQLITE_STATUS_MALLOC_SIZE 5
  4808. #define SQLITE_STATUS_PARSER_STACK 6
  4809. #define SQLITE_STATUS_PAGECACHE_SIZE 7
  4810. #define SQLITE_STATUS_SCRATCH_SIZE 8
  4811. /*
  4812. ** CAPI3REF: Database Connection Status {H17500} <S60200>
  4813. ** EXPERIMENTAL
  4814. **
  4815. ** This interface is used to retrieve runtime status information
  4816. ** about a single [database connection]. The first argument is the
  4817. ** database connection object to be interrogated. The second argument
  4818. ** is the parameter to interrogate. Currently, the only allowed value
  4819. ** for the second parameter is [SQLITE_DBSTATUS_LOOKASIDE_USED].
  4820. ** Additional options will likely appear in future releases of SQLite.
  4821. **
  4822. ** The current value of the requested parameter is written into *pCur
  4823. ** and the highest instantaneous value is written into *pHiwtr. If
  4824. ** the resetFlg is true, then the highest instantaneous value is
  4825. ** reset back down to the current value.
  4826. **
  4827. ** See also: [sqlite3_status()] and [sqlite3_stmt_status()].
  4828. */
  4829. SQLITE_EXPERIMENTAL int sqlite3_db_status(sqlite3*, int op, int *pCur, int *pHiwtr, int resetFlg);
  4830. /*
  4831. ** CAPI3REF: Status Parameters for database connections {H17520} <H17500>
  4832. ** EXPERIMENTAL
  4833. **
  4834. ** Status verbs for [sqlite3_db_status()].
  4835. **
  4836. ** <dl>
  4837. ** <dt>SQLITE_DBSTATUS_LOOKASIDE_USED</dt>
  4838. ** <dd>This parameter returns the number of lookaside memory slots currently
  4839. ** checked out.</dd>
  4840. ** </dl>
  4841. */
  4842. #define SQLITE_DBSTATUS_LOOKASIDE_USED 0
  4843. /*
  4844. ** CAPI3REF: Prepared Statement Status {H17550} <S60200>
  4845. ** EXPERIMENTAL
  4846. **
  4847. ** Each prepared statement maintains various
  4848. ** [SQLITE_STMTSTATUS_SORT | counters] that measure the number
  4849. ** of times it has performed specific operations. These counters can
  4850. ** be used to monitor the performance characteristics of the prepared
  4851. ** statements. For example, if the number of table steps greatly exceeds
  4852. ** the number of table searches or result rows, that would tend to indicate
  4853. ** that the prepared statement is using a full table scan rather than
  4854. ** an index.
  4855. **
  4856. ** This interface is used to retrieve and reset counter values from
  4857. ** a [prepared statement]. The first argument is the prepared statement
  4858. ** object to be interrogated. The second argument
  4859. ** is an integer code for a specific [SQLITE_STMTSTATUS_SORT | counter]
  4860. ** to be interrogated.
  4861. ** The current value of the requested counter is returned.
  4862. ** If the resetFlg is true, then the counter is reset to zero after this
  4863. ** interface call returns.
  4864. **
  4865. ** See also: [sqlite3_status()] and [sqlite3_db_status()].
  4866. */
  4867. SQLITE_EXPERIMENTAL int sqlite3_stmt_status(sqlite3_stmt*, int op,int resetFlg);
  4868. /*
  4869. ** CAPI3REF: Status Parameters for prepared statements {H17570} <H17550>
  4870. ** EXPERIMENTAL
  4871. **
  4872. ** These preprocessor macros define integer codes that name counter
  4873. ** values associated with the [sqlite3_stmt_status()] interface.
  4874. ** The meanings of the various counters are as follows:
  4875. **
  4876. ** <dl>
  4877. ** <dt>SQLITE_STMTSTATUS_FULLSCAN_STEP</dt>
  4878. ** <dd>This is the number of times that SQLite has stepped forward in
  4879. ** a table as part of a full table scan. Large numbers for this counter
  4880. ** may indicate opportunities for performance improvement through
  4881. ** careful use of indices.</dd>
  4882. **
  4883. ** <dt>SQLITE_STMTSTATUS_SORT</dt>
  4884. ** <dd>This is the number of sort operations that have occurred.
  4885. ** A non-zero value in this counter may indicate an opportunity to
  4886. ** improvement performance through careful use of indices.</dd>
  4887. **
  4888. ** </dl>
  4889. */
  4890. #define SQLITE_STMTSTATUS_FULLSCAN_STEP 1
  4891. #define SQLITE_STMTSTATUS_SORT 2
  4892. /*
  4893. ** CAPI3REF: Custom Page Cache Object
  4894. ** EXPERIMENTAL
  4895. **
  4896. ** The sqlite3_pcache type is opaque. It is implemented by
  4897. ** the pluggable module. The SQLite core has no knowledge of
  4898. ** its size or internal structure and never deals with the
  4899. ** sqlite3_pcache object except by holding and passing pointers
  4900. ** to the object.
  4901. **
  4902. ** See [sqlite3_pcache_methods] for additional information.
  4903. */
  4904. typedef struct sqlite3_pcache sqlite3_pcache;
  4905. /*
  4906. ** CAPI3REF: Application Defined Page Cache.
  4907. ** EXPERIMENTAL
  4908. **
  4909. ** The [sqlite3_config]([SQLITE_CONFIG_PCACHE], ...) interface can
  4910. ** register an alternative page cache implementation by passing in an
  4911. ** instance of the sqlite3_pcache_methods structure. The majority of the
  4912. ** heap memory used by sqlite is used by the page cache to cache data read
  4913. ** from, or ready to be written to, the database file. By implementing a
  4914. ** custom page cache using this API, an application can control more
  4915. ** precisely the amount of memory consumed by sqlite, the way in which
  4916. ** said memory is allocated and released, and the policies used to
  4917. ** determine exactly which parts of a database file are cached and for
  4918. ** how long.
  4919. **
  4920. ** The contents of the structure are copied to an internal buffer by sqlite
  4921. ** within the call to [sqlite3_config].
  4922. **
  4923. ** The xInit() method is called once for each call to [sqlite3_initialize()]
  4924. ** (usually only once during the lifetime of the process). It is passed
  4925. ** a copy of the sqlite3_pcache_methods.pArg value. It can be used to set
  4926. ** up global structures and mutexes required by the custom page cache
  4927. ** implementation. The xShutdown() method is called from within
  4928. ** [sqlite3_shutdown()], if the application invokes this API. It can be used
  4929. ** to clean up any outstanding resources before process shutdown, if required.
  4930. **
  4931. ** The xCreate() method is used to construct a new cache instance. The
  4932. ** first parameter, szPage, is the size in bytes of the pages that must
  4933. ** be allocated by the cache. szPage will not be a power of two. The
  4934. ** second argument, bPurgeable, is true if the cache being created will
  4935. ** be used to cache database pages read from a file stored on disk, or
  4936. ** false if it is used for an in-memory database. The cache implementation
  4937. ** does not have to do anything special based on the value of bPurgeable,
  4938. ** it is purely advisory.
  4939. **
  4940. ** The xCachesize() method may be called at any time by SQLite to set the
  4941. ** suggested maximum cache-size (number of pages stored by) the cache
  4942. ** instance passed as the first argument. This is the value configured using
  4943. ** the SQLite "[PRAGMA cache_size]" command. As with the bPurgeable parameter,
  4944. ** the implementation is not required to do anything special with this
  4945. ** value, it is advisory only.
  4946. **
  4947. ** The xPagecount() method should return the number of pages currently
  4948. ** stored in the cache supplied as an argument.
  4949. **
  4950. ** The xFetch() method is used to fetch a page and return a pointer to it.
  4951. ** A 'page', in this context, is a buffer of szPage bytes aligned at an
  4952. ** 8-byte boundary. The page to be fetched is determined by the key. The
  4953. ** mimimum key value is 1. After it has been retrieved using xFetch, the page
  4954. ** is considered to be pinned.
  4955. **
  4956. ** If the requested page is already in the page cache, then a pointer to
  4957. ** the cached buffer should be returned with its contents intact. If the
  4958. ** page is not already in the cache, then the expected behaviour of the
  4959. ** cache is determined by the value of the createFlag parameter passed
  4960. ** to xFetch, according to the following table:
  4961. **
  4962. ** <table border=1 width=85% align=center>
  4963. ** <tr><th>createFlag<th>Expected Behaviour
  4964. ** <tr><td>0<td>NULL should be returned. No new cache entry is created.
  4965. ** <tr><td>1<td>If createFlag is set to 1, this indicates that
  4966. ** SQLite is holding pinned pages that can be unpinned
  4967. ** by writing their contents to the database file (a
  4968. ** relatively expensive operation). In this situation the
  4969. ** cache implementation has two choices: it can return NULL,
  4970. ** in which case SQLite will attempt to unpin one or more
  4971. ** pages before re-requesting the same page, or it can
  4972. ** allocate a new page and return a pointer to it. If a new
  4973. ** page is allocated, then the first sizeof(void*) bytes of
  4974. ** it (at least) must be zeroed before it is returned.
  4975. ** <tr><td>2<td>If createFlag is set to 2, then SQLite is not holding any
  4976. ** pinned pages associated with the specific cache passed
  4977. ** as the first argument to xFetch() that can be unpinned. The
  4978. ** cache implementation should attempt to allocate a new
  4979. ** cache entry and return a pointer to it. Again, the first
  4980. ** sizeof(void*) bytes of the page should be zeroed before
  4981. ** it is returned. If the xFetch() method returns NULL when
  4982. ** createFlag==2, SQLite assumes that a memory allocation
  4983. ** failed and returns SQLITE_NOMEM to the user.
  4984. ** </table>
  4985. **
  4986. ** xUnpin() is called by SQLite with a pointer to a currently pinned page
  4987. ** as its second argument. If the third parameter, discard, is non-zero,
  4988. ** then the page should be evicted from the cache. In this case SQLite
  4989. ** assumes that the next time the page is retrieved from the cache using
  4990. ** the xFetch() method, it will be zeroed. If the discard parameter is
  4991. ** zero, then the page is considered to be unpinned. The cache implementation
  4992. ** may choose to reclaim (free or recycle) unpinned pages at any time.
  4993. ** SQLite assumes that next time the page is retrieved from the cache
  4994. ** it will either be zeroed, or contain the same data that it did when it
  4995. ** was unpinned.
  4996. **
  4997. ** The cache is not required to perform any reference counting. A single
  4998. ** call to xUnpin() unpins the page regardless of the number of prior calls
  4999. ** to xFetch().
  5000. **
  5001. ** The xRekey() method is used to change the key value associated with the
  5002. ** page passed as the second argument from oldKey to newKey. If the cache
  5003. ** previously contains an entry associated with newKey, it should be
  5004. ** discarded. Any prior cache entry associated with newKey is guaranteed not
  5005. ** to be pinned.
  5006. **
  5007. ** When SQLite calls the xTruncate() method, the cache must discard all
  5008. ** existing cache entries with page numbers (keys) greater than or equal
  5009. ** to the value of the iLimit parameter passed to xTruncate(). If any
  5010. ** of these pages are pinned, they are implicitly unpinned, meaning that
  5011. ** they can be safely discarded.
  5012. **
  5013. ** The xDestroy() method is used to delete a cache allocated by xCreate().
  5014. ** All resources associated with the specified cache should be freed. After
  5015. ** calling the xDestroy() method, SQLite considers the [sqlite3_pcache*]
  5016. ** handle invalid, and will not use it with any other sqlite3_pcache_methods
  5017. ** functions.
  5018. */
  5019. typedef struct sqlite3_pcache_methods sqlite3_pcache_methods;
  5020. struct sqlite3_pcache_methods {
  5021. void *pArg;
  5022. int (*xInit)(void*);
  5023. void (*xShutdown)(void*);
  5024. sqlite3_pcache *(*xCreate)(int szPage, int bPurgeable);
  5025. void (*xCachesize)(sqlite3_pcache*, int nCachesize);
  5026. int (*xPagecount)(sqlite3_pcache*);
  5027. void *(*xFetch)(sqlite3_pcache*, unsigned key, int createFlag);
  5028. void (*xUnpin)(sqlite3_pcache*, void*, int discard);
  5029. void (*xRekey)(sqlite3_pcache*, void*, unsigned oldKey, unsigned newKey);
  5030. void (*xTruncate)(sqlite3_pcache*, unsigned iLimit);
  5031. void (*xDestroy)(sqlite3_pcache*);
  5032. };
  5033. /*
  5034. ** CAPI3REF: Online Backup Object
  5035. ** EXPERIMENTAL
  5036. **
  5037. ** The sqlite3_backup object records state information about an ongoing
  5038. ** online backup operation. The sqlite3_backup object is created by
  5039. ** a call to [sqlite3_backup_init()] and is destroyed by a call to
  5040. ** [sqlite3_backup_finish()].
  5041. **
  5042. ** See Also: [Using the SQLite Online Backup API]
  5043. */
  5044. typedef struct sqlite3_backup sqlite3_backup;
  5045. /*
  5046. ** CAPI3REF: Online Backup API.
  5047. ** EXPERIMENTAL
  5048. **
  5049. ** This API is used to overwrite the contents of one database with that
  5050. ** of another. It is useful either for creating backups of databases or
  5051. ** for copying in-memory databases to or from persistent files.
  5052. **
  5053. ** See Also: [Using the SQLite Online Backup API]
  5054. **
  5055. ** Exclusive access is required to the destination database for the
  5056. ** duration of the operation. However the source database is only
  5057. ** read-locked while it is actually being read, it is not locked
  5058. ** continuously for the entire operation. Thus, the backup may be
  5059. ** performed on a live database without preventing other users from
  5060. ** writing to the database for an extended period of time.
  5061. **
  5062. ** To perform a backup operation:
  5063. ** <ol>
  5064. ** <li><b>sqlite3_backup_init()</b> is called once to initialize the
  5065. ** backup,
  5066. ** <li><b>sqlite3_backup_step()</b> is called one or more times to transfer
  5067. ** the data between the two databases, and finally
  5068. ** <li><b>sqlite3_backup_finish()</b> is called to release all resources
  5069. ** associated with the backup operation.
  5070. ** </ol>
  5071. ** There should be exactly one call to sqlite3_backup_finish() for each
  5072. ** successful call to sqlite3_backup_init().
  5073. **
  5074. ** <b>sqlite3_backup_init()</b>
  5075. **
  5076. ** The first two arguments passed to [sqlite3_backup_init()] are the database
  5077. ** handle associated with the destination database and the database name
  5078. ** used to attach the destination database to the handle. The database name
  5079. ** is "main" for the main database, "temp" for the temporary database, or
  5080. ** the name specified as part of the [ATTACH] statement if the destination is
  5081. ** an attached database. The third and fourth arguments passed to
  5082. ** sqlite3_backup_init() identify the [database connection]
  5083. ** and database name used
  5084. ** to access the source database. The values passed for the source and
  5085. ** destination [database connection] parameters must not be the same.
  5086. **
  5087. ** If an error occurs within sqlite3_backup_init(), then NULL is returned
  5088. ** and an error code and error message written into the [database connection]
  5089. ** passed as the first argument. They may be retrieved using the
  5090. ** [sqlite3_errcode()], [sqlite3_errmsg()], and [sqlite3_errmsg16()] functions.
  5091. ** Otherwise, if successful, a pointer to an [sqlite3_backup] object is
  5092. ** returned. This pointer may be used with the sqlite3_backup_step() and
  5093. ** sqlite3_backup_finish() functions to perform the specified backup
  5094. ** operation.
  5095. **
  5096. ** <b>sqlite3_backup_step()</b>
  5097. **
  5098. ** Function [sqlite3_backup_step()] is used to copy up to nPage pages between
  5099. ** the source and destination databases, where nPage is the value of the
  5100. ** second parameter passed to sqlite3_backup_step(). If nPage is a negative
  5101. ** value, all remaining source pages are copied. If the required pages are
  5102. ** succesfully copied, but there are still more pages to copy before the
  5103. ** backup is complete, it returns [SQLITE_OK]. If no error occured and there
  5104. ** are no more pages to copy, then [SQLITE_DONE] is returned. If an error
  5105. ** occurs, then an SQLite error code is returned. As well as [SQLITE_OK] and
  5106. ** [SQLITE_DONE], a call to sqlite3_backup_step() may return [SQLITE_READONLY],
  5107. ** [SQLITE_NOMEM], [SQLITE_BUSY], [SQLITE_LOCKED], or an
  5108. ** [SQLITE_IOERR_ACCESS | SQLITE_IOERR_XXX] extended error code.
  5109. **
  5110. ** As well as the case where the destination database file was opened for
  5111. ** read-only access, sqlite3_backup_step() may return [SQLITE_READONLY] if
  5112. ** the destination is an in-memory database with a different page size
  5113. ** from the source database.
  5114. **
  5115. ** If sqlite3_backup_step() cannot obtain a required file-system lock, then
  5116. ** the [sqlite3_busy_handler | busy-handler function]
  5117. ** is invoked (if one is specified). If the
  5118. ** busy-handler returns non-zero before the lock is available, then
  5119. ** [SQLITE_BUSY] is returned to the caller. In this case the call to
  5120. ** sqlite3_backup_step() can be retried later. If the source
  5121. ** [database connection]
  5122. ** is being used to write to the source database when sqlite3_backup_step()
  5123. ** is called, then [SQLITE_LOCKED] is returned immediately. Again, in this
  5124. ** case the call to sqlite3_backup_step() can be retried later on. If
  5125. ** [SQLITE_IOERR_ACCESS | SQLITE_IOERR_XXX], [SQLITE_NOMEM], or
  5126. ** [SQLITE_READONLY] is returned, then
  5127. ** there is no point in retrying the call to sqlite3_backup_step(). These
  5128. ** errors are considered fatal. At this point the application must accept
  5129. ** that the backup operation has failed and pass the backup operation handle
  5130. ** to the sqlite3_backup_finish() to release associated resources.
  5131. **
  5132. ** Following the first call to sqlite3_backup_step(), an exclusive lock is
  5133. ** obtained on the destination file. It is not released until either
  5134. ** sqlite3_backup_finish() is called or the backup operation is complete
  5135. ** and sqlite3_backup_step() returns [SQLITE_DONE]. Additionally, each time
  5136. ** a call to sqlite3_backup_step() is made a [shared lock] is obtained on
  5137. ** the source database file. This lock is released before the
  5138. ** sqlite3_backup_step() call returns. Because the source database is not
  5139. ** locked between calls to sqlite3_backup_step(), it may be modified mid-way
  5140. ** through the backup procedure. If the source database is modified by an
  5141. ** external process or via a database connection other than the one being
  5142. ** used by the backup operation, then the backup will be transparently
  5143. ** restarted by the next call to sqlite3_backup_step(). If the source
  5144. ** database is modified by the using the same database connection as is used
  5145. ** by the backup operation, then the backup database is transparently
  5146. ** updated at the same time.
  5147. **
  5148. ** <b>sqlite3_backup_finish()</b>
  5149. **
  5150. ** Once sqlite3_backup_step() has returned [SQLITE_DONE], or when the
  5151. ** application wishes to abandon the backup operation, the [sqlite3_backup]
  5152. ** object should be passed to sqlite3_backup_finish(). This releases all
  5153. ** resources associated with the backup operation. If sqlite3_backup_step()
  5154. ** has not yet returned [SQLITE_DONE], then any active write-transaction on the
  5155. ** destination database is rolled back. The [sqlite3_backup] object is invalid
  5156. ** and may not be used following a call to sqlite3_backup_finish().
  5157. **
  5158. ** The value returned by sqlite3_backup_finish is [SQLITE_OK] if no error
  5159. ** occurred, regardless or whether or not sqlite3_backup_step() was called
  5160. ** a sufficient number of times to complete the backup operation. Or, if
  5161. ** an out-of-memory condition or IO error occured during a call to
  5162. ** sqlite3_backup_step() then [SQLITE_NOMEM] or an
  5163. ** [SQLITE_IOERR_ACCESS | SQLITE_IOERR_XXX] error code
  5164. ** is returned. In this case the error code and an error message are
  5165. ** written to the destination [database connection].
  5166. **
  5167. ** A return of [SQLITE_BUSY] or [SQLITE_LOCKED] from sqlite3_backup_step() is
  5168. ** not a permanent error and does not affect the return value of
  5169. ** sqlite3_backup_finish().
  5170. **
  5171. ** <b>sqlite3_backup_remaining(), sqlite3_backup_pagecount()</b>
  5172. **
  5173. ** Each call to sqlite3_backup_step() sets two values stored internally
  5174. ** by an [sqlite3_backup] object. The number of pages still to be backed
  5175. ** up, which may be queried by sqlite3_backup_remaining(), and the total
  5176. ** number of pages in the source database file, which may be queried by
  5177. ** sqlite3_backup_pagecount().
  5178. **
  5179. ** The values returned by these functions are only updated by
  5180. ** sqlite3_backup_step(). If the source database is modified during a backup
  5181. ** operation, then the values are not updated to account for any extra
  5182. ** pages that need to be updated or the size of the source database file
  5183. ** changing.
  5184. **
  5185. ** <b>Concurrent Usage of Database Handles</b>
  5186. **
  5187. ** The source [database connection] may be used by the application for other
  5188. ** purposes while a backup operation is underway or being initialized.
  5189. ** If SQLite is compiled and configured to support threadsafe database
  5190. ** connections, then the source database connection may be used concurrently
  5191. ** from within other threads.
  5192. **
  5193. ** However, the application must guarantee that the destination database
  5194. ** connection handle is not passed to any other API (by any thread) after
  5195. ** sqlite3_backup_init() is called and before the corresponding call to
  5196. ** sqlite3_backup_finish(). Unfortunately SQLite does not currently check
  5197. ** for this, if the application does use the destination [database connection]
  5198. ** for some other purpose during a backup operation, things may appear to
  5199. ** work correctly but in fact be subtly malfunctioning. Use of the
  5200. ** destination database connection while a backup is in progress might
  5201. ** also cause a mutex deadlock.
  5202. **
  5203. ** Furthermore, if running in [shared cache mode], the application must
  5204. ** guarantee that the shared cache used by the destination database
  5205. ** is not accessed while the backup is running. In practice this means
  5206. ** that the application must guarantee that the file-system file being
  5207. ** backed up to is not accessed by any connection within the process,
  5208. ** not just the specific connection that was passed to sqlite3_backup_init().
  5209. **
  5210. ** The [sqlite3_backup] object itself is partially threadsafe. Multiple
  5211. ** threads may safely make multiple concurrent calls to sqlite3_backup_step().
  5212. ** However, the sqlite3_backup_remaining() and sqlite3_backup_pagecount()
  5213. ** APIs are not strictly speaking threadsafe. If they are invoked at the
  5214. ** same time as another thread is invoking sqlite3_backup_step() it is
  5215. ** possible that they return invalid values.
  5216. */
  5217. sqlite3_backup *sqlite3_backup_init(
  5218. sqlite3 *pDest, /* Destination database handle */
  5219. const char *zDestName, /* Destination database name */
  5220. sqlite3 *pSource, /* Source database handle */
  5221. const char *zSourceName /* Source database name */
  5222. );
  5223. int sqlite3_backup_step(sqlite3_backup *p, int nPage);
  5224. int sqlite3_backup_finish(sqlite3_backup *p);
  5225. int sqlite3_backup_remaining(sqlite3_backup *p);
  5226. int sqlite3_backup_pagecount(sqlite3_backup *p);
  5227. /*
  5228. ** CAPI3REF: Unlock Notification
  5229. ** EXPERIMENTAL
  5230. **
  5231. ** When running in shared-cache mode, a database operation may fail with
  5232. ** an [SQLITE_LOCKED] error if the required locks on the shared-cache or
  5233. ** individual tables within the shared-cache cannot be obtained. See
  5234. ** [SQLite Shared-Cache Mode] for a description of shared-cache locking.
  5235. ** This API may be used to register a callback that SQLite will invoke
  5236. ** when the connection currently holding the required lock relinquishes it.
  5237. ** This API is only available if the library was compiled with the
  5238. ** [SQLITE_ENABLE_UNLOCK_NOTIFY] C-preprocessor symbol defined.
  5239. **
  5240. ** See Also: [Using the SQLite Unlock Notification Feature].
  5241. **
  5242. ** Shared-cache locks are released when a database connection concludes
  5243. ** its current transaction, either by committing it or rolling it back.
  5244. **
  5245. ** When a connection (known as the blocked connection) fails to obtain a
  5246. ** shared-cache lock and SQLITE_LOCKED is returned to the caller, the
  5247. ** identity of the database connection (the blocking connection) that
  5248. ** has locked the required resource is stored internally. After an
  5249. ** application receives an SQLITE_LOCKED error, it may call the
  5250. ** sqlite3_unlock_notify() method with the blocked connection handle as
  5251. ** the first argument to register for a callback that will be invoked
  5252. ** when the blocking connections current transaction is concluded. The
  5253. ** callback is invoked from within the [sqlite3_step] or [sqlite3_close]
  5254. ** call that concludes the blocking connections transaction.
  5255. **
  5256. ** If sqlite3_unlock_notify() is called in a multi-threaded application,
  5257. ** there is a chance that the blocking connection will have already
  5258. ** concluded its transaction by the time sqlite3_unlock_notify() is invoked.
  5259. ** If this happens, then the specified callback is invoked immediately,
  5260. ** from within the call to sqlite3_unlock_notify().
  5261. **
  5262. ** If the blocked connection is attempting to obtain a write-lock on a
  5263. ** shared-cache table, and more than one other connection currently holds
  5264. ** a read-lock on the same table, then SQLite arbitrarily selects one of
  5265. ** the other connections to use as the blocking connection.
  5266. **
  5267. ** There may be at most one unlock-notify callback registered by a
  5268. ** blocked connection. If sqlite3_unlock_notify() is called when the
  5269. ** blocked connection already has a registered unlock-notify callback,
  5270. ** then the new callback replaces the old. If sqlite3_unlock_notify() is
  5271. ** called with a NULL pointer as its second argument, then any existing
  5272. ** unlock-notify callback is cancelled. The blocked connections
  5273. ** unlock-notify callback may also be canceled by closing the blocked
  5274. ** connection using [sqlite3_close()].
  5275. **
  5276. ** The unlock-notify callback is not reentrant. If an application invokes
  5277. ** any sqlite3_xxx API functions from within an unlock-notify callback, a
  5278. ** crash or deadlock may be the result.
  5279. **
  5280. ** Unless deadlock is detected (see below), sqlite3_unlock_notify() always
  5281. ** returns SQLITE_OK.
  5282. **
  5283. ** <b>Callback Invocation Details</b>
  5284. **
  5285. ** When an unlock-notify callback is registered, the application provides a
  5286. ** single void* pointer that is passed to the callback when it is invoked.
  5287. ** However, the signature of the callback function allows SQLite to pass
  5288. ** it an array of void* context pointers. The first argument passed to
  5289. ** an unlock-notify callback is a pointer to an array of void* pointers,
  5290. ** and the second is the number of entries in the array.
  5291. **
  5292. ** When a blocking connections transaction is concluded, there may be
  5293. ** more than one blocked connection that has registered for an unlock-notify
  5294. ** callback. If two or more such blocked connections have specified the
  5295. ** same callback function, then instead of invoking the callback function
  5296. ** multiple times, it is invoked once with the set of void* context pointers
  5297. ** specified by the blocked connections bundled together into an array.
  5298. ** This gives the application an opportunity to prioritize any actions
  5299. ** related to the set of unblocked database connections.
  5300. **
  5301. ** <b>Deadlock Detection</b>
  5302. **
  5303. ** Assuming that after registering for an unlock-notify callback a
  5304. ** database waits for the callback to be issued before taking any further
  5305. ** action (a reasonable assumption), then using this API may cause the
  5306. ** application to deadlock. For example, if connection X is waiting for
  5307. ** connection Y's transaction to be concluded, and similarly connection
  5308. ** Y is waiting on connection X's transaction, then neither connection
  5309. ** will proceed and the system may remain deadlocked indefinitely.
  5310. **
  5311. ** To avoid this scenario, the sqlite3_unlock_notify() performs deadlock
  5312. ** detection. If a given call to sqlite3_unlock_notify() would put the
  5313. ** system in a deadlocked state, then SQLITE_LOCKED is returned and no
  5314. ** unlock-notify callback is registered. The system is said to be in
  5315. ** a deadlocked state if connection A has registered for an unlock-notify
  5316. ** callback on the conclusion of connection B's transaction, and connection
  5317. ** B has itself registered for an unlock-notify callback when connection
  5318. ** A's transaction is concluded. Indirect deadlock is also detected, so
  5319. ** the system is also considered to be deadlocked if connection B has
  5320. ** registered for an unlock-notify callback on the conclusion of connection
  5321. ** C's transaction, where connection C is waiting on connection A. Any
  5322. ** number of levels of indirection are allowed.
  5323. **
  5324. ** <b>The "DROP TABLE" Exception</b>
  5325. **
  5326. ** When a call to [sqlite3_step()] returns SQLITE_LOCKED, it is almost
  5327. ** always appropriate to call sqlite3_unlock_notify(). There is however,
  5328. ** one exception. When executing a "DROP TABLE" or "DROP INDEX" statement,
  5329. ** SQLite checks if there are any currently executing SELECT statements
  5330. ** that belong to the same connection. If there are, SQLITE_LOCKED is
  5331. ** returned. In this case there is no "blocking connection", so invoking
  5332. ** sqlite3_unlock_notify() results in the unlock-notify callback being
  5333. ** invoked immediately. If the application then re-attempts the "DROP TABLE"
  5334. ** or "DROP INDEX" query, an infinite loop might be the result.
  5335. **
  5336. ** One way around this problem is to check the extended error code returned
  5337. ** by an sqlite3_step() call. If there is a blocking connection, then the
  5338. ** extended error code is set to SQLITE_LOCKED_SHAREDCACHE. Otherwise, in
  5339. ** the special "DROP TABLE/INDEX" case, the extended error code is just
  5340. ** SQLITE_LOCKED.
  5341. */
  5342. int sqlite3_unlock_notify(
  5343. sqlite3 *pBlocked, /* Waiting connection */
  5344. void (*xNotify)(void **apArg, int nArg), /* Callback function to invoke */
  5345. void *pNotifyArg /* Argument to pass to xNotify */
  5346. );
  5347. /*
  5348. ** Undo the hack that converts floating point types to integer for
  5349. ** builds on processors without floating point support.
  5350. */
  5351. #ifdef SQLITE_OMIT_FLOATING_POINT
  5352. # undef double
  5353. #endif
  5354. #ifdef __cplusplus
  5355. } /* End of the 'extern "C"' block */
  5356. #endif
  5357. #endif
粤ICP备19079148号