sqlite3.inc 281 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666166716681669167016711672167316741675167616771678167916801681168216831684168516861687168816891690169116921693169416951696169716981699170017011702170317041705170617071708170917101711171217131714171517161717171817191720172117221723172417251726172717281729173017311732173317341735173617371738173917401741174217431744174517461747174817491750175117521753175417551756175717581759176017611762176317641765176617671768176917701771177217731774177517761777177817791780178117821783178417851786178717881789179017911792179317941795179617971798179918001801180218031804180518061807180818091810181118121813181418151816181718181819182018211822182318241825182618271828182918301831183218331834183518361837183818391840184118421843184418451846184718481849185018511852185318541855185618571858185918601861186218631864186518661867186818691870187118721873187418751876187718781879188018811882188318841885188618871888188918901891189218931894189518961897189818991900190119021903190419051906190719081909191019111912191319141915191619171918191919201921192219231924192519261927192819291930193119321933193419351936193719381939194019411942194319441945194619471948194919501951195219531954195519561957195819591960196119621963196419651966196719681969197019711972197319741975197619771978197919801981198219831984198519861987198819891990199119921993199419951996199719981999200020012002200320042005200620072008200920102011201220132014201520162017201820192020202120222023202420252026202720282029203020312032203320342035203620372038203920402041204220432044204520462047204820492050205120522053205420552056205720582059206020612062206320642065206620672068206920702071207220732074207520762077207820792080208120822083208420852086208720882089209020912092209320942095209620972098209921002101210221032104210521062107210821092110211121122113211421152116211721182119212021212122212321242125212621272128212921302131213221332134213521362137213821392140214121422143214421452146214721482149215021512152215321542155215621572158215921602161216221632164216521662167216821692170217121722173217421752176217721782179218021812182218321842185218621872188218921902191219221932194219521962197219821992200220122022203220422052206220722082209221022112212221322142215221622172218221922202221222222232224222522262227222822292230223122322233223422352236223722382239224022412242224322442245224622472248224922502251225222532254225522562257225822592260226122622263226422652266226722682269227022712272227322742275227622772278227922802281228222832284228522862287228822892290229122922293229422952296229722982299230023012302230323042305230623072308230923102311231223132314231523162317231823192320232123222323232423252326232723282329233023312332233323342335233623372338233923402341234223432344234523462347234823492350235123522353235423552356235723582359236023612362236323642365236623672368236923702371237223732374237523762377237823792380238123822383238423852386238723882389239023912392239323942395239623972398239924002401240224032404240524062407240824092410241124122413241424152416241724182419242024212422242324242425242624272428242924302431243224332434243524362437243824392440244124422443244424452446244724482449245024512452245324542455245624572458245924602461246224632464246524662467246824692470247124722473247424752476247724782479248024812482248324842485248624872488248924902491249224932494249524962497249824992500250125022503250425052506250725082509251025112512251325142515251625172518251925202521252225232524252525262527252825292530253125322533253425352536253725382539254025412542254325442545254625472548254925502551255225532554255525562557255825592560256125622563256425652566256725682569257025712572257325742575257625772578257925802581258225832584258525862587258825892590259125922593259425952596259725982599260026012602260326042605260626072608260926102611261226132614261526162617261826192620262126222623262426252626262726282629263026312632263326342635263626372638263926402641264226432644264526462647264826492650265126522653265426552656265726582659266026612662266326642665266626672668266926702671267226732674267526762677267826792680268126822683268426852686268726882689269026912692269326942695269626972698269927002701270227032704270527062707270827092710271127122713271427152716271727182719272027212722272327242725272627272728272927302731273227332734273527362737273827392740274127422743274427452746274727482749275027512752275327542755275627572758275927602761276227632764276527662767276827692770277127722773277427752776277727782779278027812782278327842785278627872788278927902791279227932794279527962797279827992800280128022803280428052806280728082809281028112812281328142815281628172818281928202821282228232824282528262827282828292830283128322833283428352836283728382839284028412842284328442845284628472848284928502851285228532854285528562857285828592860286128622863286428652866286728682869287028712872287328742875287628772878287928802881288228832884288528862887288828892890289128922893289428952896289728982899290029012902290329042905290629072908290929102911291229132914291529162917291829192920292129222923292429252926292729282929293029312932293329342935293629372938293929402941294229432944294529462947294829492950295129522953295429552956295729582959296029612962296329642965296629672968296929702971297229732974297529762977297829792980298129822983298429852986298729882989299029912992299329942995299629972998299930003001300230033004300530063007300830093010301130123013301430153016301730183019302030213022302330243025302630273028302930303031303230333034303530363037303830393040304130423043304430453046304730483049305030513052305330543055305630573058305930603061306230633064306530663067306830693070307130723073307430753076307730783079308030813082308330843085308630873088308930903091309230933094309530963097309830993100310131023103310431053106310731083109311031113112311331143115311631173118311931203121312231233124312531263127312831293130313131323133313431353136313731383139314031413142314331443145314631473148314931503151315231533154315531563157315831593160316131623163316431653166316731683169317031713172317331743175317631773178317931803181318231833184318531863187318831893190319131923193319431953196319731983199320032013202320332043205320632073208320932103211321232133214321532163217321832193220322132223223322432253226322732283229323032313232323332343235323632373238323932403241324232433244324532463247324832493250325132523253325432553256325732583259326032613262326332643265326632673268326932703271327232733274327532763277327832793280328132823283328432853286328732883289329032913292329332943295329632973298329933003301330233033304330533063307330833093310331133123313331433153316331733183319332033213322332333243325332633273328332933303331333233333334333533363337333833393340334133423343334433453346334733483349335033513352335333543355335633573358335933603361336233633364336533663367336833693370337133723373337433753376337733783379338033813382338333843385338633873388338933903391339233933394339533963397339833993400340134023403340434053406340734083409341034113412341334143415341634173418341934203421342234233424342534263427342834293430343134323433343434353436343734383439344034413442344334443445344634473448344934503451345234533454345534563457345834593460346134623463346434653466346734683469347034713472347334743475347634773478347934803481348234833484348534863487348834893490349134923493349434953496349734983499350035013502350335043505350635073508350935103511351235133514351535163517351835193520352135223523352435253526352735283529353035313532353335343535353635373538353935403541354235433544354535463547354835493550355135523553355435553556355735583559356035613562356335643565356635673568356935703571357235733574357535763577357835793580358135823583358435853586358735883589359035913592359335943595359635973598359936003601360236033604360536063607360836093610361136123613361436153616361736183619362036213622362336243625362636273628362936303631363236333634363536363637363836393640364136423643364436453646364736483649365036513652365336543655365636573658365936603661366236633664366536663667366836693670367136723673367436753676367736783679368036813682368336843685368636873688368936903691369236933694369536963697369836993700370137023703370437053706370737083709371037113712371337143715371637173718371937203721372237233724372537263727372837293730373137323733373437353736373737383739374037413742374337443745374637473748374937503751375237533754375537563757375837593760376137623763376437653766376737683769377037713772377337743775377637773778377937803781378237833784378537863787378837893790379137923793379437953796379737983799380038013802380338043805380638073808380938103811381238133814381538163817381838193820382138223823382438253826382738283829383038313832383338343835383638373838383938403841384238433844384538463847384838493850385138523853385438553856385738583859386038613862386338643865386638673868386938703871387238733874387538763877387838793880388138823883388438853886388738883889389038913892389338943895389638973898389939003901390239033904390539063907390839093910391139123913391439153916391739183919392039213922392339243925392639273928392939303931393239333934393539363937393839393940394139423943394439453946394739483949395039513952395339543955395639573958395939603961396239633964396539663967396839693970397139723973397439753976397739783979398039813982398339843985398639873988398939903991399239933994399539963997399839994000400140024003400440054006400740084009401040114012401340144015401640174018401940204021402240234024402540264027402840294030403140324033403440354036403740384039404040414042404340444045404640474048404940504051405240534054405540564057405840594060406140624063406440654066406740684069407040714072407340744075407640774078407940804081408240834084408540864087408840894090409140924093409440954096409740984099410041014102410341044105410641074108410941104111411241134114411541164117411841194120412141224123412441254126412741284129413041314132413341344135413641374138413941404141414241434144414541464147414841494150415141524153415441554156415741584159416041614162416341644165416641674168416941704171417241734174417541764177417841794180418141824183418441854186418741884189419041914192419341944195419641974198419942004201420242034204420542064207420842094210421142124213421442154216421742184219422042214222422342244225422642274228422942304231423242334234423542364237423842394240424142424243424442454246424742484249425042514252425342544255425642574258425942604261426242634264426542664267426842694270427142724273427442754276427742784279428042814282428342844285428642874288428942904291429242934294429542964297429842994300430143024303430443054306430743084309431043114312431343144315431643174318431943204321432243234324432543264327432843294330433143324333433443354336433743384339434043414342434343444345434643474348434943504351435243534354435543564357435843594360436143624363436443654366436743684369437043714372437343744375437643774378437943804381438243834384438543864387438843894390439143924393439443954396439743984399440044014402440344044405440644074408440944104411441244134414441544164417441844194420442144224423442444254426442744284429443044314432443344344435443644374438443944404441444244434444444544464447444844494450445144524453445444554456445744584459446044614462446344644465446644674468446944704471447244734474447544764477447844794480448144824483448444854486448744884489449044914492449344944495449644974498449945004501450245034504450545064507450845094510451145124513451445154516451745184519452045214522452345244525452645274528452945304531453245334534453545364537453845394540454145424543454445454546454745484549455045514552455345544555455645574558455945604561456245634564456545664567456845694570457145724573457445754576457745784579458045814582458345844585458645874588458945904591459245934594459545964597459845994600460146024603460446054606460746084609461046114612461346144615461646174618461946204621462246234624462546264627462846294630463146324633463446354636463746384639464046414642464346444645464646474648464946504651465246534654465546564657465846594660466146624663466446654666466746684669467046714672467346744675467646774678467946804681468246834684468546864687468846894690469146924693469446954696469746984699470047014702470347044705470647074708470947104711471247134714471547164717471847194720472147224723472447254726472747284729473047314732473347344735473647374738473947404741474247434744474547464747474847494750475147524753475447554756475747584759476047614762476347644765476647674768476947704771477247734774477547764777477847794780478147824783478447854786478747884789479047914792479347944795479647974798479948004801480248034804480548064807480848094810481148124813481448154816481748184819482048214822482348244825482648274828482948304831483248334834483548364837483848394840484148424843484448454846484748484849485048514852485348544855485648574858485948604861486248634864486548664867486848694870487148724873487448754876487748784879488048814882488348844885488648874888488948904891489248934894489548964897489848994900490149024903490449054906490749084909491049114912491349144915491649174918491949204921492249234924492549264927492849294930493149324933493449354936493749384939494049414942494349444945494649474948494949504951495249534954495549564957495849594960496149624963496449654966496749684969497049714972497349744975497649774978497949804981498249834984498549864987498849894990499149924993499449954996499749984999500050015002500350045005500650075008500950105011501250135014501550165017501850195020502150225023502450255026502750285029503050315032503350345035503650375038503950405041504250435044504550465047504850495050505150525053505450555056505750585059506050615062506350645065506650675068506950705071507250735074507550765077507850795080508150825083508450855086508750885089509050915092509350945095509650975098509951005101510251035104510551065107510851095110511151125113511451155116511751185119512051215122512351245125512651275128512951305131513251335134513551365137513851395140514151425143514451455146514751485149515051515152515351545155515651575158515951605161516251635164516551665167516851695170517151725173517451755176517751785179518051815182518351845185518651875188518951905191519251935194519551965197519851995200520152025203520452055206520752085209521052115212521352145215521652175218521952205221522252235224522552265227522852295230523152325233523452355236523752385239524052415242524352445245524652475248524952505251525252535254525552565257525852595260526152625263526452655266526752685269527052715272527352745275527652775278527952805281528252835284528552865287528852895290529152925293529452955296529752985299530053015302530353045305530653075308530953105311531253135314531553165317531853195320532153225323532453255326532753285329533053315332533353345335533653375338533953405341534253435344534553465347534853495350535153525353535453555356535753585359536053615362536353645365536653675368536953705371537253735374537553765377537853795380538153825383538453855386538753885389539053915392539353945395539653975398539954005401540254035404540554065407540854095410541154125413541454155416541754185419542054215422542354245425542654275428542954305431543254335434543554365437543854395440544154425443544454455446544754485449545054515452545354545455545654575458545954605461546254635464546554665467546854695470547154725473547454755476547754785479548054815482548354845485548654875488548954905491549254935494549554965497549854995500550155025503550455055506550755085509551055115512551355145515551655175518551955205521552255235524552555265527552855295530553155325533553455355536553755385539554055415542554355445545554655475548554955505551555255535554555555565557555855595560556155625563556455655566556755685569557055715572557355745575557655775578557955805581558255835584558555865587558855895590559155925593559455955596559755985599560056015602560356045605560656075608560956105611561256135614561556165617561856195620562156225623562456255626562756285629563056315632563356345635563656375638563956405641564256435644564556465647564856495650565156525653565456555656565756585659566056615662566356645665566656675668566956705671567256735674567556765677567856795680568156825683568456855686568756885689569056915692569356945695569656975698569957005701570257035704570557065707570857095710571157125713571457155716571757185719572057215722572357245725572657275728572957305731573257335734573557365737573857395740574157425743574457455746574757485749575057515752575357545755575657575758575957605761576257635764576557665767576857695770577157725773577457755776577757785779578057815782578357845785578657875788578957905791579257935794579557965797579857995800580158025803580458055806580758085809581058115812581358145815581658175818581958205821582258235824582558265827582858295830583158325833583458355836583758385839584058415842584358445845584658475848584958505851585258535854585558565857585858595860586158625863586458655866586758685869587058715872587358745875587658775878587958805881588258835884588558865887588858895890589158925893589458955896589758985899590059015902590359045905590659075908590959105911591259135914591559165917591859195920592159225923592459255926592759285929593059315932593359345935593659375938593959405941594259435944594559465947594859495950595159525953595459555956595759585959596059615962
  1. {$mode objfpc}{$h+}
  2. {$ifdef BSD}
  3. {$linklib c}
  4. {$linklib pthread}
  5. {$endif}
  6. {$packrecords C}
  7. {.$DEFINE SQLITE_OBSOLETE}
  8. interface
  9. uses
  10. ctypes,
  11. {$ifdef LOAD_DYNAMICALLY}
  12. SysUtils, DynLibs;
  13. {$else}
  14. DynLibs;
  15. {$ifdef darwin}
  16. {$linklib sqlite3}
  17. {$endif}
  18. {$endif}
  19. const
  20. {$IFDEF WINDOWS}
  21. Sqlite3Lib = 'sqlite3.dll';
  22. {$else}
  23. Sqlite3Lib = 'libsqlite3.'+sharedsuffix;
  24. {$endif}
  25. {$IFDEF LOAD_DYNAMICALLY}
  26. {$DEFINE D}
  27. {$ELSE}
  28. {$DEFINE S}
  29. {$ENDIF}
  30. (*
  31. ** 2001 September 15
  32. **
  33. ** The author disclaims copyright to this source code. In place of
  34. ** a legal notice, here is a blessing:
  35. **
  36. ** May you do good and not evil.
  37. ** May you find forgiveness for yourself and forgive others.
  38. ** May you share freely, never taking more than you give.
  39. **
  40. *************************************************************************
  41. ** This header file defines the interface that the SQLite library
  42. ** presents to client programs. If a C-function, structure, datatype,
  43. ** or constant definition does not appear in this file, then it is
  44. ** not a published API of SQLite, is subject to change without
  45. ** notice, and should not be referenced by programs that use SQLite.
  46. **
  47. ** Some of the definitions that are in this file are marked as
  48. ** "experimental". Experimental interfaces are normally new
  49. ** features recently added to SQLite. We do not anticipate changes
  50. ** to experimental interfaces but reserve to make minor changes if
  51. ** experience from use "in the wild" suggest such changes are prudent.
  52. **
  53. ** The official C-language API documentation for SQLite is derived
  54. ** from comments in this file. This file is the authoritative source
  55. ** on how SQLite interfaces are suppose to operate.
  56. **
  57. ** The name of this file under configuration management is "sqlite.h.in".
  58. ** The makefile makes some minor changes to this file (such as inserting
  59. ** the version number) and changes its name to "sqlite3.h" as
  60. ** part of the build process.
  61. **
  62. ** @(#) $Id: sqlite.h.in,v 1.312 2008/05/12 12:39:56 drh Exp $
  63. *)
  64. (*
  65. ** CAPI3REF: Compile-Time Library Version Numbers {F10010}
  66. **
  67. ** The SQLITE_VERSION and SQLITE_VERSION_NUMBER #defines in
  68. ** the sqlite3.h file specify the version of SQLite with which
  69. ** that header file is associated.
  70. **
  71. ** The "version" of SQLite is a string of the form "X.Y.Z".
  72. ** The phrase "alpha" or "beta" might be appended after the Z.
  73. ** The X value is major version number always 3 in SQLite3.
  74. ** The X value only changes when backwards compatibility is
  75. ** broken and we intend to never break
  76. ** backwards compatibility. The Y value is the minor version
  77. ** number and only changes when
  78. ** there are major feature enhancements that are forwards compatible
  79. ** but not backwards compatible. The Z value is release number
  80. ** and is incremented with
  81. ** each release but resets back to 0 when Y is incremented.
  82. **
  83. ** See also: [sqlite3_libversion()] and [sqlite3_libversion_number()].
  84. **
  85. ** INVARIANTS:
  86. **
  87. ** {F10011} The SQLITE_VERSION #define in the sqlite3.h header file
  88. ** evaluates to a string literal that is the SQLite version
  89. ** with which the header file is associated.
  90. **
  91. ** {F10014} The SQLITE_VERSION_NUMBER #define resolves to an integer
  92. ** with the value (X*1000000 + Y*1000 + Z) where X, Y, and
  93. ** Z are the major version, minor version, and release number.
  94. *)
  95. const
  96. SQLITE_VERSION = '3.5.9';
  97. SQLITE_VERSION_NUMBER = 3005009;
  98. (*
  99. ** CAPI3REF: Run-Time Library Version Numbers {F10020}
  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. ** INVARIANTS:
  115. **
  116. ** {F10021} The [sqlite3_libversion_number()] interface returns an integer
  117. ** equal to [SQLITE_VERSION_NUMBER].
  118. **
  119. ** {F10022} The [sqlite3_version] string constant contains the text of the
  120. ** [SQLITE_VERSION] string.
  121. **
  122. ** {F10023} The [sqlite3_libversion()] function returns
  123. ** a pointer to the [sqlite3_version] string constant.
  124. *)
  125. //SQLITE_EXTERN const char sqlite3_version[];
  126. {$IFDEF S}function{$ELSE}var{$ENDIF}sqlite3_libversion{$IFDEF D}: function{$ENDIF}(): pchar; cdecl;{$IFDEF S}external Sqlite3Lib;{$ENDIF}
  127. {$IFDEF S}function{$ELSE}var{$ENDIF}sqlite3_libversion_number{$IFDEF D}: function{$ENDIF}(): cint; cdecl;{$IFDEF S}external Sqlite3Lib;{$ENDIF}
  128. function sqlite3_version(): pchar;
  129. (*
  130. ** CAPI3REF: Test To See If The Library Is Threadsafe {F10100}
  131. **
  132. ** SQLite can be compiled with or without mutexes. When
  133. ** the SQLITE_THREADSAFE C preprocessor macro is true, mutexes
  134. ** are enabled and SQLite is threadsafe. When that macro is false,
  135. ** the mutexes are omitted. Without the mutexes, it is not safe
  136. ** to use SQLite from more than one thread.
  137. **
  138. ** There is a measurable performance penalty for enabling mutexes.
  139. ** So if speed is of utmost importance, it makes sense to disable
  140. ** the mutexes. But for maximum safety, mutexes should be enabled.
  141. ** The default behavior is for mutexes to be enabled.
  142. **
  143. ** This interface can be used by a program to make sure that the
  144. ** version of SQLite that it is linking against was compiled with
  145. ** the desired setting of the SQLITE_THREADSAFE macro.
  146. **
  147. ** INVARIANTS:
  148. **
  149. ** {F10101} The [sqlite3_threadsafe()] function returns nonzero if
  150. ** SQLite was compiled with its mutexes enabled or zero
  151. ** if SQLite was compiled with mutexes disabled.
  152. *)
  153. {$IFDEF S}function{$ELSE}var{$ENDIF}sqlite3_threadsafe{$IFDEF D}: function{$ENDIF}(): cint; cdecl;{$IFDEF S}external Sqlite3Lib;{$ENDIF}
  154. (*
  155. ** CAPI3REF: Database Connection Handle {F12000}
  156. ** KEYWORDS: {database connection} {database connections}
  157. **
  158. ** Each open SQLite database is represented by pointer to an instance of the
  159. ** opaque structure named "sqlite3". It is useful to think of an sqlite3
  160. ** pointer as an object. The [sqlite3_open()], [sqlite3_open16()], and
  161. ** [sqlite3_open_v2()] interfaces are its constructors
  162. ** and [sqlite3_close()] is its destructor. There are many other interfaces
  163. ** (such as [sqlite3_prepare_v2()], [sqlite3_create_function()], and
  164. ** [sqlite3_busy_timeout()] to name but three) that are methods on this
  165. ** object.
  166. *)
  167. type
  168. ppsqlite3 = ^psqlite3;
  169. psqlite3 = ^_sqlite3;
  170. _sqlite3 = record end;
  171. (*
  172. ** CAPI3REF: Constants Defining Special Destructor Behavior {F10280}
  173. **
  174. ** These are special value for the destructor that is passed in as the
  175. ** final argument to routines like [sqlite3_result_blob()]. If the destructor
  176. ** argument is SQLITE_STATIC; it means that the content pointer is constant
  177. ** and will never change. It does not need to be destroyed. The
  178. ** SQLITE_TRANSIENT value means that the content will likely change in
  179. ** the near future and that SQLite should make its own private copy of
  180. ** the content before returning.
  181. **
  182. ** The typedef is necessary to work around problems in certain
  183. ** C++ compilers. See ticket #2191.
  184. *)
  185. type
  186. sqlite3_destructor_type = procedure(user: pointer); cdecl;
  187. const
  188. SQLITE_STATIC = sqlite3_destructor_type(nil);
  189. SQLITE_TRANSIENT = pointer(-1);//sqlite3_destructor_type(-1);
  190. (*
  191. ** CAPI3REF: 64-Bit Integer Types {F10200}
  192. ** KEYWORDS: sqlite_int64 sqlite_uint64
  193. **
  194. ** Because there is no cross-platform way to specify 64-bit integer types
  195. ** SQLite includes typedefs for 64-bit signed and unsigned integers.
  196. **
  197. ** The sqlite3_int64 and sqlite3_uint64 are the preferred type
  198. ** definitions. The sqlite_int64 and sqlite_uint64 types are
  199. ** supported for backwards compatibility only.
  200. **
  201. ** INVARIANTS:
  202. **
  203. ** {F10201} The [sqlite_int64] and [sqlite3_int64] types specify a
  204. ** 64-bit signed integer.
  205. **
  206. ** {F10202} The [sqlite_uint64] and [sqlite3_uint64] types specify
  207. ** a 64-bit unsigned integer.
  208. *)
  209. type
  210. psqlite_int64 = ^sqlite_int64;
  211. sqlite_int64 = Int64;
  212. psqlite_uint64 = ^sqlite_uint64;
  213. sqlite_uint64 = QWord;
  214. psqlite3_int64 = ^sqlite3_int64;
  215. sqlite3_int64 = sqlite_int64;
  216. psqlite3_uint64 = ^sqlite3_uint64;
  217. sqlite3_uint64 = sqlite_uint64;
  218. (*
  219. ** CAPI3REF: Closing A Database Connection {F12010}
  220. **
  221. ** This routine is the destructor for the [sqlite3] object.
  222. **
  223. ** Applications should [sqlite3_finalize | finalize] all
  224. ** [prepared statements] and
  225. ** [sqlite3_blob_close | close] all [sqlite3_blob | BLOBs]
  226. ** associated with the [sqlite3] object prior
  227. ** to attempting to close the [sqlite3] object.
  228. **
  229. ** <todo>What happens to pending transactions? Are they
  230. ** rolled back, or abandoned?</todo>
  231. **
  232. ** INVARIANTS:
  233. **
  234. ** {F12011} The [sqlite3_close()] interface destroys an [sqlite3] object
  235. ** allocated by a prior call to [sqlite3_open()],
  236. ** [sqlite3_open16()], or [sqlite3_open_v2()].
  237. **
  238. ** {F12012} The [sqlite3_close()] function releases all memory used by the
  239. ** connection and closes all open files.
  240. **
  241. ** {F12013} If the database connection contains
  242. ** [prepared statements] that have not been
  243. ** finalized by [sqlite3_finalize()], then [sqlite3_close()]
  244. ** returns [SQLITE_BUSY] and leaves the connection open.
  245. **
  246. ** {F12014} Giving sqlite3_close() a NULL pointer is a harmless no-op.
  247. **
  248. ** LIMITATIONS:
  249. **
  250. ** {U12015} The parameter to [sqlite3_close()] must be an [sqlite3] object
  251. ** pointer previously obtained from [sqlite3_open()] or the
  252. ** equivalent, or NULL.
  253. **
  254. ** {U12016} The parameter to [sqlite3_close()] must not have been previously
  255. ** closed.
  256. *)
  257. {$IFDEF S}function{$ELSE}var{$ENDIF}sqlite3_close{$IFDEF D}: function{$ENDIF}(ref: psqlite3): cint; cdecl;{$IFDEF S}external Sqlite3Lib;{$ENDIF}
  258. (*
  259. ** The type for a callback function.
  260. ** This is legacy and deprecated. It is included for historical
  261. ** compatibility and is not documented.
  262. *)
  263. type
  264. sqlite3_callback = function(user: pointer; cols: cint; values, name: ppchar): cint; cdecl;
  265. (*
  266. ** CAPI3REF: One-Step Query Execution Interface {F12100}
  267. **
  268. ** The sqlite3_exec() interface is a convenient way of running
  269. ** one or more SQL statements without a lot of C code. The
  270. ** SQL statements are passed in as the second parameter to
  271. ** sqlite3_exec(). The statements are evaluated one by one
  272. ** until either an error or an interrupt is encountered or
  273. ** until they are all done. The 3rd parameter is an optional
  274. ** callback that is invoked once for each row of any query results
  275. ** produced by the SQL statements. The 5th parameter tells where
  276. ** to write any error messages.
  277. **
  278. ** The sqlite3_exec() interface is implemented in terms of
  279. ** [sqlite3_prepare_v2()], [sqlite3_step()], and [sqlite3_finalize()].
  280. ** The sqlite3_exec() routine does nothing that cannot be done
  281. ** by [sqlite3_prepare_v2()], [sqlite3_step()], and [sqlite3_finalize()].
  282. ** The sqlite3_exec() is just a convenient wrapper.
  283. **
  284. ** INVARIANTS:
  285. **
  286. ** {F12101} The [sqlite3_exec()] interface evaluates zero or more UTF-8
  287. ** encoded, semicolon-separated, SQL statements in the
  288. ** zero-terminated string of its 2nd parameter within the
  289. ** context of the [sqlite3] object given in the 1st parameter.
  290. **
  291. ** {F12104} The return value of [sqlite3_exec()] is SQLITE_OK if all
  292. ** SQL statements run successfully.
  293. **
  294. ** {F12105} The return value of [sqlite3_exec()] is an appropriate
  295. ** non-zero error code if any SQL statement fails.
  296. **
  297. ** {F12107} If one or more of the SQL statements handed to [sqlite3_exec()]
  298. ** return results and the 3rd parameter is not NULL, then
  299. ** the callback function specified by the 3rd parameter is
  300. ** invoked once for each row of result.
  301. **
  302. ** {F12110} If the callback returns a non-zero value then [sqlite3_exec()]
  303. ** will aborted the SQL statement it is currently evaluating,
  304. ** skip all subsequent SQL statements, and return [SQLITE_ABORT].
  305. ** <todo>What happens to *errmsg here? Does the result code for
  306. ** sqlite3_errcode() get set?</todo>
  307. **
  308. ** {F12113} The [sqlite3_exec()] routine will pass its 4th parameter through
  309. ** as the 1st parameter of the callback.
  310. **
  311. ** {F12116} The [sqlite3_exec()] routine sets the 2nd parameter of its
  312. ** callback to be the number of columns in the current row of
  313. ** result.
  314. **
  315. ** {F12119} The [sqlite3_exec()] routine sets the 3rd parameter of its
  316. ** callback to be an array of pointers to strings holding the
  317. ** values for each column in the current result set row as
  318. ** obtained from [sqlite3_column_text()].
  319. **
  320. ** {F12122} The [sqlite3_exec()] routine sets the 4th parameter of its
  321. ** callback to be an array of pointers to strings holding the
  322. ** names of result columns as obtained from [sqlite3_column_name()].
  323. **
  324. ** {F12125} If the 3rd parameter to [sqlite3_exec()] is NULL then
  325. ** [sqlite3_exec()] never invokes a callback. All query
  326. ** results are silently discarded.
  327. **
  328. ** {F12128} If an error occurs while parsing or evaluating any of the SQL
  329. ** statements handed to [sqlite3_exec()] then [sqlite3_exec()] will
  330. ** return an [error code] other than [SQLITE_OK].
  331. **
  332. ** {F12131} If an error occurs while parsing or evaluating any of the SQL
  333. ** handed to [sqlite3_exec()] and if the 5th parameter (errmsg)
  334. ** to [sqlite3_exec()] is not NULL, then an error message is
  335. ** allocated using the equivalent of [sqlite3_mprintf()] and
  336. ** *errmsg is made to point to that message.
  337. **
  338. ** {F12134} The [sqlite3_exec()] routine does not change the value of
  339. ** *errmsg if errmsg is NULL or if there are no errors.
  340. **
  341. ** {F12137} The [sqlite3_exec()] function sets the error code and message
  342. ** accessible via [sqlite3_errcode()], [sqlite3_errmsg()], and
  343. ** [sqlite3_errmsg16()].
  344. **
  345. ** LIMITATIONS:
  346. **
  347. ** {U12141} The first parameter to [sqlite3_exec()] must be an valid and open
  348. ** [database connection].
  349. **
  350. ** {U12142} The database connection must not be closed while
  351. ** [sqlite3_exec()] is running.
  352. **
  353. ** {U12143} The calling function is should use [sqlite3_free()] to free
  354. ** the memory that *errmsg is left pointing at once the error
  355. ** message is no longer needed.
  356. **
  357. ** {U12145} The SQL statement text in the 2nd parameter to [sqlite3_exec()]
  358. ** must remain unchanged while [sqlite3_exec()] is running.
  359. *)
  360. {$IFDEF S}function{$ELSE}var{$ENDIF}sqlite3_exec{$IFDEF D}: function{$ENDIF}(
  361. db: psqlite3; (* An open database *)
  362. sql: pchar; (* SQL to be evaluted *)
  363. cb: sqlite3_callback; (* Callback function *)
  364. user: pointer; (* 1st argument to callback *)
  365. errmsg: ppchar (* Error msg written here *)
  366. ): cint; cdecl;{$IFDEF S}external Sqlite3Lib;{$ENDIF}
  367. (*
  368. ** CAPI3REF: Result Codes {F10210}
  369. ** KEYWORDS: SQLITE_OK {error code} {error codes}
  370. **
  371. ** Many SQLite functions return an integer result code from the set shown
  372. ** here in order to indicates success or failure.
  373. **
  374. ** See also: [SQLITE_IOERR_READ | extended result codes]
  375. *)
  376. const
  377. SQLITE_OK = 0; (* Successful result *)
  378. (* beginning-of-error-codes *)
  379. SQLITE_ERROR = 1; (* SQL error or missing database *)
  380. SQLITE_INTERNAL = 2; (* Internal logic error in SQLite *)
  381. SQLITE_PERM = 3; (* Access permission denied *)
  382. SQLITE_ABORT = 4; (* Callback routine requested an abort *)
  383. SQLITE_BUSY = 5; (* The database file is locked *)
  384. SQLITE_LOCKED = 6; (* A table in the database is locked *)
  385. SQLITE_NOMEM = 7; (* A malloc() failed *)
  386. SQLITE_READONLY = 8; (* Attempt to write a readonly database *)
  387. SQLITE_INTERRUPT = 9; (* Operation terminated by sqlite3_interrupt()*)
  388. SQLITE_IOERR = 10; (* Some kind of disk I/O error occurred *)
  389. SQLITE_CORRUPT = 11; (* The database disk image is malformed *)
  390. SQLITE_NOTFOUND = 12; (* NOT USED. Table or record not found *)
  391. SQLITE_FULL = 13; (* Insertion failed because database is full *)
  392. SQLITE_CANTOPEN = 14; (* Unable to open the database file *)
  393. SQLITE_PROTOCOL = 15; (* NOT USED. Database lock protocol error *)
  394. SQLITE_EMPTY = 16; (* Database is empty *)
  395. SQLITE_SCHEMA = 17; (* The database schema changed *)
  396. SQLITE_TOOBIG = 18; (* String or BLOB exceeds size limit *)
  397. SQLITE_CONSTRAINT = 19; (* Abort due to constraint violation *)
  398. SQLITE_MISMATCH = 20; (* Data type mismatch *)
  399. SQLITE_MISUSE = 21; (* Library used incorrectly *)
  400. SQLITE_NOLFS = 22; (* Uses OS features not supported on host *)
  401. SQLITE_AUTH = 23; (* Authorization denied *)
  402. SQLITE_FORMAT = 24; (* Auxiliary database format error *)
  403. SQLITE_RANGE = 25; (* 2nd parameter to sqlite3_bind out of range *)
  404. SQLITE_NOTADB = 26; (* File opened that is not a database file *)
  405. SQLITE_ROW = 100; (* sqlite3_step() has another row ready *)
  406. SQLITE_DONE = 101; (* sqlite3_step() has finished executing *)
  407. (* end-of-error-codes *)
  408. (*
  409. ** CAPI3REF: Extended Result Codes {F10220}
  410. ** KEYWORDS: {extended error code} {extended error codes}
  411. ** KEYWORDS: {extended result codes}
  412. **
  413. ** In its default configuration, SQLite API routines return one of 26 integer
  414. ** [SQLITE_OK | result codes]. However, experience has shown that
  415. ** many of these result codes are too course-grained. They do not provide as
  416. ** much information about problems as programmers might like. In an effort to
  417. ** address this, newer versions of SQLite (version 3.3.8 and later) include
  418. ** support for additional result codes that provide more detailed information
  419. ** about errors. The extended result codes are enabled or disabled
  420. ** for each database connection using the [sqlite3_extended_result_codes()]
  421. ** API.
  422. **
  423. ** Some of the available extended result codes are listed here.
  424. ** One may expect the number of extended result codes will be expand
  425. ** over time. Software that uses extended result codes should expect
  426. ** to see new result codes in future releases of SQLite.
  427. **
  428. ** The SQLITE_OK result code will never be extended. It will always
  429. ** be exactly zero.
  430. **
  431. ** INVARIANTS:
  432. **
  433. ** {F10223} The symbolic name for an extended result code always contains
  434. ** a related primary result code as a prefix.
  435. **
  436. ** {F10224} Primary result code names contain a single "_" character.
  437. **
  438. ** {F10225} Extended result code names contain two or more "_" characters.
  439. **
  440. ** {F10226} The numeric value of an extended result code contains the
  441. ** numeric value of its corresponding primary result code in
  442. ** its least significant 8 bits.
  443. *)
  444. SQLITE_IOERR_READ = (SQLITE_IOERR or (1 shl 8));
  445. SQLITE_IOERR_SHORT_READ = (SQLITE_IOERR or (2 shl 8));
  446. SQLITE_IOERR_WRITE = (SQLITE_IOERR or (3 shl 8));
  447. SQLITE_IOERR_FSYNC = (SQLITE_IOERR or (4 shl 8));
  448. SQLITE_IOERR_DIR_FSYNC = (SQLITE_IOERR or (5 shl 8));
  449. SQLITE_IOERR_TRUNCATE = (SQLITE_IOERR or (6 shl 8));
  450. SQLITE_IOERR_FSTAT = (SQLITE_IOERR or (7 shl 8));
  451. SQLITE_IOERR_UNLOCK = (SQLITE_IOERR or (8 shl 8));
  452. SQLITE_IOERR_RDLOCK = (SQLITE_IOERR or (9 shl 8));
  453. SQLITE_IOERR_DELETE = (SQLITE_IOERR or (10 shl 8));
  454. SQLITE_IOERR_BLOCKED = (SQLITE_IOERR or (11 shl 8));
  455. SQLITE_IOERR_NOMEM = (SQLITE_IOERR or (12 shl 8));
  456. (*
  457. ** CAPI3REF: Flags For File Open Operations {F10230}
  458. **
  459. ** These bit values are intended for use in the
  460. ** 3rd parameter to the [sqlite3_open_v2()] interface and
  461. ** in the 4th parameter to the xOpen method of the
  462. ** [sqlite3_vfs] object.
  463. *)
  464. SQLITE_OPEN_READONLY = $00000001;
  465. SQLITE_OPEN_READWRITE = $00000002;
  466. SQLITE_OPEN_CREATE = $00000004;
  467. SQLITE_OPEN_DELETEONCLOSE = $00000008;
  468. SQLITE_OPEN_EXCLUSIVE = $00000010;
  469. SQLITE_OPEN_MAIN_DB = $00000100;
  470. SQLITE_OPEN_TEMP_DB = $00000200;
  471. SQLITE_OPEN_TRANSIENT_DB = $00000400;
  472. SQLITE_OPEN_MAIN_JOURNAL = $00000800;
  473. SQLITE_OPEN_TEMP_JOURNAL = $00001000;
  474. SQLITE_OPEN_SUBJOURNAL = $00002000;
  475. SQLITE_OPEN_MASTER_JOURNAL = $00004000;
  476. (*
  477. ** CAPI3REF: Device Characteristics {F10240}
  478. **
  479. ** The xDeviceCapabilities method of the [sqlite3_io_methods]
  480. ** object returns an integer which is a vector of the these
  481. ** bit values expressing I/O characteristics of the mass storage
  482. ** device that holds the file that the [sqlite3_io_methods]
  483. ** refers to.
  484. **
  485. ** The SQLITE_IOCAP_ATOMIC property means that all writes of
  486. ** any size are atomic. The SQLITE_IOCAP_ATOMICnnn values
  487. ** mean that writes of blocks that are nnn bytes in size and
  488. ** are aligned to an address which is an integer multiple of
  489. ** nnn are atomic. The SQLITE_IOCAP_SAFE_APPEND value means
  490. ** that when data is appended to a file, the data is appended
  491. ** first then the size of the file is extended, never the other
  492. ** way around. The SQLITE_IOCAP_SEQUENTIAL property means that
  493. ** information is written to disk in the same order as calls
  494. ** to xWrite().
  495. *)
  496. SQLITE_IOCAP_ATOMIC = $00000001;
  497. SQLITE_IOCAP_ATOMIC512 = $00000002;
  498. SQLITE_IOCAP_ATOMIC1K = $00000004;
  499. SQLITE_IOCAP_ATOMIC2K = $00000008;
  500. SQLITE_IOCAP_ATOMIC4K = $00000010;
  501. SQLITE_IOCAP_ATOMIC8K = $00000020;
  502. SQLITE_IOCAP_ATOMIC16K = $00000040;
  503. SQLITE_IOCAP_ATOMIC32K = $00000080;
  504. SQLITE_IOCAP_ATOMIC64K = $00000100;
  505. SQLITE_IOCAP_SAFE_APPEND = $00000200;
  506. SQLITE_IOCAP_SEQUENTIAL = $00000400;
  507. (*
  508. ** CAPI3REF: File Locking Levels {F10250}
  509. **
  510. ** SQLite uses one of these integer values as the second
  511. ** argument to calls it makes to the xLock() and xUnlock() methods
  512. ** of an [sqlite3_io_methods] object.
  513. *)
  514. SQLITE_LOCK_NONE = 0;
  515. SQLITE_LOCK_SHARED = 1;
  516. SQLITE_LOCK_RESERVED = 2;
  517. SQLITE_LOCK_PENDING = 3;
  518. SQLITE_LOCK_EXCLUSIVE = 4;
  519. (*
  520. ** CAPI3REF: Synchronization Type Flags {F10260}
  521. **
  522. ** When SQLite invokes the xSync() method of an
  523. ** [sqlite3_io_methods] object it uses a combination of
  524. ** these integer values as the second argument.
  525. **
  526. ** When the SQLITE_SYNC_DATAONLY flag is used, it means that the
  527. ** sync operation only needs to flush data to mass storage. Inode
  528. ** information need not be flushed. The SQLITE_SYNC_NORMAL flag means
  529. ** to use normal fsync() semantics. The SQLITE_SYNC_FULL flag means
  530. ** to use Mac OS-X style fullsync instead of fsync().
  531. *)
  532. SQLITE_SYNC_NORMAL = $00002;
  533. SQLITE_SYNC_FULL = $00003;
  534. SQLITE_SYNC_DATAONLY = $00010;
  535. (*
  536. ** CAPI3REF: OS Interface Open File Handle {F11110}
  537. **
  538. ** An [sqlite3_file] object represents an open file in the OS
  539. ** interface layer. Individual OS interface implementations will
  540. ** want to subclass this object by appending additional fields
  541. ** for their own use. The pMethods entry is a pointer to an
  542. ** [sqlite3_io_methods] object that defines methods for performing
  543. ** I/O operations on the open file.
  544. *)
  545. type
  546. psqlite3_io_methods = ^sqlite3_io_methods;
  547. psqlite3_file = ^sqlite3_file;
  548. sqlite3_file = record
  549. pMethods: psqlite3_io_methods; (* Methods for an open file *)
  550. end;
  551. (*
  552. ** CAPI3REF: OS Interface File Virtual Methods Object {F11120}
  553. **
  554. ** Every file opened by the [sqlite3_vfs] xOpen method contains a pointer to
  555. ** an instance of this object. This object defines the
  556. ** methods used to perform various operations against the open file.
  557. **
  558. ** The flags argument to xSync may be one of [SQLITE_SYNC_NORMAL] or
  559. ** [SQLITE_SYNC_FULL]. The first choice is the normal fsync().
  560. * The second choice is an
  561. ** OS-X style fullsync. The SQLITE_SYNC_DATA flag may be ORed in to
  562. ** indicate that only the data of the file and not its inode needs to be
  563. ** synced.
  564. **
  565. ** The integer values to xLock() and xUnlock() are one of
  566. ** <ul>
  567. ** <li> [SQLITE_LOCK_NONE],
  568. ** <li> [SQLITE_LOCK_SHARED],
  569. ** <li> [SQLITE_LOCK_RESERVED],
  570. ** <li> [SQLITE_LOCK_PENDING], or
  571. ** <li> [SQLITE_LOCK_EXCLUSIVE].
  572. ** </ul>
  573. ** xLock() increases the lock. xUnlock() decreases the lock.
  574. ** The xCheckReservedLock() method looks
  575. ** to see if any database connection, either in this
  576. ** process or in some other process, is holding an RESERVED,
  577. ** PENDING, or EXCLUSIVE lock on the file. It returns true
  578. ** if such a lock exists and false if not.
  579. **
  580. ** The xFileControl() method is a generic interface that allows custom
  581. ** VFS implementations to directly control an open file using the
  582. ** [sqlite3_file_control()] interface. The second "op" argument
  583. ** is an integer opcode. The third
  584. ** argument is a generic pointer which is intended to be a pointer
  585. ** to a structure that may contain arguments or space in which to
  586. ** write return values. Potential uses for xFileControl() might be
  587. ** functions to enable blocking locks with timeouts, to change the
  588. ** locking strategy (for example to use dot-file locks), to inquire
  589. ** about the status of a lock, or to break stale locks. The SQLite
  590. ** core reserves opcodes less than 100 for its own use.
  591. ** A [SQLITE_FCNTL_LOCKSTATE | list of opcodes] less than 100 is available.
  592. ** Applications that define a custom xFileControl method should use opcodes
  593. ** greater than 100 to avoid conflicts.
  594. **
  595. ** The xSectorSize() method returns the sector size of the
  596. ** device that underlies the file. The sector size is the
  597. ** minimum write that can be performed without disturbing
  598. ** other bytes in the file. The xDeviceCharacteristics()
  599. ** method returns a bit vector describing behaviors of the
  600. ** underlying device:
  601. **
  602. ** <ul>
  603. ** <li> [SQLITE_IOCAP_ATOMIC]
  604. ** <li> [SQLITE_IOCAP_ATOMIC512]
  605. ** <li> [SQLITE_IOCAP_ATOMIC1K]
  606. ** <li> [SQLITE_IOCAP_ATOMIC2K]
  607. ** <li> [SQLITE_IOCAP_ATOMIC4K]
  608. ** <li> [SQLITE_IOCAP_ATOMIC8K]
  609. ** <li> [SQLITE_IOCAP_ATOMIC16K]
  610. ** <li> [SQLITE_IOCAP_ATOMIC32K]
  611. ** <li> [SQLITE_IOCAP_ATOMIC64K]
  612. ** <li> [SQLITE_IOCAP_SAFE_APPEND]
  613. ** <li> [SQLITE_IOCAP_SEQUENTIAL]
  614. ** </ul>
  615. **
  616. ** The SQLITE_IOCAP_ATOMIC property means that all writes of
  617. ** any size are atomic. The SQLITE_IOCAP_ATOMICnnn values
  618. ** mean that writes of blocks that are nnn bytes in size and
  619. ** are aligned to an address which is an integer multiple of
  620. ** nnn are atomic. The SQLITE_IOCAP_SAFE_APPEND value means
  621. ** that when data is appended to a file, the data is appended
  622. ** first then the size of the file is extended, never the other
  623. ** way around. The SQLITE_IOCAP_SEQUENTIAL property means that
  624. ** information is written to disk in the same order as calls
  625. ** to xWrite().
  626. *)
  627. sqlite3_io_methods = record
  628. iVersion : cint;
  629. Close : function(f: psqlite3_file): cint; stdcall;
  630. Read : function(f: psqlite3_file; addr: pointer; iAmt: cint; iOfst: sqlite3_int64): cint; stdcall;
  631. Write : function(f: psqlite3_file; size: sqlite3_int64): cint; stdcall;
  632. Truncate : function(f: psqlite3_file; size: sqlite3_int64): cint; stdcall;
  633. Sync : function(f: psqlite3_file; flags: cint): cint; stdcall;
  634. FileSize : function(f: psqlite3_file; pSize: psqlite3_int64): cint; stdcall;
  635. Lock : function(f: psqlite3_file; flags: cint): cint; stdcall;
  636. Unlock : function(f: psqlite3_file; flags: cint): cint; stdcall;
  637. CheckReservedLock : function(f: psqlite3_file): cint; stdcall;
  638. FileControl : function(f: psqlite3_file; op: cint; pArg: pointer): cint; stdcall;
  639. SectorSize : function(f: psqlite3_file): cint; stdcall;
  640. DeviceCharacteristics: function(f: psqlite3_file): cint; stdcall;
  641. (* Additional methods may be added in future releases *)
  642. end;
  643. (*
  644. ** CAPI3REF: Standard File Control Opcodes {F11310}
  645. **
  646. ** These integer constants are opcodes for the xFileControl method
  647. ** of the [sqlite3_io_methods] object and to the [sqlite3_file_control()]
  648. ** interface.
  649. **
  650. ** The [SQLITE_FCNTL_LOCKSTATE] opcode is used for debugging. This
  651. ** opcode causes the xFileControl method to write the current state of
  652. ** the lock (one of [SQLITE_LOCK_NONE], [SQLITE_LOCK_SHARED],
  653. ** [SQLITE_LOCK_RESERVED], [SQLITE_LOCK_PENDING], or [SQLITE_LOCK_EXCLUSIVE])
  654. ** into an integer that the pArg argument points to. This capability
  655. ** is used during testing and only needs to be supported when SQLITE_TEST
  656. ** is defined.
  657. *)
  658. const
  659. SQLITE_FCNTL_LOCKSTATE = 1;
  660. (*
  661. ** CAPI3REF: Mutex Handle {F17110}
  662. **
  663. ** The mutex module within SQLite defines [sqlite3_mutex] to be an
  664. ** abstract type for a mutex object. The SQLite core never looks
  665. ** at the internal representation of an [sqlite3_mutex]. It only
  666. ** deals with pointers to the [sqlite3_mutex] object.
  667. **
  668. ** Mutexes are created using [sqlite3_mutex_alloc()].
  669. *)
  670. type
  671. psqlite3_mutex = ^sqlite3_mutex;
  672. sqlite3_mutex = record end;
  673. (*
  674. ** CAPI3REF: OS Interface Object {F11140}
  675. **
  676. ** An instance of this object defines the interface between the
  677. ** SQLite core and the underlying operating system. The "vfs"
  678. ** in the name of the object stands for "virtual file system".
  679. **
  680. ** The iVersion field is initially 1 but may be larger for future
  681. ** versions of SQLite. Additional fields may be appended to this
  682. ** object when the iVersion value is increased.
  683. **
  684. ** The szOsFile field is the size of the subclassed [sqlite3_file]
  685. ** structure used by this VFS. mxPathname is the maximum length of
  686. ** a pathname in this VFS.
  687. **
  688. ** Registered sqlite3_vfs objects are kept on a linked list formed by
  689. ** the pNext pointer. The [sqlite3_vfs_register()]
  690. ** and [sqlite3_vfs_unregister()] interfaces manage this list
  691. ** in a thread-safe way. The [sqlite3_vfs_find()] interface
  692. ** searches the list.
  693. **
  694. ** The pNext field is the only field in the sqlite3_vfs
  695. ** structure that SQLite will ever modify. SQLite will only access
  696. ** or modify this field while holding a particular static mutex.
  697. ** The application should never modify anything within the sqlite3_vfs
  698. ** object once the object has been registered.
  699. **
  700. ** The zName field holds the name of the VFS module. The name must
  701. ** be unique across all VFS modules.
  702. **
  703. ** {F11141} SQLite will guarantee that the zFilename string passed to
  704. ** xOpen() is a full pathname as generated by xFullPathname() and
  705. ** that the string will be valid and unchanged until xClose() is
  706. ** called. {END} So the [sqlite3_file] can store a pointer to the
  707. ** filename if it needs to remember the filename for some reason.
  708. **
  709. ** {F11142} The flags argument to xOpen() includes all bits set in
  710. ** the flags argument to [sqlite3_open_v2()]. Or if [sqlite3_open()]
  711. ** or [sqlite3_open16()] is used, then flags includes at least
  712. ** [SQLITE_OPEN_READWRITE] | [SQLITE_OPEN_CREATE]. {END}
  713. ** If xOpen() opens a file read-only then it sets *pOutFlags to
  714. ** include [SQLITE_OPEN_READONLY]. Other bits in *pOutFlags may be
  715. ** set.
  716. **
  717. ** {F11143} SQLite will also add one of the following flags to the xOpen()
  718. ** call, depending on the object being opened:
  719. **
  720. ** <ul>
  721. ** <li> [SQLITE_OPEN_MAIN_DB]
  722. ** <li> [SQLITE_OPEN_MAIN_JOURNAL]
  723. ** <li> [SQLITE_OPEN_TEMP_DB]
  724. ** <li> [SQLITE_OPEN_TEMP_JOURNAL]
  725. ** <li> [SQLITE_OPEN_TRANSIENT_DB]
  726. ** <li> [SQLITE_OPEN_SUBJOURNAL]
  727. ** <li> [SQLITE_OPEN_MASTER_JOURNAL]
  728. ** </ul> {END}
  729. **
  730. ** The file I/O implementation can use the object type flags to
  731. ** changes the way it deals with files. For example, an application
  732. ** that does not care about crash recovery or rollback might make
  733. ** the open of a journal file a no-op. Writes to this journal would
  734. ** also be no-ops, and any attempt to read the journal would return
  735. ** SQLITE_IOERR. Or the implementation might recognize that a database
  736. ** file will be doing page-aligned sector reads and writes in a random
  737. ** order and set up its I/O subsystem accordingly.
  738. **
  739. ** SQLite might also add one of the following flags to the xOpen
  740. ** method:
  741. **
  742. ** <ul>
  743. ** <li> [SQLITE_OPEN_DELETEONCLOSE]
  744. ** <li> [SQLITE_OPEN_EXCLUSIVE]
  745. ** </ul>
  746. **
  747. ** {F11145} The [SQLITE_OPEN_DELETEONCLOSE] flag means the file should be
  748. ** deleted when it is closed. {F11146} The [SQLITE_OPEN_DELETEONCLOSE]
  749. ** will be set for TEMP databases, journals and for subjournals.
  750. ** {F11147} The [SQLITE_OPEN_EXCLUSIVE] flag means the file should be opened
  751. ** for exclusive access. This flag is set for all files except
  752. ** for the main database file. {END}
  753. **
  754. ** {F11148} At least szOsFile bytes of memory are allocated by SQLite
  755. ** to hold the [sqlite3_file] structure passed as the third
  756. ** argument to xOpen. {END} The xOpen method does not have to
  757. ** allocate the structure; it should just fill it in.
  758. **
  759. ** {F11149} The flags argument to xAccess() may be [SQLITE_ACCESS_EXISTS]
  760. ** to test for the existance of a file,
  761. ** or [SQLITE_ACCESS_READWRITE] to test to see
  762. ** if a file is readable and writable, or [SQLITE_ACCESS_READ]
  763. ** to test to see if a file is at least readable. {END} The file can be a
  764. ** directory.
  765. **
  766. ** {F11150} SQLite will always allocate at least mxPathname+1 bytes for
  767. ** the output buffers for xGetTempname and xFullPathname. {F11151} The exact
  768. ** size of the output buffer is also passed as a parameter to both
  769. ** methods. {END} If the output buffer is not large enough, SQLITE_CANTOPEN
  770. ** should be returned. As this is handled as a fatal error by SQLite,
  771. ** vfs implementations should endeavor to prevent this by setting
  772. ** mxPathname to a sufficiently large value.
  773. **
  774. ** The xRandomness(), xSleep(), and xCurrentTime() interfaces
  775. ** are not strictly a part of the filesystem, but they are
  776. ** included in the VFS structure for completeness.
  777. ** The xRandomness() function attempts to return nBytes bytes
  778. ** of good-quality randomness into zOut. The return value is
  779. ** the actual number of bytes of randomness obtained. The
  780. ** xSleep() method causes the calling thread to sleep for at
  781. ** least the number of microseconds given. The xCurrentTime()
  782. ** method returns a Julian Day Number for the current date and
  783. ** time.
  784. *)
  785. type
  786. psqlite3_vfs = ^sqlite3_vfs;
  787. sqlite3_vfs = record
  788. iVersion : cint; (* Structure version number *)
  789. szOsFile : cint; (* Size of subclassed sqlite3_file *)
  790. mxPathname : cint; (* Maximum file pathname length *)
  791. pNext : psqlite3_vfs; (* Next registered VFS *)
  792. zName : pchar; (* Name of this virtual file system *)
  793. pAppData : ppointer; (* Pointer to application-specific *)
  794. Open : function(vfs: psqlite3_vfs; zName: pchar; f: psqlite3_file; flags: cint; pOutFlags: pcint): cint; cdecl;
  795. Delete : function(vfs: psqlite3_vfs; zName: pchar; syncDir: cint): cint; cdecl;
  796. Access : function(vfs: psqlite3_vfs; zName: pchar; flags: cint): cint; cdecl;
  797. GetTempname : function(vfs: psqlite3_vfs; nOut: cint; zOut: pchar): cint; cdecl;
  798. FullPathname : function(vfs: psqlite3_vfs; zName: pchar; nOut: cint; zOut: pchar): cint; cdecl;
  799. DlOpen : function(vfs: psqlite3_vfs; zFilename: pchar): pointer; cdecl;
  800. DlError : procedure(vfs: psqlite3_vfs; nByte: cint; zErrMsg: pchar); cdecl;
  801. DlSym : function(vfs: psqlite3_vfs; addr: pointer; zSymbol: pchar): pointer; cdecl;
  802. DlClose : procedure(vfs: psqlite3_vfs; addr: pointer); cdecl;
  803. Randomness : function(vfs: psqlite3_vfs; nByte: cint; zOut: pchar): cint; cdecl;
  804. Sleep : function(vfs: psqlite3_vfs; microseconds: cint): cint; cdecl;
  805. CurrentTime : function(vfs: psqlite3_vfs; time: pcdouble): cint; cdecl;
  806. (* New fields may be appended in figure versions. The iVersion
  807. ** value will increment whenever this happens.*)
  808. end;
  809. (*
  810. ** CAPI3REF: Flags for the xAccess VFS method {F11190}
  811. **
  812. ** {F11191} These integer constants can be used as the third parameter to
  813. ** the xAccess method of an [sqlite3_vfs] object. {END} They determine
  814. ** what kind of permissions the xAccess method is
  815. ** looking for. {F11192} With SQLITE_ACCESS_EXISTS, the xAccess method
  816. ** simply checks to see if the file exists. {F11193} With
  817. ** SQLITE_ACCESS_READWRITE, the xAccess method checks to see
  818. ** if the file is both readable and writable. {F11194} With
  819. ** SQLITE_ACCESS_READ the xAccess method
  820. ** checks to see if the file is readable.
  821. *)
  822. const
  823. SQLITE_ACCESS_EXISTS = 0;
  824. SQLITE_ACCESS_READWRITE = 1;
  825. SQLITE_ACCESS_READ = 2;
  826. (*
  827. ** CAPI3REF: Enable Or Disable Extended Result Codes {F12200}
  828. **
  829. ** The sqlite3_extended_result_codes() routine enables or disables the
  830. ** [SQLITE_IOERR_READ | extended result codes] feature of SQLite.
  831. ** The extended result codes are disabled by default for historical
  832. ** compatibility.
  833. **
  834. ** INVARIANTS:
  835. **
  836. ** {F12201} Each new [database connection] has the
  837. ** [extended result codes] feature
  838. ** disabled by default.
  839. **
  840. ** {F12202} The [sqlite3_extended_result_codes(D,F)] interface will enable
  841. ** [extended result codes] for the
  842. ** [database connection] D if the F parameter
  843. ** is true, or disable them if F is false.
  844. *)
  845. {$IFDEF S}function{$ELSE}var{$ENDIF}sqlite3_extended_result_codes{$IFDEF D}: function{$ENDIF}(db: psqlite3; onoff: cint): cint; cdecl;{$IFDEF S}external Sqlite3Lib;{$ENDIF}
  846. (*
  847. ** CAPI3REF: Last Insert Rowid {F12220}
  848. **
  849. ** Each entry in an SQLite table has a unique 64-bit signed
  850. ** integer key called the "rowid". The rowid is always available
  851. ** as an undeclared column named ROWID, OID, or _ROWID_ as long as those
  852. ** names are not also used by explicitly declared columns. If
  853. ** the table has a column of type INTEGER PRIMARY KEY then that column
  854. ** is another alias for the rowid.
  855. **
  856. ** This routine returns the rowid of the most recent
  857. ** successful INSERT into the database from the database connection
  858. ** shown in the first argument. If no successful inserts
  859. ** have ever occurred on this database connection, zero is returned.
  860. **
  861. ** If an INSERT occurs within a trigger, then the rowid of the
  862. ** inserted row is returned by this routine as long as the trigger
  863. ** is running. But once the trigger terminates, the value returned
  864. ** by this routine reverts to the last value inserted before the
  865. ** trigger fired.
  866. **
  867. ** An INSERT that fails due to a constraint violation is not a
  868. ** successful insert and does not change the value returned by this
  869. ** routine. Thus INSERT OR FAIL, INSERT OR IGNORE, INSERT OR ROLLBACK,
  870. ** and INSERT OR ABORT make no changes to the return value of this
  871. ** routine when their insertion fails. When INSERT OR REPLACE
  872. ** encounters a constraint violation, it does not fail. The
  873. ** INSERT continues to completion after deleting rows that caused
  874. ** the constraint problem so INSERT OR REPLACE will always change
  875. ** the return value of this interface.
  876. **
  877. ** For the purposes of this routine, an insert is considered to
  878. ** be successful even if it is subsequently rolled back.
  879. **
  880. ** INVARIANTS:
  881. **
  882. ** {F12221} The [sqlite3_last_insert_rowid()] function returns the
  883. ** rowid of the most recent successful insert done
  884. ** on the same database connection and within the same
  885. ** trigger context, or zero if there have
  886. ** been no qualifying inserts on that connection.
  887. **
  888. ** {F12223} The [sqlite3_last_insert_rowid()] function returns
  889. ** same value when called from the same trigger context
  890. ** immediately before and after a ROLLBACK.
  891. **
  892. ** LIMITATIONS:
  893. **
  894. ** {U12232} If a separate thread does a new insert on the same
  895. ** database connection while the [sqlite3_last_insert_rowid()]
  896. ** function is running and thus changes the last insert rowid,
  897. ** then the value returned by [sqlite3_last_insert_rowid()] is
  898. ** unpredictable and might not equal either the old or the new
  899. ** last insert rowid.
  900. *)
  901. {$IFDEF S}function{$ELSE}var{$ENDIF}sqlite3_last_insert_rowid{$IFDEF D}: function{$ENDIF}(db: psqlite3): sqlite3_int64; cdecl;{$IFDEF S}external Sqlite3Lib;{$ENDIF}
  902. (*
  903. ** CAPI3REF: Count The Number Of Rows Modified {F12240}
  904. **
  905. ** This function returns the number of database rows that were changed
  906. ** or inserted or deleted by the most recently completed SQL statement
  907. ** on the connection specified by the first parameter. Only
  908. ** changes that are directly specified by the INSERT, UPDATE, or
  909. ** DELETE statement are counted. Auxiliary changes caused by
  910. ** triggers are not counted. Use the [sqlite3_total_changes()] function
  911. ** to find the total number of changes including changes caused by triggers.
  912. **
  913. ** A "row change" is a change to a single row of a single table
  914. ** caused by an INSERT, DELETE, or UPDATE statement. Rows that
  915. ** are changed as side effects of REPLACE constraint resolution,
  916. ** rollback, ABORT processing, DROP TABLE, or by any other
  917. ** mechanisms do not count as direct row changes.
  918. **
  919. ** A "trigger context" is a scope of execution that begins and
  920. ** ends with the script of a trigger. Most SQL statements are
  921. ** evaluated outside of any trigger. This is the "top level"
  922. ** trigger context. If a trigger fires from the top level, a
  923. ** new trigger context is entered for the duration of that one
  924. ** trigger. Subtriggers create subcontexts for their duration.
  925. **
  926. ** Calling [sqlite3_exec()] or [sqlite3_step()] recursively does
  927. ** not create a new trigger context.
  928. **
  929. ** This function returns the number of direct row changes in the
  930. ** most recent INSERT, UPDATE, or DELETE statement within the same
  931. ** trigger context.
  932. **
  933. ** So when called from the top level, this function returns the
  934. ** number of changes in the most recent INSERT, UPDATE, or DELETE
  935. ** that also occurred at the top level.
  936. ** Within the body of a trigger, the sqlite3_changes() interface
  937. ** can be called to find the number of
  938. ** changes in the most recently completed INSERT, UPDATE, or DELETE
  939. ** statement within the body of the same trigger.
  940. ** However, the number returned does not include in changes
  941. ** caused by subtriggers since they have their own context.
  942. **
  943. ** SQLite implements the command "DELETE FROM table" without
  944. ** a WHERE clause by dropping and recreating the table. (This is much
  945. ** faster than going through and deleting individual elements from the
  946. ** table.) Because of this optimization, the deletions in
  947. ** "DELETE FROM table" are not row changes and will not be counted
  948. ** by the sqlite3_changes() or [sqlite3_total_changes()] functions.
  949. ** To get an accurate count of the number of rows deleted, use
  950. ** "DELETE FROM table WHERE 1" instead.
  951. **
  952. ** INVARIANTS:
  953. **
  954. ** {F12241} The [sqlite3_changes()] function returns the number of
  955. ** row changes caused by the most recent INSERT, UPDATE,
  956. ** or DELETE statement on the same database connection and
  957. ** within the same trigger context, or zero if there have
  958. ** not been any qualifying row changes.
  959. **
  960. ** LIMITATIONS:
  961. **
  962. ** {U12252} If a separate thread makes changes on the same database connection
  963. ** while [sqlite3_changes()] is running then the value returned
  964. ** is unpredictable and unmeaningful.
  965. *)
  966. {$IFDEF S}function{$ELSE}var{$ENDIF}sqlite3_changes{$IFDEF D}: function{$ENDIF}(db: psqlite3): cint; cdecl;{$IFDEF S}external Sqlite3Lib;{$ENDIF}
  967. (*
  968. ** CAPI3REF: Total Number Of Rows Modified {F12260}
  969. ***
  970. ** This function returns the number of row changes caused
  971. ** by INSERT, UPDATE or DELETE statements since the database handle
  972. ** was opened. The count includes all changes from all trigger
  973. ** contexts. But the count does not include changes used to
  974. ** implement REPLACE constraints, do rollbacks or ABORT processing,
  975. ** or DROP table processing.
  976. ** The changes
  977. ** are counted as soon as the statement that makes them is completed
  978. ** (when the statement handle is passed to [sqlite3_reset()] or
  979. ** [sqlite3_finalize()]).
  980. **
  981. ** SQLite implements the command "DELETE FROM table" without
  982. ** a WHERE clause by dropping and recreating the table. (This is much
  983. ** faster than going
  984. ** through and deleting individual elements from the table.) Because of
  985. ** this optimization, the change count for "DELETE FROM table" will be
  986. ** zero regardless of the number of elements that were originally in the
  987. ** table. To get an accurate count of the number of rows deleted, use
  988. ** "DELETE FROM table WHERE 1" instead.
  989. **
  990. ** See also the [sqlite3_changes()] interface.
  991. **
  992. ** INVARIANTS:
  993. **
  994. ** {F12261} The [sqlite3_total_changes()] returns the total number
  995. ** of row changes caused by INSERT, UPDATE, and/or DELETE
  996. ** statements on the same [database connection], in any
  997. ** trigger context, since the database connection was
  998. ** created.
  999. **
  1000. ** LIMITATIONS:
  1001. **
  1002. ** {U12264} If a separate thread makes changes on the same database connection
  1003. ** while [sqlite3_total_changes()] is running then the value
  1004. ** returned is unpredictable and unmeaningful.
  1005. *)
  1006. {$IFDEF S}function{$ELSE}var{$ENDIF}sqlite3_total_changes{$IFDEF D}: function{$ENDIF}(db: psqlite3): cint; cdecl;{$IFDEF S}external Sqlite3Lib;{$ENDIF}
  1007. (*
  1008. ** CAPI3REF: Interrupt A Long-Running Query {F12270}
  1009. **
  1010. ** This function causes any pending database operation to abort and
  1011. ** return at its earliest opportunity. This routine is typically
  1012. ** called in response to a user action such as pressing "Cancel"
  1013. ** or Ctrl-C where the user wants a long query operation to halt
  1014. ** immediately.
  1015. **
  1016. ** It is safe to call this routine from a thread different from the
  1017. ** thread that is currently running the database operation. But it
  1018. ** is not safe to call this routine with a database connection that
  1019. ** is closed or might close before sqlite3_interrupt() returns.
  1020. **
  1021. ** If an SQL is very nearly finished at the time when sqlite3_interrupt()
  1022. ** is called, then it might not have an opportunity to be interrupted.
  1023. ** It might continue to completion.
  1024. ** An SQL operation that is interrupted will return
  1025. ** [SQLITE_INTERRUPT]. If the interrupted SQL operation is an
  1026. ** INSERT, UPDATE, or DELETE that is inside an explicit transaction,
  1027. ** then the entire transaction will be rolled back automatically.
  1028. ** A call to sqlite3_interrupt() has no effect on SQL statements
  1029. ** that are started after sqlite3_interrupt() returns.
  1030. **
  1031. ** INVARIANTS:
  1032. **
  1033. ** {F12271} The [sqlite3_interrupt()] interface will force all running
  1034. ** SQL statements associated with the same database connection
  1035. ** to halt after processing at most one additional row of
  1036. ** data.
  1037. **
  1038. ** {F12272} Any SQL statement that is interrupted by [sqlite3_interrupt()]
  1039. ** will return [SQLITE_INTERRUPT].
  1040. **
  1041. ** LIMITATIONS:
  1042. **
  1043. ** {U12279} If the database connection closes while [sqlite3_interrupt()]
  1044. ** is running then bad things will likely happen.
  1045. *)
  1046. {$IFDEF S}procedure{$ELSE}var{$ENDIF}sqlite3_interrupt{$IFDEF D}: procedure{$ENDIF}(db: psqlite3); cdecl;{$IFDEF S}external Sqlite3Lib;{$ENDIF}
  1047. (*
  1048. ** CAPI3REF: Determine If An SQL Statement Is Complete {F10510}
  1049. **
  1050. ** These routines are useful for command-line input to determine if the
  1051. ** currently entered text seems to form complete a SQL statement or
  1052. ** if additional input is needed before sending the text into
  1053. ** SQLite for parsing. These routines return true if the input string
  1054. ** appears to be a complete SQL statement. A statement is judged to be
  1055. ** complete if it ends with a semicolon token and is not a fragment of a
  1056. ** CREATE TRIGGER statement. Semicolons that are embedded within
  1057. ** string literals or quoted identifier names or comments are not
  1058. ** independent tokens (they are part of the token in which they are
  1059. ** embedded) and thus do not count as a statement terminator.
  1060. **
  1061. ** These routines do not parse the SQL and
  1062. ** so will not detect syntactically incorrect SQL.
  1063. **
  1064. ** INVARIANTS:
  1065. **
  1066. ** {F10511} The sqlite3_complete() and sqlite3_complete16() functions
  1067. ** return true (non-zero) if and only if the last
  1068. ** non-whitespace token in their input is a semicolon that
  1069. ** is not in between the BEGIN and END of a CREATE TRIGGER
  1070. ** statement.
  1071. **
  1072. ** LIMITATIONS:
  1073. **
  1074. ** {U10512} The input to sqlite3_complete() must be a zero-terminated
  1075. ** UTF-8 string.
  1076. **
  1077. ** {U10513} The input to sqlite3_complete16() must be a zero-terminated
  1078. ** UTF-16 string in native byte order.
  1079. *)
  1080. {$IFDEF S}function{$ELSE}var{$ENDIF}sqlite3_complete{$IFDEF D}: function{$ENDIF}(sql: pchar): cint; cdecl;{$IFDEF S}external Sqlite3Lib;{$ENDIF}
  1081. {$IFDEF S}function{$ELSE}var{$ENDIF}sqlite3_complete16{$IFDEF D}: function{$ENDIF}(sql: pchar): cint; cdecl;{$IFDEF S}external Sqlite3Lib;{$ENDIF}
  1082. (*
  1083. ** CAPI3REF: Register A Callback To Handle SQLITE_BUSY Errors {F12310}
  1084. **
  1085. ** This routine identifies a callback function that might be
  1086. ** invoked whenever an attempt is made to open a database table
  1087. ** that another thread or process has locked.
  1088. ** If the busy callback is NULL, then [SQLITE_BUSY]
  1089. ** or [SQLITE_IOERR_BLOCKED]
  1090. ** is returned immediately upon encountering the lock.
  1091. ** If the busy callback is not NULL, then the
  1092. ** callback will be invoked with two arguments. The
  1093. ** first argument to the handler is a copy of the void* pointer which
  1094. ** is the third argument to this routine. The second argument to
  1095. ** the handler is the number of times that the busy handler has
  1096. ** been invoked for this locking event. If the
  1097. ** busy callback returns 0, then no additional attempts are made to
  1098. ** access the database and [SQLITE_BUSY] or [SQLITE_IOERR_BLOCKED] is returned.
  1099. ** If the callback returns non-zero, then another attempt
  1100. ** is made to open the database for reading and the cycle repeats.
  1101. **
  1102. ** The presence of a busy handler does not guarantee that
  1103. ** it will be invoked when there is lock contention.
  1104. ** If SQLite determines that invoking the busy handler could result in
  1105. ** a deadlock, it will go ahead and return [SQLITE_BUSY] or
  1106. ** [SQLITE_IOERR_BLOCKED] instead of invoking the
  1107. ** busy handler.
  1108. ** Consider a scenario where one process is holding a read lock that
  1109. ** it is trying to promote to a reserved lock and
  1110. ** a second process is holding a reserved lock that it is trying
  1111. ** to promote to an exclusive lock. The first process cannot proceed
  1112. ** because it is blocked by the second and the second process cannot
  1113. ** proceed because it is blocked by the first. If both processes
  1114. ** invoke the busy handlers, neither will make any progress. Therefore,
  1115. ** SQLite returns [SQLITE_BUSY] for the first process, hoping that this
  1116. ** will induce the first process to release its read lock and allow
  1117. ** the second process to proceed.
  1118. **
  1119. ** The default busy callback is NULL.
  1120. **
  1121. ** The [SQLITE_BUSY] error is converted to [SQLITE_IOERR_BLOCKED]
  1122. ** when SQLite is in the middle of a large transaction where all the
  1123. ** changes will not fit into the in-memory cache. SQLite will
  1124. ** already hold a RESERVED lock on the database file, but it needs
  1125. ** to promote this lock to EXCLUSIVE so that it can spill cache
  1126. ** pages into the database file without harm to concurrent
  1127. ** readers. If it is unable to promote the lock, then the in-memory
  1128. ** cache will be left in an inconsistent state and so the error
  1129. ** code is promoted from the relatively benign [SQLITE_BUSY] to
  1130. ** the more severe [SQLITE_IOERR_BLOCKED]. This error code promotion
  1131. ** forces an automatic rollback of the changes. See the
  1132. ** <a href="http://www.sqlite.org/cvstrac/wiki?p=CorruptionFollowingBusyError">
  1133. ** CorruptionFollowingBusyError</a> wiki page for a discussion of why
  1134. ** this is important.
  1135. **
  1136. ** There can only be a single busy handler defined for each database
  1137. ** connection. Setting a new busy handler clears any previous one.
  1138. ** Note that calling [sqlite3_busy_timeout()] will also set or clear
  1139. ** the busy handler.
  1140. **
  1141. ** INVARIANTS:
  1142. **
  1143. ** {F12311} The [sqlite3_busy_handler()] function replaces the busy handler
  1144. ** callback in the database connection identified by the 1st
  1145. ** parameter with a new busy handler identified by the 2nd and 3rd
  1146. ** parameters.
  1147. **
  1148. ** {F12312} The default busy handler for new database connections is NULL.
  1149. **
  1150. ** {F12314} When two or more database connection share a common cache,
  1151. ** the busy handler for the database connection currently using
  1152. ** the cache is invoked when the cache encounters a lock.
  1153. **
  1154. ** {F12316} If a busy handler callback returns zero, then the SQLite
  1155. ** interface that provoked the locking event will return
  1156. ** [SQLITE_BUSY].
  1157. **
  1158. ** {F12318} SQLite will invokes the busy handler with two argument which
  1159. ** are a copy of the pointer supplied by the 3rd parameter to
  1160. ** [sqlite3_busy_handler()] and a count of the number of prior
  1161. ** invocations of the busy handler for the same locking event.
  1162. **
  1163. ** LIMITATIONS:
  1164. **
  1165. ** {U12319} A busy handler should not call close the database connection
  1166. ** or prepared statement that invoked the busy handler.
  1167. *)
  1168. type
  1169. busyhandler_callback = function(user: pointer; cnt: cint): cint; cdecl;
  1170. {$IFDEF S}function{$ELSE}var{$ENDIF}sqlite3_busy_handler{$IFDEF D}: function{$ENDIF}(db: psqlite3; cb: busyhandler_callback; user: pointer): cint; cdecl;{$IFDEF S}external Sqlite3Lib;{$ENDIF}
  1171. (*
  1172. ** CAPI3REF: Set A Busy Timeout {F12340}
  1173. **
  1174. ** This routine sets a [sqlite3_busy_handler | busy handler]
  1175. ** that sleeps for a while when a
  1176. ** table is locked. The handler will sleep multiple times until
  1177. ** at least "ms" milliseconds of sleeping have been done. {F12343} After
  1178. ** "ms" milliseconds of sleeping, the handler returns 0 which
  1179. ** causes [sqlite3_step()] to return [SQLITE_BUSY] or [SQLITE_IOERR_BLOCKED].
  1180. **
  1181. ** Calling this routine with an argument less than or equal to zero
  1182. ** turns off all busy handlers.
  1183. **
  1184. ** There can only be a single busy handler for a particular database
  1185. ** connection. If another busy handler was defined
  1186. ** (using [sqlite3_busy_handler()]) prior to calling
  1187. ** this routine, that other busy handler is cleared.
  1188. **
  1189. ** INVARIANTS:
  1190. **
  1191. ** {F12341} The [sqlite3_busy_timeout()] function overrides any prior
  1192. ** [sqlite3_busy_timeout()] or [sqlite3_busy_handler()] setting
  1193. ** on the same database connection.
  1194. **
  1195. ** {F12343} If the 2nd parameter to [sqlite3_busy_timeout()] is less than
  1196. ** or equal to zero, then the busy handler is cleared so that
  1197. ** all subsequent locking events immediately return [SQLITE_BUSY].
  1198. **
  1199. ** {F12344} If the 2nd parameter to [sqlite3_busy_timeout()] is a positive
  1200. ** number N, then a busy handler is set that repeatedly calls
  1201. ** the xSleep() method in the VFS interface until either the
  1202. ** lock clears or until the cumulative sleep time reported back
  1203. ** by xSleep() exceeds N milliseconds.
  1204. *)
  1205. {$IFDEF S}function{$ELSE}var{$ENDIF}sqlite3_busy_timeout{$IFDEF D}: function{$ENDIF}(db: psqlite3; ms: cint): cint; cdecl;{$IFDEF S}external Sqlite3Lib;{$ENDIF}
  1206. (*
  1207. ** CAPI3REF: Convenience Routines For Running Queries {F12370}
  1208. **
  1209. ** Definition: A <b>result table</b> is memory data structure created by the
  1210. ** [sqlite3_get_table()] interface. A result table records the
  1211. ** complete query results from one or more queries.
  1212. **
  1213. ** The table conceptually has a number of rows and columns. But
  1214. ** these numbers are not part of the result table itself. These
  1215. ** numbers are obtained separately. Let N be the number of rows
  1216. ** and M be the number of columns.
  1217. **
  1218. ** A result table is an array of pointers to zero-terminated
  1219. ** UTF-8 strings. There are (N+1)*M elements in the array.
  1220. ** The first M pointers point to zero-terminated strings that
  1221. ** contain the names of the columns.
  1222. ** The remaining entries all point to query results. NULL
  1223. ** values are give a NULL pointer. All other values are in
  1224. ** their UTF-8 zero-terminated string representation as returned by
  1225. ** [sqlite3_column_text()].
  1226. **
  1227. ** A result table might consists of one or more memory allocations.
  1228. ** It is not safe to pass a result table directly to [sqlite3_free()].
  1229. ** A result table should be deallocated using [sqlite3_free_table()].
  1230. **
  1231. ** As an example of the result table format, suppose a query result
  1232. ** is as follows:
  1233. **
  1234. ** <blockquote><pre>
  1235. ** Name | Age
  1236. ** -----------------------
  1237. ** Alice | 43
  1238. ** Bob | 28
  1239. ** Cindy | 21
  1240. ** </pre></blockquote>
  1241. **
  1242. ** There are two column (M==2) and three rows (N==3). Thus the
  1243. ** result table has 8 entries. Suppose the result table is stored
  1244. ** in an array names azResult. Then azResult holds this content:
  1245. **
  1246. ** <blockquote><pre>
  1247. ** azResult&#91;0] = "Name";
  1248. ** azResult&#91;1] = "Age";
  1249. ** azResult&#91;2] = "Alice";
  1250. ** azResult&#91;3] = "43";
  1251. ** azResult&#91;4] = "Bob";
  1252. ** azResult&#91;5] = "28";
  1253. ** azResult&#91;6] = "Cindy";
  1254. ** azResult&#91;7] = "21";
  1255. ** </pre></blockquote>
  1256. **
  1257. ** The sqlite3_get_table() function evaluates one or more
  1258. ** semicolon-separated SQL statements in the zero-terminated UTF-8
  1259. ** string of its 2nd parameter. It returns a result table to the
  1260. ** pointer given in its 3rd parameter.
  1261. **
  1262. ** After the calling function has finished using the result, it should
  1263. ** pass the pointer to the result table to sqlite3_free_table() in order to
  1264. ** release the memory that was malloc-ed. Because of the way the
  1265. ** [sqlite3_malloc()] happens within sqlite3_get_table(), the calling
  1266. ** function must not try to call [sqlite3_free()] directly. Only
  1267. ** [sqlite3_free_table()] is able to release the memory properly and safely.
  1268. **
  1269. ** The sqlite3_get_table() interface is implemented as a wrapper around
  1270. ** [sqlite3_exec()]. The sqlite3_get_table() routine does not have access
  1271. ** to any internal data structures of SQLite. It uses only the public
  1272. ** interface defined here. As a consequence, errors that occur in the
  1273. ** wrapper layer outside of the internal [sqlite3_exec()] call are not
  1274. ** reflected in subsequent calls to [sqlite3_errcode()] or
  1275. ** [sqlite3_errmsg()].
  1276. **
  1277. ** INVARIANTS:
  1278. **
  1279. ** {F12371} If a [sqlite3_get_table()] fails a memory allocation, then
  1280. ** it frees the result table under construction, aborts the
  1281. ** query in process, skips any subsequent queries, sets the
  1282. ** *resultp output pointer to NULL and returns [SQLITE_NOMEM].
  1283. **
  1284. ** {F12373} If the ncolumn parameter to [sqlite3_get_table()] is not NULL
  1285. ** then [sqlite3_get_table()] write the number of columns in the
  1286. ** result set of the query into *ncolumn if the query is
  1287. ** successful (if the function returns SQLITE_OK).
  1288. **
  1289. ** {F12374} If the nrow parameter to [sqlite3_get_table()] is not NULL
  1290. ** then [sqlite3_get_table()] write the number of rows in the
  1291. ** result set of the query into *nrow if the query is
  1292. ** successful (if the function returns SQLITE_OK).
  1293. **
  1294. ** {F12376} The [sqlite3_get_table()] function sets its *ncolumn value
  1295. ** to the number of columns in the result set of the query in the
  1296. ** sql parameter, or to zero if the query in sql has an empty
  1297. ** result set.
  1298. *)
  1299. {$IFDEF S}function{$ELSE}var{$ENDIF}sqlite3_get_table{$IFDEF D}: function{$ENDIF}(
  1300. db: psqlite3; (* An open database *)
  1301. sql: pchar; (* SQL to be evaluated *)
  1302. pResult: pppchar; (* Results of the query *)
  1303. nrow: pcint; (* Number of result rows written here *)
  1304. ncolumn: pcint; (* Number of result columns written here *)
  1305. errmsg: ppchar (* Error msg written here *)
  1306. ): cint; cdecl;{$IFDEF S}external Sqlite3Lib;{$ENDIF}
  1307. {$IFDEF S}procedure{$ELSE}var{$ENDIF}sqlite3_free_table{$IFDEF D}: procedure{$ENDIF}(result: ppchar); cdecl;{$IFDEF S}external Sqlite3Lib;{$ENDIF}
  1308. (*
  1309. ** CAPI3REF: Formatted String Printing Functions {F17400}
  1310. **
  1311. ** These routines are workalikes of the "printf()" family of functions
  1312. ** from the standard C library.
  1313. **
  1314. ** The sqlite3_mprintf() and sqlite3_vmprintf() routines write their
  1315. ** results into memory obtained from [sqlite3_malloc()].
  1316. ** The strings returned by these two routines should be
  1317. ** released by [sqlite3_free()]. Both routines return a
  1318. ** NULL pointer if [sqlite3_malloc()] is unable to allocate enough
  1319. ** memory to hold the resulting string.
  1320. **
  1321. ** In sqlite3_snprintf() routine is similar to "snprintf()" from
  1322. ** the standard C library. The result is written into the
  1323. ** buffer supplied as the second parameter whose size is given by
  1324. ** the first parameter. Note that the order of the
  1325. ** first two parameters is reversed from snprintf(). This is an
  1326. ** historical accident that cannot be fixed without breaking
  1327. ** backwards compatibility. Note also that sqlite3_snprintf()
  1328. ** returns a pointer to its buffer instead of the number of
  1329. ** characters actually written into the buffer. We admit that
  1330. ** the number of characters written would be a more useful return
  1331. ** value but we cannot change the implementation of sqlite3_snprintf()
  1332. ** now without breaking compatibility.
  1333. **
  1334. ** As long as the buffer size is greater than zero, sqlite3_snprintf()
  1335. ** guarantees that the buffer is always zero-terminated. The first
  1336. ** parameter "n" is the total size of the buffer, including space for
  1337. ** the zero terminator. So the longest string that can be completely
  1338. ** written will be n-1 characters.
  1339. **
  1340. ** These routines all implement some additional formatting
  1341. ** options that are useful for constructing SQL statements.
  1342. ** All of the usual printf formatting options apply. In addition, there
  1343. ** is are "%q", "%Q", and "%z" options.
  1344. **
  1345. ** The %q option works like %s in that it substitutes a null-terminated
  1346. ** string from the argument list. But %q also doubles every '\'' character.
  1347. ** %q is designed for use inside a string literal. By doubling each '\''
  1348. ** character it escapes that character and allows it to be inserted into
  1349. ** the string.
  1350. **
  1351. ** For example, so some string variable contains text as follows:
  1352. **
  1353. ** <blockquote><pre>
  1354. ** char *zText = "It's a happy day!";
  1355. ** </pre></blockquote>
  1356. **
  1357. ** One can use this text in an SQL statement as follows:
  1358. **
  1359. ** <blockquote><pre>
  1360. ** char *zSQL = sqlite3_mprintf("INSERT INTO table VALUES('%q')", zText);
  1361. ** sqlite3_exec(db, zSQL, 0, 0, 0);
  1362. ** sqlite3_free(zSQL);
  1363. ** </pre></blockquote>
  1364. **
  1365. ** Because the %q format string is used, the '\'' character in zText
  1366. ** is escaped and the SQL generated is as follows:
  1367. **
  1368. ** <blockquote><pre>
  1369. ** INSERT INTO table1 VALUES('It''s a happy day!')
  1370. ** </pre></blockquote>
  1371. **
  1372. ** This is correct. Had we used %s instead of %q, the generated SQL
  1373. ** would have looked like this:
  1374. **
  1375. ** <blockquote><pre>
  1376. ** INSERT INTO table1 VALUES('It's a happy day!');
  1377. ** </pre></blockquote>
  1378. **
  1379. ** This second example is an SQL syntax error. As a general rule you
  1380. ** should always use %q instead of %s when inserting text into a string
  1381. ** literal.
  1382. **
  1383. ** The %Q option works like %q except it also adds single quotes around
  1384. ** the outside of the total string. Or if the parameter in the argument
  1385. ** list is a NULL pointer, %Q substitutes the text "NULL" (without single
  1386. ** quotes) in place of the %Q option. {END} So, for example, one could say:
  1387. **
  1388. ** <blockquote><pre>
  1389. ** char *zSQL = sqlite3_mprintf("INSERT INTO table VALUES(%Q)", zText);
  1390. ** sqlite3_exec(db, zSQL, 0, 0, 0);
  1391. ** sqlite3_free(zSQL);
  1392. ** </pre></blockquote>
  1393. **
  1394. ** The code above will render a correct SQL statement in the zSQL
  1395. ** variable even if the zText variable is a NULL pointer.
  1396. **
  1397. ** The "%z" formatting option works exactly like "%s" with the
  1398. ** addition that after the string has been read and copied into
  1399. ** the result, [sqlite3_free()] is called on the input string. {END}
  1400. **
  1401. ** INVARIANTS:
  1402. **
  1403. ** {F17403} The [sqlite3_mprintf()] and [sqlite3_vmprintf()] interfaces
  1404. ** return either pointers to zero-terminated UTF-8 strings held in
  1405. ** memory obtained from [sqlite3_malloc()] or NULL pointers if
  1406. ** a call to [sqlite3_malloc()] fails.
  1407. **
  1408. ** {F17406} The [sqlite3_snprintf()] interface writes a zero-terminated
  1409. ** UTF-8 string into the buffer pointed to by the second parameter
  1410. ** provided that the first parameter is greater than zero.
  1411. **
  1412. ** {F17407} The [sqlite3_snprintf()] interface does not writes slots of
  1413. ** its output buffer (the second parameter) outside the range
  1414. ** of 0 through N-1 (where N is the first parameter)
  1415. ** regardless of the length of the string
  1416. ** requested by the format specification.
  1417. **
  1418. *)
  1419. //char *sqlite3_mprintf(const char*,...);
  1420. //char *sqlite3_vmprintf(const char*, va_list);
  1421. //char *sqlite3_snprintf(int,char*,const char*, ...);
  1422. (*
  1423. ** CAPI3REF: Memory Allocation Subsystem {F17300}
  1424. **
  1425. ** The SQLite core uses these three routines for all of its own
  1426. ** internal memory allocation needs. "Core" in the previous sentence
  1427. ** does not include operating-system specific VFS implementation. The
  1428. ** windows VFS uses native malloc and free for some operations.
  1429. **
  1430. ** The sqlite3_malloc() routine returns a pointer to a block
  1431. ** of memory at least N bytes in length, where N is the parameter.
  1432. ** If sqlite3_malloc() is unable to obtain sufficient free
  1433. ** memory, it returns a NULL pointer. If the parameter N to
  1434. ** sqlite3_malloc() is zero or negative then sqlite3_malloc() returns
  1435. ** a NULL pointer.
  1436. **
  1437. ** Calling sqlite3_free() with a pointer previously returned
  1438. ** by sqlite3_malloc() or sqlite3_realloc() releases that memory so
  1439. ** that it might be reused. The sqlite3_free() routine is
  1440. ** a no-op if is called with a NULL pointer. Passing a NULL pointer
  1441. ** to sqlite3_free() is harmless. After being freed, memory
  1442. ** should neither be read nor written. Even reading previously freed
  1443. ** memory might result in a segmentation fault or other severe error.
  1444. ** Memory corruption, a segmentation fault, or other severe error
  1445. ** might result if sqlite3_free() is called with a non-NULL pointer that
  1446. ** was not obtained from sqlite3_malloc() or sqlite3_free().
  1447. **
  1448. ** The sqlite3_realloc() interface attempts to resize a
  1449. ** prior memory allocation to be at least N bytes, where N is the
  1450. ** second parameter. The memory allocation to be resized is the first
  1451. ** parameter. If the first parameter to sqlite3_realloc()
  1452. ** is a NULL pointer then its behavior is identical to calling
  1453. ** sqlite3_malloc(N) where N is the second parameter to sqlite3_realloc().
  1454. ** If the second parameter to sqlite3_realloc() is zero or
  1455. ** negative then the behavior is exactly the same as calling
  1456. ** sqlite3_free(P) where P is the first parameter to sqlite3_realloc().
  1457. ** Sqlite3_realloc() returns a pointer to a memory allocation
  1458. ** of at least N bytes in size or NULL if sufficient memory is unavailable.
  1459. ** If M is the size of the prior allocation, then min(N,M) bytes
  1460. ** of the prior allocation are copied into the beginning of buffer returned
  1461. ** by sqlite3_realloc() and the prior allocation is freed.
  1462. ** If sqlite3_realloc() returns NULL, then the prior allocation
  1463. ** is not freed.
  1464. **
  1465. ** The memory returned by sqlite3_malloc() and sqlite3_realloc()
  1466. ** is always aligned to at least an 8 byte boundary. {END}
  1467. **
  1468. ** The default implementation
  1469. ** of the memory allocation subsystem uses the malloc(), realloc()
  1470. ** and free() provided by the standard C library. {F17382} However, if
  1471. ** SQLite is compiled with the following C preprocessor macro
  1472. **
  1473. ** <blockquote> SQLITE_MEMORY_SIZE=<i>NNN</i> </blockquote>
  1474. **
  1475. ** where <i>NNN</i> is an integer, then SQLite create a static
  1476. ** array of at least <i>NNN</i> bytes in size and use that array
  1477. ** for all of its dynamic memory allocation needs. {END} Additional
  1478. ** memory allocator options may be added in future releases.
  1479. **
  1480. ** In SQLite version 3.5.0 and 3.5.1, it was possible to define
  1481. ** the SQLITE_OMIT_MEMORY_ALLOCATION which would cause the built-in
  1482. ** implementation of these routines to be omitted. That capability
  1483. ** is no longer provided. Only built-in memory allocators can be
  1484. ** used.
  1485. **
  1486. ** The windows OS interface layer calls
  1487. ** the system malloc() and free() directly when converting
  1488. ** filenames between the UTF-8 encoding used by SQLite
  1489. ** and whatever filename encoding is used by the particular windows
  1490. ** installation. Memory allocation errors are detected, but
  1491. ** they are reported back as [SQLITE_CANTOPEN] or
  1492. ** [SQLITE_IOERR] rather than [SQLITE_NOMEM].
  1493. **
  1494. ** INVARIANTS:
  1495. **
  1496. ** {F17303} The [sqlite3_malloc(N)] interface returns either a pointer to
  1497. ** newly checked-out block of at least N bytes of memory
  1498. ** that is 8-byte aligned,
  1499. ** or it returns NULL if it is unable to fulfill the request.
  1500. **
  1501. ** {F17304} The [sqlite3_malloc(N)] interface returns a NULL pointer if
  1502. ** N is less than or equal to zero.
  1503. **
  1504. ** {F17305} The [sqlite3_free(P)] interface releases memory previously
  1505. ** returned from [sqlite3_malloc()] or [sqlite3_realloc()],
  1506. ** making it available for reuse.
  1507. **
  1508. ** {F17306} A call to [sqlite3_free(NULL)] is a harmless no-op.
  1509. **
  1510. ** {F17310} A call to [sqlite3_realloc(0,N)] is equivalent to a call
  1511. ** to [sqlite3_malloc(N)].
  1512. **
  1513. ** {F17312} A call to [sqlite3_realloc(P,0)] is equivalent to a call
  1514. ** to [sqlite3_free(P)].
  1515. **
  1516. ** {F17315} The SQLite core uses [sqlite3_malloc()], [sqlite3_realloc()],
  1517. ** and [sqlite3_free()] for all of its memory allocation and
  1518. ** deallocation needs.
  1519. **
  1520. ** {F17318} The [sqlite3_realloc(P,N)] interface returns either a pointer
  1521. ** to a block of checked-out memory of at least N bytes in size
  1522. ** that is 8-byte aligned, or a NULL pointer.
  1523. **
  1524. ** {F17321} When [sqlite3_realloc(P,N)] returns a non-NULL pointer, it first
  1525. ** copies the first K bytes of content from P into the newly allocated
  1526. ** where K is the lessor of N and the size of the buffer P.
  1527. **
  1528. ** {F17322} When [sqlite3_realloc(P,N)] returns a non-NULL pointer, it first
  1529. ** releases the buffer P.
  1530. **
  1531. ** {F17323} When [sqlite3_realloc(P,N)] returns NULL, the buffer P is
  1532. ** not modified or released.
  1533. **
  1534. ** LIMITATIONS:
  1535. **
  1536. ** {U17350} The pointer arguments to [sqlite3_free()] and [sqlite3_realloc()]
  1537. ** must be either NULL or else a pointer obtained from a prior
  1538. ** invocation of [sqlite3_malloc()] or [sqlite3_realloc()] that has
  1539. ** not been released.
  1540. **
  1541. ** {U17351} The application must not read or write any part of
  1542. ** a block of memory after it has been released using
  1543. ** [sqlite3_free()] or [sqlite3_realloc()].
  1544. **
  1545. *)
  1546. {$IFDEF S}function{$ELSE}var{$ENDIF}sqlite3_malloc{$IFDEF D}: function{$ENDIF}(size: cint): pointer;cdecl;{$IFDEF S}external Sqlite3Lib;{$ENDIF}
  1547. {$IFDEF S}function{$ELSE}var{$ENDIF}sqlite3_realloc{$IFDEF D}: function{$ENDIF}(ptr: pointer; size: cint): pointer;cdecl;{$IFDEF S}external Sqlite3Lib;{$ENDIF}
  1548. {$IFDEF S}procedure{$ELSE}var{$ENDIF}sqlite3_free{$IFDEF D}: procedure{$ENDIF}(ptr: pointer);cdecl;{$IFDEF S}external Sqlite3Lib;{$ENDIF}
  1549. (*
  1550. ** CAPI3REF: Memory Allocator Statistics {F17370}
  1551. **
  1552. ** SQLite provides these two interfaces for reporting on the status
  1553. ** of the [sqlite3_malloc()], [sqlite3_free()], and [sqlite3_realloc()]
  1554. ** the memory allocation subsystem included within the SQLite.
  1555. **
  1556. ** INVARIANTS:
  1557. **
  1558. ** {F17371} The [sqlite3_memory_used()] routine returns the
  1559. ** number of bytes of memory currently outstanding
  1560. ** (malloced but not freed).
  1561. **
  1562. ** {F17373} The [sqlite3_memory_highwater()] routine returns the maximum
  1563. ** value of [sqlite3_memory_used()]
  1564. ** since the highwater mark was last reset.
  1565. **
  1566. ** {F17374} The values returned by [sqlite3_memory_used()] and
  1567. ** [sqlite3_memory_highwater()] include any overhead
  1568. ** added by SQLite in its implementation of [sqlite3_malloc()],
  1569. ** but not overhead added by the any underlying system library
  1570. ** routines that [sqlite3_malloc()] may call.
  1571. **
  1572. ** {F17375} The memory highwater mark is reset to the current value of
  1573. ** [sqlite3_memory_used()] if and only if the parameter to
  1574. ** [sqlite3_memory_highwater()] is true. The value returned
  1575. ** by [sqlite3_memory_highwater(1)] is the highwater mark
  1576. ** prior to the reset.
  1577. *)
  1578. {$IFDEF S}function{$ELSE}var{$ENDIF}sqlite3_memory_used{$IFDEF D}: function{$ENDIF}(): sqlite3_int64; cdecl;{$IFDEF S}external Sqlite3Lib;{$ENDIF}
  1579. {$IFDEF S}function{$ELSE}var{$ENDIF}sqlite3_memory_highwater{$IFDEF D}: function{$ENDIF}(resetFlag: cint): sqlite3_int64; cdecl;{$IFDEF S}external Sqlite3Lib;{$ENDIF}
  1580. (*
  1581. ** CAPI3REF: Pseudo-Random Number Generator {F17390}
  1582. **
  1583. ** SQLite contains a high-quality pseudo-random number generator (PRNG) used to
  1584. ** select random ROWIDs when inserting new records into a table that
  1585. ** already uses the largest possible ROWID. The PRNG is also used for
  1586. ** the build-in random() and randomblob() SQL functions. This interface allows
  1587. ** appliations to access the same PRNG for other purposes.
  1588. **
  1589. ** A call to this routine stores N bytes of randomness into buffer P.
  1590. **
  1591. ** The first time this routine is invoked (either internally or by
  1592. ** the application) the PRNG is seeded using randomness obtained
  1593. ** from the xRandomness method of the default [sqlite3_vfs] object.
  1594. ** On all subsequent invocations, the pseudo-randomness is generated
  1595. ** internally and without recourse to the [sqlite3_vfs] xRandomness
  1596. ** method.
  1597. **
  1598. ** INVARIANTS:
  1599. **
  1600. ** {F17392} The [sqlite3_randomness(N,P)] interface writes N bytes of
  1601. ** high-quality pseudo-randomness into buffer P.
  1602. *)
  1603. {$IFDEF S}procedure{$ELSE}var{$ENDIF}sqlite3_randomness{$IFDEF D}: procedure{$ENDIF}(N: cint; P: pointer); cdecl;{$IFDEF S}external Sqlite3Lib;{$ENDIF}
  1604. (*
  1605. ** CAPI3REF: Compile-Time Authorization Callbacks {F12500}
  1606. **
  1607. ** This routine registers a authorizer callback with a particular
  1608. ** [database connection], supplied in the first argument.
  1609. ** The authorizer callback is invoked as SQL statements are being compiled
  1610. ** by [sqlite3_prepare()] or its variants [sqlite3_prepare_v2()],
  1611. ** [sqlite3_prepare16()] and [sqlite3_prepare16_v2()]. At various
  1612. ** points during the compilation process, as logic is being created
  1613. ** to perform various actions, the authorizer callback is invoked to
  1614. ** see if those actions are allowed. The authorizer callback should
  1615. ** return [SQLITE_OK] to allow the action, [SQLITE_IGNORE] to disallow the
  1616. ** specific action but allow the SQL statement to continue to be
  1617. ** compiled, or [SQLITE_DENY] to cause the entire SQL statement to be
  1618. ** rejected with an error. If the authorizer callback returns
  1619. ** any value other than [SQLITE_IGNORE], [SQLITE_OK], or [SQLITE_DENY]
  1620. ** then [sqlite3_prepare_v2()] or equivalent call that triggered
  1621. ** the authorizer will fail with an error message.
  1622. **
  1623. ** When the callback returns [SQLITE_OK], that means the operation
  1624. ** requested is ok. When the callback returns [SQLITE_DENY], the
  1625. ** [sqlite3_prepare_v2()] or equivalent call that triggered the
  1626. ** authorizer will fail with an error message explaining that
  1627. ** access is denied. If the authorizer code is [SQLITE_READ]
  1628. ** and the callback returns [SQLITE_IGNORE] then the
  1629. ** [prepared statement] statement is constructed to substitute
  1630. ** a NULL value in place of the table column that would have
  1631. ** been read if [SQLITE_OK] had been returned. The [SQLITE_IGNORE]
  1632. ** return can be used to deny an untrusted user access to individual
  1633. ** columns of a table.
  1634. **
  1635. ** The first parameter to the authorizer callback is a copy of
  1636. ** the third parameter to the sqlite3_set_authorizer() interface.
  1637. ** The second parameter to the callback is an integer
  1638. ** [SQLITE_COPY | action code] that specifies the particular action
  1639. ** to be authorized. The third through sixth
  1640. ** parameters to the callback are zero-terminated strings that contain
  1641. ** additional details about the action to be authorized.
  1642. **
  1643. ** An authorizer is used when [sqlite3_prepare | preparing]
  1644. ** SQL statements from an untrusted
  1645. ** source, to ensure that the SQL statements do not try to access data
  1646. ** that they are not allowed to see, or that they do not try to
  1647. ** execute malicious statements that damage the database. For
  1648. ** example, an application may allow a user to enter arbitrary
  1649. ** SQL queries for evaluation by a database. But the application does
  1650. ** not want the user to be able to make arbitrary changes to the
  1651. ** database. An authorizer could then be put in place while the
  1652. ** user-entered SQL is being [sqlite3_prepare | prepared] that
  1653. ** disallows everything except [SELECT] statements.
  1654. **
  1655. ** Applications that need to process SQL from untrusted sources
  1656. ** might also consider lowering resource limits using [sqlite3_limit()]
  1657. ** and limiting database size using the [max_page_count] [PRAGMA]
  1658. ** in addition to using an authorizer.
  1659. **
  1660. ** Only a single authorizer can be in place on a database connection
  1661. ** at a time. Each call to sqlite3_set_authorizer overrides the
  1662. ** previous call. Disable the authorizer by installing a NULL callback.
  1663. ** The authorizer is disabled by default.
  1664. **
  1665. ** Note that the authorizer callback is invoked only during
  1666. ** [sqlite3_prepare()] or its variants. Authorization is not
  1667. ** performed during statement evaluation in [sqlite3_step()].
  1668. **
  1669. ** INVARIANTS:
  1670. **
  1671. ** {F12501} The [sqlite3_set_authorizer(D,...)] interface registers a
  1672. ** authorizer callback with database connection D.
  1673. **
  1674. ** {F12502} The authorizer callback is invoked as SQL statements are
  1675. ** being compiled
  1676. **
  1677. ** {F12503} If the authorizer callback returns any value other than
  1678. ** [SQLITE_IGNORE], [SQLITE_OK], or [SQLITE_DENY] then
  1679. ** the [sqlite3_prepare_v2()] or equivalent call that caused
  1680. ** the authorizer callback to run shall fail with an
  1681. ** [SQLITE_ERROR] error code and an appropriate error message.
  1682. **
  1683. ** {F12504} When the authorizer callback returns [SQLITE_OK], the operation
  1684. ** described is coded normally.
  1685. **
  1686. ** {F12505} When the authorizer callback returns [SQLITE_DENY], the
  1687. ** [sqlite3_prepare_v2()] or equivalent call that caused the
  1688. ** authorizer callback to run shall fail
  1689. ** with an [SQLITE_ERROR] error code and an error message
  1690. ** explaining that access is denied.
  1691. **
  1692. ** {F12506} If the authorizer code (the 2nd parameter to the authorizer
  1693. ** callback) is [SQLITE_READ] and the authorizer callback returns
  1694. ** [SQLITE_IGNORE] then the prepared statement is constructed to
  1695. ** insert a NULL value in place of the table column that would have
  1696. ** been read if [SQLITE_OK] had been returned.
  1697. **
  1698. ** {F12507} If the authorizer code (the 2nd parameter to the authorizer
  1699. ** callback) is anything other than [SQLITE_READ], then
  1700. ** a return of [SQLITE_IGNORE] has the same effect as [SQLITE_DENY].
  1701. **
  1702. ** {F12510} The first parameter to the authorizer callback is a copy of
  1703. ** the third parameter to the [sqlite3_set_authorizer()] interface.
  1704. **
  1705. ** {F12511} The second parameter to the callback is an integer
  1706. ** [SQLITE_COPY | action code] that specifies the particular action
  1707. ** to be authorized.
  1708. **
  1709. ** {F12512} The third through sixth parameters to the callback are
  1710. ** zero-terminated strings that contain
  1711. ** additional details about the action to be authorized.
  1712. **
  1713. ** {F12520} Each call to [sqlite3_set_authorizer()] overrides the
  1714. ** any previously installed authorizer.
  1715. **
  1716. ** {F12521} A NULL authorizer means that no authorization
  1717. ** callback is invoked.
  1718. **
  1719. ** {F12522} The default authorizer is NULL.
  1720. *)
  1721. type
  1722. xAuth = function(pUserData: pointer; code: cint; s1, s2, s3, s4: pchar): cint; cdecl;
  1723. {$IFDEF S}function{$ELSE}var{$ENDIF}sqlite3_set_authorizer{$IFDEF D}: function{$ENDIF}(
  1724. db: psqlite3;
  1725. cb: xAuth;
  1726. pUserData: pointer
  1727. ): cint; cdecl;{$IFDEF S}external Sqlite3Lib;{$ENDIF}
  1728. (*
  1729. ** CAPI3REF: Authorizer Return Codes {F12590}
  1730. **
  1731. ** The [sqlite3_set_authorizer | authorizer callback function] must
  1732. ** return either [SQLITE_OK] or one of these two constants in order
  1733. ** to signal SQLite whether or not the action is permitted. See the
  1734. ** [sqlite3_set_authorizer | authorizer documentation] for additional
  1735. ** information.
  1736. *)
  1737. const
  1738. SQLITE_DENY = 1; (* Abort the SQL statement with an error *)
  1739. SQLITE_IGNORE = 2; (* Don't allow access, but don't generate an error *)
  1740. (*
  1741. ** CAPI3REF: Authorizer Action Codes {F12550}
  1742. **
  1743. ** The [sqlite3_set_authorizer()] interface registers a callback function
  1744. ** that is invoked to authorizer certain SQL statement actions. The
  1745. ** second parameter to the callback is an integer code that specifies
  1746. ** what action is being authorized. These are the integer action codes that
  1747. ** the authorizer callback may be passed.
  1748. **
  1749. ** These action code values signify what kind of operation is to be
  1750. ** authorized. The 3rd and 4th parameters to the authorization
  1751. ** callback function will be parameters or NULL depending on which of these
  1752. ** codes is used as the second parameter. The 5th parameter to the
  1753. ** authorizer callback is the name of the database ("main", "temp",
  1754. ** etc.) if applicable. The 6th parameter to the authorizer callback
  1755. ** is the name of the inner-most trigger or view that is responsible for
  1756. ** the access attempt or NULL if this access attempt is directly from
  1757. ** top-level SQL code.
  1758. **
  1759. ** INVARIANTS:
  1760. **
  1761. ** {F12551} The second parameter to an
  1762. ** [sqlite3_set_authorizer | authorizer callback is always an integer
  1763. ** [SQLITE_COPY | authorizer code] that specifies what action
  1764. ** is being authorized.
  1765. **
  1766. ** {F12552} The 3rd and 4th parameters to the
  1767. ** [sqlite3_set_authorizer | authorization callback function]
  1768. ** will be parameters or NULL depending on which
  1769. ** [SQLITE_COPY | authorizer code] is used as the second parameter.
  1770. **
  1771. ** {F12553} The 5th parameter to the
  1772. ** [sqlite3_set_authorizer | authorizer callback] is the name
  1773. ** of the database (example: "main", "temp", etc.) if applicable.
  1774. **
  1775. ** {F12554} The 6th parameter to the
  1776. ** [sqlite3_set_authorizer | authorizer callback] is the name
  1777. ** of the inner-most trigger or view that is responsible for
  1778. ** the access attempt or NULL if this access attempt is directly from
  1779. ** top-level SQL code.
  1780. *)
  1781. (******************************************* 3rd ************ 4th ***********)
  1782. const
  1783. SQLITE_CREATE_INDEX = 1; (* Index Name Table Name *)
  1784. SQLITE_CREATE_TABLE = 2; (* Table Name NULL *)
  1785. SQLITE_CREATE_TEMP_INDEX = 3; (* Index Name Table Name *)
  1786. SQLITE_CREATE_TEMP_TABLE = 4; (* Table Name NULL *)
  1787. SQLITE_CREATE_TEMP_TRIGGER = 5; (* Trigger Name Table Name *)
  1788. SQLITE_CREATE_TEMP_VIEW = 6; (* View Name NULL *)
  1789. SQLITE_CREATE_TRIGGER = 7; (* Trigger Name Table Name *)
  1790. SQLITE_CREATE_VIEW = 8; (* View Name NULL *)
  1791. SQLITE_DELETE = 9; (* Table Name NULL *)
  1792. SQLITE_DROP_INDEX = 10; (* Index Name Table Name *)
  1793. SQLITE_DROP_TABLE = 11; (* Table Name NULL *)
  1794. SQLITE_DROP_TEMP_INDEX = 12; (* Index Name Table Name *)
  1795. SQLITE_DROP_TEMP_TABLE = 13; (* Table Name NULL *)
  1796. SQLITE_DROP_TEMP_TRIGGER = 14; (* Trigger Name Table Name *)
  1797. SQLITE_DROP_TEMP_VIEW = 15; (* View Name NULL *)
  1798. SQLITE_DROP_TRIGGER = 16; (* Trigger Name Table Name *)
  1799. SQLITE_DROP_VIEW = 17; (* View Name NULL *)
  1800. SQLITE_INSERT = 18; (* Table Name NULL *)
  1801. SQLITE_PRAGMA = 19; (* Pragma Name 1st arg or NULL *)
  1802. SQLITE_READ = 20; (* Table Name Column Name *)
  1803. SQLITE_SELECT = 21; (* NULL NULL *)
  1804. SQLITE_TRANSACTION = 22; (* NULL NULL *)
  1805. SQLITE_UPDATE = 23; (* Table Name Column Name *)
  1806. SQLITE_ATTACH = 24; (* Filename NULL *)
  1807. SQLITE_DETACH = 25; (* Database Name NULL *)
  1808. SQLITE_ALTER_TABLE = 26; (* Database Name Table Name *)
  1809. SQLITE_REINDEX = 27; (* Index Name NULL *)
  1810. SQLITE_ANALYZE = 28; (* Table Name NULL *)
  1811. SQLITE_CREATE_VTABLE = 29; (* Table Name Module Name *)
  1812. SQLITE_DROP_VTABLE = 30; (* Table Name Module Name *)
  1813. SQLITE_FUNCTION = 31; (* Function Name NULL *)
  1814. SQLITE_COPY = 0; (* No longer used *)
  1815. (*
  1816. ** CAPI3REF: Tracing And Profiling Functions {F12280}
  1817. **
  1818. ** These routines register callback functions that can be used for
  1819. ** tracing and profiling the execution of SQL statements.
  1820. **
  1821. ** The callback function registered by sqlite3_trace() is invoked at
  1822. ** various times when an SQL statement is being run by [sqlite3_step()].
  1823. ** The callback returns a UTF-8 rendering of the SQL statement text
  1824. ** as the statement first begins executing. Additional callbacks occur
  1825. ** as each triggersubprogram is entered. The callbacks for triggers
  1826. ** contain a UTF-8 SQL comment that identifies the trigger.
  1827. **
  1828. ** The callback function registered by sqlite3_profile() is invoked
  1829. ** as each SQL statement finishes. The profile callback contains
  1830. ** the original statement text and an estimate of wall-clock time
  1831. ** of how long that statement took to run.
  1832. **
  1833. ** The sqlite3_profile() API is currently considered experimental and
  1834. ** is subject to change or removal in a future release.
  1835. **
  1836. ** The trigger reporting feature of the trace callback is considered
  1837. ** experimental and is subject to change or removal in future releases.
  1838. ** Future versions of SQLite might also add new trace callback
  1839. ** invocations.
  1840. **
  1841. ** INVARIANTS:
  1842. **
  1843. ** {F12281} The callback function registered by [sqlite3_trace()] is
  1844. ** whenever an SQL statement first begins to execute and
  1845. ** whenever a trigger subprogram first begins to run.
  1846. **
  1847. ** {F12282} Each call to [sqlite3_trace()] overrides the previously
  1848. ** registered trace callback.
  1849. **
  1850. ** {F12283} A NULL trace callback disables tracing.
  1851. **
  1852. ** {F12284} The first argument to the trace callback is a copy of
  1853. ** the pointer which was the 3rd argument to [sqlite3_trace()].
  1854. **
  1855. ** {F12285} The second argument to the trace callback is a
  1856. ** zero-terminated UTF8 string containing the original text
  1857. ** of the SQL statement as it was passed into [sqlite3_prepare_v2()]
  1858. ** or the equivalent, or an SQL comment indicating the beginning
  1859. ** of a trigger subprogram.
  1860. **
  1861. ** {F12287} The callback function registered by [sqlite3_profile()] is invoked
  1862. ** as each SQL statement finishes.
  1863. **
  1864. ** {F12288} The first parameter to the profile callback is a copy of
  1865. ** the 3rd parameter to [sqlite3_profile()].
  1866. **
  1867. ** {F12289} The second parameter to the profile callback is a
  1868. ** zero-terminated UTF-8 string that contains the complete text of
  1869. ** the SQL statement as it was processed by [sqlite3_prepare_v2()]
  1870. ** or the equivalent.
  1871. **
  1872. ** {F12290} The third parameter to the profile callback is an estimate
  1873. ** of the number of nanoseconds of wall-clock time required to
  1874. ** run the SQL statement from start to finish.
  1875. *)
  1876. type
  1877. xTrace = procedure(user: pointer; s: pchar); cdecl;
  1878. xProfile = procedure(user: pointer; s: char; i: sqlite3_uint64); cdecl;
  1879. {$IFDEF S}function{$ELSE}var{$ENDIF}sqlite3_trace{$IFDEF D}: function{$ENDIF}(db: psqlite3; cb: xTrace; user: pointer): pointer; cdecl;{$IFDEF S}external Sqlite3Lib;{$ENDIF}
  1880. {$IFDEF S}function{$ELSE}var{$ENDIF}sqlite3_profile{$IFDEF D}: function{$ENDIF}(db: psqlite3; cb: xProfile; user: pointer): pointer; cdecl;{$IFDEF S}external Sqlite3Lib;{$ENDIF}
  1881. (*
  1882. ** CAPI3REF: Query Progress Callbacks {F12910}
  1883. **
  1884. ** This routine configures a callback function - the
  1885. ** progress callback - that is invoked periodically during long
  1886. ** running calls to [sqlite3_exec()], [sqlite3_step()] and
  1887. ** [sqlite3_get_table()]. An example use for this
  1888. ** interface is to keep a GUI updated during a large query.
  1889. **
  1890. ** If the progress callback returns non-zero, the opertion is
  1891. ** interrupted. This feature can be used to implement a
  1892. ** "Cancel" button on a GUI dialog box.
  1893. **
  1894. ** INVARIANTS:
  1895. **
  1896. ** {F12911} The callback function registered by [sqlite3_progress_handler()]
  1897. ** is invoked periodically during long running calls to
  1898. ** [sqlite3_step()].
  1899. **
  1900. ** {F12912} The progress callback is invoked once for every N virtual
  1901. ** machine opcodes, where N is the second argument to
  1902. ** the [sqlite3_progress_handler()] call that registered
  1903. ** the callback. <todo>What if N is less than 1?</todo>
  1904. **
  1905. ** {F12913} The progress callback itself is identified by the third
  1906. ** argument to [sqlite3_progress_handler()].
  1907. **
  1908. ** {F12914} The fourth argument [sqlite3_progress_handler()] is a
  1909. *** void pointer passed to the progress callback
  1910. ** function each time it is invoked.
  1911. **
  1912. ** {F12915} If a call to [sqlite3_step()] results in fewer than
  1913. ** N opcodes being executed,
  1914. ** then the progress callback is never invoked. {END}
  1915. **
  1916. ** {F12916} Every call to [sqlite3_progress_handler()]
  1917. ** overwrites any previously registere progress handler.
  1918. **
  1919. ** {F12917} If the progress handler callback is NULL then no progress
  1920. ** handler is invoked.
  1921. **
  1922. ** {F12918} If the progress callback returns a result other than 0, then
  1923. ** the behavior is a if [sqlite3_interrupt()] had been called.
  1924. *)
  1925. type
  1926. progress_callback = function(user: pointer): cint; cdecl;
  1927. {$IFDEF S}procedure{$ELSE}var{$ENDIF}sqlite3_progress_handler{$IFDEF D}: procedure{$ENDIF}(db: psqlite3; i: cint; cb: progress_callback; user: pointer); cdecl;{$IFDEF S}external Sqlite3Lib;{$ENDIF}
  1928. (*
  1929. ** CAPI3REF: Opening A New Database Connection {F12700}
  1930. **
  1931. ** These routines open an SQLite database file whose name
  1932. ** is given by the filename argument.
  1933. ** The filename argument is interpreted as UTF-8
  1934. ** for [sqlite3_open()] and [sqlite3_open_v2()] and as UTF-16
  1935. ** in the native byte order for [sqlite3_open16()].
  1936. ** An [db: psqlite3] handle is usually returned in *ppDb, even
  1937. ** if an error occurs. The only exception is if SQLite is unable
  1938. ** to allocate memory to hold the [sqlite3] object, a NULL will
  1939. ** be written into *ppDb instead of a pointer to the [sqlite3] object.
  1940. ** If the database is opened (and/or created)
  1941. ** successfully, then [SQLITE_OK] is returned. Otherwise an
  1942. ** error code is returned. The
  1943. ** [sqlite3_errmsg()] or [sqlite3_errmsg16()] routines can be used to obtain
  1944. ** an English language description of the error.
  1945. **
  1946. ** The default encoding for the database will be UTF-8 if
  1947. ** [sqlite3_open()] or [sqlite3_open_v2()] is called and
  1948. ** UTF-16 in the native byte order if [sqlite3_open16()] is used.
  1949. **
  1950. ** Whether or not an error occurs when it is opened, resources
  1951. ** associated with the [db: psqlite3] handle should be released by passing it
  1952. ** to [sqlite3_close()] when it is no longer required.
  1953. **
  1954. ** The [sqlite3_open_v2()] interface works like [sqlite3_open()]
  1955. ** except that it acccepts two additional parameters for additional control
  1956. ** over the new database connection. The flags parameter can be
  1957. ** one of:
  1958. **
  1959. ** <ol>
  1960. ** <li> [SQLITE_OPEN_READONLY]
  1961. ** <li> [SQLITE_OPEN_READWRITE]
  1962. ** <li> [SQLITE_OPEN_READWRITE] | [SQLITE_OPEN_CREATE]
  1963. ** </ol>
  1964. **
  1965. ** The first value opens the database read-only.
  1966. ** If the database does not previously exist, an error is returned.
  1967. ** The second option opens
  1968. ** the database for reading and writing if possible, or reading only if
  1969. ** if the file is write protected. In either case the database
  1970. ** must already exist or an error is returned. The third option
  1971. ** opens the database for reading and writing and creates it if it does
  1972. ** not already exist.
  1973. ** The third options is behavior that is always used for [sqlite3_open()]
  1974. ** and [sqlite3_open16()].
  1975. **
  1976. ** If the 3rd parameter to [sqlite3_open_v2()] is not one of the
  1977. ** combinations shown above then the behavior is undefined.
  1978. **
  1979. ** If the filename is ":memory:", then an private
  1980. ** in-memory database is created for the connection. This in-memory
  1981. ** database will vanish when the database connection is closed. Future
  1982. ** version of SQLite might make use of additional special filenames
  1983. ** that begin with the ":" character. It is recommended that
  1984. ** when a database filename really does begin with
  1985. ** ":" that you prefix the filename with a pathname like "./" to
  1986. ** avoid ambiguity.
  1987. **
  1988. ** If the filename is an empty string, then a private temporary
  1989. ** on-disk database will be created. This private database will be
  1990. ** automatically deleted as soon as the database connection is closed.
  1991. **
  1992. ** The fourth parameter to sqlite3_open_v2() is the name of the
  1993. ** [sqlite3_vfs] object that defines the operating system
  1994. ** interface that the new database connection should use. If the
  1995. ** fourth parameter is a NULL pointer then the default [sqlite3_vfs]
  1996. ** object is used.
  1997. **
  1998. ** <b>Note to windows users:</b> The encoding used for the filename argument
  1999. ** of [sqlite3_open()] and [sqlite3_open_v2()] must be UTF-8, not whatever
  2000. ** codepage is currently defined. Filenames containing international
  2001. ** characters must be converted to UTF-8 prior to passing them into
  2002. ** [sqlite3_open()] or [sqlite3_open_v2()].
  2003. **
  2004. ** INVARIANTS:
  2005. **
  2006. ** {F12701} The [sqlite3_open()], [sqlite3_open16()], and
  2007. ** [sqlite3_open_v2()] interfaces create a new
  2008. ** [database connection] associated with
  2009. ** the database file given in their first parameter.
  2010. **
  2011. ** {F12702} The filename argument is interpreted as UTF-8
  2012. ** for [sqlite3_open()] and [sqlite3_open_v2()] and as UTF-16
  2013. ** in the native byte order for [sqlite3_open16()].
  2014. **
  2015. ** {F12703} A successful invocation of [sqlite3_open()], [sqlite3_open16()],
  2016. ** or [sqlite3_open_v2()] writes a pointer to a new
  2017. ** [database connection] into *ppDb.
  2018. **
  2019. ** {F12704} The [sqlite3_open()], [sqlite3_open16()], and
  2020. ** [sqlite3_open_v2()] interfaces return [SQLITE_OK] upon success,
  2021. ** or an appropriate [error code] on failure.
  2022. **
  2023. ** {F12706} The default text encoding for a new database created using
  2024. ** [sqlite3_open()] or [sqlite3_open_v2()] will be UTF-8.
  2025. **
  2026. ** {F12707} The default text encoding for a new database created using
  2027. ** [sqlite3_open16()] will be UTF-16.
  2028. **
  2029. ** {F12709} The [sqlite3_open(F,D)] interface is equivalent to
  2030. ** [sqlite3_open_v2(F,D,G,0)] where the G parameter is
  2031. ** [SQLITE_OPEN_READWRITE]|[SQLITE_OPEN_CREATE].
  2032. **
  2033. ** {F12711} If the G parameter to [sqlite3_open_v2(F,D,G,V)] contains the
  2034. ** bit value [SQLITE_OPEN_READONLY] then the database is opened
  2035. ** for reading only.
  2036. **
  2037. ** {F12712} If the G parameter to [sqlite3_open_v2(F,D,G,V)] contains the
  2038. ** bit value [SQLITE_OPEN_READWRITE] then the database is opened
  2039. ** reading and writing if possible, or for reading only if the
  2040. ** file is write protected by the operating system.
  2041. **
  2042. ** {F12713} If the G parameter to [sqlite3_open(v2(F,D,G,V)] omits the
  2043. ** bit value [SQLITE_OPEN_CREATE] and the database does not
  2044. ** previously exist, an error is returned.
  2045. **
  2046. ** {F12714} If the G parameter to [sqlite3_open(v2(F,D,G,V)] contains the
  2047. ** bit value [SQLITE_OPEN_CREATE] and the database does not
  2048. ** previously exist, then an attempt is made to create and
  2049. ** initialize the database.
  2050. **
  2051. ** {F12717} If the filename argument to [sqlite3_open()], [sqlite3_open16()],
  2052. ** or [sqlite3_open_v2()] is ":memory:", then an private,
  2053. ** ephemeral, in-memory database is created for the connection.
  2054. ** <todo>Is SQLITE_OPEN_CREATE|SQLITE_OPEN_READWRITE required
  2055. ** in sqlite3_open_v2()?</todo>
  2056. **
  2057. ** {F12719} If the filename is NULL or an empty string, then a private,
  2058. ** ephermeral on-disk database will be created.
  2059. ** <todo>Is SQLITE_OPEN_CREATE|SQLITE_OPEN_READWRITE required
  2060. ** in sqlite3_open_v2()?</todo>
  2061. **
  2062. ** {F12721} The [database connection] created by
  2063. ** [sqlite3_open_v2(F,D,G,V)] will use the
  2064. ** [sqlite3_vfs] object identified by the V parameter, or
  2065. ** the default [sqlite3_vfs] object is V is a NULL pointer.
  2066. *)
  2067. {$IFDEF S}function{$ELSE}var{$ENDIF}sqlite3_open{$IFDEF D}: function{$ENDIF}(
  2068. filename: pchar; (* Database filename (UTF-8) *)
  2069. ppDb: ppsqlite3 (* OUT: SQLite db handle *)
  2070. ): cint; cdecl;{$IFDEF S}external Sqlite3Lib;{$ENDIF}
  2071. {$IFDEF S}function{$ELSE}var{$ENDIF}sqlite3_open16{$IFDEF D}: function{$ENDIF}(
  2072. filename: pwidechar; (* Database filename (UTF-16) *)
  2073. ppDb: ppsqlite3 (* OUT: SQLite db handle *)
  2074. ): cint; cdecl;{$IFDEF S}external Sqlite3Lib;{$ENDIF}
  2075. {$IFDEF S}function{$ELSE}var{$ENDIF}sqlite3_open_v2{$IFDEF D}: function{$ENDIF}(
  2076. filename: pchar; (* Database filename (UTF-8) *)
  2077. ppDb: ppsqlite3; (* OUT: SQLite db handle *)
  2078. flags: cint; (* Flags *)
  2079. zVfs: pchar (* Name of VFS module to use *)
  2080. ): cint; cdecl;{$IFDEF S}external Sqlite3Lib;{$ENDIF}
  2081. (*
  2082. ** CAPI3REF: Error Codes And Messages {F12800}
  2083. **
  2084. ** The sqlite3_errcode() interface returns the numeric
  2085. ** [SQLITE_OK | result code] or [SQLITE_IOERR_READ | extended result code]
  2086. ** for the most recent failed sqlite3_* API call associated
  2087. ** with [sqlite3] handle 'db'. If a prior API call failed but the
  2088. ** most recent API call succeeded, the return value from sqlite3_errcode()
  2089. ** is undefined.
  2090. **
  2091. ** The sqlite3_errmsg() and sqlite3_errmsg16() return English-language
  2092. ** text that describes the error, as either UTF8 or UTF16 respectively.
  2093. ** Memory to hold the error message string is managed internally.
  2094. ** The application does not need to worry with freeing the result.
  2095. ** However, the error string might be overwritten or deallocated by
  2096. ** subsequent calls to other SQLite interface functions.
  2097. **
  2098. ** INVARIANTS:
  2099. **
  2100. ** {F12801} The [sqlite3_errcode(D)] interface returns the numeric
  2101. ** [SQLITE_OK | result code] or
  2102. ** [SQLITE_IOERR_READ | extended result code]
  2103. ** for the most recently failed interface call associated
  2104. ** with [database connection] D.
  2105. **
  2106. ** {F12803} The [sqlite3_errmsg(D)] and [sqlite3_errmsg16(D)]
  2107. ** interfaces return English-language text that describes
  2108. ** the error in the mostly recently failed interface call,
  2109. ** encoded as either UTF8 or UTF16 respectively.
  2110. **
  2111. ** {F12807} The strings returned by [sqlite3_errmsg()] and [sqlite3_errmsg16()]
  2112. ** are valid until the next SQLite interface call.
  2113. **
  2114. ** {F12808} Calls to API routines that do not return an error code
  2115. ** (example: [sqlite3_data_count()]) do not
  2116. ** change the error code or message returned by
  2117. ** [sqlite3_errcode()], [sqlite3_errmsg()], or [sqlite3_errmsg16()].
  2118. **
  2119. ** {F12809} Interfaces that are not associated with a specific
  2120. ** [database connection] (examples:
  2121. ** [sqlite3_mprintf()] or [sqlite3_enable_shared_cache()]
  2122. ** do not change the values returned by
  2123. ** [sqlite3_errcode()], [sqlite3_errmsg()], or [sqlite3_errmsg16()].
  2124. *)
  2125. {$IFDEF S}function{$ELSE}var{$ENDIF}sqlite3_errcode{$IFDEF D}: function{$ENDIF}(db: psqlite3): cint; cdecl;{$IFDEF S}external Sqlite3Lib;{$ENDIF}
  2126. {$IFDEF S}function{$ELSE}var{$ENDIF}sqlite3_errmsg{$IFDEF D}: function{$ENDIF}(db: psqlite3): pchar; cdecl;{$IFDEF S}external Sqlite3Lib;{$ENDIF}
  2127. {$IFDEF S}function{$ELSE}var{$ENDIF}sqlite3_errmsg16{$IFDEF D}: function{$ENDIF}(db: psqlite3): pwidechar; cdecl;{$IFDEF S}external Sqlite3Lib;{$ENDIF}
  2128. (*
  2129. ** CAPI3REF: SQL Statement Object {F13000}
  2130. ** KEYWORDS: {prepared statement} {prepared statements}
  2131. **
  2132. ** An instance of this object represent single SQL statements. This
  2133. ** object is variously known as a "prepared statement" or a
  2134. ** "compiled SQL statement" or simply as a "statement".
  2135. **
  2136. ** The life of a statement object goes something like this:
  2137. **
  2138. ** <ol>
  2139. ** <li> Create the object using [sqlite3_prepare_v2()] or a related
  2140. ** function.
  2141. ** <li> Bind values to host parameters using
  2142. ** [sqlite3_bind_blob | sqlite3_bind_* interfaces].
  2143. ** <li> Run the SQL by calling [sqlite3_step()] one or more times.
  2144. ** <li> Reset the statement using [sqlite3_reset()] then go back
  2145. ** to step 2. Do this zero or more times.
  2146. ** <li> Destroy the object using [sqlite3_finalize()].
  2147. ** </ol>
  2148. **
  2149. ** Refer to documentation on individual methods above for additional
  2150. ** information.
  2151. *)
  2152. type
  2153. ppsqlite3_stmt = ^psqlite3_stmt;
  2154. psqlite3_stmt = ^sqlite3_stmt;
  2155. sqlite3_stmt = record end;
  2156. (*
  2157. ** CAPI3REF: Run-time Limits {F12760}
  2158. **
  2159. ** This interface allows the size of various constructs to be limited
  2160. ** on a connection by connection basis. The first parameter is the
  2161. ** [database connection] whose limit is to be set or queried. The
  2162. ** second parameter is one of the [limit categories] that define a
  2163. ** class of constructs to be size limited. The third parameter is the
  2164. ** new limit for that construct. The function returns the old limit.
  2165. **
  2166. ** If the new limit is a negative number, the limit is unchanged.
  2167. ** For the limit category of SQLITE_LIMIT_XYZ there is a hard upper
  2168. ** bound set by a compile-time C-preprocess macro named SQLITE_MAX_XYZ.
  2169. ** (The "_LIMIT_" in the name is changed to "_MAX_".)
  2170. ** Attempts to increase a limit above its hard upper bound are
  2171. ** silently truncated to the hard upper limit.
  2172. **
  2173. ** Run time limits are intended for use in applications that manage
  2174. ** both their own internal database and also databases that are controlled
  2175. ** by untrusted external sources. An example application might be a
  2176. ** webbrowser that has its own databases for storing history and
  2177. ** separate databases controlled by javascript applications downloaded
  2178. ** off the internet. The internal databases can be given the
  2179. ** large, default limits. Databases managed by external sources can
  2180. ** be given much smaller limits designed to prevent a denial of service
  2181. ** attach. Developers might also want to use the [sqlite3_set_authorizer()]
  2182. ** interface to further control untrusted SQL. The size of the database
  2183. ** created by an untrusted script can be contained using the
  2184. ** [max_page_count] [PRAGMA].
  2185. **
  2186. ** This interface is currently considered experimental and is subject
  2187. ** to change or removal without prior notice.
  2188. **
  2189. ** INVARIANTS:
  2190. **
  2191. ** {F12762} A successful call to [sqlite3_limit(D,C,V)] where V is
  2192. ** positive changes the
  2193. ** limit on the size of construct C in [database connection] D
  2194. ** to the lessor of V and the hard upper bound on the size
  2195. ** of C that is set at compile-time.
  2196. **
  2197. ** {F12766} A successful call to [sqlite3_limit(D,C,V)] where V is negative
  2198. ** leaves the state of [database connection] D unchanged.
  2199. **
  2200. ** {F12769} A successful call to [sqlite3_limit(D,C,V)] returns the
  2201. ** value of the limit on the size of construct C in
  2202. ** in [database connection] D as it was prior to the call.
  2203. *)
  2204. {$IFDEF S}function{$ELSE}var{$ENDIF}sqlite3_limit{$IFDEF D}: function{$ENDIF}(db: psqlite3; id: cint; newVal: cint): cint; cdecl;{$IFDEF S}external Sqlite3Lib;{$ENDIF}
  2205. (*
  2206. ** CAPI3REF: Run-Time Limit Categories {F12790}
  2207. ** KEYWORDS: {limit category} {limit categories}
  2208. **
  2209. ** These constants define various aspects of a [database connection]
  2210. ** that can be limited in size by calls to [sqlite3_limit()].
  2211. ** The meanings of the various limits are as follows:
  2212. **
  2213. ** <dl>
  2214. ** <dt>SQLITE_LIMIT_LENGTH</dt>
  2215. ** <dd>The maximum size of any
  2216. ** string or blob or table row.<dd>
  2217. **
  2218. ** <dt>SQLITE_LIMIT_SQL_LENGTH</dt>
  2219. ** <dd>The maximum length of an SQL statement.</dd>
  2220. **
  2221. ** <dt>SQLITE_LIMIT_COLUMN</dt>
  2222. ** <dd>The maximum number of columns in a table definition or in the
  2223. ** result set of a SELECT or the maximum number of columns in an index
  2224. ** or in an ORDER BY or GROUP BY clause.</dd>
  2225. **
  2226. ** <dt>SQLITE_LIMIT_EXPR_DEPTH</dt>
  2227. ** <dd>The maximum depth of the parse tree on any expression.</dd>
  2228. **
  2229. ** <dt>SQLITE_LIMIT_COMPOUND_SELECT</dt>
  2230. ** <dd>The maximum number of terms in a compound SELECT statement.</dd>
  2231. **
  2232. ** <dt>SQLITE_LIMIT_VDBE_OP</dt>
  2233. ** <dd>The maximum number of instructions in a virtual machine program
  2234. ** used to implement an SQL statement.</dd>
  2235. **
  2236. ** <dt>SQLITE_LIMIT_FUNCTION_ARG</dt>
  2237. ** <dd>The maximum number of arguments on a function.</dd>
  2238. **
  2239. ** <dt>SQLITE_LIMIT_ATTACHED</dt>
  2240. ** <dd>The maximum number of attached databases.</dd>
  2241. **
  2242. ** <dt>SQLITE_LIMIT_LIKE_PATTERN_LENGTH</dt>
  2243. ** <dd>The maximum length of the pattern argument to the LIKE or
  2244. ** GLOB operators.</dd>
  2245. **
  2246. ** <dt>SQLITE_LIMIT_VARIABLE_NUMBER</dt>
  2247. ** <dd>The maximum number of variables in an SQL statement that can
  2248. ** be bound.</dd>
  2249. ** </dl>
  2250. *)
  2251. const
  2252. SQLITE_LIMIT_LENGTH = 0;
  2253. SQLITE_LIMIT_SQL_LENGTH = 1;
  2254. SQLITE_LIMIT_COLUMN = 2;
  2255. SQLITE_LIMIT_EXPR_DEPTH = 3;
  2256. SQLITE_LIMIT_COMPOUND_SELECT = 4;
  2257. SQLITE_LIMIT_VDBE_OP = 5;
  2258. SQLITE_LIMIT_FUNCTION_ARG = 6;
  2259. SQLITE_LIMIT_ATTACHED = 7;
  2260. SQLITE_LIMIT_LIKE_PATTERN_LENGTH = 8;
  2261. SQLITE_LIMIT_VARIABLE_NUMBER = 9;
  2262. (*
  2263. ** CAPI3REF: Compiling An SQL Statement {F13010}
  2264. **
  2265. ** To execute an SQL query, it must first be compiled into a byte-code
  2266. ** program using one of these routines.
  2267. **
  2268. ** The first argument "db" is an [database connection]
  2269. ** obtained from a prior call to [sqlite3_open()], [sqlite3_open_v2()]
  2270. ** or [sqlite3_open16()].
  2271. ** The second argument "zSql" is the statement to be compiled, encoded
  2272. ** as either UTF-8 or UTF-16. The sqlite3_prepare() and sqlite3_prepare_v2()
  2273. ** interfaces uses UTF-8 and sqlite3_prepare16() and sqlite3_prepare16_v2()
  2274. ** use UTF-16. {END}
  2275. **
  2276. ** If the nByte argument is less
  2277. ** than zero, then zSql is read up to the first zero terminator.
  2278. ** If nByte is non-negative, then it is the maximum number of
  2279. ** bytes read from zSql. When nByte is non-negative, the
  2280. ** zSql string ends at either the first '\000' or '\u0000' character or
  2281. ** the nByte-th byte, whichever comes first. If the caller knows
  2282. ** that the supplied string is nul-terminated, then there is a small
  2283. ** performance advantage to be had by passing an nByte parameter that
  2284. ** is equal to the number of bytes in the input string <i>including</i>
  2285. ** the nul-terminator bytes.{END}
  2286. **
  2287. ** *pzTail is made to point to the first byte past the end of the
  2288. ** first SQL statement in zSql. These routines only compiles the first
  2289. ** statement in zSql, so *pzTail is left pointing to what remains
  2290. ** uncompiled.
  2291. **
  2292. ** *ppStmt is left pointing to a compiled [prepared statement] that can be
  2293. ** executed using [sqlite3_step()]. Or if there is an error, *ppStmt is
  2294. ** set to NULL. If the input text contains no SQL (if the input
  2295. ** is and empty string or a comment) then *ppStmt is set to NULL.
  2296. ** {U13018} The calling procedure is responsible for deleting the
  2297. ** compiled SQL statement
  2298. ** using [sqlite3_finalize()] after it has finished with it.
  2299. **
  2300. ** On success, [SQLITE_OK] is returned. Otherwise an
  2301. ** [error code] is returned.
  2302. **
  2303. ** The sqlite3_prepare_v2() and sqlite3_prepare16_v2() interfaces are
  2304. ** recommended for all new programs. The two older interfaces are retained
  2305. ** for backwards compatibility, but their use is discouraged.
  2306. ** In the "v2" interfaces, the prepared statement
  2307. ** that is returned (the [sqlite3_stmt] object) contains a copy of the
  2308. ** original SQL text. {END} This causes the [sqlite3_step()] interface to
  2309. ** behave a differently in two ways:
  2310. **
  2311. ** <ol>
  2312. ** <li>
  2313. ** If the database schema changes, instead of returning [SQLITE_SCHEMA] as it
  2314. ** always used to do, [sqlite3_step()] will automatically recompile the SQL
  2315. ** statement and try to run it again. If the schema has changed in
  2316. ** a way that makes the statement no longer valid, [sqlite3_step()] will still
  2317. ** return [SQLITE_SCHEMA]. But unlike the legacy behavior,
  2318. ** [SQLITE_SCHEMA] is now a fatal error. Calling
  2319. ** [sqlite3_prepare_v2()] again will not make the
  2320. ** error go away. Note: use [sqlite3_errmsg()] to find the text
  2321. ** of the parsing error that results in an [SQLITE_SCHEMA] return. {END}
  2322. ** </li>
  2323. **
  2324. ** <li>
  2325. ** When an error occurs,
  2326. ** [sqlite3_step()] will return one of the detailed
  2327. ** [error codes] or [extended error codes].
  2328. ** The legacy behavior was that [sqlite3_step()] would only return a generic
  2329. ** [SQLITE_ERROR] result code and you would have to make a second call to
  2330. ** [sqlite3_reset()] in order to find the underlying cause of the problem.
  2331. ** With the "v2" prepare interfaces, the underlying reason for the error is
  2332. ** returned immediately.
  2333. ** </li>
  2334. ** </ol>
  2335. **
  2336. ** INVARIANTS:
  2337. **
  2338. ** {F13011} The [sqlite3_prepare(db,zSql,...)] and
  2339. ** [sqlite3_prepare_v2(db,zSql,...)] interfaces interpret the
  2340. ** text in their zSql parameter as UTF-8.
  2341. **
  2342. ** {F13012} The [sqlite3_prepare16(db,zSql,...)] and
  2343. ** [sqlite3_prepare16_v2(db,zSql,...)] interfaces interpret the
  2344. ** text in their zSql parameter as UTF-16 in the native byte order.
  2345. **
  2346. ** {F13013} If the nByte argument to [sqlite3_prepare_v2(db,zSql,nByte,...)]
  2347. ** and its variants is less than zero, then SQL text is
  2348. ** read from zSql is read up to the first zero terminator.
  2349. **
  2350. ** {F13014} If the nByte argument to [sqlite3_prepare_v2(db,zSql,nByte,...)]
  2351. ** and its variants is non-negative, then at most nBytes bytes
  2352. ** SQL text is read from zSql.
  2353. **
  2354. ** {F13015} In [sqlite3_prepare_v2(db,zSql,N,P,pzTail)] and its variants
  2355. ** if the zSql input text contains more than one SQL statement
  2356. ** and pzTail is not NULL, then *pzTail is made to point to the
  2357. ** first byte past the end of the first SQL statement in zSql.
  2358. ** <todo>What does *pzTail point to if there is one statement?</todo>
  2359. **
  2360. ** {F13016} A successful call to [sqlite3_prepare_v2(db,zSql,N,ppStmt,...)]
  2361. ** or one of its variants writes into *ppStmt a pointer to a new
  2362. ** [prepared statement] or a pointer to NULL
  2363. ** if zSql contains nothing other than whitespace or comments.
  2364. **
  2365. ** {F13019} The [sqlite3_prepare_v2()] interface and its variants return
  2366. ** [SQLITE_OK] or an appropriate [error code] upon failure.
  2367. **
  2368. ** {F13021} Before [sqlite3_prepare(db,zSql,nByte,ppStmt,pzTail)] or its
  2369. ** variants returns an error (any value other than [SQLITE_OK])
  2370. ** it first sets *ppStmt to NULL.
  2371. *)
  2372. {$IFDEF S}function{$ELSE}var{$ENDIF}sqlite3_prepare{$IFDEF D}: function{$ENDIF}(
  2373. db: psqlite3; (* Database handle *)
  2374. zSql: pchar; (* SQL statement, UTF-8 encoded *)
  2375. nByte: cint; (* Maximum length of zSql in bytes. *)
  2376. ppStmt: ppsqlite3_stmt; (* OUT: Statement handle *)
  2377. pzTail: ppchar (* OUT: Pointer to unused portion of zSql *)
  2378. ): cint; cdecl;{$IFDEF S}external Sqlite3Lib;{$ENDIF}
  2379. {$IFDEF S}function{$ELSE}var{$ENDIF}sqlite3_prepare_v2{$IFDEF D}: function{$ENDIF}(
  2380. db: psqlite3; (* Database handle *)
  2381. zSql: pchar; (* SQL statement, UTF-8 encoded *)
  2382. nByte: cint; (* Maximum length of zSql in bytes. *)
  2383. ppStmt: ppsqlite3_stmt; (* OUT: Statement handle *)
  2384. pzTail: ppchar (* OUT: Pointer to unused portion of zSql *)
  2385. ): cint; cdecl;{$IFDEF S}external Sqlite3Lib;{$ENDIF}
  2386. {$IFDEF S}function{$ELSE}var{$ENDIF}sqlite3_prepare16{$IFDEF D}: function{$ENDIF}(
  2387. db: psqlite3; (* Database handle *)
  2388. zSql: pwidechar; (* SQL statement, UTF-16 encoded *)
  2389. nByte: cint; (* Maximum length of zSql in bytes. *)
  2390. ppStmt: ppsqlite3_stmt; (* OUT: Statement handle *)
  2391. pzTail: ppwidechar (* OUT: Pointer to unused portion of zSql *)
  2392. ): cint; cdecl;{$IFDEF S}external Sqlite3Lib;{$ENDIF}
  2393. {$IFDEF S}function{$ELSE}var{$ENDIF}sqlite3_prepare16_v2{$IFDEF D}: function{$ENDIF}(
  2394. db: psqlite3; (* Database handle *)
  2395. zSql: pwidechar; (* SQL statement, UTF-16 encoded *)
  2396. nByte: cint; (* Maximum length of zSql in bytes. *)
  2397. ppStmt: ppsqlite3_stmt; (* OUT: Statement handle *)
  2398. pzTail: ppwidechar (* OUT: Pointer to unused portion of zSql *)
  2399. ): cint; cdecl;{$IFDEF S}external Sqlite3Lib;{$ENDIF}
  2400. (*
  2401. ** CAPIREF: Retrieving Statement SQL {F13100}
  2402. **
  2403. ** This intereface can be used to retrieve a saved copy of the original
  2404. ** SQL text used to create a [prepared statement].
  2405. **
  2406. ** INVARIANTS:
  2407. **
  2408. ** {F13101} If the [prepared statement] passed as
  2409. ** the an argument to [sqlite3_sql()] was compiled
  2410. ** compiled using either [sqlite3_prepare_v2()] or
  2411. ** [sqlite3_prepare16_v2()],
  2412. ** then [sqlite3_sql()] function returns a pointer to a
  2413. ** zero-terminated string containing a UTF-8 rendering
  2414. ** of the original SQL statement.
  2415. **
  2416. ** {F13102} If the [prepared statement] passed as
  2417. ** the an argument to [sqlite3_sql()] was compiled
  2418. ** compiled using either [sqlite3_prepare()] or
  2419. ** [sqlite3_prepare16()],
  2420. ** then [sqlite3_sql()] function returns a NULL pointer.
  2421. **
  2422. ** {F13103} The string returned by [sqlite3_sql(S)] is valid until the
  2423. ** [prepared statement] S is deleted using [sqlite3_finalize(S)].
  2424. *)
  2425. {$IFDEF S}function{$ELSE}var{$ENDIF}sqlite3_sql{$IFDEF D}: function{$ENDIF}(pStmt: psqlite3_stmt): pchar; cdecl;{$IFDEF S}external Sqlite3Lib;{$ENDIF}
  2426. (*
  2427. ** CAPI3REF: Dynamically Typed Value Object {F15000}
  2428. ** KEYWORDS: {protected sqlite3_value} {unprotected sqlite3_value}
  2429. **
  2430. ** SQLite uses the sqlite3_value object to represent all values
  2431. ** that can be stored in a database table.
  2432. ** SQLite uses dynamic typing for the values it stores.
  2433. ** Values stored in sqlite3_value objects can be
  2434. ** be integers, floating point values, strings, BLOBs, or NULL.
  2435. **
  2436. ** An sqlite3_value object may be either "protected" or "unprotected".
  2437. ** Some interfaces require a protected sqlite3_value. Other interfaces
  2438. ** will accept either a protected or an unprotected sqlite3_value.
  2439. ** Every interface that accepts sqlite3_value arguments specifies
  2440. ** whether or not it requires a protected sqlite3_value.
  2441. **
  2442. ** The terms "protected" and "unprotected" refer to whether or not
  2443. ** a mutex is held. A internal mutex is held for a protected
  2444. ** sqlite3_value object but no mutex is held for an unprotected
  2445. ** sqlite3_value object. If SQLite is compiled to be single-threaded
  2446. ** (with SQLITE_THREADSAFE=0 and with [sqlite3_threadsafe()] returning 0)
  2447. ** then there is no distinction between
  2448. ** protected and unprotected sqlite3_value objects and they can be
  2449. ** used interchangable. However, for maximum code portability it
  2450. ** is recommended that applications make the distinction between
  2451. ** between protected and unprotected sqlite3_value objects even if
  2452. ** they are single threaded.
  2453. **
  2454. ** The sqlite3_value objects that are passed as parameters into the
  2455. ** implementation of application-defined SQL functions are protected.
  2456. ** The sqlite3_value object returned by
  2457. ** [sqlite3_column_value()] is unprotected.
  2458. ** Unprotected sqlite3_value objects may only be used with
  2459. ** [sqlite3_result_value()] and [sqlite3_bind_value()]. All other
  2460. ** interfaces that use sqlite3_value require protected sqlite3_value objects.
  2461. *)
  2462. type
  2463. ppsqlite3_value = ^psqlite3_value;
  2464. psqlite3_value = ^sqlite3_value;
  2465. sqlite3_value = record end;
  2466. (*
  2467. ** CAPI3REF: SQL Function Context Object {F16001}
  2468. **
  2469. ** The context in which an SQL function executes is stored in an
  2470. ** sqlite3_context object. A pointer to an sqlite3_context
  2471. ** object is always first parameter to application-defined SQL functions.
  2472. *)
  2473. psqlite3_context = ^sqlite3_context;
  2474. sqlite3_context = record end;
  2475. (*
  2476. ** CAPI3REF: Binding Values To Prepared Statements {F13500}
  2477. **
  2478. ** In the SQL strings input to [sqlite3_prepare_v2()] and its
  2479. ** variants, literals may be replace by a parameter in one
  2480. ** of these forms:
  2481. **
  2482. ** <ul>
  2483. ** <li> ?
  2484. ** <li> ?NNN
  2485. ** <li> :VVV
  2486. ** <li> @VVV
  2487. ** <li> $VVV
  2488. ** </ul>
  2489. **
  2490. ** In the parameter forms shown above NNN is an integer literal,
  2491. ** VVV alpha-numeric parameter name.
  2492. ** The values of these parameters (also called "host parameter names"
  2493. ** or "SQL parameters")
  2494. ** can be set using the sqlite3_bind_*() routines defined here.
  2495. **
  2496. ** The first argument to the sqlite3_bind_*() routines always
  2497. ** is a pointer to the [sqlite3_stmt] object returned from
  2498. ** [sqlite3_prepare_v2()] or its variants. The second
  2499. ** argument is the index of the parameter to be set. The
  2500. ** first parameter has an index of 1. When the same named
  2501. ** parameter is used more than once, second and subsequent
  2502. ** occurrences have the same index as the first occurrence.
  2503. ** The index for named parameters can be looked up using the
  2504. ** [sqlite3_bind_parameter_name()] API if desired. The index
  2505. ** for "?NNN" parameters is the value of NNN.
  2506. ** The NNN value must be between 1 and the compile-time
  2507. ** parameter SQLITE_MAX_VARIABLE_NUMBER (default value: 999).
  2508. **
  2509. ** The third argument is the value to bind to the parameter.
  2510. **
  2511. ** In those
  2512. ** routines that have a fourth argument, its value is the number of bytes
  2513. ** in the parameter. To be clear: the value is the number of <u>bytes</u>
  2514. ** in the value, not the number of characters.
  2515. ** If the fourth parameter is negative, the length of the string is
  2516. ** number of bytes up to the first zero terminator.
  2517. **
  2518. ** The fifth argument to sqlite3_bind_blob(), sqlite3_bind_text(), and
  2519. ** sqlite3_bind_text16() is a destructor used to dispose of the BLOB or
  2520. ** string after SQLite has finished with it. If the fifth argument is
  2521. ** the special value [SQLITE_STATIC], then SQLite assumes that the
  2522. ** information is in static, unmanaged space and does not need to be freed.
  2523. ** If the fifth argument has the value [SQLITE_TRANSIENT], then
  2524. ** SQLite makes its own private copy of the data immediately, before
  2525. ** the sqlite3_bind_*() routine returns.
  2526. **
  2527. ** The sqlite3_bind_zeroblob() routine binds a BLOB of length N that
  2528. ** is filled with zeros. A zeroblob uses a fixed amount of memory
  2529. ** (just an integer to hold it size) while it is being processed.
  2530. ** Zeroblobs are intended to serve as place-holders for BLOBs whose
  2531. ** content is later written using
  2532. ** [sqlite3_blob_open | increment BLOB I/O] routines. A negative
  2533. ** value for the zeroblob results in a zero-length BLOB.
  2534. **
  2535. ** The sqlite3_bind_*() routines must be called after
  2536. ** [sqlite3_prepare_v2()] (and its variants) or [sqlite3_reset()] and
  2537. ** before [sqlite3_step()].
  2538. ** Bindings are not cleared by the [sqlite3_reset()] routine.
  2539. ** Unbound parameters are interpreted as NULL.
  2540. **
  2541. ** These routines return [SQLITE_OK] on success or an error code if
  2542. ** anything goes wrong. [SQLITE_RANGE] is returned if the parameter
  2543. ** index is out of range. [SQLITE_NOMEM] is returned if malloc fails.
  2544. ** [SQLITE_MISUSE] might be returned if these routines are called on a
  2545. ** virtual machine that is the wrong state or which has already been finalized.
  2546. ** Detection of misuse is unreliable. Applications should not depend
  2547. ** on SQLITE_MISUSE returns. SQLITE_MISUSE is intended to indicate a
  2548. ** a logic error in the application. Future versions of SQLite might
  2549. ** panic rather than return SQLITE_MISUSE.
  2550. **
  2551. ** See also: [sqlite3_bind_parameter_count()],
  2552. ** [sqlite3_bind_parameter_name()], and
  2553. ** [sqlite3_bind_parameter_index()].
  2554. **
  2555. ** INVARIANTS:
  2556. **
  2557. ** {F13506} The [sqlite3_prepare | SQL statement compiler] recognizes
  2558. ** tokens of the forms "?", "?NNN", "$VVV", ":VVV", and "@VVV"
  2559. ** as SQL parameters, where NNN is any sequence of one or more
  2560. ** digits and where VVV is any sequence of one or more
  2561. ** alphanumeric characters or "::" optionally followed by
  2562. ** a string containing no spaces and contained within parentheses.
  2563. **
  2564. ** {F13509} The initial value of an SQL parameter is NULL.
  2565. **
  2566. ** {F13512} The index of an "?" SQL parameter is one larger than the
  2567. ** largest index of SQL parameter to the left, or 1 if
  2568. ** the "?" is the leftmost SQL parameter.
  2569. **
  2570. ** {F13515} The index of an "?NNN" SQL parameter is the integer NNN.
  2571. **
  2572. ** {F13518} The index of an ":VVV", "$VVV", or "@VVV" SQL parameter is
  2573. ** the same as the index of leftmost occurances of the same
  2574. ** parameter, or one more than the largest index over all
  2575. ** parameters to the left if this is the first occurrance
  2576. ** of this parameter, or 1 if this is the leftmost parameter.
  2577. **
  2578. ** {F13521} The [sqlite3_prepare | SQL statement compiler] fail with
  2579. ** an [SQLITE_RANGE] error if the index of an SQL parameter
  2580. ** is less than 1 or greater than SQLITE_MAX_VARIABLE_NUMBER.
  2581. **
  2582. ** {F13524} Calls to [sqlite3_bind_text | sqlite3_bind(S,N,V,...)]
  2583. ** associate the value V with all SQL parameters having an
  2584. ** index of N in the [prepared statement] S.
  2585. **
  2586. ** {F13527} Calls to [sqlite3_bind_text | sqlite3_bind(S,N,...)]
  2587. ** override prior calls with the same values of S and N.
  2588. **
  2589. ** {F13530} Bindings established by [sqlite3_bind_text | sqlite3_bind(S,...)]
  2590. ** persist across calls to [sqlite3_reset(S)].
  2591. **
  2592. ** {F13533} In calls to [sqlite3_bind_blob(S,N,V,L,D)],
  2593. ** [sqlite3_bind_text(S,N,V,L,D)], or
  2594. ** [sqlite3_bind_text16(S,N,V,L,D)] SQLite binds the first L
  2595. ** bytes of the blob or string pointed to by V, when L
  2596. ** is non-negative.
  2597. **
  2598. ** {F13536} In calls to [sqlite3_bind_text(S,N,V,L,D)] or
  2599. ** [sqlite3_bind_text16(S,N,V,L,D)] SQLite binds characters
  2600. ** from V through the first zero character when L is negative.
  2601. **
  2602. ** {F13539} In calls to [sqlite3_bind_blob(S,N,V,L,D)],
  2603. ** [sqlite3_bind_text(S,N,V,L,D)], or
  2604. ** [sqlite3_bind_text16(S,N,V,L,D)] when D is the special
  2605. ** constant [SQLITE_STATIC], SQLite assumes that the value V
  2606. ** is held in static unmanaged space that will not change
  2607. ** during the lifetime of the binding.
  2608. **
  2609. ** {F13542} In calls to [sqlite3_bind_blob(S,N,V,L,D)],
  2610. ** [sqlite3_bind_text(S,N,V,L,D)], or
  2611. ** [sqlite3_bind_text16(S,N,V,L,D)] when D is the special
  2612. ** constant [SQLITE_TRANSIENT], the routine makes a
  2613. ** private copy of V value before it returns.
  2614. **
  2615. ** {F13545} In calls to [sqlite3_bind_blob(S,N,V,L,D)],
  2616. ** [sqlite3_bind_text(S,N,V,L,D)], or
  2617. ** [sqlite3_bind_text16(S,N,V,L,D)] when D is a pointer to
  2618. ** a function, SQLite invokes that function to destroy the
  2619. ** V value after it has finished using the V value.
  2620. **
  2621. ** {F13548} In calls to [sqlite3_bind_zeroblob(S,N,V,L)] the value bound
  2622. ** is a blob of L bytes, or a zero-length blob if L is negative.
  2623. **
  2624. ** {F13551} In calls to [sqlite3_bind_value(S,N,V)] the V argument may
  2625. ** be either a [protected sqlite3_value] object or an
  2626. ** [unprotected sqlite3_value] object.
  2627. *)
  2628. {$IFDEF S}function{$ELSE}var{$ENDIF}sqlite3_bind_blob{$IFDEF D}: function{$ENDIF}(stmt: psqlite3_stmt; N: cint; V: pointer; L: cint; D: sqlite3_destructor_type): cint; cdecl;{$IFDEF S}external Sqlite3Lib;{$ENDIF}
  2629. {$IFDEF S}function{$ELSE}var{$ENDIF}sqlite3_bind_double{$IFDEF D}: function{$ENDIF}(stmt: psqlite3_stmt; N: cint; V: cdouble): cint; cdecl;{$IFDEF S}external Sqlite3Lib;{$ENDIF}
  2630. {$IFDEF S}function{$ELSE}var{$ENDIF}sqlite3_bind_int{$IFDEF D}: function{$ENDIF}(stmt: psqlite3_stmt; N: cint; V: cint): cint; cdecl;{$IFDEF S}external Sqlite3Lib;{$ENDIF}
  2631. {$IFDEF S}function{$ELSE}var{$ENDIF}sqlite3_bind_int64{$IFDEF D}: function{$ENDIF}(stmt: psqlite3_stmt; N: cint; V: sqlite3_int64): cint; cdecl;{$IFDEF S}external Sqlite3Lib;{$ENDIF}
  2632. {$IFDEF S}function{$ELSE}var{$ENDIF}sqlite3_bind_null{$IFDEF D}: function{$ENDIF}(stmt: psqlite3_stmt; N: cint): cint; cdecl;{$IFDEF S}external Sqlite3Lib;{$ENDIF}
  2633. {$IFDEF S}function{$ELSE}var{$ENDIF}sqlite3_bind_text{$IFDEF D}: function{$ENDIF}(stmt: psqlite3_stmt; N: cint; V: pchar; L: cint; D: sqlite3_destructor_type): cint; cdecl;{$IFDEF S}external Sqlite3Lib;{$ENDIF}
  2634. {$IFDEF S}function{$ELSE}var{$ENDIF}sqlite3_bind_text16{$IFDEF D}: function{$ENDIF}(stmt: psqlite3_stmt; N: cint; V: pwidechar; L: cint; D: sqlite3_destructor_type): cint; cdecl;{$IFDEF S}external Sqlite3Lib;{$ENDIF}
  2635. {$IFDEF S}function{$ELSE}var{$ENDIF}sqlite3_bind_value{$IFDEF D}: function{$ENDIF}(stmt: psqlite3_stmt; N: cint; V: psqlite3_value): cint; cdecl;{$IFDEF S}external Sqlite3Lib;{$ENDIF}
  2636. {$IFDEF S}function{$ELSE}var{$ENDIF}sqlite3_bind_zeroblob{$IFDEF D}: function{$ENDIF}(stmt: psqlite3_stmt; N: cint; V: cint): cint; cdecl;{$IFDEF S}external Sqlite3Lib;{$ENDIF}
  2637. (*
  2638. ** CAPI3REF: Number Of SQL Parameters {F13600}
  2639. **
  2640. ** This routine can be used to find the number of SQL parameters
  2641. ** in a prepared statement. SQL parameters are tokens of the
  2642. ** form "?", "?NNN", ":AAA", "$AAA", or "@AAA" that serve as
  2643. ** place-holders for values that are [sqlite3_bind_blob | bound]
  2644. ** to the parameters at a later time.
  2645. **
  2646. ** This routine actually returns the index of the largest parameter.
  2647. ** For all forms except ?NNN, this will correspond to the number of
  2648. ** unique parameters. If parameters of the ?NNN are used, there may
  2649. ** be gaps in the list.
  2650. **
  2651. ** See also: [sqlite3_bind_blob|sqlite3_bind()],
  2652. ** [sqlite3_bind_parameter_name()], and
  2653. ** [sqlite3_bind_parameter_index()].
  2654. **
  2655. ** INVARIANTS:
  2656. **
  2657. ** {F13601} The [sqlite3_bind_parameter_count(S)] interface returns
  2658. ** the largest index of all SQL parameters in the
  2659. ** [prepared statement] S, or 0 if S
  2660. ** contains no SQL parameters.
  2661. *)
  2662. {$IFDEF S}function{$ELSE}var{$ENDIF}sqlite3_bind_parameter_count{$IFDEF D}: function{$ENDIF}(stmt: psqlite3_stmt): cint; cdecl;{$IFDEF S}external Sqlite3Lib;{$ENDIF}
  2663. (*
  2664. ** CAPI3REF: Name Of A Host Parameter {F13620}
  2665. **
  2666. ** This routine returns a pointer to the name of the n-th
  2667. ** SQL parameter in a [prepared statement].
  2668. ** SQL parameters of the form "?NNN" or ":AAA" or "@AAA" or "$AAA"
  2669. ** have a name which is the string "?NNN" or ":AAA" or "@AAA" or "$AAA"
  2670. ** respectively.
  2671. ** In other words, the initial ":" or "$" or "@" or "?"
  2672. ** is included as part of the name.
  2673. ** Parameters of the form "?" without a following integer have no name.
  2674. **
  2675. ** The first host parameter has an index of 1, not 0.
  2676. **
  2677. ** If the value n is out of range or if the n-th parameter is
  2678. ** nameless, then NULL is returned. The returned string is
  2679. ** always in the UTF-8 encoding even if the named parameter was
  2680. ** originally specified as UTF-16 in [sqlite3_prepare16()] or
  2681. ** [sqlite3_prepare16_v2()].
  2682. **
  2683. ** See also: [sqlite3_bind_blob|sqlite3_bind()],
  2684. ** [sqlite3_bind_parameter_count()], and
  2685. ** [sqlite3_bind_parameter_index()].
  2686. **
  2687. ** INVARIANTS:
  2688. **
  2689. ** {F13621} The [sqlite3_bind_parameter_name(S,N)] interface returns
  2690. ** a UTF-8 rendering of the name of the SQL parameter in
  2691. ** [prepared statement] S having index N, or
  2692. ** NULL if there is no SQL parameter with index N or if the
  2693. ** parameter with index N is an anonymous parameter "?".
  2694. *)
  2695. {$IFDEF S}function{$ELSE}var{$ENDIF}sqlite3_bind_parameter_name{$IFDEF D}: function{$ENDIF}(stmt: psqlite3_stmt; N: cint): pchar; cdecl;{$IFDEF S}external Sqlite3Lib;{$ENDIF}
  2696. (*
  2697. ** CAPI3REF: Index Of A Parameter With A Given Name {F13640}
  2698. **
  2699. ** Return the index of an SQL parameter given its name. The
  2700. ** index value returned is suitable for use as the second
  2701. ** parameter to [sqlite3_bind_blob|sqlite3_bind()]. A zero
  2702. ** is returned if no matching parameter is found. The parameter
  2703. ** name must be given in UTF-8 even if the original statement
  2704. ** was prepared from UTF-16 text using [sqlite3_prepare16_v2()].
  2705. **
  2706. ** See also: [sqlite3_bind_blob|sqlite3_bind()],
  2707. ** [sqlite3_bind_parameter_count()], and
  2708. ** [sqlite3_bind_parameter_index()].
  2709. **
  2710. ** INVARIANTS:
  2711. **
  2712. ** {F13641} The [sqlite3_bind_parameter_index(S,N)] interface returns
  2713. ** the index of SQL parameter in [prepared statement]
  2714. ** S whose name matches the UTF-8 string N, or 0 if there is
  2715. ** no match.
  2716. *)
  2717. {$IFDEF S}function{$ELSE}var{$ENDIF}sqlite3_bind_parameter_index{$IFDEF D}: function{$ENDIF}(stmt: psqlite3_stmt; zName: pchar): cint; cdecl;{$IFDEF S}external Sqlite3Lib;{$ENDIF}
  2718. (*
  2719. ** CAPI3REF: Reset All Bindings On A Prepared Statement {F13660}
  2720. **
  2721. ** Contrary to the intuition of many, [sqlite3_reset()] does not
  2722. ** reset the [sqlite3_bind_blob | bindings] on a
  2723. ** [prepared statement]. Use this routine to
  2724. ** reset all host parameters to NULL.
  2725. **
  2726. ** INVARIANTS:
  2727. **
  2728. ** {F13661} The [sqlite3_clear_bindings(S)] interface resets all
  2729. ** SQL parameter bindings in [prepared statement] S
  2730. ** back to NULL.
  2731. *)
  2732. {$IFDEF S}function{$ELSE}var{$ENDIF}sqlite3_clear_bindings{$IFDEF D}: function{$ENDIF}(stmt: psqlite3_stmt): cint; cdecl;{$IFDEF S}external Sqlite3Lib;{$ENDIF}
  2733. (*
  2734. ** CAPI3REF: Number Of Columns In A Result Set {F13710}
  2735. **
  2736. ** Return the number of columns in the result set returned by the
  2737. ** [prepared statement]. This routine returns 0
  2738. ** if pStmt is an SQL statement that does not return data (for
  2739. ** example an UPDATE).
  2740. **
  2741. ** INVARIANTS:
  2742. **
  2743. ** {F13711} The [sqlite3_column_count(S)] interface returns the number of
  2744. ** columns in the result set generated by the
  2745. ** [prepared statement] S, or 0 if S does not generate
  2746. ** a result set.
  2747. *)
  2748. {$IFDEF S}function{$ELSE}var{$ENDIF}sqlite3_column_count{$IFDEF D}: function{$ENDIF}(stmt: psqlite3_stmt): cint; cdecl;{$IFDEF S}external Sqlite3Lib;{$ENDIF}
  2749. (*
  2750. ** CAPI3REF: Column Names In A Result Set {F13720}
  2751. **
  2752. ** These routines return the name assigned to a particular column
  2753. ** in the result set of a SELECT statement. The sqlite3_column_name()
  2754. ** interface returns a pointer to a zero-terminated UTF8 string
  2755. ** and sqlite3_column_name16() returns a pointer to a zero-terminated
  2756. ** UTF16 string. The first parameter is the
  2757. ** [prepared statement] that implements the SELECT statement.
  2758. ** The second parameter is the column number. The left-most column is
  2759. ** number 0.
  2760. **
  2761. ** The returned string pointer is valid until either the
  2762. ** [prepared statement] is destroyed by [sqlite3_finalize()]
  2763. ** or until the next call sqlite3_column_name() or sqlite3_column_name16()
  2764. ** on the same column.
  2765. **
  2766. ** If sqlite3_malloc() fails during the processing of either routine
  2767. ** (for example during a conversion from UTF-8 to UTF-16) then a
  2768. ** NULL pointer is returned.
  2769. **
  2770. ** The name of a result column is the value of the "AS" clause for
  2771. ** that column, if there is an AS clause. If there is no AS clause
  2772. ** then the name of the column is unspecified and may change from
  2773. ** one release of SQLite to the next.
  2774. **
  2775. ** INVARIANTS:
  2776. **
  2777. ** {F13721} A successful invocation of the [sqlite3_column_name(S,N)]
  2778. ** interface returns the name
  2779. ** of the Nth column (where 0 is the left-most column) for the
  2780. ** result set of [prepared statement] S as a
  2781. ** zero-terminated UTF-8 string.
  2782. **
  2783. ** {F13723} A successful invocation of the [sqlite3_column_name16(S,N)]
  2784. ** interface returns the name
  2785. ** of the Nth column (where 0 is the left-most column) for the
  2786. ** result set of [prepared statement] S as a
  2787. ** zero-terminated UTF-16 string in the native byte order.
  2788. **
  2789. ** {F13724} The [sqlite3_column_name()] and [sqlite3_column_name16()]
  2790. ** interfaces return a NULL pointer if they are unable to
  2791. ** allocate memory memory to hold there normal return strings.
  2792. **
  2793. ** {F13725} If the N parameter to [sqlite3_column_name(S,N)] or
  2794. ** [sqlite3_column_name16(S,N)] is out of range, then the
  2795. ** interfaces returns a NULL pointer.
  2796. **
  2797. ** {F13726} The strings returned by [sqlite3_column_name(S,N)] and
  2798. ** [sqlite3_column_name16(S,N)] are valid until the next
  2799. ** call to either routine with the same S and N parameters
  2800. ** or until [sqlite3_finalize(S)] is called.
  2801. **
  2802. ** {F13727} When a result column of a [SELECT] statement contains
  2803. ** an AS clause, the name of that column is the indentifier
  2804. ** to the right of the AS keyword.
  2805. *)
  2806. {$IFDEF S}function{$ELSE}var{$ENDIF}sqlite3_column_name{$IFDEF D}: function{$ENDIF}(stmt: psqlite3_stmt; N: cint): pchar; cdecl;{$IFDEF S}external Sqlite3Lib;{$ENDIF}
  2807. {$IFDEF S}function{$ELSE}var{$ENDIF}sqlite3_column_name16{$IFDEF D}: function{$ENDIF}(stmt: psqlite3_stmt; N: cint): pwidechar; cdecl;{$IFDEF S}external Sqlite3Lib;{$ENDIF}
  2808. (*
  2809. ** CAPI3REF: Source Of Data In A Query Result {F13740}
  2810. **
  2811. ** These routines provide a means to determine what column of what
  2812. ** table in which database a result of a SELECT statement comes from.
  2813. ** The name of the database or table or column can be returned as
  2814. ** either a UTF8 or UTF16 string. The _database_ routines return
  2815. ** the database name, the _table_ routines return the table name, and
  2816. ** the origin_ routines return the column name.
  2817. ** The returned string is valid until
  2818. ** the [prepared statement] is destroyed using
  2819. ** [sqlite3_finalize()] or until the same information is requested
  2820. ** again in a different encoding.
  2821. **
  2822. ** The names returned are the original un-aliased names of the
  2823. ** database, table, and column.
  2824. **
  2825. ** The first argument to the following calls is a [prepared statement].
  2826. ** These functions return information about the Nth column returned by
  2827. ** the statement, where N is the second function argument.
  2828. **
  2829. ** If the Nth column returned by the statement is an expression
  2830. ** or subquery and is not a column value, then all of these functions
  2831. ** return NULL. These routine might also return NULL if a memory
  2832. ** allocation error occurs. Otherwise, they return the
  2833. ** name of the attached database, table and column that query result
  2834. ** column was extracted from.
  2835. **
  2836. ** As with all other SQLite APIs, those postfixed with "16" return
  2837. ** UTF-16 encoded strings, the other functions return UTF-8. {END}
  2838. **
  2839. ** These APIs are only available if the library was compiled with the
  2840. ** SQLITE_ENABLE_COLUMN_METADATA preprocessor symbol defined.
  2841. **
  2842. ** {U13751}
  2843. ** If two or more threads call one or more of these routines against the same
  2844. ** prepared statement and column at the same time then the results are
  2845. ** undefined.
  2846. **
  2847. ** INVARIANTS:
  2848. **
  2849. ** {F13741} The [sqlite3_column_database_name(S,N)] interface returns either
  2850. ** the UTF-8 zero-terminated name of the database from which the
  2851. ** Nth result column of [prepared statement] S
  2852. ** is extracted, or NULL if the the Nth column of S is a
  2853. ** general expression or if unable to allocate memory
  2854. ** to store the name.
  2855. **
  2856. ** {F13742} The [sqlite3_column_database_name16(S,N)] interface returns either
  2857. ** the UTF-16 native byte order
  2858. ** zero-terminated name of the database from which the
  2859. ** Nth result column of [prepared statement] S
  2860. ** is extracted, or NULL if the the Nth column of S is a
  2861. ** general expression or if unable to allocate memory
  2862. ** to store the name.
  2863. **
  2864. ** {F13743} The [sqlite3_column_table_name(S,N)] interface returns either
  2865. ** the UTF-8 zero-terminated name of the table from which the
  2866. ** Nth result column of [prepared statement] S
  2867. ** is extracted, or NULL if the the Nth column of S is a
  2868. ** general expression or if unable to allocate memory
  2869. ** to store the name.
  2870. **
  2871. ** {F13744} The [sqlite3_column_table_name16(S,N)] interface returns either
  2872. ** the UTF-16 native byte order
  2873. ** zero-terminated name of the table from which the
  2874. ** Nth result column of [prepared statement] S
  2875. ** is extracted, or NULL if the the Nth column of S is a
  2876. ** general expression or if unable to allocate memory
  2877. ** to store the name.
  2878. **
  2879. ** {F13745} The [sqlite3_column_origin_name(S,N)] interface returns either
  2880. ** the UTF-8 zero-terminated name of the table column from which the
  2881. ** Nth result column of [prepared statement] S
  2882. ** is extracted, or NULL if the the Nth column of S is a
  2883. ** general expression or if unable to allocate memory
  2884. ** to store the name.
  2885. **
  2886. ** {F13746} The [sqlite3_column_origin_name16(S,N)] interface returns either
  2887. ** the UTF-16 native byte order
  2888. ** zero-terminated name of the table column from which the
  2889. ** Nth result column of [prepared statement] S
  2890. ** is extracted, or NULL if the the Nth column of S is a
  2891. ** general expression or if unable to allocate memory
  2892. ** to store the name.
  2893. **
  2894. ** {F13748} The return values from
  2895. ** [sqlite3_column_database_name|column metadata interfaces]
  2896. ** are valid
  2897. ** for the lifetime of the [prepared statement]
  2898. ** or until the encoding is changed by another metadata
  2899. ** interface call for the same prepared statement and column.
  2900. **
  2901. ** LIMITATIONS:
  2902. **
  2903. ** {U13751} If two or more threads call one or more
  2904. ** [sqlite3_column_database_name|column metadata interfaces]
  2905. ** the same [prepared statement] and result column
  2906. ** at the same time then the results are undefined.
  2907. *)
  2908. {$IFDEF S}function{$ELSE}var{$ENDIF}sqlite3_column_database_name{$IFDEF D}: function{$ENDIF}(stmt: psqlite3_stmt; N: cint): pchar; cdecl;{$IFDEF S}external Sqlite3Lib;{$ENDIF}
  2909. {$IFDEF S}function{$ELSE}var{$ENDIF}sqlite3_column_database_name16{$IFDEF D}: function{$ENDIF}(stmt: psqlite3_stmt; N: cint): pwidechar; cdecl;{$IFDEF S}external Sqlite3Lib;{$ENDIF}
  2910. {$IFDEF S}function{$ELSE}var{$ENDIF}sqlite3_column_table_name{$IFDEF D}: function{$ENDIF}(stmt: psqlite3_stmt; N: cint): pchar; cdecl;{$IFDEF S}external Sqlite3Lib;{$ENDIF}
  2911. {$IFDEF S}function{$ELSE}var{$ENDIF}sqlite3_column_table_name16{$IFDEF D}: function{$ENDIF}(stmt: psqlite3_stmt; N: cint): pwidechar; cdecl;{$IFDEF S}external Sqlite3Lib;{$ENDIF}
  2912. {$IFDEF S}function{$ELSE}var{$ENDIF}sqlite3_column_origin_name{$IFDEF D}: function{$ENDIF}(stmt: psqlite3_stmt; N: cint): pchar; cdecl;{$IFDEF S}external Sqlite3Lib;{$ENDIF}
  2913. {$IFDEF S}function{$ELSE}var{$ENDIF}sqlite3_column_origin_name16{$IFDEF D}: function{$ENDIF}(stmt: psqlite3_stmt; N: cint): pwidechar; cdecl;{$IFDEF S}external Sqlite3Lib;{$ENDIF}
  2914. (*
  2915. ** CAPI3REF: Declared Datatype Of A Query Result {F13760}
  2916. **
  2917. ** The first parameter is a [prepared statement].
  2918. ** If this statement is a SELECT statement and the Nth column of the
  2919. ** returned result set of that SELECT is a table column (not an
  2920. ** expression or subquery) then the declared type of the table
  2921. ** column is returned. If the Nth column of the result set is an
  2922. ** expression or subquery, then a NULL pointer is returned.
  2923. ** The returned string is always UTF-8 encoded. {END}
  2924. ** For example, in the database schema:
  2925. **
  2926. ** CREATE TABLE t1(c1 VARIANT);
  2927. **
  2928. ** And the following statement compiled:
  2929. **
  2930. ** SELECT c1 + 1, c1 FROM t1;
  2931. **
  2932. ** Then this routine would return the string "VARIANT" for the second
  2933. ** result column (i==1), and a NULL pointer for the first result column
  2934. ** (i==0).
  2935. **
  2936. ** SQLite uses dynamic run-time typing. So just because a column
  2937. ** is declared to contain a particular type does not mean that the
  2938. ** data stored in that column is of the declared type. SQLite is
  2939. ** strongly typed, but the typing is dynamic not static. Type
  2940. ** is associated with individual values, not with the containers
  2941. ** used to hold those values.
  2942. **
  2943. ** INVARIANTS:
  2944. **
  2945. ** {F13761} A successful call to [sqlite3_column_decltype(S,N)]
  2946. ** returns a zero-terminated UTF-8 string containing the
  2947. ** the declared datatype of the table column that appears
  2948. ** as the Nth column (numbered from 0) of the result set to the
  2949. ** [prepared statement] S.
  2950. **
  2951. ** {F13762} A successful call to [sqlite3_column_decltype16(S,N)]
  2952. ** returns a zero-terminated UTF-16 native byte order string
  2953. ** containing the declared datatype of the table column that appears
  2954. ** as the Nth column (numbered from 0) of the result set to the
  2955. ** [prepared statement] S.
  2956. **
  2957. ** {F13763} If N is less than 0 or N is greater than or equal to
  2958. ** the number of columns in [prepared statement] S
  2959. ** or if the Nth column of S is an expression or subquery rather
  2960. ** than a table column or if a memory allocation failure
  2961. ** occurs during encoding conversions, then
  2962. ** calls to [sqlite3_column_decltype(S,N)] or
  2963. ** [sqlite3_column_decltype16(S,N)] return NULL.
  2964. *)
  2965. {$IFDEF S}function{$ELSE}var{$ENDIF}sqlite3_column_decltype{$IFDEF D}: function{$ENDIF}(stmt: psqlite3_stmt; N: cint): pchar; cdecl;{$IFDEF S}external Sqlite3Lib;{$ENDIF}
  2966. {$IFDEF S}function{$ELSE}var{$ENDIF}sqlite3_column_decltype16{$IFDEF D}: function{$ENDIF}(stmt: psqlite3_stmt; N: cint): pwidechar; cdecl;{$IFDEF S}external Sqlite3Lib;{$ENDIF}
  2967. (*
  2968. ** CAPI3REF: Evaluate An SQL Statement {F13200}
  2969. **
  2970. ** After an [prepared statement] has been prepared with a call
  2971. ** to either [sqlite3_prepare_v2()] or [sqlite3_prepare16_v2()] or to one of
  2972. ** the legacy interfaces [sqlite3_prepare()] or [sqlite3_prepare16()],
  2973. ** then this function must be called one or more times to evaluate the
  2974. ** statement.
  2975. **
  2976. ** The details of the behavior of this sqlite3_step() interface depend
  2977. ** on whether the statement was prepared using the newer "v2" interface
  2978. ** [sqlite3_prepare_v2()] and [sqlite3_prepare16_v2()] or the older legacy
  2979. ** interface [sqlite3_prepare()] and [sqlite3_prepare16()]. The use of the
  2980. ** new "v2" interface is recommended for new applications but the legacy
  2981. ** interface will continue to be supported.
  2982. **
  2983. ** In the legacy interface, the return value will be either [SQLITE_BUSY],
  2984. ** [SQLITE_DONE], [SQLITE_ROW], [SQLITE_ERROR], or [SQLITE_MISUSE].
  2985. ** With the "v2" interface, any of the other [SQLITE_OK | result code]
  2986. ** or [SQLITE_IOERR_READ | extended result code] might be returned as
  2987. ** well.
  2988. **
  2989. ** [SQLITE_BUSY] means that the database engine was unable to acquire the
  2990. ** database locks it needs to do its job. If the statement is a COMMIT
  2991. ** or occurs outside of an explicit transaction, then you can retry the
  2992. ** statement. If the statement is not a COMMIT and occurs within a
  2993. ** explicit transaction then you should rollback the transaction before
  2994. ** continuing.
  2995. **
  2996. ** [SQLITE_DONE] means that the statement has finished executing
  2997. ** successfully. sqlite3_step() should not be called again on this virtual
  2998. ** machine without first calling [sqlite3_reset()] to reset the virtual
  2999. ** machine back to its initial state.
  3000. **
  3001. ** If the SQL statement being executed returns any data, then
  3002. ** [SQLITE_ROW] is returned each time a new row of data is ready
  3003. ** for processing by the caller. The values may be accessed using
  3004. ** the [sqlite3_column_cint | column access functions].
  3005. ** sqlite3_step() is called again to retrieve the next row of data.
  3006. **
  3007. ** [SQLITE_ERROR] means that a run-time error (such as a constracint
  3008. ** violation) has occurred. sqlite3_step() should not be called again on
  3009. ** the VM. More information may be found by calling [sqlite3_errmsg()].
  3010. ** With the legacy interface, a more specific error code (example:
  3011. ** [SQLITE_cintERRUPT], [SQLITE_SCHEMA], [SQLITE_CORRUPT], and so forth)
  3012. ** can be obtained by calling [sqlite3_reset()] on the
  3013. ** [prepared statement]. In the "v2" interface,
  3014. ** the more specific error code is returned directly by sqlite3_step().
  3015. **
  3016. ** [SQLITE_MISUSE] means that the this routine was called inappropriately.
  3017. ** Perhaps it was called on a [prepared statement] that has
  3018. ** already been [sqlite3_finalize | finalized] or on one that had
  3019. ** previously returned [SQLITE_ERROR] or [SQLITE_DONE]. Or it could
  3020. ** be the case that the same database connection is being used by two or
  3021. ** more threads at the same moment in time.
  3022. **
  3023. ** <b>Goofy interface Alert:</b>
  3024. ** In the legacy interface,
  3025. ** the sqlite3_step() API always returns a generic error code,
  3026. ** [SQLITE_ERROR], following any error other than [SQLITE_BUSY]
  3027. ** and [SQLITE_MISUSE]. You must call [sqlite3_reset()] or
  3028. ** [sqlite3_finalize()] in order to find one of the specific
  3029. ** [error codes] that better describes the error.
  3030. ** We admit that this is a goofy design. The problem has been fixed
  3031. ** with the "v2" interface. If you prepare all of your SQL statements
  3032. ** using either [sqlite3_prepare_v2()] or [sqlite3_prepare16_v2()] instead
  3033. ** of the legacy [sqlite3_prepare()] and [sqlite3_prepare16()], then the
  3034. ** more specific [error codes] are returned directly
  3035. ** by sqlite3_step(). The use of the "v2" interface is recommended.
  3036. **
  3037. ** INVARIANTS:
  3038. **
  3039. ** {F13202} If [prepared statement] S is ready to be
  3040. ** run, then [sqlite3_step(S)] advances that prepared statement
  3041. ** until to completion or until it is ready to return another
  3042. ** row of the result set or an cinterrupt or run-time error occurs.
  3043. **
  3044. ** {F15304} When a call to [sqlite3_step(S)] causes the
  3045. ** [prepared statement] S to run to completion,
  3046. ** the function returns [SQLITE_DONE].
  3047. **
  3048. ** {F15306} When a call to [sqlite3_step(S)] stops because it is ready
  3049. ** to return another row of the result set, it returns
  3050. ** [SQLITE_ROW].
  3051. **
  3052. ** {F15308} If a call to [sqlite3_step(S)] encounters an
  3053. ** [sqlite3_cinterrupt|cinterrupt] or a run-time error,
  3054. ** it returns an appropraite error code that is not one of
  3055. ** [SQLITE_OK], [SQLITE_ROW], or [SQLITE_DONE].
  3056. **
  3057. ** {F15310} If an [sqlite3_cinterrupt|cinterrupt] or run-time error
  3058. ** occurs during a call to [sqlite3_step(S)]
  3059. ** for a [prepared statement] S created using
  3060. ** legacy interfaces [sqlite3_prepare()] or
  3061. ** [sqlite3_prepare16()] then the function returns either
  3062. ** [SQLITE_ERROR], [SQLITE_BUSY], or [SQLITE_MISUSE].
  3063. *)
  3064. {$IFDEF S}function{$ELSE}var{$ENDIF}sqlite3_step{$IFDEF D}: function{$ENDIF}(stmt: psqlite3_stmt): cint; cdecl;{$IFDEF S}external Sqlite3Lib;{$ENDIF}
  3065. (*
  3066. ** CAPI3REF: Number of columns in a result set {F13770}
  3067. **
  3068. ** Return the number of values in the current row of the result set.
  3069. **
  3070. ** INVARIANTS:
  3071. **
  3072. ** {F13771} After a call to [sqlite3_step(S)] that returns
  3073. ** [SQLITE_ROW], the [sqlite3_data_count(S)] routine
  3074. ** will return the same value as the
  3075. ** [sqlite3_column_count(S)] function.
  3076. **
  3077. ** {F13772} After [sqlite3_step(S)] has returned any value other than
  3078. ** [SQLITE_ROW] or before [sqlite3_step(S)] has been
  3079. ** called on the [prepared statement] for
  3080. ** the first time since it was [sqlite3_prepare|prepared]
  3081. ** or [sqlite3_reset|reset], the [sqlite3_data_count(S)]
  3082. ** routine returns zero.
  3083. *)
  3084. {$IFDEF S}function{$ELSE}var{$ENDIF}sqlite3_data_count{$IFDEF D}: function{$ENDIF}(stmt: psqlite3_stmt): cint; cdecl;{$IFDEF S}external Sqlite3Lib;{$ENDIF}
  3085. (*
  3086. ** CAPI3REF: Fundamental Datatypes {F10265}
  3087. ** KEYWORDS: SQLITE_TEXT
  3088. **
  3089. ** {F10266}Every value in SQLite has one of five fundamental datatypes:
  3090. **
  3091. ** <ul>
  3092. ** <li> 64-bit signed INTEGER
  3093. ** <li> 64-bit IEEE floating pocint number
  3094. ** <li> string
  3095. ** <li> BLOB
  3096. ** <li> NULL
  3097. ** </ul> {END}
  3098. **
  3099. ** These constants are codes for each of those types.
  3100. **
  3101. ** Note that the SQLITE_TEXT constant was also used in SQLite version 2
  3102. ** for a completely different meaning. Software that links against both
  3103. ** SQLite version 2 and SQLite version 3 should use SQLITE3_TEXT not
  3104. ** SQLITE_TEXT.
  3105. *)
  3106. const
  3107. SQLITE_INTEGER = 1;
  3108. SQLITE_FLOAT = 2;
  3109. SQLITE_BLOB = 4;
  3110. SQLITE_NULL = 5;
  3111. SQLITE_TEXT = 3;
  3112. SQLITE3_TEXT = 3;
  3113. (*
  3114. ** CAPI3REF: Results Values From A Query {F13800}
  3115. **
  3116. ** These routines form the "result set query" interface.
  3117. **
  3118. ** These routines return information about
  3119. ** a single column of the current result row of a query. In every
  3120. ** case the first argument is a pointer to the
  3121. ** [prepared statement] that is being
  3122. ** evaluated (the [stmt: psqlite3_stmt] that was returned from
  3123. ** [sqlite3_prepare_v2()] or one of its variants) and
  3124. ** the second argument is the index of the column for which information
  3125. ** should be returned. The left-most column of the result set
  3126. ** has an index of 0.
  3127. **
  3128. ** If the SQL statement is not currently point to a valid row, or if the
  3129. ** the column index is out of range, the result is undefined.
  3130. ** These routines may only be called when the most recent call to
  3131. ** [sqlite3_step()] has returned [SQLITE_ROW] and neither
  3132. ** [sqlite3_reset()] nor [sqlite3_finalize()] has been call subsequently.
  3133. ** If any of these routines are called after [sqlite3_reset()] or
  3134. ** [sqlite3_finalize()] or after [sqlite3_step()] has returned
  3135. ** something other than [SQLITE_ROW], the results are undefined.
  3136. ** If [sqlite3_step()] or [sqlite3_reset()] or [sqlite3_finalize()]
  3137. ** are called from a different thread while any of these routines
  3138. ** are pending, then the results are undefined.
  3139. **
  3140. ** The sqlite3_column_type() routine returns
  3141. ** [SQLITE_INTEGER | datatype code] for the initial data type
  3142. ** of the result column. The returned value is one of [SQLITE_INTEGER],
  3143. ** [SQLITE_FLOAT], [SQLITE_TEXT], [SQLITE_BLOB], or [SQLITE_NULL]. The value
  3144. ** returned by sqlite3_column_type() is only meaningful if no type
  3145. ** conversions have occurred as described below. After a type conversion,
  3146. ** the value returned by sqlite3_column_type() is undefined. Future
  3147. ** versions of SQLite may change the behavior of sqlite3_column_type()
  3148. ** following a type conversion.
  3149. **
  3150. ** If the result is a BLOB or UTF-8 string then the sqlite3_column_bytes()
  3151. ** routine returns the number of bytes in that BLOB or string.
  3152. ** If the result is a UTF-16 string, then sqlite3_column_bytes() converts
  3153. ** the string to UTF-8 and then returns the number of bytes.
  3154. ** If the result is a numeric value then sqlite3_column_bytes() uses
  3155. ** [sqlite3_snprcintf()] to convert that value to a UTF-8 string and returns
  3156. ** the number of bytes in that string.
  3157. ** The value returned does not include the zero terminator at the end
  3158. ** of the string. For clarity: the value returned is the number of
  3159. ** bytes in the string, not the number of characters.
  3160. **
  3161. ** Strings returned by sqlite3_column_text() and sqlite3_column_text16(),
  3162. ** even empty strings, are always zero terminated. The return
  3163. ** value from sqlite3_column_blob() for a zero-length blob is an arbitrary
  3164. ** pointer, possibly even a NULL pointer.
  3165. **
  3166. ** The sqlite3_column_bytes16() routine is similar to sqlite3_column_bytes()
  3167. ** but leaves the result in UTF-16 in native byte order instead of UTF-8.
  3168. ** The zero terminator is not included in this count.
  3169. **
  3170. ** The object returned by [sqlite3_column_value()] is an
  3171. ** [unprotected sqlite3_value] object. An unprotected sqlite3_value object
  3172. ** may only be used with [sqlite3_bind_value()] and [sqlite3_result_value()].
  3173. ** If the [unprotected sqlite3_value] object returned by
  3174. ** [sqlite3_column_value()] is used in any other way, including calls
  3175. ** to routines like
  3176. ** [sqlite3_value_int()], [sqlite3_value_text()], or [sqlite3_value_bytes()],
  3177. ** then the behavior is undefined.
  3178. **
  3179. ** These routines attempt to convert the value where appropriate. For
  3180. ** example, if the cinternal representation is FLOAT and a text result
  3181. ** is requested, [sqlite3_snprcintf()] is used cinternally to do the conversion
  3182. ** automatically. The following table details the conversions that
  3183. ** are applied:
  3184. **
  3185. ** <blockquote>
  3186. ** <table border="1">
  3187. ** <tr><th> cinternal<br>Type <th> Requested<br>Type <th> Conversion
  3188. **
  3189. ** <tr><td> NULL <td> INTEGER <td> Result is 0
  3190. ** <tr><td> NULL <td> FLOAT <td> Result is 0.0
  3191. ** <tr><td> NULL <td> TEXT <td> Result is NULL pointer
  3192. ** <tr><td> NULL <td> BLOB <td> Result is NULL pointer
  3193. ** <tr><td> INTEGER <td> FLOAT <td> Convert from INTEGER to float
  3194. ** <tr><td> INTEGER <td> TEXT <td> ASCII rendering of the INTEGER
  3195. ** <tr><td> INTEGER <td> BLOB <td> Same as for INTEGER->TEXT
  3196. ** <tr><td> FLOAT <td> INTEGER <td> Convert from float to INTEGER
  3197. ** <tr><td> FLOAT <td> TEXT <td> ASCII rendering of the float
  3198. ** <tr><td> FLOAT <td> BLOB <td> Same as FLOAT->TEXT
  3199. ** <tr><td> TEXT <td> INTEGER <td> Use atoi()
  3200. ** <tr><td> TEXT <td> FLOAT <td> Use atof()
  3201. ** <tr><td> TEXT <td> BLOB <td> No change
  3202. ** <tr><td> BLOB <td> INTEGER <td> Convert to TEXT then use atoi()
  3203. ** <tr><td> BLOB <td> FLOAT <td> Convert to TEXT then use atof()
  3204. ** <tr><td> BLOB <td> TEXT <td> Add a zero terminator if needed
  3205. ** </table>
  3206. ** </blockquote>
  3207. **
  3208. ** The table above makes reference to standard C library functions atoi()
  3209. ** and atof(). SQLite does not really use these functions. It has its
  3210. ** on equavalent cinternal routines. The atoi() and atof() names are
  3211. ** used in the table for brevity and because they are familiar to most
  3212. ** C programmers.
  3213. **
  3214. ** Note that when type conversions occur, pointers returned by prior
  3215. ** calls to sqlite3_column_blob(), sqlite3_column_text(), and/or
  3216. ** sqlite3_column_text16() may be invalidated.
  3217. ** Type conversions and pointer invalidations might occur
  3218. ** in the following cases:
  3219. **
  3220. ** <ul>
  3221. ** <li><p> The initial content is a BLOB and sqlite3_column_text()
  3222. ** or sqlite3_column_text16() is called. A zero-terminator might
  3223. ** need to be added to the string.</p></li>
  3224. **
  3225. ** <li><p> The initial content is UTF-8 text and sqlite3_column_bytes16() or
  3226. ** sqlite3_column_text16() is called. The content must be converted
  3227. ** to UTF-16.</p></li>
  3228. **
  3229. ** <li><p> The initial content is UTF-16 text and sqlite3_column_bytes() or
  3230. ** sqlite3_column_text() is called. The content must be converted
  3231. ** to UTF-8.</p></li>
  3232. ** </ul>
  3233. **
  3234. ** Conversions between UTF-16be and UTF-16le are always done in place and do
  3235. ** not invalidate a prior pointer, though of course the content of the buffer
  3236. ** that the prior pointer points to will have been modified. Other kinds
  3237. ** of conversion are done in place when it is possible, but sometime it is
  3238. ** not possible and in those cases prior pointers are invalidated.
  3239. **
  3240. ** The safest and easiest to remember policy is to invoke these routines
  3241. ** in one of the following ways:
  3242. **
  3243. ** <ul>
  3244. ** <li>sqlite3_column_text() followed by sqlite3_column_bytes()</li>
  3245. ** <li>sqlite3_column_blob() followed by sqlite3_column_bytes()</li>
  3246. ** <li>sqlite3_column_text16() followed by sqlite3_column_bytes16()</li>
  3247. ** </ul>
  3248. **
  3249. ** In other words, you should call sqlite3_column_text(), sqlite3_column_blob(),
  3250. ** or sqlite3_column_text16() first to force the result cinto the desired
  3251. ** format, then invoke sqlite3_column_bytes() or sqlite3_column_bytes16() to
  3252. ** find the size of the result. Do not mix call to sqlite3_column_text() or
  3253. ** sqlite3_column_blob() with calls to sqlite3_column_bytes16(). And do not
  3254. ** mix calls to sqlite3_column_text16() with calls to sqlite3_column_bytes().
  3255. **
  3256. ** The pointers returned are valid until a type conversion occurs as
  3257. ** described above, or until [sqlite3_step()] or [sqlite3_reset()] or
  3258. ** [sqlite3_finalize()] is called. The memory space used to hold strings
  3259. ** and blobs is freed automatically. Do <b>not</b> pass the pointers returned
  3260. ** [sqlite3_column_blob()], [sqlite3_column_text()], etc. cinto
  3261. ** [sqlite3_free()].
  3262. **
  3263. ** If a memory allocation error occurs during the evaluation of any
  3264. ** of these routines, a default value is returned. The default value
  3265. ** is either the INTEGER 0, the floating point number 0.0, or a NULL
  3266. ** pointer. Subsequent calls to [sqlite3_errcode()] will return
  3267. ** [SQLITE_NOMEM].
  3268. **
  3269. ** INVARIANTS:
  3270. **
  3271. ** {F13803} The [sqlite3_column_blob(S,N)] interface converts the
  3272. ** Nth column in the current row of the result set for
  3273. ** [prepared statement] S cinto a blob and then returns a
  3274. ** pointer to the converted value.
  3275. **
  3276. ** {F13806} The [sqlite3_column_bytes(S,N)] interface returns the
  3277. ** number of bytes in the blob or string (exclusive of the
  3278. ** zero terminator on the string) that was returned by the
  3279. ** most recent call to [sqlite3_column_blob(S,N)] or
  3280. ** [sqlite3_column_text(S,N)].
  3281. **
  3282. ** {F13809} The [sqlite3_column_bytes16(S,N)] interface returns the
  3283. ** number of bytes in the string (exclusive of the
  3284. ** zero terminator on the string) that was returned by the
  3285. ** most recent call to [sqlite3_column_text16(S,N)].
  3286. **
  3287. ** {F13812} The [sqlite3_column_double(S,N)] interface converts the
  3288. ** Nth column in the current row of the result set for
  3289. ** [prepared statement] S cinto a floating point value and
  3290. ** returns a copy of that value.
  3291. **
  3292. ** {F13815} The [sqlite3_column_cint(S,N)] interface converts the
  3293. ** Nth column in the current row of the result set for
  3294. ** [prepared statement] S cinto a 64-bit signed INTEGER and
  3295. ** returns the lower 32 bits of that INTEGER.
  3296. **
  3297. ** {F13818} The [sqlite3_column_cint64(S,N)] interface converts the
  3298. ** Nth column in the current row of the result set for
  3299. ** [prepared statement] S cinto a 64-bit signed INTEGER and
  3300. ** returns a copy of that INTEGER.
  3301. **
  3302. ** {F13821} The [sqlite3_column_text(S,N)] interface converts the
  3303. ** Nth column in the current row of the result set for
  3304. ** [prepared statement] S cinto a zero-terminated UTF-8
  3305. ** string and returns a pointer to that string.
  3306. **
  3307. ** {F13824} The [sqlite3_column_text16(S,N)] interface converts the
  3308. ** Nth column in the current row of the result set for
  3309. ** [prepared statement] S cinto a zero-terminated 2-byte
  3310. ** aligned UTF-16 native byte order
  3311. ** string and returns a pointer to that string.
  3312. **
  3313. ** {F13827} The [sqlite3_column_type(S,N)] interface returns
  3314. ** one of [SQLITE_NULL], [SQLITE_INTEGER], [SQLITE_FLOAT],
  3315. ** [SQLITE_TEXT], or [SQLITE_BLOB] as appropriate for
  3316. ** the Nth column in the current row of the result set for
  3317. ** [prepared statement] S.
  3318. **
  3319. ** {F13830} The [sqlite3_column_value(S,N)] interface returns a
  3320. ** pointer to an [unprotected sqlite3_value] object for the
  3321. ** Nth column in the current row of the result set for
  3322. ** [prepared statement] S.
  3323. *)
  3324. {$IFDEF S}function{$ELSE}var{$ENDIF}sqlite3_column_blob{$IFDEF D}: function{$ENDIF}(stmt: psqlite3_stmt; iCol: cint): pointer; cdecl;{$IFDEF S}external Sqlite3Lib;{$ENDIF}
  3325. {$IFDEF S}function{$ELSE}var{$ENDIF}sqlite3_column_bytes{$IFDEF D}: function{$ENDIF}(stmt: psqlite3_stmt; iCol: cint): cint; cdecl;{$IFDEF S}external Sqlite3Lib;{$ENDIF}
  3326. {$IFDEF S}function{$ELSE}var{$ENDIF}sqlite3_column_bytes16{$IFDEF D}: function{$ENDIF}(stmt: psqlite3_stmt; iCol: cint): cint; cdecl;{$IFDEF S}external Sqlite3Lib;{$ENDIF}
  3327. {$IFDEF S}function{$ELSE}var{$ENDIF}sqlite3_column_double{$IFDEF D}: function{$ENDIF}(stmt: psqlite3_stmt; iCol: cint): cdouble; cdecl;{$IFDEF S}external Sqlite3Lib;{$ENDIF}
  3328. {$IFDEF S}function{$ELSE}var{$ENDIF}sqlite3_column_int{$IFDEF D}: function{$ENDIF}(stmt: psqlite3_stmt; iCol: cint): cint; cdecl;{$IFDEF S}external Sqlite3Lib;{$ENDIF}
  3329. {$IFDEF S}function{$ELSE}var{$ENDIF}sqlite3_column_int64{$IFDEF D}: function{$ENDIF}(stmt: psqlite3_stmt; iCol: cint): sqlite3_int64; cdecl;{$IFDEF S}external Sqlite3Lib;{$ENDIF}
  3330. {$IFDEF S}function{$ELSE}var{$ENDIF}sqlite3_column_text{$IFDEF D}: function{$ENDIF}(stmt: psqlite3_stmt; iCol: cint): pchar; cdecl;{$IFDEF S}external Sqlite3Lib;{$ENDIF}
  3331. {$IFDEF S}function{$ELSE}var{$ENDIF}sqlite3_column_text16{$IFDEF D}: function{$ENDIF}(stmt: psqlite3_stmt; iCol: cint): pwidechar; cdecl;{$IFDEF S}external Sqlite3Lib;{$ENDIF}
  3332. {$IFDEF S}function{$ELSE}var{$ENDIF}sqlite3_column_type{$IFDEF D}: function{$ENDIF}(stmt: psqlite3_stmt; iCol: cint): cint; cdecl;{$IFDEF S}external Sqlite3Lib;{$ENDIF}
  3333. {$IFDEF S}function{$ELSE}var{$ENDIF}sqlite3_column_value{$IFDEF D}: function{$ENDIF}(stmt: psqlite3_stmt; iCol: cint): psqlite3_value; cdecl;{$IFDEF S}external Sqlite3Lib;{$ENDIF}
  3334. (*
  3335. ** CAPI3REF: Destroy A Prepared Statement Object {F13300}
  3336. **
  3337. ** The sqlite3_finalize() function is called to delete a
  3338. ** [prepared statement]. If the statement was
  3339. ** executed successfully, or not executed at all, then SQLITE_OK is returned.
  3340. ** If execution of the statement failed then an
  3341. ** [error code] or [extended error code]
  3342. ** is returned.
  3343. **
  3344. ** This routine can be called at any point during the execution of the
  3345. ** [prepared statement]. If the virtual machine has not
  3346. ** completed execution when this routine is called, that is like
  3347. ** encountering an error or an cinterrupt. (See [sqlite3_cinterrupt()].)
  3348. ** Incomplete updates may be rolled back and transactions cancelled,
  3349. ** depending on the circumstances, and the
  3350. ** [error code] returned will be [SQLITE_ABORT].
  3351. **
  3352. ** INVARIANTS:
  3353. **
  3354. ** {F11302} The [sqlite3_finalize(S)] interface destroys the
  3355. ** [prepared statement] S and releases all
  3356. ** memory and file resources held by that object.
  3357. **
  3358. ** {F11304} If the most recent call to [sqlite3_step(S)] for the
  3359. ** [prepared statement] S returned an error,
  3360. ** then [sqlite3_finalize(S)] returns that same error.
  3361. *)
  3362. {$IFDEF S}function{$ELSE}var{$ENDIF}sqlite3_finalize{$IFDEF D}: function{$ENDIF}(stmt: psqlite3_stmt): cint; cdecl;{$IFDEF S}external Sqlite3Lib;{$ENDIF}
  3363. (*
  3364. ** CAPI3REF: Reset A Prepared Statement Object {F13330}
  3365. **
  3366. ** The sqlite3_reset() function is called to reset a
  3367. ** [prepared statement] object.
  3368. ** back to its initial state, ready to be re-executed.
  3369. ** Any SQL statement variables that had values bound to them using
  3370. ** the [sqlite3_bind_blob | sqlite3_bind_*() API] retain their values.
  3371. ** Use [sqlite3_clear_bindings()] to reset the bindings.
  3372. **
  3373. ** {F11332} The [sqlite3_reset(S)] interface resets the [prepared statement] S
  3374. ** back to the beginning of its program.
  3375. **
  3376. ** {F11334} If the most recent call to [sqlite3_step(S)] for
  3377. ** [prepared statement] S returned [SQLITE_ROW] or [SQLITE_DONE],
  3378. ** or if [sqlite3_step(S)] has never before been called on S,
  3379. ** then [sqlite3_reset(S)] returns [SQLITE_OK].
  3380. **
  3381. ** {F11336} If the most recent call to [sqlite3_step(S)] for
  3382. ** [prepared statement] S indicated an error, then
  3383. ** [sqlite3_reset(S)] returns an appropriate [error code].
  3384. **
  3385. ** {F11338} The [sqlite3_reset(S)] interface does not change the values
  3386. ** of any [sqlite3_bind_blob|bindings] on [prepared statement] S.
  3387. *)
  3388. {$IFDEF S}function{$ELSE}var{$ENDIF}sqlite3_reset{$IFDEF D}: function{$ENDIF}(stmt: psqlite3_stmt): cint; cdecl;{$IFDEF S}external Sqlite3Lib;{$ENDIF}
  3389. (*
  3390. ** CAPI3REF: Create Or Redefine SQL Functions {F16100}
  3391. ** KEYWORDS: {function creation routines}
  3392. **
  3393. ** These two functions (collectively known as
  3394. ** "function creation routines") are used to add SQL functions or aggregates
  3395. ** or to redefine the behavior of existing SQL functions or aggregates. The
  3396. ** difference only between the two is that the second parameter, the
  3397. ** name of the (scalar) function or aggregate, is encoded in UTF-8 for
  3398. ** sqlite3_create_function() and UTF-16 for sqlite3_create_function16().
  3399. **
  3400. ** The first parameter is the [database connection] to which the SQL
  3401. ** function is to be added. If a single
  3402. ** program uses more than one [database connection] cinternally, then SQL
  3403. ** functions must be added individually to each [database connection].
  3404. **
  3405. ** The second parameter is the name of the SQL function to be created
  3406. ** or redefined.
  3407. ** The length of the name is limited to 255 bytes, exclusive of the
  3408. ** zero-terminator. Note that the name length limit is in bytes, not
  3409. ** characters. Any attempt to create a function with a longer name
  3410. ** will result in an SQLITE_ERROR error.
  3411. **
  3412. ** The third parameter is the number of arguments that the SQL function or
  3413. ** aggregate takes. If this parameter is negative, then the SQL function or
  3414. ** aggregate may take any number of arguments.
  3415. **
  3416. ** The fourth parameter, eTextRep, specifies what
  3417. ** [SQLITE_UTF8 | text encoding] this SQL function prefers for
  3418. ** its parameters. Any SQL function implementation should be able to work
  3419. ** work with UTF-8, UTF-16le, or UTF-16be. But some implementations may be
  3420. ** more efficient with one encoding than another. It is allowed to
  3421. ** invoke sqlite3_create_function() or sqlite3_create_function16() multiple
  3422. ** times with the same function but with different values of eTextRep.
  3423. ** When multiple implementations of the same function are available, SQLite
  3424. ** will pick the one that involves the least amount of data conversion.
  3425. ** If there is only a single implementation which does not care what
  3426. ** text encoding is used, then the fourth argument should be
  3427. ** [SQLITE_ANY].
  3428. **
  3429. ** The fifth parameter is an arbitrary pointer. The implementation
  3430. ** of the function can gain access to this pointer using
  3431. ** [sqlite3_user_data()].
  3432. **
  3433. ** The seventh, eighth and ncinth parameters, xFunc, xStep and xFinal, are
  3434. ** pointers to C-language functions that implement the SQL
  3435. ** function or aggregate. A scalar SQL function requires an implementation of
  3436. ** the xFunc callback only, NULL pointers should be passed as the xStep
  3437. ** and xFinal parameters. An aggregate SQL function requires an implementation
  3438. ** of xStep and xFinal and NULL should be passed for xFunc. To delete an
  3439. ** existing SQL function or aggregate, pass NULL for all three function
  3440. ** callback.
  3441. **
  3442. ** It is permitted to register multiple implementations of the same
  3443. ** functions with the same name but with either differing numbers of
  3444. ** arguments or differing perferred text encodings. SQLite will use
  3445. ** the implementation most closely matches the way in which the
  3446. ** SQL function is used.
  3447. **
  3448. ** INVARIANTS:
  3449. **
  3450. ** {F16103} The [sqlite3_create_function16()] interface behaves exactly
  3451. ** like [sqlite3_create_function()] in every way except that it
  3452. ** cinterprets the zFunctionName argument as
  3453. ** zero-terminated UTF-16 native byte order instead of as a
  3454. ** zero-terminated UTF-8.
  3455. **
  3456. ** {F16106} A successful invocation of
  3457. ** the [sqlite3_create_function(D,X,N,E,...)] interface registers
  3458. ** or replaces callback functions in [database connection] D
  3459. ** used to implement the SQL function named X with N parameters
  3460. ** and having a perferred text encoding of E.
  3461. **
  3462. ** {F16109} A successful call to [sqlite3_create_function(D,X,N,E,P,F,S,L)]
  3463. ** replaces the P, F, S, and L values from any prior calls with
  3464. ** the same D, X, N, and E values.
  3465. **
  3466. ** {F16112} The [sqlite3_create_function(D,X,...)] interface fails with
  3467. ** a return code of [SQLITE_ERROR] if the SQL function name X is
  3468. ** longer than 255 bytes exclusive of the zero terminator.
  3469. **
  3470. ** {F16118} Either F must be NULL and S and L are non-NULL or else F
  3471. ** is non-NULL and S and L are NULL, otherwise
  3472. ** [sqlite3_create_function(D,X,N,E,P,F,S,L)] returns [SQLITE_ERROR].
  3473. **
  3474. ** {F16121} The [sqlite3_create_function(D,...)] interface fails with an
  3475. ** error code of [SQLITE_BUSY] if there exist [prepared statements]
  3476. ** associated with the [database connection] D.
  3477. **
  3478. ** {F16124} The [sqlite3_create_function(D,X,N,...)] interface fails with an
  3479. ** error code of [SQLITE_ERROR] if parameter N (specifying the number
  3480. ** of arguments to the SQL function being registered) is less
  3481. ** than -1 or greater than 127.
  3482. **
  3483. ** {F16127} When N is non-negative, the [sqlite3_create_function(D,X,N,...)]
  3484. ** interface causes callbacks to be invoked for the SQL function
  3485. ** named X when the number of arguments to the SQL function is
  3486. ** exactly N.
  3487. **
  3488. ** {F16130} When N is -1, the [sqlite3_create_function(D,X,N,...)]
  3489. ** interface causes callbacks to be invoked for the SQL function
  3490. ** named X with any number of arguments.
  3491. **
  3492. ** {F16133} When calls to [sqlite3_create_function(D,X,N,...)]
  3493. ** specify multiple implementations of the same function X
  3494. ** and when one implementation has N>=0 and the other has N=(-1)
  3495. ** the implementation with a non-zero N is preferred.
  3496. **
  3497. ** {F16136} When calls to [sqlite3_create_function(D,X,N,E,...)]
  3498. ** specify multiple implementations of the same function X with
  3499. ** the same number of arguments N but with different
  3500. ** encodings E, then the implementation where E matches the
  3501. ** database encoding is preferred.
  3502. **
  3503. ** {F16139} For an aggregate SQL function created using
  3504. ** [sqlite3_create_function(D,X,N,E,P,0,S,L)] the finializer
  3505. ** function L will always be invoked exactly once if the
  3506. ** step function S is called one or more times.
  3507. **
  3508. ** {F16142} When SQLite invokes either the xFunc or xStep function of
  3509. ** an application-defined SQL function or aggregate created
  3510. ** by [sqlite3_create_function()] or [sqlite3_create_function16()],
  3511. ** then the array of [sqlite3_value] objects passed as the
  3512. ** third parameter are always [protected sqlite3_value] objects.
  3513. *)
  3514. type
  3515. xFunc = procedure(ctx: psqlite3_context; N: cint; V: ppsqlite3_value); cdecl;
  3516. xStep = procedure(ctx: psqlite3_context; N: cint; V: ppsqlite3_value); cdecl;
  3517. xFinal = procedure(ctx: psqlite3_context); cdecl;
  3518. {$IFDEF S}function{$ELSE}var{$ENDIF}sqlite3_create_function{$IFDEF D}: function{$ENDIF}(
  3519. db: psqlite3;
  3520. zFunctionName: pchar;
  3521. nArg: cint;
  3522. eTextRep: cint;
  3523. pApp: pointer;
  3524. funccb: xFunc;
  3525. stepcb: xStep;
  3526. finalcb: xFinal
  3527. ): cint; cdecl;{$IFDEF S}external Sqlite3Lib;{$ENDIF}
  3528. {$IFDEF S}function{$ELSE}var{$ENDIF}sqlite3_create_function16{$IFDEF D}: function{$ENDIF}(
  3529. db: psqlite3;
  3530. zFunctionName: pwidechar;
  3531. nArg: cint;
  3532. eTextRep: cint;
  3533. pApp: pointer;
  3534. funccb: xFunc;
  3535. stepcb: xStep;
  3536. finalcb: xFinal
  3537. ): cint; cdecl;{$IFDEF S}external Sqlite3Lib;{$ENDIF}
  3538. (*
  3539. ** CAPI3REF: Text Encodings {F10267}
  3540. **
  3541. ** These constant define INTEGER codes that represent the various
  3542. ** text encodings supported by SQLite.
  3543. *)
  3544. const
  3545. SQLITE_UTF8 = 1;
  3546. SQLITE_UTF16LE = 2;
  3547. SQLITE_UTF16BE = 3;
  3548. SQLITE_UTF16 = 4; (* Use native byte order *)
  3549. SQLITE_ANY = 5; (* sqlite3_create_function only *)
  3550. SQLITE_UTF16_ALIGNED = 8; (* sqlite3_create_collation only *)
  3551. (*
  3552. ** CAPI3REF: Obsolete Functions
  3553. **
  3554. ** These functions are all now obsolete. In order to macintain
  3555. ** backwards compatibility with older code; we continue to support
  3556. ** these functions. However; new development projects should avoid
  3557. ** the use of these functions. To help encourage people to avoid
  3558. ** using these functions; we are not going to tell you want they do.
  3559. *)
  3560. {$IFDEF SQLITE_OBSOLETE}
  3561. type
  3562. memory_alarm_cb = function(user: pointer; i64: sqlite3_int64; i: cint): pointer; cdecl;
  3563. {$IFDEF S}function{$ELSE}var{$ENDIF}sqlite3_aggregate_count{$IFDEF D}: function{$ENDIF}(ctx: psqlite3_context): cint; cdecl;{$IFDEF S}external Sqlite3Lib;{$ENDIF}
  3564. {$IFDEF S}function{$ELSE}var{$ENDIF}sqlite3_expired{$IFDEF D}: function{$ENDIF}(stmt: psqlite3_stmt): cint; cdecl;{$IFDEF S}external Sqlite3Lib;{$ENDIF}
  3565. {$IFDEF S}function{$ELSE}var{$ENDIF}sqlite3_transfer_bindings{$IFDEF D}: function{$ENDIF}(stmt: psqlite3_stmt; stmt2: psqlite3_stmt): cint; cdecl;{$IFDEF S}external Sqlite3Lib;{$ENDIF}
  3566. {$IFDEF S}function{$ELSE}var{$ENDIF}sqlite3_global_recover{$IFDEF D}: function{$ENDIF}(): cint; cdecl;{$IFDEF S}external Sqlite3Lib;{$ENDIF}
  3567. {$IFDEF S}procedure{$ELSE}var{$ENDIF}sqlite3_thread_cleanup{$IFDEF D}: procedure{$ENDIF}(); cdecl;{$IFDEF S}external Sqlite3Lib;{$ENDIF}
  3568. {$IFDEF S}function{$ELSE}var{$ENDIF}sqlite3_memory_alarm{$IFDEF D}: function{$ENDIF}(cb: memory_alarm_cb; user: pointer; i64: sqlite3_int64): cint; cdecl;{$IFDEF S}external Sqlite3Lib;{$ENDIF}
  3569. {$ENDIF}
  3570. (*
  3571. ** CAPI3REF: Obtaining SQL Function Parameter Values {F15100}
  3572. **
  3573. ** The C-language implementation of SQL functions and aggregates uses
  3574. ** this set of interface routines to access the parameter values on
  3575. ** the function or aggregate.
  3576. **
  3577. ** The xFunc (for scalar functions) or xStep (for aggregates) parameters
  3578. ** to [sqlite3_create_function()] and [sqlite3_create_function16()]
  3579. ** define callbacks that implement the SQL functions and aggregates.
  3580. ** The 4th parameter to these callbacks is an array of pointers to
  3581. ** [protected sqlite3_value] objects. There is one [sqlite3_value] object for
  3582. ** each parameter to the SQL function. These routines are used to
  3583. ** extract values from the [sqlite3_value] objects.
  3584. **
  3585. ** These routines work only with [protected sqlite3_value] objects.
  3586. ** Any attempt to use these routines on an [unprotected sqlite3_value]
  3587. ** object results in undefined behavior.
  3588. **
  3589. ** These routines work just like the corresponding
  3590. ** [sqlite3_column_blob | sqlite3_column_* routines] except that
  3591. ** these routines take a single [protected sqlite3_value] object pointer
  3592. ** instead of an [stmt: psqlite3_stmt] pointer and an INTEGER column number.
  3593. **
  3594. ** The sqlite3_value_text16() interface extracts a UTF16 string
  3595. ** in the native byte-order of the host machine. The
  3596. ** sqlite3_value_text16be() and sqlite3_value_text16le() interfaces
  3597. ** extract UTF16 strings as big-endian and little-endian respectively.
  3598. **
  3599. ** The sqlite3_value_numeric_type() interface attempts to apply
  3600. ** numeric affinity to the value. This means that an attempt is
  3601. ** made to convert the value to an INTEGER or floating point. If
  3602. ** such a conversion is possible without loss of information (in other
  3603. ** words if the value is a string that looks like a number)
  3604. ** then the conversion is done. Otherwise no conversion occurs. The
  3605. ** [SQLITE_INTEGER | datatype] after conversion is returned.
  3606. **
  3607. ** Please pay particular attention to the fact that the pointer that
  3608. ** is returned from [sqlite3_value_blob()]; [sqlite3_value_text()]; or
  3609. ** [sqlite3_value_text16()] can be invalidated by a subsequent call to
  3610. ** [sqlite3_value_bytes()]; [sqlite3_value_bytes16()]; [sqlite3_value_text()];
  3611. ** or [sqlite3_value_text16()].
  3612. **
  3613. ** These routines must be called from the same thread as
  3614. ** the SQL function that supplied the [sqlite3_value*] parameters.
  3615. **
  3616. **
  3617. ** INVARIANTS:
  3618. **
  3619. ** {F15103} The [sqlite3_value_blob(V)] interface converts the
  3620. ** [protected sqlite3_value] object V cinto a blob and then returns a
  3621. ** pointer to the converted value.
  3622. **
  3623. ** {F15106} The [sqlite3_value_bytes(V)] interface returns the
  3624. ** number of bytes in the blob or string (exclusive of the
  3625. ** zero terminator on the string) that was returned by the
  3626. ** most recent call to [sqlite3_value_blob(V)] or
  3627. ** [sqlite3_value_text(V)].
  3628. **
  3629. ** {F15109} The [sqlite3_value_bytes16(V)] interface returns the
  3630. ** number of bytes in the string (exclusive of the
  3631. ** zero terminator on the string) that was returned by the
  3632. ** most recent call to [sqlite3_value_text16(V)];
  3633. ** [sqlite3_value_text16be(V)]; or [sqlite3_value_text16le(V)].
  3634. **
  3635. ** {F15112} The [sqlite3_value_double(V)] interface converts the
  3636. ** [protected sqlite3_value] object V cinto a floating point value and
  3637. ** returns a copy of that value.
  3638. **
  3639. ** {F15115} The [sqlite3_value_int(V)] interface converts the
  3640. ** [protected sqlite3_value] object V cinto a 64-bit signed INTEGER and
  3641. ** returns the lower 32 bits of that INTEGER.
  3642. **
  3643. ** {F15118} The [sqlite3_value_int64(V)] interface converts the
  3644. ** [protected sqlite3_value] object V cinto a 64-bit signed INTEGER and
  3645. ** returns a copy of that INTEGER.
  3646. **
  3647. ** {F15121} The [sqlite3_value_text(V)] interface converts the
  3648. ** [protected sqlite3_value] object V cinto a zero-terminated UTF-8
  3649. ** string and returns a pointer to that string.
  3650. **
  3651. ** {F15124} The [sqlite3_value_text16(V)] interface converts the
  3652. ** [protected sqlite3_value] object V cinto a zero-terminated 2-byte
  3653. ** aligned UTF-16 native byte order
  3654. ** string and returns a pointer to that string.
  3655. **
  3656. ** {F15127} The [sqlite3_value_text16be(V)] interface converts the
  3657. ** [protected sqlite3_value] object V cinto a zero-terminated 2-byte
  3658. ** aligned UTF-16 big-endian
  3659. ** string and returns a pointer to that string.
  3660. **
  3661. ** {F15130} The [sqlite3_value_text16le(V)] interface converts the
  3662. ** [protected sqlite3_value] object V cinto a zero-terminated 2-byte
  3663. ** aligned UTF-16 little-endian
  3664. ** string and returns a pointer to that string.
  3665. **
  3666. ** {F15133} The [sqlite3_value_type(V)] interface returns
  3667. ** one of [SQLITE_NULL]; [SQLITE_INTEGER]; [SQLITE_FLOAT];
  3668. ** [SQLITE_TEXT]; or [SQLITE_BLOB] as appropriate for
  3669. ** the [sqlite3_value] object V.
  3670. **
  3671. ** {F15136} The [sqlite3_value_numeric_type(V)] interface converts
  3672. ** the [protected sqlite3_value] object V cinto either an INTEGER or
  3673. ** a floating point value if it can do so without loss of
  3674. ** information; and returns one of [SQLITE_NULL];
  3675. ** [SQLITE_INTEGER]; [SQLITE_FLOAT]; [SQLITE_TEXT]; or
  3676. ** [SQLITE_BLOB] as appropriate for
  3677. ** the [protected sqlite3_value] object V after the conversion attempt.
  3678. *)
  3679. {$IFDEF S}function{$ELSE}var{$ENDIF}sqlite3_value_blob{$IFDEF D}: function{$ENDIF}(val: psqlite3_value): pointer; cdecl;{$IFDEF S}external Sqlite3Lib;{$ENDIF}
  3680. {$IFDEF S}function{$ELSE}var{$ENDIF}sqlite3_value_bytes{$IFDEF D}: function{$ENDIF}(val: psqlite3_value): cint; cdecl;{$IFDEF S}external Sqlite3Lib;{$ENDIF}
  3681. {$IFDEF S}function{$ELSE}var{$ENDIF}sqlite3_value_bytes16{$IFDEF D}: function{$ENDIF}(val: psqlite3_value): cint; cdecl;{$IFDEF S}external Sqlite3Lib;{$ENDIF}
  3682. {$IFDEF S}function{$ELSE}var{$ENDIF}sqlite3_value_double{$IFDEF D}: function{$ENDIF}(val: psqlite3_value): cdouble; cdecl;{$IFDEF S}external Sqlite3Lib;{$ENDIF}
  3683. {$IFDEF S}function{$ELSE}var{$ENDIF}sqlite3_value_int{$IFDEF D}: function{$ENDIF}(val: psqlite3_value): cint; cdecl;{$IFDEF S}external Sqlite3Lib;{$ENDIF}
  3684. {$IFDEF S}function{$ELSE}var{$ENDIF}sqlite3_value_int64{$IFDEF D}: function{$ENDIF}(val: psqlite3_value): sqlite3_int64; cdecl;{$IFDEF S}external Sqlite3Lib;{$ENDIF}
  3685. {$IFDEF S}function{$ELSE}var{$ENDIF}sqlite3_value_text{$IFDEF D}: function{$ENDIF}(val: psqlite3_value): pchar; cdecl;{$IFDEF S}external Sqlite3Lib;{$ENDIF}
  3686. {$IFDEF S}function{$ELSE}var{$ENDIF}sqlite3_value_text16{$IFDEF D}: function{$ENDIF}(val: psqlite3_value): pwidechar; cdecl;{$IFDEF S}external Sqlite3Lib;{$ENDIF}
  3687. {$IFDEF S}function{$ELSE}var{$ENDIF}sqlite3_value_text16le{$IFDEF D}: function{$ENDIF}(val: psqlite3_value): pwidechar; cdecl;{$IFDEF S}external Sqlite3Lib;{$ENDIF}
  3688. {$IFDEF S}function{$ELSE}var{$ENDIF}sqlite3_value_text16be{$IFDEF D}: function{$ENDIF}(val: psqlite3_value): pwidechar; cdecl;{$IFDEF S}external Sqlite3Lib;{$ENDIF}
  3689. {$IFDEF S}function{$ELSE}var{$ENDIF}sqlite3_value_type{$IFDEF D}: function{$ENDIF}(val: psqlite3_value): cint; cdecl;{$IFDEF S}external Sqlite3Lib;{$ENDIF}
  3690. {$IFDEF S}function{$ELSE}var{$ENDIF}sqlite3_value_numeric_type{$IFDEF D}: function{$ENDIF}(val: psqlite3_value): cint; cdecl;{$IFDEF S}external Sqlite3Lib;{$ENDIF}
  3691. (*
  3692. ** CAPI3REF: Obtain Aggregate Function Context {F16210}
  3693. **
  3694. ** The implementation of aggregate SQL functions use this routine to allocate
  3695. ** a structure for storing their state.
  3696. ** The first time the sqlite3_aggregate_context() routine is
  3697. ** is called for a particular aggregate; SQLite allocates nBytes of memory
  3698. ** zeros that memory; and returns a pointer to it.
  3699. ** On second and subsequent calls to sqlite3_aggregate_context()
  3700. ** for the same aggregate function index; the same buffer is returned.
  3701. ** The implementation
  3702. ** of the aggregate can use the returned buffer to accumulate data.
  3703. **
  3704. ** SQLite automatically frees the allocated buffer when the aggregate
  3705. ** query concludes.
  3706. **
  3707. ** The first parameter should be a copy of the
  3708. ** [sqlite3_context | SQL function context] that is the first
  3709. ** parameter to the callback routine that implements the aggregate
  3710. ** function.
  3711. **
  3712. ** This routine must be called from the same thread in which
  3713. ** the aggregate SQL function is running.
  3714. **
  3715. ** INVARIANTS:
  3716. **
  3717. ** {F16211} The first invocation of [sqlite3_aggregate_context(C;N)] for
  3718. ** a particular instance of an aggregate function (for a particular
  3719. ** context C) causes SQLite to allocation N bytes of memory;
  3720. ** zero that memory; and return a pointer to the allocationed
  3721. ** memory.
  3722. **
  3723. ** {F16213} If a memory allocation error occurs during
  3724. ** [sqlite3_aggregate_context(C;N)] then the function returns 0.
  3725. **
  3726. ** {F16215} Second and subsequent invocations of
  3727. ** [sqlite3_aggregate_context(C;N)] for the same context pointer C
  3728. ** ignore the N parameter and return a pointer to the same
  3729. ** block of memory returned by the first invocation.
  3730. **
  3731. ** {F16217} The memory allocated by [sqlite3_aggregate_context(C;N)] is
  3732. ** automatically freed on the next call to [sqlite3_reset()]
  3733. ** or [sqlite3_finalize()] for the [prepared statement] containing
  3734. ** the aggregate function associated with context C.
  3735. *)
  3736. {$IFDEF S}function{$ELSE}var{$ENDIF}sqlite3_aggregate_context{$IFDEF D}: function{$ENDIF}(ctx: psqlite3_context; nBytes: cint): pointer; cdecl;{$IFDEF S}external Sqlite3Lib;{$ENDIF}
  3737. (*
  3738. ** CAPI3REF: User Data For Functions {F16240}
  3739. **
  3740. ** The sqlite3_user_data() interface returns a copy of
  3741. ** the pointer that was the pUserData parameter (the 5th parameter)
  3742. ** of the the [sqlite3_create_function()]
  3743. ** and [sqlite3_create_function16()] routines that originally
  3744. ** registered the application defined function. {END}
  3745. **
  3746. ** This routine must be called from the same thread in which
  3747. ** the application-defined function is running.
  3748. **
  3749. ** INVARIANTS:
  3750. **
  3751. ** {F16243} The [sqlite3_user_data(C)] interface returns a copy of the
  3752. ** P pointer from the [sqlite3_create_function(D;X;N;E;P;F;S;L)]
  3753. ** or [sqlite3_create_function16(D;X;N;E;P;F;S;L)] call that
  3754. ** registered the SQL function associated with
  3755. ** [sqlite3_context] C.
  3756. *)
  3757. {$IFDEF S}function{$ELSE}var{$ENDIF}sqlite3_user_data{$IFDEF D}: function{$ENDIF}(ctx: psqlite3_context): pointer; cdecl;{$IFDEF S}external Sqlite3Lib;{$ENDIF}
  3758. (*
  3759. ** CAPI3REF: Database Connection For Functions {F16250}
  3760. **
  3761. ** The sqlite3_context_db_handle() interface returns a copy of
  3762. ** the pointer to the [database connection] (the 1st parameter)
  3763. ** of the the [sqlite3_create_function()]
  3764. ** and [sqlite3_create_function16()] routines that originally
  3765. ** registered the application defined function.
  3766. **
  3767. ** INVARIANTS:
  3768. **
  3769. ** {F16253} The [sqlite3_context_db_handle(C)] interface returns a copy of the
  3770. ** D pointer from the [sqlite3_create_function(D;X;N;E;P;F;S;L)]
  3771. ** or [sqlite3_create_function16(D;X;N;E;P;F;S;L)] call that
  3772. ** registered the SQL function associated with
  3773. ** [sqlite3_context] C.
  3774. *)
  3775. {$IFDEF S}function{$ELSE}var{$ENDIF}sqlite3_context_db_handle{$IFDEF D}: function{$ENDIF}(ctx: psqlite3_context): psqlite3; cdecl;{$IFDEF S}external Sqlite3Lib;{$ENDIF}
  3776. (*
  3777. ** CAPI3REF: Function Auxiliary Data {F16270}
  3778. **
  3779. ** The following two functions may be used by scalar SQL functions to
  3780. ** associate meta-data with argument values. If the same value is passed to
  3781. ** multiple invocations of the same SQL function during query execution; under
  3782. ** some circumstances the associated meta-data may be preserved. This may
  3783. ** be used; for example; to add a regular-expression matching scalar
  3784. ** function. The compiled version of the regular expression is stored as
  3785. ** meta-data associated with the SQL value passed as the regular expression
  3786. ** pattern. The compiled regular expression can be reused on multiple
  3787. ** invocations of the same function so that the original pattern string
  3788. ** does not need to be recompiled on each invocation.
  3789. **
  3790. ** The sqlite3_get_auxdata() interface returns a pointer to the meta-data
  3791. ** associated by the sqlite3_set_auxdata() function with the Nth argument
  3792. ** value to the application-defined function.
  3793. ** If no meta-data has been ever been set for the Nth
  3794. ** argument of the function; or if the cooresponding function parameter
  3795. ** has changed since the meta-data was set; then sqlite3_get_auxdata()
  3796. ** returns a NULL pointer.
  3797. **
  3798. ** The sqlite3_set_auxdata() interface saves the meta-data
  3799. ** pointed to by its 3rd parameter as the meta-data for the N-th
  3800. ** argument of the application-defined function. Subsequent
  3801. ** calls to sqlite3_get_auxdata() might return this data; if it has
  3802. ** not been destroyed.
  3803. ** If it is not NULL; SQLite will invoke the destructor
  3804. ** function given by the 4th parameter to sqlite3_set_auxdata() on
  3805. ** the meta-data when the corresponding function parameter changes
  3806. ** or when the SQL statement completes; whichever comes first.
  3807. **
  3808. ** SQLite is free to call the destructor and drop meta-data on
  3809. ** any parameter of any function at any time. The only guarantee
  3810. ** is that the destructor will be called before the metadata is
  3811. ** dropped.
  3812. **
  3813. ** In practice; meta-data is preserved between function calls for
  3814. ** expressions that are constant at compile time. This includes literal
  3815. ** values and SQL variables.
  3816. **
  3817. ** These routines must be called from the same thread in which
  3818. ** the SQL function is running.
  3819. **
  3820. ** INVARIANTS:
  3821. **
  3822. ** {F16272} The [sqlite3_get_auxdata(C;N)] interface returns a pointer
  3823. ** to metadata associated with the Nth parameter of the SQL function
  3824. ** whose context is C; or NULL if there is no metadata associated
  3825. ** with that parameter.
  3826. **
  3827. ** {F16274} The [sqlite3_set_auxdata(C;N;P;D)] interface assigns a metadata
  3828. ** pointer P to the Nth parameter of the SQL function with context
  3829. ** C.
  3830. **
  3831. ** {F16276} SQLite will invoke the destructor D with a single argument
  3832. ** which is the metadata pointer P following a call to
  3833. ** [sqlite3_set_auxdata(C;N;P;D)] when SQLite ceases to hold
  3834. ** the metadata.
  3835. **
  3836. ** {F16277} SQLite ceases to hold metadata for an SQL function parameter
  3837. ** when the value of that parameter changes.
  3838. **
  3839. ** {F16278} When [sqlite3_set_auxdata(C;N;P;D)] is invoked; the destructor
  3840. ** is called for any prior metadata associated with the same function
  3841. ** context C and parameter N.
  3842. **
  3843. ** {F16279} SQLite will call destructors for any metadata it is holding
  3844. ** in a particular [prepared statement] S when either
  3845. ** [sqlite3_reset(S)] or [sqlite3_finalize(S)] is called.
  3846. *)
  3847. type
  3848. set_auxdata_cb = function(p: pointer): pointer; cdecl;
  3849. {$IFDEF S}function{$ELSE}var{$ENDIF}sqlite3_get_auxdata{$IFDEF D}: function{$ENDIF}(ctx: psqlite3_context; N: cint): pointer; cdecl;{$IFDEF S}external Sqlite3Lib;{$ENDIF}
  3850. {$IFDEF S}procedure{$ELSE}var{$ENDIF}sqlite3_set_auxdata{$IFDEF D}: procedure{$ENDIF}(ctx: psqlite3_context; N: cint; P: pointer; cb: set_auxdata_cb); cdecl;{$IFDEF S}external Sqlite3Lib;{$ENDIF}
  3851. (*
  3852. ** CAPI3REF: Setting The Result Of An SQL Function {F16400}
  3853. **
  3854. ** These routines are used by the xFunc or xFinal callbacks that
  3855. ** implement SQL functions and aggregates. See
  3856. ** [sqlite3_create_function()] and [sqlite3_create_function16()]
  3857. ** for additional information.
  3858. **
  3859. ** These functions work very much like the
  3860. ** [sqlite3_bind_blob | sqlite3_bind_*] family of functions used
  3861. ** to bind values to host parameters in prepared statements.
  3862. ** Refer to the
  3863. ** [sqlite3_bind_blob | sqlite3_bind_* documentation] for
  3864. ** additional information.
  3865. **
  3866. ** The sqlite3_result_blob() interface sets the result from
  3867. ** an application defined function to be the BLOB whose content is pointed
  3868. ** to by the second parameter and which is N bytes long where N is the
  3869. ** third parameter.
  3870. ** The sqlite3_result_zeroblob() inerfaces set the result of
  3871. ** the application defined function to be a BLOB containing all zero
  3872. ** bytes and N bytes in size; where N is the value of the 2nd parameter.
  3873. **
  3874. ** The sqlite3_result_double() interface sets the result from
  3875. ** an application defined function to be a floating point value specified
  3876. ** by its 2nd argument.
  3877. **
  3878. ** The sqlite3_result_error() and sqlite3_result_error16() functions
  3879. ** cause the implemented SQL function to throw an exception.
  3880. ** SQLite uses the string pointed to by the
  3881. ** 2nd parameter of sqlite3_result_error() or sqlite3_result_error16()
  3882. ** as the text of an error message. SQLite cinterprets the error
  3883. ** message string from sqlite3_result_error() as UTF8. SQLite
  3884. ** cinterprets the string from sqlite3_result_error16() as UTF16 in native
  3885. ** byte order. If the third parameter to sqlite3_result_error()
  3886. ** or sqlite3_result_error16() is negative then SQLite takes as the error
  3887. ** message all text up through the first zero character.
  3888. ** If the third parameter to sqlite3_result_error() or
  3889. ** sqlite3_result_error16() is non-negative then SQLite takes that many
  3890. ** bytes (not characters) from the 2nd parameter as the error message.
  3891. ** The sqlite3_result_error() and sqlite3_result_error16()
  3892. ** routines make a copy private copy of the error message text before
  3893. ** they return. Hence; the calling function can deallocate or
  3894. ** modify the text after they return without harm.
  3895. ** The sqlite3_result_error_code() function changes the error code
  3896. ** returned by SQLite as a result of an error in a function. By default;
  3897. ** the error code is SQLITE_ERROR. A subsequent call to sqlite3_result_error()
  3898. ** or sqlite3_result_error16() resets the error code to SQLITE_ERROR.
  3899. **
  3900. ** The sqlite3_result_toobig() interface causes SQLite
  3901. ** to throw an error indicating that a string or BLOB is to long
  3902. ** to represent. The sqlite3_result_nomem() interface
  3903. ** causes SQLite to throw an exception indicating that the a
  3904. ** memory allocation failed.
  3905. **
  3906. ** The sqlite3_result_cint() interface sets the return value
  3907. ** of the application-defined function to be the 32-bit signed INTEGER
  3908. ** value given in the 2nd argument.
  3909. ** The sqlite3_result_cint64() interface sets the return value
  3910. ** of the application-defined function to be the 64-bit signed INTEGER
  3911. ** value given in the 2nd argument.
  3912. **
  3913. ** The sqlite3_result_null() interface sets the return value
  3914. ** of the application-defined function to be NULL.
  3915. **
  3916. ** The sqlite3_result_text(); sqlite3_result_text16();
  3917. ** sqlite3_result_text16le(); and sqlite3_result_text16be() interfaces
  3918. ** set the return value of the application-defined function to be
  3919. ** a text string which is represented as UTF-8; UTF-16 native byte order;
  3920. ** UTF-16 little endian; or UTF-16 big endian; respectively.
  3921. ** SQLite takes the text result from the application from
  3922. ** the 2nd parameter of the sqlite3_result_text* interfaces.
  3923. ** If the 3rd parameter to the sqlite3_result_text* interfaces
  3924. ** is negative; then SQLite takes result text from the 2nd parameter
  3925. ** through the first zero character.
  3926. ** If the 3rd parameter to the sqlite3_result_text* interfaces
  3927. ** is non-negative; then as many bytes (not characters) of the text
  3928. ** pointed to by the 2nd parameter are taken as the application-defined
  3929. ** function result.
  3930. ** If the 4th parameter to the sqlite3_result_text* interfaces
  3931. ** or sqlite3_result_blob is a non-NULL pointer; then SQLite calls that
  3932. ** function as the destructor on the text or blob result when it has
  3933. ** finished using that result.
  3934. ** If the 4th parameter to the sqlite3_result_text* interfaces
  3935. ** or sqlite3_result_blob is the special constant SQLITE_STATIC; then
  3936. ** SQLite assumes that the text or blob result is constant space and
  3937. ** does not copy the space or call a destructor when it has
  3938. ** finished using that result.
  3939. ** If the 4th parameter to the sqlite3_result_text* interfaces
  3940. ** or sqlite3_result_blob is the special constant SQLITE_TRANSIENT
  3941. ** then SQLite makes a copy of the result cinto space obtained from
  3942. ** from [sqlite3_malloc()] before it returns.
  3943. **
  3944. ** The sqlite3_result_value() interface sets the result of
  3945. ** the application-defined function to be a copy the
  3946. ** [unprotected sqlite3_value] object specified by the 2nd parameter. The
  3947. ** sqlite3_result_value() interface makes a copy of the [sqlite3_value]
  3948. ** so that [sqlite3_value] specified in the parameter may change or
  3949. ** be deallocated after sqlite3_result_value() returns without harm.
  3950. ** A [protected sqlite3_value] object may always be used where an
  3951. ** [unprotected sqlite3_value] object is required; so either
  3952. ** kind of [sqlite3_value] object can be used with this interface.
  3953. **
  3954. ** If these routines are called from within the different thread
  3955. ** than the one containing the application-defined function that recieved
  3956. ** the [sqlite3_context] pointer; the results are undefined.
  3957. **
  3958. ** INVARIANTS:
  3959. **
  3960. ** {F16403} The default return value from any SQL function is NULL.
  3961. **
  3962. ** {F16406} The [sqlite3_result_blob(C;V;N;D)] interface changes the
  3963. ** return value of function C to be a blob that is N bytes
  3964. ** in length and with content pointed to by V.
  3965. **
  3966. ** {F16409} The [sqlite3_result_double(C;V)] interface changes the
  3967. ** return value of function C to be the floating point value V.
  3968. **
  3969. ** {F16412} The [sqlite3_result_error(C;V;N)] interface changes the return
  3970. ** value of function C to be an exception with error code
  3971. ** [SQLITE_ERROR] and a UTF8 error message copied from V up to the
  3972. ** first zero byte or until N bytes are read if N is positive.
  3973. **
  3974. ** {F16415} The [sqlite3_result_error16(C;V;N)] interface changes the return
  3975. ** value of function C to be an exception with error code
  3976. ** [SQLITE_ERROR] and a UTF16 native byte order error message
  3977. ** copied from V up to the first zero terminator or until N bytes
  3978. ** are read if N is positive.
  3979. **
  3980. ** {F16418} The [sqlite3_result_error_toobig(C)] interface changes the return
  3981. ** value of the function C to be an exception with error code
  3982. ** [SQLITE_TOOBIG] and an appropriate error message.
  3983. **
  3984. ** {F16421} The [sqlite3_result_error_nomem(C)] interface changes the return
  3985. ** value of the function C to be an exception with error code
  3986. ** [SQLITE_NOMEM] and an appropriate error message.
  3987. **
  3988. ** {F16424} The [sqlite3_result_error_code(C;E)] interface changes the return
  3989. ** value of the function C to be an exception with error code E.
  3990. ** The error message text is unchanged.
  3991. **
  3992. ** {F16427} The [sqlite3_result_cint(C;V)] interface changes the
  3993. ** return value of function C to be the 32-bit INTEGER value V.
  3994. **
  3995. ** {F16430} The [sqlite3_result_cint64(C;V)] interface changes the
  3996. ** return value of function C to be the 64-bit INTEGER value V.
  3997. **
  3998. ** {F16433} The [sqlite3_result_null(C)] interface changes the
  3999. ** return value of function C to be NULL.
  4000. **
  4001. ** {F16436} The [sqlite3_result_text(C;V;N;D)] interface changes the
  4002. ** return value of function C to be the UTF8 string
  4003. ** V up to the first zero if N is negative
  4004. ** or the first N bytes of V if N is non-negative.
  4005. **
  4006. ** {F16439} The [sqlite3_result_text16(C;V;N;D)] interface changes the
  4007. ** return value of function C to be the UTF16 native byte order
  4008. ** string V up to the first zero if N is
  4009. ** negative or the first N bytes of V if N is non-negative.
  4010. **
  4011. ** {F16442} The [sqlite3_result_text16be(C;V;N;D)] interface changes the
  4012. ** return value of function C to be the UTF16 big-endian
  4013. ** string V up to the first zero if N is
  4014. ** is negative or the first N bytes or V if N is non-negative.
  4015. **
  4016. ** {F16445} The [sqlite3_result_text16le(C;V;N;D)] interface changes the
  4017. ** return value of function C to be the UTF16 little-endian
  4018. ** string V up to the first zero if N is
  4019. ** negative or the first N bytes of V if N is non-negative.
  4020. **
  4021. ** {F16448} The [sqlite3_result_value(C;V)] interface changes the
  4022. ** return value of function C to be [unprotected sqlite3_value]
  4023. ** object V.
  4024. **
  4025. ** {F16451} The [sqlite3_result_zeroblob(C;N)] interface changes the
  4026. ** return value of function C to be an N-byte blob of all zeros.
  4027. **
  4028. ** {F16454} The [sqlite3_result_error()] and [sqlite3_result_error16()]
  4029. ** interfaces make a copy of their error message strings before
  4030. ** returning.
  4031. **
  4032. ** {F16457} If the D destructor parameter to [sqlite3_result_blob(C;V;N;D)];
  4033. ** [sqlite3_result_text(C;V;N;D)]; [sqlite3_result_text16(C;V;N;D)];
  4034. ** [sqlite3_result_text16be(C;V;N;D)]; or
  4035. ** [sqlite3_result_text16le(C;V;N;D)] is the constant [SQLITE_STATIC]
  4036. ** then no destructor is ever called on the pointer V and SQLite
  4037. ** assumes that V is immutable.
  4038. **
  4039. ** {F16460} If the D destructor parameter to [sqlite3_result_blob(C;V;N;D)];
  4040. ** [sqlite3_result_text(C;V;N;D)]; [sqlite3_result_text16(C;V;N;D)];
  4041. ** [sqlite3_result_text16be(C;V;N;D)]; or
  4042. ** [sqlite3_result_text16le(C;V;N;D)] is the constant
  4043. ** [SQLITE_TRANSIENT] then the interfaces makes a copy of the
  4044. ** content of V and retains the copy.
  4045. **
  4046. ** {F16463} If the D destructor parameter to [sqlite3_result_blob(C;V;N;D)];
  4047. ** [sqlite3_result_text(C;V;N;D)]; [sqlite3_result_text16(C;V;N;D)];
  4048. ** [sqlite3_result_text16be(C;V;N;D)]; or
  4049. ** [sqlite3_result_text16le(C;V;N;D)] is some value other than
  4050. ** the constants [SQLITE_STATIC] and [SQLITE_TRANSIENT] then
  4051. ** SQLite will invoke the destructor D with V as its only argument
  4052. ** when it has finished with the V value.
  4053. *)
  4054. {$IFDEF S}procedure{$ELSE}var{$ENDIF}sqlite3_result_blob{$IFDEF D}: procedure{$ENDIF}(ctx: psqlite3_context; V: pointer; N: cint; D: sqlite3_destructor_type); cdecl;{$IFDEF S}external Sqlite3Lib;{$ENDIF}
  4055. {$IFDEF S}procedure{$ELSE}var{$ENDIF}sqlite3_result_double{$IFDEF D}: procedure{$ENDIF}(ctx: psqlite3_context; V: cdouble); cdecl;{$IFDEF S}external Sqlite3Lib;{$ENDIF}
  4056. {$IFDEF S}procedure{$ELSE}var{$ENDIF}sqlite3_result_error{$IFDEF D}: procedure{$ENDIF}(ctx: psqlite3_context; V: pchar; N: cint); cdecl;{$IFDEF S}external Sqlite3Lib;{$ENDIF}
  4057. {$IFDEF S}procedure{$ELSE}var{$ENDIF}sqlite3_result_error16{$IFDEF D}: procedure{$ENDIF}(ctx: psqlite3_context; V: pwidechar; N: cint); cdecl;{$IFDEF S}external Sqlite3Lib;{$ENDIF}
  4058. {$IFDEF S}procedure{$ELSE}var{$ENDIF}sqlite3_result_error_toobig{$IFDEF D}: procedure{$ENDIF}(ctx: psqlite3_context); cdecl;{$IFDEF S}external Sqlite3Lib;{$ENDIF}
  4059. {$IFDEF S}procedure{$ELSE}var{$ENDIF}sqlite3_result_error_nomem{$IFDEF D}: procedure{$ENDIF}(ctx: psqlite3_context); cdecl;{$IFDEF S}external Sqlite3Lib;{$ENDIF}
  4060. {$IFDEF S}procedure{$ELSE}var{$ENDIF}sqlite3_result_error_code{$IFDEF D}: procedure{$ENDIF}(ctx: psqlite3_context; V: cint); cdecl;{$IFDEF S}external Sqlite3Lib;{$ENDIF}
  4061. {$IFDEF S}procedure{$ELSE}var{$ENDIF}sqlite3_result_cint{$IFDEF D}: procedure{$ENDIF}(ctx: psqlite3_context; V: cint); cdecl;{$IFDEF S}external Sqlite3Lib;{$ENDIF}
  4062. {$IFDEF S}procedure{$ELSE}var{$ENDIF}sqlite3_result_cint64{$IFDEF D}: procedure{$ENDIF}(ctx: psqlite3_context; V: sqlite3_int64); cdecl;{$IFDEF S}external Sqlite3Lib;{$ENDIF}
  4063. {$IFDEF S}procedure{$ELSE}var{$ENDIF}sqlite3_result_null{$IFDEF D}: procedure{$ENDIF}(ctx: psqlite3_context); cdecl;{$IFDEF S}external Sqlite3Lib;{$ENDIF}
  4064. {$IFDEF S}procedure{$ELSE}var{$ENDIF}sqlite3_result_text{$IFDEF D}: procedure{$ENDIF}(ctx: psqlite3_context; V: pchar; N: cint; D: sqlite3_destructor_type); cdecl;{$IFDEF S}external Sqlite3Lib;{$ENDIF}
  4065. {$IFDEF S}procedure{$ELSE}var{$ENDIF}sqlite3_result_text16{$IFDEF D}: procedure{$ENDIF}(ctx: psqlite3_context; V: pwidechar; N: cint; D: sqlite3_destructor_type); cdecl;{$IFDEF S}external Sqlite3Lib;{$ENDIF}
  4066. {$IFDEF S}procedure{$ELSE}var{$ENDIF}sqlite3_result_text16le{$IFDEF D}: procedure{$ENDIF}(ctx: psqlite3_context; V: pwidechar; N: cint; D: sqlite3_destructor_type); cdecl;{$IFDEF S}external Sqlite3Lib;{$ENDIF}
  4067. {$IFDEF S}procedure{$ELSE}var{$ENDIF}sqlite3_result_text16be{$IFDEF D}: procedure{$ENDIF}(ctx: psqlite3_context; V: pwidechar; N: cint; D: sqlite3_destructor_type); cdecl;{$IFDEF S}external Sqlite3Lib;{$ENDIF}
  4068. {$IFDEF S}procedure{$ELSE}var{$ENDIF}sqlite3_result_value{$IFDEF D}: procedure{$ENDIF}(ctx: psqlite3_context; V: psqlite3_value); cdecl;{$IFDEF S}external Sqlite3Lib;{$ENDIF}
  4069. {$IFDEF S}procedure{$ELSE}var{$ENDIF}sqlite3_result_zeroblob{$IFDEF D}: procedure{$ENDIF}(ctx: psqlite3_context; V: cint); cdecl;{$IFDEF S}external Sqlite3Lib;{$ENDIF}
  4070. (*
  4071. ** CAPI3REF: Define New Collating Sequences {F16600}
  4072. **
  4073. ** These functions are used to add new collation sequences to the
  4074. ** [db: psqlite3] handle specified as the first argument.
  4075. **
  4076. ** The name of the new collation sequence is specified as a UTF-8 string
  4077. ** for sqlite3_create_collation() and sqlite3_create_collation_v2()
  4078. ** and a UTF-16 string for sqlite3_create_collation16(). In all cases
  4079. ** the name is passed as the second function argument.
  4080. **
  4081. ** The third argument may be one of the constants [SQLITE_UTF8];
  4082. ** [SQLITE_UTF16LE] or [SQLITE_UTF16BE]; indicating that the user-supplied
  4083. ** routine expects to be passed pointers to strings encoded using UTF-8;
  4084. ** UTF-16 little-endian or UTF-16 big-endian respectively. The
  4085. ** third argument might also be [SQLITE_UTF16_ALIGNED] to indicate that
  4086. ** the routine expects pointers to 16-bit word aligned strings
  4087. ** of UTF16 in the native byte order of the host computer.
  4088. **
  4089. ** A pointer to the user supplied routine must be passed as the fifth
  4090. ** argument. If it is NULL; this is the same as deleting the collation
  4091. ** sequence (so that SQLite cannot call it anymore).
  4092. ** Each time the application
  4093. ** supplied function is invoked; it is passed a copy of the void* passed as
  4094. ** the fourth argument to sqlite3_create_collation() or
  4095. ** sqlite3_create_collation16() as its first parameter.
  4096. **
  4097. ** The remaining arguments to the application-supplied routine are two strings;
  4098. ** each represented by a (length; data) pair and encoded in the encoding
  4099. ** that was passed as the third argument when the collation sequence was
  4100. ** registered. {END} The application defined collation routine should
  4101. ** return negative; zero or positive if
  4102. ** the first string is less than; equal to; or greater than the second
  4103. ** string. i.e. (STRING1 - STRING2).
  4104. **
  4105. ** The sqlite3_create_collation_v2() works like sqlite3_create_collation()
  4106. ** excapt that it takes an extra argument which is a destructor for
  4107. ** the collation. The destructor is called when the collation is
  4108. ** destroyed and is passed a copy of the fourth parameter void* pointer
  4109. ** of the sqlite3_create_collation_v2().
  4110. ** Collations are destroyed when
  4111. ** they are overridden by later calls to the collation creation functions
  4112. ** or when the [db: psqlite3] database handle is closed using [sqlite3_close()].
  4113. **
  4114. ** INVARIANTS:
  4115. **
  4116. ** {F16603} A successful call to the
  4117. ** [sqlite3_create_collation_v2(B;X;E;P;F;D)] interface
  4118. ** registers function F as the comparison function used to
  4119. ** implement collation X on [database connection] B for
  4120. ** databases having encoding E.
  4121. **
  4122. ** {F16604} SQLite understands the X parameter to
  4123. ** [sqlite3_create_collation_v2(B;X;E;P;F;D)] as a zero-terminated
  4124. ** UTF-8 string in which case is ignored for ASCII characters and
  4125. ** is significant for non-ASCII characters.
  4126. **
  4127. ** {F16606} Successive calls to [sqlite3_create_collation_v2(B;X;E;P;F;D)]
  4128. ** with the same values for B; X; and E; override prior values
  4129. ** of P; F; and D.
  4130. **
  4131. ** {F16609} The destructor D in [sqlite3_create_collation_v2(B;X;E;P;F;D)]
  4132. ** is not NULL then it is called with argument P when the
  4133. ** collating function is dropped by SQLite.
  4134. **
  4135. ** {F16612} A collating function is dropped when it is overloaded.
  4136. **
  4137. ** {F16615} A collating function is dropped when the database connection
  4138. ** is closed using [sqlite3_close()].
  4139. **
  4140. ** {F16618} The pointer P in [sqlite3_create_collation_v2(B;X;E;P;F;D)]
  4141. ** is passed through as the first parameter to the comparison
  4142. ** function F for all subsequent invocations of F.
  4143. **
  4144. ** {F16621} A call to [sqlite3_create_collation(B;X;E;P;F)] is exactly
  4145. ** the same as a call to [sqlite3_create_collation_v2()] with
  4146. ** the same parameters and a NULL destructor.
  4147. **
  4148. ** {F16624} Following a [sqlite3_create_collation_v2(B;X;E;P;F;D)];
  4149. ** SQLite uses the comparison function F for all text comparison
  4150. ** operations on [database connection] B on text values that
  4151. ** use the collating sequence name X.
  4152. **
  4153. ** {F16627} The [sqlite3_create_collation16(B;X;E;P;F)] works the same
  4154. ** as [sqlite3_create_collation(B;X;E;P;F)] except that the
  4155. ** collation name X is understood as UTF-16 in native byte order
  4156. ** instead of UTF-8.
  4157. **
  4158. ** {F16630} When multiple comparison functions are available for the same
  4159. ** collating sequence; SQLite chooses the one whose text encoding
  4160. ** requires the least amount of conversion from the default
  4161. ** text encoding of the database.
  4162. *)
  4163. type
  4164. xCompare = function(user: pointer; A: cint; B: pointer; C: cint; D: pointer): cint; cdecl;
  4165. xDestroy = sqlite3_destructor_type;
  4166. {$IFDEF S}function{$ELSE}var{$ENDIF}sqlite3_create_collation{$IFDEF D}: function{$ENDIF}(
  4167. db: psqlite3;
  4168. zName: pchar;
  4169. eTextRep: cint;
  4170. user: pointer;
  4171. xcomparecb: xCompare
  4172. ): cint; cdecl;{$IFDEF S}external Sqlite3Lib;{$ENDIF}
  4173. {$IFDEF S}function{$ELSE}var{$ENDIF}sqlite3_create_collation_v2{$IFDEF D}: function{$ENDIF}(
  4174. db: psqlite3;
  4175. zName: pchar;
  4176. eTextRep: cint;
  4177. user: pointer;
  4178. xcomparecb: xCompare;
  4179. xdestroycb: xDestroy
  4180. ): cint; cdecl;{$IFDEF S}external Sqlite3Lib;{$ENDIF}
  4181. {$IFDEF S}function{$ELSE}var{$ENDIF}sqlite3_create_collation16{$IFDEF D}: function{$ENDIF}(
  4182. db: psqlite3;
  4183. zName: pwidechar;
  4184. eTextRep: cint;
  4185. user: pointer;
  4186. xcomparecb: xCompare
  4187. ): cint; cdecl;{$IFDEF S}external Sqlite3Lib;{$ENDIF}
  4188. (*
  4189. ** CAPI3REF: Collation Needed Callbacks {F16700}
  4190. **
  4191. ** To avoid having to register all collation sequences before a database
  4192. ** can be used; a single callback function may be registered with the
  4193. ** database handle to be called whenever an undefined collation sequence is
  4194. ** required.
  4195. **
  4196. ** If the function is registered using the sqlite3_collation_needed() API;
  4197. ** then it is passed the names of undefined collation sequences as strings
  4198. ** encoded in UTF-8. {F16703} If sqlite3_collation_needed16() is used; the names
  4199. ** are passed as UTF-16 in machine native byte order. A call to either
  4200. ** function replaces any existing callback.
  4201. **
  4202. ** When the callback is invoked; the first argument passed is a copy
  4203. ** of the second argument to sqlite3_collation_needed() or
  4204. ** sqlite3_collation_needed16(). The second argument is the database
  4205. ** handle. The third argument is one of [SQLITE_UTF8];
  4206. ** [SQLITE_UTF16BE]; or [SQLITE_UTF16LE]; indicating the most
  4207. ** desirable form of the collation sequence function required.
  4208. ** The fourth parameter is the name of the
  4209. ** required collation sequence.
  4210. **
  4211. ** The callback function should register the desired collation using
  4212. ** [sqlite3_create_collation()]; [sqlite3_create_collation16()]; or
  4213. ** [sqlite3_create_collation_v2()].
  4214. **
  4215. ** INVARIANTS:
  4216. **
  4217. ** {F16702} A successful call to [sqlite3_collation_needed(D;P;F)]
  4218. ** or [sqlite3_collation_needed16(D;P;F)] causes
  4219. ** the [database connection] D to invoke callback F with first
  4220. ** parameter P whenever it needs a comparison function for a
  4221. ** collating sequence that it does not know about.
  4222. **
  4223. ** {F16704} Each successful call to [sqlite3_collation_needed()] or
  4224. ** [sqlite3_collation_needed16()] overrides the callback registered
  4225. ** on the same [database connection] by prior calls to either
  4226. ** interface.
  4227. **
  4228. ** {F16706} The name of the requested collating function passed in the
  4229. ** 4th parameter to the callback is in UTF-8 if the callback
  4230. ** was registered using [sqlite3_collation_needed()] and
  4231. ** is in UTF-16 native byte order if the callback was
  4232. ** registered using [sqlite3_collation_needed16()].
  4233. **
  4234. **
  4235. *)
  4236. type
  4237. collation_needed_cb = function(user: pointer; db: psqlite3; eTextRep: cint; s: pchar): pointer; cdecl;
  4238. {$IFDEF S}function{$ELSE}var{$ENDIF}sqlite3_collation_needed{$IFDEF D}: function{$ENDIF}(
  4239. db: psqlite3;
  4240. user: pointer;
  4241. cb: collation_needed_cb
  4242. ): cint; cdecl;{$IFDEF S}external Sqlite3Lib;{$ENDIF}
  4243. {$IFDEF S}function{$ELSE}var{$ENDIF}sqlite3_collation_needed16{$IFDEF D}: function{$ENDIF}(
  4244. db: psqlite3;
  4245. user: pointer;
  4246. cb: collation_needed_cb
  4247. ): cint; cdecl;{$IFDEF S}external Sqlite3Lib;{$ENDIF}
  4248. (*
  4249. ** Specify the key for an encrypted database. This routine should be
  4250. ** called right after sqlite3_open().
  4251. **
  4252. ** The code to implement this API is not available in the public release
  4253. ** of SQLite.
  4254. *)
  4255. {$IFDEF S}function{$ELSE}var{$ENDIF}sqlite3_key{$IFDEF D}: function{$ENDIF}(
  4256. db: psqlite3; (* Database to be rekeyed *)
  4257. pKey: pointer; nKey: cint (* The key *)
  4258. ): cint; cdecl;{$IFDEF S}external Sqlite3Lib;{$ENDIF}
  4259. (*
  4260. ** Change the key on an open database. If the current database is not
  4261. ** encrypted; this routine will encrypt it. If pNew==0 or nNew==0; the
  4262. ** database is decrypted.
  4263. **
  4264. ** The code to implement this API is not available in the public release
  4265. ** of SQLite.
  4266. *)
  4267. {$IFDEF S}function{$ELSE}var{$ENDIF}sqlite3_rekey{$IFDEF D}: function{$ENDIF}(
  4268. db: psqlite3; (* Database to be rekeyed *)
  4269. pKey: pointer; nKey: cint (* The new key *)
  4270. ): cint; cdecl;{$IFDEF S}external Sqlite3Lib;{$ENDIF}
  4271. (*
  4272. ** CAPI3REF: Suspend Execution For A Short Time {F10530}
  4273. **
  4274. ** The sqlite3_sleep() function
  4275. ** causes the current thread to suspend execution
  4276. ** for at least a number of milliseconds specified in its parameter.
  4277. **
  4278. ** If the operating system does not support sleep requests with
  4279. ** millisecond time resolution; then the time will be rounded up to
  4280. ** the nearest second. The number of milliseconds of sleep actually
  4281. ** requested from the operating system is returned.
  4282. **
  4283. ** SQLite implements this interface by calling the xSleep()
  4284. ** method of the default [sqlite3_vfs] object.
  4285. **
  4286. ** INVARIANTS:
  4287. **
  4288. ** {F10533} The [sqlite3_sleep(M)] interface invokes the xSleep
  4289. ** method of the default [sqlite3_vfs|VFS] in order to
  4290. ** suspend execution of the current thread for at least
  4291. ** M milliseconds.
  4292. **
  4293. ** {F10536} The [sqlite3_sleep(M)] interface returns the number of
  4294. ** milliseconds of sleep actually requested of the operating
  4295. ** system; which might be larger than the parameter M.
  4296. *)
  4297. {$IFDEF S}function{$ELSE}var{$ENDIF}sqlite3_sleep{$IFDEF D}: function{$ENDIF}(M: cint): cint; cdecl;{$IFDEF S}external Sqlite3Lib;{$ENDIF}
  4298. (*
  4299. ** CAPI3REF: Name Of The Folder Holding Temporary Files {F10310}
  4300. **
  4301. ** If this global variable is made to point to a string which is
  4302. ** the name of a folder (a.ka. directory); then all temporary files
  4303. ** created by SQLite will be placed in that directory. If this variable
  4304. ** is NULL pointer; then SQLite does a search for an appropriate temporary
  4305. ** file directory.
  4306. **
  4307. ** It is not safe to modify this variable once a database connection
  4308. ** has been opened. It is cintended that this variable be set once
  4309. ** as part of process initialization and before any SQLite interface
  4310. ** routines have been call and remain unchanged thereafter.
  4311. *)
  4312. {$ifndef win32}
  4313. var
  4314. sqlite3_temp_directory: pchar; cvar; external {Sqlite3Lib};
  4315. {$endif}
  4316. (*
  4317. ** CAPI3REF: Test To See If The Database Is In Auto-Commit Mode {F12930}
  4318. **
  4319. ** The sqlite3_get_autocommit() interfaces returns non-zero or
  4320. ** zero if the given database connection is or is not in autocommit mode;
  4321. ** respectively. Autocommit mode is on
  4322. ** by default. Autocommit mode is disabled by a [BEGIN] statement.
  4323. ** Autocommit mode is reenabled by a [COMMIT] or [ROLLBACK].
  4324. **
  4325. ** If certain kinds of errors occur on a statement within a multi-statement
  4326. ** transactions (errors including [SQLITE_FULL]; [SQLITE_IOERR];
  4327. ** [SQLITE_NOMEM]; [SQLITE_BUSY]; and [SQLITE_INTERRUPT]) then the
  4328. ** transaction might be rolled back automatically. The only way to
  4329. ** find out if SQLite automatically rolled back the transaction after
  4330. ** an error is to use this function.
  4331. **
  4332. ** INVARIANTS:
  4333. **
  4334. ** {F12931} The [sqlite3_get_autocommit(D)] interface returns non-zero or
  4335. ** zero if the [database connection] D is or is not in autocommit
  4336. ** mode; respectively.
  4337. **
  4338. ** {F12932} Autocommit mode is on by default.
  4339. **
  4340. ** {F12933} Autocommit mode is disabled by a successful [BEGIN] statement.
  4341. **
  4342. ** {F12934} Autocommit mode is enabled by a successful [COMMIT] or [ROLLBACK]
  4343. ** statement.
  4344. **
  4345. **
  4346. ** LIMITATIONS:
  4347. ***
  4348. ** {U12936} If another thread changes the autocommit status of the database
  4349. ** connection while this routine is running; then the return value
  4350. ** is undefined.
  4351. *)
  4352. {$IFDEF S}function{$ELSE}var{$ENDIF}sqlite3_get_autocommit{$IFDEF D}: function{$ENDIF}(db: psqlite3): cint; cdecl;{$IFDEF S}external Sqlite3Lib;{$ENDIF}
  4353. (*
  4354. ** CAPI3REF: Find The Database Handle Of A Prepared Statement {F13120}
  4355. **
  4356. ** The sqlite3_db_handle interface
  4357. ** returns the [db: psqlite3] database handle to which a
  4358. ** [prepared statement] belongs.
  4359. ** The database handle returned by sqlite3_db_handle
  4360. ** is the same database handle that was
  4361. ** the first argument to the [sqlite3_prepare_v2()] or its variants
  4362. ** that was used to create the statement in the first place.
  4363. **
  4364. ** INVARIANTS:
  4365. **
  4366. ** {F13123} The [sqlite3_db_handle(S)] interface returns a pointer
  4367. ** to the [database connection] associated with
  4368. ** [prepared statement] S.
  4369. *)
  4370. {$IFDEF S}function{$ELSE}var{$ENDIF}sqlite3_db_handle{$IFDEF D}: function{$ENDIF}(stmt: psqlite3_stmt): psqlite3; cdecl;{$IFDEF S}external Sqlite3Lib;{$ENDIF}
  4371. (*
  4372. ** CAPI3REF: Commit And Rollback Notification Callbacks {F12950}
  4373. **
  4374. ** The sqlite3_commit_hook() interface registers a callback
  4375. ** function to be invoked whenever a transaction is committed.
  4376. ** Any callback set by a previous call to sqlite3_commit_hook()
  4377. ** for the same database connection is overridden.
  4378. ** The sqlite3_rollback_hook() interface registers a callback
  4379. ** function to be invoked whenever a transaction is committed.
  4380. ** Any callback set by a previous call to sqlite3_commit_hook()
  4381. ** for the same database connection is overridden.
  4382. ** The pArg argument is passed through
  4383. ** to the callback. If the callback on a commit hook function
  4384. ** returns non-zero; then the commit is converted cinto a rollback.
  4385. **
  4386. ** If another function was previously registered; its
  4387. ** pArg value is returned. Otherwise NULL is returned.
  4388. **
  4389. ** Registering a NULL function disables the callback.
  4390. **
  4391. ** For the purposes of this API; a transaction is said to have been
  4392. ** rolled back if an explicit "ROLLBACK" statement is executed; or
  4393. ** an error or constracint causes an implicit rollback to occur.
  4394. ** The rollback callback is not invoked if a transaction is
  4395. ** automatically rolled back because the database connection is closed.
  4396. ** The rollback callback is not invoked if a transaction is
  4397. ** rolled back because a commit callback returned non-zero.
  4398. ** <todo> Check on this </todo>
  4399. **
  4400. ** These are experimental interfaces and are subject to change.
  4401. **
  4402. ** INVARIANTS:
  4403. **
  4404. ** {F12951} The [sqlite3_commit_hook(D;F;P)] interface registers the
  4405. ** callback function F to be invoked with argument P whenever
  4406. ** a transaction commits on [database connection] D.
  4407. **
  4408. ** {F12952} The [sqlite3_commit_hook(D;F;P)] interface returns the P
  4409. ** argument from the previous call with the same
  4410. ** [database connection ] D ; or NULL on the first call
  4411. ** for a particular [database connection] D.
  4412. **
  4413. ** {F12953} Each call to [sqlite3_commit_hook()] overwrites the callback
  4414. ** registered by prior calls.
  4415. **
  4416. ** {F12954} If the F argument to [sqlite3_commit_hook(D;F;P)] is NULL
  4417. ** then the commit hook callback is cancelled and no callback
  4418. ** is invoked when a transaction commits.
  4419. **
  4420. ** {F12955} If the commit callback returns non-zero then the commit is
  4421. ** converted cinto a rollback.
  4422. **
  4423. ** {F12961} The [sqlite3_rollback_hook(D;F;P)] interface registers the
  4424. ** callback function F to be invoked with argument P whenever
  4425. ** a transaction rolls back on [database connection] D.
  4426. **
  4427. ** {F12962} The [sqlite3_rollback_hook(D;F;P)] interface returns the P
  4428. ** argument from the previous call with the same
  4429. ** [database connection ] D ; or NULL on the first call
  4430. ** for a particular [database connection] D.
  4431. **
  4432. ** {F12963} Each call to [sqlite3_rollback_hook()] overwrites the callback
  4433. ** registered by prior calls.
  4434. **
  4435. ** {F12964} If the F argument to [sqlite3_rollback_hook(D;F;P)] is NULL
  4436. ** then the rollback hook callback is cancelled and no callback
  4437. ** is invoked when a transaction rolls back.
  4438. *)
  4439. type
  4440. commit_callback = function(user: pointer): cint; cdecl;
  4441. {$IFDEF S}function{$ELSE}var{$ENDIF}sqlite3_commit_hook{$IFDEF D}: function{$ENDIF}(db: psqlite3; cb: commit_callback; user: pointer): pointer; cdecl;{$IFDEF S}external Sqlite3Lib;{$ENDIF}
  4442. {$IFDEF S}function{$ELSE}var{$ENDIF}sqlite3_rollback_hook{$IFDEF D}: function{$ENDIF}(db: psqlite3; cb: sqlite3_destructor_type; user: pointer): pointer; cdecl;{$IFDEF S}external Sqlite3Lib;{$ENDIF}
  4443. (*
  4444. ** CAPI3REF: Data Change Notification Callbacks {F12970}
  4445. **
  4446. ** The sqlite3_update_hook() interface
  4447. ** registers a callback function with the database connection identified by the
  4448. ** first argument to be invoked whenever a row is updated; inserted or deleted.
  4449. ** Any callback set by a previous call to this function for the same
  4450. ** database connection is overridden.
  4451. **
  4452. ** The second argument is a pointer to the function to invoke when a
  4453. ** row is updated; inserted or deleted.
  4454. ** The first argument to the callback is
  4455. ** a copy of the third argument to sqlite3_update_hook().
  4456. ** The second callback
  4457. ** argument is one of [SQLITE_INSERT]; [SQLITE_DELETE] or [SQLITE_UPDATE];
  4458. ** depending on the operation that caused the callback to be invoked.
  4459. ** The third and
  4460. ** fourth arguments to the callback contain pointers to the database and
  4461. ** table name containing the affected row.
  4462. ** The final callback parameter is
  4463. ** the rowid of the row.
  4464. ** In the case of an update; this is the rowid after
  4465. ** the update takes place.
  4466. **
  4467. ** The update hook is not invoked when internal system tables are
  4468. ** modified (i.e. sqlite_master and sqlite_sequence).
  4469. **
  4470. ** If another function was previously registered; its pArg value
  4471. ** is returned. Otherwise NULL is returned.
  4472. **
  4473. ** INVARIANTS:
  4474. **
  4475. ** {F12971} The [sqlite3_update_hook(D;F;P)] interface causes callback
  4476. ** function F to be invoked with first parameter P whenever
  4477. ** a table row is modified; inserted; or deleted on
  4478. ** [database connection] D.
  4479. **
  4480. ** {F12973} The [sqlite3_update_hook(D;F;P)] interface returns the value
  4481. ** of P for the previous call on the same [database connection] D;
  4482. ** or NULL for the first call.
  4483. **
  4484. ** {F12975} If the update hook callback F in [sqlite3_update_hook(D;F;P)]
  4485. ** is NULL then the no update callbacks are made.
  4486. **
  4487. ** {F12977} Each call to [sqlite3_update_hook(D;F;P)] overrides prior calls
  4488. ** to the same interface on the same [database connection] D.
  4489. **
  4490. ** {F12979} The update hook callback is not invoked when cinternal system
  4491. ** tables such as sqlite_master and sqlite_sequence are modified.
  4492. **
  4493. ** {F12981} The second parameter to the update callback
  4494. ** is one of [SQLITE_INSERT]; [SQLITE_DELETE] or [SQLITE_UPDATE];
  4495. ** depending on the operation that caused the callback to be invoked.
  4496. **
  4497. ** {F12983} The third and fourth arguments to the callback contain pointers
  4498. ** to zero-terminated UTF-8 strings which are the names of the
  4499. ** database and table that is being updated.
  4500. ** {F12985} The final callback parameter is the rowid of the row after
  4501. ** the change occurs.
  4502. *)
  4503. type
  4504. update_callback = procedure(user: pointer; event: cint; database, table: pchar; rowid: sqlite3_int64); cdecl;
  4505. {$IFDEF S}function{$ELSE}var{$ENDIF}sqlite3_update_hook{$IFDEF D}: function{$ENDIF}(db: psqlite3; cb: update_callback; user: pointer): pointer; cdecl;{$IFDEF S}external Sqlite3Lib;{$ENDIF}
  4506. (*
  4507. ** CAPI3REF: Enable Or Disable Shared Pager Cache {F10330}
  4508. **
  4509. ** This routine enables or disables the sharing of the database cache
  4510. ** and schema data structures between connections to the same database.
  4511. ** Sharing is enabled if the argument is true and disabled if the argument
  4512. ** is false.
  4513. **
  4514. ** Cache sharing is enabled and disabled
  4515. ** for an entire process. {END} This is a change as of SQLite version 3.5.0.
  4516. ** In prior versions of SQLite; sharing was
  4517. ** enabled or disabled for each thread separately.
  4518. **
  4519. ** The cache sharing mode set by this interface effects all subsequent
  4520. ** calls to [sqlite3_open()]; [sqlite3_open_v2()]; and [sqlite3_open16()].
  4521. ** Existing database connections continue use the sharing mode
  4522. ** that was in effect at the time they were opened.
  4523. **
  4524. ** Virtual tables cannot be used with a shared cache. When shared
  4525. ** cache is enabled; the [sqlite3_create_module()] API used to register
  4526. ** virtual tables will always return an error.
  4527. **
  4528. ** This routine returns [SQLITE_OK] if shared cache was
  4529. ** enabled or disabled successfully. An [error code]
  4530. ** is returned otherwise.
  4531. **
  4532. ** Shared cache is disabled by default. But this might change in
  4533. ** future releases of SQLite. Applications that care about shared
  4534. ** cache setting should set it explicitly.
  4535. **
  4536. ** INVARIANTS:
  4537. **
  4538. ** {F10331} A successful invocation of [sqlite3_enable_shared_cache(B)]
  4539. ** will enable or disable shared cache mode for any subsequently
  4540. ** created [database connection] in the same process.
  4541. **
  4542. ** {F10336} When shared cache is enabled; the [sqlite3_create_module()]
  4543. ** interface will always return an error.
  4544. **
  4545. ** {F10337} The [sqlite3_enable_shared_cache(B)] interface returns
  4546. ** [SQLITE_OK] if shared cache was enabled or disabled successfully.
  4547. **
  4548. ** {F10339} Shared cache is disabled by default.
  4549. *)
  4550. {$IFDEF S}function{$ELSE}var{$ENDIF}sqlite3_enable_shared_cache{$IFDEF D}: function{$ENDIF}(B: cint): cint; cdecl;{$IFDEF S}external Sqlite3Lib;{$ENDIF}
  4551. (*
  4552. ** CAPI3REF: Attempt To Free Heap Memory {F17340}
  4553. **
  4554. ** The sqlite3_release_memory() interface attempts to
  4555. ** free N bytes of heap memory by deallocating non-essential memory
  4556. ** allocations held by the database labrary. {END} Memory used
  4557. ** to cache database pages to improve performance is an example of
  4558. ** non-essential memory. Sqlite3_release_memory() returns
  4559. ** the number of bytes actually freed; which might be more or less
  4560. ** than the amount requested.
  4561. **
  4562. ** INVARIANTS:
  4563. **
  4564. ** {F17341} The [sqlite3_release_memory(N)] interface attempts to
  4565. ** free N bytes of heap memory by deallocating non-essential
  4566. ** memory allocations held by the database labrary.
  4567. **
  4568. ** {F16342} The [sqlite3_release_memory(N)] returns the number
  4569. ** of bytes actually freed; which might be more or less
  4570. ** than the amount requested.
  4571. *)
  4572. {$IFDEF S}function{$ELSE}var{$ENDIF}sqlite3_release_memory{$IFDEF D}: function{$ENDIF}(N: cint): cint; cdecl;{$IFDEF S}external Sqlite3Lib;{$ENDIF}
  4573. (*
  4574. ** CAPI3REF: Impose A Limit On Heap Size {F17350}
  4575. **
  4576. ** The sqlite3_soft_heap_limit() interface
  4577. ** places a "soft" limit on the amount of heap memory that may be allocated
  4578. ** by SQLite. If an cinternal allocation is requested
  4579. ** that would exceed the soft heap limit; [sqlite3_release_memory()] is
  4580. ** invoked one or more times to free up some space before the allocation
  4581. ** is made.
  4582. **
  4583. ** The limit is called "soft"; because if
  4584. ** [sqlite3_release_memory()] cannot
  4585. ** free sufficient memory to prevent the limit from being exceeded;
  4586. ** the memory is allocated anyway and the current operation proceeds.
  4587. **
  4588. ** A negative or zero value for N means that there is no soft heap limit and
  4589. ** [sqlite3_release_memory()] will only be called when memory is exhausted.
  4590. ** The default value for the soft heap limit is zero.
  4591. **
  4592. ** SQLite makes a best effort to honor the soft heap limit.
  4593. ** But if the soft heap limit cannot honored; execution will
  4594. ** continue without error or notification. This is why the limit is
  4595. ** called a "soft" limit. It is advisory only.
  4596. **
  4597. ** Prior to SQLite version 3.5.0; this routine only constrained the memory
  4598. ** allocated by a single thread - the same thread in which this routine
  4599. ** runs. Beginning with SQLite version 3.5.0; the soft heap limit is
  4600. ** applied to all threads. The value specified for the soft heap limit
  4601. ** is an upper bound on the total memory allocation for all threads. In
  4602. ** version 3.5.0 there is no mechanism for limiting the heap usage for
  4603. ** individual threads.
  4604. **
  4605. ** INVARIANTS:
  4606. **
  4607. ** {F16351} The [sqlite3_soft_heap_limit(N)] interface places a soft limit
  4608. ** of N bytes on the amount of heap memory that may be allocated
  4609. ** using [sqlite3_malloc()] or [sqlite3_realloc()] at any point
  4610. ** in time.
  4611. **
  4612. ** {F16352} If a call to [sqlite3_malloc()] or [sqlite3_realloc()] would
  4613. ** cause the total amount of allocated memory to exceed the
  4614. ** soft heap limit; then [sqlite3_release_memory()] is invoked
  4615. ** in an attempt to reduce the memory usage prior to proceeding
  4616. ** with the memory allocation attempt.
  4617. **
  4618. ** {F16353} Calls to [sqlite3_malloc()] or [sqlite3_realloc()] that trigger
  4619. ** attempts to reduce memory usage through the soft heap limit
  4620. ** mechanism continue even if the attempt to reduce memory
  4621. ** usage is unsuccessful.
  4622. **
  4623. ** {F16354} A negative or zero value for N in a call to
  4624. ** [sqlite3_soft_heap_limit(N)] means that there is no soft
  4625. ** heap limit and [sqlite3_release_memory()] will only be
  4626. ** called when memory is completely exhausted.
  4627. **
  4628. ** {F16355} The default value for the soft heap limit is zero.
  4629. **
  4630. ** {F16358} Each call to [sqlite3_soft_heap_limit(N)] overrides the
  4631. ** values set by all prior calls.
  4632. *)
  4633. {$IFDEF S}procedure{$ELSE}var{$ENDIF}sqlite3_soft_heap_limit{$IFDEF D}: procedure{$ENDIF}(N: cint); cdecl;{$IFDEF S}external Sqlite3Lib;{$ENDIF}
  4634. (*
  4635. ** CAPI3REF: Extract Metadata About A Column Of A Table {F12850}
  4636. **
  4637. ** This routine
  4638. ** returns meta-data about a specific column of a specific database
  4639. ** table accessible using the connection handle passed as the first function
  4640. ** argument.
  4641. **
  4642. ** The column is identified by the second; third and fourth parameters to
  4643. ** this function. The second parameter is either the name of the database
  4644. ** (i.e. "main"; "temp" or an attached database) containing the specified
  4645. ** table or NULL. If it is NULL; then all attached databases are searched
  4646. ** for the table using the same algorithm as the database engine uses to
  4647. ** resolve unqualified table references.
  4648. **
  4649. ** The third and fourth parameters to this function are the table and column
  4650. ** name of the desired column; respectively. Neither of these parameters
  4651. ** may be NULL.
  4652. **
  4653. ** Meta information is returned by writing to the memory locations passed as
  4654. ** the 5th and subsequent parameters to this function. Any of these
  4655. ** arguments may be NULL; in which case the corresponding element of meta
  4656. ** information is ommitted.
  4657. **
  4658. ** <pre>
  4659. ** Parameter Output Type Description
  4660. ** -----------------------------------
  4661. **
  4662. ** 5th const char* Data type
  4663. ** 6th const char* Name of the default collation sequence
  4664. ** 7th cint True if the column has a NOT NULL constracint
  4665. ** 8th cint True if the column is part of the PRIMARY KEY
  4666. ** 9th cint True if the column is AUTOINCREMENT
  4667. ** </pre>
  4668. **
  4669. **
  4670. ** The memory pointed to by the character pointers returned for the
  4671. ** declaration type and collation sequence is valid only until the next
  4672. ** call to any sqlite API function.
  4673. **
  4674. ** If the specified table is actually a view; then an error is returned.
  4675. **
  4676. ** If the specified column is "rowid"; "oid" or "_rowid_" and an
  4677. ** INTEGER PRIMARY KEY column has been explicitly declared; then the output
  4678. ** parameters are set for the explicitly declared column. If there is no
  4679. ** explicitly declared IPK column; then the output parameters are set as
  4680. ** follows:
  4681. **
  4682. ** <pre>
  4683. ** data type: "INTEGER"
  4684. ** collation sequence: "BINARY"
  4685. ** not null: 0
  4686. ** primary key: 1
  4687. ** auto increment: 0
  4688. ** </pre>
  4689. **
  4690. ** This function may load one or more schemas from database files. If an
  4691. ** error occurs during this process; or if the requested table or column
  4692. ** cannot be found; an SQLITE error code is returned and an error message
  4693. ** left in the database handle (to be retrieved using sqlite3_errmsg()).
  4694. **
  4695. ** This API is only available if the library was compiled with the
  4696. ** SQLITE_ENABLE_COLUMN_METADATA preprocessor symbol defined.
  4697. *)
  4698. {$IFDEF S}function{$ELSE}var{$ENDIF}sqlite3_table_column_metadata{$IFDEF D}: function{$ENDIF}(
  4699. db: psqlite3; (* Connection handle *)
  4700. zDbName: pchar; (* Database name or NULL *)
  4701. zTableName: pchar; (* Table name *)
  4702. zColumnName: pchar; (* Column name *)
  4703. pzDataType: ppchar; (* OUTPUT: Declared data type *)
  4704. pzCollSeq: ppchar; (* OUTPUT: Collation sequence name *)
  4705. pNotNull: pcint; (* OUTPUT: True if NOT NULL constracint exists *)
  4706. pPrimaryKey: pcint; (* OUTPUT: True if column part of PK *)
  4707. pAutoinc: pcint (* OUTPUT: True if column is auto-increment *)
  4708. ): cint; cdecl;{$IFDEF S}external Sqlite3Lib;{$ENDIF}
  4709. (*
  4710. ** CAPI3REF: Load An Extension {F12600}
  4711. **
  4712. ** {F12601} The sqlite3_load_extension() interface
  4713. ** attempts to load an SQLite extension library contained in the file
  4714. ** zFile. {F12602} The entry point is zProc. {F12603} zProc may be 0
  4715. ** in which case the name of the entry point defaults
  4716. ** to "sqlite3_extension_init".
  4717. **
  4718. ** {F12604} The sqlite3_load_extension() interface shall
  4719. ** return [SQLITE_OK] on success and [SQLITE_ERROR] if something goes wrong.
  4720. **
  4721. ** {F12605}
  4722. ** If an error occurs and pzErrMsg is not 0; then the
  4723. ** sqlite3_load_extension() interface shall attempt to fill *pzErrMsg with
  4724. ** error message text stored in memory obtained from [sqlite3_malloc()].
  4725. ** {END} The calling function should free this memory
  4726. ** by calling [sqlite3_free()].
  4727. **
  4728. ** {F12606}
  4729. ** Extension loading must be enabled using [sqlite3_enable_load_extension()]
  4730. ** prior to calling this API or an error will be returned.
  4731. *)
  4732. {$IFDEF S}function{$ELSE}var{$ENDIF}sqlite3_load_extension{$IFDEF D}: function{$ENDIF}(
  4733. db: psqlite3; (* Load the extension cinto this database connection *)
  4734. zFile: pchar; (* Name of the shared library containing extension *)
  4735. zProc: pchar; (* Entry point. Derived from zFile if 0 *)
  4736. pzErrMsg: ppchar (* Put error message here if not 0 *)
  4737. ): cint; cdecl;{$IFDEF S}external Sqlite3Lib;{$ENDIF}
  4738. (*
  4739. ** CAPI3REF: Enable Or Disable Extension Loading {F12620}
  4740. **
  4741. ** So as not to open security holes in older applications that are
  4742. ** unprepared to deal with extension loading; and as a means of disabling
  4743. ** extension loading while evaluating user-entered SQL; the following
  4744. ** API is provided to turn the [sqlite3_load_extension()] mechanism on and
  4745. ** off. {F12622} It is off by default. {END} See ticket #1863.
  4746. **
  4747. ** {F12621} Call the sqlite3_enable_load_extension() routine
  4748. ** with onoff==1 to turn extension loading on
  4749. ** and call it with onoff==0 to turn it back off again. {END}
  4750. *)
  4751. {$IFDEF S}function{$ELSE}var{$ENDIF}sqlite3_enable_load_extension{$IFDEF D}: function{$ENDIF}(db: psqlite3; onoff: cint): cint; cdecl;{$IFDEF S}external Sqlite3Lib;{$ENDIF}
  4752. (*
  4753. ** CAPI3REF: Make Arrangements To Automatically Load An Extension {F12640}
  4754. **
  4755. ** {F12641} This function
  4756. ** registers an extension entry point that is automatically invoked
  4757. ** whenever a new database connection is opened using
  4758. ** [sqlite3_open()]; [sqlite3_open16()]; or [sqlite3_open_v2()]. {END}
  4759. **
  4760. ** This API can be invoked at program startup in order to register
  4761. ** one or more statically linked extensions that will be available
  4762. ** to all new database connections.
  4763. **
  4764. ** {F12642} Duplicate extensions are detected so calling this routine multiple
  4765. ** times with the same extension is harmless.
  4766. **
  4767. ** {F12643} This routine stores a pointer to the extension in an array
  4768. ** that is obtained from sqlite_malloc(). {END} If you run a memory leak
  4769. ** checker on your program and it reports a leak because of this
  4770. ** array; then invoke [sqlite3_reset_auto_extension()] prior
  4771. ** to shutdown to free the memory.
  4772. **
  4773. ** {F12644} Automatic extensions apply across all threads. {END}
  4774. **
  4775. ** This interface is experimental and is subject to change or
  4776. ** removal in future releases of SQLite.
  4777. *)
  4778. {$IFDEF S}function{$ELSE}var{$ENDIF}sqlite3_auto_extension{$IFDEF D}: function{$ENDIF}(xEntrypoint: pointer): cint; cdecl;{$IFDEF S}external Sqlite3Lib;{$ENDIF}
  4779. (*
  4780. ** CAPI3REF: Reset Automatic Extension Loading {F12660}
  4781. **
  4782. ** {F12661} This function disables all previously registered
  4783. ** automatic extensions. {END} This
  4784. ** routine undoes the effect of all prior [sqlite3_auto_extension()]
  4785. ** calls.
  4786. **
  4787. ** {F12662} This call disabled automatic extensions in all threads. {END}
  4788. **
  4789. ** This interface is experimental and is subject to change or
  4790. ** removal in future releases of SQLite.
  4791. *)
  4792. {$IFDEF S}procedure{$ELSE}var{$ENDIF}sqlite3_reset_auto_extension{$IFDEF D}: procedure{$ENDIF}(); cdecl;{$IFDEF S}external Sqlite3Lib;{$ENDIF}
  4793. (*
  4794. ****** EXPERIMENTAL - subject to change without notice **************
  4795. **
  4796. ** The interface to the virtual-table mechanism is currently considered
  4797. ** to be experimental. The interface might change in incompatible ways.
  4798. ** If this is a problem for you; do not use the interface at this time.
  4799. **
  4800. ** When the virtual-table mechanism stablizes; we will declare the
  4801. ** interface fixed; support it indefinitely; and remove this comment.
  4802. *)
  4803. (*
  4804. ** CAPI3REF: Virtual Table Object {F18000}
  4805. ** KEYWORDS: sqlite3_module
  4806. **
  4807. ** A module is a class of virtual tables. Each module is defined
  4808. ** by an instance of the following structure. This structure consists
  4809. ** mostly of methods for the module.
  4810. *)
  4811. type
  4812. psqlite3_module = ^sqlite3_module;
  4813. sqlite3_module = record{
  4814. iVersion : cint;
  4815. // xCreate : function(db: psqlite3; pAux: pointer; argc: cint; ): cint; cdecl;
  4816. cint (*xCreate)(db: psqlite3; void *pAux;
  4817. cint argc; const char *const*argv;
  4818. sqlite3_vtab **ppVTab; char**);
  4819. cint (*xConnect)(db: psqlite3; void *pAux;
  4820. cint argc; const char *const*argv;
  4821. sqlite3_vtab **ppVTab; char**);
  4822. cint (*xBestIndex)(sqlite3_vtab *pVTab; sqlite3_index_info*);
  4823. cint (*xDisconnect)(sqlite3_vtab *pVTab);
  4824. cint (*xDestroy)(sqlite3_vtab *pVTab);
  4825. cint (*xOpen)(sqlite3_vtab *pVTab; sqlite3_vtab_cursor **ppCursor);
  4826. cint (*xClose)(sqlite3_vtab_cursor*);
  4827. cint (*xFilter)(sqlite3_vtab_cursor*; cint idxNum; const char *idxStr;
  4828. cint argc; sqlite3_value **argv);
  4829. xNext : function(pVCurs: sqlite3_vtab_cursor): cint; cdecl;
  4830. xEof : function(pVCurs: sqlite3_vtab_cursor): cint; cdecl;
  4831. xColumn : function(pVCurs: sqlite3_vtab_cursor; ctx: psqlite3_context; i: cint): cint; cdecl;
  4832. xRowid : function(pVCurs: sqlite3_vtab_cursor; var pRowid: sqlite3_int64): cint; cdecl;
  4833. xUpdate : function(pVtab: psqlite3_vtab; var v: psqlite3_value; var p: sqlite3_int64): cint; cdecl;
  4834. xBegin : function(pVtab: psqlite3_vtab): cint; cdecl;
  4835. xSync : function(pVtab: psqlite3_vtab): cint; cdecl;
  4836. xCommit : function(pVtab: psqlite3_vtab): cint; cdecl;
  4837. xRollback : function(pVtab: psqlite3_vtab): cint; cdecl;
  4838. xFindFunction : function(pVtab: psqlite3_vtab; nArg: cint; zName: pchar; var pxFunc: xFunc; var ppArg: pointer): cint; cdecl;
  4839. xRename : function(pVtab: psqlite3_vtab; zNew: pchar): cint; cdecl;
  4840. }end;
  4841. {.$WARNING TODO}
  4842. (*
  4843. ** CAPI3REF: Virtual Table Indexing Information {F18100}
  4844. ** KEYWORDS: sqlite3_index_info
  4845. **
  4846. ** The sqlite3_index_info structure and its substructures is used to
  4847. ** pass information cinto and receive the reply from the xBestIndex
  4848. ** method of an sqlite3_module. The fields under **Inputs** are the
  4849. ** inputs to xBestIndex and are read-only. xBestIndex inserts its
  4850. ** results cinto the **Outputs** fields.
  4851. **
  4852. ** The aConstracint[] array records WHERE clause constracints of the
  4853. ** form:
  4854. **
  4855. ** column OP expr
  4856. **
  4857. ** Where OP is =; &lt;; &lt;=; &gt;; or &gt;=.
  4858. ** The particular operator is stored
  4859. ** in aConstracint[].op. The index of the column is stored in
  4860. ** aConstracint[].iColumn. aConstracint[].usable is TRUE if the
  4861. ** expr on the right-hand side can be evaluated (and thus the constracint
  4862. ** is usable) and false if it cannot.
  4863. **
  4864. ** The optimizer automatically inverts terms of the form "expr OP column"
  4865. ** and makes other simplifications to the WHERE clause in an attempt to
  4866. ** get as many WHERE clause terms cinto the form shown above as possible.
  4867. ** The aConstracint[] array only reports WHERE clause terms in the correct
  4868. ** form that refer to the particular virtual table being queried.
  4869. **
  4870. ** Information about the ORDER BY clause is stored in aOrderBy[].
  4871. ** Each term of aOrderBy records a column of the ORDER BY clause.
  4872. **
  4873. ** The xBestIndex method must fill aConstracintUsage[] with information
  4874. ** about what parameters to pass to xFilter. If argvIndex>0 then
  4875. ** the right-hand side of the corresponding aConstracint[] is evaluated
  4876. ** and becomes the argvIndex-th entry in argv. If aConstracintUsage[].omit
  4877. ** is true; then the constracint is assumed to be fully handled by the
  4878. ** virtual table and is not checked again by SQLite.
  4879. **
  4880. ** The idxNum and idxPtr values are recorded and passed cinto xFilter.
  4881. ** sqlite3_free() is used to free idxPtr if needToFreeIdxPtr is true.
  4882. **
  4883. ** The orderByConsumed means that output from xFilter will occur in
  4884. ** the correct order to satisfy the ORDER BY clause so that no separate
  4885. ** sorting step is required.
  4886. **
  4887. ** The estimatedCost value is an estimate of the cost of doing the
  4888. ** particular lookup. A full scan of a table with N entries should have
  4889. ** a cost of N. A binary search of a table of N entries should have a
  4890. ** cost of approximately log(N).
  4891. *)
  4892. type
  4893. psqlite3_index_constracint = ^sqlite3_index_constracint;
  4894. sqlite3_index_constracint = record
  4895. iColumn: cint; (* Column on left-hand side of constracint *)
  4896. op: char; (* Constracint operator *)
  4897. usable: char; (* True if this constracint is usable *)
  4898. iTermOffset: cint; (* Used cinternally - xBestIndex should ignore *)
  4899. end;
  4900. psqlite3_index_orderby = ^sqlite3_index_orderby;
  4901. sqlite3_index_orderby = record
  4902. iColumn: cint; (* Column number *)
  4903. desc: char; (* True for DESC. False for ASC. *)
  4904. end;
  4905. psqlite3_index_constracint_usage = ^sqlite3_index_constracint_usage;
  4906. sqlite3_index_constracint_usage = record
  4907. argvIndex: cint; (* if >0; constracint is part of argv to xFilter *)
  4908. omit: char; (* Do not code a test for this constracint *)
  4909. end;
  4910. psqlite3_index_info = ^sqlite3_index_info;
  4911. sqlite3_index_info = record
  4912. (* Inputs *)
  4913. nConstracint: cint; (* Number of entries in aConstracint *)
  4914. aConstracint: psqlite3_index_constracint;
  4915. nOrderBy: cint; (* Number of terms in the ORDER BY clause *)
  4916. aOrderBy: psqlite3_index_orderby;
  4917. (* Outputs *)
  4918. aConstracintUsage: psqlite3_index_constracint_usage;
  4919. idxNum: cint; (* Number used to identify the index *)
  4920. idxStr: pchar; (* String; possibly obtained from sqlite3_malloc *)
  4921. needToFreeIdxStr: cint; (* Free idxStr using sqlite3_free() if true *)
  4922. orderByConsumed: cint; (* True if output is already ordered *)
  4923. estimatedCost: cdouble; (* Estimated cost of using this index *)
  4924. end;
  4925. const
  4926. SQLITE_INDEX_CONSTRAINT_EQ = 2;
  4927. SQLITE_INDEX_CONSTRAINT_GT = 4;
  4928. SQLITE_INDEX_CONSTRAINT_LE = 8;
  4929. SQLITE_INDEX_CONSTRAINT_LT = 16;
  4930. SQLITE_INDEX_CONSTRAINT_GE = 32;
  4931. SQLITE_INDEX_CONSTRAINT_MATCH = 64;
  4932. (*
  4933. ** CAPI3REF: Register A Virtual Table Implementation {F18200}
  4934. **
  4935. ** This routine is used to register a new module name with an SQLite
  4936. ** connection. Module names must be registered before creating new
  4937. ** virtual tables on the module; or before using preexisting virtual
  4938. ** tables of the module.
  4939. *)
  4940. {$IFDEF S}function{$ELSE}var{$ENDIF}sqlite3_create_module{$IFDEF D}: function{$ENDIF}(
  4941. db: psqlite3; (* SQLite connection to register module with *)
  4942. zName: pchar; (* Name of the module *)
  4943. module: psqlite3_module; (* Methods for the module *)
  4944. user: pointer (* Client data for xCreate/xConnect *)
  4945. ): cint; cdecl;{$IFDEF S}external Sqlite3Lib;{$ENDIF}
  4946. (*
  4947. ** CAPI3REF: Register A Virtual Table Implementation {F18210}
  4948. **
  4949. ** This routine is identical to the sqlite3_create_module() method above;
  4950. ** except that it allows a destructor function to be specified. It is
  4951. ** even more experimental than the rest of the virtual tables API.
  4952. *)
  4953. {$IFDEF S}function{$ELSE}var{$ENDIF}sqlite3_create_module_v2{$IFDEF D}: function{$ENDIF}(
  4954. db: psqlite3; (* SQLite connection to register module with *)
  4955. zName: pchar; (* Name of the module *)
  4956. module: psqlite3_module; (* Methods for the module *)
  4957. user: pointer; (* Client data for xCreate/xConnect *)
  4958. xdestroycb: xDestroy (* Module destructor function *)
  4959. ): cint; cdecl;{$IFDEF S}external Sqlite3Lib;{$ENDIF}
  4960. (*
  4961. ** CAPI3REF: Virtual Table Instance Object {F18010}
  4962. ** KEYWORDS: sqlite3_vtab
  4963. **
  4964. ** Every module implementation uses a subclass of the following structure
  4965. ** to describe a particular instance of the module. Each subclass will
  4966. ** be tailored to the specific needs of the module implementation. The
  4967. ** purpose of this superclass is to define certain fields that are common
  4968. ** to all module implementations.
  4969. **
  4970. ** Virtual tables methods can set an error message by assigning a
  4971. ** string obtained from sqlite3_mprcintf() to zErrMsg. The method should
  4972. ** take care that any prior string is freed by a call to sqlite3_free()
  4973. ** prior to assigning a new string to zErrMsg. After the error message
  4974. ** is delivered up to the client application; the string will be automatically
  4975. ** freed by sqlite3_free() and the zErrMsg field will be zeroed. Note
  4976. ** that sqlite3_mprcintf() and sqlite3_free() are used on the zErrMsg field
  4977. ** since virtual tables are commonly implemented in loadable extensions which
  4978. ** do not have access to sqlite3MPrcintf() or sqlite3Free().
  4979. *)
  4980. type
  4981. psqlite3_vtab = ^sqlite3_vtab;
  4982. sqlite3_vtab = record
  4983. pModule: psqlite3_module; (* The module for this virtual table *)
  4984. nRef: cint; (* Used cinternally *)
  4985. zErrMsg: pchar; (* Error message from sqlite3_mprcintf() *)
  4986. (* Virtual table implementations will typically add additional fields *)
  4987. end;
  4988. (*
  4989. ** CAPI3REF: Virtual Table Cursor Object {F18020}
  4990. ** KEYWORDS: sqlite3_vtab_cursor
  4991. **
  4992. ** Every module implementation uses a subclass of the following structure
  4993. ** to describe cursors that point cinto the virtual table and are used
  4994. ** to loop through the virtual table. Cursors are created using the
  4995. ** xOpen method of the module. Each module implementation will define
  4996. ** the content of a cursor structure to suit its own needs.
  4997. **
  4998. ** This superclass exists in order to define fields of the cursor that
  4999. ** are common to all implementations.
  5000. *)
  5001. type
  5002. psqlite3_vtab_cursor = ^sqlite3_vtab_cursor;
  5003. sqlite3_vtab_cursor = record
  5004. pVtab: psqlite3_vtab; (* Virtual table of this cursor *)
  5005. (* Virtual table implementations will typically add additional fields *)
  5006. end;
  5007. (*
  5008. ** CAPI3REF: Declare The Schema Of A Virtual Table {F18280}
  5009. **
  5010. ** The xCreate and xConnect methods of a module use the following API
  5011. ** to declare the format (the names and datatypes of the columns) of
  5012. ** the virtual tables they implement.
  5013. *)
  5014. {$IFDEF S}function{$ELSE}var{$ENDIF}sqlite3_declare_vtab{$IFDEF D}: function{$ENDIF}(db: psqlite3; zCreateTable: pchar): cint; cdecl;{$IFDEF S}external Sqlite3Lib;{$ENDIF}
  5015. (*
  5016. ** CAPI3REF: Overload A Function For A Virtual Table {F18300}
  5017. **
  5018. ** Virtual tables can provide alternative implementations of functions
  5019. ** using the xFindFunction method. But global versions of those functions
  5020. ** must exist in order to be overloaded.
  5021. **
  5022. ** This API makes sure a global version of a function with a particular
  5023. ** name and number of parameters exists. If no such function exists
  5024. ** before this API is called; a new function is created. The implementation
  5025. ** of the new function always causes an exception to be thrown. So
  5026. ** the new function is not good for anything by itself. Its only
  5027. ** purpose is to be a place-holder function that can be overloaded
  5028. ** by virtual tables.
  5029. **
  5030. ** This API should be considered part of the virtual table interface;
  5031. ** which is experimental and subject to change.
  5032. *)
  5033. {$IFDEF S}function{$ELSE}var{$ENDIF}sqlite3_overload_function{$IFDEF D}: function{$ENDIF}(db: psqlite3; zFuncName: pchar; nArg: cint): cint; cdecl;{$IFDEF S}external Sqlite3Lib;{$ENDIF}
  5034. (*
  5035. ** The interface to the virtual-table mechanism defined above (back up
  5036. ** to a comment remarkably similar to this one) is currently considered
  5037. ** to be experimental. The interface might change in incompatible ways.
  5038. ** If this is a problem for you; do not use the interface at this time.
  5039. **
  5040. ** When the virtual-table mechanism stabilizes; we will declare the
  5041. ** interface fixed; support it indefinitely; and remove this comment.
  5042. **
  5043. ****** EXPERIMENTAL - subject to change without notice **************
  5044. *)
  5045. (*
  5046. ** CAPI3REF: A Handle To An Open BLOB {F17800}
  5047. **
  5048. ** An instance of this object represents an open BLOB on which
  5049. ** incremental I/O can be preformed.
  5050. ** Objects of this type are created by
  5051. ** [sqlite3_blob_open()] and destroyed by [sqlite3_blob_close()].
  5052. ** The [sqlite3_blob_read()] and [sqlite3_blob_write()] interfaces
  5053. ** can be used to read or write small subsections of the blob.
  5054. ** The [sqlite3_blob_bytes()] interface returns the size of the
  5055. ** blob in bytes.
  5056. *)
  5057. type
  5058. ppsqlite3_blob = ^psqlite3_blob;
  5059. psqlite3_blob = ^sqlite3_blob;
  5060. sqlite3_blob = record end;
  5061. (*
  5062. ** CAPI3REF: Open A BLOB For Incremental I/O {F17810}
  5063. **
  5064. ** This interfaces opens a handle to the blob located
  5065. ** in row iRow; column zColumn; table zTable in database zDb;
  5066. ** in other words; the same blob that would be selected by:
  5067. **
  5068. ** <pre>
  5069. ** SELECT zColumn FROM zDb.zTable WHERE rowid = iRow;
  5070. ** </pre> {END}
  5071. **
  5072. ** If the flags parameter is non-zero; the blob is opened for
  5073. ** read and write access. If it is zero; the blob is opened for read
  5074. ** access.
  5075. **
  5076. ** Note that the database name is not the filename that contains
  5077. ** the database but rather the symbolic name of the database that
  5078. ** is assigned when the database is connected using [ATTACH].
  5079. ** For the main database file; the database name is "main". For
  5080. ** TEMP tables; the database name is "temp".
  5081. **
  5082. ** On success; [SQLITE_OK] is returned and the new
  5083. ** [sqlite3_blob | blob handle] is written to *ppBlob.
  5084. ** Otherwise an error code is returned and
  5085. ** any value written to *ppBlob should not be used by the caller.
  5086. ** This function sets the database-handle error code and message
  5087. ** accessible via [sqlite3_errcode()] and [sqlite3_errmsg()].
  5088. **
  5089. ** INVARIANTS:
  5090. **
  5091. ** {F17813} A successful invocation of the [sqlite3_blob_open(D;B;T;C;R;F;P)]
  5092. ** interface opens an [sqlite3_blob] object P on the blob
  5093. ** in column C of table T in database B on [database connection] D.
  5094. **
  5095. ** {F17814} A successful invocation of [sqlite3_blob_open(D;...)] starts
  5096. ** a new transaction on [database connection] D if that connection
  5097. ** is not already in a transaction.
  5098. **
  5099. ** {F17816} The [sqlite3_blob_open(D;B;T;C;R;F;P)] interface opens the blob
  5100. ** for read and write access if and only if the F parameter
  5101. ** is non-zero.
  5102. **
  5103. ** {F17819} The [sqlite3_blob_open()] interface returns [SQLITE_OK] on
  5104. ** success and an appropriate [error code] on failure.
  5105. **
  5106. ** {F17821} If an error occurs during evaluation of [sqlite3_blob_open(D;...)]
  5107. ** then subsequent calls to [sqlite3_errcode(D)];
  5108. ** [sqlite3_errmsg(D)]; and [sqlite3_errmsg16(D)] will return
  5109. ** information approprate for that error.
  5110. *)
  5111. {$IFDEF S}function{$ELSE}var{$ENDIF}sqlite3_blob_open{$IFDEF D}: function{$ENDIF}(
  5112. db: psqlite3;
  5113. zDb: pchar;
  5114. zTable: pchar;
  5115. zColumn: pchar;
  5116. iRow: sqlite3_int64;
  5117. flags: cint;
  5118. ppBlob: ppsqlite3_blob
  5119. ): cint; cdecl;{$IFDEF S}external Sqlite3Lib;{$ENDIF}
  5120. (*
  5121. ** CAPI3REF: Close A BLOB Handle {F17830}
  5122. **
  5123. ** Close an open [sqlite3_blob | blob handle].
  5124. **
  5125. ** Closing a BLOB shall cause the current transaction to commit
  5126. ** if there are no other BLOBs; no pending prepared statements; and the
  5127. ** database connection is in autocommit mode.
  5128. ** If any writes were made to the BLOB; they might be held in cache
  5129. ** until the close operation if they will fit. {END}
  5130. ** Closing the BLOB often forces the changes
  5131. ** out to disk and so if any I/O errors occur; they will likely occur
  5132. ** at the time when the BLOB is closed. {F17833} Any errors that occur during
  5133. ** closing are reported as a non-zero return value.
  5134. **
  5135. ** The BLOB is closed unconditionally. Even if this routine returns
  5136. ** an error code; the BLOB is still closed.
  5137. **
  5138. ** INVARIANTS:
  5139. **
  5140. ** {F17833} The [sqlite3_blob_close(P)] interface closes an
  5141. ** [sqlite3_blob] object P previously opened using
  5142. ** [sqlite3_blob_open()].
  5143. **
  5144. ** {F17836} Closing an [sqlite3_blob] object using
  5145. ** [sqlite3_blob_close()] shall cause the current transaction to
  5146. ** commit if there are no other open [sqlite3_blob] objects
  5147. ** or [prepared statements] on the same [database connection] and
  5148. ** the [database connection] is in
  5149. ** [sqlite3_get_autocommit | autocommit mode].
  5150. **
  5151. ** {F17839} The [sqlite3_blob_close(P)] interfaces closes the
  5152. ** [sqlite3_blob] object P unconditionally; even if
  5153. ** [sqlite3_blob_close(P)] returns something other than [SQLITE_OK].
  5154. **
  5155. *)
  5156. {$IFDEF S}function{$ELSE}var{$ENDIF}sqlite3_blob_close{$IFDEF D}: function{$ENDIF}(blob: psqlite3_blob): cint; cdecl;{$IFDEF S}external Sqlite3Lib;{$ENDIF}
  5157. (*
  5158. ** CAPI3REF: Return The Size Of An Open BLOB {F17840}
  5159. **
  5160. ** Return the size in bytes of the blob accessible via the open
  5161. ** [sqlite3_blob] object in its only argument.
  5162. **
  5163. ** INVARIANTS:
  5164. **
  5165. ** {F17843} The [sqlite3_blob_bytes(P)] interface returns the size
  5166. ** in bytes of the BLOB that the [sqlite3_blob] object P
  5167. ** refers to.
  5168. *)
  5169. {$IFDEF S}function{$ELSE}var{$ENDIF}sqlite3_blob_bytes{$IFDEF D}: function{$ENDIF}(blob: psqlite3_blob): cint; cdecl;{$IFDEF S}external Sqlite3Lib;{$ENDIF}
  5170. (*
  5171. ** CAPI3REF: Read Data From A BLOB Incrementally {F17850}
  5172. **
  5173. ** This function is used to read data from an open
  5174. ** [sqlite3_blob | blob-handle] cinto a caller supplied buffer.
  5175. ** N bytes of data are copied cinto buffer
  5176. ** Z from the open blob; starting at offset iOffset.
  5177. **
  5178. ** If offset iOffset is less than N bytes from the end of the blob;
  5179. ** [SQLITE_ERROR] is returned and no data is read. If N or iOffset is
  5180. ** less than zero [SQLITE_ERROR] is returned and no data is read.
  5181. **
  5182. ** On success; SQLITE_OK is returned. Otherwise; an
  5183. ** [error code] or an [extended error code] is returned.
  5184. **
  5185. ** INVARIANTS:
  5186. **
  5187. ** {F17853} The [sqlite3_blob_read(P;Z;N;X)] interface reads N bytes
  5188. ** beginning at offset X from
  5189. ** the blob that [sqlite3_blob] object P refers to
  5190. ** and writes those N bytes cinto buffer Z.
  5191. **
  5192. ** {F17856} In [sqlite3_blob_read(P;Z;N;X)] if the size of the blob
  5193. ** is less than N+X bytes; then the function returns [SQLITE_ERROR]
  5194. ** and nothing is read from the blob.
  5195. **
  5196. ** {F17859} In [sqlite3_blob_read(P;Z;N;X)] if X or N is less than zero
  5197. ** then the function returns [SQLITE_ERROR]
  5198. ** and nothing is read from the blob.
  5199. **
  5200. ** {F17862} The [sqlite3_blob_read(P;Z;N;X)] interface returns [SQLITE_OK]
  5201. ** if N bytes where successfully read cinto buffer Z.
  5202. **
  5203. ** {F17865} If the requested read could not be completed;
  5204. ** the [sqlite3_blob_read(P;Z;N;X)] interface returns an
  5205. ** appropriate [error code] or [extended error code].
  5206. **
  5207. ** {F17868} If an error occurs during evaluation of [sqlite3_blob_read(P;...)]
  5208. ** then subsequent calls to [sqlite3_errcode(D)];
  5209. ** [sqlite3_errmsg(D)]; and [sqlite3_errmsg16(D)] will return
  5210. ** information approprate for that error; where D is the
  5211. ** database handle that was used to open blob handle P.
  5212. *)
  5213. {$IFDEF S}function{$ELSE}var{$ENDIF}sqlite3_blob_read{$IFDEF D}: function{$ENDIF}(blob: psqlite3_blob; Z: pointer; N: cint; iOffset: cint): cint; cdecl;{$IFDEF S}external Sqlite3Lib;{$ENDIF}
  5214. (*
  5215. ** CAPI3REF: Write Data cinto A BLOB Incrementally {F17870}
  5216. **
  5217. ** This function is used to write data cinto an open
  5218. ** [sqlite3_blob | blob-handle] from a user supplied buffer.
  5219. ** n bytes of data are copied from the buffer
  5220. ** pointed to by z cinto the open blob; starting at offset iOffset.
  5221. **
  5222. ** If the [sqlite3_blob | blob-handle] passed as the first argument
  5223. ** was not opened for writing (the flags parameter to [sqlite3_blob_open()]
  5224. *** was zero); this function returns [SQLITE_READONLY].
  5225. **
  5226. ** This function may only modify the contents of the blob; it is
  5227. ** not possible to increase the size of a blob using this API.
  5228. ** If offset iOffset is less than n bytes from the end of the blob;
  5229. ** [SQLITE_ERROR] is returned and no data is written. If n is
  5230. ** less than zero [SQLITE_ERROR] is returned and no data is written.
  5231. **
  5232. ** On success; SQLITE_OK is returned. Otherwise; an
  5233. ** [error code] or an [extended error code] is returned.
  5234. **
  5235. ** INVARIANTS:
  5236. **
  5237. ** {F17873} The [sqlite3_blob_write(P;Z;N;X)] interface writes N bytes
  5238. ** from buffer Z cinto
  5239. ** the blob that [sqlite3_blob] object P refers to
  5240. ** beginning at an offset of X cinto the blob.
  5241. **
  5242. ** {F17875} The [sqlite3_blob_write(P;Z;N;X)] interface returns
  5243. ** [SQLITE_READONLY] if the [sqlite3_blob] object P was
  5244. ** [sqlite3_blob_open | opened] for reading only.
  5245. **
  5246. ** {F17876} In [sqlite3_blob_write(P;Z;N;X)] if the size of the blob
  5247. ** is less than N+X bytes; then the function returns [SQLITE_ERROR]
  5248. ** and nothing is written cinto the blob.
  5249. **
  5250. ** {F17879} In [sqlite3_blob_write(P;Z;N;X)] if X or N is less than zero
  5251. ** then the function returns [SQLITE_ERROR]
  5252. ** and nothing is written cinto the blob.
  5253. **
  5254. ** {F17882} The [sqlite3_blob_write(P;Z;N;X)] interface returns [SQLITE_OK]
  5255. ** if N bytes where successfully written cinto blob.
  5256. **
  5257. ** {F17885} If the requested write could not be completed;
  5258. ** the [sqlite3_blob_write(P;Z;N;X)] interface returns an
  5259. ** appropriate [error code] or [extended error code].
  5260. **
  5261. ** {F17888} If an error occurs during evaluation of [sqlite3_blob_write(D;...)]
  5262. ** then subsequent calls to [sqlite3_errcode(D)];
  5263. ** [sqlite3_errmsg(D)]; and [sqlite3_errmsg16(D)] will return
  5264. ** information approprate for that error.
  5265. *)
  5266. {$IFDEF S}function{$ELSE}var{$ENDIF}sqlite3_blob_write{$IFDEF D}: function{$ENDIF}(blob: psqlite3_blob; Z: pointer; N: cint; iOffset: cint): cint; cdecl;{$IFDEF S}external Sqlite3Lib;{$ENDIF}
  5267. (*
  5268. ** CAPI3REF: Virtual File System Objects {F11200}
  5269. **
  5270. ** A virtual filesystem (VFS) is an [sqlite3_vfs] object
  5271. ** that SQLite uses to cinteract
  5272. ** with the underlying operating system. Most SQLite builds come with a
  5273. ** single default VFS that is appropriate for the host computer.
  5274. ** New VFSes can be registered and existing VFSes can be unregistered.
  5275. ** The following interfaces are provided.
  5276. **
  5277. ** The sqlite3_vfs_find() interface returns a pointer to
  5278. ** a VFS given its name. Names are case sensitive.
  5279. ** Names are zero-terminated UTF-8 strings.
  5280. ** If there is no match; a NULL
  5281. ** pointer is returned. If zVfsName is NULL then the default
  5282. ** VFS is returned.
  5283. **
  5284. ** New VFSes are registered with sqlite3_vfs_register().
  5285. ** Each new VFS becomes the default VFS if the makeDflt flag is set.
  5286. ** The same VFS can be registered multiple times without injury.
  5287. ** To make an existing VFS cinto the default VFS; register it again
  5288. ** with the makeDflt flag set. If two different VFSes with the
  5289. ** same name are registered; the behavior is undefined. If a
  5290. ** VFS is registered with a name that is NULL or an empty string;
  5291. ** then the behavior is undefined.
  5292. **
  5293. ** Unregister a VFS with the sqlite3_vfs_unregister() interface.
  5294. ** If the default VFS is unregistered; another VFS is chosen as
  5295. ** the default. The choice for the new VFS is arbitrary.
  5296. **
  5297. ** INVARIANTS:
  5298. **
  5299. ** {F11203} The [sqlite3_vfs_find(N)] interface returns a pointer to the
  5300. ** registered [sqlite3_vfs] object whose name exactly matches
  5301. ** the zero-terminated UTF-8 string N; or it returns NULL if
  5302. ** there is no match.
  5303. **
  5304. ** {F11206} If the N parameter to [sqlite3_vfs_find(N)] is NULL then
  5305. ** the function returns a pointer to the default [sqlite3_vfs]
  5306. ** object if there is one; or NULL if there is no default
  5307. ** [sqlite3_vfs] object.
  5308. **
  5309. ** {F11209} The [sqlite3_vfs_register(P;F)] interface registers the
  5310. ** well-formed [sqlite3_vfs] object P using the name given
  5311. ** by the zName field of the object.
  5312. **
  5313. ** {F11212} Using the [sqlite3_vfs_register(P;F)] interface to register
  5314. ** the same [sqlite3_vfs] object multiple times is a harmless no-op.
  5315. **
  5316. ** {F11215} The [sqlite3_vfs_register(P;F)] interface makes the
  5317. ** the [sqlite3_vfs] object P the default [sqlite3_vfs] object
  5318. ** if F is non-zero.
  5319. **
  5320. ** {F11218} The [sqlite3_vfs_unregister(P)] interface unregisters the
  5321. ** [sqlite3_vfs] object P so that it is no longer returned by
  5322. ** subsequent calls to [sqlite3_vfs_find()].
  5323. *)
  5324. {$IFDEF S}function{$ELSE}var{$ENDIF}sqlite3_vfs_find{$IFDEF D}: function{$ENDIF}(zVfsName: pchar): psqlite3_vfs; cdecl;{$IFDEF S}external Sqlite3Lib;{$ENDIF}
  5325. {$IFDEF S}function{$ELSE}var{$ENDIF}sqlite3_vfs_register{$IFDEF D}: function{$ENDIF}(vfs: psqlite3_vfs; makeDflt: cint): cint; cdecl;{$IFDEF S}external Sqlite3Lib;{$ENDIF}
  5326. {$IFDEF S}function{$ELSE}var{$ENDIF}sqlite3_vfs_unregister{$IFDEF D}: function{$ENDIF}(vfs: psqlite3_vfs): cint; cdecl;{$IFDEF S}external Sqlite3Lib;{$ENDIF}
  5327. (*
  5328. ** CAPI3REF: Mutexes {F17000}
  5329. **
  5330. ** The SQLite core uses these routines for thread
  5331. ** synchronization. Though they are cintended for cinternal
  5332. ** use by SQLite; code that links against SQLite is
  5333. ** permitted to use any of these routines.
  5334. **
  5335. ** The SQLite source code contains multiple implementations
  5336. ** of these mutex routines. An appropriate implementation
  5337. ** is selected automatically at compile-time. The following
  5338. ** implementations are available in the SQLite core:
  5339. **
  5340. ** <ul>
  5341. ** <li> SQLITE_MUTEX_OS2
  5342. ** <li> SQLITE_MUTEX_PTHREAD
  5343. ** <li> SQLITE_MUTEX_W32
  5344. ** <li> SQLITE_MUTEX_NOOP
  5345. ** </ul>
  5346. **
  5347. ** The SQLITE_MUTEX_NOOP implementation is a set of routines
  5348. ** that does no real locking and is appropriate for use in
  5349. ** a single-threaded application. The SQLITE_MUTEX_OS2;
  5350. ** SQLITE_MUTEX_PTHREAD; and SQLITE_MUTEX_W32 implementations
  5351. ** are appropriate for use on os/2; unix; and windows.
  5352. **
  5353. ** If SQLite is compiled with the SQLITE_MUTEX_APPDEF preprocessor
  5354. ** macro defined (with "-DSQLITE_MUTEX_APPDEF=1"); then no mutex
  5355. ** implementation is included with the library. The
  5356. ** mutex interface routines defined here become external
  5357. ** references in the SQLite library for which implementations
  5358. ** must be provided by the application. This facility allows an
  5359. ** application that links against SQLite to provide its own mutex
  5360. ** implementation without having to modify the SQLite core.
  5361. **
  5362. ** {F17011} The sqlite3_mutex_alloc() routine allocates a new
  5363. ** mutex and returns a pointer to it. {F17012} If it returns NULL
  5364. ** that means that a mutex could not be allocated. {F17013} SQLite
  5365. ** will unwind its stack and return an error. {F17014} The argument
  5366. ** to sqlite3_mutex_alloc() is one of these INTEGER constants:
  5367. **
  5368. ** <ul>
  5369. ** <li> SQLITE_MUTEX_FAST
  5370. ** <li> SQLITE_MUTEX_RECURSIVE
  5371. ** <li> SQLITE_MUTEX_STATIC_MASTER
  5372. ** <li> SQLITE_MUTEX_STATIC_MEM
  5373. ** <li> SQLITE_MUTEX_STATIC_MEM2
  5374. ** <li> SQLITE_MUTEX_STATIC_PRNG
  5375. ** <li> SQLITE_MUTEX_STATIC_LRU
  5376. ** <li> SQLITE_MUTEX_STATIC_LRU2
  5377. ** </ul> {END}
  5378. **
  5379. ** {F17015} The first two constants cause sqlite3_mutex_alloc() to create
  5380. ** a new mutex. The new mutex is recursive when SQLITE_MUTEX_RECURSIVE
  5381. ** is used but not necessarily so when SQLITE_MUTEX_FAST is used. {END}
  5382. ** The mutex implementation does not need to make a distinction
  5383. ** between SQLITE_MUTEX_RECURSIVE and SQLITE_MUTEX_FAST if it does
  5384. ** not want to. {F17016} But SQLite will only request a recursive mutex in
  5385. ** cases where it really needs one. {END} If a faster non-recursive mutex
  5386. ** implementation is available on the host platform; the mutex subsystem
  5387. ** might return such a mutex in response to SQLITE_MUTEX_FAST.
  5388. **
  5389. ** {F17017} The other allowed parameters to sqlite3_mutex_alloc() each return
  5390. ** a pointer to a static preexisting mutex. {END} Four static mutexes are
  5391. ** used by the current version of SQLite. Future versions of SQLite
  5392. ** may add additional static mutexes. Static mutexes are for cinternal
  5393. ** use by SQLite only. Applications that use SQLite mutexes should
  5394. ** use only the dynamic mutexes returned by SQLITE_MUTEX_FAST or
  5395. ** SQLITE_MUTEX_RECURSIVE.
  5396. **
  5397. ** {F17018} Note that if one of the dynamic mutex parameters (SQLITE_MUTEX_FAST
  5398. ** or SQLITE_MUTEX_RECURSIVE) is used then sqlite3_mutex_alloc()
  5399. ** returns a different mutex on every call. {F17034} But for the static
  5400. ** mutex types; the same mutex is returned on every call that has
  5401. ** the same type number. {END}
  5402. **
  5403. ** {F17019} The sqlite3_mutex_free() routine deallocates a previously
  5404. ** allocated dynamic mutex. {F17020} SQLite is careful to deallocate every
  5405. ** dynamic mutex that it allocates. {U17021} The dynamic mutexes must not be in
  5406. ** use when they are deallocated. {U17022} Attempting to deallocate a static
  5407. ** mutex results in undefined behavior. {F17023} SQLite never deallocates
  5408. ** a static mutex. {END}
  5409. **
  5410. ** The sqlite3_mutex_enter() and sqlite3_mutex_try() routines attempt
  5411. ** to enter a mutex. {F17024} If another thread is already within the mutex;
  5412. ** sqlite3_mutex_enter() will block and sqlite3_mutex_try() will return
  5413. ** SQLITE_BUSY. {F17025} The sqlite3_mutex_try() interface returns SQLITE_OK
  5414. ** upon successful entry. {F17026} Mutexes created using
  5415. ** SQLITE_MUTEX_RECURSIVE can be entered multiple times by the same thread.
  5416. ** {F17027} In such cases the;
  5417. ** mutex must be exited an equal number of times before another thread
  5418. ** can enter. {U17028} If the same thread tries to enter any other
  5419. ** kind of mutex more than once; the behavior is undefined.
  5420. ** {F17029} SQLite will never exhibit
  5421. ** such behavior in its own use of mutexes. {END}
  5422. **
  5423. ** Some systems (ex: windows95) do not the operation implemented by
  5424. ** sqlite3_mutex_try(). On those systems; sqlite3_mutex_try() will
  5425. ** always return SQLITE_BUSY. {F17030} The SQLite core only ever uses
  5426. ** sqlite3_mutex_try() as an optimization so this is acceptable behavior. {END}
  5427. **
  5428. ** {F17031} The sqlite3_mutex_leave() routine exits a mutex that was
  5429. ** previously entered by the same thread. {U17032} The behavior
  5430. ** is undefined if the mutex is not currently entered by the
  5431. ** calling thread or is not currently allocated. {F17033} SQLite will
  5432. ** never do either. {END}
  5433. **
  5434. ** See also: [sqlite3_mutex_held()] and [sqlite3_mutex_notheld()].
  5435. *)
  5436. {$IFDEF S}function{$ELSE}var{$ENDIF}sqlite3_mutex_alloc{$IFDEF D}: function{$ENDIF}(n: cint): psqlite3_mutex; cdecl;{$IFDEF S}external Sqlite3Lib;{$ENDIF}
  5437. {$IFDEF S}procedure{$ELSE}var{$ENDIF}sqlite3_mutex_free{$IFDEF D}: procedure{$ENDIF}(mtx: psqlite3_mutex); cdecl;{$IFDEF S}external Sqlite3Lib;{$ENDIF}
  5438. {$IFDEF S}procedure{$ELSE}var{$ENDIF}sqlite3_mutex_ente{$IFDEF D}: procedure{$ENDIF}(mtx: psqlite3_mutex); cdecl;{$IFDEF S}external Sqlite3Lib;{$ENDIF}
  5439. {$IFDEF S}function{$ELSE}var{$ENDIF}sqlite3_mutex_try{$IFDEF D}: function{$ENDIF}(mtx: psqlite3_mutex): cint; cdecl;{$IFDEF S}external Sqlite3Lib;{$ENDIF}
  5440. {$IFDEF S}procedure{$ELSE}var{$ENDIF}sqlite3_mutex_leave{$IFDEF D}: procedure{$ENDIF}(mtx: psqlite3_mutex); cdecl;{$IFDEF S}external Sqlite3Lib;{$ENDIF}
  5441. (*
  5442. ** CAPI3REF: Mutex Verifcation Routines {F17080}
  5443. **
  5444. ** The sqlite3_mutex_held() and sqlite3_mutex_notheld() routines
  5445. ** are cintended for use inside assert() statements. {F17081} The SQLite core
  5446. ** never uses these routines except inside an assert() and applications
  5447. ** are advised to follow the lead of the core. {F17082} The core only
  5448. ** provides implementations for these routines when it is compiled
  5449. ** with the SQLITE_DEBUG flag. {U17087} External mutex implementations
  5450. ** are only required to provide these routines if SQLITE_DEBUG is
  5451. ** defined and if NDEBUG is not defined.
  5452. **
  5453. ** {F17083} These routines should return true if the mutex in their argument
  5454. ** is held or not held; respectively; by the calling thread. {END}
  5455. **
  5456. ** {X17084} The implementation is not required to provided versions of these
  5457. ** routines that actually work.
  5458. ** If the implementation does not provide working
  5459. ** versions of these routines; it should at least provide stubs
  5460. ** that always return true so that one does not get spurious
  5461. ** assertion failures. {END}
  5462. **
  5463. ** {F17085} If the argument to sqlite3_mutex_held() is a NULL pointer then
  5464. ** the routine should return 1. {END} This seems counter-cintuitive since
  5465. ** clearly the mutex cannot be held if it does not exist. But the
  5466. ** the reason the mutex does not exist is because the build is not
  5467. ** using mutexes. And we do not want the assert() containing the
  5468. ** call to sqlite3_mutex_held() to fail; so a non-zero return is
  5469. ** the appropriate thing to do. {F17086} The sqlite3_mutex_notheld()
  5470. ** interface should also return 1 when given a NULL pointer.
  5471. *)
  5472. {$IFDEF S}function{$ELSE}var{$ENDIF}sqlite3_mutex_held{$IFDEF D}: function{$ENDIF}(mtx: psqlite3_mutex): cint; cdecl;{$IFDEF S}external Sqlite3Lib;{$ENDIF}
  5473. {$IFDEF S}function{$ELSE}var{$ENDIF}sqlite3_mutex_notheld{$IFDEF D}: function{$ENDIF}(mtx: psqlite3_mutex): cint; cdecl;{$IFDEF S}external Sqlite3Lib;{$ENDIF}
  5474. (*
  5475. ** CAPI3REF: Mutex Types {F17001}
  5476. **
  5477. ** {F17002} The [sqlite3_mutex_alloc()] interface takes a single argument
  5478. ** which is one of these INTEGER constants. {END}
  5479. *)
  5480. const
  5481. SQLITE_MUTEX_FAST = 0;
  5482. SQLITE_MUTEX_RECURSIVE = 1;
  5483. SQLITE_MUTEX_STATIC_MASTER = 2;
  5484. SQLITE_MUTEX_STATIC_MEM = 3; (* sqlite3_malloc() *)
  5485. SQLITE_MUTEX_STATIC_MEM2 = 4; (* sqlite3_release_memory() *)
  5486. SQLITE_MUTEX_STATIC_PRNG = 5; (* sqlite3_random() *)
  5487. SQLITE_MUTEX_STATIC_LRU = 6; (* lru page list *)
  5488. SQLITE_MUTEX_STATIC_LRU2 = 7; (* lru page list *)
  5489. (*
  5490. ** CAPI3REF: Low-Level Control Of Database Files {F11300}
  5491. **
  5492. ** {F11301} The [sqlite3_file_control()] interface makes a direct call to the
  5493. ** xFileControl method for the [sqlite3_io_methods] object associated
  5494. ** with a particular database identified by the second argument. {F11302} The
  5495. ** name of the database is the name assigned to the database by the
  5496. ** <a href="lang_attach.html">ATTACH</a> SQL command that opened the
  5497. ** database. {F11303} To control the main database file; use the name "main"
  5498. ** or a NULL pointer. {F11304} The third and fourth parameters to this routine
  5499. ** are passed directly through to the second and third parameters of
  5500. ** the xFileControl method. {F11305} The return value of the xFileControl
  5501. ** method becomes the return value of this routine.
  5502. **
  5503. ** {F11306} If the second parameter (zDbName) does not match the name of any
  5504. ** open database file; then SQLITE_ERROR is returned. {F11307} This error
  5505. ** code is not remembered and will not be recalled by [sqlite3_errcode()]
  5506. ** or [sqlite3_errmsg()]. {U11308} The underlying xFileControl method might
  5507. ** also return SQLITE_ERROR. {U11309} There is no way to distinguish between
  5508. ** an incorrect zDbName and an SQLITE_ERROR return from the underlying
  5509. ** xFileControl method. {END}
  5510. **
  5511. ** See also: [SQLITE_FCNTL_LOCKSTATE]
  5512. *)
  5513. {$IFDEF S}function{$ELSE}var{$ENDIF}sqlite3_file_control{$IFDEF D}: function{$ENDIF}(db: psqlite3; zDbName: pchar; op: cint; p: pointer): cint; cdecl;{$IFDEF S}external Sqlite3Lib;{$ENDIF}
  5514. (*
  5515. ** CAPI3REF: Testing interface {F11400}
  5516. **
  5517. ** The sqlite3_test_control() interface is used to read out cinternal
  5518. ** state of SQLite and to inject faults cinto SQLite for testing
  5519. ** purposes. The first parameter a operation code that determines
  5520. ** the number; meaning; and operation of all subsequent parameters.
  5521. **
  5522. ** This interface is not for use by applications. It exists solely
  5523. ** for verifying the correct operation of the SQLite library. Depending
  5524. ** on how the SQLite library is compiled; this interface might not exist.
  5525. **
  5526. ** The details of the operation codes; their meanings; the parameters
  5527. ** they take; and what they do are all subject to change without notice.
  5528. ** Unlike most of the SQLite API; this function is not guaranteed to
  5529. ** operate consistently from one release to the next.
  5530. *)
  5531. {$IFDEF S}function{$ELSE}var{$ENDIF}sqlite3_test_control{$IFDEF D}: function{$ENDIF}(op: cint; args: array of const): cint; cdecl;{$IFDEF S}external Sqlite3Lib;{$ENDIF}
  5532. (*
  5533. ** CAPI3REF: Testing interface Operation Codes {F11410}
  5534. **
  5535. ** These constants are the valid operation code parameters used
  5536. ** as the first argument to [sqlite3_test_control()].
  5537. **
  5538. ** These parameters and their meansing are subject to change
  5539. ** without notice. These values are for testing purposes only.
  5540. ** Applications should not use any of these parameters or the
  5541. ** [sqlite3_test_control()] interface.
  5542. *)
  5543. const
  5544. SQLITE_TESTCTRL_FAULT_CONFIG = 1;
  5545. SQLITE_TESTCTRL_FAULT_FAILURES = 2;
  5546. SQLITE_TESTCTRL_FAULT_BENIGN_FAILURES = 3;
  5547. SQLITE_TESTCTRL_FAULT_PENDING = 4;
  5548. SQLITE_TESTCTRL_PRNG_SAVE = 5;
  5549. SQLITE_TESTCTRL_PRNG_RESTORE = 6;
  5550. SQLITE_TESTCTRL_PRNG_RESET = 7;
  5551. SQLITE_TESTCTRL_BITVEC_TEST = 8;
  5552. {$IFDEF LOAD_DYNAMICALLY}
  5553. function InitializeSqlite(const LibraryName: String = ''): Integer;
  5554. function TryInitializeSqlite(const LibraryName: string = ''): Integer;
  5555. function ReleaseSqlite: Integer;
  5556. function InitialiseSQLite: Integer; deprecated;
  5557. function InitialiseSQLite(const LibraryName: String): Integer; deprecated;
  5558. var
  5559. SQLiteLibraryHandle: TLibHandle;
  5560. SQLiteDefaultLibrary: String = Sqlite3Lib;
  5561. {$ENDIF LOAD_DYNAMICALLY}
  5562. implementation
  5563. function sqlite3_version(): pchar;
  5564. begin
  5565. Result := sqlite3_libversion();
  5566. end;
  5567. {$IFDEF LOAD_DYNAMICALLY}
  5568. resourcestring
  5569. SErrLoadFailed = 'Can not load SQLite client library "%s". Check your installation.';
  5570. SErrAlreadyLoaded = 'SQLIte interface already initialized from library %s.';
  5571. procedure LoadAddresses(LibHandle: TLibHandle);
  5572. begin
  5573. pointer(sqlite3_libversion) := GetProcedureAddress(LibHandle,'sqlite3_libversion');
  5574. pointer(sqlite3_libversion_number) := GetProcedureAddress(LibHandle,'sqlite3_libversion_number');
  5575. pointer(sqlite3_threadsafe) := GetProcedureAddress(LibHandle,'sqlite3_threadsafe');
  5576. pointer(sqlite3_close) := GetProcedureAddress(LibHandle,'sqlite3_close');
  5577. pointer(sqlite3_exec) := GetProcedureAddress(LibHandle,'sqlite3_exec');
  5578. pointer(sqlite3_extended_result_codes) := GetProcedureAddress(LibHandle,'sqlite3_extended_result_codes');
  5579. pointer(sqlite3_last_insert_rowid) := GetProcedureAddress(LibHandle,'sqlite3_last_insert_rowid');
  5580. pointer(sqlite3_changes) := GetProcedureAddress(LibHandle,'sqlite3_changes');
  5581. pointer(sqlite3_total_changes) := GetProcedureAddress(LibHandle,'sqlite3_total_changes');
  5582. pointer(sqlite3_complete) := GetProcedureAddress(LibHandle,'sqlite3_complete');
  5583. pointer(sqlite3_complete16) := GetProcedureAddress(LibHandle,'sqlite3_complete16');
  5584. pointer(sqlite3_busy_handler) := GetProcedureAddress(LibHandle,'sqlite3_busy_handler');
  5585. pointer(sqlite3_busy_timeout) := GetProcedureAddress(LibHandle,'sqlite3_busy_timeout');
  5586. pointer(sqlite3_get_table) := GetProcedureAddress(LibHandle,'sqlite3_get_table');
  5587. pointer(sqlite3_malloc) := GetProcedureAddress(LibHandle,'sqlite3_malloc');
  5588. pointer(sqlite3_realloc) := GetProcedureAddress(LibHandle,'sqlite3_realloc');
  5589. pointer(sqlite3_memory_used) := GetProcedureAddress(LibHandle,'sqlite3_memory_used');
  5590. pointer(sqlite3_memory_highwater) := GetProcedureAddress(LibHandle,'sqlite3_memory_highwater');
  5591. pointer(sqlite3_set_authorizer) := GetProcedureAddress(LibHandle,'sqlite3_set_authorizer');
  5592. pointer(sqlite3_trace) := GetProcedureAddress(LibHandle,'sqlite3_trace');
  5593. pointer(sqlite3_profile) := GetProcedureAddress(LibHandle,'sqlite3_profile');
  5594. pointer(sqlite3_open) := GetProcedureAddress(LibHandle,'sqlite3_open');
  5595. pointer(sqlite3_open16) := GetProcedureAddress(LibHandle,'sqlite3_open16');
  5596. pointer(sqlite3_open_v2) := GetProcedureAddress(LibHandle,'sqlite3_open_v2');
  5597. pointer(sqlite3_errcode) := GetProcedureAddress(LibHandle,'sqlite3_errcode');
  5598. pointer(sqlite3_errmsg) := GetProcedureAddress(LibHandle,'sqlite3_errmsg');
  5599. pointer(sqlite3_errmsg16) := GetProcedureAddress(LibHandle,'sqlite3_errmsg16');
  5600. pointer(sqlite3_limit) := GetProcedureAddress(LibHandle,'sqlite3_limit');
  5601. pointer(sqlite3_prepare) := GetProcedureAddress(LibHandle,'sqlite3_prepare');
  5602. pointer(sqlite3_prepare_v2) := GetProcedureAddress(LibHandle,'sqlite3_prepare_v2');
  5603. pointer(sqlite3_prepare16) := GetProcedureAddress(LibHandle,'sqlite3_prepare16');
  5604. pointer(sqlite3_prepare16_v2) := GetProcedureAddress(LibHandle,'sqlite3_prepare16_v2');
  5605. pointer(sqlite3_sql) := GetProcedureAddress(LibHandle,'sqlite3_sql');
  5606. pointer(sqlite3_bind_blob) := GetProcedureAddress(LibHandle,'sqlite3_bind_blob');
  5607. pointer(sqlite3_bind_double) := GetProcedureAddress(LibHandle,'sqlite3_bind_double');
  5608. pointer(sqlite3_bind_int) := GetProcedureAddress(LibHandle,'sqlite3_bind_int');
  5609. pointer(sqlite3_bind_int64) := GetProcedureAddress(LibHandle,'sqlite3_bind_int64');
  5610. pointer(sqlite3_bind_null) := GetProcedureAddress(LibHandle,'sqlite3_bind_null');
  5611. pointer(sqlite3_bind_text) := GetProcedureAddress(LibHandle,'sqlite3_bind_text');
  5612. pointer(sqlite3_bind_text16) := GetProcedureAddress(LibHandle,'sqlite3_bind_text16');
  5613. pointer(sqlite3_bind_value) := GetProcedureAddress(LibHandle,'sqlite3_bind_value');
  5614. pointer(sqlite3_bind_zeroblob) := GetProcedureAddress(LibHandle,'sqlite3_bind_zeroblob');
  5615. pointer(sqlite3_bind_parameter_count) := GetProcedureAddress(LibHandle,'sqlite3_bind_parameter_count');
  5616. pointer(sqlite3_bind_parameter_name) := GetProcedureAddress(LibHandle,'sqlite3_bind_parameter_name');
  5617. pointer(sqlite3_bind_parameter_index) := GetProcedureAddress(LibHandle,'sqlite3_bind_parameter_index');
  5618. pointer(sqlite3_clear_bindings) := GetProcedureAddress(LibHandle,'sqlite3_clear_bindings');
  5619. pointer(sqlite3_column_count) := GetProcedureAddress(LibHandle,'sqlite3_column_count');
  5620. pointer(sqlite3_column_name) := GetProcedureAddress(LibHandle,'sqlite3_column_name');
  5621. pointer(sqlite3_column_name16) := GetProcedureAddress(LibHandle,'sqlite3_column_name16');
  5622. pointer(sqlite3_column_database_name) := GetProcedureAddress(LibHandle,'sqlite3_column_database_name');
  5623. pointer(sqlite3_column_database_name16) := GetProcedureAddress(LibHandle,'sqlite3_column_database_name16');
  5624. pointer(sqlite3_column_table_name) := GetProcedureAddress(LibHandle,'sqlite3_column_table_name');
  5625. pointer(sqlite3_column_table_name16) := GetProcedureAddress(LibHandle,'sqlite3_column_table_name16');
  5626. pointer(sqlite3_column_origin_name) := GetProcedureAddress(LibHandle,'sqlite3_column_origin_name');
  5627. pointer(sqlite3_column_origin_name16) := GetProcedureAddress(LibHandle,'sqlite3_column_origin_name16');
  5628. pointer(sqlite3_column_decltype) := GetProcedureAddress(LibHandle,'sqlite3_column_decltype');
  5629. pointer(sqlite3_column_decltype16) := GetProcedureAddress(LibHandle,'sqlite3_column_decltype16');
  5630. pointer(sqlite3_step) := GetProcedureAddress(LibHandle,'sqlite3_step');
  5631. pointer(sqlite3_data_count) := GetProcedureAddress(LibHandle,'sqlite3_data_count');
  5632. pointer(sqlite3_column_blob) := GetProcedureAddress(LibHandle,'sqlite3_column_blob');
  5633. pointer(sqlite3_column_bytes) := GetProcedureAddress(LibHandle,'sqlite3_column_bytes');
  5634. pointer(sqlite3_column_bytes16) := GetProcedureAddress(LibHandle,'sqlite3_column_bytes16');
  5635. pointer(sqlite3_column_double) := GetProcedureAddress(LibHandle,'sqlite3_column_double');
  5636. pointer(sqlite3_column_int) := GetProcedureAddress(LibHandle,'sqlite3_column_int');
  5637. pointer(sqlite3_column_int64) := GetProcedureAddress(LibHandle,'sqlite3_column_int64');
  5638. pointer(sqlite3_column_text) := GetProcedureAddress(LibHandle,'sqlite3_column_text');
  5639. pointer(sqlite3_column_text16) := GetProcedureAddress(LibHandle,'sqlite3_column_text16');
  5640. pointer(sqlite3_column_type) := GetProcedureAddress(LibHandle,'sqlite3_column_type');
  5641. pointer(sqlite3_column_value) := GetProcedureAddress(LibHandle,'sqlite3_column_value');
  5642. pointer(sqlite3_finalize) := GetProcedureAddress(LibHandle,'sqlite3_finalize');
  5643. pointer(sqlite3_reset) := GetProcedureAddress(LibHandle,'sqlite3_reset');
  5644. pointer(sqlite3_create_function) := GetProcedureAddress(LibHandle,'sqlite3_create_function');
  5645. pointer(sqlite3_create_function16) := GetProcedureAddress(LibHandle,'sqlite3_create_function16');
  5646. pointer(sqlite3_value_blob) := GetProcedureAddress(LibHandle,'sqlite3_value_blob');
  5647. pointer(sqlite3_value_bytes) := GetProcedureAddress(LibHandle,'sqlite3_value_bytes');
  5648. pointer(sqlite3_value_bytes16) := GetProcedureAddress(LibHandle,'sqlite3_value_bytes16');
  5649. pointer(sqlite3_value_double) := GetProcedureAddress(LibHandle,'sqlite3_value_double');
  5650. pointer(sqlite3_value_int) := GetProcedureAddress(LibHandle,'sqlite3_value_int');
  5651. pointer(sqlite3_value_int64) := GetProcedureAddress(LibHandle,'sqlite3_value_int64');
  5652. pointer(sqlite3_value_text) := GetProcedureAddress(LibHandle,'sqlite3_value_text');
  5653. pointer(sqlite3_value_text16) := GetProcedureAddress(LibHandle,'sqlite3_value_text16');
  5654. pointer(sqlite3_value_text16le) := GetProcedureAddress(LibHandle,'sqlite3_value_text16le');
  5655. pointer(sqlite3_value_text16be) := GetProcedureAddress(LibHandle,'sqlite3_value_text16be');
  5656. pointer(sqlite3_value_type) := GetProcedureAddress(LibHandle,'sqlite3_value_type');
  5657. pointer(sqlite3_value_numeric_type) := GetProcedureAddress(LibHandle,'sqlite3_value_numeric_type');
  5658. pointer(sqlite3_aggregate_context) := GetProcedureAddress(LibHandle,'sqlite3_aggregate_context');
  5659. pointer(sqlite3_user_data) := GetProcedureAddress(LibHandle,'sqlite3_user_data');
  5660. pointer(sqlite3_context_db_handle) := GetProcedureAddress(LibHandle,'sqlite3_context_db_handle');
  5661. pointer(sqlite3_get_auxdata) := GetProcedureAddress(LibHandle,'sqlite3_get_auxdata');
  5662. pointer(sqlite3_create_collation) := GetProcedureAddress(LibHandle,'sqlite3_create_collation');
  5663. pointer(sqlite3_create_collation_v2) := GetProcedureAddress(LibHandle,'sqlite3_create_collation_v2');
  5664. pointer(sqlite3_create_collation16) := GetProcedureAddress(LibHandle,'sqlite3_create_collation16');
  5665. pointer(sqlite3_collation_needed) := GetProcedureAddress(LibHandle,'sqlite3_collation_needed');
  5666. pointer(sqlite3_collation_needed16) := GetProcedureAddress(LibHandle,'sqlite3_collation_needed16');
  5667. pointer(sqlite3_key) := GetProcedureAddress(LibHandle,'sqlite3_key');
  5668. pointer(sqlite3_rekey) := GetProcedureAddress(LibHandle,'sqlite3_rekey');
  5669. pointer(sqlite3_sleep) := GetProcedureAddress(LibHandle,'sqlite3_sleep');
  5670. pointer(sqlite3_get_autocommit) := GetProcedureAddress(LibHandle,'sqlite3_get_autocommit');
  5671. pointer(sqlite3_db_handle) := GetProcedureAddress(LibHandle,'sqlite3_db_handle');
  5672. pointer(sqlite3_commit_hook) := GetProcedureAddress(LibHandle,'sqlite3_commit_hook');
  5673. pointer(sqlite3_rollback_hook) := GetProcedureAddress(LibHandle,'sqlite3_rollback_hook');
  5674. pointer(sqlite3_update_hook) := GetProcedureAddress(LibHandle,'sqlite3_update_hook');
  5675. pointer(sqlite3_enable_shared_cache) := GetProcedureAddress(LibHandle,'sqlite3_enable_shared_cache');
  5676. pointer(sqlite3_release_memory) := GetProcedureAddress(LibHandle,'sqlite3_release_memory');
  5677. pointer(sqlite3_table_column_metadata) := GetProcedureAddress(LibHandle,'sqlite3_table_column_metadata');
  5678. pointer(sqlite3_load_extension) := GetProcedureAddress(LibHandle,'sqlite3_load_extension');
  5679. pointer(sqlite3_enable_load_extension) := GetProcedureAddress(LibHandle,'sqlite3_enable_load_extension');
  5680. pointer(sqlite3_auto_extension) := GetProcedureAddress(LibHandle,'sqlite3_auto_extension');
  5681. pointer(sqlite3_create_module) := GetProcedureAddress(LibHandle,'sqlite3_create_module');
  5682. pointer(sqlite3_create_module_v2) := GetProcedureAddress(LibHandle,'sqlite3_create_module_v2');
  5683. pointer(sqlite3_declare_vtab) := GetProcedureAddress(LibHandle,'sqlite3_declare_vtab');
  5684. pointer(sqlite3_overload_function) := GetProcedureAddress(LibHandle,'sqlite3_overload_function');
  5685. pointer(sqlite3_blob_open) := GetProcedureAddress(LibHandle,'sqlite3_blob_open');
  5686. pointer(sqlite3_blob_close) := GetProcedureAddress(LibHandle,'sqlite3_blob_close');
  5687. pointer(sqlite3_blob_bytes) := GetProcedureAddress(LibHandle,'sqlite3_blob_bytes');
  5688. pointer(sqlite3_blob_read) := GetProcedureAddress(LibHandle,'sqlite3_blob_read');
  5689. pointer(sqlite3_blob_write) := GetProcedureAddress(LibHandle,'sqlite3_blob_write');
  5690. pointer(sqlite3_vfs_find) := GetProcedureAddress(LibHandle,'sqlite3_vfs_find');
  5691. pointer(sqlite3_vfs_register) := GetProcedureAddress(LibHandle,'sqlite3_vfs_register');
  5692. pointer(sqlite3_vfs_unregister) := GetProcedureAddress(LibHandle,'sqlite3_vfs_unregister');
  5693. pointer(sqlite3_mutex_alloc) := GetProcedureAddress(LibHandle,'sqlite3_mutex_alloc');
  5694. pointer(sqlite3_mutex_try) := GetProcedureAddress(LibHandle,'sqlite3_mutex_try');
  5695. pointer(sqlite3_mutex_held) := GetProcedureAddress(LibHandle,'sqlite3_mutex_held');
  5696. pointer(sqlite3_mutex_notheld) := GetProcedureAddress(LibHandle,'sqlite3_mutex_notheld');
  5697. pointer(sqlite3_file_control) := GetProcedureAddress(LibHandle,'sqlite3_file_control');
  5698. pointer(sqlite3_test_control) := GetProcedureAddress(LibHandle,'sqlite3_test_control');
  5699. pointer(sqlite3_interrupt) := GetProcedureAddress(LibHandle,'sqlite3_interrupt');
  5700. pointer(sqlite3_free_table) := GetProcedureAddress(LibHandle,'sqlite3_free_table');
  5701. pointer(sqlite3_free) := GetProcedureAddress(LibHandle,'sqlite3_free');
  5702. pointer(sqlite3_randomness) := GetProcedureAddress(LibHandle,'sqlite3_randomness');
  5703. pointer(sqlite3_progress_handler) := GetProcedureAddress(LibHandle,'sqlite3_progress_handler');
  5704. pointer(sqlite3_set_auxdata) := GetProcedureAddress(LibHandle,'sqlite3_set_auxdata');
  5705. pointer(sqlite3_result_blob) := GetProcedureAddress(LibHandle,'sqlite3_result_blob');
  5706. pointer(sqlite3_result_double) := GetProcedureAddress(LibHandle,'sqlite3_result_double');
  5707. pointer(sqlite3_result_error) := GetProcedureAddress(LibHandle,'sqlite3_result_error');
  5708. pointer(sqlite3_result_error16) := GetProcedureAddress(LibHandle,'sqlite3_result_error16');
  5709. pointer(sqlite3_result_error_toobig) := GetProcedureAddress(LibHandle,'sqlite3_result_error_toobig');
  5710. pointer(sqlite3_result_error_nomem) := GetProcedureAddress(LibHandle,'sqlite3_result_error_nomem');
  5711. pointer(sqlite3_result_error_code) := GetProcedureAddress(LibHandle,'sqlite3_result_error_code');
  5712. pointer(sqlite3_result_cint) := GetProcedureAddress(LibHandle,'sqlite3_result_cint');
  5713. pointer(sqlite3_result_cint64) := GetProcedureAddress(LibHandle,'sqlite3_result_cint64');
  5714. pointer(sqlite3_result_null) := GetProcedureAddress(LibHandle,'sqlite3_result_null');
  5715. pointer(sqlite3_result_text) := GetProcedureAddress(LibHandle,'sqlite3_result_text');
  5716. pointer(sqlite3_result_text16) := GetProcedureAddress(LibHandle,'sqlite3_result_text16');
  5717. pointer(sqlite3_result_text16le) := GetProcedureAddress(LibHandle,'sqlite3_result_text16le');
  5718. pointer(sqlite3_result_text16be) := GetProcedureAddress(LibHandle,'sqlite3_result_text16be');
  5719. pointer(sqlite3_result_value) := GetProcedureAddress(LibHandle,'sqlite3_result_value');
  5720. pointer(sqlite3_result_zeroblob) := GetProcedureAddress(LibHandle,'sqlite3_result_zeroblob');
  5721. pointer(sqlite3_soft_heap_limit) := GetProcedureAddress(LibHandle,'sqlite3_soft_heap_limit');
  5722. pointer(sqlite3_reset_auto_extension) := GetProcedureAddress(LibHandle,'sqlite3_reset_auto_extension');
  5723. pointer(sqlite3_mutex_free) := GetProcedureAddress(LibHandle,'sqlite3_mutex_free');
  5724. pointer(sqlite3_mutex_ente) := GetProcedureAddress(LibHandle,'sqlite3_mutex_ente');
  5725. pointer(sqlite3_mutex_leave) := GetProcedureAddress(LibHandle,'sqlite3_mutex_leave');
  5726. {$IFDEF SQLITE_OBSOLETE}
  5727. pointer(sqlite3_aggregate_count) := GetProcedureAddress(LibHandle,'sqlite3_aggregate_count');
  5728. pointer(sqlite3_expired) := GetProcedureAddress(LibHandle,'sqlite3_expired');
  5729. pointer(sqlite3_transfer_bindings) := GetProcedureAddress(LibHandle,'sqlite3_transfer_bindings');
  5730. pointer(sqlite3_global_recover) := GetProcedureAddress(LibHandle,'sqlite3_global_recover');
  5731. pointer(sqlite3_memory_alarm) := GetProcedureAddress(LibHandle,'sqlite3_memory_alarm');
  5732. pointer(sqlite3_thread_cleanup) := GetProcedureAddress(LibHandle,'sqlite3_thread_cleanup');
  5733. {$ENDIF}
  5734. end;
  5735. var
  5736. RefCount: Integer;
  5737. LoadedLibrary: String;
  5738. function TryInitializeSqlite(const LibraryName: string): Integer;
  5739. begin
  5740. result:=InterlockedIncrement(RefCount);
  5741. if result = 1 then
  5742. begin
  5743. SQLiteLibraryHandle := LoadLibrary(LibraryName);
  5744. if (SQLiteLibraryHandle = NilHandle) then
  5745. begin
  5746. RefCount := 0;
  5747. Exit(-1);
  5748. end;
  5749. LoadedLibrary := LibraryName;
  5750. LoadAddresses(SQLiteLibraryHandle);
  5751. end;
  5752. end;
  5753. function InitialiseSQLite:integer;
  5754. begin
  5755. result:=InitializeSqlite(SQLiteDefaultLibrary);
  5756. end;
  5757. function InitializeSQLite(const LibraryName: String) :integer;
  5758. begin
  5759. if (LoadedLibrary <> '') and (LoadedLibrary <> LibraryName) then
  5760. raise EInoutError.CreateFmt(SErrAlreadyLoaded,[LoadedLibrary]);
  5761. result:= TryInitializeSQLIte(LibraryName);
  5762. if result=-1 then
  5763. raise EInOutError.CreateFmt(SErrLoadFailed,[LibraryName]);
  5764. end;
  5765. function InitialiseSQLite(const LibraryName: String):integer;
  5766. begin
  5767. result:=InitializeSqlite(LibraryName);
  5768. end;
  5769. function ReleaseSQLite:integer;
  5770. begin
  5771. if InterlockedDecrement(RefCount) <= 0 then
  5772. begin
  5773. if SQLiteLibraryHandle <> NilHandle then
  5774. UnloadLibrary(SQLiteLibraryHandle);
  5775. SQLiteLibraryHandle := NilHandle;
  5776. LoadedLibrary := '';
  5777. RefCount := 0;
  5778. end;
  5779. end;
  5780. {$ENDIF}